]> code.delx.au - gnu-emacs/blob - lisp/gnus/message.el
46f01770480fe5620a4c8b691fe579a1894ef644
[gnu-emacs] / lisp / gnus / message.el
1 ;;; message.el --- composing mail and news messages
2
3 ;; Copyright (C) 1996-2016 Free Software Foundation, Inc.
4
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
6 ;; Keywords: mail, news
7
8 ;; This file is part of GNU Emacs.
9
10 ;; GNU Emacs is free software: you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation, either version 3 of the License, or
13 ;; (at your option) any later version.
14
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
19
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
22
23 ;;; Commentary:
24
25 ;; This mode provides mail-sending facilities from within Emacs. It
26 ;; consists mainly of large chunks of code from the sendmail.el,
27 ;; gnus-msg.el and rnewspost.el files.
28
29 ;;; Code:
30
31 (eval-when-compile
32 (require 'cl))
33
34 (require 'mailheader)
35 (require 'gmm-utils)
36 (require 'mail-utils)
37 ;; Only for the trivial macros mail-header-from, mail-header-date
38 ;; mail-header-references, mail-header-subject, mail-header-id
39 (eval-when-compile (require 'nnheader))
40 ;; This is apparently necessary even though things are autoloaded.
41 ;; Because we dynamically bind mail-abbrev-mode-regexp, we'd better
42 ;; require mailabbrev here.
43 (require 'mailabbrev)
44 (require 'mail-parse)
45 (require 'mml)
46 (require 'rfc822)
47 (require 'format-spec)
48 (require 'dired)
49 (require 'mm-util)
50 (require 'rfc2047)
51
52 (autoload 'mailclient-send-it "mailclient") ;; Emacs 22 or contrib/
53
54 (defvar gnus-message-group-art)
55 (defvar gnus-list-identifiers) ; gnus-sum is required where necessary
56 (defvar rmail-enable-mime-composing)
57
58 (defgroup message '((user-mail-address custom-variable)
59 (user-full-name custom-variable))
60 "Mail and news message composing."
61 :link '(custom-manual "(message)Top")
62 :group 'mail
63 :group 'news)
64
65 (put 'user-mail-address 'custom-type 'string)
66 (put 'user-full-name 'custom-type 'string)
67
68 (defgroup message-various nil
69 "Various Message Variables."
70 :link '(custom-manual "(message)Various Message Variables")
71 :group 'message)
72
73 (defgroup message-buffers nil
74 "Message Buffers."
75 :link '(custom-manual "(message)Message Buffers")
76 :group 'message)
77
78 (defgroup message-sending nil
79 "Message Sending."
80 :link '(custom-manual "(message)Sending Variables")
81 :group 'message)
82
83 (defgroup message-interface nil
84 "Message Interface."
85 :link '(custom-manual "(message)Interface")
86 :group 'message)
87
88 (defgroup message-forwarding nil
89 "Message Forwarding."
90 :link '(custom-manual "(message)Forwarding")
91 :group 'message-interface)
92
93 (defgroup message-insertion nil
94 "Message Insertion."
95 :link '(custom-manual "(message)Insertion")
96 :group 'message)
97
98 (defgroup message-headers nil
99 "Message Headers."
100 :link '(custom-manual "(message)Message Headers")
101 :group 'message)
102
103 (defgroup message-news nil
104 "Composing News Messages."
105 :group 'message)
106
107 (defgroup message-mail nil
108 "Composing Mail Messages."
109 :group 'message)
110
111 (defgroup message-faces nil
112 "Faces used for message composing."
113 :group 'message
114 :group 'faces)
115
116 (defcustom message-directory "~/Mail/"
117 "*Directory from which all other mail file variables are derived."
118 :group 'message-various
119 :type 'directory)
120
121 (defcustom message-max-buffers 10
122 "*How many buffers to keep before starting to kill them off."
123 :group 'message-buffers
124 :type 'integer)
125
126 (defcustom message-send-rename-function nil
127 "Function called to rename the buffer after sending it."
128 :group 'message-buffers
129 :type '(choice function (const nil)))
130
131 (defcustom message-fcc-handler-function 'message-output
132 "*A function called to save outgoing articles.
133 This function will be called with the name of the file to store the
134 article in. The default function is `message-output' which saves in Unix
135 mailbox format."
136 :type '(radio (function-item message-output)
137 (function :tag "Other"))
138 :group 'message-sending)
139
140 (defcustom message-fcc-externalize-attachments nil
141 "If non-nil, attachments are included as external parts in Fcc copies."
142 :version "22.1"
143 :type 'boolean
144 :group 'message-sending)
145
146 (defcustom message-courtesy-message
147 "The following message is a courtesy copy of an article\nthat has been posted to %s as well.\n\n"
148 "*This is inserted at the start of a mailed copy of a posted message.
149 If the string contains the format spec \"%s\", the Newsgroups
150 the article has been posted to will be inserted there.
151 If this variable is nil, no such courtesy message will be added."
152 :group 'message-sending
153 :type '(radio string (const nil)))
154
155 (defcustom message-ignored-bounced-headers
156 "^\\(Received\\|Return-Path\\|Delivered-To\\):"
157 "*Regexp that matches headers to be removed in resent bounced mail."
158 :group 'message-interface
159 :type 'regexp)
160
161 (defcustom message-from-style mail-from-style
162 "Specifies how \"From\" headers look.
163
164 If nil, they contain just the return address like:
165 king@grassland.com
166 If `parens', they look like:
167 king@grassland.com (Elvis Parsley)
168 If `angles', they look like:
169 Elvis Parsley <king@grassland.com>
170
171 Otherwise, most addresses look like `angles', but they look like
172 `parens' if `angles' would need quoting and `parens' would not."
173 :version "23.2"
174 :type '(choice (const :tag "simple" nil)
175 (const parens)
176 (const angles)
177 (const default))
178 :group 'message-headers)
179
180 (defcustom message-insert-canlock t
181 "Whether to insert a Cancel-Lock header in news postings."
182 :version "22.1"
183 :group 'message-headers
184 :type 'boolean)
185
186 (defcustom message-syntax-checks
187 (if message-insert-canlock '((sender . disabled)) nil)
188 ;; Guess this one shouldn't be easy to customize...
189 "*Controls what syntax checks should not be performed on outgoing posts.
190 To disable checking of long signatures, for instance, add
191 `(signature . disabled)' to this list.
192
193 Don't touch this variable unless you really know what you're doing.
194
195 Checks include `approved', `bogus-recipient', `continuation-headers',
196 `control-chars', `empty', `existing-newsgroups', `from', `illegible-text',
197 `invisible-text', `long-header-lines', `long-lines', `message-id',
198 `multiple-headers', `new-text', `newsgroups', `quoting-style',
199 `repeated-newsgroups', `reply-to', `sender', `sendsys', `shoot',
200 `shorten-followup-to', `signature', `size', `subject', `subject-cmsg'
201 and `valid-newsgroups'."
202 :group 'message-news
203 :type '(repeat sexp)) ; Fixme: improve this
204
205 (defcustom message-required-headers '((optional . References)
206 From)
207 "*Headers to be generated or prompted for when sending a message.
208 Also see `message-required-news-headers' and
209 `message-required-mail-headers'."
210 :version "22.1"
211 :group 'message-news
212 :group 'message-headers
213 :link '(custom-manual "(message)Message Headers")
214 :type '(repeat sexp))
215
216 (defcustom message-draft-headers '(References From Date)
217 "*Headers to be generated when saving a draft message."
218 :version "22.1"
219 :group 'message-news
220 :group 'message-headers
221 :link '(custom-manual "(message)Message Headers")
222 :type '(repeat sexp))
223
224 (defcustom message-required-news-headers
225 '(From Newsgroups Subject Date Message-ID
226 (optional . Organization)
227 (optional . User-Agent))
228 "*Headers to be generated or prompted for when posting an article.
229 RFC977 and RFC1036 require From, Date, Newsgroups, Subject,
230 Message-ID. Organization, Lines, In-Reply-To, Expires, and
231 User-Agent are optional. If you don't want message to insert some
232 header, remove it from this list."
233 :group 'message-news
234 :group 'message-headers
235 :link '(custom-manual "(message)Message Headers")
236 :type '(repeat sexp))
237
238 (defcustom message-required-mail-headers
239 '(From Subject Date (optional . In-Reply-To) Message-ID
240 (optional . User-Agent))
241 "*Headers to be generated or prompted for when mailing a message.
242 It is recommended that From, Date, To, Subject and Message-ID be
243 included. Organization and User-Agent are optional."
244 :group 'message-mail
245 :group 'message-headers
246 :link '(custom-manual "(message)Message Headers")
247 :type '(repeat sexp))
248
249 (defcustom message-prune-recipient-rules nil
250 "Rules for how to prune the list of recipients when doing wide replies.
251 This is a list of regexps and regexp matches."
252 :version "24.1"
253 :group 'message-mail
254 :group 'message-headers
255 :link '(custom-manual "(message)Wide Reply")
256 :type '(repeat regexp))
257
258 (defcustom message-deletable-headers '(Message-ID Date Lines)
259 "Headers to delete if present and previously generated by message."
260 :group 'message-headers
261 :link '(custom-manual "(message)Message Headers")
262 :type '(repeat (symbol :tag "Header")))
263
264 (defcustom message-ignored-news-headers
265 "^NNTP-Posting-Host:\\|^Xref:\\|^[BGF]cc:\\|^Resent-Fcc:\\|^X-Draft-From:\\|^X-Gnus-Agent-Meta-Information:\\|^X-Message-SMTP-Method:\\|^X-Gnus-Delayed:"
266 "*Regexp of headers to be removed unconditionally before posting."
267 :group 'message-news
268 :group 'message-headers
269 :link '(custom-manual "(message)Message Headers")
270 :type '(repeat :value-to-internal (lambda (widget value)
271 (custom-split-regexp-maybe value))
272 :match (lambda (widget value)
273 (or (stringp value)
274 (widget-editable-list-match widget value)))
275 regexp))
276
277 (defcustom message-ignored-mail-headers
278 "^\\([GF]cc\\|Resent-Fcc\\|Xref\\|X-Draft-From\\|X-Gnus-Agent-Meta-Information\\):"
279 "*Regexp of headers to be removed unconditionally before mailing."
280 :group 'message-mail
281 :group 'message-headers
282 :link '(custom-manual "(message)Mail Headers")
283 :type 'regexp)
284
285 (defcustom message-ignored-supersedes-headers "^Path:\\|^Date\\|^NNTP-Posting-Host:\\|^Xref:\\|^Lines:\\|^Received:\\|^X-From-Line:\\|^X-Trace:\\|^X-ID:\\|^X-Complaints-To:\\|Return-Path:\\|^Supersedes:\\|^NNTP-Posting-Date:\\|^X-Trace:\\|^X-Complaints-To:\\|^Cancel-Lock:\\|^Cancel-Key:\\|^X-Hashcash:\\|^X-Payment:\\|^Approved:\\|^Injection-Date:\\|^Injection-Info:"
286 "*Header lines matching this regexp will be deleted before posting.
287 It's best to delete old Path and Date headers before posting to avoid
288 any confusion."
289 :group 'message-interface
290 :link '(custom-manual "(message)Superseding")
291 :type '(repeat :value-to-internal (lambda (widget value)
292 (custom-split-regexp-maybe value))
293 :match (lambda (widget value)
294 (or (stringp value)
295 (widget-editable-list-match widget value)))
296 regexp))
297
298 (defcustom message-subject-re-regexp
299 "^[ \t]*\\([Rr][Ee]\\(\\[[0-9]*\\]\\)* ?:[ \t]*\\)*[ \t]*"
300 "*Regexp matching \"Re: \" in the subject line."
301 :group 'message-various
302 :link '(custom-manual "(message)Message Headers")
303 :type 'regexp)
304
305 ;;; Start of variables adopted from `message-utils.el'.
306
307 (defcustom message-subject-trailing-was-query t
308 "*What to do with trailing \"(was: <old subject>)\" in subject lines.
309 If nil, leave the subject unchanged. If it is the symbol `ask', query
310 the user what do do. In this case, the subject is matched against
311 `message-subject-trailing-was-ask-regexp'. If
312 `message-subject-trailing-was-query' is t, always strip the trailing
313 old subject. In this case, `message-subject-trailing-was-regexp' is
314 used."
315 :version "24.1"
316 :type '(choice (const :tag "never" nil)
317 (const :tag "always strip" t)
318 (const ask))
319 :link '(custom-manual "(message)Message Headers")
320 :group 'message-various)
321
322 (defcustom message-subject-trailing-was-ask-regexp
323 "[ \t]*\\([[(]+[Ww][Aa][Ss]:?[ \t]*.*[])]+\\)"
324 "*Regexp matching \"(was: <old subject>)\" in the subject line.
325
326 The function `message-strip-subject-trailing-was' uses this regexp if
327 `message-subject-trailing-was-query' is set to the symbol `ask'. If
328 the variable is t instead of `ask', use
329 `message-subject-trailing-was-regexp' instead.
330
331 It is okay to create some false positives here, as the user is asked."
332 :version "22.1"
333 :group 'message-various
334 :link '(custom-manual "(message)Message Headers")
335 :type 'regexp)
336
337 (defcustom message-subject-trailing-was-regexp
338 "[ \t]*\\((*[Ww][Aa][Ss]:[ \t]*.*)\\)"
339 "*Regexp matching \"(was: <old subject>)\" in the subject line.
340
341 If `message-subject-trailing-was-query' is set to t, the subject is
342 matched against `message-subject-trailing-was-regexp' in
343 `message-strip-subject-trailing-was'. You should use a regexp creating very
344 few false positives here."
345 :version "22.1"
346 :group 'message-various
347 :link '(custom-manual "(message)Message Headers")
348 :type 'regexp)
349
350 ;;; marking inserted text
351
352 (defcustom message-mark-insert-begin
353 "--8<---------------cut here---------------start------------->8---\n"
354 "How to mark the beginning of some inserted text."
355 :version "22.1"
356 :type 'string
357 :link '(custom-manual "(message)Insertion Variables")
358 :group 'message-various)
359
360 (defcustom message-mark-insert-end
361 "--8<---------------cut here---------------end--------------->8---\n"
362 "How to mark the end of some inserted text."
363 :version "22.1"
364 :type 'string
365 :link '(custom-manual "(message)Insertion Variables")
366 :group 'message-various)
367
368 (defcustom message-archive-header "X-No-Archive: Yes\n"
369 "Header to insert when you don't want your article to be archived.
370 Archives \(such as groups.google.com) respect this header."
371 :version "22.1"
372 :type 'string
373 :link '(custom-manual "(message)Header Commands")
374 :group 'message-various)
375
376 (defcustom message-archive-note
377 "X-No-Archive: Yes - save http://groups.google.com/"
378 "Note to insert why you wouldn't want this posting archived.
379 If nil, don't insert any text in the body."
380 :version "22.1"
381 :type '(radio string (const nil))
382 :link '(custom-manual "(message)Header Commands")
383 :group 'message-various)
384
385 ;;; Crossposts and Followups
386 ;; inspired by JoH-followup-to by Jochem Huhman <joh at gmx.de>
387 ;; new suggestions by R. Weikusat <rw at another.de>
388
389 (defvar message-cross-post-old-target nil
390 "Old target for cross-posts or follow-ups.")
391 (make-variable-buffer-local 'message-cross-post-old-target)
392
393 (defcustom message-cross-post-default t
394 "When non-nil `message-cross-post-followup-to' will perform a crosspost.
395 If nil, `message-cross-post-followup-to' will only do a followup. Note that
396 you can explicitly override this setting by calling
397 `message-cross-post-followup-to' with a prefix."
398 :version "22.1"
399 :type 'boolean
400 :group 'message-various)
401
402 (defcustom message-cross-post-note "Crosspost & Followup-To: "
403 "Note to insert before signature to notify of cross-post and follow-up."
404 :version "22.1"
405 :type 'string
406 :group 'message-various)
407
408 (defcustom message-followup-to-note "Followup-To: "
409 "Note to insert before signature to notify of follow-up only."
410 :version "22.1"
411 :type 'string
412 :group 'message-various)
413
414 (defcustom message-cross-post-note-function 'message-cross-post-insert-note
415 "Function to use to insert note about Crosspost or Followup-To.
416 The function will be called with four arguments. The function should not only
417 insert a note, but also ensure old notes are deleted. See the documentation
418 for `message-cross-post-insert-note'."
419 :version "22.1"
420 :type 'function
421 :group 'message-various)
422
423 ;;; End of variables adopted from `message-utils.el'.
424
425 (defcustom message-signature-separator "^-- $"
426 "Regexp matching the signature separator.
427 This variable is used to strip off the signature from quoted text
428 when `message-cite-function' is
429 `message-cite-original-without-signature'. Most useful values
430 are \"^-- $\" (strict) and \"^-- *$\" (loose; allow missing
431 whitespace)."
432 :type '(choice (const :tag "strict" "^-- $")
433 (const :tag "loose" "^-- *$")
434 regexp)
435 :version "22.3" ;; Gnus 5.10.12 (changed default)
436 :link '(custom-manual "(message)Various Message Variables")
437 :group 'message-various)
438
439 (defcustom message-elide-ellipsis "\n[...]\n\n"
440 "*The string which is inserted for elided text.
441 This is a format-spec string, and you can use %l to say how many
442 lines were removed, and %c to say how many characters were
443 removed."
444 :type 'string
445 :link '(custom-manual "(message)Various Commands")
446 :group 'message-various)
447
448 (defcustom message-interactive mail-interactive
449 "Non-nil means when sending a message wait for and display errors.
450 A value of nil means let mailer mail back a message to report errors."
451 :version "23.2"
452 :group 'message-sending
453 :group 'message-mail
454 :link '(custom-manual "(message)Sending Variables")
455 :type 'boolean)
456
457 (defcustom message-confirm-send nil
458 "When non-nil, ask for confirmation when sending a message."
459 :group 'message-sending
460 :group 'message-mail
461 :version "23.1" ;; No Gnus
462 :link '(custom-manual "(message)Sending Variables")
463 :type 'boolean)
464
465 (defcustom message-generate-new-buffers 'unsent
466 "*Say whether to create a new message buffer to compose a message.
467 Valid values include:
468
469 nil
470 Generate the buffer name in the Message way (e.g., *mail*, *news*,
471 *mail to whom*, *news on group*, etc.) and continue editing in the
472 existing buffer of that name. If there is no such buffer, it will
473 be newly created.
474
475 `unique' or t
476 Create the new buffer with the name generated in the Message way.
477
478 `unsent'
479 Similar to `unique' but the buffer name begins with \"*unsent \".
480
481 `standard'
482 Similar to nil but the buffer name is simpler like *mail message*.
483
484 function
485 If this is a function, call that function with three parameters:
486 The type, the To address and the group name (any of these may be nil).
487 The function should return the new buffer name."
488 :version "24.1"
489 :group 'message-buffers
490 :link '(custom-manual "(message)Message Buffers")
491 :type '(choice (const nil)
492 (sexp :tag "unique" :format "unique\n" :value unique
493 :match (lambda (widget value) (memq value '(unique t))))
494 (const unsent)
495 (const standard)
496 (function :format "\n %{%t%}: %v")))
497
498 (defcustom message-kill-buffer-on-exit nil
499 "*Non-nil means that the message buffer will be killed after sending a message."
500 :group 'message-buffers
501 :link '(custom-manual "(message)Message Buffers")
502 :type 'boolean)
503
504 (defcustom message-kill-buffer-query t
505 "*Non-nil means that killing a modified message buffer has to be confirmed.
506 This is used by `message-kill-buffer'."
507 :version "23.1" ;; No Gnus
508 :group 'message-buffers
509 :type 'boolean)
510
511 (defcustom message-user-organization
512 (or (getenv "ORGANIZATION") t)
513 "String to be used as an Organization header.
514 If t, use `message-user-organization-file'."
515 :group 'message-headers
516 :type '(choice string
517 (const :tag "consult file" t)))
518
519 (defcustom message-user-organization-file
520 (let (orgfile)
521 (dolist (f (list "/etc/organization"
522 "/etc/news/organization"
523 "/usr/lib/news/organization"))
524 (when (file-readable-p f)
525 (setq orgfile f)))
526 orgfile)
527 "*Local news organization file."
528 :type '(choice (const nil) file)
529 :link '(custom-manual "(message)News Headers")
530 :group 'message-headers)
531
532 (defcustom message-make-forward-subject-function
533 #'message-forward-subject-name-subject
534 "*List of functions called to generate subject headers for forwarded messages.
535 The subject generated by the previous function is passed into each
536 successive function.
537
538 The provided functions are:
539
540 * `message-forward-subject-author-subject' Source of article (author or
541 newsgroup), in brackets followed by the subject
542 * `message-forward-subject-name-subject' Source of article (name of author
543 or newsgroup), in brackets followed by the subject
544 * `message-forward-subject-fwd' Subject of article with `Fwd:' prepended
545 to it."
546 :group 'message-forwarding
547 :link '(custom-manual "(message)Forwarding")
548 :type '(radio (function-item message-forward-subject-author-subject)
549 (function-item message-forward-subject-fwd)
550 (function-item message-forward-subject-name-subject)
551 (repeat :tag "List of functions" function)))
552
553 (defcustom message-forward-as-mime t
554 "*Non-nil means forward messages as an inline/rfc822 MIME section.
555 Otherwise, directly inline the old message in the forwarded message."
556 :version "21.1"
557 :group 'message-forwarding
558 :link '(custom-manual "(message)Forwarding")
559 :type 'boolean)
560
561 (defcustom message-forward-show-mml 'best
562 "*Non-nil means show forwarded messages as MML (decoded from MIME).
563 Otherwise, forwarded messages are unchanged.
564 Can also be the symbol `best' to indicate that MML should be
565 used, except when it is a bad idea to use MML. One example where
566 it is a bad idea is when forwarding a signed or encrypted
567 message, because converting MIME to MML would invalidate the
568 digital signature."
569 :version "21.1"
570 :group 'message-forwarding
571 :type '(choice (const :tag "use MML" t)
572 (const :tag "don't use MML " nil)
573 (const :tag "use MML when appropriate" best)))
574
575 (defcustom message-forward-before-signature t
576 "*Non-nil means put forwarded message before signature, else after."
577 :group 'message-forwarding
578 :type 'boolean)
579
580 (defcustom message-wash-forwarded-subjects nil
581 "*Non-nil means try to remove as much cruft as possible from the subject.
582 Done before generating the new subject of a forward."
583 :group 'message-forwarding
584 :link '(custom-manual "(message)Forwarding")
585 :type 'boolean)
586
587 (defcustom message-ignored-resent-headers
588 ;; `Delivered-To' needs to be removed because some mailers use it to
589 ;; detect loops, so if you resend a message to an address that ultimately
590 ;; comes back to you (e.g. a mailing-list to which you subscribe, in which
591 ;; case you may be removed from the list on the grounds that mail to you
592 ;; bounced with a "mailing loop" error).
593 "^Return-receipt\\|^X-Gnus\\|^Gnus-Warning:\\|^>?From \\|^Delivered-To:\
594 \\|^X-Content-Length:\\|^X-UIDL:"
595 "*All headers that match this regexp will be deleted when resending a message."
596 :version "24.4"
597 :group 'message-interface
598 :link '(custom-manual "(message)Resending")
599 :type '(repeat :value-to-internal (lambda (widget value)
600 (custom-split-regexp-maybe value))
601 :match (lambda (widget value)
602 (or (stringp value)
603 (widget-editable-list-match widget value)))
604 regexp))
605
606 (defcustom message-forward-ignored-headers "^Content-Transfer-Encoding:\\|^X-Gnus"
607 "*All headers that match this regexp will be deleted when forwarding a message.
608 This may also be a list of regexps."
609 :version "21.1"
610 :group 'message-forwarding
611 :type '(repeat :value-to-internal (lambda (widget value)
612 (custom-split-regexp-maybe value))
613 :match (lambda (widget value)
614 (or (stringp value)
615 (widget-editable-list-match widget value)))
616 regexp))
617
618 (defcustom message-forward-included-headers nil
619 "If non-nil, delete non-matching headers when forwarding a message.
620 Only headers that match this regexp will be included. This
621 variable should be a regexp or a list of regexps."
622 :version "25.1"
623 :group 'message-forwarding
624 :type '(repeat :value-to-internal (lambda (widget value)
625 (custom-split-regexp-maybe value))
626 :match (lambda (widget value)
627 (or (stringp value)
628 (widget-editable-list-match widget value)))
629 regexp))
630
631 (defcustom message-ignored-cited-headers "."
632 "*Delete these headers from the messages you yank."
633 :group 'message-insertion
634 :link '(custom-manual "(message)Insertion Variables")
635 :type 'regexp)
636
637 (defcustom message-cite-prefix-regexp mail-citation-prefix-regexp
638 "*Regexp matching the longest possible citation prefix on a line."
639 :version "24.1"
640 :group 'message-insertion
641 :link '(custom-manual "(message)Insertion Variables")
642 :type 'regexp
643 :set (lambda (symbol value)
644 (prog1
645 (custom-set-default symbol value)
646 (if (boundp 'gnus-message-cite-prefix-regexp)
647 (setq gnus-message-cite-prefix-regexp
648 (concat "^\\(?:" value "\\)"))))))
649
650 (defcustom message-cancel-message "I am canceling my own article.\n"
651 "Message to be inserted in the cancel message."
652 :group 'message-interface
653 :link '(custom-manual "(message)Canceling News")
654 :type 'string)
655
656 (defun message-send-mail-function ()
657 "Return suitable value for the variable `message-send-mail-function'."
658 (cond ((and (require 'sendmail)
659 sendmail-program
660 (executable-find sendmail-program))
661 'message-send-mail-with-sendmail)
662 ((and (locate-library "smtpmail")
663 smtpmail-default-smtp-server)
664 'message-smtpmail-send-it)
665 ((locate-library "mailclient")
666 'message-send-mail-with-mailclient)
667 (t
668 (error "Don't know how to send mail. Please customize `message-send-mail-function'"))))
669
670 (defun message-default-send-mail-function ()
671 (cond ((eq send-mail-function 'smtpmail-send-it) 'message-smtpmail-send-it)
672 ((eq send-mail-function 'feedmail-send-it) 'feedmail-send-it)
673 ((eq send-mail-function 'sendmail-query-once) 'sendmail-query-once)
674 ((eq send-mail-function 'mailclient-send-it)
675 'message-send-mail-with-mailclient)
676 (t (message-send-mail-function))))
677
678 ;; Useful to set in site-init.el
679 (defcustom message-send-mail-function (message-default-send-mail-function)
680 "Function to call to send the current buffer as mail.
681 The headers should be delimited by a line whose contents match the
682 variable `mail-header-separator'.
683
684 Valid values include `message-send-mail-with-sendmail'
685 `message-send-mail-with-mh', `message-send-mail-with-qmail',
686 `message-smtpmail-send-it', `smtpmail-send-it',
687 `feedmail-send-it' and `message-send-mail-with-mailclient'. The
688 default is system dependent and determined by the function
689 `message-send-mail-function'.
690
691 See also `send-mail-function'."
692 :type '(radio (function-item message-send-mail-with-sendmail)
693 (function-item message-send-mail-with-mh)
694 (function-item message-send-mail-with-qmail)
695 (function-item message-smtpmail-send-it)
696 (function-item smtpmail-send-it)
697 (function-item feedmail-send-it)
698 (function-item message-send-mail-with-mailclient
699 :tag "Use Mailclient package")
700 (function :tag "Other"))
701 :group 'message-sending
702 :version "23.2"
703 :initialize 'custom-initialize-default
704 :link '(custom-manual "(message)Mail Variables")
705 :group 'message-mail)
706
707 (defcustom message-send-news-function 'message-send-news
708 "Function to call to send the current buffer as news.
709 The headers should be delimited by a line whose contents match the
710 variable `mail-header-separator'."
711 :group 'message-sending
712 :group 'message-news
713 :link '(custom-manual "(message)News Variables")
714 :type 'function)
715
716 (defcustom message-reply-to-function nil
717 "If non-nil, function that should return a list of headers.
718 This function should pick out addresses from the To, Cc, and From headers
719 and respond with new To and Cc headers."
720 :group 'message-interface
721 :link '(custom-manual "(message)Reply")
722 :type '(choice function (const nil)))
723
724 (defcustom message-wide-reply-to-function nil
725 "If non-nil, function that should return a list of headers.
726 This function should pick out addresses from the To, Cc, and From headers
727 and respond with new To and Cc headers."
728 :group 'message-interface
729 :link '(custom-manual "(message)Wide Reply")
730 :type '(choice function (const nil)))
731
732 (defcustom message-followup-to-function nil
733 "If non-nil, function that should return a list of headers.
734 This function should pick out addresses from the To, Cc, and From headers
735 and respond with new To and Cc headers."
736 :group 'message-interface
737 :link '(custom-manual "(message)Followup")
738 :type '(choice function (const nil)))
739
740 (defcustom message-extra-wide-headers nil
741 "If non-nil, a list of additional address headers.
742 These are used when composing a wide reply."
743 :group 'message-sending
744 :type '(repeat string))
745
746 (defcustom message-use-followup-to 'ask
747 "*Specifies what to do with Followup-To header.
748 If nil, always ignore the header. If it is t, use its value, but
749 query before using the \"poster\" value. If it is the symbol `ask',
750 always query the user whether to use the value. If it is the symbol
751 `use', always use the value."
752 :group 'message-interface
753 :link '(custom-manual "(message)Followup")
754 :type '(choice (const :tag "ignore" nil)
755 (const :tag "use & query" t)
756 (const use)
757 (const ask)))
758
759 (defcustom message-use-mail-followup-to 'use
760 "*Specifies what to do with Mail-Followup-To header.
761 If nil, always ignore the header. If it is the symbol `ask', always
762 query the user whether to use the value. If it is the symbol `use',
763 always use the value."
764 :version "22.1"
765 :group 'message-interface
766 :link '(custom-manual "(message)Mailing Lists")
767 :type '(choice (const :tag "ignore" nil)
768 (const use)
769 (const ask)))
770
771 (defcustom message-subscribed-address-functions nil
772 "*Specifies functions for determining list subscription.
773 If nil, do not attempt to determine list subscription with functions.
774 If non-nil, this variable contains a list of functions which return
775 regular expressions to match lists. These functions can be used in
776 conjunction with `message-subscribed-regexps' and
777 `message-subscribed-addresses'."
778 :version "22.1"
779 :group 'message-interface
780 :link '(custom-manual "(message)Mailing Lists")
781 :type '(repeat sexp))
782
783 (defcustom message-subscribed-address-file nil
784 "*A file containing addresses the user is subscribed to.
785 If nil, do not look at any files to determine list subscriptions. If
786 non-nil, each line of this file should be a mailing list address."
787 :version "22.1"
788 :group 'message-interface
789 :link '(custom-manual "(message)Mailing Lists")
790 :type '(radio file (const nil)))
791
792 (defcustom message-subscribed-addresses nil
793 "*Specifies a list of addresses the user is subscribed to.
794 If nil, do not use any predefined list subscriptions. This list of
795 addresses can be used in conjunction with
796 `message-subscribed-address-functions' and `message-subscribed-regexps'."
797 :version "22.1"
798 :group 'message-interface
799 :link '(custom-manual "(message)Mailing Lists")
800 :type '(repeat string))
801
802 (defcustom message-subscribed-regexps nil
803 "*Specifies a list of addresses the user is subscribed to.
804 If nil, do not use any predefined list subscriptions. This list of
805 regular expressions can be used in conjunction with
806 `message-subscribed-address-functions' and `message-subscribed-addresses'."
807 :version "22.1"
808 :group 'message-interface
809 :link '(custom-manual "(message)Mailing Lists")
810 :type '(repeat regexp))
811
812 (defcustom message-allow-no-recipients 'ask
813 "Specifies what to do when there are no recipients other than Gcc/Fcc.
814 If it is the symbol `always', the posting is allowed. If it is the
815 symbol `never', the posting is not allowed. If it is the symbol
816 `ask', you are prompted."
817 :version "22.1"
818 :group 'message-interface
819 :link '(custom-manual "(message)Message Headers")
820 :type '(choice (const always)
821 (const never)
822 (const ask)))
823
824 (defcustom message-sendmail-f-is-evil nil
825 "*Non-nil means don't add \"-f username\" to the sendmail command line.
826 Doing so would be even more evil than leaving it out."
827 :group 'message-sending
828 :link '(custom-manual "(message)Mail Variables")
829 :type 'boolean)
830
831 (defcustom message-sendmail-envelope-from
832 ;; `mail-envelope-from' is unavailable unless sendmail.el is loaded.
833 (if (boundp 'mail-envelope-from) mail-envelope-from)
834 "*Envelope-from when sending mail with sendmail.
835 If this is nil, use `user-mail-address'. If it is the symbol
836 `header', use the From: header of the message."
837 :version "23.2"
838 :type '(choice (string :tag "From name")
839 (const :tag "Use From: header from message" header)
840 (const :tag "Use `user-mail-address'" nil))
841 :link '(custom-manual "(message)Mail Variables")
842 :group 'message-sending)
843
844 (defcustom message-sendmail-extra-arguments nil
845 "Additional arguments to `sendmail-program'."
846 ;; E.g. '("-a" "account") for msmtp
847 :version "23.1" ;; No Gnus
848 :type '(repeat string)
849 ;; :link '(custom-manual "(message)Mail Variables")
850 :group 'message-sending)
851
852 ;; qmail-related stuff
853 (defcustom message-qmail-inject-program "/var/qmail/bin/qmail-inject"
854 "Location of the qmail-inject program."
855 :group 'message-sending
856 :link '(custom-manual "(message)Mail Variables")
857 :type 'file)
858
859 (defcustom message-qmail-inject-args nil
860 "Arguments passed to qmail-inject programs.
861 This should be a list of strings, one string for each argument.
862 It may also be a function.
863
864 For e.g., if you wish to set the envelope sender address so that bounces
865 go to the right place or to deal with listserv's usage of that address, you
866 might set this variable to (\"-f\" \"you@some.where\")."
867 :group 'message-sending
868 :link '(custom-manual "(message)Mail Variables")
869 :type '(choice (function)
870 (repeat string)))
871
872 (defvar gnus-post-method)
873 (defvar gnus-select-method)
874 (defcustom message-post-method
875 (cond ((and (boundp 'gnus-post-method)
876 (listp gnus-post-method)
877 gnus-post-method)
878 gnus-post-method)
879 ((boundp 'gnus-select-method)
880 gnus-select-method)
881 (t '(nnspool "")))
882 "*Method used to post news.
883 Note that when posting from inside Gnus, for instance, this
884 variable isn't used."
885 :group 'message-news
886 :group 'message-sending
887 ;; This should be the `gnus-select-method' widget, but that might
888 ;; create a dependence to `gnus.el'.
889 :type 'sexp)
890
891 (defcustom message-generate-headers-first nil
892 "Which headers should be generated before starting to compose a message.
893 If t, generate all required headers. This can also be a list of headers to
894 generate. The variables `message-required-news-headers' and
895 `message-required-mail-headers' specify which headers to generate.
896
897 Note that the variable `message-deletable-headers' specifies headers which
898 are to be deleted and then re-generated before sending, so this variable
899 will not have a visible effect for those headers."
900 :group 'message-headers
901 :link '(custom-manual "(message)Message Headers")
902 :type '(choice (const :tag "None" nil)
903 (const :tag "All" t)
904 (repeat (sexp :tag "Header"))))
905
906 (defcustom message-fill-column 72
907 "Column beyond which automatic line-wrapping should happen.
908 Local value for message buffers. If non-nil, also turn on
909 auto-fill in message buffers."
910 :group 'message-various
911 ;; :link '(custom-manual "(message)Message Headers")
912 :type '(choice (const :tag "Don't turn on auto fill" nil)
913 (integer)))
914
915 (defcustom message-setup-hook nil
916 "Normal hook, run each time a new outgoing message is initialized.
917 The function `message-setup' runs this hook."
918 :group 'message-various
919 :link '(custom-manual "(message)Various Message Variables")
920 :type 'hook)
921
922 (defcustom message-cancel-hook nil
923 "Hook run when canceling articles."
924 :group 'message-various
925 :link '(custom-manual "(message)Various Message Variables")
926 :type 'hook)
927
928 (defcustom message-signature-setup-hook nil
929 "Normal hook, run each time a new outgoing message is initialized.
930 It is run after the headers have been inserted and before
931 the signature is inserted."
932 :group 'message-various
933 :link '(custom-manual "(message)Various Message Variables")
934 :type 'hook)
935
936 (defcustom message-mode-hook nil
937 "Hook run in message mode buffers."
938 :group 'message-various
939 :type 'hook)
940
941 (defcustom message-header-hook nil
942 "Hook run in a message mode buffer narrowed to the headers."
943 :group 'message-various
944 :type 'hook)
945
946 (defcustom message-header-setup-hook nil
947 "Hook called narrowed to the headers when setting up a message buffer."
948 :group 'message-various
949 :link '(custom-manual "(message)Various Message Variables")
950 :type 'hook)
951
952 (defcustom message-minibuffer-local-map
953 (let ((map (make-sparse-keymap 'message-minibuffer-local-map)))
954 (set-keymap-parent map minibuffer-local-map)
955 map)
956 "Keymap for `message-read-from-minibuffer'."
957 ;; FIXME improve type.
958 :type '(restricted-sexp :match-alternatives (symbolp keymapp))
959 :version "22.1"
960 :group 'message-various)
961
962 (defcustom message-citation-line-function 'message-insert-citation-line
963 "*Function called to insert the \"Whomever writes:\" line.
964
965 Predefined functions include `message-insert-citation-line' and
966 `message-insert-formatted-citation-line' (see the variable
967 `message-citation-line-format').
968
969 Note that Gnus provides a feature where the reader can click on
970 `writes:' to hide the cited text. If you change this line too much,
971 people who read your message will have to change their Gnus
972 configuration. See the variable `gnus-cite-attribution-suffix'."
973 :type '(choice
974 (function-item :tag "plain" message-insert-citation-line)
975 (function-item :tag "formatted" message-insert-formatted-citation-line)
976 (function :tag "Other"))
977 :link '(custom-manual "(message)Insertion Variables")
978 :group 'message-insertion)
979
980 (defcustom message-citation-line-format "On %a, %b %d %Y, %N wrote:\n"
981 "Format of the \"Whomever writes:\" line.
982
983 The string is formatted using `format-spec'. The following constructs
984 are replaced:
985
986 %f The full From, e.g. \"John Doe <john.doe@example.invalid>\".
987 %n The mail address, e.g. \"john.doe@example.invalid\".
988 %N The real name if present, e.g.: \"John Doe\", else fall
989 back to the mail address.
990 %F The first name if present, e.g.: \"John\", else fall
991 back to the mail address.
992 %L The last name if present, e.g.: \"Doe\".
993 %Z, %z The time zone in the numeric form, e.g.:\"+0000\".
994
995 All other format specifiers are passed to `format-time-string'
996 which is called using the date from the article your replying to, but
997 the date in the formatted string will be expressed in the author's
998 time zone as much as possible.
999 Extracting the first (%F) and last name (%L) is done heuristically,
1000 so you should always check it yourself.
1001
1002 Please also read the note in the documentation of
1003 `message-citation-line-function'."
1004 :type '(choice (const :tag "Plain" "%f writes:")
1005 (const :tag "Include date" "On %a, %b %d %Y, %n wrote:")
1006 string)
1007 :link '(custom-manual "(message)Insertion Variables")
1008 :version "23.1" ;; No Gnus
1009 :group 'message-insertion)
1010
1011 (defcustom message-yank-prefix mail-yank-prefix
1012 "*Prefix inserted on the lines of yanked messages.
1013 Fix `message-cite-prefix-regexp' if it is set to an abnormal value.
1014 See also `message-yank-cited-prefix' and `message-yank-empty-prefix'."
1015 :version "23.2"
1016 :type 'string
1017 :link '(custom-manual "(message)Insertion Variables")
1018 :group 'message-insertion)
1019
1020 (defcustom message-yank-cited-prefix ">"
1021 "*Prefix inserted on cited lines of yanked messages.
1022 Fix `message-cite-prefix-regexp' if it is set to an abnormal value.
1023 See also `message-yank-prefix' and `message-yank-empty-prefix'."
1024 :version "22.1"
1025 :type 'string
1026 :link '(custom-manual "(message)Insertion Variables")
1027 :group 'message-insertion)
1028
1029 (defcustom message-yank-empty-prefix ">"
1030 "*Prefix inserted on empty lines of yanked messages.
1031 See also `message-yank-prefix' and `message-yank-cited-prefix'."
1032 :version "22.1"
1033 :type 'string
1034 :link '(custom-manual "(message)Insertion Variables")
1035 :group 'message-insertion)
1036
1037 (defcustom message-indentation-spaces mail-indentation-spaces
1038 "*Number of spaces to insert at the beginning of each cited line.
1039 Used by `message-yank-original' via `message-yank-cite'."
1040 :version "23.2"
1041 :group 'message-insertion
1042 :link '(custom-manual "(message)Insertion Variables")
1043 :type 'integer)
1044
1045 (defcustom message-cite-function 'message-cite-original-without-signature
1046 "*Function for citing an original message.
1047 Predefined functions include `message-cite-original' and
1048 `message-cite-original-without-signature'.
1049 Note that these functions use `mail-citation-hook' if that is non-nil."
1050 :type '(radio (function-item message-cite-original)
1051 (function-item message-cite-original-without-signature)
1052 (function-item sc-cite-original)
1053 (function :tag "Other"))
1054 :link '(custom-manual "(message)Insertion Variables")
1055 :version "22.3" ;; Gnus 5.10.12 (changed default)
1056 :group 'message-insertion)
1057
1058 (defcustom message-indent-citation-function 'message-indent-citation
1059 "*Function for modifying a citation just inserted in the mail buffer.
1060 This can also be a list of functions. Each function can find the
1061 citation between (point) and (mark t). And each function should leave
1062 point and mark around the citation text as modified."
1063 :type 'function
1064 :link '(custom-manual "(message)Insertion Variables")
1065 :group 'message-insertion)
1066
1067 (defcustom message-signature mail-signature
1068 "*String to be inserted at the end of the message buffer.
1069 If t, the `message-signature-file' file will be inserted instead.
1070 If a function, the result from the function will be used instead.
1071 If a form, the result from the form will be used instead."
1072 :version "23.2"
1073 :type '(choice string (const :tag "Contents of signature file" t)
1074 function
1075 sexp)
1076 :risky t
1077 :link '(custom-manual "(message)Insertion Variables")
1078 :group 'message-insertion)
1079
1080 (defcustom message-signature-file mail-signature-file
1081 "*Name of file containing the text inserted at end of message buffer.
1082 Ignored if the named file doesn't exist.
1083 If nil, don't insert a signature.
1084 If a path is specified, the value of `message-signature-directory' is ignored,
1085 even if set."
1086 :version "23.2"
1087 :type '(choice file (const :tags "None" nil))
1088 :link '(custom-manual "(message)Insertion Variables")
1089 :group 'message-insertion)
1090
1091 (defcustom message-signature-directory nil
1092 "*Name of directory containing signature files.
1093 Comes in handy if you have many such files, handled via posting styles for
1094 instance.
1095 If nil, `message-signature-file' is expected to specify the directory if
1096 needed."
1097 :type '(choice string (const :tags "None" nil))
1098 :link '(custom-manual "(message)Insertion Variables")
1099 :group 'message-insertion)
1100
1101 (defcustom message-signature-insert-empty-line t
1102 "*If non-nil, insert an empty line before the signature separator."
1103 :version "22.1"
1104 :type 'boolean
1105 :link '(custom-manual "(message)Insertion Variables")
1106 :group 'message-insertion)
1107
1108 (defcustom message-cite-reply-position 'traditional
1109 "*Where the reply should be positioned.
1110 If `traditional', reply inline.
1111 If `above', reply above quoted text.
1112 If `below', reply below quoted text.
1113
1114 Note: Many newsgroups frown upon nontraditional reply styles. You
1115 probably want to set this variable only for specific groups,
1116 e.g. using `gnus-posting-styles':
1117
1118 (eval (set (make-local-variable \\='message-cite-reply-position) \\='above))"
1119 :version "24.1"
1120 :type '(choice (const :tag "Reply inline" traditional)
1121 (const :tag "Reply above" above)
1122 (const :tag "Reply below" below))
1123 :group 'message-insertion)
1124
1125 (defcustom message-cite-style nil
1126 "*The overall style to be used when yanking cited text.
1127 Value is either nil (no variable overrides) or a let-style list
1128 of pairs (VARIABLE VALUE) that will be bound in
1129 `message-yank-original' to do the quoting.
1130
1131 Presets to impersonate popular mail agents are found in the
1132 message-cite-style-* variables. This variable is intended for
1133 use in `gnus-posting-styles', such as:
1134
1135 ((posting-from-work-p) (eval (set (make-local-variable \\='message-cite-style) message-cite-style-outlook)))"
1136 :version "24.1"
1137 :group 'message-insertion
1138 :type '(choice (const :tag "Do not override variables" :value nil)
1139 (const :tag "MS Outlook" :value message-cite-style-outlook)
1140 (const :tag "Mozilla Thunderbird" :value message-cite-style-thunderbird)
1141 (const :tag "Gmail" :value message-cite-style-gmail)
1142 (variable :tag "User-specified")))
1143
1144 (defconst message-cite-style-outlook
1145 '((message-cite-function 'message-cite-original)
1146 (message-citation-line-function 'message-insert-formatted-citation-line)
1147 (message-cite-reply-position 'above)
1148 (message-yank-prefix "")
1149 (message-yank-cited-prefix "")
1150 (message-yank-empty-prefix "")
1151 (message-citation-line-format "\n\n-----------------------\nOn %a, %b %d %Y, %N wrote:\n"))
1152 "Message citation style used by MS Outlook. Use with message-cite-style.")
1153
1154 (defconst message-cite-style-thunderbird
1155 '((message-cite-function 'message-cite-original)
1156 (message-citation-line-function 'message-insert-formatted-citation-line)
1157 (message-cite-reply-position 'above)
1158 (message-yank-prefix "> ")
1159 (message-yank-cited-prefix ">")
1160 (message-yank-empty-prefix ">")
1161 (message-citation-line-format "On %D %R %p, %N wrote:"))
1162 "Message citation style used by Mozilla Thunderbird. Use with message-cite-style.")
1163
1164 (defconst message-cite-style-gmail
1165 '((message-cite-function 'message-cite-original)
1166 (message-citation-line-function 'message-insert-formatted-citation-line)
1167 (message-cite-reply-position 'above)
1168 (message-yank-prefix " ")
1169 (message-yank-cited-prefix " ")
1170 (message-yank-empty-prefix " ")
1171 (message-citation-line-format "On %e %B %Y %R, %f wrote:\n"))
1172 "Message citation style used by Gmail. Use with message-cite-style.")
1173
1174 (defcustom message-distribution-function nil
1175 "*Function called to return a Distribution header."
1176 :group 'message-news
1177 :group 'message-headers
1178 :link '(custom-manual "(message)News Headers")
1179 :type '(choice function (const nil)))
1180
1181 (defcustom message-expires 14
1182 "Number of days before your article expires."
1183 :group 'message-news
1184 :group 'message-headers
1185 :link '(custom-manual "(message)News Headers")
1186 :type 'integer)
1187
1188 (defcustom message-user-path nil
1189 "If nil, use the NNTP server name in the Path header.
1190 If stringp, use this; if non-nil, use no host name (user name only)."
1191 :group 'message-news
1192 :group 'message-headers
1193 :link '(custom-manual "(message)News Headers")
1194 :type '(choice (const :tag "nntp" nil)
1195 (string :tag "name")
1196 (sexp :tag "none" :format "%t" t)))
1197
1198 ;; This can be the name of a buffer, or a cons cell (FUNCTION . ARGS)
1199 ;; for yanking the original buffer.
1200 (defvar message-reply-buffer nil)
1201 (defvar message-reply-headers nil
1202 "The headers of the current replied article.
1203 It is a vector of the following headers:
1204 [number subject from date id references chars lines xref extra].")
1205 (defvar message-newsreader nil)
1206 (defvar message-mailer nil)
1207 (defvar message-sent-message-via nil)
1208 (defvar message-checksum nil)
1209 (defvar message-send-actions nil
1210 "A list of actions to be performed upon successful sending of a message.")
1211 (defvar message-return-action nil
1212 "Action to return to the caller after sending or postponing a message.")
1213 (defvar message-exit-actions nil
1214 "A list of actions to be performed upon exiting after sending a message.")
1215 (defvar message-kill-actions nil
1216 "A list of actions to be performed before killing a message buffer.")
1217 (defvar message-postpone-actions nil
1218 "A list of actions to be performed after postponing a message.")
1219
1220 (define-widget 'message-header-lines 'text
1221 "All header lines must be LFD terminated."
1222 :format "%{%t%}:%n%v"
1223 :valid-regexp "^\\'"
1224 :error "All header lines must be newline terminated")
1225
1226 (defcustom message-default-headers ""
1227 "Header lines to be inserted in outgoing messages.
1228 This can be set to a string containing or a function returning
1229 header lines to be inserted before you edit the message, so you
1230 can edit or delete these lines. If set to a function, it is
1231 called and its result is inserted."
1232 :version "23.2"
1233 :group 'message-headers
1234 :link '(custom-manual "(message)Message Headers")
1235 :type '(choice
1236 (message-header-lines :tag "String")
1237 (function :tag "Function")))
1238
1239 (defcustom message-default-mail-headers
1240 ;; Ease the transition from mail-mode to message-mode. See bugs#4431, 5555.
1241 (concat (if (and (boundp 'mail-default-reply-to)
1242 (stringp mail-default-reply-to))
1243 (format "Reply-to: %s\n" mail-default-reply-to))
1244 (if (and (boundp 'mail-self-blind)
1245 mail-self-blind)
1246 (format "BCC: %s\n" user-mail-address))
1247 (if (and (boundp 'mail-archive-file-name)
1248 (stringp mail-archive-file-name))
1249 (format "FCC: %s\n" mail-archive-file-name))
1250 mail-default-headers)
1251 "*A string of header lines to be inserted in outgoing mails."
1252 :version "23.2"
1253 :group 'message-headers
1254 :group 'message-mail
1255 :link '(custom-manual "(message)Mail Headers")
1256 :type 'message-header-lines)
1257
1258 (defcustom message-default-news-headers ""
1259 "*A string of header lines to be inserted in outgoing news articles."
1260 :group 'message-headers
1261 :group 'message-news
1262 :link '(custom-manual "(message)News Headers")
1263 :type 'message-header-lines)
1264
1265 ;; Note: could use /usr/ucb/mail instead of sendmail;
1266 ;; options -t, and -v if not interactive.
1267 (defcustom message-mailer-swallows-blank-line
1268 (if (and (string-match "sparc-sun-sunos\\(\\'\\|[^5]\\)"
1269 system-configuration)
1270 (file-readable-p "/etc/sendmail.cf")
1271 (with-temp-buffer
1272 (insert-file-contents "/etc/sendmail.cf")
1273 (goto-char (point-min))
1274 (let ((case-fold-search nil))
1275 (re-search-forward "^OR\\>" nil t))))
1276 ;; According to RFC822, "The field-name must be composed of printable
1277 ;; ASCII characters (i. e., characters that have decimal values between
1278 ;; 33 and 126, except colon)", i. e., any chars except ctl chars,
1279 ;; space, or colon.
1280 '(looking-at "[ \t]\\|[][!\"#$%&'()*+,-./0-9;<=>?@A-Z\\\\^_`a-z{|}~]+:"))
1281 "*Set this non-nil if the system's mailer runs the header and body together.
1282 \(This problem exists on Sunos 4 when sendmail is run in remote mode.)
1283 The value should be an expression to test whether the problem will
1284 actually occur."
1285 :group 'message-sending
1286 :link '(custom-manual "(message)Mail Variables")
1287 :risky t
1288 :type 'sexp)
1289
1290 ;;;###autoload
1291 (define-mail-user-agent 'message-user-agent
1292 'message-mail 'message-send-and-exit
1293 'message-kill-buffer 'message-send-hook)
1294
1295 (defvar message-mh-deletable-headers '(Message-ID Date Lines Sender)
1296 "If non-nil, delete the deletable headers before feeding to mh.")
1297
1298 (defvar message-send-method-alist
1299 '((news message-news-p message-send-via-news)
1300 (mail message-mail-p message-send-via-mail))
1301 "Alist of ways to send outgoing messages.
1302 Each element has the form
1303
1304 (TYPE PREDICATE FUNCTION)
1305
1306 where TYPE is a symbol that names the method; PREDICATE is a function
1307 called without any parameters to determine whether the message is
1308 a message of type TYPE; and FUNCTION is a function to be called if
1309 PREDICATE returns non-nil. FUNCTION is called with one parameter --
1310 the prefix.")
1311
1312 (defcustom message-mail-alias-type 'abbrev
1313 "*What alias expansion type to use in Message buffers.
1314 The default is `abbrev', which uses mailabbrev. `ecomplete' uses
1315 an electric completion mode. nil switches mail aliases off.
1316 This can also be a list of values."
1317 :group 'message
1318 :link '(custom-manual "(message)Mail Aliases")
1319 :type '(choice (const :tag "Use Mailabbrev" abbrev)
1320 (const :tag "Use ecomplete" ecomplete)
1321 (const :tag "No expansion" nil)))
1322
1323 (defcustom message-self-insert-commands '(self-insert-command)
1324 "List of `self-insert-command's used to trigger ecomplete.
1325 When one of those commands is invoked to enter a character in To or Cc
1326 header, ecomplete will suggest the candidates of recipients (see also
1327 `message-mail-alias-type'). If you use some tool to enter non-ASCII
1328 text and it replaces `self-insert-command' with the other command, e.g.
1329 `egg-self-insert-command', you may want to add it to this list."
1330 :group 'message-various
1331 :type '(repeat function))
1332
1333 (defcustom message-auto-save-directory
1334 (if (file-writable-p message-directory)
1335 (file-name-as-directory (expand-file-name "drafts" message-directory))
1336 "~/")
1337 "*Directory where Message auto-saves buffers if Gnus isn't running.
1338 If nil, Message won't auto-save."
1339 :group 'message-buffers
1340 :link '(custom-manual "(message)Various Message Variables")
1341 :type '(choice directory (const :tag "Don't auto-save" nil)))
1342
1343 (defcustom message-default-charset
1344 (and (not (mm-multibyte-p)) 'iso-8859-1)
1345 "Default charset used in non-MULE Emacsen.
1346 If nil, you might be asked to input the charset."
1347 :version "21.1"
1348 :group 'message
1349 :link '(custom-manual "(message)Various Message Variables")
1350 :type 'symbol)
1351
1352 (defcustom message-dont-reply-to-names mail-dont-reply-to-names
1353 "Addresses to prune when doing wide replies.
1354 This can be a regexp, a list of regexps or a predicate function.
1355 Also, a value of nil means exclude your own user name only.
1356
1357 If a function email is passed as the argument."
1358 :version "24.3"
1359 :group 'message
1360 :link '(custom-manual "(message)Wide Reply")
1361 :type '(choice (const :tag "Yourself" nil)
1362 regexp
1363 (repeat :tag "Regexp List" regexp)))
1364
1365 (defsubst message-dont-reply-to-names ()
1366 (cond ((functionp message-dont-reply-to-names)
1367 message-dont-reply-to-names)
1368 ((stringp message-dont-reply-to-names)
1369 (gmm-regexp-concat message-dont-reply-to-names))))
1370
1371 (defvar message-shoot-gnksa-feet nil
1372 "*A list of GNKSA feet you are allowed to shoot.
1373 Gnus gives you all the opportunity you could possibly want for
1374 shooting yourself in the foot. Also, Gnus allows you to shoot the
1375 feet of Good Net-Keeping Seal of Approval. The following are foot
1376 candidates:
1377 `empty-article' Allow you to post an empty article;
1378 `quoted-text-only' Allow you to post quoted text only;
1379 `multiple-copies' Allow you to post multiple copies;
1380 `cancel-messages' Allow you to cancel or supersede messages from
1381 your other email addresses;
1382 `canlock-verify' Allow you to cancel messages without verifying canlock.")
1383
1384 (defsubst message-gnksa-enable-p (feature)
1385 (or (not (listp message-shoot-gnksa-feet))
1386 (memq feature message-shoot-gnksa-feet)))
1387
1388 (defcustom message-hidden-headers '("^References:" "^Face:" "^X-Face:"
1389 "^X-Draft-From:")
1390 "Regexp of headers to be hidden when composing new messages.
1391 This can also be a list of regexps to match headers. Or a list
1392 starting with `not' and followed by regexps."
1393 :version "22.1"
1394 :group 'message
1395 :link '(custom-manual "(message)Message Headers")
1396 :type '(choice
1397 :format "%{%t%}: %[Value Type%] %v"
1398 (regexp :menu-tag "regexp" :format "regexp\n%t: %v")
1399 (repeat :menu-tag "(regexp ...)" :format "(regexp ...)\n%v%i"
1400 (regexp :format "%t: %v"))
1401 (cons :menu-tag "(not regexp ...)" :format "(not regexp ...)\n%v"
1402 (const not)
1403 (repeat :format "%v%i"
1404 (regexp :format "%t: %v")))))
1405
1406 (defcustom message-cite-articles-with-x-no-archive t
1407 "If non-nil, cite text from articles that has X-No-Archive set."
1408 :group 'message
1409 :type 'boolean)
1410
1411 ;;; Internal variables.
1412 ;;; Well, not really internal.
1413
1414 (defvar message-mode-syntax-table
1415 (let ((table (copy-syntax-table text-mode-syntax-table)))
1416 (modify-syntax-entry ?% ". " table)
1417 (modify-syntax-entry ?> ". " table)
1418 (modify-syntax-entry ?< ". " table)
1419 table)
1420 "Syntax table used while in Message mode.")
1421
1422 (defface message-header-to
1423 '((((class color)
1424 (background dark))
1425 (:foreground "DarkOliveGreen1" :bold t))
1426 (((class color)
1427 (background light))
1428 (:foreground "MidnightBlue" :bold t))
1429 (t
1430 (:bold t :italic t)))
1431 "Face used for displaying From headers."
1432 :group 'message-faces)
1433 ;; backward-compatibility alias
1434 (put 'message-header-to-face 'face-alias 'message-header-to)
1435 (put 'message-header-to-face 'obsolete-face "22.1")
1436
1437 (defface message-header-cc
1438 '((((class color)
1439 (background dark))
1440 (:foreground "chartreuse1" :bold t))
1441 (((class color)
1442 (background light))
1443 (:foreground "MidnightBlue"))
1444 (t
1445 (:bold t)))
1446 "Face used for displaying Cc headers."
1447 :group 'message-faces)
1448 ;; backward-compatibility alias
1449 (put 'message-header-cc-face 'face-alias 'message-header-cc)
1450 (put 'message-header-cc-face 'obsolete-face "22.1")
1451
1452 (defface message-header-subject
1453 '((((class color)
1454 (background dark))
1455 (:foreground "OliveDrab1"))
1456 (((class color)
1457 (background light))
1458 (:foreground "navy blue" :bold t))
1459 (t
1460 (:bold t)))
1461 "Face used for displaying subject headers."
1462 :group 'message-faces)
1463 ;; backward-compatibility alias
1464 (put 'message-header-subject-face 'face-alias 'message-header-subject)
1465 (put 'message-header-subject-face 'obsolete-face "22.1")
1466
1467 (defface message-header-newsgroups
1468 '((((class color)
1469 (background dark))
1470 (:foreground "yellow" :bold t :italic t))
1471 (((class color)
1472 (background light))
1473 (:foreground "blue4" :bold t :italic t))
1474 (t
1475 (:bold t :italic t)))
1476 "Face used for displaying newsgroups headers."
1477 :group 'message-faces)
1478 ;; backward-compatibility alias
1479 (put 'message-header-newsgroups-face 'face-alias 'message-header-newsgroups)
1480 (put 'message-header-newsgroups-face 'obsolete-face "22.1")
1481
1482 (defface message-header-other
1483 '((((class color)
1484 (background dark))
1485 (:foreground "VioletRed1"))
1486 (((class color)
1487 (background light))
1488 (:foreground "steel blue"))
1489 (t
1490 (:bold t :italic t)))
1491 "Face used for displaying newsgroups headers."
1492 :group 'message-faces)
1493 ;; backward-compatibility alias
1494 (put 'message-header-other-face 'face-alias 'message-header-other)
1495 (put 'message-header-other-face 'obsolete-face "22.1")
1496
1497 (defface message-header-name
1498 '((((class color)
1499 (background dark))
1500 (:foreground "green"))
1501 (((class color)
1502 (background light))
1503 (:foreground "cornflower blue"))
1504 (t
1505 (:bold t)))
1506 "Face used for displaying header names."
1507 :group 'message-faces)
1508 ;; backward-compatibility alias
1509 (put 'message-header-name-face 'face-alias 'message-header-name)
1510 (put 'message-header-name-face 'obsolete-face "22.1")
1511
1512 (defface message-header-xheader
1513 '((((class color)
1514 (background dark))
1515 (:foreground "DeepSkyBlue1"))
1516 (((class color)
1517 (background light))
1518 (:foreground "blue"))
1519 (t
1520 (:bold t)))
1521 "Face used for displaying X-Header headers."
1522 :group 'message-faces)
1523 ;; backward-compatibility alias
1524 (put 'message-header-xheader-face 'face-alias 'message-header-xheader)
1525 (put 'message-header-xheader-face 'obsolete-face "22.1")
1526
1527 (defface message-separator
1528 '((((class color)
1529 (background dark))
1530 (:foreground "LightSkyBlue1"))
1531 (((class color)
1532 (background light))
1533 (:foreground "brown"))
1534 (t
1535 (:bold t)))
1536 "Face used for displaying the separator."
1537 :group 'message-faces)
1538 ;; backward-compatibility alias
1539 (put 'message-separator-face 'face-alias 'message-separator)
1540 (put 'message-separator-face 'obsolete-face "22.1")
1541
1542 (defface message-cited-text
1543 '((((class color)
1544 (background dark))
1545 (:foreground "LightPink1"))
1546 (((class color)
1547 (background light))
1548 (:foreground "red"))
1549 (t
1550 (:bold t)))
1551 "Face used for displaying cited text names."
1552 :group 'message-faces)
1553 ;; backward-compatibility alias
1554 (put 'message-cited-text-face 'face-alias 'message-cited-text)
1555 (put 'message-cited-text-face 'obsolete-face "22.1")
1556
1557 (defface message-mml
1558 '((((class color)
1559 (background dark))
1560 (:foreground "MediumSpringGreen"))
1561 (((class color)
1562 (background light))
1563 (:foreground "ForestGreen"))
1564 (t
1565 (:bold t)))
1566 "Face used for displaying MML."
1567 :group 'message-faces)
1568 ;; backward-compatibility alias
1569 (put 'message-mml-face 'face-alias 'message-mml)
1570 (put 'message-mml-face 'obsolete-face "22.1")
1571
1572 (defun message-font-lock-make-header-matcher (regexp)
1573 (let ((form
1574 `(lambda (limit)
1575 (let ((start (point)))
1576 (save-restriction
1577 (widen)
1578 (goto-char (point-min))
1579 (if (re-search-forward
1580 (concat "^" (regexp-quote mail-header-separator) "$")
1581 nil t)
1582 (setq limit (min limit (match-beginning 0))))
1583 (goto-char start))
1584 (and (< start limit)
1585 (re-search-forward ,regexp limit t))))))
1586 (if (featurep 'bytecomp)
1587 (byte-compile form)
1588 form)))
1589
1590 (defvar message-font-lock-keywords
1591 (let ((content "[ \t]*\\(.+\\(\n[ \t].*\\)*\\)\n?"))
1592 `((,(message-font-lock-make-header-matcher
1593 (concat "^\\([Tt]o:\\)" content))
1594 (1 'message-header-name)
1595 (2 'message-header-to nil t))
1596 (,(message-font-lock-make-header-matcher
1597 (concat "^\\(^[GBF]?[Cc][Cc]:\\|^[Rr]eply-[Tt]o:\\)" content))
1598 (1 'message-header-name)
1599 (2 'message-header-cc nil t))
1600 (,(message-font-lock-make-header-matcher
1601 (concat "^\\([Ss]ubject:\\)" content))
1602 (1 'message-header-name)
1603 (2 'message-header-subject nil t))
1604 (,(message-font-lock-make-header-matcher
1605 (concat "^\\([Nn]ewsgroups:\\|Followup-[Tt]o:\\)" content))
1606 (1 'message-header-name)
1607 (2 'message-header-newsgroups nil t))
1608 (,(message-font-lock-make-header-matcher
1609 (concat "^\\(X-[A-Za-z0-9-]+:\\|In-Reply-To:\\)" content))
1610 (1 'message-header-name)
1611 (2 'message-header-xheader))
1612 (,(message-font-lock-make-header-matcher
1613 (concat "^\\([A-Z][^: \n\t]+:\\)" content))
1614 (1 'message-header-name)
1615 (2 'message-header-other nil t))
1616 ,@(if (and mail-header-separator
1617 (not (equal mail-header-separator "")))
1618 `((,(concat "^\\(" (regexp-quote mail-header-separator) "\\)$")
1619 1 'message-separator))
1620 nil)
1621 ((lambda (limit)
1622 (re-search-forward (concat "^\\("
1623 message-cite-prefix-regexp
1624 "\\).*")
1625 limit t))
1626 (0 'message-cited-text))
1627 ("<#/?\\(multipart\\|part\\|external\\|mml\\|secure\\)[^>]*>"
1628 (0 'message-mml))))
1629 "Additional expressions to highlight in Message mode.")
1630
1631 (defvar message-face-alist
1632 '((bold . message-bold-region)
1633 (underline . underline-region)
1634 (default . (lambda (b e)
1635 (message-unbold-region b e)
1636 (ununderline-region b e))))
1637 "Alist of mail and news faces for facemenu.
1638 The cdr of each entry is a function for applying the face to a region.")
1639
1640 (defcustom message-send-hook nil
1641 "Hook run before sending messages.
1642 This hook is run quite early when sending."
1643 :group 'message-various
1644 :options '(ispell-message)
1645 :link '(custom-manual "(message)Various Message Variables")
1646 :type 'hook)
1647
1648 (defcustom message-send-mail-hook nil
1649 "Hook run before sending mail messages.
1650 This hook is run very late -- just before the message is sent as
1651 mail."
1652 :group 'message-various
1653 :link '(custom-manual "(message)Various Message Variables")
1654 :type 'hook)
1655
1656 (defcustom message-send-news-hook nil
1657 "Hook run before sending news messages.
1658 This hook is run very late -- just before the message is sent as
1659 news."
1660 :group 'message-various
1661 :link '(custom-manual "(message)Various Message Variables")
1662 :type 'hook)
1663
1664 (defcustom message-sent-hook nil
1665 "Hook run after sending messages."
1666 :group 'message-various
1667 :type 'hook)
1668
1669 (defvar message-send-coding-system 'binary
1670 "Coding system to encode outgoing mail.")
1671
1672 (defvar message-draft-coding-system mm-auto-save-coding-system
1673 "Coding system to compose mail.")
1674
1675 (defcustom message-send-mail-partially-limit nil
1676 "The limitation of messages sent as message/partial.
1677 The lower bound of message size in characters, beyond which the message
1678 should be sent in several parts. If it is nil, the size is unlimited."
1679 :version "24.1"
1680 :group 'message-buffers
1681 :link '(custom-manual "(message)Mail Variables")
1682 :type '(choice (const :tag "unlimited" nil)
1683 (integer 1000000)))
1684
1685 (defcustom message-alternative-emails nil
1686 "*Regexp or predicate function matching alternative email addresses.
1687 The first address in the To, Cc or From headers of the original
1688 article matching this variable is used as the From field of
1689 outgoing messages.
1690
1691 If a function, an email string is passed as the argument.
1692
1693 This variable has precedence over posting styles and anything that runs
1694 off `message-setup-hook'."
1695 :group 'message-headers
1696 :link '(custom-manual "(message)Message Headers")
1697 :type '(choice (const :tag "Always use primary" nil)
1698 regexp
1699 function))
1700
1701 (defcustom message-hierarchical-addresses nil
1702 "A list of hierarchical mail address definitions.
1703
1704 Inside each entry, the first address is the \"top\" address, and
1705 subsequent addresses are subaddresses; this is used to indicate that
1706 mail sent to the first address will automatically be delivered to the
1707 subaddresses. So if the first address appears in the recipient list
1708 for a message, the subaddresses will be removed (if present) before
1709 the mail is sent. All addresses in this structure should be
1710 downcased."
1711 :version "22.1"
1712 :group 'message-headers
1713 :type '(repeat (repeat string)))
1714
1715 (defcustom message-mail-user-agent nil
1716 "Like `mail-user-agent'.
1717 Except if it is nil, use Gnus native MUA; if it is t, use
1718 `mail-user-agent'."
1719 :version "22.1"
1720 :type '(radio (const :tag "Gnus native"
1721 :format "%t\n"
1722 nil)
1723 (const :tag "`mail-user-agent'"
1724 :format "%t\n"
1725 t)
1726 (function-item :tag "Default Emacs mail"
1727 :format "%t\n"
1728 sendmail-user-agent)
1729 (function-item :tag "Emacs interface to MH"
1730 :format "%t\n"
1731 mh-e-user-agent)
1732 (function :tag "Other"))
1733 :version "21.1"
1734 :group 'message)
1735
1736 (defcustom message-wide-reply-confirm-recipients nil
1737 "Whether to confirm a wide reply to multiple email recipients.
1738 If this variable is nil, don't ask whether to reply to all recipients.
1739 If this variable is non-nil, pose the question \"Reply to all
1740 recipients?\" before a wide reply to multiple recipients. If the user
1741 answers yes, reply to all recipients as usual. If the user answers
1742 no, only reply back to the author."
1743 :version "22.1"
1744 :group 'message-headers
1745 :link '(custom-manual "(message)Wide Reply")
1746 :type 'boolean)
1747
1748 (defcustom message-user-fqdn nil
1749 "*Domain part of Message-Ids."
1750 :version "22.1"
1751 :group 'message-headers
1752 :link '(custom-manual "(message)News Headers")
1753 :type '(radio (const :format "%v " nil)
1754 (string :format "FQDN: %v")))
1755
1756 (defcustom message-use-idna
1757 (and (or (mm-coding-system-p 'utf-8)
1758 (condition-case nil
1759 (let (mucs-ignore-version-incompatibilities)
1760 (require 'un-define))
1761 (error)))
1762 (condition-case nil
1763 (require 'idna)
1764 (file-error)
1765 (invalid-operation))
1766 idna-program
1767 (executable-find idna-program)
1768 (string= (idna-to-ascii "räksmörgås") "xn--rksmrgs-5wao1o")
1769 t)
1770 "Whether to encode non-ASCII in domain names into ASCII according to IDNA.
1771 GNU Libidn, and in particular the elisp package \"idna.el\" and
1772 the external program \"idn\", must be installed for this
1773 functionality to work."
1774 :version "22.1"
1775 :group 'message-headers
1776 :link '(custom-manual "(message)IDNA")
1777 :type '(choice (const :tag "Ask" ask)
1778 (const :tag "Never" nil)
1779 (const :tag "Always" t)))
1780
1781 (defcustom message-generate-hashcash (if (executable-find "hashcash") 'opportunistic)
1782 "*Whether to generate X-Hashcash: headers.
1783 If t, always generate hashcash headers. If `opportunistic',
1784 only generate hashcash headers if it can be done without the user
1785 waiting (i.e., only asynchronously).
1786
1787 You must have the \"hashcash\" binary installed, see `hashcash-path'."
1788 :version "24.1"
1789 :group 'message-headers
1790 :link '(custom-manual "(message)Mail Headers")
1791 :type '(choice (const :tag "Always" t)
1792 (const :tag "Never" nil)
1793 (const :tag "Opportunistic" opportunistic)))
1794
1795 ;;; Internal variables.
1796
1797 (defvar message-sending-message "Sending...")
1798 (defvar message-buffer-list nil)
1799 (defvar message-this-is-news nil)
1800 (defvar message-this-is-mail nil)
1801 (defvar message-draft-article nil)
1802 (defvar message-mime-part nil)
1803 (defvar message-posting-charset nil)
1804 (defvar message-inserted-headers nil)
1805 (defvar message-inhibit-ecomplete nil)
1806
1807 ;; Byte-compiler warning
1808 (defvar gnus-active-hashtb)
1809 (defvar gnus-read-active-file)
1810
1811 ;;; Regexp matching the delimiter of messages in UNIX mail format
1812 ;;; (UNIX From lines), minus the initial ^. It should be a copy
1813 ;;; of rmail.el's rmail-unix-mail-delimiter.
1814 (defvar message-unix-mail-delimiter
1815 (let ((time-zone-regexp
1816 (concat "\\([A-Z]?[A-Z]?[A-Z][A-Z]\\( DST\\)?"
1817 "\\|[-+]?[0-9][0-9][0-9][0-9]"
1818 "\\|"
1819 "\\) *")))
1820 (concat
1821 "From "
1822
1823 ;; Many things can happen to an RFC 822 mailbox before it is put into
1824 ;; a `From' line. The leading phrase can be stripped, e.g.
1825 ;; `Joe <@w.x:joe@y.z>' -> `<@w.x:joe@y.z>'. The <> can be stripped, e.g.
1826 ;; `<@x.y:joe@y.z>' -> `@x.y:joe@y.z'. Everything starting with a CRLF
1827 ;; can be removed, e.g.
1828 ;; From: joe@y.z (Joe K
1829 ;; User)
1830 ;; can yield `From joe@y.z (Joe K Fri Mar 22 08:11:15 1996', and
1831 ;; From: Joe User
1832 ;; <joe@y.z>
1833 ;; can yield `From Joe User Fri Mar 22 08:11:15 1996'.
1834 ;; The mailbox can be removed or be replaced by white space, e.g.
1835 ;; From: "Joe User"{space}{tab}
1836 ;; <joe@y.z>
1837 ;; can yield `From {space}{tab} Fri Mar 22 08:11:15 1996',
1838 ;; where {space} and {tab} represent the Ascii space and tab characters.
1839 ;; We want to match the results of any of these manglings.
1840 ;; The following regexp rejects names whose first characters are
1841 ;; obviously bogus, but after that anything goes.
1842 "\\([^\0-\b\n-\r\^?].*\\)?"
1843
1844 ;; The time the message was sent.
1845 "\\([^\0-\r \^?]+\\) +" ; day of the week
1846 "\\([^\0-\r \^?]+\\) +" ; month
1847 "\\([0-3]?[0-9]\\) +" ; day of month
1848 "\\([0-2][0-9]:[0-5][0-9]\\(:[0-6][0-9]\\)?\\) *" ; time of day
1849
1850 ;; Perhaps a time zone, specified by an abbreviation, or by a
1851 ;; numeric offset.
1852 time-zone-regexp
1853
1854 ;; The year.
1855 " \\([0-9][0-9]+\\) *"
1856
1857 ;; On some systems the time zone can appear after the year, too.
1858 time-zone-regexp
1859
1860 ;; Old uucp cruft.
1861 "\\(remote from .*\\)?"
1862
1863 "\n"))
1864 "Regexp matching the delimiter of messages in UNIX mail format.")
1865
1866 (defvar message-unsent-separator
1867 (concat "^ *---+ +Unsent message follows +---+ *$\\|"
1868 "^ *---+ +Returned message +---+ *$\\|"
1869 "^Start of returned message$\\|"
1870 "^ *---+ +Original message +---+ *$\\|"
1871 "^ *--+ +begin message +--+ *$\\|"
1872 "^ *---+ +Original message follows +---+ *$\\|"
1873 "^ *---+ +Undelivered message follows +---+ *$\\|"
1874 "^------ This is a copy of the message, including all the headers. ------ *$\\|"
1875 "^|? *---+ +Message text follows: +---+ *|?$")
1876 "A regexp that matches the separator before the text of a failed message.")
1877
1878 (defvar message-field-fillers
1879 '((To message-fill-field-address)
1880 (Cc message-fill-field-address)
1881 (From message-fill-field-address))
1882 "Alist of header names/filler functions.")
1883
1884 (defvar message-header-format-alist
1885 `((From)
1886 (Newsgroups)
1887 (To)
1888 (Cc)
1889 (Subject)
1890 (In-Reply-To)
1891 (Fcc)
1892 (Bcc)
1893 (Date)
1894 (Organization)
1895 (Distribution)
1896 (Lines)
1897 (Expires)
1898 (Message-ID)
1899 (References . message-shorten-references)
1900 (User-Agent))
1901 "Alist used for formatting headers.")
1902
1903 (defvar message-options nil
1904 "Some saved answers when sending message.")
1905 (make-variable-buffer-local 'message-options)
1906
1907 (defvar message-send-mail-real-function nil
1908 "Internal send mail function.")
1909
1910 (defvar message-bogus-system-names "\\`localhost\\.\\|\\.local\\'"
1911 "The regexp of bogus system names.")
1912
1913 (autoload 'gnus-alive-p "gnus-util")
1914 (autoload 'gnus-delay-article "gnus-delay")
1915 (autoload 'gnus-extract-address-components "gnus-util")
1916 (autoload 'gnus-find-method-for-group "gnus")
1917 (autoload 'gnus-group-decoded-name "gnus-group")
1918 (autoload 'gnus-group-name-charset "gnus-group")
1919 (autoload 'gnus-group-name-decode "gnus-group")
1920 (autoload 'gnus-groups-from-server "gnus")
1921 (autoload 'gnus-open-server "gnus-int")
1922 (autoload 'gnus-output-to-mail "gnus-util")
1923 (autoload 'gnus-output-to-rmail "gnus-util")
1924 (autoload 'gnus-request-post "gnus-int")
1925 (autoload 'gnus-server-string "gnus")
1926 (autoload 'idna-to-ascii "idna")
1927 (autoload 'message-setup-toolbar "messagexmas")
1928 (autoload 'mh-new-draft-name "mh-comp")
1929 (autoload 'mh-send-letter "mh-comp")
1930 (autoload 'nndraft-request-associate-buffer "nndraft")
1931 (autoload 'nndraft-request-expire-articles "nndraft")
1932 (autoload 'nnvirtual-find-group-art "nnvirtual")
1933 (autoload 'rmail-msg-is-pruned "rmail")
1934 (autoload 'rmail-output "rmailout")
1935
1936 (defun message-kill-all-overlays ()
1937 (mapcar #'delete-overlay (overlays-in (point-min) (point-max))))
1938
1939 \f
1940
1941 ;;;
1942 ;;; Utility functions.
1943 ;;;
1944
1945 (defmacro message-y-or-n-p (question show &rest text)
1946 "Ask QUESTION, displaying remaining args in a temporary buffer if SHOW."
1947 `(message-talkative-question 'y-or-n-p ,question ,show ,@text))
1948
1949 (defmacro message-delete-line (&optional n)
1950 "Delete the current line (and the next N lines)."
1951 `(delete-region (progn (beginning-of-line) (point))
1952 (progn (forward-line ,(or n 1)) (point))))
1953
1954 (defun message-mark-active-p ()
1955 "Non-nil means the mark and region are currently active in this buffer."
1956 mark-active)
1957
1958 (defun message-unquote-tokens (elems)
1959 "Remove double quotes (\") from strings in list ELEMS."
1960 (mapcar (lambda (item)
1961 (while (string-match "^\\(.*\\)\"\\(.*\\)$" item)
1962 (setq item (concat (match-string 1 item)
1963 (match-string 2 item))))
1964 item)
1965 elems))
1966
1967 (defun message-tokenize-header (header &optional separator)
1968 "Split HEADER into a list of header elements.
1969 SEPARATOR is a string of characters to be used as separators. \",\"
1970 is used by default."
1971 (if (not header)
1972 nil
1973 (let ((regexp (format "[%s]+" (or separator ",")))
1974 (first t)
1975 beg quoted elems paren)
1976 (with-temp-buffer
1977 (mm-enable-multibyte)
1978 (setq beg (point-min))
1979 (insert header)
1980 (goto-char (point-min))
1981 (while (not (eobp))
1982 (if first
1983 (setq first nil)
1984 (forward-char 1))
1985 (cond ((and (> (point) beg)
1986 (or (eobp)
1987 (and (looking-at regexp)
1988 (not quoted)
1989 (not paren))))
1990 (push (buffer-substring beg (point)) elems)
1991 (setq beg (match-end 0)))
1992 ((eq (char-after) ?\")
1993 (setq quoted (not quoted)))
1994 ((and (eq (char-after) ?\()
1995 (not quoted))
1996 (setq paren t))
1997 ((and (eq (char-after) ?\))
1998 (not quoted))
1999 (setq paren nil))))
2000 (nreverse elems)))))
2001
2002 (autoload 'nnheader-insert-file-contents "nnheader")
2003
2004 (defun message-mail-file-mbox-p (file)
2005 "Say whether FILE looks like a Unix mbox file."
2006 (when (and (file-exists-p file)
2007 (file-readable-p file)
2008 (file-regular-p file))
2009 (with-temp-buffer
2010 (nnheader-insert-file-contents file)
2011 (goto-char (point-min))
2012 (looking-at message-unix-mail-delimiter))))
2013
2014 (defun message-fetch-field (header &optional not-all)
2015 "The same as `mail-fetch-field', only remove all newlines.
2016 The buffer is expected to be narrowed to just the header of the message;
2017 see `message-narrow-to-headers-or-head'."
2018 (let* ((inhibit-point-motion-hooks t)
2019 (value (mail-fetch-field header nil (not not-all))))
2020 (when value
2021 (while (string-match "\n[\t ]+" value)
2022 (setq value (replace-match " " t t value)))
2023 value)))
2024
2025 (defun message-field-value (header &optional not-all)
2026 "The same as `message-fetch-field', only narrow to the headers first."
2027 (save-excursion
2028 (save-restriction
2029 (message-narrow-to-headers-or-head)
2030 (message-fetch-field header not-all))))
2031
2032 (defun message-narrow-to-field ()
2033 "Narrow the buffer to the header on the current line."
2034 (beginning-of-line)
2035 (while (looking-at "[ \t]")
2036 (forward-line -1))
2037 (narrow-to-region
2038 (point)
2039 (progn
2040 (forward-line 1)
2041 (if (re-search-forward "^[^ \n\t]" nil t)
2042 (point-at-bol)
2043 (point-max))))
2044 (goto-char (point-min)))
2045
2046 (defun message-add-header (&rest headers)
2047 "Add the HEADERS to the message header, skipping those already present."
2048 (while headers
2049 (let (hclean)
2050 (unless (string-match "^\\([^:]+\\):[ \t]*[^ \t]" (car headers))
2051 (error "Invalid header `%s'" (car headers)))
2052 (setq hclean (match-string 1 (car headers)))
2053 (save-restriction
2054 (message-narrow-to-headers)
2055 (unless (re-search-forward (concat "^" (regexp-quote hclean) ":") nil t)
2056 (goto-char (point-max))
2057 (if (string-match "\n$" (car headers))
2058 (insert (car headers))
2059 (insert (car headers) ?\n)))))
2060 (setq headers (cdr headers))))
2061
2062 (defmacro message-with-reply-buffer (&rest forms)
2063 "Evaluate FORMS in the reply buffer, if it exists."
2064 `(when (and (bufferp message-reply-buffer)
2065 (buffer-name message-reply-buffer))
2066 (with-current-buffer message-reply-buffer
2067 ,@forms)))
2068
2069 (put 'message-with-reply-buffer 'lisp-indent-function 0)
2070 (put 'message-with-reply-buffer 'edebug-form-spec '(body))
2071
2072 (defun message-fetch-reply-field (header)
2073 "Fetch field HEADER from the message we're replying to."
2074 (message-with-reply-buffer
2075 (save-restriction
2076 (mail-narrow-to-head)
2077 (message-fetch-field header))))
2078
2079 (defun message-strip-list-identifiers (subject)
2080 "Remove list identifiers in `gnus-list-identifiers' from string SUBJECT."
2081 (require 'gnus-sum) ; for gnus-list-identifiers
2082 (let ((regexp (if (stringp gnus-list-identifiers)
2083 gnus-list-identifiers
2084 (mapconcat 'identity gnus-list-identifiers " *\\|"))))
2085 (if (string-match (concat "\\(\\(\\(Re: +\\)?\\(" regexp
2086 " *\\)\\)+\\(Re: +\\)?\\)") subject)
2087 (concat (substring subject 0 (match-beginning 1))
2088 (or (match-string 3 subject)
2089 (match-string 5 subject))
2090 (substring subject
2091 (match-end 1)))
2092 subject)))
2093
2094 (defun message-strip-subject-re (subject)
2095 "Remove \"Re:\" from subject lines in string SUBJECT."
2096 (if (string-match message-subject-re-regexp subject)
2097 (substring subject (match-end 0))
2098 subject))
2099
2100 (defcustom message-replacement-char "."
2101 "Replacement character used instead of unprintable or not decodable chars."
2102 :group 'message-various
2103 :version "22.1" ;; Gnus 5.10.9
2104 :type '(choice string
2105 (const ".")
2106 (const "?")))
2107
2108 ;; FIXME: We also should call `message-strip-subject-encoded-words'
2109 ;; when forwarding. Probably in `message-make-forward-subject' and
2110 ;; `message-forward-make-body'.
2111
2112 (defun message-strip-subject-encoded-words (subject)
2113 "Fix non-decodable words in SUBJECT."
2114 ;; Cf. `gnus-simplify-subject-fully'.
2115 (let* ((case-fold-search t)
2116 (replacement-chars (format "[%s%s%s]"
2117 message-replacement-char
2118 message-replacement-char
2119 message-replacement-char))
2120 (enc-word-re "=\\?\\([^?]+\\)\\?\\([QB]\\)\\?\\([^?]+\\)\\(\\?=\\)")
2121 cs-string
2122 (have-marker
2123 (with-temp-buffer
2124 (insert subject)
2125 (goto-char (point-min))
2126 (when (re-search-forward enc-word-re nil t)
2127 (setq cs-string (match-string 1)))))
2128 cs-coding q-or-b word-beg word-end)
2129 (if (or (not have-marker) ;; No encoded word found...
2130 ;; ... or double encoding was correct:
2131 (and (stringp cs-string)
2132 (setq cs-string (downcase cs-string))
2133 (mm-coding-system-p (intern cs-string))
2134 (not (prog1
2135 (y-or-n-p
2136 (format "\
2137 Decoded Subject \"%s\"
2138 contains a valid encoded word. Decode again? "
2139 subject))
2140 (setq cs-coding (intern cs-string))))))
2141 subject
2142 (with-temp-buffer
2143 (insert subject)
2144 (goto-char (point-min))
2145 (while (re-search-forward enc-word-re nil t)
2146 (setq cs-string (downcase (match-string 1))
2147 q-or-b (match-string 2)
2148 word-beg (match-beginning 0)
2149 word-end (match-end 0))
2150 (setq cs-coding
2151 (if (mm-coding-system-p (intern cs-string))
2152 (setq cs-coding (intern cs-string))
2153 nil))
2154 ;; No double encoded subject? => bogus charset.
2155 (unless cs-coding
2156 (setq cs-coding
2157 (read-coding-system
2158 (format-message "\
2159 Decoded Subject \"%s\"
2160 contains an encoded word. The charset `%s' is unknown or invalid.
2161 Hit RET to replace non-decodable characters with \"%s\" or enter replacement
2162 charset: "
2163 subject cs-string message-replacement-char)))
2164 (if cs-coding
2165 (replace-match (concat "=?" (symbol-name cs-coding)
2166 "?\\2?\\3\\4\\5"))
2167 (save-excursion
2168 (goto-char word-beg)
2169 (re-search-forward "=\\?\\([^?]+\\)\\?\\([QB]\\)\\?" word-end t)
2170 (replace-match "")
2171 ;; QP or base64
2172 (if (string-match "\\`Q\\'" q-or-b)
2173 ;; QP
2174 (progn
2175 (message "Replacing non-decodable characters with \"%s\"."
2176 message-replacement-char)
2177 (while (re-search-forward "\\(=[A-F0-9][A-F0-9]\\)+"
2178 word-end t)
2179 (replace-match message-replacement-char)))
2180 ;; base64
2181 (message "Replacing non-decodable characters with \"%s\"."
2182 replacement-chars)
2183 (re-search-forward "[^?]+" word-end t)
2184 (replace-match replacement-chars))
2185 (re-search-forward "\\?=")
2186 (replace-match "")))))
2187 (rfc2047-decode-region (point-min) (point-max))
2188 (buffer-string)))))
2189
2190 ;;; Start of functions adopted from `message-utils.el'.
2191
2192 (defun message-strip-subject-trailing-was (subject)
2193 "Remove trailing \"(was: <old subject>)\" from SUBJECT lines.
2194 Leading \"Re: \" is not stripped by this function. Use the function
2195 `message-strip-subject-re' for this."
2196 (let* ((query message-subject-trailing-was-query)
2197 (new) (found))
2198 (setq found
2199 (string-match
2200 (if (eq query 'ask)
2201 message-subject-trailing-was-ask-regexp
2202 message-subject-trailing-was-regexp)
2203 subject))
2204 (if found
2205 (setq new (substring subject 0 (match-beginning 0))))
2206 (if (or (not found) (eq query nil))
2207 subject
2208 (if (eq query 'ask)
2209 (if (message-y-or-n-p
2210 "Strip `(was: <old subject>)' in subject? " t
2211 (concat
2212 "Strip `(was: <old subject>)' in subject "
2213 "and use the new one instead?\n\n"
2214 "Current subject is: \""
2215 subject "\"\n\n"
2216 "New subject would be: \""
2217 new "\"\n\n"
2218 "See the variable `message-subject-trailing-was-query' "
2219 "to get rid of this query."
2220 ))
2221 new subject)
2222 new))))
2223
2224 ;;; Suggested by Jonas Steverud @ www.dtek.chalmers.se/~d4jonas/
2225
2226 (defun message-change-subject (new-subject)
2227 "Ask for NEW-SUBJECT header, append (was: <Old Subject>)."
2228 (interactive
2229 (list
2230 (read-from-minibuffer "New subject: ")))
2231 (cond ((and (not (or (null new-subject) ; new subject not empty
2232 (zerop (string-width new-subject))
2233 (string-match "^[ \t]*$" new-subject))))
2234 (save-excursion
2235 (let ((old-subject
2236 (save-restriction
2237 (message-narrow-to-headers)
2238 (message-fetch-field "Subject"))))
2239 (cond ((not old-subject)
2240 (error "No current subject"))
2241 ((not (string-match
2242 (concat "^[ \t]*"
2243 (regexp-quote new-subject)
2244 "[ \t]*$")
2245 old-subject)) ; yes, it really is a new subject
2246 ;; delete eventual Re: prefix
2247 (setq old-subject
2248 (message-strip-subject-re old-subject))
2249 (message-goto-subject)
2250 (message-delete-line)
2251 (insert (concat "Subject: "
2252 new-subject
2253 " (was: "
2254 old-subject ")\n")))))))))
2255
2256 (defun message-mark-inserted-region (beg end &optional verbatim)
2257 "Mark some region in the current article with enclosing tags.
2258 See `message-mark-insert-begin' and `message-mark-insert-end'.
2259 If VERBATIM, use slrn style verbatim marks (\"#v+\" and \"#v-\")."
2260 (interactive "r\nP")
2261 (save-excursion
2262 ;; add to the end of the region first, otherwise end would be invalid
2263 (goto-char end)
2264 (insert (if verbatim "#v-\n" message-mark-insert-end))
2265 (goto-char beg)
2266 (insert (if verbatim "#v+\n" message-mark-insert-begin))))
2267
2268 (defun message-mark-insert-file (file &optional verbatim)
2269 "Insert FILE at point, marking it with enclosing tags.
2270 See `message-mark-insert-begin' and `message-mark-insert-end'.
2271 If VERBATIM, use slrn style verbatim marks (\"#v+\" and \"#v-\")."
2272 (interactive "fFile to insert: \nP")
2273 ;; reverse insertion to get correct result.
2274 (let ((p (point)))
2275 (insert (if verbatim "#v-\n" message-mark-insert-end))
2276 (goto-char p)
2277 (insert-file-contents file)
2278 (goto-char p)
2279 (insert (if verbatim "#v+\n" message-mark-insert-begin))))
2280
2281 (defun message-add-archive-header ()
2282 "Insert \"X-No-Archive: Yes\" in the header and a note in the body.
2283 The note can be customized using `message-archive-note'. When called with a
2284 prefix argument, ask for a text to insert. If you don't want the note in the
2285 body, set `message-archive-note' to nil."
2286 (interactive)
2287 (if current-prefix-arg
2288 (setq message-archive-note
2289 (read-from-minibuffer "Reason for No-Archive: "
2290 (cons message-archive-note 0))))
2291 (save-excursion
2292 (if (message-goto-signature)
2293 (re-search-backward message-signature-separator))
2294 (when message-archive-note
2295 (insert message-archive-note)
2296 (newline))
2297 (message-add-header message-archive-header)
2298 (message-sort-headers)))
2299
2300 (defun message-cross-post-followup-to-header (target-group)
2301 "Mangles FollowUp-To and Newsgroups header to point to TARGET-GROUP.
2302 With prefix-argument just set Follow-Up, don't cross-post."
2303 (interactive
2304 (list ; Completion based on Gnus
2305 (completing-read "Followup To: "
2306 (if (boundp 'gnus-newsrc-alist)
2307 gnus-newsrc-alist)
2308 nil nil '("poster" . 0)
2309 (if (boundp 'gnus-group-history)
2310 'gnus-group-history))))
2311 (message-remove-header "Follow[Uu]p-[Tt]o" t)
2312 (message-goto-newsgroups)
2313 (beginning-of-line)
2314 ;; if we already did a crosspost before, kill old target
2315 (if (and message-cross-post-old-target
2316 (re-search-forward
2317 (regexp-quote (concat "," message-cross-post-old-target))
2318 nil t))
2319 (replace-match ""))
2320 ;; unless (followup is to poster or user explicitly asked not
2321 ;; to cross-post, or target-group is already in Newsgroups)
2322 ;; add target-group to Newsgroups line.
2323 (cond ((and (or
2324 ;; def: cross-post, req:no
2325 (and message-cross-post-default (not current-prefix-arg))
2326 ;; def: no-cross-post, req:yes
2327 (and (not message-cross-post-default) current-prefix-arg))
2328 (not (string-match "poster" target-group))
2329 (not (string-match (regexp-quote target-group)
2330 (message-fetch-field "Newsgroups"))))
2331 (end-of-line)
2332 (insert (concat "," target-group))))
2333 (end-of-line) ; ensure Followup: comes after Newsgroups:
2334 ;; unless new followup would be identical to Newsgroups line
2335 ;; make a new Followup-To line
2336 (if (not (string-match (concat "^[ \t]*"
2337 target-group
2338 "[ \t]*$")
2339 (message-fetch-field "Newsgroups")))
2340 (insert (concat "\nFollowup-To: " target-group)))
2341 (setq message-cross-post-old-target target-group))
2342
2343 (defun message-cross-post-insert-note (target-group cross-post in-old
2344 old-groups)
2345 "Insert a in message body note about a set Followup or Crosspost.
2346 If there have been previous notes, delete them. TARGET-GROUP specifies the
2347 group to Followup-To. When CROSS-POST is t, insert note about
2348 crossposting. IN-OLD specifies whether TARGET-GROUP is a member of
2349 OLD-GROUPS. OLD-GROUPS lists the old-groups the posting would have
2350 been made to before the user asked for a Crosspost."
2351 ;; start scanning body for previous uses
2352 (message-goto-signature)
2353 (let ((head (re-search-backward
2354 (concat "^" mail-header-separator)
2355 nil t))) ; just search in body
2356 (message-goto-signature)
2357 (while (re-search-backward
2358 (concat "^" (regexp-quote message-cross-post-note) ".*")
2359 head t)
2360 (message-delete-line))
2361 (message-goto-signature)
2362 (while (re-search-backward
2363 (concat "^" (regexp-quote message-followup-to-note) ".*")
2364 head t)
2365 (message-delete-line))
2366 ;; insert new note
2367 (if (message-goto-signature)
2368 (re-search-backward message-signature-separator))
2369 (if (or in-old
2370 (not cross-post)
2371 (string-match "^[ \t]*poster[ \t]*$" target-group))
2372 (insert (concat message-followup-to-note target-group "\n"))
2373 (insert (concat message-cross-post-note target-group "\n")))))
2374
2375 (defun message-cross-post-followup-to (target-group)
2376 "Crossposts message and set Followup-To to TARGET-GROUP.
2377 With prefix-argument just set Follow-Up, don't cross-post."
2378 (interactive
2379 (list ; Completion based on Gnus
2380 (completing-read "Followup To: "
2381 (if (boundp 'gnus-newsrc-alist)
2382 gnus-newsrc-alist)
2383 nil nil '("poster" . 0)
2384 (if (boundp 'gnus-group-history)
2385 'gnus-group-history))))
2386 (when (fboundp 'gnus-group-real-name)
2387 (setq target-group (gnus-group-real-name target-group)))
2388 (cond ((not (or (null target-group) ; new subject not empty
2389 (zerop (string-width target-group))
2390 (string-match "^[ \t]*$" target-group)))
2391 (save-excursion
2392 (let* ((old-groups (message-fetch-field "Newsgroups"))
2393 (in-old (string-match
2394 (regexp-quote target-group)
2395 (or old-groups ""))))
2396 ;; check whether target exactly matches old Newsgroups
2397 (cond ((not old-groups)
2398 (error "No current newsgroup"))
2399 ((or (not in-old)
2400 (not (string-match
2401 (concat "^[ \t]*"
2402 (regexp-quote target-group)
2403 "[ \t]*$")
2404 old-groups)))
2405 ;; yes, Newsgroups line must change
2406 (message-cross-post-followup-to-header target-group)
2407 ;; insert note whether we do cross-post or followup-to
2408 (funcall message-cross-post-note-function
2409 target-group
2410 (if (or (and message-cross-post-default
2411 (not current-prefix-arg))
2412 (and (not message-cross-post-default)
2413 current-prefix-arg)) t)
2414 in-old old-groups))))))))
2415
2416 ;;; Reduce To: to Cc: or Bcc: header
2417
2418 (defun message-reduce-to-to-cc ()
2419 "Replace contents of To: header with contents of Cc: or Bcc: header."
2420 (interactive)
2421 (let ((cc-content
2422 (save-restriction (message-narrow-to-headers)
2423 (message-fetch-field "cc")))
2424 (bcc nil))
2425 (if (and (not cc-content)
2426 (setq cc-content
2427 (save-restriction
2428 (message-narrow-to-headers)
2429 (message-fetch-field "bcc"))))
2430 (setq bcc t))
2431 (cond (cc-content
2432 (save-excursion
2433 (message-goto-to)
2434 (message-delete-line)
2435 (insert (concat "To: " cc-content "\n"))
2436 (save-restriction
2437 (message-narrow-to-headers)
2438 (message-remove-header (if bcc
2439 "bcc"
2440 "cc"))))))))
2441
2442 ;;; End of functions adopted from `message-utils.el'.
2443
2444 (defun message-remove-header (header &optional is-regexp first reverse)
2445 "Remove HEADER in the narrowed buffer.
2446 If IS-REGEXP, HEADER is a regular expression.
2447 If FIRST, only remove the first instance of the header.
2448 If REVERSE, remove headers that doesn't match HEADER.
2449 Return the number of headers removed."
2450 (goto-char (point-min))
2451 (let ((regexp (if is-regexp header (concat "^" (regexp-quote header) ":")))
2452 (number 0)
2453 (case-fold-search t)
2454 last)
2455 (while (and (not (eobp))
2456 (not last))
2457 (if (if reverse
2458 (not (looking-at regexp))
2459 (looking-at regexp))
2460 (progn
2461 (incf number)
2462 (when first
2463 (setq last t))
2464 (delete-region
2465 (point)
2466 ;; There might be a continuation header, so we have to search
2467 ;; until we find a new non-continuation line.
2468 (progn
2469 (forward-line 1)
2470 (if (re-search-forward "^[^ \t]" nil t)
2471 (goto-char (match-beginning 0))
2472 (point-max)))))
2473 (forward-line 1)
2474 (if (re-search-forward "^[^ \t]" nil t)
2475 (goto-char (match-beginning 0))
2476 (goto-char (point-max)))))
2477 number))
2478
2479 (defun message-remove-first-header (header)
2480 "Remove the first instance of HEADER if there is more than one."
2481 (let ((count 0)
2482 (regexp (concat "^" (regexp-quote header) ":")))
2483 (save-excursion
2484 (goto-char (point-min))
2485 (while (re-search-forward regexp nil t)
2486 (incf count)))
2487 (while (> count 1)
2488 (message-remove-header header nil t)
2489 (decf count))))
2490
2491 (defun message-narrow-to-headers ()
2492 "Narrow the buffer to the head of the message."
2493 (widen)
2494 (narrow-to-region
2495 (goto-char (point-min))
2496 (if (re-search-forward
2497 (concat "^" (regexp-quote mail-header-separator) "\n") nil t)
2498 (match-beginning 0)
2499 (point-max)))
2500 (goto-char (point-min)))
2501
2502 (defun message-narrow-to-head-1 ()
2503 "Like `message-narrow-to-head'. Don't widen."
2504 (narrow-to-region
2505 (goto-char (point-min))
2506 (if (search-forward "\n\n" nil 1)
2507 (1- (point))
2508 (point-max)))
2509 (goto-char (point-min)))
2510
2511 ;; FIXME: clarify difference: message-narrow-to-head,
2512 ;; message-narrow-to-headers-or-head, message-narrow-to-headers
2513 (defun message-narrow-to-head ()
2514 "Narrow the buffer to the head of the message.
2515 Point is left at the beginning of the narrowed-to region."
2516 (widen)
2517 (message-narrow-to-head-1))
2518
2519 (defun message-narrow-to-headers-or-head ()
2520 "Narrow the buffer to the head of the message."
2521 (widen)
2522 (narrow-to-region
2523 (goto-char (point-min))
2524 (if (re-search-forward (concat "\\(\n\\)\n\\|^\\("
2525 (regexp-quote mail-header-separator)
2526 "\n\\)")
2527 nil t)
2528 (or (match-end 1) (match-beginning 2))
2529 (point-max)))
2530 (goto-char (point-min)))
2531
2532 (defun message-news-p ()
2533 "Say whether the current buffer contains a news message."
2534 (and (not message-this-is-mail)
2535 (or message-this-is-news
2536 (save-excursion
2537 (save-restriction
2538 (message-narrow-to-headers)
2539 (and (message-fetch-field "newsgroups")
2540 (not (message-fetch-field "posted-to"))))))))
2541
2542 (defun message-mail-p ()
2543 "Say whether the current buffer contains a mail message."
2544 (and (not message-this-is-news)
2545 (or message-this-is-mail
2546 (save-excursion
2547 (save-restriction
2548 (message-narrow-to-headers)
2549 (or (message-fetch-field "to")
2550 (message-fetch-field "cc")
2551 (message-fetch-field "bcc")))))))
2552
2553 (defun message-subscribed-p ()
2554 "Say whether we need to insert a MFT header."
2555 (or message-subscribed-regexps
2556 message-subscribed-addresses
2557 message-subscribed-address-file
2558 message-subscribed-address-functions))
2559
2560 (defun message-next-header ()
2561 "Go to the beginning of the next header."
2562 (beginning-of-line)
2563 (or (eobp) (forward-char 1))
2564 (not (if (re-search-forward "^[^ \t]" nil t)
2565 (beginning-of-line)
2566 (goto-char (point-max)))))
2567
2568 (defun message-sort-headers-1 ()
2569 "Sort the buffer as headers using `message-rank' text props."
2570 (goto-char (point-min))
2571 (require 'sort)
2572 (sort-subr
2573 nil 'message-next-header
2574 (lambda ()
2575 (message-next-header)
2576 (unless (bobp)
2577 (forward-char -1)))
2578 (lambda ()
2579 (or (get-text-property (point) 'message-rank)
2580 10000))))
2581
2582 (defun message-sort-headers ()
2583 "Sort the headers of the current message according to `message-header-format-alist'."
2584 (interactive)
2585 (save-excursion
2586 (save-restriction
2587 (let ((max (1+ (length message-header-format-alist)))
2588 rank)
2589 (message-narrow-to-headers)
2590 (while (re-search-forward "^[^ \n]+:" nil t)
2591 (put-text-property
2592 (match-beginning 0) (1+ (match-beginning 0))
2593 'message-rank
2594 (if (setq rank (length (memq (assq (intern (buffer-substring
2595 (match-beginning 0)
2596 (1- (match-end 0))))
2597 message-header-format-alist)
2598 message-header-format-alist)))
2599 (- max rank)
2600 (1+ max)))))
2601 (message-sort-headers-1))))
2602
2603 (defun message-kill-address ()
2604 "Kill the address under point."
2605 (interactive)
2606 (let ((start (point)))
2607 (message-skip-to-next-address)
2608 (kill-region start (if (bolp) (1- (point)) (point)))))
2609
2610
2611 (autoload 'Info-goto-node "info")
2612 (defvar mml2015-use)
2613
2614 (defun message-info (&optional arg)
2615 "Display the Message manual.
2616
2617 Prefixed with one \\[universal-argument], display the Emacs MIME
2618 manual. With two \\[universal-argument]'s, display the EasyPG or
2619 PGG manual, depending on the value of `mml2015-use'."
2620 (interactive "p")
2621 (info (format "(%s)Top"
2622 (cond ((eq arg 16)
2623 (require 'mml2015)
2624 mml2015-use)
2625 ((eq arg 4) 'emacs-mime)
2626 ;; `booleanp' only available in Emacs 22+
2627 ((and (not (memq arg '(nil t)))
2628 (symbolp arg))
2629 arg)
2630 (t
2631 'message)))))
2632
2633 \f
2634
2635 ;;;
2636 ;;; Message mode
2637 ;;;
2638
2639 ;;; Set up keymap.
2640
2641 (defvar message-mode-map nil)
2642
2643 (unless message-mode-map
2644 (setq message-mode-map (make-keymap))
2645 (set-keymap-parent message-mode-map text-mode-map)
2646 (define-key message-mode-map "\C-c?" 'describe-mode)
2647
2648 (define-key message-mode-map "\C-c\C-f\C-t" 'message-goto-to)
2649 (define-key message-mode-map "\C-c\C-f\C-o" 'message-goto-from)
2650 (define-key message-mode-map "\C-c\C-f\C-b" 'message-goto-bcc)
2651 (define-key message-mode-map "\C-c\C-f\C-w" 'message-goto-fcc)
2652 (define-key message-mode-map "\C-c\C-f\C-c" 'message-goto-cc)
2653 (define-key message-mode-map "\C-c\C-f\C-s" 'message-goto-subject)
2654 (define-key message-mode-map "\C-c\C-f\C-r" 'message-goto-reply-to)
2655 (define-key message-mode-map "\C-c\C-f\C-n" 'message-goto-newsgroups)
2656 (define-key message-mode-map "\C-c\C-f\C-d" 'message-goto-distribution)
2657 (define-key message-mode-map "\C-c\C-f\C-f" 'message-goto-followup-to)
2658 (define-key message-mode-map "\C-c\C-f\C-m" 'message-goto-mail-followup-to)
2659 (define-key message-mode-map "\C-c\C-f\C-k" 'message-goto-keywords)
2660 (define-key message-mode-map "\C-c\C-f\C-u" 'message-goto-summary)
2661 (define-key message-mode-map "\C-c\C-f\C-i"
2662 'message-insert-or-toggle-importance)
2663 (define-key message-mode-map "\C-c\C-f\C-a"
2664 'message-generate-unsubscribed-mail-followup-to)
2665
2666 ;; modify headers (and insert notes in body)
2667 (define-key message-mode-map "\C-c\C-fs" 'message-change-subject)
2668 ;;
2669 (define-key message-mode-map "\C-c\C-fx" 'message-cross-post-followup-to)
2670 ;; prefix+message-cross-post-followup-to = same w/o cross-post
2671 (define-key message-mode-map "\C-c\C-ft" 'message-reduce-to-to-cc)
2672 (define-key message-mode-map "\C-c\C-fa" 'message-add-archive-header)
2673 ;; mark inserted text
2674 (define-key message-mode-map "\C-c\M-m" 'message-mark-inserted-region)
2675 (define-key message-mode-map "\C-c\M-f" 'message-mark-insert-file)
2676
2677 (define-key message-mode-map "\C-c\C-b" 'message-goto-body)
2678 (define-key message-mode-map "\C-c\C-i" 'message-goto-signature)
2679
2680 (define-key message-mode-map "\C-c\C-t" 'message-insert-to)
2681 (define-key message-mode-map "\C-c\C-fw" 'message-insert-wide-reply)
2682 (define-key message-mode-map "\C-c\C-n" 'message-insert-newsgroups)
2683 (define-key message-mode-map "\C-c\C-l" 'message-to-list-only)
2684 (define-key message-mode-map "\C-c\C-f\C-e" 'message-insert-expires)
2685
2686 (define-key message-mode-map "\C-c\C-u" 'message-insert-or-toggle-importance)
2687 (define-key message-mode-map "\C-c\M-n"
2688 'message-insert-disposition-notification-to)
2689
2690 (define-key message-mode-map "\C-c\C-y" 'message-yank-original)
2691 (define-key message-mode-map "\C-c\M-\C-y" 'message-yank-buffer)
2692 (define-key message-mode-map "\C-c\C-q" 'message-fill-yanked-message)
2693 (define-key message-mode-map "\C-c\C-w" 'message-insert-signature)
2694 (define-key message-mode-map "\C-c\M-h" 'message-insert-headers)
2695 (define-key message-mode-map "\C-c\C-r" 'message-caesar-buffer-body)
2696 (define-key message-mode-map "\C-c\C-o" 'message-sort-headers)
2697 (define-key message-mode-map "\C-c\M-r" 'message-rename-buffer)
2698
2699 (define-key message-mode-map "\C-c\C-c" 'message-send-and-exit)
2700 (define-key message-mode-map "\C-c\C-s" 'message-send)
2701 (define-key message-mode-map "\C-c\C-k" 'message-kill-buffer)
2702 (define-key message-mode-map "\C-c\C-d" 'message-dont-send)
2703 (define-key message-mode-map "\C-c\n" 'gnus-delay-article)
2704
2705 (define-key message-mode-map "\C-c\M-k" 'message-kill-address)
2706 (define-key message-mode-map "\C-c\C-e" 'message-elide-region)
2707 (define-key message-mode-map "\C-c\C-v" 'message-delete-not-region)
2708 (define-key message-mode-map "\C-c\C-z" 'message-kill-to-signature)
2709 (define-key message-mode-map "\M-\r" 'message-newline-and-reformat)
2710 (define-key message-mode-map [remap split-line] 'message-split-line)
2711
2712 (define-key message-mode-map "\C-c\C-a" 'mml-attach-file)
2713
2714 (define-key message-mode-map "\C-a" 'message-beginning-of-line)
2715 (define-key message-mode-map "\t" 'message-tab)
2716
2717 (define-key message-mode-map "\M-n" 'message-display-abbrev))
2718
2719 (easy-menu-define
2720 message-mode-menu message-mode-map "Message Menu."
2721 `("Message"
2722 ["Yank Original" message-yank-original message-reply-buffer]
2723 ["Fill Yanked Message" message-fill-yanked-message t]
2724 ["Insert Signature" message-insert-signature t]
2725 ["Caesar (rot13) Message" message-caesar-buffer-body t]
2726 ["Caesar (rot13) Region" message-caesar-region (message-mark-active-p)]
2727 ["Elide Region" message-elide-region
2728 :active (message-mark-active-p)
2729 :help "Replace text in region with an ellipsis"]
2730 ["Delete Outside Region" message-delete-not-region
2731 :active (message-mark-active-p)
2732 :help "Delete all quoted text outside region"]
2733 ["Kill To Signature" message-kill-to-signature t]
2734 ["Newline and Reformat" message-newline-and-reformat t]
2735 ["Rename buffer" message-rename-buffer t]
2736 ["Spellcheck" ispell-message :help "Spellcheck this message"]
2737 "----"
2738 ["Insert Region Marked" message-mark-inserted-region
2739 :active (message-mark-active-p) :help "Mark region with enclosing tags"]
2740 ["Insert File Marked..." message-mark-insert-file
2741 :help "Insert file at point marked with enclosing tags"]
2742 "----"
2743 ["Send Message" message-send-and-exit :help "Send this message"]
2744 ["Postpone Message" message-dont-send
2745 :help "File this draft message and exit"]
2746 ["Send at Specific Time..." gnus-delay-article
2747 :help "Ask, then arrange to send message at that time"]
2748 ["Kill Message" message-kill-buffer
2749 :help "Delete this message without sending"]
2750 "----"
2751 ["Message manual" message-info :help "Display the Message manual"]))
2752
2753 (easy-menu-define
2754 message-mode-field-menu message-mode-map ""
2755 `("Field"
2756 ["To" message-goto-to t]
2757 ["From" message-goto-from t]
2758 ["Subject" message-goto-subject t]
2759 ["Change subject..." message-change-subject t]
2760 ["Cc" message-goto-cc t]
2761 ["Bcc" message-goto-bcc t]
2762 ["Fcc" message-goto-fcc t]
2763 ["Reply-To" message-goto-reply-to t]
2764 ["Flag As Important" message-insert-importance-high
2765 :help "Mark this message as important"]
2766 ["Flag As Unimportant" message-insert-importance-low
2767 :help "Mark this message as unimportant"]
2768 ["Request Receipt"
2769 message-insert-disposition-notification-to
2770 :help "Request a receipt notification"]
2771 "----"
2772 ;; (typical) news stuff
2773 ["Summary" message-goto-summary t]
2774 ["Keywords" message-goto-keywords t]
2775 ["Newsgroups" message-goto-newsgroups t]
2776 ["Fetch Newsgroups" message-insert-newsgroups t]
2777 ["Followup-To" message-goto-followup-to t]
2778 ;; ["Followup-To (with note in body)" message-cross-post-followup-to t]
2779 ["Crosspost / Followup-To..." message-cross-post-followup-to t]
2780 ["Distribution" message-goto-distribution t]
2781 ["Expires" message-insert-expires t ]
2782 ["X-No-Archive" message-add-archive-header t ]
2783 "----"
2784 ;; (typical) mailing-lists stuff
2785 ["Fetch To" message-insert-to
2786 :help "Insert a To header that points to the author."]
2787 ["Fetch To and Cc" message-insert-wide-reply
2788 :help "Insert To and Cc headers as if you were doing a wide reply."]
2789 "----"
2790 ["Send to list only" message-to-list-only t]
2791 ["Mail-Followup-To" message-goto-mail-followup-to t]
2792 ["Unsubscribed list post" message-generate-unsubscribed-mail-followup-to
2793 :help "Insert a reasonable `Mail-Followup-To:' header."]
2794 ["Reduce To: to Cc:" message-reduce-to-to-cc t]
2795 "----"
2796 ["Sort Headers" message-sort-headers t]
2797 ["Encode non-ASCII domain names" message-idna-to-ascii-rhs t]
2798 ;; We hide `message-hidden-headers' by narrowing the buffer.
2799 ["Show Hidden Headers" widen t]
2800 ["Goto Body" message-goto-body t]
2801 ["Goto Signature" message-goto-signature t]))
2802
2803 (defvar message-tool-bar-map nil)
2804
2805 (defvar facemenu-add-face-function)
2806 (defvar facemenu-remove-face-function)
2807
2808 ;;; Forbidden properties
2809 ;;
2810 ;; We use `after-change-functions' to keep special text properties
2811 ;; that interfere with the normal function of message mode out of the
2812 ;; buffer.
2813
2814 (defcustom message-strip-special-text-properties t
2815 "Strip special properties from the message buffer.
2816
2817 Emacs has a number of special text properties which can break message
2818 composing in various ways. If this option is set, message will strip
2819 these properties from the message composition buffer. However, some
2820 packages requires these properties to be present in order to work.
2821 If you use one of these packages, turn this option off, and hope the
2822 message composition doesn't break too bad."
2823 :version "22.1"
2824 :group 'message-various
2825 :link '(custom-manual "(message)Various Message Variables")
2826 :type 'boolean)
2827
2828 (defvar message-forbidden-properties
2829 ;; No reason this should be clutter up customize. We make it a
2830 ;; property list (rather than a list of property symbols), to be
2831 ;; directly useful for `remove-text-properties'.
2832 '(field nil read-only nil invisible nil intangible nil
2833 mouse-face nil modification-hooks nil insert-in-front-hooks nil
2834 insert-behind-hooks nil point-entered nil point-left nil)
2835 ;; Other special properties:
2836 ;; category, face, display: probably doesn't do any harm.
2837 ;; fontified: is used by font-lock.
2838 ;; syntax-table, local-map: I dunno.
2839 "Property list of with properties forbidden in message buffers.
2840 The values of the properties are ignored, only the property names are used.")
2841
2842 (defun message-tamago-not-in-use-p (pos)
2843 "Return t when tamago version 4 is not in use at the cursor position.
2844 Tamago version 4 is a popular input method for writing Japanese text.
2845 It uses the properties `intangible', `invisible', `modification-hooks'
2846 and `read-only' when translating ascii or kana text to kanji text.
2847 These properties are essential to work, so we should never strip them."
2848 (not (and (boundp 'egg-modefull-mode)
2849 (symbol-value 'egg-modefull-mode)
2850 (or (memq (get-text-property pos 'intangible)
2851 '(its-part-1 its-part-2))
2852 (get-text-property pos 'egg-end)
2853 (get-text-property pos 'egg-lang)
2854 (get-text-property pos 'egg-start)))))
2855
2856 (defsubst message-mail-alias-type-p (type)
2857 (if (atom message-mail-alias-type)
2858 (eq message-mail-alias-type type)
2859 (memq type message-mail-alias-type)))
2860
2861 (defun message-strip-forbidden-properties (begin end &optional old-length)
2862 "Strip forbidden properties between BEGIN and END, ignoring the third arg.
2863 This function is intended to be called from `after-change-functions'.
2864 See also `message-forbidden-properties'."
2865 (when (and (message-mail-alias-type-p 'ecomplete)
2866 (memq this-command message-self-insert-commands))
2867 (message-display-abbrev))
2868 (when (and message-strip-special-text-properties
2869 (message-tamago-not-in-use-p begin))
2870 (let ((buffer-read-only nil)
2871 (inhibit-read-only t))
2872 (remove-text-properties begin end message-forbidden-properties))))
2873
2874 (autoload 'ecomplete-setup "ecomplete") ;; for Emacs <23.
2875
2876 (defvar message-smileys '(":-)" ":)"
2877 ":-(" ":("
2878 ";-)" ";)")
2879 "A list of recognized smiley faces in `message-mode'.")
2880
2881 (defun message--syntax-propertize (beg end)
2882 "Syntax-propertize certain message text specially."
2883 (let ((citation-regexp (concat "^" message-cite-prefix-regexp ".*$"))
2884 (smiley-regexp (regexp-opt message-smileys)))
2885 (goto-char beg)
2886 (while (search-forward-regexp citation-regexp
2887 end 'noerror)
2888 (let ((start (match-beginning 0))
2889 (end (match-end 0)))
2890 (add-text-properties start (1+ start)
2891 `(syntax-table ,(string-to-syntax "<")))
2892 (add-text-properties end (min (1+ end) (point-max))
2893 `(syntax-table ,(string-to-syntax ">")))))
2894 (goto-char beg)
2895 (while (search-forward-regexp smiley-regexp
2896 end 'noerror)
2897 (add-text-properties (match-beginning 0) (match-end 0)
2898 `(syntax-table ,(string-to-syntax "."))))))
2899
2900 ;;;###autoload
2901 (define-derived-mode message-mode text-mode "Message"
2902 "Major mode for editing mail and news to be sent.
2903 Like Text Mode but with these additional commands:\\<message-mode-map>
2904 C-c C-s `message-send' (send the message) C-c C-c `message-send-and-exit'
2905 C-c C-d Postpone sending the message C-c C-k Kill the message
2906 C-c C-f move to a header field (and create it if there isn't):
2907 C-c C-f C-t move to To C-c C-f C-s move to Subject
2908 C-c C-f C-c move to Cc C-c C-f C-b move to Bcc
2909 C-c C-f C-w move to Fcc C-c C-f C-r move to Reply-To
2910 C-c C-f C-u move to Summary C-c C-f C-n move to Newsgroups
2911 C-c C-f C-k move to Keywords C-c C-f C-d move to Distribution
2912 C-c C-f C-o move to From (\"Originator\")
2913 C-c C-f C-f move to Followup-To
2914 C-c C-f C-m move to Mail-Followup-To
2915 C-c C-f C-e move to Expires
2916 C-c C-f C-i cycle through Importance values
2917 C-c C-f s change subject and append \"(was: <Old Subject>)\"
2918 C-c C-f x crossposting with FollowUp-To header and note in body
2919 C-c C-f t replace To: header with contents of Cc: or Bcc:
2920 C-c C-f a Insert X-No-Archive: header and a note in the body
2921 C-c C-t `message-insert-to' (add a To header to a news followup)
2922 C-c C-l `message-to-list-only' (removes all but list address in to/cc)
2923 C-c C-n `message-insert-newsgroups' (add a Newsgroup header to a news reply)
2924 C-c C-b `message-goto-body' (move to beginning of message text).
2925 C-c C-i `message-goto-signature' (move to the beginning of the signature).
2926 C-c C-w `message-insert-signature' (insert `message-signature-file' file).
2927 C-c C-y `message-yank-original' (insert current message, if any).
2928 C-c C-q `message-fill-yanked-message' (fill what was yanked).
2929 C-c C-e `message-elide-region' (elide the text between point and mark).
2930 C-c C-v `message-delete-not-region' (remove the text outside the region).
2931 C-c C-z `message-kill-to-signature' (kill the text up to the signature).
2932 C-c C-r `message-caesar-buffer-body' (rot13 the message body).
2933 C-c C-a `mml-attach-file' (attach a file as MIME).
2934 C-c C-u `message-insert-or-toggle-importance' (insert or cycle importance).
2935 C-c M-n `message-insert-disposition-notification-to' (request receipt).
2936 C-c M-m `message-mark-inserted-region' (mark region with enclosing tags).
2937 C-c M-f `message-mark-insert-file' (insert file marked with enclosing tags).
2938 M-RET `message-newline-and-reformat' (break the line and reformat)."
2939 (set (make-local-variable 'message-reply-buffer) nil)
2940 (set (make-local-variable 'message-inserted-headers) nil)
2941 (set (make-local-variable 'message-send-actions) nil)
2942 (set (make-local-variable 'message-return-action) nil)
2943 (set (make-local-variable 'message-exit-actions) nil)
2944 (set (make-local-variable 'message-kill-actions) nil)
2945 (set (make-local-variable 'message-postpone-actions) nil)
2946 (set (make-local-variable 'message-draft-article) nil)
2947 (setq buffer-offer-save t)
2948 (set (make-local-variable 'facemenu-add-face-function)
2949 (lambda (face end)
2950 (let ((face-fun (cdr (assq face message-face-alist))))
2951 (if face-fun
2952 (funcall face-fun (point) end)
2953 (error "Face %s not configured for %s mode" face mode-name)))
2954 ""))
2955 (set (make-local-variable 'facemenu-remove-face-function) t)
2956 (set (make-local-variable 'message-reply-headers) nil)
2957 (make-local-variable 'message-newsreader)
2958 (make-local-variable 'message-mailer)
2959 (make-local-variable 'message-post-method)
2960 (set (make-local-variable 'message-sent-message-via) nil)
2961 (set (make-local-variable 'message-checksum) nil)
2962 (set (make-local-variable 'message-mime-part) 0)
2963 (message-setup-fill-variables)
2964 (when message-fill-column
2965 (setq fill-column message-fill-column)
2966 (turn-on-auto-fill))
2967 ;; Allow using comment commands to add/remove quoting.
2968 ;; (set (make-local-variable 'comment-start) message-yank-prefix)
2969 (when message-yank-prefix
2970 (set (make-local-variable 'comment-start) message-yank-prefix)
2971 (set (make-local-variable 'comment-start-skip)
2972 (concat "^" (regexp-quote message-yank-prefix) "[ \t]*")))
2973 (set (make-local-variable 'font-lock-defaults)
2974 '(message-font-lock-keywords t))
2975 (if (boundp 'tool-bar-map)
2976 (set (make-local-variable 'tool-bar-map) (message-make-tool-bar)))
2977 (easy-menu-add message-mode-menu message-mode-map)
2978 (easy-menu-add message-mode-field-menu message-mode-map)
2979 ;; Mmmm... Forbidden properties...
2980 (add-hook 'after-change-functions 'message-strip-forbidden-properties
2981 nil 'local)
2982 ;; Allow mail alias things.
2983 (cond
2984 ((message-mail-alias-type-p 'abbrev)
2985 (mail-abbrevs-setup))
2986 ((message-mail-alias-type-p 'ecomplete)
2987 (ecomplete-setup)))
2988 (add-hook 'completion-at-point-functions 'message-completion-function nil t)
2989 (unless buffer-file-name
2990 (message-set-auto-save-file-name))
2991 (unless (buffer-base-buffer)
2992 ;; Don't enable multibyte on an indirect buffer. Maybe enabling
2993 ;; multibyte is not necessary at all. -- zsh
2994 (mm-enable-multibyte))
2995 (set (make-local-variable 'indent-tabs-mode) nil) ;No tabs for indentation.
2996 (mml-mode)
2997 ;; Syntactic fontification. Helps `show-paren-mode',
2998 ;; `electric-pair-mode', and C-M-* navigation by syntactically
2999 ;; excluding citations and other artifacts.
3000 ;;
3001 (set (make-local-variable 'syntax-propertize-function) 'message--syntax-propertize)
3002 (set (make-local-variable 'parse-sexp-ignore-comments) t))
3003
3004 (defun message-setup-fill-variables ()
3005 "Setup message fill variables."
3006 (set (make-local-variable 'fill-paragraph-function)
3007 'message-fill-paragraph)
3008 (make-local-variable 'paragraph-separate)
3009 (make-local-variable 'paragraph-start)
3010 (make-local-variable 'adaptive-fill-regexp)
3011 (make-local-variable 'adaptive-fill-first-line-regexp)
3012 (let ((quote-prefix-regexp
3013 ;; User should change message-cite-prefix-regexp if
3014 ;; message-yank-prefix is set to an abnormal value.
3015 (concat "\\(" message-cite-prefix-regexp "\\)[ \t]*")))
3016 (setq paragraph-start
3017 (concat
3018 (regexp-quote mail-header-separator) "$\\|"
3019 "[ \t]*$\\|" ; blank lines
3020 "-- $\\|" ; signature delimiter
3021 "---+$\\|" ; delimiters for forwarded messages
3022 page-delimiter "$\\|" ; spoiler warnings
3023 ".*wrote:$\\|" ; attribution lines
3024 quote-prefix-regexp "$\\|" ; empty lines in quoted text
3025 ; mml tags
3026 "<#!*/?\\(multipart\\|part\\|external\\|mml\\|secure\\)"))
3027 (setq paragraph-separate paragraph-start)
3028 (setq adaptive-fill-regexp
3029 (concat quote-prefix-regexp "\\|" adaptive-fill-regexp))
3030 (setq adaptive-fill-first-line-regexp
3031 (concat quote-prefix-regexp "\\|"
3032 adaptive-fill-first-line-regexp)))
3033 (make-local-variable 'auto-fill-inhibit-regexp)
3034 ;;(setq auto-fill-inhibit-regexp "^[A-Z][^: \n\t]+:")
3035 (setq auto-fill-inhibit-regexp nil)
3036 (make-local-variable 'normal-auto-fill-function)
3037 (setq normal-auto-fill-function 'message-do-auto-fill)
3038 ;; KLUDGE: auto fill might already be turned on in `text-mode-hook'.
3039 ;; In that case, ensure that it uses the right function. The real
3040 ;; solution would be not to use `define-derived-mode', and run
3041 ;; `text-mode-hook' ourself at the end of the mode.
3042 ;; -- Per Abrahamsen <abraham@dina.kvl.dk> Date: 2001-10-19.
3043 ;; This kludge is unneeded in Emacs>=21 since define-derived-mode is
3044 ;; now careful to run parent hooks after the body. --Stef
3045 (when auto-fill-function
3046 (setq auto-fill-function normal-auto-fill-function)))
3047
3048 \f
3049
3050 ;;;
3051 ;;; Message mode commands
3052 ;;;
3053
3054 ;;; Movement commands
3055
3056 (defun message-goto-to ()
3057 "Move point to the To header."
3058 (interactive)
3059 (push-mark)
3060 (message-position-on-field "To"))
3061
3062 (defun message-goto-from ()
3063 "Move point to the From header."
3064 (interactive)
3065 (push-mark)
3066 (message-position-on-field "From"))
3067
3068 (defun message-goto-subject ()
3069 "Move point to the Subject header."
3070 (interactive)
3071 (push-mark)
3072 (message-position-on-field "Subject"))
3073
3074 (defun message-goto-cc ()
3075 "Move point to the Cc header."
3076 (interactive)
3077 (push-mark)
3078 (message-position-on-field "Cc" "To"))
3079
3080 (defun message-goto-bcc ()
3081 "Move point to the Bcc header."
3082 (interactive)
3083 (push-mark)
3084 (message-position-on-field "Bcc" "Cc" "To"))
3085
3086 (defun message-goto-fcc ()
3087 "Move point to the Fcc header."
3088 (interactive)
3089 (push-mark)
3090 (message-position-on-field "Fcc" "To" "Newsgroups"))
3091
3092 (defun message-goto-reply-to ()
3093 "Move point to the Reply-To header."
3094 (interactive)
3095 (push-mark)
3096 (message-position-on-field "Reply-To" "Subject"))
3097
3098 (defun message-goto-newsgroups ()
3099 "Move point to the Newsgroups header."
3100 (interactive)
3101 (push-mark)
3102 (message-position-on-field "Newsgroups"))
3103
3104 (defun message-goto-distribution ()
3105 "Move point to the Distribution header."
3106 (interactive)
3107 (push-mark)
3108 (message-position-on-field "Distribution"))
3109
3110 (defun message-goto-followup-to ()
3111 "Move point to the Followup-To header."
3112 (interactive)
3113 (push-mark)
3114 (message-position-on-field "Followup-To" "Newsgroups"))
3115
3116 (defun message-goto-mail-followup-to ()
3117 "Move point to the Mail-Followup-To header."
3118 (interactive)
3119 (push-mark)
3120 (message-position-on-field "Mail-Followup-To" "To"))
3121
3122 (defun message-goto-keywords ()
3123 "Move point to the Keywords header."
3124 (interactive)
3125 (push-mark)
3126 (message-position-on-field "Keywords" "Subject"))
3127
3128 (defun message-goto-summary ()
3129 "Move point to the Summary header."
3130 (interactive)
3131 (push-mark)
3132 (message-position-on-field "Summary" "Subject"))
3133
3134 (defun message-goto-body ()
3135 "Move point to the beginning of the message body."
3136 (interactive)
3137 (when (and (called-interactively-p 'any)
3138 (looking-at "[ \t]*\n"))
3139 (expand-abbrev))
3140 (push-mark)
3141 (goto-char (point-min))
3142 (or (search-forward (concat "\n" mail-header-separator "\n") nil t)
3143 (search-forward-regexp "[^:]+:\\([^\n]\\|\n[ \t]\\)+\n\n" nil t)))
3144
3145 (defun message-in-body-p ()
3146 "Return t if point is in the message body."
3147 (>= (point)
3148 (save-excursion
3149 (goto-char (point-min))
3150 (or (search-forward (concat "\n" mail-header-separator "\n") nil t)
3151 (search-forward-regexp "[^:]+:\\([^\n]\\|\n[ \t]\\)+\n\n" nil t))
3152 (point))))
3153
3154 (defun message-goto-eoh ()
3155 "Move point to the end of the headers."
3156 (interactive)
3157 (message-goto-body)
3158 (forward-line -1))
3159
3160 (defun message-goto-signature ()
3161 "Move point to the beginning of the message signature.
3162 If there is no signature in the article, go to the end and
3163 return nil."
3164 (interactive)
3165 (push-mark)
3166 (goto-char (point-min))
3167 (if (re-search-forward message-signature-separator nil t)
3168 (forward-line 1)
3169 (goto-char (point-max))
3170 nil))
3171
3172 (defun message-generate-unsubscribed-mail-followup-to (&optional include-cc)
3173 "Insert a reasonable MFT header in a post to an unsubscribed list.
3174 When making original posts to a mailing list you are not subscribed to,
3175 you have to type in a MFT header by hand. The contents, usually, are
3176 the addresses of the list and your own address. This function inserts
3177 such a header automatically. It fetches the contents of the To: header
3178 in the current mail buffer, and appends the current `user-mail-address'.
3179
3180 If the optional argument INCLUDE-CC is non-nil, the addresses in the
3181 Cc: header are also put into the MFT."
3182
3183 (interactive "P")
3184 (let* (cc tos)
3185 (save-restriction
3186 (message-narrow-to-headers)
3187 (message-remove-header "Mail-Followup-To")
3188 (setq cc (and include-cc (message-fetch-field "Cc")))
3189 (setq tos (if cc
3190 (concat (message-fetch-field "To") "," cc)
3191 (message-fetch-field "To"))))
3192 (message-goto-mail-followup-to)
3193 (insert (concat tos ", " user-mail-address))))
3194
3195 \f
3196
3197 (defun message-insert-to (&optional force)
3198 "Insert a To header that points to the author of the article being replied to.
3199 If the original author requested not to be sent mail, don't insert unless the
3200 prefix FORCE is given."
3201 (interactive "P")
3202 (let* ((mct (message-fetch-reply-field "mail-copies-to"))
3203 (dont (and mct (or (equal (downcase mct) "never")
3204 (equal (downcase mct) "nobody"))))
3205 (to (or (message-fetch-reply-field "mail-reply-to")
3206 (message-fetch-reply-field "reply-to")
3207 (message-fetch-reply-field "from"))))
3208 (when (and dont to)
3209 (message
3210 (if force
3211 "Ignoring the user request not to have copies sent via mail"
3212 "Complying with the user request not to have copies sent via mail")))
3213 (when (and force (not to))
3214 (error "No mail address in the article"))
3215 (when (and to (or force (not dont)))
3216 (message-carefully-insert-headers (list (cons 'To to))))))
3217
3218 (defun message-insert-wide-reply ()
3219 "Insert To and Cc headers as if you were doing a wide reply."
3220 (interactive)
3221 (let ((headers (message-with-reply-buffer
3222 (message-get-reply-headers t))))
3223 (message-carefully-insert-headers headers)))
3224
3225 (defcustom message-header-synonyms
3226 '((To Cc Bcc)
3227 (Original-To))
3228 "List of lists of header synonyms.
3229 E.g., if this list contains a member list with elements `Cc' and `To',
3230 then `message-carefully-insert-headers' will not insert a `To' header
3231 when the message is already `Cc'ed to the recipient."
3232 :version "22.1"
3233 :group 'message-headers
3234 :link '(custom-manual "(message)Message Headers")
3235 :type '(repeat sexp))
3236
3237 (defun message-carefully-insert-headers (headers)
3238 "Insert the HEADERS, an alist, into the message buffer.
3239 Does not insert the headers when they are already present there
3240 or in the synonym headers, defined by `message-header-synonyms'."
3241 ;; FIXME: Should compare only the address and not the full name. Comparison
3242 ;; should be done case-folded (and with `string=' rather than
3243 ;; `string-match').
3244 ;; (mail-strip-quoted-names "Foo Bar <foo@bar>, bla@fasel (Bla Fasel)")
3245 (dolist (header headers)
3246 (let* ((header-name (symbol-name (car header)))
3247 (new-header (cdr header))
3248 (synonyms (loop for synonym in message-header-synonyms
3249 when (memq (car header) synonym) return synonym))
3250 (old-header
3251 (loop for synonym in synonyms
3252 for old-header = (mail-fetch-field (symbol-name synonym))
3253 when (and old-header (string-match new-header old-header))
3254 return synonym)))
3255 (if old-header
3256 (message "already have `%s' in `%s'" new-header old-header)
3257 (when (and (message-position-on-field header-name)
3258 (setq old-header (mail-fetch-field header-name))
3259 (not (string-match "\\` *\\'" old-header)))
3260 (insert ", "))
3261 (insert new-header)))))
3262
3263 (defun message-widen-reply ()
3264 "Widen the reply to include maximum recipients."
3265 (interactive)
3266 (let ((follow-to
3267 (and (bufferp message-reply-buffer)
3268 (buffer-name message-reply-buffer)
3269 (with-current-buffer message-reply-buffer
3270 (message-get-reply-headers t)))))
3271 (save-excursion
3272 (save-restriction
3273 (message-narrow-to-headers)
3274 (dolist (elem follow-to)
3275 (message-remove-header (symbol-name (car elem)))
3276 (goto-char (point-min))
3277 (insert (symbol-name (car elem)) ": "
3278 (cdr elem) "\n"))))))
3279
3280 (defun message-insert-newsgroups ()
3281 "Insert the Newsgroups header from the article being replied to."
3282 (interactive)
3283 (let ((old-newsgroups (mail-fetch-field "newsgroups"))
3284 (new-newsgroups (message-fetch-reply-field "newsgroups"))
3285 (first t)
3286 insert-newsgroups)
3287 (message-position-on-field "Newsgroups")
3288 (cond
3289 ((not new-newsgroups)
3290 (error "No Newsgroups to insert"))
3291 ((not old-newsgroups)
3292 (insert new-newsgroups))
3293 (t
3294 (setq new-newsgroups (split-string new-newsgroups "[, ]+")
3295 old-newsgroups (split-string old-newsgroups "[, ]+"))
3296 (dolist (group new-newsgroups)
3297 (unless (member group old-newsgroups)
3298 (push group insert-newsgroups)))
3299 (if (null insert-newsgroups)
3300 (error "Newgroup%s already in the header"
3301 (if (> (length new-newsgroups) 1)
3302 "s" ""))
3303 (when old-newsgroups
3304 (setq first nil))
3305 (dolist (group insert-newsgroups)
3306 (unless first
3307 (insert ","))
3308 (setq first nil)
3309 (insert group)))))))
3310
3311 \f
3312
3313 ;;; Various commands
3314
3315 (defun message-delete-not-region (beg end)
3316 "Delete everything in the body of the current message outside of the region."
3317 (interactive "r")
3318 (let (citeprefix)
3319 (save-excursion
3320 (goto-char beg)
3321 ;; snarf citation prefix, if appropriate
3322 (unless (eq (point) (progn (beginning-of-line) (point)))
3323 (when (looking-at message-cite-prefix-regexp)
3324 (setq citeprefix (match-string 0))))
3325 (goto-char end)
3326 (delete-region (point) (if (not (message-goto-signature))
3327 (point)
3328 (forward-line -2)
3329 (point)))
3330 (insert "\n")
3331 (goto-char beg)
3332 (delete-region beg (progn (message-goto-body)
3333 (forward-line 2)
3334 (point)))
3335 (when citeprefix
3336 (insert citeprefix))))
3337 (when (message-goto-signature)
3338 (forward-line -2)))
3339
3340 (defun message-kill-to-signature (&optional arg)
3341 "Kill all text up to the signature.
3342 If a numeric argument or prefix arg is given, leave that number
3343 of lines before the signature intact."
3344 (interactive "P")
3345 (save-excursion
3346 (save-restriction
3347 (let ((point (point)))
3348 (narrow-to-region point (point-max))
3349 (message-goto-signature)
3350 (unless (eobp)
3351 (if (and arg (numberp arg))
3352 (forward-line (- -1 arg))
3353 (end-of-line -1)))
3354 (unless (= point (point))
3355 (kill-region point (point))
3356 (unless (bolp)
3357 (insert "\n")))))))
3358
3359 (defun message-newline-and-reformat (&optional arg not-break)
3360 "Insert four newlines, and then reformat if inside quoted text.
3361 Prefix arg means justify as well."
3362 (interactive (list (if current-prefix-arg 'full)))
3363 (let (quoted point beg end leading-space bolp fill-paragraph-function)
3364 (setq point (point))
3365 (beginning-of-line)
3366 (setq beg (point))
3367 (setq bolp (= beg point))
3368 ;; Find first line of the paragraph.
3369 (if not-break
3370 (while (and (not (eobp))
3371 (not (looking-at message-cite-prefix-regexp))
3372 (looking-at paragraph-start))
3373 (forward-line 1)))
3374 ;; Find the prefix
3375 (when (looking-at message-cite-prefix-regexp)
3376 (setq quoted (match-string 0))
3377 (goto-char (match-end 0))
3378 (looking-at "[ \t]*")
3379 (setq leading-space (match-string 0)))
3380 (if (and quoted
3381 (not not-break)
3382 (not bolp)
3383 (< (- point beg) (length quoted)))
3384 ;; break inside the cite prefix.
3385 (setq quoted nil
3386 end nil))
3387 (if quoted
3388 (progn
3389 (forward-line 1)
3390 (while (and (not (eobp))
3391 (not (looking-at paragraph-separate))
3392 (looking-at message-cite-prefix-regexp)
3393 (equal quoted (match-string 0)))
3394 (goto-char (match-end 0))
3395 (looking-at "[ \t]*")
3396 (if (> (length leading-space) (length (match-string 0)))
3397 (setq leading-space (match-string 0)))
3398 (forward-line 1))
3399 (setq end (point))
3400 (goto-char beg)
3401 (while (and (if (bobp) nil (forward-line -1) t)
3402 (not (looking-at paragraph-start))
3403 (looking-at message-cite-prefix-regexp)
3404 (equal quoted (match-string 0)))
3405 (setq beg (point))
3406 (goto-char (match-end 0))
3407 (looking-at "[ \t]*")
3408 (if (> (length leading-space) (length (match-string 0)))
3409 (setq leading-space (match-string 0)))))
3410 (while (and (not (eobp))
3411 (not (looking-at paragraph-separate))
3412 (not (looking-at message-cite-prefix-regexp)))
3413 (forward-line 1))
3414 (setq end (point))
3415 (goto-char beg)
3416 (while (and (if (bobp) nil (forward-line -1) t)
3417 (not (looking-at paragraph-start))
3418 (not (looking-at message-cite-prefix-regexp)))
3419 (setq beg (point))))
3420 (goto-char point)
3421 (save-restriction
3422 (narrow-to-region beg end)
3423 (if not-break
3424 (setq point nil)
3425 (if bolp
3426 (newline)
3427 (newline)
3428 (newline))
3429 (setq point (point))
3430 ;; (newline 2) doesn't mark both newline's as hard, so call
3431 ;; newline twice. -jas
3432 (newline)
3433 (newline)
3434 (delete-region (point) (re-search-forward "[ \t]*"))
3435 (when (and quoted (not bolp))
3436 (insert quoted leading-space)))
3437 (undo-boundary)
3438 (if quoted
3439 (let* ((adaptive-fill-regexp
3440 (regexp-quote (concat quoted leading-space)))
3441 (adaptive-fill-first-line-regexp
3442 adaptive-fill-regexp ))
3443 (fill-paragraph arg))
3444 (fill-paragraph arg))
3445 (if point (goto-char point)))))
3446
3447 (defun message-fill-paragraph (&optional arg)
3448 "Message specific function to fill a paragraph.
3449 This function is used as the value of `fill-paragraph-function' in
3450 Message buffers and is not meant to be called directly."
3451 (interactive (list (if current-prefix-arg 'full)))
3452 (if (message-point-in-header-p)
3453 (message-fill-field)
3454 (message-newline-and-reformat arg t))
3455 t)
3456
3457 (defun message-point-in-header-p ()
3458 "Return t if point is in the header."
3459 (save-excursion
3460 (save-restriction
3461 (widen)
3462 (let ((bound (+ (point-at-eol) 1)) case-fold-search)
3463 (goto-char (point-min))
3464 (not (search-forward (concat "\n" mail-header-separator "\n")
3465 bound t))))))
3466
3467 (defun message-do-auto-fill ()
3468 "Like `do-auto-fill', but don't fill in message header."
3469 (unless (message-point-in-header-p)
3470 (do-auto-fill)))
3471
3472 (defun message-insert-signature (&optional force)
3473 "Insert a signature. See documentation for variable `message-signature'."
3474 (interactive (list 0))
3475 (let* ((signature
3476 (cond
3477 ((and (null message-signature)
3478 (eq force 0))
3479 (save-excursion
3480 (goto-char (point-max))
3481 (not (re-search-backward message-signature-separator nil t))))
3482 ((and (null message-signature)
3483 force)
3484 t)
3485 ((functionp message-signature)
3486 (funcall message-signature))
3487 ((listp message-signature)
3488 (eval message-signature))
3489 (t message-signature)))
3490 signature-file)
3491 (setq signature
3492 (cond ((stringp signature)
3493 signature)
3494 ((and (eq t signature) message-signature-file)
3495 (setq signature-file
3496 (if (and message-signature-directory
3497 ;; don't actually use the signature directory
3498 ;; if message-signature-file contains a path.
3499 (not (file-name-directory
3500 message-signature-file)))
3501 (expand-file-name message-signature-file
3502 message-signature-directory)
3503 message-signature-file))
3504 (file-exists-p signature-file))))
3505 (when signature
3506 (goto-char (point-max))
3507 ;; Insert the signature.
3508 (unless (bolp)
3509 (newline))
3510 (when message-signature-insert-empty-line
3511 (newline))
3512 (insert "-- ")
3513 (newline)
3514 (if (eq signature t)
3515 (insert-file-contents signature-file)
3516 (insert signature))
3517 (goto-char (point-max))
3518 (or (bolp) (newline)))))
3519
3520 (defun message-insert-importance-high ()
3521 "Insert header to mark message as important."
3522 (interactive)
3523 (save-excursion
3524 (save-restriction
3525 (message-narrow-to-headers)
3526 (message-remove-header "Importance"))
3527 (message-goto-eoh)
3528 (insert "Importance: high\n")))
3529
3530 (defun message-insert-importance-low ()
3531 "Insert header to mark message as unimportant."
3532 (interactive)
3533 (save-excursion
3534 (save-restriction
3535 (message-narrow-to-headers)
3536 (message-remove-header "Importance"))
3537 (message-goto-eoh)
3538 (insert "Importance: low\n")))
3539
3540 (defun message-insert-or-toggle-importance ()
3541 "Insert a \"Importance: high\" header, or cycle through the header values.
3542 The three allowed values according to RFC 1327 are `high', `normal'
3543 and `low'."
3544 (interactive)
3545 (save-excursion
3546 (let ((new "high")
3547 cur)
3548 (save-restriction
3549 (message-narrow-to-headers)
3550 (when (setq cur (message-fetch-field "Importance"))
3551 (message-remove-header "Importance")
3552 (setq new (cond ((string= cur "high")
3553 "low")
3554 ((string= cur "low")
3555 "normal")
3556 (t
3557 "high")))))
3558 (message-goto-eoh)
3559 (insert (format "Importance: %s\n" new)))))
3560
3561 (defun message-insert-disposition-notification-to ()
3562 "Request a disposition notification (return receipt) to this message.
3563 Note that this should not be used in newsgroups."
3564 (interactive)
3565 (save-excursion
3566 (save-restriction
3567 (message-narrow-to-headers)
3568 (message-remove-header "Disposition-Notification-To"))
3569 (message-goto-eoh)
3570 (insert (format "Disposition-Notification-To: %s\n"
3571 (or (message-field-value "Reply-to")
3572 (message-field-value "From")
3573 (message-make-from))))))
3574
3575 (defun message-elide-region (b e)
3576 "Elide the text in the region.
3577 An ellipsis (from `message-elide-ellipsis') will be inserted where the
3578 text was killed."
3579 (interactive "r")
3580 (let ((lines (count-lines b e))
3581 (chars (- e b)))
3582 (kill-region b e)
3583 (insert (format-spec message-elide-ellipsis
3584 `((?l . ,lines)
3585 (?c . ,chars))))))
3586
3587 (defvar message-caesar-translation-table nil)
3588
3589 (defun message-caesar-region (b e &optional n)
3590 "Caesar rotate region B to E by N, default 13, for decrypting netnews."
3591 (interactive
3592 (list
3593 (min (point) (or (mark t) (point)))
3594 (max (point) (or (mark t) (point)))
3595 (when current-prefix-arg
3596 (prefix-numeric-value current-prefix-arg))))
3597
3598 (setq n (if (numberp n) (mod n 26) 13)) ;canonize N
3599 (unless (or (zerop n) ; no action needed for a rot of 0
3600 (= b e)) ; no region to rotate
3601 ;; We build the table, if necessary.
3602 (when (or (not message-caesar-translation-table)
3603 (/= (aref message-caesar-translation-table ?a) (+ ?a n)))
3604 (setq message-caesar-translation-table
3605 (message-make-caesar-translation-table n)))
3606 (translate-region b e message-caesar-translation-table)))
3607
3608 (defun message-make-caesar-translation-table (n)
3609 "Create a rot table with offset N."
3610 (let ((i -1)
3611 (table (make-string 256 0)))
3612 (while (< (incf i) 256)
3613 (aset table i i))
3614 (concat
3615 (substring table 0 ?A)
3616 (substring table (+ ?A n) (+ ?A n (- 26 n)))
3617 (substring table ?A (+ ?A n))
3618 (substring table (+ ?A 26) ?a)
3619 (substring table (+ ?a n) (+ ?a n (- 26 n)))
3620 (substring table ?a (+ ?a n))
3621 (substring table (+ ?a 26) 255))))
3622
3623 (defun message-caesar-buffer-body (&optional rotnum wide)
3624 "Caesar rotate all letters in the current buffer by 13 places.
3625 Used to encode/decode possibly offensive messages (commonly in rec.humor).
3626 With prefix arg, specifies the number of places to rotate each letter forward.
3627 Mail and USENET news headers are not rotated unless WIDE is non-nil."
3628 (interactive (if current-prefix-arg
3629 (list (prefix-numeric-value current-prefix-arg))
3630 (list nil)))
3631 (save-excursion
3632 (save-restriction
3633 (when (and (not wide) (message-goto-body))
3634 (narrow-to-region (point) (point-max)))
3635 (message-caesar-region (point-min) (point-max) rotnum))))
3636
3637 (defun message-pipe-buffer-body (program)
3638 "Pipe the message body in the current buffer through PROGRAM."
3639 (save-excursion
3640 (save-restriction
3641 (when (message-goto-body)
3642 (narrow-to-region (point) (point-max)))
3643 (shell-command-on-region
3644 (point-min) (point-max) program nil t))))
3645
3646 (defun message-rename-buffer (&optional enter-string)
3647 "Rename the *message* buffer to \"*message* RECIPIENT\".
3648 If the function is run with a prefix, it will ask for a new buffer
3649 name, rather than giving an automatic name."
3650 (interactive "Pbuffer name: ")
3651 (save-excursion
3652 (save-restriction
3653 (goto-char (point-min))
3654 (narrow-to-region (point)
3655 (search-forward mail-header-separator nil 'end))
3656 (let* ((mail-to (or
3657 (if (message-news-p) (message-fetch-field "Newsgroups")
3658 (message-fetch-field "To"))
3659 ""))
3660 (mail-trimmed-to
3661 (if (string-match "," mail-to)
3662 (concat (substring mail-to 0 (match-beginning 0)) ", ...")
3663 mail-to))
3664 (name-default (concat "*message* " mail-trimmed-to))
3665 (name (if enter-string
3666 (read-string "New buffer name: " name-default)
3667 name-default)))
3668 (rename-buffer name t)))))
3669
3670 (defun message-fill-yanked-message (&optional justifyp)
3671 "Fill the paragraphs of a message yanked into this one.
3672 Numeric argument means justify as well."
3673 (interactive "P")
3674 (save-excursion
3675 (goto-char (point-min))
3676 (search-forward (concat "\n" mail-header-separator "\n") nil t)
3677 (let ((fill-prefix message-yank-prefix))
3678 (fill-individual-paragraphs (point) (point-max) justifyp))))
3679
3680 (defun message-indent-citation (&optional start end yank-only)
3681 "Modify text just inserted from a message to be cited.
3682 The inserted text should be the region.
3683 When this function returns, the region is again around the modified text.
3684
3685 Normally, indent each nonblank line `message-indentation-spaces' spaces.
3686 However, if `message-yank-prefix' is non-nil, insert that prefix on each line."
3687 (unless start (setq start (point)))
3688 (unless yank-only
3689 ;; Remove unwanted headers.
3690 (when message-ignored-cited-headers
3691 (let (all-removed)
3692 (save-restriction
3693 (narrow-to-region
3694 (goto-char start)
3695 (if (search-forward "\n\n" nil t)
3696 (1- (point))
3697 (point)))
3698 (message-remove-header message-ignored-cited-headers t)
3699 (when (= (point-min) (point-max))
3700 (setq all-removed t))
3701 (goto-char (point-max)))
3702 (if all-removed
3703 (goto-char start)
3704 (forward-line 1))))
3705 ;; Delete blank lines at the start of the buffer.
3706 (while (and (point-min)
3707 (eolp)
3708 (not (eobp)))
3709 (message-delete-line))
3710 ;; Delete blank lines at the end of the buffer.
3711 (goto-char (point-max))
3712 (unless (eq (preceding-char) ?\n)
3713 (insert "\n"))
3714 (while (and (zerop (forward-line -1))
3715 (looking-at "$"))
3716 (message-delete-line)))
3717 ;; Do the indentation.
3718 (if (null message-yank-prefix)
3719 (indent-rigidly start (or end (mark t)) message-indentation-spaces)
3720 (save-excursion
3721 (goto-char start)
3722 (while (< (point) (or end (mark t)))
3723 (cond ((looking-at ">")
3724 (insert message-yank-cited-prefix))
3725 ((looking-at "^$")
3726 (insert message-yank-empty-prefix))
3727 (t
3728 (insert message-yank-prefix)))
3729 (forward-line 1))))
3730 (goto-char start))
3731
3732 (defun message-remove-blank-cited-lines (&optional remove)
3733 "Remove cited lines containing only blanks.
3734 If REMOVE is non-nil, remove newlines, too.
3735
3736 To use this automatically, you may add this function to
3737 `gnus-message-setup-hook'."
3738 (interactive "P")
3739 (let ((citexp (concat "^\\("
3740 (concat message-yank-cited-prefix "\\|")
3741 message-yank-prefix
3742 "\\)+ *\n")))
3743 (message "Removing `%s'" citexp)
3744 (save-excursion
3745 (message-goto-body)
3746 (while (re-search-forward citexp nil t)
3747 (replace-match (if remove "" "\n"))))))
3748
3749 (defun message--yank-original-internal (arg)
3750 (let ((modified (buffer-modified-p))
3751 body-text)
3752 (when (and message-reply-buffer
3753 message-cite-function)
3754 (when (equal message-cite-reply-position 'above)
3755 (save-excursion
3756 (setq body-text
3757 (buffer-substring (message-goto-body)
3758 (point-max)))
3759 (delete-region (message-goto-body) (point-max))))
3760 (if (bufferp message-reply-buffer)
3761 (delete-windows-on message-reply-buffer t))
3762 (push-mark (save-excursion
3763 (cond
3764 ((bufferp message-reply-buffer)
3765 (insert-buffer-substring message-reply-buffer))
3766 ((and (consp message-reply-buffer)
3767 (functionp (car message-reply-buffer)))
3768 (apply (car message-reply-buffer)
3769 (cdr message-reply-buffer))))
3770 (unless (bolp)
3771 (insert ?\n))
3772 (point)))
3773 (unless arg
3774 (funcall message-cite-function)
3775 (unless (eq (char-before (mark t)) ?\n)
3776 (let ((pt (point)))
3777 (goto-char (mark t))
3778 (insert-before-markers ?\n)
3779 (goto-char pt))))
3780 (case message-cite-reply-position
3781 (above
3782 (message-goto-body)
3783 (insert body-text)
3784 (insert (if (bolp) "\n" "\n\n"))
3785 (message-goto-body))
3786 (below
3787 (message-goto-signature)))
3788 ;; Add a `message-setup-very-last-hook' here?
3789 ;; Add `gnus-article-highlight-citation' here?
3790 (unless modified
3791 (setq message-checksum (message-checksum))))))
3792
3793 (defun message-yank-original (&optional arg)
3794 "Insert the message being replied to, if any.
3795 Puts point before the text and mark after.
3796 Normally indents each nonblank line ARG spaces (default 3). However,
3797 if `message-yank-prefix' is non-nil, insert that prefix on each line.
3798
3799 This function uses `message-cite-function' to do the actual citing.
3800
3801 Just \\[universal-argument] as argument means don't indent, insert no
3802 prefix, and don't delete any headers."
3803 (interactive "P")
3804 ;; eval the let forms contained in message-cite-style
3805 (eval
3806 `(let ,(if (symbolp message-cite-style)
3807 (symbol-value message-cite-style)
3808 message-cite-style)
3809 (message--yank-original-internal ',arg))))
3810
3811 (defun message-yank-buffer (buffer)
3812 "Insert BUFFER into the current buffer and quote it."
3813 (interactive "bYank buffer: ")
3814 (let ((message-reply-buffer (get-buffer buffer)))
3815 (save-window-excursion
3816 (message-yank-original))))
3817
3818 (defun message-buffers ()
3819 "Return a list of active message buffers."
3820 (let (buffers)
3821 (save-current-buffer
3822 (dolist (buffer (buffer-list t))
3823 (set-buffer buffer)
3824 (when (and (derived-mode-p 'message-mode)
3825 (null message-sent-message-via))
3826 (push (buffer-name buffer) buffers))))
3827 (nreverse buffers)))
3828
3829 (defun message-cite-original-1 (strip-signature)
3830 "Cite an original message.
3831 If STRIP-SIGNATURE is non-nil, strips off the signature from the
3832 original message.
3833
3834 This function uses `mail-citation-hook' if that is non-nil."
3835 (if (and (boundp 'mail-citation-hook)
3836 mail-citation-hook)
3837 (run-hooks 'mail-citation-hook)
3838 (let* ((start (point))
3839 (end (mark t))
3840 (x-no-archive nil)
3841 (functions
3842 (when message-indent-citation-function
3843 (if (listp message-indent-citation-function)
3844 message-indent-citation-function
3845 (list message-indent-citation-function))))
3846 ;; This function may be called by `gnus-summary-yank-message' and
3847 ;; may insert a different article from the original. So, we will
3848 ;; modify the value of `message-reply-headers' with that article.
3849 (message-reply-headers
3850 (save-restriction
3851 (narrow-to-region start end)
3852 (message-narrow-to-head-1)
3853 (setq x-no-archive (message-fetch-field "x-no-archive"))
3854 (vector 0
3855 (or (message-fetch-field "subject") "none")
3856 (or (message-fetch-field "from") "nobody")
3857 (message-fetch-field "date")
3858 (message-fetch-field "message-id" t)
3859 (message-fetch-field "references")
3860 0 0 ""))))
3861 (mml-quote-region start end)
3862 (when strip-signature
3863 ;; Allow undoing.
3864 (undo-boundary)
3865 (goto-char end)
3866 (when (re-search-backward message-signature-separator start t)
3867 ;; Also peel off any blank lines before the signature.
3868 (forward-line -1)
3869 (while (looking-at "^[ \t]*$")
3870 (forward-line -1))
3871 (forward-line 1)
3872 (delete-region (point) end)
3873 (unless (search-backward "\n\n" start t)
3874 ;; Insert a blank line if it is peeled off.
3875 (insert "\n"))))
3876 (goto-char start)
3877 (mapc 'funcall functions)
3878 (when message-citation-line-function
3879 (unless (bolp)
3880 (insert "\n"))
3881 (funcall message-citation-line-function))
3882 (when (and x-no-archive
3883 (not message-cite-articles-with-x-no-archive)
3884 (string-match "yes" x-no-archive))
3885 (undo-boundary)
3886 (delete-region (point) (mark t))
3887 (insert "> [Quoted text removed due to X-No-Archive]\n")
3888 (push-mark)
3889 (forward-line -1)))))
3890
3891 (defun message-cite-original ()
3892 "Cite function in the standard Message manner."
3893 (message-cite-original-1 nil))
3894
3895 (autoload 'format-spec "format-spec")
3896 (autoload 'gnus-date-get-time "gnus-util")
3897
3898 (defun message-insert-formatted-citation-line (&optional from date tz)
3899 "Function that inserts a formatted citation line.
3900 The optional FROM, and DATE are strings containing the contents of
3901 the From header and the Date header respectively. The optional TZ
3902 is a number of seconds, overrides the time zone of DATE.
3903
3904 See `message-citation-line-format'."
3905 ;; The optional args are for testing/debugging. They will disappear later.
3906 ;; Example:
3907 ;; (with-temp-buffer
3908 ;; (message-insert-formatted-citation-line
3909 ;; "John Doe <john.doe@example.invalid>"
3910 ;; (message-make-date))
3911 ;; (buffer-string))
3912 (when (or message-reply-headers (and from date))
3913 (unless from
3914 (setq from (mail-header-from message-reply-headers)))
3915 (let* ((data (condition-case ()
3916 (funcall (if (boundp 'gnus-extract-address-components)
3917 gnus-extract-address-components
3918 'mail-extract-address-components)
3919 from)
3920 (error nil)))
3921 (name (car data))
3922 (fname name)
3923 (lname name)
3924 (net (car (cdr data)))
3925 (name-or-net (or (car data)
3926 (car (cdr data)) from))
3927 (time
3928 (when (string-match "%[^fnNFL]" message-citation-line-format)
3929 (cond ((numberp (car-safe date)) date) ;; backward compatibility
3930 (date (gnus-date-get-time date))
3931 (t
3932 (gnus-date-get-time
3933 (setq date (mail-header-date message-reply-headers)))))))
3934 (tz (or tz
3935 (when (stringp date)
3936 (nth 8 (parse-time-string date)))))
3937 (flist
3938 (let ((i ?A) lst)
3939 (when (stringp name)
3940 ;; Guess first name and last name:
3941 (let* ((names (delq
3942 nil
3943 (mapcar
3944 (lambda (x)
3945 (if (string-match "\\`\\(\\w\\|[-.]\\)+\\'"
3946 x)
3947 x
3948 nil))
3949 (split-string name "[ \t]+"))))
3950 (count (length names)))
3951 (cond ((= count 1)
3952 (setq fname (car names)
3953 lname ""))
3954 ((or (= count 2) (= count 3))
3955 (setq fname (car names)
3956 lname (mapconcat 'identity (cdr names) " ")))
3957 ((> count 3)
3958 (setq fname (mapconcat 'identity
3959 (butlast names (- count 2))
3960 " ")
3961 lname (mapconcat 'identity
3962 (nthcdr 2 names)
3963 " "))))
3964 (when (string-match "\\(.*\\),\\'" fname)
3965 (let ((newlname (match-string 1 fname)))
3966 (setq fname lname lname newlname)))))
3967 ;; The following letters are not used in `format-time-string':
3968 (push ?E lst) (push "<E>" lst)
3969 (push ?F lst) (push (or fname name-or-net) lst)
3970 ;; We might want to use "" instead of "<X>" later.
3971 (push ?J lst) (push "<J>" lst)
3972 (push ?K lst) (push "<K>" lst)
3973 (push ?L lst) (push lname lst)
3974 (push ?N lst) (push name-or-net lst)
3975 (push ?O lst) (push "<O>" lst)
3976 (push ?P lst) (push "<P>" lst)
3977 (push ?Q lst) (push "<Q>" lst)
3978 (push ?f lst) (push from lst)
3979 (push ?i lst) (push "<i>" lst)
3980 (push ?n lst) (push net lst)
3981 (push ?o lst) (push "<o>" lst)
3982 (push ?q lst) (push "<q>" lst)
3983 (push ?t lst) (push "<t>" lst)
3984 (push ?v lst) (push "<v>" lst)
3985 ;; Delegate the rest to `format-time-string':
3986 (while (<= i ?z)
3987 (when (and (not (memq i lst))
3988 ;; Skip (Z,a)
3989 (or (<= i ?Z)
3990 (>= i ?a)))
3991 (push i lst)
3992 (push (condition-case nil
3993 (gmm-format-time-string (format "%%%c" i) time tz)
3994 (error (format ">%c<" i)))
3995 lst))
3996 (setq i (1+ i)))
3997 (reverse lst)))
3998 (spec (apply 'format-spec-make flist)))
3999 (insert (format-spec message-citation-line-format spec)))
4000 (newline)))
4001
4002 (defun message-cite-original-without-signature ()
4003 "Cite function in the standard Message manner.
4004 This function strips off the signature from the original message."
4005 (message-cite-original-1 t))
4006
4007 (defun message-insert-citation-line ()
4008 "Insert a simple citation line."
4009 (when message-reply-headers
4010 (insert (mail-header-from message-reply-headers) " writes:")
4011 (newline)
4012 (newline)))
4013
4014 (defun message-position-on-field (header &rest afters)
4015 (let ((case-fold-search t))
4016 (save-restriction
4017 (narrow-to-region
4018 (goto-char (point-min))
4019 (progn
4020 (re-search-forward
4021 (concat "^" (regexp-quote mail-header-separator) "$"))
4022 (match-beginning 0)))
4023 (goto-char (point-min))
4024 (if (re-search-forward (concat "^" (regexp-quote header) ":") nil t)
4025 (progn
4026 (re-search-forward "^[^ \t]" nil 'move)
4027 (beginning-of-line)
4028 (skip-chars-backward "\n")
4029 t)
4030 (while (and afters
4031 (not (re-search-forward
4032 (concat "^" (regexp-quote (car afters)) ":")
4033 nil t)))
4034 (pop afters))
4035 (when afters
4036 (re-search-forward "^[^ \t]" nil 'move)
4037 (beginning-of-line))
4038 (insert header ": \n")
4039 (forward-char -1)
4040 nil))))
4041
4042 \f
4043
4044 ;;;
4045 ;;; Sending messages
4046 ;;;
4047
4048 (defun message-send-and-exit (&optional arg)
4049 "Send message like `message-send', then, if no errors, exit from mail buffer.
4050 The usage of ARG is defined by the instance that called Message.
4051 It should typically alter the sending method in some way or other."
4052 (interactive "P")
4053 (let ((buf (current-buffer))
4054 (actions message-exit-actions))
4055 (when (and (message-send arg)
4056 (buffer-name buf))
4057 (message-bury buf)
4058 (if message-kill-buffer-on-exit
4059 (kill-buffer buf))
4060 (message-do-actions actions)
4061 t)))
4062
4063 (defun message-dont-send ()
4064 "Don't send the message you have been editing.
4065 Instead, just auto-save the buffer and then bury it."
4066 (interactive)
4067 (set-buffer-modified-p t)
4068 (save-buffer)
4069 (let ((actions message-postpone-actions))
4070 (message-bury (current-buffer))
4071 (message-do-actions actions)))
4072
4073 (defun message-kill-buffer ()
4074 "Kill the current buffer."
4075 (interactive)
4076 (when (or (not (buffer-modified-p))
4077 (not message-kill-buffer-query)
4078 (yes-or-no-p "Message modified; kill anyway? "))
4079 (let ((actions message-kill-actions)
4080 (draft-article message-draft-article)
4081 (auto-save-file-name buffer-auto-save-file-name)
4082 (file-name buffer-file-name)
4083 (modified (buffer-modified-p)))
4084 (setq buffer-file-name nil)
4085 (kill-buffer (current-buffer))
4086 (when (and (or (and auto-save-file-name
4087 (file-exists-p auto-save-file-name))
4088 (and file-name
4089 (file-exists-p file-name)))
4090 (progn
4091 ;; If the message buffer has lived in a dedicated window,
4092 ;; `kill-buffer' has killed the frame. Thus the
4093 ;; `yes-or-no-p' may show up in a lowered frame. Make sure
4094 ;; that the user can see the question by raising the
4095 ;; current frame:
4096 (raise-frame)
4097 (yes-or-no-p (format "Remove the backup file%s? "
4098 (if modified " too" "")))))
4099 (ignore-errors
4100 (delete-file auto-save-file-name))
4101 (let ((message-draft-article draft-article))
4102 (message-disassociate-draft)))
4103 (message-do-actions actions))))
4104
4105 (defun message-bury (buffer)
4106 "Bury this mail BUFFER."
4107 ;; Note that this is not quite the same as (bury-buffer buffer),
4108 ;; since bury-buffer does extra stuff with a nil argument.
4109 ;; Eg http://lists.gnu.org/archive/html/emacs-devel/2014-01/msg00539.html
4110 (with-current-buffer buffer (bury-buffer))
4111 (if message-return-action
4112 (apply (car message-return-action) (cdr message-return-action))))
4113
4114 (autoload 'mml-secure-bcc-is-safe "mml-sec")
4115
4116 (defun message-send (&optional arg)
4117 "Send the message in the current buffer.
4118 If `message-interactive' is non-nil, wait for success indication or
4119 error messages, and inform user.
4120 Otherwise any failure is reported in a message back to the user from
4121 the mailer.
4122 The usage of ARG is defined by the instance that called Message.
4123 It should typically alter the sending method in some way or other."
4124 (interactive "P")
4125 ;; Make it possible to undo the coming changes.
4126 (undo-boundary)
4127 (let ((inhibit-read-only t))
4128 (put-text-property (point-min) (point-max) 'read-only nil))
4129 (message-fix-before-sending)
4130 (mml-secure-bcc-is-safe)
4131 (run-hooks 'message-send-hook)
4132 (when message-confirm-send
4133 (or (y-or-n-p "Send message? ")
4134 (keyboard-quit)))
4135 (message message-sending-message)
4136 (let ((alist message-send-method-alist)
4137 (success t)
4138 elem sent dont-barf-on-no-method
4139 (message-options message-options))
4140 (message-options-set-recipient)
4141 (while (and success
4142 (setq elem (pop alist)))
4143 (when (funcall (cadr elem))
4144 (when (and (or (not (memq (car elem)
4145 message-sent-message-via))
4146 (message-fetch-field "supersedes")
4147 (if (or (message-gnksa-enable-p 'multiple-copies)
4148 (not (eq (car elem) 'news)))
4149 (y-or-n-p
4150 (format
4151 "Already sent message via %s; resend? "
4152 (car elem)))
4153 (error "Denied posting -- multiple copies")))
4154 (setq success (funcall (caddr elem) arg)))
4155 (setq sent t))))
4156 (unless (or sent
4157 (not success)
4158 (let ((fcc (message-fetch-field "Fcc"))
4159 (gcc (message-fetch-field "Gcc")))
4160 (when (or fcc gcc)
4161 (or (eq message-allow-no-recipients 'always)
4162 (and (not (eq message-allow-no-recipients 'never))
4163 (setq dont-barf-on-no-method
4164 (y-or-n-p
4165 (format "No receiver, perform %s anyway? "
4166 (cond ((and fcc gcc) "Fcc and Gcc")
4167 (fcc "Fcc")
4168 (t "Gcc"))))))))))
4169 (error "No methods specified to send by"))
4170 (when (or dont-barf-on-no-method
4171 (and success sent))
4172 (message-do-fcc)
4173 (save-excursion
4174 (run-hooks 'message-sent-hook))
4175 (message "Sending...done")
4176 ;; Do ecomplete address snarfing.
4177 (when (and (message-mail-alias-type-p 'ecomplete)
4178 (not message-inhibit-ecomplete))
4179 (message-put-addresses-in-ecomplete))
4180 ;; Mark the buffer as unmodified and delete auto-save.
4181 (set-buffer-modified-p nil)
4182 (delete-auto-save-file-if-necessary t)
4183 (message-disassociate-draft)
4184 ;; Delete other mail buffers and stuff.
4185 (message-do-send-housekeeping)
4186 (message-do-actions message-send-actions)
4187 ;; Return success.
4188 t)))
4189
4190 (defun message-send-via-mail (arg)
4191 "Send the current message via mail."
4192 (message-send-mail arg))
4193
4194 (defun message-send-via-news (arg)
4195 "Send the current message via news."
4196 (funcall message-send-news-function arg))
4197
4198 (defmacro message-check (type &rest forms)
4199 "Eval FORMS if TYPE is to be checked."
4200 `(or (message-check-element ,type)
4201 (save-excursion
4202 ,@forms)))
4203
4204 (put 'message-check 'lisp-indent-function 1)
4205 (put 'message-check 'edebug-form-spec '(form body))
4206
4207 (defun message-text-with-property (prop &optional start end reverse)
4208 "Return a list of start and end positions where the text has PROP.
4209 START and END bound the search, they default to `point-min' and
4210 `point-max' respectively. If REVERSE is non-nil, find text which does
4211 not have PROP."
4212 (unless start
4213 (setq start (point-min)))
4214 (unless end
4215 (setq end (point-max)))
4216 (let (next regions)
4217 (if reverse
4218 (while (and start
4219 (setq start (text-property-any start end prop nil)))
4220 (setq next (next-single-property-change start prop nil end))
4221 (push (cons start (or next end)) regions)
4222 (setq start next))
4223 (while (and start
4224 (or (get-text-property start prop)
4225 (and (setq start (next-single-property-change
4226 start prop nil end))
4227 (get-text-property start prop))))
4228 (setq next (text-property-any start end prop nil))
4229 (push (cons start (or next end)) regions)
4230 (setq start next)))
4231 (nreverse regions)))
4232
4233 (defcustom message-bogus-addresses
4234 '("noreply" "nospam" "invalid" "@@" "[^[:ascii:]].*@" "[ \t]")
4235 "List of regexps of potentially bogus mail addresses.
4236 See `message-check-recipients' how to setup checking.
4237
4238 This list should make it possible to catch typos or warn about
4239 spam-trap addresses. It doesn't aim to verify strict RFC
4240 conformance."
4241 :version "23.1" ;; No Gnus
4242 :group 'message-headers
4243 :type '(choice
4244 (const :tag "None" nil)
4245 (list
4246 (set :inline t
4247 (const "noreply")
4248 (const "nospam")
4249 (const "invalid")
4250 (const :tag "duplicate @" "@@")
4251 (const :tag "non-ascii local part" "[^[:ascii:]].*@")
4252 (const :tag "`_' in domain part" "@.*_")
4253 (const :tag "whitespace" "[ \t]"))
4254 (repeat :inline t
4255 :tag "Other"
4256 (regexp)))))
4257
4258 (defun message-fix-before-sending ()
4259 "Do various things to make the message nice before sending it."
4260 ;; Make sure there's a newline at the end of the message.
4261 (goto-char (point-max))
4262 (unless (bolp)
4263 (insert "\n"))
4264 ;; Make the hidden headers visible.
4265 (widen)
4266 ;; Sort headers before sending the message.
4267 (message-sort-headers)
4268 ;; Make invisible text visible.
4269 ;; It doesn't seem as if this is useful, since the invisible property
4270 ;; is clobbered by an after-change hook anyhow.
4271 (message-check 'invisible-text
4272 (let ((regions (message-text-with-property 'invisible))
4273 from to)
4274 (when regions
4275 (while regions
4276 (setq from (caar regions)
4277 to (cdar regions)
4278 regions (cdr regions))
4279 (put-text-property from to 'invisible nil)
4280 (overlay-put (make-overlay from to) 'face 'highlight))
4281 (unless (yes-or-no-p
4282 "Invisible text found and made visible; continue sending? ")
4283 (error "Invisible text found and made visible")))))
4284 (message-check 'illegible-text
4285 (let (char found choice nul-chars)
4286 (message-goto-body)
4287 (setq nul-chars (save-excursion
4288 (search-forward "\000" nil t)))
4289 (while (progn
4290 (skip-chars-forward mm-7bit-chars)
4291 (when (get-text-property (point) 'no-illegible-text)
4292 ;; There is a signed or encrypted raw message part
4293 ;; that is considered to be safe.
4294 (goto-char (or (next-single-property-change
4295 (point) 'no-illegible-text)
4296 (point-max))))
4297 (setq char (char-after)))
4298 (when (or (< char 128)
4299 (and (mm-multibyte-p)
4300 (memq (char-charset char)
4301 '(eight-bit-control eight-bit-graphic
4302 ;; Emacs 23, Bug#1770:
4303 eight-bit
4304 control-1))
4305 (not (get-text-property
4306 (point) 'untranslated-utf-8))))
4307 (overlay-put (make-overlay (point) (1+ (point))) 'face 'highlight)
4308 (setq found t))
4309 (forward-char))
4310 (when found
4311 (setq choice
4312 (car
4313 (read-multiple-choice
4314 (if nul-chars
4315 "NUL characters found, which may cause problems. Continue sending?"
4316 "Non-printable characters found. Continue sending?")
4317 `((?d "delete" "Remove non-printable characters and send")
4318 (?r "replace"
4319 ,(format
4320 "Replace non-printable characters with \"%s\" and send"
4321 message-replacement-char))
4322 (?s "send" "Send as is without removing anything")
4323 (?e "edit" "Continue editing")))))
4324 (if (eq choice ?e)
4325 (error "Non-printable characters"))
4326 (message-goto-body)
4327 (skip-chars-forward mm-7bit-chars)
4328 (while (not (eobp))
4329 (when (let ((char (char-after)))
4330 (or (< char 128)
4331 (and (mm-multibyte-p)
4332 ;; FIXME: Wrong for Emacs 23 (unicode) and for
4333 ;; things like undecodable utf-8 (in Emacs 21?).
4334 ;; Should at least use find-coding-systems-region.
4335 ;; -- fx
4336 (memq (char-charset char)
4337 '(eight-bit-control eight-bit-graphic
4338 ;; Emacs 23, Bug#1770:
4339 eight-bit
4340 control-1))
4341 (not (get-text-property
4342 (point) 'untranslated-utf-8)))))
4343 (if (eq choice ?i)
4344 (message-kill-all-overlays)
4345 (delete-char 1)
4346 (when (eq choice ?r)
4347 (insert message-replacement-char))))
4348 (forward-char)
4349 (skip-chars-forward mm-7bit-chars)))))
4350 (message-check 'bogus-recipient
4351 ;; Warn before sending a mail to an invalid address.
4352 (message-check-recipients)))
4353
4354 (defun message-bogus-recipient-p (recipients)
4355 "Check if a mail address in RECIPIENTS looks bogus.
4356
4357 RECIPIENTS is a mail header. Return a list of potentially bogus
4358 addresses. If none is found, return nil.
4359
4360 An address might be bogus if if there's a matching entry in
4361 `message-bogus-addresses'."
4362 ;; FIXME: How about "foo@subdomain", when the MTA adds ".domain.tld"?
4363 (let (found)
4364 (mapc (lambda (address)
4365 (setq address (or (cadr address) ""))
4366 (when (or (string= "" address)
4367 (not (string-match "@" address))
4368 (string-match "@.*@" address)
4369 (and message-bogus-addresses
4370 (let ((re
4371 (if (listp message-bogus-addresses)
4372 (mapconcat 'identity
4373 message-bogus-addresses
4374 "\\|")
4375 message-bogus-addresses)))
4376 (string-match re address))))
4377 (push address found)))
4378 (mail-extract-address-components recipients t))
4379 found))
4380
4381 (defun message-check-recipients ()
4382 "Warn before composing or sending a mail to an invalid address.
4383
4384 This function could be useful in `message-setup-hook'."
4385 (interactive)
4386 (save-restriction
4387 (message-narrow-to-headers)
4388 (dolist (hdr '("To" "Cc" "Bcc"))
4389 (let ((addr (message-fetch-field hdr)))
4390 (when (stringp addr)
4391 (dolist (bog (message-bogus-recipient-p addr))
4392 (and bog
4393 (not (y-or-n-p
4394 (format-message
4395 "Address `%s'%s might be bogus. Continue? "
4396 bog
4397 ;; If the encoded version of the email address
4398 ;; is different from the unencoded version,
4399 ;; then we likely have invisible characters or
4400 ;; the like. Display the encoded version,
4401 ;; too.
4402 (let ((encoded (rfc2047-encode-string bog)))
4403 (if (string= encoded bog)
4404 ""
4405 (format " (%s)" encoded))))))
4406 (error "Bogus address"))))))))
4407
4408 (custom-add-option 'message-setup-hook 'message-check-recipients)
4409
4410 (defun message-add-action (action &rest types)
4411 "Add ACTION to be performed when doing an exit of type TYPES."
4412 (while types
4413 (add-to-list (intern (format "message-%s-actions" (pop types)))
4414 action)))
4415
4416 (defun message-delete-action (action &rest types)
4417 "Delete ACTION from lists of actions performed when doing an exit of type TYPES."
4418 (let (var)
4419 (while types
4420 (set (setq var (intern (format "message-%s-actions" (pop types))))
4421 (delq action (symbol-value var))))))
4422
4423 (defun message-do-actions (actions)
4424 "Perform all actions in ACTIONS."
4425 ;; Now perform actions on successful sending.
4426 (dolist (action actions)
4427 (ignore-errors
4428 (cond
4429 ;; A simple function.
4430 ((functionp action)
4431 (funcall action))
4432 ;; Something to be evalled.
4433 (t
4434 (eval action))))))
4435
4436 (defun message-send-mail-partially ()
4437 "Send mail as message/partial."
4438 ;; replace the header delimiter with a blank line
4439 (goto-char (point-min))
4440 (re-search-forward
4441 (concat "^" (regexp-quote mail-header-separator) "\n"))
4442 (replace-match "\n")
4443 (run-hooks 'message-send-mail-hook)
4444 (let ((p (goto-char (point-min)))
4445 (tembuf (message-generate-new-buffer-clone-locals " message temp"))
4446 (curbuf (current-buffer))
4447 (id (message-make-message-id)) (n 1)
4448 plist total header)
4449 (while (not (eobp))
4450 (if (< (point-max) (+ p message-send-mail-partially-limit))
4451 (goto-char (point-max))
4452 (goto-char (+ p message-send-mail-partially-limit))
4453 (beginning-of-line)
4454 (if (<= (point) p) (forward-line 1))) ;; In case of bad message.
4455 (push p plist)
4456 (setq p (point)))
4457 (setq total (length plist))
4458 (push (point-max) plist)
4459 (setq plist (nreverse plist))
4460 (unwind-protect
4461 (save-excursion
4462 (setq p (pop plist))
4463 (while plist
4464 (set-buffer curbuf)
4465 (copy-to-buffer tembuf p (car plist))
4466 (set-buffer tembuf)
4467 (goto-char (point-min))
4468 (if header
4469 (progn
4470 (goto-char (point-min))
4471 (narrow-to-region (point) (point))
4472 (insert header))
4473 (message-goto-eoh)
4474 (setq header (buffer-substring (point-min) (point)))
4475 (goto-char (point-min))
4476 (narrow-to-region (point) (point))
4477 (insert header)
4478 (message-remove-header "Mime-Version")
4479 (message-remove-header "Content-Type")
4480 (message-remove-header "Content-Transfer-Encoding")
4481 (message-remove-header "Message-ID")
4482 (message-remove-header "Lines")
4483 (goto-char (point-max))
4484 (insert "Mime-Version: 1.0\n")
4485 (setq header (buffer-string)))
4486 (goto-char (point-max))
4487 (insert (format "Content-Type: message/partial; id=\"%s\"; number=%d; total=%d\n\n"
4488 id n total))
4489 (forward-char -1)
4490 (let ((mail-header-separator ""))
4491 (when (memq 'Message-ID message-required-mail-headers)
4492 (insert "Message-ID: " (message-make-message-id) "\n"))
4493 (when (memq 'Lines message-required-mail-headers)
4494 (insert "Lines: " (message-make-lines) "\n"))
4495 (message-goto-subject)
4496 (end-of-line)
4497 (insert (format " (%d/%d)" n total))
4498 (widen)
4499 (if message-send-mail-real-function
4500 (funcall message-send-mail-real-function)
4501 (message-multi-smtp-send-mail)))
4502 (setq n (+ n 1))
4503 (setq p (pop plist))
4504 (erase-buffer)))
4505 (kill-buffer tembuf))))
4506
4507 (declare-function hashcash-wait-async "hashcash" (&optional buffer))
4508
4509 (defun message-send-mail (&optional arg)
4510 (require 'mail-utils)
4511 (let* ((tembuf (message-generate-new-buffer-clone-locals " message temp"))
4512 (case-fold-search nil)
4513 (news (message-news-p))
4514 (mailbuf (current-buffer))
4515 (message-this-is-mail t)
4516 ;; gnus-setup-posting-charset is autoloaded in mml.el (FIXME
4517 ;; maybe it should not be), which this file requires. Hence
4518 ;; the fboundp test is always true. Loading it from gnus-msg
4519 ;; loads many Gnus files (Bug#5642). If
4520 ;; gnus-group-posting-charset-alist hasn't been customized,
4521 ;; this is just going to return nil anyway. FIXME it would
4522 ;; be good to improve this further, because even if g-g-p-c-a
4523 ;; has been customized, that is likely to just be for news.
4524 ;; Eg either move the definition from gnus-msg, or separate out
4525 ;; the mail and news parts.
4526 (message-posting-charset
4527 (if (and (fboundp 'gnus-setup-posting-charset)
4528 (boundp 'gnus-group-posting-charset-alist))
4529 (gnus-setup-posting-charset nil)
4530 message-posting-charset))
4531 (headers message-required-mail-headers)
4532 options)
4533 (when (and message-generate-hashcash
4534 (not (eq message-generate-hashcash 'opportunistic)))
4535 (message "Generating hashcash...")
4536 (require 'hashcash)
4537 ;; Wait for calculations already started to finish...
4538 (hashcash-wait-async)
4539 ;; ...and do calculations not already done. mail-add-payment
4540 ;; will leave existing X-Hashcash headers alone.
4541 (mail-add-payment)
4542 (message "Generating hashcash...done"))
4543 (save-restriction
4544 (message-narrow-to-headers)
4545 ;; Generate the Mail-Followup-To header if the header is not there...
4546 (if (and (message-subscribed-p)
4547 (not (mail-fetch-field "mail-followup-to")))
4548 (setq headers
4549 (cons
4550 (cons "Mail-Followup-To" (message-make-mail-followup-to))
4551 message-required-mail-headers))
4552 ;; otherwise, delete the MFT header if the field is empty
4553 (when (equal "" (mail-fetch-field "mail-followup-to"))
4554 (message-remove-header "^Mail-Followup-To:")))
4555 ;; Insert some headers.
4556 (let ((message-deletable-headers
4557 (if news nil message-deletable-headers)))
4558 (message-generate-headers headers))
4559 ;; Check continuation headers.
4560 (message-check 'continuation-headers
4561 (goto-char (point-min))
4562 (while (re-search-forward "^[^ \t\n][^ \t\n:]*[ \t\n]" nil t)
4563 (goto-char (match-beginning 0))
4564 (if (y-or-n-p "Fix continuation lines? ")
4565 (insert " ")
4566 (forward-line 1)
4567 (unless (y-or-n-p "Send anyway? ")
4568 (error "Failed to send the message")))))
4569 ;; Let the user do all of the above.
4570 (run-hooks 'message-header-hook))
4571 (setq options message-options)
4572 (unwind-protect
4573 (with-current-buffer tembuf
4574 (erase-buffer)
4575 (setq message-options options)
4576 ;; Avoid copying text props (except hard newlines).
4577 (insert (with-current-buffer mailbuf
4578 (mml-buffer-substring-no-properties-except-hard-newlines
4579 (point-min) (point-max))))
4580 ;; Remove some headers.
4581 (message-encode-message-body)
4582 (save-restriction
4583 (message-narrow-to-headers)
4584 ;; We (re)generate the Lines header.
4585 (when (memq 'Lines message-required-mail-headers)
4586 (message-generate-headers '(Lines)))
4587 ;; Remove some headers.
4588 (message-remove-header message-ignored-mail-headers t)
4589 (let ((mail-parse-charset message-default-charset))
4590 (mail-encode-encoded-word-buffer)))
4591 (goto-char (point-max))
4592 ;; require one newline at the end.
4593 (or (= (preceding-char) ?\n)
4594 (insert ?\n))
4595 (message-cleanup-headers)
4596 ;; FIXME: we're inserting the courtesy copy after encoding.
4597 ;; This is wrong if the courtesy copy string contains
4598 ;; non-ASCII characters. -- jh
4599 (when
4600 (save-restriction
4601 (message-narrow-to-headers)
4602 (and news
4603 (not (message-fetch-field "List-Post"))
4604 (not (message-fetch-field "List-ID"))
4605 (or (message-fetch-field "cc")
4606 (message-fetch-field "bcc")
4607 (message-fetch-field "to"))
4608 (let ((content-type (message-fetch-field
4609 "content-type")))
4610 (and
4611 (or
4612 (not content-type)
4613 (string= "text/plain"
4614 (car
4615 (mail-header-parse-content-type
4616 content-type))))
4617 (not
4618 (string= "base64"
4619 (message-fetch-field
4620 "content-transfer-encoding")))))))
4621 (message-insert-courtesy-copy
4622 (with-current-buffer mailbuf
4623 message-courtesy-message)))
4624 ;; Let's make sure we encoded all the body.
4625 (assert (save-excursion
4626 (goto-char (point-min))
4627 (not (re-search-forward "[^\000-\377]" nil t))))
4628 (mm-disable-multibyte)
4629 (if (or (not message-send-mail-partially-limit)
4630 (< (buffer-size) message-send-mail-partially-limit)
4631 (not (message-y-or-n-p
4632 "The message size is too large, split? "
4633 t
4634 "\
4635 The message size, "
4636 (/ (buffer-size) 1000) "KB, is too large.
4637
4638 Some mail gateways (MTA's) bounce large messages. To avoid the
4639 problem, answer `y', and the message will be split into several
4640 smaller pieces, the size of each is about "
4641 (/ message-send-mail-partially-limit 1000)
4642 "KB except the last
4643 one.
4644
4645 However, some mail readers (MUA's) can't read split messages, i.e.,
4646 mails in message/partially format. Answer `n', and the message will be
4647 sent in one piece.
4648
4649 The size limit is controlled by `message-send-mail-partially-limit'.
4650 If you always want Gnus to send messages in one piece, set
4651 `message-send-mail-partially-limit' to nil.
4652 ")))
4653 (progn
4654 (message "Sending via mail...")
4655 (if message-send-mail-real-function
4656 (funcall message-send-mail-real-function)
4657 (message-multi-smtp-send-mail)))
4658 (message-send-mail-partially))
4659 (setq options message-options))
4660 (kill-buffer tembuf))
4661 (set-buffer mailbuf)
4662 (setq message-options options)
4663 (push 'mail message-sent-message-via)))
4664
4665 (defvar sendmail-program)
4666 (defvar smtpmail-smtp-user)
4667
4668 (defun message-multi-smtp-send-mail ()
4669 "Send the current buffer to `message-send-mail-function'.
4670 Or, if there's a header that specifies a different method, use
4671 that instead."
4672 (let ((method (message-field-value "X-Message-SMTP-Method")))
4673 (if (not method)
4674 (funcall message-send-mail-function)
4675 (message-remove-header "X-Message-SMTP-Method")
4676 (setq method (split-string method))
4677 (cond
4678 ((equal (car method) "sendmail")
4679 (message-send-mail-with-sendmail))
4680 ((equal (car method) "smtp")
4681 (require 'smtpmail)
4682 (let ((smtpmail-smtp-server (nth 1 method))
4683 (smtpmail-smtp-service (nth 2 method))
4684 (smtpmail-smtp-user (or (nth 3 method) smtpmail-smtp-user)))
4685 (message-smtpmail-send-it)))
4686 (t
4687 (error "Unknown method %s" method))))))
4688
4689 (defun message-send-mail-with-sendmail ()
4690 "Send off the prepared buffer with sendmail."
4691 (require 'sendmail)
4692 (let ((errbuf (if message-interactive
4693 (message-generate-new-buffer-clone-locals
4694 " sendmail errors")
4695 0))
4696 resend-to-addresses delimline)
4697 (unwind-protect
4698 (progn
4699 (let ((case-fold-search t))
4700 (save-restriction
4701 (message-narrow-to-headers)
4702 (setq resend-to-addresses (message-fetch-field "resent-to")))
4703 ;; Change header-delimiter to be what sendmail expects.
4704 (goto-char (point-min))
4705 (re-search-forward
4706 (concat "^" (regexp-quote mail-header-separator) "\n"))
4707 (replace-match "\n")
4708 (backward-char 1)
4709 (setq delimline (point-marker))
4710 (run-hooks 'message-send-mail-hook)
4711 ;; Insert an extra newline if we need it to work around
4712 ;; Sun's bug that swallows newlines.
4713 (goto-char (1+ delimline))
4714 (when (eval message-mailer-swallows-blank-line)
4715 (newline))
4716 (when message-interactive
4717 (with-current-buffer errbuf
4718 (erase-buffer))))
4719 (let* ((default-directory "/")
4720 (coding-system-for-write message-send-coding-system)
4721 (cpr (apply
4722 'call-process-region
4723 (append
4724 (list (point-min) (point-max) sendmail-program
4725 nil errbuf nil "-oi")
4726 message-sendmail-extra-arguments
4727 ;; Always specify who from,
4728 ;; since some systems have broken sendmails.
4729 ;; But some systems are more broken with -f, so
4730 ;; we'll let users override this.
4731 (and (null message-sendmail-f-is-evil)
4732 (list "-f" (message-sendmail-envelope-from)))
4733 ;; These mean "report errors by mail"
4734 ;; and "deliver in background".
4735 (if (null message-interactive) '("-oem" "-odb"))
4736 ;; Get the addresses from the message
4737 ;; unless this is a resend.
4738 ;; We must not do that for a resend
4739 ;; because we would find the original addresses.
4740 ;; For a resend, include the specific addresses.
4741 (if resend-to-addresses
4742 (list resend-to-addresses)
4743 '("-t"))))))
4744 (unless (or (null cpr) (and (numberp cpr) (zerop cpr)))
4745 (when errbuf
4746 (pop-to-buffer errbuf)
4747 (setq errbuf nil))
4748 (error "Sending...failed with exit value %d" cpr)))
4749 (when message-interactive
4750 (with-current-buffer errbuf
4751 (goto-char (point-min))
4752 (while (re-search-forward "\n+ *" nil t)
4753 (replace-match "; "))
4754 (if (not (zerop (buffer-size)))
4755 (error "Sending...failed to %s"
4756 (buffer-string))))))
4757 (when (bufferp errbuf)
4758 (kill-buffer errbuf)))))
4759
4760 (defun message-send-mail-with-qmail ()
4761 "Pass the prepared message buffer to qmail-inject.
4762 Refer to the documentation for the variable `message-send-mail-function'
4763 to find out how to use this."
4764 ;; replace the header delimiter with a blank line
4765 (goto-char (point-min))
4766 (re-search-forward
4767 (concat "^" (regexp-quote mail-header-separator) "\n"))
4768 (replace-match "\n")
4769 (run-hooks 'message-send-mail-hook)
4770 ;; send the message
4771 (case
4772 (let ((coding-system-for-write message-send-coding-system))
4773 (apply
4774 'call-process-region (point-min) (point-max)
4775 message-qmail-inject-program nil nil nil
4776 ;; qmail-inject's default behavior is to look for addresses on the
4777 ;; command line; if there're none, it scans the headers.
4778 ;; yes, it does The Right Thing w.r.t. Resent-To and it's kin.
4779 ;;
4780 ;; in general, ALL of qmail-inject's defaults are perfect for simply
4781 ;; reading a formatted (i. e., at least a To: or Resent-To header)
4782 ;; message from stdin.
4783 ;;
4784 ;; qmail also has the advantage of not having been raped by
4785 ;; various vendors, so we don't have to allow for that, either --
4786 ;; compare this with message-send-mail-with-sendmail and weep
4787 ;; for sendmail's lost innocence.
4788 ;;
4789 ;; all this is way cool coz it lets us keep the arguments entirely
4790 ;; free for -inject-arguments -- a big win for the user and for us
4791 ;; since we don't have to play that double-guessing game and the user
4792 ;; gets full control (no gestapo'ish -f's, for instance). --sj
4793 (if (functionp message-qmail-inject-args)
4794 (funcall message-qmail-inject-args)
4795 message-qmail-inject-args)))
4796 ;; qmail-inject doesn't say anything on it's stdout/stderr,
4797 ;; we have to look at the retval instead
4798 (0 nil)
4799 (100 (error "qmail-inject reported permanent failure"))
4800 (111 (error "qmail-inject reported transient failure"))
4801 ;; should never happen
4802 (t (error "qmail-inject reported unknown failure"))))
4803
4804 (defvar mh-previous-window-config)
4805
4806 (defun message-send-mail-with-mh ()
4807 "Send the prepared message buffer with mh."
4808 (let ((mh-previous-window-config nil)
4809 (name (mh-new-draft-name)))
4810 (setq buffer-file-name name)
4811 ;; MH wants to generate these headers itself.
4812 (when message-mh-deletable-headers
4813 (let ((headers message-mh-deletable-headers))
4814 (while headers
4815 (goto-char (point-min))
4816 (and (re-search-forward
4817 (concat "^" (symbol-name (car headers)) ": *") nil t)
4818 (message-delete-line))
4819 (pop headers))))
4820 (run-hooks 'message-send-mail-hook)
4821 ;; Pass it on to mh.
4822 (mh-send-letter)))
4823
4824 (defun message-smtpmail-send-it ()
4825 "Send the prepared message buffer with `smtpmail-send-it'.
4826 The only difference from `smtpmail-send-it' is that this command
4827 evaluates `message-send-mail-hook' just before sending a message.
4828 It is useful if your ISP requires the POP-before-SMTP
4829 authentication. See the Gnus manual for details."
4830 (run-hooks 'message-send-mail-hook)
4831 ;; Change header-delimiter to be what smtpmail expects.
4832 (goto-char (point-min))
4833 (when (re-search-forward
4834 (concat "^" (regexp-quote mail-header-separator) "\n"))
4835 (replace-match "\n"))
4836 (smtpmail-send-it))
4837
4838 (defun message-send-mail-with-mailclient ()
4839 "Send the prepared message buffer with `mailclient-send-it'.
4840 The only difference from `mailclient-send-it' is that this
4841 command evaluates `message-send-mail-hook' just before sending a message."
4842 (run-hooks 'message-send-mail-hook)
4843 (mailclient-send-it))
4844
4845 (defun message-canlock-generate ()
4846 "Return a string that is non-trivial to guess.
4847 Do not use this for anything important, it is cryptographically weak."
4848 (require 'sha1)
4849 (let (sha1-maximum-internal-length)
4850 (sha1 (concat (message-unique-id)
4851 (format "%x%x%x" (random) (random) (random))
4852 (prin1-to-string (recent-keys))
4853 (prin1-to-string (garbage-collect))))))
4854
4855 (defvar canlock-password)
4856 (defvar canlock-password-for-verify)
4857
4858 (defun message-canlock-password ()
4859 "The password used by message for cancel locks.
4860 This is the value of `canlock-password', if that option is non-nil.
4861 Otherwise, generate and save a value for `canlock-password' first."
4862 (require 'canlock)
4863 (unless canlock-password
4864 (customize-save-variable 'canlock-password (message-canlock-generate))
4865 (setq canlock-password-for-verify canlock-password))
4866 canlock-password)
4867
4868 (defun message-insert-canlock ()
4869 (when message-insert-canlock
4870 (message-canlock-password)
4871 (canlock-insert-header)))
4872
4873 (autoload 'nnheader-get-report "nnheader")
4874
4875 (declare-function gnus-setup-posting-charset "gnus-msg" (group))
4876
4877 (defun message-send-news (&optional arg)
4878 (require 'gnus-msg)
4879 (let* ((tembuf (message-generate-new-buffer-clone-locals " *message temp*"))
4880 (case-fold-search nil)
4881 (method (if (functionp message-post-method)
4882 (funcall message-post-method arg)
4883 message-post-method))
4884 (newsgroups-field (save-restriction
4885 (message-narrow-to-headers-or-head)
4886 (message-fetch-field "Newsgroups")))
4887 (followup-field (save-restriction
4888 (message-narrow-to-headers-or-head)
4889 (message-fetch-field "Followup-To")))
4890 ;; BUG: We really need to get the charset for each name in the
4891 ;; Newsgroups and Followup-To lines to allow crossposting
4892 ;; between group names with incompatible character sets.
4893 ;; -- Per Abrahamsen <abraham@dina.kvl.dk> 2001-10-08.
4894 (group-field-charset
4895 (gnus-group-name-charset method newsgroups-field))
4896 (followup-field-charset
4897 (gnus-group-name-charset method (or followup-field "")))
4898 (rfc2047-header-encoding-alist
4899 (append (when group-field-charset
4900 (list (cons "Newsgroups" group-field-charset)))
4901 (when followup-field-charset
4902 (list (cons "Followup-To" followup-field-charset)))
4903 rfc2047-header-encoding-alist))
4904 (messbuf (current-buffer))
4905 (message-syntax-checks
4906 (if (and arg
4907 (listp message-syntax-checks))
4908 (cons '(existing-newsgroups . disabled)
4909 message-syntax-checks)
4910 message-syntax-checks))
4911 (message-this-is-news t)
4912 (message-posting-charset
4913 (gnus-setup-posting-charset newsgroups-field))
4914 result)
4915 (if (not (message-check-news-body-syntax))
4916 nil
4917 (save-restriction
4918 (message-narrow-to-headers)
4919 ;; Insert some headers.
4920 (message-generate-headers message-required-news-headers)
4921 (message-insert-canlock)
4922 ;; Let the user do all of the above.
4923 (run-hooks 'message-header-hook))
4924 ;; Note: This check will be disabled by the ".*" default value for
4925 ;; gnus-group-name-charset-group-alist. -- Pa 2001-10-07.
4926 (when (and group-field-charset
4927 (listp message-syntax-checks))
4928 (setq message-syntax-checks
4929 (cons '(valid-newsgroups . disabled)
4930 message-syntax-checks)))
4931 (message-cleanup-headers)
4932 (if (not (let ((message-post-method method))
4933 (message-check-news-syntax)))
4934 nil
4935 (unwind-protect
4936 (with-current-buffer tembuf
4937 (buffer-disable-undo)
4938 (erase-buffer)
4939 ;; Avoid copying text props (except hard newlines).
4940 (insert
4941 (with-current-buffer messbuf
4942 (mml-buffer-substring-no-properties-except-hard-newlines
4943 (point-min) (point-max))))
4944 (message-encode-message-body)
4945 ;; Remove some headers.
4946 (save-restriction
4947 (message-narrow-to-headers)
4948 ;; We (re)generate the Lines header.
4949 (when (memq 'Lines message-required-mail-headers)
4950 (message-generate-headers '(Lines)))
4951 ;; Remove some headers.
4952 (message-remove-header message-ignored-news-headers t)
4953 (let ((mail-parse-charset message-default-charset))
4954 (mail-encode-encoded-word-buffer)))
4955 (goto-char (point-max))
4956 ;; require one newline at the end.
4957 (or (= (preceding-char) ?\n)
4958 (insert ?\n))
4959 (let ((case-fold-search t))
4960 ;; Remove the delimiter.
4961 (goto-char (point-min))
4962 (re-search-forward
4963 (concat "^" (regexp-quote mail-header-separator) "\n"))
4964 (replace-match "\n")
4965 (backward-char 1))
4966 (run-hooks 'message-send-news-hook)
4967 (gnus-open-server method)
4968 (message "Sending news via %s..." (gnus-server-string method))
4969 (setq result (let ((mail-header-separator ""))
4970 (gnus-request-post method))))
4971 (kill-buffer tembuf))
4972 (set-buffer messbuf)
4973 (if result
4974 (push 'news message-sent-message-via)
4975 (message "Couldn't send message via news: %s"
4976 (nnheader-get-report (car method)))
4977 nil)))))
4978
4979 ;;;
4980 ;;; Header generation & syntax checking.
4981 ;;;
4982
4983 (defun message-check-element (type)
4984 "Return non-nil if this TYPE is not to be checked."
4985 (if (eq message-syntax-checks 'dont-check-for-anything-just-trust-me)
4986 t
4987 (let ((able (assq type message-syntax-checks)))
4988 (and (consp able)
4989 (eq (cdr able) 'disabled)))))
4990
4991 (defun message-check-news-syntax ()
4992 "Check the syntax of the message."
4993 (save-excursion
4994 (save-restriction
4995 (widen)
4996 ;; We narrow to the headers and check them first.
4997 (save-excursion
4998 (save-restriction
4999 (message-narrow-to-headers)
5000 (message-check-news-header-syntax))))))
5001
5002 (defun message-check-news-header-syntax ()
5003 (and
5004 ;; Check Newsgroups header.
5005 (message-check 'newsgroups
5006 (let ((group (message-fetch-field "newsgroups")))
5007 (or
5008 (and group
5009 (not (string-match "\\`[ \t]*\\'" group)))
5010 (ignore
5011 (message
5012 "The newsgroups field is empty or missing. Posting is denied.")))))
5013 ;; Check the Subject header.
5014 (message-check 'subject
5015 (let* ((case-fold-search t)
5016 (subject (message-fetch-field "subject")))
5017 (or
5018 (and subject
5019 (not (string-match "\\`[ \t]*\\'" subject)))
5020 (ignore
5021 (message
5022 "The subject field is empty or missing. Posting is denied.")))))
5023 ;; Check for commands in Subject.
5024 (message-check 'subject-cmsg
5025 (if (string-match "^cmsg " (message-fetch-field "subject"))
5026 (y-or-n-p
5027 "The control code \"cmsg\" is in the subject. Really post? ")
5028 t))
5029 ;; Check long header lines.
5030 (message-check 'long-header-lines
5031 (let ((header nil)
5032 (length 0)
5033 found)
5034 (while (and (not found)
5035 (re-search-forward "^\\([^ \t:]+\\): " nil t))
5036 (if (> (- (point) (match-beginning 0)) 998)
5037 (setq found t
5038 length (- (point) (match-beginning 0)))
5039 (setq header (match-string-no-properties 1)))
5040 (forward-line 1))
5041 (if found
5042 (y-or-n-p (format "Your %s header is too long (%d). Really post? "
5043 header length))
5044 t)))
5045 ;; Check for multiple identical headers.
5046 (message-check 'multiple-headers
5047 (let (found)
5048 (while (and (not found)
5049 (re-search-forward "^[^ \t:]+: " nil t))
5050 (save-excursion
5051 (or (re-search-forward
5052 (concat "^"
5053 (regexp-quote
5054 (setq found
5055 (buffer-substring
5056 (match-beginning 0) (- (match-end 0) 2))))
5057 ":")
5058 nil t)
5059 (setq found nil))))
5060 (if found
5061 (y-or-n-p (format "Multiple %s headers. Really post? " found))
5062 t)))
5063 ;; Check for Version and Sendsys.
5064 (message-check 'sendsys
5065 (if (re-search-forward "^Sendsys:\\|^Version:" nil t)
5066 (y-or-n-p
5067 (format "The article contains a %s command. Really post? "
5068 (buffer-substring (match-beginning 0)
5069 (1- (match-end 0)))))
5070 t))
5071 ;; See whether we can shorten Followup-To.
5072 (message-check 'shorten-followup-to
5073 (let ((newsgroups (message-fetch-field "newsgroups"))
5074 (followup-to (message-fetch-field "followup-to"))
5075 to)
5076 (when (and newsgroups
5077 (string-match "," newsgroups)
5078 (not followup-to)
5079 (not
5080 (zerop
5081 (length
5082 (setq to (completing-read
5083 "Followups to (default no Followup-To header): "
5084 (mapcar #'list
5085 (cons "poster"
5086 (message-tokenize-header
5087 newsgroups)))))))))
5088 (goto-char (point-min))
5089 (insert "Followup-To: " to "\n"))
5090 t))
5091 ;; Check "Shoot me".
5092 (message-check 'shoot
5093 (if (re-search-forward
5094 "Message-ID.*.i-did-not-set--mail-host-address--so-tickle-me" nil t)
5095 (y-or-n-p "You appear to have a misconfigured system. Really post? ")
5096 t))
5097 ;; Check for Approved.
5098 (message-check 'approved
5099 (if (re-search-forward "^Approved:" nil t)
5100 (y-or-n-p "The article contains an Approved header. Really post? ")
5101 t))
5102 ;; Check the Message-ID header.
5103 (message-check 'message-id
5104 (let* ((case-fold-search t)
5105 (message-id (message-fetch-field "message-id" t)))
5106 (or (not message-id)
5107 ;; Is there an @ in the ID?
5108 (and (string-match "@" message-id)
5109 ;; Is there a dot in the ID?
5110 (string-match "@[^.]*\\." message-id)
5111 ;; Does the ID end with a dot?
5112 (not (string-match "\\.>" message-id)))
5113 (y-or-n-p
5114 (format "The Message-ID looks strange: \"%s\". Really post? "
5115 message-id)))))
5116 ;; Check the Newsgroups & Followup-To headers.
5117 (message-check 'existing-newsgroups
5118 (let* ((case-fold-search t)
5119 (newsgroups (message-fetch-field "newsgroups"))
5120 (followup-to (message-fetch-field "followup-to"))
5121 (groups (message-tokenize-header
5122 (if followup-to
5123 (concat newsgroups "," followup-to)
5124 newsgroups)))
5125 (post-method (if (functionp message-post-method)
5126 (funcall message-post-method)
5127 message-post-method))
5128 ;; KLUDGE to handle nnvirtual groups. Doing this right
5129 ;; would probably involve a new nnoo function.
5130 ;; -- Per Abrahamsen <abraham@dina.kvl.dk>, 2001-10-17.
5131 (method (if (and (consp post-method)
5132 (eq (car post-method) 'nnvirtual)
5133 gnus-message-group-art)
5134 (let ((group (car (nnvirtual-find-group-art
5135 (car gnus-message-group-art)
5136 (cdr gnus-message-group-art)))))
5137 (gnus-find-method-for-group group))
5138 post-method))
5139 (known-groups
5140 (mapcar (lambda (n)
5141 (gnus-group-name-decode
5142 (gnus-group-real-name n)
5143 (gnus-group-name-charset method n)))
5144 (gnus-groups-from-server method)))
5145 errors)
5146 (while groups
5147 (when (and (not (equal (car groups) "poster"))
5148 (not (member (car groups) known-groups))
5149 (not (member (car groups) errors)))
5150 (push (car groups) errors))
5151 (pop groups))
5152 (cond
5153 ;; Gnus is not running.
5154 ((or (not (and (boundp 'gnus-active-hashtb)
5155 gnus-active-hashtb))
5156 (not (boundp 'gnus-read-active-file)))
5157 t)
5158 ;; We don't have all the group names.
5159 ((and (or (not gnus-read-active-file)
5160 (eq gnus-read-active-file 'some))
5161 errors)
5162 (y-or-n-p
5163 (format
5164 "Really use %s possibly unknown group%s: %s? "
5165 (if (= (length errors) 1) "this" "these")
5166 (if (= (length errors) 1) "" "s")
5167 (mapconcat 'identity errors ", "))))
5168 ;; There were no errors.
5169 ((not errors)
5170 t)
5171 ;; There are unknown groups.
5172 (t
5173 (y-or-n-p
5174 (format
5175 "Really post to %s unknown group%s: %s? "
5176 (if (= (length errors) 1) "this" "these")
5177 (if (= (length errors) 1) "" "s")
5178 (mapconcat 'identity errors ", ")))))))
5179 ;; Check continuation headers.
5180 (message-check 'continuation-headers
5181 (goto-char (point-min))
5182 (let ((do-posting t))
5183 (while (re-search-forward "^[^ \t\n][^ \t\n:]*[ \t\n]" nil t)
5184 (goto-char (match-beginning 0))
5185 (if (y-or-n-p "Fix continuation lines? ")
5186 (insert " ")
5187 (forward-line 1)
5188 (unless (y-or-n-p "Send anyway? ")
5189 (setq do-posting nil))))
5190 do-posting))
5191 ;; Check the Newsgroups & Followup-To headers for syntax errors.
5192 (message-check 'valid-newsgroups
5193 (let ((case-fold-search t)
5194 (headers '("Newsgroups" "Followup-To"))
5195 header error)
5196 (while (and headers (not error))
5197 (when (setq header (mail-fetch-field (car headers)))
5198 (if (or
5199 (not
5200 (string-match
5201 "\\`\\([-+_&.a-zA-Z0-9]+\\)?\\(,[-+_&.a-zA-Z0-9]+\\)*\\'"
5202 header))
5203 (memq
5204 nil (mapcar
5205 (lambda (g)
5206 (not (string-match "\\.\\'\\|\\.\\." g)))
5207 (message-tokenize-header header ","))))
5208 (setq error t)))
5209 (unless error
5210 (pop headers)))
5211 (if (not error)
5212 t
5213 (y-or-n-p
5214 (format "The %s header looks odd: \"%s\". Really post? "
5215 (car headers) header)))))
5216 (message-check 'repeated-newsgroups
5217 (let ((case-fold-search t)
5218 (headers '("Newsgroups" "Followup-To"))
5219 header error groups group)
5220 (while (and headers
5221 (not error))
5222 (when (setq header (mail-fetch-field (pop headers)))
5223 (setq groups (message-tokenize-header header ","))
5224 (while (setq group (pop groups))
5225 (when (member group groups)
5226 (setq error group
5227 groups nil)))))
5228 (if (not error)
5229 t
5230 (y-or-n-p
5231 (format "Group %s is repeated in headers. Really post? " error)))))
5232 ;; Check the From header.
5233 (message-check 'from
5234 (let* ((case-fold-search t)
5235 (from (message-fetch-field "from"))
5236 ad)
5237 (cond
5238 ((not from)
5239 (message "There is no From line. Posting is denied.")
5240 nil)
5241 ((or (not (string-match
5242 "@[^\\.]*\\."
5243 (setq ad (nth 1 (mail-extract-address-components
5244 from))))) ;larsi@ifi
5245 (string-match "\\.\\." ad) ;larsi@ifi..uio
5246 (string-match "@\\." ad) ;larsi@.ifi.uio
5247 (string-match "\\.$" ad) ;larsi@ifi.uio.
5248 (not (string-match "^[^@]+@[^@]+$" ad)) ;larsi.ifi.uio
5249 (string-match "(.*).*(.*)" from)) ;(lars) (lars)
5250 (message
5251 "Denied posting -- the From looks strange: \"%s\"." from)
5252 nil)
5253 ((let ((addresses (rfc822-addresses from)))
5254 ;; `rfc822-addresses' returns a string if parsing fails.
5255 (while (and (consp addresses)
5256 (not (eq (string-to-char (car addresses)) ?\()))
5257 (setq addresses (cdr addresses)))
5258 addresses)
5259 (message
5260 "Denied posting -- bad From address: \"%s\"." from)
5261 nil)
5262 (t t))))
5263 ;; Check the Reply-To header.
5264 (message-check 'reply-to
5265 (let* ((case-fold-search t)
5266 (reply-to (message-fetch-field "reply-to"))
5267 ad)
5268 (cond
5269 ((not reply-to)
5270 t)
5271 ((string-match "," reply-to)
5272 (y-or-n-p
5273 (format "Multiple Reply-To addresses: \"%s\". Really post? "
5274 reply-to)))
5275 ((or (not (string-match
5276 "@[^\\.]*\\."
5277 (setq ad (nth 1 (mail-extract-address-components
5278 reply-to))))) ;larsi@ifi
5279 (string-match "\\.\\." ad) ;larsi@ifi..uio
5280 (string-match "@\\." ad) ;larsi@.ifi.uio
5281 (string-match "\\.$" ad) ;larsi@ifi.uio.
5282 (not (string-match "^[^@]+@[^@]+$" ad)) ;larsi.ifi.uio
5283 (string-match "(.*).*(.*)" reply-to)) ;(lars) (lars)
5284 (y-or-n-p
5285 (format
5286 "The Reply-To looks strange: \"%s\". Really post? "
5287 reply-to)))
5288 (t t))))))
5289
5290 (defun message-check-news-body-syntax ()
5291 (and
5292 ;; Check for long lines.
5293 (message-check 'long-lines
5294 (goto-char (point-min))
5295 (re-search-forward
5296 (concat "^" (regexp-quote mail-header-separator) "$"))
5297 (forward-line 1)
5298 (while (and
5299 (or (looking-at
5300 "<#\\(/\\)?\\(multipart\\|part\\|external\\|mml\\)")
5301 (let ((p (point)))
5302 (end-of-line)
5303 (< (- (point) p) 80)))
5304 (zerop (forward-line 1))))
5305 (or (bolp)
5306 (eobp)
5307 (y-or-n-p
5308 "You have lines longer than 79 characters. Really post? ")))
5309 ;; Check whether the article is empty.
5310 (message-check 'empty
5311 (goto-char (point-min))
5312 (re-search-forward
5313 (concat "^" (regexp-quote mail-header-separator) "$"))
5314 (forward-line 1)
5315 (let ((b (point)))
5316 (goto-char (point-max))
5317 (re-search-backward message-signature-separator nil t)
5318 (beginning-of-line)
5319 (or (re-search-backward "[^ \n\t]" b t)
5320 (if (message-gnksa-enable-p 'empty-article)
5321 (y-or-n-p "Empty article. Really post? ")
5322 (message "Denied posting -- Empty article.")
5323 nil))))
5324 ;; Check for control characters.
5325 (message-check 'control-chars
5326 (if (re-search-forward
5327 (string-to-multibyte "[\000-\007\013\015-\032\034-\037\200-\237]")
5328 nil t)
5329 (y-or-n-p
5330 "The article contains control characters. Really post? ")
5331 t))
5332 ;; Check excessive size.
5333 (message-check 'size
5334 (if (> (buffer-size) 60000)
5335 (y-or-n-p
5336 (format "The article is %d octets long. Really post? "
5337 (buffer-size)))
5338 t))
5339 ;; Check whether any new text has been added.
5340 (message-check 'new-text
5341 (or
5342 (not message-checksum)
5343 (not (eq (message-checksum) message-checksum))
5344 (if (message-gnksa-enable-p 'quoted-text-only)
5345 (y-or-n-p
5346 "It looks like no new text has been added. Really post? ")
5347 (message "Denied posting -- no new text has been added.")
5348 nil)))
5349 ;; Check the length of the signature.
5350 (message-check 'signature
5351 (let (sig-start sig-end)
5352 (goto-char (point-max))
5353 (if (not (re-search-backward message-signature-separator nil t))
5354 t
5355 (setq sig-start (1+ (point-at-eol)))
5356 (setq sig-end
5357 (if (re-search-forward
5358 "<#/?\\(multipart\\|part\\|external\\|mml\\)" nil t)
5359 (- (point-at-bol) 1)
5360 (point-max)))
5361 (if (>= (count-lines sig-start sig-end) 5)
5362 (if (message-gnksa-enable-p 'signature)
5363 (y-or-n-p
5364 (format "Signature is excessively long (%d lines). Really post? "
5365 (count-lines sig-start sig-end)))
5366 (message "Denied posting -- Excessive signature.")
5367 nil)
5368 t))))
5369 ;; Ensure that text follows last quoted portion.
5370 (message-check 'quoting-style
5371 (goto-char (point-max))
5372 (let ((no-problem t))
5373 (when (search-backward-regexp "^>[^\n]*\n" nil t)
5374 (setq no-problem (search-forward-regexp "^[ \t]*[^>\n]" nil t)))
5375 (if no-problem
5376 t
5377 (if (message-gnksa-enable-p 'quoted-text-only)
5378 (y-or-n-p "Your text should follow quoted text. Really post? ")
5379 ;; Ensure that
5380 (goto-char (point-min))
5381 (re-search-forward
5382 (concat "^" (regexp-quote mail-header-separator) "$"))
5383 (if (search-forward-regexp "^[ \t]*[^>\n]" nil t)
5384 (y-or-n-p "Your text should follow quoted text. Really post? ")
5385 (message "Denied posting -- only quoted text.")
5386 nil)))))))
5387
5388 (defun message-checksum ()
5389 "Return a \"checksum\" for the current buffer."
5390 (let ((sum 0))
5391 (save-excursion
5392 (goto-char (point-min))
5393 (re-search-forward
5394 (concat "^" (regexp-quote mail-header-separator) "$"))
5395 (while (not (eobp))
5396 (when (not (looking-at "[ \t\n]"))
5397 (setq sum (logxor (ash sum 1) (if (natnump sum) 0 1)
5398 (char-after))))
5399 (forward-char 1)))
5400 sum))
5401
5402 (defun message-do-fcc ()
5403 "Process Fcc headers in the current buffer."
5404 (let ((case-fold-search t)
5405 (buf (current-buffer))
5406 list file
5407 (mml-externalize-attachments message-fcc-externalize-attachments))
5408 (save-excursion
5409 (save-restriction
5410 (message-narrow-to-headers)
5411 (setq file (message-fetch-field "fcc" t)))
5412 (when file
5413 (set-buffer (get-buffer-create " *message temp*"))
5414 (erase-buffer)
5415 (insert-buffer-substring buf)
5416 (message-encode-message-body)
5417 (save-restriction
5418 (message-narrow-to-headers)
5419 (while (setq file (message-fetch-field "fcc" t))
5420 (push file list)
5421 (message-remove-header "fcc" nil t))
5422 (let ((mail-parse-charset message-default-charset)
5423 (rfc2047-header-encoding-alist
5424 (cons '("Newsgroups" . default)
5425 rfc2047-header-encoding-alist)))
5426 (mail-encode-encoded-word-buffer)))
5427 (goto-char (point-min))
5428 (when (re-search-forward
5429 (concat "^" (regexp-quote mail-header-separator) "$")
5430 nil t)
5431 (replace-match "" t t ))
5432 ;; Process FCC operations.
5433 (while list
5434 (setq file (pop list))
5435 (if (string-match "^[ \t]*|[ \t]*\\(.*\\)[ \t]*$" file)
5436 ;; Pipe the article to the program in question.
5437 (call-process-region (point-min) (point-max) shell-file-name
5438 nil nil nil shell-command-switch
5439 (match-string 1 file))
5440 ;; Save the article.
5441 (setq file (expand-file-name file))
5442 (unless (file-exists-p (file-name-directory file))
5443 (make-directory (file-name-directory file) t))
5444 (if (and message-fcc-handler-function
5445 (not (eq message-fcc-handler-function 'rmail-output)))
5446 (funcall message-fcc-handler-function file)
5447 ;; FIXME this option, rmail-output (also used if
5448 ;; message-fcc-handler-function is nil) is not
5449 ;; documented anywhere AFAICS. It should work in Emacs
5450 ;; 23; I suspect it does not work in Emacs 22.
5451 ;; FIXME I don't see the need for the two different cases here.
5452 ;; mail-use-rfc822 makes no difference (in Emacs 23),and
5453 ;; the third argument just controls \"Wrote file\" message.
5454 (if (and (file-readable-p file) (mail-file-babyl-p file))
5455 (rmail-output file 1 nil t)
5456 (let ((mail-use-rfc822 t))
5457 (rmail-output file 1 t t))))))
5458 (kill-buffer (current-buffer))))))
5459
5460 (defun message-output (filename)
5461 "Append this article to Unix/babyl mail file FILENAME."
5462 (if (or (and (file-readable-p filename)
5463 (mail-file-babyl-p filename))
5464 ;; gnus-output-to-mail does the wrong thing with live, mbox
5465 ;; Rmail buffers in Emacs 23.
5466 ;; http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=597255
5467 (let ((buff (find-buffer-visiting filename)))
5468 (and buff (with-current-buffer buff
5469 (eq major-mode 'rmail-mode)))))
5470 (gnus-output-to-rmail filename t)
5471 (gnus-output-to-mail filename t)))
5472
5473 (defun message-cleanup-headers ()
5474 "Do various automatic cleanups of the headers."
5475 ;; Remove empty lines in the header.
5476 (save-restriction
5477 (message-narrow-to-headers)
5478 ;; Remove blank lines.
5479 (while (re-search-forward "^[ \t]*\n" nil t)
5480 (replace-match "" t t))
5481
5482 ;; Correct Newsgroups and Followup-To headers: Change sequence of
5483 ;; spaces to comma and eliminate spaces around commas. Eliminate
5484 ;; embedded line breaks.
5485 (goto-char (point-min))
5486 (while (re-search-forward "^\\(Newsgroups\\|Followup-To\\): +" nil t)
5487 (save-restriction
5488 (narrow-to-region
5489 (point)
5490 (if (re-search-forward "^[^ \t]" nil t)
5491 (match-beginning 0)
5492 (forward-line 1)
5493 (point)))
5494 (goto-char (point-min))
5495 (while (re-search-forward "\n[ \t]+" nil t)
5496 (replace-match " " t t)) ;No line breaks (too confusing)
5497 (goto-char (point-min))
5498 (while (re-search-forward "[ \t\n]*,[ \t\n]*\\|[ \t]+" nil t)
5499 (replace-match "," t t))
5500 (goto-char (point-min))
5501 ;; Remove trailing commas.
5502 (when (re-search-forward ",+$" nil t)
5503 (replace-match "" t t))))))
5504
5505 (defun message-make-date (&optional now)
5506 "Make a valid data header.
5507 If NOW, use that time instead."
5508 (let ((system-time-locale "C"))
5509 (format-time-string "%a, %d %b %Y %T %z" now)))
5510
5511 (defun message-insert-expires (days)
5512 "Insert the Expires header. Expiry in DAYS days."
5513 (interactive "NExpire article in how many days? ")
5514 (save-excursion
5515 (message-position-on-field "Expires" "X-Draft-From")
5516 (insert (message-make-expires-date days))))
5517
5518 (defun message-make-expires-date (days)
5519 "Make date string for the Expires header. Expiry in DAYS days.
5520
5521 In posting styles use `(\"Expires\" (make-expires-date 30))'."
5522 (let* ((cur (decode-time))
5523 (nday (+ days (nth 3 cur))))
5524 (setf (nth 3 cur) nday)
5525 (message-make-date (apply 'encode-time cur))))
5526
5527 (defun message-make-message-id ()
5528 "Make a unique Message-ID."
5529 (concat "<" (message-unique-id)
5530 (let ((psubject (save-excursion (message-fetch-field "subject")))
5531 (psupersedes
5532 (save-excursion (message-fetch-field "supersedes"))))
5533 (if (or
5534 (and message-reply-headers
5535 (mail-header-references message-reply-headers)
5536 (mail-header-subject message-reply-headers)
5537 psubject
5538 (not (string=
5539 (message-strip-subject-re
5540 (mail-header-subject message-reply-headers))
5541 (message-strip-subject-re psubject))))
5542 (and psupersedes
5543 (string-match "_-_@" psupersedes)))
5544 "_-_" ""))
5545 "@" (message-make-fqdn) ">"))
5546
5547 (defvar message-unique-id-char nil)
5548
5549 ;; If you ever change this function, make sure the new version
5550 ;; cannot generate IDs that the old version could.
5551 ;; You might for example insert a "." somewhere (not next to another dot
5552 ;; or string boundary), or modify the "fsf" string.
5553 (defun message-unique-id ()
5554 ;; Don't use microseconds from (current-time), they may be unsupported.
5555 ;; Instead we use this randomly inited counter.
5556 (setq message-unique-id-char
5557 (% (1+ (or message-unique-id-char
5558 (logand (random most-positive-fixnum) (1- (lsh 1 20)))))
5559 ;; (current-time) returns 16-bit ints,
5560 ;; and 2^16*25 just fits into 4 digits i base 36.
5561 (* 25 25)))
5562 (let ((tm (current-time)))
5563 (concat
5564 (if (or (eq system-type 'ms-dos)
5565 ;; message-number-base36 doesn't handle bigints.
5566 (floatp (user-uid)))
5567 (let ((user (downcase (user-login-name))))
5568 (while (string-match "[^a-z0-9_]" user)
5569 (aset user (match-beginning 0) ?_))
5570 user)
5571 (message-number-base36 (user-uid) -1))
5572 (message-number-base36 (+ (car tm)
5573 (lsh (% message-unique-id-char 25) 16)) 4)
5574 (message-number-base36 (+ (nth 1 tm)
5575 (lsh (/ message-unique-id-char 25) 16)) 4)
5576 ;; Append a given name, because while the generated ID is unique
5577 ;; to this newsreader, other newsreaders might otherwise generate
5578 ;; the same ID via another algorithm.
5579 ".fsf")))
5580
5581 (defun message-number-base36 (num len)
5582 (if (if (< len 0)
5583 (<= num 0)
5584 (= len 0))
5585 ""
5586 (concat (message-number-base36 (/ num 36) (1- len))
5587 (char-to-string (aref "zyxwvutsrqponmlkjihgfedcba9876543210"
5588 (% num 36))))))
5589
5590 (defun message-make-organization ()
5591 "Make an Organization header."
5592 (let* ((organization
5593 (when message-user-organization
5594 (if (functionp message-user-organization)
5595 (funcall message-user-organization)
5596 message-user-organization))))
5597 (with-temp-buffer
5598 (mm-enable-multibyte)
5599 (cond ((stringp organization)
5600 (insert organization))
5601 ((and (eq t organization)
5602 message-user-organization-file
5603 (file-exists-p message-user-organization-file))
5604 (insert-file-contents message-user-organization-file)))
5605 (goto-char (point-min))
5606 (while (re-search-forward "[\t\n]+" nil t)
5607 (replace-match "" t t))
5608 (unless (zerop (buffer-size))
5609 (buffer-string)))))
5610
5611 (defun message-make-lines ()
5612 "Count the number of lines and return numeric string."
5613 (save-excursion
5614 (save-restriction
5615 (widen)
5616 (message-goto-body)
5617 (int-to-string (count-lines (point) (point-max))))))
5618
5619 (defun message-make-references ()
5620 "Return the References header for this message."
5621 (when message-reply-headers
5622 (let ((message-id (mail-header-id message-reply-headers))
5623 (references (mail-header-references message-reply-headers)))
5624 (if (or references message-id)
5625 (concat (or references "") (and references " ")
5626 (or message-id ""))
5627 nil))))
5628
5629 (defun message-make-in-reply-to ()
5630 "Return the In-Reply-To header for this message."
5631 (when message-reply-headers
5632 (let ((from (mail-header-from message-reply-headers))
5633 (date (mail-header-date message-reply-headers))
5634 (msg-id (mail-header-id message-reply-headers)))
5635 (when from
5636 (let ((name (mail-extract-address-components from)))
5637 (concat
5638 msg-id (if msg-id " (")
5639 (if (car name)
5640 (if (string-match "[^\000-\177]" (car name))
5641 ;; Quote a string containing non-ASCII characters.
5642 ;; It will make the RFC2047 encoder cause an error
5643 ;; if there are special characters.
5644 (mm-with-multibyte-buffer
5645 (insert (car name))
5646 (goto-char (point-min))
5647 (while (search-forward "\"" nil t)
5648 (when (prog2
5649 (backward-char)
5650 (zerop (% (skip-chars-backward "\\\\") 2))
5651 (goto-char (match-beginning 0)))
5652 (insert "\\"))
5653 (forward-char))
5654 ;; Those quotes will be removed by the RFC2047 encoder.
5655 (concat "\"" (buffer-string) "\""))
5656 (car name))
5657 (nth 1 name))
5658 "'s message of \""
5659 (if (or (not date) (string= date ""))
5660 "(unknown date)" date)
5661 "\"" (if msg-id ")")))))))
5662
5663 (defun message-make-distribution ()
5664 "Make a Distribution header."
5665 (let ((orig-distribution (message-fetch-reply-field "distribution")))
5666 (cond ((functionp message-distribution-function)
5667 (funcall message-distribution-function))
5668 (t orig-distribution))))
5669
5670 (defun message-make-expires ()
5671 "Return an Expires header based on `message-expires'."
5672 (let ((current (current-time))
5673 (future (* 1.0 message-expires 60 60 24)))
5674 ;; Add the future to current.
5675 (setcar current (+ (car current) (round (/ future (expt 2 16)))))
5676 (setcar (cdr current) (+ (nth 1 current) (% (round future) (expt 2 16))))
5677 (message-make-date current)))
5678
5679 (defun message-make-path ()
5680 "Return uucp path."
5681 (let ((login-name (user-login-name)))
5682 (cond ((null message-user-path)
5683 (concat (system-name) "!" login-name))
5684 ((stringp message-user-path)
5685 ;; Support GENERICPATH. Suggested by vixie@decwrl.dec.com.
5686 (concat message-user-path "!" login-name))
5687 (t login-name))))
5688
5689 (defun message-make-from (&optional name address)
5690 "Make a From header."
5691 (let* ((style message-from-style)
5692 (login (or address (message-make-address)))
5693 (fullname (or name user-full-name (user-full-name))))
5694 (when (string= fullname "&")
5695 (setq fullname (user-login-name)))
5696 (with-temp-buffer
5697 (mm-enable-multibyte)
5698 (cond
5699 ((or (null style)
5700 (equal fullname ""))
5701 (insert login))
5702 ((or (eq style 'angles)
5703 (and (not (eq style 'parens))
5704 ;; Use angles if no quoting is needed, or if parens would
5705 ;; need quoting too.
5706 (or (not (string-match "[^- !#-'*+/-9=?A-Z^-~]" fullname))
5707 (let ((tmp (concat fullname nil)))
5708 (while (string-match "([^()]*)" tmp)
5709 (aset tmp (match-beginning 0) ?-)
5710 (aset tmp (1- (match-end 0)) ?-))
5711 (string-match "[\\()]" tmp)))))
5712 (insert fullname)
5713 (goto-char (point-min))
5714 ;; Look for a character that cannot appear unquoted
5715 ;; according to RFC 822.
5716 (when (re-search-forward "[^- !#-'*+/-9=?A-Z^-~]" nil 1)
5717 ;; Quote fullname, escaping specials.
5718 (goto-char (point-min))
5719 (insert "\"")
5720 (while (re-search-forward "[\"\\]" nil 1)
5721 (replace-match "\\\\\\&" t))
5722 (insert "\""))
5723 (insert " <" login ">"))
5724 (t ; 'parens or default
5725 (insert login " (")
5726 (let ((fullname-start (point)))
5727 (insert fullname)
5728 (goto-char fullname-start)
5729 ;; RFC 822 says \ and nonmatching parentheses
5730 ;; must be escaped in comments.
5731 ;; Escape every instance of ()\ ...
5732 (while (re-search-forward "[()\\]" nil 1)
5733 (replace-match "\\\\\\&" t))
5734 ;; ... then undo escaping of matching parentheses,
5735 ;; including matching nested parentheses.
5736 (goto-char fullname-start)
5737 (while (re-search-forward
5738 "\\(\\=\\|[^\\]\\(\\\\\\\\\\)*\\)\\\\(\\(\\([^\\]\\|\\\\\\\\\\)*\\)\\\\)"
5739 nil 1)
5740 (replace-match "\\1(\\3)" t)
5741 (goto-char fullname-start)))
5742 (insert ")")))
5743 (buffer-string))))
5744
5745 (defun message-make-sender ()
5746 "Return the \"real\" user address.
5747 This function tries to ignore all user modifications, and
5748 give as trustworthy answer as possible."
5749 (concat (user-login-name) "@" (system-name)))
5750
5751 (defun message-make-address ()
5752 "Make the address of the user."
5753 (or (message-user-mail-address)
5754 (concat (user-login-name) "@" (message-make-domain))))
5755
5756 (defun message-user-mail-address ()
5757 "Return the pertinent part of `user-mail-address'."
5758 (when (and user-mail-address
5759 (string-match "@.*\\." user-mail-address))
5760 (if (string-match " " user-mail-address)
5761 (nth 1 (mail-extract-address-components user-mail-address))
5762 user-mail-address)))
5763
5764 (defun message-sendmail-envelope-from ()
5765 "Return the envelope from."
5766 (cond ((eq message-sendmail-envelope-from 'header)
5767 (nth 1 (mail-extract-address-components
5768 (message-fetch-field "from"))))
5769 ((stringp message-sendmail-envelope-from)
5770 message-sendmail-envelope-from)
5771 (t
5772 (message-make-address))))
5773
5774 (defun message-make-fqdn ()
5775 "Return user's fully qualified domain name."
5776 (let* ((sysname (system-name))
5777 (user-mail (message-user-mail-address))
5778 (user-domain
5779 (if (and user-mail
5780 (string-match "@\\(.*\\)\\'" user-mail))
5781 (match-string 1 user-mail)))
5782 (case-fold-search t))
5783 (cond
5784 ((and message-user-fqdn
5785 (stringp message-user-fqdn)
5786 (not (string-match message-bogus-system-names message-user-fqdn)))
5787 ;; `message-user-fqdn' seems to be valid
5788 message-user-fqdn)
5789 ((and (string-match message-bogus-system-names sysname))
5790 ;; `system-name' returned the right result.
5791 sysname)
5792 ;; Try `mail-host-address'.
5793 ((and (stringp mail-host-address)
5794 (not (string-match message-bogus-system-names mail-host-address)))
5795 mail-host-address)
5796 ;; We try `user-mail-address' as a backup.
5797 ((and user-domain
5798 (stringp user-domain)
5799 (not (string-match message-bogus-system-names user-domain)))
5800 user-domain)
5801 ;; Default to this bogus thing.
5802 (t
5803 (concat sysname
5804 ".i-did-not-set--mail-host-address--so-tickle-me")))))
5805
5806 (defun message-make-domain ()
5807 "Return the domain name."
5808 (or mail-host-address
5809 (message-make-fqdn)))
5810
5811 (defun message-to-list-only ()
5812 "Send a message to the list only.
5813 Remove all addresses but the list address from To and Cc headers."
5814 (interactive)
5815 (let ((listaddr (message-make-mail-followup-to t)))
5816 (when listaddr
5817 (save-excursion
5818 (message-remove-header "to")
5819 (message-remove-header "cc")
5820 (message-position-on-field "To" "X-Draft-From")
5821 (insert listaddr)))))
5822
5823 (defun message-make-mail-followup-to (&optional only-show-subscribed)
5824 "Return the Mail-Followup-To header.
5825 If passed the optional argument ONLY-SHOW-SUBSCRIBED only return the
5826 subscribed address (and not the additional To and Cc header contents)."
5827 (let* ((case-fold-search t)
5828 (to (message-fetch-field "To"))
5829 (cc (message-fetch-field "cc"))
5830 (msg-recipients (concat to (and to cc ", ") cc))
5831 (recipients
5832 (mapcar 'mail-strip-quoted-names
5833 (message-tokenize-header msg-recipients)))
5834 (file-regexps
5835 (if message-subscribed-address-file
5836 (let (begin end item re)
5837 (save-excursion
5838 (with-temp-buffer
5839 (insert-file-contents message-subscribed-address-file)
5840 (while (not (eobp))
5841 (setq begin (point))
5842 (forward-line 1)
5843 (setq end (point))
5844 (if (bolp) (setq end (1- end)))
5845 (setq item (regexp-quote (buffer-substring begin end)))
5846 (if re (setq re (concat re "\\|" item))
5847 (setq re (concat "\\`\\(" item))))
5848 (and re (list (concat re "\\)\\'"))))))))
5849 (mft-regexps (apply 'append message-subscribed-regexps
5850 (mapcar 'regexp-quote
5851 message-subscribed-addresses)
5852 file-regexps
5853 (mapcar 'funcall
5854 message-subscribed-address-functions))))
5855 (save-match-data
5856 (let ((list
5857 (loop for recipient in recipients
5858 when (loop for regexp in mft-regexps
5859 when (string-match regexp recipient) return t)
5860 return recipient)))
5861 (when list
5862 (if only-show-subscribed
5863 list
5864 msg-recipients))))))
5865
5866 (defun message-idna-to-ascii-rhs-1 (header)
5867 "Interactively potentially IDNA encode domain names in HEADER."
5868 (let ((field (message-fetch-field header))
5869 ace)
5870 (when field
5871 (dolist (rhs
5872 (delete-dups
5873 (mapcar (lambda (rhs) (or (cadr (split-string rhs "@")) ""))
5874 (mapcar 'downcase
5875 (mapcar
5876 (lambda (elem)
5877 (or (cadr elem)
5878 ""))
5879 (mail-extract-address-components field t))))))
5880 ;; Note that `rhs' will be "" if the address does not have
5881 ;; the domain part, i.e., if it is a local user's address.
5882 (setq ace (if (string-match "\\`[[:ascii:]]*\\'" rhs)
5883 rhs
5884 (downcase (idna-to-ascii rhs))))
5885 (when (and (not (equal rhs ace))
5886 (or (not (eq message-use-idna 'ask))
5887 (y-or-n-p (format "Replace %s with %s in %s:? "
5888 rhs ace header))))
5889 (goto-char (point-min))
5890 (while (re-search-forward (concat "^" header ":") nil t)
5891 (message-narrow-to-field)
5892 (while (search-forward (concat "@" rhs) nil t)
5893 (replace-match (concat "@" ace) t t))
5894 (goto-char (point-max))
5895 (widen)))))))
5896
5897 (defun message-idna-to-ascii-rhs ()
5898 "Possibly IDNA encode non-ASCII domain names in From:, To: and Cc: headers.
5899 See `message-idna-encode'."
5900 (interactive)
5901 (when message-use-idna
5902 (save-excursion
5903 (save-restriction
5904 ;; `message-narrow-to-head' that recognizes only the first empty
5905 ;; line as the message header separator used to be used here.
5906 ;; However, since there is the "--text follows this line--" line
5907 ;; normally, it failed in narrowing to the headers and potentially
5908 ;; caused the IDNA encoding on lines that look like headers in
5909 ;; the message body.
5910 (message-narrow-to-headers-or-head)
5911 (message-idna-to-ascii-rhs-1 "From")
5912 (message-idna-to-ascii-rhs-1 "To")
5913 (message-idna-to-ascii-rhs-1 "Reply-To")
5914 (message-idna-to-ascii-rhs-1 "Mail-Reply-To")
5915 (message-idna-to-ascii-rhs-1 "Mail-Followup-To")
5916 (message-idna-to-ascii-rhs-1 "Cc")))))
5917
5918 (defun message-generate-headers (headers)
5919 "Prepare article HEADERS.
5920 Headers already prepared in the buffer are not modified."
5921 (setq headers (append headers message-required-headers))
5922 (save-restriction
5923 (message-narrow-to-headers)
5924 (let* ((header-values
5925 (list 'Date (message-make-date)
5926 'Message-ID (message-make-message-id)
5927 'Organization (message-make-organization)
5928 'From (message-make-from)
5929 'Path (message-make-path)
5930 'Subject nil
5931 'Newsgroups nil
5932 'In-Reply-To (message-make-in-reply-to)
5933 'References (message-make-references)
5934 'To nil
5935 'Distribution (message-make-distribution)
5936 'Lines (message-make-lines)
5937 'User-Agent message-newsreader
5938 'Expires (message-make-expires)))
5939 (case-fold-search t)
5940 (optionalp nil)
5941 header value elem header-string)
5942 ;; First we remove any old generated headers.
5943 (let ((headers message-deletable-headers))
5944 (unless (buffer-modified-p)
5945 (setq headers (delq 'Message-ID (copy-sequence headers))))
5946 (while headers
5947 (goto-char (point-min))
5948 (and (re-search-forward
5949 (concat "^" (symbol-name (car headers)) ": *") nil t)
5950 (get-text-property (1+ (match-beginning 0)) 'message-deletable)
5951 (message-delete-line))
5952 (pop headers)))
5953 ;; Go through all the required headers and see if they are in the
5954 ;; articles already. If they are not, or are empty, they are
5955 ;; inserted automatically - except for Subject, Newsgroups and
5956 ;; Distribution.
5957 (while headers
5958 (goto-char (point-min))
5959 (setq elem (pop headers))
5960 (if (consp elem)
5961 (if (eq (car elem) 'optional)
5962 (setq header (cdr elem)
5963 optionalp t)
5964 (setq header (car elem)))
5965 (setq header elem))
5966 (setq header-string (if (stringp header)
5967 header
5968 (symbol-name header)))
5969 (when (or (not (re-search-forward
5970 (concat "^"
5971 (regexp-quote (downcase header-string))
5972 ":")
5973 nil t))
5974 (progn
5975 ;; The header was found. We insert a space after the
5976 ;; colon, if there is none.
5977 (if (/= (char-after) ? ) (insert " ") (forward-char 1))
5978 ;; Find out whether the header is empty.
5979 (looking-at "[ \t]*\n[^ \t]")))
5980 ;; So we find out what value we should insert.
5981 (setq value
5982 (cond
5983 ((and (consp elem)
5984 (eq (car elem) 'optional)
5985 (not (member header-string message-inserted-headers)))
5986 ;; This is an optional header. If the cdr of this
5987 ;; is something that is nil, then we do not insert
5988 ;; this header.
5989 (setq header (cdr elem))
5990 (or (and (functionp (cdr elem))
5991 (funcall (cdr elem)))
5992 (and (symbolp (cdr elem))
5993 (plist-get header-values (cdr elem)))))
5994 ((consp elem)
5995 ;; The element is a cons. Either the cdr is a
5996 ;; string to be inserted verbatim, or it is a
5997 ;; function, and we insert the value returned from
5998 ;; this function.
5999 (or (and (stringp (cdr elem))
6000 (cdr elem))
6001 (and (functionp (cdr elem))
6002 (funcall (cdr elem)))))
6003 ((and (symbolp header)
6004 (plist-member header-values header))
6005 ;; The element is a symbol. We insert the value of
6006 ;; this symbol, if any.
6007 (plist-get header-values header))
6008 ((not (message-check-element
6009 (intern (downcase (symbol-name header)))))
6010 ;; We couldn't generate a value for this header,
6011 ;; so we just ask the user.
6012 (read-from-minibuffer
6013 (format "Empty header for %s; enter value: " header)))))
6014 ;; Finally insert the header.
6015 (when (and value
6016 (not (equal value "")))
6017 (save-excursion
6018 (if (bolp)
6019 (progn
6020 ;; This header didn't exist, so we insert it.
6021 (goto-char (point-max))
6022 (let ((formatter
6023 (cdr (assq header message-header-format-alist))))
6024 (if formatter
6025 (funcall formatter header value)
6026 (insert header-string ": " value))
6027 (push header-string message-inserted-headers)
6028 (goto-char (message-fill-field))
6029 ;; We check whether the value was ended by a
6030 ;; newline. If not, we insert one.
6031 (unless (bolp)
6032 (insert "\n"))
6033 (forward-line -1)))
6034 ;; The value of this header was empty, so we clear
6035 ;; totally and insert the new value.
6036 (delete-region (point) (point-at-eol))
6037 ;; If the header is optional, and the header was
6038 ;; empty, we can't insert it anyway.
6039 (unless optionalp
6040 (push header-string message-inserted-headers)
6041 (insert value)
6042 (message-fill-field)))
6043 ;; Add the deletable property to the headers that require it.
6044 (and (memq header message-deletable-headers)
6045 (progn (beginning-of-line) (looking-at "[^:]+: "))
6046 (add-text-properties
6047 (point) (match-end 0)
6048 '(message-deletable t face italic) (current-buffer)))))))
6049 ;; Insert new Sender if the From is strange.
6050 (let ((from (message-fetch-field "from"))
6051 (sender (message-fetch-field "sender"))
6052 (secure-sender (message-make-sender)))
6053 (when (and from
6054 (not (message-check-element 'sender))
6055 (not (string=
6056 (downcase
6057 (cadr (mail-extract-address-components from)))
6058 (downcase secure-sender)))
6059 (or (null sender)
6060 (not
6061 (string=
6062 (downcase
6063 (cadr (mail-extract-address-components sender)))
6064 (downcase secure-sender)))))
6065 (goto-char (point-min))
6066 ;; Rename any old Sender headers to Original-Sender.
6067 (when (re-search-forward "^\\(Original-\\)*Sender:" nil t)
6068 (beginning-of-line)
6069 (insert "Original-")
6070 (beginning-of-line))
6071 (when (or (message-news-p)
6072 (string-match "@.+\\.." secure-sender))
6073 (insert "Sender: " secure-sender "\n"))))
6074 ;; Check for IDNA
6075 (message-idna-to-ascii-rhs))))
6076
6077 (defun message-insert-courtesy-copy (message)
6078 "Insert a courtesy message in mail copies of combined messages."
6079 (let (newsgroups)
6080 (save-excursion
6081 (save-restriction
6082 (message-narrow-to-headers)
6083 (when (setq newsgroups (message-fetch-field "newsgroups"))
6084 (goto-char (point-max))
6085 (insert "Posted-To: " newsgroups "\n")))
6086 (forward-line 1)
6087 (when message
6088 (cond
6089 ((string-match "%s" message)
6090 (insert (format message newsgroups)))
6091 (t
6092 (insert message)))))))
6093
6094 ;;;
6095 ;;; Setting up a message buffer
6096 ;;;
6097
6098 (defun message-skip-to-next-address ()
6099 (let ((end (save-excursion
6100 (message-next-header)
6101 (point)))
6102 quoted char)
6103 (when (looking-at ",")
6104 (forward-char 1))
6105 (while (and (not (= (point) end))
6106 (or (not (eq char ?,))
6107 quoted))
6108 (skip-chars-forward "^,\"" end)
6109 (when (eq (setq char (following-char)) ?\")
6110 (setq quoted (not quoted)))
6111 (unless (= (point) end)
6112 (forward-char 1)))
6113 (skip-chars-forward " \t\n")))
6114
6115 (defun message-split-line ()
6116 "Split current line, moving portion beyond point vertically down.
6117 If the current line has `message-yank-prefix', insert it on the new line."
6118 (interactive "*")
6119 (condition-case nil
6120 (split-line message-yank-prefix) ;; Emacs 22.1+ supports arg.
6121 (error
6122 (split-line))))
6123
6124 (defun message-insert-header (header value)
6125 (insert (capitalize (symbol-name header))
6126 ": "
6127 (if (consp value) (car value) value)))
6128
6129 (defun message-field-name ()
6130 (save-excursion
6131 (goto-char (point-min))
6132 (when (looking-at "\\([^:]+\\):")
6133 (intern (capitalize (match-string 1))))))
6134
6135 (defun message-fill-field ()
6136 (save-excursion
6137 (save-restriction
6138 (message-narrow-to-field)
6139 (let ((field-name (message-field-name)))
6140 (funcall (or (cadr (assq field-name message-field-fillers))
6141 'message-fill-field-general)))
6142 (point-max))))
6143
6144 (defun message-fill-field-address ()
6145 (let (end last)
6146 (while (not end)
6147 (message-skip-to-next-address)
6148 (cond ((bolp)
6149 (end-of-line 0)
6150 (setq end 1))
6151 ((eobp)
6152 (setq end 0)))
6153 (when (and (> (current-column) 78)
6154 last)
6155 (save-excursion
6156 (goto-char last)
6157 (delete-char (- (skip-chars-backward " \t")))
6158 (insert "\n\t")))
6159 (setq last (point)))
6160 (forward-line end)))
6161
6162 (defun message-fill-field-general ()
6163 (let ((begin (point))
6164 (fill-column 78)
6165 (fill-prefix "\t"))
6166 (while (and (search-forward "\n" nil t)
6167 (not (eobp)))
6168 (replace-match " " t t))
6169 (fill-region-as-paragraph begin (point-max))
6170 ;; Tapdance around looong Message-IDs.
6171 (forward-line -1)
6172 (when (looking-at "[ \t]*$")
6173 (message-delete-line))
6174 (goto-char begin)
6175 (search-forward ":" nil t)
6176 (when (looking-at "\n[ \t]+")
6177 (replace-match " " t t))
6178 (goto-char (point-max))))
6179
6180 (defun message-shorten-1 (list cut surplus)
6181 "Cut SURPLUS elements out of LIST, beginning with CUTth one."
6182 (setcdr (nthcdr (- cut 2) list)
6183 (nthcdr (+ (- cut 2) surplus 1) list)))
6184
6185 (defun message-shorten-references (header references)
6186 "Trim REFERENCES to be 21 Message-ID long or less, and fold them.
6187 When sending via news, also check that the REFERENCES are less
6188 than 988 characters long, and if they are not, trim them until
6189 they are."
6190 ;; 21 is the number suggested by USAGE.
6191 (let ((maxcount 21)
6192 (count 0)
6193 (cut 2)
6194 refs)
6195 (with-temp-buffer
6196 (insert references)
6197 (goto-char (point-min))
6198 ;; Cons a list of valid references. GNKSA says we must not include MIDs
6199 ;; with whitespace or missing brackets (7.a "Does not propagate broken
6200 ;; Message-IDs in original References").
6201 (while (re-search-forward "<[^ <]+@[^ <]+>" nil t)
6202 (push (match-string 0) refs))
6203 (setq refs (nreverse refs)
6204 count (length refs)))
6205
6206 ;; If the list has more than MAXCOUNT elements, trim it by
6207 ;; removing the CUTth element and the required number of
6208 ;; elements that follow.
6209 (when (> count maxcount)
6210 (let ((surplus (- count maxcount)))
6211 (message-shorten-1 refs cut surplus)
6212 (decf count surplus)))
6213
6214 ;; When sending via news, make sure the total folded length will
6215 ;; be less than 998 characters. This is to cater to broken INN
6216 ;; 2.3 which counts the total number of characters in a header
6217 ;; rather than the physical line length of each line, as it should.
6218 ;;
6219 ;; This hack should be removed when it's believed than INN 2.3 is
6220 ;; no longer widely used.
6221 ;;
6222 ;; At this point the headers have not been generated, thus we use
6223 ;; message-this-is-news directly.
6224 (when message-this-is-news
6225 (while (< 998
6226 (with-temp-buffer
6227 (message-insert-header
6228 header (mapconcat #'identity refs " "))
6229 (buffer-size)))
6230 (message-shorten-1 refs cut 1)))
6231 ;; Finally, collect the references back into a string and insert
6232 ;; it into the buffer.
6233 (message-insert-header header (mapconcat #'identity refs " "))))
6234
6235 (defun message-position-point ()
6236 "Move point to where the user probably wants to find it."
6237 (message-narrow-to-headers)
6238 (cond
6239 ((re-search-forward "^[^:]+:[ \t]*$" nil t)
6240 (search-backward ":" )
6241 (widen)
6242 (forward-char 1)
6243 (if (eq (char-after) ? )
6244 (forward-char 1)
6245 (insert " ")))
6246 (t
6247 (goto-char (point-max))
6248 (widen)
6249 (forward-line 1)
6250 (unless (looking-at "$")
6251 (forward-line 2)))
6252 (sit-for 0)))
6253
6254 (defcustom message-beginning-of-line t
6255 "Whether \\<message-mode-map>\\[message-beginning-of-line]\
6256 goes to beginning of header values."
6257 :version "22.1"
6258 :group 'message-buffers
6259 :link '(custom-manual "(message)Movement")
6260 :type 'boolean)
6261
6262 (defvar visual-line-mode)
6263 (declare-function beginning-of-visual-line "simple" (&optional n))
6264
6265 (defun message-beginning-of-header (handle-folded)
6266 "Move point to beginning of header’s value.
6267
6268 When point is at the first header line, moves it after the colon
6269 and spaces separating header name and header value.
6270
6271 When point is in a continuation line of a folded header (i.e. the
6272 line starts with a space), the behaviour depends on HANDLE-FOLDED
6273 argument. If it’s nil, function moves the point to the start of
6274 the header continuation; otherwise, function locates the
6275 beginning of the header and moves point past the colon as is the
6276 case of single-line headers.
6277
6278 No check whether point is inside of a header or body of the
6279 message is performed.
6280
6281 Returns point or nil if beginning of header’s value could not be
6282 found. In the latter case, the point is still moved to the
6283 beginning of line (possibly after attempting to move it to the
6284 beginning of a folded header)."
6285 ;; https://www.rfc-editor.org/rfc/rfc2822.txt, section 2.2.3. says that when
6286 ;; unfolding a single WSP should be consumed. WSP is defined as a space
6287 ;; character or a horizontal tab.
6288 (beginning-of-line)
6289 (when handle-folded
6290 (while (and (> (point) (point-min))
6291 (or (eq (char-after) ?\s) (eq (char-after) ?\t)))
6292 (beginning-of-line 0)))
6293 (when (or (eq (char-after) ?\s) (eq (char-after) ?\t)
6294 (search-forward ":" (point-at-eol) t))
6295 ;; We are a bit more lacks than the RFC and allow any positive number of WSP
6296 ;; characters.
6297 (skip-chars-forward " \t" (point-at-eol))
6298 (point)))
6299
6300 (defun message-beginning-of-line (&optional n)
6301 "Move point to beginning of header value or to beginning of line.
6302 The prefix argument N is passed directly to `beginning-of-line'.
6303
6304 This command is identical to `beginning-of-line' if point is
6305 outside the message header or if the option
6306 `message-beginning-of-line' is nil.
6307
6308 If point is in the message header and on a header line, move
6309 point to the beginning of the header value or the beginning of
6310 line, whichever is closer. If point is already at beginning of
6311 line, move point to beginning of header value. Therefore,
6312 repeated calls will toggle point between beginning of field and
6313 beginning of line.
6314
6315 When called without a prefix argument, header value spanning
6316 multiple lines is treated as a single line. Otherwise, even if
6317 N is 1, when point is on a continuation header line, it will be
6318 moved to the beginning "
6319 (interactive "p")
6320 (cond
6321 ;; Go to beginning of header or beginning of line.
6322 ((and message-beginning-of-line (message-point-in-header-p))
6323 (let* ((point (point))
6324 (bol (progn (beginning-of-line n) (point)))
6325 (boh (message-beginning-of-header visual-line-mode)))
6326 (goto-char (if (and boh (or (< boh point) (= bol point))) boh bol))))
6327 ;; Go to beginning of visual line
6328 (visual-line-mode
6329 (beginning-of-visual-line n))
6330 ;; Go to beginning of line.
6331 ((beginning-of-line n))))
6332
6333 (defun message-buffer-name (type &optional to group)
6334 "Return a new (unique) buffer name based on TYPE and TO."
6335 (cond
6336 ;; Generate a new buffer name The Message Way.
6337 ((memq message-generate-new-buffers '(unique t))
6338 (generate-new-buffer-name
6339 (concat "*" type
6340 (if to
6341 (concat " to "
6342 (or (car (mail-extract-address-components to))
6343 to) "")
6344 "")
6345 (if (and group (not (string= group ""))) (concat " on " group) "")
6346 "*")))
6347 ;; Check whether `message-generate-new-buffers' is a function,
6348 ;; and if so, call it.
6349 ((functionp message-generate-new-buffers)
6350 (funcall message-generate-new-buffers type to group))
6351 ((eq message-generate-new-buffers 'unsent)
6352 (generate-new-buffer-name
6353 (concat "*unsent " type
6354 (if to
6355 (concat " to "
6356 (or (car (mail-extract-address-components to))
6357 to) "")
6358 "")
6359 (if (and group (not (string= group ""))) (concat " on " group) "")
6360 "*")))
6361 ;; Search for the existing message buffer with the specified name.
6362 (t
6363 (let* ((new (if (eq message-generate-new-buffers 'standard)
6364 (generate-new-buffer-name (concat "*" type " message*"))
6365 (let ((message-generate-new-buffers 'unique))
6366 (message-buffer-name type to group))))
6367 (regexp (concat "\\`"
6368 (regexp-quote
6369 (if (string-match "<[0-9]+>\\'" new)
6370 (substring new 0 (match-beginning 0))
6371 new))
6372 "\\(?:<\\([0-9]+\\)>\\)?\\'"))
6373 (case-fold-search nil))
6374 (or (cdar
6375 (last
6376 (sort
6377 (delq nil
6378 (mapcar
6379 (lambda (b)
6380 (when (and (string-match regexp (setq b (buffer-name b)))
6381 (eq (with-current-buffer b major-mode)
6382 'message-mode))
6383 (cons (string-to-number (or (match-string 1 b) "1"))
6384 b)))
6385 (buffer-list)))
6386 'car-less-than-car)))
6387 new)))))
6388
6389 (defun message-pop-to-buffer (name &optional switch-function)
6390 "Pop to buffer NAME, and warn if it already exists and is modified."
6391 (let ((buffer (get-buffer name)))
6392 (if (and buffer
6393 (buffer-name buffer))
6394 (let ((window (get-buffer-window buffer 0)))
6395 (if window
6396 ;; Raise the frame already displaying the message buffer.
6397 (progn
6398 (select-frame-set-input-focus (window-frame window))
6399 (select-window window))
6400 (funcall (or switch-function #'pop-to-buffer) buffer)
6401 (set-buffer buffer))
6402 (when (and (buffer-modified-p)
6403 (not (prog1
6404 (y-or-n-p
6405 "Message already being composed; erase? ")
6406 (message nil))))
6407 (error "Message being composed")))
6408 (funcall (or switch-function 'pop-to-buffer-same-window)
6409 name)
6410 (set-buffer name))
6411 (erase-buffer)
6412 (message-mode)))
6413
6414 (defun message-do-send-housekeeping ()
6415 "Kill old message buffers."
6416 ;; We might have sent this buffer already. Delete it from the
6417 ;; list of buffers.
6418 (setq message-buffer-list (delq (current-buffer) message-buffer-list))
6419 (while (and message-max-buffers
6420 message-buffer-list
6421 (>= (length message-buffer-list) message-max-buffers))
6422 ;; Kill the oldest buffer -- unless it has been changed.
6423 (let ((buffer (pop message-buffer-list)))
6424 (when (and (buffer-name buffer)
6425 (not (buffer-modified-p buffer)))
6426 (kill-buffer buffer))))
6427 ;; Rename the buffer.
6428 (if message-send-rename-function
6429 (funcall message-send-rename-function)
6430 (message-default-send-rename-function))
6431 ;; Push the current buffer onto the list.
6432 (when message-max-buffers
6433 (setq message-buffer-list
6434 (nconc message-buffer-list (list (current-buffer))))))
6435
6436 (defun message-default-send-rename-function ()
6437 ;; Note: mail-abbrevs of XEmacs renames buffer name behind Gnus.
6438 (when (string-match
6439 "\\`\\*\\(sent \\|unsent \\)?\\(.+\\)\\*[^\\*]*\\|\\`mail to "
6440 (buffer-name))
6441 (let ((name (match-string 2 (buffer-name)))
6442 to group)
6443 (if (not (or (null name)
6444 (string-equal name "mail")
6445 (string-equal name "posting")))
6446 (setq name (concat "*sent " name "*"))
6447 (message-narrow-to-headers)
6448 (setq to (message-fetch-field "to"))
6449 (setq group (message-fetch-field "newsgroups"))
6450 (widen)
6451 (setq name
6452 (cond
6453 (to (concat "*sent mail to "
6454 (or (car (mail-extract-address-components to))
6455 to) "*"))
6456 ((and group (not (string= group "")))
6457 (concat "*sent posting on " group "*"))
6458 (t "*sent mail*"))))
6459 (unless (string-equal name (buffer-name))
6460 (rename-buffer name t)))))
6461
6462 (defun message-mail-user-agent ()
6463 (let ((mua (cond
6464 ((not message-mail-user-agent) nil)
6465 ((eq message-mail-user-agent t) mail-user-agent)
6466 (t message-mail-user-agent))))
6467 (if (memq mua '(message-user-agent gnus-user-agent))
6468 nil
6469 mua)))
6470
6471 ;; YANK-ACTION, if non-nil, can be a buffer or a yank action of the
6472 ;; form (FUNCTION . ARGS).
6473 (defun message-setup (headers &optional yank-action actions
6474 continue switch-function return-action)
6475 (let ((mua (message-mail-user-agent))
6476 subject to field)
6477 (if (not (and message-this-is-mail mua))
6478 (message-setup-1 headers yank-action actions return-action)
6479 (setq headers (copy-sequence headers))
6480 (setq field (assq 'Subject headers))
6481 (when field
6482 (setq subject (cdr field))
6483 (setq headers (delq field headers)))
6484 (setq field (assq 'To headers))
6485 (when field
6486 (setq to (cdr field))
6487 (setq headers (delq field headers)))
6488 (let ((mail-user-agent mua))
6489 (compose-mail to subject
6490 (mapcar (lambda (item)
6491 (cons
6492 (format "%s" (car item))
6493 (cdr item)))
6494 headers)
6495 continue switch-function
6496 (if (bufferp yank-action)
6497 (list 'insert-buffer yank-action)
6498 yank-action)
6499 actions)))))
6500
6501 (defun message-headers-to-generate (headers included-headers excluded-headers)
6502 "Return a list that includes all headers from HEADERS.
6503 If INCLUDED-HEADERS is a list, just include those headers. If it is
6504 t, include all headers. In any case, headers from EXCLUDED-HEADERS
6505 are not included."
6506 (let ((result nil)
6507 header-name)
6508 (dolist (header headers)
6509 (setq header-name (cond
6510 ((and (consp header)
6511 (eq (car header) 'optional))
6512 ;; On the form (optional . Header)
6513 (cdr header))
6514 ((consp header)
6515 ;; On the form (Header . function)
6516 (car header))
6517 (t
6518 ;; Just a Header.
6519 header)))
6520 (when (and (not (memq header-name excluded-headers))
6521 (or (eq included-headers t)
6522 (memq header-name included-headers)))
6523 (push header result)))
6524 (nreverse result)))
6525
6526 (defun message-setup-1 (headers &optional yank-action actions return-action)
6527 (dolist (action actions)
6528 (condition-case nil
6529 (add-to-list 'message-send-actions
6530 `(apply ',(car action) ',(cdr action)))))
6531 (setq message-return-action return-action)
6532 (setq message-reply-buffer
6533 (if (and (consp yank-action)
6534 (eq (car yank-action) 'insert-buffer))
6535 (nth 1 yank-action)
6536 yank-action))
6537 (goto-char (point-min))
6538 ;; Insert all the headers.
6539 (mail-header-format
6540 (let ((h headers)
6541 (alist message-header-format-alist))
6542 (while h
6543 (unless (assq (caar h) message-header-format-alist)
6544 (push (list (caar h)) alist))
6545 (pop h))
6546 alist)
6547 headers)
6548 (delete-region (point) (progn (forward-line -1) (point)))
6549 (when message-default-headers
6550 (insert
6551 (if (functionp message-default-headers)
6552 (funcall message-default-headers)
6553 message-default-headers))
6554 (or (bolp) (insert ?\n)))
6555 (insert (concat mail-header-separator "\n"))
6556 (forward-line -1)
6557 ;; If a crash happens while replying, the auto-save file would *not* have a
6558 ;; `References:' header if `message-generate-headers-first' was nil.
6559 ;; Therefore, always generate it first.
6560 (let ((message-generate-headers-first
6561 (if (eq message-generate-headers-first t)
6562 t
6563 (append message-generate-headers-first '(References)))))
6564 (when (message-news-p)
6565 (when message-default-news-headers
6566 (insert message-default-news-headers)
6567 (or (bolp) (insert ?\n)))
6568 (message-generate-headers
6569 (message-headers-to-generate
6570 (append message-required-news-headers
6571 message-required-headers)
6572 message-generate-headers-first
6573 '(Lines Subject))))
6574 (when (message-mail-p)
6575 (when message-default-mail-headers
6576 (insert message-default-mail-headers)
6577 (or (bolp) (insert ?\n)))
6578 (message-generate-headers
6579 (message-headers-to-generate
6580 (append message-required-mail-headers
6581 message-required-headers)
6582 message-generate-headers-first
6583 '(Lines Subject)))))
6584 (run-hooks 'message-signature-setup-hook)
6585 (message-insert-signature)
6586 (save-restriction
6587 (message-narrow-to-headers)
6588 (run-hooks 'message-header-setup-hook))
6589 (setq buffer-undo-list nil)
6590 (when message-generate-hashcash
6591 ;; Generate hashcash headers for recipients already known
6592 (mail-add-payment-async))
6593 ;; Gnus posting styles are applied via buffer-local `message-setup-hook'
6594 ;; values.
6595 (run-hooks 'message-setup-hook)
6596 ;; Do this last to give it precedence over posting styles, etc.
6597 (when (message-mail-p)
6598 (save-restriction
6599 (message-narrow-to-headers)
6600 (if message-alternative-emails
6601 (message-use-alternative-email-as-from))))
6602 (message-position-point)
6603 ;; Allow correct handling of `message-checksum' in `message-yank-original':
6604 (set-buffer-modified-p nil)
6605 (undo-boundary)
6606 ;; rmail-start-mail expects message-mail to return t (Bug#9392)
6607 t)
6608
6609 (defun message-set-auto-save-file-name ()
6610 "Associate the message buffer with a file in the drafts directory."
6611 (when message-auto-save-directory
6612 (unless (file-directory-p
6613 (directory-file-name message-auto-save-directory))
6614 (make-directory message-auto-save-directory t))
6615 (if (gnus-alive-p)
6616 (setq message-draft-article
6617 (nndraft-request-associate-buffer "drafts"))
6618
6619 ;; If Gnus were alive, draft messages would be saved in the drafts folder.
6620 ;; But Gnus is not alive, so arrange to save the draft message in a
6621 ;; regular file in message-auto-save-directory. Append a unique
6622 ;; time-based suffix to the filename to allow multiple drafts to be saved
6623 ;; simultaneously without overwriting each other (which mimics the
6624 ;; functionality of the Gnus drafts folder).
6625 (setq buffer-file-name (expand-file-name
6626 (concat
6627 (if (memq system-type
6628 '(ms-dos windows-nt cygwin))
6629 "message"
6630 "*message*")
6631 (format-time-string "-%Y%m%d-%H%M%S"))
6632 message-auto-save-directory))
6633 (setq buffer-auto-save-file-name (make-auto-save-file-name)))
6634 (clear-visited-file-modtime)
6635 (setq buffer-file-coding-system message-draft-coding-system)))
6636
6637 (defun message-disassociate-draft ()
6638 "Disassociate the message buffer from the drafts directory."
6639 (when message-draft-article
6640 (nndraft-request-expire-articles
6641 (list message-draft-article) "drafts" nil t)))
6642
6643 (defun message-insert-headers ()
6644 "Generate the headers for the article."
6645 (interactive)
6646 (save-excursion
6647 (save-restriction
6648 (message-narrow-to-headers)
6649 (when (message-news-p)
6650 (message-generate-headers
6651 (delq 'Lines
6652 (delq 'Subject
6653 (copy-sequence message-required-news-headers)))))
6654 (when (message-mail-p)
6655 (message-generate-headers
6656 (delq 'Lines
6657 (delq 'Subject
6658 (copy-sequence message-required-mail-headers))))))))
6659
6660 \f
6661
6662 ;;;
6663 ;;; Commands for interfacing with message
6664 ;;;
6665
6666 ;;;###autoload
6667 (defun message-mail (&optional to subject other-headers continue
6668 switch-function yank-action send-actions
6669 return-action &rest ignored)
6670 "Start editing a mail message to be sent.
6671 OTHER-HEADERS is an alist of header/value pairs. CONTINUE says whether
6672 to continue editing a message already being composed. SWITCH-FUNCTION
6673 is a function used to switch to and display the mail buffer."
6674 (interactive)
6675 (let ((message-this-is-mail t))
6676 (unless (message-mail-user-agent)
6677 (message-pop-to-buffer
6678 ;; Search for the existing message buffer if `continue' is non-nil.
6679 (let ((message-generate-new-buffers
6680 (when (or (not continue)
6681 (eq message-generate-new-buffers 'standard)
6682 (functionp message-generate-new-buffers))
6683 message-generate-new-buffers)))
6684 (message-buffer-name "mail" to))
6685 switch-function))
6686 (message-setup
6687 (nconc
6688 `((To . ,(or to "")) (Subject . ,(or subject "")))
6689 ;; C-h f compose-mail says that headers should be specified as
6690 ;; (string . value); however all the rest of message expects
6691 ;; headers to be symbols, not strings (eg message-header-format-alist).
6692 ;; http://lists.gnu.org/archive/html/emacs-devel/2011-01/msg00337.html
6693 ;; We need to convert any string input, eg from rmail-start-mail.
6694 (dolist (h other-headers other-headers)
6695 (if (stringp (car h)) (setcar h (intern (capitalize (car h)))))))
6696 yank-action send-actions continue switch-function
6697 return-action)))
6698
6699 ;;;###autoload
6700 (defun message-news (&optional newsgroups subject)
6701 "Start editing a news article to be sent."
6702 (interactive)
6703 (let ((message-this-is-news t))
6704 (message-pop-to-buffer (message-buffer-name "posting" nil newsgroups))
6705 (message-setup `((Newsgroups . ,(or newsgroups ""))
6706 (Subject . ,(or subject ""))))))
6707
6708 (defun message-alter-recipients-discard-bogus-full-name (addrcell)
6709 "Discard mail address in full names.
6710 When the full name in reply headers contains the mail
6711 address (e.g. \"foo@bar <foo@bar>\"), discard full name.
6712 ADDRCELL is a cons cell where the car is the mail address and the
6713 cdr is the complete address (full name and mail address)."
6714 (if (string-match (concat (regexp-quote (car addrcell)) ".*"
6715 (regexp-quote (car addrcell)))
6716 (cdr addrcell))
6717 (cons (car addrcell) (car addrcell))
6718 addrcell))
6719
6720 (defcustom message-alter-recipients-function nil
6721 "Function called to allow alteration of reply header structures.
6722 It is called in `message-get-reply-headers' for each recipient.
6723 The function is called with one parameter, a cons cell ..."
6724 :type '(choice (const :tag "None" nil)
6725 (const :tag "Discard bogus full name"
6726 message-alter-recipients-discard-bogus-full-name)
6727 function)
6728 :version "23.1" ;; No Gnus
6729 :group 'message-headers)
6730
6731 (defun message-get-reply-headers (wide &optional to-address address-headers)
6732 (let (follow-to mct never-mct to cc author mft recipients extra)
6733 ;; Find all relevant headers we need.
6734 (save-restriction
6735 (message-narrow-to-headers-or-head)
6736 ;; Gmane renames "To". Look at "Original-To", too, if it is present in
6737 ;; message-header-synonyms.
6738 (setq to (or (message-fetch-field "to")
6739 (and (loop for synonym in message-header-synonyms
6740 when (memq 'Original-To synonym)
6741 return t)
6742 (message-fetch-field "original-to")))
6743 cc (message-fetch-field "cc")
6744 extra (when message-extra-wide-headers
6745 (mapconcat 'identity
6746 (mapcar 'message-fetch-field
6747 message-extra-wide-headers)
6748 ", "))
6749 mct (message-fetch-field "mail-copies-to")
6750 author (or (message-fetch-field "mail-reply-to")
6751 (message-fetch-field "reply-to"))
6752 mft (and message-use-mail-followup-to
6753 (message-fetch-field "mail-followup-to")))
6754 ;; Make sure this message goes to the author if this is a wide
6755 ;; reply, since Reply-To address may be a list address a mailing
6756 ;; list server added.
6757 (when (and wide author)
6758 (setq cc (concat author ", " cc)))
6759 (when (or wide (not author))
6760 (setq author (or (message-fetch-field "from") ""))))
6761
6762 ;; Handle special values of Mail-Copies-To.
6763 (when mct
6764 (cond ((or (equal (downcase mct) "never")
6765 (equal (downcase mct) "nobody"))
6766 (setq never-mct t)
6767 (setq mct nil))
6768 ((or (equal (downcase mct) "always")
6769 (equal (downcase mct) "poster"))
6770 (setq mct author))))
6771
6772 (save-match-data
6773 ;; Build (textual) list of new recipient addresses.
6774 (cond
6775 (to-address
6776 (setq recipients (concat ", " to-address))
6777 ;; If the author explicitly asked for a copy, we don't deny it to them.
6778 (if mct (setq recipients (concat recipients ", " mct))))
6779 ((not wide)
6780 (setq recipients (concat ", " author)))
6781 (address-headers
6782 (dolist (header address-headers)
6783 (let ((value (message-fetch-field header)))
6784 (when value
6785 (setq recipients (concat recipients ", " value))))))
6786 ((and mft
6787 (string-match "[^ \t,]" mft)
6788 (or (not (eq message-use-mail-followup-to 'ask))
6789 (message-y-or-n-p "Obey Mail-Followup-To? " t "\
6790 You should normally obey the Mail-Followup-To: header. In this
6791 article, it has the value of
6792
6793 " mft "
6794
6795 which directs your response to " (if (string-match "," mft)
6796 "the specified addresses"
6797 "that address only") ".
6798
6799 Most commonly, Mail-Followup-To is used by a mailing list poster to
6800 express that responses should be sent to just the list, and not the
6801 poster as well.
6802
6803 If a message is posted to several mailing lists, Mail-Followup-To may
6804 also be used to direct the following discussion to one list only,
6805 because discussions that are spread over several lists tend to be
6806 fragmented and very difficult to follow.
6807
6808 Also, some source/announcement lists are not intended for discussion;
6809 responses here are directed to other addresses.
6810
6811 You may customize the variable `message-use-mail-followup-to', if you
6812 want to get rid of this query permanently.")))
6813 (setq recipients (concat ", " mft)))
6814 (t
6815 (setq recipients (if never-mct "" (concat ", " author)))
6816 (if to (setq recipients (concat recipients ", " to)))
6817 (if cc (setq recipients (concat recipients ", " cc)))
6818 (if extra (setq recipients (concat recipients ", " extra)))
6819 (if mct (setq recipients (concat recipients ", " mct)))))
6820 (if (>= (length recipients) 2)
6821 ;; Strip the leading ", ".
6822 (setq recipients (substring recipients 2)))
6823 ;; Squeeze whitespace.
6824 (while (string-match "[ \t][ \t]+" recipients)
6825 (setq recipients (replace-match " " t t recipients)))
6826 ;; Remove addresses that match `message-dont-reply-to-names'.
6827 (setq recipients
6828 (cond ((functionp message-dont-reply-to-names)
6829 (mapconcat
6830 'identity
6831 (delq nil
6832 (mapcar (lambda (mail)
6833 (unless (funcall message-dont-reply-to-names
6834 (mail-strip-quoted-names mail))
6835 mail))
6836 (message-tokenize-header recipients)))
6837 ", "))
6838 (t (let ((mail-dont-reply-to-names (message-dont-reply-to-names)))
6839 (mail-dont-reply-to recipients)))))
6840 ;; Perhaps "Mail-Copies-To: never" removed the only address?
6841 (if (string-equal recipients "")
6842 (setq recipients author))
6843 ;; Convert string to a list of (("foo@bar" . "Name <Foo@BAR>") ...).
6844 (setq recipients
6845 (mapcar
6846 (lambda (addr)
6847 (if message-alter-recipients-function
6848 (funcall message-alter-recipients-function
6849 (cons (downcase (mail-strip-quoted-names addr))
6850 addr))
6851 (cons (downcase (mail-strip-quoted-names addr)) addr)))
6852 (message-tokenize-header recipients)))
6853 ;; Remove all duplicates.
6854 (let ((s recipients))
6855 (while s
6856 (let ((address (car (pop s))))
6857 (while (assoc address s)
6858 (setq recipients (delq (assoc address s) recipients)
6859 s (delq (assoc address s) s))))))
6860
6861 ;; Remove hierarchical lists that are contained within each other,
6862 ;; if message-hierarchical-addresses is defined.
6863 (when message-hierarchical-addresses
6864 (let ((plain-addrs (mapcar 'car recipients))
6865 subaddrs recip)
6866 (while plain-addrs
6867 (setq subaddrs (assoc (car plain-addrs)
6868 message-hierarchical-addresses)
6869 plain-addrs (cdr plain-addrs))
6870 (when subaddrs
6871 (setq subaddrs (cdr subaddrs))
6872 (while subaddrs
6873 (setq recip (assoc (car subaddrs) recipients)
6874 subaddrs (cdr subaddrs))
6875 (if recip
6876 (setq recipients (delq recip recipients))))))))
6877
6878 (setq recipients (message-prune-recipients recipients))
6879
6880 ;; Build the header alist. Allow the user to be asked whether
6881 ;; or not to reply to all recipients in a wide reply.
6882 (setq follow-to (list (cons 'To (cdr (pop recipients)))))
6883 (when (and recipients
6884 (or (not message-wide-reply-confirm-recipients)
6885 (y-or-n-p "Reply to all recipients? ")))
6886 (setq recipients (mapconcat
6887 (lambda (addr) (cdr addr)) recipients ", "))
6888 (if (string-match "^ +" recipients)
6889 (setq recipients (substring recipients (match-end 0))))
6890 (push (cons 'Cc recipients) follow-to)))
6891 follow-to))
6892
6893 (defun message-prune-recipients (recipients)
6894 (dolist (rule message-prune-recipient-rules)
6895 (let ((match (car rule))
6896 dup-match
6897 address)
6898 (dolist (recipient recipients)
6899 (setq address (car recipient))
6900 (when (string-match match address)
6901 (setq dup-match (replace-match (cadr rule) nil nil address))
6902 (dolist (recipient recipients)
6903 ;; Don't delete the address that triggered this.
6904 (when (and (not (eq address (car recipient)))
6905 (string-match dup-match (car recipient)))
6906 (setq recipients (delq recipient recipients))))))))
6907 recipients)
6908
6909 (defcustom message-simplify-subject-functions
6910 '(message-strip-list-identifiers
6911 message-strip-subject-re
6912 message-strip-subject-trailing-was
6913 message-strip-subject-encoded-words)
6914 "List of functions taking a string argument that simplify subjects.
6915 The functions are applied when replying to a message.
6916
6917 Useful functions to put in this list include:
6918 `message-strip-list-identifiers', `message-strip-subject-re',
6919 `message-strip-subject-trailing-was', and
6920 `message-strip-subject-encoded-words'."
6921 :version "22.1" ;; Gnus 5.10.9
6922 :group 'message-various
6923 :type '(repeat function))
6924
6925 (defun message-simplify-subject (subject &optional functions)
6926 "Return simplified SUBJECT."
6927 (unless functions
6928 ;; Simplify fully:
6929 (setq functions message-simplify-subject-functions))
6930 (when (and (memq 'message-strip-list-identifiers functions)
6931 gnus-list-identifiers)
6932 (setq subject (message-strip-list-identifiers subject)))
6933 (when (memq 'message-strip-subject-re functions)
6934 (setq subject (concat "Re: " (message-strip-subject-re subject))))
6935 (when (and (memq 'message-strip-subject-trailing-was functions)
6936 message-subject-trailing-was-query)
6937 (setq subject (message-strip-subject-trailing-was subject)))
6938 (when (memq 'message-strip-subject-encoded-words functions)
6939 (setq subject (message-strip-subject-encoded-words subject)))
6940 subject)
6941
6942 ;;;###autoload
6943 (defun message-reply (&optional to-address wide switch-function)
6944 "Start editing a reply to the article in the current buffer."
6945 (interactive)
6946 (require 'gnus-sum) ; for gnus-list-identifiers
6947 (let ((cur (current-buffer))
6948 from subject date
6949 references message-id follow-to
6950 (inhibit-point-motion-hooks t)
6951 (message-this-is-mail t)
6952 gnus-warning)
6953 (save-restriction
6954 (message-narrow-to-head-1)
6955 ;; Allow customizations to have their say.
6956 (if (not wide)
6957 ;; This is a regular reply.
6958 (when (functionp message-reply-to-function)
6959 (save-excursion
6960 (setq follow-to (funcall message-reply-to-function))))
6961 ;; This is a followup.
6962 (when (functionp message-wide-reply-to-function)
6963 (save-excursion
6964 (setq follow-to
6965 (funcall message-wide-reply-to-function)))))
6966 (setq message-id (message-fetch-field "message-id" t)
6967 references (message-fetch-field "references")
6968 date (message-fetch-field "date")
6969 from (or (message-fetch-field "from") "nobody")
6970 subject (or (message-fetch-field "subject") "none"))
6971
6972 ;; Strip list identifiers, "Re: ", and "was:"
6973 (setq subject (message-simplify-subject subject))
6974
6975 (when (and (setq gnus-warning (message-fetch-field "gnus-warning"))
6976 (string-match "<[^>]+>" gnus-warning))
6977 (setq message-id (match-string 0 gnus-warning)))
6978
6979 (unless follow-to
6980 (setq follow-to (message-get-reply-headers wide to-address))))
6981
6982 (let ((headers
6983 `((Subject . ,subject)
6984 ,@follow-to)))
6985 (unless (message-mail-user-agent)
6986 (message-pop-to-buffer
6987 (message-buffer-name
6988 (if wide "wide reply" "reply") from
6989 (if wide to-address nil))
6990 switch-function))
6991 (setq message-reply-headers
6992 (vector 0 (cdr (assq 'Subject headers))
6993 from date message-id references 0 0 ""))
6994 (message-setup headers cur))))
6995
6996 ;;;###autoload
6997 (defun message-wide-reply (&optional to-address)
6998 "Make a \"wide\" reply to the message in the current buffer."
6999 (interactive)
7000 (message-reply to-address t))
7001
7002 ;;;###autoload
7003 (defun message-followup (&optional to-newsgroups)
7004 "Follow up to the message in the current buffer.
7005 If TO-NEWSGROUPS, use that as the new Newsgroups line."
7006 (interactive)
7007 (require 'gnus-sum) ; for gnus-list-identifiers
7008 (let ((cur (current-buffer))
7009 from subject date reply-to mrt mct
7010 references message-id follow-to
7011 (inhibit-point-motion-hooks t)
7012 (message-this-is-news t)
7013 followup-to distribution newsgroups gnus-warning posted-to)
7014 (save-restriction
7015 (narrow-to-region
7016 (goto-char (point-min))
7017 (if (search-forward "\n\n" nil t)
7018 (1- (point))
7019 (point-max)))
7020 (when (functionp message-followup-to-function)
7021 (setq follow-to
7022 (funcall message-followup-to-function)))
7023 (setq from (message-fetch-field "from")
7024 date (message-fetch-field "date")
7025 subject (or (message-fetch-field "subject") "none")
7026 references (message-fetch-field "references")
7027 message-id (message-fetch-field "message-id" t)
7028 followup-to (message-fetch-field "followup-to")
7029 newsgroups (message-fetch-field "newsgroups")
7030 posted-to (message-fetch-field "posted-to")
7031 reply-to (message-fetch-field "reply-to")
7032 mrt (message-fetch-field "mail-reply-to")
7033 distribution (message-fetch-field "distribution")
7034 mct (message-fetch-field "mail-copies-to"))
7035 (when (and (setq gnus-warning (message-fetch-field "gnus-warning"))
7036 (string-match "<[^>]+>" gnus-warning))
7037 (setq message-id (match-string 0 gnus-warning)))
7038 ;; Remove bogus distribution.
7039 (when (and (stringp distribution)
7040 (let ((case-fold-search t))
7041 (string-match "world" distribution)))
7042 (setq distribution nil))
7043 ;; Strip list identifiers, "Re: ", and "was:"
7044 (setq subject (message-simplify-subject subject))
7045 (widen))
7046
7047 (message-pop-to-buffer (message-buffer-name "followup" from newsgroups))
7048
7049 (setq message-reply-headers
7050 (vector 0 subject from date message-id references 0 0 ""))
7051
7052 (message-setup
7053 `((Subject . ,subject)
7054 ,@(cond
7055 (to-newsgroups
7056 (list (cons 'Newsgroups to-newsgroups)))
7057 (follow-to follow-to)
7058 ((and followup-to message-use-followup-to)
7059 (list
7060 (cond
7061 ((equal (downcase followup-to) "poster")
7062 (if (or (eq message-use-followup-to 'use)
7063 (message-y-or-n-p "Obey Followup-To: poster? " t "\
7064 You should normally obey the Followup-To: header.
7065
7066 `Followup-To: poster' sends your response via e-mail instead of news.
7067
7068 A typical situation where `Followup-To: poster' is used is when the poster
7069 does not read the newsgroup, so he wouldn't see any replies sent to it.
7070
7071 You may customize the variable `message-use-followup-to', if you
7072 want to get rid of this query permanently."))
7073 (progn
7074 (setq message-this-is-news nil)
7075 (cons 'To (or mrt reply-to from "")))
7076 (cons 'Newsgroups newsgroups)))
7077 (t
7078 (if (or (equal followup-to newsgroups)
7079 (not (eq message-use-followup-to 'ask))
7080 (message-y-or-n-p
7081 (concat "Obey Followup-To: " followup-to "? ") t "\
7082 You should normally obey the Followup-To: header.
7083
7084 `Followup-To: " followup-to "'
7085 directs your response to " (if (string-match "," followup-to)
7086 "the specified newsgroups"
7087 "that newsgroup only") ".
7088
7089 If a message is posted to several newsgroups, Followup-To is often
7090 used to direct the following discussion to one newsgroup only,
7091 because discussions that are spread over several newsgroup tend to
7092 be fragmented and very difficult to follow.
7093
7094 Also, some source/announcement newsgroups are not intended for discussion;
7095 responses here are directed to other newsgroups.
7096
7097 You may customize the variable `message-use-followup-to', if you
7098 want to get rid of this query permanently."))
7099 (cons 'Newsgroups followup-to)
7100 (cons 'Newsgroups newsgroups))))))
7101 (posted-to
7102 `((Newsgroups . ,posted-to)))
7103 (t
7104 `((Newsgroups . ,newsgroups))))
7105 ,@(and distribution (list (cons 'Distribution distribution)))
7106 ,@(when (and mct
7107 (not (or (equal (downcase mct) "never")
7108 (equal (downcase mct) "nobody"))))
7109 (list (cons 'Cc (if (or (equal (downcase mct) "always")
7110 (equal (downcase mct) "poster"))
7111 (or mrt reply-to from "")
7112 mct)))))
7113
7114 cur)))
7115
7116 (defun message-is-yours-p ()
7117 "Non-nil means current article is yours.
7118 If you have added `cancel-messages' to `message-shoot-gnksa-feet', all articles
7119 are yours except those that have Cancel-Lock header not belonging to you.
7120 Instead of shooting GNKSA feet, you should modify `message-alternative-emails'
7121 to match all of yours addresses."
7122 ;; Canlock-logic as suggested by Per Abrahamsen
7123 ;; <abraham@dina.kvl.dk>
7124 ;;
7125 ;; IF article has cancel-lock THEN
7126 ;; IF we can verify it THEN
7127 ;; issue cancel
7128 ;; ELSE
7129 ;; error: cancellock: article is not yours
7130 ;; ELSE
7131 ;; Use old rules, comparing sender...
7132 (save-excursion
7133 (save-restriction
7134 (message-narrow-to-head-1)
7135 (if (and (message-fetch-field "Cancel-Lock")
7136 (message-gnksa-enable-p 'canlock-verify))
7137 (if (null (canlock-verify))
7138 t
7139 (error "Failed to verify Cancel-lock: This article is not yours"))
7140 (let (sender from)
7141 (or
7142 (message-gnksa-enable-p 'cancel-messages)
7143 (and (setq sender (message-fetch-field "sender"))
7144 (string-equal (downcase sender)
7145 (downcase (message-make-sender))))
7146 ;; Email address in From field equals to our address
7147 (and (setq from (message-fetch-field "from"))
7148 (string-equal
7149 (downcase (car (mail-header-parse-address from)))
7150 (downcase (car (mail-header-parse-address
7151 (message-make-from))))))
7152 ;; Email address in From field matches
7153 ;; 'message-alternative-emails' regexp or function.
7154 (and from
7155 message-alternative-emails
7156 (cond ((functionp message-alternative-emails)
7157 (funcall message-alternative-emails
7158 (mail-header-parse-address from)))
7159 (t (string-match message-alternative-emails
7160 (car (mail-header-parse-address from))))))))))))
7161
7162 ;;;###autoload
7163 (defun message-cancel-news (&optional arg)
7164 "Cancel an article you posted.
7165 If ARG, allow editing of the cancellation message."
7166 (interactive "P")
7167 (unless (message-news-p)
7168 (error "This is not a news article; canceling is impossible"))
7169 (let (from newsgroups message-id distribution buf)
7170 (save-excursion
7171 ;; Get header info from original article.
7172 (save-restriction
7173 (message-narrow-to-head-1)
7174 (setq from (message-fetch-field "from")
7175 newsgroups (message-fetch-field "newsgroups")
7176 message-id (message-fetch-field "message-id" t)
7177 distribution (message-fetch-field "distribution")))
7178 ;; Make sure that this article was written by the user.
7179 (unless (message-is-yours-p)
7180 (error "This article is not yours"))
7181 (when (yes-or-no-p "Do you really want to cancel this article? ")
7182 ;; Make control message.
7183 (if arg
7184 (message-news)
7185 (setq buf (set-buffer (get-buffer-create " *message cancel*"))))
7186 (erase-buffer)
7187 (insert "Newsgroups: " newsgroups "\n"
7188 "From: " from "\n"
7189 "Subject: cancel " message-id "\n"
7190 "Control: cancel " message-id "\n"
7191 (if distribution
7192 (concat "Distribution: " distribution "\n")
7193 "")
7194 mail-header-separator "\n"
7195 message-cancel-message)
7196 (run-hooks 'message-cancel-hook)
7197 (unless arg
7198 (message "Canceling your article...")
7199 (if (let ((message-syntax-checks
7200 'dont-check-for-anything-just-trust-me))
7201 (funcall message-send-news-function))
7202 (message "Canceling your article...done"))
7203 (kill-buffer buf))))))
7204
7205 ;;;###autoload
7206 (defun message-supersede ()
7207 "Start composing a message to supersede the current message.
7208 This is done simply by taking the old article and adding a Supersedes
7209 header line with the old Message-ID."
7210 (interactive)
7211 (let ((cur (current-buffer)))
7212 ;; Check whether the user owns the article that is to be superseded.
7213 (unless (message-is-yours-p)
7214 (error "This article is not yours"))
7215 ;; Get a normal message buffer.
7216 (message-pop-to-buffer (message-buffer-name "supersede"))
7217 (insert-buffer-substring cur)
7218 (mime-to-mml)
7219 (message-narrow-to-head-1)
7220 ;; Remove unwanted headers.
7221 (when message-ignored-supersedes-headers
7222 (message-remove-header message-ignored-supersedes-headers t))
7223 (goto-char (point-min))
7224 (if (not (re-search-forward "^Message-ID: " nil t))
7225 (error "No Message-ID in this article")
7226 (replace-match "Supersedes: " t t))
7227 (goto-char (point-max))
7228 (insert mail-header-separator)
7229 (widen)
7230 (forward-line 1)))
7231
7232 ;;;###autoload
7233 (defun message-recover ()
7234 "Reread contents of current buffer from its last auto-save file."
7235 (interactive)
7236 (let ((file-name (make-auto-save-file-name)))
7237 (cond ((save-window-excursion
7238 (with-output-to-temp-buffer "*Directory*"
7239 (with-current-buffer standard-output
7240 (fundamental-mode)) ; for Emacs 20.4+
7241 (buffer-disable-undo standard-output)
7242 (let ((default-directory "/"))
7243 (call-process
7244 "ls" nil standard-output nil "-l" file-name)))
7245 (yes-or-no-p (format "Recover auto save file %s? " file-name)))
7246 (let ((buffer-read-only nil))
7247 (erase-buffer)
7248 (insert-file-contents file-name nil)))
7249 (t (error "message-recover canceled")))))
7250
7251 ;;; Washing Subject:
7252
7253 (defun message-wash-subject (subject)
7254 "Remove junk like \"Re:\", \"(fwd)\", etc. added to subject string SUBJECT.
7255 Previous forwarders, repliers, etc. may add it."
7256 (with-temp-buffer
7257 (insert subject)
7258 (goto-char (point-min))
7259 ;; strip Re/Fwd stuff off the beginning
7260 (while (re-search-forward
7261 "\\([Rr][Ee]:\\|[Ff][Ww][Dd]\\(\\[[0-9]*\\]\\)?:\\|[Ff][Ww]:\\)" nil t)
7262 (replace-match ""))
7263
7264 ;; and gnus-style forwards [foo@bar.com] subject
7265 (goto-char (point-min))
7266 (while (re-search-forward "\\[[^ \t]*\\(@\\|\\.\\)[^ \t]*\\]" nil t)
7267 (replace-match ""))
7268
7269 ;; and off the end
7270 (goto-char (point-max))
7271 (while (re-search-backward "([Ff][Ww][Dd])" nil t)
7272 (replace-match ""))
7273
7274 ;; and finally, any whitespace that was left-over
7275 (goto-char (point-min))
7276 (while (re-search-forward "^[ \t]+" nil t)
7277 (replace-match ""))
7278 (goto-char (point-max))
7279 (while (re-search-backward "[ \t]+$" nil t)
7280 (replace-match ""))
7281
7282 (buffer-string)))
7283
7284 ;;; Forwarding messages.
7285
7286 (defvar message-forward-decoded-p nil
7287 "Non-nil means the original message is decoded.")
7288
7289 (defun message-forward-subject-name-subject (subject)
7290 "Generate a SUBJECT for a forwarded message.
7291 The form is: [Source] Subject, where if the original message was mail,
7292 Source is the name of the sender, and if the original message was
7293 news, Source is the list of newsgroups is was posted to."
7294 (let* ((group (message-fetch-field "newsgroups"))
7295 (from (message-fetch-field "from"))
7296 (prefix
7297 (if group
7298 (gnus-group-decoded-name group)
7299 (or (and from (or
7300 (car (gnus-extract-address-components from))
7301 (cadr (gnus-extract-address-components from))))
7302 "(nowhere)"))))
7303 (concat "["
7304 (if message-forward-decoded-p
7305 prefix
7306 (mail-decode-encoded-word-string prefix))
7307 "] " subject)))
7308
7309 (defun message-forward-subject-author-subject (subject)
7310 "Generate a SUBJECT for a forwarded message.
7311 The form is: [Source] Subject, where if the original message was mail,
7312 Source is the sender, and if the original message was news, Source is
7313 the list of newsgroups is was posted to."
7314 (let* ((group (message-fetch-field "newsgroups"))
7315 (prefix
7316 (if group
7317 (gnus-group-decoded-name group)
7318 (or (message-fetch-field "from")
7319 "(nowhere)"))))
7320 (concat "["
7321 (if message-forward-decoded-p
7322 prefix
7323 (mail-decode-encoded-word-string prefix))
7324 "] " subject)))
7325
7326 (defun message-forward-subject-fwd (subject)
7327 "Generate a SUBJECT for a forwarded message.
7328 The form is: Fwd: Subject, where Subject is the original subject of
7329 the message."
7330 (if (string-match "^Fwd: " subject)
7331 subject
7332 (concat "Fwd: " subject)))
7333
7334 (defun message-make-forward-subject ()
7335 "Return a Subject header suitable for the message in the current buffer."
7336 (save-excursion
7337 (save-restriction
7338 (message-narrow-to-head-1)
7339 (let ((funcs message-make-forward-subject-function)
7340 (subject (message-fetch-field "Subject")))
7341 (setq subject
7342 (if subject
7343 (if message-forward-decoded-p
7344 subject
7345 (mail-decode-encoded-word-string subject))
7346 ""))
7347 (when message-wash-forwarded-subjects
7348 (setq subject (message-wash-subject subject)))
7349 ;; Make sure funcs is a list.
7350 (and funcs
7351 (not (listp funcs))
7352 (setq funcs (list funcs)))
7353 ;; Apply funcs in order, passing subject generated by previous
7354 ;; func to the next one.
7355 (dolist (func funcs)
7356 (when (functionp func)
7357 (setq subject (funcall func subject))))
7358 subject))))
7359
7360 (defvar gnus-article-decoded-p)
7361
7362
7363 ;;;###autoload
7364 (defun message-forward (&optional news digest)
7365 "Forward the current message via mail.
7366 Optional NEWS will use news to forward instead of mail.
7367 Optional DIGEST will use digest to forward."
7368 (interactive "P")
7369 (let* ((cur (current-buffer))
7370 (message-forward-decoded-p
7371 (if (local-variable-p 'gnus-article-decoded-p (current-buffer))
7372 gnus-article-decoded-p ;; In an article buffer.
7373 message-forward-decoded-p))
7374 (subject (message-make-forward-subject)))
7375 (if news
7376 (message-news nil subject)
7377 (message-mail nil subject))
7378 (message-forward-make-body cur digest)))
7379
7380 (defun message-forward-make-body-plain (forward-buffer)
7381 (insert
7382 "\n-------------------- Start of forwarded message --------------------\n")
7383 (let ((b (point))
7384 (contents (with-current-buffer forward-buffer (buffer-string)))
7385 e)
7386 (unless (multibyte-string-p contents)
7387 (error "Attempt to insert unibyte string from the buffer \"%s\"\
7388 to the multibyte buffer \"%s\""
7389 (if (bufferp forward-buffer)
7390 (buffer-name forward-buffer)
7391 forward-buffer)
7392 (buffer-name)))
7393 (insert (mm-with-multibyte-buffer
7394 (insert contents)
7395 (mime-to-mml)
7396 (goto-char (point-min))
7397 (when (looking-at "From ")
7398 (replace-match "X-From-Line: "))
7399 (buffer-string)))
7400 (unless (bolp) (insert "\n"))
7401 (setq e (point))
7402 (insert
7403 "-------------------- End of forwarded message --------------------\n")
7404 (message-remove-ignored-headers b e)))
7405
7406 (defun message-remove-ignored-headers (b e)
7407 (when (or message-forward-ignored-headers
7408 message-forward-included-headers)
7409 (save-restriction
7410 (narrow-to-region b e)
7411 (goto-char b)
7412 (narrow-to-region (point)
7413 (or (search-forward "\n\n" nil t) (point)))
7414 (when message-forward-ignored-headers
7415 (let ((ignored (if (stringp message-forward-ignored-headers)
7416 (list message-forward-ignored-headers)
7417 message-forward-ignored-headers)))
7418 (dolist (elem ignored)
7419 (message-remove-header elem t))))
7420 (when message-forward-included-headers
7421 (message-remove-header
7422 (if (listp message-forward-included-headers)
7423 (regexp-opt message-forward-included-headers)
7424 message-forward-included-headers)
7425 t nil t)))))
7426
7427 (defun message-forward-make-body-mime (forward-buffer &optional beg end)
7428 (let ((b (point)))
7429 (insert "\n\n<#part type=message/rfc822 disposition=inline raw=t>\n")
7430 (save-restriction
7431 (narrow-to-region (point) (point))
7432 (insert-buffer-substring forward-buffer beg end)
7433 (mml-quote-region (point-min) (point-max))
7434 (goto-char (point-min))
7435 (when (looking-at "From ")
7436 (replace-match "X-From-Line: "))
7437 (goto-char (point-max)))
7438 (insert "<#/part>\n")
7439 ;; Consider there is no illegible text.
7440 (add-text-properties
7441 b (point)
7442 `(no-illegible-text t rear-nonsticky t start-open t))))
7443
7444 (defun message-forward-make-body-mml (forward-buffer)
7445 (insert "\n\n<#mml type=message/rfc822 disposition=inline>\n")
7446 (let ((b (point)) e)
7447 (if (not message-forward-decoded-p)
7448 (let ((contents (with-current-buffer forward-buffer (buffer-string))))
7449 (unless (multibyte-string-p contents)
7450 (error "Attempt to insert unibyte string from the buffer \"%s\"\
7451 to the multibyte buffer \"%s\""
7452 (if (bufferp forward-buffer)
7453 (buffer-name forward-buffer)
7454 forward-buffer)
7455 (buffer-name)))
7456 (insert (mm-with-multibyte-buffer
7457 (insert contents)
7458 (mime-to-mml)
7459 (goto-char (point-min))
7460 (when (looking-at "From ")
7461 (replace-match "X-From-Line: "))
7462 (buffer-string))))
7463 (save-restriction
7464 (narrow-to-region (point) (point))
7465 (mml-insert-buffer forward-buffer)
7466 (goto-char (point-min))
7467 (when (looking-at "From ")
7468 (replace-match "X-From-Line: "))
7469 (goto-char (point-max))))
7470 (setq e (point))
7471 (insert "<#/mml>\n")
7472 (when (not message-forward-decoded-p)
7473 (message-remove-ignored-headers b e))))
7474
7475 (defun message-forward-make-body-digest-plain (forward-buffer)
7476 (insert
7477 "\n-------------------- Start of forwarded message --------------------\n")
7478 (mml-insert-buffer forward-buffer)
7479 (insert
7480 "\n-------------------- End of forwarded message --------------------\n"))
7481
7482 (defun message-forward-make-body-digest-mime (forward-buffer)
7483 (insert "\n<#multipart type=digest>\n")
7484 (let ((b (point)) e)
7485 (insert-buffer-substring forward-buffer)
7486 (setq e (point))
7487 (insert "<#/multipart>\n")
7488 (save-restriction
7489 (narrow-to-region b e)
7490 (goto-char b)
7491 (narrow-to-region (point)
7492 (or (search-forward "\n\n" nil t) (point)))
7493 (delete-region (point-min) (point-max)))))
7494
7495 (defun message-forward-make-body-digest (forward-buffer)
7496 (if message-forward-as-mime
7497 (message-forward-make-body-digest-mime forward-buffer)
7498 (message-forward-make-body-digest-plain forward-buffer)))
7499
7500 (autoload 'mm-uu-dissect-text-parts "mm-uu")
7501 (autoload 'mm-uu-dissect "mm-uu")
7502
7503 (defun message-signed-or-encrypted-p (&optional dont-emulate-mime handles)
7504 "Say whether the current buffer contains signed or encrypted message.
7505 If DONT-EMULATE-MIME is nil, this function does the MIME emulation on
7506 messages that don't conform to PGP/MIME described in RFC2015. HANDLES
7507 is for the internal use."
7508 (unless handles
7509 (let ((mm-decrypt-option 'never)
7510 (mm-verify-option 'never))
7511 (if (setq handles (mm-dissect-buffer nil t))
7512 (unless dont-emulate-mime
7513 (mm-uu-dissect-text-parts handles))
7514 (unless dont-emulate-mime
7515 (setq handles (mm-uu-dissect))))))
7516 ;; Check text/plain message in which there is a signed or encrypted
7517 ;; body that has been encoded by B or Q.
7518 (unless (or handles dont-emulate-mime)
7519 (let ((cur (current-buffer))
7520 (mm-decrypt-option 'never)
7521 (mm-verify-option 'never))
7522 (with-temp-buffer
7523 (insert-buffer-substring cur)
7524 (when (setq handles (mm-dissect-buffer t t))
7525 (if (and (bufferp (car handles))
7526 (equal (mm-handle-media-type handles) "text/plain"))
7527 (progn
7528 (erase-buffer)
7529 (insert-buffer-substring (car handles))
7530 (mm-decode-content-transfer-encoding
7531 (mm-handle-encoding handles))
7532 (mm-destroy-parts handles)
7533 (setq handles (mm-uu-dissect)))
7534 (mm-destroy-parts handles)
7535 (setq handles nil))))))
7536 (when handles
7537 (prog1
7538 (catch 'found
7539 (dolist (handle (if (stringp (car handles))
7540 (if (member (car handles)
7541 '("multipart/signed"
7542 "multipart/encrypted"))
7543 (throw 'found t)
7544 (cdr handles))
7545 (list handles)))
7546 (if (stringp (car handle))
7547 (when (message-signed-or-encrypted-p dont-emulate-mime handle)
7548 (throw 'found t))
7549 (when (and (bufferp (car handle))
7550 (equal (mm-handle-media-type handle)
7551 "message/rfc822"))
7552 (with-current-buffer (mm-handle-buffer handle)
7553 (when (message-signed-or-encrypted-p dont-emulate-mime)
7554 (throw 'found t)))))))
7555 (mm-destroy-parts handles))))
7556
7557 ;;;###autoload
7558 (defun message-forward-make-body (forward-buffer &optional digest)
7559 ;; Put point where we want it before inserting the forwarded
7560 ;; message.
7561 (if message-forward-before-signature
7562 (message-goto-body)
7563 (goto-char (point-max)))
7564 (if digest
7565 (message-forward-make-body-digest forward-buffer)
7566 (if message-forward-as-mime
7567 (if (and message-forward-show-mml
7568 (not (and (eq message-forward-show-mml 'best)
7569 ;; Use the raw form in the body if it contains
7570 ;; signed or encrypted message so as not to be
7571 ;; destroyed by re-encoding.
7572 (with-current-buffer forward-buffer
7573 (condition-case nil
7574 (message-signed-or-encrypted-p)
7575 (error t))))))
7576 (message-forward-make-body-mml forward-buffer)
7577 (message-forward-make-body-mime forward-buffer))
7578 (message-forward-make-body-plain forward-buffer)))
7579 (message-position-point))
7580
7581 (declare-function rmail-toggle-header "rmail" (&optional arg))
7582
7583 ;;;###autoload
7584 (defun message-forward-rmail-make-body (forward-buffer)
7585 (save-window-excursion
7586 (set-buffer forward-buffer)
7587 (when (rmail-msg-is-pruned)
7588 (rmail-toggle-header 0)))
7589 (message-forward-make-body forward-buffer))
7590
7591 ;; Fixme: Should have defcustom.
7592 ;;;###autoload
7593 (defun message-insinuate-rmail ()
7594 "Let RMAIL use message to forward."
7595 (interactive)
7596 (setq rmail-enable-mime-composing t)
7597 (setq rmail-insert-mime-forwarded-message-function
7598 'message-forward-rmail-make-body))
7599
7600 (defvar message-inhibit-body-encoding nil)
7601
7602 ;;;###autoload
7603 (defun message-resend (address)
7604 "Resend the current article to ADDRESS."
7605 (interactive
7606 (list (message-read-from-minibuffer "Resend message to: ")))
7607 (message "Resending message to %s..." address)
7608 (save-excursion
7609 (let ((cur (current-buffer))
7610 gcc beg)
7611 ;; We first set up a normal mail buffer.
7612 (unless (message-mail-user-agent)
7613 (set-buffer (get-buffer-create " *message resend*"))
7614 (let ((inhibit-read-only t))
7615 (erase-buffer)))
7616 (let ((message-this-is-mail t)
7617 message-generate-hashcash
7618 message-setup-hook)
7619 (message-setup `((To . ,address))))
7620 ;; Insert our usual headers.
7621 (message-generate-headers '(From Date To Message-ID))
7622 (message-narrow-to-headers)
7623 (when (setq gcc (mail-fetch-field "gcc" nil t))
7624 (message-remove-header "gcc"))
7625 ;; Remove X-Draft-From header etc.
7626 (message-remove-header message-ignored-mail-headers t)
7627 ;; Rename them all to "Resent-*".
7628 (goto-char (point-min))
7629 (while (re-search-forward "^[A-Za-z]" nil t)
7630 (forward-char -1)
7631 (insert "Resent-"))
7632 (widen)
7633 (forward-line)
7634 (let ((inhibit-read-only t))
7635 (delete-region (point) (point-max)))
7636 (setq beg (point))
7637 ;; Insert the message to be resent.
7638 (insert-buffer-substring cur)
7639 (goto-char (point-min))
7640 (search-forward "\n\n")
7641 (forward-char -1)
7642 (save-restriction
7643 (narrow-to-region beg (point))
7644 (message-remove-header message-ignored-resent-headers t)
7645 (goto-char (point-max)))
7646 (insert mail-header-separator)
7647 ;; Rename all old ("Also-")Resent headers.
7648 (while (re-search-backward "^\\(Also-\\)*Resent-" beg t)
7649 (beginning-of-line)
7650 (insert "Also-"))
7651 ;; Quote any "From " lines at the beginning.
7652 (goto-char beg)
7653 (when (looking-at "From ")
7654 (replace-match "X-From-Line: "))
7655 ;; Send it.
7656 (let ((message-inhibit-body-encoding
7657 ;; Don't do any further encoding if it looks like the
7658 ;; message has already been encoded.
7659 (let ((case-fold-search t))
7660 (re-search-forward "^mime-version:" nil t)))
7661 (message-inhibit-ecomplete t)
7662 message-required-mail-headers
7663 message-generate-hashcash
7664 rfc2047-encode-encoded-words)
7665 (message-send-mail))
7666 (when gcc
7667 (message-goto-eoh)
7668 (insert "Gcc: " gcc "\n"))
7669 (run-hooks 'message-sent-hook)
7670 (kill-buffer (current-buffer)))
7671 (message "Resending message to %s...done" address)))
7672
7673 ;;;###autoload
7674 (defun message-bounce ()
7675 "Re-mail the current message.
7676 This only makes sense if the current message is a bounce message that
7677 contains some mail you have written which has been bounced back to
7678 you."
7679 (interactive)
7680 (let ((handles (mm-dissect-buffer t))
7681 boundary)
7682 (message-pop-to-buffer (message-buffer-name "bounce"))
7683 (if (stringp (car handles))
7684 ;; This is a MIME bounce.
7685 (mm-insert-part (car (last handles)))
7686 ;; This is a non-MIME bounce, so we try to remove things
7687 ;; manually.
7688 (mm-insert-part handles)
7689 (undo-boundary)
7690 (goto-char (point-min))
7691 (re-search-forward "\n\n+" nil t)
7692 (setq boundary (point))
7693 ;; We remove everything before the bounced mail.
7694 (if (or (re-search-forward message-unsent-separator nil t)
7695 (progn
7696 (search-forward "\n\n" nil 'move)
7697 (re-search-backward "^Return-Path:.*\n" boundary t)))
7698 (progn
7699 (forward-line 1)
7700 (delete-region (point-min)
7701 (if (re-search-forward "^[^ \n\t]+:" nil t)
7702 (match-beginning 0)
7703 (point))))
7704 (goto-char boundary)
7705 (when (re-search-backward "^.?From .*\n" nil t)
7706 (delete-region (match-beginning 0) (match-end 0)))))
7707 (mime-to-mml)
7708 (save-restriction
7709 (message-narrow-to-head-1)
7710 (message-remove-header message-ignored-bounced-headers t)
7711 (goto-char (point-max))
7712 (insert mail-header-separator))
7713 (message-position-point)))
7714
7715 ;;;
7716 ;;; Interactive entry points for new message buffers.
7717 ;;;
7718
7719 ;;;###autoload
7720 (defun message-mail-other-window (&optional to subject)
7721 "Like `message-mail' command, but display mail buffer in another window."
7722 (interactive)
7723 (unless (message-mail-user-agent)
7724 (message-pop-to-buffer (message-buffer-name "mail" to)
7725 'switch-to-buffer-other-window))
7726 (let ((message-this-is-mail t))
7727 (message-setup `((To . ,(or to "")) (Subject . ,(or subject "")))
7728 nil nil nil 'switch-to-buffer-other-window)))
7729
7730 ;;;###autoload
7731 (defun message-mail-other-frame (&optional to subject)
7732 "Like `message-mail' command, but display mail buffer in another frame."
7733 (interactive)
7734 (unless (message-mail-user-agent)
7735 (message-pop-to-buffer (message-buffer-name "mail" to)
7736 'switch-to-buffer-other-frame))
7737 (let ((message-this-is-mail t))
7738 (message-setup `((To . ,(or to "")) (Subject . ,(or subject "")))
7739 nil nil nil 'switch-to-buffer-other-frame)))
7740
7741 ;;;###autoload
7742 (defun message-news-other-window (&optional newsgroups subject)
7743 "Start editing a news article to be sent."
7744 (interactive)
7745 (message-pop-to-buffer (message-buffer-name "posting" nil newsgroups)
7746 'switch-to-buffer-other-window)
7747 (let ((message-this-is-news t))
7748 (message-setup `((Newsgroups . ,(or newsgroups ""))
7749 (Subject . ,(or subject ""))))))
7750
7751 ;;;###autoload
7752 (defun message-news-other-frame (&optional newsgroups subject)
7753 "Start editing a news article to be sent."
7754 (interactive)
7755 (message-pop-to-buffer (message-buffer-name "posting" nil newsgroups)
7756 'switch-to-buffer-other-frame)
7757 (let ((message-this-is-news t))
7758 (message-setup `((Newsgroups . ,(or newsgroups ""))
7759 (Subject . ,(or subject ""))))))
7760
7761 ;;; underline.el
7762
7763 ;; This code should be moved to underline.el (from which it is stolen).
7764
7765 ;;;###autoload
7766 (defun message-bold-region (start end)
7767 "Bold all nonblank characters in the region.
7768 Works by overstriking characters.
7769 Called from program, takes two arguments START and END
7770 which specify the range to operate on."
7771 (interactive "r")
7772 (save-excursion
7773 (let ((end1 (make-marker)))
7774 (move-marker end1 (max start end))
7775 (goto-char (min start end))
7776 (while (< (point) end1)
7777 (or (looking-at "[_\^@- ]")
7778 (insert (char-after) "\b"))
7779 (forward-char 1)))))
7780
7781 ;;;###autoload
7782 (defun message-unbold-region (start end)
7783 "Remove all boldness (overstruck characters) in the region.
7784 Called from program, takes two arguments START and END
7785 which specify the range to operate on."
7786 (interactive "r")
7787 (save-excursion
7788 (let ((end1 (make-marker)))
7789 (move-marker end1 (max start end))
7790 (goto-char (min start end))
7791 (while (search-forward "\b" end1 t)
7792 (if (eq (char-after) (char-after (- (point) 2)))
7793 (delete-char -2))))))
7794
7795 (defun message-exchange-point-and-mark ()
7796 "Exchange point and mark, but don't activate region if it was inactive."
7797 (goto-char (prog1 (mark t)
7798 (set-marker (mark-marker) (point)))))
7799
7800 ;; Support for toolbar
7801 (defvar tool-bar-mode)
7802
7803 ;; Note: The :set function in the `message-tool-bar*' variables will only
7804 ;; affect _new_ message buffers. We might add a function that walks thru all
7805 ;; message-mode buffers and force the update.
7806 (defun message-tool-bar-update (&optional symbol value)
7807 "Update message mode toolbar.
7808 Setter function for custom variables."
7809 (setq-default message-tool-bar-map nil)
7810 (when symbol
7811 ;; When used as ":set" function:
7812 (set-default symbol value)))
7813
7814 (defcustom message-tool-bar (if (eq gmm-tool-bar-style 'gnome)
7815 'message-tool-bar-gnome
7816 'message-tool-bar-retro)
7817 "Specifies the message mode tool bar.
7818
7819 It can be either a list or a symbol referring to a list. See
7820 `gmm-tool-bar-from-list' for the format of the list. The
7821 default key map is `message-mode-map'.
7822
7823 Pre-defined symbols include `message-tool-bar-gnome' and
7824 `message-tool-bar-retro'."
7825 :type '(repeat gmm-tool-bar-list-item)
7826 :type '(choice (const :tag "GNOME style" message-tool-bar-gnome)
7827 (const :tag "Retro look" message-tool-bar-retro)
7828 (repeat :tag "User defined list" gmm-tool-bar-item)
7829 (symbol))
7830 :version "23.1" ;; No Gnus
7831 :initialize 'custom-initialize-default
7832 :set 'message-tool-bar-update
7833 :group 'message)
7834
7835 (defcustom message-tool-bar-gnome
7836 '((ispell-message "spell" nil
7837 :vert-only t
7838 :visible (not flyspell-mode))
7839 (flyspell-buffer "spell" t
7840 :vert-only t
7841 :visible flyspell-mode
7842 :help "Flyspell whole buffer")
7843 (message-send-and-exit "mail/send" t :label "Send")
7844 (message-dont-send "mail/save-draft")
7845 (mml-attach-file "attach" mml-mode-map :vert-only t)
7846 (mml-preview "mail/preview" mml-mode-map)
7847 (mml-secure-message-sign-encrypt "lock" mml-mode-map :visible nil)
7848 (message-insert-importance-high "important" nil :visible nil)
7849 (message-insert-importance-low "unimportant" nil :visible nil)
7850 (message-insert-disposition-notification-to "receipt" nil :visible nil))
7851 "List of items for the message tool bar (GNOME style).
7852
7853 See `gmm-tool-bar-from-list' for details on the format of the list."
7854 :type '(repeat gmm-tool-bar-item)
7855 :version "23.1" ;; No Gnus
7856 :initialize 'custom-initialize-default
7857 :set 'message-tool-bar-update
7858 :group 'message)
7859
7860 (defcustom message-tool-bar-retro
7861 '(;; Old Emacs 21 icon for consistency.
7862 (message-send-and-exit "gnus/mail-send")
7863 (message-kill-buffer "close")
7864 (message-dont-send "cancel")
7865 (mml-attach-file "attach" mml-mode-map)
7866 (ispell-message "spell")
7867 (mml-preview "preview" mml-mode-map)
7868 (message-insert-importance-high "gnus/important")
7869 (message-insert-importance-low "gnus/unimportant")
7870 (message-insert-disposition-notification-to "gnus/receipt"))
7871 "List of items for the message tool bar (retro style).
7872
7873 See `gmm-tool-bar-from-list' for details on the format of the list."
7874 :type '(repeat gmm-tool-bar-item)
7875 :version "23.1" ;; No Gnus
7876 :initialize 'custom-initialize-default
7877 :set 'message-tool-bar-update
7878 :group 'message)
7879
7880 (defcustom message-tool-bar-zap-list
7881 '(new-file open-file dired kill-buffer write-file
7882 print-buffer customize help)
7883 "List of icon items from the global tool bar.
7884 These items are not displayed on the message mode tool bar.
7885
7886 See `gmm-tool-bar-from-list' for the format of the list."
7887 :type 'gmm-tool-bar-zap-list
7888 :version "23.1" ;; No Gnus
7889 :initialize 'custom-initialize-default
7890 :set 'message-tool-bar-update
7891 :group 'message)
7892
7893 (defvar image-load-path)
7894
7895 (defun message-make-tool-bar (&optional force)
7896 "Make a message mode tool bar from `message-tool-bar-list'.
7897 When FORCE, rebuild the tool bar."
7898 (when (and (boundp 'tool-bar-mode)
7899 tool-bar-mode
7900 (or (not message-tool-bar-map) force))
7901 (setq message-tool-bar-map
7902 (let* ((load-path
7903 (gmm-image-load-path-for-library "message"
7904 "mail/save-draft.xpm"
7905 nil t))
7906 (image-load-path (cons (car load-path) image-load-path)))
7907 (gmm-tool-bar-from-list message-tool-bar
7908 message-tool-bar-zap-list
7909 'message-mode-map))))
7910 message-tool-bar-map)
7911
7912 ;;; Group name completion.
7913
7914 (defcustom message-newgroups-header-regexp
7915 "^\\(Newsgroups\\|Followup-To\\|Posted-To\\|Gcc\\):"
7916 "Regexp that match headers that lists groups."
7917 :group 'message
7918 :type 'regexp)
7919
7920 (defcustom message-completion-alist
7921 (list (cons message-newgroups-header-regexp 'message-expand-group)
7922 '("^\\(Resent-\\)?\\(To\\|B?Cc\\):" . message-expand-name)
7923 '("^\\(Reply-To\\|From\\|Mail-Followup-To\\|Mail-Copies-To\\):"
7924 . message-expand-name)
7925 '("^\\(Disposition-Notification-To\\|Return-Receipt-To\\):"
7926 . message-expand-name))
7927 "Alist of (RE . FUN). Use FUN for completion on header lines matching RE."
7928 :version "22.1"
7929 :group 'message
7930 :type '(alist :key-type regexp :value-type function))
7931
7932 (defcustom message-expand-name-databases
7933 '(bbdb eudc)
7934 "List of databases to try for name completion (`message-expand-name').
7935 Each element is a symbol and can be `bbdb' or `eudc'."
7936 :group 'message
7937 :type '(set (const bbdb) (const eudc)))
7938
7939 (defcustom message-tab-body-function nil
7940 "*Function to execute when `message-tab' (TAB) is executed in the body.
7941 If nil, the function bound in `text-mode-map' or `global-map' is executed."
7942 :version "22.1"
7943 :group 'message
7944 :link '(custom-manual "(message)Various Commands")
7945 :type '(choice (const nil)
7946 function))
7947
7948 (declare-function mail-abbrev-in-expansion-header-p "mailabbrev" ())
7949
7950 (defun message-tab ()
7951 "Complete names according to `message-completion-alist'.
7952 Execute function specified by `message-tab-body-function' when
7953 not in those headers. If that variable is nil, indent with the
7954 regular text mode tabbing command."
7955 (interactive)
7956 (cond
7957 ((let ((completion-fail-discreetly t))
7958 (completion-at-point))
7959 ;; Completion was performed; nothing else to do.
7960 nil)
7961 (message-tab-body-function (funcall message-tab-body-function))
7962 (t (funcall (or (lookup-key text-mode-map "\t")
7963 (lookup-key global-map "\t")
7964 'indent-relative)))))
7965
7966 (defvar mail-abbrev-mode-regexp)
7967
7968 (defun message-completion-function ()
7969 (let ((alist message-completion-alist))
7970 (while (and alist
7971 (let ((mail-abbrev-mode-regexp (caar alist)))
7972 (not (mail-abbrev-in-expansion-header-p))))
7973 (setq alist (cdr alist)))
7974 (when (cdar alist)
7975 (lexical-let ((fun (cdar alist)))
7976 ;; Even if completion fails, return a non-nil value, so as to avoid
7977 ;; falling back to message-tab-body-function.
7978 (lambda () (funcall fun) 'completion-attempted)))))
7979
7980 (defun message-expand-group ()
7981 "Expand the group name under point."
7982 (let ((b (save-excursion
7983 (save-restriction
7984 (narrow-to-region
7985 (save-excursion
7986 (beginning-of-line)
7987 (skip-chars-forward "^:")
7988 (1+ (point)))
7989 (point))
7990 (skip-chars-backward "^, \t\n") (point))))
7991 (completion-ignore-case t)
7992 (e (progn (skip-chars-forward "^,\t\n ") (point)))
7993 group collection)
7994 (when (and (boundp 'gnus-active-hashtb)
7995 gnus-active-hashtb)
7996 (mapatoms
7997 (lambda (symbol)
7998 (setq group (symbol-name symbol))
7999 (push (if (string-match "[^\000-\177]" group)
8000 (gnus-group-decoded-name group)
8001 group)
8002 collection))
8003 gnus-active-hashtb))
8004 (completion-in-region b e collection)))
8005
8006 (defun message-expand-name ()
8007 (cond ((and (memq 'eudc message-expand-name-databases)
8008 (boundp 'eudc-protocol)
8009 eudc-protocol)
8010 (eudc-expand-inline))
8011 ((and (memq 'bbdb message-expand-name-databases)
8012 (fboundp 'bbdb-complete-name))
8013 (let ((starttick (buffer-modified-tick)))
8014 (or (bbdb-complete-name)
8015 ;; Apparently, bbdb-complete-name can return nil even when
8016 ;; completion took place. So let's double check the buffer was
8017 ;; not modified.
8018 (/= starttick (buffer-modified-tick)))))
8019 (t
8020 (expand-abbrev))))
8021
8022 ;;; Help stuff.
8023
8024 (defun message-talkative-question (ask question show &rest text)
8025 "Call FUNCTION with argument QUESTION; optionally display TEXT... args.
8026 If SHOW is non-nil, the arguments TEXT... are displayed in a temp buffer.
8027 The following arguments may contain lists of values."
8028 (if (and show
8029 (setq text (message-flatten-list text)))
8030 (save-window-excursion
8031 (with-output-to-temp-buffer " *MESSAGE information message*"
8032 (with-current-buffer " *MESSAGE information message*"
8033 (fundamental-mode) ; for Emacs 20.4+
8034 (mapc 'princ text)
8035 (goto-char (point-min))))
8036 (funcall ask question))
8037 (funcall ask question)))
8038
8039 (defun message-flatten-list (list)
8040 "Return a new, flat list that contains all elements of LIST.
8041
8042 \(message-flatten-list \\='(1 (2 3 (4 5 (6))) 7))
8043 => (1 2 3 4 5 6 7)"
8044 (cond ((consp list)
8045 (apply 'append (mapcar 'message-flatten-list list)))
8046 (list
8047 (list list))))
8048
8049 (defun message-generate-new-buffer-clone-locals (name &optional varstr)
8050 "Create and return a buffer with name based on NAME using `generate-new-buffer'.
8051 Then clone the local variables and values from the old buffer to the
8052 new one, cloning only the locals having a substring matching the
8053 regexp VARSTR."
8054 (let ((oldbuf (current-buffer)))
8055 (with-current-buffer (generate-new-buffer name)
8056 (message-clone-locals oldbuf varstr)
8057 (current-buffer))))
8058
8059 (defun message-clone-locals (buffer &optional varstr)
8060 "Clone the local variables from BUFFER to the current buffer."
8061 (let ((locals (with-current-buffer buffer (buffer-local-variables)))
8062 (regexp "^gnus\\|^nn\\|^message\\|^sendmail\\|^smtp\\|^user-mail-address"))
8063 (mapcar
8064 (lambda (local)
8065 (when (and (consp local)
8066 (car local)
8067 (string-match regexp (symbol-name (car local)))
8068 (or (null varstr)
8069 (string-match varstr (symbol-name (car local)))))
8070 (ignore-errors
8071 (set (make-local-variable (car local))
8072 (cdr local)))))
8073 locals)))
8074
8075 ;;;
8076 ;;; MIME functions
8077 ;;;
8078
8079 (defun message-encode-message-body ()
8080 (unless message-inhibit-body-encoding
8081 (let ((mail-parse-charset (or mail-parse-charset
8082 message-default-charset))
8083 (case-fold-search t)
8084 lines content-type-p)
8085 (message-goto-body)
8086 (save-restriction
8087 (narrow-to-region (point) (point-max))
8088 (let ((new (mml-generate-mime)))
8089 (when new
8090 (delete-region (point-min) (point-max))
8091 (insert new)
8092 (goto-char (point-min))
8093 (if (eq (aref new 0) ?\n)
8094 (delete-char 1)
8095 (search-forward "\n\n")
8096 (setq lines (buffer-substring (point-min) (1- (point))))
8097 (delete-region (point-min) (point))))))
8098 (save-restriction
8099 (message-narrow-to-headers-or-head)
8100 (message-remove-header "Mime-Version")
8101 (goto-char (point-max))
8102 (insert "MIME-Version: 1.0\n")
8103 (when lines
8104 (insert lines))
8105 (setq content-type-p
8106 (or mml-boundary
8107 (re-search-backward "^Content-Type:" nil t))))
8108 (save-restriction
8109 (message-narrow-to-headers-or-head)
8110 (message-remove-first-header "Content-Type")
8111 (message-remove-first-header "Content-Transfer-Encoding"))
8112 ;; We always make sure that the message has a Content-Type
8113 ;; header. This is because some broken MTAs and MUAs get
8114 ;; awfully confused when confronted with a message with a
8115 ;; MIME-Version header and without a Content-Type header. For
8116 ;; instance, Solaris' /usr/bin/mail.
8117 (unless content-type-p
8118 (goto-char (point-min))
8119 ;; For unknown reason, MIME-Version doesn't exist.
8120 (when (re-search-forward "^MIME-Version:" nil t)
8121 (forward-line 1)
8122 (insert "Content-Type: text/plain; charset=us-ascii\n"))))))
8123
8124 (defun message-read-from-minibuffer (prompt &optional initial-contents)
8125 "Read from the minibuffer while providing abbrev expansion."
8126 (let ((minibuffer-setup-hook 'mail-abbrevs-setup)
8127 (minibuffer-local-map message-minibuffer-local-map))
8128 (read-from-minibuffer prompt initial-contents)))
8129
8130 (defun message-use-alternative-email-as-from ()
8131 "Set From field of the outgoing message to the first matching
8132 address in `message-alternative-emails', looking at To, Cc and
8133 From headers in the original article."
8134 (require 'mail-utils)
8135 (let* ((fields '("To" "Cc" "From"))
8136 (emails
8137 (message-tokenize-header
8138 (mail-strip-quoted-names
8139 (mapconcat 'message-fetch-reply-field fields ","))))
8140 (email (cond ((functionp message-alternative-emails)
8141 (car (cl-remove-if-not message-alternative-emails emails)))
8142 (t (loop for email in emails
8143 if (string-match-p message-alternative-emails email)
8144 return email)))))
8145 (unless (or (not email) (equal email user-mail-address))
8146 (message-remove-header "From")
8147 (goto-char (point-max))
8148 (insert "From: " (let ((user-mail-address email)) (message-make-from))
8149 "\n"))))
8150
8151 (defun message-options-get (symbol)
8152 (cdr (assq symbol message-options)))
8153
8154 (defun message-options-set (symbol value)
8155 (let ((the-cons (assq symbol message-options)))
8156 (if the-cons
8157 (if value
8158 (setcdr the-cons value)
8159 (setq message-options (delq the-cons message-options)))
8160 (and value
8161 (push (cons symbol value) message-options))))
8162 value)
8163
8164 (defun message-options-set-recipient ()
8165 (save-restriction
8166 (message-narrow-to-headers-or-head)
8167 (message-options-set 'message-sender
8168 (mail-strip-quoted-names
8169 (message-fetch-field "from")))
8170 (message-options-set 'message-recipients
8171 (mail-strip-quoted-names
8172 (let ((to (message-fetch-field "to"))
8173 (cc (message-fetch-field "cc"))
8174 (bcc (message-fetch-field "bcc")))
8175 (concat
8176 (or to "")
8177 (if (and to cc) ", ")
8178 (or cc "")
8179 (if (and (or to cc) bcc) ", ")
8180 (or bcc "")))))))
8181
8182 (defun message-hide-headers ()
8183 "Hide headers based on the `message-hidden-headers' variable."
8184 (let ((regexps (if (stringp message-hidden-headers)
8185 (list message-hidden-headers)
8186 message-hidden-headers))
8187 (inhibit-point-motion-hooks t)
8188 (inhibit-modification-hooks t)
8189 (end-of-headers (point-min)))
8190 (when regexps
8191 (save-excursion
8192 (save-restriction
8193 (message-narrow-to-headers)
8194 (goto-char (point-min))
8195 (while (not (eobp))
8196 (if (not (message-hide-header-p regexps))
8197 (message-next-header)
8198 (let ((begin (point))
8199 header header-len)
8200 (message-next-header)
8201 (setq header (buffer-substring begin (point))
8202 header-len (- (point) begin))
8203 (delete-region begin (point))
8204 (goto-char end-of-headers)
8205 (insert header)
8206 (setq end-of-headers
8207 (+ end-of-headers header-len))))))))
8208 (narrow-to-region end-of-headers (point-max))))
8209
8210 (defun message-hide-header-p (regexps)
8211 (let ((result nil)
8212 (reverse nil))
8213 (when (eq (car regexps) 'not)
8214 (setq reverse t)
8215 (pop regexps))
8216 (dolist (regexp regexps)
8217 (setq result (or result (looking-at regexp))))
8218 (if reverse
8219 (not result)
8220 result)))
8221
8222 (declare-function ecomplete-add-item "ecomplete" (type key text))
8223 (declare-function ecomplete-save "ecomplete" ())
8224
8225 (defun message-put-addresses-in-ecomplete ()
8226 (require 'ecomplete)
8227 (dolist (header '("to" "cc" "from" "reply-to"))
8228 (let ((value (message-field-value header)))
8229 (dolist (string (mail-header-parse-addresses value 'raw))
8230 (setq string
8231 (replace-regexp-in-string
8232 "\n" ""
8233 (replace-regexp-in-string "^ +\\| +$" "" string)))
8234 (ecomplete-add-item 'mail (car (mail-header-parse-address string))
8235 string))))
8236 (ecomplete-save))
8237
8238 (autoload 'ecomplete-display-matches "ecomplete")
8239
8240 (defun message-display-abbrev (&optional choose)
8241 "Display the next possible abbrev for the text before point."
8242 (interactive (list t))
8243 (when (and (memq (char-after (point-at-bol)) '(?C ?T ?\t ? ))
8244 (message-point-in-header-p)
8245 (save-excursion
8246 (beginning-of-line)
8247 (while (and (memq (char-after) '(?\t ? ))
8248 (zerop (forward-line -1))))
8249 (looking-at "To:\\|Cc:")))
8250 (let* ((end (point))
8251 (start (save-excursion
8252 (and (re-search-backward "[\n\t ]" nil t)
8253 (1+ (point)))))
8254 (word (when start (buffer-substring start end)))
8255 (match (when (and word
8256 (not (zerop (length word))))
8257 (ecomplete-display-matches 'mail word choose))))
8258 (when (and choose match)
8259 (delete-region start end)
8260 (insert match)))))
8261
8262 ;; To send pre-formatted letters like the example below, you can use
8263 ;; `message-send-form-letter':
8264 ;; --8<---------------cut here---------------start------------->8---
8265 ;; To: alice@invalid.invalid
8266 ;; Subject: Verification of your contact information
8267 ;; From: Contact verification <admin@foo.invalid>
8268 ;; --text follows this line--
8269 ;; Hi Alice,
8270 ;; please verify that your contact information is still valid:
8271 ;; Alice A, A avenue 11, 1111 A town, Austria
8272 ;; ----------next form letter message follows this line----------
8273 ;; To: bob@invalid.invalid
8274 ;; Subject: Verification of your contact information
8275 ;; From: Contact verification <admin@foo.invalid>
8276 ;; --text follows this line--
8277 ;; Hi Bob,
8278 ;; please verify that your contact information is still valid:
8279 ;; Bob, B street 22, 22222 Be town, Belgium
8280 ;; ----------next form letter message follows this line----------
8281 ;; To: charlie@invalid.invalid
8282 ;; Subject: Verification of your contact information
8283 ;; From: Contact verification <admin@foo.invalid>
8284 ;; --text follows this line--
8285 ;; Hi Charlie,
8286 ;; please verify that your contact information is still valid:
8287 ;; Charlie Chaplin, C plaza 33, 33333 C town, Chile
8288 ;; --8<---------------cut here---------------end--------------->8---
8289
8290 ;; FIXME: What is the most common term (circular letter, form letter, serial
8291 ;; letter, standard letter) for such kind of letter? See also
8292 ;; <http://en.wikipedia.org/wiki/Form_letter>
8293
8294 ;; FIXME: Maybe extent message-mode's font-lock support to recognize
8295 ;; `message-form-letter-separator', i.e. highlight each message like a single
8296 ;; message.
8297
8298 (defcustom message-form-letter-separator
8299 "\n----------next form letter message follows this line----------\n"
8300 "Separator for `message-send-form-letter'."
8301 ;; :group 'message-form-letter
8302 :group 'message-various
8303 :version "23.1" ;; No Gnus
8304 :type 'string)
8305
8306 (defcustom message-send-form-letter-delay 1
8307 "Delay in seconds when sending a message with `message-send-form-letter'.
8308 Only used when `message-send-form-letter' is called with non-nil
8309 argument `force'."
8310 ;; :group 'message-form-letter
8311 :group 'message-various
8312 :version "23.1" ;; No Gnus
8313 :type 'integer)
8314
8315 (defun message-send-form-letter (&optional force)
8316 "Sent all form letter messages from current buffer.
8317 Unless FORCE, prompt before sending.
8318
8319 The messages are separated by `message-form-letter-separator'.
8320 Header and body are separated by `mail-header-separator'."
8321 (interactive "P")
8322 (let ((sent 0) (skipped 0)
8323 start end text
8324 buff
8325 to done)
8326 (goto-char (point-min))
8327 (while (not done)
8328 (setq start (point)
8329 end (if (search-forward message-form-letter-separator nil t)
8330 (- (point) (length message-form-letter-separator) -1)
8331 (setq done t)
8332 (point-max)))
8333 (setq text
8334 (buffer-substring-no-properties start end))
8335 (setq buff (generate-new-buffer "*mail - form letter*"))
8336 (with-current-buffer buff
8337 (insert text)
8338 (message-mode)
8339 (setq to (message-fetch-field "To"))
8340 (switch-to-buffer buff)
8341 (when force
8342 (sit-for message-send-form-letter-delay))
8343 (if (or force
8344 (y-or-n-p (format-message "Send message to `%s'? " to)))
8345 (progn
8346 (setq sent (1+ sent))
8347 (message-send-and-exit))
8348 (message "Message to `%s' skipped." to)
8349 (setq skipped (1+ skipped)))
8350 (when (buffer-live-p buff)
8351 (kill-buffer buff))))
8352 (message "%s message(s) sent, %s skipped." sent skipped)))
8353
8354 (defun message-replace-header (header new-value &optional after force)
8355 "Remove HEADER and insert the NEW-VALUE.
8356 If AFTER, insert after this header. If FORCE, insert new field
8357 even if NEW-VALUE is empty."
8358 ;; Similar to `nnheader-replace-header' but for message buffers.
8359 (save-excursion
8360 (save-restriction
8361 (message-narrow-to-headers)
8362 (message-remove-header header))
8363 (when (or force (> (length new-value) 0))
8364 (if after
8365 (message-position-on-field header after)
8366 (message-position-on-field header))
8367 (insert new-value))))
8368
8369 (defcustom message-recipients-without-full-name
8370 (list "ding@gnus.org"
8371 "bugs@gnus.org"
8372 "emacs-devel@gnu.org"
8373 "emacs-pretest-bug@gnu.org"
8374 "bug-gnu-emacs@gnu.org")
8375 "Mail addresses that have no full name.
8376 Used in `message-simplify-recipients'."
8377 ;; Maybe the addresses could be extracted from
8378 ;; `gnus-parameter-to-list-alist'?
8379 :type '(choice (const :tag "None" nil)
8380 (repeat string))
8381 :version "23.1" ;; No Gnus
8382 :group 'message-headers)
8383
8384 (defun message-simplify-recipients ()
8385 (interactive)
8386 (dolist (hdr '("Cc" "To"))
8387 (message-replace-header
8388 hdr
8389 (mapconcat
8390 (lambda (addrcomp)
8391 (if (and message-recipients-without-full-name
8392 (string-match
8393 (regexp-opt message-recipients-without-full-name)
8394 (cadr addrcomp)))
8395 (cadr addrcomp)
8396 (if (car addrcomp)
8397 (message-make-from (car addrcomp) (cadr addrcomp))
8398 (cadr addrcomp))))
8399 (when (message-fetch-field hdr)
8400 (mail-extract-address-components
8401 (message-fetch-field hdr) t))
8402 ", "))))
8403
8404 ;;; multipart/related and HTML support.
8405
8406 (defun message-make-html-message-with-image-files (files)
8407 "Make a message containing the current dired-marked image files."
8408 (interactive (list (dired-get-marked-files nil current-prefix-arg)))
8409 (message-mail)
8410 (message-goto-body)
8411 (insert "<#part type=text/html>\n\n")
8412 (dolist (file files)
8413 (insert (format "<img src=%S>\n\n" file)))
8414 (message-toggle-image-thumbnails)
8415 (message-goto-to))
8416
8417 (defun message-toggle-image-thumbnails ()
8418 "For any included image files, insert a thumbnail of that image."
8419 (interactive)
8420 (let ((overlays (overlays-in (point-min) (point-max)))
8421 (displayed nil))
8422 (while overlays
8423 (let ((overlay (car overlays)))
8424 (when (overlay-get overlay 'put-image)
8425 (delete-overlay overlay)
8426 (setq displayed t)))
8427 (setq overlays (cdr overlays)))
8428 (unless displayed
8429 (save-excursion
8430 (goto-char (point-min))
8431 (while (re-search-forward "<img.*src=\"\\([^\"]+\\)" nil t)
8432 (let ((file (match-string 1))
8433 (edges (window-inside-pixel-edges
8434 (get-buffer-window (current-buffer)))))
8435 (put-image
8436 (create-image
8437 file 'imagemagick nil
8438 :max-width (truncate
8439 (* 0.7 (- (nth 2 edges) (nth 0 edges))))
8440 :max-height (truncate
8441 (* 0.5 (- (nth 3 edges) (nth 1 edges)))))
8442 (match-beginning 0)
8443 " ")))))))
8444
8445 (provide 'message)
8446
8447 (run-hooks 'message-load-hook)
8448
8449 ;; Local Variables:
8450 ;; coding: utf-8
8451 ;; End:
8452
8453 ;;; message.el ends here