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 (defcustom 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 :type '(set (const empty-article) (const quoted-text-only)
1389 (const multiple-copies) (const cancel-messages)
1390 (const canlock-verify)))
1392 (defsubst message-gnksa-enable-p (feature)
1393 (or (not (listp message-shoot-gnksa-feet))
1394 (memq feature message-shoot-gnksa-feet)))
1396 (defcustom message-hidden-headers '("^References:" "^Face:" "^X-Face:"
1398 "Regexp of headers to be hidden when composing new messages.
1399 This can also be a list of regexps to match headers. Or a list
1400 starting with `not' and followed by regexps."
1403 :link '(custom-manual "(message)Message Headers")
1405 :format "%{%t%}: %[Value Type%] %v"
1406 (regexp :menu-tag "regexp" :format "regexp\n%t: %v")
1407 (repeat :menu-tag "(regexp ...)" :format "(regexp ...)\n%v%i"
1408 (regexp :format "%t: %v"))
1409 (cons :menu-tag "(not regexp ...)" :format "(not regexp ...)\n%v"
1411 (repeat :format "%v%i"
1412 (regexp :format "%t: %v")))))
1414 (defcustom message-cite-articles-with-x-no-archive t
1415 "If non-nil, cite text from articles that has X-No-Archive set."
1419 ;;; Internal variables.
1420 ;;; Well, not really internal.
1422 (defvar message-mode-syntax-table
1423 (let ((table (copy-syntax-table text-mode-syntax-table)))
1424 (modify-syntax-entry ?% ". " table)
1425 (modify-syntax-entry ?> ". " table)
1426 (modify-syntax-entry ?< ". " table)
1428 "Syntax table used while in Message mode.")
1430 (defface message-header-to
1433 (:foreground "DarkOliveGreen1" :bold t))
1436 (:foreground "MidnightBlue" :bold t))
1438 (:bold t :italic t)))
1439 "Face used for displaying From headers."
1440 :group 'message-faces)
1441 ;; backward-compatibility alias
1442 (put 'message-header-to-face 'face-alias 'message-header-to)
1443 (put 'message-header-to-face 'obsolete-face "22.1")
1445 (defface message-header-cc
1448 (:foreground "chartreuse1" :bold t))
1451 (:foreground "MidnightBlue"))
1454 "Face used for displaying Cc headers."
1455 :group 'message-faces)
1456 ;; backward-compatibility alias
1457 (put 'message-header-cc-face 'face-alias 'message-header-cc)
1458 (put 'message-header-cc-face 'obsolete-face "22.1")
1460 (defface message-header-subject
1463 (:foreground "OliveDrab1"))
1466 (:foreground "navy blue" :bold t))
1469 "Face used for displaying subject headers."
1470 :group 'message-faces)
1471 ;; backward-compatibility alias
1472 (put 'message-header-subject-face 'face-alias 'message-header-subject)
1473 (put 'message-header-subject-face 'obsolete-face "22.1")
1475 (defface message-header-newsgroups
1478 (:foreground "yellow" :bold t :italic t))
1481 (:foreground "blue4" :bold t :italic t))
1483 (:bold t :italic t)))
1484 "Face used for displaying newsgroups headers."
1485 :group 'message-faces)
1486 ;; backward-compatibility alias
1487 (put 'message-header-newsgroups-face 'face-alias 'message-header-newsgroups)
1488 (put 'message-header-newsgroups-face 'obsolete-face "22.1")
1490 (defface message-header-other
1493 (:foreground "VioletRed1"))
1496 (:foreground "steel blue"))
1498 (:bold t :italic t)))
1499 "Face used for displaying newsgroups headers."
1500 :group 'message-faces)
1501 ;; backward-compatibility alias
1502 (put 'message-header-other-face 'face-alias 'message-header-other)
1503 (put 'message-header-other-face 'obsolete-face "22.1")
1505 (defface message-header-name
1508 (:foreground "green"))
1511 (:foreground "cornflower blue"))
1514 "Face used for displaying header names."
1515 :group 'message-faces)
1516 ;; backward-compatibility alias
1517 (put 'message-header-name-face 'face-alias 'message-header-name)
1518 (put 'message-header-name-face 'obsolete-face "22.1")
1520 (defface message-header-xheader
1523 (:foreground "DeepSkyBlue1"))
1526 (:foreground "blue"))
1529 "Face used for displaying X-Header headers."
1530 :group 'message-faces)
1531 ;; backward-compatibility alias
1532 (put 'message-header-xheader-face 'face-alias 'message-header-xheader)
1533 (put 'message-header-xheader-face 'obsolete-face "22.1")
1535 (defface message-separator
1538 (:foreground "LightSkyBlue1"))
1541 (:foreground "brown"))
1544 "Face used for displaying the separator."
1545 :group 'message-faces)
1546 ;; backward-compatibility alias
1547 (put 'message-separator-face 'face-alias 'message-separator)
1548 (put 'message-separator-face 'obsolete-face "22.1")
1550 (defface message-cited-text
1553 (:foreground "LightPink1"))
1556 (:foreground "red"))
1559 "Face used for displaying cited text names."
1560 :group 'message-faces)
1561 ;; backward-compatibility alias
1562 (put 'message-cited-text-face 'face-alias 'message-cited-text)
1563 (put 'message-cited-text-face 'obsolete-face "22.1")
1565 (defface message-mml
1568 (:foreground "MediumSpringGreen"))
1571 (:foreground "ForestGreen"))
1574 "Face used for displaying MML."
1575 :group 'message-faces)
1576 ;; backward-compatibility alias
1577 (put 'message-mml-face 'face-alias 'message-mml)
1578 (put 'message-mml-face 'obsolete-face "22.1")
1580 (defun message-font-lock-make-header-matcher (regexp)
1583 (let ((start (point)))
1586 (goto-char (point-min))
1587 (if (re-search-forward
1588 (concat "^" (regexp-quote mail-header-separator) "$")
1590 (setq limit (min limit (match-beginning 0))))
1592 (and (< start limit)
1593 (re-search-forward ,regexp limit t))))))
1594 (if (featurep 'bytecomp)
1598 (defvar message-font-lock-keywords
1599 (let ((content "[ \t]*\\(.+\\(\n[ \t].*\\)*\\)\n?"))
1600 `((,(message-font-lock-make-header-matcher
1601 (concat "^\\([Tt]o:\\)" content))
1602 (1 'message-header-name)
1603 (2 'message-header-to nil t))
1604 (,(message-font-lock-make-header-matcher
1605 (concat "^\\(^[GBF]?[Cc][Cc]:\\|^[Rr]eply-[Tt]o:\\)" content))
1606 (1 'message-header-name)
1607 (2 'message-header-cc nil t))
1608 (,(message-font-lock-make-header-matcher
1609 (concat "^\\([Ss]ubject:\\)" content))
1610 (1 'message-header-name)
1611 (2 'message-header-subject nil t))
1612 (,(message-font-lock-make-header-matcher
1613 (concat "^\\([Nn]ewsgroups:\\|Followup-[Tt]o:\\)" content))
1614 (1 'message-header-name)
1615 (2 'message-header-newsgroups nil t))
1616 (,(message-font-lock-make-header-matcher
1617 (concat "^\\(X-[A-Za-z0-9-]+:\\|In-Reply-To:\\)" content))
1618 (1 'message-header-name)
1619 (2 'message-header-xheader))
1620 (,(message-font-lock-make-header-matcher
1621 (concat "^\\([A-Z][^: \n\t]+:\\)" content))
1622 (1 'message-header-name)
1623 (2 'message-header-other nil t))
1624 ,@(if (and mail-header-separator
1625 (not (equal mail-header-separator "")))
1626 `((,(concat "^\\(" (regexp-quote mail-header-separator) "\\)$")
1627 1 'message-separator))
1630 (re-search-forward (concat "^\\("
1631 message-cite-prefix-regexp
1634 (0 'message-cited-text))
1635 ("<#/?\\(multipart\\|part\\|external\\|mml\\|secure\\)[^>]*>"
1637 "Additional expressions to highlight in Message mode.")
1639 (defvar message-face-alist
1640 '((bold . message-bold-region)
1641 (underline . underline-region)
1642 (default . (lambda (b e)
1643 (message-unbold-region b e)
1644 (ununderline-region b e))))
1645 "Alist of mail and news faces for facemenu.
1646 The cdr of each entry is a function for applying the face to a region.")
1648 (defcustom message-send-hook nil
1649 "Hook run before sending messages.
1650 This hook is run quite early when sending."
1651 :group 'message-various
1652 :options '(ispell-message)
1653 :link '(custom-manual "(message)Various Message Variables")
1656 (defcustom message-send-mail-hook nil
1657 "Hook run before sending mail messages.
1658 This hook is run very late -- just before the message is sent as
1660 :group 'message-various
1661 :link '(custom-manual "(message)Various Message Variables")
1664 (defcustom message-send-news-hook nil
1665 "Hook run before sending news messages.
1666 This hook is run very late -- just before the message is sent as
1668 :group 'message-various
1669 :link '(custom-manual "(message)Various Message Variables")
1672 (defcustom message-sent-hook nil
1673 "Hook run after sending messages."
1674 :group 'message-various
1677 (defvar message-send-coding-system 'binary
1678 "Coding system to encode outgoing mail.")
1680 (defvar message-draft-coding-system mm-auto-save-coding-system
1681 "Coding system to compose mail.")
1683 (defcustom message-send-mail-partially-limit nil
1684 "The limitation of messages sent as message/partial.
1685 The lower bound of message size in characters, beyond which the message
1686 should be sent in several parts. If it is nil, the size is unlimited."
1688 :group 'message-buffers
1689 :link '(custom-manual "(message)Mail Variables")
1690 :type '(choice (const :tag "unlimited" nil)
1693 (defcustom message-alternative-emails nil
1694 "Regexp or predicate function matching alternative email addresses.
1695 The first address in the To, Cc or From headers of the original
1696 article matching this variable is used as the From field of
1699 If a function, an email string is passed as the argument.
1701 This variable has precedence over posting styles and anything that runs
1702 off `message-setup-hook'."
1703 :group 'message-headers
1704 :link '(custom-manual "(message)Message Headers")
1705 :type '(choice (const :tag "Always use primary" nil)
1709 (defcustom message-hierarchical-addresses nil
1710 "A list of hierarchical mail address definitions.
1712 Inside each entry, the first address is the \"top\" address, and
1713 subsequent addresses are subaddresses; this is used to indicate that
1714 mail sent to the first address will automatically be delivered to the
1715 subaddresses. So if the first address appears in the recipient list
1716 for a message, the subaddresses will be removed (if present) before
1717 the mail is sent. All addresses in this structure should be
1720 :group 'message-headers
1721 :type '(repeat (repeat string)))
1723 (defcustom message-mail-user-agent nil
1724 "Like `mail-user-agent'.
1725 Except if it is nil, use Gnus native MUA; if it is t, use
1728 :type '(radio (const :tag "Gnus native"
1731 (const :tag "`mail-user-agent'"
1734 (function-item :tag "Default Emacs mail"
1736 sendmail-user-agent)
1737 (function-item :tag "Emacs interface to MH"
1740 (function :tag "Other"))
1744 (defcustom message-wide-reply-confirm-recipients nil
1745 "Whether to confirm a wide reply to multiple email recipients.
1746 If this variable is nil, don't ask whether to reply to all recipients.
1747 If this variable is non-nil, pose the question \"Reply to all
1748 recipients?\" before a wide reply to multiple recipients. If the user
1749 answers yes, reply to all recipients as usual. If the user answers
1750 no, only reply back to the author."
1752 :group 'message-headers
1753 :link '(custom-manual "(message)Wide Reply")
1756 (defcustom message-user-fqdn nil
1757 "Domain part of Message-Ids."
1759 :group 'message-headers
1760 :link '(custom-manual "(message)News Headers")
1761 :type '(radio (const :format "%v " nil)
1762 (string :format "FQDN: %v")))
1764 (defcustom message-use-idna t
1765 "Whether to encode non-ASCII in domain names into ASCII according to IDNA."
1767 :group 'message-headers
1768 :link '(custom-manual "(message)IDNA")
1769 :type '(choice (const :tag "Ask" ask)
1770 (const :tag "Never" nil)
1771 (const :tag "Always" t)))
1773 (defcustom message-generate-hashcash (if (executable-find "hashcash") 'opportunistic)
1774 "Whether to generate X-Hashcash: headers.
1775 If t, always generate hashcash headers. If `opportunistic',
1776 only generate hashcash headers if it can be done without the user
1777 waiting (i.e., only asynchronously).
1779 You must have the \"hashcash\" binary installed, see `hashcash-path'."
1781 :group 'message-headers
1782 :link '(custom-manual "(message)Mail Headers")
1783 :type '(choice (const :tag "Always" t)
1784 (const :tag "Never" nil)
1785 (const :tag "Opportunistic" opportunistic)))
1787 ;;; Internal variables.
1789 (defvar message-sending-message "Sending...")
1790 (defvar message-buffer-list nil)
1791 (defvar message-this-is-news nil)
1792 (defvar message-this-is-mail nil)
1793 (defvar message-draft-article nil)
1794 (defvar message-mime-part nil)
1795 (defvar message-posting-charset nil)
1796 (defvar message-inserted-headers nil)
1797 (defvar message-inhibit-ecomplete nil)
1799 ;; Byte-compiler warning
1800 (defvar gnus-active-hashtb)
1801 (defvar gnus-read-active-file)
1803 ;;; Regexp matching the delimiter of messages in UNIX mail format
1804 ;;; (UNIX From lines), minus the initial ^. It should be a copy
1805 ;;; of rmail.el's rmail-unix-mail-delimiter.
1806 (defvar message-unix-mail-delimiter
1807 (let ((time-zone-regexp
1808 (concat "\\([A-Z]?[A-Z]?[A-Z][A-Z]\\( DST\\)?"
1809 "\\|[-+]?[0-9][0-9][0-9][0-9]"
1815 ;; Many things can happen to an RFC 822 mailbox before it is put into
1816 ;; a `From' line. The leading phrase can be stripped, e.g.
1817 ;; `Joe <@w.x:joe@y.z>' -> `<@w.x:joe@y.z>'. The <> can be stripped, e.g.
1818 ;; `<@x.y:joe@y.z>' -> `@x.y:joe@y.z'. Everything starting with a CRLF
1819 ;; can be removed, e.g.
1820 ;; From: joe@y.z (Joe K
1822 ;; can yield `From joe@y.z (Joe K Fri Mar 22 08:11:15 1996', and
1825 ;; can yield `From Joe User Fri Mar 22 08:11:15 1996'.
1826 ;; The mailbox can be removed or be replaced by white space, e.g.
1827 ;; From: "Joe User"{space}{tab}
1829 ;; can yield `From {space}{tab} Fri Mar 22 08:11:15 1996',
1830 ;; where {space} and {tab} represent the Ascii space and tab characters.
1831 ;; We want to match the results of any of these manglings.
1832 ;; The following regexp rejects names whose first characters are
1833 ;; obviously bogus, but after that anything goes.
1834 "\\([^\0-\b\n-\r\^?].*\\)?"
1836 ;; The time the message was sent.
1837 "\\([^\0-\r \^?]+\\) +" ; day of the week
1838 "\\([^\0-\r \^?]+\\) +" ; month
1839 "\\([0-3]?[0-9]\\) +" ; day of month
1840 "\\([0-2][0-9]:[0-5][0-9]\\(:[0-6][0-9]\\)?\\) *" ; time of day
1842 ;; Perhaps a time zone, specified by an abbreviation, or by a
1847 " \\([0-9][0-9]+\\) *"
1849 ;; On some systems the time zone can appear after the year, too.
1853 "\\(remote from .*\\)?"
1856 "Regexp matching the delimiter of messages in UNIX mail format.")
1858 (defvar message-unsent-separator
1859 (concat "^ *---+ +Unsent message follows +---+ *$\\|"
1860 "^ *---+ +Returned message +---+ *$\\|"
1861 "^Start of returned message$\\|"
1862 "^ *---+ +Original message +---+ *$\\|"
1863 "^ *--+ +begin message +--+ *$\\|"
1864 "^ *---+ +Original message follows +---+ *$\\|"
1865 "^ *---+ +Undelivered message follows +---+ *$\\|"
1866 "^------ This is a copy of the message, including all the headers. ------ *$\\|"
1867 "^|? *---+ +Message text follows: +---+ *|?$")
1868 "A regexp that matches the separator before the text of a failed message.")
1870 (defvar message-field-fillers
1871 '((To message-fill-field-address)
1872 (Cc message-fill-field-address)
1873 (From message-fill-field-address))
1874 "Alist of header names/filler functions.")
1876 (defvar message-header-format-alist
1891 (References . message-shorten-references)
1893 "Alist used for formatting headers.")
1895 (defvar message-options nil
1896 "Some saved answers when sending message.")
1897 (make-variable-buffer-local 'message-options)
1899 (defvar message-send-mail-real-function nil
1900 "Internal send mail function.")
1902 (defvar message-bogus-system-names "\\`localhost\\.\\|\\.local\\'"
1903 "The regexp of bogus system names.")
1905 (autoload 'gnus-alive-p "gnus-util")
1906 (autoload 'gnus-delay-article "gnus-delay")
1907 (autoload 'gnus-extract-address-components "gnus-util")
1908 (autoload 'gnus-find-method-for-group "gnus")
1909 (autoload 'gnus-group-decoded-name "gnus-group")
1910 (autoload 'gnus-group-name-charset "gnus-group")
1911 (autoload 'gnus-group-name-decode "gnus-group")
1912 (autoload 'gnus-groups-from-server "gnus")
1913 (autoload 'gnus-open-server "gnus-int")
1914 (autoload 'gnus-output-to-mail "gnus-util")
1915 (autoload 'gnus-output-to-rmail "gnus-util")
1916 (autoload 'gnus-request-post "gnus-int")
1917 (autoload 'gnus-server-string "gnus")
1918 (autoload 'message-setup-toolbar "messagexmas")
1919 (autoload 'mh-new-draft-name "mh-comp")
1920 (autoload 'mh-send-letter "mh-comp")
1921 (autoload 'nndraft-request-associate-buffer "nndraft")
1922 (autoload 'nndraft-request-expire-articles "nndraft")
1923 (autoload 'nnvirtual-find-group-art "nnvirtual")
1924 (autoload 'rmail-msg-is-pruned "rmail")
1925 (autoload 'rmail-output "rmailout")
1927 (defun message-kill-all-overlays ()
1928 (mapcar #'delete-overlay (overlays-in (point-min) (point-max))))
1933 ;;; Utility functions.
1936 (defmacro message-y-or-n-p (question show &rest text)
1937 "Ask QUESTION, displaying remaining args in a temporary buffer if SHOW."
1938 `(message-talkative-question 'y-or-n-p ,question ,show ,@text))
1940 (defmacro message-delete-line (&optional n)
1941 "Delete the current line (and the next N lines)."
1942 `(delete-region (progn (beginning-of-line) (point))
1943 (progn (forward-line ,(or n 1)) (point))))
1945 (defun message-mark-active-p ()
1946 "Non-nil means the mark and region are currently active in this buffer."
1949 (defun message-unquote-tokens (elems)
1950 "Remove double quotes (\") from strings in list ELEMS."
1951 (mapcar (lambda (item)
1952 (while (string-match "^\\(.*\\)\"\\(.*\\)$" item)
1953 (setq item (concat (match-string 1 item)
1954 (match-string 2 item))))
1958 (defun message-tokenize-header (header &optional separator)
1959 "Split HEADER into a list of header elements.
1960 SEPARATOR is a string of characters to be used as separators. \",\"
1961 is used by default."
1964 (let ((regexp (format "[%s]+" (or separator ",")))
1966 beg quoted elems paren)
1968 (mm-enable-multibyte)
1969 (setq beg (point-min))
1971 (goto-char (point-min))
1976 (cond ((and (> (point) beg)
1978 (and (looking-at regexp)
1981 (push (buffer-substring beg (point)) elems)
1982 (setq beg (match-end 0)))
1983 ((eq (char-after) ?\")
1984 (setq quoted (not quoted)))
1985 ((and (eq (char-after) ?\()
1988 ((and (eq (char-after) ?\))
1991 (nreverse elems)))))
1993 (autoload 'nnheader-insert-file-contents "nnheader")
1995 (defun message-mail-file-mbox-p (file)
1996 "Say whether FILE looks like a Unix mbox file."
1997 (when (and (file-exists-p file)
1998 (file-readable-p file)
1999 (file-regular-p file))
2001 (nnheader-insert-file-contents file)
2002 (goto-char (point-min))
2003 (looking-at message-unix-mail-delimiter))))
2005 (defun message-fetch-field (header &optional not-all)
2006 "The same as `mail-fetch-field', only remove all newlines.
2007 The buffer is expected to be narrowed to just the header of the message;
2008 see `message-narrow-to-headers-or-head'."
2009 (let* ((inhibit-point-motion-hooks t)
2010 (value (mail-fetch-field header nil (not not-all))))
2012 (while (string-match "\n[\t ]+" value)
2013 (setq value (replace-match " " t t value)))
2016 (defun message-field-value (header &optional not-all)
2017 "The same as `message-fetch-field', only narrow to the headers first."
2020 (message-narrow-to-headers-or-head)
2021 (message-fetch-field header not-all))))
2023 (defun message-narrow-to-field ()
2024 "Narrow the buffer to the header on the current line."
2026 (while (looking-at "[ \t]")
2032 (if (re-search-forward "^[^ \n\t]" nil t)
2035 (goto-char (point-min)))
2037 (defun message-add-header (&rest headers)
2038 "Add the HEADERS to the message header, skipping those already present."
2041 (unless (string-match "^\\([^:]+\\):[ \t]*[^ \t]" (car headers))
2042 (error "Invalid header `%s'" (car headers)))
2043 (setq hclean (match-string 1 (car headers)))
2045 (message-narrow-to-headers)
2046 (unless (re-search-forward (concat "^" (regexp-quote hclean) ":") nil t)
2047 (goto-char (point-max))
2048 (if (string-match "\n$" (car headers))
2049 (insert (car headers))
2050 (insert (car headers) ?\n)))))
2051 (setq headers (cdr headers))))
2053 (defmacro message-with-reply-buffer (&rest forms)
2054 "Evaluate FORMS in the reply buffer, if it exists."
2055 `(when (and (bufferp message-reply-buffer)
2056 (buffer-name message-reply-buffer))
2057 (with-current-buffer message-reply-buffer
2060 (put 'message-with-reply-buffer 'lisp-indent-function 0)
2061 (put 'message-with-reply-buffer 'edebug-form-spec '(body))
2063 (defun message-fetch-reply-field (header)
2064 "Fetch field HEADER from the message we're replying to."
2065 (message-with-reply-buffer
2067 (mail-narrow-to-head)
2068 (message-fetch-field header))))
2070 (defun message-strip-list-identifiers (subject)
2071 "Remove list identifiers in `gnus-list-identifiers' from string SUBJECT."
2072 (require 'gnus-sum) ; for gnus-list-identifiers
2073 (let ((regexp (if (stringp gnus-list-identifiers)
2074 gnus-list-identifiers
2075 (mapconcat 'identity gnus-list-identifiers " *\\|"))))
2076 (if (string-match (concat "\\(\\(\\(Re: +\\)?\\(" regexp
2077 " *\\)\\)+\\(Re: +\\)?\\)") subject)
2078 (concat (substring subject 0 (match-beginning 1))
2079 (or (match-string 3 subject)
2080 (match-string 5 subject))
2085 (defun message-strip-subject-re (subject)
2086 "Remove \"Re:\" from subject lines in string SUBJECT."
2087 (if (string-match message-subject-re-regexp subject)
2088 (substring subject (match-end 0))
2091 (defcustom message-replacement-char "."
2092 "Replacement character used instead of unprintable or not decodable chars."
2093 :group 'message-various
2094 :version "22.1" ;; Gnus 5.10.9
2095 :type '(choice string
2099 ;; FIXME: We also should call `message-strip-subject-encoded-words'
2100 ;; when forwarding. Probably in `message-make-forward-subject' and
2101 ;; `message-forward-make-body'.
2103 (defun message-strip-subject-encoded-words (subject)
2104 "Fix non-decodable words in SUBJECT."
2105 ;; Cf. `gnus-simplify-subject-fully'.
2106 (let* ((case-fold-search t)
2107 (replacement-chars (format "[%s%s%s]"
2108 message-replacement-char
2109 message-replacement-char
2110 message-replacement-char))
2111 (enc-word-re "=\\?\\([^?]+\\)\\?\\([QB]\\)\\?\\([^?]+\\)\\(\\?=\\)")
2116 (goto-char (point-min))
2117 (when (re-search-forward enc-word-re nil t)
2118 (setq cs-string (match-string 1)))))
2119 cs-coding q-or-b word-beg word-end)
2120 (if (or (not have-marker) ;; No encoded word found...
2121 ;; ... or double encoding was correct:
2122 (and (stringp cs-string)
2123 (setq cs-string (downcase cs-string))
2124 (mm-coding-system-p (intern cs-string))
2128 Decoded Subject \"%s\"
2129 contains a valid encoded word. Decode again? "
2131 (setq cs-coding (intern cs-string))))))
2135 (goto-char (point-min))
2136 (while (re-search-forward enc-word-re nil t)
2137 (setq cs-string (downcase (match-string 1))
2138 q-or-b (match-string 2)
2139 word-beg (match-beginning 0)
2140 word-end (match-end 0))
2142 (if (mm-coding-system-p (intern cs-string))
2143 (setq cs-coding (intern cs-string))
2145 ;; No double encoded subject? => bogus charset.
2150 Decoded Subject \"%s\"
2151 contains an encoded word. The charset `%s' is unknown or invalid.
2152 Hit RET to replace non-decodable characters with \"%s\" or enter replacement
2154 subject cs-string message-replacement-char)))
2156 (replace-match (concat "=?" (symbol-name cs-coding)
2159 (goto-char word-beg)
2160 (re-search-forward "=\\?\\([^?]+\\)\\?\\([QB]\\)\\?" word-end t)
2163 (if (string-match "\\`Q\\'" q-or-b)
2166 (message "Replacing non-decodable characters with \"%s\"."
2167 message-replacement-char)
2168 (while (re-search-forward "\\(=[A-F0-9][A-F0-9]\\)+"
2170 (replace-match message-replacement-char)))
2172 (message "Replacing non-decodable characters with \"%s\"."
2174 (re-search-forward "[^?]+" word-end t)
2175 (replace-match replacement-chars))
2176 (re-search-forward "\\?=")
2177 (replace-match "")))))
2178 (rfc2047-decode-region (point-min) (point-max))
2181 ;;; Start of functions adopted from `message-utils.el'.
2183 (defun message-strip-subject-trailing-was (subject)
2184 "Remove trailing \"(was: <old subject>)\" from SUBJECT lines.
2185 Leading \"Re: \" is not stripped by this function. Use the function
2186 `message-strip-subject-re' for this."
2188 (let ((query message-subject-trailing-was-query) new)
2190 (string-match (if (eq query 'ask)
2191 message-subject-trailing-was-ask-regexp
2192 message-subject-trailing-was-regexp)
2194 (setq new (substring subject 0 (match-beginning 0)))
2195 (or (not (eq query 'ask))
2197 "Strip `(was: <old subject>)' in subject? " t
2199 "Strip `(was: <old subject>)' in subject "
2200 "and use the new one instead?\n\n"
2201 "Current subject is: \"" subject "\"\n\n"
2202 "New subject would be: \"" new "\"\n\n"
2203 "See the variable `message-subject-trailing-was-query' "
2204 "to get rid of this query.")))
2208 ;;; Suggested by Jonas Steverud @ www.dtek.chalmers.se/~d4jonas/
2210 (defun message-change-subject (new-subject)
2211 "Ask for NEW-SUBJECT header, append (was: <Old Subject>)."
2214 (read-from-minibuffer "New subject: ")))
2215 (cond ((and (not (or (null new-subject) ; new subject not empty
2216 (zerop (string-width new-subject))
2217 (string-match "^[ \t]*$" new-subject))))
2221 (message-narrow-to-headers)
2222 (message-fetch-field "Subject"))))
2223 (cond ((not old-subject)
2224 (error "No current subject"))
2227 (regexp-quote new-subject)
2229 old-subject)) ; yes, it really is a new subject
2230 ;; delete eventual Re: prefix
2232 (message-strip-subject-re old-subject))
2233 (message-goto-subject)
2234 (message-delete-line)
2235 (insert (concat "Subject: "
2238 old-subject ")\n")))))))))
2240 (defun message-mark-inserted-region (beg end &optional verbatim)
2241 "Mark some region in the current article with enclosing tags.
2242 See `message-mark-insert-begin' and `message-mark-insert-end'.
2243 If VERBATIM, use slrn style verbatim marks (\"#v+\" and \"#v-\")."
2244 (interactive "r\nP")
2246 ;; add to the end of the region first, otherwise end would be invalid
2248 (insert (if verbatim "#v-\n" message-mark-insert-end))
2250 (insert (if verbatim "#v+\n" message-mark-insert-begin))))
2252 (defun message-mark-insert-file (file &optional verbatim)
2253 "Insert FILE at point, marking it with enclosing tags.
2254 See `message-mark-insert-begin' and `message-mark-insert-end'.
2255 If VERBATIM, use slrn style verbatim marks (\"#v+\" and \"#v-\")."
2256 (interactive "fFile to insert: \nP")
2257 ;; reverse insertion to get correct result.
2259 (insert (if verbatim "#v-\n" message-mark-insert-end))
2261 (insert-file-contents file)
2263 (insert (if verbatim "#v+\n" message-mark-insert-begin))))
2265 (defun message-add-archive-header ()
2266 "Insert \"X-No-Archive: Yes\" in the header and a note in the body.
2267 The note can be customized using `message-archive-note'. When called with a
2268 prefix argument, ask for a text to insert. If you don't want the note in the
2269 body, set `message-archive-note' to nil."
2271 (if current-prefix-arg
2272 (setq message-archive-note
2273 (read-from-minibuffer "Reason for No-Archive: "
2274 (cons message-archive-note 0))))
2276 (if (message-goto-signature)
2277 (re-search-backward message-signature-separator))
2278 (when message-archive-note
2279 (insert message-archive-note)
2281 (message-add-header message-archive-header)
2282 (message-sort-headers)))
2284 (defun message-cross-post-followup-to-header (target-group)
2285 "Mangles FollowUp-To and Newsgroups header to point to TARGET-GROUP.
2286 With prefix-argument just set Follow-Up, don't cross-post."
2288 (list ; Completion based on Gnus
2289 (completing-read "Followup To: "
2290 (if (boundp 'gnus-newsrc-alist)
2292 nil nil '("poster" . 0)
2293 (if (boundp 'gnus-group-history)
2294 'gnus-group-history))))
2295 (message-remove-header "Follow[Uu]p-[Tt]o" t)
2296 (message-goto-newsgroups)
2298 ;; if we already did a crosspost before, kill old target
2299 (if (and message-cross-post-old-target
2301 (regexp-quote (concat "," message-cross-post-old-target))
2304 ;; unless (followup is to poster or user explicitly asked not
2305 ;; to cross-post, or target-group is already in Newsgroups)
2306 ;; add target-group to Newsgroups line.
2308 ;; def: cross-post, req:no
2309 (and message-cross-post-default (not current-prefix-arg))
2310 ;; def: no-cross-post, req:yes
2311 (and (not message-cross-post-default) current-prefix-arg))
2312 (not (string-match "poster" target-group))
2313 (not (string-match (regexp-quote target-group)
2314 (message-fetch-field "Newsgroups"))))
2316 (insert (concat "," target-group))))
2317 (end-of-line) ; ensure Followup: comes after Newsgroups:
2318 ;; unless new followup would be identical to Newsgroups line
2319 ;; make a new Followup-To line
2320 (if (not (string-match (concat "^[ \t]*"
2323 (message-fetch-field "Newsgroups")))
2324 (insert (concat "\nFollowup-To: " target-group)))
2325 (setq message-cross-post-old-target target-group))
2327 (defun message-cross-post-insert-note (target-group cross-post in-old
2329 "Insert a in message body note about a set Followup or Crosspost.
2330 If there have been previous notes, delete them. TARGET-GROUP specifies the
2331 group to Followup-To. When CROSS-POST is t, insert note about
2332 crossposting. IN-OLD specifies whether TARGET-GROUP is a member of
2333 OLD-GROUPS. OLD-GROUPS lists the old-groups the posting would have
2334 been made to before the user asked for a Crosspost."
2335 ;; start scanning body for previous uses
2336 (message-goto-signature)
2337 (let ((head (re-search-backward
2338 (concat "^" mail-header-separator)
2339 nil t))) ; just search in body
2340 (message-goto-signature)
2341 (while (re-search-backward
2342 (concat "^" (regexp-quote message-cross-post-note) ".*")
2344 (message-delete-line))
2345 (message-goto-signature)
2346 (while (re-search-backward
2347 (concat "^" (regexp-quote message-followup-to-note) ".*")
2349 (message-delete-line))
2351 (if (message-goto-signature)
2352 (re-search-backward message-signature-separator))
2355 (string-match "^[ \t]*poster[ \t]*$" target-group))
2356 (insert (concat message-followup-to-note target-group "\n"))
2357 (insert (concat message-cross-post-note target-group "\n")))))
2359 (defun message-cross-post-followup-to (target-group)
2360 "Crossposts message and set Followup-To to TARGET-GROUP.
2361 With prefix-argument just set Follow-Up, don't cross-post."
2363 (list ; Completion based on Gnus
2364 (completing-read "Followup To: "
2365 (if (boundp 'gnus-newsrc-alist)
2367 nil nil '("poster" . 0)
2368 (if (boundp 'gnus-group-history)
2369 'gnus-group-history))))
2370 (when (fboundp 'gnus-group-real-name)
2371 (setq target-group (gnus-group-real-name target-group)))
2372 (cond ((not (or (null target-group) ; new subject not empty
2373 (zerop (string-width target-group))
2374 (string-match "^[ \t]*$" target-group)))
2376 (let* ((old-groups (message-fetch-field "Newsgroups"))
2377 (in-old (string-match
2378 (regexp-quote target-group)
2379 (or old-groups ""))))
2380 ;; check whether target exactly matches old Newsgroups
2381 (cond ((not old-groups)
2382 (error "No current newsgroup"))
2386 (regexp-quote target-group)
2389 ;; yes, Newsgroups line must change
2390 (message-cross-post-followup-to-header target-group)
2391 ;; insert note whether we do cross-post or followup-to
2392 (funcall message-cross-post-note-function
2394 (if (or (and message-cross-post-default
2395 (not current-prefix-arg))
2396 (and (not message-cross-post-default)
2397 current-prefix-arg)) t)
2398 in-old old-groups))))))))
2400 ;;; Reduce To: to Cc: or Bcc: header
2402 (defun message-reduce-to-to-cc ()
2403 "Replace contents of To: header with contents of Cc: or Bcc: header."
2406 (save-restriction (message-narrow-to-headers)
2407 (message-fetch-field "cc")))
2409 (if (and (not cc-content)
2412 (message-narrow-to-headers)
2413 (message-fetch-field "bcc"))))
2418 (message-delete-line)
2419 (insert (concat "To: " cc-content "\n"))
2421 (message-narrow-to-headers)
2422 (message-remove-header (if bcc
2426 ;;; End of functions adopted from `message-utils.el'.
2428 (defun message-remove-header (header &optional is-regexp first reverse)
2429 "Remove HEADER in the narrowed buffer.
2430 If IS-REGEXP, HEADER is a regular expression.
2431 If FIRST, only remove the first instance of the header.
2432 If REVERSE, remove headers that doesn't match HEADER.
2433 Return the number of headers removed."
2434 (goto-char (point-min))
2435 (let ((regexp (if is-regexp header (concat "^" (regexp-quote header) ":")))
2437 (case-fold-search t)
2439 (while (and (not (eobp))
2442 (not (looking-at regexp))
2443 (looking-at regexp))
2450 ;; There might be a continuation header, so we have to search
2451 ;; until we find a new non-continuation line.
2454 (if (re-search-forward "^[^ \t]" nil t)
2455 (goto-char (match-beginning 0))
2458 (if (re-search-forward "^[^ \t]" nil t)
2459 (goto-char (match-beginning 0))
2460 (goto-char (point-max)))))
2463 (defun message-remove-first-header (header)
2464 "Remove the first instance of HEADER if there is more than one."
2466 (regexp (concat "^" (regexp-quote header) ":")))
2468 (goto-char (point-min))
2469 (while (re-search-forward regexp nil t)
2472 (message-remove-header header nil t)
2475 (defun message-narrow-to-headers ()
2476 "Narrow the buffer to the head of the message."
2479 (goto-char (point-min))
2480 (if (re-search-forward
2481 (concat "^" (regexp-quote mail-header-separator) "\n") nil t)
2484 (goto-char (point-min)))
2486 (defun message-narrow-to-head-1 ()
2487 "Like `message-narrow-to-head'. Don't widen."
2489 (goto-char (point-min))
2490 (if (search-forward "\n\n" nil 1)
2493 (goto-char (point-min)))
2495 ;; FIXME: clarify difference: message-narrow-to-head,
2496 ;; message-narrow-to-headers-or-head, message-narrow-to-headers
2497 (defun message-narrow-to-head ()
2498 "Narrow the buffer to the head of the message.
2499 Point is left at the beginning of the narrowed-to region."
2501 (message-narrow-to-head-1))
2503 (defun message-narrow-to-headers-or-head ()
2504 "Narrow the buffer to the head of the message."
2507 (goto-char (point-min))
2508 (if (re-search-forward (concat "\\(\n\\)\n\\|^\\("
2509 (regexp-quote mail-header-separator)
2512 (or (match-end 1) (match-beginning 2))
2514 (goto-char (point-min)))
2516 (defun message-news-p ()
2517 "Say whether the current buffer contains a news message."
2518 (and (not message-this-is-mail)
2519 (or message-this-is-news
2522 (message-narrow-to-headers)
2523 (and (message-fetch-field "newsgroups")
2524 (not (message-fetch-field "posted-to"))))))))
2526 (defun message-mail-p ()
2527 "Say whether the current buffer contains a mail message."
2528 (and (not message-this-is-news)
2529 (or message-this-is-mail
2532 (message-narrow-to-headers)
2533 (or (message-fetch-field "to")
2534 (message-fetch-field "cc")
2535 (message-fetch-field "bcc")))))))
2537 (defun message-subscribed-p ()
2538 "Say whether we need to insert a MFT header."
2539 (or message-subscribed-regexps
2540 message-subscribed-addresses
2541 message-subscribed-address-file
2542 message-subscribed-address-functions))
2544 (defun message-next-header ()
2545 "Go to the beginning of the next header."
2547 (or (eobp) (forward-char 1))
2548 (not (if (re-search-forward "^[^ \t]" nil t)
2550 (goto-char (point-max)))))
2552 (defun message-sort-headers-1 ()
2553 "Sort the buffer as headers using `message-rank' text props."
2554 (goto-char (point-min))
2557 nil 'message-next-header
2559 (message-next-header)
2563 (or (get-text-property (point) 'message-rank)
2566 (defun message-sort-headers ()
2567 "Sort the headers of the current message according to `message-header-format-alist'."
2571 (let ((max (1+ (length message-header-format-alist)))
2573 (message-narrow-to-headers)
2574 (while (re-search-forward "^[^ \n]+:" nil t)
2576 (match-beginning 0) (1+ (match-beginning 0))
2578 (if (setq rank (length (memq (assq (intern (buffer-substring
2580 (1- (match-end 0))))
2581 message-header-format-alist)
2582 message-header-format-alist)))
2585 (message-sort-headers-1))))
2587 (defun message-kill-address ()
2588 "Kill the address under point."
2590 (let ((start (point)))
2591 (message-skip-to-next-address)
2592 (kill-region start (if (bolp) (1- (point)) (point)))))
2595 (autoload 'Info-goto-node "info")
2596 (defvar mml2015-use)
2598 (defun message-info (&optional arg)
2599 "Display the Message manual.
2601 Prefixed with one \\[universal-argument], display the Emacs MIME
2602 manual. With two \\[universal-argument]'s, display the EasyPG or
2603 PGG manual, depending on the value of `mml2015-use'."
2605 (info (format "(%s)Top"
2609 ((eq arg 4) 'emacs-mime)
2610 ((and (not (booleanp arg))
2624 (defvar message-mode-map nil)
2626 (unless message-mode-map
2627 (setq message-mode-map (make-keymap))
2628 (set-keymap-parent message-mode-map text-mode-map)
2629 (define-key message-mode-map "\C-c?" 'describe-mode)
2631 (define-key message-mode-map "\C-c\C-f\C-t" 'message-goto-to)
2632 (define-key message-mode-map "\C-c\C-f\C-o" 'message-goto-from)
2633 (define-key message-mode-map "\C-c\C-f\C-b" 'message-goto-bcc)
2634 (define-key message-mode-map "\C-c\C-f\C-w" 'message-goto-fcc)
2635 (define-key message-mode-map "\C-c\C-f\C-c" 'message-goto-cc)
2636 (define-key message-mode-map "\C-c\C-f\C-s" 'message-goto-subject)
2637 (define-key message-mode-map "\C-c\C-f\C-r" 'message-goto-reply-to)
2638 (define-key message-mode-map "\C-c\C-f\C-n" 'message-goto-newsgroups)
2639 (define-key message-mode-map "\C-c\C-f\C-d" 'message-goto-distribution)
2640 (define-key message-mode-map "\C-c\C-f\C-f" 'message-goto-followup-to)
2641 (define-key message-mode-map "\C-c\C-f\C-m" 'message-goto-mail-followup-to)
2642 (define-key message-mode-map "\C-c\C-f\C-k" 'message-goto-keywords)
2643 (define-key message-mode-map "\C-c\C-f\C-u" 'message-goto-summary)
2644 (define-key message-mode-map "\C-c\C-f\C-i"
2645 'message-insert-or-toggle-importance)
2646 (define-key message-mode-map "\C-c\C-f\C-a"
2647 'message-generate-unsubscribed-mail-followup-to)
2649 ;; modify headers (and insert notes in body)
2650 (define-key message-mode-map "\C-c\C-fs" 'message-change-subject)
2652 (define-key message-mode-map "\C-c\C-fx" 'message-cross-post-followup-to)
2653 ;; prefix+message-cross-post-followup-to = same w/o cross-post
2654 (define-key message-mode-map "\C-c\C-ft" 'message-reduce-to-to-cc)
2655 (define-key message-mode-map "\C-c\C-fa" 'message-add-archive-header)
2656 ;; mark inserted text
2657 (define-key message-mode-map "\C-c\M-m" 'message-mark-inserted-region)
2658 (define-key message-mode-map "\C-c\M-f" 'message-mark-insert-file)
2660 (define-key message-mode-map "\C-c\C-b" 'message-goto-body)
2661 (define-key message-mode-map "\C-c\C-i" 'message-goto-signature)
2663 (define-key message-mode-map "\C-c\C-t" 'message-insert-to)
2664 (define-key message-mode-map "\C-c\C-fw" 'message-insert-wide-reply)
2665 (define-key message-mode-map "\C-c\C-n" 'message-insert-newsgroups)
2666 (define-key message-mode-map "\C-c\C-l" 'message-to-list-only)
2667 (define-key message-mode-map "\C-c\C-f\C-e" 'message-insert-expires)
2669 (define-key message-mode-map "\C-c\C-u" 'message-insert-or-toggle-importance)
2670 (define-key message-mode-map "\C-c\M-n"
2671 'message-insert-disposition-notification-to)
2673 (define-key message-mode-map "\C-c\C-y" 'message-yank-original)
2674 (define-key message-mode-map "\C-c\M-\C-y" 'message-yank-buffer)
2675 (define-key message-mode-map "\C-c\C-q" 'message-fill-yanked-message)
2676 (define-key message-mode-map "\C-c\C-w" 'message-insert-signature)
2677 (define-key message-mode-map "\C-c\M-h" 'message-insert-headers)
2678 (define-key message-mode-map "\C-c\C-r" 'message-caesar-buffer-body)
2679 (define-key message-mode-map "\C-c\C-o" 'message-sort-headers)
2680 (define-key message-mode-map "\C-c\M-r" 'message-rename-buffer)
2682 (define-key message-mode-map "\C-c\C-c" 'message-send-and-exit)
2683 (define-key message-mode-map "\C-c\C-s" 'message-send)
2684 (define-key message-mode-map "\C-c\C-k" 'message-kill-buffer)
2685 (define-key message-mode-map "\C-c\C-d" 'message-dont-send)
2686 (define-key message-mode-map "\C-c\n" 'gnus-delay-article)
2688 (define-key message-mode-map "\C-c\M-k" 'message-kill-address)
2689 (define-key message-mode-map "\C-c\C-e" 'message-elide-region)
2690 (define-key message-mode-map "\C-c\C-v" 'message-delete-not-region)
2691 (define-key message-mode-map "\C-c\C-z" 'message-kill-to-signature)
2692 (define-key message-mode-map "\M-\r" 'message-newline-and-reformat)
2693 (define-key message-mode-map [remap split-line] 'message-split-line)
2695 (define-key message-mode-map "\C-c\C-a" 'mml-attach-file)
2697 (define-key message-mode-map "\C-a" 'message-beginning-of-line)
2698 (define-key message-mode-map "\t" 'message-tab)
2700 (define-key message-mode-map "\M-n" 'message-display-abbrev))
2703 message-mode-menu message-mode-map "Message Menu."
2705 ["Yank Original" message-yank-original message-reply-buffer]
2706 ["Fill Yanked Message" message-fill-yanked-message t]
2707 ["Insert Signature" message-insert-signature t]
2708 ["Caesar (rot13) Message" message-caesar-buffer-body t]
2709 ["Caesar (rot13) Region" message-caesar-region (message-mark-active-p)]
2710 ["Elide Region" message-elide-region
2711 :active (message-mark-active-p)
2712 :help "Replace text in region with an ellipsis"]
2713 ["Delete Outside Region" message-delete-not-region
2714 :active (message-mark-active-p)
2715 :help "Delete all quoted text outside region"]
2716 ["Kill To Signature" message-kill-to-signature t]
2717 ["Newline and Reformat" message-newline-and-reformat t]
2718 ["Rename buffer" message-rename-buffer t]
2719 ["Spellcheck" ispell-message :help "Spellcheck this message"]
2721 ["Insert Region Marked" message-mark-inserted-region
2722 :active (message-mark-active-p) :help "Mark region with enclosing tags"]
2723 ["Insert File Marked..." message-mark-insert-file
2724 :help "Insert file at point marked with enclosing tags"]
2726 ["Send Message" message-send-and-exit :help "Send this message"]
2727 ["Postpone Message" message-dont-send
2728 :help "File this draft message and exit"]
2729 ["Send at Specific Time..." gnus-delay-article
2730 :help "Ask, then arrange to send message at that time"]
2731 ["Kill Message" message-kill-buffer
2732 :help "Delete this message without sending"]
2734 ["Message manual" message-info :help "Display the Message manual"]))
2737 message-mode-field-menu message-mode-map ""
2739 ["To" message-goto-to t]
2740 ["From" message-goto-from t]
2741 ["Subject" message-goto-subject t]
2742 ["Change subject..." message-change-subject t]
2743 ["Cc" message-goto-cc t]
2744 ["Bcc" message-goto-bcc t]
2745 ["Fcc" message-goto-fcc t]
2746 ["Reply-To" message-goto-reply-to t]
2747 ["Flag As Important" message-insert-importance-high
2748 :help "Mark this message as important"]
2749 ["Flag As Unimportant" message-insert-importance-low
2750 :help "Mark this message as unimportant"]
2752 message-insert-disposition-notification-to
2753 :help "Request a receipt notification"]
2755 ;; (typical) news stuff
2756 ["Summary" message-goto-summary t]
2757 ["Keywords" message-goto-keywords t]
2758 ["Newsgroups" message-goto-newsgroups t]
2759 ["Fetch Newsgroups" message-insert-newsgroups t]
2760 ["Followup-To" message-goto-followup-to t]
2761 ;; ["Followup-To (with note in body)" message-cross-post-followup-to t]
2762 ["Crosspost / Followup-To..." message-cross-post-followup-to t]
2763 ["Distribution" message-goto-distribution t]
2764 ["Expires" message-insert-expires t ]
2765 ["X-No-Archive" message-add-archive-header t ]
2767 ;; (typical) mailing-lists stuff
2768 ["Fetch To" message-insert-to
2769 :help "Insert a To header that points to the author."]
2770 ["Fetch To and Cc" message-insert-wide-reply
2771 :help "Insert To and Cc headers as if you were doing a wide reply."]
2773 ["Send to list only" message-to-list-only t]
2774 ["Mail-Followup-To" message-goto-mail-followup-to t]
2775 ["Unsubscribed list post" message-generate-unsubscribed-mail-followup-to
2776 :help "Insert a reasonable `Mail-Followup-To:' header."]
2777 ["Reduce To: to Cc:" message-reduce-to-to-cc t]
2779 ["Sort Headers" message-sort-headers t]
2780 ["Encode non-ASCII domain names" message-idna-to-ascii-rhs t]
2781 ;; We hide `message-hidden-headers' by narrowing the buffer.
2782 ["Show Hidden Headers" widen t]
2783 ["Goto Body" message-goto-body t]
2784 ["Goto Signature" message-goto-signature t]))
2786 (defvar message-tool-bar-map nil)
2788 (defvar facemenu-add-face-function)
2789 (defvar facemenu-remove-face-function)
2791 ;;; Forbidden properties
2793 ;; We use `after-change-functions' to keep special text properties
2794 ;; that interfere with the normal function of message mode out of the
2797 (defcustom message-strip-special-text-properties t
2798 "Strip special properties from the message buffer.
2800 Emacs has a number of special text properties which can break message
2801 composing in various ways. If this option is set, message will strip
2802 these properties from the message composition buffer. However, some
2803 packages requires these properties to be present in order to work.
2804 If you use one of these packages, turn this option off, and hope the
2805 message composition doesn't break too bad."
2807 :group 'message-various
2808 :link '(custom-manual "(message)Various Message Variables")
2811 (defvar message-forbidden-properties
2812 ;; No reason this should be clutter up customize. We make it a
2813 ;; property list (rather than a list of property symbols), to be
2814 ;; directly useful for `remove-text-properties'.
2815 '(field nil read-only nil invisible nil intangible nil
2816 mouse-face nil modification-hooks nil insert-in-front-hooks nil
2817 insert-behind-hooks nil point-entered nil point-left nil)
2818 ;; Other special properties:
2819 ;; category, face, display: probably doesn't do any harm.
2820 ;; fontified: is used by font-lock.
2821 ;; syntax-table, local-map: I dunno.
2822 "Property list of with properties forbidden in message buffers.
2823 The values of the properties are ignored, only the property names are used.")
2825 (defun message-tamago-not-in-use-p (pos)
2826 "Return t when tamago version 4 is not in use at the cursor position.
2827 Tamago version 4 is a popular input method for writing Japanese text.
2828 It uses the properties `intangible', `invisible', `modification-hooks'
2829 and `read-only' when translating ascii or kana text to kanji text.
2830 These properties are essential to work, so we should never strip them."
2831 (not (and (boundp 'egg-modefull-mode)
2832 (symbol-value 'egg-modefull-mode)
2833 (or (memq (get-text-property pos 'intangible)
2834 '(its-part-1 its-part-2))
2835 (get-text-property pos 'egg-end)
2836 (get-text-property pos 'egg-lang)
2837 (get-text-property pos 'egg-start)))))
2839 (defsubst message-mail-alias-type-p (type)
2840 (if (atom message-mail-alias-type)
2841 (eq message-mail-alias-type type)
2842 (memq type message-mail-alias-type)))
2844 (defun message-strip-forbidden-properties (begin end &optional old-length)
2845 "Strip forbidden properties between BEGIN and END, ignoring the third arg.
2846 This function is intended to be called from `after-change-functions'.
2847 See also `message-forbidden-properties'."
2848 (when (and (message-mail-alias-type-p 'ecomplete)
2849 (memq this-command message-self-insert-commands))
2850 (message-display-abbrev))
2851 (when (and message-strip-special-text-properties
2852 (message-tamago-not-in-use-p begin))
2853 (let ((buffer-read-only nil)
2854 (inhibit-read-only t))
2855 (remove-text-properties begin end message-forbidden-properties))))
2857 (defvar message-smileys '(":-)" ":)"
2860 "A list of recognized smiley faces in `message-mode'.")
2862 (defun message--syntax-propertize (beg end)
2863 "Syntax-propertize certain message text specially."
2864 (let ((citation-regexp (concat "^" message-cite-prefix-regexp ".*$"))
2865 (smiley-regexp (regexp-opt message-smileys)))
2867 (while (search-forward-regexp citation-regexp
2869 (let ((start (match-beginning 0))
2870 (end (match-end 0)))
2871 (add-text-properties start (1+ start)
2872 `(syntax-table ,(string-to-syntax "<")))
2873 (add-text-properties end (min (1+ end) (point-max))
2874 `(syntax-table ,(string-to-syntax ">")))))
2876 (while (search-forward-regexp smiley-regexp
2878 (add-text-properties (match-beginning 0) (match-end 0)
2879 `(syntax-table ,(string-to-syntax "."))))))
2882 (define-derived-mode message-mode text-mode "Message"
2883 "Major mode for editing mail and news to be sent.
2884 Like Text Mode but with these additional commands:\\<message-mode-map>
2885 C-c C-s `message-send' (send the message) C-c C-c `message-send-and-exit'
2886 C-c C-d Postpone sending the message C-c C-k Kill the message
2887 C-c C-f move to a header field (and create it if there isn't):
2888 C-c C-f C-t move to To C-c C-f C-s move to Subject
2889 C-c C-f C-c move to Cc C-c C-f C-b move to Bcc
2890 C-c C-f C-w move to Fcc C-c C-f C-r move to Reply-To
2891 C-c C-f C-u move to Summary C-c C-f C-n move to Newsgroups
2892 C-c C-f C-k move to Keywords C-c C-f C-d move to Distribution
2893 C-c C-f C-o move to From (\"Originator\")
2894 C-c C-f C-f move to Followup-To
2895 C-c C-f C-m move to Mail-Followup-To
2896 C-c C-f C-e move to Expires
2897 C-c C-f C-i cycle through Importance values
2898 C-c C-f s change subject and append \"(was: <Old Subject>)\"
2899 C-c C-f x crossposting with FollowUp-To header and note in body
2900 C-c C-f t replace To: header with contents of Cc: or Bcc:
2901 C-c C-f a Insert X-No-Archive: header and a note in the body
2902 C-c C-t `message-insert-to' (add a To header to a news followup)
2903 C-c C-l `message-to-list-only' (removes all but list address in to/cc)
2904 C-c C-n `message-insert-newsgroups' (add a Newsgroup header to a news reply)
2905 C-c C-b `message-goto-body' (move to beginning of message text).
2906 C-c C-i `message-goto-signature' (move to the beginning of the signature).
2907 C-c C-w `message-insert-signature' (insert `message-signature-file' file).
2908 C-c C-y `message-yank-original' (insert current message, if any).
2909 C-c C-q `message-fill-yanked-message' (fill what was yanked).
2910 C-c C-e `message-elide-region' (elide the text between point and mark).
2911 C-c C-v `message-delete-not-region' (remove the text outside the region).
2912 C-c C-z `message-kill-to-signature' (kill the text up to the signature).
2913 C-c C-r `message-caesar-buffer-body' (rot13 the message body).
2914 C-c C-a `mml-attach-file' (attach a file as MIME).
2915 C-c C-u `message-insert-or-toggle-importance' (insert or cycle importance).
2916 C-c M-n `message-insert-disposition-notification-to' (request receipt).
2917 C-c M-m `message-mark-inserted-region' (mark region with enclosing tags).
2918 C-c M-f `message-mark-insert-file' (insert file marked with enclosing tags).
2919 M-RET `message-newline-and-reformat' (break the line and reformat)."
2920 (set (make-local-variable 'message-reply-buffer) nil)
2921 (set (make-local-variable 'message-inserted-headers) nil)
2922 (set (make-local-variable 'message-send-actions) nil)
2923 (set (make-local-variable 'message-return-action) nil)
2924 (set (make-local-variable 'message-exit-actions) nil)
2925 (set (make-local-variable 'message-kill-actions) nil)
2926 (set (make-local-variable 'message-postpone-actions) nil)
2927 (set (make-local-variable 'message-draft-article) nil)
2928 (setq buffer-offer-save t)
2929 (set (make-local-variable 'facemenu-add-face-function)
2931 (let ((face-fun (cdr (assq face message-face-alist))))
2933 (funcall face-fun (point) end)
2934 (error "Face %s not configured for %s mode" face mode-name)))
2936 (set (make-local-variable 'facemenu-remove-face-function) t)
2937 (set (make-local-variable 'message-reply-headers) nil)
2938 (make-local-variable 'message-newsreader)
2939 (make-local-variable 'message-mailer)
2940 (make-local-variable 'message-post-method)
2941 (set (make-local-variable 'message-sent-message-via) nil)
2942 (set (make-local-variable 'message-checksum) nil)
2943 (set (make-local-variable 'message-mime-part) 0)
2944 (message-setup-fill-variables)
2945 (when message-fill-column
2946 (setq fill-column message-fill-column)
2947 (turn-on-auto-fill))
2948 ;; Allow using comment commands to add/remove quoting.
2949 ;; (set (make-local-variable 'comment-start) message-yank-prefix)
2950 (when message-yank-prefix
2951 (set (make-local-variable 'comment-start) message-yank-prefix)
2952 (set (make-local-variable 'comment-start-skip)
2953 (concat "^" (regexp-quote message-yank-prefix) "[ \t]*")))
2954 (set (make-local-variable 'font-lock-defaults)
2955 '(message-font-lock-keywords t))
2956 (if (boundp 'tool-bar-map)
2957 (set (make-local-variable 'tool-bar-map) (message-make-tool-bar)))
2958 (easy-menu-add message-mode-menu message-mode-map)
2959 (easy-menu-add message-mode-field-menu message-mode-map)
2960 ;; Mmmm... Forbidden properties...
2961 (add-hook 'after-change-functions 'message-strip-forbidden-properties
2963 ;; Allow mail alias things.
2965 ((message-mail-alias-type-p 'abbrev)
2966 (mail-abbrevs-setup))
2967 ((message-mail-alias-type-p 'ecomplete)
2969 (add-hook 'completion-at-point-functions 'message-completion-function nil t)
2970 (unless buffer-file-name
2971 (message-set-auto-save-file-name))
2972 (unless (buffer-base-buffer)
2973 ;; Don't enable multibyte on an indirect buffer. Maybe enabling
2974 ;; multibyte is not necessary at all. -- zsh
2975 (mm-enable-multibyte))
2976 (set (make-local-variable 'indent-tabs-mode) nil) ;No tabs for indentation.
2978 ;; Syntactic fontification. Helps `show-paren-mode',
2979 ;; `electric-pair-mode', and C-M-* navigation by syntactically
2980 ;; excluding citations and other artifacts.
2982 (set (make-local-variable 'syntax-propertize-function) 'message--syntax-propertize)
2983 (set (make-local-variable 'parse-sexp-ignore-comments) t))
2985 (defun message-setup-fill-variables ()
2986 "Setup message fill variables."
2987 (set (make-local-variable 'fill-paragraph-function)
2988 'message-fill-paragraph)
2989 (make-local-variable 'paragraph-separate)
2990 (make-local-variable 'paragraph-start)
2991 (make-local-variable 'adaptive-fill-regexp)
2992 (make-local-variable 'adaptive-fill-first-line-regexp)
2993 (let ((quote-prefix-regexp
2994 ;; User should change message-cite-prefix-regexp if
2995 ;; message-yank-prefix is set to an abnormal value.
2996 (concat "\\(" message-cite-prefix-regexp "\\)[ \t]*")))
2997 (setq paragraph-start
2999 (regexp-quote mail-header-separator) "$\\|"
3000 "[ \t]*$\\|" ; blank lines
3001 "-- $\\|" ; signature delimiter
3002 "---+$\\|" ; delimiters for forwarded messages
3003 page-delimiter "$\\|" ; spoiler warnings
3004 ".*wrote:$\\|" ; attribution lines
3005 quote-prefix-regexp "$\\|" ; empty lines in quoted text
3007 "<#!*/?\\(multipart\\|part\\|external\\|mml\\|secure\\)"))
3008 (setq paragraph-separate paragraph-start)
3009 (setq adaptive-fill-regexp
3010 (concat quote-prefix-regexp "\\|" adaptive-fill-regexp))
3011 (setq adaptive-fill-first-line-regexp
3012 (concat quote-prefix-regexp "\\|"
3013 adaptive-fill-first-line-regexp)))
3014 (setq-local auto-fill-inhibit-regexp nil)
3015 (setq-local normal-auto-fill-function 'message-do-auto-fill))
3020 ;;; Message mode commands
3023 ;;; Movement commands
3025 (defun message-goto-to ()
3026 "Move point to the To header."
3029 (message-position-on-field "To"))
3031 (defun message-goto-from ()
3032 "Move point to the From header."
3035 (message-position-on-field "From"))
3037 (defun message-goto-subject ()
3038 "Move point to the Subject header."
3041 (message-position-on-field "Subject"))
3043 (defun message-goto-cc ()
3044 "Move point to the Cc header."
3047 (message-position-on-field "Cc" "To"))
3049 (defun message-goto-bcc ()
3050 "Move point to the Bcc header."
3053 (message-position-on-field "Bcc" "Cc" "To"))
3055 (defun message-goto-fcc ()
3056 "Move point to the Fcc header."
3059 (message-position-on-field "Fcc" "To" "Newsgroups"))
3061 (defun message-goto-reply-to ()
3062 "Move point to the Reply-To header."
3065 (message-position-on-field "Reply-To" "Subject"))
3067 (defun message-goto-newsgroups ()
3068 "Move point to the Newsgroups header."
3071 (message-position-on-field "Newsgroups"))
3073 (defun message-goto-distribution ()
3074 "Move point to the Distribution header."
3077 (message-position-on-field "Distribution"))
3079 (defun message-goto-followup-to ()
3080 "Move point to the Followup-To header."
3083 (message-position-on-field "Followup-To" "Newsgroups"))
3085 (defun message-goto-mail-followup-to ()
3086 "Move point to the Mail-Followup-To header."
3089 (message-position-on-field "Mail-Followup-To" "To"))
3091 (defun message-goto-keywords ()
3092 "Move point to the Keywords header."
3095 (message-position-on-field "Keywords" "Subject"))
3097 (defun message-goto-summary ()
3098 "Move point to the Summary header."
3101 (message-position-on-field "Summary" "Subject"))
3103 (defun message-goto-body ()
3104 "Move point to the beginning of the message body."
3106 (when (and (called-interactively-p 'any)
3107 (looking-at "[ \t]*\n"))
3110 (goto-char (point-min))
3111 (or (search-forward (concat "\n" mail-header-separator "\n") nil t)
3112 (search-forward-regexp "[^:]+:\\([^\n]\\|\n[ \t]\\)+\n\n" nil t)))
3114 (defun message-in-body-p ()
3115 "Return t if point is in the message body."
3118 (goto-char (point-min))
3119 (or (search-forward (concat "\n" mail-header-separator "\n") nil t)
3120 (search-forward-regexp "[^:]+:\\([^\n]\\|\n[ \t]\\)+\n\n" nil t))
3123 (defun message-goto-eoh ()
3124 "Move point to the end of the headers."
3129 (defun message-goto-signature ()
3130 "Move point to the beginning of the message signature.
3131 If there is no signature in the article, go to the end and
3135 (goto-char (point-min))
3136 (if (re-search-forward message-signature-separator nil t)
3138 (goto-char (point-max))
3141 (defun message-generate-unsubscribed-mail-followup-to (&optional include-cc)
3142 "Insert a reasonable MFT header in a post to an unsubscribed list.
3143 When making original posts to a mailing list you are not subscribed to,
3144 you have to type in a MFT header by hand. The contents, usually, are
3145 the addresses of the list and your own address. This function inserts
3146 such a header automatically. It fetches the contents of the To: header
3147 in the current mail buffer, and appends the current `user-mail-address'.
3149 If the optional argument INCLUDE-CC is non-nil, the addresses in the
3150 Cc: header are also put into the MFT."
3155 (message-narrow-to-headers)
3156 (message-remove-header "Mail-Followup-To")
3157 (setq cc (and include-cc (message-fetch-field "Cc")))
3159 (concat (message-fetch-field "To") "," cc)
3160 (message-fetch-field "To"))))
3161 (message-goto-mail-followup-to)
3162 (insert (concat tos ", " user-mail-address))))
3166 (defun message-insert-to (&optional force)
3167 "Insert a To header that points to the author of the article being replied to.
3168 If the original author requested not to be sent mail, don't insert unless the
3169 prefix FORCE is given."
3171 (let* ((mct (message-fetch-reply-field "mail-copies-to"))
3172 (dont (and mct (or (equal (downcase mct) "never")
3173 (equal (downcase mct) "nobody"))))
3174 (to (or (message-fetch-reply-field "mail-reply-to")
3175 (message-fetch-reply-field "reply-to")
3176 (message-fetch-reply-field "from"))))
3180 "Ignoring the user request not to have copies sent via mail"
3181 "Complying with the user request not to have copies sent via mail")))
3182 (when (and force (not to))
3183 (error "No mail address in the article"))
3184 (when (and to (or force (not dont)))
3185 (message-carefully-insert-headers (list (cons 'To to))))))
3187 (defun message-insert-wide-reply ()
3188 "Insert To and Cc headers as if you were doing a wide reply."
3190 (let ((headers (message-with-reply-buffer
3191 (message-get-reply-headers t))))
3192 (message-carefully-insert-headers headers)))
3194 (defcustom message-header-synonyms
3197 "List of lists of header synonyms.
3198 E.g., if this list contains a member list with elements `Cc' and `To',
3199 then `message-carefully-insert-headers' will not insert a `To' header
3200 when the message is already `Cc'ed to the recipient."
3202 :group 'message-headers
3203 :link '(custom-manual "(message)Message Headers")
3204 :type '(repeat sexp))
3206 (defun message-carefully-insert-headers (headers)
3207 "Insert the HEADERS, an alist, into the message buffer.
3208 Does not insert the headers when they are already present there
3209 or in the synonym headers, defined by `message-header-synonyms'."
3210 ;; FIXME: Should compare only the address and not the full name. Comparison
3211 ;; should be done case-folded (and with `string=' rather than
3213 ;; (mail-strip-quoted-names "Foo Bar <foo@bar>, bla@fasel (Bla Fasel)")
3214 (dolist (header headers)
3215 (let* ((header-name (symbol-name (car header)))
3216 (new-header (cdr header))
3217 (synonyms (loop for synonym in message-header-synonyms
3218 when (memq (car header) synonym) return synonym))
3220 (loop for synonym in synonyms
3221 for old-header = (mail-fetch-field (symbol-name synonym))
3222 when (and old-header (string-match new-header old-header))
3225 (message "already have `%s' in `%s'" new-header old-header)
3226 (when (and (message-position-on-field header-name)
3227 (setq old-header (mail-fetch-field header-name))
3228 (not (string-match "\\` *\\'" old-header)))
3230 (insert new-header)))))
3232 (defun message-widen-reply ()
3233 "Widen the reply to include maximum recipients."
3236 (and (bufferp message-reply-buffer)
3237 (buffer-name message-reply-buffer)
3238 (with-current-buffer message-reply-buffer
3239 (message-get-reply-headers t)))))
3242 (message-narrow-to-headers)
3243 (dolist (elem follow-to)
3244 (message-remove-header (symbol-name (car elem)))
3245 (goto-char (point-min))
3246 (insert (symbol-name (car elem)) ": "
3247 (cdr elem) "\n"))))))
3249 (defun message-insert-newsgroups ()
3250 "Insert the Newsgroups header from the article being replied to."
3252 (let ((old-newsgroups (mail-fetch-field "newsgroups"))
3253 (new-newsgroups (message-fetch-reply-field "newsgroups"))
3256 (message-position-on-field "Newsgroups")
3258 ((not new-newsgroups)
3259 (error "No Newsgroups to insert"))
3260 ((not old-newsgroups)
3261 (insert new-newsgroups))
3263 (setq new-newsgroups (split-string new-newsgroups "[, ]+")
3264 old-newsgroups (split-string old-newsgroups "[, ]+"))
3265 (dolist (group new-newsgroups)
3266 (unless (member group old-newsgroups)
3267 (push group insert-newsgroups)))
3268 (if (null insert-newsgroups)
3269 (error "Newgroup%s already in the header"
3270 (if (> (length new-newsgroups) 1)
3272 (when old-newsgroups
3274 (dolist (group insert-newsgroups)
3278 (insert group)))))))
3282 ;;; Various commands
3284 (defun message-delete-not-region (beg end)
3285 "Delete everything in the body of the current message outside of the region."
3290 ;; snarf citation prefix, if appropriate
3291 (unless (eq (point) (progn (beginning-of-line) (point)))
3292 (when (looking-at message-cite-prefix-regexp)
3293 (setq citeprefix (match-string 0))))
3295 (delete-region (point) (if (not (message-goto-signature))
3301 (delete-region beg (progn (message-goto-body)
3305 (insert citeprefix))))
3306 (when (message-goto-signature)
3309 (defun message-kill-to-signature (&optional arg)
3310 "Kill all text up to the signature.
3311 If a numeric argument or prefix arg is given, leave that number
3312 of lines before the signature intact."
3316 (let ((point (point)))
3317 (narrow-to-region point (point-max))
3318 (message-goto-signature)
3320 (if (and arg (numberp arg))
3321 (forward-line (- -1 arg))
3323 (unless (= point (point))
3324 (kill-region point (point))
3328 (defun message-newline-and-reformat (&optional arg not-break)
3329 "Insert four newlines, and then reformat if inside quoted text.
3330 Prefix arg means justify as well."
3331 (interactive (list (if current-prefix-arg 'full)))
3332 (let (quoted point beg end leading-space bolp fill-paragraph-function)
3333 (setq point (point))
3336 (setq bolp (= beg point))
3337 ;; Find first line of the paragraph.
3339 (while (and (not (eobp))
3340 (not (looking-at message-cite-prefix-regexp))
3341 (looking-at paragraph-start))
3344 (when (looking-at message-cite-prefix-regexp)
3345 (setq quoted (match-string 0))
3346 (goto-char (match-end 0))
3347 (looking-at "[ \t]*")
3348 (setq leading-space (match-string 0)))
3352 (< (- point beg) (length quoted)))
3353 ;; break inside the cite prefix.
3359 (while (and (not (eobp))
3360 (not (looking-at paragraph-separate))
3361 (looking-at message-cite-prefix-regexp)
3362 (equal quoted (match-string 0)))
3363 (goto-char (match-end 0))
3364 (looking-at "[ \t]*")
3365 (if (> (length leading-space) (length (match-string 0)))
3366 (setq leading-space (match-string 0)))
3370 (while (and (if (bobp) nil (forward-line -1) t)
3371 (not (looking-at paragraph-start))
3372 (looking-at message-cite-prefix-regexp)
3373 (equal quoted (match-string 0)))
3375 (goto-char (match-end 0))
3376 (looking-at "[ \t]*")
3377 (if (> (length leading-space) (length (match-string 0)))
3378 (setq leading-space (match-string 0)))))
3379 (while (and (not (eobp))
3380 (not (looking-at paragraph-separate))
3381 (not (looking-at message-cite-prefix-regexp)))
3385 (while (and (if (bobp) nil (forward-line -1) t)
3386 (not (looking-at paragraph-start))
3387 (not (looking-at message-cite-prefix-regexp)))
3388 (setq beg (point))))
3391 (narrow-to-region beg end)
3398 (setq point (point))
3399 ;; (newline 2) doesn't mark both newline's as hard, so call
3400 ;; newline twice. -jas
3403 (delete-region (point) (re-search-forward "[ \t]*"))
3404 (when (and quoted (not bolp))
3405 (insert quoted leading-space)))
3408 (let* ((adaptive-fill-regexp
3409 (regexp-quote (concat quoted leading-space)))
3410 (adaptive-fill-first-line-regexp
3411 adaptive-fill-regexp ))
3412 (fill-paragraph arg))
3413 (fill-paragraph arg))
3414 (if point (goto-char point)))))
3416 (defun message-fill-paragraph (&optional arg)
3417 "Message specific function to fill a paragraph.
3418 This function is used as the value of `fill-paragraph-function' in
3419 Message buffers and is not meant to be called directly."
3420 (interactive (list (if current-prefix-arg 'full)))
3421 (if (message-point-in-header-p)
3422 (message-fill-field)
3423 (message-newline-and-reformat arg t))
3426 (defun message-point-in-header-p ()
3427 "Return t if point is in the header."
3431 (let ((bound (+ (point-at-eol) 1)) case-fold-search)
3432 (goto-char (point-min))
3433 (not (search-forward (concat "\n" mail-header-separator "\n")
3436 (defun message-do-auto-fill ()
3437 "Like `do-auto-fill', but don't fill in message header."
3438 (unless (message-point-in-header-p)
3441 (defun message-insert-signature (&optional force)
3442 "Insert a signature. See documentation for variable `message-signature'."
3443 (interactive (list 0))
3446 ((and (null message-signature)
3449 (goto-char (point-max))
3450 (not (re-search-backward message-signature-separator nil t))))
3451 ((and (null message-signature)
3454 ((functionp message-signature)
3455 (funcall message-signature))
3456 ((listp message-signature)
3457 (eval message-signature))
3458 (t message-signature)))
3461 (cond ((stringp signature)
3463 ((and (eq t signature) message-signature-file)
3464 (setq signature-file
3465 (if (and message-signature-directory
3466 ;; don't actually use the signature directory
3467 ;; if message-signature-file contains a path.
3468 (not (file-name-directory
3469 message-signature-file)))
3470 (expand-file-name message-signature-file
3471 message-signature-directory)
3472 message-signature-file))
3473 (file-exists-p signature-file))))
3475 (goto-char (point-max))
3476 ;; Insert the signature.
3479 (when message-signature-insert-empty-line
3483 (if (eq signature t)
3484 (insert-file-contents signature-file)
3486 (goto-char (point-max))
3487 (or (bolp) (newline)))))
3489 (defun message-insert-importance-high ()
3490 "Insert header to mark message as important."
3494 (message-narrow-to-headers)
3495 (message-remove-header "Importance"))
3497 (insert "Importance: high\n")))
3499 (defun message-insert-importance-low ()
3500 "Insert header to mark message as unimportant."
3504 (message-narrow-to-headers)
3505 (message-remove-header "Importance"))
3507 (insert "Importance: low\n")))
3509 (defun message-insert-or-toggle-importance ()
3510 "Insert a \"Importance: high\" header, or cycle through the header values.
3511 The three allowed values according to RFC 1327 are `high', `normal'
3518 (message-narrow-to-headers)
3519 (when (setq cur (message-fetch-field "Importance"))
3520 (message-remove-header "Importance")
3521 (setq new (cond ((string= cur "high")
3523 ((string= cur "low")
3528 (insert (format "Importance: %s\n" new)))))
3530 (defun message-insert-disposition-notification-to ()
3531 "Request a disposition notification (return receipt) to this message.
3532 Note that this should not be used in newsgroups."
3536 (message-narrow-to-headers)
3537 (message-remove-header "Disposition-Notification-To"))
3539 (insert (format "Disposition-Notification-To: %s\n"
3540 (or (message-field-value "Reply-to")
3541 (message-field-value "From")
3542 (message-make-from))))))
3544 (defun message-elide-region (b e)
3545 "Elide the text in the region.
3546 An ellipsis (from `message-elide-ellipsis') will be inserted where the
3549 (let ((lines (count-lines b e))
3552 (insert (format-spec message-elide-ellipsis
3556 (defvar message-caesar-translation-table nil)
3558 (defun message-caesar-region (b e &optional n)
3559 "Caesar rotate region B to E by N, default 13, for decrypting netnews."
3562 (min (point) (or (mark t) (point)))
3563 (max (point) (or (mark t) (point)))
3564 (when current-prefix-arg
3565 (prefix-numeric-value current-prefix-arg))))
3567 (setq n (if (numberp n) (mod n 26) 13)) ;canonize N
3568 (unless (or (zerop n) ; no action needed for a rot of 0
3569 (= b e)) ; no region to rotate
3570 ;; We build the table, if necessary.
3571 (when (or (not message-caesar-translation-table)
3572 (/= (aref message-caesar-translation-table ?a) (+ ?a n)))
3573 (setq message-caesar-translation-table
3574 (message-make-caesar-translation-table n)))
3575 (translate-region b e message-caesar-translation-table)))
3577 (defun message-make-caesar-translation-table (n)
3578 "Create a rot table with offset N."
3580 (table (make-string 256 0)))
3581 (while (< (incf i) 256)
3584 (substring table 0 ?A)
3585 (substring table (+ ?A n) (+ ?A n (- 26 n)))
3586 (substring table ?A (+ ?A n))
3587 (substring table (+ ?A 26) ?a)
3588 (substring table (+ ?a n) (+ ?a n (- 26 n)))
3589 (substring table ?a (+ ?a n))
3590 (substring table (+ ?a 26) 255))))
3592 (defun message-caesar-buffer-body (&optional rotnum wide)
3593 "Caesar rotate all letters in the current buffer by 13 places.
3594 Used to encode/decode possibly offensive messages (commonly in rec.humor).
3595 With prefix arg, specifies the number of places to rotate each letter forward.
3596 Mail and USENET news headers are not rotated unless WIDE is non-nil."
3597 (interactive (if current-prefix-arg
3598 (list (prefix-numeric-value current-prefix-arg))
3602 (when (and (not wide) (message-goto-body))
3603 (narrow-to-region (point) (point-max)))
3604 (message-caesar-region (point-min) (point-max) rotnum))))
3606 (defun message-pipe-buffer-body (program)
3607 "Pipe the message body in the current buffer through PROGRAM."
3610 (when (message-goto-body)
3611 (narrow-to-region (point) (point-max)))
3612 (shell-command-on-region
3613 (point-min) (point-max) program nil t))))
3615 (defun message-rename-buffer (&optional enter-string)
3616 "Rename the *message* buffer to \"*message* RECIPIENT\".
3617 If the function is run with a prefix, it will ask for a new buffer
3618 name, rather than giving an automatic name."
3619 (interactive "Pbuffer name: ")
3622 (goto-char (point-min))
3623 (narrow-to-region (point)
3624 (search-forward mail-header-separator nil 'end))
3626 (if (message-news-p) (message-fetch-field "Newsgroups")
3627 (message-fetch-field "To"))
3630 (if (string-match "," mail-to)
3631 (concat (substring mail-to 0 (match-beginning 0)) ", ...")
3633 (name-default (concat "*message* " mail-trimmed-to))
3634 (name (if enter-string
3635 (read-string "New buffer name: " name-default)
3637 (rename-buffer name t)))))
3639 (defun message-fill-yanked-message (&optional justifyp)
3640 "Fill the paragraphs of a message yanked into this one.
3641 Numeric argument means justify as well."
3644 (goto-char (point-min))
3645 (search-forward (concat "\n" mail-header-separator "\n") nil t)
3646 (let ((fill-prefix message-yank-prefix))
3647 (fill-individual-paragraphs (point) (point-max) justifyp))))
3649 (defun message-indent-citation (&optional start end yank-only)
3650 "Modify text just inserted from a message to be cited.
3651 The inserted text should be the region.
3652 When this function returns, the region is again around the modified text.
3654 Normally, indent each nonblank line `message-indentation-spaces' spaces.
3655 However, if `message-yank-prefix' is non-nil, insert that prefix on each line."
3656 (unless start (setq start (point)))
3658 ;; Remove unwanted headers.
3659 (when message-ignored-cited-headers
3664 (if (search-forward "\n\n" nil t)
3667 (message-remove-header message-ignored-cited-headers t)
3668 (when (= (point-min) (point-max))
3669 (setq all-removed t))
3670 (goto-char (point-max)))
3674 ;; Delete blank lines at the start of the buffer.
3675 (while (and (point-min)
3678 (message-delete-line))
3679 ;; Delete blank lines at the end of the buffer.
3680 (goto-char (point-max))
3681 (unless (eq (preceding-char) ?\n)
3683 (while (and (zerop (forward-line -1))
3685 (message-delete-line)))
3686 ;; Do the indentation.
3687 (if (null message-yank-prefix)
3688 (indent-rigidly start (or end (mark t)) message-indentation-spaces)
3691 (while (< (point) (or end (mark t)))
3692 (cond ((looking-at ">")
3693 (insert message-yank-cited-prefix))
3695 (insert message-yank-empty-prefix))
3697 (insert message-yank-prefix)))
3701 (defun message-remove-blank-cited-lines (&optional remove)
3702 "Remove cited lines containing only blanks.
3703 If REMOVE is non-nil, remove newlines, too.
3705 To use this automatically, you may add this function to
3706 `gnus-message-setup-hook'."
3708 (let ((citexp (concat "^\\("
3709 (concat message-yank-cited-prefix "\\|")
3712 (message "Removing `%s'" citexp)
3715 (while (re-search-forward citexp nil t)
3716 (replace-match (if remove "" "\n"))))))
3718 (defun message--yank-original-internal (arg)
3719 (let ((modified (buffer-modified-p))
3721 (when (and message-reply-buffer
3722 message-cite-function)
3723 (when (equal message-cite-reply-position 'above)
3726 (buffer-substring (message-goto-body)
3728 (delete-region (message-goto-body) (point-max))))
3729 (if (bufferp message-reply-buffer)
3730 (delete-windows-on message-reply-buffer t))
3731 (push-mark (save-excursion
3733 ((bufferp message-reply-buffer)
3734 (insert-buffer-substring message-reply-buffer))
3735 ((and (consp message-reply-buffer)
3736 (functionp (car message-reply-buffer)))
3737 (apply (car message-reply-buffer)
3738 (cdr message-reply-buffer))))
3743 (funcall message-cite-function)
3744 (unless (eq (char-before (mark t)) ?\n)
3746 (goto-char (mark t))
3747 (insert-before-markers ?\n)
3749 (case message-cite-reply-position
3753 (insert (if (bolp) "\n" "\n\n"))
3754 (message-goto-body))
3756 (message-goto-signature)))
3757 ;; Add a `message-setup-very-last-hook' here?
3758 ;; Add `gnus-article-highlight-citation' here?
3760 (setq message-checksum (message-checksum))))))
3762 (defun message-yank-original (&optional arg)
3763 "Insert the message being replied to, if any.
3764 Puts point before the text and mark after.
3765 Normally indents each nonblank line ARG spaces (default 3). However,
3766 if `message-yank-prefix' is non-nil, insert that prefix on each line.
3768 This function uses `message-cite-function' to do the actual citing.
3770 Just \\[universal-argument] as argument means don't indent, insert no
3771 prefix, and don't delete any headers."
3773 ;; eval the let forms contained in message-cite-style
3775 `(let ,(if (symbolp message-cite-style)
3776 (symbol-value message-cite-style)
3778 (message--yank-original-internal ',arg))))
3780 (defun message-yank-buffer (buffer)
3781 "Insert BUFFER into the current buffer and quote it."
3782 (interactive "bYank buffer: ")
3783 (let ((message-reply-buffer (get-buffer buffer)))
3784 (save-window-excursion
3785 (message-yank-original))))
3787 (defun message-buffers ()
3788 "Return a list of active message buffers."
3790 (save-current-buffer
3791 (dolist (buffer (buffer-list t))
3793 (when (and (derived-mode-p 'message-mode)
3794 (null message-sent-message-via))
3795 (push (buffer-name buffer) buffers))))
3796 (nreverse buffers)))
3798 (defun message-cite-original-1 (strip-signature)
3799 "Cite an original message.
3800 If STRIP-SIGNATURE is non-nil, strips off the signature from the
3803 This function uses `mail-citation-hook' if that is non-nil."
3804 (if (and (boundp 'mail-citation-hook)
3806 (run-hooks 'mail-citation-hook)
3807 (let* ((start (point))
3811 (when message-indent-citation-function
3812 (if (listp message-indent-citation-function)
3813 message-indent-citation-function
3814 (list message-indent-citation-function))))
3815 ;; This function may be called by `gnus-summary-yank-message' and
3816 ;; may insert a different article from the original. So, we will
3817 ;; modify the value of `message-reply-headers' with that article.
3818 (message-reply-headers
3820 (narrow-to-region start end)
3821 (message-narrow-to-head-1)
3822 (setq x-no-archive (message-fetch-field "x-no-archive"))
3824 (or (message-fetch-field "subject") "none")
3825 (or (message-fetch-field "from") "nobody")
3826 (message-fetch-field "date")
3827 (message-fetch-field "message-id" t)
3828 (message-fetch-field "references")
3830 (mml-quote-region start end)
3831 (when strip-signature
3835 (when (re-search-backward message-signature-separator start t)
3836 ;; Also peel off any blank lines before the signature.
3838 (while (looking-at "^[ \t]*$")
3841 (delete-region (point) end)
3842 (unless (search-backward "\n\n" start t)
3843 ;; Insert a blank line if it is peeled off.
3846 (mapc 'funcall functions)
3847 (when message-citation-line-function
3850 (funcall message-citation-line-function))
3851 (when (and x-no-archive
3852 (not message-cite-articles-with-x-no-archive)
3853 (string-match "yes" x-no-archive))
3855 (delete-region (point) (mark t))
3856 (insert "> [Quoted text removed due to X-No-Archive]\n")
3858 (forward-line -1)))))
3860 (defun message-cite-original ()
3861 "Cite function in the standard Message manner."
3862 (message-cite-original-1 nil))
3864 (autoload 'format-spec "format-spec")
3865 (autoload 'gnus-date-get-time "gnus-util")
3867 (defun message-insert-formatted-citation-line (&optional from date tz)
3868 "Function that inserts a formatted citation line.
3869 The optional FROM, and DATE are strings containing the contents of
3870 the From header and the Date header respectively.
3872 The optional TZ is omitted or nil for Emacs local time, t for
3873 Universal Time, `wall' for system wall clock time, or a string as
3874 in the TZ environment variable. It can also be a list (as from
3875 `current-time-zone') or an integer (as from `decode-time')
3876 applied without consideration for daylight saving time.
3878 See `message-citation-line-format'."
3879 ;; The optional args are for testing/debugging. They will disappear later.
3881 ;; (with-temp-buffer
3882 ;; (message-insert-formatted-citation-line
3883 ;; "John Doe <john.doe@example.invalid>"
3884 ;; (message-make-date))
3886 (when (or message-reply-headers (and from date))
3888 (setq from (mail-header-from message-reply-headers)))
3889 (let* ((data (condition-case ()
3890 (funcall (if (boundp 'gnus-extract-address-components)
3891 gnus-extract-address-components
3892 'mail-extract-address-components)
3898 (net (car (cdr data)))
3899 (name-or-net (or (car data)
3900 (car (cdr data)) from))
3902 (when (string-match "%[^fnNFL]" message-citation-line-format)
3903 (cond ((numberp (car-safe date)) date) ;; backward compatibility
3904 (date (gnus-date-get-time date))
3907 (setq date (mail-header-date message-reply-headers)))))))
3909 (when (stringp date)
3910 (nth 8 (parse-time-string date)))))
3913 (when (stringp name)
3914 ;; Guess first name and last name:
3919 (if (string-match "\\`\\(\\w\\|[-.]\\)+\\'"
3923 (split-string name "[ \t]+"))))
3924 (count (length names)))
3926 (setq fname (car names)
3928 ((or (= count 2) (= count 3))
3929 (setq fname (car names)
3930 lname (mapconcat 'identity (cdr names) " ")))
3932 (setq fname (mapconcat 'identity
3933 (butlast names (- count 2))
3935 lname (mapconcat 'identity
3938 (when (string-match "\\(.*\\),\\'" fname)
3939 (let ((newlname (match-string 1 fname)))
3940 (setq fname lname lname newlname)))))
3941 ;; The following letters are not used in `format-time-string':
3942 (push ?E lst) (push "<E>" lst)
3943 (push ?F lst) (push (or fname name-or-net) lst)
3944 ;; We might want to use "" instead of "<X>" later.
3945 (push ?J lst) (push "<J>" lst)
3946 (push ?K lst) (push "<K>" lst)
3947 (push ?L lst) (push lname lst)
3948 (push ?N lst) (push name-or-net lst)
3949 (push ?O lst) (push "<O>" lst)
3950 (push ?P lst) (push "<P>" lst)
3951 (push ?Q lst) (push "<Q>" lst)
3952 (push ?f lst) (push from lst)
3953 (push ?i lst) (push "<i>" lst)
3954 (push ?n lst) (push net lst)
3955 (push ?o lst) (push "<o>" lst)
3956 (push ?q lst) (push "<q>" lst)
3957 (push ?t lst) (push "<t>" lst)
3958 (push ?v lst) (push "<v>" lst)
3959 ;; Delegate the rest to `format-time-string':
3961 (when (and (not (memq i lst))
3966 (push (condition-case nil
3967 (format-time-string (format "%%%c" i) time tz)
3968 (error (format ">%c<" i)))
3972 (spec (apply 'format-spec-make flist)))
3973 (insert (format-spec message-citation-line-format spec)))
3976 (defun message-cite-original-without-signature ()
3977 "Cite function in the standard Message manner.
3978 This function strips off the signature from the original message."
3979 (message-cite-original-1 t))
3981 (defun message-insert-citation-line ()
3982 "Insert a simple citation line."
3983 (when message-reply-headers
3984 (insert (mail-header-from message-reply-headers) " writes:")
3988 (defun message-position-on-field (header &rest afters)
3989 (let ((case-fold-search t))
3992 (goto-char (point-min))
3995 (concat "^" (regexp-quote mail-header-separator) "$"))
3996 (match-beginning 0)))
3997 (goto-char (point-min))
3998 (if (re-search-forward (concat "^" (regexp-quote header) ":") nil t)
4000 (re-search-forward "^[^ \t]" nil 'move)
4002 (skip-chars-backward "\n")
4005 (not (re-search-forward
4006 (concat "^" (regexp-quote (car afters)) ":")
4010 (re-search-forward "^[^ \t]" nil 'move)
4011 (beginning-of-line))
4012 (insert header ": \n")
4019 ;;; Sending messages
4022 (defun message-send-and-exit (&optional arg)
4023 "Send message like `message-send', then, if no errors, exit from mail buffer.
4024 The usage of ARG is defined by the instance that called Message.
4025 It should typically alter the sending method in some way or other."
4027 (let ((buf (current-buffer))
4028 (actions message-exit-actions))
4029 (when (and (message-send arg)
4032 (if message-kill-buffer-on-exit
4034 (message-do-actions actions)
4037 (defun message-dont-send ()
4038 "Don't send the message you have been editing.
4039 Instead, just auto-save the buffer and then bury it."
4041 (set-buffer-modified-p t)
4043 (let ((actions message-postpone-actions))
4044 (message-bury (current-buffer))
4045 (message-do-actions actions)))
4047 (defun message-kill-buffer ()
4048 "Kill the current buffer."
4050 (when (or (not (buffer-modified-p))
4051 (not message-kill-buffer-query)
4052 (yes-or-no-p "Message modified; kill anyway? "))
4053 (let ((actions message-kill-actions)
4054 (draft-article message-draft-article)
4055 (auto-save-file-name buffer-auto-save-file-name)
4056 (file-name buffer-file-name)
4057 (modified (buffer-modified-p)))
4058 (setq buffer-file-name nil)
4059 (kill-buffer (current-buffer))
4060 (when (and (or (and auto-save-file-name
4061 (file-exists-p auto-save-file-name))
4063 (file-exists-p file-name)))
4065 ;; If the message buffer has lived in a dedicated window,
4066 ;; `kill-buffer' has killed the frame. Thus the
4067 ;; `yes-or-no-p' may show up in a lowered frame. Make sure
4068 ;; that the user can see the question by raising the
4071 (yes-or-no-p (format "Remove the backup file%s? "
4072 (if modified " too" "")))))
4074 (delete-file auto-save-file-name))
4075 (let ((message-draft-article draft-article))
4076 (message-disassociate-draft)))
4077 (message-do-actions actions))))
4079 (defun message-bury (buffer)
4080 "Bury this mail BUFFER."
4081 ;; Note that this is not quite the same as (bury-buffer buffer),
4082 ;; since bury-buffer does extra stuff with a nil argument.
4083 ;; Eg http://lists.gnu.org/archive/html/emacs-devel/2014-01/msg00539.html
4084 (with-current-buffer buffer (bury-buffer))
4085 (if message-return-action
4086 (apply (car message-return-action) (cdr message-return-action))))
4088 (autoload 'mml-secure-bcc-is-safe "mml-sec")
4090 (defun message-send (&optional arg)
4091 "Send the message in the current buffer.
4092 If `message-interactive' is non-nil, wait for success indication or
4093 error messages, and inform user.
4094 Otherwise any failure is reported in a message back to the user from
4096 The usage of ARG is defined by the instance that called Message.
4097 It should typically alter the sending method in some way or other."
4099 ;; Make it possible to undo the coming changes.
4101 (let ((inhibit-read-only t))
4102 (put-text-property (point-min) (point-max) 'read-only nil))
4103 (message-fix-before-sending)
4104 (mml-secure-bcc-is-safe)
4105 (run-hooks 'message-send-hook)
4106 (when message-confirm-send
4107 (or (y-or-n-p "Send message? ")
4109 (message message-sending-message)
4110 (let ((alist message-send-method-alist)
4112 elem sent dont-barf-on-no-method
4113 (message-options message-options))
4114 (message-options-set-recipient)
4116 (setq elem (pop alist)))
4117 (when (funcall (cadr elem))
4118 (when (and (or (not (memq (car elem)
4119 message-sent-message-via))
4120 (message-fetch-field "supersedes")
4121 (if (or (message-gnksa-enable-p 'multiple-copies)
4122 (not (eq (car elem) 'news)))
4125 "Already sent message via %s; resend? "
4127 (error "Denied posting -- multiple copies")))
4128 (setq success (funcall (caddr elem) arg)))
4132 (let ((fcc (message-fetch-field "Fcc"))
4133 (gcc (message-fetch-field "Gcc")))
4135 (or (eq message-allow-no-recipients 'always)
4136 (and (not (eq message-allow-no-recipients 'never))
4137 (setq dont-barf-on-no-method
4139 (format "No receiver, perform %s anyway? "
4140 (cond ((and fcc gcc) "Fcc and Gcc")
4143 (error "No methods specified to send by"))
4144 (when (or dont-barf-on-no-method
4148 (run-hooks 'message-sent-hook))
4149 (message "Sending...done")
4150 ;; Do ecomplete address snarfing.
4151 (when (and (message-mail-alias-type-p 'ecomplete)
4152 (not message-inhibit-ecomplete))
4153 (message-put-addresses-in-ecomplete))
4154 ;; Mark the buffer as unmodified and delete auto-save.
4155 (set-buffer-modified-p nil)
4156 (delete-auto-save-file-if-necessary t)
4157 (message-disassociate-draft)
4158 ;; Delete other mail buffers and stuff.
4159 (message-do-send-housekeeping)
4160 (message-do-actions message-send-actions)
4164 (defun message-send-via-mail (arg)
4165 "Send the current message via mail."
4166 (message-send-mail arg))
4168 (defun message-send-via-news (arg)
4169 "Send the current message via news."
4170 (funcall message-send-news-function arg))
4172 (defmacro message-check (type &rest forms)
4173 "Eval FORMS if TYPE is to be checked."
4174 `(or (message-check-element ,type)
4178 (put 'message-check 'lisp-indent-function 1)
4179 (put 'message-check 'edebug-form-spec '(form body))
4181 (defun message-text-with-property (prop &optional start end reverse)
4182 "Return a list of start and end positions where the text has PROP.
4183 START and END bound the search, they default to `point-min' and
4184 `point-max' respectively. If REVERSE is non-nil, find text which does
4187 (setq start (point-min)))
4189 (setq end (point-max)))
4193 (setq start (text-property-any start end prop nil)))
4194 (setq next (next-single-property-change start prop nil end))
4195 (push (cons start (or next end)) regions)
4198 (or (get-text-property start prop)
4199 (and (setq start (next-single-property-change
4200 start prop nil end))
4201 (get-text-property start prop))))
4202 (setq next (text-property-any start end prop nil))
4203 (push (cons start (or next end)) regions)
4205 (nreverse regions)))
4207 (defcustom message-bogus-addresses
4208 '("noreply" "nospam" "invalid" "@@" "[^[:ascii:]].*@" "[ \t]")
4209 "List of regexps of potentially bogus mail addresses.
4210 See `message-check-recipients' how to setup checking.
4212 This list should make it possible to catch typos or warn about
4213 spam-trap addresses. It doesn't aim to verify strict RFC
4215 :version "23.1" ;; No Gnus
4216 :group 'message-headers
4218 (const :tag "None" nil)
4224 (const :tag "duplicate @" "@@")
4225 (const :tag "non-ascii local part" "[^[:ascii:]].*@")
4226 (const :tag "`_' in domain part" "@.*_")
4227 (const :tag "whitespace" "[ \t]"))
4232 (defun message-fix-before-sending ()
4233 "Do various things to make the message nice before sending it."
4234 ;; Make sure there's a newline at the end of the message.
4235 (goto-char (point-max))
4238 ;; Make the hidden headers visible.
4240 ;; Sort headers before sending the message.
4241 (message-sort-headers)
4242 ;; Make invisible text visible.
4243 ;; It doesn't seem as if this is useful, since the invisible property
4244 ;; is clobbered by an after-change hook anyhow.
4245 (message-check 'invisible-text
4246 (let ((regions (message-text-with-property 'invisible))
4250 (setq from (caar regions)
4252 regions (cdr regions))
4253 (put-text-property from to 'invisible nil)
4254 (overlay-put (make-overlay from to) 'face 'highlight))
4255 (unless (yes-or-no-p
4256 "Invisible text found and made visible; continue sending? ")
4257 (error "Invisible text found and made visible")))))
4258 (message-check 'illegible-text
4259 (let (char found choice nul-chars)
4261 (setq nul-chars (save-excursion
4262 (search-forward "\000" nil t)))
4264 (skip-chars-forward mm-7bit-chars)
4265 (when (get-text-property (point) 'no-illegible-text)
4266 ;; There is a signed or encrypted raw message part
4267 ;; that is considered to be safe.
4268 (goto-char (or (next-single-property-change
4269 (point) 'no-illegible-text)
4271 (setq char (char-after)))
4272 (when (or (< char 128)
4273 (and (mm-multibyte-p)
4274 (memq (char-charset char)
4275 '(eight-bit-control eight-bit-graphic
4276 ;; Emacs 23, Bug#1770:
4279 (not (get-text-property
4280 (point) 'untranslated-utf-8))))
4281 (overlay-put (make-overlay (point) (1+ (point))) 'face 'highlight)
4287 (read-multiple-choice
4289 "NUL characters found, which may cause problems. Continue sending?"
4290 "Non-printable characters found. Continue sending?")
4291 `((?d "delete" "Remove non-printable characters and send")
4294 "Replace non-printable characters with \"%s\" and send"
4295 message-replacement-char))
4296 (?s "send" "Send as is without removing anything")
4297 (?e "edit" "Continue editing")))))
4299 (error "Non-printable characters"))
4301 (skip-chars-forward mm-7bit-chars)
4303 (when (let ((char (char-after)))
4305 (and (mm-multibyte-p)
4306 ;; FIXME: Wrong for Emacs 23 (unicode) and for
4307 ;; things like undecodable utf-8 (in Emacs 21?).
4308 ;; Should at least use find-coding-systems-region.
4310 (memq (char-charset char)
4311 '(eight-bit-control eight-bit-graphic
4312 ;; Emacs 23, Bug#1770:
4315 (not (get-text-property
4316 (point) 'untranslated-utf-8)))))
4318 (message-kill-all-overlays)
4320 (when (eq choice ?r)
4321 (insert message-replacement-char))))
4323 (skip-chars-forward mm-7bit-chars)))))
4324 (message-check 'bogus-recipient
4325 ;; Warn before sending a mail to an invalid address.
4326 (message-check-recipients)))
4328 (defun message-bogus-recipient-p (recipients)
4329 "Check if a mail address in RECIPIENTS looks bogus.
4331 RECIPIENTS is a mail header. Return a list of potentially bogus
4332 addresses. If none is found, return nil.
4334 An address might be bogus if if there's a matching entry in
4335 `message-bogus-addresses'."
4336 ;; FIXME: How about "foo@subdomain", when the MTA adds ".domain.tld"?
4338 (mapc (lambda (address)
4339 (setq address (or (cadr address) ""))
4340 (when (or (string= "" address)
4341 (not (string-match "@" address))
4342 (string-match "@.*@" address)
4343 (and message-bogus-addresses
4345 (if (listp message-bogus-addresses)
4346 (mapconcat 'identity
4347 message-bogus-addresses
4349 message-bogus-addresses)))
4350 (string-match re address))))
4351 (push address found)))
4352 (mail-extract-address-components recipients t))
4355 (defun message-check-recipients ()
4356 "Warn before composing or sending a mail to an invalid address.
4358 This function could be useful in `message-setup-hook'."
4361 (message-narrow-to-headers)
4362 (dolist (hdr '("To" "Cc" "Bcc"))
4363 (let ((addr (message-fetch-field hdr)))
4364 (when (stringp addr)
4365 (dolist (bog (message-bogus-recipient-p addr))
4369 "Address `%s'%s might be bogus. Continue? "
4371 ;; If the encoded version of the email address
4372 ;; is different from the unencoded version,
4373 ;; then we likely have invisible characters or
4374 ;; the like. Display the encoded version,
4376 (let ((encoded (rfc2047-encode-string bog)))
4377 (if (string= encoded bog)
4379 (format " (%s)" encoded))))))
4380 (error "Bogus address"))))))))
4382 (custom-add-option 'message-setup-hook 'message-check-recipients)
4384 (defun message-add-action (action &rest types)
4385 "Add ACTION to be performed when doing an exit of type TYPES."
4387 (add-to-list (intern (format "message-%s-actions" (pop types)))
4390 (defun message-delete-action (action &rest types)
4391 "Delete ACTION from lists of actions performed when doing an exit of type TYPES."
4394 (set (setq var (intern (format "message-%s-actions" (pop types))))
4395 (delq action (symbol-value var))))))
4397 (defun message-do-actions (actions)
4398 "Perform all actions in ACTIONS."
4399 ;; Now perform actions on successful sending.
4400 (dolist (action actions)
4403 ;; A simple function.
4406 ;; Something to be evalled.
4410 (defun message-send-mail-partially ()
4411 "Send mail as message/partial."
4412 ;; replace the header delimiter with a blank line
4413 (goto-char (point-min))
4415 (concat "^" (regexp-quote mail-header-separator) "\n"))
4416 (replace-match "\n")
4417 (run-hooks 'message-send-mail-hook)
4418 (let ((p (goto-char (point-min)))
4419 (tembuf (message-generate-new-buffer-clone-locals " message temp"))
4420 (curbuf (current-buffer))
4421 (id (message-make-message-id)) (n 1)
4424 (if (< (point-max) (+ p message-send-mail-partially-limit))
4425 (goto-char (point-max))
4426 (goto-char (+ p message-send-mail-partially-limit))
4428 (if (<= (point) p) (forward-line 1))) ;; In case of bad message.
4431 (setq total (length plist))
4432 (push (point-max) plist)
4433 (setq plist (nreverse plist))
4436 (setq p (pop plist))
4439 (copy-to-buffer tembuf p (car plist))
4441 (goto-char (point-min))
4444 (goto-char (point-min))
4445 (narrow-to-region (point) (point))
4448 (setq header (buffer-substring (point-min) (point)))
4449 (goto-char (point-min))
4450 (narrow-to-region (point) (point))
4452 (message-remove-header "Mime-Version")
4453 (message-remove-header "Content-Type")
4454 (message-remove-header "Content-Transfer-Encoding")
4455 (message-remove-header "Message-ID")
4456 (message-remove-header "Lines")
4457 (goto-char (point-max))
4458 (insert "Mime-Version: 1.0\n")
4459 (setq header (buffer-string)))
4460 (goto-char (point-max))
4461 (insert (format "Content-Type: message/partial; id=\"%s\"; number=%d; total=%d\n\n"
4464 (let ((mail-header-separator ""))
4465 (when (memq 'Message-ID message-required-mail-headers)
4466 (insert "Message-ID: " (message-make-message-id) "\n"))
4467 (when (memq 'Lines message-required-mail-headers)
4468 (insert "Lines: " (message-make-lines) "\n"))
4469 (message-goto-subject)
4471 (insert (format " (%d/%d)" n total))
4473 (if message-send-mail-real-function
4474 (funcall message-send-mail-real-function)
4475 (message-multi-smtp-send-mail)))
4477 (setq p (pop plist))
4479 (kill-buffer tembuf))))
4481 (declare-function hashcash-wait-async "hashcash" (&optional buffer))
4483 (defun message-send-mail (&optional arg)
4484 (require 'mail-utils)
4485 (let* ((tembuf (message-generate-new-buffer-clone-locals " message temp"))
4486 (case-fold-search nil)
4487 (news (message-news-p))
4488 (mailbuf (current-buffer))
4489 (message-this-is-mail t)
4490 ;; gnus-setup-posting-charset is autoloaded in mml.el (FIXME
4491 ;; maybe it should not be), which this file requires. Hence
4492 ;; the fboundp test is always true. Loading it from gnus-msg
4493 ;; loads many Gnus files (Bug#5642). If
4494 ;; gnus-group-posting-charset-alist hasn't been customized,
4495 ;; this is just going to return nil anyway. FIXME it would
4496 ;; be good to improve this further, because even if g-g-p-c-a
4497 ;; has been customized, that is likely to just be for news.
4498 ;; Eg either move the definition from gnus-msg, or separate out
4499 ;; the mail and news parts.
4500 (message-posting-charset
4501 (if (and (fboundp 'gnus-setup-posting-charset)
4502 (boundp 'gnus-group-posting-charset-alist))
4503 (gnus-setup-posting-charset nil)
4504 message-posting-charset))
4505 (headers message-required-mail-headers)
4507 (when (and message-generate-hashcash
4508 (not (eq message-generate-hashcash 'opportunistic)))
4509 (message "Generating hashcash...")
4511 ;; Wait for calculations already started to finish...
4512 (hashcash-wait-async)
4513 ;; ...and do calculations not already done. mail-add-payment
4514 ;; will leave existing X-Hashcash headers alone.
4516 (message "Generating hashcash...done"))
4518 (message-narrow-to-headers)
4519 ;; Generate the Mail-Followup-To header if the header is not there...
4520 (if (and (message-subscribed-p)
4521 (not (mail-fetch-field "mail-followup-to")))
4524 (cons "Mail-Followup-To" (message-make-mail-followup-to))
4525 message-required-mail-headers))
4526 ;; otherwise, delete the MFT header if the field is empty
4527 (when (equal "" (mail-fetch-field "mail-followup-to"))
4528 (message-remove-header "^Mail-Followup-To:")))
4529 ;; Insert some headers.
4530 (let ((message-deletable-headers
4531 (if news nil message-deletable-headers)))
4532 (message-generate-headers headers))
4533 ;; Check continuation headers.
4534 (message-check 'continuation-headers
4535 (goto-char (point-min))
4536 (while (re-search-forward "^[^ \t\n][^ \t\n:]*[ \t\n]" nil t)
4537 (goto-char (match-beginning 0))
4538 (if (y-or-n-p "Fix continuation lines? ")
4541 (unless (y-or-n-p "Send anyway? ")
4542 (error "Failed to send the message")))))
4543 ;; Let the user do all of the above.
4544 (run-hooks 'message-header-hook))
4545 (setq options message-options)
4547 (with-current-buffer tembuf
4549 (setq message-options options)
4550 ;; Avoid copying text props (except hard newlines).
4551 (insert (with-current-buffer mailbuf
4552 (mml-buffer-substring-no-properties-except-some
4553 (point-min) (point-max))))
4554 ;; Remove some headers.
4555 (message-encode-message-body)
4557 (message-narrow-to-headers)
4558 ;; We (re)generate the Lines header.
4559 (when (memq 'Lines message-required-mail-headers)
4560 (message-generate-headers '(Lines)))
4561 ;; Remove some headers.
4562 (message-remove-header message-ignored-mail-headers t)
4563 (let ((mail-parse-charset message-default-charset))
4564 (mail-encode-encoded-word-buffer)))
4565 (goto-char (point-max))
4566 ;; require one newline at the end.
4567 (or (= (preceding-char) ?\n)
4569 (message-cleanup-headers)
4570 ;; FIXME: we're inserting the courtesy copy after encoding.
4571 ;; This is wrong if the courtesy copy string contains
4572 ;; non-ASCII characters. -- jh
4575 (message-narrow-to-headers)
4577 (not (message-fetch-field "List-Post"))
4578 (not (message-fetch-field "List-ID"))
4579 (or (message-fetch-field "cc")
4580 (message-fetch-field "bcc")
4581 (message-fetch-field "to"))
4582 (let ((content-type (message-fetch-field
4587 (string= "text/plain"
4589 (mail-header-parse-content-type
4593 (message-fetch-field
4594 "content-transfer-encoding")))))))
4595 (message-insert-courtesy-copy
4596 (with-current-buffer mailbuf
4597 message-courtesy-message)))
4598 ;; Let's make sure we encoded all the body.
4599 (assert (save-excursion
4600 (goto-char (point-min))
4601 (not (re-search-forward "[^\000-\377]" nil t))))
4602 (mm-disable-multibyte)
4603 (if (or (not message-send-mail-partially-limit)
4604 (< (buffer-size) message-send-mail-partially-limit)
4605 (not (message-y-or-n-p
4606 "The message size is too large, split? "
4610 (/ (buffer-size) 1000) "KB, is too large.
4612 Some mail gateways (MTA's) bounce large messages. To avoid the
4613 problem, answer `y', and the message will be split into several
4614 smaller pieces, the size of each is about "
4615 (/ message-send-mail-partially-limit 1000)
4619 However, some mail readers (MUA's) can't read split messages, i.e.,
4620 mails in message/partially format. Answer `n', and the message will be
4623 The size limit is controlled by `message-send-mail-partially-limit'.
4624 If you always want Gnus to send messages in one piece, set
4625 `message-send-mail-partially-limit' to nil.
4628 (message "Sending via mail...")
4629 (if message-send-mail-real-function
4630 (funcall message-send-mail-real-function)
4631 (message-multi-smtp-send-mail)))
4632 (message-send-mail-partially))
4633 (setq options message-options))
4634 (kill-buffer tembuf))
4635 (set-buffer mailbuf)
4636 (setq message-options options)
4637 (push 'mail message-sent-message-via)))
4639 (defvar sendmail-program)
4640 (defvar smtpmail-smtp-user)
4642 (defun message-multi-smtp-send-mail ()
4643 "Send the current buffer to `message-send-mail-function'.
4644 Or, if there's a header that specifies a different method, use
4646 (let ((method (message-field-value "X-Message-SMTP-Method")))
4648 (funcall message-send-mail-function)
4649 (message-remove-header "X-Message-SMTP-Method")
4650 (setq method (split-string method))
4652 ((equal (car method) "sendmail")
4653 (message-send-mail-with-sendmail))
4654 ((equal (car method) "smtp")
4656 (let ((smtpmail-smtp-server (nth 1 method))
4657 (smtpmail-smtp-service (nth 2 method))
4658 (smtpmail-smtp-user (or (nth 3 method) smtpmail-smtp-user)))
4659 (message-smtpmail-send-it)))
4661 (error "Unknown method %s" method))))))
4663 (defun message-send-mail-with-sendmail ()
4664 "Send off the prepared buffer with sendmail."
4666 (let ((errbuf (if message-interactive
4667 (message-generate-new-buffer-clone-locals
4670 resend-to-addresses delimline)
4673 (let ((case-fold-search t))
4675 (message-narrow-to-headers)
4676 (setq resend-to-addresses (message-fetch-field "resent-to")))
4677 ;; Change header-delimiter to be what sendmail expects.
4678 (goto-char (point-min))
4680 (concat "^" (regexp-quote mail-header-separator) "\n"))
4681 (replace-match "\n")
4683 (setq delimline (point-marker))
4684 (run-hooks 'message-send-mail-hook)
4685 ;; Insert an extra newline if we need it to work around
4686 ;; Sun's bug that swallows newlines.
4687 (goto-char (1+ delimline))
4688 (when (eval message-mailer-swallows-blank-line)
4690 (when message-interactive
4691 (with-current-buffer errbuf
4693 (let* ((default-directory "/")
4694 (coding-system-for-write message-send-coding-system)
4696 'call-process-region
4698 (list (point-min) (point-max) sendmail-program
4699 nil errbuf nil "-oi")
4700 message-sendmail-extra-arguments
4701 ;; Always specify who from,
4702 ;; since some systems have broken sendmails.
4703 ;; But some systems are more broken with -f, so
4704 ;; we'll let users override this.
4705 (and (null message-sendmail-f-is-evil)
4706 (list "-f" (message-sendmail-envelope-from)))
4707 ;; These mean "report errors by mail"
4708 ;; and "deliver in background".
4709 (if (null message-interactive) '("-oem" "-odb"))
4710 ;; Get the addresses from the message
4711 ;; unless this is a resend.
4712 ;; We must not do that for a resend
4713 ;; because we would find the original addresses.
4714 ;; For a resend, include the specific addresses.
4715 (if resend-to-addresses
4716 (list resend-to-addresses)
4718 (unless (or (null cpr) (and (numberp cpr) (zerop cpr)))
4720 (pop-to-buffer errbuf)
4722 (error "Sending...failed with exit value %d" cpr)))
4723 (when message-interactive
4724 (with-current-buffer errbuf
4725 (goto-char (point-min))
4726 (while (re-search-forward "\n+ *" nil t)
4727 (replace-match "; "))
4728 (if (not (zerop (buffer-size)))
4729 (error "Sending...failed to %s"
4730 (buffer-string))))))
4731 (when (bufferp errbuf)
4732 (kill-buffer errbuf)))))
4734 (defun message-send-mail-with-qmail ()
4735 "Pass the prepared message buffer to qmail-inject.
4736 Refer to the documentation for the variable `message-send-mail-function'
4737 to find out how to use this."
4738 ;; replace the header delimiter with a blank line
4739 (goto-char (point-min))
4741 (concat "^" (regexp-quote mail-header-separator) "\n"))
4742 (replace-match "\n")
4743 (run-hooks 'message-send-mail-hook)
4746 (let ((coding-system-for-write message-send-coding-system))
4748 'call-process-region (point-min) (point-max)
4749 message-qmail-inject-program nil nil nil
4750 ;; qmail-inject's default behavior is to look for addresses on the
4751 ;; command line; if there're none, it scans the headers.
4752 ;; yes, it does The Right Thing w.r.t. Resent-To and it's kin.
4754 ;; in general, ALL of qmail-inject's defaults are perfect for simply
4755 ;; reading a formatted (i. e., at least a To: or Resent-To header)
4756 ;; message from stdin.
4758 ;; qmail also has the advantage of not having been raped by
4759 ;; various vendors, so we don't have to allow for that, either --
4760 ;; compare this with message-send-mail-with-sendmail and weep
4761 ;; for sendmail's lost innocence.
4763 ;; all this is way cool coz it lets us keep the arguments entirely
4764 ;; free for -inject-arguments -- a big win for the user and for us
4765 ;; since we don't have to play that double-guessing game and the user
4766 ;; gets full control (no gestapo'ish -f's, for instance). --sj
4767 (if (functionp message-qmail-inject-args)
4768 (funcall message-qmail-inject-args)
4769 message-qmail-inject-args)))
4770 ;; qmail-inject doesn't say anything on it's stdout/stderr,
4771 ;; we have to look at the retval instead
4773 (100 (error "qmail-inject reported permanent failure"))
4774 (111 (error "qmail-inject reported transient failure"))
4775 ;; should never happen
4776 (t (error "qmail-inject reported unknown failure"))))
4778 (defvar mh-previous-window-config)
4780 (defun message-send-mail-with-mh ()
4781 "Send the prepared message buffer with mh."
4782 (let ((mh-previous-window-config nil)
4783 (name (mh-new-draft-name)))
4784 (setq buffer-file-name name)
4785 ;; MH wants to generate these headers itself.
4786 (when message-mh-deletable-headers
4787 (let ((headers message-mh-deletable-headers))
4789 (goto-char (point-min))
4790 (and (re-search-forward
4791 (concat "^" (symbol-name (car headers)) ": *") nil t)
4792 (message-delete-line))
4794 (run-hooks 'message-send-mail-hook)
4795 ;; Pass it on to mh.
4798 (defun message-smtpmail-send-it ()
4799 "Send the prepared message buffer with `smtpmail-send-it'.
4800 The only difference from `smtpmail-send-it' is that this command
4801 evaluates `message-send-mail-hook' just before sending a message.
4802 It is useful if your ISP requires the POP-before-SMTP
4803 authentication. See the Gnus manual for details."
4804 (run-hooks 'message-send-mail-hook)
4805 ;; Change header-delimiter to be what smtpmail expects.
4806 (goto-char (point-min))
4807 (when (re-search-forward
4808 (concat "^" (regexp-quote mail-header-separator) "\n"))
4809 (replace-match "\n"))
4812 (defun message-send-mail-with-mailclient ()
4813 "Send the prepared message buffer with `mailclient-send-it'.
4814 The only difference from `mailclient-send-it' is that this
4815 command evaluates `message-send-mail-hook' just before sending a message."
4816 (run-hooks 'message-send-mail-hook)
4817 (mailclient-send-it))
4819 (defun message-canlock-generate ()
4820 "Return a string that is non-trivial to guess.
4821 Do not use this for anything important, it is cryptographically weak."
4823 (let (sha1-maximum-internal-length)
4824 (sha1 (concat (message-unique-id)
4825 (format "%x%x%x" (random) (random) (random))
4826 (prin1-to-string (recent-keys))
4827 (prin1-to-string (garbage-collect))))))
4829 (defvar canlock-password)
4830 (defvar canlock-password-for-verify)
4832 (defun message-canlock-password ()
4833 "The password used by message for cancel locks.
4834 This is the value of `canlock-password', if that option is non-nil.
4835 Otherwise, generate and save a value for `canlock-password' first."
4837 (unless canlock-password
4838 (customize-save-variable 'canlock-password (message-canlock-generate))
4839 (setq canlock-password-for-verify canlock-password))
4842 (defun message-insert-canlock ()
4843 (when message-insert-canlock
4844 (message-canlock-password)
4845 (canlock-insert-header)))
4847 (autoload 'nnheader-get-report "nnheader")
4849 (declare-function gnus-setup-posting-charset "gnus-msg" (group))
4851 (defun message-send-news (&optional arg)
4853 (let* ((tembuf (message-generate-new-buffer-clone-locals " *message temp*"))
4854 (case-fold-search nil)
4855 (method (if (functionp message-post-method)
4856 (funcall message-post-method arg)
4857 message-post-method))
4858 (newsgroups-field (save-restriction
4859 (message-narrow-to-headers-or-head)
4860 (message-fetch-field "Newsgroups")))
4861 (followup-field (save-restriction
4862 (message-narrow-to-headers-or-head)
4863 (message-fetch-field "Followup-To")))
4864 ;; BUG: We really need to get the charset for each name in the
4865 ;; Newsgroups and Followup-To lines to allow crossposting
4866 ;; between group names with incompatible character sets.
4867 ;; -- Per Abrahamsen <abraham@dina.kvl.dk> 2001-10-08.
4868 (group-field-charset
4869 (gnus-group-name-charset method newsgroups-field))
4870 (followup-field-charset
4871 (gnus-group-name-charset method (or followup-field "")))
4872 (rfc2047-header-encoding-alist
4873 (append (when group-field-charset
4874 (list (cons "Newsgroups" group-field-charset)))
4875 (when followup-field-charset
4876 (list (cons "Followup-To" followup-field-charset)))
4877 rfc2047-header-encoding-alist))
4878 (messbuf (current-buffer))
4879 (message-syntax-checks
4881 (listp message-syntax-checks))
4882 (cons '(existing-newsgroups . disabled)
4883 message-syntax-checks)
4884 message-syntax-checks))
4885 (message-this-is-news t)
4886 (message-posting-charset
4887 (gnus-setup-posting-charset newsgroups-field))
4889 (if (not (message-check-news-body-syntax))
4892 (message-narrow-to-headers)
4893 ;; Insert some headers.
4894 (message-generate-headers message-required-news-headers)
4895 (message-insert-canlock)
4896 ;; Let the user do all of the above.
4897 (run-hooks 'message-header-hook))
4898 ;; Note: This check will be disabled by the ".*" default value for
4899 ;; gnus-group-name-charset-group-alist. -- Pa 2001-10-07.
4900 (when (and group-field-charset
4901 (listp message-syntax-checks))
4902 (setq message-syntax-checks
4903 (cons '(valid-newsgroups . disabled)
4904 message-syntax-checks)))
4905 (message-cleanup-headers)
4906 (if (not (let ((message-post-method method))
4907 (message-check-news-syntax)))
4910 (with-current-buffer tembuf
4911 (buffer-disable-undo)
4913 ;; Avoid copying text props (except hard newlines).
4915 (with-current-buffer messbuf
4916 (mml-buffer-substring-no-properties-except-some
4917 (point-min) (point-max))))
4918 (message-encode-message-body)
4919 ;; Remove some headers.
4921 (message-narrow-to-headers)
4922 ;; We (re)generate the Lines header.
4923 (when (memq 'Lines message-required-mail-headers)
4924 (message-generate-headers '(Lines)))
4925 ;; Remove some headers.
4926 (message-remove-header message-ignored-news-headers t)
4927 (let ((mail-parse-charset message-default-charset))
4928 (mail-encode-encoded-word-buffer)))
4929 (goto-char (point-max))
4930 ;; require one newline at the end.
4931 (or (= (preceding-char) ?\n)
4933 (let ((case-fold-search t))
4934 ;; Remove the delimiter.
4935 (goto-char (point-min))
4937 (concat "^" (regexp-quote mail-header-separator) "\n"))
4938 (replace-match "\n")
4940 (run-hooks 'message-send-news-hook)
4941 (gnus-open-server method)
4942 (message "Sending news via %s..." (gnus-server-string method))
4943 (setq result (let ((mail-header-separator ""))
4944 (gnus-request-post method))))
4945 (kill-buffer tembuf))
4946 (set-buffer messbuf)
4948 (push 'news message-sent-message-via)
4949 (message "Couldn't send message via news: %s"
4950 (nnheader-get-report (car method)))
4954 ;;; Header generation & syntax checking.
4957 (defun message-check-element (type)
4958 "Return non-nil if this TYPE is not to be checked."
4959 (if (eq message-syntax-checks 'dont-check-for-anything-just-trust-me)
4961 (let ((able (assq type message-syntax-checks)))
4963 (eq (cdr able) 'disabled)))))
4965 (defun message-check-news-syntax ()
4966 "Check the syntax of the message."
4970 ;; We narrow to the headers and check them first.
4973 (message-narrow-to-headers)
4974 (message-check-news-header-syntax))))))
4976 (defun message-check-news-header-syntax ()
4978 ;; Check Newsgroups header.
4979 (message-check 'newsgroups
4980 (let ((group (message-fetch-field "newsgroups")))
4983 (not (string-match "\\`[ \t]*\\'" group)))
4986 "The newsgroups field is empty or missing. Posting is denied.")))))
4987 ;; Check the Subject header.
4988 (message-check 'subject
4989 (let* ((case-fold-search t)
4990 (subject (message-fetch-field "subject")))
4993 (not (string-match "\\`[ \t]*\\'" subject)))
4996 "The subject field is empty or missing. Posting is denied.")))))
4997 ;; Check for commands in Subject.
4998 (message-check 'subject-cmsg
4999 (if (string-match "^cmsg " (message-fetch-field "subject"))
5001 "The control code \"cmsg\" is in the subject. Really post? ")
5003 ;; Check long header lines.
5004 (message-check 'long-header-lines
5008 (while (and (not found)
5009 (re-search-forward "^\\([^ \t:]+\\): " nil t))
5010 (if (> (- (point) (match-beginning 0)) 998)
5012 length (- (point) (match-beginning 0)))
5013 (setq header (match-string-no-properties 1)))
5016 (y-or-n-p (format "Your %s header is too long (%d). Really post? "
5019 ;; Check for multiple identical headers.
5020 (message-check 'multiple-headers
5022 (while (and (not found)
5023 (re-search-forward "^[^ \t:]+: " nil t))
5025 (or (re-search-forward
5030 (match-beginning 0) (- (match-end 0) 2))))
5035 (y-or-n-p (format "Multiple %s headers. Really post? " found))
5037 ;; Check for Version and Sendsys.
5038 (message-check 'sendsys
5039 (if (re-search-forward "^Sendsys:\\|^Version:" nil t)
5041 (format "The article contains a %s command. Really post? "
5042 (buffer-substring (match-beginning 0)
5043 (1- (match-end 0)))))
5045 ;; See whether we can shorten Followup-To.
5046 (message-check 'shorten-followup-to
5047 (let ((newsgroups (message-fetch-field "newsgroups"))
5048 (followup-to (message-fetch-field "followup-to"))
5050 (when (and newsgroups
5051 (string-match "," newsgroups)
5056 (setq to (completing-read
5057 "Followups to (default no Followup-To header): "
5060 (message-tokenize-header
5062 (goto-char (point-min))
5063 (insert "Followup-To: " to "\n"))
5065 ;; Check "Shoot me".
5066 (message-check 'shoot
5067 (if (re-search-forward
5068 "Message-ID.*.i-did-not-set--mail-host-address--so-tickle-me" nil t)
5069 (y-or-n-p "You appear to have a misconfigured system. Really post? ")
5071 ;; Check for Approved.
5072 (message-check 'approved
5073 (if (re-search-forward "^Approved:" nil t)
5074 (y-or-n-p "The article contains an Approved header. Really post? ")
5076 ;; Check the Message-ID header.
5077 (message-check 'message-id
5078 (let* ((case-fold-search t)
5079 (message-id (message-fetch-field "message-id" t)))
5080 (or (not message-id)
5081 ;; Is there an @ in the ID?
5082 (and (string-match "@" message-id)
5083 ;; Is there a dot in the ID?
5084 (string-match "@[^.]*\\." message-id)
5085 ;; Does the ID end with a dot?
5086 (not (string-match "\\.>" message-id)))
5088 (format "The Message-ID looks strange: \"%s\". Really post? "
5090 ;; Check the Newsgroups & Followup-To headers.
5091 (message-check 'existing-newsgroups
5092 (let* ((case-fold-search t)
5093 (newsgroups (message-fetch-field "newsgroups"))
5094 (followup-to (message-fetch-field "followup-to"))
5095 (groups (message-tokenize-header
5097 (concat newsgroups "," followup-to)
5099 (post-method (if (functionp message-post-method)
5100 (funcall message-post-method)
5101 message-post-method))
5102 ;; KLUDGE to handle nnvirtual groups. Doing this right
5103 ;; would probably involve a new nnoo function.
5104 ;; -- Per Abrahamsen <abraham@dina.kvl.dk>, 2001-10-17.
5105 (method (if (and (consp post-method)
5106 (eq (car post-method) 'nnvirtual)
5107 gnus-message-group-art)
5108 (let ((group (car (nnvirtual-find-group-art
5109 (car gnus-message-group-art)
5110 (cdr gnus-message-group-art)))))
5111 (gnus-find-method-for-group group))
5115 (gnus-group-name-decode
5116 (gnus-group-real-name n)
5117 (gnus-group-name-charset method n)))
5118 (gnus-groups-from-server method)))
5121 (when (and (not (equal (car groups) "poster"))
5122 (not (member (car groups) known-groups))
5123 (not (member (car groups) errors)))
5124 (push (car groups) errors))
5127 ;; Gnus is not running.
5128 ((or (not (and (boundp 'gnus-active-hashtb)
5129 gnus-active-hashtb))
5130 (not (boundp 'gnus-read-active-file)))
5132 ;; We don't have all the group names.
5133 ((and (or (not gnus-read-active-file)
5134 (eq gnus-read-active-file 'some))
5138 "Really use %s possibly unknown group%s: %s? "
5139 (if (= (length errors) 1) "this" "these")
5140 (if (= (length errors) 1) "" "s")
5141 (mapconcat 'identity errors ", "))))
5142 ;; There were no errors.
5145 ;; There are unknown groups.
5149 "Really post to %s unknown group%s: %s? "
5150 (if (= (length errors) 1) "this" "these")
5151 (if (= (length errors) 1) "" "s")
5152 (mapconcat 'identity errors ", ")))))))
5153 ;; Check continuation headers.
5154 (message-check 'continuation-headers
5155 (goto-char (point-min))
5156 (let ((do-posting t))
5157 (while (re-search-forward "^[^ \t\n][^ \t\n:]*[ \t\n]" nil t)
5158 (goto-char (match-beginning 0))
5159 (if (y-or-n-p "Fix continuation lines? ")
5162 (unless (y-or-n-p "Send anyway? ")
5163 (setq do-posting nil))))
5165 ;; Check the Newsgroups & Followup-To headers for syntax errors.
5166 (message-check 'valid-newsgroups
5167 (let ((case-fold-search t)
5168 (headers '("Newsgroups" "Followup-To"))
5170 (while (and headers (not error))
5171 (when (setq header (mail-fetch-field (car headers)))
5175 "\\`\\([-+_&.a-zA-Z0-9]+\\)?\\(,[-+_&.a-zA-Z0-9]+\\)*\\'"
5180 (not (string-match "\\.\\'\\|\\.\\." g)))
5181 (message-tokenize-header header ","))))
5188 (format "The %s header looks odd: \"%s\". Really post? "
5189 (car headers) header)))))
5190 (message-check 'repeated-newsgroups
5191 (let ((case-fold-search t)
5192 (headers '("Newsgroups" "Followup-To"))
5193 header error groups group)
5196 (when (setq header (mail-fetch-field (pop headers)))
5197 (setq groups (message-tokenize-header header ","))
5198 (while (setq group (pop groups))
5199 (when (member group groups)
5205 (format "Group %s is repeated in headers. Really post? " error)))))
5206 ;; Check the From header.
5207 (message-check 'from
5208 (let* ((case-fold-search t)
5209 (from (message-fetch-field "from"))
5213 (message "There is no From line. Posting is denied.")
5215 ((or (not (string-match
5217 (setq ad (nth 1 (mail-extract-address-components
5218 from))))) ;larsi@ifi
5219 (string-match "\\.\\." ad) ;larsi@ifi..uio
5220 (string-match "@\\." ad) ;larsi@.ifi.uio
5221 (string-match "\\.$" ad) ;larsi@ifi.uio.
5222 (not (string-match "^[^@]+@[^@]+$" ad)) ;larsi.ifi.uio
5223 (string-match "(.*).*(.*)" from)) ;(lars) (lars)
5225 "Denied posting -- the From looks strange: \"%s\"." from)
5227 ((let ((addresses (rfc822-addresses from)))
5228 ;; `rfc822-addresses' returns a string if parsing fails.
5229 (while (and (consp addresses)
5230 (not (eq (string-to-char (car addresses)) ?\()))
5231 (setq addresses (cdr addresses)))
5234 "Denied posting -- bad From address: \"%s\"." from)
5237 ;; Check the Reply-To header.
5238 (message-check 'reply-to
5239 (let* ((case-fold-search t)
5240 (reply-to (message-fetch-field "reply-to"))
5245 ((string-match "," reply-to)
5247 (format "Multiple Reply-To addresses: \"%s\". Really post? "
5249 ((or (not (string-match
5251 (setq ad (nth 1 (mail-extract-address-components
5252 reply-to))))) ;larsi@ifi
5253 (string-match "\\.\\." ad) ;larsi@ifi..uio
5254 (string-match "@\\." ad) ;larsi@.ifi.uio
5255 (string-match "\\.$" ad) ;larsi@ifi.uio.
5256 (not (string-match "^[^@]+@[^@]+$" ad)) ;larsi.ifi.uio
5257 (string-match "(.*).*(.*)" reply-to)) ;(lars) (lars)
5260 "The Reply-To looks strange: \"%s\". Really post? "
5264 (defun message-check-news-body-syntax ()
5266 ;; Check for long lines.
5267 (message-check 'long-lines
5268 (goto-char (point-min))
5270 (concat "^" (regexp-quote mail-header-separator) "$"))
5274 "<#\\(/\\)?\\(multipart\\|part\\|external\\|mml\\)")
5277 (< (- (point) p) 80)))
5278 (zerop (forward-line 1))))
5282 "You have lines longer than 79 characters. Really post? ")))
5283 ;; Check whether the article is empty.
5284 (message-check 'empty
5285 (goto-char (point-min))
5287 (concat "^" (regexp-quote mail-header-separator) "$"))
5290 (goto-char (point-max))
5291 (re-search-backward message-signature-separator nil t)
5293 (or (re-search-backward "[^ \n\t]" b t)
5294 (if (message-gnksa-enable-p 'empty-article)
5295 (y-or-n-p "Empty article. Really post? ")
5296 (message "Denied posting -- Empty article.")
5298 ;; Check for control characters.
5299 (message-check 'control-chars
5300 (if (re-search-forward
5301 (string-to-multibyte "[\000-\007\013\015-\032\034-\037\200-\237]")
5304 "The article contains control characters. Really post? ")
5306 ;; Check excessive size.
5307 (message-check 'size
5308 (if (> (buffer-size) 60000)
5310 (format "The article is %d octets long. Really post? "
5313 ;; Check whether any new text has been added.
5314 (message-check 'new-text
5316 (not message-checksum)
5317 (not (eq (message-checksum) message-checksum))
5318 (if (message-gnksa-enable-p 'quoted-text-only)
5320 "It looks like no new text has been added. Really post? ")
5321 (message "Denied posting -- no new text has been added.")
5323 ;; Check the length of the signature.
5324 (message-check 'signature
5325 (let (sig-start sig-end)
5326 (goto-char (point-max))
5327 (if (not (re-search-backward message-signature-separator nil t))
5329 (setq sig-start (1+ (point-at-eol)))
5331 (if (re-search-forward
5332 "<#/?\\(multipart\\|part\\|external\\|mml\\)" nil t)
5333 (- (point-at-bol) 1)
5335 (if (>= (count-lines sig-start sig-end) 5)
5336 (if (message-gnksa-enable-p 'signature)
5338 (format "Signature is excessively long (%d lines). Really post? "
5339 (count-lines sig-start sig-end)))
5340 (message "Denied posting -- Excessive signature.")
5343 ;; Ensure that text follows last quoted portion.
5344 (message-check 'quoting-style
5345 (goto-char (point-max))
5346 (let ((no-problem t))
5347 (when (search-backward-regexp "^>[^\n]*\n" nil t)
5348 (setq no-problem (search-forward-regexp "^[ \t]*[^>\n]" nil t)))
5351 (if (message-gnksa-enable-p 'quoted-text-only)
5352 (y-or-n-p "Your text should follow quoted text. Really post? ")
5354 (goto-char (point-min))
5356 (concat "^" (regexp-quote mail-header-separator) "$"))
5357 (if (search-forward-regexp "^[ \t]*[^>\n]" nil t)
5358 (y-or-n-p "Your text should follow quoted text. Really post? ")
5359 (message "Denied posting -- only quoted text.")
5362 (defun message-checksum ()
5363 "Return a \"checksum\" for the current buffer."
5366 (goto-char (point-min))
5368 (concat "^" (regexp-quote mail-header-separator) "$"))
5370 (when (not (looking-at "[ \t\n]"))
5371 (setq sum (logxor (ash sum 1) (if (natnump sum) 0 1)
5376 (defun message-do-fcc ()
5377 "Process Fcc headers in the current buffer."
5378 (let ((case-fold-search t)
5379 (buf (current-buffer))
5381 (mml-externalize-attachments message-fcc-externalize-attachments))
5384 (message-narrow-to-headers)
5385 (setq file (message-fetch-field "fcc" t)))
5387 (set-buffer (get-buffer-create " *message temp*"))
5389 (insert-buffer-substring buf)
5390 (message-encode-message-body)
5392 (message-narrow-to-headers)
5393 (while (setq file (message-fetch-field "fcc" t))
5395 (message-remove-header "fcc" nil t))
5396 (let ((mail-parse-charset message-default-charset)
5397 (rfc2047-header-encoding-alist
5398 (cons '("Newsgroups" . default)
5399 rfc2047-header-encoding-alist)))
5400 (mail-encode-encoded-word-buffer)))
5401 (goto-char (point-min))
5402 (when (re-search-forward
5403 (concat "^" (regexp-quote mail-header-separator) "$")
5405 (replace-match "" t t ))
5406 ;; Process FCC operations.
5408 (setq file (pop list))
5409 (if (string-match "^[ \t]*|[ \t]*\\(.*\\)[ \t]*$" file)
5410 ;; Pipe the article to the program in question.
5411 (call-process-region (point-min) (point-max) shell-file-name
5412 nil nil nil shell-command-switch
5413 (match-string 1 file))
5414 ;; Save the article.
5415 (setq file (expand-file-name file))
5416 (unless (file-exists-p (file-name-directory file))
5417 (make-directory (file-name-directory file) t))
5418 (if (and message-fcc-handler-function
5419 (not (eq message-fcc-handler-function 'rmail-output)))
5420 (funcall message-fcc-handler-function file)
5421 ;; FIXME this option, rmail-output (also used if
5422 ;; message-fcc-handler-function is nil) is not
5423 ;; documented anywhere AFAICS. It should work in Emacs
5424 ;; 23; I suspect it does not work in Emacs 22.
5425 ;; FIXME I don't see the need for the two different cases here.
5426 ;; mail-use-rfc822 makes no difference (in Emacs 23),and
5427 ;; the third argument just controls \"Wrote file\" message.
5428 (if (and (file-readable-p file) (mail-file-babyl-p file))
5429 (rmail-output file 1 nil t)
5430 (let ((mail-use-rfc822 t))
5431 (rmail-output file 1 t t))))))
5432 (kill-buffer (current-buffer))))))
5434 (defun message-output (filename)
5435 "Append this article to Unix/babyl mail file FILENAME."
5436 (if (or (and (file-readable-p filename)
5437 (mail-file-babyl-p filename))
5438 ;; gnus-output-to-mail does the wrong thing with live, mbox
5439 ;; Rmail buffers in Emacs 23.
5440 ;; http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=597255
5441 (let ((buff (find-buffer-visiting filename)))
5442 (and buff (with-current-buffer buff
5443 (eq major-mode 'rmail-mode)))))
5444 (gnus-output-to-rmail filename t)
5445 (gnus-output-to-mail filename t)))
5447 (defun message-cleanup-headers ()
5448 "Do various automatic cleanups of the headers."
5449 ;; Remove empty lines in the header.
5451 (message-narrow-to-headers)
5452 ;; Remove blank lines.
5453 (while (re-search-forward "^[ \t]*\n" nil t)
5454 (replace-match "" t t))
5456 ;; Correct Newsgroups and Followup-To headers: Change sequence of
5457 ;; spaces to comma and eliminate spaces around commas. Eliminate
5458 ;; embedded line breaks.
5459 (goto-char (point-min))
5460 (while (re-search-forward "^\\(Newsgroups\\|Followup-To\\): +" nil t)
5464 (if (re-search-forward "^[^ \t]" nil t)
5468 (goto-char (point-min))
5469 (while (re-search-forward "\n[ \t]+" nil t)
5470 (replace-match " " t t)) ;No line breaks (too confusing)
5471 (goto-char (point-min))
5472 (while (re-search-forward "[ \t\n]*,[ \t\n]*\\|[ \t]+" nil t)
5473 (replace-match "," t t))
5474 (goto-char (point-min))
5475 ;; Remove trailing commas.
5476 (when (re-search-forward ",+$" nil t)
5477 (replace-match "" t t))))))
5479 (defun message-make-date (&optional now)
5480 "Make a valid data header.
5481 If NOW, use that time instead."
5482 (let ((system-time-locale "C"))
5483 (format-time-string "%a, %d %b %Y %T %z" now)))
5485 (defun message-insert-expires (days)
5486 "Insert the Expires header. Expiry in DAYS days."
5487 (interactive "NExpire article in how many days? ")
5489 (message-position-on-field "Expires" "X-Draft-From")
5490 (insert (message-make-expires-date days))))
5492 (defun message-make-expires-date (days)
5493 "Make date string for the Expires header. Expiry in DAYS days.
5495 In posting styles use `(\"Expires\" (make-expires-date 30))'."
5496 (let* ((cur (decode-time))
5497 (nday (+ days (nth 3 cur))))
5498 (setf (nth 3 cur) nday)
5499 (message-make-date (apply 'encode-time cur))))
5501 (defun message-make-message-id ()
5502 "Make a unique Message-ID."
5503 (concat "<" (message-unique-id)
5504 (let ((psubject (save-excursion (message-fetch-field "subject")))
5506 (save-excursion (message-fetch-field "supersedes"))))
5508 (and message-reply-headers
5509 (mail-header-references message-reply-headers)
5510 (mail-header-subject message-reply-headers)
5513 (message-strip-subject-re
5514 (mail-header-subject message-reply-headers))
5515 (message-strip-subject-re psubject))))
5517 (string-match "_-_@" psupersedes)))
5519 "@" (message-make-fqdn) ">"))
5521 (defvar message-unique-id-char nil)
5523 ;; If you ever change this function, make sure the new version
5524 ;; cannot generate IDs that the old version could.
5525 ;; You might for example insert a "." somewhere (not next to another dot
5526 ;; or string boundary), or modify the "fsf" string.
5527 (defun message-unique-id ()
5528 ;; Don't use microseconds from (current-time), they may be unsupported.
5529 ;; Instead we use this randomly inited counter.
5530 (setq message-unique-id-char
5531 (% (1+ (or message-unique-id-char
5532 (logand (random most-positive-fixnum) (1- (lsh 1 20)))))
5533 ;; (current-time) returns 16-bit ints,
5534 ;; and 2^16*25 just fits into 4 digits i base 36.
5536 (let ((tm (current-time)))
5538 (if (or (eq system-type 'ms-dos)
5539 ;; message-number-base36 doesn't handle bigints.
5540 (floatp (user-uid)))
5541 (let ((user (downcase (user-login-name))))
5542 (while (string-match "[^a-z0-9_]" user)
5543 (aset user (match-beginning 0) ?_))
5545 (message-number-base36 (user-uid) -1))
5546 (message-number-base36 (+ (car tm)
5547 (lsh (% message-unique-id-char 25) 16)) 4)
5548 (message-number-base36 (+ (nth 1 tm)
5549 (lsh (/ message-unique-id-char 25) 16)) 4)
5550 ;; Append a given name, because while the generated ID is unique
5551 ;; to this newsreader, other newsreaders might otherwise generate
5552 ;; the same ID via another algorithm.
5555 (defun message-number-base36 (num len)
5560 (concat (message-number-base36 (/ num 36) (1- len))
5561 (char-to-string (aref "zyxwvutsrqponmlkjihgfedcba9876543210"
5564 (defun message-make-organization ()
5565 "Make an Organization header."
5566 (let* ((organization
5567 (when message-user-organization
5568 (if (functionp message-user-organization)
5569 (funcall message-user-organization)
5570 message-user-organization))))
5572 (mm-enable-multibyte)
5573 (cond ((stringp organization)
5574 (insert organization))
5575 ((and (eq t organization)
5576 message-user-organization-file
5577 (file-exists-p message-user-organization-file))
5578 (insert-file-contents message-user-organization-file)))
5579 (goto-char (point-min))
5580 (while (re-search-forward "[\t\n]+" nil t)
5581 (replace-match "" t t))
5582 (unless (zerop (buffer-size))
5585 (defun message-make-lines ()
5586 "Count the number of lines and return numeric string."
5591 (int-to-string (count-lines (point) (point-max))))))
5593 (defun message-make-references ()
5594 "Return the References header for this message."
5595 (when message-reply-headers
5596 (let ((message-id (mail-header-id message-reply-headers))
5597 (references (mail-header-references message-reply-headers)))
5598 (if (or references message-id)
5599 (concat (or references "") (and references " ")
5603 (defun message-make-in-reply-to ()
5604 "Return the In-Reply-To header for this message."
5605 (when message-reply-headers
5606 (let ((from (mail-header-from message-reply-headers))
5607 (date (mail-header-date message-reply-headers))
5608 (msg-id (mail-header-id message-reply-headers)))
5610 (let ((name (mail-extract-address-components from)))
5612 msg-id (if msg-id " (")
5614 (if (string-match "[^\000-\177]" (car name))
5615 ;; Quote a string containing non-ASCII characters.
5616 ;; It will make the RFC2047 encoder cause an error
5617 ;; if there are special characters.
5618 (mm-with-multibyte-buffer
5620 (goto-char (point-min))
5621 (while (search-forward "\"" nil t)
5624 (zerop (% (skip-chars-backward "\\\\") 2))
5625 (goto-char (match-beginning 0)))
5628 ;; Those quotes will be removed by the RFC2047 encoder.
5629 (concat "\"" (buffer-string) "\""))
5633 (if (or (not date) (string= date ""))
5634 "(unknown date)" date)
5635 "\"" (if msg-id ")")))))))
5637 (defun message-make-distribution ()
5638 "Make a Distribution header."
5639 (let ((orig-distribution (message-fetch-reply-field "distribution")))
5640 (cond ((functionp message-distribution-function)
5641 (funcall message-distribution-function))
5642 (t orig-distribution))))
5644 (defun message-make-expires ()
5645 "Return an Expires header based on `message-expires'."
5646 (let ((current (current-time))
5647 (future (* 1.0 message-expires 60 60 24)))
5648 ;; Add the future to current.
5649 (setcar current (+ (car current) (round (/ future (expt 2 16)))))
5650 (setcar (cdr current) (+ (nth 1 current) (% (round future) (expt 2 16))))
5651 (message-make-date current)))
5653 (defun message-make-path ()
5655 (let ((login-name (user-login-name)))
5656 (cond ((null message-user-path)
5657 (concat (system-name) "!" login-name))
5658 ((stringp message-user-path)
5659 ;; Support GENERICPATH. Suggested by vixie@decwrl.dec.com.
5660 (concat message-user-path "!" login-name))
5663 (defun message-make-from (&optional name address)
5664 "Make a From header."
5665 (let* ((style message-from-style)
5666 (login (or address (message-make-address)))
5667 (fullname (or name user-full-name (user-full-name))))
5668 (when (string= fullname "&")
5669 (setq fullname (user-login-name)))
5671 (mm-enable-multibyte)
5674 (equal fullname ""))
5676 ((or (eq style 'angles)
5677 (and (not (eq style 'parens))
5678 ;; Use angles if no quoting is needed, or if parens would
5679 ;; need quoting too.
5680 (or (not (string-match "[^- !#-'*+/-9=?A-Z^-~]" fullname))
5681 (let ((tmp (concat fullname nil)))
5682 (while (string-match "([^()]*)" tmp)
5683 (aset tmp (match-beginning 0) ?-)
5684 (aset tmp (1- (match-end 0)) ?-))
5685 (string-match "[\\()]" tmp)))))
5687 (goto-char (point-min))
5688 ;; Look for a character that cannot appear unquoted
5689 ;; according to RFC 822.
5690 (when (re-search-forward "[^- !#-'*+/-9=?A-Z^-~]" nil 1)
5691 ;; Quote fullname, escaping specials.
5692 (goto-char (point-min))
5694 (while (re-search-forward "[\"\\]" nil 1)
5695 (replace-match "\\\\\\&" t))
5697 (insert " <" login ">"))
5698 (t ; 'parens or default
5700 (let ((fullname-start (point)))
5702 (goto-char fullname-start)
5703 ;; RFC 822 says \ and nonmatching parentheses
5704 ;; must be escaped in comments.
5705 ;; Escape every instance of ()\ ...
5706 (while (re-search-forward "[()\\]" nil 1)
5707 (replace-match "\\\\\\&" t))
5708 ;; ... then undo escaping of matching parentheses,
5709 ;; including matching nested parentheses.
5710 (goto-char fullname-start)
5711 (while (re-search-forward
5712 "\\(\\=\\|[^\\]\\(\\\\\\\\\\)*\\)\\\\(\\(\\([^\\]\\|\\\\\\\\\\)*\\)\\\\)"
5714 (replace-match "\\1(\\3)" t)
5715 (goto-char fullname-start)))
5719 (defun message-make-sender ()
5720 "Return the \"real\" user address.
5721 This function tries to ignore all user modifications, and
5722 give as trustworthy answer as possible."
5723 (concat (user-login-name) "@" (system-name)))
5725 (defun message-make-address ()
5726 "Make the address of the user."
5727 (or (message-user-mail-address)
5728 (concat (user-login-name) "@" (message-make-domain))))
5730 (defun message-user-mail-address ()
5731 "Return the pertinent part of `user-mail-address'."
5732 (when (and user-mail-address
5733 (string-match "@.*\\." user-mail-address))
5734 (if (string-match " " user-mail-address)
5735 (nth 1 (mail-extract-address-components user-mail-address))
5736 user-mail-address)))
5738 (defun message-sendmail-envelope-from ()
5739 "Return the envelope from."
5740 (cond ((eq message-sendmail-envelope-from 'header)
5741 (nth 1 (mail-extract-address-components
5742 (message-fetch-field "from"))))
5743 ((stringp message-sendmail-envelope-from)
5744 message-sendmail-envelope-from)
5746 (message-make-address))))
5748 (defun message-make-fqdn ()
5749 "Return user's fully qualified domain name."
5750 (let* ((sysname (system-name))
5751 (user-mail (message-user-mail-address))
5754 (string-match "@\\(.*\\)\\'" user-mail))
5755 (match-string 1 user-mail)))
5756 (case-fold-search t))
5758 ((and message-user-fqdn
5759 (stringp message-user-fqdn)
5760 (not (string-match message-bogus-system-names message-user-fqdn)))
5761 ;; `message-user-fqdn' seems to be valid
5763 ((and (string-match message-bogus-system-names sysname))
5764 ;; `system-name' returned the right result.
5766 ;; Try `mail-host-address'.
5767 ((and (stringp mail-host-address)
5768 (not (string-match message-bogus-system-names mail-host-address)))
5770 ;; We try `user-mail-address' as a backup.
5772 (stringp user-domain)
5773 (not (string-match message-bogus-system-names user-domain)))
5775 ;; Default to this bogus thing.
5778 ".i-did-not-set--mail-host-address--so-tickle-me")))))
5780 (defun message-make-domain ()
5781 "Return the domain name."
5782 (or mail-host-address
5783 (message-make-fqdn)))
5785 (defun message-to-list-only ()
5786 "Send a message to the list only.
5787 Remove all addresses but the list address from To and Cc headers."
5789 (let ((listaddr (message-make-mail-followup-to t)))
5792 (message-remove-header "to")
5793 (message-remove-header "cc")
5794 (message-position-on-field "To" "X-Draft-From")
5795 (insert listaddr)))))
5797 (defun message-make-mail-followup-to (&optional only-show-subscribed)
5798 "Return the Mail-Followup-To header.
5799 If passed the optional argument ONLY-SHOW-SUBSCRIBED only return the
5800 subscribed address (and not the additional To and Cc header contents)."
5801 (let* ((case-fold-search t)
5802 (to (message-fetch-field "To"))
5803 (cc (message-fetch-field "cc"))
5804 (msg-recipients (concat to (and to cc ", ") cc))
5806 (mapcar 'mail-strip-quoted-names
5807 (message-tokenize-header msg-recipients)))
5809 (if message-subscribed-address-file
5810 (let (begin end item re)
5813 (insert-file-contents message-subscribed-address-file)
5815 (setq begin (point))
5818 (if (bolp) (setq end (1- end)))
5819 (setq item (regexp-quote (buffer-substring begin end)))
5820 (if re (setq re (concat re "\\|" item))
5821 (setq re (concat "\\`\\(" item))))
5822 (and re (list (concat re "\\)\\'"))))))))
5823 (mft-regexps (apply 'append message-subscribed-regexps
5824 (mapcar 'regexp-quote
5825 message-subscribed-addresses)
5828 message-subscribed-address-functions))))
5831 (loop for recipient in recipients
5832 when (loop for regexp in mft-regexps
5833 when (string-match regexp recipient) return t)
5836 (if only-show-subscribed
5838 msg-recipients))))))
5840 (defun message-idna-to-ascii-rhs-1 (header)
5841 "Interactively potentially IDNA encode domain names in HEADER."
5842 (let ((field (message-fetch-field header))
5847 (mapcar (lambda (rhs) (or (cadr (split-string rhs "@")) ""))
5853 (mail-extract-address-components field t))))))
5854 ;; Note that `rhs' will be "" if the address does not have
5855 ;; the domain part, i.e., if it is a local user's address.
5856 (setq ace (if (string-match "\\`[[:ascii:]]*\\'" rhs)
5858 (downcase (puny-encode-domain rhs))))
5859 (when (and (not (equal rhs ace))
5860 (or (not (eq message-use-idna 'ask))
5861 (y-or-n-p (format "Replace %s with %s in %s:? "
5863 (goto-char (point-min))
5864 (while (re-search-forward (concat "^" header ":") nil t)
5865 (message-narrow-to-field)
5866 (while (search-forward (concat "@" rhs) nil t)
5867 (replace-match (concat "@" ace) t t))
5868 (goto-char (point-max))
5871 (defun message-idna-to-ascii-rhs ()
5872 "Possibly IDNA encode non-ASCII domain names in From:, To: and Cc: headers.
5873 See `message-idna-encode'."
5875 (when message-use-idna
5878 ;; `message-narrow-to-head' that recognizes only the first empty
5879 ;; line as the message header separator used to be used here.
5880 ;; However, since there is the "--text follows this line--" line
5881 ;; normally, it failed in narrowing to the headers and potentially
5882 ;; caused the IDNA encoding on lines that look like headers in
5883 ;; the message body.
5884 (message-narrow-to-headers-or-head)
5885 (message-idna-to-ascii-rhs-1 "From")
5886 (message-idna-to-ascii-rhs-1 "To")
5887 (message-idna-to-ascii-rhs-1 "Reply-To")
5888 (message-idna-to-ascii-rhs-1 "Mail-Reply-To")
5889 (message-idna-to-ascii-rhs-1 "Mail-Followup-To")
5890 (message-idna-to-ascii-rhs-1 "Cc")))))
5892 (defun message-generate-headers (headers)
5893 "Prepare article HEADERS.
5894 Headers already prepared in the buffer are not modified."
5895 (setq headers (append headers message-required-headers))
5897 (message-narrow-to-headers)
5898 (let* ((header-values
5899 (list 'Date (message-make-date)
5900 'Message-ID (message-make-message-id)
5901 'Organization (message-make-organization)
5902 'From (message-make-from)
5903 'Path (message-make-path)
5906 'In-Reply-To (message-make-in-reply-to)
5907 'References (message-make-references)
5909 'Distribution (message-make-distribution)
5910 'Lines (message-make-lines)
5911 'User-Agent message-newsreader
5912 'Expires (message-make-expires)))
5913 (case-fold-search t)
5915 header value elem header-string)
5916 ;; First we remove any old generated headers.
5917 (let ((headers message-deletable-headers))
5918 (unless (buffer-modified-p)
5919 (setq headers (delq 'Message-ID (copy-sequence headers))))
5921 (goto-char (point-min))
5922 (and (re-search-forward
5923 (concat "^" (symbol-name (car headers)) ": *") nil t)
5924 (get-text-property (1+ (match-beginning 0)) 'message-deletable)
5925 (message-delete-line))
5927 ;; Go through all the required headers and see if they are in the
5928 ;; articles already. If they are not, or are empty, they are
5929 ;; inserted automatically - except for Subject, Newsgroups and
5932 (goto-char (point-min))
5933 (setq elem (pop headers))
5935 (if (eq (car elem) 'optional)
5936 (setq header (cdr elem)
5938 (setq header (car elem)))
5940 (setq header-string (if (stringp header)
5942 (symbol-name header)))
5943 (when (or (not (re-search-forward
5945 (regexp-quote (downcase header-string))
5949 ;; The header was found. We insert a space after the
5950 ;; colon, if there is none.
5951 (if (/= (char-after) ? ) (insert " ") (forward-char 1))
5952 ;; Find out whether the header is empty.
5953 (looking-at "[ \t]*\n[^ \t]")))
5954 ;; So we find out what value we should insert.
5958 (eq (car elem) 'optional)
5959 (not (member header-string message-inserted-headers)))
5960 ;; This is an optional header. If the cdr of this
5961 ;; is something that is nil, then we do not insert
5963 (setq header (cdr elem))
5964 (or (and (functionp (cdr elem))
5965 (funcall (cdr elem)))
5966 (and (symbolp (cdr elem))
5967 (plist-get header-values (cdr elem)))))
5969 ;; The element is a cons. Either the cdr is a
5970 ;; string to be inserted verbatim, or it is a
5971 ;; function, and we insert the value returned from
5973 (or (and (stringp (cdr elem))
5975 (and (functionp (cdr elem))
5976 (funcall (cdr elem)))))
5977 ((and (symbolp header)
5978 (plist-member header-values header))
5979 ;; The element is a symbol. We insert the value of
5980 ;; this symbol, if any.
5981 (plist-get header-values header))
5982 ((not (message-check-element
5983 (intern (downcase (symbol-name header)))))
5984 ;; We couldn't generate a value for this header,
5985 ;; so we just ask the user.
5986 (read-from-minibuffer
5987 (format "Empty header for %s; enter value: " header)))))
5988 ;; Finally insert the header.
5990 (not (equal value "")))
5994 ;; This header didn't exist, so we insert it.
5995 (goto-char (point-max))
5997 (cdr (assq header message-header-format-alist))))
5999 (funcall formatter header value)
6000 (insert header-string ": " value))
6001 (push header-string message-inserted-headers)
6002 (goto-char (message-fill-field))
6003 ;; We check whether the value was ended by a
6004 ;; newline. If not, we insert one.
6008 ;; The value of this header was empty, so we clear
6009 ;; totally and insert the new value.
6010 (delete-region (point) (point-at-eol))
6011 ;; If the header is optional, and the header was
6012 ;; empty, we can't insert it anyway.
6014 (push header-string message-inserted-headers)
6016 (message-fill-field)))
6017 ;; Add the deletable property to the headers that require it.
6018 (and (memq header message-deletable-headers)
6019 (progn (beginning-of-line) (looking-at "[^:]+: "))
6020 (add-text-properties
6021 (point) (match-end 0)
6022 '(message-deletable t face italic) (current-buffer)))))))
6023 ;; Insert new Sender if the From is strange.
6024 (let ((from (message-fetch-field "from"))
6025 (sender (message-fetch-field "sender"))
6026 (secure-sender (message-make-sender)))
6028 (not (message-check-element 'sender))
6031 (cadr (mail-extract-address-components from)))
6032 (downcase secure-sender)))
6037 (cadr (mail-extract-address-components sender)))
6038 (downcase secure-sender)))))
6039 (goto-char (point-min))
6040 ;; Rename any old Sender headers to Original-Sender.
6041 (when (re-search-forward "^\\(Original-\\)*Sender:" nil t)
6043 (insert "Original-")
6044 (beginning-of-line))
6045 (when (or (message-news-p)
6046 (string-match "@.+\\.." secure-sender))
6047 (insert "Sender: " secure-sender "\n"))))
6049 (message-idna-to-ascii-rhs))))
6051 (defun message-insert-courtesy-copy (message)
6052 "Insert a courtesy message in mail copies of combined messages."
6056 (message-narrow-to-headers)
6057 (when (setq newsgroups (message-fetch-field "newsgroups"))
6058 (goto-char (point-max))
6059 (insert "Posted-To: " newsgroups "\n")))
6063 ((string-match "%s" message)
6064 (insert (format message newsgroups)))
6066 (insert message)))))))
6069 ;;; Setting up a message buffer
6072 (defun message-skip-to-next-address ()
6073 (let ((end (save-excursion
6074 (message-next-header)
6077 (when (looking-at ",")
6079 (while (and (not (= (point) end))
6080 (or (not (eq char ?,))
6082 (skip-chars-forward "^,\"" end)
6083 (when (eq (setq char (following-char)) ?\")
6084 (setq quoted (not quoted)))
6085 (unless (= (point) end)
6087 (skip-chars-forward " \t\n")))
6089 (defun message-split-line ()
6090 "Split current line, moving portion beyond point vertically down.
6091 If the current line has `message-yank-prefix', insert it on the new line."
6093 (split-line message-yank-prefix))
6095 (defun message-insert-header (header value)
6096 (insert (capitalize (symbol-name header))
6098 (if (consp value) (car value) value)))
6100 (defun message-field-name ()
6102 (goto-char (point-min))
6103 (when (looking-at "\\([^:]+\\):")
6104 (intern (capitalize (match-string 1))))))
6106 (defun message-fill-field ()
6109 (message-narrow-to-field)
6110 (let ((field-name (message-field-name)))
6111 (funcall (or (cadr (assq field-name message-field-fillers))
6112 'message-fill-field-general)))
6115 (defun message-fill-field-address ()
6118 (message-skip-to-next-address)
6124 (when (and (> (current-column) 78)
6128 (delete-char (- (skip-chars-backward " \t")))
6130 (setq last (point)))
6131 (forward-line end)))
6133 (defun message-fill-field-general ()
6134 (let ((begin (point))
6137 (while (and (search-forward "\n" nil t)
6139 (replace-match " " t t))
6140 (fill-region-as-paragraph begin (point-max))
6141 ;; Tapdance around looong Message-IDs.
6143 (when (looking-at "[ \t]*$")
6144 (message-delete-line))
6146 (search-forward ":" nil t)
6147 (when (looking-at "\n[ \t]+")
6148 (replace-match " " t t))
6149 (goto-char (point-max))))
6151 (defun message-shorten-1 (list cut surplus)
6152 "Cut SURPLUS elements out of LIST, beginning with CUTth one."
6153 (setcdr (nthcdr (- cut 2) list)
6154 (nthcdr (+ (- cut 2) surplus 1) list)))
6156 (defun message-shorten-references (header references)
6157 "Trim REFERENCES to be 21 Message-ID long or less, and fold them.
6158 When sending via news, also check that the REFERENCES are less
6159 than 988 characters long, and if they are not, trim them until
6161 ;; 21 is the number suggested by USAGE.
6168 (goto-char (point-min))
6169 ;; Cons a list of valid references. GNKSA says we must not include MIDs
6170 ;; with whitespace or missing brackets (7.a "Does not propagate broken
6171 ;; Message-IDs in original References").
6172 (while (re-search-forward "<[^ <]+@[^ <]+>" nil t)
6173 (push (match-string 0) refs))
6174 (setq refs (nreverse refs)
6175 count (length refs)))
6177 ;; If the list has more than MAXCOUNT elements, trim it by
6178 ;; removing the CUTth element and the required number of
6179 ;; elements that follow.
6180 (when (> count maxcount)
6181 (let ((surplus (- count maxcount)))
6182 (message-shorten-1 refs cut surplus)
6183 (decf count surplus)))
6185 ;; When sending via news, make sure the total folded length will
6186 ;; be less than 998 characters. This is to cater to broken INN
6187 ;; 2.3 which counts the total number of characters in a header
6188 ;; rather than the physical line length of each line, as it should.
6190 ;; This hack should be removed when it's believed than INN 2.3 is
6191 ;; no longer widely used.
6193 ;; At this point the headers have not been generated, thus we use
6194 ;; message-this-is-news directly.
6195 (when message-this-is-news
6198 (message-insert-header
6199 header (mapconcat #'identity refs " "))
6201 (message-shorten-1 refs cut 1)))
6202 ;; Finally, collect the references back into a string and insert
6203 ;; it into the buffer.
6204 (message-insert-header header (mapconcat #'identity refs " "))))
6206 (defun message-position-point ()
6207 "Move point to where the user probably wants to find it."
6208 (message-narrow-to-headers)
6210 ((re-search-forward "^[^:]+:[ \t]*$" nil t)
6211 (search-backward ":" )
6214 (if (eq (char-after) ? )
6218 (goto-char (point-max))
6221 (unless (looking-at "$")
6225 (defcustom message-beginning-of-line t
6226 "Whether \\<message-mode-map>\\[message-beginning-of-line]\
6227 goes to beginning of header values."
6229 :group 'message-buffers
6230 :link '(custom-manual "(message)Movement")
6233 (defvar visual-line-mode)
6234 (declare-function beginning-of-visual-line "simple" (&optional n))
6236 (defun message-beginning-of-header (handle-folded)
6237 "Move point to beginning of header’s value.
6239 When point is at the first header line, moves it after the colon
6240 and spaces separating header name and header value.
6242 When point is in a continuation line of a folded header (i.e. the
6243 line starts with a space), the behaviour depends on HANDLE-FOLDED
6244 argument. If it’s nil, function moves the point to the start of
6245 the header continuation; otherwise, function locates the
6246 beginning of the header and moves point past the colon as is the
6247 case of single-line headers.
6249 No check whether point is inside of a header or body of the
6250 message is performed.
6252 Returns point or nil if beginning of header’s value could not be
6253 found. In the latter case, the point is still moved to the
6254 beginning of line (possibly after attempting to move it to the
6255 beginning of a folded header)."
6256 ;; https://www.rfc-editor.org/rfc/rfc2822.txt, section 2.2.3. says that when
6257 ;; unfolding a single WSP should be consumed. WSP is defined as a space
6258 ;; character or a horizontal tab.
6261 (while (and (> (point) (point-min))
6262 (or (eq (char-after) ?\s) (eq (char-after) ?\t)))
6263 (beginning-of-line 0)))
6264 (when (or (eq (char-after) ?\s) (eq (char-after) ?\t)
6265 (search-forward ":" (point-at-eol) t))
6266 ;; We are a bit more lacks than the RFC and allow any positive number of WSP
6268 (skip-chars-forward " \t" (point-at-eol))
6271 (defun message-beginning-of-line (&optional n)
6272 "Move point to beginning of header value or to beginning of line.
6273 The prefix argument N is passed directly to `beginning-of-line'.
6275 This command is identical to `beginning-of-line' if point is
6276 outside the message header or if the option
6277 `message-beginning-of-line' is nil.
6279 If point is in the message header and on a header line, move
6280 point to the beginning of the header value or the beginning of
6281 line, whichever is closer. If point is already at beginning of
6282 line, move point to beginning of header value. Therefore,
6283 repeated calls will toggle point between beginning of field and
6286 When called without a prefix argument, header value spanning
6287 multiple lines is treated as a single line. Otherwise, even if
6288 N is 1, when point is on a continuation header line, it will be
6289 moved to the beginning "
6292 ;; Go to beginning of header or beginning of line.
6293 ((and message-beginning-of-line (message-point-in-header-p))
6294 (let* ((point (point))
6295 (bol (progn (beginning-of-line n) (point)))
6296 (boh (message-beginning-of-header visual-line-mode)))
6297 (goto-char (if (and boh (or (< boh point) (= bol point))) boh bol))))
6298 ;; Go to beginning of visual line
6300 (beginning-of-visual-line n))
6301 ;; Go to beginning of line.
6302 ((beginning-of-line n))))
6304 (defun message-buffer-name (type &optional to group)
6305 "Return a new (unique) buffer name based on TYPE and TO."
6307 ;; Generate a new buffer name The Message Way.
6308 ((memq message-generate-new-buffers '(unique t))
6309 (generate-new-buffer-name
6313 (or (car (mail-extract-address-components to))
6316 (if (and group (not (string= group ""))) (concat " on " group) "")
6318 ;; Check whether `message-generate-new-buffers' is a function,
6319 ;; and if so, call it.
6320 ((functionp message-generate-new-buffers)
6321 (funcall message-generate-new-buffers type to group))
6322 ((eq message-generate-new-buffers 'unsent)
6323 (generate-new-buffer-name
6324 (concat "*unsent " type
6327 (or (car (mail-extract-address-components to))
6330 (if (and group (not (string= group ""))) (concat " on " group) "")
6332 ;; Search for the existing message buffer with the specified name.
6334 (let* ((new (if (eq message-generate-new-buffers 'standard)
6335 (generate-new-buffer-name (concat "*" type " message*"))
6336 (let ((message-generate-new-buffers 'unique))
6337 (message-buffer-name type to group))))
6338 (regexp (concat "\\`"
6340 (if (string-match "<[0-9]+>\\'" new)
6341 (substring new 0 (match-beginning 0))
6343 "\\(?:<\\([0-9]+\\)>\\)?\\'"))
6344 (case-fold-search nil))
6351 (when (and (string-match regexp (setq b (buffer-name b)))
6352 (eq (with-current-buffer b major-mode)
6354 (cons (string-to-number (or (match-string 1 b) "1"))
6357 'car-less-than-car)))
6360 (defun message-pop-to-buffer (name &optional switch-function)
6361 "Pop to buffer NAME, and warn if it already exists and is modified."
6362 (let ((buffer (get-buffer name)))
6364 (buffer-name buffer))
6365 (let ((window (get-buffer-window buffer 0)))
6367 ;; Raise the frame already displaying the message buffer.
6369 (select-frame-set-input-focus (window-frame window))
6370 (select-window window))
6371 (funcall (or switch-function #'pop-to-buffer) buffer)
6372 (set-buffer buffer))
6373 (when (and (buffer-modified-p)
6376 "Message already being composed; erase? ")
6378 (error "Message being composed")))
6379 (funcall (or switch-function 'pop-to-buffer-same-window)
6385 (defun message-do-send-housekeeping ()
6386 "Kill old message buffers."
6387 ;; We might have sent this buffer already. Delete it from the
6389 (setq message-buffer-list (delq (current-buffer) message-buffer-list))
6390 (while (and message-max-buffers
6392 (>= (length message-buffer-list) message-max-buffers))
6393 ;; Kill the oldest buffer -- unless it has been changed.
6394 (let ((buffer (pop message-buffer-list)))
6395 (when (and (buffer-name buffer)
6396 (not (buffer-modified-p buffer)))
6397 (kill-buffer buffer))))
6398 ;; Rename the buffer.
6399 (if message-send-rename-function
6400 (funcall message-send-rename-function)
6401 (message-default-send-rename-function))
6402 ;; Push the current buffer onto the list.
6403 (when message-max-buffers
6404 (setq message-buffer-list
6405 (nconc message-buffer-list (list (current-buffer))))))
6407 (defun message-default-send-rename-function ()
6408 ;; Note: mail-abbrevs of XEmacs renames buffer name behind Gnus.
6410 "\\`\\*\\(sent \\|unsent \\)?\\(.+\\)\\*[^\\*]*\\|\\`mail to "
6412 (let ((name (match-string 2 (buffer-name)))
6414 (if (not (or (null name)
6415 (string-equal name "mail")
6416 (string-equal name "posting")))
6417 (setq name (concat "*sent " name "*"))
6418 (message-narrow-to-headers)
6419 (setq to (message-fetch-field "to"))
6420 (setq group (message-fetch-field "newsgroups"))
6424 (to (concat "*sent mail to "
6425 (or (car (mail-extract-address-components to))
6427 ((and group (not (string= group "")))
6428 (concat "*sent posting on " group "*"))
6429 (t "*sent mail*"))))
6430 (unless (string-equal name (buffer-name))
6431 (rename-buffer name t)))))
6433 (defun message-mail-user-agent ()
6435 ((not message-mail-user-agent) nil)
6436 ((eq message-mail-user-agent t) mail-user-agent)
6437 (t message-mail-user-agent))))
6438 (if (memq mua '(message-user-agent gnus-user-agent))
6442 ;; YANK-ACTION, if non-nil, can be a buffer or a yank action of the
6443 ;; form (FUNCTION . ARGS).
6444 (defun message-setup (headers &optional yank-action actions
6445 continue switch-function return-action)
6446 (let ((mua (message-mail-user-agent))
6448 (if (not (and message-this-is-mail mua))
6449 (message-setup-1 headers yank-action actions return-action)
6450 (setq headers (copy-sequence headers))
6451 (setq field (assq 'Subject headers))
6453 (setq subject (cdr field))
6454 (setq headers (delq field headers)))
6455 (setq field (assq 'To headers))
6457 (setq to (cdr field))
6458 (setq headers (delq field headers)))
6459 (let ((mail-user-agent mua))
6460 (compose-mail to subject
6461 (mapcar (lambda (item)
6463 (format "%s" (car item))
6466 continue switch-function
6467 (if (bufferp yank-action)
6468 (list 'insert-buffer yank-action)
6472 (defun message-headers-to-generate (headers included-headers excluded-headers)
6473 "Return a list that includes all headers from HEADERS.
6474 If INCLUDED-HEADERS is a list, just include those headers. If it is
6475 t, include all headers. In any case, headers from EXCLUDED-HEADERS
6479 (dolist (header headers)
6480 (setq header-name (cond
6481 ((and (consp header)
6482 (eq (car header) 'optional))
6483 ;; On the form (optional . Header)
6486 ;; On the form (Header . function)
6491 (when (and (not (memq header-name excluded-headers))
6492 (or (eq included-headers t)
6493 (memq header-name included-headers)))
6494 (push header result)))
6497 (defun message-setup-1 (headers &optional yank-action actions return-action)
6498 (dolist (action actions)
6500 (add-to-list 'message-send-actions
6501 `(apply ',(car action) ',(cdr action)))))
6502 (setq message-return-action return-action)
6503 (setq message-reply-buffer
6504 (if (and (consp yank-action)
6505 (eq (car yank-action) 'insert-buffer))
6508 (goto-char (point-min))
6509 ;; Insert all the headers.
6512 (alist message-header-format-alist))
6514 (unless (assq (caar h) message-header-format-alist)
6515 (push (list (caar h)) alist))
6519 (delete-region (point) (progn (forward-line -1) (point)))
6520 (when message-default-headers
6522 (if (functionp message-default-headers)
6523 (funcall message-default-headers)
6524 message-default-headers))
6525 (or (bolp) (insert ?\n)))
6526 (insert (concat mail-header-separator "\n"))
6528 ;; If a crash happens while replying, the auto-save file would *not* have a
6529 ;; `References:' header if `message-generate-headers-first' was nil.
6530 ;; Therefore, always generate it first.
6531 (let ((message-generate-headers-first
6532 (if (eq message-generate-headers-first t)
6534 (append message-generate-headers-first '(References)))))
6535 (when (message-news-p)
6536 (when message-default-news-headers
6537 (insert message-default-news-headers)
6538 (or (bolp) (insert ?\n)))
6539 (message-generate-headers
6540 (message-headers-to-generate
6541 (append message-required-news-headers
6542 message-required-headers)
6543 message-generate-headers-first
6545 (when (message-mail-p)
6546 (when message-default-mail-headers
6547 (insert message-default-mail-headers)
6548 (or (bolp) (insert ?\n)))
6549 (message-generate-headers
6550 (message-headers-to-generate
6551 (append message-required-mail-headers
6552 message-required-headers)
6553 message-generate-headers-first
6554 '(Lines Subject)))))
6555 (run-hooks 'message-signature-setup-hook)
6556 (message-insert-signature)
6558 (message-narrow-to-headers)
6559 (run-hooks 'message-header-setup-hook))
6560 (setq buffer-undo-list nil)
6561 (when message-generate-hashcash
6562 ;; Generate hashcash headers for recipients already known
6563 (mail-add-payment-async))
6564 ;; Gnus posting styles are applied via buffer-local `message-setup-hook'
6566 (run-hooks 'message-setup-hook)
6567 ;; Do this last to give it precedence over posting styles, etc.
6568 (when (message-mail-p)
6570 (message-narrow-to-headers)
6571 (if message-alternative-emails
6572 (message-use-alternative-email-as-from))))
6573 (message-position-point)
6574 ;; Allow correct handling of `message-checksum' in `message-yank-original':
6575 (set-buffer-modified-p nil)
6577 ;; rmail-start-mail expects message-mail to return t (Bug#9392)
6580 (defun message-set-auto-save-file-name ()
6581 "Associate the message buffer with a file in the drafts directory."
6582 (when message-auto-save-directory
6583 (unless (file-directory-p
6584 (directory-file-name message-auto-save-directory))
6585 (make-directory message-auto-save-directory t))
6587 (setq message-draft-article
6588 (nndraft-request-associate-buffer "drafts"))
6590 ;; If Gnus were alive, draft messages would be saved in the drafts folder.
6591 ;; But Gnus is not alive, so arrange to save the draft message in a
6592 ;; regular file in message-auto-save-directory. Append a unique
6593 ;; time-based suffix to the filename to allow multiple drafts to be saved
6594 ;; simultaneously without overwriting each other (which mimics the
6595 ;; functionality of the Gnus drafts folder).
6596 (setq buffer-file-name (expand-file-name
6598 (if (memq system-type
6599 '(ms-dos windows-nt cygwin))
6602 (format-time-string "-%Y%m%d-%H%M%S"))
6603 message-auto-save-directory))
6604 (setq buffer-auto-save-file-name (make-auto-save-file-name)))
6605 (clear-visited-file-modtime)
6606 (setq buffer-file-coding-system message-draft-coding-system)))
6608 (defun message-disassociate-draft ()
6609 "Disassociate the message buffer from the drafts directory."
6610 (when message-draft-article
6611 (nndraft-request-expire-articles
6612 (list message-draft-article) "drafts" nil t)))
6614 (defun message-insert-headers ()
6615 "Generate the headers for the article."
6619 (message-narrow-to-headers)
6620 (when (message-news-p)
6621 (message-generate-headers
6624 (copy-sequence message-required-news-headers)))))
6625 (when (message-mail-p)
6626 (message-generate-headers
6629 (copy-sequence message-required-mail-headers))))))))
6634 ;;; Commands for interfacing with message
6638 (defun message-mail (&optional to subject other-headers continue
6639 switch-function yank-action send-actions
6640 return-action &rest ignored)
6641 "Start editing a mail message to be sent.
6642 OTHER-HEADERS is an alist of header/value pairs. CONTINUE says whether
6643 to continue editing a message already being composed. SWITCH-FUNCTION
6644 is a function used to switch to and display the mail buffer."
6646 (let ((message-this-is-mail t))
6647 (unless (message-mail-user-agent)
6648 (message-pop-to-buffer
6649 ;; Search for the existing message buffer if `continue' is non-nil.
6650 (let ((message-generate-new-buffers
6651 (when (or (not continue)
6652 (eq message-generate-new-buffers 'standard)
6653 (functionp message-generate-new-buffers))
6654 message-generate-new-buffers)))
6655 (message-buffer-name "mail" to))
6659 `((To . ,(or to "")) (Subject . ,(or subject "")))
6660 ;; C-h f compose-mail says that headers should be specified as
6661 ;; (string . value); however all the rest of message expects
6662 ;; headers to be symbols, not strings (eg message-header-format-alist).
6663 ;; http://lists.gnu.org/archive/html/emacs-devel/2011-01/msg00337.html
6664 ;; We need to convert any string input, eg from rmail-start-mail.
6665 (dolist (h other-headers other-headers)
6666 (if (stringp (car h)) (setcar h (intern (capitalize (car h)))))))
6667 yank-action send-actions continue switch-function
6671 (defun message-news (&optional newsgroups subject)
6672 "Start editing a news article to be sent."
6674 (let ((message-this-is-news t))
6675 (message-pop-to-buffer (message-buffer-name "posting" nil newsgroups))
6676 (message-setup `((Newsgroups . ,(or newsgroups ""))
6677 (Subject . ,(or subject ""))))))
6679 (defun message-alter-recipients-discard-bogus-full-name (addrcell)
6680 "Discard mail address in full names.
6681 When the full name in reply headers contains the mail
6682 address (e.g. \"foo@bar <foo@bar>\"), discard full name.
6683 ADDRCELL is a cons cell where the car is the mail address and the
6684 cdr is the complete address (full name and mail address)."
6685 (if (string-match (concat (regexp-quote (car addrcell)) ".*"
6686 (regexp-quote (car addrcell)))
6688 (cons (car addrcell) (car addrcell))
6691 (defcustom message-alter-recipients-function nil
6692 "Function called to allow alteration of reply header structures.
6693 It is called in `message-get-reply-headers' for each recipient.
6694 The function is called with one parameter, a cons cell ..."
6695 :type '(choice (const :tag "None" nil)
6696 (const :tag "Discard bogus full name"
6697 message-alter-recipients-discard-bogus-full-name)
6699 :version "23.1" ;; No Gnus
6700 :group 'message-headers)
6702 (defun message-get-reply-headers (wide &optional to-address address-headers)
6703 (let (follow-to mct never-mct to cc author mft recipients extra)
6704 ;; Find all relevant headers we need.
6706 (message-narrow-to-headers-or-head)
6707 ;; Gmane renames "To". Look at "Original-To", too, if it is present in
6708 ;; message-header-synonyms.
6709 (setq to (or (message-fetch-field "to")
6710 (and (loop for synonym in message-header-synonyms
6711 when (memq 'Original-To synonym)
6713 (message-fetch-field "original-to")))
6714 cc (message-fetch-field "cc")
6715 extra (when message-extra-wide-headers
6716 (mapconcat 'identity
6717 (mapcar 'message-fetch-field
6718 message-extra-wide-headers)
6720 mct (message-fetch-field "mail-copies-to")
6721 author (or (message-fetch-field "mail-reply-to")
6722 (message-fetch-field "reply-to"))
6723 mft (and message-use-mail-followup-to
6724 (message-fetch-field "mail-followup-to")))
6725 ;; Make sure this message goes to the author if this is a wide
6726 ;; reply, since Reply-To address may be a list address a mailing
6727 ;; list server added.
6728 (when (and wide author)
6729 (setq cc (concat author ", " cc)))
6730 (when (or wide (not author))
6731 (setq author (or (message-fetch-field "from") ""))))
6733 ;; Handle special values of Mail-Copies-To.
6735 (cond ((or (equal (downcase mct) "never")
6736 (equal (downcase mct) "nobody"))
6739 ((or (equal (downcase mct) "always")
6740 (equal (downcase mct) "poster"))
6741 (setq mct author))))
6744 ;; Build (textual) list of new recipient addresses.
6747 (setq recipients (concat ", " to-address))
6748 ;; If the author explicitly asked for a copy, we don't deny it to them.
6749 (if mct (setq recipients (concat recipients ", " mct))))
6751 (setq recipients (concat ", " author)))
6753 (dolist (header address-headers)
6754 (let ((value (message-fetch-field header)))
6756 (setq recipients (concat recipients ", " value))))))
6758 (string-match "[^ \t,]" mft)
6759 (or (not (eq message-use-mail-followup-to 'ask))
6760 (message-y-or-n-p "Obey Mail-Followup-To? " t "\
6761 You should normally obey the Mail-Followup-To: header. In this
6762 article, it has the value of
6766 which directs your response to " (if (string-match "," mft)
6767 "the specified addresses"
6768 "that address only") ".
6770 Most commonly, Mail-Followup-To is used by a mailing list poster to
6771 express that responses should be sent to just the list, and not the
6774 If a message is posted to several mailing lists, Mail-Followup-To may
6775 also be used to direct the following discussion to one list only,
6776 because discussions that are spread over several lists tend to be
6777 fragmented and very difficult to follow.
6779 Also, some source/announcement lists are not intended for discussion;
6780 responses here are directed to other addresses.
6782 You may customize the variable `message-use-mail-followup-to', if you
6783 want to get rid of this query permanently.")))
6784 (setq recipients (concat ", " mft)))
6786 (setq recipients (if never-mct "" (concat ", " author)))
6787 (if to (setq recipients (concat recipients ", " to)))
6788 (if cc (setq recipients (concat recipients ", " cc)))
6789 (if extra (setq recipients (concat recipients ", " extra)))
6790 (if mct (setq recipients (concat recipients ", " mct)))))
6791 (if (>= (length recipients) 2)
6792 ;; Strip the leading ", ".
6793 (setq recipients (substring recipients 2)))
6794 ;; Squeeze whitespace.
6795 (while (string-match "[ \t][ \t]+" recipients)
6796 (setq recipients (replace-match " " t t recipients)))
6797 ;; Remove addresses that match `message-dont-reply-to-names'.
6799 (cond ((functionp message-dont-reply-to-names)
6803 (mapcar (lambda (mail)
6804 (unless (funcall message-dont-reply-to-names
6805 (mail-strip-quoted-names mail))
6807 (message-tokenize-header recipients)))
6809 (t (let ((mail-dont-reply-to-names (message-dont-reply-to-names)))
6810 (mail-dont-reply-to recipients)))))
6811 ;; Perhaps "Mail-Copies-To: never" removed the only address?
6812 (if (string-equal recipients "")
6813 (setq recipients author))
6814 ;; Convert string to a list of (("foo@bar" . "Name <Foo@BAR>") ...).
6818 (if message-alter-recipients-function
6819 (funcall message-alter-recipients-function
6820 (cons (downcase (mail-strip-quoted-names addr))
6822 (cons (downcase (mail-strip-quoted-names addr)) addr)))
6823 (message-tokenize-header recipients)))
6824 ;; Remove all duplicates.
6825 (let ((s recipients))
6827 (let ((address (car (pop s))))
6828 (while (assoc address s)
6829 (setq recipients (delq (assoc address s) recipients)
6830 s (delq (assoc address s) s))))))
6832 ;; Remove hierarchical lists that are contained within each other,
6833 ;; if message-hierarchical-addresses is defined.
6834 (when message-hierarchical-addresses
6835 (let ((plain-addrs (mapcar 'car recipients))
6838 (setq subaddrs (assoc (car plain-addrs)
6839 message-hierarchical-addresses)
6840 plain-addrs (cdr plain-addrs))
6842 (setq subaddrs (cdr subaddrs))
6844 (setq recip (assoc (car subaddrs) recipients)
6845 subaddrs (cdr subaddrs))
6847 (setq recipients (delq recip recipients))))))))
6849 (setq recipients (message-prune-recipients recipients))
6851 ;; Build the header alist. Allow the user to be asked whether
6852 ;; or not to reply to all recipients in a wide reply.
6853 (setq follow-to (list (cons 'To (cdr (pop recipients)))))
6854 (when (and recipients
6855 (or (not message-wide-reply-confirm-recipients)
6856 (y-or-n-p "Reply to all recipients? ")))
6857 (setq recipients (mapconcat
6858 (lambda (addr) (cdr addr)) recipients ", "))
6859 (if (string-match "^ +" recipients)
6860 (setq recipients (substring recipients (match-end 0))))
6861 (push (cons 'Cc recipients) follow-to)))
6864 (defun message-prune-recipients (recipients)
6865 (dolist (rule message-prune-recipient-rules)
6866 (let ((match (car rule))
6869 (dolist (recipient recipients)
6870 (setq address (car recipient))
6871 (when (string-match match address)
6872 (setq dup-match (replace-match (cadr rule) nil nil address))
6873 (dolist (recipient recipients)
6874 ;; Don't delete the address that triggered this.
6875 (when (and (not (eq address (car recipient)))
6876 (string-match dup-match (car recipient)))
6877 (setq recipients (delq recipient recipients))))))))
6880 (defcustom message-simplify-subject-functions
6881 '(message-strip-list-identifiers
6882 message-strip-subject-re
6883 message-strip-subject-trailing-was
6884 message-strip-subject-encoded-words)
6885 "List of functions taking a string argument that simplify subjects.
6886 The functions are applied when replying to a message.
6888 Useful functions to put in this list include:
6889 `message-strip-list-identifiers', `message-strip-subject-re',
6890 `message-strip-subject-trailing-was', and
6891 `message-strip-subject-encoded-words'."
6892 :version "22.1" ;; Gnus 5.10.9
6893 :group 'message-various
6894 :type '(repeat function))
6896 (defun message-simplify-subject (subject &optional functions)
6897 "Return simplified SUBJECT."
6900 (setq functions message-simplify-subject-functions))
6901 (when (and (memq 'message-strip-list-identifiers functions)
6902 gnus-list-identifiers)
6903 (setq subject (message-strip-list-identifiers subject)))
6904 (when (memq 'message-strip-subject-re functions)
6905 (setq subject (concat "Re: " (message-strip-subject-re subject))))
6906 (when (and (memq 'message-strip-subject-trailing-was functions)
6907 message-subject-trailing-was-query)
6908 (setq subject (message-strip-subject-trailing-was subject)))
6909 (when (memq 'message-strip-subject-encoded-words functions)
6910 (setq subject (message-strip-subject-encoded-words subject)))
6914 (defun message-reply (&optional to-address wide switch-function)
6915 "Start editing a reply to the article in the current buffer."
6917 (require 'gnus-sum) ; for gnus-list-identifiers
6918 (let ((cur (current-buffer))
6920 references message-id follow-to
6921 (inhibit-point-motion-hooks t)
6922 (message-this-is-mail t)
6925 (message-narrow-to-head-1)
6926 ;; Allow customizations to have their say.
6928 ;; This is a regular reply.
6929 (when (functionp message-reply-to-function)
6931 (setq follow-to (funcall message-reply-to-function))))
6932 ;; This is a followup.
6933 (when (functionp message-wide-reply-to-function)
6936 (funcall message-wide-reply-to-function)))))
6937 (setq message-id (message-fetch-field "message-id" t)
6938 references (message-fetch-field "references")
6939 date (message-fetch-field "date")
6940 from (or (message-fetch-field "from") "nobody")
6941 subject (or (message-fetch-field "subject") "none"))
6943 ;; Strip list identifiers, "Re: ", and "was:"
6944 (setq subject (message-simplify-subject subject))
6946 (when (and (setq gnus-warning (message-fetch-field "gnus-warning"))
6947 (string-match "<[^>]+>" gnus-warning))
6948 (setq message-id (match-string 0 gnus-warning)))
6951 (setq follow-to (message-get-reply-headers wide to-address))))
6954 `((Subject . ,subject)
6956 (unless (message-mail-user-agent)
6957 (message-pop-to-buffer
6958 (message-buffer-name
6959 (if wide "wide reply" "reply") from
6960 (if wide to-address nil))
6962 (setq message-reply-headers
6963 (vector 0 (cdr (assq 'Subject headers))
6964 from date message-id references 0 0 ""))
6965 (message-setup headers cur))))
6968 (defun message-wide-reply (&optional to-address)
6969 "Make a \"wide\" reply to the message in the current buffer."
6971 (message-reply to-address t))
6974 (defun message-followup (&optional to-newsgroups)
6975 "Follow up to the message in the current buffer.
6976 If TO-NEWSGROUPS, use that as the new Newsgroups line."
6978 (require 'gnus-sum) ; for gnus-list-identifiers
6979 (let ((cur (current-buffer))
6980 from subject date reply-to mrt mct
6981 references message-id follow-to
6982 (inhibit-point-motion-hooks t)
6983 (message-this-is-news t)
6984 followup-to distribution newsgroups gnus-warning posted-to)
6987 (goto-char (point-min))
6988 (if (search-forward "\n\n" nil t)
6991 (when (functionp message-followup-to-function)
6993 (funcall message-followup-to-function)))
6994 (setq from (message-fetch-field "from")
6995 date (message-fetch-field "date")
6996 subject (or (message-fetch-field "subject") "none")
6997 references (message-fetch-field "references")
6998 message-id (message-fetch-field "message-id" t)
6999 followup-to (message-fetch-field "followup-to")
7000 newsgroups (message-fetch-field "newsgroups")
7001 posted-to (message-fetch-field "posted-to")
7002 reply-to (message-fetch-field "reply-to")
7003 mrt (message-fetch-field "mail-reply-to")
7004 distribution (message-fetch-field "distribution")
7005 mct (message-fetch-field "mail-copies-to"))
7006 (when (and (setq gnus-warning (message-fetch-field "gnus-warning"))
7007 (string-match "<[^>]+>" gnus-warning))
7008 (setq message-id (match-string 0 gnus-warning)))
7009 ;; Remove bogus distribution.
7010 (when (and (stringp distribution)
7011 (let ((case-fold-search t))
7012 (string-match "world" distribution)))
7013 (setq distribution nil))
7014 ;; Strip list identifiers, "Re: ", and "was:"
7015 (setq subject (message-simplify-subject subject))
7018 (message-pop-to-buffer (message-buffer-name "followup" from newsgroups))
7020 (setq message-reply-headers
7021 (vector 0 subject from date message-id references 0 0 ""))
7024 `((Subject . ,subject)
7027 (list (cons 'Newsgroups to-newsgroups)))
7028 (follow-to follow-to)
7029 ((and followup-to message-use-followup-to)
7032 ((equal (downcase followup-to) "poster")
7033 (if (or (eq message-use-followup-to 'use)
7034 (message-y-or-n-p "Obey Followup-To: poster? " t "\
7035 You should normally obey the Followup-To: header.
7037 `Followup-To: poster' sends your response via e-mail instead of news.
7039 A typical situation where `Followup-To: poster' is used is when the poster
7040 does not read the newsgroup, so he wouldn't see any replies sent to it.
7042 You may customize the variable `message-use-followup-to', if you
7043 want to get rid of this query permanently."))
7045 (setq message-this-is-news nil)
7046 (cons 'To (or mrt reply-to from "")))
7047 (cons 'Newsgroups newsgroups)))
7049 (if (or (equal followup-to newsgroups)
7050 (not (eq message-use-followup-to 'ask))
7052 (concat "Obey Followup-To: " followup-to "? ") t "\
7053 You should normally obey the Followup-To: header.
7055 `Followup-To: " followup-to "'
7056 directs your response to " (if (string-match "," followup-to)
7057 "the specified newsgroups"
7058 "that newsgroup only") ".
7060 If a message is posted to several newsgroups, Followup-To is often
7061 used to direct the following discussion to one newsgroup only,
7062 because discussions that are spread over several newsgroup tend to
7063 be fragmented and very difficult to follow.
7065 Also, some source/announcement newsgroups are not intended for discussion;
7066 responses here are directed to other newsgroups.
7068 You may customize the variable `message-use-followup-to', if you
7069 want to get rid of this query permanently."))
7070 (cons 'Newsgroups followup-to)
7071 (cons 'Newsgroups newsgroups))))))
7073 `((Newsgroups . ,posted-to)))
7075 `((Newsgroups . ,newsgroups))))
7076 ,@(and distribution (list (cons 'Distribution distribution)))
7078 (not (or (equal (downcase mct) "never")
7079 (equal (downcase mct) "nobody"))))
7080 (list (cons 'Cc (if (or (equal (downcase mct) "always")
7081 (equal (downcase mct) "poster"))
7082 (or mrt reply-to from "")
7087 (defun message-is-yours-p ()
7088 "Non-nil means current article is yours.
7089 If you have added `cancel-messages' to `message-shoot-gnksa-feet', all articles
7090 are yours except those that have Cancel-Lock header not belonging to you.
7091 Instead of shooting GNKSA feet, you should modify `message-alternative-emails'
7092 to match all of yours addresses."
7093 ;; Canlock-logic as suggested by Per Abrahamsen
7094 ;; <abraham@dina.kvl.dk>
7096 ;; IF article has cancel-lock THEN
7097 ;; IF we can verify it THEN
7100 ;; error: cancellock: article is not yours
7102 ;; Use old rules, comparing sender...
7105 (message-narrow-to-head-1)
7106 (if (and (message-fetch-field "Cancel-Lock")
7107 (message-gnksa-enable-p 'canlock-verify))
7108 (if (null (canlock-verify))
7110 (error "Failed to verify Cancel-lock: This article is not yours"))
7113 (message-gnksa-enable-p 'cancel-messages)
7114 (and (setq sender (message-fetch-field "sender"))
7115 (string-equal (downcase sender)
7116 (downcase (message-make-sender))))
7117 ;; Email address in From field equals to our address
7118 (and (setq from (message-fetch-field "from"))
7120 (downcase (car (mail-header-parse-address from)))
7121 (downcase (car (mail-header-parse-address
7122 (message-make-from))))))
7123 ;; Email address in From field matches
7124 ;; 'message-alternative-emails' regexp or function.
7126 message-alternative-emails
7127 (cond ((functionp message-alternative-emails)
7128 (funcall message-alternative-emails
7129 (mail-header-parse-address from)))
7130 (t (string-match message-alternative-emails
7131 (car (mail-header-parse-address from))))))))))))
7134 (defun message-cancel-news (&optional arg)
7135 "Cancel an article you posted.
7136 If ARG, allow editing of the cancellation message."
7138 (unless (message-news-p)
7139 (error "This is not a news article; canceling is impossible"))
7140 (let (from newsgroups message-id distribution buf)
7142 ;; Get header info from original article.
7144 (message-narrow-to-head-1)
7145 (setq from (message-fetch-field "from")
7146 newsgroups (message-fetch-field "newsgroups")
7147 message-id (message-fetch-field "message-id" t)
7148 distribution (message-fetch-field "distribution")))
7149 ;; Make sure that this article was written by the user.
7150 (unless (message-is-yours-p)
7151 (error "This article is not yours"))
7152 (when (yes-or-no-p "Do you really want to cancel this article? ")
7153 ;; Make control message.
7156 (setq buf (set-buffer (get-buffer-create " *message cancel*"))))
7158 (insert "Newsgroups: " newsgroups "\n"
7160 "Subject: cancel " message-id "\n"
7161 "Control: cancel " message-id "\n"
7163 (concat "Distribution: " distribution "\n")
7165 mail-header-separator "\n"
7166 message-cancel-message)
7167 (run-hooks 'message-cancel-hook)
7169 (message "Canceling your article...")
7170 (if (let ((message-syntax-checks
7171 'dont-check-for-anything-just-trust-me))
7172 (funcall message-send-news-function))
7173 (message "Canceling your article...done"))
7174 (kill-buffer buf))))))
7177 (defun message-supersede ()
7178 "Start composing a message to supersede the current message.
7179 This is done simply by taking the old article and adding a Supersedes
7180 header line with the old Message-ID."
7182 (let ((cur (current-buffer)))
7183 ;; Check whether the user owns the article that is to be superseded.
7184 (unless (message-is-yours-p)
7185 (error "This article is not yours"))
7186 ;; Get a normal message buffer.
7187 (message-pop-to-buffer (message-buffer-name "supersede"))
7188 (insert-buffer-substring cur)
7190 (message-narrow-to-head-1)
7191 ;; Remove unwanted headers.
7192 (when message-ignored-supersedes-headers
7193 (message-remove-header message-ignored-supersedes-headers t))
7194 (goto-char (point-min))
7195 (if (not (re-search-forward "^Message-ID: " nil t))
7196 (error "No Message-ID in this article")
7197 (replace-match "Supersedes: " t t))
7198 (goto-char (point-max))
7199 (insert mail-header-separator)
7204 (defun message-recover ()
7205 "Reread contents of current buffer from its last auto-save file."
7207 (let ((file-name (make-auto-save-file-name)))
7208 (cond ((save-window-excursion
7209 (with-output-to-temp-buffer "*Directory*"
7210 (with-current-buffer standard-output
7212 (buffer-disable-undo standard-output)
7213 (let ((default-directory "/"))
7215 "ls" nil standard-output nil "-l" file-name)))
7216 (yes-or-no-p (format "Recover auto save file %s? " file-name)))
7217 (let ((buffer-read-only nil))
7219 (insert-file-contents file-name nil)))
7220 (t (error "message-recover canceled")))))
7222 ;;; Washing Subject:
7224 (defun message-wash-subject (subject)
7225 "Remove junk like \"Re:\", \"(fwd)\", etc. added to subject string SUBJECT.
7226 Previous forwarders, repliers, etc. may add it."
7229 (goto-char (point-min))
7230 ;; strip Re/Fwd stuff off the beginning
7231 (while (re-search-forward
7232 "\\([Rr][Ee]:\\|[Ff][Ww][Dd]\\(\\[[0-9]*\\]\\)?:\\|[Ff][Ww]:\\)" nil t)
7235 ;; and gnus-style forwards [foo@bar.com] subject
7236 (goto-char (point-min))
7237 (while (re-search-forward "\\[[^ \t]*\\(@\\|\\.\\)[^ \t]*\\]" nil t)
7241 (goto-char (point-max))
7242 (while (re-search-backward "([Ff][Ww][Dd])" nil t)
7245 ;; and finally, any whitespace that was left-over
7246 (goto-char (point-min))
7247 (while (re-search-forward "^[ \t]+" nil t)
7249 (goto-char (point-max))
7250 (while (re-search-backward "[ \t]+$" nil t)
7255 ;;; Forwarding messages.
7257 (defvar message-forward-decoded-p nil
7258 "Non-nil means the original message is decoded.")
7260 (defun message-forward-subject-name-subject (subject)
7261 "Generate a SUBJECT for a forwarded message.
7262 The form is: [Source] Subject, where if the original message was mail,
7263 Source is the name of the sender, and if the original message was
7264 news, Source is the list of newsgroups is was posted to."
7265 (let* ((group (message-fetch-field "newsgroups"))
7266 (from (message-fetch-field "from"))
7269 (gnus-group-decoded-name group)
7271 (car (gnus-extract-address-components from))
7272 (cadr (gnus-extract-address-components from))))
7275 (if message-forward-decoded-p
7277 (mail-decode-encoded-word-string prefix))
7280 (defun message-forward-subject-author-subject (subject)
7281 "Generate a SUBJECT for a forwarded message.
7282 The form is: [Source] Subject, where if the original message was mail,
7283 Source is the sender, and if the original message was news, Source is
7284 the list of newsgroups is was posted to."
7285 (let* ((group (message-fetch-field "newsgroups"))
7288 (gnus-group-decoded-name group)
7289 (or (message-fetch-field "from")
7292 (if message-forward-decoded-p
7294 (mail-decode-encoded-word-string prefix))
7297 (defun message-forward-subject-fwd (subject)
7298 "Generate a SUBJECT for a forwarded message.
7299 The form is: Fwd: Subject, where Subject is the original subject of
7301 (if (string-match "^Fwd: " subject)
7303 (concat "Fwd: " subject)))
7305 (defun message-make-forward-subject ()
7306 "Return a Subject header suitable for the message in the current buffer."
7309 (message-narrow-to-head-1)
7310 (let ((funcs message-make-forward-subject-function)
7311 (subject (message-fetch-field "Subject")))
7314 (if message-forward-decoded-p
7316 (mail-decode-encoded-word-string subject))
7318 (when message-wash-forwarded-subjects
7319 (setq subject (message-wash-subject subject)))
7320 ;; Make sure funcs is a list.
7323 (setq funcs (list funcs)))
7324 ;; Apply funcs in order, passing subject generated by previous
7325 ;; func to the next one.
7326 (dolist (func funcs)
7327 (when (functionp func)
7328 (setq subject (funcall func subject))))
7331 (defvar gnus-article-decoded-p)
7335 (defun message-forward (&optional news digest)
7336 "Forward the current message via mail.
7337 Optional NEWS will use news to forward instead of mail.
7338 Optional DIGEST will use digest to forward."
7340 (let* ((cur (current-buffer))
7341 (message-forward-decoded-p
7342 (if (local-variable-p 'gnus-article-decoded-p (current-buffer))
7343 gnus-article-decoded-p ;; In an article buffer.
7344 message-forward-decoded-p))
7345 (subject (message-make-forward-subject)))
7347 (message-news nil subject)
7348 (message-mail nil subject))
7349 (message-forward-make-body cur digest)))
7351 (defun message-forward-make-body-plain (forward-buffer)
7353 "\n-------------------- Start of forwarded message --------------------\n")
7355 (contents (with-current-buffer forward-buffer (buffer-string)))
7357 (unless (multibyte-string-p contents)
7358 (error "Attempt to insert unibyte string from the buffer \"%s\"\
7359 to the multibyte buffer \"%s\""
7360 (if (bufferp forward-buffer)
7361 (buffer-name forward-buffer)
7364 (insert (mm-with-multibyte-buffer
7367 (goto-char (point-min))
7368 (when (looking-at "From ")
7369 (replace-match "X-From-Line: "))
7371 (unless (bolp) (insert "\n"))
7374 "-------------------- End of forwarded message --------------------\n")
7375 (message-remove-ignored-headers b e)))
7377 (defun message-remove-ignored-headers (b e)
7378 (when (or message-forward-ignored-headers
7379 message-forward-included-headers)
7381 (narrow-to-region b e)
7383 (narrow-to-region (point)
7384 (or (search-forward "\n\n" nil t) (point)))
7385 (when message-forward-ignored-headers
7386 (let ((ignored (if (stringp message-forward-ignored-headers)
7387 (list message-forward-ignored-headers)
7388 message-forward-ignored-headers)))
7389 (dolist (elem ignored)
7390 (message-remove-header elem t))))
7391 (when message-forward-included-headers
7392 (message-remove-header
7393 (if (listp message-forward-included-headers)
7394 (regexp-opt message-forward-included-headers)
7395 message-forward-included-headers)
7398 (defun message-forward-make-body-mime (forward-buffer &optional beg end)
7400 (insert "\n\n<#part type=message/rfc822 disposition=inline raw=t>\n")
7402 (narrow-to-region (point) (point))
7403 (insert-buffer-substring forward-buffer beg end)
7404 (mml-quote-region (point-min) (point-max))
7405 (goto-char (point-min))
7406 (when (looking-at "From ")
7407 (replace-match "X-From-Line: "))
7408 (goto-char (point-max)))
7409 (insert "<#/part>\n")
7410 ;; Consider there is no illegible text.
7411 (add-text-properties
7413 `(no-illegible-text t rear-nonsticky t start-open t))))
7415 (defun message-forward-make-body-mml (forward-buffer)
7416 (insert "\n\n<#mml type=message/rfc822 disposition=inline>\n")
7417 (let ((b (point)) e)
7418 (if (not message-forward-decoded-p)
7419 (let ((contents (with-current-buffer forward-buffer (buffer-string))))
7420 (unless (multibyte-string-p contents)
7421 (error "Attempt to insert unibyte string from the buffer \"%s\"\
7422 to the multibyte buffer \"%s\""
7423 (if (bufferp forward-buffer)
7424 (buffer-name forward-buffer)
7427 (insert (mm-with-multibyte-buffer
7430 (goto-char (point-min))
7431 (when (looking-at "From ")
7432 (replace-match "X-From-Line: "))
7435 (narrow-to-region (point) (point))
7436 (mml-insert-buffer forward-buffer)
7437 (goto-char (point-min))
7438 (when (looking-at "From ")
7439 (replace-match "X-From-Line: "))
7440 (goto-char (point-max))))
7442 (insert "<#/mml>\n")
7443 (when (not message-forward-decoded-p)
7444 (message-remove-ignored-headers b e))))
7446 (defun message-forward-make-body-digest-plain (forward-buffer)
7448 "\n-------------------- Start of forwarded message --------------------\n")
7449 (mml-insert-buffer forward-buffer)
7451 "\n-------------------- End of forwarded message --------------------\n"))
7453 (defun message-forward-make-body-digest-mime (forward-buffer)
7454 (insert "\n<#multipart type=digest>\n")
7455 (let ((b (point)) e)
7456 (insert-buffer-substring forward-buffer)
7458 (insert "<#/multipart>\n")
7460 (narrow-to-region b e)
7462 (narrow-to-region (point)
7463 (or (search-forward "\n\n" nil t) (point)))
7464 (delete-region (point-min) (point-max)))))
7466 (defun message-forward-make-body-digest (forward-buffer)
7467 (if message-forward-as-mime
7468 (message-forward-make-body-digest-mime forward-buffer)
7469 (message-forward-make-body-digest-plain forward-buffer)))
7471 (autoload 'mm-uu-dissect-text-parts "mm-uu")
7472 (autoload 'mm-uu-dissect "mm-uu")
7474 (defun message-signed-or-encrypted-p (&optional dont-emulate-mime handles)
7475 "Say whether the current buffer contains signed or encrypted message.
7476 If DONT-EMULATE-MIME is nil, this function does the MIME emulation on
7477 messages that don't conform to PGP/MIME described in RFC2015. HANDLES
7478 is for the internal use."
7480 (let ((mm-decrypt-option 'never)
7481 (mm-verify-option 'never))
7482 (if (setq handles (mm-dissect-buffer nil t))
7483 (unless dont-emulate-mime
7484 (mm-uu-dissect-text-parts handles))
7485 (unless dont-emulate-mime
7486 (setq handles (mm-uu-dissect))))))
7487 ;; Check text/plain message in which there is a signed or encrypted
7488 ;; body that has been encoded by B or Q.
7489 (unless (or handles dont-emulate-mime)
7490 (let ((cur (current-buffer))
7491 (mm-decrypt-option 'never)
7492 (mm-verify-option 'never))
7494 (insert-buffer-substring cur)
7495 (when (setq handles (mm-dissect-buffer t t))
7496 (if (and (bufferp (car handles))
7497 (equal (mm-handle-media-type handles) "text/plain"))
7500 (insert-buffer-substring (car handles))
7501 (mm-decode-content-transfer-encoding
7502 (mm-handle-encoding handles))
7503 (mm-destroy-parts handles)
7504 (setq handles (mm-uu-dissect)))
7505 (mm-destroy-parts handles)
7506 (setq handles nil))))))
7510 (dolist (handle (if (stringp (car handles))
7511 (if (member (car handles)
7512 '("multipart/signed"
7513 "multipart/encrypted"))
7517 (if (stringp (car handle))
7518 (when (message-signed-or-encrypted-p dont-emulate-mime handle)
7520 (when (and (bufferp (car handle))
7521 (equal (mm-handle-media-type handle)
7523 (with-current-buffer (mm-handle-buffer handle)
7524 (when (message-signed-or-encrypted-p dont-emulate-mime)
7525 (throw 'found t)))))))
7526 (mm-destroy-parts handles))))
7529 (defun message-forward-make-body (forward-buffer &optional digest)
7530 ;; Put point where we want it before inserting the forwarded
7532 (if message-forward-before-signature
7534 (goto-char (point-max)))
7536 (message-forward-make-body-digest forward-buffer)
7537 (if message-forward-as-mime
7538 (if (and message-forward-show-mml
7539 (not (and (eq message-forward-show-mml 'best)
7540 ;; Use the raw form in the body if it contains
7541 ;; signed or encrypted message so as not to be
7542 ;; destroyed by re-encoding.
7543 (with-current-buffer forward-buffer
7545 (message-signed-or-encrypted-p)
7547 (message-forward-make-body-mml forward-buffer)
7548 (message-forward-make-body-mime forward-buffer))
7549 (message-forward-make-body-plain forward-buffer)))
7550 (message-position-point))
7552 (declare-function rmail-toggle-header "rmail" (&optional arg))
7555 (defun message-forward-rmail-make-body (forward-buffer)
7556 (save-window-excursion
7557 (set-buffer forward-buffer)
7558 (when (rmail-msg-is-pruned)
7559 (rmail-toggle-header 0)))
7560 (message-forward-make-body forward-buffer))
7562 ;; Fixme: Should have defcustom.
7564 (defun message-insinuate-rmail ()
7565 "Let RMAIL use message to forward."
7567 (setq rmail-enable-mime-composing t)
7568 (setq rmail-insert-mime-forwarded-message-function
7569 'message-forward-rmail-make-body))
7571 (defvar message-inhibit-body-encoding nil)
7574 (defun message-resend (address)
7575 "Resend the current article to ADDRESS."
7577 (list (message-read-from-minibuffer "Resend message to: ")))
7578 (message "Resending message to %s..." address)
7580 (let ((cur (current-buffer))
7582 ;; We first set up a normal mail buffer.
7583 (unless (message-mail-user-agent)
7584 (set-buffer (get-buffer-create " *message resend*"))
7585 (let ((inhibit-read-only t))
7587 (let ((message-this-is-mail t)
7588 message-generate-hashcash
7590 (message-setup `((To . ,address))))
7591 ;; Insert our usual headers.
7592 (message-generate-headers '(From Date To Message-ID))
7593 (message-narrow-to-headers)
7594 (when (setq gcc (mail-fetch-field "gcc" nil t))
7595 (message-remove-header "gcc"))
7596 ;; Remove X-Draft-From header etc.
7597 (message-remove-header message-ignored-mail-headers t)
7598 ;; Rename them all to "Resent-*".
7599 (goto-char (point-min))
7600 (while (re-search-forward "^[A-Za-z]" nil t)
7605 (let ((inhibit-read-only t))
7606 (delete-region (point) (point-max)))
7608 ;; Insert the message to be resent.
7609 (insert-buffer-substring cur)
7610 (goto-char (point-min))
7611 (search-forward "\n\n")
7614 (narrow-to-region beg (point))
7615 (message-remove-header message-ignored-resent-headers t)
7616 (goto-char (point-max)))
7617 (insert mail-header-separator)
7618 ;; Rename all old ("Also-")Resent headers.
7619 (while (re-search-backward "^\\(Also-\\)*Resent-" beg t)
7622 ;; Quote any "From " lines at the beginning.
7624 (when (looking-at "From ")
7625 (replace-match "X-From-Line: "))
7627 (let ((message-inhibit-body-encoding
7628 ;; Don't do any further encoding if it looks like the
7629 ;; message has already been encoded.
7630 (let ((case-fold-search t))
7631 (re-search-forward "^mime-version:" nil t)))
7632 (message-inhibit-ecomplete t)
7633 ;; We don't want smtpmail.el to encode anything, either.
7634 (sendmail-coding-system 'raw-text)
7635 (select-safe-coding-system-function nil)
7636 message-required-mail-headers
7637 message-generate-hashcash
7638 rfc2047-encode-encoded-words)
7639 (message-send-mail))
7642 (insert "Gcc: " gcc "\n"))
7643 (run-hooks 'message-sent-hook)
7644 (kill-buffer (current-buffer)))
7645 (message "Resending message to %s...done" address)))
7648 (defun message-bounce ()
7649 "Re-mail the current message.
7650 This only makes sense if the current message is a bounce message that
7651 contains some mail you have written which has been bounced back to
7654 (let ((handles (mm-dissect-buffer t))
7656 (message-pop-to-buffer (message-buffer-name "bounce"))
7657 (if (stringp (car handles))
7658 ;; This is a MIME bounce.
7659 (mm-insert-part (car (last handles)))
7660 ;; This is a non-MIME bounce, so we try to remove things
7662 (mm-insert-part handles)
7664 (goto-char (point-min))
7665 (re-search-forward "\n\n+" nil t)
7666 (setq boundary (point))
7667 ;; We remove everything before the bounced mail.
7668 (if (or (re-search-forward message-unsent-separator nil t)
7670 (search-forward "\n\n" nil 'move)
7671 (re-search-backward "^Return-Path:.*\n" boundary t)))
7674 (delete-region (point-min)
7675 (if (re-search-forward "^[^ \n\t]+:" nil t)
7678 (goto-char boundary)
7679 (when (re-search-backward "^.?From .*\n" nil t)
7680 (delete-region (match-beginning 0) (match-end 0)))))
7683 (message-narrow-to-head-1)
7684 (message-remove-header message-ignored-bounced-headers t)
7685 (goto-char (point-max))
7686 (insert mail-header-separator))
7687 (message-position-point)))
7690 ;;; Interactive entry points for new message buffers.
7694 (defun message-mail-other-window (&optional to subject)
7695 "Like `message-mail' command, but display mail buffer in another window."
7697 (unless (message-mail-user-agent)
7698 (message-pop-to-buffer (message-buffer-name "mail" to)
7699 'switch-to-buffer-other-window))
7700 (let ((message-this-is-mail t))
7701 (message-setup `((To . ,(or to "")) (Subject . ,(or subject "")))
7702 nil nil nil 'switch-to-buffer-other-window)))
7705 (defun message-mail-other-frame (&optional to subject)
7706 "Like `message-mail' command, but display mail buffer in another frame."
7708 (unless (message-mail-user-agent)
7709 (message-pop-to-buffer (message-buffer-name "mail" to)
7710 'switch-to-buffer-other-frame))
7711 (let ((message-this-is-mail t))
7712 (message-setup `((To . ,(or to "")) (Subject . ,(or subject "")))
7713 nil nil nil 'switch-to-buffer-other-frame)))
7716 (defun message-news-other-window (&optional newsgroups subject)
7717 "Start editing a news article to be sent."
7719 (message-pop-to-buffer (message-buffer-name "posting" nil newsgroups)
7720 'switch-to-buffer-other-window)
7721 (let ((message-this-is-news t))
7722 (message-setup `((Newsgroups . ,(or newsgroups ""))
7723 (Subject . ,(or subject ""))))))
7726 (defun message-news-other-frame (&optional newsgroups subject)
7727 "Start editing a news article to be sent."
7729 (message-pop-to-buffer (message-buffer-name "posting" nil newsgroups)
7730 'switch-to-buffer-other-frame)
7731 (let ((message-this-is-news t))
7732 (message-setup `((Newsgroups . ,(or newsgroups ""))
7733 (Subject . ,(or subject ""))))))
7737 ;; This code should be moved to underline.el (from which it is stolen).
7740 (defun message-bold-region (start end)
7741 "Bold all nonblank characters in the region.
7742 Works by overstriking characters.
7743 Called from program, takes two arguments START and END
7744 which specify the range to operate on."
7747 (let ((end1 (make-marker)))
7748 (move-marker end1 (max start end))
7749 (goto-char (min start end))
7750 (while (< (point) end1)
7751 (or (looking-at "[_\^@- ]")
7752 (insert (char-after) "\b"))
7753 (forward-char 1)))))
7756 (defun message-unbold-region (start end)
7757 "Remove all boldness (overstruck characters) in the region.
7758 Called from program, takes two arguments START and END
7759 which specify the range to operate on."
7762 (let ((end1 (make-marker)))
7763 (move-marker end1 (max start end))
7764 (goto-char (min start end))
7765 (while (search-forward "\b" end1 t)
7766 (if (eq (char-after) (char-after (- (point) 2)))
7767 (delete-char -2))))))
7769 (defun message-exchange-point-and-mark ()
7770 "Exchange point and mark, but don't activate region if it was inactive."
7771 (goto-char (prog1 (mark t)
7772 (set-marker (mark-marker) (point)))))
7774 ;; Support for toolbar
7775 (defvar tool-bar-mode)
7777 ;; Note: The :set function in the `message-tool-bar*' variables will only
7778 ;; affect _new_ message buffers. We might add a function that walks thru all
7779 ;; message-mode buffers and force the update.
7780 (defun message-tool-bar-update (&optional symbol value)
7781 "Update message mode toolbar.
7782 Setter function for custom variables."
7783 (setq-default message-tool-bar-map nil)
7785 ;; When used as ":set" function:
7786 (set-default symbol value)))
7788 (defcustom message-tool-bar (if (eq gmm-tool-bar-style 'gnome)
7789 'message-tool-bar-gnome
7790 'message-tool-bar-retro)
7791 "Specifies the message mode tool bar.
7793 It can be either a list or a symbol referring to a list. See
7794 `gmm-tool-bar-from-list' for the format of the list. The
7795 default key map is `message-mode-map'.
7797 Pre-defined symbols include `message-tool-bar-gnome' and
7798 `message-tool-bar-retro'."
7799 :type '(repeat gmm-tool-bar-list-item)
7800 :type '(choice (const :tag "GNOME style" message-tool-bar-gnome)
7801 (const :tag "Retro look" message-tool-bar-retro)
7802 (repeat :tag "User defined list" gmm-tool-bar-item)
7804 :version "23.1" ;; No Gnus
7805 :initialize 'custom-initialize-default
7806 :set 'message-tool-bar-update
7809 (defcustom message-tool-bar-gnome
7810 '((ispell-message "spell" nil
7812 :visible (not flyspell-mode))
7813 (flyspell-buffer "spell" t
7815 :visible flyspell-mode
7816 :help "Flyspell whole buffer")
7817 (message-send-and-exit "mail/send" t :label "Send")
7818 (message-dont-send "mail/save-draft")
7819 (mml-attach-file "attach" mml-mode-map :vert-only t)
7820 (mml-preview "mail/preview" mml-mode-map)
7821 (mml-secure-message-sign-encrypt "lock" mml-mode-map :visible nil)
7822 (message-insert-importance-high "important" nil :visible nil)
7823 (message-insert-importance-low "unimportant" nil :visible nil)
7824 (message-insert-disposition-notification-to "receipt" nil :visible nil))
7825 "List of items for the message tool bar (GNOME style).
7827 See `gmm-tool-bar-from-list' for details on the format of the list."
7828 :type '(repeat gmm-tool-bar-item)
7829 :version "23.1" ;; No Gnus
7830 :initialize 'custom-initialize-default
7831 :set 'message-tool-bar-update
7834 (defcustom message-tool-bar-retro
7835 '(;; Old Emacs 21 icon for consistency.
7836 (message-send-and-exit "gnus/mail-send")
7837 (message-kill-buffer "close")
7838 (message-dont-send "cancel")
7839 (mml-attach-file "attach" mml-mode-map)
7840 (ispell-message "spell")
7841 (mml-preview "preview" mml-mode-map)
7842 (message-insert-importance-high "gnus/important")
7843 (message-insert-importance-low "gnus/unimportant")
7844 (message-insert-disposition-notification-to "gnus/receipt"))
7845 "List of items for the message tool bar (retro style).
7847 See `gmm-tool-bar-from-list' for details on the format of the list."
7848 :type '(repeat gmm-tool-bar-item)
7849 :version "23.1" ;; No Gnus
7850 :initialize 'custom-initialize-default
7851 :set 'message-tool-bar-update
7854 (defcustom message-tool-bar-zap-list
7855 '(new-file open-file dired kill-buffer write-file
7856 print-buffer customize help)
7857 "List of icon items from the global tool bar.
7858 These items are not displayed on the message mode tool bar.
7860 See `gmm-tool-bar-from-list' for the format of the list."
7861 :type 'gmm-tool-bar-zap-list
7862 :version "23.1" ;; No Gnus
7863 :initialize 'custom-initialize-default
7864 :set 'message-tool-bar-update
7867 (defvar image-load-path)
7869 (defun message-make-tool-bar (&optional force)
7870 "Make a message mode tool bar from `message-tool-bar-list'.
7871 When FORCE, rebuild the tool bar."
7872 (when (and (boundp 'tool-bar-mode)
7874 (or (not message-tool-bar-map) force))
7875 (setq message-tool-bar-map
7877 (image-load-path-for-library
7878 "message" "mail/save-draft.xpm" nil t))
7879 (image-load-path (cons (car load-path) image-load-path)))
7880 (gmm-tool-bar-from-list message-tool-bar
7881 message-tool-bar-zap-list
7882 'message-mode-map))))
7883 message-tool-bar-map)
7885 ;;; Group name completion.
7887 (defcustom message-newgroups-header-regexp
7888 "^\\(Newsgroups\\|Followup-To\\|Posted-To\\|Gcc\\):"
7889 "Regexp that match headers that lists groups."
7893 (defcustom message-completion-alist
7894 (list (cons message-newgroups-header-regexp 'message-expand-group)
7895 '("^\\(Resent-\\)?\\(To\\|B?Cc\\):" . message-expand-name)
7896 '("^\\(Reply-To\\|From\\|Mail-Followup-To\\|Mail-Copies-To\\):"
7897 . message-expand-name)
7898 '("^\\(Disposition-Notification-To\\|Return-Receipt-To\\):"
7899 . message-expand-name))
7900 "Alist of (RE . FUN). Use FUN for completion on header lines matching RE."
7903 :type '(alist :key-type regexp :value-type function))
7905 (defcustom message-expand-name-databases
7907 "List of databases to try for name completion (`message-expand-name').
7908 Each element is a symbol and can be `bbdb' or `eudc'."
7910 :type '(set (const bbdb) (const eudc)))
7912 (defcustom message-tab-body-function nil
7913 "Function to execute when `message-tab' (TAB) is executed in the body.
7914 If nil, the function bound in `text-mode-map' or `global-map' is executed."
7917 :link '(custom-manual "(message)Various Commands")
7918 :type '(choice (const nil)
7921 (declare-function mail-abbrev-in-expansion-header-p "mailabbrev" ())
7923 (defun message-tab ()
7924 "Complete names according to `message-completion-alist'.
7925 Execute function specified by `message-tab-body-function' when
7926 not in those headers. If that variable is nil, indent with the
7927 regular text mode tabbing command."
7930 ((let ((completion-fail-discreetly t))
7931 (completion-at-point))
7932 ;; Completion was performed; nothing else to do.
7934 (message-tab-body-function (funcall message-tab-body-function))
7935 (t (funcall (or (lookup-key text-mode-map "\t")
7936 (lookup-key global-map "\t")
7937 'indent-relative)))))
7939 (defvar mail-abbrev-mode-regexp)
7941 (defun message-completion-function ()
7942 (let ((alist message-completion-alist))
7944 (let ((mail-abbrev-mode-regexp (caar alist)))
7945 (not (mail-abbrev-in-expansion-header-p))))
7946 (setq alist (cdr alist)))
7948 (lexical-let ((fun (cdar alist)))
7949 ;; Even if completion fails, return a non-nil value, so as to avoid
7950 ;; falling back to message-tab-body-function.
7951 (lambda () (funcall fun) 'completion-attempted)))))
7953 (defun message-expand-group ()
7954 "Expand the group name under point."
7955 (let ((b (save-excursion
7960 (skip-chars-forward "^:")
7963 (skip-chars-backward "^, \t\n") (point))))
7964 (completion-ignore-case t)
7965 (e (progn (skip-chars-forward "^,\t\n ") (point)))
7967 (when (and (boundp 'gnus-active-hashtb)
7971 (setq group (symbol-name symbol))
7972 (push (if (string-match "[^\000-\177]" group)
7973 (gnus-group-decoded-name group)
7976 gnus-active-hashtb))
7977 (completion-in-region b e collection)))
7979 (defun message-expand-name ()
7980 (cond ((and (memq 'eudc message-expand-name-databases)
7981 (boundp 'eudc-protocol)
7983 (eudc-expand-inline))
7984 ((and (memq 'bbdb message-expand-name-databases)
7985 (fboundp 'bbdb-complete-name))
7986 (let ((starttick (buffer-modified-tick)))
7987 (or (bbdb-complete-name)
7988 ;; Apparently, bbdb-complete-name can return nil even when
7989 ;; completion took place. So let's double check the buffer was
7991 (/= starttick (buffer-modified-tick)))))
7997 (defun message-talkative-question (ask question show &rest text)
7998 "Call FUNCTION with argument QUESTION; optionally display TEXT... args.
7999 If SHOW is non-nil, the arguments TEXT... are displayed in a temp buffer.
8000 The following arguments may contain lists of values."
8002 (setq text (message-flatten-list text)))
8003 (save-window-excursion
8004 (with-output-to-temp-buffer " *MESSAGE information message*"
8005 (with-current-buffer " *MESSAGE information message*"
8008 (goto-char (point-min))))
8009 (funcall ask question))
8010 (funcall ask question)))
8012 (defun message-flatten-list (list)
8013 "Return a new, flat list that contains all elements of LIST.
8015 \(message-flatten-list \\='(1 (2 3 (4 5 (6))) 7))
8018 (apply 'append (mapcar 'message-flatten-list list)))
8022 (defun message-generate-new-buffer-clone-locals (name &optional varstr)
8023 "Create and return a buffer with name based on NAME using `generate-new-buffer'.
8024 Then clone the local variables and values from the old buffer to the
8025 new one, cloning only the locals having a substring matching the
8027 (let ((oldbuf (current-buffer)))
8028 (with-current-buffer (generate-new-buffer name)
8029 (message-clone-locals oldbuf varstr)
8032 (defun message-clone-locals (buffer &optional varstr)
8033 "Clone the local variables from BUFFER to the current buffer."
8034 (let ((locals (with-current-buffer buffer (buffer-local-variables)))
8035 (regexp "^gnus\\|^nn\\|^message\\|^sendmail\\|^smtp\\|^user-mail-address"))
8038 (when (and (consp local)
8040 (string-match regexp (symbol-name (car local)))
8042 (string-match varstr (symbol-name (car local)))))
8044 (set (make-local-variable (car local))
8052 (defun message-encode-message-body ()
8053 (unless message-inhibit-body-encoding
8054 (let ((mail-parse-charset (or mail-parse-charset
8055 message-default-charset))
8056 (case-fold-search t)
8057 lines content-type-p)
8060 (narrow-to-region (point) (point-max))
8061 (let ((new (mml-generate-mime)))
8063 (delete-region (point-min) (point-max))
8065 (goto-char (point-min))
8066 (if (eq (aref new 0) ?\n)
8068 (search-forward "\n\n")
8069 (setq lines (buffer-substring (point-min) (1- (point))))
8070 (delete-region (point-min) (point))))))
8072 (message-narrow-to-headers-or-head)
8073 (message-remove-header "Mime-Version")
8074 (goto-char (point-max))
8075 (insert "MIME-Version: 1.0\n")
8078 (setq content-type-p
8080 (re-search-backward "^Content-Type:" nil t))))
8082 (message-narrow-to-headers-or-head)
8083 (message-remove-first-header "Content-Type")
8084 (message-remove-first-header "Content-Transfer-Encoding"))
8085 ;; We always make sure that the message has a Content-Type
8086 ;; header. This is because some broken MTAs and MUAs get
8087 ;; awfully confused when confronted with a message with a
8088 ;; MIME-Version header and without a Content-Type header. For
8089 ;; instance, Solaris' /usr/bin/mail.
8090 (unless content-type-p
8091 (goto-char (point-min))
8092 ;; For unknown reason, MIME-Version doesn't exist.
8093 (when (re-search-forward "^MIME-Version:" nil t)
8095 (insert "Content-Type: text/plain; charset=us-ascii\n"))))))
8097 (defun message-read-from-minibuffer (prompt &optional initial-contents)
8098 "Read from the minibuffer while providing abbrev expansion."
8099 (let ((minibuffer-setup-hook 'mail-abbrevs-setup)
8100 (minibuffer-local-map message-minibuffer-local-map))
8101 (read-from-minibuffer prompt initial-contents)))
8103 (defun message-use-alternative-email-as-from ()
8104 "Set From field of the outgoing message to the first matching
8105 address in `message-alternative-emails', looking at To, Cc and
8106 From headers in the original article."
8107 (require 'mail-utils)
8108 (let* ((fields '("To" "Cc" "From"))
8110 (message-tokenize-header
8111 (mail-strip-quoted-names
8112 (mapconcat 'message-fetch-reply-field fields ","))))
8113 (email (cond ((functionp message-alternative-emails)
8114 (car (cl-remove-if-not message-alternative-emails emails)))
8115 (t (loop for email in emails
8116 if (string-match-p message-alternative-emails email)
8118 (unless (or (not email) (equal email user-mail-address))
8119 (message-remove-header "From")
8120 (goto-char (point-max))
8121 (insert "From: " (let ((user-mail-address email)) (message-make-from))
8124 (defun message-options-get (symbol)
8125 (cdr (assq symbol message-options)))
8127 (defun message-options-set (symbol value)
8128 (let ((the-cons (assq symbol message-options)))
8131 (setcdr the-cons value)
8132 (setq message-options (delq the-cons message-options)))
8134 (push (cons symbol value) message-options))))
8137 (defun message-options-set-recipient ()
8139 (message-narrow-to-headers-or-head)
8140 (message-options-set 'message-sender
8141 (mail-strip-quoted-names
8142 (message-fetch-field "from")))
8143 (message-options-set 'message-recipients
8144 (mail-strip-quoted-names
8145 (let ((to (message-fetch-field "to"))
8146 (cc (message-fetch-field "cc"))
8147 (bcc (message-fetch-field "bcc")))
8150 (if (and to cc) ", ")
8152 (if (and (or to cc) bcc) ", ")
8155 (defun message-hide-headers ()
8156 "Hide headers based on the `message-hidden-headers' variable."
8157 (let ((regexps (if (stringp message-hidden-headers)
8158 (list message-hidden-headers)
8159 message-hidden-headers))
8160 (inhibit-point-motion-hooks t)
8161 (inhibit-modification-hooks t)
8162 (end-of-headers (point-min)))
8166 (message-narrow-to-headers)
8167 (goto-char (point-min))
8169 (if (not (message-hide-header-p regexps))
8170 (message-next-header)
8171 (let ((begin (point))
8173 (message-next-header)
8174 (setq header (buffer-substring begin (point))
8175 header-len (- (point) begin))
8176 (delete-region begin (point))
8177 (goto-char end-of-headers)
8179 (setq end-of-headers
8180 (+ end-of-headers header-len))))))))
8181 (narrow-to-region end-of-headers (point-max))))
8183 (defun message-hide-header-p (regexps)
8186 (when (eq (car regexps) 'not)
8189 (dolist (regexp regexps)
8190 (setq result (or result (looking-at regexp))))
8195 (declare-function ecomplete-add-item "ecomplete" (type key text))
8196 (declare-function ecomplete-save "ecomplete" ())
8198 (defun message-put-addresses-in-ecomplete ()
8199 (require 'ecomplete)
8200 (dolist (header '("to" "cc" "from" "reply-to"))
8201 (let ((value (message-field-value header)))
8202 (dolist (string (mail-header-parse-addresses value 'raw))
8204 (replace-regexp-in-string
8206 (replace-regexp-in-string "^ +\\| +$" "" string)))
8207 (ecomplete-add-item 'mail (car (mail-header-parse-address string))
8211 (autoload 'ecomplete-display-matches "ecomplete")
8213 (defun message-display-abbrev (&optional choose)
8214 "Display the next possible abbrev for the text before point."
8215 (interactive (list t))
8216 (when (and (memq (char-after (point-at-bol)) '(?C ?T ?\t ? ))
8217 (message-point-in-header-p)
8220 (while (and (memq (char-after) '(?\t ? ))
8221 (zerop (forward-line -1))))
8222 (looking-at "To:\\|Cc:")))
8223 (let* ((end (point))
8224 (start (save-excursion
8225 (and (re-search-backward "[\n\t ]" nil t)
8227 (word (when start (buffer-substring start end)))
8228 (match (when (and word
8229 (not (zerop (length word))))
8230 (ecomplete-display-matches 'mail word choose))))
8231 (when (and choose match)
8232 (delete-region start end)
8235 ;; To send pre-formatted letters like the example below, you can use
8236 ;; `message-send-form-letter':
8237 ;; --8<---------------cut here---------------start------------->8---
8238 ;; To: alice@invalid.invalid
8239 ;; Subject: Verification of your contact information
8240 ;; From: Contact verification <admin@foo.invalid>
8241 ;; --text follows this line--
8243 ;; please verify that your contact information is still valid:
8244 ;; Alice A, A avenue 11, 1111 A town, Austria
8245 ;; ----------next form letter message follows this line----------
8246 ;; To: bob@invalid.invalid
8247 ;; Subject: Verification of your contact information
8248 ;; From: Contact verification <admin@foo.invalid>
8249 ;; --text follows this line--
8251 ;; please verify that your contact information is still valid:
8252 ;; Bob, B street 22, 22222 Be town, Belgium
8253 ;; ----------next form letter message follows this line----------
8254 ;; To: charlie@invalid.invalid
8255 ;; Subject: Verification of your contact information
8256 ;; From: Contact verification <admin@foo.invalid>
8257 ;; --text follows this line--
8259 ;; please verify that your contact information is still valid:
8260 ;; Charlie Chaplin, C plaza 33, 33333 C town, Chile
8261 ;; --8<---------------cut here---------------end--------------->8---
8263 ;; FIXME: What is the most common term (circular letter, form letter, serial
8264 ;; letter, standard letter) for such kind of letter? See also
8265 ;; <http://en.wikipedia.org/wiki/Form_letter>
8267 ;; FIXME: Maybe extent message-mode's font-lock support to recognize
8268 ;; `message-form-letter-separator', i.e. highlight each message like a single
8271 (defcustom message-form-letter-separator
8272 "\n----------next form letter message follows this line----------\n"
8273 "Separator for `message-send-form-letter'."
8274 ;; :group 'message-form-letter
8275 :group 'message-various
8276 :version "23.1" ;; No Gnus
8279 (defcustom message-send-form-letter-delay 1
8280 "Delay in seconds when sending a message with `message-send-form-letter'.
8281 Only used when `message-send-form-letter' is called with non-nil
8283 ;; :group 'message-form-letter
8284 :group 'message-various
8285 :version "23.1" ;; No Gnus
8288 (defun message-send-form-letter (&optional force)
8289 "Sent all form letter messages from current buffer.
8290 Unless FORCE, prompt before sending.
8292 The messages are separated by `message-form-letter-separator'.
8293 Header and body are separated by `mail-header-separator'."
8295 (let ((sent 0) (skipped 0)
8299 (goto-char (point-min))
8302 end (if (search-forward message-form-letter-separator nil t)
8303 (- (point) (length message-form-letter-separator) -1)
8307 (buffer-substring-no-properties start end))
8308 (setq buff (generate-new-buffer "*mail - form letter*"))
8309 (with-current-buffer buff
8312 (setq to (message-fetch-field "To"))
8313 (switch-to-buffer buff)
8315 (sit-for message-send-form-letter-delay))
8317 (y-or-n-p (format-message "Send message to `%s'? " to)))
8319 (setq sent (1+ sent))
8320 (message-send-and-exit))
8321 (message "Message to `%s' skipped." to)
8322 (setq skipped (1+ skipped)))
8323 (when (buffer-live-p buff)
8324 (kill-buffer buff))))
8325 (message "%s message(s) sent, %s skipped." sent skipped)))
8327 (defun message-replace-header (header new-value &optional after force)
8328 "Remove HEADER and insert the NEW-VALUE.
8329 If AFTER, insert after this header. If FORCE, insert new field
8330 even if NEW-VALUE is empty."
8331 ;; Similar to `nnheader-replace-header' but for message buffers.
8334 (message-narrow-to-headers)
8335 (message-remove-header header))
8336 (when (or force (> (length new-value) 0))
8338 (message-position-on-field header after)
8339 (message-position-on-field header))
8340 (insert new-value))))
8342 (defcustom message-recipients-without-full-name
8343 (list "ding@gnus.org"
8345 "emacs-devel@gnu.org"
8346 "emacs-pretest-bug@gnu.org"
8347 "bug-gnu-emacs@gnu.org")
8348 "Mail addresses that have no full name.
8349 Used in `message-simplify-recipients'."
8350 ;; Maybe the addresses could be extracted from
8351 ;; `gnus-parameter-to-list-alist'?
8352 :type '(choice (const :tag "None" nil)
8354 :version "23.1" ;; No Gnus
8355 :group 'message-headers)
8357 (defun message-simplify-recipients ()
8359 (dolist (hdr '("Cc" "To"))
8360 (message-replace-header
8364 (if (and message-recipients-without-full-name
8366 (regexp-opt message-recipients-without-full-name)
8370 (message-make-from (car addrcomp) (cadr addrcomp))
8372 (when (message-fetch-field hdr)
8373 (mail-extract-address-components
8374 (message-fetch-field hdr) t))
8377 ;;; multipart/related and HTML support.
8379 (defun message-make-html-message-with-image-files (files)
8380 "Make a message containing the current dired-marked image files."
8381 (interactive (list (dired-get-marked-files nil current-prefix-arg)))
8384 (insert "<#part type=text/html>\n\n")
8385 (dolist (file files)
8386 (insert (format "<img src=%S>\n\n" file)))
8387 (message-toggle-image-thumbnails)
8390 (defun message-toggle-image-thumbnails ()
8391 "For any included image files, insert a thumbnail of that image."
8393 (let ((displayed nil))
8395 (goto-char (point-min))
8397 (when-let ((props (get-text-property (point) 'display)))
8398 (when (and (consp props)
8399 (eq (car props) 'image))
8400 (put-text-property (point) (1+ (point)) 'display nil)
8401 (setq displayed t)))))
8404 (goto-char (point-min))
8405 (while (re-search-forward "<img.*src=\"\\([^\"]+\\).*>" nil t)
8406 (let ((string (match-string 0))
8407 (file (match-string 1))
8408 (edges (window-inside-pixel-edges
8409 (get-buffer-window (current-buffer)))))
8410 (delete-region (match-beginning 0) (match-end 0))
8413 file 'imagemagick nil
8414 :max-width (truncate
8415 (* 0.7 (- (nth 2 edges) (nth 0 edges))))
8416 :max-height (truncate
8417 (* 0.5 (- (nth 3 edges) (nth 1 edges)))))
8422 (run-hooks 'message-load-hook)
8428 ;;; message.el ends here