1 ;;; message.el --- composing mail and news messages
3 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
4 ;; 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
6 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
7 ;; Keywords: mail, news
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software: you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation, either version 3 of the License, or
14 ;; (at your option) any later version.
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
26 ;; This mode provides mail-sending facilities from within Emacs. It
27 ;; consists mainly of large chunks of code from the sendmail.el,
28 ;; gnus-msg.el and rnewspost.el files.
33 (unless (fboundp 'declare-function) (defmacro declare-function (&rest r))))
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))
53 (autoload 'mailclient-send-it "mailclient") ;; Emacs 22 or contrib/
55 (defvar gnus-message-group-art)
56 (defvar gnus-list-identifiers) ; gnus-sum is required where necessary
57 (defvar rmail-enable-mime-composing)
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")
66 (put 'user-mail-address 'custom-type 'string)
67 (put 'user-full-name 'custom-type 'string)
69 (defgroup message-various nil
70 "Various Message Variables."
71 :link '(custom-manual "(message)Various Message Variables")
74 (defgroup message-buffers nil
76 :link '(custom-manual "(message)Message Buffers")
79 (defgroup message-sending nil
81 :link '(custom-manual "(message)Sending Variables")
84 (defgroup message-interface nil
86 :link '(custom-manual "(message)Interface")
89 (defgroup message-forwarding nil
91 :link '(custom-manual "(message)Forwarding")
92 :group 'message-interface)
94 (defgroup message-insertion nil
96 :link '(custom-manual "(message)Insertion")
99 (defgroup message-headers nil
101 :link '(custom-manual "(message)Message Headers")
104 (defgroup message-news nil
105 "Composing News Messages."
108 (defgroup message-mail nil
109 "Composing Mail Messages."
112 (defgroup message-faces nil
113 "Faces used for message composing."
117 (defcustom message-directory "~/Mail/"
118 "*Directory from which all other mail file variables are derived."
119 :group 'message-various
122 (defcustom message-max-buffers 10
123 "*How many buffers to keep before starting to kill them off."
124 :group 'message-buffers
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)))
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
137 :type '(radio (function-item message-output)
138 (function :tag "Other"))
139 :group 'message-sending)
141 (defcustom message-fcc-externalize-attachments nil
142 "If non-nil, attachments are included as external parts in Fcc copies."
145 :group 'message-sending)
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)))
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
162 (defcustom message-from-style mail-from-style
163 ;; Default to the value of `mail-from-style', available in all Emacsen
164 ;; that Gnus supports.
165 "*Specifies how \"From\" headers look.
167 If nil, they contain just the return address like:
169 If `parens', they look like:
170 king@grassland.com (Elvis Parsley)
171 If `angles', they look like:
172 Elvis Parsley <king@grassland.com>
174 Otherwise, most addresses look like `angles', but they look like
175 `parens' if `angles' would need quoting and `parens' would not."
177 :type '(choice (const :tag "simple" nil)
181 :group 'message-headers)
183 (defcustom message-insert-canlock t
184 "Whether to insert a Cancel-Lock header in news postings."
186 :group 'message-headers
189 (defcustom message-syntax-checks
190 (if message-insert-canlock '((sender . disabled)) nil)
191 ;; Guess this one shouldn't be easy to customize...
192 "*Controls what syntax checks should not be performed on outgoing posts.
193 To disable checking of long signatures, for instance, add
194 `(signature . disabled)' to this list.
196 Don't touch this variable unless you really know what you're doing.
198 Checks include `approved', `bogus-recipient', `continuation-headers',
199 `control-chars', `empty', `existing-newsgroups', `from', `illegible-text',
200 `invisible-text', `long-header-lines', `long-lines', `message-id',
201 `multiple-headers', `new-text', `newsgroups', `quoting-style',
202 `repeated-newsgroups', `reply-to', `sender', `sendsys', `shoot',
203 `shorten-followup-to', `signature', `size', `subject', `subject-cmsg'
204 and `valid-newsgroups'."
206 :type '(repeat sexp)) ; Fixme: improve this
208 (defcustom message-required-headers '((optional . References)
210 "*Headers to be generated or prompted for when sending a message.
211 Also see `message-required-news-headers' and
212 `message-required-mail-headers'."
215 :group 'message-headers
216 :link '(custom-manual "(message)Message Headers")
217 :type '(repeat sexp))
219 (defcustom message-draft-headers '(References From Date)
220 "*Headers to be generated when saving a draft message."
223 :group 'message-headers
224 :link '(custom-manual "(message)Message Headers")
225 :type '(repeat sexp))
227 (defcustom message-required-news-headers
228 '(From Newsgroups Subject Date Message-ID
229 (optional . Organization)
230 (optional . User-Agent))
231 "*Headers to be generated or prompted for when posting an article.
232 RFC977 and RFC1036 require From, Date, Newsgroups, Subject,
233 Message-ID. Organization, Lines, In-Reply-To, Expires, and
234 User-Agent are optional. If you don't want message to insert some
235 header, remove it from this list."
237 :group 'message-headers
238 :link '(custom-manual "(message)Message Headers")
239 :type '(repeat sexp))
241 (defcustom message-required-mail-headers
242 '(From Subject Date (optional . In-Reply-To) Message-ID
243 (optional . User-Agent))
244 "*Headers to be generated or prompted for when mailing a message.
245 It is recommended that From, Date, To, Subject and Message-ID be
246 included. Organization and User-Agent are optional."
248 :group 'message-headers
249 :link '(custom-manual "(message)Message Headers")
250 :type '(repeat sexp))
252 (defcustom message-prune-recipient-rules nil
253 "Rules for how to prune the list of recipients when doing wide replies.
254 This is a list of regexps and regexp matches."
257 :group 'message-headers
258 :link '(custom-manual "(message)Wide Reply")
259 :type '(repeat regexp))
261 (defcustom message-deletable-headers '(Message-ID Date Lines)
262 "Headers to be deleted if they already exist and were generated by message previously."
263 :group 'message-headers
264 :link '(custom-manual "(message)Message Headers")
267 (defcustom message-ignored-news-headers
268 "^NNTP-Posting-Host:\\|^Xref:\\|^[BGF]cc:\\|^Resent-Fcc:\\|^X-Draft-From:\\|^X-Gnus-Agent-Meta-Information:"
269 "*Regexp of headers to be removed unconditionally before posting."
271 :group 'message-headers
272 :link '(custom-manual "(message)Message Headers")
273 :type '(repeat :value-to-internal (lambda (widget value)
274 (custom-split-regexp-maybe value))
275 :match (lambda (widget value)
277 (widget-editable-list-match widget value)))
280 (defcustom message-ignored-mail-headers
281 "^[GF]cc:\\|^Resent-Fcc:\\|^Xref:\\|^X-Draft-From:\\|^X-Gnus-Agent-Meta-Information:"
282 "*Regexp of headers to be removed unconditionally before mailing."
284 :group 'message-headers
285 :link '(custom-manual "(message)Mail Headers")
288 (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:"
289 "*Header lines matching this regexp will be deleted before posting.
290 It's best to delete old Path and Date headers before posting to avoid
292 :group 'message-interface
293 :link '(custom-manual "(message)Superseding")
294 :type '(repeat :value-to-internal (lambda (widget value)
295 (custom-split-regexp-maybe value))
296 :match (lambda (widget value)
298 (widget-editable-list-match widget value)))
301 (defcustom message-subject-re-regexp
302 "^[ \t]*\\([Rr][Ee]\\(\\[[0-9]*\\]\\)*:[ \t]*\\)*[ \t]*"
303 "*Regexp matching \"Re: \" in the subject line."
304 :group 'message-various
305 :link '(custom-manual "(message)Message Headers")
308 ;;; Start of variables adopted from `message-utils.el'.
310 (defcustom message-subject-trailing-was-query 'ask
311 "*What to do with trailing \"(was: <old subject>)\" in subject lines.
312 If nil, leave the subject unchanged. If it is the symbol `ask', query
313 the user what do do. In this case, the subject is matched against
314 `message-subject-trailing-was-ask-regexp'. If
315 `message-subject-trailing-was-query' is t, always strip the trailing
316 old subject. In this case, `message-subject-trailing-was-regexp' is
319 :type '(choice (const :tag "never" nil)
320 (const :tag "always strip" t)
322 :link '(custom-manual "(message)Message Headers")
323 :group 'message-various)
325 (defcustom message-subject-trailing-was-ask-regexp
326 "[ \t]*\\([[(]+[Ww][Aa][Ss][ \t]*.*[\])]+\\)"
327 "*Regexp matching \"(was: <old subject>)\" in the subject line.
329 The function `message-strip-subject-trailing-was' uses this regexp if
330 `message-subject-trailing-was-query' is set to the symbol `ask'. If
331 the variable is t instead of `ask', use
332 `message-subject-trailing-was-regexp' instead.
334 It is okay to create some false positives here, as the user is asked."
336 :group 'message-various
337 :link '(custom-manual "(message)Message Headers")
340 (defcustom message-subject-trailing-was-regexp
341 "[ \t]*\\((*[Ww][Aa][Ss]:[ \t]*.*)\\)"
342 "*Regexp matching \"(was: <old subject>)\" in the subject line.
344 If `message-subject-trailing-was-query' is set to t, the subject is
345 matched against `message-subject-trailing-was-regexp' in
346 `message-strip-subject-trailing-was'. You should use a regexp creating very
347 few false positives here."
349 :group 'message-various
350 :link '(custom-manual "(message)Message Headers")
353 ;;; marking inserted text
355 (defcustom message-mark-insert-begin
356 "--8<---------------cut here---------------start------------->8---\n"
357 "How to mark the beginning of some inserted text."
360 :link '(custom-manual "(message)Insertion Variables")
361 :group 'message-various)
363 (defcustom message-mark-insert-end
364 "--8<---------------cut here---------------end--------------->8---\n"
365 "How to mark the end of some inserted text."
368 :link '(custom-manual "(message)Insertion Variables")
369 :group 'message-various)
371 (defcustom message-archive-header "X-No-Archive: Yes\n"
372 "Header to insert when you don't want your article to be archived.
373 Archives \(such as groups.google.com\) respect this header."
376 :link '(custom-manual "(message)Header Commands")
377 :group 'message-various)
379 (defcustom message-archive-note
380 "X-No-Archive: Yes - save http://groups.google.com/"
381 "Note to insert why you wouldn't want this posting archived.
382 If nil, don't insert any text in the body."
384 :type '(radio string (const nil))
385 :link '(custom-manual "(message)Header Commands")
386 :group 'message-various)
388 ;;; Crossposts and Followups
389 ;; inspired by JoH-followup-to by Jochem Huhman <joh at gmx.de>
390 ;; new suggestions by R. Weikusat <rw at another.de>
392 (defvar message-cross-post-old-target nil
393 "Old target for cross-posts or follow-ups.")
394 (make-variable-buffer-local 'message-cross-post-old-target)
396 (defcustom message-cross-post-default t
397 "When non-nil `message-cross-post-followup-to' will perform a crosspost.
398 If nil, `message-cross-post-followup-to' will only do a followup. Note that
399 you can explicitly override this setting by calling
400 `message-cross-post-followup-to' with a prefix."
403 :group 'message-various)
405 (defcustom message-cross-post-note "Crosspost & Followup-To: "
406 "Note to insert before signature to notify of cross-post and follow-up."
409 :group 'message-various)
411 (defcustom message-followup-to-note "Followup-To: "
412 "Note to insert before signature to notify of follow-up only."
415 :group 'message-various)
417 (defcustom message-cross-post-note-function 'message-cross-post-insert-note
418 "Function to use to insert note about Crosspost or Followup-To.
419 The function will be called with four arguments. The function should not only
420 insert a note, but also ensure old notes are deleted. See the documentation
421 for `message-cross-post-insert-note'."
424 :group 'message-various)
426 ;;; End of variables adopted from `message-utils.el'.
428 (defcustom message-signature-separator "^-- $"
429 "Regexp matching the signature separator.
430 This variable is used to strip off the signature from quoted text
431 when `message-cite-function' is
432 `message-cite-original-without-signature'. Most useful values
433 are \"^-- $\" (strict) and \"^-- *$\" (loose; allow missing
435 :type '(choice (const :tag "strict" "^-- $")
436 (const :tag "loose" "^-- *$")
438 :version "22.3" ;; Gnus 5.10.12 (changed default)
439 :link '(custom-manual "(message)Various Message Variables")
440 :group 'message-various)
442 (defcustom message-elide-ellipsis "\n[...]\n\n"
443 "*The string which is inserted for elided text."
445 :link '(custom-manual "(message)Various Commands")
446 :group 'message-various)
448 (defcustom message-interactive mail-interactive
449 ;; Default to the value of `mail-interactive', available in all Emacsen
450 ;; that Gnus supports.
451 "Non-nil means when sending a message wait for and display errors.
452 A value of nil means let mailer mail back a message to report errors."
454 :group 'message-sending
456 :link '(custom-manual "(message)Sending Variables")
459 (defcustom message-confirm-send nil
460 "When non-nil, ask for confirmation when sending a message."
461 :group 'message-sending
463 :version "23.1" ;; No Gnus
464 :link '(custom-manual "(message)Sending Variables")
467 (defcustom message-generate-new-buffers 'unsent
468 "*Say whether to create a new message buffer to compose a message.
469 Valid values include:
472 Generate the buffer name in the Message way (e.g., *mail*, *news*,
473 *mail to whom*, *news on group*, etc.) and continue editing in the
474 existing buffer of that name. If there is no such buffer, it will
478 Create the new buffer with the name generated in the Message way.
481 Similar to `unique' but the buffer name begins with \"*unsent \".
484 Similar to nil but the buffer name is simpler like *mail message*.
487 If this is a function, call that function with three parameters:
488 The type, the To address and the group name (any of these may be nil).
489 The function should return the new buffer name."
491 :group 'message-buffers
492 :link '(custom-manual "(message)Message Buffers")
493 :type '(choice (const nil)
494 (sexp :tag "unique" :format "unique\n" :value unique
495 :match (lambda (widget value) (memq value '(unique t))))
498 (function :format "\n %{%t%}: %v")))
500 (defcustom message-kill-buffer-on-exit nil
501 "*Non-nil means that the message buffer will be killed after sending a message."
502 :group 'message-buffers
503 :link '(custom-manual "(message)Message Buffers")
506 (defcustom message-kill-buffer-query t
507 "*Non-nil means that killing a modified message buffer has to be confirmed.
508 This is used by `message-kill-buffer'."
509 :version "23.1" ;; No Gnus
510 :group 'message-buffers
513 (defvar gnus-local-organization)
514 (defcustom message-user-organization
515 (or (and (boundp 'gnus-local-organization)
516 (stringp gnus-local-organization)
517 gnus-local-organization)
518 (getenv "ORGANIZATION")
520 "*String to be used as an Organization header.
521 If t, use `message-user-organization-file'."
522 :group 'message-headers
523 :type '(choice string
524 (const :tag "consult file" t)))
526 (defcustom message-user-organization-file
528 (dolist (f (list "/etc/organization"
529 "/etc/news/organization"
530 "/usr/lib/news/organization"))
531 (when (file-readable-p f)
534 "*Local news organization file."
536 :link '(custom-manual "(message)News Headers")
537 :group 'message-headers)
539 (defcustom message-make-forward-subject-function
540 #'message-forward-subject-name-subject
541 "*List of functions called to generate subject headers for forwarded messages.
542 The subject generated by the previous function is passed into each
545 The provided functions are:
547 * `message-forward-subject-author-subject' Source of article (author or
548 newsgroup), in brackets followed by the subject
549 * `message-forward-subject-name-subject' Source of article (name of author
550 or newsgroup), in brackets followed by the subject
551 * `message-forward-subject-fwd' Subject of article with 'Fwd:' prepended
553 :group 'message-forwarding
554 :link '(custom-manual "(message)Forwarding")
555 :type '(radio (function-item message-forward-subject-author-subject)
556 (function-item message-forward-subject-fwd)
557 (function-item message-forward-subject-name-subject)
558 (repeat :tag "List of functions" function)))
560 (defcustom message-forward-as-mime t
561 "*Non-nil means forward messages as an inline/rfc822 MIME section.
562 Otherwise, directly inline the old message in the forwarded message."
564 :group 'message-forwarding
565 :link '(custom-manual "(message)Forwarding")
568 (defcustom message-forward-show-mml 'best
569 "*Non-nil means show forwarded messages as MML (decoded from MIME).
570 Otherwise, forwarded messages are unchanged.
571 Can also be the symbol `best' to indicate that MML should be
572 used, except when it is a bad idea to use MML. One example where
573 it is a bad idea is when forwarding a signed or encrypted
574 message, because converting MIME to MML would invalidate the
577 :group 'message-forwarding
578 :type '(choice (const :tag "use MML" t)
579 (const :tag "don't use MML " nil)
580 (const :tag "use MML when appropriate" best)))
582 (defcustom message-forward-before-signature t
583 "*Non-nil means put forwarded message before signature, else after."
584 :group 'message-forwarding
587 (defcustom message-wash-forwarded-subjects nil
588 "*Non-nil means try to remove as much cruft as possible from the subject.
589 Done before generating the new subject of a forward."
590 :group 'message-forwarding
591 :link '(custom-manual "(message)Forwarding")
594 (defcustom message-ignored-resent-headers
595 ;; `Delivered-To' needs to be removed because some mailers use it to
596 ;; detect loops, so if you resend a message to an address that ultimately
597 ;; comes back to you (e.g. a mailing-list to which you subscribe, in which
598 ;; case you may be removed from the list on the grounds that mail to you
599 ;; bounced with a "mailing loop" error).
600 "^Return-receipt\\|^X-Gnus\\|^Gnus-Warning:\\|^>?From \\|^Delivered-To:"
601 "*All headers that match this regexp will be deleted when resending a message."
602 :group 'message-interface
603 :link '(custom-manual "(message)Resending")
604 :type '(repeat :value-to-internal (lambda (widget value)
605 (custom-split-regexp-maybe value))
606 :match (lambda (widget value)
608 (widget-editable-list-match widget value)))
611 (defcustom message-forward-ignored-headers "^Content-Transfer-Encoding:\\|^X-Gnus"
612 "*All headers that match this regexp will be deleted when forwarding a message."
614 :group 'message-forwarding
615 :type '(repeat :value-to-internal (lambda (widget value)
616 (custom-split-regexp-maybe value))
617 :match (lambda (widget value)
619 (widget-editable-list-match widget value)))
622 (defcustom message-ignored-cited-headers "."
623 "*Delete these headers from the messages you yank."
624 :group 'message-insertion
625 :link '(custom-manual "(message)Insertion Variables")
628 (defcustom message-cite-prefix-regexp
629 ;; Default to the value of `mail-citation-prefix-regexp' if available.
630 ;; Note: as for Emacs 21, XEmacs 21.4 and 21.5, it is unavailable
631 ;; unless sendmail.el is loaded.
632 (cond ((boundp 'mail-citation-prefix-regexp)
633 mail-citation-prefix-regexp)
634 ((string-match "[[:digit:]]" "1")
635 ;; Support POSIX? XEmacs 21.5.27 doesn't.
636 "\\([ \t]*[_.[:word:]]+>+\\|[ \t]*[]>|}]\\)+")
638 ;; ?-, ?_ or ?. MUST NOT be in syntax entry w.
639 (let (non-word-constituents)
640 (with-syntax-table text-mode-syntax-table
641 (setq non-word-constituents
643 (if (string-match "\\w" "_") "" "_")
644 (if (string-match "\\w" ".") "" "."))))
645 (if (equal non-word-constituents "")
646 "\\([ \t]*\\(\\w\\)+>+\\|[ \t]*[]>|}]\\)+"
647 (concat "\\([ \t]*\\(\\w\\|["
648 non-word-constituents
649 "]\\)+>+\\|[ \t]*[]>|}]\\)+")))))
650 "*Regexp matching the longest possible citation prefix on a line."
652 :group 'message-insertion
653 :link '(custom-manual "(message)Insertion Variables")
655 :set (lambda (symbol value)
657 (custom-set-default symbol value)
658 (if (boundp 'gnus-message-cite-prefix-regexp)
659 (setq gnus-message-cite-prefix-regexp
660 (concat "^\\(?:" value "\\)"))))))
662 (defcustom message-cancel-message "I am canceling my own article.\n"
663 "Message to be inserted in the cancel message."
664 :group 'message-interface
665 :link '(custom-manual "(message)Canceling News")
668 (defun message-send-mail-function ()
669 "Return suitable value for the variable `message-send-mail-function'."
670 (cond ((and (require 'sendmail)
671 (boundp 'sendmail-program)
673 (executable-find sendmail-program))
674 'message-send-mail-with-sendmail)
675 ((and (locate-library "smtpmail")
676 (boundp 'smtpmail-default-smtp-server)
677 smtpmail-default-smtp-server)
678 'message-smtpmail-send-it)
679 ((locate-library "mailclient")
680 'message-send-mail-with-mailclient)
682 (error "Don't know how to send mail. Please customize `message-send-mail-function'"))))
684 ;; Useful to set in site-init.el
685 (defcustom message-send-mail-function
686 (cond ((eq send-mail-function 'smtpmail-send-it) 'message-smtpmail-send-it)
687 ((eq send-mail-function 'feedmail-send-it) 'feedmail-send-it)
688 ((eq send-mail-function 'mailclient-send-it)
689 'message-send-mail-with-mailclient)
690 (t (message-send-mail-function)))
691 "Function to call to send the current buffer as mail.
692 The headers should be delimited by a line whose contents match the
693 variable `mail-header-separator'.
695 Valid values include `message-send-mail-with-sendmail'
696 `message-send-mail-with-mh', `message-send-mail-with-qmail',
697 `message-smtpmail-send-it', `smtpmail-send-it',
698 `feedmail-send-it' and `message-send-mail-with-mailclient'. The
699 default is system dependent and determined by the function
700 `message-send-mail-function'.
702 See also `send-mail-function'."
703 :type '(radio (function-item message-send-mail-with-sendmail)
704 (function-item message-send-mail-with-mh)
705 (function-item message-send-mail-with-qmail)
706 (function-item message-smtpmail-send-it)
707 (function-item smtpmail-send-it)
708 (function-item feedmail-send-it)
709 (function-item message-send-mail-with-mailclient
710 :tag "Use Mailclient package")
711 (function :tag "Other"))
712 :group 'message-sending
714 :initialize 'custom-initialize-default
715 :link '(custom-manual "(message)Mail Variables")
716 :group 'message-mail)
718 (defcustom message-send-news-function 'message-send-news
719 "Function to call to send the current buffer as news.
720 The headers should be delimited by a line whose contents match the
721 variable `mail-header-separator'."
722 :group 'message-sending
724 :link '(custom-manual "(message)News Variables")
727 (defcustom message-reply-to-function nil
728 "If non-nil, function that should return a list of headers.
729 This function should pick out addresses from the To, Cc, and From headers
730 and respond with new To and Cc headers."
731 :group 'message-interface
732 :link '(custom-manual "(message)Reply")
733 :type '(choice function (const nil)))
735 (defcustom message-wide-reply-to-function nil
736 "If non-nil, function that should return a list of headers.
737 This function should pick out addresses from the To, Cc, and From headers
738 and respond with new To and Cc headers."
739 :group 'message-interface
740 :link '(custom-manual "(message)Wide Reply")
741 :type '(choice function (const nil)))
743 (defcustom message-followup-to-function nil
744 "If non-nil, function that should return a list of headers.
745 This function should pick out addresses from the To, Cc, and From headers
746 and respond with new To and Cc headers."
747 :group 'message-interface
748 :link '(custom-manual "(message)Followup")
749 :type '(choice function (const nil)))
751 (defcustom message-extra-wide-headers nil
752 "If non-nil, a list of additional address headers.
753 These are used when composing a wide reply."
754 :group 'message-sending
755 :type '(repeat string))
757 (defcustom message-use-followup-to 'ask
758 "*Specifies what to do with Followup-To header.
759 If nil, always ignore the header. If it is t, use its value, but
760 query before using the \"poster\" value. If it is the symbol `ask',
761 always query the user whether to use the value. If it is the symbol
762 `use', always use the value."
763 :group 'message-interface
764 :link '(custom-manual "(message)Followup")
765 :type '(choice (const :tag "ignore" nil)
766 (const :tag "use & query" t)
770 (defcustom message-use-mail-followup-to 'use
771 "*Specifies what to do with Mail-Followup-To header.
772 If nil, always ignore the header. If it is the symbol `ask', always
773 query the user whether to use the value. If it is the symbol `use',
774 always use the value."
776 :group 'message-interface
777 :link '(custom-manual "(message)Mailing Lists")
778 :type '(choice (const :tag "ignore" nil)
782 (defcustom message-subscribed-address-functions nil
783 "*Specifies functions for determining list subscription.
784 If nil, do not attempt to determine list subscription with functions.
785 If non-nil, this variable contains a list of functions which return
786 regular expressions to match lists. These functions can be used in
787 conjunction with `message-subscribed-regexps' and
788 `message-subscribed-addresses'."
790 :group 'message-interface
791 :link '(custom-manual "(message)Mailing Lists")
792 :type '(repeat sexp))
794 (defcustom message-subscribed-address-file nil
795 "*A file containing addresses the user is subscribed to.
796 If nil, do not look at any files to determine list subscriptions. If
797 non-nil, each line of this file should be a mailing list address."
799 :group 'message-interface
800 :link '(custom-manual "(message)Mailing Lists")
801 :type '(radio file (const nil)))
803 (defcustom message-subscribed-addresses nil
804 "*Specifies a list of addresses the user is subscribed to.
805 If nil, do not use any predefined list subscriptions. This list of
806 addresses can be used in conjunction with
807 `message-subscribed-address-functions' and `message-subscribed-regexps'."
809 :group 'message-interface
810 :link '(custom-manual "(message)Mailing Lists")
811 :type '(repeat string))
813 (defcustom message-subscribed-regexps nil
814 "*Specifies a list of addresses the user is subscribed to.
815 If nil, do not use any predefined list subscriptions. This list of
816 regular expressions can be used in conjunction with
817 `message-subscribed-address-functions' and `message-subscribed-addresses'."
819 :group 'message-interface
820 :link '(custom-manual "(message)Mailing Lists")
821 :type '(repeat regexp))
823 (defcustom message-allow-no-recipients 'ask
824 "Specifies what to do when there are no recipients other than Gcc/Fcc.
825 If it is the symbol `always', the posting is allowed. If it is the
826 symbol `never', the posting is not allowed. If it is the symbol
827 `ask', you are prompted."
829 :group 'message-interface
830 :link '(custom-manual "(message)Message Headers")
831 :type '(choice (const always)
835 (defcustom message-sendmail-f-is-evil nil
836 "*Non-nil means don't add \"-f username\" to the sendmail command line.
837 Doing so would be even more evil than leaving it out."
838 :group 'message-sending
839 :link '(custom-manual "(message)Mail Variables")
842 (defcustom message-sendmail-envelope-from
843 ;; Default to the value of `mail-envelope-from' if available.
844 ;; Note: as for Emacsen that Gnus supports, except for SXEmacs, it is
845 ;; unavailable unless sendmail.el is loaded.
846 (if (boundp 'mail-envelope-from) mail-envelope-from)
847 "*Envelope-from when sending mail with sendmail.
848 If this is nil, use `user-mail-address'. If it is the symbol
849 `header', use the From: header of the message."
851 :type '(choice (string :tag "From name")
852 (const :tag "Use From: header from message" header)
853 (const :tag "Use `user-mail-address'" nil))
854 :link '(custom-manual "(message)Mail Variables")
855 :group 'message-sending)
857 (defcustom message-sendmail-extra-arguments nil
858 "Additional arguments to `sendmail-program'."
859 ;; E.g. '("-a" "account") for msmtp
860 :version "23.1" ;; No Gnus
861 :type '(repeat string)
862 ;; :link '(custom-manual "(message)Mail Variables")
863 :group 'message-sending)
865 ;; qmail-related stuff
866 (defcustom message-qmail-inject-program "/var/qmail/bin/qmail-inject"
867 "Location of the qmail-inject program."
868 :group 'message-sending
869 :link '(custom-manual "(message)Mail Variables")
872 (defcustom message-qmail-inject-args nil
873 "Arguments passed to qmail-inject programs.
874 This should be a list of strings, one string for each argument.
875 It may also be a function.
877 For e.g., if you wish to set the envelope sender address so that bounces
878 go to the right place or to deal with listserv's usage of that address, you
879 might set this variable to '(\"-f\" \"you@some.where\")."
880 :group 'message-sending
881 :link '(custom-manual "(message)Mail Variables")
882 :type '(choice (function)
885 (defvar gnus-post-method)
886 (defvar gnus-select-method)
887 (defcustom message-post-method
888 (cond ((and (boundp 'gnus-post-method)
889 (listp gnus-post-method)
892 ((boundp 'gnus-select-method)
895 "*Method used to post news.
896 Note that when posting from inside Gnus, for instance, this
897 variable isn't used."
899 :group 'message-sending
900 ;; This should be the `gnus-select-method' widget, but that might
901 ;; create a dependence to `gnus.el'.
904 ;; FIXME: This should be a temporary workaround until someone implements a
905 ;; proper solution. If a crash happens while replying, the auto-save file
906 ;; will *not* have a `References:' header if `message-generate-headers-first'
907 ;; is nil. See: http://article.gmane.org/gmane.emacs.gnus.general/51138
908 (defcustom message-generate-headers-first '(references)
909 "Which headers should be generated before starting to compose a message.
910 If t, generate all required headers. This can also be a list of headers to
911 generate. The variables `message-required-news-headers' and
912 `message-required-mail-headers' specify which headers to generate.
914 Note that the variable `message-deletable-headers' specifies headers which
915 are to be deleted and then re-generated before sending, so this variable
916 will not have a visible effect for those headers."
917 :group 'message-headers
918 :link '(custom-manual "(message)Message Headers")
919 :type '(choice (const :tag "None" nil)
920 (const :tag "References" '(references))
922 (repeat (sexp :tag "Header"))))
924 (defcustom message-fill-column 72
925 "Column beyond which automatic line-wrapping should happen.
926 Local value for message buffers. If non-nil, also turn on
927 auto-fill in message buffers."
928 :group 'message-various
929 ;; :link '(custom-manual "(message)Message Headers")
930 :type '(choice (const :tag "Don't turn on auto fill" nil)
933 (defcustom message-setup-hook nil
934 "Normal hook, run each time a new outgoing message is initialized.
935 The function `message-setup' runs this hook."
936 :group 'message-various
937 :link '(custom-manual "(message)Various Message Variables")
940 (defcustom message-cancel-hook nil
941 "Hook run when cancelling articles."
942 :group 'message-various
943 :link '(custom-manual "(message)Various Message Variables")
946 (defcustom message-signature-setup-hook nil
947 "Normal hook, run each time a new outgoing message is initialized.
948 It is run after the headers have been inserted and before
949 the signature is inserted."
950 :group 'message-various
951 :link '(custom-manual "(message)Various Message Variables")
954 (defcustom message-mode-hook nil
955 "Hook run in message mode buffers."
956 :group 'message-various
959 (defcustom message-header-hook nil
960 "Hook run in a message mode buffer narrowed to the headers."
961 :group 'message-various
964 (defcustom message-header-setup-hook nil
965 "Hook called narrowed to the headers when setting up a message buffer."
966 :group 'message-various
967 :link '(custom-manual "(message)Various Message Variables")
970 (defcustom message-minibuffer-local-map
971 (let ((map (make-sparse-keymap 'message-minibuffer-local-map)))
972 (set-keymap-parent map minibuffer-local-map)
974 "Keymap for `message-read-from-minibuffer'."
976 :group 'message-various)
978 (defcustom message-citation-line-function 'message-insert-citation-line
979 "*Function called to insert the \"Whomever writes:\" line.
981 Predefined functions include `message-insert-citation-line' and
982 `message-insert-formatted-citation-line' (see the variable
983 `message-citation-line-format').
985 Note that Gnus provides a feature where the reader can click on
986 `writes:' to hide the cited text. If you change this line too much,
987 people who read your message will have to change their Gnus
988 configuration. See the variable `gnus-cite-attribution-suffix'."
990 (function-item :tag "plain" message-insert-citation-line)
991 (function-item :tag "formatted" message-insert-formatted-citation-line)
992 (function :tag "Other"))
993 :link '(custom-manual "(message)Insertion Variables")
994 :group 'message-insertion)
996 (defcustom message-citation-line-format "On %a, %b %d %Y, %N wrote:\n"
997 "Format of the \"Whomever writes:\" line.
999 The string is formatted using `format-spec'. The following
1000 constructs are replaced:
1002 %f The full From, e.g. \"John Doe <john.doe@example.invalid>\".
1003 %n The mail address, e.g. \"john.doe@example.invalid\".
1004 %N The real name if present, e.g.: \"John Doe\", else fall
1005 back to the mail address.
1006 %F The first name if present, e.g.: \"John\".
1007 %L The last name if present, e.g.: \"Doe\".
1009 All other format specifiers are passed to `format-time-string'
1010 which is called using the date from the article your replying to.
1011 Extracting the first (%F) and last name (%L) is done
1012 heuristically, so you should always check it yourself.
1014 Please also read the note in the documentation of
1015 `message-citation-line-function'."
1016 :type '(choice (const :tag "Plain" "%f writes:")
1017 (const :tag "Include date" "On %a, %b %d %Y, %n wrote:")
1019 :link '(custom-manual "(message)Insertion Variables")
1020 :version "23.1" ;; No Gnus
1021 :group 'message-insertion)
1023 (defcustom message-yank-prefix
1024 ;; Default to the value of `mail-yank-prefix' if available.
1025 ;; Note: as for Emacs 21, it is unavailable unless sendmail.el is loaded.
1026 (if (boundp 'mail-yank-prefix) mail-yank-prefix "> ")
1027 "*Prefix inserted on the lines of yanked messages.
1028 Fix `message-cite-prefix-regexp' if it is set to an abnormal value.
1029 See also `message-yank-cited-prefix' and `message-yank-empty-prefix'."
1032 :link '(custom-manual "(message)Insertion Variables")
1033 :group 'message-insertion)
1035 (defcustom message-yank-cited-prefix ">"
1036 "*Prefix inserted on cited lines of yanked messages.
1037 Fix `message-cite-prefix-regexp' if it is set to an abnormal value.
1038 See also `message-yank-prefix' and `message-yank-empty-prefix'."
1041 :link '(custom-manual "(message)Insertion Variables")
1042 :group 'message-insertion)
1044 (defcustom message-yank-empty-prefix ">"
1045 "*Prefix inserted on empty lines of yanked messages.
1046 See also `message-yank-prefix' and `message-yank-cited-prefix'."
1049 :link '(custom-manual "(message)Insertion Variables")
1050 :group 'message-insertion)
1052 (defcustom message-indentation-spaces
1053 ;; Default to the value of `mail-indentation-spaces' if available.
1054 ;; Note: as for Emacs 21, XEmacs 21.4 and 21.5, it is unavailable
1055 ;; unless sendmail.el is loaded.
1056 (if (boundp 'mail-indentation-spaces) mail-indentation-spaces 3)
1057 "*Number of spaces to insert at the beginning of each cited line.
1058 Used by `message-yank-original' via `message-yank-cite'."
1060 :group 'message-insertion
1061 :link '(custom-manual "(message)Insertion Variables")
1064 (defcustom message-cite-function 'message-cite-original-without-signature
1065 "*Function for citing an original message.
1066 Predefined functions include `message-cite-original' and
1067 `message-cite-original-without-signature'.
1068 Note that these functions use `mail-citation-hook' if that is non-nil."
1069 :type '(radio (function-item message-cite-original)
1070 (function-item message-cite-original-without-signature)
1071 (function-item sc-cite-original)
1072 (function :tag "Other"))
1073 :link '(custom-manual "(message)Insertion Variables")
1074 :version "22.3" ;; Gnus 5.10.12 (changed default)
1075 :group 'message-insertion)
1077 (defcustom message-indent-citation-function 'message-indent-citation
1078 "*Function for modifying a citation just inserted in the mail buffer.
1079 This can also be a list of functions. Each function can find the
1080 citation between (point) and (mark t). And each function should leave
1081 point and mark around the citation text as modified."
1083 :link '(custom-manual "(message)Insertion Variables")
1084 :group 'message-insertion)
1086 (defcustom message-signature mail-signature
1087 ;; Default to the value of `mail-signature', available in all Emacsen
1088 ;; that Gnus supports.
1089 "*String to be inserted at the end of the message buffer.
1090 If t, the `message-signature-file' file will be inserted instead.
1091 If a function, the result from the function will be used instead.
1092 If a form, the result from the form will be used instead."
1095 :link '(custom-manual "(message)Insertion Variables")
1096 :group 'message-insertion)
1098 (defcustom message-signature-file
1099 ;; Default to the value of `mail-signature-file' if available.
1100 ;; Note: as for Emacs 21, XEmacs 21.4 and 21.5, it is unavailable
1101 ;; unless sendmail.el is loaded.
1102 (if (boundp 'mail-signature-file) mail-signature-file "~/.signature")
1103 "*Name of file containing the text inserted at end of message buffer.
1104 Ignored if the named file doesn't exist.
1105 If nil, don't insert a signature.
1106 If a path is specified, the value of `message-signature-directory' is ignored,
1109 :type '(choice file (const :tags "None" nil))
1110 :link '(custom-manual "(message)Insertion Variables")
1111 :group 'message-insertion)
1113 (defcustom message-signature-directory nil
1114 "*Name of directory containing signature files.
1115 Comes in handy if you have many such files, handled via posting styles for
1117 If nil, `message-signature-file' is expected to specify the directory if
1119 :type '(choice string (const :tags "None" nil))
1120 :link '(custom-manual "(message)Insertion Variables")
1121 :group 'message-insertion)
1123 (defcustom message-signature-insert-empty-line t
1124 "*If non-nil, insert an empty line before the signature separator."
1127 :link '(custom-manual "(message)Insertion Variables")
1128 :group 'message-insertion)
1130 (defcustom message-distribution-function nil
1131 "*Function called to return a Distribution header."
1132 :group 'message-news
1133 :group 'message-headers
1134 :link '(custom-manual "(message)News Headers")
1135 :type '(choice function (const nil)))
1137 (defcustom message-expires 14
1138 "Number of days before your article expires."
1139 :group 'message-news
1140 :group 'message-headers
1141 :link '(custom-manual "(message)News Headers")
1144 (defcustom message-user-path nil
1145 "If nil, use the NNTP server name in the Path header.
1146 If stringp, use this; if non-nil, use no host name (user name only)."
1147 :group 'message-news
1148 :group 'message-headers
1149 :link '(custom-manual "(message)News Headers")
1150 :type '(choice (const :tag "nntp" nil)
1151 (string :tag "name")
1152 (sexp :tag "none" :format "%t" t)))
1154 ;; This can be the name of a buffer, or a cons cell (FUNCTION . ARGS)
1155 ;; for yanking the original buffer.
1156 (defvar message-reply-buffer nil)
1157 (defvar message-reply-headers nil
1158 "The headers of the current replied article.
1159 It is a vector of the following headers:
1160 \[number subject from date id references chars lines xref extra].")
1161 (defvar message-newsreader nil)
1162 (defvar message-mailer nil)
1163 (defvar message-sent-message-via nil)
1164 (defvar message-checksum nil)
1165 (defvar message-send-actions nil
1166 "A list of actions to be performed upon successful sending of a message.")
1167 (defvar message-exit-actions nil
1168 "A list of actions to be performed upon exiting after sending a message.")
1169 (defvar message-kill-actions nil
1170 "A list of actions to be performed before killing a message buffer.")
1171 (defvar message-postpone-actions nil
1172 "A list of actions to be performed after postponing a message.")
1174 (define-widget 'message-header-lines 'text
1175 "All header lines must be LFD terminated."
1176 :format "%{%t%}:%n%v"
1177 :valid-regexp "^\\'"
1178 :error "All header lines must be newline terminated")
1180 (defcustom message-default-headers ""
1181 "*A string containing header lines to be inserted in outgoing messages.
1182 It is inserted before you edit the message, so you can edit or delete
1185 :group 'message-headers
1186 :link '(custom-manual "(message)Message Headers")
1187 :type 'message-header-lines)
1189 (defcustom message-default-mail-headers
1190 ;; Ease the transition from mail-mode to message-mode. See bugs#4431, 5555.
1191 (concat (if (and (boundp 'mail-default-reply-to)
1192 (stringp mail-default-reply-to))
1193 (format "Reply-to: %s\n" mail-default-reply-to))
1194 (if (and (boundp 'mail-self-blind)
1196 (format "BCC: %s\n" user-mail-address))
1197 (if (and (boundp 'mail-archive-file-name)
1198 (stringp mail-archive-file-name))
1199 (format "FCC: %s\n" mail-archive-file-name))
1200 ;; Use the value of `mail-default-headers' if available.
1201 ;; Note: as for Emacs 21, XEmacs 21.4 and 21.5, it is
1202 ;; unavailable unless sendmail.el is loaded.
1203 (if (boundp 'mail-default-headers)
1204 mail-default-headers))
1205 "*A string of header lines to be inserted in outgoing mails."
1207 :group 'message-headers
1208 :group 'message-mail
1209 :link '(custom-manual "(message)Mail Headers")
1210 :type 'message-header-lines)
1212 (defcustom message-default-news-headers ""
1213 "*A string of header lines to be inserted in outgoing news articles."
1214 :group 'message-headers
1215 :group 'message-news
1216 :link '(custom-manual "(message)News Headers")
1217 :type 'message-header-lines)
1219 ;; Note: could use /usr/ucb/mail instead of sendmail;
1220 ;; options -t, and -v if not interactive.
1221 (defcustom message-mailer-swallows-blank-line
1222 (if (and (string-match "sparc-sun-sunos\\(\\'\\|[^5]\\)"
1223 system-configuration)
1224 (file-readable-p "/etc/sendmail.cf")
1225 (let ((buffer (get-buffer-create " *temp*")))
1227 (with-current-buffer buffer
1228 (insert-file-contents "/etc/sendmail.cf")
1229 (goto-char (point-min))
1230 (let ((case-fold-search nil))
1231 (re-search-forward "^OR\\>" nil t)))
1232 (kill-buffer buffer))))
1233 ;; According to RFC822, "The field-name must be composed of printable
1234 ;; ASCII characters (i. e., characters that have decimal values between
1235 ;; 33 and 126, except colon)", i. e., any chars except ctl chars,
1237 '(looking-at "[ \t]\\|[][!\"#$%&'()*+,-./0-9;<=>?@A-Z\\\\^_`a-z{|}~]+:"))
1238 "*Set this non-nil if the system's mailer runs the header and body together.
1239 \(This problem exists on Sunos 4 when sendmail is run in remote mode.)
1240 The value should be an expression to test whether the problem will
1242 :group 'message-sending
1243 :link '(custom-manual "(message)Mail Variables")
1247 (define-mail-user-agent 'message-user-agent
1248 'message-mail 'message-send-and-exit
1249 'message-kill-buffer 'message-send-hook)
1251 (defvar message-mh-deletable-headers '(Message-ID Date Lines Sender)
1252 "If non-nil, delete the deletable headers before feeding to mh.")
1254 (defvar message-send-method-alist
1255 '((news message-news-p message-send-via-news)
1256 (mail message-mail-p message-send-via-mail))
1257 "Alist of ways to send outgoing messages.
1258 Each element has the form
1260 \(TYPE PREDICATE FUNCTION)
1262 where TYPE is a symbol that names the method; PREDICATE is a function
1263 called without any parameters to determine whether the message is
1264 a message of type TYPE; and FUNCTION is a function to be called if
1265 PREDICATE returns non-nil. FUNCTION is called with one parameter --
1268 (defcustom message-mail-alias-type 'abbrev
1269 "*What alias expansion type to use in Message buffers.
1270 The default is `abbrev', which uses mailabbrev. `ecomplete' uses
1271 an electric completion mode. nil switches mail aliases off.
1272 This can also be a list of values."
1274 :link '(custom-manual "(message)Mail Aliases")
1275 :type '(choice (const :tag "Use Mailabbrev" abbrev)
1276 (const :tag "Use ecomplete" ecomplete)
1277 (const :tag "No expansion" nil)))
1279 (defcustom message-self-insert-commands '(self-insert-command)
1280 "List of `self-insert-command's used to trigger ecomplete.
1281 When one of those commands is invoked to enter a character in To or Cc
1282 header, ecomplete will suggest the candidates of recipients (see also
1283 `message-mail-alias-type'). If you use some tool to enter non-ASCII
1284 text and it replaces `self-insert-command' with the other command, e.g.
1285 `egg-self-insert-command', you may want to add it to this list."
1286 :group 'message-various
1287 :type '(repeat function))
1289 (defcustom message-auto-save-directory
1290 (file-name-as-directory (expand-file-name "drafts" message-directory))
1291 "*Directory where Message auto-saves buffers if Gnus isn't running.
1292 If nil, Message won't auto-save."
1293 :group 'message-buffers
1294 :link '(custom-manual "(message)Various Message Variables")
1295 :type '(choice directory (const :tag "Don't auto-save" nil)))
1297 (defcustom message-default-charset
1298 (and (not (mm-multibyte-p)) 'iso-8859-1)
1299 "Default charset used in non-MULE Emacsen.
1300 If nil, you might be asked to input the charset."
1303 :link '(custom-manual "(message)Various Message Variables")
1306 (defcustom message-dont-reply-to-names
1307 (and (boundp 'rmail-dont-reply-to-names) rmail-dont-reply-to-names)
1308 "*Addresses to prune when doing wide replies.
1309 This can be a regexp or a list of regexps. Also, a value of nil means
1310 exclude your own user name only."
1313 :link '(custom-manual "(message)Wide Reply")
1314 :type '(choice (const :tag "Yourself" nil)
1316 (repeat :tag "Regexp List" regexp)))
1318 (defsubst message-dont-reply-to-names ()
1319 (gmm-regexp-concat message-dont-reply-to-names))
1321 (defvar message-shoot-gnksa-feet nil
1322 "*A list of GNKSA feet you are allowed to shoot.
1323 Gnus gives you all the opportunity you could possibly want for
1324 shooting yourself in the foot. Also, Gnus allows you to shoot the
1325 feet of Good Net-Keeping Seal of Approval. The following are foot
1327 `empty-article' Allow you to post an empty article;
1328 `quoted-text-only' Allow you to post quoted text only;
1329 `multiple-copies' Allow you to post multiple copies;
1330 `cancel-messages' Allow you to cancel or supersede messages from
1331 your other email addresses.")
1333 (defsubst message-gnksa-enable-p (feature)
1334 (or (not (listp message-shoot-gnksa-feet))
1335 (memq feature message-shoot-gnksa-feet)))
1337 (defcustom message-hidden-headers '("^References:" "^Face:" "^X-Face:"
1339 "Regexp of headers to be hidden when composing new messages.
1340 This can also be a list of regexps to match headers. Or a list
1341 starting with `not' and followed by regexps."
1344 :link '(custom-manual "(message)Message Headers")
1346 :format "%{%t%}: %[Value Type%] %v"
1347 (regexp :menu-tag "regexp" :format "regexp\n%t: %v")
1348 (repeat :menu-tag "(regexp ...)" :format "(regexp ...)\n%v%i"
1349 (regexp :format "%t: %v"))
1350 (cons :menu-tag "(not regexp ...)" :format "(not regexp ...)\n%v"
1352 (repeat :format "%v%i"
1353 (regexp :format "%t: %v")))))
1355 (defcustom message-cite-articles-with-x-no-archive t
1356 "If non-nil, cite text from articles that has X-No-Archive set."
1360 ;;; Internal variables.
1361 ;;; Well, not really internal.
1363 (defvar message-mode-syntax-table
1364 (let ((table (copy-syntax-table text-mode-syntax-table)))
1365 (modify-syntax-entry ?% ". " table)
1366 (modify-syntax-entry ?> ". " table)
1367 (modify-syntax-entry ?< ". " table)
1369 "Syntax table used while in Message mode.")
1371 (defface message-header-to
1374 (:foreground "DarkOliveGreen1" :bold t))
1377 (:foreground "MidnightBlue" :bold t))
1379 (:bold t :italic t)))
1380 "Face used for displaying From headers."
1381 :group 'message-faces)
1382 ;; backward-compatibility alias
1383 (put 'message-header-to-face 'face-alias 'message-header-to)
1384 (put 'message-header-to-face 'obsolete-face "22.1")
1386 (defface message-header-cc
1389 (:foreground "chartreuse1" :bold t))
1392 (:foreground "MidnightBlue"))
1395 "Face used for displaying Cc headers."
1396 :group 'message-faces)
1397 ;; backward-compatibility alias
1398 (put 'message-header-cc-face 'face-alias 'message-header-cc)
1399 (put 'message-header-cc-face 'obsolete-face "22.1")
1401 (defface message-header-subject
1404 (:foreground "OliveDrab1"))
1407 (:foreground "navy blue" :bold t))
1410 "Face used for displaying subject headers."
1411 :group 'message-faces)
1412 ;; backward-compatibility alias
1413 (put 'message-header-subject-face 'face-alias 'message-header-subject)
1414 (put 'message-header-subject-face 'obsolete-face "22.1")
1416 (defface message-header-newsgroups
1419 (:foreground "yellow" :bold t :italic t))
1422 (:foreground "blue4" :bold t :italic t))
1424 (:bold t :italic t)))
1425 "Face used for displaying newsgroups headers."
1426 :group 'message-faces)
1427 ;; backward-compatibility alias
1428 (put 'message-header-newsgroups-face 'face-alias 'message-header-newsgroups)
1429 (put 'message-header-newsgroups-face 'obsolete-face "22.1")
1431 (defface message-header-other
1434 (:foreground "VioletRed1"))
1437 (:foreground "steel blue"))
1439 (:bold t :italic t)))
1440 "Face used for displaying newsgroups headers."
1441 :group 'message-faces)
1442 ;; backward-compatibility alias
1443 (put 'message-header-other-face 'face-alias 'message-header-other)
1444 (put 'message-header-other-face 'obsolete-face "22.1")
1446 (defface message-header-name
1449 (:foreground "green"))
1452 (:foreground "cornflower blue"))
1455 "Face used for displaying header names."
1456 :group 'message-faces)
1457 ;; backward-compatibility alias
1458 (put 'message-header-name-face 'face-alias 'message-header-name)
1459 (put 'message-header-name-face 'obsolete-face "22.1")
1461 (defface message-header-xheader
1464 (:foreground "DeepSkyBlue1"))
1467 (:foreground "blue"))
1470 "Face used for displaying X-Header headers."
1471 :group 'message-faces)
1472 ;; backward-compatibility alias
1473 (put 'message-header-xheader-face 'face-alias 'message-header-xheader)
1474 (put 'message-header-xheader-face 'obsolete-face "22.1")
1476 (defface message-separator
1479 (:foreground "LightSkyBlue1"))
1482 (:foreground "brown"))
1485 "Face used for displaying the separator."
1486 :group 'message-faces)
1487 ;; backward-compatibility alias
1488 (put 'message-separator-face 'face-alias 'message-separator)
1489 (put 'message-separator-face 'obsolete-face "22.1")
1491 (defface message-cited-text
1494 (:foreground "LightPink1"))
1497 (:foreground "red"))
1500 "Face used for displaying cited text names."
1501 :group 'message-faces)
1502 ;; backward-compatibility alias
1503 (put 'message-cited-text-face 'face-alias 'message-cited-text)
1504 (put 'message-cited-text-face 'obsolete-face "22.1")
1506 (defface message-mml
1509 (:foreground "MediumSpringGreen"))
1512 (:foreground "ForestGreen"))
1515 "Face used for displaying MML."
1516 :group 'message-faces)
1517 ;; backward-compatibility alias
1518 (put 'message-mml-face 'face-alias 'message-mml)
1519 (put 'message-mml-face 'obsolete-face "22.1")
1521 (defun message-font-lock-make-header-matcher (regexp)
1524 (let ((start (point)))
1527 (goto-char (point-min))
1528 (if (re-search-forward
1529 (concat "^" (regexp-quote mail-header-separator) "$")
1531 (setq limit (min limit (match-beginning 0))))
1533 (and (< start limit)
1534 (re-search-forward ,regexp limit t))))))
1535 (if (featurep 'bytecomp)
1539 (defvar message-font-lock-keywords
1540 (let ((content "[ \t]*\\(.+\\(\n[ \t].*\\)*\\)\n?"))
1541 `((,(message-font-lock-make-header-matcher
1542 (concat "^\\([Tt]o:\\)" content))
1543 (1 'message-header-name)
1544 (2 'message-header-to nil t))
1545 (,(message-font-lock-make-header-matcher
1546 (concat "^\\(^[GBF]?[Cc][Cc]:\\|^[Rr]eply-[Tt]o:\\)" content))
1547 (1 'message-header-name)
1548 (2 'message-header-cc nil t))
1549 (,(message-font-lock-make-header-matcher
1550 (concat "^\\([Ss]ubject:\\)" content))
1551 (1 'message-header-name)
1552 (2 'message-header-subject nil t))
1553 (,(message-font-lock-make-header-matcher
1554 (concat "^\\([Nn]ewsgroups:\\|Followup-[Tt]o:\\)" content))
1555 (1 'message-header-name)
1556 (2 'message-header-newsgroups nil t))
1557 (,(message-font-lock-make-header-matcher
1558 (concat "^\\(X-[A-Za-z0-9-]+:\\|In-Reply-To:\\)" content))
1559 (1 'message-header-name)
1560 (2 'message-header-xheader))
1561 (,(message-font-lock-make-header-matcher
1562 (concat "^\\([A-Z][^: \n\t]+:\\)" content))
1563 (1 'message-header-name)
1564 (2 'message-header-other nil t))
1565 ,@(if (and mail-header-separator
1566 (not (equal mail-header-separator "")))
1567 `((,(concat "^\\(" (regexp-quote mail-header-separator) "\\)$")
1568 1 'message-separator))
1571 (re-search-forward (concat "^\\("
1572 message-cite-prefix-regexp
1575 (0 'message-cited-text))
1576 ("<#/?\\(multipart\\|part\\|external\\|mml\\|secure\\)[^>]*>"
1578 "Additional expressions to highlight in Message mode.")
1581 ;; XEmacs does it like this. For Emacs, we have to set the
1582 ;; `font-lock-defaults' buffer-local variable.
1583 (put 'message-mode 'font-lock-defaults '(message-font-lock-keywords t))
1585 (defvar message-face-alist
1586 '((bold . message-bold-region)
1587 (underline . underline-region)
1588 (default . (lambda (b e)
1589 (message-unbold-region b e)
1590 (ununderline-region b e))))
1591 "Alist of mail and news faces for facemenu.
1592 The cdr of each entry is a function for applying the face to a region.")
1594 (defcustom message-send-hook nil
1595 "Hook run before sending messages.
1596 This hook is run quite early when sending."
1597 :group 'message-various
1598 :options '(ispell-message)
1599 :link '(custom-manual "(message)Various Message Variables")
1602 (defcustom message-send-mail-hook nil
1603 "Hook run before sending mail messages.
1604 This hook is run very late -- just before the message is sent as
1606 :group 'message-various
1607 :link '(custom-manual "(message)Various Message Variables")
1610 (defcustom message-send-news-hook nil
1611 "Hook run before sending news messages.
1612 This hook is run very late -- just before the message is sent as
1614 :group 'message-various
1615 :link '(custom-manual "(message)Various Message Variables")
1618 (defcustom message-sent-hook nil
1619 "Hook run after sending messages."
1620 :group 'message-various
1623 (defvar message-send-coding-system 'binary
1624 "Coding system to encode outgoing mail.")
1626 (defvar message-draft-coding-system
1627 mm-auto-save-coding-system
1628 "*Coding system to compose mail.
1629 If you'd like to make it possible to share draft files between XEmacs
1630 and Emacs, you may use `iso-2022-7bit' for this value at your own risk.
1631 Note that the coding-system `iso-2022-7bit' isn't suitable to all data.")
1633 (defcustom message-send-mail-partially-limit nil
1634 "The limitation of messages sent as message/partial.
1635 The lower bound of message size in characters, beyond which the message
1636 should be sent in several parts. If it is nil, the size is unlimited."
1638 :group 'message-buffers
1639 :link '(custom-manual "(message)Mail Variables")
1640 :type '(choice (const :tag "unlimited" nil)
1643 (defcustom message-alternative-emails nil
1644 "*Regexp matching alternative email addresses.
1645 The first address in the To, Cc or From headers of the original
1646 article matching this variable is used as the From field of
1649 This variable has precedence over posting styles and anything that runs
1650 off `message-setup-hook'."
1651 :group 'message-headers
1652 :link '(custom-manual "(message)Message Headers")
1653 :type '(choice (const :tag "Always use primary" nil)
1656 (defcustom message-hierarchical-addresses nil
1657 "A list of hierarchical mail address definitions.
1659 Inside each entry, the first address is the \"top\" address, and
1660 subsequent addresses are subaddresses; this is used to indicate that
1661 mail sent to the first address will automatically be delivered to the
1662 subaddresses. So if the first address appears in the recipient list
1663 for a message, the subaddresses will be removed (if present) before
1664 the mail is sent. All addresses in this structure should be
1667 :group 'message-headers
1668 :type '(repeat (repeat string)))
1670 (defcustom message-mail-user-agent nil
1671 "Like `mail-user-agent'.
1672 Except if it is nil, use Gnus native MUA; if it is t, use
1675 :type '(radio (const :tag "Gnus native"
1678 (const :tag "`mail-user-agent'"
1681 (function-item :tag "Default Emacs mail"
1683 sendmail-user-agent)
1684 (function-item :tag "Emacs interface to MH"
1687 (function :tag "Other"))
1691 (defcustom message-wide-reply-confirm-recipients nil
1692 "Whether to confirm a wide reply to multiple email recipients.
1693 If this variable is nil, don't ask whether to reply to all recipients.
1694 If this variable is non-nil, pose the question \"Reply to all
1695 recipients?\" before a wide reply to multiple recipients. If the user
1696 answers yes, reply to all recipients as usual. If the user answers
1697 no, only reply back to the author."
1699 :group 'message-headers
1700 :link '(custom-manual "(message)Wide Reply")
1703 (defcustom message-user-fqdn nil
1704 "*Domain part of Message-Ids."
1706 :group 'message-headers
1707 :link '(custom-manual "(message)News Headers")
1708 :type '(radio (const :format "%v " nil)
1709 (string :format "FQDN: %v")))
1711 (defcustom message-use-idna (and (condition-case nil (require 'idna)
1713 (mm-coding-system-p 'utf-8)
1714 (executable-find idna-program)
1715 (string= (idna-to-ascii "räksmörgås")
1716 "xn--rksmrgs-5wao1o")
1718 "Whether to encode non-ASCII in domain names into ASCII according to IDNA.
1719 GNU Libidn, and in particular the elisp package \"idna.el\" and
1720 the external program \"idn\", must be installed for this
1721 functionality to work."
1723 :group 'message-headers
1724 :link '(custom-manual "(message)IDNA")
1725 :type '(choice (const :tag "Ask" ask)
1726 (const :tag "Never" nil)
1727 (const :tag "Always" t)))
1729 (defcustom message-generate-hashcash (if (executable-find "hashcash") 'opportunistic)
1730 "*Whether to generate X-Hashcash: headers.
1731 If t, always generate hashcash headers. If `opportunistic',
1732 only generate hashcash headers if it can be done without the user
1733 waiting (i.e., only asynchronously).
1735 You must have the \"hashcash\" binary installed, see `hashcash-path'."
1737 :group 'message-headers
1738 :link '(custom-manual "(message)Mail Headers")
1739 :type '(choice (const :tag "Always" t)
1740 (const :tag "Never" nil)
1741 (const :tag "Opportunistic" opportunistic)))
1743 ;;; Internal variables.
1745 (defvar message-sending-message "Sending...")
1746 (defvar message-buffer-list nil)
1747 (defvar message-this-is-news nil)
1748 (defvar message-this-is-mail nil)
1749 (defvar message-draft-article nil)
1750 (defvar message-mime-part nil)
1751 (defvar message-posting-charset nil)
1752 (defvar message-inserted-headers nil)
1753 (defvar message-inhibit-ecomplete nil)
1755 ;; Byte-compiler warning
1756 (defvar gnus-active-hashtb)
1757 (defvar gnus-read-active-file)
1759 ;;; Regexp matching the delimiter of messages in UNIX mail format
1760 ;;; (UNIX From lines), minus the initial ^. It should be a copy
1761 ;;; of rmail.el's rmail-unix-mail-delimiter.
1762 (defvar message-unix-mail-delimiter
1763 (let ((time-zone-regexp
1764 (concat "\\([A-Z]?[A-Z]?[A-Z][A-Z]\\( DST\\)?"
1765 "\\|[-+]?[0-9][0-9][0-9][0-9]"
1771 ;; Many things can happen to an RFC 822 mailbox before it is put into
1772 ;; a `From' line. The leading phrase can be stripped, e.g.
1773 ;; `Joe <@w.x:joe@y.z>' -> `<@w.x:joe@y.z>'. The <> can be stripped, e.g.
1774 ;; `<@x.y:joe@y.z>' -> `@x.y:joe@y.z'. Everything starting with a CRLF
1775 ;; can be removed, e.g.
1776 ;; From: joe@y.z (Joe K
1778 ;; can yield `From joe@y.z (Joe K Fri Mar 22 08:11:15 1996', and
1781 ;; can yield `From Joe User Fri Mar 22 08:11:15 1996'.
1782 ;; The mailbox can be removed or be replaced by white space, e.g.
1783 ;; From: "Joe User"{space}{tab}
1785 ;; can yield `From {space}{tab} Fri Mar 22 08:11:15 1996',
1786 ;; where {space} and {tab} represent the Ascii space and tab characters.
1787 ;; We want to match the results of any of these manglings.
1788 ;; The following regexp rejects names whose first characters are
1789 ;; obviously bogus, but after that anything goes.
1790 "\\([^\0-\b\n-\r\^?].*\\)?"
1792 ;; The time the message was sent.
1793 "\\([^\0-\r \^?]+\\) +" ; day of the week
1794 "\\([^\0-\r \^?]+\\) +" ; month
1795 "\\([0-3]?[0-9]\\) +" ; day of month
1796 "\\([0-2][0-9]:[0-5][0-9]\\(:[0-6][0-9]\\)?\\) *" ; time of day
1798 ;; Perhaps a time zone, specified by an abbreviation, or by a
1803 " \\([0-9][0-9]+\\) *"
1805 ;; On some systems the time zone can appear after the year, too.
1809 "\\(remote from .*\\)?"
1812 "Regexp matching the delimiter of messages in UNIX mail format.")
1814 (defvar message-unsent-separator
1815 (concat "^ *---+ +Unsent message follows +---+ *$\\|"
1816 "^ *---+ +Returned message +---+ *$\\|"
1817 "^Start of returned message$\\|"
1818 "^ *---+ +Original message +---+ *$\\|"
1819 "^ *--+ +begin message +--+ *$\\|"
1820 "^ *---+ +Original message follows +---+ *$\\|"
1821 "^ *---+ +Undelivered message follows +---+ *$\\|"
1822 "^------ This is a copy of the message, including all the headers. ------ *$\\|"
1823 "^|? *---+ +Message text follows: +---+ *|?$")
1824 "A regexp that matches the separator before the text of a failed message.")
1826 (defvar message-field-fillers
1827 '((To message-fill-field-address)
1828 (Cc message-fill-field-address)
1829 (From message-fill-field-address))
1830 "Alist of header names/filler functions.")
1832 (defvar message-header-format-alist
1847 (References . message-shorten-references)
1849 "Alist used for formatting headers.")
1851 (defvar message-options nil
1852 "Some saved answers when sending message.")
1854 (defvar message-send-mail-real-function nil
1855 "Internal send mail function.")
1857 (defvar message-bogus-system-names "^localhost\\.\\|\\.local$"
1858 "The regexp of bogus system names.")
1860 (defcustom message-valid-fqdn-regexp
1861 (concat "[a-z0-9][-.a-z0-9]+\\." ;; [hostname.subdomain.]domain.
1863 "\\([a-z][a-z]\\|" ;; two letter country TDLs
1864 "aero\\|arpa\\|bitnet\\|biz\\|bofh\\|"
1865 "cat\\|com\\|coop\\|edu\\|gov\\|"
1866 "info\\|int\\|jobs\\|"
1867 "mil\\|mobi\\|museum\\|name\\|net\\|"
1868 "org\\|pro\\|travel\\|uucp\\)")
1869 ;; http://en.wikipedia.org/wiki/List_of_Internet_top-level_domains
1870 ;; http://en.wikipedia.org/wiki/GTLD
1871 ;; `in the process of being approved': .asia .post .tel .sex
1872 ;; "dead" nato bitnet uucp
1873 "Regular expression that matches a valid FQDN."
1874 ;; see also: gnus-button-valid-fqdn-regexp
1876 :group 'message-headers
1879 (autoload 'gnus-alive-p "gnus-util")
1880 (autoload 'gnus-delay-article "gnus-delay")
1881 (autoload 'gnus-extract-address-components "gnus-util")
1882 (autoload 'gnus-find-method-for-group "gnus")
1883 (autoload 'gnus-group-decoded-name "gnus-group")
1884 (autoload 'gnus-group-name-charset "gnus-group")
1885 (autoload 'gnus-group-name-decode "gnus-group")
1886 (autoload 'gnus-groups-from-server "gnus")
1887 (autoload 'gnus-make-local-hook "gnus-util")
1888 (autoload 'gnus-open-server "gnus-int")
1889 (autoload 'gnus-output-to-mail "gnus-util")
1890 (autoload 'gnus-output-to-rmail "gnus-util")
1891 (autoload 'gnus-request-post "gnus-int")
1892 (autoload 'gnus-select-frame-set-input-focus "gnus-util")
1893 (autoload 'gnus-server-string "gnus")
1894 (autoload 'idna-to-ascii "idna")
1895 (autoload 'message-setup-toolbar "messagexmas")
1896 (autoload 'mh-new-draft-name "mh-comp")
1897 (autoload 'mh-send-letter "mh-comp")
1898 (autoload 'nndraft-request-associate-buffer "nndraft")
1899 (autoload 'nndraft-request-expire-articles "nndraft")
1900 (autoload 'nnvirtual-find-group-art "nnvirtual")
1901 (autoload 'rmail-dont-reply-to "mail-utils")
1902 (autoload 'rmail-msg-is-pruned "rmail")
1903 (autoload 'rmail-output "rmailout")
1908 ;;; Utility functions.
1911 (defmacro message-y-or-n-p (question show &rest text)
1912 "Ask QUESTION, displaying remaining args in a temporary buffer if SHOW."
1913 `(message-talkative-question 'y-or-n-p ,question ,show ,@text))
1915 (defmacro message-delete-line (&optional n)
1916 "Delete the current line (and the next N lines)."
1917 `(delete-region (progn (beginning-of-line) (point))
1918 (progn (forward-line ,(or n 1)) (point))))
1920 (defun message-mark-active-p ()
1921 "Non-nil means the mark and region are currently active in this buffer."
1924 (defun message-unquote-tokens (elems)
1925 "Remove double quotes (\") from strings in list ELEMS."
1926 (mapcar (lambda (item)
1927 (while (string-match "^\\(.*\\)\"\\(.*\\)$" item)
1928 (setq item (concat (match-string 1 item)
1929 (match-string 2 item))))
1933 (defun message-tokenize-header (header &optional separator)
1934 "Split HEADER into a list of header elements.
1935 SEPARATOR is a string of characters to be used as separators. \",\"
1936 is used by default."
1939 (let ((regexp (format "[%s]+" (or separator ",")))
1941 beg quoted elems paren)
1943 (mm-enable-multibyte)
1944 (setq beg (point-min))
1946 (goto-char (point-min))
1951 (cond ((and (> (point) beg)
1953 (and (looking-at regexp)
1956 (push (buffer-substring beg (point)) elems)
1957 (setq beg (match-end 0)))
1958 ((eq (char-after) ?\")
1959 (setq quoted (not quoted)))
1960 ((and (eq (char-after) ?\()
1963 ((and (eq (char-after) ?\))
1966 (nreverse elems)))))
1968 (autoload 'nnheader-insert-file-contents "nnheader")
1970 (defun message-mail-file-mbox-p (file)
1971 "Say whether FILE looks like a Unix mbox file."
1972 (when (and (file-exists-p file)
1973 (file-readable-p file)
1974 (file-regular-p file))
1976 (nnheader-insert-file-contents file)
1977 (goto-char (point-min))
1978 (looking-at message-unix-mail-delimiter))))
1980 (defun message-fetch-field (header &optional not-all)
1981 "The same as `mail-fetch-field', only remove all newlines.
1982 The buffer is expected to be narrowed to just the header of the message;
1983 see `message-narrow-to-headers-or-head'."
1984 (let* ((inhibit-point-motion-hooks t)
1985 (value (mail-fetch-field header nil (not not-all))))
1987 (while (string-match "\n[\t ]+" value)
1988 (setq value (replace-match " " t t value)))
1991 (defun message-field-value (header &optional not-all)
1992 "The same as `message-fetch-field', only narrow to the headers first."
1995 (message-narrow-to-headers-or-head)
1996 (message-fetch-field header not-all))))
1998 (defun message-narrow-to-field ()
1999 "Narrow the buffer to the header on the current line."
2001 (while (looking-at "[ \t]")
2007 (if (re-search-forward "^[^ \n\t]" nil t)
2010 (goto-char (point-min)))
2012 (defun message-add-header (&rest headers)
2013 "Add the HEADERS to the message header, skipping those already present."
2016 (unless (string-match "^\\([^:]+\\):[ \t]*[^ \t]" (car headers))
2017 (error "Invalid header `%s'" (car headers)))
2018 (setq hclean (match-string 1 (car headers)))
2020 (message-narrow-to-headers)
2021 (unless (re-search-forward (concat "^" (regexp-quote hclean) ":") nil t)
2022 (goto-char (point-max))
2023 (if (string-match "\n$" (car headers))
2024 (insert (car headers))
2025 (insert (car headers) ?\n)))))
2026 (setq headers (cdr headers))))
2028 (defmacro message-with-reply-buffer (&rest forms)
2029 "Evaluate FORMS in the reply buffer, if it exists."
2030 `(when (and (bufferp message-reply-buffer)
2031 (buffer-name message-reply-buffer))
2032 (with-current-buffer message-reply-buffer
2035 (put 'message-with-reply-buffer 'lisp-indent-function 0)
2036 (put 'message-with-reply-buffer 'edebug-form-spec '(body))
2038 (defun message-fetch-reply-field (header)
2039 "Fetch field HEADER from the message we're replying to."
2040 (message-with-reply-buffer
2042 (mail-narrow-to-head)
2043 (message-fetch-field header))))
2045 (defun message-strip-list-identifiers (subject)
2046 "Remove list identifiers in `gnus-list-identifiers' from string SUBJECT."
2047 (require 'gnus-sum) ; for gnus-list-identifiers
2048 (let ((regexp (if (stringp gnus-list-identifiers)
2049 gnus-list-identifiers
2050 (mapconcat 'identity gnus-list-identifiers " *\\|"))))
2051 (if (string-match (concat "\\(\\(\\(Re: +\\)?\\(" regexp
2052 " *\\)\\)+\\(Re: +\\)?\\)") subject)
2053 (concat (substring subject 0 (match-beginning 1))
2054 (or (match-string 3 subject)
2055 (match-string 5 subject))
2060 (defun message-strip-subject-re (subject)
2061 "Remove \"Re:\" from subject lines in string SUBJECT."
2062 (if (string-match message-subject-re-regexp subject)
2063 (substring subject (match-end 0))
2066 (defcustom message-replacement-char "."
2067 "Replacement character used instead of unprintable or not decodable chars."
2068 :group 'message-various
2069 :version "22.1" ;; Gnus 5.10.9
2070 :type '(choice string
2074 ;; FIXME: We also should call `message-strip-subject-encoded-words'
2075 ;; when forwarding. Probably in `message-make-forward-subject' and
2076 ;; `message-forward-make-body'.
2078 (defun message-strip-subject-encoded-words (subject)
2079 "Fix non-decodable words in SUBJECT."
2080 ;; Cf. `gnus-simplify-subject-fully'.
2081 (let* ((case-fold-search t)
2082 (replacement-chars (format "[%s%s%s]"
2083 message-replacement-char
2084 message-replacement-char
2085 message-replacement-char))
2086 (enc-word-re "=\\?\\([^?]+\\)\\?\\([QB]\\)\\?\\([^?]+\\)\\(\\?=\\)")
2091 (goto-char (point-min))
2092 (when (re-search-forward enc-word-re nil t)
2093 (setq cs-string (match-string 1)))))
2094 cs-coding q-or-b word-beg word-end)
2095 (if (or (not have-marker) ;; No encoded word found...
2096 ;; ... or double encoding was correct:
2097 (and (stringp cs-string)
2098 (setq cs-string (downcase cs-string))
2099 (mm-coding-system-p (intern cs-string))
2103 Decoded Subject \"%s\"
2104 contains a valid encoded word. Decode again? "
2106 (setq cs-coding (intern cs-string))))))
2110 (goto-char (point-min))
2111 (while (re-search-forward enc-word-re nil t)
2112 (setq cs-string (downcase (match-string 1))
2113 q-or-b (match-string 2)
2114 word-beg (match-beginning 0)
2115 word-end (match-end 0))
2117 (if (mm-coding-system-p (intern cs-string))
2118 (setq cs-coding (intern cs-string))
2120 ;; No double encoded subject? => bogus charset.
2123 (mm-read-coding-system
2125 Decoded Subject \"%s\"
2126 contains an encoded word. The charset `%s' is unknown or invalid.
2127 Hit RET to replace non-decodable characters with \"%s\" or enter replacement
2129 subject cs-string message-replacement-char)))
2131 (replace-match (concat "=?" (symbol-name cs-coding)
2134 (goto-char word-beg)
2135 (re-search-forward "=\\?\\([^?]+\\)\\?\\([QB]\\)\\?" word-end t)
2138 (if (string-match "\\`Q\\'" q-or-b)
2141 (message "Replacing non-decodable characters with \"%s\"."
2142 message-replacement-char)
2143 (while (re-search-forward "\\(=[A-F0-9][A-F0-9]\\)+"
2145 (replace-match message-replacement-char)))
2147 (message "Replacing non-decodable characters with \"%s\"."
2149 (re-search-forward "[^?]+" word-end t)
2150 (replace-match replacement-chars))
2151 (re-search-forward "\\?=")
2152 (replace-match "")))))
2153 (rfc2047-decode-region (point-min) (point-max))
2156 ;;; Start of functions adopted from `message-utils.el'.
2158 (defun message-strip-subject-trailing-was (subject)
2159 "Remove trailing \"(was: <old subject>)\" from SUBJECT lines.
2160 Leading \"Re: \" is not stripped by this function. Use the function
2161 `message-strip-subject-re' for this."
2162 (let* ((query message-subject-trailing-was-query)
2167 message-subject-trailing-was-ask-regexp
2168 message-subject-trailing-was-regexp)
2171 (setq new (substring subject 0 (match-beginning 0))))
2172 (if (or (not found) (eq query nil))
2175 (if (message-y-or-n-p
2176 "Strip `(was: <old subject>)' in subject? " t
2178 "Strip `(was: <old subject>)' in subject "
2179 "and use the new one instead?\n\n"
2180 "Current subject is: \""
2182 "New subject would be: \""
2184 "See the variable `message-subject-trailing-was-query' "
2185 "to get rid of this query."
2190 ;;; Suggested by Jonas Steverud @ www.dtek.chalmers.se/~d4jonas/
2192 (defun message-change-subject (new-subject)
2193 "Ask for NEW-SUBJECT header, append (was: <Old Subject>)."
2194 ;; <URL:http://www.landfield.com/usefor/drafts/draft-ietf-usefor-useage--1.02.unpaged>
2197 (read-from-minibuffer "New subject: ")))
2198 (cond ((and (not (or (null new-subject) ; new subject not empty
2199 (zerop (string-width new-subject))
2200 (string-match "^[ \t]*$" new-subject))))
2204 (message-narrow-to-headers)
2205 (message-fetch-field "Subject"))))
2206 (cond ((not old-subject)
2207 (error "No current subject"))
2210 (regexp-quote new-subject)
2212 old-subject)) ; yes, it really is a new subject
2213 ;; delete eventual Re: prefix
2215 (message-strip-subject-re old-subject))
2216 (message-goto-subject)
2217 (message-delete-line)
2218 (insert (concat "Subject: "
2221 old-subject ")\n")))))))))
2223 (defun message-mark-inserted-region (beg end &optional verbatim)
2224 "Mark some region in the current article with enclosing tags.
2225 See `message-mark-insert-begin' and `message-mark-insert-end'.
2226 If VERBATIM, use slrn style verbatim marks (\"#v+\" and \"#v-\")."
2227 (interactive "r\nP")
2229 ;; add to the end of the region first, otherwise end would be invalid
2231 (insert (if verbatim "#v-\n" message-mark-insert-end))
2233 (insert (if verbatim "#v+\n" message-mark-insert-begin))))
2235 (defun message-mark-insert-file (file &optional verbatim)
2236 "Insert FILE at point, marking it with enclosing tags.
2237 See `message-mark-insert-begin' and `message-mark-insert-end'.
2238 If VERBATIM, use slrn style verbatim marks (\"#v+\" and \"#v-\")."
2239 (interactive "fFile to insert: \nP")
2240 ;; reverse insertion to get correct result.
2242 (insert (if verbatim "#v-\n" message-mark-insert-end))
2244 (insert-file-contents file)
2246 (insert (if verbatim "#v+\n" message-mark-insert-begin))))
2248 (defun message-add-archive-header ()
2249 "Insert \"X-No-Archive: Yes\" in the header and a note in the body.
2250 The note can be customized using `message-archive-note'. When called with a
2251 prefix argument, ask for a text to insert. If you don't want the note in the
2252 body, set `message-archive-note' to nil."
2254 (if current-prefix-arg
2255 (setq message-archive-note
2256 (read-from-minibuffer "Reason for No-Archive: "
2257 (cons message-archive-note 0))))
2259 (if (message-goto-signature)
2260 (re-search-backward message-signature-separator))
2261 (when message-archive-note
2262 (insert message-archive-note)
2264 (message-add-header message-archive-header)
2265 (message-sort-headers)))
2267 (defun message-cross-post-followup-to-header (target-group)
2268 "Mangles FollowUp-To and Newsgroups header to point to TARGET-GROUP.
2269 With prefix-argument just set Follow-Up, don't cross-post."
2271 (list ; Completion based on Gnus
2272 (completing-read "Followup To: "
2273 (if (boundp 'gnus-newsrc-alist)
2275 nil nil '("poster" . 0)
2276 (if (boundp 'gnus-group-history)
2277 'gnus-group-history))))
2278 (message-remove-header "Follow[Uu]p-[Tt]o" t)
2279 (message-goto-newsgroups)
2281 ;; if we already did a crosspost before, kill old target
2282 (if (and message-cross-post-old-target
2284 (regexp-quote (concat "," message-cross-post-old-target))
2287 ;; unless (followup is to poster or user explicitly asked not
2288 ;; to cross-post, or target-group is already in Newsgroups)
2289 ;; add target-group to Newsgroups line.
2291 ;; def: cross-post, req:no
2292 (and message-cross-post-default (not current-prefix-arg))
2293 ;; def: no-cross-post, req:yes
2294 (and (not message-cross-post-default) current-prefix-arg))
2295 (not (string-match "poster" target-group))
2296 (not (string-match (regexp-quote target-group)
2297 (message-fetch-field "Newsgroups"))))
2299 (insert (concat "," target-group))))
2300 (end-of-line) ; ensure Followup: comes after Newsgroups:
2301 ;; unless new followup would be identical to Newsgroups line
2302 ;; make a new Followup-To line
2303 (if (not (string-match (concat "^[ \t]*"
2306 (message-fetch-field "Newsgroups")))
2307 (insert (concat "\nFollowup-To: " target-group)))
2308 (setq message-cross-post-old-target target-group))
2310 (defun message-cross-post-insert-note (target-group cross-post in-old
2312 "Insert a in message body note about a set Followup or Crosspost.
2313 If there have been previous notes, delete them. TARGET-GROUP specifies the
2314 group to Followup-To. When CROSS-POST is t, insert note about
2315 crossposting. IN-OLD specifies whether TARGET-GROUP is a member of
2316 OLD-GROUPS. OLD-GROUPS lists the old-groups the posting would have
2317 been made to before the user asked for a Crosspost."
2318 ;; start scanning body for previous uses
2319 (message-goto-signature)
2320 (let ((head (re-search-backward
2321 (concat "^" mail-header-separator)
2322 nil t))) ; just search in body
2323 (message-goto-signature)
2324 (while (re-search-backward
2325 (concat "^" (regexp-quote message-cross-post-note) ".*")
2327 (message-delete-line))
2328 (message-goto-signature)
2329 (while (re-search-backward
2330 (concat "^" (regexp-quote message-followup-to-note) ".*")
2332 (message-delete-line))
2334 (if (message-goto-signature)
2335 (re-search-backward message-signature-separator))
2338 (string-match "^[ \t]*poster[ \t]*$" target-group))
2339 (insert (concat message-followup-to-note target-group "\n"))
2340 (insert (concat message-cross-post-note target-group "\n")))))
2342 (defun message-cross-post-followup-to (target-group)
2343 "Crossposts message and set Followup-To to TARGET-GROUP.
2344 With prefix-argument just set Follow-Up, don't cross-post."
2346 (list ; Completion based on Gnus
2347 (completing-read "Followup To: "
2348 (if (boundp 'gnus-newsrc-alist)
2350 nil nil '("poster" . 0)
2351 (if (boundp 'gnus-group-history)
2352 'gnus-group-history))))
2353 (cond ((not (or (null target-group) ; new subject not empty
2354 (zerop (string-width target-group))
2355 (string-match "^[ \t]*$" target-group)))
2357 (let* ((old-groups (message-fetch-field "Newsgroups"))
2358 (in-old (string-match
2359 (regexp-quote target-group)
2360 (or old-groups ""))))
2361 ;; check whether target exactly matches old Newsgroups
2362 (cond ((not old-groups)
2363 (error "No current newsgroup"))
2367 (regexp-quote target-group)
2370 ;; yes, Newsgroups line must change
2371 (message-cross-post-followup-to-header target-group)
2372 ;; insert note whether we do cross-post or followup-to
2373 (funcall message-cross-post-note-function
2375 (if (or (and message-cross-post-default
2376 (not current-prefix-arg))
2377 (and (not message-cross-post-default)
2378 current-prefix-arg)) t)
2379 in-old old-groups))))))))
2381 ;;; Reduce To: to Cc: or Bcc: header
2383 (defun message-reduce-to-to-cc ()
2384 "Replace contents of To: header with contents of Cc: or Bcc: header."
2387 (save-restriction (message-narrow-to-headers)
2388 (message-fetch-field "cc")))
2390 (if (and (not cc-content)
2393 (message-narrow-to-headers)
2394 (message-fetch-field "bcc"))))
2399 (message-delete-line)
2400 (insert (concat "To: " cc-content "\n"))
2402 (message-narrow-to-headers)
2403 (message-remove-header (if bcc
2407 ;;; End of functions adopted from `message-utils.el'.
2409 (defun message-remove-header (header &optional is-regexp first reverse)
2410 "Remove HEADER in the narrowed buffer.
2411 If IS-REGEXP, HEADER is a regular expression.
2412 If FIRST, only remove the first instance of the header.
2413 Return the number of headers removed."
2414 (goto-char (point-min))
2415 (let ((regexp (if is-regexp header (concat "^" (regexp-quote header) ":")))
2417 (case-fold-search t)
2419 (while (and (not (eobp))
2422 (not (looking-at regexp))
2423 (looking-at regexp))
2430 ;; There might be a continuation header, so we have to search
2431 ;; until we find a new non-continuation line.
2434 (if (re-search-forward "^[^ \t]" nil t)
2435 (goto-char (match-beginning 0))
2438 (if (re-search-forward "^[^ \t]" nil t)
2439 (goto-char (match-beginning 0))
2440 (goto-char (point-max)))))
2443 (defun message-remove-first-header (header)
2444 "Remove the first instance of HEADER if there is more than one."
2446 (regexp (concat "^" (regexp-quote header) ":")))
2448 (goto-char (point-min))
2449 (while (re-search-forward regexp nil t)
2452 (message-remove-header header nil t)
2455 (defun message-narrow-to-headers ()
2456 "Narrow the buffer to the head of the message."
2459 (goto-char (point-min))
2460 (if (re-search-forward
2461 (concat "^" (regexp-quote mail-header-separator) "\n") nil t)
2464 (goto-char (point-min)))
2466 (defun message-narrow-to-head-1 ()
2467 "Like `message-narrow-to-head'. Don't widen."
2469 (goto-char (point-min))
2470 (if (search-forward "\n\n" nil 1)
2473 (goto-char (point-min)))
2475 ;; FIXME: clarify diffference: message-narrow-to-head,
2476 ;; message-narrow-to-headers-or-head, message-narrow-to-headers
2477 (defun message-narrow-to-head ()
2478 "Narrow the buffer to the head of the message.
2479 Point is left at the beginning of the narrowed-to region."
2481 (message-narrow-to-head-1))
2483 (defun message-narrow-to-headers-or-head ()
2484 "Narrow the buffer to the head of the message."
2487 (goto-char (point-min))
2488 (if (re-search-forward (concat "\\(\n\\)\n\\|^\\("
2489 (regexp-quote mail-header-separator)
2492 (or (match-end 1) (match-beginning 2))
2494 (goto-char (point-min)))
2496 (defun message-news-p ()
2497 "Say whether the current buffer contains a news message."
2498 (and (not message-this-is-mail)
2499 (or message-this-is-news
2502 (message-narrow-to-headers)
2503 (and (message-fetch-field "newsgroups")
2504 (not (message-fetch-field "posted-to"))))))))
2506 (defun message-mail-p ()
2507 "Say whether the current buffer contains a mail message."
2508 (and (not message-this-is-news)
2509 (or message-this-is-mail
2512 (message-narrow-to-headers)
2513 (or (message-fetch-field "to")
2514 (message-fetch-field "cc")
2515 (message-fetch-field "bcc")))))))
2517 (defun message-subscribed-p ()
2518 "Say whether we need to insert a MFT header."
2519 (or message-subscribed-regexps
2520 message-subscribed-addresses
2521 message-subscribed-address-file
2522 message-subscribed-address-functions))
2524 (defun message-next-header ()
2525 "Go to the beginning of the next header."
2527 (or (eobp) (forward-char 1))
2528 (not (if (re-search-forward "^[^ \t]" nil t)
2530 (goto-char (point-max)))))
2532 (defun message-sort-headers-1 ()
2533 "Sort the buffer as headers using `message-rank' text props."
2534 (goto-char (point-min))
2537 nil 'message-next-header
2539 (message-next-header)
2543 (or (get-text-property (point) 'message-rank)
2546 (defun message-sort-headers ()
2547 "Sort the headers of the current message according to `message-header-format-alist'."
2551 (let ((max (1+ (length message-header-format-alist)))
2553 (message-narrow-to-headers)
2554 (while (re-search-forward "^[^ \n]+:" nil t)
2556 (match-beginning 0) (1+ (match-beginning 0))
2558 (if (setq rank (length (memq (assq (intern (buffer-substring
2560 (1- (match-end 0))))
2561 message-header-format-alist)
2562 message-header-format-alist)))
2565 (message-sort-headers-1))))
2567 (defun message-kill-address ()
2568 "Kill the address under point."
2570 (let ((start (point)))
2571 (message-skip-to-next-address)
2572 (kill-region start (point))))
2575 (autoload 'Info-goto-node "info")
2576 (defvar mml2015-use)
2578 (defun message-info (&optional arg)
2579 "Display the Message manual.
2581 Prefixed with one \\[universal-argument], display the Emacs MIME
2582 manual. With two \\[universal-argument]'s, display the EasyPG or
2583 PGG manual, depending on the value of `mml2015-use'."
2585 ;; Don't use `info' because support for `(filename)nodename' is not
2586 ;; available in XEmacs < 21.5.12.
2587 (Info-goto-node (format "(%s)Top"
2591 ((eq arg 4) 'emacs-mime)
2592 ;; `booleanp' only available in Emacs 22+
2593 ((and (not (memq arg '(nil t)))
2607 (defvar message-mode-map nil)
2609 (unless message-mode-map
2610 (setq message-mode-map (make-keymap))
2611 (set-keymap-parent message-mode-map text-mode-map)
2612 (define-key message-mode-map "\C-c?" 'describe-mode)
2614 (define-key message-mode-map "\C-c\C-f\C-t" 'message-goto-to)
2615 (define-key message-mode-map "\C-c\C-f\C-o" 'message-goto-from)
2616 (define-key message-mode-map "\C-c\C-f\C-b" 'message-goto-bcc)
2617 (define-key message-mode-map "\C-c\C-f\C-w" 'message-goto-fcc)
2618 (define-key message-mode-map "\C-c\C-f\C-c" 'message-goto-cc)
2619 (define-key message-mode-map "\C-c\C-f\C-s" 'message-goto-subject)
2620 (define-key message-mode-map "\C-c\C-f\C-r" 'message-goto-reply-to)
2621 (define-key message-mode-map "\C-c\C-f\C-n" 'message-goto-newsgroups)
2622 (define-key message-mode-map "\C-c\C-f\C-d" 'message-goto-distribution)
2623 (define-key message-mode-map "\C-c\C-f\C-f" 'message-goto-followup-to)
2624 (define-key message-mode-map "\C-c\C-f\C-m" 'message-goto-mail-followup-to)
2625 (define-key message-mode-map "\C-c\C-f\C-k" 'message-goto-keywords)
2626 (define-key message-mode-map "\C-c\C-f\C-u" 'message-goto-summary)
2627 (define-key message-mode-map "\C-c\C-f\C-i"
2628 'message-insert-or-toggle-importance)
2629 (define-key message-mode-map "\C-c\C-f\C-a"
2630 'message-generate-unsubscribed-mail-followup-to)
2632 ;; modify headers (and insert notes in body)
2633 (define-key message-mode-map "\C-c\C-fs" 'message-change-subject)
2635 (define-key message-mode-map "\C-c\C-fx" 'message-cross-post-followup-to)
2636 ;; prefix+message-cross-post-followup-to = same w/o cross-post
2637 (define-key message-mode-map "\C-c\C-ft" 'message-reduce-to-to-cc)
2638 (define-key message-mode-map "\C-c\C-fa" 'message-add-archive-header)
2639 ;; mark inserted text
2640 (define-key message-mode-map "\C-c\M-m" 'message-mark-inserted-region)
2641 (define-key message-mode-map "\C-c\M-f" 'message-mark-insert-file)
2643 (define-key message-mode-map "\C-c\C-b" 'message-goto-body)
2644 (define-key message-mode-map "\C-c\C-i" 'message-goto-signature)
2646 (define-key message-mode-map "\C-c\C-t" 'message-insert-to)
2647 (define-key message-mode-map "\C-c\C-fw" 'message-insert-wide-reply)
2648 (define-key message-mode-map "\C-c\C-n" 'message-insert-newsgroups)
2649 (define-key message-mode-map "\C-c\C-l" 'message-to-list-only)
2650 (define-key message-mode-map "\C-c\C-f\C-e" 'message-insert-expires)
2652 (define-key message-mode-map "\C-c\C-u" 'message-insert-or-toggle-importance)
2653 (define-key message-mode-map "\C-c\M-n"
2654 'message-insert-disposition-notification-to)
2656 (define-key message-mode-map "\C-c\C-y" 'message-yank-original)
2657 (define-key message-mode-map "\C-c\M-\C-y" 'message-yank-buffer)
2658 (define-key message-mode-map "\C-c\C-q" 'message-fill-yanked-message)
2659 (define-key message-mode-map "\C-c\C-w" 'message-insert-signature)
2660 (define-key message-mode-map "\C-c\M-h" 'message-insert-headers)
2661 (define-key message-mode-map "\C-c\C-r" 'message-caesar-buffer-body)
2662 (define-key message-mode-map "\C-c\C-o" 'message-sort-headers)
2663 (define-key message-mode-map "\C-c\M-r" 'message-rename-buffer)
2665 (define-key message-mode-map "\C-c\C-c" 'message-send-and-exit)
2666 (define-key message-mode-map "\C-c\C-s" 'message-send)
2667 (define-key message-mode-map "\C-c\C-k" 'message-kill-buffer)
2668 (define-key message-mode-map "\C-c\C-d" 'message-dont-send)
2669 (define-key message-mode-map "\C-c\n" 'gnus-delay-article)
2671 (define-key message-mode-map "\C-c\M-k" 'message-kill-address)
2672 (define-key message-mode-map "\C-c\C-e" 'message-elide-region)
2673 (define-key message-mode-map "\C-c\C-v" 'message-delete-not-region)
2674 (define-key message-mode-map "\C-c\C-z" 'message-kill-to-signature)
2675 (define-key message-mode-map "\M-\r" 'message-newline-and-reformat)
2676 (define-key message-mode-map [remap split-line] 'message-split-line)
2678 (define-key message-mode-map "\C-c\C-a" 'mml-attach-file)
2680 (define-key message-mode-map "\C-a" 'message-beginning-of-line)
2681 (define-key message-mode-map "\t" 'message-tab)
2682 (define-key message-mode-map "\M-;" 'comment-region)
2684 (define-key message-mode-map "\M-n" 'message-display-abbrev))
2687 message-mode-menu message-mode-map "Message Menu."
2689 ["Yank Original" message-yank-original message-reply-buffer]
2690 ["Fill Yanked Message" message-fill-yanked-message t]
2691 ["Insert Signature" message-insert-signature t]
2692 ["Caesar (rot13) Message" message-caesar-buffer-body t]
2693 ["Caesar (rot13) Region" message-caesar-region (message-mark-active-p)]
2694 ["Elide Region" message-elide-region
2695 :active (message-mark-active-p)
2696 ,@(if (featurep 'xemacs) nil
2697 '(:help "Replace text in region with an ellipsis"))]
2698 ["Delete Outside Region" message-delete-not-region
2699 :active (message-mark-active-p)
2700 ,@(if (featurep 'xemacs) nil
2701 '(:help "Delete all quoted text outside region"))]
2702 ["Kill To Signature" message-kill-to-signature t]
2703 ["Newline and Reformat" message-newline-and-reformat t]
2704 ["Rename buffer" message-rename-buffer t]
2705 ["Spellcheck" ispell-message
2706 ,@(if (featurep 'xemacs) '(t)
2707 '(:help "Spellcheck this message"))]
2709 ["Insert Region Marked" message-mark-inserted-region
2710 :active (message-mark-active-p)
2711 ,@(if (featurep 'xemacs) nil
2712 '(:help "Mark region with enclosing tags"))]
2713 ["Insert File Marked..." message-mark-insert-file
2714 ,@(if (featurep 'xemacs) '(t)
2715 '(:help "Insert file at point marked with enclosing tags"))]
2717 ["Send Message" message-send-and-exit
2718 ,@(if (featurep 'xemacs) '(t)
2719 '(:help "Send this message"))]
2720 ["Postpone Message" message-dont-send
2721 ,@(if (featurep 'xemacs) '(t)
2722 '(:help "File this draft message and exit"))]
2723 ["Send at Specific Time..." gnus-delay-article
2724 ,@(if (featurep 'xemacs) '(t)
2725 '(:help "Ask, then arrange to send message at that time"))]
2726 ["Kill Message" message-kill-buffer
2727 ,@(if (featurep 'xemacs) '(t)
2728 '(:help "Delete this message without sending"))]
2730 ["Message manual" message-info
2731 ,@(if (featurep 'xemacs) '(t)
2732 '(:help "Display the Message manual"))]))
2735 message-mode-field-menu message-mode-map ""
2737 ["To" message-goto-to t]
2738 ["From" message-goto-from t]
2739 ["Subject" message-goto-subject t]
2740 ["Change subject..." message-change-subject t]
2741 ["Cc" message-goto-cc t]
2742 ["Bcc" message-goto-bcc t]
2743 ["Fcc" message-goto-fcc t]
2744 ["Reply-To" message-goto-reply-to t]
2745 ["Flag As Important" message-insert-importance-high
2746 ,@(if (featurep 'xemacs) '(t)
2747 '(:help "Mark this message as important"))]
2748 ["Flag As Unimportant" message-insert-importance-low
2749 ,@(if (featurep 'xemacs) '(t)
2750 '(:help "Mark this message as unimportant"))]
2752 message-insert-disposition-notification-to
2753 ,@(if (featurep 'xemacs) '(t)
2754 '(:help "Request a receipt notification"))]
2756 ;; (typical) news stuff
2757 ["Summary" message-goto-summary t]
2758 ["Keywords" message-goto-keywords t]
2759 ["Newsgroups" message-goto-newsgroups t]
2760 ["Fetch Newsgroups" message-insert-newsgroups t]
2761 ["Followup-To" message-goto-followup-to t]
2762 ;; ["Followup-To (with note in body)" message-cross-post-followup-to t]
2763 ["Crosspost / Followup-To..." message-cross-post-followup-to t]
2764 ["Distribution" message-goto-distribution t]
2765 ["Expires" message-insert-expires t ]
2766 ["X-No-Archive" message-add-archive-header t ]
2768 ;; (typical) mailing-lists stuff
2769 ["Fetch To" message-insert-to
2770 ,@(if (featurep 'xemacs) '(t)
2771 '(:help "Insert a To header that points to the author."))]
2772 ["Fetch To and Cc" message-insert-wide-reply
2773 ,@(if (featurep 'xemacs) '(t)
2775 "Insert To and Cc headers as if you were doing a wide reply."))]
2777 ["Send to list only" message-to-list-only t]
2778 ["Mail-Followup-To" message-goto-mail-followup-to t]
2779 ["Unsubscribed list post" message-generate-unsubscribed-mail-followup-to
2780 ,@(if (featurep 'xemacs) '(t)
2781 '(:help "Insert a reasonable `Mail-Followup-To:' header."))]
2782 ["Reduce To: to Cc:" message-reduce-to-to-cc t]
2784 ["Sort Headers" message-sort-headers t]
2785 ["Encode non-ASCII domain names" message-idna-to-ascii-rhs t]
2786 ;; We hide `message-hidden-headers' by narrowing the buffer.
2787 ["Show Hidden Headers" widen t]
2788 ["Goto Body" message-goto-body t]
2789 ["Goto Signature" message-goto-signature t]))
2791 (defvar message-tool-bar-map nil)
2793 (defvar facemenu-add-face-function)
2794 (defvar facemenu-remove-face-function)
2796 ;;; Forbidden properties
2798 ;; We use `after-change-functions' to keep special text properties
2799 ;; that interfere with the normal function of message mode out of the
2802 (defcustom message-strip-special-text-properties t
2803 "Strip special properties from the message buffer.
2805 Emacs has a number of special text properties which can break message
2806 composing in various ways. If this option is set, message will strip
2807 these properties from the message composition buffer. However, some
2808 packages requires these properties to be present in order to work.
2809 If you use one of these packages, turn this option off, and hope the
2810 message composition doesn't break too bad."
2812 :group 'message-various
2813 :link '(custom-manual "(message)Various Message Variables")
2816 (defconst message-forbidden-properties
2817 ;; No reason this should be clutter up customize. We make it a
2818 ;; property list (rather than a list of property symbols), to be
2819 ;; directly useful for `remove-text-properties'.
2820 '(field nil read-only nil invisible nil intangible nil
2821 mouse-face nil modification-hooks nil insert-in-front-hooks nil
2822 insert-behind-hooks nil point-entered nil point-left nil)
2823 ;; Other special properties:
2824 ;; category, face, display: probably doesn't do any harm.
2825 ;; fontified: is used by font-lock.
2826 ;; syntax-table, local-map: I dunno.
2827 ;; We need to add XEmacs names to the list.
2828 "Property list of with properties forbidden in message buffers.
2829 The values of the properties are ignored, only the property names are used.")
2831 (defun message-tamago-not-in-use-p (pos)
2832 "Return t when tamago version 4 is not in use at the cursor position.
2833 Tamago version 4 is a popular input method for writing Japanese text.
2834 It uses the properties `intangible', `invisible', `modification-hooks'
2835 and `read-only' when translating ascii or kana text to kanji text.
2836 These properties are essential to work, so we should never strip them."
2837 (not (and (boundp 'egg-modefull-mode)
2838 (symbol-value 'egg-modefull-mode)
2839 (or (memq (get-text-property pos 'intangible)
2840 '(its-part-1 its-part-2))
2841 (get-text-property pos 'egg-end)
2842 (get-text-property pos 'egg-lang)
2843 (get-text-property pos 'egg-start)))))
2845 (defsubst message-mail-alias-type-p (type)
2846 (if (atom message-mail-alias-type)
2847 (eq message-mail-alias-type type)
2848 (memq type message-mail-alias-type)))
2850 (defun message-strip-forbidden-properties (begin end &optional old-length)
2851 "Strip forbidden properties between BEGIN and END, ignoring the third arg.
2852 This function is intended to be called from `after-change-functions'.
2853 See also `message-forbidden-properties'."
2854 (when (and (message-mail-alias-type-p 'ecomplete)
2855 (memq this-command message-self-insert-commands))
2856 (message-display-abbrev))
2857 (when (and message-strip-special-text-properties
2858 (message-tamago-not-in-use-p begin))
2859 (let ((buffer-read-only nil)
2860 (inhibit-read-only t))
2861 (remove-text-properties begin end message-forbidden-properties))))
2863 (autoload 'ecomplete-setup "ecomplete") ;; for Emacs <23.
2866 (define-derived-mode message-mode text-mode "Message"
2867 "Major mode for editing mail and news to be sent.
2868 Like Text Mode but with these additional commands:\\<message-mode-map>
2869 C-c C-s `message-send' (send the message) C-c C-c `message-send-and-exit'
2870 C-c C-d Postpone sending the message C-c C-k Kill the message
2871 C-c C-f move to a header field (and create it if there isn't):
2872 C-c C-f C-t move to To C-c C-f C-s move to Subject
2873 C-c C-f C-c move to Cc C-c C-f C-b move to Bcc
2874 C-c C-f C-w move to Fcc C-c C-f C-r move to Reply-To
2875 C-c C-f C-u move to Summary C-c C-f C-n move to Newsgroups
2876 C-c C-f C-k move to Keywords C-c C-f C-d move to Distribution
2877 C-c C-f C-o move to From (\"Originator\")
2878 C-c C-f C-f move to Followup-To
2879 C-c C-f C-m move to Mail-Followup-To
2880 C-c C-f C-e move to Expires
2881 C-c C-f C-i cycle through Importance values
2882 C-c C-f s change subject and append \"(was: <Old Subject>)\"
2883 C-c C-f x crossposting with FollowUp-To header and note in body
2884 C-c C-f t replace To: header with contents of Cc: or Bcc:
2885 C-c C-f a Insert X-No-Archive: header and a note in the body
2886 C-c C-t `message-insert-to' (add a To header to a news followup)
2887 C-c C-l `message-to-list-only' (removes all but list address in to/cc)
2888 C-c C-n `message-insert-newsgroups' (add a Newsgroup header to a news reply)
2889 C-c C-b `message-goto-body' (move to beginning of message text).
2890 C-c C-i `message-goto-signature' (move to the beginning of the signature).
2891 C-c C-w `message-insert-signature' (insert `message-signature-file' file).
2892 C-c C-y `message-yank-original' (insert current message, if any).
2893 C-c C-q `message-fill-yanked-message' (fill what was yanked).
2894 C-c C-e `message-elide-region' (elide the text between point and mark).
2895 C-c C-v `message-delete-not-region' (remove the text outside the region).
2896 C-c C-z `message-kill-to-signature' (kill the text up to the signature).
2897 C-c C-r `message-caesar-buffer-body' (rot13 the message body).
2898 C-c C-a `mml-attach-file' (attach a file as MIME).
2899 C-c C-u `message-insert-or-toggle-importance' (insert or cycle importance).
2900 C-c M-n `message-insert-disposition-notification-to' (request receipt).
2901 C-c M-m `message-mark-inserted-region' (mark region with enclosing tags).
2902 C-c M-f `message-mark-insert-file' (insert file marked with enclosing tags).
2903 M-RET `message-newline-and-reformat' (break the line and reformat)."
2904 (setq local-abbrev-table text-mode-abbrev-table)
2905 (set (make-local-variable 'message-reply-buffer) nil)
2906 (set (make-local-variable 'message-inserted-headers) nil)
2907 (set (make-local-variable 'message-send-actions) nil)
2908 (set (make-local-variable 'message-exit-actions) nil)
2909 (set (make-local-variable 'message-kill-actions) nil)
2910 (set (make-local-variable 'message-postpone-actions) nil)
2911 (set (make-local-variable 'message-draft-article) nil)
2912 (setq buffer-offer-save t)
2913 (set (make-local-variable 'facemenu-add-face-function)
2915 (let ((face-fun (cdr (assq face message-face-alist))))
2917 (funcall face-fun (point) end)
2918 (error "Face %s not configured for %s mode" face mode-name)))
2920 (set (make-local-variable 'facemenu-remove-face-function) t)
2921 (set (make-local-variable 'message-reply-headers) nil)
2922 (make-local-variable 'message-newsreader)
2923 (make-local-variable 'message-mailer)
2924 (make-local-variable 'message-post-method)
2925 (set (make-local-variable 'message-sent-message-via) nil)
2926 (set (make-local-variable 'message-checksum) nil)
2927 (set (make-local-variable 'message-mime-part) 0)
2928 (message-setup-fill-variables)
2929 (when message-fill-column
2930 (setq fill-column message-fill-column)
2931 (turn-on-auto-fill))
2932 ;; Allow using comment commands to add/remove quoting.
2933 ;; (set (make-local-variable 'comment-start) message-yank-prefix)
2934 (when message-yank-prefix
2935 (set (make-local-variable 'comment-start) message-yank-prefix)
2936 (set (make-local-variable 'comment-start-skip)
2937 (concat "^" (regexp-quote message-yank-prefix) "[ \t]*")))
2938 (if (featurep 'xemacs)
2939 (message-setup-toolbar)
2940 (set (make-local-variable 'font-lock-defaults)
2941 '(message-font-lock-keywords t))
2942 (if (boundp 'tool-bar-map)
2943 (set (make-local-variable 'tool-bar-map) (message-make-tool-bar))))
2944 (easy-menu-add message-mode-menu message-mode-map)
2945 (easy-menu-add message-mode-field-menu message-mode-map)
2946 (gnus-make-local-hook 'after-change-functions)
2947 ;; Mmmm... Forbidden properties...
2948 (add-hook 'after-change-functions 'message-strip-forbidden-properties
2950 ;; Allow mail alias things.
2952 ((message-mail-alias-type-p 'abbrev)
2953 (if (fboundp 'mail-abbrevs-setup)
2954 (mail-abbrevs-setup)
2955 (if (fboundp 'mail-aliases-setup) ; warning avoidance
2956 (mail-aliases-setup))))
2957 ((message-mail-alias-type-p 'ecomplete)
2959 (unless buffer-file-name
2960 (message-set-auto-save-file-name))
2961 (unless (buffer-base-buffer)
2962 ;; Don't enable multibyte on an indirect buffer. Maybe enabling
2963 ;; multibyte is not necessary at all. -- zsh
2964 (mm-enable-multibyte))
2965 (set (make-local-variable 'indent-tabs-mode) nil) ;No tabs for indentation.
2968 (defun message-setup-fill-variables ()
2969 "Setup message fill variables."
2970 (set (make-local-variable 'fill-paragraph-function)
2971 'message-fill-paragraph)
2972 (make-local-variable 'paragraph-separate)
2973 (make-local-variable 'paragraph-start)
2974 (make-local-variable 'adaptive-fill-regexp)
2975 (unless (boundp 'adaptive-fill-first-line-regexp)
2976 (setq adaptive-fill-first-line-regexp nil))
2977 (make-local-variable 'adaptive-fill-first-line-regexp)
2978 (let ((quote-prefix-regexp
2979 ;; User should change message-cite-prefix-regexp if
2980 ;; message-yank-prefix is set to an abnormal value.
2981 (concat "\\(" message-cite-prefix-regexp "\\)[ \t]*")))
2982 (setq paragraph-start
2984 (regexp-quote mail-header-separator) "$\\|"
2985 "[ \t]*$\\|" ; blank lines
2986 "-- $\\|" ; signature delimiter
2987 "---+$\\|" ; delimiters for forwarded messages
2988 page-delimiter "$\\|" ; spoiler warnings
2989 ".*wrote:$\\|" ; attribution lines
2990 quote-prefix-regexp "$\\|" ; empty lines in quoted text
2992 "<#!*/?\\(multipart\\|part\\|external\\|mml\\|secure\\)"))
2993 (setq paragraph-separate paragraph-start)
2994 (setq adaptive-fill-regexp
2995 (concat quote-prefix-regexp "\\|" adaptive-fill-regexp))
2996 (setq adaptive-fill-first-line-regexp
2997 (concat quote-prefix-regexp "\\|"
2998 adaptive-fill-first-line-regexp)))
2999 (make-local-variable 'auto-fill-inhibit-regexp)
3000 ;;(setq auto-fill-inhibit-regexp "^[A-Z][^: \n\t]+:")
3001 (setq auto-fill-inhibit-regexp nil)
3002 (make-local-variable 'normal-auto-fill-function)
3003 (setq normal-auto-fill-function 'message-do-auto-fill)
3004 ;; KLUDGE: auto fill might already be turned on in `text-mode-hook'.
3005 ;; In that case, ensure that it uses the right function. The real
3006 ;; solution would be not to use `define-derived-mode', and run
3007 ;; `text-mode-hook' ourself at the end of the mode.
3008 ;; -- Per Abrahamsen <abraham@dina.kvl.dk> Date: 2001-10-19.
3009 ;; This kludge is unneeded in Emacs>=21 since define-derived-mode is
3010 ;; now careful to run parent hooks after the body. --Stef
3011 (when auto-fill-function
3012 (setq auto-fill-function normal-auto-fill-function)))
3017 ;;; Message mode commands
3020 ;;; Movement commands
3022 (defun message-goto-to ()
3023 "Move point to the To header."
3025 (message-position-on-field "To"))
3027 (defun message-goto-from ()
3028 "Move point to the From header."
3030 (message-position-on-field "From"))
3032 (defun message-goto-subject ()
3033 "Move point to the Subject header."
3035 (message-position-on-field "Subject"))
3037 (defun message-goto-cc ()
3038 "Move point to the Cc header."
3040 (message-position-on-field "Cc" "To"))
3042 (defun message-goto-bcc ()
3043 "Move point to the Bcc header."
3045 (message-position-on-field "Bcc" "Cc" "To"))
3047 (defun message-goto-fcc ()
3048 "Move point to the Fcc header."
3050 (message-position-on-field "Fcc" "To" "Newsgroups"))
3052 (defun message-goto-reply-to ()
3053 "Move point to the Reply-To header."
3055 (message-position-on-field "Reply-To" "Subject"))
3057 (defun message-goto-newsgroups ()
3058 "Move point to the Newsgroups header."
3060 (message-position-on-field "Newsgroups"))
3062 (defun message-goto-distribution ()
3063 "Move point to the Distribution header."
3065 (message-position-on-field "Distribution"))
3067 (defun message-goto-followup-to ()
3068 "Move point to the Followup-To header."
3070 (message-position-on-field "Followup-To" "Newsgroups"))
3072 (defun message-goto-mail-followup-to ()
3073 "Move point to the Mail-Followup-To header."
3075 (message-position-on-field "Mail-Followup-To" "To"))
3077 (defun message-goto-keywords ()
3078 "Move point to the Keywords header."
3080 (message-position-on-field "Keywords" "Subject"))
3082 (defun message-goto-summary ()
3083 "Move point to the Summary header."
3085 (message-position-on-field "Summary" "Subject"))
3087 (defun message-goto-body (&optional interactivep)
3088 "Move point to the beginning of the message body."
3089 (interactive (list t))
3090 (when (and interactivep
3091 (looking-at "[ \t]*\n"))
3093 (goto-char (point-min))
3094 (or (search-forward (concat "\n" mail-header-separator "\n") nil t)
3095 (search-forward-regexp "[^:]+:\\([^\n]\\|\n[ \t]\\)+\n\n" nil t)))
3097 (defun message-in-body-p ()
3098 "Return t if point is in the message body."
3099 (let ((body (save-excursion (message-goto-body) (point))))
3102 (defun message-goto-eoh ()
3103 "Move point to the end of the headers."
3108 (defun message-goto-signature ()
3109 "Move point to the beginning of the message signature.
3110 If there is no signature in the article, go to the end and
3113 (goto-char (point-min))
3114 (if (re-search-forward message-signature-separator nil t)
3116 (goto-char (point-max))
3119 (defun message-generate-unsubscribed-mail-followup-to (&optional include-cc)
3120 "Insert a reasonable MFT header in a post to an unsubscribed list.
3121 When making original posts to a mailing list you are not subscribed to,
3122 you have to type in a MFT header by hand. The contents, usually, are
3123 the addresses of the list and your own address. This function inserts
3124 such a header automatically. It fetches the contents of the To: header
3125 in the current mail buffer, and appends the current `user-mail-address'.
3127 If the optional argument INCLUDE-CC is non-nil, the addresses in the
3128 Cc: header are also put into the MFT."
3133 (message-narrow-to-headers)
3134 (message-remove-header "Mail-Followup-To")
3135 (setq cc (and include-cc (message-fetch-field "Cc")))
3137 (concat (message-fetch-field "To") "," cc)
3138 (message-fetch-field "To"))))
3139 (message-goto-mail-followup-to)
3140 (insert (concat tos ", " user-mail-address))))
3144 (defun message-insert-to (&optional force)
3145 "Insert a To header that points to the author of the article being replied to.
3146 If the original author requested not to be sent mail, don't insert unless the
3147 prefix FORCE is given."
3149 (let* ((mct (message-fetch-reply-field "mail-copies-to"))
3150 (dont (and mct (or (equal (downcase mct) "never")
3151 (equal (downcase mct) "nobody"))))
3152 (to (or (message-fetch-reply-field "mail-reply-to")
3153 (message-fetch-reply-field "reply-to")
3154 (message-fetch-reply-field "from"))))
3158 "Ignoring the user request not to have copies sent via mail"
3159 "Complying with the user request not to have copies sent via mail")))
3160 (when (and force (not to))
3161 (error "No mail address in the article"))
3162 (when (and to (or force (not dont)))
3163 (message-carefully-insert-headers (list (cons 'To to))))))
3165 (defun message-insert-wide-reply ()
3166 "Insert To and Cc headers as if you were doing a wide reply."
3168 (let ((headers (message-with-reply-buffer
3169 (message-get-reply-headers t))))
3170 (message-carefully-insert-headers headers)))
3172 (defcustom message-header-synonyms
3175 "List of lists of header synonyms.
3176 E.g., if this list contains a member list with elements `Cc' and `To',
3177 then `message-carefully-insert-headers' will not insert a `To' header
3178 when the message is already `Cc'ed to the recipient."
3180 :group 'message-headers
3181 :link '(custom-manual "(message)Message Headers")
3182 :type '(repeat sexp))
3184 (defun message-carefully-insert-headers (headers)
3185 "Insert the HEADERS, an alist, into the message buffer.
3186 Does not insert the headers when they are already present there
3187 or in the synonym headers, defined by `message-header-synonyms'."
3188 ;; FIXME: Should compare only the address and not the full name. Comparison
3189 ;; should be done case-folded (and with `string=' rather than
3191 ;; (mail-strip-quoted-names "Foo Bar <foo@bar>, bla@fasel (Bla Fasel)")
3192 (dolist (header headers)
3193 (let* ((header-name (symbol-name (car header)))
3194 (new-header (cdr header))
3195 (synonyms (loop for synonym in message-header-synonyms
3196 when (memq (car header) synonym) return synonym))
3198 (loop for synonym in synonyms
3199 for old-header = (mail-fetch-field (symbol-name synonym))
3200 when (and old-header (string-match new-header old-header))
3203 (message "already have `%s' in `%s'" new-header old-header)
3204 (when (and (message-position-on-field header-name)
3205 (setq old-header (mail-fetch-field header-name))
3206 (not (string-match "\\` *\\'" old-header)))
3208 (insert new-header)))))
3210 (defun message-widen-reply ()
3211 "Widen the reply to include maximum recipients."
3214 (and (bufferp message-reply-buffer)
3215 (buffer-name message-reply-buffer)
3216 (with-current-buffer message-reply-buffer
3217 (message-get-reply-headers t)))))
3220 (message-narrow-to-headers)
3221 (dolist (elem follow-to)
3222 (message-remove-header (symbol-name (car elem)))
3223 (goto-char (point-min))
3224 (insert (symbol-name (car elem)) ": "
3225 (cdr elem) "\n"))))))
3227 (defun message-insert-newsgroups ()
3228 "Insert the Newsgroups header from the article being replied to."
3230 (when (and (message-position-on-field "Newsgroups")
3231 (mail-fetch-field "newsgroups")
3232 (not (string-match "\\` *\\'" (mail-fetch-field "newsgroups"))))
3234 (insert (or (message-fetch-reply-field "newsgroups") "")))
3238 ;;; Various commands
3240 (defun message-delete-not-region (beg end)
3241 "Delete everything in the body of the current message outside of the region."
3246 ;; snarf citation prefix, if appropriate
3247 (unless (eq (point) (progn (beginning-of-line) (point)))
3248 (when (looking-at message-cite-prefix-regexp)
3249 (setq citeprefix (match-string 0))))
3251 (delete-region (point) (if (not (message-goto-signature))
3257 (delete-region beg (progn (message-goto-body)
3261 (insert citeprefix))))
3262 (when (message-goto-signature)
3265 (defun message-kill-to-signature (&optional arg)
3266 "Kill all text up to the signature.
3267 If a numeric argument or prefix arg is given, leave that number
3268 of lines before the signature intact."
3272 (let ((point (point)))
3273 (narrow-to-region point (point-max))
3274 (message-goto-signature)
3276 (if (and arg (numberp arg))
3277 (forward-line (- -1 arg))
3279 (unless (= point (point))
3280 (kill-region point (point))
3284 (defun message-newline-and-reformat (&optional arg not-break)
3285 "Insert four newlines, and then reformat if inside quoted text.
3286 Prefix arg means justify as well."
3287 (interactive (list (if current-prefix-arg 'full)))
3288 (let (quoted point beg end leading-space bolp fill-paragraph-function)
3289 (setq point (point))
3292 (setq bolp (= beg point))
3293 ;; Find first line of the paragraph.
3295 (while (and (not (eobp))
3296 (not (looking-at message-cite-prefix-regexp))
3297 (looking-at paragraph-start))
3300 (when (looking-at message-cite-prefix-regexp)
3301 (setq quoted (match-string 0))
3302 (goto-char (match-end 0))
3303 (looking-at "[ \t]*")
3304 (setq leading-space (match-string 0)))
3308 (< (- point beg) (length quoted)))
3309 ;; break inside the cite prefix.
3315 (while (and (not (eobp))
3316 (not (looking-at paragraph-separate))
3317 (looking-at message-cite-prefix-regexp)
3318 (equal quoted (match-string 0)))
3319 (goto-char (match-end 0))
3320 (looking-at "[ \t]*")
3321 (if (> (length leading-space) (length (match-string 0)))
3322 (setq leading-space (match-string 0)))
3326 (while (and (if (bobp) nil (forward-line -1) t)
3327 (not (looking-at paragraph-start))
3328 (looking-at message-cite-prefix-regexp)
3329 (equal quoted (match-string 0)))
3331 (goto-char (match-end 0))
3332 (looking-at "[ \t]*")
3333 (if (> (length leading-space) (length (match-string 0)))
3334 (setq leading-space (match-string 0)))))
3335 (while (and (not (eobp))
3336 (not (looking-at paragraph-separate))
3337 (not (looking-at message-cite-prefix-regexp)))
3341 (while (and (if (bobp) nil (forward-line -1) t)
3342 (not (looking-at paragraph-start))
3343 (not (looking-at message-cite-prefix-regexp)))
3344 (setq beg (point))))
3347 (narrow-to-region beg end)
3354 (setq point (point))
3355 ;; (newline 2) doesn't mark both newline's as hard, so call
3356 ;; newline twice. -jas
3359 (delete-region (point) (re-search-forward "[ \t]*"))
3360 (when (and quoted (not bolp))
3361 (insert quoted leading-space)))
3364 (let* ((adaptive-fill-regexp
3365 (regexp-quote (concat quoted leading-space)))
3366 (adaptive-fill-first-line-regexp
3367 adaptive-fill-regexp ))
3368 (fill-paragraph arg))
3369 (fill-paragraph arg))
3370 (if point (goto-char point)))))
3372 (defun message-fill-paragraph (&optional arg)
3373 "Message specific function to fill a paragraph.
3374 This function is used as the value of `fill-paragraph-function' in
3375 Message buffers and is not meant to be called directly."
3376 (interactive (list (if current-prefix-arg 'full)))
3377 (if (if (boundp 'filladapt-mode) filladapt-mode)
3379 (if (message-point-in-header-p)
3380 (message-fill-field)
3381 (message-newline-and-reformat arg t))
3384 (defun message-point-in-header-p ()
3385 "Return t if point is in the header."
3387 (not (re-search-backward
3388 (concat "^" (regexp-quote mail-header-separator) "\n") nil t))))
3390 (defun message-do-auto-fill ()
3391 "Like `do-auto-fill', but don't fill in message header."
3392 (unless (message-point-in-header-p)
3395 (defun message-insert-signature (&optional force)
3396 "Insert a signature. See documentation for variable `message-signature'."
3397 (interactive (list 0))
3400 ((and (null message-signature)
3403 (goto-char (point-max))
3404 (not (re-search-backward message-signature-separator nil t))))
3405 ((and (null message-signature)
3408 ((functionp message-signature)
3409 (funcall message-signature))
3410 ((listp message-signature)
3411 (eval message-signature))
3412 (t message-signature)))
3415 (cond ((stringp signature)
3417 ((and (eq t signature) message-signature-file)
3418 (setq signature-file
3419 (if (and message-signature-directory
3420 ;; don't actually use the signature directory
3421 ;; if message-signature-file contains a path.
3422 (not (file-name-directory
3423 message-signature-file)))
3424 (expand-file-name message-signature-file
3425 message-signature-directory)
3426 message-signature-file))
3427 (file-exists-p signature-file))))
3429 (goto-char (point-max))
3430 ;; Insert the signature.
3433 (when message-signature-insert-empty-line
3436 (if (eq signature t)
3437 (insert-file-contents signature-file)
3439 (goto-char (point-max))
3440 (or (bolp) (insert "\n")))))
3442 (defun message-insert-importance-high ()
3443 "Insert header to mark message as important."
3447 (message-narrow-to-headers)
3448 (message-remove-header "Importance"))
3450 (insert "Importance: high\n")))
3452 (defun message-insert-importance-low ()
3453 "Insert header to mark message as unimportant."
3457 (message-narrow-to-headers)
3458 (message-remove-header "Importance"))
3460 (insert "Importance: low\n")))
3462 (defun message-insert-or-toggle-importance ()
3463 "Insert a \"Importance: high\" header, or cycle through the header values.
3464 The three allowed values according to RFC 1327 are `high', `normal'
3471 (message-narrow-to-headers)
3472 (when (setq cur (message-fetch-field "Importance"))
3473 (message-remove-header "Importance")
3474 (setq new (cond ((string= cur "high")
3476 ((string= cur "low")
3481 (insert (format "Importance: %s\n" new)))))
3483 (defun message-insert-disposition-notification-to ()
3484 "Request a disposition notification (return receipt) to this message.
3485 Note that this should not be used in newsgroups."
3489 (message-narrow-to-headers)
3490 (message-remove-header "Disposition-Notification-To"))
3492 (insert (format "Disposition-Notification-To: %s\n"
3493 (or (message-field-value "Reply-to")
3494 (message-field-value "From")
3495 (message-make-from))))))
3497 (defun message-elide-region (b e)
3498 "Elide the text in the region.
3499 An ellipsis (from `message-elide-ellipsis') will be inserted where the
3503 (insert message-elide-ellipsis))
3505 (defvar message-caesar-translation-table nil)
3507 (defun message-caesar-region (b e &optional n)
3508 "Caesar rotate region B to E by N, default 13, for decrypting netnews."
3511 (min (point) (or (mark t) (point)))
3512 (max (point) (or (mark t) (point)))
3513 (when current-prefix-arg
3514 (prefix-numeric-value current-prefix-arg))))
3516 (setq n (if (numberp n) (mod n 26) 13)) ;canonize N
3517 (unless (or (zerop n) ; no action needed for a rot of 0
3518 (= b e)) ; no region to rotate
3519 ;; We build the table, if necessary.
3520 (when (or (not message-caesar-translation-table)
3521 (/= (aref message-caesar-translation-table ?a) (+ ?a n)))
3522 (setq message-caesar-translation-table
3523 (message-make-caesar-translation-table n)))
3524 (translate-region b e message-caesar-translation-table)))
3526 (defun message-make-caesar-translation-table (n)
3527 "Create a rot table with offset N."
3529 (table (make-string 256 0)))
3530 (while (< (incf i) 256)
3533 (substring table 0 ?A)
3534 (substring table (+ ?A n) (+ ?A n (- 26 n)))
3535 (substring table ?A (+ ?A n))
3536 (substring table (+ ?A 26) ?a)
3537 (substring table (+ ?a n) (+ ?a n (- 26 n)))
3538 (substring table ?a (+ ?a n))
3539 (substring table (+ ?a 26) 255))))
3541 (defun message-caesar-buffer-body (&optional rotnum wide)
3542 "Caesar rotate all letters in the current buffer by 13 places.
3543 Used to encode/decode possibly offensive messages (commonly in rec.humor).
3544 With prefix arg, specifies the number of places to rotate each letter forward.
3545 Mail and USENET news headers are not rotated unless WIDE is non-nil."
3546 (interactive (if current-prefix-arg
3547 (list (prefix-numeric-value current-prefix-arg))
3551 (when (and (not wide) (message-goto-body))
3552 (narrow-to-region (point) (point-max)))
3553 (message-caesar-region (point-min) (point-max) rotnum))))
3555 (defun message-pipe-buffer-body (program)
3556 "Pipe the message body in the current buffer through PROGRAM."
3559 (when (message-goto-body)
3560 (narrow-to-region (point) (point-max)))
3561 (shell-command-on-region
3562 (point-min) (point-max) program nil t))))
3564 (defun message-rename-buffer (&optional enter-string)
3565 "Rename the *message* buffer to \"*message* RECIPIENT\".
3566 If the function is run with a prefix, it will ask for a new buffer
3567 name, rather than giving an automatic name."
3568 (interactive "Pbuffer name: ")
3571 (goto-char (point-min))
3572 (narrow-to-region (point)
3573 (search-forward mail-header-separator nil 'end))
3575 (if (message-news-p) (message-fetch-field "Newsgroups")
3576 (message-fetch-field "To"))
3579 (if (string-match "," mail-to)
3580 (concat (substring mail-to 0 (match-beginning 0)) ", ...")
3582 (name-default (concat "*message* " mail-trimmed-to))
3583 (name (if enter-string
3584 (read-string "New buffer name: " name-default)
3586 (rename-buffer name t)))))
3588 (defun message-fill-yanked-message (&optional justifyp)
3589 "Fill the paragraphs of a message yanked into this one.
3590 Numeric argument means justify as well."
3593 (goto-char (point-min))
3594 (search-forward (concat "\n" mail-header-separator "\n") nil t)
3595 (let ((fill-prefix message-yank-prefix))
3596 (fill-individual-paragraphs (point) (point-max) justifyp))))
3598 (defun message-indent-citation (&optional start end yank-only)
3599 "Modify text just inserted from a message to be cited.
3600 The inserted text should be the region.
3601 When this function returns, the region is again around the modified text.
3603 Normally, indent each nonblank line `message-indentation-spaces' spaces.
3604 However, if `message-yank-prefix' is non-nil, insert that prefix on each line."
3605 (unless start (setq start (point)))
3607 ;; Remove unwanted headers.
3608 (when message-ignored-cited-headers
3613 (if (search-forward "\n\n" nil t)
3616 (message-remove-header message-ignored-cited-headers t)
3617 (when (= (point-min) (point-max))
3618 (setq all-removed t))
3619 (goto-char (point-max)))
3623 ;; Delete blank lines at the start of the buffer.
3624 (while (and (point-min)
3627 (message-delete-line))
3628 ;; Delete blank lines at the end of the buffer.
3629 (goto-char (point-max))
3632 (while (and (zerop (forward-line -1))
3634 (message-delete-line)))
3635 ;; Do the indentation.
3636 (if (null message-yank-prefix)
3637 (indent-rigidly start (or end (mark t)) message-indentation-spaces)
3640 (while (< (point) (or end (mark t)))
3641 (cond ((looking-at ">")
3642 (insert message-yank-cited-prefix))
3644 (insert message-yank-empty-prefix))
3646 (insert message-yank-prefix)))
3650 (defun message-remove-blank-cited-lines (&optional remove)
3651 "Remove cited lines containing only blanks.
3652 If REMOVE is non-nil, remove newlines, too.
3654 To use this automatically, you may add this function to
3655 `gnus-message-setup-hook'."
3660 (when (boundp 'message-yank-cited-prefix)
3661 (concat message-yank-cited-prefix "\\|"))
3665 (gnus-message 8 "removing `%s'" citexp)
3668 (while (re-search-forward citexp nil t)
3669 (replace-match (if remove "" "\n"))))))
3671 (defvar message-cite-reply-above nil
3672 "If non-nil, start own text above the quote.
3674 Note: Top posting is bad netiquette. Don't use it unless you
3675 really must. You probably want to set variable only for specific
3676 groups, e.g. using `gnus-posting-styles':
3678 (eval (set (make-local-variable 'message-cite-reply-above) t))
3680 This variable has no effect in news postings.")
3682 (defun message-yank-original (&optional arg)
3683 "Insert the message being replied to, if any.
3684 Puts point before the text and mark after.
3685 Normally indents each nonblank line ARG spaces (default 3). However,
3686 if `message-yank-prefix' is non-nil, insert that prefix on each line.
3688 This function uses `message-cite-function' to do the actual citing.
3690 Just \\[universal-argument] as argument means don't indent, insert no
3691 prefix, and don't delete any headers."
3693 (let ((modified (buffer-modified-p))
3695 (when (and message-reply-buffer
3696 message-cite-function)
3697 (when message-cite-reply-above
3698 (if (and (not (message-news-p))
3699 (or (eq message-cite-reply-above 'is-evil)
3701 Top posting is bad netiquette. Please don't top post unless you really must.
3702 Really top post? ")))
3705 (buffer-substring (message-goto-body)
3707 (delete-region (message-goto-body) (point-max)))
3708 (set (make-local-variable 'message-cite-reply-above) nil)))
3709 (if (bufferp message-reply-buffer)
3710 (delete-windows-on message-reply-buffer t))
3711 (push-mark (save-excursion
3713 ((bufferp message-reply-buffer)
3714 (insert-buffer-substring message-reply-buffer))
3715 ((and (consp message-reply-buffer)
3716 (functionp (car message-reply-buffer)))
3717 (apply (car message-reply-buffer)
3718 (cdr message-reply-buffer))))
3723 (funcall message-cite-function)
3724 (unless (eq (char-before (mark t)) ?\n)
3726 (goto-char (mark t))
3727 (insert-before-markers ?\n)
3729 (when message-cite-reply-above
3732 (insert (if (bolp) "\n" "\n\n"))
3733 (message-goto-body))
3734 ;; Add a `message-setup-very-last-hook' here?
3735 ;; Add `gnus-article-highlight-citation' here?
3737 (setq message-checksum (message-checksum))))))
3739 (defun message-yank-buffer (buffer)
3740 "Insert BUFFER into the current buffer and quote it."
3741 (interactive "bYank buffer: ")
3742 (let ((message-reply-buffer (get-buffer buffer)))
3743 (save-window-excursion
3744 (message-yank-original))))
3746 (defun message-buffers ()
3747 "Return a list of active message buffers."
3749 (save-current-buffer
3750 (dolist (buffer (buffer-list t))
3752 (when (and (eq major-mode 'message-mode)
3753 (null message-sent-message-via))
3754 (push (buffer-name buffer) buffers))))
3755 (nreverse buffers)))
3757 (defun message-cite-original-1 (strip-signature)
3758 "Cite an original message.
3759 If STRIP-SIGNATURE is non-nil, strips off the signature from the
3762 This function uses `mail-citation-hook' if that is non-nil."
3763 (if (and (boundp 'mail-citation-hook)
3765 (run-hooks 'mail-citation-hook)
3766 (let* ((start (point))
3770 (when message-indent-citation-function
3771 (if (listp message-indent-citation-function)
3772 message-indent-citation-function
3773 (list message-indent-citation-function))))
3774 ;; This function may be called by `gnus-summary-yank-message' and
3775 ;; may insert a different article from the original. So, we will
3776 ;; modify the value of `message-reply-headers' with that article.
3777 (message-reply-headers
3779 (narrow-to-region start end)
3780 (message-narrow-to-head-1)
3781 (setq x-no-archive (message-fetch-field "x-no-archive"))
3783 (or (message-fetch-field "subject") "none")
3784 (or (message-fetch-field "from") "nobody")
3785 (message-fetch-field "date")
3786 (message-fetch-field "message-id" t)
3787 (message-fetch-field "references")
3789 (mml-quote-region start end)
3790 (when strip-signature
3794 (when (re-search-backward message-signature-separator start t)
3795 ;; Also peel off any blank lines before the signature.
3797 (while (looking-at "^[ \t]*$")
3800 (delete-region (point) end)
3801 (unless (search-backward "\n\n" start t)
3802 ;; Insert a blank line if it is peeled off.
3805 (mapc 'funcall functions)
3806 (when message-citation-line-function
3809 (funcall message-citation-line-function))
3810 (when (and x-no-archive
3811 (not message-cite-articles-with-x-no-archive)
3812 (string-match "yes" x-no-archive))
3814 (delete-region (point) (mark t))
3815 (insert "> [Quoted text removed due to X-No-Archive]\n")
3817 (forward-line -1)))))
3819 (defun message-cite-original ()
3820 "Cite function in the standard Message manner."
3821 (message-cite-original-1 nil))
3823 (defvar gnus-extract-address-components)
3825 (autoload 'format-spec "format-spec")
3827 (defun message-insert-formatted-citation-line (&optional from date)
3828 "Function that inserts a formatted citation line.
3830 See `message-citation-line-format'."
3831 ;; The optional args are for testing/debugging. They will disappear later.
3833 ;; (with-temp-buffer
3834 ;; (message-insert-formatted-citation-line
3835 ;; "John Doe <john.doe@example.invalid>"
3838 (when (or message-reply-headers (and from date))
3840 (setq from (mail-header-from message-reply-headers)))
3841 (let* ((data (condition-case ()
3842 (funcall (if (boundp gnus-extract-address-components)
3843 gnus-extract-address-components
3844 'mail-extract-address-components)
3850 (net (car (cdr data)))
3851 (name-or-net (or (car data)
3852 (car (cdr data)) from))
3856 ;; We need Gnus functionality if the user wants date or time from
3857 ;; the original article:
3858 (when (string-match "%[^fnNFL]" message-citation-line-format)
3859 (autoload 'gnus-date-get-time "gnus-util")
3860 (gnus-date-get-time (mail-header-date message-reply-headers)))))
3863 (when (stringp name)
3864 ;; Guess first name and last name:
3865 (cond ((string-match
3866 "\\`\\(\\w\\|[-.]\\)+ \\(\\w\\|[-.]\\)+\\'" name)
3867 (setq fname (nth 0 (split-string name "[ \t]+"))
3868 lname (nth 1 (split-string name "[ \t]+"))))
3870 "\\`\\(\\w\\|[-.]\\)+, \\(\\w\\|[-.]\\)+\\'" name)
3871 (setq fname (nth 1 (split-string name "[ \t,]+"))
3872 lname (nth 0 (split-string name "[ \t,]+"))))
3874 "\\`\\(\\w\\|[-.]\\)+\\'" name)
3877 ;; The following letters are not used in `format-time-string':
3878 (push ?E lst) (push "<E>" lst)
3879 (push ?F lst) (push fname lst)
3880 ;; We might want to use "" instead of "<X>" later.
3881 (push ?J lst) (push "<J>" lst)
3882 (push ?K lst) (push "<K>" lst)
3883 (push ?L lst) (push lname lst)
3884 (push ?N lst) (push name-or-net lst)
3885 (push ?O lst) (push "<O>" lst)
3886 (push ?P lst) (push "<P>" lst)
3887 (push ?Q lst) (push "<Q>" lst)
3888 (push ?f lst) (push from lst)
3889 (push ?i lst) (push "<i>" lst)
3890 (push ?n lst) (push net lst)
3891 (push ?o lst) (push "<o>" lst)
3892 (push ?q lst) (push "<q>" lst)
3893 (push ?t lst) (push "<t>" lst)
3894 (push ?v lst) (push "<v>" lst)
3895 ;; Delegate the rest to `format-time-string':
3897 (when (and (not (memq i lst))
3902 (push (condition-case nil
3903 (format-time-string (format "%%%c" i) replydate)
3904 (error (format ">%c<" i)))
3908 (spec (apply 'format-spec-make flist)))
3909 (insert (format-spec message-citation-line-format spec)))
3912 (defun message-cite-original-without-signature ()
3913 "Cite function in the standard Message manner.
3914 This function strips off the signature from the original message."
3915 (message-cite-original-1 t))
3917 (defun message-insert-citation-line ()
3918 "Insert a simple citation line."
3919 (when message-reply-headers
3920 (insert (mail-header-from message-reply-headers) " writes:")
3924 (defun message-position-on-field (header &rest afters)
3925 (let ((case-fold-search t))
3928 (goto-char (point-min))
3931 (concat "^" (regexp-quote mail-header-separator) "$"))
3932 (match-beginning 0)))
3933 (goto-char (point-min))
3934 (if (re-search-forward (concat "^" (regexp-quote header) ":") nil t)
3936 (re-search-forward "^[^ \t]" nil 'move)
3938 (skip-chars-backward "\n")
3941 (not (re-search-forward
3942 (concat "^" (regexp-quote (car afters)) ":")
3946 (re-search-forward "^[^ \t]" nil 'move)
3947 (beginning-of-line))
3948 (insert header ": \n")
3952 (defun message-remove-signature ()
3953 "Remove the signature from the text between point and mark.
3954 The text will also be indented the normal way."
3956 (let ((start (point))
3958 (if (not (re-search-forward message-signature-separator (mark t) t))
3959 ;; No signature here, so we just indent the cited text.
3960 (message-indent-citation)
3961 ;; Find the last non-empty line.
3963 (while (looking-at "[ \t]*$")
3966 (setq mark (set-marker (make-marker) (point)))
3968 (message-indent-citation)
3969 ;; Enable undoing the deletion.
3971 (delete-region mark (mark t))
3972 (set-marker mark nil)))))
3977 ;;; Sending messages
3980 (defun message-send-and-exit (&optional arg)
3981 "Send message like `message-send', then, if no errors, exit from mail buffer."
3983 (let ((buf (current-buffer))
3984 (actions message-exit-actions))
3985 (when (and (message-send arg)
3987 (if message-kill-buffer-on-exit
3990 (when (eq buf (current-buffer))
3991 (message-bury buf)))
3992 (message-do-actions actions)
3995 (defun message-dont-send ()
3996 "Don't send the message you have been editing.
3997 Instead, just auto-save the buffer and then bury it."
3999 (set-buffer-modified-p t)
4001 (let ((actions message-postpone-actions))
4002 (message-bury (current-buffer))
4003 (message-do-actions actions)))
4005 (defun message-kill-buffer ()
4006 "Kill the current buffer."
4008 (when (or (not (buffer-modified-p))
4009 (not message-kill-buffer-query)
4010 (yes-or-no-p "Message modified; kill anyway? "))
4011 (let ((actions message-kill-actions)
4012 (draft-article message-draft-article)
4013 (auto-save-file-name buffer-auto-save-file-name)
4014 (file-name buffer-file-name)
4015 (modified (buffer-modified-p)))
4016 (setq buffer-file-name nil)
4017 (kill-buffer (current-buffer))
4018 (when (and (or (and auto-save-file-name
4019 (file-exists-p auto-save-file-name))
4021 (file-exists-p file-name)))
4023 ;; If the message buffer has lived in a dedicated window,
4024 ;; `kill-buffer' has killed the frame. Thus the
4025 ;; `yes-or-no-p' may show up in a lowered frame. Make sure
4026 ;; that the user can see the question by raising the
4029 (yes-or-no-p (format "Remove the backup file%s? "
4030 (if modified " too" "")))))
4032 (delete-file auto-save-file-name))
4033 (let ((message-draft-article draft-article))
4034 (message-disassociate-draft)))
4035 (message-do-actions actions))))
4037 (defun message-bury (buffer)
4038 "Bury this mail BUFFER."
4039 (let ((newbuf (other-buffer buffer)))
4040 (bury-buffer buffer)
4041 (if (and (window-dedicated-p (selected-window))
4042 (not (null (delq (selected-frame) (visible-frame-list)))))
4043 (delete-frame (selected-frame))
4044 (switch-to-buffer newbuf))))
4046 (defun message-send (&optional arg)
4047 "Send the message in the current buffer.
4048 If `message-interactive' is non-nil, wait for success indication or
4049 error messages, and inform user.
4050 Otherwise any failure is reported in a message back to the user from
4052 The usage of ARG is defined by the instance that called Message.
4053 It should typically alter the sending method in some way or other."
4055 ;; Make it possible to undo the coming changes.
4057 (let ((inhibit-read-only t))
4058 (put-text-property (point-min) (point-max) 'read-only nil))
4059 (message-fix-before-sending)
4060 (run-hooks 'message-send-hook)
4061 (when message-confirm-send
4062 (or (y-or-n-p "Send message? ")
4064 (message message-sending-message)
4065 (let ((alist message-send-method-alist)
4067 elem sent dont-barf-on-no-method
4068 (message-options message-options))
4069 (message-options-set-recipient)
4071 (setq elem (pop alist)))
4072 (when (funcall (cadr elem))
4073 (when (and (or (not (memq (car elem)
4074 message-sent-message-via))
4075 (message-fetch-field "supersedes")
4076 (if (or (message-gnksa-enable-p 'multiple-copies)
4077 (not (eq (car elem) 'news)))
4080 "Already sent message via %s; resend? "
4082 (error "Denied posting -- multiple copies")))
4083 (setq success (funcall (caddr elem) arg)))
4087 (let ((fcc (message-fetch-field "Fcc"))
4088 (gcc (message-fetch-field "Gcc")))
4090 (or (eq message-allow-no-recipients 'always)
4091 (and (not (eq message-allow-no-recipients 'never))
4092 (setq dont-barf-on-no-method
4094 (format "No receiver, perform %s anyway? "
4095 (cond ((and fcc gcc) "Fcc and Gcc")
4098 (error "No methods specified to send by"))
4099 (when (or dont-barf-on-no-method
4103 (run-hooks 'message-sent-hook))
4104 (message "Sending...done")
4105 ;; Do ecomplete address snarfing.
4106 (when (and (message-mail-alias-type-p 'ecomplete)
4107 (not message-inhibit-ecomplete))
4108 (message-put-addresses-in-ecomplete))
4109 ;; Mark the buffer as unmodified and delete auto-save.
4110 (set-buffer-modified-p nil)
4111 (delete-auto-save-file-if-necessary t)
4112 (message-disassociate-draft)
4113 ;; Delete other mail buffers and stuff.
4114 (message-do-send-housekeeping)
4115 (message-do-actions message-send-actions)
4119 (defun message-send-via-mail (arg)
4120 "Send the current message via mail."
4121 (message-send-mail arg))
4123 (defun message-send-via-news (arg)
4124 "Send the current message via news."
4125 (funcall message-send-news-function arg))
4127 (defmacro message-check (type &rest forms)
4128 "Eval FORMS if TYPE is to be checked."
4129 `(or (message-check-element ,type)
4133 (put 'message-check 'lisp-indent-function 1)
4134 (put 'message-check 'edebug-form-spec '(form body))
4136 (defun message-text-with-property (prop &optional start end reverse)
4137 "Return a list of start and end positions where the text has PROP.
4138 START and END bound the search, they default to `point-min' and
4139 `point-max' respectively. If REVERSE is non-nil, find text which does
4142 (setq start (point-min)))
4144 (setq end (point-max)))
4148 (setq start (text-property-any start end prop nil)))
4149 (setq next (next-single-property-change start prop nil end))
4150 (push (cons start (or next end)) regions)
4153 (or (get-text-property start prop)
4154 (and (setq start (next-single-property-change
4155 start prop nil end))
4156 (get-text-property start prop))))
4157 (setq next (text-property-any start end prop nil))
4158 (push (cons start (or next end)) regions)
4160 (nreverse regions)))
4162 (defcustom message-bogus-addresses
4163 ;; '("noreply" "nospam" "invalid")
4164 '("noreply" "nospam" "invalid" "@@" "[^[:ascii:]].*@" "[ \t]")
4165 "List of regexps of potentially bogus mail addresses.
4166 See `message-check-recipients' how to setup checking.
4168 This list should make it possible to catch typos or warn about
4169 spam-trap addresses. It doesn't aim to verify strict RFC
4171 :version "23.1" ;; No Gnus
4172 :group 'message-headers
4174 (const :tag "None" nil)
4180 (const :tag "duplicate @" "@@")
4181 (const :tag "non-ascii local part" "[^[:ascii:]].*@")
4182 ;; Already caught by `message-valid-fqdn-regexp'
4183 ;; (const :tag "`_' in domain part" "@.*_")
4184 (const :tag "whitespace" "[ \t]"))
4189 (defun message-fix-before-sending ()
4190 "Do various things to make the message nice before sending it."
4191 ;; Make sure there's a newline at the end of the message.
4192 (goto-char (point-max))
4195 ;; Make the hidden headers visible.
4197 ;; Sort headers before sending the message.
4198 (message-sort-headers)
4199 ;; Make invisible text visible.
4200 ;; It doesn't seem as if this is useful, since the invisible property
4201 ;; is clobbered by an after-change hook anyhow.
4202 (message-check 'invisible-text
4203 (let ((regions (message-text-with-property 'invisible))
4207 (setq from (caar regions)
4209 regions (cdr regions))
4210 (put-text-property from to 'invisible nil)
4211 (message-overlay-put (message-make-overlay from to)
4213 (unless (yes-or-no-p
4214 "Invisible text found and made visible; continue sending? ")
4215 (error "Invisible text found and made visible")))))
4216 (message-check 'illegible-text
4217 (let (char found choice)
4220 (skip-chars-forward mm-7bit-chars)
4221 (when (get-text-property (point) 'no-illegible-text)
4222 ;; There is a signed or encrypted raw message part
4223 ;; that is considered to be safe.
4224 (goto-char (or (next-single-property-change
4225 (point) 'no-illegible-text)
4227 (setq char (char-after)))
4228 (when (or (< (mm-char-int char) 128)
4229 (and (mm-multibyte-p)
4230 (memq (char-charset char)
4231 '(eight-bit-control eight-bit-graphic
4232 ;; Emacs 23, Bug#1770:
4235 (not (get-text-property
4236 (point) 'untranslated-utf-8))))
4237 (message-overlay-put (message-make-overlay (point) (1+ (point)))
4243 (gnus-multiple-choice
4244 "Non-printable characters found. Continue sending?"
4245 `((?d "Remove non-printable characters and send")
4247 "Replace non-printable characters with \"%s\" and send"
4248 message-replacement-char))
4249 (?i "Ignore non-printable characters and send")
4250 (?e "Continue editing"))))
4252 (error "Non-printable characters"))
4254 (skip-chars-forward mm-7bit-chars)
4256 (when (let ((char (char-after)))
4257 (or (< (mm-char-int char) 128)
4258 (and (mm-multibyte-p)
4259 ;; FIXME: Wrong for Emacs 23 (unicode) and for
4260 ;; things like undecodable utf-8 (in Emacs 21?).
4261 ;; Should at least use find-coding-systems-region.
4263 (memq (char-charset char)
4264 '(eight-bit-control eight-bit-graphic
4265 ;; Emacs 23, Bug#1770:
4268 (not (get-text-property
4269 (point) 'untranslated-utf-8)))))
4271 (message-kill-all-overlays)
4273 (when (eq choice ?r)
4274 (insert message-replacement-char))))
4276 (skip-chars-forward mm-7bit-chars)))))
4277 (message-check 'bogus-recipient
4278 ;; Warn before sending a mail to an invalid address.
4279 (message-check-recipients)))
4281 (defun message-bogus-recipient-p (recipients)
4282 "Check if a mail address in RECIPIENTS looks bogus.
4284 RECIPIENTS is a mail header. Return a list of potentially bogus
4285 addresses. If none is found, return nil.
4287 An address might be bogus if the domain part is not fully
4288 qualified, see `message-valid-fqdn-regexp', or if there's a
4289 matching entry in `message-bogus-addresses'."
4290 ;; FIXME: How about "foo@subdomain", when the MTA adds ".domain.tld"?
4292 (mapc (lambda (address)
4293 (setq address (cadr address))
4297 (not (string-match "@" address))
4300 message-valid-fqdn-regexp "\\)\\'") address)))
4301 (and message-bogus-addresses
4303 (if (listp message-bogus-addresses)
4304 (mapconcat 'identity
4305 message-bogus-addresses
4307 message-bogus-addresses)))
4308 (string-match re address))))
4309 (push address found)))
4311 (mail-extract-address-components recipients t))
4314 (defun message-check-recipients ()
4315 "Warn before composing or sending a mail to an invalid address.
4317 This function could be useful in `message-setup-hook'."
4320 (message-narrow-to-headers)
4321 (dolist (hdr '("To" "Cc" "Bcc"))
4322 (let ((addr (message-fetch-field hdr)))
4323 (when (stringp addr)
4324 (dolist (bog (message-bogus-recipient-p addr))
4328 "Address `%s' might be bogus. Continue? " bog)))
4329 (error "Bogus address"))))))))
4331 (custom-add-option 'message-setup-hook 'message-check-recipients)
4333 (defun message-add-action (action &rest types)
4334 "Add ACTION to be performed when doing an exit of type TYPES."
4336 (add-to-list (intern (format "message-%s-actions" (pop types)))
4339 (defun message-delete-action (action &rest types)
4340 "Delete ACTION from lists of actions performed when doing an exit of type TYPES."
4343 (set (setq var (intern (format "message-%s-actions" (pop types))))
4344 (delq action (symbol-value var))))))
4346 (defun message-do-actions (actions)
4347 "Perform all actions in ACTIONS."
4348 ;; Now perform actions on successful sending.
4349 (dolist (action actions)
4352 ;; A simple function.
4355 ;; Something to be evaled.
4359 (defun message-send-mail-partially ()
4360 "Send mail as message/partial."
4361 ;; replace the header delimiter with a blank line
4362 (goto-char (point-min))
4364 (concat "^" (regexp-quote mail-header-separator) "\n"))
4365 (replace-match "\n")
4366 (run-hooks 'message-send-mail-hook)
4367 (let ((p (goto-char (point-min)))
4368 (tembuf (message-generate-new-buffer-clone-locals " message temp"))
4369 (curbuf (current-buffer))
4370 (id (message-make-message-id)) (n 1)
4371 plist total header required-mail-headers)
4373 (if (< (point-max) (+ p message-send-mail-partially-limit))
4374 (goto-char (point-max))
4375 (goto-char (+ p message-send-mail-partially-limit))
4377 (if (<= (point) p) (forward-line 1))) ;; In case of bad message.
4380 (setq total (length plist))
4381 (push (point-max) plist)
4382 (setq plist (nreverse plist))
4385 (setq p (pop plist))
4388 (copy-to-buffer tembuf p (car plist))
4390 (goto-char (point-min))
4393 (goto-char (point-min))
4394 (narrow-to-region (point) (point))
4397 (setq header (buffer-substring (point-min) (point)))
4398 (goto-char (point-min))
4399 (narrow-to-region (point) (point))
4401 (message-remove-header "Mime-Version")
4402 (message-remove-header "Content-Type")
4403 (message-remove-header "Content-Transfer-Encoding")
4404 (message-remove-header "Message-ID")
4405 (message-remove-header "Lines")
4406 (goto-char (point-max))
4407 (insert "Mime-Version: 1.0\n")
4408 (setq header (buffer-string)))
4409 (goto-char (point-max))
4410 (insert (format "Content-Type: message/partial; id=\"%s\"; number=%d; total=%d\n\n"
4413 (let ((mail-header-separator ""))
4414 (when (memq 'Message-ID message-required-mail-headers)
4415 (insert "Message-ID: " (message-make-message-id) "\n"))
4416 (when (memq 'Lines message-required-mail-headers)
4417 (insert "Lines: " (message-make-lines) "\n"))
4418 (message-goto-subject)
4420 (insert (format " (%d/%d)" n total))
4422 (funcall (or message-send-mail-real-function
4423 message-send-mail-function)))
4425 (setq p (pop plist))
4427 (kill-buffer tembuf))))
4429 (declare-function hashcash-wait-async "hashcash" (&optional buffer))
4431 (defun message-send-mail (&optional arg)
4432 (require 'mail-utils)
4433 (let* ((tembuf (message-generate-new-buffer-clone-locals " message temp"))
4434 (case-fold-search nil)
4435 (news (message-news-p))
4436 (mailbuf (current-buffer))
4437 (message-this-is-mail t)
4438 ;; gnus-setup-posting-charset is autoloaded in mml.el (FIXME
4439 ;; maybe it should not be), which this file requires. Hence
4440 ;; the fboundp test is always true. Loading it from gnus-msg
4441 ;; loads many Gnus files (Bug#5642). If
4442 ;; gnus-group-posting-charset-alist hasn't been customized,
4443 ;; this is just going to return nil anyway. FIXME it would
4444 ;; be good to improve this further, because even if g-g-p-c-a
4445 ;; has been customized, that is likely to just be for news.
4446 ;; Eg either move the definition from gnus-msg, or separate out
4447 ;; the mail and news parts.
4448 (message-posting-charset
4449 (if (and (fboundp 'gnus-setup-posting-charset)
4450 (boundp 'gnus-group-posting-charset-alist))
4451 (gnus-setup-posting-charset nil)
4452 message-posting-charset))
4453 (headers message-required-mail-headers))
4454 (when (and message-generate-hashcash
4455 (not (eq message-generate-hashcash 'opportunistic)))
4456 (message "Generating hashcash...")
4458 ;; Wait for calculations already started to finish...
4459 (hashcash-wait-async)
4460 ;; ...and do calculations not already done. mail-add-payment
4461 ;; will leave existing X-Hashcash headers alone.
4463 (message "Generating hashcash...done"))
4465 (message-narrow-to-headers)
4466 ;; Generate the Mail-Followup-To header if the header is not there...
4467 (if (and (message-subscribed-p)
4468 (not (mail-fetch-field "mail-followup-to")))
4471 (cons "Mail-Followup-To" (message-make-mail-followup-to))
4472 message-required-mail-headers))
4473 ;; otherwise, delete the MFT header if the field is empty
4474 (when (equal "" (mail-fetch-field "mail-followup-to"))
4475 (message-remove-header "^Mail-Followup-To:")))
4476 ;; Insert some headers.
4477 (let ((message-deletable-headers
4478 (if news nil message-deletable-headers)))
4479 (message-generate-headers headers))
4480 ;; Check continuation headers.
4481 (message-check 'continuation-headers
4482 (goto-char (point-min))
4483 (while (re-search-forward "^[^ \t\n][^ \t\n:]*[ \t\n]" nil t)
4484 (goto-char (match-beginning 0))
4485 (if (y-or-n-p "Fix continuation lines? ")
4488 (unless (y-or-n-p "Send anyway? ")
4489 (error "Failed to send the message")))))
4490 ;; Let the user do all of the above.
4491 (run-hooks 'message-header-hook))
4493 (with-current-buffer tembuf
4495 ;; Avoid copying text props (except hard newlines).
4496 (insert (with-current-buffer mailbuf
4497 (mml-buffer-substring-no-properties-except-hard-newlines
4498 (point-min) (point-max))))
4499 ;; Remove some headers.
4500 (message-encode-message-body)
4502 (message-narrow-to-headers)
4503 ;; We (re)generate the Lines header.
4504 (when (memq 'Lines message-required-mail-headers)
4505 (message-generate-headers '(Lines)))
4506 ;; Remove some headers.
4507 (message-remove-header message-ignored-mail-headers t)
4508 (let ((mail-parse-charset message-default-charset))
4509 (mail-encode-encoded-word-buffer)))
4510 (goto-char (point-max))
4511 ;; require one newline at the end.
4512 (or (= (preceding-char) ?\n)
4514 (message-cleanup-headers)
4515 ;; FIXME: we're inserting the courtesy copy after encoding.
4516 ;; This is wrong if the courtesy copy string contains
4517 ;; non-ASCII characters. -- jh
4520 (message-narrow-to-headers)
4522 (or (message-fetch-field "cc")
4523 (message-fetch-field "bcc")
4524 (message-fetch-field "to"))
4525 (let ((content-type (message-fetch-field
4530 (string= "text/plain"
4532 (mail-header-parse-content-type
4536 (message-fetch-field
4537 "content-transfer-encoding")))))))
4538 (message-insert-courtesy-copy))
4539 ;; Let's make sure we encoded all the body.
4540 (assert (save-excursion
4541 (goto-char (point-min))
4542 (not (re-search-forward "[^\000-\377]" nil t))))
4543 (mm-disable-multibyte)
4544 (if (or (not message-send-mail-partially-limit)
4545 (< (buffer-size) message-send-mail-partially-limit)
4546 (not (message-y-or-n-p
4547 "The message size is too large, split? "
4551 (/ (buffer-size) 1000) "KB, is too large.
4553 Some mail gateways (MTA's) bounce large messages. To avoid the
4554 problem, answer `y', and the message will be split into several
4555 smaller pieces, the size of each is about "
4556 (/ message-send-mail-partially-limit 1000)
4560 However, some mail readers (MUA's) can't read split messages, i.e.,
4561 mails in message/partially format. Answer `n', and the message will be
4564 The size limit is controlled by `message-send-mail-partially-limit'.
4565 If you always want Gnus to send messages in one piece, set
4566 `message-send-mail-partially-limit' to nil.
4569 (message "Sending via mail...")
4570 (funcall (or message-send-mail-real-function
4571 message-send-mail-function)))
4572 (message-send-mail-partially)))
4573 (kill-buffer tembuf))
4574 (set-buffer mailbuf)
4575 (push 'mail message-sent-message-via)))
4577 (defun message-send-mail-with-sendmail ()
4578 "Send off the prepared buffer with sendmail."
4580 (let ((errbuf (if message-interactive
4581 (message-generate-new-buffer-clone-locals
4584 resend-to-addresses delimline)
4587 (let ((case-fold-search t))
4589 (message-narrow-to-headers)
4590 (setq resend-to-addresses (message-fetch-field "resent-to")))
4591 ;; Change header-delimiter to be what sendmail expects.
4592 (goto-char (point-min))
4594 (concat "^" (regexp-quote mail-header-separator) "\n"))
4595 (replace-match "\n")
4597 (setq delimline (point-marker))
4598 (run-hooks 'message-send-mail-hook)
4599 ;; Insert an extra newline if we need it to work around
4600 ;; Sun's bug that swallows newlines.
4601 (goto-char (1+ delimline))
4602 (when (eval message-mailer-swallows-blank-line)
4604 (when message-interactive
4605 (with-current-buffer errbuf
4607 (let* ((default-directory "/")
4608 (coding-system-for-write message-send-coding-system)
4610 'call-process-region
4612 (list (point-min) (point-max)
4613 (cond ((boundp 'sendmail-program)
4615 ((file-exists-p "/usr/sbin/sendmail")
4616 "/usr/sbin/sendmail")
4617 ((file-exists-p "/usr/lib/sendmail")
4618 "/usr/lib/sendmail")
4619 ((file-exists-p "/usr/ucblib/sendmail")
4620 "/usr/ucblib/sendmail")
4622 nil errbuf nil "-oi")
4623 message-sendmail-extra-arguments
4624 ;; Always specify who from,
4625 ;; since some systems have broken sendmails.
4626 ;; But some systems are more broken with -f, so
4627 ;; we'll let users override this.
4628 (and (null message-sendmail-f-is-evil)
4629 (list "-f" (message-sendmail-envelope-from)))
4630 ;; These mean "report errors by mail"
4631 ;; and "deliver in background".
4632 (if (null message-interactive) '("-oem" "-odb"))
4633 ;; Get the addresses from the message
4634 ;; unless this is a resend.
4635 ;; We must not do that for a resend
4636 ;; because we would find the original addresses.
4637 ;; For a resend, include the specific addresses.
4638 (if resend-to-addresses
4639 (list resend-to-addresses)
4641 (unless (or (null cpr) (and (numberp cpr) (zerop cpr)))
4642 (if errbuf (pop-to-buffer errbuf))
4643 (error "Sending...failed with exit value %d" cpr)))
4644 (when message-interactive
4645 (with-current-buffer errbuf
4646 (goto-char (point-min))
4647 (while (re-search-forward "\n+ *" nil t)
4648 (replace-match "; "))
4649 (if (not (zerop (buffer-size)))
4650 (error "Sending...failed to %s"
4651 (buffer-string))))))
4652 (when (bufferp errbuf)
4653 (kill-buffer errbuf)))))
4655 (defun message-send-mail-with-qmail ()
4656 "Pass the prepared message buffer to qmail-inject.
4657 Refer to the documentation for the variable `message-send-mail-function'
4658 to find out how to use this."
4659 ;; replace the header delimiter with a blank line
4660 (goto-char (point-min))
4662 (concat "^" (regexp-quote mail-header-separator) "\n"))
4663 (replace-match "\n")
4664 (run-hooks 'message-send-mail-hook)
4667 (let ((coding-system-for-write message-send-coding-system))
4669 'call-process-region (point-min) (point-max)
4670 message-qmail-inject-program nil nil nil
4671 ;; qmail-inject's default behavior is to look for addresses on the
4672 ;; command line; if there're none, it scans the headers.
4673 ;; yes, it does The Right Thing w.r.t. Resent-To and it's kin.
4675 ;; in general, ALL of qmail-inject's defaults are perfect for simply
4676 ;; reading a formatted (i. e., at least a To: or Resent-To header)
4677 ;; message from stdin.
4679 ;; qmail also has the advantage of not having been raped by
4680 ;; various vendors, so we don't have to allow for that, either --
4681 ;; compare this with message-send-mail-with-sendmail and weep
4682 ;; for sendmail's lost innocence.
4684 ;; all this is way cool coz it lets us keep the arguments entirely
4685 ;; free for -inject-arguments -- a big win for the user and for us
4686 ;; since we don't have to play that double-guessing game and the user
4687 ;; gets full control (no gestapo'ish -f's, for instance). --sj
4688 (if (functionp message-qmail-inject-args)
4689 (funcall message-qmail-inject-args)
4690 message-qmail-inject-args)))
4691 ;; qmail-inject doesn't say anything on it's stdout/stderr,
4692 ;; we have to look at the retval instead
4694 (100 (error "qmail-inject reported permanent failure"))
4695 (111 (error "qmail-inject reported transient failure"))
4696 ;; should never happen
4697 (t (error "qmail-inject reported unknown failure"))))
4699 (defun message-send-mail-with-mh ()
4700 "Send the prepared message buffer with mh."
4701 (let ((mh-previous-window-config nil)
4702 (name (mh-new-draft-name)))
4703 (setq buffer-file-name name)
4704 ;; MH wants to generate these headers itself.
4705 (when message-mh-deletable-headers
4706 (let ((headers message-mh-deletable-headers))
4708 (goto-char (point-min))
4709 (and (re-search-forward
4710 (concat "^" (symbol-name (car headers)) ": *") nil t)
4711 (message-delete-line))
4713 (run-hooks 'message-send-mail-hook)
4714 ;; Pass it on to mh.
4717 (defun message-smtpmail-send-it ()
4718 "Send the prepared message buffer with `smtpmail-send-it'.
4719 The only difference from `smtpmail-send-it' is that this command
4720 evaluates `message-send-mail-hook' just before sending a message.
4721 It is useful if your ISP requires the POP-before-SMTP
4722 authentication. See the Gnus manual for details."
4723 (run-hooks 'message-send-mail-hook)
4726 (defun message-send-mail-with-mailclient ()
4727 "Send the prepared message buffer with `mailclient-send-it'.
4728 The only difference from `mailclient-send-it' is that this
4729 command evaluates `message-send-mail-hook' just before sending a message."
4730 (run-hooks 'message-send-mail-hook)
4731 (mailclient-send-it))
4733 (defun message-canlock-generate ()
4734 "Return a string that is non-trivial to guess.
4735 Do not use this for anything important, it is cryptographically weak."
4737 (let (sha1-maximum-internal-length)
4738 (sha1 (concat (message-unique-id)
4739 (format "%x%x%x" (random) (random t) (random))
4740 (prin1-to-string (recent-keys))
4741 (prin1-to-string (garbage-collect))))))
4743 (defvar canlock-password)
4744 (defvar canlock-password-for-verify)
4746 (defun message-canlock-password ()
4747 "The password used by message for cancel locks.
4748 This is the value of `canlock-password', if that option is non-nil.
4749 Otherwise, generate and save a value for `canlock-password' first."
4751 (unless canlock-password
4752 (customize-save-variable 'canlock-password (message-canlock-generate))
4753 (setq canlock-password-for-verify canlock-password))
4756 (defun message-insert-canlock ()
4757 (when message-insert-canlock
4758 (message-canlock-password)
4759 (canlock-insert-header)))
4761 (autoload 'nnheader-get-report "nnheader")
4763 (declare-function gnus-setup-posting-charset "gnus-msg" (group))
4765 (defun message-send-news (&optional arg)
4767 (let* ((tembuf (message-generate-new-buffer-clone-locals " *message temp*"))
4768 (case-fold-search nil)
4769 (method (if (functionp message-post-method)
4770 (funcall message-post-method arg)
4771 message-post-method))
4772 (newsgroups-field (save-restriction
4773 (message-narrow-to-headers-or-head)
4774 (message-fetch-field "Newsgroups")))
4775 (followup-field (save-restriction
4776 (message-narrow-to-headers-or-head)
4777 (message-fetch-field "Followup-To")))
4778 ;; BUG: We really need to get the charset for each name in the
4779 ;; Newsgroups and Followup-To lines to allow crossposting
4780 ;; between group namess with incompatible character sets.
4781 ;; -- Per Abrahamsen <abraham@dina.kvl.dk> 2001-10-08.
4782 (group-field-charset
4783 (gnus-group-name-charset method newsgroups-field))
4784 (followup-field-charset
4785 (gnus-group-name-charset method (or followup-field "")))
4786 (rfc2047-header-encoding-alist
4787 (append (when group-field-charset
4788 (list (cons "Newsgroups" group-field-charset)))
4789 (when followup-field-charset
4790 (list (cons "Followup-To" followup-field-charset)))
4791 rfc2047-header-encoding-alist))
4792 (messbuf (current-buffer))
4793 (message-syntax-checks
4795 (listp message-syntax-checks))
4796 (cons '(existing-newsgroups . disabled)
4797 message-syntax-checks)
4798 message-syntax-checks))
4799 (message-this-is-news t)
4800 (message-posting-charset
4801 (gnus-setup-posting-charset newsgroups-field))
4803 (if (not (message-check-news-body-syntax))
4806 (message-narrow-to-headers)
4807 ;; Insert some headers.
4808 (message-generate-headers message-required-news-headers)
4809 (message-insert-canlock)
4810 ;; Let the user do all of the above.
4811 (run-hooks 'message-header-hook))
4812 ;; Note: This check will be disabled by the ".*" default value for
4813 ;; gnus-group-name-charset-group-alist. -- Pa 2001-10-07.
4814 (when (and group-field-charset
4815 (listp message-syntax-checks))
4816 (setq message-syntax-checks
4817 (cons '(valid-newsgroups . disabled)
4818 message-syntax-checks)))
4819 (message-cleanup-headers)
4820 (if (not (let ((message-post-method method))
4821 (message-check-news-syntax)))
4824 (with-current-buffer tembuf
4825 (buffer-disable-undo)
4827 ;; Avoid copying text props (except hard newlines).
4829 (with-current-buffer messbuf
4830 (mml-buffer-substring-no-properties-except-hard-newlines
4831 (point-min) (point-max))))
4832 (message-encode-message-body)
4833 ;; Remove some headers.
4835 (message-narrow-to-headers)
4836 ;; We (re)generate the Lines header.
4837 (when (memq 'Lines message-required-mail-headers)
4838 (message-generate-headers '(Lines)))
4839 ;; Remove some headers.
4840 (message-remove-header message-ignored-news-headers t)
4841 (let ((mail-parse-charset message-default-charset))
4842 (mail-encode-encoded-word-buffer)))
4843 (goto-char (point-max))
4844 ;; require one newline at the end.
4845 (or (= (preceding-char) ?\n)
4847 (let ((case-fold-search t))
4848 ;; Remove the delimiter.
4849 (goto-char (point-min))
4851 (concat "^" (regexp-quote mail-header-separator) "\n"))
4852 (replace-match "\n")
4854 (run-hooks 'message-send-news-hook)
4855 (gnus-open-server method)
4856 (message "Sending news via %s..." (gnus-server-string method))
4857 (setq result (let ((mail-header-separator ""))
4858 (gnus-request-post method))))
4859 (kill-buffer tembuf))
4860 (set-buffer messbuf)
4862 (push 'news message-sent-message-via)
4863 (message "Couldn't send message via news: %s"
4864 (nnheader-get-report (car method)))
4868 ;;; Header generation & syntax checking.
4871 (defun message-check-element (type)
4872 "Return non-nil if this TYPE is not to be checked."
4873 (if (eq message-syntax-checks 'dont-check-for-anything-just-trust-me)
4875 (let ((able (assq type message-syntax-checks)))
4877 (eq (cdr able) 'disabled)))))
4879 (defun message-check-news-syntax ()
4880 "Check the syntax of the message."
4884 ;; We narrow to the headers and check them first.
4887 (message-narrow-to-headers)
4888 (message-check-news-header-syntax))))))
4890 (defun message-check-news-header-syntax ()
4892 ;; Check Newsgroups header.
4893 (message-check 'newsgroups
4894 (let ((group (message-fetch-field "newsgroups")))
4897 (not (string-match "\\`[ \t]*\\'" group)))
4900 "The newsgroups field is empty or missing. Posting is denied.")))))
4901 ;; Check the Subject header.
4902 (message-check 'subject
4903 (let* ((case-fold-search t)
4904 (subject (message-fetch-field "subject")))
4907 (not (string-match "\\`[ \t]*\\'" subject)))
4910 "The subject field is empty or missing. Posting is denied.")))))
4911 ;; Check for commands in Subject.
4912 (message-check 'subject-cmsg
4913 (if (string-match "^cmsg " (message-fetch-field "subject"))
4915 "The control code \"cmsg\" is in the subject. Really post? ")
4917 ;; Check long header lines.
4918 (message-check 'long-header-lines
4919 (let ((start (point))
4923 (while (and (not found)
4924 (re-search-forward "^\\([^ \t:]+\\): " nil t))
4925 (if (> (- (point) (match-beginning 0)) 998)
4927 length (- (point) (match-beginning 0)))
4928 (setq header (match-string-no-properties 1)))
4929 (setq start (match-beginning 0))
4932 (y-or-n-p (format "Your %s header is too long (%d). Really post? "
4935 ;; Check for multiple identical headers.
4936 (message-check 'multiple-headers
4938 (while (and (not found)
4939 (re-search-forward "^[^ \t:]+: " nil t))
4941 (or (re-search-forward
4946 (match-beginning 0) (- (match-end 0) 2))))
4951 (y-or-n-p (format "Multiple %s headers. Really post? " found))
4953 ;; Check for Version and Sendsys.
4954 (message-check 'sendsys
4955 (if (re-search-forward "^Sendsys:\\|^Version:" nil t)
4957 (format "The article contains a %s command. Really post? "
4958 (buffer-substring (match-beginning 0)
4959 (1- (match-end 0)))))
4961 ;; See whether we can shorten Followup-To.
4962 (message-check 'shorten-followup-to
4963 (let ((newsgroups (message-fetch-field "newsgroups"))
4964 (followup-to (message-fetch-field "followup-to"))
4966 (when (and newsgroups
4967 (string-match "," newsgroups)
4972 (setq to (completing-read
4973 "Followups to (default no Followup-To header): "
4976 (message-tokenize-header
4978 (goto-char (point-min))
4979 (insert "Followup-To: " to "\n"))
4981 ;; Check "Shoot me".
4982 (message-check 'shoot
4983 (if (re-search-forward
4984 "Message-ID.*.i-did-not-set--mail-host-address--so-tickle-me" nil t)
4985 (y-or-n-p "You appear to have a misconfigured system. Really post? ")
4987 ;; Check for Approved.
4988 (message-check 'approved
4989 (if (re-search-forward "^Approved:" nil t)
4990 (y-or-n-p "The article contains an Approved header. Really post? ")
4992 ;; Check the Message-ID header.
4993 (message-check 'message-id
4994 (let* ((case-fold-search t)
4995 (message-id (message-fetch-field "message-id" t)))
4996 (or (not message-id)
4997 ;; Is there an @ in the ID?
4998 (and (string-match "@" message-id)
4999 ;; Is there a dot in the ID?
5000 (string-match "@[^.]*\\." message-id)
5001 ;; Does the ID end with a dot?
5002 (not (string-match "\\.>" message-id)))
5004 (format "The Message-ID looks strange: \"%s\". Really post? "
5006 ;; Check the Newsgroups & Followup-To headers.
5007 (message-check 'existing-newsgroups
5008 (let* ((case-fold-search t)
5009 (newsgroups (message-fetch-field "newsgroups"))
5010 (followup-to (message-fetch-field "followup-to"))
5011 (groups (message-tokenize-header
5013 (concat newsgroups "," followup-to)
5015 (post-method (if (functionp message-post-method)
5016 (funcall message-post-method)
5017 message-post-method))
5018 ;; KLUDGE to handle nnvirtual groups. Doing this right
5019 ;; would probably involve a new nnoo function.
5020 ;; -- Per Abrahamsen <abraham@dina.kvl.dk>, 2001-10-17.
5021 (method (if (and (consp post-method)
5022 (eq (car post-method) 'nnvirtual)
5023 gnus-message-group-art)
5024 (let ((group (car (nnvirtual-find-group-art
5025 (car gnus-message-group-art)
5026 (cdr gnus-message-group-art)))))
5027 (gnus-find-method-for-group group))
5031 (gnus-group-name-decode
5032 (gnus-group-real-name n)
5033 (gnus-group-name-charset method n)))
5034 (gnus-groups-from-server method)))
5037 (when (and (not (equal (car groups) "poster"))
5038 (not (member (car groups) known-groups))
5039 (not (member (car groups) errors)))
5040 (push (car groups) errors))
5043 ;; Gnus is not running.
5044 ((or (not (and (boundp 'gnus-active-hashtb)
5045 gnus-active-hashtb))
5046 (not (boundp 'gnus-read-active-file)))
5048 ;; We don't have all the group names.
5049 ((and (or (not gnus-read-active-file)
5050 (eq gnus-read-active-file 'some))
5054 "Really use %s possibly unknown group%s: %s? "
5055 (if (= (length errors) 1) "this" "these")
5056 (if (= (length errors) 1) "" "s")
5057 (mapconcat 'identity errors ", "))))
5058 ;; There were no errors.
5061 ;; There are unknown groups.
5065 "Really post to %s unknown group%s: %s? "
5066 (if (= (length errors) 1) "this" "these")
5067 (if (= (length errors) 1) "" "s")
5068 (mapconcat 'identity errors ", ")))))))
5069 ;; Check continuation headers.
5070 (message-check 'continuation-headers
5071 (goto-char (point-min))
5072 (let ((do-posting t))
5073 (while (re-search-forward "^[^ \t\n][^ \t\n:]*[ \t\n]" nil t)
5074 (goto-char (match-beginning 0))
5075 (if (y-or-n-p "Fix continuation lines? ")
5078 (unless (y-or-n-p "Send anyway? ")
5079 (setq do-posting nil))))
5081 ;; Check the Newsgroups & Followup-To headers for syntax errors.
5082 (message-check 'valid-newsgroups
5083 (let ((case-fold-search t)
5084 (headers '("Newsgroups" "Followup-To"))
5086 (while (and headers (not error))
5087 (when (setq header (mail-fetch-field (car headers)))
5091 "\\`\\([-+_&.a-zA-Z0-9]+\\)?\\(,[-+_&.a-zA-Z0-9]+\\)*\\'"
5096 (not (string-match "\\.\\'\\|\\.\\." g)))
5097 (message-tokenize-header header ","))))
5104 (format "The %s header looks odd: \"%s\". Really post? "
5105 (car headers) header)))))
5106 (message-check 'repeated-newsgroups
5107 (let ((case-fold-search t)
5108 (headers '("Newsgroups" "Followup-To"))
5109 header error groups group)
5112 (when (setq header (mail-fetch-field (pop headers)))
5113 (setq groups (message-tokenize-header header ","))
5114 (while (setq group (pop groups))
5115 (when (member group groups)
5121 (format "Group %s is repeated in headers. Really post? " error)))))
5122 ;; Check the From header.
5123 (message-check 'from
5124 (let* ((case-fold-search t)
5125 (from (message-fetch-field "from"))
5129 (message "There is no From line. Posting is denied.")
5131 ((or (not (string-match
5133 (setq ad (nth 1 (mail-extract-address-components
5134 from))))) ;larsi@ifi
5135 (string-match "\\.\\." ad) ;larsi@ifi..uio
5136 (string-match "@\\." ad) ;larsi@.ifi.uio
5137 (string-match "\\.$" ad) ;larsi@ifi.uio.
5138 (not (string-match "^[^@]+@[^@]+$" ad)) ;larsi.ifi.uio
5139 (string-match "(.*).*(.*)" from)) ;(lars) (lars)
5141 "Denied posting -- the From looks strange: \"%s\"." from)
5143 ((let ((addresses (rfc822-addresses from)))
5144 ;; `rfc822-addresses' returns a string if parsing fails.
5145 (while (and (consp addresses)
5146 (not (eq (string-to-char (car addresses)) ?\()))
5147 (setq addresses (cdr addresses)))
5150 "Denied posting -- bad From address: \"%s\"." from)
5153 ;; Check the Reply-To header.
5154 (message-check 'reply-to
5155 (let* ((case-fold-search t)
5156 (reply-to (message-fetch-field "reply-to"))
5161 ((string-match "," reply-to)
5163 (format "Multiple Reply-To addresses: \"%s\". Really post? "
5165 ((or (not (string-match
5167 (setq ad (nth 1 (mail-extract-address-components
5168 reply-to))))) ;larsi@ifi
5169 (string-match "\\.\\." ad) ;larsi@ifi..uio
5170 (string-match "@\\." ad) ;larsi@.ifi.uio
5171 (string-match "\\.$" ad) ;larsi@ifi.uio.
5172 (not (string-match "^[^@]+@[^@]+$" ad)) ;larsi.ifi.uio
5173 (string-match "(.*).*(.*)" reply-to)) ;(lars) (lars)
5176 "The Reply-To looks strange: \"%s\". Really post? "
5180 (defun message-check-news-body-syntax ()
5182 ;; Check for long lines.
5183 (message-check 'long-lines
5184 (goto-char (point-min))
5186 (concat "^" (regexp-quote mail-header-separator) "$"))
5190 "<#\\(/\\)?\\(multipart\\|part\\|external\\|mml\\)")
5193 (< (- (point) p) 80)))
5194 (zerop (forward-line 1))))
5198 "You have lines longer than 79 characters. Really post? ")))
5199 ;; Check whether the article is empty.
5200 (message-check 'empty
5201 (goto-char (point-min))
5203 (concat "^" (regexp-quote mail-header-separator) "$"))
5206 (goto-char (point-max))
5207 (re-search-backward message-signature-separator nil t)
5209 (or (re-search-backward "[^ \n\t]" b t)
5210 (if (message-gnksa-enable-p 'empty-article)
5211 (y-or-n-p "Empty article. Really post? ")
5212 (message "Denied posting -- Empty article.")
5214 ;; Check for control characters.
5215 (message-check 'control-chars
5216 (if (re-search-forward
5217 (mm-string-to-multibyte "[\000-\007\013\015-\032\034-\037\200-\237]")
5220 "The article contains control characters. Really post? ")
5222 ;; Check excessive size.
5223 (message-check 'size
5224 (if (> (buffer-size) 60000)
5226 (format "The article is %d octets long. Really post? "
5229 ;; Check whether any new text has been added.
5230 (message-check 'new-text
5232 (not message-checksum)
5233 (not (eq (message-checksum) message-checksum))
5234 (if (message-gnksa-enable-p 'quoted-text-only)
5236 "It looks like no new text has been added. Really post? ")
5237 (message "Denied posting -- no new text has been added.")
5239 ;; Check the length of the signature.
5240 (message-check 'signature
5241 (let (sig-start sig-end)
5242 (goto-char (point-max))
5243 (if (not (re-search-backward message-signature-separator nil t))
5245 (setq sig-start (1+ (point-at-eol)))
5247 (if (re-search-forward
5248 "<#/?\\(multipart\\|part\\|external\\|mml\\)" nil t)
5249 (- (point-at-bol) 1)
5251 (if (>= (count-lines sig-start sig-end) 5)
5252 (if (message-gnksa-enable-p 'signature)
5254 (format "Signature is excessively long (%d lines). Really post? "
5255 (count-lines sig-start sig-end)))
5256 (message "Denied posting -- Excessive signature.")
5259 ;; Ensure that text follows last quoted portion.
5260 (message-check 'quoting-style
5261 (goto-char (point-max))
5262 (let ((no-problem t))
5263 (when (search-backward-regexp "^>[^\n]*\n" nil t)
5264 (setq no-problem (search-forward-regexp "^[ \t]*[^>\n]" nil t)))
5267 (if (message-gnksa-enable-p 'quoted-text-only)
5268 (y-or-n-p "Your text should follow quoted text. Really post? ")
5270 (goto-char (point-min))
5272 (concat "^" (regexp-quote mail-header-separator) "$"))
5273 (if (search-forward-regexp "^[ \t]*[^>\n]" nil t)
5274 (y-or-n-p "Your text should follow quoted text. Really post? ")
5275 (message "Denied posting -- only quoted text.")
5278 (defun message-checksum ()
5279 "Return a \"checksum\" for the current buffer."
5282 (goto-char (point-min))
5284 (concat "^" (regexp-quote mail-header-separator) "$"))
5286 (when (not (looking-at "[ \t\n]"))
5287 (setq sum (logxor (ash sum 1) (if (natnump sum) 0 1)
5292 (defun message-do-fcc ()
5293 "Process Fcc headers in the current buffer."
5294 (let ((case-fold-search t)
5295 (buf (current-buffer))
5297 (mml-externalize-attachments message-fcc-externalize-attachments))
5300 (message-narrow-to-headers)
5301 (setq file (message-fetch-field "fcc" t)))
5303 (set-buffer (get-buffer-create " *message temp*"))
5305 (insert-buffer-substring buf)
5306 (message-encode-message-body)
5308 (message-narrow-to-headers)
5309 (while (setq file (message-fetch-field "fcc" t))
5311 (message-remove-header "fcc" nil t))
5312 (let ((mail-parse-charset message-default-charset)
5313 (rfc2047-header-encoding-alist
5314 (cons '("Newsgroups" . default)
5315 rfc2047-header-encoding-alist)))
5316 (mail-encode-encoded-word-buffer)))
5317 (goto-char (point-min))
5318 (when (re-search-forward
5319 (concat "^" (regexp-quote mail-header-separator) "$")
5321 (replace-match "" t t ))
5322 ;; Process FCC operations.
5324 (setq file (pop list))
5325 (if (string-match "^[ \t]*|[ \t]*\\(.*\\)[ \t]*$" file)
5326 ;; Pipe the article to the program in question.
5327 (call-process-region (point-min) (point-max) shell-file-name
5328 nil nil nil shell-command-switch
5329 (match-string 1 file))
5330 ;; Save the article.
5331 (setq file (expand-file-name file))
5332 (unless (file-exists-p (file-name-directory file))
5333 (make-directory (file-name-directory file) t))
5334 (if (and message-fcc-handler-function
5335 (not (eq message-fcc-handler-function 'rmail-output)))
5336 (funcall message-fcc-handler-function file)
5337 ;; FIXME this option, rmail-output (also used if
5338 ;; message-fcc-handler-function is nil) is not
5339 ;; documented anywhere AFAICS. It should work in Emacs
5340 ;; 23; I suspect it does not work in Emacs 22.
5341 ;; FIXME I don't see the need for the two different cases here.
5342 ;; mail-use-rfc822 makes no difference (in Emacs 23),and
5343 ;; the third argument just controls \"Wrote file\" message.
5344 (if (and (file-readable-p file) (mail-file-babyl-p file))
5345 (rmail-output file 1 nil t)
5346 (let ((mail-use-rfc822 t))
5347 (rmail-output file 1 t t))))))
5348 (kill-buffer (current-buffer))))))
5350 (defun message-output (filename)
5351 "Append this article to Unix/babyl mail file FILENAME."
5352 (if (or (and (file-readable-p filename)
5353 (mail-file-babyl-p filename))
5354 ;; gnus-output-to-mail does the wrong thing with live, mbox
5355 ;; Rmail buffers in Emacs 23.
5356 ;; http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=597255
5357 (let ((buff (find-buffer-visiting filename)))
5358 (and buff (with-current-buffer buff
5359 (eq major-mode 'rmail-mode)))))
5360 (gnus-output-to-rmail filename t)
5361 (gnus-output-to-mail filename t)))
5363 (defun message-cleanup-headers ()
5364 "Do various automatic cleanups of the headers."
5365 ;; Remove empty lines in the header.
5367 (message-narrow-to-headers)
5368 ;; Remove blank lines.
5369 (while (re-search-forward "^[ \t]*\n" nil t)
5370 (replace-match "" t t))
5372 ;; Correct Newsgroups and Followup-To headers: Change sequence of
5373 ;; spaces to comma and eliminate spaces around commas. Eliminate
5374 ;; embedded line breaks.
5375 (goto-char (point-min))
5376 (while (re-search-forward "^\\(Newsgroups\\|Followup-To\\): +" nil t)
5380 (if (re-search-forward "^[^ \t]" nil t)
5384 (goto-char (point-min))
5385 (while (re-search-forward "\n[ \t]+" nil t)
5386 (replace-match " " t t)) ;No line breaks (too confusing)
5387 (goto-char (point-min))
5388 (while (re-search-forward "[ \t\n]*,[ \t\n]*\\|[ \t]+" nil t)
5389 (replace-match "," t t))
5390 (goto-char (point-min))
5391 ;; Remove trailing commas.
5392 (when (re-search-forward ",+$" nil t)
5393 (replace-match "" t t))))))
5395 (defun message-make-date (&optional now)
5396 "Make a valid data header.
5397 If NOW, use that time instead."
5398 (let ((system-time-locale "C"))
5399 (format-time-string "%a, %d %b %Y %T %z" now)))
5401 (defun message-insert-expires (days)
5402 "Insert the Expires header. Expiry in DAYS days."
5403 (interactive "NExpire article in how many days? ")
5405 (message-position-on-field "Expires" "X-Draft-From")
5406 (insert (message-make-expires-date days))))
5408 (defun message-make-expires-date (days)
5409 "Make date string for the Expires header. Expiry in DAYS days.
5411 In posting styles use `(\"Expires\" (make-expires-date 30))'."
5412 (let* ((cur (decode-time (current-time)))
5413 (nday (+ days (nth 3 cur))))
5414 (setf (nth 3 cur) nday)
5415 (message-make-date (apply 'encode-time cur))))
5417 (defun message-make-message-id ()
5418 "Make a unique Message-ID."
5419 (concat "<" (message-unique-id)
5420 (let ((psubject (save-excursion (message-fetch-field "subject")))
5422 (save-excursion (message-fetch-field "supersedes"))))
5424 (and message-reply-headers
5425 (mail-header-references message-reply-headers)
5426 (mail-header-subject message-reply-headers)
5429 (message-strip-subject-re
5430 (mail-header-subject message-reply-headers))
5431 (message-strip-subject-re psubject))))
5433 (string-match "_-_@" psupersedes)))
5435 "@" (message-make-fqdn) ">"))
5437 (defvar message-unique-id-char nil)
5439 ;; If you ever change this function, make sure the new version
5440 ;; cannot generate IDs that the old version could.
5441 ;; You might for example insert a "." somewhere (not next to another dot
5442 ;; or string boundary), or modify the "fsf" string.
5443 (defun message-unique-id ()
5444 ;; Don't use microseconds from (current-time), they may be unsupported.
5445 ;; Instead we use this randomly inited counter.
5446 (setq message-unique-id-char
5447 (% (1+ (or message-unique-id-char (logand (random t) (1- (lsh 1 20)))))
5448 ;; (current-time) returns 16-bit ints,
5449 ;; and 2^16*25 just fits into 4 digits i base 36.
5451 (let ((tm (current-time)))
5453 (if (or (eq system-type 'ms-dos)
5454 ;; message-number-base36 doesn't handle bigints.
5455 (floatp (user-uid)))
5456 (let ((user (downcase (user-login-name))))
5457 (while (string-match "[^a-z0-9_]" user)
5458 (aset user (match-beginning 0) ?_))
5460 (message-number-base36 (user-uid) -1))
5461 (message-number-base36 (+ (car tm)
5462 (lsh (% message-unique-id-char 25) 16)) 4)
5463 (message-number-base36 (+ (nth 1 tm)
5464 (lsh (/ message-unique-id-char 25) 16)) 4)
5465 ;; Append a given name, because while the generated ID is unique
5466 ;; to this newsreader, other newsreaders might otherwise generate
5467 ;; the same ID via another algorithm.
5470 (defun message-number-base36 (num len)
5475 (concat (message-number-base36 (/ num 36) (1- len))
5476 (char-to-string (aref "zyxwvutsrqponmlkjihgfedcba9876543210"
5479 (defun message-make-organization ()
5480 "Make an Organization header."
5481 (let* ((organization
5482 (when message-user-organization
5483 (if (functionp message-user-organization)
5484 (funcall message-user-organization)
5485 message-user-organization))))
5487 (mm-enable-multibyte)
5488 (cond ((stringp organization)
5489 (insert organization))
5490 ((and (eq t organization)
5491 message-user-organization-file
5492 (file-exists-p message-user-organization-file))
5493 (insert-file-contents message-user-organization-file)))
5494 (goto-char (point-min))
5495 (while (re-search-forward "[\t\n]+" nil t)
5496 (replace-match "" t t))
5497 (unless (zerop (buffer-size))
5500 (defun message-make-lines ()
5501 "Count the number of lines and return numeric string."
5506 (int-to-string (count-lines (point) (point-max))))))
5508 (defun message-make-references ()
5509 "Return the References header for this message."
5510 (when message-reply-headers
5511 (let ((message-id (mail-header-id message-reply-headers))
5512 (references (mail-header-references message-reply-headers)))
5513 (if (or references message-id)
5514 (concat (or references "") (and references " ")
5518 (defun message-make-in-reply-to ()
5519 "Return the In-Reply-To header for this message."
5520 (when message-reply-headers
5521 (let ((from (mail-header-from message-reply-headers))
5522 (date (mail-header-date message-reply-headers))
5523 (msg-id (mail-header-id message-reply-headers)))
5525 (let ((name (mail-extract-address-components from)))
5527 msg-id (if msg-id " (")
5529 (if (string-match "[^\000-\177]" (car name))
5530 ;; Quote a string containing non-ASCII characters.
5531 ;; It will make the RFC2047 encoder cause an error
5532 ;; if there are special characters.
5533 (mm-with-multibyte-buffer
5535 (goto-char (point-min))
5536 (while (search-forward "\"" nil t)
5539 (zerop (% (skip-chars-backward "\\\\") 2))
5540 (goto-char (match-beginning 0)))
5543 ;; Those quotes will be removed by the RFC2047 encoder.
5544 (concat "\"" (buffer-string) "\""))
5548 (if (or (not date) (string= date ""))
5549 "(unknown date)" date)
5550 "\"" (if msg-id ")")))))))
5552 (defun message-make-distribution ()
5553 "Make a Distribution header."
5554 (let ((orig-distribution (message-fetch-reply-field "distribution")))
5555 (cond ((functionp message-distribution-function)
5556 (funcall message-distribution-function))
5557 (t orig-distribution))))
5559 (defun message-make-expires ()
5560 "Return an Expires header based on `message-expires'."
5561 (let ((current (current-time))
5562 (future (* 1.0 message-expires 60 60 24)))
5563 ;; Add the future to current.
5564 (setcar current (+ (car current) (round (/ future (expt 2 16)))))
5565 (setcar (cdr current) (+ (nth 1 current) (% (round future) (expt 2 16))))
5566 (message-make-date current)))
5568 (defun message-make-path ()
5570 (let ((login-name (user-login-name)))
5571 (cond ((null message-user-path)
5572 (concat (system-name) "!" login-name))
5573 ((stringp message-user-path)
5574 ;; Support GENERICPATH. Suggested by vixie@decwrl.dec.com.
5575 (concat message-user-path "!" login-name))
5578 (defun message-make-from (&optional name address)
5579 "Make a From header."
5580 (let* ((style message-from-style)
5581 (login (or address (message-make-address)))
5583 (and (boundp 'user-full-name)
5586 (when (string= fullname "&")
5587 (setq fullname (user-login-name)))
5589 (mm-enable-multibyte)
5592 (equal fullname ""))
5594 ((or (eq style 'angles)
5595 (and (not (eq style 'parens))
5596 ;; Use angles if no quoting is needed, or if parens would
5597 ;; need quoting too.
5598 (or (not (string-match "[^- !#-'*+/-9=?A-Z^-~]" fullname))
5599 (let ((tmp (concat fullname nil)))
5600 (while (string-match "([^()]*)" tmp)
5601 (aset tmp (match-beginning 0) ?-)
5602 (aset tmp (1- (match-end 0)) ?-))
5603 (string-match "[\\()]" tmp)))))
5605 (goto-char (point-min))
5606 ;; Look for a character that cannot appear unquoted
5607 ;; according to RFC 822.
5608 (when (re-search-forward "[^- !#-'*+/-9=?A-Z^-~]" nil 1)
5609 ;; Quote fullname, escaping specials.
5610 (goto-char (point-min))
5612 (while (re-search-forward "[\"\\]" nil 1)
5613 (replace-match "\\\\\\&" t))
5615 (insert " <" login ">"))
5616 (t ; 'parens or default
5618 (let ((fullname-start (point)))
5620 (goto-char fullname-start)
5621 ;; RFC 822 says \ and nonmatching parentheses
5622 ;; must be escaped in comments.
5623 ;; Escape every instance of ()\ ...
5624 (while (re-search-forward "[()\\]" nil 1)
5625 (replace-match "\\\\\\&" t))
5626 ;; ... then undo escaping of matching parentheses,
5627 ;; including matching nested parentheses.
5628 (goto-char fullname-start)
5629 (while (re-search-forward
5630 "\\(\\=\\|[^\\]\\(\\\\\\\\\\)*\\)\\\\(\\(\\([^\\]\\|\\\\\\\\\\)*\\)\\\\)"
5632 (replace-match "\\1(\\3)" t)
5633 (goto-char fullname-start)))
5637 (defun message-make-sender ()
5638 "Return the \"real\" user address.
5639 This function tries to ignore all user modifications, and
5640 give as trustworthy answer as possible."
5641 (concat (user-login-name) "@" (system-name)))
5643 (defun message-make-address ()
5644 "Make the address of the user."
5645 (or (message-user-mail-address)
5646 (concat (user-login-name) "@" (message-make-domain))))
5648 (defun message-user-mail-address ()
5649 "Return the pertinent part of `user-mail-address'."
5650 (when (and user-mail-address
5651 (string-match "@.*\\." user-mail-address))
5652 (if (string-match " " user-mail-address)
5653 (nth 1 (mail-extract-address-components user-mail-address))
5654 user-mail-address)))
5656 (defun message-sendmail-envelope-from ()
5657 "Return the envelope from."
5658 (cond ((eq message-sendmail-envelope-from 'header)
5659 (nth 1 (mail-extract-address-components
5660 (message-fetch-field "from"))))
5661 ((stringp message-sendmail-envelope-from)
5662 message-sendmail-envelope-from)
5664 (message-make-address))))
5666 (defun message-make-fqdn ()
5667 "Return user's fully qualified domain name."
5668 (let* ((system-name (system-name))
5669 (user-mail (message-user-mail-address))
5672 (string-match "@\\(.*\\)\\'" user-mail))
5673 (match-string 1 user-mail)))
5674 (case-fold-search t))
5676 ((and message-user-fqdn
5677 (stringp message-user-fqdn)
5678 (string-match message-valid-fqdn-regexp message-user-fqdn)
5679 (not (string-match message-bogus-system-names message-user-fqdn)))
5680 ;; `message-user-fqdn' seems to be valid
5682 ((and (string-match message-valid-fqdn-regexp system-name)
5683 (not (string-match message-bogus-system-names system-name)))
5684 ;; `system-name' returned the right result.
5686 ;; Try `mail-host-address'.
5687 ((and (boundp 'mail-host-address)
5688 (stringp mail-host-address)
5689 (string-match message-valid-fqdn-regexp mail-host-address)
5690 (not (string-match message-bogus-system-names mail-host-address)))
5692 ;; We try `user-mail-address' as a backup.
5694 (stringp user-domain)
5695 (string-match message-valid-fqdn-regexp user-domain)
5696 (not (string-match message-bogus-system-names user-domain)))
5698 ;; Default to this bogus thing.
5701 ".i-did-not-set--mail-host-address--so-tickle-me")))))
5703 (defun message-make-host-name ()
5704 "Return the name of the host."
5705 (let ((fqdn (message-make-fqdn)))
5706 (string-match "^[^.]+\\." fqdn)
5707 (substring fqdn 0 (1- (match-end 0)))))
5709 (defun message-make-domain ()
5710 "Return the domain name."
5711 (or mail-host-address
5712 (message-make-fqdn)))
5714 (defun message-to-list-only ()
5715 "Send a message to the list only.
5716 Remove all addresses but the list address from To and Cc headers."
5718 (let ((listaddr (message-make-mail-followup-to t)))
5721 (message-remove-header "to")
5722 (message-remove-header "cc")
5723 (message-position-on-field "To" "X-Draft-From")
5724 (insert listaddr)))))
5726 (defun message-make-mail-followup-to (&optional only-show-subscribed)
5727 "Return the Mail-Followup-To header.
5728 If passed the optional argument ONLY-SHOW-SUBSCRIBED only return the
5729 subscribed address (and not the additional To and Cc header contents)."
5730 (let* ((case-fold-search t)
5731 (to (message-fetch-field "To"))
5732 (cc (message-fetch-field "cc"))
5733 (msg-recipients (concat to (and to cc ", ") cc))
5735 (mapcar 'mail-strip-quoted-names
5736 (message-tokenize-header msg-recipients)))
5738 (if message-subscribed-address-file
5739 (let (begin end item re)
5742 (insert-file-contents message-subscribed-address-file)
5744 (setq begin (point))
5747 (if (bolp) (setq end (1- end)))
5748 (setq item (regexp-quote (buffer-substring begin end)))
5749 (if re (setq re (concat re "\\|" item))
5750 (setq re (concat "\\`\\(" item))))
5751 (and re (list (concat re "\\)\\'"))))))))
5752 (mft-regexps (apply 'append message-subscribed-regexps
5753 (mapcar 'regexp-quote
5754 message-subscribed-addresses)
5757 message-subscribed-address-functions))))
5760 (loop for recipient in recipients
5761 when (loop for regexp in mft-regexps
5762 when (string-match regexp recipient) return t)
5765 (if only-show-subscribed
5767 msg-recipients))))))
5769 (defun message-idna-to-ascii-rhs-1 (header)
5770 "Interactively potentially IDNA encode domain names in HEADER."
5771 (let ((field (message-fetch-field header))
5775 (mm-delete-duplicates
5776 (mapcar (lambda (rhs) (or (cadr (split-string rhs "@")) ""))
5780 (mail-extract-address-components field t))))))
5781 ;; Note that `rhs' will be "" if the address does not have
5782 ;; the domain part, i.e., if it is a local user's address.
5783 (setq ace (if (string-match "\\`[[:ascii:]]*\\'" rhs)
5785 (downcase (idna-to-ascii rhs))))
5786 (when (and (not (equal rhs ace))
5787 (or (not (eq message-use-idna 'ask))
5788 (y-or-n-p (format "Replace %s with %s in %s:? "
5790 (goto-char (point-min))
5791 (while (re-search-forward (concat "^" header ":") nil t)
5792 (message-narrow-to-field)
5793 (while (search-forward (concat "@" rhs) nil t)
5794 (replace-match (concat "@" ace) t t))
5795 (goto-char (point-max))
5798 (defun message-idna-to-ascii-rhs ()
5799 "Possibly IDNA encode non-ASCII domain names in From:, To: and Cc: headers.
5800 See `message-idna-encode'."
5802 (when message-use-idna
5805 ;; `message-narrow-to-head' that recognizes only the first empty
5806 ;; line as the message header separator used to be used here.
5807 ;; However, since there is the "--text follows this line--" line
5808 ;; normally, it failed in narrowing to the headers and potentially
5809 ;; caused the IDNA encoding on lines that look like headers in
5810 ;; the message body.
5811 (message-narrow-to-headers-or-head)
5812 (message-idna-to-ascii-rhs-1 "From")
5813 (message-idna-to-ascii-rhs-1 "To")
5814 (message-idna-to-ascii-rhs-1 "Reply-To")
5815 (message-idna-to-ascii-rhs-1 "Mail-Reply-To")
5816 (message-idna-to-ascii-rhs-1 "Mail-Followup-To")
5817 (message-idna-to-ascii-rhs-1 "Cc")))))
5819 (defun message-generate-headers (headers)
5820 "Prepare article HEADERS.
5821 Headers already prepared in the buffer are not modified."
5822 (setq headers (append headers message-required-headers))
5824 (message-narrow-to-headers)
5825 (let* ((Date (message-make-date))
5826 (Message-ID (message-make-message-id))
5827 (Organization (message-make-organization))
5828 (From (message-make-from))
5829 (Path (message-make-path))
5832 (In-Reply-To (message-make-in-reply-to))
5833 (References (message-make-references))
5835 (Distribution (message-make-distribution))
5836 (Lines (message-make-lines))
5837 (User-Agent message-newsreader)
5838 (Expires (message-make-expires))
5839 (case-fold-search t)
5841 header value elem header-string)
5842 ;; First we remove any old generated headers.
5843 (let ((headers message-deletable-headers))
5844 (unless (buffer-modified-p)
5845 (setq headers (delq 'Message-ID (copy-sequence headers))))
5847 (goto-char (point-min))
5848 (and (re-search-forward
5849 (concat "^" (symbol-name (car headers)) ": *") nil t)
5850 (get-text-property (1+ (match-beginning 0)) 'message-deletable)
5851 (message-delete-line))
5853 ;; Go through all the required headers and see if they are in the
5854 ;; articles already. If they are not, or are empty, they are
5855 ;; inserted automatically - except for Subject, Newsgroups and
5858 (goto-char (point-min))
5859 (setq elem (pop headers))
5861 (if (eq (car elem) 'optional)
5862 (setq header (cdr elem)
5864 (setq header (car elem)))
5866 (setq header-string (if (stringp header)
5868 (symbol-name header)))
5869 (when (or (not (re-search-forward
5871 (regexp-quote (downcase header-string))
5875 ;; The header was found. We insert a space after the
5876 ;; colon, if there is none.
5877 (if (/= (char-after) ? ) (insert " ") (forward-char 1))
5878 ;; Find out whether the header is empty.
5879 (looking-at "[ \t]*\n[^ \t]")))
5880 ;; So we find out what value we should insert.
5884 (eq (car elem) 'optional)
5885 (not (member header-string message-inserted-headers)))
5886 ;; This is an optional header. If the cdr of this
5887 ;; is something that is nil, then we do not insert
5889 (setq header (cdr elem))
5890 (or (and (functionp (cdr elem))
5891 (funcall (cdr elem)))
5892 (and (boundp (cdr elem))
5893 (symbol-value (cdr elem)))))
5895 ;; The element is a cons. Either the cdr is a
5896 ;; string to be inserted verbatim, or it is a
5897 ;; function, and we insert the value returned from
5899 (or (and (stringp (cdr elem))
5901 (and (functionp (cdr elem))
5902 (funcall (cdr elem)))))
5903 ((and (boundp header)
5904 (symbol-value header))
5905 ;; The element is a symbol. We insert the value
5906 ;; of this symbol, if any.
5907 (symbol-value header))
5908 ((not (message-check-element
5909 (intern (downcase (symbol-name header)))))
5910 ;; We couldn't generate a value for this header,
5911 ;; so we just ask the user.
5912 (read-from-minibuffer
5913 (format "Empty header for %s; enter value: " header)))))
5914 ;; Finally insert the header.
5916 (not (equal value "")))
5920 ;; This header didn't exist, so we insert it.
5921 (goto-char (point-max))
5923 (cdr (assq header message-header-format-alist))))
5925 (funcall formatter header value)
5926 (insert header-string ": " value))
5927 (push header-string message-inserted-headers)
5928 (goto-char (message-fill-field))
5929 ;; We check whether the value was ended by a
5930 ;; newline. If not, we insert one.
5934 ;; The value of this header was empty, so we clear
5935 ;; totally and insert the new value.
5936 (delete-region (point) (point-at-eol))
5937 ;; If the header is optional, and the header was
5938 ;; empty, we can't insert it anyway.
5940 (push header-string message-inserted-headers)
5942 (message-fill-field)))
5943 ;; Add the deletable property to the headers that require it.
5944 (and (memq header message-deletable-headers)
5945 (progn (beginning-of-line) (looking-at "[^:]+: "))
5946 (add-text-properties
5947 (point) (match-end 0)
5948 '(message-deletable t face italic) (current-buffer)))))))
5949 ;; Insert new Sender if the From is strange.
5950 (let ((from (message-fetch-field "from"))
5951 (sender (message-fetch-field "sender"))
5952 (secure-sender (message-make-sender)))
5954 (not (message-check-element 'sender))
5957 (cadr (mail-extract-address-components from)))
5958 (downcase secure-sender)))
5963 (cadr (mail-extract-address-components sender)))
5964 (downcase secure-sender)))))
5965 (goto-char (point-min))
5966 ;; Rename any old Sender headers to Original-Sender.
5967 (when (re-search-forward "^\\(Original-\\)*Sender:" nil t)
5969 (insert "Original-")
5970 (beginning-of-line))
5971 (when (or (message-news-p)
5972 (string-match "@.+\\.." secure-sender))
5973 (insert "Sender: " secure-sender "\n"))))
5975 (message-idna-to-ascii-rhs))))
5977 (defun message-insert-courtesy-copy ()
5978 "Insert a courtesy message in mail copies of combined messages."
5982 (message-narrow-to-headers)
5983 (when (setq newsgroups (message-fetch-field "newsgroups"))
5984 (goto-char (point-max))
5985 (insert "Posted-To: " newsgroups "\n")))
5987 (when message-courtesy-message
5989 ((string-match "%s" message-courtesy-message)
5990 (insert (format message-courtesy-message newsgroups)))
5992 (insert message-courtesy-message)))))))
5995 ;;; Setting up a message buffer
5998 (defun message-skip-to-next-address ()
5999 (let ((end (save-excursion
6000 (message-next-header)
6003 (when (looking-at ",")
6005 (while (and (not (= (point) end))
6006 (or (not (eq char ?,))
6008 (skip-chars-forward "^,\"" (point-max))
6009 (when (eq (setq char (following-char)) ?\")
6010 (setq quoted (not quoted)))
6011 (unless (= (point) end)
6013 (skip-chars-forward " \t\n")))
6015 (defun message-fill-address (header value)
6016 (insert (capitalize (symbol-name header))
6018 (if (consp value) (car value) value)
6020 (message-fill-field-address))
6022 (defun message-split-line ()
6023 "Split current line, moving portion beyond point vertically down.
6024 If the current line has `message-yank-prefix', insert it on the new line."
6027 (split-line message-yank-prefix) ;; Emacs 22.1+ supports arg.
6031 (defun message-insert-header (header value)
6032 (insert (capitalize (symbol-name header))
6034 (if (consp value) (car value) value)))
6036 (defun message-field-name ()
6038 (goto-char (point-min))
6039 (when (looking-at "\\([^:]+\\):")
6040 (intern (capitalize (match-string 1))))))
6042 (defun message-fill-field ()
6045 (message-narrow-to-field)
6046 (let ((field-name (message-field-name)))
6047 (funcall (or (cadr (assq field-name message-field-fillers))
6048 'message-fill-field-general)))
6051 (defun message-fill-field-address ()
6053 (message-skip-to-next-address)
6055 (if (and (> (current-column) 78)
6061 (setq last (1+ (point))))
6062 (setq last (1+ (point)))))))
6064 (defun message-fill-field-general ()
6065 (let ((begin (point))
6068 (while (and (search-forward "\n" nil t)
6070 (replace-match " " t t))
6071 (fill-region-as-paragraph begin (point-max))
6072 ;; Tapdance around looong Message-IDs.
6074 (when (looking-at "[ \t]*$")
6075 (message-delete-line))
6077 (search-forward ":" nil t)
6078 (when (looking-at "\n[ \t]+")
6079 (replace-match " " t t))
6080 (goto-char (point-max))))
6082 (defun message-shorten-1 (list cut surplus)
6083 "Cut SURPLUS elements out of LIST, beginning with CUTth one."
6084 (setcdr (nthcdr (- cut 2) list)
6085 (nthcdr (+ (- cut 2) surplus 1) list)))
6087 (defun message-shorten-references (header references)
6088 "Trim REFERENCES to be 21 Message-ID long or less, and fold them.
6089 When sending via news, also check that the REFERENCES are less
6090 than 988 characters long, and if they are not, trim them until
6098 (goto-char (point-min))
6099 ;; Cons a list of valid references. GNKSA says we must not include MIDs
6100 ;; with whitespace or missing brackets (7.a "Does not propagate broken
6101 ;; Message-IDs in original References").
6102 (while (re-search-forward "<[^ <]+@[^ <]+>" nil t)
6103 (push (match-string 0) refs))
6104 (setq refs (nreverse refs)
6105 count (length refs)))
6107 ;; If the list has more than MAXCOUNT elements, trim it by
6108 ;; removing the CUTth element and the required number of
6109 ;; elements that follow.
6110 (when (> count maxcount)
6111 (let ((surplus (- count maxcount)))
6112 (message-shorten-1 refs cut surplus)
6113 (decf count surplus)))
6115 ;; When sending via news, make sure the total folded length will
6116 ;; be less than 998 characters. This is to cater to broken INN
6117 ;; 2.3 which counts the total number of characters in a header
6118 ;; rather than the physical line length of each line, as it should.
6120 ;; This hack should be removed when it's believed than INN 2.3 is
6121 ;; no longer widely used.
6123 ;; At this point the headers have not been generated, thus we use
6124 ;; message-this-is-news directly.
6125 (when message-this-is-news
6128 (message-insert-header
6129 header (mapconcat #'identity refs " "))
6131 (message-shorten-1 refs cut 1)))
6132 ;; Finally, collect the references back into a string and insert
6133 ;; it into the buffer.
6134 (message-insert-header header (mapconcat #'identity refs " "))))
6136 (defun message-position-point ()
6137 "Move point to where the user probably wants to find it."
6138 (message-narrow-to-headers)
6140 ((re-search-forward "^[^:]+:[ \t]*$" nil t)
6141 (search-backward ":" )
6144 (if (eq (char-after) ? )
6148 (goto-char (point-max))
6151 (unless (looking-at "$")
6155 (defcustom message-beginning-of-line t
6156 "Whether \\<message-mode-map>\\[message-beginning-of-line]\
6157 goes to beginning of header values."
6159 :group 'message-buffers
6160 :link '(custom-manual "(message)Movement")
6163 (defun message-beginning-of-line (&optional n)
6164 "Move point to beginning of header value or to beginning of line.
6165 The prefix argument N is passed directly to `beginning-of-line'.
6167 This command is identical to `beginning-of-line' if point is
6168 outside the message header or if the option `message-beginning-of-line'
6171 If point is in the message header and on a (non-continued) header
6172 line, move point to the beginning of the header value or the beginning of line,
6173 whichever is closer. If point is already at beginning of line, move point to
6174 beginning of header value. Therefore, repeated calls will toggle point
6175 between beginning of field and beginning of line."
6177 (let ((zrs 'zmacs-region-stays))
6178 (when (and (featurep 'xemacs) (interactive-p) (boundp zrs))
6180 (if (and message-beginning-of-line
6181 (message-point-in-header-p))
6182 (let* ((here (point))
6183 (bol (progn (beginning-of-line n) (point)))
6184 (eol (point-at-eol))
6185 (eoh (re-search-forward ": *" eol t)))
6187 (if (and eoh (or (< eoh here) (= bol here)))
6189 (beginning-of-line n)))
6191 (defun message-buffer-name (type &optional to group)
6192 "Return a new (unique) buffer name based on TYPE and TO."
6194 ;; Generate a new buffer name The Message Way.
6195 ((memq message-generate-new-buffers '(unique t))
6196 (generate-new-buffer-name
6200 (or (car (mail-extract-address-components to))
6203 (if (and group (not (string= group ""))) (concat " on " group) "")
6205 ;; Check whether `message-generate-new-buffers' is a function,
6206 ;; and if so, call it.
6207 ((functionp message-generate-new-buffers)
6208 (funcall message-generate-new-buffers type to group))
6209 ((eq message-generate-new-buffers 'unsent)
6210 (generate-new-buffer-name
6211 (concat "*unsent " type
6214 (or (car (mail-extract-address-components to))
6217 (if (and group (not (string= group ""))) (concat " on " group) "")
6219 ;; Search for the existing message buffer with the specified name.
6221 (let* ((new (if (eq message-generate-new-buffers 'standard)
6222 (generate-new-buffer-name (concat "*" type " message*"))
6223 (let ((message-generate-new-buffers 'unique))
6224 (message-buffer-name type to group))))
6225 (regexp (concat "\\`"
6227 (if (string-match "<[0-9]+>\\'" new)
6228 (substring new 0 (match-beginning 0))
6230 "\\(?:<\\([0-9]+\\)>\\)?\\'"))
6231 (case-fold-search nil))
6238 (when (and (string-match regexp (setq b (buffer-name b)))
6239 (eq (with-current-buffer b major-mode)
6241 (cons (string-to-number (or (match-string 1 b) "1"))
6244 'car-less-than-car)))
6247 (defun message-pop-to-buffer (name &optional switch-function)
6248 "Pop to buffer NAME, and warn if it already exists and is modified."
6249 (let ((buffer (get-buffer name)))
6251 (buffer-name buffer))
6252 (let ((window (get-buffer-window buffer 0)))
6254 ;; Raise the frame already displaying the message buffer.
6256 (gnus-select-frame-set-input-focus (window-frame window))
6257 (select-window window))
6258 (funcall (or switch-function 'pop-to-buffer) buffer)
6259 (set-buffer buffer))
6260 (when (and (buffer-modified-p)
6263 "Message already being composed; erase? ")
6265 (error "Message being composed")))
6266 (funcall (or switch-function 'pop-to-buffer) name)
6271 (defun message-do-send-housekeeping ()
6272 "Kill old message buffers."
6273 ;; We might have sent this buffer already. Delete it from the
6275 (setq message-buffer-list (delq (current-buffer) message-buffer-list))
6276 (while (and message-max-buffers
6278 (>= (length message-buffer-list) message-max-buffers))
6279 ;; Kill the oldest buffer -- unless it has been changed.
6280 (let ((buffer (pop message-buffer-list)))
6281 (when (and (buffer-name buffer)
6282 (not (buffer-modified-p buffer)))
6283 (kill-buffer buffer))))
6284 ;; Rename the buffer.
6285 (if message-send-rename-function
6286 (funcall message-send-rename-function)
6287 ;; Note: mail-abbrevs of XEmacs renames buffer name behind Gnus.
6289 "\\`\\*\\(sent \\|unsent \\)?\\(.+\\)\\*[^\\*]*\\|\\`mail to "
6291 (let ((name (match-string 2 (buffer-name)))
6293 (if (not (or (null name)
6294 (string-equal name "mail")
6295 (string-equal name "posting")))
6296 (setq name (concat "*sent " name "*"))
6297 (message-narrow-to-headers)
6298 (setq to (message-fetch-field "to"))
6299 (setq group (message-fetch-field "newsgroups"))
6303 (to (concat "*sent mail to "
6304 (or (car (mail-extract-address-components to))
6306 ((and group (not (string= group "")))
6307 (concat "*sent posting on " group "*"))
6308 (t "*sent mail*"))))
6309 (unless (string-equal name (buffer-name))
6310 (rename-buffer name t)))))
6311 ;; Push the current buffer onto the list.
6312 (when message-max-buffers
6313 (setq message-buffer-list
6314 (nconc message-buffer-list (list (current-buffer))))))
6316 (defun message-mail-user-agent ()
6318 ((not message-mail-user-agent) nil)
6319 ((eq message-mail-user-agent t) mail-user-agent)
6320 (t message-mail-user-agent))))
6321 (if (memq mua '(message-user-agent gnus-user-agent))
6325 ;; YANK-ACTION, if non-nil, can be a buffer or a yank action of the
6326 ;; form (FUNCTION . ARGS).
6327 (defun message-setup (headers &optional yank-action actions
6328 continue switch-function)
6329 (let ((mua (message-mail-user-agent))
6331 (if (not (and message-this-is-mail mua))
6332 (message-setup-1 headers yank-action actions)
6333 (setq headers (copy-sequence headers))
6334 (setq field (assq 'Subject headers))
6336 (setq subject (cdr field))
6337 (setq headers (delq field headers)))
6338 (setq field (assq 'To headers))
6340 (setq to (cdr field))
6341 (setq headers (delq field headers)))
6342 (let ((mail-user-agent mua))
6343 (compose-mail to subject
6344 (mapcar (lambda (item)
6346 (format "%s" (car item))
6349 continue switch-function
6350 (if (bufferp yank-action)
6351 (list 'insert-buffer yank-action)
6355 (defun message-headers-to-generate (headers included-headers excluded-headers)
6356 "Return a list that includes all headers from HEADERS.
6357 If INCLUDED-HEADERS is a list, just include those headers. If it is
6358 t, include all headers. In any case, headers from EXCLUDED-HEADERS
6362 (dolist (header headers)
6363 (setq header-name (cond
6364 ((and (consp header)
6365 (eq (car header) 'optional))
6366 ;; On the form (optional . Header)
6369 ;; On the form (Header . function)
6374 (when (and (not (memq header-name excluded-headers))
6375 (or (eq included-headers t)
6376 (memq header-name included-headers)))
6377 (push header result)))
6380 (defun message-setup-1 (headers &optional yank-action actions)
6381 (dolist (action actions)
6383 (add-to-list 'message-send-actions
6384 `(apply ',(car action) ',(cdr action)))))
6385 (setq message-reply-buffer
6386 (if (and (consp yank-action)
6387 (eq (car yank-action) 'insert-buffer))
6390 (goto-char (point-min))
6391 ;; Insert all the headers.
6394 (alist message-header-format-alist))
6396 (unless (assq (caar h) message-header-format-alist)
6397 (push (list (caar h)) alist))
6401 (delete-region (point) (progn (forward-line -1) (point)))
6402 (when message-default-headers
6403 (insert message-default-headers)
6404 (or (bolp) (insert ?\n)))
6405 (insert mail-header-separator "\n")
6407 (when (message-news-p)
6408 (when message-default-news-headers
6409 (insert message-default-news-headers)
6410 (or (bolp) (insert ?\n)))
6411 (when message-generate-headers-first
6412 (message-generate-headers
6413 (message-headers-to-generate
6414 (append message-required-news-headers
6415 message-required-headers)
6416 message-generate-headers-first
6417 '(Lines Subject)))))
6418 (when (message-mail-p)
6419 (when message-default-mail-headers
6420 (insert message-default-mail-headers)
6421 (or (bolp) (insert ?\n)))
6422 (when message-generate-headers-first
6423 (message-generate-headers
6424 (message-headers-to-generate
6425 (append message-required-mail-headers
6426 message-required-headers)
6427 message-generate-headers-first
6428 '(Lines Subject)))))
6429 (run-hooks 'message-signature-setup-hook)
6430 (message-insert-signature)
6432 (message-narrow-to-headers)
6433 (run-hooks 'message-header-setup-hook))
6434 (setq buffer-undo-list nil)
6435 (when message-generate-hashcash
6436 ;; Generate hashcash headers for recipients already known
6437 (mail-add-payment-async))
6438 ;; Gnus posting styles are applied via buffer-local `message-setup-hook'
6440 (run-hooks 'message-setup-hook)
6441 ;; Do this last to give it precedence over posting styles, etc.
6442 (when (message-mail-p)
6444 (message-narrow-to-headers)
6445 (if message-alternative-emails
6446 (message-use-alternative-email-as-from))))
6447 (message-position-point)
6448 ;; Allow correct handling of `message-checksum' in `message-yank-original':
6449 (set-buffer-modified-p nil)
6452 (defun message-set-auto-save-file-name ()
6453 "Associate the message buffer with a file in the drafts directory."
6454 (when message-auto-save-directory
6455 (unless (file-directory-p
6456 (directory-file-name message-auto-save-directory))
6457 (make-directory message-auto-save-directory t))
6459 (setq message-draft-article
6460 (nndraft-request-associate-buffer "drafts"))
6462 ;; If Gnus were alive, draft messages would be saved in the drafts folder.
6463 ;; But Gnus is not alive, so arrange to save the draft message in a
6464 ;; regular file in message-auto-save-directory. Append a unique
6465 ;; time-based suffix to the filename to allow multiple drafts to be saved
6466 ;; simultaneously without overwriting each other (which mimics the
6467 ;; functionality of the Gnus drafts folder).
6468 (setq buffer-file-name (expand-file-name
6470 (if (memq system-type
6471 '(ms-dos windows-nt cygwin))
6474 (format-time-string "-%Y%m%d-%H%M%S"))
6475 message-auto-save-directory))
6476 (setq buffer-auto-save-file-name (make-auto-save-file-name)))
6477 (clear-visited-file-modtime)
6478 (setq buffer-file-coding-system message-draft-coding-system)))
6480 (defun message-disassociate-draft ()
6481 "Disassociate the message buffer from the drafts directory."
6482 (when message-draft-article
6483 (nndraft-request-expire-articles
6484 (list message-draft-article) "drafts" nil t)))
6486 (defun message-insert-headers ()
6487 "Generate the headers for the article."
6491 (message-narrow-to-headers)
6492 (when (message-news-p)
6493 (message-generate-headers
6496 (copy-sequence message-required-news-headers)))))
6497 (when (message-mail-p)
6498 (message-generate-headers
6501 (copy-sequence message-required-mail-headers))))))))
6506 ;;; Commands for interfacing with message
6510 (defun message-mail (&optional to subject
6511 other-headers continue switch-function
6512 yank-action send-actions)
6513 "Start editing a mail message to be sent.
6514 OTHER-HEADERS is an alist of header/value pairs. CONTINUE says whether
6515 to continue editing a message already being composed. SWITCH-FUNCTION
6516 is a function used to switch to and display the mail buffer."
6518 (let ((message-this-is-mail t))
6519 (unless (message-mail-user-agent)
6520 (message-pop-to-buffer
6521 ;; Search for the existing message buffer if `continue' is non-nil.
6522 (let ((message-generate-new-buffers
6523 (when (or (not continue)
6524 (eq message-generate-new-buffers 'standard)
6525 (functionp message-generate-new-buffers))
6526 message-generate-new-buffers)))
6527 (message-buffer-name "mail" to))
6531 `((To . ,(or to "")) (Subject . ,(or subject "")))
6532 (when other-headers other-headers))
6533 yank-action send-actions continue switch-function)
6534 ;; FIXME: Should return nil if failure.
6538 (defun message-news (&optional newsgroups subject)
6539 "Start editing a news article to be sent."
6541 (let ((message-this-is-news t))
6542 (message-pop-to-buffer (message-buffer-name "posting" nil newsgroups))
6543 (message-setup `((Newsgroups . ,(or newsgroups ""))
6544 (Subject . ,(or subject ""))))))
6546 (defun message-alter-recipients-discard-bogus-full-name (addrcell)
6547 "Discard mail address in full names.
6548 When the full name in reply headers contains the mail
6549 address (e.g. \"foo@bar <foo@bar>\"), discard full name.
6550 ADDRCELL is a cons cell where the car is the mail address and the
6551 cdr is the complete address (full name and mail address)."
6552 (if (string-match (concat (regexp-quote (car addrcell)) ".*"
6553 (regexp-quote (car addrcell)))
6555 (cons (car addrcell) (car addrcell))
6558 (defcustom message-alter-recipients-function nil
6559 "Function called to allow alteration of reply header structures.
6560 It is called in `message-get-reply-headers' for each recipient.
6561 The function is called with one parameter, a cons cell ..."
6562 :type '(choice (const :tag "None" nil)
6563 (const :tag "Discard bogus full name"
6564 message-alter-recipients-discard-bogus-full-name)
6566 :version "23.1" ;; No Gnus
6567 :group 'message-headers)
6569 (defun message-get-reply-headers (wide &optional to-address address-headers)
6570 (let (follow-to mct never-mct to cc author mft recipients extra)
6571 ;; Find all relevant headers we need.
6573 (message-narrow-to-headers-or-head)
6574 ;; Gmane renames "To". Look at "Original-To", too, if it is present in
6575 ;; message-header-synonyms.
6576 (setq to (or (message-fetch-field "to")
6577 (and (loop for synonym in message-header-synonyms
6578 when (memq 'Original-To synonym)
6580 (message-fetch-field "original-to")))
6581 cc (message-fetch-field "cc")
6582 extra (when message-extra-wide-headers
6583 (mapconcat 'identity
6584 (mapcar 'message-fetch-field
6585 message-extra-wide-headers)
6587 mct (message-fetch-field "mail-copies-to")
6588 author (or (message-fetch-field "mail-reply-to")
6589 (message-fetch-field "reply-to")
6590 (message-fetch-field "from")
6592 mft (and message-use-mail-followup-to
6593 (message-fetch-field "mail-followup-to"))))
6595 ;; Handle special values of Mail-Copies-To.
6597 (cond ((or (equal (downcase mct) "never")
6598 (equal (downcase mct) "nobody"))
6601 ((or (equal (downcase mct) "always")
6602 (equal (downcase mct) "poster"))
6603 (setq mct author))))
6606 ;; Build (textual) list of new recipient addresses.
6609 (setq recipients (concat ", " author)))
6611 (dolist (header address-headers)
6612 (let ((value (message-fetch-field header)))
6614 (setq recipients (concat recipients ", " value))))))
6616 (string-match "[^ \t,]" mft)
6617 (or (not (eq message-use-mail-followup-to 'ask))
6618 (message-y-or-n-p "Obey Mail-Followup-To? " t "\
6619 You should normally obey the Mail-Followup-To: header. In this
6620 article, it has the value of
6624 which directs your response to " (if (string-match "," mft)
6625 "the specified addresses"
6626 "that address only") ".
6628 Most commonly, Mail-Followup-To is used by a mailing list poster to
6629 express that responses should be sent to just the list, and not the
6632 If a message is posted to several mailing lists, Mail-Followup-To may
6633 also be used to direct the following discussion to one list only,
6634 because discussions that are spread over several lists tend to be
6635 fragmented and very difficult to follow.
6637 Also, some source/announcement lists are not intended for discussion;
6638 responses here are directed to other addresses.
6640 You may customize the variable `message-use-mail-followup-to', if you
6641 want to get rid of this query permanently.")))
6642 (setq recipients (concat ", " mft)))
6644 (setq recipients (concat ", " to-address))
6645 ;; If the author explicitly asked for a copy, we don't deny it to them.
6646 (if mct (setq recipients (concat recipients ", " mct))))
6648 (setq recipients (if never-mct "" (concat ", " author)))
6649 (if to (setq recipients (concat recipients ", " to)))
6650 (if cc (setq recipients (concat recipients ", " cc)))
6651 (if extra (setq recipients (concat recipients ", " extra)))
6652 (if mct (setq recipients (concat recipients ", " mct)))))
6653 (if (>= (length recipients) 2)
6654 ;; Strip the leading ", ".
6655 (setq recipients (substring recipients 2)))
6656 ;; Squeeze whitespace.
6657 (while (string-match "[ \t][ \t]+" recipients)
6658 (setq recipients (replace-match " " t t recipients)))
6659 ;; Remove addresses that match `rmail-dont-reply-to-names'.
6660 (let ((rmail-dont-reply-to-names (message-dont-reply-to-names)))
6661 (setq recipients (rmail-dont-reply-to recipients)))
6662 ;; Perhaps "Mail-Copies-To: never" removed the only address?
6663 (if (string-equal recipients "")
6664 (setq recipients author))
6665 ;; Convert string to a list of (("foo@bar" . "Name <Foo@BAR>") ...).
6669 (if message-alter-recipients-function
6670 (funcall message-alter-recipients-function
6671 (cons (downcase (mail-strip-quoted-names addr))
6673 (cons (downcase (mail-strip-quoted-names addr)) addr)))
6674 (message-tokenize-header recipients)))
6675 ;; Remove first duplicates. (Why not all duplicates? Is this a bug?)
6676 (let ((s recipients))
6678 (setq recipients (delq (assoc (car (pop s)) s) recipients))))
6680 ;; Remove hierarchical lists that are contained within each other,
6681 ;; if message-hierarchical-addresses is defined.
6682 (when message-hierarchical-addresses
6683 (let ((plain-addrs (mapcar 'car recipients))
6686 (setq subaddrs (assoc (car plain-addrs)
6687 message-hierarchical-addresses)
6688 plain-addrs (cdr plain-addrs))
6690 (setq subaddrs (cdr subaddrs))
6692 (setq recip (assoc (car subaddrs) recipients)
6693 subaddrs (cdr subaddrs))
6695 (setq recipients (delq recip recipients))))))))
6697 (setq recipients (message-prune-recipients recipients))
6699 ;; Build the header alist. Allow the user to be asked whether
6700 ;; or not to reply to all recipients in a wide reply.
6701 (setq follow-to (list (cons 'To (cdr (pop recipients)))))
6702 (when (and recipients
6703 (or (not message-wide-reply-confirm-recipients)
6704 (y-or-n-p "Reply to all recipients? ")))
6705 (setq recipients (mapconcat
6706 (lambda (addr) (cdr addr)) recipients ", "))
6707 (if (string-match "^ +" recipients)
6708 (setq recipients (substring recipients (match-end 0))))
6709 (push (cons 'Cc recipients) follow-to)))
6712 (defun message-prune-recipients (recipients)
6713 (dolist (rule message-prune-recipient-rules)
6714 (let ((match (car rule))
6717 (dolist (recipient recipients)
6718 (setq address (car recipient))
6719 (when (string-match match address)
6720 (setq dup-match (replace-match (cadr rule) nil nil address))
6721 (dolist (recipient recipients)
6722 ;; Don't delete the address that triggered this.
6723 (when (and (not (eq address (car recipient)))
6724 (string-match dup-match (car recipient)))
6725 (setq recipients (delq recipient recipients))))))))
6728 (defcustom message-simplify-subject-functions
6729 '(message-strip-list-identifiers
6730 message-strip-subject-re
6731 message-strip-subject-trailing-was
6732 message-strip-subject-encoded-words)
6733 "List of functions taking a string argument that simplify subjects.
6734 The functions are applied when replying to a message.
6736 Useful functions to put in this list include:
6737 `message-strip-list-identifiers', `message-strip-subject-re',
6738 `message-strip-subject-trailing-was', and
6739 `message-strip-subject-encoded-words'."
6740 :version "22.1" ;; Gnus 5.10.9
6741 :group 'message-various
6742 :type '(repeat function))
6744 (defun message-simplify-subject (subject &optional functions)
6745 "Return simplified SUBJECT."
6748 (setq functions message-simplify-subject-functions))
6749 (when (and (memq 'message-strip-list-identifiers functions)
6750 gnus-list-identifiers)
6751 (setq subject (message-strip-list-identifiers subject)))
6752 (when (memq 'message-strip-subject-re functions)
6753 (setq subject (concat "Re: " (message-strip-subject-re subject))))
6754 (when (and (memq 'message-strip-subject-trailing-was functions)
6755 message-subject-trailing-was-query)
6756 (setq subject (message-strip-subject-trailing-was subject)))
6757 (when (memq 'message-strip-subject-encoded-words functions)
6758 (setq subject (message-strip-subject-encoded-words subject)))
6762 (defun message-reply (&optional to-address wide)
6763 "Start editing a reply to the article in the current buffer."
6765 (require 'gnus-sum) ; for gnus-list-identifiers
6766 (let ((cur (current-buffer))
6767 from subject date reply-to to cc
6768 references message-id follow-to
6769 (inhibit-point-motion-hooks t)
6770 (message-this-is-mail t)
6773 (message-narrow-to-head-1)
6774 ;; Allow customizations to have their say.
6776 ;; This is a regular reply.
6777 (when (functionp message-reply-to-function)
6779 (setq follow-to (funcall message-reply-to-function))))
6780 ;; This is a followup.
6781 (when (functionp message-wide-reply-to-function)
6784 (funcall message-wide-reply-to-function)))))
6785 (setq message-id (message-fetch-field "message-id" t)
6786 references (message-fetch-field "references")
6787 date (message-fetch-field "date")
6788 from (or (message-fetch-field "from") "nobody")
6789 subject (or (message-fetch-field "subject") "none"))
6791 ;; Strip list identifiers, "Re: ", and "was:"
6792 (setq subject (message-simplify-subject subject))
6794 (when (and (setq gnus-warning (message-fetch-field "gnus-warning"))
6795 (string-match "<[^>]+>" gnus-warning))
6796 (setq message-id (match-string 0 gnus-warning)))
6799 (setq follow-to (message-get-reply-headers wide to-address))))
6801 (unless (message-mail-user-agent)
6802 (message-pop-to-buffer
6803 (message-buffer-name
6804 (if wide "wide reply" "reply") from
6805 (if wide to-address nil))))
6807 (setq message-reply-headers
6808 (vector 0 subject from date message-id references 0 0 ""))
6811 `((Subject . ,subject)
6816 (defun message-wide-reply (&optional to-address)
6817 "Make a \"wide\" reply to the message in the current buffer."
6819 (message-reply to-address t))
6822 (defun message-followup (&optional to-newsgroups)
6823 "Follow up to the message in the current buffer.
6824 If TO-NEWSGROUPS, use that as the new Newsgroups line."
6826 (require 'gnus-sum) ; for gnus-list-identifiers
6827 (let ((cur (current-buffer))
6828 from subject date reply-to mrt mct
6829 references message-id follow-to
6830 (inhibit-point-motion-hooks t)
6831 (message-this-is-news t)
6832 followup-to distribution newsgroups gnus-warning posted-to)
6835 (goto-char (point-min))
6836 (if (search-forward "\n\n" nil t)
6839 (when (functionp message-followup-to-function)
6841 (funcall message-followup-to-function)))
6842 (setq from (message-fetch-field "from")
6843 date (message-fetch-field "date")
6844 subject (or (message-fetch-field "subject") "none")
6845 references (message-fetch-field "references")
6846 message-id (message-fetch-field "message-id" t)
6847 followup-to (message-fetch-field "followup-to")
6848 newsgroups (message-fetch-field "newsgroups")
6849 posted-to (message-fetch-field "posted-to")
6850 reply-to (message-fetch-field "reply-to")
6851 mrt (message-fetch-field "mail-reply-to")
6852 distribution (message-fetch-field "distribution")
6853 mct (message-fetch-field "mail-copies-to"))
6854 (when (and (setq gnus-warning (message-fetch-field "gnus-warning"))
6855 (string-match "<[^>]+>" gnus-warning))
6856 (setq message-id (match-string 0 gnus-warning)))
6857 ;; Remove bogus distribution.
6858 (when (and (stringp distribution)
6859 (let ((case-fold-search t))
6860 (string-match "world" distribution)))
6861 (setq distribution nil))
6862 ;; Strip list identifiers, "Re: ", and "was:"
6863 (setq subject (message-simplify-subject subject))
6866 (message-pop-to-buffer (message-buffer-name "followup" from newsgroups))
6868 (setq message-reply-headers
6869 (vector 0 subject from date message-id references 0 0 ""))
6872 `((Subject . ,subject)
6875 (list (cons 'Newsgroups to-newsgroups)))
6876 (follow-to follow-to)
6877 ((and followup-to message-use-followup-to)
6880 ((equal (downcase followup-to) "poster")
6881 (if (or (eq message-use-followup-to 'use)
6882 (message-y-or-n-p "Obey Followup-To: poster? " t "\
6883 You should normally obey the Followup-To: header.
6885 `Followup-To: poster' sends your response via e-mail instead of news.
6887 A typical situation where `Followup-To: poster' is used is when the poster
6888 does not read the newsgroup, so he wouldn't see any replies sent to it.
6890 You may customize the variable `message-use-followup-to', if you
6891 want to get rid of this query permanently."))
6893 (setq message-this-is-news nil)
6894 (cons 'To (or mrt reply-to from "")))
6895 (cons 'Newsgroups newsgroups)))
6897 (if (or (equal followup-to newsgroups)
6898 (not (eq message-use-followup-to 'ask))
6900 (concat "Obey Followup-To: " followup-to "? ") t "\
6901 You should normally obey the Followup-To: header.
6903 `Followup-To: " followup-to "'
6904 directs your response to " (if (string-match "," followup-to)
6905 "the specified newsgroups"
6906 "that newsgroup only") ".
6908 If a message is posted to several newsgroups, Followup-To is often
6909 used to direct the following discussion to one newsgroup only,
6910 because discussions that are spread over several newsgroup tend to
6911 be fragmented and very difficult to follow.
6913 Also, some source/announcement newsgroups are not intended for discussion;
6914 responses here are directed to other newsgroups.
6916 You may customize the variable `message-use-followup-to', if you
6917 want to get rid of this query permanently."))
6918 (cons 'Newsgroups followup-to)
6919 (cons 'Newsgroups newsgroups))))))
6921 `((Newsgroups . ,posted-to)))
6923 `((Newsgroups . ,newsgroups))))
6924 ,@(and distribution (list (cons 'Distribution distribution)))
6926 (not (or (equal (downcase mct) "never")
6927 (equal (downcase mct) "nobody"))))
6928 (list (cons 'Cc (if (or (equal (downcase mct) "always")
6929 (equal (downcase mct) "poster"))
6930 (or mrt reply-to from "")
6935 (defun message-is-yours-p ()
6936 "Non-nil means current article is yours.
6937 If you have added 'cancel-messages to `message-shoot-gnksa-feet', all articles
6938 are yours except those that have Cancel-Lock header not belonging to you.
6939 Instead of shooting GNKSA feet, you should modify `message-alternative-emails'
6940 regexp to match all of yours addresses."
6941 ;; Canlock-logic as suggested by Per Abrahamsen
6942 ;; <abraham@dina.kvl.dk>
6944 ;; IF article has cancel-lock THEN
6945 ;; IF we can verify it THEN
6948 ;; error: cancellock: article is not yours
6950 ;; Use old rules, comparing sender...
6953 (message-narrow-to-head-1)
6954 (if (message-fetch-field "Cancel-Lock")
6955 (if (null (canlock-verify))
6957 (error "Failed to verify Cancel-lock: This article is not yours"))
6960 (message-gnksa-enable-p 'cancel-messages)
6961 (and (setq sender (message-fetch-field "sender"))
6962 (string-equal (downcase sender)
6963 (downcase (message-make-sender))))
6964 ;; Email address in From field equals to our address
6965 (and (setq from (message-fetch-field "from"))
6967 (downcase (car (mail-header-parse-address from)))
6968 (downcase (car (mail-header-parse-address
6969 (message-make-from))))))
6970 ;; Email address in From field matches
6971 ;; 'message-alternative-emails' regexp
6973 message-alternative-emails
6975 message-alternative-emails
6976 (car (mail-header-parse-address from))))))))))
6979 (defun message-cancel-news (&optional arg)
6980 "Cancel an article you posted.
6981 If ARG, allow editing of the cancellation message."
6983 (unless (message-news-p)
6984 (error "This is not a news article; canceling is impossible"))
6985 (let (from newsgroups message-id distribution buf)
6987 ;; Get header info from original article.
6989 (message-narrow-to-head-1)
6990 (setq from (message-fetch-field "from")
6991 newsgroups (message-fetch-field "newsgroups")
6992 message-id (message-fetch-field "message-id" t)
6993 distribution (message-fetch-field "distribution")))
6994 ;; Make sure that this article was written by the user.
6995 (unless (message-is-yours-p)
6996 (error "This article is not yours"))
6997 (when (yes-or-no-p "Do you really want to cancel this article? ")
6998 ;; Make control message.
7001 (setq buf (set-buffer (get-buffer-create " *message cancel*"))))
7003 (insert "Newsgroups: " newsgroups "\n"
7005 "Subject: cmsg cancel " message-id "\n"
7006 "Control: cancel " message-id "\n"
7008 (concat "Distribution: " distribution "\n")
7010 mail-header-separator "\n"
7011 message-cancel-message)
7012 (run-hooks 'message-cancel-hook)
7014 (message "Canceling your article...")
7015 (if (let ((message-syntax-checks
7016 'dont-check-for-anything-just-trust-me))
7017 (funcall message-send-news-function))
7018 (message "Canceling your article...done"))
7019 (kill-buffer buf))))))
7022 (defun message-supersede ()
7023 "Start composing a message to supersede the current message.
7024 This is done simply by taking the old article and adding a Supersedes
7025 header line with the old Message-ID."
7027 (let ((cur (current-buffer)))
7028 ;; Check whether the user owns the article that is to be superseded.
7029 (unless (message-is-yours-p)
7030 (error "This article is not yours"))
7031 ;; Get a normal message buffer.
7032 (message-pop-to-buffer (message-buffer-name "supersede"))
7033 (insert-buffer-substring cur)
7035 (message-narrow-to-head-1)
7036 ;; Remove unwanted headers.
7037 (when message-ignored-supersedes-headers
7038 (message-remove-header message-ignored-supersedes-headers t))
7039 (goto-char (point-min))
7040 (if (not (re-search-forward "^Message-ID: " nil t))
7041 (error "No Message-ID in this article")
7042 (replace-match "Supersedes: " t t))
7043 (goto-char (point-max))
7044 (insert mail-header-separator)
7049 (defun message-recover ()
7050 "Reread contents of current buffer from its last auto-save file."
7052 (let ((file-name (make-auto-save-file-name)))
7053 (cond ((save-window-excursion
7054 (with-output-to-temp-buffer "*Directory*"
7055 (with-current-buffer standard-output
7056 (fundamental-mode)) ; for Emacs 20.4+
7057 (buffer-disable-undo standard-output)
7058 (let ((default-directory "/"))
7060 "ls" nil standard-output nil "-l" file-name)))
7061 (yes-or-no-p (format "Recover auto save file %s? " file-name)))
7062 (let ((buffer-read-only nil))
7064 (insert-file-contents file-name nil)))
7065 (t (error "message-recover cancelled")))))
7067 ;;; Washing Subject:
7069 (defun message-wash-subject (subject)
7070 "Remove junk like \"Re:\", \"(fwd)\", etc. added to subject string SUBJECT.
7071 Previous forwarders, replyers, etc. may add it."
7074 (goto-char (point-min))
7075 ;; strip Re/Fwd stuff off the beginning
7076 (while (re-search-forward
7077 "\\([Rr][Ee]:\\|[Ff][Ww][Dd]\\(\\[[0-9]*\\]\\)?:\\|[Ff][Ww]:\\)" nil t)
7080 ;; and gnus-style forwards [foo@bar.com] subject
7081 (goto-char (point-min))
7082 (while (re-search-forward "\\[[^ \t]*\\(@\\|\\.\\)[^ \t]*\\]" nil t)
7086 (goto-char (point-max))
7087 (while (re-search-backward "([Ff][Ww][Dd])" nil t)
7090 ;; and finally, any whitespace that was left-over
7091 (goto-char (point-min))
7092 (while (re-search-forward "^[ \t]+" nil t)
7094 (goto-char (point-max))
7095 (while (re-search-backward "[ \t]+$" nil t)
7100 ;;; Forwarding messages.
7102 (defvar message-forward-decoded-p nil
7103 "Non-nil means the original message is decoded.")
7105 (defun message-forward-subject-name-subject (subject)
7106 "Generate a SUBJECT for a forwarded message.
7107 The form is: [Source] Subject, where if the original message was mail,
7108 Source is the name of the sender, and if the original message was
7109 news, Source is the list of newsgroups is was posted to."
7110 (let* ((group (message-fetch-field "newsgroups"))
7111 (from (message-fetch-field "from"))
7114 (gnus-group-decoded-name group)
7116 (car (gnus-extract-address-components from))
7117 (cadr (gnus-extract-address-components from))))
7120 (if message-forward-decoded-p
7122 (mail-decode-encoded-word-string prefix))
7125 (defun message-forward-subject-author-subject (subject)
7126 "Generate a SUBJECT for a forwarded message.
7127 The form is: [Source] Subject, where if the original message was mail,
7128 Source is the sender, and if the original message was news, Source is
7129 the list of newsgroups is was posted to."
7130 (let* ((group (message-fetch-field "newsgroups"))
7133 (gnus-group-decoded-name group)
7134 (or (message-fetch-field "from")
7137 (if message-forward-decoded-p
7139 (mail-decode-encoded-word-string prefix))
7142 (defun message-forward-subject-fwd (subject)
7143 "Generate a SUBJECT for a forwarded message.
7144 The form is: Fwd: Subject, where Subject is the original subject of
7146 (if (string-match "^Fwd: " subject)
7148 (concat "Fwd: " subject)))
7150 (defun message-make-forward-subject ()
7151 "Return a Subject header suitable for the message in the current buffer."
7154 (message-narrow-to-head-1)
7155 (let ((funcs message-make-forward-subject-function)
7156 (subject (message-fetch-field "Subject")))
7159 (if message-forward-decoded-p
7161 (mail-decode-encoded-word-string subject))
7163 (when message-wash-forwarded-subjects
7164 (setq subject (message-wash-subject subject)))
7165 ;; Make sure funcs is a list.
7168 (setq funcs (list funcs)))
7169 ;; Apply funcs in order, passing subject generated by previous
7170 ;; func to the next one.
7171 (dolist (func funcs)
7172 (when (functionp func)
7173 (setq subject (funcall func subject))))
7176 (defvar gnus-article-decoded-p)
7180 (defun message-forward (&optional news digest)
7181 "Forward the current message via mail.
7182 Optional NEWS will use news to forward instead of mail.
7183 Optional DIGEST will use digest to forward."
7185 (let* ((cur (current-buffer))
7186 (message-forward-decoded-p
7187 (if (local-variable-p 'gnus-article-decoded-p (current-buffer))
7188 gnus-article-decoded-p ;; In an article buffer.
7189 message-forward-decoded-p))
7190 (subject (message-make-forward-subject)))
7192 (message-news nil subject)
7193 (message-mail nil subject))
7194 (message-forward-make-body cur digest)))
7196 (defun message-forward-make-body-plain (forward-buffer)
7198 "\n-------------------- Start of forwarded message --------------------\n")
7200 (contents (with-current-buffer forward-buffer (buffer-string)))
7202 (unless (featurep 'xemacs)
7203 (unless (mm-multibyte-string-p contents)
7204 (error "Attempt to insert unibyte string from the buffer \"%s\"\
7205 to the multibyte buffer \"%s\""
7206 (if (bufferp forward-buffer)
7207 (buffer-name forward-buffer)
7210 (insert (mm-with-multibyte-buffer
7213 (goto-char (point-min))
7214 (when (looking-at "From ")
7215 (replace-match "X-From-Line: "))
7217 (unless (bolp) (insert "\n"))
7220 "-------------------- End of forwarded message --------------------\n")
7221 (message-remove-ignored-headers b e)))
7223 (defun message-remove-ignored-headers (b e)
7224 (when message-forward-ignored-headers
7226 (narrow-to-region b e)
7228 (narrow-to-region (point)
7229 (or (search-forward "\n\n" nil t) (point)))
7230 (let ((ignored (if (stringp message-forward-ignored-headers)
7231 (list message-forward-ignored-headers)
7232 message-forward-ignored-headers)))
7233 (dolist (elem ignored)
7234 (message-remove-header elem t))))))
7236 (defun message-forward-make-body-mime (forward-buffer)
7238 (insert "\n\n<#part type=message/rfc822 disposition=inline raw=t>\n")
7240 (narrow-to-region (point) (point))
7241 (mml-insert-buffer forward-buffer)
7242 (goto-char (point-min))
7243 (when (looking-at "From ")
7244 (replace-match "X-From-Line: "))
7245 (goto-char (point-max)))
7246 (insert "<#/part>\n")
7247 ;; Consider there is no illegible text.
7248 (add-text-properties
7250 `(no-illegible-text t rear-nonsticky t start-open t))))
7252 (defun message-forward-make-body-mml (forward-buffer)
7253 (insert "\n\n<#mml type=message/rfc822 disposition=inline>\n")
7254 (let ((b (point)) e)
7255 (if (not message-forward-decoded-p)
7256 (let ((contents (with-current-buffer forward-buffer (buffer-string))))
7257 (unless (featurep 'xemacs)
7258 (unless (mm-multibyte-string-p contents)
7259 (error "Attempt to insert unibyte string from the buffer \"%s\"\
7260 to the multibyte buffer \"%s\""
7261 (if (bufferp forward-buffer)
7262 (buffer-name forward-buffer)
7265 (insert (mm-with-multibyte-buffer
7268 (goto-char (point-min))
7269 (when (looking-at "From ")
7270 (replace-match "X-From-Line: "))
7273 (narrow-to-region (point) (point))
7274 (mml-insert-buffer forward-buffer)
7275 (goto-char (point-min))
7276 (when (looking-at "From ")
7277 (replace-match "X-From-Line: "))
7278 (goto-char (point-max))))
7280 (insert "<#/mml>\n")
7281 (when (and (not message-forward-decoded-p)
7282 message-forward-ignored-headers)
7283 (message-remove-ignored-headers b e))))
7285 (defun message-forward-make-body-digest-plain (forward-buffer)
7287 "\n-------------------- Start of forwarded message --------------------\n")
7288 (let ((b (point)) e)
7289 (mml-insert-buffer forward-buffer)
7292 "\n-------------------- End of forwarded message --------------------\n")))
7294 (defun message-forward-make-body-digest-mime (forward-buffer)
7295 (insert "\n<#multipart type=digest>\n")
7296 (let ((b (point)) e)
7297 (insert-buffer-substring forward-buffer)
7299 (insert "<#/multipart>\n")
7301 (narrow-to-region b e)
7303 (narrow-to-region (point)
7304 (or (search-forward "\n\n" nil t) (point)))
7305 (delete-region (point-min) (point-max)))))
7307 (defun message-forward-make-body-digest (forward-buffer)
7308 (if message-forward-as-mime
7309 (message-forward-make-body-digest-mime forward-buffer)
7310 (message-forward-make-body-digest-plain forward-buffer)))
7312 (autoload 'mm-uu-dissect-text-parts "mm-uu")
7313 (autoload 'mm-uu-dissect "mm-uu")
7315 (defun message-signed-or-encrypted-p (&optional dont-emulate-mime handles)
7316 "Say whether the current buffer contains signed or encrypted message.
7317 If DONT-EMULATE-MIME is nil, this function does the MIME emulation on
7318 messages that don't conform to PGP/MIME described in RFC2015. HANDLES
7319 is for the internal use."
7321 (let ((mm-decrypt-option 'never)
7322 (mm-verify-option 'never))
7323 (if (setq handles (mm-dissect-buffer nil t))
7324 (unless dont-emulate-mime
7325 (mm-uu-dissect-text-parts handles))
7326 (unless dont-emulate-mime
7327 (setq handles (mm-uu-dissect))))))
7328 ;; Check text/plain message in which there is a signed or encrypted
7329 ;; body that has been encoded by B or Q.
7330 (unless (or handles dont-emulate-mime)
7331 (let ((cur (current-buffer))
7332 (mm-decrypt-option 'never)
7333 (mm-verify-option 'never))
7335 (insert-buffer-substring cur)
7336 (when (setq handles (mm-dissect-buffer t t))
7338 (bufferp (car handles))
7339 (mm-destroy-parts handles))
7340 (equal (mm-handle-media-type handles) "text/plain"))
7342 (mm-decode-content-transfer-encoding
7343 (mm-handle-encoding handles))
7344 (setq handles (mm-uu-dissect)))
7345 (setq handles nil))))))
7349 (dolist (handle (if (stringp (car handles))
7350 (if (member (car handles)
7351 '("multipart/signed"
7352 "multipart/encrypted"))
7356 (if (stringp (car handle))
7357 (when (message-signed-or-encrypted-p dont-emulate-mime handle)
7359 (when (and (bufferp (car handle))
7360 (equal (mm-handle-media-type handle)
7362 (with-current-buffer (mm-handle-buffer handle)
7363 (when (message-signed-or-encrypted-p dont-emulate-mime)
7364 (throw 'found t)))))))
7365 (mm-destroy-parts handles))))
7368 (defun message-forward-make-body (forward-buffer &optional digest)
7369 ;; Put point where we want it before inserting the forwarded
7371 (if message-forward-before-signature
7373 (goto-char (point-max)))
7375 (message-forward-make-body-digest forward-buffer)
7376 (if message-forward-as-mime
7377 (if (and message-forward-show-mml
7378 (not (and (eq message-forward-show-mml 'best)
7379 ;; Use the raw form in the body if it contains
7380 ;; signed or encrypted message so as not to be
7381 ;; destroyed by re-encoding.
7382 (with-current-buffer forward-buffer
7384 (message-signed-or-encrypted-p)
7386 (message-forward-make-body-mml forward-buffer)
7387 (message-forward-make-body-mime forward-buffer))
7388 (message-forward-make-body-plain forward-buffer)))
7389 (message-position-point))
7391 (declare-function rmail-toggle-header "rmail" (&optional arg))
7394 (defun message-forward-rmail-make-body (forward-buffer)
7395 (save-window-excursion
7396 (set-buffer forward-buffer)
7397 (if (rmail-msg-is-pruned)
7398 (if (fboundp 'rmail-msg-restore-non-pruned-header)
7399 (rmail-msg-restore-non-pruned-header) ; Emacs 22
7400 (rmail-toggle-header 0)))) ; Emacs 23
7401 (message-forward-make-body forward-buffer))
7403 ;; Fixme: Should have defcustom.
7405 (defun message-insinuate-rmail ()
7406 "Let RMAIL use message to forward."
7408 (setq rmail-enable-mime-composing t)
7409 (setq rmail-insert-mime-forwarded-message-function
7410 'message-forward-rmail-make-body))
7413 (defun message-resend (address)
7414 "Resend the current article to ADDRESS."
7416 (list (message-read-from-minibuffer "Resend message to: ")))
7417 (message "Resending message to %s..." address)
7419 (let ((cur (current-buffer))
7421 ;; We first set up a normal mail buffer.
7422 (unless (message-mail-user-agent)
7423 (set-buffer (get-buffer-create " *message resend*"))
7425 (let ((message-this-is-mail t)
7426 message-generate-hashcash
7428 (message-setup `((To . ,address))))
7429 ;; Insert our usual headers.
7430 (message-generate-headers '(From Date To Message-ID))
7431 (message-narrow-to-headers)
7432 ;; Remove X-Draft-From header etc.
7433 (message-remove-header message-ignored-mail-headers t)
7434 ;; Rename them all to "Resent-*".
7435 (goto-char (point-min))
7436 (while (re-search-forward "^[A-Za-z]" nil t)
7441 (delete-region (point) (point-max))
7443 ;; Insert the message to be resent.
7444 (insert-buffer-substring cur)
7445 (goto-char (point-min))
7446 (search-forward "\n\n")
7449 (narrow-to-region beg (point))
7450 (message-remove-header message-ignored-resent-headers t)
7451 (goto-char (point-max)))
7452 (insert mail-header-separator)
7453 ;; Rename all old ("Also-")Resent headers.
7454 (while (re-search-backward "^\\(Also-\\)*Resent-" beg t)
7457 ;; Quote any "From " lines at the beginning.
7459 (when (looking-at "From ")
7460 (replace-match "X-From-Line: "))
7462 (let ((message-inhibit-body-encoding t)
7463 (message-inhibit-ecomplete t)
7464 message-required-mail-headers
7465 message-generate-hashcash
7466 rfc2047-encode-encoded-words)
7467 (message-send-mail))
7468 (kill-buffer (current-buffer)))
7469 (message "Resending message to %s...done" address)))
7472 (defun message-bounce ()
7473 "Re-mail the current message.
7474 This only makes sense if the current message is a bounce message that
7475 contains some mail you have written which has been bounced back to
7478 (let ((handles (mm-dissect-buffer t))
7480 (message-pop-to-buffer (message-buffer-name "bounce"))
7481 (if (stringp (car handles))
7482 ;; This is a MIME bounce.
7483 (mm-insert-part (car (last handles)))
7484 ;; This is a non-MIME bounce, so we try to remove things
7486 (mm-insert-part handles)
7488 (goto-char (point-min))
7489 (re-search-forward "\n\n+" nil t)
7490 (setq boundary (point))
7491 ;; We remove everything before the bounced mail.
7492 (if (or (re-search-forward message-unsent-separator nil t)
7494 (search-forward "\n\n" nil 'move)
7495 (re-search-backward "^Return-Path:.*\n" boundary t)))
7498 (delete-region (point-min)
7499 (if (re-search-forward "^[^ \n\t]+:" nil t)
7502 (goto-char boundary)
7503 (when (re-search-backward "^.?From .*\n" nil t)
7504 (delete-region (match-beginning 0) (match-end 0)))))
7507 (message-narrow-to-head-1)
7508 (message-remove-header message-ignored-bounced-headers t)
7509 (goto-char (point-max))
7510 (insert mail-header-separator))
7511 (message-position-point)))
7514 ;;; Interactive entry points for new message buffers.
7518 (defun message-mail-other-window (&optional to subject)
7519 "Like `message-mail' command, but display mail buffer in another window."
7521 (unless (message-mail-user-agent)
7522 (let ((pop-up-windows t)
7523 (special-display-buffer-names nil)
7524 (special-display-regexps nil)
7525 (same-window-buffer-names nil)
7526 (same-window-regexps nil))
7527 (message-pop-to-buffer (message-buffer-name "mail" to))))
7528 (let ((message-this-is-mail t))
7529 (message-setup `((To . ,(or to "")) (Subject . ,(or subject "")))
7530 nil nil nil 'switch-to-buffer-other-window)))
7533 (defun message-mail-other-frame (&optional to subject)
7534 "Like `message-mail' command, but display mail buffer in another frame."
7536 (unless (message-mail-user-agent)
7537 (let ((pop-up-frames t)
7538 (special-display-buffer-names nil)
7539 (special-display-regexps nil)
7540 (same-window-buffer-names nil)
7541 (same-window-regexps nil))
7542 (message-pop-to-buffer (message-buffer-name "mail" to))))
7543 (let ((message-this-is-mail t))
7544 (message-setup `((To . ,(or to "")) (Subject . ,(or subject "")))
7545 nil nil nil 'switch-to-buffer-other-frame)))
7548 (defun message-news-other-window (&optional newsgroups subject)
7549 "Start editing a news article to be sent."
7551 (let ((pop-up-windows t)
7552 (special-display-buffer-names nil)
7553 (special-display-regexps nil)
7554 (same-window-buffer-names nil)
7555 (same-window-regexps nil))
7556 (message-pop-to-buffer (message-buffer-name "posting" nil newsgroups)))
7557 (let ((message-this-is-news t))
7558 (message-setup `((Newsgroups . ,(or newsgroups ""))
7559 (Subject . ,(or subject ""))))))
7562 (defun message-news-other-frame (&optional newsgroups subject)
7563 "Start editing a news article to be sent."
7565 (let ((pop-up-frames t)
7566 (special-display-buffer-names nil)
7567 (special-display-regexps nil)
7568 (same-window-buffer-names nil)
7569 (same-window-regexps nil))
7570 (message-pop-to-buffer (message-buffer-name "posting" nil newsgroups)))
7571 (let ((message-this-is-news t))
7572 (message-setup `((Newsgroups . ,(or newsgroups ""))
7573 (Subject . ,(or subject ""))))))
7577 ;; This code should be moved to underline.el (from which it is stolen).
7580 (defun message-bold-region (start end)
7581 "Bold all nonblank characters in the region.
7582 Works by overstriking characters.
7583 Called from program, takes two arguments START and END
7584 which specify the range to operate on."
7587 (let ((end1 (make-marker)))
7588 (move-marker end1 (max start end))
7589 (goto-char (min start end))
7590 (while (< (point) end1)
7591 (or (looking-at "[_\^@- ]")
7592 (insert (char-after) "\b"))
7593 (forward-char 1)))))
7596 (defun message-unbold-region (start end)
7597 "Remove all boldness (overstruck characters) in the region.
7598 Called from program, takes two arguments START and END
7599 which specify the range to operate on."
7602 (let ((end1 (make-marker)))
7603 (move-marker end1 (max start end))
7604 (goto-char (min start end))
7605 (while (search-forward "\b" end1 t)
7606 (if (eq (char-after) (char-after (- (point) 2)))
7607 (delete-char -2))))))
7609 (defun message-exchange-point-and-mark ()
7610 "Exchange point and mark, but don't activate region if it was inactive."
7611 (goto-char (prog1 (mark t)
7612 (set-marker (mark-marker) (point)))))
7614 (defalias 'message-make-overlay 'make-overlay)
7615 (defalias 'message-delete-overlay 'delete-overlay)
7616 (defalias 'message-overlay-put 'overlay-put)
7617 (defun message-kill-all-overlays ()
7618 (if (featurep 'xemacs)
7619 (map-extents (lambda (extent ignore) (delete-extent extent)))
7620 (mapcar #'delete-overlay (overlays-in (point-min) (point-max)))))
7622 ;; Support for toolbar
7623 (defvar tool-bar-mode)
7625 ;; Note: The :set function in the `message-tool-bar*' variables will only
7626 ;; affect _new_ message buffers. We might add a function that walks thru all
7627 ;; message-mode buffers and force the update.
7628 (defun message-tool-bar-update (&optional symbol value)
7629 "Update message mode toolbar.
7630 Setter function for custom variables."
7631 (setq-default message-tool-bar-map nil)
7633 ;; When used as ":set" function:
7634 (set-default symbol value)))
7636 (defcustom message-tool-bar (if (eq gmm-tool-bar-style 'gnome)
7637 'message-tool-bar-gnome
7638 'message-tool-bar-retro)
7639 "Specifies the message mode tool bar.
7641 It can be either a list or a symbol refering to a list. See
7642 `gmm-tool-bar-from-list' for the format of the list. The
7643 default key map is `message-mode-map'.
7645 Pre-defined symbols include `message-tool-bar-gnome' and
7646 `message-tool-bar-retro'."
7647 :type '(repeat gmm-tool-bar-list-item)
7648 :type '(choice (const :tag "GNOME style" message-tool-bar-gnome)
7649 (const :tag "Retro look" message-tool-bar-retro)
7650 (repeat :tag "User defined list" gmm-tool-bar-item)
7652 :version "23.1" ;; No Gnus
7653 :initialize 'custom-initialize-default
7654 :set 'message-tool-bar-update
7657 (defcustom message-tool-bar-gnome
7658 '((ispell-message "spell" nil
7659 :visible (or (not (boundp 'flyspell-mode))
7660 (not flyspell-mode)))
7661 (flyspell-buffer "spell" t
7662 :visible (and (boundp 'flyspell-mode)
7664 :help "Flyspell whole buffer")
7665 (gmm-ignore "separator")
7666 (message-send-and-exit "mail/send")
7667 (message-dont-send "mail/save-draft")
7668 (message-kill-buffer "close") ;; stock_cancel
7669 (mml-attach-file "attach" mml-mode-map)
7670 (mml-preview "mail/preview" mml-mode-map)
7671 (mml-secure-message-sign-encrypt "lock" mml-mode-map :visible nil)
7672 (message-insert-importance-high "important" nil :visible nil)
7673 (message-insert-importance-low "unimportant" nil :visible nil)
7674 (message-insert-disposition-notification-to "receipt" nil :visible nil)
7675 (gmm-customize-mode "preferences" t :help "Edit mode preferences")
7676 (message-info "help" t :help "Message manual"))
7677 "List of items for the message tool bar (GNOME style).
7679 See `gmm-tool-bar-from-list' for details on the format of the list."
7680 :type '(repeat gmm-tool-bar-item)
7681 :version "23.1" ;; No Gnus
7682 :initialize 'custom-initialize-default
7683 :set 'message-tool-bar-update
7686 (defcustom message-tool-bar-retro
7687 '(;; Old Emacs 21 icon for consistency.
7688 (message-send-and-exit "gnus/mail-send")
7689 (message-kill-buffer "close")
7690 (message-dont-send "cancel")
7691 (mml-attach-file "attach" mml-mode-map)
7692 (ispell-message "spell")
7693 (mml-preview "preview" mml-mode-map)
7694 (message-insert-importance-high "gnus/important")
7695 (message-insert-importance-low "gnus/unimportant")
7696 (message-insert-disposition-notification-to "gnus/receipt"))
7697 "List of items for the message tool bar (retro style).
7699 See `gmm-tool-bar-from-list' for details on the format of the list."
7700 :type '(repeat gmm-tool-bar-item)
7701 :version "23.1" ;; No Gnus
7702 :initialize 'custom-initialize-default
7703 :set 'message-tool-bar-update
7706 (defcustom message-tool-bar-zap-list
7707 '(new-file open-file dired kill-buffer write-file
7708 print-buffer customize help)
7709 "List of icon items from the global tool bar.
7710 These items are not displayed on the message mode tool bar.
7712 See `gmm-tool-bar-from-list' for the format of the list."
7713 :type 'gmm-tool-bar-zap-list
7714 :version "23.1" ;; No Gnus
7715 :initialize 'custom-initialize-default
7716 :set 'message-tool-bar-update
7719 (defvar image-load-path)
7721 (defun message-make-tool-bar (&optional force)
7722 "Make a message mode tool bar from `message-tool-bar-list'.
7723 When FORCE, rebuild the tool bar."
7724 (when (and (not (featurep 'xemacs))
7725 (boundp 'tool-bar-mode)
7727 (or (not message-tool-bar-map) force))
7728 (setq message-tool-bar-map
7730 (gmm-image-load-path-for-library "message"
7731 "mail/save-draft.xpm"
7733 (image-load-path (cons (car load-path)
7734 (when (boundp 'image-load-path)
7736 (gmm-tool-bar-from-list message-tool-bar
7737 message-tool-bar-zap-list
7738 'message-mode-map))))
7739 message-tool-bar-map)
7741 ;;; Group name completion.
7743 (defcustom message-newgroups-header-regexp
7744 "^\\(Newsgroups\\|Followup-To\\|Posted-To\\|Gcc\\):"
7745 "Regexp that match headers that lists groups."
7749 (defcustom message-completion-alist
7750 (list (cons message-newgroups-header-regexp 'message-expand-group)
7751 '("^\\(Resent-\\)?\\(To\\|B?Cc\\):" . message-expand-name)
7752 '("^\\(Reply-To\\|From\\|Mail-Followup-To\\|Mail-Copies-To\\):"
7753 . message-expand-name)
7754 '("^\\(Disposition-Notification-To\\|Return-Receipt-To\\):"
7755 . message-expand-name))
7756 "Alist of (RE . FUN). Use FUN for completion on header lines matching RE."
7759 :type '(alist :key-type regexp :value-type function))
7761 (defcustom message-expand-name-databases
7763 "List of databases to try for name completion (`message-expand-name').
7764 Each element is a symbol and can be `bbdb' or `eudc'."
7766 :type '(set (const bbdb) (const eudc)))
7768 (defcustom message-tab-body-function nil
7769 "*Function to execute when `message-tab' (TAB) is executed in the body.
7770 If nil, the function bound in `text-mode-map' or `global-map' is executed."
7773 :link '(custom-manual "(message)Various Commands")
7774 :type '(choice (const nil)
7777 (declare-function mail-abbrev-in-expansion-header-p "mailabbrev" ())
7779 (defun message-tab ()
7780 "Complete names according to `message-completion-alist'.
7781 Execute function specified by `message-tab-body-function' when not in
7784 (let ((alist message-completion-alist))
7786 (let ((mail-abbrev-mode-regexp (caar alist)))
7787 (not (mail-abbrev-in-expansion-header-p))))
7788 (setq alist (cdr alist)))
7789 (funcall (or (cdar alist) message-tab-body-function
7790 (lookup-key text-mode-map "\t")
7791 (lookup-key global-map "\t")
7792 'indent-relative))))
7797 (let ((standard-output (current-buffer)))
7798 (eval '(display-completion-list nil "")))
7799 (defalias 'message-display-completion-list 'display-completion-list))
7800 (error ;; Don't use `wrong-number-of-arguments' here because of XEmacs.
7801 (defun message-display-completion-list (completions &optional ignore)
7802 "Display the list of completions, COMPLETIONS, using `standard-output'."
7803 (display-completion-list completions)))))
7805 (defun message-expand-group ()
7806 "Expand the group name under point."
7807 (let* ((b (save-excursion
7812 (skip-chars-forward "^:")
7815 (skip-chars-backward "^, \t\n") (point))))
7816 (completion-ignore-case t)
7817 (e (progn (skip-chars-forward "^,\t\n ") (point)))
7818 (hashtb (and (boundp 'gnus-active-hashtb) gnus-active-hashtb)))
7819 (message-completion-in-region e b hashtb)))
7821 (defalias 'message-completion-in-region
7822 (if (fboundp 'completion-in-region)
7823 'completion-in-region
7824 (lambda (e b hashtb)
7825 (let* ((string (buffer-substring b e))
7826 (completions (all-completions string hashtb))
7828 (delete-region b (point))
7830 ((= (length completions) 1)
7831 (if (string= (car completions) string)
7834 (message "Only matching group"))
7835 (insert (car completions))))
7836 ((and (setq comp (try-completion string hashtb))
7837 (not (string= comp string)))
7842 (message "No matching groups")
7843 (save-selected-window
7844 (pop-to-buffer "*Completions*")
7845 (buffer-disable-undo)
7846 (let ((buffer-read-only nil))
7848 (let ((standard-output (current-buffer)))
7849 (message-display-completion-list (sort completions 'string<)
7851 (setq buffer-read-only nil)
7852 (goto-char (point-min))
7853 (delete-region (point)
7854 (progn (forward-line 3) (point))))))))))))
7856 (defun message-expand-name ()
7857 (cond ((and (memq 'eudc message-expand-name-databases)
7858 (boundp 'eudc-protocol)
7860 (eudc-expand-inline))
7861 ((and (memq 'bbdb message-expand-name-databases)
7862 (fboundp 'bbdb-complete-name))
7863 (bbdb-complete-name))
7869 (defun message-talkative-question (ask question show &rest text)
7870 "Call FUNCTION with argument QUESTION; optionally display TEXT... args.
7871 If SHOW is non-nil, the arguments TEXT... are displayed in a temp buffer.
7872 The following arguments may contain lists of values."
7874 (setq text (message-flatten-list text)))
7875 (save-window-excursion
7876 (with-output-to-temp-buffer " *MESSAGE information message*"
7877 (with-current-buffer " *MESSAGE information message*"
7878 (fundamental-mode) ; for Emacs 20.4+
7880 (goto-char (point-min))))
7881 (funcall ask question))
7882 (funcall ask question)))
7884 (defun message-flatten-list (list)
7885 "Return a new, flat list that contains all elements of LIST.
7887 \(message-flatten-list '(1 (2 3 (4 5 (6))) 7))
7890 (apply 'append (mapcar 'message-flatten-list list)))
7894 (defun message-generate-new-buffer-clone-locals (name &optional varstr)
7895 "Create and return a buffer with name based on NAME using `generate-new-buffer'.
7896 Then clone the local variables and values from the old buffer to the
7897 new one, cloning only the locals having a substring matching the
7899 (let ((oldbuf (current-buffer)))
7900 (with-current-buffer (generate-new-buffer name)
7901 (message-clone-locals oldbuf varstr)
7904 (defun message-clone-locals (buffer &optional varstr)
7905 "Clone the local variables from BUFFER to the current buffer."
7906 (let ((locals (with-current-buffer buffer (buffer-local-variables)))
7907 (regexp "^gnus\\|^nn\\|^message\\|^sendmail\\|^smtp\\|^user-mail-address"))
7910 (when (and (consp local)
7912 (string-match regexp (symbol-name (car local)))
7914 (string-match varstr (symbol-name (car local)))))
7916 (set (make-local-variable (car local))
7924 (defvar message-inhibit-body-encoding nil)
7926 (defun message-encode-message-body ()
7927 (unless message-inhibit-body-encoding
7928 (let ((mail-parse-charset (or mail-parse-charset
7929 message-default-charset))
7930 (case-fold-search t)
7931 lines content-type-p)
7934 (narrow-to-region (point) (point-max))
7935 (let ((new (mml-generate-mime)))
7937 (delete-region (point-min) (point-max))
7939 (goto-char (point-min))
7940 (if (eq (aref new 0) ?\n)
7942 (search-forward "\n\n")
7943 (setq lines (buffer-substring (point-min) (1- (point))))
7944 (delete-region (point-min) (point))))))
7946 (message-narrow-to-headers-or-head)
7947 (message-remove-header "Mime-Version")
7948 (goto-char (point-max))
7949 (insert "MIME-Version: 1.0\n")
7952 (setq content-type-p
7954 (re-search-backward "^Content-Type:" nil t))))
7956 (message-narrow-to-headers-or-head)
7957 (message-remove-first-header "Content-Type")
7958 (message-remove-first-header "Content-Transfer-Encoding"))
7959 ;; We always make sure that the message has a Content-Type
7960 ;; header. This is because some broken MTAs and MUAs get
7961 ;; awfully confused when confronted with a message with a
7962 ;; MIME-Version header and without a Content-Type header. For
7963 ;; instance, Solaris' /usr/bin/mail.
7964 (unless content-type-p
7965 (goto-char (point-min))
7966 ;; For unknown reason, MIME-Version doesn't exist.
7967 (when (re-search-forward "^MIME-Version:" nil t)
7969 (insert "Content-Type: text/plain; charset=us-ascii\n"))))))
7971 (defun message-read-from-minibuffer (prompt &optional initial-contents)
7972 "Read from the minibuffer while providing abbrev expansion."
7973 (if (fboundp 'mail-abbrevs-setup)
7974 (let ((mail-abbrev-mode-regexp "")
7975 (minibuffer-setup-hook 'mail-abbrevs-setup)
7976 (minibuffer-local-map message-minibuffer-local-map))
7977 (read-from-minibuffer prompt initial-contents))
7978 (let ((minibuffer-setup-hook 'mail-abbrev-minibuffer-setup-hook)
7979 (minibuffer-local-map message-minibuffer-local-map))
7980 (read-string prompt initial-contents))))
7982 (defun message-use-alternative-email-as-from ()
7983 "Set From field of the outgoing message to the first matching
7984 address in `message-alternative-emails', looking at To, Cc and
7985 From headers in the original article."
7986 (require 'mail-utils)
7987 (let* ((fields '("To" "Cc" "From"))
7990 (mail-strip-quoted-names
7991 (mapconcat 'message-fetch-reply-field fields ","))
7995 (if (string-match message-alternative-emails (car emails))
7996 (setq email (car emails)
7999 (unless (or (not email) (equal email user-mail-address))
8000 (message-remove-header "From")
8001 (goto-char (point-max))
8002 (insert "From: " (let ((user-mail-address email)) (message-make-from))
8005 (defun message-options-get (symbol)
8006 (cdr (assq symbol message-options)))
8008 (defun message-options-set (symbol value)
8009 (let ((the-cons (assq symbol message-options)))
8012 (setcdr the-cons value)
8013 (setq message-options (delq the-cons message-options)))
8015 (push (cons symbol value) message-options))))
8018 (defun message-options-set-recipient ()
8020 (message-narrow-to-headers-or-head)
8021 (message-options-set 'message-sender
8022 (mail-strip-quoted-names
8023 (message-fetch-field "from")))
8024 (message-options-set 'message-recipients
8025 (mail-strip-quoted-names
8026 (let ((to (message-fetch-field "to"))
8027 (cc (message-fetch-field "cc"))
8028 (bcc (message-fetch-field "bcc")))
8031 (if (and to cc) ", ")
8033 (if (and (or to cc) bcc) ", ")
8036 (defun message-hide-headers ()
8037 "Hide headers based on the `message-hidden-headers' variable."
8038 (let ((regexps (if (stringp message-hidden-headers)
8039 (list message-hidden-headers)
8040 message-hidden-headers))
8041 (inhibit-point-motion-hooks t)
8042 (after-change-functions nil)
8043 (end-of-headers (point-min)))
8047 (message-narrow-to-headers)
8048 (goto-char (point-min))
8050 (if (not (message-hide-header-p regexps))
8051 (message-next-header)
8052 (let ((begin (point))
8054 (message-next-header)
8055 (setq header (buffer-substring begin (point))
8056 header-len (- (point) begin))
8057 (delete-region begin (point))
8058 (goto-char end-of-headers)
8060 (setq end-of-headers
8061 (+ end-of-headers header-len))))))))
8062 (narrow-to-region end-of-headers (point-max))))
8064 (defun message-hide-header-p (regexps)
8067 (when (eq (car regexps) 'not)
8070 (dolist (regexp regexps)
8071 (setq result (or result (looking-at regexp))))
8076 (declare-function ecomplete-add-item "ecomplete" (type key text))
8077 (declare-function ecomplete-save "ecomplete" ())
8079 (defun message-put-addresses-in-ecomplete ()
8080 (require 'ecomplete)
8081 (dolist (header '("to" "cc" "from" "reply-to"))
8082 (let ((value (message-field-value header)))
8083 (dolist (string (mail-header-parse-addresses value 'raw))
8085 (gnus-replace-in-string
8086 (gnus-replace-in-string string "^ +\\| +$" "") "\n" ""))
8087 (ecomplete-add-item 'mail (car (mail-header-parse-address string))
8091 (autoload 'ecomplete-display-matches "ecomplete")
8093 (defun message-display-abbrev (&optional choose)
8094 "Display the next possible abbrev for the text before point."
8095 (interactive (list t))
8096 (when (and (memq (char-after (point-at-bol)) '(?C ?T ?\t ? ))
8097 (message-point-in-header-p)
8100 (while (and (memq (char-after) '(?\t ? ))
8101 (zerop (forward-line -1))))
8102 (looking-at "To:\\|Cc:")))
8103 (let* ((end (point))
8104 (start (save-excursion
8105 (and (re-search-backward "[\n\t ]" nil t)
8107 (word (when start (buffer-substring start end)))
8108 (match (when (and word
8109 (not (zerop (length word))))
8110 (ecomplete-display-matches 'mail word choose))))
8111 (when (and choose match)
8112 (delete-region start end)
8115 ;; To send pre-formatted letters like the example below, you can use
8116 ;; `message-send-form-letter':
8117 ;; --8<---------------cut here---------------start------------->8---
8118 ;; To: alice@invalid.invalid
8119 ;; Subject: Verification of your contact information
8120 ;; From: Contact verification <admin@foo.invalid>
8121 ;; --text follows this line--
8123 ;; please verify that your contact information is still valid:
8124 ;; Alice A, A avenue 11, 1111 A town, Austria
8125 ;; ----------next form letter message follows this line----------
8126 ;; To: bob@invalid.invalid
8127 ;; Subject: Verification of your contact information
8128 ;; From: Contact verification <admin@foo.invalid>
8129 ;; --text follows this line--
8131 ;; please verify that your contact information is still valid:
8132 ;; Bob, B street 22, 22222 Be town, Belgium
8133 ;; ----------next form letter message follows this line----------
8134 ;; To: charlie@invalid.invalid
8135 ;; Subject: Verification of your contact information
8136 ;; From: Contact verification <admin@foo.invalid>
8137 ;; --text follows this line--
8139 ;; please verify that your contact information is still valid:
8140 ;; Charlie Chaplin, C plaza 33, 33333 C town, Chile
8141 ;; --8<---------------cut here---------------end--------------->8---
8143 ;; FIXME: What is the most common term (circular letter, form letter, serial
8144 ;; letter, standard letter) for such kind of letter? See also
8145 ;; <http://en.wikipedia.org/wiki/Form_letter>
8147 ;; FIXME: Maybe extent message-mode's font-lock support to recognize
8148 ;; `message-form-letter-separator', i.e. highlight each message like a single
8151 (defcustom message-form-letter-separator
8152 "\n----------next form letter message follows this line----------\n"
8153 "Separator for `message-send-form-letter'."
8154 ;; :group 'message-form-letter
8155 :group 'message-various
8156 :version "23.1" ;; No Gnus
8159 (defcustom message-send-form-letter-delay 1
8160 "Delay in seconds when sending a message with `message-send-form-letter'.
8161 Only used when `message-send-form-letter' is called with non-nil
8163 ;; :group 'message-form-letter
8164 :group 'message-various
8165 :version "23.1" ;; No Gnus
8168 (defun message-send-form-letter (&optional force)
8169 "Sent all form letter messages from current buffer.
8170 Unless FORCE, prompt before sending.
8172 The messages are separated by `message-form-letter-separator'.
8173 Header and body are separated by `mail-header-separator'."
8175 (let ((sent 0) (skipped 0)
8179 (goto-char (point-min))
8182 end (if (search-forward message-form-letter-separator nil t)
8183 (- (point) (length message-form-letter-separator) -1)
8187 (buffer-substring-no-properties start end))
8188 (setq buff (generate-new-buffer "*mail - form letter*"))
8189 (with-current-buffer buff
8192 (setq to (message-fetch-field "To"))
8193 (switch-to-buffer buff)
8195 (sit-for message-send-form-letter-delay))
8197 (y-or-n-p (format "Send message to `%s'? " to)))
8199 (setq sent (1+ sent))
8200 (message-send-and-exit))
8201 (message (format "Message to `%s' skipped." to))
8202 (setq skipped (1+ skipped)))
8203 (when (buffer-live-p buff)
8204 (kill-buffer buff))))
8205 (message "%s message(s) sent, %s skipped." sent skipped)))
8207 (defun message-replace-header (header new-value &optional after force)
8208 "Remove HEADER and insert the NEW-VALUE.
8209 If AFTER, insert after this header. If FORCE, insert new field
8210 even if NEW-VALUE is empty."
8211 ;; Similar to `nnheader-replace-header' but for message buffers.
8214 (message-narrow-to-headers)
8215 (message-remove-header header))
8216 (when (or force (> (length new-value) 0))
8218 (message-position-on-field header after)
8219 (message-position-on-field header))
8220 (insert new-value))))
8222 (defcustom message-recipients-without-full-name
8223 (list "ding@gnus.org"
8225 "emacs-devel@gnu.org"
8226 "emacs-pretest-bug@gnu.org"
8227 "bug-gnu-emacs@gnu.org")
8228 "Mail addresses that have no full name.
8229 Used in `message-simplify-recipients'."
8230 ;; Maybe the addresses could be extracted from
8231 ;; `gnus-parameter-to-list-alist'?
8232 :type '(choice (const :tag "None" nil)
8234 :version "23.1" ;; No Gnus
8235 :group 'message-headers)
8237 (defun message-simplify-recipients ()
8239 (dolist (hdr '("Cc" "To"))
8240 (message-replace-header
8244 (if (and message-recipients-without-full-name
8246 (regexp-opt message-recipients-without-full-name)
8250 (message-make-from (car addrcomp) (cadr addrcomp))
8252 (when (message-fetch-field hdr)
8253 (mail-extract-address-components
8254 (message-fetch-field hdr) t))
8257 (when (featurep 'xemacs)
8258 (require 'messagexmas)
8259 (message-xmas-redefine))
8263 (run-hooks 'message-load-hook)
8266 ;; coding: iso-8859-1
8269 ;;; message.el ends here