eec8456642516b7e6526903b8c3a9cd31b49593b
[gnus] / lisp / message.el
1 ;;; message.el --- composing mail and news messages
2 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004
3 ;;        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 2, or (at your option)
13 ;; 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; see the file COPYING.  If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
24
25 ;;; Commentary:
26
27 ;; This mode provides mail-sending facilities from within Emacs.  It
28 ;; consists mainly of large chunks of code from the sendmail.el,
29 ;; gnus-msg.el and rnewspost.el files.
30
31 ;;; Code:
32
33 (eval-when-compile
34   (require 'cl)
35   (defvar gnus-message-group-art)
36   (defvar gnus-list-identifiers)) ; gnus-sum is required where necessary
37 (require 'canlock)
38 (require 'mailheader)
39 (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 (if (featurep 'xemacs)
44     (require 'mail-abbrevs)
45   (require 'mailabbrev))
46 (require 'mail-parse)
47 (require 'mml)
48 (require 'rfc822)
49
50 (defgroup message '((user-mail-address custom-variable)
51                     (user-full-name custom-variable))
52   "Mail and news message composing."
53   :link '(custom-manual "(message)Top")
54   :group 'mail
55   :group 'news)
56
57 (put 'user-mail-address 'custom-type 'string)
58 (put 'user-full-name 'custom-type 'string)
59
60 (defgroup message-various nil
61   "Various Message Variables"
62   :link '(custom-manual "(message)Various Message Variables")
63   :group 'message)
64
65 (defgroup message-buffers nil
66   "Message Buffers"
67   :link '(custom-manual "(message)Message Buffers")
68   :group 'message)
69
70 (defgroup message-sending nil
71   "Message Sending"
72   :link '(custom-manual "(message)Sending Variables")
73   :group 'message)
74
75 (defgroup message-interface nil
76   "Message Interface"
77   :link '(custom-manual "(message)Interface")
78   :group 'message)
79
80 (defgroup message-forwarding nil
81   "Message Forwarding"
82   :link '(custom-manual "(message)Forwarding")
83   :group 'message-interface)
84
85 (defgroup message-insertion nil
86   "Message Insertion"
87   :link '(custom-manual "(message)Insertion")
88   :group 'message)
89
90 (defgroup message-headers nil
91   "Message Headers"
92   :link '(custom-manual "(message)Message Headers")
93   :group 'message)
94
95 (defgroup message-news nil
96   "Composing News Messages"
97   :group 'message)
98
99 (defgroup message-mail nil
100   "Composing Mail Messages"
101   :group 'message)
102
103 (defgroup message-faces nil
104   "Faces used for message composing."
105   :group 'message
106   :group 'faces)
107
108 (defcustom message-directory "~/Mail/"
109   "*Directory from which all other mail file variables are derived."
110   :group 'message-various
111   :type 'directory)
112
113 (defcustom message-max-buffers 10
114   "*How many buffers to keep before starting to kill them off."
115   :group 'message-buffers
116   :type 'integer)
117
118 (defcustom message-send-rename-function nil
119   "Function called to rename the buffer after sending it."
120   :group 'message-buffers
121   :type '(choice function (const nil)))
122
123 (defcustom message-fcc-handler-function 'message-output
124   "*A function called to save outgoing articles.
125 This function will be called with the name of the file to store the
126 article in.  The default function is `message-output' which saves in Unix
127 mailbox format."
128   :type '(radio (function-item message-output)
129                 (function :tag "Other"))
130   :group 'message-sending)
131
132 (defcustom message-fcc-externalize-attachments nil
133   "If non-nil, attachments are included as external parts in Fcc copies."
134   :type 'boolean
135   :group 'message-sending)
136
137 (defcustom message-courtesy-message
138   "The following message is a courtesy copy of an article\nthat has been posted to %s as well.\n\n"
139   "*This is inserted at the start of a mailed copy of a posted message.
140 If the string contains the format spec \"%s\", the Newsgroups
141 the article has been posted to will be inserted there.
142 If this variable is nil, no such courtesy message will be added."
143   :group 'message-sending
144   :type '(radio (string :format "%t: %v\n" :size 0) (const nil)))
145
146 (defcustom message-ignored-bounced-headers
147   "^\\(Received\\|Return-Path\\|Delivered-To\\):"
148   "*Regexp that matches headers to be removed in resent bounced mail."
149   :group 'message-interface
150   :type 'regexp)
151
152 ;;;###autoload
153 (defcustom message-from-style 'default
154   "*Specifies how \"From\" headers look.
155
156 If nil, they contain just the return address like:
157         king@grassland.com
158 If `parens', they look like:
159         king@grassland.com (Elvis Parsley)
160 If `angles', they look like:
161         Elvis Parsley <king@grassland.com>
162
163 Otherwise, most addresses look like `angles', but they look like
164 `parens' if `angles' would need quoting and `parens' would not."
165   :type '(choice (const :tag "simple" nil)
166                  (const parens)
167                  (const angles)
168                  (const default))
169   :group 'message-headers)
170
171 (defcustom message-insert-canlock t
172   "Whether to insert a Cancel-Lock header in news postings."
173   :version "21.3"
174   :group 'message-headers
175   :type 'boolean)
176
177 (defcustom message-syntax-checks
178   (if message-insert-canlock '((sender . disabled)) nil)
179   ;; Guess this one shouldn't be easy to customize...
180   "*Controls what syntax checks should not be performed on outgoing posts.
181 To disable checking of long signatures, for instance, add
182  `(signature . disabled)' to this list.
183
184 Don't touch this variable unless you really know what you're doing.
185
186 Checks include `subject-cmsg', `multiple-headers', `sendsys',
187 `message-id', `from', `long-lines', `control-chars', `size',
188 `new-text', `quoting-style', `redirected-followup', `signature',
189 `approved', `sender', `empty', `empty-headers', `message-id', `from',
190 `subject', `shorten-followup-to', `existing-newsgroups',
191 `buffer-file-name', `unchanged', `newsgroups', `reply-to',
192 `continuation-headers', `long-header-lines', `invisible-text' and
193 `illegible-text'."
194   :group 'message-news
195   :type '(repeat sexp))                 ; Fixme: improve this
196
197 (defcustom message-required-headers '((optional . References)
198                                       From)
199   "*Headers to be generated or prompted for when sending a message.
200 Also see `message-required-news-headers' and
201 `message-required-mail-headers'."
202   :group 'message-news
203   :group 'message-headers
204   :link '(custom-manual "(message)Message Headers")
205   :type '(repeat sexp))
206
207 (defcustom message-draft-headers '(References From)
208   "*Headers to be generated when saving a draft message."
209   :group 'message-news
210   :group 'message-headers
211   :link '(custom-manual "(message)Message Headers")
212   :type '(repeat sexp))
213
214 (defcustom message-required-news-headers
215   '(From Newsgroups Subject Date Message-ID
216          (optional . Organization)
217          (optional . User-Agent))
218   "*Headers to be generated or prompted for when posting an article.
219 RFC977 and RFC1036 require From, Date, Newsgroups, Subject,
220 Message-ID.  Organization, Lines, In-Reply-To, Expires, and
221 User-Agent are optional.  If don't you want message to insert some
222 header, remove it from this list."
223   :group 'message-news
224   :group 'message-headers
225   :link '(custom-manual "(message)Message Headers")
226   :type '(repeat sexp))
227
228 (defcustom message-required-mail-headers
229   '(From Subject Date (optional . In-Reply-To) Message-ID
230          (optional . User-Agent))
231   "*Headers to be generated or prompted for when mailing a message.
232 It is recommended that From, Date, To, Subject and Message-ID be
233 included.  Organization and User-Agent are optional."
234   :group 'message-mail
235   :group 'message-headers
236   :link '(custom-manual "(message)Message Headers")
237   :type '(repeat sexp))
238
239 (defcustom message-deletable-headers '(Message-ID Date Lines)
240   "Headers to be deleted if they already exist and were generated by message previously."
241   :group 'message-headers
242   :link '(custom-manual "(message)Message Headers")
243   :type 'sexp)
244
245 (defcustom message-ignored-news-headers
246   "^NNTP-Posting-Host:\\|^Xref:\\|^[BGF]cc:\\|^Resent-Fcc:\\|^X-Draft-From:\\|^X-Gnus-Agent-Meta-Information:"
247   "*Regexp of headers to be removed unconditionally before posting."
248   :group 'message-news
249   :group 'message-headers
250   :link '(custom-manual "(message)Message Headers")
251   :type 'regexp)
252
253 (defcustom message-ignored-mail-headers
254   "^[GF]cc:\\|^Resent-Fcc:\\|^Xref:\\|^X-Draft-From:\\|^X-Gnus-Agent-Meta-Information:"
255   "*Regexp of headers to be removed unconditionally before mailing."
256   :group 'message-mail
257   :group 'message-headers
258   :link '(custom-manual "(message)Mail Headers")
259   :type 'regexp)
260
261 (defcustom message-ignored-supersedes-headers "^Path:\\|^Date\\|^NNTP-Posting-Host:\\|^Xref:\\|^Lines:\\|^Received:\\|^X-From-Line:\\|^X-Trace:\\|^X-Complaints-To:\\|Return-Path:\\|^Supersedes:\\|^NNTP-Posting-Date:\\|^X-Trace:\\|^X-Complaints-To:\\|^Cancel-Lock:\\|^Cancel-Key:\\|^X-Hashcash:\\|^X-Payment:"
262   "*Header lines matching this regexp will be deleted before posting.
263 It's best to delete old Path and Date headers before posting to avoid
264 any confusion."
265   :group 'message-interface
266   :link '(custom-manual "(message)Superseding")
267   :type 'regexp)
268
269 (defcustom message-subject-re-regexp
270   "^[ \t]*\\([Rr][Ee]\\(\\[[0-9]*\\]\\)*:[ \t]*\\)*[ \t]*"
271   "*Regexp matching \"Re: \" in the subject line."
272   :group 'message-various
273   :link '(custom-manual "(message)Message Headers")
274   :type 'regexp)
275
276 ;;; Start of variables adopted from `message-utils.el'.
277
278 (defcustom message-subject-trailing-was-query 'ask
279   "*What to do with trailing \"(was: <old subject>)\" in subject lines.
280 If nil, leave the subject unchanged.  If it is the symbol `ask', query
281 the user what do do.  In this case, the subject is matched against
282 `message-subject-trailing-was-ask-regexp'.  If
283 `message-subject-trailing-was-query' is t, always strip the trailing
284 old subject.  In this case, `message-subject-trailing-was-regexp' is
285 used."
286   :type '(choice (const :tag "never" nil)
287                  (const :tag "always strip" t)
288                  (const ask))
289   :link '(custom-manual "(message)Message Headers")
290   :group 'message-various)
291
292 (defcustom message-subject-trailing-was-ask-regexp
293   "[ \t]*\\([[(]+[Ww][Aa][Ss][ \t]*.*[\])]+\\)"
294   "*Regexp matching \"(was: <old subject>)\" in the subject line.
295
296 The function `message-strip-subject-trailing-was' uses this regexp if
297 `message-subject-trailing-was-query' is set to the symbol `ask'.  If
298 the variable is t instead of `ask', use
299 `message-subject-trailing-was-regexp' instead.
300
301 It is okay to create some false positives here, as the user is asked."
302   :group 'message-various
303   :link '(custom-manual "(message)Message Headers")
304   :type 'regexp)
305
306 (defcustom message-subject-trailing-was-regexp
307   "[ \t]*\\((*[Ww][Aa][Ss]:[ \t]*.*)\\)"
308   "*Regexp matching \"(was: <old subject>)\" in the subject line.
309
310 If `message-subject-trailing-was-query' is set to t, the subject is
311 matched against `message-subject-trailing-was-regexp' in
312 `message-strip-subject-trailing-was'.  You should use a regexp creating very
313 few false positives here."
314   :group 'message-various
315   :link '(custom-manual "(message)Message Headers")
316   :type 'regexp)
317
318 ;; Fixme: Why are all these things autoloaded?
319
320 ;;; marking inserted text
321
322 ;;;###autoload
323 (defcustom message-mark-insert-begin
324   "--8<---------------cut here---------------start------------->8---\n"
325   "How to mark the beginning of some inserted text."
326   :type 'string
327   :link '(custom-manual "(message)Insertion Variables")
328   :group 'message-various)
329
330 ;;;###autoload
331 (defcustom message-mark-insert-end
332   "--8<---------------cut here---------------end--------------->8---\n"
333   "How to mark the end of some inserted text."
334   :type 'string
335   :link '(custom-manual "(message)Insertion Variables")
336   :group 'message-various)
337
338 ;;;###autoload
339 (defcustom message-archive-header
340   "X-No-Archive: Yes\n"
341   "Header to insert when you don't want your article to be archived.
342 Archives \(such as groups.google.com\) respect this header."
343   :type 'string
344   :link '(custom-manual "(message)Header Commands")
345   :group 'message-various)
346
347 ;;;###autoload
348 (defcustom message-archive-note
349   "X-No-Archive: Yes - save http://groups.google.com/"
350   "Note to insert why you wouldn't want this posting archived.
351 If nil, don't insert any text in the body."
352   :type '(radio (string :format "%t: %v\n" :size 0)
353                 (const nil))
354   :link '(custom-manual "(message)Header Commands")
355   :group 'message-various)
356
357 ;;; Crossposts and Followups
358 ;; inspired by JoH-followup-to by Jochem Huhman <joh  at gmx.de>
359 ;; new suggestions by R. Weikusat <rw at another.de>
360
361 (defvar message-cross-post-old-target nil
362   "Old target for cross-posts or follow-ups.")
363 (make-variable-buffer-local 'message-cross-post-old-target)
364
365 ;;;###autoload
366 (defcustom message-cross-post-default t
367   "When non-nil `message-cross-post-followup-to' will perform a crosspost.
368 If nil, `message-cross-post-followup-to' will only do a followup.  Note that
369 you can explicitly override this setting by calling
370 `message-cross-post-followup-to' with a prefix."
371   :type 'boolean
372   :group 'message-various)
373
374 ;;;###autoload
375 (defcustom message-cross-post-note
376   "Crosspost & Followup-To: "
377   "Note to insert before signature to notify of cross-post and follow-up."
378   :type 'string
379   :group 'message-various)
380
381 ;;;###autoload
382 (defcustom message-followup-to-note
383   "Followup-To: "
384   "Note to insert before signature to notify of follow-up only."
385   :type 'string
386   :group 'message-various)
387
388 ;;;###autoload
389 (defcustom message-cross-post-note-function
390   'message-cross-post-insert-note
391   "Function to use to insert note about Crosspost or Followup-To.
392 The function will be called with four arguments.  The function should not only
393 insert a note, but also ensure old notes are deleted.  See the documentation
394 for `message-cross-post-insert-note'."
395   :type 'function
396   :group 'message-various)
397
398 ;;; End of variables adopted from `message-utils.el'.
399
400 ;;;###autoload
401 (defcustom message-signature-separator "^-- *$"
402   "Regexp matching the signature separator."
403   :type 'regexp
404   :link '(custom-manual "(message)Various Message Variables")
405   :group 'message-various)
406
407 (defcustom message-elide-ellipsis "\n[...]\n\n"
408   "*The string which is inserted for elided text."
409   :type 'string
410   :link '(custom-manual "(message)Various Commands")
411   :group 'message-various)
412
413 (defcustom message-interactive t
414   "Non-nil means when sending a message wait for and display errors.
415 nil means let mailer mail back a message to report errors."
416   :group 'message-sending
417   :group 'message-mail
418   :link '(custom-manual "(message)Sending Variables")
419   :type 'boolean)
420
421 (defcustom message-generate-new-buffers 'unique
422   "*Non-nil means create a new message buffer whenever `message-setup' is called.
423 If this is a function, call that function with three parameters:  The type,
424 the to address and the group name.  (Any of these may be nil.)  The function
425 should return the new buffer name."
426   :group 'message-buffers
427   :link '(custom-manual "(message)Message Buffers")
428   :type '(choice (const :tag "off" nil)
429                  (const :tag "unique" unique)
430                  (const :tag "unsent" unsent)
431                  (function fun)))
432
433 (defcustom message-kill-buffer-on-exit nil
434   "*Non-nil means that the message buffer will be killed after sending a message."
435   :group 'message-buffers
436   :link '(custom-manual "(message)Message Buffers")
437   :type 'boolean)
438
439 (eval-when-compile
440   (defvar gnus-local-organization))
441 (defcustom message-user-organization
442   (or (and (boundp 'gnus-local-organization)
443            (stringp gnus-local-organization)
444            gnus-local-organization)
445       (getenv "ORGANIZATION")
446       t)
447   "*String to be used as an Organization header.
448 If t, use `message-user-organization-file'."
449   :group 'message-headers
450   :type '(choice string
451                  (const :tag "consult file" t)))
452
453 ;;;###autoload
454 (defcustom message-user-organization-file "/usr/lib/news/organization"
455   "*Local news organization file."
456   :type 'file
457   :link '(custom-manual "(message)News Headers")
458   :group 'message-headers)
459
460 (defcustom message-make-forward-subject-function
461   #'message-forward-subject-name-subject
462   "*List of functions called to generate subject headers for forwarded messages.
463 The subject generated by the previous function is passed into each
464 successive function.
465
466 The provided functions are:
467
468 * `message-forward-subject-author-subject' Source of article (author or
469       newsgroup), in brackets followed by the subject
470 * `message-forward-subject-name-subject' Source of article (name of author
471       or newsgroup), in brackets followed by the subject
472 * `message-forward-subject-fwd' Subject of article with 'Fwd:' prepended
473       to it."
474   :group 'message-forwarding
475   :link '(custom-manual "(message)Forwarding")
476   :type '(radio (function-item message-forward-subject-author-subject)
477                 (function-item message-forward-subject-fwd)
478                 (function-item message-forward-subject-name-subject)
479                 (repeat :tag "List of functions" function)))
480
481 (defcustom message-forward-as-mime t
482   "*Non-nil means forward messages as an inline/rfc822 MIME section.
483 Otherwise, directly inline the old message in the forwarded message."
484   :version "21.1"
485   :group 'message-forwarding
486   :link '(custom-manual "(message)Forwarding")
487   :type 'boolean)
488
489 (defcustom message-forward-show-mml 'best
490   "*Non-nil means show forwarded messages as MML (decoded from MIME).
491 Otherwise, forwarded messages are unchanged.
492 Can also be the symbol `best' to indicate that MML should be
493 used, except when it is a bad idea to use MML.  One example where
494 it is a bad idea is when forwarding a signed or encrypted
495 message, because converting MIME to MML would invalidate the
496 digital signature."
497   :version "21.1"
498   :group 'message-forwarding
499   :type '(choice (const :tag "use MML" t)
500                  (const :tag "don't use MML " nil)
501                  (const :tag "use MML when appropriate" best)))
502
503 (defcustom message-forward-before-signature t
504   "*Non-nil means put forwarded message before signature, else after."
505   :group 'message-forwarding
506   :type 'boolean)
507
508 (defcustom message-wash-forwarded-subjects nil
509   "*Non-nil means try to remove as much cruft as possible from the subject.
510 Done before generating the new subject of a forward."
511   :group 'message-forwarding
512   :link '(custom-manual "(message)Forwarding")
513   :type 'boolean)
514
515 (defcustom message-ignored-resent-headers "^Return-receipt\\|^X-Gnus\\|^Gnus-Warning:\\|^>?From "
516   "*All headers that match this regexp will be deleted when resending a message."
517   :group 'message-interface
518   :link '(custom-manual "(message)Resending")
519   :type 'regexp)
520
521 (defcustom message-forward-ignored-headers "^Content-Transfer-Encoding:\\|^X-Gnus"
522   "*All headers that match this regexp will be deleted when forwarding a message."
523   :version "21.1"
524   :group 'message-forwarding
525   :type '(choice (const :tag "None" nil)
526                  regexp))
527
528 (defcustom message-ignored-cited-headers "."
529   "*Delete these headers from the messages you yank."
530   :group 'message-insertion
531   :link '(custom-manual "(message)Insertion Variables")
532   :type 'regexp)
533
534 (defcustom message-cite-prefix-regexp
535   (if (string-match "[[:digit:]]" "1") ;; support POSIX?
536       "\\([ \t]*[-_.[:word:]]+>+\\|[ \t]*[]>|}+]\\)+"
537     ;; ?-, ?_ or ?. MUST NOT be in syntax entry w.
538     (let (non-word-constituents)
539       (with-syntax-table text-mode-syntax-table
540         (setq non-word-constituents
541               (concat
542                (if (string-match "\\w" "-")  "" "-")
543                (if (string-match "\\w" "_")  "" "_")
544                (if (string-match "\\w" ".")  "" "."))))
545       (if (equal non-word-constituents "")
546           "\\([ \t]*\\(\\w\\)+>+\\|[ \t]*[]>|}+]\\)+"
547         (concat "\\([ \t]*\\(\\w\\|["
548                 non-word-constituents
549                 "]\\)+>+\\|[ \t]*[]>|}+]\\)+"))))
550   "*Regexp matching the longest possible citation prefix on a line."
551   :group 'message-insertion
552   :link '(custom-manual "(message)Insertion Variables")
553   :type 'regexp)
554
555 (defcustom message-cancel-message "I am canceling my own article.\n"
556   "Message to be inserted in the cancel message."
557   :group 'message-interface
558   :link '(custom-manual "(message)Canceling News")
559   :type 'string)
560
561 ;; Useful to set in site-init.el
562 ;;;###autoload
563 (defcustom message-send-mail-function 'message-send-mail-with-sendmail
564   "Function to call to send the current buffer as mail.
565 The headers should be delimited by a line whose contents match the
566 variable `mail-header-separator'.
567
568 Valid values include `message-send-mail-with-sendmail' (the default),
569 `message-send-mail-with-mh', `message-send-mail-with-qmail',
570 `message-smtpmail-send-it', `smtpmail-send-it' and `feedmail-send-it'.
571
572 See also `send-mail-function'."
573   :type '(radio (function-item message-send-mail-with-sendmail)
574                 (function-item message-send-mail-with-mh)
575                 (function-item message-send-mail-with-qmail)
576                 (function-item message-smtpmail-send-it)
577                 (function-item smtpmail-send-it)
578                 (function-item feedmail-send-it)
579                 (function :tag "Other"))
580   :group 'message-sending
581   :link '(custom-manual "(message)Mail Variables")
582   :group 'message-mail)
583
584 (defcustom message-send-news-function 'message-send-news
585   "Function to call to send the current buffer as news.
586 The headers should be delimited by a line whose contents match the
587 variable `mail-header-separator'."
588   :group 'message-sending
589   :group 'message-news
590   :link '(custom-manual "(message)News Variables")
591   :type 'function)
592
593 (defcustom message-reply-to-function nil
594   "If non-nil, function that should return a list of headers.
595 This function should pick out addresses from the To, Cc, and From headers
596 and respond with new To and Cc headers."
597   :group 'message-interface
598   :link '(custom-manual "(message)Reply")
599   :type '(choice function (const nil)))
600
601 (defcustom message-wide-reply-to-function nil
602   "If non-nil, function that should return a list of headers.
603 This function should pick out addresses from the To, Cc, and From headers
604 and respond with new To and Cc headers."
605   :group 'message-interface
606   :link '(custom-manual "(message)Wide Reply")
607   :type '(choice function (const nil)))
608
609 (defcustom message-followup-to-function nil
610   "If non-nil, function that should return a list of headers.
611 This function should pick out addresses from the To, Cc, and From headers
612 and respond with new To and Cc headers."
613   :group 'message-interface
614   :link '(custom-manual "(message)Followup")
615   :type '(choice function (const nil)))
616
617 (defcustom message-use-followup-to 'ask
618   "*Specifies what to do with Followup-To header.
619 If nil, always ignore the header.  If it is t, use its value, but
620 query before using the \"poster\" value.  If it is the symbol `ask',
621 always query the user whether to use the value.  If it is the symbol
622 `use', always use the value."
623   :group 'message-interface
624   :link '(custom-manual "(message)Followup")
625   :type '(choice (const :tag "ignore" nil)
626                  (const :tag "use & query" t)
627                  (const use)
628                  (const ask)))
629
630 (defcustom message-use-mail-followup-to 'use
631   "*Specifies what to do with Mail-Followup-To header.
632 If nil, always ignore the header.  If it is the symbol `ask', always
633 query the user whether to use the value.  If it is the symbol `use',
634 always use the value."
635   :group 'message-interface
636   :link '(custom-manual "(message)Mailing Lists")
637   :type '(choice (const :tag "ignore" nil)
638                  (const use)
639                  (const ask)))
640
641 (defcustom message-subscribed-address-functions nil
642   "*Specifies functions for determining list subscription.
643 If nil, do not attempt to determine list subscription with functions.
644 If non-nil, this variable contains a list of functions which return
645 regular expressions to match lists.  These functions can be used in
646 conjunction with `message-subscribed-regexps' and
647 `message-subscribed-addresses'."
648   :group 'message-interface
649   :link '(custom-manual "(message)Mailing Lists")
650   :type '(repeat sexp))
651
652 (defcustom message-subscribed-address-file nil
653   "*A file containing addresses the user is subscribed to.
654 If nil, do not look at any files to determine list subscriptions.  If
655 non-nil, each line of this file should be a mailing list address."
656   :group 'message-interface
657   :link '(custom-manual "(message)Mailing Lists")
658   :type '(radio (file :format "%t: %v\n" :size 0)
659                 (const nil)))
660
661 (defcustom message-subscribed-addresses nil
662   "*Specifies a list of addresses the user is subscribed to.
663 If nil, do not use any predefined list subscriptions.  This list of
664 addresses can be used in conjunction with
665 `message-subscribed-address-functions' and `message-subscribed-regexps'."
666   :group 'message-interface
667   :link '(custom-manual "(message)Mailing Lists")
668   :type '(repeat string))
669
670 (defcustom message-subscribed-regexps nil
671   "*Specifies a list of addresses the user is subscribed to.
672 If nil, do not use any predefined list subscriptions.  This list of
673 regular expressions can be used in conjunction with
674 `message-subscribed-address-functions' and `message-subscribed-addresses'."
675   :group 'message-interface
676   :link '(custom-manual "(message)Mailing Lists")
677   :type '(repeat regexp))
678
679 (defcustom message-allow-no-recipients 'ask
680   "Specifies what to do when there are no recipients other than Gcc/Fcc.
681 If it is the symbol `always', the posting is allowed.  If it is the
682 symbol `never', the posting is not allowed.  If it is the symbol
683 `ask', you are prompted."
684   :group 'message-interface
685   :link '(custom-manual "(message)Message Headers")
686   :type '(choice (const always)
687                  (const never)
688                  (const ask)))
689
690 (defcustom message-sendmail-f-is-evil nil
691   "*Non-nil means don't add \"-f username\" to the sendmail command line.
692 Doing so would be even more evil than leaving it out."
693   :group 'message-sending
694   :link '(custom-manual "(message)Mail Variables")
695   :type 'boolean)
696
697 (defcustom message-sendmail-envelope-from nil
698   "*Envelope-from when sending mail with sendmail.
699 If this is nil, use `user-mail-address'.  If it is the symbol
700 `header', use the From: header of the message."
701   :type '(choice (string :tag "From name")
702                  (const :tag "Use From: header from message" header)
703                  (const :tag "Use `user-mail-address'" nil))
704   :link '(custom-manual "(message)Mail Variables")
705   :group 'message-sending)
706
707 ;; qmail-related stuff
708 (defcustom message-qmail-inject-program "/var/qmail/bin/qmail-inject"
709   "Location of the qmail-inject program."
710   :group 'message-sending
711   :link '(custom-manual "(message)Mail Variables")
712   :type 'file)
713
714 (defcustom message-qmail-inject-args nil
715   "Arguments passed to qmail-inject programs.
716 This should be a list of strings, one string for each argument.  It
717 may also be a function.
718
719 For e.g., if you wish to set the envelope sender address so that bounces
720 go to the right place or to deal with listserv's usage of that address, you
721 might set this variable to '(\"-f\" \"you@some.where\")."
722   :group 'message-sending
723   :link '(custom-manual "(message)Mail Variables")
724   :type '(choice (function)
725                  (repeat string)))
726
727 (eval-when-compile
728   (defvar gnus-post-method)
729   (defvar gnus-select-method))
730 (defcustom message-post-method
731   (cond ((and (boundp 'gnus-post-method)
732               (listp gnus-post-method)
733               gnus-post-method)
734          gnus-post-method)
735         ((boundp 'gnus-select-method)
736          gnus-select-method)
737         (t '(nnspool "")))
738   "*Method used to post news.
739 Note that when posting from inside Gnus, for instance, this
740 variable isn't used."
741   :group 'message-news
742   :group 'message-sending
743   ;; This should be the `gnus-select-method' widget, but that might
744   ;; create a dependence to `gnus.el'.
745   :type 'sexp)
746
747 ;; FIXME: This should be a temporary workaround until someone implements a
748 ;; proper solution.  If a crash happens while replying, the auto-save file
749 ;; will *not* have a `References:' header if `message-generate-headers-first'
750 ;; is nil.  See: http://article.gmane.org/gmane.emacs.gnus.general/51138
751 (defcustom message-generate-headers-first '(references)
752   "Which headers should be generated before starting to compose a message.
753 If t, generate all required headers.  This can also be a list of headers to
754 generate.  The variables `message-required-news-headers' and
755 `message-required-mail-headers' specify which headers to generate.
756
757 Note that the variable `message-deletable-headers' specifies headers which
758 are to be deleted and then re-generated before sending, so this variable
759 will not have a visible effect for those headers."
760   :group 'message-headers
761   :link '(custom-manual "(message)Message Headers")
762   :type '(choice (const :tag "None" nil)
763                  (const :tag "References" '(references))
764                  (const :tag "All" t)
765                  (repeat (sexp :tag "Header"))))
766
767 (defcustom message-setup-hook nil
768   "Normal hook, run each time a new outgoing message is initialized.
769 The function `message-setup' runs this hook."
770   :group 'message-various
771   :link '(custom-manual "(message)Various Message Variables")
772   :type 'hook)
773
774 (defcustom message-cancel-hook nil
775   "Hook run when cancelling articles."
776   :group 'message-various
777   :link '(custom-manual "(message)Various Message Variables")
778   :type 'hook)
779
780 (defcustom message-signature-setup-hook nil
781   "Normal hook, run each time a new outgoing message is initialized.
782 It is run after the headers have been inserted and before
783 the signature is inserted."
784   :group 'message-various
785   :link '(custom-manual "(message)Various Message Variables")
786   :type 'hook)
787
788 (defcustom message-mode-hook nil
789   "Hook run in message mode buffers."
790   :group 'message-various
791   :type 'hook)
792
793 (defcustom message-header-hook nil
794   "Hook run in a message mode buffer narrowed to the headers."
795   :group 'message-various
796   :type 'hook)
797
798 (defcustom message-header-setup-hook nil
799   "Hook called narrowed to the headers when setting up a message buffer."
800   :group 'message-various
801   :link '(custom-manual "(message)Various Message Variables")
802   :type 'hook)
803
804 (defcustom message-minibuffer-local-map
805   (let ((map (make-sparse-keymap 'message-minibuffer-local-map)))
806     (set-keymap-parent map minibuffer-local-map)
807     map)
808   "Keymap for `message-read-from-minibuffer'.")
809
810 ;;;###autoload
811 (defcustom message-citation-line-function 'message-insert-citation-line
812   "*Function called to insert the \"Whomever writes:\" line.
813
814 Note that Gnus provides a feature where the reader can click on
815 `writes:' to hide the cited text.  If you change this line too much,
816 people who read your message will have to change their Gnus
817 configuration.  See the variable `gnus-cite-attribution-suffix'."
818   :type 'function
819   :link '(custom-manual "(message)Insertion Variables")
820   :group 'message-insertion)
821
822 ;;;###autoload
823 (defcustom message-yank-prefix "> "
824   "*Prefix inserted on the lines of yanked messages.
825 Fix `message-cite-prefix-regexp' if it is set to an abnormal value.
826 See also `message-yank-cited-prefix'."
827   :type 'string
828   :link '(custom-manual "(message)Insertion Variables")
829   :group 'message-insertion)
830
831 (defcustom message-yank-cited-prefix ">"
832   "*Prefix inserted on cited or empty lines of yanked messages.
833 Fix `message-cite-prefix-regexp' if it is set to an abnormal value.
834 See also `message-yank-prefix'."
835   :type 'string
836   :link '(custom-manual "(message)Insertion Variables")
837   :group 'message-insertion)
838
839 (defcustom message-indentation-spaces 3
840   "*Number of spaces to insert at the beginning of each cited line.
841 Used by `message-yank-original' via `message-yank-cite'."
842   :group 'message-insertion
843   :link '(custom-manual "(message)Insertion Variables")
844   :type 'integer)
845
846 ;;;###autoload
847 (defcustom message-cite-function 'message-cite-original
848   "*Function for citing an original message.
849 Predefined functions include `message-cite-original' and
850 `message-cite-original-without-signature'.
851 Note that `message-cite-original' uses `mail-citation-hook' if that is non-nil."
852   :type '(radio (function-item message-cite-original)
853                 (function-item message-cite-original-without-signature)
854                 (function-item sc-cite-original)
855                 (function :tag "Other"))
856   :link '(custom-manual "(message)Insertion Variables")
857   :group 'message-insertion)
858
859 ;;;###autoload
860 (defcustom message-indent-citation-function 'message-indent-citation
861   "*Function for modifying a citation just inserted in the mail buffer.
862 This can also be a list of functions.  Each function can find the
863 citation between (point) and (mark t).  And each function should leave
864 point and mark around the citation text as modified."
865   :type 'function
866   :link '(custom-manual "(message)Insertion Variables")
867   :group 'message-insertion)
868
869 ;;;###autoload
870 (defcustom message-signature t
871   "*String to be inserted at the end of the message buffer.
872 If t, the `message-signature-file' file will be inserted instead.
873 If a function, the result from the function will be used instead.
874 If a form, the result from the form will be used instead."
875   :type 'sexp
876   :link '(custom-manual "(message)Insertion Variables")
877   :group 'message-insertion)
878
879 ;;;###autoload
880 (defcustom message-signature-file "~/.signature"
881   "*Name of file containing the text inserted at end of message buffer.
882 Ignored if the named file doesn't exist.
883 If nil, don't insert a signature."
884   :type '(choice file (const :tags "None" nil))
885   :link '(custom-manual "(message)Insertion Variables")
886   :group 'message-insertion)
887
888 ;;;###autoload
889 (defcustom message-signature-insert-empty-line t
890   "*If non-nil, insert an empty line before the signature separator."
891   :type 'boolean
892   :link '(custom-manual "(message)Insertion Variables")
893   :group 'message-insertion)
894
895 (defcustom message-distribution-function nil
896   "*Function called to return a Distribution header."
897   :group 'message-news
898   :group 'message-headers
899   :link '(custom-manual "(message)News Headers")
900   :type '(choice function (const nil)))
901
902 (defcustom message-expires 14
903   "Number of days before your article expires."
904   :group 'message-news
905   :group 'message-headers
906   :link '(custom-manual "(message)News Headers")
907   :type 'integer)
908
909 (defcustom message-user-path nil
910   "If nil, use the NNTP server name in the Path header.
911 If stringp, use this; if non-nil, use no host name (user name only)."
912   :group 'message-news
913   :group 'message-headers
914   :link '(custom-manual "(message)News Headers")
915   :type '(choice (const :tag "nntp" nil)
916                  (string :tag "name")
917                  (sexp :tag "none" :format "%t" t)))
918
919 (defvar message-reply-buffer nil)
920 (defvar message-reply-headers nil
921   "The headers of the current replied article.
922 It is a vector of the following headers:
923 \[number subject from date id references chars lines xref extra].")
924 (defvar message-newsreader nil)
925 (defvar message-mailer nil)
926 (defvar message-sent-message-via nil)
927 (defvar message-checksum nil)
928 (defvar message-send-actions nil
929   "A list of actions to be performed upon successful sending of a message.")
930 (defvar message-exit-actions nil
931   "A list of actions to be performed upon exiting after sending a message.")
932 (defvar message-kill-actions nil
933   "A list of actions to be performed before killing a message buffer.")
934 (defvar message-postpone-actions nil
935   "A list of actions to be performed after postponing a message.")
936
937 (define-widget 'message-header-lines 'text
938   "All header lines must be LFD terminated."
939   :format "%{%t%}:%n%v"
940   :valid-regexp "^\\'"
941   :error "All header lines must be newline terminated")
942
943 (defcustom message-default-headers ""
944   "*A string containing header lines to be inserted in outgoing messages.
945 It is inserted before you edit the message, so you can edit or delete
946 these lines."
947   :group 'message-headers
948   :link '(custom-manual "(message)Message Headers")
949   :type 'message-header-lines)
950
951 (defcustom message-default-mail-headers ""
952   "*A string of header lines to be inserted in outgoing mails."
953   :group 'message-headers
954   :group 'message-mail
955   :link '(custom-manual "(message)Mail Headers")
956   :type 'message-header-lines)
957
958 (defcustom message-default-news-headers ""
959   "*A string of header lines to be inserted in outgoing news articles."
960   :group 'message-headers
961   :group 'message-news
962   :link '(custom-manual "(message)News Headers")
963   :type 'message-header-lines)
964
965 ;; Note: could use /usr/ucb/mail instead of sendmail;
966 ;; options -t, and -v if not interactive.
967 (defcustom message-mailer-swallows-blank-line
968   (if (and (string-match "sparc-sun-sunos\\(\\'\\|[^5]\\)"
969                          system-configuration)
970            (file-readable-p "/etc/sendmail.cf")
971            (let ((buffer (get-buffer-create " *temp*")))
972              (unwind-protect
973                  (save-excursion
974                    (set-buffer buffer)
975                    (insert-file-contents "/etc/sendmail.cf")
976                    (goto-char (point-min))
977                    (let ((case-fold-search nil))
978                      (re-search-forward "^OR\\>" nil t)))
979                (kill-buffer buffer))))
980       ;; According to RFC822, "The field-name must be composed of printable
981       ;; ASCII characters (i. e., characters that have decimal values between
982       ;; 33 and 126, except colon)", i. e., any chars except ctl chars,
983       ;; space, or colon.
984       '(looking-at "[ \t]\\|[][!\"#$%&'()*+,-./0-9;<=>?@A-Z\\\\^_`a-z{|}~]+:"))
985   "*Set this non-nil if the system's mailer runs the header and body together.
986 \(This problem exists on Sunos 4 when sendmail is run in remote mode.)
987 The value should be an expression to test whether the problem will
988 actually occur."
989   :group 'message-sending
990   :link '(custom-manual "(message)Mail Variables")
991   :type 'sexp)
992
993 ;;;###autoload
994 (define-mail-user-agent 'message-user-agent
995   'message-mail 'message-send-and-exit
996   'message-kill-buffer 'message-send-hook)
997
998 (defvar message-mh-deletable-headers '(Message-ID Date Lines Sender)
999   "If non-nil, delete the deletable headers before feeding to mh.")
1000
1001 (defvar message-send-method-alist
1002   '((news message-news-p message-send-via-news)
1003     (mail message-mail-p message-send-via-mail))
1004   "Alist of ways to send outgoing messages.
1005 Each element has the form
1006
1007   \(TYPE PREDICATE FUNCTION)
1008
1009 where TYPE is a symbol that names the method; PREDICATE is a function
1010 called without any parameters to determine whether the message is
1011 a message of type TYPE; and FUNCTION is a function to be called if
1012 PREDICATE returns non-nil.  FUNCTION is called with one parameter --
1013 the prefix.")
1014
1015 (defcustom message-mail-alias-type 'abbrev
1016   "*What alias expansion type to use in Message buffers.
1017 The default is `abbrev', which uses mailabbrev.  nil switches
1018 mail aliases off."
1019   :group 'message
1020   :link '(custom-manual "(message)Mail Aliases")
1021   :type '(choice (const :tag "Use Mailabbrev" abbrev)
1022                  (const :tag "No expansion" nil)))
1023
1024 (defcustom message-auto-save-directory
1025   (file-name-as-directory (nnheader-concat message-directory "drafts"))
1026   "*Directory where Message auto-saves buffers if Gnus isn't running.
1027 If nil, Message won't auto-save."
1028   :group 'message-buffers
1029   :link '(custom-manual "(message)Various Message Variables")
1030   :type '(choice directory (const :tag "Don't auto-save" nil)))
1031
1032 (defcustom message-default-charset
1033   (and (not (mm-multibyte-p)) 'iso-8859-1)
1034   "Default charset used in non-MULE Emacsen.
1035 If nil, you might be asked to input the charset."
1036   :version "21.1"
1037   :group 'message
1038   :link '(custom-manual "(message)Various Message Variables")
1039   :type 'symbol)
1040
1041 (defcustom message-dont-reply-to-names
1042   (and (boundp 'rmail-dont-reply-to-names) rmail-dont-reply-to-names)
1043   "*A regexp specifying addresses to prune when doing wide replies.
1044 A value of nil means exclude your own user name only."
1045   :version "21.1"
1046   :group 'message
1047   :link '(custom-manual "(message)Wide Reply")
1048   :type '(choice (const :tag "Yourself" nil)
1049                  regexp))
1050
1051 (defvar message-shoot-gnksa-feet nil
1052   "*A list of GNKSA feet you are allowed to shoot.
1053 Gnus gives you all the opportunity you could possibly want for
1054 shooting yourself in the foot.  Also, Gnus allows you to shoot the
1055 feet of Good Net-Keeping Seal of Approval.  The following are foot
1056 candidates:
1057 `empty-article'     Allow you to post an empty article;
1058 `quoted-text-only'  Allow you to post quoted text only;
1059 `multiple-copies'   Allow you to post multiple copies;
1060 `cancel-messages'   Allow you to cancel or supersede messages from
1061                     your other email addresses.")
1062
1063 (defsubst message-gnksa-enable-p (feature)
1064   (or (not (listp message-shoot-gnksa-feet))
1065       (memq feature message-shoot-gnksa-feet)))
1066
1067 (defcustom message-hidden-headers nil
1068   "Regexp of headers to be hidden when composing new messages.
1069 This can also be a list of regexps to match headers.  Or a list
1070 starting with `not' and followed by regexps."
1071   :group 'message
1072   :link '(custom-manual "(message)Message Headers")
1073   :type '(repeat regexp))
1074
1075 ;;; Internal variables.
1076 ;;; Well, not really internal.
1077
1078 (defvar message-mode-syntax-table
1079   (let ((table (copy-syntax-table text-mode-syntax-table)))
1080     (modify-syntax-entry ?% ". " table)
1081     (modify-syntax-entry ?> ". " table)
1082     (modify-syntax-entry ?< ". " table)
1083     table)
1084   "Syntax table used while in Message mode.")
1085
1086 (defface message-header-to-face
1087   '((((class color)
1088       (background dark))
1089      (:foreground "green2" :bold t))
1090     (((class color)
1091       (background light))
1092      (:foreground "MidnightBlue" :bold t))
1093     (t
1094      (:bold t :italic t)))
1095   "Face used for displaying From headers."
1096   :group 'message-faces)
1097
1098 (defface message-header-cc-face
1099   '((((class color)
1100       (background dark))
1101      (:foreground "green4" :bold t))
1102     (((class color)
1103       (background light))
1104      (:foreground "MidnightBlue"))
1105     (t
1106      (:bold t)))
1107   "Face used for displaying Cc headers."
1108   :group 'message-faces)
1109
1110 (defface message-header-subject-face
1111   '((((class color)
1112       (background dark))
1113      (:foreground "green3"))
1114     (((class color)
1115       (background light))
1116      (:foreground "navy blue" :bold t))
1117     (t
1118      (:bold t)))
1119   "Face used for displaying subject headers."
1120   :group 'message-faces)
1121
1122 (defface message-header-newsgroups-face
1123   '((((class color)
1124       (background dark))
1125      (:foreground "yellow" :bold t :italic t))
1126     (((class color)
1127       (background light))
1128      (:foreground "blue4" :bold t :italic t))
1129     (t
1130      (:bold t :italic t)))
1131   "Face used for displaying newsgroups headers."
1132   :group 'message-faces)
1133
1134 (defface message-header-other-face
1135   '((((class color)
1136       (background dark))
1137      (:foreground "#b00000"))
1138     (((class color)
1139       (background light))
1140      (:foreground "steel blue"))
1141     (t
1142      (:bold t :italic t)))
1143   "Face used for displaying newsgroups headers."
1144   :group 'message-faces)
1145
1146 (defface message-header-name-face
1147   '((((class color)
1148       (background dark))
1149      (:foreground "DarkGreen"))
1150     (((class color)
1151       (background light))
1152      (:foreground "cornflower blue"))
1153     (t
1154      (:bold t)))
1155   "Face used for displaying header names."
1156   :group 'message-faces)
1157
1158 (defface message-header-xheader-face
1159   '((((class color)
1160       (background dark))
1161      (:foreground "blue"))
1162     (((class color)
1163       (background light))
1164      (:foreground "blue"))
1165     (t
1166      (:bold t)))
1167   "Face used for displaying X-Header headers."
1168   :group 'message-faces)
1169
1170 (defface message-separator-face
1171   '((((class color)
1172       (background dark))
1173      (:foreground "blue3"))
1174     (((class color)
1175       (background light))
1176      (:foreground "brown"))
1177     (t
1178      (:bold t)))
1179   "Face used for displaying the separator."
1180   :group 'message-faces)
1181
1182 (defface message-cited-text-face
1183   '((((class color)
1184       (background dark))
1185      (:foreground "red"))
1186     (((class color)
1187       (background light))
1188      (:foreground "red"))
1189     (t
1190      (:bold t)))
1191   "Face used for displaying cited text names."
1192   :group 'message-faces)
1193
1194 (defface message-mml-face
1195   '((((class color)
1196       (background dark))
1197      (:foreground "ForestGreen"))
1198     (((class color)
1199       (background light))
1200      (:foreground "ForestGreen"))
1201     (t
1202      (:bold t)))
1203   "Face used for displaying MML."
1204   :group 'message-faces)
1205
1206 (defun message-font-lock-make-header-matcher (regexp)
1207   (let ((form
1208          `(lambda (limit)
1209             (let ((start (point)))
1210               (save-restriction
1211                 (widen)
1212                 (goto-char (point-min))
1213                 (if (re-search-forward
1214                      (concat "^" (regexp-quote mail-header-separator) "$")
1215                      nil t)
1216                     (setq limit (min limit (match-beginning 0))))
1217                 (goto-char start))
1218               (and (< start limit)
1219                    (re-search-forward ,regexp limit t))))))
1220     (if (featurep 'bytecomp)
1221         (byte-compile form)
1222       form)))
1223
1224 (defvar message-font-lock-keywords
1225   (let ((content "[ \t]*\\(.+\\(\n[ \t].*\\)*\\)\n?"))
1226     `((,(message-font-lock-make-header-matcher
1227          (concat "^\\([Tt]o:\\)" content))
1228        (1 'message-header-name-face)
1229        (2 'message-header-to-face nil t))
1230       (,(message-font-lock-make-header-matcher
1231          (concat "^\\(^[GBF]?[Cc][Cc]:\\|^[Rr]eply-[Tt]o:\\)" content))
1232        (1 'message-header-name-face)
1233        (2 'message-header-cc-face nil t))
1234       (,(message-font-lock-make-header-matcher
1235          (concat "^\\([Ss]ubject:\\)" content))
1236        (1 'message-header-name-face)
1237        (2 'message-header-subject-face nil t))
1238       (,(message-font-lock-make-header-matcher
1239          (concat "^\\([Nn]ewsgroups:\\|Followup-[Tt]o:\\)" content))
1240        (1 'message-header-name-face)
1241        (2 'message-header-newsgroups-face nil t))
1242       (,(message-font-lock-make-header-matcher
1243          (concat "^\\([A-Z][^: \n\t]+:\\)" content))
1244        (1 'message-header-name-face)
1245        (2 'message-header-other-face nil t))
1246       (,(message-font-lock-make-header-matcher
1247          (concat "^\\(X-[A-Za-z0-9-]+:\\|In-Reply-To:\\)" content))
1248        (1 'message-header-name-face)
1249        (2 'message-header-name-face))
1250       ,@(if (and mail-header-separator
1251                  (not (equal mail-header-separator "")))
1252             `((,(concat "^\\(" (regexp-quote mail-header-separator) "\\)$")
1253                1 'message-separator-face))
1254           nil)
1255       ((lambda (limit)
1256          (re-search-forward (concat "^\\("
1257                                     message-cite-prefix-regexp
1258                                     "\\).*")
1259                             limit t))
1260        (0 'message-cited-text-face))
1261       ("<#/?\\(multipart\\|part\\|external\\|mml\\|secure\\)[^>]*>"
1262        (0 'message-mml-face))))
1263   "Additional expressions to highlight in Message mode.")
1264
1265
1266 ;; XEmacs does it like this.  For Emacs, we have to set the
1267 ;; `font-lock-defaults' buffer-local variable.
1268 (put 'message-mode 'font-lock-defaults '(message-font-lock-keywords t))
1269
1270 (defvar message-face-alist
1271   '((bold . bold-region)
1272     (underline . underline-region)
1273     (default . (lambda (b e)
1274                  (unbold-region b e)
1275                  (ununderline-region b e))))
1276   "Alist of mail and news faces for facemenu.
1277 The cdr of each entry is a function for applying the face to a region.")
1278
1279 (defcustom message-send-hook nil
1280   "Hook run before sending messages.
1281 This hook is run quite early when sending."
1282   :group 'message-various
1283   :options '(ispell-message)
1284   :link '(custom-manual "(message)Various Message Variables")
1285   :type 'hook)
1286
1287 (defcustom message-send-mail-hook nil
1288   "Hook run before sending mail messages.
1289 This hook is run very late -- just before the message is sent as
1290 mail."
1291   :group 'message-various
1292   :link '(custom-manual "(message)Various Message Variables")
1293   :type 'hook)
1294
1295 (defcustom message-send-news-hook nil
1296   "Hook run before sending news messages.
1297 This hook is run very late -- just before the message is sent as
1298 news."
1299   :group 'message-various
1300   :link '(custom-manual "(message)Various Message Variables")
1301   :type 'hook)
1302
1303 (defcustom message-sent-hook nil
1304   "Hook run after sending messages."
1305   :group 'message-various
1306   :type 'hook)
1307
1308 (defvar message-send-coding-system 'binary
1309   "Coding system to encode outgoing mail.")
1310
1311 (defvar message-draft-coding-system
1312   mm-auto-save-coding-system
1313   "*Coding system to compose mail.
1314 If you'd like to make it possible to share draft files between XEmacs
1315 and Emacs, you may use `iso-2022-7bit' for this value at your own risk.
1316 Note that the coding-system `iso-2022-7bit' isn't suitable to all data.")
1317
1318 (defcustom message-send-mail-partially-limit 1000000
1319   "The limitation of messages sent as message/partial.
1320 The lower bound of message size in characters, beyond which the message
1321 should be sent in several parts.  If it is nil, the size is unlimited."
1322   :version "21.1"
1323   :group 'message-buffers
1324   :link '(custom-manual "(message)Mail Variables")
1325   :type '(choice (const :tag "unlimited" nil)
1326                  (integer 1000000)))
1327
1328 (defcustom message-alternative-emails nil
1329   "A regexp to match the alternative email addresses.
1330 The first matched address (not primary one) is used in the From field."
1331   :group 'message-headers
1332   :link '(custom-manual "(message)Message Headers")
1333   :type '(choice (const :tag "Always use primary" nil)
1334                  regexp))
1335
1336 (defcustom message-hierarchical-addresses nil
1337   "A list of hierarchical mail address definitions.
1338
1339 Inside each entry, the first address is the \"top\" address, and
1340 subsequent addresses are subaddresses; this is used to indicate that
1341 mail sent to the first address will automatically be delivered to the
1342 subaddresses.  So if the first address appears in the recipient list
1343 for a message, the subaddresses will be removed (if present) before
1344 the mail is sent.  All addresses in this structure should be
1345 downcased."
1346   :group 'message-headers
1347   :type '(repeat (repeat string)))
1348
1349 (defcustom message-mail-user-agent nil
1350   "Like `mail-user-agent'.
1351 Except if it is nil, use Gnus native MUA; if it is t, use
1352 `mail-user-agent'."
1353   :type '(radio (const :tag "Gnus native"
1354                        :format "%t\n"
1355                        nil)
1356                 (const :tag "`mail-user-agent'"
1357                        :format "%t\n"
1358                        t)
1359                 (function-item :tag "Default Emacs mail"
1360                                :format "%t\n"
1361                                sendmail-user-agent)
1362                 (function-item :tag "Emacs interface to MH"
1363                                :format "%t\n"
1364                                mh-e-user-agent)
1365                 (function :tag "Other"))
1366   :version "21.1"
1367   :group 'message)
1368
1369 (defcustom message-wide-reply-confirm-recipients nil
1370   "Whether to confirm a wide reply to multiple email recipients.
1371 If this variable is nil, don't ask whether to reply to all recipients.
1372 If this variable is non-nil, pose the question \"Reply to all
1373 recipients?\" before a wide reply to multiple recipients.  If the user
1374 answers yes, reply to all recipients as usual.  If the user answers
1375 no, only reply back to the author."
1376   :version "21.3"
1377   :group 'message-headers
1378   :link '(custom-manual "(message)Wide Reply")
1379   :type 'boolean)
1380
1381 (defcustom message-user-fqdn nil
1382   "*Domain part of Messsage-Ids."
1383   :group 'message-headers
1384   :link '(custom-manual "(message)News Headers")
1385   :type '(radio (const :format "%v  " nil)
1386                 (string :format "FQDN: %v\n" :size 0)))
1387
1388 (defcustom message-use-idna (and (condition-case nil (require 'idna)
1389                                    (file-error))
1390                                  (mm-coding-system-p 'utf-8)
1391                                  (executable-find idna-program)
1392                                  'ask)
1393   "Whether to encode non-ASCII in domain names into ASCII according to IDNA."
1394   :group 'message-headers
1395   :link '(custom-manual "(message)IDNA")
1396   :type '(choice (const :tag "Ask" ask)
1397                  (const :tag "Never" nil)
1398                  (const :tag "Always" t)))
1399
1400 ;;; Internal variables.
1401
1402 (defvar message-sending-message "Sending...")
1403 (defvar message-buffer-list nil)
1404 (defvar message-this-is-news nil)
1405 (defvar message-this-is-mail nil)
1406 (defvar message-draft-article nil)
1407 (defvar message-mime-part nil)
1408 (defvar message-posting-charset nil)
1409 (defvar message-inserted-headers nil)
1410
1411 ;; Byte-compiler warning
1412 (eval-when-compile
1413   (defvar gnus-active-hashtb)
1414   (defvar gnus-read-active-file))
1415
1416 ;;; Regexp matching the delimiter of messages in UNIX mail format
1417 ;;; (UNIX From lines), minus the initial ^.  It should be a copy
1418 ;;; of rmail.el's rmail-unix-mail-delimiter.
1419 (defvar message-unix-mail-delimiter
1420   (let ((time-zone-regexp
1421          (concat "\\([A-Z]?[A-Z]?[A-Z][A-Z]\\( DST\\)?"
1422                  "\\|[-+]?[0-9][0-9][0-9][0-9]"
1423                  "\\|"
1424                  "\\) *")))
1425     (concat
1426      "From "
1427
1428      ;; Many things can happen to an RFC 822 mailbox before it is put into
1429      ;; a `From' line.  The leading phrase can be stripped, e.g.
1430      ;; `Joe <@w.x:joe@y.z>' -> `<@w.x:joe@y.z>'.  The <> can be stripped, e.g.
1431      ;; `<@x.y:joe@y.z>' -> `@x.y:joe@y.z'.  Everything starting with a CRLF
1432      ;; can be removed, e.g.
1433      ;;         From: joe@y.z (Joe      K
1434      ;;                 User)
1435      ;; can yield `From joe@y.z (Joe    K Fri Mar 22 08:11:15 1996', and
1436      ;;         From: Joe User
1437      ;;                 <joe@y.z>
1438      ;; can yield `From Joe User Fri Mar 22 08:11:15 1996'.
1439      ;; The mailbox can be removed or be replaced by white space, e.g.
1440      ;;         From: "Joe User"{space}{tab}
1441      ;;                 <joe@y.z>
1442      ;; can yield `From {space}{tab} Fri Mar 22 08:11:15 1996',
1443      ;; where {space} and {tab} represent the Ascii space and tab characters.
1444      ;; We want to match the results of any of these manglings.
1445      ;; The following regexp rejects names whose first characters are
1446      ;; obviously bogus, but after that anything goes.
1447      "\\([^\0-\b\n-\r\^?].*\\)?"
1448
1449      ;; The time the message was sent.
1450      "\\([^\0-\r \^?]+\\) +"            ; day of the week
1451      "\\([^\0-\r \^?]+\\) +"            ; month
1452      "\\([0-3]?[0-9]\\) +"              ; day of month
1453      "\\([0-2][0-9]:[0-5][0-9]\\(:[0-6][0-9]\\)?\\) *" ; time of day
1454
1455      ;; Perhaps a time zone, specified by an abbreviation, or by a
1456      ;; numeric offset.
1457      time-zone-regexp
1458
1459      ;; The year.
1460      " \\([0-9][0-9]+\\) *"
1461
1462      ;; On some systems the time zone can appear after the year, too.
1463      time-zone-regexp
1464
1465      ;; Old uucp cruft.
1466      "\\(remote from .*\\)?"
1467
1468      "\n"))
1469   "Regexp matching the delimiter of messages in UNIX mail format.")
1470
1471 (defvar message-unsent-separator
1472   (concat "^ *---+ +Unsent message follows +---+ *$\\|"
1473           "^ *---+ +Returned message +---+ *$\\|"
1474           "^Start of returned message$\\|"
1475           "^ *---+ +Original message +---+ *$\\|"
1476           "^ *--+ +begin message +--+ *$\\|"
1477           "^ *---+ +Original message follows +---+ *$\\|"
1478           "^ *---+ +Undelivered message follows +---+ *$\\|"
1479           "^|? *---+ +Message text follows: +---+ *|?$")
1480   "A regexp that matches the separator before the text of a failed message.")
1481
1482 (defvar message-header-format-alist
1483   `((Newsgroups)
1484     (To . message-fill-address)
1485     (Cc . message-fill-address)
1486     (Subject)
1487     (In-Reply-To)
1488     (Fcc)
1489     (Bcc)
1490     (Date)
1491     (Organization)
1492     (Distribution)
1493     (Lines)
1494     (Expires)
1495     (Message-ID)
1496     (References . message-shorten-references)
1497     (User-Agent))
1498   "Alist used for formatting headers.")
1499
1500 (defvar message-options nil
1501   "Some saved answers when sending message.")
1502
1503 (defvar message-send-mail-real-function nil
1504   "Internal send mail function.")
1505
1506 (defvar message-bogus-system-names "^localhost\\."
1507   "The regexp of bogus system names.")
1508
1509 (defcustom message-valid-fqdn-regexp
1510   (concat "[a-z0-9][-.a-z0-9]+\\." ;; [hostname.subdomain.]domain.
1511           ;; valid TLDs:
1512           "\\([a-z][a-z]" ;; two letter country TDLs
1513           "\\|biz\\|com\\|edu\\|gov\\|int\\|mil\\|net\\|org"
1514           "\\|aero\\|coop\\|info\\|name\\|museum"
1515           "\\|arpa\\|pro\\|uucp\\|bitnet\\|bofh" ;; old style?
1516           "\\)")
1517   "Regular expression that matches a valid FQDN."
1518   ;; see also: gnus-button-valid-fqdn-regexp
1519   :group 'message-headers
1520   :type 'regexp)
1521
1522 (eval-and-compile
1523   (autoload 'gnus-alive-p "gnus-util")
1524   (autoload 'gnus-delay-article "gnus-delay")
1525   (autoload 'gnus-extract-address-components "gnus-util")
1526   (autoload 'gnus-find-method-for-group "gnus")
1527   (autoload 'gnus-group-decoded-name "gnus-group")
1528   (autoload 'gnus-group-name-charset "gnus-group")
1529   (autoload 'gnus-group-name-decode "gnus-group")
1530   (autoload 'gnus-groups-from-server "gnus")
1531   (autoload 'gnus-make-local-hook "gnus-util")
1532   (autoload 'gnus-open-server "gnus-int")
1533   (autoload 'gnus-output-to-mail "gnus-util")
1534   (autoload 'gnus-output-to-rmail "gnus-util")
1535   (autoload 'gnus-request-post "gnus-int")
1536   (autoload 'gnus-server-string "gnus")
1537   (autoload 'idna-to-ascii "idna")
1538   (autoload 'message-setup-toolbar "messagexmas")
1539   (autoload 'mh-new-draft-name "mh-comp")
1540   (autoload 'mh-send-letter "mh-comp")
1541   (autoload 'nndraft-request-associate-buffer "nndraft")
1542   (autoload 'nndraft-request-expire-articles "nndraft")
1543   (autoload 'nnvirtual-find-group-art "nnvirtual")
1544   (autoload 'rmail-dont-reply-to "mail-utils")
1545   (autoload 'rmail-msg-is-pruned "rmail")
1546   (autoload 'rmail-msg-restore-non-pruned-header "rmail")
1547   (autoload 'rmail-output "rmailout"))
1548
1549 (eval-when-compile
1550   (autoload 'sha1 "sha1-el"))
1551
1552 \f
1553
1554 ;;;
1555 ;;; Utility functions.
1556 ;;;
1557
1558 (defmacro message-y-or-n-p (question show &rest text)
1559   "Ask QUESTION, displaying remaining args in a temporary buffer if SHOW."
1560   `(message-talkative-question 'y-or-n-p ,question ,show ,@text))
1561
1562 (defmacro message-delete-line (&optional n)
1563   "Delete the current line (and the next N lines)."
1564   `(delete-region (progn (beginning-of-line) (point))
1565                   (progn (forward-line ,(or n 1)) (point))))
1566
1567 (defun message-mark-active-p ()
1568   "Non-nil means the mark and region are currently active in this buffer."
1569   mark-active)
1570
1571 (defun message-unquote-tokens (elems)
1572   "Remove double quotes (\") from strings in list ELEMS."
1573   (mapcar (lambda (item)
1574             (while (string-match "^\\(.*\\)\"\\(.*\\)$" item)
1575               (setq item (concat (match-string 1 item)
1576                                  (match-string 2 item))))
1577             item)
1578           elems))
1579
1580 (defun message-tokenize-header (header &optional separator)
1581   "Split HEADER into a list of header elements.
1582 SEPARATOR is a string of characters to be used as separators.  \",\"
1583 is used by default."
1584   (if (not header)
1585       nil
1586     (let ((regexp (format "[%s]+" (or separator ",")))
1587           (beg 1)
1588           (first t)
1589           quoted elems paren)
1590       (with-temp-buffer
1591         (mm-enable-multibyte)
1592         (insert header)
1593         (goto-char (point-min))
1594         (while (not (eobp))
1595           (if first
1596               (setq first nil)
1597             (forward-char 1))
1598           (cond ((and (> (point) beg)
1599                       (or (eobp)
1600                           (and (looking-at regexp)
1601                                (not quoted)
1602                                (not paren))))
1603                  (push (buffer-substring beg (point)) elems)
1604                  (setq beg (match-end 0)))
1605                 ((eq (char-after) ?\")
1606                  (setq quoted (not quoted)))
1607                 ((and (eq (char-after) ?\()
1608                       (not quoted))
1609                  (setq paren t))
1610                 ((and (eq (char-after) ?\))
1611                       (not quoted))
1612                  (setq paren nil))))
1613         (nreverse elems)))))
1614
1615 (defun message-mail-file-mbox-p (file)
1616   "Say whether FILE looks like a Unix mbox file."
1617   (when (and (file-exists-p file)
1618              (file-readable-p file)
1619              (file-regular-p file))
1620     (with-temp-buffer
1621       (nnheader-insert-file-contents file)
1622       (goto-char (point-min))
1623       (looking-at message-unix-mail-delimiter))))
1624
1625 (defun message-fetch-field (header &optional not-all)
1626   "The same as `mail-fetch-field', only remove all newlines.
1627 The buffer is expected to be narrowed to just the header of the message;
1628 see `message-narrow-to-headers-or-head'."
1629   (let* ((inhibit-point-motion-hooks t)
1630          (value (mail-fetch-field header nil (not not-all))))
1631     (when value
1632       (while (string-match "\n[\t ]+" value)
1633         (setq value (replace-match " " t t value)))
1634       (set-text-properties 0 (length value) nil value)
1635       value)))
1636
1637 (defun message-field-value (header &optional not-all)
1638   "The same as `message-fetch-field', only narrow to the headers first."
1639   (save-excursion
1640     (save-restriction
1641       (message-narrow-to-headers-or-head)
1642       (message-fetch-field header not-all))))
1643
1644 (defun message-narrow-to-field ()
1645   "Narrow the buffer to the header on the current line."
1646   (beginning-of-line)
1647   (narrow-to-region
1648    (point)
1649    (progn
1650      (forward-line 1)
1651      (if (re-search-forward "^[^ \n\t]" nil t)
1652          (point-at-bol)
1653        (point-max))))
1654   (goto-char (point-min)))
1655
1656 (defun message-add-header (&rest headers)
1657   "Add the HEADERS to the message header, skipping those already present."
1658   (while headers
1659     (let (hclean)
1660       (unless (string-match "^\\([^:]+\\):[ \t]*[^ \t]" (car headers))
1661         (error "Invalid header `%s'" (car headers)))
1662       (setq hclean (match-string 1 (car headers)))
1663       (save-restriction
1664         (message-narrow-to-headers)
1665         (unless (re-search-forward (concat "^" (regexp-quote hclean) ":") nil t)
1666           (goto-char (point-max))
1667           (if (string-match "\n$" (car headers))
1668               (insert (car headers))
1669             (insert (car headers) ?\n)))))
1670     (setq headers (cdr headers))))
1671
1672 (defmacro message-with-reply-buffer (&rest forms)
1673   "Evaluate FORMS in the reply buffer, if it exists."
1674   `(when (and message-reply-buffer
1675               (buffer-name message-reply-buffer))
1676      (save-excursion
1677        (set-buffer message-reply-buffer)
1678        ,@forms)))
1679
1680 (put 'message-with-reply-buffer 'lisp-indent-function 0)
1681 (put 'message-with-reply-buffer 'edebug-form-spec '(body))
1682
1683 (defun message-fetch-reply-field (header)
1684   "Fetch field HEADER from the message we're replying to."
1685   (message-with-reply-buffer
1686     (save-restriction
1687       (mail-narrow-to-head)
1688       (message-fetch-field header))))
1689
1690 (defun message-strip-list-identifiers (subject)
1691   "Remove list identifiers in `gnus-list-identifiers' from string SUBJECT."
1692   (require 'gnus-sum)                   ; for gnus-list-identifiers
1693   (let ((regexp (if (stringp gnus-list-identifiers)
1694                     gnus-list-identifiers
1695                   (mapconcat 'identity gnus-list-identifiers " *\\|"))))
1696     (if (string-match (concat "\\(\\(\\(Re: +\\)?\\(" regexp
1697                               " *\\)\\)+\\(Re: +\\)?\\)") subject)
1698         (concat (substring subject 0 (match-beginning 1))
1699                 (or (match-string 3 subject)
1700                     (match-string 5 subject))
1701                 (substring subject
1702                            (match-end 1)))
1703       subject)))
1704
1705 (defun message-strip-subject-re (subject)
1706   "Remove \"Re:\" from subject lines in string SUBJECT."
1707   (if (string-match message-subject-re-regexp subject)
1708       (substring subject (match-end 0))
1709     subject))
1710
1711 ;;; Start of functions adopted from `message-utils.el'.
1712
1713 (defun message-strip-subject-trailing-was (subject)
1714   "Remove trailing \"(Was: <old subject>)\" from SUBJECT lines.
1715 Leading \"Re: \" is not stripped by this function.  Use the function
1716 `message-strip-subject-re' for this."
1717   (let* ((query message-subject-trailing-was-query)
1718          (new) (found))
1719     (setq found
1720           (string-match
1721            (if (eq query 'ask)
1722                message-subject-trailing-was-ask-regexp
1723              message-subject-trailing-was-regexp)
1724            subject))
1725     (if found
1726         (setq new (substring subject 0 (match-beginning 0))))
1727     (if (or (not found) (eq query nil))
1728         subject
1729       (if (eq query 'ask)
1730           (if (message-y-or-n-p
1731                "Strip `(was: <old subject>)' in subject? " t
1732                (concat
1733                 "Strip `(was: <old subject>)' in subject "
1734                 "and use the new one instead?\n\n"
1735                 "Current subject is:   \""
1736                 subject "\"\n\n"
1737                 "New subject would be: \""
1738                 new "\"\n\n"
1739                 "See the variable `message-subject-trailing-was-query' "
1740                 "to get rid of this query."
1741                 ))
1742               new subject)
1743         new))))
1744
1745 ;;; Suggested by Jonas Steverud  @  www.dtek.chalmers.se/~d4jonas/
1746
1747 ;;;###autoload
1748 (defun message-change-subject (new-subject)
1749   "Ask for NEW-SUBJECT header, append (was: <Old Subject>)."
1750   ;; <URL:http://www.landfield.com/usefor/drafts/draft-ietf-usefor-useage--1.02.unpaged>
1751   (interactive
1752    (list
1753     (read-from-minibuffer "New subject: ")))
1754   (cond ((and (not (or (null new-subject) ; new subject not empty
1755                        (zerop (string-width new-subject))
1756                        (string-match "^[ \t]*$" new-subject))))
1757          (save-excursion
1758            (let ((old-subject
1759                   (save-restriction
1760                     (message-narrow-to-headers)
1761                     (message-fetch-field "Subject"))))
1762              (cond ((not old-subject)
1763                     (error "No current subject"))
1764                    ((not (string-match
1765                           (concat "^[ \t]*"
1766                                   (regexp-quote new-subject)
1767                                   " \t]*$")
1768                           old-subject))  ; yes, it really is a new subject
1769                     ;; delete eventual Re: prefix
1770                     (setq old-subject
1771                           (message-strip-subject-re old-subject))
1772                     (message-goto-subject)
1773                     (message-delete-line)
1774                     (insert (concat "Subject: "
1775                                     new-subject
1776                                     " (was: "
1777                                     old-subject ")\n")))))))))
1778
1779 ;;;###autoload
1780 (defun message-mark-inserted-region (beg end)
1781   "Mark some region in the current article with enclosing tags.
1782 See `message-mark-insert-begin' and `message-mark-insert-end'."
1783   (interactive "r")
1784   (save-excursion
1785     ;; add to the end of the region first, otherwise end would be invalid
1786     (goto-char end)
1787     (insert message-mark-insert-end)
1788     (goto-char beg)
1789     (insert message-mark-insert-begin)))
1790
1791 ;;;###autoload
1792 (defun message-mark-insert-file (file)
1793   "Insert FILE at point, marking it with enclosing tags.
1794 See `message-mark-insert-begin' and `message-mark-insert-end'."
1795   (interactive "fFile to insert: ")
1796     ;; reverse insertion to get correct result.
1797   (let ((p (point)))
1798     (insert message-mark-insert-end)
1799     (goto-char p)
1800     (insert-file-contents file)
1801     (goto-char p)
1802     (insert message-mark-insert-begin)))
1803
1804 ;;;###autoload
1805 (defun message-add-archive-header ()
1806   "Insert \"X-No-Archive: Yes\" in the header and a note in the body.
1807 The note can be customized using `message-archive-note'.  When called with a
1808 prefix argument, ask for a text to insert.  If you don't want the note in the
1809 body, set  `message-archive-note' to nil."
1810   (interactive)
1811   (if current-prefix-arg
1812       (setq message-archive-note
1813             (read-from-minibuffer "Reason for No-Archive: "
1814                                   (cons message-archive-note 0))))
1815     (save-excursion
1816       (if (message-goto-signature)
1817           (re-search-backward message-signature-separator))
1818       (when message-archive-note
1819         (insert message-archive-note)
1820         (newline))
1821       (message-add-header message-archive-header)
1822       (message-sort-headers)))
1823
1824 ;;;###autoload
1825 (defun message-cross-post-followup-to-header (target-group)
1826   "Mangles FollowUp-To and Newsgroups header to point to TARGET-GROUP.
1827 With prefix-argument just set Follow-Up, don't cross-post."
1828   (interactive
1829    (list ; Completion based on Gnus
1830     (completing-read "Followup To: "
1831                      (if (boundp 'gnus-newsrc-alist)
1832                          gnus-newsrc-alist)
1833                      nil nil '("poster" . 0)
1834                      (if (boundp 'gnus-group-history)
1835                          'gnus-group-history))))
1836   (message-remove-header "Follow[Uu]p-[Tt]o" t)
1837   (message-goto-newsgroups)
1838   (beginning-of-line)
1839   ;; if we already did a crosspost before, kill old target
1840   (if (and message-cross-post-old-target
1841            (re-search-forward
1842             (regexp-quote (concat "," message-cross-post-old-target))
1843             nil t))
1844       (replace-match ""))
1845   ;; unless (followup is to poster or user explicitly asked not
1846   ;; to cross-post, or target-group is already in Newsgroups)
1847   ;; add target-group to Newsgroups line.
1848   (cond ((and (or
1849                ;; def: cross-post, req:no
1850                (and message-cross-post-default (not current-prefix-arg))
1851                ;; def: no-cross-post, req:yes
1852                (and (not message-cross-post-default) current-prefix-arg))
1853               (not (string-match "poster" target-group))
1854               (not (string-match (regexp-quote target-group)
1855                                  (message-fetch-field "Newsgroups"))))
1856          (end-of-line)
1857          (insert (concat "," target-group))))
1858   (end-of-line) ; ensure Followup: comes after Newsgroups:
1859   ;; unless new followup would be identical to Newsgroups line
1860   ;; make a new Followup-To line
1861   (if (not (string-match (concat "^[ \t]*"
1862                                  target-group
1863                                  "[ \t]*$")
1864                          (message-fetch-field "Newsgroups")))
1865       (insert (concat "\nFollowup-To: " target-group)))
1866   (setq message-cross-post-old-target target-group))
1867
1868 ;;;###autoload
1869 (defun message-cross-post-insert-note (target-group cross-post in-old
1870                                                     old-groups)
1871   "Insert a in message body note about a set Followup or Crosspost.
1872 If there have been previous notes, delete them.  TARGET-GROUP specifies the
1873 group to Followup-To.  When CROSS-POST is t, insert note about
1874 crossposting.  IN-OLD specifies whether TARGET-GROUP is a member of
1875 OLD-GROUPS.  OLD-GROUPS lists the old-groups the posting would have
1876 been made to before the user asked for a Crosspost."
1877   ;; start scanning body for previous uses
1878   (message-goto-signature)
1879   (let ((head (re-search-backward
1880                (concat "^" mail-header-separator)
1881                nil t))) ; just search in body
1882     (message-goto-signature)
1883     (while (re-search-backward
1884             (concat "^" (regexp-quote message-cross-post-note) ".*")
1885             head t)
1886       (message-delete-line))
1887     (message-goto-signature)
1888     (while (re-search-backward
1889             (concat "^" (regexp-quote message-followup-to-note) ".*")
1890             head t)
1891       (message-delete-line))
1892     ;; insert new note
1893     (if (message-goto-signature)
1894         (re-search-backward message-signature-separator))
1895     (if (or in-old
1896             (not cross-post)
1897             (string-match "^[ \t]*poster[ \t]*$" target-group))
1898         (insert (concat message-followup-to-note target-group "\n"))
1899       (insert (concat message-cross-post-note target-group "\n")))))
1900
1901 ;;;###autoload
1902 (defun message-cross-post-followup-to (target-group)
1903   "Crossposts message and set Followup-To to TARGET-GROUP.
1904 With prefix-argument just set Follow-Up, don't cross-post."
1905   (interactive
1906    (list ; Completion based on Gnus
1907     (completing-read "Followup To: "
1908                      (if (boundp 'gnus-newsrc-alist)
1909                          gnus-newsrc-alist)
1910                      nil nil '("poster" . 0)
1911                      (if (boundp 'gnus-group-history)
1912                          'gnus-group-history))))
1913   (cond ((not (or (null target-group) ; new subject not empty
1914                   (zerop (string-width target-group))
1915                   (string-match "^[ \t]*$" target-group)))
1916          (save-excursion
1917            (let* ((old-groups (message-fetch-field "Newsgroups"))
1918                   (in-old (string-match
1919                            (regexp-quote target-group)
1920                            (or old-groups ""))))
1921              ;; check whether target exactly matches old Newsgroups
1922              (cond ((not old-groups)
1923                     (error "No current newsgroup"))
1924                    ((or (not in-old)
1925                         (not (string-match
1926                               (concat "^[ \t]*"
1927                                       (regexp-quote target-group)
1928                                       "[ \t]*$")
1929                               old-groups)))
1930                     ;; yes, Newsgroups line must change
1931                     (message-cross-post-followup-to-header target-group)
1932                     ;; insert note whether we do cross-post or followup-to
1933                     (funcall message-cross-post-note-function
1934                              target-group
1935                              (if (or (and message-cross-post-default
1936                                           (not current-prefix-arg))
1937                                      (and (not message-cross-post-default)
1938                                           current-prefix-arg)) t)
1939                              in-old old-groups))))))))
1940
1941 ;;; Reduce To: to Cc: or Bcc: header
1942
1943 ;;;###autoload
1944 (defun message-reduce-to-to-cc ()
1945  "Replace contents of To: header with contents of Cc: or Bcc: header."
1946  (interactive)
1947  (let ((cc-content
1948         (save-restriction (message-narrow-to-headers)
1949                           (message-fetch-field "cc")))
1950        (bcc nil))
1951    (if (and (not cc-content)
1952             (setq cc-content
1953                   (save-restriction
1954                     (message-narrow-to-headers)
1955                     (message-fetch-field "bcc"))))
1956        (setq bcc t))
1957    (cond (cc-content
1958           (save-excursion
1959             (message-goto-to)
1960             (message-delete-line)
1961             (insert (concat "To: " cc-content "\n"))
1962             (save-restriction
1963               (message-narrow-to-headers)
1964               (message-remove-header (if bcc
1965                                          "bcc"
1966                                        "cc"))))))))
1967
1968 ;;; End of functions adopted from `message-utils.el'.
1969
1970 (defun message-remove-header (header &optional is-regexp first reverse)
1971   "Remove HEADER in the narrowed buffer.
1972 If IS-REGEXP, HEADER is a regular expression.
1973 If FIRST, only remove the first instance of the header.
1974 Return the number of headers removed."
1975   (goto-char (point-min))
1976   (let ((regexp (if is-regexp header (concat "^" (regexp-quote header) ":")))
1977         (number 0)
1978         (case-fold-search t)
1979         last)
1980     (while (and (not (eobp))
1981                 (not last))
1982       (if (if reverse
1983               (not (looking-at regexp))
1984             (looking-at regexp))
1985           (progn
1986             (incf number)
1987             (when first
1988               (setq last t))
1989             (delete-region
1990              (point)
1991              ;; There might be a continuation header, so we have to search
1992              ;; until we find a new non-continuation line.
1993              (progn
1994                (forward-line 1)
1995                (if (re-search-forward "^[^ \t]" nil t)
1996                    (goto-char (match-beginning 0))
1997                  (point-max)))))
1998         (forward-line 1)
1999         (if (re-search-forward "^[^ \t]" nil t)
2000             (goto-char (match-beginning 0))
2001           (goto-char (point-max)))))
2002     number))
2003
2004 (defun message-remove-first-header (header)
2005   "Remove the first instance of HEADER if there is more than one."
2006   (let ((count 0)
2007         (regexp (concat "^" (regexp-quote header) ":")))
2008     (save-excursion
2009       (goto-char (point-min))
2010       (while (re-search-forward regexp nil t)
2011         (incf count)))
2012     (while (> count 1)
2013       (message-remove-header header nil t)
2014       (decf count))))
2015
2016 (defun message-narrow-to-headers ()
2017   "Narrow the buffer to the head of the message."
2018   (widen)
2019   (narrow-to-region
2020    (goto-char (point-min))
2021    (if (re-search-forward
2022         (concat "^" (regexp-quote mail-header-separator) "\n") nil t)
2023        (match-beginning 0)
2024      (point-max)))
2025   (goto-char (point-min)))
2026
2027 (defun message-narrow-to-head-1 ()
2028   "Like `message-narrow-to-head'.  Don't widen."
2029   (narrow-to-region
2030    (goto-char (point-min))
2031    (if (search-forward "\n\n" nil 1)
2032        (1- (point))
2033      (point-max)))
2034   (goto-char (point-min)))
2035
2036 (defun message-narrow-to-head ()
2037   "Narrow the buffer to the head of the message.
2038 Point is left at the beginning of the narrowed-to region."
2039   (widen)
2040   (message-narrow-to-head-1))
2041
2042 (defun message-narrow-to-headers-or-head ()
2043   "Narrow the buffer to the head of the message."
2044   (widen)
2045   (narrow-to-region
2046    (goto-char (point-min))
2047    (cond
2048     ((re-search-forward
2049       (concat "^" (regexp-quote mail-header-separator) "\n") nil t)
2050      (match-beginning 0))
2051     ((search-forward "\n\n" nil t)
2052      (1- (point)))
2053     (t
2054      (point-max))))
2055   (goto-char (point-min)))
2056
2057 (defun message-news-p ()
2058   "Say whether the current buffer contains a news message."
2059   (and (not message-this-is-mail)
2060        (or message-this-is-news
2061            (save-excursion
2062              (save-restriction
2063                (message-narrow-to-headers)
2064                (and (message-fetch-field "newsgroups")
2065                     (not (message-fetch-field "posted-to"))))))))
2066
2067 (defun message-mail-p ()
2068   "Say whether the current buffer contains a mail message."
2069   (and (not message-this-is-news)
2070        (or message-this-is-mail
2071            (save-excursion
2072              (save-restriction
2073                (message-narrow-to-headers)
2074                (or (message-fetch-field "to")
2075                    (message-fetch-field "cc")
2076                    (message-fetch-field "bcc")))))))
2077
2078 (defun message-subscribed-p ()
2079   "Say whether we need to insert a MFT header."
2080   (or message-subscribed-regexps
2081       message-subscribed-addresses
2082       message-subscribed-address-file
2083       message-subscribed-address-functions))
2084
2085 (defun message-next-header ()
2086   "Go to the beginning of the next header."
2087   (beginning-of-line)
2088   (or (eobp) (forward-char 1))
2089   (not (if (re-search-forward "^[^ \t]" nil t)
2090            (beginning-of-line)
2091          (goto-char (point-max)))))
2092
2093 (defun message-sort-headers-1 ()
2094   "Sort the buffer as headers using `message-rank' text props."
2095   (goto-char (point-min))
2096   (require 'sort)
2097   (sort-subr
2098    nil 'message-next-header
2099    (lambda ()
2100      (message-next-header)
2101      (unless (bobp)
2102        (forward-char -1)))
2103    (lambda ()
2104      (or (get-text-property (point) 'message-rank)
2105          10000))))
2106
2107 (defun message-sort-headers ()
2108   "Sort the headers of the current message according to `message-header-format-alist'."
2109   (interactive)
2110   (save-excursion
2111     (save-restriction
2112       (let ((max (1+ (length message-header-format-alist)))
2113             rank)
2114         (message-narrow-to-headers)
2115         (while (re-search-forward "^[^ \n]+:" nil t)
2116           (put-text-property
2117            (match-beginning 0) (1+ (match-beginning 0))
2118            'message-rank
2119            (if (setq rank (length (memq (assq (intern (buffer-substring
2120                                                        (match-beginning 0)
2121                                                        (1- (match-end 0))))
2122                                               message-header-format-alist)
2123                                         message-header-format-alist)))
2124                (- max rank)
2125              (1+ max)))))
2126       (message-sort-headers-1))))
2127
2128
2129 \f
2130
2131 ;;;
2132 ;;; Message mode
2133 ;;;
2134
2135 ;;; Set up keymap.
2136
2137 (defvar message-mode-map nil)
2138
2139 (unless message-mode-map
2140   (setq message-mode-map (make-keymap))
2141   (set-keymap-parent message-mode-map text-mode-map)
2142   (define-key message-mode-map "\C-c?" 'describe-mode)
2143
2144   (define-key message-mode-map "\C-c\C-f\C-t" 'message-goto-to)
2145   (define-key message-mode-map "\C-c\C-f\C-o" 'message-goto-from)
2146   (define-key message-mode-map "\C-c\C-f\C-b" 'message-goto-bcc)
2147   (define-key message-mode-map "\C-c\C-f\C-w" 'message-goto-fcc)
2148   (define-key message-mode-map "\C-c\C-f\C-c" 'message-goto-cc)
2149   (define-key message-mode-map "\C-c\C-f\C-s" 'message-goto-subject)
2150   (define-key message-mode-map "\C-c\C-f\C-r" 'message-goto-reply-to)
2151   (define-key message-mode-map "\C-c\C-f\C-n" 'message-goto-newsgroups)
2152   (define-key message-mode-map "\C-c\C-f\C-d" 'message-goto-distribution)
2153   (define-key message-mode-map "\C-c\C-f\C-f" 'message-goto-followup-to)
2154   (define-key message-mode-map "\C-c\C-f\C-m" 'message-goto-mail-followup-to)
2155   (define-key message-mode-map "\C-c\C-f\C-k" 'message-goto-keywords)
2156   (define-key message-mode-map "\C-c\C-f\C-u" 'message-goto-summary)
2157   (define-key message-mode-map "\C-c\C-f\C-i"
2158     'message-insert-or-toggle-importance)
2159   (define-key message-mode-map "\C-c\C-f\C-a"
2160     'message-generate-unsubscribed-mail-followup-to)
2161
2162   ;; modify headers (and insert notes in body)
2163   (define-key message-mode-map "\C-c\C-fs"    'message-change-subject)
2164   ;;
2165   (define-key message-mode-map "\C-c\C-fx"    'message-cross-post-followup-to)
2166   ;; prefix+message-cross-post-followup-to = same w/o cross-post
2167   (define-key message-mode-map "\C-c\C-ft"    'message-reduce-to-to-cc)
2168   (define-key message-mode-map "\C-c\C-fa"    'message-add-archive-header)
2169   ;; mark inserted text
2170   (define-key message-mode-map "\C-c\M-m" 'message-mark-inserted-region)
2171   (define-key message-mode-map "\C-c\M-f" 'message-mark-insert-file)
2172
2173   (define-key message-mode-map "\C-c\C-b" 'message-goto-body)
2174   (define-key message-mode-map "\C-c\C-i" 'message-goto-signature)
2175
2176   (define-key message-mode-map "\C-c\C-t" 'message-insert-to)
2177   (define-key message-mode-map "\C-c\C-fw" 'message-insert-wide-reply)
2178   (define-key message-mode-map "\C-c\C-n" 'message-insert-newsgroups)
2179   (define-key message-mode-map "\C-c\C-l" 'message-to-list-only)
2180
2181   (define-key message-mode-map "\C-c\C-u" 'message-insert-or-toggle-importance)
2182   (define-key message-mode-map "\C-c\M-n"
2183     'message-insert-disposition-notification-to)
2184
2185   (define-key message-mode-map "\C-c\C-y" 'message-yank-original)
2186   (define-key message-mode-map "\C-c\M-\C-y" 'message-yank-buffer)
2187   (define-key message-mode-map "\C-c\C-q" 'message-fill-yanked-message)
2188   (define-key message-mode-map "\C-c\C-w" 'message-insert-signature)
2189   (define-key message-mode-map "\C-c\M-h" 'message-insert-headers)
2190   (define-key message-mode-map "\C-c\C-r" 'message-caesar-buffer-body)
2191   (define-key message-mode-map "\C-c\C-o" 'message-sort-headers)
2192   (define-key message-mode-map "\C-c\M-r" 'message-rename-buffer)
2193
2194   (define-key message-mode-map "\C-c\C-c" 'message-send-and-exit)
2195   (define-key message-mode-map "\C-c\C-s" 'message-send)
2196   (define-key message-mode-map "\C-c\C-k" 'message-kill-buffer)
2197   (define-key message-mode-map "\C-c\C-d" 'message-dont-send)
2198   (define-key message-mode-map "\C-c\n" 'gnus-delay-article)
2199
2200   (define-key message-mode-map "\C-c\C-e" 'message-elide-region)
2201   (define-key message-mode-map "\C-c\C-v" 'message-delete-not-region)
2202   (define-key message-mode-map "\C-c\C-z" 'message-kill-to-signature)
2203   (define-key message-mode-map "\M-\r" 'message-newline-and-reformat)
2204   ;;(define-key message-mode-map "\M-q" 'message-fill-paragraph)
2205   (define-key message-mode-map [remap split-line]  'message-split-line)
2206
2207   (define-key message-mode-map "\C-c\C-a" 'mml-attach-file)
2208
2209   (define-key message-mode-map "\C-a" 'message-beginning-of-line)
2210   (define-key message-mode-map "\t" 'message-tab)
2211   (define-key message-mode-map "\M-;" 'comment-region))
2212
2213 (easy-menu-define
2214   message-mode-menu message-mode-map "Message Menu."
2215   `("Message"
2216     ["Yank Original" message-yank-original message-reply-buffer]
2217     ["Fill Yanked Message" message-fill-yanked-message t]
2218     ["Insert Signature" message-insert-signature t]
2219     ["Caesar (rot13) Message" message-caesar-buffer-body t]
2220     ["Caesar (rot13) Region" message-caesar-region (message-mark-active-p)]
2221     ["Elide Region" message-elide-region
2222      :active (message-mark-active-p)
2223      ,@(if (featurep 'xemacs) nil
2224          '(:help "Replace text in region with an ellipsis"))]
2225     ["Delete Outside Region" message-delete-not-region
2226      :active (message-mark-active-p)
2227      ,@(if (featurep 'xemacs) nil
2228          '(:help "Delete all quoted text outside region"))]
2229     ["Kill To Signature" message-kill-to-signature t]
2230     ["Newline and Reformat" message-newline-and-reformat t]
2231     ["Rename buffer" message-rename-buffer t]
2232     ["Spellcheck" ispell-message
2233      ,@(if (featurep 'xemacs) '(t)
2234          '(:help "Spellcheck this message"))]
2235     "----"
2236     ["Insert Region Marked" message-mark-inserted-region
2237      :active (message-mark-active-p)
2238      ,@(if (featurep 'xemacs) nil
2239          '(:help "Mark region with enclosing tags"))]
2240     ["Insert File Marked..." message-mark-insert-file
2241      ,@(if (featurep 'xemacs) '(t)
2242          '(:help "Insert file at point marked with enclosing tags"))]
2243     "----"
2244     ["Send Message" message-send-and-exit
2245      ,@(if (featurep 'xemacs) '(t)
2246          '(:help "Send this message"))]
2247     ["Postpone Message" message-dont-send
2248      ,@(if (featurep 'xemacs) '(t)
2249          '(:help "File this draft message and exit"))]
2250     ["Send at Specific Time..." gnus-delay-article
2251      ,@(if (featurep 'xemacs) '(t)
2252          '(:help "Ask, then arrange to send message at that time"))]
2253     ["Kill Message" message-kill-buffer
2254      ,@(if (featurep 'xemacs) '(t)
2255          '(:help "Delete this message without sending"))]))
2256
2257 (easy-menu-define
2258   message-mode-field-menu message-mode-map ""
2259   `("Field"
2260     ["To" message-goto-to t]
2261     ["From" message-goto-from t]
2262     ["Subject" message-goto-subject t]
2263     ["Change subject..." message-change-subject t]
2264     ["Cc" message-goto-cc t]
2265     ["Bcc" message-goto-bcc t]
2266     ["Fcc" message-goto-fcc t]
2267     ["Reply-To" message-goto-reply-to t]
2268     ["Flag As Important" message-insert-importance-high
2269      ,@(if (featurep 'xemacs) '(t)
2270          '(:help "Mark this message as important"))]
2271     ["Flag As Unimportant" message-insert-importance-low
2272      ,@(if (featurep 'xemacs) '(t)
2273          '(:help "Mark this message as unimportant"))]
2274     ["Request Receipt"
2275      message-insert-disposition-notification-to
2276      ,@(if (featurep 'xemacs) '(t)
2277          '(:help "Request a receipt notification"))]
2278     "----"
2279     ;; (typical) news stuff
2280     ["Summary" message-goto-summary t]
2281     ["Keywords" message-goto-keywords t]
2282     ["Newsgroups" message-goto-newsgroups t]
2283     ["Fetch Newsgroups" message-insert-newsgroups t]
2284     ["Followup-To" message-goto-followup-to t]
2285     ;; ["Followup-To (with note in body)" message-cross-post-followup-to t]
2286     ["Crosspost / Followup-To..." message-cross-post-followup-to t]
2287     ["Distribution" message-goto-distribution t]
2288     ["X-No-Archive:" message-add-archive-header t ]
2289     "----"
2290     ;; (typical) mailing-lists stuff
2291     ["Fetch To" message-insert-to
2292      ,@(if (featurep 'xemacs) '(t)
2293          '(:help "Insert a To header that points to the author."))]
2294     ["Fetch To and Cc" message-insert-wide-reply
2295      ,@(if (featurep 'xemacs) '(t)
2296          '(:help
2297            "Insert To and Cc headers as if you were doing a wide reply."))]
2298     "----"
2299     ["Send to list only" message-to-list-only t]
2300     ["Mail-Followup-To" message-goto-mail-followup-to t]
2301     ["Unsubscribed list post" message-generate-unsubscribed-mail-followup-to
2302      ,@(if (featurep 'xemacs) '(t)
2303          '(:help "Insert a reasonable `Mail-Followup-To:' header."))]
2304     ["Reduce To: to Cc:" message-reduce-to-to-cc t]
2305     "----"
2306     ["Sort Headers" message-sort-headers t]
2307     ["Encode non-ASCII domain names" message-idna-to-ascii-rhs t]
2308     ["Goto Body" message-goto-body t]
2309     ["Goto Signature" message-goto-signature t]))
2310
2311 (defvar message-tool-bar-map nil)
2312
2313 (eval-when-compile
2314   (defvar facemenu-add-face-function)
2315   (defvar facemenu-remove-face-function))
2316
2317 ;;; Forbidden properties
2318 ;;
2319 ;; We use `after-change-functions' to keep special text properties
2320 ;; that interfer with the normal function of message mode out of the
2321 ;; buffer.
2322
2323 (defcustom message-strip-special-text-properties t
2324   "Strip special properties from the message buffer.
2325
2326 Emacs has a number of special text properties which can break message
2327 composing in various ways.  If this option is set, message will strip
2328 these properties from the message composition buffer.  However, some
2329 packages requires these properties to be present in order to work.
2330 If you use one of these packages, turn this option off, and hope the
2331 message composition doesn't break too bad."
2332   :group 'message-various
2333   :link '(custom-manual "(message)Various Message Variables")
2334   :type 'boolean)
2335
2336 (defconst message-forbidden-properties
2337   ;; No reason this should be clutter up customize.  We make it a
2338   ;; property list (rather than a list of property symbols), to be
2339   ;; directly useful for `remove-text-properties'.
2340   '(field nil read-only nil invisible nil intangible nil
2341           mouse-face nil modification-hooks nil insert-in-front-hooks nil
2342           insert-behind-hooks nil point-entered nil point-left nil)
2343   ;; Other special properties:
2344   ;; category, face, display: probably doesn't do any harm.
2345   ;; fontified: is used by font-lock.
2346   ;; syntax-table, local-map: I dunno.
2347   ;; We need to add XEmacs names to the list.
2348   "Property list of with properties.forbidden in message buffers.
2349 The values of the properties are ignored, only the property names are used.")
2350
2351 (defun message-tamago-not-in-use-p (pos)
2352   "Return t when tamago version 4 is not in use at the cursor position.
2353 Tamago version 4 is a popular input method for writing Japanese text.
2354 It uses the properties `intangible', `invisible', `modification-hooks'
2355 and `read-only' when translating ascii or kana text to kanji text.
2356 These properties are essential to work, so we should never strip them."
2357   (not (and (boundp 'egg-modefull-mode)
2358             (symbol-value 'egg-modefull-mode)
2359             (or (memq (get-text-property pos 'intangible)
2360                       '(its-part-1 its-part-2))
2361                 (get-text-property pos 'egg-end)
2362                 (get-text-property pos 'egg-lang)
2363                 (get-text-property pos 'egg-start)))))
2364
2365 (defun message-strip-forbidden-properties (begin end &optional old-length)
2366   "Strip forbidden properties between BEGIN and END, ignoring the third arg.
2367 This function is intended to be called from `after-change-functions'.
2368 See also `message-forbidden-properties'."
2369   (when (and message-strip-special-text-properties
2370              (message-tamago-not-in-use-p begin))
2371     (while (not (= begin end))
2372       (when (not (get-text-property begin 'message-hidden))
2373         (remove-text-properties begin (1+ begin)
2374                                 message-forbidden-properties))
2375       (incf begin))))
2376
2377 ;;;###autoload
2378 (define-derived-mode message-mode text-mode "Message"
2379   "Major mode for editing mail and news to be sent.
2380 Like Text Mode but with these additional commands:\\<message-mode-map>
2381 C-c C-s  `message-send' (send the message)  C-c C-c  `message-send-and-exit'
2382 C-c C-d  Postpone sending the message       C-c C-k  Kill the message
2383 C-c C-f  move to a header field (and create it if there isn't):
2384          C-c C-f C-t  move to To        C-c C-f C-s  move to Subject
2385          C-c C-f C-c  move to Cc        C-c C-f C-b  move to Bcc
2386          C-c C-f C-w  move to Fcc       C-c C-f C-r  move to Reply-To
2387          C-c C-f C-u  move to Summary   C-c C-f C-n  move to Newsgroups
2388          C-c C-f C-k  move to Keywords  C-c C-f C-d  move to Distribution
2389          C-c C-f C-o  move to From (\"Originator\")
2390          C-c C-f C-f  move to Followup-To
2391          C-c C-f C-m  move to Mail-Followup-To
2392          C-c C-f C-i  cycle through Importance values
2393          C-c C-f s    change subject and append \"(was: <Old Subject>)\"
2394          C-c C-f x    crossposting with FollowUp-To header and note in body
2395          C-c C-f t    replace To: header with contents of Cc: or Bcc:
2396          C-c C-f a    Insert X-No-Archive: header and a note in the body
2397 C-c C-t  `message-insert-to' (add a To header to a news followup)
2398 C-c C-l  `message-to-list-only' (removes all but list address in to/cc)
2399 C-c C-n  `message-insert-newsgroups' (add a Newsgroup header to a news reply)
2400 C-c C-b  `message-goto-body' (move to beginning of message text).
2401 C-c C-i  `message-goto-signature' (move to the beginning of the signature).
2402 C-c C-w  `message-insert-signature' (insert `message-signature-file' file).
2403 C-c C-y  `message-yank-original' (insert current message, if any).
2404 C-c C-q  `message-fill-yanked-message' (fill what was yanked).
2405 C-c C-e  `message-elide-region' (elide the text between point and mark).
2406 C-c C-v  `message-delete-not-region' (remove the text outside the region).
2407 C-c C-z  `message-kill-to-signature' (kill the text up to the signature).
2408 C-c C-r  `message-caesar-buffer-body' (rot13 the message body).
2409 C-c C-a  `mml-attach-file' (attach a file as MIME).
2410 C-c C-u  `message-insert-or-toggle-importance'  (insert or cycle importance).
2411 C-c M-n  `message-insert-disposition-notification-to'  (request receipt).
2412 C-c M-m  `message-mark-inserted-region' (mark region with enclosing tags).
2413 C-c M-f  `message-mark-insert-file' (insert file marked with enclosing tags).
2414 M-RET    `message-newline-and-reformat' (break the line and reformat)."
2415   (setq local-abbrev-table text-mode-abbrev-table)
2416   (set (make-local-variable 'message-reply-buffer) nil)
2417   (set (make-local-variable 'message-inserted-headers) nil)
2418   (set (make-local-variable 'message-send-actions) nil)
2419   (set (make-local-variable 'message-exit-actions) nil)
2420   (set (make-local-variable 'message-kill-actions) nil)
2421   (set (make-local-variable 'message-postpone-actions) nil)
2422   (set (make-local-variable 'message-draft-article) nil)
2423   (setq buffer-offer-save t)
2424   (set (make-local-variable 'facemenu-add-face-function)
2425        (lambda (face end)
2426          (let ((face-fun (cdr (assq face message-face-alist))))
2427            (if face-fun
2428                (funcall face-fun (point) end)
2429              (error "Face %s not configured for %s mode" face mode-name)))
2430          ""))
2431   (set (make-local-variable 'facemenu-remove-face-function) t)
2432   (set (make-local-variable 'message-reply-headers) nil)
2433   (make-local-variable 'message-newsreader)
2434   (make-local-variable 'message-mailer)
2435   (make-local-variable 'message-post-method)
2436   (set (make-local-variable 'message-sent-message-via) nil)
2437   (set (make-local-variable 'message-checksum) nil)
2438   (set (make-local-variable 'message-mime-part) 0)
2439   (message-setup-fill-variables)
2440   ;; Allow using comment commands to add/remove quoting.
2441   (set (make-local-variable 'comment-start) message-yank-prefix)
2442   (if (featurep 'xemacs)
2443       (message-setup-toolbar)
2444     (set (make-local-variable 'font-lock-defaults)
2445          '(message-font-lock-keywords t))
2446     (if (boundp 'tool-bar-map)
2447         (set (make-local-variable 'tool-bar-map) (message-tool-bar-map))))
2448   (easy-menu-add message-mode-menu message-mode-map)
2449   (easy-menu-add message-mode-field-menu message-mode-map)
2450   (gnus-make-local-hook 'after-change-functions)
2451   ;; Mmmm... Forbidden properties...
2452   (add-hook 'after-change-functions 'message-strip-forbidden-properties
2453             nil 'local)
2454   ;; Allow mail alias things.
2455   (when (eq message-mail-alias-type 'abbrev)
2456     (if (fboundp 'mail-abbrevs-setup)
2457         (mail-abbrevs-setup)
2458       (if (fboundp 'mail-aliases-setup) ; warning avoidance
2459           (mail-aliases-setup))))
2460   (unless buffer-file-name
2461     (message-set-auto-save-file-name))
2462   (unless (buffer-base-buffer)
2463     ;; Don't enable multibyte on an indirect buffer.  Maybe enabling
2464     ;; multibyte is not necessary at all. -- zsh
2465     (mm-enable-multibyte))
2466   (set (make-local-variable 'indent-tabs-mode) nil) ;No tabs for indentation.
2467   (mml-mode))
2468
2469 (defun message-setup-fill-variables ()
2470   "Setup message fill variables."
2471   (set (make-local-variable 'fill-paragraph-function)
2472        'message-fill-paragraph)
2473   (make-local-variable 'paragraph-separate)
2474   (make-local-variable 'paragraph-start)
2475   (make-local-variable 'adaptive-fill-regexp)
2476   (unless (boundp 'adaptive-fill-first-line-regexp)
2477     (setq adaptive-fill-first-line-regexp nil))
2478   (make-local-variable 'adaptive-fill-first-line-regexp)
2479   (let ((quote-prefix-regexp
2480          ;; User should change message-cite-prefix-regexp if
2481          ;; message-yank-prefix is set to an abnormal value.
2482          (concat "\\(" message-cite-prefix-regexp "\\)[ \t]*")))
2483     (setq paragraph-start
2484           (concat
2485            (regexp-quote mail-header-separator) "$\\|"
2486            "[ \t]*$\\|"                 ; blank lines
2487            "-- $\\|"                    ; signature delimiter
2488            "---+$\\|"              ; delimiters for forwarded messages
2489            page-delimiter "$\\|"        ; spoiler warnings
2490            ".*wrote:$\\|"               ; attribution lines
2491            quote-prefix-regexp "$\\|"   ; empty lines in quoted text
2492                                         ; mml tags
2493            "<#!*/?\\(multipart\\|part\\|external\\|mml\\|secure\\)"))
2494     (setq paragraph-separate paragraph-start)
2495     (setq adaptive-fill-regexp
2496           (concat quote-prefix-regexp "\\|" adaptive-fill-regexp))
2497     (setq adaptive-fill-first-line-regexp
2498           (concat quote-prefix-regexp "\\|"
2499                   adaptive-fill-first-line-regexp)))
2500   (make-local-variable 'auto-fill-inhibit-regexp)
2501   ;;(setq auto-fill-inhibit-regexp "^[A-Z][^: \n\t]+:")
2502   (setq auto-fill-inhibit-regexp nil)
2503   (make-local-variable 'normal-auto-fill-function)
2504   (setq normal-auto-fill-function 'message-do-auto-fill)
2505   ;; KLUDGE: auto fill might already be turned on in `text-mode-hook'.
2506   ;; In that case, ensure that it uses the right function.  The real
2507   ;; solution would be not to use `define-derived-mode', and run
2508   ;; `text-mode-hook' ourself at the end of the mode.
2509   ;; -- Per Abrahamsen <abraham@dina.kvl.dk> Date: 2001-10-19.
2510   (when auto-fill-function
2511     (setq auto-fill-function normal-auto-fill-function)))
2512
2513 \f
2514
2515 ;;;
2516 ;;; Message mode commands
2517 ;;;
2518
2519 ;;; Movement commands
2520
2521 (defun message-goto-to ()
2522   "Move point to the To header."
2523   (interactive)
2524   (message-position-on-field "To"))
2525
2526 (defun message-goto-from ()
2527   "Move point to the From header."
2528   (interactive)
2529   (message-position-on-field "From"))
2530
2531 (defun message-goto-subject ()
2532   "Move point to the Subject header."
2533   (interactive)
2534   (message-position-on-field "Subject"))
2535
2536 (defun message-goto-cc ()
2537   "Move point to the Cc header."
2538   (interactive)
2539   (message-position-on-field "Cc" "To"))
2540
2541 (defun message-goto-bcc ()
2542   "Move point to the Bcc  header."
2543   (interactive)
2544   (message-position-on-field "Bcc" "Cc" "To"))
2545
2546 (defun message-goto-fcc ()
2547   "Move point to the Fcc header."
2548   (interactive)
2549   (message-position-on-field "Fcc" "To" "Newsgroups"))
2550
2551 (defun message-goto-reply-to ()
2552   "Move point to the Reply-To header."
2553   (interactive)
2554   (message-position-on-field "Reply-To" "Subject"))
2555
2556 (defun message-goto-newsgroups ()
2557   "Move point to the Newsgroups header."
2558   (interactive)
2559   (message-position-on-field "Newsgroups"))
2560
2561 (defun message-goto-distribution ()
2562   "Move point to the Distribution header."
2563   (interactive)
2564   (message-position-on-field "Distribution"))
2565
2566 (defun message-goto-followup-to ()
2567   "Move point to the Followup-To header."
2568   (interactive)
2569   (message-position-on-field "Followup-To" "Newsgroups"))
2570
2571 (defun message-goto-mail-followup-to ()
2572   "Move point to the Mail-Followup-To header."
2573   (interactive)
2574   (message-position-on-field "Mail-Followup-To" "From"))
2575
2576 (defun message-goto-keywords ()
2577   "Move point to the Keywords header."
2578   (interactive)
2579   (message-position-on-field "Keywords" "Subject"))
2580
2581 (defun message-goto-summary ()
2582   "Move point to the Summary header."
2583   (interactive)
2584   (message-position-on-field "Summary" "Subject"))
2585
2586 (defun message-goto-body (&optional interactivep)
2587   "Move point to the beginning of the message body."
2588   (interactive (list t))
2589   (when (and interactivep
2590              (looking-at "[ \t]*\n"))
2591     (expand-abbrev))
2592   (goto-char (point-min))
2593   (or (search-forward (concat "\n" mail-header-separator "\n") nil t)
2594       (search-forward-regexp "[^:]+:\\([^\n]\\|\n[ \t]\\)+\n\n" nil t)))
2595
2596 (defun message-goto-eoh ()
2597   "Move point to the end of the headers."
2598   (interactive)
2599   (message-goto-body)
2600   (forward-line -1))
2601
2602 (defun message-goto-signature ()
2603   "Move point to the beginning of the message signature.
2604 If there is no signature in the article, go to the end and
2605 return nil."
2606   (interactive)
2607   (goto-char (point-min))
2608   (if (re-search-forward message-signature-separator nil t)
2609       (forward-line 1)
2610     (goto-char (point-max))
2611     nil))
2612
2613 (defun message-generate-unsubscribed-mail-followup-to (&optional include-cc)
2614   "Insert a reasonable MFT header in a post to an unsubscribed list.
2615 When making original posts to a mailing list you are not subscribed to,
2616 you have to type in a MFT header by hand.  The contents, usually, are
2617 the addresses of the list and your own address.  This function inserts
2618 such a header automatically.  It fetches the contents of the To: header
2619 in the current mail buffer, and appends the current `user-mail-address'.
2620
2621 If the optional argument INCLUDE-CC is non-nil, the addresses in the
2622 Cc: header are also put into the MFT."
2623
2624   (interactive "P")
2625   (let* (cc tos)
2626     (save-restriction
2627       (message-narrow-to-headers)
2628       (message-remove-header "Mail-Followup-To")
2629       (setq cc (and include-cc (message-fetch-field "Cc")))
2630       (setq tos (if cc
2631                     (concat (message-fetch-field "To") "," cc)
2632                   (message-fetch-field "To"))))
2633     (message-goto-mail-followup-to)
2634     (insert (concat tos ", " user-mail-address))))
2635
2636 \f
2637
2638 (defun message-insert-to (&optional force)
2639   "Insert a To header that points to the author of the article being replied to.
2640 If the original author requested not to be sent mail, don't insert unless the
2641 prefix FORCE is given."
2642   (interactive "P")
2643   (let* ((mct (message-fetch-reply-field "mail-copies-to"))
2644          (dont (and mct (or (equal (downcase mct) "never")
2645                             (equal (downcase mct) "nobody"))))
2646          (to (or (message-fetch-reply-field "mail-reply-to")
2647                  (message-fetch-reply-field "reply-to")
2648                  (message-fetch-reply-field "from"))))
2649     (when (and dont to)
2650       (message
2651        (if force
2652            "Ignoring the user request not to have copies sent via mail"
2653          "Complying with the user request not to have copies sent via mail")))
2654     (when (and force (not to))
2655       (error "No mail address in the article"))
2656     (when (and to (or force (not dont)))
2657       (message-carefully-insert-headers (list (cons 'To to))))))
2658
2659 (defun message-insert-wide-reply ()
2660   "Insert To and Cc headers as if you were doing a wide reply."
2661   (interactive)
2662   (let ((headers (message-with-reply-buffer
2663                    (message-get-reply-headers t))))
2664     (message-carefully-insert-headers headers)))
2665
2666 (defcustom message-header-synonyms
2667   '((To Cc Bcc))
2668   "List of lists of header synonyms.
2669 E.g., if this list contains a member list with elements `Cc' and `To',
2670 then `message-carefully-insert-headers' will not insert a `To' header
2671 when the message is already `Cc'ed to the recipient."
2672   :group 'message-headers
2673   :link '(custom-manual "(message)Message Headers")
2674   :type '(repeat sexp))
2675
2676 (defun message-carefully-insert-headers (headers)
2677   "Insert the HEADERS, an alist, into the message buffer.
2678 Does not insert the headers when they are already present there
2679 or in the synonym headers, defined by `message-header-synonyms'."
2680   ;; FIXME: Should compare only the address and not the full name.  Comparison
2681   ;; should be done case-folded (and with `string=' rather than
2682   ;; `string-match').
2683   (dolist (header headers)
2684     (let* ((header-name (symbol-name (car header)))
2685            (new-header (cdr header))
2686            (synonyms (loop for synonym in message-header-synonyms
2687                            when (memq (car header) synonym) return synonym))
2688            (old-header
2689             (loop for synonym in synonyms
2690                   for old-header = (mail-fetch-field (symbol-name synonym))
2691                   when (and old-header (string-match new-header old-header))
2692                   return synonym)))
2693       (if old-header
2694           (message "already have `%s' in `%s'" new-header old-header)
2695         (when (and (message-position-on-field header-name)
2696                    (setq old-header (mail-fetch-field header-name))
2697                    (not (string-match "\\` *\\'" old-header)))
2698           (insert ", "))
2699         (insert new-header)))))
2700
2701 (defun message-widen-reply ()
2702   "Widen the reply to include maximum recipients."
2703   (interactive)
2704   (let ((follow-to
2705          (and message-reply-buffer
2706               (buffer-name message-reply-buffer)
2707               (save-excursion
2708                 (set-buffer message-reply-buffer)
2709                 (message-get-reply-headers t)))))
2710     (save-excursion
2711       (save-restriction
2712         (message-narrow-to-headers)
2713         (dolist (elem follow-to)
2714           (message-remove-header (symbol-name (car elem)))
2715           (goto-char (point-min))
2716           (insert (symbol-name (car elem)) ": "
2717                   (cdr elem) "\n"))))))
2718
2719 (defun message-insert-newsgroups ()
2720   "Insert the Newsgroups header from the article being replied to."
2721   (interactive)
2722   (when (and (message-position-on-field "Newsgroups")
2723              (mail-fetch-field "newsgroups")
2724              (not (string-match "\\` *\\'" (mail-fetch-field "newsgroups"))))
2725     (insert ","))
2726   (insert (or (message-fetch-reply-field "newsgroups") "")))
2727
2728 \f
2729
2730 ;;; Various commands
2731
2732 (defun message-delete-not-region (beg end)
2733   "Delete everything in the body of the current message outside of the region."
2734   (interactive "r")
2735   (let (citeprefix)
2736     (save-excursion
2737       (goto-char beg)
2738       ;; snarf citation prefix, if appropriate
2739       (unless (eq (point) (progn (beginning-of-line) (point)))
2740         (when (looking-at message-cite-prefix-regexp)
2741           (setq citeprefix (match-string 0))))
2742       (goto-char end)
2743       (delete-region (point) (if (not (message-goto-signature))
2744                                  (point)
2745                                (forward-line -2)
2746                                (point)))
2747       (insert "\n")
2748       (goto-char beg)
2749       (delete-region beg (progn (message-goto-body)
2750                                 (forward-line 2)
2751                                 (point)))
2752       (when citeprefix
2753         (insert citeprefix))))
2754   (when (message-goto-signature)
2755     (forward-line -2)))
2756
2757 (defun message-kill-to-signature (&optional arg)
2758   "Kill all text up to the signature.
2759 If a numberic argument or prefix arg is given, leave that number
2760 of lines before the signature intact."
2761   (interactive "p")
2762   (save-excursion
2763     (save-restriction
2764       (let ((point (point)))
2765         (narrow-to-region point (point-max))
2766         (message-goto-signature)
2767         (unless (eobp)
2768           (if (and arg (numberp arg))
2769               (forward-line (- -1 arg))
2770             (end-of-line -1)))
2771         (unless (= point (point))
2772           (kill-region point (point))
2773           (insert "\n"))))))
2774
2775 (defun message-newline-and-reformat (&optional arg not-break)
2776   "Insert four newlines, and then reformat if inside quoted text.
2777 Prefix arg means justify as well."
2778   (interactive (list (if current-prefix-arg 'full)))
2779   (let (quoted point beg end leading-space bolp)
2780     (setq point (point))
2781     (beginning-of-line)
2782     (setq beg (point))
2783     (setq bolp (= beg point))
2784     ;; Find first line of the paragraph.
2785     (if not-break
2786         (while (and (not (eobp))
2787                     (not (looking-at message-cite-prefix-regexp))
2788                     (looking-at paragraph-start))
2789           (forward-line 1)))
2790     ;; Find the prefix
2791     (when (looking-at message-cite-prefix-regexp)
2792       (setq quoted (match-string 0))
2793       (goto-char (match-end 0))
2794       (looking-at "[ \t]*")
2795       (setq leading-space (match-string 0)))
2796     (if (and quoted
2797              (not not-break)
2798              (not bolp)
2799              (< (- point beg) (length quoted)))
2800         ;; break inside the cite prefix.
2801         (setq quoted nil
2802               end nil))
2803     (if quoted
2804         (progn
2805           (forward-line 1)
2806           (while (and (not (eobp))
2807                       (not (looking-at paragraph-separate))
2808                       (looking-at message-cite-prefix-regexp)
2809                       (equal quoted (match-string 0)))
2810             (goto-char (match-end 0))
2811             (looking-at "[ \t]*")
2812             (if (> (length leading-space) (length (match-string 0)))
2813                 (setq leading-space (match-string 0)))
2814             (forward-line 1))
2815           (setq end (point))
2816           (goto-char beg)
2817           (while (and (if (bobp) nil (forward-line -1) t)
2818                       (not (looking-at paragraph-start))
2819                       (looking-at message-cite-prefix-regexp)
2820                       (equal quoted (match-string 0)))
2821             (setq beg (point))
2822             (goto-char (match-end 0))
2823             (looking-at "[ \t]*")
2824             (if (> (length leading-space) (length (match-string 0)))
2825                 (setq leading-space (match-string 0)))))
2826       (while (and (not (eobp))
2827                   (not (looking-at paragraph-separate))
2828                   (not (looking-at message-cite-prefix-regexp)))
2829         (forward-line 1))
2830       (setq end (point))
2831       (goto-char beg)
2832       (while (and (if (bobp) nil (forward-line -1) t)
2833                   (not (looking-at paragraph-start))
2834                   (not (looking-at message-cite-prefix-regexp)))
2835         (setq beg (point))))
2836     (goto-char point)
2837     (save-restriction
2838       (narrow-to-region beg end)
2839       (if not-break
2840           (setq point nil)
2841         (if bolp
2842             (newline)
2843           (newline)
2844           (newline))
2845         (setq point (point))
2846         ;; (newline 2) doesn't mark both newline's as hard, so call
2847         ;; newline twice. -jas
2848         (newline)
2849         (newline)
2850         (delete-region (point) (re-search-forward "[ \t]*"))
2851         (when (and quoted (not bolp))
2852           (insert quoted leading-space)))
2853       (undo-boundary)
2854       (if quoted
2855           (let* ((adaptive-fill-regexp
2856                   (regexp-quote (concat quoted leading-space)))
2857                  (adaptive-fill-first-line-regexp
2858                   adaptive-fill-regexp ))
2859             (fill-paragraph arg))
2860         (fill-paragraph arg))
2861       (if point (goto-char point)))))
2862
2863 (defun message-fill-paragraph (&optional arg)
2864   "Like `fill-paragraph'."
2865   (interactive (list (if current-prefix-arg 'full)))
2866   (if (if (boundp 'filladapt-mode) filladapt-mode)
2867       nil
2868     (message-newline-and-reformat arg t)
2869     t))
2870
2871 ;; Is it better to use `mail-header-end'?
2872 (defun message-point-in-header-p ()
2873   "Return t if point is in the header."
2874   (save-excursion
2875     (let ((p (point)))
2876       (goto-char (point-min))
2877       (not (re-search-forward
2878             (concat "^" (regexp-quote mail-header-separator) "\n")
2879             p t)))))
2880
2881 (defun message-do-auto-fill ()
2882   "Like `do-auto-fill', but don't fill in message header."
2883   (unless (message-point-in-header-p)
2884     (do-auto-fill)))
2885
2886 (defun message-insert-signature (&optional force)
2887   "Insert a signature.  See documentation for variable `message-signature'."
2888   (interactive (list 0))
2889   (let* ((signature
2890           (cond
2891            ((and (null message-signature)
2892                  (eq force 0))
2893             (save-excursion
2894               (goto-char (point-max))
2895               (not (re-search-backward message-signature-separator nil t))))
2896            ((and (null message-signature)
2897                  force)
2898             t)
2899            ((functionp message-signature)
2900             (funcall message-signature))
2901            ((listp message-signature)
2902             (eval message-signature))
2903            (t message-signature)))
2904          (signature
2905           (cond ((stringp signature)
2906                  signature)
2907                 ((and (eq t signature)
2908                       message-signature-file
2909                       (file-exists-p message-signature-file))
2910                  signature))))
2911     (when signature
2912       (goto-char (point-max))
2913       ;; Insert the signature.
2914       (unless (bolp)
2915         (insert "\n"))
2916       (when message-signature-insert-empty-line
2917         (insert "\n"))
2918       (insert "-- \n")
2919       (if (eq signature t)
2920           (insert-file-contents message-signature-file)
2921         (insert signature))
2922       (goto-char (point-max))
2923       (or (bolp) (insert "\n")))))
2924
2925 (defun message-insert-importance-high ()
2926   "Insert header to mark message as important."
2927   (interactive)
2928   (save-excursion
2929     (save-restriction
2930       (message-narrow-to-headers)
2931       (message-remove-header "Importance"))
2932     (message-goto-eoh)
2933     (insert "Importance: high\n")))
2934
2935 (defun message-insert-importance-low ()
2936   "Insert header to mark message as unimportant."
2937   (interactive)
2938   (save-excursion
2939     (save-restriction
2940       (message-narrow-to-headers)
2941       (message-remove-header "Importance"))
2942     (message-goto-eoh)
2943     (insert "Importance: low\n")))
2944
2945 (defun message-insert-or-toggle-importance ()
2946   "Insert a \"Importance: high\" header, or cycle through the header values.
2947 The three allowed values according to RFC 1327 are `high', `normal'
2948 and `low'."
2949   (interactive)
2950   (save-excursion
2951     (let ((valid '("high" "normal" "low"))
2952           (new "high")
2953           cur)
2954       (save-restriction
2955         (message-narrow-to-headers)
2956         (when (setq cur (message-fetch-field "Importance"))
2957           (message-remove-header "Importance")
2958           (setq new (cond ((string= cur "high")
2959                            "low")
2960                           ((string= cur "low")
2961                            "normal")
2962                           (t
2963                            "high")))))
2964       (message-goto-eoh)
2965       (insert (format "Importance: %s\n" new)))))
2966
2967 (defun message-insert-disposition-notification-to ()
2968   "Request a disposition notification (return receipt) to this message.
2969 Note that this should not be used in newsgroups."
2970   (interactive)
2971   (save-excursion
2972     (save-restriction
2973       (message-narrow-to-headers)
2974       (message-remove-header "Disposition-Notification-To"))
2975     (message-goto-eoh)
2976     (insert (format "Disposition-Notification-To: %s\n"
2977                     (or (message-field-value "Reply-to")
2978                         (message-field-value "From")
2979                         (message-make-from))))))
2980
2981 (defun message-elide-region (b e)
2982   "Elide the text in the region.
2983 An ellipsis (from `message-elide-ellipsis') will be inserted where the
2984 text was killed."
2985   (interactive "r")
2986   (kill-region b e)
2987   (insert message-elide-ellipsis))
2988
2989 (defvar message-caesar-translation-table nil)
2990
2991 (defun message-caesar-region (b e &optional n)
2992   "Caesar rotate region B to E by N, default 13, for decrypting netnews."
2993   (interactive
2994    (list
2995     (min (point) (or (mark t) (point)))
2996     (max (point) (or (mark t) (point)))
2997     (when current-prefix-arg
2998       (prefix-numeric-value current-prefix-arg))))
2999
3000   (setq n (if (numberp n) (mod n 26) 13)) ;canonize N
3001   (unless (or (zerop n)                 ; no action needed for a rot of 0
3002               (= b e))                  ; no region to rotate
3003     ;; We build the table, if necessary.
3004     (when (or (not message-caesar-translation-table)
3005               (/= (aref message-caesar-translation-table ?a) (+ ?a n)))
3006       (setq message-caesar-translation-table
3007             (message-make-caesar-translation-table n)))
3008     (translate-region b e message-caesar-translation-table)))
3009
3010 (defun message-make-caesar-translation-table (n)
3011   "Create a rot table with offset N."
3012   (let ((i -1)
3013         (table (make-string 256 0)))
3014     (while (< (incf i) 256)
3015       (aset table i i))
3016     (concat
3017      (substring table 0 ?A)
3018      (substring table (+ ?A n) (+ ?A n (- 26 n)))
3019      (substring table ?A (+ ?A n))
3020      (substring table (+ ?A 26) ?a)
3021      (substring table (+ ?a n) (+ ?a n (- 26 n)))
3022      (substring table ?a (+ ?a n))
3023      (substring table (+ ?a 26) 255))))
3024
3025 (defun message-caesar-buffer-body (&optional rotnum)
3026   "Caesar rotate all letters in the current buffer by 13 places.
3027 Used to encode/decode possibly offensive messages (commonly in rec.humor).
3028 With prefix arg, specifies the number of places to rotate each letter forward.
3029 Mail and USENET news headers are not rotated."
3030   (interactive (if current-prefix-arg
3031                    (list (prefix-numeric-value current-prefix-arg))
3032                  (list nil)))
3033   (save-excursion
3034     (save-restriction
3035       (when (message-goto-body)
3036         (narrow-to-region (point) (point-max)))
3037       (message-caesar-region (point-min) (point-max) rotnum))))
3038