1 ;;; message.el --- composing mail and news messages -*- lexical-binding: t -*-
3 ;; Copyright (C) 1996-2017 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
)
54 (autoload 'mailclient-send-it
"mailclient")
56 (defvar gnus-message-group-art
)
57 (defvar gnus-list-identifiers
) ; gnus-sum is required where necessary
58 (defvar rmail-enable-mime-composing
)
60 (defgroup message
'((user-mail-address custom-variable
)
61 (user-full-name custom-variable
))
62 "Mail and news message composing."
63 :link
'(custom-manual "(message)Top")
67 (put 'user-mail-address
'custom-type
'string
)
68 (put 'user-full-name
'custom-type
'string
)
70 (defgroup message-various nil
71 "Various Message Variables."
72 :link
'(custom-manual "(message)Various Message Variables")
75 (defgroup message-buffers nil
77 :link
'(custom-manual "(message)Message Buffers")
80 (defgroup message-sending nil
82 :link
'(custom-manual "(message)Sending Variables")
85 (defgroup message-interface nil
87 :link
'(custom-manual "(message)Interface")
90 (defgroup message-forwarding nil
92 :link
'(custom-manual "(message)Forwarding")
93 :group
'message-interface
)
95 (defgroup message-insertion nil
97 :link
'(custom-manual "(message)Insertion")
100 (defgroup message-headers nil
102 :link
'(custom-manual "(message)Message Headers")
105 (defgroup message-news nil
106 "Composing News Messages."
109 (defgroup message-mail nil
110 "Composing Mail Messages."
113 (defgroup message-faces nil
114 "Faces used for message composing."
118 (defcustom message-directory
"~/Mail/"
119 "Directory from which all other mail file variables are derived."
120 :group
'message-various
123 (defcustom message-max-buffers
10
124 "How many buffers to keep before starting to kill them off."
125 :group
'message-buffers
128 (defcustom message-send-rename-function nil
129 "Function called to rename the buffer after sending it."
130 :group
'message-buffers
131 :type
'(choice function
(const nil
)))
133 (defcustom message-fcc-handler-function
'message-output
134 "A function called to save outgoing articles.
135 This function will be called with the name of the file to store the
136 article in. The default function is `message-output' which saves in Unix
138 :type
'(radio (function-item message-output
)
139 (function :tag
"Other"))
140 :group
'message-sending
)
142 (defcustom message-fcc-externalize-attachments nil
143 "If non-nil, attachments are included as external parts in Fcc copies."
146 :group
'message-sending
)
148 (defcustom message-courtesy-message
149 "The following message is a courtesy copy of an article\nthat has been posted to %s as well.\n\n"
150 "This is inserted at the start of a mailed copy of a posted message.
151 If the string contains the format spec \"%s\", the Newsgroups
152 the article has been posted to will be inserted there.
153 If this variable is nil, no such courtesy message will be added."
154 :group
'message-sending
155 :type
'(radio string
(const nil
)))
157 (defcustom message-ignored-bounced-headers
158 "^\\(Received\\|Return-Path\\|Delivered-To\\):"
159 "Regexp that matches headers to be removed in resent bounced mail."
160 :group
'message-interface
163 (defcustom message-from-style mail-from-style
164 "Specifies how \"From\" headers look.
166 If nil, they contain just the return address like:
168 If `parens', they look like:
169 king@grassland.com (Elvis Parsley)
170 If `angles', they look like:
171 Elvis Parsley <king@grassland.com>
173 Otherwise, most addresses look like `angles', but they look like
174 `parens' if `angles' would need quoting and `parens' would not."
176 :type
'(choice (const :tag
"simple" nil
)
180 :group
'message-headers
)
182 (defcustom message-insert-canlock t
183 "Whether to insert a Cancel-Lock header in news postings."
185 :group
'message-headers
188 (defcustom message-syntax-checks
189 (if message-insert-canlock
'((sender . disabled
)) nil
)
190 ;; Guess this one shouldn't be easy to customize...
191 "Controls what syntax checks should not be performed on outgoing posts.
192 To disable checking of long signatures, for instance, add
193 `(signature . disabled)' to this list.
195 Don't touch this variable unless you really know what you're doing.
197 Checks include `approved', `bogus-recipient', `continuation-headers',
198 `control-chars', `empty', `existing-newsgroups', `from', `illegible-text',
199 `invisible-text', `long-header-lines', `long-lines', `message-id',
200 `multiple-headers', `new-text', `newsgroups', `quoting-style',
201 `repeated-newsgroups', `reply-to', `sender', `sendsys', `shoot',
202 `shorten-followup-to', `signature', `size', `subject', `subject-cmsg'
203 and `valid-newsgroups'."
205 :type
'(repeat sexp
)) ; Fixme: improve this
207 (defcustom message-required-headers
'((optional . References
)
209 "Headers to be generated or prompted for when sending a message.
210 Also see `message-required-news-headers' and
211 `message-required-mail-headers'."
214 :group
'message-headers
215 :link
'(custom-manual "(message)Message Headers")
216 :type
'(repeat sexp
))
218 (defcustom message-draft-headers
'(References From Date
)
219 "Headers to be generated when saving a draft message."
222 :group
'message-headers
223 :link
'(custom-manual "(message)Message Headers")
224 :type
'(repeat sexp
))
226 (defcustom message-required-news-headers
227 '(From Newsgroups Subject Date Message-ID
228 (optional . Organization
)
229 (optional . User-Agent
))
230 "Headers to be generated or prompted for when posting an article.
231 RFC977 and RFC1036 require From, Date, Newsgroups, Subject,
232 Message-ID. Organization, Lines, In-Reply-To, Expires, and
233 User-Agent are optional. If you don't want message to insert some
234 header, remove it from this list."
236 :group
'message-headers
237 :link
'(custom-manual "(message)Message Headers")
238 :type
'(repeat sexp
))
240 (defcustom message-required-mail-headers
241 '(From Subject Date
(optional . In-Reply-To
) Message-ID
242 (optional . User-Agent
))
243 "Headers to be generated or prompted for when mailing a message.
244 It is recommended that From, Date, To, Subject and Message-ID be
245 included. Organization and User-Agent are optional."
247 :group
'message-headers
248 :link
'(custom-manual "(message)Message Headers")
249 :type
'(repeat sexp
))
251 (defcustom message-prune-recipient-rules nil
252 "Rules for how to prune the list of recipients when doing wide replies.
253 This is a list of regexps and regexp matches."
256 :group
'message-headers
257 :link
'(custom-manual "(message)Wide Reply")
258 :type
'(repeat regexp
))
260 (defcustom message-deletable-headers
'(Message-ID Date Lines
)
261 "Headers to delete if present and previously generated by message."
262 :group
'message-headers
263 :link
'(custom-manual "(message)Message Headers")
264 :type
'(repeat (symbol :tag
"Header")))
266 (defcustom message-ignored-news-headers
267 "^NNTP-Posting-Host:\\|^Xref:\\|^[BGF]cc:\\|^Resent-Fcc:\\|^X-Draft-From:\\|^X-Gnus-Agent-Meta-Information:\\|^X-Message-SMTP-Method:\\|^X-Gnus-Delayed:"
268 "Regexp of headers to be removed unconditionally before posting."
270 :group
'message-headers
271 :link
'(custom-manual "(message)Message Headers")
272 :type
'(repeat :value-to-internal
(lambda (widget value
)
273 (custom-split-regexp-maybe value
))
274 :match
(lambda (widget value
)
276 (widget-editable-list-match widget value
)))
279 (defcustom message-ignored-mail-headers
280 "^\\([GF]cc\\|Resent-Fcc\\|Xref\\|X-Draft-From\\|X-Gnus-Agent-Meta-Information\\):"
281 "Regexp of headers to be removed unconditionally before mailing."
283 :group
'message-headers
284 :link
'(custom-manual "(message)Mail Headers")
287 (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:"
288 "Header lines matching this regexp will be deleted before posting.
289 It's best to delete old Path and Date headers before posting to avoid
291 :group
'message-interface
292 :link
'(custom-manual "(message)Superseding")
293 :type
'(repeat :value-to-internal
(lambda (widget value
)
294 (custom-split-regexp-maybe value
))
295 :match
(lambda (widget value
)
297 (widget-editable-list-match widget value
)))
300 (defcustom message-subject-re-regexp
301 "^[ \t]*\\([Rr][Ee]\\(\\[[0-9]*\\]\\)* ?:[ \t]*\\)*[ \t]*"
302 "Regexp matching \"Re: \" in the subject line."
303 :group
'message-various
304 :link
'(custom-manual "(message)Message Headers")
307 ;;; Start of variables adopted from `message-utils.el'.
309 (defcustom message-subject-trailing-was-query t
310 "What to do with trailing \"(was: <old subject>)\" in subject lines.
311 If nil, leave the subject unchanged. If it is the symbol `ask', query
312 the user what do do. In this case, the subject is matched against
313 `message-subject-trailing-was-ask-regexp'. If
314 `message-subject-trailing-was-query' is t, always strip the trailing
315 old subject. In this case, `message-subject-trailing-was-regexp' is
318 :type
'(choice (const :tag
"never" nil
)
319 (const :tag
"always strip" t
)
321 :link
'(custom-manual "(message)Message Headers")
322 :group
'message-various
)
324 (defcustom message-subject-trailing-was-ask-regexp
325 "[ \t]*\\([[(]+[Ww][Aa][Ss]:?[ \t]*.*[])]+\\)"
326 "Regexp matching \"(was: <old subject>)\" in the subject line.
328 The function `message-strip-subject-trailing-was' uses this regexp if
329 `message-subject-trailing-was-query' is set to the symbol `ask'. If
330 the variable is t instead of `ask', use
331 `message-subject-trailing-was-regexp' instead.
333 It is okay to create some false positives here, as the user is asked."
335 :group
'message-various
336 :link
'(custom-manual "(message)Message Headers")
339 (defcustom message-subject-trailing-was-regexp
340 "[ \t]*\\((*[Ww][Aa][Ss]:[ \t]*.*)\\)"
341 "Regexp matching \"(was: <old subject>)\" in the subject line.
343 If `message-subject-trailing-was-query' is set to t, the subject is
344 matched against `message-subject-trailing-was-regexp' in
345 `message-strip-subject-trailing-was'. You should use a regexp creating very
346 few false positives here."
348 :group
'message-various
349 :link
'(custom-manual "(message)Message Headers")
352 ;;; marking inserted text
354 (defcustom message-mark-insert-begin
355 "--8<---------------cut here---------------start------------->8---\n"
356 "How to mark the beginning of some inserted text."
359 :link
'(custom-manual "(message)Insertion Variables")
360 :group
'message-various
)
362 (defcustom message-mark-insert-end
363 "--8<---------------cut here---------------end--------------->8---\n"
364 "How to mark the end of some inserted text."
367 :link
'(custom-manual "(message)Insertion Variables")
368 :group
'message-various
)
370 (defcustom message-archive-header
"X-No-Archive: Yes\n"
371 "Header to insert when you don't want your article to be archived.
372 Archives \(such as groups.google.com) respect this header."
375 :link
'(custom-manual "(message)Header Commands")
376 :group
'message-various
)
378 (defcustom message-archive-note
379 "X-No-Archive: Yes - save http://groups.google.com/"
380 "Note to insert why you wouldn't want this posting archived.
381 If nil, don't insert any text in the body."
383 :type
'(radio string
(const nil
))
384 :link
'(custom-manual "(message)Header Commands")
385 :group
'message-various
)
387 ;;; Crossposts and Followups
388 ;; inspired by JoH-followup-to by Jochem Huhman <joh at gmx.de>
389 ;; new suggestions by R. Weikusat <rw at another.de>
391 (defvar message-cross-post-old-target nil
392 "Old target for cross-posts or follow-ups.")
393 (make-variable-buffer-local 'message-cross-post-old-target
)
395 (defcustom message-cross-post-default t
396 "When non-nil `message-cross-post-followup-to' will perform a crosspost.
397 If nil, `message-cross-post-followup-to' will only do a followup. Note that
398 you can explicitly override this setting by calling
399 `message-cross-post-followup-to' with a prefix."
402 :group
'message-various
)
404 (defcustom message-cross-post-note
"Crosspost & Followup-To: "
405 "Note to insert before signature to notify of cross-post and follow-up."
408 :group
'message-various
)
410 (defcustom message-followup-to-note
"Followup-To: "
411 "Note to insert before signature to notify of follow-up only."
414 :group
'message-various
)
416 (defcustom message-cross-post-note-function
'message-cross-post-insert-note
417 "Function to use to insert note about Crosspost or Followup-To.
418 The function will be called with four arguments. The function should not only
419 insert a note, but also ensure old notes are deleted. See the documentation
420 for `message-cross-post-insert-note'."
423 :group
'message-various
)
425 ;;; End of variables adopted from `message-utils.el'.
427 (defcustom message-signature-separator
"^-- $"
428 "Regexp matching the signature separator.
429 This variable is used to strip off the signature from quoted text
430 when `message-cite-function' is
431 `message-cite-original-without-signature'. Most useful values
432 are \"^-- $\" (strict) and \"^-- *$\" (loose; allow missing
434 :type
'(choice (const :tag
"strict" "^-- $")
435 (const :tag
"loose" "^-- *$")
437 :version
"22.3" ;; Gnus 5.10.12 (changed default)
438 :link
'(custom-manual "(message)Various Message Variables")
439 :group
'message-various
)
441 (defcustom message-elide-ellipsis
"\n[...]\n\n"
442 "The string which is inserted for elided text.
443 This is a format-spec string, and you can use %l to say how many
444 lines were removed, and %c to say how many characters were
447 :link
'(custom-manual "(message)Various Commands")
448 :group
'message-various
)
450 (defcustom message-interactive mail-interactive
451 "Non-nil means when sending a message wait for and display errors.
452 A value of nil means let mailer mail back a message to report errors."
454 :group
'message-sending
456 :link
'(custom-manual "(message)Sending Variables")
459 (defcustom message-confirm-send nil
460 "When non-nil, ask for confirmation when sending a message."
461 :group
'message-sending
463 :version
"23.1" ;; No Gnus
464 :link
'(custom-manual "(message)Sending Variables")
467 (defcustom message-generate-new-buffers
'unsent
468 "Say whether to create a new message buffer to compose a message.
469 Valid values include:
472 Generate the buffer name in the Message way (e.g., *mail*, *news*,
473 *mail to whom*, *news on group*, etc.) and continue editing in the
474 existing buffer of that name. If there is no such buffer, it will
478 Create the new buffer with the name generated in the Message way.
481 Similar to `unique' but the buffer name begins with \"*unsent \".
484 Similar to nil but the buffer name is simpler like *mail message*.
487 If this is a function, call that function with three parameters:
488 The type, the To address and the group name (any of these may be nil).
489 The function should return the new buffer name."
491 :group
'message-buffers
492 :link
'(custom-manual "(message)Message Buffers")
493 :type
'(choice (const nil
)
494 (sexp :tag
"unique" :format
"unique\n" :value unique
495 :match
(lambda (widget value
) (memq value
'(unique t
))))
498 (function :format
"\n %{%t%}: %v")))
500 (defcustom message-kill-buffer-on-exit nil
501 "Non-nil means that the message buffer will be killed after sending a message."
502 :group
'message-buffers
503 :link
'(custom-manual "(message)Message Buffers")
506 (defcustom message-kill-buffer-query t
507 "Non-nil means that killing a modified message buffer has to be confirmed.
508 This is used by `message-kill-buffer'."
509 :version
"23.1" ;; No Gnus
510 :group
'message-buffers
513 (defcustom message-user-organization
514 (or (getenv "ORGANIZATION") t
)
515 "String to be used as an Organization header.
516 If t, use `message-user-organization-file'."
517 :group
'message-headers
518 :type
'(choice string
519 (const :tag
"consult file" t
)))
521 (defcustom message-user-organization-file
523 (dolist (f (list "/etc/organization"
524 "/etc/news/organization"
525 "/usr/lib/news/organization"))
526 (when (file-readable-p f
)
529 "Local news organization file."
530 :type
'(choice (const nil
) file
)
531 :link
'(custom-manual "(message)News Headers")
532 :group
'message-headers
)
534 (defcustom message-make-forward-subject-function
535 #'message-forward-subject-name-subject
536 "List of functions called to generate subject headers for forwarded messages.
537 The subject generated by the previous function is passed into each
540 The provided functions are:
542 * `message-forward-subject-author-subject' Source of article (author or
543 newsgroup), in brackets followed by the subject
544 * `message-forward-subject-name-subject' Source of article (name of author
545 or newsgroup), in brackets followed by the subject
546 * `message-forward-subject-fwd' Subject of article with `Fwd:' prepended
548 :group
'message-forwarding
549 :link
'(custom-manual "(message)Forwarding")
550 :type
'(radio (function-item message-forward-subject-author-subject
)
551 (function-item message-forward-subject-fwd
)
552 (function-item message-forward-subject-name-subject
)
553 (repeat :tag
"List of functions" function
)))
555 (defcustom message-forward-as-mime t
556 "Non-nil means forward messages as an inline/rfc822 MIME section.
557 Otherwise, directly inline the old message in the forwarded message."
559 :group
'message-forwarding
560 :link
'(custom-manual "(message)Forwarding")
563 (defcustom message-forward-show-mml
'best
564 "Non-nil means show forwarded messages as MML (decoded from MIME).
565 Otherwise, forwarded messages are unchanged.
566 Can also be the symbol `best' to indicate that MML should be
567 used, except when it is a bad idea to use MML. One example where
568 it is a bad idea is when forwarding a signed or encrypted
569 message, because converting MIME to MML would invalidate the
572 :group
'message-forwarding
573 :type
'(choice (const :tag
"use MML" t
)
574 (const :tag
"don't use MML " nil
)
575 (const :tag
"use MML when appropriate" best
)))
577 (defcustom message-forward-before-signature t
578 "Non-nil means put forwarded message before signature, else after."
579 :group
'message-forwarding
582 (defcustom message-wash-forwarded-subjects nil
583 "Non-nil means try to remove as much cruft as possible from the subject.
584 Done before generating the new subject of a forward."
585 :group
'message-forwarding
586 :link
'(custom-manual "(message)Forwarding")
589 (defcustom message-ignored-resent-headers
590 ;; `Delivered-To' needs to be removed because some mailers use it to
591 ;; detect loops, so if you resend a message to an address that ultimately
592 ;; comes back to you (e.g. a mailing-list to which you subscribe, in which
593 ;; case you may be removed from the list on the grounds that mail to you
594 ;; bounced with a "mailing loop" error).
595 "^Return-receipt\\|^X-Gnus\\|^Gnus-Warning:\\|^>?From \\|^Delivered-To:\
596 \\|^X-Content-Length:\\|^X-UIDL:"
597 "All headers that match this regexp will be deleted when resending a message."
599 :group
'message-interface
600 :link
'(custom-manual "(message)Resending")
601 :type
'(repeat :value-to-internal
(lambda (widget value
)
602 (custom-split-regexp-maybe value
))
603 :match
(lambda (widget value
)
605 (widget-editable-list-match widget value
)))
608 (defcustom message-forward-ignored-headers
"^Content-Transfer-Encoding:\\|^X-Gnus"
609 "All headers that match this regexp will be deleted when forwarding a message.
610 This may also be a list of regexps."
612 :group
'message-forwarding
613 :type
'(repeat :value-to-internal
(lambda (widget value
)
614 (custom-split-regexp-maybe value
))
615 :match
(lambda (widget value
)
617 (widget-editable-list-match widget value
)))
620 (defcustom message-forward-included-headers nil
621 "If non-nil, delete non-matching headers when forwarding a message.
622 Only headers that match this regexp will be included. This
623 variable should be a regexp or a list of regexps."
625 :group
'message-forwarding
626 :type
'(repeat :value-to-internal
(lambda (widget value
)
627 (custom-split-regexp-maybe value
))
628 :match
(lambda (widget value
)
630 (widget-editable-list-match widget value
)))
633 (defcustom message-ignored-cited-headers
"."
634 "Delete these headers from the messages you yank."
635 :group
'message-insertion
636 :link
'(custom-manual "(message)Insertion Variables")
639 (defcustom message-cite-prefix-regexp mail-citation-prefix-regexp
640 "Regexp matching the longest possible citation prefix on a line."
642 :group
'message-insertion
643 :link
'(custom-manual "(message)Insertion Variables")
645 :set
(lambda (symbol value
)
647 (custom-set-default symbol value
)
648 (if (boundp 'gnus-message-cite-prefix-regexp
)
649 (setq gnus-message-cite-prefix-regexp
650 (concat "^\\(?:" value
"\\)"))))))
652 (defcustom message-cancel-message
"I am canceling my own article.\n"
653 "Message to be inserted in the cancel message."
654 :group
'message-interface
655 :link
'(custom-manual "(message)Canceling News")
658 (defun message-send-mail-function ()
659 "Return suitable value for the variable `message-send-mail-function'."
660 (cond ((and (require 'sendmail
)
661 (boundp 'sendmail-program
)
663 (executable-find sendmail-program
))
664 'message-send-mail-with-sendmail
)
665 ((and (locate-library "smtpmail")
666 (boundp 'smtpmail-default-smtp-server
)
667 smtpmail-default-smtp-server
)
668 'message-smtpmail-send-it
)
669 ((locate-library "mailclient")
670 'message-send-mail-with-mailclient
)
672 (error "Don't know how to send mail. Please customize `message-send-mail-function'"))))
674 (defun message-default-send-mail-function ()
675 (cond ((eq send-mail-function
'smtpmail-send-it
) 'message-smtpmail-send-it
)
676 ((eq send-mail-function
'feedmail-send-it
) 'feedmail-send-it
)
677 ((eq send-mail-function
'sendmail-query-once
) 'sendmail-query-once
)
678 ((eq send-mail-function
'mailclient-send-it
)
679 'message-send-mail-with-mailclient
)
680 (t (message-send-mail-function))))
682 ;; Useful to set in site-init.el
683 (defcustom message-send-mail-function
(message-default-send-mail-function)
684 "Function to call to send the current buffer as mail.
685 The headers should be delimited by a line whose contents match the
686 variable `mail-header-separator'.
688 Valid values include `message-send-mail-with-sendmail'
689 `message-send-mail-with-mh', `message-send-mail-with-qmail',
690 `message-smtpmail-send-it', `smtpmail-send-it',
691 `feedmail-send-it' and `message-send-mail-with-mailclient'. The
692 default is system dependent and determined by the function
693 `message-send-mail-function'.
695 See also `send-mail-function'."
696 :type
'(radio (function-item message-send-mail-with-sendmail
)
697 (function-item message-send-mail-with-mh
)
698 (function-item message-send-mail-with-qmail
)
699 (function-item message-smtpmail-send-it
)
700 (function-item smtpmail-send-it
)
701 (function-item feedmail-send-it
)
702 (function-item message-send-mail-with-mailclient
703 :tag
"Use Mailclient package")
704 (function :tag
"Other"))
705 :group
'message-sending
707 :initialize
'custom-initialize-default
708 :link
'(custom-manual "(message)Mail Variables")
709 :group
'message-mail
)
711 (defcustom message-send-news-function
'message-send-news
712 "Function to call to send the current buffer as news.
713 The headers should be delimited by a line whose contents match the
714 variable `mail-header-separator'."
715 :group
'message-sending
717 :link
'(custom-manual "(message)News Variables")
720 (defcustom message-reply-to-function nil
721 "If non-nil, function that should return a list of headers.
722 This function should pick out addresses from the To, Cc, and From headers
723 and respond with new To and Cc headers."
724 :group
'message-interface
725 :link
'(custom-manual "(message)Reply")
726 :type
'(choice function
(const nil
)))
728 (defcustom message-wide-reply-to-function nil
729 "If non-nil, function that should return a list of headers.
730 This function should pick out addresses from the To, Cc, and From headers
731 and respond with new To and Cc headers."
732 :group
'message-interface
733 :link
'(custom-manual "(message)Wide Reply")
734 :type
'(choice function
(const nil
)))
736 (defcustom message-followup-to-function nil
737 "If non-nil, function that should return a list of headers.
738 This function should pick out addresses from the To, Cc, and From headers
739 and respond with new To and Cc headers."
740 :group
'message-interface
741 :link
'(custom-manual "(message)Followup")
742 :type
'(choice function
(const nil
)))
744 (defcustom message-extra-wide-headers nil
745 "If non-nil, a list of additional address headers.
746 These are used when composing a wide reply."
747 :group
'message-sending
748 :type
'(repeat string
))
750 (defcustom message-use-followup-to
'ask
751 "Specifies what to do with Followup-To header.
752 If nil, always ignore the header. If it is t, use its value, but
753 query before using the \"poster\" value. If it is the symbol `ask',
754 always query the user whether to use the value. If it is the symbol
755 `use', always use the value."
756 :group
'message-interface
757 :link
'(custom-manual "(message)Followup")
758 :type
'(choice (const :tag
"ignore" nil
)
759 (const :tag
"use & query" t
)
763 (defcustom message-use-mail-followup-to
'use
764 "Specifies what to do with Mail-Followup-To header.
765 If nil, always ignore the header. If it is the symbol `ask', always
766 query the user whether to use the value. If it is the symbol `use',
767 always use the value."
769 :group
'message-interface
770 :link
'(custom-manual "(message)Mailing Lists")
771 :type
'(choice (const :tag
"ignore" nil
)
775 (defcustom message-subscribed-address-functions nil
776 "Specifies functions for determining list subscription.
777 If nil, do not attempt to determine list subscription with functions.
778 If non-nil, this variable contains a list of functions which return
779 regular expressions to match lists. These functions can be used in
780 conjunction with `message-subscribed-regexps' and
781 `message-subscribed-addresses'."
783 :group
'message-interface
784 :link
'(custom-manual "(message)Mailing Lists")
785 :type
'(repeat sexp
))
787 (defcustom message-subscribed-address-file nil
788 "A file containing addresses the user is subscribed to.
789 If nil, do not look at any files to determine list subscriptions. If
790 non-nil, each line of this file should be a mailing list address."
792 :group
'message-interface
793 :link
'(custom-manual "(message)Mailing Lists")
794 :type
'(radio file
(const nil
)))
796 (defcustom message-subscribed-addresses nil
797 "Specifies a list of addresses the user is subscribed to.
798 If nil, do not use any predefined list subscriptions. This list of
799 addresses can be used in conjunction with
800 `message-subscribed-address-functions' and `message-subscribed-regexps'."
802 :group
'message-interface
803 :link
'(custom-manual "(message)Mailing Lists")
804 :type
'(repeat string
))
806 (defcustom message-subscribed-regexps nil
807 "Specifies a list of addresses the user is subscribed to.
808 If nil, do not use any predefined list subscriptions. This list of
809 regular expressions can be used in conjunction with
810 `message-subscribed-address-functions' and `message-subscribed-addresses'."
812 :group
'message-interface
813 :link
'(custom-manual "(message)Mailing Lists")
814 :type
'(repeat regexp
))
816 (defcustom message-allow-no-recipients
'ask
817 "Specifies what to do when there are no recipients other than Gcc/Fcc.
818 If it is the symbol `always', the posting is allowed. If it is the
819 symbol `never', the posting is not allowed. If it is the symbol
820 `ask', you are prompted."
822 :group
'message-interface
823 :link
'(custom-manual "(message)Message Headers")
824 :type
'(choice (const always
)
828 (defcustom message-sendmail-f-is-evil nil
829 "Non-nil means don't add \"-f username\" to the sendmail command line.
830 Doing so would be even more evil than leaving it out."
831 :group
'message-sending
832 :link
'(custom-manual "(message)Mail Variables")
835 (defcustom message-sendmail-envelope-from
836 ;; `mail-envelope-from' is unavailable unless sendmail.el is loaded.
837 (if (boundp 'mail-envelope-from
) mail-envelope-from
)
838 "Envelope-from when sending mail with sendmail.
839 If this is nil, use `user-mail-address'. If it is the symbol
840 `header', use the From: header of the message."
842 :type
'(choice (string :tag
"From name")
843 (const :tag
"Use From: header from message" header
)
844 (const :tag
"Use `user-mail-address'" nil
))
845 :link
'(custom-manual "(message)Mail Variables")
846 :group
'message-sending
)
848 (defcustom message-sendmail-extra-arguments nil
849 "Additional arguments to `sendmail-program'."
850 ;; E.g. '("-a" "account") for msmtp
851 :version
"23.1" ;; No Gnus
852 :type
'(repeat string
)
853 ;; :link '(custom-manual "(message)Mail Variables")
854 :group
'message-sending
)
856 ;; qmail-related stuff
857 (defcustom message-qmail-inject-program
"/var/qmail/bin/qmail-inject"
858 "Location of the qmail-inject program."
859 :group
'message-sending
860 :link
'(custom-manual "(message)Mail Variables")
863 (defcustom message-qmail-inject-args nil
864 "Arguments passed to qmail-inject programs.
865 This should be a list of strings, one string for each argument.
866 It may also be a function.
868 For e.g., if you wish to set the envelope sender address so that bounces
869 go to the right place or to deal with listserv's usage of that address, you
870 might set this variable to (\"-f\" \"you@some.where\")."
871 :group
'message-sending
872 :link
'(custom-manual "(message)Mail Variables")
873 :type
'(choice (function)
876 (defvar gnus-post-method
)
877 (defvar gnus-select-method
)
878 (defcustom message-post-method
879 (cond ((and (boundp 'gnus-post-method
)
880 (listp gnus-post-method
)
883 ((boundp 'gnus-select-method
)
886 "Method used to post news.
887 Note that when posting from inside Gnus, for instance, this
888 variable isn't used."
890 :group
'message-sending
891 ;; This should be the `gnus-select-method' widget, but that might
892 ;; create a dependence to `gnus.el'.
895 (defcustom message-generate-headers-first nil
896 "Which headers should be generated before starting to compose a message.
897 If t, generate all required headers. This can also be a list of headers to
898 generate. The variables `message-required-news-headers' and
899 `message-required-mail-headers' specify which headers to generate.
901 Note that the variable `message-deletable-headers' specifies headers which
902 are to be deleted and then re-generated before sending, so this variable
903 will not have a visible effect for those headers."
904 :group
'message-headers
905 :link
'(custom-manual "(message)Message Headers")
906 :type
'(choice (const :tag
"None" nil
)
908 (repeat (sexp :tag
"Header"))))
910 (defcustom message-fill-column
72
911 "Column beyond which automatic line-wrapping should happen.
912 Local value for message buffers. If non-nil, also turn on
913 auto-fill in message buffers."
914 :group
'message-various
915 ;; :link '(custom-manual "(message)Message Headers")
916 :type
'(choice (const :tag
"Don't turn on auto fill" nil
)
919 (defcustom message-setup-hook nil
920 "Normal hook, run each time a new outgoing message is initialized.
921 The function `message-setup' runs this hook."
922 :group
'message-various
923 :link
'(custom-manual "(message)Various Message Variables")
926 (defcustom message-cancel-hook nil
927 "Hook run when canceling articles."
928 :group
'message-various
929 :link
'(custom-manual "(message)Various Message Variables")
932 (defcustom message-signature-setup-hook nil
933 "Normal hook, run each time a new outgoing message is initialized.
934 It is run after the headers have been inserted and before
935 the signature is inserted."
936 :group
'message-various
937 :link
'(custom-manual "(message)Various Message Variables")
940 (defcustom message-mode-hook nil
941 "Hook run in message mode buffers."
942 :group
'message-various
945 (defcustom message-header-hook nil
946 "Hook run in a message mode buffer narrowed to the headers."
947 :group
'message-various
950 (defcustom message-header-setup-hook nil
951 "Hook called narrowed to the headers when setting up a message buffer."
952 :group
'message-various
953 :link
'(custom-manual "(message)Various Message Variables")
956 (defcustom message-minibuffer-local-map
957 (let ((map (make-sparse-keymap 'message-minibuffer-local-map
)))
958 (set-keymap-parent map minibuffer-local-map
)
960 "Keymap for `message-read-from-minibuffer'."
961 ;; FIXME improve type.
962 :type
'(restricted-sexp :match-alternatives
(symbolp keymapp
))
964 :group
'message-various
)
966 (defcustom message-citation-line-function
'message-insert-citation-line
967 "Function called to insert the \"Whomever writes:\" line.
969 Predefined functions include `message-insert-citation-line' and
970 `message-insert-formatted-citation-line' (see the variable
971 `message-citation-line-format').
973 Note that Gnus provides a feature where the reader can click on
974 `writes:' to hide the cited text. If you change this line too much,
975 people who read your message will have to change their Gnus
976 configuration. See the variable `gnus-cite-attribution-suffix'."
978 (function-item :tag
"plain" message-insert-citation-line
)
979 (function-item :tag
"formatted" message-insert-formatted-citation-line
)
980 (function :tag
"Other"))
981 :link
'(custom-manual "(message)Insertion Variables")
982 :group
'message-insertion
)
984 (defcustom message-citation-line-format
"On %a, %b %d %Y, %N wrote:\n"
985 "Format of the \"Whomever writes:\" line.
987 The string is formatted using `format-spec'. The following constructs
990 %f The full From, e.g. \"John Doe <john.doe@example.invalid>\".
991 %n The mail address, e.g. \"john.doe@example.invalid\".
992 %N The real name if present, e.g.: \"John Doe\", else fall
993 back to the mail address.
994 %F The first name if present, e.g.: \"John\", else fall
995 back to the mail address.
996 %L The last name if present, e.g.: \"Doe\".
997 %Z, %z The time zone in the numeric form, e.g.:\"+0000\".
999 All other format specifiers are passed to `format-time-string'
1000 which is called using the date from the article your replying to, but
1001 the date in the formatted string will be expressed in the author's
1002 time zone as much as possible.
1003 Extracting the first (%F) and last name (%L) is done heuristically,
1004 so you should always check it yourself.
1006 Please also read the note in the documentation of
1007 `message-citation-line-function'."
1008 :type
'(choice (const :tag
"Plain" "%f writes:")
1009 (const :tag
"Include date" "On %a, %b %d %Y, %n wrote:")
1011 :link
'(custom-manual "(message)Insertion Variables")
1012 :version
"23.1" ;; No Gnus
1013 :group
'message-insertion
)
1015 (defcustom message-yank-prefix mail-yank-prefix
1016 "Prefix inserted on the lines of yanked messages.
1017 Fix `message-cite-prefix-regexp' if it is set to an abnormal value.
1018 See also `message-yank-cited-prefix' and `message-yank-empty-prefix'."
1021 :link
'(custom-manual "(message)Insertion Variables")
1022 :group
'message-insertion
)
1024 (defcustom message-yank-cited-prefix
">"
1025 "Prefix inserted on cited lines of yanked messages.
1026 Fix `message-cite-prefix-regexp' if it is set to an abnormal value.
1027 See also `message-yank-prefix' and `message-yank-empty-prefix'."
1030 :link
'(custom-manual "(message)Insertion Variables")
1031 :group
'message-insertion
)
1033 (defcustom message-yank-empty-prefix
">"
1034 "Prefix inserted on empty lines of yanked messages.
1035 See also `message-yank-prefix' and `message-yank-cited-prefix'."
1038 :link
'(custom-manual "(message)Insertion Variables")
1039 :group
'message-insertion
)
1041 (defcustom message-indentation-spaces mail-indentation-spaces
1042 "Number of spaces to insert at the beginning of each cited line.
1043 Used by `message-yank-original' via `message-yank-cite'."
1045 :group
'message-insertion
1046 :link
'(custom-manual "(message)Insertion Variables")
1049 (defcustom message-cite-function
'message-cite-original-without-signature
1050 "Function for citing an original message.
1051 Predefined functions include `message-cite-original' and
1052 `message-cite-original-without-signature'.
1053 Note that these functions use `mail-citation-hook' if that is non-nil."
1054 :type
'(radio (function-item message-cite-original
)
1055 (function-item message-cite-original-without-signature
)
1056 (function-item sc-cite-original
)
1057 (function :tag
"Other"))
1058 :link
'(custom-manual "(message)Insertion Variables")
1059 :version
"22.3" ;; Gnus 5.10.12 (changed default)
1060 :group
'message-insertion
)
1062 (defcustom message-indent-citation-function
'message-indent-citation
1063 "Function for modifying a citation just inserted in the mail buffer.
1064 This can also be a list of functions. Each function can find the
1065 citation between (point) and (mark t). And each function should leave
1066 point and mark around the citation text as modified."
1068 :link
'(custom-manual "(message)Insertion Variables")
1069 :group
'message-insertion
)
1071 (defcustom message-signature mail-signature
1072 "String to be inserted at the end of the message buffer.
1073 If t, the `message-signature-file' file will be inserted instead.
1074 If a function, the result from the function will be used instead.
1075 If a form, the result from the form will be used instead."
1077 :type
'(choice string
(const :tag
"Contents of signature file" t
)
1081 :link
'(custom-manual "(message)Insertion Variables")
1082 :group
'message-insertion
)
1084 (defcustom message-signature-file mail-signature-file
1085 "Name of file containing the text inserted at end of message buffer.
1086 Ignored if the named file doesn't exist.
1087 If nil, don't insert a signature.
1088 If a path is specified, the value of `message-signature-directory' is ignored,
1091 :type
'(choice file
(const :tags
"None" nil
))
1092 :link
'(custom-manual "(message)Insertion Variables")
1093 :group
'message-insertion
)
1095 (defcustom message-signature-directory nil
1096 "Name of directory containing signature files.
1097 Comes in handy if you have many such files, handled via posting styles for
1099 If nil, `message-signature-file' is expected to specify the directory if
1101 :type
'(choice string
(const :tags
"None" nil
))
1102 :link
'(custom-manual "(message)Insertion Variables")
1103 :group
'message-insertion
)
1105 (defcustom message-signature-insert-empty-line t
1106 "If non-nil, insert an empty line before the signature separator."
1109 :link
'(custom-manual "(message)Insertion Variables")
1110 :group
'message-insertion
)
1112 (defcustom message-cite-reply-position
'traditional
1113 "Where the reply should be positioned.
1114 If `traditional', reply inline.
1115 If `above', reply above quoted text.
1116 If `below', reply below quoted text.
1118 Note: Many newsgroups frown upon nontraditional reply styles. You
1119 probably want to set this variable only for specific groups,
1120 e.g. using `gnus-posting-styles':
1122 (eval (set (make-local-variable \\='message-cite-reply-position) \\='above))"
1124 :type
'(choice (const :tag
"Reply inline" traditional
)
1125 (const :tag
"Reply above" above
)
1126 (const :tag
"Reply below" below
))
1127 :group
'message-insertion
)
1129 (defcustom message-cite-style nil
1130 "The overall style to be used when yanking cited text.
1131 Value is either nil (no variable overrides) or a let-style list
1132 of pairs (VARIABLE VALUE) that will be bound in
1133 `message-yank-original' to do the quoting.
1135 Presets to impersonate popular mail agents are found in the
1136 message-cite-style-* variables. This variable is intended for
1137 use in `gnus-posting-styles', such as:
1139 ((posting-from-work-p) (eval (set (make-local-variable \\='message-cite-style) message-cite-style-outlook)))"
1141 :group
'message-insertion
1142 :type
'(choice (const :tag
"Do not override variables" :value nil
)
1143 (const :tag
"MS Outlook" :value message-cite-style-outlook
)
1144 (const :tag
"Mozilla Thunderbird" :value message-cite-style-thunderbird
)
1145 (const :tag
"Gmail" :value message-cite-style-gmail
)
1146 (variable :tag
"User-specified")))
1148 (defconst message-cite-style-outlook
1149 '((message-cite-function 'message-cite-original
)
1150 (message-citation-line-function 'message-insert-formatted-citation-line
)
1151 (message-cite-reply-position 'above
)
1152 (message-yank-prefix "")
1153 (message-yank-cited-prefix "")
1154 (message-yank-empty-prefix "")
1155 (message-citation-line-format "\n\n-----------------------\nOn %a, %b %d %Y, %N wrote:\n"))
1156 "Message citation style used by MS Outlook. Use with message-cite-style.")
1158 (defconst message-cite-style-thunderbird
1159 '((message-cite-function 'message-cite-original
)
1160 (message-citation-line-function 'message-insert-formatted-citation-line
)
1161 (message-cite-reply-position 'above
)
1162 (message-yank-prefix "> ")
1163 (message-yank-cited-prefix ">")
1164 (message-yank-empty-prefix ">")
1165 (message-citation-line-format "On %D %R %p, %N wrote:"))
1166 "Message citation style used by Mozilla Thunderbird. Use with message-cite-style.")
1168 (defconst message-cite-style-gmail
1169 '((message-cite-function 'message-cite-original
)
1170 (message-citation-line-function 'message-insert-formatted-citation-line
)
1171 (message-cite-reply-position 'above
)
1172 (message-yank-prefix " ")
1173 (message-yank-cited-prefix " ")
1174 (message-yank-empty-prefix " ")
1175 (message-citation-line-format "On %e %B %Y %R, %f wrote:\n"))
1176 "Message citation style used by Gmail. Use with message-cite-style.")
1178 (defcustom message-distribution-function nil
1179 "Function called to return a Distribution header."
1180 :group
'message-news
1181 :group
'message-headers
1182 :link
'(custom-manual "(message)News Headers")
1183 :type
'(choice function
(const nil
)))
1185 (defcustom message-expires
14
1186 "Number of days before your article expires."
1187 :group
'message-news
1188 :group
'message-headers
1189 :link
'(custom-manual "(message)News Headers")
1192 (defcustom message-user-path nil
1193 "If nil, use the NNTP server name in the Path header.
1194 If stringp, use this; if non-nil, use no host name (user name only)."
1195 :group
'message-news
1196 :group
'message-headers
1197 :link
'(custom-manual "(message)News Headers")
1198 :type
'(choice (const :tag
"nntp" nil
)
1199 (string :tag
"name")
1200 (sexp :tag
"none" :format
"%t" t
)))
1202 ;; This can be the name of a buffer, or a cons cell (FUNCTION . ARGS)
1203 ;; for yanking the original buffer.
1204 (defvar message-reply-buffer nil
)
1205 (defvar message-reply-headers nil
1206 "The headers of the current replied article.
1207 It is a vector of the following headers:
1208 [number subject from date id references chars lines xref extra].")
1209 (defvar message-newsreader nil
)
1210 (defvar message-mailer nil
)
1211 (defvar message-sent-message-via nil
)
1212 (defvar message-checksum nil
)
1213 (defvar message-send-actions nil
1214 "A list of actions to be performed upon successful sending of a message.")
1215 (defvar message-return-action nil
1216 "Action to return to the caller after sending or postponing a message.")
1217 (defvar message-exit-actions nil
1218 "A list of actions to be performed upon exiting after sending a message.")
1219 (defvar message-kill-actions nil
1220 "A list of actions to be performed before killing a message buffer.")
1221 (defvar message-postpone-actions nil
1222 "A list of actions to be performed after postponing a message.")
1224 (define-widget 'message-header-lines
'text
1225 "All header lines must be LFD terminated."
1226 :format
"%{%t%}:%n%v"
1227 :valid-regexp
"^\\'"
1228 :error
"All header lines must be newline terminated")
1230 (defcustom message-default-headers
""
1231 "Header lines to be inserted in outgoing messages.
1232 This can be set to a string containing or a function returning
1233 header lines to be inserted before you edit the message, so you
1234 can edit or delete these lines. If set to a function, it is
1235 called and its result is inserted."
1237 :group
'message-headers
1238 :link
'(custom-manual "(message)Message Headers")
1240 (message-header-lines :tag
"String")
1241 (function :tag
"Function")))
1243 (defcustom message-default-mail-headers
1244 ;; Ease the transition from mail-mode to message-mode. See bugs#4431, 5555.
1245 (concat (if (and (boundp 'mail-default-reply-to
)
1246 (stringp mail-default-reply-to
))
1247 (format "Reply-to: %s\n" mail-default-reply-to
))
1248 (if (and (boundp 'mail-self-blind
)
1250 (format "BCC: %s\n" user-mail-address
))
1251 (if (and (boundp 'mail-archive-file-name
)
1252 (stringp mail-archive-file-name
))
1253 (format "FCC: %s\n" mail-archive-file-name
))
1254 mail-default-headers
)
1255 "A string of header lines to be inserted in outgoing mails."
1257 :group
'message-headers
1258 :group
'message-mail
1259 :link
'(custom-manual "(message)Mail Headers")
1260 :type
'message-header-lines
)
1262 (defcustom message-default-news-headers
""
1263 "A string of header lines to be inserted in outgoing news articles."
1264 :group
'message-headers
1265 :group
'message-news
1266 :link
'(custom-manual "(message)News Headers")
1267 :type
'message-header-lines
)
1269 ;; Note: could use /usr/ucb/mail instead of sendmail;
1270 ;; options -t, and -v if not interactive.
1271 (defcustom message-mailer-swallows-blank-line
1272 (if (and (string-match "sparc-sun-sunos\\(\\'\\|[^5]\\)"
1273 system-configuration
)
1274 (file-readable-p "/etc/sendmail.cf")
1276 (insert-file-contents "/etc/sendmail.cf")
1277 (goto-char (point-min))
1278 (let ((case-fold-search nil
))
1279 (re-search-forward "^OR\\>" nil t
))))
1280 ;; According to RFC822, "The field-name must be composed of printable
1281 ;; ASCII characters (i. e., characters that have decimal values between
1282 ;; 33 and 126, except colon)", i. e., any chars except ctl chars,
1284 '(looking-at "[ \t]\\|[][!\"#$%&'()*+,-./0-9;<=>?@A-Z\\\\^_`a-z{|}~]+:"))
1285 "Set this non-nil if the system's mailer runs the header and body together.
1286 \(This problem exists on Sunos 4 when sendmail is run in remote mode.)
1287 The value should be an expression to test whether the problem will
1289 :group
'message-sending
1290 :link
'(custom-manual "(message)Mail Variables")
1295 (define-mail-user-agent 'message-user-agent
1296 'message-mail
'message-send-and-exit
1297 'message-kill-buffer
'message-send-hook
)
1299 (defvar message-mh-deletable-headers
'(Message-ID Date Lines Sender
)
1300 "If non-nil, delete the deletable headers before feeding to mh.")
1302 (defvar message-send-method-alist
1303 '((news message-news-p message-send-via-news
)
1304 (mail message-mail-p message-send-via-mail
))
1305 "Alist of ways to send outgoing messages.
1306 Each element has the form
1308 (TYPE PREDICATE FUNCTION)
1310 where TYPE is a symbol that names the method; PREDICATE is a function
1311 called without any parameters to determine whether the message is
1312 a message of type TYPE; and FUNCTION is a function to be called if
1313 PREDICATE returns non-nil. FUNCTION is called with one parameter --
1316 (defcustom message-mail-alias-type
'abbrev
1317 "What alias expansion type to use in Message buffers.
1318 The default is `abbrev', which uses mailabbrev. `ecomplete' uses
1319 an electric completion mode. nil switches mail aliases off.
1320 This can also be a list of values."
1322 :link
'(custom-manual "(message)Mail Aliases")
1323 :type
'(choice (const :tag
"Use Mailabbrev" abbrev
)
1324 (const :tag
"Use ecomplete" ecomplete
)
1325 (const :tag
"No expansion" nil
)))
1327 (defcustom message-self-insert-commands
'(self-insert-command)
1328 "List of `self-insert-command's used to trigger ecomplete.
1329 When one of those commands is invoked to enter a character in To or Cc
1330 header, ecomplete will suggest the candidates of recipients (see also
1331 `message-mail-alias-type'). If you use some tool to enter non-ASCII
1332 text and it replaces `self-insert-command' with the other command, e.g.
1333 `egg-self-insert-command', you may want to add it to this list."
1334 :group
'message-various
1335 :type
'(repeat function
))
1337 (defcustom message-auto-save-directory
1338 (if (file-writable-p message-directory
)
1339 (file-name-as-directory (expand-file-name "drafts" message-directory
))
1341 "Directory where Message auto-saves buffers if Gnus isn't running.
1342 If nil, Message won't auto-save."
1343 :group
'message-buffers
1344 :link
'(custom-manual "(message)Various Message Variables")
1345 :type
'(choice directory
(const :tag
"Don't auto-save" nil
)))
1347 (defcustom message-default-charset
(and (not (mm-multibyte-p)) 'iso-8859-1
)
1348 "Default charset used in non-MULE Emacsen.
1349 If nil, you might be asked to input the charset."
1352 :link
'(custom-manual "(message)Various Message Variables")
1354 (make-obsolete-variable
1355 'message-default-charset
1356 "The default charset comes from the language environment" "26.1")
1358 (defcustom message-dont-reply-to-names mail-dont-reply-to-names
1359 "Addresses to prune when doing wide replies.
1360 This can be a regexp, a list of regexps or a predicate function.
1361 Also, a value of nil means exclude your own user name only.
1363 If a function email is passed as the argument."
1366 :link
'(custom-manual "(message)Wide Reply")
1367 :type
'(choice (const :tag
"Yourself" nil
)
1369 (repeat :tag
"Regexp List" regexp
)))
1371 (defsubst message-dont-reply-to-names
()
1372 (if (functionp message-dont-reply-to-names
)
1373 message-dont-reply-to-names
1374 (gmm-regexp-concat message-dont-reply-to-names
)))
1376 (defcustom message-shoot-gnksa-feet nil
1377 "A list of GNKSA feet you are allowed to shoot.
1378 Gnus gives you all the opportunity you could possibly want for
1379 shooting yourself in the foot. Also, Gnus allows you to shoot the
1380 feet of Good Net-Keeping Seal of Approval. The following are foot
1382 `empty-article' Allow you to post an empty article;
1383 `quoted-text-only' Allow you to post quoted text only;
1384 `multiple-copies' Allow you to post multiple copies;
1385 `cancel-messages' Allow you to cancel or supersede messages from
1386 your other email addresses;
1387 `canlock-verify' Allow you to cancel messages without verifying canlock."
1389 :type
'(set (const empty-article
) (const quoted-text-only
)
1390 (const multiple-copies
) (const cancel-messages
)
1391 (const canlock-verify
)))
1393 (defsubst message-gnksa-enable-p
(feature)
1394 (or (not (listp message-shoot-gnksa-feet
))
1395 (memq feature message-shoot-gnksa-feet
)))
1397 (defcustom message-hidden-headers
'("^References:" "^Face:" "^X-Face:"
1399 "Regexp of headers to be hidden when composing new messages.
1400 This can also be a list of regexps to match headers. Or a list
1401 starting with `not' and followed by regexps."
1404 :link
'(custom-manual "(message)Message Headers")
1406 :format
"%{%t%}: %[Value Type%] %v"
1407 (regexp :menu-tag
"regexp" :format
"regexp\n%t: %v")
1408 (repeat :menu-tag
"(regexp ...)" :format
"(regexp ...)\n%v%i"
1409 (regexp :format
"%t: %v"))
1410 (cons :menu-tag
"(not regexp ...)" :format
"(not regexp ...)\n%v"
1412 (repeat :format
"%v%i"
1413 (regexp :format
"%t: %v")))))
1415 (defcustom message-cite-articles-with-x-no-archive t
1416 "If non-nil, cite text from articles that has X-No-Archive set."
1420 ;;; Internal variables.
1421 ;;; Well, not really internal.
1423 (defvar message-mode-syntax-table
1424 (let ((table (copy-syntax-table text-mode-syntax-table
)))
1425 (modify-syntax-entry ?%
". " table
)
1426 (modify-syntax-entry ?
> ". " table
)
1427 (modify-syntax-entry ?
< ". " table
)
1429 "Syntax table used while in Message mode.")
1431 (defface message-header-to
1434 (:foreground
"DarkOliveGreen1" :bold t
))
1437 (:foreground
"MidnightBlue" :bold t
))
1439 (:bold t
:italic t
)))
1440 "Face used for displaying From headers."
1441 :group
'message-faces
)
1442 ;; backward-compatibility alias
1443 (put 'message-header-to-face
'face-alias
'message-header-to
)
1444 (put 'message-header-to-face
'obsolete-face
"22.1")
1446 (defface message-header-cc
1449 (:foreground
"chartreuse1" :bold t
))
1452 (:foreground
"MidnightBlue"))
1455 "Face used for displaying Cc headers."
1456 :group
'message-faces
)
1457 ;; backward-compatibility alias
1458 (put 'message-header-cc-face
'face-alias
'message-header-cc
)
1459 (put 'message-header-cc-face
'obsolete-face
"22.1")
1461 (defface message-header-subject
1464 (:foreground
"OliveDrab1"))
1467 (:foreground
"navy blue" :bold t
))
1470 "Face used for displaying subject headers."
1471 :group
'message-faces
)
1472 ;; backward-compatibility alias
1473 (put 'message-header-subject-face
'face-alias
'message-header-subject
)
1474 (put 'message-header-subject-face
'obsolete-face
"22.1")
1476 (defface message-header-newsgroups
1479 (:foreground
"yellow" :bold t
:italic t
))
1482 (:foreground
"blue4" :bold t
:italic t
))
1484 (:bold t
:italic t
)))
1485 "Face used for displaying newsgroups headers."
1486 :group
'message-faces
)
1487 ;; backward-compatibility alias
1488 (put 'message-header-newsgroups-face
'face-alias
'message-header-newsgroups
)
1489 (put 'message-header-newsgroups-face
'obsolete-face
"22.1")
1491 (defface message-header-other
1494 (:foreground
"VioletRed1"))
1497 (:foreground
"steel blue"))
1499 (:bold t
:italic t
)))
1500 "Face used for displaying newsgroups headers."
1501 :group
'message-faces
)
1502 ;; backward-compatibility alias
1503 (put 'message-header-other-face
'face-alias
'message-header-other
)
1504 (put 'message-header-other-face
'obsolete-face
"22.1")
1506 (defface message-header-name
1509 (:foreground
"green"))
1512 (:foreground
"cornflower blue"))
1515 "Face used for displaying header names."
1516 :group
'message-faces
)
1517 ;; backward-compatibility alias
1518 (put 'message-header-name-face
'face-alias
'message-header-name
)
1519 (put 'message-header-name-face
'obsolete-face
"22.1")
1521 (defface message-header-xheader
1524 (:foreground
"DeepSkyBlue1"))
1527 (:foreground
"blue"))
1530 "Face used for displaying X-Header headers."
1531 :group
'message-faces
)
1532 ;; backward-compatibility alias
1533 (put 'message-header-xheader-face
'face-alias
'message-header-xheader
)
1534 (put 'message-header-xheader-face
'obsolete-face
"22.1")
1536 (defface message-separator
1539 (:foreground
"LightSkyBlue1"))
1542 (:foreground
"brown"))
1545 "Face used for displaying the separator."
1546 :group
'message-faces
)
1547 ;; backward-compatibility alias
1548 (put 'message-separator-face
'face-alias
'message-separator
)
1549 (put 'message-separator-face
'obsolete-face
"22.1")
1551 (defface message-cited-text
1554 (:foreground
"LightPink1"))
1557 (:foreground
"red"))
1560 "Face used for displaying cited text names."
1561 :group
'message-faces
)
1562 ;; backward-compatibility alias
1563 (put 'message-cited-text-face
'face-alias
'message-cited-text
)
1564 (put 'message-cited-text-face
'obsolete-face
"22.1")
1566 (defface message-mml
1569 (:foreground
"MediumSpringGreen"))
1572 (:foreground
"ForestGreen"))
1575 "Face used for displaying MML."
1576 :group
'message-faces
)
1577 ;; backward-compatibility alias
1578 (put 'message-mml-face
'face-alias
'message-mml
)
1579 (put 'message-mml-face
'obsolete-face
"22.1")
1581 (defun message-font-lock-make-header-matcher (regexp)
1584 (let ((start (point)))
1587 (goto-char (point-min))
1588 (if (re-search-forward
1589 (concat "^" (regexp-quote mail-header-separator
) "$")
1591 (setq limit
(min limit
(match-beginning 0))))
1593 (and (< start limit
)
1594 (re-search-forward ,regexp limit t
))))))
1595 (if (featurep 'bytecomp
)
1599 (defvar message-font-lock-keywords
1600 (let ((content "[ \t]*\\(.+\\(\n[ \t].*\\)*\\)\n?"))
1601 `((,(message-font-lock-make-header-matcher
1602 (concat "^\\([Tt]o:\\)" content
))
1603 (1 'message-header-name
)
1604 (2 'message-header-to nil t
))
1605 (,(message-font-lock-make-header-matcher
1606 (concat "^\\(^[GBF]?[Cc][Cc]:\\|^[Rr]eply-[Tt]o:\\)" content
))
1607 (1 'message-header-name
)
1608 (2 'message-header-cc nil t
))
1609 (,(message-font-lock-make-header-matcher
1610 (concat "^\\([Ss]ubject:\\)" content
))
1611 (1 'message-header-name
)
1612 (2 'message-header-subject nil t
))
1613 (,(message-font-lock-make-header-matcher
1614 (concat "^\\([Nn]ewsgroups:\\|Followup-[Tt]o:\\)" content
))
1615 (1 'message-header-name
)
1616 (2 'message-header-newsgroups nil t
))
1617 (,(message-font-lock-make-header-matcher
1618 (concat "^\\(X-[A-Za-z0-9-]+:\\|In-Reply-To:\\)" content
))
1619 (1 'message-header-name
)
1620 (2 'message-header-xheader
))
1621 (,(message-font-lock-make-header-matcher
1622 (concat "^\\([A-Z][^: \n\t]+:\\)" content
))
1623 (1 'message-header-name
)
1624 (2 'message-header-other nil t
))
1625 ,@(if (and mail-header-separator
1626 (not (equal mail-header-separator
"")))
1627 `((,(concat "^\\(" (regexp-quote mail-header-separator
) "\\)$")
1628 1 'message-separator
))
1631 (re-search-forward (concat "^\\("
1632 message-cite-prefix-regexp
1635 (0 'message-cited-text
))
1636 ("<#/?\\(multipart\\|part\\|external\\|mml\\|secure\\)[^>]*>"
1638 "Additional expressions to highlight in Message mode.")
1640 (defvar message-face-alist
1641 '((bold . message-bold-region
)
1642 (underline . underline-region
)
1643 (default .
(lambda (b e
)
1644 (message-unbold-region b e
)
1645 (ununderline-region b e
))))
1646 "Alist of mail and news faces for facemenu.
1647 The cdr of each entry is a function for applying the face to a region.")
1649 (defcustom message-send-hook nil
1650 "Hook run before sending messages.
1651 This hook is run quite early when sending."
1652 :group
'message-various
1653 :options
'(ispell-message)
1654 :link
'(custom-manual "(message)Various Message Variables")
1657 (defcustom message-send-mail-hook nil
1658 "Hook run before sending mail messages.
1659 This hook is run very late -- just before the message is sent as
1661 :group
'message-various
1662 :link
'(custom-manual "(message)Various Message Variables")
1665 (defcustom message-send-news-hook nil
1666 "Hook run before sending news messages.
1667 This hook is run very late -- just before the message is sent as
1669 :group
'message-various
1670 :link
'(custom-manual "(message)Various Message Variables")
1673 (defcustom message-sent-hook nil
1674 "Hook run after sending messages."
1675 :group
'message-various
1678 (defvar message-send-coding-system
'binary
1679 "Coding system to encode outgoing mail.")
1681 (defvar message-draft-coding-system mm-auto-save-coding-system
1682 "Coding system to compose mail.")
1684 (defcustom message-send-mail-partially-limit nil
1685 "The limitation of messages sent as message/partial.
1686 The lower bound of message size in characters, beyond which the message
1687 should be sent in several parts. If it is nil, the size is unlimited."
1689 :group
'message-buffers
1690 :link
'(custom-manual "(message)Mail Variables")
1691 :type
'(choice (const :tag
"unlimited" nil
)
1694 (defcustom message-alternative-emails nil
1695 "Regexp or predicate function matching alternative email addresses.
1696 The first address in the To, Cc or From headers of the original
1697 article matching this variable is used as the From field of
1700 If a function, an email string is passed as the argument.
1702 This variable has precedence over posting styles and anything that runs
1703 off `message-setup-hook'."
1704 :group
'message-headers
1705 :link
'(custom-manual "(message)Message Headers")
1706 :type
'(choice (const :tag
"Always use primary" nil
)
1710 (defcustom message-hierarchical-addresses nil
1711 "A list of hierarchical mail address definitions.
1713 Inside each entry, the first address is the \"top\" address, and
1714 subsequent addresses are subaddresses; this is used to indicate that
1715 mail sent to the first address will automatically be delivered to the
1716 subaddresses. So if the first address appears in the recipient list
1717 for a message, the subaddresses will be removed (if present) before
1718 the mail is sent. All addresses in this structure should be
1721 :group
'message-headers
1722 :type
'(repeat (repeat string
)))
1724 (defcustom message-mail-user-agent nil
1725 "Like `mail-user-agent'.
1726 Except if it is nil, use Gnus native MUA; if it is t, use
1729 :type
'(radio (const :tag
"Gnus native"
1732 (const :tag
"`mail-user-agent'"
1735 (function-item :tag
"Default Emacs mail"
1737 sendmail-user-agent
)
1738 (function-item :tag
"Emacs interface to MH"
1741 (function :tag
"Other"))
1745 (defcustom message-wide-reply-confirm-recipients nil
1746 "Whether to confirm a wide reply to multiple email recipients.
1747 If this variable is nil, don't ask whether to reply to all recipients.
1748 If this variable is non-nil, pose the question \"Reply to all
1749 recipients?\" before a wide reply to multiple recipients. If the user
1750 answers yes, reply to all recipients as usual. If the user answers
1751 no, only reply back to the author."
1753 :group
'message-headers
1754 :link
'(custom-manual "(message)Wide Reply")
1757 (defcustom message-user-fqdn nil
1758 "Domain part of Message-Ids."
1760 :group
'message-headers
1761 :link
'(custom-manual "(message)News Headers")
1762 :type
'(radio (const :format
"%v " nil
)
1763 (string :format
"FQDN: %v")))
1765 (defcustom message-use-idna t
1766 "Whether to encode non-ASCII in domain names into ASCII according to IDNA."
1768 :group
'message-headers
1769 :link
'(custom-manual "(message)IDNA")
1770 :type
'(choice (const :tag
"Ask" ask
)
1771 (const :tag
"Never" nil
)
1772 (const :tag
"Always" t
)))
1774 (defcustom message-generate-hashcash
(if (executable-find "hashcash") 'opportunistic
)
1775 "Whether to generate X-Hashcash: headers.
1776 If t, always generate hashcash headers. If `opportunistic',
1777 only generate hashcash headers if it can be done without the user
1778 waiting (i.e., only asynchronously).
1780 You must have the \"hashcash\" binary installed, see `hashcash-path'."
1782 :group
'message-headers
1783 :link
'(custom-manual "(message)Mail Headers")
1784 :type
'(choice (const :tag
"Always" t
)
1785 (const :tag
"Never" nil
)
1786 (const :tag
"Opportunistic" opportunistic
)))
1788 ;;; Internal variables.
1790 (defvar message-sending-message
"Sending...")
1791 (defvar message-buffer-list nil
)
1792 (defvar message-this-is-news nil
)
1793 (defvar message-this-is-mail nil
)
1794 (defvar message-draft-article nil
)
1795 (defvar message-mime-part nil
)
1796 (defvar message-posting-charset nil
)
1797 (defvar message-inserted-headers nil
)
1798 (defvar message-inhibit-ecomplete nil
)
1800 ;; Byte-compiler warning
1801 (defvar gnus-active-hashtb
)
1802 (defvar gnus-read-active-file
)
1804 ;;; Regexp matching the delimiter of messages in UNIX mail format
1805 ;;; (UNIX From lines), minus the initial ^. It should be a copy
1806 ;;; of rmail.el's rmail-unix-mail-delimiter.
1807 (defvar message-unix-mail-delimiter
1808 (let ((time-zone-regexp
1809 (concat "\\([A-Z]?[A-Z]?[A-Z][A-Z]\\( DST\\)?"
1810 "\\|[-+]?[0-9][0-9][0-9][0-9]"
1816 ;; Many things can happen to an RFC 822 mailbox before it is put into
1817 ;; a `From' line. The leading phrase can be stripped, e.g.
1818 ;; `Joe <@w.x:joe@y.z>' -> `<@w.x:joe@y.z>'. The <> can be stripped, e.g.
1819 ;; `<@x.y:joe@y.z>' -> `@x.y:joe@y.z'. Everything starting with a CRLF
1820 ;; can be removed, e.g.
1821 ;; From: joe@y.z (Joe K
1823 ;; can yield `From joe@y.z (Joe K Fri Mar 22 08:11:15 1996', and
1826 ;; can yield `From Joe User Fri Mar 22 08:11:15 1996'.
1827 ;; The mailbox can be removed or be replaced by white space, e.g.
1828 ;; From: "Joe User"{space}{tab}
1830 ;; can yield `From {space}{tab} Fri Mar 22 08:11:15 1996',
1831 ;; where {space} and {tab} represent the Ascii space and tab characters.
1832 ;; We want to match the results of any of these manglings.
1833 ;; The following regexp rejects names whose first characters are
1834 ;; obviously bogus, but after that anything goes.
1835 "\\([^\0-\b\n-\r\^?].*\\)?"
1837 ;; The time the message was sent.
1838 "\\([^\0-\r \^?]+\\) +" ; day of the week
1839 "\\([^\0-\r \^?]+\\) +" ; month
1840 "\\([0-3]?[0-9]\\) +" ; day of month
1841 "\\([0-2][0-9]:[0-5][0-9]\\(:[0-6][0-9]\\)?\\) *" ; time of day
1843 ;; Perhaps a time zone, specified by an abbreviation, or by a
1848 " \\([0-9][0-9]+\\) *"
1850 ;; On some systems the time zone can appear after the year, too.
1854 "\\(remote from .*\\)?"
1857 "Regexp matching the delimiter of messages in UNIX mail format.")
1859 (defvar message-unsent-separator
1860 (concat "^ *---+ +Unsent message follows +---+ *$\\|"
1861 "^ *---+ +Returned message +---+ *$\\|"
1862 "^Start of returned message$\\|"
1863 "^ *---+ +Original message +---+ *$\\|"
1864 "^ *--+ +begin message +--+ *$\\|"
1865 "^ *---+ +Original message follows +---+ *$\\|"
1866 "^ *---+ +Undelivered message follows +---+ *$\\|"
1867 "^------ This is a copy of the message, including all the headers. ------ *$\\|"
1868 "^|? *---+ +Message text follows: +---+ *|?$")
1869 "A regexp that matches the separator before the text of a failed message.")
1871 (defvar message-field-fillers
1872 '((To message-fill-field-address
)
1873 (Cc message-fill-field-address
)
1874 (From message-fill-field-address
))
1875 "Alist of header names/filler functions.")
1877 (defvar message-header-format-alist
1892 (References . message-shorten-references
)
1894 "Alist used for formatting headers.")
1896 (defvar message-options nil
1897 "Some saved answers when sending message.")
1898 (make-variable-buffer-local 'message-options
)
1900 (defvar message-send-mail-real-function nil
1901 "Internal send mail function.")
1903 (defvar message-bogus-system-names
"\\`localhost\\.\\|\\.local\\'"
1904 "The regexp of bogus system names.")
1906 (autoload 'gnus-alive-p
"gnus-util")
1907 (autoload 'gnus-delay-article
"gnus-delay")
1908 (autoload 'gnus-extract-address-components
"gnus-util")
1909 (autoload 'gnus-find-method-for-group
"gnus")
1910 (autoload 'gnus-group-decoded-name
"gnus-group")
1911 (autoload 'gnus-group-name-charset
"gnus-group")
1912 (autoload 'gnus-group-name-decode
"gnus-group")
1913 (autoload 'gnus-groups-from-server
"gnus")
1914 (autoload 'gnus-open-server
"gnus-int")
1915 (autoload 'gnus-output-to-mail
"gnus-util")
1916 (autoload 'gnus-output-to-rmail
"gnus-util")
1917 (autoload 'gnus-request-post
"gnus-int")
1918 (autoload 'gnus-server-string
"gnus")
1919 (autoload 'message-setup-toolbar
"messagexmas")
1920 (autoload 'mh-new-draft-name
"mh-comp")
1921 (autoload 'mh-send-letter
"mh-comp")
1922 (autoload 'nndraft-request-associate-buffer
"nndraft")
1923 (autoload 'nndraft-request-expire-articles
"nndraft")
1924 (autoload 'nnvirtual-find-group-art
"nnvirtual")
1925 (autoload 'rmail-msg-is-pruned
"rmail")
1926 (autoload 'rmail-output
"rmailout")
1928 (defun message-kill-all-overlays ()
1929 (mapcar #'delete-overlay
(overlays-in (point-min) (point-max))))
1934 ;;; Utility functions.
1937 (defmacro message-y-or-n-p
(question show
&rest text
)
1938 "Ask QUESTION, displaying remaining args in a temporary buffer if SHOW."
1939 `(message-talkative-question 'y-or-n-p
,question
,show
,@text
))
1941 (defmacro message-delete-line
(&optional n
)
1942 "Delete the current line (and the next N lines)."
1943 `(delete-region (progn (beginning-of-line) (point))
1944 (progn (forward-line ,(or n
1)) (point))))
1946 (defun message-mark-active-p ()
1947 "Non-nil means the mark and region are currently active in this buffer."
1950 (defun message-unquote-tokens (elems)
1951 "Remove double quotes (\") from strings in list ELEMS."
1952 (mapcar (lambda (item)
1953 (while (string-match "^\\(.*\\)\"\\(.*\\)$" item
)
1954 (setq item
(concat (match-string 1 item
)
1955 (match-string 2 item
))))
1959 (defun message-tokenize-header (header &optional separator
)
1960 "Split HEADER into a list of header elements.
1961 SEPARATOR is a string of characters to be used as separators. \",\"
1962 is used by default."
1965 (let ((regexp (format "[%s]+" (or separator
",")))
1967 beg quoted elems paren
)
1969 (mm-enable-multibyte)
1970 (setq beg
(point-min))
1972 (goto-char (point-min))
1977 (cond ((and (> (point) beg
)
1979 (and (looking-at regexp
)
1982 (push (buffer-substring beg
(point)) elems
)
1983 (setq beg
(match-end 0)))
1984 ((eq (char-after) ?
\")
1985 (setq quoted
(not quoted
)))
1986 ((and (eq (char-after) ?\
()
1989 ((and (eq (char-after) ?\
))
1992 (nreverse elems
)))))
1994 (autoload 'nnheader-insert-file-contents
"nnheader")
1996 (defun message-mail-file-mbox-p (file)
1997 "Say whether FILE looks like a Unix mbox file."
1998 (when (and (file-exists-p file
)
1999 (file-readable-p file
)
2000 (file-regular-p file
))
2002 (nnheader-insert-file-contents file
)
2003 (goto-char (point-min))
2004 (looking-at message-unix-mail-delimiter
))))
2006 (defun message-fetch-field (header &optional not-all
)
2007 "The same as `mail-fetch-field', only remove all newlines.
2008 The buffer is expected to be narrowed to just the header of the message;
2009 see `message-narrow-to-headers-or-head'."
2010 (let* ((inhibit-point-motion-hooks t
)
2011 (value (mail-fetch-field header nil
(not not-all
))))
2013 (while (string-match "\n[\t ]+" value
)
2014 (setq value
(replace-match " " t t value
)))
2017 (defun message-field-value (header &optional not-all
)
2018 "The same as `message-fetch-field', only narrow to the headers first."
2021 (message-narrow-to-headers-or-head)
2022 (message-fetch-field header not-all
))))
2024 (defun message-narrow-to-field ()
2025 "Narrow the buffer to the header on the current line."
2027 (while (looking-at "[ \t]")
2033 (if (re-search-forward "^[^ \n\t]" nil t
)
2036 (goto-char (point-min)))
2038 (defun message-add-header (&rest headers
)
2039 "Add the HEADERS to the message header, skipping those already present."
2042 (unless (string-match "^\\([^:]+\\):[ \t]*[^ \t]" (car headers
))
2043 (error "Invalid header `%s'" (car headers
)))
2044 (setq hclean
(match-string 1 (car headers
)))
2046 (message-narrow-to-headers)
2047 (unless (re-search-forward (concat "^" (regexp-quote hclean
) ":") nil t
)
2048 (goto-char (point-max))
2049 (if (string-match "\n$" (car headers
))
2050 (insert (car headers
))
2051 (insert (car headers
) ?
\n)))))
2052 (setq headers
(cdr headers
))))
2054 (defmacro message-with-reply-buffer
(&rest forms
)
2055 "Evaluate FORMS in the reply buffer, if it exists."
2056 `(when (and (bufferp message-reply-buffer
)
2057 (buffer-name message-reply-buffer
))
2058 (with-current-buffer message-reply-buffer
2061 (put 'message-with-reply-buffer
'lisp-indent-function
0)
2062 (put 'message-with-reply-buffer
'edebug-form-spec
'(body))
2064 (defun message-fetch-reply-field (header)
2065 "Fetch field HEADER from the message we're replying to."
2066 (message-with-reply-buffer
2068 (mail-narrow-to-head)
2069 (message-fetch-field header
))))
2071 (defun message-strip-list-identifiers (subject)
2072 "Remove list identifiers in `gnus-list-identifiers' from string SUBJECT."
2073 (require 'gnus-sum
) ; for gnus-list-identifiers
2074 (let ((regexp (if (stringp gnus-list-identifiers
)
2075 gnus-list-identifiers
2076 (mapconcat 'identity gnus-list-identifiers
" *\\|"))))
2077 (if (string-match (concat "\\(\\(\\(Re: +\\)?\\(" regexp
2078 " *\\)\\)+\\(Re: +\\)?\\)") subject
)
2079 (concat (substring subject
0 (match-beginning 1))
2080 (or (match-string 3 subject
)
2081 (match-string 5 subject
))
2086 (defun message-strip-subject-re (subject)
2087 "Remove \"Re:\" from subject lines in string SUBJECT."
2088 (if (string-match message-subject-re-regexp subject
)
2089 (substring subject
(match-end 0))
2092 (defcustom message-replacement-char
"."
2093 "Replacement character used instead of unprintable or not decodable chars."
2094 :group
'message-various
2095 :version
"22.1" ;; Gnus 5.10.9
2096 :type
'(choice string
2100 ;; FIXME: We also should call `message-strip-subject-encoded-words'
2101 ;; when forwarding. Probably in `message-make-forward-subject' and
2102 ;; `message-forward-make-body'.
2104 (defun message-strip-subject-encoded-words (subject)
2105 "Fix non-decodable words in SUBJECT."
2106 ;; Cf. `gnus-simplify-subject-fully'.
2107 (let* ((case-fold-search t
)
2108 (replacement-chars (format "[%s%s%s]"
2109 message-replacement-char
2110 message-replacement-char
2111 message-replacement-char
))
2112 (enc-word-re "=\\?\\([^?]+\\)\\?\\([QB]\\)\\?\\([^?]+\\)\\(\\?=\\)")
2117 (goto-char (point-min))
2118 (when (re-search-forward enc-word-re nil t
)
2119 (setq cs-string
(match-string 1)))))
2120 cs-coding q-or-b word-beg word-end
)
2121 (if (or (not have-marker
) ;; No encoded word found...
2122 ;; ... or double encoding was correct:
2123 (and (stringp cs-string
)
2124 (setq cs-string
(downcase cs-string
))
2125 (mm-coding-system-p (intern cs-string
))
2129 Decoded Subject \"%s\"
2130 contains a valid encoded word. Decode again? "
2132 (setq cs-coding
(intern cs-string
))))))
2136 (goto-char (point-min))
2137 (while (re-search-forward enc-word-re nil t
)
2138 (setq cs-string
(downcase (match-string 1))
2139 q-or-b
(match-string 2)
2140 word-beg
(match-beginning 0)
2141 word-end
(match-end 0))
2143 (if (mm-coding-system-p (intern cs-string
))
2144 (setq cs-coding
(intern cs-string
))
2146 ;; No double encoded subject? => bogus charset.
2151 Decoded Subject \"%s\"
2152 contains an encoded word. The charset `%s' is unknown or invalid.
2153 Hit RET to replace non-decodable characters with \"%s\" or enter replacement
2155 subject cs-string message-replacement-char
)))
2157 (replace-match (concat "=?" (symbol-name cs-coding
)
2160 (goto-char word-beg
)
2161 (re-search-forward "=\\?\\([^?]+\\)\\?\\([QB]\\)\\?" word-end t
)
2164 (if (string-match "\\`Q\\'" q-or-b
)
2167 (message "Replacing non-decodable characters with \"%s\"."
2168 message-replacement-char
)
2169 (while (re-search-forward "\\(=[A-F0-9][A-F0-9]\\)+"
2171 (replace-match message-replacement-char
)))
2173 (message "Replacing non-decodable characters with \"%s\"."
2175 (re-search-forward "[^?]+" word-end t
)
2176 (replace-match replacement-chars
))
2177 (re-search-forward "\\?=")
2178 (replace-match "")))))
2179 (rfc2047-decode-region (point-min) (point-max))
2182 ;;; Start of functions adopted from `message-utils.el'.
2184 (defun message-strip-subject-trailing-was (subject)
2185 "Remove trailing \"(was: <old subject>)\" from SUBJECT lines.
2186 Leading \"Re: \" is not stripped by this function. Use the function
2187 `message-strip-subject-re' for this."
2189 (let ((query message-subject-trailing-was-query
) new
)
2191 (string-match (if (eq query
'ask
)
2192 message-subject-trailing-was-ask-regexp
2193 message-subject-trailing-was-regexp
)
2195 (setq new
(substring subject
0 (match-beginning 0)))
2196 (or (not (eq query
'ask
))
2198 "Strip `(was: <old subject>)' in subject? " t
2200 "Strip `(was: <old subject>)' in subject "
2201 "and use the new one instead?\n\n"
2202 "Current subject is: \"" subject
"\"\n\n"
2203 "New subject would be: \"" new
"\"\n\n"
2204 "See the variable `message-subject-trailing-was-query' "
2205 "to get rid of this query.")))
2209 ;;; Suggested by Jonas Steverud @ www.dtek.chalmers.se/~d4jonas/
2211 (defun message-change-subject (new-subject)
2212 "Ask for NEW-SUBJECT header, append (was: <Old Subject>)."
2215 (read-from-minibuffer "New subject: ")))
2216 (cond ((and (not (or (null new-subject
) ; new subject not empty
2217 (zerop (string-width new-subject
))
2218 (string-match "^[ \t]*$" new-subject
))))
2222 (message-narrow-to-headers)
2223 (message-fetch-field "Subject"))))
2224 (cond ((not old-subject
)
2225 (error "No current subject"))
2228 (regexp-quote new-subject
)
2230 old-subject
)) ; yes, it really is a new subject
2231 ;; delete eventual Re: prefix
2233 (message-strip-subject-re old-subject
))
2234 (message-goto-subject)
2235 (message-delete-line)
2236 (insert (concat "Subject: "
2239 old-subject
")\n")))))))))
2241 (defun message-mark-inserted-region (beg end
&optional verbatim
)
2242 "Mark some region in the current article with enclosing tags.
2243 See `message-mark-insert-begin' and `message-mark-insert-end'.
2244 If VERBATIM, use slrn style verbatim marks (\"#v+\" and \"#v-\")."
2245 (interactive "r\nP")
2247 ;; add to the end of the region first, otherwise end would be invalid
2249 (insert (if verbatim
"#v-\n" message-mark-insert-end
))
2251 (insert (if verbatim
"#v+\n" message-mark-insert-begin
))))
2253 (defun message-mark-insert-file (file &optional verbatim
)
2254 "Insert FILE at point, marking it with enclosing tags.
2255 See `message-mark-insert-begin' and `message-mark-insert-end'.
2256 If VERBATIM, use slrn style verbatim marks (\"#v+\" and \"#v-\")."
2257 (interactive "fFile to insert: \nP")
2258 ;; reverse insertion to get correct result.
2260 (insert (if verbatim
"#v-\n" message-mark-insert-end
))
2262 (insert-file-contents file
)
2264 (insert (if verbatim
"#v+\n" message-mark-insert-begin
))))
2266 (defun message-add-archive-header ()
2267 "Insert \"X-No-Archive: Yes\" in the header and a note in the body.
2268 The note can be customized using `message-archive-note'. When called with a
2269 prefix argument, ask for a text to insert. If you don't want the note in the
2270 body, set `message-archive-note' to nil."
2272 (if current-prefix-arg
2273 (setq message-archive-note
2274 (read-from-minibuffer "Reason for No-Archive: "
2275 (cons message-archive-note
0))))
2277 (if (message-goto-signature)
2278 (re-search-backward message-signature-separator
))
2279 (when message-archive-note
2280 (insert message-archive-note
)
2282 (message-add-header message-archive-header
)
2283 (message-sort-headers)))
2285 (defun message-cross-post-followup-to-header (target-group)
2286 "Mangles FollowUp-To and Newsgroups header to point to TARGET-GROUP.
2287 With prefix-argument just set Follow-Up, don't cross-post."
2289 (list ; Completion based on Gnus
2290 (replace-regexp-in-string
2292 (completing-read "Followup To: "
2293 (if (boundp 'gnus-newsrc-alist
)
2295 nil nil
'("poster" .
0)
2296 (if (boundp 'gnus-group-history
)
2297 'gnus-group-history
)))))
2298 (message-remove-header "Follow[Uu]p-[Tt]o" t
)
2299 (message-goto-newsgroups)
2301 ;; if we already did a crosspost before, kill old target
2302 (if (and message-cross-post-old-target
2304 (regexp-quote (concat "," message-cross-post-old-target
))
2307 ;; unless (followup is to poster or user explicitly asked not
2308 ;; to cross-post, or target-group is already in Newsgroups)
2309 ;; add target-group to Newsgroups line.
2311 ;; def: cross-post, req:no
2312 (and message-cross-post-default
(not current-prefix-arg
))
2313 ;; def: no-cross-post, req:yes
2314 (and (not message-cross-post-default
) current-prefix-arg
))
2315 (not (string-match "poster" target-group
))
2316 (not (string-match (regexp-quote target-group
)
2317 (message-fetch-field "Newsgroups"))))
2319 (insert (concat "," target-group
))))
2320 (end-of-line) ; ensure Followup: comes after Newsgroups:
2321 ;; unless new followup would be identical to Newsgroups line
2322 ;; make a new Followup-To line
2323 (if (not (string-match (concat "^[ \t]*"
2326 (message-fetch-field "Newsgroups")))
2327 (insert (concat "\nFollowup-To: " target-group
)))
2328 (setq message-cross-post-old-target target-group
))
2330 (defun message-cross-post-insert-note (target-group cross-post in-old
2332 "Insert a in message body note about a set Followup or Crosspost.
2333 If there have been previous notes, delete them. TARGET-GROUP specifies the
2334 group to Followup-To. When CROSS-POST is t, insert note about
2335 crossposting. IN-OLD specifies whether TARGET-GROUP is a member of
2336 OLD-GROUPS. OLD-GROUPS lists the old-groups the posting would have
2337 been made to before the user asked for a Crosspost."
2338 ;; start scanning body for previous uses
2339 (message-goto-signature)
2340 (let ((head (re-search-backward
2341 (concat "^" mail-header-separator
)
2342 nil t
))) ; just search in body
2343 (message-goto-signature)
2344 (while (re-search-backward
2345 (concat "^" (regexp-quote message-cross-post-note
) ".*")
2347 (message-delete-line))
2348 (message-goto-signature)
2349 (while (re-search-backward
2350 (concat "^" (regexp-quote message-followup-to-note
) ".*")
2352 (message-delete-line))
2354 (if (message-goto-signature)
2355 (re-search-backward message-signature-separator
))
2358 (string-match "^[ \t]*poster[ \t]*$" target-group
))
2359 (insert (concat message-followup-to-note target-group
"\n"))
2360 (insert (concat message-cross-post-note target-group
"\n")))))
2362 (defun message-cross-post-followup-to (target-group)
2363 "Crossposts message and set Followup-To to TARGET-GROUP.
2364 With prefix-argument just set Follow-Up, don't cross-post."
2366 (list ; Completion based on Gnus
2367 (replace-regexp-in-string
2369 (completing-read "Followup To: "
2370 (if (boundp 'gnus-newsrc-alist
)
2372 nil nil
'("poster" .
0)
2373 (if (boundp 'gnus-group-history
)
2374 'gnus-group-history
)))))
2375 (when (fboundp 'gnus-group-real-name
)
2376 (setq target-group
(gnus-group-real-name target-group
)))
2377 (cond ((not (or (null target-group
) ; new subject not empty
2378 (zerop (string-width target-group
))
2379 (string-match "^[ \t]*$" target-group
)))
2381 (let* ((old-groups (message-fetch-field "Newsgroups"))
2382 (in-old (string-match
2383 (regexp-quote target-group
)
2384 (or old-groups
""))))
2385 ;; check whether target exactly matches old Newsgroups
2386 (cond ((not old-groups
)
2387 (error "No current newsgroup"))
2391 (regexp-quote target-group
)
2394 ;; yes, Newsgroups line must change
2395 (message-cross-post-followup-to-header target-group
)
2396 ;; insert note whether we do cross-post or followup-to
2397 (funcall message-cross-post-note-function
2399 (if (or (and message-cross-post-default
2400 (not current-prefix-arg
))
2401 (and (not message-cross-post-default
)
2402 current-prefix-arg
)) t
)
2403 in-old old-groups
))))))))
2405 ;;; Reduce To: to Cc: or Bcc: header
2407 (defun message-reduce-to-to-cc ()
2408 "Replace contents of To: header with contents of Cc: or Bcc: header."
2411 (save-restriction (message-narrow-to-headers)
2412 (message-fetch-field "cc")))
2414 (if (and (not cc-content
)
2417 (message-narrow-to-headers)
2418 (message-fetch-field "bcc"))))
2423 (message-delete-line)
2424 (insert (concat "To: " cc-content
"\n"))
2426 (message-narrow-to-headers)
2427 (message-remove-header (if bcc
2431 ;;; End of functions adopted from `message-utils.el'.
2433 (defun message-remove-header (header &optional is-regexp first reverse
)
2434 "Remove HEADER in the narrowed buffer.
2435 If IS-REGEXP, HEADER is a regular expression.
2436 If FIRST, only remove the first instance of the header.
2437 If REVERSE, remove headers that doesn't match HEADER.
2438 Return the number of headers removed."
2439 (goto-char (point-min))
2440 (let ((regexp (if is-regexp header
(concat "^" (regexp-quote header
) ":")))
2442 (case-fold-search t
)
2444 (while (and (not (eobp))
2447 (not (looking-at regexp
))
2448 (looking-at regexp
))
2455 ;; There might be a continuation header, so we have to search
2456 ;; until we find a new non-continuation line.
2459 (if (re-search-forward "^[^ \t]" nil t
)
2460 (goto-char (match-beginning 0))
2463 (if (re-search-forward "^[^ \t]" nil t
)
2464 (goto-char (match-beginning 0))
2465 (goto-char (point-max)))))
2468 (defun message-remove-first-header (header)
2469 "Remove the first instance of HEADER if there is more than one."
2471 (regexp (concat "^" (regexp-quote header
) ":")))
2473 (goto-char (point-min))
2474 (while (re-search-forward regexp nil t
)
2477 (message-remove-header header nil t
)
2480 (defun message-narrow-to-headers ()
2481 "Narrow the buffer to the head of the message."
2484 (goto-char (point-min))
2485 (if (re-search-forward
2486 (concat "^" (regexp-quote mail-header-separator
) "\n") nil t
)
2489 (goto-char (point-min)))
2491 (defun message-narrow-to-head-1 ()
2492 "Like `message-narrow-to-head'. Don't widen."
2494 (goto-char (point-min))
2495 (if (search-forward "\n\n" nil
1)
2498 (goto-char (point-min)))
2500 ;; FIXME: clarify difference: message-narrow-to-head,
2501 ;; message-narrow-to-headers-or-head, message-narrow-to-headers
2502 (defun message-narrow-to-head ()
2503 "Narrow the buffer to the head of the message.
2504 Point is left at the beginning of the narrowed-to region."
2506 (message-narrow-to-head-1))
2508 (defun message-narrow-to-headers-or-head ()
2509 "Narrow the buffer to the head of the message."
2512 (goto-char (point-min))
2513 (if (re-search-forward (concat "\\(\n\\)\n\\|^\\("
2514 (regexp-quote mail-header-separator
)
2517 (or (match-end 1) (match-beginning 2))
2519 (goto-char (point-min)))
2521 (defun message-news-p ()
2522 "Say whether the current buffer contains a news message."
2523 (and (not message-this-is-mail
)
2524 (or message-this-is-news
2527 (message-narrow-to-headers)
2528 (and (message-fetch-field "newsgroups")
2529 (not (message-fetch-field "posted-to"))))))))
2531 (defun message-mail-p ()
2532 "Say whether the current buffer contains a mail message."
2533 (and (not message-this-is-news
)
2534 (or message-this-is-mail
2537 (message-narrow-to-headers)
2538 (or (message-fetch-field "to")
2539 (message-fetch-field "cc")
2540 (message-fetch-field "bcc")))))))
2542 (defun message-subscribed-p ()
2543 "Say whether we need to insert a MFT header."
2544 (or message-subscribed-regexps
2545 message-subscribed-addresses
2546 message-subscribed-address-file
2547 message-subscribed-address-functions
))
2549 (defun message-next-header ()
2550 "Go to the beginning of the next header."
2552 (or (eobp) (forward-char 1))
2553 (not (if (re-search-forward "^[^ \t]" nil t
)
2555 (goto-char (point-max)))))
2557 (defun message-sort-headers-1 ()
2558 "Sort the buffer as headers using `message-rank' text props."
2559 (goto-char (point-min))
2562 nil
'message-next-header
2564 (message-next-header)
2568 (or (get-text-property (point) 'message-rank
)
2571 (defun message-sort-headers ()
2572 "Sort the headers of the current message according to `message-header-format-alist'."
2576 (let ((max (1+ (length message-header-format-alist
)))
2578 (message-narrow-to-headers)
2579 (while (re-search-forward "^[^ \n]+:" nil t
)
2581 (match-beginning 0) (1+ (match-beginning 0))
2583 (if (setq rank
(length (memq (assq (intern (buffer-substring
2585 (1- (match-end 0))))
2586 message-header-format-alist
)
2587 message-header-format-alist
)))
2590 (message-sort-headers-1))))
2592 (defun message-kill-address ()
2593 "Kill the address under point."
2595 (let ((start (point)))
2596 (message-skip-to-next-address)
2597 (kill-region start
(if (bolp) (1- (point)) (point)))))
2600 (autoload 'Info-goto-node
"info")
2601 (defvar mml2015-use
)
2603 (defun message-info (&optional arg
)
2604 "Display the Message manual.
2606 Prefixed with one \\[universal-argument], display the Emacs MIME
2607 manual. With two \\[universal-argument]'s, display the EasyPG or
2608 PGG manual, depending on the value of `mml2015-use'."
2610 (info (format "(%s)Top"
2614 ((eq arg
4) 'emacs-mime
)
2615 ((and (not (booleanp arg
))
2629 (defvar message-mode-map nil
)
2631 (unless message-mode-map
2632 (setq message-mode-map
(make-keymap))
2633 (set-keymap-parent message-mode-map text-mode-map
)
2634 (define-key message-mode-map
"\C-c?" 'describe-mode
)
2636 (define-key message-mode-map
"\C-c\C-f\C-t" 'message-goto-to
)
2637 (define-key message-mode-map
"\C-c\C-f\C-o" 'message-goto-from
)
2638 (define-key message-mode-map
"\C-c\C-f\C-b" 'message-goto-bcc
)
2639 (define-key message-mode-map
"\C-c\C-f\C-w" 'message-goto-fcc
)
2640 (define-key message-mode-map
"\C-c\C-f\C-c" 'message-goto-cc
)
2641 (define-key message-mode-map
"\C-c\C-f\C-s" 'message-goto-subject
)
2642 (define-key message-mode-map
"\C-c\C-f\C-r" 'message-goto-reply-to
)
2643 (define-key message-mode-map
"\C-c\C-f\C-n" 'message-goto-newsgroups
)
2644 (define-key message-mode-map
"\C-c\C-f\C-d" 'message-goto-distribution
)
2645 (define-key message-mode-map
"\C-c\C-f\C-f" 'message-goto-followup-to
)
2646 (define-key message-mode-map
"\C-c\C-f\C-m" 'message-goto-mail-followup-to
)
2647 (define-key message-mode-map
"\C-c\C-f\C-k" 'message-goto-keywords
)
2648 (define-key message-mode-map
"\C-c\C-f\C-u" 'message-goto-summary
)
2649 (define-key message-mode-map
"\C-c\C-f\C-i"
2650 'message-insert-or-toggle-importance
)
2651 (define-key message-mode-map
"\C-c\C-f\C-a"
2652 'message-generate-unsubscribed-mail-followup-to
)
2654 ;; modify headers (and insert notes in body)
2655 (define-key message-mode-map
"\C-c\C-fs" 'message-change-subject
)
2657 (define-key message-mode-map
"\C-c\C-fx" 'message-cross-post-followup-to
)
2658 ;; prefix+message-cross-post-followup-to = same w/o cross-post
2659 (define-key message-mode-map
"\C-c\C-ft" 'message-reduce-to-to-cc
)
2660 (define-key message-mode-map
"\C-c\C-fa" 'message-add-archive-header
)
2661 ;; mark inserted text
2662 (define-key message-mode-map
"\C-c\M-m" 'message-mark-inserted-region
)
2663 (define-key message-mode-map
"\C-c\M-f" 'message-mark-insert-file
)
2665 (define-key message-mode-map
"\C-c\C-b" 'message-goto-body
)
2666 (define-key message-mode-map
"\C-c\C-i" 'message-goto-signature
)
2668 (define-key message-mode-map
"\C-c\C-t" 'message-insert-to
)
2669 (define-key message-mode-map
"\C-c\C-fw" 'message-insert-wide-reply
)
2670 (define-key message-mode-map
"\C-c\C-n" 'message-insert-newsgroups
)
2671 (define-key message-mode-map
"\C-c\C-l" 'message-to-list-only
)
2672 (define-key message-mode-map
"\C-c\C-f\C-e" 'message-insert-expires
)
2674 (define-key message-mode-map
"\C-c\C-u" 'message-insert-or-toggle-importance
)
2675 (define-key message-mode-map
"\C-c\M-n"
2676 'message-insert-disposition-notification-to
)
2678 (define-key message-mode-map
"\C-c\C-y" 'message-yank-original
)
2679 (define-key message-mode-map
"\C-c\M-\C-y" 'message-yank-buffer
)
2680 (define-key message-mode-map
"\C-c\C-q" 'message-fill-yanked-message
)
2681 (define-key message-mode-map
"\C-c\C-w" 'message-insert-signature
)
2682 (define-key message-mode-map
"\C-c\M-h" 'message-insert-headers
)
2683 (define-key message-mode-map
"\C-c\C-r" 'message-caesar-buffer-body
)
2684 (define-key message-mode-map
"\C-c\C-o" 'message-sort-headers
)
2685 (define-key message-mode-map
"\C-c\M-r" 'message-rename-buffer
)
2687 (define-key message-mode-map
"\C-c\C-c" 'message-send-and-exit
)
2688 (define-key message-mode-map
"\C-c\C-s" 'message-send
)
2689 (define-key message-mode-map
"\C-c\C-k" 'message-kill-buffer
)
2690 (define-key message-mode-map
"\C-c\C-d" 'message-dont-send
)
2691 (define-key message-mode-map
"\C-c\n" 'gnus-delay-article
)
2693 (define-key message-mode-map
"\C-c\M-k" 'message-kill-address
)
2694 (define-key message-mode-map
"\C-c\C-e" 'message-elide-region
)
2695 (define-key message-mode-map
"\C-c\C-v" 'message-delete-not-region
)
2696 (define-key message-mode-map
"\C-c\C-z" 'message-kill-to-signature
)
2697 (define-key message-mode-map
"\M-\r" 'message-newline-and-reformat
)
2698 (define-key message-mode-map
[remap split-line
] 'message-split-line
)
2700 (define-key message-mode-map
"\C-c\C-a" 'mml-attach-file
)
2702 (define-key message-mode-map
"\C-a" 'message-beginning-of-line
)
2703 (define-key message-mode-map
"\t" 'message-tab
)
2705 (define-key message-mode-map
"\M-n" 'message-display-abbrev
))
2708 message-mode-menu message-mode-map
"Message Menu."
2710 ["Yank Original" message-yank-original message-reply-buffer
]
2711 ["Fill Yanked Message" message-fill-yanked-message t
]
2712 ["Insert Signature" message-insert-signature t
]
2713 ["Caesar (rot13) Message" message-caesar-buffer-body t
]
2714 ["Caesar (rot13) Region" message-caesar-region
(message-mark-active-p)]
2715 ["Elide Region" message-elide-region
2716 :active
(message-mark-active-p)
2717 :help
"Replace text in region with an ellipsis"]
2718 ["Delete Outside Region" message-delete-not-region
2719 :active
(message-mark-active-p)
2720 :help
"Delete all quoted text outside region"]
2721 ["Kill To Signature" message-kill-to-signature t
]
2722 ["Newline and Reformat" message-newline-and-reformat t
]
2723 ["Rename buffer" message-rename-buffer t
]
2724 ["Spellcheck" ispell-message
:help
"Spellcheck this message"]
2726 ["Insert Region Marked" message-mark-inserted-region
2727 :active
(message-mark-active-p) :help
"Mark region with enclosing tags"]
2728 ["Insert File Marked..." message-mark-insert-file
2729 :help
"Insert file at point marked with enclosing tags"]
2731 ["Send Message" message-send-and-exit
:help
"Send this message"]
2732 ["Postpone Message" message-dont-send
2733 :help
"File this draft message and exit"]
2734 ["Send at Specific Time..." gnus-delay-article
2735 :help
"Ask, then arrange to send message at that time"]
2736 ["Kill Message" message-kill-buffer
2737 :help
"Delete this message without sending"]
2739 ["Message manual" message-info
:help
"Display the Message manual"]))
2742 message-mode-field-menu message-mode-map
""
2744 ["To" message-goto-to t
]
2745 ["From" message-goto-from t
]
2746 ["Subject" message-goto-subject t
]
2747 ["Change subject..." message-change-subject t
]
2748 ["Cc" message-goto-cc t
]
2749 ["Bcc" message-goto-bcc t
]
2750 ["Fcc" message-goto-fcc t
]
2751 ["Reply-To" message-goto-reply-to t
]
2752 ["Flag As Important" message-insert-importance-high
2753 :help
"Mark this message as important"]
2754 ["Flag As Unimportant" message-insert-importance-low
2755 :help
"Mark this message as unimportant"]
2757 message-insert-disposition-notification-to
2758 :help
"Request a receipt notification"]
2760 ;; (typical) news stuff
2761 ["Summary" message-goto-summary t
]
2762 ["Keywords" message-goto-keywords t
]
2763 ["Newsgroups" message-goto-newsgroups t
]
2764 ["Fetch Newsgroups" message-insert-newsgroups t
]
2765 ["Followup-To" message-goto-followup-to t
]
2766 ;; ["Followup-To (with note in body)" message-cross-post-followup-to t]
2767 ["Crosspost / Followup-To..." message-cross-post-followup-to t
]
2768 ["Distribution" message-goto-distribution t
]
2769 ["Expires" message-insert-expires t
]
2770 ["X-No-Archive" message-add-archive-header t
]
2772 ;; (typical) mailing-lists stuff
2773 ["Fetch To" message-insert-to
2774 :help
"Insert a To header that points to the author."]
2775 ["Fetch To and Cc" message-insert-wide-reply
2776 :help
"Insert To and Cc headers as if you were doing a wide reply."]
2778 ["Send to list only" message-to-list-only t
]
2779 ["Mail-Followup-To" message-goto-mail-followup-to t
]
2780 ["Unsubscribed list post" message-generate-unsubscribed-mail-followup-to
2781 :help
"Insert a reasonable `Mail-Followup-To:' header."]
2782 ["Reduce To: to Cc:" message-reduce-to-to-cc t
]
2784 ["Sort Headers" message-sort-headers t
]
2785 ["Encode non-ASCII domain names" message-idna-to-ascii-rhs t
]
2786 ;; We hide `message-hidden-headers' by narrowing the buffer.
2787 ["Show Hidden Headers" widen t
]
2788 ["Goto Body" message-goto-body t
]
2789 ["Goto Signature" message-goto-signature t
]))
2791 (defvar message-tool-bar-map nil
)
2793 (defvar facemenu-add-face-function
)
2794 (defvar facemenu-remove-face-function
)
2796 ;;; Forbidden properties
2798 ;; We use `after-change-functions' to keep special text properties
2799 ;; that interfere with the normal function of message mode out of the
2802 (defcustom message-strip-special-text-properties t
2803 "Strip special properties from the message buffer.
2805 Emacs has a number of special text properties which can break message
2806 composing in various ways. If this option is set, message will strip
2807 these properties from the message composition buffer. However, some
2808 packages requires these properties to be present in order to work.
2809 If you use one of these packages, turn this option off, and hope the
2810 message composition doesn't break too bad."
2812 :group
'message-various
2813 :link
'(custom-manual "(message)Various Message Variables")
2816 (defvar message-forbidden-properties
2817 ;; No reason this should be clutter up customize. We make it a
2818 ;; property list (rather than a list of property symbols), to be
2819 ;; directly useful for `remove-text-properties'.
2820 '(field nil read-only nil invisible nil intangible nil
2821 mouse-face nil modification-hooks nil insert-in-front-hooks nil
2822 insert-behind-hooks nil point-entered nil point-left nil
)
2823 ;; Other special properties:
2824 ;; category, face, display: probably doesn't do any harm.
2825 ;; fontified: is used by font-lock.
2826 ;; syntax-table, local-map: I dunno.
2827 "Property list of with properties forbidden in message buffers.
2828 The values of the properties are ignored, only the property names are used.")
2830 (defun message-tamago-not-in-use-p (pos)
2831 "Return t when tamago version 4 is not in use at the cursor position.
2832 Tamago version 4 is a popular input method for writing Japanese text.
2833 It uses the properties `intangible', `invisible', `modification-hooks'
2834 and `read-only' when translating ascii or kana text to kanji text.
2835 These properties are essential to work, so we should never strip them."
2836 (not (and (boundp 'egg-modefull-mode
)
2837 (symbol-value 'egg-modefull-mode
)
2838 (or (memq (get-text-property pos
'intangible
)
2839 '(its-part-1 its-part-2
))
2840 (get-text-property pos
'egg-end
)
2841 (get-text-property pos
'egg-lang
)
2842 (get-text-property pos
'egg-start
)))))
2844 (defsubst message-mail-alias-type-p
(type)
2845 (if (atom message-mail-alias-type
)
2846 (eq message-mail-alias-type type
)
2847 (memq type message-mail-alias-type
)))
2849 (defun message-strip-forbidden-properties (begin end
&optional old-length
)
2850 "Strip forbidden properties between BEGIN and END, ignoring the third arg.
2851 This function is intended to be called from `after-change-functions'.
2852 See also `message-forbidden-properties'."
2853 (when (and (message-mail-alias-type-p 'ecomplete
)
2854 (memq this-command message-self-insert-commands
))
2855 (message-display-abbrev))
2856 (when (and message-strip-special-text-properties
2857 (message-tamago-not-in-use-p begin
))
2858 (let ((buffer-read-only nil
)
2859 (inhibit-read-only t
))
2860 (remove-text-properties begin end message-forbidden-properties
))))
2862 (defvar message-smileys
'(":-)" ":)"
2865 "A list of recognized smiley faces in `message-mode'.")
2867 (defun message--syntax-propertize (beg end
)
2868 "Syntax-propertize certain message text specially."
2869 (let ((citation-regexp (concat "^" message-cite-prefix-regexp
".*$"))
2870 (smiley-regexp (regexp-opt message-smileys
)))
2872 (while (search-forward-regexp citation-regexp
2874 (let ((start (match-beginning 0))
2875 (end (match-end 0)))
2876 (add-text-properties start
(1+ start
)
2877 `(syntax-table ,(string-to-syntax "<")))
2878 (add-text-properties end
(min (1+ end
) (point-max))
2879 `(syntax-table ,(string-to-syntax ">")))))
2881 (while (search-forward-regexp smiley-regexp
2883 (add-text-properties (match-beginning 0) (match-end 0)
2884 `(syntax-table ,(string-to-syntax "."))))))
2887 (define-derived-mode message-mode text-mode
"Message"
2888 "Major mode for editing mail and news to be sent.
2889 Like Text Mode but with these additional commands:\\<message-mode-map>
2890 C-c C-s `message-send' (send the message) C-c C-c `message-send-and-exit'
2891 C-c C-d Postpone sending the message C-c C-k Kill the message
2892 C-c C-f move to a header field (and create it if there isn't):
2893 C-c C-f C-t move to To C-c C-f C-s move to Subject
2894 C-c C-f C-c move to Cc C-c C-f C-b move to Bcc
2895 C-c C-f C-w move to Fcc C-c C-f C-r move to Reply-To
2896 C-c C-f C-u move to Summary C-c C-f C-n move to Newsgroups
2897 C-c C-f C-k move to Keywords C-c C-f C-d move to Distribution
2898 C-c C-f C-o move to From (\"Originator\")
2899 C-c C-f C-f move to Followup-To
2900 C-c C-f C-m move to Mail-Followup-To
2901 C-c C-f C-e move to Expires
2902 C-c C-f C-i cycle through Importance values
2903 C-c C-f s change subject and append \"(was: <Old Subject>)\"
2904 C-c C-f x crossposting with FollowUp-To header and note in body
2905 C-c C-f t replace To: header with contents of Cc: or Bcc:
2906 C-c C-f a Insert X-No-Archive: header and a note in the body
2907 C-c C-t `message-insert-to' (add a To header to a news followup)
2908 C-c C-l `message-to-list-only' (removes all but list address in to/cc)
2909 C-c C-n `message-insert-newsgroups' (add a Newsgroup header to a news reply)
2910 C-c C-b `message-goto-body' (move to beginning of message text).
2911 C-c C-i `message-goto-signature' (move to the beginning of the signature).
2912 C-c C-w `message-insert-signature' (insert `message-signature-file' file).
2913 C-c C-y `message-yank-original' (insert current message, if any).
2914 C-c C-q `message-fill-yanked-message' (fill what was yanked).
2915 C-c C-e `message-elide-region' (elide the text between point and mark).
2916 C-c C-v `message-delete-not-region' (remove the text outside the region).
2917 C-c C-z `message-kill-to-signature' (kill the text up to the signature).
2918 C-c C-r `message-caesar-buffer-body' (rot13 the message body).
2919 C-c C-a `mml-attach-file' (attach a file as MIME).
2920 C-c C-u `message-insert-or-toggle-importance' (insert or cycle importance).
2921 C-c M-n `message-insert-disposition-notification-to' (request receipt).
2922 C-c M-m `message-mark-inserted-region' (mark region with enclosing tags).
2923 C-c M-f `message-mark-insert-file' (insert file marked with enclosing tags).
2924 M-RET `message-newline-and-reformat' (break the line and reformat)."
2925 (set (make-local-variable 'message-reply-buffer
) nil
)
2926 (set (make-local-variable 'message-inserted-headers
) nil
)
2927 (set (make-local-variable 'message-send-actions
) nil
)
2928 (set (make-local-variable 'message-return-action
) nil
)
2929 (set (make-local-variable 'message-exit-actions
) nil
)
2930 (set (make-local-variable 'message-kill-actions
) nil
)
2931 (set (make-local-variable 'message-postpone-actions
) nil
)
2932 (set (make-local-variable 'message-draft-article
) nil
)
2933 (setq buffer-offer-save t
)
2934 (set (make-local-variable 'facemenu-add-face-function
)
2936 (let ((face-fun (cdr (assq face message-face-alist
))))
2938 (funcall face-fun
(point) end
)
2939 (error "Face %s not configured for %s mode" face mode-name
)))
2941 (set (make-local-variable 'facemenu-remove-face-function
) t
)
2942 (set (make-local-variable 'message-reply-headers
) nil
)
2943 (make-local-variable 'message-newsreader
)
2944 (make-local-variable 'message-mailer
)
2945 (make-local-variable 'message-post-method
)
2946 (set (make-local-variable 'message-sent-message-via
) nil
)
2947 (set (make-local-variable 'message-checksum
) nil
)
2948 (set (make-local-variable 'message-mime-part
) 0)
2949 (message-setup-fill-variables)
2950 (when message-fill-column
2951 (setq fill-column message-fill-column
)
2952 (turn-on-auto-fill))
2953 ;; Allow using comment commands to add/remove quoting.
2954 ;; (set (make-local-variable 'comment-start) message-yank-prefix)
2955 (when message-yank-prefix
2956 (set (make-local-variable 'comment-start
) message-yank-prefix
)
2957 (set (make-local-variable 'comment-start-skip
)
2958 (concat "^" (regexp-quote message-yank-prefix
) "[ \t]*")))
2959 (set (make-local-variable 'font-lock-defaults
)
2960 '(message-font-lock-keywords t
))
2961 (if (boundp 'tool-bar-map
)
2962 (set (make-local-variable 'tool-bar-map
) (message-make-tool-bar)))
2963 (easy-menu-add message-mode-menu message-mode-map
)
2964 (easy-menu-add message-mode-field-menu message-mode-map
)
2965 ;; Mmmm... Forbidden properties...
2966 (add-hook 'after-change-functions
'message-strip-forbidden-properties
2968 ;; Allow mail alias things.
2970 ((message-mail-alias-type-p 'abbrev
)
2971 (mail-abbrevs-setup))
2972 ((message-mail-alias-type-p 'ecomplete
)
2974 (add-hook 'completion-at-point-functions
'message-completion-function nil t
)
2975 (unless buffer-file-name
2976 (message-set-auto-save-file-name))
2977 (unless (buffer-base-buffer)
2978 ;; Don't enable multibyte on an indirect buffer. Maybe enabling
2979 ;; multibyte is not necessary at all. -- zsh
2980 (mm-enable-multibyte))
2981 (set (make-local-variable 'indent-tabs-mode
) nil
) ;No tabs for indentation.
2983 ;; Syntactic fontification. Helps `show-paren-mode',
2984 ;; `electric-pair-mode', and C-M-* navigation by syntactically
2985 ;; excluding citations and other artifacts.
2987 (set (make-local-variable 'syntax-propertize-function
) 'message--syntax-propertize
)
2988 (set (make-local-variable 'parse-sexp-ignore-comments
) t
))
2990 (defun message-setup-fill-variables ()
2991 "Setup message fill variables."
2992 (set (make-local-variable 'fill-paragraph-function
)
2993 'message-fill-paragraph
)
2994 (make-local-variable 'paragraph-separate
)
2995 (make-local-variable 'paragraph-start
)
2996 (make-local-variable 'adaptive-fill-regexp
)
2997 (make-local-variable 'adaptive-fill-first-line-regexp
)
2998 (let ((quote-prefix-regexp
2999 ;; User should change message-cite-prefix-regexp if
3000 ;; message-yank-prefix is set to an abnormal value.
3001 (concat "\\(" message-cite-prefix-regexp
"\\)[ \t]*")))
3002 (setq paragraph-start
3004 (regexp-quote mail-header-separator
) "$\\|"
3005 "[ \t]*$\\|" ; blank lines
3006 "-- $\\|" ; signature delimiter
3007 "---+$\\|" ; delimiters for forwarded messages
3008 page-delimiter
"$\\|" ; spoiler warnings
3009 ".*wrote:$\\|" ; attribution lines
3010 quote-prefix-regexp
"$\\|" ; empty lines in quoted text
3012 "<#!*/?\\(multipart\\|part\\|external\\|mml\\|secure\\)"))
3013 (setq paragraph-separate paragraph-start
)
3014 (setq adaptive-fill-regexp
3015 (concat quote-prefix-regexp
"\\|" adaptive-fill-regexp
))
3016 (setq adaptive-fill-first-line-regexp
3017 (concat quote-prefix-regexp
"\\|"
3018 adaptive-fill-first-line-regexp
)))
3019 (setq-local auto-fill-inhibit-regexp nil
)
3020 (setq-local normal-auto-fill-function
'message-do-auto-fill
))
3025 ;;; Message mode commands
3028 ;;; Movement commands
3030 (defun message-goto-to ()
3031 "Move point to the To header."
3034 (message-position-on-field "To"))
3036 (defun message-goto-from ()
3037 "Move point to the From header."
3040 (message-position-on-field "From"))
3042 (defun message-goto-subject ()
3043 "Move point to the Subject header."
3046 (message-position-on-field "Subject"))
3048 (defun message-goto-cc ()
3049 "Move point to the Cc header."
3052 (message-position-on-field "Cc" "To"))
3054 (defun message-goto-bcc ()
3055 "Move point to the Bcc header."
3058 (message-position-on-field "Bcc" "Cc" "To"))
3060 (defun message-goto-fcc ()
3061 "Move point to the Fcc header."
3064 (message-position-on-field "Fcc" "To" "Newsgroups"))
3066 (defun message-goto-reply-to ()
3067 "Move point to the Reply-To header."
3070 (message-position-on-field "Reply-To" "Subject"))
3072 (defun message-goto-newsgroups ()
3073 "Move point to the Newsgroups header."
3076 (message-position-on-field "Newsgroups"))
3078 (defun message-goto-distribution ()
3079 "Move point to the Distribution header."
3082 (message-position-on-field "Distribution"))
3084 (defun message-goto-followup-to ()
3085 "Move point to the Followup-To header."
3088 (message-position-on-field "Followup-To" "Newsgroups"))
3090 (defun message-goto-mail-followup-to ()
3091 "Move point to the Mail-Followup-To header."
3094 (message-position-on-field "Mail-Followup-To" "To"))
3096 (defun message-goto-keywords ()
3097 "Move point to the Keywords header."
3100 (message-position-on-field "Keywords" "Subject"))
3102 (defun message-goto-summary ()
3103 "Move point to the Summary header."
3106 (message-position-on-field "Summary" "Subject"))
3108 (defun message-goto-body ()
3109 "Move point to the beginning of the message body."
3111 (when (and (called-interactively-p 'any
)
3112 (looking-at "[ \t]*\n"))
3115 (message-goto-body-1))
3117 (defun message-goto-body-1 ()
3118 "Go to the body and return point."
3119 (goto-char (point-min))
3120 (or (search-forward (concat "\n" mail-header-separator
"\n") nil t
)
3121 ;; If the message is mangled, find the end of the headers the
3124 ;; Skip past all headers and continuation lines.
3125 (while (looking-at "[^:]+:\\|[\t ]+[^\t ]")
3127 ;; We're now at the first empty line, so perhaps move past it.
3133 (defun message-in-body-p ()
3134 "Return t if point is in the message body."
3137 (message-goto-body-1))))
3139 (defun message-goto-eoh ()
3140 "Move point to the end of the headers."
3145 (defun message-goto-signature ()
3146 "Move point to the beginning of the message signature.
3147 If there is no signature in the article, go to the end and
3151 (goto-char (point-min))
3152 (if (re-search-forward message-signature-separator nil t
)
3154 (goto-char (point-max))
3157 (defun message-generate-unsubscribed-mail-followup-to (&optional include-cc
)
3158 "Insert a reasonable MFT header in a post to an unsubscribed list.
3159 When making original posts to a mailing list you are not subscribed to,
3160 you have to type in a MFT header by hand. The contents, usually, are
3161 the addresses of the list and your own address. This function inserts
3162 such a header automatically. It fetches the contents of the To: header
3163 in the current mail buffer, and appends the current `user-mail-address'.
3165 If the optional argument INCLUDE-CC is non-nil, the addresses in the
3166 Cc: header are also put into the MFT."
3171 (message-narrow-to-headers)
3172 (message-remove-header "Mail-Followup-To")
3173 (setq cc
(and include-cc
(message-fetch-field "Cc")))
3175 (concat (message-fetch-field "To") "," cc
)
3176 (message-fetch-field "To"))))
3177 (message-goto-mail-followup-to)
3178 (insert (concat tos
", " user-mail-address
))))
3182 (defun message-insert-to (&optional force
)
3183 "Insert a To header that points to the author of the article being replied to.
3184 If the original author requested not to be sent mail, don't insert unless the
3185 prefix FORCE is given."
3187 (let* ((mct (message-fetch-reply-field "mail-copies-to"))
3188 (dont (and mct
(or (equal (downcase mct
) "never")
3189 (equal (downcase mct
) "nobody"))))
3190 (to (or (message-fetch-reply-field "mail-reply-to")
3191 (message-fetch-reply-field "reply-to")
3192 (message-fetch-reply-field "from"))))
3196 "Ignoring the user request not to have copies sent via mail"
3197 "Complying with the user request not to have copies sent via mail")))
3198 (when (and force
(not to
))
3199 (error "No mail address in the article"))
3200 (when (and to
(or force
(not dont
)))
3201 (message-carefully-insert-headers (list (cons 'To to
))))))
3203 (defun message-insert-wide-reply ()
3204 "Insert To and Cc headers as if you were doing a wide reply."
3206 (let ((headers (message-with-reply-buffer
3207 (message-get-reply-headers t
))))
3208 (message-carefully-insert-headers headers
)))
3210 (defcustom message-header-synonyms
3213 "List of lists of header synonyms.
3214 E.g., if this list contains a member list with elements `Cc' and `To',
3215 then `message-carefully-insert-headers' will not insert a `To' header
3216 when the message is already `Cc'ed to the recipient."
3218 :group
'message-headers
3219 :link
'(custom-manual "(message)Message Headers")
3220 :type
'(repeat sexp
))
3222 (defun message-carefully-insert-headers (headers)
3223 "Insert the HEADERS, an alist, into the message buffer.
3224 Does not insert the headers when they are already present there
3225 or in the synonym headers, defined by `message-header-synonyms'."
3226 ;; FIXME: Should compare only the address and not the full name. Comparison
3227 ;; should be done case-folded (and with `string=' rather than
3229 ;; (mail-strip-quoted-names "Foo Bar <foo@bar>, bla@fasel (Bla Fasel)")
3230 (dolist (header headers
)
3231 (let* ((header-name (symbol-name (car header
)))
3232 (new-header (cdr header
))
3233 (synonyms (loop for synonym in message-header-synonyms
3234 when
(memq (car header
) synonym
) return synonym
))
3236 (loop for synonym in synonyms
3237 for old-header
= (mail-fetch-field (symbol-name synonym
))
3238 when
(and old-header
(string-match new-header old-header
))
3241 (message "already have `%s' in `%s'" new-header old-header
)
3242 (when (and (message-position-on-field header-name
)
3243 (setq old-header
(mail-fetch-field header-name
))
3244 (not (string-match "\\` *\\'" old-header
)))
3246 (insert new-header
)))))
3248 (defun message-widen-reply ()
3249 "Widen the reply to include maximum recipients."
3252 (and (bufferp message-reply-buffer
)
3253 (buffer-name message-reply-buffer
)
3254 (with-current-buffer message-reply-buffer
3255 (message-get-reply-headers t
)))))
3258 (message-narrow-to-headers)
3259 (dolist (elem follow-to
)
3260 (message-remove-header (symbol-name (car elem
)))
3261 (goto-char (point-min))
3262 (insert (symbol-name (car elem
)) ": "
3263 (cdr elem
) "\n"))))))
3265 (defun message-insert-newsgroups ()
3266 "Insert the Newsgroups header from the article being replied to."
3268 (let ((old-newsgroups (mail-fetch-field "newsgroups"))
3269 (new-newsgroups (message-fetch-reply-field "newsgroups"))
3272 (message-position-on-field "Newsgroups")
3274 ((not new-newsgroups
)
3275 (error "No Newsgroups to insert"))
3276 ((not old-newsgroups
)
3277 (insert new-newsgroups
))
3279 (setq new-newsgroups
(split-string new-newsgroups
"[, ]+")
3280 old-newsgroups
(split-string old-newsgroups
"[, ]+"))
3281 (dolist (group new-newsgroups
)
3282 (unless (member group old-newsgroups
)
3283 (push group insert-newsgroups
)))
3284 (if (null insert-newsgroups
)
3285 (error "Newgroup%s already in the header"
3286 (if (> (length new-newsgroups
) 1)
3288 (when old-newsgroups
3290 (dolist (group insert-newsgroups
)
3294 (insert group
)))))))
3298 ;;; Various commands
3300 (defun message-delete-not-region (beg end
)
3301 "Delete everything in the body of the current message outside of the region."
3306 ;; snarf citation prefix, if appropriate
3307 (unless (eq (point) (progn (beginning-of-line) (point)))
3308 (when (looking-at message-cite-prefix-regexp
)
3309 (setq citeprefix
(match-string 0))))
3311 (delete-region (point) (if (not (message-goto-signature))
3317 (delete-region beg
(progn (message-goto-body)
3321 (insert citeprefix
))))
3322 (when (message-goto-signature)
3325 (defun message-kill-to-signature (&optional arg
)
3326 "Kill all text up to the signature.
3327 If a numeric argument or prefix arg is given, leave that number
3328 of lines before the signature intact."
3332 (let ((point (point)))
3333 (narrow-to-region point
(point-max))
3334 (message-goto-signature)
3336 (if (and arg
(numberp arg
))
3337 (forward-line (- -
1 arg
))
3339 (unless (= point
(point))
3340 (kill-region point
(point))
3344 (defun message-newline-and-reformat (&optional arg not-break
)
3345 "Insert four newlines, and then reformat if inside quoted text.
3346 Prefix arg means justify as well."
3347 (interactive (list (if current-prefix-arg
'full
)))
3348 (unless (message-in-body-p)
3349 (error "This command only works in the body of the message"))
3350 (let (quoted point beg end leading-space bolp fill-paragraph-function
)
3351 (setq point
(point))
3354 (setq bolp
(= beg point
))
3355 ;; Find first line of the paragraph.
3357 (while (and (not (eobp))
3358 (not (looking-at message-cite-prefix-regexp
))
3359 (looking-at paragraph-start
))
3362 (when (looking-at message-cite-prefix-regexp
)
3363 (setq quoted
(match-string 0))
3364 (goto-char (match-end 0))
3365 (looking-at "[ \t]*")
3366 (setq leading-space
(match-string 0)))
3370 (< (- point beg
) (length quoted
)))
3371 ;; break inside the cite prefix.
3377 (while (and (not (eobp))
3378 (not (looking-at paragraph-separate
))
3379 (looking-at message-cite-prefix-regexp
)
3380 (equal quoted
(match-string 0)))
3381 (goto-char (match-end 0))
3382 (looking-at "[ \t]*")
3383 (if (> (length leading-space
) (length (match-string 0)))
3384 (setq leading-space
(match-string 0)))
3388 (while (and (if (bobp) nil
(forward-line -
1) t
)
3389 (not (looking-at paragraph-start
))
3390 (looking-at message-cite-prefix-regexp
)
3391 (equal quoted
(match-string 0)))
3393 (goto-char (match-end 0))
3394 (looking-at "[ \t]*")
3395 (if (> (length leading-space
) (length (match-string 0)))
3396 (setq leading-space
(match-string 0)))))
3397 (while (and (not (eobp))
3398 (not (looking-at paragraph-separate
))
3399 (not (looking-at message-cite-prefix-regexp
)))
3403 (while (and (if (bobp) nil
(forward-line -
1) t
)
3404 (not (looking-at paragraph-start
))
3405 (not (looking-at message-cite-prefix-regexp
)))
3406 (setq beg
(point))))
3409 (narrow-to-region beg end
)
3416 (setq point
(point))
3417 ;; (newline 2) doesn't mark both newline's as hard, so call
3418 ;; newline twice. -jas
3421 (delete-region (point) (re-search-forward "[ \t]*"))
3422 (when (and quoted
(not bolp
))
3423 (insert quoted leading-space
)))
3426 (let* ((adaptive-fill-regexp
3427 (regexp-quote (concat quoted leading-space
)))
3428 (adaptive-fill-first-line-regexp
3429 adaptive-fill-regexp
))
3430 (fill-paragraph arg
))
3431 (fill-paragraph arg
))
3432 (if point
(goto-char point
)))))
3434 (defun message-fill-paragraph (&optional arg
)
3435 "Message specific function to fill a paragraph.
3436 This function is used as the value of `fill-paragraph-function' in
3437 Message buffers and is not meant to be called directly."
3438 (interactive (list (if current-prefix-arg
'full
)))
3439 (if (message-point-in-header-p)
3440 (message-fill-field)
3441 (message-newline-and-reformat arg t
))
3444 (defun message-point-in-header-p ()
3445 "Return t if point is in the header."
3449 (let ((bound (+ (point-at-eol) 1)) case-fold-search
)
3450 (goto-char (point-min))
3451 (not (search-forward (concat "\n" mail-header-separator
"\n")
3454 (defun message-do-auto-fill ()
3455 "Like `do-auto-fill', but don't fill in message header."
3456 (unless (message-point-in-header-p)
3459 (defun message-insert-signature (&optional force
)
3460 "Insert a signature. See documentation for variable `message-signature'."
3461 (interactive (list 0))
3464 ((and (null message-signature
)
3467 (goto-char (point-max))
3468 (not (re-search-backward message-signature-separator nil t
))))
3469 ((and (null message-signature
)
3472 ((functionp message-signature
)
3473 (funcall message-signature
))
3474 ((listp message-signature
)
3475 (eval message-signature
))
3476 (t message-signature
)))
3479 (cond ((stringp signature
)
3481 ((and (eq t signature
) message-signature-file
)
3482 (setq signature-file
3483 (if (and message-signature-directory
3484 ;; don't actually use the signature directory
3485 ;; if message-signature-file contains a path.
3486 (not (file-name-directory
3487 message-signature-file
)))
3488 (expand-file-name message-signature-file
3489 message-signature-directory
)
3490 message-signature-file
))
3491 (file-exists-p signature-file
))))
3493 (goto-char (point-max))
3494 ;; Insert the signature.
3497 (when message-signature-insert-empty-line
3501 (if (eq signature t
)
3502 (insert-file-contents signature-file
)
3504 (goto-char (point-max))
3505 (or (bolp) (newline)))))
3507 (defun message-insert-importance-high ()
3508 "Insert header to mark message as important."
3512 (message-narrow-to-headers)
3513 (message-remove-header "Importance"))
3515 (insert "Importance: high\n")))
3517 (defun message-insert-importance-low ()
3518 "Insert header to mark message as unimportant."
3522 (message-narrow-to-headers)
3523 (message-remove-header "Importance"))
3525 (insert "Importance: low\n")))
3527 (defun message-insert-or-toggle-importance ()
3528 "Insert a \"Importance: high\" header, or cycle through the header values.
3529 The three allowed values according to RFC 1327 are `high', `normal'
3536 (message-narrow-to-headers)
3537 (when (setq cur
(message-fetch-field "Importance"))
3538 (message-remove-header "Importance")
3539 (setq new
(cond ((string= cur
"high")
3541 ((string= cur
"low")
3546 (insert (format "Importance: %s\n" new
)))))
3548 (defun message-insert-disposition-notification-to ()
3549 "Request a disposition notification (return receipt) to this message.
3550 Note that this should not be used in newsgroups."
3554 (message-narrow-to-headers)
3555 (message-remove-header "Disposition-Notification-To"))
3557 (insert (format "Disposition-Notification-To: %s\n"
3558 (or (message-field-value "Reply-to")
3559 (message-field-value "From")
3560 (message-make-from))))))
3562 (defun message-elide-region (b e
)
3563 "Elide the text in the region.
3564 An ellipsis (from `message-elide-ellipsis') will be inserted where the
3567 (let ((lines (count-lines b e
))
3570 (insert (format-spec message-elide-ellipsis
3574 (defvar message-caesar-translation-table nil
)
3576 (defun message-caesar-region (b e
&optional n
)
3577 "Caesar rotate region B to E by N, default 13, for decrypting netnews."
3580 (min (point) (or (mark t
) (point)))
3581 (max (point) (or (mark t
) (point)))
3582 (when current-prefix-arg
3583 (prefix-numeric-value current-prefix-arg
))))
3585 (setq n
(if (numberp n
) (mod n
26) 13)) ;canonize N
3586 (unless (or (zerop n
) ; no action needed for a rot of 0
3587 (= b e
)) ; no region to rotate
3588 ;; We build the table, if necessary.
3589 (when (or (not message-caesar-translation-table
)
3590 (/= (aref message-caesar-translation-table ?a
) (+ ?a n
)))
3591 (setq message-caesar-translation-table
3592 (message-make-caesar-translation-table n
)))
3593 (translate-region b e message-caesar-translation-table
)))
3595 (defun message-make-caesar-translation-table (n)
3596 "Create a rot table with offset N."
3598 (table (make-string 256 0)))
3599 (while (< (incf i
) 256)
3602 (substring table
0 ?A
)
3603 (substring table
(+ ?A n
) (+ ?A n
(- 26 n
)))
3604 (substring table ?A
(+ ?A n
))
3605 (substring table
(+ ?A
26) ?a
)
3606 (substring table
(+ ?a n
) (+ ?a n
(- 26 n
)))
3607 (substring table ?a
(+ ?a n
))
3608 (substring table
(+ ?a
26) 255))))
3610 (defun message-caesar-buffer-body (&optional rotnum wide
)
3611 "Caesar rotate all letters in the current buffer by 13 places.
3612 Used to encode/decode possibly offensive messages (commonly in rec.humor).
3613 With prefix arg, specifies the number of places to rotate each letter forward.
3614 Mail and USENET news headers are not rotated unless WIDE is non-nil."
3615 (interactive (if current-prefix-arg
3616 (list (prefix-numeric-value current-prefix-arg
))
3620 (when (and (not wide
) (message-goto-body))
3621 (narrow-to-region (point) (point-max)))
3622 (message-caesar-region (point-min) (point-max) rotnum
))))
3624 (defun message-pipe-buffer-body (program)
3625 "Pipe the message body in the current buffer through PROGRAM."
3628 (when (message-goto-body)
3629 (narrow-to-region (point) (point-max)))
3630 (shell-command-on-region
3631 (point-min) (point-max) program nil t
))))
3633 (defun message-rename-buffer (&optional enter-string
)
3634 "Rename the *message* buffer to \"*message* RECIPIENT\".
3635 If the function is run with a prefix, it will ask for a new buffer
3636 name, rather than giving an automatic name."
3637 (interactive "Pbuffer name: ")
3640 (goto-char (point-min))
3641 (narrow-to-region (point)
3642 (search-forward mail-header-separator nil
'end
))
3644 (if (message-news-p) (message-fetch-field "Newsgroups")
3645 (message-fetch-field "To"))
3648 (if (string-match "," mail-to
)
3649 (concat (substring mail-to
0 (match-beginning 0)) ", ...")
3651 (name-default (concat "*message* " mail-trimmed-to
))
3652 (name (if enter-string
3653 (read-string "New buffer name: " name-default
)
3655 (rename-buffer name t
)))))
3657 (defun message-fill-yanked-message (&optional justifyp
)
3658 "Fill the paragraphs of a message yanked into this one.
3659 Numeric argument means justify as well."
3662 (goto-char (point-min))
3663 (search-forward (concat "\n" mail-header-separator
"\n") nil t
)
3664 (let ((fill-prefix message-yank-prefix
))
3665 (fill-individual-paragraphs (point) (point-max) justifyp
))))
3667 (defun message-indent-citation (&optional start end yank-only
)
3668 "Modify text just inserted from a message to be cited.
3669 The inserted text should be the region.
3670 When this function returns, the region is again around the modified text.
3672 Normally, indent each nonblank line `message-indentation-spaces' spaces.
3673 However, if `message-yank-prefix' is non-nil, insert that prefix on each line."
3674 (unless start
(setq start
(point)))
3676 ;; Remove unwanted headers.
3677 (when message-ignored-cited-headers
3682 (if (search-forward "\n\n" nil t
)
3685 (message-remove-header message-ignored-cited-headers t
)
3686 (when (= (point-min) (point-max))
3687 (setq all-removed t
))
3688 (goto-char (point-max)))
3692 ;; Delete blank lines at the start of the buffer.
3693 (while (and (point-min)
3696 (message-delete-line))
3697 ;; Delete blank lines at the end of the buffer.
3698 (goto-char (point-max))
3699 (unless (eq (preceding-char) ?
\n)
3701 (while (and (zerop (forward-line -
1))
3703 (message-delete-line)))
3704 ;; Do the indentation.
3705 (if (null message-yank-prefix
)
3706 (indent-rigidly start
(or end
(mark t
)) message-indentation-spaces
)
3709 (while (< (point) (or end
(mark t
)))
3710 (cond ((looking-at ">")
3711 (insert message-yank-cited-prefix
))
3713 (insert message-yank-empty-prefix
))
3715 (insert message-yank-prefix
)))
3719 (defun message-remove-blank-cited-lines (&optional remove
)
3720 "Remove cited lines containing only blanks.
3721 If REMOVE is non-nil, remove newlines, too.
3723 To use this automatically, you may add this function to
3724 `gnus-message-setup-hook'."
3726 (let ((citexp (concat "^\\("
3727 (concat message-yank-cited-prefix
"\\|")
3730 (message "Removing `%s'" citexp
)
3733 (while (re-search-forward citexp nil t
)
3734 (replace-match (if remove
"" "\n"))))))
3736 (defun message--yank-original-internal (arg)
3737 (let ((modified (buffer-modified-p))
3739 (when (and message-reply-buffer
3740 message-cite-function
)
3741 (when (equal message-cite-reply-position
'above
)
3744 (buffer-substring (message-goto-body)
3746 (delete-region (message-goto-body) (point-max))))
3747 (if (bufferp message-reply-buffer
)
3748 (delete-windows-on message-reply-buffer t
))
3749 (push-mark (save-excursion
3751 ((bufferp message-reply-buffer
)
3752 (insert-buffer-substring message-reply-buffer
))
3753 ((and (consp message-reply-buffer
)
3754 (functionp (car message-reply-buffer
)))
3755 (apply (car message-reply-buffer
)
3756 (cdr message-reply-buffer
))))
3761 (funcall message-cite-function
)
3762 (unless (eq (char-before (mark t
)) ?
\n)
3764 (goto-char (mark t
))
3765 (insert-before-markers ?
\n)
3767 (case message-cite-reply-position
3771 (insert (if (bolp) "\n" "\n\n"))
3772 (message-goto-body))
3774 (message-goto-signature)))
3775 ;; Add a `message-setup-very-last-hook' here?
3776 ;; Add `gnus-article-highlight-citation' here?
3778 (setq message-checksum
(message-checksum))))))
3780 (defun message-yank-original (&optional arg
)
3781 "Insert the message being replied to, if any.
3782 Puts point before the text and mark after.
3783 Normally indents each nonblank line ARG spaces (default 3). However,
3784 if `message-yank-prefix' is non-nil, insert that prefix on each line.
3786 This function uses `message-cite-function' to do the actual citing.
3788 Just \\[universal-argument] as argument means don't indent, insert no
3789 prefix, and don't delete any headers."
3791 ;; eval the let forms contained in message-cite-style
3793 `(let ,(if (symbolp message-cite-style
)
3794 (symbol-value message-cite-style
)
3796 (message--yank-original-internal ',arg
))))
3798 (defun message-yank-buffer (buffer)
3799 "Insert BUFFER into the current buffer and quote it."
3800 (interactive "bYank buffer: ")
3801 (let ((message-reply-buffer (get-buffer buffer
)))
3802 (save-window-excursion
3803 (message-yank-original))))
3805 (defun message-buffers ()
3806 "Return a list of active message buffers."
3808 (save-current-buffer
3809 (dolist (buffer (buffer-list t
))
3811 (when (and (derived-mode-p 'message-mode
)
3812 (null message-sent-message-via
))
3813 (push (buffer-name buffer
) buffers
))))
3814 (nreverse buffers
)))
3816 (defun message-cite-original-1 (strip-signature)
3817 "Cite an original message.
3818 If STRIP-SIGNATURE is non-nil, strips off the signature from the
3821 This function uses `mail-citation-hook' if that is non-nil."
3822 (if (and (boundp 'mail-citation-hook
)
3824 (run-hooks 'mail-citation-hook
)
3825 (let* ((start (point))
3829 (when message-indent-citation-function
3830 (if (listp message-indent-citation-function
)
3831 message-indent-citation-function
3832 (list message-indent-citation-function
))))
3833 ;; This function may be called by `gnus-summary-yank-message' and
3834 ;; may insert a different article from the original. So, we will
3835 ;; modify the value of `message-reply-headers' with that article.
3836 (message-reply-headers
3838 (narrow-to-region start end
)
3839 (message-narrow-to-head-1)
3840 (setq x-no-archive
(message-fetch-field "x-no-archive"))
3842 (or (message-fetch-field "subject") "none")
3843 (or (message-fetch-field "from") "nobody")
3844 (message-fetch-field "date")
3845 (message-fetch-field "message-id" t
)
3846 (message-fetch-field "references")
3848 (mml-quote-region start end
)
3849 (when strip-signature
3853 (when (re-search-backward message-signature-separator start t
)
3854 ;; Also peel off any blank lines before the signature.
3856 (while (looking-at "^[ \t]*$")
3859 (delete-region (point) end
)
3860 (unless (search-backward "\n\n" start t
)
3861 ;; Insert a blank line if it is peeled off.
3864 (mapc 'funcall functions
)
3865 (when message-citation-line-function
3868 (funcall message-citation-line-function
))
3869 (when (and x-no-archive
3870 (not message-cite-articles-with-x-no-archive
)
3871 (string-match "yes" x-no-archive
))
3873 (delete-region (point) (mark t
))
3874 (insert "> [Quoted text removed due to X-No-Archive]\n")
3876 (forward-line -
1)))))
3878 (defun message-cite-original ()
3879 "Cite function in the standard Message manner."
3880 (message-cite-original-1 nil
))
3882 (autoload 'format-spec
"format-spec")
3883 (autoload 'gnus-date-get-time
"gnus-util")
3885 (defun message-insert-formatted-citation-line (&optional from date tz
)
3886 "Function that inserts a formatted citation line.
3887 The optional FROM, and DATE are strings containing the contents of
3888 the From header and the Date header respectively.
3890 The optional TZ is omitted or nil for Emacs local time, t for
3891 Universal Time, `wall' for system wall clock time, or a string as
3892 in the TZ environment variable. It can also be a list (as from
3893 `current-time-zone') or an integer (as from `decode-time')
3894 applied without consideration for daylight saving time.
3896 See `message-citation-line-format'."
3897 ;; The optional args are for testing/debugging. They will disappear later.
3899 ;; (with-temp-buffer
3900 ;; (message-insert-formatted-citation-line
3901 ;; "John Doe <john.doe@example.invalid>"
3902 ;; (message-make-date))
3904 (when (or message-reply-headers
(and from date
))
3906 (setq from
(mail-header-from message-reply-headers
)))
3907 (let* ((data (condition-case ()
3908 (funcall (if (boundp 'gnus-extract-address-components
)
3909 gnus-extract-address-components
3910 'mail-extract-address-components
)
3916 (net (car (cdr data
)))
3917 (name-or-net (or (car data
)
3918 (car (cdr data
)) from
))
3920 (when (string-match "%[^fnNFL]" message-citation-line-format
)
3921 (cond ((numberp (car-safe date
)) date
) ;; backward compatibility
3922 (date (gnus-date-get-time date
))
3925 (setq date
(mail-header-date message-reply-headers
)))))))
3927 (when (stringp date
)
3928 (nth 8 (parse-time-string date
)))))
3931 (when (stringp name
)
3932 ;; Guess first name and last name:
3937 (if (string-match "\\`\\(\\w\\|[-.]\\)+\\'"
3941 (split-string name
"[ \t]+"))))
3942 (count (length names
)))
3944 (setq fname
(car names
)
3946 ((or (= count
2) (= count
3))
3947 (setq fname
(car names
)
3948 lname
(mapconcat 'identity
(cdr names
) " ")))
3950 (setq fname
(mapconcat 'identity
3951 (butlast names
(- count
2))
3953 lname
(mapconcat 'identity
3956 (when (string-match "\\(.*\\),\\'" fname
)
3957 (let ((newlname (match-string 1 fname
)))
3958 (setq fname lname lname newlname
)))))
3959 ;; The following letters are not used in `format-time-string':
3960 (push ?E lst
) (push "<E>" lst
)
3961 (push ?F lst
) (push (or fname name-or-net
) lst
)
3962 ;; We might want to use "" instead of "<X>" later.
3963 (push ?J lst
) (push "<J>" lst
)
3964 (push ?K lst
) (push "<K>" lst
)
3965 (push ?L lst
) (push lname lst
)
3966 (push ?N lst
) (push name-or-net lst
)
3967 (push ?O lst
) (push "<O>" lst
)
3968 (push ?P lst
) (push "<P>" lst
)
3969 (push ?Q lst
) (push "<Q>" lst
)
3970 (push ?f lst
) (push from lst
)
3971 (push ?i lst
) (push "<i>" lst
)
3972 (push ?n lst
) (push net lst
)
3973 (push ?o lst
) (push "<o>" lst
)
3974 (push ?q lst
) (push "<q>" lst
)
3975 (push ?t lst
) (push "<t>" lst
)
3976 (push ?v lst
) (push "<v>" lst
)
3977 ;; Delegate the rest to `format-time-string':
3979 (when (and (not (memq i lst
))
3984 (push (condition-case nil
3985 (format-time-string (format "%%%c" i
) time tz
)
3986 (error (format ">%c<" i
)))
3990 (spec (apply 'format-spec-make flist
)))
3991 (insert (format-spec message-citation-line-format spec
)))
3994 (defun message-cite-original-without-signature ()
3995 "Cite function in the standard Message manner.
3996 This function strips off the signature from the original message."
3997 (message-cite-original-1 t
))
3999 (defun message-insert-citation-line ()
4000 "Insert a simple citation line."
4001 (when message-reply-headers
4002 (insert (mail-header-from message-reply-headers
) " writes:")
4006 (defun message-position-on-field (header &rest afters
)
4007 (let ((case-fold-search t
))
4010 (goto-char (point-min))
4013 (concat "^" (regexp-quote mail-header-separator
) "$"))
4014 (match-beginning 0)))
4015 (goto-char (point-min))
4016 (if (re-search-forward (concat "^" (regexp-quote header
) ":") nil t
)
4018 (re-search-forward "^[^ \t]" nil
'move
)
4020 (skip-chars-backward "\n")
4023 (not (re-search-forward
4024 (concat "^" (regexp-quote (car afters
)) ":")
4028 (re-search-forward "^[^ \t]" nil
'move
)
4029 (beginning-of-line))
4030 (insert header
": \n")
4037 ;;; Sending messages
4040 (defun message-send-and-exit (&optional arg
)
4041 "Send message like `message-send', then, if no errors, exit from mail buffer.
4042 The usage of ARG is defined by the instance that called Message.
4043 It should typically alter the sending method in some way or other."
4045 (let ((buf (current-buffer))
4046 (actions message-exit-actions
))
4047 (when (and (message-send arg
)
4050 (if message-kill-buffer-on-exit
4052 (message-do-actions actions
)
4055 (defun message-dont-send ()
4056 "Don't send the message you have been editing.
4057 Instead, just auto-save the buffer and then bury it."
4059 (set-buffer-modified-p t
)
4061 (let ((actions message-postpone-actions
))
4062 (message-bury (current-buffer))
4063 (message-do-actions actions
)))
4065 (defun message-kill-buffer ()
4066 "Kill the current buffer."
4068 (when (or (not (buffer-modified-p))
4069 (not message-kill-buffer-query
)
4070 (yes-or-no-p "Message modified; kill anyway? "))
4071 (let ((actions message-kill-actions
)
4072 (draft-article message-draft-article
)
4073 (auto-save-file-name buffer-auto-save-file-name
)
4074 (file-name buffer-file-name
)
4075 (modified (buffer-modified-p)))
4076 (setq buffer-file-name nil
)
4077 (kill-buffer (current-buffer))
4078 (when (and (or (and auto-save-file-name
4079 (file-exists-p auto-save-file-name
))
4081 (file-exists-p file-name
)))
4083 ;; If the message buffer has lived in a dedicated window,
4084 ;; `kill-buffer' has killed the frame. Thus the
4085 ;; `yes-or-no-p' may show up in a lowered frame. Make sure
4086 ;; that the user can see the question by raising the
4089 (yes-or-no-p (format "Remove the backup file%s? "
4090 (if modified
" too" "")))))
4092 (delete-file auto-save-file-name
))
4093 (let ((message-draft-article draft-article
))
4094 (message-disassociate-draft)))
4095 (message-do-actions actions
))))
4097 (defun message-bury (buffer)
4098 "Bury this mail BUFFER."
4099 ;; Note that this is not quite the same as (bury-buffer buffer),
4100 ;; since bury-buffer does extra stuff with a nil argument.
4101 ;; Eg http://lists.gnu.org/archive/html/emacs-devel/2014-01/msg00539.html
4102 (with-current-buffer buffer
(bury-buffer))
4103 (if message-return-action
4104 (apply (car message-return-action
) (cdr message-return-action
))))
4106 (autoload 'mml-secure-bcc-is-safe
"mml-sec")
4108 (defun message-send (&optional arg
)
4109 "Send the message in the current buffer.
4110 If `message-interactive' is non-nil, wait for success indication or
4111 error messages, and inform user.
4112 Otherwise any failure is reported in a message back to the user from
4114 The usage of ARG is defined by the instance that called Message.
4115 It should typically alter the sending method in some way or other."
4117 ;; Make it possible to undo the coming changes.
4119 (let ((inhibit-read-only t
))
4120 (put-text-property (point-min) (point-max) 'read-only nil
))
4121 (message-fix-before-sending)
4122 (run-hooks 'message-send-hook
)
4123 (mml-secure-bcc-is-safe)
4124 (when message-confirm-send
4125 (or (y-or-n-p "Send message? ")
4127 (message message-sending-message
)
4128 (let ((alist message-send-method-alist
)
4130 elem sent dont-barf-on-no-method
4131 (message-options message-options
))
4132 (message-options-set-recipient)
4134 (setq elem
(pop alist
)))
4135 (when (funcall (cadr elem
))
4136 (when (and (or (not (memq (car elem
)
4137 message-sent-message-via
))
4138 (message-fetch-field "supersedes")
4139 (if (or (message-gnksa-enable-p 'multiple-copies
)
4140 (not (eq (car elem
) 'news
)))
4143 "Already sent message via %s; resend? "
4145 (error "Denied posting -- multiple copies")))
4146 (setq success
(funcall (caddr elem
) arg
)))
4150 (let ((fcc (message-fetch-field "Fcc"))
4151 (gcc (message-fetch-field "Gcc")))
4153 (or (eq message-allow-no-recipients
'always
)
4154 (and (not (eq message-allow-no-recipients
'never
))
4155 (setq dont-barf-on-no-method
4157 (format "No receiver, perform %s anyway? "
4158 (cond ((and fcc gcc
) "Fcc and Gcc")
4161 (error "No methods specified to send by"))
4162 (when (or dont-barf-on-no-method
4166 (run-hooks 'message-sent-hook
))
4167 (message "Sending...done")
4168 ;; Do ecomplete address snarfing.
4169 (when (and (message-mail-alias-type-p 'ecomplete
)
4170 (not message-inhibit-ecomplete
))
4171 (message-put-addresses-in-ecomplete))
4172 ;; Mark the buffer as unmodified and delete auto-save.
4173 (set-buffer-modified-p nil
)
4174 (delete-auto-save-file-if-necessary t
)
4175 (message-disassociate-draft)
4176 ;; Delete other mail buffers and stuff.
4177 (message-do-send-housekeeping)
4178 (message-do-actions message-send-actions
)
4182 (defun message-send-via-mail (arg)
4183 "Send the current message via mail."
4184 (message-send-mail arg
))
4186 (defun message-send-via-news (arg)
4187 "Send the current message via news."
4188 (funcall message-send-news-function arg
))
4190 (defmacro message-check
(type &rest forms
)
4191 "Eval FORMS if TYPE is to be checked."
4192 `(or (message-check-element ,type
)
4196 (put 'message-check
'lisp-indent-function
1)
4197 (put 'message-check
'edebug-form-spec
'(form body
))
4199 (defun message-text-with-property (prop &optional start end reverse
)
4200 "Return a list of start and end positions where the text has PROP.
4201 START and END bound the search, they default to `point-min' and
4202 `point-max' respectively. If REVERSE is non-nil, find text which does
4205 (setq start
(point-min)))
4207 (setq end
(point-max)))
4211 (setq start
(text-property-any start end prop nil
)))
4212 (setq next
(next-single-property-change start prop nil end
))
4213 (push (cons start
(or next end
)) regions
)
4216 (or (get-text-property start prop
)
4217 (and (setq start
(next-single-property-change
4218 start prop nil end
))
4219 (get-text-property start prop
))))
4220 (setq next
(text-property-any start end prop nil
))
4221 (push (cons start
(or next end
)) regions
)
4223 (nreverse regions
)))
4225 (defcustom message-bogus-addresses
4226 '("noreply" "nospam" "invalid" "@.*@" "[^[:ascii:]].*@" "[ \t]")
4227 "List of regexps of potentially bogus mail addresses.
4228 See `message-check-recipients' how to setup checking.
4230 This list should make it possible to catch typos or warn about
4231 spam-trap addresses. It doesn't aim to verify strict RFC
4233 :version
"26.1" ; @@ -> @.*@
4234 :group
'message-headers
4236 (const :tag
"None" nil
)
4242 (const :tag
"duplicate @" "@.*@")
4243 (const :tag
"non-ascii local part" "[^[:ascii:]].*@")
4244 (const :tag
"`_' in domain part" "@.*_")
4245 (const :tag
"whitespace" "[ \t]"))
4250 (defun message-fix-before-sending ()
4251 "Do various things to make the message nice before sending it."
4252 ;; Make sure there's a newline at the end of the message.
4253 (goto-char (point-max))
4256 ;; Make the hidden headers visible.
4258 ;; Sort headers before sending the message.
4259 (message-sort-headers)
4260 ;; Make invisible text visible.
4261 ;; It doesn't seem as if this is useful, since the invisible property
4262 ;; is clobbered by an after-change hook anyhow.
4263 (message-check 'invisible-text
4264 (let ((regions (message-text-with-property 'invisible
))
4268 (setq from
(caar regions
)
4270 regions
(cdr regions
))
4271 (put-text-property from to
'invisible nil
)
4272 (overlay-put (make-overlay from to
) 'face
'highlight
))
4273 (unless (yes-or-no-p
4274 "Invisible text found and made visible; continue sending? ")
4275 (error "Invisible text found and made visible")))))
4276 (message-check 'illegible-text
4277 (let (char found choice nul-chars
)
4279 (setq nul-chars
(save-excursion
4280 (search-forward "\000" nil t
)))
4282 (skip-chars-forward mm-7bit-chars
)
4283 (when (get-text-property (point) 'no-illegible-text
)
4284 ;; There is a signed or encrypted raw message part
4285 ;; that is considered to be safe.
4286 (goto-char (or (next-single-property-change
4287 (point) 'no-illegible-text
)
4289 (setq char
(char-after)))
4290 (when (or (< char
128)
4291 (and (mm-multibyte-p)
4292 (memq (char-charset char
)
4293 '(eight-bit-control eight-bit-graphic
4294 ;; Emacs 23, Bug#1770:
4297 (not (get-text-property
4298 (point) 'untranslated-utf-8
))))
4299 (overlay-put (make-overlay (point) (1+ (point))) 'face
'highlight
)
4305 (read-multiple-choice
4307 "NUL characters found, which may cause problems. Continue sending?"
4308 "Non-printable characters found. Continue sending?")
4309 `((?d
"delete" "Remove non-printable characters and send")
4312 "Replace non-printable characters with \"%s\" and send"
4313 message-replacement-char
))
4314 (?s
"send" "Send as is without removing anything")
4315 (?e
"edit" "Continue editing")))))
4317 (error "Non-printable characters"))
4319 (skip-chars-forward mm-7bit-chars
)
4321 (when (let ((char (char-after)))
4323 (and (mm-multibyte-p)
4324 ;; FIXME: Wrong for Emacs 23 (unicode) and for
4325 ;; things like undecodable utf-8 (in Emacs 21?).
4326 ;; Should at least use find-coding-systems-region.
4328 (memq (char-charset char
)
4329 '(eight-bit-control eight-bit-graphic
4330 ;; Emacs 23, Bug#1770:
4333 (not (get-text-property
4334 (point) 'untranslated-utf-8
)))))
4336 (message-kill-all-overlays)
4338 (when (eq choice ?r
)
4339 (insert message-replacement-char
))))
4341 (skip-chars-forward mm-7bit-chars
)))))
4342 (message-check 'bogus-recipient
4343 ;; Warn before sending a mail to an invalid address.
4344 (message-check-recipients)))
4346 (defun message-bogus-recipient-p (recipients)
4347 "Check if a mail address in RECIPIENTS looks bogus.
4349 RECIPIENTS is a mail header. Return a list of potentially bogus
4350 addresses. If none is found, return nil.
4352 An address might be bogus if if there's a matching entry in
4353 `message-bogus-addresses'."
4354 ;; FIXME: How about "foo@subdomain", when the MTA adds ".domain.tld"?
4356 (mapc (lambda (address)
4357 (setq address
(or (cadr address
) ""))
4358 (when (or (string= "" address
)
4359 (and message-bogus-addresses
4361 (if (listp message-bogus-addresses
)
4362 (mapconcat 'identity
4363 message-bogus-addresses
4365 message-bogus-addresses
)))
4366 (string-match re address
))))
4367 (push address found
)))
4368 (mail-extract-address-components recipients t
))
4371 (defun message-check-recipients ()
4372 "Warn before composing or sending a mail to an invalid address.
4374 This function could be useful in `message-setup-hook'."
4377 (message-narrow-to-headers)
4378 (dolist (hdr '("To" "Cc" "Bcc"))
4379 (let ((addr (message-fetch-field hdr
)))
4380 (when (stringp addr
)
4381 (dolist (bog (message-bogus-recipient-p addr
))
4385 "Address `%s'%s might be bogus. Continue? "
4387 ;; If the encoded version of the email address
4388 ;; is different from the unencoded version,
4389 ;; then we likely have invisible characters or
4390 ;; the like. Display the encoded version,
4392 (let ((encoded (rfc2047-encode-string bog
)))
4393 (if (string= encoded bog
)
4395 (format " (%s)" encoded
))))))
4396 (error "Bogus address"))))))))
4398 (custom-add-option 'message-setup-hook
'message-check-recipients
)
4400 (defun message-add-action (action &rest types
)
4401 "Add ACTION to be performed when doing an exit of type TYPES."
4403 (add-to-list (intern (format "message-%s-actions" (pop types
)))
4406 (defun message-delete-action (action &rest types
)
4407 "Delete ACTION from lists of actions performed when doing an exit of type TYPES."
4410 (set (setq var
(intern (format "message-%s-actions" (pop types
))))
4411 (delq action
(symbol-value var
))))))
4413 (defun message-do-actions (actions)
4414 "Perform all actions in ACTIONS."
4415 ;; Now perform actions on successful sending.
4416 (dolist (action actions
)
4419 ;; A simple function.
4422 ;; Something to be evalled.
4426 (defun message-send-mail-partially ()
4427 "Send mail as message/partial."
4428 ;; replace the header delimiter with a blank line
4429 (goto-char (point-min))
4431 (concat "^" (regexp-quote mail-header-separator
) "\n"))
4432 (replace-match "\n")
4433 (run-hooks 'message-send-mail-hook
)
4434 (let ((p (goto-char (point-min)))
4435 (tembuf (message-generate-new-buffer-clone-locals " message temp"))
4436 (curbuf (current-buffer))
4437 (id (message-make-message-id)) (n 1)
4440 (if (< (point-max) (+ p message-send-mail-partially-limit
))
4441 (goto-char (point-max))
4442 (goto-char (+ p message-send-mail-partially-limit
))
4444 (if (<= (point) p
) (forward-line 1))) ;; In case of bad message.
4447 (setq total
(length plist
))
4448 (push (point-max) plist
)
4449 (setq plist
(nreverse plist
))
4452 (setq p
(pop plist
))
4455 (copy-to-buffer tembuf p
(car plist
))
4457 (goto-char (point-min))
4460 (goto-char (point-min))
4461 (narrow-to-region (point) (point))
4464 (setq header
(buffer-substring (point-min) (point)))
4465 (goto-char (point-min))
4466 (narrow-to-region (point) (point))
4468 (message-remove-header "Mime-Version")
4469 (message-remove-header "Content-Type")
4470 (message-remove-header "Content-Transfer-Encoding")
4471 (message-remove-header "Message-ID")
4472 (message-remove-header "Lines")
4473 (goto-char (point-max))
4474 (insert "Mime-Version: 1.0\n")
4475 (setq header
(buffer-string)))
4476 (goto-char (point-max))
4477 (insert (format "Content-Type: message/partial; id=\"%s\"; number=%d; total=%d\n\n"
4480 (let ((mail-header-separator ""))
4481 (when (memq 'Message-ID message-required-mail-headers
)
4482 (insert "Message-ID: " (message-make-message-id) "\n"))
4483 (when (memq 'Lines message-required-mail-headers
)
4484 (insert "Lines: " (message-make-lines) "\n"))
4485 (message-goto-subject)
4487 (insert (format " (%d/%d)" n total
))
4489 (if message-send-mail-real-function
4490 (funcall message-send-mail-real-function
)
4491 (message-multi-smtp-send-mail)))
4493 (setq p
(pop plist
))
4495 (kill-buffer tembuf
))))
4497 (declare-function hashcash-wait-async
"hashcash" (&optional buffer
))
4499 (defun message-send-mail (&optional _
)
4500 (require 'mail-utils
)
4501 (let* ((tembuf (message-generate-new-buffer-clone-locals " message temp"))
4502 (case-fold-search nil
)
4503 (news (message-news-p))
4504 (mailbuf (current-buffer))
4505 (message-this-is-mail t
)
4506 ;; gnus-setup-posting-charset is autoloaded in mml.el (FIXME
4507 ;; maybe it should not be), which this file requires. Hence
4508 ;; the fboundp test is always true. Loading it from gnus-msg
4509 ;; loads many Gnus files (Bug#5642). If
4510 ;; gnus-group-posting-charset-alist hasn't been customized,
4511 ;; this is just going to return nil anyway. FIXME it would
4512 ;; be good to improve this further, because even if g-g-p-c-a
4513 ;; has been customized, that is likely to just be for news.
4514 ;; Eg either move the definition from gnus-msg, or separate out
4515 ;; the mail and news parts.
4516 (message-posting-charset
4517 (if (and (fboundp 'gnus-setup-posting-charset
)
4518 (boundp 'gnus-group-posting-charset-alist
))
4519 (gnus-setup-posting-charset nil
)
4520 message-posting-charset
))
4521 (headers message-required-mail-headers
)
4523 (when (and message-generate-hashcash
4524 (not (eq message-generate-hashcash
'opportunistic
)))
4525 (message "Generating hashcash...")
4527 ;; Wait for calculations already started to finish...
4528 (hashcash-wait-async)
4529 ;; ...and do calculations not already done. mail-add-payment
4530 ;; will leave existing X-Hashcash headers alone.
4532 (message "Generating hashcash...done"))
4534 (message-narrow-to-headers)
4535 ;; Generate the Mail-Followup-To header if the header is not there...
4536 (if (and (message-subscribed-p)
4537 (not (mail-fetch-field "mail-followup-to")))
4540 (cons "Mail-Followup-To" (message-make-mail-followup-to))
4541 message-required-mail-headers
))
4542 ;; otherwise, delete the MFT header if the field is empty
4543 (when (equal "" (mail-fetch-field "mail-followup-to"))
4544 (message-remove-header "^Mail-Followup-To:")))
4545 ;; Insert some headers.
4546 (let ((message-deletable-headers
4547 (if news nil message-deletable-headers
)))
4548 (message-generate-headers headers
))
4549 ;; Check continuation headers.
4550 (message-check 'continuation-headers
4551 (goto-char (point-min))
4552 (while (re-search-forward "^[^ \t\n][^ \t\n:]*[ \t\n]" nil t
)
4553 (goto-char (match-beginning 0))
4554 (if (y-or-n-p "Fix continuation lines? ")
4557 (unless (y-or-n-p "Send anyway? ")
4558 (error "Failed to send the message")))))
4559 ;; Fold too-long header lines. They should be no longer than
4561 (message--fold-long-headers)
4562 ;; Let the user do all of the above.
4563 (run-hooks 'message-header-hook
))
4564 (setq options message-options
)
4566 (with-current-buffer tembuf
4568 (setq message-options options
)
4569 ;; Avoid copying text props (except hard newlines).
4570 (insert (with-current-buffer mailbuf
4571 (mml-buffer-substring-no-properties-except-some
4572 (point-min) (point-max))))
4573 ;; Remove some headers.
4574 (message-encode-message-body)
4576 (message-narrow-to-headers)
4577 ;; We (re)generate the Lines header.
4578 (when (memq 'Lines message-required-mail-headers
)
4579 (message-generate-headers '(Lines)))
4580 ;; Remove some headers.
4581 (message-remove-header message-ignored-mail-headers t
)
4582 (let ((mail-parse-charset message-default-charset
))
4583 (mail-encode-encoded-word-buffer)))
4584 (goto-char (point-max))
4585 ;; require one newline at the end.
4586 (or (= (preceding-char) ?
\n)
4588 (message-cleanup-headers)
4589 ;; FIXME: we're inserting the courtesy copy after encoding.
4590 ;; This is wrong if the courtesy copy string contains
4591 ;; non-ASCII characters. -- jh
4594 (message-narrow-to-headers)
4596 (not (message-fetch-field "List-Post"))
4597 (not (message-fetch-field "List-ID"))
4598 (or (message-fetch-field "cc")
4599 (message-fetch-field "bcc")
4600 (message-fetch-field "to"))
4601 (let ((content-type (message-fetch-field
4606 (string= "text/plain"
4608 (mail-header-parse-content-type
4612 (message-fetch-field
4613 "content-transfer-encoding")))))))
4614 (message-insert-courtesy-copy
4615 (with-current-buffer mailbuf
4616 message-courtesy-message
)))
4617 ;; Let's make sure we encoded all the body.
4618 (assert (save-excursion
4619 (goto-char (point-min))
4620 (not (re-search-forward "[^\000-\377]" nil t
))))
4621 (mm-disable-multibyte)
4622 (if (or (not message-send-mail-partially-limit
)
4623 (< (buffer-size) message-send-mail-partially-limit
)
4624 (not (message-y-or-n-p
4625 "The message size is too large, split? "
4629 (/ (buffer-size) 1000) "KB, is too large.
4631 Some mail gateways (MTA's) bounce large messages. To avoid the
4632 problem, answer `y', and the message will be split into several
4633 smaller pieces, the size of each is about "
4634 (/ message-send-mail-partially-limit
1000)
4638 However, some mail readers (MUA's) can't read split messages, i.e.,
4639 mails in message/partially format. Answer `n', and the message will be
4642 The size limit is controlled by `message-send-mail-partially-limit'.
4643 If you always want Gnus to send messages in one piece, set
4644 `message-send-mail-partially-limit' to nil.
4647 (message "Sending via mail...")
4648 (if message-send-mail-real-function
4649 (funcall message-send-mail-real-function
)
4650 (message-multi-smtp-send-mail)))
4651 (message-send-mail-partially))
4652 (setq options message-options
))
4653 (kill-buffer tembuf
))
4654 (set-buffer mailbuf
)
4655 (setq message-options options
)
4656 (push 'mail message-sent-message-via
)))
4658 (defun message--fold-long-headers ()
4659 (goto-char (point-min))
4661 (when (and (looking-at "[^:]+:")
4662 (> (- (line-end-position) (point)) 998))
4663 (mail-header-fold-field))
4666 (defvar sendmail-program
)
4667 (defvar smtpmail-smtp-server
)
4668 (defvar smtpmail-smtp-service
)
4669 (defvar smtpmail-smtp-user
)
4671 (defun message-multi-smtp-send-mail ()
4672 "Send the current buffer to `message-send-mail-function'.
4673 Or, if there's a header that specifies a different method, use
4675 (let ((method (message-field-value "X-Message-SMTP-Method")))
4677 (funcall message-send-mail-function
)
4678 (message-remove-header "X-Message-SMTP-Method")
4679 (setq method
(split-string method
))
4681 ((equal (car method
) "sendmail")
4682 (message-send-mail-with-sendmail))
4683 ((equal (car method
) "smtp")
4685 (let ((smtpmail-smtp-server (nth 1 method
))
4686 (smtpmail-smtp-service (nth 2 method
))
4687 (smtpmail-smtp-user (or (nth 3 method
) smtpmail-smtp-user
)))
4688 (message-smtpmail-send-it)))
4690 (error "Unknown method %s" method
))))))
4692 (defun message-send-mail-with-sendmail ()
4693 "Send off the prepared buffer with sendmail."
4695 (let ((errbuf (if message-interactive
4696 (message-generate-new-buffer-clone-locals
4699 resend-to-addresses delimline
)
4702 (let ((case-fold-search t
))
4704 (message-narrow-to-headers)
4705 (setq resend-to-addresses
(message-fetch-field "resent-to")))
4706 ;; Change header-delimiter to be what sendmail expects.
4707 (goto-char (point-min))
4709 (concat "^" (regexp-quote mail-header-separator
) "\n"))
4710 (replace-match "\n")
4712 (setq delimline
(point-marker))
4713 (run-hooks 'message-send-mail-hook
)
4714 ;; Insert an extra newline if we need it to work around
4715 ;; Sun's bug that swallows newlines.
4716 (goto-char (1+ delimline
))
4717 (when (eval message-mailer-swallows-blank-line
)
4719 (when message-interactive
4720 (with-current-buffer errbuf
4722 (let* ((default-directory "/")
4723 (coding-system-for-write message-send-coding-system
)
4725 'call-process-region
4727 (list (point-min) (point-max) sendmail-program
4728 nil errbuf nil
"-oi")
4729 message-sendmail-extra-arguments
4730 ;; Always specify who from,
4731 ;; since some systems have broken sendmails.
4732 ;; But some systems are more broken with -f, so
4733 ;; we'll let users override this.
4734 (and (null message-sendmail-f-is-evil
)
4735 (list "-f" (message-sendmail-envelope-from)))
4736 ;; These mean "report errors by mail"
4737 ;; and "deliver in background".
4738 (if (null message-interactive
) '("-oem" "-odb"))
4739 ;; Get the addresses from the message
4740 ;; unless this is a resend.
4741 ;; We must not do that for a resend
4742 ;; because we would find the original addresses.
4743 ;; For a resend, include the specific addresses.
4744 (if resend-to-addresses
4745 (list resend-to-addresses
)
4747 (unless (or (null cpr
) (and (numberp cpr
) (zerop cpr
)))
4749 (pop-to-buffer errbuf
)
4751 (error "Sending...failed with exit value %d" cpr
)))
4752 (when message-interactive
4753 (with-current-buffer errbuf
4754 (goto-char (point-min))
4755 (while (re-search-forward "\n+ *" nil t
)
4756 (replace-match "; "))
4757 (if (not (zerop (buffer-size)))
4758 (error "Sending...failed to %s"
4759 (buffer-string))))))
4760 (when (bufferp errbuf
)
4761 (kill-buffer errbuf
)))))
4763 (defun message-send-mail-with-qmail ()
4764 "Pass the prepared message buffer to qmail-inject.
4765 Refer to the documentation for the variable `message-send-mail-function'
4766 to find out how to use this."
4767 ;; replace the header delimiter with a blank line
4768 (goto-char (point-min))
4770 (concat "^" (regexp-quote mail-header-separator
) "\n"))
4771 (replace-match "\n")
4772 (run-hooks 'message-send-mail-hook
)
4775 (let ((coding-system-for-write message-send-coding-system
))
4777 'call-process-region
(point-min) (point-max)
4778 message-qmail-inject-program nil nil nil
4779 ;; qmail-inject's default behavior is to look for addresses on the
4780 ;; command line; if there're none, it scans the headers.
4781 ;; yes, it does The Right Thing w.r.t. Resent-To and it's kin.
4783 ;; in general, ALL of qmail-inject's defaults are perfect for simply
4784 ;; reading a formatted (i. e., at least a To: or Resent-To header)
4785 ;; message from stdin.
4787 ;; qmail also has the advantage of not having been raped by
4788 ;; various vendors, so we don't have to allow for that, either --
4789 ;; compare this with message-send-mail-with-sendmail and weep
4790 ;; for sendmail's lost innocence.
4792 ;; all this is way cool coz it lets us keep the arguments entirely
4793 ;; free for -inject-arguments -- a big win for the user and for us
4794 ;; since we don't have to play that double-guessing game and the user
4795 ;; gets full control (no gestapo'ish -f's, for instance). --sj
4796 (if (functionp message-qmail-inject-args
)
4797 (funcall message-qmail-inject-args
)
4798 message-qmail-inject-args
)))
4799 ;; qmail-inject doesn't say anything on it's stdout/stderr,
4800 ;; we have to look at the retval instead
4802 (100 (error "qmail-inject reported permanent failure"))
4803 (111 (error "qmail-inject reported transient failure"))
4804 ;; should never happen
4805 (t (error "qmail-inject reported unknown failure"))))
4807 (defvar mh-previous-window-config
)
4809 (defun message-send-mail-with-mh ()
4810 "Send the prepared message buffer with mh."
4811 (let ((mh-previous-window-config nil
)
4812 (name (mh-new-draft-name)))
4813 (setq buffer-file-name name
)
4814 ;; MH wants to generate these headers itself.
4815 (when message-mh-deletable-headers
4816 (let ((headers message-mh-deletable-headers
))
4818 (goto-char (point-min))
4819 (and (re-search-forward
4820 (concat "^" (symbol-name (car headers
)) ": *") nil t
)
4821 (message-delete-line))
4823 (run-hooks 'message-send-mail-hook
)
4824 ;; Pass it on to mh.
4827 (defun message-smtpmail-send-it ()
4828 "Send the prepared message buffer with `smtpmail-send-it'.
4829 The only difference from `smtpmail-send-it' is that this command
4830 evaluates `message-send-mail-hook' just before sending a message.
4831 It is useful if your ISP requires the POP-before-SMTP
4832 authentication. See the Gnus manual for details."
4833 (run-hooks 'message-send-mail-hook
)
4834 ;; Change header-delimiter to be what smtpmail expects.
4835 (goto-char (point-min))
4836 (when (re-search-forward
4837 (concat "^" (regexp-quote mail-header-separator
) "\n"))
4838 (replace-match "\n"))
4841 (defun message-send-mail-with-mailclient ()
4842 "Send the prepared message buffer with `mailclient-send-it'.
4843 The only difference from `mailclient-send-it' is that this
4844 command evaluates `message-send-mail-hook' just before sending a message."
4845 (run-hooks 'message-send-mail-hook
)
4846 (mailclient-send-it))
4848 (defvar sha1-maximum-internal-length
)
4850 (defun message-canlock-generate ()
4851 "Return a string that is non-trivial to guess.
4852 Do not use this for anything important, it is cryptographically weak."
4854 (let (sha1-maximum-internal-length)
4855 (sha1 (concat (message-unique-id)
4856 (format "%x%x%x" (random) (random) (random))
4857 (prin1-to-string (recent-keys))
4858 (prin1-to-string (garbage-collect))))))
4860 (defvar canlock-password
)
4861 (defvar canlock-password-for-verify
)
4863 (defun message-canlock-password ()
4864 "The password used by message for cancel locks.
4865 This is the value of `canlock-password', if that option is non-nil.
4866 Otherwise, generate and save a value for `canlock-password' first."
4868 (unless canlock-password
4869 (customize-save-variable 'canlock-password
(message-canlock-generate))
4870 (setq canlock-password-for-verify canlock-password
))
4873 (defun message-insert-canlock ()
4874 (when message-insert-canlock
4875 (message-canlock-password)
4876 (canlock-insert-header)))
4878 (autoload 'nnheader-get-report
"nnheader")
4880 (declare-function gnus-setup-posting-charset
"gnus-msg" (group))
4882 (defun message-send-news (&optional arg
)
4884 (let* ((tembuf (message-generate-new-buffer-clone-locals " *message temp*"))
4885 (case-fold-search nil
)
4886 (method (if (functionp message-post-method
)
4887 (funcall message-post-method arg
)
4888 message-post-method
))
4889 (newsgroups-field (save-restriction
4890 (message-narrow-to-headers-or-head)
4891 (message-fetch-field "Newsgroups")))
4892 (followup-field (save-restriction
4893 (message-narrow-to-headers-or-head)
4894 (message-fetch-field "Followup-To")))
4895 ;; BUG: We really need to get the charset for each name in the
4896 ;; Newsgroups and Followup-To lines to allow crossposting
4897 ;; between group names with incompatible character sets.
4898 ;; -- Per Abrahamsen <abraham@dina.kvl.dk> 2001-10-08.
4899 (group-field-charset
4900 (gnus-group-name-charset method newsgroups-field
))
4901 (followup-field-charset
4902 (gnus-group-name-charset method
(or followup-field
"")))
4903 (rfc2047-header-encoding-alist
4904 (append (when group-field-charset
4905 (list (cons "Newsgroups" group-field-charset
)))
4906 (when followup-field-charset
4907 (list (cons "Followup-To" followup-field-charset
)))
4908 rfc2047-header-encoding-alist
))
4909 (messbuf (current-buffer))
4910 (message-syntax-checks
4912 (listp message-syntax-checks
))
4913 (cons '(existing-newsgroups . disabled
)
4914 message-syntax-checks
)
4915 message-syntax-checks
))
4916 (message-this-is-news t
)
4917 (message-posting-charset
4918 (gnus-setup-posting-charset newsgroups-field
))
4920 (if (not (message-check-news-body-syntax))
4923 (message-narrow-to-headers)
4924 ;; Insert some headers.
4925 (message-generate-headers message-required-news-headers
)
4926 (message-insert-canlock)
4927 ;; Let the user do all of the above.
4928 (run-hooks 'message-header-hook
))
4929 ;; Note: This check will be disabled by the ".*" default value for
4930 ;; gnus-group-name-charset-group-alist. -- Pa 2001-10-07.
4931 (when (and group-field-charset
4932 (listp message-syntax-checks
))
4933 (setq message-syntax-checks
4934 (cons '(valid-newsgroups . disabled
)
4935 message-syntax-checks
)))
4936 (message-cleanup-headers)
4937 (if (not (let ((message-post-method method
))
4938 (message-check-news-syntax)))
4941 (with-current-buffer tembuf
4942 (buffer-disable-undo)
4944 ;; Avoid copying text props (except hard newlines).
4946 (with-current-buffer messbuf
4947 (mml-buffer-substring-no-properties-except-some
4948 (point-min) (point-max))))
4949 (message-encode-message-body)
4950 ;; Remove some headers.
4952 (message-narrow-to-headers)
4953 ;; We (re)generate the Lines header.
4954 (when (memq 'Lines message-required-mail-headers
)
4955 (message-generate-headers '(Lines)))
4956 ;; Remove some headers.
4957 (message-remove-header message-ignored-news-headers t
)
4958 (let ((mail-parse-charset message-default-charset
))
4959 (mail-encode-encoded-word-buffer)))
4960 (goto-char (point-max))
4961 ;; require one newline at the end.
4962 (or (= (preceding-char) ?
\n)
4964 (let ((case-fold-search t
))
4965 ;; Remove the delimiter.
4966 (goto-char (point-min))
4968 (concat "^" (regexp-quote mail-header-separator
) "\n"))
4969 (replace-match "\n")
4971 (run-hooks 'message-send-news-hook
)
4972 (gnus-open-server method
)
4973 (message "Sending news via %s..." (gnus-server-string method
))
4974 (setq result
(let ((mail-header-separator ""))
4975 (gnus-request-post method
))))
4976 (kill-buffer tembuf
))
4977 (set-buffer messbuf
)
4979 (push 'news message-sent-message-via
)
4980 (message "Couldn't send message via news: %s"
4981 (nnheader-get-report (car method
)))
4985 ;;; Header generation & syntax checking.
4988 (defun message-check-element (type)
4989 "Return non-nil if this TYPE is not to be checked."
4990 (if (eq message-syntax-checks
'dont-check-for-anything-just-trust-me
)
4992 (let ((able (assq type message-syntax-checks
)))
4994 (eq (cdr able
) 'disabled
)))))
4996 (defun message-check-news-syntax ()
4997 "Check the syntax of the message."
5001 ;; We narrow to the headers and check them first.
5004 (message-narrow-to-headers)
5005 (message-check-news-header-syntax))))))
5007 (defun message-check-news-header-syntax ()
5009 ;; Check Newsgroups header.
5010 (message-check 'newsgroups
5011 (let ((group (message-fetch-field "newsgroups")))
5014 (not (string-match "\\`[ \t]*\\'" group
)))
5017 "The newsgroups field is empty or missing. Posting is denied.")))))
5018 ;; Check the Subject header.
5019 (message-check 'subject
5020 (let* ((case-fold-search t
)
5021 (subject (message-fetch-field "subject")))
5024 (not (string-match "\\`[ \t]*\\'" subject
)))
5027 "The subject field is empty or missing. Posting is denied.")))))
5028 ;; Check for commands in Subject.
5029 (message-check 'subject-cmsg
5030 (if (string-match "^cmsg " (message-fetch-field "subject"))
5032 "The control code \"cmsg\" is in the subject. Really post? ")
5034 ;; Check long header lines.
5035 (message-check 'long-header-lines
5039 (while (and (not found
)
5040 (re-search-forward "^\\([^ \t:]+\\): " nil t
))
5041 (if (> (- (point) (match-beginning 0)) 998)
5043 length
(- (point) (match-beginning 0)))
5044 (setq header
(match-string-no-properties 1)))
5047 (y-or-n-p (format "Your %s header is too long (%d). Really post? "
5050 ;; Check for multiple identical headers.
5051 (message-check 'multiple-headers
5053 (while (and (not found
)
5054 (re-search-forward "^[^ \t:]+: " nil t
))
5056 (or (re-search-forward
5061 (match-beginning 0) (- (match-end 0) 2))))
5066 (y-or-n-p (format "Multiple %s headers. Really post? " found
))
5068 ;; Check for Version and Sendsys.
5069 (message-check 'sendsys
5070 (if (re-search-forward "^Sendsys:\\|^Version:" nil t
)
5072 (format "The article contains a %s command. Really post? "
5073 (buffer-substring (match-beginning 0)
5074 (1- (match-end 0)))))
5076 ;; See whether we can shorten Followup-To.
5077 (message-check 'shorten-followup-to
5078 (let ((newsgroups (message-fetch-field "newsgroups"))
5079 (followup-to (message-fetch-field "followup-to"))
5081 (when (and newsgroups
5082 (string-match "," newsgroups
)
5087 (setq to
(completing-read
5088 "Followups to (default no Followup-To header): "
5091 (message-tokenize-header
5093 (goto-char (point-min))
5094 (insert "Followup-To: " to
"\n"))
5096 ;; Check "Shoot me".
5097 (message-check 'shoot
5098 (if (re-search-forward
5099 "Message-ID.*.i-did-not-set--mail-host-address--so-tickle-me" nil t
)
5100 (y-or-n-p "You appear to have a misconfigured system. Really post? ")
5102 ;; Check for Approved.
5103 (message-check 'approved
5104 (if (re-search-forward "^Approved:" nil t
)
5105 (y-or-n-p "The article contains an Approved header. Really post? ")
5107 ;; Check the Message-ID header.
5108 (message-check 'message-id
5109 (let* ((case-fold-search t
)
5110 (message-id (message-fetch-field "message-id" t
)))
5111 (or (not message-id
)
5112 ;; Is there an @ in the ID?
5113 (and (string-match "@" message-id
)
5114 ;; Is there a dot in the ID?
5115 (string-match "@[^.]*\\." message-id
)
5116 ;; Does the ID end with a dot?
5117 (not (string-match "\\.>" message-id
)))
5119 (format "The Message-ID looks strange: \"%s\". Really post? "
5121 ;; Check the Newsgroups & Followup-To headers.
5122 (message-check 'existing-newsgroups
5123 (let* ((case-fold-search t
)
5124 (newsgroups (message-fetch-field "newsgroups"))
5125 (followup-to (message-fetch-field "followup-to"))
5126 (groups (message-tokenize-header
5128 (concat newsgroups
"," followup-to
)
5130 (post-method (if (functionp message-post-method
)
5131 (funcall message-post-method
)
5132 message-post-method
))
5133 ;; KLUDGE to handle nnvirtual groups. Doing this right
5134 ;; would probably involve a new nnoo function.
5135 ;; -- Per Abrahamsen <abraham@dina.kvl.dk>, 2001-10-17.
5136 (method (if (and (consp post-method
)
5137 (eq (car post-method
) 'nnvirtual
)
5138 gnus-message-group-art
)
5139 (let ((group (car (nnvirtual-find-group-art
5140 (car gnus-message-group-art
)
5141 (cdr gnus-message-group-art
)))))
5142 (gnus-find-method-for-group group
))
5146 (gnus-group-name-decode
5147 (gnus-group-real-name n
)
5148 (gnus-group-name-charset method n
)))
5149 (gnus-groups-from-server method
)))
5152 (when (and (not (equal (car groups
) "poster"))
5153 (not (member (car groups
) known-groups
))
5154 (not (member (car groups
) errors
)))
5155 (push (car groups
) errors
))
5158 ;; Gnus is not running.
5159 ((or (not (and (boundp 'gnus-active-hashtb
)
5160 gnus-active-hashtb
))
5161 (not (boundp 'gnus-read-active-file
)))
5163 ;; We don't have all the group names.
5164 ((and (or (not gnus-read-active-file
)
5165 (eq gnus-read-active-file
'some
))
5169 "Really use %s possibly unknown group%s: %s? "
5170 (if (= (length errors
) 1) "this" "these")
5171 (if (= (length errors
) 1) "" "s")
5172 (mapconcat 'identity errors
", "))))
5173 ;; There were no errors.
5176 ;; There are unknown groups.
5180 "Really post to %s unknown group%s: %s? "
5181 (if (= (length errors
) 1) "this" "these")
5182 (if (= (length errors
) 1) "" "s")
5183 (mapconcat 'identity errors
", ")))))))
5184 ;; Check continuation headers.
5185 (message-check 'continuation-headers
5186 (goto-char (point-min))
5187 (let ((do-posting t
))
5188 (while (re-search-forward "^[^ \t\n][^ \t\n:]*[ \t\n]" nil t
)
5189 (goto-char (match-beginning 0))
5190 (if (y-or-n-p "Fix continuation lines? ")
5193 (unless (y-or-n-p "Send anyway? ")
5194 (setq do-posting nil
))))
5196 ;; Check the Newsgroups & Followup-To headers for syntax errors.
5197 (message-check 'valid-newsgroups
5198 (let ((case-fold-search t
)
5199 (headers '("Newsgroups" "Followup-To"))
5201 (while (and headers
(not error
))
5202 (when (setq header
(mail-fetch-field (car headers
)))
5206 "\\`\\([-+_&.a-zA-Z0-9]+\\)?\\(,[-+_&.a-zA-Z0-9]+\\)*\\'"
5211 (not (string-match "\\.\\'\\|\\.\\." g
)))
5212 (message-tokenize-header header
","))))
5219 (format "The %s header looks odd: \"%s\". Really post? "
5220 (car headers
) header
)))))
5221 (message-check 'repeated-newsgroups
5222 (let ((case-fold-search t
)
5223 (headers '("Newsgroups" "Followup-To"))
5224 header error groups group
)
5227 (when (setq header
(mail-fetch-field (pop headers
)))
5228 (setq groups
(message-tokenize-header header
","))
5229 (while (setq group
(pop groups
))
5230 (when (member group groups
)
5236 (format "Group %s is repeated in headers. Really post? " error
)))))
5237 ;; Check the From header.
5238 (message-check 'from
5239 (let* ((case-fold-search t
)
5240 (from (message-fetch-field "from"))
5244 (message "There is no From line. Posting is denied.")
5246 ((or (not (string-match
5248 (setq ad
(nth 1 (mail-extract-address-components
5249 from
))))) ;larsi@ifi
5250 (string-match "\\.\\." ad
) ;larsi@ifi..uio
5251 (string-match "@\\." ad
) ;larsi@.ifi.uio
5252 (string-match "\\.$" ad
) ;larsi@ifi.uio.
5253 (not (string-match "^[^@]+@[^@]+$" ad
)) ;larsi.ifi.uio
5254 (string-match "(.*).*(.*)" from
)) ;(lars) (lars)
5256 "Denied posting -- the From looks strange: \"%s\"." from
)
5258 ((let ((addresses (rfc822-addresses from
)))
5259 ;; `rfc822-addresses' returns a string if parsing fails.
5260 (while (and (consp addresses
)
5261 (not (eq (string-to-char (car addresses
)) ?\
()))
5262 (setq addresses
(cdr addresses
)))
5265 "Denied posting -- bad From address: \"%s\"." from
)
5268 ;; Check the Reply-To header.
5269 (message-check 'reply-to
5270 (let* ((case-fold-search t
)
5271 (reply-to (message-fetch-field "reply-to"))
5276 ((string-match "," reply-to
)
5278 (format "Multiple Reply-To addresses: \"%s\". Really post? "
5280 ((or (not (string-match
5282 (setq ad
(nth 1 (mail-extract-address-components
5283 reply-to
))))) ;larsi@ifi
5284 (string-match "\\.\\." ad
) ;larsi@ifi..uio
5285 (string-match "@\\." ad
) ;larsi@.ifi.uio
5286 (string-match "\\.$" ad
) ;larsi@ifi.uio.
5287 (not (string-match "^[^@]+@[^@]+$" ad
)) ;larsi.ifi.uio
5288 (string-match "(.*).*(.*)" reply-to
)) ;(lars) (lars)
5291 "The Reply-To looks strange: \"%s\". Really post? "
5295 (defun message-check-news-body-syntax ()
5297 ;; Check for long lines.
5298 (message-check 'long-lines
5299 (goto-char (point-min))
5301 (concat "^" (regexp-quote mail-header-separator
) "$"))
5305 "<#\\(/\\)?\\(multipart\\|part\\|external\\|mml\\)")
5308 (< (- (point) p
) 80)))
5309 (zerop (forward-line 1))))
5313 "You have lines longer than 79 characters. Really post? ")))
5314 ;; Check whether the article is empty.
5315 (message-check 'empty
5316 (goto-char (point-min))
5318 (concat "^" (regexp-quote mail-header-separator
) "$"))
5321 (goto-char (point-max))
5322 (re-search-backward message-signature-separator nil t
)
5324 (or (re-search-backward "[^ \n\t]" b t
)
5325 (if (message-gnksa-enable-p 'empty-article
)
5326 (y-or-n-p "Empty article. Really post? ")
5327 (message "Denied posting -- Empty article.")
5329 ;; Check for control characters.
5330 (message-check 'control-chars
5331 (if (re-search-forward
5332 (string-to-multibyte "[\000-\007\013\015-\032\034-\037\200-\237]")
5335 "The article contains control characters. Really post? ")
5337 ;; Check excessive size.
5338 (message-check 'size
5339 (if (> (buffer-size) 60000)
5341 (format "The article is %d octets long. Really post? "
5344 ;; Check whether any new text has been added.
5345 (message-check 'new-text
5347 (not message-checksum
)
5348 (not (eq (message-checksum) message-checksum
))
5349 (if (message-gnksa-enable-p 'quoted-text-only
)
5351 "It looks like no new text has been added. Really post? ")
5352 (message "Denied posting -- no new text has been added.")
5354 ;; Check the length of the signature.
5355 (message-check 'signature
5356 (let (sig-start sig-end
)
5357 (goto-char (point-max))
5358 (if (not (re-search-backward message-signature-separator nil t
))
5360 (setq sig-start
(1+ (point-at-eol)))
5362 (if (re-search-forward
5363 "<#/?\\(multipart\\|part\\|external\\|mml\\)" nil t
)
5364 (- (point-at-bol) 1)
5366 (if (>= (count-lines sig-start sig-end
) 5)
5367 (if (message-gnksa-enable-p 'signature
)
5369 (format "Signature is excessively long (%d lines). Really post? "
5370 (count-lines sig-start sig-end
)))
5371 (message "Denied posting -- Excessive signature.")
5374 ;; Ensure that text follows last quoted portion.
5375 (message-check 'quoting-style
5376 (goto-char (point-max))
5377 (let ((no-problem t
))
5378 (when (search-backward-regexp "^>[^\n]*\n" nil t
)
5379 (setq no-problem
(search-forward-regexp "^[ \t]*[^>\n]" nil t
)))
5382 (if (message-gnksa-enable-p 'quoted-text-only
)
5383 (y-or-n-p "Your text should follow quoted text. Really post? ")
5385 (goto-char (point-min))
5387 (concat "^" (regexp-quote mail-header-separator
) "$"))
5388 (if (search-forward-regexp "^[ \t]*[^>\n]" nil t
)
5389 (y-or-n-p "Your text should follow quoted text. Really post? ")
5390 (message "Denied posting -- only quoted text.")
5393 (defun message-checksum ()
5394 "Return a \"checksum\" for the current buffer."
5397 (goto-char (point-min))
5399 (concat "^" (regexp-quote mail-header-separator
) "$"))
5401 (when (not (looking-at "[ \t\n]"))
5402 (setq sum
(logxor (ash sum
1) (if (natnump sum
) 0 1)
5407 (defun message-do-fcc ()
5408 "Process Fcc headers in the current buffer."
5409 (let ((case-fold-search t
)
5410 (buf (current-buffer))
5411 (mml-externalize-attachments message-fcc-externalize-attachments
)
5412 (file (message-field-value "fcc" t
))
5416 (insert-buffer-substring buf
)
5417 (message-clone-locals buf
)
5418 (message-encode-message-body)
5420 (message-narrow-to-headers)
5421 (while (setq file
(message-fetch-field "fcc" t
))
5423 (message-remove-header "fcc" nil t
))
5424 (let ((mail-parse-charset message-default-charset
)
5425 (rfc2047-header-encoding-alist
5426 (cons '("Newsgroups" . default
)
5427 rfc2047-header-encoding-alist
)))
5428 (mail-encode-encoded-word-buffer)))
5429 (goto-char (point-min))
5430 (when (re-search-forward
5431 (concat "^" (regexp-quote mail-header-separator
) "$")
5433 (replace-match "" t t
))
5434 ;; Process FCC operations.
5436 (setq file
(pop list
))
5437 (if (string-match "^[ \t]*|[ \t]*\\(.*\\)[ \t]*$" file
)
5438 ;; Pipe the article to the program in question.
5439 (call-shell-region (point-min) (point-max) (match-string 1 file
))
5440 ;; Save the article.
5441 (setq file
(expand-file-name file
))
5442 (unless (file-exists-p (file-name-directory file
))
5443 (make-directory (file-name-directory file
) t
))
5444 (if (and message-fcc-handler-function
5445 (not (eq message-fcc-handler-function
'rmail-output
)))
5446 (funcall message-fcc-handler-function file
)
5447 ;; FIXME this option, rmail-output (also used if
5448 ;; message-fcc-handler-function is nil) is not
5449 ;; documented anywhere AFAICS. It should work in Emacs
5450 ;; 23; I suspect it does not work in Emacs 22.
5451 ;; FIXME I don't see the need for the two different cases here.
5452 ;; mail-use-rfc822 makes no difference (in Emacs 23),and
5453 ;; the third argument just controls \"Wrote file\" message.
5454 (if (and (file-readable-p file
) (mail-file-babyl-p file
))
5455 (rmail-output file
1 nil t
)
5456 (let ((mail-use-rfc822 t
))
5457 (rmail-output file
1 t t
))))))))))
5459 (defun message-output (filename)
5460 "Append this article to Unix/babyl mail file FILENAME."
5461 (if (or (and (file-readable-p filename
)
5462 (mail-file-babyl-p filename
))
5463 ;; gnus-output-to-mail does the wrong thing with live, mbox
5464 ;; Rmail buffers in Emacs 23.
5465 ;; http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=597255
5466 (let ((buff (find-buffer-visiting filename
)))
5467 (and buff
(with-current-buffer buff
5468 (eq major-mode
'rmail-mode
)))))
5469 (gnus-output-to-rmail filename t
)
5470 (gnus-output-to-mail filename t
)))
5472 (defun message-cleanup-headers ()
5473 "Do various automatic cleanups of the headers."
5474 ;; Remove empty lines in the header.
5476 (message-narrow-to-headers)
5477 ;; Remove blank lines.
5478 (while (re-search-forward "^[ \t]*\n" nil t
)
5479 (replace-match "" t t
))
5481 ;; Correct Newsgroups and Followup-To headers: Change sequence of
5482 ;; spaces to comma and eliminate spaces around commas. Eliminate
5483 ;; embedded line breaks.
5484 (goto-char (point-min))
5485 (while (re-search-forward "^\\(Newsgroups\\|Followup-To\\): +" nil t
)
5489 (if (re-search-forward "^[^ \t]" nil t
)
5493 (goto-char (point-min))
5494 (while (re-search-forward "\n[ \t]+" nil t
)
5495 (replace-match " " t t
)) ;No line breaks (too confusing)
5496 (goto-char (point-min))
5497 (while (re-search-forward "[ \t\n]*,[ \t\n]*\\|[ \t]+" nil t
)
5498 (replace-match "," t t
))
5499 (goto-char (point-min))
5500 ;; Remove trailing commas.
5501 (when (re-search-forward ",+$" nil t
)
5502 (replace-match "" t t
))))))
5504 (defun message-make-date (&optional now
)
5505 "Make a valid data header.
5506 If NOW, use that time instead."
5507 (let ((system-time-locale "C"))
5508 (format-time-string "%a, %d %b %Y %T %z" now
)))
5510 (defun message-insert-expires (days)
5511 "Insert the Expires header. Expiry in DAYS days."
5512 (interactive "NExpire article in how many days? ")
5514 (message-position-on-field "Expires" "X-Draft-From")
5515 (insert (message-make-expires-date days
))))
5517 (defun message-make-expires-date (days)
5518 "Make date string for the Expires header. Expiry in DAYS days.
5520 In posting styles use `(\"Expires\" (make-expires-date 30))'."
5521 (let* ((cur (decode-time))
5522 (nday (+ days
(nth 3 cur
))))
5523 (setf (nth 3 cur
) nday
)
5524 (message-make-date (apply 'encode-time cur
))))
5526 (defun message-make-message-id ()
5527 "Make a unique Message-ID."
5528 (concat "<" (message-unique-id)
5529 (let ((psubject (save-excursion (message-fetch-field "subject")))
5531 (save-excursion (message-fetch-field "supersedes"))))
5533 (and message-reply-headers
5534 (mail-header-references message-reply-headers
)
5535 (mail-header-subject message-reply-headers
)
5538 (message-strip-subject-re
5539 (mail-header-subject message-reply-headers
))
5540 (message-strip-subject-re psubject
))))
5542 (string-match "_-_@" psupersedes
)))
5544 "@" (message-make-fqdn) ">"))
5546 (defvar message-unique-id-char nil
)
5548 ;; If you ever change this function, make sure the new version
5549 ;; cannot generate IDs that the old version could.
5550 ;; You might for example insert a "." somewhere (not next to another dot
5551 ;; or string boundary), or modify the "fsf" string.
5552 (defun message-unique-id ()
5553 ;; Don't use microseconds from (current-time), they may be unsupported.
5554 ;; Instead we use this randomly inited counter.
5555 (setq message-unique-id-char
5556 (%
(1+ (or message-unique-id-char
5557 (logand (random most-positive-fixnum
) (1- (lsh 1 20)))))
5558 ;; (current-time) returns 16-bit ints,
5559 ;; and 2^16*25 just fits into 4 digits i base 36.
5561 (let ((tm (current-time)))
5563 (if (or (eq system-type
'ms-dos
)
5564 ;; message-number-base36 doesn't handle bigints.
5565 (floatp (user-uid)))
5566 (let ((user (downcase (user-login-name))))
5567 (while (string-match "[^a-z0-9_]" user
)
5568 (aset user
(match-beginning 0) ?_
))
5570 (message-number-base36 (user-uid) -
1))
5571 (message-number-base36 (+ (car tm
)
5572 (lsh (% message-unique-id-char
25) 16)) 4)
5573 (message-number-base36 (+ (nth 1 tm
)
5574 (lsh (/ message-unique-id-char
25) 16)) 4)
5575 ;; Append a given name, because while the generated ID is unique
5576 ;; to this newsreader, other newsreaders might otherwise generate
5577 ;; the same ID via another algorithm.
5580 (defun message-number-base36 (num len
)
5585 (concat (message-number-base36 (/ num
36) (1- len
))
5586 (char-to-string (aref "zyxwvutsrqponmlkjihgfedcba9876543210"
5589 (defun message-make-organization ()
5590 "Make an Organization header."
5591 (let* ((organization
5592 (when message-user-organization
5593 (if (functionp message-user-organization
)
5594 (funcall message-user-organization
)
5595 message-user-organization
))))
5597 (mm-enable-multibyte)
5598 (cond ((stringp organization
)
5599 (insert organization
))
5600 ((and (eq t organization
)
5601 message-user-organization-file
5602 (file-exists-p message-user-organization-file
))
5603 (insert-file-contents message-user-organization-file
)))
5604 (goto-char (point-min))
5605 (while (re-search-forward "[\t\n]+" nil t
)
5606 (replace-match "" t t
))
5607 (unless (zerop (buffer-size))
5610 (defun message-make-lines ()
5611 "Count the number of lines and return numeric string."
5616 (int-to-string (count-lines (point) (point-max))))))
5618 (defun message-make-references ()
5619 "Return the References header for this message."
5620 (when message-reply-headers
5621 (let ((message-id (mail-header-id message-reply-headers
))
5622 (references (mail-header-references message-reply-headers
)))
5623 (if (or references message-id
)
5624 (concat (or references
"") (and references
" ")
5628 (defun message-make-in-reply-to ()
5629 "Return the In-Reply-To header for this message."
5630 (when message-reply-headers
5631 (let ((from (mail-header-from message-reply-headers
))
5632 (date (mail-header-date message-reply-headers
))
5633 (msg-id (mail-header-id message-reply-headers
)))
5635 (let ((name (mail-extract-address-components from
)))
5637 msg-id
(if msg-id
" (")
5639 (if (string-match "[^\000-\177]" (car name
))
5640 ;; Quote a string containing non-ASCII characters.
5641 ;; It will make the RFC2047 encoder cause an error
5642 ;; if there are special characters.
5643 (mm-with-multibyte-buffer
5645 (goto-char (point-min))
5646 (while (search-forward "\"" nil t
)
5649 (zerop (%
(skip-chars-backward "\\\\") 2))
5650 (goto-char (match-beginning 0)))
5653 ;; Those quotes will be removed by the RFC2047 encoder.
5654 (concat "\"" (buffer-string) "\""))
5658 (if (or (not date
) (string= date
""))
5659 "(unknown date)" date
)
5660 "\"" (if msg-id
")")))))))
5662 (defun message-make-distribution ()
5663 "Make a Distribution header."
5664 (let ((orig-distribution (message-fetch-reply-field "distribution")))
5665 (cond ((functionp message-distribution-function
)
5666 (funcall message-distribution-function
))
5667 (t orig-distribution
))))
5669 (defun message-make-expires ()
5670 "Return an Expires header based on `message-expires'."
5671 (let ((current (current-time))
5672 (future (* 1.0 message-expires
60 60 24)))
5673 ;; Add the future to current.
5674 (setcar current
(+ (car current
) (round (/ future
(expt 2 16)))))
5675 (setcar (cdr current
) (+ (nth 1 current
) (%
(round future
) (expt 2 16))))
5676 (message-make-date current
)))
5678 (defun message-make-path ()
5680 (let ((login-name (user-login-name)))
5681 (cond ((null message-user-path
)
5682 (concat (system-name) "!" login-name
))
5683 ((stringp message-user-path
)
5684 ;; Support GENERICPATH. Suggested by vixie@decwrl.dec.com.
5685 (concat message-user-path
"!" login-name
))
5688 (defun message-make-from (&optional name address
)
5689 "Make a From header."
5690 (let* ((style message-from-style
)
5691 (login (or address
(message-make-address)))
5692 (fullname (or name user-full-name
(user-full-name))))
5693 (when (string= fullname
"&")
5694 (setq fullname
(user-login-name)))
5696 (mm-enable-multibyte)
5699 (equal fullname
""))
5701 ((or (eq style
'angles
)
5702 (and (not (eq style
'parens
))
5703 ;; Use angles if no quoting is needed, or if parens would
5704 ;; need quoting too.
5705 (or (not (string-match "[^- !#-'*+/-9=?A-Z^-~]" fullname
))
5706 (let ((tmp (concat fullname nil
)))
5707 (while (string-match "([^()]*)" tmp
)
5708 (aset tmp
(match-beginning 0) ?-
)
5709 (aset tmp
(1- (match-end 0)) ?-
))
5710 (string-match "[\\()]" tmp
)))))
5712 (goto-char (point-min))
5713 ;; Look for a character that cannot appear unquoted
5714 ;; according to RFC 822.
5715 (when (re-search-forward "[^- !#-'*+/-9=?A-Z^-~]" nil
1)
5716 ;; Quote fullname, escaping specials.
5717 (goto-char (point-min))
5719 (while (re-search-forward "[\"\\]" nil
1)
5720 (replace-match "\\\\\\&" t
))
5722 (insert " <" login
">"))
5723 (t ; 'parens or default
5725 (let ((fullname-start (point)))
5727 (goto-char fullname-start
)
5728 ;; RFC 822 says \ and nonmatching parentheses
5729 ;; must be escaped in comments.
5730 ;; Escape every instance of ()\ ...
5731 (while (re-search-forward "[()\\]" nil
1)
5732 (replace-match "\\\\\\&" t
))
5733 ;; ... then undo escaping of matching parentheses,
5734 ;; including matching nested parentheses.
5735 (goto-char fullname-start
)
5736 (while (re-search-forward
5737 "\\(\\=\\|[^\\]\\(\\\\\\\\\\)*\\)\\\\(\\(\\([^\\]\\|\\\\\\\\\\)*\\)\\\\)"
5739 (replace-match "\\1(\\3)" t
)
5740 (goto-char fullname-start
)))
5744 (defun message-make-sender ()
5745 "Return the \"real\" user address.
5746 This function tries to ignore all user modifications, and
5747 give as trustworthy answer as possible."
5748 (concat (user-login-name) "@" (system-name)))
5750 (defun message-make-address ()
5751 "Make the address of the user."
5752 (or (message-user-mail-address)
5753 (concat (user-login-name) "@" (message-make-domain))))
5755 (defun message-user-mail-address ()
5756 "Return the pertinent part of `user-mail-address'."
5757 (when (and user-mail-address
5758 (string-match "@.*\\." user-mail-address
))
5759 (if (string-match " " user-mail-address
)
5760 (nth 1 (mail-extract-address-components user-mail-address
))
5761 user-mail-address
)))
5763 (defun message-sendmail-envelope-from ()
5764 "Return the envelope from."
5765 (cond ((eq message-sendmail-envelope-from
'header
)
5766 (nth 1 (mail-extract-address-components
5767 (message-fetch-field "from"))))
5768 ((stringp message-sendmail-envelope-from
)
5769 message-sendmail-envelope-from
)
5771 (message-make-address))))
5773 (defun message-make-fqdn ()
5774 "Return user's fully qualified domain name."
5775 (let* ((sysname (system-name))
5776 (user-mail (message-user-mail-address))
5779 (string-match "@\\(.*\\)\\'" user-mail
))
5780 (match-string 1 user-mail
)))
5781 (case-fold-search t
))
5783 ((and message-user-fqdn
5784 (stringp message-user-fqdn
)
5785 (not (string-match message-bogus-system-names message-user-fqdn
)))
5786 ;; `message-user-fqdn' seems to be valid
5788 ((not (string-match message-bogus-system-names sysname
))
5789 ;; `system-name' returned the right result.
5791 ;; Try `mail-host-address'.
5792 ((and (stringp mail-host-address
)
5793 (not (string-match message-bogus-system-names mail-host-address
)))
5795 ;; We try `user-mail-address' as a backup.
5797 (stringp user-domain
)
5798 (not (string-match message-bogus-system-names user-domain
)))
5800 ;; Default to this bogus thing.
5803 ".i-did-not-set--mail-host-address--so-tickle-me")))))
5805 (defun message-make-domain ()
5806 "Return the domain name."
5807 (or mail-host-address
5808 (message-make-fqdn)))
5810 (defun message-to-list-only ()
5811 "Send a message to the list only.
5812 Remove all addresses but the list address from To and Cc headers."
5814 (let ((listaddr (message-make-mail-followup-to t
)))
5817 (message-remove-header "to")
5818 (message-remove-header "cc")
5819 (message-position-on-field "To" "X-Draft-From")
5820 (insert listaddr
)))))
5822 (defun message-make-mail-followup-to (&optional only-show-subscribed
)
5823 "Return the Mail-Followup-To header.
5824 If passed the optional argument ONLY-SHOW-SUBSCRIBED only return the
5825 subscribed address (and not the additional To and Cc header contents)."
5826 (let* ((case-fold-search t
)
5827 (to (message-fetch-field "To"))
5828 (cc (message-fetch-field "cc"))
5829 (msg-recipients (concat to
(and to cc
", ") cc
))
5831 (mapcar 'mail-strip-quoted-names
5832 (message-tokenize-header msg-recipients
)))
5834 (if message-subscribed-address-file
5835 (let (begin end item re
)
5838 (insert-file-contents message-subscribed-address-file
)
5840 (setq begin
(point))
5843 (if (bolp) (setq end
(1- end
)))
5844 (setq item
(regexp-quote (buffer-substring begin end
)))
5845 (if re
(setq re
(concat re
"\\|" item
))
5846 (setq re
(concat "\\`\\(" item
))))
5847 (and re
(list (concat re
"\\)\\'"))))))))
5848 (mft-regexps (apply 'append message-subscribed-regexps
5849 (mapcar 'regexp-quote
5850 message-subscribed-addresses
)
5853 message-subscribed-address-functions
))))
5856 (loop for recipient in recipients
5857 when
(loop for regexp in mft-regexps
5858 when
(string-match regexp recipient
) return t
)
5861 (if only-show-subscribed
5863 msg-recipients
))))))
5865 (defun message-idna-to-ascii-rhs-1 (header)
5866 "Interactively potentially IDNA encode domain names in HEADER."
5867 (let ((field (message-fetch-field header
))
5872 (mapcar (lambda (rhs) (or (cadr (split-string rhs
"@")) ""))
5878 (mail-extract-address-components field t
))))))
5879 ;; Note that `rhs' will be "" if the address does not have
5880 ;; the domain part, i.e., if it is a local user's address.
5881 (setq ace
(if (string-match "\\`[[:ascii:]]*\\'" rhs
)
5883 (downcase (puny-encode-domain rhs
))))
5884 (when (and (not (equal rhs ace
))
5885 (or (not (eq message-use-idna
'ask
))
5886 (y-or-n-p (format "Replace %s with %s in %s:? "
5888 (goto-char (point-min))
5889 (while (re-search-forward (concat "^" header
":") nil t
)
5890 (message-narrow-to-field)
5891 (while (search-forward (concat "@" rhs
) nil t
)
5892 (replace-match (concat "@" ace
) t t
))
5893 (goto-char (point-max))
5896 (defun message-idna-to-ascii-rhs ()
5897 "Possibly IDNA encode non-ASCII domain names in From:, To: and Cc: headers.
5898 See `message-idna-encode'."
5900 (when message-use-idna
5903 ;; `message-narrow-to-head' that recognizes only the first empty
5904 ;; line as the message header separator used to be used here.
5905 ;; However, since there is the "--text follows this line--" line
5906 ;; normally, it failed in narrowing to the headers and potentially
5907 ;; caused the IDNA encoding on lines that look like headers in
5908 ;; the message body.
5909 (message-narrow-to-headers-or-head)
5910 (message-idna-to-ascii-rhs-1 "From")
5911 (message-idna-to-ascii-rhs-1 "To")
5912 (message-idna-to-ascii-rhs-1 "Reply-To")
5913 (message-idna-to-ascii-rhs-1 "Mail-Reply-To")
5914 (message-idna-to-ascii-rhs-1 "Mail-Followup-To")
5915 (message-idna-to-ascii-rhs-1 "Cc")))))
5917 (defun message-generate-headers (headers)
5918 "Prepare article HEADERS.
5919 Headers already prepared in the buffer are not modified."
5920 (setq headers
(append headers message-required-headers
))
5922 (message-narrow-to-headers)
5923 (let* ((header-values
5924 (list 'Date
(message-make-date)
5925 'Message-ID
(message-make-message-id)
5926 'Organization
(message-make-organization)
5927 'From
(message-make-from)
5928 'Path
(message-make-path)
5931 'In-Reply-To
(message-make-in-reply-to)
5932 'References
(message-make-references)
5934 'Distribution
(message-make-distribution)
5935 'Lines
(message-make-lines)
5936 'User-Agent message-newsreader
5937 'Expires
(message-make-expires)))
5938 (case-fold-search t
)
5940 header value elem header-string
)
5941 ;; First we remove any old generated headers.
5942 (let ((headers message-deletable-headers
))
5943 (unless (buffer-modified-p)
5944 (setq headers
(delq 'Message-ID
(copy-sequence headers
))))
5946 (goto-char (point-min))
5947 (and (re-search-forward
5948 (concat "^" (symbol-name (car headers
)) ": *") nil t
)
5949 (get-text-property (1+ (match-beginning 0)) 'message-deletable
)
5950 (message-delete-line))
5952 ;; Go through all the required headers and see if they are in the
5953 ;; articles already. If they are not, or are empty, they are
5954 ;; inserted automatically - except for Subject, Newsgroups and
5957 (goto-char (point-min))
5958 (setq elem
(pop headers
))
5960 (if (eq (car elem
) 'optional
)
5961 (setq header
(cdr elem
)
5963 (setq header
(car elem
)))
5965 (setq header-string
(if (stringp header
)
5967 (symbol-name header
)))
5968 (when (or (not (re-search-forward
5970 (regexp-quote (downcase header-string
))
5974 ;; The header was found. We insert a space after the
5975 ;; colon, if there is none.
5976 (if (/= (char-after) ?
) (insert " ") (forward-char 1))
5977 ;; Find out whether the header is empty.
5978 (looking-at "[ \t]*\n[^ \t]")))
5979 ;; So we find out what value we should insert.
5983 (eq (car elem
) 'optional
)
5984 (not (member header-string message-inserted-headers
)))
5985 ;; This is an optional header. If the cdr of this
5986 ;; is something that is nil, then we do not insert
5988 (setq header
(cdr elem
))
5989 (or (and (functionp (cdr elem
))
5990 (funcall (cdr elem
)))
5991 (and (symbolp (cdr elem
))
5992 (plist-get header-values
(cdr elem
)))))
5994 ;; The element is a cons. Either the cdr is a
5995 ;; string to be inserted verbatim, or it is a
5996 ;; function, and we insert the value returned from
5998 (or (and (stringp (cdr elem
))
6000 (and (functionp (cdr elem
))
6001 (funcall (cdr elem
)))))
6002 ((and (symbolp header
)
6003 (plist-member header-values header
))
6004 ;; The element is a symbol. We insert the value of
6005 ;; this symbol, if any.
6006 (plist-get header-values header
))
6007 ((not (message-check-element
6008 (intern (downcase (symbol-name header
)))))
6009 ;; We couldn't generate a value for this header,
6010 ;; so we just ask the user.
6011 (read-from-minibuffer
6012 (format "Empty header for %s; enter value: " header
)))))
6013 ;; Finally insert the header.
6015 (not (equal value
"")))
6019 ;; This header didn't exist, so we insert it.
6020 (goto-char (point-max))
6022 (cdr (assq header message-header-format-alist
))))
6024 (funcall formatter header value
)
6025 (insert header-string
": " value
))
6026 (push header-string message-inserted-headers
)
6027 (goto-char (message-fill-field))
6028 ;; We check whether the value was ended by a
6029 ;; newline. If not, we insert one.
6033 ;; The value of this header was empty, so we clear
6034 ;; totally and insert the new value.
6035 (delete-region (point) (point-at-eol))
6036 ;; If the header is optional, and the header was
6037 ;; empty, we can't insert it anyway.
6039 (push header-string message-inserted-headers
)
6041 (message-fill-field)))
6042 ;; Add the deletable property to the headers that require it.
6043 (and (memq header message-deletable-headers
)
6044 (progn (beginning-of-line) (looking-at "[^:]+: "))
6045 (add-text-properties
6046 (point) (match-end 0)
6047 '(message-deletable t face italic
) (current-buffer)))))))
6048 ;; Insert new Sender if the From is strange.
6049 (let ((from (message-fetch-field "from"))
6050 (sender (message-fetch-field "sender"))
6051 (secure-sender (message-make-sender)))
6053 (not (message-check-element 'sender
))
6056 (cadr (mail-extract-address-components from
)))
6057 (downcase secure-sender
)))
6062 (cadr (mail-extract-address-components sender
)))
6063 (downcase secure-sender
)))))
6064 (goto-char (point-min))
6065 ;; Rename any old Sender headers to Original-Sender.
6066 (when (re-search-forward "^\\(Original-\\)*Sender:" nil t
)
6068 (insert "Original-")
6069 (beginning-of-line))
6070 (when (or (message-news-p)
6071 (string-match "@.+\\.." secure-sender
))
6072 (insert "Sender: " secure-sender
"\n"))))
6074 (message-idna-to-ascii-rhs))))
6076 (defun message-insert-courtesy-copy (message)
6077 "Insert a courtesy message in mail copies of combined messages."
6081 (message-narrow-to-headers)
6082 (when (setq newsgroups
(message-fetch-field "newsgroups"))
6083 (goto-char (point-max))
6084 (insert "Posted-To: " newsgroups
"\n")))
6088 ((string-match "%s" message
)
6089 (insert (format message newsgroups
)))
6091 (insert message
)))))))
6094 ;;; Setting up a message buffer
6097 (defun message-skip-to-next-address ()
6098 (let ((end (save-excursion
6099 (message-next-header)
6102 (when (looking-at ",")
6104 (while (and (not (= (point) end
))
6105 (or (not (eq char ?
,))
6107 (skip-chars-forward "^,\"" end
)
6108 (when (eq (setq char
(following-char)) ?
\")
6109 (setq quoted
(not quoted
)))
6110 (unless (= (point) end
)
6112 (skip-chars-forward " \t\n")))
6114 (defun message-split-line ()
6115 "Split current line, moving portion beyond point vertically down.
6116 If the current line has `message-yank-prefix', insert it on the new line."
6118 (split-line message-yank-prefix
))
6120 (defun message-insert-header (header value
)
6121 (insert (capitalize (symbol-name header
))
6123 (if (consp value
) (car value
) value
)))
6125 (defun message-field-name ()
6127 (goto-char (point-min))
6128 (when (looking-at "\\([^:]+\\):")
6129 (intern (capitalize (match-string 1))))))
6131 (defun message-fill-field ()
6134 (message-narrow-to-field)
6135 (let ((field-name (message-field-name)))
6136 (funcall (or (cadr (assq field-name message-field-fillers
))
6137 'message-fill-field-general
)))
6140 (defun message-fill-field-address ()
6143 (message-skip-to-next-address)
6149 (when (and (> (current-column) 78)
6153 (delete-char (- (skip-chars-backward " \t")))
6155 (setq last
(point)))
6156 (forward-line end
)))
6158 (defun message-fill-field-general ()
6159 (let ((begin (point))
6162 (while (and (search-forward "\n" nil t
)
6164 (replace-match " " t t
))
6165 (fill-region-as-paragraph begin
(point-max))
6166 ;; Tapdance around looong Message-IDs.
6168 (when (looking-at "[ \t]*$")
6169 (message-delete-line))
6171 (search-forward ":" nil t
)
6172 (when (looking-at "\n[ \t]+")
6173 (replace-match " " t t
))
6174 (goto-char (point-max))))
6176 (defun message-shorten-1 (list cut surplus
)
6177 "Cut SURPLUS elements out of LIST, beginning with CUTth one."
6178 (setcdr (nthcdr (- cut
2) list
)
6179 (nthcdr (+ (- cut
2) surplus
1) list
)))
6181 (defun message-shorten-references (header references
)
6182 "Trim REFERENCES to be 21 Message-ID long or less, and fold them.
6183 When sending via news, also check that the REFERENCES are less
6184 than 988 characters long, and if they are not, trim them until
6186 ;; 21 is the number suggested by USAGE.
6193 (goto-char (point-min))
6194 ;; Cons a list of valid references. GNKSA says we must not include MIDs
6195 ;; with whitespace or missing brackets (7.a "Does not propagate broken
6196 ;; Message-IDs in original References").
6197 (while (re-search-forward "<[^ <]+@[^ <]+>" nil t
)
6198 (push (match-string 0) refs
))
6199 (setq refs
(nreverse refs
)
6200 count
(length refs
)))
6202 ;; If the list has more than MAXCOUNT elements, trim it by
6203 ;; removing the CUTth element and the required number of
6204 ;; elements that follow.
6205 (when (> count maxcount
)
6206 (let ((surplus (- count maxcount
)))
6207 (message-shorten-1 refs cut surplus
)
6208 (decf count surplus
)))
6210 ;; When sending via news, make sure the total folded length will
6211 ;; be less than 998 characters. This is to cater to broken INN
6212 ;; 2.3 which counts the total number of characters in a header
6213 ;; rather than the physical line length of each line, as it should.
6215 ;; This hack should be removed when it's believed than INN 2.3 is
6216 ;; no longer widely used.
6218 ;; At this point the headers have not been generated, thus we use
6219 ;; message-this-is-news directly.
6220 (when message-this-is-news
6223 (message-insert-header
6224 header
(mapconcat #'identity refs
" "))
6226 (message-shorten-1 refs cut
1)))
6227 ;; Finally, collect the references back into a string and insert
6228 ;; it into the buffer.
6229 (message-insert-header header
(mapconcat #'identity refs
" "))))
6231 (defun message-position-point ()
6232 "Move point to where the user probably wants to find it."
6233 (message-narrow-to-headers)
6235 ((re-search-forward "^[^:]+:[ \t]*$" nil t
)
6236 (search-backward ":" )
6239 (if (eq (char-after) ?
)
6243 (goto-char (point-max))
6246 (unless (looking-at "$")
6250 (defcustom message-beginning-of-line t
6251 "Whether \\<message-mode-map>\\[message-beginning-of-line]\
6252 goes to beginning of header values."
6254 :group
'message-buffers
6255 :link
'(custom-manual "(message)Movement")
6258 (defvar visual-line-mode
)
6259 (declare-function beginning-of-visual-line
"simple" (&optional n
))
6261 (defun message-beginning-of-header (handle-folded)
6262 "Move point to beginning of header’s value.
6264 When point is at the first header line, moves it after the colon
6265 and spaces separating header name and header value.
6267 When point is in a continuation line of a folded header (i.e. the
6268 line starts with a space), the behavior depends on HANDLE-FOLDED
6269 argument. If it’s nil, function moves the point to the start of
6270 the header continuation; otherwise, function locates the
6271 beginning of the header and moves point past the colon as is the
6272 case of single-line headers.
6274 No check whether point is inside of a header or body of the
6275 message is performed.
6277 Returns point or nil if beginning of header’s value could not be
6278 found. In the latter case, the point is still moved to the
6279 beginning of line (possibly after attempting to move it to the
6280 beginning of a folded header)."
6281 ;; https://www.rfc-editor.org/rfc/rfc2822.txt, section 2.2.3. says that when
6282 ;; unfolding a single WSP should be consumed. WSP is defined as a space
6283 ;; character or a horizontal tab.
6286 (while (and (> (point) (point-min))
6287 (or (eq (char-after) ?\s
) (eq (char-after) ?
\t)))
6288 (beginning-of-line 0)))
6289 (when (or (eq (char-after) ?\s
) (eq (char-after) ?
\t)
6290 (search-forward ":" (point-at-eol) t
))
6291 ;; We are a bit more lacks than the RFC and allow any positive number of WSP
6293 (skip-chars-forward " \t" (point-at-eol))
6296 (defun message-beginning-of-line (&optional n
)
6297 "Move point to beginning of header value or to beginning of line.
6298 The prefix argument N is passed directly to `beginning-of-line'.
6300 This command is identical to `beginning-of-line' if point is
6301 outside the message header or if the option
6302 `message-beginning-of-line' is nil.
6304 If point is in the message header and on a header line, move
6305 point to the beginning of the header value or the beginning of
6306 line, whichever is closer. If point is already at beginning of
6307 line, move point to beginning of header value. Therefore,
6308 repeated calls will toggle point between beginning of field and
6311 When called without a prefix argument, header value spanning
6312 multiple lines is treated as a single line. Otherwise, even if
6313 N is 1, when point is on a continuation header line, it will be
6314 moved to the beginning "
6317 ;; Go to beginning of header or beginning of line.
6318 ((and message-beginning-of-line
(message-point-in-header-p))
6319 (let* ((point (point))
6320 (bol (progn (beginning-of-line n
) (point)))
6321 (boh (message-beginning-of-header visual-line-mode
)))
6322 (goto-char (if (and boh
(or (< boh point
) (= bol point
))) boh bol
))))
6323 ;; Go to beginning of visual line
6325 (beginning-of-visual-line n
))
6326 ;; Go to beginning of line.
6327 ((beginning-of-line n
))))
6329 (defun message-buffer-name (type &optional to group
)
6330 "Return a new (unique) buffer name based on TYPE and TO."
6332 ;; Generate a new buffer name The Message Way.
6333 ((memq message-generate-new-buffers
'(unique t
))
6334 (generate-new-buffer-name
6338 (or (car (mail-extract-address-components to
))
6341 (if (and group
(not (string= group
""))) (concat " on " group
) "")
6343 ;; Check whether `message-generate-new-buffers' is a function,
6344 ;; and if so, call it.
6345 ((functionp message-generate-new-buffers
)
6346 (funcall message-generate-new-buffers type to group
))
6347 ((eq message-generate-new-buffers
'unsent
)
6348 (generate-new-buffer-name
6349 (concat "*unsent " type
6352 (or (car (mail-extract-address-components to
))
6355 (if (and group
(not (string= group
""))) (concat " on " group
) "")
6357 ;; Search for the existing message buffer with the specified name.
6359 (let* ((new (if (eq message-generate-new-buffers
'standard
)
6360 (generate-new-buffer-name (concat "*" type
" message*"))
6361 (let ((message-generate-new-buffers 'unique
))
6362 (message-buffer-name type to group
))))
6363 (regexp (concat "\\`"
6365 (if (string-match "<[0-9]+>\\'" new
)
6366 (substring new
0 (match-beginning 0))
6368 "\\(?:<\\([0-9]+\\)>\\)?\\'"))
6369 (case-fold-search nil
))
6376 (when (and (string-match regexp
(setq b
(buffer-name b
)))
6377 (eq (with-current-buffer b major-mode
)
6379 (cons (string-to-number (or (match-string 1 b
) "1"))
6382 'car-less-than-car
)))
6385 (defun message-pop-to-buffer (name &optional switch-function
)
6386 "Pop to buffer NAME, and warn if it already exists and is modified."
6387 (let ((buffer (get-buffer name
)))
6389 (buffer-name buffer
))
6390 (let ((window (get-buffer-window buffer
0)))
6392 ;; Raise the frame already displaying the message buffer.
6394 (select-frame-set-input-focus (window-frame window
))
6395 (select-window window
))
6396 (funcall (or switch-function
#'pop-to-buffer
) buffer
)
6397 (set-buffer buffer
))
6398 (when (and (buffer-modified-p)
6401 "Message already being composed; erase? ")
6403 (error "Message being composed")))
6404 (funcall (or switch-function
'pop-to-buffer-same-window
)
6410 (defun message-do-send-housekeeping ()
6411 "Kill old message buffers."
6412 ;; We might have sent this buffer already. Delete it from the
6414 (setq message-buffer-list
(delq (current-buffer) message-buffer-list
))
6415 (while (and message-max-buffers
6417 (>= (length message-buffer-list
) message-max-buffers
))
6418 ;; Kill the oldest buffer -- unless it has been changed.
6419 (let ((buffer (pop message-buffer-list
)))
6420 (when (and (buffer-name buffer
)
6421 (not (buffer-modified-p buffer
)))
6422 (kill-buffer buffer
))))
6423 ;; Rename the buffer.
6424 (if message-send-rename-function
6425 (funcall message-send-rename-function
)
6426 (message-default-send-rename-function))
6427 ;; Push the current buffer onto the list.
6428 (when message-max-buffers
6429 (setq message-buffer-list
6430 (nconc message-buffer-list
(list (current-buffer))))))
6432 (defun message-default-send-rename-function ()
6433 ;; Note: mail-abbrevs of XEmacs renames buffer name behind Gnus.
6435 "\\`\\*\\(sent \\|unsent \\)?\\(.+\\)\\*[^\\*]*\\|\\`mail to "
6437 (let ((name (match-string 2 (buffer-name)))
6439 (if (not (or (null name
)
6440 (string-equal name
"mail")
6441 (string-equal name
"posting")))
6442 (setq name
(concat "*sent " name
"*"))
6443 (message-narrow-to-headers)
6444 (setq to
(message-fetch-field "to"))
6445 (setq group
(message-fetch-field "newsgroups"))
6449 (to (concat "*sent mail to "
6450 (or (car (mail-extract-address-components to
))
6452 ((and group
(not (string= group
"")))
6453 (concat "*sent posting on " group
"*"))
6454 (t "*sent mail*"))))
6455 (unless (string-equal name
(buffer-name))
6456 (rename-buffer name t
)))))
6458 (defun message-mail-user-agent ()
6460 ((not message-mail-user-agent
) nil
)
6461 ((eq message-mail-user-agent t
) mail-user-agent
)
6462 (t message-mail-user-agent
))))
6463 (if (memq mua
'(message-user-agent gnus-user-agent
))
6467 ;; YANK-ACTION, if non-nil, can be a buffer or a yank action of the
6468 ;; form (FUNCTION . ARGS).
6469 (defun message-setup (headers &optional yank-action actions
6470 continue switch-function return-action
)
6471 (let ((mua (message-mail-user-agent))
6473 (if (not (and message-this-is-mail mua
))
6474 (message-setup-1 headers yank-action actions return-action
)
6475 (setq headers
(copy-sequence headers
))
6476 (setq field
(assq 'Subject headers
))
6478 (setq subject
(cdr field
))
6479 (setq headers
(delq field headers
)))
6480 (setq field
(assq 'To headers
))
6482 (setq to
(cdr field
))
6483 (setq headers
(delq field headers
)))
6484 (let ((mail-user-agent mua
))
6485 (compose-mail to subject
6486 (mapcar (lambda (item)
6488 (format "%s" (car item
))
6491 continue switch-function
6492 (if (bufferp yank-action
)
6493 (list 'insert-buffer yank-action
)
6497 (defun message-headers-to-generate (headers included-headers excluded-headers
)
6498 "Return a list that includes all headers from HEADERS.
6499 If INCLUDED-HEADERS is a list, just include those headers. If it is
6500 t, include all headers. In any case, headers from EXCLUDED-HEADERS
6504 (dolist (header headers
)
6505 (setq header-name
(cond
6506 ((and (consp header
)
6507 (eq (car header
) 'optional
))
6508 ;; On the form (optional . Header)
6511 ;; On the form (Header . function)
6516 (when (and (not (memq header-name excluded-headers
))
6517 (or (eq included-headers t
)
6518 (memq header-name included-headers
)))
6519 (push header result
)))
6522 (defun message-setup-1 (headers &optional yank-action actions return-action
)
6523 (dolist (action actions
)
6525 (add-to-list 'message-send-actions
6526 `(apply ',(car action
) ',(cdr action
)))))
6527 (setq message-return-action return-action
)
6528 (setq message-reply-buffer
6529 (if (and (consp yank-action
)
6530 (eq (car yank-action
) 'insert-buffer
))
6533 (goto-char (point-min))
6534 ;; Insert all the headers.
6537 (alist message-header-format-alist
))
6539 (unless (assq (caar h
) message-header-format-alist
)
6540 (push (list (caar h
)) alist
))
6544 (delete-region (point) (progn (forward-line -
1) (point)))
6545 (when message-default-headers
6547 (if (functionp message-default-headers
)
6548 (funcall message-default-headers
)
6549 message-default-headers
))
6550 (or (bolp) (insert ?
\n)))
6551 (insert (concat mail-header-separator
"\n"))
6553 ;; If a crash happens while replying, the auto-save file would *not* have a
6554 ;; `References:' header if `message-generate-headers-first' was nil.
6555 ;; Therefore, always generate it first.
6556 (let ((message-generate-headers-first
6557 (if (eq message-generate-headers-first t
)
6559 (append message-generate-headers-first
'(References)))))
6560 (when (message-news-p)
6561 (when message-default-news-headers
6562 (insert message-default-news-headers
)
6563 (or (bolp) (insert ?
\n)))
6564 (message-generate-headers
6565 (message-headers-to-generate
6566 (append message-required-news-headers
6567 message-required-headers
)
6568 message-generate-headers-first
6570 (when (message-mail-p)
6571 (when message-default-mail-headers
6572 (insert message-default-mail-headers
)
6573 (or (bolp) (insert ?
\n)))
6574 (message-generate-headers
6575 (message-headers-to-generate
6576 (append message-required-mail-headers
6577 message-required-headers
)
6578 message-generate-headers-first
6579 '(Lines Subject
)))))
6580 (run-hooks 'message-signature-setup-hook
)
6581 (message-insert-signature)
6583 (message-narrow-to-headers)
6584 (run-hooks 'message-header-setup-hook
))
6585 (setq buffer-undo-list nil
)
6586 (when message-generate-hashcash
6587 ;; Generate hashcash headers for recipients already known
6588 (mail-add-payment-async))
6589 ;; Gnus posting styles are applied via buffer-local `message-setup-hook'
6591 (run-hooks 'message-setup-hook
)
6592 ;; Do this last to give it precedence over posting styles, etc.
6593 (when (message-mail-p)
6595 (message-narrow-to-headers)
6596 (if message-alternative-emails
6597 (message-use-alternative-email-as-from))))
6598 (message-position-point)
6599 ;; Allow correct handling of `message-checksum' in `message-yank-original':
6600 (set-buffer-modified-p nil
)
6602 ;; rmail-start-mail expects message-mail to return t (Bug#9392)
6605 (defun message-set-auto-save-file-name ()
6606 "Associate the message buffer with a file in the drafts directory."
6607 (when message-auto-save-directory
6608 (unless (file-directory-p
6609 (directory-file-name message-auto-save-directory
))
6610 (make-directory message-auto-save-directory t
))
6612 (setq message-draft-article
6613 (nndraft-request-associate-buffer "drafts"))
6615 ;; If Gnus were alive, draft messages would be saved in the drafts folder.
6616 ;; But Gnus is not alive, so arrange to save the draft message in a
6617 ;; regular file in message-auto-save-directory. Append a unique
6618 ;; time-based suffix to the filename to allow multiple drafts to be saved
6619 ;; simultaneously without overwriting each other (which mimics the
6620 ;; functionality of the Gnus drafts folder).
6621 (setq buffer-file-name
(expand-file-name
6623 (if (memq system-type
6624 '(ms-dos windows-nt cygwin
))
6627 (format-time-string "-%Y%m%d-%H%M%S"))
6628 message-auto-save-directory
))
6629 (setq buffer-auto-save-file-name
(make-auto-save-file-name)))
6630 (clear-visited-file-modtime)
6631 (setq buffer-file-coding-system message-draft-coding-system
)))
6633 (defun message-disassociate-draft ()
6634 "Disassociate the message buffer from the drafts directory."
6635 (when message-draft-article
6636 (nndraft-request-expire-articles
6637 (list message-draft-article
) "drafts" nil t
)))
6639 (defun message-insert-headers ()
6640 "Generate the headers for the article."
6644 (message-narrow-to-headers)
6645 (when (message-news-p)
6646 (message-generate-headers
6649 (copy-sequence message-required-news-headers
)))))
6650 (when (message-mail-p)
6651 (message-generate-headers
6654 (copy-sequence message-required-mail-headers
))))))))
6659 ;;; Commands for interfacing with message
6663 (defun message-mail (&optional to subject other-headers continue
6664 switch-function yank-action send-actions
6665 return-action
&rest ignored
)
6666 "Start editing a mail message to be sent.
6667 OTHER-HEADERS is an alist of header/value pairs. CONTINUE says whether
6668 to continue editing a message already being composed. SWITCH-FUNCTION
6669 is a function used to switch to and display the mail buffer."
6671 (let ((message-this-is-mail t
)
6673 ;; Search for the existing message buffer if `continue' is non-nil.
6675 (setq message-buffers
(message-buffers)))
6676 (pop-to-buffer (car message-buffers
))
6677 ;; Start a new buffer.
6678 (unless (message-mail-user-agent)
6679 (message-pop-to-buffer (message-buffer-name "mail" to
) switch-function
))
6682 `((To .
,(or to
"")) (Subject .
,(or subject
"")))
6683 ;; C-h f compose-mail says that headers should be specified as
6684 ;; (string . value); however all the rest of message expects
6685 ;; headers to be symbols, not strings (eg message-header-format-alist).
6686 ;; http://lists.gnu.org/archive/html/emacs-devel/2011-01/msg00337.html
6687 ;; We need to convert any string input, eg from rmail-start-mail.
6688 (dolist (h other-headers other-headers
)
6689 (if (stringp (car h
)) (setcar h
(intern (capitalize (car h
)))))))
6690 yank-action send-actions continue switch-function
6694 (defun message-news (&optional newsgroups subject
)
6695 "Start editing a news article to be sent."
6697 (let ((message-this-is-news t
))
6698 (message-pop-to-buffer (message-buffer-name "posting" nil newsgroups
))
6699 (message-setup `((Newsgroups .
,(or newsgroups
""))
6700 (Subject .
,(or subject
""))))))
6702 (defun message-alter-recipients-discard-bogus-full-name (addrcell)
6703 "Discard mail address in full names.
6704 When the full name in reply headers contains the mail
6705 address (e.g. \"foo@bar <foo@bar>\"), discard full name.
6706 ADDRCELL is a cons cell where the car is the mail address and the
6707 cdr is the complete address (full name and mail address)."
6708 (if (string-match (concat (regexp-quote (car addrcell
)) ".*"
6709 (regexp-quote (car addrcell
)))
6711 (cons (car addrcell
) (car addrcell
))
6714 (defcustom message-alter-recipients-function nil
6715 "Function called to allow alteration of reply header structures.
6716 It is called in `message-get-reply-headers' for each recipient.
6717 The function is called with one parameter, a cons cell ..."
6718 :type
'(choice (const :tag
"None" nil
)
6719 (const :tag
"Discard bogus full name"
6720 message-alter-recipients-discard-bogus-full-name
)
6722 :version
"23.1" ;; No Gnus
6723 :group
'message-headers
)
6725 (defun message-get-reply-headers (wide &optional to-address address-headers
)
6726 (let (follow-to mct never-mct to cc author mft recipients extra
)
6727 ;; Find all relevant headers we need.
6729 (message-narrow-to-headers-or-head)
6730 ;; Gmane renames "To". Look at "Original-To", too, if it is present in
6731 ;; message-header-synonyms.
6732 (setq to
(or (message-fetch-field "to")
6733 (and (loop for synonym in message-header-synonyms
6734 when
(memq 'Original-To synonym
)
6736 (message-fetch-field "original-to")))
6737 cc
(message-fetch-field "cc")
6738 extra
(when message-extra-wide-headers
6739 (mapconcat 'identity
6740 (mapcar 'message-fetch-field
6741 message-extra-wide-headers
)
6743 mct
(message-fetch-field "mail-copies-to")
6744 author
(or (message-fetch-field "mail-reply-to")
6745 (message-fetch-field "reply-to"))
6746 mft
(and message-use-mail-followup-to
6747 (message-fetch-field "mail-followup-to")))
6748 ;; Make sure this message goes to the author if this is a wide
6749 ;; reply, since Reply-To address may be a list address a mailing
6750 ;; list server added.
6751 (when (and wide author
)
6752 (setq cc
(concat author
", " cc
)))
6753 (when (or wide
(not author
))
6754 (setq author
(or (message-fetch-field "from") ""))))
6756 ;; Handle special values of Mail-Copies-To.
6758 (cond ((or (equal (downcase mct
) "never")
6759 (equal (downcase mct
) "nobody"))
6762 ((or (equal (downcase mct
) "always")
6763 (equal (downcase mct
) "poster"))
6764 (setq mct author
))))
6767 ;; Build (textual) list of new recipient addresses.
6770 (setq recipients
(concat ", " to-address
))
6771 ;; If the author explicitly asked for a copy, we don't deny it to them.
6772 (if mct
(setq recipients
(concat recipients
", " mct
))))
6774 (setq recipients
(concat ", " author
)))
6776 (dolist (header address-headers
)
6777 (let ((value (message-fetch-field header
)))
6779 (setq recipients
(concat recipients
", " value
))))))
6781 (string-match "[^ \t,]" mft
)
6782 (or (not (eq message-use-mail-followup-to
'ask
))
6783 (message-y-or-n-p "Obey Mail-Followup-To? " t
"\
6784 You should normally obey the Mail-Followup-To: header. In this
6785 article, it has the value of
6789 which directs your response to " (if (string-match "," mft
)
6790 "the specified addresses"
6791 "that address only") ".
6793 Most commonly, Mail-Followup-To is used by a mailing list poster to
6794 express that responses should be sent to just the list, and not the
6797 If a message is posted to several mailing lists, Mail-Followup-To may
6798 also be used to direct the following discussion to one list only,
6799 because discussions that are spread over several lists tend to be
6800 fragmented and very difficult to follow.
6802 Also, some source/announcement lists are not intended for discussion;
6803 responses here are directed to other addresses.
6805 You may customize the variable `message-use-mail-followup-to', if you
6806 want to get rid of this query permanently.")))
6807 (setq recipients
(concat ", " mft
)))
6809 (setq recipients
(if never-mct
"" (concat ", " author
)))
6810 (if to
(setq recipients
(concat recipients
", " to
)))
6811 (if cc
(setq recipients
(concat recipients
", " cc
)))
6812 (if extra
(setq recipients
(concat recipients
", " extra
)))
6813 (if mct
(setq recipients
(concat recipients
", " mct
)))))
6814 (if (>= (length recipients
) 2)
6815 ;; Strip the leading ", ".
6816 (setq recipients
(substring recipients
2)))
6817 ;; Squeeze whitespace.
6818 (while (string-match "[ \t][ \t]+" recipients
)
6819 (setq recipients
(replace-match " " t t recipients
)))
6820 ;; Remove addresses that match `message-dont-reply-to-names'.
6822 (cond ((functionp message-dont-reply-to-names
)
6826 (mapcar (lambda (mail)
6827 (unless (funcall message-dont-reply-to-names
6828 (mail-strip-quoted-names mail
))
6830 (message-tokenize-header recipients
)))
6832 (t (let ((mail-dont-reply-to-names (message-dont-reply-to-names)))
6833 (mail-dont-reply-to recipients
)))))
6834 ;; Perhaps "Mail-Copies-To: never" removed the only address?
6835 (if (string-equal recipients
"")
6836 (setq recipients author
))
6837 ;; Convert string to a list of (("foo@bar" . "Name <Foo@BAR>") ...).
6841 (if message-alter-recipients-function
6842 (funcall message-alter-recipients-function
6843 (cons (downcase (mail-strip-quoted-names addr
))
6845 (cons (downcase (mail-strip-quoted-names addr
)) addr
)))
6846 (message-tokenize-header recipients
)))
6847 ;; Remove all duplicates.
6848 (let ((s recipients
))
6850 (let ((address (car (pop s
))))
6851 (while (assoc address s
)
6852 (setq recipients
(delq (assoc address s
) recipients
)
6853 s
(delq (assoc address s
) s
))))))
6855 ;; Remove hierarchical lists that are contained within each other,
6856 ;; if message-hierarchical-addresses is defined.
6857 (when message-hierarchical-addresses
6858 (let ((plain-addrs (mapcar 'car recipients
))
6861 (setq subaddrs
(assoc (car plain-addrs
)
6862 message-hierarchical-addresses
)
6863 plain-addrs
(cdr plain-addrs
))
6865 (setq subaddrs
(cdr subaddrs
))
6867 (setq recip
(assoc (car subaddrs
) recipients
)
6868 subaddrs
(cdr subaddrs
))
6870 (setq recipients
(delq recip recipients
))))))))
6872 (setq recipients
(message-prune-recipients recipients
))
6874 ;; Build the header alist. Allow the user to be asked whether
6875 ;; or not to reply to all recipients in a wide reply.
6876 (setq follow-to
(list (cons 'To
(cdr (pop recipients
)))))
6877 (when (and recipients
6878 (or (not message-wide-reply-confirm-recipients
)
6879 (y-or-n-p "Reply to all recipients? ")))
6880 (setq recipients
(mapconcat
6881 (lambda (addr) (cdr addr
)) recipients
", "))
6882 (if (string-match "^ +" recipients
)
6883 (setq recipients
(substring recipients
(match-end 0))))
6884 (push (cons 'Cc recipients
) follow-to
)))
6887 (defun message-prune-recipients (recipients)
6888 (dolist (rule message-prune-recipient-rules
)
6889 (let ((match (car rule
))
6892 (dolist (recipient recipients
)
6893 (setq address
(car recipient
))
6894 (when (string-match match address
)
6895 (setq dup-match
(replace-match (cadr rule
) nil nil address
))
6896 (dolist (recipient recipients
)
6897 ;; Don't delete the address that triggered this.
6898 (when (and (not (eq address
(car recipient
)))
6899 (string-match dup-match
(car recipient
)))
6900 (setq recipients
(delq recipient recipients
))))))))
6903 (defcustom message-simplify-subject-functions
6904 '(message-strip-list-identifiers
6905 message-strip-subject-re
6906 message-strip-subject-trailing-was
6907 message-strip-subject-encoded-words
)
6908 "List of functions taking a string argument that simplify subjects.
6909 The functions are applied when replying to a message.
6911 Useful functions to put in this list include:
6912 `message-strip-list-identifiers', `message-strip-subject-re',
6913 `message-strip-subject-trailing-was', and
6914 `message-strip-subject-encoded-words'."
6915 :version
"22.1" ;; Gnus 5.10.9
6916 :group
'message-various
6917 :type
'(repeat function
))
6919 (defun message-simplify-subject (subject &optional functions
)
6920 "Return simplified SUBJECT."
6923 (setq functions message-simplify-subject-functions
))
6924 (when (and (memq 'message-strip-list-identifiers functions
)
6925 gnus-list-identifiers
)
6926 (setq subject
(message-strip-list-identifiers subject
)))
6927 (when (memq 'message-strip-subject-re functions
)
6928 (setq subject
(concat "Re: " (message-strip-subject-re subject
))))
6929 (when (and (memq 'message-strip-subject-trailing-was functions
)
6930 message-subject-trailing-was-query
)
6931 (setq subject
(message-strip-subject-trailing-was subject
)))
6932 (when (memq 'message-strip-subject-encoded-words functions
)
6933 (setq subject
(message-strip-subject-encoded-words subject
)))
6937 (defun message-reply (&optional to-address wide switch-function
)
6938 "Start editing a reply to the article in the current buffer."
6940 (require 'gnus-sum
) ; for gnus-list-identifiers
6941 (let ((cur (current-buffer))
6943 references message-id follow-to
6944 (inhibit-point-motion-hooks t
)
6945 (message-this-is-mail t
)
6948 (message-narrow-to-head-1)
6949 ;; Allow customizations to have their say.
6951 ;; This is a regular reply.
6952 (when (functionp message-reply-to-function
)
6954 (setq follow-to
(funcall message-reply-to-function
))))
6955 ;; This is a followup.
6956 (when (functionp message-wide-reply-to-function
)
6959 (funcall message-wide-reply-to-function
)))))
6960 (setq message-id
(message-fetch-field "message-id" t
)
6961 references
(message-fetch-field "references")
6962 date
(message-fetch-field "date")
6963 from
(or (message-fetch-field "from") "nobody")
6964 subject
(or (message-fetch-field "subject") "none"))
6966 ;; Strip list identifiers, "Re: ", and "was:"
6967 (setq subject
(message-simplify-subject subject
))
6969 (when (and (setq gnus-warning
(message-fetch-field "gnus-warning"))
6970 (string-match "<[^>]+>" gnus-warning
))
6971 (setq message-id
(match-string 0 gnus-warning
)))
6974 (setq follow-to
(message-get-reply-headers wide to-address
))))
6977 `((Subject .
,subject
)
6979 (unless (message-mail-user-agent)
6980 (message-pop-to-buffer
6981 (message-buffer-name
6982 (if wide
"wide reply" "reply") from
6983 (if wide to-address nil
))
6985 (setq message-reply-headers
6986 (vector 0 (cdr (assq 'Subject headers
))
6987 from date message-id references
0 0 ""))
6988 (message-setup headers cur
))))
6991 (defun message-wide-reply (&optional to-address
)
6992 "Make a \"wide\" reply to the message in the current buffer."
6994 (message-reply to-address t
))
6997 (defun message-followup (&optional to-newsgroups
)
6998 "Follow up to the message in the current buffer.
6999 If TO-NEWSGROUPS, use that as the new Newsgroups line."
7001 (require 'gnus-sum
) ; for gnus-list-identifiers
7002 (let ((cur (current-buffer))
7003 from subject date reply-to mrt mct
7004 references message-id follow-to
7005 (inhibit-point-motion-hooks t
)
7006 (message-this-is-news t
)
7007 followup-to distribution newsgroups gnus-warning posted-to
)
7010 (goto-char (point-min))
7011 (if (search-forward "\n\n" nil t
)
7014 (when (functionp message-followup-to-function
)
7016 (funcall message-followup-to-function
)))
7017 (setq from
(message-fetch-field "from")
7018 date
(message-fetch-field "date")
7019 subject
(or (message-fetch-field "subject") "none")
7020 references
(message-fetch-field "references")
7021 message-id
(message-fetch-field "message-id" t
)
7022 followup-to
(message-fetch-field "followup-to")
7023 newsgroups
(message-fetch-field "newsgroups")
7024 posted-to
(message-fetch-field "posted-to")
7025 reply-to
(message-fetch-field "reply-to")
7026 mrt
(message-fetch-field "mail-reply-to")
7027 distribution
(message-fetch-field "distribution")
7028 mct
(message-fetch-field "mail-copies-to"))
7029 (when (and (setq gnus-warning
(message-fetch-field "gnus-warning"))
7030 (string-match "<[^>]+>" gnus-warning
))
7031 (setq message-id
(match-string 0 gnus-warning
)))
7032 ;; Remove bogus distribution.
7033 (when (and (stringp distribution
)
7034 (let ((case-fold-search t
))
7035 (string-match "world" distribution
)))
7036 (setq distribution nil
))
7037 ;; Strip list identifiers, "Re: ", and "was:"
7038 (setq subject
(message-simplify-subject subject
))
7041 (message-pop-to-buffer (message-buffer-name "followup" from newsgroups
))
7043 (setq message-reply-headers
7044 (vector 0 subject from date message-id references
0 0 ""))
7047 `((Subject .
,subject
)
7050 (list (cons 'Newsgroups to-newsgroups
)))
7051 (follow-to follow-to
)
7052 ((and followup-to message-use-followup-to
)
7055 ((equal (downcase followup-to
) "poster")
7056 (if (or (eq message-use-followup-to
'use
)
7057 (message-y-or-n-p "Obey Followup-To: poster? " t
"\
7058 You should normally obey the Followup-To: header.
7060 `Followup-To: poster' sends your response via e-mail instead of news.
7062 A typical situation where `Followup-To: poster' is used is when the poster
7063 does not read the newsgroup, so he wouldn't see any replies sent to it.
7065 You may customize the variable `message-use-followup-to', if you
7066 want to get rid of this query permanently."))
7068 (setq message-this-is-news nil
)
7069 (cons 'To
(or mrt reply-to from
"")))
7070 (cons 'Newsgroups newsgroups
)))
7072 (if (or (equal followup-to newsgroups
)
7073 (not (eq message-use-followup-to
'ask
))
7075 (concat "Obey Followup-To: " followup-to
"? ") t
"\
7076 You should normally obey the Followup-To: header.
7078 `Followup-To: " followup-to
"'
7079 directs your response to " (if (string-match "," followup-to
)
7080 "the specified newsgroups"
7081 "that newsgroup only") ".
7083 If a message is posted to several newsgroups, Followup-To is often
7084 used to direct the following discussion to one newsgroup only,
7085 because discussions that are spread over several newsgroup tend to
7086 be fragmented and very difficult to follow.
7088 Also, some source/announcement newsgroups are not intended for discussion;
7089 responses here are directed to other newsgroups.
7091 You may customize the variable `message-use-followup-to', if you
7092 want to get rid of this query permanently."))
7093 (cons 'Newsgroups followup-to
)
7094 (cons 'Newsgroups newsgroups
))))))
7096 `((Newsgroups .
,posted-to
)))
7098 `((Newsgroups .
,newsgroups
))))
7099 ,@(and distribution
(list (cons 'Distribution distribution
)))
7101 (not (or (equal (downcase mct
) "never")
7102 (equal (downcase mct
) "nobody"))))
7103 (list (cons 'Cc
(if (or (equal (downcase mct
) "always")
7104 (equal (downcase mct
) "poster"))
7105 (or mrt reply-to from
"")
7110 (defun message-is-yours-p ()
7111 "Non-nil means current article is yours.
7112 If you have added `cancel-messages' to `message-shoot-gnksa-feet', all articles
7113 are yours except those that have Cancel-Lock header not belonging to you.
7114 Instead of shooting GNKSA feet, you should modify `message-alternative-emails'
7115 to match all of yours addresses."
7116 ;; Canlock-logic as suggested by Per Abrahamsen
7117 ;; <abraham@dina.kvl.dk>
7119 ;; IF article has cancel-lock THEN
7120 ;; IF we can verify it THEN
7123 ;; error: cancellock: article is not yours
7125 ;; Use old rules, comparing sender...
7128 (message-narrow-to-head-1)
7129 (if (and (message-fetch-field "Cancel-Lock")
7130 (message-gnksa-enable-p 'canlock-verify
))
7131 (if (null (canlock-verify))
7133 (error "Failed to verify Cancel-lock: This article is not yours"))
7136 (message-gnksa-enable-p 'cancel-messages
)
7137 (and (setq sender
(message-fetch-field "sender"))
7138 (string-equal (downcase sender
)
7139 (downcase (message-make-sender))))
7140 ;; Email address in From field equals to our address
7141 (and (setq from
(message-fetch-field "from"))
7143 (downcase (car (mail-header-parse-address from
)))
7144 (downcase (car (mail-header-parse-address
7145 (message-make-from))))))
7146 ;; Email address in From field matches
7147 ;; 'message-alternative-emails' regexp or function.
7149 message-alternative-emails
7150 (cond ((functionp message-alternative-emails
)
7151 (funcall message-alternative-emails
7152 (mail-header-parse-address from
)))
7153 (t (string-match message-alternative-emails
7154 (car (mail-header-parse-address from
))))))))))))
7157 (defun message-cancel-news (&optional arg
)
7158 "Cancel an article you posted.
7159 If ARG, allow editing of the cancellation message."
7161 (unless (message-news-p)
7162 (error "This is not a news article; canceling is impossible"))
7163 (let (from newsgroups message-id distribution buf
)
7165 ;; Get header info from original article.
7167 (message-narrow-to-head-1)
7168 (setq from
(message-fetch-field "from")
7169 newsgroups
(message-fetch-field "newsgroups")
7170 message-id
(message-fetch-field "message-id" t
)
7171 distribution
(message-fetch-field "distribution")))
7172 ;; Make sure that this article was written by the user.
7173 (unless (message-is-yours-p)
7174 (error "This article is not yours"))
7175 (when (yes-or-no-p "Do you really want to cancel this article? ")
7176 ;; Make control message.
7179 (setq buf
(set-buffer (get-buffer-create " *message cancel*"))))
7181 (insert "Newsgroups: " newsgroups
"\n"
7183 "Subject: cancel " message-id
"\n"
7184 "Control: cancel " message-id
"\n"
7186 (concat "Distribution: " distribution
"\n")
7188 mail-header-separator
"\n"
7189 message-cancel-message
)
7190 (run-hooks 'message-cancel-hook
)
7192 (message "Canceling your article...")
7193 (if (let ((message-syntax-checks
7194 'dont-check-for-anything-just-trust-me
))
7195 (funcall message-send-news-function
))
7196 (message "Canceling your article...done"))
7197 (kill-buffer buf
))))))
7200 (defun message-supersede ()
7201 "Start composing a message to supersede the current message.
7202 This is done simply by taking the old article and adding a Supersedes
7203 header line with the old Message-ID."
7205 (let ((cur (current-buffer)))
7206 ;; Check whether the user owns the article that is to be superseded.
7207 (unless (message-is-yours-p)
7208 (error "This article is not yours"))
7209 ;; Get a normal message buffer.
7210 (message-pop-to-buffer (message-buffer-name "supersede"))
7211 (insert-buffer-substring cur
)
7213 (message-narrow-to-head-1)
7214 ;; Remove unwanted headers.
7215 (when message-ignored-supersedes-headers
7216 (message-remove-header message-ignored-supersedes-headers t
))
7217 (goto-char (point-min))
7218 (if (not (re-search-forward "^Message-ID: " nil t
))
7219 (error "No Message-ID in this article")
7220 (replace-match "Supersedes: " t t
))
7221 (goto-char (point-max))
7222 (insert mail-header-separator
)
7227 (defun message-recover ()
7228 "Reread contents of current buffer from its last auto-save file."
7230 (let ((file-name (make-auto-save-file-name)))
7231 (cond ((save-window-excursion
7232 (with-output-to-temp-buffer "*Directory*"
7233 (with-current-buffer standard-output
7235 (buffer-disable-undo standard-output
)
7236 (let ((default-directory "/"))
7238 "ls" nil standard-output nil
"-l" file-name
)))
7239 (yes-or-no-p (format "Recover auto save file %s? " file-name
)))
7240 (let ((buffer-read-only nil
))
7242 (insert-file-contents file-name nil
)))
7243 (t (error "message-recover canceled")))))
7245 ;;; Washing Subject:
7247 (defun message-wash-subject (subject)
7248 "Remove junk like \"Re:\", \"(fwd)\", etc. added to subject string SUBJECT.
7249 Previous forwarders, repliers, etc. may add it."
7252 (goto-char (point-min))
7253 ;; strip Re/Fwd stuff off the beginning
7254 (while (re-search-forward
7255 "\\([Rr][Ee]:\\|[Ff][Ww][Dd]\\(\\[[0-9]*\\]\\)?:\\|[Ff][Ww]:\\)" nil t
)
7258 ;; and gnus-style forwards [foo@bar.com] subject
7259 (goto-char (point-min))
7260 (while (re-search-forward "\\[[^ \t]*\\(@\\|\\.\\)[^ \t]*\\]" nil t
)
7264 (goto-char (point-max))
7265 (while (re-search-backward "([Ff][Ww][Dd])" nil t
)
7268 ;; and finally, any whitespace that was left-over
7269 (goto-char (point-min))
7270 (while (re-search-forward "^[ \t]+" nil t
)
7272 (goto-char (point-max))
7273 (while (re-search-backward "[ \t]+$" nil t
)
7278 ;;; Forwarding messages.
7280 (defvar message-forward-decoded-p nil
7281 "Non-nil means the original message is decoded.")
7283 (defun message-forward-subject-name-subject (subject)
7284 "Generate a SUBJECT for a forwarded message.
7285 The form is: [Source] Subject, where if the original message was mail,
7286 Source is the name of the sender, and if the original message was
7287 news, Source is the list of newsgroups is was posted to."
7288 (let* ((group (message-fetch-field "newsgroups"))
7289 (from (message-fetch-field "from"))
7292 (gnus-group-decoded-name group
)
7294 (car (gnus-extract-address-components from
))
7295 (cadr (gnus-extract-address-components from
))))
7298 (if message-forward-decoded-p
7300 (mail-decode-encoded-word-string prefix
))
7303 (defun message-forward-subject-author-subject (subject)
7304 "Generate a SUBJECT for a forwarded message.
7305 The form is: [Source] Subject, where if the original message was mail,
7306 Source is the sender, and if the original message was news, Source is
7307 the list of newsgroups is was posted to."
7308 (let* ((group (message-fetch-field "newsgroups"))
7311 (gnus-group-decoded-name group
)
7312 (or (message-fetch-field "from")
7315 (if message-forward-decoded-p
7317 (mail-decode-encoded-word-string prefix
))
7320 (defun message-forward-subject-fwd (subject)
7321 "Generate a SUBJECT for a forwarded message.
7322 The form is: Fwd: Subject, where Subject is the original subject of
7324 (if (string-match "^Fwd: " subject
)
7326 (concat "Fwd: " subject
)))
7328 (defun message-make-forward-subject ()
7329 "Return a Subject header suitable for the message in the current buffer."
7332 (message-narrow-to-head-1)
7333 (let ((funcs message-make-forward-subject-function
)
7334 (subject (message-fetch-field "Subject")))
7337 (if message-forward-decoded-p
7339 (mail-decode-encoded-word-string subject
))
7341 (when message-wash-forwarded-subjects
7342 (setq subject
(message-wash-subject subject
)))
7343 ;; Make sure funcs is a list.
7346 (setq funcs
(list funcs
)))
7347 ;; Apply funcs in order, passing subject generated by previous
7348 ;; func to the next one.
7349 (dolist (func funcs
)
7350 (when (functionp func
)
7351 (setq subject
(funcall func subject
))))
7354 (defvar gnus-article-decoded-p
)
7358 (defun message-forward (&optional news digest
)
7359 "Forward the current message via mail.
7360 Optional NEWS will use news to forward instead of mail.
7361 Optional DIGEST will use digest to forward."
7363 (let* ((cur (current-buffer))
7364 (message-forward-decoded-p
7365 (if (local-variable-p 'gnus-article-decoded-p
(current-buffer))
7366 gnus-article-decoded-p
;; In an article buffer.
7367 message-forward-decoded-p
))
7368 (subject (message-make-forward-subject)))
7370 (message-news nil subject
)
7371 (message-mail nil subject
))
7372 (message-forward-make-body cur digest
)))
7374 (defun message-forward-make-body-plain (forward-buffer)
7376 "\n-------------------- Start of forwarded message --------------------\n")
7378 (contents (with-current-buffer forward-buffer
(buffer-string)))
7380 (unless (multibyte-string-p contents
)
7381 (error "Attempt to insert unibyte string from the buffer \"%s\"\
7382 to the multibyte buffer \"%s\""
7383 (if (bufferp forward-buffer
)
7384 (buffer-name forward-buffer
)
7387 (insert (mm-with-multibyte-buffer
7390 (goto-char (point-min))
7391 (when (looking-at "From ")
7392 (replace-match "X-From-Line: "))
7394 (unless (bolp) (insert "\n"))
7397 "-------------------- End of forwarded message --------------------\n")
7398 (message-remove-ignored-headers b e
)))
7400 (defun message-remove-ignored-headers (b e
)
7401 (when (or message-forward-ignored-headers
7402 message-forward-included-headers
)
7404 (narrow-to-region b e
)
7406 (narrow-to-region (point)
7407 (or (search-forward "\n\n" nil t
) (point)))
7408 (when message-forward-ignored-headers
7409 (let ((ignored (if (stringp message-forward-ignored-headers
)
7410 (list message-forward-ignored-headers
)
7411 message-forward-ignored-headers
)))
7412 (dolist (elem ignored
)
7413 (message-remove-header elem t
))))
7414 (when message-forward-included-headers
7415 (message-remove-header
7416 (if (listp message-forward-included-headers
)
7417 (regexp-opt message-forward-included-headers
)
7418 message-forward-included-headers
)
7421 (defun message-forward-make-body-mime (forward-buffer &optional beg end
)
7423 (insert "\n\n<#part type=message/rfc822 disposition=inline raw=t>\n")
7425 (narrow-to-region (point) (point))
7426 (insert-buffer-substring forward-buffer beg end
)
7427 (mml-quote-region (point-min) (point-max))
7428 (goto-char (point-min))
7429 (when (looking-at "From ")
7430 (replace-match "X-From-Line: "))
7431 (goto-char (point-max)))
7432 (insert "<#/part>\n")
7433 ;; Consider there is no illegible text.
7434 (add-text-properties
7436 `(no-illegible-text t rear-nonsticky t start-open t
))))
7438 (defun message-forward-make-body-mml (forward-buffer)
7439 (insert "\n\n<#mml type=message/rfc822 disposition=inline>\n")
7440 (let ((b (point)) e
)
7441 (if (not message-forward-decoded-p
)
7442 (let ((contents (with-current-buffer forward-buffer
(buffer-string))))
7443 (unless (multibyte-string-p contents
)
7444 (error "Attempt to insert unibyte string from the buffer \"%s\"\
7445 to the multibyte buffer \"%s\""
7446 (if (bufferp forward-buffer
)
7447 (buffer-name forward-buffer
)
7450 (insert (mm-with-multibyte-buffer
7453 (goto-char (point-min))
7454 (when (looking-at "From ")
7455 (replace-match "X-From-Line: "))
7458 (narrow-to-region (point) (point))
7459 (mml-insert-buffer forward-buffer
)
7460 (goto-char (point-min))
7461 (when (looking-at "From ")
7462 (replace-match "X-From-Line: "))
7463 (goto-char (point-max))))
7465 (insert "<#/mml>\n")
7466 (when (not message-forward-decoded-p
)
7467 (message-remove-ignored-headers b e
))))
7469 (defun message-forward-make-body-digest-plain (forward-buffer)
7471 "\n-------------------- Start of forwarded message --------------------\n")
7472 (mml-insert-buffer forward-buffer
)
7474 "\n-------------------- End of forwarded message --------------------\n"))
7476 (defun message-forward-make-body-digest-mime (forward-buffer)
7477 (insert "\n<#multipart type=digest>\n")
7478 (let ((b (point)) e
)
7479 (insert-buffer-substring forward-buffer
)
7481 (insert "<#/multipart>\n")
7483 (narrow-to-region b e
)
7485 (narrow-to-region (point)
7486 (or (search-forward "\n\n" nil t
) (point)))
7487 (delete-region (point-min) (point-max)))))
7489 (defun message-forward-make-body-digest (forward-buffer)
7490 (if message-forward-as-mime
7491 (message-forward-make-body-digest-mime forward-buffer
)
7492 (message-forward-make-body-digest-plain forward-buffer
)))
7494 (autoload 'mm-uu-dissect-text-parts
"mm-uu")
7495 (autoload 'mm-uu-dissect
"mm-uu")
7497 (defun message-signed-or-encrypted-p (&optional dont-emulate-mime handles
)
7498 "Say whether the current buffer contains signed or encrypted message.
7499 If DONT-EMULATE-MIME is nil, this function does the MIME emulation on
7500 messages that don't conform to PGP/MIME described in RFC2015. HANDLES
7501 is for the internal use."
7503 (let ((mm-decrypt-option 'never
)
7504 (mm-verify-option 'never
))
7505 (if (setq handles
(mm-dissect-buffer nil t
))
7506 (unless dont-emulate-mime
7507 (mm-uu-dissect-text-parts handles
))
7508 (unless dont-emulate-mime
7509 (setq handles
(mm-uu-dissect))))))
7510 ;; Check text/plain message in which there is a signed or encrypted
7511 ;; body that has been encoded by B or Q.
7512 (unless (or handles dont-emulate-mime
)
7513 (let ((cur (current-buffer))
7514 (mm-decrypt-option 'never
)
7515 (mm-verify-option 'never
))
7517 (insert-buffer-substring cur
)
7518 (when (setq handles
(mm-dissect-buffer t t
))
7519 (if (and (bufferp (car handles
))
7520 (equal (mm-handle-media-type handles
) "text/plain"))
7523 (insert-buffer-substring (car handles
))
7524 (mm-decode-content-transfer-encoding
7525 (mm-handle-encoding handles
))
7526 (mm-destroy-parts handles
)
7527 (setq handles
(mm-uu-dissect)))
7528 (mm-destroy-parts handles
)
7529 (setq handles nil
))))))
7533 (dolist (handle (if (stringp (car handles
))
7534 (if (member (car handles
)
7535 '("multipart/signed"
7536 "multipart/encrypted"))
7540 (if (stringp (car handle
))
7541 (when (message-signed-or-encrypted-p dont-emulate-mime handle
)
7543 (when (and (bufferp (car handle
))
7544 (equal (mm-handle-media-type handle
)
7546 (with-current-buffer (mm-handle-buffer handle
)
7547 (when (message-signed-or-encrypted-p dont-emulate-mime
)
7548 (throw 'found t
)))))))
7549 (mm-destroy-parts handles
))))
7552 (defun message-forward-make-body (forward-buffer &optional digest
)
7553 ;; Put point where we want it before inserting the forwarded
7555 (if message-forward-before-signature
7557 (goto-char (point-max)))
7559 (message-forward-make-body-digest forward-buffer
)
7560 (if message-forward-as-mime
7561 (if (and message-forward-show-mml
7562 (not (and (eq message-forward-show-mml
'best
)
7563 ;; Use the raw form in the body if it contains
7564 ;; signed or encrypted message so as not to be
7565 ;; destroyed by re-encoding.
7566 (with-current-buffer forward-buffer
7568 (message-signed-or-encrypted-p)
7570 (message-forward-make-body-mml forward-buffer
)
7571 (message-forward-make-body-mime forward-buffer
))
7572 (message-forward-make-body-plain forward-buffer
)))
7573 (message-position-point))
7575 (declare-function rmail-toggle-header
"rmail" (&optional arg
))
7578 (defun message-forward-rmail-make-body (forward-buffer)
7579 (save-window-excursion
7580 (set-buffer forward-buffer
)
7581 (when (rmail-msg-is-pruned)
7582 (rmail-toggle-header 0)))
7583 (message-forward-make-body forward-buffer
))
7585 ;; Fixme: Should have defcustom.
7587 (defun message-insinuate-rmail ()
7588 "Let RMAIL use message to forward."
7590 (setq rmail-enable-mime-composing t
)
7591 (setq rmail-insert-mime-forwarded-message-function
7592 'message-forward-rmail-make-body
))
7594 (defvar message-inhibit-body-encoding nil
)
7597 (defun message-resend (address)
7598 "Resend the current article to ADDRESS."
7600 (list (message-read-from-minibuffer "Resend message to: ")))
7601 (message "Resending message to %s..." address
)
7603 (let ((cur (current-buffer))
7605 ;; We first set up a normal mail buffer.
7606 (unless (message-mail-user-agent)
7607 (set-buffer (get-buffer-create " *message resend*"))
7608 (let ((inhibit-read-only t
))
7610 (let ((message-this-is-mail t
)
7611 message-generate-hashcash
7613 (message-setup `((To .
,address
))))
7614 ;; Insert our usual headers.
7615 (message-generate-headers '(From Date To Message-ID
))
7616 (message-narrow-to-headers)
7617 (when (setq gcc
(mail-fetch-field "gcc" nil t
))
7618 (message-remove-header "gcc"))
7619 ;; Remove X-Draft-From header etc.
7620 (message-remove-header message-ignored-mail-headers t
)
7621 ;; Rename them all to "Resent-*".
7622 (goto-char (point-min))
7623 (while (re-search-forward "^[A-Za-z]" nil t
)
7628 (let ((inhibit-read-only t
))
7629 (delete-region (point) (point-max)))
7631 ;; Insert the message to be resent.
7632 (insert-buffer-substring cur
)
7633 (goto-char (point-min))
7634 (search-forward "\n\n")
7637 (narrow-to-region beg
(point))
7638 (message-remove-header message-ignored-resent-headers t
)
7639 (goto-char (point-max)))
7640 (insert mail-header-separator
)
7641 ;; Rename all old ("Also-")Resent headers.
7642 (while (re-search-backward "^\\(Also-\\)*Resent-" beg t
)
7645 ;; Quote any "From " lines at the beginning.
7647 (when (looking-at "From ")
7648 (replace-match "X-From-Line: "))
7650 (let ((message-inhibit-body-encoding
7651 ;; Don't do any further encoding if it looks like the
7652 ;; message has already been encoded.
7653 (let ((case-fold-search t
))
7654 (re-search-forward "^mime-version:" nil t
)))
7655 (message-inhibit-ecomplete t
)
7656 ;; We don't want smtpmail.el to encode anything, either.
7657 (sendmail-coding-system 'raw-text
)
7658 (select-safe-coding-system-function nil
)
7659 message-required-mail-headers
7660 message-generate-hashcash
7661 rfc2047-encode-encoded-words
)
7662 (message-send-mail))
7665 (insert "Gcc: " gcc
"\n"))
7666 (run-hooks 'message-sent-hook
)
7667 (kill-buffer (current-buffer)))
7668 (message "Resending message to %s...done" address
)))
7671 (defun message-bounce ()
7672 "Re-mail the current message.
7673 This only makes sense if the current message is a bounce message that
7674 contains some mail you have written which has been bounced back to
7677 (let ((handles (mm-dissect-buffer t
))
7679 (message-pop-to-buffer (message-buffer-name "bounce"))
7680 (if (stringp (car handles
))
7681 ;; This is a MIME bounce.
7682 (mm-insert-part (car (last handles
)))
7683 ;; This is a non-MIME bounce, so we try to remove things
7685 (mm-insert-part handles
)
7687 (goto-char (point-min))
7688 (re-search-forward "\n\n+" nil t
)
7689 (setq boundary
(point))
7690 ;; We remove everything before the bounced mail.
7691 (if (or (re-search-forward message-unsent-separator nil t
)
7693 (search-forward "\n\n" nil
'move
)
7694 (re-search-backward "^Return-Path:.*\n" boundary t
)))
7697 (delete-region (point-min)
7698 (if (re-search-forward "^[^ \n\t]+:" nil t
)
7701 (goto-char boundary
)
7702 (when (re-search-backward "^.?From .*\n" nil t
)
7703 (delete-region (match-beginning 0) (match-end 0)))))
7706 (message-narrow-to-head-1)
7707 (message-remove-header message-ignored-bounced-headers t
)
7708 (goto-char (point-max))
7709 (insert mail-header-separator
))
7710 (message-position-point)))
7713 ;;; Interactive entry points for new message buffers.
7717 (defun message-mail-other-window (&optional to subject
)
7718 "Like `message-mail' command, but display mail buffer in another window."
7720 (unless (message-mail-user-agent)
7721 (message-pop-to-buffer (message-buffer-name "mail" to
)
7722 'switch-to-buffer-other-window
))
7723 (let ((message-this-is-mail t
))
7724 (message-setup `((To .
,(or to
"")) (Subject .
,(or subject
"")))
7725 nil nil nil
'switch-to-buffer-other-window
)))
7728 (defun message-mail-other-frame (&optional to subject
)
7729 "Like `message-mail' command, but display mail buffer in another frame."
7731 (unless (message-mail-user-agent)
7732 (message-pop-to-buffer (message-buffer-name "mail" to
)
7733 'switch-to-buffer-other-frame
))
7734 (let ((message-this-is-mail t
))
7735 (message-setup `((To .
,(or to
"")) (Subject .
,(or subject
"")))
7736 nil nil nil
'switch-to-buffer-other-frame
)))
7739 (defun message-news-other-window (&optional newsgroups subject
)
7740 "Start editing a news article to be sent."
7742 (message-pop-to-buffer (message-buffer-name "posting" nil newsgroups
)
7743 'switch-to-buffer-other-window
)
7744 (let ((message-this-is-news t
))
7745 (message-setup `((Newsgroups .
,(or newsgroups
""))
7746 (Subject .
,(or subject
""))))))
7749 (defun message-news-other-frame (&optional newsgroups subject
)
7750 "Start editing a news article to be sent."
7752 (message-pop-to-buffer (message-buffer-name "posting" nil newsgroups
)
7753 'switch-to-buffer-other-frame
)
7754 (let ((message-this-is-news t
))
7755 (message-setup `((Newsgroups .
,(or newsgroups
""))
7756 (Subject .
,(or subject
""))))))
7760 ;; This code should be moved to underline.el (from which it is stolen).
7763 (defun message-bold-region (start end
)
7764 "Bold all nonblank characters in the region.
7765 Works by overstriking characters.
7766 Called from program, takes two arguments START and END
7767 which specify the range to operate on."
7770 (let ((end1 (make-marker)))
7771 (move-marker end1
(max start end
))
7772 (goto-char (min start end
))
7773 (while (< (point) end1
)
7774 (or (looking-at "[_\^@- ]")
7775 (insert (char-after) "\b"))
7776 (forward-char 1)))))
7779 (defun message-unbold-region (start end
)
7780 "Remove all boldness (overstruck characters) in the region.
7781 Called from program, takes two arguments START and END
7782 which specify the range to operate on."
7785 (let ((end1 (make-marker)))
7786 (move-marker end1
(max start end
))
7787 (goto-char (min start end
))
7788 (while (search-forward "\b" end1 t
)
7789 (if (eq (char-after) (char-after (- (point) 2)))
7790 (delete-char -
2))))))
7792 (defun message-exchange-point-and-mark ()
7793 "Exchange point and mark, but don't activate region if it was inactive."
7794 (goto-char (prog1 (mark t
)
7795 (set-marker (mark-marker) (point)))))
7797 ;; Support for toolbar
7798 (defvar tool-bar-mode
)
7800 ;; Note: The :set function in the `message-tool-bar*' variables will only
7801 ;; affect _new_ message buffers. We might add a function that walks thru all
7802 ;; message-mode buffers and force the update.
7803 (defun message-tool-bar-update (&optional symbol value
)
7804 "Update message mode toolbar.
7805 Setter function for custom variables."
7806 (setq-default message-tool-bar-map nil
)
7808 ;; When used as ":set" function:
7809 (set-default symbol value
)))
7811 (defcustom message-tool-bar
(if (eq gmm-tool-bar-style
'gnome
)
7812 'message-tool-bar-gnome
7813 'message-tool-bar-retro
)
7814 "Specifies the message mode tool bar.
7816 It can be either a list or a symbol referring to a list. See
7817 `gmm-tool-bar-from-list' for the format of the list. The
7818 default key map is `message-mode-map'.
7820 Pre-defined symbols include `message-tool-bar-gnome' and
7821 `message-tool-bar-retro'."
7822 :type
'(repeat gmm-tool-bar-list-item
)
7823 :type
'(choice (const :tag
"GNOME style" message-tool-bar-gnome
)
7824 (const :tag
"Retro look" message-tool-bar-retro
)
7825 (repeat :tag
"User defined list" gmm-tool-bar-item
)
7827 :version
"23.1" ;; No Gnus
7828 :initialize
'custom-initialize-default
7829 :set
'message-tool-bar-update
7832 (defcustom message-tool-bar-gnome
7833 '((ispell-message "spell" nil
7835 :visible
(not flyspell-mode
))
7836 (flyspell-buffer "spell" t
7838 :visible flyspell-mode
7839 :help
"Flyspell whole buffer")
7840 (message-send-and-exit "mail/send" t
:label
"Send")
7841 (message-dont-send "mail/save-draft")
7842 (mml-attach-file "attach" mml-mode-map
:vert-only t
)
7843 (mml-preview "mail/preview" mml-mode-map
)
7844 (mml-secure-message-sign-encrypt "lock" mml-mode-map
:visible nil
)
7845 (message-insert-importance-high "important" nil
:visible nil
)
7846 (message-insert-importance-low "unimportant" nil
:visible nil
)
7847 (message-insert-disposition-notification-to "receipt" nil
:visible nil
))
7848 "List of items for the message tool bar (GNOME style).
7850 See `gmm-tool-bar-from-list' for details on the format of the list."
7851 :type
'(repeat gmm-tool-bar-item
)
7852 :version
"23.1" ;; No Gnus
7853 :initialize
'custom-initialize-default
7854 :set
'message-tool-bar-update
7857 (defcustom message-tool-bar-retro
7858 '(;; Old Emacs 21 icon for consistency.
7859 (message-send-and-exit "gnus/mail-send")
7860 (message-kill-buffer "close")
7861 (message-dont-send "cancel")
7862 (mml-attach-file "attach" mml-mode-map
)
7863 (ispell-message "spell")
7864 (mml-preview "preview" mml-mode-map
)
7865 (message-insert-importance-high "gnus/important")
7866 (message-insert-importance-low "gnus/unimportant")
7867 (message-insert-disposition-notification-to "gnus/receipt"))
7868 "List of items for the message tool bar (retro style).
7870 See `gmm-tool-bar-from-list' for details on the format of the list."
7871 :type
'(repeat gmm-tool-bar-item
)
7872 :version
"23.1" ;; No Gnus
7873 :initialize
'custom-initialize-default
7874 :set
'message-tool-bar-update
7877 (defcustom message-tool-bar-zap-list
7878 '(new-file open-file dired kill-buffer write-file
7879 print-buffer customize help
)
7880 "List of icon items from the global tool bar.
7881 These items are not displayed on the message mode tool bar.
7883 See `gmm-tool-bar-from-list' for the format of the list."
7884 :type
'gmm-tool-bar-zap-list
7885 :version
"23.1" ;; No Gnus
7886 :initialize
'custom-initialize-default
7887 :set
'message-tool-bar-update
7890 (defvar image-load-path
)
7892 (defun message-make-tool-bar (&optional force
)
7893 "Make a message mode tool bar from `message-tool-bar-list'.
7894 When FORCE, rebuild the tool bar."
7895 (when (and (boundp 'tool-bar-mode
)
7897 (or (not message-tool-bar-map
) force
))
7898 (setq message-tool-bar-map
7900 (image-load-path-for-library
7901 "message" "mail/save-draft.xpm" nil t
))
7902 (image-load-path (cons (car load-path
) image-load-path
)))
7903 (gmm-tool-bar-from-list message-tool-bar
7904 message-tool-bar-zap-list
7905 'message-mode-map
))))
7906 message-tool-bar-map
)
7908 ;;; Group name completion.
7910 (defcustom message-newgroups-header-regexp
7911 "^\\(Newsgroups\\|Followup-To\\|Posted-To\\|Gcc\\):"
7912 "Regexp that match headers that lists groups."
7916 (defcustom message-completion-alist
7917 (list (cons message-newgroups-header-regexp
'message-expand-group
)
7918 '("^\\(Resent-\\)?\\(To\\|B?Cc\\):" . message-expand-name
)
7919 '("^\\(Reply-To\\|From\\|Mail-Followup-To\\|Mail-Copies-To\\):"
7920 . message-expand-name
)
7921 '("^\\(Disposition-Notification-To\\|Return-Receipt-To\\):"
7922 . message-expand-name
))
7923 "Alist of (RE . FUN). Use FUN for completion on header lines matching RE."
7926 :type
'(alist :key-type regexp
:value-type function
))
7928 (defcustom message-expand-name-databases
7930 "List of databases to try for name completion (`message-expand-name').
7931 Each element is a symbol and can be `bbdb' or `eudc'."
7933 :type
'(set (const bbdb
) (const eudc
)))
7935 (defcustom message-tab-body-function nil
7936 "Function to execute when `message-tab' (TAB) is executed in the body.
7937 If nil, the function bound in `text-mode-map' or `global-map' is executed."
7940 :link
'(custom-manual "(message)Various Commands")
7941 :type
'(choice (const nil
)
7944 (declare-function mail-abbrev-in-expansion-header-p
"mailabbrev" ())
7946 (defun message-tab ()
7947 "Complete names according to `message-completion-alist'.
7948 Execute function specified by `message-tab-body-function' when
7949 not in those headers. If that variable is nil, indent with the
7950 regular text mode tabbing command."
7953 ((let ((completion-fail-discreetly t
))
7954 (completion-at-point))
7955 ;; Completion was performed; nothing else to do.
7957 (message-tab-body-function (funcall message-tab-body-function
))
7958 (t (funcall (or (lookup-key text-mode-map
"\t")
7959 (lookup-key global-map
"\t")
7960 'indent-relative
)))))
7962 (defvar mail-abbrev-mode-regexp
)
7964 (defun message-completion-function ()
7965 (let ((alist message-completion-alist
))
7967 (let ((mail-abbrev-mode-regexp (caar alist
)))
7968 (not (mail-abbrev-in-expansion-header-p))))
7969 (setq alist
(cdr alist
)))
7971 (let ((fun (cdar alist
)))
7972 ;; Even if completion fails, return a non-nil value, so as to avoid
7973 ;; falling back to message-tab-body-function.
7974 (lambda () (funcall fun
) 'completion-attempted
)))))
7976 (defun message-expand-group ()
7977 "Expand the group name under point."
7978 (let ((b (save-excursion
7983 (skip-chars-forward "^:")
7986 (skip-chars-backward "^, \t\n") (point))))
7987 (completion-ignore-case t
)
7988 (e (progn (skip-chars-forward "^,\t\n ") (point)))
7990 (when (and (boundp 'gnus-active-hashtb
)
7994 (setq group
(symbol-name symbol
))
7995 (push (if (string-match "[^\000-\177]" group
)
7996 (gnus-group-decoded-name group
)
7999 gnus-active-hashtb
))
8000 (completion-in-region b e collection
)))
8002 (defun message-expand-name ()
8003 (cond ((and (memq 'eudc message-expand-name-databases
)
8004 (boundp 'eudc-protocol
)
8006 (eudc-expand-inline))
8007 ((and (memq 'bbdb message-expand-name-databases
)
8008 (fboundp 'bbdb-complete-name
))
8009 (let ((starttick (buffer-modified-tick)))
8010 (or (bbdb-complete-name)
8011 ;; Apparently, bbdb-complete-name can return nil even when
8012 ;; completion took place. So let's double check the buffer was
8014 (/= starttick
(buffer-modified-tick)))))
8020 (defun message-talkative-question (ask question show
&rest text
)
8021 "Call FUNCTION with argument QUESTION; optionally display TEXT... args.
8022 If SHOW is non-nil, the arguments TEXT... are displayed in a temp buffer.
8023 The following arguments may contain lists of values."
8025 (setq text
(message-flatten-list text
)))
8026 (save-window-excursion
8027 (with-output-to-temp-buffer " *MESSAGE information message*"
8028 (with-current-buffer " *MESSAGE information message*"
8031 (goto-char (point-min))))
8032 (funcall ask question
))
8033 (funcall ask question
)))
8035 (defun message-flatten-list (list)
8036 "Return a new, flat list that contains all elements of LIST.
8038 \(message-flatten-list \\='(1 (2 3 (4 5 (6))) 7))
8041 (apply 'append
(mapcar 'message-flatten-list list
)))
8045 (defun message-generate-new-buffer-clone-locals (name &optional varstr
)
8046 "Create and return a buffer with name based on NAME using `generate-new-buffer'.
8047 Then clone the local variables and values from the old buffer to the
8048 new one, cloning only the locals having a substring matching the
8050 (let ((oldbuf (current-buffer)))
8051 (with-current-buffer (generate-new-buffer name
)
8052 (message-clone-locals oldbuf varstr
)
8055 (defun message-clone-locals (buffer &optional varstr
)
8056 "Clone the local variables from BUFFER to the current buffer."
8057 (let ((locals (with-current-buffer buffer
(buffer-local-variables)))
8058 (regexp "^gnus\\|^nn\\|^message\\|^sendmail\\|^smtp\\|^user-mail-address"))
8061 (when (and (consp local
)
8063 (string-match regexp
(symbol-name (car local
)))
8065 (string-match varstr
(symbol-name (car local
)))))
8067 (set (make-local-variable (car local
))
8075 (defun message-encode-message-body ()
8076 (unless message-inhibit-body-encoding
8077 (let ((mail-parse-charset (or mail-parse-charset
8078 message-default-charset
))
8079 (case-fold-search t
)
8080 lines content-type-p
)
8083 (narrow-to-region (point) (point-max))
8084 (let ((new (mml-generate-mime)))
8086 (delete-region (point-min) (point-max))
8088 (goto-char (point-min))
8089 (if (eq (aref new
0) ?
\n)
8091 (search-forward "\n\n")
8092 (setq lines
(buffer-substring (point-min) (1- (point))))
8093 (delete-region (point-min) (point))))))
8095 (message-narrow-to-headers-or-head)
8096 (message-remove-header "Mime-Version")
8097 (goto-char (point-max))
8098 (insert "MIME-Version: 1.0\n")
8101 (setq content-type-p
8103 (re-search-backward "^Content-Type:" nil t
))))
8105 (message-narrow-to-headers-or-head)
8106 (message-remove-first-header "Content-Type")
8107 (message-remove-first-header "Content-Transfer-Encoding"))
8108 ;; We always make sure that the message has a Content-Type
8109 ;; header. This is because some broken MTAs and MUAs get
8110 ;; awfully confused when confronted with a message with a
8111 ;; MIME-Version header and without a Content-Type header. For
8112 ;; instance, Solaris' /usr/bin/mail.
8113 (unless content-type-p
8114 (goto-char (point-min))
8115 ;; For unknown reason, MIME-Version doesn't exist.
8116 (when (re-search-forward "^MIME-Version:" nil t
)
8118 (insert "Content-Type: text/plain; charset=us-ascii\n"))))))
8120 (defun message-read-from-minibuffer (prompt &optional initial-contents
)
8121 "Read from the minibuffer while providing abbrev expansion."
8122 (let ((minibuffer-setup-hook 'mail-abbrevs-setup
)
8123 (minibuffer-local-map message-minibuffer-local-map
))
8124 (read-from-minibuffer prompt initial-contents
)))
8126 (defun message-use-alternative-email-as-from ()
8127 "Set From field of the outgoing message to the first matching
8128 address in `message-alternative-emails', looking at To, Cc and
8129 From headers in the original article."
8130 (require 'mail-utils
)
8131 (let* ((fields '("To" "Cc" "From"))
8133 (message-tokenize-header
8134 (mail-strip-quoted-names
8135 (mapconcat 'message-fetch-reply-field fields
","))))
8136 (email (cond ((functionp message-alternative-emails
)
8137 (car (cl-remove-if-not message-alternative-emails emails
)))
8138 (t (loop for email in emails
8139 if
(string-match-p message-alternative-emails email
)
8141 (unless (or (not email
) (equal email user-mail-address
))
8142 (message-remove-header "From")
8143 (goto-char (point-max))
8144 (insert "From: " (let ((user-mail-address email
)) (message-make-from))
8147 (defun message-options-get (symbol)
8148 (cdr (assq symbol message-options
)))
8150 (defun message-options-set (symbol value
)
8151 (let ((the-cons (assq symbol message-options
)))
8154 (setcdr the-cons value
)
8155 (setq message-options
(delq the-cons message-options
)))
8157 (push (cons symbol value
) message-options
))))
8160 (defun message-options-set-recipient ()
8162 (message-narrow-to-headers-or-head)
8163 (message-options-set 'message-sender
8164 (mail-strip-quoted-names
8165 (message-fetch-field "from")))
8166 (message-options-set 'message-recipients
8167 (mail-strip-quoted-names
8168 (let ((to (message-fetch-field "to"))
8169 (cc (message-fetch-field "cc"))
8170 (bcc (message-fetch-field "bcc")))
8173 (if (and to cc
) ", ")
8175 (if (and (or to cc
) bcc
) ", ")
8178 (defun message-hide-headers ()
8179 "Hide headers based on the `message-hidden-headers' variable."
8180 (let ((regexps (if (stringp message-hidden-headers
)
8181 (list message-hidden-headers
)
8182 message-hidden-headers
))
8183 (inhibit-point-motion-hooks t
)
8184 (inhibit-modification-hooks t
)
8185 (end-of-headers (point-min)))
8189 (message-narrow-to-headers)
8190 (goto-char (point-min))
8192 (if (not (message-hide-header-p regexps
))
8193 (message-next-header)
8194 (let ((begin (point))
8196 (message-next-header)
8197 (setq header
(buffer-substring begin
(point))
8198 header-len
(- (point) begin
))
8199 (delete-region begin
(point))
8200 (goto-char end-of-headers
)
8202 (setq end-of-headers
8203 (+ end-of-headers header-len
))))))))
8204 (narrow-to-region end-of-headers
(point-max))))
8206 (defun message-hide-header-p (regexps)
8209 (when (eq (car regexps
) 'not
)
8212 (dolist (regexp regexps
)
8213 (setq result
(or result
(looking-at regexp
))))
8218 (declare-function ecomplete-add-item
"ecomplete" (type key text
))
8219 (declare-function ecomplete-save
"ecomplete" ())
8221 (defun message-put-addresses-in-ecomplete ()
8222 (require 'ecomplete
)
8223 (dolist (header '("to" "cc" "from" "reply-to"))
8224 (let ((value (message-field-value header
)))
8225 (dolist (string (mail-header-parse-addresses value
'raw
))
8227 (replace-regexp-in-string
8229 (replace-regexp-in-string "^ +\\| +$" "" string
)))
8230 (ecomplete-add-item 'mail
(car (mail-header-parse-address string
))
8234 (autoload 'ecomplete-display-matches
"ecomplete")
8236 (defun message-display-abbrev (&optional choose
)
8237 "Display the next possible abbrev for the text before point."
8238 (interactive (list t
))
8239 (when (and (memq (char-after (point-at-bol)) '(?C ?T ?
\t ?
))
8240 (message-point-in-header-p)
8243 (while (and (memq (char-after) '(?
\t ?
))
8244 (zerop (forward-line -
1))))
8245 (looking-at "To:\\|Cc:")))
8246 (let* ((end (point))
8247 (start (save-excursion
8248 (and (re-search-backward "[\n\t ]" nil t
)
8250 (word (when start
(buffer-substring start end
)))
8251 (match (when (and word
8252 (not (zerop (length word
))))
8253 (ecomplete-display-matches 'mail word choose
))))
8254 (when (and choose match
)
8255 (delete-region start end
)
8258 ;; To send pre-formatted letters like the example below, you can use
8259 ;; `message-send-form-letter':
8260 ;; --8<---------------cut here---------------start------------->8---
8261 ;; To: alice@invalid.invalid
8262 ;; Subject: Verification of your contact information
8263 ;; From: Contact verification <admin@foo.invalid>
8264 ;; --text follows this line--
8266 ;; please verify that your contact information is still valid:
8267 ;; Alice A, A avenue 11, 1111 A town, Austria
8268 ;; ----------next form letter message follows this line----------
8269 ;; To: bob@invalid.invalid
8270 ;; Subject: Verification of your contact information
8271 ;; From: Contact verification <admin@foo.invalid>
8272 ;; --text follows this line--
8274 ;; please verify that your contact information is still valid:
8275 ;; Bob, B street 22, 22222 Be town, Belgium
8276 ;; ----------next form letter message follows this line----------
8277 ;; To: charlie@invalid.invalid
8278 ;; Subject: Verification of your contact information
8279 ;; From: Contact verification <admin@foo.invalid>
8280 ;; --text follows this line--
8282 ;; please verify that your contact information is still valid:
8283 ;; Charlie Chaplin, C plaza 33, 33333 C town, Chile
8284 ;; --8<---------------cut here---------------end--------------->8---
8286 ;; FIXME: What is the most common term (circular letter, form letter, serial
8287 ;; letter, standard letter) for such kind of letter? See also
8288 ;; <http://en.wikipedia.org/wiki/Form_letter>
8290 ;; FIXME: Maybe extent message-mode's font-lock support to recognize
8291 ;; `message-form-letter-separator', i.e. highlight each message like a single
8294 (defcustom message-form-letter-separator
8295 "\n----------next form letter message follows this line----------\n"
8296 "Separator for `message-send-form-letter'."
8297 ;; :group 'message-form-letter
8298 :group
'message-various
8299 :version
"23.1" ;; No Gnus
8302 (defcustom message-send-form-letter-delay
1
8303 "Delay in seconds when sending a message with `message-send-form-letter'.
8304 Only used when `message-send-form-letter' is called with non-nil
8306 ;; :group 'message-form-letter
8307 :group
'message-various
8308 :version
"23.1" ;; No Gnus
8311 (defun message-send-form-letter (&optional force
)
8312 "Sent all form letter messages from current buffer.
8313 Unless FORCE, prompt before sending.
8315 The messages are separated by `message-form-letter-separator'.
8316 Header and body are separated by `mail-header-separator'."
8318 (let ((sent 0) (skipped 0)
8322 (goto-char (point-min))
8325 end
(if (search-forward message-form-letter-separator nil t
)
8326 (- (point) (length message-form-letter-separator
) -
1)
8330 (buffer-substring-no-properties start end
))
8331 (setq buff
(generate-new-buffer "*mail - form letter*"))
8332 (with-current-buffer buff
8335 (setq to
(message-fetch-field "To"))
8336 (switch-to-buffer buff
)
8338 (sit-for message-send-form-letter-delay
))
8340 (y-or-n-p (format-message "Send message to `%s'? " to
)))
8342 (setq sent
(1+ sent
))
8343 (message-send-and-exit))
8344 (message "Message to `%s' skipped." to
)
8345 (setq skipped
(1+ skipped
)))
8346 (when (buffer-live-p buff
)
8347 (kill-buffer buff
))))
8348 (message "%s message(s) sent, %s skipped." sent skipped
)))
8350 (defun message-replace-header (header new-value
&optional after force
)
8351 "Remove HEADER and insert the NEW-VALUE.
8352 If AFTER, insert after this header. If FORCE, insert new field
8353 even if NEW-VALUE is empty."
8354 ;; Similar to `nnheader-replace-header' but for message buffers.
8357 (message-narrow-to-headers)
8358 (message-remove-header header
))
8359 (when (or force
(> (length new-value
) 0))
8361 (message-position-on-field header after
)
8362 (message-position-on-field header
))
8363 (insert new-value
))))
8365 (defcustom message-recipients-without-full-name
8366 (list "ding@gnus.org"
8368 "emacs-devel@gnu.org"
8369 "emacs-pretest-bug@gnu.org"
8370 "bug-gnu-emacs@gnu.org")
8371 "Mail addresses that have no full name.
8372 Used in `message-simplify-recipients'."
8373 ;; Maybe the addresses could be extracted from
8374 ;; `gnus-parameter-to-list-alist'?
8375 :type
'(choice (const :tag
"None" nil
)
8377 :version
"23.1" ;; No Gnus
8378 :group
'message-headers
)
8380 (defun message-simplify-recipients ()
8382 (dolist (hdr '("Cc" "To"))
8383 (message-replace-header
8387 (if (and message-recipients-without-full-name
8389 (regexp-opt message-recipients-without-full-name
)
8393 (message-make-from (car addrcomp
) (cadr addrcomp
))
8395 (when (message-fetch-field hdr
)
8396 (mail-extract-address-components
8397 (message-fetch-field hdr
) t
))
8400 ;;; multipart/related and HTML support.
8402 (defun message-make-html-message-with-image-files (files)
8403 "Make a message containing the current dired-marked image files."
8404 (interactive (list (dired-get-marked-files nil current-prefix-arg
)))
8407 (insert "<#part type=text/html>\n\n")
8408 (dolist (file files
)
8409 (insert (format "<img src=%S>\n\n" file
)))
8410 (message-toggle-image-thumbnails)
8413 (defun message-toggle-image-thumbnails ()
8414 "For any included image files, insert a thumbnail of that image."
8416 (let ((displayed nil
))
8418 (goto-char (point-min))
8420 (when-let ((props (get-text-property (point) 'display
)))
8421 (when (and (consp props
)
8422 (eq (car props
) 'image
))
8423 (put-text-property (point) (1+ (point)) 'display nil
)
8424 (setq displayed t
)))
8428 (goto-char (point-min))
8429 (while (re-search-forward "<img.*src=\"\\([^\"]+\\).*>" nil t
)
8430 (let ((string (match-string 0))
8431 (file (match-string 1))
8432 (edges (window-inside-pixel-edges
8433 (get-buffer-window (current-buffer)))))
8434 (delete-region (match-beginning 0) (match-end 0))
8437 file
'imagemagick nil
8438 :max-width
(truncate
8439 (* 0.7 (- (nth 2 edges
) (nth 0 edges
))))
8440 :max-height
(truncate
8441 (* 0.5 (- (nth 3 edges
) (nth 1 edges
)))))
8446 (run-hooks 'message-load-hook
)
8452 ;;; message.el ends here