1 ;;; message.el --- composing mail and news messages
3 ;; Copyright (C) 1996-2011 Free Software Foundation, Inc.
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
6 ;; Keywords: mail, news
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is free software: you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation, either version 3 of the License, or
13 ;; (at your option) any later version.
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
25 ;; This mode provides mail-sending facilities from within Emacs. It
26 ;; consists mainly of large chunks of code from the sendmail.el,
27 ;; gnus-msg.el and rnewspost.el files.
31 ;; For Emacs <22.2 and XEmacs.
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-cite-style nil
133 "The overall style to be used when yanking cited text.
134 Values are either `traditional' (cited text first),
135 `top-post' (cited text at the bottom), or nil (don't override the
136 individual message variables)."
138 :group 'message-various
139 :type '(choice (const :tag "None" :value nil)
140 (const :tag "Traditional" :value traditional)
141 (const :tag "Top-post" :value top-post)))
143 (defcustom message-fcc-handler-function 'message-output
144 "*A function called to save outgoing articles.
145 This function will be called with the name of the file to store the
146 article in. The default function is `message-output' which saves in Unix
148 :type '(radio (function-item message-output)
149 (function :tag "Other"))
150 :group 'message-sending)
152 (defcustom message-fcc-externalize-attachments nil
153 "If non-nil, attachments are included as external parts in Fcc copies."
156 :group 'message-sending)
158 (defcustom message-courtesy-message
159 "The following message is a courtesy copy of an article\nthat has been posted to %s as well.\n\n"
160 "*This is inserted at the start of a mailed copy of a posted message.
161 If the string contains the format spec \"%s\", the Newsgroups
162 the article has been posted to will be inserted there.
163 If this variable is nil, no such courtesy message will be added."
164 :group 'message-sending
165 :type '(radio string (const nil)))
167 (defcustom message-ignored-bounced-headers
168 "^\\(Received\\|Return-Path\\|Delivered-To\\):"
169 "*Regexp that matches headers to be removed in resent bounced mail."
170 :group 'message-interface
173 (defcustom message-from-style 'default
174 ;; In Emacs 24.1 this defaults to the value of `mail-from-style'
176 ;; `angles' in Emacs 22.1~23.1, XEmacs 21.4, 21.5, and SXEmacs 22.1;
177 ;; `system-default' in Emacs 23.2, and 24.1
178 "Specifies how \"From\" headers look.
180 If nil, they contain just the return address like:
182 If `parens', they look like:
183 king@grassland.com (Elvis Parsley)
184 If `angles', they look like:
185 Elvis Parsley <king@grassland.com>
187 Otherwise, most addresses look like `angles', but they look like
188 `parens' if `angles' would need quoting and `parens' would not."
190 :type '(choice (const :tag "simple" nil)
194 :group 'message-headers)
196 (defcustom message-insert-canlock t
197 "Whether to insert a Cancel-Lock header in news postings."
199 :group 'message-headers
202 (defcustom message-syntax-checks
203 (if message-insert-canlock '((sender . disabled)) nil)
204 ;; Guess this one shouldn't be easy to customize...
205 "*Controls what syntax checks should not be performed on outgoing posts.
206 To disable checking of long signatures, for instance, add
207 `(signature . disabled)' to this list.
209 Don't touch this variable unless you really know what you're doing.
211 Checks include `approved', `bogus-recipient', `continuation-headers',
212 `control-chars', `empty', `existing-newsgroups', `from', `illegible-text',
213 `invisible-text', `long-header-lines', `long-lines', `message-id',
214 `multiple-headers', `new-text', `newsgroups', `quoting-style',
215 `repeated-newsgroups', `reply-to', `sender', `sendsys', `shoot',
216 `shorten-followup-to', `signature', `size', `subject', `subject-cmsg'
217 and `valid-newsgroups'."
219 :type '(repeat sexp)) ; Fixme: improve this
221 (defcustom message-required-headers '((optional . References)
223 "*Headers to be generated or prompted for when sending a message.
224 Also see `message-required-news-headers' and
225 `message-required-mail-headers'."
228 :group 'message-headers
229 :link '(custom-manual "(message)Message Headers")
230 :type '(repeat sexp))
232 (defcustom message-draft-headers '(References From Date)
233 "*Headers to be generated when saving a draft message."
236 :group 'message-headers
237 :link '(custom-manual "(message)Message Headers")
238 :type '(repeat sexp))
240 (defcustom message-required-news-headers
241 '(From Newsgroups Subject Date Message-ID
242 (optional . Organization)
243 (optional . User-Agent))
244 "*Headers to be generated or prompted for when posting an article.
245 RFC977 and RFC1036 require From, Date, Newsgroups, Subject,
246 Message-ID. Organization, Lines, In-Reply-To, Expires, and
247 User-Agent are optional. If you don't want message to insert some
248 header, remove it from this list."
250 :group 'message-headers
251 :link '(custom-manual "(message)Message Headers")
252 :type '(repeat sexp))
254 (defcustom message-required-mail-headers
255 '(From Subject Date (optional . In-Reply-To) Message-ID
256 (optional . User-Agent))
257 "*Headers to be generated or prompted for when mailing a message.
258 It is recommended that From, Date, To, Subject and Message-ID be
259 included. Organization and User-Agent are optional."
261 :group 'message-headers
262 :link '(custom-manual "(message)Message Headers")
263 :type '(repeat sexp))
265 (defcustom message-prune-recipient-rules nil
266 "Rules for how to prune the list of recipients when doing wide replies.
267 This is a list of regexps and regexp matches."
270 :group 'message-headers
271 :link '(custom-manual "(message)Wide Reply")
272 :type '(repeat regexp))
274 (defcustom message-deletable-headers '(Message-ID Date Lines)
275 "Headers to be deleted if they already exist and were generated by message previously."
276 :group 'message-headers
277 :link '(custom-manual "(message)Message Headers")
280 (defcustom message-ignored-news-headers
281 "^NNTP-Posting-Host:\\|^Xref:\\|^[BGF]cc:\\|^Resent-Fcc:\\|^X-Draft-From:\\|^X-Gnus-Agent-Meta-Information:"
282 "*Regexp of headers to be removed unconditionally before posting."
284 :group 'message-headers
285 :link '(custom-manual "(message)Message Headers")
286 :type '(repeat :value-to-internal (lambda (widget value)
287 (custom-split-regexp-maybe value))
288 :match (lambda (widget value)
290 (widget-editable-list-match widget value)))
293 (defcustom message-ignored-mail-headers
294 "^\\([GF]cc\\|Resent-Fcc\\|Xref\\|X-Draft-From\\|X-Gnus-Agent-Meta-Information\\):"
295 "*Regexp of headers to be removed unconditionally before mailing."
297 :group 'message-headers
298 :link '(custom-manual "(message)Mail Headers")
301 (defcustom message-ignored-supersedes-headers "^Path:\\|^Date\\|^NNTP-Posting-Host:\\|^Xref:\\|^Lines:\\|^Received:\\|^X-From-Line:\\|^X-Trace:\\|^X-ID:\\|^X-Complaints-To:\\|Return-Path:\\|^Supersedes:\\|^NNTP-Posting-Date:\\|^X-Trace:\\|^X-Complaints-To:\\|^Cancel-Lock:\\|^Cancel-Key:\\|^X-Hashcash:\\|^X-Payment:\\|^Approved:\\|^Injection-Date:\\|^Injection-Info:"
302 "*Header lines matching this regexp will be deleted before posting.
303 It's best to delete old Path and Date headers before posting to avoid
305 :group 'message-interface
306 :link '(custom-manual "(message)Superseding")
307 :type '(repeat :value-to-internal (lambda (widget value)
308 (custom-split-regexp-maybe value))
309 :match (lambda (widget value)
311 (widget-editable-list-match widget value)))
314 (defcustom message-subject-re-regexp
315 "^[ \t]*\\([Rr][Ee]\\(\\[[0-9]*\\]\\)*:[ \t]*\\)*[ \t]*"
316 "*Regexp matching \"Re: \" in the subject line."
317 :group 'message-various
318 :link '(custom-manual "(message)Message Headers")
321 ;;; Start of variables adopted from `message-utils.el'.
323 (defcustom message-subject-trailing-was-query t
324 "*What to do with trailing \"(was: <old subject>)\" in subject lines.
325 If nil, leave the subject unchanged. If it is the symbol `ask', query
326 the user what do do. In this case, the subject is matched against
327 `message-subject-trailing-was-ask-regexp'. If
328 `message-subject-trailing-was-query' is t, always strip the trailing
329 old subject. In this case, `message-subject-trailing-was-regexp' is
332 :type '(choice (const :tag "never" nil)
333 (const :tag "always strip" t)
335 :link '(custom-manual "(message)Message Headers")
336 :group 'message-various)
338 (defcustom message-subject-trailing-was-ask-regexp
339 "[ \t]*\\([[(]+[Ww][Aa][Ss]:?[ \t]*.*[])]+\\)"
340 "*Regexp matching \"(was: <old subject>)\" in the subject line.
342 The function `message-strip-subject-trailing-was' uses this regexp if
343 `message-subject-trailing-was-query' is set to the symbol `ask'. If
344 the variable is t instead of `ask', use
345 `message-subject-trailing-was-regexp' instead.
347 It is okay to create some false positives here, as the user is asked."
349 :group 'message-various
350 :link '(custom-manual "(message)Message Headers")
353 (defcustom message-subject-trailing-was-regexp
354 "[ \t]*\\((*[Ww][Aa][Ss]:[ \t]*.*)\\)"
355 "*Regexp matching \"(was: <old subject>)\" in the subject line.
357 If `message-subject-trailing-was-query' is set to t, the subject is
358 matched against `message-subject-trailing-was-regexp' in
359 `message-strip-subject-trailing-was'. You should use a regexp creating very
360 few false positives here."
362 :group 'message-various
363 :link '(custom-manual "(message)Message Headers")
366 ;;; marking inserted text
368 (defcustom message-mark-insert-begin
369 "--8<---------------cut here---------------start------------->8---\n"
370 "How to mark the beginning of some inserted text."
373 :link '(custom-manual "(message)Insertion Variables")
374 :group 'message-various)
376 (defcustom message-mark-insert-end
377 "--8<---------------cut here---------------end--------------->8---\n"
378 "How to mark the end of some inserted text."
381 :link '(custom-manual "(message)Insertion Variables")
382 :group 'message-various)
384 (defcustom message-archive-header "X-No-Archive: Yes\n"
385 "Header to insert when you don't want your article to be archived.
386 Archives \(such as groups.google.com\) respect this header."
389 :link '(custom-manual "(message)Header Commands")
390 :group 'message-various)
392 (defcustom message-archive-note
393 "X-No-Archive: Yes - save http://groups.google.com/"
394 "Note to insert why you wouldn't want this posting archived.
395 If nil, don't insert any text in the body."
397 :type '(radio string (const nil))
398 :link '(custom-manual "(message)Header Commands")
399 :group 'message-various)
401 ;;; Crossposts and Followups
402 ;; inspired by JoH-followup-to by Jochem Huhman <joh at gmx.de>
403 ;; new suggestions by R. Weikusat <rw at another.de>
405 (defvar message-cross-post-old-target nil
406 "Old target for cross-posts or follow-ups.")
407 (make-variable-buffer-local 'message-cross-post-old-target)
409 (defcustom message-cross-post-default t
410 "When non-nil `message-cross-post-followup-to' will perform a crosspost.
411 If nil, `message-cross-post-followup-to' will only do a followup. Note that
412 you can explicitly override this setting by calling
413 `message-cross-post-followup-to' with a prefix."
416 :group 'message-various)
418 (defcustom message-cross-post-note "Crosspost & Followup-To: "
419 "Note to insert before signature to notify of cross-post and follow-up."
422 :group 'message-various)
424 (defcustom message-followup-to-note "Followup-To: "
425 "Note to insert before signature to notify of follow-up only."
428 :group 'message-various)
430 (defcustom message-cross-post-note-function 'message-cross-post-insert-note
431 "Function to use to insert note about Crosspost or Followup-To.
432 The function will be called with four arguments. The function should not only
433 insert a note, but also ensure old notes are deleted. See the documentation
434 for `message-cross-post-insert-note'."
437 :group 'message-various)
439 ;;; End of variables adopted from `message-utils.el'.
441 (defcustom message-signature-separator "^-- $"
442 "Regexp matching the signature separator.
443 This variable is used to strip off the signature from quoted text
444 when `message-cite-function' is
445 `message-cite-original-without-signature'. Most useful values
446 are \"^-- $\" (strict) and \"^-- *$\" (loose; allow missing
448 :type '(choice (const :tag "strict" "^-- $")
449 (const :tag "loose" "^-- *$")
451 :version "22.3" ;; Gnus 5.10.12 (changed default)
452 :link '(custom-manual "(message)Various Message Variables")
453 :group 'message-various)
455 (defcustom message-elide-ellipsis "\n[...]\n\n"
456 "*The string which is inserted for elided text."
458 :link '(custom-manual "(message)Various Commands")
459 :group 'message-various)
461 (defcustom message-interactive t
462 ;; In Emacs 24.1 this defaults to the value of `mail-interactive'
464 ;; `nil' in Emacs 22.1~22.3, XEmacs 21.4, 21.5, and SXEmacs 22.1;
465 ;; `t' in Emacs 23.1~24.1
466 "Non-nil means when sending a message wait for and display errors.
467 A value of nil means let mailer mail back a message to report errors."
469 :group 'message-sending
471 :link '(custom-manual "(message)Sending Variables")
474 (defcustom message-confirm-send nil
475 "When non-nil, ask for confirmation when sending a message."
476 :group 'message-sending
478 :version "23.1" ;; No Gnus
479 :link '(custom-manual "(message)Sending Variables")
482 (defcustom message-generate-new-buffers 'unsent
483 "*Say whether to create a new message buffer to compose a message.
484 Valid values include:
487 Generate the buffer name in the Message way (e.g., *mail*, *news*,
488 *mail to whom*, *news on group*, etc.) and continue editing in the
489 existing buffer of that name. If there is no such buffer, it will
493 Create the new buffer with the name generated in the Message way.
496 Similar to `unique' but the buffer name begins with \"*unsent \".
499 Similar to nil but the buffer name is simpler like *mail message*.
502 If this is a function, call that function with three parameters:
503 The type, the To address and the group name (any of these may be nil).
504 The function should return the new buffer name."
506 :group 'message-buffers
507 :link '(custom-manual "(message)Message Buffers")
508 :type '(choice (const nil)
509 (sexp :tag "unique" :format "unique\n" :value unique
510 :match (lambda (widget value) (memq value '(unique t))))
513 (function :format "\n %{%t%}: %v")))
515 (defcustom message-kill-buffer-on-exit nil
516 "*Non-nil means that the message buffer will be killed after sending a message."
517 :group 'message-buffers
518 :link '(custom-manual "(message)Message Buffers")
521 (defcustom message-kill-buffer-query t
522 "*Non-nil means that killing a modified message buffer has to be confirmed.
523 This is used by `message-kill-buffer'."
524 :version "23.1" ;; No Gnus
525 :group 'message-buffers
528 (defcustom message-user-organization
529 (or (getenv "ORGANIZATION") t)
530 "String to be used as an Organization header.
531 If t, use `message-user-organization-file'."
532 :group 'message-headers
533 :type '(choice string
534 (const :tag "consult file" t)))
536 (defcustom message-user-organization-file
538 (dolist (f (list "/etc/organization"
539 "/etc/news/organization"
540 "/usr/lib/news/organization"))
541 (when (file-readable-p f)
544 "*Local news organization file."
546 :link '(custom-manual "(message)News Headers")
547 :group 'message-headers)
549 (defcustom message-make-forward-subject-function
550 #'message-forward-subject-name-subject
551 "*List of functions called to generate subject headers for forwarded messages.
552 The subject generated by the previous function is passed into each
555 The provided functions are:
557 * `message-forward-subject-author-subject' Source of article (author or
558 newsgroup), in brackets followed by the subject
559 * `message-forward-subject-name-subject' Source of article (name of author
560 or newsgroup), in brackets followed by the subject
561 * `message-forward-subject-fwd' Subject of article with 'Fwd:' prepended
563 :group 'message-forwarding
564 :link '(custom-manual "(message)Forwarding")
565 :type '(radio (function-item message-forward-subject-author-subject)
566 (function-item message-forward-subject-fwd)
567 (function-item message-forward-subject-name-subject)
568 (repeat :tag "List of functions" function)))
570 (defcustom message-forward-as-mime t
571 "*Non-nil means forward messages as an inline/rfc822 MIME section.
572 Otherwise, directly inline the old message in the forwarded message."
574 :group 'message-forwarding
575 :link '(custom-manual "(message)Forwarding")
578 (defcustom message-forward-show-mml 'best
579 "*Non-nil means show forwarded messages as MML (decoded from MIME).
580 Otherwise, forwarded messages are unchanged.
581 Can also be the symbol `best' to indicate that MML should be
582 used, except when it is a bad idea to use MML. One example where
583 it is a bad idea is when forwarding a signed or encrypted
584 message, because converting MIME to MML would invalidate the
587 :group 'message-forwarding
588 :type '(choice (const :tag "use MML" t)
589 (const :tag "don't use MML " nil)
590 (const :tag "use MML when appropriate" best)))
592 (defcustom message-forward-before-signature t
593 "*Non-nil means put forwarded message before signature, else after."
594 :group 'message-forwarding
597 (defcustom message-wash-forwarded-subjects nil
598 "*Non-nil means try to remove as much cruft as possible from the subject.
599 Done before generating the new subject of a forward."
600 :group 'message-forwarding
601 :link '(custom-manual "(message)Forwarding")
604 (defcustom message-ignored-resent-headers
605 ;; `Delivered-To' needs to be removed because some mailers use it to
606 ;; detect loops, so if you resend a message to an address that ultimately
607 ;; comes back to you (e.g. a mailing-list to which you subscribe, in which
608 ;; case you may be removed from the list on the grounds that mail to you
609 ;; bounced with a "mailing loop" error).
610 "^Return-receipt\\|^X-Gnus\\|^Gnus-Warning:\\|^>?From \\|^Delivered-To:"
611 "*All headers that match this regexp will be deleted when resending a message."
612 :group 'message-interface
613 :link '(custom-manual "(message)Resending")
614 :type '(repeat :value-to-internal (lambda (widget value)
615 (custom-split-regexp-maybe value))
616 :match (lambda (widget value)
618 (widget-editable-list-match widget value)))
621 (defcustom message-forward-ignored-headers "^Content-Transfer-Encoding:\\|^X-Gnus"
622 "*All headers that match this regexp will be deleted when forwarding a message."
624 :group 'message-forwarding
625 :type '(repeat :value-to-internal (lambda (widget value)
626 (custom-split-regexp-maybe value))
627 :match (lambda (widget value)
629 (widget-editable-list-match widget value)))
632 (defcustom message-ignored-cited-headers "."
633 "*Delete these headers from the messages you yank."
634 :group 'message-insertion
635 :link '(custom-manual "(message)Insertion Variables")
638 (defcustom message-cite-prefix-regexp
639 ;; In Emacs 24.1 this defaults to the value of
640 ;; `mail-citation-prefix-regexp'; the default value varies according
641 ;; to the Emacs version. In XEmacs 21.4 and 21.5, sendmail.el
643 (if (string-match "[[:digit:]]" "1")
644 ;; Support POSIX? XEmacs 21.5.27 doesn't.
645 "\\([ \t]*[_.[:word:]]+>+\\|[ \t]*[]>|]\\)+"
646 ;; ?-, ?_ or ?. MUST NOT be in syntax entry w.
647 (let (non-word-constituents)
648 (with-syntax-table text-mode-syntax-table
649 (setq non-word-constituents
651 (if (string-match "\\w" "_") "" "_")
652 (if (string-match "\\w" ".") "" "."))))
653 (if (equal non-word-constituents "")
654 "\\([ \t]*\\(\\w\\)+>+\\|[ \t]*[]>|]\\)+"
655 (concat "\\([ \t]*\\(\\w\\|["
656 non-word-constituents
657 "]\\)+>+\\|[ \t]*[]>|]\\)+"))))
658 "*Regexp matching the longest possible citation prefix on a line."
660 :group 'message-insertion
661 :link '(custom-manual "(message)Insertion Variables")
663 :set (lambda (symbol value)
665 (custom-set-default symbol value)
666 (if (boundp 'gnus-message-cite-prefix-regexp)
667 (setq gnus-message-cite-prefix-regexp
668 (concat "^\\(?:" value "\\)"))))))
670 (defcustom message-cancel-message "I am canceling my own article.\n"
671 "Message to be inserted in the cancel message."
672 :group 'message-interface
673 :link '(custom-manual "(message)Canceling News")
676 (defun message-send-mail-function ()
677 "Return suitable value for the variable `message-send-mail-function'."
678 (cond ((and (require 'sendmail)
679 (boundp 'sendmail-program)
681 (executable-find sendmail-program))
682 'message-send-mail-with-sendmail)
683 ((and (locate-library "smtpmail")
684 (boundp 'smtpmail-default-smtp-server)
685 smtpmail-default-smtp-server)
686 'message-smtpmail-send-it)
687 ((locate-library "mailclient")
688 'message-send-mail-with-mailclient)
690 (error "Don't know how to send mail. Please customize `message-send-mail-function'"))))
692 ;; Useful to set in site-init.el
693 (defcustom message-send-mail-function
694 (cond ((eq send-mail-function 'smtpmail-send-it) 'message-smtpmail-send-it)
695 ((eq send-mail-function 'feedmail-send-it) 'feedmail-send-it)
696 ((eq send-mail-function 'mailclient-send-it)
697 'message-send-mail-with-mailclient)
698 (t (message-send-mail-function)))
699 "Function to call to send the current buffer as mail.
700 The headers should be delimited by a line whose contents match the
701 variable `mail-header-separator'.
703 Valid values include `message-send-mail-with-sendmail'
704 `message-send-mail-with-mh', `message-send-mail-with-qmail',
705 `message-smtpmail-send-it', `smtpmail-send-it',
706 `feedmail-send-it' and `message-send-mail-with-mailclient'. The
707 default is system dependent and determined by the function
708 `message-send-mail-function'.
710 See also `send-mail-function'."
711 :type '(radio (function-item message-send-mail-with-sendmail)
712 (function-item message-send-mail-with-mh)
713 (function-item message-send-mail-with-qmail)
714 (function-item message-smtpmail-send-it)
715 (function-item smtpmail-send-it)
716 (function-item feedmail-send-it)
717 (function-item message-send-mail-with-mailclient
718 :tag "Use Mailclient package")
719 (function :tag "Other"))
720 :group 'message-sending
722 :initialize 'custom-initialize-default
723 :link '(custom-manual "(message)Mail Variables")
724 :group 'message-mail)
726 (defcustom message-send-news-function 'message-send-news
727 "Function to call to send the current buffer as news.
728 The headers should be delimited by a line whose contents match the
729 variable `mail-header-separator'."
730 :group 'message-sending
732 :link '(custom-manual "(message)News Variables")
735 (defcustom message-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)Reply")
741 :type '(choice function (const nil)))
743 (defcustom message-wide-reply-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)Wide Reply")
749 :type '(choice function (const nil)))
751 (defcustom message-followup-to-function nil
752 "If non-nil, function that should return a list of headers.
753 This function should pick out addresses from the To, Cc, and From headers
754 and respond with new To and Cc headers."
755 :group 'message-interface
756 :link '(custom-manual "(message)Followup")
757 :type '(choice function (const nil)))
759 (defcustom message-extra-wide-headers nil
760 "If non-nil, a list of additional address headers.
761 These are used when composing a wide reply."
762 :group 'message-sending
763 :type '(repeat string))
765 (defcustom message-use-followup-to 'ask
766 "*Specifies what to do with Followup-To header.
767 If nil, always ignore the header. If it is t, use its value, but
768 query before using the \"poster\" value. If it is the symbol `ask',
769 always query the user whether to use the value. If it is the symbol
770 `use', always use the value."
771 :group 'message-interface
772 :link '(custom-manual "(message)Followup")
773 :type '(choice (const :tag "ignore" nil)
774 (const :tag "use & query" t)
778 (defcustom message-use-mail-followup-to 'use
779 "*Specifies what to do with Mail-Followup-To header.
780 If nil, always ignore the header. If it is the symbol `ask', always
781 query the user whether to use the value. If it is the symbol `use',
782 always use the value."
784 :group 'message-interface
785 :link '(custom-manual "(message)Mailing Lists")
786 :type '(choice (const :tag "ignore" nil)
790 (defcustom message-subscribed-address-functions nil
791 "*Specifies functions for determining list subscription.
792 If nil, do not attempt to determine list subscription with functions.
793 If non-nil, this variable contains a list of functions which return
794 regular expressions to match lists. These functions can be used in
795 conjunction with `message-subscribed-regexps' and
796 `message-subscribed-addresses'."
798 :group 'message-interface
799 :link '(custom-manual "(message)Mailing Lists")
800 :type '(repeat sexp))
802 (defcustom message-subscribed-address-file nil
803 "*A file containing addresses the user is subscribed to.
804 If nil, do not look at any files to determine list subscriptions. If
805 non-nil, each line of this file should be a mailing list address."
807 :group 'message-interface
808 :link '(custom-manual "(message)Mailing Lists")
809 :type '(radio file (const nil)))
811 (defcustom message-subscribed-addresses nil
812 "*Specifies a list of addresses the user is subscribed to.
813 If nil, do not use any predefined list subscriptions. This list of
814 addresses can be used in conjunction with
815 `message-subscribed-address-functions' and `message-subscribed-regexps'."
817 :group 'message-interface
818 :link '(custom-manual "(message)Mailing Lists")
819 :type '(repeat string))
821 (defcustom message-subscribed-regexps nil
822 "*Specifies a list of addresses the user is subscribed to.
823 If nil, do not use any predefined list subscriptions. This list of
824 regular expressions can be used in conjunction with
825 `message-subscribed-address-functions' and `message-subscribed-addresses'."
827 :group 'message-interface
828 :link '(custom-manual "(message)Mailing Lists")
829 :type '(repeat regexp))
831 (defcustom message-allow-no-recipients 'ask
832 "Specifies what to do when there are no recipients other than Gcc/Fcc.
833 If it is the symbol `always', the posting is allowed. If it is the
834 symbol `never', the posting is not allowed. If it is the symbol
835 `ask', you are prompted."
837 :group 'message-interface
838 :link '(custom-manual "(message)Message Headers")
839 :type '(choice (const always)
843 (defcustom message-sendmail-f-is-evil nil
844 "*Non-nil means don't add \"-f username\" to the sendmail command line.
845 Doing so would be even more evil than leaving it out."
846 :group 'message-sending
847 :link '(custom-manual "(message)Mail Variables")
850 (defcustom message-sendmail-envelope-from nil
851 ;; In Emacs 24.1 this defaults to the value of `mail-envelope-from'
852 ;; if it is available, or defaults to nil. sendmail.el provides it;
853 ;; the default value is nil in all (X)Emacsen that Gnus supports.
854 "*Envelope-from when sending mail with sendmail.
855 If this is nil, use `user-mail-address'. If it is the symbol
856 `header', use the From: header of the message."
858 :type '(choice (string :tag "From name")
859 (const :tag "Use From: header from message" header)
860 (const :tag "Use `user-mail-address'" nil))
861 :link '(custom-manual "(message)Mail Variables")
862 :group 'message-sending)
864 (defcustom message-sendmail-extra-arguments nil
865 "Additional arguments to `sendmail-program'."
866 ;; E.g. '("-a" "account") for msmtp
867 :version "23.1" ;; No Gnus
868 :type '(repeat string)
869 ;; :link '(custom-manual "(message)Mail Variables")
870 :group 'message-sending)
872 ;; qmail-related stuff
873 (defcustom message-qmail-inject-program "/var/qmail/bin/qmail-inject"
874 "Location of the qmail-inject program."
875 :group 'message-sending
876 :link '(custom-manual "(message)Mail Variables")
879 (defcustom message-qmail-inject-args nil
880 "Arguments passed to qmail-inject programs.
881 This should be a list of strings, one string for each argument.
882 It may also be a function.
884 For e.g., if you wish to set the envelope sender address so that bounces
885 go to the right place or to deal with listserv's usage of that address, you
886 might set this variable to '(\"-f\" \"you@some.where\")."
887 :group 'message-sending
888 :link '(custom-manual "(message)Mail Variables")
889 :type '(choice (function)
892 (defvar gnus-post-method)
893 (defvar gnus-select-method)
894 (defcustom message-post-method
895 (cond ((and (boundp 'gnus-post-method)
896 (listp gnus-post-method)
899 ((boundp 'gnus-select-method)
902 "*Method used to post news.
903 Note that when posting from inside Gnus, for instance, this
904 variable isn't used."
906 :group 'message-sending
907 ;; This should be the `gnus-select-method' widget, but that might
908 ;; create a dependence to `gnus.el'.
911 (defcustom message-generate-headers-first nil
912 "Which headers should be generated before starting to compose a message.
913 If t, generate all required headers. This can also be a list of headers to
914 generate. The variables `message-required-news-headers' and
915 `message-required-mail-headers' specify which headers to generate.
917 Note that the variable `message-deletable-headers' specifies headers which
918 are to be deleted and then re-generated before sending, so this variable
919 will not have a visible effect for those headers."
920 :group 'message-headers
921 :link '(custom-manual "(message)Message Headers")
922 :type '(choice (const :tag "None" nil)
924 (repeat (sexp :tag "Header"))))
926 (defcustom message-fill-column 72
927 "Column beyond which automatic line-wrapping should happen.
928 Local value for message buffers. If non-nil, also turn on
929 auto-fill in message buffers."
930 :group 'message-various
931 ;; :link '(custom-manual "(message)Message Headers")
932 :type '(choice (const :tag "Don't turn on auto fill" nil)
935 (defcustom message-setup-hook nil
936 "Normal hook, run each time a new outgoing message is initialized.
937 The function `message-setup' runs this hook."
938 :group 'message-various
939 :link '(custom-manual "(message)Various Message Variables")
942 (defcustom message-cancel-hook nil
943 "Hook run when cancelling articles."
944 :group 'message-various
945 :link '(custom-manual "(message)Various Message Variables")
948 (defcustom message-signature-setup-hook nil
949 "Normal hook, run each time a new outgoing message is initialized.
950 It is run after the headers have been inserted and before
951 the signature is inserted."
952 :group 'message-various
953 :link '(custom-manual "(message)Various Message Variables")
956 (defcustom message-mode-hook nil
957 "Hook run in message mode buffers."
958 :group 'message-various
961 (defcustom message-header-hook nil
962 "Hook run in a message mode buffer narrowed to the headers."
963 :group 'message-various
966 (defcustom message-header-setup-hook nil
967 "Hook called narrowed to the headers when setting up a message buffer."
968 :group 'message-various
969 :link '(custom-manual "(message)Various Message Variables")
972 (defcustom message-minibuffer-local-map
973 (let ((map (make-sparse-keymap 'message-minibuffer-local-map)))
974 (set-keymap-parent map minibuffer-local-map)
976 "Keymap for `message-read-from-minibuffer'."
978 :group 'message-various)
980 (defcustom message-citation-line-function 'message-insert-citation-line
981 "*Function called to insert the \"Whomever writes:\" line.
983 Predefined functions include `message-insert-citation-line' and
984 `message-insert-formatted-citation-line' (see the variable
985 `message-citation-line-format').
987 Note that Gnus provides a feature where the reader can click on
988 `writes:' to hide the cited text. If you change this line too much,
989 people who read your message will have to change their Gnus
990 configuration. See the variable `gnus-cite-attribution-suffix'."
992 (function-item :tag "plain" message-insert-citation-line)
993 (function-item :tag "formatted" message-insert-formatted-citation-line)
994 (function :tag "Other"))
995 :link '(custom-manual "(message)Insertion Variables")
996 :group 'message-insertion)
998 (defcustom message-citation-line-format "On %a, %b %d %Y, %N wrote:\n"
999 "Format of the \"Whomever writes:\" line.
1001 The string is formatted using `format-spec'. The following
1002 constructs are replaced:
1004 %f The full From, e.g. \"John Doe <john.doe@example.invalid>\".
1005 %n The mail address, e.g. \"john.doe@example.invalid\".
1006 %N The real name if present, e.g.: \"John Doe\", else fall
1007 back to the mail address.
1008 %F The first name if present, e.g.: \"John\".
1009 %L The last name if present, e.g.: \"Doe\".
1011 All other format specifiers are passed to `format-time-string'
1012 which is called using the date from the article your replying to.
1013 Extracting the first (%F) and last name (%L) is done
1014 heuristically, so you should always check it yourself.
1016 Please also read the note in the documentation of
1017 `message-citation-line-function'."
1018 :type '(choice (const :tag "Plain" "%f writes:")
1019 (const :tag "Include date" "On %a, %b %d %Y, %n wrote:")
1021 :link '(custom-manual "(message)Insertion Variables")
1022 :version "23.1" ;; No Gnus
1023 :group 'message-insertion)
1025 (defcustom message-yank-prefix "> "
1026 ;; In Emacs 24.1 this defaults to the value of `mail-yank-prefix'
1027 ;; that defaults to:
1028 ;; `nil' in Emacs 22.1~23.1;
1029 ;; "> " in Emacs 23.2, 24.1, XEmacs 21.4, 21.5, and SXEmacs 22.1
1030 "*Prefix inserted on the lines of yanked messages.
1031 Fix `message-cite-prefix-regexp' if it is set to an abnormal value.
1032 See also `message-yank-cited-prefix' and `message-yank-empty-prefix'."
1035 :link '(custom-manual "(message)Insertion Variables")
1036 :group 'message-insertion)
1038 (defcustom message-yank-cited-prefix ">"
1039 "*Prefix inserted on cited lines of yanked messages.
1040 Fix `message-cite-prefix-regexp' if it is set to an abnormal value.
1041 See also `message-yank-prefix' and `message-yank-empty-prefix'."
1044 :link '(custom-manual "(message)Insertion Variables")
1045 :group 'message-insertion)
1047 (defcustom message-yank-empty-prefix ">"
1048 "*Prefix inserted on empty lines of yanked messages.
1049 See also `message-yank-prefix' and `message-yank-cited-prefix'."
1052 :link '(custom-manual "(message)Insertion Variables")
1053 :group 'message-insertion)
1055 (defcustom message-indentation-spaces 3
1056 ;; In Emacs 24.1 this defaults to the value of
1057 ;; `mail-indentation-spaces' that defaults to `3' in Emacs 22.1~24.1,
1058 ;; and SXEmacs 22.1. In XEmacs 21.4 and 21.5, sendmail.el provides
1059 ;; it; the defalut value is `3'.
1060 "*Number of spaces to insert at the beginning of each cited line.
1061 Used by `message-yank-original' via `message-yank-cite'."
1063 :group 'message-insertion
1064 :link '(custom-manual "(message)Insertion Variables")
1067 (defcustom message-cite-function 'message-cite-original-without-signature
1068 "*Function for citing an original message.
1069 Predefined functions include `message-cite-original' and
1070 `message-cite-original-without-signature'.
1071 Note that these functions use `mail-citation-hook' if that is non-nil."
1072 :type '(radio (function-item message-cite-original)
1073 (function-item message-cite-original-without-signature)
1074 (function-item sc-cite-original)
1075 (function :tag "Other"))
1076 :link '(custom-manual "(message)Insertion Variables")
1077 :version "22.3" ;; Gnus 5.10.12 (changed default)
1078 :group 'message-insertion)
1080 (defcustom message-indent-citation-function 'message-indent-citation
1081 "*Function for modifying a citation just inserted in the mail buffer.
1082 This can also be a list of functions. Each function can find the
1083 citation between (point) and (mark t). And each function should leave
1084 point and mark around the citation text as modified."
1086 :link '(custom-manual "(message)Insertion Variables")
1087 :group 'message-insertion)
1089 (defcustom message-signature t
1090 ;; In Emacs 24.1 this defaults to the value of `mail-signature' that
1092 ;; `nil' in Emacs 22.1~23.1, XEmacs 21.4, 21.5, and SXEmacs 22.1;
1093 ;; `t' in Emacs 23.2, and 24.1
1094 "*String to be inserted at the end of the message buffer.
1095 If t, the `message-signature-file' file will be inserted instead.
1096 If a function, the result from the function will be used instead.
1097 If a form, the result from the form will be used instead."
1100 :link '(custom-manual "(message)Insertion Variables")
1101 :group 'message-insertion)
1103 (defcustom message-signature-file "~/.signature"
1104 ;; In Emacs 24.1 this defaults to the value of `mail-signature-file'
1105 ;; that defaults to "~/.signature" in Emacs 22.1~24.1, and SXEmacs
1106 ;; 22.1. In XEmacs 21.4 and 21.5, sendmail.el provides it;
1107 ;; the defalut value is "~/.signature".
1108 "*Name of file containing the text inserted at end of message buffer.
1109 Ignored if the named file doesn't exist.
1110 If nil, don't insert a signature.
1111 If a path is specified, the value of `message-signature-directory' is ignored,
1114 :type '(choice file (const :tags "None" nil))
1115 :link '(custom-manual "(message)Insertion Variables")
1116 :group 'message-insertion)
1118 (defcustom message-signature-directory nil
1119 "*Name of directory containing signature files.
1120 Comes in handy if you have many such files, handled via posting styles for
1122 If nil, `message-signature-file' is expected to specify the directory if
1124 :type '(choice string (const :tags "None" nil))
1125 :link '(custom-manual "(message)Insertion Variables")
1126 :group 'message-insertion)
1128 (defcustom message-signature-insert-empty-line t
1129 "*If non-nil, insert an empty line before the signature separator."
1132 :link '(custom-manual "(message)Insertion Variables")
1133 :group 'message-insertion)
1135 (defcustom message-distribution-function nil
1136 "*Function called to return a Distribution header."
1137 :group 'message-news
1138 :group 'message-headers
1139 :link '(custom-manual "(message)News Headers")
1140 :type '(choice function (const nil)))
1142 (defcustom message-expires 14
1143 "Number of days before your article expires."
1144 :group 'message-news
1145 :group 'message-headers
1146 :link '(custom-manual "(message)News Headers")
1149 (defcustom message-user-path nil
1150 "If nil, use the NNTP server name in the Path header.
1151 If stringp, use this; if non-nil, use no host name (user name only)."
1152 :group 'message-news
1153 :group 'message-headers
1154 :link '(custom-manual "(message)News Headers")
1155 :type '(choice (const :tag "nntp" nil)
1156 (string :tag "name")
1157 (sexp :tag "none" :format "%t" t)))
1159 ;; This can be the name of a buffer, or a cons cell (FUNCTION . ARGS)
1160 ;; for yanking the original buffer.
1161 (defvar message-reply-buffer nil)
1162 (defvar message-reply-headers nil
1163 "The headers of the current replied article.
1164 It is a vector of the following headers:
1165 \[number subject from date id references chars lines xref extra].")
1166 (defvar message-newsreader nil)
1167 (defvar message-mailer nil)
1168 (defvar message-sent-message-via nil)
1169 (defvar message-checksum nil)
1170 (defvar message-send-actions nil
1171 "A list of actions to be performed upon successful sending of a message.")
1172 (defvar message-return-action nil
1173 "Action to return to the caller after sending or postphoning a message.")
1174 (defvar message-exit-actions nil
1175 "A list of actions to be performed upon exiting after sending a message.")
1176 (defvar message-kill-actions nil
1177 "A list of actions to be performed before killing a message buffer.")
1178 (defvar message-postpone-actions nil
1179 "A list of actions to be performed after postponing a message.")
1181 (define-widget 'message-header-lines 'text
1182 "All header lines must be LFD terminated."
1183 :format "%{%t%}:%n%v"
1184 :valid-regexp "^\\'"
1185 :error "All header lines must be newline terminated")
1187 (defcustom message-default-headers ""
1188 "Header lines to be inserted in outgoing messages.
1189 This can be set to a string containing or a function returning
1190 header lines to be inserted before you edit the message, so you
1191 can edit or delete these lines. If set to a function, it is
1192 called and its result is inserted."
1194 :group 'message-headers
1195 :link '(custom-manual "(message)Message Headers")
1197 (message-header-lines :tag "String")
1198 (function :tag "Function")))
1200 (defcustom message-default-mail-headers
1201 ;; Ease the transition from mail-mode to message-mode. See bugs#4431, 5555.
1202 (concat (if (and (boundp 'mail-default-reply-to)
1203 (stringp mail-default-reply-to))
1204 (format "Reply-to: %s\n" mail-default-reply-to))
1205 (if (and (boundp 'mail-self-blind)
1207 (format "BCC: %s\n" user-mail-address))
1208 (if (and (boundp 'mail-archive-file-name)
1209 (stringp mail-archive-file-name))
1210 (format "FCC: %s\n" mail-archive-file-name))
1211 ;; Use the value of `mail-default-headers' if available.
1212 ;; Note: as for XEmacs 21.4 and 21.5, it is unavailable
1213 ;; unless sendmail.el is loaded.
1214 (if (boundp 'mail-default-headers)
1215 mail-default-headers))
1216 "*A string of header lines to be inserted in outgoing mails."
1218 :group 'message-headers
1219 :group 'message-mail
1220 :link '(custom-manual "(message)Mail Headers")
1221 :type 'message-header-lines)
1223 (defcustom message-default-news-headers ""
1224 "*A string of header lines to be inserted in outgoing news articles."
1225 :group 'message-headers
1226 :group 'message-news
1227 :link '(custom-manual "(message)News Headers")
1228 :type 'message-header-lines)
1230 ;; Note: could use /usr/ucb/mail instead of sendmail;
1231 ;; options -t, and -v if not interactive.
1232 (defcustom message-mailer-swallows-blank-line
1233 (if (and (string-match "sparc-sun-sunos\\(\\'\\|[^5]\\)"
1234 system-configuration)
1235 (file-readable-p "/etc/sendmail.cf")
1237 (insert-file-contents "/etc/sendmail.cf")
1238 (goto-char (point-min))
1239 (let ((case-fold-search nil))
1240 (re-search-forward "^OR\\>" nil t))))
1241 ;; According to RFC822, "The field-name must be composed of printable
1242 ;; ASCII characters (i. e., characters that have decimal values between
1243 ;; 33 and 126, except colon)", i. e., any chars except ctl chars,
1245 '(looking-at "[ \t]\\|[][!\"#$%&'()*+,-./0-9;<=>?@A-Z\\\\^_`a-z{|}~]+:"))
1246 "*Set this non-nil if the system's mailer runs the header and body together.
1247 \(This problem exists on Sunos 4 when sendmail is run in remote mode.)
1248 The value should be an expression to test whether the problem will
1250 :group 'message-sending
1251 :link '(custom-manual "(message)Mail Variables")
1255 (define-mail-user-agent 'message-user-agent
1256 'message-mail 'message-send-and-exit
1257 'message-kill-buffer 'message-send-hook)
1259 (defvar message-mh-deletable-headers '(Message-ID Date Lines Sender)
1260 "If non-nil, delete the deletable headers before feeding to mh.")
1262 (defvar message-send-method-alist
1263 '((news message-news-p message-send-via-news)
1264 (mail message-mail-p message-send-via-mail))
1265 "Alist of ways to send outgoing messages.
1266 Each element has the form
1268 \(TYPE PREDICATE FUNCTION)
1270 where TYPE is a symbol that names the method; PREDICATE is a function
1271 called without any parameters to determine whether the message is
1272 a message of type TYPE; and FUNCTION is a function to be called if
1273 PREDICATE returns non-nil. FUNCTION is called with one parameter --
1276 (defcustom message-mail-alias-type 'abbrev
1277 "*What alias expansion type to use in Message buffers.
1278 The default is `abbrev', which uses mailabbrev. `ecomplete' uses
1279 an electric completion mode. nil switches mail aliases off.
1280 This can also be a list of values."
1282 :link '(custom-manual "(message)Mail Aliases")
1283 :type '(choice (const :tag "Use Mailabbrev" abbrev)
1284 (const :tag "Use ecomplete" ecomplete)
1285 (const :tag "No expansion" nil)))
1287 (defcustom message-self-insert-commands '(self-insert-command)
1288 "List of `self-insert-command's used to trigger ecomplete.
1289 When one of those commands is invoked to enter a character in To or Cc
1290 header, ecomplete will suggest the candidates of recipients (see also
1291 `message-mail-alias-type'). If you use some tool to enter non-ASCII
1292 text and it replaces `self-insert-command' with the other command, e.g.
1293 `egg-self-insert-command', you may want to add it to this list."
1294 :group 'message-various
1295 :type '(repeat function))
1297 (defcustom message-auto-save-directory
1298 (file-name-as-directory (expand-file-name "drafts" message-directory))
1299 "*Directory where Message auto-saves buffers if Gnus isn't running.
1300 If nil, Message won't auto-save."
1301 :group 'message-buffers
1302 :link '(custom-manual "(message)Various Message Variables")
1303 :type '(choice directory (const :tag "Don't auto-save" nil)))
1305 (defcustom message-default-charset
1306 (and (not (mm-multibyte-p)) 'iso-8859-1)
1307 "Default charset used in non-MULE Emacsen.
1308 If nil, you might be asked to input the charset."
1311 :link '(custom-manual "(message)Various Message Variables")
1314 (defcustom message-dont-reply-to-names
1315 (and (boundp 'rmail-dont-reply-to-names) rmail-dont-reply-to-names)
1316 "*Addresses to prune when doing wide replies.
1317 This can be a regexp or a list of regexps. Also, a value of nil means
1318 exclude your own user name only."
1321 :link '(custom-manual "(message)Wide Reply")
1322 :type '(choice (const :tag "Yourself" nil)
1324 (repeat :tag "Regexp List" regexp)))
1326 (defsubst message-dont-reply-to-names ()
1327 (gmm-regexp-concat message-dont-reply-to-names))
1329 (defvar message-shoot-gnksa-feet nil
1330 "*A list of GNKSA feet you are allowed to shoot.
1331 Gnus gives you all the opportunity you could possibly want for
1332 shooting yourself in the foot. Also, Gnus allows you to shoot the
1333 feet of Good Net-Keeping Seal of Approval. The following are foot
1335 `empty-article' Allow you to post an empty article;
1336 `quoted-text-only' Allow you to post quoted text only;
1337 `multiple-copies' Allow you to post multiple copies;
1338 `cancel-messages' Allow you to cancel or supersede messages from
1339 your other email addresses.")
1341 (defsubst message-gnksa-enable-p (feature)
1342 (or (not (listp message-shoot-gnksa-feet))
1343 (memq feature message-shoot-gnksa-feet)))
1345 (defcustom message-hidden-headers '("^References:" "^Face:" "^X-Face:"
1347 "Regexp of headers to be hidden when composing new messages.
1348 This can also be a list of regexps to match headers. Or a list
1349 starting with `not' and followed by regexps."
1352 :link '(custom-manual "(message)Message Headers")
1354 :format "%{%t%}: %[Value Type%] %v"
1355 (regexp :menu-tag "regexp" :format "regexp\n%t: %v")
1356 (repeat :menu-tag "(regexp ...)" :format "(regexp ...)\n%v%i"
1357 (regexp :format "%t: %v"))
1358 (cons :menu-tag "(not regexp ...)" :format "(not regexp ...)\n%v"
1360 (repeat :format "%v%i"
1361 (regexp :format "%t: %v")))))
1363 (defcustom message-cite-articles-with-x-no-archive t
1364 "If non-nil, cite text from articles that has X-No-Archive set."
1368 ;;; Internal variables.
1369 ;;; Well, not really internal.
1371 (defvar message-mode-syntax-table
1372 (let ((table (copy-syntax-table text-mode-syntax-table)))
1373 (modify-syntax-entry ?% ". " table)
1374 (modify-syntax-entry ?> ". " table)
1375 (modify-syntax-entry ?< ". " table)
1377 "Syntax table used while in Message mode.")
1379 (defface message-header-to
1382 (:foreground "DarkOliveGreen1" :bold t))
1385 (:foreground "MidnightBlue" :bold t))
1387 (:bold t :italic t)))
1388 "Face used for displaying From headers."
1389 :group 'message-faces)
1390 ;; backward-compatibility alias
1391 (put 'message-header-to-face 'face-alias 'message-header-to)
1392 (put 'message-header-to-face 'obsolete-face "22.1")
1394 (defface message-header-cc
1397 (:foreground "chartreuse1" :bold t))
1400 (:foreground "MidnightBlue"))
1403 "Face used for displaying Cc headers."
1404 :group 'message-faces)
1405 ;; backward-compatibility alias
1406 (put 'message-header-cc-face 'face-alias 'message-header-cc)
1407 (put 'message-header-cc-face 'obsolete-face "22.1")
1409 (defface message-header-subject
1412 (:foreground "OliveDrab1"))
1415 (:foreground "navy blue" :bold t))
1418 "Face used for displaying subject headers."
1419 :group 'message-faces)
1420 ;; backward-compatibility alias
1421 (put 'message-header-subject-face 'face-alias 'message-header-subject)
1422 (put 'message-header-subject-face 'obsolete-face "22.1")
1424 (defface message-header-newsgroups
1427 (:foreground "yellow" :bold t :italic t))
1430 (:foreground "blue4" :bold t :italic t))
1432 (:bold t :italic t)))
1433 "Face used for displaying newsgroups headers."
1434 :group 'message-faces)
1435 ;; backward-compatibility alias
1436 (put 'message-header-newsgroups-face 'face-alias 'message-header-newsgroups)
1437 (put 'message-header-newsgroups-face 'obsolete-face "22.1")
1439 (defface message-header-other
1442 (:foreground "VioletRed1"))
1445 (:foreground "steel blue"))
1447 (:bold t :italic t)))
1448 "Face used for displaying newsgroups headers."
1449 :group 'message-faces)
1450 ;; backward-compatibility alias
1451 (put 'message-header-other-face 'face-alias 'message-header-other)
1452 (put 'message-header-other-face 'obsolete-face "22.1")
1454 (defface message-header-name
1457 (:foreground "green"))
1460 (:foreground "cornflower blue"))
1463 "Face used for displaying header names."
1464 :group 'message-faces)
1465 ;; backward-compatibility alias
1466 (put 'message-header-name-face 'face-alias 'message-header-name)
1467 (put 'message-header-name-face 'obsolete-face "22.1")
1469 (defface message-header-xheader
1472 (:foreground "DeepSkyBlue1"))
1475 (:foreground "blue"))
1478 "Face used for displaying X-Header headers."
1479 :group 'message-faces)
1480 ;; backward-compatibility alias
1481 (put 'message-header-xheader-face 'face-alias 'message-header-xheader)
1482 (put 'message-header-xheader-face 'obsolete-face "22.1")
1484 (defface message-separator
1487 (:foreground "LightSkyBlue1"))
1490 (:foreground "brown"))
1493 "Face used for displaying the separator."
1494 :group 'message-faces)
1495 ;; backward-compatibility alias
1496 (put 'message-separator-face 'face-alias 'message-separator)
1497 (put 'message-separator-face 'obsolete-face "22.1")
1499 (defface message-cited-text
1502 (:foreground "LightPink1"))
1505 (:foreground "red"))
1508 "Face used for displaying cited text names."
1509 :group 'message-faces)
1510 ;; backward-compatibility alias
1511 (put 'message-cited-text-face 'face-alias 'message-cited-text)
1512 (put 'message-cited-text-face 'obsolete-face "22.1")
1514 (defface message-mml
1517 (:foreground "MediumSpringGreen"))
1520 (:foreground "ForestGreen"))
1523 "Face used for displaying MML."
1524 :group 'message-faces)
1525 ;; backward-compatibility alias
1526 (put 'message-mml-face 'face-alias 'message-mml)
1527 (put 'message-mml-face 'obsolete-face "22.1")
1529 (defun message-font-lock-make-header-matcher (regexp)
1532 (let ((start (point)))
1535 (goto-char (point-min))
1536 (if (re-search-forward
1537 (concat "^" (regexp-quote mail-header-separator) "$")
1539 (setq limit (min limit (match-beginning 0))))
1541 (and (< start limit)
1542 (re-search-forward ,regexp limit t))))))
1543 (if (featurep 'bytecomp)
1547 (defvar message-font-lock-keywords
1548 (let ((content "[ \t]*\\(.+\\(\n[ \t].*\\)*\\)\n?"))
1549 `((,(message-font-lock-make-header-matcher
1550 (concat "^\\([Tt]o:\\)" content))
1551 (1 'message-header-name)
1552 (2 'message-header-to nil t))
1553 (,(message-font-lock-make-header-matcher
1554 (concat "^\\(^[GBF]?[Cc][Cc]:\\|^[Rr]eply-[Tt]o:\\)" content))
1555 (1 'message-header-name)
1556 (2 'message-header-cc nil t))
1557 (,(message-font-lock-make-header-matcher
1558 (concat "^\\([Ss]ubject:\\)" content))
1559 (1 'message-header-name)
1560 (2 'message-header-subject nil t))
1561 (,(message-font-lock-make-header-matcher
1562 (concat "^\\([Nn]ewsgroups:\\|Followup-[Tt]o:\\)" content))
1563 (1 'message-header-name)
1564 (2 'message-header-newsgroups nil t))
1565 (,(message-font-lock-make-header-matcher
1566 (concat "^\\(X-[A-Za-z0-9-]+:\\|In-Reply-To:\\)" content))
1567 (1 'message-header-name)
1568 (2 'message-header-xheader))
1569 (,(message-font-lock-make-header-matcher
1570 (concat "^\\([A-Z][^: \n\t]+:\\)" content))
1571 (1 'message-header-name)
1572 (2 'message-header-other nil t))
1573 ,@(if (and mail-header-separator
1574 (not (equal mail-header-separator "")))
1575 `((,(concat "^\\(" (regexp-quote mail-header-separator) "\\)$")
1576 1 'message-separator))
1579 (re-search-forward (concat "^\\("
1580 message-cite-prefix-regexp
1583 (0 'message-cited-text))
1584 ("<#/?\\(multipart\\|part\\|external\\|mml\\|secure\\)[^>]*>"
1586 "Additional expressions to highlight in Message mode.")
1589 ;; XEmacs does it like this. For Emacs, we have to set the
1590 ;; `font-lock-defaults' buffer-local variable.
1591 (put 'message-mode 'font-lock-defaults '(message-font-lock-keywords t))
1593 (defvar message-face-alist
1594 '((bold . message-bold-region)
1595 (underline . underline-region)
1596 (default . (lambda (b e)
1597 (message-unbold-region b e)
1598 (ununderline-region b e))))
1599 "Alist of mail and news faces for facemenu.
1600 The cdr of each entry is a function for applying the face to a region.")
1602 (defcustom message-send-hook nil
1603 "Hook run before sending messages.
1604 This hook is run quite early when sending."
1605 :group 'message-various
1606 :options '(ispell-message)
1607 :link '(custom-manual "(message)Various Message Variables")
1610 (defcustom message-send-mail-hook nil
1611 "Hook run before sending mail 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-send-news-hook nil
1619 "Hook run before sending news messages.
1620 This hook is run very late -- just before the message is sent as
1622 :group 'message-various
1623 :link '(custom-manual "(message)Various Message Variables")
1626 (defcustom message-sent-hook nil
1627 "Hook run after sending messages."
1628 :group 'message-various
1631 (defvar message-send-coding-system 'binary
1632 "Coding system to encode outgoing mail.")
1634 (defvar message-draft-coding-system
1635 mm-auto-save-coding-system
1636 "*Coding system to compose mail.
1637 If you'd like to make it possible to share draft files between XEmacs
1638 and Emacs, you may use `iso-2022-7bit' for this value at your own risk.
1639 Note that the coding-system `iso-2022-7bit' isn't suitable to all data.")
1641 (defcustom message-send-mail-partially-limit nil
1642 "The limitation of messages sent as message/partial.
1643 The lower bound of message size in characters, beyond which the message
1644 should be sent in several parts. If it is nil, the size is unlimited."
1646 :group 'message-buffers
1647 :link '(custom-manual "(message)Mail Variables")
1648 :type '(choice (const :tag "unlimited" nil)
1651 (defcustom message-alternative-emails nil
1652 "*Regexp matching alternative email addresses.
1653 The first address in the To, Cc or From headers of the original
1654 article matching this variable is used as the From field of
1657 This variable has precedence over posting styles and anything that runs
1658 off `message-setup-hook'."
1659 :group 'message-headers
1660 :link '(custom-manual "(message)Message Headers")
1661 :type '(choice (const :tag "Always use primary" nil)
1664 (defcustom message-hierarchical-addresses nil
1665 "A list of hierarchical mail address definitions.
1667 Inside each entry, the first address is the \"top\" address, and
1668 subsequent addresses are subaddresses; this is used to indicate that
1669 mail sent to the first address will automatically be delivered to the
1670 subaddresses. So if the first address appears in the recipient list
1671 for a message, the subaddresses will be removed (if present) before
1672 the mail is sent. All addresses in this structure should be
1675 :group 'message-headers
1676 :type '(repeat (repeat string)))
1678 (defcustom message-mail-user-agent nil
1679 "Like `mail-user-agent'.
1680 Except if it is nil, use Gnus native MUA; if it is t, use
1683 :type '(radio (const :tag "Gnus native"
1686 (const :tag "`mail-user-agent'"
1689 (function-item :tag "Default Emacs mail"
1691 sendmail-user-agent)
1692 (function-item :tag "Emacs interface to MH"
1695 (function :tag "Other"))
1699 (defcustom message-wide-reply-confirm-recipients nil
1700 "Whether to confirm a wide reply to multiple email recipients.
1701 If this variable is nil, don't ask whether to reply to all recipients.
1702 If this variable is non-nil, pose the question \"Reply to all
1703 recipients?\" before a wide reply to multiple recipients. If the user
1704 answers yes, reply to all recipients as usual. If the user answers
1705 no, only reply back to the author."
1707 :group 'message-headers
1708 :link '(custom-manual "(message)Wide Reply")
1711 (defcustom message-user-fqdn nil
1712 "*Domain part of Message-Ids."
1714 :group 'message-headers
1715 :link '(custom-manual "(message)News Headers")
1716 :type '(radio (const :format "%v " nil)
1717 (string :format "FQDN: %v")))
1719 (defcustom message-use-idna (and (condition-case nil (require 'idna)
1721 (mm-coding-system-p 'utf-8)
1722 (executable-find idna-program)
1723 (string= (idna-to-ascii "räksmörgås")
1724 "xn--rksmrgs-5wao1o")
1726 "Whether to encode non-ASCII in domain names into ASCII according to IDNA.
1727 GNU Libidn, and in particular the elisp package \"idna.el\" and
1728 the external program \"idn\", must be installed for this
1729 functionality to work."
1731 :group 'message-headers
1732 :link '(custom-manual "(message)IDNA")
1733 :type '(choice (const :tag "Ask" ask)
1734 (const :tag "Never" nil)
1735 (const :tag "Always" t)))
1737 (defcustom message-generate-hashcash (if (executable-find "hashcash") 'opportunistic)
1738 "*Whether to generate X-Hashcash: headers.
1739 If t, always generate hashcash headers. If `opportunistic',
1740 only generate hashcash headers if it can be done without the user
1741 waiting (i.e., only asynchronously).
1743 You must have the \"hashcash\" binary installed, see `hashcash-path'."
1745 :group 'message-headers
1746 :link '(custom-manual "(message)Mail Headers")
1747 :type '(choice (const :tag "Always" t)
1748 (const :tag "Never" nil)
1749 (const :tag "Opportunistic" opportunistic)))
1751 ;;; Internal variables.
1753 (defvar message-sending-message "Sending...")
1754 (defvar message-buffer-list nil)
1755 (defvar message-this-is-news nil)
1756 (defvar message-this-is-mail nil)
1757 (defvar message-draft-article nil)
1758 (defvar message-mime-part nil)
1759 (defvar message-posting-charset nil)
1760 (defvar message-inserted-headers nil)
1761 (defvar message-inhibit-ecomplete nil)
1763 ;; Byte-compiler warning
1764 (defvar gnus-active-hashtb)
1765 (defvar gnus-read-active-file)
1767 ;;; Regexp matching the delimiter of messages in UNIX mail format
1768 ;;; (UNIX From lines), minus the initial ^. It should be a copy
1769 ;;; of rmail.el's rmail-unix-mail-delimiter.
1770 (defvar message-unix-mail-delimiter
1771 (let ((time-zone-regexp
1772 (concat "\\([A-Z]?[A-Z]?[A-Z][A-Z]\\( DST\\)?"
1773 "\\|[-+]?[0-9][0-9][0-9][0-9]"
1779 ;; Many things can happen to an RFC 822 mailbox before it is put into
1780 ;; a `From' line. The leading phrase can be stripped, e.g.
1781 ;; `Joe <@w.x:joe@y.z>' -> `<@w.x:joe@y.z>'. The <> can be stripped, e.g.
1782 ;; `<@x.y:joe@y.z>' -> `@x.y:joe@y.z'. Everything starting with a CRLF
1783 ;; can be removed, e.g.
1784 ;; From: joe@y.z (Joe K
1786 ;; can yield `From joe@y.z (Joe K Fri Mar 22 08:11:15 1996', and
1789 ;; can yield `From Joe User Fri Mar 22 08:11:15 1996'.
1790 ;; The mailbox can be removed or be replaced by white space, e.g.
1791 ;; From: "Joe User"{space}{tab}
1793 ;; can yield `From {space}{tab} Fri Mar 22 08:11:15 1996',
1794 ;; where {space} and {tab} represent the Ascii space and tab characters.
1795 ;; We want to match the results of any of these manglings.
1796 ;; The following regexp rejects names whose first characters are
1797 ;; obviously bogus, but after that anything goes.
1798 "\\([^\0-\b\n-\r\^?].*\\)?"
1800 ;; The time the message was sent.
1801 "\\([^\0-\r \^?]+\\) +" ; day of the week
1802 "\\([^\0-\r \^?]+\\) +" ; month
1803 "\\([0-3]?[0-9]\\) +" ; day of month
1804 "\\([0-2][0-9]:[0-5][0-9]\\(:[0-6][0-9]\\)?\\) *" ; time of day
1806 ;; Perhaps a time zone, specified by an abbreviation, or by a
1811 " \\([0-9][0-9]+\\) *"
1813 ;; On some systems the time zone can appear after the year, too.
1817 "\\(remote from .*\\)?"
1820 "Regexp matching the delimiter of messages in UNIX mail format.")
1822 (defvar message-unsent-separator
1823 (concat "^ *---+ +Unsent message follows +---+ *$\\|"
1824 "^ *---+ +Returned message +---+ *$\\|"
1825 "^Start of returned message$\\|"
1826 "^ *---+ +Original message +---+ *$\\|"
1827 "^ *--+ +begin message +--+ *$\\|"
1828 "^ *---+ +Original message follows +---+ *$\\|"
1829 "^ *---+ +Undelivered message follows +---+ *$\\|"
1830 "^------ This is a copy of the message, including all the headers. ------ *$\\|"
1831 "^|? *---+ +Message text follows: +---+ *|?$")
1832 "A regexp that matches the separator before the text of a failed message.")
1834 (defvar message-field-fillers
1835 '((To message-fill-field-address)
1836 (Cc message-fill-field-address)
1837 (From message-fill-field-address))
1838 "Alist of header names/filler functions.")
1840 (defvar message-header-format-alist
1855 (References . message-shorten-references)
1857 "Alist used for formatting headers.")
1859 (defvar message-options nil
1860 "Some saved answers when sending message.")
1862 (defvar message-send-mail-real-function nil
1863 "Internal send mail function.")
1865 (defvar message-bogus-system-names "^localhost\\.\\|\\.local$"
1866 "The regexp of bogus system names.")
1868 (defcustom message-valid-fqdn-regexp
1869 (concat "[a-z0-9][-.a-z0-9]+\\." ;; [hostname.subdomain.]domain.
1871 "\\([a-z][a-z]\\|" ;; two letter country TDLs
1872 "aero\\|arpa\\|bitnet\\|biz\\|bofh\\|"
1873 "cat\\|com\\|coop\\|edu\\|gov\\|"
1874 "info\\|int\\|jobs\\|"
1875 "mil\\|mobi\\|museum\\|name\\|net\\|"
1876 "org\\|pro\\|travel\\|uucp\\)")
1877 ;; http://en.wikipedia.org/wiki/List_of_Internet_top-level_domains
1878 ;; http://en.wikipedia.org/wiki/GTLD
1879 ;; `in the process of being approved': .asia .post .tel .sex
1880 ;; "dead" nato bitnet uucp
1881 "Regular expression that matches a valid FQDN."
1882 ;; see also: gnus-button-valid-fqdn-regexp
1884 :group 'message-headers
1887 (autoload 'gnus-alive-p "gnus-util")
1888 (autoload 'gnus-delay-article "gnus-delay")
1889 (autoload 'gnus-extract-address-components "gnus-util")
1890 (autoload 'gnus-find-method-for-group "gnus")
1891 (autoload 'gnus-group-decoded-name "gnus-group")
1892 (autoload 'gnus-group-name-charset "gnus-group")
1893 (autoload 'gnus-group-name-decode "gnus-group")
1894 (autoload 'gnus-groups-from-server "gnus")
1895 (autoload 'gnus-make-local-hook "gnus-util")
1896 (autoload 'gnus-open-server "gnus-int")
1897 (autoload 'gnus-output-to-mail "gnus-util")
1898 (autoload 'gnus-output-to-rmail "gnus-util")
1899 (autoload 'gnus-request-post "gnus-int")
1900 (autoload 'gnus-select-frame-set-input-focus "gnus-util")
1901 (autoload 'gnus-server-string "gnus")
1902 (autoload 'idna-to-ascii "idna")
1903 (autoload 'message-setup-toolbar "messagexmas")
1904 (autoload 'mh-new-draft-name "mh-comp")
1905 (autoload 'mh-send-letter "mh-comp")
1906 (autoload 'nndraft-request-associate-buffer "nndraft")
1907 (autoload 'nndraft-request-expire-articles "nndraft")
1908 (autoload 'nnvirtual-find-group-art "nnvirtual")
1909 (autoload 'rmail-dont-reply-to "mail-utils")
1910 (autoload 'rmail-msg-is-pruned "rmail")
1911 (autoload 'rmail-output "rmailout")
1916 ;;; Utility functions.
1919 (defmacro message-y-or-n-p (question show &rest text)
1920 "Ask QUESTION, displaying remaining args in a temporary buffer if SHOW."
1921 `(message-talkative-question 'y-or-n-p ,question ,show ,@text))
1923 (defmacro message-delete-line (&optional n)
1924 "Delete the current line (and the next N lines)."
1925 `(delete-region (progn (beginning-of-line) (point))
1926 (progn (forward-line ,(or n 1)) (point))))
1928 (defun message-mark-active-p ()
1929 "Non-nil means the mark and region are currently active in this buffer."
1932 (defun message-unquote-tokens (elems)
1933 "Remove double quotes (\") from strings in list ELEMS."
1934 (mapcar (lambda (item)
1935 (while (string-match "^\\(.*\\)\"\\(.*\\)$" item)
1936 (setq item (concat (match-string 1 item)
1937 (match-string 2 item))))
1941 (defun message-tokenize-header (header &optional separator)
1942 "Split HEADER into a list of header elements.
1943 SEPARATOR is a string of characters to be used as separators. \",\"
1944 is used by default."
1947 (let ((regexp (format "[%s]+" (or separator ",")))
1949 beg quoted elems paren)
1951 (mm-enable-multibyte)
1952 (setq beg (point-min))
1954 (goto-char (point-min))
1959 (cond ((and (> (point) beg)
1961 (and (looking-at regexp)
1964 (push (buffer-substring beg (point)) elems)
1965 (setq beg (match-end 0)))
1966 ((eq (char-after) ?\")
1967 (setq quoted (not quoted)))
1968 ((and (eq (char-after) ?\()
1971 ((and (eq (char-after) ?\))
1974 (nreverse elems)))))
1976 (autoload 'nnheader-insert-file-contents "nnheader")
1978 (defun message-mail-file-mbox-p (file)
1979 "Say whether FILE looks like a Unix mbox file."
1980 (when (and (file-exists-p file)
1981 (file-readable-p file)
1982 (file-regular-p file))
1984 (nnheader-insert-file-contents file)
1985 (goto-char (point-min))
1986 (looking-at message-unix-mail-delimiter))))
1988 (defun message-fetch-field (header &optional not-all)
1989 "The same as `mail-fetch-field', only remove all newlines.
1990 The buffer is expected to be narrowed to just the header of the message;
1991 see `message-narrow-to-headers-or-head'."
1992 (let* ((inhibit-point-motion-hooks t)
1993 (value (mail-fetch-field header nil (not not-all))))
1995 (while (string-match "\n[\t ]+" value)
1996 (setq value (replace-match " " t t value)))
1999 (defun message-field-value (header &optional not-all)
2000 "The same as `message-fetch-field', only narrow to the headers first."
2003 (message-narrow-to-headers-or-head)
2004 (message-fetch-field header not-all))))
2006 (defun message-narrow-to-field ()
2007 "Narrow the buffer to the header on the current line."
2009 (while (looking-at "[ \t]")
2015 (if (re-search-forward "^[^ \n\t]" nil t)
2018 (goto-char (point-min)))
2020 (defun message-add-header (&rest headers)
2021 "Add the HEADERS to the message header, skipping those already present."
2024 (unless (string-match "^\\([^:]+\\):[ \t]*[^ \t]" (car headers))
2025 (error "Invalid header `%s'" (car headers)))
2026 (setq hclean (match-string 1 (car headers)))
2028 (message-narrow-to-headers)
2029 (unless (re-search-forward (concat "^" (regexp-quote hclean) ":") nil t)
2030 (goto-char (point-max))
2031 (if (string-match "\n$" (car headers))
2032 (insert (car headers))
2033 (insert (car headers) ?\n)))))
2034 (setq headers (cdr headers))))
2036 (defmacro message-with-reply-buffer (&rest forms)
2037 "Evaluate FORMS in the reply buffer, if it exists."
2038 `(when (and (bufferp message-reply-buffer)
2039 (buffer-name message-reply-buffer))
2040 (with-current-buffer message-reply-buffer
2043 (put 'message-with-reply-buffer 'lisp-indent-function 0)
2044 (put 'message-with-reply-buffer 'edebug-form-spec '(body))
2046 (defun message-fetch-reply-field (header)
2047 "Fetch field HEADER from the message we're replying to."
2048 (message-with-reply-buffer
2050 (mail-narrow-to-head)
2051 (message-fetch-field header))))
2053 (defun message-strip-list-identifiers (subject)
2054 "Remove list identifiers in `gnus-list-identifiers' from string SUBJECT."
2055 (require 'gnus-sum) ; for gnus-list-identifiers
2056 (let ((regexp (if (stringp gnus-list-identifiers)
2057 gnus-list-identifiers
2058 (mapconcat 'identity gnus-list-identifiers " *\\|"))))
2059 (if (string-match (concat "\\(\\(\\(Re: +\\)?\\(" regexp
2060 " *\\)\\)+\\(Re: +\\)?\\)") subject)
2061 (concat (substring subject 0 (match-beginning 1))
2062 (or (match-string 3 subject)
2063 (match-string 5 subject))
2068 (defun message-strip-subject-re (subject)
2069 "Remove \"Re:\" from subject lines in string SUBJECT."
2070 (if (string-match message-subject-re-regexp subject)
2071 (substring subject (match-end 0))
2074 (defcustom message-replacement-char "."
2075 "Replacement character used instead of unprintable or not decodable chars."
2076 :group 'message-various
2077 :version "22.1" ;; Gnus 5.10.9
2078 :type '(choice string
2082 ;; FIXME: We also should call `message-strip-subject-encoded-words'
2083 ;; when forwarding. Probably in `message-make-forward-subject' and
2084 ;; `message-forward-make-body'.
2086 (defun message-strip-subject-encoded-words (subject)
2087 "Fix non-decodable words in SUBJECT."
2088 ;; Cf. `gnus-simplify-subject-fully'.
2089 (let* ((case-fold-search t)
2090 (replacement-chars (format "[%s%s%s]"
2091 message-replacement-char
2092 message-replacement-char
2093 message-replacement-char))
2094 (enc-word-re "=\\?\\([^?]+\\)\\?\\([QB]\\)\\?\\([^?]+\\)\\(\\?=\\)")
2099 (goto-char (point-min))
2100 (when (re-search-forward enc-word-re nil t)
2101 (setq cs-string (match-string 1)))))
2102 cs-coding q-or-b word-beg word-end)
2103 (if (or (not have-marker) ;; No encoded word found...
2104 ;; ... or double encoding was correct:
2105 (and (stringp cs-string)
2106 (setq cs-string (downcase cs-string))
2107 (mm-coding-system-p (intern cs-string))
2111 Decoded Subject \"%s\"
2112 contains a valid encoded word. Decode again? "
2114 (setq cs-coding (intern cs-string))))))
2118 (goto-char (point-min))
2119 (while (re-search-forward enc-word-re nil t)
2120 (setq cs-string (downcase (match-string 1))
2121 q-or-b (match-string 2)
2122 word-beg (match-beginning 0)
2123 word-end (match-end 0))
2125 (if (mm-coding-system-p (intern cs-string))
2126 (setq cs-coding (intern cs-string))
2128 ;; No double encoded subject? => bogus charset.
2131 (mm-read-coding-system
2133 Decoded Subject \"%s\"
2134 contains an encoded word. The charset `%s' is unknown or invalid.
2135 Hit RET to replace non-decodable characters with \"%s\" or enter replacement
2137 subject cs-string message-replacement-char)))
2139 (replace-match (concat "=?" (symbol-name cs-coding)
2142 (goto-char word-beg)
2143 (re-search-forward "=\\?\\([^?]+\\)\\?\\([QB]\\)\\?" word-end t)
2146 (if (string-match "\\`Q\\'" q-or-b)
2149 (message "Replacing non-decodable characters with \"%s\"."
2150 message-replacement-char)
2151 (while (re-search-forward "\\(=[A-F0-9][A-F0-9]\\)+"
2153 (replace-match message-replacement-char)))
2155 (message "Replacing non-decodable characters with \"%s\"."
2157 (re-search-forward "[^?]+" word-end t)
2158 (replace-match replacement-chars))
2159 (re-search-forward "\\?=")
2160 (replace-match "")))))
2161 (rfc2047-decode-region (point-min) (point-max))
2164 ;;; Start of functions adopted from `message-utils.el'.
2166 (defun message-strip-subject-trailing-was (subject)
2167 "Remove trailing \"(was: <old subject>)\" from SUBJECT lines.
2168 Leading \"Re: \" is not stripped by this function. Use the function
2169 `message-strip-subject-re' for this."
2170 (let* ((query message-subject-trailing-was-query)
2175 message-subject-trailing-was-ask-regexp
2176 message-subject-trailing-was-regexp)
2179 (setq new (substring subject 0 (match-beginning 0))))
2180 (if (or (not found) (eq query nil))
2183 (if (message-y-or-n-p
2184 "Strip `(was: <old subject>)' in subject? " t
2186 "Strip `(was: <old subject>)' in subject "
2187 "and use the new one instead?\n\n"
2188 "Current subject is: \""
2190 "New subject would be: \""
2192 "See the variable `message-subject-trailing-was-query' "
2193 "to get rid of this query."
2198 ;;; Suggested by Jonas Steverud @ www.dtek.chalmers.se/~d4jonas/
2200 (defun message-change-subject (new-subject)
2201 "Ask for NEW-SUBJECT header, append (was: <Old Subject>)."
2204 (read-from-minibuffer "New subject: ")))
2205 (cond ((and (not (or (null new-subject) ; new subject not empty
2206 (zerop (string-width new-subject))
2207 (string-match "^[ \t]*$" new-subject))))
2211 (message-narrow-to-headers)
2212 (message-fetch-field "Subject"))))
2213 (cond ((not old-subject)
2214 (error "No current subject"))
2217 (regexp-quote new-subject)
2219 old-subject)) ; yes, it really is a new subject
2220 ;; delete eventual Re: prefix
2222 (message-strip-subject-re old-subject))
2223 (message-goto-subject)
2224 (message-delete-line)
2225 (insert (concat "Subject: "
2228 old-subject ")\n")))))))))
2230 (defun message-mark-inserted-region (beg end &optional verbatim)
2231 "Mark some region in the current article with enclosing tags.
2232 See `message-mark-insert-begin' and `message-mark-insert-end'.
2233 If VERBATIM, use slrn style verbatim marks (\"#v+\" and \"#v-\")."
2234 (interactive "r\nP")
2236 ;; add to the end of the region first, otherwise end would be invalid
2238 (insert (if verbatim "#v-\n" message-mark-insert-end))
2240 (insert (if verbatim "#v+\n" message-mark-insert-begin))))
2242 (defun message-mark-insert-file (file &optional verbatim)
2243 "Insert FILE at point, marking it with enclosing tags.
2244 See `message-mark-insert-begin' and `message-mark-insert-end'.
2245 If VERBATIM, use slrn style verbatim marks (\"#v+\" and \"#v-\")."
2246 (interactive "fFile to insert: \nP")
2247 ;; reverse insertion to get correct result.
2249 (insert (if verbatim "#v-\n" message-mark-insert-end))
2251 (insert-file-contents file)
2253 (insert (if verbatim "#v+\n" message-mark-insert-begin))))
2255 (defun message-add-archive-header ()
2256 "Insert \"X-No-Archive: Yes\" in the header and a note in the body.
2257 The note can be customized using `message-archive-note'. When called with a
2258 prefix argument, ask for a text to insert. If you don't want the note in the
2259 body, set `message-archive-note' to nil."
2261 (if current-prefix-arg
2262 (setq message-archive-note
2263 (read-from-minibuffer "Reason for No-Archive: "
2264 (cons message-archive-note 0))))
2266 (if (message-goto-signature)
2267 (re-search-backward message-signature-separator))
2268 (when message-archive-note
2269 (insert message-archive-note)
2271 (message-add-header message-archive-header)
2272 (message-sort-headers)))
2274 (defun message-cross-post-followup-to-header (target-group)
2275 "Mangles FollowUp-To and Newsgroups header to point to TARGET-GROUP.
2276 With prefix-argument just set Follow-Up, don't cross-post."
2278 (list ; Completion based on Gnus
2279 (completing-read "Followup To: "
2280 (if (boundp 'gnus-newsrc-alist)
2282 nil nil '("poster" . 0)
2283 (if (boundp 'gnus-group-history)
2284 'gnus-group-history))))
2285 (message-remove-header "Follow[Uu]p-[Tt]o" t)
2286 (message-goto-newsgroups)
2288 ;; if we already did a crosspost before, kill old target
2289 (if (and message-cross-post-old-target
2291 (regexp-quote (concat "," message-cross-post-old-target))
2294 ;; unless (followup is to poster or user explicitly asked not
2295 ;; to cross-post, or target-group is already in Newsgroups)
2296 ;; add target-group to Newsgroups line.
2298 ;; def: cross-post, req:no
2299 (and message-cross-post-default (not current-prefix-arg))
2300 ;; def: no-cross-post, req:yes
2301 (and (not message-cross-post-default) current-prefix-arg))
2302 (not (string-match "poster" target-group))
2303 (not (string-match (regexp-quote target-group)
2304 (message-fetch-field "Newsgroups"))))
2306 (insert (concat "," target-group))))
2307 (end-of-line) ; ensure Followup: comes after Newsgroups:
2308 ;; unless new followup would be identical to Newsgroups line
2309 ;; make a new Followup-To line
2310 (if (not (string-match (concat "^[ \t]*"
2313 (message-fetch-field "Newsgroups")))
2314 (insert (concat "\nFollowup-To: " target-group)))
2315 (setq message-cross-post-old-target target-group))
2317 (defun message-cross-post-insert-note (target-group cross-post in-old
2319 "Insert a in message body note about a set Followup or Crosspost.
2320 If there have been previous notes, delete them. TARGET-GROUP specifies the
2321 group to Followup-To. When CROSS-POST is t, insert note about
2322 crossposting. IN-OLD specifies whether TARGET-GROUP is a member of
2323 OLD-GROUPS. OLD-GROUPS lists the old-groups the posting would have
2324 been made to before the user asked for a Crosspost."
2325 ;; start scanning body for previous uses
2326 (message-goto-signature)
2327 (let ((head (re-search-backward
2328 (concat "^" mail-header-separator)
2329 nil t))) ; just search in body
2330 (message-goto-signature)
2331 (while (re-search-backward
2332 (concat "^" (regexp-quote message-cross-post-note) ".*")
2334 (message-delete-line))
2335 (message-goto-signature)
2336 (while (re-search-backward
2337 (concat "^" (regexp-quote message-followup-to-note) ".*")
2339 (message-delete-line))
2341 (if (message-goto-signature)
2342 (re-search-backward message-signature-separator))
2345 (string-match "^[ \t]*poster[ \t]*$" target-group))
2346 (insert (concat message-followup-to-note target-group "\n"))
2347 (insert (concat message-cross-post-note target-group "\n")))))
2349 (defun message-cross-post-followup-to (target-group)
2350 "Crossposts message and set Followup-To to TARGET-GROUP.
2351 With prefix-argument just set Follow-Up, don't cross-post."
2353 (list ; Completion based on Gnus
2354 (completing-read "Followup To: "
2355 (if (boundp 'gnus-newsrc-alist)
2357 nil nil '("poster" . 0)
2358 (if (boundp 'gnus-group-history)
2359 'gnus-group-history))))
2360 (cond ((not (or (null target-group) ; new subject not empty
2361 (zerop (string-width target-group))
2362 (string-match "^[ \t]*$" target-group)))
2364 (let* ((old-groups (message-fetch-field "Newsgroups"))
2365 (in-old (string-match
2366 (regexp-quote target-group)
2367 (or old-groups ""))))
2368 ;; check whether target exactly matches old Newsgroups
2369 (cond ((not old-groups)
2370 (error "No current newsgroup"))
2374 (regexp-quote target-group)
2377 ;; yes, Newsgroups line must change
2378 (message-cross-post-followup-to-header target-group)
2379 ;; insert note whether we do cross-post or followup-to
2380 (funcall message-cross-post-note-function
2382 (if (or (and message-cross-post-default
2383 (not current-prefix-arg))
2384 (and (not message-cross-post-default)
2385 current-prefix-arg)) t)
2386 in-old old-groups))))))))
2388 ;;; Reduce To: to Cc: or Bcc: header
2390 (defun message-reduce-to-to-cc ()
2391 "Replace contents of To: header with contents of Cc: or Bcc: header."
2394 (save-restriction (message-narrow-to-headers)
2395 (message-fetch-field "cc")))
2397 (if (and (not cc-content)
2400 (message-narrow-to-headers)
2401 (message-fetch-field "bcc"))))
2406 (message-delete-line)
2407 (insert (concat "To: " cc-content "\n"))
2409 (message-narrow-to-headers)
2410 (message-remove-header (if bcc
2414 ;;; End of functions adopted from `message-utils.el'.
2416 (defun message-remove-header (header &optional is-regexp first reverse)
2417 "Remove HEADER in the narrowed buffer.
2418 If IS-REGEXP, HEADER is a regular expression.
2419 If FIRST, only remove the first instance of the header.
2420 Return the number of headers removed."
2421 (goto-char (point-min))
2422 (let ((regexp (if is-regexp header (concat "^" (regexp-quote header) ":")))
2424 (case-fold-search t)
2426 (while (and (not (eobp))
2429 (not (looking-at regexp))
2430 (looking-at regexp))
2437 ;; There might be a continuation header, so we have to search
2438 ;; until we find a new non-continuation line.
2441 (if (re-search-forward "^[^ \t]" nil t)
2442 (goto-char (match-beginning 0))
2445 (if (re-search-forward "^[^ \t]" nil t)
2446 (goto-char (match-beginning 0))
2447 (goto-char (point-max)))))
2450 (defun message-remove-first-header (header)
2451 "Remove the first instance of HEADER if there is more than one."
2453 (regexp (concat "^" (regexp-quote header) ":")))
2455 (goto-char (point-min))
2456 (while (re-search-forward regexp nil t)
2459 (message-remove-header header nil t)
2462 (defun message-narrow-to-headers ()
2463 "Narrow the buffer to the head of the message."
2466 (goto-char (point-min))
2467 (if (re-search-forward
2468 (concat "^" (regexp-quote mail-header-separator) "\n") nil t)
2471 (goto-char (point-min)))
2473 (defun message-narrow-to-head-1 ()
2474 "Like `message-narrow-to-head'. Don't widen."
2476 (goto-char (point-min))
2477 (if (search-forward "\n\n" nil 1)
2480 (goto-char (point-min)))
2482 ;; FIXME: clarify diffference: message-narrow-to-head,
2483 ;; message-narrow-to-headers-or-head, message-narrow-to-headers
2484 (defun message-narrow-to-head ()
2485 "Narrow the buffer to the head of the message.
2486 Point is left at the beginning of the narrowed-to region."
2488 (message-narrow-to-head-1))
2490 (defun message-narrow-to-headers-or-head ()
2491 "Narrow the buffer to the head of the message."
2494 (goto-char (point-min))
2495 (if (re-search-forward (concat "\\(\n\\)\n\\|^\\("
2496 (regexp-quote mail-header-separator)
2499 (or (match-end 1) (match-beginning 2))
2501 (goto-char (point-min)))
2503 (defun message-news-p ()
2504 "Say whether the current buffer contains a news message."
2505 (and (not message-this-is-mail)
2506 (or message-this-is-news
2509 (message-narrow-to-headers)
2510 (and (message-fetch-field "newsgroups")
2511 (not (message-fetch-field "posted-to"))))))))
2513 (defun message-mail-p ()
2514 "Say whether the current buffer contains a mail message."
2515 (and (not message-this-is-news)
2516 (or message-this-is-mail
2519 (message-narrow-to-headers)
2520 (or (message-fetch-field "to")
2521 (message-fetch-field "cc")
2522 (message-fetch-field "bcc")))))))
2524 (defun message-subscribed-p ()
2525 "Say whether we need to insert a MFT header."
2526 (or message-subscribed-regexps
2527 message-subscribed-addresses
2528 message-subscribed-address-file
2529 message-subscribed-address-functions))
2531 (defun message-next-header ()
2532 "Go to the beginning of the next header."
2534 (or (eobp) (forward-char 1))
2535 (not (if (re-search-forward "^[^ \t]" nil t)
2537 (goto-char (point-max)))))
2539 (defun message-sort-headers-1 ()
2540 "Sort the buffer as headers using `message-rank' text props."
2541 (goto-char (point-min))
2544 nil 'message-next-header
2546 (message-next-header)
2550 (or (get-text-property (point) 'message-rank)
2553 (defun message-sort-headers ()
2554 "Sort the headers of the current message according to `message-header-format-alist'."
2558 (let ((max (1+ (length message-header-format-alist)))
2560 (message-narrow-to-headers)
2561 (while (re-search-forward "^[^ \n]+:" nil t)
2563 (match-beginning 0) (1+ (match-beginning 0))
2565 (if (setq rank (length (memq (assq (intern (buffer-substring
2567 (1- (match-end 0))))
2568 message-header-format-alist)
2569 message-header-format-alist)))
2572 (message-sort-headers-1))))
2574 (defun message-kill-address ()
2575 "Kill the address under point."
2577 (let ((start (point)))
2578 (message-skip-to-next-address)
2579 (kill-region start (point))))
2582 (autoload 'Info-goto-node "info")
2583 (defvar mml2015-use)
2585 (defun message-info (&optional arg)
2586 "Display the Message manual.
2588 Prefixed with one \\[universal-argument], display the Emacs MIME
2589 manual. With two \\[universal-argument]'s, display the EasyPG or
2590 PGG manual, depending on the value of `mml2015-use'."
2592 ;; Don't use `info' because support for `(filename)nodename' is not
2593 ;; available in XEmacs < 21.5.12.
2594 (Info-goto-node (format "(%s)Top"
2598 ((eq arg 4) 'emacs-mime)
2599 ;; `booleanp' only available in Emacs 22+
2600 ((and (not (memq arg '(nil t)))
2614 (defvar message-mode-map nil)
2616 (unless message-mode-map
2617 (setq message-mode-map (make-keymap))
2618 (set-keymap-parent message-mode-map text-mode-map)
2619 (define-key message-mode-map "\C-c?" 'describe-mode)
2621 (define-key message-mode-map "\C-c\C-f\C-t" 'message-goto-to)
2622 (define-key message-mode-map "\C-c\C-f\C-o" 'message-goto-from)
2623 (define-key message-mode-map "\C-c\C-f\C-b" 'message-goto-bcc)
2624 (define-key message-mode-map "\C-c\C-f\C-w" 'message-goto-fcc)
2625 (define-key message-mode-map "\C-c\C-f\C-c" 'message-goto-cc)
2626 (define-key message-mode-map "\C-c\C-f\C-s" 'message-goto-subject)
2627 (define-key message-mode-map "\C-c\C-f\C-r" 'message-goto-reply-to)
2628 (define-key message-mode-map "\C-c\C-f\C-n" 'message-goto-newsgroups)
2629 (define-key message-mode-map "\C-c\C-f\C-d" 'message-goto-distribution)
2630 (define-key message-mode-map "\C-c\C-f\C-f" 'message-goto-followup-to)
2631 (define-key message-mode-map "\C-c\C-f\C-m" 'message-goto-mail-followup-to)
2632 (define-key message-mode-map "\C-c\C-f\C-k" 'message-goto-keywords)
2633 (define-key message-mode-map "\C-c\C-f\C-u" 'message-goto-summary)
2634 (define-key message-mode-map "\C-c\C-f\C-i"
2635 'message-insert-or-toggle-importance)
2636 (define-key message-mode-map "\C-c\C-f\C-a"
2637 'message-generate-unsubscribed-mail-followup-to)
2639 ;; modify headers (and insert notes in body)
2640 (define-key message-mode-map "\C-c\C-fs" 'message-change-subject)
2642 (define-key message-mode-map "\C-c\C-fx" 'message-cross-post-followup-to)
2643 ;; prefix+message-cross-post-followup-to = same w/o cross-post
2644 (define-key message-mode-map "\C-c\C-ft" 'message-reduce-to-to-cc)
2645 (define-key message-mode-map "\C-c\C-fa" 'message-add-archive-header)
2646 ;; mark inserted text
2647 (define-key message-mode-map "\C-c\M-m" 'message-mark-inserted-region)
2648 (define-key message-mode-map "\C-c\M-f" 'message-mark-insert-file)
2650 (define-key message-mode-map "\C-c\C-b" 'message-goto-body)
2651 (define-key message-mode-map "\C-c\C-i" 'message-goto-signature)
2653 (define-key message-mode-map "\C-c\C-t" 'message-insert-to)
2654 (define-key message-mode-map "\C-c\C-fw" 'message-insert-wide-reply)
2655 (define-key message-mode-map "\C-c\C-n" 'message-insert-newsgroups)
2656 (define-key message-mode-map "\C-c\C-l" 'message-to-list-only)
2657 (define-key message-mode-map "\C-c\C-f\C-e" 'message-insert-expires)
2659 (define-key message-mode-map "\C-c\C-u" 'message-insert-or-toggle-importance)
2660 (define-key message-mode-map "\C-c\M-n"
2661 'message-insert-disposition-notification-to)
2663 (define-key message-mode-map "\C-c\C-y" 'message-yank-original)
2664 (define-key message-mode-map "\C-c\M-\C-y" 'message-yank-buffer)
2665 (define-key message-mode-map "\C-c\C-q" 'message-fill-yanked-message)
2666 (define-key message-mode-map "\C-c\C-w" 'message-insert-signature)
2667 (define-key message-mode-map "\C-c\M-h" 'message-insert-headers)
2668 (define-key message-mode-map "\C-c\C-r" 'message-caesar-buffer-body)
2669 (define-key message-mode-map "\C-c\C-o" 'message-sort-headers)
2670 (define-key message-mode-map "\C-c\M-r" 'message-rename-buffer)
2672 (define-key message-mode-map "\C-c\C-c" 'message-send-and-exit)
2673 (define-key message-mode-map "\C-c\C-s" 'message-send)
2674 (define-key message-mode-map "\C-c\C-k" 'message-kill-buffer)
2675 (define-key message-mode-map "\C-c\C-d" 'message-dont-send)
2676 (define-key message-mode-map "\C-c\n" 'gnus-delay-article)
2678 (define-key message-mode-map "\C-c\M-k" 'message-kill-address)
2679 (define-key message-mode-map "\C-c\C-e" 'message-elide-region)
2680 (define-key message-mode-map "\C-c\C-v" 'message-delete-not-region)
2681 (define-key message-mode-map "\C-c\C-z" 'message-kill-to-signature)
2682 (define-key message-mode-map "\M-\r" 'message-newline-and-reformat)
2683 (define-key message-mode-map [remap split-line] 'message-split-line)
2685 (define-key message-mode-map "\C-c\C-a" 'mml-attach-file)
2687 (define-key message-mode-map "\C-a" 'message-beginning-of-line)
2688 (define-key message-mode-map "\t" 'message-tab)
2690 (define-key message-mode-map "\M-n" 'message-display-abbrev))
2693 message-mode-menu message-mode-map "Message Menu."
2695 ["Yank Original" message-yank-original message-reply-buffer]
2696 ["Fill Yanked Message" message-fill-yanked-message t]
2697 ["Insert Signature" message-insert-signature t]
2698 ["Caesar (rot13) Message" message-caesar-buffer-body t]
2699 ["Caesar (rot13) Region" message-caesar-region (message-mark-active-p)]
2700 ["Elide Region" message-elide-region
2701 :active (message-mark-active-p)
2702 ,@(if (featurep 'xemacs) nil
2703 '(:help "Replace text in region with an ellipsis"))]
2704 ["Delete Outside Region" message-delete-not-region
2705 :active (message-mark-active-p)
2706 ,@(if (featurep 'xemacs) nil
2707 '(:help "Delete all quoted text outside region"))]
2708 ["Kill To Signature" message-kill-to-signature t]
2709 ["Newline and Reformat" message-newline-and-reformat t]
2710 ["Rename buffer" message-rename-buffer t]
2711 ["Spellcheck" ispell-message
2712 ,@(if (featurep 'xemacs) '(t)
2713 '(:help "Spellcheck this message"))]
2715 ["Insert Region Marked" message-mark-inserted-region
2716 :active (message-mark-active-p)
2717 ,@(if (featurep 'xemacs) nil
2718 '(:help "Mark region with enclosing tags"))]
2719 ["Insert File Marked..." message-mark-insert-file
2720 ,@(if (featurep 'xemacs) '(t)
2721 '(:help "Insert file at point marked with enclosing tags"))]
2723 ["Send Message" message-send-and-exit
2724 ,@(if (featurep 'xemacs) '(t)
2725 '(:help "Send this message"))]
2726 ["Postpone Message" message-dont-send
2727 ,@(if (featurep 'xemacs) '(t)
2728 '(:help "File this draft message and exit"))]
2729 ["Send at Specific Time..." gnus-delay-article
2730 ,@(if (featurep 'xemacs) '(t)
2731 '(:help "Ask, then arrange to send message at that time"))]
2732 ["Kill Message" message-kill-buffer
2733 ,@(if (featurep 'xemacs) '(t)
2734 '(:help "Delete this message without sending"))]
2736 ["Message manual" message-info
2737 ,@(if (featurep 'xemacs) '(t)
2738 '(:help "Display the Message manual"))]))
2741 message-mode-field-menu message-mode-map ""
2743 ["To" message-goto-to t]
2744 ["From" message-goto-from t]
2745 ["Subject" message-goto-subject t]
2746 ["Change subject..." message-change-subject t]
2747 ["Cc" message-goto-cc t]
2748 ["Bcc" message-goto-bcc t]
2749 ["Fcc" message-goto-fcc t]
2750 ["Reply-To" message-goto-reply-to t]
2751 ["Flag As Important" message-insert-importance-high
2752 ,@(if (featurep 'xemacs) '(t)
2753 '(:help "Mark this message as important"))]
2754 ["Flag As Unimportant" message-insert-importance-low
2755 ,@(if (featurep 'xemacs) '(t)
2756 '(:help "Mark this message as unimportant"))]
2758 message-insert-disposition-notification-to
2759 ,@(if (featurep 'xemacs) '(t)
2760 '(:help "Request a receipt notification"))]
2762 ;; (typical) news stuff
2763 ["Summary" message-goto-summary t]
2764 ["Keywords" message-goto-keywords t]
2765 ["Newsgroups" message-goto-newsgroups t]
2766 ["Fetch Newsgroups" message-insert-newsgroups t]
2767 ["Followup-To" message-goto-followup-to t]
2768 ;; ["Followup-To (with note in body)" message-cross-post-followup-to t]
2769 ["Crosspost / Followup-To..." message-cross-post-followup-to t]
2770 ["Distribution" message-goto-distribution t]
2771 ["Expires" message-insert-expires t ]
2772 ["X-No-Archive" message-add-archive-header t ]
2774 ;; (typical) mailing-lists stuff
2775 ["Fetch To" message-insert-to
2776 ,@(if (featurep 'xemacs) '(t)
2777 '(:help "Insert a To header that points to the author."))]
2778 ["Fetch To and Cc" message-insert-wide-reply
2779 ,@(if (featurep 'xemacs) '(t)
2781 "Insert To and Cc headers as if you were doing a wide reply."))]
2783 ["Send to list only" message-to-list-only t]
2784 ["Mail-Followup-To" message-goto-mail-followup-to t]
2785 ["Unsubscribed list post" message-generate-unsubscribed-mail-followup-to
2786 ,@(if (featurep 'xemacs) '(t)
2787 '(:help "Insert a reasonable `Mail-Followup-To:' header."))]
2788 ["Reduce To: to Cc:" message-reduce-to-to-cc t]
2790 ["Sort Headers" message-sort-headers t]
2791 ["Encode non-ASCII domain names" message-idna-to-ascii-rhs t]
2792 ;; We hide `message-hidden-headers' by narrowing the buffer.
2793 ["Show Hidden Headers" widen t]
2794 ["Goto Body" message-goto-body t]
2795 ["Goto Signature" message-goto-signature t]))
2797 (defvar message-tool-bar-map nil)
2799 (defvar facemenu-add-face-function)
2800 (defvar facemenu-remove-face-function)
2802 ;;; Forbidden properties
2804 ;; We use `after-change-functions' to keep special text properties
2805 ;; that interfere with the normal function of message mode out of the
2808 (defcustom message-strip-special-text-properties t
2809 "Strip special properties from the message buffer.
2811 Emacs has a number of special text properties which can break message
2812 composing in various ways. If this option is set, message will strip
2813 these properties from the message composition buffer. However, some
2814 packages requires these properties to be present in order to work.
2815 If you use one of these packages, turn this option off, and hope the
2816 message composition doesn't break too bad."
2818 :group 'message-various
2819 :link '(custom-manual "(message)Various Message Variables")
2822 (defvar message-forbidden-properties
2823 ;; No reason this should be clutter up customize. We make it a
2824 ;; property list (rather than a list of property symbols), to be
2825 ;; directly useful for `remove-text-properties'.
2826 '(field nil read-only nil invisible nil intangible nil
2827 mouse-face nil modification-hooks nil insert-in-front-hooks nil
2828 insert-behind-hooks nil point-entered nil point-left nil)
2829 ;; Other special properties:
2830 ;; category, face, display: probably doesn't do any harm.
2831 ;; fontified: is used by font-lock.
2832 ;; syntax-table, local-map: I dunno.
2833 ;; We need to add XEmacs names to the list.
2834 "Property list of with properties forbidden in message buffers.
2835 The values of the properties are ignored, only the property names are used.")
2837 (defun message-tamago-not-in-use-p (pos)
2838 "Return t when tamago version 4 is not in use at the cursor position.
2839 Tamago version 4 is a popular input method for writing Japanese text.
2840 It uses the properties `intangible', `invisible', `modification-hooks'
2841 and `read-only' when translating ascii or kana text to kanji text.
2842 These properties are essential to work, so we should never strip them."
2843 (not (and (boundp 'egg-modefull-mode)
2844 (symbol-value 'egg-modefull-mode)
2845 (or (memq (get-text-property pos 'intangible)
2846 '(its-part-1 its-part-2))
2847 (get-text-property pos 'egg-end)
2848 (get-text-property pos 'egg-lang)
2849 (get-text-property pos 'egg-start)))))
2851 (defsubst message-mail-alias-type-p (type)
2852 (if (atom message-mail-alias-type)
2853 (eq message-mail-alias-type type)
2854 (memq type message-mail-alias-type)))
2856 (defun message-strip-forbidden-properties (begin end &optional old-length)
2857 "Strip forbidden properties between BEGIN and END, ignoring the third arg.
2858 This function is intended to be called from `after-change-functions'.
2859 See also `message-forbidden-properties'."
2860 (when (and (message-mail-alias-type-p 'ecomplete)
2861 (memq this-command message-self-insert-commands))
2862 (message-display-abbrev))
2863 (when (and message-strip-special-text-properties
2864 (message-tamago-not-in-use-p begin))
2865 (let ((buffer-read-only nil)
2866 (inhibit-read-only t))
2867 (remove-text-properties begin end message-forbidden-properties))))
2869 (autoload 'ecomplete-setup "ecomplete") ;; for Emacs <23.
2872 (define-derived-mode message-mode text-mode "Message"
2873 "Major mode for editing mail and news to be sent.
2874 Like Text Mode but with these additional commands:\\<message-mode-map>
2875 C-c C-s `message-send' (send the message) C-c C-c `message-send-and-exit'
2876 C-c C-d Postpone sending the message C-c C-k Kill the message
2877 C-c C-f move to a header field (and create it if there isn't):
2878 C-c C-f C-t move to To C-c C-f C-s move to Subject
2879 C-c C-f C-c move to Cc C-c C-f C-b move to Bcc
2880 C-c C-f C-w move to Fcc C-c C-f C-r move to Reply-To
2881 C-c C-f C-u move to Summary C-c C-f C-n move to Newsgroups
2882 C-c C-f C-k move to Keywords C-c C-f C-d move to Distribution
2883 C-c C-f C-o move to From (\"Originator\")
2884 C-c C-f C-f move to Followup-To
2885 C-c C-f C-m move to Mail-Followup-To
2886 C-c C-f C-e move to Expires
2887 C-c C-f C-i cycle through Importance values
2888 C-c C-f s change subject and append \"(was: <Old Subject>)\"
2889 C-c C-f x crossposting with FollowUp-To header and note in body
2890 C-c C-f t replace To: header with contents of Cc: or Bcc:
2891 C-c C-f a Insert X-No-Archive: header and a note in the body
2892 C-c C-t `message-insert-to' (add a To header to a news followup)
2893 C-c C-l `message-to-list-only' (removes all but list address in to/cc)
2894 C-c C-n `message-insert-newsgroups' (add a Newsgroup header to a news reply)
2895 C-c C-b `message-goto-body' (move to beginning of message text).
2896 C-c C-i `message-goto-signature' (move to the beginning of the signature).
2897 C-c C-w `message-insert-signature' (insert `message-signature-file' file).
2898 C-c C-y `message-yank-original' (insert current message, if any).
2899 C-c C-q `message-fill-yanked-message' (fill what was yanked).
2900 C-c C-e `message-elide-region' (elide the text between point and mark).
2901 C-c C-v `message-delete-not-region' (remove the text outside the region).
2902 C-c C-z `message-kill-to-signature' (kill the text up to the signature).
2903 C-c C-r `message-caesar-buffer-body' (rot13 the message body).
2904 C-c C-a `mml-attach-file' (attach a file as MIME).
2905 C-c C-u `message-insert-or-toggle-importance' (insert or cycle importance).
2906 C-c M-n `message-insert-disposition-notification-to' (request receipt).
2907 C-c M-m `message-mark-inserted-region' (mark region with enclosing tags).
2908 C-c M-f `message-mark-insert-file' (insert file marked with enclosing tags).
2909 M-RET `message-newline-and-reformat' (break the line and reformat)."
2910 (setq local-abbrev-table text-mode-abbrev-table)
2911 (set (make-local-variable 'message-reply-buffer) nil)
2912 (set (make-local-variable 'message-inserted-headers) nil)
2913 (set (make-local-variable 'message-send-actions) nil)
2914 (set (make-local-variable 'message-return-action) nil)
2915 (set (make-local-variable 'message-exit-actions) nil)
2916 (set (make-local-variable 'message-kill-actions) nil)
2917 (set (make-local-variable 'message-postpone-actions) nil)
2918 (set (make-local-variable 'message-draft-article) nil)
2919 (setq buffer-offer-save t)
2920 (set (make-local-variable 'facemenu-add-face-function)
2922 (let ((face-fun (cdr (assq face message-face-alist))))
2924 (funcall face-fun (point) end)
2925 (error "Face %s not configured for %s mode" face mode-name)))
2927 (set (make-local-variable 'facemenu-remove-face-function) t)
2928 (set (make-local-variable 'message-reply-headers) nil)
2929 (make-local-variable 'message-newsreader)
2930 (make-local-variable 'message-mailer)
2931 (make-local-variable 'message-post-method)
2932 (set (make-local-variable 'message-sent-message-via) nil)
2933 (set (make-local-variable 'message-checksum) nil)
2934 (set (make-local-variable 'message-mime-part) 0)
2935 (message-setup-fill-variables)
2936 (when message-fill-column
2937 (setq fill-column message-fill-column)
2938 (turn-on-auto-fill))
2939 ;; Allow using comment commands to add/remove quoting.
2940 ;; (set (make-local-variable 'comment-start) message-yank-prefix)
2941 (when message-yank-prefix
2942 (set (make-local-variable 'comment-start) message-yank-prefix)
2943 (set (make-local-variable 'comment-start-skip)
2944 (concat "^" (regexp-quote message-yank-prefix) "[ \t]*")))
2945 (if (featurep 'xemacs)
2946 (message-setup-toolbar)
2947 (set (make-local-variable 'font-lock-defaults)
2948 '(message-font-lock-keywords t))
2949 (if (boundp 'tool-bar-map)
2950 (set (make-local-variable 'tool-bar-map) (message-make-tool-bar))))
2951 (easy-menu-add message-mode-menu message-mode-map)
2952 (easy-menu-add message-mode-field-menu message-mode-map)
2953 (gnus-make-local-hook 'after-change-functions)
2954 ;; Mmmm... Forbidden properties...
2955 (add-hook 'after-change-functions 'message-strip-forbidden-properties
2957 ;; Allow mail alias things.
2959 ((message-mail-alias-type-p 'abbrev)
2960 (if (fboundp 'mail-abbrevs-setup)
2961 (mail-abbrevs-setup)
2962 (if (fboundp 'mail-aliases-setup) ; warning avoidance
2963 (mail-aliases-setup))))
2964 ((message-mail-alias-type-p 'ecomplete)
2966 (add-hook 'completion-at-point-functions 'message-completion-function nil t)
2967 (unless buffer-file-name
2968 (message-set-auto-save-file-name))
2969 (unless (buffer-base-buffer)
2970 ;; Don't enable multibyte on an indirect buffer. Maybe enabling
2971 ;; multibyte is not necessary at all. -- zsh
2972 (mm-enable-multibyte))
2973 (set (make-local-variable 'indent-tabs-mode) nil) ;No tabs for indentation.
2976 (defun message-setup-fill-variables ()
2977 "Setup message fill variables."
2978 (set (make-local-variable 'fill-paragraph-function)
2979 'message-fill-paragraph)
2980 (make-local-variable 'paragraph-separate)
2981 (make-local-variable 'paragraph-start)
2982 (make-local-variable 'adaptive-fill-regexp)
2983 (unless (boundp 'adaptive-fill-first-line-regexp)
2984 (setq adaptive-fill-first-line-regexp nil))
2985 (make-local-variable 'adaptive-fill-first-line-regexp)
2986 (let ((quote-prefix-regexp
2987 ;; User should change message-cite-prefix-regexp if
2988 ;; message-yank-prefix is set to an abnormal value.
2989 (concat "\\(" message-cite-prefix-regexp "\\)[ \t]*")))
2990 (setq paragraph-start
2992 (regexp-quote mail-header-separator) "$\\|"
2993 "[ \t]*$\\|" ; blank lines
2994 "-- $\\|" ; signature delimiter
2995 "---+$\\|" ; delimiters for forwarded messages
2996 page-delimiter "$\\|" ; spoiler warnings
2997 ".*wrote:$\\|" ; attribution lines
2998 quote-prefix-regexp "$\\|" ; empty lines in quoted text
3000 "<#!*/?\\(multipart\\|part\\|external\\|mml\\|secure\\)"))
3001 (setq paragraph-separate paragraph-start)
3002 (setq adaptive-fill-regexp
3003 (concat quote-prefix-regexp "\\|" adaptive-fill-regexp))
3004 (setq adaptive-fill-first-line-regexp
3005 (concat quote-prefix-regexp "\\|"
3006 adaptive-fill-first-line-regexp)))
3007 (make-local-variable 'auto-fill-inhibit-regexp)
3008 ;;(setq auto-fill-inhibit-regexp "^[A-Z][^: \n\t]+:")
3009 (setq auto-fill-inhibit-regexp nil)
3010 (make-local-variable 'normal-auto-fill-function)
3011 (setq normal-auto-fill-function 'message-do-auto-fill)
3012 ;; KLUDGE: auto fill might already be turned on in `text-mode-hook'.
3013 ;; In that case, ensure that it uses the right function. The real
3014 ;; solution would be not to use `define-derived-mode', and run
3015 ;; `text-mode-hook' ourself at the end of the mode.
3016 ;; -- Per Abrahamsen <abraham@dina.kvl.dk> Date: 2001-10-19.
3017 ;; This kludge is unneeded in Emacs>=21 since define-derived-mode is
3018 ;; now careful to run parent hooks after the body. --Stef
3019 (when auto-fill-function
3020 (setq auto-fill-function normal-auto-fill-function)))
3025 ;;; Message mode commands
3028 ;;; Movement commands
3030 (defun message-goto-to ()
3031 "Move point to the To header."
3033 (message-position-on-field "To"))
3035 (defun message-goto-from ()
3036 "Move point to the From header."
3038 (message-position-on-field "From"))
3040 (defun message-goto-subject ()
3041 "Move point to the Subject header."
3043 (message-position-on-field "Subject"))
3045 (defun message-goto-cc ()
3046 "Move point to the Cc header."
3048 (message-position-on-field "Cc" "To"))
3050 (defun message-goto-bcc ()
3051 "Move point to the Bcc header."
3053 (message-position-on-field "Bcc" "Cc" "To"))
3055 (defun message-goto-fcc ()
3056 "Move point to the Fcc header."
3058 (message-position-on-field "Fcc" "To" "Newsgroups"))
3060 (defun message-goto-reply-to ()
3061 "Move point to the Reply-To header."
3063 (message-position-on-field "Reply-To" "Subject"))
3065 (defun message-goto-newsgroups ()
3066 "Move point to the Newsgroups header."
3068 (message-position-on-field "Newsgroups"))
3070 (defun message-goto-distribution ()
3071 "Move point to the Distribution header."
3073 (message-position-on-field "Distribution"))
3075 (defun message-goto-followup-to ()
3076 "Move point to the Followup-To header."
3078 (message-position-on-field "Followup-To" "Newsgroups"))
3080 (defun message-goto-mail-followup-to ()
3081 "Move point to the Mail-Followup-To header."
3083 (message-position-on-field "Mail-Followup-To" "To"))
3085 (defun message-goto-keywords ()
3086 "Move point to the Keywords header."
3088 (message-position-on-field "Keywords" "Subject"))
3090 (defun message-goto-summary ()
3091 "Move point to the Summary header."
3093 (message-position-on-field "Summary" "Subject"))
3096 (defmacro message-called-interactively-p (kind)
3099 (eval '(called-interactively-p 'any))
3101 `(called-interactively-p ,kind))
3103 (wrong-number-of-arguments '(called-interactively-p))
3105 (void-function '(interactive-p)))))
3107 (defun message-goto-body ()
3108 "Move point to the beginning of the message body."
3110 (when (and (message-called-interactively-p 'any)
3111 (looking-at "[ \t]*\n"))
3113 (goto-char (point-min))
3114 (or (search-forward (concat "\n" mail-header-separator "\n") nil t)
3115 (search-forward-regexp "[^:]+:\\([^\n]\\|\n[ \t]\\)+\n\n" nil t)))
3117 (defun message-in-body-p ()
3118 "Return t if point is in the message body."
3119 (let ((body (save-excursion (message-goto-body))))
3122 (defun message-goto-eoh ()
3123 "Move point to the end of the headers."
3128 (defun message-goto-signature ()
3129 "Move point to the beginning of the message signature.
3130 If there is no signature in the article, go to the end and
3133 (goto-char (point-min))
3134 (if (re-search-forward message-signature-separator nil t)
3136 (goto-char (point-max))
3139 (defun message-generate-unsubscribed-mail-followup-to (&optional include-cc)
3140 "Insert a reasonable MFT header in a post to an unsubscribed list.
3141 When making original posts to a mailing list you are not subscribed to,
3142 you have to type in a MFT header by hand. The contents, usually, are
3143 the addresses of the list and your own address. This function inserts
3144 such a header automatically. It fetches the contents of the To: header
3145 in the current mail buffer, and appends the current `user-mail-address'.
3147 If the optional argument INCLUDE-CC is non-nil, the addresses in the
3148 Cc: header are also put into the MFT."
3153 (message-narrow-to-headers)
3154 (message-remove-header "Mail-Followup-To")
3155 (setq cc (and include-cc (message-fetch-field "Cc")))
3157 (concat (message-fetch-field "To") "," cc)
3158 (message-fetch-field "To"))))
3159 (message-goto-mail-followup-to)
3160 (insert (concat tos ", " user-mail-address))))
3164 (defun message-insert-to (&optional force)
3165 "Insert a To header that points to the author of the article being replied to.
3166 If the original author requested not to be sent mail, don't insert unless the
3167 prefix FORCE is given."
3169 (let* ((mct (message-fetch-reply-field "mail-copies-to"))
3170 (dont (and mct (or (equal (downcase mct) "never")
3171 (equal (downcase mct) "nobody"))))
3172 (to (or (message-fetch-reply-field "mail-reply-to")
3173 (message-fetch-reply-field "reply-to")
3174 (message-fetch-reply-field "from"))))
3178 "Ignoring the user request not to have copies sent via mail"
3179 "Complying with the user request not to have copies sent via mail")))
3180 (when (and force (not to))
3181 (error "No mail address in the article"))
3182 (when (and to (or force (not dont)))
3183 (message-carefully-insert-headers (list (cons 'To to))))))
3185 (defun message-insert-wide-reply ()
3186 "Insert To and Cc headers as if you were doing a wide reply."
3188 (let ((headers (message-with-reply-buffer
3189 (message-get-reply-headers t))))
3190 (message-carefully-insert-headers headers)))
3192 (defcustom message-header-synonyms
3195 "List of lists of header synonyms.
3196 E.g., if this list contains a member list with elements `Cc' and `To',
3197 then `message-carefully-insert-headers' will not insert a `To' header
3198 when the message is already `Cc'ed to the recipient."
3200 :group 'message-headers
3201 :link '(custom-manual "(message)Message Headers")
3202 :type '(repeat sexp))
3204 (defun message-carefully-insert-headers (headers)
3205 "Insert the HEADERS, an alist, into the message buffer.
3206 Does not insert the headers when they are already present there
3207 or in the synonym headers, defined by `message-header-synonyms'."
3208 ;; FIXME: Should compare only the address and not the full name. Comparison
3209 ;; should be done case-folded (and with `string=' rather than
3211 ;; (mail-strip-quoted-names "Foo Bar <foo@bar>, bla@fasel (Bla Fasel)")
3212 (dolist (header headers)
3213 (let* ((header-name (symbol-name (car header)))
3214 (new-header (cdr header))
3215 (synonyms (loop for synonym in message-header-synonyms
3216 when (memq (car header) synonym) return synonym))
3218 (loop for synonym in synonyms
3219 for old-header = (mail-fetch-field (symbol-name synonym))
3220 when (and old-header (string-match new-header old-header))
3223 (message "already have `%s' in `%s'" new-header old-header)
3224 (when (and (message-position-on-field header-name)
3225 (setq old-header (mail-fetch-field header-name))
3226 (not (string-match "\\` *\\'" old-header)))
3228 (insert new-header)))))
3230 (defun message-widen-reply ()
3231 "Widen the reply to include maximum recipients."
3234 (and (bufferp message-reply-buffer)
3235 (buffer-name message-reply-buffer)
3236 (with-current-buffer message-reply-buffer
3237 (message-get-reply-headers t)))))
3240 (message-narrow-to-headers)
3241 (dolist (elem follow-to)
3242 (message-remove-header (symbol-name (car elem)))
3243 (goto-char (point-min))
3244 (insert (symbol-name (car elem)) ": "
3245 (cdr elem) "\n"))))))
3247 (defun message-insert-newsgroups ()
3248 "Insert the Newsgroups header from the article being replied to."
3250 (when (and (message-position-on-field "Newsgroups")
3251 (mail-fetch-field "newsgroups")
3252 (not (string-match "\\` *\\'" (mail-fetch-field "newsgroups"))))
3254 (insert (or (message-fetch-reply-field "newsgroups") "")))
3258 ;;; Various commands
3260 (defun message-delete-not-region (beg end)
3261 "Delete everything in the body of the current message outside of the region."
3266 ;; snarf citation prefix, if appropriate
3267 (unless (eq (point) (progn (beginning-of-line) (point)))
3268 (when (looking-at message-cite-prefix-regexp)
3269 (setq citeprefix (match-string 0))))
3271 (delete-region (point) (if (not (message-goto-signature))
3277 (delete-region beg (progn (message-goto-body)
3281 (insert citeprefix))))
3282 (when (message-goto-signature)
3285 (defun message-kill-to-signature (&optional arg)
3286 "Kill all text up to the signature.
3287 If a numeric argument or prefix arg is given, leave that number
3288 of lines before the signature intact."
3292 (let ((point (point)))
3293 (narrow-to-region point (point-max))
3294 (message-goto-signature)
3296 (if (and arg (numberp arg))
3297 (forward-line (- -1 arg))
3299 (unless (= point (point))
3300 (kill-region point (point))
3304 (defun message-newline-and-reformat (&optional arg not-break)
3305 "Insert four newlines, and then reformat if inside quoted text.
3306 Prefix arg means justify as well."
3307 (interactive (list (if current-prefix-arg 'full)))
3308 (let (quoted point beg end leading-space bolp fill-paragraph-function)
3309 (setq point (point))
3312 (setq bolp (= beg point))
3313 ;; Find first line of the paragraph.
3315 (while (and (not (eobp))
3316 (not (looking-at message-cite-prefix-regexp))
3317 (looking-at paragraph-start))
3320 (when (looking-at message-cite-prefix-regexp)
3321 (setq quoted (match-string 0))
3322 (goto-char (match-end 0))
3323 (looking-at "[ \t]*")
3324 (setq leading-space (match-string 0)))
3328 (< (- point beg) (length quoted)))
3329 ;; break inside the cite prefix.
3335 (while (and (not (eobp))
3336 (not (looking-at paragraph-separate))
3337 (looking-at message-cite-prefix-regexp)
3338 (equal quoted (match-string 0)))
3339 (goto-char (match-end 0))
3340 (looking-at "[ \t]*")
3341 (if (> (length leading-space) (length (match-string 0)))
3342 (setq leading-space (match-string 0)))
3346 (while (and (if (bobp) nil (forward-line -1) t)
3347 (not (looking-at paragraph-start))
3348 (looking-at message-cite-prefix-regexp)
3349 (equal quoted (match-string 0)))
3351 (goto-char (match-end 0))
3352 (looking-at "[ \t]*")
3353 (if (> (length leading-space) (length (match-string 0)))
3354 (setq leading-space (match-string 0)))))
3355 (while (and (not (eobp))
3356 (not (looking-at paragraph-separate))
3357 (not (looking-at message-cite-prefix-regexp)))
3361 (while (and (if (bobp) nil (forward-line -1) t)
3362 (not (looking-at paragraph-start))
3363 (not (looking-at message-cite-prefix-regexp)))
3364 (setq beg (point))))
3367 (narrow-to-region beg end)
3374 (setq point (point))
3375 ;; (newline 2) doesn't mark both newline's as hard, so call
3376 ;; newline twice. -jas
3379 (delete-region (point) (re-search-forward "[ \t]*"))
3380 (when (and quoted (not bolp))
3381 (insert quoted leading-space)))
3384 (let* ((adaptive-fill-regexp
3385 (regexp-quote (concat quoted leading-space)))
3386 (adaptive-fill-first-line-regexp
3387 adaptive-fill-regexp ))
3388 (fill-paragraph arg))
3389 (fill-paragraph arg))
3390 (if point (goto-char point)))))
3392 (defun message-fill-paragraph (&optional arg)
3393 "Message specific function to fill a paragraph.
3394 This function is used as the value of `fill-paragraph-function' in
3395 Message buffers and is not meant to be called directly."
3396 (interactive (list (if current-prefix-arg 'full)))
3397 (if (if (boundp 'filladapt-mode) filladapt-mode)
3399 (if (message-point-in-header-p)
3400 (message-fill-field)
3401 (message-newline-and-reformat arg t))
3404 (defun message-point-in-header-p ()
3405 "Return t if point is in the header."
3407 (not (re-search-backward
3408 (concat "^" (regexp-quote mail-header-separator) "\n") nil t))))
3410 (defun message-do-auto-fill ()
3411 "Like `do-auto-fill', but don't fill in message header."
3412 (unless (message-point-in-header-p)
3415 (defun message-insert-signature (&optional force)
3416 "Insert a signature. See documentation for variable `message-signature'."
3417 (interactive (list 0))
3420 ((and (null message-signature)
3423 (goto-char (point-max))
3424 (not (re-search-backward message-signature-separator nil t))))
3425 ((and (null message-signature)
3428 ((functionp message-signature)
3429 (funcall message-signature))
3430 ((listp message-signature)
3431 (eval message-signature))
3432 (t message-signature)))
3435 (cond ((stringp signature)
3437 ((and (eq t signature) message-signature-file)
3438 (setq signature-file
3439 (if (and message-signature-directory
3440 ;; don't actually use the signature directory
3441 ;; if message-signature-file contains a path.
3442 (not (file-name-directory
3443 message-signature-file)))
3444 (expand-file-name message-signature-file
3445 message-signature-directory)
3446 message-signature-file))
3447 (file-exists-p signature-file))))
3449 (goto-char (point-max))
3450 ;; Insert the signature.
3453 (when message-signature-insert-empty-line
3456 (if (eq signature t)
3457 (insert-file-contents signature-file)
3459 (goto-char (point-max))
3460 (or (bolp) (insert "\n")))))
3462 (defun message-insert-importance-high ()
3463 "Insert header to mark message as important."
3467 (message-narrow-to-headers)
3468 (message-remove-header "Importance"))
3470 (insert "Importance: high\n")))
3472 (defun message-insert-importance-low ()
3473 "Insert header to mark message as unimportant."
3477 (message-narrow-to-headers)
3478 (message-remove-header "Importance"))
3480 (insert "Importance: low\n")))
3482 (defun message-insert-or-toggle-importance ()
3483 "Insert a \"Importance: high\" header, or cycle through the header values.
3484 The three allowed values according to RFC 1327 are `high', `normal'
3491 (message-narrow-to-headers)
3492 (when (setq cur (message-fetch-field "Importance"))
3493 (message-remove-header "Importance")
3494 (setq new (cond ((string= cur "high")
3496 ((string= cur "low")
3501 (insert (format "Importance: %s\n" new)))))
3503 (defun message-insert-disposition-notification-to ()
3504 "Request a disposition notification (return receipt) to this message.
3505 Note that this should not be used in newsgroups."
3509 (message-narrow-to-headers)
3510 (message-remove-header "Disposition-Notification-To"))
3512 (insert (format "Disposition-Notification-To: %s\n"
3513 (or (message-field-value "Reply-to")
3514 (message-field-value "From")
3515 (message-make-from))))))
3517 (defun message-elide-region (b e)
3518 "Elide the text in the region.
3519 An ellipsis (from `message-elide-ellipsis') will be inserted where the
3523 (insert message-elide-ellipsis))
3525 (defvar message-caesar-translation-table nil)
3527 (defun message-caesar-region (b e &optional n)
3528 "Caesar rotate region B to E by N, default 13, for decrypting netnews."
3531 (min (point) (or (mark t) (point)))
3532 (max (point) (or (mark t) (point)))
3533 (when current-prefix-arg
3534 (prefix-numeric-value current-prefix-arg))))
3536 (setq n (if (numberp n) (mod n 26) 13)) ;canonize N
3537 (unless (or (zerop n) ; no action needed for a rot of 0
3538 (= b e)) ; no region to rotate
3539 ;; We build the table, if necessary.
3540 (when (or (not message-caesar-translation-table)
3541 (/= (aref message-caesar-translation-table ?a) (+ ?a n)))
3542 (setq message-caesar-translation-table
3543 (message-make-caesar-translation-table n)))
3544 (translate-region b e message-caesar-translation-table)))
3546 (defun message-make-caesar-translation-table (n)
3547 "Create a rot table with offset N."
3549 (table (make-string 256 0)))
3550 (while (< (incf i) 256)
3553 (substring table 0 ?A)
3554 (substring table (+ ?A n) (+ ?A n (- 26 n)))
3555 (substring table ?A (+ ?A n))
3556 (substring table (+ ?A 26) ?a)
3557 (substring table (+ ?a n) (+ ?a n (- 26 n)))
3558 (substring table ?a (+ ?a n))
3559 (substring table (+ ?a 26) 255))))
3561 (defun message-caesar-buffer-body (&optional rotnum wide)
3562 "Caesar rotate all letters in the current buffer by 13 places.
3563 Used to encode/decode possibly offensive messages (commonly in rec.humor).
3564 With prefix arg, specifies the number of places to rotate each letter forward.
3565 Mail and USENET news headers are not rotated unless WIDE is non-nil."
3566 (interactive (if current-prefix-arg
3567 (list (prefix-numeric-value current-prefix-arg))
3571 (when (and (not wide) (message-goto-body))
3572 (narrow-to-region (point) (point-max)))
3573 (message-caesar-region (point-min) (point-max) rotnum))))
3575 (defun message-pipe-buffer-body (program)
3576 "Pipe the message body in the current buffer through PROGRAM."
3579 (when (message-goto-body)
3580 (narrow-to-region (point) (point-max)))
3581 (shell-command-on-region
3582 (point-min) (point-max) program nil t))))
3584 (defun message-rename-buffer (&optional enter-string)
3585 "Rename the *message* buffer to \"*message* RECIPIENT\".
3586 If the function is run with a prefix, it will ask for a new buffer
3587 name, rather than giving an automatic name."
3588 (interactive "Pbuffer name: ")
3591 (goto-char (point-min))
3592 (narrow-to-region (point)
3593 (search-forward mail-header-separator nil 'end))
3595 (if (message-news-p) (message-fetch-field "Newsgroups")
3596 (message-fetch-field "To"))
3599 (if (string-match "," mail-to)
3600 (concat (substring mail-to 0 (match-beginning 0)) ", ...")
3602 (name-default (concat "*message* " mail-trimmed-to))
3603 (name (if enter-string
3604 (read-string "New buffer name: " name-default)
3606 (rename-buffer name t)))))
3608 (defun message-fill-yanked-message (&optional justifyp)
3609 "Fill the paragraphs of a message yanked into this one.
3610 Numeric argument means justify as well."
3613 (goto-char (point-min))
3614 (search-forward (concat "\n" mail-header-separator "\n") nil t)
3615 (let ((fill-prefix message-yank-prefix))
3616 (fill-individual-paragraphs (point) (point-max) justifyp))))
3618 (defun message-indent-citation (&optional start end yank-only)
3619 "Modify text just inserted from a message to be cited.
3620 The inserted text should be the region.
3621 When this function returns, the region is again around the modified text.
3623 Normally, indent each nonblank line `message-indentation-spaces' spaces.
3624 However, if `message-yank-prefix' is non-nil, insert that prefix on each line."
3625 (unless start (setq start (point)))
3627 ;; Remove unwanted headers.
3628 (when message-ignored-cited-headers
3633 (if (search-forward "\n\n" nil t)
3636 (message-remove-header message-ignored-cited-headers t)
3637 (when (= (point-min) (point-max))
3638 (setq all-removed t))
3639 (goto-char (point-max)))
3643 ;; Delete blank lines at the start of the buffer.
3644 (while (and (point-min)
3647 (message-delete-line))
3648 ;; Delete blank lines at the end of the buffer.
3649 (goto-char (point-max))
3652 (while (and (zerop (forward-line -1))
3654 (message-delete-line)))
3655 ;; Do the indentation.
3656 (if (null message-yank-prefix)
3657 (indent-rigidly start (or end (mark t)) message-indentation-spaces)
3660 (while (< (point) (or end (mark t)))
3661 (cond ((looking-at ">")
3662 (insert message-yank-cited-prefix))
3664 (insert message-yank-empty-prefix))
3666 (insert message-yank-prefix)))
3670 (defun message-remove-blank-cited-lines (&optional remove)
3671 "Remove cited lines containing only blanks.
3672 If REMOVE is non-nil, remove newlines, too.
3674 To use this automatically, you may add this function to
3675 `gnus-message-setup-hook'."
3680 (when (boundp 'message-yank-cited-prefix)
3681 (concat message-yank-cited-prefix "\\|"))
3685 (gnus-message 8 "removing `%s'" citexp)
3688 (while (re-search-forward citexp nil t)
3689 (replace-match (if remove "" "\n"))))))
3691 (defvar message-cite-reply-above nil
3692 "If non-nil, start own text above the quote.
3694 Note: Top posting is bad netiquette. Don't use it unless you
3695 really must. You probably want to set variable only for specific
3696 groups, e.g. using `gnus-posting-styles':
3698 (eval (set (make-local-variable 'message-cite-reply-above) t))
3700 This variable has no effect in news postings.")
3702 (defun message-yank-original (&optional arg)
3703 "Insert the message being replied to, if any.
3704 Puts point before the text and mark after.
3705 Normally indents each nonblank line ARG spaces (default 3). However,
3706 if `message-yank-prefix' is non-nil, insert that prefix on each line.
3708 This function uses `message-cite-function' to do the actual citing.
3710 Just \\[universal-argument] as argument means don't indent, insert no
3711 prefix, and don't delete any headers."
3713 (let ((modified (buffer-modified-p))
3715 (when (and message-reply-buffer
3716 message-cite-function)
3717 (when message-cite-reply-above
3718 (if (and (not (message-news-p))
3719 (or (eq message-cite-reply-above 'is-evil)
3721 Top posting is bad netiquette. Please don't top post unless you really must.
3722 Really top post? ")))
3725 (buffer-substring (message-goto-body)
3727 (delete-region (message-goto-body) (point-max)))
3728 (set (make-local-variable 'message-cite-reply-above) nil)))
3729 (if (bufferp message-reply-buffer)
3730 (delete-windows-on message-reply-buffer t))
3731 (push-mark (save-excursion
3733 ((bufferp message-reply-buffer)
3734 (insert-buffer-substring message-reply-buffer))
3735 ((and (consp message-reply-buffer)
3736 (functionp (car message-reply-buffer)))
3737 (apply (car message-reply-buffer)
3738 (cdr message-reply-buffer))))
3743 (funcall message-cite-function)
3744 (unless (eq (char-before (mark t)) ?\n)
3746 (goto-char (mark t))
3747 (insert-before-markers ?\n)
3749 (when message-cite-reply-above
3752 (insert (if (bolp) "\n" "\n\n"))
3753 (message-goto-body))
3754 ;; Add a `message-setup-very-last-hook' here?
3755 ;; Add `gnus-article-highlight-citation' here?
3757 (setq message-checksum (message-checksum))))))
3759 (defun message-yank-buffer (buffer)
3760 "Insert BUFFER into the current buffer and quote it."
3761 (interactive "bYank buffer: ")
3762 (let ((message-reply-buffer (get-buffer buffer)))
3763 (save-window-excursion
3764 (message-yank-original))))
3766 (defun message-buffers ()
3767 "Return a list of active message buffers."
3769 (save-current-buffer
3770 (dolist (buffer (buffer-list t))
3772 (when (and (eq major-mode 'message-mode)
3773 (null message-sent-message-via))
3774 (push (buffer-name buffer) buffers))))
3775 (nreverse buffers)))
3777 (defun message-cite-original-1 (strip-signature)
3778 "Cite an original message.
3779 If STRIP-SIGNATURE is non-nil, strips off the signature from the
3782 This function uses `mail-citation-hook' if that is non-nil."
3783 (if (and (boundp 'mail-citation-hook)
3785 (run-hooks 'mail-citation-hook)
3786 (let* ((start (point))
3790 (when message-indent-citation-function
3791 (if (listp message-indent-citation-function)
3792 message-indent-citation-function
3793 (list message-indent-citation-function))))
3794 ;; This function may be called by `gnus-summary-yank-message' and
3795 ;; may insert a different article from the original. So, we will
3796 ;; modify the value of `message-reply-headers' with that article.
3797 (message-reply-headers
3799 (narrow-to-region start end)
3800 (message-narrow-to-head-1)
3801 (setq x-no-archive (message-fetch-field "x-no-archive"))
3803 (or (message-fetch-field "subject") "none")
3804 (or (message-fetch-field "from") "nobody")
3805 (message-fetch-field "date")
3806 (message-fetch-field "message-id" t)
3807 (message-fetch-field "references")
3809 (mml-quote-region start end)
3810 (when strip-signature
3814 (when (re-search-backward message-signature-separator start t)
3815 ;; Also peel off any blank lines before the signature.
3817 (while (looking-at "^[ \t]*$")
3820 (delete-region (point) end)
3821 (unless (search-backward "\n\n" start t)
3822 ;; Insert a blank line if it is peeled off.
3825 (mapc 'funcall functions)
3826 (when message-citation-line-function
3829 (funcall message-citation-line-function))
3830 (when (and x-no-archive
3831 (not message-cite-articles-with-x-no-archive)
3832 (string-match "yes" x-no-archive))
3834 (delete-region (point) (mark t))
3835 (insert "> [Quoted text removed due to X-No-Archive]\n")
3837 (forward-line -1)))))
3839 (defun message-cite-original ()
3840 "Cite function in the standard Message manner."
3841 (message-cite-original-1 nil))
3843 (defvar gnus-extract-address-components)
3845 (autoload 'format-spec "format-spec")
3847 (defun message-insert-formatted-citation-line (&optional from date)
3848 "Function that inserts a formatted citation line.
3850 See `message-citation-line-format'."
3851 ;; The optional args are for testing/debugging. They will disappear later.
3853 ;; (with-temp-buffer
3854 ;; (message-insert-formatted-citation-line
3855 ;; "John Doe <john.doe@example.invalid>"
3858 (when (or message-reply-headers (and from date))
3860 (setq from (mail-header-from message-reply-headers)))
3861 (let* ((data (condition-case ()
3862 (funcall (if (boundp gnus-extract-address-components)
3863 gnus-extract-address-components
3864 'mail-extract-address-components)
3870 (net (car (cdr data)))
3871 (name-or-net (or (car data)
3872 (car (cdr data)) from))
3876 ;; We need Gnus functionality if the user wants date or time from
3877 ;; the original article:
3878 (when (string-match "%[^fnNFL]" message-citation-line-format)
3879 (autoload 'gnus-date-get-time "gnus-util")
3880 (gnus-date-get-time (mail-header-date message-reply-headers)))))
3883 (when (stringp name)
3884 ;; Guess first name and last name:
3885 (cond ((string-match
3886 "\\`\\(\\w\\|[-.]\\)+ \\(\\w\\|[-.]\\)+\\'" name)
3887 (setq fname (nth 0 (split-string name "[ \t]+"))
3888 lname (nth 1 (split-string name "[ \t]+"))))
3890 "\\`\\(\\w\\|[-.]\\)+, \\(\\w\\|[-.]\\)+\\'" name)
3891 (setq fname (nth 1 (split-string name "[ \t,]+"))
3892 lname (nth 0 (split-string name "[ \t,]+"))))
3894 "\\`\\(\\w\\|[-.]\\)+\\'" name)
3897 ;; The following letters are not used in `format-time-string':
3898 (push ?E lst) (push "<E>" lst)
3899 (push ?F lst) (push fname lst)
3900 ;; We might want to use "" instead of "<X>" later.
3901 (push ?J lst) (push "<J>" lst)
3902 (push ?K lst) (push "<K>" lst)
3903 (push ?L lst) (push lname lst)
3904 (push ?N lst) (push name-or-net lst)
3905 (push ?O lst) (push "<O>" lst)
3906 (push ?P lst) (push "<P>" lst)
3907 (push ?Q lst) (push "<Q>" lst)
3908 (push ?f lst) (push from lst)
3909 (push ?i lst) (push "<i>" lst)
3910 (push ?n lst) (push net lst)
3911 (push ?o lst) (push "<o>" lst)
3912 (push ?q lst) (push "<q>" lst)
3913 (push ?t lst) (push "<t>" lst)
3914 (push ?v lst) (push "<v>" lst)
3915 ;; Delegate the rest to `format-time-string':
3917 (when (and (not (memq i lst))
3922 (push (condition-case nil
3923 (format-time-string (format "%%%c" i) replydate)
3924 (error (format ">%c<" i)))
3928 (spec (apply 'format-spec-make flist)))
3929 (insert (format-spec message-citation-line-format spec)))
3932 (defun message-cite-original-without-signature ()
3933 "Cite function in the standard Message manner.
3934 This function strips off the signature from the original message."
3935 (message-cite-original-1 t))
3937 (defun message-insert-citation-line ()
3938 "Insert a simple citation line."
3939 (when message-reply-headers
3940 (insert (mail-header-from message-reply-headers) " writes:")
3944 (defun message-position-on-field (header &rest afters)
3945 (let ((case-fold-search t))
3948 (goto-char (point-min))
3951 (concat "^" (regexp-quote mail-header-separator) "$"))
3952 (match-beginning 0)))
3953 (goto-char (point-min))
3954 (if (re-search-forward (concat "^" (regexp-quote header) ":") nil t)
3956 (re-search-forward "^[^ \t]" nil 'move)
3958 (skip-chars-backward "\n")
3961 (not (re-search-forward
3962 (concat "^" (regexp-quote (car afters)) ":")
3966 (re-search-forward "^[^ \t]" nil 'move)
3967 (beginning-of-line))
3968 (insert header ": \n")
3972 (defun message-remove-signature ()
3973 "Remove the signature from the text between point and mark.
3974 The text will also be indented the normal way."
3976 (let ((start (point))
3978 (if (not (re-search-forward message-signature-separator (mark t) t))
3979 ;; No signature here, so we just indent the cited text.
3980 (message-indent-citation)
3981 ;; Find the last non-empty line.
3983 (while (looking-at "[ \t]*$")
3986 (setq mark (set-marker (make-marker) (point)))
3988 (message-indent-citation)
3989 ;; Enable undoing the deletion.
3991 (delete-region mark (mark t))
3992 (set-marker mark nil)))))
3997 ;;; Sending messages
4000 (defun message-send-and-exit (&optional arg)
4001 "Send message like `message-send', then, if no errors, exit from mail buffer."
4003 (let ((buf (current-buffer))
4004 (actions message-exit-actions))
4005 (when (and (message-send arg)
4008 (if message-kill-buffer-on-exit
4010 (message-do-actions actions)
4013 (defun message-dont-send ()
4014 "Don't send the message you have been editing.
4015 Instead, just auto-save the buffer and then bury it."
4017 (set-buffer-modified-p t)
4019 (let ((actions message-postpone-actions))
4020 (message-bury (current-buffer))
4021 (message-do-actions actions)))
4023 (defun message-kill-buffer ()
4024 "Kill the current buffer."
4026 (when (or (not (buffer-modified-p))
4027 (not message-kill-buffer-query)
4028 (yes-or-no-p "Message modified; kill anyway? "))
4029 (let ((actions message-kill-actions)
4030 (draft-article message-draft-article)
4031 (auto-save-file-name buffer-auto-save-file-name)
4032 (file-name buffer-file-name)
4033 (modified (buffer-modified-p)))
4034 (setq buffer-file-name nil)
4035 (kill-buffer (current-buffer))
4036 (when (and (or (and auto-save-file-name
4037 (file-exists-p auto-save-file-name))
4039 (file-exists-p file-name)))
4041 ;; If the message buffer has lived in a dedicated window,
4042 ;; `kill-buffer' has killed the frame. Thus the
4043 ;; `yes-or-no-p' may show up in a lowered frame. Make sure
4044 ;; that the user can see the question by raising the
4047 (yes-or-no-p (format "Remove the backup file%s? "
4048 (if modified " too" "")))))
4050 (delete-file auto-save-file-name))
4051 (let ((message-draft-article draft-article))
4052 (message-disassociate-draft)))
4053 (message-do-actions actions))))
4055 (defun message-bury (buffer)
4056 "Bury this mail BUFFER."
4057 (let ((newbuf (other-buffer buffer)))
4058 (bury-buffer buffer)
4059 (if message-return-action
4060 (apply (car message-return-action) (cdr message-return-action))
4061 (switch-to-buffer newbuf))))
4063 (defun message-send (&optional arg)
4064 "Send the message in the current buffer.
4065 If `message-interactive' is non-nil, wait for success indication or
4066 error messages, and inform user.
4067 Otherwise any failure is reported in a message back to the user from
4069 The usage of ARG is defined by the instance that called Message.
4070 It should typically alter the sending method in some way or other."
4072 ;; Make it possible to undo the coming changes.
4074 (let ((inhibit-read-only t))
4075 (put-text-property (point-min) (point-max) 'read-only nil))
4076 (message-fix-before-sending)
4077 (run-hooks 'message-send-hook)
4078 (when message-confirm-send
4079 (or (y-or-n-p "Send message? ")
4081 (message message-sending-message)
4082 (let ((alist message-send-method-alist)
4084 elem sent dont-barf-on-no-method
4085 (message-options message-options))
4086 (message-options-set-recipient)
4088 (setq elem (pop alist)))
4089 (when (funcall (cadr elem))
4090 (when (and (or (not (memq (car elem)
4091 message-sent-message-via))
4092 (message-fetch-field "supersedes")
4093 (if (or (message-gnksa-enable-p 'multiple-copies)
4094 (not (eq (car elem) 'news)))
4097 "Already sent message via %s; resend? "
4099 (error "Denied posting -- multiple copies")))
4100 (setq success (funcall (caddr elem) arg)))
4104 (let ((fcc (message-fetch-field "Fcc"))
4105 (gcc (message-fetch-field "Gcc")))
4107 (or (eq message-allow-no-recipients 'always)
4108 (and (not (eq message-allow-no-recipients 'never))
4109 (setq dont-barf-on-no-method
4111 (format "No receiver, perform %s anyway? "
4112 (cond ((and fcc gcc) "Fcc and Gcc")
4115 (error "No methods specified to send by"))
4116 (when (or dont-barf-on-no-method
4120 (run-hooks 'message-sent-hook))
4121 (message "Sending...done")
4122 ;; Do ecomplete address snarfing.
4123 (when (and (message-mail-alias-type-p 'ecomplete)
4124 (not message-inhibit-ecomplete))
4125 (message-put-addresses-in-ecomplete))
4126 ;; Mark the buffer as unmodified and delete auto-save.
4127 (set-buffer-modified-p nil)
4128 (delete-auto-save-file-if-necessary t)
4129 (message-disassociate-draft)
4130 ;; Delete other mail buffers and stuff.
4131 (message-do-send-housekeeping)
4132 (message-do-actions message-send-actions)
4136 (defun message-send-via-mail (arg)
4137 "Send the current message via mail."
4138 (message-send-mail arg))
4140 (defun message-send-via-news (arg)
4141 "Send the current message via news."
4142 (funcall message-send-news-function arg))
4144 (defmacro message-check (type &rest forms)
4145 "Eval FORMS if TYPE is to be checked."
4146 `(or (message-check-element ,type)
4150 (put 'message-check 'lisp-indent-function 1)
4151 (put 'message-check 'edebug-form-spec '(form body))
4153 (defun message-text-with-property (prop &optional start end reverse)
4154 "Return a list of start and end positions where the text has PROP.
4155 START and END bound the search, they default to `point-min' and
4156 `point-max' respectively. If REVERSE is non-nil, find text which does
4159 (setq start (point-min)))
4161 (setq end (point-max)))
4165 (setq start (text-property-any start end prop nil)))
4166 (setq next (next-single-property-change start prop nil end))
4167 (push (cons start (or next end)) regions)
4170 (or (get-text-property start prop)
4171 (and (setq start (next-single-property-change
4172 start prop nil end))
4173 (get-text-property start prop))))
4174 (setq next (text-property-any start end prop nil))
4175 (push (cons start (or next end)) regions)
4177 (nreverse regions)))
4179 (defcustom message-bogus-addresses
4180 '("noreply" "nospam" "invalid" "@@" "[^[:ascii:]].*@" "[ \t]")
4181 "List of regexps of potentially bogus mail addresses.
4182 See `message-check-recipients' how to setup checking.
4184 This list should make it possible to catch typos or warn about
4185 spam-trap addresses. It doesn't aim to verify strict RFC
4187 :version "23.1" ;; No Gnus
4188 :group 'message-headers
4190 (const :tag "None" nil)
4196 (const :tag "duplicate @" "@@")
4197 (const :tag "non-ascii local part" "[^[:ascii:]].*@")
4198 ;; Already caught by `message-valid-fqdn-regexp'
4199 ;; (const :tag "`_' in domain part" "@.*_")
4200 (const :tag "whitespace" "[ \t]"))
4205 (defun message-fix-before-sending ()
4206 "Do various things to make the message nice before sending it."
4207 ;; Make sure there's a newline at the end of the message.
4208 (goto-char (point-max))
4211 ;; Make the hidden headers visible.
4213 ;; Sort headers before sending the message.
4214 (message-sort-headers)
4215 ;; Make invisible text visible.
4216 ;; It doesn't seem as if this is useful, since the invisible property
4217 ;; is clobbered by an after-change hook anyhow.
4218 (message-check 'invisible-text
4219 (let ((regions (message-text-with-property 'invisible))
4223 (setq from (caar regions)
4225 regions (cdr regions))
4226 (put-text-property from to 'invisible nil)
4227 (message-overlay-put (message-make-overlay from to)
4229 (unless (yes-or-no-p
4230 "Invisible text found and made visible; continue sending? ")
4231 (error "Invisible text found and made visible")))))
4232 (message-check 'illegible-text
4233 (let (char found choice)
4236 (skip-chars-forward mm-7bit-chars)
4237 (when (get-text-property (point) 'no-illegible-text)
4238 ;; There is a signed or encrypted raw message part
4239 ;; that is considered to be safe.
4240 (goto-char (or (next-single-property-change
4241 (point) 'no-illegible-text)
4243 (setq char (char-after)))
4244 (when (or (< (mm-char-int char) 128)
4245 (and (mm-multibyte-p)
4246 (memq (char-charset char)
4247 '(eight-bit-control eight-bit-graphic
4248 ;; Emacs 23, Bug#1770:
4251 (not (get-text-property
4252 (point) 'untranslated-utf-8))))
4253 (message-overlay-put (message-make-overlay (point) (1+ (point)))
4259 (gnus-multiple-choice
4260 "Non-printable characters found. Continue sending?"
4261 `((?d "Remove non-printable characters and send")
4263 "Replace non-printable characters with \"%s\" and send"
4264 message-replacement-char))
4265 (?s "Send as is without removing anything")
4266 (?e "Continue editing"))))
4268 (error "Non-printable characters"))
4270 (skip-chars-forward mm-7bit-chars)
4272 (when (let ((char (char-after)))
4273 (or (< (mm-char-int char) 128)
4274 (and (mm-multibyte-p)
4275 ;; FIXME: Wrong for Emacs 23 (unicode) and for
4276 ;; things like undecodable utf-8 (in Emacs 21?).
4277 ;; Should at least use find-coding-systems-region.
4279 (memq (char-charset char)
4280 '(eight-bit-control eight-bit-graphic
4281 ;; Emacs 23, Bug#1770:
4284 (not (get-text-property
4285 (point) 'untranslated-utf-8)))))
4287 (message-kill-all-overlays)
4289 (when (eq choice ?r)
4290 (insert message-replacement-char))))
4292 (skip-chars-forward mm-7bit-chars)))))
4293 (message-check 'bogus-recipient
4294 ;; Warn before sending a mail to an invalid address.
4295 (message-check-recipients)))
4297 (defun message-bogus-recipient-p (recipients)
4298 "Check if a mail address in RECIPIENTS looks bogus.
4300 RECIPIENTS is a mail header. Return a list of potentially bogus
4301 addresses. If none is found, return nil.
4303 An address might be bogus if the domain part is not fully
4304 qualified, see `message-valid-fqdn-regexp', or if there's a
4305 matching entry in `message-bogus-addresses'."
4306 ;; FIXME: How about "foo@subdomain", when the MTA adds ".domain.tld"?
4308 (mapc (lambda (address)
4309 (setq address (or (cadr address) ""))
4311 (or (string= "" address)
4314 (not (string-match "@" address))
4317 message-valid-fqdn-regexp "\\)\\'") address)))
4318 (and message-bogus-addresses
4320 (if (listp message-bogus-addresses)
4321 (mapconcat 'identity
4322 message-bogus-addresses
4324 message-bogus-addresses)))
4325 (string-match re address))))
4326 (push address found)))
4328 (mail-extract-address-components recipients t))
4331 (defun message-check-recipients ()
4332 "Warn before composing or sending a mail to an invalid address.
4334 This function could be useful in `message-setup-hook'."
4337 (message-narrow-to-headers)
4338 (dolist (hdr '("To" "Cc" "Bcc"))
4339 (let ((addr (message-fetch-field hdr)))
4340 (when (stringp addr)
4341 (dolist (bog (message-bogus-recipient-p addr))
4345 "Address `%s'%s might be bogus. Continue? "
4347 ;; If the encoded version of the email address
4348 ;; is different from the unencoded version,
4349 ;; then we likely have invisible characters or
4350 ;; the like. Display the encoded version,
4352 (let ((encoded (rfc2047-encode-string bog)))
4353 (if (string= encoded bog)
4355 (format " (%s)" encoded))))))
4356 (error "Bogus address"))))))))
4358 (custom-add-option 'message-setup-hook 'message-check-recipients)
4360 (defun message-add-action (action &rest types)
4361 "Add ACTION to be performed when doing an exit of type TYPES."
4363 (add-to-list (intern (format "message-%s-actions" (pop types)))
4366 (defun message-delete-action (action &rest types)
4367 "Delete ACTION from lists of actions performed when doing an exit of type TYPES."
4370 (set (setq var (intern (format "message-%s-actions" (pop types))))
4371 (delq action (symbol-value var))))))
4373 (defun message-do-actions (actions)
4374 "Perform all actions in ACTIONS."
4375 ;; Now perform actions on successful sending.
4376 (dolist (action actions)
4379 ;; A simple function.
4382 ;; Something to be evaled.
4386 (defun message-send-mail-partially ()
4387 "Send mail as message/partial."
4388 ;; replace the header delimiter with a blank line
4389 (goto-char (point-min))
4391 (concat "^" (regexp-quote mail-header-separator) "\n"))
4392 (replace-match "\n")
4393 (run-hooks 'message-send-mail-hook)
4394 (let ((p (goto-char (point-min)))
4395 (tembuf (message-generate-new-buffer-clone-locals " message temp"))
4396 (curbuf (current-buffer))
4397 (id (message-make-message-id)) (n 1)
4400 (if (< (point-max) (+ p message-send-mail-partially-limit))
4401 (goto-char (point-max))
4402 (goto-char (+ p message-send-mail-partially-limit))
4404 (if (<= (point) p) (forward-line 1))) ;; In case of bad message.
4407 (setq total (length plist))
4408 (push (point-max) plist)
4409 (setq plist (nreverse plist))
4412 (setq p (pop plist))
4415 (copy-to-buffer tembuf p (car plist))
4417 (goto-char (point-min))
4420 (goto-char (point-min))
4421 (narrow-to-region (point) (point))
4424 (setq header (buffer-substring (point-min) (point)))
4425 (goto-char (point-min))
4426 (narrow-to-region (point) (point))
4428 (message-remove-header "Mime-Version")
4429 (message-remove-header "Content-Type")
4430 (message-remove-header "Content-Transfer-Encoding")
4431 (message-remove-header "Message-ID")
4432 (message-remove-header "Lines")
4433 (goto-char (point-max))
4434 (insert "Mime-Version: 1.0\n")
4435 (setq header (buffer-string)))
4436 (goto-char (point-max))
4437 (insert (format "Content-Type: message/partial; id=\"%s\"; number=%d; total=%d\n\n"
4440 (let ((mail-header-separator ""))
4441 (when (memq 'Message-ID message-required-mail-headers)
4442 (insert "Message-ID: " (message-make-message-id) "\n"))
4443 (when (memq 'Lines message-required-mail-headers)
4444 (insert "Lines: " (message-make-lines) "\n"))
4445 (message-goto-subject)
4447 (insert (format " (%d/%d)" n total))
4449 (funcall (or message-send-mail-real-function
4450 message-send-mail-function)))
4452 (setq p (pop plist))
4454 (kill-buffer tembuf))))
4456 (declare-function hashcash-wait-async "hashcash" (&optional buffer))
4458 (defun message-send-mail (&optional arg)
4459 (require 'mail-utils)
4460 (let* ((tembuf (message-generate-new-buffer-clone-locals " message temp"))
4461 (case-fold-search nil)
4462 (news (message-news-p))
4463 (mailbuf (current-buffer))
4464 (message-this-is-mail t)
4465 ;; gnus-setup-posting-charset is autoloaded in mml.el (FIXME
4466 ;; maybe it should not be), which this file requires. Hence
4467 ;; the fboundp test is always true. Loading it from gnus-msg
4468 ;; loads many Gnus files (Bug#5642). If
4469 ;; gnus-group-posting-charset-alist hasn't been customized,
4470 ;; this is just going to return nil anyway. FIXME it would
4471 ;; be good to improve this further, because even if g-g-p-c-a
4472 ;; has been customized, that is likely to just be for news.
4473 ;; Eg either move the definition from gnus-msg, or separate out
4474 ;; the mail and news parts.
4475 (message-posting-charset
4476 (if (and (fboundp 'gnus-setup-posting-charset)
4477 (boundp 'gnus-group-posting-charset-alist))
4478 (gnus-setup-posting-charset nil)
4479 message-posting-charset))
4480 (headers message-required-mail-headers))
4481 (when (and message-generate-hashcash
4482 (not (eq message-generate-hashcash 'opportunistic)))
4483 (message "Generating hashcash...")
4485 ;; Wait for calculations already started to finish...
4486 (hashcash-wait-async)
4487 ;; ...and do calculations not already done. mail-add-payment
4488 ;; will leave existing X-Hashcash headers alone.
4490 (message "Generating hashcash...done"))
4492 (message-narrow-to-headers)
4493 ;; Generate the Mail-Followup-To header if the header is not there...
4494 (if (and (message-subscribed-p)
4495 (not (mail-fetch-field "mail-followup-to")))
4498 (cons "Mail-Followup-To" (message-make-mail-followup-to))
4499 message-required-mail-headers))
4500 ;; otherwise, delete the MFT header if the field is empty
4501 (when (equal "" (mail-fetch-field "mail-followup-to"))
4502 (message-remove-header "^Mail-Followup-To:")))
4503 ;; Insert some headers.
4504 (let ((message-deletable-headers
4505 (if news nil message-deletable-headers)))
4506 (message-generate-headers headers))
4507 ;; Check continuation headers.
4508 (message-check 'continuation-headers
4509 (goto-char (point-min))
4510 (while (re-search-forward "^[^ \t\n][^ \t\n:]*[ \t\n]" nil t)
4511 (goto-char (match-beginning 0))
4512 (if (y-or-n-p "Fix continuation lines? ")
4515 (unless (y-or-n-p "Send anyway? ")
4516 (error "Failed to send the message")))))
4517 ;; Let the user do all of the above.
4518 (run-hooks 'message-header-hook))
4520 (with-current-buffer tembuf
4522 ;; Avoid copying text props (except hard newlines).
4523 (insert (with-current-buffer mailbuf
4524 (mml-buffer-substring-no-properties-except-hard-newlines
4525 (point-min) (point-max))))
4526 ;; Remove some headers.
4527 (message-encode-message-body)
4529 (message-narrow-to-headers)
4530 ;; We (re)generate the Lines header.
4531 (when (memq 'Lines message-required-mail-headers)
4532 (message-generate-headers '(Lines)))
4533 ;; Remove some headers.
4534 (message-remove-header message-ignored-mail-headers t)
4535 (let ((mail-parse-charset message-default-charset))
4536 (mail-encode-encoded-word-buffer)))
4537 (goto-char (point-max))
4538 ;; require one newline at the end.
4539 (or (= (preceding-char) ?\n)
4541 (message-cleanup-headers)
4542 ;; FIXME: we're inserting the courtesy copy after encoding.
4543 ;; This is wrong if the courtesy copy string contains
4544 ;; non-ASCII characters. -- jh
4547 (message-narrow-to-headers)
4549 (not (message-fetch-field "List-Post"))
4550 (not (message-fetch-field "List-ID"))
4551 (or (message-fetch-field "cc")
4552 (message-fetch-field "bcc")
4553 (message-fetch-field "to"))
4554 (let ((content-type (message-fetch-field
4559 (string= "text/plain"
4561 (mail-header-parse-content-type
4565 (message-fetch-field
4566 "content-transfer-encoding")))))))
4567 (message-insert-courtesy-copy
4568 (with-current-buffer mailbuf
4569 message-courtesy-message)))
4570 ;; Let's make sure we encoded all the body.
4571 (assert (save-excursion
4572 (goto-char (point-min))
4573 (not (re-search-forward "[^\000-\377]" nil t))))
4574 (mm-disable-multibyte)
4575 (if (or (not message-send-mail-partially-limit)
4576 (< (buffer-size) message-send-mail-partially-limit)
4577 (not (message-y-or-n-p
4578 "The message size is too large, split? "
4582 (/ (buffer-size) 1000) "KB, is too large.
4584 Some mail gateways (MTA's) bounce large messages. To avoid the
4585 problem, answer `y', and the message will be split into several
4586 smaller pieces, the size of each is about "
4587 (/ message-send-mail-partially-limit 1000)
4591 However, some mail readers (MUA's) can't read split messages, i.e.,
4592 mails in message/partially format. Answer `n', and the message will be
4595 The size limit is controlled by `message-send-mail-partially-limit'.
4596 If you always want Gnus to send messages in one piece, set
4597 `message-send-mail-partially-limit' to nil.
4600 (message "Sending via mail...")
4601 (funcall (or message-send-mail-real-function
4602 message-send-mail-function)))
4603 (message-send-mail-partially)))
4604 (kill-buffer tembuf))
4605 (set-buffer mailbuf)
4606 (push 'mail message-sent-message-via)))
4608 (defun message-send-mail-with-sendmail ()
4609 "Send off the prepared buffer with sendmail."
4611 (let ((errbuf (if message-interactive
4612 (message-generate-new-buffer-clone-locals
4615 resend-to-addresses delimline)
4618 (let ((case-fold-search t))
4620 (message-narrow-to-headers)
4621 (setq resend-to-addresses (message-fetch-field "resent-to")))
4622 ;; Change header-delimiter to be what sendmail expects.
4623 (goto-char (point-min))
4625 (concat "^" (regexp-quote mail-header-separator) "\n"))
4626 (replace-match "\n")
4628 (setq delimline (point-marker))
4629 (run-hooks 'message-send-mail-hook)
4630 ;; Insert an extra newline if we need it to work around
4631 ;; Sun's bug that swallows newlines.
4632 (goto-char (1+ delimline))
4633 (when (eval message-mailer-swallows-blank-line)
4635 (when message-interactive
4636 (with-current-buffer errbuf
4638 (let* ((default-directory "/")
4639 (coding-system-for-write message-send-coding-system)
4641 'call-process-region
4643 (list (point-min) (point-max)
4644 (cond ((boundp 'sendmail-program)
4646 ((file-exists-p "/usr/sbin/sendmail")
4647 "/usr/sbin/sendmail")
4648 ((file-exists-p "/usr/lib/sendmail")
4649 "/usr/lib/sendmail")
4650 ((file-exists-p "/usr/ucblib/sendmail")
4651 "/usr/ucblib/sendmail")
4653 nil errbuf nil "-oi")
4654 message-sendmail-extra-arguments
4655 ;; Always specify who from,
4656 ;; since some systems have broken sendmails.
4657 ;; But some systems are more broken with -f, so
4658 ;; we'll let users override this.
4659 (and (null message-sendmail-f-is-evil)
4660 (list "-f" (message-sendmail-envelope-from)))
4661 ;; These mean "report errors by mail"
4662 ;; and "deliver in background".
4663 (if (null message-interactive) '("-oem" "-odb"))
4664 ;; Get the addresses from the message
4665 ;; unless this is a resend.
4666 ;; We must not do that for a resend
4667 ;; because we would find the original addresses.
4668 ;; For a resend, include the specific addresses.
4669 (if resend-to-addresses
4670 (list resend-to-addresses)
4672 (unless (or (null cpr) (and (numberp cpr) (zerop cpr)))
4673 (if errbuf (pop-to-buffer errbuf))
4674 (error "Sending...failed with exit value %d" cpr)))
4675 (when message-interactive
4676 (with-current-buffer errbuf
4677 (goto-char (point-min))
4678 (while (re-search-forward "\n+ *" nil t)
4679 (replace-match "; "))
4680 (if (not (zerop (buffer-size)))
4681 (error "Sending...failed to %s"
4682 (buffer-string))))))
4683 (when (bufferp errbuf)
4684 (kill-buffer errbuf)))))
4686 (defun message-send-mail-with-qmail ()
4687 "Pass the prepared message buffer to qmail-inject.
4688 Refer to the documentation for the variable `message-send-mail-function'
4689 to find out how to use this."
4690 ;; replace the header delimiter with a blank line
4691 (goto-char (point-min))
4693 (concat "^" (regexp-quote mail-header-separator) "\n"))
4694 (replace-match "\n")
4695 (run-hooks 'message-send-mail-hook)
4698 (let ((coding-system-for-write message-send-coding-system))
4700 'call-process-region (point-min) (point-max)
4701 message-qmail-inject-program nil nil nil
4702 ;; qmail-inject's default behavior is to look for addresses on the
4703 ;; command line; if there're none, it scans the headers.
4704 ;; yes, it does The Right Thing w.r.t. Resent-To and it's kin.
4706 ;; in general, ALL of qmail-inject's defaults are perfect for simply
4707 ;; reading a formatted (i. e., at least a To: or Resent-To header)
4708 ;; message from stdin.
4710 ;; qmail also has the advantage of not having been raped by
4711 ;; various vendors, so we don't have to allow for that, either --
4712 ;; compare this with message-send-mail-with-sendmail and weep
4713 ;; for sendmail's lost innocence.
4715 ;; all this is way cool coz it lets us keep the arguments entirely
4716 ;; free for -inject-arguments -- a big win for the user and for us
4717 ;; since we don't have to play that double-guessing game and the user
4718 ;; gets full control (no gestapo'ish -f's, for instance). --sj
4719 (if (functionp message-qmail-inject-args)
4720 (funcall message-qmail-inject-args)
4721 message-qmail-inject-args)))
4722 ;; qmail-inject doesn't say anything on it's stdout/stderr,
4723 ;; we have to look at the retval instead
4725 (100 (error "qmail-inject reported permanent failure"))
4726 (111 (error "qmail-inject reported transient failure"))
4727 ;; should never happen
4728 (t (error "qmail-inject reported unknown failure"))))
4730 (defvar mh-previous-window-config)
4732 (defun message-send-mail-with-mh ()
4733 "Send the prepared message buffer with mh."
4734 (let ((mh-previous-window-config nil)
4735 (name (mh-new-draft-name)))
4736 (setq buffer-file-name name)
4737 ;; MH wants to generate these headers itself.
4738 (when message-mh-deletable-headers
4739 (let ((headers message-mh-deletable-headers))
4741 (goto-char (point-min))
4742 (and (re-search-forward
4743 (concat "^" (symbol-name (car headers)) ": *") nil t)
4744 (message-delete-line))
4746 (run-hooks 'message-send-mail-hook)
4747 ;; Pass it on to mh.
4750 (defun message-smtpmail-send-it ()
4751 "Send the prepared message buffer with `smtpmail-send-it'.
4752 The only difference from `smtpmail-send-it' is that this command
4753 evaluates `message-send-mail-hook' just before sending a message.
4754 It is useful if your ISP requires the POP-before-SMTP
4755 authentication. See the Gnus manual for details."
4756 (run-hooks 'message-send-mail-hook)
4759 (defun message-send-mail-with-mailclient ()
4760 "Send the prepared message buffer with `mailclient-send-it'.
4761 The only difference from `mailclient-send-it' is that this
4762 command evaluates `message-send-mail-hook' just before sending a message."
4763 (run-hooks 'message-send-mail-hook)
4764 (mailclient-send-it))
4766 (defun message-canlock-generate ()
4767 "Return a string that is non-trivial to guess.
4768 Do not use this for anything important, it is cryptographically weak."
4770 (let (sha1-maximum-internal-length)
4771 (sha1 (concat (message-unique-id)
4772 (format "%x%x%x" (random) (random t) (random))
4773 (prin1-to-string (recent-keys))
4774 (prin1-to-string (garbage-collect))))))
4776 (defvar canlock-password)
4777 (defvar canlock-password-for-verify)
4779 (defun message-canlock-password ()
4780 "The password used by message for cancel locks.
4781 This is the value of `canlock-password', if that option is non-nil.
4782 Otherwise, generate and save a value for `canlock-password' first."
4784 (unless canlock-password
4785 (customize-save-variable 'canlock-password (message-canlock-generate))
4786 (setq canlock-password-for-verify canlock-password))
4789 (defun message-insert-canlock ()
4790 (when message-insert-canlock
4791 (message-canlock-password)
4792 (canlock-insert-header)))
4794 (autoload 'nnheader-get-report "nnheader")
4796 (declare-function gnus-setup-posting-charset "gnus-msg" (group))
4798 (defun message-send-news (&optional arg)
4800 (let* ((tembuf (message-generate-new-buffer-clone-locals " *message temp*"))
4801 (case-fold-search nil)
4802 (method (if (functionp message-post-method)
4803 (funcall message-post-method arg)
4804 message-post-method))
4805 (newsgroups-field (save-restriction
4806 (message-narrow-to-headers-or-head)
4807 (message-fetch-field "Newsgroups")))
4808 (followup-field (save-restriction
4809 (message-narrow-to-headers-or-head)
4810 (message-fetch-field "Followup-To")))
4811 ;; BUG: We really need to get the charset for each name in the
4812 ;; Newsgroups and Followup-To lines to allow crossposting
4813 ;; between group namess with incompatible character sets.
4814 ;; -- Per Abrahamsen <abraham@dina.kvl.dk> 2001-10-08.
4815 (group-field-charset
4816 (gnus-group-name-charset method newsgroups-field))
4817 (followup-field-charset
4818 (gnus-group-name-charset method (or followup-field "")))
4819 (rfc2047-header-encoding-alist
4820 (append (when group-field-charset
4821 (list (cons "Newsgroups" group-field-charset)))
4822 (when followup-field-charset
4823 (list (cons "Followup-To" followup-field-charset)))
4824 rfc2047-header-encoding-alist))
4825 (messbuf (current-buffer))
4826 (message-syntax-checks
4828 (listp message-syntax-checks))
4829 (cons '(existing-newsgroups . disabled)
4830 message-syntax-checks)
4831 message-syntax-checks))
4832 (message-this-is-news t)
4833 (message-posting-charset
4834 (gnus-setup-posting-charset newsgroups-field))
4836 (if (not (message-check-news-body-syntax))
4839 (message-narrow-to-headers)
4840 ;; Insert some headers.
4841 (message-generate-headers message-required-news-headers)
4842 (message-insert-canlock)
4843 ;; Let the user do all of the above.
4844 (run-hooks 'message-header-hook))
4845 ;; Note: This check will be disabled by the ".*" default value for
4846 ;; gnus-group-name-charset-group-alist. -- Pa 2001-10-07.
4847 (when (and group-field-charset
4848 (listp message-syntax-checks))
4849 (setq message-syntax-checks
4850 (cons '(valid-newsgroups . disabled)
4851 message-syntax-checks)))
4852 (message-cleanup-headers)
4853 (if (not (let ((message-post-method method))
4854 (message-check-news-syntax)))
4857 (with-current-buffer tembuf
4858 (buffer-disable-undo)
4860 ;; Avoid copying text props (except hard newlines).
4862 (with-current-buffer messbuf
4863 (mml-buffer-substring-no-properties-except-hard-newlines
4864 (point-min) (point-max))))
4865 (message-encode-message-body)
4866 ;; Remove some headers.
4868 (message-narrow-to-headers)
4869 ;; We (re)generate the Lines header.
4870 (when (memq 'Lines message-required-mail-headers)
4871 (message-generate-headers '(Lines)))
4872 ;; Remove some headers.
4873 (message-remove-header message-ignored-news-headers t)
4874 (let ((mail-parse-charset message-default-charset))
4875 (mail-encode-encoded-word-buffer)))
4876 (goto-char (point-max))
4877 ;; require one newline at the end.
4878 (or (= (preceding-char) ?\n)
4880 (let ((case-fold-search t))
4881 ;; Remove the delimiter.
4882 (goto-char (point-min))
4884 (concat "^" (regexp-quote mail-header-separator) "\n"))
4885 (replace-match "\n")
4887 (run-hooks 'message-send-news-hook)
4888 (gnus-open-server method)
4889 (message "Sending news via %s..." (gnus-server-string method))
4890 (setq result (let ((mail-header-separator ""))
4891 (gnus-request-post method))))
4892 (kill-buffer tembuf))
4893 (set-buffer messbuf)
4895 (push 'news message-sent-message-via)
4896 (message "Couldn't send message via news: %s"
4897 (nnheader-get-report (car method)))
4901 ;;; Header generation & syntax checking.
4904 (defun message-check-element (type)
4905 "Return non-nil if this TYPE is not to be checked."
4906 (if (eq message-syntax-checks 'dont-check-for-anything-just-trust-me)
4908 (let ((able (assq type message-syntax-checks)))
4910 (eq (cdr able) 'disabled)))))
4912 (defun message-check-news-syntax ()
4913 "Check the syntax of the message."
4917 ;; We narrow to the headers and check them first.
4920 (message-narrow-to-headers)
4921 (message-check-news-header-syntax))))))
4923 (defun message-check-news-header-syntax ()
4925 ;; Check Newsgroups header.
4926 (message-check 'newsgroups
4927 (let ((group (message-fetch-field "newsgroups")))
4930 (not (string-match "\\`[ \t]*\\'" group)))
4933 "The newsgroups field is empty or missing. Posting is denied.")))))
4934 ;; Check the Subject header.
4935 (message-check 'subject
4936 (let* ((case-fold-search t)
4937 (subject (message-fetch-field "subject")))
4940 (not (string-match "\\`[ \t]*\\'" subject)))
4943 "The subject field is empty or missing. Posting is denied.")))))
4944 ;; Check for commands in Subject.
4945 (message-check 'subject-cmsg
4946 (if (string-match "^cmsg " (message-fetch-field "subject"))
4948 "The control code \"cmsg\" is in the subject. Really post? ")
4950 ;; Check long header lines.
4951 (message-check 'long-header-lines
4955 (while (and (not found)
4956 (re-search-forward "^\\([^ \t:]+\\): " nil t))
4957 (if (> (- (point) (match-beginning 0)) 998)
4959 length (- (point) (match-beginning 0)))
4960 (setq header (match-string-no-properties 1)))
4963 (y-or-n-p (format "Your %s header is too long (%d). Really post? "
4966 ;; Check for multiple identical headers.
4967 (message-check 'multiple-headers
4969 (while (and (not found)
4970 (re-search-forward "^[^ \t:]+: " nil t))
4972 (or (re-search-forward
4977 (match-beginning 0) (- (match-end 0) 2))))
4982 (y-or-n-p (format "Multiple %s headers. Really post? " found))
4984 ;; Check for Version and Sendsys.
4985 (message-check 'sendsys
4986 (if (re-search-forward "^Sendsys:\\|^Version:" nil t)
4988 (format "The article contains a %s command. Really post? "
4989 (buffer-substring (match-beginning 0)
4990 (1- (match-end 0)))))
4992 ;; See whether we can shorten Followup-To.
4993 (message-check 'shorten-followup-to
4994 (let ((newsgroups (message-fetch-field "newsgroups"))
4995 (followup-to (message-fetch-field "followup-to"))
4997 (when (and newsgroups
4998 (string-match "," newsgroups)
5003 (setq to (completing-read
5004 "Followups to (default no Followup-To header): "
5007 (message-tokenize-header
5009 (goto-char (point-min))
5010 (insert "Followup-To: " to "\n"))
5012 ;; Check "Shoot me".
5013 (message-check 'shoot
5014 (if (re-search-forward
5015 "Message-ID.*.i-did-not-set--mail-host-address--so-tickle-me" nil t)
5016 (y-or-n-p "You appear to have a misconfigured system. Really post? ")
5018 ;; Check for Approved.
5019 (message-check 'approved
5020 (if (re-search-forward "^Approved:" nil t)
5021 (y-or-n-p "The article contains an Approved header. Really post? ")
5023 ;; Check the Message-ID header.
5024 (message-check 'message-id
5025 (let* ((case-fold-search t)
5026 (message-id (message-fetch-field "message-id" t)))
5027 (or (not message-id)
5028 ;; Is there an @ in the ID?
5029 (and (string-match "@" message-id)
5030 ;; Is there a dot in the ID?
5031 (string-match "@[^.]*\\." message-id)
5032 ;; Does the ID end with a dot?
5033 (not (string-match "\\.>" message-id)))
5035 (format "The Message-ID looks strange: \"%s\". Really post? "
5037 ;; Check the Newsgroups & Followup-To headers.
5038 (message-check 'existing-newsgroups
5039 (let* ((case-fold-search t)
5040 (newsgroups (message-fetch-field "newsgroups"))
5041 (followup-to (message-fetch-field "followup-to"))
5042 (groups (message-tokenize-header
5044 (concat newsgroups "," followup-to)
5046 (post-method (if (functionp message-post-method)
5047 (funcall message-post-method)
5048 message-post-method))
5049 ;; KLUDGE to handle nnvirtual groups. Doing this right
5050 ;; would probably involve a new nnoo function.
5051 ;; -- Per Abrahamsen <abraham@dina.kvl.dk>, 2001-10-17.
5052 (method (if (and (consp post-method)
5053 (eq (car post-method) 'nnvirtual)
5054 gnus-message-group-art)
5055 (let ((group (car (nnvirtual-find-group-art
5056 (car gnus-message-group-art)
5057 (cdr gnus-message-group-art)))))
5058 (gnus-find-method-for-group group))
5062 (gnus-group-name-decode
5063 (gnus-group-real-name n)
5064 (gnus-group-name-charset method n)))
5065 (gnus-groups-from-server method)))
5068 (when (and (not (equal (car groups) "poster"))
5069 (not (member (car groups) known-groups))
5070 (not (member (car groups) errors)))
5071 (push (car groups) errors))
5074 ;; Gnus is not running.
5075 ((or (not (and (boundp 'gnus-active-hashtb)
5076 gnus-active-hashtb))
5077 (not (boundp 'gnus-read-active-file)))
5079 ;; We don't have all the group names.
5080 ((and (or (not gnus-read-active-file)
5081 (eq gnus-read-active-file 'some))
5085 "Really use %s possibly unknown group%s: %s? "
5086 (if (= (length errors) 1) "this" "these")
5087 (if (= (length errors) 1) "" "s")
5088 (mapconcat 'identity errors ", "))))
5089 ;; There were no errors.
5092 ;; There are unknown groups.
5096 "Really post to %s unknown group%s: %s? "
5097 (if (= (length errors) 1) "this" "these")
5098 (if (= (length errors) 1) "" "s")
5099 (mapconcat 'identity errors ", ")))))))
5100 ;; Check continuation headers.
5101 (message-check 'continuation-headers
5102 (goto-char (point-min))
5103 (let ((do-posting t))
5104 (while (re-search-forward "^[^ \t\n][^ \t\n:]*[ \t\n]" nil t)
5105 (goto-char (match-beginning 0))
5106 (if (y-or-n-p "Fix continuation lines? ")
5109 (unless (y-or-n-p "Send anyway? ")
5110 (setq do-posting nil))))
5112 ;; Check the Newsgroups & Followup-To headers for syntax errors.
5113 (message-check 'valid-newsgroups
5114 (let ((case-fold-search t)
5115 (headers '("Newsgroups" "Followup-To"))
5117 (while (and headers (not error))
5118 (when (setq header (mail-fetch-field (car headers)))
5122 "\\`\\([-+_&.a-zA-Z0-9]+\\)?\\(,[-+_&.a-zA-Z0-9]+\\)*\\'"
5127 (not (string-match "\\.\\'\\|\\.\\." g)))
5128 (message-tokenize-header header ","))))
5135 (format "The %s header looks odd: \"%s\". Really post? "
5136 (car headers) header)))))
5137 (message-check 'repeated-newsgroups
5138 (let ((case-fold-search t)
5139 (headers '("Newsgroups" "Followup-To"))
5140 header error groups group)
5143 (when (setq header (mail-fetch-field (pop headers)))
5144 (setq groups (message-tokenize-header header ","))
5145 (while (setq group (pop groups))
5146 (when (member group groups)
5152 (format "Group %s is repeated in headers. Really post? " error)))))
5153 ;; Check the From header.
5154 (message-check 'from
5155 (let* ((case-fold-search t)
5156 (from (message-fetch-field "from"))
5160 (message "There is no From line. Posting is denied.")
5162 ((or (not (string-match
5164 (setq ad (nth 1 (mail-extract-address-components
5165 from))))) ;larsi@ifi
5166 (string-match "\\.\\." ad) ;larsi@ifi..uio
5167 (string-match "@\\." ad) ;larsi@.ifi.uio
5168 (string-match "\\.$" ad) ;larsi@ifi.uio.
5169 (not (string-match "^[^@]+@[^@]+$" ad)) ;larsi.ifi.uio
5170 (string-match "(.*).*(.*)" from)) ;(lars) (lars)
5172 "Denied posting -- the From looks strange: \"%s\"." from)
5174 ((let ((addresses (rfc822-addresses from)))
5175 ;; `rfc822-addresses' returns a string if parsing fails.
5176 (while (and (consp addresses)
5177 (not (eq (string-to-char (car addresses)) ?\()))
5178 (setq addresses (cdr addresses)))
5181 "Denied posting -- bad From address: \"%s\"." from)
5184 ;; Check the Reply-To header.
5185 (message-check 'reply-to
5186 (let* ((case-fold-search t)
5187 (reply-to (message-fetch-field "reply-to"))
5192 ((string-match "," reply-to)
5194 (format "Multiple Reply-To addresses: \"%s\". Really post? "
5196 ((or (not (string-match
5198 (setq ad (nth 1 (mail-extract-address-components
5199 reply-to))))) ;larsi@ifi
5200 (string-match "\\.\\." ad) ;larsi@ifi..uio
5201 (string-match "@\\." ad) ;larsi@.ifi.uio
5202 (string-match "\\.$" ad) ;larsi@ifi.uio.
5203 (not (string-match "^[^@]+@[^@]+$" ad)) ;larsi.ifi.uio
5204 (string-match "(.*).*(.*)" reply-to)) ;(lars) (lars)
5207 "The Reply-To looks strange: \"%s\". Really post? "
5211 (defun message-check-news-body-syntax ()
5213 ;; Check for long lines.
5214 (message-check 'long-lines
5215 (goto-char (point-min))
5217 (concat "^" (regexp-quote mail-header-separator) "$"))
5221 "<#\\(/\\)?\\(multipart\\|part\\|external\\|mml\\)")
5224 (< (- (point) p) 80)))
5225 (zerop (forward-line 1))))
5229 "You have lines longer than 79 characters. Really post? ")))
5230 ;; Check whether the article is empty.
5231 (message-check 'empty
5232 (goto-char (point-min))
5234 (concat "^" (regexp-quote mail-header-separator) "$"))
5237 (goto-char (point-max))
5238 (re-search-backward message-signature-separator nil t)
5240 (or (re-search-backward "[^ \n\t]" b t)
5241 (if (message-gnksa-enable-p 'empty-article)
5242 (y-or-n-p "Empty article. Really post? ")
5243 (message "Denied posting -- Empty article.")
5245 ;; Check for control characters.
5246 (message-check 'control-chars
5247 (if (re-search-forward
5248 (mm-string-to-multibyte "[\000-\007\013\015-\032\034-\037\200-\237]")
5251 "The article contains control characters. Really post? ")
5253 ;; Check excessive size.
5254 (message-check 'size
5255 (if (> (buffer-size) 60000)
5257 (format "The article is %d octets long. Really post? "
5260 ;; Check whether any new text has been added.
5261 (message-check 'new-text
5263 (not message-checksum)
5264 (not (eq (message-checksum) message-checksum))
5265 (if (message-gnksa-enable-p 'quoted-text-only)
5267 "It looks like no new text has been added. Really post? ")
5268 (message "Denied posting -- no new text has been added.")
5270 ;; Check the length of the signature.
5271 (message-check 'signature
5272 (let (sig-start sig-end)
5273 (goto-char (point-max))
5274 (if (not (re-search-backward message-signature-separator nil t))
5276 (setq sig-start (1+ (point-at-eol)))
5278 (if (re-search-forward
5279 "<#/?\\(multipart\\|part\\|external\\|mml\\)" nil t)
5280 (- (point-at-bol) 1)
5282 (if (>= (count-lines sig-start sig-end) 5)
5283 (if (message-gnksa-enable-p 'signature)
5285 (format "Signature is excessively long (%d lines). Really post? "
5286 (count-lines sig-start sig-end)))
5287 (message "Denied posting -- Excessive signature.")
5290 ;; Ensure that text follows last quoted portion.
5291 (message-check 'quoting-style
5292 (goto-char (point-max))
5293 (let ((no-problem t))
5294 (when (search-backward-regexp "^>[^\n]*\n" nil t)
5295 (setq no-problem (search-forward-regexp "^[ \t]*[^>\n]" nil t)))
5298 (if (message-gnksa-enable-p 'quoted-text-only)
5299 (y-or-n-p "Your text should follow quoted text. Really post? ")
5301 (goto-char (point-min))
5303 (concat "^" (regexp-quote mail-header-separator) "$"))
5304 (if (search-forward-regexp "^[ \t]*[^>\n]" nil t)
5305 (y-or-n-p "Your text should follow quoted text. Really post? ")
5306 (message "Denied posting -- only quoted text.")
5309 (defun message-checksum ()
5310 "Return a \"checksum\" for the current buffer."
5313 (goto-char (point-min))
5315 (concat "^" (regexp-quote mail-header-separator) "$"))
5317 (when (not (looking-at "[ \t\n]"))
5318 (setq sum (logxor (ash sum 1) (if (natnump sum) 0 1)
5323 (defun message-do-fcc ()
5324 "Process Fcc headers in the current buffer."
5325 (let ((case-fold-search t)
5326 (buf (current-buffer))
5328 (mml-externalize-attachments message-fcc-externalize-attachments))
5331 (message-narrow-to-headers)
5332 (setq file (message-fetch-field "fcc" t)))
5334 (set-buffer (get-buffer-create " *message temp*"))
5336 (insert-buffer-substring buf)
5337 (message-encode-message-body)
5339 (message-narrow-to-headers)
5340 (while (setq file (message-fetch-field "fcc" t))
5342 (message-remove-header "fcc" nil t))
5343 (let ((mail-parse-charset message-default-charset)
5344 (rfc2047-header-encoding-alist
5345 (cons '("Newsgroups" . default)
5346 rfc2047-header-encoding-alist)))
5347 (mail-encode-encoded-word-buffer)))
5348 (goto-char (point-min))
5349 (when (re-search-forward
5350 (concat "^" (regexp-quote mail-header-separator) "$")
5352 (replace-match "" t t ))
5353 ;; Process FCC operations.
5355 (setq file (pop list))
5356 (if (string-match "^[ \t]*|[ \t]*\\(.*\\)[ \t]*$" file)
5357 ;; Pipe the article to the program in question.
5358 (call-process-region (point-min) (point-max) shell-file-name
5359 nil nil nil shell-command-switch
5360 (match-string 1 file))
5361 ;; Save the article.
5362 (setq file (expand-file-name file))
5363 (unless (file-exists-p (file-name-directory file))
5364 (make-directory (file-name-directory file) t))
5365 (if (and message-fcc-handler-function
5366 (not (eq message-fcc-handler-function 'rmail-output)))
5367 (funcall message-fcc-handler-function file)
5368 ;; FIXME this option, rmail-output (also used if
5369 ;; message-fcc-handler-function is nil) is not
5370 ;; documented anywhere AFAICS. It should work in Emacs
5371 ;; 23; I suspect it does not work in Emacs 22.
5372 ;; FIXME I don't see the need for the two different cases here.
5373 ;; mail-use-rfc822 makes no difference (in Emacs 23),and
5374 ;; the third argument just controls \"Wrote file\" message.
5375 (if (and (file-readable-p file) (mail-file-babyl-p file))
5376 (rmail-output file 1 nil t)
5377 (let ((mail-use-rfc822 t))
5378 (rmail-output file 1 t t))))))
5379 (kill-buffer (current-buffer))))))
5381 (defun message-output (filename)
5382 "Append this article to Unix/babyl mail file FILENAME."
5383 (if (or (and (file-readable-p filename)
5384 (mail-file-babyl-p filename))
5385 ;; gnus-output-to-mail does the wrong thing with live, mbox
5386 ;; Rmail buffers in Emacs 23.
5387 ;; http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=597255
5388 (let ((buff (find-buffer-visiting filename)))
5389 (and buff (with-current-buffer buff
5390 (eq major-mode 'rmail-mode)))))
5391 (gnus-output-to-rmail filename t)
5392 (gnus-output-to-mail filename t)))
5394 (defun message-cleanup-headers ()
5395 "Do various automatic cleanups of the headers."
5396 ;; Remove empty lines in the header.
5398 (message-narrow-to-headers)
5399 ;; Remove blank lines.
5400 (while (re-search-forward "^[ \t]*\n" nil t)
5401 (replace-match "" t t))
5403 ;; Correct Newsgroups and Followup-To headers: Change sequence of
5404 ;; spaces to comma and eliminate spaces around commas. Eliminate
5405 ;; embedded line breaks.
5406 (goto-char (point-min))
5407 (while (re-search-forward "^\\(Newsgroups\\|Followup-To\\): +" nil t)
5411 (if (re-search-forward "^[^ \t]" nil t)
5415 (goto-char (point-min))
5416 (while (re-search-forward "\n[ \t]+" nil t)
5417 (replace-match " " t t)) ;No line breaks (too confusing)
5418 (goto-char (point-min))
5419 (while (re-search-forward "[ \t\n]*,[ \t\n]*\\|[ \t]+" nil t)
5420 (replace-match "," t t))
5421 (goto-char (point-min))
5422 ;; Remove trailing commas.
5423 (when (re-search-forward ",+$" nil t)
5424 (replace-match "" t t))))))
5426 (defun message-make-date (&optional now)
5427 "Make a valid data header.
5428 If NOW, use that time instead."
5429 (let ((system-time-locale "C"))
5430 (format-time-string "%a, %d %b %Y %T %z" now)))
5432 (defun message-insert-expires (days)
5433 "Insert the Expires header. Expiry in DAYS days."
5434 (interactive "NExpire article in how many days? ")
5436 (message-position-on-field "Expires" "X-Draft-From")
5437 (insert (message-make-expires-date days))))
5439 (defun message-make-expires-date (days)
5440 "Make date string for the Expires header. Expiry in DAYS days.
5442 In posting styles use `(\"Expires\" (make-expires-date 30))'."
5443 (let* ((cur (decode-time (current-time)))
5444 (nday (+ days (nth 3 cur))))
5445 (setf (nth 3 cur) nday)
5446 (message-make-date (apply 'encode-time cur))))
5448 (defun message-make-message-id ()
5449 "Make a unique Message-ID."
5450 (concat "<" (message-unique-id)
5451 (let ((psubject (save-excursion (message-fetch-field "subject")))
5453 (save-excursion (message-fetch-field "supersedes"))))
5455 (and message-reply-headers
5456 (mail-header-references message-reply-headers)
5457 (mail-header-subject message-reply-headers)
5460 (message-strip-subject-re
5461 (mail-header-subject message-reply-headers))
5462 (message-strip-subject-re psubject))))
5464 (string-match "_-_@" psupersedes)))
5466 "@" (message-make-fqdn) ">"))
5468 (defvar message-unique-id-char nil)
5470 ;; If you ever change this function, make sure the new version
5471 ;; cannot generate IDs that the old version could.
5472 ;; You might for example insert a "." somewhere (not next to another dot
5473 ;; or string boundary), or modify the "fsf" string.
5474 (defun message-unique-id ()
5475 ;; Don't use microseconds from (current-time), they may be unsupported.
5476 ;; Instead we use this randomly inited counter.
5477 (setq message-unique-id-char
5478 (% (1+ (or message-unique-id-char (logand (random t) (1- (lsh 1 20)))))
5479 ;; (current-time) returns 16-bit ints,
5480 ;; and 2^16*25 just fits into 4 digits i base 36.
5482 (let ((tm (current-time)))
5484 (if (or (eq system-type 'ms-dos)
5485 ;; message-number-base36 doesn't handle bigints.
5486 (floatp (user-uid)))
5487 (let ((user (downcase (user-login-name))))
5488 (while (string-match "[^a-z0-9_]" user)
5489 (aset user (match-beginning 0) ?_))
5491 (message-number-base36 (user-uid) -1))
5492 (message-number-base36 (+ (car tm)
5493 (lsh (% message-unique-id-char 25) 16)) 4)
5494 (message-number-base36 (+ (nth 1 tm)
5495 (lsh (/ message-unique-id-char 25) 16)) 4)
5496 ;; Append a given name, because while the generated ID is unique
5497 ;; to this newsreader, other newsreaders might otherwise generate
5498 ;; the same ID via another algorithm.
5501 (defun message-number-base36 (num len)
5506 (concat (message-number-base36 (/ num 36) (1- len))
5507 (char-to-string (aref "zyxwvutsrqponmlkjihgfedcba9876543210"
5510 (defun message-make-organization ()
5511 "Make an Organization header."
5512 (let* ((organization
5513 (when message-user-organization
5514 (if (functionp message-user-organization)
5515 (funcall message-user-organization)
5516 message-user-organization))))
5518 (mm-enable-multibyte)
5519 (cond ((stringp organization)
5520 (insert organization))
5521 ((and (eq t organization)
5522 message-user-organization-file
5523 (file-exists-p message-user-organization-file))
5524 (insert-file-contents message-user-organization-file)))
5525 (goto-char (point-min))
5526 (while (re-search-forward "[\t\n]+" nil t)
5527 (replace-match "" t t))
5528 (unless (zerop (buffer-size))
5531 (defun message-make-lines ()
5532 "Count the number of lines and return numeric string."
5537 (int-to-string (count-lines (point) (point-max))))))
5539 (defun message-make-references ()
5540 "Return the References header for this message."
5541 (when message-reply-headers
5542 (let ((message-id (mail-header-id message-reply-headers))
5543 (references (mail-header-references message-reply-headers)))
5544 (if (or references message-id)
5545 (concat (or references "") (and references " ")
5549 (defun message-make-in-reply-to ()
5550 "Return the In-Reply-To header for this message."
5551 (when message-reply-headers
5552 (let ((from (mail-header-from message-reply-headers))
5553 (date (mail-header-date message-reply-headers))
5554 (msg-id (mail-header-id message-reply-headers)))
5556 (let ((name (mail-extract-address-components from)))
5558 msg-id (if msg-id " (")
5560 (if (string-match "[^\000-\177]" (car name))
5561 ;; Quote a string containing non-ASCII characters.
5562 ;; It will make the RFC2047 encoder cause an error
5563 ;; if there are special characters.
5564 (mm-with-multibyte-buffer
5566 (goto-char (point-min))
5567 (while (search-forward "\"" nil t)
5570 (zerop (% (skip-chars-backward "\\\\") 2))
5571 (goto-char (match-beginning 0)))
5574 ;; Those quotes will be removed by the RFC2047 encoder.
5575 (concat "\"" (buffer-string) "\""))
5579 (if (or (not date) (string= date ""))
5580 "(unknown date)" date)
5581 "\"" (if msg-id ")")))))))
5583 (defun message-make-distribution ()
5584 "Make a Distribution header."
5585 (let ((orig-distribution (message-fetch-reply-field "distribution")))
5586 (cond ((functionp message-distribution-function)
5587 (funcall message-distribution-function))
5588 (t orig-distribution))))
5590 (defun message-make-expires ()
5591 "Return an Expires header based on `message-expires'."
5592 (let ((current (current-time))
5593 (future (* 1.0 message-expires 60 60 24)))
5594 ;; Add the future to current.
5595 (setcar current (+ (car current) (round (/ future (expt 2 16)))))
5596 (setcar (cdr current) (+ (nth 1 current) (% (round future) (expt 2 16))))
5597 (message-make-date current)))
5599 (defun message-make-path ()
5601 (let ((login-name (user-login-name)))
5602 (cond ((null message-user-path)
5603 (concat (system-name) "!" login-name))
5604 ((stringp message-user-path)
5605 ;; Support GENERICPATH. Suggested by vixie@decwrl.dec.com.
5606 (concat message-user-path "!" login-name))
5609 (defun message-make-from (&optional name address)
5610 "Make a From header."
5611 (let* ((style message-from-style)
5612 (login (or address (message-make-address)))
5614 (and (boundp 'user-full-name)
5617 (when (string= fullname "&")
5618 (setq fullname (user-login-name)))
5620 (mm-enable-multibyte)
5623 (equal fullname ""))
5625 ((or (eq style 'angles)
5626 (and (not (eq style 'parens))
5627 ;; Use angles if no quoting is needed, or if parens would
5628 ;; need quoting too.
5629 (or (not (string-match "[^- !#-'*+/-9=?A-Z^-~]" fullname))
5630 (let ((tmp (concat fullname nil)))
5631 (while (string-match "([^()]*)" tmp)
5632 (aset tmp (match-beginning 0) ?-)
5633 (aset tmp (1- (match-end 0)) ?-))
5634 (string-match "[\\()]" tmp)))))
5636 (goto-char (point-min))
5637 ;; Look for a character that cannot appear unquoted
5638 ;; according to RFC 822.
5639 (when (re-search-forward "[^- !#-'*+/-9=?A-Z^-~]" nil 1)
5640 ;; Quote fullname, escaping specials.
5641 (goto-char (point-min))
5643 (while (re-search-forward "[\"\\]" nil 1)
5644 (replace-match "\\\\\\&" t))
5646 (insert " <" login ">"))
5647 (t ; 'parens or default
5649 (let ((fullname-start (point)))
5651 (goto-char fullname-start)
5652 ;; RFC 822 says \ and nonmatching parentheses
5653 ;; must be escaped in comments.
5654 ;; Escape every instance of ()\ ...
5655 (while (re-search-forward "[()\\]" nil 1)
5656 (replace-match "\\\\\\&" t))
5657 ;; ... then undo escaping of matching parentheses,
5658 ;; including matching nested parentheses.
5659 (goto-char fullname-start)
5660 (while (re-search-forward
5661 "\\(\\=\\|[^\\]\\(\\\\\\\\\\)*\\)\\\\(\\(\\([^\\]\\|\\\\\\\\\\)*\\)\\\\)"
5663 (replace-match "\\1(\\3)" t)
5664 (goto-char fullname-start)))
5668 (defun message-make-sender ()
5669 "Return the \"real\" user address.
5670 This function tries to ignore all user modifications, and
5671 give as trustworthy answer as possible."
5672 (concat (user-login-name) "@" (system-name)))
5674 (defun message-make-address ()
5675 "Make the address of the user."
5676 (or (message-user-mail-address)
5677 (concat (user-login-name) "@" (message-make-domain))))
5679 (defun message-user-mail-address ()
5680 "Return the pertinent part of `user-mail-address'."
5681 (when (and user-mail-address
5682 (string-match "@.*\\." user-mail-address))
5683 (if (string-match " " user-mail-address)
5684 (nth 1 (mail-extract-address-components user-mail-address))
5685 user-mail-address)))
5687 (defun message-sendmail-envelope-from ()
5688 "Return the envelope from."
5689 (cond ((eq message-sendmail-envelope-from 'header)
5690 (nth 1 (mail-extract-address-components
5691 (message-fetch-field "from"))))
5692 ((stringp message-sendmail-envelope-from)
5693 message-sendmail-envelope-from)
5695 (message-make-address))))
5697 (defun message-make-fqdn ()
5698 "Return user's fully qualified domain name."
5699 (let* ((system-name (system-name))
5700 (user-mail (message-user-mail-address))
5703 (string-match "@\\(.*\\)\\'" user-mail))
5704 (match-string 1 user-mail)))
5705 (case-fold-search t))
5707 ((and message-user-fqdn
5708 (stringp message-user-fqdn)
5709 (string-match message-valid-fqdn-regexp message-user-fqdn)
5710 (not (string-match message-bogus-system-names message-user-fqdn)))
5711 ;; `message-user-fqdn' seems to be valid
5713 ((and (string-match message-valid-fqdn-regexp system-name)
5714 (not (string-match message-bogus-system-names system-name)))
5715 ;; `system-name' returned the right result.
5717 ;; Try `mail-host-address'.
5718 ((and (boundp 'mail-host-address)
5719 (stringp mail-host-address)
5720 (string-match message-valid-fqdn-regexp mail-host-address)
5721 (not (string-match message-bogus-system-names mail-host-address)))
5723 ;; We try `user-mail-address' as a backup.
5725 (stringp user-domain)
5726 (string-match message-valid-fqdn-regexp user-domain)
5727 (not (string-match message-bogus-system-names user-domain)))
5729 ;; Default to this bogus thing.
5732 ".i-did-not-set--mail-host-address--so-tickle-me")))))
5734 (defun message-make-host-name ()
5735 "Return the name of the host."
5736 (let ((fqdn (message-make-fqdn)))
5737 (string-match "^[^.]+\\." fqdn)
5738 (substring fqdn 0 (1- (match-end 0)))))
5740 (defun message-make-domain ()
5741 "Return the domain name."
5742 (or mail-host-address
5743 (message-make-fqdn)))
5745 (defun message-to-list-only ()
5746 "Send a message to the list only.
5747 Remove all addresses but the list address from To and Cc headers."
5749 (let ((listaddr (message-make-mail-followup-to t)))
5752 (message-remove-header "to")
5753 (message-remove-header "cc")
5754 (message-position-on-field "To" "X-Draft-From")
5755 (insert listaddr)))))
5757 (defun message-make-mail-followup-to (&optional only-show-subscribed)
5758 "Return the Mail-Followup-To header.
5759 If passed the optional argument ONLY-SHOW-SUBSCRIBED only return the
5760 subscribed address (and not the additional To and Cc header contents)."
5761 (let* ((case-fold-search t)
5762 (to (message-fetch-field "To"))
5763 (cc (message-fetch-field "cc"))
5764 (msg-recipients (concat to (and to cc ", ") cc))
5766 (mapcar 'mail-strip-quoted-names
5767 (message-tokenize-header msg-recipients)))
5769 (if message-subscribed-address-file
5770 (let (begin end item re)
5773 (insert-file-contents message-subscribed-address-file)
5775 (setq begin (point))
5778 (if (bolp) (setq end (1- end)))
5779 (setq item (regexp-quote (buffer-substring begin end)))
5780 (if re (setq re (concat re "\\|" item))
5781 (setq re (concat "\\`\\(" item))))
5782 (and re (list (concat re "\\)\\'"))))))))
5783 (mft-regexps (apply 'append message-subscribed-regexps
5784 (mapcar 'regexp-quote
5785 message-subscribed-addresses)
5788 message-subscribed-address-functions))))
5791 (loop for recipient in recipients
5792 when (loop for regexp in mft-regexps
5793 when (string-match regexp recipient) return t)
5796 (if only-show-subscribed
5798 msg-recipients))))))
5800 (defun message-idna-to-ascii-rhs-1 (header)
5801 "Interactively potentially IDNA encode domain names in HEADER."
5802 (let ((field (message-fetch-field header))
5806 (mm-delete-duplicates
5807 (mapcar (lambda (rhs) (or (cadr (split-string rhs "@")) ""))
5813 (mail-extract-address-components field t))))))
5814 ;; Note that `rhs' will be "" if the address does not have
5815 ;; the domain part, i.e., if it is a local user's address.
5816 (setq ace (if (string-match "\\`[[:ascii:]]*\\'" rhs)
5818 (downcase (idna-to-ascii rhs))))
5819 (when (and (not (equal rhs ace))
5820 (or (not (eq message-use-idna 'ask))
5821 (y-or-n-p (format "Replace %s with %s in %s:? "
5823 (goto-char (point-min))
5824 (while (re-search-forward (concat "^" header ":") nil t)
5825 (message-narrow-to-field)
5826 (while (search-forward (concat "@" rhs) nil t)
5827 (replace-match (concat "@" ace) t t))
5828 (goto-char (point-max))
5831 (defun message-idna-to-ascii-rhs ()
5832 "Possibly IDNA encode non-ASCII domain names in From:, To: and Cc: headers.
5833 See `message-idna-encode'."
5835 (when message-use-idna
5838 ;; `message-narrow-to-head' that recognizes only the first empty
5839 ;; line as the message header separator used to be used here.
5840 ;; However, since there is the "--text follows this line--" line
5841 ;; normally, it failed in narrowing to the headers and potentially
5842 ;; caused the IDNA encoding on lines that look like headers in
5843 ;; the message body.
5844 (message-narrow-to-headers-or-head)
5845 (message-idna-to-ascii-rhs-1 "From")
5846 (message-idna-to-ascii-rhs-1 "To")
5847 (message-idna-to-ascii-rhs-1 "Reply-To")
5848 (message-idna-to-ascii-rhs-1 "Mail-Reply-To")
5849 (message-idna-to-ascii-rhs-1 "Mail-Followup-To")
5850 (message-idna-to-ascii-rhs-1 "Cc")))))
5854 (defvar Organization)
5859 (defvar In-Reply-To)
5862 (defvar Distribution)
5867 (defun message-generate-headers (headers)
5868 "Prepare article HEADERS.
5869 Headers already prepared in the buffer are not modified."
5870 (setq headers (append headers message-required-headers))
5872 (message-narrow-to-headers)
5873 (let* ((Date (message-make-date))
5874 (Message-ID (message-make-message-id))
5875 (Organization (message-make-organization))
5876 (From (message-make-from))
5877 (Path (message-make-path))
5880 (In-Reply-To (message-make-in-reply-to))
5881 (References (message-make-references))
5883 (Distribution (message-make-distribution))
5884 (Lines (message-make-lines))
5885 (User-Agent message-newsreader)
5886 (Expires (message-make-expires))
5887 (case-fold-search t)
5889 header value elem header-string)
5890 ;; First we remove any old generated headers.
5891 (let ((headers message-deletable-headers))
5892 (unless (buffer-modified-p)
5893 (setq headers (delq 'Message-ID (copy-sequence headers))))
5895 (goto-char (point-min))
5896 (and (re-search-forward
5897 (concat "^" (symbol-name (car headers)) ": *") nil t)
5898 (get-text-property (1+ (match-beginning 0)) 'message-deletable)
5899 (message-delete-line))
5901 ;; Go through all the required headers and see if they are in the
5902 ;; articles already. If they are not, or are empty, they are
5903 ;; inserted automatically - except for Subject, Newsgroups and
5906 (goto-char (point-min))
5907 (setq elem (pop headers))
5909 (if (eq (car elem) 'optional)
5910 (setq header (cdr elem)
5912 (setq header (car elem)))
5914 (setq header-string (if (stringp header)
5916 (symbol-name header)))
5917 (when (or (not (re-search-forward
5919 (regexp-quote (downcase header-string))
5923 ;; The header was found. We insert a space after the
5924 ;; colon, if there is none.
5925 (if (/= (char-after) ? ) (insert " ") (forward-char 1))
5926 ;; Find out whether the header is empty.
5927 (looking-at "[ \t]*\n[^ \t]")))
5928 ;; So we find out what value we should insert.
5932 (eq (car elem) 'optional)
5933 (not (member header-string message-inserted-headers)))
5934 ;; This is an optional header. If the cdr of this
5935 ;; is something that is nil, then we do not insert
5937 (setq header (cdr elem))
5938 (or (and (functionp (cdr elem))
5939 (funcall (cdr elem)))
5940 (and (boundp (cdr elem))
5941 (symbol-value (cdr elem)))))
5943 ;; The element is a cons. Either the cdr is a
5944 ;; string to be inserted verbatim, or it is a
5945 ;; function, and we insert the value returned from
5947 (or (and (stringp (cdr elem))
5949 (and (functionp (cdr elem))
5950 (funcall (cdr elem)))))
5951 ((and (boundp header)
5952 (symbol-value header))
5953 ;; The element is a symbol. We insert the value
5954 ;; of this symbol, if any.
5955 (symbol-value header))
5956 ((not (message-check-element
5957 (intern (downcase (symbol-name header)))))
5958 ;; We couldn't generate a value for this header,
5959 ;; so we just ask the user.
5960 (read-from-minibuffer
5961 (format "Empty header for %s; enter value: " header)))))
5962 ;; Finally insert the header.
5964 (not (equal value "")))
5968 ;; This header didn't exist, so we insert it.
5969 (goto-char (point-max))
5971 (cdr (assq header message-header-format-alist))))
5973 (funcall formatter header value)
5974 (insert header-string ": " value))
5975 (push header-string message-inserted-headers)
5976 (goto-char (message-fill-field))
5977 ;; We check whether the value was ended by a
5978 ;; newline. If not, we insert one.
5982 ;; The value of this header was empty, so we clear
5983 ;; totally and insert the new value.
5984 (delete-region (point) (point-at-eol))
5985 ;; If the header is optional, and the header was
5986 ;; empty, we can't insert it anyway.
5988 (push header-string message-inserted-headers)
5990 (message-fill-field)))
5991 ;; Add the deletable property to the headers that require it.
5992 (and (memq header message-deletable-headers)
5993 (progn (beginning-of-line) (looking-at "[^:]+: "))
5994 (add-text-properties
5995 (point) (match-end 0)
5996 '(message-deletable t face italic) (current-buffer)))))))
5997 ;; Insert new Sender if the From is strange.
5998 (let ((from (message-fetch-field "from"))
5999 (sender (message-fetch-field "sender"))
6000 (secure-sender (message-make-sender)))
6002 (not (message-check-element 'sender))
6005 (cadr (mail-extract-address-components from)))
6006 (downcase secure-sender)))
6011 (cadr (mail-extract-address-components sender)))
6012 (downcase secure-sender)))))
6013 (goto-char (point-min))
6014 ;; Rename any old Sender headers to Original-Sender.
6015 (when (re-search-forward "^\\(Original-\\)*Sender:" nil t)
6017 (insert "Original-")
6018 (beginning-of-line))
6019 (when (or (message-news-p)
6020 (string-match "@.+\\.." secure-sender))
6021 (insert "Sender: " secure-sender "\n"))))
6023 (message-idna-to-ascii-rhs))))
6025 (defun message-insert-courtesy-copy (message)
6026 "Insert a courtesy message in mail copies of combined messages."
6030 (message-narrow-to-headers)
6031 (when (setq newsgroups (message-fetch-field "newsgroups"))
6032 (goto-char (point-max))
6033 (insert "Posted-To: " newsgroups "\n")))
6037 ((string-match "%s" message)
6038 (insert (format message newsgroups)))
6040 (insert message)))))))
6043 ;;; Setting up a message buffer
6046 (defun message-skip-to-next-address ()
6047 (let ((end (save-excursion
6048 (message-next-header)
6051 (when (looking-at ",")
6053 (while (and (not (= (point) end))
6054 (or (not (eq char ?,))
6056 (skip-chars-forward "^,\"" (point-max))
6057 (when (eq (setq char (following-char)) ?\")
6058 (setq quoted (not quoted)))
6059 (unless (= (point) end)
6061 (skip-chars-forward " \t\n")))
6063 (defun message-fill-address (header value)
6064 (insert (capitalize (symbol-name header))
6066 (if (consp value) (car value) value)
6068 (message-fill-field-address))
6070 (defun message-split-line ()
6071 "Split current line, moving portion beyond point vertically down.
6072 If the current line has `message-yank-prefix', insert it on the new line."
6075 (split-line message-yank-prefix) ;; Emacs 22.1+ supports arg.
6079 (defun message-insert-header (header value)
6080 (insert (capitalize (symbol-name header))
6082 (if (consp value) (car value) value)))
6084 (defun message-field-name ()
6086 (goto-char (point-min))
6087 (when (looking-at "\\([^:]+\\):")
6088 (intern (capitalize (match-string 1))))))
6090 (defun message-fill-field ()
6093 (message-narrow-to-field)
6094 (let ((field-name (message-field-name)))
6095 (funcall (or (cadr (assq field-name message-field-fillers))
6096 'message-fill-field-general)))
6099 (defun message-fill-field-address ()
6101 (message-skip-to-next-address)
6103 (if (and (> (current-column) 78)
6109 (setq last (1+ (point))))
6110 (setq last (1+ (point)))))))
6112 (defun message-fill-field-general ()
6113 (let ((begin (point))
6116 (while (and (search-forward "\n" nil t)
6118 (replace-match " " t t))
6119 (fill-region-as-paragraph begin (point-max))
6120 ;; Tapdance around looong Message-IDs.
6122 (when (looking-at "[ \t]*$")
6123 (message-delete-line))
6125 (search-forward ":" nil t)
6126 (when (looking-at "\n[ \t]+")
6127 (replace-match " " t t))
6128 (goto-char (point-max))))
6130 (defun message-shorten-1 (list cut surplus)
6131 "Cut SURPLUS elements out of LIST, beginning with CUTth one."
6132 (setcdr (nthcdr (- cut 2) list)
6133 (nthcdr (+ (- cut 2) surplus 1) list)))
6135 (defun message-shorten-references (header references)
6136 "Trim REFERENCES to be 21 Message-ID long or less, and fold them.
6137 When sending via news, also check that the REFERENCES are less
6138 than 988 characters long, and if they are not, trim them until
6140 ;; 21 is the number suggested by USEAGE.
6147 (goto-char (point-min))
6148 ;; Cons a list of valid references. GNKSA says we must not include MIDs
6149 ;; with whitespace or missing brackets (7.a "Does not propagate broken
6150 ;; Message-IDs in original References").
6151 (while (re-search-forward "<[^ <]+@[^ <]+>" nil t)
6152 (push (match-string 0) refs))
6153 (setq refs (nreverse refs)
6154 count (length refs)))
6156 ;; If the list has more than MAXCOUNT elements, trim it by
6157 ;; removing the CUTth element and the required number of
6158 ;; elements that follow.
6159 (when (> count maxcount)
6160 (let ((surplus (- count maxcount)))
6161 (message-shorten-1 refs cut surplus)
6162 (decf count surplus)))
6164 ;; When sending via news, make sure the total folded length will
6165 ;; be less than 998 characters. This is to cater to broken INN
6166 ;; 2.3 which counts the total number of characters in a header
6167 ;; rather than the physical line length of each line, as it should.
6169 ;; This hack should be removed when it's believed than INN 2.3 is
6170 ;; no longer widely used.
6172 ;; At this point the headers have not been generated, thus we use
6173 ;; message-this-is-news directly.
6174 (when message-this-is-news
6177 (message-insert-header
6178 header (mapconcat #'identity refs " "))
6180 (message-shorten-1 refs cut 1)))
6181 ;; Finally, collect the references back into a string and insert
6182 ;; it into the buffer.
6183 (message-insert-header header (mapconcat #'identity refs " "))))
6185 (defun message-position-point ()
6186 "Move point to where the user probably wants to find it."
6187 (message-narrow-to-headers)
6189 ((re-search-forward "^[^:]+:[ \t]*$" nil t)
6190 (search-backward ":" )
6193 (if (eq (char-after) ? )
6197 (goto-char (point-max))
6200 (unless (looking-at "$")
6204 (defcustom message-beginning-of-line t
6205 "Whether \\<message-mode-map>\\[message-beginning-of-line]\
6206 goes to beginning of header values."
6208 :group 'message-buffers
6209 :link '(custom-manual "(message)Movement")
6212 (defun message-beginning-of-line (&optional n)
6213 "Move point to beginning of header value or to beginning of line.
6214 The prefix argument N is passed directly to `beginning-of-line'.
6216 This command is identical to `beginning-of-line' if point is
6217 outside the message header or if the option `message-beginning-of-line'
6220 If point is in the message header and on a (non-continued) header
6221 line, move point to the beginning of the header value or the beginning of line,
6222 whichever is closer. If point is already at beginning of line, move point to
6223 beginning of header value. Therefore, repeated calls will toggle point
6224 between beginning of field and beginning of line."
6226 (let ((zrs 'zmacs-region-stays))
6227 (when (and (featurep 'xemacs) (interactive-p) (boundp zrs))
6229 (if (and message-beginning-of-line
6230 (message-point-in-header-p))
6231 (let* ((here (point))
6232 (bol (progn (beginning-of-line n) (point)))
6233 (eol (point-at-eol))
6234 (eoh (re-search-forward ": *" eol t)))
6236 (if (and eoh (or (< eoh here) (= bol here)))
6238 (beginning-of-line n)))
6240 (defun message-buffer-name (type &optional to group)
6241 "Return a new (unique) buffer name based on TYPE and TO."
6243 ;; Generate a new buffer name The Message Way.
6244 ((memq message-generate-new-buffers '(unique t))
6245 (generate-new-buffer-name
6249 (or (car (mail-extract-address-components to))
6252 (if (and group (not (string= group ""))) (concat " on " group) "")
6254 ;; Check whether `message-generate-new-buffers' is a function,
6255 ;; and if so, call it.
6256 ((functionp message-generate-new-buffers)
6257 (funcall message-generate-new-buffers type to group))
6258 ((eq message-generate-new-buffers 'unsent)
6259 (generate-new-buffer-name
6260 (concat "*unsent " type
6263 (or (car (mail-extract-address-components to))
6266 (if (and group (not (string= group ""))) (concat " on " group) "")
6268 ;; Search for the existing message buffer with the specified name.
6270 (let* ((new (if (eq message-generate-new-buffers 'standard)
6271 (generate-new-buffer-name (concat "*" type " message*"))
6272 (let ((message-generate-new-buffers 'unique))
6273 (message-buffer-name type to group))))
6274 (regexp (concat "\\`"
6276 (if (string-match "<[0-9]+>\\'" new)
6277 (substring new 0 (match-beginning 0))
6279 "\\(?:<\\([0-9]+\\)>\\)?\\'"))
6280 (case-fold-search nil))
6287 (when (and (string-match regexp (setq b (buffer-name b)))
6288 (eq (with-current-buffer b major-mode)
6290 (cons (string-to-number (or (match-string 1 b) "1"))
6293 'car-less-than-car)))
6296 (defun message-pop-to-buffer (name &optional switch-function)
6297 "Pop to buffer NAME, and warn if it already exists and is modified."
6298 (let ((buffer (get-buffer name)))
6300 (buffer-name buffer))
6301 (let ((window (get-buffer-window buffer 0)))
6303 ;; Raise the frame already displaying the message buffer.
6305 (gnus-select-frame-set-input-focus (window-frame window))
6306 (select-window window))
6307 (funcall (or switch-function 'pop-to-buffer) buffer)
6308 (set-buffer buffer))
6309 (when (and (buffer-modified-p)
6312 "Message already being composed; erase? ")
6314 (error "Message being composed")))
6315 (funcall (or switch-function 'pop-to-buffer) name)
6320 (defun message-do-send-housekeeping ()
6321 "Kill old message buffers."
6322 ;; We might have sent this buffer already. Delete it from the
6324 (setq message-buffer-list (delq (current-buffer) message-buffer-list))
6325 (while (and message-max-buffers
6327 (>= (length message-buffer-list) message-max-buffers))
6328 ;; Kill the oldest buffer -- unless it has been changed.
6329 (let ((buffer (pop message-buffer-list)))
6330 (when (and (buffer-name buffer)
6331 (not (buffer-modified-p buffer)))
6332 (kill-buffer buffer))))
6333 ;; Rename the buffer.
6334 (if message-send-rename-function
6335 (funcall message-send-rename-function)
6336 ;; Note: mail-abbrevs of XEmacs renames buffer name behind Gnus.
6338 "\\`\\*\\(sent \\|unsent \\)?\\(.+\\)\\*[^\\*]*\\|\\`mail to "
6340 (let ((name (match-string 2 (buffer-name)))
6342 (if (not (or (null name)
6343 (string-equal name "mail")
6344 (string-equal name "posting")))
6345 (setq name (concat "*sent " name "*"))
6346 (message-narrow-to-headers)
6347 (setq to (message-fetch-field "to"))
6348 (setq group (message-fetch-field "newsgroups"))
6352 (to (concat "*sent mail to "
6353 (or (car (mail-extract-address-components to))
6355 ((and group (not (string= group "")))
6356 (concat "*sent posting on " group "*"))
6357 (t "*sent mail*"))))
6358 (unless (string-equal name (buffer-name))
6359 (rename-buffer name t)))))
6360 ;; Push the current buffer onto the list.
6361 (when message-max-buffers
6362 (setq message-buffer-list
6363 (nconc message-buffer-list (list (current-buffer))))))
6365 (defun message-mail-user-agent ()
6367 ((not message-mail-user-agent) nil)
6368 ((eq message-mail-user-agent t) mail-user-agent)
6369 (t message-mail-user-agent))))
6370 (if (memq mua '(message-user-agent gnus-user-agent))
6374 ;; YANK-ACTION, if non-nil, can be a buffer or a yank action of the
6375 ;; form (FUNCTION . ARGS).
6376 (defun message-setup (headers &optional yank-action actions
6377 continue switch-function return-action)
6378 (let ((mua (message-mail-user-agent))
6380 (if (not (and message-this-is-mail mua))
6381 (message-setup-1 headers yank-action actions return-action)
6382 (setq headers (copy-sequence headers))
6383 (setq field (assq 'Subject headers))
6385 (setq subject (cdr field))
6386 (setq headers (delq field headers)))
6387 (setq field (assq 'To headers))
6389 (setq to (cdr field))
6390 (setq headers (delq field headers)))
6391 (let ((mail-user-agent mua))
6392 (compose-mail to subject
6393 (mapcar (lambda (item)
6395 (format "%s" (car item))
6398 continue switch-function
6399 (if (bufferp yank-action)
6400 (list 'insert-buffer yank-action)
6404 (defun message-headers-to-generate (headers included-headers excluded-headers)
6405 "Return a list that includes all headers from HEADERS.
6406 If INCLUDED-HEADERS is a list, just include those headers. If it is
6407 t, include all headers. In any case, headers from EXCLUDED-HEADERS
6411 (dolist (header headers)
6412 (setq header-name (cond
6413 ((and (consp header)
6414 (eq (car header) 'optional))
6415 ;; On the form (optional . Header)
6418 ;; On the form (Header . function)
6423 (when (and (not (memq header-name excluded-headers))
6424 (or (eq included-headers t)
6425 (memq header-name included-headers)))
6426 (push header result)))
6429 (defun message-setup-1 (headers &optional yank-action actions return-action)
6430 (dolist (action actions)
6432 (add-to-list 'message-send-actions
6433 `(apply ',(car action) ',(cdr action)))))
6434 (setq message-return-action return-action)
6435 (setq message-reply-buffer
6436 (if (and (consp yank-action)
6437 (eq (car yank-action) 'insert-buffer))
6440 (goto-char (point-min))
6441 ;; Insert all the headers.
6444 (alist message-header-format-alist))
6446 (unless (assq (caar h) message-header-format-alist)
6447 (push (list (caar h)) alist))
6451 (delete-region (point) (progn (forward-line -1) (point)))
6452 (when message-default-headers
6454 (if (functionp message-default-headers)
6455 (funcall message-default-headers)
6456 message-default-headers))
6457 (or (bolp) (insert ?\n)))
6458 (insert (concat mail-header-separator "\n"))
6460 ;; If a crash happens while replying, the auto-save file would *not* have a
6461 ;; `References:' header if `message-generate-headers-first' was nil.
6462 ;; Therefore, always generate it first.
6463 (let ((message-generate-headers-first
6464 (if (eq message-generate-headers-first t)
6466 (append message-generate-headers-first '(References)))))
6467 (when (message-news-p)
6468 (when message-default-news-headers
6469 (insert message-default-news-headers)
6470 (or (bolp) (insert ?\n)))
6471 (message-generate-headers
6472 (message-headers-to-generate
6473 (append message-required-news-headers
6474 message-required-headers)
6475 message-generate-headers-first
6477 (when (message-mail-p)
6478 (when message-default-mail-headers
6479 (insert message-default-mail-headers)
6480 (or (bolp) (insert ?\n)))
6481 (message-generate-headers
6482 (message-headers-to-generate
6483 (append message-required-mail-headers
6484 message-required-headers)
6485 message-generate-headers-first
6486 '(Lines Subject)))))
6487 (run-hooks 'message-signature-setup-hook)
6488 (message-insert-signature)
6490 (message-narrow-to-headers)
6491 (run-hooks 'message-header-setup-hook))
6492 (setq buffer-undo-list nil)
6493 (when message-generate-hashcash
6494 ;; Generate hashcash headers for recipients already known
6495 (mail-add-payment-async))
6496 ;; Gnus posting styles are applied via buffer-local `message-setup-hook'
6498 (run-hooks 'message-setup-hook)
6499 ;; Do this last to give it precedence over posting styles, etc.
6500 (when (message-mail-p)
6502 (message-narrow-to-headers)
6503 (if message-alternative-emails
6504 (message-use-alternative-email-as-from))))
6505 (message-position-point)
6506 ;; Allow correct handling of `message-checksum' in `message-yank-original':
6507 (set-buffer-modified-p nil)
6510 (defun message-set-auto-save-file-name ()
6511 "Associate the message buffer with a file in the drafts directory."
6512 (when message-auto-save-directory
6513 (unless (file-directory-p
6514 (directory-file-name message-auto-save-directory))
6515 (make-directory message-auto-save-directory t))
6517 (setq message-draft-article
6518 (nndraft-request-associate-buffer "drafts"))
6520 ;; If Gnus were alive, draft messages would be saved in the drafts folder.
6521 ;; But Gnus is not alive, so arrange to save the draft message in a
6522 ;; regular file in message-auto-save-directory. Append a unique
6523 ;; time-based suffix to the filename to allow multiple drafts to be saved
6524 ;; simultaneously without overwriting each other (which mimics the
6525 ;; functionality of the Gnus drafts folder).
6526 (setq buffer-file-name (expand-file-name
6528 (if (memq system-type
6529 '(ms-dos windows-nt cygwin))
6532 (format-time-string "-%Y%m%d-%H%M%S"))
6533 message-auto-save-directory))
6534 (setq buffer-auto-save-file-name (make-auto-save-file-name)))
6535 (clear-visited-file-modtime)
6536 (setq buffer-file-coding-system message-draft-coding-system)))
6538 (defun message-disassociate-draft ()
6539 "Disassociate the message buffer from the drafts directory."
6540 (when message-draft-article
6541 (nndraft-request-expire-articles
6542 (list message-draft-article) "drafts" nil t)))
6544 (defun message-insert-headers ()
6545 "Generate the headers for the article."
6549 (message-narrow-to-headers)
6550 (when (message-news-p)
6551 (message-generate-headers
6554 (copy-sequence message-required-news-headers)))))
6555 (when (message-mail-p)
6556 (message-generate-headers
6559 (copy-sequence message-required-mail-headers))))))))
6564 ;;; Commands for interfacing with message
6568 (defun message-mail (&optional to subject other-headers continue
6569 switch-function yank-action send-actions
6570 return-action &rest ignored)
6571 "Start editing a mail message to be sent.
6572 OTHER-HEADERS is an alist of header/value pairs. CONTINUE says whether
6573 to continue editing a message already being composed. SWITCH-FUNCTION
6574 is a function used to switch to and display the mail buffer."
6576 (let ((message-this-is-mail t))
6577 (unless (message-mail-user-agent)
6578 (message-pop-to-buffer
6579 ;; Search for the existing message buffer if `continue' is non-nil.
6580 (let ((message-generate-new-buffers
6581 (when (or (not continue)
6582 (eq message-generate-new-buffers 'standard)
6583 (functionp message-generate-new-buffers))
6584 message-generate-new-buffers)))
6585 (message-buffer-name "mail" to))
6589 `((To . ,(or to "")) (Subject . ,(or subject "")))
6590 ;; C-h f compose-mail says that headers should be specified as
6591 ;; (string . value); however all the rest of message expects
6592 ;; headers to be symbols, not strings (eg message-header-format-alist).
6593 ;; http://lists.gnu.org/archive/html/emacs-devel/2011-01/msg00337.html
6594 ;; We need to convert any string input, eg from rmail-start-mail.
6595 (dolist (h other-headers other-headers)
6596 (if (stringp (car h)) (setcar h (intern (capitalize (car h)))))))
6597 yank-action send-actions continue switch-function
6601 (defun message-news (&optional newsgroups subject)
6602 "Start editing a news article to be sent."
6604 (let ((message-this-is-news t))
6605 (message-pop-to-buffer (message-buffer-name "posting" nil newsgroups))
6606 (message-setup `((Newsgroups . ,(or newsgroups ""))
6607 (Subject . ,(or subject ""))))))
6609 (defun message-alter-recipients-discard-bogus-full-name (addrcell)
6610 "Discard mail address in full names.
6611 When the full name in reply headers contains the mail
6612 address (e.g. \"foo@bar <foo@bar>\"), discard full name.
6613 ADDRCELL is a cons cell where the car is the mail address and the
6614 cdr is the complete address (full name and mail address)."
6615 (if (string-match (concat (regexp-quote (car addrcell)) ".*"
6616 (regexp-quote (car addrcell)))
6618 (cons (car addrcell) (car addrcell))
6621 (defcustom message-alter-recipients-function nil
6622 "Function called to allow alteration of reply header structures.
6623 It is called in `message-get-reply-headers' for each recipient.
6624 The function is called with one parameter, a cons cell ..."
6625 :type '(choice (const :tag "None" nil)
6626 (const :tag "Discard bogus full name"
6627 message-alter-recipients-discard-bogus-full-name)
6629 :version "23.1" ;; No Gnus
6630 :group 'message-headers)
6632 (defun message-get-reply-headers (wide &optional to-address address-headers)
6633 (let (follow-to mct never-mct to cc author mft recipients extra)
6634 ;; Find all relevant headers we need.
6636 (message-narrow-to-headers-or-head)
6637 ;; Gmane renames "To". Look at "Original-To", too, if it is present in
6638 ;; message-header-synonyms.
6639 (setq to (or (message-fetch-field "to")
6640 (and (loop for synonym in message-header-synonyms
6641 when (memq 'Original-To synonym)
6643 (message-fetch-field "original-to")))
6644 cc (message-fetch-field "cc")
6645 extra (when message-extra-wide-headers
6646 (mapconcat 'identity
6647 (mapcar 'message-fetch-field
6648 message-extra-wide-headers)
6650 mct (message-fetch-field "mail-copies-to")
6651 author (or (message-fetch-field "mail-reply-to")
6652 (message-fetch-field "reply-to")
6653 (message-fetch-field "from")
6655 mft (and message-use-mail-followup-to
6656 (message-fetch-field "mail-followup-to"))))
6658 ;; Handle special values of Mail-Copies-To.
6660 (cond ((or (equal (downcase mct) "never")
6661 (equal (downcase mct) "nobody"))
6664 ((or (equal (downcase mct) "always")
6665 (equal (downcase mct) "poster"))
6666 (setq mct author))))
6669 ;; Build (textual) list of new recipient addresses.
6672 (setq recipients (concat ", " to-address))
6673 ;; If the author explicitly asked for a copy, we don't deny it to them.
6674 (if mct (setq recipients (concat recipients ", " mct))))
6676 (setq recipients (concat ", " author)))
6678 (dolist (header address-headers)
6679 (let ((value (message-fetch-field header)))
6681 (setq recipients (concat recipients ", " value))))))
6683 (string-match "[^ \t,]" mft)
6684 (or (not (eq message-use-mail-followup-to 'ask))
6685 (message-y-or-n-p "Obey Mail-Followup-To? " t "\
6686 You should normally obey the Mail-Followup-To: header. In this
6687 article, it has the value of
6691 which directs your response to " (if (string-match "," mft)
6692 "the specified addresses"
6693 "that address only") ".
6695 Most commonly, Mail-Followup-To is used by a mailing list poster to
6696 express that responses should be sent to just the list, and not the
6699 If a message is posted to several mailing lists, Mail-Followup-To may
6700 also be used to direct the following discussion to one list only,
6701 because discussions that are spread over several lists tend to be
6702 fragmented and very difficult to follow.
6704 Also, some source/announcement lists are not intended for discussion;
6705 responses here are directed to other addresses.
6707 You may customize the variable `message-use-mail-followup-to', if you
6708 want to get rid of this query permanently.")))
6709 (setq recipients (concat ", " mft)))
6711 (setq recipients (if never-mct "" (concat ", " author)))
6712 (if to (setq recipients (concat recipients ", " to)))
6713 (if cc (setq recipients (concat recipients ", " cc)))
6714 (if extra (setq recipients (concat recipients ", " extra)))
6715 (if mct (setq recipients (concat recipients ", " mct)))))
6716 (if (>= (length recipients) 2)
6717 ;; Strip the leading ", ".
6718 (setq recipients (substring recipients 2)))
6719 ;; Squeeze whitespace.
6720 (while (string-match "[ \t][ \t]+" recipients)
6721 (setq recipients (replace-match " " t t recipients)))
6722 ;; Remove addresses that match `rmail-dont-reply-to-names'.
6723 (let ((rmail-dont-reply-to-names (message-dont-reply-to-names)))
6724 (setq recipients (rmail-dont-reply-to recipients)))
6725 ;; Perhaps "Mail-Copies-To: never" removed the only address?
6726 (if (string-equal recipients "")
6727 (setq recipients author))
6728 ;; Convert string to a list of (("foo@bar" . "Name <Foo@BAR>") ...).
6732 (if message-alter-recipients-function
6733 (funcall message-alter-recipients-function
6734 (cons (downcase (mail-strip-quoted-names addr))
6736 (cons (downcase (mail-strip-quoted-names addr)) addr)))
6737 (message-tokenize-header recipients)))
6738 ;; Remove first duplicates. (Why not all duplicates? Is this a bug?)
6739 (let ((s recipients))
6741 (setq recipients (delq (assoc (car (pop s)) s) recipients))))
6743 ;; Remove hierarchical lists that are contained within each other,
6744 ;; if message-hierarchical-addresses is defined.
6745 (when message-hierarchical-addresses
6746 (let ((plain-addrs (mapcar 'car recipients))
6749 (setq subaddrs (assoc (car plain-addrs)
6750 message-hierarchical-addresses)
6751 plain-addrs (cdr plain-addrs))
6753 (setq subaddrs (cdr subaddrs))
6755 (setq recip (assoc (car subaddrs) recipients)
6756 subaddrs (cdr subaddrs))
6758 (setq recipients (delq recip recipients))))))))
6760 (setq recipients (message-prune-recipients recipients))
6762 ;; Build the header alist. Allow the user to be asked whether
6763 ;; or not to reply to all recipients in a wide reply.
6764 (setq follow-to (list (cons 'To (cdr (pop recipients)))))
6765 (when (and recipients
6766 (or (not message-wide-reply-confirm-recipients)
6767 (y-or-n-p "Reply to all recipients? ")))
6768 (setq recipients (mapconcat
6769 (lambda (addr) (cdr addr)) recipients ", "))
6770 (if (string-match "^ +" recipients)
6771 (setq recipients (substring recipients (match-end 0))))
6772 (push (cons 'Cc recipients) follow-to)))
6775 (defun message-prune-recipients (recipients)
6776 (dolist (rule message-prune-recipient-rules)
6777 (let ((match (car rule))
6780 (dolist (recipient recipients)
6781 (setq address (car recipient))
6782 (when (string-match match address)
6783 (setq dup-match (replace-match (cadr rule) nil nil address))
6784 (dolist (recipient recipients)
6785 ;; Don't delete the address that triggered this.
6786 (when (and (not (eq address (car recipient)))
6787 (string-match dup-match (car recipient)))
6788 (setq recipients (delq recipient recipients))))))))
6791 (defcustom message-simplify-subject-functions
6792 '(message-strip-list-identifiers
6793 message-strip-subject-re
6794 message-strip-subject-trailing-was
6795 message-strip-subject-encoded-words)
6796 "List of functions taking a string argument that simplify subjects.
6797 The functions are applied when replying to a message.
6799 Useful functions to put in this list include:
6800 `message-strip-list-identifiers', `message-strip-subject-re',
6801 `message-strip-subject-trailing-was', and
6802 `message-strip-subject-encoded-words'."
6803 :version "22.1" ;; Gnus 5.10.9
6804 :group 'message-various
6805 :type '(repeat function))
6807 (defun message-simplify-subject (subject &optional functions)
6808 "Return simplified SUBJECT."
6811 (setq functions message-simplify-subject-functions))
6812 (when (and (memq 'message-strip-list-identifiers functions)
6813 gnus-list-identifiers)
6814 (setq subject (message-strip-list-identifiers subject)))
6815 (when (memq 'message-strip-subject-re functions)
6816 (setq subject (concat "Re: " (message-strip-subject-re subject))))
6817 (when (and (memq 'message-strip-subject-trailing-was functions)
6818 message-subject-trailing-was-query)
6819 (setq subject (message-strip-subject-trailing-was subject)))
6820 (when (memq 'message-strip-subject-encoded-words functions)
6821 (setq subject (message-strip-subject-encoded-words subject)))
6825 (defun message-reply (&optional to-address wide)
6826 "Start editing a reply to the article in the current buffer."
6828 (require 'gnus-sum) ; for gnus-list-identifiers
6829 (let ((cur (current-buffer))
6831 references message-id follow-to
6832 (inhibit-point-motion-hooks t)
6833 (message-this-is-mail t)
6836 (message-narrow-to-head-1)
6837 ;; Allow customizations to have their say.
6839 ;; This is a regular reply.
6840 (when (functionp message-reply-to-function)
6842 (setq follow-to (funcall message-reply-to-function))))
6843 ;; This is a followup.
6844 (when (functionp message-wide-reply-to-function)
6847 (funcall message-wide-reply-to-function)))))
6848 (setq message-id (message-fetch-field "message-id" t)
6849 references (message-fetch-field "references")
6850 date (message-fetch-field "date")
6851 from (or (message-fetch-field "from") "nobody")
6852 subject (or (message-fetch-field "subject") "none"))
6854 ;; Strip list identifiers, "Re: ", and "was:"
6855 (setq subject (message-simplify-subject subject))
6857 (when (and (setq gnus-warning (message-fetch-field "gnus-warning"))
6858 (string-match "<[^>]+>" gnus-warning))
6859 (setq message-id (match-string 0 gnus-warning)))
6862 (setq follow-to (message-get-reply-headers wide to-address))))
6864 (unless (message-mail-user-agent)
6865 (message-pop-to-buffer
6866 (message-buffer-name
6867 (if wide "wide reply" "reply") from
6868 (if wide to-address nil))))
6870 (setq message-reply-headers
6871 (vector 0 subject from date message-id references 0 0 ""))
6874 `((Subject . ,subject)
6879 (defun message-wide-reply (&optional to-address)
6880 "Make a \"wide\" reply to the message in the current buffer."
6882 (message-reply to-address t))
6885 (defun message-followup (&optional to-newsgroups)
6886 "Follow up to the message in the current buffer.
6887 If TO-NEWSGROUPS, use that as the new Newsgroups line."
6889 (require 'gnus-sum) ; for gnus-list-identifiers
6890 (let ((cur (current-buffer))
6891 from subject date reply-to mrt mct
6892 references message-id follow-to
6893 (inhibit-point-motion-hooks t)
6894 (message-this-is-news t)
6895 followup-to distribution newsgroups gnus-warning posted-to)
6898 (goto-char (point-min))
6899 (if (search-forward "\n\n" nil t)
6902 (when (functionp message-followup-to-function)
6904 (funcall message-followup-to-function)))
6905 (setq from (message-fetch-field "from")
6906 date (message-fetch-field "date")
6907 subject (or (message-fetch-field "subject") "none")
6908 references (message-fetch-field "references")
6909 message-id (message-fetch-field "message-id" t)
6910 followup-to (message-fetch-field "followup-to")
6911 newsgroups (message-fetch-field "newsgroups")
6912 posted-to (message-fetch-field "posted-to")
6913 reply-to (message-fetch-field "reply-to")
6914 mrt (message-fetch-field "mail-reply-to")
6915 distribution (message-fetch-field "distribution")
6916 mct (message-fetch-field "mail-copies-to"))
6917 (when (and (setq gnus-warning (message-fetch-field "gnus-warning"))
6918 (string-match "<[^>]+>" gnus-warning))
6919 (setq message-id (match-string 0 gnus-warning)))
6920 ;; Remove bogus distribution.
6921 (when (and (stringp distribution)
6922 (let ((case-fold-search t))
6923 (string-match "world" distribution)))
6924 (setq distribution nil))
6925 ;; Strip list identifiers, "Re: ", and "was:"
6926 (setq subject (message-simplify-subject subject))
6929 (message-pop-to-buffer (message-buffer-name "followup" from newsgroups))
6931 (setq message-reply-headers
6932 (vector 0 subject from date message-id references 0 0 ""))
6935 `((Subject . ,subject)
6938 (list (cons 'Newsgroups to-newsgroups)))
6939 (follow-to follow-to)
6940 ((and followup-to message-use-followup-to)
6943 ((equal (downcase followup-to) "poster")
6944 (if (or (eq message-use-followup-to 'use)
6945 (message-y-or-n-p "Obey Followup-To: poster? " t "\
6946 You should normally obey the Followup-To: header.
6948 `Followup-To: poster' sends your response via e-mail instead of news.
6950 A typical situation where `Followup-To: poster' is used is when the poster
6951 does not read the newsgroup, so he wouldn't see any replies sent to it.
6953 You may customize the variable `message-use-followup-to', if you
6954 want to get rid of this query permanently."))
6956 (setq message-this-is-news nil)
6957 (cons 'To (or mrt reply-to from "")))
6958 (cons 'Newsgroups newsgroups)))
6960 (if (or (equal followup-to newsgroups)
6961 (not (eq message-use-followup-to 'ask))
6963 (concat "Obey Followup-To: " followup-to "? ") t "\
6964 You should normally obey the Followup-To: header.
6966 `Followup-To: " followup-to "'
6967 directs your response to " (if (string-match "," followup-to)
6968 "the specified newsgroups"
6969 "that newsgroup only") ".
6971 If a message is posted to several newsgroups, Followup-To is often
6972 used to direct the following discussion to one newsgroup only,
6973 because discussions that are spread over several newsgroup tend to
6974 be fragmented and very difficult to follow.
6976 Also, some source/announcement newsgroups are not intended for discussion;
6977 responses here are directed to other newsgroups.
6979 You may customize the variable `message-use-followup-to', if you
6980 want to get rid of this query permanently."))
6981 (cons 'Newsgroups followup-to)
6982 (cons 'Newsgroups newsgroups))))))
6984 `((Newsgroups . ,posted-to)))
6986 `((Newsgroups . ,newsgroups))))
6987 ,@(and distribution (list (cons 'Distribution distribution)))
6989 (not (or (equal (downcase mct) "never")
6990 (equal (downcase mct) "nobody"))))
6991 (list (cons 'Cc (if (or (equal (downcase mct) "always")
6992 (equal (downcase mct) "poster"))
6993 (or mrt reply-to from "")
6998 (defun message-is-yours-p ()
6999 "Non-nil means current article is yours.
7000 If you have added 'cancel-messages to `message-shoot-gnksa-feet', all articles
7001 are yours except those that have Cancel-Lock header not belonging to you.
7002 Instead of shooting GNKSA feet, you should modify `message-alternative-emails'
7003 regexp to match all of yours addresses."
7004 ;; Canlock-logic as suggested by Per Abrahamsen
7005 ;; <abraham@dina.kvl.dk>
7007 ;; IF article has cancel-lock THEN
7008 ;; IF we can verify it THEN
7011 ;; error: cancellock: article is not yours
7013 ;; Use old rules, comparing sender...
7016 (message-narrow-to-head-1)
7017 (if (message-fetch-field "Cancel-Lock")
7018 (if (null (canlock-verify))
7020 (error "Failed to verify Cancel-lock: This article is not yours"))
7023 (message-gnksa-enable-p 'cancel-messages)
7024 (and (setq sender (message-fetch-field "sender"))
7025 (string-equal (downcase sender)
7026 (downcase (message-make-sender))))
7027 ;; Email address in From field equals to our address
7028 (and (setq from (message-fetch-field "from"))
7030 (downcase (car (mail-header-parse-address from)))
7031 (downcase (car (mail-header-parse-address
7032 (message-make-from))))))
7033 ;; Email address in From field matches
7034 ;; 'message-alternative-emails' regexp
7036 message-alternative-emails
7038 message-alternative-emails
7039 (car (mail-header-parse-address from))))))))))
7042 (defun message-cancel-news (&optional arg)
7043 "Cancel an article you posted.
7044 If ARG, allow editing of the cancellation message."
7046 (unless (message-news-p)
7047 (error "This is not a news article; canceling is impossible"))
7048 (let (from newsgroups message-id distribution buf)
7050 ;; Get header info from original article.
7052 (message-narrow-to-head-1)
7053 (setq from (message-fetch-field "from")
7054 newsgroups (message-fetch-field "newsgroups")
7055 message-id (message-fetch-field "message-id" t)
7056 distribution (message-fetch-field "distribution")))
7057 ;; Make sure that this article was written by the user.
7058 (unless (message-is-yours-p)
7059 (error "This article is not yours"))
7060 (when (yes-or-no-p "Do you really want to cancel this article? ")
7061 ;; Make control message.
7064 (setq buf (set-buffer (get-buffer-create " *message cancel*"))))
7066 (insert "Newsgroups: " newsgroups "\n"
7068 "Subject: cmsg cancel " message-id "\n"
7069 "Control: cancel " message-id "\n"
7071 (concat "Distribution: " distribution "\n")
7073 mail-header-separator "\n"
7074 message-cancel-message)
7075 (run-hooks 'message-cancel-hook)
7077 (message "Canceling your article...")
7078 (if (let ((message-syntax-checks
7079 'dont-check-for-anything-just-trust-me))
7080 (funcall message-send-news-function))
7081 (message "Canceling your article...done"))
7082 (kill-buffer buf))))))
7085 (defun message-supersede ()
7086 "Start composing a message to supersede the current message.
7087 This is done simply by taking the old article and adding a Supersedes
7088 header line with the old Message-ID."
7090 (let ((cur (current-buffer)))
7091 ;; Check whether the user owns the article that is to be superseded.
7092 (unless (message-is-yours-p)
7093 (error "This article is not yours"))
7094 ;; Get a normal message buffer.
7095 (message-pop-to-buffer (message-buffer-name "supersede"))
7096 (insert-buffer-substring cur)
7098 (message-narrow-to-head-1)
7099 ;; Remove unwanted headers.
7100 (when message-ignored-supersedes-headers
7101 (message-remove-header message-ignored-supersedes-headers t))
7102 (goto-char (point-min))
7103 (if (not (re-search-forward "^Message-ID: " nil t))
7104 (error "No Message-ID in this article")
7105 (replace-match "Supersedes: " t t))
7106 (goto-char (point-max))
7107 (insert mail-header-separator)
7112 (defun message-recover ()
7113 "Reread contents of current buffer from its last auto-save file."
7115 (let ((file-name (make-auto-save-file-name)))
7116 (cond ((save-window-excursion
7117 (with-output-to-temp-buffer "*Directory*"
7118 (with-current-buffer standard-output
7119 (fundamental-mode)) ; for Emacs 20.4+
7120 (buffer-disable-undo standard-output)
7121 (let ((default-directory "/"))
7123 "ls" nil standard-output nil "-l" file-name)))
7124 (yes-or-no-p (format "Recover auto save file %s? " file-name)))
7125 (let ((buffer-read-only nil))
7127 (insert-file-contents file-name nil)))
7128 (t (error "message-recover cancelled")))))
7130 ;;; Washing Subject:
7132 (defun message-wash-subject (subject)
7133 "Remove junk like \"Re:\", \"(fwd)\", etc. added to subject string SUBJECT.
7134 Previous forwarders, replyers, etc. may add it."
7137 (goto-char (point-min))
7138 ;; strip Re/Fwd stuff off the beginning
7139 (while (re-search-forward
7140 "\\([Rr][Ee]:\\|[Ff][Ww][Dd]\\(\\[[0-9]*\\]\\)?:\\|[Ff][Ww]:\\)" nil t)
7143 ;; and gnus-style forwards [foo@bar.com] subject
7144 (goto-char (point-min))
7145 (while (re-search-forward "\\[[^ \t]*\\(@\\|\\.\\)[^ \t]*\\]" nil t)
7149 (goto-char (point-max))
7150 (while (re-search-backward "([Ff][Ww][Dd])" nil t)
7153 ;; and finally, any whitespace that was left-over
7154 (goto-char (point-min))
7155 (while (re-search-forward "^[ \t]+" nil t)
7157 (goto-char (point-max))
7158 (while (re-search-backward "[ \t]+$" nil t)
7163 ;;; Forwarding messages.
7165 (defvar message-forward-decoded-p nil
7166 "Non-nil means the original message is decoded.")
7168 (defun message-forward-subject-name-subject (subject)
7169 "Generate a SUBJECT for a forwarded message.
7170 The form is: [Source] Subject, where if the original message was mail,
7171 Source is the name of the sender, and if the original message was
7172 news, Source is the list of newsgroups is was posted to."
7173 (let* ((group (message-fetch-field "newsgroups"))
7174 (from (message-fetch-field "from"))
7177 (gnus-group-decoded-name group)
7179 (car (gnus-extract-address-components from))
7180 (cadr (gnus-extract-address-components from))))
7183 (if message-forward-decoded-p
7185 (mail-decode-encoded-word-string prefix))
7188 (defun message-forward-subject-author-subject (subject)
7189 "Generate a SUBJECT for a forwarded message.
7190 The form is: [Source] Subject, where if the original message was mail,
7191 Source is the sender, and if the original message was news, Source is
7192 the list of newsgroups is was posted to."
7193 (let* ((group (message-fetch-field "newsgroups"))
7196 (gnus-group-decoded-name group)
7197 (or (message-fetch-field "from")
7200 (if message-forward-decoded-p
7202 (mail-decode-encoded-word-string prefix))
7205 (defun message-forward-subject-fwd (subject)
7206 "Generate a SUBJECT for a forwarded message.
7207 The form is: Fwd: Subject, where Subject is the original subject of
7209 (if (string-match "^Fwd: " subject)
7211 (concat "Fwd: " subject)))
7213 (defun message-make-forward-subject ()
7214 "Return a Subject header suitable for the message in the current buffer."
7217 (message-narrow-to-head-1)
7218 (let ((funcs message-make-forward-subject-function)
7219 (subject (message-fetch-field "Subject")))
7222 (if message-forward-decoded-p
7224 (mail-decode-encoded-word-string subject))
7226 (when message-wash-forwarded-subjects
7227 (setq subject (message-wash-subject subject)))
7228 ;; Make sure funcs is a list.
7231 (setq funcs (list funcs)))
7232 ;; Apply funcs in order, passing subject generated by previous
7233 ;; func to the next one.
7234 (dolist (func funcs)
7235 (when (functionp func)
7236 (setq subject (funcall func subject))))
7239 (defvar gnus-article-decoded-p)
7243 (defun message-forward (&optional news digest)
7244 "Forward the current message via mail.
7245 Optional NEWS will use news to forward instead of mail.
7246 Optional DIGEST will use digest to forward."
7248 (let* ((cur (current-buffer))
7249 (message-forward-decoded-p
7250 (if (local-variable-p 'gnus-article-decoded-p (current-buffer))
7251 gnus-article-decoded-p ;; In an article buffer.
7252 message-forward-decoded-p))
7253 (subject (message-make-forward-subject)))
7255 (message-news nil subject)
7256 (message-mail nil subject))
7257 (message-forward-make-body cur digest)))
7259 (defun message-forward-make-body-plain (forward-buffer)
7261 "\n-------------------- Start of forwarded message --------------------\n")
7263 (contents (with-current-buffer forward-buffer (buffer-string)))
7265 (unless (featurep 'xemacs)
7266 (unless (mm-multibyte-string-p contents)
7267 (error "Attempt to insert unibyte string from the buffer \"%s\"\
7268 to the multibyte buffer \"%s\""
7269 (if (bufferp forward-buffer)
7270 (buffer-name forward-buffer)
7273 (insert (mm-with-multibyte-buffer
7276 (goto-char (point-min))
7277 (when (looking-at "From ")
7278 (replace-match "X-From-Line: "))
7280 (unless (bolp) (insert "\n"))
7283 "-------------------- End of forwarded message --------------------\n")
7284 (message-remove-ignored-headers b e)))
7286 (defun message-remove-ignored-headers (b e)
7287 (when message-forward-ignored-headers
7289 (narrow-to-region b e)
7291 (narrow-to-region (point)
7292 (or (search-forward "\n\n" nil t) (point)))
7293 (let ((ignored (if (stringp message-forward-ignored-headers)
7294 (list message-forward-ignored-headers)
7295 message-forward-ignored-headers)))
7296 (dolist (elem ignored)
7297 (message-remove-header elem t))))))
7299 (defun message-forward-make-body-mime (forward-buffer)
7301 (insert "\n\n<#part type=message/rfc822 disposition=inline raw=t>\n")
7303 (narrow-to-region (point) (point))
7304 (mml-insert-buffer forward-buffer)
7305 (goto-char (point-min))
7306 (when (looking-at "From ")
7307 (replace-match "X-From-Line: "))
7308 (goto-char (point-max)))
7309 (insert "<#/part>\n")
7310 ;; Consider there is no illegible text.
7311 (add-text-properties
7313 `(no-illegible-text t rear-nonsticky t start-open t))))
7315 (defun message-forward-make-body-mml (forward-buffer)
7316 (insert "\n\n<#mml type=message/rfc822 disposition=inline>\n")
7317 (let ((b (point)) e)
7318 (if (not message-forward-decoded-p)
7319 (let ((contents (with-current-buffer forward-buffer (buffer-string))))
7320 (unless (featurep 'xemacs)
7321 (unless (mm-multibyte-string-p contents)
7322 (error "Attempt to insert unibyte string from the buffer \"%s\"\
7323 to the multibyte buffer \"%s\""
7324 (if (bufferp forward-buffer)
7325 (buffer-name forward-buffer)
7328 (insert (mm-with-multibyte-buffer
7331 (goto-char (point-min))
7332 (when (looking-at "From ")
7333 (replace-match "X-From-Line: "))
7336 (narrow-to-region (point) (point))
7337 (mml-insert-buffer forward-buffer)
7338 (goto-char (point-min))
7339 (when (looking-at "From ")
7340 (replace-match "X-From-Line: "))
7341 (goto-char (point-max))))
7343 (insert "<#/mml>\n")
7344 (when (and (not message-forward-decoded-p)
7345 message-forward-ignored-headers)
7346 (message-remove-ignored-headers b e))))
7348 (defun message-forward-make-body-digest-plain (forward-buffer)
7350 "\n-------------------- Start of forwarded message --------------------\n")
7351 (mml-insert-buffer forward-buffer)
7353 "\n-------------------- End of forwarded message --------------------\n"))
7355 (defun message-forward-make-body-digest-mime (forward-buffer)
7356 (insert "\n<#multipart type=digest>\n")
7357 (let ((b (point)) e)
7358 (insert-buffer-substring forward-buffer)
7360 (insert "<#/multipart>\n")
7362 (narrow-to-region b e)
7364 (narrow-to-region (point)
7365 (or (search-forward "\n\n" nil t) (point)))
7366 (delete-region (point-min) (point-max)))))
7368 (defun message-forward-make-body-digest (forward-buffer)
7369 (if message-forward-as-mime
7370 (message-forward-make-body-digest-mime forward-buffer)
7371 (message-forward-make-body-digest-plain forward-buffer)))
7373 (autoload 'mm-uu-dissect-text-parts "mm-uu")
7374 (autoload 'mm-uu-dissect "mm-uu")
7376 (defun message-signed-or-encrypted-p (&optional dont-emulate-mime handles)
7377 "Say whether the current buffer contains signed or encrypted message.
7378 If DONT-EMULATE-MIME is nil, this function does the MIME emulation on
7379 messages that don't conform to PGP/MIME described in RFC2015. HANDLES
7380 is for the internal use."
7382 (let ((mm-decrypt-option 'never)
7383 (mm-verify-option 'never))
7384 (if (setq handles (mm-dissect-buffer nil t))
7385 (unless dont-emulate-mime
7386 (mm-uu-dissect-text-parts handles))
7387 (unless dont-emulate-mime
7388 (setq handles (mm-uu-dissect))))))
7389 ;; Check text/plain message in which there is a signed or encrypted
7390 ;; body that has been encoded by B or Q.
7391 (unless (or handles dont-emulate-mime)
7392 (let ((cur (current-buffer))
7393 (mm-decrypt-option 'never)
7394 (mm-verify-option 'never))
7396 (insert-buffer-substring cur)
7397 (when (setq handles (mm-dissect-buffer t t))
7399 (bufferp (car handles))
7400 (mm-destroy-parts handles))
7401 (equal (mm-handle-media-type handles) "text/plain"))
7403 (mm-decode-content-transfer-encoding
7404 (mm-handle-encoding handles))
7405 (setq handles (mm-uu-dissect)))
7406 (setq handles nil))))))
7410 (dolist (handle (if (stringp (car handles))
7411 (if (member (car handles)
7412 '("multipart/signed"
7413 "multipart/encrypted"))
7417 (if (stringp (car handle))
7418 (when (message-signed-or-encrypted-p dont-emulate-mime handle)
7420 (when (and (bufferp (car handle))
7421 (equal (mm-handle-media-type handle)
7423 (with-current-buffer (mm-handle-buffer handle)
7424 (when (message-signed-or-encrypted-p dont-emulate-mime)
7425 (throw 'found t)))))))
7426 (mm-destroy-parts handles))))
7429 (defun message-forward-make-body (forward-buffer &optional digest)
7430 ;; Put point where we want it before inserting the forwarded
7432 (if message-forward-before-signature
7434 (goto-char (point-max)))
7436 (message-forward-make-body-digest forward-buffer)
7437 (if message-forward-as-mime
7438 (if (and message-forward-show-mml
7439 (not (and (eq message-forward-show-mml 'best)
7440 ;; Use the raw form in the body if it contains
7441 ;; signed or encrypted message so as not to be
7442 ;; destroyed by re-encoding.
7443 (with-current-buffer forward-buffer
7445 (message-signed-or-encrypted-p)
7447 (message-forward-make-body-mml forward-buffer)
7448 (message-forward-make-body-mime forward-buffer))
7449 (message-forward-make-body-plain forward-buffer)))
7450 (message-position-point))
7452 (declare-function rmail-toggle-header "rmail" (&optional arg))
7455 (defun message-forward-rmail-make-body (forward-buffer)
7456 (save-window-excursion
7457 (set-buffer forward-buffer)
7458 (if (rmail-msg-is-pruned)
7459 (if (fboundp 'rmail-msg-restore-non-pruned-header)
7460 (rmail-msg-restore-non-pruned-header) ; Emacs 22
7461 (rmail-toggle-header 0)))) ; Emacs 23
7462 (message-forward-make-body forward-buffer))
7464 ;; Fixme: Should have defcustom.
7466 (defun message-insinuate-rmail ()
7467 "Let RMAIL use message to forward."
7469 (setq rmail-enable-mime-composing t)
7470 (setq rmail-insert-mime-forwarded-message-function
7471 'message-forward-rmail-make-body))
7473 (defvar message-inhibit-body-encoding nil)
7476 (defun message-resend (address)
7477 "Resend the current article to ADDRESS."
7479 (list (message-read-from-minibuffer "Resend message to: ")))
7480 (message "Resending message to %s..." address)
7482 (let ((cur (current-buffer))
7484 ;; We first set up a normal mail buffer.
7485 (unless (message-mail-user-agent)
7486 (set-buffer (get-buffer-create " *message resend*"))
7487 (let ((inhibit-read-only t))
7489 (let ((message-this-is-mail t)
7490 message-generate-hashcash
7492 (message-setup `((To . ,address))))
7493 ;; Insert our usual headers.
7494 (message-generate-headers '(From Date To Message-ID))
7495 (message-narrow-to-headers)
7496 ;; Remove X-Draft-From header etc.
7497 (message-remove-header message-ignored-mail-headers t)
7498 ;; Rename them all to "Resent-*".
7499 (goto-char (point-min))
7500 (while (re-search-forward "^[A-Za-z]" nil t)
7505 (let ((inhibit-read-only t))
7506 (delete-region (point) (point-max)))
7508 ;; Insert the message to be resent.
7509 (insert-buffer-substring cur)
7510 (goto-char (point-min))
7511 (search-forward "\n\n")
7514 (narrow-to-region beg (point))
7515 (message-remove-header message-ignored-resent-headers t)
7516 (goto-char (point-max)))
7517 (insert mail-header-separator)
7518 ;; Rename all old ("Also-")Resent headers.
7519 (while (re-search-backward "^\\(Also-\\)*Resent-" beg t)
7522 ;; Quote any "From " lines at the beginning.
7524 (when (looking-at "From ")
7525 (replace-match "X-From-Line: "))
7527 (let ((message-inhibit-body-encoding
7528 ;; Don't do any further encoding if it looks like the
7529 ;; message has already been encoded.
7530 (let ((case-fold-search t))
7531 (re-search-forward "^mime-version:" nil t)))
7532 (message-inhibit-ecomplete t)
7533 message-required-mail-headers
7534 message-generate-hashcash
7535 rfc2047-encode-encoded-words)
7536 (message-send-mail))
7537 (kill-buffer (current-buffer)))
7538 (message "Resending message to %s...done" address)))
7541 (defun message-bounce ()
7542 "Re-mail the current message.
7543 This only makes sense if the current message is a bounce message that
7544 contains some mail you have written which has been bounced back to
7547 (let ((handles (mm-dissect-buffer t))
7549 (message-pop-to-buffer (message-buffer-name "bounce"))
7550 (if (stringp (car handles))
7551 ;; This is a MIME bounce.
7552 (mm-insert-part (car (last handles)))
7553 ;; This is a non-MIME bounce, so we try to remove things
7555 (mm-insert-part handles)
7557 (goto-char (point-min))
7558 (re-search-forward "\n\n+" nil t)
7559 (setq boundary (point))
7560 ;; We remove everything before the bounced mail.
7561 (if (or (re-search-forward message-unsent-separator nil t)
7563 (search-forward "\n\n" nil 'move)
7564 (re-search-backward "^Return-Path:.*\n" boundary t)))
7567 (delete-region (point-min)
7568 (if (re-search-forward "^[^ \n\t]+:" nil t)
7571 (goto-char boundary)
7572 (when (re-search-backward "^.?From .*\n" nil t)
7573 (delete-region (match-beginning 0) (match-end 0)))))
7576 (message-narrow-to-head-1)
7577 (message-remove-header message-ignored-bounced-headers t)
7578 (goto-char (point-max))
7579 (insert mail-header-separator))
7580 (message-position-point)))
7583 ;;; Interactive entry points for new message buffers.
7587 (defun message-mail-other-window (&optional to subject)
7588 "Like `message-mail' command, but display mail buffer in another window."
7590 (unless (message-mail-user-agent)
7591 (let ((pop-up-windows t)
7592 (special-display-buffer-names nil)
7593 (special-display-regexps nil)
7594 (same-window-buffer-names nil)
7595 (same-window-regexps nil))
7596 (message-pop-to-buffer (message-buffer-name "mail" to))))
7597 (let ((message-this-is-mail t))
7598 (message-setup `((To . ,(or to "")) (Subject . ,(or subject "")))
7599 nil nil nil 'switch-to-buffer-other-window)))
7602 (defun message-mail-other-frame (&optional to subject)
7603 "Like `message-mail' command, but display mail buffer in another frame."
7605 (unless (message-mail-user-agent)
7606 (let ((pop-up-frames t)
7607 (special-display-buffer-names nil)
7608 (special-display-regexps nil)
7609 (same-window-buffer-names nil)
7610 (same-window-regexps nil))
7611 (message-pop-to-buffer (message-buffer-name "mail" to))))
7612 (let ((message-this-is-mail t))
7613 (message-setup `((To . ,(or to "")) (Subject . ,(or subject "")))
7614 nil nil nil 'switch-to-buffer-other-frame)))
7617 (defun message-news-other-window (&optional newsgroups subject)
7618 "Start editing a news article to be sent."
7620 (let ((pop-up-windows t)
7621 (special-display-buffer-names nil)
7622 (special-display-regexps nil)
7623 (same-window-buffer-names nil)
7624 (same-window-regexps nil))
7625 (message-pop-to-buffer (message-buffer-name "posting" nil newsgroups)))
7626 (let ((message-this-is-news t))
7627 (message-setup `((Newsgroups . ,(or newsgroups ""))
7628 (Subject . ,(or subject ""))))))
7631 (defun message-news-other-frame (&optional newsgroups subject)
7632 "Start editing a news article to be sent."
7634 (let ((pop-up-frames t)
7635 (special-display-buffer-names nil)
7636 (special-display-regexps nil)
7637 (same-window-buffer-names nil)
7638 (same-window-regexps nil))
7639 (message-pop-to-buffer (message-buffer-name "posting" nil newsgroups)))
7640 (let ((message-this-is-news t))
7641 (message-setup `((Newsgroups . ,(or newsgroups ""))
7642 (Subject . ,(or subject ""))))))
7646 ;; This code should be moved to underline.el (from which it is stolen).
7649 (defun message-bold-region (start end)
7650 "Bold all nonblank characters in the region.
7651 Works by overstriking characters.
7652 Called from program, takes two arguments START and END
7653 which specify the range to operate on."
7656 (let ((end1 (make-marker)))
7657 (move-marker end1 (max start end))
7658 (goto-char (min start end))
7659 (while (< (point) end1)
7660 (or (looking-at "[_\^@- ]")
7661 (insert (char-after) "\b"))
7662 (forward-char 1)))))
7665 (defun message-unbold-region (start end)
7666 "Remove all boldness (overstruck characters) in the region.
7667 Called from program, takes two arguments START and END
7668 which specify the range to operate on."
7671 (let ((end1 (make-marker)))
7672 (move-marker end1 (max start end))
7673 (goto-char (min start end))
7674 (while (search-forward "\b" end1 t)
7675 (if (eq (char-after) (char-after (- (point) 2)))
7676 (delete-char -2))))))
7678 (defun message-exchange-point-and-mark ()
7679 "Exchange point and mark, but don't activate region if it was inactive."
7680 (goto-char (prog1 (mark t)
7681 (set-marker (mark-marker) (point)))))
7683 (defalias 'message-make-overlay 'make-overlay)
7684 (defalias 'message-delete-overlay 'delete-overlay)
7685 (defalias 'message-overlay-put 'overlay-put)
7686 (defun message-kill-all-overlays ()
7687 (if (featurep 'xemacs)
7688 (map-extents (lambda (extent ignore) (delete-extent extent)))
7689 (mapcar #'delete-overlay (overlays-in (point-min) (point-max)))))
7691 ;; Support for toolbar
7692 (defvar tool-bar-mode)
7694 ;; Note: The :set function in the `message-tool-bar*' variables will only
7695 ;; affect _new_ message buffers. We might add a function that walks thru all
7696 ;; message-mode buffers and force the update.
7697 (defun message-tool-bar-update (&optional symbol value)
7698 "Update message mode toolbar.
7699 Setter function for custom variables."
7700 (setq-default message-tool-bar-map nil)
7702 ;; When used as ":set" function:
7703 (set-default symbol value)))
7705 (defcustom message-tool-bar (if (eq gmm-tool-bar-style 'gnome)
7706 'message-tool-bar-gnome
7707 'message-tool-bar-retro)
7708 "Specifies the message mode tool bar.
7710 It can be either a list or a symbol refering to a list. See
7711 `gmm-tool-bar-from-list' for the format of the list. The
7712 default key map is `message-mode-map'.
7714 Pre-defined symbols include `message-tool-bar-gnome' and
7715 `message-tool-bar-retro'."
7716 :type '(repeat gmm-tool-bar-list-item)
7717 :type '(choice (const :tag "GNOME style" message-tool-bar-gnome)
7718 (const :tag "Retro look" message-tool-bar-retro)
7719 (repeat :tag "User defined list" gmm-tool-bar-item)
7721 :version "23.1" ;; No Gnus
7722 :initialize 'custom-initialize-default
7723 :set 'message-tool-bar-update
7726 (defcustom message-tool-bar-gnome
7727 '((ispell-message "spell" nil
7729 :visible (or (not (boundp 'flyspell-mode))
7730 (not flyspell-mode)))
7731 (flyspell-buffer "spell" t
7733 :visible (and (boundp 'flyspell-mode)
7735 :help "Flyspell whole buffer")
7736 (message-send-and-exit "mail/send" t :label "Send")
7737 (message-dont-send "mail/save-draft")
7738 (mml-attach-file "attach" mml-mode-map :vert-only t)
7739 (mml-preview "mail/preview" mml-mode-map)
7740 (mml-secure-message-sign-encrypt "lock" mml-mode-map :visible nil)
7741 (message-insert-importance-high "important" nil :visible nil)
7742 (message-insert-importance-low "unimportant" nil :visible nil)
7743 (message-insert-disposition-notification-to "receipt" nil :visible nil))
7744 "List of items for the message tool bar (GNOME style).
7746 See `gmm-tool-bar-from-list' for details on the format of the list."
7747 :type '(repeat gmm-tool-bar-item)
7748 :version "23.1" ;; No Gnus
7749 :initialize 'custom-initialize-default
7750 :set 'message-tool-bar-update
7753 (defcustom message-tool-bar-retro
7754 '(;; Old Emacs 21 icon for consistency.
7755 (message-send-and-exit "gnus/mail-send")
7756 (message-kill-buffer "close")
7757 (message-dont-send "cancel")
7758 (mml-attach-file "attach" mml-mode-map)
7759 (ispell-message "spell")
7760 (mml-preview "preview" mml-mode-map)
7761 (message-insert-importance-high "gnus/important")
7762 (message-insert-importance-low "gnus/unimportant")
7763 (message-insert-disposition-notification-to "gnus/receipt"))
7764 "List of items for the message tool bar (retro style).
7766 See `gmm-tool-bar-from-list' for details on the format of the list."
7767 :type '(repeat gmm-tool-bar-item)
7768 :version "23.1" ;; No Gnus
7769 :initialize 'custom-initialize-default
7770 :set 'message-tool-bar-update
7773 (defcustom message-tool-bar-zap-list
7774 '(new-file open-file dired kill-buffer write-file
7775 print-buffer customize help)
7776 "List of icon items from the global tool bar.
7777 These items are not displayed on the message mode tool bar.
7779 See `gmm-tool-bar-from-list' for the format of the list."
7780 :type 'gmm-tool-bar-zap-list
7781 :version "23.1" ;; No Gnus
7782 :initialize 'custom-initialize-default
7783 :set 'message-tool-bar-update
7786 (defvar image-load-path)
7788 (defun message-make-tool-bar (&optional force)
7789 "Make a message mode tool bar from `message-tool-bar-list'.
7790 When FORCE, rebuild the tool bar."
7791 (when (and (not (featurep 'xemacs))
7792 (boundp 'tool-bar-mode)
7794 (or (not message-tool-bar-map) force))
7795 (setq message-tool-bar-map
7797 (gmm-image-load-path-for-library "message"
7798 "mail/save-draft.xpm"
7800 (image-load-path (cons (car load-path)
7801 (when (boundp 'image-load-path)
7803 (gmm-tool-bar-from-list message-tool-bar
7804 message-tool-bar-zap-list
7805 'message-mode-map))))
7806 message-tool-bar-map)
7808 ;;; Group name completion.
7810 (defcustom message-newgroups-header-regexp
7811 "^\\(Newsgroups\\|Followup-To\\|Posted-To\\|Gcc\\):"
7812 "Regexp that match headers that lists groups."
7816 (defcustom message-completion-alist
7817 (list (cons message-newgroups-header-regexp 'message-expand-group)
7818 '("^\\(Resent-\\)?\\(To\\|B?Cc\\):" . message-expand-name)
7819 '("^\\(Reply-To\\|From\\|Mail-Followup-To\\|Mail-Copies-To\\):"
7820 . message-expand-name)
7821 '("^\\(Disposition-Notification-To\\|Return-Receipt-To\\):"
7822 . message-expand-name))
7823 "Alist of (RE . FUN). Use FUN for completion on header lines matching RE."
7826 :type '(alist :key-type regexp :value-type function))
7828 (defcustom message-expand-name-databases
7830 "List of databases to try for name completion (`message-expand-name').
7831 Each element is a symbol and can be `bbdb' or `eudc'."
7833 :type '(set (const bbdb) (const eudc)))
7835 (defcustom message-tab-body-function nil
7836 "*Function to execute when `message-tab' (TAB) is executed in the body.
7837 If nil, the function bound in `text-mode-map' or `global-map' is executed."
7840 :link '(custom-manual "(message)Various Commands")
7841 :type '(choice (const nil)
7844 (declare-function mail-abbrev-in-expansion-header-p "mailabbrev" ())
7846 (defun message-tab ()
7847 "Complete names according to `message-completion-alist'.
7848 Execute function specified by `message-tab-body-function' when not in
7852 ((if (and (boundp 'completion-fail-discreetly)
7853 (fboundp 'completion-at-point))
7854 (let ((completion-fail-discreetly t)) (completion-at-point))
7855 (funcall (or (message-completion-function) #'ignore)))
7856 ;; Completion was performed; nothing else to do.
7858 (message-tab-body-function (funcall message-tab-body-function))
7859 (t (funcall (or (lookup-key text-mode-map "\t")
7860 (lookup-key global-map "\t")
7861 'indent-relative)))))
7863 (defvar mail-abbrev-mode-regexp)
7865 (defun message-completion-function ()
7866 (let ((alist message-completion-alist))
7868 (let ((mail-abbrev-mode-regexp (caar alist)))
7869 (not (mail-abbrev-in-expansion-header-p))))
7870 (setq alist (cdr alist)))
7876 (let ((standard-output (current-buffer)))
7877 (eval '(display-completion-list nil "")))
7878 (defalias 'message-display-completion-list 'display-completion-list))
7879 (error ;; Don't use `wrong-number-of-arguments' here because of XEmacs.
7880 (defun message-display-completion-list (completions &optional ignore)
7881 "Display the list of completions, COMPLETIONS, using `standard-output'."
7882 (display-completion-list completions)))))
7884 (defun message-expand-group ()
7885 "Expand the group name under point."
7886 (let* ((b (save-excursion
7891 (skip-chars-forward "^:")
7894 (skip-chars-backward "^, \t\n") (point))))
7895 (completion-ignore-case t)
7896 (e (progn (skip-chars-forward "^,\t\n ") (point)))
7897 (hashtb (and (boundp 'gnus-active-hashtb) gnus-active-hashtb)))
7898 (message-completion-in-region e b hashtb)))
7900 (defalias 'message-completion-in-region
7901 (if (fboundp 'completion-in-region)
7902 'completion-in-region
7903 (lambda (e b hashtb)
7904 (let* ((string (buffer-substring b e))
7905 (completions (all-completions string hashtb))
7907 (delete-region b (point))
7909 ((= (length completions) 1)
7910 (if (string= (car completions) string)
7913 (message "Only matching group"))
7914 (insert (car completions))))
7915 ((and (setq comp (try-completion string hashtb))
7916 (not (string= comp string)))
7921 (message "No matching groups")
7922 (save-selected-window
7923 (pop-to-buffer "*Completions*")
7924 (buffer-disable-undo)
7925 (let ((buffer-read-only nil))
7927 (let ((standard-output (current-buffer)))
7928 (message-display-completion-list (sort completions 'string<)
7930 (setq buffer-read-only nil)
7931 (goto-char (point-min))
7932 (delete-region (point)
7933 (progn (forward-line 3) (point))))))))))))
7935 (defun message-expand-name ()
7936 (cond ((and (memq 'eudc message-expand-name-databases)
7937 (boundp 'eudc-protocol)
7939 (eudc-expand-inline))
7940 ((and (memq 'bbdb message-expand-name-databases)
7941 (fboundp 'bbdb-complete-name))
7942 (let ((starttick (buffer-modified-tick)))
7943 (or (bbdb-complete-name)
7944 ;; Apparently, bbdb-complete-name can return nil even when
7945 ;; completion took place. So let's double check the buffer was
7947 (/= starttick (buffer-modified-tick)))))
7953 (defun message-talkative-question (ask question show &rest text)
7954 "Call FUNCTION with argument QUESTION; optionally display TEXT... args.
7955 If SHOW is non-nil, the arguments TEXT... are displayed in a temp buffer.
7956 The following arguments may contain lists of values."
7958 (setq text (message-flatten-list text)))
7959 (save-window-excursion
7960 (with-output-to-temp-buffer " *MESSAGE information message*"
7961 (with-current-buffer " *MESSAGE information message*"
7962 (fundamental-mode) ; for Emacs 20.4+
7964 (goto-char (point-min))))
7965 (funcall ask question))
7966 (funcall ask question)))
7968 (defun message-flatten-list (list)
7969 "Return a new, flat list that contains all elements of LIST.
7971 \(message-flatten-list '(1 (2 3 (4 5 (6))) 7))
7974 (apply 'append (mapcar 'message-flatten-list list)))
7978 (defun message-generate-new-buffer-clone-locals (name &optional varstr)
7979 "Create and return a buffer with name based on NAME using `generate-new-buffer'.
7980 Then clone the local variables and values from the old buffer to the
7981 new one, cloning only the locals having a substring matching the
7983 (let ((oldbuf (current-buffer)))
7984 (with-current-buffer (generate-new-buffer name)
7985 (message-clone-locals oldbuf varstr)
7988 (defun message-clone-locals (buffer &optional varstr)
7989 "Clone the local variables from BUFFER to the current buffer."
7990 (let ((locals (with-current-buffer buffer (buffer-local-variables)))
7991 (regexp "^gnus\\|^nn\\|^message\\|^sendmail\\|^smtp\\|^user-mail-address"))
7994 (when (and (consp local)
7996 (string-match regexp (symbol-name (car local)))
7998 (string-match varstr (symbol-name (car local)))))
8000 (set (make-local-variable (car local))
8008 (defun message-encode-message-body ()
8009 (unless message-inhibit-body-encoding
8010 (let ((mail-parse-charset (or mail-parse-charset
8011 message-default-charset))
8012 (case-fold-search t)
8013 lines content-type-p)
8016 (narrow-to-region (point) (point-max))
8017 (let ((new (mml-generate-mime)))
8019 (delete-region (point-min) (point-max))
8021 (goto-char (point-min))
8022 (if (eq (aref new 0) ?\n)
8024 (search-forward "\n\n")
8025 (setq lines (buffer-substring (point-min) (1- (point))))
8026 (delete-region (point-min) (point))))))
8028 (message-narrow-to-headers-or-head)
8029 (message-remove-header "Mime-Version")
8030 (goto-char (point-max))
8031 (insert "MIME-Version: 1.0\n")
8034 (setq content-type-p
8036 (re-search-backward "^Content-Type:" nil t))))
8038 (message-narrow-to-headers-or-head)
8039 (message-remove-first-header "Content-Type")
8040 (message-remove-first-header "Content-Transfer-Encoding"))
8041 ;; We always make sure that the message has a Content-Type
8042 ;; header. This is because some broken MTAs and MUAs get
8043 ;; awfully confused when confronted with a message with a
8044 ;; MIME-Version header and without a Content-Type header. For
8045 ;; instance, Solaris' /usr/bin/mail.
8046 (unless content-type-p
8047 (goto-char (point-min))
8048 ;; For unknown reason, MIME-Version doesn't exist.
8049 (when (re-search-forward "^MIME-Version:" nil t)
8051 (insert "Content-Type: text/plain; charset=us-ascii\n"))))))
8053 (defun message-read-from-minibuffer (prompt &optional initial-contents)
8054 "Read from the minibuffer while providing abbrev expansion."
8055 (if (fboundp 'mail-abbrevs-setup)
8056 (let ((mail-abbrev-mode-regexp "")
8057 (minibuffer-setup-hook 'mail-abbrevs-setup)
8058 (minibuffer-local-map message-minibuffer-local-map))
8059 (read-from-minibuffer prompt initial-contents))
8060 (let ((minibuffer-setup-hook 'mail-abbrev-minibuffer-setup-hook)
8061 (minibuffer-local-map message-minibuffer-local-map))
8062 (read-string prompt initial-contents))))
8064 (defun message-use-alternative-email-as-from ()
8065 "Set From field of the outgoing message to the first matching
8066 address in `message-alternative-emails', looking at To, Cc and
8067 From headers in the original article."
8068 (require 'mail-utils)
8069 (let* ((fields '("To" "Cc" "From"))
8072 (mail-strip-quoted-names
8073 (mapconcat 'message-fetch-reply-field fields ","))
8077 (if (string-match message-alternative-emails (car emails))
8078 (setq email (car emails)
8081 (unless (or (not email) (equal email user-mail-address))
8082 (message-remove-header "From")
8083 (goto-char (point-max))
8084 (insert "From: " (let ((user-mail-address email)) (message-make-from))
8087 (defun message-options-get (symbol)
8088 (cdr (assq symbol message-options)))
8090 (defun message-options-set (symbol value)
8091 (let ((the-cons (assq symbol message-options)))
8094 (setcdr the-cons value)
8095 (setq message-options (delq the-cons message-options)))
8097 (push (cons symbol value) message-options))))
8100 (defun message-options-set-recipient ()
8102 (message-narrow-to-headers-or-head)
8103 (message-options-set 'message-sender
8104 (mail-strip-quoted-names
8105 (message-fetch-field "from")))
8106 (message-options-set 'message-recipients
8107 (mail-strip-quoted-names
8108 (let ((to (message-fetch-field "to"))
8109 (cc (message-fetch-field "cc"))
8110 (bcc (message-fetch-field "bcc")))
8113 (if (and to cc) ", ")
8115 (if (and (or to cc) bcc) ", ")
8118 (defun message-hide-headers ()
8119 "Hide headers based on the `message-hidden-headers' variable."
8120 (let ((regexps (if (stringp message-hidden-headers)
8121 (list message-hidden-headers)
8122 message-hidden-headers))
8123 (inhibit-point-motion-hooks t)
8124 (after-change-functions nil)
8125 (end-of-headers (point-min)))
8129 (message-narrow-to-headers)
8130 (goto-char (point-min))
8132 (if (not (message-hide-header-p regexps))
8133 (message-next-header)
8134 (let ((begin (point))
8136 (message-next-header)
8137 (setq header (buffer-substring begin (point))
8138 header-len (- (point) begin))
8139 (delete-region begin (point))
8140 (goto-char end-of-headers)
8142 (setq end-of-headers
8143 (+ end-of-headers header-len))))))))
8144 (narrow-to-region end-of-headers (point-max))))
8146 (defun message-hide-header-p (regexps)
8149 (when (eq (car regexps) 'not)
8152 (dolist (regexp regexps)
8153 (setq result (or result (looking-at regexp))))
8158 (declare-function ecomplete-add-item "ecomplete" (type key text))
8159 (declare-function ecomplete-save "ecomplete" ())
8161 (defun message-put-addresses-in-ecomplete ()
8162 (require 'ecomplete)
8163 (dolist (header '("to" "cc" "from" "reply-to"))
8164 (let ((value (message-field-value header)))
8165 (dolist (string (mail-header-parse-addresses value 'raw))
8167 (gnus-replace-in-string
8168 (gnus-replace-in-string string "^ +\\| +$" "") "\n" ""))
8169 (ecomplete-add-item 'mail (car (mail-header-parse-address string))
8173 (autoload 'ecomplete-display-matches "ecomplete")
8175 (defun message-display-abbrev (&optional choose)
8176 "Display the next possible abbrev for the text before point."
8177 (interactive (list t))
8178 (when (and (memq (char-after (point-at-bol)) '(?C ?T ?\t ? ))
8179 (message-point-in-header-p)
8182 (while (and (memq (char-after) '(?\t ? ))
8183 (zerop (forward-line -1))))
8184 (looking-at "To:\\|Cc:")))
8185 (let* ((end (point))
8186 (start (save-excursion
8187 (and (re-search-backward "[\n\t ]" nil t)
8189 (word (when start (buffer-substring start end)))
8190 (match (when (and word
8191 (not (zerop (length word))))
8192 (ecomplete-display-matches 'mail word choose))))
8193 (when (and choose match)
8194 (delete-region start end)
8197 ;; To send pre-formatted letters like the example below, you can use
8198 ;; `message-send-form-letter':
8199 ;; --8<---------------cut here---------------start------------->8---
8200 ;; To: alice@invalid.invalid
8201 ;; Subject: Verification of your contact information
8202 ;; From: Contact verification <admin@foo.invalid>
8203 ;; --text follows this line--
8205 ;; please verify that your contact information is still valid:
8206 ;; Alice A, A avenue 11, 1111 A town, Austria
8207 ;; ----------next form letter message follows this line----------
8208 ;; To: bob@invalid.invalid
8209 ;; Subject: Verification of your contact information
8210 ;; From: Contact verification <admin@foo.invalid>
8211 ;; --text follows this line--
8213 ;; please verify that your contact information is still valid:
8214 ;; Bob, B street 22, 22222 Be town, Belgium
8215 ;; ----------next form letter message follows this line----------
8216 ;; To: charlie@invalid.invalid
8217 ;; Subject: Verification of your contact information
8218 ;; From: Contact verification <admin@foo.invalid>
8219 ;; --text follows this line--
8221 ;; please verify that your contact information is still valid:
8222 ;; Charlie Chaplin, C plaza 33, 33333 C town, Chile
8223 ;; --8<---------------cut here---------------end--------------->8---
8225 ;; FIXME: What is the most common term (circular letter, form letter, serial
8226 ;; letter, standard letter) for such kind of letter? See also
8227 ;; <http://en.wikipedia.org/wiki/Form_letter>
8229 ;; FIXME: Maybe extent message-mode's font-lock support to recognize
8230 ;; `message-form-letter-separator', i.e. highlight each message like a single
8233 (defcustom message-form-letter-separator
8234 "\n----------next form letter message follows this line----------\n"
8235 "Separator for `message-send-form-letter'."
8236 ;; :group 'message-form-letter
8237 :group 'message-various
8238 :version "23.1" ;; No Gnus
8241 (defcustom message-send-form-letter-delay 1
8242 "Delay in seconds when sending a message with `message-send-form-letter'.
8243 Only used when `message-send-form-letter' is called with non-nil
8245 ;; :group 'message-form-letter
8246 :group 'message-various
8247 :version "23.1" ;; No Gnus
8250 (defun message-send-form-letter (&optional force)
8251 "Sent all form letter messages from current buffer.
8252 Unless FORCE, prompt before sending.
8254 The messages are separated by `message-form-letter-separator'.
8255 Header and body are separated by `mail-header-separator'."
8257 (let ((sent 0) (skipped 0)
8261 (goto-char (point-min))
8264 end (if (search-forward message-form-letter-separator nil t)
8265 (- (point) (length message-form-letter-separator) -1)
8269 (buffer-substring-no-properties start end))
8270 (setq buff (generate-new-buffer "*mail - form letter*"))
8271 (with-current-buffer buff
8274 (setq to (message-fetch-field "To"))
8275 (switch-to-buffer buff)
8277 (sit-for message-send-form-letter-delay))
8279 (y-or-n-p (format "Send message to `%s'? " to)))
8281 (setq sent (1+ sent))
8282 (message-send-and-exit))
8283 (message (format "Message to `%s' skipped." to))
8284 (setq skipped (1+ skipped)))
8285 (when (buffer-live-p buff)
8286 (kill-buffer buff))))
8287 (message "%s message(s) sent, %s skipped." sent skipped)))
8289 (defun message-replace-header (header new-value &optional after force)
8290 "Remove HEADER and insert the NEW-VALUE.
8291 If AFTER, insert after this header. If FORCE, insert new field
8292 even if NEW-VALUE is empty."
8293 ;; Similar to `nnheader-replace-header' but for message buffers.
8296 (message-narrow-to-headers)
8297 (message-remove-header header))
8298 (when (or force (> (length new-value) 0))
8300 (message-position-on-field header after)
8301 (message-position-on-field header))
8302 (insert new-value))))
8304 (defcustom message-recipients-without-full-name
8305 (list "ding@gnus.org"
8307 "emacs-devel@gnu.org"
8308 "emacs-pretest-bug@gnu.org"
8309 "bug-gnu-emacs@gnu.org")
8310 "Mail addresses that have no full name.
8311 Used in `message-simplify-recipients'."
8312 ;; Maybe the addresses could be extracted from
8313 ;; `gnus-parameter-to-list-alist'?
8314 :type '(choice (const :tag "None" nil)
8316 :version "23.1" ;; No Gnus
8317 :group 'message-headers)
8319 (defun message-simplify-recipients ()
8321 (dolist (hdr '("Cc" "To"))
8322 (message-replace-header
8326 (if (and message-recipients-without-full-name
8328 (regexp-opt message-recipients-without-full-name)
8332 (message-make-from (car addrcomp) (cadr addrcomp))
8334 (when (message-fetch-field hdr)
8335 (mail-extract-address-components
8336 (message-fetch-field hdr) t))
8339 (when (featurep 'xemacs)
8340 (require 'messagexmas)
8341 (message-xmas-redefine))
8345 (run-hooks 'message-load-hook)
8348 ;; coding: iso-8859-1
8351 ;;; message.el ends here