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