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 (completing-read "Followup To: "
2291 (if (boundp 'gnus-newsrc-alist
)
2293 nil nil
'("poster" .
0)
2294 (if (boundp 'gnus-group-history
)
2295 'gnus-group-history
))))
2296 (message-remove-header "Follow[Uu]p-[Tt]o" t
)
2297 (message-goto-newsgroups)
2299 ;; if we already did a crosspost before, kill old target
2300 (if (and message-cross-post-old-target
2302 (regexp-quote (concat "," message-cross-post-old-target
))
2305 ;; unless (followup is to poster or user explicitly asked not
2306 ;; to cross-post, or target-group is already in Newsgroups)
2307 ;; add target-group to Newsgroups line.
2309 ;; def: cross-post, req:no
2310 (and message-cross-post-default
(not current-prefix-arg
))
2311 ;; def: no-cross-post, req:yes
2312 (and (not message-cross-post-default
) current-prefix-arg
))
2313 (not (string-match "poster" target-group
))
2314 (not (string-match (regexp-quote target-group
)
2315 (message-fetch-field "Newsgroups"))))
2317 (insert (concat "," target-group
))))
2318 (end-of-line) ; ensure Followup: comes after Newsgroups:
2319 ;; unless new followup would be identical to Newsgroups line
2320 ;; make a new Followup-To line
2321 (if (not (string-match (concat "^[ \t]*"
2324 (message-fetch-field "Newsgroups")))
2325 (insert (concat "\nFollowup-To: " target-group
)))
2326 (setq message-cross-post-old-target target-group
))
2328 (defun message-cross-post-insert-note (target-group cross-post in-old
2330 "Insert a in message body note about a set Followup or Crosspost.
2331 If there have been previous notes, delete them. TARGET-GROUP specifies the
2332 group to Followup-To. When CROSS-POST is t, insert note about
2333 crossposting. IN-OLD specifies whether TARGET-GROUP is a member of
2334 OLD-GROUPS. OLD-GROUPS lists the old-groups the posting would have
2335 been made to before the user asked for a Crosspost."
2336 ;; start scanning body for previous uses
2337 (message-goto-signature)
2338 (let ((head (re-search-backward
2339 (concat "^" mail-header-separator
)
2340 nil t
))) ; just search in body
2341 (message-goto-signature)
2342 (while (re-search-backward
2343 (concat "^" (regexp-quote message-cross-post-note
) ".*")
2345 (message-delete-line))
2346 (message-goto-signature)
2347 (while (re-search-backward
2348 (concat "^" (regexp-quote message-followup-to-note
) ".*")
2350 (message-delete-line))
2352 (if (message-goto-signature)
2353 (re-search-backward message-signature-separator
))
2356 (string-match "^[ \t]*poster[ \t]*$" target-group
))
2357 (insert (concat message-followup-to-note target-group
"\n"))
2358 (insert (concat message-cross-post-note target-group
"\n")))))
2360 (defun message-cross-post-followup-to (target-group)
2361 "Crossposts message and set Followup-To to TARGET-GROUP.
2362 With prefix-argument just set Follow-Up, don't cross-post."
2364 (list ; Completion based on Gnus
2365 (completing-read "Followup To: "
2366 (if (boundp 'gnus-newsrc-alist
)
2368 nil nil
'("poster" .
0)
2369 (if (boundp 'gnus-group-history
)
2370 'gnus-group-history
))))
2371 (when (fboundp 'gnus-group-real-name
)
2372 (setq target-group
(gnus-group-real-name target-group
)))
2373 (cond ((not (or (null target-group
) ; new subject not empty
2374 (zerop (string-width target-group
))
2375 (string-match "^[ \t]*$" target-group
)))
2377 (let* ((old-groups (message-fetch-field "Newsgroups"))
2378 (in-old (string-match
2379 (regexp-quote target-group
)
2380 (or old-groups
""))))
2381 ;; check whether target exactly matches old Newsgroups
2382 (cond ((not old-groups
)
2383 (error "No current newsgroup"))
2387 (regexp-quote target-group
)
2390 ;; yes, Newsgroups line must change
2391 (message-cross-post-followup-to-header target-group
)
2392 ;; insert note whether we do cross-post or followup-to
2393 (funcall message-cross-post-note-function
2395 (if (or (and message-cross-post-default
2396 (not current-prefix-arg
))
2397 (and (not message-cross-post-default
)
2398 current-prefix-arg
)) t
)
2399 in-old old-groups
))))))))
2401 ;;; Reduce To: to Cc: or Bcc: header
2403 (defun message-reduce-to-to-cc ()
2404 "Replace contents of To: header with contents of Cc: or Bcc: header."
2407 (save-restriction (message-narrow-to-headers)
2408 (message-fetch-field "cc")))
2410 (if (and (not cc-content
)
2413 (message-narrow-to-headers)
2414 (message-fetch-field "bcc"))))
2419 (message-delete-line)
2420 (insert (concat "To: " cc-content
"\n"))
2422 (message-narrow-to-headers)
2423 (message-remove-header (if bcc
2427 ;;; End of functions adopted from `message-utils.el'.
2429 (defun message-remove-header (header &optional is-regexp first reverse
)
2430 "Remove HEADER in the narrowed buffer.
2431 If IS-REGEXP, HEADER is a regular expression.
2432 If FIRST, only remove the first instance of the header.
2433 If REVERSE, remove headers that doesn't match HEADER.
2434 Return the number of headers removed."
2435 (goto-char (point-min))
2436 (let ((regexp (if is-regexp header
(concat "^" (regexp-quote header
) ":")))
2438 (case-fold-search t
)
2440 (while (and (not (eobp))
2443 (not (looking-at regexp
))
2444 (looking-at regexp
))
2451 ;; There might be a continuation header, so we have to search
2452 ;; until we find a new non-continuation line.
2455 (if (re-search-forward "^[^ \t]" nil t
)
2456 (goto-char (match-beginning 0))
2459 (if (re-search-forward "^[^ \t]" nil t
)
2460 (goto-char (match-beginning 0))
2461 (goto-char (point-max)))))
2464 (defun message-remove-first-header (header)
2465 "Remove the first instance of HEADER if there is more than one."
2467 (regexp (concat "^" (regexp-quote header
) ":")))
2469 (goto-char (point-min))
2470 (while (re-search-forward regexp nil t
)
2473 (message-remove-header header nil t
)
2476 (defun message-narrow-to-headers ()
2477 "Narrow the buffer to the head of the message."
2480 (goto-char (point-min))
2481 (if (re-search-forward
2482 (concat "^" (regexp-quote mail-header-separator
) "\n") nil t
)
2485 (goto-char (point-min)))
2487 (defun message-narrow-to-head-1 ()
2488 "Like `message-narrow-to-head'. Don't widen."
2490 (goto-char (point-min))
2491 (if (search-forward "\n\n" nil
1)
2494 (goto-char (point-min)))
2496 ;; FIXME: clarify difference: message-narrow-to-head,
2497 ;; message-narrow-to-headers-or-head, message-narrow-to-headers
2498 (defun message-narrow-to-head ()
2499 "Narrow the buffer to the head of the message.
2500 Point is left at the beginning of the narrowed-to region."
2502 (message-narrow-to-head-1))
2504 (defun message-narrow-to-headers-or-head ()
2505 "Narrow the buffer to the head of the message."
2508 (goto-char (point-min))
2509 (if (re-search-forward (concat "\\(\n\\)\n\\|^\\("
2510 (regexp-quote mail-header-separator
)
2513 (or (match-end 1) (match-beginning 2))
2515 (goto-char (point-min)))
2517 (defun message-news-p ()
2518 "Say whether the current buffer contains a news message."
2519 (and (not message-this-is-mail
)
2520 (or message-this-is-news
2523 (message-narrow-to-headers)
2524 (and (message-fetch-field "newsgroups")
2525 (not (message-fetch-field "posted-to"))))))))
2527 (defun message-mail-p ()
2528 "Say whether the current buffer contains a mail message."
2529 (and (not message-this-is-news
)
2530 (or message-this-is-mail
2533 (message-narrow-to-headers)
2534 (or (message-fetch-field "to")
2535 (message-fetch-field "cc")
2536 (message-fetch-field "bcc")))))))
2538 (defun message-subscribed-p ()
2539 "Say whether we need to insert a MFT header."
2540 (or message-subscribed-regexps
2541 message-subscribed-addresses
2542 message-subscribed-address-file
2543 message-subscribed-address-functions
))
2545 (defun message-next-header ()
2546 "Go to the beginning of the next header."
2548 (or (eobp) (forward-char 1))
2549 (not (if (re-search-forward "^[^ \t]" nil t
)
2551 (goto-char (point-max)))))
2553 (defun message-sort-headers-1 ()
2554 "Sort the buffer as headers using `message-rank' text props."
2555 (goto-char (point-min))
2558 nil
'message-next-header
2560 (message-next-header)
2564 (or (get-text-property (point) 'message-rank
)
2567 (defun message-sort-headers ()
2568 "Sort the headers of the current message according to `message-header-format-alist'."
2572 (let ((max (1+ (length message-header-format-alist
)))
2574 (message-narrow-to-headers)
2575 (while (re-search-forward "^[^ \n]+:" nil t
)
2577 (match-beginning 0) (1+ (match-beginning 0))
2579 (if (setq rank
(length (memq (assq (intern (buffer-substring
2581 (1- (match-end 0))))
2582 message-header-format-alist
)
2583 message-header-format-alist
)))
2586 (message-sort-headers-1))))
2588 (defun message-kill-address ()
2589 "Kill the address under point."
2591 (let ((start (point)))
2592 (message-skip-to-next-address)
2593 (kill-region start
(if (bolp) (1- (point)) (point)))))
2596 (autoload 'Info-goto-node
"info")
2597 (defvar mml2015-use
)
2599 (defun message-info (&optional arg
)
2600 "Display the Message manual.
2602 Prefixed with one \\[universal-argument], display the Emacs MIME
2603 manual. With two \\[universal-argument]'s, display the EasyPG or
2604 PGG manual, depending on the value of `mml2015-use'."
2606 (info (format "(%s)Top"
2610 ((eq arg
4) 'emacs-mime
)
2611 ((and (not (booleanp arg
))
2625 (defvar message-mode-map nil
)
2627 (unless message-mode-map
2628 (setq message-mode-map
(make-keymap))
2629 (set-keymap-parent message-mode-map text-mode-map
)
2630 (define-key message-mode-map
"\C-c?" 'describe-mode
)
2632 (define-key message-mode-map
"\C-c\C-f\C-t" 'message-goto-to
)
2633 (define-key message-mode-map
"\C-c\C-f\C-o" 'message-goto-from
)
2634 (define-key message-mode-map
"\C-c\C-f\C-b" 'message-goto-bcc
)
2635 (define-key message-mode-map
"\C-c\C-f\C-w" 'message-goto-fcc
)
2636 (define-key message-mode-map
"\C-c\C-f\C-c" 'message-goto-cc
)
2637 (define-key message-mode-map
"\C-c\C-f\C-s" 'message-goto-subject
)
2638 (define-key message-mode-map
"\C-c\C-f\C-r" 'message-goto-reply-to
)
2639 (define-key message-mode-map
"\C-c\C-f\C-n" 'message-goto-newsgroups
)
2640 (define-key message-mode-map
"\C-c\C-f\C-d" 'message-goto-distribution
)
2641 (define-key message-mode-map
"\C-c\C-f\C-f" 'message-goto-followup-to
)
2642 (define-key message-mode-map
"\C-c\C-f\C-m" 'message-goto-mail-followup-to
)
2643 (define-key message-mode-map
"\C-c\C-f\C-k" 'message-goto-keywords
)
2644 (define-key message-mode-map
"\C-c\C-f\C-u" 'message-goto-summary
)
2645 (define-key message-mode-map
"\C-c\C-f\C-i"
2646 'message-insert-or-toggle-importance
)
2647 (define-key message-mode-map
"\C-c\C-f\C-a"
2648 'message-generate-unsubscribed-mail-followup-to
)
2650 ;; modify headers (and insert notes in body)
2651 (define-key message-mode-map
"\C-c\C-fs" 'message-change-subject
)
2653 (define-key message-mode-map
"\C-c\C-fx" 'message-cross-post-followup-to
)
2654 ;; prefix+message-cross-post-followup-to = same w/o cross-post
2655 (define-key message-mode-map
"\C-c\C-ft" 'message-reduce-to-to-cc
)
2656 (define-key message-mode-map
"\C-c\C-fa" 'message-add-archive-header
)
2657 ;; mark inserted text
2658 (define-key message-mode-map
"\C-c\M-m" 'message-mark-inserted-region
)
2659 (define-key message-mode-map
"\C-c\M-f" 'message-mark-insert-file
)
2661 (define-key message-mode-map
"\C-c\C-b" 'message-goto-body
)
2662 (define-key message-mode-map
"\C-c\C-i" 'message-goto-signature
)
2664 (define-key message-mode-map
"\C-c\C-t" 'message-insert-to
)
2665 (define-key message-mode-map
"\C-c\C-fw" 'message-insert-wide-reply
)
2666 (define-key message-mode-map
"\C-c\C-n" 'message-insert-newsgroups
)
2667 (define-key message-mode-map
"\C-c\C-l" 'message-to-list-only
)
2668 (define-key message-mode-map
"\C-c\C-f\C-e" 'message-insert-expires
)
2670 (define-key message-mode-map
"\C-c\C-u" 'message-insert-or-toggle-importance
)
2671 (define-key message-mode-map
"\C-c\M-n"
2672 'message-insert-disposition-notification-to
)
2674 (define-key message-mode-map
"\C-c\C-y" 'message-yank-original
)
2675 (define-key message-mode-map
"\C-c\M-\C-y" 'message-yank-buffer
)
2676 (define-key message-mode-map
"\C-c\C-q" 'message-fill-yanked-message
)
2677 (define-key message-mode-map
"\C-c\C-w" 'message-insert-signature
)
2678 (define-key message-mode-map
"\C-c\M-h" 'message-insert-headers
)
2679 (define-key message-mode-map
"\C-c\C-r" 'message-caesar-buffer-body
)
2680 (define-key message-mode-map
"\C-c\C-o" 'message-sort-headers
)
2681 (define-key message-mode-map
"\C-c\M-r" 'message-rename-buffer
)
2683 (define-key message-mode-map
"\C-c\C-c" 'message-send-and-exit
)
2684 (define-key message-mode-map
"\C-c\C-s" 'message-send
)
2685 (define-key message-mode-map
"\C-c\C-k" 'message-kill-buffer
)
2686 (define-key message-mode-map
"\C-c\C-d" 'message-dont-send
)
2687 (define-key message-mode-map
"\C-c\n" 'gnus-delay-article
)
2689 (define-key message-mode-map
"\C-c\M-k" 'message-kill-address
)
2690 (define-key message-mode-map
"\C-c\C-e" 'message-elide-region
)
2691 (define-key message-mode-map
"\C-c\C-v" 'message-delete-not-region
)
2692 (define-key message-mode-map
"\C-c\C-z" 'message-kill-to-signature
)
2693 (define-key message-mode-map
"\M-\r" 'message-newline-and-reformat
)
2694 (define-key message-mode-map
[remap split-line
] 'message-split-line
)
2696 (define-key message-mode-map
"\C-c\C-a" 'mml-attach-file
)
2698 (define-key message-mode-map
"\C-a" 'message-beginning-of-line
)
2699 (define-key message-mode-map
"\t" 'message-tab
)
2701 (define-key message-mode-map
"\M-n" 'message-display-abbrev
))
2704 message-mode-menu message-mode-map
"Message Menu."
2706 ["Yank Original" message-yank-original message-reply-buffer
]
2707 ["Fill Yanked Message" message-fill-yanked-message t
]
2708 ["Insert Signature" message-insert-signature t
]
2709 ["Caesar (rot13) Message" message-caesar-buffer-body t
]
2710 ["Caesar (rot13) Region" message-caesar-region
(message-mark-active-p)]
2711 ["Elide Region" message-elide-region
2712 :active
(message-mark-active-p)
2713 :help
"Replace text in region with an ellipsis"]
2714 ["Delete Outside Region" message-delete-not-region
2715 :active
(message-mark-active-p)
2716 :help
"Delete all quoted text outside region"]
2717 ["Kill To Signature" message-kill-to-signature t
]
2718 ["Newline and Reformat" message-newline-and-reformat t
]
2719 ["Rename buffer" message-rename-buffer t
]
2720 ["Spellcheck" ispell-message
:help
"Spellcheck this message"]
2722 ["Insert Region Marked" message-mark-inserted-region
2723 :active
(message-mark-active-p) :help
"Mark region with enclosing tags"]
2724 ["Insert File Marked..." message-mark-insert-file
2725 :help
"Insert file at point marked with enclosing tags"]
2727 ["Send Message" message-send-and-exit
:help
"Send this message"]
2728 ["Postpone Message" message-dont-send
2729 :help
"File this draft message and exit"]
2730 ["Send at Specific Time..." gnus-delay-article
2731 :help
"Ask, then arrange to send message at that time"]
2732 ["Kill Message" message-kill-buffer
2733 :help
"Delete this message without sending"]
2735 ["Message manual" message-info
:help
"Display the Message manual"]))
2738 message-mode-field-menu message-mode-map
""
2740 ["To" message-goto-to t
]
2741 ["From" message-goto-from t
]
2742 ["Subject" message-goto-subject t
]
2743 ["Change subject..." message-change-subject t
]
2744 ["Cc" message-goto-cc t
]
2745 ["Bcc" message-goto-bcc t
]
2746 ["Fcc" message-goto-fcc t
]
2747 ["Reply-To" message-goto-reply-to t
]
2748 ["Flag As Important" message-insert-importance-high
2749 :help
"Mark this message as important"]
2750 ["Flag As Unimportant" message-insert-importance-low
2751 :help
"Mark this message as unimportant"]
2753 message-insert-disposition-notification-to
2754 :help
"Request a receipt notification"]
2756 ;; (typical) news stuff
2757 ["Summary" message-goto-summary t
]
2758 ["Keywords" message-goto-keywords t
]
2759 ["Newsgroups" message-goto-newsgroups t
]
2760 ["Fetch Newsgroups" message-insert-newsgroups t
]
2761 ["Followup-To" message-goto-followup-to t
]
2762 ;; ["Followup-To (with note in body)" message-cross-post-followup-to t]
2763 ["Crosspost / Followup-To..." message-cross-post-followup-to t
]
2764 ["Distribution" message-goto-distribution t
]
2765 ["Expires" message-insert-expires t
]
2766 ["X-No-Archive" message-add-archive-header t
]
2768 ;; (typical) mailing-lists stuff
2769 ["Fetch To" message-insert-to
2770 :help
"Insert a To header that points to the author."]
2771 ["Fetch To and Cc" message-insert-wide-reply
2772 :help
"Insert To and Cc headers as if you were doing a wide reply."]
2774 ["Send to list only" message-to-list-only t
]
2775 ["Mail-Followup-To" message-goto-mail-followup-to t
]
2776 ["Unsubscribed list post" message-generate-unsubscribed-mail-followup-to
2777 :help
"Insert a reasonable `Mail-Followup-To:' header."]
2778 ["Reduce To: to Cc:" message-reduce-to-to-cc t
]
2780 ["Sort Headers" message-sort-headers t
]
2781 ["Encode non-ASCII domain names" message-idna-to-ascii-rhs t
]
2782 ;; We hide `message-hidden-headers' by narrowing the buffer.
2783 ["Show Hidden Headers" widen t
]
2784 ["Goto Body" message-goto-body t
]
2785 ["Goto Signature" message-goto-signature t
]))
2787 (defvar message-tool-bar-map nil
)
2789 (defvar facemenu-add-face-function
)
2790 (defvar facemenu-remove-face-function
)
2792 ;;; Forbidden properties
2794 ;; We use `after-change-functions' to keep special text properties
2795 ;; that interfere with the normal function of message mode out of the
2798 (defcustom message-strip-special-text-properties t
2799 "Strip special properties from the message buffer.
2801 Emacs has a number of special text properties which can break message
2802 composing in various ways. If this option is set, message will strip
2803 these properties from the message composition buffer. However, some
2804 packages requires these properties to be present in order to work.
2805 If you use one of these packages, turn this option off, and hope the
2806 message composition doesn't break too bad."
2808 :group
'message-various
2809 :link
'(custom-manual "(message)Various Message Variables")
2812 (defvar message-forbidden-properties
2813 ;; No reason this should be clutter up customize. We make it a
2814 ;; property list (rather than a list of property symbols), to be
2815 ;; directly useful for `remove-text-properties'.
2816 '(field nil read-only nil invisible nil intangible nil
2817 mouse-face nil modification-hooks nil insert-in-front-hooks nil
2818 insert-behind-hooks nil point-entered nil point-left nil
)
2819 ;; Other special properties:
2820 ;; category, face, display: probably doesn't do any harm.
2821 ;; fontified: is used by font-lock.
2822 ;; syntax-table, local-map: I dunno.
2823 "Property list of with properties forbidden in message buffers.
2824 The values of the properties are ignored, only the property names are used.")
2826 (defun message-tamago-not-in-use-p (pos)
2827 "Return t when tamago version 4 is not in use at the cursor position.
2828 Tamago version 4 is a popular input method for writing Japanese text.
2829 It uses the properties `intangible', `invisible', `modification-hooks'
2830 and `read-only' when translating ascii or kana text to kanji text.
2831 These properties are essential to work, so we should never strip them."
2832 (not (and (boundp 'egg-modefull-mode
)
2833 (symbol-value 'egg-modefull-mode
)
2834 (or (memq (get-text-property pos
'intangible
)
2835 '(its-part-1 its-part-2
))
2836 (get-text-property pos
'egg-end
)
2837 (get-text-property pos
'egg-lang
)
2838 (get-text-property pos
'egg-start
)))))
2840 (defsubst message-mail-alias-type-p
(type)
2841 (if (atom message-mail-alias-type
)
2842 (eq message-mail-alias-type type
)
2843 (memq type message-mail-alias-type
)))
2845 (defun message-strip-forbidden-properties (begin end
&optional old-length
)
2846 "Strip forbidden properties between BEGIN and END, ignoring the third arg.
2847 This function is intended to be called from `after-change-functions'.
2848 See also `message-forbidden-properties'."
2849 (when (and (message-mail-alias-type-p 'ecomplete
)
2850 (memq this-command message-self-insert-commands
))
2851 (message-display-abbrev))
2852 (when (and message-strip-special-text-properties
2853 (message-tamago-not-in-use-p begin
))
2854 (let ((buffer-read-only nil
)
2855 (inhibit-read-only t
))
2856 (remove-text-properties begin end message-forbidden-properties
))))
2858 (defvar message-smileys
'(":-)" ":)"
2861 "A list of recognized smiley faces in `message-mode'.")
2863 (defun message--syntax-propertize (beg end
)
2864 "Syntax-propertize certain message text specially."
2865 (let ((citation-regexp (concat "^" message-cite-prefix-regexp
".*$"))
2866 (smiley-regexp (regexp-opt message-smileys
)))
2868 (while (search-forward-regexp citation-regexp
2870 (let ((start (match-beginning 0))
2871 (end (match-end 0)))
2872 (add-text-properties start
(1+ start
)
2873 `(syntax-table ,(string-to-syntax "<")))
2874 (add-text-properties end
(min (1+ end
) (point-max))
2875 `(syntax-table ,(string-to-syntax ">")))))
2877 (while (search-forward-regexp smiley-regexp
2879 (add-text-properties (match-beginning 0) (match-end 0)
2880 `(syntax-table ,(string-to-syntax "."))))))
2883 (define-derived-mode message-mode text-mode
"Message"
2884 "Major mode for editing mail and news to be sent.
2885 Like Text Mode but with these additional commands:\\<message-mode-map>
2886 C-c C-s `message-send' (send the message) C-c C-c `message-send-and-exit'
2887 C-c C-d Postpone sending the message C-c C-k Kill the message
2888 C-c C-f move to a header field (and create it if there isn't):
2889 C-c C-f C-t move to To C-c C-f C-s move to Subject
2890 C-c C-f C-c move to Cc C-c C-f C-b move to Bcc
2891 C-c C-f C-w move to Fcc C-c C-f C-r move to Reply-To
2892 C-c C-f C-u move to Summary C-c C-f C-n move to Newsgroups
2893 C-c C-f C-k move to Keywords C-c C-f C-d move to Distribution
2894 C-c C-f C-o move to From (\"Originator\")
2895 C-c C-f C-f move to Followup-To
2896 C-c C-f C-m move to Mail-Followup-To
2897 C-c C-f C-e move to Expires
2898 C-c C-f C-i cycle through Importance values
2899 C-c C-f s change subject and append \"(was: <Old Subject>)\"
2900 C-c C-f x crossposting with FollowUp-To header and note in body
2901 C-c C-f t replace To: header with contents of Cc: or Bcc:
2902 C-c C-f a Insert X-No-Archive: header and a note in the body
2903 C-c C-t `message-insert-to' (add a To header to a news followup)
2904 C-c C-l `message-to-list-only' (removes all but list address in to/cc)
2905 C-c C-n `message-insert-newsgroups' (add a Newsgroup header to a news reply)
2906 C-c C-b `message-goto-body' (move to beginning of message text).
2907 C-c C-i `message-goto-signature' (move to the beginning of the signature).
2908 C-c C-w `message-insert-signature' (insert `message-signature-file' file).
2909 C-c C-y `message-yank-original' (insert current message, if any).
2910 C-c C-q `message-fill-yanked-message' (fill what was yanked).
2911 C-c C-e `message-elide-region' (elide the text between point and mark).
2912 C-c C-v `message-delete-not-region' (remove the text outside the region).
2913 C-c C-z `message-kill-to-signature' (kill the text up to the signature).
2914 C-c C-r `message-caesar-buffer-body' (rot13 the message body).
2915 C-c C-a `mml-attach-file' (attach a file as MIME).
2916 C-c C-u `message-insert-or-toggle-importance' (insert or cycle importance).
2917 C-c M-n `message-insert-disposition-notification-to' (request receipt).
2918 C-c M-m `message-mark-inserted-region' (mark region with enclosing tags).
2919 C-c M-f `message-mark-insert-file' (insert file marked with enclosing tags).
2920 M-RET `message-newline-and-reformat' (break the line and reformat)."
2921 (set (make-local-variable 'message-reply-buffer
) nil
)
2922 (set (make-local-variable 'message-inserted-headers
) nil
)
2923 (set (make-local-variable 'message-send-actions
) nil
)
2924 (set (make-local-variable 'message-return-action
) nil
)
2925 (set (make-local-variable 'message-exit-actions
) nil
)
2926 (set (make-local-variable 'message-kill-actions
) nil
)
2927 (set (make-local-variable 'message-postpone-actions
) nil
)
2928 (set (make-local-variable 'message-draft-article
) nil
)
2929 (setq buffer-offer-save t
)
2930 (set (make-local-variable 'facemenu-add-face-function
)
2932 (let ((face-fun (cdr (assq face message-face-alist
))))
2934 (funcall face-fun
(point) end
)
2935 (error "Face %s not configured for %s mode" face mode-name
)))
2937 (set (make-local-variable 'facemenu-remove-face-function
) t
)
2938 (set (make-local-variable 'message-reply-headers
) nil
)
2939 (make-local-variable 'message-newsreader
)
2940 (make-local-variable 'message-mailer
)
2941 (make-local-variable 'message-post-method
)
2942 (set (make-local-variable 'message-sent-message-via
) nil
)
2943 (set (make-local-variable 'message-checksum
) nil
)
2944 (set (make-local-variable 'message-mime-part
) 0)
2945 (message-setup-fill-variables)
2946 (when message-fill-column
2947 (setq fill-column message-fill-column
)
2948 (turn-on-auto-fill))
2949 ;; Allow using comment commands to add/remove quoting.
2950 ;; (set (make-local-variable 'comment-start) message-yank-prefix)
2951 (when message-yank-prefix
2952 (set (make-local-variable 'comment-start
) message-yank-prefix
)
2953 (set (make-local-variable 'comment-start-skip
)
2954 (concat "^" (regexp-quote message-yank-prefix
) "[ \t]*")))
2955 (set (make-local-variable 'font-lock-defaults
)
2956 '(message-font-lock-keywords t
))
2957 (if (boundp 'tool-bar-map
)
2958 (set (make-local-variable 'tool-bar-map
) (message-make-tool-bar)))
2959 (easy-menu-add message-mode-menu message-mode-map
)
2960 (easy-menu-add message-mode-field-menu message-mode-map
)
2961 ;; Mmmm... Forbidden properties...
2962 (add-hook 'after-change-functions
'message-strip-forbidden-properties
2964 ;; Allow mail alias things.
2966 ((message-mail-alias-type-p 'abbrev
)
2967 (mail-abbrevs-setup))
2968 ((message-mail-alias-type-p 'ecomplete
)
2970 (add-hook 'completion-at-point-functions
'message-completion-function nil t
)
2971 (unless buffer-file-name
2972 (message-set-auto-save-file-name))
2973 (unless (buffer-base-buffer)
2974 ;; Don't enable multibyte on an indirect buffer. Maybe enabling
2975 ;; multibyte is not necessary at all. -- zsh
2976 (mm-enable-multibyte))
2977 (set (make-local-variable 'indent-tabs-mode
) nil
) ;No tabs for indentation.
2979 ;; Syntactic fontification. Helps `show-paren-mode',
2980 ;; `electric-pair-mode', and C-M-* navigation by syntactically
2981 ;; excluding citations and other artifacts.
2983 (set (make-local-variable 'syntax-propertize-function
) 'message--syntax-propertize
)
2984 (set (make-local-variable 'parse-sexp-ignore-comments
) t
))
2986 (defun message-setup-fill-variables ()
2987 "Setup message fill variables."
2988 (set (make-local-variable 'fill-paragraph-function
)
2989 'message-fill-paragraph
)
2990 (make-local-variable 'paragraph-separate
)
2991 (make-local-variable 'paragraph-start
)
2992 (make-local-variable 'adaptive-fill-regexp
)
2993 (make-local-variable 'adaptive-fill-first-line-regexp
)
2994 (let ((quote-prefix-regexp
2995 ;; User should change message-cite-prefix-regexp if
2996 ;; message-yank-prefix is set to an abnormal value.
2997 (concat "\\(" message-cite-prefix-regexp
"\\)[ \t]*")))
2998 (setq paragraph-start
3000 (regexp-quote mail-header-separator
) "$\\|"
3001 "[ \t]*$\\|" ; blank lines
3002 "-- $\\|" ; signature delimiter
3003 "---+$\\|" ; delimiters for forwarded messages
3004 page-delimiter
"$\\|" ; spoiler warnings
3005 ".*wrote:$\\|" ; attribution lines
3006 quote-prefix-regexp
"$\\|" ; empty lines in quoted text
3008 "<#!*/?\\(multipart\\|part\\|external\\|mml\\|secure\\)"))
3009 (setq paragraph-separate paragraph-start
)
3010 (setq adaptive-fill-regexp
3011 (concat quote-prefix-regexp
"\\|" adaptive-fill-regexp
))
3012 (setq adaptive-fill-first-line-regexp
3013 (concat quote-prefix-regexp
"\\|"
3014 adaptive-fill-first-line-regexp
)))
3015 (setq-local auto-fill-inhibit-regexp nil
)
3016 (setq-local normal-auto-fill-function
'message-do-auto-fill
))
3021 ;;; Message mode commands
3024 ;;; Movement commands
3026 (defun message-goto-to ()
3027 "Move point to the To header."
3030 (message-position-on-field "To"))
3032 (defun message-goto-from ()
3033 "Move point to the From header."
3036 (message-position-on-field "From"))
3038 (defun message-goto-subject ()
3039 "Move point to the Subject header."
3042 (message-position-on-field "Subject"))
3044 (defun message-goto-cc ()
3045 "Move point to the Cc header."
3048 (message-position-on-field "Cc" "To"))
3050 (defun message-goto-bcc ()
3051 "Move point to the Bcc header."
3054 (message-position-on-field "Bcc" "Cc" "To"))
3056 (defun message-goto-fcc ()
3057 "Move point to the Fcc header."
3060 (message-position-on-field "Fcc" "To" "Newsgroups"))
3062 (defun message-goto-reply-to ()
3063 "Move point to the Reply-To header."
3066 (message-position-on-field "Reply-To" "Subject"))
3068 (defun message-goto-newsgroups ()
3069 "Move point to the Newsgroups header."
3072 (message-position-on-field "Newsgroups"))
3074 (defun message-goto-distribution ()
3075 "Move point to the Distribution header."
3078 (message-position-on-field "Distribution"))
3080 (defun message-goto-followup-to ()
3081 "Move point to the Followup-To header."
3084 (message-position-on-field "Followup-To" "Newsgroups"))
3086 (defun message-goto-mail-followup-to ()
3087 "Move point to the Mail-Followup-To header."
3090 (message-position-on-field "Mail-Followup-To" "To"))
3092 (defun message-goto-keywords ()
3093 "Move point to the Keywords header."
3096 (message-position-on-field "Keywords" "Subject"))
3098 (defun message-goto-summary ()
3099 "Move point to the Summary header."
3102 (message-position-on-field "Summary" "Subject"))
3104 (defun message-goto-body ()
3105 "Move point to the beginning of the message body."
3107 (when (and (called-interactively-p 'any
)
3108 (looking-at "[ \t]*\n"))
3111 (goto-char (point-min))
3112 (or (search-forward (concat "\n" mail-header-separator
"\n") nil t
)
3113 (search-forward-regexp "[^:]+:\\([^\n]\\|\n[ \t]\\)+\n\n" nil t
)))
3115 (defun message-in-body-p ()
3116 "Return t if point is in the message body."
3119 (goto-char (point-min))
3120 (or (search-forward (concat "\n" mail-header-separator
"\n") nil t
)
3121 (search-forward-regexp "[^:]+:\\([^\n]\\|\n[ \t]\\)+\n\n" nil t
))
3124 (defun message-goto-eoh ()
3125 "Move point to the end of the headers."
3130 (defun message-goto-signature ()
3131 "Move point to the beginning of the message signature.
3132 If there is no signature in the article, go to the end and
3136 (goto-char (point-min))
3137 (if (re-search-forward message-signature-separator nil t
)
3139 (goto-char (point-max))
3142 (defun message-generate-unsubscribed-mail-followup-to (&optional include-cc
)
3143 "Insert a reasonable MFT header in a post to an unsubscribed list.
3144 When making original posts to a mailing list you are not subscribed to,
3145 you have to type in a MFT header by hand. The contents, usually, are
3146 the addresses of the list and your own address. This function inserts
3147 such a header automatically. It fetches the contents of the To: header
3148 in the current mail buffer, and appends the current `user-mail-address'.
3150 If the optional argument INCLUDE-CC is non-nil, the addresses in the
3151 Cc: header are also put into the MFT."
3156 (message-narrow-to-headers)
3157 (message-remove-header "Mail-Followup-To")
3158 (setq cc
(and include-cc
(message-fetch-field "Cc")))
3160 (concat (message-fetch-field "To") "," cc
)
3161 (message-fetch-field "To"))))
3162 (message-goto-mail-followup-to)
3163 (insert (concat tos
", " user-mail-address
))))
3167 (defun message-insert-to (&optional force
)
3168 "Insert a To header that points to the author of the article being replied to.
3169 If the original author requested not to be sent mail, don't insert unless the
3170 prefix FORCE is given."
3172 (let* ((mct (message-fetch-reply-field "mail-copies-to"))
3173 (dont (and mct
(or (equal (downcase mct
) "never")
3174 (equal (downcase mct
) "nobody"))))
3175 (to (or (message-fetch-reply-field "mail-reply-to")
3176 (message-fetch-reply-field "reply-to")
3177 (message-fetch-reply-field "from"))))
3181 "Ignoring the user request not to have copies sent via mail"
3182 "Complying with the user request not to have copies sent via mail")))
3183 (when (and force
(not to
))
3184 (error "No mail address in the article"))
3185 (when (and to
(or force
(not dont
)))
3186 (message-carefully-insert-headers (list (cons 'To to
))))))
3188 (defun message-insert-wide-reply ()
3189 "Insert To and Cc headers as if you were doing a wide reply."
3191 (let ((headers (message-with-reply-buffer
3192 (message-get-reply-headers t
))))
3193 (message-carefully-insert-headers headers
)))
3195 (defcustom message-header-synonyms
3198 "List of lists of header synonyms.
3199 E.g., if this list contains a member list with elements `Cc' and `To',
3200 then `message-carefully-insert-headers' will not insert a `To' header
3201 when the message is already `Cc'ed to the recipient."
3203 :group
'message-headers
3204 :link
'(custom-manual "(message)Message Headers")
3205 :type
'(repeat sexp
))
3207 (defun message-carefully-insert-headers (headers)
3208 "Insert the HEADERS, an alist, into the message buffer.
3209 Does not insert the headers when they are already present there
3210 or in the synonym headers, defined by `message-header-synonyms'."
3211 ;; FIXME: Should compare only the address and not the full name. Comparison
3212 ;; should be done case-folded (and with `string=' rather than
3214 ;; (mail-strip-quoted-names "Foo Bar <foo@bar>, bla@fasel (Bla Fasel)")
3215 (dolist (header headers
)
3216 (let* ((header-name (symbol-name (car header
)))
3217 (new-header (cdr header
))
3218 (synonyms (loop for synonym in message-header-synonyms
3219 when
(memq (car header
) synonym
) return synonym
))
3221 (loop for synonym in synonyms
3222 for old-header
= (mail-fetch-field (symbol-name synonym
))
3223 when
(and old-header
(string-match new-header old-header
))
3226 (message "already have `%s' in `%s'" new-header old-header
)
3227 (when (and (message-position-on-field header-name
)
3228 (setq old-header
(mail-fetch-field header-name
))
3229 (not (string-match "\\` *\\'" old-header
)))
3231 (insert new-header
)))))
3233 (defun message-widen-reply ()
3234 "Widen the reply to include maximum recipients."
3237 (and (bufferp message-reply-buffer
)
3238 (buffer-name message-reply-buffer
)
3239 (with-current-buffer message-reply-buffer
3240 (message-get-reply-headers t
)))))
3243 (message-narrow-to-headers)
3244 (dolist (elem follow-to
)
3245 (message-remove-header (symbol-name (car elem
)))
3246 (goto-char (point-min))
3247 (insert (symbol-name (car elem
)) ": "
3248 (cdr elem
) "\n"))))))
3250 (defun message-insert-newsgroups ()
3251 "Insert the Newsgroups header from the article being replied to."
3253 (let ((old-newsgroups (mail-fetch-field "newsgroups"))
3254 (new-newsgroups (message-fetch-reply-field "newsgroups"))
3257 (message-position-on-field "Newsgroups")
3259 ((not new-newsgroups
)
3260 (error "No Newsgroups to insert"))
3261 ((not old-newsgroups
)
3262 (insert new-newsgroups
))
3264 (setq new-newsgroups
(split-string new-newsgroups
"[, ]+")
3265 old-newsgroups
(split-string old-newsgroups
"[, ]+"))
3266 (dolist (group new-newsgroups
)
3267 (unless (member group old-newsgroups
)
3268 (push group insert-newsgroups
)))
3269 (if (null insert-newsgroups
)
3270 (error "Newgroup%s already in the header"
3271 (if (> (length new-newsgroups
) 1)
3273 (when old-newsgroups
3275 (dolist (group insert-newsgroups
)
3279 (insert group
)))))))
3283 ;;; Various commands
3285 (defun message-delete-not-region (beg end
)
3286 "Delete everything in the body of the current message outside of the region."
3291 ;; snarf citation prefix, if appropriate
3292 (unless (eq (point) (progn (beginning-of-line) (point)))
3293 (when (looking-at message-cite-prefix-regexp
)
3294 (setq citeprefix
(match-string 0))))
3296 (delete-region (point) (if (not (message-goto-signature))
3302 (delete-region beg
(progn (message-goto-body)
3306 (insert citeprefix
))))
3307 (when (message-goto-signature)
3310 (defun message-kill-to-signature (&optional arg
)
3311 "Kill all text up to the signature.
3312 If a numeric argument or prefix arg is given, leave that number
3313 of lines before the signature intact."
3317 (let ((point (point)))
3318 (narrow-to-region point
(point-max))
3319 (message-goto-signature)
3321 (if (and arg
(numberp arg
))
3322 (forward-line (- -
1 arg
))
3324 (unless (= point
(point))
3325 (kill-region point
(point))
3329 (defun message-newline-and-reformat (&optional arg not-break
)
3330 "Insert four newlines, and then reformat if inside quoted text.
3331 Prefix arg means justify as well."
3332 (interactive (list (if current-prefix-arg
'full
)))
3333 (let (quoted point beg end leading-space bolp fill-paragraph-function
)
3334 (setq point
(point))
3337 (setq bolp
(= beg point
))
3338 ;; Find first line of the paragraph.
3340 (while (and (not (eobp))
3341 (not (looking-at message-cite-prefix-regexp
))
3342 (looking-at paragraph-start
))
3345 (when (looking-at message-cite-prefix-regexp
)
3346 (setq quoted
(match-string 0))
3347 (goto-char (match-end 0))
3348 (looking-at "[ \t]*")
3349 (setq leading-space
(match-string 0)))
3353 (< (- point beg
) (length quoted
)))
3354 ;; break inside the cite prefix.
3360 (while (and (not (eobp))
3361 (not (looking-at paragraph-separate
))
3362 (looking-at message-cite-prefix-regexp
)
3363 (equal quoted
(match-string 0)))
3364 (goto-char (match-end 0))
3365 (looking-at "[ \t]*")
3366 (if (> (length leading-space
) (length (match-string 0)))
3367 (setq leading-space
(match-string 0)))
3371 (while (and (if (bobp) nil
(forward-line -
1) t
)
3372 (not (looking-at paragraph-start
))
3373 (looking-at message-cite-prefix-regexp
)
3374 (equal quoted
(match-string 0)))
3376 (goto-char (match-end 0))
3377 (looking-at "[ \t]*")
3378 (if (> (length leading-space
) (length (match-string 0)))
3379 (setq leading-space
(match-string 0)))))
3380 (while (and (not (eobp))
3381 (not (looking-at paragraph-separate
))
3382 (not (looking-at message-cite-prefix-regexp
)))
3386 (while (and (if (bobp) nil
(forward-line -
1) t
)
3387 (not (looking-at paragraph-start
))
3388 (not (looking-at message-cite-prefix-regexp
)))
3389 (setq beg
(point))))
3392 (narrow-to-region beg end
)
3399 (setq point
(point))
3400 ;; (newline 2) doesn't mark both newline's as hard, so call
3401 ;; newline twice. -jas
3404 (delete-region (point) (re-search-forward "[ \t]*"))
3405 (when (and quoted
(not bolp
))
3406 (insert quoted leading-space
)))
3409 (let* ((adaptive-fill-regexp
3410 (regexp-quote (concat quoted leading-space
)))
3411 (adaptive-fill-first-line-regexp
3412 adaptive-fill-regexp
))
3413 (fill-paragraph arg
))
3414 (fill-paragraph arg
))
3415 (if point
(goto-char point
)))))
3417 (defun message-fill-paragraph (&optional arg
)
3418 "Message specific function to fill a paragraph.
3419 This function is used as the value of `fill-paragraph-function' in
3420 Message buffers and is not meant to be called directly."
3421 (interactive (list (if current-prefix-arg
'full
)))
3422 (if (message-point-in-header-p)
3423 (message-fill-field)
3424 (message-newline-and-reformat arg t
))
3427 (defun message-point-in-header-p ()
3428 "Return t if point is in the header."
3432 (let ((bound (+ (point-at-eol) 1)) case-fold-search
)
3433 (goto-char (point-min))
3434 (not (search-forward (concat "\n" mail-header-separator
"\n")
3437 (defun message-do-auto-fill ()
3438 "Like `do-auto-fill', but don't fill in message header."
3439 (unless (message-point-in-header-p)
3442 (defun message-insert-signature (&optional force
)
3443 "Insert a signature. See documentation for variable `message-signature'."
3444 (interactive (list 0))
3447 ((and (null message-signature
)
3450 (goto-char (point-max))
3451 (not (re-search-backward message-signature-separator nil t
))))
3452 ((and (null message-signature
)
3455 ((functionp message-signature
)
3456 (funcall message-signature
))
3457 ((listp message-signature
)
3458 (eval message-signature
))
3459 (t message-signature
)))
3462 (cond ((stringp signature
)
3464 ((and (eq t signature
) message-signature-file
)
3465 (setq signature-file
3466 (if (and message-signature-directory
3467 ;; don't actually use the signature directory
3468 ;; if message-signature-file contains a path.
3469 (not (file-name-directory
3470 message-signature-file
)))
3471 (expand-file-name message-signature-file
3472 message-signature-directory
)
3473 message-signature-file
))
3474 (file-exists-p signature-file
))))
3476 (goto-char (point-max))
3477 ;; Insert the signature.
3480 (when message-signature-insert-empty-line
3484 (if (eq signature t
)
3485 (insert-file-contents signature-file
)
3487 (goto-char (point-max))
3488 (or (bolp) (newline)))))
3490 (defun message-insert-importance-high ()
3491 "Insert header to mark message as important."
3495 (message-narrow-to-headers)
3496 (message-remove-header "Importance"))
3498 (insert "Importance: high\n")))
3500 (defun message-insert-importance-low ()
3501 "Insert header to mark message as unimportant."
3505 (message-narrow-to-headers)
3506 (message-remove-header "Importance"))
3508 (insert "Importance: low\n")))
3510 (defun message-insert-or-toggle-importance ()
3511 "Insert a \"Importance: high\" header, or cycle through the header values.
3512 The three allowed values according to RFC 1327 are `high', `normal'
3519 (message-narrow-to-headers)
3520 (when (setq cur
(message-fetch-field "Importance"))
3521 (message-remove-header "Importance")
3522 (setq new
(cond ((string= cur
"high")
3524 ((string= cur
"low")
3529 (insert (format "Importance: %s\n" new
)))))
3531 (defun message-insert-disposition-notification-to ()
3532 "Request a disposition notification (return receipt) to this message.
3533 Note that this should not be used in newsgroups."
3537 (message-narrow-to-headers)
3538 (message-remove-header "Disposition-Notification-To"))
3540 (insert (format "Disposition-Notification-To: %s\n"
3541 (or (message-field-value "Reply-to")
3542 (message-field-value "From")
3543 (message-make-from))))))
3545 (defun message-elide-region (b e
)
3546 "Elide the text in the region.
3547 An ellipsis (from `message-elide-ellipsis') will be inserted where the
3550 (let ((lines (count-lines b e
))
3553 (insert (format-spec message-elide-ellipsis
3557 (defvar message-caesar-translation-table nil
)
3559 (defun message-caesar-region (b e
&optional n
)
3560 "Caesar rotate region B to E by N, default 13, for decrypting netnews."
3563 (min (point) (or (mark t
) (point)))
3564 (max (point) (or (mark t
) (point)))
3565 (when current-prefix-arg
3566 (prefix-numeric-value current-prefix-arg
))))
3568 (setq n
(if (numberp n
) (mod n
26) 13)) ;canonize N
3569 (unless (or (zerop n
) ; no action needed for a rot of 0
3570 (= b e
)) ; no region to rotate
3571 ;; We build the table, if necessary.
3572 (when (or (not message-caesar-translation-table
)
3573 (/= (aref message-caesar-translation-table ?a
) (+ ?a n
)))
3574 (setq message-caesar-translation-table
3575 (message-make-caesar-translation-table n
)))
3576 (translate-region b e message-caesar-translation-table
)))
3578 (defun message-make-caesar-translation-table (n)
3579 "Create a rot table with offset N."
3581 (table (make-string 256 0)))
3582 (while (< (incf i
) 256)
3585 (substring table
0 ?A
)
3586 (substring table
(+ ?A n
) (+ ?A n
(- 26 n
)))
3587 (substring table ?A
(+ ?A n
))
3588 (substring table
(+ ?A
26) ?a
)
3589 (substring table
(+ ?a n
) (+ ?a n
(- 26 n
)))
3590 (substring table ?a
(+ ?a n
))
3591 (substring table
(+ ?a
26) 255))))
3593 (defun message-caesar-buffer-body (&optional rotnum wide
)
3594 "Caesar rotate all letters in the current buffer by 13 places.
3595 Used to encode/decode possibly offensive messages (commonly in rec.humor).
3596 With prefix arg, specifies the number of places to rotate each letter forward.
3597 Mail and USENET news headers are not rotated unless WIDE is non-nil."
3598 (interactive (if current-prefix-arg
3599 (list (prefix-numeric-value current-prefix-arg
))
3603 (when (and (not wide
) (message-goto-body))
3604 (narrow-to-region (point) (point-max)))
3605 (message-caesar-region (point-min) (point-max) rotnum
))))
3607 (defun message-pipe-buffer-body (program)
3608 "Pipe the message body in the current buffer through PROGRAM."
3611 (when (message-goto-body)
3612 (narrow-to-region (point) (point-max)))
3613 (shell-command-on-region
3614 (point-min) (point-max) program nil t
))))
3616 (defun message-rename-buffer (&optional enter-string
)
3617 "Rename the *message* buffer to \"*message* RECIPIENT\".
3618 If the function is run with a prefix, it will ask for a new buffer
3619 name, rather than giving an automatic name."
3620 (interactive "Pbuffer name: ")
3623 (goto-char (point-min))
3624 (narrow-to-region (point)
3625 (search-forward mail-header-separator nil
'end
))
3627 (if (message-news-p) (message-fetch-field "Newsgroups")
3628 (message-fetch-field "To"))
3631 (if (string-match "," mail-to
)
3632 (concat (substring mail-to
0 (match-beginning 0)) ", ...")
3634 (name-default (concat "*message* " mail-trimmed-to
))
3635 (name (if enter-string
3636 (read-string "New buffer name: " name-default
)
3638 (rename-buffer name t
)))))
3640 (defun message-fill-yanked-message (&optional justifyp
)
3641 "Fill the paragraphs of a message yanked into this one.
3642 Numeric argument means justify as well."
3645 (goto-char (point-min))
3646 (search-forward (concat "\n" mail-header-separator
"\n") nil t
)
3647 (let ((fill-prefix message-yank-prefix
))
3648 (fill-individual-paragraphs (point) (point-max) justifyp
))))
3650 (defun message-indent-citation (&optional start end yank-only
)
3651 "Modify text just inserted from a message to be cited.
3652 The inserted text should be the region.
3653 When this function returns, the region is again around the modified text.
3655 Normally, indent each nonblank line `message-indentation-spaces' spaces.
3656 However, if `message-yank-prefix' is non-nil, insert that prefix on each line."
3657 (unless start
(setq start
(point)))
3659 ;; Remove unwanted headers.
3660 (when message-ignored-cited-headers
3665 (if (search-forward "\n\n" nil t
)
3668 (message-remove-header message-ignored-cited-headers t
)
3669 (when (= (point-min) (point-max))
3670 (setq all-removed t
))
3671 (goto-char (point-max)))
3675 ;; Delete blank lines at the start of the buffer.
3676 (while (and (point-min)
3679 (message-delete-line))
3680 ;; Delete blank lines at the end of the buffer.
3681 (goto-char (point-max))
3682 (unless (eq (preceding-char) ?
\n)
3684 (while (and (zerop (forward-line -
1))
3686 (message-delete-line)))
3687 ;; Do the indentation.
3688 (if (null message-yank-prefix
)
3689 (indent-rigidly start
(or end
(mark t
)) message-indentation-spaces
)
3692 (while (< (point) (or end
(mark t
)))
3693 (cond ((looking-at ">")
3694 (insert message-yank-cited-prefix
))
3696 (insert message-yank-empty-prefix
))
3698 (insert message-yank-prefix
)))
3702 (defun message-remove-blank-cited-lines (&optional remove
)
3703 "Remove cited lines containing only blanks.
3704 If REMOVE is non-nil, remove newlines, too.
3706 To use this automatically, you may add this function to
3707 `gnus-message-setup-hook'."
3709 (let ((citexp (concat "^\\("
3710 (concat message-yank-cited-prefix
"\\|")
3713 (message "Removing `%s'" citexp
)
3716 (while (re-search-forward citexp nil t
)
3717 (replace-match (if remove
"" "\n"))))))
3719 (defun message--yank-original-internal (arg)
3720 (let ((modified (buffer-modified-p))
3722 (when (and message-reply-buffer
3723 message-cite-function
)
3724 (when (equal message-cite-reply-position
'above
)
3727 (buffer-substring (message-goto-body)
3729 (delete-region (message-goto-body) (point-max))))
3730 (if (bufferp message-reply-buffer
)
3731 (delete-windows-on message-reply-buffer t
))
3732 (push-mark (save-excursion
3734 ((bufferp message-reply-buffer
)
3735 (insert-buffer-substring message-reply-buffer
))
3736 ((and (consp message-reply-buffer
)
3737 (functionp (car message-reply-buffer
)))
3738 (apply (car message-reply-buffer
)
3739 (cdr message-reply-buffer
))))
3744 (funcall message-cite-function
)
3745 (unless (eq (char-before (mark t
)) ?
\n)
3747 (goto-char (mark t
))
3748 (insert-before-markers ?
\n)
3750 (case message-cite-reply-position
3754 (insert (if (bolp) "\n" "\n\n"))
3755 (message-goto-body))
3757 (message-goto-signature)))
3758 ;; Add a `message-setup-very-last-hook' here?
3759 ;; Add `gnus-article-highlight-citation' here?
3761 (setq message-checksum
(message-checksum))))))
3763 (defun message-yank-original (&optional arg
)
3764 "Insert the message being replied to, if any.
3765 Puts point before the text and mark after.
3766 Normally indents each nonblank line ARG spaces (default 3). However,
3767 if `message-yank-prefix' is non-nil, insert that prefix on each line.
3769 This function uses `message-cite-function' to do the actual citing.
3771 Just \\[universal-argument] as argument means don't indent, insert no
3772 prefix, and don't delete any headers."
3774 ;; eval the let forms contained in message-cite-style
3776 `(let ,(if (symbolp message-cite-style
)
3777 (symbol-value message-cite-style
)
3779 (message--yank-original-internal ',arg
))))
3781 (defun message-yank-buffer (buffer)
3782 "Insert BUFFER into the current buffer and quote it."
3783 (interactive "bYank buffer: ")
3784 (let ((message-reply-buffer (get-buffer buffer
)))
3785 (save-window-excursion
3786 (message-yank-original))))
3788 (defun message-buffers ()
3789 "Return a list of active message buffers."
3791 (save-current-buffer
3792 (dolist (buffer (buffer-list t
))
3794 (when (and (derived-mode-p 'message-mode
)
3795 (null message-sent-message-via
))
3796 (push (buffer-name buffer
) buffers
))))
3797 (nreverse buffers
)))
3799 (defun message-cite-original-1 (strip-signature)
3800 "Cite an original message.
3801 If STRIP-SIGNATURE is non-nil, strips off the signature from the
3804 This function uses `mail-citation-hook' if that is non-nil."
3805 (if (and (boundp 'mail-citation-hook
)
3807 (run-hooks 'mail-citation-hook
)
3808 (let* ((start (point))
3812 (when message-indent-citation-function
3813 (if (listp message-indent-citation-function
)
3814 message-indent-citation-function
3815 (list message-indent-citation-function
))))
3816 ;; This function may be called by `gnus-summary-yank-message' and
3817 ;; may insert a different article from the original. So, we will
3818 ;; modify the value of `message-reply-headers' with that article.
3819 (message-reply-headers
3821 (narrow-to-region start end
)
3822 (message-narrow-to-head-1)
3823 (setq x-no-archive
(message-fetch-field "x-no-archive"))
3825 (or (message-fetch-field "subject") "none")
3826 (or (message-fetch-field "from") "nobody")
3827 (message-fetch-field "date")
3828 (message-fetch-field "message-id" t
)
3829 (message-fetch-field "references")
3831 (mml-quote-region start end
)
3832 (when strip-signature
3836 (when (re-search-backward message-signature-separator start t
)
3837 ;; Also peel off any blank lines before the signature.
3839 (while (looking-at "^[ \t]*$")
3842 (delete-region (point) end
)
3843 (unless (search-backward "\n\n" start t
)
3844 ;; Insert a blank line if it is peeled off.
3847 (mapc 'funcall functions
)
3848 (when message-citation-line-function
3851 (funcall message-citation-line-function
))
3852 (when (and x-no-archive
3853 (not message-cite-articles-with-x-no-archive
)
3854 (string-match "yes" x-no-archive
))
3856 (delete-region (point) (mark t
))
3857 (insert "> [Quoted text removed due to X-No-Archive]\n")
3859 (forward-line -
1)))))
3861 (defun message-cite-original ()
3862 "Cite function in the standard Message manner."
3863 (message-cite-original-1 nil
))
3865 (autoload 'format-spec
"format-spec")
3866 (autoload 'gnus-date-get-time
"gnus-util")
3868 (defun message-insert-formatted-citation-line (&optional from date tz
)
3869 "Function that inserts a formatted citation line.
3870 The optional FROM, and DATE are strings containing the contents of
3871 the From header and the Date header respectively.
3873 The optional TZ is omitted or nil for Emacs local time, t for
3874 Universal Time, `wall' for system wall clock time, or a string as
3875 in the TZ environment variable. It can also be a list (as from
3876 `current-time-zone') or an integer (as from `decode-time')
3877 applied without consideration for daylight saving time.
3879 See `message-citation-line-format'."
3880 ;; The optional args are for testing/debugging. They will disappear later.
3882 ;; (with-temp-buffer
3883 ;; (message-insert-formatted-citation-line
3884 ;; "John Doe <john.doe@example.invalid>"
3885 ;; (message-make-date))
3887 (when (or message-reply-headers
(and from date
))
3889 (setq from
(mail-header-from message-reply-headers
)))
3890 (let* ((data (condition-case ()
3891 (funcall (if (boundp 'gnus-extract-address-components
)
3892 gnus-extract-address-components
3893 'mail-extract-address-components
)
3899 (net (car (cdr data
)))
3900 (name-or-net (or (car data
)
3901 (car (cdr data
)) from
))
3903 (when (string-match "%[^fnNFL]" message-citation-line-format
)
3904 (cond ((numberp (car-safe date
)) date
) ;; backward compatibility
3905 (date (gnus-date-get-time date
))
3908 (setq date
(mail-header-date message-reply-headers
)))))))
3910 (when (stringp date
)
3911 (nth 8 (parse-time-string date
)))))
3914 (when (stringp name
)
3915 ;; Guess first name and last name:
3920 (if (string-match "\\`\\(\\w\\|[-.]\\)+\\'"
3924 (split-string name
"[ \t]+"))))
3925 (count (length names
)))
3927 (setq fname
(car names
)
3929 ((or (= count
2) (= count
3))
3930 (setq fname
(car names
)
3931 lname
(mapconcat 'identity
(cdr names
) " ")))
3933 (setq fname
(mapconcat 'identity
3934 (butlast names
(- count
2))
3936 lname
(mapconcat 'identity
3939 (when (string-match "\\(.*\\),\\'" fname
)
3940 (let ((newlname (match-string 1 fname
)))
3941 (setq fname lname lname newlname
)))))
3942 ;; The following letters are not used in `format-time-string':
3943 (push ?E lst
) (push "<E>" lst
)
3944 (push ?F lst
) (push (or fname name-or-net
) lst
)
3945 ;; We might want to use "" instead of "<X>" later.
3946 (push ?J lst
) (push "<J>" lst
)
3947 (push ?K lst
) (push "<K>" lst
)
3948 (push ?L lst
) (push lname lst
)
3949 (push ?N lst
) (push name-or-net lst
)
3950 (push ?O lst
) (push "<O>" lst
)
3951 (push ?P lst
) (push "<P>" lst
)
3952 (push ?Q lst
) (push "<Q>" lst
)
3953 (push ?f lst
) (push from lst
)
3954 (push ?i lst
) (push "<i>" lst
)
3955 (push ?n lst
) (push net lst
)
3956 (push ?o lst
) (push "<o>" lst
)
3957 (push ?q lst
) (push "<q>" lst
)
3958 (push ?t lst
) (push "<t>" lst
)
3959 (push ?v lst
) (push "<v>" lst
)
3960 ;; Delegate the rest to `format-time-string':
3962 (when (and (not (memq i lst
))
3967 (push (condition-case nil
3968 (format-time-string (format "%%%c" i
) time tz
)
3969 (error (format ">%c<" i
)))
3973 (spec (apply 'format-spec-make flist
)))
3974 (insert (format-spec message-citation-line-format spec
)))
3977 (defun message-cite-original-without-signature ()
3978 "Cite function in the standard Message manner.
3979 This function strips off the signature from the original message."
3980 (message-cite-original-1 t
))
3982 (defun message-insert-citation-line ()
3983 "Insert a simple citation line."
3984 (when message-reply-headers
3985 (insert (mail-header-from message-reply-headers
) " writes:")
3989 (defun message-position-on-field (header &rest afters
)
3990 (let ((case-fold-search t
))
3993 (goto-char (point-min))
3996 (concat "^" (regexp-quote mail-header-separator
) "$"))
3997 (match-beginning 0)))
3998 (goto-char (point-min))
3999 (if (re-search-forward (concat "^" (regexp-quote header
) ":") nil t
)
4001 (re-search-forward "^[^ \t]" nil
'move
)
4003 (skip-chars-backward "\n")
4006 (not (re-search-forward
4007 (concat "^" (regexp-quote (car afters
)) ":")
4011 (re-search-forward "^[^ \t]" nil
'move
)
4012 (beginning-of-line))
4013 (insert header
": \n")
4020 ;;; Sending messages
4023 (defun message-send-and-exit (&optional arg
)
4024 "Send message like `message-send', then, if no errors, exit from mail buffer.
4025 The usage of ARG is defined by the instance that called Message.
4026 It should typically alter the sending method in some way or other."
4028 (let ((buf (current-buffer))
4029 (actions message-exit-actions
))
4030 (when (and (message-send arg
)
4033 (if message-kill-buffer-on-exit
4035 (message-do-actions actions
)
4038 (defun message-dont-send ()
4039 "Don't send the message you have been editing.
4040 Instead, just auto-save the buffer and then bury it."
4042 (set-buffer-modified-p t
)
4044 (let ((actions message-postpone-actions
))
4045 (message-bury (current-buffer))
4046 (message-do-actions actions
)))
4048 (defun message-kill-buffer ()
4049 "Kill the current buffer."
4051 (when (or (not (buffer-modified-p))
4052 (not message-kill-buffer-query
)
4053 (yes-or-no-p "Message modified; kill anyway? "))
4054 (let ((actions message-kill-actions
)
4055 (draft-article message-draft-article
)
4056 (auto-save-file-name buffer-auto-save-file-name
)
4057 (file-name buffer-file-name
)
4058 (modified (buffer-modified-p)))
4059 (setq buffer-file-name nil
)
4060 (kill-buffer (current-buffer))
4061 (when (and (or (and auto-save-file-name
4062 (file-exists-p auto-save-file-name
))
4064 (file-exists-p file-name
)))
4066 ;; If the message buffer has lived in a dedicated window,
4067 ;; `kill-buffer' has killed the frame. Thus the
4068 ;; `yes-or-no-p' may show up in a lowered frame. Make sure
4069 ;; that the user can see the question by raising the
4072 (yes-or-no-p (format "Remove the backup file%s? "
4073 (if modified
" too" "")))))
4075 (delete-file auto-save-file-name
))
4076 (let ((message-draft-article draft-article
))
4077 (message-disassociate-draft)))
4078 (message-do-actions actions
))))
4080 (defun message-bury (buffer)
4081 "Bury this mail BUFFER."
4082 ;; Note that this is not quite the same as (bury-buffer buffer),
4083 ;; since bury-buffer does extra stuff with a nil argument.
4084 ;; Eg http://lists.gnu.org/archive/html/emacs-devel/2014-01/msg00539.html
4085 (with-current-buffer buffer
(bury-buffer))
4086 (if message-return-action
4087 (apply (car message-return-action
) (cdr message-return-action
))))
4089 (autoload 'mml-secure-bcc-is-safe
"mml-sec")
4091 (defun message-send (&optional arg
)
4092 "Send the message in the current buffer.
4093 If `message-interactive' is non-nil, wait for success indication or
4094 error messages, and inform user.
4095 Otherwise any failure is reported in a message back to the user from
4097 The usage of ARG is defined by the instance that called Message.
4098 It should typically alter the sending method in some way or other."
4100 ;; Make it possible to undo the coming changes.
4102 (let ((inhibit-read-only t
))
4103 (put-text-property (point-min) (point-max) 'read-only nil
))
4104 (message-fix-before-sending)
4105 (mml-secure-bcc-is-safe)
4106 (run-hooks 'message-send-hook
)
4107 (when message-confirm-send
4108 (or (y-or-n-p "Send message? ")
4110 (message message-sending-message
)
4111 (let ((alist message-send-method-alist
)
4113 elem sent dont-barf-on-no-method
4114 (message-options message-options
))
4115 (message-options-set-recipient)
4117 (setq elem
(pop alist
)))
4118 (when (funcall (cadr elem
))
4119 (when (and (or (not (memq (car elem
)
4120 message-sent-message-via
))
4121 (message-fetch-field "supersedes")
4122 (if (or (message-gnksa-enable-p 'multiple-copies
)
4123 (not (eq (car elem
) 'news
)))
4126 "Already sent message via %s; resend? "
4128 (error "Denied posting -- multiple copies")))
4129 (setq success
(funcall (caddr elem
) arg
)))
4133 (let ((fcc (message-fetch-field "Fcc"))
4134 (gcc (message-fetch-field "Gcc")))
4136 (or (eq message-allow-no-recipients
'always
)
4137 (and (not (eq message-allow-no-recipients
'never
))
4138 (setq dont-barf-on-no-method
4140 (format "No receiver, perform %s anyway? "
4141 (cond ((and fcc gcc
) "Fcc and Gcc")
4144 (error "No methods specified to send by"))
4145 (when (or dont-barf-on-no-method
4149 (run-hooks 'message-sent-hook
))
4150 (message "Sending...done")
4151 ;; Do ecomplete address snarfing.
4152 (when (and (message-mail-alias-type-p 'ecomplete
)
4153 (not message-inhibit-ecomplete
))
4154 (message-put-addresses-in-ecomplete))
4155 ;; Mark the buffer as unmodified and delete auto-save.
4156 (set-buffer-modified-p nil
)
4157 (delete-auto-save-file-if-necessary t
)
4158 (message-disassociate-draft)
4159 ;; Delete other mail buffers and stuff.
4160 (message-do-send-housekeeping)
4161 (message-do-actions message-send-actions
)
4165 (defun message-send-via-mail (arg)
4166 "Send the current message via mail."
4167 (message-send-mail arg
))
4169 (defun message-send-via-news (arg)
4170 "Send the current message via news."
4171 (funcall message-send-news-function arg
))
4173 (defmacro message-check
(type &rest forms
)
4174 "Eval FORMS if TYPE is to be checked."
4175 `(or (message-check-element ,type
)
4179 (put 'message-check
'lisp-indent-function
1)
4180 (put 'message-check
'edebug-form-spec
'(form body
))
4182 (defun message-text-with-property (prop &optional start end reverse
)
4183 "Return a list of start and end positions where the text has PROP.
4184 START and END bound the search, they default to `point-min' and
4185 `point-max' respectively. If REVERSE is non-nil, find text which does
4188 (setq start
(point-min)))
4190 (setq end
(point-max)))
4194 (setq start
(text-property-any start end prop nil
)))
4195 (setq next
(next-single-property-change start prop nil end
))
4196 (push (cons start
(or next end
)) regions
)
4199 (or (get-text-property start prop
)
4200 (and (setq start
(next-single-property-change
4201 start prop nil end
))
4202 (get-text-property start prop
))))
4203 (setq next
(text-property-any start end prop nil
))
4204 (push (cons start
(or next end
)) regions
)
4206 (nreverse regions
)))
4208 (defcustom message-bogus-addresses
4209 '("noreply" "nospam" "invalid" "@.*@" "[^[:ascii:]].*@" "[ \t]")
4210 "List of regexps of potentially bogus mail addresses.
4211 See `message-check-recipients' how to setup checking.
4213 This list should make it possible to catch typos or warn about
4214 spam-trap addresses. It doesn't aim to verify strict RFC
4216 :version
"26.1" ; @@ -> @.*@
4217 :group
'message-headers
4219 (const :tag
"None" nil
)
4225 (const :tag
"duplicate @" "@.*@")
4226 (const :tag
"non-ascii local part" "[^[:ascii:]].*@")
4227 (const :tag
"`_' in domain part" "@.*_")
4228 (const :tag
"whitespace" "[ \t]"))
4233 (defun message-fix-before-sending ()
4234 "Do various things to make the message nice before sending it."
4235 ;; Make sure there's a newline at the end of the message.
4236 (goto-char (point-max))
4239 ;; Make the hidden headers visible.
4241 ;; Sort headers before sending the message.
4242 (message-sort-headers)
4243 ;; Make invisible text visible.
4244 ;; It doesn't seem as if this is useful, since the invisible property
4245 ;; is clobbered by an after-change hook anyhow.
4246 (message-check 'invisible-text
4247 (let ((regions (message-text-with-property 'invisible
))
4251 (setq from
(caar regions
)
4253 regions
(cdr regions
))
4254 (put-text-property from to
'invisible nil
)
4255 (overlay-put (make-overlay from to
) 'face
'highlight
))
4256 (unless (yes-or-no-p
4257 "Invisible text found and made visible; continue sending? ")
4258 (error "Invisible text found and made visible")))))
4259 (message-check 'illegible-text
4260 (let (char found choice nul-chars
)
4262 (setq nul-chars
(save-excursion
4263 (search-forward "\000" nil t
)))
4265 (skip-chars-forward mm-7bit-chars
)
4266 (when (get-text-property (point) 'no-illegible-text
)
4267 ;; There is a signed or encrypted raw message part
4268 ;; that is considered to be safe.
4269 (goto-char (or (next-single-property-change
4270 (point) 'no-illegible-text
)
4272 (setq char
(char-after)))
4273 (when (or (< char
128)
4274 (and (mm-multibyte-p)
4275 (memq (char-charset char
)
4276 '(eight-bit-control eight-bit-graphic
4277 ;; Emacs 23, Bug#1770:
4280 (not (get-text-property
4281 (point) 'untranslated-utf-8
))))
4282 (overlay-put (make-overlay (point) (1+ (point))) 'face
'highlight
)
4288 (read-multiple-choice
4290 "NUL characters found, which may cause problems. Continue sending?"
4291 "Non-printable characters found. Continue sending?")
4292 `((?d
"delete" "Remove non-printable characters and send")
4295 "Replace non-printable characters with \"%s\" and send"
4296 message-replacement-char
))
4297 (?s
"send" "Send as is without removing anything")
4298 (?e
"edit" "Continue editing")))))
4300 (error "Non-printable characters"))
4302 (skip-chars-forward mm-7bit-chars
)
4304 (when (let ((char (char-after)))
4306 (and (mm-multibyte-p)
4307 ;; FIXME: Wrong for Emacs 23 (unicode) and for
4308 ;; things like undecodable utf-8 (in Emacs 21?).
4309 ;; Should at least use find-coding-systems-region.
4311 (memq (char-charset char
)
4312 '(eight-bit-control eight-bit-graphic
4313 ;; Emacs 23, Bug#1770:
4316 (not (get-text-property
4317 (point) 'untranslated-utf-8
)))))
4319 (message-kill-all-overlays)
4321 (when (eq choice ?r
)
4322 (insert message-replacement-char
))))
4324 (skip-chars-forward mm-7bit-chars
)))))
4325 (message-check 'bogus-recipient
4326 ;; Warn before sending a mail to an invalid address.
4327 (message-check-recipients)))
4329 (defun message-bogus-recipient-p (recipients)
4330 "Check if a mail address in RECIPIENTS looks bogus.
4332 RECIPIENTS is a mail header. Return a list of potentially bogus
4333 addresses. If none is found, return nil.
4335 An address might be bogus if if there's a matching entry in
4336 `message-bogus-addresses'."
4337 ;; FIXME: How about "foo@subdomain", when the MTA adds ".domain.tld"?
4339 (mapc (lambda (address)
4340 (setq address
(or (cadr address
) ""))
4341 (when (or (string= "" address
)
4342 (and message-bogus-addresses
4344 (if (listp message-bogus-addresses
)
4345 (mapconcat 'identity
4346 message-bogus-addresses
4348 message-bogus-addresses
)))
4349 (string-match re address
))))
4350 (push address found
)))
4351 (mail-extract-address-components recipients t
))
4354 (defun message-check-recipients ()
4355 "Warn before composing or sending a mail to an invalid address.
4357 This function could be useful in `message-setup-hook'."
4360 (message-narrow-to-headers)
4361 (dolist (hdr '("To" "Cc" "Bcc"))
4362 (let ((addr (message-fetch-field hdr
)))
4363 (when (stringp addr
)
4364 (dolist (bog (message-bogus-recipient-p addr
))
4368 "Address `%s'%s might be bogus. Continue? "
4370 ;; If the encoded version of the email address
4371 ;; is different from the unencoded version,
4372 ;; then we likely have invisible characters or
4373 ;; the like. Display the encoded version,
4375 (let ((encoded (rfc2047-encode-string bog
)))
4376 (if (string= encoded bog
)
4378 (format " (%s)" encoded
))))))
4379 (error "Bogus address"))))))))
4381 (custom-add-option 'message-setup-hook
'message-check-recipients
)
4383 (defun message-add-action (action &rest types
)
4384 "Add ACTION to be performed when doing an exit of type TYPES."
4386 (add-to-list (intern (format "message-%s-actions" (pop types
)))
4389 (defun message-delete-action (action &rest types
)
4390 "Delete ACTION from lists of actions performed when doing an exit of type TYPES."
4393 (set (setq var
(intern (format "message-%s-actions" (pop types
))))
4394 (delq action
(symbol-value var
))))))
4396 (defun message-do-actions (actions)
4397 "Perform all actions in ACTIONS."
4398 ;; Now perform actions on successful sending.
4399 (dolist (action actions
)
4402 ;; A simple function.
4405 ;; Something to be evalled.
4409 (defun message-send-mail-partially ()
4410 "Send mail as message/partial."
4411 ;; replace the header delimiter with a blank line
4412 (goto-char (point-min))
4414 (concat "^" (regexp-quote mail-header-separator
) "\n"))
4415 (replace-match "\n")
4416 (run-hooks 'message-send-mail-hook
)
4417 (let ((p (goto-char (point-min)))
4418 (tembuf (message-generate-new-buffer-clone-locals " message temp"))
4419 (curbuf (current-buffer))
4420 (id (message-make-message-id)) (n 1)
4423 (if (< (point-max) (+ p message-send-mail-partially-limit
))
4424 (goto-char (point-max))
4425 (goto-char (+ p message-send-mail-partially-limit
))
4427 (if (<= (point) p
) (forward-line 1))) ;; In case of bad message.
4430 (setq total
(length plist
))
4431 (push (point-max) plist
)
4432 (setq plist
(nreverse plist
))
4435 (setq p
(pop plist
))
4438 (copy-to-buffer tembuf p
(car plist
))
4440 (goto-char (point-min))
4443 (goto-char (point-min))
4444 (narrow-to-region (point) (point))
4447 (setq header
(buffer-substring (point-min) (point)))
4448 (goto-char (point-min))
4449 (narrow-to-region (point) (point))
4451 (message-remove-header "Mime-Version")
4452 (message-remove-header "Content-Type")
4453 (message-remove-header "Content-Transfer-Encoding")
4454 (message-remove-header "Message-ID")
4455 (message-remove-header "Lines")
4456 (goto-char (point-max))
4457 (insert "Mime-Version: 1.0\n")
4458 (setq header
(buffer-string)))
4459 (goto-char (point-max))
4460 (insert (format "Content-Type: message/partial; id=\"%s\"; number=%d; total=%d\n\n"
4463 (let ((mail-header-separator ""))
4464 (when (memq 'Message-ID message-required-mail-headers
)
4465 (insert "Message-ID: " (message-make-message-id) "\n"))
4466 (when (memq 'Lines message-required-mail-headers
)
4467 (insert "Lines: " (message-make-lines) "\n"))
4468 (message-goto-subject)
4470 (insert (format " (%d/%d)" n total
))
4472 (if message-send-mail-real-function
4473 (funcall message-send-mail-real-function
)
4474 (message-multi-smtp-send-mail)))
4476 (setq p
(pop plist
))
4478 (kill-buffer tembuf
))))
4480 (declare-function hashcash-wait-async
"hashcash" (&optional buffer
))
4482 (defun message-send-mail (&optional _
)
4483 (require 'mail-utils
)
4484 (let* ((tembuf (message-generate-new-buffer-clone-locals " message temp"))
4485 (case-fold-search nil
)
4486 (news (message-news-p))
4487 (mailbuf (current-buffer))
4488 (message-this-is-mail t
)
4489 ;; gnus-setup-posting-charset is autoloaded in mml.el (FIXME
4490 ;; maybe it should not be), which this file requires. Hence
4491 ;; the fboundp test is always true. Loading it from gnus-msg
4492 ;; loads many Gnus files (Bug#5642). If
4493 ;; gnus-group-posting-charset-alist hasn't been customized,
4494 ;; this is just going to return nil anyway. FIXME it would
4495 ;; be good to improve this further, because even if g-g-p-c-a
4496 ;; has been customized, that is likely to just be for news.
4497 ;; Eg either move the definition from gnus-msg, or separate out
4498 ;; the mail and news parts.
4499 (message-posting-charset
4500 (if (and (fboundp 'gnus-setup-posting-charset
)
4501 (boundp 'gnus-group-posting-charset-alist
))
4502 (gnus-setup-posting-charset nil
)
4503 message-posting-charset
))
4504 (headers message-required-mail-headers
)
4506 (when (and message-generate-hashcash
4507 (not (eq message-generate-hashcash
'opportunistic
)))
4508 (message "Generating hashcash...")
4510 ;; Wait for calculations already started to finish...
4511 (hashcash-wait-async)
4512 ;; ...and do calculations not already done. mail-add-payment
4513 ;; will leave existing X-Hashcash headers alone.
4515 (message "Generating hashcash...done"))
4517 (message-narrow-to-headers)
4518 ;; Generate the Mail-Followup-To header if the header is not there...
4519 (if (and (message-subscribed-p)
4520 (not (mail-fetch-field "mail-followup-to")))
4523 (cons "Mail-Followup-To" (message-make-mail-followup-to))
4524 message-required-mail-headers
))
4525 ;; otherwise, delete the MFT header if the field is empty
4526 (when (equal "" (mail-fetch-field "mail-followup-to"))
4527 (message-remove-header "^Mail-Followup-To:")))
4528 ;; Insert some headers.
4529 (let ((message-deletable-headers
4530 (if news nil message-deletable-headers
)))
4531 (message-generate-headers headers
))
4532 ;; Check continuation headers.
4533 (message-check 'continuation-headers
4534 (goto-char (point-min))
4535 (while (re-search-forward "^[^ \t\n][^ \t\n:]*[ \t\n]" nil t
)
4536 (goto-char (match-beginning 0))
4537 (if (y-or-n-p "Fix continuation lines? ")
4540 (unless (y-or-n-p "Send anyway? ")
4541 (error "Failed to send the message")))))
4542 ;; Let the user do all of the above.
4543 (run-hooks 'message-header-hook
))
4544 (setq options message-options
)
4546 (with-current-buffer tembuf
4548 (setq message-options options
)
4549 ;; Avoid copying text props (except hard newlines).
4550 (insert (with-current-buffer mailbuf
4551 (mml-buffer-substring-no-properties-except-some
4552 (point-min) (point-max))))
4553 ;; Remove some headers.
4554 (message-encode-message-body)
4556 (message-narrow-to-headers)
4557 ;; We (re)generate the Lines header.
4558 (when (memq 'Lines message-required-mail-headers
)
4559 (message-generate-headers '(Lines)))
4560 ;; Remove some headers.
4561 (message-remove-header message-ignored-mail-headers t
)
4562 (let ((mail-parse-charset message-default-charset
))
4563 (mail-encode-encoded-word-buffer)))
4564 (goto-char (point-max))
4565 ;; require one newline at the end.
4566 (or (= (preceding-char) ?
\n)
4568 (message-cleanup-headers)
4569 ;; FIXME: we're inserting the courtesy copy after encoding.
4570 ;; This is wrong if the courtesy copy string contains
4571 ;; non-ASCII characters. -- jh
4574 (message-narrow-to-headers)
4576 (not (message-fetch-field "List-Post"))
4577 (not (message-fetch-field "List-ID"))
4578 (or (message-fetch-field "cc")
4579 (message-fetch-field "bcc")
4580 (message-fetch-field "to"))
4581 (let ((content-type (message-fetch-field
4586 (string= "text/plain"
4588 (mail-header-parse-content-type
4592 (message-fetch-field
4593 "content-transfer-encoding")))))))
4594 (message-insert-courtesy-copy
4595 (with-current-buffer mailbuf
4596 message-courtesy-message
)))
4597 ;; Let's make sure we encoded all the body.
4598 (assert (save-excursion
4599 (goto-char (point-min))
4600 (not (re-search-forward "[^\000-\377]" nil t
))))
4601 (mm-disable-multibyte)
4602 (if (or (not message-send-mail-partially-limit
)
4603 (< (buffer-size) message-send-mail-partially-limit
)
4604 (not (message-y-or-n-p
4605 "The message size is too large, split? "
4609 (/ (buffer-size) 1000) "KB, is too large.
4611 Some mail gateways (MTA's) bounce large messages. To avoid the
4612 problem, answer `y', and the message will be split into several
4613 smaller pieces, the size of each is about "
4614 (/ message-send-mail-partially-limit
1000)
4618 However, some mail readers (MUA's) can't read split messages, i.e.,
4619 mails in message/partially format. Answer `n', and the message will be
4622 The size limit is controlled by `message-send-mail-partially-limit'.
4623 If you always want Gnus to send messages in one piece, set
4624 `message-send-mail-partially-limit' to nil.
4627 (message "Sending via mail...")
4628 (if message-send-mail-real-function
4629 (funcall message-send-mail-real-function
)
4630 (message-multi-smtp-send-mail)))
4631 (message-send-mail-partially))
4632 (setq options message-options
))
4633 (kill-buffer tembuf
))
4634 (set-buffer mailbuf
)
4635 (setq message-options options
)
4636 (push 'mail message-sent-message-via
)))
4638 (defvar sendmail-program
)
4639 (defvar smtpmail-smtp-server
)
4640 (defvar smtpmail-smtp-service
)
4641 (defvar smtpmail-smtp-user
)
4643 (defun message-multi-smtp-send-mail ()
4644 "Send the current buffer to `message-send-mail-function'.
4645 Or, if there's a header that specifies a different method, use
4647 (let ((method (message-field-value "X-Message-SMTP-Method")))
4649 (funcall message-send-mail-function
)
4650 (message-remove-header "X-Message-SMTP-Method")
4651 (setq method
(split-string method
))
4653 ((equal (car method
) "sendmail")
4654 (message-send-mail-with-sendmail))
4655 ((equal (car method
) "smtp")
4657 (let ((smtpmail-smtp-server (nth 1 method
))
4658 (smtpmail-smtp-service (nth 2 method
))
4659 (smtpmail-smtp-user (or (nth 3 method
) smtpmail-smtp-user
)))
4660 (message-smtpmail-send-it)))
4662 (error "Unknown method %s" method
))))))
4664 (defun message-send-mail-with-sendmail ()
4665 "Send off the prepared buffer with sendmail."
4667 (let ((errbuf (if message-interactive
4668 (message-generate-new-buffer-clone-locals
4671 resend-to-addresses delimline
)
4674 (let ((case-fold-search t
))
4676 (message-narrow-to-headers)
4677 (setq resend-to-addresses
(message-fetch-field "resent-to")))
4678 ;; Change header-delimiter to be what sendmail expects.
4679 (goto-char (point-min))
4681 (concat "^" (regexp-quote mail-header-separator
) "\n"))
4682 (replace-match "\n")
4684 (setq delimline
(point-marker))
4685 (run-hooks 'message-send-mail-hook
)
4686 ;; Insert an extra newline if we need it to work around
4687 ;; Sun's bug that swallows newlines.
4688 (goto-char (1+ delimline
))
4689 (when (eval message-mailer-swallows-blank-line
)
4691 (when message-interactive
4692 (with-current-buffer errbuf
4694 (let* ((default-directory "/")
4695 (coding-system-for-write message-send-coding-system
)
4697 'call-process-region
4699 (list (point-min) (point-max) sendmail-program
4700 nil errbuf nil
"-oi")
4701 message-sendmail-extra-arguments
4702 ;; Always specify who from,
4703 ;; since some systems have broken sendmails.
4704 ;; But some systems are more broken with -f, so
4705 ;; we'll let users override this.
4706 (and (null message-sendmail-f-is-evil
)
4707 (list "-f" (message-sendmail-envelope-from)))
4708 ;; These mean "report errors by mail"
4709 ;; and "deliver in background".
4710 (if (null message-interactive
) '("-oem" "-odb"))
4711 ;; Get the addresses from the message
4712 ;; unless this is a resend.
4713 ;; We must not do that for a resend
4714 ;; because we would find the original addresses.
4715 ;; For a resend, include the specific addresses.
4716 (if resend-to-addresses
4717 (list resend-to-addresses
)
4719 (unless (or (null cpr
) (and (numberp cpr
) (zerop cpr
)))
4721 (pop-to-buffer errbuf
)
4723 (error "Sending...failed with exit value %d" cpr
)))
4724 (when message-interactive
4725 (with-current-buffer errbuf
4726 (goto-char (point-min))
4727 (while (re-search-forward "\n+ *" nil t
)
4728 (replace-match "; "))
4729 (if (not (zerop (buffer-size)))
4730 (error "Sending...failed to %s"
4731 (buffer-string))))))
4732 (when (bufferp errbuf
)
4733 (kill-buffer errbuf
)))))
4735 (defun message-send-mail-with-qmail ()
4736 "Pass the prepared message buffer to qmail-inject.
4737 Refer to the documentation for the variable `message-send-mail-function'
4738 to find out how to use this."
4739 ;; replace the header delimiter with a blank line
4740 (goto-char (point-min))
4742 (concat "^" (regexp-quote mail-header-separator
) "\n"))
4743 (replace-match "\n")
4744 (run-hooks 'message-send-mail-hook
)
4747 (let ((coding-system-for-write message-send-coding-system
))
4749 'call-process-region
(point-min) (point-max)
4750 message-qmail-inject-program nil nil nil
4751 ;; qmail-inject's default behavior is to look for addresses on the
4752 ;; command line; if there're none, it scans the headers.
4753 ;; yes, it does The Right Thing w.r.t. Resent-To and it's kin.
4755 ;; in general, ALL of qmail-inject's defaults are perfect for simply
4756 ;; reading a formatted (i. e., at least a To: or Resent-To header)
4757 ;; message from stdin.
4759 ;; qmail also has the advantage of not having been raped by
4760 ;; various vendors, so we don't have to allow for that, either --
4761 ;; compare this with message-send-mail-with-sendmail and weep
4762 ;; for sendmail's lost innocence.
4764 ;; all this is way cool coz it lets us keep the arguments entirely
4765 ;; free for -inject-arguments -- a big win for the user and for us
4766 ;; since we don't have to play that double-guessing game and the user
4767 ;; gets full control (no gestapo'ish -f's, for instance). --sj
4768 (if (functionp message-qmail-inject-args
)
4769 (funcall message-qmail-inject-args
)
4770 message-qmail-inject-args
)))
4771 ;; qmail-inject doesn't say anything on it's stdout/stderr,
4772 ;; we have to look at the retval instead
4774 (100 (error "qmail-inject reported permanent failure"))
4775 (111 (error "qmail-inject reported transient failure"))
4776 ;; should never happen
4777 (t (error "qmail-inject reported unknown failure"))))
4779 (defvar mh-previous-window-config
)
4781 (defun message-send-mail-with-mh ()
4782 "Send the prepared message buffer with mh."
4783 (let ((mh-previous-window-config nil
)
4784 (name (mh-new-draft-name)))
4785 (setq buffer-file-name name
)
4786 ;; MH wants to generate these headers itself.
4787 (when message-mh-deletable-headers
4788 (let ((headers message-mh-deletable-headers
))
4790 (goto-char (point-min))
4791 (and (re-search-forward
4792 (concat "^" (symbol-name (car headers
)) ": *") nil t
)
4793 (message-delete-line))
4795 (run-hooks 'message-send-mail-hook
)
4796 ;; Pass it on to mh.
4799 (defun message-smtpmail-send-it ()
4800 "Send the prepared message buffer with `smtpmail-send-it'.
4801 The only difference from `smtpmail-send-it' is that this command
4802 evaluates `message-send-mail-hook' just before sending a message.
4803 It is useful if your ISP requires the POP-before-SMTP
4804 authentication. See the Gnus manual for details."
4805 (run-hooks 'message-send-mail-hook
)
4806 ;; Change header-delimiter to be what smtpmail expects.
4807 (goto-char (point-min))
4808 (when (re-search-forward
4809 (concat "^" (regexp-quote mail-header-separator
) "\n"))
4810 (replace-match "\n"))
4813 (defun message-send-mail-with-mailclient ()
4814 "Send the prepared message buffer with `mailclient-send-it'.
4815 The only difference from `mailclient-send-it' is that this
4816 command evaluates `message-send-mail-hook' just before sending a message."
4817 (run-hooks 'message-send-mail-hook
)
4818 (mailclient-send-it))
4820 (defvar sha1-maximum-internal-length
)
4822 (defun message-canlock-generate ()
4823 "Return a string that is non-trivial to guess.
4824 Do not use this for anything important, it is cryptographically weak."
4826 (let (sha1-maximum-internal-length)
4827 (sha1 (concat (message-unique-id)
4828 (format "%x%x%x" (random) (random) (random))
4829 (prin1-to-string (recent-keys))
4830 (prin1-to-string (garbage-collect))))))
4832 (defvar canlock-password
)
4833 (defvar canlock-password-for-verify
)
4835 (defun message-canlock-password ()
4836 "The password used by message for cancel locks.
4837 This is the value of `canlock-password', if that option is non-nil.
4838 Otherwise, generate and save a value for `canlock-password' first."
4840 (unless canlock-password
4841 (customize-save-variable 'canlock-password
(message-canlock-generate))
4842 (setq canlock-password-for-verify canlock-password
))
4845 (defun message-insert-canlock ()
4846 (when message-insert-canlock
4847 (message-canlock-password)
4848 (canlock-insert-header)))
4850 (autoload 'nnheader-get-report
"nnheader")
4852 (declare-function gnus-setup-posting-charset
"gnus-msg" (group))
4854 (defun message-send-news (&optional arg
)
4856 (let* ((tembuf (message-generate-new-buffer-clone-locals " *message temp*"))
4857 (case-fold-search nil
)
4858 (method (if (functionp message-post-method
)
4859 (funcall message-post-method arg
)
4860 message-post-method
))
4861 (newsgroups-field (save-restriction
4862 (message-narrow-to-headers-or-head)
4863 (message-fetch-field "Newsgroups")))
4864 (followup-field (save-restriction
4865 (message-narrow-to-headers-or-head)
4866 (message-fetch-field "Followup-To")))
4867 ;; BUG: We really need to get the charset for each name in the
4868 ;; Newsgroups and Followup-To lines to allow crossposting
4869 ;; between group names with incompatible character sets.
4870 ;; -- Per Abrahamsen <abraham@dina.kvl.dk> 2001-10-08.
4871 (group-field-charset
4872 (gnus-group-name-charset method newsgroups-field
))
4873 (followup-field-charset
4874 (gnus-group-name-charset method
(or followup-field
"")))
4875 (rfc2047-header-encoding-alist
4876 (append (when group-field-charset
4877 (list (cons "Newsgroups" group-field-charset
)))
4878 (when followup-field-charset
4879 (list (cons "Followup-To" followup-field-charset
)))
4880 rfc2047-header-encoding-alist
))
4881 (messbuf (current-buffer))
4882 (message-syntax-checks
4884 (listp message-syntax-checks
))
4885 (cons '(existing-newsgroups . disabled
)
4886 message-syntax-checks
)
4887 message-syntax-checks
))
4888 (message-this-is-news t
)
4889 (message-posting-charset
4890 (gnus-setup-posting-charset newsgroups-field
))
4892 (if (not (message-check-news-body-syntax))
4895 (message-narrow-to-headers)
4896 ;; Insert some headers.
4897 (message-generate-headers message-required-news-headers
)
4898 (message-insert-canlock)
4899 ;; Let the user do all of the above.
4900 (run-hooks 'message-header-hook
))
4901 ;; Note: This check will be disabled by the ".*" default value for
4902 ;; gnus-group-name-charset-group-alist. -- Pa 2001-10-07.
4903 (when (and group-field-charset
4904 (listp message-syntax-checks
))
4905 (setq message-syntax-checks
4906 (cons '(valid-newsgroups . disabled
)
4907 message-syntax-checks
)))
4908 (message-cleanup-headers)
4909 (if (not (let ((message-post-method method
))
4910 (message-check-news-syntax)))
4913 (with-current-buffer tembuf
4914 (buffer-disable-undo)
4916 ;; Avoid copying text props (except hard newlines).
4918 (with-current-buffer messbuf
4919 (mml-buffer-substring-no-properties-except-some
4920 (point-min) (point-max))))
4921 (message-encode-message-body)
4922 ;; Remove some headers.
4924 (message-narrow-to-headers)
4925 ;; We (re)generate the Lines header.
4926 (when (memq 'Lines message-required-mail-headers
)
4927 (message-generate-headers '(Lines)))
4928 ;; Remove some headers.
4929 (message-remove-header message-ignored-news-headers t
)
4930 (let ((mail-parse-charset message-default-charset
))
4931 (mail-encode-encoded-word-buffer)))
4932 (goto-char (point-max))
4933 ;; require one newline at the end.
4934 (or (= (preceding-char) ?
\n)
4936 (let ((case-fold-search t
))
4937 ;; Remove the delimiter.
4938 (goto-char (point-min))
4940 (concat "^" (regexp-quote mail-header-separator
) "\n"))
4941 (replace-match "\n")
4943 (run-hooks 'message-send-news-hook
)
4944 (gnus-open-server method
)
4945 (message "Sending news via %s..." (gnus-server-string method
))
4946 (setq result
(let ((mail-header-separator ""))
4947 (gnus-request-post method
))))
4948 (kill-buffer tembuf
))
4949 (set-buffer messbuf
)
4951 (push 'news message-sent-message-via
)
4952 (message "Couldn't send message via news: %s"
4953 (nnheader-get-report (car method
)))
4957 ;;; Header generation & syntax checking.
4960 (defun message-check-element (type)
4961 "Return non-nil if this TYPE is not to be checked."
4962 (if (eq message-syntax-checks
'dont-check-for-anything-just-trust-me
)
4964 (let ((able (assq type message-syntax-checks
)))
4966 (eq (cdr able
) 'disabled
)))))
4968 (defun message-check-news-syntax ()
4969 "Check the syntax of the message."
4973 ;; We narrow to the headers and check them first.
4976 (message-narrow-to-headers)
4977 (message-check-news-header-syntax))))))
4979 (defun message-check-news-header-syntax ()
4981 ;; Check Newsgroups header.
4982 (message-check 'newsgroups
4983 (let ((group (message-fetch-field "newsgroups")))
4986 (not (string-match "\\`[ \t]*\\'" group
)))
4989 "The newsgroups field is empty or missing. Posting is denied.")))))
4990 ;; Check the Subject header.
4991 (message-check 'subject
4992 (let* ((case-fold-search t
)
4993 (subject (message-fetch-field "subject")))
4996 (not (string-match "\\`[ \t]*\\'" subject
)))
4999 "The subject field is empty or missing. Posting is denied.")))))
5000 ;; Check for commands in Subject.
5001 (message-check 'subject-cmsg
5002 (if (string-match "^cmsg " (message-fetch-field "subject"))
5004 "The control code \"cmsg\" is in the subject. Really post? ")
5006 ;; Check long header lines.
5007 (message-check 'long-header-lines
5011 (while (and (not found
)
5012 (re-search-forward "^\\([^ \t:]+\\): " nil t
))
5013 (if (> (- (point) (match-beginning 0)) 998)
5015 length
(- (point) (match-beginning 0)))
5016 (setq header
(match-string-no-properties 1)))
5019 (y-or-n-p (format "Your %s header is too long (%d). Really post? "
5022 ;; Check for multiple identical headers.
5023 (message-check 'multiple-headers
5025 (while (and (not found
)
5026 (re-search-forward "^[^ \t:]+: " nil t
))
5028 (or (re-search-forward
5033 (match-beginning 0) (- (match-end 0) 2))))
5038 (y-or-n-p (format "Multiple %s headers. Really post? " found
))
5040 ;; Check for Version and Sendsys.
5041 (message-check 'sendsys
5042 (if (re-search-forward "^Sendsys:\\|^Version:" nil t
)
5044 (format "The article contains a %s command. Really post? "
5045 (buffer-substring (match-beginning 0)
5046 (1- (match-end 0)))))
5048 ;; See whether we can shorten Followup-To.
5049 (message-check 'shorten-followup-to
5050 (let ((newsgroups (message-fetch-field "newsgroups"))
5051 (followup-to (message-fetch-field "followup-to"))
5053 (when (and newsgroups
5054 (string-match "," newsgroups
)
5059 (setq to
(completing-read
5060 "Followups to (default no Followup-To header): "
5063 (message-tokenize-header
5065 (goto-char (point-min))
5066 (insert "Followup-To: " to
"\n"))
5068 ;; Check "Shoot me".
5069 (message-check 'shoot
5070 (if (re-search-forward
5071 "Message-ID.*.i-did-not-set--mail-host-address--so-tickle-me" nil t
)
5072 (y-or-n-p "You appear to have a misconfigured system. Really post? ")
5074 ;; Check for Approved.
5075 (message-check 'approved
5076 (if (re-search-forward "^Approved:" nil t
)
5077 (y-or-n-p "The article contains an Approved header. Really post? ")
5079 ;; Check the Message-ID header.
5080 (message-check 'message-id
5081 (let* ((case-fold-search t
)
5082 (message-id (message-fetch-field "message-id" t
)))
5083 (or (not message-id
)
5084 ;; Is there an @ in the ID?
5085 (and (string-match "@" message-id
)
5086 ;; Is there a dot in the ID?
5087 (string-match "@[^.]*\\." message-id
)
5088 ;; Does the ID end with a dot?
5089 (not (string-match "\\.>" message-id
)))
5091 (format "The Message-ID looks strange: \"%s\". Really post? "
5093 ;; Check the Newsgroups & Followup-To headers.
5094 (message-check 'existing-newsgroups
5095 (let* ((case-fold-search t
)
5096 (newsgroups (message-fetch-field "newsgroups"))
5097 (followup-to (message-fetch-field "followup-to"))
5098 (groups (message-tokenize-header
5100 (concat newsgroups
"," followup-to
)
5102 (post-method (if (functionp message-post-method
)
5103 (funcall message-post-method
)
5104 message-post-method
))
5105 ;; KLUDGE to handle nnvirtual groups. Doing this right
5106 ;; would probably involve a new nnoo function.
5107 ;; -- Per Abrahamsen <abraham@dina.kvl.dk>, 2001-10-17.
5108 (method (if (and (consp post-method
)
5109 (eq (car post-method
) 'nnvirtual
)
5110 gnus-message-group-art
)
5111 (let ((group (car (nnvirtual-find-group-art
5112 (car gnus-message-group-art
)
5113 (cdr gnus-message-group-art
)))))
5114 (gnus-find-method-for-group group
))
5118 (gnus-group-name-decode
5119 (gnus-group-real-name n
)
5120 (gnus-group-name-charset method n
)))
5121 (gnus-groups-from-server method
)))
5124 (when (and (not (equal (car groups
) "poster"))
5125 (not (member (car groups
) known-groups
))
5126 (not (member (car groups
) errors
)))
5127 (push (car groups
) errors
))
5130 ;; Gnus is not running.
5131 ((or (not (and (boundp 'gnus-active-hashtb
)
5132 gnus-active-hashtb
))
5133 (not (boundp 'gnus-read-active-file
)))
5135 ;; We don't have all the group names.
5136 ((and (or (not gnus-read-active-file
)
5137 (eq gnus-read-active-file
'some
))
5141 "Really use %s possibly unknown group%s: %s? "
5142 (if (= (length errors
) 1) "this" "these")
5143 (if (= (length errors
) 1) "" "s")
5144 (mapconcat 'identity errors
", "))))
5145 ;; There were no errors.
5148 ;; There are unknown groups.
5152 "Really post to %s unknown group%s: %s? "
5153 (if (= (length errors
) 1) "this" "these")
5154 (if (= (length errors
) 1) "" "s")
5155 (mapconcat 'identity errors
", ")))))))
5156 ;; Check continuation headers.
5157 (message-check 'continuation-headers
5158 (goto-char (point-min))
5159 (let ((do-posting t
))
5160 (while (re-search-forward "^[^ \t\n][^ \t\n:]*[ \t\n]" nil t
)
5161 (goto-char (match-beginning 0))
5162 (if (y-or-n-p "Fix continuation lines? ")
5165 (unless (y-or-n-p "Send anyway? ")
5166 (setq do-posting nil
))))
5168 ;; Check the Newsgroups & Followup-To headers for syntax errors.
5169 (message-check 'valid-newsgroups
5170 (let ((case-fold-search t
)
5171 (headers '("Newsgroups" "Followup-To"))
5173 (while (and headers
(not error
))
5174 (when (setq header
(mail-fetch-field (car headers
)))
5178 "\\`\\([-+_&.a-zA-Z0-9]+\\)?\\(,[-+_&.a-zA-Z0-9]+\\)*\\'"
5183 (not (string-match "\\.\\'\\|\\.\\." g
)))
5184 (message-tokenize-header header
","))))
5191 (format "The %s header looks odd: \"%s\". Really post? "
5192 (car headers
) header
)))))
5193 (message-check 'repeated-newsgroups
5194 (let ((case-fold-search t
)
5195 (headers '("Newsgroups" "Followup-To"))
5196 header error groups group
)
5199 (when (setq header
(mail-fetch-field (pop headers
)))
5200 (setq groups
(message-tokenize-header header
","))
5201 (while (setq group
(pop groups
))
5202 (when (member group groups
)
5208 (format "Group %s is repeated in headers. Really post? " error
)))))
5209 ;; Check the From header.
5210 (message-check 'from
5211 (let* ((case-fold-search t
)
5212 (from (message-fetch-field "from"))
5216 (message "There is no From line. Posting is denied.")
5218 ((or (not (string-match
5220 (setq ad
(nth 1 (mail-extract-address-components
5221 from
))))) ;larsi@ifi
5222 (string-match "\\.\\." ad
) ;larsi@ifi..uio
5223 (string-match "@\\." ad
) ;larsi@.ifi.uio
5224 (string-match "\\.$" ad
) ;larsi@ifi.uio.
5225 (not (string-match "^[^@]+@[^@]+$" ad
)) ;larsi.ifi.uio
5226 (string-match "(.*).*(.*)" from
)) ;(lars) (lars)
5228 "Denied posting -- the From looks strange: \"%s\"." from
)
5230 ((let ((addresses (rfc822-addresses from
)))
5231 ;; `rfc822-addresses' returns a string if parsing fails.
5232 (while (and (consp addresses
)
5233 (not (eq (string-to-char (car addresses
)) ?\
()))
5234 (setq addresses
(cdr addresses
)))
5237 "Denied posting -- bad From address: \"%s\"." from
)
5240 ;; Check the Reply-To header.
5241 (message-check 'reply-to
5242 (let* ((case-fold-search t
)
5243 (reply-to (message-fetch-field "reply-to"))
5248 ((string-match "," reply-to
)
5250 (format "Multiple Reply-To addresses: \"%s\". Really post? "
5252 ((or (not (string-match
5254 (setq ad
(nth 1 (mail-extract-address-components
5255 reply-to
))))) ;larsi@ifi
5256 (string-match "\\.\\." ad
) ;larsi@ifi..uio
5257 (string-match "@\\." ad
) ;larsi@.ifi.uio
5258 (string-match "\\.$" ad
) ;larsi@ifi.uio.
5259 (not (string-match "^[^@]+@[^@]+$" ad
)) ;larsi.ifi.uio
5260 (string-match "(.*).*(.*)" reply-to
)) ;(lars) (lars)
5263 "The Reply-To looks strange: \"%s\". Really post? "
5267 (defun message-check-news-body-syntax ()
5269 ;; Check for long lines.
5270 (message-check 'long-lines
5271 (goto-char (point-min))
5273 (concat "^" (regexp-quote mail-header-separator
) "$"))
5277 "<#\\(/\\)?\\(multipart\\|part\\|external\\|mml\\)")
5280 (< (- (point) p
) 80)))
5281 (zerop (forward-line 1))))
5285 "You have lines longer than 79 characters. Really post? ")))
5286 ;; Check whether the article is empty.
5287 (message-check 'empty
5288 (goto-char (point-min))
5290 (concat "^" (regexp-quote mail-header-separator
) "$"))
5293 (goto-char (point-max))
5294 (re-search-backward message-signature-separator nil t
)
5296 (or (re-search-backward "[^ \n\t]" b t
)
5297 (if (message-gnksa-enable-p 'empty-article
)
5298 (y-or-n-p "Empty article. Really post? ")
5299 (message "Denied posting -- Empty article.")
5301 ;; Check for control characters.
5302 (message-check 'control-chars
5303 (if (re-search-forward
5304 (string-to-multibyte "[\000-\007\013\015-\032\034-\037\200-\237]")
5307 "The article contains control characters. Really post? ")
5309 ;; Check excessive size.
5310 (message-check 'size
5311 (if (> (buffer-size) 60000)
5313 (format "The article is %d octets long. Really post? "
5316 ;; Check whether any new text has been added.
5317 (message-check 'new-text
5319 (not message-checksum
)
5320 (not (eq (message-checksum) message-checksum
))
5321 (if (message-gnksa-enable-p 'quoted-text-only
)
5323 "It looks like no new text has been added. Really post? ")
5324 (message "Denied posting -- no new text has been added.")
5326 ;; Check the length of the signature.
5327 (message-check 'signature
5328 (let (sig-start sig-end
)
5329 (goto-char (point-max))
5330 (if (not (re-search-backward message-signature-separator nil t
))
5332 (setq sig-start
(1+ (point-at-eol)))
5334 (if (re-search-forward
5335 "<#/?\\(multipart\\|part\\|external\\|mml\\)" nil t
)
5336 (- (point-at-bol) 1)
5338 (if (>= (count-lines sig-start sig-end
) 5)
5339 (if (message-gnksa-enable-p 'signature
)
5341 (format "Signature is excessively long (%d lines). Really post? "
5342 (count-lines sig-start sig-end
)))
5343 (message "Denied posting -- Excessive signature.")
5346 ;; Ensure that text follows last quoted portion.
5347 (message-check 'quoting-style
5348 (goto-char (point-max))
5349 (let ((no-problem t
))
5350 (when (search-backward-regexp "^>[^\n]*\n" nil t
)
5351 (setq no-problem
(search-forward-regexp "^[ \t]*[^>\n]" nil t
)))
5354 (if (message-gnksa-enable-p 'quoted-text-only
)
5355 (y-or-n-p "Your text should follow quoted text. Really post? ")
5357 (goto-char (point-min))
5359 (concat "^" (regexp-quote mail-header-separator
) "$"))
5360 (if (search-forward-regexp "^[ \t]*[^>\n]" nil t
)
5361 (y-or-n-p "Your text should follow quoted text. Really post? ")
5362 (message "Denied posting -- only quoted text.")
5365 (defun message-checksum ()
5366 "Return a \"checksum\" for the current buffer."
5369 (goto-char (point-min))
5371 (concat "^" (regexp-quote mail-header-separator
) "$"))
5373 (when (not (looking-at "[ \t\n]"))
5374 (setq sum
(logxor (ash sum
1) (if (natnump sum
) 0 1)
5379 (defun message-do-fcc ()
5380 "Process Fcc headers in the current buffer."
5381 (let ((case-fold-search t
)
5382 (buf (current-buffer))
5384 (mml-externalize-attachments message-fcc-externalize-attachments
))
5387 (message-narrow-to-headers)
5388 (setq file
(message-fetch-field "fcc" t
)))
5390 (set-buffer (get-buffer-create " *message temp*"))
5392 (insert-buffer-substring buf
)
5393 (message-encode-message-body)
5395 (message-narrow-to-headers)
5396 (while (setq file
(message-fetch-field "fcc" t
))
5398 (message-remove-header "fcc" nil t
))
5399 (let ((mail-parse-charset message-default-charset
)
5400 (rfc2047-header-encoding-alist
5401 (cons '("Newsgroups" . default
)
5402 rfc2047-header-encoding-alist
)))
5403 (mail-encode-encoded-word-buffer)))
5404 (goto-char (point-min))
5405 (when (re-search-forward
5406 (concat "^" (regexp-quote mail-header-separator
) "$")
5408 (replace-match "" t t
))
5409 ;; Process FCC operations.
5411 (setq file
(pop list
))
5412 (if (string-match "^[ \t]*|[ \t]*\\(.*\\)[ \t]*$" file
)
5413 ;; Pipe the article to the program in question.
5414 (call-shell-region (point-min) (point-max) (match-string 1 file
))
5415 ;; Save the article.
5416 (setq file
(expand-file-name file
))
5417 (unless (file-exists-p (file-name-directory file
))
5418 (make-directory (file-name-directory file
) t
))
5419 (if (and message-fcc-handler-function
5420 (not (eq message-fcc-handler-function
'rmail-output
)))
5421 (funcall message-fcc-handler-function file
)
5422 ;; FIXME this option, rmail-output (also used if
5423 ;; message-fcc-handler-function is nil) is not
5424 ;; documented anywhere AFAICS. It should work in Emacs
5425 ;; 23; I suspect it does not work in Emacs 22.
5426 ;; FIXME I don't see the need for the two different cases here.
5427 ;; mail-use-rfc822 makes no difference (in Emacs 23),and
5428 ;; the third argument just controls \"Wrote file\" message.
5429 (if (and (file-readable-p file
) (mail-file-babyl-p file
))
5430 (rmail-output file
1 nil t
)
5431 (let ((mail-use-rfc822 t
))
5432 (rmail-output file
1 t t
))))))
5433 (kill-buffer (current-buffer))))))
5435 (defun message-output (filename)
5436 "Append this article to Unix/babyl mail file FILENAME."
5437 (if (or (and (file-readable-p filename
)
5438 (mail-file-babyl-p filename
))
5439 ;; gnus-output-to-mail does the wrong thing with live, mbox
5440 ;; Rmail buffers in Emacs 23.
5441 ;; http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=597255
5442 (let ((buff (find-buffer-visiting filename
)))
5443 (and buff
(with-current-buffer buff
5444 (eq major-mode
'rmail-mode
)))))
5445 (gnus-output-to-rmail filename t
)
5446 (gnus-output-to-mail filename t
)))
5448 (defun message-cleanup-headers ()
5449 "Do various automatic cleanups of the headers."
5450 ;; Remove empty lines in the header.
5452 (message-narrow-to-headers)
5453 ;; Remove blank lines.
5454 (while (re-search-forward "^[ \t]*\n" nil t
)
5455 (replace-match "" t t
))
5457 ;; Correct Newsgroups and Followup-To headers: Change sequence of
5458 ;; spaces to comma and eliminate spaces around commas. Eliminate
5459 ;; embedded line breaks.
5460 (goto-char (point-min))
5461 (while (re-search-forward "^\\(Newsgroups\\|Followup-To\\): +" nil t
)
5465 (if (re-search-forward "^[^ \t]" nil t
)
5469 (goto-char (point-min))
5470 (while (re-search-forward "\n[ \t]+" nil t
)
5471 (replace-match " " t t
)) ;No line breaks (too confusing)
5472 (goto-char (point-min))
5473 (while (re-search-forward "[ \t\n]*,[ \t\n]*\\|[ \t]+" nil t
)
5474 (replace-match "," t t
))
5475 (goto-char (point-min))
5476 ;; Remove trailing commas.
5477 (when (re-search-forward ",+$" nil t
)
5478 (replace-match "" t t
))))))
5480 (defun message-make-date (&optional now
)
5481 "Make a valid data header.
5482 If NOW, use that time instead."
5483 (let ((system-time-locale "C"))
5484 (format-time-string "%a, %d %b %Y %T %z" now
)))
5486 (defun message-insert-expires (days)
5487 "Insert the Expires header. Expiry in DAYS days."
5488 (interactive "NExpire article in how many days? ")
5490 (message-position-on-field "Expires" "X-Draft-From")
5491 (insert (message-make-expires-date days
))))
5493 (defun message-make-expires-date (days)
5494 "Make date string for the Expires header. Expiry in DAYS days.
5496 In posting styles use `(\"Expires\" (make-expires-date 30))'."
5497 (let* ((cur (decode-time))
5498 (nday (+ days
(nth 3 cur
))))
5499 (setf (nth 3 cur
) nday
)
5500 (message-make-date (apply 'encode-time cur
))))
5502 (defun message-make-message-id ()
5503 "Make a unique Message-ID."
5504 (concat "<" (message-unique-id)
5505 (let ((psubject (save-excursion (message-fetch-field "subject")))
5507 (save-excursion (message-fetch-field "supersedes"))))
5509 (and message-reply-headers
5510 (mail-header-references message-reply-headers
)
5511 (mail-header-subject message-reply-headers
)
5514 (message-strip-subject-re
5515 (mail-header-subject message-reply-headers
))
5516 (message-strip-subject-re psubject
))))
5518 (string-match "_-_@" psupersedes
)))
5520 "@" (message-make-fqdn) ">"))
5522 (defvar message-unique-id-char nil
)
5524 ;; If you ever change this function, make sure the new version
5525 ;; cannot generate IDs that the old version could.
5526 ;; You might for example insert a "." somewhere (not next to another dot
5527 ;; or string boundary), or modify the "fsf" string.
5528 (defun message-unique-id ()
5529 ;; Don't use microseconds from (current-time), they may be unsupported.
5530 ;; Instead we use this randomly inited counter.
5531 (setq message-unique-id-char
5532 (%
(1+ (or message-unique-id-char
5533 (logand (random most-positive-fixnum
) (1- (lsh 1 20)))))
5534 ;; (current-time) returns 16-bit ints,
5535 ;; and 2^16*25 just fits into 4 digits i base 36.
5537 (let ((tm (current-time)))
5539 (if (or (eq system-type
'ms-dos
)
5540 ;; message-number-base36 doesn't handle bigints.
5541 (floatp (user-uid)))
5542 (let ((user (downcase (user-login-name))))
5543 (while (string-match "[^a-z0-9_]" user
)
5544 (aset user
(match-beginning 0) ?_
))
5546 (message-number-base36 (user-uid) -
1))
5547 (message-number-base36 (+ (car tm
)
5548 (lsh (% message-unique-id-char
25) 16)) 4)
5549 (message-number-base36 (+ (nth 1 tm
)
5550 (lsh (/ message-unique-id-char
25) 16)) 4)
5551 ;; Append a given name, because while the generated ID is unique
5552 ;; to this newsreader, other newsreaders might otherwise generate
5553 ;; the same ID via another algorithm.
5556 (defun message-number-base36 (num len
)
5561 (concat (message-number-base36 (/ num
36) (1- len
))
5562 (char-to-string (aref "zyxwvutsrqponmlkjihgfedcba9876543210"
5565 (defun message-make-organization ()
5566 "Make an Organization header."
5567 (let* ((organization
5568 (when message-user-organization
5569 (if (functionp message-user-organization
)
5570 (funcall message-user-organization
)
5571 message-user-organization
))))
5573 (mm-enable-multibyte)
5574 (cond ((stringp organization
)
5575 (insert organization
))
5576 ((and (eq t organization
)
5577 message-user-organization-file
5578 (file-exists-p message-user-organization-file
))
5579 (insert-file-contents message-user-organization-file
)))
5580 (goto-char (point-min))
5581 (while (re-search-forward "[\t\n]+" nil t
)
5582 (replace-match "" t t
))
5583 (unless (zerop (buffer-size))
5586 (defun message-make-lines ()
5587 "Count the number of lines and return numeric string."
5592 (int-to-string (count-lines (point) (point-max))))))
5594 (defun message-make-references ()
5595 "Return the References header for this message."
5596 (when message-reply-headers
5597 (let ((message-id (mail-header-id message-reply-headers
))
5598 (references (mail-header-references message-reply-headers
)))
5599 (if (or references message-id
)
5600 (concat (or references
"") (and references
" ")
5604 (defun message-make-in-reply-to ()
5605 "Return the In-Reply-To header for this message."
5606 (when message-reply-headers
5607 (let ((from (mail-header-from message-reply-headers
))
5608 (date (mail-header-date message-reply-headers
))
5609 (msg-id (mail-header-id message-reply-headers
)))
5611 (let ((name (mail-extract-address-components from
)))
5613 msg-id
(if msg-id
" (")
5615 (if (string-match "[^\000-\177]" (car name
))
5616 ;; Quote a string containing non-ASCII characters.
5617 ;; It will make the RFC2047 encoder cause an error
5618 ;; if there are special characters.
5619 (mm-with-multibyte-buffer
5621 (goto-char (point-min))
5622 (while (search-forward "\"" nil t
)
5625 (zerop (%
(skip-chars-backward "\\\\") 2))
5626 (goto-char (match-beginning 0)))
5629 ;; Those quotes will be removed by the RFC2047 encoder.
5630 (concat "\"" (buffer-string) "\""))
5634 (if (or (not date
) (string= date
""))
5635 "(unknown date)" date
)
5636 "\"" (if msg-id
")")))))))
5638 (defun message-make-distribution ()
5639 "Make a Distribution header."
5640 (let ((orig-distribution (message-fetch-reply-field "distribution")))
5641 (cond ((functionp message-distribution-function
)
5642 (funcall message-distribution-function
))
5643 (t orig-distribution
))))
5645 (defun message-make-expires ()
5646 "Return an Expires header based on `message-expires'."
5647 (let ((current (current-time))
5648 (future (* 1.0 message-expires
60 60 24)))
5649 ;; Add the future to current.
5650 (setcar current
(+ (car current
) (round (/ future
(expt 2 16)))))
5651 (setcar (cdr current
) (+ (nth 1 current
) (%
(round future
) (expt 2 16))))
5652 (message-make-date current
)))
5654 (defun message-make-path ()
5656 (let ((login-name (user-login-name)))
5657 (cond ((null message-user-path
)
5658 (concat (system-name) "!" login-name
))
5659 ((stringp message-user-path
)
5660 ;; Support GENERICPATH. Suggested by vixie@decwrl.dec.com.
5661 (concat message-user-path
"!" login-name
))
5664 (defun message-make-from (&optional name address
)
5665 "Make a From header."
5666 (let* ((style message-from-style
)
5667 (login (or address
(message-make-address)))
5668 (fullname (or name user-full-name
(user-full-name))))
5669 (when (string= fullname
"&")
5670 (setq fullname
(user-login-name)))
5672 (mm-enable-multibyte)
5675 (equal fullname
""))
5677 ((or (eq style
'angles
)
5678 (and (not (eq style
'parens
))
5679 ;; Use angles if no quoting is needed, or if parens would
5680 ;; need quoting too.
5681 (or (not (string-match "[^- !#-'*+/-9=?A-Z^-~]" fullname
))
5682 (let ((tmp (concat fullname nil
)))
5683 (while (string-match "([^()]*)" tmp
)
5684 (aset tmp
(match-beginning 0) ?-
)
5685 (aset tmp
(1- (match-end 0)) ?-
))
5686 (string-match "[\\()]" tmp
)))))
5688 (goto-char (point-min))
5689 ;; Look for a character that cannot appear unquoted
5690 ;; according to RFC 822.
5691 (when (re-search-forward "[^- !#-'*+/-9=?A-Z^-~]" nil
1)
5692 ;; Quote fullname, escaping specials.
5693 (goto-char (point-min))
5695 (while (re-search-forward "[\"\\]" nil
1)
5696 (replace-match "\\\\\\&" t
))
5698 (insert " <" login
">"))
5699 (t ; 'parens or default
5701 (let ((fullname-start (point)))
5703 (goto-char fullname-start
)
5704 ;; RFC 822 says \ and nonmatching parentheses
5705 ;; must be escaped in comments.
5706 ;; Escape every instance of ()\ ...
5707 (while (re-search-forward "[()\\]" nil
1)
5708 (replace-match "\\\\\\&" t
))
5709 ;; ... then undo escaping of matching parentheses,
5710 ;; including matching nested parentheses.
5711 (goto-char fullname-start
)
5712 (while (re-search-forward
5713 "\\(\\=\\|[^\\]\\(\\\\\\\\\\)*\\)\\\\(\\(\\([^\\]\\|\\\\\\\\\\)*\\)\\\\)"
5715 (replace-match "\\1(\\3)" t
)
5716 (goto-char fullname-start
)))
5720 (defun message-make-sender ()
5721 "Return the \"real\" user address.
5722 This function tries to ignore all user modifications, and
5723 give as trustworthy answer as possible."
5724 (concat (user-login-name) "@" (system-name)))
5726 (defun message-make-address ()
5727 "Make the address of the user."
5728 (or (message-user-mail-address)
5729 (concat (user-login-name) "@" (message-make-domain))))
5731 (defun message-user-mail-address ()
5732 "Return the pertinent part of `user-mail-address'."
5733 (when (and user-mail-address
5734 (string-match "@.*\\." user-mail-address
))
5735 (if (string-match " " user-mail-address
)
5736 (nth 1 (mail-extract-address-components user-mail-address
))
5737 user-mail-address
)))
5739 (defun message-sendmail-envelope-from ()
5740 "Return the envelope from."
5741 (cond ((eq message-sendmail-envelope-from
'header
)
5742 (nth 1 (mail-extract-address-components
5743 (message-fetch-field "from"))))
5744 ((stringp message-sendmail-envelope-from
)
5745 message-sendmail-envelope-from
)
5747 (message-make-address))))
5749 (defun message-make-fqdn ()
5750 "Return user's fully qualified domain name."
5751 (let* ((sysname (system-name))
5752 (user-mail (message-user-mail-address))
5755 (string-match "@\\(.*\\)\\'" user-mail
))
5756 (match-string 1 user-mail
)))
5757 (case-fold-search t
))
5759 ((and message-user-fqdn
5760 (stringp message-user-fqdn
)
5761 (not (string-match message-bogus-system-names message-user-fqdn
)))
5762 ;; `message-user-fqdn' seems to be valid
5764 ((and (string-match message-bogus-system-names sysname
))
5765 ;; `system-name' returned the right result.
5767 ;; Try `mail-host-address'.
5768 ((and (stringp mail-host-address
)
5769 (not (string-match message-bogus-system-names mail-host-address
)))
5771 ;; We try `user-mail-address' as a backup.
5773 (stringp user-domain
)
5774 (not (string-match message-bogus-system-names user-domain
)))
5776 ;; Default to this bogus thing.
5779 ".i-did-not-set--mail-host-address--so-tickle-me")))))
5781 (defun message-make-domain ()
5782 "Return the domain name."
5783 (or mail-host-address
5784 (message-make-fqdn)))
5786 (defun message-to-list-only ()
5787 "Send a message to the list only.
5788 Remove all addresses but the list address from To and Cc headers."
5790 (let ((listaddr (message-make-mail-followup-to t
)))
5793 (message-remove-header "to")
5794 (message-remove-header "cc")
5795 (message-position-on-field "To" "X-Draft-From")
5796 (insert listaddr
)))))
5798 (defun message-make-mail-followup-to (&optional only-show-subscribed
)
5799 "Return the Mail-Followup-To header.
5800 If passed the optional argument ONLY-SHOW-SUBSCRIBED only return the
5801 subscribed address (and not the additional To and Cc header contents)."
5802 (let* ((case-fold-search t
)
5803 (to (message-fetch-field "To"))
5804 (cc (message-fetch-field "cc"))
5805 (msg-recipients (concat to
(and to cc
", ") cc
))
5807 (mapcar 'mail-strip-quoted-names
5808 (message-tokenize-header msg-recipients
)))
5810 (if message-subscribed-address-file
5811 (let (begin end item re
)
5814 (insert-file-contents message-subscribed-address-file
)
5816 (setq begin
(point))
5819 (if (bolp) (setq end
(1- end
)))
5820 (setq item
(regexp-quote (buffer-substring begin end
)))
5821 (if re
(setq re
(concat re
"\\|" item
))
5822 (setq re
(concat "\\`\\(" item
))))
5823 (and re
(list (concat re
"\\)\\'"))))))))
5824 (mft-regexps (apply 'append message-subscribed-regexps
5825 (mapcar 'regexp-quote
5826 message-subscribed-addresses
)
5829 message-subscribed-address-functions
))))
5832 (loop for recipient in recipients
5833 when
(loop for regexp in mft-regexps
5834 when
(string-match regexp recipient
) return t
)
5837 (if only-show-subscribed
5839 msg-recipients
))))))
5841 (defun message-idna-to-ascii-rhs-1 (header)
5842 "Interactively potentially IDNA encode domain names in HEADER."
5843 (let ((field (message-fetch-field header
))
5848 (mapcar (lambda (rhs) (or (cadr (split-string rhs
"@")) ""))
5854 (mail-extract-address-components field t
))))))
5855 ;; Note that `rhs' will be "" if the address does not have
5856 ;; the domain part, i.e., if it is a local user's address.
5857 (setq ace
(if (string-match "\\`[[:ascii:]]*\\'" rhs
)
5859 (downcase (puny-encode-domain rhs
))))
5860 (when (and (not (equal rhs ace
))
5861 (or (not (eq message-use-idna
'ask
))
5862 (y-or-n-p (format "Replace %s with %s in %s:? "
5864 (goto-char (point-min))
5865 (while (re-search-forward (concat "^" header
":") nil t
)
5866 (message-narrow-to-field)
5867 (while (search-forward (concat "@" rhs
) nil t
)
5868 (replace-match (concat "@" ace
) t t
))
5869 (goto-char (point-max))
5872 (defun message-idna-to-ascii-rhs ()
5873 "Possibly IDNA encode non-ASCII domain names in From:, To: and Cc: headers.
5874 See `message-idna-encode'."
5876 (when message-use-idna
5879 ;; `message-narrow-to-head' that recognizes only the first empty
5880 ;; line as the message header separator used to be used here.
5881 ;; However, since there is the "--text follows this line--" line
5882 ;; normally, it failed in narrowing to the headers and potentially
5883 ;; caused the IDNA encoding on lines that look like headers in
5884 ;; the message body.
5885 (message-narrow-to-headers-or-head)
5886 (message-idna-to-ascii-rhs-1 "From")
5887 (message-idna-to-ascii-rhs-1 "To")
5888 (message-idna-to-ascii-rhs-1 "Reply-To")
5889 (message-idna-to-ascii-rhs-1 "Mail-Reply-To")
5890 (message-idna-to-ascii-rhs-1 "Mail-Followup-To")
5891 (message-idna-to-ascii-rhs-1 "Cc")))))
5893 (defun message-generate-headers (headers)
5894 "Prepare article HEADERS.
5895 Headers already prepared in the buffer are not modified."
5896 (setq headers
(append headers message-required-headers
))
5898 (message-narrow-to-headers)
5899 (let* ((header-values
5900 (list 'Date
(message-make-date)
5901 'Message-ID
(message-make-message-id)
5902 'Organization
(message-make-organization)
5903 'From
(message-make-from)
5904 'Path
(message-make-path)
5907 'In-Reply-To
(message-make-in-reply-to)
5908 'References
(message-make-references)
5910 'Distribution
(message-make-distribution)
5911 'Lines
(message-make-lines)
5912 'User-Agent message-newsreader
5913 'Expires
(message-make-expires)))
5914 (case-fold-search t
)
5916 header value elem header-string
)
5917 ;; First we remove any old generated headers.
5918 (let ((headers message-deletable-headers
))
5919 (unless (buffer-modified-p)
5920 (setq headers
(delq 'Message-ID
(copy-sequence headers
))))
5922 (goto-char (point-min))
5923 (and (re-search-forward
5924 (concat "^" (symbol-name (car headers
)) ": *") nil t
)
5925 (get-text-property (1+ (match-beginning 0)) 'message-deletable
)
5926 (message-delete-line))
5928 ;; Go through all the required headers and see if they are in the
5929 ;; articles already. If they are not, or are empty, they are
5930 ;; inserted automatically - except for Subject, Newsgroups and
5933 (goto-char (point-min))
5934 (setq elem
(pop headers
))
5936 (if (eq (car elem
) 'optional
)
5937 (setq header
(cdr elem
)
5939 (setq header
(car elem
)))
5941 (setq header-string
(if (stringp header
)
5943 (symbol-name header
)))
5944 (when (or (not (re-search-forward
5946 (regexp-quote (downcase header-string
))
5950 ;; The header was found. We insert a space after the
5951 ;; colon, if there is none.
5952 (if (/= (char-after) ?
) (insert " ") (forward-char 1))
5953 ;; Find out whether the header is empty.
5954 (looking-at "[ \t]*\n[^ \t]")))
5955 ;; So we find out what value we should insert.
5959 (eq (car elem
) 'optional
)
5960 (not (member header-string message-inserted-headers
)))
5961 ;; This is an optional header. If the cdr of this
5962 ;; is something that is nil, then we do not insert
5964 (setq header
(cdr elem
))
5965 (or (and (functionp (cdr elem
))
5966 (funcall (cdr elem
)))
5967 (and (symbolp (cdr elem
))
5968 (plist-get header-values
(cdr elem
)))))
5970 ;; The element is a cons. Either the cdr is a
5971 ;; string to be inserted verbatim, or it is a
5972 ;; function, and we insert the value returned from
5974 (or (and (stringp (cdr elem
))
5976 (and (functionp (cdr elem
))
5977 (funcall (cdr elem
)))))
5978 ((and (symbolp header
)
5979 (plist-member header-values header
))
5980 ;; The element is a symbol. We insert the value of
5981 ;; this symbol, if any.
5982 (plist-get header-values header
))
5983 ((not (message-check-element
5984 (intern (downcase (symbol-name header
)))))
5985 ;; We couldn't generate a value for this header,
5986 ;; so we just ask the user.
5987 (read-from-minibuffer
5988 (format "Empty header for %s; enter value: " header
)))))
5989 ;; Finally insert the header.
5991 (not (equal value
"")))
5995 ;; This header didn't exist, so we insert it.
5996 (goto-char (point-max))
5998 (cdr (assq header message-header-format-alist
))))
6000 (funcall formatter header value
)
6001 (insert header-string
": " value
))
6002 (push header-string message-inserted-headers
)
6003 (goto-char (message-fill-field))
6004 ;; We check whether the value was ended by a
6005 ;; newline. If not, we insert one.
6009 ;; The value of this header was empty, so we clear
6010 ;; totally and insert the new value.
6011 (delete-region (point) (point-at-eol))
6012 ;; If the header is optional, and the header was
6013 ;; empty, we can't insert it anyway.
6015 (push header-string message-inserted-headers
)
6017 (message-fill-field)))
6018 ;; Add the deletable property to the headers that require it.
6019 (and (memq header message-deletable-headers
)
6020 (progn (beginning-of-line) (looking-at "[^:]+: "))
6021 (add-text-properties
6022 (point) (match-end 0)
6023 '(message-deletable t face italic
) (current-buffer)))))))
6024 ;; Insert new Sender if the From is strange.
6025 (let ((from (message-fetch-field "from"))
6026 (sender (message-fetch-field "sender"))
6027 (secure-sender (message-make-sender)))
6029 (not (message-check-element 'sender
))
6032 (cadr (mail-extract-address-components from
)))
6033 (downcase secure-sender
)))
6038 (cadr (mail-extract-address-components sender
)))
6039 (downcase secure-sender
)))))
6040 (goto-char (point-min))
6041 ;; Rename any old Sender headers to Original-Sender.
6042 (when (re-search-forward "^\\(Original-\\)*Sender:" nil t
)
6044 (insert "Original-")
6045 (beginning-of-line))
6046 (when (or (message-news-p)
6047 (string-match "@.+\\.." secure-sender
))
6048 (insert "Sender: " secure-sender
"\n"))))
6050 (message-idna-to-ascii-rhs))))
6052 (defun message-insert-courtesy-copy (message)
6053 "Insert a courtesy message in mail copies of combined messages."
6057 (message-narrow-to-headers)
6058 (when (setq newsgroups
(message-fetch-field "newsgroups"))
6059 (goto-char (point-max))
6060 (insert "Posted-To: " newsgroups
"\n")))
6064 ((string-match "%s" message
)
6065 (insert (format message newsgroups
)))
6067 (insert message
)))))))
6070 ;;; Setting up a message buffer
6073 (defun message-skip-to-next-address ()
6074 (let ((end (save-excursion
6075 (message-next-header)
6078 (when (looking-at ",")
6080 (while (and (not (= (point) end
))
6081 (or (not (eq char ?
,))
6083 (skip-chars-forward "^,\"" end
)
6084 (when (eq (setq char
(following-char)) ?
\")
6085 (setq quoted
(not quoted
)))
6086 (unless (= (point) end
)
6088 (skip-chars-forward " \t\n")))
6090 (defun message-split-line ()
6091 "Split current line, moving portion beyond point vertically down.
6092 If the current line has `message-yank-prefix', insert it on the new line."
6094 (split-line message-yank-prefix
))
6096 (defun message-insert-header (header value
)
6097 (insert (capitalize (symbol-name header
))
6099 (if (consp value
) (car value
) value
)))
6101 (defun message-field-name ()
6103 (goto-char (point-min))
6104 (when (looking-at "\\([^:]+\\):")
6105 (intern (capitalize (match-string 1))))))
6107 (defun message-fill-field ()
6110 (message-narrow-to-field)
6111 (let ((field-name (message-field-name)))
6112 (funcall (or (cadr (assq field-name message-field-fillers
))
6113 'message-fill-field-general
)))
6116 (defun message-fill-field-address ()
6119 (message-skip-to-next-address)
6125 (when (and (> (current-column) 78)
6129 (delete-char (- (skip-chars-backward " \t")))
6131 (setq last
(point)))
6132 (forward-line end
)))
6134 (defun message-fill-field-general ()
6135 (let ((begin (point))
6138 (while (and (search-forward "\n" nil t
)
6140 (replace-match " " t t
))
6141 (fill-region-as-paragraph begin
(point-max))
6142 ;; Tapdance around looong Message-IDs.
6144 (when (looking-at "[ \t]*$")
6145 (message-delete-line))
6147 (search-forward ":" nil t
)
6148 (when (looking-at "\n[ \t]+")
6149 (replace-match " " t t
))
6150 (goto-char (point-max))))
6152 (defun message-shorten-1 (list cut surplus
)
6153 "Cut SURPLUS elements out of LIST, beginning with CUTth one."
6154 (setcdr (nthcdr (- cut
2) list
)
6155 (nthcdr (+ (- cut
2) surplus
1) list
)))
6157 (defun message-shorten-references (header references
)
6158 "Trim REFERENCES to be 21 Message-ID long or less, and fold them.
6159 When sending via news, also check that the REFERENCES are less
6160 than 988 characters long, and if they are not, trim them until
6162 ;; 21 is the number suggested by USAGE.
6169 (goto-char (point-min))
6170 ;; Cons a list of valid references. GNKSA says we must not include MIDs
6171 ;; with whitespace or missing brackets (7.a "Does not propagate broken
6172 ;; Message-IDs in original References").
6173 (while (re-search-forward "<[^ <]+@[^ <]+>" nil t
)
6174 (push (match-string 0) refs
))
6175 (setq refs
(nreverse refs
)
6176 count
(length refs
)))
6178 ;; If the list has more than MAXCOUNT elements, trim it by
6179 ;; removing the CUTth element and the required number of
6180 ;; elements that follow.
6181 (when (> count maxcount
)
6182 (let ((surplus (- count maxcount
)))
6183 (message-shorten-1 refs cut surplus
)
6184 (decf count surplus
)))
6186 ;; When sending via news, make sure the total folded length will
6187 ;; be less than 998 characters. This is to cater to broken INN
6188 ;; 2.3 which counts the total number of characters in a header
6189 ;; rather than the physical line length of each line, as it should.
6191 ;; This hack should be removed when it's believed than INN 2.3 is
6192 ;; no longer widely used.
6194 ;; At this point the headers have not been generated, thus we use
6195 ;; message-this-is-news directly.
6196 (when message-this-is-news
6199 (message-insert-header
6200 header
(mapconcat #'identity refs
" "))
6202 (message-shorten-1 refs cut
1)))
6203 ;; Finally, collect the references back into a string and insert
6204 ;; it into the buffer.
6205 (message-insert-header header
(mapconcat #'identity refs
" "))))
6207 (defun message-position-point ()
6208 "Move point to where the user probably wants to find it."
6209 (message-narrow-to-headers)
6211 ((re-search-forward "^[^:]+:[ \t]*$" nil t
)
6212 (search-backward ":" )
6215 (if (eq (char-after) ?
)
6219 (goto-char (point-max))
6222 (unless (looking-at "$")
6226 (defcustom message-beginning-of-line t
6227 "Whether \\<message-mode-map>\\[message-beginning-of-line]\
6228 goes to beginning of header values."
6230 :group
'message-buffers
6231 :link
'(custom-manual "(message)Movement")
6234 (defvar visual-line-mode
)
6235 (declare-function beginning-of-visual-line
"simple" (&optional n
))
6237 (defun message-beginning-of-header (handle-folded)
6238 "Move point to beginning of header’s value.
6240 When point is at the first header line, moves it after the colon
6241 and spaces separating header name and header value.
6243 When point is in a continuation line of a folded header (i.e. the
6244 line starts with a space), the behavior depends on HANDLE-FOLDED
6245 argument. If it’s nil, function moves the point to the start of
6246 the header continuation; otherwise, function locates the
6247 beginning of the header and moves point past the colon as is the
6248 case of single-line headers.
6250 No check whether point is inside of a header or body of the
6251 message is performed.
6253 Returns point or nil if beginning of header’s value could not be
6254 found. In the latter case, the point is still moved to the
6255 beginning of line (possibly after attempting to move it to the
6256 beginning of a folded header)."
6257 ;; https://www.rfc-editor.org/rfc/rfc2822.txt, section 2.2.3. says that when
6258 ;; unfolding a single WSP should be consumed. WSP is defined as a space
6259 ;; character or a horizontal tab.
6262 (while (and (> (point) (point-min))
6263 (or (eq (char-after) ?\s
) (eq (char-after) ?
\t)))
6264 (beginning-of-line 0)))
6265 (when (or (eq (char-after) ?\s
) (eq (char-after) ?
\t)
6266 (search-forward ":" (point-at-eol) t
))
6267 ;; We are a bit more lacks than the RFC and allow any positive number of WSP
6269 (skip-chars-forward " \t" (point-at-eol))
6272 (defun message-beginning-of-line (&optional n
)
6273 "Move point to beginning of header value or to beginning of line.
6274 The prefix argument N is passed directly to `beginning-of-line'.
6276 This command is identical to `beginning-of-line' if point is
6277 outside the message header or if the option
6278 `message-beginning-of-line' is nil.
6280 If point is in the message header and on a header line, move
6281 point to the beginning of the header value or the beginning of
6282 line, whichever is closer. If point is already at beginning of
6283 line, move point to beginning of header value. Therefore,
6284 repeated calls will toggle point between beginning of field and
6287 When called without a prefix argument, header value spanning
6288 multiple lines is treated as a single line. Otherwise, even if
6289 N is 1, when point is on a continuation header line, it will be
6290 moved to the beginning "
6293 ;; Go to beginning of header or beginning of line.
6294 ((and message-beginning-of-line
(message-point-in-header-p))
6295 (let* ((point (point))
6296 (bol (progn (beginning-of-line n
) (point)))
6297 (boh (message-beginning-of-header visual-line-mode
)))
6298 (goto-char (if (and boh
(or (< boh point
) (= bol point
))) boh bol
))))
6299 ;; Go to beginning of visual line
6301 (beginning-of-visual-line n
))
6302 ;; Go to beginning of line.
6303 ((beginning-of-line n
))))
6305 (defun message-buffer-name (type &optional to group
)
6306 "Return a new (unique) buffer name based on TYPE and TO."
6308 ;; Generate a new buffer name The Message Way.
6309 ((memq message-generate-new-buffers
'(unique t
))
6310 (generate-new-buffer-name
6314 (or (car (mail-extract-address-components to
))
6317 (if (and group
(not (string= group
""))) (concat " on " group
) "")
6319 ;; Check whether `message-generate-new-buffers' is a function,
6320 ;; and if so, call it.
6321 ((functionp message-generate-new-buffers
)
6322 (funcall message-generate-new-buffers type to group
))
6323 ((eq message-generate-new-buffers
'unsent
)
6324 (generate-new-buffer-name
6325 (concat "*unsent " type
6328 (or (car (mail-extract-address-components to
))
6331 (if (and group
(not (string= group
""))) (concat " on " group
) "")
6333 ;; Search for the existing message buffer with the specified name.
6335 (let* ((new (if (eq message-generate-new-buffers
'standard
)
6336 (generate-new-buffer-name (concat "*" type
" message*"))
6337 (let ((message-generate-new-buffers 'unique
))
6338 (message-buffer-name type to group
))))
6339 (regexp (concat "\\`"
6341 (if (string-match "<[0-9]+>\\'" new
)
6342 (substring new
0 (match-beginning 0))
6344 "\\(?:<\\([0-9]+\\)>\\)?\\'"))
6345 (case-fold-search nil
))
6352 (when (and (string-match regexp
(setq b
(buffer-name b
)))
6353 (eq (with-current-buffer b major-mode
)
6355 (cons (string-to-number (or (match-string 1 b
) "1"))
6358 'car-less-than-car
)))
6361 (defun message-pop-to-buffer (name &optional switch-function
)
6362 "Pop to buffer NAME, and warn if it already exists and is modified."
6363 (let ((buffer (get-buffer name
)))
6365 (buffer-name buffer
))
6366 (let ((window (get-buffer-window buffer
0)))
6368 ;; Raise the frame already displaying the message buffer.
6370 (select-frame-set-input-focus (window-frame window
))
6371 (select-window window
))
6372 (funcall (or switch-function
#'pop-to-buffer
) buffer
)
6373 (set-buffer buffer
))
6374 (when (and (buffer-modified-p)
6377 "Message already being composed; erase? ")
6379 (error "Message being composed")))
6380 (funcall (or switch-function
'pop-to-buffer-same-window
)
6386 (defun message-do-send-housekeeping ()
6387 "Kill old message buffers."
6388 ;; We might have sent this buffer already. Delete it from the
6390 (setq message-buffer-list
(delq (current-buffer) message-buffer-list
))
6391 (while (and message-max-buffers
6393 (>= (length message-buffer-list
) message-max-buffers
))
6394 ;; Kill the oldest buffer -- unless it has been changed.
6395 (let ((buffer (pop message-buffer-list
)))
6396 (when (and (buffer-name buffer
)
6397 (not (buffer-modified-p buffer
)))
6398 (kill-buffer buffer
))))
6399 ;; Rename the buffer.
6400 (if message-send-rename-function
6401 (funcall message-send-rename-function
)
6402 (message-default-send-rename-function))
6403 ;; Push the current buffer onto the list.
6404 (when message-max-buffers
6405 (setq message-buffer-list
6406 (nconc message-buffer-list
(list (current-buffer))))))
6408 (defun message-default-send-rename-function ()
6409 ;; Note: mail-abbrevs of XEmacs renames buffer name behind Gnus.
6411 "\\`\\*\\(sent \\|unsent \\)?\\(.+\\)\\*[^\\*]*\\|\\`mail to "
6413 (let ((name (match-string 2 (buffer-name)))
6415 (if (not (or (null name
)
6416 (string-equal name
"mail")
6417 (string-equal name
"posting")))
6418 (setq name
(concat "*sent " name
"*"))
6419 (message-narrow-to-headers)
6420 (setq to
(message-fetch-field "to"))
6421 (setq group
(message-fetch-field "newsgroups"))
6425 (to (concat "*sent mail to "
6426 (or (car (mail-extract-address-components to
))
6428 ((and group
(not (string= group
"")))
6429 (concat "*sent posting on " group
"*"))
6430 (t "*sent mail*"))))
6431 (unless (string-equal name
(buffer-name))
6432 (rename-buffer name t
)))))
6434 (defun message-mail-user-agent ()
6436 ((not message-mail-user-agent
) nil
)
6437 ((eq message-mail-user-agent t
) mail-user-agent
)
6438 (t message-mail-user-agent
))))
6439 (if (memq mua
'(message-user-agent gnus-user-agent
))
6443 ;; YANK-ACTION, if non-nil, can be a buffer or a yank action of the
6444 ;; form (FUNCTION . ARGS).
6445 (defun message-setup (headers &optional yank-action actions
6446 continue switch-function return-action
)
6447 (let ((mua (message-mail-user-agent))
6449 (if (not (and message-this-is-mail mua
))
6450 (message-setup-1 headers yank-action actions return-action
)
6451 (setq headers
(copy-sequence headers
))
6452 (setq field
(assq 'Subject headers
))
6454 (setq subject
(cdr field
))
6455 (setq headers
(delq field headers
)))
6456 (setq field
(assq 'To headers
))
6458 (setq to
(cdr field
))
6459 (setq headers
(delq field headers
)))
6460 (let ((mail-user-agent mua
))
6461 (compose-mail to subject
6462 (mapcar (lambda (item)
6464 (format "%s" (car item
))
6467 continue switch-function
6468 (if (bufferp yank-action
)
6469 (list 'insert-buffer yank-action
)
6473 (defun message-headers-to-generate (headers included-headers excluded-headers
)
6474 "Return a list that includes all headers from HEADERS.
6475 If INCLUDED-HEADERS is a list, just include those headers. If it is
6476 t, include all headers. In any case, headers from EXCLUDED-HEADERS
6480 (dolist (header headers
)
6481 (setq header-name
(cond
6482 ((and (consp header
)
6483 (eq (car header
) 'optional
))
6484 ;; On the form (optional . Header)
6487 ;; On the form (Header . function)
6492 (when (and (not (memq header-name excluded-headers
))
6493 (or (eq included-headers t
)
6494 (memq header-name included-headers
)))
6495 (push header result
)))
6498 (defun message-setup-1 (headers &optional yank-action actions return-action
)
6499 (dolist (action actions
)
6501 (add-to-list 'message-send-actions
6502 `(apply ',(car action
) ',(cdr action
)))))
6503 (setq message-return-action return-action
)
6504 (setq message-reply-buffer
6505 (if (and (consp yank-action
)
6506 (eq (car yank-action
) 'insert-buffer
))
6509 (goto-char (point-min))
6510 ;; Insert all the headers.
6513 (alist message-header-format-alist
))
6515 (unless (assq (caar h
) message-header-format-alist
)
6516 (push (list (caar h
)) alist
))
6520 (delete-region (point) (progn (forward-line -
1) (point)))
6521 (when message-default-headers
6523 (if (functionp message-default-headers
)
6524 (funcall message-default-headers
)
6525 message-default-headers
))
6526 (or (bolp) (insert ?
\n)))
6527 (insert (concat mail-header-separator
"\n"))
6529 ;; If a crash happens while replying, the auto-save file would *not* have a
6530 ;; `References:' header if `message-generate-headers-first' was nil.
6531 ;; Therefore, always generate it first.
6532 (let ((message-generate-headers-first
6533 (if (eq message-generate-headers-first t
)
6535 (append message-generate-headers-first
'(References)))))
6536 (when (message-news-p)
6537 (when message-default-news-headers
6538 (insert message-default-news-headers
)
6539 (or (bolp) (insert ?
\n)))
6540 (message-generate-headers
6541 (message-headers-to-generate
6542 (append message-required-news-headers
6543 message-required-headers
)
6544 message-generate-headers-first
6546 (when (message-mail-p)
6547 (when message-default-mail-headers
6548 (insert message-default-mail-headers
)
6549 (or (bolp) (insert ?
\n)))
6550 (message-generate-headers
6551 (message-headers-to-generate
6552 (append message-required-mail-headers
6553 message-required-headers
)
6554 message-generate-headers-first
6555 '(Lines Subject
)))))
6556 (run-hooks 'message-signature-setup-hook
)
6557 (message-insert-signature)
6559 (message-narrow-to-headers)
6560 (run-hooks 'message-header-setup-hook
))
6561 (setq buffer-undo-list nil
)
6562 (when message-generate-hashcash
6563 ;; Generate hashcash headers for recipients already known
6564 (mail-add-payment-async))
6565 ;; Gnus posting styles are applied via buffer-local `message-setup-hook'
6567 (run-hooks 'message-setup-hook
)
6568 ;; Do this last to give it precedence over posting styles, etc.
6569 (when (message-mail-p)
6571 (message-narrow-to-headers)
6572 (if message-alternative-emails
6573 (message-use-alternative-email-as-from))))
6574 (message-position-point)
6575 ;; Allow correct handling of `message-checksum' in `message-yank-original':
6576 (set-buffer-modified-p nil
)
6578 ;; rmail-start-mail expects message-mail to return t (Bug#9392)
6581 (defun message-set-auto-save-file-name ()
6582 "Associate the message buffer with a file in the drafts directory."
6583 (when message-auto-save-directory
6584 (unless (file-directory-p
6585 (directory-file-name message-auto-save-directory
))
6586 (make-directory message-auto-save-directory t
))
6588 (setq message-draft-article
6589 (nndraft-request-associate-buffer "drafts"))
6591 ;; If Gnus were alive, draft messages would be saved in the drafts folder.
6592 ;; But Gnus is not alive, so arrange to save the draft message in a
6593 ;; regular file in message-auto-save-directory. Append a unique
6594 ;; time-based suffix to the filename to allow multiple drafts to be saved
6595 ;; simultaneously without overwriting each other (which mimics the
6596 ;; functionality of the Gnus drafts folder).
6597 (setq buffer-file-name
(expand-file-name
6599 (if (memq system-type
6600 '(ms-dos windows-nt cygwin
))
6603 (format-time-string "-%Y%m%d-%H%M%S"))
6604 message-auto-save-directory
))
6605 (setq buffer-auto-save-file-name
(make-auto-save-file-name)))
6606 (clear-visited-file-modtime)
6607 (setq buffer-file-coding-system message-draft-coding-system
)))
6609 (defun message-disassociate-draft ()
6610 "Disassociate the message buffer from the drafts directory."
6611 (when message-draft-article
6612 (nndraft-request-expire-articles
6613 (list message-draft-article
) "drafts" nil t
)))
6615 (defun message-insert-headers ()
6616 "Generate the headers for the article."
6620 (message-narrow-to-headers)
6621 (when (message-news-p)
6622 (message-generate-headers
6625 (copy-sequence message-required-news-headers
)))))
6626 (when (message-mail-p)
6627 (message-generate-headers
6630 (copy-sequence message-required-mail-headers
))))))))
6635 ;;; Commands for interfacing with message
6639 (defun message-mail (&optional to subject other-headers continue
6640 switch-function yank-action send-actions
6641 return-action
&rest ignored
)
6642 "Start editing a mail message to be sent.
6643 OTHER-HEADERS is an alist of header/value pairs. CONTINUE says whether
6644 to continue editing a message already being composed. SWITCH-FUNCTION
6645 is a function used to switch to and display the mail buffer."
6647 (let ((message-this-is-mail t
))
6648 (unless (message-mail-user-agent)
6649 (message-pop-to-buffer
6650 ;; Search for the existing message buffer if `continue' is non-nil.
6651 (let ((message-generate-new-buffers
6652 (when (or (not continue
)
6653 (eq message-generate-new-buffers
'standard
)
6654 (functionp message-generate-new-buffers
))
6655 message-generate-new-buffers
)))
6656 (message-buffer-name "mail" to
))
6660 `((To .
,(or to
"")) (Subject .
,(or subject
"")))
6661 ;; C-h f compose-mail says that headers should be specified as
6662 ;; (string . value); however all the rest of message expects
6663 ;; headers to be symbols, not strings (eg message-header-format-alist).
6664 ;; http://lists.gnu.org/archive/html/emacs-devel/2011-01/msg00337.html
6665 ;; We need to convert any string input, eg from rmail-start-mail.
6666 (dolist (h other-headers other-headers
)
6667 (if (stringp (car h
)) (setcar h
(intern (capitalize (car h
)))))))
6668 yank-action send-actions continue switch-function
6672 (defun message-news (&optional newsgroups subject
)
6673 "Start editing a news article to be sent."
6675 (let ((message-this-is-news t
))
6676 (message-pop-to-buffer (message-buffer-name "posting" nil newsgroups
))
6677 (message-setup `((Newsgroups .
,(or newsgroups
""))
6678 (Subject .
,(or subject
""))))))
6680 (defun message-alter-recipients-discard-bogus-full-name (addrcell)
6681 "Discard mail address in full names.
6682 When the full name in reply headers contains the mail
6683 address (e.g. \"foo@bar <foo@bar>\"), discard full name.
6684 ADDRCELL is a cons cell where the car is the mail address and the
6685 cdr is the complete address (full name and mail address)."
6686 (if (string-match (concat (regexp-quote (car addrcell
)) ".*"
6687 (regexp-quote (car addrcell
)))
6689 (cons (car addrcell
) (car addrcell
))
6692 (defcustom message-alter-recipients-function nil
6693 "Function called to allow alteration of reply header structures.
6694 It is called in `message-get-reply-headers' for each recipient.
6695 The function is called with one parameter, a cons cell ..."
6696 :type
'(choice (const :tag
"None" nil
)
6697 (const :tag
"Discard bogus full name"
6698 message-alter-recipients-discard-bogus-full-name
)
6700 :version
"23.1" ;; No Gnus
6701 :group
'message-headers
)
6703 (defun message-get-reply-headers (wide &optional to-address address-headers
)
6704 (let (follow-to mct never-mct to cc author mft recipients extra
)
6705 ;; Find all relevant headers we need.
6707 (message-narrow-to-headers-or-head)
6708 ;; Gmane renames "To". Look at "Original-To", too, if it is present in
6709 ;; message-header-synonyms.
6710 (setq to
(or (message-fetch-field "to")
6711 (and (loop for synonym in message-header-synonyms
6712 when
(memq 'Original-To synonym
)
6714 (message-fetch-field "original-to")))
6715 cc
(message-fetch-field "cc")
6716 extra
(when message-extra-wide-headers
6717 (mapconcat 'identity
6718 (mapcar 'message-fetch-field
6719 message-extra-wide-headers
)
6721 mct
(message-fetch-field "mail-copies-to")
6722 author
(or (message-fetch-field "mail-reply-to")
6723 (message-fetch-field "reply-to"))
6724 mft
(and message-use-mail-followup-to
6725 (message-fetch-field "mail-followup-to")))
6726 ;; Make sure this message goes to the author if this is a wide
6727 ;; reply, since Reply-To address may be a list address a mailing
6728 ;; list server added.
6729 (when (and wide author
)
6730 (setq cc
(concat author
", " cc
)))
6731 (when (or wide
(not author
))
6732 (setq author
(or (message-fetch-field "from") ""))))
6734 ;; Handle special values of Mail-Copies-To.
6736 (cond ((or (equal (downcase mct
) "never")
6737 (equal (downcase mct
) "nobody"))
6740 ((or (equal (downcase mct
) "always")
6741 (equal (downcase mct
) "poster"))
6742 (setq mct author
))))
6745 ;; Build (textual) list of new recipient addresses.
6748 (setq recipients
(concat ", " to-address
))
6749 ;; If the author explicitly asked for a copy, we don't deny it to them.
6750 (if mct
(setq recipients
(concat recipients
", " mct
))))
6752 (setq recipients
(concat ", " author
)))
6754 (dolist (header address-headers
)
6755 (let ((value (message-fetch-field header
)))
6757 (setq recipients
(concat recipients
", " value
))))))
6759 (string-match "[^ \t,]" mft
)
6760 (or (not (eq message-use-mail-followup-to
'ask
))
6761 (message-y-or-n-p "Obey Mail-Followup-To? " t
"\
6762 You should normally obey the Mail-Followup-To: header. In this
6763 article, it has the value of
6767 which directs your response to " (if (string-match "," mft
)
6768 "the specified addresses"
6769 "that address only") ".
6771 Most commonly, Mail-Followup-To is used by a mailing list poster to
6772 express that responses should be sent to just the list, and not the
6775 If a message is posted to several mailing lists, Mail-Followup-To may
6776 also be used to direct the following discussion to one list only,
6777 because discussions that are spread over several lists tend to be
6778 fragmented and very difficult to follow.
6780 Also, some source/announcement lists are not intended for discussion;
6781 responses here are directed to other addresses.
6783 You may customize the variable `message-use-mail-followup-to', if you
6784 want to get rid of this query permanently.")))
6785 (setq recipients
(concat ", " mft
)))
6787 (setq recipients
(if never-mct
"" (concat ", " author
)))
6788 (if to
(setq recipients
(concat recipients
", " to
)))
6789 (if cc
(setq recipients
(concat recipients
", " cc
)))
6790 (if extra
(setq recipients
(concat recipients
", " extra
)))
6791 (if mct
(setq recipients
(concat recipients
", " mct
)))))
6792 (if (>= (length recipients
) 2)
6793 ;; Strip the leading ", ".
6794 (setq recipients
(substring recipients
2)))
6795 ;; Squeeze whitespace.
6796 (while (string-match "[ \t][ \t]+" recipients
)
6797 (setq recipients
(replace-match " " t t recipients
)))
6798 ;; Remove addresses that match `message-dont-reply-to-names'.
6800 (cond ((functionp message-dont-reply-to-names
)
6804 (mapcar (lambda (mail)
6805 (unless (funcall message-dont-reply-to-names
6806 (mail-strip-quoted-names mail
))
6808 (message-tokenize-header recipients
)))
6810 (t (let ((mail-dont-reply-to-names (message-dont-reply-to-names)))
6811 (mail-dont-reply-to recipients
)))))
6812 ;; Perhaps "Mail-Copies-To: never" removed the only address?
6813 (if (string-equal recipients
"")
6814 (setq recipients author
))
6815 ;; Convert string to a list of (("foo@bar" . "Name <Foo@BAR>") ...).
6819 (if message-alter-recipients-function
6820 (funcall message-alter-recipients-function
6821 (cons (downcase (mail-strip-quoted-names addr
))
6823 (cons (downcase (mail-strip-quoted-names addr
)) addr
)))
6824 (message-tokenize-header recipients
)))
6825 ;; Remove all duplicates.
6826 (let ((s recipients
))
6828 (let ((address (car (pop s
))))
6829 (while (assoc address s
)
6830 (setq recipients
(delq (assoc address s
) recipients
)
6831 s
(delq (assoc address s
) s
))))))
6833 ;; Remove hierarchical lists that are contained within each other,
6834 ;; if message-hierarchical-addresses is defined.
6835 (when message-hierarchical-addresses
6836 (let ((plain-addrs (mapcar 'car recipients
))
6839 (setq subaddrs
(assoc (car plain-addrs
)
6840 message-hierarchical-addresses
)
6841 plain-addrs
(cdr plain-addrs
))
6843 (setq subaddrs
(cdr subaddrs
))
6845 (setq recip
(assoc (car subaddrs
) recipients
)
6846 subaddrs
(cdr subaddrs
))
6848 (setq recipients
(delq recip recipients
))))))))
6850 (setq recipients
(message-prune-recipients recipients
))
6852 ;; Build the header alist. Allow the user to be asked whether
6853 ;; or not to reply to all recipients in a wide reply.
6854 (setq follow-to
(list (cons 'To
(cdr (pop recipients
)))))
6855 (when (and recipients
6856 (or (not message-wide-reply-confirm-recipients
)
6857 (y-or-n-p "Reply to all recipients? ")))
6858 (setq recipients
(mapconcat
6859 (lambda (addr) (cdr addr
)) recipients
", "))
6860 (if (string-match "^ +" recipients
)
6861 (setq recipients
(substring recipients
(match-end 0))))
6862 (push (cons 'Cc recipients
) follow-to
)))
6865 (defun message-prune-recipients (recipients)
6866 (dolist (rule message-prune-recipient-rules
)
6867 (let ((match (car rule
))
6870 (dolist (recipient recipients
)
6871 (setq address
(car recipient
))
6872 (when (string-match match address
)
6873 (setq dup-match
(replace-match (cadr rule
) nil nil address
))
6874 (dolist (recipient recipients
)
6875 ;; Don't delete the address that triggered this.
6876 (when (and (not (eq address
(car recipient
)))
6877 (string-match dup-match
(car recipient
)))
6878 (setq recipients
(delq recipient recipients
))))))))
6881 (defcustom message-simplify-subject-functions
6882 '(message-strip-list-identifiers
6883 message-strip-subject-re
6884 message-strip-subject-trailing-was
6885 message-strip-subject-encoded-words
)
6886 "List of functions taking a string argument that simplify subjects.
6887 The functions are applied when replying to a message.
6889 Useful functions to put in this list include:
6890 `message-strip-list-identifiers', `message-strip-subject-re',
6891 `message-strip-subject-trailing-was', and
6892 `message-strip-subject-encoded-words'."
6893 :version
"22.1" ;; Gnus 5.10.9
6894 :group
'message-various
6895 :type
'(repeat function
))
6897 (defun message-simplify-subject (subject &optional functions
)
6898 "Return simplified SUBJECT."
6901 (setq functions message-simplify-subject-functions
))
6902 (when (and (memq 'message-strip-list-identifiers functions
)
6903 gnus-list-identifiers
)
6904 (setq subject
(message-strip-list-identifiers subject
)))
6905 (when (memq 'message-strip-subject-re functions
)
6906 (setq subject
(concat "Re: " (message-strip-subject-re subject
))))
6907 (when (and (memq 'message-strip-subject-trailing-was functions
)
6908 message-subject-trailing-was-query
)
6909 (setq subject
(message-strip-subject-trailing-was subject
)))
6910 (when (memq 'message-strip-subject-encoded-words functions
)
6911 (setq subject
(message-strip-subject-encoded-words subject
)))
6915 (defun message-reply (&optional to-address wide switch-function
)
6916 "Start editing a reply to the article in the current buffer."
6918 (require 'gnus-sum
) ; for gnus-list-identifiers
6919 (let ((cur (current-buffer))
6921 references message-id follow-to
6922 (inhibit-point-motion-hooks t
)
6923 (message-this-is-mail t
)
6926 (message-narrow-to-head-1)
6927 ;; Allow customizations to have their say.
6929 ;; This is a regular reply.
6930 (when (functionp message-reply-to-function
)
6932 (setq follow-to
(funcall message-reply-to-function
))))
6933 ;; This is a followup.
6934 (when (functionp message-wide-reply-to-function
)
6937 (funcall message-wide-reply-to-function
)))))
6938 (setq message-id
(message-fetch-field "message-id" t
)
6939 references
(message-fetch-field "references")
6940 date
(message-fetch-field "date")
6941 from
(or (message-fetch-field "from") "nobody")
6942 subject
(or (message-fetch-field "subject") "none"))
6944 ;; Strip list identifiers, "Re: ", and "was:"
6945 (setq subject
(message-simplify-subject subject
))
6947 (when (and (setq gnus-warning
(message-fetch-field "gnus-warning"))
6948 (string-match "<[^>]+>" gnus-warning
))
6949 (setq message-id
(match-string 0 gnus-warning
)))
6952 (setq follow-to
(message-get-reply-headers wide to-address
))))
6955 `((Subject .
,subject
)
6957 (unless (message-mail-user-agent)
6958 (message-pop-to-buffer
6959 (message-buffer-name
6960 (if wide
"wide reply" "reply") from
6961 (if wide to-address nil
))
6963 (setq message-reply-headers
6964 (vector 0 (cdr (assq 'Subject headers
))
6965 from date message-id references
0 0 ""))
6966 (message-setup headers cur
))))
6969 (defun message-wide-reply (&optional to-address
)
6970 "Make a \"wide\" reply to the message in the current buffer."
6972 (message-reply to-address t
))
6975 (defun message-followup (&optional to-newsgroups
)
6976 "Follow up to the message in the current buffer.
6977 If TO-NEWSGROUPS, use that as the new Newsgroups line."
6979 (require 'gnus-sum
) ; for gnus-list-identifiers
6980 (let ((cur (current-buffer))
6981 from subject date reply-to mrt mct
6982 references message-id follow-to
6983 (inhibit-point-motion-hooks t
)
6984 (message-this-is-news t
)
6985 followup-to distribution newsgroups gnus-warning posted-to
)
6988 (goto-char (point-min))
6989 (if (search-forward "\n\n" nil t
)
6992 (when (functionp message-followup-to-function
)
6994 (funcall message-followup-to-function
)))
6995 (setq from
(message-fetch-field "from")
6996 date
(message-fetch-field "date")
6997 subject
(or (message-fetch-field "subject") "none")
6998 references
(message-fetch-field "references")
6999 message-id
(message-fetch-field "message-id" t
)
7000 followup-to
(message-fetch-field "followup-to")
7001 newsgroups
(message-fetch-field "newsgroups")
7002 posted-to
(message-fetch-field "posted-to")
7003 reply-to
(message-fetch-field "reply-to")
7004 mrt
(message-fetch-field "mail-reply-to")
7005 distribution
(message-fetch-field "distribution")
7006 mct
(message-fetch-field "mail-copies-to"))
7007 (when (and (setq gnus-warning
(message-fetch-field "gnus-warning"))
7008 (string-match "<[^>]+>" gnus-warning
))
7009 (setq message-id
(match-string 0 gnus-warning
)))
7010 ;; Remove bogus distribution.
7011 (when (and (stringp distribution
)
7012 (let ((case-fold-search t
))
7013 (string-match "world" distribution
)))
7014 (setq distribution nil
))
7015 ;; Strip list identifiers, "Re: ", and "was:"
7016 (setq subject
(message-simplify-subject subject
))
7019 (message-pop-to-buffer (message-buffer-name "followup" from newsgroups
))
7021 (setq message-reply-headers
7022 (vector 0 subject from date message-id references
0 0 ""))
7025 `((Subject .
,subject
)
7028 (list (cons 'Newsgroups to-newsgroups
)))
7029 (follow-to follow-to
)
7030 ((and followup-to message-use-followup-to
)
7033 ((equal (downcase followup-to
) "poster")
7034 (if (or (eq message-use-followup-to
'use
)
7035 (message-y-or-n-p "Obey Followup-To: poster? " t
"\
7036 You should normally obey the Followup-To: header.
7038 `Followup-To: poster' sends your response via e-mail instead of news.
7040 A typical situation where `Followup-To: poster' is used is when the poster
7041 does not read the newsgroup, so he wouldn't see any replies sent to it.
7043 You may customize the variable `message-use-followup-to', if you
7044 want to get rid of this query permanently."))
7046 (setq message-this-is-news nil
)
7047 (cons 'To
(or mrt reply-to from
"")))
7048 (cons 'Newsgroups newsgroups
)))
7050 (if (or (equal followup-to newsgroups
)
7051 (not (eq message-use-followup-to
'ask
))
7053 (concat "Obey Followup-To: " followup-to
"? ") t
"\
7054 You should normally obey the Followup-To: header.
7056 `Followup-To: " followup-to
"'
7057 directs your response to " (if (string-match "," followup-to
)
7058 "the specified newsgroups"
7059 "that newsgroup only") ".
7061 If a message is posted to several newsgroups, Followup-To is often
7062 used to direct the following discussion to one newsgroup only,
7063 because discussions that are spread over several newsgroup tend to
7064 be fragmented and very difficult to follow.
7066 Also, some source/announcement newsgroups are not intended for discussion;
7067 responses here are directed to other newsgroups.
7069 You may customize the variable `message-use-followup-to', if you
7070 want to get rid of this query permanently."))
7071 (cons 'Newsgroups followup-to
)
7072 (cons 'Newsgroups newsgroups
))))))
7074 `((Newsgroups .
,posted-to
)))
7076 `((Newsgroups .
,newsgroups
))))
7077 ,@(and distribution
(list (cons 'Distribution distribution
)))
7079 (not (or (equal (downcase mct
) "never")
7080 (equal (downcase mct
) "nobody"))))
7081 (list (cons 'Cc
(if (or (equal (downcase mct
) "always")
7082 (equal (downcase mct
) "poster"))
7083 (or mrt reply-to from
"")
7088 (defun message-is-yours-p ()
7089 "Non-nil means current article is yours.
7090 If you have added `cancel-messages' to `message-shoot-gnksa-feet', all articles
7091 are yours except those that have Cancel-Lock header not belonging to you.
7092 Instead of shooting GNKSA feet, you should modify `message-alternative-emails'
7093 to match all of yours addresses."
7094 ;; Canlock-logic as suggested by Per Abrahamsen
7095 ;; <abraham@dina.kvl.dk>
7097 ;; IF article has cancel-lock THEN
7098 ;; IF we can verify it THEN
7101 ;; error: cancellock: article is not yours
7103 ;; Use old rules, comparing sender...
7106 (message-narrow-to-head-1)
7107 (if (and (message-fetch-field "Cancel-Lock")
7108 (message-gnksa-enable-p 'canlock-verify
))
7109 (if (null (canlock-verify))
7111 (error "Failed to verify Cancel-lock: This article is not yours"))
7114 (message-gnksa-enable-p 'cancel-messages
)
7115 (and (setq sender
(message-fetch-field "sender"))
7116 (string-equal (downcase sender
)
7117 (downcase (message-make-sender))))
7118 ;; Email address in From field equals to our address
7119 (and (setq from
(message-fetch-field "from"))
7121 (downcase (car (mail-header-parse-address from
)))
7122 (downcase (car (mail-header-parse-address
7123 (message-make-from))))))
7124 ;; Email address in From field matches
7125 ;; 'message-alternative-emails' regexp or function.
7127 message-alternative-emails
7128 (cond ((functionp message-alternative-emails
)
7129 (funcall message-alternative-emails
7130 (mail-header-parse-address from
)))
7131 (t (string-match message-alternative-emails
7132 (car (mail-header-parse-address from
))))))))))))
7135 (defun message-cancel-news (&optional arg
)
7136 "Cancel an article you posted.
7137 If ARG, allow editing of the cancellation message."
7139 (unless (message-news-p)
7140 (error "This is not a news article; canceling is impossible"))
7141 (let (from newsgroups message-id distribution buf
)
7143 ;; Get header info from original article.
7145 (message-narrow-to-head-1)
7146 (setq from
(message-fetch-field "from")
7147 newsgroups
(message-fetch-field "newsgroups")
7148 message-id
(message-fetch-field "message-id" t
)
7149 distribution
(message-fetch-field "distribution")))
7150 ;; Make sure that this article was written by the user.
7151 (unless (message-is-yours-p)
7152 (error "This article is not yours"))
7153 (when (yes-or-no-p "Do you really want to cancel this article? ")
7154 ;; Make control message.
7157 (setq buf
(set-buffer (get-buffer-create " *message cancel*"))))
7159 (insert "Newsgroups: " newsgroups
"\n"
7161 "Subject: cancel " message-id
"\n"
7162 "Control: cancel " message-id
"\n"
7164 (concat "Distribution: " distribution
"\n")
7166 mail-header-separator
"\n"
7167 message-cancel-message
)
7168 (run-hooks 'message-cancel-hook
)
7170 (message "Canceling your article...")
7171 (if (let ((message-syntax-checks
7172 'dont-check-for-anything-just-trust-me
))
7173 (funcall message-send-news-function
))
7174 (message "Canceling your article...done"))
7175 (kill-buffer buf
))))))
7178 (defun message-supersede ()
7179 "Start composing a message to supersede the current message.
7180 This is done simply by taking the old article and adding a Supersedes
7181 header line with the old Message-ID."
7183 (let ((cur (current-buffer)))
7184 ;; Check whether the user owns the article that is to be superseded.
7185 (unless (message-is-yours-p)
7186 (error "This article is not yours"))
7187 ;; Get a normal message buffer.
7188 (message-pop-to-buffer (message-buffer-name "supersede"))
7189 (insert-buffer-substring cur
)
7191 (message-narrow-to-head-1)
7192 ;; Remove unwanted headers.
7193 (when message-ignored-supersedes-headers
7194 (message-remove-header message-ignored-supersedes-headers t
))
7195 (goto-char (point-min))
7196 (if (not (re-search-forward "^Message-ID: " nil t
))
7197 (error "No Message-ID in this article")
7198 (replace-match "Supersedes: " t t
))
7199 (goto-char (point-max))
7200 (insert mail-header-separator
)
7205 (defun message-recover ()
7206 "Reread contents of current buffer from its last auto-save file."
7208 (let ((file-name (make-auto-save-file-name)))
7209 (cond ((save-window-excursion
7210 (with-output-to-temp-buffer "*Directory*"
7211 (with-current-buffer standard-output
7213 (buffer-disable-undo standard-output
)
7214 (let ((default-directory "/"))
7216 "ls" nil standard-output nil
"-l" file-name
)))
7217 (yes-or-no-p (format "Recover auto save file %s? " file-name
)))
7218 (let ((buffer-read-only nil
))
7220 (insert-file-contents file-name nil
)))
7221 (t (error "message-recover canceled")))))
7223 ;;; Washing Subject:
7225 (defun message-wash-subject (subject)
7226 "Remove junk like \"Re:\", \"(fwd)\", etc. added to subject string SUBJECT.
7227 Previous forwarders, repliers, etc. may add it."
7230 (goto-char (point-min))
7231 ;; strip Re/Fwd stuff off the beginning
7232 (while (re-search-forward
7233 "\\([Rr][Ee]:\\|[Ff][Ww][Dd]\\(\\[[0-9]*\\]\\)?:\\|[Ff][Ww]:\\)" nil t
)
7236 ;; and gnus-style forwards [foo@bar.com] subject
7237 (goto-char (point-min))
7238 (while (re-search-forward "\\[[^ \t]*\\(@\\|\\.\\)[^ \t]*\\]" nil t
)
7242 (goto-char (point-max))
7243 (while (re-search-backward "([Ff][Ww][Dd])" nil t
)
7246 ;; and finally, any whitespace that was left-over
7247 (goto-char (point-min))
7248 (while (re-search-forward "^[ \t]+" nil t
)
7250 (goto-char (point-max))
7251 (while (re-search-backward "[ \t]+$" nil t
)
7256 ;;; Forwarding messages.
7258 (defvar message-forward-decoded-p nil
7259 "Non-nil means the original message is decoded.")
7261 (defun message-forward-subject-name-subject (subject)
7262 "Generate a SUBJECT for a forwarded message.
7263 The form is: [Source] Subject, where if the original message was mail,
7264 Source is the name of the sender, and if the original message was
7265 news, Source is the list of newsgroups is was posted to."
7266 (let* ((group (message-fetch-field "newsgroups"))
7267 (from (message-fetch-field "from"))
7270 (gnus-group-decoded-name group
)
7272 (car (gnus-extract-address-components from
))
7273 (cadr (gnus-extract-address-components from
))))
7276 (if message-forward-decoded-p
7278 (mail-decode-encoded-word-string prefix
))
7281 (defun message-forward-subject-author-subject (subject)
7282 "Generate a SUBJECT for a forwarded message.
7283 The form is: [Source] Subject, where if the original message was mail,
7284 Source is the sender, and if the original message was news, Source is
7285 the list of newsgroups is was posted to."
7286 (let* ((group (message-fetch-field "newsgroups"))
7289 (gnus-group-decoded-name group
)
7290 (or (message-fetch-field "from")
7293 (if message-forward-decoded-p
7295 (mail-decode-encoded-word-string prefix
))
7298 (defun message-forward-subject-fwd (subject)
7299 "Generate a SUBJECT for a forwarded message.
7300 The form is: Fwd: Subject, where Subject is the original subject of
7302 (if (string-match "^Fwd: " subject
)
7304 (concat "Fwd: " subject
)))
7306 (defun message-make-forward-subject ()
7307 "Return a Subject header suitable for the message in the current buffer."
7310 (message-narrow-to-head-1)
7311 (let ((funcs message-make-forward-subject-function
)
7312 (subject (message-fetch-field "Subject")))
7315 (if message-forward-decoded-p
7317 (mail-decode-encoded-word-string subject
))
7319 (when message-wash-forwarded-subjects
7320 (setq subject
(message-wash-subject subject
)))
7321 ;; Make sure funcs is a list.
7324 (setq funcs
(list funcs
)))
7325 ;; Apply funcs in order, passing subject generated by previous
7326 ;; func to the next one.
7327 (dolist (func funcs
)
7328 (when (functionp func
)
7329 (setq subject
(funcall func subject
))))
7332 (defvar gnus-article-decoded-p
)
7336 (defun message-forward (&optional news digest
)
7337 "Forward the current message via mail.
7338 Optional NEWS will use news to forward instead of mail.
7339 Optional DIGEST will use digest to forward."
7341 (let* ((cur (current-buffer))
7342 (message-forward-decoded-p
7343 (if (local-variable-p 'gnus-article-decoded-p
(current-buffer))
7344 gnus-article-decoded-p
;; In an article buffer.
7345 message-forward-decoded-p
))
7346 (subject (message-make-forward-subject)))
7348 (message-news nil subject
)
7349 (message-mail nil subject
))
7350 (message-forward-make-body cur digest
)))
7352 (defun message-forward-make-body-plain (forward-buffer)
7354 "\n-------------------- Start of forwarded message --------------------\n")
7356 (contents (with-current-buffer forward-buffer
(buffer-string)))
7358 (unless (multibyte-string-p contents
)
7359 (error "Attempt to insert unibyte string from the buffer \"%s\"\
7360 to the multibyte buffer \"%s\""
7361 (if (bufferp forward-buffer
)
7362 (buffer-name forward-buffer
)
7365 (insert (mm-with-multibyte-buffer
7368 (goto-char (point-min))
7369 (when (looking-at "From ")
7370 (replace-match "X-From-Line: "))
7372 (unless (bolp) (insert "\n"))
7375 "-------------------- End of forwarded message --------------------\n")
7376 (message-remove-ignored-headers b e
)))
7378 (defun message-remove-ignored-headers (b e
)
7379 (when (or message-forward-ignored-headers
7380 message-forward-included-headers
)
7382 (narrow-to-region b e
)
7384 (narrow-to-region (point)
7385 (or (search-forward "\n\n" nil t
) (point)))
7386 (when message-forward-ignored-headers
7387 (let ((ignored (if (stringp message-forward-ignored-headers
)
7388 (list message-forward-ignored-headers
)
7389 message-forward-ignored-headers
)))
7390 (dolist (elem ignored
)
7391 (message-remove-header elem t
))))
7392 (when message-forward-included-headers
7393 (message-remove-header
7394 (if (listp message-forward-included-headers
)
7395 (regexp-opt message-forward-included-headers
)
7396 message-forward-included-headers
)
7399 (defun message-forward-make-body-mime (forward-buffer &optional beg end
)
7401 (insert "\n\n<#part type=message/rfc822 disposition=inline raw=t>\n")
7403 (narrow-to-region (point) (point))
7404 (insert-buffer-substring forward-buffer beg end
)
7405 (mml-quote-region (point-min) (point-max))
7406 (goto-char (point-min))
7407 (when (looking-at "From ")
7408 (replace-match "X-From-Line: "))
7409 (goto-char (point-max)))
7410 (insert "<#/part>\n")
7411 ;; Consider there is no illegible text.
7412 (add-text-properties
7414 `(no-illegible-text t rear-nonsticky t start-open t
))))
7416 (defun message-forward-make-body-mml (forward-buffer)
7417 (insert "\n\n<#mml type=message/rfc822 disposition=inline>\n")
7418 (let ((b (point)) e
)
7419 (if (not message-forward-decoded-p
)
7420 (let ((contents (with-current-buffer forward-buffer
(buffer-string))))
7421 (unless (multibyte-string-p contents
)
7422 (error "Attempt to insert unibyte string from the buffer \"%s\"\
7423 to the multibyte buffer \"%s\""
7424 (if (bufferp forward-buffer
)
7425 (buffer-name forward-buffer
)
7428 (insert (mm-with-multibyte-buffer
7431 (goto-char (point-min))
7432 (when (looking-at "From ")
7433 (replace-match "X-From-Line: "))
7436 (narrow-to-region (point) (point))
7437 (mml-insert-buffer forward-buffer
)
7438 (goto-char (point-min))
7439 (when (looking-at "From ")
7440 (replace-match "X-From-Line: "))
7441 (goto-char (point-max))))
7443 (insert "<#/mml>\n")
7444 (when (not message-forward-decoded-p
)
7445 (message-remove-ignored-headers b e
))))
7447 (defun message-forward-make-body-digest-plain (forward-buffer)
7449 "\n-------------------- Start of forwarded message --------------------\n")
7450 (mml-insert-buffer forward-buffer
)
7452 "\n-------------------- End of forwarded message --------------------\n"))
7454 (defun message-forward-make-body-digest-mime (forward-buffer)
7455 (insert "\n<#multipart type=digest>\n")
7456 (let ((b (point)) e
)
7457 (insert-buffer-substring forward-buffer
)
7459 (insert "<#/multipart>\n")
7461 (narrow-to-region b e
)
7463 (narrow-to-region (point)
7464 (or (search-forward "\n\n" nil t
) (point)))
7465 (delete-region (point-min) (point-max)))))
7467 (defun message-forward-make-body-digest (forward-buffer)
7468 (if message-forward-as-mime
7469 (message-forward-make-body-digest-mime forward-buffer
)
7470 (message-forward-make-body-digest-plain forward-buffer
)))
7472 (autoload 'mm-uu-dissect-text-parts
"mm-uu")
7473 (autoload 'mm-uu-dissect
"mm-uu")
7475 (defun message-signed-or-encrypted-p (&optional dont-emulate-mime handles
)
7476 "Say whether the current buffer contains signed or encrypted message.
7477 If DONT-EMULATE-MIME is nil, this function does the MIME emulation on
7478 messages that don't conform to PGP/MIME described in RFC2015. HANDLES
7479 is for the internal use."
7481 (let ((mm-decrypt-option 'never
)
7482 (mm-verify-option 'never
))
7483 (if (setq handles
(mm-dissect-buffer nil t
))
7484 (unless dont-emulate-mime
7485 (mm-uu-dissect-text-parts handles
))
7486 (unless dont-emulate-mime
7487 (setq handles
(mm-uu-dissect))))))
7488 ;; Check text/plain message in which there is a signed or encrypted
7489 ;; body that has been encoded by B or Q.
7490 (unless (or handles dont-emulate-mime
)
7491 (let ((cur (current-buffer))
7492 (mm-decrypt-option 'never
)
7493 (mm-verify-option 'never
))
7495 (insert-buffer-substring cur
)
7496 (when (setq handles
(mm-dissect-buffer t t
))
7497 (if (and (bufferp (car handles
))
7498 (equal (mm-handle-media-type handles
) "text/plain"))
7501 (insert-buffer-substring (car handles
))
7502 (mm-decode-content-transfer-encoding
7503 (mm-handle-encoding handles
))
7504 (mm-destroy-parts handles
)
7505 (setq handles
(mm-uu-dissect)))
7506 (mm-destroy-parts handles
)
7507 (setq handles nil
))))))
7511 (dolist (handle (if (stringp (car handles
))
7512 (if (member (car handles
)
7513 '("multipart/signed"
7514 "multipart/encrypted"))
7518 (if (stringp (car handle
))
7519 (when (message-signed-or-encrypted-p dont-emulate-mime handle
)
7521 (when (and (bufferp (car handle
))
7522 (equal (mm-handle-media-type handle
)
7524 (with-current-buffer (mm-handle-buffer handle
)
7525 (when (message-signed-or-encrypted-p dont-emulate-mime
)
7526 (throw 'found t
)))))))
7527 (mm-destroy-parts handles
))))
7530 (defun message-forward-make-body (forward-buffer &optional digest
)
7531 ;; Put point where we want it before inserting the forwarded
7533 (if message-forward-before-signature
7535 (goto-char (point-max)))
7537 (message-forward-make-body-digest forward-buffer
)
7538 (if message-forward-as-mime
7539 (if (and message-forward-show-mml
7540 (not (and (eq message-forward-show-mml
'best
)
7541 ;; Use the raw form in the body if it contains
7542 ;; signed or encrypted message so as not to be
7543 ;; destroyed by re-encoding.
7544 (with-current-buffer forward-buffer
7546 (message-signed-or-encrypted-p)
7548 (message-forward-make-body-mml forward-buffer
)
7549 (message-forward-make-body-mime forward-buffer
))
7550 (message-forward-make-body-plain forward-buffer
)))
7551 (message-position-point))
7553 (declare-function rmail-toggle-header
"rmail" (&optional arg
))
7556 (defun message-forward-rmail-make-body (forward-buffer)
7557 (save-window-excursion
7558 (set-buffer forward-buffer
)
7559 (when (rmail-msg-is-pruned)
7560 (rmail-toggle-header 0)))
7561 (message-forward-make-body forward-buffer
))
7563 ;; Fixme: Should have defcustom.
7565 (defun message-insinuate-rmail ()
7566 "Let RMAIL use message to forward."
7568 (setq rmail-enable-mime-composing t
)
7569 (setq rmail-insert-mime-forwarded-message-function
7570 'message-forward-rmail-make-body
))
7572 (defvar message-inhibit-body-encoding nil
)
7575 (defun message-resend (address)
7576 "Resend the current article to ADDRESS."
7578 (list (message-read-from-minibuffer "Resend message to: ")))
7579 (message "Resending message to %s..." address
)
7581 (let ((cur (current-buffer))
7583 ;; We first set up a normal mail buffer.
7584 (unless (message-mail-user-agent)
7585 (set-buffer (get-buffer-create " *message resend*"))
7586 (let ((inhibit-read-only t
))
7588 (let ((message-this-is-mail t
)
7589 message-generate-hashcash
7591 (message-setup `((To .
,address
))))
7592 ;; Insert our usual headers.
7593 (message-generate-headers '(From Date To Message-ID
))
7594 (message-narrow-to-headers)
7595 (when (setq gcc
(mail-fetch-field "gcc" nil t
))
7596 (message-remove-header "gcc"))
7597 ;; Remove X-Draft-From header etc.
7598 (message-remove-header message-ignored-mail-headers t
)
7599 ;; Rename them all to "Resent-*".
7600 (goto-char (point-min))
7601 (while (re-search-forward "^[A-Za-z]" nil t
)
7606 (let ((inhibit-read-only t
))
7607 (delete-region (point) (point-max)))
7609 ;; Insert the message to be resent.
7610 (insert-buffer-substring cur
)
7611 (goto-char (point-min))
7612 (search-forward "\n\n")
7615 (narrow-to-region beg
(point))
7616 (message-remove-header message-ignored-resent-headers t
)
7617 (goto-char (point-max)))
7618 (insert mail-header-separator
)
7619 ;; Rename all old ("Also-")Resent headers.
7620 (while (re-search-backward "^\\(Also-\\)*Resent-" beg t
)
7623 ;; Quote any "From " lines at the beginning.
7625 (when (looking-at "From ")
7626 (replace-match "X-From-Line: "))
7628 (let ((message-inhibit-body-encoding
7629 ;; Don't do any further encoding if it looks like the
7630 ;; message has already been encoded.
7631 (let ((case-fold-search t
))
7632 (re-search-forward "^mime-version:" nil t
)))
7633 (message-inhibit-ecomplete t
)
7634 ;; We don't want smtpmail.el to encode anything, either.
7635 (sendmail-coding-system 'raw-text
)
7636 (select-safe-coding-system-function nil
)
7637 message-required-mail-headers
7638 message-generate-hashcash
7639 rfc2047-encode-encoded-words
)
7640 (message-send-mail))
7643 (insert "Gcc: " gcc
"\n"))
7644 (run-hooks 'message-sent-hook
)
7645 (kill-buffer (current-buffer)))
7646 (message "Resending message to %s...done" address
)))
7649 (defun message-bounce ()
7650 "Re-mail the current message.
7651 This only makes sense if the current message is a bounce message that
7652 contains some mail you have written which has been bounced back to
7655 (let ((handles (mm-dissect-buffer t
))
7657 (message-pop-to-buffer (message-buffer-name "bounce"))
7658 (if (stringp (car handles
))
7659 ;; This is a MIME bounce.
7660 (mm-insert-part (car (last handles
)))
7661 ;; This is a non-MIME bounce, so we try to remove things
7663 (mm-insert-part handles
)
7665 (goto-char (point-min))
7666 (re-search-forward "\n\n+" nil t
)
7667 (setq boundary
(point))
7668 ;; We remove everything before the bounced mail.
7669 (if (or (re-search-forward message-unsent-separator nil t
)
7671 (search-forward "\n\n" nil
'move
)
7672 (re-search-backward "^Return-Path:.*\n" boundary t
)))
7675 (delete-region (point-min)
7676 (if (re-search-forward "^[^ \n\t]+:" nil t
)
7679 (goto-char boundary
)
7680 (when (re-search-backward "^.?From .*\n" nil t
)
7681 (delete-region (match-beginning 0) (match-end 0)))))
7684 (message-narrow-to-head-1)
7685 (message-remove-header message-ignored-bounced-headers t
)
7686 (goto-char (point-max))
7687 (insert mail-header-separator
))
7688 (message-position-point)))
7691 ;;; Interactive entry points for new message buffers.
7695 (defun message-mail-other-window (&optional to subject
)
7696 "Like `message-mail' command, but display mail buffer in another window."
7698 (unless (message-mail-user-agent)
7699 (message-pop-to-buffer (message-buffer-name "mail" to
)
7700 'switch-to-buffer-other-window
))
7701 (let ((message-this-is-mail t
))
7702 (message-setup `((To .
,(or to
"")) (Subject .
,(or subject
"")))
7703 nil nil nil
'switch-to-buffer-other-window
)))
7706 (defun message-mail-other-frame (&optional to subject
)
7707 "Like `message-mail' command, but display mail buffer in another frame."
7709 (unless (message-mail-user-agent)
7710 (message-pop-to-buffer (message-buffer-name "mail" to
)
7711 'switch-to-buffer-other-frame
))
7712 (let ((message-this-is-mail t
))
7713 (message-setup `((To .
,(or to
"")) (Subject .
,(or subject
"")))
7714 nil nil nil
'switch-to-buffer-other-frame
)))
7717 (defun message-news-other-window (&optional newsgroups subject
)
7718 "Start editing a news article to be sent."
7720 (message-pop-to-buffer (message-buffer-name "posting" nil newsgroups
)
7721 'switch-to-buffer-other-window
)
7722 (let ((message-this-is-news t
))
7723 (message-setup `((Newsgroups .
,(or newsgroups
""))
7724 (Subject .
,(or subject
""))))))
7727 (defun message-news-other-frame (&optional newsgroups subject
)
7728 "Start editing a news article to be sent."
7730 (message-pop-to-buffer (message-buffer-name "posting" nil newsgroups
)
7731 'switch-to-buffer-other-frame
)
7732 (let ((message-this-is-news t
))
7733 (message-setup `((Newsgroups .
,(or newsgroups
""))
7734 (Subject .
,(or subject
""))))))
7738 ;; This code should be moved to underline.el (from which it is stolen).
7741 (defun message-bold-region (start end
)
7742 "Bold all nonblank characters in the region.
7743 Works by overstriking characters.
7744 Called from program, takes two arguments START and END
7745 which specify the range to operate on."
7748 (let ((end1 (make-marker)))
7749 (move-marker end1
(max start end
))
7750 (goto-char (min start end
))
7751 (while (< (point) end1
)
7752 (or (looking-at "[_\^@- ]")
7753 (insert (char-after) "\b"))
7754 (forward-char 1)))))
7757 (defun message-unbold-region (start end
)
7758 "Remove all boldness (overstruck characters) in the region.
7759 Called from program, takes two arguments START and END
7760 which specify the range to operate on."
7763 (let ((end1 (make-marker)))
7764 (move-marker end1
(max start end
))
7765 (goto-char (min start end
))
7766 (while (search-forward "\b" end1 t
)
7767 (if (eq (char-after) (char-after (- (point) 2)))
7768 (delete-char -
2))))))
7770 (defun message-exchange-point-and-mark ()
7771 "Exchange point and mark, but don't activate region if it was inactive."
7772 (goto-char (prog1 (mark t
)
7773 (set-marker (mark-marker) (point)))))
7775 ;; Support for toolbar
7776 (defvar tool-bar-mode
)
7778 ;; Note: The :set function in the `message-tool-bar*' variables will only
7779 ;; affect _new_ message buffers. We might add a function that walks thru all
7780 ;; message-mode buffers and force the update.
7781 (defun message-tool-bar-update (&optional symbol value
)
7782 "Update message mode toolbar.
7783 Setter function for custom variables."
7784 (setq-default message-tool-bar-map nil
)
7786 ;; When used as ":set" function:
7787 (set-default symbol value
)))
7789 (defcustom message-tool-bar
(if (eq gmm-tool-bar-style
'gnome
)
7790 'message-tool-bar-gnome
7791 'message-tool-bar-retro
)
7792 "Specifies the message mode tool bar.
7794 It can be either a list or a symbol referring to a list. See
7795 `gmm-tool-bar-from-list' for the format of the list. The
7796 default key map is `message-mode-map'.
7798 Pre-defined symbols include `message-tool-bar-gnome' and
7799 `message-tool-bar-retro'."
7800 :type
'(repeat gmm-tool-bar-list-item
)
7801 :type
'(choice (const :tag
"GNOME style" message-tool-bar-gnome
)
7802 (const :tag
"Retro look" message-tool-bar-retro
)
7803 (repeat :tag
"User defined list" gmm-tool-bar-item
)
7805 :version
"23.1" ;; No Gnus
7806 :initialize
'custom-initialize-default
7807 :set
'message-tool-bar-update
7810 (defcustom message-tool-bar-gnome
7811 '((ispell-message "spell" nil
7813 :visible
(not flyspell-mode
))
7814 (flyspell-buffer "spell" t
7816 :visible flyspell-mode
7817 :help
"Flyspell whole buffer")
7818 (message-send-and-exit "mail/send" t
:label
"Send")
7819 (message-dont-send "mail/save-draft")
7820 (mml-attach-file "attach" mml-mode-map
:vert-only t
)
7821 (mml-preview "mail/preview" mml-mode-map
)
7822 (mml-secure-message-sign-encrypt "lock" mml-mode-map
:visible nil
)
7823 (message-insert-importance-high "important" nil
:visible nil
)
7824 (message-insert-importance-low "unimportant" nil
:visible nil
)
7825 (message-insert-disposition-notification-to "receipt" nil
:visible nil
))
7826 "List of items for the message tool bar (GNOME style).
7828 See `gmm-tool-bar-from-list' for details on the format of the list."
7829 :type
'(repeat gmm-tool-bar-item
)
7830 :version
"23.1" ;; No Gnus
7831 :initialize
'custom-initialize-default
7832 :set
'message-tool-bar-update
7835 (defcustom message-tool-bar-retro
7836 '(;; Old Emacs 21 icon for consistency.
7837 (message-send-and-exit "gnus/mail-send")
7838 (message-kill-buffer "close")
7839 (message-dont-send "cancel")
7840 (mml-attach-file "attach" mml-mode-map
)
7841 (ispell-message "spell")
7842 (mml-preview "preview" mml-mode-map
)
7843 (message-insert-importance-high "gnus/important")
7844 (message-insert-importance-low "gnus/unimportant")
7845 (message-insert-disposition-notification-to "gnus/receipt"))
7846 "List of items for the message tool bar (retro style).
7848 See `gmm-tool-bar-from-list' for details on the format of the list."
7849 :type
'(repeat gmm-tool-bar-item
)
7850 :version
"23.1" ;; No Gnus
7851 :initialize
'custom-initialize-default
7852 :set
'message-tool-bar-update
7855 (defcustom message-tool-bar-zap-list
7856 '(new-file open-file dired kill-buffer write-file
7857 print-buffer customize help
)
7858 "List of icon items from the global tool bar.
7859 These items are not displayed on the message mode tool bar.
7861 See `gmm-tool-bar-from-list' for the format of the list."
7862 :type
'gmm-tool-bar-zap-list
7863 :version
"23.1" ;; No Gnus
7864 :initialize
'custom-initialize-default
7865 :set
'message-tool-bar-update
7868 (defvar image-load-path
)
7870 (defun message-make-tool-bar (&optional force
)
7871 "Make a message mode tool bar from `message-tool-bar-list'.
7872 When FORCE, rebuild the tool bar."
7873 (when (and (boundp 'tool-bar-mode
)
7875 (or (not message-tool-bar-map
) force
))
7876 (setq message-tool-bar-map
7878 (image-load-path-for-library
7879 "message" "mail/save-draft.xpm" nil t
))
7880 (image-load-path (cons (car load-path
) image-load-path
)))
7881 (gmm-tool-bar-from-list message-tool-bar
7882 message-tool-bar-zap-list
7883 'message-mode-map
))))
7884 message-tool-bar-map
)
7886 ;;; Group name completion.
7888 (defcustom message-newgroups-header-regexp
7889 "^\\(Newsgroups\\|Followup-To\\|Posted-To\\|Gcc\\):"
7890 "Regexp that match headers that lists groups."
7894 (defcustom message-completion-alist
7895 (list (cons message-newgroups-header-regexp
'message-expand-group
)
7896 '("^\\(Resent-\\)?\\(To\\|B?Cc\\):" . message-expand-name
)
7897 '("^\\(Reply-To\\|From\\|Mail-Followup-To\\|Mail-Copies-To\\):"
7898 . message-expand-name
)
7899 '("^\\(Disposition-Notification-To\\|Return-Receipt-To\\):"
7900 . message-expand-name
))
7901 "Alist of (RE . FUN). Use FUN for completion on header lines matching RE."
7904 :type
'(alist :key-type regexp
:value-type function
))
7906 (defcustom message-expand-name-databases
7908 "List of databases to try for name completion (`message-expand-name').
7909 Each element is a symbol and can be `bbdb' or `eudc'."
7911 :type
'(set (const bbdb
) (const eudc
)))
7913 (defcustom message-tab-body-function nil
7914 "Function to execute when `message-tab' (TAB) is executed in the body.
7915 If nil, the function bound in `text-mode-map' or `global-map' is executed."
7918 :link
'(custom-manual "(message)Various Commands")
7919 :type
'(choice (const nil
)
7922 (declare-function mail-abbrev-in-expansion-header-p
"mailabbrev" ())
7924 (defun message-tab ()
7925 "Complete names according to `message-completion-alist'.
7926 Execute function specified by `message-tab-body-function' when
7927 not in those headers. If that variable is nil, indent with the
7928 regular text mode tabbing command."
7931 ((let ((completion-fail-discreetly t
))
7932 (completion-at-point))
7933 ;; Completion was performed; nothing else to do.
7935 (message-tab-body-function (funcall message-tab-body-function
))
7936 (t (funcall (or (lookup-key text-mode-map
"\t")
7937 (lookup-key global-map
"\t")
7938 'indent-relative
)))))
7940 (defvar mail-abbrev-mode-regexp
)
7942 (defun message-completion-function ()
7943 (let ((alist message-completion-alist
))
7945 (let ((mail-abbrev-mode-regexp (caar alist
)))
7946 (not (mail-abbrev-in-expansion-header-p))))
7947 (setq alist
(cdr alist
)))
7949 (let ((fun (cdar alist
)))
7950 ;; Even if completion fails, return a non-nil value, so as to avoid
7951 ;; falling back to message-tab-body-function.
7952 (lambda () (funcall fun
) 'completion-attempted
)))))
7954 (defun message-expand-group ()
7955 "Expand the group name under point."
7956 (let ((b (save-excursion
7961 (skip-chars-forward "^:")
7964 (skip-chars-backward "^, \t\n") (point))))
7965 (completion-ignore-case t
)
7966 (e (progn (skip-chars-forward "^,\t\n ") (point)))
7968 (when (and (boundp 'gnus-active-hashtb
)
7972 (setq group
(symbol-name symbol
))
7973 (push (if (string-match "[^\000-\177]" group
)
7974 (gnus-group-decoded-name group
)
7977 gnus-active-hashtb
))
7978 (completion-in-region b e collection
)))
7980 (defun message-expand-name ()
7981 (cond ((and (memq 'eudc message-expand-name-databases
)
7982 (boundp 'eudc-protocol
)
7984 (eudc-expand-inline))
7985 ((and (memq 'bbdb message-expand-name-databases
)
7986 (fboundp 'bbdb-complete-name
))
7987 (let ((starttick (buffer-modified-tick)))
7988 (or (bbdb-complete-name)
7989 ;; Apparently, bbdb-complete-name can return nil even when
7990 ;; completion took place. So let's double check the buffer was
7992 (/= starttick
(buffer-modified-tick)))))
7998 (defun message-talkative-question (ask question show
&rest text
)
7999 "Call FUNCTION with argument QUESTION; optionally display TEXT... args.
8000 If SHOW is non-nil, the arguments TEXT... are displayed in a temp buffer.
8001 The following arguments may contain lists of values."
8003 (setq text
(message-flatten-list text
)))
8004 (save-window-excursion
8005 (with-output-to-temp-buffer " *MESSAGE information message*"
8006 (with-current-buffer " *MESSAGE information message*"
8009 (goto-char (point-min))))
8010 (funcall ask question
))
8011 (funcall ask question
)))
8013 (defun message-flatten-list (list)
8014 "Return a new, flat list that contains all elements of LIST.
8016 \(message-flatten-list \\='(1 (2 3 (4 5 (6))) 7))
8019 (apply 'append
(mapcar 'message-flatten-list list
)))
8023 (defun message-generate-new-buffer-clone-locals (name &optional varstr
)
8024 "Create and return a buffer with name based on NAME using `generate-new-buffer'.
8025 Then clone the local variables and values from the old buffer to the
8026 new one, cloning only the locals having a substring matching the
8028 (let ((oldbuf (current-buffer)))
8029 (with-current-buffer (generate-new-buffer name
)
8030 (message-clone-locals oldbuf varstr
)
8033 (defun message-clone-locals (buffer &optional varstr
)
8034 "Clone the local variables from BUFFER to the current buffer."
8035 (let ((locals (with-current-buffer buffer
(buffer-local-variables)))
8036 (regexp "^gnus\\|^nn\\|^message\\|^sendmail\\|^smtp\\|^user-mail-address"))
8039 (when (and (consp local
)
8041 (string-match regexp
(symbol-name (car local
)))
8043 (string-match varstr
(symbol-name (car local
)))))
8045 (set (make-local-variable (car local
))
8053 (defun message-encode-message-body ()
8054 (unless message-inhibit-body-encoding
8055 (let ((mail-parse-charset (or mail-parse-charset
8056 message-default-charset
))
8057 (case-fold-search t
)
8058 lines content-type-p
)
8061 (narrow-to-region (point) (point-max))
8062 (let ((new (mml-generate-mime)))
8064 (delete-region (point-min) (point-max))
8066 (goto-char (point-min))
8067 (if (eq (aref new
0) ?
\n)
8069 (search-forward "\n\n")
8070 (setq lines
(buffer-substring (point-min) (1- (point))))
8071 (delete-region (point-min) (point))))))
8073 (message-narrow-to-headers-or-head)
8074 (message-remove-header "Mime-Version")
8075 (goto-char (point-max))
8076 (insert "MIME-Version: 1.0\n")
8079 (setq content-type-p
8081 (re-search-backward "^Content-Type:" nil t
))))
8083 (message-narrow-to-headers-or-head)
8084 (message-remove-first-header "Content-Type")
8085 (message-remove-first-header "Content-Transfer-Encoding"))
8086 ;; We always make sure that the message has a Content-Type
8087 ;; header. This is because some broken MTAs and MUAs get
8088 ;; awfully confused when confronted with a message with a
8089 ;; MIME-Version header and without a Content-Type header. For
8090 ;; instance, Solaris' /usr/bin/mail.
8091 (unless content-type-p
8092 (goto-char (point-min))
8093 ;; For unknown reason, MIME-Version doesn't exist.
8094 (when (re-search-forward "^MIME-Version:" nil t
)
8096 (insert "Content-Type: text/plain; charset=us-ascii\n"))))))
8098 (defun message-read-from-minibuffer (prompt &optional initial-contents
)
8099 "Read from the minibuffer while providing abbrev expansion."
8100 (let ((minibuffer-setup-hook 'mail-abbrevs-setup
)
8101 (minibuffer-local-map message-minibuffer-local-map
))
8102 (read-from-minibuffer prompt initial-contents
)))
8104 (defun message-use-alternative-email-as-from ()
8105 "Set From field of the outgoing message to the first matching
8106 address in `message-alternative-emails', looking at To, Cc and
8107 From headers in the original article."
8108 (require 'mail-utils
)
8109 (let* ((fields '("To" "Cc" "From"))
8111 (message-tokenize-header
8112 (mail-strip-quoted-names
8113 (mapconcat 'message-fetch-reply-field fields
","))))
8114 (email (cond ((functionp message-alternative-emails
)
8115 (car (cl-remove-if-not message-alternative-emails emails
)))
8116 (t (loop for email in emails
8117 if
(string-match-p message-alternative-emails email
)
8119 (unless (or (not email
) (equal email user-mail-address
))
8120 (message-remove-header "From")
8121 (goto-char (point-max))
8122 (insert "From: " (let ((user-mail-address email
)) (message-make-from))
8125 (defun message-options-get (symbol)
8126 (cdr (assq symbol message-options
)))
8128 (defun message-options-set (symbol value
)
8129 (let ((the-cons (assq symbol message-options
)))
8132 (setcdr the-cons value
)
8133 (setq message-options
(delq the-cons message-options
)))
8135 (push (cons symbol value
) message-options
))))
8138 (defun message-options-set-recipient ()
8140 (message-narrow-to-headers-or-head)
8141 (message-options-set 'message-sender
8142 (mail-strip-quoted-names
8143 (message-fetch-field "from")))
8144 (message-options-set 'message-recipients
8145 (mail-strip-quoted-names
8146 (let ((to (message-fetch-field "to"))
8147 (cc (message-fetch-field "cc"))
8148 (bcc (message-fetch-field "bcc")))
8151 (if (and to cc
) ", ")
8153 (if (and (or to cc
) bcc
) ", ")
8156 (defun message-hide-headers ()
8157 "Hide headers based on the `message-hidden-headers' variable."
8158 (let ((regexps (if (stringp message-hidden-headers
)
8159 (list message-hidden-headers
)
8160 message-hidden-headers
))
8161 (inhibit-point-motion-hooks t
)
8162 (inhibit-modification-hooks t
)
8163 (end-of-headers (point-min)))
8167 (message-narrow-to-headers)
8168 (goto-char (point-min))
8170 (if (not (message-hide-header-p regexps
))
8171 (message-next-header)
8172 (let ((begin (point))
8174 (message-next-header)
8175 (setq header
(buffer-substring begin
(point))
8176 header-len
(- (point) begin
))
8177 (delete-region begin
(point))
8178 (goto-char end-of-headers
)
8180 (setq end-of-headers
8181 (+ end-of-headers header-len
))))))))
8182 (narrow-to-region end-of-headers
(point-max))))
8184 (defun message-hide-header-p (regexps)
8187 (when (eq (car regexps
) 'not
)
8190 (dolist (regexp regexps
)
8191 (setq result
(or result
(looking-at regexp
))))
8196 (declare-function ecomplete-add-item
"ecomplete" (type key text
))
8197 (declare-function ecomplete-save
"ecomplete" ())
8199 (defun message-put-addresses-in-ecomplete ()
8200 (require 'ecomplete
)
8201 (dolist (header '("to" "cc" "from" "reply-to"))
8202 (let ((value (message-field-value header
)))
8203 (dolist (string (mail-header-parse-addresses value
'raw
))
8205 (replace-regexp-in-string
8207 (replace-regexp-in-string "^ +\\| +$" "" string
)))
8208 (ecomplete-add-item 'mail
(car (mail-header-parse-address string
))
8212 (autoload 'ecomplete-display-matches
"ecomplete")
8214 (defun message-display-abbrev (&optional choose
)
8215 "Display the next possible abbrev for the text before point."
8216 (interactive (list t
))
8217 (when (and (memq (char-after (point-at-bol)) '(?C ?T ?
\t ?
))
8218 (message-point-in-header-p)
8221 (while (and (memq (char-after) '(?
\t ?
))
8222 (zerop (forward-line -
1))))
8223 (looking-at "To:\\|Cc:")))
8224 (let* ((end (point))
8225 (start (save-excursion
8226 (and (re-search-backward "[\n\t ]" nil t
)
8228 (word (when start
(buffer-substring start end
)))
8229 (match (when (and word
8230 (not (zerop (length word
))))
8231 (ecomplete-display-matches 'mail word choose
))))
8232 (when (and choose match
)
8233 (delete-region start end
)
8236 ;; To send pre-formatted letters like the example below, you can use
8237 ;; `message-send-form-letter':
8238 ;; --8<---------------cut here---------------start------------->8---
8239 ;; To: alice@invalid.invalid
8240 ;; Subject: Verification of your contact information
8241 ;; From: Contact verification <admin@foo.invalid>
8242 ;; --text follows this line--
8244 ;; please verify that your contact information is still valid:
8245 ;; Alice A, A avenue 11, 1111 A town, Austria
8246 ;; ----------next form letter message follows this line----------
8247 ;; To: bob@invalid.invalid
8248 ;; Subject: Verification of your contact information
8249 ;; From: Contact verification <admin@foo.invalid>
8250 ;; --text follows this line--
8252 ;; please verify that your contact information is still valid:
8253 ;; Bob, B street 22, 22222 Be town, Belgium
8254 ;; ----------next form letter message follows this line----------
8255 ;; To: charlie@invalid.invalid
8256 ;; Subject: Verification of your contact information
8257 ;; From: Contact verification <admin@foo.invalid>
8258 ;; --text follows this line--
8260 ;; please verify that your contact information is still valid:
8261 ;; Charlie Chaplin, C plaza 33, 33333 C town, Chile
8262 ;; --8<---------------cut here---------------end--------------->8---
8264 ;; FIXME: What is the most common term (circular letter, form letter, serial
8265 ;; letter, standard letter) for such kind of letter? See also
8266 ;; <http://en.wikipedia.org/wiki/Form_letter>
8268 ;; FIXME: Maybe extent message-mode's font-lock support to recognize
8269 ;; `message-form-letter-separator', i.e. highlight each message like a single
8272 (defcustom message-form-letter-separator
8273 "\n----------next form letter message follows this line----------\n"
8274 "Separator for `message-send-form-letter'."
8275 ;; :group 'message-form-letter
8276 :group
'message-various
8277 :version
"23.1" ;; No Gnus
8280 (defcustom message-send-form-letter-delay
1
8281 "Delay in seconds when sending a message with `message-send-form-letter'.
8282 Only used when `message-send-form-letter' is called with non-nil
8284 ;; :group 'message-form-letter
8285 :group
'message-various
8286 :version
"23.1" ;; No Gnus
8289 (defun message-send-form-letter (&optional force
)
8290 "Sent all form letter messages from current buffer.
8291 Unless FORCE, prompt before sending.
8293 The messages are separated by `message-form-letter-separator'.
8294 Header and body are separated by `mail-header-separator'."
8296 (let ((sent 0) (skipped 0)
8300 (goto-char (point-min))
8303 end
(if (search-forward message-form-letter-separator nil t
)
8304 (- (point) (length message-form-letter-separator
) -
1)
8308 (buffer-substring-no-properties start end
))
8309 (setq buff
(generate-new-buffer "*mail - form letter*"))
8310 (with-current-buffer buff
8313 (setq to
(message-fetch-field "To"))
8314 (switch-to-buffer buff
)
8316 (sit-for message-send-form-letter-delay
))
8318 (y-or-n-p (format-message "Send message to `%s'? " to
)))
8320 (setq sent
(1+ sent
))
8321 (message-send-and-exit))
8322 (message "Message to `%s' skipped." to
)
8323 (setq skipped
(1+ skipped
)))
8324 (when (buffer-live-p buff
)
8325 (kill-buffer buff
))))
8326 (message "%s message(s) sent, %s skipped." sent skipped
)))
8328 (defun message-replace-header (header new-value
&optional after force
)
8329 "Remove HEADER and insert the NEW-VALUE.
8330 If AFTER, insert after this header. If FORCE, insert new field
8331 even if NEW-VALUE is empty."
8332 ;; Similar to `nnheader-replace-header' but for message buffers.
8335 (message-narrow-to-headers)
8336 (message-remove-header header
))
8337 (when (or force
(> (length new-value
) 0))
8339 (message-position-on-field header after
)
8340 (message-position-on-field header
))
8341 (insert new-value
))))
8343 (defcustom message-recipients-without-full-name
8344 (list "ding@gnus.org"
8346 "emacs-devel@gnu.org"
8347 "emacs-pretest-bug@gnu.org"
8348 "bug-gnu-emacs@gnu.org")
8349 "Mail addresses that have no full name.
8350 Used in `message-simplify-recipients'."
8351 ;; Maybe the addresses could be extracted from
8352 ;; `gnus-parameter-to-list-alist'?
8353 :type
'(choice (const :tag
"None" nil
)
8355 :version
"23.1" ;; No Gnus
8356 :group
'message-headers
)
8358 (defun message-simplify-recipients ()
8360 (dolist (hdr '("Cc" "To"))
8361 (message-replace-header
8365 (if (and message-recipients-without-full-name
8367 (regexp-opt message-recipients-without-full-name
)
8371 (message-make-from (car addrcomp
) (cadr addrcomp
))
8373 (when (message-fetch-field hdr
)
8374 (mail-extract-address-components
8375 (message-fetch-field hdr
) t
))
8378 ;;; multipart/related and HTML support.
8380 (defun message-make-html-message-with-image-files (files)
8381 "Make a message containing the current dired-marked image files."
8382 (interactive (list (dired-get-marked-files nil current-prefix-arg
)))
8385 (insert "<#part type=text/html>\n\n")
8386 (dolist (file files
)
8387 (insert (format "<img src=%S>\n\n" file
)))
8388 (message-toggle-image-thumbnails)
8391 (defun message-toggle-image-thumbnails ()
8392 "For any included image files, insert a thumbnail of that image."
8394 (let ((displayed nil
))
8396 (goto-char (point-min))
8398 (when-let ((props (get-text-property (point) 'display
)))
8399 (when (and (consp props
)
8400 (eq (car props
) 'image
))
8401 (put-text-property (point) (1+ (point)) 'display nil
)
8402 (setq displayed t
)))
8406 (goto-char (point-min))
8407 (while (re-search-forward "<img.*src=\"\\([^\"]+\\).*>" nil t
)
8408 (let ((string (match-string 0))
8409 (file (match-string 1))
8410 (edges (window-inside-pixel-edges
8411 (get-buffer-window (current-buffer)))))
8412 (delete-region (match-beginning 0) (match-end 0))
8415 file
'imagemagick nil
8416 :max-width
(truncate
8417 (* 0.7 (- (nth 2 edges
) (nth 0 edges
))))
8418 :max-height
(truncate
8419 (* 0.5 (- (nth 3 edges
) (nth 1 edges
)))))
8424 (run-hooks 'message-load-hook
)
8430 ;;; message.el ends here