1 ;;; message.el --- composing mail and news messages
3 ;; Copyright (C) 1996-2016 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.
37 ;; Only for the trivial macros mail-header-from, mail-header-date
38 ;; mail-header-references, mail-header-subject, mail-header-id
39 (eval-when-compile (require 'nnheader))
40 ;; This is apparently necessary even though things are autoloaded.
41 ;; Because we dynamically bind mail-abbrev-mode-regexp, we'd better
42 ;; require mailabbrev here.
47 (require 'format-spec)
52 (autoload 'mailclient-send-it "mailclient") ;; Emacs 22 or contrib/
54 (defvar gnus-message-group-art)
55 (defvar gnus-list-identifiers) ; gnus-sum is required where necessary
56 (defvar rmail-enable-mime-composing)
58 (defgroup message '((user-mail-address custom-variable)
59 (user-full-name custom-variable))
60 "Mail and news message composing."
61 :link '(custom-manual "(message)Top")
65 (put 'user-mail-address 'custom-type 'string)
66 (put 'user-full-name 'custom-type 'string)
68 (defgroup message-various nil
69 "Various Message Variables."
70 :link '(custom-manual "(message)Various Message Variables")
73 (defgroup message-buffers nil
75 :link '(custom-manual "(message)Message Buffers")
78 (defgroup message-sending nil
80 :link '(custom-manual "(message)Sending Variables")
83 (defgroup message-interface nil
85 :link '(custom-manual "(message)Interface")
88 (defgroup message-forwarding nil
90 :link '(custom-manual "(message)Forwarding")
91 :group 'message-interface)
93 (defgroup message-insertion nil
95 :link '(custom-manual "(message)Insertion")
98 (defgroup message-headers nil
100 :link '(custom-manual "(message)Message Headers")
103 (defgroup message-news nil
104 "Composing News Messages."
107 (defgroup message-mail nil
108 "Composing Mail Messages."
111 (defgroup message-faces nil
112 "Faces used for message composing."
116 (defcustom message-directory "~/Mail/"
117 "*Directory from which all other mail file variables are derived."
118 :group 'message-various
121 (defcustom message-max-buffers 10
122 "*How many buffers to keep before starting to kill them off."
123 :group 'message-buffers
126 (defcustom message-send-rename-function nil
127 "Function called to rename the buffer after sending it."
128 :group 'message-buffers
129 :type '(choice function (const nil)))
131 (defcustom message-fcc-handler-function 'message-output
132 "*A function called to save outgoing articles.
133 This function will be called with the name of the file to store the
134 article in. The default function is `message-output' which saves in Unix
136 :type '(radio (function-item message-output)
137 (function :tag "Other"))
138 :group 'message-sending)
140 (defcustom message-fcc-externalize-attachments nil
141 "If non-nil, attachments are included as external parts in Fcc copies."
144 :group 'message-sending)
146 (defcustom message-courtesy-message
147 "The following message is a courtesy copy of an article\nthat has been posted to %s as well.\n\n"
148 "*This is inserted at the start of a mailed copy of a posted message.
149 If the string contains the format spec \"%s\", the Newsgroups
150 the article has been posted to will be inserted there.
151 If this variable is nil, no such courtesy message will be added."
152 :group 'message-sending
153 :type '(radio string (const nil)))
155 (defcustom message-ignored-bounced-headers
156 "^\\(Received\\|Return-Path\\|Delivered-To\\):"
157 "*Regexp that matches headers to be removed in resent bounced mail."
158 :group 'message-interface
161 (defcustom message-from-style mail-from-style
162 "Specifies how \"From\" headers look.
164 If nil, they contain just the return address like:
166 If `parens', they look like:
167 king@grassland.com (Elvis Parsley)
168 If `angles', they look like:
169 Elvis Parsley <king@grassland.com>
171 Otherwise, most addresses look like `angles', but they look like
172 `parens' if `angles' would need quoting and `parens' would not."
174 :type '(choice (const :tag "simple" nil)
178 :group 'message-headers)
180 (defcustom message-insert-canlock t
181 "Whether to insert a Cancel-Lock header in news postings."
183 :group 'message-headers
186 (defcustom message-syntax-checks
187 (if message-insert-canlock '((sender . disabled)) nil)
188 ;; Guess this one shouldn't be easy to customize...
189 "*Controls what syntax checks should not be performed on outgoing posts.
190 To disable checking of long signatures, for instance, add
191 `(signature . disabled)' to this list.
193 Don't touch this variable unless you really know what you're doing.
195 Checks include `approved', `bogus-recipient', `continuation-headers',
196 `control-chars', `empty', `existing-newsgroups', `from', `illegible-text',
197 `invisible-text', `long-header-lines', `long-lines', `message-id',
198 `multiple-headers', `new-text', `newsgroups', `quoting-style',
199 `repeated-newsgroups', `reply-to', `sender', `sendsys', `shoot',
200 `shorten-followup-to', `signature', `size', `subject', `subject-cmsg'
201 and `valid-newsgroups'."
203 :type '(repeat sexp)) ; Fixme: improve this
205 (defcustom message-required-headers '((optional . References)
207 "*Headers to be generated or prompted for when sending a message.
208 Also see `message-required-news-headers' and
209 `message-required-mail-headers'."
212 :group 'message-headers
213 :link '(custom-manual "(message)Message Headers")
214 :type '(repeat sexp))
216 (defcustom message-draft-headers '(References From Date)
217 "*Headers to be generated when saving a draft message."
220 :group 'message-headers
221 :link '(custom-manual "(message)Message Headers")
222 :type '(repeat sexp))
224 (defcustom message-required-news-headers
225 '(From Newsgroups Subject Date Message-ID
226 (optional . Organization)
227 (optional . User-Agent))
228 "*Headers to be generated or prompted for when posting an article.
229 RFC977 and RFC1036 require From, Date, Newsgroups, Subject,
230 Message-ID. Organization, Lines, In-Reply-To, Expires, and
231 User-Agent are optional. If you don't want message to insert some
232 header, remove it from this list."
234 :group 'message-headers
235 :link '(custom-manual "(message)Message Headers")
236 :type '(repeat sexp))
238 (defcustom message-required-mail-headers
239 '(From Subject Date (optional . In-Reply-To) Message-ID
240 (optional . User-Agent))
241 "*Headers to be generated or prompted for when mailing a message.
242 It is recommended that From, Date, To, Subject and Message-ID be
243 included. Organization and User-Agent are optional."
245 :group 'message-headers
246 :link '(custom-manual "(message)Message Headers")
247 :type '(repeat sexp))
249 (defcustom message-prune-recipient-rules nil
250 "Rules for how to prune the list of recipients when doing wide replies.
251 This is a list of regexps and regexp matches."
254 :group 'message-headers
255 :link '(custom-manual "(message)Wide Reply")
256 :type '(repeat regexp))
258 (defcustom message-deletable-headers '(Message-ID Date Lines)
259 "Headers to delete if present and previously generated by message."
260 :group 'message-headers
261 :link '(custom-manual "(message)Message Headers")
262 :type '(repeat (symbol :tag "Header")))
264 (defcustom message-ignored-news-headers
265 "^NNTP-Posting-Host:\\|^Xref:\\|^[BGF]cc:\\|^Resent-Fcc:\\|^X-Draft-From:\\|^X-Gnus-Agent-Meta-Information:\\|^X-Message-SMTP-Method:\\|^X-Gnus-Delayed:"
266 "*Regexp of headers to be removed unconditionally before posting."
268 :group 'message-headers
269 :link '(custom-manual "(message)Message Headers")
270 :type '(repeat :value-to-internal (lambda (widget value)
271 (custom-split-regexp-maybe value))
272 :match (lambda (widget value)
274 (widget-editable-list-match widget value)))
277 (defcustom message-ignored-mail-headers
278 "^\\([GF]cc\\|Resent-Fcc\\|Xref\\|X-Draft-From\\|X-Gnus-Agent-Meta-Information\\):"
279 "*Regexp of headers to be removed unconditionally before mailing."
281 :group 'message-headers
282 :link '(custom-manual "(message)Mail Headers")
285 (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:"
286 "*Header lines matching this regexp will be deleted before posting.
287 It's best to delete old Path and Date headers before posting to avoid
289 :group 'message-interface
290 :link '(custom-manual "(message)Superseding")
291 :type '(repeat :value-to-internal (lambda (widget value)
292 (custom-split-regexp-maybe value))
293 :match (lambda (widget value)
295 (widget-editable-list-match widget value)))
298 (defcustom message-subject-re-regexp
299 "^[ \t]*\\([Rr][Ee]\\(\\[[0-9]*\\]\\)* ?:[ \t]*\\)*[ \t]*"
300 "*Regexp matching \"Re: \" in the subject line."
301 :group 'message-various
302 :link '(custom-manual "(message)Message Headers")
305 ;;; Start of variables adopted from `message-utils.el'.
307 (defcustom message-subject-trailing-was-query t
308 "*What to do with trailing \"(was: <old subject>)\" in subject lines.
309 If nil, leave the subject unchanged. If it is the symbol `ask', query
310 the user what do do. In this case, the subject is matched against
311 `message-subject-trailing-was-ask-regexp'. If
312 `message-subject-trailing-was-query' is t, always strip the trailing
313 old subject. In this case, `message-subject-trailing-was-regexp' is
316 :type '(choice (const :tag "never" nil)
317 (const :tag "always strip" t)
319 :link '(custom-manual "(message)Message Headers")
320 :group 'message-various)
322 (defcustom message-subject-trailing-was-ask-regexp
323 "[ \t]*\\([[(]+[Ww][Aa][Ss]:?[ \t]*.*[])]+\\)"
324 "*Regexp matching \"(was: <old subject>)\" in the subject line.
326 The function `message-strip-subject-trailing-was' uses this regexp if
327 `message-subject-trailing-was-query' is set to the symbol `ask'. If
328 the variable is t instead of `ask', use
329 `message-subject-trailing-was-regexp' instead.
331 It is okay to create some false positives here, as the user is asked."
333 :group 'message-various
334 :link '(custom-manual "(message)Message Headers")
337 (defcustom message-subject-trailing-was-regexp
338 "[ \t]*\\((*[Ww][Aa][Ss]:[ \t]*.*)\\)"
339 "*Regexp matching \"(was: <old subject>)\" in the subject line.
341 If `message-subject-trailing-was-query' is set to t, the subject is
342 matched against `message-subject-trailing-was-regexp' in
343 `message-strip-subject-trailing-was'. You should use a regexp creating very
344 few false positives here."
346 :group 'message-various
347 :link '(custom-manual "(message)Message Headers")
350 ;;; marking inserted text
352 (defcustom message-mark-insert-begin
353 "--8<---------------cut here---------------start------------->8---\n"
354 "How to mark the beginning of some inserted text."
357 :link '(custom-manual "(message)Insertion Variables")
358 :group 'message-various)
360 (defcustom message-mark-insert-end
361 "--8<---------------cut here---------------end--------------->8---\n"
362 "How to mark the end of some inserted text."
365 :link '(custom-manual "(message)Insertion Variables")
366 :group 'message-various)
368 (defcustom message-archive-header "X-No-Archive: Yes\n"
369 "Header to insert when you don't want your article to be archived.
370 Archives \(such as groups.google.com) respect this header."
373 :link '(custom-manual "(message)Header Commands")
374 :group 'message-various)
376 (defcustom message-archive-note
377 "X-No-Archive: Yes - save http://groups.google.com/"
378 "Note to insert why you wouldn't want this posting archived.
379 If nil, don't insert any text in the body."
381 :type '(radio string (const nil))
382 :link '(custom-manual "(message)Header Commands")
383 :group 'message-various)
385 ;;; Crossposts and Followups
386 ;; inspired by JoH-followup-to by Jochem Huhman <joh at gmx.de>
387 ;; new suggestions by R. Weikusat <rw at another.de>
389 (defvar message-cross-post-old-target nil
390 "Old target for cross-posts or follow-ups.")
391 (make-variable-buffer-local 'message-cross-post-old-target)
393 (defcustom message-cross-post-default t
394 "When non-nil `message-cross-post-followup-to' will perform a crosspost.
395 If nil, `message-cross-post-followup-to' will only do a followup. Note that
396 you can explicitly override this setting by calling
397 `message-cross-post-followup-to' with a prefix."
400 :group 'message-various)
402 (defcustom message-cross-post-note "Crosspost & Followup-To: "
403 "Note to insert before signature to notify of cross-post and follow-up."
406 :group 'message-various)
408 (defcustom message-followup-to-note "Followup-To: "
409 "Note to insert before signature to notify of follow-up only."
412 :group 'message-various)
414 (defcustom message-cross-post-note-function 'message-cross-post-insert-note
415 "Function to use to insert note about Crosspost or Followup-To.
416 The function will be called with four arguments. The function should not only
417 insert a note, but also ensure old notes are deleted. See the documentation
418 for `message-cross-post-insert-note'."
421 :group 'message-various)
423 ;;; End of variables adopted from `message-utils.el'.
425 (defcustom message-signature-separator "^-- $"
426 "Regexp matching the signature separator.
427 This variable is used to strip off the signature from quoted text
428 when `message-cite-function' is
429 `message-cite-original-without-signature'. Most useful values
430 are \"^-- $\" (strict) and \"^-- *$\" (loose; allow missing
432 :type '(choice (const :tag "strict" "^-- $")
433 (const :tag "loose" "^-- *$")
435 :version "22.3" ;; Gnus 5.10.12 (changed default)
436 :link '(custom-manual "(message)Various Message Variables")
437 :group 'message-various)
439 (defcustom message-elide-ellipsis "\n[...]\n\n"
440 "*The string which is inserted for elided text.
441 This is a format-spec string, and you can use %l to say how many
442 lines were removed, and %c to say how many characters were
445 :link '(custom-manual "(message)Various Commands")
446 :group 'message-various)
448 (defcustom message-interactive mail-interactive
449 "Non-nil means when sending a message wait for and display errors.
450 A value of nil means let mailer mail back a message to report errors."
452 :group 'message-sending
454 :link '(custom-manual "(message)Sending Variables")
457 (defcustom message-confirm-send nil
458 "When non-nil, ask for confirmation when sending a message."
459 :group 'message-sending
461 :version "23.1" ;; No Gnus
462 :link '(custom-manual "(message)Sending Variables")
465 (defcustom message-generate-new-buffers 'unsent
466 "*Say whether to create a new message buffer to compose a message.
467 Valid values include:
470 Generate the buffer name in the Message way (e.g., *mail*, *news*,
471 *mail to whom*, *news on group*, etc.) and continue editing in the
472 existing buffer of that name. If there is no such buffer, it will
476 Create the new buffer with the name generated in the Message way.
479 Similar to `unique' but the buffer name begins with \"*unsent \".
482 Similar to nil but the buffer name is simpler like *mail message*.
485 If this is a function, call that function with three parameters:
486 The type, the To address and the group name (any of these may be nil).
487 The function should return the new buffer name."
489 :group 'message-buffers
490 :link '(custom-manual "(message)Message Buffers")
491 :type '(choice (const nil)
492 (sexp :tag "unique" :format "unique\n" :value unique
493 :match (lambda (widget value) (memq value '(unique t))))
496 (function :format "\n %{%t%}: %v")))
498 (defcustom message-kill-buffer-on-exit nil
499 "*Non-nil means that the message buffer will be killed after sending a message."
500 :group 'message-buffers
501 :link '(custom-manual "(message)Message Buffers")
504 (defcustom message-kill-buffer-query t
505 "*Non-nil means that killing a modified message buffer has to be confirmed.
506 This is used by `message-kill-buffer'."
507 :version "23.1" ;; No Gnus
508 :group 'message-buffers
511 (defcustom message-user-organization
512 (or (getenv "ORGANIZATION") t)
513 "String to be used as an Organization header.
514 If t, use `message-user-organization-file'."
515 :group 'message-headers
516 :type '(choice string
517 (const :tag "consult file" t)))
519 (defcustom message-user-organization-file
521 (dolist (f (list "/etc/organization"
522 "/etc/news/organization"
523 "/usr/lib/news/organization"))
524 (when (file-readable-p f)
527 "*Local news organization file."
528 :type '(choice (const nil) file)
529 :link '(custom-manual "(message)News Headers")
530 :group 'message-headers)
532 (defcustom message-make-forward-subject-function
533 #'message-forward-subject-name-subject
534 "*List of functions called to generate subject headers for forwarded messages.
535 The subject generated by the previous function is passed into each
538 The provided functions are:
540 * `message-forward-subject-author-subject' Source of article (author or
541 newsgroup), in brackets followed by the subject
542 * `message-forward-subject-name-subject' Source of article (name of author
543 or newsgroup), in brackets followed by the subject
544 * `message-forward-subject-fwd' Subject of article with `Fwd:' prepended
546 :group 'message-forwarding
547 :link '(custom-manual "(message)Forwarding")
548 :type '(radio (function-item message-forward-subject-author-subject)
549 (function-item message-forward-subject-fwd)
550 (function-item message-forward-subject-name-subject)
551 (repeat :tag "List of functions" function)))
553 (defcustom message-forward-as-mime t
554 "*Non-nil means forward messages as an inline/rfc822 MIME section.
555 Otherwise, directly inline the old message in the forwarded message."
557 :group 'message-forwarding
558 :link '(custom-manual "(message)Forwarding")
561 (defcustom message-forward-show-mml 'best
562 "*Non-nil means show forwarded messages as MML (decoded from MIME).
563 Otherwise, forwarded messages are unchanged.
564 Can also be the symbol `best' to indicate that MML should be
565 used, except when it is a bad idea to use MML. One example where
566 it is a bad idea is when forwarding a signed or encrypted
567 message, because converting MIME to MML would invalidate the
570 :group 'message-forwarding
571 :type '(choice (const :tag "use MML" t)
572 (const :tag "don't use MML " nil)
573 (const :tag "use MML when appropriate" best)))
575 (defcustom message-forward-before-signature t
576 "*Non-nil means put forwarded message before signature, else after."
577 :group 'message-forwarding
580 (defcustom message-wash-forwarded-subjects nil
581 "*Non-nil means try to remove as much cruft as possible from the subject.
582 Done before generating the new subject of a forward."
583 :group 'message-forwarding
584 :link '(custom-manual "(message)Forwarding")
587 (defcustom message-ignored-resent-headers
588 ;; `Delivered-To' needs to be removed because some mailers use it to
589 ;; detect loops, so if you resend a message to an address that ultimately
590 ;; comes back to you (e.g. a mailing-list to which you subscribe, in which
591 ;; case you may be removed from the list on the grounds that mail to you
592 ;; bounced with a "mailing loop" error).
593 "^Return-receipt\\|^X-Gnus\\|^Gnus-Warning:\\|^>?From \\|^Delivered-To:\
594 \\|^X-Content-Length:\\|^X-UIDL:"
595 "*All headers that match this regexp will be deleted when resending a message."
597 :group 'message-interface
598 :link '(custom-manual "(message)Resending")
599 :type '(repeat :value-to-internal (lambda (widget value)
600 (custom-split-regexp-maybe value))
601 :match (lambda (widget value)
603 (widget-editable-list-match widget value)))
606 (defcustom message-forward-ignored-headers "^Content-Transfer-Encoding:\\|^X-Gnus"
607 "*All headers that match this regexp will be deleted when forwarding a message.
608 This may also be a list of regexps."
610 :group 'message-forwarding
611 :type '(repeat :value-to-internal (lambda (widget value)
612 (custom-split-regexp-maybe value))
613 :match (lambda (widget value)
615 (widget-editable-list-match widget value)))
618 (defcustom message-forward-included-headers nil
619 "If non-nil, delete non-matching headers when forwarding a message.
620 Only headers that match this regexp will be included. This
621 variable should be a regexp or a list of regexps."
623 :group 'message-forwarding
624 :type '(repeat :value-to-internal (lambda (widget value)
625 (custom-split-regexp-maybe value))
626 :match (lambda (widget value)
628 (widget-editable-list-match widget value)))
631 (defcustom message-ignored-cited-headers "."
632 "*Delete these headers from the messages you yank."
633 :group 'message-insertion
634 :link '(custom-manual "(message)Insertion Variables")
637 (defcustom message-cite-prefix-regexp mail-citation-prefix-regexp
638 "*Regexp matching the longest possible citation prefix on a line."
640 :group 'message-insertion
641 :link '(custom-manual "(message)Insertion Variables")
643 :set (lambda (symbol value)
645 (custom-set-default symbol value)
646 (if (boundp 'gnus-message-cite-prefix-regexp)
647 (setq gnus-message-cite-prefix-regexp
648 (concat "^\\(?:" value "\\)"))))))
650 (defcustom message-cancel-message "I am canceling my own article.\n"
651 "Message to be inserted in the cancel message."
652 :group 'message-interface
653 :link '(custom-manual "(message)Canceling News")
656 (defun message-send-mail-function ()
657 "Return suitable value for the variable `message-send-mail-function'."
658 (cond ((and (require 'sendmail)
659 (boundp 'sendmail-program)
661 (executable-find sendmail-program))
662 'message-send-mail-with-sendmail)
663 ((and (locate-library "smtpmail")
664 (boundp 'smtpmail-default-smtp-server)
665 smtpmail-default-smtp-server)
666 'message-smtpmail-send-it)
667 ((locate-library "mailclient")
668 'message-send-mail-with-mailclient)
670 (error "Don't know how to send mail. Please customize `message-send-mail-function'"))))
672 (defun message-default-send-mail-function ()
673 (cond ((eq send-mail-function 'smtpmail-send-it) 'message-smtpmail-send-it)
674 ((eq send-mail-function 'feedmail-send-it) 'feedmail-send-it)
675 ((eq send-mail-function 'sendmail-query-once) 'sendmail-query-once)
676 ((eq send-mail-function 'mailclient-send-it)
677 'message-send-mail-with-mailclient)
678 (t (message-send-mail-function))))
680 ;; Useful to set in site-init.el
681 (defcustom message-send-mail-function (message-default-send-mail-function)
682 "Function to call to send the current buffer as mail.
683 The headers should be delimited by a line whose contents match the
684 variable `mail-header-separator'.
686 Valid values include `message-send-mail-with-sendmail'
687 `message-send-mail-with-mh', `message-send-mail-with-qmail',
688 `message-smtpmail-send-it', `smtpmail-send-it',
689 `feedmail-send-it' and `message-send-mail-with-mailclient'. The
690 default is system dependent and determined by the function
691 `message-send-mail-function'.
693 See also `send-mail-function'."
694 :type '(radio (function-item message-send-mail-with-sendmail)
695 (function-item message-send-mail-with-mh)
696 (function-item message-send-mail-with-qmail)
697 (function-item message-smtpmail-send-it)
698 (function-item smtpmail-send-it)
699 (function-item feedmail-send-it)
700 (function-item message-send-mail-with-mailclient
701 :tag "Use Mailclient package")
702 (function :tag "Other"))
703 :group 'message-sending
705 :initialize 'custom-initialize-default
706 :link '(custom-manual "(message)Mail Variables")
707 :group 'message-mail)
709 (defcustom message-send-news-function 'message-send-news
710 "Function to call to send the current buffer as news.
711 The headers should be delimited by a line whose contents match the
712 variable `mail-header-separator'."
713 :group 'message-sending
715 :link '(custom-manual "(message)News Variables")
718 (defcustom message-reply-to-function nil
719 "If non-nil, function that should return a list of headers.
720 This function should pick out addresses from the To, Cc, and From headers
721 and respond with new To and Cc headers."
722 :group 'message-interface
723 :link '(custom-manual "(message)Reply")
724 :type '(choice function (const nil)))
726 (defcustom message-wide-reply-to-function nil
727 "If non-nil, function that should return a list of headers.
728 This function should pick out addresses from the To, Cc, and From headers
729 and respond with new To and Cc headers."
730 :group 'message-interface
731 :link '(custom-manual "(message)Wide Reply")
732 :type '(choice function (const nil)))
734 (defcustom message-followup-to-function nil
735 "If non-nil, function that should return a list of headers.
736 This function should pick out addresses from the To, Cc, and From headers
737 and respond with new To and Cc headers."
738 :group 'message-interface
739 :link '(custom-manual "(message)Followup")
740 :type '(choice function (const nil)))
742 (defcustom message-extra-wide-headers nil
743 "If non-nil, a list of additional address headers.
744 These are used when composing a wide reply."
745 :group 'message-sending
746 :type '(repeat string))
748 (defcustom message-use-followup-to 'ask
749 "*Specifies what to do with Followup-To header.
750 If nil, always ignore the header. If it is t, use its value, but
751 query before using the \"poster\" value. If it is the symbol `ask',
752 always query the user whether to use the value. If it is the symbol
753 `use', always use the value."
754 :group 'message-interface
755 :link '(custom-manual "(message)Followup")
756 :type '(choice (const :tag "ignore" nil)
757 (const :tag "use & query" t)
761 (defcustom message-use-mail-followup-to 'use
762 "*Specifies what to do with Mail-Followup-To header.
763 If nil, always ignore the header. If it is the symbol `ask', always
764 query the user whether to use the value. If it is the symbol `use',
765 always use the value."
767 :group 'message-interface
768 :link '(custom-manual "(message)Mailing Lists")
769 :type '(choice (const :tag "ignore" nil)
773 (defcustom message-subscribed-address-functions nil
774 "*Specifies functions for determining list subscription.
775 If nil, do not attempt to determine list subscription with functions.
776 If non-nil, this variable contains a list of functions which return
777 regular expressions to match lists. These functions can be used in
778 conjunction with `message-subscribed-regexps' and
779 `message-subscribed-addresses'."
781 :group 'message-interface
782 :link '(custom-manual "(message)Mailing Lists")
783 :type '(repeat sexp))
785 (defcustom message-subscribed-address-file nil
786 "*A file containing addresses the user is subscribed to.
787 If nil, do not look at any files to determine list subscriptions. If
788 non-nil, each line of this file should be a mailing list address."
790 :group 'message-interface
791 :link '(custom-manual "(message)Mailing Lists")
792 :type '(radio file (const nil)))
794 (defcustom message-subscribed-addresses nil
795 "*Specifies a list of addresses the user is subscribed to.
796 If nil, do not use any predefined list subscriptions. This list of
797 addresses can be used in conjunction with
798 `message-subscribed-address-functions' and `message-subscribed-regexps'."
800 :group 'message-interface
801 :link '(custom-manual "(message)Mailing Lists")
802 :type '(repeat string))
804 (defcustom message-subscribed-regexps nil
805 "*Specifies a list of addresses the user is subscribed to.
806 If nil, do not use any predefined list subscriptions. This list of
807 regular expressions can be used in conjunction with
808 `message-subscribed-address-functions' and `message-subscribed-addresses'."
810 :group 'message-interface
811 :link '(custom-manual "(message)Mailing Lists")
812 :type '(repeat regexp))
814 (defcustom message-allow-no-recipients 'ask
815 "Specifies what to do when there are no recipients other than Gcc/Fcc.
816 If it is the symbol `always', the posting is allowed. If it is the
817 symbol `never', the posting is not allowed. If it is the symbol
818 `ask', you are prompted."
820 :group 'message-interface
821 :link '(custom-manual "(message)Message Headers")
822 :type '(choice (const always)
826 (defcustom message-sendmail-f-is-evil nil
827 "*Non-nil means don't add \"-f username\" to the sendmail command line.
828 Doing so would be even more evil than leaving it out."
829 :group 'message-sending
830 :link '(custom-manual "(message)Mail Variables")
833 (defcustom message-sendmail-envelope-from
834 ;; `mail-envelope-from' is unavailable unless sendmail.el is loaded.
835 (if (boundp 'mail-envelope-from) mail-envelope-from)
836 "*Envelope-from when sending mail with sendmail.
837 If this is nil, use `user-mail-address'. If it is the symbol
838 `header', use the From: header of the message."
840 :type '(choice (string :tag "From name")
841 (const :tag "Use From: header from message" header)
842 (const :tag "Use `user-mail-address'" nil))
843 :link '(custom-manual "(message)Mail Variables")
844 :group 'message-sending)
846 (defcustom message-sendmail-extra-arguments nil
847 "Additional arguments to `sendmail-program'."
848 ;; E.g. '("-a" "account") for msmtp
849 :version "23.1" ;; No Gnus
850 :type '(repeat string)
851 ;; :link '(custom-manual "(message)Mail Variables")
852 :group 'message-sending)
854 ;; qmail-related stuff
855 (defcustom message-qmail-inject-program "/var/qmail/bin/qmail-inject"
856 "Location of the qmail-inject program."
857 :group 'message-sending
858 :link '(custom-manual "(message)Mail Variables")
861 (defcustom message-qmail-inject-args nil
862 "Arguments passed to qmail-inject programs.
863 This should be a list of strings, one string for each argument.
864 It may also be a function.
866 For e.g., if you wish to set the envelope sender address so that bounces
867 go to the right place or to deal with listserv's usage of that address, you
868 might set this variable to (\"-f\" \"you@some.where\")."
869 :group 'message-sending
870 :link '(custom-manual "(message)Mail Variables")
871 :type '(choice (function)
874 (defvar gnus-post-method)
875 (defvar gnus-select-method)
876 (defcustom message-post-method
877 (cond ((and (boundp 'gnus-post-method)
878 (listp gnus-post-method)
881 ((boundp 'gnus-select-method)
884 "*Method used to post news.
885 Note that when posting from inside Gnus, for instance, this
886 variable isn't used."
888 :group 'message-sending
889 ;; This should be the `gnus-select-method' widget, but that might
890 ;; create a dependence to `gnus.el'.
893 (defcustom message-generate-headers-first nil
894 "Which headers should be generated before starting to compose a message.
895 If t, generate all required headers. This can also be a list of headers to
896 generate. The variables `message-required-news-headers' and
897 `message-required-mail-headers' specify which headers to generate.
899 Note that the variable `message-deletable-headers' specifies headers which
900 are to be deleted and then re-generated before sending, so this variable
901 will not have a visible effect for those headers."
902 :group 'message-headers
903 :link '(custom-manual "(message)Message Headers")
904 :type '(choice (const :tag "None" nil)
906 (repeat (sexp :tag "Header"))))
908 (defcustom message-fill-column 72
909 "Column beyond which automatic line-wrapping should happen.
910 Local value for message buffers. If non-nil, also turn on
911 auto-fill in message buffers."
912 :group 'message-various
913 ;; :link '(custom-manual "(message)Message Headers")
914 :type '(choice (const :tag "Don't turn on auto fill" nil)
917 (defcustom message-setup-hook nil
918 "Normal hook, run each time a new outgoing message is initialized.
919 The function `message-setup' runs this hook."
920 :group 'message-various
921 :link '(custom-manual "(message)Various Message Variables")
924 (defcustom message-cancel-hook nil
925 "Hook run when canceling articles."
926 :group 'message-various
927 :link '(custom-manual "(message)Various Message Variables")
930 (defcustom message-signature-setup-hook nil
931 "Normal hook, run each time a new outgoing message is initialized.
932 It is run after the headers have been inserted and before
933 the signature is inserted."
934 :group 'message-various
935 :link '(custom-manual "(message)Various Message Variables")
938 (defcustom message-mode-hook nil
939 "Hook run in message mode buffers."
940 :group 'message-various
943 (defcustom message-header-hook nil
944 "Hook run in a message mode buffer narrowed to the headers."
945 :group 'message-various
948 (defcustom message-header-setup-hook nil
949 "Hook called narrowed to the headers when setting up a message buffer."
950 :group 'message-various
951 :link '(custom-manual "(message)Various Message Variables")
954 (defcustom message-minibuffer-local-map
955 (let ((map (make-sparse-keymap 'message-minibuffer-local-map)))
956 (set-keymap-parent map minibuffer-local-map)
958 "Keymap for `message-read-from-minibuffer'."
959 ;; FIXME improve type.
960 :type '(restricted-sexp :match-alternatives (symbolp keymapp))
962 :group 'message-various)
964 (defcustom message-citation-line-function 'message-insert-citation-line
965 "*Function called to insert the \"Whomever writes:\" line.
967 Predefined functions include `message-insert-citation-line' and
968 `message-insert-formatted-citation-line' (see the variable
969 `message-citation-line-format').
971 Note that Gnus provides a feature where the reader can click on
972 `writes:' to hide the cited text. If you change this line too much,
973 people who read your message will have to change their Gnus
974 configuration. See the variable `gnus-cite-attribution-suffix'."
976 (function-item :tag "plain" message-insert-citation-line)
977 (function-item :tag "formatted" message-insert-formatted-citation-line)
978 (function :tag "Other"))
979 :link '(custom-manual "(message)Insertion Variables")
980 :group 'message-insertion)
982 (defcustom message-citation-line-format "On %a, %b %d %Y, %N wrote:\n"
983 "Format of the \"Whomever writes:\" line.
985 The string is formatted using `format-spec'. The following constructs
988 %f The full From, e.g. \"John Doe <john.doe@example.invalid>\".
989 %n The mail address, e.g. \"john.doe@example.invalid\".
990 %N The real name if present, e.g.: \"John Doe\", else fall
991 back to the mail address.
992 %F The first name if present, e.g.: \"John\", else fall
993 back to the mail address.
994 %L The last name if present, e.g.: \"Doe\".
995 %Z, %z The time zone in the numeric form, e.g.:\"+0000\".
997 All other format specifiers are passed to `format-time-string'
998 which is called using the date from the article your replying to, but
999 the date in the formatted string will be expressed in the author's
1000 time zone as much as possible.
1001 Extracting the first (%F) and last name (%L) is done heuristically,
1002 so you should always check it yourself.
1004 Please also read the note in the documentation of
1005 `message-citation-line-function'."
1006 :type '(choice (const :tag "Plain" "%f writes:")
1007 (const :tag "Include date" "On %a, %b %d %Y, %n wrote:")
1009 :link '(custom-manual "(message)Insertion Variables")
1010 :version "23.1" ;; No Gnus
1011 :group 'message-insertion)
1013 (defcustom message-yank-prefix mail-yank-prefix
1014 "*Prefix inserted on the lines of yanked messages.
1015 Fix `message-cite-prefix-regexp' if it is set to an abnormal value.
1016 See also `message-yank-cited-prefix' and `message-yank-empty-prefix'."
1019 :link '(custom-manual "(message)Insertion Variables")
1020 :group 'message-insertion)
1022 (defcustom message-yank-cited-prefix ">"
1023 "*Prefix inserted on cited lines of yanked messages.
1024 Fix `message-cite-prefix-regexp' if it is set to an abnormal value.
1025 See also `message-yank-prefix' and `message-yank-empty-prefix'."
1028 :link '(custom-manual "(message)Insertion Variables")
1029 :group 'message-insertion)
1031 (defcustom message-yank-empty-prefix ">"
1032 "*Prefix inserted on empty lines of yanked messages.
1033 See also `message-yank-prefix' and `message-yank-cited-prefix'."
1036 :link '(custom-manual "(message)Insertion Variables")
1037 :group 'message-insertion)
1039 (defcustom message-indentation-spaces mail-indentation-spaces
1040 "*Number of spaces to insert at the beginning of each cited line.
1041 Used by `message-yank-original' via `message-yank-cite'."
1043 :group 'message-insertion
1044 :link '(custom-manual "(message)Insertion Variables")
1047 (defcustom message-cite-function 'message-cite-original-without-signature
1048 "*Function for citing an original message.
1049 Predefined functions include `message-cite-original' and
1050 `message-cite-original-without-signature'.
1051 Note that these functions use `mail-citation-hook' if that is non-nil."
1052 :type '(radio (function-item message-cite-original)
1053 (function-item message-cite-original-without-signature)
1054 (function-item sc-cite-original)
1055 (function :tag "Other"))
1056 :link '(custom-manual "(message)Insertion Variables")
1057 :version "22.3" ;; Gnus 5.10.12 (changed default)
1058 :group 'message-insertion)
1060 (defcustom message-indent-citation-function 'message-indent-citation
1061 "*Function for modifying a citation just inserted in the mail buffer.
1062 This can also be a list of functions. Each function can find the
1063 citation between (point) and (mark t). And each function should leave
1064 point and mark around the citation text as modified."
1066 :link '(custom-manual "(message)Insertion Variables")
1067 :group 'message-insertion)
1069 (defcustom message-signature mail-signature
1070 "*String to be inserted at the end of the message buffer.
1071 If t, the `message-signature-file' file will be inserted instead.
1072 If a function, the result from the function will be used instead.
1073 If a form, the result from the form will be used instead."
1075 :type '(choice string (const :tag "Contents of signature file" t)
1079 :link '(custom-manual "(message)Insertion Variables")
1080 :group 'message-insertion)
1082 (defcustom message-signature-file mail-signature-file
1083 "*Name of file containing the text inserted at end of message buffer.
1084 Ignored if the named file doesn't exist.
1085 If nil, don't insert a signature.
1086 If a path is specified, the value of `message-signature-directory' is ignored,
1089 :type '(choice file (const :tags "None" nil))
1090 :link '(custom-manual "(message)Insertion Variables")
1091 :group 'message-insertion)
1093 (defcustom message-signature-directory nil
1094 "*Name of directory containing signature files.
1095 Comes in handy if you have many such files, handled via posting styles for
1097 If nil, `message-signature-file' is expected to specify the directory if
1099 :type '(choice string (const :tags "None" nil))
1100 :link '(custom-manual "(message)Insertion Variables")
1101 :group 'message-insertion)
1103 (defcustom message-signature-insert-empty-line t
1104 "*If non-nil, insert an empty line before the signature separator."
1107 :link '(custom-manual "(message)Insertion Variables")
1108 :group 'message-insertion)
1110 (defcustom message-cite-reply-position 'traditional
1111 "*Where the reply should be positioned.
1112 If `traditional', reply inline.
1113 If `above', reply above quoted text.
1114 If `below', reply below quoted text.
1116 Note: Many newsgroups frown upon nontraditional reply styles. You
1117 probably want to set this variable only for specific groups,
1118 e.g. using `gnus-posting-styles':
1120 (eval (set (make-local-variable \\='message-cite-reply-position) \\='above))"
1122 :type '(choice (const :tag "Reply inline" traditional)
1123 (const :tag "Reply above" above)
1124 (const :tag "Reply below" below))
1125 :group 'message-insertion)
1127 (defcustom message-cite-style nil
1128 "*The overall style to be used when yanking cited text.
1129 Value is either nil (no variable overrides) or a let-style list
1130 of pairs (VARIABLE VALUE) that will be bound in
1131 `message-yank-original' to do the quoting.
1133 Presets to impersonate popular mail agents are found in the
1134 message-cite-style-* variables. This variable is intended for
1135 use in `gnus-posting-styles', such as:
1137 ((posting-from-work-p) (eval (set (make-local-variable \\='message-cite-style) message-cite-style-outlook)))"
1139 :group 'message-insertion
1140 :type '(choice (const :tag "Do not override variables" :value nil)
1141 (const :tag "MS Outlook" :value message-cite-style-outlook)
1142 (const :tag "Mozilla Thunderbird" :value message-cite-style-thunderbird)
1143 (const :tag "Gmail" :value message-cite-style-gmail)
1144 (variable :tag "User-specified")))
1146 (defconst message-cite-style-outlook
1147 '((message-cite-function 'message-cite-original)
1148 (message-citation-line-function 'message-insert-formatted-citation-line)
1149 (message-cite-reply-position 'above)
1150 (message-yank-prefix "")
1151 (message-yank-cited-prefix "")
1152 (message-yank-empty-prefix "")
1153 (message-citation-line-format "\n\n-----------------------\nOn %a, %b %d %Y, %N wrote:\n"))
1154 "Message citation style used by MS Outlook. Use with message-cite-style.")
1156 (defconst message-cite-style-thunderbird
1157 '((message-cite-function 'message-cite-original)
1158 (message-citation-line-function 'message-insert-formatted-citation-line)
1159 (message-cite-reply-position 'above)
1160 (message-yank-prefix "> ")
1161 (message-yank-cited-prefix ">")
1162 (message-yank-empty-prefix ">")
1163 (message-citation-line-format "On %D %R %p, %N wrote:"))
1164 "Message citation style used by Mozilla Thunderbird. Use with message-cite-style.")
1166 (defconst message-cite-style-gmail
1167 '((message-cite-function 'message-cite-original)
1168 (message-citation-line-function 'message-insert-formatted-citation-line)
1169 (message-cite-reply-position 'above)
1170 (message-yank-prefix " ")
1171 (message-yank-cited-prefix " ")
1172 (message-yank-empty-prefix " ")
1173 (message-citation-line-format "On %e %B %Y %R, %f wrote:\n"))
1174 "Message citation style used by Gmail. Use with message-cite-style.")
1176 (defcustom message-distribution-function nil
1177 "*Function called to return a Distribution header."
1178 :group 'message-news
1179 :group 'message-headers
1180 :link '(custom-manual "(message)News Headers")
1181 :type '(choice function (const nil)))
1183 (defcustom message-expires 14
1184 "Number of days before your article expires."
1185 :group 'message-news
1186 :group 'message-headers
1187 :link '(custom-manual "(message)News Headers")
1190 (defcustom message-user-path nil
1191 "If nil, use the NNTP server name in the Path header.
1192 If stringp, use this; if non-nil, use no host name (user name only)."
1193 :group 'message-news
1194 :group 'message-headers
1195 :link '(custom-manual "(message)News Headers")
1196 :type '(choice (const :tag "nntp" nil)
1197 (string :tag "name")
1198 (sexp :tag "none" :format "%t" t)))
1200 ;; This can be the name of a buffer, or a cons cell (FUNCTION . ARGS)
1201 ;; for yanking the original buffer.
1202 (defvar message-reply-buffer nil)
1203 (defvar message-reply-headers nil
1204 "The headers of the current replied article.
1205 It is a vector of the following headers:
1206 [number subject from date id references chars lines xref extra].")
1207 (defvar message-newsreader nil)
1208 (defvar message-mailer nil)
1209 (defvar message-sent-message-via nil)
1210 (defvar message-checksum nil)
1211 (defvar message-send-actions nil
1212 "A list of actions to be performed upon successful sending of a message.")
1213 (defvar message-return-action nil
1214 "Action to return to the caller after sending or postponing a message.")
1215 (defvar message-exit-actions nil
1216 "A list of actions to be performed upon exiting after sending a message.")
1217 (defvar message-kill-actions nil
1218 "A list of actions to be performed before killing a message buffer.")
1219 (defvar message-postpone-actions nil
1220 "A list of actions to be performed after postponing a message.")
1222 (define-widget 'message-header-lines 'text
1223 "All header lines must be LFD terminated."
1224 :format "%{%t%}:%n%v"
1225 :valid-regexp "^\\'"
1226 :error "All header lines must be newline terminated")
1228 (defcustom message-default-headers ""
1229 "Header lines to be inserted in outgoing messages.
1230 This can be set to a string containing or a function returning
1231 header lines to be inserted before you edit the message, so you
1232 can edit or delete these lines. If set to a function, it is
1233 called and its result is inserted."
1235 :group 'message-headers
1236 :link '(custom-manual "(message)Message Headers")
1238 (message-header-lines :tag "String")
1239 (function :tag "Function")))
1241 (defcustom message-default-mail-headers
1242 ;; Ease the transition from mail-mode to message-mode. See bugs#4431, 5555.
1243 (concat (if (and (boundp 'mail-default-reply-to)
1244 (stringp mail-default-reply-to))
1245 (format "Reply-to: %s\n" mail-default-reply-to))
1246 (if (and (boundp 'mail-self-blind)
1248 (format "BCC: %s\n" user-mail-address))
1249 (if (and (boundp 'mail-archive-file-name)
1250 (stringp mail-archive-file-name))
1251 (format "FCC: %s\n" mail-archive-file-name))
1252 mail-default-headers)
1253 "*A string of header lines to be inserted in outgoing mails."
1255 :group 'message-headers
1256 :group 'message-mail
1257 :link '(custom-manual "(message)Mail Headers")
1258 :type 'message-header-lines)
1260 (defcustom message-default-news-headers ""
1261 "*A string of header lines to be inserted in outgoing news articles."
1262 :group 'message-headers
1263 :group 'message-news
1264 :link '(custom-manual "(message)News Headers")
1265 :type 'message-header-lines)
1267 ;; Note: could use /usr/ucb/mail instead of sendmail;
1268 ;; options -t, and -v if not interactive.
1269 (defcustom message-mailer-swallows-blank-line
1270 (if (and (string-match "sparc-sun-sunos\\(\\'\\|[^5]\\)"
1271 system-configuration)
1272 (file-readable-p "/etc/sendmail.cf")
1274 (insert-file-contents "/etc/sendmail.cf")
1275 (goto-char (point-min))
1276 (let ((case-fold-search nil))
1277 (re-search-forward "^OR\\>" nil t))))
1278 ;; According to RFC822, "The field-name must be composed of printable
1279 ;; ASCII characters (i. e., characters that have decimal values between
1280 ;; 33 and 126, except colon)", i. e., any chars except ctl chars,
1282 '(looking-at "[ \t]\\|[][!\"#$%&'()*+,-./0-9;<=>?@A-Z\\\\^_`a-z{|}~]+:"))
1283 "*Set this non-nil if the system's mailer runs the header and body together.
1284 \(This problem exists on Sunos 4 when sendmail is run in remote mode.)
1285 The value should be an expression to test whether the problem will
1287 :group 'message-sending
1288 :link '(custom-manual "(message)Mail Variables")
1293 (define-mail-user-agent 'message-user-agent
1294 'message-mail 'message-send-and-exit
1295 'message-kill-buffer 'message-send-hook)
1297 (defvar message-mh-deletable-headers '(Message-ID Date Lines Sender)
1298 "If non-nil, delete the deletable headers before feeding to mh.")
1300 (defvar message-send-method-alist
1301 '((news message-news-p message-send-via-news)
1302 (mail message-mail-p message-send-via-mail))
1303 "Alist of ways to send outgoing messages.
1304 Each element has the form
1306 (TYPE PREDICATE FUNCTION)
1308 where TYPE is a symbol that names the method; PREDICATE is a function
1309 called without any parameters to determine whether the message is
1310 a message of type TYPE; and FUNCTION is a function to be called if
1311 PREDICATE returns non-nil. FUNCTION is called with one parameter --
1314 (defcustom message-mail-alias-type 'abbrev
1315 "*What alias expansion type to use in Message buffers.
1316 The default is `abbrev', which uses mailabbrev. `ecomplete' uses
1317 an electric completion mode. nil switches mail aliases off.
1318 This can also be a list of values."
1320 :link '(custom-manual "(message)Mail Aliases")
1321 :type '(choice (const :tag "Use Mailabbrev" abbrev)
1322 (const :tag "Use ecomplete" ecomplete)
1323 (const :tag "No expansion" nil)))
1325 (defcustom message-self-insert-commands '(self-insert-command)
1326 "List of `self-insert-command's used to trigger ecomplete.
1327 When one of those commands is invoked to enter a character in To or Cc
1328 header, ecomplete will suggest the candidates of recipients (see also
1329 `message-mail-alias-type'). If you use some tool to enter non-ASCII
1330 text and it replaces `self-insert-command' with the other command, e.g.
1331 `egg-self-insert-command', you may want to add it to this list."
1332 :group 'message-various
1333 :type '(repeat function))
1335 (defcustom message-auto-save-directory
1336 (if (file-writable-p message-directory)
1337 (file-name-as-directory (expand-file-name "drafts" message-directory))
1339 "*Directory where Message auto-saves buffers if Gnus isn't running.
1340 If nil, Message won't auto-save."
1341 :group 'message-buffers
1342 :link '(custom-manual "(message)Various Message Variables")
1343 :type '(choice directory (const :tag "Don't auto-save" nil)))
1345 (defcustom message-default-charset
1346 (and (not (mm-multibyte-p)) 'iso-8859-1)
1347 "Default charset used in non-MULE Emacsen.
1348 If nil, you might be asked to input the charset."
1351 :link '(custom-manual "(message)Various Message Variables")
1354 (defcustom message-dont-reply-to-names mail-dont-reply-to-names
1355 "Addresses to prune when doing wide replies.
1356 This can be a regexp, a list of regexps or a predicate function.
1357 Also, a value of nil means exclude your own user name only.
1359 If a function email is passed as the argument."
1362 :link '(custom-manual "(message)Wide Reply")
1363 :type '(choice (const :tag "Yourself" nil)
1365 (repeat :tag "Regexp List" regexp)))
1367 (defsubst message-dont-reply-to-names ()
1368 (cond ((functionp message-dont-reply-to-names)
1369 message-dont-reply-to-names)
1370 ((stringp message-dont-reply-to-names)
1371 (gmm-regexp-concat message-dont-reply-to-names))))
1373 (defvar message-shoot-gnksa-feet nil
1374 "*A list of GNKSA feet you are allowed to shoot.
1375 Gnus gives you all the opportunity you could possibly want for
1376 shooting yourself in the foot. Also, Gnus allows you to shoot the
1377 feet of Good Net-Keeping Seal of Approval. The following are foot
1379 `empty-article' Allow you to post an empty article;
1380 `quoted-text-only' Allow you to post quoted text only;
1381 `multiple-copies' Allow you to post multiple copies;
1382 `cancel-messages' Allow you to cancel or supersede messages from
1383 your other email addresses;
1384 `canlock-verify' Allow you to cancel messages without verifying canlock.")
1386 (defsubst message-gnksa-enable-p (feature)
1387 (or (not (listp message-shoot-gnksa-feet))
1388 (memq feature message-shoot-gnksa-feet)))
1390 (defcustom message-hidden-headers '("^References:" "^Face:" "^X-Face:"
1392 "Regexp of headers to be hidden when composing new messages.
1393 This can also be a list of regexps to match headers. Or a list
1394 starting with `not' and followed by regexps."
1397 :link '(custom-manual "(message)Message Headers")
1399 :format "%{%t%}: %[Value Type%] %v"
1400 (regexp :menu-tag "regexp" :format "regexp\n%t: %v")
1401 (repeat :menu-tag "(regexp ...)" :format "(regexp ...)\n%v%i"
1402 (regexp :format "%t: %v"))
1403 (cons :menu-tag "(not regexp ...)" :format "(not regexp ...)\n%v"
1405 (repeat :format "%v%i"
1406 (regexp :format "%t: %v")))))
1408 (defcustom message-cite-articles-with-x-no-archive t
1409 "If non-nil, cite text from articles that has X-No-Archive set."
1413 ;;; Internal variables.
1414 ;;; Well, not really internal.
1416 (defvar message-mode-syntax-table
1417 (let ((table (copy-syntax-table text-mode-syntax-table)))
1418 (modify-syntax-entry ?% ". " table)
1419 (modify-syntax-entry ?> ". " table)
1420 (modify-syntax-entry ?< ". " table)
1422 "Syntax table used while in Message mode.")
1424 (defface message-header-to
1427 (:foreground "DarkOliveGreen1" :bold t))
1430 (:foreground "MidnightBlue" :bold t))
1432 (:bold t :italic t)))
1433 "Face used for displaying From headers."
1434 :group 'message-faces)
1435 ;; backward-compatibility alias
1436 (put 'message-header-to-face 'face-alias 'message-header-to)
1437 (put 'message-header-to-face 'obsolete-face "22.1")
1439 (defface message-header-cc
1442 (:foreground "chartreuse1" :bold t))
1445 (:foreground "MidnightBlue"))
1448 "Face used for displaying Cc headers."
1449 :group 'message-faces)
1450 ;; backward-compatibility alias
1451 (put 'message-header-cc-face 'face-alias 'message-header-cc)
1452 (put 'message-header-cc-face 'obsolete-face "22.1")
1454 (defface message-header-subject
1457 (:foreground "OliveDrab1"))
1460 (:foreground "navy blue" :bold t))
1463 "Face used for displaying subject headers."
1464 :group 'message-faces)
1465 ;; backward-compatibility alias
1466 (put 'message-header-subject-face 'face-alias 'message-header-subject)
1467 (put 'message-header-subject-face 'obsolete-face "22.1")
1469 (defface message-header-newsgroups
1472 (:foreground "yellow" :bold t :italic t))
1475 (:foreground "blue4" :bold t :italic t))
1477 (:bold t :italic t)))
1478 "Face used for displaying newsgroups headers."
1479 :group 'message-faces)
1480 ;; backward-compatibility alias
1481 (put 'message-header-newsgroups-face 'face-alias 'message-header-newsgroups)
1482 (put 'message-header-newsgroups-face 'obsolete-face "22.1")
1484 (defface message-header-other
1487 (:foreground "VioletRed1"))
1490 (:foreground "steel blue"))
1492 (:bold t :italic t)))
1493 "Face used for displaying newsgroups headers."
1494 :group 'message-faces)
1495 ;; backward-compatibility alias
1496 (put 'message-header-other-face 'face-alias 'message-header-other)
1497 (put 'message-header-other-face 'obsolete-face "22.1")
1499 (defface message-header-name
1502 (:foreground "green"))
1505 (:foreground "cornflower blue"))
1508 "Face used for displaying header names."
1509 :group 'message-faces)
1510 ;; backward-compatibility alias
1511 (put 'message-header-name-face 'face-alias 'message-header-name)
1512 (put 'message-header-name-face 'obsolete-face "22.1")
1514 (defface message-header-xheader
1517 (:foreground "DeepSkyBlue1"))
1520 (:foreground "blue"))
1523 "Face used for displaying X-Header headers."
1524 :group 'message-faces)
1525 ;; backward-compatibility alias
1526 (put 'message-header-xheader-face 'face-alias 'message-header-xheader)
1527 (put 'message-header-xheader-face 'obsolete-face "22.1")
1529 (defface message-separator
1532 (:foreground "LightSkyBlue1"))
1535 (:foreground "brown"))
1538 "Face used for displaying the separator."
1539 :group 'message-faces)
1540 ;; backward-compatibility alias
1541 (put 'message-separator-face 'face-alias 'message-separator)
1542 (put 'message-separator-face 'obsolete-face "22.1")
1544 (defface message-cited-text
1547 (:foreground "LightPink1"))
1550 (:foreground "red"))
1553 "Face used for displaying cited text names."
1554 :group 'message-faces)
1555 ;; backward-compatibility alias
1556 (put 'message-cited-text-face 'face-alias 'message-cited-text)
1557 (put 'message-cited-text-face 'obsolete-face "22.1")
1559 (defface message-mml
1562 (:foreground "MediumSpringGreen"))
1565 (:foreground "ForestGreen"))
1568 "Face used for displaying MML."
1569 :group 'message-faces)
1570 ;; backward-compatibility alias
1571 (put 'message-mml-face 'face-alias 'message-mml)
1572 (put 'message-mml-face 'obsolete-face "22.1")
1574 (defun message-font-lock-make-header-matcher (regexp)
1577 (let ((start (point)))
1580 (goto-char (point-min))
1581 (if (re-search-forward
1582 (concat "^" (regexp-quote mail-header-separator) "$")
1584 (setq limit (min limit (match-beginning 0))))
1586 (and (< start limit)
1587 (re-search-forward ,regexp limit t))))))
1588 (if (featurep 'bytecomp)
1592 (defvar message-font-lock-keywords
1593 (let ((content "[ \t]*\\(.+\\(\n[ \t].*\\)*\\)\n?"))
1594 `((,(message-font-lock-make-header-matcher
1595 (concat "^\\([Tt]o:\\)" content))
1596 (1 'message-header-name)
1597 (2 'message-header-to nil t))
1598 (,(message-font-lock-make-header-matcher
1599 (concat "^\\(^[GBF]?[Cc][Cc]:\\|^[Rr]eply-[Tt]o:\\)" content))
1600 (1 'message-header-name)
1601 (2 'message-header-cc nil t))
1602 (,(message-font-lock-make-header-matcher
1603 (concat "^\\([Ss]ubject:\\)" content))
1604 (1 'message-header-name)
1605 (2 'message-header-subject nil t))
1606 (,(message-font-lock-make-header-matcher
1607 (concat "^\\([Nn]ewsgroups:\\|Followup-[Tt]o:\\)" content))
1608 (1 'message-header-name)
1609 (2 'message-header-newsgroups nil t))
1610 (,(message-font-lock-make-header-matcher
1611 (concat "^\\(X-[A-Za-z0-9-]+:\\|In-Reply-To:\\)" content))
1612 (1 'message-header-name)
1613 (2 'message-header-xheader))
1614 (,(message-font-lock-make-header-matcher
1615 (concat "^\\([A-Z][^: \n\t]+:\\)" content))
1616 (1 'message-header-name)
1617 (2 'message-header-other nil t))
1618 ,@(if (and mail-header-separator
1619 (not (equal mail-header-separator "")))
1620 `((,(concat "^\\(" (regexp-quote mail-header-separator) "\\)$")
1621 1 'message-separator))
1624 (re-search-forward (concat "^\\("
1625 message-cite-prefix-regexp
1628 (0 'message-cited-text))
1629 ("<#/?\\(multipart\\|part\\|external\\|mml\\|secure\\)[^>]*>"
1631 "Additional expressions to highlight in Message mode.")
1633 (defvar message-face-alist
1634 '((bold . message-bold-region)
1635 (underline . underline-region)
1636 (default . (lambda (b e)
1637 (message-unbold-region b e)
1638 (ununderline-region b e))))
1639 "Alist of mail and news faces for facemenu.
1640 The cdr of each entry is a function for applying the face to a region.")
1642 (defcustom message-send-hook nil
1643 "Hook run before sending messages.
1644 This hook is run quite early when sending."
1645 :group 'message-various
1646 :options '(ispell-message)
1647 :link '(custom-manual "(message)Various Message Variables")
1650 (defcustom message-send-mail-hook nil
1651 "Hook run before sending mail messages.
1652 This hook is run very late -- just before the message is sent as
1654 :group 'message-various
1655 :link '(custom-manual "(message)Various Message Variables")
1658 (defcustom message-send-news-hook nil
1659 "Hook run before sending news messages.
1660 This hook is run very late -- just before the message is sent as
1662 :group 'message-various
1663 :link '(custom-manual "(message)Various Message Variables")
1666 (defcustom message-sent-hook nil
1667 "Hook run after sending messages."
1668 :group 'message-various
1671 (defvar message-send-coding-system 'binary
1672 "Coding system to encode outgoing mail.")
1674 (defvar message-draft-coding-system mm-auto-save-coding-system
1675 "Coding system to compose mail.")
1677 (defcustom message-send-mail-partially-limit nil
1678 "The limitation of messages sent as message/partial.
1679 The lower bound of message size in characters, beyond which the message
1680 should be sent in several parts. If it is nil, the size is unlimited."
1682 :group 'message-buffers
1683 :link '(custom-manual "(message)Mail Variables")
1684 :type '(choice (const :tag "unlimited" nil)
1687 (defcustom message-alternative-emails nil
1688 "*Regexp or predicate function matching alternative email addresses.
1689 The first address in the To, Cc or From headers of the original
1690 article matching this variable is used as the From field of
1693 If a function, an email string is passed as the argument.
1695 This variable has precedence over posting styles and anything that runs
1696 off `message-setup-hook'."
1697 :group 'message-headers
1698 :link '(custom-manual "(message)Message Headers")
1699 :type '(choice (const :tag "Always use primary" nil)
1703 (defcustom message-hierarchical-addresses nil
1704 "A list of hierarchical mail address definitions.
1706 Inside each entry, the first address is the \"top\" address, and
1707 subsequent addresses are subaddresses; this is used to indicate that
1708 mail sent to the first address will automatically be delivered to the
1709 subaddresses. So if the first address appears in the recipient list
1710 for a message, the subaddresses will be removed (if present) before
1711 the mail is sent. All addresses in this structure should be
1714 :group 'message-headers
1715 :type '(repeat (repeat string)))
1717 (defcustom message-mail-user-agent nil
1718 "Like `mail-user-agent'.
1719 Except if it is nil, use Gnus native MUA; if it is t, use
1722 :type '(radio (const :tag "Gnus native"
1725 (const :tag "`mail-user-agent'"
1728 (function-item :tag "Default Emacs mail"
1730 sendmail-user-agent)
1731 (function-item :tag "Emacs interface to MH"
1734 (function :tag "Other"))
1738 (defcustom message-wide-reply-confirm-recipients nil
1739 "Whether to confirm a wide reply to multiple email recipients.
1740 If this variable is nil, don't ask whether to reply to all recipients.
1741 If this variable is non-nil, pose the question \"Reply to all
1742 recipients?\" before a wide reply to multiple recipients. If the user
1743 answers yes, reply to all recipients as usual. If the user answers
1744 no, only reply back to the author."
1746 :group 'message-headers
1747 :link '(custom-manual "(message)Wide Reply")
1750 (defcustom message-user-fqdn nil
1751 "*Domain part of Message-Ids."
1753 :group 'message-headers
1754 :link '(custom-manual "(message)News Headers")
1755 :type '(radio (const :format "%v " nil)
1756 (string :format "FQDN: %v")))
1758 (defcustom message-use-idna
1759 (and (or (mm-coding-system-p 'utf-8)
1761 (let (mucs-ignore-version-incompatibilities)
1762 (require 'un-define))
1767 (invalid-operation))
1769 (executable-find idna-program)
1770 (string= (idna-to-ascii "räksmörgås") "xn--rksmrgs-5wao1o")
1772 "Whether to encode non-ASCII in domain names into ASCII according to IDNA.
1773 GNU Libidn, and in particular the elisp package \"idna.el\" and
1774 the external program \"idn\", must be installed for this
1775 functionality to work."
1777 :group 'message-headers
1778 :link '(custom-manual "(message)IDNA")
1779 :type '(choice (const :tag "Ask" ask)
1780 (const :tag "Never" nil)
1781 (const :tag "Always" t)))
1783 (defcustom message-generate-hashcash (if (executable-find "hashcash") 'opportunistic)
1784 "*Whether to generate X-Hashcash: headers.
1785 If t, always generate hashcash headers. If `opportunistic',
1786 only generate hashcash headers if it can be done without the user
1787 waiting (i.e., only asynchronously).
1789 You must have the \"hashcash\" binary installed, see `hashcash-path'."
1791 :group 'message-headers
1792 :link '(custom-manual "(message)Mail Headers")
1793 :type '(choice (const :tag "Always" t)
1794 (const :tag "Never" nil)
1795 (const :tag "Opportunistic" opportunistic)))
1797 ;;; Internal variables.
1799 (defvar message-sending-message "Sending...")
1800 (defvar message-buffer-list nil)
1801 (defvar message-this-is-news nil)
1802 (defvar message-this-is-mail nil)
1803 (defvar message-draft-article nil)
1804 (defvar message-mime-part nil)
1805 (defvar message-posting-charset nil)
1806 (defvar message-inserted-headers nil)
1807 (defvar message-inhibit-ecomplete nil)
1809 ;; Byte-compiler warning
1810 (defvar gnus-active-hashtb)
1811 (defvar gnus-read-active-file)
1813 ;;; Regexp matching the delimiter of messages in UNIX mail format
1814 ;;; (UNIX From lines), minus the initial ^. It should be a copy
1815 ;;; of rmail.el's rmail-unix-mail-delimiter.
1816 (defvar message-unix-mail-delimiter
1817 (let ((time-zone-regexp
1818 (concat "\\([A-Z]?[A-Z]?[A-Z][A-Z]\\( DST\\)?"
1819 "\\|[-+]?[0-9][0-9][0-9][0-9]"
1825 ;; Many things can happen to an RFC 822 mailbox before it is put into
1826 ;; a `From' line. The leading phrase can be stripped, e.g.
1827 ;; `Joe <@w.x:joe@y.z>' -> `<@w.x:joe@y.z>'. The <> can be stripped, e.g.
1828 ;; `<@x.y:joe@y.z>' -> `@x.y:joe@y.z'. Everything starting with a CRLF
1829 ;; can be removed, e.g.
1830 ;; From: joe@y.z (Joe K
1832 ;; can yield `From joe@y.z (Joe K Fri Mar 22 08:11:15 1996', and
1835 ;; can yield `From Joe User Fri Mar 22 08:11:15 1996'.
1836 ;; The mailbox can be removed or be replaced by white space, e.g.
1837 ;; From: "Joe User"{space}{tab}
1839 ;; can yield `From {space}{tab} Fri Mar 22 08:11:15 1996',
1840 ;; where {space} and {tab} represent the Ascii space and tab characters.
1841 ;; We want to match the results of any of these manglings.
1842 ;; The following regexp rejects names whose first characters are
1843 ;; obviously bogus, but after that anything goes.
1844 "\\([^\0-\b\n-\r\^?].*\\)?"
1846 ;; The time the message was sent.
1847 "\\([^\0-\r \^?]+\\) +" ; day of the week
1848 "\\([^\0-\r \^?]+\\) +" ; month
1849 "\\([0-3]?[0-9]\\) +" ; day of month
1850 "\\([0-2][0-9]:[0-5][0-9]\\(:[0-6][0-9]\\)?\\) *" ; time of day
1852 ;; Perhaps a time zone, specified by an abbreviation, or by a
1857 " \\([0-9][0-9]+\\) *"
1859 ;; On some systems the time zone can appear after the year, too.
1863 "\\(remote from .*\\)?"
1866 "Regexp matching the delimiter of messages in UNIX mail format.")
1868 (defvar message-unsent-separator
1869 (concat "^ *---+ +Unsent message follows +---+ *$\\|"
1870 "^ *---+ +Returned message +---+ *$\\|"
1871 "^Start of returned message$\\|"
1872 "^ *---+ +Original message +---+ *$\\|"
1873 "^ *--+ +begin message +--+ *$\\|"
1874 "^ *---+ +Original message follows +---+ *$\\|"
1875 "^ *---+ +Undelivered message follows +---+ *$\\|"
1876 "^------ This is a copy of the message, including all the headers. ------ *$\\|"
1877 "^|? *---+ +Message text follows: +---+ *|?$")
1878 "A regexp that matches the separator before the text of a failed message.")
1880 (defvar message-field-fillers
1881 '((To message-fill-field-address)
1882 (Cc message-fill-field-address)
1883 (From message-fill-field-address))
1884 "Alist of header names/filler functions.")
1886 (defvar message-header-format-alist
1901 (References . message-shorten-references)
1903 "Alist used for formatting headers.")
1905 (defvar message-options nil
1906 "Some saved answers when sending message.")
1907 (make-variable-buffer-local 'message-options)
1909 (defvar message-send-mail-real-function nil
1910 "Internal send mail function.")
1912 (defvar message-bogus-system-names "\\`localhost\\.\\|\\.local\\'"
1913 "The regexp of bogus system names.")
1915 (autoload 'gnus-alive-p "gnus-util")
1916 (autoload 'gnus-delay-article "gnus-delay")
1917 (autoload 'gnus-extract-address-components "gnus-util")
1918 (autoload 'gnus-find-method-for-group "gnus")
1919 (autoload 'gnus-group-decoded-name "gnus-group")
1920 (autoload 'gnus-group-name-charset "gnus-group")
1921 (autoload 'gnus-group-name-decode "gnus-group")
1922 (autoload 'gnus-groups-from-server "gnus")
1923 (autoload 'gnus-open-server "gnus-int")
1924 (autoload 'gnus-output-to-mail "gnus-util")
1925 (autoload 'gnus-output-to-rmail "gnus-util")
1926 (autoload 'gnus-request-post "gnus-int")
1927 (autoload 'gnus-server-string "gnus")
1928 (autoload 'idna-to-ascii "idna")
1929 (autoload 'message-setup-toolbar "messagexmas")
1930 (autoload 'mh-new-draft-name "mh-comp")
1931 (autoload 'mh-send-letter "mh-comp")
1932 (autoload 'nndraft-request-associate-buffer "nndraft")
1933 (autoload 'nndraft-request-expire-articles "nndraft")
1934 (autoload 'nnvirtual-find-group-art "nnvirtual")
1935 (autoload 'rmail-msg-is-pruned "rmail")
1936 (autoload 'rmail-output "rmailout")
1938 (defun message-kill-all-overlays ()
1939 (mapcar #'delete-overlay (overlays-in (point-min) (point-max))))
1944 ;;; Utility functions.
1947 (defmacro message-y-or-n-p (question show &rest text)
1948 "Ask QUESTION, displaying remaining args in a temporary buffer if SHOW."
1949 `(message-talkative-question 'y-or-n-p ,question ,show ,@text))
1951 (defmacro message-delete-line (&optional n)
1952 "Delete the current line (and the next N lines)."
1953 `(delete-region (progn (beginning-of-line) (point))
1954 (progn (forward-line ,(or n 1)) (point))))
1956 (defun message-mark-active-p ()
1957 "Non-nil means the mark and region are currently active in this buffer."
1960 (defun message-unquote-tokens (elems)
1961 "Remove double quotes (\") from strings in list ELEMS."
1962 (mapcar (lambda (item)
1963 (while (string-match "^\\(.*\\)\"\\(.*\\)$" item)
1964 (setq item (concat (match-string 1 item)
1965 (match-string 2 item))))
1969 (defun message-tokenize-header (header &optional separator)
1970 "Split HEADER into a list of header elements.
1971 SEPARATOR is a string of characters to be used as separators. \",\"
1972 is used by default."
1975 (let ((regexp (format "[%s]+" (or separator ",")))
1977 beg quoted elems paren)
1979 (mm-enable-multibyte)
1980 (setq beg (point-min))
1982 (goto-char (point-min))
1987 (cond ((and (> (point) beg)
1989 (and (looking-at regexp)
1992 (push (buffer-substring beg (point)) elems)
1993 (setq beg (match-end 0)))
1994 ((eq (char-after) ?\")
1995 (setq quoted (not quoted)))
1996 ((and (eq (char-after) ?\()
1999 ((and (eq (char-after) ?\))
2002 (nreverse elems)))))
2004 (autoload 'nnheader-insert-file-contents "nnheader")
2006 (defun message-mail-file-mbox-p (file)
2007 "Say whether FILE looks like a Unix mbox file."
2008 (when (and (file-exists-p file)
2009 (file-readable-p file)
2010 (file-regular-p file))
2012 (nnheader-insert-file-contents file)
2013 (goto-char (point-min))
2014 (looking-at message-unix-mail-delimiter))))
2016 (defun message-fetch-field (header &optional not-all)
2017 "The same as `mail-fetch-field', only remove all newlines.
2018 The buffer is expected to be narrowed to just the header of the message;
2019 see `message-narrow-to-headers-or-head'."
2020 (let* ((inhibit-point-motion-hooks t)
2021 (value (mail-fetch-field header nil (not not-all))))
2023 (while (string-match "\n[\t ]+" value)
2024 (setq value (replace-match " " t t value)))
2027 (defun message-field-value (header &optional not-all)
2028 "The same as `message-fetch-field', only narrow to the headers first."
2031 (message-narrow-to-headers-or-head)
2032 (message-fetch-field header not-all))))
2034 (defun message-narrow-to-field ()
2035 "Narrow the buffer to the header on the current line."
2037 (while (looking-at "[ \t]")
2043 (if (re-search-forward "^[^ \n\t]" nil t)
2046 (goto-char (point-min)))
2048 (defun message-add-header (&rest headers)
2049 "Add the HEADERS to the message header, skipping those already present."
2052 (unless (string-match "^\\([^:]+\\):[ \t]*[^ \t]" (car headers))
2053 (error "Invalid header `%s'" (car headers)))
2054 (setq hclean (match-string 1 (car headers)))
2056 (message-narrow-to-headers)
2057 (unless (re-search-forward (concat "^" (regexp-quote hclean) ":") nil t)
2058 (goto-char (point-max))
2059 (if (string-match "\n$" (car headers))
2060 (insert (car headers))
2061 (insert (car headers) ?\n)))))
2062 (setq headers (cdr headers))))
2064 (defmacro message-with-reply-buffer (&rest forms)
2065 "Evaluate FORMS in the reply buffer, if it exists."
2066 `(when (and (bufferp message-reply-buffer)
2067 (buffer-name message-reply-buffer))
2068 (with-current-buffer message-reply-buffer
2071 (put 'message-with-reply-buffer 'lisp-indent-function 0)
2072 (put 'message-with-reply-buffer 'edebug-form-spec '(body))
2074 (defun message-fetch-reply-field (header)
2075 "Fetch field HEADER from the message we're replying to."
2076 (message-with-reply-buffer
2078 (mail-narrow-to-head)
2079 (message-fetch-field header))))
2081 (defun message-strip-list-identifiers (subject)
2082 "Remove list identifiers in `gnus-list-identifiers' from string SUBJECT."
2083 (require 'gnus-sum) ; for gnus-list-identifiers
2084 (let ((regexp (if (stringp gnus-list-identifiers)
2085 gnus-list-identifiers
2086 (mapconcat 'identity gnus-list-identifiers " *\\|"))))
2087 (if (string-match (concat "\\(\\(\\(Re: +\\)?\\(" regexp
2088 " *\\)\\)+\\(Re: +\\)?\\)") subject)
2089 (concat (substring subject 0 (match-beginning 1))
2090 (or (match-string 3 subject)
2091 (match-string 5 subject))
2096 (defun message-strip-subject-re (subject)
2097 "Remove \"Re:\" from subject lines in string SUBJECT."
2098 (if (string-match message-subject-re-regexp subject)
2099 (substring subject (match-end 0))
2102 (defcustom message-replacement-char "."
2103 "Replacement character used instead of unprintable or not decodable chars."
2104 :group 'message-various
2105 :version "22.1" ;; Gnus 5.10.9
2106 :type '(choice string
2110 ;; FIXME: We also should call `message-strip-subject-encoded-words'
2111 ;; when forwarding. Probably in `message-make-forward-subject' and
2112 ;; `message-forward-make-body'.
2114 (defun message-strip-subject-encoded-words (subject)
2115 "Fix non-decodable words in SUBJECT."
2116 ;; Cf. `gnus-simplify-subject-fully'.
2117 (let* ((case-fold-search t)
2118 (replacement-chars (format "[%s%s%s]"
2119 message-replacement-char
2120 message-replacement-char
2121 message-replacement-char))
2122 (enc-word-re "=\\?\\([^?]+\\)\\?\\([QB]\\)\\?\\([^?]+\\)\\(\\?=\\)")
2127 (goto-char (point-min))
2128 (when (re-search-forward enc-word-re nil t)
2129 (setq cs-string (match-string 1)))))
2130 cs-coding q-or-b word-beg word-end)
2131 (if (or (not have-marker) ;; No encoded word found...
2132 ;; ... or double encoding was correct:
2133 (and (stringp cs-string)
2134 (setq cs-string (downcase cs-string))
2135 (mm-coding-system-p (intern cs-string))
2139 Decoded Subject \"%s\"
2140 contains a valid encoded word. Decode again? "
2142 (setq cs-coding (intern cs-string))))))
2146 (goto-char (point-min))
2147 (while (re-search-forward enc-word-re nil t)
2148 (setq cs-string (downcase (match-string 1))
2149 q-or-b (match-string 2)
2150 word-beg (match-beginning 0)
2151 word-end (match-end 0))
2153 (if (mm-coding-system-p (intern cs-string))
2154 (setq cs-coding (intern cs-string))
2156 ;; No double encoded subject? => bogus charset.
2161 Decoded Subject \"%s\"
2162 contains an encoded word. The charset `%s' is unknown or invalid.
2163 Hit RET to replace non-decodable characters with \"%s\" or enter replacement
2165 subject cs-string message-replacement-char)))
2167 (replace-match (concat "=?" (symbol-name cs-coding)
2170 (goto-char word-beg)
2171 (re-search-forward "=\\?\\([^?]+\\)\\?\\([QB]\\)\\?" word-end t)
2174 (if (string-match "\\`Q\\'" q-or-b)
2177 (message "Replacing non-decodable characters with \"%s\"."
2178 message-replacement-char)
2179 (while (re-search-forward "\\(=[A-F0-9][A-F0-9]\\)+"
2181 (replace-match message-replacement-char)))
2183 (message "Replacing non-decodable characters with \"%s\"."
2185 (re-search-forward "[^?]+" word-end t)
2186 (replace-match replacement-chars))
2187 (re-search-forward "\\?=")
2188 (replace-match "")))))
2189 (rfc2047-decode-region (point-min) (point-max))
2192 ;;; Start of functions adopted from `message-utils.el'.
2194 (defun message-strip-subject-trailing-was (subject)
2195 "Remove trailing \"(was: <old subject>)\" from SUBJECT lines.
2196 Leading \"Re: \" is not stripped by this function. Use the function
2197 `message-strip-subject-re' for this."
2198 (let* ((query message-subject-trailing-was-query)
2203 message-subject-trailing-was-ask-regexp
2204 message-subject-trailing-was-regexp)
2207 (setq new (substring subject 0 (match-beginning 0))))
2208 (if (or (not found) (eq query nil))
2211 (if (message-y-or-n-p
2212 "Strip `(was: <old subject>)' in subject? " t
2214 "Strip `(was: <old subject>)' in subject "
2215 "and use the new one instead?\n\n"
2216 "Current subject is: \""
2218 "New subject would be: \""
2220 "See the variable `message-subject-trailing-was-query' "
2221 "to get rid of this query."
2226 ;;; Suggested by Jonas Steverud @ www.dtek.chalmers.se/~d4jonas/
2228 (defun message-change-subject (new-subject)
2229 "Ask for NEW-SUBJECT header, append (was: <Old Subject>)."
2232 (read-from-minibuffer "New subject: ")))
2233 (cond ((and (not (or (null new-subject) ; new subject not empty
2234 (zerop (string-width new-subject))
2235 (string-match "^[ \t]*$" new-subject))))
2239 (message-narrow-to-headers)
2240 (message-fetch-field "Subject"))))
2241 (cond ((not old-subject)
2242 (error "No current subject"))
2245 (regexp-quote new-subject)
2247 old-subject)) ; yes, it really is a new subject
2248 ;; delete eventual Re: prefix
2250 (message-strip-subject-re old-subject))
2251 (message-goto-subject)
2252 (message-delete-line)
2253 (insert (concat "Subject: "
2256 old-subject ")\n")))))))))
2258 (defun message-mark-inserted-region (beg end &optional verbatim)
2259 "Mark some region in the current article with enclosing tags.
2260 See `message-mark-insert-begin' and `message-mark-insert-end'.
2261 If VERBATIM, use slrn style verbatim marks (\"#v+\" and \"#v-\")."
2262 (interactive "r\nP")
2264 ;; add to the end of the region first, otherwise end would be invalid
2266 (insert (if verbatim "#v-\n" message-mark-insert-end))
2268 (insert (if verbatim "#v+\n" message-mark-insert-begin))))
2270 (defun message-mark-insert-file (file &optional verbatim)
2271 "Insert FILE at point, marking it with enclosing tags.
2272 See `message-mark-insert-begin' and `message-mark-insert-end'.
2273 If VERBATIM, use slrn style verbatim marks (\"#v+\" and \"#v-\")."
2274 (interactive "fFile to insert: \nP")
2275 ;; reverse insertion to get correct result.
2277 (insert (if verbatim "#v-\n" message-mark-insert-end))
2279 (insert-file-contents file)
2281 (insert (if verbatim "#v+\n" message-mark-insert-begin))))
2283 (defun message-add-archive-header ()
2284 "Insert \"X-No-Archive: Yes\" in the header and a note in the body.
2285 The note can be customized using `message-archive-note'. When called with a
2286 prefix argument, ask for a text to insert. If you don't want the note in the
2287 body, set `message-archive-note' to nil."
2289 (if current-prefix-arg
2290 (setq message-archive-note
2291 (read-from-minibuffer "Reason for No-Archive: "
2292 (cons message-archive-note 0))))
2294 (if (message-goto-signature)
2295 (re-search-backward message-signature-separator))
2296 (when message-archive-note
2297 (insert message-archive-note)
2299 (message-add-header message-archive-header)
2300 (message-sort-headers)))
2302 (defun message-cross-post-followup-to-header (target-group)
2303 "Mangles FollowUp-To and Newsgroups header to point to TARGET-GROUP.
2304 With prefix-argument just set Follow-Up, don't cross-post."
2306 (list ; Completion based on Gnus
2307 (completing-read "Followup To: "
2308 (if (boundp 'gnus-newsrc-alist)
2310 nil nil '("poster" . 0)
2311 (if (boundp 'gnus-group-history)
2312 'gnus-group-history))))
2313 (message-remove-header "Follow[Uu]p-[Tt]o" t)
2314 (message-goto-newsgroups)
2316 ;; if we already did a crosspost before, kill old target
2317 (if (and message-cross-post-old-target
2319 (regexp-quote (concat "," message-cross-post-old-target))
2322 ;; unless (followup is to poster or user explicitly asked not
2323 ;; to cross-post, or target-group is already in Newsgroups)
2324 ;; add target-group to Newsgroups line.
2326 ;; def: cross-post, req:no
2327 (and message-cross-post-default (not current-prefix-arg))
2328 ;; def: no-cross-post, req:yes
2329 (and (not message-cross-post-default) current-prefix-arg))
2330 (not (string-match "poster" target-group))
2331 (not (string-match (regexp-quote target-group)
2332 (message-fetch-field "Newsgroups"))))
2334 (insert (concat "," target-group))))
2335 (end-of-line) ; ensure Followup: comes after Newsgroups:
2336 ;; unless new followup would be identical to Newsgroups line
2337 ;; make a new Followup-To line
2338 (if (not (string-match (concat "^[ \t]*"
2341 (message-fetch-field "Newsgroups")))
2342 (insert (concat "\nFollowup-To: " target-group)))
2343 (setq message-cross-post-old-target target-group))
2345 (defun message-cross-post-insert-note (target-group cross-post in-old
2347 "Insert a in message body note about a set Followup or Crosspost.
2348 If there have been previous notes, delete them. TARGET-GROUP specifies the
2349 group to Followup-To. When CROSS-POST is t, insert note about
2350 crossposting. IN-OLD specifies whether TARGET-GROUP is a member of
2351 OLD-GROUPS. OLD-GROUPS lists the old-groups the posting would have
2352 been made to before the user asked for a Crosspost."
2353 ;; start scanning body for previous uses
2354 (message-goto-signature)
2355 (let ((head (re-search-backward
2356 (concat "^" mail-header-separator)
2357 nil t))) ; just search in body
2358 (message-goto-signature)
2359 (while (re-search-backward
2360 (concat "^" (regexp-quote message-cross-post-note) ".*")
2362 (message-delete-line))
2363 (message-goto-signature)
2364 (while (re-search-backward
2365 (concat "^" (regexp-quote message-followup-to-note) ".*")
2367 (message-delete-line))
2369 (if (message-goto-signature)
2370 (re-search-backward message-signature-separator))
2373 (string-match "^[ \t]*poster[ \t]*$" target-group))
2374 (insert (concat message-followup-to-note target-group "\n"))
2375 (insert (concat message-cross-post-note target-group "\n")))))
2377 (defun message-cross-post-followup-to (target-group)
2378 "Crossposts message and set Followup-To to TARGET-GROUP.
2379 With prefix-argument just set Follow-Up, don't cross-post."
2381 (list ; Completion based on Gnus
2382 (completing-read "Followup To: "
2383 (if (boundp 'gnus-newsrc-alist)
2385 nil nil '("poster" . 0)
2386 (if (boundp 'gnus-group-history)
2387 'gnus-group-history))))
2388 (when (fboundp 'gnus-group-real-name)
2389 (setq target-group (gnus-group-real-name target-group)))
2390 (cond ((not (or (null target-group) ; new subject not empty
2391 (zerop (string-width target-group))
2392 (string-match "^[ \t]*$" target-group)))
2394 (let* ((old-groups (message-fetch-field "Newsgroups"))
2395 (in-old (string-match
2396 (regexp-quote target-group)
2397 (or old-groups ""))))
2398 ;; check whether target exactly matches old Newsgroups
2399 (cond ((not old-groups)
2400 (error "No current newsgroup"))
2404 (regexp-quote target-group)
2407 ;; yes, Newsgroups line must change
2408 (message-cross-post-followup-to-header target-group)
2409 ;; insert note whether we do cross-post or followup-to
2410 (funcall message-cross-post-note-function
2412 (if (or (and message-cross-post-default
2413 (not current-prefix-arg))
2414 (and (not message-cross-post-default)
2415 current-prefix-arg)) t)
2416 in-old old-groups))))))))
2418 ;;; Reduce To: to Cc: or Bcc: header
2420 (defun message-reduce-to-to-cc ()
2421 "Replace contents of To: header with contents of Cc: or Bcc: header."
2424 (save-restriction (message-narrow-to-headers)
2425 (message-fetch-field "cc")))
2427 (if (and (not cc-content)
2430 (message-narrow-to-headers)
2431 (message-fetch-field "bcc"))))
2436 (message-delete-line)
2437 (insert (concat "To: " cc-content "\n"))
2439 (message-narrow-to-headers)
2440 (message-remove-header (if bcc
2444 ;;; End of functions adopted from `message-utils.el'.
2446 (defun message-remove-header (header &optional is-regexp first reverse)
2447 "Remove HEADER in the narrowed buffer.
2448 If IS-REGEXP, HEADER is a regular expression.
2449 If FIRST, only remove the first instance of the header.
2450 If REVERSE, remove headers that doesn't match HEADER.
2451 Return the number of headers removed."
2452 (goto-char (point-min))
2453 (let ((regexp (if is-regexp header (concat "^" (regexp-quote header) ":")))
2455 (case-fold-search t)
2457 (while (and (not (eobp))
2460 (not (looking-at regexp))
2461 (looking-at regexp))
2468 ;; There might be a continuation header, so we have to search
2469 ;; until we find a new non-continuation line.
2472 (if (re-search-forward "^[^ \t]" nil t)
2473 (goto-char (match-beginning 0))
2476 (if (re-search-forward "^[^ \t]" nil t)
2477 (goto-char (match-beginning 0))
2478 (goto-char (point-max)))))
2481 (defun message-remove-first-header (header)
2482 "Remove the first instance of HEADER if there is more than one."
2484 (regexp (concat "^" (regexp-quote header) ":")))
2486 (goto-char (point-min))
2487 (while (re-search-forward regexp nil t)
2490 (message-remove-header header nil t)
2493 (defun message-narrow-to-headers ()
2494 "Narrow the buffer to the head of the message."
2497 (goto-char (point-min))
2498 (if (re-search-forward
2499 (concat "^" (regexp-quote mail-header-separator) "\n") nil t)
2502 (goto-char (point-min)))
2504 (defun message-narrow-to-head-1 ()
2505 "Like `message-narrow-to-head'. Don't widen."
2507 (goto-char (point-min))
2508 (if (search-forward "\n\n" nil 1)
2511 (goto-char (point-min)))
2513 ;; FIXME: clarify difference: message-narrow-to-head,
2514 ;; message-narrow-to-headers-or-head, message-narrow-to-headers
2515 (defun message-narrow-to-head ()
2516 "Narrow the buffer to the head of the message.
2517 Point is left at the beginning of the narrowed-to region."
2519 (message-narrow-to-head-1))
2521 (defun message-narrow-to-headers-or-head ()
2522 "Narrow the buffer to the head of the message."
2525 (goto-char (point-min))
2526 (if (re-search-forward (concat "\\(\n\\)\n\\|^\\("
2527 (regexp-quote mail-header-separator)
2530 (or (match-end 1) (match-beginning 2))
2532 (goto-char (point-min)))
2534 (defun message-news-p ()
2535 "Say whether the current buffer contains a news message."
2536 (and (not message-this-is-mail)
2537 (or message-this-is-news
2540 (message-narrow-to-headers)
2541 (and (message-fetch-field "newsgroups")
2542 (not (message-fetch-field "posted-to"))))))))
2544 (defun message-mail-p ()
2545 "Say whether the current buffer contains a mail message."
2546 (and (not message-this-is-news)
2547 (or message-this-is-mail
2550 (message-narrow-to-headers)
2551 (or (message-fetch-field "to")
2552 (message-fetch-field "cc")
2553 (message-fetch-field "bcc")))))))
2555 (defun message-subscribed-p ()
2556 "Say whether we need to insert a MFT header."
2557 (or message-subscribed-regexps
2558 message-subscribed-addresses
2559 message-subscribed-address-file
2560 message-subscribed-address-functions))
2562 (defun message-next-header ()
2563 "Go to the beginning of the next header."
2565 (or (eobp) (forward-char 1))
2566 (not (if (re-search-forward "^[^ \t]" nil t)
2568 (goto-char (point-max)))))
2570 (defun message-sort-headers-1 ()
2571 "Sort the buffer as headers using `message-rank' text props."
2572 (goto-char (point-min))
2575 nil 'message-next-header
2577 (message-next-header)
2581 (or (get-text-property (point) 'message-rank)
2584 (defun message-sort-headers ()
2585 "Sort the headers of the current message according to `message-header-format-alist'."
2589 (let ((max (1+ (length message-header-format-alist)))
2591 (message-narrow-to-headers)
2592 (while (re-search-forward "^[^ \n]+:" nil t)
2594 (match-beginning 0) (1+ (match-beginning 0))
2596 (if (setq rank (length (memq (assq (intern (buffer-substring
2598 (1- (match-end 0))))
2599 message-header-format-alist)
2600 message-header-format-alist)))
2603 (message-sort-headers-1))))
2605 (defun message-kill-address ()
2606 "Kill the address under point."
2608 (let ((start (point)))
2609 (message-skip-to-next-address)
2610 (kill-region start (if (bolp) (1- (point)) (point)))))
2613 (autoload 'Info-goto-node "info")
2614 (defvar mml2015-use)
2616 (defun message-info (&optional arg)
2617 "Display the Message manual.
2619 Prefixed with one \\[universal-argument], display the Emacs MIME
2620 manual. With two \\[universal-argument]'s, display the EasyPG or
2621 PGG manual, depending on the value of `mml2015-use'."
2623 (info (format "(%s)Top"
2627 ((eq arg 4) 'emacs-mime)
2628 ;; `booleanp' only available in Emacs 22+
2629 ((and (not (memq arg '(nil t)))
2643 (defvar message-mode-map nil)
2645 (unless message-mode-map
2646 (setq message-mode-map (make-keymap))
2647 (set-keymap-parent message-mode-map text-mode-map)
2648 (define-key message-mode-map "\C-c?" 'describe-mode)
2650 (define-key message-mode-map "\C-c\C-f\C-t" 'message-goto-to)
2651 (define-key message-mode-map "\C-c\C-f\C-o" 'message-goto-from)
2652 (define-key message-mode-map "\C-c\C-f\C-b" 'message-goto-bcc)
2653 (define-key message-mode-map "\C-c\C-f\C-w" 'message-goto-fcc)
2654 (define-key message-mode-map "\C-c\C-f\C-c" 'message-goto-cc)
2655 (define-key message-mode-map "\C-c\C-f\C-s" 'message-goto-subject)
2656 (define-key message-mode-map "\C-c\C-f\C-r" 'message-goto-reply-to)
2657 (define-key message-mode-map "\C-c\C-f\C-n" 'message-goto-newsgroups)
2658 (define-key message-mode-map "\C-c\C-f\C-d" 'message-goto-distribution)
2659 (define-key message-mode-map "\C-c\C-f\C-f" 'message-goto-followup-to)
2660 (define-key message-mode-map "\C-c\C-f\C-m" 'message-goto-mail-followup-to)
2661 (define-key message-mode-map "\C-c\C-f\C-k" 'message-goto-keywords)
2662 (define-key message-mode-map "\C-c\C-f\C-u" 'message-goto-summary)
2663 (define-key message-mode-map "\C-c\C-f\C-i"
2664 'message-insert-or-toggle-importance)
2665 (define-key message-mode-map "\C-c\C-f\C-a"
2666 'message-generate-unsubscribed-mail-followup-to)
2668 ;; modify headers (and insert notes in body)
2669 (define-key message-mode-map "\C-c\C-fs" 'message-change-subject)
2671 (define-key message-mode-map "\C-c\C-fx" 'message-cross-post-followup-to)
2672 ;; prefix+message-cross-post-followup-to = same w/o cross-post
2673 (define-key message-mode-map "\C-c\C-ft" 'message-reduce-to-to-cc)
2674 (define-key message-mode-map "\C-c\C-fa" 'message-add-archive-header)
2675 ;; mark inserted text
2676 (define-key message-mode-map "\C-c\M-m" 'message-mark-inserted-region)
2677 (define-key message-mode-map "\C-c\M-f" 'message-mark-insert-file)
2679 (define-key message-mode-map "\C-c\C-b" 'message-goto-body)
2680 (define-key message-mode-map "\C-c\C-i" 'message-goto-signature)
2682 (define-key message-mode-map "\C-c\C-t" 'message-insert-to)
2683 (define-key message-mode-map "\C-c\C-fw" 'message-insert-wide-reply)
2684 (define-key message-mode-map "\C-c\C-n" 'message-insert-newsgroups)
2685 (define-key message-mode-map "\C-c\C-l" 'message-to-list-only)
2686 (define-key message-mode-map "\C-c\C-f\C-e" 'message-insert-expires)
2688 (define-key message-mode-map "\C-c\C-u" 'message-insert-or-toggle-importance)
2689 (define-key message-mode-map "\C-c\M-n"
2690 'message-insert-disposition-notification-to)
2692 (define-key message-mode-map "\C-c\C-y" 'message-yank-original)
2693 (define-key message-mode-map "\C-c\M-\C-y" 'message-yank-buffer)
2694 (define-key message-mode-map "\C-c\C-q" 'message-fill-yanked-message)
2695 (define-key message-mode-map "\C-c\C-w" 'message-insert-signature)
2696 (define-key message-mode-map "\C-c\M-h" 'message-insert-headers)
2697 (define-key message-mode-map "\C-c\C-r" 'message-caesar-buffer-body)
2698 (define-key message-mode-map "\C-c\C-o" 'message-sort-headers)
2699 (define-key message-mode-map "\C-c\M-r" 'message-rename-buffer)
2701 (define-key message-mode-map "\C-c\C-c" 'message-send-and-exit)
2702 (define-key message-mode-map "\C-c\C-s" 'message-send)
2703 (define-key message-mode-map "\C-c\C-k" 'message-kill-buffer)
2704 (define-key message-mode-map "\C-c\C-d" 'message-dont-send)
2705 (define-key message-mode-map "\C-c\n" 'gnus-delay-article)
2707 (define-key message-mode-map "\C-c\M-k" 'message-kill-address)
2708 (define-key message-mode-map "\C-c\C-e" 'message-elide-region)
2709 (define-key message-mode-map "\C-c\C-v" 'message-delete-not-region)
2710 (define-key message-mode-map "\C-c\C-z" 'message-kill-to-signature)
2711 (define-key message-mode-map "\M-\r" 'message-newline-and-reformat)
2712 (define-key message-mode-map [remap split-line] 'message-split-line)
2714 (define-key message-mode-map "\C-c\C-a" 'mml-attach-file)
2716 (define-key message-mode-map "\C-a" 'message-beginning-of-line)
2717 (define-key message-mode-map "\t" 'message-tab)
2719 (define-key message-mode-map "\M-n" 'message-display-abbrev))
2722 message-mode-menu message-mode-map "Message Menu."
2724 ["Yank Original" message-yank-original message-reply-buffer]
2725 ["Fill Yanked Message" message-fill-yanked-message t]
2726 ["Insert Signature" message-insert-signature t]
2727 ["Caesar (rot13) Message" message-caesar-buffer-body t]
2728 ["Caesar (rot13) Region" message-caesar-region (message-mark-active-p)]
2729 ["Elide Region" message-elide-region
2730 :active (message-mark-active-p)
2731 :help "Replace text in region with an ellipsis"]
2732 ["Delete Outside Region" message-delete-not-region
2733 :active (message-mark-active-p)
2734 :help "Delete all quoted text outside region"]
2735 ["Kill To Signature" message-kill-to-signature t]
2736 ["Newline and Reformat" message-newline-and-reformat t]
2737 ["Rename buffer" message-rename-buffer t]
2738 ["Spellcheck" ispell-message :help "Spellcheck this message"]
2740 ["Insert Region Marked" message-mark-inserted-region
2741 :active (message-mark-active-p) :help "Mark region with enclosing tags"]
2742 ["Insert File Marked..." message-mark-insert-file
2743 :help "Insert file at point marked with enclosing tags"]
2745 ["Send Message" message-send-and-exit :help "Send this message"]
2746 ["Postpone Message" message-dont-send
2747 :help "File this draft message and exit"]
2748 ["Send at Specific Time..." gnus-delay-article
2749 :help "Ask, then arrange to send message at that time"]
2750 ["Kill Message" message-kill-buffer
2751 :help "Delete this message without sending"]
2753 ["Message manual" message-info :help "Display the Message manual"]))
2756 message-mode-field-menu message-mode-map ""
2758 ["To" message-goto-to t]
2759 ["From" message-goto-from t]
2760 ["Subject" message-goto-subject t]
2761 ["Change subject..." message-change-subject t]
2762 ["Cc" message-goto-cc t]
2763 ["Bcc" message-goto-bcc t]
2764 ["Fcc" message-goto-fcc t]
2765 ["Reply-To" message-goto-reply-to t]
2766 ["Flag As Important" message-insert-importance-high
2767 :help "Mark this message as important"]
2768 ["Flag As Unimportant" message-insert-importance-low
2769 :help "Mark this message as unimportant"]
2771 message-insert-disposition-notification-to
2772 :help "Request a receipt notification"]
2774 ;; (typical) news stuff
2775 ["Summary" message-goto-summary t]
2776 ["Keywords" message-goto-keywords t]
2777 ["Newsgroups" message-goto-newsgroups t]
2778 ["Fetch Newsgroups" message-insert-newsgroups t]
2779 ["Followup-To" message-goto-followup-to t]
2780 ;; ["Followup-To (with note in body)" message-cross-post-followup-to t]
2781 ["Crosspost / Followup-To..." message-cross-post-followup-to t]
2782 ["Distribution" message-goto-distribution t]
2783 ["Expires" message-insert-expires t ]
2784 ["X-No-Archive" message-add-archive-header t ]
2786 ;; (typical) mailing-lists stuff
2787 ["Fetch To" message-insert-to
2788 :help "Insert a To header that points to the author."]
2789 ["Fetch To and Cc" message-insert-wide-reply
2790 :help "Insert To and Cc headers as if you were doing a wide reply."]
2792 ["Send to list only" message-to-list-only t]
2793 ["Mail-Followup-To" message-goto-mail-followup-to t]
2794 ["Unsubscribed list post" message-generate-unsubscribed-mail-followup-to
2795 :help "Insert a reasonable `Mail-Followup-To:' header."]
2796 ["Reduce To: to Cc:" message-reduce-to-to-cc t]
2798 ["Sort Headers" message-sort-headers t]
2799 ["Encode non-ASCII domain names" message-idna-to-ascii-rhs t]
2800 ;; We hide `message-hidden-headers' by narrowing the buffer.
2801 ["Show Hidden Headers" widen t]
2802 ["Goto Body" message-goto-body t]
2803 ["Goto Signature" message-goto-signature t]))
2805 (defvar message-tool-bar-map nil)
2807 (defvar facemenu-add-face-function)
2808 (defvar facemenu-remove-face-function)
2810 ;;; Forbidden properties
2812 ;; We use `after-change-functions' to keep special text properties
2813 ;; that interfere with the normal function of message mode out of the
2816 (defcustom message-strip-special-text-properties t
2817 "Strip special properties from the message buffer.
2819 Emacs has a number of special text properties which can break message
2820 composing in various ways. If this option is set, message will strip
2821 these properties from the message composition buffer. However, some
2822 packages requires these properties to be present in order to work.
2823 If you use one of these packages, turn this option off, and hope the
2824 message composition doesn't break too bad."
2826 :group 'message-various
2827 :link '(custom-manual "(message)Various Message Variables")
2830 (defvar message-forbidden-properties
2831 ;; No reason this should be clutter up customize. We make it a
2832 ;; property list (rather than a list of property symbols), to be
2833 ;; directly useful for `remove-text-properties'.
2834 '(field nil read-only nil invisible nil intangible nil
2835 mouse-face nil modification-hooks nil insert-in-front-hooks nil
2836 insert-behind-hooks nil point-entered nil point-left nil)
2837 ;; Other special properties:
2838 ;; category, face, display: probably doesn't do any harm.
2839 ;; fontified: is used by font-lock.
2840 ;; syntax-table, local-map: I dunno.
2841 "Property list of with properties forbidden in message buffers.
2842 The values of the properties are ignored, only the property names are used.")
2844 (defun message-tamago-not-in-use-p (pos)
2845 "Return t when tamago version 4 is not in use at the cursor position.
2846 Tamago version 4 is a popular input method for writing Japanese text.
2847 It uses the properties `intangible', `invisible', `modification-hooks'
2848 and `read-only' when translating ascii or kana text to kanji text.
2849 These properties are essential to work, so we should never strip them."
2850 (not (and (boundp 'egg-modefull-mode)
2851 (symbol-value 'egg-modefull-mode)
2852 (or (memq (get-text-property pos 'intangible)
2853 '(its-part-1 its-part-2))
2854 (get-text-property pos 'egg-end)
2855 (get-text-property pos 'egg-lang)
2856 (get-text-property pos 'egg-start)))))
2858 (defsubst message-mail-alias-type-p (type)
2859 (if (atom message-mail-alias-type)
2860 (eq message-mail-alias-type type)
2861 (memq type message-mail-alias-type)))
2863 (defun message-strip-forbidden-properties (begin end &optional old-length)
2864 "Strip forbidden properties between BEGIN and END, ignoring the third arg.
2865 This function is intended to be called from `after-change-functions'.
2866 See also `message-forbidden-properties'."
2867 (when (and (message-mail-alias-type-p 'ecomplete)
2868 (memq this-command message-self-insert-commands))
2869 (message-display-abbrev))
2870 (when (and message-strip-special-text-properties
2871 (message-tamago-not-in-use-p begin))
2872 (let ((buffer-read-only nil)
2873 (inhibit-read-only t))
2874 (remove-text-properties begin end message-forbidden-properties))))
2876 (autoload 'ecomplete-setup "ecomplete") ;; for Emacs <23.
2878 (defvar message-smileys '(":-)" ":)"
2881 "A list of recognized smiley faces in `message-mode'.")
2883 (defun message--syntax-propertize (beg end)
2884 "Syntax-propertize certain message text specially."
2885 (let ((citation-regexp (concat "^" message-cite-prefix-regexp ".*$"))
2886 (smiley-regexp (regexp-opt message-smileys)))
2888 (while (search-forward-regexp citation-regexp
2890 (let ((start (match-beginning 0))
2891 (end (match-end 0)))
2892 (add-text-properties start (1+ start)
2893 `(syntax-table ,(string-to-syntax "<")))
2894 (add-text-properties end (min (1+ end) (point-max))
2895 `(syntax-table ,(string-to-syntax ">")))))
2897 (while (search-forward-regexp smiley-regexp
2899 (add-text-properties (match-beginning 0) (match-end 0)
2900 `(syntax-table ,(string-to-syntax "."))))))
2903 (define-derived-mode message-mode text-mode "Message"
2904 "Major mode for editing mail and news to be sent.
2905 Like Text Mode but with these additional commands:\\<message-mode-map>
2906 C-c C-s `message-send' (send the message) C-c C-c `message-send-and-exit'
2907 C-c C-d Postpone sending the message C-c C-k Kill the message
2908 C-c C-f move to a header field (and create it if there isn't):
2909 C-c C-f C-t move to To C-c C-f C-s move to Subject
2910 C-c C-f C-c move to Cc C-c C-f C-b move to Bcc
2911 C-c C-f C-w move to Fcc C-c C-f C-r move to Reply-To
2912 C-c C-f C-u move to Summary C-c C-f C-n move to Newsgroups
2913 C-c C-f C-k move to Keywords C-c C-f C-d move to Distribution
2914 C-c C-f C-o move to From (\"Originator\")
2915 C-c C-f C-f move to Followup-To
2916 C-c C-f C-m move to Mail-Followup-To
2917 C-c C-f C-e move to Expires
2918 C-c C-f C-i cycle through Importance values
2919 C-c C-f s change subject and append \"(was: <Old Subject>)\"
2920 C-c C-f x crossposting with FollowUp-To header and note in body
2921 C-c C-f t replace To: header with contents of Cc: or Bcc:
2922 C-c C-f a Insert X-No-Archive: header and a note in the body
2923 C-c C-t `message-insert-to' (add a To header to a news followup)
2924 C-c C-l `message-to-list-only' (removes all but list address in to/cc)
2925 C-c C-n `message-insert-newsgroups' (add a Newsgroup header to a news reply)
2926 C-c C-b `message-goto-body' (move to beginning of message text).
2927 C-c C-i `message-goto-signature' (move to the beginning of the signature).
2928 C-c C-w `message-insert-signature' (insert `message-signature-file' file).
2929 C-c C-y `message-yank-original' (insert current message, if any).
2930 C-c C-q `message-fill-yanked-message' (fill what was yanked).
2931 C-c C-e `message-elide-region' (elide the text between point and mark).
2932 C-c C-v `message-delete-not-region' (remove the text outside the region).
2933 C-c C-z `message-kill-to-signature' (kill the text up to the signature).
2934 C-c C-r `message-caesar-buffer-body' (rot13 the message body).
2935 C-c C-a `mml-attach-file' (attach a file as MIME).
2936 C-c C-u `message-insert-or-toggle-importance' (insert or cycle importance).
2937 C-c M-n `message-insert-disposition-notification-to' (request receipt).
2938 C-c M-m `message-mark-inserted-region' (mark region with enclosing tags).
2939 C-c M-f `message-mark-insert-file' (insert file marked with enclosing tags).
2940 M-RET `message-newline-and-reformat' (break the line and reformat)."
2941 (set (make-local-variable 'message-reply-buffer) nil)
2942 (set (make-local-variable 'message-inserted-headers) nil)
2943 (set (make-local-variable 'message-send-actions) nil)
2944 (set (make-local-variable 'message-return-action) nil)
2945 (set (make-local-variable 'message-exit-actions) nil)
2946 (set (make-local-variable 'message-kill-actions) nil)
2947 (set (make-local-variable 'message-postpone-actions) nil)
2948 (set (make-local-variable 'message-draft-article) nil)
2949 (setq buffer-offer-save t)
2950 (set (make-local-variable 'facemenu-add-face-function)
2952 (let ((face-fun (cdr (assq face message-face-alist))))
2954 (funcall face-fun (point) end)
2955 (error "Face %s not configured for %s mode" face mode-name)))
2957 (set (make-local-variable 'facemenu-remove-face-function) t)
2958 (set (make-local-variable 'message-reply-headers) nil)
2959 (make-local-variable 'message-newsreader)
2960 (make-local-variable 'message-mailer)
2961 (make-local-variable 'message-post-method)
2962 (set (make-local-variable 'message-sent-message-via) nil)
2963 (set (make-local-variable 'message-checksum) nil)
2964 (set (make-local-variable 'message-mime-part) 0)
2965 (message-setup-fill-variables)
2966 (when message-fill-column
2967 (setq fill-column message-fill-column)
2968 (turn-on-auto-fill))
2969 ;; Allow using comment commands to add/remove quoting.
2970 ;; (set (make-local-variable 'comment-start) message-yank-prefix)
2971 (when message-yank-prefix
2972 (set (make-local-variable 'comment-start) message-yank-prefix)
2973 (set (make-local-variable 'comment-start-skip)
2974 (concat "^" (regexp-quote message-yank-prefix) "[ \t]*")))
2975 (set (make-local-variable 'font-lock-defaults)
2976 '(message-font-lock-keywords t))
2977 (if (boundp 'tool-bar-map)
2978 (set (make-local-variable 'tool-bar-map) (message-make-tool-bar)))
2979 (easy-menu-add message-mode-menu message-mode-map)
2980 (easy-menu-add message-mode-field-menu message-mode-map)
2981 ;; Mmmm... Forbidden properties...
2982 (add-hook 'after-change-functions 'message-strip-forbidden-properties
2984 ;; Allow mail alias things.
2986 ((message-mail-alias-type-p 'abbrev)
2987 (mail-abbrevs-setup))
2988 ((message-mail-alias-type-p 'ecomplete)
2990 (add-hook 'completion-at-point-functions 'message-completion-function nil t)
2991 (unless buffer-file-name
2992 (message-set-auto-save-file-name))
2993 (unless (buffer-base-buffer)
2994 ;; Don't enable multibyte on an indirect buffer. Maybe enabling
2995 ;; multibyte is not necessary at all. -- zsh
2996 (mm-enable-multibyte))
2997 (set (make-local-variable 'indent-tabs-mode) nil) ;No tabs for indentation.
2999 ;; Syntactic fontification. Helps `show-paren-mode',
3000 ;; `electric-pair-mode', and C-M-* navigation by syntactically
3001 ;; excluding citations and other artifacts.
3003 (set (make-local-variable 'syntax-propertize-function) 'message--syntax-propertize)
3004 (set (make-local-variable 'parse-sexp-ignore-comments) t))
3006 (defun message-setup-fill-variables ()
3007 "Setup message fill variables."
3008 (set (make-local-variable 'fill-paragraph-function)
3009 'message-fill-paragraph)
3010 (make-local-variable 'paragraph-separate)
3011 (make-local-variable 'paragraph-start)
3012 (make-local-variable 'adaptive-fill-regexp)
3013 (make-local-variable 'adaptive-fill-first-line-regexp)
3014 (let ((quote-prefix-regexp
3015 ;; User should change message-cite-prefix-regexp if
3016 ;; message-yank-prefix is set to an abnormal value.
3017 (concat "\\(" message-cite-prefix-regexp "\\)[ \t]*")))
3018 (setq paragraph-start
3020 (regexp-quote mail-header-separator) "$\\|"
3021 "[ \t]*$\\|" ; blank lines
3022 "-- $\\|" ; signature delimiter
3023 "---+$\\|" ; delimiters for forwarded messages
3024 page-delimiter "$\\|" ; spoiler warnings
3025 ".*wrote:$\\|" ; attribution lines
3026 quote-prefix-regexp "$\\|" ; empty lines in quoted text
3028 "<#!*/?\\(multipart\\|part\\|external\\|mml\\|secure\\)"))
3029 (setq paragraph-separate paragraph-start)
3030 (setq adaptive-fill-regexp
3031 (concat quote-prefix-regexp "\\|" adaptive-fill-regexp))
3032 (setq adaptive-fill-first-line-regexp
3033 (concat quote-prefix-regexp "\\|"
3034 adaptive-fill-first-line-regexp)))
3035 (make-local-variable 'auto-fill-inhibit-regexp)
3036 ;;(setq auto-fill-inhibit-regexp "^[A-Z][^: \n\t]+:")
3037 (setq auto-fill-inhibit-regexp nil)
3038 (make-local-variable 'normal-auto-fill-function)
3039 (setq normal-auto-fill-function 'message-do-auto-fill)
3040 ;; KLUDGE: auto fill might already be turned on in `text-mode-hook'.
3041 ;; In that case, ensure that it uses the right function. The real
3042 ;; solution would be not to use `define-derived-mode', and run
3043 ;; `text-mode-hook' ourself at the end of the mode.
3044 ;; -- Per Abrahamsen <abraham@dina.kvl.dk> Date: 2001-10-19.
3045 ;; This kludge is unneeded in Emacs>=21 since define-derived-mode is
3046 ;; now careful to run parent hooks after the body. --Stef
3047 (when auto-fill-function
3048 (setq auto-fill-function normal-auto-fill-function)))
3053 ;;; Message mode commands
3056 ;;; Movement commands
3058 (defun message-goto-to ()
3059 "Move point to the To header."
3062 (message-position-on-field "To"))
3064 (defun message-goto-from ()
3065 "Move point to the From header."
3068 (message-position-on-field "From"))
3070 (defun message-goto-subject ()
3071 "Move point to the Subject header."
3074 (message-position-on-field "Subject"))
3076 (defun message-goto-cc ()
3077 "Move point to the Cc header."
3080 (message-position-on-field "Cc" "To"))
3082 (defun message-goto-bcc ()
3083 "Move point to the Bcc header."
3086 (message-position-on-field "Bcc" "Cc" "To"))
3088 (defun message-goto-fcc ()
3089 "Move point to the Fcc header."
3092 (message-position-on-field "Fcc" "To" "Newsgroups"))
3094 (defun message-goto-reply-to ()
3095 "Move point to the Reply-To header."
3098 (message-position-on-field "Reply-To" "Subject"))
3100 (defun message-goto-newsgroups ()
3101 "Move point to the Newsgroups header."
3104 (message-position-on-field "Newsgroups"))
3106 (defun message-goto-distribution ()
3107 "Move point to the Distribution header."
3110 (message-position-on-field "Distribution"))
3112 (defun message-goto-followup-to ()
3113 "Move point to the Followup-To header."
3116 (message-position-on-field "Followup-To" "Newsgroups"))
3118 (defun message-goto-mail-followup-to ()
3119 "Move point to the Mail-Followup-To header."
3122 (message-position-on-field "Mail-Followup-To" "To"))
3124 (defun message-goto-keywords ()
3125 "Move point to the Keywords header."
3128 (message-position-on-field "Keywords" "Subject"))
3130 (defun message-goto-summary ()
3131 "Move point to the Summary header."
3134 (message-position-on-field "Summary" "Subject"))
3136 (defun message-goto-body ()
3137 "Move point to the beginning of the message body."
3139 (when (and (called-interactively-p 'any)
3140 (looking-at "[ \t]*\n"))
3143 (goto-char (point-min))
3144 (or (search-forward (concat "\n" mail-header-separator "\n") nil t)
3145 (search-forward-regexp "[^:]+:\\([^\n]\\|\n[ \t]\\)+\n\n" nil t)))
3147 (defun message-in-body-p ()
3148 "Return t if point is in the message body."
3151 (goto-char (point-min))
3152 (or (search-forward (concat "\n" mail-header-separator "\n") nil t)
3153 (search-forward-regexp "[^:]+:\\([^\n]\\|\n[ \t]\\)+\n\n" nil t))
3156 (defun message-goto-eoh ()
3157 "Move point to the end of the headers."
3162 (defun message-goto-signature ()
3163 "Move point to the beginning of the message signature.
3164 If there is no signature in the article, go to the end and
3168 (goto-char (point-min))
3169 (if (re-search-forward message-signature-separator nil t)
3171 (goto-char (point-max))
3174 (defun message-generate-unsubscribed-mail-followup-to (&optional include-cc)
3175 "Insert a reasonable MFT header in a post to an unsubscribed list.
3176 When making original posts to a mailing list you are not subscribed to,
3177 you have to type in a MFT header by hand. The contents, usually, are
3178 the addresses of the list and your own address. This function inserts
3179 such a header automatically. It fetches the contents of the To: header
3180 in the current mail buffer, and appends the current `user-mail-address'.
3182 If the optional argument INCLUDE-CC is non-nil, the addresses in the
3183 Cc: header are also put into the MFT."
3188 (message-narrow-to-headers)
3189 (message-remove-header "Mail-Followup-To")
3190 (setq cc (and include-cc (message-fetch-field "Cc")))
3192 (concat (message-fetch-field "To") "," cc)
3193 (message-fetch-field "To"))))
3194 (message-goto-mail-followup-to)
3195 (insert (concat tos ", " user-mail-address))))
3199 (defun message-insert-to (&optional force)
3200 "Insert a To header that points to the author of the article being replied to.
3201 If the original author requested not to be sent mail, don't insert unless the
3202 prefix FORCE is given."
3204 (let* ((mct (message-fetch-reply-field "mail-copies-to"))
3205 (dont (and mct (or (equal (downcase mct) "never")
3206 (equal (downcase mct) "nobody"))))
3207 (to (or (message-fetch-reply-field "mail-reply-to")
3208 (message-fetch-reply-field "reply-to")
3209 (message-fetch-reply-field "from"))))
3213 "Ignoring the user request not to have copies sent via mail"
3214 "Complying with the user request not to have copies sent via mail")))
3215 (when (and force (not to))
3216 (error "No mail address in the article"))
3217 (when (and to (or force (not dont)))
3218 (message-carefully-insert-headers (list (cons 'To to))))))
3220 (defun message-insert-wide-reply ()
3221 "Insert To and Cc headers as if you were doing a wide reply."
3223 (let ((headers (message-with-reply-buffer
3224 (message-get-reply-headers t))))
3225 (message-carefully-insert-headers headers)))
3227 (defcustom message-header-synonyms
3230 "List of lists of header synonyms.
3231 E.g., if this list contains a member list with elements `Cc' and `To',
3232 then `message-carefully-insert-headers' will not insert a `To' header
3233 when the message is already `Cc'ed to the recipient."
3235 :group 'message-headers
3236 :link '(custom-manual "(message)Message Headers")
3237 :type '(repeat sexp))
3239 (defun message-carefully-insert-headers (headers)
3240 "Insert the HEADERS, an alist, into the message buffer.
3241 Does not insert the headers when they are already present there
3242 or in the synonym headers, defined by `message-header-synonyms'."
3243 ;; FIXME: Should compare only the address and not the full name. Comparison
3244 ;; should be done case-folded (and with `string=' rather than
3246 ;; (mail-strip-quoted-names "Foo Bar <foo@bar>, bla@fasel (Bla Fasel)")
3247 (dolist (header headers)
3248 (let* ((header-name (symbol-name (car header)))
3249 (new-header (cdr header))
3250 (synonyms (loop for synonym in message-header-synonyms
3251 when (memq (car header) synonym) return synonym))
3253 (loop for synonym in synonyms
3254 for old-header = (mail-fetch-field (symbol-name synonym))
3255 when (and old-header (string-match new-header old-header))
3258 (message "already have `%s' in `%s'" new-header old-header)
3259 (when (and (message-position-on-field header-name)
3260 (setq old-header (mail-fetch-field header-name))
3261 (not (string-match "\\` *\\'" old-header)))
3263 (insert new-header)))))
3265 (defun message-widen-reply ()
3266 "Widen the reply to include maximum recipients."
3269 (and (bufferp message-reply-buffer)
3270 (buffer-name message-reply-buffer)
3271 (with-current-buffer message-reply-buffer
3272 (message-get-reply-headers t)))))
3275 (message-narrow-to-headers)
3276 (dolist (elem follow-to)
3277 (message-remove-header (symbol-name (car elem)))
3278 (goto-char (point-min))
3279 (insert (symbol-name (car elem)) ": "
3280 (cdr elem) "\n"))))))
3282 (defun message-insert-newsgroups ()
3283 "Insert the Newsgroups header from the article being replied to."
3285 (let ((old-newsgroups (mail-fetch-field "newsgroups"))
3286 (new-newsgroups (message-fetch-reply-field "newsgroups"))
3289 (message-position-on-field "Newsgroups")
3291 ((not new-newsgroups)
3292 (error "No Newsgroups to insert"))
3293 ((not old-newsgroups)
3294 (insert new-newsgroups))
3296 (setq new-newsgroups (split-string new-newsgroups "[, ]+")
3297 old-newsgroups (split-string old-newsgroups "[, ]+"))
3298 (dolist (group new-newsgroups)
3299 (unless (member group old-newsgroups)
3300 (push group insert-newsgroups)))
3301 (if (null insert-newsgroups)
3302 (error "Newgroup%s already in the header"
3303 (if (> (length new-newsgroups) 1)
3305 (when old-newsgroups
3307 (dolist (group insert-newsgroups)
3311 (insert group)))))))
3315 ;;; Various commands
3317 (defun message-delete-not-region (beg end)
3318 "Delete everything in the body of the current message outside of the region."
3323 ;; snarf citation prefix, if appropriate
3324 (unless (eq (point) (progn (beginning-of-line) (point)))
3325 (when (looking-at message-cite-prefix-regexp)
3326 (setq citeprefix (match-string 0))))
3328 (delete-region (point) (if (not (message-goto-signature))
3334 (delete-region beg (progn (message-goto-body)
3338 (insert citeprefix))))
3339 (when (message-goto-signature)
3342 (defun message-kill-to-signature (&optional arg)
3343 "Kill all text up to the signature.
3344 If a numeric argument or prefix arg is given, leave that number
3345 of lines before the signature intact."
3349 (let ((point (point)))
3350 (narrow-to-region point (point-max))
3351 (message-goto-signature)
3353 (if (and arg (numberp arg))
3354 (forward-line (- -1 arg))
3356 (unless (= point (point))
3357 (kill-region point (point))
3361 (defun message-newline-and-reformat (&optional arg not-break)
3362 "Insert four newlines, and then reformat if inside quoted text.
3363 Prefix arg means justify as well."
3364 (interactive (list (if current-prefix-arg 'full)))
3365 (let (quoted point beg end leading-space bolp fill-paragraph-function)
3366 (setq point (point))
3369 (setq bolp (= beg point))
3370 ;; Find first line of the paragraph.
3372 (while (and (not (eobp))
3373 (not (looking-at message-cite-prefix-regexp))
3374 (looking-at paragraph-start))
3377 (when (looking-at message-cite-prefix-regexp)
3378 (setq quoted (match-string 0))
3379 (goto-char (match-end 0))
3380 (looking-at "[ \t]*")
3381 (setq leading-space (match-string 0)))
3385 (< (- point beg) (length quoted)))
3386 ;; break inside the cite prefix.
3392 (while (and (not (eobp))
3393 (not (looking-at paragraph-separate))
3394 (looking-at message-cite-prefix-regexp)
3395 (equal quoted (match-string 0)))
3396 (goto-char (match-end 0))
3397 (looking-at "[ \t]*")
3398 (if (> (length leading-space) (length (match-string 0)))
3399 (setq leading-space (match-string 0)))
3403 (while (and (if (bobp) nil (forward-line -1) t)
3404 (not (looking-at paragraph-start))
3405 (looking-at message-cite-prefix-regexp)
3406 (equal quoted (match-string 0)))
3408 (goto-char (match-end 0))
3409 (looking-at "[ \t]*")
3410 (if (> (length leading-space) (length (match-string 0)))
3411 (setq leading-space (match-string 0)))))
3412 (while (and (not (eobp))
3413 (not (looking-at paragraph-separate))
3414 (not (looking-at message-cite-prefix-regexp)))
3418 (while (and (if (bobp) nil (forward-line -1) t)
3419 (not (looking-at paragraph-start))
3420 (not (looking-at message-cite-prefix-regexp)))
3421 (setq beg (point))))
3424 (narrow-to-region beg end)
3431 (setq point (point))
3432 ;; (newline 2) doesn't mark both newline's as hard, so call
3433 ;; newline twice. -jas
3436 (delete-region (point) (re-search-forward "[ \t]*"))
3437 (when (and quoted (not bolp))
3438 (insert quoted leading-space)))
3441 (let* ((adaptive-fill-regexp
3442 (regexp-quote (concat quoted leading-space)))
3443 (adaptive-fill-first-line-regexp
3444 adaptive-fill-regexp ))
3445 (fill-paragraph arg))
3446 (fill-paragraph arg))
3447 (if point (goto-char point)))))
3449 (defun message-fill-paragraph (&optional arg)
3450 "Message specific function to fill a paragraph.
3451 This function is used as the value of `fill-paragraph-function' in
3452 Message buffers and is not meant to be called directly."
3453 (interactive (list (if current-prefix-arg 'full)))
3454 (if (message-point-in-header-p)
3455 (message-fill-field)
3456 (message-newline-and-reformat arg t))
3459 (defun message-point-in-header-p ()
3460 "Return t if point is in the header."
3464 (let ((bound (+ (point-at-eol) 1)) case-fold-search)
3465 (goto-char (point-min))
3466 (not (search-forward (concat "\n" mail-header-separator "\n")
3469 (defun message-do-auto-fill ()
3470 "Like `do-auto-fill', but don't fill in message header."
3471 (unless (message-point-in-header-p)
3474 (defun message-insert-signature (&optional force)
3475 "Insert a signature. See documentation for variable `message-signature'."
3476 (interactive (list 0))
3479 ((and (null message-signature)
3482 (goto-char (point-max))
3483 (not (re-search-backward message-signature-separator nil t))))
3484 ((and (null message-signature)
3487 ((functionp message-signature)
3488 (funcall message-signature))
3489 ((listp message-signature)
3490 (eval message-signature))
3491 (t message-signature)))
3494 (cond ((stringp signature)
3496 ((and (eq t signature) message-signature-file)
3497 (setq signature-file
3498 (if (and message-signature-directory
3499 ;; don't actually use the signature directory
3500 ;; if message-signature-file contains a path.
3501 (not (file-name-directory
3502 message-signature-file)))
3503 (expand-file-name message-signature-file
3504 message-signature-directory)
3505 message-signature-file))
3506 (file-exists-p signature-file))))
3508 (goto-char (point-max))
3509 ;; Insert the signature.
3512 (when message-signature-insert-empty-line
3516 (if (eq signature t)
3517 (insert-file-contents signature-file)
3519 (goto-char (point-max))
3520 (or (bolp) (newline)))))
3522 (defun message-insert-importance-high ()
3523 "Insert header to mark message as important."
3527 (message-narrow-to-headers)
3528 (message-remove-header "Importance"))
3530 (insert "Importance: high\n")))
3532 (defun message-insert-importance-low ()
3533 "Insert header to mark message as unimportant."
3537 (message-narrow-to-headers)
3538 (message-remove-header "Importance"))
3540 (insert "Importance: low\n")))
3542 (defun message-insert-or-toggle-importance ()
3543 "Insert a \"Importance: high\" header, or cycle through the header values.
3544 The three allowed values according to RFC 1327 are `high', `normal'
3551 (message-narrow-to-headers)
3552 (when (setq cur (message-fetch-field "Importance"))
3553 (message-remove-header "Importance")
3554 (setq new (cond ((string= cur "high")
3556 ((string= cur "low")
3561 (insert (format "Importance: %s\n" new)))))
3563 (defun message-insert-disposition-notification-to ()
3564 "Request a disposition notification (return receipt) to this message.
3565 Note that this should not be used in newsgroups."
3569 (message-narrow-to-headers)
3570 (message-remove-header "Disposition-Notification-To"))
3572 (insert (format "Disposition-Notification-To: %s\n"
3573 (or (message-field-value "Reply-to")
3574 (message-field-value "From")
3575 (message-make-from))))))
3577 (defun message-elide-region (b e)
3578 "Elide the text in the region.
3579 An ellipsis (from `message-elide-ellipsis') will be inserted where the
3582 (let ((lines (count-lines b e))
3585 (insert (format-spec message-elide-ellipsis
3589 (defvar message-caesar-translation-table nil)
3591 (defun message-caesar-region (b e &optional n)
3592 "Caesar rotate region B to E by N, default 13, for decrypting netnews."
3595 (min (point) (or (mark t) (point)))
3596 (max (point) (or (mark t) (point)))
3597 (when current-prefix-arg
3598 (prefix-numeric-value current-prefix-arg))))
3600 (setq n (if (numberp n) (mod n 26) 13)) ;canonize N
3601 (unless (or (zerop n) ; no action needed for a rot of 0
3602 (= b e)) ; no region to rotate
3603 ;; We build the table, if necessary.
3604 (when (or (not message-caesar-translation-table)
3605 (/= (aref message-caesar-translation-table ?a) (+ ?a n)))
3606 (setq message-caesar-translation-table
3607 (message-make-caesar-translation-table n)))
3608 (translate-region b e message-caesar-translation-table)))
3610 (defun message-make-caesar-translation-table (n)
3611 "Create a rot table with offset N."
3613 (table (make-string 256 0)))
3614 (while (< (incf i) 256)
3617 (substring table 0 ?A)
3618 (substring table (+ ?A n) (+ ?A n (- 26 n)))
3619 (substring table ?A (+ ?A n))
3620 (substring table (+ ?A 26) ?a)
3621 (substring table (+ ?a n) (+ ?a n (- 26 n)))
3622 (substring table ?a (+ ?a n))
3623 (substring table (+ ?a 26) 255))))
3625 (defun message-caesar-buffer-body (&optional rotnum wide)
3626 "Caesar rotate all letters in the current buffer by 13 places.
3627 Used to encode/decode possibly offensive messages (commonly in rec.humor).
3628 With prefix arg, specifies the number of places to rotate each letter forward.
3629 Mail and USENET news headers are not rotated unless WIDE is non-nil."
3630 (interactive (if current-prefix-arg
3631 (list (prefix-numeric-value current-prefix-arg))
3635 (when (and (not wide) (message-goto-body))
3636 (narrow-to-region (point) (point-max)))
3637 (message-caesar-region (point-min) (point-max) rotnum))))
3639 (defun message-pipe-buffer-body (program)
3640 "Pipe the message body in the current buffer through PROGRAM."
3643 (when (message-goto-body)
3644 (narrow-to-region (point) (point-max)))
3645 (shell-command-on-region
3646 (point-min) (point-max) program nil t))))
3648 (defun message-rename-buffer (&optional enter-string)
3649 "Rename the *message* buffer to \"*message* RECIPIENT\".
3650 If the function is run with a prefix, it will ask for a new buffer
3651 name, rather than giving an automatic name."
3652 (interactive "Pbuffer name: ")
3655 (goto-char (point-min))
3656 (narrow-to-region (point)
3657 (search-forward mail-header-separator nil 'end))
3659 (if (message-news-p) (message-fetch-field "Newsgroups")
3660 (message-fetch-field "To"))
3663 (if (string-match "," mail-to)
3664 (concat (substring mail-to 0 (match-beginning 0)) ", ...")
3666 (name-default (concat "*message* " mail-trimmed-to))
3667 (name (if enter-string
3668 (read-string "New buffer name: " name-default)
3670 (rename-buffer name t)))))
3672 (defun message-fill-yanked-message (&optional justifyp)
3673 "Fill the paragraphs of a message yanked into this one.
3674 Numeric argument means justify as well."
3677 (goto-char (point-min))
3678 (search-forward (concat "\n" mail-header-separator "\n") nil t)
3679 (let ((fill-prefix message-yank-prefix))
3680 (fill-individual-paragraphs (point) (point-max) justifyp))))
3682 (defun message-indent-citation (&optional start end yank-only)
3683 "Modify text just inserted from a message to be cited.
3684 The inserted text should be the region.
3685 When this function returns, the region is again around the modified text.
3687 Normally, indent each nonblank line `message-indentation-spaces' spaces.
3688 However, if `message-yank-prefix' is non-nil, insert that prefix on each line."
3689 (unless start (setq start (point)))
3691 ;; Remove unwanted headers.
3692 (when message-ignored-cited-headers
3697 (if (search-forward "\n\n" nil t)
3700 (message-remove-header message-ignored-cited-headers t)
3701 (when (= (point-min) (point-max))
3702 (setq all-removed t))
3703 (goto-char (point-max)))
3707 ;; Delete blank lines at the start of the buffer.
3708 (while (and (point-min)
3711 (message-delete-line))
3712 ;; Delete blank lines at the end of the buffer.
3713 (goto-char (point-max))
3714 (unless (eq (preceding-char) ?\n)
3716 (while (and (zerop (forward-line -1))
3718 (message-delete-line)))
3719 ;; Do the indentation.
3720 (if (null message-yank-prefix)
3721 (indent-rigidly start (or end (mark t)) message-indentation-spaces)
3724 (while (< (point) (or end (mark t)))
3725 (cond ((looking-at ">")
3726 (insert message-yank-cited-prefix))
3728 (insert message-yank-empty-prefix))
3730 (insert message-yank-prefix)))
3734 (defun message-remove-blank-cited-lines (&optional remove)
3735 "Remove cited lines containing only blanks.
3736 If REMOVE is non-nil, remove newlines, too.
3738 To use this automatically, you may add this function to
3739 `gnus-message-setup-hook'."
3741 (let ((citexp (concat "^\\("
3742 (concat message-yank-cited-prefix "\\|")
3745 (message "Removing `%s'" citexp)
3748 (while (re-search-forward citexp nil t)
3749 (replace-match (if remove "" "\n"))))))
3751 (defun message--yank-original-internal (arg)
3752 (let ((modified (buffer-modified-p))
3754 (when (and message-reply-buffer
3755 message-cite-function)
3756 (when (equal message-cite-reply-position 'above)
3759 (buffer-substring (message-goto-body)
3761 (delete-region (message-goto-body) (point-max))))
3762 (if (bufferp message-reply-buffer)
3763 (delete-windows-on message-reply-buffer t))
3764 (push-mark (save-excursion
3766 ((bufferp message-reply-buffer)
3767 (insert-buffer-substring message-reply-buffer))
3768 ((and (consp message-reply-buffer)
3769 (functionp (car message-reply-buffer)))
3770 (apply (car message-reply-buffer)
3771 (cdr message-reply-buffer))))
3776 (funcall message-cite-function)
3777 (unless (eq (char-before (mark t)) ?\n)
3779 (goto-char (mark t))
3780 (insert-before-markers ?\n)
3782 (case message-cite-reply-position
3786 (insert (if (bolp) "\n" "\n\n"))
3787 (message-goto-body))
3789 (message-goto-signature)))
3790 ;; Add a `message-setup-very-last-hook' here?
3791 ;; Add `gnus-article-highlight-citation' here?
3793 (setq message-checksum (message-checksum))))))
3795 (defun message-yank-original (&optional arg)
3796 "Insert the message being replied to, if any.
3797 Puts point before the text and mark after.
3798 Normally indents each nonblank line ARG spaces (default 3). However,
3799 if `message-yank-prefix' is non-nil, insert that prefix on each line.
3801 This function uses `message-cite-function' to do the actual citing.
3803 Just \\[universal-argument] as argument means don't indent, insert no
3804 prefix, and don't delete any headers."
3806 ;; eval the let forms contained in message-cite-style
3808 `(let ,(if (symbolp message-cite-style)
3809 (symbol-value message-cite-style)
3811 (message--yank-original-internal ',arg))))
3813 (defun message-yank-buffer (buffer)
3814 "Insert BUFFER into the current buffer and quote it."
3815 (interactive "bYank buffer: ")
3816 (let ((message-reply-buffer (get-buffer buffer)))
3817 (save-window-excursion
3818 (message-yank-original))))
3820 (defun message-buffers ()
3821 "Return a list of active message buffers."
3823 (save-current-buffer
3824 (dolist (buffer (buffer-list t))
3826 (when (and (derived-mode-p 'message-mode)
3827 (null message-sent-message-via))
3828 (push (buffer-name buffer) buffers))))
3829 (nreverse buffers)))
3831 (defun message-cite-original-1 (strip-signature)
3832 "Cite an original message.
3833 If STRIP-SIGNATURE is non-nil, strips off the signature from the
3836 This function uses `mail-citation-hook' if that is non-nil."
3837 (if (and (boundp 'mail-citation-hook)
3839 (run-hooks 'mail-citation-hook)
3840 (let* ((start (point))
3844 (when message-indent-citation-function
3845 (if (listp message-indent-citation-function)
3846 message-indent-citation-function
3847 (list message-indent-citation-function))))
3848 ;; This function may be called by `gnus-summary-yank-message' and
3849 ;; may insert a different article from the original. So, we will
3850 ;; modify the value of `message-reply-headers' with that article.
3851 (message-reply-headers
3853 (narrow-to-region start end)
3854 (message-narrow-to-head-1)
3855 (setq x-no-archive (message-fetch-field "x-no-archive"))
3857 (or (message-fetch-field "subject") "none")
3858 (or (message-fetch-field "from") "nobody")
3859 (message-fetch-field "date")
3860 (message-fetch-field "message-id" t)
3861 (message-fetch-field "references")
3863 (mml-quote-region start end)
3864 (when strip-signature
3868 (when (re-search-backward message-signature-separator start t)
3869 ;; Also peel off any blank lines before the signature.
3871 (while (looking-at "^[ \t]*$")
3874 (delete-region (point) end)
3875 (unless (search-backward "\n\n" start t)
3876 ;; Insert a blank line if it is peeled off.
3879 (mapc 'funcall functions)
3880 (when message-citation-line-function
3883 (funcall message-citation-line-function))
3884 (when (and x-no-archive
3885 (not message-cite-articles-with-x-no-archive)
3886 (string-match "yes" x-no-archive))
3888 (delete-region (point) (mark t))
3889 (insert "> [Quoted text removed due to X-No-Archive]\n")
3891 (forward-line -1)))))
3893 (defun message-cite-original ()
3894 "Cite function in the standard Message manner."
3895 (message-cite-original-1 nil))
3897 (autoload 'format-spec "format-spec")
3898 (autoload 'gnus-date-get-time "gnus-util")
3900 (defun message-insert-formatted-citation-line (&optional from date tz)
3901 "Function that inserts a formatted citation line.
3902 The optional FROM, and DATE are strings containing the contents of
3903 the From header and the Date header respectively. The optional TZ
3904 is a number of seconds, overrides the time zone of DATE.
3906 See `message-citation-line-format'."
3907 ;; The optional args are for testing/debugging. They will disappear later.
3909 ;; (with-temp-buffer
3910 ;; (message-insert-formatted-citation-line
3911 ;; "John Doe <john.doe@example.invalid>"
3912 ;; (message-make-date))
3914 (when (or message-reply-headers (and from date))
3916 (setq from (mail-header-from message-reply-headers)))
3917 (let* ((data (condition-case ()
3918 (funcall (if (boundp 'gnus-extract-address-components)
3919 gnus-extract-address-components
3920 'mail-extract-address-components)
3926 (net (car (cdr data)))
3927 (name-or-net (or (car data)
3928 (car (cdr data)) from))
3930 (when (string-match "%[^fnNFL]" message-citation-line-format)
3931 (cond ((numberp (car-safe date)) date) ;; backward compatibility
3932 (date (gnus-date-get-time date))
3935 (setq date (mail-header-date message-reply-headers)))))))
3937 (when (stringp date)
3938 (nth 8 (parse-time-string date)))))
3941 (when (stringp name)
3942 ;; Guess first name and last name:
3947 (if (string-match "\\`\\(\\w\\|[-.]\\)+\\'"
3951 (split-string name "[ \t]+"))))
3952 (count (length names)))
3954 (setq fname (car names)
3956 ((or (= count 2) (= count 3))
3957 (setq fname (car names)
3958 lname (mapconcat 'identity (cdr names) " ")))
3960 (setq fname (mapconcat 'identity
3961 (butlast names (- count 2))
3963 lname (mapconcat 'identity
3966 (when (string-match "\\(.*\\),\\'" fname)
3967 (let ((newlname (match-string 1 fname)))
3968 (setq fname lname lname newlname)))))
3969 ;; The following letters are not used in `format-time-string':
3970 (push ?E lst) (push "<E>" lst)
3971 (push ?F lst) (push (or fname name-or-net) lst)
3972 ;; We might want to use "" instead of "<X>" later.
3973 (push ?J lst) (push "<J>" lst)
3974 (push ?K lst) (push "<K>" lst)
3975 (push ?L lst) (push lname lst)
3976 (push ?N lst) (push name-or-net lst)
3977 (push ?O lst) (push "<O>" lst)
3978 (push ?P lst) (push "<P>" lst)
3979 (push ?Q lst) (push "<Q>" lst)
3980 (push ?f lst) (push from lst)
3981 (push ?i lst) (push "<i>" lst)
3982 (push ?n lst) (push net lst)
3983 (push ?o lst) (push "<o>" lst)
3984 (push ?q lst) (push "<q>" lst)
3985 (push ?t lst) (push "<t>" lst)
3986 (push ?v lst) (push "<v>" lst)
3987 ;; Delegate the rest to `format-time-string':
3989 (when (and (not (memq i lst))
3994 (push (condition-case nil
3995 (gmm-format-time-string (format "%%%c" i) time tz)
3996 (error (format ">%c<" i)))
4000 (spec (apply 'format-spec-make flist)))
4001 (insert (format-spec message-citation-line-format spec)))
4004 (defun message-cite-original-without-signature ()
4005 "Cite function in the standard Message manner.
4006 This function strips off the signature from the original message."
4007 (message-cite-original-1 t))
4009 (defun message-insert-citation-line ()
4010 "Insert a simple citation line."
4011 (when message-reply-headers
4012 (insert (mail-header-from message-reply-headers) " writes:")
4016 (defun message-position-on-field (header &rest afters)
4017 (let ((case-fold-search t))
4020 (goto-char (point-min))
4023 (concat "^" (regexp-quote mail-header-separator) "$"))
4024 (match-beginning 0)))
4025 (goto-char (point-min))
4026 (if (re-search-forward (concat "^" (regexp-quote header) ":") nil t)
4028 (re-search-forward "^[^ \t]" nil 'move)
4030 (skip-chars-backward "\n")
4033 (not (re-search-forward
4034 (concat "^" (regexp-quote (car afters)) ":")
4038 (re-search-forward "^[^ \t]" nil 'move)
4039 (beginning-of-line))
4040 (insert header ": \n")
4047 ;;; Sending messages
4050 (defun message-send-and-exit (&optional arg)
4051 "Send message like `message-send', then, if no errors, exit from mail buffer.
4052 The usage of ARG is defined by the instance that called Message.
4053 It should typically alter the sending method in some way or other."
4055 (let ((buf (current-buffer))
4056 (actions message-exit-actions))
4057 (when (and (message-send arg)
4060 (if message-kill-buffer-on-exit
4062 (message-do-actions actions)
4065 (defun message-dont-send ()
4066 "Don't send the message you have been editing.
4067 Instead, just auto-save the buffer and then bury it."
4069 (set-buffer-modified-p t)
4071 (let ((actions message-postpone-actions))
4072 (message-bury (current-buffer))
4073 (message-do-actions actions)))
4075 (defun message-kill-buffer ()
4076 "Kill the current buffer."
4078 (when (or (not (buffer-modified-p))
4079 (not message-kill-buffer-query)
4080 (yes-or-no-p "Message modified; kill anyway? "))
4081 (let ((actions message-kill-actions)
4082 (draft-article message-draft-article)
4083 (auto-save-file-name buffer-auto-save-file-name)
4084 (file-name buffer-file-name)
4085 (modified (buffer-modified-p)))
4086 (setq buffer-file-name nil)
4087 (kill-buffer (current-buffer))
4088 (when (and (or (and auto-save-file-name
4089 (file-exists-p auto-save-file-name))
4091 (file-exists-p file-name)))
4093 ;; If the message buffer has lived in a dedicated window,
4094 ;; `kill-buffer' has killed the frame. Thus the
4095 ;; `yes-or-no-p' may show up in a lowered frame. Make sure
4096 ;; that the user can see the question by raising the
4099 (yes-or-no-p (format "Remove the backup file%s? "
4100 (if modified " too" "")))))
4102 (delete-file auto-save-file-name))
4103 (let ((message-draft-article draft-article))
4104 (message-disassociate-draft)))
4105 (message-do-actions actions))))
4107 (defun message-bury (buffer)
4108 "Bury this mail BUFFER."
4109 ;; Note that this is not quite the same as (bury-buffer buffer),
4110 ;; since bury-buffer does extra stuff with a nil argument.
4111 ;; Eg http://lists.gnu.org/archive/html/emacs-devel/2014-01/msg00539.html
4112 (with-current-buffer buffer (bury-buffer))
4113 (if message-return-action
4114 (apply (car message-return-action) (cdr message-return-action))))
4116 (autoload 'mml-secure-bcc-is-safe "mml-sec")
4118 (defun message-send (&optional arg)
4119 "Send the message in the current buffer.
4120 If `message-interactive' is non-nil, wait for success indication or
4121 error messages, and inform user.
4122 Otherwise any failure is reported in a message back to the user from
4124 The usage of ARG is defined by the instance that called Message.
4125 It should typically alter the sending method in some way or other."
4127 ;; Make it possible to undo the coming changes.
4129 (let ((inhibit-read-only t))
4130 (put-text-property (point-min) (point-max) 'read-only nil))
4131 (message-fix-before-sending)
4132 (mml-secure-bcc-is-safe)
4133 (run-hooks 'message-send-hook)
4134 (when message-confirm-send
4135 (or (y-or-n-p "Send message? ")
4137 (message message-sending-message)
4138 (let ((alist message-send-method-alist)
4140 elem sent dont-barf-on-no-method
4141 (message-options message-options))
4142 (message-options-set-recipient)
4144 (setq elem (pop alist)))
4145 (when (funcall (cadr elem))
4146 (when (and (or (not (memq (car elem)
4147 message-sent-message-via))
4148 (message-fetch-field "supersedes")
4149 (if (or (message-gnksa-enable-p 'multiple-copies)
4150 (not (eq (car elem) 'news)))
4153 "Already sent message via %s; resend? "
4155 (error "Denied posting -- multiple copies")))
4156 (setq success (funcall (caddr elem) arg)))
4160 (let ((fcc (message-fetch-field "Fcc"))
4161 (gcc (message-fetch-field "Gcc")))
4163 (or (eq message-allow-no-recipients 'always)
4164 (and (not (eq message-allow-no-recipients 'never))
4165 (setq dont-barf-on-no-method
4167 (format "No receiver, perform %s anyway? "
4168 (cond ((and fcc gcc) "Fcc and Gcc")
4171 (error "No methods specified to send by"))
4172 (when (or dont-barf-on-no-method
4176 (run-hooks 'message-sent-hook))
4177 (message "Sending...done")
4178 ;; Do ecomplete address snarfing.
4179 (when (and (message-mail-alias-type-p 'ecomplete)
4180 (not message-inhibit-ecomplete))
4181 (message-put-addresses-in-ecomplete))
4182 ;; Mark the buffer as unmodified and delete auto-save.
4183 (set-buffer-modified-p nil)
4184 (delete-auto-save-file-if-necessary t)
4185 (message-disassociate-draft)
4186 ;; Delete other mail buffers and stuff.
4187 (message-do-send-housekeeping)
4188 (message-do-actions message-send-actions)
4192 (defun message-send-via-mail (arg)
4193 "Send the current message via mail."
4194 (message-send-mail arg))
4196 (defun message-send-via-news (arg)
4197 "Send the current message via news."
4198 (funcall message-send-news-function arg))
4200 (defmacro message-check (type &rest forms)
4201 "Eval FORMS if TYPE is to be checked."
4202 `(or (message-check-element ,type)
4206 (put 'message-check 'lisp-indent-function 1)
4207 (put 'message-check 'edebug-form-spec '(form body))
4209 (defun message-text-with-property (prop &optional start end reverse)
4210 "Return a list of start and end positions where the text has PROP.
4211 START and END bound the search, they default to `point-min' and
4212 `point-max' respectively. If REVERSE is non-nil, find text which does
4215 (setq start (point-min)))
4217 (setq end (point-max)))
4221 (setq start (text-property-any start end prop nil)))
4222 (setq next (next-single-property-change start prop nil end))
4223 (push (cons start (or next end)) regions)
4226 (or (get-text-property start prop)
4227 (and (setq start (next-single-property-change
4228 start prop nil end))
4229 (get-text-property start prop))))
4230 (setq next (text-property-any start end prop nil))
4231 (push (cons start (or next end)) regions)
4233 (nreverse regions)))
4235 (defcustom message-bogus-addresses
4236 '("noreply" "nospam" "invalid" "@@" "[^[:ascii:]].*@" "[ \t]")
4237 "List of regexps of potentially bogus mail addresses.
4238 See `message-check-recipients' how to setup checking.
4240 This list should make it possible to catch typos or warn about
4241 spam-trap addresses. It doesn't aim to verify strict RFC
4243 :version "23.1" ;; No Gnus
4244 :group 'message-headers
4246 (const :tag "None" nil)
4252 (const :tag "duplicate @" "@@")
4253 (const :tag "non-ascii local part" "[^[:ascii:]].*@")
4254 (const :tag "`_' in domain part" "@.*_")
4255 (const :tag "whitespace" "[ \t]"))
4260 (defun message-fix-before-sending ()
4261 "Do various things to make the message nice before sending it."
4262 ;; Make sure there's a newline at the end of the message.
4263 (goto-char (point-max))
4266 ;; Make the hidden headers visible.
4268 ;; Sort headers before sending the message.
4269 (message-sort-headers)
4270 ;; Make invisible text visible.
4271 ;; It doesn't seem as if this is useful, since the invisible property
4272 ;; is clobbered by an after-change hook anyhow.
4273 (message-check 'invisible-text
4274 (let ((regions (message-text-with-property 'invisible))
4278 (setq from (caar regions)
4280 regions (cdr regions))
4281 (put-text-property from to 'invisible nil)
4282 (overlay-put (make-overlay from to) 'face 'highlight))
4283 (unless (yes-or-no-p
4284 "Invisible text found and made visible; continue sending? ")
4285 (error "Invisible text found and made visible")))))
4286 (message-check 'illegible-text
4287 (let (char found choice nul-chars)
4289 (setq nul-chars (save-excursion
4290 (search-forward "\000" nil t)))
4292 (skip-chars-forward mm-7bit-chars)
4293 (when (get-text-property (point) 'no-illegible-text)
4294 ;; There is a signed or encrypted raw message part
4295 ;; that is considered to be safe.
4296 (goto-char (or (next-single-property-change
4297 (point) 'no-illegible-text)
4299 (setq char (char-after)))
4300 (when (or (< char 128)
4301 (and (mm-multibyte-p)
4302 (memq (char-charset char)
4303 '(eight-bit-control eight-bit-graphic
4304 ;; Emacs 23, Bug#1770:
4307 (not (get-text-property
4308 (point) 'untranslated-utf-8))))
4309 (overlay-put (make-overlay (point) (1+ (point))) 'face 'highlight)
4315 (read-multiple-choice
4317 "NUL characters found, which may cause problems. Continue sending?"
4318 "Non-printable characters found. Continue sending?")
4319 `((?d "delete" "Remove non-printable characters and send")
4322 "Replace non-printable characters with \"%s\" and send"
4323 message-replacement-char))
4324 (?s "send" "Send as is without removing anything")
4325 (?e "edit" "Continue editing")))))
4327 (error "Non-printable characters"))
4329 (skip-chars-forward mm-7bit-chars)
4331 (when (let ((char (char-after)))
4333 (and (mm-multibyte-p)
4334 ;; FIXME: Wrong for Emacs 23 (unicode) and for
4335 ;; things like undecodable utf-8 (in Emacs 21?).
4336 ;; Should at least use find-coding-systems-region.
4338 (memq (char-charset char)
4339 '(eight-bit-control eight-bit-graphic
4340 ;; Emacs 23, Bug#1770:
4343 (not (get-text-property
4344 (point) 'untranslated-utf-8)))))
4346 (message-kill-all-overlays)
4348 (when (eq choice ?r)
4349 (insert message-replacement-char))))
4351 (skip-chars-forward mm-7bit-chars)))))
4352 (message-check 'bogus-recipient
4353 ;; Warn before sending a mail to an invalid address.
4354 (message-check-recipients)))
4356 (defun message-bogus-recipient-p (recipients)
4357 "Check if a mail address in RECIPIENTS looks bogus.
4359 RECIPIENTS is a mail header. Return a list of potentially bogus
4360 addresses. If none is found, return nil.
4362 An address might be bogus if if there's a matching entry in
4363 `message-bogus-addresses'."
4364 ;; FIXME: How about "foo@subdomain", when the MTA adds ".domain.tld"?
4366 (mapc (lambda (address)
4367 (setq address (or (cadr address) ""))
4368 (when (or (string= "" address)
4369 (not (string-match "@" address))
4370 (string-match "@.*@" address)
4371 (and message-bogus-addresses
4373 (if (listp message-bogus-addresses)
4374 (mapconcat 'identity
4375 message-bogus-addresses
4377 message-bogus-addresses)))
4378 (string-match re address))))
4379 (push address found)))
4380 (mail-extract-address-components recipients t))
4383 (defun message-check-recipients ()
4384 "Warn before composing or sending a mail to an invalid address.
4386 This function could be useful in `message-setup-hook'."
4389 (message-narrow-to-headers)
4390 (dolist (hdr '("To" "Cc" "Bcc"))
4391 (let ((addr (message-fetch-field hdr)))
4392 (when (stringp addr)
4393 (dolist (bog (message-bogus-recipient-p addr))
4397 "Address `%s'%s might be bogus. Continue? "
4399 ;; If the encoded version of the email address
4400 ;; is different from the unencoded version,
4401 ;; then we likely have invisible characters or
4402 ;; the like. Display the encoded version,
4404 (let ((encoded (rfc2047-encode-string bog)))
4405 (if (string= encoded bog)
4407 (format " (%s)" encoded))))))
4408 (error "Bogus address"))))))))
4410 (custom-add-option 'message-setup-hook 'message-check-recipients)
4412 (defun message-add-action (action &rest types)
4413 "Add ACTION to be performed when doing an exit of type TYPES."
4415 (add-to-list (intern (format "message-%s-actions" (pop types)))
4418 (defun message-delete-action (action &rest types)
4419 "Delete ACTION from lists of actions performed when doing an exit of type TYPES."
4422 (set (setq var (intern (format "message-%s-actions" (pop types))))
4423 (delq action (symbol-value var))))))
4425 (defun message-do-actions (actions)
4426 "Perform all actions in ACTIONS."
4427 ;; Now perform actions on successful sending.
4428 (dolist (action actions)
4431 ;; A simple function.
4434 ;; Something to be evalled.
4438 (defun message-send-mail-partially ()
4439 "Send mail as message/partial."
4440 ;; replace the header delimiter with a blank line
4441 (goto-char (point-min))
4443 (concat "^" (regexp-quote mail-header-separator) "\n"))
4444 (replace-match "\n")
4445 (run-hooks 'message-send-mail-hook)
4446 (let ((p (goto-char (point-min)))
4447 (tembuf (message-generate-new-buffer-clone-locals " message temp"))
4448 (curbuf (current-buffer))
4449 (id (message-make-message-id)) (n 1)
4452 (if (< (point-max) (+ p message-send-mail-partially-limit))
4453 (goto-char (point-max))
4454 (goto-char (+ p message-send-mail-partially-limit))
4456 (if (<= (point) p) (forward-line 1))) ;; In case of bad message.
4459 (setq total (length plist))
4460 (push (point-max) plist)
4461 (setq plist (nreverse plist))
4464 (setq p (pop plist))
4467 (copy-to-buffer tembuf p (car plist))
4469 (goto-char (point-min))
4472 (goto-char (point-min))
4473 (narrow-to-region (point) (point))
4476 (setq header (buffer-substring (point-min) (point)))
4477 (goto-char (point-min))
4478 (narrow-to-region (point) (point))
4480 (message-remove-header "Mime-Version")
4481 (message-remove-header "Content-Type")
4482 (message-remove-header "Content-Transfer-Encoding")
4483 (message-remove-header "Message-ID")
4484 (message-remove-header "Lines")
4485 (goto-char (point-max))
4486 (insert "Mime-Version: 1.0\n")
4487 (setq header (buffer-string)))
4488 (goto-char (point-max))
4489 (insert (format "Content-Type: message/partial; id=\"%s\"; number=%d; total=%d\n\n"
4492 (let ((mail-header-separator ""))
4493 (when (memq 'Message-ID message-required-mail-headers)
4494 (insert "Message-ID: " (message-make-message-id) "\n"))
4495 (when (memq 'Lines message-required-mail-headers)
4496 (insert "Lines: " (message-make-lines) "\n"))
4497 (message-goto-subject)
4499 (insert (format " (%d/%d)" n total))
4501 (if message-send-mail-real-function
4502 (funcall message-send-mail-real-function)
4503 (message-multi-smtp-send-mail)))
4505 (setq p (pop plist))
4507 (kill-buffer tembuf))))
4509 (declare-function hashcash-wait-async "hashcash" (&optional buffer))
4511 (defun message-send-mail (&optional arg)
4512 (require 'mail-utils)
4513 (let* ((tembuf (message-generate-new-buffer-clone-locals " message temp"))
4514 (case-fold-search nil)
4515 (news (message-news-p))
4516 (mailbuf (current-buffer))
4517 (message-this-is-mail t)
4518 ;; gnus-setup-posting-charset is autoloaded in mml.el (FIXME
4519 ;; maybe it should not be), which this file requires. Hence
4520 ;; the fboundp test is always true. Loading it from gnus-msg
4521 ;; loads many Gnus files (Bug#5642). If
4522 ;; gnus-group-posting-charset-alist hasn't been customized,
4523 ;; this is just going to return nil anyway. FIXME it would
4524 ;; be good to improve this further, because even if g-g-p-c-a
4525 ;; has been customized, that is likely to just be for news.
4526 ;; Eg either move the definition from gnus-msg, or separate out
4527 ;; the mail and news parts.
4528 (message-posting-charset
4529 (if (and (fboundp 'gnus-setup-posting-charset)
4530 (boundp 'gnus-group-posting-charset-alist))
4531 (gnus-setup-posting-charset nil)
4532 message-posting-charset))
4533 (headers message-required-mail-headers)
4535 (when (and message-generate-hashcash
4536 (not (eq message-generate-hashcash 'opportunistic)))
4537 (message "Generating hashcash...")
4539 ;; Wait for calculations already started to finish...
4540 (hashcash-wait-async)
4541 ;; ...and do calculations not already done. mail-add-payment
4542 ;; will leave existing X-Hashcash headers alone.
4544 (message "Generating hashcash...done"))
4546 (message-narrow-to-headers)
4547 ;; Generate the Mail-Followup-To header if the header is not there...
4548 (if (and (message-subscribed-p)
4549 (not (mail-fetch-field "mail-followup-to")))
4552 (cons "Mail-Followup-To" (message-make-mail-followup-to))
4553 message-required-mail-headers))
4554 ;; otherwise, delete the MFT header if the field is empty
4555 (when (equal "" (mail-fetch-field "mail-followup-to"))
4556 (message-remove-header "^Mail-Followup-To:")))
4557 ;; Insert some headers.
4558 (let ((message-deletable-headers
4559 (if news nil message-deletable-headers)))
4560 (message-generate-headers headers))
4561 ;; Check continuation headers.
4562 (message-check 'continuation-headers
4563 (goto-char (point-min))
4564 (while (re-search-forward "^[^ \t\n][^ \t\n:]*[ \t\n]" nil t)
4565 (goto-char (match-beginning 0))
4566 (if (y-or-n-p "Fix continuation lines? ")
4569 (unless (y-or-n-p "Send anyway? ")
4570 (error "Failed to send the message")))))
4571 ;; Let the user do all of the above.
4572 (run-hooks 'message-header-hook))
4573 (setq options message-options)
4575 (with-current-buffer tembuf
4577 (setq message-options options)
4578 ;; Avoid copying text props (except hard newlines).
4579 (insert (with-current-buffer mailbuf
4580 (mml-buffer-substring-no-properties-except-hard-newlines
4581 (point-min) (point-max))))
4582 ;; Remove some headers.
4583 (message-encode-message-body)
4585 (message-narrow-to-headers)
4586 ;; We (re)generate the Lines header.
4587 (when (memq 'Lines message-required-mail-headers)
4588 (message-generate-headers '(Lines)))
4589 ;; Remove some headers.
4590 (message-remove-header message-ignored-mail-headers t)
4591 (let ((mail-parse-charset message-default-charset))
4592 (mail-encode-encoded-word-buffer)))
4593 (goto-char (point-max))
4594 ;; require one newline at the end.
4595 (or (= (preceding-char) ?\n)
4597 (message-cleanup-headers)
4598 ;; FIXME: we're inserting the courtesy copy after encoding.
4599 ;; This is wrong if the courtesy copy string contains
4600 ;; non-ASCII characters. -- jh
4603 (message-narrow-to-headers)
4605 (not (message-fetch-field "List-Post"))
4606 (not (message-fetch-field "List-ID"))
4607 (or (message-fetch-field "cc")
4608 (message-fetch-field "bcc")
4609 (message-fetch-field "to"))
4610 (let ((content-type (message-fetch-field
4615 (string= "text/plain"
4617 (mail-header-parse-content-type
4621 (message-fetch-field
4622 "content-transfer-encoding")))))))
4623 (message-insert-courtesy-copy
4624 (with-current-buffer mailbuf
4625 message-courtesy-message)))
4626 ;; Let's make sure we encoded all the body.
4627 (assert (save-excursion
4628 (goto-char (point-min))
4629 (not (re-search-forward "[^\000-\377]" nil t))))
4630 (mm-disable-multibyte)
4631 (if (or (not message-send-mail-partially-limit)
4632 (< (buffer-size) message-send-mail-partially-limit)
4633 (not (message-y-or-n-p
4634 "The message size is too large, split? "
4638 (/ (buffer-size) 1000) "KB, is too large.
4640 Some mail gateways (MTA's) bounce large messages. To avoid the
4641 problem, answer `y', and the message will be split into several
4642 smaller pieces, the size of each is about "
4643 (/ message-send-mail-partially-limit 1000)
4647 However, some mail readers (MUA's) can't read split messages, i.e.,
4648 mails in message/partially format. Answer `n', and the message will be
4651 The size limit is controlled by `message-send-mail-partially-limit'.
4652 If you always want Gnus to send messages in one piece, set
4653 `message-send-mail-partially-limit' to nil.
4656 (message "Sending via mail...")
4657 (if message-send-mail-real-function
4658 (funcall message-send-mail-real-function)
4659 (message-multi-smtp-send-mail)))
4660 (message-send-mail-partially))
4661 (setq options message-options))
4662 (kill-buffer tembuf))
4663 (set-buffer mailbuf)
4664 (setq message-options options)
4665 (push 'mail message-sent-message-via)))
4667 (defvar sendmail-program)
4668 (defvar smtpmail-smtp-user)
4670 (defun message-multi-smtp-send-mail ()
4671 "Send the current buffer to `message-send-mail-function'.
4672 Or, if there's a header that specifies a different method, use
4674 (let ((method (message-field-value "X-Message-SMTP-Method")))
4676 (funcall message-send-mail-function)
4677 (message-remove-header "X-Message-SMTP-Method")
4678 (setq method (split-string method))
4680 ((equal (car method) "sendmail")
4681 (message-send-mail-with-sendmail))
4682 ((equal (car method) "smtp")
4684 (let ((smtpmail-smtp-server (nth 1 method))
4685 (smtpmail-smtp-service (nth 2 method))
4686 (smtpmail-smtp-user (or (nth 3 method) smtpmail-smtp-user)))
4687 (message-smtpmail-send-it)))
4689 (error "Unknown method %s" method))))))
4691 (defun message-send-mail-with-sendmail ()
4692 "Send off the prepared buffer with sendmail."
4694 (let ((errbuf (if message-interactive
4695 (message-generate-new-buffer-clone-locals
4698 resend-to-addresses delimline)
4701 (let ((case-fold-search t))
4703 (message-narrow-to-headers)
4704 (setq resend-to-addresses (message-fetch-field "resent-to")))
4705 ;; Change header-delimiter to be what sendmail expects.
4706 (goto-char (point-min))
4708 (concat "^" (regexp-quote mail-header-separator) "\n"))
4709 (replace-match "\n")
4711 (setq delimline (point-marker))
4712 (run-hooks 'message-send-mail-hook)
4713 ;; Insert an extra newline if we need it to work around
4714 ;; Sun's bug that swallows newlines.
4715 (goto-char (1+ delimline))
4716 (when (eval message-mailer-swallows-blank-line)
4718 (when message-interactive
4719 (with-current-buffer errbuf
4721 (let* ((default-directory "/")
4722 (coding-system-for-write message-send-coding-system)
4724 'call-process-region
4726 (list (point-min) (point-max) sendmail-program
4727 nil errbuf nil "-oi")
4728 message-sendmail-extra-arguments
4729 ;; Always specify who from,
4730 ;; since some systems have broken sendmails.
4731 ;; But some systems are more broken with -f, so
4732 ;; we'll let users override this.
4733 (and (null message-sendmail-f-is-evil)
4734 (list "-f" (message-sendmail-envelope-from)))
4735 ;; These mean "report errors by mail"
4736 ;; and "deliver in background".
4737 (if (null message-interactive) '("-oem" "-odb"))
4738 ;; Get the addresses from the message
4739 ;; unless this is a resend.
4740 ;; We must not do that for a resend
4741 ;; because we would find the original addresses.
4742 ;; For a resend, include the specific addresses.
4743 (if resend-to-addresses
4744 (list resend-to-addresses)
4746 (unless (or (null cpr) (and (numberp cpr) (zerop cpr)))
4748 (pop-to-buffer errbuf)
4750 (error "Sending...failed with exit value %d" cpr)))
4751 (when message-interactive
4752 (with-current-buffer errbuf
4753 (goto-char (point-min))
4754 (while (re-search-forward "\n+ *" nil t)
4755 (replace-match "; "))
4756 (if (not (zerop (buffer-size)))
4757 (error "Sending...failed to %s"
4758 (buffer-string))))))
4759 (when (bufferp errbuf)
4760 (kill-buffer errbuf)))))
4762 (defun message-send-mail-with-qmail ()
4763 "Pass the prepared message buffer to qmail-inject.
4764 Refer to the documentation for the variable `message-send-mail-function'
4765 to find out how to use this."
4766 ;; replace the header delimiter with a blank line
4767 (goto-char (point-min))
4769 (concat "^" (regexp-quote mail-header-separator) "\n"))
4770 (replace-match "\n")
4771 (run-hooks 'message-send-mail-hook)
4774 (let ((coding-system-for-write message-send-coding-system))
4776 'call-process-region (point-min) (point-max)
4777 message-qmail-inject-program nil nil nil
4778 ;; qmail-inject's default behavior is to look for addresses on the
4779 ;; command line; if there're none, it scans the headers.
4780 ;; yes, it does The Right Thing w.r.t. Resent-To and it's kin.
4782 ;; in general, ALL of qmail-inject's defaults are perfect for simply
4783 ;; reading a formatted (i. e., at least a To: or Resent-To header)
4784 ;; message from stdin.
4786 ;; qmail also has the advantage of not having been raped by
4787 ;; various vendors, so we don't have to allow for that, either --
4788 ;; compare this with message-send-mail-with-sendmail and weep
4789 ;; for sendmail's lost innocence.
4791 ;; all this is way cool coz it lets us keep the arguments entirely
4792 ;; free for -inject-arguments -- a big win for the user and for us
4793 ;; since we don't have to play that double-guessing game and the user
4794 ;; gets full control (no gestapo'ish -f's, for instance). --sj
4795 (if (functionp message-qmail-inject-args)
4796 (funcall message-qmail-inject-args)
4797 message-qmail-inject-args)))
4798 ;; qmail-inject doesn't say anything on it's stdout/stderr,
4799 ;; we have to look at the retval instead
4801 (100 (error "qmail-inject reported permanent failure"))
4802 (111 (error "qmail-inject reported transient failure"))
4803 ;; should never happen
4804 (t (error "qmail-inject reported unknown failure"))))
4806 (defvar mh-previous-window-config)
4808 (defun message-send-mail-with-mh ()
4809 "Send the prepared message buffer with mh."
4810 (let ((mh-previous-window-config nil)
4811 (name (mh-new-draft-name)))
4812 (setq buffer-file-name name)
4813 ;; MH wants to generate these headers itself.
4814 (when message-mh-deletable-headers
4815 (let ((headers message-mh-deletable-headers))
4817 (goto-char (point-min))
4818 (and (re-search-forward
4819 (concat "^" (symbol-name (car headers)) ": *") nil t)
4820 (message-delete-line))
4822 (run-hooks 'message-send-mail-hook)
4823 ;; Pass it on to mh.
4826 (defun message-smtpmail-send-it ()
4827 "Send the prepared message buffer with `smtpmail-send-it'.
4828 The only difference from `smtpmail-send-it' is that this command
4829 evaluates `message-send-mail-hook' just before sending a message.
4830 It is useful if your ISP requires the POP-before-SMTP
4831 authentication. See the Gnus manual for details."
4832 (run-hooks 'message-send-mail-hook)
4833 ;; Change header-delimiter to be what smtpmail expects.
4834 (goto-char (point-min))
4835 (when (re-search-forward
4836 (concat "^" (regexp-quote mail-header-separator) "\n"))
4837 (replace-match "\n"))
4840 (defun message-send-mail-with-mailclient ()
4841 "Send the prepared message buffer with `mailclient-send-it'.
4842 The only difference from `mailclient-send-it' is that this
4843 command evaluates `message-send-mail-hook' just before sending a message."
4844 (run-hooks 'message-send-mail-hook)
4845 (mailclient-send-it))
4847 (defun message-canlock-generate ()
4848 "Return a string that is non-trivial to guess.
4849 Do not use this for anything important, it is cryptographically weak."
4851 (let (sha1-maximum-internal-length)
4852 (sha1 (concat (message-unique-id)
4853 (format "%x%x%x" (random) (random) (random))
4854 (prin1-to-string (recent-keys))
4855 (prin1-to-string (garbage-collect))))))
4857 (defvar canlock-password)
4858 (defvar canlock-password-for-verify)
4860 (defun message-canlock-password ()
4861 "The password used by message for cancel locks.
4862 This is the value of `canlock-password', if that option is non-nil.
4863 Otherwise, generate and save a value for `canlock-password' first."
4865 (unless canlock-password
4866 (customize-save-variable 'canlock-password (message-canlock-generate))
4867 (setq canlock-password-for-verify canlock-password))
4870 (defun message-insert-canlock ()
4871 (when message-insert-canlock
4872 (message-canlock-password)
4873 (canlock-insert-header)))
4875 (autoload 'nnheader-get-report "nnheader")
4877 (declare-function gnus-setup-posting-charset "gnus-msg" (group))
4879 (defun message-send-news (&optional arg)
4881 (let* ((tembuf (message-generate-new-buffer-clone-locals " *message temp*"))
4882 (case-fold-search nil)
4883 (method (if (functionp message-post-method)
4884 (funcall message-post-method arg)
4885 message-post-method))
4886 (newsgroups-field (save-restriction
4887 (message-narrow-to-headers-or-head)
4888 (message-fetch-field "Newsgroups")))
4889 (followup-field (save-restriction
4890 (message-narrow-to-headers-or-head)
4891 (message-fetch-field "Followup-To")))
4892 ;; BUG: We really need to get the charset for each name in the
4893 ;; Newsgroups and Followup-To lines to allow crossposting
4894 ;; between group names with incompatible character sets.
4895 ;; -- Per Abrahamsen <abraham@dina.kvl.dk> 2001-10-08.
4896 (group-field-charset
4897 (gnus-group-name-charset method newsgroups-field))
4898 (followup-field-charset
4899 (gnus-group-name-charset method (or followup-field "")))
4900 (rfc2047-header-encoding-alist
4901 (append (when group-field-charset
4902 (list (cons "Newsgroups" group-field-charset)))
4903 (when followup-field-charset
4904 (list (cons "Followup-To" followup-field-charset)))
4905 rfc2047-header-encoding-alist))
4906 (messbuf (current-buffer))
4907 (message-syntax-checks
4909 (listp message-syntax-checks))
4910 (cons '(existing-newsgroups . disabled)
4911 message-syntax-checks)
4912 message-syntax-checks))
4913 (message-this-is-news t)
4914 (message-posting-charset
4915 (gnus-setup-posting-charset newsgroups-field))
4917 (if (not (message-check-news-body-syntax))
4920 (message-narrow-to-headers)
4921 ;; Insert some headers.
4922 (message-generate-headers message-required-news-headers)
4923 (message-insert-canlock)
4924 ;; Let the user do all of the above.
4925 (run-hooks 'message-header-hook))
4926 ;; Note: This check will be disabled by the ".*" default value for
4927 ;; gnus-group-name-charset-group-alist. -- Pa 2001-10-07.
4928 (when (and group-field-charset
4929 (listp message-syntax-checks))
4930 (setq message-syntax-checks
4931 (cons '(valid-newsgroups . disabled)
4932 message-syntax-checks)))
4933 (message-cleanup-headers)
4934 (if (not (let ((message-post-method method))
4935 (message-check-news-syntax)))
4938 (with-current-buffer tembuf
4939 (buffer-disable-undo)
4941 ;; Avoid copying text props (except hard newlines).
4943 (with-current-buffer messbuf
4944 (mml-buffer-substring-no-properties-except-hard-newlines
4945 (point-min) (point-max))))
4946 (message-encode-message-body)
4947 ;; Remove some headers.
4949 (message-narrow-to-headers)
4950 ;; We (re)generate the Lines header.
4951 (when (memq 'Lines message-required-mail-headers)
4952 (message-generate-headers '(Lines)))
4953 ;; Remove some headers.
4954 (message-remove-header message-ignored-news-headers t)
4955 (let ((mail-parse-charset message-default-charset))
4956 (mail-encode-encoded-word-buffer)))
4957 (goto-char (point-max))
4958 ;; require one newline at the end.
4959 (or (= (preceding-char) ?\n)
4961 (let ((case-fold-search t))
4962 ;; Remove the delimiter.
4963 (goto-char (point-min))
4965 (concat "^" (regexp-quote mail-header-separator) "\n"))
4966 (replace-match "\n")
4968 (run-hooks 'message-send-news-hook)
4969 (gnus-open-server method)
4970 (message "Sending news via %s..." (gnus-server-string method))
4971 (setq result (let ((mail-header-separator ""))
4972 (gnus-request-post method))))
4973 (kill-buffer tembuf))
4974 (set-buffer messbuf)
4976 (push 'news message-sent-message-via)
4977 (message "Couldn't send message via news: %s"
4978 (nnheader-get-report (car method)))
4982 ;;; Header generation & syntax checking.
4985 (defun message-check-element (type)
4986 "Return non-nil if this TYPE is not to be checked."
4987 (if (eq message-syntax-checks 'dont-check-for-anything-just-trust-me)
4989 (let ((able (assq type message-syntax-checks)))
4991 (eq (cdr able) 'disabled)))))
4993 (defun message-check-news-syntax ()
4994 "Check the syntax of the message."
4998 ;; We narrow to the headers and check them first.
5001 (message-narrow-to-headers)
5002 (message-check-news-header-syntax))))))
5004 (defun message-check-news-header-syntax ()
5006 ;; Check Newsgroups header.
5007 (message-check 'newsgroups
5008 (let ((group (message-fetch-field "newsgroups")))
5011 (not (string-match "\\`[ \t]*\\'" group)))
5014 "The newsgroups field is empty or missing. Posting is denied.")))))
5015 ;; Check the Subject header.
5016 (message-check 'subject
5017 (let* ((case-fold-search t)
5018 (subject (message-fetch-field "subject")))
5021 (not (string-match "\\`[ \t]*\\'" subject)))
5024 "The subject field is empty or missing. Posting is denied.")))))
5025 ;; Check for commands in Subject.
5026 (message-check 'subject-cmsg
5027 (if (string-match "^cmsg " (message-fetch-field "subject"))
5029 "The control code \"cmsg\" is in the subject. Really post? ")
5031 ;; Check long header lines.
5032 (message-check 'long-header-lines
5036 (while (and (not found)
5037 (re-search-forward "^\\([^ \t:]+\\): " nil t))
5038 (if (> (- (point) (match-beginning 0)) 998)
5040 length (- (point) (match-beginning 0)))
5041 (setq header (match-string-no-properties 1)))
5044 (y-or-n-p (format "Your %s header is too long (%d). Really post? "
5047 ;; Check for multiple identical headers.
5048 (message-check 'multiple-headers
5050 (while (and (not found)
5051 (re-search-forward "^[^ \t:]+: " nil t))
5053 (or (re-search-forward
5058 (match-beginning 0) (- (match-end 0) 2))))
5063 (y-or-n-p (format "Multiple %s headers. Really post? " found))
5065 ;; Check for Version and Sendsys.
5066 (message-check 'sendsys
5067 (if (re-search-forward "^Sendsys:\\|^Version:" nil t)
5069 (format "The article contains a %s command. Really post? "
5070 (buffer-substring (match-beginning 0)
5071 (1- (match-end 0)))))
5073 ;; See whether we can shorten Followup-To.
5074 (message-check 'shorten-followup-to
5075 (let ((newsgroups (message-fetch-field "newsgroups"))
5076 (followup-to (message-fetch-field "followup-to"))
5078 (when (and newsgroups
5079 (string-match "," newsgroups)
5084 (setq to (completing-read
5085 "Followups to (default no Followup-To header): "
5088 (message-tokenize-header
5090 (goto-char (point-min))
5091 (insert "Followup-To: " to "\n"))
5093 ;; Check "Shoot me".
5094 (message-check 'shoot
5095 (if (re-search-forward
5096 "Message-ID.*.i-did-not-set--mail-host-address--so-tickle-me" nil t)
5097 (y-or-n-p "You appear to have a misconfigured system. Really post? ")
5099 ;; Check for Approved.
5100 (message-check 'approved
5101 (if (re-search-forward "^Approved:" nil t)
5102 (y-or-n-p "The article contains an Approved header. Really post? ")
5104 ;; Check the Message-ID header.
5105 (message-check 'message-id
5106 (let* ((case-fold-search t)
5107 (message-id (message-fetch-field "message-id" t)))
5108 (or (not message-id)
5109 ;; Is there an @ in the ID?
5110 (and (string-match "@" message-id)
5111 ;; Is there a dot in the ID?
5112 (string-match "@[^.]*\\." message-id)
5113 ;; Does the ID end with a dot?
5114 (not (string-match "\\.>" message-id)))
5116 (format "The Message-ID looks strange: \"%s\". Really post? "
5118 ;; Check the Newsgroups & Followup-To headers.
5119 (message-check 'existing-newsgroups
5120 (let* ((case-fold-search t)
5121 (newsgroups (message-fetch-field "newsgroups"))
5122 (followup-to (message-fetch-field "followup-to"))
5123 (groups (message-tokenize-header
5125 (concat newsgroups "," followup-to)
5127 (post-method (if (functionp message-post-method)
5128 (funcall message-post-method)
5129 message-post-method))
5130 ;; KLUDGE to handle nnvirtual groups. Doing this right
5131 ;; would probably involve a new nnoo function.
5132 ;; -- Per Abrahamsen <abraham@dina.kvl.dk>, 2001-10-17.
5133 (method (if (and (consp post-method)
5134 (eq (car post-method) 'nnvirtual)
5135 gnus-message-group-art)
5136 (let ((group (car (nnvirtual-find-group-art
5137 (car gnus-message-group-art)
5138 (cdr gnus-message-group-art)))))
5139 (gnus-find-method-for-group group))
5143 (gnus-group-name-decode
5144 (gnus-group-real-name n)
5145 (gnus-group-name-charset method n)))
5146 (gnus-groups-from-server method)))
5149 (when (and (not (equal (car groups) "poster"))
5150 (not (member (car groups) known-groups))
5151 (not (member (car groups) errors)))
5152 (push (car groups) errors))
5155 ;; Gnus is not running.
5156 ((or (not (and (boundp 'gnus-active-hashtb)
5157 gnus-active-hashtb))
5158 (not (boundp 'gnus-read-active-file)))
5160 ;; We don't have all the group names.
5161 ((and (or (not gnus-read-active-file)
5162 (eq gnus-read-active-file 'some))
5166 "Really use %s possibly unknown group%s: %s? "
5167 (if (= (length errors) 1) "this" "these")
5168 (if (= (length errors) 1) "" "s")
5169 (mapconcat 'identity errors ", "))))
5170 ;; There were no errors.
5173 ;; There are unknown groups.
5177 "Really post to %s unknown group%s: %s? "
5178 (if (= (length errors) 1) "this" "these")
5179 (if (= (length errors) 1) "" "s")
5180 (mapconcat 'identity errors ", ")))))))
5181 ;; Check continuation headers.
5182 (message-check 'continuation-headers
5183 (goto-char (point-min))
5184 (let ((do-posting t))
5185 (while (re-search-forward "^[^ \t\n][^ \t\n:]*[ \t\n]" nil t)
5186 (goto-char (match-beginning 0))
5187 (if (y-or-n-p "Fix continuation lines? ")
5190 (unless (y-or-n-p "Send anyway? ")
5191 (setq do-posting nil))))
5193 ;; Check the Newsgroups & Followup-To headers for syntax errors.
5194 (message-check 'valid-newsgroups
5195 (let ((case-fold-search t)
5196 (headers '("Newsgroups" "Followup-To"))
5198 (while (and headers (not error))
5199 (when (setq header (mail-fetch-field (car headers)))
5203 "\\`\\([-+_&.a-zA-Z0-9]+\\)?\\(,[-+_&.a-zA-Z0-9]+\\)*\\'"
5208 (not (string-match "\\.\\'\\|\\.\\." g)))
5209 (message-tokenize-header header ","))))
5216 (format "The %s header looks odd: \"%s\". Really post? "
5217 (car headers) header)))))
5218 (message-check 'repeated-newsgroups
5219 (let ((case-fold-search t)
5220 (headers '("Newsgroups" "Followup-To"))
5221 header error groups group)
5224 (when (setq header (mail-fetch-field (pop headers)))
5225 (setq groups (message-tokenize-header header ","))
5226 (while (setq group (pop groups))
5227 (when (member group groups)
5233 (format "Group %s is repeated in headers. Really post? " error)))))
5234 ;; Check the From header.
5235 (message-check 'from
5236 (let* ((case-fold-search t)
5237 (from (message-fetch-field "from"))
5241 (message "There is no From line. Posting is denied.")
5243 ((or (not (string-match
5245 (setq ad (nth 1 (mail-extract-address-components
5246 from))))) ;larsi@ifi
5247 (string-match "\\.\\." ad) ;larsi@ifi..uio
5248 (string-match "@\\." ad) ;larsi@.ifi.uio
5249 (string-match "\\.$" ad) ;larsi@ifi.uio.
5250 (not (string-match "^[^@]+@[^@]+$" ad)) ;larsi.ifi.uio
5251 (string-match "(.*).*(.*)" from)) ;(lars) (lars)
5253 "Denied posting -- the From looks strange: \"%s\"." from)
5255 ((let ((addresses (rfc822-addresses from)))
5256 ;; `rfc822-addresses' returns a string if parsing fails.
5257 (while (and (consp addresses)
5258 (not (eq (string-to-char (car addresses)) ?\()))
5259 (setq addresses (cdr addresses)))
5262 "Denied posting -- bad From address: \"%s\"." from)
5265 ;; Check the Reply-To header.
5266 (message-check 'reply-to
5267 (let* ((case-fold-search t)
5268 (reply-to (message-fetch-field "reply-to"))
5273 ((string-match "," reply-to)
5275 (format "Multiple Reply-To addresses: \"%s\". Really post? "
5277 ((or (not (string-match
5279 (setq ad (nth 1 (mail-extract-address-components
5280 reply-to))))) ;larsi@ifi
5281 (string-match "\\.\\." ad) ;larsi@ifi..uio
5282 (string-match "@\\." ad) ;larsi@.ifi.uio
5283 (string-match "\\.$" ad) ;larsi@ifi.uio.
5284 (not (string-match "^[^@]+@[^@]+$" ad)) ;larsi.ifi.uio
5285 (string-match "(.*).*(.*)" reply-to)) ;(lars) (lars)
5288 "The Reply-To looks strange: \"%s\". Really post? "
5292 (defun message-check-news-body-syntax ()
5294 ;; Check for long lines.
5295 (message-check 'long-lines
5296 (goto-char (point-min))
5298 (concat "^" (regexp-quote mail-header-separator) "$"))
5302 "<#\\(/\\)?\\(multipart\\|part\\|external\\|mml\\)")
5305 (< (- (point) p) 80)))
5306 (zerop (forward-line 1))))
5310 "You have lines longer than 79 characters. Really post? ")))
5311 ;; Check whether the article is empty.
5312 (message-check 'empty
5313 (goto-char (point-min))
5315 (concat "^" (regexp-quote mail-header-separator) "$"))
5318 (goto-char (point-max))
5319 (re-search-backward message-signature-separator nil t)
5321 (or (re-search-backward "[^ \n\t]" b t)
5322 (if (message-gnksa-enable-p 'empty-article)
5323 (y-or-n-p "Empty article. Really post? ")
5324 (message "Denied posting -- Empty article.")
5326 ;; Check for control characters.
5327 (message-check 'control-chars
5328 (if (re-search-forward
5329 (string-to-multibyte "[\000-\007\013\015-\032\034-\037\200-\237]")
5332 "The article contains control characters. Really post? ")
5334 ;; Check excessive size.
5335 (message-check 'size
5336 (if (> (buffer-size) 60000)
5338 (format "The article is %d octets long. Really post? "
5341 ;; Check whether any new text has been added.
5342 (message-check 'new-text
5344 (not message-checksum)
5345 (not (eq (message-checksum) message-checksum))
5346 (if (message-gnksa-enable-p 'quoted-text-only)
5348 "It looks like no new text has been added. Really post? ")
5349 (message "Denied posting -- no new text has been added.")
5351 ;; Check the length of the signature.
5352 (message-check 'signature
5353 (let (sig-start sig-end)
5354 (goto-char (point-max))
5355 (if (not (re-search-backward message-signature-separator nil t))
5357 (setq sig-start (1+ (point-at-eol)))
5359 (if (re-search-forward
5360 "<#/?\\(multipart\\|part\\|external\\|mml\\)" nil t)
5361 (- (point-at-bol) 1)
5363 (if (>= (count-lines sig-start sig-end) 5)
5364 (if (message-gnksa-enable-p 'signature)
5366 (format "Signature is excessively long (%d lines). Really post? "
5367 (count-lines sig-start sig-end)))
5368 (message "Denied posting -- Excessive signature.")
5371 ;; Ensure that text follows last quoted portion.
5372 (message-check 'quoting-style
5373 (goto-char (point-max))
5374 (let ((no-problem t))
5375 (when (search-backward-regexp "^>[^\n]*\n" nil t)
5376 (setq no-problem (search-forward-regexp "^[ \t]*[^>\n]" nil t)))
5379 (if (message-gnksa-enable-p 'quoted-text-only)
5380 (y-or-n-p "Your text should follow quoted text. Really post? ")
5382 (goto-char (point-min))
5384 (concat "^" (regexp-quote mail-header-separator) "$"))
5385 (if (search-forward-regexp "^[ \t]*[^>\n]" nil t)
5386 (y-or-n-p "Your text should follow quoted text. Really post? ")
5387 (message "Denied posting -- only quoted text.")
5390 (defun message-checksum ()
5391 "Return a \"checksum\" for the current buffer."
5394 (goto-char (point-min))
5396 (concat "^" (regexp-quote mail-header-separator) "$"))
5398 (when (not (looking-at "[ \t\n]"))
5399 (setq sum (logxor (ash sum 1) (if (natnump sum) 0 1)
5404 (defun message-do-fcc ()
5405 "Process Fcc headers in the current buffer."
5406 (let ((case-fold-search t)
5407 (buf (current-buffer))
5409 (mml-externalize-attachments message-fcc-externalize-attachments))
5412 (message-narrow-to-headers)
5413 (setq file (message-fetch-field "fcc" t)))
5415 (set-buffer (get-buffer-create " *message temp*"))
5417 (insert-buffer-substring buf)
5418 (message-encode-message-body)
5420 (message-narrow-to-headers)
5421 (while (setq file (message-fetch-field "fcc" t))
5423 (message-remove-header "fcc" nil t))
5424 (let ((mail-parse-charset message-default-charset)
5425 (rfc2047-header-encoding-alist
5426 (cons '("Newsgroups" . default)
5427 rfc2047-header-encoding-alist)))
5428 (mail-encode-encoded-word-buffer)))
5429 (goto-char (point-min))
5430 (when (re-search-forward
5431 (concat "^" (regexp-quote mail-header-separator) "$")
5433 (replace-match "" t t ))
5434 ;; Process FCC operations.
5436 (setq file (pop list))
5437 (if (string-match "^[ \t]*|[ \t]*\\(.*\\)[ \t]*$" file)
5438 ;; Pipe the article to the program in question.
5439 (call-process-region (point-min) (point-max) shell-file-name
5440 nil nil nil shell-command-switch
5441 (match-string 1 file))
5442 ;; Save the article.
5443 (setq file (expand-file-name file))
5444 (unless (file-exists-p (file-name-directory file))
5445 (make-directory (file-name-directory file) t))
5446 (if (and message-fcc-handler-function
5447 (not (eq message-fcc-handler-function 'rmail-output)))
5448 (funcall message-fcc-handler-function file)
5449 ;; FIXME this option, rmail-output (also used if
5450 ;; message-fcc-handler-function is nil) is not
5451 ;; documented anywhere AFAICS. It should work in Emacs
5452 ;; 23; I suspect it does not work in Emacs 22.
5453 ;; FIXME I don't see the need for the two different cases here.
5454 ;; mail-use-rfc822 makes no difference (in Emacs 23),and
5455 ;; the third argument just controls \"Wrote file\" message.
5456 (if (and (file-readable-p file) (mail-file-babyl-p file))
5457 (rmail-output file 1 nil t)
5458 (let ((mail-use-rfc822 t))
5459 (rmail-output file 1 t t))))))
5460 (kill-buffer (current-buffer))))))
5462 (defun message-output (filename)
5463 "Append this article to Unix/babyl mail file FILENAME."
5464 (if (or (and (file-readable-p filename)
5465 (mail-file-babyl-p filename))
5466 ;; gnus-output-to-mail does the wrong thing with live, mbox
5467 ;; Rmail buffers in Emacs 23.
5468 ;; http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=597255
5469 (let ((buff (find-buffer-visiting filename)))
5470 (and buff (with-current-buffer buff
5471 (eq major-mode 'rmail-mode)))))
5472 (gnus-output-to-rmail filename t)
5473 (gnus-output-to-mail filename t)))
5475 (defun message-cleanup-headers ()
5476 "Do various automatic cleanups of the headers."
5477 ;; Remove empty lines in the header.
5479 (message-narrow-to-headers)
5480 ;; Remove blank lines.
5481 (while (re-search-forward "^[ \t]*\n" nil t)
5482 (replace-match "" t t))
5484 ;; Correct Newsgroups and Followup-To headers: Change sequence of
5485 ;; spaces to comma and eliminate spaces around commas. Eliminate
5486 ;; embedded line breaks.
5487 (goto-char (point-min))
5488 (while (re-search-forward "^\\(Newsgroups\\|Followup-To\\): +" nil t)
5492 (if (re-search-forward "^[^ \t]" nil t)
5496 (goto-char (point-min))
5497 (while (re-search-forward "\n[ \t]+" nil t)
5498 (replace-match " " t t)) ;No line breaks (too confusing)
5499 (goto-char (point-min))
5500 (while (re-search-forward "[ \t\n]*,[ \t\n]*\\|[ \t]+" nil t)
5501 (replace-match "," t t))
5502 (goto-char (point-min))
5503 ;; Remove trailing commas.
5504 (when (re-search-forward ",+$" nil t)
5505 (replace-match "" t t))))))
5507 (defun message-make-date (&optional now)
5508 "Make a valid data header.
5509 If NOW, use that time instead."
5510 (let ((system-time-locale "C"))
5511 (format-time-string "%a, %d %b %Y %T %z" now)))
5513 (defun message-insert-expires (days)
5514 "Insert the Expires header. Expiry in DAYS days."
5515 (interactive "NExpire article in how many days? ")
5517 (message-position-on-field "Expires" "X-Draft-From")
5518 (insert (message-make-expires-date days))))
5520 (defun message-make-expires-date (days)
5521 "Make date string for the Expires header. Expiry in DAYS days.
5523 In posting styles use `(\"Expires\" (make-expires-date 30))'."
5524 (let* ((cur (decode-time))
5525 (nday (+ days (nth 3 cur))))
5526 (setf (nth 3 cur) nday)
5527 (message-make-date (apply 'encode-time cur))))
5529 (defun message-make-message-id ()
5530 "Make a unique Message-ID."
5531 (concat "<" (message-unique-id)
5532 (let ((psubject (save-excursion (message-fetch-field "subject")))
5534 (save-excursion (message-fetch-field "supersedes"))))
5536 (and message-reply-headers
5537 (mail-header-references message-reply-headers)
5538 (mail-header-subject message-reply-headers)
5541 (message-strip-subject-re
5542 (mail-header-subject message-reply-headers))
5543 (message-strip-subject-re psubject))))
5545 (string-match "_-_@" psupersedes)))
5547 "@" (message-make-fqdn) ">"))
5549 (defvar message-unique-id-char nil)
5551 ;; If you ever change this function, make sure the new version
5552 ;; cannot generate IDs that the old version could.
5553 ;; You might for example insert a "." somewhere (not next to another dot
5554 ;; or string boundary), or modify the "fsf" string.
5555 (defun message-unique-id ()
5556 ;; Don't use microseconds from (current-time), they may be unsupported.
5557 ;; Instead we use this randomly inited counter.
5558 (setq message-unique-id-char
5559 (% (1+ (or message-unique-id-char
5560 (logand (random most-positive-fixnum) (1- (lsh 1 20)))))
5561 ;; (current-time) returns 16-bit ints,
5562 ;; and 2^16*25 just fits into 4 digits i base 36.
5564 (let ((tm (current-time)))
5566 (if (or (eq system-type 'ms-dos)
5567 ;; message-number-base36 doesn't handle bigints.
5568 (floatp (user-uid)))
5569 (let ((user (downcase (user-login-name))))
5570 (while (string-match "[^a-z0-9_]" user)
5571 (aset user (match-beginning 0) ?_))
5573 (message-number-base36 (user-uid) -1))
5574 (message-number-base36 (+ (car tm)
5575 (lsh (% message-unique-id-char 25) 16)) 4)
5576 (message-number-base36 (+ (nth 1 tm)
5577 (lsh (/ message-unique-id-char 25) 16)) 4)
5578 ;; Append a given name, because while the generated ID is unique
5579 ;; to this newsreader, other newsreaders might otherwise generate
5580 ;; the same ID via another algorithm.
5583 (defun message-number-base36 (num len)
5588 (concat (message-number-base36 (/ num 36) (1- len))
5589 (char-to-string (aref "zyxwvutsrqponmlkjihgfedcba9876543210"
5592 (defun message-make-organization ()
5593 "Make an Organization header."
5594 (let* ((organization
5595 (when message-user-organization
5596 (if (functionp message-user-organization)
5597 (funcall message-user-organization)
5598 message-user-organization))))
5600 (mm-enable-multibyte)
5601 (cond ((stringp organization)
5602 (insert organization))
5603 ((and (eq t organization)
5604 message-user-organization-file
5605 (file-exists-p message-user-organization-file))
5606 (insert-file-contents message-user-organization-file)))
5607 (goto-char (point-min))
5608 (while (re-search-forward "[\t\n]+" nil t)
5609 (replace-match "" t t))
5610 (unless (zerop (buffer-size))
5613 (defun message-make-lines ()
5614 "Count the number of lines and return numeric string."
5619 (int-to-string (count-lines (point) (point-max))))))
5621 (defun message-make-references ()
5622 "Return the References header for this message."
5623 (when message-reply-headers
5624 (let ((message-id (mail-header-id message-reply-headers))
5625 (references (mail-header-references message-reply-headers)))
5626 (if (or references message-id)
5627 (concat (or references "") (and references " ")
5631 (defun message-make-in-reply-to ()
5632 "Return the In-Reply-To header for this message."
5633 (when message-reply-headers
5634 (let ((from (mail-header-from message-reply-headers))
5635 (date (mail-header-date message-reply-headers))
5636 (msg-id (mail-header-id message-reply-headers)))
5638 (let ((name (mail-extract-address-components from)))
5640 msg-id (if msg-id " (")
5642 (if (string-match "[^\000-\177]" (car name))
5643 ;; Quote a string containing non-ASCII characters.
5644 ;; It will make the RFC2047 encoder cause an error
5645 ;; if there are special characters.
5646 (mm-with-multibyte-buffer
5648 (goto-char (point-min))
5649 (while (search-forward "\"" nil t)
5652 (zerop (% (skip-chars-backward "\\\\") 2))
5653 (goto-char (match-beginning 0)))
5656 ;; Those quotes will be removed by the RFC2047 encoder.
5657 (concat "\"" (buffer-string) "\""))
5661 (if (or (not date) (string= date ""))
5662 "(unknown date)" date)
5663 "\"" (if msg-id ")")))))))
5665 (defun message-make-distribution ()
5666 "Make a Distribution header."
5667 (let ((orig-distribution (message-fetch-reply-field "distribution")))
5668 (cond ((functionp message-distribution-function)
5669 (funcall message-distribution-function))
5670 (t orig-distribution))))
5672 (defun message-make-expires ()
5673 "Return an Expires header based on `message-expires'."
5674 (let ((current (current-time))
5675 (future (* 1.0 message-expires 60 60 24)))
5676 ;; Add the future to current.
5677 (setcar current (+ (car current) (round (/ future (expt 2 16)))))
5678 (setcar (cdr current) (+ (nth 1 current) (% (round future) (expt 2 16))))
5679 (message-make-date current)))
5681 (defun message-make-path ()
5683 (let ((login-name (user-login-name)))
5684 (cond ((null message-user-path)
5685 (concat (system-name) "!" login-name))
5686 ((stringp message-user-path)
5687 ;; Support GENERICPATH. Suggested by vixie@decwrl.dec.com.
5688 (concat message-user-path "!" login-name))
5691 (defun message-make-from (&optional name address)
5692 "Make a From header."
5693 (let* ((style message-from-style)
5694 (login (or address (message-make-address)))
5695 (fullname (or name user-full-name (user-full-name))))
5696 (when (string= fullname "&")
5697 (setq fullname (user-login-name)))
5699 (mm-enable-multibyte)
5702 (equal fullname ""))
5704 ((or (eq style 'angles)
5705 (and (not (eq style 'parens))
5706 ;; Use angles if no quoting is needed, or if parens would
5707 ;; need quoting too.
5708 (or (not (string-match "[^- !#-'*+/-9=?A-Z^-~]" fullname))
5709 (let ((tmp (concat fullname nil)))
5710 (while (string-match "([^()]*)" tmp)
5711 (aset tmp (match-beginning 0) ?-)
5712 (aset tmp (1- (match-end 0)) ?-))
5713 (string-match "[\\()]" tmp)))))
5715 (goto-char (point-min))
5716 ;; Look for a character that cannot appear unquoted
5717 ;; according to RFC 822.
5718 (when (re-search-forward "[^- !#-'*+/-9=?A-Z^-~]" nil 1)
5719 ;; Quote fullname, escaping specials.
5720 (goto-char (point-min))
5722 (while (re-search-forward "[\"\\]" nil 1)
5723 (replace-match "\\\\\\&" t))
5725 (insert " <" login ">"))
5726 (t ; 'parens or default
5728 (let ((fullname-start (point)))
5730 (goto-char fullname-start)
5731 ;; RFC 822 says \ and nonmatching parentheses
5732 ;; must be escaped in comments.
5733 ;; Escape every instance of ()\ ...
5734 (while (re-search-forward "[()\\]" nil 1)
5735 (replace-match "\\\\\\&" t))
5736 ;; ... then undo escaping of matching parentheses,
5737 ;; including matching nested parentheses.
5738 (goto-char fullname-start)
5739 (while (re-search-forward
5740 "\\(\\=\\|[^\\]\\(\\\\\\\\\\)*\\)\\\\(\\(\\([^\\]\\|\\\\\\\\\\)*\\)\\\\)"
5742 (replace-match "\\1(\\3)" t)
5743 (goto-char fullname-start)))
5747 (defun message-make-sender ()
5748 "Return the \"real\" user address.
5749 This function tries to ignore all user modifications, and
5750 give as trustworthy answer as possible."
5751 (concat (user-login-name) "@" (system-name)))
5753 (defun message-make-address ()
5754 "Make the address of the user."
5755 (or (message-user-mail-address)
5756 (concat (user-login-name) "@" (message-make-domain))))
5758 (defun message-user-mail-address ()
5759 "Return the pertinent part of `user-mail-address'."
5760 (when (and user-mail-address
5761 (string-match "@.*\\." user-mail-address))
5762 (if (string-match " " user-mail-address)
5763 (nth 1 (mail-extract-address-components user-mail-address))
5764 user-mail-address)))
5766 (defun message-sendmail-envelope-from ()
5767 "Return the envelope from."
5768 (cond ((eq message-sendmail-envelope-from 'header)
5769 (nth 1 (mail-extract-address-components
5770 (message-fetch-field "from"))))
5771 ((stringp message-sendmail-envelope-from)
5772 message-sendmail-envelope-from)
5774 (message-make-address))))
5776 (defun message-make-fqdn ()
5777 "Return user's fully qualified domain name."
5778 (let* ((sysname (system-name))
5779 (user-mail (message-user-mail-address))
5782 (string-match "@\\(.*\\)\\'" user-mail))
5783 (match-string 1 user-mail)))
5784 (case-fold-search t))
5786 ((and message-user-fqdn
5787 (stringp message-user-fqdn)
5788 (not (string-match message-bogus-system-names message-user-fqdn)))
5789 ;; `message-user-fqdn' seems to be valid
5791 ((and (string-match message-bogus-system-names sysname))
5792 ;; `system-name' returned the right result.
5794 ;; Try `mail-host-address'.
5795 ((and (stringp mail-host-address)
5796 (not (string-match message-bogus-system-names mail-host-address)))
5798 ;; We try `user-mail-address' as a backup.
5800 (stringp user-domain)
5801 (not (string-match message-bogus-system-names user-domain)))
5803 ;; Default to this bogus thing.
5806 ".i-did-not-set--mail-host-address--so-tickle-me")))))
5808 (defun message-make-domain ()
5809 "Return the domain name."
5810 (or mail-host-address
5811 (message-make-fqdn)))
5813 (defun message-to-list-only ()
5814 "Send a message to the list only.
5815 Remove all addresses but the list address from To and Cc headers."
5817 (let ((listaddr (message-make-mail-followup-to t)))
5820 (message-remove-header "to")
5821 (message-remove-header "cc")
5822 (message-position-on-field "To" "X-Draft-From")
5823 (insert listaddr)))))
5825 (defun message-make-mail-followup-to (&optional only-show-subscribed)
5826 "Return the Mail-Followup-To header.
5827 If passed the optional argument ONLY-SHOW-SUBSCRIBED only return the
5828 subscribed address (and not the additional To and Cc header contents)."
5829 (let* ((case-fold-search t)
5830 (to (message-fetch-field "To"))
5831 (cc (message-fetch-field "cc"))
5832 (msg-recipients (concat to (and to cc ", ") cc))
5834 (mapcar 'mail-strip-quoted-names
5835 (message-tokenize-header msg-recipients)))
5837 (if message-subscribed-address-file
5838 (let (begin end item re)
5841 (insert-file-contents message-subscribed-address-file)
5843 (setq begin (point))
5846 (if (bolp) (setq end (1- end)))
5847 (setq item (regexp-quote (buffer-substring begin end)))
5848 (if re (setq re (concat re "\\|" item))
5849 (setq re (concat "\\`\\(" item))))
5850 (and re (list (concat re "\\)\\'"))))))))
5851 (mft-regexps (apply 'append message-subscribed-regexps
5852 (mapcar 'regexp-quote
5853 message-subscribed-addresses)
5856 message-subscribed-address-functions))))
5859 (loop for recipient in recipients
5860 when (loop for regexp in mft-regexps
5861 when (string-match regexp recipient) return t)
5864 (if only-show-subscribed
5866 msg-recipients))))))
5868 (defun message-idna-to-ascii-rhs-1 (header)
5869 "Interactively potentially IDNA encode domain names in HEADER."
5870 (let ((field (message-fetch-field header))
5875 (mapcar (lambda (rhs) (or (cadr (split-string rhs "@")) ""))
5881 (mail-extract-address-components field t))))))
5882 ;; Note that `rhs' will be "" if the address does not have
5883 ;; the domain part, i.e., if it is a local user's address.
5884 (setq ace (if (string-match "\\`[[:ascii:]]*\\'" rhs)
5886 (downcase (idna-to-ascii rhs))))
5887 (when (and (not (equal rhs ace))
5888 (or (not (eq message-use-idna 'ask))
5889 (y-or-n-p (format "Replace %s with %s in %s:? "
5891 (goto-char (point-min))
5892 (while (re-search-forward (concat "^" header ":") nil t)
5893 (message-narrow-to-field)
5894 (while (search-forward (concat "@" rhs) nil t)
5895 (replace-match (concat "@" ace) t t))
5896 (goto-char (point-max))
5899 (defun message-idna-to-ascii-rhs ()
5900 "Possibly IDNA encode non-ASCII domain names in From:, To: and Cc: headers.
5901 See `message-idna-encode'."
5903 (when message-use-idna
5906 ;; `message-narrow-to-head' that recognizes only the first empty
5907 ;; line as the message header separator used to be used here.
5908 ;; However, since there is the "--text follows this line--" line
5909 ;; normally, it failed in narrowing to the headers and potentially
5910 ;; caused the IDNA encoding on lines that look like headers in
5911 ;; the message body.
5912 (message-narrow-to-headers-or-head)
5913 (message-idna-to-ascii-rhs-1 "From")
5914 (message-idna-to-ascii-rhs-1 "To")
5915 (message-idna-to-ascii-rhs-1 "Reply-To")
5916 (message-idna-to-ascii-rhs-1 "Mail-Reply-To")
5917 (message-idna-to-ascii-rhs-1 "Mail-Followup-To")
5918 (message-idna-to-ascii-rhs-1 "Cc")))))
5920 (defun message-generate-headers (headers)
5921 "Prepare article HEADERS.
5922 Headers already prepared in the buffer are not modified."
5923 (setq headers (append headers message-required-headers))
5925 (message-narrow-to-headers)
5926 (let* ((header-values
5927 (list 'Date (message-make-date)
5928 'Message-ID (message-make-message-id)
5929 'Organization (message-make-organization)
5930 'From (message-make-from)
5931 'Path (message-make-path)
5934 'In-Reply-To (message-make-in-reply-to)
5935 'References (message-make-references)
5937 'Distribution (message-make-distribution)
5938 'Lines (message-make-lines)
5939 'User-Agent message-newsreader
5940 'Expires (message-make-expires)))
5941 (case-fold-search t)
5943 header value elem header-string)
5944 ;; First we remove any old generated headers.
5945 (let ((headers message-deletable-headers))
5946 (unless (buffer-modified-p)
5947 (setq headers (delq 'Message-ID (copy-sequence headers))))
5949 (goto-char (point-min))
5950 (and (re-search-forward
5951 (concat "^" (symbol-name (car headers)) ": *") nil t)
5952 (get-text-property (1+ (match-beginning 0)) 'message-deletable)
5953 (message-delete-line))
5955 ;; Go through all the required headers and see if they are in the
5956 ;; articles already. If they are not, or are empty, they are
5957 ;; inserted automatically - except for Subject, Newsgroups and
5960 (goto-char (point-min))
5961 (setq elem (pop headers))
5963 (if (eq (car elem) 'optional)
5964 (setq header (cdr elem)
5966 (setq header (car elem)))
5968 (setq header-string (if (stringp header)
5970 (symbol-name header)))
5971 (when (or (not (re-search-forward
5973 (regexp-quote (downcase header-string))
5977 ;; The header was found. We insert a space after the
5978 ;; colon, if there is none.
5979 (if (/= (char-after) ? ) (insert " ") (forward-char 1))
5980 ;; Find out whether the header is empty.
5981 (looking-at "[ \t]*\n[^ \t]")))
5982 ;; So we find out what value we should insert.
5986 (eq (car elem) 'optional)
5987 (not (member header-string message-inserted-headers)))
5988 ;; This is an optional header. If the cdr of this
5989 ;; is something that is nil, then we do not insert
5991 (setq header (cdr elem))
5992 (or (and (functionp (cdr elem))
5993 (funcall (cdr elem)))
5994 (and (symbolp (cdr elem))
5995 (plist-get header-values (cdr elem)))))
5997 ;; The element is a cons. Either the cdr is a
5998 ;; string to be inserted verbatim, or it is a
5999 ;; function, and we insert the value returned from
6001 (or (and (stringp (cdr elem))
6003 (and (functionp (cdr elem))
6004 (funcall (cdr elem)))))
6005 ((and (symbolp header)
6006 (plist-member header-values header))
6007 ;; The element is a symbol. We insert the value of
6008 ;; this symbol, if any.
6009 (plist-get header-values header))
6010 ((not (message-check-element
6011 (intern (downcase (symbol-name header)))))
6012 ;; We couldn't generate a value for this header,
6013 ;; so we just ask the user.
6014 (read-from-minibuffer
6015 (format "Empty header for %s; enter value: " header)))))
6016 ;; Finally insert the header.
6018 (not (equal value "")))
6022 ;; This header didn't exist, so we insert it.
6023 (goto-char (point-max))
6025 (cdr (assq header message-header-format-alist))))
6027 (funcall formatter header value)
6028 (insert header-string ": " value))
6029 (push header-string message-inserted-headers)
6030 (goto-char (message-fill-field))
6031 ;; We check whether the value was ended by a
6032 ;; newline. If not, we insert one.
6036 ;; The value of this header was empty, so we clear
6037 ;; totally and insert the new value.
6038 (delete-region (point) (point-at-eol))
6039 ;; If the header is optional, and the header was
6040 ;; empty, we can't insert it anyway.
6042 (push header-string message-inserted-headers)
6044 (message-fill-field)))
6045 ;; Add the deletable property to the headers that require it.
6046 (and (memq header message-deletable-headers)
6047 (progn (beginning-of-line) (looking-at "[^:]+: "))
6048 (add-text-properties
6049 (point) (match-end 0)
6050 '(message-deletable t face italic) (current-buffer)))))))
6051 ;; Insert new Sender if the From is strange.
6052 (let ((from (message-fetch-field "from"))
6053 (sender (message-fetch-field "sender"))
6054 (secure-sender (message-make-sender)))
6056 (not (message-check-element 'sender))
6059 (cadr (mail-extract-address-components from)))
6060 (downcase secure-sender)))
6065 (cadr (mail-extract-address-components sender)))
6066 (downcase secure-sender)))))
6067 (goto-char (point-min))
6068 ;; Rename any old Sender headers to Original-Sender.
6069 (when (re-search-forward "^\\(Original-\\)*Sender:" nil t)
6071 (insert "Original-")
6072 (beginning-of-line))
6073 (when (or (message-news-p)
6074 (string-match "@.+\\.." secure-sender))
6075 (insert "Sender: " secure-sender "\n"))))
6077 (message-idna-to-ascii-rhs))))
6079 (defun message-insert-courtesy-copy (message)
6080 "Insert a courtesy message in mail copies of combined messages."
6084 (message-narrow-to-headers)
6085 (when (setq newsgroups (message-fetch-field "newsgroups"))
6086 (goto-char (point-max))
6087 (insert "Posted-To: " newsgroups "\n")))
6091 ((string-match "%s" message)
6092 (insert (format message newsgroups)))
6094 (insert message)))))))
6097 ;;; Setting up a message buffer
6100 (defun message-skip-to-next-address ()
6101 (let ((end (save-excursion
6102 (message-next-header)
6105 (when (looking-at ",")
6107 (while (and (not (= (point) end))
6108 (or (not (eq char ?,))
6110 (skip-chars-forward "^,\"" end)
6111 (when (eq (setq char (following-char)) ?\")
6112 (setq quoted (not quoted)))
6113 (unless (= (point) end)
6115 (skip-chars-forward " \t\n")))
6117 (defun message-split-line ()
6118 "Split current line, moving portion beyond point vertically down.
6119 If the current line has `message-yank-prefix', insert it on the new line."
6122 (split-line message-yank-prefix) ;; Emacs 22.1+ supports arg.
6126 (defun message-insert-header (header value)
6127 (insert (capitalize (symbol-name header))
6129 (if (consp value) (car value) value)))
6131 (defun message-field-name ()
6133 (goto-char (point-min))
6134 (when (looking-at "\\([^:]+\\):")
6135 (intern (capitalize (match-string 1))))))
6137 (defun message-fill-field ()
6140 (message-narrow-to-field)
6141 (let ((field-name (message-field-name)))
6142 (funcall (or (cadr (assq field-name message-field-fillers))
6143 'message-fill-field-general)))
6146 (defun message-fill-field-address ()
6149 (message-skip-to-next-address)
6155 (when (and (> (current-column) 78)
6159 (delete-char (- (skip-chars-backward " \t")))
6161 (setq last (point)))
6162 (forward-line end)))
6164 (defun message-fill-field-general ()
6165 (let ((begin (point))
6168 (while (and (search-forward "\n" nil t)
6170 (replace-match " " t t))
6171 (fill-region-as-paragraph begin (point-max))
6172 ;; Tapdance around looong Message-IDs.
6174 (when (looking-at "[ \t]*$")
6175 (message-delete-line))
6177 (search-forward ":" nil t)
6178 (when (looking-at "\n[ \t]+")
6179 (replace-match " " t t))
6180 (goto-char (point-max))))
6182 (defun message-shorten-1 (list cut surplus)
6183 "Cut SURPLUS elements out of LIST, beginning with CUTth one."
6184 (setcdr (nthcdr (- cut 2) list)
6185 (nthcdr (+ (- cut 2) surplus 1) list)))
6187 (defun message-shorten-references (header references)
6188 "Trim REFERENCES to be 21 Message-ID long or less, and fold them.
6189 When sending via news, also check that the REFERENCES are less
6190 than 988 characters long, and if they are not, trim them until
6192 ;; 21 is the number suggested by USAGE.
6199 (goto-char (point-min))
6200 ;; Cons a list of valid references. GNKSA says we must not include MIDs
6201 ;; with whitespace or missing brackets (7.a "Does not propagate broken
6202 ;; Message-IDs in original References").
6203 (while (re-search-forward "<[^ <]+@[^ <]+>" nil t)
6204 (push (match-string 0) refs))
6205 (setq refs (nreverse refs)
6206 count (length refs)))
6208 ;; If the list has more than MAXCOUNT elements, trim it by
6209 ;; removing the CUTth element and the required number of
6210 ;; elements that follow.
6211 (when (> count maxcount)
6212 (let ((surplus (- count maxcount)))
6213 (message-shorten-1 refs cut surplus)
6214 (decf count surplus)))
6216 ;; When sending via news, make sure the total folded length will
6217 ;; be less than 998 characters. This is to cater to broken INN
6218 ;; 2.3 which counts the total number of characters in a header
6219 ;; rather than the physical line length of each line, as it should.
6221 ;; This hack should be removed when it's believed than INN 2.3 is
6222 ;; no longer widely used.
6224 ;; At this point the headers have not been generated, thus we use
6225 ;; message-this-is-news directly.
6226 (when message-this-is-news
6229 (message-insert-header
6230 header (mapconcat #'identity refs " "))
6232 (message-shorten-1 refs cut 1)))
6233 ;; Finally, collect the references back into a string and insert
6234 ;; it into the buffer.
6235 (message-insert-header header (mapconcat #'identity refs " "))))
6237 (defun message-position-point ()
6238 "Move point to where the user probably wants to find it."
6239 (message-narrow-to-headers)
6241 ((re-search-forward "^[^:]+:[ \t]*$" nil t)
6242 (search-backward ":" )
6245 (if (eq (char-after) ? )
6249 (goto-char (point-max))
6252 (unless (looking-at "$")
6256 (defcustom message-beginning-of-line t
6257 "Whether \\<message-mode-map>\\[message-beginning-of-line]\
6258 goes to beginning of header values."
6260 :group 'message-buffers
6261 :link '(custom-manual "(message)Movement")
6264 (defvar visual-line-mode)
6265 (declare-function beginning-of-visual-line "simple" (&optional n))
6267 (defun message-beginning-of-header (handle-folded)
6268 "Move point to beginning of header’s value.
6270 When point is at the first header line, moves it after the colon
6271 and spaces separating header name and header value.
6273 When point is in a continuation line of a folded header (i.e. the
6274 line starts with a space), the behaviour depends on HANDLE-FOLDED
6275 argument. If it’s nil, function moves the point to the start of
6276 the header continuation; otherwise, function locates the
6277 beginning of the header and moves point past the colon as is the
6278 case of single-line headers.
6280 No check whether point is inside of a header or body of the
6281 message is performed.
6283 Returns point or nil if beginning of header’s value could not be
6284 found. In the latter case, the point is still moved to the
6285 beginning of line (possibly after attempting to move it to the
6286 beginning of a folded header)."
6287 ;; https://www.rfc-editor.org/rfc/rfc2822.txt, section 2.2.3. says that when
6288 ;; unfolding a single WSP should be consumed. WSP is defined as a space
6289 ;; character or a horizontal tab.
6292 (while (and (> (point) (point-min))
6293 (or (eq (char-after) ?\s) (eq (char-after) ?\t)))
6294 (beginning-of-line 0)))
6295 (when (or (eq (char-after) ?\s) (eq (char-after) ?\t)
6296 (search-forward ":" (point-at-eol) t))
6297 ;; We are a bit more lacks than the RFC and allow any positive number of WSP
6299 (skip-chars-forward " \t" (point-at-eol))
6302 (defun message-beginning-of-line (&optional n)
6303 "Move point to beginning of header value or to beginning of line.
6304 The prefix argument N is passed directly to `beginning-of-line'.
6306 This command is identical to `beginning-of-line' if point is
6307 outside the message header or if the option
6308 `message-beginning-of-line' is nil.
6310 If point is in the message header and on a header line, move
6311 point to the beginning of the header value or the beginning of
6312 line, whichever is closer. If point is already at beginning of
6313 line, move point to beginning of header value. Therefore,
6314 repeated calls will toggle point between beginning of field and
6317 When called without a prefix argument, header value spanning
6318 multiple lines is treated as a single line. Otherwise, even if
6319 N is 1, when point is on a continuation header line, it will be
6320 moved to the beginning "
6323 ;; Go to beginning of header or beginning of line.
6324 ((and message-beginning-of-line (message-point-in-header-p))
6325 (let* ((point (point))
6326 (bol (progn (beginning-of-line n) (point)))
6327 (boh (message-beginning-of-header visual-line-mode)))
6328 (goto-char (if (and boh (or (< boh point) (= bol point))) boh bol))))
6329 ;; Go to beginning of visual line
6331 (beginning-of-visual-line n))
6332 ;; Go to beginning of line.
6333 ((beginning-of-line n))))
6335 (defun message-buffer-name (type &optional to group)
6336 "Return a new (unique) buffer name based on TYPE and TO."
6338 ;; Generate a new buffer name The Message Way.
6339 ((memq message-generate-new-buffers '(unique t))
6340 (generate-new-buffer-name
6344 (or (car (mail-extract-address-components to))
6347 (if (and group (not (string= group ""))) (concat " on " group) "")
6349 ;; Check whether `message-generate-new-buffers' is a function,
6350 ;; and if so, call it.
6351 ((functionp message-generate-new-buffers)
6352 (funcall message-generate-new-buffers type to group))
6353 ((eq message-generate-new-buffers 'unsent)
6354 (generate-new-buffer-name
6355 (concat "*unsent " type
6358 (or (car (mail-extract-address-components to))
6361 (if (and group (not (string= group ""))) (concat " on " group) "")
6363 ;; Search for the existing message buffer with the specified name.
6365 (let* ((new (if (eq message-generate-new-buffers 'standard)
6366 (generate-new-buffer-name (concat "*" type " message*"))
6367 (let ((message-generate-new-buffers 'unique))
6368 (message-buffer-name type to group))))
6369 (regexp (concat "\\`"
6371 (if (string-match "<[0-9]+>\\'" new)
6372 (substring new 0 (match-beginning 0))
6374 "\\(?:<\\([0-9]+\\)>\\)?\\'"))
6375 (case-fold-search nil))
6382 (when (and (string-match regexp (setq b (buffer-name b)))
6383 (eq (with-current-buffer b major-mode)
6385 (cons (string-to-number (or (match-string 1 b) "1"))
6388 'car-less-than-car)))
6391 (defun message-pop-to-buffer (name &optional switch-function)
6392 "Pop to buffer NAME, and warn if it already exists and is modified."
6393 (let ((buffer (get-buffer name)))
6395 (buffer-name buffer))
6396 (let ((window (get-buffer-window buffer 0)))
6398 ;; Raise the frame already displaying the message buffer.
6400 (select-frame-set-input-focus (window-frame window))
6401 (select-window window))
6402 (funcall (or switch-function #'pop-to-buffer) buffer)
6403 (set-buffer buffer))
6404 (when (and (buffer-modified-p)
6407 "Message already being composed; erase? ")
6409 (error "Message being composed")))
6410 (funcall (or switch-function 'pop-to-buffer-same-window)
6416 (defun message-do-send-housekeeping ()
6417 "Kill old message buffers."
6418 ;; We might have sent this buffer already. Delete it from the
6420 (setq message-buffer-list (delq (current-buffer) message-buffer-list))
6421 (while (and message-max-buffers
6423 (>= (length message-buffer-list) message-max-buffers))
6424 ;; Kill the oldest buffer -- unless it has been changed.
6425 (let ((buffer (pop message-buffer-list)))
6426 (when (and (buffer-name buffer)
6427 (not (buffer-modified-p buffer)))
6428 (kill-buffer buffer))))
6429 ;; Rename the buffer.
6430 (if message-send-rename-function
6431 (funcall message-send-rename-function)
6432 (message-default-send-rename-function))
6433 ;; Push the current buffer onto the list.
6434 (when message-max-buffers
6435 (setq message-buffer-list
6436 (nconc message-buffer-list (list (current-buffer))))))
6438 (defun message-default-send-rename-function ()
6439 ;; Note: mail-abbrevs of XEmacs renames buffer name behind Gnus.
6441 "\\`\\*\\(sent \\|unsent \\)?\\(.+\\)\\*[^\\*]*\\|\\`mail to "
6443 (let ((name (match-string 2 (buffer-name)))
6445 (if (not (or (null name)
6446 (string-equal name "mail")
6447 (string-equal name "posting")))
6448 (setq name (concat "*sent " name "*"))
6449 (message-narrow-to-headers)
6450 (setq to (message-fetch-field "to"))
6451 (setq group (message-fetch-field "newsgroups"))
6455 (to (concat "*sent mail to "
6456 (or (car (mail-extract-address-components to))
6458 ((and group (not (string= group "")))
6459 (concat "*sent posting on " group "*"))
6460 (t "*sent mail*"))))
6461 (unless (string-equal name (buffer-name))
6462 (rename-buffer name t)))))
6464 (defun message-mail-user-agent ()
6466 ((not message-mail-user-agent) nil)
6467 ((eq message-mail-user-agent t) mail-user-agent)
6468 (t message-mail-user-agent))))
6469 (if (memq mua '(message-user-agent gnus-user-agent))
6473 ;; YANK-ACTION, if non-nil, can be a buffer or a yank action of the
6474 ;; form (FUNCTION . ARGS).
6475 (defun message-setup (headers &optional yank-action actions
6476 continue switch-function return-action)
6477 (let ((mua (message-mail-user-agent))
6479 (if (not (and message-this-is-mail mua))
6480 (message-setup-1 headers yank-action actions return-action)
6481 (setq headers (copy-sequence headers))
6482 (setq field (assq 'Subject headers))
6484 (setq subject (cdr field))
6485 (setq headers (delq field headers)))
6486 (setq field (assq 'To headers))
6488 (setq to (cdr field))
6489 (setq headers (delq field headers)))
6490 (let ((mail-user-agent mua))
6491 (compose-mail to subject
6492 (mapcar (lambda (item)
6494 (format "%s" (car item))
6497 continue switch-function
6498 (if (bufferp yank-action)
6499 (list 'insert-buffer yank-action)
6503 (defun message-headers-to-generate (headers included-headers excluded-headers)
6504 "Return a list that includes all headers from HEADERS.
6505 If INCLUDED-HEADERS is a list, just include those headers. If it is
6506 t, include all headers. In any case, headers from EXCLUDED-HEADERS
6510 (dolist (header headers)
6511 (setq header-name (cond
6512 ((and (consp header)
6513 (eq (car header) 'optional))
6514 ;; On the form (optional . Header)
6517 ;; On the form (Header . function)
6522 (when (and (not (memq header-name excluded-headers))
6523 (or (eq included-headers t)
6524 (memq header-name included-headers)))
6525 (push header result)))
6528 (defun message-setup-1 (headers &optional yank-action actions return-action)
6529 (dolist (action actions)
6531 (add-to-list 'message-send-actions
6532 `(apply ',(car action) ',(cdr action)))))
6533 (setq message-return-action return-action)
6534 (setq message-reply-buffer
6535 (if (and (consp yank-action)
6536 (eq (car yank-action) 'insert-buffer))
6539 (goto-char (point-min))
6540 ;; Insert all the headers.
6543 (alist message-header-format-alist))
6545 (unless (assq (caar h) message-header-format-alist)
6546 (push (list (caar h)) alist))
6550 (delete-region (point) (progn (forward-line -1) (point)))
6551 (when message-default-headers
6553 (if (functionp message-default-headers)
6554 (funcall message-default-headers)
6555 message-default-headers))
6556 (or (bolp) (insert ?\n)))
6557 (insert (concat mail-header-separator "\n"))
6559 ;; If a crash happens while replying, the auto-save file would *not* have a
6560 ;; `References:' header if `message-generate-headers-first' was nil.
6561 ;; Therefore, always generate it first.
6562 (let ((message-generate-headers-first
6563 (if (eq message-generate-headers-first t)
6565 (append message-generate-headers-first '(References)))))
6566 (when (message-news-p)
6567 (when message-default-news-headers
6568 (insert message-default-news-headers)
6569 (or (bolp) (insert ?\n)))
6570 (message-generate-headers
6571 (message-headers-to-generate
6572 (append message-required-news-headers
6573 message-required-headers)
6574 message-generate-headers-first
6576 (when (message-mail-p)
6577 (when message-default-mail-headers
6578 (insert message-default-mail-headers)
6579 (or (bolp) (insert ?\n)))
6580 (message-generate-headers
6581 (message-headers-to-generate
6582 (append message-required-mail-headers
6583 message-required-headers)
6584 message-generate-headers-first
6585 '(Lines Subject)))))
6586 (run-hooks 'message-signature-setup-hook)
6587 (message-insert-signature)
6589 (message-narrow-to-headers)
6590 (run-hooks 'message-header-setup-hook))
6591 (setq buffer-undo-list nil)
6592 (when message-generate-hashcash
6593 ;; Generate hashcash headers for recipients already known
6594 (mail-add-payment-async))
6595 ;; Gnus posting styles are applied via buffer-local `message-setup-hook'
6597 (run-hooks 'message-setup-hook)
6598 ;; Do this last to give it precedence over posting styles, etc.
6599 (when (message-mail-p)
6601 (message-narrow-to-headers)
6602 (if message-alternative-emails
6603 (message-use-alternative-email-as-from))))
6604 (message-position-point)
6605 ;; Allow correct handling of `message-checksum' in `message-yank-original':
6606 (set-buffer-modified-p nil)
6608 ;; rmail-start-mail expects message-mail to return t (Bug#9392)
6611 (defun message-set-auto-save-file-name ()
6612 "Associate the message buffer with a file in the drafts directory."
6613 (when message-auto-save-directory
6614 (unless (file-directory-p
6615 (directory-file-name message-auto-save-directory))
6616 (make-directory message-auto-save-directory t))
6618 (setq message-draft-article
6619 (nndraft-request-associate-buffer "drafts"))
6621 ;; If Gnus were alive, draft messages would be saved in the drafts folder.
6622 ;; But Gnus is not alive, so arrange to save the draft message in a
6623 ;; regular file in message-auto-save-directory. Append a unique
6624 ;; time-based suffix to the filename to allow multiple drafts to be saved
6625 ;; simultaneously without overwriting each other (which mimics the
6626 ;; functionality of the Gnus drafts folder).
6627 (setq buffer-file-name (expand-file-name
6629 (if (memq system-type
6630 '(ms-dos windows-nt cygwin))
6633 (format-time-string "-%Y%m%d-%H%M%S"))
6634 message-auto-save-directory))
6635 (setq buffer-auto-save-file-name (make-auto-save-file-name)))
6636 (clear-visited-file-modtime)
6637 (setq buffer-file-coding-system message-draft-coding-system)))
6639 (defun message-disassociate-draft ()
6640 "Disassociate the message buffer from the drafts directory."
6641 (when message-draft-article
6642 (nndraft-request-expire-articles
6643 (list message-draft-article) "drafts" nil t)))
6645 (defun message-insert-headers ()
6646 "Generate the headers for the article."
6650 (message-narrow-to-headers)
6651 (when (message-news-p)
6652 (message-generate-headers
6655 (copy-sequence message-required-news-headers)))))
6656 (when (message-mail-p)
6657 (message-generate-headers
6660 (copy-sequence message-required-mail-headers))))))))
6665 ;;; Commands for interfacing with message
6669 (defun message-mail (&optional to subject other-headers continue
6670 switch-function yank-action send-actions
6671 return-action &rest ignored)
6672 "Start editing a mail message to be sent.
6673 OTHER-HEADERS is an alist of header/value pairs. CONTINUE says whether
6674 to continue editing a message already being composed. SWITCH-FUNCTION
6675 is a function used to switch to and display the mail buffer."
6677 (let ((message-this-is-mail t))
6678 (unless (message-mail-user-agent)
6679 (message-pop-to-buffer
6680 ;; Search for the existing message buffer if `continue' is non-nil.
6681 (let ((message-generate-new-buffers
6682 (when (or (not continue)
6683 (eq message-generate-new-buffers 'standard)
6684 (functionp message-generate-new-buffers))
6685 message-generate-new-buffers)))
6686 (message-buffer-name "mail" to))
6690 `((To . ,(or to "")) (Subject . ,(or subject "")))
6691 ;; C-h f compose-mail says that headers should be specified as
6692 ;; (string . value); however all the rest of message expects
6693 ;; headers to be symbols, not strings (eg message-header-format-alist).
6694 ;; http://lists.gnu.org/archive/html/emacs-devel/2011-01/msg00337.html
6695 ;; We need to convert any string input, eg from rmail-start-mail.
6696 (dolist (h other-headers other-headers)
6697 (if (stringp (car h)) (setcar h (intern (capitalize (car h)))))))
6698 yank-action send-actions continue switch-function
6702 (defun message-news (&optional newsgroups subject)
6703 "Start editing a news article to be sent."
6705 (let ((message-this-is-news t))
6706 (message-pop-to-buffer (message-buffer-name "posting" nil newsgroups))
6707 (message-setup `((Newsgroups . ,(or newsgroups ""))
6708 (Subject . ,(or subject ""))))))
6710 (defun message-alter-recipients-discard-bogus-full-name (addrcell)
6711 "Discard mail address in full names.
6712 When the full name in reply headers contains the mail
6713 address (e.g. \"foo@bar <foo@bar>\"), discard full name.
6714 ADDRCELL is a cons cell where the car is the mail address and the
6715 cdr is the complete address (full name and mail address)."
6716 (if (string-match (concat (regexp-quote (car addrcell)) ".*"
6717 (regexp-quote (car addrcell)))
6719 (cons (car addrcell) (car addrcell))
6722 (defcustom message-alter-recipients-function nil
6723 "Function called to allow alteration of reply header structures.
6724 It is called in `message-get-reply-headers' for each recipient.
6725 The function is called with one parameter, a cons cell ..."
6726 :type '(choice (const :tag "None" nil)
6727 (const :tag "Discard bogus full name"
6728 message-alter-recipients-discard-bogus-full-name)
6730 :version "23.1" ;; No Gnus
6731 :group 'message-headers)
6733 (defun message-get-reply-headers (wide &optional to-address address-headers)
6734 (let (follow-to mct never-mct to cc author mft recipients extra)
6735 ;; Find all relevant headers we need.
6737 (message-narrow-to-headers-or-head)
6738 ;; Gmane renames "To". Look at "Original-To", too, if it is present in
6739 ;; message-header-synonyms.
6740 (setq to (or (message-fetch-field "to")
6741 (and (loop for synonym in message-header-synonyms
6742 when (memq 'Original-To synonym)
6744 (message-fetch-field "original-to")))
6745 cc (message-fetch-field "cc")
6746 extra (when message-extra-wide-headers
6747 (mapconcat 'identity
6748 (mapcar 'message-fetch-field
6749 message-extra-wide-headers)
6751 mct (message-fetch-field "mail-copies-to")
6752 author (or (message-fetch-field "mail-reply-to")
6753 (message-fetch-field "reply-to"))
6754 mft (and message-use-mail-followup-to
6755 (message-fetch-field "mail-followup-to")))
6756 ;; Make sure this message goes to the author if this is a wide
6757 ;; reply, since Reply-To address may be a list address a mailing
6758 ;; list server added.
6759 (when (and wide author)
6760 (setq cc (concat author ", " cc)))
6761 (when (or wide (not author))
6762 (setq author (or (message-fetch-field "from") ""))))
6764 ;; Handle special values of Mail-Copies-To.
6766 (cond ((or (equal (downcase mct) "never")
6767 (equal (downcase mct) "nobody"))
6770 ((or (equal (downcase mct) "always")
6771 (equal (downcase mct) "poster"))
6772 (setq mct author))))
6775 ;; Build (textual) list of new recipient addresses.
6778 (setq recipients (concat ", " to-address))
6779 ;; If the author explicitly asked for a copy, we don't deny it to them.
6780 (if mct (setq recipients (concat recipients ", " mct))))
6782 (setq recipients (concat ", " author)))
6784 (dolist (header address-headers)
6785 (let ((value (message-fetch-field header)))
6787 (setq recipients (concat recipients ", " value))))))
6789 (string-match "[^ \t,]" mft)
6790 (or (not (eq message-use-mail-followup-to 'ask))
6791 (message-y-or-n-p "Obey Mail-Followup-To? " t "\
6792 You should normally obey the Mail-Followup-To: header. In this
6793 article, it has the value of
6797 which directs your response to " (if (string-match "," mft)
6798 "the specified addresses"
6799 "that address only") ".
6801 Most commonly, Mail-Followup-To is used by a mailing list poster to
6802 express that responses should be sent to just the list, and not the
6805 If a message is posted to several mailing lists, Mail-Followup-To may
6806 also be used to direct the following discussion to one list only,
6807 because discussions that are spread over several lists tend to be
6808 fragmented and very difficult to follow.
6810 Also, some source/announcement lists are not intended for discussion;
6811 responses here are directed to other addresses.
6813 You may customize the variable `message-use-mail-followup-to', if you
6814 want to get rid of this query permanently.")))
6815 (setq recipients (concat ", " mft)))
6817 (setq recipients (if never-mct "" (concat ", " author)))
6818 (if to (setq recipients (concat recipients ", " to)))
6819 (if cc (setq recipients (concat recipients ", " cc)))
6820 (if extra (setq recipients (concat recipients ", " extra)))
6821 (if mct (setq recipients (concat recipients ", " mct)))))
6822 (if (>= (length recipients) 2)
6823 ;; Strip the leading ", ".
6824 (setq recipients (substring recipients 2)))
6825 ;; Squeeze whitespace.
6826 (while (string-match "[ \t][ \t]+" recipients)
6827 (setq recipients (replace-match " " t t recipients)))
6828 ;; Remove addresses that match `message-dont-reply-to-names'.
6830 (cond ((functionp message-dont-reply-to-names)
6834 (mapcar (lambda (mail)
6835 (unless (funcall message-dont-reply-to-names
6836 (mail-strip-quoted-names mail))
6838 (message-tokenize-header recipients)))
6840 (t (let ((mail-dont-reply-to-names (message-dont-reply-to-names)))
6841 (mail-dont-reply-to recipients)))))
6842 ;; Perhaps "Mail-Copies-To: never" removed the only address?
6843 (if (string-equal recipients "")
6844 (setq recipients author))
6845 ;; Convert string to a list of (("foo@bar" . "Name <Foo@BAR>") ...).
6849 (if message-alter-recipients-function
6850 (funcall message-alter-recipients-function
6851 (cons (downcase (mail-strip-quoted-names addr))
6853 (cons (downcase (mail-strip-quoted-names addr)) addr)))
6854 (message-tokenize-header recipients)))
6855 ;; Remove all duplicates.
6856 (let ((s recipients))
6858 (let ((address (car (pop s))))
6859 (while (assoc address s)
6860 (setq recipients (delq (assoc address s) recipients)
6861 s (delq (assoc address s) s))))))
6863 ;; Remove hierarchical lists that are contained within each other,
6864 ;; if message-hierarchical-addresses is defined.
6865 (when message-hierarchical-addresses
6866 (let ((plain-addrs (mapcar 'car recipients))
6869 (setq subaddrs (assoc (car plain-addrs)
6870 message-hierarchical-addresses)
6871 plain-addrs (cdr plain-addrs))
6873 (setq subaddrs (cdr subaddrs))
6875 (setq recip (assoc (car subaddrs) recipients)
6876 subaddrs (cdr subaddrs))
6878 (setq recipients (delq recip recipients))))))))
6880 (setq recipients (message-prune-recipients recipients))
6882 ;; Build the header alist. Allow the user to be asked whether
6883 ;; or not to reply to all recipients in a wide reply.
6884 (setq follow-to (list (cons 'To (cdr (pop recipients)))))
6885 (when (and recipients
6886 (or (not message-wide-reply-confirm-recipients)
6887 (y-or-n-p "Reply to all recipients? ")))
6888 (setq recipients (mapconcat
6889 (lambda (addr) (cdr addr)) recipients ", "))
6890 (if (string-match "^ +" recipients)
6891 (setq recipients (substring recipients (match-end 0))))
6892 (push (cons 'Cc recipients) follow-to)))
6895 (defun message-prune-recipients (recipients)
6896 (dolist (rule message-prune-recipient-rules)
6897 (let ((match (car rule))
6900 (dolist (recipient recipients)
6901 (setq address (car recipient))
6902 (when (string-match match address)
6903 (setq dup-match (replace-match (cadr rule) nil nil address))
6904 (dolist (recipient recipients)
6905 ;; Don't delete the address that triggered this.
6906 (when (and (not (eq address (car recipient)))
6907 (string-match dup-match (car recipient)))
6908 (setq recipients (delq recipient recipients))))))))
6911 (defcustom message-simplify-subject-functions
6912 '(message-strip-list-identifiers
6913 message-strip-subject-re
6914 message-strip-subject-trailing-was
6915 message-strip-subject-encoded-words)
6916 "List of functions taking a string argument that simplify subjects.
6917 The functions are applied when replying to a message.
6919 Useful functions to put in this list include:
6920 `message-strip-list-identifiers', `message-strip-subject-re',
6921 `message-strip-subject-trailing-was', and
6922 `message-strip-subject-encoded-words'."
6923 :version "22.1" ;; Gnus 5.10.9
6924 :group 'message-various
6925 :type '(repeat function))
6927 (defun message-simplify-subject (subject &optional functions)
6928 "Return simplified SUBJECT."
6931 (setq functions message-simplify-subject-functions))
6932 (when (and (memq 'message-strip-list-identifiers functions)
6933 gnus-list-identifiers)
6934 (setq subject (message-strip-list-identifiers subject)))
6935 (when (memq 'message-strip-subject-re functions)
6936 (setq subject (concat "Re: " (message-strip-subject-re subject))))
6937 (when (and (memq 'message-strip-subject-trailing-was functions)
6938 message-subject-trailing-was-query)
6939 (setq subject (message-strip-subject-trailing-was subject)))
6940 (when (memq 'message-strip-subject-encoded-words functions)
6941 (setq subject (message-strip-subject-encoded-words subject)))
6945 (defun message-reply (&optional to-address wide switch-function)
6946 "Start editing a reply to the article in the current buffer."
6948 (require 'gnus-sum) ; for gnus-list-identifiers
6949 (let ((cur (current-buffer))
6951 references message-id follow-to
6952 (inhibit-point-motion-hooks t)
6953 (message-this-is-mail t)
6956 (message-narrow-to-head-1)
6957 ;; Allow customizations to have their say.
6959 ;; This is a regular reply.
6960 (when (functionp message-reply-to-function)
6962 (setq follow-to (funcall message-reply-to-function))))
6963 ;; This is a followup.
6964 (when (functionp message-wide-reply-to-function)
6967 (funcall message-wide-reply-to-function)))))
6968 (setq message-id (message-fetch-field "message-id" t)
6969 references (message-fetch-field "references")
6970 date (message-fetch-field "date")
6971 from (or (message-fetch-field "from") "nobody")
6972 subject (or (message-fetch-field "subject") "none"))
6974 ;; Strip list identifiers, "Re: ", and "was:"
6975 (setq subject (message-simplify-subject subject))
6977 (when (and (setq gnus-warning (message-fetch-field "gnus-warning"))
6978 (string-match "<[^>]+>" gnus-warning))
6979 (setq message-id (match-string 0 gnus-warning)))
6982 (setq follow-to (message-get-reply-headers wide to-address))))
6985 `((Subject . ,subject)
6987 (unless (message-mail-user-agent)
6988 (message-pop-to-buffer
6989 (message-buffer-name
6990 (if wide "wide reply" "reply") from
6991 (if wide to-address nil))
6993 (setq message-reply-headers
6994 (vector 0 (cdr (assq 'Subject headers))
6995 from date message-id references 0 0 ""))
6996 (message-setup headers cur))))
6999 (defun message-wide-reply (&optional to-address)
7000 "Make a \"wide\" reply to the message in the current buffer."
7002 (message-reply to-address t))
7005 (defun message-followup (&optional to-newsgroups)
7006 "Follow up to the message in the current buffer.
7007 If TO-NEWSGROUPS, use that as the new Newsgroups line."
7009 (require 'gnus-sum) ; for gnus-list-identifiers
7010 (let ((cur (current-buffer))
7011 from subject date reply-to mrt mct
7012 references message-id follow-to
7013 (inhibit-point-motion-hooks t)
7014 (message-this-is-news t)
7015 followup-to distribution newsgroups gnus-warning posted-to)
7018 (goto-char (point-min))
7019 (if (search-forward "\n\n" nil t)
7022 (when (functionp message-followup-to-function)
7024 (funcall message-followup-to-function)))
7025 (setq from (message-fetch-field "from")
7026 date (message-fetch-field "date")
7027 subject (or (message-fetch-field "subject") "none")
7028 references (message-fetch-field "references")
7029 message-id (message-fetch-field "message-id" t)
7030 followup-to (message-fetch-field "followup-to")
7031 newsgroups (message-fetch-field "newsgroups")
7032 posted-to (message-fetch-field "posted-to")
7033 reply-to (message-fetch-field "reply-to")
7034 mrt (message-fetch-field "mail-reply-to")
7035 distribution (message-fetch-field "distribution")
7036 mct (message-fetch-field "mail-copies-to"))
7037 (when (and (setq gnus-warning (message-fetch-field "gnus-warning"))
7038 (string-match "<[^>]+>" gnus-warning))
7039 (setq message-id (match-string 0 gnus-warning)))
7040 ;; Remove bogus distribution.
7041 (when (and (stringp distribution)
7042 (let ((case-fold-search t))
7043 (string-match "world" distribution)))
7044 (setq distribution nil))
7045 ;; Strip list identifiers, "Re: ", and "was:"
7046 (setq subject (message-simplify-subject subject))
7049 (message-pop-to-buffer (message-buffer-name "followup" from newsgroups))
7051 (setq message-reply-headers
7052 (vector 0 subject from date message-id references 0 0 ""))
7055 `((Subject . ,subject)
7058 (list (cons 'Newsgroups to-newsgroups)))
7059 (follow-to follow-to)
7060 ((and followup-to message-use-followup-to)
7063 ((equal (downcase followup-to) "poster")
7064 (if (or (eq message-use-followup-to 'use)
7065 (message-y-or-n-p "Obey Followup-To: poster? " t "\
7066 You should normally obey the Followup-To: header.
7068 `Followup-To: poster' sends your response via e-mail instead of news.
7070 A typical situation where `Followup-To: poster' is used is when the poster
7071 does not read the newsgroup, so he wouldn't see any replies sent to it.
7073 You may customize the variable `message-use-followup-to', if you
7074 want to get rid of this query permanently."))
7076 (setq message-this-is-news nil)
7077 (cons 'To (or mrt reply-to from "")))
7078 (cons 'Newsgroups newsgroups)))
7080 (if (or (equal followup-to newsgroups)
7081 (not (eq message-use-followup-to 'ask))
7083 (concat "Obey Followup-To: " followup-to "? ") t "\
7084 You should normally obey the Followup-To: header.
7086 `Followup-To: " followup-to "'
7087 directs your response to " (if (string-match "," followup-to)
7088 "the specified newsgroups"
7089 "that newsgroup only") ".
7091 If a message is posted to several newsgroups, Followup-To is often
7092 used to direct the following discussion to one newsgroup only,
7093 because discussions that are spread over several newsgroup tend to
7094 be fragmented and very difficult to follow.
7096 Also, some source/announcement newsgroups are not intended for discussion;
7097 responses here are directed to other newsgroups.
7099 You may customize the variable `message-use-followup-to', if you
7100 want to get rid of this query permanently."))
7101 (cons 'Newsgroups followup-to)
7102 (cons 'Newsgroups newsgroups))))))
7104 `((Newsgroups . ,posted-to)))
7106 `((Newsgroups . ,newsgroups))))
7107 ,@(and distribution (list (cons 'Distribution distribution)))
7109 (not (or (equal (downcase mct) "never")
7110 (equal (downcase mct) "nobody"))))
7111 (list (cons 'Cc (if (or (equal (downcase mct) "always")
7112 (equal (downcase mct) "poster"))
7113 (or mrt reply-to from "")
7118 (defun message-is-yours-p ()
7119 "Non-nil means current article is yours.
7120 If you have added `cancel-messages' to `message-shoot-gnksa-feet', all articles
7121 are yours except those that have Cancel-Lock header not belonging to you.
7122 Instead of shooting GNKSA feet, you should modify `message-alternative-emails'
7123 to match all of yours addresses."
7124 ;; Canlock-logic as suggested by Per Abrahamsen
7125 ;; <abraham@dina.kvl.dk>
7127 ;; IF article has cancel-lock THEN
7128 ;; IF we can verify it THEN
7131 ;; error: cancellock: article is not yours
7133 ;; Use old rules, comparing sender...
7136 (message-narrow-to-head-1)
7137 (if (and (message-fetch-field "Cancel-Lock")
7138 (message-gnksa-enable-p 'canlock-verify))
7139 (if (null (canlock-verify))
7141 (error "Failed to verify Cancel-lock: This article is not yours"))
7144 (message-gnksa-enable-p 'cancel-messages)
7145 (and (setq sender (message-fetch-field "sender"))
7146 (string-equal (downcase sender)
7147 (downcase (message-make-sender))))
7148 ;; Email address in From field equals to our address
7149 (and (setq from (message-fetch-field "from"))
7151 (downcase (car (mail-header-parse-address from)))
7152 (downcase (car (mail-header-parse-address
7153 (message-make-from))))))
7154 ;; Email address in From field matches
7155 ;; 'message-alternative-emails' regexp or function.
7157 message-alternative-emails
7158 (cond ((functionp message-alternative-emails)
7159 (funcall message-alternative-emails
7160 (mail-header-parse-address from)))
7161 (t (string-match message-alternative-emails
7162 (car (mail-header-parse-address from))))))))))))
7165 (defun message-cancel-news (&optional arg)
7166 "Cancel an article you posted.
7167 If ARG, allow editing of the cancellation message."
7169 (unless (message-news-p)
7170 (error "This is not a news article; canceling is impossible"))
7171 (let (from newsgroups message-id distribution buf)
7173 ;; Get header info from original article.
7175 (message-narrow-to-head-1)
7176 (setq from (message-fetch-field "from")
7177 newsgroups (message-fetch-field "newsgroups")
7178 message-id (message-fetch-field "message-id" t)
7179 distribution (message-fetch-field "distribution")))
7180 ;; Make sure that this article was written by the user.
7181 (unless (message-is-yours-p)
7182 (error "This article is not yours"))
7183 (when (yes-or-no-p "Do you really want to cancel this article? ")
7184 ;; Make control message.
7187 (setq buf (set-buffer (get-buffer-create " *message cancel*"))))
7189 (insert "Newsgroups: " newsgroups "\n"
7191 "Subject: cancel " message-id "\n"
7192 "Control: cancel " message-id "\n"
7194 (concat "Distribution: " distribution "\n")
7196 mail-header-separator "\n"
7197 message-cancel-message)
7198 (run-hooks 'message-cancel-hook)
7200 (message "Canceling your article...")
7201 (if (let ((message-syntax-checks
7202 'dont-check-for-anything-just-trust-me))
7203 (funcall message-send-news-function))
7204 (message "Canceling your article...done"))
7205 (kill-buffer buf))))))
7208 (defun message-supersede ()
7209 "Start composing a message to supersede the current message.
7210 This is done simply by taking the old article and adding a Supersedes
7211 header line with the old Message-ID."
7213 (let ((cur (current-buffer)))
7214 ;; Check whether the user owns the article that is to be superseded.
7215 (unless (message-is-yours-p)
7216 (error "This article is not yours"))
7217 ;; Get a normal message buffer.
7218 (message-pop-to-buffer (message-buffer-name "supersede"))
7219 (insert-buffer-substring cur)
7221 (message-narrow-to-head-1)
7222 ;; Remove unwanted headers.
7223 (when message-ignored-supersedes-headers
7224 (message-remove-header message-ignored-supersedes-headers t))
7225 (goto-char (point-min))
7226 (if (not (re-search-forward "^Message-ID: " nil t))
7227 (error "No Message-ID in this article")
7228 (replace-match "Supersedes: " t t))
7229 (goto-char (point-max))
7230 (insert mail-header-separator)
7235 (defun message-recover ()
7236 "Reread contents of current buffer from its last auto-save file."
7238 (let ((file-name (make-auto-save-file-name)))
7239 (cond ((save-window-excursion
7240 (with-output-to-temp-buffer "*Directory*"
7241 (with-current-buffer standard-output
7242 (fundamental-mode)) ; for Emacs 20.4+
7243 (buffer-disable-undo standard-output)
7244 (let ((default-directory "/"))
7246 "ls" nil standard-output nil "-l" file-name)))
7247 (yes-or-no-p (format "Recover auto save file %s? " file-name)))
7248 (let ((buffer-read-only nil))
7250 (insert-file-contents file-name nil)))
7251 (t (error "message-recover canceled")))))
7253 ;;; Washing Subject:
7255 (defun message-wash-subject (subject)
7256 "Remove junk like \"Re:\", \"(fwd)\", etc. added to subject string SUBJECT.
7257 Previous forwarders, repliers, etc. may add it."
7260 (goto-char (point-min))
7261 ;; strip Re/Fwd stuff off the beginning
7262 (while (re-search-forward
7263 "\\([Rr][Ee]:\\|[Ff][Ww][Dd]\\(\\[[0-9]*\\]\\)?:\\|[Ff][Ww]:\\)" nil t)
7266 ;; and gnus-style forwards [foo@bar.com] subject
7267 (goto-char (point-min))
7268 (while (re-search-forward "\\[[^ \t]*\\(@\\|\\.\\)[^ \t]*\\]" nil t)
7272 (goto-char (point-max))
7273 (while (re-search-backward "([Ff][Ww][Dd])" nil t)
7276 ;; and finally, any whitespace that was left-over
7277 (goto-char (point-min))
7278 (while (re-search-forward "^[ \t]+" nil t)
7280 (goto-char (point-max))
7281 (while (re-search-backward "[ \t]+$" nil t)
7286 ;;; Forwarding messages.
7288 (defvar message-forward-decoded-p nil
7289 "Non-nil means the original message is decoded.")
7291 (defun message-forward-subject-name-subject (subject)
7292 "Generate a SUBJECT for a forwarded message.
7293 The form is: [Source] Subject, where if the original message was mail,
7294 Source is the name of the sender, and if the original message was
7295 news, Source is the list of newsgroups is was posted to."
7296 (let* ((group (message-fetch-field "newsgroups"))
7297 (from (message-fetch-field "from"))
7300 (gnus-group-decoded-name group)
7302 (car (gnus-extract-address-components from))
7303 (cadr (gnus-extract-address-components from))))
7306 (if message-forward-decoded-p
7308 (mail-decode-encoded-word-string prefix))
7311 (defun message-forward-subject-author-subject (subject)
7312 "Generate a SUBJECT for a forwarded message.
7313 The form is: [Source] Subject, where if the original message was mail,
7314 Source is the sender, and if the original message was news, Source is
7315 the list of newsgroups is was posted to."
7316 (let* ((group (message-fetch-field "newsgroups"))
7319 (gnus-group-decoded-name group)
7320 (or (message-fetch-field "from")
7323 (if message-forward-decoded-p
7325 (mail-decode-encoded-word-string prefix))
7328 (defun message-forward-subject-fwd (subject)
7329 "Generate a SUBJECT for a forwarded message.
7330 The form is: Fwd: Subject, where Subject is the original subject of
7332 (if (string-match "^Fwd: " subject)
7334 (concat "Fwd: " subject)))
7336 (defun message-make-forward-subject ()
7337 "Return a Subject header suitable for the message in the current buffer."
7340 (message-narrow-to-head-1)
7341 (let ((funcs message-make-forward-subject-function)
7342 (subject (message-fetch-field "Subject")))
7345 (if message-forward-decoded-p
7347 (mail-decode-encoded-word-string subject))
7349 (when message-wash-forwarded-subjects
7350 (setq subject (message-wash-subject subject)))
7351 ;; Make sure funcs is a list.
7354 (setq funcs (list funcs)))
7355 ;; Apply funcs in order, passing subject generated by previous
7356 ;; func to the next one.
7357 (dolist (func funcs)
7358 (when (functionp func)
7359 (setq subject (funcall func subject))))
7362 (defvar gnus-article-decoded-p)
7366 (defun message-forward (&optional news digest)
7367 "Forward the current message via mail.
7368 Optional NEWS will use news to forward instead of mail.
7369 Optional DIGEST will use digest to forward."
7371 (let* ((cur (current-buffer))
7372 (message-forward-decoded-p
7373 (if (local-variable-p 'gnus-article-decoded-p (current-buffer))
7374 gnus-article-decoded-p ;; In an article buffer.
7375 message-forward-decoded-p))
7376 (subject (message-make-forward-subject)))
7378 (message-news nil subject)
7379 (message-mail nil subject))
7380 (message-forward-make-body cur digest)))
7382 (defun message-forward-make-body-plain (forward-buffer)
7384 "\n-------------------- Start of forwarded message --------------------\n")
7386 (contents (with-current-buffer forward-buffer (buffer-string)))
7388 (unless (multibyte-string-p contents)
7389 (error "Attempt to insert unibyte string from the buffer \"%s\"\
7390 to the multibyte buffer \"%s\""
7391 (if (bufferp forward-buffer)
7392 (buffer-name forward-buffer)
7395 (insert (mm-with-multibyte-buffer
7398 (goto-char (point-min))
7399 (when (looking-at "From ")
7400 (replace-match "X-From-Line: "))
7402 (unless (bolp) (insert "\n"))
7405 "-------------------- End of forwarded message --------------------\n")
7406 (message-remove-ignored-headers b e)))
7408 (defun message-remove-ignored-headers (b e)
7409 (when (or message-forward-ignored-headers
7410 message-forward-included-headers)
7412 (narrow-to-region b e)
7414 (narrow-to-region (point)
7415 (or (search-forward "\n\n" nil t) (point)))
7416 (when message-forward-ignored-headers
7417 (let ((ignored (if (stringp message-forward-ignored-headers)
7418 (list message-forward-ignored-headers)
7419 message-forward-ignored-headers)))
7420 (dolist (elem ignored)
7421 (message-remove-header elem t))))
7422 (when message-forward-included-headers
7423 (message-remove-header
7424 (if (listp message-forward-included-headers)
7425 (regexp-opt message-forward-included-headers)
7426 message-forward-included-headers)
7429 (defun message-forward-make-body-mime (forward-buffer &optional beg end)
7431 (insert "\n\n<#part type=message/rfc822 disposition=inline raw=t>\n")
7433 (narrow-to-region (point) (point))
7434 (insert-buffer-substring forward-buffer beg end)
7435 (mml-quote-region (point-min) (point-max))
7436 (goto-char (point-min))
7437 (when (looking-at "From ")
7438 (replace-match "X-From-Line: "))
7439 (goto-char (point-max)))
7440 (insert "<#/part>\n")
7441 ;; Consider there is no illegible text.
7442 (add-text-properties
7444 `(no-illegible-text t rear-nonsticky t start-open t))))
7446 (defun message-forward-make-body-mml (forward-buffer)
7447 (insert "\n\n<#mml type=message/rfc822 disposition=inline>\n")
7448 (let ((b (point)) e)
7449 (if (not message-forward-decoded-p)
7450 (let ((contents (with-current-buffer forward-buffer (buffer-string))))
7451 (unless (multibyte-string-p contents)
7452 (error "Attempt to insert unibyte string from the buffer \"%s\"\
7453 to the multibyte buffer \"%s\""
7454 (if (bufferp forward-buffer)
7455 (buffer-name forward-buffer)
7458 (insert (mm-with-multibyte-buffer
7461 (goto-char (point-min))
7462 (when (looking-at "From ")
7463 (replace-match "X-From-Line: "))
7466 (narrow-to-region (point) (point))
7467 (mml-insert-buffer forward-buffer)
7468 (goto-char (point-min))
7469 (when (looking-at "From ")
7470 (replace-match "X-From-Line: "))
7471 (goto-char (point-max))))
7473 (insert "<#/mml>\n")
7474 (when (not message-forward-decoded-p)
7475 (message-remove-ignored-headers b e))))
7477 (defun message-forward-make-body-digest-plain (forward-buffer)
7479 "\n-------------------- Start of forwarded message --------------------\n")
7480 (mml-insert-buffer forward-buffer)
7482 "\n-------------------- End of forwarded message --------------------\n"))
7484 (defun message-forward-make-body-digest-mime (forward-buffer)
7485 (insert "\n<#multipart type=digest>\n")
7486 (let ((b (point)) e)
7487 (insert-buffer-substring forward-buffer)
7489 (insert "<#/multipart>\n")
7491 (narrow-to-region b e)
7493 (narrow-to-region (point)
7494 (or (search-forward "\n\n" nil t) (point)))
7495 (delete-region (point-min) (point-max)))))
7497 (defun message-forward-make-body-digest (forward-buffer)
7498 (if message-forward-as-mime
7499 (message-forward-make-body-digest-mime forward-buffer)
7500 (message-forward-make-body-digest-plain forward-buffer)))
7502 (autoload 'mm-uu-dissect-text-parts "mm-uu")
7503 (autoload 'mm-uu-dissect "mm-uu")
7505 (defun message-signed-or-encrypted-p (&optional dont-emulate-mime handles)
7506 "Say whether the current buffer contains signed or encrypted message.
7507 If DONT-EMULATE-MIME is nil, this function does the MIME emulation on
7508 messages that don't conform to PGP/MIME described in RFC2015. HANDLES
7509 is for the internal use."
7511 (let ((mm-decrypt-option 'never)
7512 (mm-verify-option 'never))
7513 (if (setq handles (mm-dissect-buffer nil t))
7514 (unless dont-emulate-mime
7515 (mm-uu-dissect-text-parts handles))
7516 (unless dont-emulate-mime
7517 (setq handles (mm-uu-dissect))))))
7518 ;; Check text/plain message in which there is a signed or encrypted
7519 ;; body that has been encoded by B or Q.
7520 (unless (or handles dont-emulate-mime)
7521 (let ((cur (current-buffer))
7522 (mm-decrypt-option 'never)
7523 (mm-verify-option 'never))
7525 (insert-buffer-substring cur)
7526 (when (setq handles (mm-dissect-buffer t t))
7527 (if (and (bufferp (car handles))
7528 (equal (mm-handle-media-type handles) "text/plain"))
7531 (insert-buffer-substring (car handles))
7532 (mm-decode-content-transfer-encoding
7533 (mm-handle-encoding handles))
7534 (mm-destroy-parts handles)
7535 (setq handles (mm-uu-dissect)))
7536 (mm-destroy-parts handles)
7537 (setq handles nil))))))
7541 (dolist (handle (if (stringp (car handles))
7542 (if (member (car handles)
7543 '("multipart/signed"
7544 "multipart/encrypted"))
7548 (if (stringp (car handle))
7549 (when (message-signed-or-encrypted-p dont-emulate-mime handle)
7551 (when (and (bufferp (car handle))
7552 (equal (mm-handle-media-type handle)
7554 (with-current-buffer (mm-handle-buffer handle)
7555 (when (message-signed-or-encrypted-p dont-emulate-mime)
7556 (throw 'found t)))))))
7557 (mm-destroy-parts handles))))
7560 (defun message-forward-make-body (forward-buffer &optional digest)
7561 ;; Put point where we want it before inserting the forwarded
7563 (if message-forward-before-signature
7565 (goto-char (point-max)))
7567 (message-forward-make-body-digest forward-buffer)
7568 (if message-forward-as-mime
7569 (if (and message-forward-show-mml
7570 (not (and (eq message-forward-show-mml 'best)
7571 ;; Use the raw form in the body if it contains
7572 ;; signed or encrypted message so as not to be
7573 ;; destroyed by re-encoding.
7574 (with-current-buffer forward-buffer
7576 (message-signed-or-encrypted-p)
7578 (message-forward-make-body-mml forward-buffer)
7579 (message-forward-make-body-mime forward-buffer))
7580 (message-forward-make-body-plain forward-buffer)))
7581 (message-position-point))
7583 (declare-function rmail-toggle-header "rmail" (&optional arg))
7586 (defun message-forward-rmail-make-body (forward-buffer)
7587 (save-window-excursion
7588 (set-buffer forward-buffer)
7589 (when (rmail-msg-is-pruned)
7590 (rmail-toggle-header 0)))
7591 (message-forward-make-body forward-buffer))
7593 ;; Fixme: Should have defcustom.
7595 (defun message-insinuate-rmail ()
7596 "Let RMAIL use message to forward."
7598 (setq rmail-enable-mime-composing t)
7599 (setq rmail-insert-mime-forwarded-message-function
7600 'message-forward-rmail-make-body))
7602 (defvar message-inhibit-body-encoding nil)
7605 (defun message-resend (address)
7606 "Resend the current article to ADDRESS."
7608 (list (message-read-from-minibuffer "Resend message to: ")))
7609 (message "Resending message to %s..." address)
7611 (let ((cur (current-buffer))
7613 ;; We first set up a normal mail buffer.
7614 (unless (message-mail-user-agent)
7615 (set-buffer (get-buffer-create " *message resend*"))
7616 (let ((inhibit-read-only t))
7618 (let ((message-this-is-mail t)
7619 message-generate-hashcash
7621 (message-setup `((To . ,address))))
7622 ;; Insert our usual headers.
7623 (message-generate-headers '(From Date To Message-ID))
7624 (message-narrow-to-headers)
7625 (when (setq gcc (mail-fetch-field "gcc" nil t))
7626 (message-remove-header "gcc"))
7627 ;; Remove X-Draft-From header etc.
7628 (message-remove-header message-ignored-mail-headers t)
7629 ;; Rename them all to "Resent-*".
7630 (goto-char (point-min))
7631 (while (re-search-forward "^[A-Za-z]" nil t)
7636 (let ((inhibit-read-only t))
7637 (delete-region (point) (point-max)))
7639 ;; Insert the message to be resent.
7640 (insert-buffer-substring cur)
7641 (goto-char (point-min))
7642 (search-forward "\n\n")
7645 (narrow-to-region beg (point))
7646 (message-remove-header message-ignored-resent-headers t)
7647 (goto-char (point-max)))
7648 (insert mail-header-separator)
7649 ;; Rename all old ("Also-")Resent headers.
7650 (while (re-search-backward "^\\(Also-\\)*Resent-" beg t)
7653 ;; Quote any "From " lines at the beginning.
7655 (when (looking-at "From ")
7656 (replace-match "X-From-Line: "))
7658 (let ((message-inhibit-body-encoding
7659 ;; Don't do any further encoding if it looks like the
7660 ;; message has already been encoded.
7661 (let ((case-fold-search t))
7662 (re-search-forward "^mime-version:" nil t)))
7663 (message-inhibit-ecomplete t)
7664 message-required-mail-headers
7665 message-generate-hashcash
7666 rfc2047-encode-encoded-words)
7667 (message-send-mail))
7670 (insert "Gcc: " gcc "\n"))
7671 (run-hooks 'message-sent-hook)
7672 (kill-buffer (current-buffer)))
7673 (message "Resending message to %s...done" address)))
7676 (defun message-bounce ()
7677 "Re-mail the current message.
7678 This only makes sense if the current message is a bounce message that
7679 contains some mail you have written which has been bounced back to
7682 (let ((handles (mm-dissect-buffer t))
7684 (message-pop-to-buffer (message-buffer-name "bounce"))
7685 (if (stringp (car handles))
7686 ;; This is a MIME bounce.
7687 (mm-insert-part (car (last handles)))
7688 ;; This is a non-MIME bounce, so we try to remove things
7690 (mm-insert-part handles)
7692 (goto-char (point-min))
7693 (re-search-forward "\n\n+" nil t)
7694 (setq boundary (point))
7695 ;; We remove everything before the bounced mail.
7696 (if (or (re-search-forward message-unsent-separator nil t)
7698 (search-forward "\n\n" nil 'move)
7699 (re-search-backward "^Return-Path:.*\n" boundary t)))
7702 (delete-region (point-min)
7703 (if (re-search-forward "^[^ \n\t]+:" nil t)
7706 (goto-char boundary)
7707 (when (re-search-backward "^.?From .*\n" nil t)
7708 (delete-region (match-beginning 0) (match-end 0)))))
7711 (message-narrow-to-head-1)
7712 (message-remove-header message-ignored-bounced-headers t)
7713 (goto-char (point-max))
7714 (insert mail-header-separator))
7715 (message-position-point)))
7718 ;;; Interactive entry points for new message buffers.
7722 (defun message-mail-other-window (&optional to subject)
7723 "Like `message-mail' command, but display mail buffer in another window."
7725 (unless (message-mail-user-agent)
7726 (message-pop-to-buffer (message-buffer-name "mail" to)
7727 'switch-to-buffer-other-window))
7728 (let ((message-this-is-mail t))
7729 (message-setup `((To . ,(or to "")) (Subject . ,(or subject "")))
7730 nil nil nil 'switch-to-buffer-other-window)))
7733 (defun message-mail-other-frame (&optional to subject)
7734 "Like `message-mail' command, but display mail buffer in another frame."
7736 (unless (message-mail-user-agent)
7737 (message-pop-to-buffer (message-buffer-name "mail" to)
7738 'switch-to-buffer-other-frame))
7739 (let ((message-this-is-mail t))
7740 (message-setup `((To . ,(or to "")) (Subject . ,(or subject "")))
7741 nil nil nil 'switch-to-buffer-other-frame)))
7744 (defun message-news-other-window (&optional newsgroups subject)
7745 "Start editing a news article to be sent."
7747 (message-pop-to-buffer (message-buffer-name "posting" nil newsgroups)
7748 'switch-to-buffer-other-window)
7749 (let ((message-this-is-news t))
7750 (message-setup `((Newsgroups . ,(or newsgroups ""))
7751 (Subject . ,(or subject ""))))))
7754 (defun message-news-other-frame (&optional newsgroups subject)
7755 "Start editing a news article to be sent."
7757 (message-pop-to-buffer (message-buffer-name "posting" nil newsgroups)
7758 'switch-to-buffer-other-frame)
7759 (let ((message-this-is-news t))
7760 (message-setup `((Newsgroups . ,(or newsgroups ""))
7761 (Subject . ,(or subject ""))))))
7765 ;; This code should be moved to underline.el (from which it is stolen).
7768 (defun message-bold-region (start end)
7769 "Bold all nonblank characters in the region.
7770 Works by overstriking characters.
7771 Called from program, takes two arguments START and END
7772 which specify the range to operate on."
7775 (let ((end1 (make-marker)))
7776 (move-marker end1 (max start end))
7777 (goto-char (min start end))
7778 (while (< (point) end1)
7779 (or (looking-at "[_\^@- ]")
7780 (insert (char-after) "\b"))
7781 (forward-char 1)))))
7784 (defun message-unbold-region (start end)
7785 "Remove all boldness (overstruck characters) in the region.
7786 Called from program, takes two arguments START and END
7787 which specify the range to operate on."
7790 (let ((end1 (make-marker)))
7791 (move-marker end1 (max start end))
7792 (goto-char (min start end))
7793 (while (search-forward "\b" end1 t)
7794 (if (eq (char-after) (char-after (- (point) 2)))
7795 (delete-char -2))))))
7797 (defun message-exchange-point-and-mark ()
7798 "Exchange point and mark, but don't activate region if it was inactive."
7799 (goto-char (prog1 (mark t)
7800 (set-marker (mark-marker) (point)))))
7802 ;; Support for toolbar
7803 (defvar tool-bar-mode)
7805 ;; Note: The :set function in the `message-tool-bar*' variables will only
7806 ;; affect _new_ message buffers. We might add a function that walks thru all
7807 ;; message-mode buffers and force the update.
7808 (defun message-tool-bar-update (&optional symbol value)
7809 "Update message mode toolbar.
7810 Setter function for custom variables."
7811 (setq-default message-tool-bar-map nil)
7813 ;; When used as ":set" function:
7814 (set-default symbol value)))
7816 (defcustom message-tool-bar (if (eq gmm-tool-bar-style 'gnome)
7817 'message-tool-bar-gnome
7818 'message-tool-bar-retro)
7819 "Specifies the message mode tool bar.
7821 It can be either a list or a symbol referring to a list. See
7822 `gmm-tool-bar-from-list' for the format of the list. The
7823 default key map is `message-mode-map'.
7825 Pre-defined symbols include `message-tool-bar-gnome' and
7826 `message-tool-bar-retro'."
7827 :type '(repeat gmm-tool-bar-list-item)
7828 :type '(choice (const :tag "GNOME style" message-tool-bar-gnome)
7829 (const :tag "Retro look" message-tool-bar-retro)
7830 (repeat :tag "User defined list" gmm-tool-bar-item)
7832 :version "23.1" ;; No Gnus
7833 :initialize 'custom-initialize-default
7834 :set 'message-tool-bar-update
7837 (defcustom message-tool-bar-gnome
7838 '((ispell-message "spell" nil
7840 :visible (not flyspell-mode))
7841 (flyspell-buffer "spell" t
7843 :visible flyspell-mode
7844 :help "Flyspell whole buffer")
7845 (message-send-and-exit "mail/send" t :label "Send")
7846 (message-dont-send "mail/save-draft")
7847 (mml-attach-file "attach" mml-mode-map :vert-only t)
7848 (mml-preview "mail/preview" mml-mode-map)
7849 (mml-secure-message-sign-encrypt "lock" mml-mode-map :visible nil)
7850 (message-insert-importance-high "important" nil :visible nil)
7851 (message-insert-importance-low "unimportant" nil :visible nil)
7852 (message-insert-disposition-notification-to "receipt" nil :visible nil))
7853 "List of items for the message tool bar (GNOME style).
7855 See `gmm-tool-bar-from-list' for details on the format of the list."
7856 :type '(repeat gmm-tool-bar-item)
7857 :version "23.1" ;; No Gnus
7858 :initialize 'custom-initialize-default
7859 :set 'message-tool-bar-update
7862 (defcustom message-tool-bar-retro
7863 '(;; Old Emacs 21 icon for consistency.
7864 (message-send-and-exit "gnus/mail-send")
7865 (message-kill-buffer "close")
7866 (message-dont-send "cancel")
7867 (mml-attach-file "attach" mml-mode-map)
7868 (ispell-message "spell")
7869 (mml-preview "preview" mml-mode-map)
7870 (message-insert-importance-high "gnus/important")
7871 (message-insert-importance-low "gnus/unimportant")
7872 (message-insert-disposition-notification-to "gnus/receipt"))
7873 "List of items for the message tool bar (retro style).
7875 See `gmm-tool-bar-from-list' for details on the format of the list."
7876 :type '(repeat gmm-tool-bar-item)
7877 :version "23.1" ;; No Gnus
7878 :initialize 'custom-initialize-default
7879 :set 'message-tool-bar-update
7882 (defcustom message-tool-bar-zap-list
7883 '(new-file open-file dired kill-buffer write-file
7884 print-buffer customize help)
7885 "List of icon items from the global tool bar.
7886 These items are not displayed on the message mode tool bar.
7888 See `gmm-tool-bar-from-list' for the format of the list."
7889 :type 'gmm-tool-bar-zap-list
7890 :version "23.1" ;; No Gnus
7891 :initialize 'custom-initialize-default
7892 :set 'message-tool-bar-update
7895 (defvar image-load-path)
7897 (defun message-make-tool-bar (&optional force)
7898 "Make a message mode tool bar from `message-tool-bar-list'.
7899 When FORCE, rebuild the tool bar."
7900 (when (and (boundp 'tool-bar-mode)
7902 (or (not message-tool-bar-map) force))
7903 (setq message-tool-bar-map
7905 (gmm-image-load-path-for-library "message"
7906 "mail/save-draft.xpm"
7908 (image-load-path (cons (car load-path) image-load-path)))
7909 (gmm-tool-bar-from-list message-tool-bar
7910 message-tool-bar-zap-list
7911 'message-mode-map))))
7912 message-tool-bar-map)
7914 ;;; Group name completion.
7916 (defcustom message-newgroups-header-regexp
7917 "^\\(Newsgroups\\|Followup-To\\|Posted-To\\|Gcc\\):"
7918 "Regexp that match headers that lists groups."
7922 (defcustom message-completion-alist
7923 (list (cons message-newgroups-header-regexp 'message-expand-group)
7924 '("^\\(Resent-\\)?\\(To\\|B?Cc\\):" . message-expand-name)
7925 '("^\\(Reply-To\\|From\\|Mail-Followup-To\\|Mail-Copies-To\\):"
7926 . message-expand-name)
7927 '("^\\(Disposition-Notification-To\\|Return-Receipt-To\\):"
7928 . message-expand-name))
7929 "Alist of (RE . FUN). Use FUN for completion on header lines matching RE."
7932 :type '(alist :key-type regexp :value-type function))
7934 (defcustom message-expand-name-databases
7936 "List of databases to try for name completion (`message-expand-name').
7937 Each element is a symbol and can be `bbdb' or `eudc'."
7939 :type '(set (const bbdb) (const eudc)))
7941 (defcustom message-tab-body-function nil
7942 "*Function to execute when `message-tab' (TAB) is executed in the body.
7943 If nil, the function bound in `text-mode-map' or `global-map' is executed."
7946 :link '(custom-manual "(message)Various Commands")
7947 :type '(choice (const nil)
7950 (declare-function mail-abbrev-in-expansion-header-p "mailabbrev" ())
7952 (defun message-tab ()
7953 "Complete names according to `message-completion-alist'.
7954 Execute function specified by `message-tab-body-function' when
7955 not in those headers. If that variable is nil, indent with the
7956 regular text mode tabbing command."
7959 ((let ((completion-fail-discreetly t))
7960 (completion-at-point))
7961 ;; Completion was performed; nothing else to do.
7963 (message-tab-body-function (funcall message-tab-body-function))
7964 (t (funcall (or (lookup-key text-mode-map "\t")
7965 (lookup-key global-map "\t")
7966 'indent-relative)))))
7968 (defvar mail-abbrev-mode-regexp)
7970 (defun message-completion-function ()
7971 (let ((alist message-completion-alist))
7973 (let ((mail-abbrev-mode-regexp (caar alist)))
7974 (not (mail-abbrev-in-expansion-header-p))))
7975 (setq alist (cdr alist)))
7977 (lexical-let ((fun (cdar alist)))
7978 ;; Even if completion fails, return a non-nil value, so as to avoid
7979 ;; falling back to message-tab-body-function.
7980 (lambda () (funcall fun) 'completion-attempted)))))
7982 (defun message-expand-group ()
7983 "Expand the group name under point."
7984 (let ((b (save-excursion
7989 (skip-chars-forward "^:")
7992 (skip-chars-backward "^, \t\n") (point))))
7993 (completion-ignore-case t)
7994 (e (progn (skip-chars-forward "^,\t\n ") (point)))
7996 (when (and (boundp 'gnus-active-hashtb)
8000 (setq group (symbol-name symbol))
8001 (push (if (string-match "[^\000-\177]" group)
8002 (gnus-group-decoded-name group)
8005 gnus-active-hashtb))
8006 (completion-in-region b e collection)))
8008 (defun message-expand-name ()
8009 (cond ((and (memq 'eudc message-expand-name-databases)
8010 (boundp 'eudc-protocol)
8012 (eudc-expand-inline))
8013 ((and (memq 'bbdb message-expand-name-databases)
8014 (fboundp 'bbdb-complete-name))
8015 (let ((starttick (buffer-modified-tick)))
8016 (or (bbdb-complete-name)
8017 ;; Apparently, bbdb-complete-name can return nil even when
8018 ;; completion took place. So let's double check the buffer was
8020 (/= starttick (buffer-modified-tick)))))
8026 (defun message-talkative-question (ask question show &rest text)
8027 "Call FUNCTION with argument QUESTION; optionally display TEXT... args.
8028 If SHOW is non-nil, the arguments TEXT... are displayed in a temp buffer.
8029 The following arguments may contain lists of values."
8031 (setq text (message-flatten-list text)))
8032 (save-window-excursion
8033 (with-output-to-temp-buffer " *MESSAGE information message*"
8034 (with-current-buffer " *MESSAGE information message*"
8035 (fundamental-mode) ; for Emacs 20.4+
8037 (goto-char (point-min))))
8038 (funcall ask question))
8039 (funcall ask question)))
8041 (defun message-flatten-list (list)
8042 "Return a new, flat list that contains all elements of LIST.
8044 \(message-flatten-list \\='(1 (2 3 (4 5 (6))) 7))
8047 (apply 'append (mapcar 'message-flatten-list list)))
8051 (defun message-generate-new-buffer-clone-locals (name &optional varstr)
8052 "Create and return a buffer with name based on NAME using `generate-new-buffer'.
8053 Then clone the local variables and values from the old buffer to the
8054 new one, cloning only the locals having a substring matching the
8056 (let ((oldbuf (current-buffer)))
8057 (with-current-buffer (generate-new-buffer name)
8058 (message-clone-locals oldbuf varstr)
8061 (defun message-clone-locals (buffer &optional varstr)
8062 "Clone the local variables from BUFFER to the current buffer."
8063 (let ((locals (with-current-buffer buffer (buffer-local-variables)))
8064 (regexp "^gnus\\|^nn\\|^message\\|^sendmail\\|^smtp\\|^user-mail-address"))
8067 (when (and (consp local)
8069 (string-match regexp (symbol-name (car local)))
8071 (string-match varstr (symbol-name (car local)))))
8073 (set (make-local-variable (car local))
8081 (defun message-encode-message-body ()
8082 (unless message-inhibit-body-encoding
8083 (let ((mail-parse-charset (or mail-parse-charset
8084 message-default-charset))
8085 (case-fold-search t)
8086 lines content-type-p)
8089 (narrow-to-region (point) (point-max))
8090 (let ((new (mml-generate-mime)))
8092 (delete-region (point-min) (point-max))
8094 (goto-char (point-min))
8095 (if (eq (aref new 0) ?\n)
8097 (search-forward "\n\n")
8098 (setq lines (buffer-substring (point-min) (1- (point))))
8099 (delete-region (point-min) (point))))))
8101 (message-narrow-to-headers-or-head)
8102 (message-remove-header "Mime-Version")
8103 (goto-char (point-max))
8104 (insert "MIME-Version: 1.0\n")
8107 (setq content-type-p
8109 (re-search-backward "^Content-Type:" nil t))))
8111 (message-narrow-to-headers-or-head)
8112 (message-remove-first-header "Content-Type")
8113 (message-remove-first-header "Content-Transfer-Encoding"))
8114 ;; We always make sure that the message has a Content-Type
8115 ;; header. This is because some broken MTAs and MUAs get
8116 ;; awfully confused when confronted with a message with a
8117 ;; MIME-Version header and without a Content-Type header. For
8118 ;; instance, Solaris' /usr/bin/mail.
8119 (unless content-type-p
8120 (goto-char (point-min))
8121 ;; For unknown reason, MIME-Version doesn't exist.
8122 (when (re-search-forward "^MIME-Version:" nil t)
8124 (insert "Content-Type: text/plain; charset=us-ascii\n"))))))
8126 (defun message-read-from-minibuffer (prompt &optional initial-contents)
8127 "Read from the minibuffer while providing abbrev expansion."
8128 (let ((minibuffer-setup-hook 'mail-abbrevs-setup)
8129 (minibuffer-local-map message-minibuffer-local-map))
8130 (read-from-minibuffer prompt initial-contents)))
8132 (defun message-use-alternative-email-as-from ()
8133 "Set From field of the outgoing message to the first matching
8134 address in `message-alternative-emails', looking at To, Cc and
8135 From headers in the original article."
8136 (require 'mail-utils)
8137 (let* ((fields '("To" "Cc" "From"))
8139 (message-tokenize-header
8140 (mail-strip-quoted-names
8141 (mapconcat 'message-fetch-reply-field fields ","))))
8142 (email (cond ((functionp message-alternative-emails)
8143 (car (cl-remove-if-not message-alternative-emails emails)))
8144 (t (loop for email in emails
8145 if (string-match-p message-alternative-emails email)
8147 (unless (or (not email) (equal email user-mail-address))
8148 (message-remove-header "From")
8149 (goto-char (point-max))
8150 (insert "From: " (let ((user-mail-address email)) (message-make-from))
8153 (defun message-options-get (symbol)
8154 (cdr (assq symbol message-options)))
8156 (defun message-options-set (symbol value)
8157 (let ((the-cons (assq symbol message-options)))
8160 (setcdr the-cons value)
8161 (setq message-options (delq the-cons message-options)))
8163 (push (cons symbol value) message-options))))
8166 (defun message-options-set-recipient ()
8168 (message-narrow-to-headers-or-head)
8169 (message-options-set 'message-sender
8170 (mail-strip-quoted-names
8171 (message-fetch-field "from")))
8172 (message-options-set 'message-recipients
8173 (mail-strip-quoted-names
8174 (let ((to (message-fetch-field "to"))
8175 (cc (message-fetch-field "cc"))
8176 (bcc (message-fetch-field "bcc")))
8179 (if (and to cc) ", ")
8181 (if (and (or to cc) bcc) ", ")
8184 (defun message-hide-headers ()
8185 "Hide headers based on the `message-hidden-headers' variable."
8186 (let ((regexps (if (stringp message-hidden-headers)
8187 (list message-hidden-headers)
8188 message-hidden-headers))
8189 (inhibit-point-motion-hooks t)
8190 (inhibit-modification-hooks t)
8191 (end-of-headers (point-min)))
8195 (message-narrow-to-headers)
8196 (goto-char (point-min))
8198 (if (not (message-hide-header-p regexps))
8199 (message-next-header)
8200 (let ((begin (point))
8202 (message-next-header)
8203 (setq header (buffer-substring begin (point))
8204 header-len (- (point) begin))
8205 (delete-region begin (point))
8206 (goto-char end-of-headers)
8208 (setq end-of-headers
8209 (+ end-of-headers header-len))))))))
8210 (narrow-to-region end-of-headers (point-max))))
8212 (defun message-hide-header-p (regexps)
8215 (when (eq (car regexps) 'not)
8218 (dolist (regexp regexps)
8219 (setq result (or result (looking-at regexp))))
8224 (declare-function ecomplete-add-item "ecomplete" (type key text))
8225 (declare-function ecomplete-save "ecomplete" ())
8227 (defun message-put-addresses-in-ecomplete ()
8228 (require 'ecomplete)
8229 (dolist (header '("to" "cc" "from" "reply-to"))
8230 (let ((value (message-field-value header)))
8231 (dolist (string (mail-header-parse-addresses value 'raw))
8233 (replace-regexp-in-string
8235 (replace-regexp-in-string "^ +\\| +$" "" string)))
8236 (ecomplete-add-item 'mail (car (mail-header-parse-address string))
8240 (autoload 'ecomplete-display-matches "ecomplete")
8242 (defun message-display-abbrev (&optional choose)
8243 "Display the next possible abbrev for the text before point."
8244 (interactive (list t))
8245 (when (and (memq (char-after (point-at-bol)) '(?C ?T ?\t ? ))
8246 (message-point-in-header-p)
8249 (while (and (memq (char-after) '(?\t ? ))
8250 (zerop (forward-line -1))))
8251 (looking-at "To:\\|Cc:")))
8252 (let* ((end (point))
8253 (start (save-excursion
8254 (and (re-search-backward "[\n\t ]" nil t)
8256 (word (when start (buffer-substring start end)))
8257 (match (when (and word
8258 (not (zerop (length word))))
8259 (ecomplete-display-matches 'mail word choose))))
8260 (when (and choose match)
8261 (delete-region start end)
8264 ;; To send pre-formatted letters like the example below, you can use
8265 ;; `message-send-form-letter':
8266 ;; --8<---------------cut here---------------start------------->8---
8267 ;; To: alice@invalid.invalid
8268 ;; Subject: Verification of your contact information
8269 ;; From: Contact verification <admin@foo.invalid>
8270 ;; --text follows this line--
8272 ;; please verify that your contact information is still valid:
8273 ;; Alice A, A avenue 11, 1111 A town, Austria
8274 ;; ----------next form letter message follows this line----------
8275 ;; To: bob@invalid.invalid
8276 ;; Subject: Verification of your contact information
8277 ;; From: Contact verification <admin@foo.invalid>
8278 ;; --text follows this line--
8280 ;; please verify that your contact information is still valid:
8281 ;; Bob, B street 22, 22222 Be town, Belgium
8282 ;; ----------next form letter message follows this line----------
8283 ;; To: charlie@invalid.invalid
8284 ;; Subject: Verification of your contact information
8285 ;; From: Contact verification <admin@foo.invalid>
8286 ;; --text follows this line--
8288 ;; please verify that your contact information is still valid:
8289 ;; Charlie Chaplin, C plaza 33, 33333 C town, Chile
8290 ;; --8<---------------cut here---------------end--------------->8---
8292 ;; FIXME: What is the most common term (circular letter, form letter, serial
8293 ;; letter, standard letter) for such kind of letter? See also
8294 ;; <http://en.wikipedia.org/wiki/Form_letter>
8296 ;; FIXME: Maybe extent message-mode's font-lock support to recognize
8297 ;; `message-form-letter-separator', i.e. highlight each message like a single
8300 (defcustom message-form-letter-separator
8301 "\n----------next form letter message follows this line----------\n"
8302 "Separator for `message-send-form-letter'."
8303 ;; :group 'message-form-letter
8304 :group 'message-various
8305 :version "23.1" ;; No Gnus
8308 (defcustom message-send-form-letter-delay 1
8309 "Delay in seconds when sending a message with `message-send-form-letter'.
8310 Only used when `message-send-form-letter' is called with non-nil
8312 ;; :group 'message-form-letter
8313 :group 'message-various
8314 :version "23.1" ;; No Gnus
8317 (defun message-send-form-letter (&optional force)
8318 "Sent all form letter messages from current buffer.
8319 Unless FORCE, prompt before sending.
8321 The messages are separated by `message-form-letter-separator'.
8322 Header and body are separated by `mail-header-separator'."
8324 (let ((sent 0) (skipped 0)
8328 (goto-char (point-min))
8331 end (if (search-forward message-form-letter-separator nil t)
8332 (- (point) (length message-form-letter-separator) -1)
8336 (buffer-substring-no-properties start end))
8337 (setq buff (generate-new-buffer "*mail - form letter*"))
8338 (with-current-buffer buff
8341 (setq to (message-fetch-field "To"))
8342 (switch-to-buffer buff)
8344 (sit-for message-send-form-letter-delay))
8346 (y-or-n-p (format-message "Send message to `%s'? " to)))
8348 (setq sent (1+ sent))
8349 (message-send-and-exit))
8350 (message "Message to `%s' skipped." to)
8351 (setq skipped (1+ skipped)))
8352 (when (buffer-live-p buff)
8353 (kill-buffer buff))))
8354 (message "%s message(s) sent, %s skipped." sent skipped)))
8356 (defun message-replace-header (header new-value &optional after force)
8357 "Remove HEADER and insert the NEW-VALUE.
8358 If AFTER, insert after this header. If FORCE, insert new field
8359 even if NEW-VALUE is empty."
8360 ;; Similar to `nnheader-replace-header' but for message buffers.
8363 (message-narrow-to-headers)
8364 (message-remove-header header))
8365 (when (or force (> (length new-value) 0))
8367 (message-position-on-field header after)
8368 (message-position-on-field header))
8369 (insert new-value))))
8371 (defcustom message-recipients-without-full-name
8372 (list "ding@gnus.org"
8374 "emacs-devel@gnu.org"
8375 "emacs-pretest-bug@gnu.org"
8376 "bug-gnu-emacs@gnu.org")
8377 "Mail addresses that have no full name.
8378 Used in `message-simplify-recipients'."
8379 ;; Maybe the addresses could be extracted from
8380 ;; `gnus-parameter-to-list-alist'?
8381 :type '(choice (const :tag "None" nil)
8383 :version "23.1" ;; No Gnus
8384 :group 'message-headers)
8386 (defun message-simplify-recipients ()
8388 (dolist (hdr '("Cc" "To"))
8389 (message-replace-header
8393 (if (and message-recipients-without-full-name
8395 (regexp-opt message-recipients-without-full-name)
8399 (message-make-from (car addrcomp) (cadr addrcomp))
8401 (when (message-fetch-field hdr)
8402 (mail-extract-address-components
8403 (message-fetch-field hdr) t))
8406 ;;; multipart/related and HTML support.
8408 (defun message-make-html-message-with-image-files (files)
8409 "Make a message containing the current dired-marked image files."
8410 (interactive (list (dired-get-marked-files nil current-prefix-arg)))
8413 (insert "<#part type=text/html>\n\n")
8414 (dolist (file files)
8415 (insert (format "<img src=%S>\n\n" file)))
8416 (message-toggle-image-thumbnails)
8419 (defun message-toggle-image-thumbnails ()
8420 "For any included image files, insert a thumbnail of that image."
8422 (let ((overlays (overlays-in (point-min) (point-max)))
8425 (let ((overlay (car overlays)))
8426 (when (overlay-get overlay 'put-image)
8427 (delete-overlay overlay)
8428 (setq displayed t)))
8429 (setq overlays (cdr overlays)))
8432 (goto-char (point-min))
8433 (while (re-search-forward "<img.*src=\"\\([^\"]+\\)" nil t)
8434 (let ((file (match-string 1))
8435 (edges (window-inside-pixel-edges
8436 (get-buffer-window (current-buffer)))))
8439 file 'imagemagick nil
8440 :max-width (truncate
8441 (* 0.7 (- (nth 2 edges) (nth 0 edges))))
8442 :max-height (truncate
8443 (* 0.5 (- (nth 3 edges) (nth 1 edges)))))
8449 (run-hooks 'message-load-hook)
8455 ;;; message.el ends here