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)
53 (autoload 'mailclient-send-it "mailclient")
55 (defvar gnus-message-group-art)
56 (defvar gnus-list-identifiers) ; gnus-sum is required where necessary
57 (defvar rmail-enable-mime-composing)
59 (defgroup message '((user-mail-address custom-variable)
60 (user-full-name custom-variable))
61 "Mail and news message composing."
62 :link '(custom-manual "(message)Top")
66 (put 'user-mail-address 'custom-type 'string)
67 (put 'user-full-name 'custom-type 'string)
69 (defgroup message-various nil
70 "Various Message Variables."
71 :link '(custom-manual "(message)Various Message Variables")
74 (defgroup message-buffers nil
76 :link '(custom-manual "(message)Message Buffers")
79 (defgroup message-sending nil
81 :link '(custom-manual "(message)Sending Variables")
84 (defgroup message-interface nil
86 :link '(custom-manual "(message)Interface")
89 (defgroup message-forwarding nil
91 :link '(custom-manual "(message)Forwarding")
92 :group 'message-interface)
94 (defgroup message-insertion nil
96 :link '(custom-manual "(message)Insertion")
99 (defgroup message-headers nil
101 :link '(custom-manual "(message)Message Headers")
104 (defgroup message-news nil
105 "Composing News Messages."
108 (defgroup message-mail nil
109 "Composing Mail Messages."
112 (defgroup message-faces nil
113 "Faces used for message composing."
117 (defcustom message-directory "~/Mail/"
118 "*Directory from which all other mail file variables are derived."
119 :group 'message-various
122 (defcustom message-max-buffers 10
123 "*How many buffers to keep before starting to kill them off."
124 :group 'message-buffers
127 (defcustom message-send-rename-function nil
128 "Function called to rename the buffer after sending it."
129 :group 'message-buffers
130 :type '(choice function (const nil)))
132 (defcustom message-fcc-handler-function 'message-output
133 "*A function called to save outgoing articles.
134 This function will be called with the name of the file to store the
135 article in. The default function is `message-output' which saves in Unix
137 :type '(radio (function-item message-output)
138 (function :tag "Other"))
139 :group 'message-sending)
141 (defcustom message-fcc-externalize-attachments nil
142 "If non-nil, attachments are included as external parts in Fcc copies."
145 :group 'message-sending)
147 (defcustom message-courtesy-message
148 "The following message is a courtesy copy of an article\nthat has been posted to %s as well.\n\n"
149 "*This is inserted at the start of a mailed copy of a posted message.
150 If the string contains the format spec \"%s\", the Newsgroups
151 the article has been posted to will be inserted there.
152 If this variable is nil, no such courtesy message will be added."
153 :group 'message-sending
154 :type '(radio string (const nil)))
156 (defcustom message-ignored-bounced-headers
157 "^\\(Received\\|Return-Path\\|Delivered-To\\):"
158 "*Regexp that matches headers to be removed in resent bounced mail."
159 :group 'message-interface
162 (defcustom message-from-style mail-from-style
163 "Specifies how \"From\" headers look.
165 If nil, they contain just the return address like:
167 If `parens', they look like:
168 king@grassland.com (Elvis Parsley)
169 If `angles', they look like:
170 Elvis Parsley <king@grassland.com>
172 Otherwise, most addresses look like `angles', but they look like
173 `parens' if `angles' would need quoting and `parens' would not."
175 :type '(choice (const :tag "simple" nil)
179 :group 'message-headers)
181 (defcustom message-insert-canlock t
182 "Whether to insert a Cancel-Lock header in news postings."
184 :group 'message-headers
187 (defcustom message-syntax-checks
188 (if message-insert-canlock '((sender . disabled)) nil)
189 ;; Guess this one shouldn't be easy to customize...
190 "*Controls what syntax checks should not be performed on outgoing posts.
191 To disable checking of long signatures, for instance, add
192 `(signature . disabled)' to this list.
194 Don't touch this variable unless you really know what you're doing.
196 Checks include `approved', `bogus-recipient', `continuation-headers',
197 `control-chars', `empty', `existing-newsgroups', `from', `illegible-text',
198 `invisible-text', `long-header-lines', `long-lines', `message-id',
199 `multiple-headers', `new-text', `newsgroups', `quoting-style',
200 `repeated-newsgroups', `reply-to', `sender', `sendsys', `shoot',
201 `shorten-followup-to', `signature', `size', `subject', `subject-cmsg'
202 and `valid-newsgroups'."
204 :type '(repeat sexp)) ; Fixme: improve this
206 (defcustom message-required-headers '((optional . References)
208 "*Headers to be generated or prompted for when sending a message.
209 Also see `message-required-news-headers' and
210 `message-required-mail-headers'."
213 :group 'message-headers
214 :link '(custom-manual "(message)Message Headers")
215 :type '(repeat sexp))
217 (defcustom message-draft-headers '(References From Date)
218 "*Headers to be generated when saving a draft message."
221 :group 'message-headers
222 :link '(custom-manual "(message)Message Headers")
223 :type '(repeat sexp))
225 (defcustom message-required-news-headers
226 '(From Newsgroups Subject Date Message-ID
227 (optional . Organization)
228 (optional . User-Agent))
229 "*Headers to be generated or prompted for when posting an article.
230 RFC977 and RFC1036 require From, Date, Newsgroups, Subject,
231 Message-ID. Organization, Lines, In-Reply-To, Expires, and
232 User-Agent are optional. If you don't want message to insert some
233 header, remove it from this list."
235 :group 'message-headers
236 :link '(custom-manual "(message)Message Headers")
237 :type '(repeat sexp))
239 (defcustom message-required-mail-headers
240 '(From Subject Date (optional . In-Reply-To) Message-ID
241 (optional . User-Agent))
242 "*Headers to be generated or prompted for when mailing a message.
243 It is recommended that From, Date, To, Subject and Message-ID be
244 included. Organization and User-Agent are optional."
246 :group 'message-headers
247 :link '(custom-manual "(message)Message Headers")
248 :type '(repeat sexp))
250 (defcustom message-prune-recipient-rules nil
251 "Rules for how to prune the list of recipients when doing wide replies.
252 This is a list of regexps and regexp matches."
255 :group 'message-headers
256 :link '(custom-manual "(message)Wide Reply")
257 :type '(repeat regexp))
259 (defcustom message-deletable-headers '(Message-ID Date Lines)
260 "Headers to delete if present and previously generated by message."
261 :group 'message-headers
262 :link '(custom-manual "(message)Message Headers")
263 :type '(repeat (symbol :tag "Header")))
265 (defcustom message-ignored-news-headers
266 "^NNTP-Posting-Host:\\|^Xref:\\|^[BGF]cc:\\|^Resent-Fcc:\\|^X-Draft-From:\\|^X-Gnus-Agent-Meta-Information:\\|^X-Message-SMTP-Method:\\|^X-Gnus-Delayed:"
267 "*Regexp of headers to be removed unconditionally before posting."
269 :group 'message-headers
270 :link '(custom-manual "(message)Message Headers")
271 :type '(repeat :value-to-internal (lambda (widget value)
272 (custom-split-regexp-maybe value))
273 :match (lambda (widget value)
275 (widget-editable-list-match widget value)))
278 (defcustom message-ignored-mail-headers
279 "^\\([GF]cc\\|Resent-Fcc\\|Xref\\|X-Draft-From\\|X-Gnus-Agent-Meta-Information\\):"
280 "*Regexp of headers to be removed unconditionally before mailing."
282 :group 'message-headers
283 :link '(custom-manual "(message)Mail Headers")
286 (defcustom message-ignored-supersedes-headers "^Path:\\|^Date\\|^NNTP-Posting-Host:\\|^Xref:\\|^Lines:\\|^Received:\\|^X-From-Line:\\|^X-Trace:\\|^X-ID:\\|^X-Complaints-To:\\|Return-Path:\\|^Supersedes:\\|^NNTP-Posting-Date:\\|^X-Trace:\\|^X-Complaints-To:\\|^Cancel-Lock:\\|^Cancel-Key:\\|^X-Hashcash:\\|^X-Payment:\\|^Approved:\\|^Injection-Date:\\|^Injection-Info:"
287 "*Header lines matching this regexp will be deleted before posting.
288 It's best to delete old Path and Date headers before posting to avoid
290 :group 'message-interface
291 :link '(custom-manual "(message)Superseding")
292 :type '(repeat :value-to-internal (lambda (widget value)
293 (custom-split-regexp-maybe value))
294 :match (lambda (widget value)
296 (widget-editable-list-match widget value)))
299 (defcustom message-subject-re-regexp
300 "^[ \t]*\\([Rr][Ee]\\(\\[[0-9]*\\]\\)* ?:[ \t]*\\)*[ \t]*"
301 "*Regexp matching \"Re: \" in the subject line."
302 :group 'message-various
303 :link '(custom-manual "(message)Message Headers")
306 ;;; Start of variables adopted from `message-utils.el'.
308 (defcustom message-subject-trailing-was-query t
309 "*What to do with trailing \"(was: <old subject>)\" in subject lines.
310 If nil, leave the subject unchanged. If it is the symbol `ask', query
311 the user what do do. In this case, the subject is matched against
312 `message-subject-trailing-was-ask-regexp'. If
313 `message-subject-trailing-was-query' is t, always strip the trailing
314 old subject. In this case, `message-subject-trailing-was-regexp' is
317 :type '(choice (const :tag "never" nil)
318 (const :tag "always strip" t)
320 :link '(custom-manual "(message)Message Headers")
321 :group 'message-various)
323 (defcustom message-subject-trailing-was-ask-regexp
324 "[ \t]*\\([[(]+[Ww][Aa][Ss]:?[ \t]*.*[])]+\\)"
325 "*Regexp matching \"(was: <old subject>)\" in the subject line.
327 The function `message-strip-subject-trailing-was' uses this regexp if
328 `message-subject-trailing-was-query' is set to the symbol `ask'. If
329 the variable is t instead of `ask', use
330 `message-subject-trailing-was-regexp' instead.
332 It is okay to create some false positives here, as the user is asked."
334 :group 'message-various
335 :link '(custom-manual "(message)Message Headers")
338 (defcustom message-subject-trailing-was-regexp
339 "[ \t]*\\((*[Ww][Aa][Ss]:[ \t]*.*)\\)"
340 "*Regexp matching \"(was: <old subject>)\" in the subject line.
342 If `message-subject-trailing-was-query' is set to t, the subject is
343 matched against `message-subject-trailing-was-regexp' in
344 `message-strip-subject-trailing-was'. You should use a regexp creating very
345 few false positives here."
347 :group 'message-various
348 :link '(custom-manual "(message)Message Headers")
351 ;;; marking inserted text
353 (defcustom message-mark-insert-begin
354 "--8<---------------cut here---------------start------------->8---\n"
355 "How to mark the beginning of some inserted text."
358 :link '(custom-manual "(message)Insertion Variables")
359 :group 'message-various)
361 (defcustom message-mark-insert-end
362 "--8<---------------cut here---------------end--------------->8---\n"
363 "How to mark the end of some inserted text."
366 :link '(custom-manual "(message)Insertion Variables")
367 :group 'message-various)
369 (defcustom message-archive-header "X-No-Archive: Yes\n"
370 "Header to insert when you don't want your article to be archived.
371 Archives \(such as groups.google.com) respect this header."
374 :link '(custom-manual "(message)Header Commands")
375 :group 'message-various)
377 (defcustom message-archive-note
378 "X-No-Archive: Yes - save http://groups.google.com/"
379 "Note to insert why you wouldn't want this posting archived.
380 If nil, don't insert any text in the body."
382 :type '(radio string (const nil))
383 :link '(custom-manual "(message)Header Commands")
384 :group 'message-various)
386 ;;; Crossposts and Followups
387 ;; inspired by JoH-followup-to by Jochem Huhman <joh at gmx.de>
388 ;; new suggestions by R. Weikusat <rw at another.de>
390 (defvar message-cross-post-old-target nil
391 "Old target for cross-posts or follow-ups.")
392 (make-variable-buffer-local 'message-cross-post-old-target)
394 (defcustom message-cross-post-default t
395 "When non-nil `message-cross-post-followup-to' will perform a crosspost.
396 If nil, `message-cross-post-followup-to' will only do a followup. Note that
397 you can explicitly override this setting by calling
398 `message-cross-post-followup-to' with a prefix."
401 :group 'message-various)
403 (defcustom message-cross-post-note "Crosspost & Followup-To: "
404 "Note to insert before signature to notify of cross-post and follow-up."
407 :group 'message-various)
409 (defcustom message-followup-to-note "Followup-To: "
410 "Note to insert before signature to notify of follow-up only."
413 :group 'message-various)
415 (defcustom message-cross-post-note-function 'message-cross-post-insert-note
416 "Function to use to insert note about Crosspost or Followup-To.
417 The function will be called with four arguments. The function should not only
418 insert a note, but also ensure old notes are deleted. See the documentation
419 for `message-cross-post-insert-note'."
422 :group 'message-various)
424 ;;; End of variables adopted from `message-utils.el'.
426 (defcustom message-signature-separator "^-- $"
427 "Regexp matching the signature separator.
428 This variable is used to strip off the signature from quoted text
429 when `message-cite-function' is
430 `message-cite-original-without-signature'. Most useful values
431 are \"^-- $\" (strict) and \"^-- *$\" (loose; allow missing
433 :type '(choice (const :tag "strict" "^-- $")
434 (const :tag "loose" "^-- *$")
436 :version "22.3" ;; Gnus 5.10.12 (changed default)
437 :link '(custom-manual "(message)Various Message Variables")
438 :group 'message-various)
440 (defcustom message-elide-ellipsis "\n[...]\n\n"
441 "*The string which is inserted for elided text.
442 This is a format-spec string, and you can use %l to say how many
443 lines were removed, and %c to say how many characters were
446 :link '(custom-manual "(message)Various Commands")
447 :group 'message-various)
449 (defcustom message-interactive mail-interactive
450 "Non-nil means when sending a message wait for and display errors.
451 A value of nil means let mailer mail back a message to report errors."
453 :group 'message-sending
455 :link '(custom-manual "(message)Sending Variables")
458 (defcustom message-confirm-send nil
459 "When non-nil, ask for confirmation when sending a message."
460 :group 'message-sending
462 :version "23.1" ;; No Gnus
463 :link '(custom-manual "(message)Sending Variables")
466 (defcustom message-generate-new-buffers 'unsent
467 "*Say whether to create a new message buffer to compose a message.
468 Valid values include:
471 Generate the buffer name in the Message way (e.g., *mail*, *news*,
472 *mail to whom*, *news on group*, etc.) and continue editing in the
473 existing buffer of that name. If there is no such buffer, it will
477 Create the new buffer with the name generated in the Message way.
480 Similar to `unique' but the buffer name begins with \"*unsent \".
483 Similar to nil but the buffer name is simpler like *mail message*.
486 If this is a function, call that function with three parameters:
487 The type, the To address and the group name (any of these may be nil).
488 The function should return the new buffer name."
490 :group 'message-buffers
491 :link '(custom-manual "(message)Message Buffers")
492 :type '(choice (const nil)
493 (sexp :tag "unique" :format "unique\n" :value unique
494 :match (lambda (widget value) (memq value '(unique t))))
497 (function :format "\n %{%t%}: %v")))
499 (defcustom message-kill-buffer-on-exit nil
500 "*Non-nil means that the message buffer will be killed after sending a message."
501 :group 'message-buffers
502 :link '(custom-manual "(message)Message Buffers")
505 (defcustom message-kill-buffer-query t
506 "*Non-nil means that killing a modified message buffer has to be confirmed.
507 This is used by `message-kill-buffer'."
508 :version "23.1" ;; No Gnus
509 :group 'message-buffers
512 (defcustom message-user-organization
513 (or (getenv "ORGANIZATION") t)
514 "String to be used as an Organization header.
515 If t, use `message-user-organization-file'."
516 :group 'message-headers
517 :type '(choice string
518 (const :tag "consult file" t)))
520 (defcustom message-user-organization-file
522 (dolist (f (list "/etc/organization"
523 "/etc/news/organization"
524 "/usr/lib/news/organization"))
525 (when (file-readable-p f)
528 "*Local news organization file."
529 :type '(choice (const nil) file)
530 :link '(custom-manual "(message)News Headers")
531 :group 'message-headers)
533 (defcustom message-make-forward-subject-function
534 #'message-forward-subject-name-subject
535 "*List of functions called to generate subject headers for forwarded messages.
536 The subject generated by the previous function is passed into each
539 The provided functions are:
541 * `message-forward-subject-author-subject' Source of article (author or
542 newsgroup), in brackets followed by the subject
543 * `message-forward-subject-name-subject' Source of article (name of author
544 or newsgroup), in brackets followed by the subject
545 * `message-forward-subject-fwd' Subject of article with `Fwd:' prepended
547 :group 'message-forwarding
548 :link '(custom-manual "(message)Forwarding")
549 :type '(radio (function-item message-forward-subject-author-subject)
550 (function-item message-forward-subject-fwd)
551 (function-item message-forward-subject-name-subject)
552 (repeat :tag "List of functions" function)))
554 (defcustom message-forward-as-mime t
555 "*Non-nil means forward messages as an inline/rfc822 MIME section.
556 Otherwise, directly inline the old message in the forwarded message."
558 :group 'message-forwarding
559 :link '(custom-manual "(message)Forwarding")
562 (defcustom message-forward-show-mml 'best
563 "*Non-nil means show forwarded messages as MML (decoded from MIME).
564 Otherwise, forwarded messages are unchanged.
565 Can also be the symbol `best' to indicate that MML should be
566 used, except when it is a bad idea to use MML. One example where
567 it is a bad idea is when forwarding a signed or encrypted
568 message, because converting MIME to MML would invalidate the
571 :group 'message-forwarding
572 :type '(choice (const :tag "use MML" t)
573 (const :tag "don't use MML " nil)
574 (const :tag "use MML when appropriate" best)))
576 (defcustom message-forward-before-signature t
577 "*Non-nil means put forwarded message before signature, else after."
578 :group 'message-forwarding
581 (defcustom message-wash-forwarded-subjects nil
582 "*Non-nil means try to remove as much cruft as possible from the subject.
583 Done before generating the new subject of a forward."
584 :group 'message-forwarding
585 :link '(custom-manual "(message)Forwarding")
588 (defcustom message-ignored-resent-headers
589 ;; `Delivered-To' needs to be removed because some mailers use it to
590 ;; detect loops, so if you resend a message to an address that ultimately
591 ;; comes back to you (e.g. a mailing-list to which you subscribe, in which
592 ;; case you may be removed from the list on the grounds that mail to you
593 ;; bounced with a "mailing loop" error).
594 "^Return-receipt\\|^X-Gnus\\|^Gnus-Warning:\\|^>?From \\|^Delivered-To:\
595 \\|^X-Content-Length:\\|^X-UIDL:"
596 "*All headers that match this regexp will be deleted when resending a message."
598 :group 'message-interface
599 :link '(custom-manual "(message)Resending")
600 :type '(repeat :value-to-internal (lambda (widget value)
601 (custom-split-regexp-maybe value))
602 :match (lambda (widget value)
604 (widget-editable-list-match widget value)))
607 (defcustom message-forward-ignored-headers "^Content-Transfer-Encoding:\\|^X-Gnus"
608 "*All headers that match this regexp will be deleted when forwarding a message.
609 This may also be a list of regexps."
611 :group 'message-forwarding
612 :type '(repeat :value-to-internal (lambda (widget value)
613 (custom-split-regexp-maybe value))
614 :match (lambda (widget value)
616 (widget-editable-list-match widget value)))
619 (defcustom message-forward-included-headers nil
620 "If non-nil, delete non-matching headers when forwarding a message.
621 Only headers that match this regexp will be included. This
622 variable should be a regexp or a list of regexps."
624 :group 'message-forwarding
625 :type '(repeat :value-to-internal (lambda (widget value)
626 (custom-split-regexp-maybe value))
627 :match (lambda (widget value)
629 (widget-editable-list-match widget value)))
632 (defcustom message-ignored-cited-headers "."
633 "*Delete these headers from the messages you yank."
634 :group 'message-insertion
635 :link '(custom-manual "(message)Insertion Variables")
638 (defcustom message-cite-prefix-regexp mail-citation-prefix-regexp
639 "*Regexp matching the longest possible citation prefix on a line."
641 :group 'message-insertion
642 :link '(custom-manual "(message)Insertion Variables")
644 :set (lambda (symbol value)
646 (custom-set-default symbol value)
647 (if (boundp 'gnus-message-cite-prefix-regexp)
648 (setq gnus-message-cite-prefix-regexp
649 (concat "^\\(?:" value "\\)"))))))
651 (defcustom message-cancel-message "I am canceling my own article.\n"
652 "Message to be inserted in the cancel message."
653 :group 'message-interface
654 :link '(custom-manual "(message)Canceling News")
657 (defun message-send-mail-function ()
658 "Return suitable value for the variable `message-send-mail-function'."
659 (cond ((and (require 'sendmail)
660 (boundp 'sendmail-program)
662 (executable-find sendmail-program))
663 'message-send-mail-with-sendmail)
664 ((and (locate-library "smtpmail")
665 (boundp 'smtpmail-default-smtp-server)
666 smtpmail-default-smtp-server)
667 'message-smtpmail-send-it)
668 ((locate-library "mailclient")
669 'message-send-mail-with-mailclient)
671 (error "Don't know how to send mail. Please customize `message-send-mail-function'"))))
673 (defun message-default-send-mail-function ()
674 (cond ((eq send-mail-function 'smtpmail-send-it) 'message-smtpmail-send-it)
675 ((eq send-mail-function 'feedmail-send-it) 'feedmail-send-it)
676 ((eq send-mail-function 'sendmail-query-once) 'sendmail-query-once)
677 ((eq send-mail-function 'mailclient-send-it)
678 'message-send-mail-with-mailclient)
679 (t (message-send-mail-function))))
681 ;; Useful to set in site-init.el
682 (defcustom message-send-mail-function (message-default-send-mail-function)
683 "Function to call to send the current buffer as mail.
684 The headers should be delimited by a line whose contents match the
685 variable `mail-header-separator'.
687 Valid values include `message-send-mail-with-sendmail'
688 `message-send-mail-with-mh', `message-send-mail-with-qmail',
689 `message-smtpmail-send-it', `smtpmail-send-it',
690 `feedmail-send-it' and `message-send-mail-with-mailclient'. The
691 default is system dependent and determined by the function
692 `message-send-mail-function'.
694 See also `send-mail-function'."
695 :type '(radio (function-item message-send-mail-with-sendmail)
696 (function-item message-send-mail-with-mh)
697 (function-item message-send-mail-with-qmail)
698 (function-item message-smtpmail-send-it)
699 (function-item smtpmail-send-it)
700 (function-item feedmail-send-it)
701 (function-item message-send-mail-with-mailclient
702 :tag "Use Mailclient package")
703 (function :tag "Other"))
704 :group 'message-sending
706 :initialize 'custom-initialize-default
707 :link '(custom-manual "(message)Mail Variables")
708 :group 'message-mail)
710 (defcustom message-send-news-function 'message-send-news
711 "Function to call to send the current buffer as news.
712 The headers should be delimited by a line whose contents match the
713 variable `mail-header-separator'."
714 :group 'message-sending
716 :link '(custom-manual "(message)News Variables")
719 (defcustom message-reply-to-function nil
720 "If non-nil, function that should return a list of headers.
721 This function should pick out addresses from the To, Cc, and From headers
722 and respond with new To and Cc headers."
723 :group 'message-interface
724 :link '(custom-manual "(message)Reply")
725 :type '(choice function (const nil)))
727 (defcustom message-wide-reply-to-function nil
728 "If non-nil, function that should return a list of headers.
729 This function should pick out addresses from the To, Cc, and From headers
730 and respond with new To and Cc headers."
731 :group 'message-interface
732 :link '(custom-manual "(message)Wide Reply")
733 :type '(choice function (const nil)))
735 (defcustom message-followup-to-function nil
736 "If non-nil, function that should return a list of headers.
737 This function should pick out addresses from the To, Cc, and From headers
738 and respond with new To and Cc headers."
739 :group 'message-interface
740 :link '(custom-manual "(message)Followup")
741 :type '(choice function (const nil)))
743 (defcustom message-extra-wide-headers nil
744 "If non-nil, a list of additional address headers.
745 These are used when composing a wide reply."
746 :group 'message-sending
747 :type '(repeat string))
749 (defcustom message-use-followup-to 'ask
750 "*Specifies what to do with Followup-To header.
751 If nil, always ignore the header. If it is t, use its value, but
752 query before using the \"poster\" value. If it is the symbol `ask',
753 always query the user whether to use the value. If it is the symbol
754 `use', always use the value."
755 :group 'message-interface
756 :link '(custom-manual "(message)Followup")
757 :type '(choice (const :tag "ignore" nil)
758 (const :tag "use & query" t)
762 (defcustom message-use-mail-followup-to 'use
763 "*Specifies what to do with Mail-Followup-To header.
764 If nil, always ignore the header. If it is the symbol `ask', always
765 query the user whether to use the value. If it is the symbol `use',
766 always use the value."
768 :group 'message-interface
769 :link '(custom-manual "(message)Mailing Lists")
770 :type '(choice (const :tag "ignore" nil)
774 (defcustom message-subscribed-address-functions nil
775 "*Specifies functions for determining list subscription.
776 If nil, do not attempt to determine list subscription with functions.
777 If non-nil, this variable contains a list of functions which return
778 regular expressions to match lists. These functions can be used in
779 conjunction with `message-subscribed-regexps' and
780 `message-subscribed-addresses'."
782 :group 'message-interface
783 :link '(custom-manual "(message)Mailing Lists")
784 :type '(repeat sexp))
786 (defcustom message-subscribed-address-file nil
787 "*A file containing addresses the user is subscribed to.
788 If nil, do not look at any files to determine list subscriptions. If
789 non-nil, each line of this file should be a mailing list address."
791 :group 'message-interface
792 :link '(custom-manual "(message)Mailing Lists")
793 :type '(radio file (const nil)))
795 (defcustom message-subscribed-addresses nil
796 "*Specifies a list of addresses the user is subscribed to.
797 If nil, do not use any predefined list subscriptions. This list of
798 addresses can be used in conjunction with
799 `message-subscribed-address-functions' and `message-subscribed-regexps'."
801 :group 'message-interface
802 :link '(custom-manual "(message)Mailing Lists")
803 :type '(repeat string))
805 (defcustom message-subscribed-regexps nil
806 "*Specifies a list of addresses the user is subscribed to.
807 If nil, do not use any predefined list subscriptions. This list of
808 regular expressions can be used in conjunction with
809 `message-subscribed-address-functions' and `message-subscribed-addresses'."
811 :group 'message-interface
812 :link '(custom-manual "(message)Mailing Lists")
813 :type '(repeat regexp))
815 (defcustom message-allow-no-recipients 'ask
816 "Specifies what to do when there are no recipients other than Gcc/Fcc.
817 If it is the symbol `always', the posting is allowed. If it is the
818 symbol `never', the posting is not allowed. If it is the symbol
819 `ask', you are prompted."
821 :group 'message-interface
822 :link '(custom-manual "(message)Message Headers")
823 :type '(choice (const always)
827 (defcustom message-sendmail-f-is-evil nil
828 "*Non-nil means don't add \"-f username\" to the sendmail command line.
829 Doing so would be even more evil than leaving it out."
830 :group 'message-sending
831 :link '(custom-manual "(message)Mail Variables")
834 (defcustom message-sendmail-envelope-from
835 ;; `mail-envelope-from' is unavailable unless sendmail.el is loaded.
836 (if (boundp 'mail-envelope-from) mail-envelope-from)
837 "*Envelope-from when sending mail with sendmail.
838 If this is nil, use `user-mail-address'. If it is the symbol
839 `header', use the From: header of the message."
841 :type '(choice (string :tag "From name")
842 (const :tag "Use From: header from message" header)
843 (const :tag "Use `user-mail-address'" nil))
844 :link '(custom-manual "(message)Mail Variables")
845 :group 'message-sending)
847 (defcustom message-sendmail-extra-arguments nil
848 "Additional arguments to `sendmail-program'."
849 ;; E.g. '("-a" "account") for msmtp
850 :version "23.1" ;; No Gnus
851 :type '(repeat string)
852 ;; :link '(custom-manual "(message)Mail Variables")
853 :group 'message-sending)
855 ;; qmail-related stuff
856 (defcustom message-qmail-inject-program "/var/qmail/bin/qmail-inject"
857 "Location of the qmail-inject program."
858 :group 'message-sending
859 :link '(custom-manual "(message)Mail Variables")
862 (defcustom message-qmail-inject-args nil
863 "Arguments passed to qmail-inject programs.
864 This should be a list of strings, one string for each argument.
865 It may also be a function.
867 For e.g., if you wish to set the envelope sender address so that bounces
868 go to the right place or to deal with listserv's usage of that address, you
869 might set this variable to (\"-f\" \"you@some.where\")."
870 :group 'message-sending
871 :link '(custom-manual "(message)Mail Variables")
872 :type '(choice (function)
875 (defvar gnus-post-method)
876 (defvar gnus-select-method)
877 (defcustom message-post-method
878 (cond ((and (boundp 'gnus-post-method)
879 (listp gnus-post-method)
882 ((boundp 'gnus-select-method)
885 "*Method used to post news.
886 Note that when posting from inside Gnus, for instance, this
887 variable isn't used."
889 :group 'message-sending
890 ;; This should be the `gnus-select-method' widget, but that might
891 ;; create a dependence to `gnus.el'.
894 (defcustom message-generate-headers-first nil
895 "Which headers should be generated before starting to compose a message.
896 If t, generate all required headers. This can also be a list of headers to
897 generate. The variables `message-required-news-headers' and
898 `message-required-mail-headers' specify which headers to generate.
900 Note that the variable `message-deletable-headers' specifies headers which
901 are to be deleted and then re-generated before sending, so this variable
902 will not have a visible effect for those headers."
903 :group 'message-headers
904 :link '(custom-manual "(message)Message Headers")
905 :type '(choice (const :tag "None" nil)
907 (repeat (sexp :tag "Header"))))
909 (defcustom message-fill-column 72
910 "Column beyond which automatic line-wrapping should happen.
911 Local value for message buffers. If non-nil, also turn on
912 auto-fill in message buffers."
913 :group 'message-various
914 ;; :link '(custom-manual "(message)Message Headers")
915 :type '(choice (const :tag "Don't turn on auto fill" nil)
918 (defcustom message-setup-hook nil
919 "Normal hook, run each time a new outgoing message is initialized.
920 The function `message-setup' runs this hook."
921 :group 'message-various
922 :link '(custom-manual "(message)Various Message Variables")
925 (defcustom message-cancel-hook nil
926 "Hook run when canceling articles."
927 :group 'message-various
928 :link '(custom-manual "(message)Various Message Variables")
931 (defcustom message-signature-setup-hook nil
932 "Normal hook, run each time a new outgoing message is initialized.
933 It is run after the headers have been inserted and before
934 the signature is inserted."
935 :group 'message-various
936 :link '(custom-manual "(message)Various Message Variables")
939 (defcustom message-mode-hook nil
940 "Hook run in message mode buffers."
941 :group 'message-various
944 (defcustom message-header-hook nil
945 "Hook run in a message mode buffer narrowed to the headers."
946 :group 'message-various
949 (defcustom message-header-setup-hook nil
950 "Hook called narrowed to the headers when setting up a message buffer."
951 :group 'message-various
952 :link '(custom-manual "(message)Various Message Variables")
955 (defcustom message-minibuffer-local-map
956 (let ((map (make-sparse-keymap 'message-minibuffer-local-map)))
957 (set-keymap-parent map minibuffer-local-map)
959 "Keymap for `message-read-from-minibuffer'."
960 ;; FIXME improve type.
961 :type '(restricted-sexp :match-alternatives (symbolp keymapp))
963 :group 'message-various)
965 (defcustom message-citation-line-function 'message-insert-citation-line
966 "*Function called to insert the \"Whomever writes:\" line.
968 Predefined functions include `message-insert-citation-line' and
969 `message-insert-formatted-citation-line' (see the variable
970 `message-citation-line-format').
972 Note that Gnus provides a feature where the reader can click on
973 `writes:' to hide the cited text. If you change this line too much,
974 people who read your message will have to change their Gnus
975 configuration. See the variable `gnus-cite-attribution-suffix'."
977 (function-item :tag "plain" message-insert-citation-line)
978 (function-item :tag "formatted" message-insert-formatted-citation-line)
979 (function :tag "Other"))
980 :link '(custom-manual "(message)Insertion Variables")
981 :group 'message-insertion)
983 (defcustom message-citation-line-format "On %a, %b %d %Y, %N wrote:\n"
984 "Format of the \"Whomever writes:\" line.
986 The string is formatted using `format-spec'. The following constructs
989 %f The full From, e.g. \"John Doe <john.doe@example.invalid>\".
990 %n The mail address, e.g. \"john.doe@example.invalid\".
991 %N The real name if present, e.g.: \"John Doe\", else fall
992 back to the mail address.
993 %F The first name if present, e.g.: \"John\", else fall
994 back to the mail address.
995 %L The last name if present, e.g.: \"Doe\".
996 %Z, %z The time zone in the numeric form, e.g.:\"+0000\".
998 All other format specifiers are passed to `format-time-string'
999 which is called using the date from the article your replying to, but
1000 the date in the formatted string will be expressed in the author's
1001 time zone as much as possible.
1002 Extracting the first (%F) and last name (%L) is done heuristically,
1003 so you should always check it yourself.
1005 Please also read the note in the documentation of
1006 `message-citation-line-function'."
1007 :type '(choice (const :tag "Plain" "%f writes:")
1008 (const :tag "Include date" "On %a, %b %d %Y, %n wrote:")
1010 :link '(custom-manual "(message)Insertion Variables")
1011 :version "23.1" ;; No Gnus
1012 :group 'message-insertion)
1014 (defcustom message-yank-prefix mail-yank-prefix
1015 "*Prefix inserted on the lines of yanked messages.
1016 Fix `message-cite-prefix-regexp' if it is set to an abnormal value.
1017 See also `message-yank-cited-prefix' and `message-yank-empty-prefix'."
1020 :link '(custom-manual "(message)Insertion Variables")
1021 :group 'message-insertion)
1023 (defcustom message-yank-cited-prefix ">"
1024 "*Prefix inserted on cited lines of yanked messages.
1025 Fix `message-cite-prefix-regexp' if it is set to an abnormal value.
1026 See also `message-yank-prefix' and `message-yank-empty-prefix'."
1029 :link '(custom-manual "(message)Insertion Variables")
1030 :group 'message-insertion)
1032 (defcustom message-yank-empty-prefix ">"
1033 "*Prefix inserted on empty lines of yanked messages.
1034 See also `message-yank-prefix' and `message-yank-cited-prefix'."
1037 :link '(custom-manual "(message)Insertion Variables")
1038 :group 'message-insertion)
1040 (defcustom message-indentation-spaces mail-indentation-spaces
1041 "*Number of spaces to insert at the beginning of each cited line.
1042 Used by `message-yank-original' via `message-yank-cite'."
1044 :group 'message-insertion
1045 :link '(custom-manual "(message)Insertion Variables")
1048 (defcustom message-cite-function 'message-cite-original-without-signature
1049 "*Function for citing an original message.
1050 Predefined functions include `message-cite-original' and
1051 `message-cite-original-without-signature'.
1052 Note that these functions use `mail-citation-hook' if that is non-nil."
1053 :type '(radio (function-item message-cite-original)
1054 (function-item message-cite-original-without-signature)
1055 (function-item sc-cite-original)
1056 (function :tag "Other"))
1057 :link '(custom-manual "(message)Insertion Variables")
1058 :version "22.3" ;; Gnus 5.10.12 (changed default)
1059 :group 'message-insertion)
1061 (defcustom message-indent-citation-function 'message-indent-citation
1062 "*Function for modifying a citation just inserted in the mail buffer.
1063 This can also be a list of functions. Each function can find the
1064 citation between (point) and (mark t). And each function should leave
1065 point and mark around the citation text as modified."
1067 :link '(custom-manual "(message)Insertion Variables")
1068 :group 'message-insertion)
1070 (defcustom message-signature mail-signature
1071 "*String to be inserted at the end of the message buffer.
1072 If t, the `message-signature-file' file will be inserted instead.
1073 If a function, the result from the function will be used instead.
1074 If a form, the result from the form will be used instead."
1076 :type '(choice string (const :tag "Contents of signature file" t)
1080 :link '(custom-manual "(message)Insertion Variables")
1081 :group 'message-insertion)
1083 (defcustom message-signature-file mail-signature-file
1084 "*Name of file containing the text inserted at end of message buffer.
1085 Ignored if the named file doesn't exist.
1086 If nil, don't insert a signature.
1087 If a path is specified, the value of `message-signature-directory' is ignored,
1090 :type '(choice file (const :tags "None" nil))
1091 :link '(custom-manual "(message)Insertion Variables")
1092 :group 'message-insertion)
1094 (defcustom message-signature-directory nil
1095 "*Name of directory containing signature files.
1096 Comes in handy if you have many such files, handled via posting styles for
1098 If nil, `message-signature-file' is expected to specify the directory if
1100 :type '(choice string (const :tags "None" nil))
1101 :link '(custom-manual "(message)Insertion Variables")
1102 :group 'message-insertion)
1104 (defcustom message-signature-insert-empty-line t
1105 "*If non-nil, insert an empty line before the signature separator."
1108 :link '(custom-manual "(message)Insertion Variables")
1109 :group 'message-insertion)
1111 (defcustom message-cite-reply-position 'traditional
1112 "*Where the reply should be positioned.
1113 If `traditional', reply inline.
1114 If `above', reply above quoted text.
1115 If `below', reply below quoted text.
1117 Note: Many newsgroups frown upon nontraditional reply styles. You
1118 probably want to set this variable only for specific groups,
1119 e.g. using `gnus-posting-styles':
1121 (eval (set (make-local-variable \\='message-cite-reply-position) \\='above))"
1123 :type '(choice (const :tag "Reply inline" traditional)
1124 (const :tag "Reply above" above)
1125 (const :tag "Reply below" below))
1126 :group 'message-insertion)
1128 (defcustom message-cite-style nil
1129 "*The overall style to be used when yanking cited text.
1130 Value is either nil (no variable overrides) or a let-style list
1131 of pairs (VARIABLE VALUE) that will be bound in
1132 `message-yank-original' to do the quoting.
1134 Presets to impersonate popular mail agents are found in the
1135 message-cite-style-* variables. This variable is intended for
1136 use in `gnus-posting-styles', such as:
1138 ((posting-from-work-p) (eval (set (make-local-variable \\='message-cite-style) message-cite-style-outlook)))"
1140 :group 'message-insertion
1141 :type '(choice (const :tag "Do not override variables" :value nil)
1142 (const :tag "MS Outlook" :value message-cite-style-outlook)
1143 (const :tag "Mozilla Thunderbird" :value message-cite-style-thunderbird)
1144 (const :tag "Gmail" :value message-cite-style-gmail)
1145 (variable :tag "User-specified")))
1147 (defconst message-cite-style-outlook
1148 '((message-cite-function 'message-cite-original)
1149 (message-citation-line-function 'message-insert-formatted-citation-line)
1150 (message-cite-reply-position 'above)
1151 (message-yank-prefix "")
1152 (message-yank-cited-prefix "")
1153 (message-yank-empty-prefix "")
1154 (message-citation-line-format "\n\n-----------------------\nOn %a, %b %d %Y, %N wrote:\n"))
1155 "Message citation style used by MS Outlook. Use with message-cite-style.")
1157 (defconst message-cite-style-thunderbird
1158 '((message-cite-function 'message-cite-original)
1159 (message-citation-line-function 'message-insert-formatted-citation-line)
1160 (message-cite-reply-position 'above)
1161 (message-yank-prefix "> ")
1162 (message-yank-cited-prefix ">")
1163 (message-yank-empty-prefix ">")
1164 (message-citation-line-format "On %D %R %p, %N wrote:"))
1165 "Message citation style used by Mozilla Thunderbird. Use with message-cite-style.")
1167 (defconst message-cite-style-gmail
1168 '((message-cite-function 'message-cite-original)
1169 (message-citation-line-function 'message-insert-formatted-citation-line)
1170 (message-cite-reply-position 'above)
1171 (message-yank-prefix " ")
1172 (message-yank-cited-prefix " ")
1173 (message-yank-empty-prefix " ")
1174 (message-citation-line-format "On %e %B %Y %R, %f wrote:\n"))
1175 "Message citation style used by Gmail. Use with message-cite-style.")
1177 (defcustom message-distribution-function nil
1178 "*Function called to return a Distribution header."
1179 :group 'message-news
1180 :group 'message-headers
1181 :link '(custom-manual "(message)News Headers")
1182 :type '(choice function (const nil)))
1184 (defcustom message-expires 14
1185 "Number of days before your article expires."
1186 :group 'message-news
1187 :group 'message-headers
1188 :link '(custom-manual "(message)News Headers")
1191 (defcustom message-user-path nil
1192 "If nil, use the NNTP server name in the Path header.
1193 If stringp, use this; if non-nil, use no host name (user name only)."
1194 :group 'message-news
1195 :group 'message-headers
1196 :link '(custom-manual "(message)News Headers")
1197 :type '(choice (const :tag "nntp" nil)
1198 (string :tag "name")
1199 (sexp :tag "none" :format "%t" t)))
1201 ;; This can be the name of a buffer, or a cons cell (FUNCTION . ARGS)
1202 ;; for yanking the original buffer.
1203 (defvar message-reply-buffer nil)
1204 (defvar message-reply-headers nil
1205 "The headers of the current replied article.
1206 It is a vector of the following headers:
1207 [number subject from date id references chars lines xref extra].")
1208 (defvar message-newsreader nil)
1209 (defvar message-mailer nil)
1210 (defvar message-sent-message-via nil)
1211 (defvar message-checksum nil)
1212 (defvar message-send-actions nil
1213 "A list of actions to be performed upon successful sending of a message.")
1214 (defvar message-return-action nil
1215 "Action to return to the caller after sending or postponing a message.")
1216 (defvar message-exit-actions nil
1217 "A list of actions to be performed upon exiting after sending a message.")
1218 (defvar message-kill-actions nil
1219 "A list of actions to be performed before killing a message buffer.")
1220 (defvar message-postpone-actions nil
1221 "A list of actions to be performed after postponing a message.")
1223 (define-widget 'message-header-lines 'text
1224 "All header lines must be LFD terminated."
1225 :format "%{%t%}:%n%v"
1226 :valid-regexp "^\\'"
1227 :error "All header lines must be newline terminated")
1229 (defcustom message-default-headers ""
1230 "Header lines to be inserted in outgoing messages.
1231 This can be set to a string containing or a function returning
1232 header lines to be inserted before you edit the message, so you
1233 can edit or delete these lines. If set to a function, it is
1234 called and its result is inserted."
1236 :group 'message-headers
1237 :link '(custom-manual "(message)Message Headers")
1239 (message-header-lines :tag "String")
1240 (function :tag "Function")))
1242 (defcustom message-default-mail-headers
1243 ;; Ease the transition from mail-mode to message-mode. See bugs#4431, 5555.
1244 (concat (if (and (boundp 'mail-default-reply-to)
1245 (stringp mail-default-reply-to))
1246 (format "Reply-to: %s\n" mail-default-reply-to))
1247 (if (and (boundp 'mail-self-blind)
1249 (format "BCC: %s\n" user-mail-address))
1250 (if (and (boundp 'mail-archive-file-name)
1251 (stringp mail-archive-file-name))
1252 (format "FCC: %s\n" mail-archive-file-name))
1253 mail-default-headers)
1254 "*A string of header lines to be inserted in outgoing mails."
1256 :group 'message-headers
1257 :group 'message-mail
1258 :link '(custom-manual "(message)Mail Headers")
1259 :type 'message-header-lines)
1261 (defcustom message-default-news-headers ""
1262 "*A string of header lines to be inserted in outgoing news articles."
1263 :group 'message-headers
1264 :group 'message-news
1265 :link '(custom-manual "(message)News Headers")
1266 :type 'message-header-lines)
1268 ;; Note: could use /usr/ucb/mail instead of sendmail;
1269 ;; options -t, and -v if not interactive.
1270 (defcustom message-mailer-swallows-blank-line
1271 (if (and (string-match "sparc-sun-sunos\\(\\'\\|[^5]\\)"
1272 system-configuration)
1273 (file-readable-p "/etc/sendmail.cf")
1275 (insert-file-contents "/etc/sendmail.cf")
1276 (goto-char (point-min))
1277 (let ((case-fold-search nil))
1278 (re-search-forward "^OR\\>" nil t))))
1279 ;; According to RFC822, "The field-name must be composed of printable
1280 ;; ASCII characters (i. e., characters that have decimal values between
1281 ;; 33 and 126, except colon)", i. e., any chars except ctl chars,
1283 '(looking-at "[ \t]\\|[][!\"#$%&'()*+,-./0-9;<=>?@A-Z\\\\^_`a-z{|}~]+:"))
1284 "*Set this non-nil if the system's mailer runs the header and body together.
1285 \(This problem exists on Sunos 4 when sendmail is run in remote mode.)
1286 The value should be an expression to test whether the problem will
1288 :group 'message-sending
1289 :link '(custom-manual "(message)Mail Variables")
1294 (define-mail-user-agent 'message-user-agent
1295 'message-mail 'message-send-and-exit
1296 'message-kill-buffer 'message-send-hook)
1298 (defvar message-mh-deletable-headers '(Message-ID Date Lines Sender)
1299 "If non-nil, delete the deletable headers before feeding to mh.")
1301 (defvar message-send-method-alist
1302 '((news message-news-p message-send-via-news)
1303 (mail message-mail-p message-send-via-mail))
1304 "Alist of ways to send outgoing messages.
1305 Each element has the form
1307 (TYPE PREDICATE FUNCTION)
1309 where TYPE is a symbol that names the method; PREDICATE is a function
1310 called without any parameters to determine whether the message is
1311 a message of type TYPE; and FUNCTION is a function to be called if
1312 PREDICATE returns non-nil. FUNCTION is called with one parameter --
1315 (defcustom message-mail-alias-type 'abbrev
1316 "*What alias expansion type to use in Message buffers.
1317 The default is `abbrev', which uses mailabbrev. `ecomplete' uses
1318 an electric completion mode. nil switches mail aliases off.
1319 This can also be a list of values."
1321 :link '(custom-manual "(message)Mail Aliases")
1322 :type '(choice (const :tag "Use Mailabbrev" abbrev)
1323 (const :tag "Use ecomplete" ecomplete)
1324 (const :tag "No expansion" nil)))
1326 (defcustom message-self-insert-commands '(self-insert-command)
1327 "List of `self-insert-command's used to trigger ecomplete.
1328 When one of those commands is invoked to enter a character in To or Cc
1329 header, ecomplete will suggest the candidates of recipients (see also
1330 `message-mail-alias-type'). If you use some tool to enter non-ASCII
1331 text and it replaces `self-insert-command' with the other command, e.g.
1332 `egg-self-insert-command', you may want to add it to this list."
1333 :group 'message-various
1334 :type '(repeat function))
1336 (defcustom message-auto-save-directory
1337 (if (file-writable-p message-directory)
1338 (file-name-as-directory (expand-file-name "drafts" message-directory))
1340 "*Directory where Message auto-saves buffers if Gnus isn't running.
1341 If nil, Message won't auto-save."
1342 :group 'message-buffers
1343 :link '(custom-manual "(message)Various Message Variables")
1344 :type '(choice directory (const :tag "Don't auto-save" nil)))
1346 (defcustom message-default-charset (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")
1353 (make-obsolete-variable
1354 'message-default-charset
1355 "The default charset comes from the language environment" "25.2")
1357 (defcustom message-dont-reply-to-names mail-dont-reply-to-names
1358 "Addresses to prune when doing wide replies.
1359 This can be a regexp, a list of regexps or a predicate function.
1360 Also, a value of nil means exclude your own user name only.
1362 If a function email is passed as the argument."
1365 :link '(custom-manual "(message)Wide Reply")
1366 :type '(choice (const :tag "Yourself" nil)
1368 (repeat :tag "Regexp List" regexp)))
1370 (defsubst message-dont-reply-to-names ()
1371 (if (functionp message-dont-reply-to-names)
1372 message-dont-reply-to-names
1373 (gmm-regexp-concat message-dont-reply-to-names)))
1375 (defvar message-shoot-gnksa-feet nil
1376 "*A list of GNKSA feet you are allowed to shoot.
1377 Gnus gives you all the opportunity you could possibly want for
1378 shooting yourself in the foot. Also, Gnus allows you to shoot the
1379 feet of Good Net-Keeping Seal of Approval. The following are foot
1381 `empty-article' Allow you to post an empty article;
1382 `quoted-text-only' Allow you to post quoted text only;
1383 `multiple-copies' Allow you to post multiple copies;
1384 `cancel-messages' Allow you to cancel or supersede messages from
1385 your other email addresses;
1386 `canlock-verify' Allow you to cancel messages without verifying canlock.")
1388 (defsubst message-gnksa-enable-p (feature)
1389 (or (not (listp message-shoot-gnksa-feet))
1390 (memq feature message-shoot-gnksa-feet)))
1392 (defcustom message-hidden-headers '("^References:" "^Face:" "^X-Face:"
1394 "Regexp of headers to be hidden when composing new messages.
1395 This can also be a list of regexps to match headers. Or a list
1396 starting with `not' and followed by regexps."
1399 :link '(custom-manual "(message)Message Headers")
1401 :format "%{%t%}: %[Value Type%] %v"
1402 (regexp :menu-tag "regexp" :format "regexp\n%t: %v")
1403 (repeat :menu-tag "(regexp ...)" :format "(regexp ...)\n%v%i"
1404 (regexp :format "%t: %v"))
1405 (cons :menu-tag "(not regexp ...)" :format "(not regexp ...)\n%v"
1407 (repeat :format "%v%i"
1408 (regexp :format "%t: %v")))))
1410 (defcustom message-cite-articles-with-x-no-archive t
1411 "If non-nil, cite text from articles that has X-No-Archive set."
1415 ;;; Internal variables.
1416 ;;; Well, not really internal.
1418 (defvar message-mode-syntax-table
1419 (let ((table (copy-syntax-table text-mode-syntax-table)))
1420 (modify-syntax-entry ?% ". " table)
1421 (modify-syntax-entry ?> ". " table)
1422 (modify-syntax-entry ?< ". " table)
1424 "Syntax table used while in Message mode.")
1426 (defface message-header-to
1429 (:foreground "DarkOliveGreen1" :bold t))
1432 (:foreground "MidnightBlue" :bold t))
1434 (:bold t :italic t)))
1435 "Face used for displaying From headers."
1436 :group 'message-faces)
1437 ;; backward-compatibility alias
1438 (put 'message-header-to-face 'face-alias 'message-header-to)
1439 (put 'message-header-to-face 'obsolete-face "22.1")
1441 (defface message-header-cc
1444 (:foreground "chartreuse1" :bold t))
1447 (:foreground "MidnightBlue"))
1450 "Face used for displaying Cc headers."
1451 :group 'message-faces)
1452 ;; backward-compatibility alias
1453 (put 'message-header-cc-face 'face-alias 'message-header-cc)
1454 (put 'message-header-cc-face 'obsolete-face "22.1")
1456 (defface message-header-subject
1459 (:foreground "OliveDrab1"))
1462 (:foreground "navy blue" :bold t))
1465 "Face used for displaying subject headers."
1466 :group 'message-faces)
1467 ;; backward-compatibility alias
1468 (put 'message-header-subject-face 'face-alias 'message-header-subject)
1469 (put 'message-header-subject-face 'obsolete-face "22.1")
1471 (defface message-header-newsgroups
1474 (:foreground "yellow" :bold t :italic t))
1477 (:foreground "blue4" :bold t :italic t))
1479 (:bold t :italic t)))
1480 "Face used for displaying newsgroups headers."
1481 :group 'message-faces)
1482 ;; backward-compatibility alias
1483 (put 'message-header-newsgroups-face 'face-alias 'message-header-newsgroups)
1484 (put 'message-header-newsgroups-face 'obsolete-face "22.1")
1486 (defface message-header-other
1489 (:foreground "VioletRed1"))
1492 (:foreground "steel blue"))
1494 (:bold t :italic t)))
1495 "Face used for displaying newsgroups headers."
1496 :group 'message-faces)
1497 ;; backward-compatibility alias
1498 (put 'message-header-other-face 'face-alias 'message-header-other)
1499 (put 'message-header-other-face 'obsolete-face "22.1")
1501 (defface message-header-name
1504 (:foreground "green"))
1507 (:foreground "cornflower blue"))
1510 "Face used for displaying header names."
1511 :group 'message-faces)
1512 ;; backward-compatibility alias
1513 (put 'message-header-name-face 'face-alias 'message-header-name)
1514 (put 'message-header-name-face 'obsolete-face "22.1")
1516 (defface message-header-xheader
1519 (:foreground "DeepSkyBlue1"))
1522 (:foreground "blue"))
1525 "Face used for displaying X-Header headers."
1526 :group 'message-faces)
1527 ;; backward-compatibility alias
1528 (put 'message-header-xheader-face 'face-alias 'message-header-xheader)
1529 (put 'message-header-xheader-face 'obsolete-face "22.1")
1531 (defface message-separator
1534 (:foreground "LightSkyBlue1"))
1537 (:foreground "brown"))
1540 "Face used for displaying the separator."
1541 :group 'message-faces)
1542 ;; backward-compatibility alias
1543 (put 'message-separator-face 'face-alias 'message-separator)
1544 (put 'message-separator-face 'obsolete-face "22.1")
1546 (defface message-cited-text
1549 (:foreground "LightPink1"))
1552 (:foreground "red"))
1555 "Face used for displaying cited text names."
1556 :group 'message-faces)
1557 ;; backward-compatibility alias
1558 (put 'message-cited-text-face 'face-alias 'message-cited-text)
1559 (put 'message-cited-text-face 'obsolete-face "22.1")
1561 (defface message-mml
1564 (:foreground "MediumSpringGreen"))
1567 (:foreground "ForestGreen"))
1570 "Face used for displaying MML."
1571 :group 'message-faces)
1572 ;; backward-compatibility alias
1573 (put 'message-mml-face 'face-alias 'message-mml)
1574 (put 'message-mml-face 'obsolete-face "22.1")
1576 (defun message-font-lock-make-header-matcher (regexp)
1579 (let ((start (point)))
1582 (goto-char (point-min))
1583 (if (re-search-forward
1584 (concat "^" (regexp-quote mail-header-separator) "$")
1586 (setq limit (min limit (match-beginning 0))))
1588 (and (< start limit)
1589 (re-search-forward ,regexp limit t))))))
1590 (if (featurep 'bytecomp)
1594 (defvar message-font-lock-keywords
1595 (let ((content "[ \t]*\\(.+\\(\n[ \t].*\\)*\\)\n?"))
1596 `((,(message-font-lock-make-header-matcher
1597 (concat "^\\([Tt]o:\\)" content))
1598 (1 'message-header-name)
1599 (2 'message-header-to nil t))
1600 (,(message-font-lock-make-header-matcher
1601 (concat "^\\(^[GBF]?[Cc][Cc]:\\|^[Rr]eply-[Tt]o:\\)" content))
1602 (1 'message-header-name)
1603 (2 'message-header-cc nil t))
1604 (,(message-font-lock-make-header-matcher
1605 (concat "^\\([Ss]ubject:\\)" content))
1606 (1 'message-header-name)
1607 (2 'message-header-subject nil t))
1608 (,(message-font-lock-make-header-matcher
1609 (concat "^\\([Nn]ewsgroups:\\|Followup-[Tt]o:\\)" content))
1610 (1 'message-header-name)
1611 (2 'message-header-newsgroups nil t))
1612 (,(message-font-lock-make-header-matcher
1613 (concat "^\\(X-[A-Za-z0-9-]+:\\|In-Reply-To:\\)" content))
1614 (1 'message-header-name)
1615 (2 'message-header-xheader))
1616 (,(message-font-lock-make-header-matcher
1617 (concat "^\\([A-Z][^: \n\t]+:\\)" content))
1618 (1 'message-header-name)
1619 (2 'message-header-other nil t))
1620 ,@(if (and mail-header-separator
1621 (not (equal mail-header-separator "")))
1622 `((,(concat "^\\(" (regexp-quote mail-header-separator) "\\)$")
1623 1 'message-separator))
1626 (re-search-forward (concat "^\\("
1627 message-cite-prefix-regexp
1630 (0 'message-cited-text))
1631 ("<#/?\\(multipart\\|part\\|external\\|mml\\|secure\\)[^>]*>"
1633 "Additional expressions to highlight in Message mode.")
1635 (defvar message-face-alist
1636 '((bold . message-bold-region)
1637 (underline . underline-region)
1638 (default . (lambda (b e)
1639 (message-unbold-region b e)
1640 (ununderline-region b e))))
1641 "Alist of mail and news faces for facemenu.
1642 The cdr of each entry is a function for applying the face to a region.")
1644 (defcustom message-send-hook nil
1645 "Hook run before sending messages.
1646 This hook is run quite early when sending."
1647 :group 'message-various
1648 :options '(ispell-message)
1649 :link '(custom-manual "(message)Various Message Variables")
1652 (defcustom message-send-mail-hook nil
1653 "Hook run before sending mail messages.
1654 This hook is run very late -- just before the message is sent as
1656 :group 'message-various
1657 :link '(custom-manual "(message)Various Message Variables")
1660 (defcustom message-send-news-hook nil
1661 "Hook run before sending news messages.
1662 This hook is run very late -- just before the message is sent as
1664 :group 'message-various
1665 :link '(custom-manual "(message)Various Message Variables")
1668 (defcustom message-sent-hook nil
1669 "Hook run after sending messages."
1670 :group 'message-various
1673 (defvar message-send-coding-system 'binary
1674 "Coding system to encode outgoing mail.")
1676 (defvar message-draft-coding-system mm-auto-save-coding-system
1677 "Coding system to compose mail.")
1679 (defcustom message-send-mail-partially-limit nil
1680 "The limitation of messages sent as message/partial.
1681 The lower bound of message size in characters, beyond which the message
1682 should be sent in several parts. If it is nil, the size is unlimited."
1684 :group 'message-buffers
1685 :link '(custom-manual "(message)Mail Variables")
1686 :type '(choice (const :tag "unlimited" nil)
1689 (defcustom message-alternative-emails nil
1690 "*Regexp or predicate function matching alternative email addresses.
1691 The first address in the To, Cc or From headers of the original
1692 article matching this variable is used as the From field of
1695 If a function, an email string is passed as the argument.
1697 This variable has precedence over posting styles and anything that runs
1698 off `message-setup-hook'."
1699 :group 'message-headers
1700 :link '(custom-manual "(message)Message Headers")
1701 :type '(choice (const :tag "Always use primary" nil)
1705 (defcustom message-hierarchical-addresses nil
1706 "A list of hierarchical mail address definitions.
1708 Inside each entry, the first address is the \"top\" address, and
1709 subsequent addresses are subaddresses; this is used to indicate that
1710 mail sent to the first address will automatically be delivered to the
1711 subaddresses. So if the first address appears in the recipient list
1712 for a message, the subaddresses will be removed (if present) before
1713 the mail is sent. All addresses in this structure should be
1716 :group 'message-headers
1717 :type '(repeat (repeat string)))
1719 (defcustom message-mail-user-agent nil
1720 "Like `mail-user-agent'.
1721 Except if it is nil, use Gnus native MUA; if it is t, use
1724 :type '(radio (const :tag "Gnus native"
1727 (const :tag "`mail-user-agent'"
1730 (function-item :tag "Default Emacs mail"
1732 sendmail-user-agent)
1733 (function-item :tag "Emacs interface to MH"
1736 (function :tag "Other"))
1740 (defcustom message-wide-reply-confirm-recipients nil
1741 "Whether to confirm a wide reply to multiple email recipients.
1742 If this variable is nil, don't ask whether to reply to all recipients.
1743 If this variable is non-nil, pose the question \"Reply to all
1744 recipients?\" before a wide reply to multiple recipients. If the user
1745 answers yes, reply to all recipients as usual. If the user answers
1746 no, only reply back to the author."
1748 :group 'message-headers
1749 :link '(custom-manual "(message)Wide Reply")
1752 (defcustom message-user-fqdn nil
1753 "*Domain part of Message-Ids."
1755 :group 'message-headers
1756 :link '(custom-manual "(message)News Headers")
1757 :type '(radio (const :format "%v " nil)
1758 (string :format "FQDN: %v")))
1760 (defcustom message-use-idna t
1761 "Whether to encode non-ASCII in domain names into ASCII according to IDNA."
1763 :group 'message-headers
1764 :link '(custom-manual "(message)IDNA")
1765 :type '(choice (const :tag "Ask" ask)
1766 (const :tag "Never" nil)
1767 (const :tag "Always" t)))
1769 (defcustom message-generate-hashcash (if (executable-find "hashcash") 'opportunistic)
1770 "*Whether to generate X-Hashcash: headers.
1771 If t, always generate hashcash headers. If `opportunistic',
1772 only generate hashcash headers if it can be done without the user
1773 waiting (i.e., only asynchronously).
1775 You must have the \"hashcash\" binary installed, see `hashcash-path'."
1777 :group 'message-headers
1778 :link '(custom-manual "(message)Mail Headers")
1779 :type '(choice (const :tag "Always" t)
1780 (const :tag "Never" nil)
1781 (const :tag "Opportunistic" opportunistic)))
1783 ;;; Internal variables.
1785 (defvar message-sending-message "Sending...")
1786 (defvar message-buffer-list nil)
1787 (defvar message-this-is-news nil)
1788 (defvar message-this-is-mail nil)
1789 (defvar message-draft-article nil)
1790 (defvar message-mime-part nil)
1791 (defvar message-posting-charset nil)
1792 (defvar message-inserted-headers nil)
1793 (defvar message-inhibit-ecomplete nil)
1795 ;; Byte-compiler warning
1796 (defvar gnus-active-hashtb)
1797 (defvar gnus-read-active-file)
1799 ;;; Regexp matching the delimiter of messages in UNIX mail format
1800 ;;; (UNIX From lines), minus the initial ^. It should be a copy
1801 ;;; of rmail.el's rmail-unix-mail-delimiter.
1802 (defvar message-unix-mail-delimiter
1803 (let ((time-zone-regexp
1804 (concat "\\([A-Z]?[A-Z]?[A-Z][A-Z]\\( DST\\)?"
1805 "\\|[-+]?[0-9][0-9][0-9][0-9]"
1811 ;; Many things can happen to an RFC 822 mailbox before it is put into
1812 ;; a `From' line. The leading phrase can be stripped, e.g.
1813 ;; `Joe <@w.x:joe@y.z>' -> `<@w.x:joe@y.z>'. The <> can be stripped, e.g.
1814 ;; `<@x.y:joe@y.z>' -> `@x.y:joe@y.z'. Everything starting with a CRLF
1815 ;; can be removed, e.g.
1816 ;; From: joe@y.z (Joe K
1818 ;; can yield `From joe@y.z (Joe K Fri Mar 22 08:11:15 1996', and
1821 ;; can yield `From Joe User Fri Mar 22 08:11:15 1996'.
1822 ;; The mailbox can be removed or be replaced by white space, e.g.
1823 ;; From: "Joe User"{space}{tab}
1825 ;; can yield `From {space}{tab} Fri Mar 22 08:11:15 1996',
1826 ;; where {space} and {tab} represent the Ascii space and tab characters.
1827 ;; We want to match the results of any of these manglings.
1828 ;; The following regexp rejects names whose first characters are
1829 ;; obviously bogus, but after that anything goes.
1830 "\\([^\0-\b\n-\r\^?].*\\)?"
1832 ;; The time the message was sent.
1833 "\\([^\0-\r \^?]+\\) +" ; day of the week
1834 "\\([^\0-\r \^?]+\\) +" ; month
1835 "\\([0-3]?[0-9]\\) +" ; day of month
1836 "\\([0-2][0-9]:[0-5][0-9]\\(:[0-6][0-9]\\)?\\) *" ; time of day
1838 ;; Perhaps a time zone, specified by an abbreviation, or by a
1843 " \\([0-9][0-9]+\\) *"
1845 ;; On some systems the time zone can appear after the year, too.
1849 "\\(remote from .*\\)?"
1852 "Regexp matching the delimiter of messages in UNIX mail format.")
1854 (defvar message-unsent-separator
1855 (concat "^ *---+ +Unsent message follows +---+ *$\\|"
1856 "^ *---+ +Returned message +---+ *$\\|"
1857 "^Start of returned message$\\|"
1858 "^ *---+ +Original message +---+ *$\\|"
1859 "^ *--+ +begin message +--+ *$\\|"
1860 "^ *---+ +Original message follows +---+ *$\\|"
1861 "^ *---+ +Undelivered message follows +---+ *$\\|"
1862 "^------ This is a copy of the message, including all the headers. ------ *$\\|"
1863 "^|? *---+ +Message text follows: +---+ *|?$")
1864 "A regexp that matches the separator before the text of a failed message.")
1866 (defvar message-field-fillers
1867 '((To message-fill-field-address)
1868 (Cc message-fill-field-address)
1869 (From message-fill-field-address))
1870 "Alist of header names/filler functions.")
1872 (defvar message-header-format-alist
1887 (References . message-shorten-references)
1889 "Alist used for formatting headers.")
1891 (defvar message-options nil
1892 "Some saved answers when sending message.")
1893 (make-variable-buffer-local 'message-options)
1895 (defvar message-send-mail-real-function nil
1896 "Internal send mail function.")
1898 (defvar message-bogus-system-names "\\`localhost\\.\\|\\.local\\'"
1899 "The regexp of bogus system names.")
1901 (autoload 'gnus-alive-p "gnus-util")
1902 (autoload 'gnus-delay-article "gnus-delay")
1903 (autoload 'gnus-extract-address-components "gnus-util")
1904 (autoload 'gnus-find-method-for-group "gnus")
1905 (autoload 'gnus-group-decoded-name "gnus-group")
1906 (autoload 'gnus-group-name-charset "gnus-group")
1907 (autoload 'gnus-group-name-decode "gnus-group")
1908 (autoload 'gnus-groups-from-server "gnus")
1909 (autoload 'gnus-open-server "gnus-int")
1910 (autoload 'gnus-output-to-mail "gnus-util")
1911 (autoload 'gnus-output-to-rmail "gnus-util")
1912 (autoload 'gnus-request-post "gnus-int")
1913 (autoload 'gnus-server-string "gnus")
1914 (autoload 'message-setup-toolbar "messagexmas")
1915 (autoload 'mh-new-draft-name "mh-comp")
1916 (autoload 'mh-send-letter "mh-comp")
1917 (autoload 'nndraft-request-associate-buffer "nndraft")
1918 (autoload 'nndraft-request-expire-articles "nndraft")
1919 (autoload 'nnvirtual-find-group-art "nnvirtual")
1920 (autoload 'rmail-msg-is-pruned "rmail")
1921 (autoload 'rmail-output "rmailout")
1923 (defun message-kill-all-overlays ()
1924 (mapcar #'delete-overlay (overlays-in (point-min) (point-max))))
1929 ;;; Utility functions.
1932 (defmacro message-y-or-n-p (question show &rest text)
1933 "Ask QUESTION, displaying remaining args in a temporary buffer if SHOW."
1934 `(message-talkative-question 'y-or-n-p ,question ,show ,@text))
1936 (defmacro message-delete-line (&optional n)
1937 "Delete the current line (and the next N lines)."
1938 `(delete-region (progn (beginning-of-line) (point))
1939 (progn (forward-line ,(or n 1)) (point))))
1941 (defun message-mark-active-p ()
1942 "Non-nil means the mark and region are currently active in this buffer."
1945 (defun message-unquote-tokens (elems)
1946 "Remove double quotes (\") from strings in list ELEMS."
1947 (mapcar (lambda (item)
1948 (while (string-match "^\\(.*\\)\"\\(.*\\)$" item)
1949 (setq item (concat (match-string 1 item)
1950 (match-string 2 item))))
1954 (defun message-tokenize-header (header &optional separator)
1955 "Split HEADER into a list of header elements.
1956 SEPARATOR is a string of characters to be used as separators. \",\"
1957 is used by default."
1960 (let ((regexp (format "[%s]+" (or separator ",")))
1962 beg quoted elems paren)
1964 (mm-enable-multibyte)
1965 (setq beg (point-min))
1967 (goto-char (point-min))
1972 (cond ((and (> (point) beg)
1974 (and (looking-at regexp)
1977 (push (buffer-substring beg (point)) elems)
1978 (setq beg (match-end 0)))
1979 ((eq (char-after) ?\")
1980 (setq quoted (not quoted)))
1981 ((and (eq (char-after) ?\()
1984 ((and (eq (char-after) ?\))
1987 (nreverse elems)))))
1989 (autoload 'nnheader-insert-file-contents "nnheader")
1991 (defun message-mail-file-mbox-p (file)
1992 "Say whether FILE looks like a Unix mbox file."
1993 (when (and (file-exists-p file)
1994 (file-readable-p file)
1995 (file-regular-p file))
1997 (nnheader-insert-file-contents file)
1998 (goto-char (point-min))
1999 (looking-at message-unix-mail-delimiter))))
2001 (defun message-fetch-field (header &optional not-all)
2002 "The same as `mail-fetch-field', only remove all newlines.
2003 The buffer is expected to be narrowed to just the header of the message;
2004 see `message-narrow-to-headers-or-head'."
2005 (let* ((inhibit-point-motion-hooks t)
2006 (value (mail-fetch-field header nil (not not-all))))
2008 (while (string-match "\n[\t ]+" value)
2009 (setq value (replace-match " " t t value)))
2012 (defun message-field-value (header &optional not-all)
2013 "The same as `message-fetch-field', only narrow to the headers first."
2016 (message-narrow-to-headers-or-head)
2017 (message-fetch-field header not-all))))
2019 (defun message-narrow-to-field ()
2020 "Narrow the buffer to the header on the current line."
2022 (while (looking-at "[ \t]")
2028 (if (re-search-forward "^[^ \n\t]" nil t)
2031 (goto-char (point-min)))
2033 (defun message-add-header (&rest headers)
2034 "Add the HEADERS to the message header, skipping those already present."
2037 (unless (string-match "^\\([^:]+\\):[ \t]*[^ \t]" (car headers))
2038 (error "Invalid header `%s'" (car headers)))
2039 (setq hclean (match-string 1 (car headers)))
2041 (message-narrow-to-headers)
2042 (unless (re-search-forward (concat "^" (regexp-quote hclean) ":") nil t)
2043 (goto-char (point-max))
2044 (if (string-match "\n$" (car headers))
2045 (insert (car headers))
2046 (insert (car headers) ?\n)))))
2047 (setq headers (cdr headers))))
2049 (defmacro message-with-reply-buffer (&rest forms)
2050 "Evaluate FORMS in the reply buffer, if it exists."
2051 `(when (and (bufferp message-reply-buffer)
2052 (buffer-name message-reply-buffer))
2053 (with-current-buffer message-reply-buffer
2056 (put 'message-with-reply-buffer 'lisp-indent-function 0)
2057 (put 'message-with-reply-buffer 'edebug-form-spec '(body))
2059 (defun message-fetch-reply-field (header)
2060 "Fetch field HEADER from the message we're replying to."
2061 (message-with-reply-buffer
2063 (mail-narrow-to-head)
2064 (message-fetch-field header))))
2066 (defun message-strip-list-identifiers (subject)
2067 "Remove list identifiers in `gnus-list-identifiers' from string SUBJECT."
2068 (require 'gnus-sum) ; for gnus-list-identifiers
2069 (let ((regexp (if (stringp gnus-list-identifiers)
2070 gnus-list-identifiers
2071 (mapconcat 'identity gnus-list-identifiers " *\\|"))))
2072 (if (string-match (concat "\\(\\(\\(Re: +\\)?\\(" regexp
2073 " *\\)\\)+\\(Re: +\\)?\\)") subject)
2074 (concat (substring subject 0 (match-beginning 1))
2075 (or (match-string 3 subject)
2076 (match-string 5 subject))
2081 (defun message-strip-subject-re (subject)
2082 "Remove \"Re:\" from subject lines in string SUBJECT."
2083 (if (string-match message-subject-re-regexp subject)
2084 (substring subject (match-end 0))
2087 (defcustom message-replacement-char "."
2088 "Replacement character used instead of unprintable or not decodable chars."
2089 :group 'message-various
2090 :version "22.1" ;; Gnus 5.10.9
2091 :type '(choice string
2095 ;; FIXME: We also should call `message-strip-subject-encoded-words'
2096 ;; when forwarding. Probably in `message-make-forward-subject' and
2097 ;; `message-forward-make-body'.
2099 (defun message-strip-subject-encoded-words (subject)
2100 "Fix non-decodable words in SUBJECT."
2101 ;; Cf. `gnus-simplify-subject-fully'.
2102 (let* ((case-fold-search t)
2103 (replacement-chars (format "[%s%s%s]"
2104 message-replacement-char
2105 message-replacement-char
2106 message-replacement-char))
2107 (enc-word-re "=\\?\\([^?]+\\)\\?\\([QB]\\)\\?\\([^?]+\\)\\(\\?=\\)")
2112 (goto-char (point-min))
2113 (when (re-search-forward enc-word-re nil t)
2114 (setq cs-string (match-string 1)))))
2115 cs-coding q-or-b word-beg word-end)
2116 (if (or (not have-marker) ;; No encoded word found...
2117 ;; ... or double encoding was correct:
2118 (and (stringp cs-string)
2119 (setq cs-string (downcase cs-string))
2120 (mm-coding-system-p (intern cs-string))
2124 Decoded Subject \"%s\"
2125 contains a valid encoded word. Decode again? "
2127 (setq cs-coding (intern cs-string))))))
2131 (goto-char (point-min))
2132 (while (re-search-forward enc-word-re nil t)
2133 (setq cs-string (downcase (match-string 1))
2134 q-or-b (match-string 2)
2135 word-beg (match-beginning 0)
2136 word-end (match-end 0))
2138 (if (mm-coding-system-p (intern cs-string))
2139 (setq cs-coding (intern cs-string))
2141 ;; No double encoded subject? => bogus charset.
2146 Decoded Subject \"%s\"
2147 contains an encoded word. The charset `%s' is unknown or invalid.
2148 Hit RET to replace non-decodable characters with \"%s\" or enter replacement
2150 subject cs-string message-replacement-char)))
2152 (replace-match (concat "=?" (symbol-name cs-coding)
2155 (goto-char word-beg)
2156 (re-search-forward "=\\?\\([^?]+\\)\\?\\([QB]\\)\\?" word-end t)
2159 (if (string-match "\\`Q\\'" q-or-b)
2162 (message "Replacing non-decodable characters with \"%s\"."
2163 message-replacement-char)
2164 (while (re-search-forward "\\(=[A-F0-9][A-F0-9]\\)+"
2166 (replace-match message-replacement-char)))
2168 (message "Replacing non-decodable characters with \"%s\"."
2170 (re-search-forward "[^?]+" word-end t)
2171 (replace-match replacement-chars))
2172 (re-search-forward "\\?=")
2173 (replace-match "")))))
2174 (rfc2047-decode-region (point-min) (point-max))
2177 ;;; Start of functions adopted from `message-utils.el'.
2179 (defun message-strip-subject-trailing-was (subject)
2180 "Remove trailing \"(was: <old subject>)\" from SUBJECT lines.
2181 Leading \"Re: \" is not stripped by this function. Use the function
2182 `message-strip-subject-re' for this."
2184 (let ((query message-subject-trailing-was-query) new)
2186 (string-match (if (eq query 'ask)
2187 message-subject-trailing-was-ask-regexp
2188 message-subject-trailing-was-regexp)
2190 (setq new (substring subject 0 (match-beginning 0)))
2191 (or (not (eq query 'ask))
2193 "Strip `(was: <old subject>)' in subject? " t
2195 "Strip `(was: <old subject>)' in subject "
2196 "and use the new one instead?\n\n"
2197 "Current subject is: \"" subject "\"\n\n"
2198 "New subject would be: \"" new "\"\n\n"
2199 "See the variable `message-subject-trailing-was-query' "
2200 "to get rid of this query.")))
2204 ;;; Suggested by Jonas Steverud @ www.dtek.chalmers.se/~d4jonas/
2206 (defun message-change-subject (new-subject)
2207 "Ask for NEW-SUBJECT header, append (was: <Old Subject>)."
2210 (read-from-minibuffer "New subject: ")))
2211 (cond ((and (not (or (null new-subject) ; new subject not empty
2212 (zerop (string-width new-subject))
2213 (string-match "^[ \t]*$" new-subject))))
2217 (message-narrow-to-headers)
2218 (message-fetch-field "Subject"))))
2219 (cond ((not old-subject)
2220 (error "No current subject"))
2223 (regexp-quote new-subject)
2225 old-subject)) ; yes, it really is a new subject
2226 ;; delete eventual Re: prefix
2228 (message-strip-subject-re old-subject))
2229 (message-goto-subject)
2230 (message-delete-line)
2231 (insert (concat "Subject: "
2234 old-subject ")\n")))))))))
2236 (defun message-mark-inserted-region (beg end &optional verbatim)
2237 "Mark some region in the current article with enclosing tags.
2238 See `message-mark-insert-begin' and `message-mark-insert-end'.
2239 If VERBATIM, use slrn style verbatim marks (\"#v+\" and \"#v-\")."
2240 (interactive "r\nP")
2242 ;; add to the end of the region first, otherwise end would be invalid
2244 (insert (if verbatim "#v-\n" message-mark-insert-end))
2246 (insert (if verbatim "#v+\n" message-mark-insert-begin))))
2248 (defun message-mark-insert-file (file &optional verbatim)
2249 "Insert FILE at point, marking it with enclosing tags.
2250 See `message-mark-insert-begin' and `message-mark-insert-end'.
2251 If VERBATIM, use slrn style verbatim marks (\"#v+\" and \"#v-\")."
2252 (interactive "fFile to insert: \nP")
2253 ;; reverse insertion to get correct result.
2255 (insert (if verbatim "#v-\n" message-mark-insert-end))
2257 (insert-file-contents file)
2259 (insert (if verbatim "#v+\n" message-mark-insert-begin))))
2261 (defun message-add-archive-header ()
2262 "Insert \"X-No-Archive: Yes\" in the header and a note in the body.
2263 The note can be customized using `message-archive-note'. When called with a
2264 prefix argument, ask for a text to insert. If you don't want the note in the
2265 body, set `message-archive-note' to nil."
2267 (if current-prefix-arg
2268 (setq message-archive-note
2269 (read-from-minibuffer "Reason for No-Archive: "
2270 (cons message-archive-note 0))))
2272 (if (message-goto-signature)
2273 (re-search-backward message-signature-separator))
2274 (when message-archive-note
2275 (insert message-archive-note)
2277 (message-add-header message-archive-header)
2278 (message-sort-headers)))
2280 (defun message-cross-post-followup-to-header (target-group)
2281 "Mangles FollowUp-To and Newsgroups header to point to TARGET-GROUP.
2282 With prefix-argument just set Follow-Up, don't cross-post."
2284 (list ; Completion based on Gnus
2285 (completing-read "Followup To: "
2286 (if (boundp 'gnus-newsrc-alist)
2288 nil nil '("poster" . 0)
2289 (if (boundp 'gnus-group-history)
2290 'gnus-group-history))))
2291 (message-remove-header "Follow[Uu]p-[Tt]o" t)
2292 (message-goto-newsgroups)
2294 ;; if we already did a crosspost before, kill old target
2295 (if (and message-cross-post-old-target
2297 (regexp-quote (concat "," message-cross-post-old-target))
2300 ;; unless (followup is to poster or user explicitly asked not
2301 ;; to cross-post, or target-group is already in Newsgroups)
2302 ;; add target-group to Newsgroups line.
2304 ;; def: cross-post, req:no
2305 (and message-cross-post-default (not current-prefix-arg))
2306 ;; def: no-cross-post, req:yes
2307 (and (not message-cross-post-default) current-prefix-arg))
2308 (not (string-match "poster" target-group))
2309 (not (string-match (regexp-quote target-group)
2310 (message-fetch-field "Newsgroups"))))
2312 (insert (concat "," target-group))))
2313 (end-of-line) ; ensure Followup: comes after Newsgroups:
2314 ;; unless new followup would be identical to Newsgroups line
2315 ;; make a new Followup-To line
2316 (if (not (string-match (concat "^[ \t]*"
2319 (message-fetch-field "Newsgroups")))
2320 (insert (concat "\nFollowup-To: " target-group)))
2321 (setq message-cross-post-old-target target-group))
2323 (defun message-cross-post-insert-note (target-group cross-post in-old
2325 "Insert a in message body note about a set Followup or Crosspost.
2326 If there have been previous notes, delete them. TARGET-GROUP specifies the
2327 group to Followup-To. When CROSS-POST is t, insert note about
2328 crossposting. IN-OLD specifies whether TARGET-GROUP is a member of
2329 OLD-GROUPS. OLD-GROUPS lists the old-groups the posting would have
2330 been made to before the user asked for a Crosspost."
2331 ;; start scanning body for previous uses
2332 (message-goto-signature)
2333 (let ((head (re-search-backward
2334 (concat "^" mail-header-separator)
2335 nil t))) ; just search in body
2336 (message-goto-signature)
2337 (while (re-search-backward
2338 (concat "^" (regexp-quote message-cross-post-note) ".*")
2340 (message-delete-line))
2341 (message-goto-signature)
2342 (while (re-search-backward
2343 (concat "^" (regexp-quote message-followup-to-note) ".*")
2345 (message-delete-line))
2347 (if (message-goto-signature)
2348 (re-search-backward message-signature-separator))
2351 (string-match "^[ \t]*poster[ \t]*$" target-group))
2352 (insert (concat message-followup-to-note target-group "\n"))
2353 (insert (concat message-cross-post-note target-group "\n")))))
2355 (defun message-cross-post-followup-to (target-group)
2356 "Crossposts message and set Followup-To to TARGET-GROUP.
2357 With prefix-argument just set Follow-Up, don't cross-post."
2359 (list ; Completion based on Gnus
2360 (completing-read "Followup To: "
2361 (if (boundp 'gnus-newsrc-alist)
2363 nil nil '("poster" . 0)
2364 (if (boundp 'gnus-group-history)
2365 'gnus-group-history))))
2366 (when (fboundp 'gnus-group-real-name)
2367 (setq target-group (gnus-group-real-name target-group)))
2368 (cond ((not (or (null target-group) ; new subject not empty
2369 (zerop (string-width target-group))
2370 (string-match "^[ \t]*$" target-group)))
2372 (let* ((old-groups (message-fetch-field "Newsgroups"))
2373 (in-old (string-match
2374 (regexp-quote target-group)
2375 (or old-groups ""))))
2376 ;; check whether target exactly matches old Newsgroups
2377 (cond ((not old-groups)
2378 (error "No current newsgroup"))
2382 (regexp-quote target-group)
2385 ;; yes, Newsgroups line must change
2386 (message-cross-post-followup-to-header target-group)
2387 ;; insert note whether we do cross-post or followup-to
2388 (funcall message-cross-post-note-function
2390 (if (or (and message-cross-post-default
2391 (not current-prefix-arg))
2392 (and (not message-cross-post-default)
2393 current-prefix-arg)) t)
2394 in-old old-groups))))))))
2396 ;;; Reduce To: to Cc: or Bcc: header
2398 (defun message-reduce-to-to-cc ()
2399 "Replace contents of To: header with contents of Cc: or Bcc: header."
2402 (save-restriction (message-narrow-to-headers)
2403 (message-fetch-field "cc")))
2405 (if (and (not cc-content)
2408 (message-narrow-to-headers)
2409 (message-fetch-field "bcc"))))
2414 (message-delete-line)
2415 (insert (concat "To: " cc-content "\n"))
2417 (message-narrow-to-headers)
2418 (message-remove-header (if bcc
2422 ;;; End of functions adopted from `message-utils.el'.
2424 (defun message-remove-header (header &optional is-regexp first reverse)
2425 "Remove HEADER in the narrowed buffer.
2426 If IS-REGEXP, HEADER is a regular expression.
2427 If FIRST, only remove the first instance of the header.
2428 If REVERSE, remove headers that doesn't match HEADER.
2429 Return the number of headers removed."
2430 (goto-char (point-min))
2431 (let ((regexp (if is-regexp header (concat "^" (regexp-quote header) ":")))
2433 (case-fold-search t)
2435 (while (and (not (eobp))
2438 (not (looking-at regexp))
2439 (looking-at regexp))
2446 ;; There might be a continuation header, so we have to search
2447 ;; until we find a new non-continuation line.
2450 (if (re-search-forward "^[^ \t]" nil t)
2451 (goto-char (match-beginning 0))
2454 (if (re-search-forward "^[^ \t]" nil t)
2455 (goto-char (match-beginning 0))
2456 (goto-char (point-max)))))
2459 (defun message-remove-first-header (header)
2460 "Remove the first instance of HEADER if there is more than one."
2462 (regexp (concat "^" (regexp-quote header) ":")))
2464 (goto-char (point-min))
2465 (while (re-search-forward regexp nil t)
2468 (message-remove-header header nil t)
2471 (defun message-narrow-to-headers ()
2472 "Narrow the buffer to the head of the message."
2475 (goto-char (point-min))
2476 (if (re-search-forward
2477 (concat "^" (regexp-quote mail-header-separator) "\n") nil t)
2480 (goto-char (point-min)))
2482 (defun message-narrow-to-head-1 ()
2483 "Like `message-narrow-to-head'. Don't widen."
2485 (goto-char (point-min))
2486 (if (search-forward "\n\n" nil 1)
2489 (goto-char (point-min)))
2491 ;; FIXME: clarify difference: message-narrow-to-head,
2492 ;; message-narrow-to-headers-or-head, message-narrow-to-headers
2493 (defun message-narrow-to-head ()
2494 "Narrow the buffer to the head of the message.
2495 Point is left at the beginning of the narrowed-to region."
2497 (message-narrow-to-head-1))
2499 (defun message-narrow-to-headers-or-head ()
2500 "Narrow the buffer to the head of the message."
2503 (goto-char (point-min))
2504 (if (re-search-forward (concat "\\(\n\\)\n\\|^\\("
2505 (regexp-quote mail-header-separator)
2508 (or (match-end 1) (match-beginning 2))
2510 (goto-char (point-min)))
2512 (defun message-news-p ()
2513 "Say whether the current buffer contains a news message."
2514 (and (not message-this-is-mail)
2515 (or message-this-is-news
2518 (message-narrow-to-headers)
2519 (and (message-fetch-field "newsgroups")
2520 (not (message-fetch-field "posted-to"))))))))
2522 (defun message-mail-p ()
2523 "Say whether the current buffer contains a mail message."
2524 (and (not message-this-is-news)
2525 (or message-this-is-mail
2528 (message-narrow-to-headers)
2529 (or (message-fetch-field "to")
2530 (message-fetch-field "cc")
2531 (message-fetch-field "bcc")))))))
2533 (defun message-subscribed-p ()
2534 "Say whether we need to insert a MFT header."
2535 (or message-subscribed-regexps
2536 message-subscribed-addresses
2537 message-subscribed-address-file
2538 message-subscribed-address-functions))
2540 (defun message-next-header ()
2541 "Go to the beginning of the next header."
2543 (or (eobp) (forward-char 1))
2544 (not (if (re-search-forward "^[^ \t]" nil t)
2546 (goto-char (point-max)))))
2548 (defun message-sort-headers-1 ()
2549 "Sort the buffer as headers using `message-rank' text props."
2550 (goto-char (point-min))
2553 nil 'message-next-header
2555 (message-next-header)
2559 (or (get-text-property (point) 'message-rank)
2562 (defun message-sort-headers ()
2563 "Sort the headers of the current message according to `message-header-format-alist'."
2567 (let ((max (1+ (length message-header-format-alist)))
2569 (message-narrow-to-headers)
2570 (while (re-search-forward "^[^ \n]+:" nil t)
2572 (match-beginning 0) (1+ (match-beginning 0))
2574 (if (setq rank (length (memq (assq (intern (buffer-substring
2576 (1- (match-end 0))))
2577 message-header-format-alist)
2578 message-header-format-alist)))
2581 (message-sort-headers-1))))
2583 (defun message-kill-address ()
2584 "Kill the address under point."
2586 (let ((start (point)))
2587 (message-skip-to-next-address)
2588 (kill-region start (if (bolp) (1- (point)) (point)))))
2591 (autoload 'Info-goto-node "info")
2592 (defvar mml2015-use)
2594 (defun message-info (&optional arg)
2595 "Display the Message manual.
2597 Prefixed with one \\[universal-argument], display the Emacs MIME
2598 manual. With two \\[universal-argument]'s, display the EasyPG or
2599 PGG manual, depending on the value of `mml2015-use'."
2601 (info (format "(%s)Top"
2605 ((eq arg 4) 'emacs-mime)
2606 ((and (not (booleanp arg))
2620 (defvar message-mode-map nil)
2622 (unless message-mode-map
2623 (setq message-mode-map (make-keymap))
2624 (set-keymap-parent message-mode-map text-mode-map)
2625 (define-key message-mode-map "\C-c?" 'describe-mode)
2627 (define-key message-mode-map "\C-c\C-f\C-t" 'message-goto-to)
2628 (define-key message-mode-map "\C-c\C-f\C-o" 'message-goto-from)
2629 (define-key message-mode-map "\C-c\C-f\C-b" 'message-goto-bcc)
2630 (define-key message-mode-map "\C-c\C-f\C-w" 'message-goto-fcc)
2631 (define-key message-mode-map "\C-c\C-f\C-c" 'message-goto-cc)
2632 (define-key message-mode-map "\C-c\C-f\C-s" 'message-goto-subject)
2633 (define-key message-mode-map "\C-c\C-f\C-r" 'message-goto-reply-to)
2634 (define-key message-mode-map "\C-c\C-f\C-n" 'message-goto-newsgroups)
2635 (define-key message-mode-map "\C-c\C-f\C-d" 'message-goto-distribution)
2636 (define-key message-mode-map "\C-c\C-f\C-f" 'message-goto-followup-to)
2637 (define-key message-mode-map "\C-c\C-f\C-m" 'message-goto-mail-followup-to)
2638 (define-key message-mode-map "\C-c\C-f\C-k" 'message-goto-keywords)
2639 (define-key message-mode-map "\C-c\C-f\C-u" 'message-goto-summary)
2640 (define-key message-mode-map "\C-c\C-f\C-i"
2641 'message-insert-or-toggle-importance)
2642 (define-key message-mode-map "\C-c\C-f\C-a"
2643 'message-generate-unsubscribed-mail-followup-to)
2645 ;; modify headers (and insert notes in body)
2646 (define-key message-mode-map "\C-c\C-fs" 'message-change-subject)
2648 (define-key message-mode-map "\C-c\C-fx" 'message-cross-post-followup-to)
2649 ;; prefix+message-cross-post-followup-to = same w/o cross-post
2650 (define-key message-mode-map "\C-c\C-ft" 'message-reduce-to-to-cc)
2651 (define-key message-mode-map "\C-c\C-fa" 'message-add-archive-header)
2652 ;; mark inserted text
2653 (define-key message-mode-map "\C-c\M-m" 'message-mark-inserted-region)
2654 (define-key message-mode-map "\C-c\M-f" 'message-mark-insert-file)
2656 (define-key message-mode-map "\C-c\C-b" 'message-goto-body)
2657 (define-key message-mode-map "\C-c\C-i" 'message-goto-signature)
2659 (define-key message-mode-map "\C-c\C-t" 'message-insert-to)
2660 (define-key message-mode-map "\C-c\C-fw" 'message-insert-wide-reply)
2661 (define-key message-mode-map "\C-c\C-n" 'message-insert-newsgroups)
2662 (define-key message-mode-map "\C-c\C-l" 'message-to-list-only)
2663 (define-key message-mode-map "\C-c\C-f\C-e" 'message-insert-expires)
2665 (define-key message-mode-map "\C-c\C-u" 'message-insert-or-toggle-importance)
2666 (define-key message-mode-map "\C-c\M-n"
2667 'message-insert-disposition-notification-to)
2669 (define-key message-mode-map "\C-c\C-y" 'message-yank-original)
2670 (define-key message-mode-map "\C-c\M-\C-y" 'message-yank-buffer)
2671 (define-key message-mode-map "\C-c\C-q" 'message-fill-yanked-message)
2672 (define-key message-mode-map "\C-c\C-w" 'message-insert-signature)
2673 (define-key message-mode-map "\C-c\M-h" 'message-insert-headers)
2674 (define-key message-mode-map "\C-c\C-r" 'message-caesar-buffer-body)
2675 (define-key message-mode-map "\C-c\C-o" 'message-sort-headers)
2676 (define-key message-mode-map "\C-c\M-r" 'message-rename-buffer)
2678 (define-key message-mode-map "\C-c\C-c" 'message-send-and-exit)
2679 (define-key message-mode-map "\C-c\C-s" 'message-send)
2680 (define-key message-mode-map "\C-c\C-k" 'message-kill-buffer)
2681 (define-key message-mode-map "\C-c\C-d" 'message-dont-send)
2682 (define-key message-mode-map "\C-c\n" 'gnus-delay-article)
2684 (define-key message-mode-map "\C-c\M-k" 'message-kill-address)
2685 (define-key message-mode-map "\C-c\C-e" 'message-elide-region)
2686 (define-key message-mode-map "\C-c\C-v" 'message-delete-not-region)
2687 (define-key message-mode-map "\C-c\C-z" 'message-kill-to-signature)
2688 (define-key message-mode-map "\M-\r" 'message-newline-and-reformat)
2689 (define-key message-mode-map [remap split-line] 'message-split-line)
2691 (define-key message-mode-map "\C-c\C-a" 'mml-attach-file)
2693 (define-key message-mode-map "\C-a" 'message-beginning-of-line)
2694 (define-key message-mode-map "\t" 'message-tab)
2696 (define-key message-mode-map "\M-n" 'message-display-abbrev))
2699 message-mode-menu message-mode-map "Message Menu."
2701 ["Yank Original" message-yank-original message-reply-buffer]
2702 ["Fill Yanked Message" message-fill-yanked-message t]
2703 ["Insert Signature" message-insert-signature t]
2704 ["Caesar (rot13) Message" message-caesar-buffer-body t]
2705 ["Caesar (rot13) Region" message-caesar-region (message-mark-active-p)]
2706 ["Elide Region" message-elide-region
2707 :active (message-mark-active-p)
2708 :help "Replace text in region with an ellipsis"]
2709 ["Delete Outside Region" message-delete-not-region
2710 :active (message-mark-active-p)
2711 :help "Delete all quoted text outside region"]
2712 ["Kill To Signature" message-kill-to-signature t]
2713 ["Newline and Reformat" message-newline-and-reformat t]
2714 ["Rename buffer" message-rename-buffer t]
2715 ["Spellcheck" ispell-message :help "Spellcheck this message"]
2717 ["Insert Region Marked" message-mark-inserted-region
2718 :active (message-mark-active-p) :help "Mark region with enclosing tags"]
2719 ["Insert File Marked..." message-mark-insert-file
2720 :help "Insert file at point marked with enclosing tags"]
2722 ["Send Message" message-send-and-exit :help "Send this message"]
2723 ["Postpone Message" message-dont-send
2724 :help "File this draft message and exit"]
2725 ["Send at Specific Time..." gnus-delay-article
2726 :help "Ask, then arrange to send message at that time"]
2727 ["Kill Message" message-kill-buffer
2728 :help "Delete this message without sending"]
2730 ["Message manual" message-info :help "Display the Message manual"]))
2733 message-mode-field-menu message-mode-map ""
2735 ["To" message-goto-to t]
2736 ["From" message-goto-from t]
2737 ["Subject" message-goto-subject t]
2738 ["Change subject..." message-change-subject t]
2739 ["Cc" message-goto-cc t]
2740 ["Bcc" message-goto-bcc t]
2741 ["Fcc" message-goto-fcc t]
2742 ["Reply-To" message-goto-reply-to t]
2743 ["Flag As Important" message-insert-importance-high
2744 :help "Mark this message as important"]
2745 ["Flag As Unimportant" message-insert-importance-low
2746 :help "Mark this message as unimportant"]
2748 message-insert-disposition-notification-to
2749 :help "Request a receipt notification"]
2751 ;; (typical) news stuff
2752 ["Summary" message-goto-summary t]
2753 ["Keywords" message-goto-keywords t]
2754 ["Newsgroups" message-goto-newsgroups t]
2755 ["Fetch Newsgroups" message-insert-newsgroups t]
2756 ["Followup-To" message-goto-followup-to t]
2757 ;; ["Followup-To (with note in body)" message-cross-post-followup-to t]
2758 ["Crosspost / Followup-To..." message-cross-post-followup-to t]
2759 ["Distribution" message-goto-distribution t]
2760 ["Expires" message-insert-expires t ]
2761 ["X-No-Archive" message-add-archive-header t ]
2763 ;; (typical) mailing-lists stuff
2764 ["Fetch To" message-insert-to
2765 :help "Insert a To header that points to the author."]
2766 ["Fetch To and Cc" message-insert-wide-reply
2767 :help "Insert To and Cc headers as if you were doing a wide reply."]
2769 ["Send to list only" message-to-list-only t]
2770 ["Mail-Followup-To" message-goto-mail-followup-to t]
2771 ["Unsubscribed list post" message-generate-unsubscribed-mail-followup-to
2772 :help "Insert a reasonable `Mail-Followup-To:' header."]
2773 ["Reduce To: to Cc:" message-reduce-to-to-cc t]
2775 ["Sort Headers" message-sort-headers t]
2776 ["Encode non-ASCII domain names" message-idna-to-ascii-rhs t]
2777 ;; We hide `message-hidden-headers' by narrowing the buffer.
2778 ["Show Hidden Headers" widen t]
2779 ["Goto Body" message-goto-body t]
2780 ["Goto Signature" message-goto-signature t]))
2782 (defvar message-tool-bar-map nil)
2784 (defvar facemenu-add-face-function)
2785 (defvar facemenu-remove-face-function)
2787 ;;; Forbidden properties
2789 ;; We use `after-change-functions' to keep special text properties
2790 ;; that interfere with the normal function of message mode out of the
2793 (defcustom message-strip-special-text-properties t
2794 "Strip special properties from the message buffer.
2796 Emacs has a number of special text properties which can break message
2797 composing in various ways. If this option is set, message will strip
2798 these properties from the message composition buffer. However, some
2799 packages requires these properties to be present in order to work.
2800 If you use one of these packages, turn this option off, and hope the
2801 message composition doesn't break too bad."
2803 :group 'message-various
2804 :link '(custom-manual "(message)Various Message Variables")
2807 (defvar message-forbidden-properties
2808 ;; No reason this should be clutter up customize. We make it a
2809 ;; property list (rather than a list of property symbols), to be
2810 ;; directly useful for `remove-text-properties'.
2811 '(field nil read-only nil invisible nil intangible nil
2812 mouse-face nil modification-hooks nil insert-in-front-hooks nil
2813 insert-behind-hooks nil point-entered nil point-left nil)
2814 ;; Other special properties:
2815 ;; category, face, display: probably doesn't do any harm.
2816 ;; fontified: is used by font-lock.
2817 ;; syntax-table, local-map: I dunno.
2818 "Property list of with properties forbidden in message buffers.
2819 The values of the properties are ignored, only the property names are used.")
2821 (defun message-tamago-not-in-use-p (pos)
2822 "Return t when tamago version 4 is not in use at the cursor position.
2823 Tamago version 4 is a popular input method for writing Japanese text.
2824 It uses the properties `intangible', `invisible', `modification-hooks'
2825 and `read-only' when translating ascii or kana text to kanji text.
2826 These properties are essential to work, so we should never strip them."
2827 (not (and (boundp 'egg-modefull-mode)
2828 (symbol-value 'egg-modefull-mode)
2829 (or (memq (get-text-property pos 'intangible)
2830 '(its-part-1 its-part-2))
2831 (get-text-property pos 'egg-end)
2832 (get-text-property pos 'egg-lang)
2833 (get-text-property pos 'egg-start)))))
2835 (defsubst message-mail-alias-type-p (type)
2836 (if (atom message-mail-alias-type)
2837 (eq message-mail-alias-type type)
2838 (memq type message-mail-alias-type)))
2840 (defun message-strip-forbidden-properties (begin end &optional old-length)
2841 "Strip forbidden properties between BEGIN and END, ignoring the third arg.
2842 This function is intended to be called from `after-change-functions'.
2843 See also `message-forbidden-properties'."
2844 (when (and (message-mail-alias-type-p 'ecomplete)
2845 (memq this-command message-self-insert-commands))
2846 (message-display-abbrev))
2847 (when (and message-strip-special-text-properties
2848 (message-tamago-not-in-use-p begin))
2849 (let ((buffer-read-only nil)
2850 (inhibit-read-only t))
2851 (remove-text-properties begin end message-forbidden-properties))))
2853 (defvar message-smileys '(":-)" ":)"
2856 "A list of recognized smiley faces in `message-mode'.")
2858 (defun message--syntax-propertize (beg end)
2859 "Syntax-propertize certain message text specially."
2860 (let ((citation-regexp (concat "^" message-cite-prefix-regexp ".*$"))
2861 (smiley-regexp (regexp-opt message-smileys)))
2863 (while (search-forward-regexp citation-regexp
2865 (let ((start (match-beginning 0))
2866 (end (match-end 0)))
2867 (add-text-properties start (1+ start)
2868 `(syntax-table ,(string-to-syntax "<")))
2869 (add-text-properties end (min (1+ end) (point-max))
2870 `(syntax-table ,(string-to-syntax ">")))))
2872 (while (search-forward-regexp smiley-regexp
2874 (add-text-properties (match-beginning 0) (match-end 0)
2875 `(syntax-table ,(string-to-syntax "."))))))
2878 (define-derived-mode message-mode text-mode "Message"
2879 "Major mode for editing mail and news to be sent.
2880 Like Text Mode but with these additional commands:\\<message-mode-map>
2881 C-c C-s `message-send' (send the message) C-c C-c `message-send-and-exit'
2882 C-c C-d Postpone sending the message C-c C-k Kill the message
2883 C-c C-f move to a header field (and create it if there isn't):
2884 C-c C-f C-t move to To C-c C-f C-s move to Subject
2885 C-c C-f C-c move to Cc C-c C-f C-b move to Bcc
2886 C-c C-f C-w move to Fcc C-c C-f C-r move to Reply-To
2887 C-c C-f C-u move to Summary C-c C-f C-n move to Newsgroups
2888 C-c C-f C-k move to Keywords C-c C-f C-d move to Distribution
2889 C-c C-f C-o move to From (\"Originator\")
2890 C-c C-f C-f move to Followup-To
2891 C-c C-f C-m move to Mail-Followup-To
2892 C-c C-f C-e move to Expires
2893 C-c C-f C-i cycle through Importance values
2894 C-c C-f s change subject and append \"(was: <Old Subject>)\"
2895 C-c C-f x crossposting with FollowUp-To header and note in body
2896 C-c C-f t replace To: header with contents of Cc: or Bcc:
2897 C-c C-f a Insert X-No-Archive: header and a note in the body
2898 C-c C-t `message-insert-to' (add a To header to a news followup)
2899 C-c C-l `message-to-list-only' (removes all but list address in to/cc)
2900 C-c C-n `message-insert-newsgroups' (add a Newsgroup header to a news reply)
2901 C-c C-b `message-goto-body' (move to beginning of message text).
2902 C-c C-i `message-goto-signature' (move to the beginning of the signature).
2903 C-c C-w `message-insert-signature' (insert `message-signature-file' file).
2904 C-c C-y `message-yank-original' (insert current message, if any).
2905 C-c C-q `message-fill-yanked-message' (fill what was yanked).
2906 C-c C-e `message-elide-region' (elide the text between point and mark).
2907 C-c C-v `message-delete-not-region' (remove the text outside the region).
2908 C-c C-z `message-kill-to-signature' (kill the text up to the signature).
2909 C-c C-r `message-caesar-buffer-body' (rot13 the message body).
2910 C-c C-a `mml-attach-file' (attach a file as MIME).
2911 C-c C-u `message-insert-or-toggle-importance' (insert or cycle importance).
2912 C-c M-n `message-insert-disposition-notification-to' (request receipt).
2913 C-c M-m `message-mark-inserted-region' (mark region with enclosing tags).
2914 C-c M-f `message-mark-insert-file' (insert file marked with enclosing tags).
2915 M-RET `message-newline-and-reformat' (break the line and reformat)."
2916 (set (make-local-variable 'message-reply-buffer) nil)
2917 (set (make-local-variable 'message-inserted-headers) nil)
2918 (set (make-local-variable 'message-send-actions) nil)
2919 (set (make-local-variable 'message-return-action) nil)
2920 (set (make-local-variable 'message-exit-actions) nil)
2921 (set (make-local-variable 'message-kill-actions) nil)
2922 (set (make-local-variable 'message-postpone-actions) nil)
2923 (set (make-local-variable 'message-draft-article) nil)
2924 (setq buffer-offer-save t)
2925 (set (make-local-variable 'facemenu-add-face-function)
2927 (let ((face-fun (cdr (assq face message-face-alist))))
2929 (funcall face-fun (point) end)
2930 (error "Face %s not configured for %s mode" face mode-name)))
2932 (set (make-local-variable 'facemenu-remove-face-function) t)
2933 (set (make-local-variable 'message-reply-headers) nil)
2934 (make-local-variable 'message-newsreader)
2935 (make-local-variable 'message-mailer)
2936 (make-local-variable 'message-post-method)
2937 (set (make-local-variable 'message-sent-message-via) nil)
2938 (set (make-local-variable 'message-checksum) nil)
2939 (set (make-local-variable 'message-mime-part) 0)
2940 (message-setup-fill-variables)
2941 (when message-fill-column
2942 (setq fill-column message-fill-column)
2943 (turn-on-auto-fill))
2944 ;; Allow using comment commands to add/remove quoting.
2945 ;; (set (make-local-variable 'comment-start) message-yank-prefix)
2946 (when message-yank-prefix
2947 (set (make-local-variable 'comment-start) message-yank-prefix)
2948 (set (make-local-variable 'comment-start-skip)
2949 (concat "^" (regexp-quote message-yank-prefix) "[ \t]*")))
2950 (set (make-local-variable 'font-lock-defaults)
2951 '(message-font-lock-keywords t))
2952 (if (boundp 'tool-bar-map)
2953 (set (make-local-variable 'tool-bar-map) (message-make-tool-bar)))
2954 (easy-menu-add message-mode-menu message-mode-map)
2955 (easy-menu-add message-mode-field-menu message-mode-map)
2956 ;; Mmmm... Forbidden properties...
2957 (add-hook 'after-change-functions 'message-strip-forbidden-properties
2959 ;; Allow mail alias things.
2961 ((message-mail-alias-type-p 'abbrev)
2962 (mail-abbrevs-setup))
2963 ((message-mail-alias-type-p 'ecomplete)
2965 (add-hook 'completion-at-point-functions 'message-completion-function nil t)
2966 (unless buffer-file-name
2967 (message-set-auto-save-file-name))
2968 (unless (buffer-base-buffer)
2969 ;; Don't enable multibyte on an indirect buffer. Maybe enabling
2970 ;; multibyte is not necessary at all. -- zsh
2971 (mm-enable-multibyte))
2972 (set (make-local-variable 'indent-tabs-mode) nil) ;No tabs for indentation.
2974 ;; Syntactic fontification. Helps `show-paren-mode',
2975 ;; `electric-pair-mode', and C-M-* navigation by syntactically
2976 ;; excluding citations and other artifacts.
2978 (set (make-local-variable 'syntax-propertize-function) 'message--syntax-propertize)
2979 (set (make-local-variable 'parse-sexp-ignore-comments) t))
2981 (defun message-setup-fill-variables ()
2982 "Setup message fill variables."
2983 (set (make-local-variable 'fill-paragraph-function)
2984 'message-fill-paragraph)
2985 (make-local-variable 'paragraph-separate)
2986 (make-local-variable 'paragraph-start)
2987 (make-local-variable 'adaptive-fill-regexp)
2988 (make-local-variable 'adaptive-fill-first-line-regexp)
2989 (let ((quote-prefix-regexp
2990 ;; User should change message-cite-prefix-regexp if
2991 ;; message-yank-prefix is set to an abnormal value.
2992 (concat "\\(" message-cite-prefix-regexp "\\)[ \t]*")))
2993 (setq paragraph-start
2995 (regexp-quote mail-header-separator) "$\\|"
2996 "[ \t]*$\\|" ; blank lines
2997 "-- $\\|" ; signature delimiter
2998 "---+$\\|" ; delimiters for forwarded messages
2999 page-delimiter "$\\|" ; spoiler warnings
3000 ".*wrote:$\\|" ; attribution lines
3001 quote-prefix-regexp "$\\|" ; empty lines in quoted text
3003 "<#!*/?\\(multipart\\|part\\|external\\|mml\\|secure\\)"))
3004 (setq paragraph-separate paragraph-start)
3005 (setq adaptive-fill-regexp
3006 (concat quote-prefix-regexp "\\|" adaptive-fill-regexp))
3007 (setq adaptive-fill-first-line-regexp
3008 (concat quote-prefix-regexp "\\|"
3009 adaptive-fill-first-line-regexp)))
3010 (setq-local auto-fill-inhibit-regexp nil)
3011 (setq-local normal-auto-fill-function 'message-do-auto-fill))
3016 ;;; Message mode commands
3019 ;;; Movement commands
3021 (defun message-goto-to ()
3022 "Move point to the To header."
3025 (message-position-on-field "To"))
3027 (defun message-goto-from ()
3028 "Move point to the From header."
3031 (message-position-on-field "From"))
3033 (defun message-goto-subject ()
3034 "Move point to the Subject header."
3037 (message-position-on-field "Subject"))
3039 (defun message-goto-cc ()
3040 "Move point to the Cc header."
3043 (message-position-on-field "Cc" "To"))
3045 (defun message-goto-bcc ()
3046 "Move point to the Bcc header."
3049 (message-position-on-field "Bcc" "Cc" "To"))
3051 (defun message-goto-fcc ()
3052 "Move point to the Fcc header."
3055 (message-position-on-field "Fcc" "To" "Newsgroups"))
3057 (defun message-goto-reply-to ()
3058 "Move point to the Reply-To header."
3061 (message-position-on-field "Reply-To" "Subject"))
3063 (defun message-goto-newsgroups ()
3064 "Move point to the Newsgroups header."
3067 (message-position-on-field "Newsgroups"))
3069 (defun message-goto-distribution ()
3070 "Move point to the Distribution header."
3073 (message-position-on-field "Distribution"))
3075 (defun message-goto-followup-to ()
3076 "Move point to the Followup-To header."
3079 (message-position-on-field "Followup-To" "Newsgroups"))
3081 (defun message-goto-mail-followup-to ()
3082 "Move point to the Mail-Followup-To header."
3085 (message-position-on-field "Mail-Followup-To" "To"))
3087 (defun message-goto-keywords ()
3088 "Move point to the Keywords header."
3091 (message-position-on-field "Keywords" "Subject"))
3093 (defun message-goto-summary ()
3094 "Move point to the Summary header."
3097 (message-position-on-field "Summary" "Subject"))
3099 (defun message-goto-body ()
3100 "Move point to the beginning of the message body."
3102 (when (and (called-interactively-p 'any)
3103 (looking-at "[ \t]*\n"))
3106 (goto-char (point-min))
3107 (or (search-forward (concat "\n" mail-header-separator "\n") nil t)
3108 (search-forward-regexp "[^:]+:\\([^\n]\\|\n[ \t]\\)+\n\n" nil t)))
3110 (defun message-in-body-p ()
3111 "Return t if point is in the message body."
3114 (goto-char (point-min))
3115 (or (search-forward (concat "\n" mail-header-separator "\n") nil t)
3116 (search-forward-regexp "[^:]+:\\([^\n]\\|\n[ \t]\\)+\n\n" nil t))
3119 (defun message-goto-eoh ()
3120 "Move point to the end of the headers."
3125 (defun message-goto-signature ()
3126 "Move point to the beginning of the message signature.
3127 If there is no signature in the article, go to the end and
3131 (goto-char (point-min))
3132 (if (re-search-forward message-signature-separator nil t)
3134 (goto-char (point-max))
3137 (defun message-generate-unsubscribed-mail-followup-to (&optional include-cc)
3138 "Insert a reasonable MFT header in a post to an unsubscribed list.
3139 When making original posts to a mailing list you are not subscribed to,
3140 you have to type in a MFT header by hand. The contents, usually, are
3141 the addresses of the list and your own address. This function inserts
3142 such a header automatically. It fetches the contents of the To: header
3143 in the current mail buffer, and appends the current `user-mail-address'.
3145 If the optional argument INCLUDE-CC is non-nil, the addresses in the
3146 Cc: header are also put into the MFT."
3151 (message-narrow-to-headers)
3152 (message-remove-header "Mail-Followup-To")
3153 (setq cc (and include-cc (message-fetch-field "Cc")))
3155 (concat (message-fetch-field "To") "," cc)
3156 (message-fetch-field "To"))))
3157 (message-goto-mail-followup-to)
3158 (insert (concat tos ", " user-mail-address))))
3162 (defun message-insert-to (&optional force)
3163 "Insert a To header that points to the author of the article being replied to.
3164 If the original author requested not to be sent mail, don't insert unless the
3165 prefix FORCE is given."
3167 (let* ((mct (message-fetch-reply-field "mail-copies-to"))
3168 (dont (and mct (or (equal (downcase mct) "never")
3169 (equal (downcase mct) "nobody"))))
3170 (to (or (message-fetch-reply-field "mail-reply-to")
3171 (message-fetch-reply-field "reply-to")
3172 (message-fetch-reply-field "from"))))
3176 "Ignoring the user request not to have copies sent via mail"
3177 "Complying with the user request not to have copies sent via mail")))
3178 (when (and force (not to))
3179 (error "No mail address in the article"))
3180 (when (and to (or force (not dont)))
3181 (message-carefully-insert-headers (list (cons 'To to))))))
3183 (defun message-insert-wide-reply ()
3184 "Insert To and Cc headers as if you were doing a wide reply."
3186 (let ((headers (message-with-reply-buffer
3187 (message-get-reply-headers t))))
3188 (message-carefully-insert-headers headers)))
3190 (defcustom message-header-synonyms
3193 "List of lists of header synonyms.
3194 E.g., if this list contains a member list with elements `Cc' and `To',
3195 then `message-carefully-insert-headers' will not insert a `To' header
3196 when the message is already `Cc'ed to the recipient."
3198 :group 'message-headers
3199 :link '(custom-manual "(message)Message Headers")
3200 :type '(repeat sexp))
3202 (defun message-carefully-insert-headers (headers)
3203 "Insert the HEADERS, an alist, into the message buffer.
3204 Does not insert the headers when they are already present there
3205 or in the synonym headers, defined by `message-header-synonyms'."
3206 ;; FIXME: Should compare only the address and not the full name. Comparison
3207 ;; should be done case-folded (and with `string=' rather than
3209 ;; (mail-strip-quoted-names "Foo Bar <foo@bar>, bla@fasel (Bla Fasel)")
3210 (dolist (header headers)
3211 (let* ((header-name (symbol-name (car header)))
3212 (new-header (cdr header))
3213 (synonyms (loop for synonym in message-header-synonyms
3214 when (memq (car header) synonym) return synonym))
3216 (loop for synonym in synonyms
3217 for old-header = (mail-fetch-field (symbol-name synonym))
3218 when (and old-header (string-match new-header old-header))
3221 (message "already have `%s' in `%s'" new-header old-header)
3222 (when (and (message-position-on-field header-name)
3223 (setq old-header (mail-fetch-field header-name))
3224 (not (string-match "\\` *\\'" old-header)))
3226 (insert new-header)))))
3228 (defun message-widen-reply ()
3229 "Widen the reply to include maximum recipients."
3232 (and (bufferp message-reply-buffer)
3233 (buffer-name message-reply-buffer)
3234 (with-current-buffer message-reply-buffer
3235 (message-get-reply-headers t)))))
3238 (message-narrow-to-headers)
3239 (dolist (elem follow-to)
3240 (message-remove-header (symbol-name (car elem)))
3241 (goto-char (point-min))
3242 (insert (symbol-name (car elem)) ": "
3243 (cdr elem) "\n"))))))
3245 (defun message-insert-newsgroups ()
3246 "Insert the Newsgroups header from the article being replied to."
3248 (let ((old-newsgroups (mail-fetch-field "newsgroups"))
3249 (new-newsgroups (message-fetch-reply-field "newsgroups"))
3252 (message-position-on-field "Newsgroups")
3254 ((not new-newsgroups)
3255 (error "No Newsgroups to insert"))
3256 ((not old-newsgroups)
3257 (insert new-newsgroups))
3259 (setq new-newsgroups (split-string new-newsgroups "[, ]+")
3260 old-newsgroups (split-string old-newsgroups "[, ]+"))
3261 (dolist (group new-newsgroups)
3262 (unless (member group old-newsgroups)
3263 (push group insert-newsgroups)))
3264 (if (null insert-newsgroups)
3265 (error "Newgroup%s already in the header"
3266 (if (> (length new-newsgroups) 1)
3268 (when old-newsgroups
3270 (dolist (group insert-newsgroups)
3274 (insert group)))))))
3278 ;;; Various commands
3280 (defun message-delete-not-region (beg end)
3281 "Delete everything in the body of the current message outside of the region."
3286 ;; snarf citation prefix, if appropriate
3287 (unless (eq (point) (progn (beginning-of-line) (point)))
3288 (when (looking-at message-cite-prefix-regexp)
3289 (setq citeprefix (match-string 0))))
3291 (delete-region (point) (if (not (message-goto-signature))
3297 (delete-region beg (progn (message-goto-body)
3301 (insert citeprefix))))
3302 (when (message-goto-signature)
3305 (defun message-kill-to-signature (&optional arg)
3306 "Kill all text up to the signature.
3307 If a numeric argument or prefix arg is given, leave that number
3308 of lines before the signature intact."
3312 (let ((point (point)))
3313 (narrow-to-region point (point-max))
3314 (message-goto-signature)
3316 (if (and arg (numberp arg))
3317 (forward-line (- -1 arg))
3319 (unless (= point (point))
3320 (kill-region point (point))
3324 (defun message-newline-and-reformat (&optional arg not-break)
3325 "Insert four newlines, and then reformat if inside quoted text.
3326 Prefix arg means justify as well."
3327 (interactive (list (if current-prefix-arg 'full)))
3328 (let (quoted point beg end leading-space bolp fill-paragraph-function)
3329 (setq point (point))
3332 (setq bolp (= beg point))
3333 ;; Find first line of the paragraph.
3335 (while (and (not (eobp))
3336 (not (looking-at message-cite-prefix-regexp))
3337 (looking-at paragraph-start))
3340 (when (looking-at message-cite-prefix-regexp)
3341 (setq quoted (match-string 0))
3342 (goto-char (match-end 0))
3343 (looking-at "[ \t]*")
3344 (setq leading-space (match-string 0)))
3348 (< (- point beg) (length quoted)))
3349 ;; break inside the cite prefix.
3355 (while (and (not (eobp))
3356 (not (looking-at paragraph-separate))
3357 (looking-at message-cite-prefix-regexp)
3358 (equal quoted (match-string 0)))
3359 (goto-char (match-end 0))
3360 (looking-at "[ \t]*")
3361 (if (> (length leading-space) (length (match-string 0)))
3362 (setq leading-space (match-string 0)))
3366 (while (and (if (bobp) nil (forward-line -1) t)
3367 (not (looking-at paragraph-start))
3368 (looking-at message-cite-prefix-regexp)
3369 (equal quoted (match-string 0)))
3371 (goto-char (match-end 0))
3372 (looking-at "[ \t]*")
3373 (if (> (length leading-space) (length (match-string 0)))
3374 (setq leading-space (match-string 0)))))
3375 (while (and (not (eobp))
3376 (not (looking-at paragraph-separate))
3377 (not (looking-at message-cite-prefix-regexp)))
3381 (while (and (if (bobp) nil (forward-line -1) t)
3382 (not (looking-at paragraph-start))
3383 (not (looking-at message-cite-prefix-regexp)))
3384 (setq beg (point))))
3387 (narrow-to-region beg end)
3394 (setq point (point))
3395 ;; (newline 2) doesn't mark both newline's as hard, so call
3396 ;; newline twice. -jas
3399 (delete-region (point) (re-search-forward "[ \t]*"))
3400 (when (and quoted (not bolp))
3401 (insert quoted leading-space)))
3404 (let* ((adaptive-fill-regexp
3405 (regexp-quote (concat quoted leading-space)))
3406 (adaptive-fill-first-line-regexp
3407 adaptive-fill-regexp ))
3408 (fill-paragraph arg))
3409 (fill-paragraph arg))
3410 (if point (goto-char point)))))
3412 (defun message-fill-paragraph (&optional arg)
3413 "Message specific function to fill a paragraph.
3414 This function is used as the value of `fill-paragraph-function' in
3415 Message buffers and is not meant to be called directly."
3416 (interactive (list (if current-prefix-arg 'full)))
3417 (if (message-point-in-header-p)
3418 (message-fill-field)
3419 (message-newline-and-reformat arg t))
3422 (defun message-point-in-header-p ()
3423 "Return t if point is in the header."
3427 (let ((bound (+ (point-at-eol) 1)) case-fold-search)
3428 (goto-char (point-min))
3429 (not (search-forward (concat "\n" mail-header-separator "\n")
3432 (defun message-do-auto-fill ()
3433 "Like `do-auto-fill', but don't fill in message header."
3434 (unless (message-point-in-header-p)
3437 (defun message-insert-signature (&optional force)
3438 "Insert a signature. See documentation for variable `message-signature'."
3439 (interactive (list 0))
3442 ((and (null message-signature)
3445 (goto-char (point-max))
3446 (not (re-search-backward message-signature-separator nil t))))
3447 ((and (null message-signature)
3450 ((functionp message-signature)
3451 (funcall message-signature))
3452 ((listp message-signature)
3453 (eval message-signature))
3454 (t message-signature)))
3457 (cond ((stringp signature)
3459 ((and (eq t signature) message-signature-file)
3460 (setq signature-file
3461 (if (and message-signature-directory
3462 ;; don't actually use the signature directory
3463 ;; if message-signature-file contains a path.
3464 (not (file-name-directory
3465 message-signature-file)))
3466 (expand-file-name message-signature-file
3467 message-signature-directory)
3468 message-signature-file))
3469 (file-exists-p signature-file))))
3471 (goto-char (point-max))
3472 ;; Insert the signature.
3475 (when message-signature-insert-empty-line
3479 (if (eq signature t)
3480 (insert-file-contents signature-file)
3482 (goto-char (point-max))
3483 (or (bolp) (newline)))))
3485 (defun message-insert-importance-high ()
3486 "Insert header to mark message as important."
3490 (message-narrow-to-headers)
3491 (message-remove-header "Importance"))
3493 (insert "Importance: high\n")))
3495 (defun message-insert-importance-low ()
3496 "Insert header to mark message as unimportant."
3500 (message-narrow-to-headers)
3501 (message-remove-header "Importance"))
3503 (insert "Importance: low\n")))
3505 (defun message-insert-or-toggle-importance ()
3506 "Insert a \"Importance: high\" header, or cycle through the header values.
3507 The three allowed values according to RFC 1327 are `high', `normal'
3514 (message-narrow-to-headers)
3515 (when (setq cur (message-fetch-field "Importance"))
3516 (message-remove-header "Importance")
3517 (setq new (cond ((string= cur "high")
3519 ((string= cur "low")
3524 (insert (format "Importance: %s\n" new)))))
3526 (defun message-insert-disposition-notification-to ()
3527 "Request a disposition notification (return receipt) to this message.
3528 Note that this should not be used in newsgroups."
3532 (message-narrow-to-headers)
3533 (message-remove-header "Disposition-Notification-To"))
3535 (insert (format "Disposition-Notification-To: %s\n"
3536 (or (message-field-value "Reply-to")
3537 (message-field-value "From")
3538 (message-make-from))))))
3540 (defun message-elide-region (b e)
3541 "Elide the text in the region.
3542 An ellipsis (from `message-elide-ellipsis') will be inserted where the
3545 (let ((lines (count-lines b e))
3548 (insert (format-spec message-elide-ellipsis
3552 (defvar message-caesar-translation-table nil)
3554 (defun message-caesar-region (b e &optional n)
3555 "Caesar rotate region B to E by N, default 13, for decrypting netnews."
3558 (min (point) (or (mark t) (point)))
3559 (max (point) (or (mark t) (point)))
3560 (when current-prefix-arg
3561 (prefix-numeric-value current-prefix-arg))))
3563 (setq n (if (numberp n) (mod n 26) 13)) ;canonize N
3564 (unless (or (zerop n) ; no action needed for a rot of 0
3565 (= b e)) ; no region to rotate
3566 ;; We build the table, if necessary.
3567 (when (or (not message-caesar-translation-table)
3568 (/= (aref message-caesar-translation-table ?a) (+ ?a n)))
3569 (setq message-caesar-translation-table
3570 (message-make-caesar-translation-table n)))
3571 (translate-region b e message-caesar-translation-table)))
3573 (defun message-make-caesar-translation-table (n)
3574 "Create a rot table with offset N."
3576 (table (make-string 256 0)))
3577 (while (< (incf i) 256)
3580 (substring table 0 ?A)
3581 (substring table (+ ?A n) (+ ?A n (- 26 n)))
3582 (substring table ?A (+ ?A n))
3583 (substring table (+ ?A 26) ?a)
3584 (substring table (+ ?a n) (+ ?a n (- 26 n)))
3585 (substring table ?a (+ ?a n))
3586 (substring table (+ ?a 26) 255))))
3588 (defun message-caesar-buffer-body (&optional rotnum wide)
3589 "Caesar rotate all letters in the current buffer by 13 places.
3590 Used to encode/decode possibly offensive messages (commonly in rec.humor).
3591 With prefix arg, specifies the number of places to rotate each letter forward.
3592 Mail and USENET news headers are not rotated unless WIDE is non-nil."
3593 (interactive (if current-prefix-arg
3594 (list (prefix-numeric-value current-prefix-arg))
3598 (when (and (not wide) (message-goto-body))
3599 (narrow-to-region (point) (point-max)))
3600 (message-caesar-region (point-min) (point-max) rotnum))))
3602 (defun message-pipe-buffer-body (program)
3603 "Pipe the message body in the current buffer through PROGRAM."
3606 (when (message-goto-body)
3607 (narrow-to-region (point) (point-max)))
3608 (shell-command-on-region
3609 (point-min) (point-max) program nil t))))
3611 (defun message-rename-buffer (&optional enter-string)
3612 "Rename the *message* buffer to \"*message* RECIPIENT\".
3613 If the function is run with a prefix, it will ask for a new buffer
3614 name, rather than giving an automatic name."
3615 (interactive "Pbuffer name: ")
3618 (goto-char (point-min))
3619 (narrow-to-region (point)
3620 (search-forward mail-header-separator nil 'end))
3622 (if (message-news-p) (message-fetch-field "Newsgroups")
3623 (message-fetch-field "To"))
3626 (if (string-match "," mail-to)
3627 (concat (substring mail-to 0 (match-beginning 0)) ", ...")
3629 (name-default (concat "*message* " mail-trimmed-to))
3630 (name (if enter-string
3631 (read-string "New buffer name: " name-default)
3633 (rename-buffer name t)))))
3635 (defun message-fill-yanked-message (&optional justifyp)
3636 "Fill the paragraphs of a message yanked into this one.
3637 Numeric argument means justify as well."
3640 (goto-char (point-min))
3641 (search-forward (concat "\n" mail-header-separator "\n") nil t)
3642 (let ((fill-prefix message-yank-prefix))
3643 (fill-individual-paragraphs (point) (point-max) justifyp))))
3645 (defun message-indent-citation (&optional start end yank-only)
3646 "Modify text just inserted from a message to be cited.
3647 The inserted text should be the region.
3648 When this function returns, the region is again around the modified text.
3650 Normally, indent each nonblank line `message-indentation-spaces' spaces.
3651 However, if `message-yank-prefix' is non-nil, insert that prefix on each line."
3652 (unless start (setq start (point)))
3654 ;; Remove unwanted headers.
3655 (when message-ignored-cited-headers
3660 (if (search-forward "\n\n" nil t)
3663 (message-remove-header message-ignored-cited-headers t)
3664 (when (= (point-min) (point-max))
3665 (setq all-removed t))
3666 (goto-char (point-max)))
3670 ;; Delete blank lines at the start of the buffer.
3671 (while (and (point-min)
3674 (message-delete-line))
3675 ;; Delete blank lines at the end of the buffer.
3676 (goto-char (point-max))
3677 (unless (eq (preceding-char) ?\n)
3679 (while (and (zerop (forward-line -1))
3681 (message-delete-line)))
3682 ;; Do the indentation.
3683 (if (null message-yank-prefix)
3684 (indent-rigidly start (or end (mark t)) message-indentation-spaces)
3687 (while (< (point) (or end (mark t)))
3688 (cond ((looking-at ">")
3689 (insert message-yank-cited-prefix))
3691 (insert message-yank-empty-prefix))
3693 (insert message-yank-prefix)))
3697 (defun message-remove-blank-cited-lines (&optional remove)
3698 "Remove cited lines containing only blanks.
3699 If REMOVE is non-nil, remove newlines, too.
3701 To use this automatically, you may add this function to
3702 `gnus-message-setup-hook'."
3704 (let ((citexp (concat "^\\("
3705 (concat message-yank-cited-prefix "\\|")
3708 (message "Removing `%s'" citexp)
3711 (while (re-search-forward citexp nil t)
3712 (replace-match (if remove "" "\n"))))))
3714 (defun message--yank-original-internal (arg)
3715 (let ((modified (buffer-modified-p))
3717 (when (and message-reply-buffer
3718 message-cite-function)
3719 (when (equal message-cite-reply-position 'above)
3722 (buffer-substring (message-goto-body)
3724 (delete-region (message-goto-body) (point-max))))
3725 (if (bufferp message-reply-buffer)
3726 (delete-windows-on message-reply-buffer t))
3727 (push-mark (save-excursion
3729 ((bufferp message-reply-buffer)
3730 (insert-buffer-substring message-reply-buffer))
3731 ((and (consp message-reply-buffer)
3732 (functionp (car message-reply-buffer)))
3733 (apply (car message-reply-buffer)
3734 (cdr message-reply-buffer))))
3739 (funcall message-cite-function)
3740 (unless (eq (char-before (mark t)) ?\n)
3742 (goto-char (mark t))
3743 (insert-before-markers ?\n)
3745 (case message-cite-reply-position
3749 (insert (if (bolp) "\n" "\n\n"))
3750 (message-goto-body))
3752 (message-goto-signature)))
3753 ;; Add a `message-setup-very-last-hook' here?
3754 ;; Add `gnus-article-highlight-citation' here?
3756 (setq message-checksum (message-checksum))))))
3758 (defun message-yank-original (&optional arg)
3759 "Insert the message being replied to, if any.
3760 Puts point before the text and mark after.
3761 Normally indents each nonblank line ARG spaces (default 3). However,
3762 if `message-yank-prefix' is non-nil, insert that prefix on each line.
3764 This function uses `message-cite-function' to do the actual citing.
3766 Just \\[universal-argument] as argument means don't indent, insert no
3767 prefix, and don't delete any headers."
3769 ;; eval the let forms contained in message-cite-style
3771 `(let ,(if (symbolp message-cite-style)
3772 (symbol-value message-cite-style)
3774 (message--yank-original-internal ',arg))))
3776 (defun message-yank-buffer (buffer)
3777 "Insert BUFFER into the current buffer and quote it."
3778 (interactive "bYank buffer: ")
3779 (let ((message-reply-buffer (get-buffer buffer)))
3780 (save-window-excursion
3781 (message-yank-original))))
3783 (defun message-buffers ()
3784 "Return a list of active message buffers."
3786 (save-current-buffer
3787 (dolist (buffer (buffer-list t))
3789 (when (and (derived-mode-p 'message-mode)
3790 (null message-sent-message-via))
3791 (push (buffer-name buffer) buffers))))
3792 (nreverse buffers)))
3794 (defun message-cite-original-1 (strip-signature)
3795 "Cite an original message.
3796 If STRIP-SIGNATURE is non-nil, strips off the signature from the
3799 This function uses `mail-citation-hook' if that is non-nil."
3800 (if (and (boundp 'mail-citation-hook)
3802 (run-hooks 'mail-citation-hook)
3803 (let* ((start (point))
3807 (when message-indent-citation-function
3808 (if (listp message-indent-citation-function)
3809 message-indent-citation-function
3810 (list message-indent-citation-function))))
3811 ;; This function may be called by `gnus-summary-yank-message' and
3812 ;; may insert a different article from the original. So, we will
3813 ;; modify the value of `message-reply-headers' with that article.
3814 (message-reply-headers
3816 (narrow-to-region start end)
3817 (message-narrow-to-head-1)
3818 (setq x-no-archive (message-fetch-field "x-no-archive"))
3820 (or (message-fetch-field "subject") "none")
3821 (or (message-fetch-field "from") "nobody")
3822 (message-fetch-field "date")
3823 (message-fetch-field "message-id" t)
3824 (message-fetch-field "references")
3826 (mml-quote-region start end)
3827 (when strip-signature
3831 (when (re-search-backward message-signature-separator start t)
3832 ;; Also peel off any blank lines before the signature.
3834 (while (looking-at "^[ \t]*$")
3837 (delete-region (point) end)
3838 (unless (search-backward "\n\n" start t)
3839 ;; Insert a blank line if it is peeled off.
3842 (mapc 'funcall functions)
3843 (when message-citation-line-function
3846 (funcall message-citation-line-function))
3847 (when (and x-no-archive
3848 (not message-cite-articles-with-x-no-archive)
3849 (string-match "yes" x-no-archive))
3851 (delete-region (point) (mark t))
3852 (insert "> [Quoted text removed due to X-No-Archive]\n")
3854 (forward-line -1)))))
3856 (defun message-cite-original ()
3857 "Cite function in the standard Message manner."
3858 (message-cite-original-1 nil))
3860 (autoload 'format-spec "format-spec")
3861 (autoload 'gnus-date-get-time "gnus-util")
3863 (defun message-insert-formatted-citation-line (&optional from date tz)
3864 "Function that inserts a formatted citation line.
3865 The optional FROM, and DATE are strings containing the contents of
3866 the From header and the Date header respectively.
3868 The optional TZ is omitted or nil for Emacs local time, t for
3869 Universal Time, `wall' for system wall clock time, or a string as
3870 in the TZ environment variable. It can also be a list (as from
3871 `current-time-zone') or an integer (as from `decode-time')
3872 applied without consideration for daylight saving time.
3874 See `message-citation-line-format'."
3875 ;; The optional args are for testing/debugging. They will disappear later.
3877 ;; (with-temp-buffer
3878 ;; (message-insert-formatted-citation-line
3879 ;; "John Doe <john.doe@example.invalid>"
3880 ;; (message-make-date))
3882 (when (or message-reply-headers (and from date))
3884 (setq from (mail-header-from message-reply-headers)))
3885 (let* ((data (condition-case ()
3886 (funcall (if (boundp 'gnus-extract-address-components)
3887 gnus-extract-address-components
3888 'mail-extract-address-components)
3894 (net (car (cdr data)))
3895 (name-or-net (or (car data)
3896 (car (cdr data)) from))
3898 (when (string-match "%[^fnNFL]" message-citation-line-format)
3899 (cond ((numberp (car-safe date)) date) ;; backward compatibility
3900 (date (gnus-date-get-time date))
3903 (setq date (mail-header-date message-reply-headers)))))))
3905 (when (stringp date)
3906 (nth 8 (parse-time-string date)))))
3909 (when (stringp name)
3910 ;; Guess first name and last name:
3915 (if (string-match "\\`\\(\\w\\|[-.]\\)+\\'"
3919 (split-string name "[ \t]+"))))
3920 (count (length names)))
3922 (setq fname (car names)
3924 ((or (= count 2) (= count 3))
3925 (setq fname (car names)
3926 lname (mapconcat 'identity (cdr names) " ")))
3928 (setq fname (mapconcat 'identity
3929 (butlast names (- count 2))
3931 lname (mapconcat 'identity
3934 (when (string-match "\\(.*\\),\\'" fname)
3935 (let ((newlname (match-string 1 fname)))
3936 (setq fname lname lname newlname)))))
3937 ;; The following letters are not used in `format-time-string':
3938 (push ?E lst) (push "<E>" lst)
3939 (push ?F lst) (push (or fname name-or-net) lst)
3940 ;; We might want to use "" instead of "<X>" later.
3941 (push ?J lst) (push "<J>" lst)
3942 (push ?K lst) (push "<K>" lst)
3943 (push ?L lst) (push lname lst)
3944 (push ?N lst) (push name-or-net lst)
3945 (push ?O lst) (push "<O>" lst)
3946 (push ?P lst) (push "<P>" lst)
3947 (push ?Q lst) (push "<Q>" lst)
3948 (push ?f lst) (push from lst)
3949 (push ?i lst) (push "<i>" lst)
3950 (push ?n lst) (push net lst)
3951 (push ?o lst) (push "<o>" lst)
3952 (push ?q lst) (push "<q>" lst)
3953 (push ?t lst) (push "<t>" lst)
3954 (push ?v lst) (push "<v>" lst)
3955 ;; Delegate the rest to `format-time-string':
3957 (when (and (not (memq i lst))
3962 (push (condition-case nil
3963 (format-time-string (format "%%%c" i) time tz)
3964 (error (format ">%c<" i)))
3968 (spec (apply 'format-spec-make flist)))
3969 (insert (format-spec message-citation-line-format spec)))
3972 (defun message-cite-original-without-signature ()
3973 "Cite function in the standard Message manner.
3974 This function strips off the signature from the original message."
3975 (message-cite-original-1 t))
3977 (defun message-insert-citation-line ()
3978 "Insert a simple citation line."
3979 (when message-reply-headers
3980 (insert (mail-header-from message-reply-headers) " writes:")
3984 (defun message-position-on-field (header &rest afters)
3985 (let ((case-fold-search t))
3988 (goto-char (point-min))
3991 (concat "^" (regexp-quote mail-header-separator) "$"))
3992 (match-beginning 0)))
3993 (goto-char (point-min))
3994 (if (re-search-forward (concat "^" (regexp-quote header) ":") nil t)
3996 (re-search-forward "^[^ \t]" nil 'move)
3998 (skip-chars-backward "\n")
4001 (not (re-search-forward
4002 (concat "^" (regexp-quote (car afters)) ":")
4006 (re-search-forward "^[^ \t]" nil 'move)
4007 (beginning-of-line))
4008 (insert header ": \n")
4015 ;;; Sending messages
4018 (defun message-send-and-exit (&optional arg)
4019 "Send message like `message-send', then, if no errors, exit from mail buffer.
4020 The usage of ARG is defined by the instance that called Message.
4021 It should typically alter the sending method in some way or other."
4023 (let ((buf (current-buffer))
4024 (actions message-exit-actions))
4025 (when (and (message-send arg)
4028 (if message-kill-buffer-on-exit
4030 (message-do-actions actions)
4033 (defun message-dont-send ()
4034 "Don't send the message you have been editing.
4035 Instead, just auto-save the buffer and then bury it."
4037 (set-buffer-modified-p t)
4039 (let ((actions message-postpone-actions))
4040 (message-bury (current-buffer))
4041 (message-do-actions actions)))
4043 (defun message-kill-buffer ()
4044 "Kill the current buffer."
4046 (when (or (not (buffer-modified-p))
4047 (not message-kill-buffer-query)
4048 (yes-or-no-p "Message modified; kill anyway? "))
4049 (let ((actions message-kill-actions)
4050 (draft-article message-draft-article)
4051 (auto-save-file-name buffer-auto-save-file-name)
4052 (file-name buffer-file-name)
4053 (modified (buffer-modified-p)))
4054 (setq buffer-file-name nil)
4055 (kill-buffer (current-buffer))
4056 (when (and (or (and auto-save-file-name
4057 (file-exists-p auto-save-file-name))
4059 (file-exists-p file-name)))
4061 ;; If the message buffer has lived in a dedicated window,
4062 ;; `kill-buffer' has killed the frame. Thus the
4063 ;; `yes-or-no-p' may show up in a lowered frame. Make sure
4064 ;; that the user can see the question by raising the
4067 (yes-or-no-p (format "Remove the backup file%s? "
4068 (if modified " too" "")))))
4070 (delete-file auto-save-file-name))
4071 (let ((message-draft-article draft-article))
4072 (message-disassociate-draft)))
4073 (message-do-actions actions))))
4075 (defun message-bury (buffer)
4076 "Bury this mail BUFFER."
4077 ;; Note that this is not quite the same as (bury-buffer buffer),
4078 ;; since bury-buffer does extra stuff with a nil argument.
4079 ;; Eg http://lists.gnu.org/archive/html/emacs-devel/2014-01/msg00539.html
4080 (with-current-buffer buffer (bury-buffer))
4081 (if message-return-action
4082 (apply (car message-return-action) (cdr message-return-action))))
4084 (autoload 'mml-secure-bcc-is-safe "mml-sec")
4086 (defun message-send (&optional arg)
4087 "Send the message in the current buffer.
4088 If `message-interactive' is non-nil, wait for success indication or
4089 error messages, and inform user.
4090 Otherwise any failure is reported in a message back to the user from
4092 The usage of ARG is defined by the instance that called Message.
4093 It should typically alter the sending method in some way or other."
4095 ;; Make it possible to undo the coming changes.
4097 (let ((inhibit-read-only t))
4098 (put-text-property (point-min) (point-max) 'read-only nil))
4099 (message-fix-before-sending)
4100 (mml-secure-bcc-is-safe)
4101 (run-hooks 'message-send-hook)
4102 (when message-confirm-send
4103 (or (y-or-n-p "Send message? ")
4105 (message message-sending-message)
4106 (let ((alist message-send-method-alist)
4108 elem sent dont-barf-on-no-method
4109 (message-options message-options))
4110 (message-options-set-recipient)
4112 (setq elem (pop alist)))
4113 (when (funcall (cadr elem))
4114 (when (and (or (not (memq (car elem)
4115 message-sent-message-via))
4116 (message-fetch-field "supersedes")
4117 (if (or (message-gnksa-enable-p 'multiple-copies)
4118 (not (eq (car elem) 'news)))
4121 "Already sent message via %s; resend? "
4123 (error "Denied posting -- multiple copies")))
4124 (setq success (funcall (caddr elem) arg)))
4128 (let ((fcc (message-fetch-field "Fcc"))
4129 (gcc (message-fetch-field "Gcc")))
4131 (or (eq message-allow-no-recipients 'always)
4132 (and (not (eq message-allow-no-recipients 'never))
4133 (setq dont-barf-on-no-method
4135 (format "No receiver, perform %s anyway? "
4136 (cond ((and fcc gcc) "Fcc and Gcc")
4139 (error "No methods specified to send by"))
4140 (when (or dont-barf-on-no-method
4144 (run-hooks 'message-sent-hook))
4145 (message "Sending...done")
4146 ;; Do ecomplete address snarfing.
4147 (when (and (message-mail-alias-type-p 'ecomplete)
4148 (not message-inhibit-ecomplete))
4149 (message-put-addresses-in-ecomplete))
4150 ;; Mark the buffer as unmodified and delete auto-save.
4151 (set-buffer-modified-p nil)
4152 (delete-auto-save-file-if-necessary t)
4153 (message-disassociate-draft)
4154 ;; Delete other mail buffers and stuff.
4155 (message-do-send-housekeeping)
4156 (message-do-actions message-send-actions)
4160 (defun message-send-via-mail (arg)
4161 "Send the current message via mail."
4162 (message-send-mail arg))
4164 (defun message-send-via-news (arg)
4165 "Send the current message via news."
4166 (funcall message-send-news-function arg))
4168 (defmacro message-check (type &rest forms)
4169 "Eval FORMS if TYPE is to be checked."
4170 `(or (message-check-element ,type)
4174 (put 'message-check 'lisp-indent-function 1)
4175 (put 'message-check 'edebug-form-spec '(form body))
4177 (defun message-text-with-property (prop &optional start end reverse)
4178 "Return a list of start and end positions where the text has PROP.
4179 START and END bound the search, they default to `point-min' and
4180 `point-max' respectively. If REVERSE is non-nil, find text which does
4183 (setq start (point-min)))
4185 (setq end (point-max)))
4189 (setq start (text-property-any start end prop nil)))
4190 (setq next (next-single-property-change start prop nil end))
4191 (push (cons start (or next end)) regions)
4194 (or (get-text-property start prop)
4195 (and (setq start (next-single-property-change
4196 start prop nil end))
4197 (get-text-property start prop))))
4198 (setq next (text-property-any start end prop nil))
4199 (push (cons start (or next end)) regions)
4201 (nreverse regions)))
4203 (defcustom message-bogus-addresses
4204 '("noreply" "nospam" "invalid" "@@" "[^[:ascii:]].*@" "[ \t]")
4205 "List of regexps of potentially bogus mail addresses.
4206 See `message-check-recipients' how to setup checking.
4208 This list should make it possible to catch typos or warn about
4209 spam-trap addresses. It doesn't aim to verify strict RFC
4211 :version "23.1" ;; No Gnus
4212 :group 'message-headers
4214 (const :tag "None" nil)
4220 (const :tag "duplicate @" "@@")
4221 (const :tag "non-ascii local part" "[^[:ascii:]].*@")
4222 (const :tag "`_' in domain part" "@.*_")
4223 (const :tag "whitespace" "[ \t]"))
4228 (defun message-fix-before-sending ()
4229 "Do various things to make the message nice before sending it."
4230 ;; Make sure there's a newline at the end of the message.
4231 (goto-char (point-max))
4234 ;; Make the hidden headers visible.
4236 ;; Sort headers before sending the message.
4237 (message-sort-headers)
4238 ;; Make invisible text visible.
4239 ;; It doesn't seem as if this is useful, since the invisible property
4240 ;; is clobbered by an after-change hook anyhow.
4241 (message-check 'invisible-text
4242 (let ((regions (message-text-with-property 'invisible))
4246 (setq from (caar regions)
4248 regions (cdr regions))
4249 (put-text-property from to 'invisible nil)
4250 (overlay-put (make-overlay from to) 'face 'highlight))
4251 (unless (yes-or-no-p
4252 "Invisible text found and made visible; continue sending? ")
4253 (error "Invisible text found and made visible")))))
4254 (message-check 'illegible-text
4255 (let (char found choice nul-chars)
4257 (setq nul-chars (save-excursion
4258 (search-forward "\000" nil t)))
4260 (skip-chars-forward mm-7bit-chars)
4261 (when (get-text-property (point) 'no-illegible-text)
4262 ;; There is a signed or encrypted raw message part
4263 ;; that is considered to be safe.
4264 (goto-char (or (next-single-property-change
4265 (point) 'no-illegible-text)
4267 (setq char (char-after)))
4268 (when (or (< char 128)
4269 (and (mm-multibyte-p)
4270 (memq (char-charset char)
4271 '(eight-bit-control eight-bit-graphic
4272 ;; Emacs 23, Bug#1770:
4275 (not (get-text-property
4276 (point) 'untranslated-utf-8))))
4277 (overlay-put (make-overlay (point) (1+ (point))) 'face 'highlight)
4283 (read-multiple-choice
4285 "NUL characters found, which may cause problems. Continue sending?"
4286 "Non-printable characters found. Continue sending?")
4287 `((?d "delete" "Remove non-printable characters and send")
4290 "Replace non-printable characters with \"%s\" and send"
4291 message-replacement-char))
4292 (?s "send" "Send as is without removing anything")
4293 (?e "edit" "Continue editing")))))
4295 (error "Non-printable characters"))
4297 (skip-chars-forward mm-7bit-chars)
4299 (when (let ((char (char-after)))
4301 (and (mm-multibyte-p)
4302 ;; FIXME: Wrong for Emacs 23 (unicode) and for
4303 ;; things like undecodable utf-8 (in Emacs 21?).
4304 ;; Should at least use find-coding-systems-region.
4306 (memq (char-charset char)
4307 '(eight-bit-control eight-bit-graphic
4308 ;; Emacs 23, Bug#1770:
4311 (not (get-text-property
4312 (point) 'untranslated-utf-8)))))
4314 (message-kill-all-overlays)
4316 (when (eq choice ?r)
4317 (insert message-replacement-char))))
4319 (skip-chars-forward mm-7bit-chars)))))
4320 (message-check 'bogus-recipient
4321 ;; Warn before sending a mail to an invalid address.
4322 (message-check-recipients)))
4324 (defun message-bogus-recipient-p (recipients)
4325 "Check if a mail address in RECIPIENTS looks bogus.
4327 RECIPIENTS is a mail header. Return a list of potentially bogus
4328 addresses. If none is found, return nil.
4330 An address might be bogus if if there's a matching entry in
4331 `message-bogus-addresses'."
4332 ;; FIXME: How about "foo@subdomain", when the MTA adds ".domain.tld"?
4334 (mapc (lambda (address)
4335 (setq address (or (cadr address) ""))
4336 (when (or (string= "" address)
4337 (not (string-match "@" address))
4338 (string-match "@.*@" address)
4339 (and message-bogus-addresses
4341 (if (listp message-bogus-addresses)
4342 (mapconcat 'identity
4343 message-bogus-addresses
4345 message-bogus-addresses)))
4346 (string-match re address))))
4347 (push address found)))
4348 (mail-extract-address-components recipients t))
4351 (defun message-check-recipients ()
4352 "Warn before composing or sending a mail to an invalid address.
4354 This function could be useful in `message-setup-hook'."
4357 (message-narrow-to-headers)
4358 (dolist (hdr '("To" "Cc" "Bcc"))
4359 (let ((addr (message-fetch-field hdr)))
4360 (when (stringp addr)
4361 (dolist (bog (message-bogus-recipient-p addr))
4365 "Address `%s'%s might be bogus. Continue? "
4367 ;; If the encoded version of the email address
4368 ;; is different from the unencoded version,
4369 ;; then we likely have invisible characters or
4370 ;; the like. Display the encoded version,
4372 (let ((encoded (rfc2047-encode-string bog)))
4373 (if (string= encoded bog)
4375 (format " (%s)" encoded))))))
4376 (error "Bogus address"))))))))
4378 (custom-add-option 'message-setup-hook 'message-check-recipients)
4380 (defun message-add-action (action &rest types)
4381 "Add ACTION to be performed when doing an exit of type TYPES."
4383 (add-to-list (intern (format "message-%s-actions" (pop types)))
4386 (defun message-delete-action (action &rest types)
4387 "Delete ACTION from lists of actions performed when doing an exit of type TYPES."
4390 (set (setq var (intern (format "message-%s-actions" (pop types))))
4391 (delq action (symbol-value var))))))
4393 (defun message-do-actions (actions)
4394 "Perform all actions in ACTIONS."
4395 ;; Now perform actions on successful sending.
4396 (dolist (action actions)
4399 ;; A simple function.
4402 ;; Something to be evalled.
4406 (defun message-send-mail-partially ()
4407 "Send mail as message/partial."
4408 ;; replace the header delimiter with a blank line
4409 (goto-char (point-min))
4411 (concat "^" (regexp-quote mail-header-separator) "\n"))
4412 (replace-match "\n")
4413 (run-hooks 'message-send-mail-hook)
4414 (let ((p (goto-char (point-min)))
4415 (tembuf (message-generate-new-buffer-clone-locals " message temp"))
4416 (curbuf (current-buffer))
4417 (id (message-make-message-id)) (n 1)
4420 (if (< (point-max) (+ p message-send-mail-partially-limit))
4421 (goto-char (point-max))
4422 (goto-char (+ p message-send-mail-partially-limit))
4424 (if (<= (point) p) (forward-line 1))) ;; In case of bad message.
4427 (setq total (length plist))
4428 (push (point-max) plist)
4429 (setq plist (nreverse plist))
4432 (setq p (pop plist))
4435 (copy-to-buffer tembuf p (car plist))
4437 (goto-char (point-min))
4440 (goto-char (point-min))
4441 (narrow-to-region (point) (point))
4444 (setq header (buffer-substring (point-min) (point)))
4445 (goto-char (point-min))
4446 (narrow-to-region (point) (point))
4448 (message-remove-header "Mime-Version")
4449 (message-remove-header "Content-Type")
4450 (message-remove-header "Content-Transfer-Encoding")
4451 (message-remove-header "Message-ID")
4452 (message-remove-header "Lines")
4453 (goto-char (point-max))
4454 (insert "Mime-Version: 1.0\n")
4455 (setq header (buffer-string)))
4456 (goto-char (point-max))
4457 (insert (format "Content-Type: message/partial; id=\"%s\"; number=%d; total=%d\n\n"
4460 (let ((mail-header-separator ""))
4461 (when (memq 'Message-ID message-required-mail-headers)
4462 (insert "Message-ID: " (message-make-message-id) "\n"))
4463 (when (memq 'Lines message-required-mail-headers)
4464 (insert "Lines: " (message-make-lines) "\n"))
4465 (message-goto-subject)
4467 (insert (format " (%d/%d)" n total))
4469 (if message-send-mail-real-function
4470 (funcall message-send-mail-real-function)
4471 (message-multi-smtp-send-mail)))
4473 (setq p (pop plist))
4475 (kill-buffer tembuf))))
4477 (declare-function hashcash-wait-async "hashcash" (&optional buffer))
4479 (defun message-send-mail (&optional arg)
4480 (require 'mail-utils)
4481 (let* ((tembuf (message-generate-new-buffer-clone-locals " message temp"))
4482 (case-fold-search nil)
4483 (news (message-news-p))
4484 (mailbuf (current-buffer))
4485 (message-this-is-mail t)
4486 ;; gnus-setup-posting-charset is autoloaded in mml.el (FIXME
4487 ;; maybe it should not be), which this file requires. Hence
4488 ;; the fboundp test is always true. Loading it from gnus-msg
4489 ;; loads many Gnus files (Bug#5642). If
4490 ;; gnus-group-posting-charset-alist hasn't been customized,
4491 ;; this is just going to return nil anyway. FIXME it would
4492 ;; be good to improve this further, because even if g-g-p-c-a
4493 ;; has been customized, that is likely to just be for news.
4494 ;; Eg either move the definition from gnus-msg, or separate out
4495 ;; the mail and news parts.
4496 (message-posting-charset
4497 (if (and (fboundp 'gnus-setup-posting-charset)
4498 (boundp 'gnus-group-posting-charset-alist))
4499 (gnus-setup-posting-charset nil)
4500 message-posting-charset))
4501 (headers message-required-mail-headers)
4503 (when (and message-generate-hashcash
4504 (not (eq message-generate-hashcash 'opportunistic)))
4505 (message "Generating hashcash...")
4507 ;; Wait for calculations already started to finish...
4508 (hashcash-wait-async)
4509 ;; ...and do calculations not already done. mail-add-payment
4510 ;; will leave existing X-Hashcash headers alone.
4512 (message "Generating hashcash...done"))
4514 (message-narrow-to-headers)
4515 ;; Generate the Mail-Followup-To header if the header is not there...
4516 (if (and (message-subscribed-p)
4517 (not (mail-fetch-field "mail-followup-to")))
4520 (cons "Mail-Followup-To" (message-make-mail-followup-to))
4521 message-required-mail-headers))
4522 ;; otherwise, delete the MFT header if the field is empty
4523 (when (equal "" (mail-fetch-field "mail-followup-to"))
4524 (message-remove-header "^Mail-Followup-To:")))
4525 ;; Insert some headers.
4526 (let ((message-deletable-headers
4527 (if news nil message-deletable-headers)))
4528 (message-generate-headers headers))
4529 ;; Check continuation headers.
4530 (message-check 'continuation-headers
4531 (goto-char (point-min))
4532 (while (re-search-forward "^[^ \t\n][^ \t\n:]*[ \t\n]" nil t)
4533 (goto-char (match-beginning 0))
4534 (if (y-or-n-p "Fix continuation lines? ")
4537 (unless (y-or-n-p "Send anyway? ")
4538 (error "Failed to send the message")))))
4539 ;; Let the user do all of the above.
4540 (run-hooks 'message-header-hook))
4541 (setq options message-options)
4543 (with-current-buffer tembuf
4545 (setq message-options options)
4546 ;; Avoid copying text props (except hard newlines).
4547 (insert (with-current-buffer mailbuf
4548 (mml-buffer-substring-no-properties-except-hard-newlines
4549 (point-min) (point-max))))
4550 ;; Remove some headers.
4551 (message-encode-message-body)
4553 (message-narrow-to-headers)
4554 ;; We (re)generate the Lines header.
4555 (when (memq 'Lines message-required-mail-headers)
4556 (message-generate-headers '(Lines)))
4557 ;; Remove some headers.
4558 (message-remove-header message-ignored-mail-headers t)
4559 (let ((mail-parse-charset message-default-charset))
4560 (mail-encode-encoded-word-buffer)))
4561 (goto-char (point-max))
4562 ;; require one newline at the end.
4563 (or (= (preceding-char) ?\n)
4565 (message-cleanup-headers)
4566 ;; FIXME: we're inserting the courtesy copy after encoding.
4567 ;; This is wrong if the courtesy copy string contains
4568 ;; non-ASCII characters. -- jh
4571 (message-narrow-to-headers)
4573 (not (message-fetch-field "List-Post"))
4574 (not (message-fetch-field "List-ID"))
4575 (or (message-fetch-field "cc")
4576 (message-fetch-field "bcc")
4577 (message-fetch-field "to"))
4578 (let ((content-type (message-fetch-field
4583 (string= "text/plain"
4585 (mail-header-parse-content-type
4589 (message-fetch-field
4590 "content-transfer-encoding")))))))
4591 (message-insert-courtesy-copy
4592 (with-current-buffer mailbuf
4593 message-courtesy-message)))
4594 ;; Let's make sure we encoded all the body.
4595 (assert (save-excursion
4596 (goto-char (point-min))
4597 (not (re-search-forward "[^\000-\377]" nil t))))
4598 (mm-disable-multibyte)
4599 (if (or (not message-send-mail-partially-limit)
4600 (< (buffer-size) message-send-mail-partially-limit)
4601 (not (message-y-or-n-p
4602 "The message size is too large, split? "
4606 (/ (buffer-size) 1000) "KB, is too large.
4608 Some mail gateways (MTA's) bounce large messages. To avoid the
4609 problem, answer `y', and the message will be split into several
4610 smaller pieces, the size of each is about "
4611 (/ message-send-mail-partially-limit 1000)
4615 However, some mail readers (MUA's) can't read split messages, i.e.,
4616 mails in message/partially format. Answer `n', and the message will be
4619 The size limit is controlled by `message-send-mail-partially-limit'.
4620 If you always want Gnus to send messages in one piece, set
4621 `message-send-mail-partially-limit' to nil.
4624 (message "Sending via mail...")
4625 (if message-send-mail-real-function
4626 (funcall message-send-mail-real-function)
4627 (message-multi-smtp-send-mail)))
4628 (message-send-mail-partially))
4629 (setq options message-options))
4630 (kill-buffer tembuf))
4631 (set-buffer mailbuf)
4632 (setq message-options options)
4633 (push 'mail message-sent-message-via)))
4635 (defvar sendmail-program)
4636 (defvar smtpmail-smtp-user)
4638 (defun message-multi-smtp-send-mail ()
4639 "Send the current buffer to `message-send-mail-function'.
4640 Or, if there's a header that specifies a different method, use
4642 (let ((method (message-field-value "X-Message-SMTP-Method")))
4644 (funcall message-send-mail-function)
4645 (message-remove-header "X-Message-SMTP-Method")
4646 (setq method (split-string method))
4648 ((equal (car method) "sendmail")
4649 (message-send-mail-with-sendmail))
4650 ((equal (car method) "smtp")
4652 (let ((smtpmail-smtp-server (nth 1 method))
4653 (smtpmail-smtp-service (nth 2 method))
4654 (smtpmail-smtp-user (or (nth 3 method) smtpmail-smtp-user)))
4655 (message-smtpmail-send-it)))
4657 (error "Unknown method %s" method))))))
4659 (defun message-send-mail-with-sendmail ()
4660 "Send off the prepared buffer with sendmail."
4662 (let ((errbuf (if message-interactive
4663 (message-generate-new-buffer-clone-locals
4666 resend-to-addresses delimline)
4669 (let ((case-fold-search t))
4671 (message-narrow-to-headers)
4672 (setq resend-to-addresses (message-fetch-field "resent-to")))
4673 ;; Change header-delimiter to be what sendmail expects.
4674 (goto-char (point-min))
4676 (concat "^" (regexp-quote mail-header-separator) "\n"))
4677 (replace-match "\n")
4679 (setq delimline (point-marker))
4680 (run-hooks 'message-send-mail-hook)
4681 ;; Insert an extra newline if we need it to work around
4682 ;; Sun's bug that swallows newlines.
4683 (goto-char (1+ delimline))
4684 (when (eval message-mailer-swallows-blank-line)
4686 (when message-interactive
4687 (with-current-buffer errbuf
4689 (let* ((default-directory "/")
4690 (coding-system-for-write message-send-coding-system)
4692 'call-process-region
4694 (list (point-min) (point-max) sendmail-program
4695 nil errbuf nil "-oi")
4696 message-sendmail-extra-arguments
4697 ;; Always specify who from,
4698 ;; since some systems have broken sendmails.
4699 ;; But some systems are more broken with -f, so
4700 ;; we'll let users override this.
4701 (and (null message-sendmail-f-is-evil)
4702 (list "-f" (message-sendmail-envelope-from)))
4703 ;; These mean "report errors by mail"
4704 ;; and "deliver in background".
4705 (if (null message-interactive) '("-oem" "-odb"))
4706 ;; Get the addresses from the message
4707 ;; unless this is a resend.
4708 ;; We must not do that for a resend
4709 ;; because we would find the original addresses.
4710 ;; For a resend, include the specific addresses.
4711 (if resend-to-addresses
4712 (list resend-to-addresses)
4714 (unless (or (null cpr) (and (numberp cpr) (zerop cpr)))
4716 (pop-to-buffer errbuf)
4718 (error "Sending...failed with exit value %d" cpr)))
4719 (when message-interactive
4720 (with-current-buffer errbuf
4721 (goto-char (point-min))
4722 (while (re-search-forward "\n+ *" nil t)
4723 (replace-match "; "))
4724 (if (not (zerop (buffer-size)))
4725 (error "Sending...failed to %s"
4726 (buffer-string))))))
4727 (when (bufferp errbuf)
4728 (kill-buffer errbuf)))))
4730 (defun message-send-mail-with-qmail ()
4731 "Pass the prepared message buffer to qmail-inject.
4732 Refer to the documentation for the variable `message-send-mail-function'
4733 to find out how to use this."
4734 ;; replace the header delimiter with a blank line
4735 (goto-char (point-min))
4737 (concat "^" (regexp-quote mail-header-separator) "\n"))
4738 (replace-match "\n")
4739 (run-hooks 'message-send-mail-hook)
4742 (let ((coding-system-for-write message-send-coding-system))
4744 'call-process-region (point-min) (point-max)
4745 message-qmail-inject-program nil nil nil
4746 ;; qmail-inject's default behavior is to look for addresses on the
4747 ;; command line; if there're none, it scans the headers.
4748 ;; yes, it does The Right Thing w.r.t. Resent-To and it's kin.
4750 ;; in general, ALL of qmail-inject's defaults are perfect for simply
4751 ;; reading a formatted (i. e., at least a To: or Resent-To header)
4752 ;; message from stdin.
4754 ;; qmail also has the advantage of not having been raped by
4755 ;; various vendors, so we don't have to allow for that, either --
4756 ;; compare this with message-send-mail-with-sendmail and weep
4757 ;; for sendmail's lost innocence.
4759 ;; all this is way cool coz it lets us keep the arguments entirely
4760 ;; free for -inject-arguments -- a big win for the user and for us
4761 ;; since we don't have to play that double-guessing game and the user
4762 ;; gets full control (no gestapo'ish -f's, for instance). --sj
4763 (if (functionp message-qmail-inject-args)
4764 (funcall message-qmail-inject-args)
4765 message-qmail-inject-args)))
4766 ;; qmail-inject doesn't say anything on it's stdout/stderr,
4767 ;; we have to look at the retval instead
4769 (100 (error "qmail-inject reported permanent failure"))
4770 (111 (error "qmail-inject reported transient failure"))
4771 ;; should never happen
4772 (t (error "qmail-inject reported unknown failure"))))
4774 (defvar mh-previous-window-config)
4776 (defun message-send-mail-with-mh ()
4777 "Send the prepared message buffer with mh."
4778 (let ((mh-previous-window-config nil)
4779 (name (mh-new-draft-name)))
4780 (setq buffer-file-name name)
4781 ;; MH wants to generate these headers itself.
4782 (when message-mh-deletable-headers
4783 (let ((headers message-mh-deletable-headers))
4785 (goto-char (point-min))
4786 (and (re-search-forward
4787 (concat "^" (symbol-name (car headers)) ": *") nil t)
4788 (message-delete-line))
4790 (run-hooks 'message-send-mail-hook)
4791 ;; Pass it on to mh.
4794 (defun message-smtpmail-send-it ()
4795 "Send the prepared message buffer with `smtpmail-send-it'.
4796 The only difference from `smtpmail-send-it' is that this command
4797 evaluates `message-send-mail-hook' just before sending a message.
4798 It is useful if your ISP requires the POP-before-SMTP
4799 authentication. See the Gnus manual for details."
4800 (run-hooks 'message-send-mail-hook)
4801 ;; Change header-delimiter to be what smtpmail expects.
4802 (goto-char (point-min))
4803 (when (re-search-forward
4804 (concat "^" (regexp-quote mail-header-separator) "\n"))
4805 (replace-match "\n"))
4808 (defun message-send-mail-with-mailclient ()
4809 "Send the prepared message buffer with `mailclient-send-it'.
4810 The only difference from `mailclient-send-it' is that this
4811 command evaluates `message-send-mail-hook' just before sending a message."
4812 (run-hooks 'message-send-mail-hook)
4813 (mailclient-send-it))
4815 (defun message-canlock-generate ()
4816 "Return a string that is non-trivial to guess.
4817 Do not use this for anything important, it is cryptographically weak."
4819 (let (sha1-maximum-internal-length)
4820 (sha1 (concat (message-unique-id)
4821 (format "%x%x%x" (random) (random) (random))
4822 (prin1-to-string (recent-keys))
4823 (prin1-to-string (garbage-collect))))))
4825 (defvar canlock-password)
4826 (defvar canlock-password-for-verify)
4828 (defun message-canlock-password ()
4829 "The password used by message for cancel locks.
4830 This is the value of `canlock-password', if that option is non-nil.
4831 Otherwise, generate and save a value for `canlock-password' first."
4833 (unless canlock-password
4834 (customize-save-variable 'canlock-password (message-canlock-generate))
4835 (setq canlock-password-for-verify canlock-password))
4838 (defun message-insert-canlock ()
4839 (when message-insert-canlock
4840 (message-canlock-password)
4841 (canlock-insert-header)))
4843 (autoload 'nnheader-get-report "nnheader")
4845 (declare-function gnus-setup-posting-charset "gnus-msg" (group))
4847 (defun message-send-news (&optional arg)
4849 (let* ((tembuf (message-generate-new-buffer-clone-locals " *message temp*"))
4850 (case-fold-search nil)
4851 (method (if (functionp message-post-method)
4852 (funcall message-post-method arg)
4853 message-post-method))
4854 (newsgroups-field (save-restriction
4855 (message-narrow-to-headers-or-head)
4856 (message-fetch-field "Newsgroups")))
4857 (followup-field (save-restriction
4858 (message-narrow-to-headers-or-head)
4859 (message-fetch-field "Followup-To")))
4860 ;; BUG: We really need to get the charset for each name in the
4861 ;; Newsgroups and Followup-To lines to allow crossposting
4862 ;; between group names with incompatible character sets.
4863 ;; -- Per Abrahamsen <abraham@dina.kvl.dk> 2001-10-08.
4864 (group-field-charset
4865 (gnus-group-name-charset method newsgroups-field))
4866 (followup-field-charset
4867 (gnus-group-name-charset method (or followup-field "")))
4868 (rfc2047-header-encoding-alist
4869 (append (when group-field-charset
4870 (list (cons "Newsgroups" group-field-charset)))
4871 (when followup-field-charset
4872 (list (cons "Followup-To" followup-field-charset)))
4873 rfc2047-header-encoding-alist))
4874 (messbuf (current-buffer))
4875 (message-syntax-checks
4877 (listp message-syntax-checks))
4878 (cons '(existing-newsgroups . disabled)
4879 message-syntax-checks)
4880 message-syntax-checks))
4881 (message-this-is-news t)
4882 (message-posting-charset
4883 (gnus-setup-posting-charset newsgroups-field))
4885 (if (not (message-check-news-body-syntax))
4888 (message-narrow-to-headers)
4889 ;; Insert some headers.
4890 (message-generate-headers message-required-news-headers)
4891 (message-insert-canlock)
4892 ;; Let the user do all of the above.
4893 (run-hooks 'message-header-hook))
4894 ;; Note: This check will be disabled by the ".*" default value for
4895 ;; gnus-group-name-charset-group-alist. -- Pa 2001-10-07.
4896 (when (and group-field-charset
4897 (listp message-syntax-checks))
4898 (setq message-syntax-checks
4899 (cons '(valid-newsgroups . disabled)
4900 message-syntax-checks)))
4901 (message-cleanup-headers)
4902 (if (not (let ((message-post-method method))
4903 (message-check-news-syntax)))
4906 (with-current-buffer tembuf
4907 (buffer-disable-undo)
4909 ;; Avoid copying text props (except hard newlines).
4911 (with-current-buffer messbuf
4912 (mml-buffer-substring-no-properties-except-hard-newlines
4913 (point-min) (point-max))))
4914 (message-encode-message-body)
4915 ;; Remove some headers.
4917 (message-narrow-to-headers)
4918 ;; We (re)generate the Lines header.
4919 (when (memq 'Lines message-required-mail-headers)
4920 (message-generate-headers '(Lines)))
4921 ;; Remove some headers.
4922 (message-remove-header message-ignored-news-headers t)
4923 (let ((mail-parse-charset message-default-charset))
4924 (mail-encode-encoded-word-buffer)))
4925 (goto-char (point-max))
4926 ;; require one newline at the end.
4927 (or (= (preceding-char) ?\n)
4929 (let ((case-fold-search t))
4930 ;; Remove the delimiter.
4931 (goto-char (point-min))
4933 (concat "^" (regexp-quote mail-header-separator) "\n"))
4934 (replace-match "\n")
4936 (run-hooks 'message-send-news-hook)
4937 (gnus-open-server method)
4938 (message "Sending news via %s..." (gnus-server-string method))
4939 (setq result (let ((mail-header-separator ""))
4940 (gnus-request-post method))))
4941 (kill-buffer tembuf))
4942 (set-buffer messbuf)
4944 (push 'news message-sent-message-via)
4945 (message "Couldn't send message via news: %s"
4946 (nnheader-get-report (car method)))
4950 ;;; Header generation & syntax checking.
4953 (defun message-check-element (type)
4954 "Return non-nil if this TYPE is not to be checked."
4955 (if (eq message-syntax-checks 'dont-check-for-anything-just-trust-me)
4957 (let ((able (assq type message-syntax-checks)))
4959 (eq (cdr able) 'disabled)))))
4961 (defun message-check-news-syntax ()
4962 "Check the syntax of the message."
4966 ;; We narrow to the headers and check them first.
4969 (message-narrow-to-headers)
4970 (message-check-news-header-syntax))))))
4972 (defun message-check-news-header-syntax ()
4974 ;; Check Newsgroups header.
4975 (message-check 'newsgroups
4976 (let ((group (message-fetch-field "newsgroups")))
4979 (not (string-match "\\`[ \t]*\\'" group)))
4982 "The newsgroups field is empty or missing. Posting is denied.")))))
4983 ;; Check the Subject header.
4984 (message-check 'subject
4985 (let* ((case-fold-search t)
4986 (subject (message-fetch-field "subject")))
4989 (not (string-match "\\`[ \t]*\\'" subject)))
4992 "The subject field is empty or missing. Posting is denied.")))))
4993 ;; Check for commands in Subject.
4994 (message-check 'subject-cmsg
4995 (if (string-match "^cmsg " (message-fetch-field "subject"))
4997 "The control code \"cmsg\" is in the subject. Really post? ")
4999 ;; Check long header lines.
5000 (message-check 'long-header-lines
5004 (while (and (not found)
5005 (re-search-forward "^\\([^ \t:]+\\): " nil t))
5006 (if (> (- (point) (match-beginning 0)) 998)
5008 length (- (point) (match-beginning 0)))
5009 (setq header (match-string-no-properties 1)))
5012 (y-or-n-p (format "Your %s header is too long (%d). Really post? "
5015 ;; Check for multiple identical headers.
5016 (message-check 'multiple-headers
5018 (while (and (not found)
5019 (re-search-forward "^[^ \t:]+: " nil t))
5021 (or (re-search-forward
5026 (match-beginning 0) (- (match-end 0) 2))))
5031 (y-or-n-p (format "Multiple %s headers. Really post? " found))
5033 ;; Check for Version and Sendsys.
5034 (message-check 'sendsys
5035 (if (re-search-forward "^Sendsys:\\|^Version:" nil t)
5037 (format "The article contains a %s command. Really post? "
5038 (buffer-substring (match-beginning 0)
5039 (1- (match-end 0)))))
5041 ;; See whether we can shorten Followup-To.
5042 (message-check 'shorten-followup-to
5043 (let ((newsgroups (message-fetch-field "newsgroups"))
5044 (followup-to (message-fetch-field "followup-to"))
5046 (when (and newsgroups
5047 (string-match "," newsgroups)
5052 (setq to (completing-read
5053 "Followups to (default no Followup-To header): "
5056 (message-tokenize-header
5058 (goto-char (point-min))
5059 (insert "Followup-To: " to "\n"))
5061 ;; Check "Shoot me".
5062 (message-check 'shoot
5063 (if (re-search-forward
5064 "Message-ID.*.i-did-not-set--mail-host-address--so-tickle-me" nil t)
5065 (y-or-n-p "You appear to have a misconfigured system. Really post? ")
5067 ;; Check for Approved.
5068 (message-check 'approved
5069 (if (re-search-forward "^Approved:" nil t)
5070 (y-or-n-p "The article contains an Approved header. Really post? ")
5072 ;; Check the Message-ID header.
5073 (message-check 'message-id
5074 (let* ((case-fold-search t)
5075 (message-id (message-fetch-field "message-id" t)))
5076 (or (not message-id)
5077 ;; Is there an @ in the ID?
5078 (and (string-match "@" message-id)
5079 ;; Is there a dot in the ID?
5080 (string-match "@[^.]*\\." message-id)
5081 ;; Does the ID end with a dot?
5082 (not (string-match "\\.>" message-id)))
5084 (format "The Message-ID looks strange: \"%s\". Really post? "
5086 ;; Check the Newsgroups & Followup-To headers.
5087 (message-check 'existing-newsgroups
5088 (let* ((case-fold-search t)
5089 (newsgroups (message-fetch-field "newsgroups"))
5090 (followup-to (message-fetch-field "followup-to"))
5091 (groups (message-tokenize-header
5093 (concat newsgroups "," followup-to)
5095 (post-method (if (functionp message-post-method)
5096 (funcall message-post-method)
5097 message-post-method))
5098 ;; KLUDGE to handle nnvirtual groups. Doing this right
5099 ;; would probably involve a new nnoo function.
5100 ;; -- Per Abrahamsen <abraham@dina.kvl.dk>, 2001-10-17.
5101 (method (if (and (consp post-method)
5102 (eq (car post-method) 'nnvirtual)
5103 gnus-message-group-art)
5104 (let ((group (car (nnvirtual-find-group-art
5105 (car gnus-message-group-art)
5106 (cdr gnus-message-group-art)))))
5107 (gnus-find-method-for-group group))
5111 (gnus-group-name-decode
5112 (gnus-group-real-name n)
5113 (gnus-group-name-charset method n)))
5114 (gnus-groups-from-server method)))
5117 (when (and (not (equal (car groups) "poster"))
5118 (not (member (car groups) known-groups))
5119 (not (member (car groups) errors)))
5120 (push (car groups) errors))
5123 ;; Gnus is not running.
5124 ((or (not (and (boundp 'gnus-active-hashtb)
5125 gnus-active-hashtb))
5126 (not (boundp 'gnus-read-active-file)))
5128 ;; We don't have all the group names.
5129 ((and (or (not gnus-read-active-file)
5130 (eq gnus-read-active-file 'some))
5134 "Really use %s possibly unknown group%s: %s? "
5135 (if (= (length errors) 1) "this" "these")
5136 (if (= (length errors) 1) "" "s")
5137 (mapconcat 'identity errors ", "))))
5138 ;; There were no errors.
5141 ;; There are unknown groups.
5145 "Really post to %s unknown group%s: %s? "
5146 (if (= (length errors) 1) "this" "these")
5147 (if (= (length errors) 1) "" "s")
5148 (mapconcat 'identity errors ", ")))))))
5149 ;; Check continuation headers.
5150 (message-check 'continuation-headers
5151 (goto-char (point-min))
5152 (let ((do-posting t))
5153 (while (re-search-forward "^[^ \t\n][^ \t\n:]*[ \t\n]" nil t)
5154 (goto-char (match-beginning 0))
5155 (if (y-or-n-p "Fix continuation lines? ")
5158 (unless (y-or-n-p "Send anyway? ")
5159 (setq do-posting nil))))
5161 ;; Check the Newsgroups & Followup-To headers for syntax errors.
5162 (message-check 'valid-newsgroups
5163 (let ((case-fold-search t)
5164 (headers '("Newsgroups" "Followup-To"))
5166 (while (and headers (not error))
5167 (when (setq header (mail-fetch-field (car headers)))
5171 "\\`\\([-+_&.a-zA-Z0-9]+\\)?\\(,[-+_&.a-zA-Z0-9]+\\)*\\'"
5176 (not (string-match "\\.\\'\\|\\.\\." g)))
5177 (message-tokenize-header header ","))))
5184 (format "The %s header looks odd: \"%s\". Really post? "
5185 (car headers) header)))))
5186 (message-check 'repeated-newsgroups
5187 (let ((case-fold-search t)
5188 (headers '("Newsgroups" "Followup-To"))
5189 header error groups group)
5192 (when (setq header (mail-fetch-field (pop headers)))
5193 (setq groups (message-tokenize-header header ","))
5194 (while (setq group (pop groups))
5195 (when (member group groups)
5201 (format "Group %s is repeated in headers. Really post? " error)))))
5202 ;; Check the From header.
5203 (message-check 'from
5204 (let* ((case-fold-search t)
5205 (from (message-fetch-field "from"))
5209 (message "There is no From line. Posting is denied.")
5211 ((or (not (string-match
5213 (setq ad (nth 1 (mail-extract-address-components
5214 from))))) ;larsi@ifi
5215 (string-match "\\.\\." ad) ;larsi@ifi..uio
5216 (string-match "@\\." ad) ;larsi@.ifi.uio
5217 (string-match "\\.$" ad) ;larsi@ifi.uio.
5218 (not (string-match "^[^@]+@[^@]+$" ad)) ;larsi.ifi.uio
5219 (string-match "(.*).*(.*)" from)) ;(lars) (lars)
5221 "Denied posting -- the From looks strange: \"%s\"." from)
5223 ((let ((addresses (rfc822-addresses from)))
5224 ;; `rfc822-addresses' returns a string if parsing fails.
5225 (while (and (consp addresses)
5226 (not (eq (string-to-char (car addresses)) ?\()))
5227 (setq addresses (cdr addresses)))
5230 "Denied posting -- bad From address: \"%s\"." from)
5233 ;; Check the Reply-To header.
5234 (message-check 'reply-to
5235 (let* ((case-fold-search t)
5236 (reply-to (message-fetch-field "reply-to"))
5241 ((string-match "," reply-to)
5243 (format "Multiple Reply-To addresses: \"%s\". Really post? "
5245 ((or (not (string-match
5247 (setq ad (nth 1 (mail-extract-address-components
5248 reply-to))))) ;larsi@ifi
5249 (string-match "\\.\\." ad) ;larsi@ifi..uio
5250 (string-match "@\\." ad) ;larsi@.ifi.uio
5251 (string-match "\\.$" ad) ;larsi@ifi.uio.
5252 (not (string-match "^[^@]+@[^@]+$" ad)) ;larsi.ifi.uio
5253 (string-match "(.*).*(.*)" reply-to)) ;(lars) (lars)
5256 "The Reply-To looks strange: \"%s\". Really post? "
5260 (defun message-check-news-body-syntax ()
5262 ;; Check for long lines.
5263 (message-check 'long-lines
5264 (goto-char (point-min))
5266 (concat "^" (regexp-quote mail-header-separator) "$"))
5270 "<#\\(/\\)?\\(multipart\\|part\\|external\\|mml\\)")
5273 (< (- (point) p) 80)))
5274 (zerop (forward-line 1))))
5278 "You have lines longer than 79 characters. Really post? ")))
5279 ;; Check whether the article is empty.
5280 (message-check 'empty
5281 (goto-char (point-min))
5283 (concat "^" (regexp-quote mail-header-separator) "$"))
5286 (goto-char (point-max))
5287 (re-search-backward message-signature-separator nil t)
5289 (or (re-search-backward "[^ \n\t]" b t)
5290 (if (message-gnksa-enable-p 'empty-article)
5291 (y-or-n-p "Empty article. Really post? ")
5292 (message "Denied posting -- Empty article.")
5294 ;; Check for control characters.
5295 (message-check 'control-chars
5296 (if (re-search-forward
5297 (string-to-multibyte "[\000-\007\013\015-\032\034-\037\200-\237]")
5300 "The article contains control characters. Really post? ")
5302 ;; Check excessive size.
5303 (message-check 'size
5304 (if (> (buffer-size) 60000)
5306 (format "The article is %d octets long. Really post? "
5309 ;; Check whether any new text has been added.
5310 (message-check 'new-text
5312 (not message-checksum)
5313 (not (eq (message-checksum) message-checksum))
5314 (if (message-gnksa-enable-p 'quoted-text-only)
5316 "It looks like no new text has been added. Really post? ")
5317 (message "Denied posting -- no new text has been added.")
5319 ;; Check the length of the signature.
5320 (message-check 'signature
5321 (let (sig-start sig-end)
5322 (goto-char (point-max))
5323 (if (not (re-search-backward message-signature-separator nil t))
5325 (setq sig-start (1+ (point-at-eol)))
5327 (if (re-search-forward
5328 "<#/?\\(multipart\\|part\\|external\\|mml\\)" nil t)
5329 (- (point-at-bol) 1)
5331 (if (>= (count-lines sig-start sig-end) 5)
5332 (if (message-gnksa-enable-p 'signature)
5334 (format "Signature is excessively long (%d lines). Really post? "
5335 (count-lines sig-start sig-end)))
5336 (message "Denied posting -- Excessive signature.")
5339 ;; Ensure that text follows last quoted portion.
5340 (message-check 'quoting-style
5341 (goto-char (point-max))
5342 (let ((no-problem t))
5343 (when (search-backward-regexp "^>[^\n]*\n" nil t)
5344 (setq no-problem (search-forward-regexp "^[ \t]*[^>\n]" nil t)))
5347 (if (message-gnksa-enable-p 'quoted-text-only)
5348 (y-or-n-p "Your text should follow quoted text. Really post? ")
5350 (goto-char (point-min))
5352 (concat "^" (regexp-quote mail-header-separator) "$"))
5353 (if (search-forward-regexp "^[ \t]*[^>\n]" nil t)
5354 (y-or-n-p "Your text should follow quoted text. Really post? ")
5355 (message "Denied posting -- only quoted text.")
5358 (defun message-checksum ()
5359 "Return a \"checksum\" for the current buffer."
5362 (goto-char (point-min))
5364 (concat "^" (regexp-quote mail-header-separator) "$"))
5366 (when (not (looking-at "[ \t\n]"))
5367 (setq sum (logxor (ash sum 1) (if (natnump sum) 0 1)
5372 (defun message-do-fcc ()
5373 "Process Fcc headers in the current buffer."
5374 (let ((case-fold-search t)
5375 (buf (current-buffer))
5377 (mml-externalize-attachments message-fcc-externalize-attachments))
5380 (message-narrow-to-headers)
5381 (setq file (message-fetch-field "fcc" t)))
5383 (set-buffer (get-buffer-create " *message temp*"))
5385 (insert-buffer-substring buf)
5386 (message-encode-message-body)
5388 (message-narrow-to-headers)
5389 (while (setq file (message-fetch-field "fcc" t))
5391 (message-remove-header "fcc" nil t))
5392 (let ((mail-parse-charset message-default-charset)
5393 (rfc2047-header-encoding-alist
5394 (cons '("Newsgroups" . default)
5395 rfc2047-header-encoding-alist)))
5396 (mail-encode-encoded-word-buffer)))
5397 (goto-char (point-min))
5398 (when (re-search-forward
5399 (concat "^" (regexp-quote mail-header-separator) "$")
5401 (replace-match "" t t ))
5402 ;; Process FCC operations.
5404 (setq file (pop list))
5405 (if (string-match "^[ \t]*|[ \t]*\\(.*\\)[ \t]*$" file)
5406 ;; Pipe the article to the program in question.
5407 (call-process-region (point-min) (point-max) shell-file-name
5408 nil nil nil shell-command-switch
5409 (match-string 1 file))
5410 ;; Save the article.
5411 (setq file (expand-file-name file))
5412 (unless (file-exists-p (file-name-directory file))
5413 (make-directory (file-name-directory file) t))
5414 (if (and message-fcc-handler-function
5415 (not (eq message-fcc-handler-function 'rmail-output)))
5416 (funcall message-fcc-handler-function file)
5417 ;; FIXME this option, rmail-output (also used if
5418 ;; message-fcc-handler-function is nil) is not
5419 ;; documented anywhere AFAICS. It should work in Emacs
5420 ;; 23; I suspect it does not work in Emacs 22.
5421 ;; FIXME I don't see the need for the two different cases here.
5422 ;; mail-use-rfc822 makes no difference (in Emacs 23),and
5423 ;; the third argument just controls \"Wrote file\" message.
5424 (if (and (file-readable-p file) (mail-file-babyl-p file))
5425 (rmail-output file 1 nil t)
5426 (let ((mail-use-rfc822 t))
5427 (rmail-output file 1 t t))))))
5428 (kill-buffer (current-buffer))))))
5430 (defun message-output (filename)
5431 "Append this article to Unix/babyl mail file FILENAME."
5432 (if (or (and (file-readable-p filename)
5433 (mail-file-babyl-p filename))
5434 ;; gnus-output-to-mail does the wrong thing with live, mbox
5435 ;; Rmail buffers in Emacs 23.
5436 ;; http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=597255
5437 (let ((buff (find-buffer-visiting filename)))
5438 (and buff (with-current-buffer buff
5439 (eq major-mode 'rmail-mode)))))
5440 (gnus-output-to-rmail filename t)
5441 (gnus-output-to-mail filename t)))
5443 (defun message-cleanup-headers ()
5444 "Do various automatic cleanups of the headers."
5445 ;; Remove empty lines in the header.
5447 (message-narrow-to-headers)
5448 ;; Remove blank lines.
5449 (while (re-search-forward "^[ \t]*\n" nil t)
5450 (replace-match "" t t))
5452 ;; Correct Newsgroups and Followup-To headers: Change sequence of
5453 ;; spaces to comma and eliminate spaces around commas. Eliminate
5454 ;; embedded line breaks.
5455 (goto-char (point-min))
5456 (while (re-search-forward "^\\(Newsgroups\\|Followup-To\\): +" nil t)
5460 (if (re-search-forward "^[^ \t]" nil t)
5464 (goto-char (point-min))
5465 (while (re-search-forward "\n[ \t]+" nil t)
5466 (replace-match " " t t)) ;No line breaks (too confusing)
5467 (goto-char (point-min))
5468 (while (re-search-forward "[ \t\n]*,[ \t\n]*\\|[ \t]+" nil t)
5469 (replace-match "," t t))
5470 (goto-char (point-min))
5471 ;; Remove trailing commas.
5472 (when (re-search-forward ",+$" nil t)
5473 (replace-match "" t t))))))
5475 (defun message-make-date (&optional now)
5476 "Make a valid data header.
5477 If NOW, use that time instead."
5478 (let ((system-time-locale "C"))
5479 (format-time-string "%a, %d %b %Y %T %z" now)))
5481 (defun message-insert-expires (days)
5482 "Insert the Expires header. Expiry in DAYS days."
5483 (interactive "NExpire article in how many days? ")
5485 (message-position-on-field "Expires" "X-Draft-From")
5486 (insert (message-make-expires-date days))))
5488 (defun message-make-expires-date (days)
5489 "Make date string for the Expires header. Expiry in DAYS days.
5491 In posting styles use `(\"Expires\" (make-expires-date 30))'."
5492 (let* ((cur (decode-time))
5493 (nday (+ days (nth 3 cur))))
5494 (setf (nth 3 cur) nday)
5495 (message-make-date (apply 'encode-time cur))))
5497 (defun message-make-message-id ()
5498 "Make a unique Message-ID."
5499 (concat "<" (message-unique-id)
5500 (let ((psubject (save-excursion (message-fetch-field "subject")))
5502 (save-excursion (message-fetch-field "supersedes"))))
5504 (and message-reply-headers
5505 (mail-header-references message-reply-headers)
5506 (mail-header-subject message-reply-headers)
5509 (message-strip-subject-re
5510 (mail-header-subject message-reply-headers))
5511 (message-strip-subject-re psubject))))
5513 (string-match "_-_@" psupersedes)))
5515 "@" (message-make-fqdn) ">"))
5517 (defvar message-unique-id-char nil)
5519 ;; If you ever change this function, make sure the new version
5520 ;; cannot generate IDs that the old version could.
5521 ;; You might for example insert a "." somewhere (not next to another dot
5522 ;; or string boundary), or modify the "fsf" string.
5523 (defun message-unique-id ()
5524 ;; Don't use microseconds from (current-time), they may be unsupported.
5525 ;; Instead we use this randomly inited counter.
5526 (setq message-unique-id-char
5527 (% (1+ (or message-unique-id-char
5528 (logand (random most-positive-fixnum) (1- (lsh 1 20)))))
5529 ;; (current-time) returns 16-bit ints,
5530 ;; and 2^16*25 just fits into 4 digits i base 36.
5532 (let ((tm (current-time)))
5534 (if (or (eq system-type 'ms-dos)
5535 ;; message-number-base36 doesn't handle bigints.
5536 (floatp (user-uid)))
5537 (let ((user (downcase (user-login-name))))
5538 (while (string-match "[^a-z0-9_]" user)
5539 (aset user (match-beginning 0) ?_))
5541 (message-number-base36 (user-uid) -1))
5542 (message-number-base36 (+ (car tm)
5543 (lsh (% message-unique-id-char 25) 16)) 4)
5544 (message-number-base36 (+ (nth 1 tm)
5545 (lsh (/ message-unique-id-char 25) 16)) 4)
5546 ;; Append a given name, because while the generated ID is unique
5547 ;; to this newsreader, other newsreaders might otherwise generate
5548 ;; the same ID via another algorithm.
5551 (defun message-number-base36 (num len)
5556 (concat (message-number-base36 (/ num 36) (1- len))
5557 (char-to-string (aref "zyxwvutsrqponmlkjihgfedcba9876543210"
5560 (defun message-make-organization ()
5561 "Make an Organization header."
5562 (let* ((organization
5563 (when message-user-organization
5564 (if (functionp message-user-organization)
5565 (funcall message-user-organization)
5566 message-user-organization))))
5568 (mm-enable-multibyte)
5569 (cond ((stringp organization)
5570 (insert organization))
5571 ((and (eq t organization)
5572 message-user-organization-file
5573 (file-exists-p message-user-organization-file))
5574 (insert-file-contents message-user-organization-file)))
5575 (goto-char (point-min))
5576 (while (re-search-forward "[\t\n]+" nil t)
5577 (replace-match "" t t))
5578 (unless (zerop (buffer-size))
5581 (defun message-make-lines ()
5582 "Count the number of lines and return numeric string."
5587 (int-to-string (count-lines (point) (point-max))))))
5589 (defun message-make-references ()
5590 "Return the References header for this message."
5591 (when message-reply-headers
5592 (let ((message-id (mail-header-id message-reply-headers))
5593 (references (mail-header-references message-reply-headers)))
5594 (if (or references message-id)
5595 (concat (or references "") (and references " ")
5599 (defun message-make-in-reply-to ()
5600 "Return the In-Reply-To header for this message."
5601 (when message-reply-headers
5602 (let ((from (mail-header-from message-reply-headers))
5603 (date (mail-header-date message-reply-headers))
5604 (msg-id (mail-header-id message-reply-headers)))
5606 (let ((name (mail-extract-address-components from)))
5608 msg-id (if msg-id " (")
5610 (if (string-match "[^\000-\177]" (car name))
5611 ;; Quote a string containing non-ASCII characters.
5612 ;; It will make the RFC2047 encoder cause an error
5613 ;; if there are special characters.
5614 (mm-with-multibyte-buffer
5616 (goto-char (point-min))
5617 (while (search-forward "\"" nil t)
5620 (zerop (% (skip-chars-backward "\\\\") 2))
5621 (goto-char (match-beginning 0)))
5624 ;; Those quotes will be removed by the RFC2047 encoder.
5625 (concat "\"" (buffer-string) "\""))
5629 (if (or (not date) (string= date ""))
5630 "(unknown date)" date)
5631 "\"" (if msg-id ")")))))))
5633 (defun message-make-distribution ()
5634 "Make a Distribution header."
5635 (let ((orig-distribution (message-fetch-reply-field "distribution")))
5636 (cond ((functionp message-distribution-function)
5637 (funcall message-distribution-function))
5638 (t orig-distribution))))
5640 (defun message-make-expires ()
5641 "Return an Expires header based on `message-expires'."
5642 (let ((current (current-time))
5643 (future (* 1.0 message-expires 60 60 24)))
5644 ;; Add the future to current.
5645 (setcar current (+ (car current) (round (/ future (expt 2 16)))))
5646 (setcar (cdr current) (+ (nth 1 current) (% (round future) (expt 2 16))))
5647 (message-make-date current)))
5649 (defun message-make-path ()
5651 (let ((login-name (user-login-name)))
5652 (cond ((null message-user-path)
5653 (concat (system-name) "!" login-name))
5654 ((stringp message-user-path)
5655 ;; Support GENERICPATH. Suggested by vixie@decwrl.dec.com.
5656 (concat message-user-path "!" login-name))
5659 (defun message-make-from (&optional name address)
5660 "Make a From header."
5661 (let* ((style message-from-style)
5662 (login (or address (message-make-address)))
5663 (fullname (or name user-full-name (user-full-name))))
5664 (when (string= fullname "&")
5665 (setq fullname (user-login-name)))
5667 (mm-enable-multibyte)
5670 (equal fullname ""))
5672 ((or (eq style 'angles)
5673 (and (not (eq style 'parens))
5674 ;; Use angles if no quoting is needed, or if parens would
5675 ;; need quoting too.
5676 (or (not (string-match "[^- !#-'*+/-9=?A-Z^-~]" fullname))
5677 (let ((tmp (concat fullname nil)))
5678 (while (string-match "([^()]*)" tmp)
5679 (aset tmp (match-beginning 0) ?-)
5680 (aset tmp (1- (match-end 0)) ?-))
5681 (string-match "[\\()]" tmp)))))
5683 (goto-char (point-min))
5684 ;; Look for a character that cannot appear unquoted
5685 ;; according to RFC 822.
5686 (when (re-search-forward "[^- !#-'*+/-9=?A-Z^-~]" nil 1)
5687 ;; Quote fullname, escaping specials.
5688 (goto-char (point-min))
5690 (while (re-search-forward "[\"\\]" nil 1)
5691 (replace-match "\\\\\\&" t))
5693 (insert " <" login ">"))
5694 (t ; 'parens or default
5696 (let ((fullname-start (point)))
5698 (goto-char fullname-start)
5699 ;; RFC 822 says \ and nonmatching parentheses
5700 ;; must be escaped in comments.
5701 ;; Escape every instance of ()\ ...
5702 (while (re-search-forward "[()\\]" nil 1)
5703 (replace-match "\\\\\\&" t))
5704 ;; ... then undo escaping of matching parentheses,
5705 ;; including matching nested parentheses.
5706 (goto-char fullname-start)
5707 (while (re-search-forward
5708 "\\(\\=\\|[^\\]\\(\\\\\\\\\\)*\\)\\\\(\\(\\([^\\]\\|\\\\\\\\\\)*\\)\\\\)"
5710 (replace-match "\\1(\\3)" t)
5711 (goto-char fullname-start)))
5715 (defun message-make-sender ()
5716 "Return the \"real\" user address.
5717 This function tries to ignore all user modifications, and
5718 give as trustworthy answer as possible."
5719 (concat (user-login-name) "@" (system-name)))
5721 (defun message-make-address ()
5722 "Make the address of the user."
5723 (or (message-user-mail-address)
5724 (concat (user-login-name) "@" (message-make-domain))))
5726 (defun message-user-mail-address ()
5727 "Return the pertinent part of `user-mail-address'."
5728 (when (and user-mail-address
5729 (string-match "@.*\\." user-mail-address))
5730 (if (string-match " " user-mail-address)
5731 (nth 1 (mail-extract-address-components user-mail-address))
5732 user-mail-address)))
5734 (defun message-sendmail-envelope-from ()
5735 "Return the envelope from."
5736 (cond ((eq message-sendmail-envelope-from 'header)
5737 (nth 1 (mail-extract-address-components
5738 (message-fetch-field "from"))))
5739 ((stringp message-sendmail-envelope-from)
5740 message-sendmail-envelope-from)
5742 (message-make-address))))
5744 (defun message-make-fqdn ()
5745 "Return user's fully qualified domain name."
5746 (let* ((sysname (system-name))
5747 (user-mail (message-user-mail-address))
5750 (string-match "@\\(.*\\)\\'" user-mail))
5751 (match-string 1 user-mail)))
5752 (case-fold-search t))
5754 ((and message-user-fqdn
5755 (stringp message-user-fqdn)
5756 (not (string-match message-bogus-system-names message-user-fqdn)))
5757 ;; `message-user-fqdn' seems to be valid
5759 ((and (string-match message-bogus-system-names sysname))
5760 ;; `system-name' returned the right result.
5762 ;; Try `mail-host-address'.
5763 ((and (stringp mail-host-address)
5764 (not (string-match message-bogus-system-names mail-host-address)))
5766 ;; We try `user-mail-address' as a backup.
5768 (stringp user-domain)
5769 (not (string-match message-bogus-system-names user-domain)))
5771 ;; Default to this bogus thing.
5774 ".i-did-not-set--mail-host-address--so-tickle-me")))))
5776 (defun message-make-domain ()
5777 "Return the domain name."
5778 (or mail-host-address
5779 (message-make-fqdn)))
5781 (defun message-to-list-only ()
5782 "Send a message to the list only.
5783 Remove all addresses but the list address from To and Cc headers."
5785 (let ((listaddr (message-make-mail-followup-to t)))
5788 (message-remove-header "to")
5789 (message-remove-header "cc")
5790 (message-position-on-field "To" "X-Draft-From")
5791 (insert listaddr)))))
5793 (defun message-make-mail-followup-to (&optional only-show-subscribed)
5794 "Return the Mail-Followup-To header.
5795 If passed the optional argument ONLY-SHOW-SUBSCRIBED only return the
5796 subscribed address (and not the additional To and Cc header contents)."
5797 (let* ((case-fold-search t)
5798 (to (message-fetch-field "To"))
5799 (cc (message-fetch-field "cc"))
5800 (msg-recipients (concat to (and to cc ", ") cc))
5802 (mapcar 'mail-strip-quoted-names
5803 (message-tokenize-header msg-recipients)))
5805 (if message-subscribed-address-file
5806 (let (begin end item re)
5809 (insert-file-contents message-subscribed-address-file)
5811 (setq begin (point))
5814 (if (bolp) (setq end (1- end)))
5815 (setq item (regexp-quote (buffer-substring begin end)))
5816 (if re (setq re (concat re "\\|" item))
5817 (setq re (concat "\\`\\(" item))))
5818 (and re (list (concat re "\\)\\'"))))))))
5819 (mft-regexps (apply 'append message-subscribed-regexps
5820 (mapcar 'regexp-quote
5821 message-subscribed-addresses)
5824 message-subscribed-address-functions))))
5827 (loop for recipient in recipients
5828 when (loop for regexp in mft-regexps
5829 when (string-match regexp recipient) return t)
5832 (if only-show-subscribed
5834 msg-recipients))))))
5836 (defun message-idna-to-ascii-rhs-1 (header)
5837 "Interactively potentially IDNA encode domain names in HEADER."
5838 (let ((field (message-fetch-field header))
5843 (mapcar (lambda (rhs) (or (cadr (split-string rhs "@")) ""))
5849 (mail-extract-address-components field t))))))
5850 ;; Note that `rhs' will be "" if the address does not have
5851 ;; the domain part, i.e., if it is a local user's address.
5852 (setq ace (if (string-match "\\`[[:ascii:]]*\\'" rhs)
5854 (downcase (puny-encode-domain rhs))))
5855 (when (and (not (equal rhs ace))
5856 (or (not (eq message-use-idna 'ask))
5857 (y-or-n-p (format "Replace %s with %s in %s:? "
5859 (goto-char (point-min))
5860 (while (re-search-forward (concat "^" header ":") nil t)
5861 (message-narrow-to-field)
5862 (while (search-forward (concat "@" rhs) nil t)
5863 (replace-match (concat "@" ace) t t))
5864 (goto-char (point-max))
5867 (defun message-idna-to-ascii-rhs ()
5868 "Possibly IDNA encode non-ASCII domain names in From:, To: and Cc: headers.
5869 See `message-idna-encode'."
5871 (when message-use-idna
5874 ;; `message-narrow-to-head' that recognizes only the first empty
5875 ;; line as the message header separator used to be used here.
5876 ;; However, since there is the "--text follows this line--" line
5877 ;; normally, it failed in narrowing to the headers and potentially
5878 ;; caused the IDNA encoding on lines that look like headers in
5879 ;; the message body.
5880 (message-narrow-to-headers-or-head)
5881 (message-idna-to-ascii-rhs-1 "From")
5882 (message-idna-to-ascii-rhs-1 "To")
5883 (message-idna-to-ascii-rhs-1 "Reply-To")
5884 (message-idna-to-ascii-rhs-1 "Mail-Reply-To")
5885 (message-idna-to-ascii-rhs-1 "Mail-Followup-To")
5886 (message-idna-to-ascii-rhs-1 "Cc")))))
5888 (defun message-generate-headers (headers)
5889 "Prepare article HEADERS.
5890 Headers already prepared in the buffer are not modified."
5891 (setq headers (append headers message-required-headers))
5893 (message-narrow-to-headers)
5894 (let* ((header-values
5895 (list 'Date (message-make-date)
5896 'Message-ID (message-make-message-id)
5897 'Organization (message-make-organization)
5898 'From (message-make-from)
5899 'Path (message-make-path)
5902 'In-Reply-To (message-make-in-reply-to)
5903 'References (message-make-references)
5905 'Distribution (message-make-distribution)
5906 'Lines (message-make-lines)
5907 'User-Agent message-newsreader
5908 'Expires (message-make-expires)))
5909 (case-fold-search t)
5911 header value elem header-string)
5912 ;; First we remove any old generated headers.
5913 (let ((headers message-deletable-headers))
5914 (unless (buffer-modified-p)
5915 (setq headers (delq 'Message-ID (copy-sequence headers))))
5917 (goto-char (point-min))
5918 (and (re-search-forward
5919 (concat "^" (symbol-name (car headers)) ": *") nil t)
5920 (get-text-property (1+ (match-beginning 0)) 'message-deletable)
5921 (message-delete-line))
5923 ;; Go through all the required headers and see if they are in the
5924 ;; articles already. If they are not, or are empty, they are
5925 ;; inserted automatically - except for Subject, Newsgroups and
5928 (goto-char (point-min))
5929 (setq elem (pop headers))
5931 (if (eq (car elem) 'optional)
5932 (setq header (cdr elem)
5934 (setq header (car elem)))
5936 (setq header-string (if (stringp header)
5938 (symbol-name header)))
5939 (when (or (not (re-search-forward
5941 (regexp-quote (downcase header-string))
5945 ;; The header was found. We insert a space after the
5946 ;; colon, if there is none.
5947 (if (/= (char-after) ? ) (insert " ") (forward-char 1))
5948 ;; Find out whether the header is empty.
5949 (looking-at "[ \t]*\n[^ \t]")))
5950 ;; So we find out what value we should insert.
5954 (eq (car elem) 'optional)
5955 (not (member header-string message-inserted-headers)))
5956 ;; This is an optional header. If the cdr of this
5957 ;; is something that is nil, then we do not insert
5959 (setq header (cdr elem))
5960 (or (and (functionp (cdr elem))
5961 (funcall (cdr elem)))
5962 (and (symbolp (cdr elem))
5963 (plist-get header-values (cdr elem)))))
5965 ;; The element is a cons. Either the cdr is a
5966 ;; string to be inserted verbatim, or it is a
5967 ;; function, and we insert the value returned from
5969 (or (and (stringp (cdr elem))
5971 (and (functionp (cdr elem))
5972 (funcall (cdr elem)))))
5973 ((and (symbolp header)
5974 (plist-member header-values header))
5975 ;; The element is a symbol. We insert the value of
5976 ;; this symbol, if any.
5977 (plist-get header-values header))
5978 ((not (message-check-element
5979 (intern (downcase (symbol-name header)))))
5980 ;; We couldn't generate a value for this header,
5981 ;; so we just ask the user.
5982 (read-from-minibuffer
5983 (format "Empty header for %s; enter value: " header)))))
5984 ;; Finally insert the header.
5986 (not (equal value "")))
5990 ;; This header didn't exist, so we insert it.
5991 (goto-char (point-max))
5993 (cdr (assq header message-header-format-alist))))
5995 (funcall formatter header value)
5996 (insert header-string ": " value))
5997 (push header-string message-inserted-headers)
5998 (goto-char (message-fill-field))
5999 ;; We check whether the value was ended by a
6000 ;; newline. If not, we insert one.
6004 ;; The value of this header was empty, so we clear
6005 ;; totally and insert the new value.
6006 (delete-region (point) (point-at-eol))
6007 ;; If the header is optional, and the header was
6008 ;; empty, we can't insert it anyway.
6010 (push header-string message-inserted-headers)
6012 (message-fill-field)))
6013 ;; Add the deletable property to the headers that require it.
6014 (and (memq header message-deletable-headers)
6015 (progn (beginning-of-line) (looking-at "[^:]+: "))
6016 (add-text-properties
6017 (point) (match-end 0)
6018 '(message-deletable t face italic) (current-buffer)))))))
6019 ;; Insert new Sender if the From is strange.
6020 (let ((from (message-fetch-field "from"))
6021 (sender (message-fetch-field "sender"))
6022 (secure-sender (message-make-sender)))
6024 (not (message-check-element 'sender))
6027 (cadr (mail-extract-address-components from)))
6028 (downcase secure-sender)))
6033 (cadr (mail-extract-address-components sender)))
6034 (downcase secure-sender)))))
6035 (goto-char (point-min))
6036 ;; Rename any old Sender headers to Original-Sender.
6037 (when (re-search-forward "^\\(Original-\\)*Sender:" nil t)
6039 (insert "Original-")
6040 (beginning-of-line))
6041 (when (or (message-news-p)
6042 (string-match "@.+\\.." secure-sender))
6043 (insert "Sender: " secure-sender "\n"))))
6045 (message-idna-to-ascii-rhs))))
6047 (defun message-insert-courtesy-copy (message)
6048 "Insert a courtesy message in mail copies of combined messages."
6052 (message-narrow-to-headers)
6053 (when (setq newsgroups (message-fetch-field "newsgroups"))
6054 (goto-char (point-max))
6055 (insert "Posted-To: " newsgroups "\n")))
6059 ((string-match "%s" message)
6060 (insert (format message newsgroups)))
6062 (insert message)))))))
6065 ;;; Setting up a message buffer
6068 (defun message-skip-to-next-address ()
6069 (let ((end (save-excursion
6070 (message-next-header)
6073 (when (looking-at ",")
6075 (while (and (not (= (point) end))
6076 (or (not (eq char ?,))
6078 (skip-chars-forward "^,\"" end)
6079 (when (eq (setq char (following-char)) ?\")
6080 (setq quoted (not quoted)))
6081 (unless (= (point) end)
6083 (skip-chars-forward " \t\n")))
6085 (defun message-split-line ()
6086 "Split current line, moving portion beyond point vertically down.
6087 If the current line has `message-yank-prefix', insert it on the new line."
6089 (split-line message-yank-prefix))
6091 (defun message-insert-header (header value)
6092 (insert (capitalize (symbol-name header))
6094 (if (consp value) (car value) value)))
6096 (defun message-field-name ()
6098 (goto-char (point-min))
6099 (when (looking-at "\\([^:]+\\):")
6100 (intern (capitalize (match-string 1))))))
6102 (defun message-fill-field ()
6105 (message-narrow-to-field)
6106 (let ((field-name (message-field-name)))
6107 (funcall (or (cadr (assq field-name message-field-fillers))
6108 'message-fill-field-general)))
6111 (defun message-fill-field-address ()
6114 (message-skip-to-next-address)
6120 (when (and (> (current-column) 78)
6124 (delete-char (- (skip-chars-backward " \t")))
6126 (setq last (point)))
6127 (forward-line end)))
6129 (defun message-fill-field-general ()
6130 (let ((begin (point))
6133 (while (and (search-forward "\n" nil t)
6135 (replace-match " " t t))
6136 (fill-region-as-paragraph begin (point-max))
6137 ;; Tapdance around looong Message-IDs.
6139 (when (looking-at "[ \t]*$")
6140 (message-delete-line))
6142 (search-forward ":" nil t)
6143 (when (looking-at "\n[ \t]+")
6144 (replace-match " " t t))
6145 (goto-char (point-max))))
6147 (defun message-shorten-1 (list cut surplus)
6148 "Cut SURPLUS elements out of LIST, beginning with CUTth one."
6149 (setcdr (nthcdr (- cut 2) list)
6150 (nthcdr (+ (- cut 2) surplus 1) list)))
6152 (defun message-shorten-references (header references)
6153 "Trim REFERENCES to be 21 Message-ID long or less, and fold them.
6154 When sending via news, also check that the REFERENCES are less
6155 than 988 characters long, and if they are not, trim them until
6157 ;; 21 is the number suggested by USAGE.
6164 (goto-char (point-min))
6165 ;; Cons a list of valid references. GNKSA says we must not include MIDs
6166 ;; with whitespace or missing brackets (7.a "Does not propagate broken
6167 ;; Message-IDs in original References").
6168 (while (re-search-forward "<[^ <]+@[^ <]+>" nil t)
6169 (push (match-string 0) refs))
6170 (setq refs (nreverse refs)
6171 count (length refs)))
6173 ;; If the list has more than MAXCOUNT elements, trim it by
6174 ;; removing the CUTth element and the required number of
6175 ;; elements that follow.
6176 (when (> count maxcount)
6177 (let ((surplus (- count maxcount)))
6178 (message-shorten-1 refs cut surplus)
6179 (decf count surplus)))
6181 ;; When sending via news, make sure the total folded length will
6182 ;; be less than 998 characters. This is to cater to broken INN
6183 ;; 2.3 which counts the total number of characters in a header
6184 ;; rather than the physical line length of each line, as it should.
6186 ;; This hack should be removed when it's believed than INN 2.3 is
6187 ;; no longer widely used.
6189 ;; At this point the headers have not been generated, thus we use
6190 ;; message-this-is-news directly.
6191 (when message-this-is-news
6194 (message-insert-header
6195 header (mapconcat #'identity refs " "))
6197 (message-shorten-1 refs cut 1)))
6198 ;; Finally, collect the references back into a string and insert
6199 ;; it into the buffer.
6200 (message-insert-header header (mapconcat #'identity refs " "))))
6202 (defun message-position-point ()
6203 "Move point to where the user probably wants to find it."
6204 (message-narrow-to-headers)
6206 ((re-search-forward "^[^:]+:[ \t]*$" nil t)
6207 (search-backward ":" )
6210 (if (eq (char-after) ? )
6214 (goto-char (point-max))
6217 (unless (looking-at "$")
6221 (defcustom message-beginning-of-line t
6222 "Whether \\<message-mode-map>\\[message-beginning-of-line]\
6223 goes to beginning of header values."
6225 :group 'message-buffers
6226 :link '(custom-manual "(message)Movement")
6229 (defvar visual-line-mode)
6230 (declare-function beginning-of-visual-line "simple" (&optional n))
6232 (defun message-beginning-of-header (handle-folded)
6233 "Move point to beginning of header’s value.
6235 When point is at the first header line, moves it after the colon
6236 and spaces separating header name and header value.
6238 When point is in a continuation line of a folded header (i.e. the
6239 line starts with a space), the behaviour depends on HANDLE-FOLDED
6240 argument. If it’s nil, function moves the point to the start of
6241 the header continuation; otherwise, function locates the
6242 beginning of the header and moves point past the colon as is the
6243 case of single-line headers.
6245 No check whether point is inside of a header or body of the
6246 message is performed.
6248 Returns point or nil if beginning of header’s value could not be
6249 found. In the latter case, the point is still moved to the
6250 beginning of line (possibly after attempting to move it to the
6251 beginning of a folded header)."
6252 ;; https://www.rfc-editor.org/rfc/rfc2822.txt, section 2.2.3. says that when
6253 ;; unfolding a single WSP should be consumed. WSP is defined as a space
6254 ;; character or a horizontal tab.
6257 (while (and (> (point) (point-min))
6258 (or (eq (char-after) ?\s) (eq (char-after) ?\t)))
6259 (beginning-of-line 0)))
6260 (when (or (eq (char-after) ?\s) (eq (char-after) ?\t)
6261 (search-forward ":" (point-at-eol) t))
6262 ;; We are a bit more lacks than the RFC and allow any positive number of WSP
6264 (skip-chars-forward " \t" (point-at-eol))
6267 (defun message-beginning-of-line (&optional n)
6268 "Move point to beginning of header value or to beginning of line.
6269 The prefix argument N is passed directly to `beginning-of-line'.
6271 This command is identical to `beginning-of-line' if point is
6272 outside the message header or if the option
6273 `message-beginning-of-line' is nil.
6275 If point is in the message header and on a header line, move
6276 point to the beginning of the header value or the beginning of
6277 line, whichever is closer. If point is already at beginning of
6278 line, move point to beginning of header value. Therefore,
6279 repeated calls will toggle point between beginning of field and
6282 When called without a prefix argument, header value spanning
6283 multiple lines is treated as a single line. Otherwise, even if
6284 N is 1, when point is on a continuation header line, it will be
6285 moved to the beginning "
6288 ;; Go to beginning of header or beginning of line.
6289 ((and message-beginning-of-line (message-point-in-header-p))
6290 (let* ((point (point))
6291 (bol (progn (beginning-of-line n) (point)))
6292 (boh (message-beginning-of-header visual-line-mode)))
6293 (goto-char (if (and boh (or (< boh point) (= bol point))) boh bol))))
6294 ;; Go to beginning of visual line
6296 (beginning-of-visual-line n))
6297 ;; Go to beginning of line.
6298 ((beginning-of-line n))))
6300 (defun message-buffer-name (type &optional to group)
6301 "Return a new (unique) buffer name based on TYPE and TO."
6303 ;; Generate a new buffer name The Message Way.
6304 ((memq message-generate-new-buffers '(unique t))
6305 (generate-new-buffer-name
6309 (or (car (mail-extract-address-components to))
6312 (if (and group (not (string= group ""))) (concat " on " group) "")
6314 ;; Check whether `message-generate-new-buffers' is a function,
6315 ;; and if so, call it.
6316 ((functionp message-generate-new-buffers)
6317 (funcall message-generate-new-buffers type to group))
6318 ((eq message-generate-new-buffers 'unsent)
6319 (generate-new-buffer-name
6320 (concat "*unsent " type
6323 (or (car (mail-extract-address-components to))
6326 (if (and group (not (string= group ""))) (concat " on " group) "")
6328 ;; Search for the existing message buffer with the specified name.
6330 (let* ((new (if (eq message-generate-new-buffers 'standard)
6331 (generate-new-buffer-name (concat "*" type " message*"))
6332 (let ((message-generate-new-buffers 'unique))
6333 (message-buffer-name type to group))))
6334 (regexp (concat "\\`"
6336 (if (string-match "<[0-9]+>\\'" new)
6337 (substring new 0 (match-beginning 0))
6339 "\\(?:<\\([0-9]+\\)>\\)?\\'"))
6340 (case-fold-search nil))
6347 (when (and (string-match regexp (setq b (buffer-name b)))
6348 (eq (with-current-buffer b major-mode)
6350 (cons (string-to-number (or (match-string 1 b) "1"))
6353 'car-less-than-car)))
6356 (defun message-pop-to-buffer (name &optional switch-function)
6357 "Pop to buffer NAME, and warn if it already exists and is modified."
6358 (let ((buffer (get-buffer name)))
6360 (buffer-name buffer))
6361 (let ((window (get-buffer-window buffer 0)))
6363 ;; Raise the frame already displaying the message buffer.
6365 (select-frame-set-input-focus (window-frame window))
6366 (select-window window))
6367 (funcall (or switch-function #'pop-to-buffer) buffer)
6368 (set-buffer buffer))
6369 (when (and (buffer-modified-p)
6372 "Message already being composed; erase? ")
6374 (error "Message being composed")))
6375 (funcall (or switch-function 'pop-to-buffer-same-window)
6381 (defun message-do-send-housekeeping ()
6382 "Kill old message buffers."
6383 ;; We might have sent this buffer already. Delete it from the
6385 (setq message-buffer-list (delq (current-buffer) message-buffer-list))
6386 (while (and message-max-buffers
6388 (>= (length message-buffer-list) message-max-buffers))
6389 ;; Kill the oldest buffer -- unless it has been changed.
6390 (let ((buffer (pop message-buffer-list)))
6391 (when (and (buffer-name buffer)
6392 (not (buffer-modified-p buffer)))
6393 (kill-buffer buffer))))
6394 ;; Rename the buffer.
6395 (if message-send-rename-function
6396 (funcall message-send-rename-function)
6397 (message-default-send-rename-function))
6398 ;; Push the current buffer onto the list.
6399 (when message-max-buffers
6400 (setq message-buffer-list
6401 (nconc message-buffer-list (list (current-buffer))))))
6403 (defun message-default-send-rename-function ()
6404 ;; Note: mail-abbrevs of XEmacs renames buffer name behind Gnus.
6406 "\\`\\*\\(sent \\|unsent \\)?\\(.+\\)\\*[^\\*]*\\|\\`mail to "
6408 (let ((name (match-string 2 (buffer-name)))
6410 (if (not (or (null name)
6411 (string-equal name "mail")
6412 (string-equal name "posting")))
6413 (setq name (concat "*sent " name "*"))
6414 (message-narrow-to-headers)
6415 (setq to (message-fetch-field "to"))
6416 (setq group (message-fetch-field "newsgroups"))
6420 (to (concat "*sent mail to "
6421 (or (car (mail-extract-address-components to))
6423 ((and group (not (string= group "")))
6424 (concat "*sent posting on " group "*"))
6425 (t "*sent mail*"))))
6426 (unless (string-equal name (buffer-name))
6427 (rename-buffer name t)))))
6429 (defun message-mail-user-agent ()
6431 ((not message-mail-user-agent) nil)
6432 ((eq message-mail-user-agent t) mail-user-agent)
6433 (t message-mail-user-agent))))
6434 (if (memq mua '(message-user-agent gnus-user-agent))
6438 ;; YANK-ACTION, if non-nil, can be a buffer or a yank action of the
6439 ;; form (FUNCTION . ARGS).
6440 (defun message-setup (headers &optional yank-action actions
6441 continue switch-function return-action)
6442 (let ((mua (message-mail-user-agent))
6444 (if (not (and message-this-is-mail mua))
6445 (message-setup-1 headers yank-action actions return-action)
6446 (setq headers (copy-sequence headers))
6447 (setq field (assq 'Subject headers))
6449 (setq subject (cdr field))
6450 (setq headers (delq field headers)))
6451 (setq field (assq 'To headers))
6453 (setq to (cdr field))
6454 (setq headers (delq field headers)))
6455 (let ((mail-user-agent mua))
6456 (compose-mail to subject
6457 (mapcar (lambda (item)
6459 (format "%s" (car item))
6462 continue switch-function
6463 (if (bufferp yank-action)
6464 (list 'insert-buffer yank-action)
6468 (defun message-headers-to-generate (headers included-headers excluded-headers)
6469 "Return a list that includes all headers from HEADERS.
6470 If INCLUDED-HEADERS is a list, just include those headers. If it is
6471 t, include all headers. In any case, headers from EXCLUDED-HEADERS
6475 (dolist (header headers)
6476 (setq header-name (cond
6477 ((and (consp header)
6478 (eq (car header) 'optional))
6479 ;; On the form (optional . Header)
6482 ;; On the form (Header . function)
6487 (when (and (not (memq header-name excluded-headers))
6488 (or (eq included-headers t)
6489 (memq header-name included-headers)))
6490 (push header result)))
6493 (defun message-setup-1 (headers &optional yank-action actions return-action)
6494 (dolist (action actions)
6496 (add-to-list 'message-send-actions
6497 `(apply ',(car action) ',(cdr action)))))
6498 (setq message-return-action return-action)
6499 (setq message-reply-buffer
6500 (if (and (consp yank-action)
6501 (eq (car yank-action) 'insert-buffer))
6504 (goto-char (point-min))
6505 ;; Insert all the headers.
6508 (alist message-header-format-alist))
6510 (unless (assq (caar h) message-header-format-alist)
6511 (push (list (caar h)) alist))
6515 (delete-region (point) (progn (forward-line -1) (point)))
6516 (when message-default-headers
6518 (if (functionp message-default-headers)
6519 (funcall message-default-headers)
6520 message-default-headers))
6521 (or (bolp) (insert ?\n)))
6522 (insert (concat mail-header-separator "\n"))
6524 ;; If a crash happens while replying, the auto-save file would *not* have a
6525 ;; `References:' header if `message-generate-headers-first' was nil.
6526 ;; Therefore, always generate it first.
6527 (let ((message-generate-headers-first
6528 (if (eq message-generate-headers-first t)
6530 (append message-generate-headers-first '(References)))))
6531 (when (message-news-p)
6532 (when message-default-news-headers
6533 (insert message-default-news-headers)
6534 (or (bolp) (insert ?\n)))
6535 (message-generate-headers
6536 (message-headers-to-generate
6537 (append message-required-news-headers
6538 message-required-headers)
6539 message-generate-headers-first
6541 (when (message-mail-p)
6542 (when message-default-mail-headers
6543 (insert message-default-mail-headers)
6544 (or (bolp) (insert ?\n)))
6545 (message-generate-headers
6546 (message-headers-to-generate
6547 (append message-required-mail-headers
6548 message-required-headers)
6549 message-generate-headers-first
6550 '(Lines Subject)))))
6551 (run-hooks 'message-signature-setup-hook)
6552 (message-insert-signature)
6554 (message-narrow-to-headers)
6555 (run-hooks 'message-header-setup-hook))
6556 (setq buffer-undo-list nil)
6557 (when message-generate-hashcash
6558 ;; Generate hashcash headers for recipients already known
6559 (mail-add-payment-async))
6560 ;; Gnus posting styles are applied via buffer-local `message-setup-hook'
6562 (run-hooks 'message-setup-hook)
6563 ;; Do this last to give it precedence over posting styles, etc.
6564 (when (message-mail-p)
6566 (message-narrow-to-headers)
6567 (if message-alternative-emails
6568 (message-use-alternative-email-as-from))))
6569 (message-position-point)
6570 ;; Allow correct handling of `message-checksum' in `message-yank-original':
6571 (set-buffer-modified-p nil)
6573 ;; rmail-start-mail expects message-mail to return t (Bug#9392)
6576 (defun message-set-auto-save-file-name ()
6577 "Associate the message buffer with a file in the drafts directory."
6578 (when message-auto-save-directory
6579 (unless (file-directory-p
6580 (directory-file-name message-auto-save-directory))
6581 (make-directory message-auto-save-directory t))
6583 (setq message-draft-article
6584 (nndraft-request-associate-buffer "drafts"))
6586 ;; If Gnus were alive, draft messages would be saved in the drafts folder.
6587 ;; But Gnus is not alive, so arrange to save the draft message in a
6588 ;; regular file in message-auto-save-directory. Append a unique
6589 ;; time-based suffix to the filename to allow multiple drafts to be saved
6590 ;; simultaneously without overwriting each other (which mimics the
6591 ;; functionality of the Gnus drafts folder).
6592 (setq buffer-file-name (expand-file-name
6594 (if (memq system-type
6595 '(ms-dos windows-nt cygwin))
6598 (format-time-string "-%Y%m%d-%H%M%S"))
6599 message-auto-save-directory))
6600 (setq buffer-auto-save-file-name (make-auto-save-file-name)))
6601 (clear-visited-file-modtime)
6602 (setq buffer-file-coding-system message-draft-coding-system)))
6604 (defun message-disassociate-draft ()
6605 "Disassociate the message buffer from the drafts directory."
6606 (when message-draft-article
6607 (nndraft-request-expire-articles
6608 (list message-draft-article) "drafts" nil t)))
6610 (defun message-insert-headers ()
6611 "Generate the headers for the article."
6615 (message-narrow-to-headers)
6616 (when (message-news-p)
6617 (message-generate-headers
6620 (copy-sequence message-required-news-headers)))))
6621 (when (message-mail-p)
6622 (message-generate-headers
6625 (copy-sequence message-required-mail-headers))))))))
6630 ;;; Commands for interfacing with message
6634 (defun message-mail (&optional to subject other-headers continue
6635 switch-function yank-action send-actions
6636 return-action &rest ignored)
6637 "Start editing a mail message to be sent.
6638 OTHER-HEADERS is an alist of header/value pairs. CONTINUE says whether
6639 to continue editing a message already being composed. SWITCH-FUNCTION
6640 is a function used to switch to and display the mail buffer."
6642 (let ((message-this-is-mail t))
6643 (unless (message-mail-user-agent)
6644 (message-pop-to-buffer
6645 ;; Search for the existing message buffer if `continue' is non-nil.
6646 (let ((message-generate-new-buffers
6647 (when (or (not continue)
6648 (eq message-generate-new-buffers 'standard)
6649 (functionp message-generate-new-buffers))
6650 message-generate-new-buffers)))
6651 (message-buffer-name "mail" to))
6655 `((To . ,(or to "")) (Subject . ,(or subject "")))
6656 ;; C-h f compose-mail says that headers should be specified as
6657 ;; (string . value); however all the rest of message expects
6658 ;; headers to be symbols, not strings (eg message-header-format-alist).
6659 ;; http://lists.gnu.org/archive/html/emacs-devel/2011-01/msg00337.html
6660 ;; We need to convert any string input, eg from rmail-start-mail.
6661 (dolist (h other-headers other-headers)
6662 (if (stringp (car h)) (setcar h (intern (capitalize (car h)))))))
6663 yank-action send-actions continue switch-function
6667 (defun message-news (&optional newsgroups subject)
6668 "Start editing a news article to be sent."
6670 (let ((message-this-is-news t))
6671 (message-pop-to-buffer (message-buffer-name "posting" nil newsgroups))
6672 (message-setup `((Newsgroups . ,(or newsgroups ""))
6673 (Subject . ,(or subject ""))))))
6675 (defun message-alter-recipients-discard-bogus-full-name (addrcell)
6676 "Discard mail address in full names.
6677 When the full name in reply headers contains the mail
6678 address (e.g. \"foo@bar <foo@bar>\"), discard full name.
6679 ADDRCELL is a cons cell where the car is the mail address and the
6680 cdr is the complete address (full name and mail address)."
6681 (if (string-match (concat (regexp-quote (car addrcell)) ".*"
6682 (regexp-quote (car addrcell)))
6684 (cons (car addrcell) (car addrcell))
6687 (defcustom message-alter-recipients-function nil
6688 "Function called to allow alteration of reply header structures.
6689 It is called in `message-get-reply-headers' for each recipient.
6690 The function is called with one parameter, a cons cell ..."
6691 :type '(choice (const :tag "None" nil)
6692 (const :tag "Discard bogus full name"
6693 message-alter-recipients-discard-bogus-full-name)
6695 :version "23.1" ;; No Gnus
6696 :group 'message-headers)
6698 (defun message-get-reply-headers (wide &optional to-address address-headers)
6699 (let (follow-to mct never-mct to cc author mft recipients extra)
6700 ;; Find all relevant headers we need.
6702 (message-narrow-to-headers-or-head)
6703 ;; Gmane renames "To". Look at "Original-To", too, if it is present in
6704 ;; message-header-synonyms.
6705 (setq to (or (message-fetch-field "to")
6706 (and (loop for synonym in message-header-synonyms
6707 when (memq 'Original-To synonym)
6709 (message-fetch-field "original-to")))
6710 cc (message-fetch-field "cc")
6711 extra (when message-extra-wide-headers
6712 (mapconcat 'identity
6713 (mapcar 'message-fetch-field
6714 message-extra-wide-headers)
6716 mct (message-fetch-field "mail-copies-to")
6717 author (or (message-fetch-field "mail-reply-to")
6718 (message-fetch-field "reply-to"))
6719 mft (and message-use-mail-followup-to
6720 (message-fetch-field "mail-followup-to")))
6721 ;; Make sure this message goes to the author if this is a wide
6722 ;; reply, since Reply-To address may be a list address a mailing
6723 ;; list server added.
6724 (when (and wide author)
6725 (setq cc (concat author ", " cc)))
6726 (when (or wide (not author))
6727 (setq author (or (message-fetch-field "from") ""))))
6729 ;; Handle special values of Mail-Copies-To.
6731 (cond ((or (equal (downcase mct) "never")
6732 (equal (downcase mct) "nobody"))
6735 ((or (equal (downcase mct) "always")
6736 (equal (downcase mct) "poster"))
6737 (setq mct author))))
6740 ;; Build (textual) list of new recipient addresses.
6743 (setq recipients (concat ", " to-address))
6744 ;; If the author explicitly asked for a copy, we don't deny it to them.
6745 (if mct (setq recipients (concat recipients ", " mct))))
6747 (setq recipients (concat ", " author)))
6749 (dolist (header address-headers)
6750 (let ((value (message-fetch-field header)))
6752 (setq recipients (concat recipients ", " value))))))
6754 (string-match "[^ \t,]" mft)
6755 (or (not (eq message-use-mail-followup-to 'ask))
6756 (message-y-or-n-p "Obey Mail-Followup-To? " t "\
6757 You should normally obey the Mail-Followup-To: header. In this
6758 article, it has the value of
6762 which directs your response to " (if (string-match "," mft)
6763 "the specified addresses"
6764 "that address only") ".
6766 Most commonly, Mail-Followup-To is used by a mailing list poster to
6767 express that responses should be sent to just the list, and not the
6770 If a message is posted to several mailing lists, Mail-Followup-To may
6771 also be used to direct the following discussion to one list only,
6772 because discussions that are spread over several lists tend to be
6773 fragmented and very difficult to follow.
6775 Also, some source/announcement lists are not intended for discussion;
6776 responses here are directed to other addresses.
6778 You may customize the variable `message-use-mail-followup-to', if you
6779 want to get rid of this query permanently.")))
6780 (setq recipients (concat ", " mft)))
6782 (setq recipients (if never-mct "" (concat ", " author)))
6783 (if to (setq recipients (concat recipients ", " to)))
6784 (if cc (setq recipients (concat recipients ", " cc)))
6785 (if extra (setq recipients (concat recipients ", " extra)))
6786 (if mct (setq recipients (concat recipients ", " mct)))))
6787 (if (>= (length recipients) 2)
6788 ;; Strip the leading ", ".
6789 (setq recipients (substring recipients 2)))
6790 ;; Squeeze whitespace.
6791 (while (string-match "[ \t][ \t]+" recipients)
6792 (setq recipients (replace-match " " t t recipients)))
6793 ;; Remove addresses that match `message-dont-reply-to-names'.
6795 (cond ((functionp message-dont-reply-to-names)
6799 (mapcar (lambda (mail)
6800 (unless (funcall message-dont-reply-to-names
6801 (mail-strip-quoted-names mail))
6803 (message-tokenize-header recipients)))
6805 (t (let ((mail-dont-reply-to-names (message-dont-reply-to-names)))
6806 (mail-dont-reply-to recipients)))))
6807 ;; Perhaps "Mail-Copies-To: never" removed the only address?
6808 (if (string-equal recipients "")
6809 (setq recipients author))
6810 ;; Convert string to a list of (("foo@bar" . "Name <Foo@BAR>") ...).
6814 (if message-alter-recipients-function
6815 (funcall message-alter-recipients-function
6816 (cons (downcase (mail-strip-quoted-names addr))
6818 (cons (downcase (mail-strip-quoted-names addr)) addr)))
6819 (message-tokenize-header recipients)))
6820 ;; Remove all duplicates.
6821 (let ((s recipients))
6823 (let ((address (car (pop s))))
6824 (while (assoc address s)
6825 (setq recipients (delq (assoc address s) recipients)
6826 s (delq (assoc address s) s))))))
6828 ;; Remove hierarchical lists that are contained within each other,
6829 ;; if message-hierarchical-addresses is defined.
6830 (when message-hierarchical-addresses
6831 (let ((plain-addrs (mapcar 'car recipients))
6834 (setq subaddrs (assoc (car plain-addrs)
6835 message-hierarchical-addresses)
6836 plain-addrs (cdr plain-addrs))
6838 (setq subaddrs (cdr subaddrs))
6840 (setq recip (assoc (car subaddrs) recipients)
6841 subaddrs (cdr subaddrs))
6843 (setq recipients (delq recip recipients))))))))
6845 (setq recipients (message-prune-recipients recipients))
6847 ;; Build the header alist. Allow the user to be asked whether
6848 ;; or not to reply to all recipients in a wide reply.
6849 (setq follow-to (list (cons 'To (cdr (pop recipients)))))
6850 (when (and recipients
6851 (or (not message-wide-reply-confirm-recipients)
6852 (y-or-n-p "Reply to all recipients? ")))
6853 (setq recipients (mapconcat
6854 (lambda (addr) (cdr addr)) recipients ", "))
6855 (if (string-match "^ +" recipients)
6856 (setq recipients (substring recipients (match-end 0))))
6857 (push (cons 'Cc recipients) follow-to)))
6860 (defun message-prune-recipients (recipients)
6861 (dolist (rule message-prune-recipient-rules)
6862 (let ((match (car rule))
6865 (dolist (recipient recipients)
6866 (setq address (car recipient))
6867 (when (string-match match address)
6868 (setq dup-match (replace-match (cadr rule) nil nil address))
6869 (dolist (recipient recipients)
6870 ;; Don't delete the address that triggered this.
6871 (when (and (not (eq address (car recipient)))
6872 (string-match dup-match (car recipient)))
6873 (setq recipients (delq recipient recipients))))))))
6876 (defcustom message-simplify-subject-functions
6877 '(message-strip-list-identifiers
6878 message-strip-subject-re
6879 message-strip-subject-trailing-was
6880 message-strip-subject-encoded-words)
6881 "List of functions taking a string argument that simplify subjects.
6882 The functions are applied when replying to a message.
6884 Useful functions to put in this list include:
6885 `message-strip-list-identifiers', `message-strip-subject-re',
6886 `message-strip-subject-trailing-was', and
6887 `message-strip-subject-encoded-words'."
6888 :version "22.1" ;; Gnus 5.10.9
6889 :group 'message-various
6890 :type '(repeat function))
6892 (defun message-simplify-subject (subject &optional functions)
6893 "Return simplified SUBJECT."
6896 (setq functions message-simplify-subject-functions))
6897 (when (and (memq 'message-strip-list-identifiers functions)
6898 gnus-list-identifiers)
6899 (setq subject (message-strip-list-identifiers subject)))
6900 (when (memq 'message-strip-subject-re functions)
6901 (setq subject (concat "Re: " (message-strip-subject-re subject))))
6902 (when (and (memq 'message-strip-subject-trailing-was functions)
6903 message-subject-trailing-was-query)
6904 (setq subject (message-strip-subject-trailing-was subject)))
6905 (when (memq 'message-strip-subject-encoded-words functions)
6906 (setq subject (message-strip-subject-encoded-words subject)))
6910 (defun message-reply (&optional to-address wide switch-function)
6911 "Start editing a reply to the article in the current buffer."
6913 (require 'gnus-sum) ; for gnus-list-identifiers
6914 (let ((cur (current-buffer))
6916 references message-id follow-to
6917 (inhibit-point-motion-hooks t)
6918 (message-this-is-mail t)
6921 (message-narrow-to-head-1)
6922 ;; Allow customizations to have their say.
6924 ;; This is a regular reply.
6925 (when (functionp message-reply-to-function)
6927 (setq follow-to (funcall message-reply-to-function))))
6928 ;; This is a followup.
6929 (when (functionp message-wide-reply-to-function)
6932 (funcall message-wide-reply-to-function)))))
6933 (setq message-id (message-fetch-field "message-id" t)
6934 references (message-fetch-field "references")
6935 date (message-fetch-field "date")
6936 from (or (message-fetch-field "from") "nobody")
6937 subject (or (message-fetch-field "subject") "none"))
6939 ;; Strip list identifiers, "Re: ", and "was:"
6940 (setq subject (message-simplify-subject subject))
6942 (when (and (setq gnus-warning (message-fetch-field "gnus-warning"))
6943 (string-match "<[^>]+>" gnus-warning))
6944 (setq message-id (match-string 0 gnus-warning)))
6947 (setq follow-to (message-get-reply-headers wide to-address))))
6950 `((Subject . ,subject)
6952 (unless (message-mail-user-agent)
6953 (message-pop-to-buffer
6954 (message-buffer-name
6955 (if wide "wide reply" "reply") from
6956 (if wide to-address nil))
6958 (setq message-reply-headers
6959 (vector 0 (cdr (assq 'Subject headers))
6960 from date message-id references 0 0 ""))
6961 (message-setup headers cur))))
6964 (defun message-wide-reply (&optional to-address)
6965 "Make a \"wide\" reply to the message in the current buffer."
6967 (message-reply to-address t))
6970 (defun message-followup (&optional to-newsgroups)
6971 "Follow up to the message in the current buffer.
6972 If TO-NEWSGROUPS, use that as the new Newsgroups line."
6974 (require 'gnus-sum) ; for gnus-list-identifiers
6975 (let ((cur (current-buffer))
6976 from subject date reply-to mrt mct
6977 references message-id follow-to
6978 (inhibit-point-motion-hooks t)
6979 (message-this-is-news t)
6980 followup-to distribution newsgroups gnus-warning posted-to)
6983 (goto-char (point-min))
6984 (if (search-forward "\n\n" nil t)
6987 (when (functionp message-followup-to-function)
6989 (funcall message-followup-to-function)))
6990 (setq from (message-fetch-field "from")
6991 date (message-fetch-field "date")
6992 subject (or (message-fetch-field "subject") "none")
6993 references (message-fetch-field "references")
6994 message-id (message-fetch-field "message-id" t)
6995 followup-to (message-fetch-field "followup-to")
6996 newsgroups (message-fetch-field "newsgroups")
6997 posted-to (message-fetch-field "posted-to")
6998 reply-to (message-fetch-field "reply-to")
6999 mrt (message-fetch-field "mail-reply-to")
7000 distribution (message-fetch-field "distribution")
7001 mct (message-fetch-field "mail-copies-to"))
7002 (when (and (setq gnus-warning (message-fetch-field "gnus-warning"))
7003 (string-match "<[^>]+>" gnus-warning))
7004 (setq message-id (match-string 0 gnus-warning)))
7005 ;; Remove bogus distribution.
7006 (when (and (stringp distribution)
7007 (let ((case-fold-search t))
7008 (string-match "world" distribution)))
7009 (setq distribution nil))
7010 ;; Strip list identifiers, "Re: ", and "was:"
7011 (setq subject (message-simplify-subject subject))
7014 (message-pop-to-buffer (message-buffer-name "followup" from newsgroups))
7016 (setq message-reply-headers
7017 (vector 0 subject from date message-id references 0 0 ""))
7020 `((Subject . ,subject)
7023 (list (cons 'Newsgroups to-newsgroups)))
7024 (follow-to follow-to)
7025 ((and followup-to message-use-followup-to)
7028 ((equal (downcase followup-to) "poster")
7029 (if (or (eq message-use-followup-to 'use)
7030 (message-y-or-n-p "Obey Followup-To: poster? " t "\
7031 You should normally obey the Followup-To: header.
7033 `Followup-To: poster' sends your response via e-mail instead of news.
7035 A typical situation where `Followup-To: poster' is used is when the poster
7036 does not read the newsgroup, so he wouldn't see any replies sent to it.
7038 You may customize the variable `message-use-followup-to', if you
7039 want to get rid of this query permanently."))
7041 (setq message-this-is-news nil)
7042 (cons 'To (or mrt reply-to from "")))
7043 (cons 'Newsgroups newsgroups)))
7045 (if (or (equal followup-to newsgroups)
7046 (not (eq message-use-followup-to 'ask))
7048 (concat "Obey Followup-To: " followup-to "? ") t "\
7049 You should normally obey the Followup-To: header.
7051 `Followup-To: " followup-to "'
7052 directs your response to " (if (string-match "," followup-to)
7053 "the specified newsgroups"
7054 "that newsgroup only") ".
7056 If a message is posted to several newsgroups, Followup-To is often
7057 used to direct the following discussion to one newsgroup only,
7058 because discussions that are spread over several newsgroup tend to
7059 be fragmented and very difficult to follow.
7061 Also, some source/announcement newsgroups are not intended for discussion;
7062 responses here are directed to other newsgroups.
7064 You may customize the variable `message-use-followup-to', if you
7065 want to get rid of this query permanently."))
7066 (cons 'Newsgroups followup-to)
7067 (cons 'Newsgroups newsgroups))))))
7069 `((Newsgroups . ,posted-to)))
7071 `((Newsgroups . ,newsgroups))))
7072 ,@(and distribution (list (cons 'Distribution distribution)))
7074 (not (or (equal (downcase mct) "never")
7075 (equal (downcase mct) "nobody"))))
7076 (list (cons 'Cc (if (or (equal (downcase mct) "always")
7077 (equal (downcase mct) "poster"))
7078 (or mrt reply-to from "")
7083 (defun message-is-yours-p ()
7084 "Non-nil means current article is yours.
7085 If you have added `cancel-messages' to `message-shoot-gnksa-feet', all articles
7086 are yours except those that have Cancel-Lock header not belonging to you.
7087 Instead of shooting GNKSA feet, you should modify `message-alternative-emails'
7088 to match all of yours addresses."
7089 ;; Canlock-logic as suggested by Per Abrahamsen
7090 ;; <abraham@dina.kvl.dk>
7092 ;; IF article has cancel-lock THEN
7093 ;; IF we can verify it THEN
7096 ;; error: cancellock: article is not yours
7098 ;; Use old rules, comparing sender...
7101 (message-narrow-to-head-1)
7102 (if (and (message-fetch-field "Cancel-Lock")
7103 (message-gnksa-enable-p 'canlock-verify))
7104 (if (null (canlock-verify))
7106 (error "Failed to verify Cancel-lock: This article is not yours"))
7109 (message-gnksa-enable-p 'cancel-messages)
7110 (and (setq sender (message-fetch-field "sender"))
7111 (string-equal (downcase sender)
7112 (downcase (message-make-sender))))
7113 ;; Email address in From field equals to our address
7114 (and (setq from (message-fetch-field "from"))
7116 (downcase (car (mail-header-parse-address from)))
7117 (downcase (car (mail-header-parse-address
7118 (message-make-from))))))
7119 ;; Email address in From field matches
7120 ;; 'message-alternative-emails' regexp or function.
7122 message-alternative-emails
7123 (cond ((functionp message-alternative-emails)
7124 (funcall message-alternative-emails
7125 (mail-header-parse-address from)))
7126 (t (string-match message-alternative-emails
7127 (car (mail-header-parse-address from))))))))))))
7130 (defun message-cancel-news (&optional arg)
7131 "Cancel an article you posted.
7132 If ARG, allow editing of the cancellation message."
7134 (unless (message-news-p)
7135 (error "This is not a news article; canceling is impossible"))
7136 (let (from newsgroups message-id distribution buf)
7138 ;; Get header info from original article.
7140 (message-narrow-to-head-1)
7141 (setq from (message-fetch-field "from")
7142 newsgroups (message-fetch-field "newsgroups")
7143 message-id (message-fetch-field "message-id" t)
7144 distribution (message-fetch-field "distribution")))
7145 ;; Make sure that this article was written by the user.
7146 (unless (message-is-yours-p)
7147 (error "This article is not yours"))
7148 (when (yes-or-no-p "Do you really want to cancel this article? ")
7149 ;; Make control message.
7152 (setq buf (set-buffer (get-buffer-create " *message cancel*"))))
7154 (insert "Newsgroups: " newsgroups "\n"
7156 "Subject: cancel " message-id "\n"
7157 "Control: cancel " message-id "\n"
7159 (concat "Distribution: " distribution "\n")
7161 mail-header-separator "\n"
7162 message-cancel-message)
7163 (run-hooks 'message-cancel-hook)
7165 (message "Canceling your article...")
7166 (if (let ((message-syntax-checks
7167 'dont-check-for-anything-just-trust-me))
7168 (funcall message-send-news-function))
7169 (message "Canceling your article...done"))
7170 (kill-buffer buf))))))
7173 (defun message-supersede ()
7174 "Start composing a message to supersede the current message.
7175 This is done simply by taking the old article and adding a Supersedes
7176 header line with the old Message-ID."
7178 (let ((cur (current-buffer)))
7179 ;; Check whether the user owns the article that is to be superseded.
7180 (unless (message-is-yours-p)
7181 (error "This article is not yours"))
7182 ;; Get a normal message buffer.
7183 (message-pop-to-buffer (message-buffer-name "supersede"))
7184 (insert-buffer-substring cur)
7186 (message-narrow-to-head-1)
7187 ;; Remove unwanted headers.
7188 (when message-ignored-supersedes-headers
7189 (message-remove-header message-ignored-supersedes-headers t))
7190 (goto-char (point-min))
7191 (if (not (re-search-forward "^Message-ID: " nil t))
7192 (error "No Message-ID in this article")
7193 (replace-match "Supersedes: " t t))
7194 (goto-char (point-max))
7195 (insert mail-header-separator)
7200 (defun message-recover ()
7201 "Reread contents of current buffer from its last auto-save file."
7203 (let ((file-name (make-auto-save-file-name)))
7204 (cond ((save-window-excursion
7205 (with-output-to-temp-buffer "*Directory*"
7206 (with-current-buffer standard-output
7208 (buffer-disable-undo standard-output)
7209 (let ((default-directory "/"))
7211 "ls" nil standard-output nil "-l" file-name)))
7212 (yes-or-no-p (format "Recover auto save file %s? " file-name)))
7213 (let ((buffer-read-only nil))
7215 (insert-file-contents file-name nil)))
7216 (t (error "message-recover canceled")))))
7218 ;;; Washing Subject:
7220 (defun message-wash-subject (subject)
7221 "Remove junk like \"Re:\", \"(fwd)\", etc. added to subject string SUBJECT.
7222 Previous forwarders, repliers, etc. may add it."
7225 (goto-char (point-min))
7226 ;; strip Re/Fwd stuff off the beginning
7227 (while (re-search-forward
7228 "\\([Rr][Ee]:\\|[Ff][Ww][Dd]\\(\\[[0-9]*\\]\\)?:\\|[Ff][Ww]:\\)" nil t)
7231 ;; and gnus-style forwards [foo@bar.com] subject
7232 (goto-char (point-min))
7233 (while (re-search-forward "\\[[^ \t]*\\(@\\|\\.\\)[^ \t]*\\]" nil t)
7237 (goto-char (point-max))
7238 (while (re-search-backward "([Ff][Ww][Dd])" nil t)
7241 ;; and finally, any whitespace that was left-over
7242 (goto-char (point-min))
7243 (while (re-search-forward "^[ \t]+" nil t)
7245 (goto-char (point-max))
7246 (while (re-search-backward "[ \t]+$" nil t)
7251 ;;; Forwarding messages.
7253 (defvar message-forward-decoded-p nil
7254 "Non-nil means the original message is decoded.")
7256 (defun message-forward-subject-name-subject (subject)
7257 "Generate a SUBJECT for a forwarded message.
7258 The form is: [Source] Subject, where if the original message was mail,
7259 Source is the name of the sender, and if the original message was
7260 news, Source is the list of newsgroups is was posted to."
7261 (let* ((group (message-fetch-field "newsgroups"))
7262 (from (message-fetch-field "from"))
7265 (gnus-group-decoded-name group)
7267 (car (gnus-extract-address-components from))
7268 (cadr (gnus-extract-address-components from))))
7271 (if message-forward-decoded-p
7273 (mail-decode-encoded-word-string prefix))
7276 (defun message-forward-subject-author-subject (subject)
7277 "Generate a SUBJECT for a forwarded message.
7278 The form is: [Source] Subject, where if the original message was mail,
7279 Source is the sender, and if the original message was news, Source is
7280 the list of newsgroups is was posted to."
7281 (let* ((group (message-fetch-field "newsgroups"))
7284 (gnus-group-decoded-name group)
7285 (or (message-fetch-field "from")
7288 (if message-forward-decoded-p
7290 (mail-decode-encoded-word-string prefix))
7293 (defun message-forward-subject-fwd (subject)
7294 "Generate a SUBJECT for a forwarded message.
7295 The form is: Fwd: Subject, where Subject is the original subject of
7297 (if (string-match "^Fwd: " subject)
7299 (concat "Fwd: " subject)))
7301 (defun message-make-forward-subject ()
7302 "Return a Subject header suitable for the message in the current buffer."
7305 (message-narrow-to-head-1)
7306 (let ((funcs message-make-forward-subject-function)
7307 (subject (message-fetch-field "Subject")))
7310 (if message-forward-decoded-p
7312 (mail-decode-encoded-word-string subject))
7314 (when message-wash-forwarded-subjects
7315 (setq subject (message-wash-subject subject)))
7316 ;; Make sure funcs is a list.
7319 (setq funcs (list funcs)))
7320 ;; Apply funcs in order, passing subject generated by previous
7321 ;; func to the next one.
7322 (dolist (func funcs)
7323 (when (functionp func)
7324 (setq subject (funcall func subject))))
7327 (defvar gnus-article-decoded-p)
7331 (defun message-forward (&optional news digest)
7332 "Forward the current message via mail.
7333 Optional NEWS will use news to forward instead of mail.
7334 Optional DIGEST will use digest to forward."
7336 (let* ((cur (current-buffer))
7337 (message-forward-decoded-p
7338 (if (local-variable-p 'gnus-article-decoded-p (current-buffer))
7339 gnus-article-decoded-p ;; In an article buffer.
7340 message-forward-decoded-p))
7341 (subject (message-make-forward-subject)))
7343 (message-news nil subject)
7344 (message-mail nil subject))
7345 (message-forward-make-body cur digest)))
7347 (defun message-forward-make-body-plain (forward-buffer)
7349 "\n-------------------- Start of forwarded message --------------------\n")
7351 (contents (with-current-buffer forward-buffer (buffer-string)))
7353 (unless (multibyte-string-p contents)
7354 (error "Attempt to insert unibyte string from the buffer \"%s\"\
7355 to the multibyte buffer \"%s\""
7356 (if (bufferp forward-buffer)
7357 (buffer-name forward-buffer)
7360 (insert (mm-with-multibyte-buffer
7363 (goto-char (point-min))
7364 (when (looking-at "From ")
7365 (replace-match "X-From-Line: "))
7367 (unless (bolp) (insert "\n"))
7370 "-------------------- End of forwarded message --------------------\n")
7371 (message-remove-ignored-headers b e)))
7373 (defun message-remove-ignored-headers (b e)
7374 (when (or message-forward-ignored-headers
7375 message-forward-included-headers)
7377 (narrow-to-region b e)
7379 (narrow-to-region (point)
7380 (or (search-forward "\n\n" nil t) (point)))
7381 (when message-forward-ignored-headers
7382 (let ((ignored (if (stringp message-forward-ignored-headers)
7383 (list message-forward-ignored-headers)
7384 message-forward-ignored-headers)))
7385 (dolist (elem ignored)
7386 (message-remove-header elem t))))
7387 (when message-forward-included-headers
7388 (message-remove-header
7389 (if (listp message-forward-included-headers)
7390 (regexp-opt message-forward-included-headers)
7391 message-forward-included-headers)
7394 (defun message-forward-make-body-mime (forward-buffer &optional beg end)
7396 (insert "\n\n<#part type=message/rfc822 disposition=inline raw=t>\n")
7398 (narrow-to-region (point) (point))
7399 (insert-buffer-substring forward-buffer beg end)
7400 (mml-quote-region (point-min) (point-max))
7401 (goto-char (point-min))
7402 (when (looking-at "From ")
7403 (replace-match "X-From-Line: "))
7404 (goto-char (point-max)))
7405 (insert "<#/part>\n")
7406 ;; Consider there is no illegible text.
7407 (add-text-properties
7409 `(no-illegible-text t rear-nonsticky t start-open t))))
7411 (defun message-forward-make-body-mml (forward-buffer)
7412 (insert "\n\n<#mml type=message/rfc822 disposition=inline>\n")
7413 (let ((b (point)) e)
7414 (if (not message-forward-decoded-p)
7415 (let ((contents (with-current-buffer forward-buffer (buffer-string))))
7416 (unless (multibyte-string-p contents)
7417 (error "Attempt to insert unibyte string from the buffer \"%s\"\
7418 to the multibyte buffer \"%s\""
7419 (if (bufferp forward-buffer)
7420 (buffer-name forward-buffer)
7423 (insert (mm-with-multibyte-buffer
7426 (goto-char (point-min))
7427 (when (looking-at "From ")
7428 (replace-match "X-From-Line: "))
7431 (narrow-to-region (point) (point))
7432 (mml-insert-buffer forward-buffer)
7433 (goto-char (point-min))
7434 (when (looking-at "From ")
7435 (replace-match "X-From-Line: "))
7436 (goto-char (point-max))))
7438 (insert "<#/mml>\n")
7439 (when (not message-forward-decoded-p)
7440 (message-remove-ignored-headers b e))))
7442 (defun message-forward-make-body-digest-plain (forward-buffer)
7444 "\n-------------------- Start of forwarded message --------------------\n")
7445 (mml-insert-buffer forward-buffer)
7447 "\n-------------------- End of forwarded message --------------------\n"))
7449 (defun message-forward-make-body-digest-mime (forward-buffer)
7450 (insert "\n<#multipart type=digest>\n")
7451 (let ((b (point)) e)
7452 (insert-buffer-substring forward-buffer)
7454 (insert "<#/multipart>\n")
7456 (narrow-to-region b e)
7458 (narrow-to-region (point)
7459 (or (search-forward "\n\n" nil t) (point)))
7460 (delete-region (point-min) (point-max)))))
7462 (defun message-forward-make-body-digest (forward-buffer)
7463 (if message-forward-as-mime
7464 (message-forward-make-body-digest-mime forward-buffer)
7465 (message-forward-make-body-digest-plain forward-buffer)))
7467 (autoload 'mm-uu-dissect-text-parts "mm-uu")
7468 (autoload 'mm-uu-dissect "mm-uu")
7470 (defun message-signed-or-encrypted-p (&optional dont-emulate-mime handles)
7471 "Say whether the current buffer contains signed or encrypted message.
7472 If DONT-EMULATE-MIME is nil, this function does the MIME emulation on
7473 messages that don't conform to PGP/MIME described in RFC2015. HANDLES
7474 is for the internal use."
7476 (let ((mm-decrypt-option 'never)
7477 (mm-verify-option 'never))
7478 (if (setq handles (mm-dissect-buffer nil t))
7479 (unless dont-emulate-mime
7480 (mm-uu-dissect-text-parts handles))
7481 (unless dont-emulate-mime
7482 (setq handles (mm-uu-dissect))))))
7483 ;; Check text/plain message in which there is a signed or encrypted
7484 ;; body that has been encoded by B or Q.
7485 (unless (or handles dont-emulate-mime)
7486 (let ((cur (current-buffer))
7487 (mm-decrypt-option 'never)
7488 (mm-verify-option 'never))
7490 (insert-buffer-substring cur)
7491 (when (setq handles (mm-dissect-buffer t t))
7492 (if (and (bufferp (car handles))
7493 (equal (mm-handle-media-type handles) "text/plain"))
7496 (insert-buffer-substring (car handles))
7497 (mm-decode-content-transfer-encoding
7498 (mm-handle-encoding handles))
7499 (mm-destroy-parts handles)
7500 (setq handles (mm-uu-dissect)))
7501 (mm-destroy-parts handles)
7502 (setq handles nil))))))
7506 (dolist (handle (if (stringp (car handles))
7507 (if (member (car handles)
7508 '("multipart/signed"
7509 "multipart/encrypted"))
7513 (if (stringp (car handle))
7514 (when (message-signed-or-encrypted-p dont-emulate-mime handle)
7516 (when (and (bufferp (car handle))
7517 (equal (mm-handle-media-type handle)
7519 (with-current-buffer (mm-handle-buffer handle)
7520 (when (message-signed-or-encrypted-p dont-emulate-mime)
7521 (throw 'found t)))))))
7522 (mm-destroy-parts handles))))
7525 (defun message-forward-make-body (forward-buffer &optional digest)
7526 ;; Put point where we want it before inserting the forwarded
7528 (if message-forward-before-signature
7530 (goto-char (point-max)))
7532 (message-forward-make-body-digest forward-buffer)
7533 (if message-forward-as-mime
7534 (if (and message-forward-show-mml
7535 (not (and (eq message-forward-show-mml 'best)
7536 ;; Use the raw form in the body if it contains
7537 ;; signed or encrypted message so as not to be
7538 ;; destroyed by re-encoding.
7539 (with-current-buffer forward-buffer
7541 (message-signed-or-encrypted-p)
7543 (message-forward-make-body-mml forward-buffer)
7544 (message-forward-make-body-mime forward-buffer))
7545 (message-forward-make-body-plain forward-buffer)))
7546 (message-position-point))
7548 (declare-function rmail-toggle-header "rmail" (&optional arg))
7551 (defun message-forward-rmail-make-body (forward-buffer)
7552 (save-window-excursion
7553 (set-buffer forward-buffer)
7554 (when (rmail-msg-is-pruned)
7555 (rmail-toggle-header 0)))
7556 (message-forward-make-body forward-buffer))
7558 ;; Fixme: Should have defcustom.
7560 (defun message-insinuate-rmail ()
7561 "Let RMAIL use message to forward."
7563 (setq rmail-enable-mime-composing t)
7564 (setq rmail-insert-mime-forwarded-message-function
7565 'message-forward-rmail-make-body))
7567 (defvar message-inhibit-body-encoding nil)
7570 (defun message-resend (address)
7571 "Resend the current article to ADDRESS."
7573 (list (message-read-from-minibuffer "Resend message to: ")))
7574 (message "Resending message to %s..." address)
7576 (let ((cur (current-buffer))
7578 ;; We first set up a normal mail buffer.
7579 (unless (message-mail-user-agent)
7580 (set-buffer (get-buffer-create " *message resend*"))
7581 (let ((inhibit-read-only t))
7583 (let ((message-this-is-mail t)
7584 message-generate-hashcash
7586 (message-setup `((To . ,address))))
7587 ;; Insert our usual headers.
7588 (message-generate-headers '(From Date To Message-ID))
7589 (message-narrow-to-headers)
7590 (when (setq gcc (mail-fetch-field "gcc" nil t))
7591 (message-remove-header "gcc"))
7592 ;; Remove X-Draft-From header etc.
7593 (message-remove-header message-ignored-mail-headers t)
7594 ;; Rename them all to "Resent-*".
7595 (goto-char (point-min))
7596 (while (re-search-forward "^[A-Za-z]" nil t)
7601 (let ((inhibit-read-only t))
7602 (delete-region (point) (point-max)))
7604 ;; Insert the message to be resent.
7605 (insert-buffer-substring cur)
7606 (goto-char (point-min))
7607 (search-forward "\n\n")
7610 (narrow-to-region beg (point))
7611 (message-remove-header message-ignored-resent-headers t)
7612 (goto-char (point-max)))
7613 (insert mail-header-separator)
7614 ;; Rename all old ("Also-")Resent headers.
7615 (while (re-search-backward "^\\(Also-\\)*Resent-" beg t)
7618 ;; Quote any "From " lines at the beginning.
7620 (when (looking-at "From ")
7621 (replace-match "X-From-Line: "))
7623 (let ((message-inhibit-body-encoding
7624 ;; Don't do any further encoding if it looks like the
7625 ;; message has already been encoded.
7626 (let ((case-fold-search t))
7627 (re-search-forward "^mime-version:" nil t)))
7628 (message-inhibit-ecomplete t)
7629 ;; We don't want smtpmail.el to encode anything, either.
7630 (sendmail-coding-system 'raw-text)
7631 (select-safe-coding-system-function nil)
7632 message-required-mail-headers
7633 message-generate-hashcash
7634 rfc2047-encode-encoded-words)
7635 (message-send-mail))
7638 (insert "Gcc: " gcc "\n"))
7639 (run-hooks 'message-sent-hook)
7640 (kill-buffer (current-buffer)))
7641 (message "Resending message to %s...done" address)))
7644 (defun message-bounce ()
7645 "Re-mail the current message.
7646 This only makes sense if the current message is a bounce message that
7647 contains some mail you have written which has been bounced back to
7650 (let ((handles (mm-dissect-buffer t))
7652 (message-pop-to-buffer (message-buffer-name "bounce"))
7653 (if (stringp (car handles))
7654 ;; This is a MIME bounce.
7655 (mm-insert-part (car (last handles)))
7656 ;; This is a non-MIME bounce, so we try to remove things
7658 (mm-insert-part handles)
7660 (goto-char (point-min))
7661 (re-search-forward "\n\n+" nil t)
7662 (setq boundary (point))
7663 ;; We remove everything before the bounced mail.
7664 (if (or (re-search-forward message-unsent-separator nil t)
7666 (search-forward "\n\n" nil 'move)
7667 (re-search-backward "^Return-Path:.*\n" boundary t)))
7670 (delete-region (point-min)
7671 (if (re-search-forward "^[^ \n\t]+:" nil t)
7674 (goto-char boundary)
7675 (when (re-search-backward "^.?From .*\n" nil t)
7676 (delete-region (match-beginning 0) (match-end 0)))))
7679 (message-narrow-to-head-1)
7680 (message-remove-header message-ignored-bounced-headers t)
7681 (goto-char (point-max))
7682 (insert mail-header-separator))
7683 (message-position-point)))
7686 ;;; Interactive entry points for new message buffers.
7690 (defun message-mail-other-window (&optional to subject)
7691 "Like `message-mail' command, but display mail buffer in another window."
7693 (unless (message-mail-user-agent)
7694 (message-pop-to-buffer (message-buffer-name "mail" to)
7695 'switch-to-buffer-other-window))
7696 (let ((message-this-is-mail t))
7697 (message-setup `((To . ,(or to "")) (Subject . ,(or subject "")))
7698 nil nil nil 'switch-to-buffer-other-window)))
7701 (defun message-mail-other-frame (&optional to subject)
7702 "Like `message-mail' command, but display mail buffer in another frame."
7704 (unless (message-mail-user-agent)
7705 (message-pop-to-buffer (message-buffer-name "mail" to)
7706 'switch-to-buffer-other-frame))
7707 (let ((message-this-is-mail t))
7708 (message-setup `((To . ,(or to "")) (Subject . ,(or subject "")))
7709 nil nil nil 'switch-to-buffer-other-frame)))
7712 (defun message-news-other-window (&optional newsgroups subject)
7713 "Start editing a news article to be sent."
7715 (message-pop-to-buffer (message-buffer-name "posting" nil newsgroups)
7716 'switch-to-buffer-other-window)
7717 (let ((message-this-is-news t))
7718 (message-setup `((Newsgroups . ,(or newsgroups ""))
7719 (Subject . ,(or subject ""))))))
7722 (defun message-news-other-frame (&optional newsgroups subject)
7723 "Start editing a news article to be sent."
7725 (message-pop-to-buffer (message-buffer-name "posting" nil newsgroups)
7726 'switch-to-buffer-other-frame)
7727 (let ((message-this-is-news t))
7728 (message-setup `((Newsgroups . ,(or newsgroups ""))
7729 (Subject . ,(or subject ""))))))
7733 ;; This code should be moved to underline.el (from which it is stolen).
7736 (defun message-bold-region (start end)
7737 "Bold all nonblank characters in the region.
7738 Works by overstriking characters.
7739 Called from program, takes two arguments START and END
7740 which specify the range to operate on."
7743 (let ((end1 (make-marker)))
7744 (move-marker end1 (max start end))
7745 (goto-char (min start end))
7746 (while (< (point) end1)
7747 (or (looking-at "[_\^@- ]")
7748 (insert (char-after) "\b"))
7749 (forward-char 1)))))
7752 (defun message-unbold-region (start end)
7753 "Remove all boldness (overstruck characters) in the region.
7754 Called from program, takes two arguments START and END
7755 which specify the range to operate on."
7758 (let ((end1 (make-marker)))
7759 (move-marker end1 (max start end))
7760 (goto-char (min start end))
7761 (while (search-forward "\b" end1 t)
7762 (if (eq (char-after) (char-after (- (point) 2)))
7763 (delete-char -2))))))
7765 (defun message-exchange-point-and-mark ()
7766 "Exchange point and mark, but don't activate region if it was inactive."
7767 (goto-char (prog1 (mark t)
7768 (set-marker (mark-marker) (point)))))
7770 ;; Support for toolbar
7771 (defvar tool-bar-mode)
7773 ;; Note: The :set function in the `message-tool-bar*' variables will only
7774 ;; affect _new_ message buffers. We might add a function that walks thru all
7775 ;; message-mode buffers and force the update.
7776 (defun message-tool-bar-update (&optional symbol value)
7777 "Update message mode toolbar.
7778 Setter function for custom variables."
7779 (setq-default message-tool-bar-map nil)
7781 ;; When used as ":set" function:
7782 (set-default symbol value)))
7784 (defcustom message-tool-bar (if (eq gmm-tool-bar-style 'gnome)
7785 'message-tool-bar-gnome
7786 'message-tool-bar-retro)
7787 "Specifies the message mode tool bar.
7789 It can be either a list or a symbol referring to a list. See
7790 `gmm-tool-bar-from-list' for the format of the list. The
7791 default key map is `message-mode-map'.
7793 Pre-defined symbols include `message-tool-bar-gnome' and
7794 `message-tool-bar-retro'."
7795 :type '(repeat gmm-tool-bar-list-item)
7796 :type '(choice (const :tag "GNOME style" message-tool-bar-gnome)
7797 (const :tag "Retro look" message-tool-bar-retro)
7798 (repeat :tag "User defined list" gmm-tool-bar-item)
7800 :version "23.1" ;; No Gnus
7801 :initialize 'custom-initialize-default
7802 :set 'message-tool-bar-update
7805 (defcustom message-tool-bar-gnome
7806 '((ispell-message "spell" nil
7808 :visible (not flyspell-mode))
7809 (flyspell-buffer "spell" t
7811 :visible flyspell-mode
7812 :help "Flyspell whole buffer")
7813 (message-send-and-exit "mail/send" t :label "Send")
7814 (message-dont-send "mail/save-draft")
7815 (mml-attach-file "attach" mml-mode-map :vert-only t)
7816 (mml-preview "mail/preview" mml-mode-map)
7817 (mml-secure-message-sign-encrypt "lock" mml-mode-map :visible nil)
7818 (message-insert-importance-high "important" nil :visible nil)
7819 (message-insert-importance-low "unimportant" nil :visible nil)
7820 (message-insert-disposition-notification-to "receipt" nil :visible nil))
7821 "List of items for the message tool bar (GNOME style).
7823 See `gmm-tool-bar-from-list' for details on the format of the list."
7824 :type '(repeat gmm-tool-bar-item)
7825 :version "23.1" ;; No Gnus
7826 :initialize 'custom-initialize-default
7827 :set 'message-tool-bar-update
7830 (defcustom message-tool-bar-retro
7831 '(;; Old Emacs 21 icon for consistency.
7832 (message-send-and-exit "gnus/mail-send")
7833 (message-kill-buffer "close")
7834 (message-dont-send "cancel")
7835 (mml-attach-file "attach" mml-mode-map)
7836 (ispell-message "spell")
7837 (mml-preview "preview" mml-mode-map)
7838 (message-insert-importance-high "gnus/important")
7839 (message-insert-importance-low "gnus/unimportant")
7840 (message-insert-disposition-notification-to "gnus/receipt"))
7841 "List of items for the message tool bar (retro style).
7843 See `gmm-tool-bar-from-list' for details on the format of the list."
7844 :type '(repeat gmm-tool-bar-item)
7845 :version "23.1" ;; No Gnus
7846 :initialize 'custom-initialize-default
7847 :set 'message-tool-bar-update
7850 (defcustom message-tool-bar-zap-list
7851 '(new-file open-file dired kill-buffer write-file
7852 print-buffer customize help)
7853 "List of icon items from the global tool bar.
7854 These items are not displayed on the message mode tool bar.
7856 See `gmm-tool-bar-from-list' for the format of the list."
7857 :type 'gmm-tool-bar-zap-list
7858 :version "23.1" ;; No Gnus
7859 :initialize 'custom-initialize-default
7860 :set 'message-tool-bar-update
7863 (defvar image-load-path)
7865 (defun message-make-tool-bar (&optional force)
7866 "Make a message mode tool bar from `message-tool-bar-list'.
7867 When FORCE, rebuild the tool bar."
7868 (when (and (boundp 'tool-bar-mode)
7870 (or (not message-tool-bar-map) force))
7871 (setq message-tool-bar-map
7873 (image-load-path-for-library
7874 "message" "mail/save-draft.xpm" nil t))
7875 (image-load-path (cons (car load-path) image-load-path)))
7876 (gmm-tool-bar-from-list message-tool-bar
7877 message-tool-bar-zap-list
7878 'message-mode-map))))
7879 message-tool-bar-map)
7881 ;;; Group name completion.
7883 (defcustom message-newgroups-header-regexp
7884 "^\\(Newsgroups\\|Followup-To\\|Posted-To\\|Gcc\\):"
7885 "Regexp that match headers that lists groups."
7889 (defcustom message-completion-alist
7890 (list (cons message-newgroups-header-regexp 'message-expand-group)
7891 '("^\\(Resent-\\)?\\(To\\|B?Cc\\):" . message-expand-name)
7892 '("^\\(Reply-To\\|From\\|Mail-Followup-To\\|Mail-Copies-To\\):"
7893 . message-expand-name)
7894 '("^\\(Disposition-Notification-To\\|Return-Receipt-To\\):"
7895 . message-expand-name))
7896 "Alist of (RE . FUN). Use FUN for completion on header lines matching RE."
7899 :type '(alist :key-type regexp :value-type function))
7901 (defcustom message-expand-name-databases
7903 "List of databases to try for name completion (`message-expand-name').
7904 Each element is a symbol and can be `bbdb' or `eudc'."
7906 :type '(set (const bbdb) (const eudc)))
7908 (defcustom message-tab-body-function nil
7909 "*Function to execute when `message-tab' (TAB) is executed in the body.
7910 If nil, the function bound in `text-mode-map' or `global-map' is executed."
7913 :link '(custom-manual "(message)Various Commands")
7914 :type '(choice (const nil)
7917 (declare-function mail-abbrev-in-expansion-header-p "mailabbrev" ())
7919 (defun message-tab ()
7920 "Complete names according to `message-completion-alist'.
7921 Execute function specified by `message-tab-body-function' when
7922 not in those headers. If that variable is nil, indent with the
7923 regular text mode tabbing command."
7926 ((let ((completion-fail-discreetly t))
7927 (completion-at-point))
7928 ;; Completion was performed; nothing else to do.
7930 (message-tab-body-function (funcall message-tab-body-function))
7931 (t (funcall (or (lookup-key text-mode-map "\t")
7932 (lookup-key global-map "\t")
7933 'indent-relative)))))
7935 (defvar mail-abbrev-mode-regexp)
7937 (defun message-completion-function ()
7938 (let ((alist message-completion-alist))
7940 (let ((mail-abbrev-mode-regexp (caar alist)))
7941 (not (mail-abbrev-in-expansion-header-p))))
7942 (setq alist (cdr alist)))
7944 (lexical-let ((fun (cdar alist)))
7945 ;; Even if completion fails, return a non-nil value, so as to avoid
7946 ;; falling back to message-tab-body-function.
7947 (lambda () (funcall fun) 'completion-attempted)))))
7949 (defun message-expand-group ()
7950 "Expand the group name under point."
7951 (let ((b (save-excursion
7956 (skip-chars-forward "^:")
7959 (skip-chars-backward "^, \t\n") (point))))
7960 (completion-ignore-case t)
7961 (e (progn (skip-chars-forward "^,\t\n ") (point)))
7963 (when (and (boundp 'gnus-active-hashtb)
7967 (setq group (symbol-name symbol))
7968 (push (if (string-match "[^\000-\177]" group)
7969 (gnus-group-decoded-name group)
7972 gnus-active-hashtb))
7973 (completion-in-region b e collection)))
7975 (defun message-expand-name ()
7976 (cond ((and (memq 'eudc message-expand-name-databases)
7977 (boundp 'eudc-protocol)
7979 (eudc-expand-inline))
7980 ((and (memq 'bbdb message-expand-name-databases)
7981 (fboundp 'bbdb-complete-name))
7982 (let ((starttick (buffer-modified-tick)))
7983 (or (bbdb-complete-name)
7984 ;; Apparently, bbdb-complete-name can return nil even when
7985 ;; completion took place. So let's double check the buffer was
7987 (/= starttick (buffer-modified-tick)))))
7993 (defun message-talkative-question (ask question show &rest text)
7994 "Call FUNCTION with argument QUESTION; optionally display TEXT... args.
7995 If SHOW is non-nil, the arguments TEXT... are displayed in a temp buffer.
7996 The following arguments may contain lists of values."
7998 (setq text (message-flatten-list text)))
7999 (save-window-excursion
8000 (with-output-to-temp-buffer " *MESSAGE information message*"
8001 (with-current-buffer " *MESSAGE information message*"
8004 (goto-char (point-min))))
8005 (funcall ask question))
8006 (funcall ask question)))
8008 (defun message-flatten-list (list)
8009 "Return a new, flat list that contains all elements of LIST.
8011 \(message-flatten-list \\='(1 (2 3 (4 5 (6))) 7))
8014 (apply 'append (mapcar 'message-flatten-list list)))
8018 (defun message-generate-new-buffer-clone-locals (name &optional varstr)
8019 "Create and return a buffer with name based on NAME using `generate-new-buffer'.
8020 Then clone the local variables and values from the old buffer to the
8021 new one, cloning only the locals having a substring matching the
8023 (let ((oldbuf (current-buffer)))
8024 (with-current-buffer (generate-new-buffer name)
8025 (message-clone-locals oldbuf varstr)
8028 (defun message-clone-locals (buffer &optional varstr)
8029 "Clone the local variables from BUFFER to the current buffer."
8030 (let ((locals (with-current-buffer buffer (buffer-local-variables)))
8031 (regexp "^gnus\\|^nn\\|^message\\|^sendmail\\|^smtp\\|^user-mail-address"))
8034 (when (and (consp local)
8036 (string-match regexp (symbol-name (car local)))
8038 (string-match varstr (symbol-name (car local)))))
8040 (set (make-local-variable (car local))
8048 (defun message-encode-message-body ()
8049 (unless message-inhibit-body-encoding
8050 (let ((mail-parse-charset (or mail-parse-charset
8051 message-default-charset))
8052 (case-fold-search t)
8053 lines content-type-p)
8056 (narrow-to-region (point) (point-max))
8057 (let ((new (mml-generate-mime)))
8059 (delete-region (point-min) (point-max))
8061 (goto-char (point-min))
8062 (if (eq (aref new 0) ?\n)
8064 (search-forward "\n\n")
8065 (setq lines (buffer-substring (point-min) (1- (point))))
8066 (delete-region (point-min) (point))))))
8068 (message-narrow-to-headers-or-head)
8069 (message-remove-header "Mime-Version")
8070 (goto-char (point-max))
8071 (insert "MIME-Version: 1.0\n")
8074 (setq content-type-p
8076 (re-search-backward "^Content-Type:" nil t))))
8078 (message-narrow-to-headers-or-head)
8079 (message-remove-first-header "Content-Type")
8080 (message-remove-first-header "Content-Transfer-Encoding"))
8081 ;; We always make sure that the message has a Content-Type
8082 ;; header. This is because some broken MTAs and MUAs get
8083 ;; awfully confused when confronted with a message with a
8084 ;; MIME-Version header and without a Content-Type header. For
8085 ;; instance, Solaris' /usr/bin/mail.
8086 (unless content-type-p
8087 (goto-char (point-min))
8088 ;; For unknown reason, MIME-Version doesn't exist.
8089 (when (re-search-forward "^MIME-Version:" nil t)
8091 (insert "Content-Type: text/plain; charset=us-ascii\n"))))))
8093 (defun message-read-from-minibuffer (prompt &optional initial-contents)
8094 "Read from the minibuffer while providing abbrev expansion."
8095 (let ((minibuffer-setup-hook 'mail-abbrevs-setup)
8096 (minibuffer-local-map message-minibuffer-local-map))
8097 (read-from-minibuffer prompt initial-contents)))
8099 (defun message-use-alternative-email-as-from ()
8100 "Set From field of the outgoing message to the first matching
8101 address in `message-alternative-emails', looking at To, Cc and
8102 From headers in the original article."
8103 (require 'mail-utils)
8104 (let* ((fields '("To" "Cc" "From"))
8106 (message-tokenize-header
8107 (mail-strip-quoted-names
8108 (mapconcat 'message-fetch-reply-field fields ","))))
8109 (email (cond ((functionp message-alternative-emails)
8110 (car (cl-remove-if-not message-alternative-emails emails)))
8111 (t (loop for email in emails
8112 if (string-match-p message-alternative-emails email)
8114 (unless (or (not email) (equal email user-mail-address))
8115 (message-remove-header "From")
8116 (goto-char (point-max))
8117 (insert "From: " (let ((user-mail-address email)) (message-make-from))
8120 (defun message-options-get (symbol)
8121 (cdr (assq symbol message-options)))
8123 (defun message-options-set (symbol value)
8124 (let ((the-cons (assq symbol message-options)))
8127 (setcdr the-cons value)
8128 (setq message-options (delq the-cons message-options)))
8130 (push (cons symbol value) message-options))))
8133 (defun message-options-set-recipient ()
8135 (message-narrow-to-headers-or-head)
8136 (message-options-set 'message-sender
8137 (mail-strip-quoted-names
8138 (message-fetch-field "from")))
8139 (message-options-set 'message-recipients
8140 (mail-strip-quoted-names
8141 (let ((to (message-fetch-field "to"))
8142 (cc (message-fetch-field "cc"))
8143 (bcc (message-fetch-field "bcc")))
8146 (if (and to cc) ", ")
8148 (if (and (or to cc) bcc) ", ")
8151 (defun message-hide-headers ()
8152 "Hide headers based on the `message-hidden-headers' variable."
8153 (let ((regexps (if (stringp message-hidden-headers)
8154 (list message-hidden-headers)
8155 message-hidden-headers))
8156 (inhibit-point-motion-hooks t)
8157 (inhibit-modification-hooks t)
8158 (end-of-headers (point-min)))
8162 (message-narrow-to-headers)
8163 (goto-char (point-min))
8165 (if (not (message-hide-header-p regexps))
8166 (message-next-header)
8167 (let ((begin (point))
8169 (message-next-header)
8170 (setq header (buffer-substring begin (point))
8171 header-len (- (point) begin))
8172 (delete-region begin (point))
8173 (goto-char end-of-headers)
8175 (setq end-of-headers
8176 (+ end-of-headers header-len))))))))
8177 (narrow-to-region end-of-headers (point-max))))
8179 (defun message-hide-header-p (regexps)
8182 (when (eq (car regexps) 'not)
8185 (dolist (regexp regexps)
8186 (setq result (or result (looking-at regexp))))
8191 (declare-function ecomplete-add-item "ecomplete" (type key text))
8192 (declare-function ecomplete-save "ecomplete" ())
8194 (defun message-put-addresses-in-ecomplete ()
8195 (require 'ecomplete)
8196 (dolist (header '("to" "cc" "from" "reply-to"))
8197 (let ((value (message-field-value header)))
8198 (dolist (string (mail-header-parse-addresses value 'raw))
8200 (replace-regexp-in-string
8202 (replace-regexp-in-string "^ +\\| +$" "" string)))
8203 (ecomplete-add-item 'mail (car (mail-header-parse-address string))
8207 (autoload 'ecomplete-display-matches "ecomplete")
8209 (defun message-display-abbrev (&optional choose)
8210 "Display the next possible abbrev for the text before point."
8211 (interactive (list t))
8212 (when (and (memq (char-after (point-at-bol)) '(?C ?T ?\t ? ))
8213 (message-point-in-header-p)
8216 (while (and (memq (char-after) '(?\t ? ))
8217 (zerop (forward-line -1))))
8218 (looking-at "To:\\|Cc:")))
8219 (let* ((end (point))
8220 (start (save-excursion
8221 (and (re-search-backward "[\n\t ]" nil t)
8223 (word (when start (buffer-substring start end)))
8224 (match (when (and word
8225 (not (zerop (length word))))
8226 (ecomplete-display-matches 'mail word choose))))
8227 (when (and choose match)
8228 (delete-region start end)
8231 ;; To send pre-formatted letters like the example below, you can use
8232 ;; `message-send-form-letter':
8233 ;; --8<---------------cut here---------------start------------->8---
8234 ;; To: alice@invalid.invalid
8235 ;; Subject: Verification of your contact information
8236 ;; From: Contact verification <admin@foo.invalid>
8237 ;; --text follows this line--
8239 ;; please verify that your contact information is still valid:
8240 ;; Alice A, A avenue 11, 1111 A town, Austria
8241 ;; ----------next form letter message follows this line----------
8242 ;; To: bob@invalid.invalid
8243 ;; Subject: Verification of your contact information
8244 ;; From: Contact verification <admin@foo.invalid>
8245 ;; --text follows this line--
8247 ;; please verify that your contact information is still valid:
8248 ;; Bob, B street 22, 22222 Be town, Belgium
8249 ;; ----------next form letter message follows this line----------
8250 ;; To: charlie@invalid.invalid
8251 ;; Subject: Verification of your contact information
8252 ;; From: Contact verification <admin@foo.invalid>
8253 ;; --text follows this line--
8255 ;; please verify that your contact information is still valid:
8256 ;; Charlie Chaplin, C plaza 33, 33333 C town, Chile
8257 ;; --8<---------------cut here---------------end--------------->8---
8259 ;; FIXME: What is the most common term (circular letter, form letter, serial
8260 ;; letter, standard letter) for such kind of letter? See also
8261 ;; <http://en.wikipedia.org/wiki/Form_letter>
8263 ;; FIXME: Maybe extent message-mode's font-lock support to recognize
8264 ;; `message-form-letter-separator', i.e. highlight each message like a single
8267 (defcustom message-form-letter-separator
8268 "\n----------next form letter message follows this line----------\n"
8269 "Separator for `message-send-form-letter'."
8270 ;; :group 'message-form-letter
8271 :group 'message-various
8272 :version "23.1" ;; No Gnus
8275 (defcustom message-send-form-letter-delay 1
8276 "Delay in seconds when sending a message with `message-send-form-letter'.
8277 Only used when `message-send-form-letter' is called with non-nil
8279 ;; :group 'message-form-letter
8280 :group 'message-various
8281 :version "23.1" ;; No Gnus
8284 (defun message-send-form-letter (&optional force)
8285 "Sent all form letter messages from current buffer.
8286 Unless FORCE, prompt before sending.
8288 The messages are separated by `message-form-letter-separator'.
8289 Header and body are separated by `mail-header-separator'."
8291 (let ((sent 0) (skipped 0)
8295 (goto-char (point-min))
8298 end (if (search-forward message-form-letter-separator nil t)
8299 (- (point) (length message-form-letter-separator) -1)
8303 (buffer-substring-no-properties start end))
8304 (setq buff (generate-new-buffer "*mail - form letter*"))
8305 (with-current-buffer buff
8308 (setq to (message-fetch-field "To"))
8309 (switch-to-buffer buff)
8311 (sit-for message-send-form-letter-delay))
8313 (y-or-n-p (format-message "Send message to `%s'? " to)))
8315 (setq sent (1+ sent))
8316 (message-send-and-exit))
8317 (message "Message to `%s' skipped." to)
8318 (setq skipped (1+ skipped)))
8319 (when (buffer-live-p buff)
8320 (kill-buffer buff))))
8321 (message "%s message(s) sent, %s skipped." sent skipped)))
8323 (defun message-replace-header (header new-value &optional after force)
8324 "Remove HEADER and insert the NEW-VALUE.
8325 If AFTER, insert after this header. If FORCE, insert new field
8326 even if NEW-VALUE is empty."
8327 ;; Similar to `nnheader-replace-header' but for message buffers.
8330 (message-narrow-to-headers)
8331 (message-remove-header header))
8332 (when (or force (> (length new-value) 0))
8334 (message-position-on-field header after)
8335 (message-position-on-field header))
8336 (insert new-value))))
8338 (defcustom message-recipients-without-full-name
8339 (list "ding@gnus.org"
8341 "emacs-devel@gnu.org"
8342 "emacs-pretest-bug@gnu.org"
8343 "bug-gnu-emacs@gnu.org")
8344 "Mail addresses that have no full name.
8345 Used in `message-simplify-recipients'."
8346 ;; Maybe the addresses could be extracted from
8347 ;; `gnus-parameter-to-list-alist'?
8348 :type '(choice (const :tag "None" nil)
8350 :version "23.1" ;; No Gnus
8351 :group 'message-headers)
8353 (defun message-simplify-recipients ()
8355 (dolist (hdr '("Cc" "To"))
8356 (message-replace-header
8360 (if (and message-recipients-without-full-name
8362 (regexp-opt message-recipients-without-full-name)
8366 (message-make-from (car addrcomp) (cadr addrcomp))
8368 (when (message-fetch-field hdr)
8369 (mail-extract-address-components
8370 (message-fetch-field hdr) t))
8373 ;;; multipart/related and HTML support.
8375 (defun message-make-html-message-with-image-files (files)
8376 "Make a message containing the current dired-marked image files."
8377 (interactive (list (dired-get-marked-files nil current-prefix-arg)))
8380 (insert "<#part type=text/html>\n\n")
8381 (dolist (file files)
8382 (insert (format "<img src=%S>\n\n" file)))
8383 (message-toggle-image-thumbnails)
8386 (defun message-toggle-image-thumbnails ()
8387 "For any included image files, insert a thumbnail of that image."
8389 (let ((overlays (overlays-in (point-min) (point-max)))
8392 (let ((overlay (car overlays)))
8393 (when (overlay-get overlay 'put-image)
8394 (delete-overlay overlay)
8395 (setq displayed t)))
8396 (setq overlays (cdr overlays)))
8399 (goto-char (point-min))
8400 (while (re-search-forward "<img.*src=\"\\([^\"]+\\)" nil t)
8401 (let ((file (match-string 1))
8402 (edges (window-inside-pixel-edges
8403 (get-buffer-window (current-buffer)))))
8406 file 'imagemagick nil
8407 :max-width (truncate
8408 (* 0.7 (- (nth 2 edges) (nth 0 edges))))
8409 :max-height (truncate
8410 (* 0.5 (- (nth 3 edges) (nth 1 edges)))))
8416 (run-hooks 'message-load-hook)
8422 ;;; message.el ends here