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