Output alists with dotted pair notation in .dir-locals.el
[emacs.git] / lisp / gnus / message.el
blob66356b6fda29b45d31e069a83e0db82ffd645c18
1 ;;; message.el --- composing mail and news messages -*- lexical-binding: t -*-
3 ;; Copyright (C) 1996-2018 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 <https://www.gnu.org/licenses/>.
23 ;;; Commentary:
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.
29 ;;; Code:
31 (require 'cl-lib)
32 (require 'mailheader)
33 (require 'gmm-utils)
34 (require 'mail-utils)
35 ;; Only for the trivial macros mail-header-from, mail-header-date
36 ;; mail-header-references, mail-header-subject, mail-header-id
37 (eval-when-compile (require 'nnheader))
38 ;; This is apparently necessary even though things are autoloaded.
39 ;; Because we dynamically bind mail-abbrev-mode-regexp, we'd better
40 ;; require mailabbrev here.
41 (require 'mailabbrev)
42 (require 'mail-parse)
43 (require 'mml)
44 (require 'rfc822)
45 (require 'format-spec)
46 (require 'dired)
47 (require 'mm-util)
48 (require 'rfc2047)
49 (require 'puny)
50 (require 'rmc) ; read-multiple-choice
51 (eval-when-compile (require 'subr-x)) ; when-let*
53 (autoload 'mailclient-send-it "mailclient")
55 (defvar gnus-message-group-art)
56 (defvar gnus-list-identifiers) ; gnus-sum is required where necessary
57 (defvar rmail-enable-mime-composing)
59 (defgroup message '((user-mail-address custom-variable)
60 (user-full-name custom-variable))
61 "Mail and news message composing."
62 :link '(custom-manual "(message)Top")
63 :group 'mail
64 :group 'news)
66 (defgroup message-various nil
67 "Various Message Variables."
68 :link '(custom-manual "(message)Various Message Variables")
69 :group 'message)
71 (defgroup message-buffers nil
72 "Message Buffers."
73 :link '(custom-manual "(message)Message Buffers")
74 :group 'message)
76 (defgroup message-sending nil
77 "Message Sending."
78 :link '(custom-manual "(message)Sending Variables")
79 :group 'message)
81 (defgroup message-interface nil
82 "Message Interface."
83 :link '(custom-manual "(message)Interface")
84 :group 'message)
86 (defgroup message-forwarding nil
87 "Message Forwarding."
88 :link '(custom-manual "(message)Forwarding")
89 :group 'message-interface)
91 (defgroup message-insertion nil
92 "Message Insertion."
93 :link '(custom-manual "(message)Insertion")
94 :group 'message)
96 (defgroup message-headers nil
97 "Message Headers."
98 :link '(custom-manual "(message)Message Headers")
99 :group 'message)
101 (defgroup message-news nil
102 "Composing News Messages."
103 :group 'message)
105 (defgroup message-mail nil
106 "Composing Mail Messages."
107 :group 'message)
109 (defgroup message-faces nil
110 "Faces used for message composing."
111 :group 'message
112 :group 'faces)
114 (defcustom message-directory "~/Mail/"
115 "Directory from which all other mail file variables are derived."
116 :group 'message-various
117 :type 'directory)
119 (defcustom message-max-buffers 10
120 "How many buffers to keep before starting to kill them off."
121 :group 'message-buffers
122 :type 'integer)
124 (defcustom message-send-rename-function nil
125 "Function called to rename the buffer after sending it."
126 :group 'message-buffers
127 :type '(choice function (const nil)))
129 (defcustom message-fcc-handler-function 'message-output
130 "A function called to save outgoing articles.
131 This function will be called with the name of the file to store the
132 article in. The default function is `message-output' which saves in Unix
133 mailbox format."
134 :type '(radio (function-item message-output)
135 (function :tag "Other"))
136 :group 'message-sending)
138 (defcustom message-fcc-externalize-attachments nil
139 "If non-nil, attachments are included as external parts in Fcc copies."
140 :version "22.1"
141 :type 'boolean
142 :group 'message-sending)
144 (defcustom message-courtesy-message
145 "The following message is a courtesy copy of an article\nthat has been posted to %s as well.\n\n"
146 "This is inserted at the start of a mailed copy of a posted message.
147 If the string contains the format spec \"%s\", the Newsgroups
148 the article has been posted to will be inserted there.
149 If this variable is nil, no such courtesy message will be added."
150 :group 'message-sending
151 :type '(radio string (const nil)))
153 (defcustom message-ignored-bounced-headers
154 "^\\(Received\\|Return-Path\\|Delivered-To\\):"
155 "Regexp that matches headers to be removed in resent bounced mail."
156 :group 'message-interface
157 :type 'regexp)
159 (defcustom message-from-style 'angles
160 "Specifies how \"From\" headers look.
162 If nil, they contain just the return address like:
163 king@grassland.com
164 If `parens', they look like:
165 king@grassland.com (Elvis Parsley)
166 If `angles', they look like:
167 Elvis Parsley <king@grassland.com>
169 Otherwise, most addresses look like `angles', but they look like
170 `parens' if `angles' would need quoting and `parens' would not."
171 :version "27.1"
172 :type '(choice (const :tag "simple" nil)
173 (const parens)
174 (const angles)
175 (const default))
176 :group 'message-headers)
177 (make-obsolete-variable
178 'message-from-style
179 "Only the `angles' value is valid according to RFC2822" "27.1")
182 (defcustom message-insert-canlock t
183 "Whether to insert a Cancel-Lock header in news postings."
184 :version "22.1"
185 :group 'message-headers
186 :type 'boolean)
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'."
204 :group 'message-news
205 :type '(repeat sexp)) ; Fixme: improve this
207 (defcustom message-required-headers '((optional . References)
208 From)
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'."
212 :version "22.1"
213 :group 'message-news
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."
220 :version "22.1"
221 :group 'message-news
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."
235 :group 'message-news
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."
246 :group 'message-mail
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."
254 :version "24.1"
255 :group 'message-mail
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."
269 :group 'message-news
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)
275 (or (stringp value)
276 (widget-editable-list-match widget value)))
277 regexp))
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."
282 :group 'message-mail
283 :group 'message-headers
284 :link '(custom-manual "(message)Mail Headers")
285 :type 'regexp)
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
290 any confusion."
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)
296 (or (stringp value)
297 (widget-editable-list-match widget value)))
298 regexp))
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")
305 :type 'regexp)
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 to 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
316 used."
317 :version "24.1"
318 :type '(choice (const :tag "never" nil)
319 (const :tag "always strip" t)
320 (const ask))
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."
334 :version "22.1"
335 :group 'message-various
336 :link '(custom-manual "(message)Message Headers")
337 :type 'regexp)
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."
347 :version "22.1"
348 :group 'message-various
349 :link '(custom-manual "(message)Message Headers")
350 :type 'regexp)
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."
357 :version "22.1"
358 :type 'string
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."
365 :version "22.1"
366 :type 'string
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."
373 :version "22.1"
374 :type 'string
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."
382 :version "22.1"
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."
400 :version "22.1"
401 :type 'boolean
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."
406 :version "22.1"
407 :type 'string
408 :group 'message-various)
410 (defcustom message-followup-to-note "Followup-To: "
411 "Note to insert before signature to notify of follow-up only."
412 :version "22.1"
413 :type 'string
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'."
421 :version "22.1"
422 :type 'function
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
433 whitespace)."
434 :type '(choice (const :tag "strict" "^-- $")
435 (const :tag "loose" "^-- *$")
436 regexp)
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
445 removed."
446 :type 'string
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."
453 :version "23.2"
454 :group 'message-sending
455 :group 'message-mail
456 :link '(custom-manual "(message)Sending Variables")
457 :type 'boolean)
459 (defcustom message-confirm-send nil
460 "When non-nil, ask for confirmation when sending a message."
461 :group 'message-sending
462 :group 'message-mail
463 :version "23.1" ;; No Gnus
464 :link '(custom-manual "(message)Sending Variables")
465 :type 'boolean)
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
475 be newly created.
477 `unique' or t
478 Create the new buffer with the name generated in the Message way.
480 `unsent'
481 Similar to `unique' but the buffer name begins with \"*unsent \".
483 `standard'
484 Similar to nil but the buffer name is simpler like *mail message*.
486 function
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."
490 :version "24.1"
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))))
496 (const unsent)
497 (const standard)
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")
504 :type 'boolean)
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
511 :type 'boolean)
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
522 (let (orgfile)
523 (dolist (f (list "/etc/organization"
524 "/etc/news/organization"
525 "/usr/lib/news/organization"))
526 (when (file-readable-p f)
527 (setq orgfile f)))
528 orgfile)
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
538 successive function.
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
547 to it."
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 nil
556 "Non-nil means forward messages as an inline/rfc822 MIME section.
557 Otherwise, directly inline the old message in the forwarded
558 message.
560 When forwarding as MIME, certain MIME-related headers in the
561 forwarded message may be removed/altered to ensure that the
562 resulting mail is syntactically valid."
563 :version "27.1"
564 :group 'message-forwarding
565 :link '(custom-manual "(message)Forwarding")
566 :type 'boolean)
568 (defcustom message-forward-show-mml 'best
569 "Non-nil means show forwarded messages as MML (decoded from MIME).
570 Otherwise, forwarded messages are unchanged.
571 Can also be the symbol `best' to indicate that MML should be
572 used, except when it is a bad idea to use MML. One example where
573 it is a bad idea is when forwarding a signed or encrypted
574 message, because converting MIME to MML would invalidate the
575 digital signature."
576 :version "21.1"
577 :group 'message-forwarding
578 :type '(choice (const :tag "use MML" t)
579 (const :tag "don't use MML " nil)
580 (const :tag "use MML when appropriate" best)))
582 (defcustom message-forward-before-signature t
583 "Non-nil means put forwarded message before signature, else after."
584 :group 'message-forwarding
585 :type 'boolean)
587 (defcustom message-wash-forwarded-subjects nil
588 "Non-nil means try to remove as much cruft as possible from the subject.
589 Done before generating the new subject of a forward."
590 :group 'message-forwarding
591 :link '(custom-manual "(message)Forwarding")
592 :type 'boolean)
594 (defcustom message-ignored-resent-headers
595 ;; `Delivered-To' needs to be removed because some mailers use it to
596 ;; detect loops, so if you resend a message to an address that ultimately
597 ;; comes back to you (e.g. a mailing-list to which you subscribe, in which
598 ;; case you may be removed from the list on the grounds that mail to you
599 ;; bounced with a "mailing loop" error).
600 "^Return-receipt\\|^X-Gnus\\|^Gnus-Warning:\\|^>?From \\|^Delivered-To:\
601 \\|^X-Content-Length:\\|^X-UIDL:"
602 "All headers that match this regexp will be deleted when resending a message."
603 :version "24.4"
604 :group 'message-interface
605 :link '(custom-manual "(message)Resending")
606 :type '(repeat :value-to-internal (lambda (widget value)
607 (custom-split-regexp-maybe value))
608 :match (lambda (widget value)
609 (or (stringp value)
610 (widget-editable-list-match widget value)))
611 regexp))
613 (defcustom message-forward-ignored-headers "^Content-Transfer-Encoding:\\|^X-Gnus"
614 "All headers that match this regexp will be deleted when forwarding a message.
615 This variable is only consulted when forwarding \"normally\", not
616 when forwarding as MIME or the like.
618 This may also be a list of regexps."
619 :version "21.1"
620 :group 'message-forwarding
621 :type '(repeat :value-to-internal (lambda (widget value)
622 (custom-split-regexp-maybe value))
623 :match (lambda (widget value)
624 (or (stringp value)
625 (widget-editable-list-match widget value)))
626 regexp))
628 (defcustom message-forward-included-headers
629 '("^From:" "^Subject:" "^Date:")
630 "If non-nil, delete non-matching headers when forwarding a message.
631 Only headers that match this regexp will be included. This
632 variable should be a regexp or a list of regexps."
633 :version "27.1"
634 :group 'message-forwarding
635 :type '(repeat :value-to-internal (lambda (widget value)
636 (custom-split-regexp-maybe value))
637 :match (lambda (widget value)
638 (or (stringp value)
639 (widget-editable-list-match widget value)))
640 regexp))
642 (defcustom message-ignored-cited-headers "."
643 "Delete these headers from the messages you yank."
644 :group 'message-insertion
645 :link '(custom-manual "(message)Insertion Variables")
646 :type 'regexp)
648 (defcustom message-cite-prefix-regexp mail-citation-prefix-regexp
649 "Regexp matching the longest possible citation prefix on a line."
650 :version "24.1"
651 :group 'message-insertion
652 :link '(custom-manual "(message)Insertion Variables")
653 :type 'regexp
654 :set (lambda (symbol value)
655 (prog1
656 (custom-set-default symbol value)
657 (if (boundp 'gnus-message-cite-prefix-regexp)
658 (setq gnus-message-cite-prefix-regexp
659 (concat "^\\(?:" value "\\)"))))))
661 (defcustom message-cancel-message "I am canceling my own article.\n"
662 "Message to be inserted in the cancel message."
663 :group 'message-interface
664 :link '(custom-manual "(message)Canceling News")
665 :type 'string)
667 (defun message-send-mail-function ()
668 "Return suitable value for the variable `message-send-mail-function'."
669 (cond ((and (require 'sendmail)
670 (boundp 'sendmail-program)
671 sendmail-program
672 (executable-find sendmail-program))
673 'message-send-mail-with-sendmail)
674 ((and (locate-library "smtpmail")
675 (boundp 'smtpmail-default-smtp-server)
676 smtpmail-default-smtp-server)
677 'message-smtpmail-send-it)
678 ((locate-library "mailclient")
679 'message-send-mail-with-mailclient)
681 (error "Don't know how to send mail. Please customize `message-send-mail-function'"))))
683 (defun message-default-send-mail-function ()
684 (cond ((eq send-mail-function 'smtpmail-send-it) 'message-smtpmail-send-it)
685 ((eq send-mail-function 'feedmail-send-it) 'feedmail-send-it)
686 ((eq send-mail-function 'sendmail-query-once) 'sendmail-query-once)
687 ((eq send-mail-function 'mailclient-send-it)
688 'message-send-mail-with-mailclient)
689 (t (message-send-mail-function))))
691 ;; Useful to set in site-init.el
692 (defcustom message-send-mail-function (message-default-send-mail-function)
693 "Function to call to send the current buffer as mail.
694 The headers should be delimited by a line whose contents match the
695 variable `mail-header-separator'.
697 Valid values include `message-send-mail-with-sendmail'
698 `message-send-mail-with-mh', `message-send-mail-with-qmail',
699 `message-smtpmail-send-it', `smtpmail-send-it',
700 `feedmail-send-it' and `message-send-mail-with-mailclient'. The
701 default is system dependent and determined by the function
702 `message-send-mail-function'.
704 See also `send-mail-function'."
705 :type '(radio (function-item message-send-mail-with-sendmail)
706 (function-item message-send-mail-with-mh)
707 (function-item message-send-mail-with-qmail)
708 (function-item message-smtpmail-send-it)
709 (function-item smtpmail-send-it)
710 (function-item feedmail-send-it)
711 (function-item message-send-mail-with-mailclient
712 :tag "Use Mailclient package")
713 (function :tag "Other"))
714 :group 'message-sending
715 :version "23.2"
716 :initialize 'custom-initialize-default
717 :link '(custom-manual "(message)Mail Variables")
718 :group 'message-mail)
720 (defcustom message-send-news-function 'message-send-news
721 "Function to call to send the current buffer as news.
722 The headers should be delimited by a line whose contents match the
723 variable `mail-header-separator'."
724 :group 'message-sending
725 :group 'message-news
726 :link '(custom-manual "(message)News Variables")
727 :type 'function)
729 (defcustom message-reply-to-function nil
730 "If non-nil, function that should return a list of headers.
731 This function should pick out addresses from the To, Cc, and From headers
732 and respond with new To and Cc headers."
733 :group 'message-interface
734 :link '(custom-manual "(message)Reply")
735 :type '(choice function (const nil)))
737 (defcustom message-wide-reply-to-function nil
738 "If non-nil, function that should return a list of headers.
739 This function should pick out addresses from the To, Cc, and From headers
740 and respond with new To and Cc headers."
741 :group 'message-interface
742 :link '(custom-manual "(message)Wide Reply")
743 :type '(choice function (const nil)))
745 (defcustom message-followup-to-function nil
746 "If non-nil, function that should return a list of headers.
747 This function should pick out addresses from the To, Cc, and From headers
748 and respond with new To and Cc headers."
749 :group 'message-interface
750 :link '(custom-manual "(message)Followup")
751 :type '(choice function (const nil)))
753 (defcustom message-extra-wide-headers nil
754 "If non-nil, a list of additional address headers.
755 These are used when composing a wide reply."
756 :group 'message-sending
757 :type '(repeat string))
759 (defcustom message-use-followup-to 'ask
760 "Specifies what to do with Followup-To header.
761 If nil, always ignore the header. If it is t, use its value, but
762 query before using the \"poster\" value. If it is the symbol `ask',
763 always query the user whether to use the value. If it is the symbol
764 `use', always use the value."
765 :group 'message-interface
766 :link '(custom-manual "(message)Followup")
767 :type '(choice (const :tag "ignore" nil)
768 (const :tag "use & query" t)
769 (const use)
770 (const ask)))
772 (defcustom message-use-mail-followup-to 'use
773 "Specifies what to do with Mail-Followup-To header.
774 If nil, always ignore the header. If it is the symbol `ask', always
775 query the user whether to use the value. If it is the symbol `use',
776 always use the value."
777 :version "22.1"
778 :group 'message-interface
779 :link '(custom-manual "(message)Mailing Lists")
780 :type '(choice (const :tag "ignore" nil)
781 (const use)
782 (const ask)))
784 (defcustom message-subscribed-address-functions nil
785 "Specifies functions for determining list subscription.
786 If nil, do not attempt to determine list subscription with functions.
787 If non-nil, this variable contains a list of functions which return
788 regular expressions to match lists. These functions can be used in
789 conjunction with `message-subscribed-regexps' and
790 `message-subscribed-addresses'."
791 :version "22.1"
792 :group 'message-interface
793 :link '(custom-manual "(message)Mailing Lists")
794 :type '(repeat sexp))
796 (defcustom message-subscribed-address-file nil
797 "A file containing addresses the user is subscribed to.
798 If nil, do not look at any files to determine list subscriptions. If
799 non-nil, each line of this file should be a mailing list address."
800 :version "22.1"
801 :group 'message-interface
802 :link '(custom-manual "(message)Mailing Lists")
803 :type '(radio file (const nil)))
805 (defcustom message-subscribed-addresses nil
806 "Specifies a list of addresses the user is subscribed to.
807 If nil, do not use any predefined list subscriptions. This list of
808 addresses can be used in conjunction with
809 `message-subscribed-address-functions' and `message-subscribed-regexps'."
810 :version "22.1"
811 :group 'message-interface
812 :link '(custom-manual "(message)Mailing Lists")
813 :type '(repeat string))
815 (defcustom message-subscribed-regexps nil
816 "Specifies a list of addresses the user is subscribed to.
817 If nil, do not use any predefined list subscriptions. This list of
818 regular expressions can be used in conjunction with
819 `message-subscribed-address-functions' and `message-subscribed-addresses'."
820 :version "22.1"
821 :group 'message-interface
822 :link '(custom-manual "(message)Mailing Lists")
823 :type '(repeat regexp))
825 (defcustom message-allow-no-recipients 'ask
826 "Specifies what to do when there are no recipients other than Gcc/Fcc.
827 If it is the symbol `always', the posting is allowed. If it is the
828 symbol `never', the posting is not allowed. If it is the symbol
829 `ask', you are prompted."
830 :version "22.1"
831 :group 'message-interface
832 :link '(custom-manual "(message)Message Headers")
833 :type '(choice (const always)
834 (const never)
835 (const ask)))
837 (defcustom message-sendmail-f-is-evil nil
838 "Non-nil means don't add \"-f username\" to the sendmail command line.
839 Doing so would be even more evil than leaving it out."
840 :group 'message-sending
841 :link '(custom-manual "(message)Mail Variables")
842 :type 'boolean)
844 (defcustom message-sendmail-envelope-from
845 ;; `mail-envelope-from' is unavailable unless sendmail.el is loaded.
846 (if (boundp 'mail-envelope-from) mail-envelope-from)
847 "Envelope-from when sending mail with sendmail.
848 If this is nil, use `user-mail-address'. If it is the symbol
849 `header', use the From: header of the message."
850 :version "23.2"
851 :type '(choice (string :tag "From name")
852 (const :tag "Use From: header from message" header)
853 (const :tag "Use `user-mail-address'" nil))
854 :link '(custom-manual "(message)Mail Variables")
855 :group 'message-sending)
857 (defcustom message-sendmail-extra-arguments nil
858 "Additional arguments to `sendmail-program'."
859 ;; E.g. '("-a" "account") for msmtp
860 :version "23.1" ;; No Gnus
861 :type '(repeat string)
862 ;; :link '(custom-manual "(message)Mail Variables")
863 :group 'message-sending)
865 ;; qmail-related stuff
866 (defcustom message-qmail-inject-program "/var/qmail/bin/qmail-inject"
867 "Location of the qmail-inject program."
868 :group 'message-sending
869 :link '(custom-manual "(message)Mail Variables")
870 :type 'file)
872 (defcustom message-qmail-inject-args nil
873 "Arguments passed to qmail-inject programs.
874 This should be a list of strings, one string for each argument.
875 It may also be a function.
877 For e.g., if you wish to set the envelope sender address so that bounces
878 go to the right place or to deal with listserv's usage of that address, you
879 might set this variable to (\"-f\" \"you@some.where\")."
880 :group 'message-sending
881 :link '(custom-manual "(message)Mail Variables")
882 :type '(choice (function)
883 (repeat string)))
885 (defvar gnus-post-method)
886 (defvar gnus-select-method)
887 (defcustom message-post-method
888 (cond ((and (boundp 'gnus-post-method)
889 (listp gnus-post-method)
890 gnus-post-method)
891 gnus-post-method)
892 ((boundp 'gnus-select-method)
893 gnus-select-method)
894 (t '(nnspool "")))
895 "Method used to post news.
896 Note that when posting from inside Gnus, for instance, this
897 variable isn't used."
898 :group 'message-news
899 :group 'message-sending
900 ;; This should be the `gnus-select-method' widget, but that might
901 ;; create a dependence to `gnus.el'.
902 :type 'sexp)
904 (defcustom message-generate-headers-first nil
905 "Which headers should be generated before starting to compose a message.
906 If t, generate all required headers. This can also be a list of headers to
907 generate. The variables `message-required-news-headers' and
908 `message-required-mail-headers' specify which headers to generate.
910 Note that the variable `message-deletable-headers' specifies headers which
911 are to be deleted and then re-generated before sending, so this variable
912 will not have a visible effect for those headers."
913 :group 'message-headers
914 :link '(custom-manual "(message)Message Headers")
915 :type '(choice (const :tag "None" nil)
916 (const :tag "All" t)
917 (repeat (sexp :tag "Header"))))
919 (defcustom message-fill-column 72
920 "Column beyond which automatic line-wrapping should happen.
921 Local value for message buffers. If non-nil, also turn on
922 auto-fill in message buffers."
923 :group 'message-various
924 ;; :link '(custom-manual "(message)Message Headers")
925 :type '(choice (const :tag "Don't turn on auto fill" nil)
926 (integer)))
928 (defcustom message-setup-hook nil
929 "Normal hook, run each time a new outgoing message is initialized.
930 The function `message-setup' runs this hook."
931 :group 'message-various
932 :link '(custom-manual "(message)Various Message Variables")
933 :type 'hook)
935 (defcustom message-cancel-hook nil
936 "Hook run when canceling articles."
937 :group 'message-various
938 :link '(custom-manual "(message)Various Message Variables")
939 :type 'hook)
941 (defcustom message-signature-setup-hook nil
942 "Normal hook, run each time a new outgoing message is initialized.
943 It is run after the headers have been inserted and before
944 the signature is inserted."
945 :group 'message-various
946 :link '(custom-manual "(message)Various Message Variables")
947 :type 'hook)
949 (defcustom message-mode-hook nil
950 "Hook run in message mode buffers."
951 :group 'message-various
952 :type 'hook)
954 (defcustom message-header-hook nil
955 "Hook run in a message mode buffer narrowed to the headers."
956 :group 'message-various
957 :type 'hook)
959 (defcustom message-header-setup-hook nil
960 "Hook called narrowed to the headers when setting up a message buffer."
961 :group 'message-various
962 :link '(custom-manual "(message)Various Message Variables")
963 :type 'hook)
965 (defcustom message-minibuffer-local-map
966 (let ((map (make-sparse-keymap 'message-minibuffer-local-map)))
967 (set-keymap-parent map minibuffer-local-map)
968 map)
969 "Keymap for `message-read-from-minibuffer'."
970 ;; FIXME improve type.
971 :type '(restricted-sexp :match-alternatives (symbolp keymapp))
972 :version "22.1"
973 :group 'message-various)
975 (defcustom message-citation-line-function 'message-insert-citation-line
976 "Function called to insert the \"Whomever writes:\" line.
978 Predefined functions include `message-insert-citation-line' and
979 `message-insert-formatted-citation-line' (see the variable
980 `message-citation-line-format').
982 Note that Gnus provides a feature where the reader can click on
983 `writes:' to hide the cited text. If you change this line too much,
984 people who read your message will have to change their Gnus
985 configuration. See the variable `gnus-cite-attribution-suffix'."
986 :type '(choice
987 (function-item :tag "plain" message-insert-citation-line)
988 (function-item :tag "formatted" message-insert-formatted-citation-line)
989 (function :tag "Other"))
990 :link '(custom-manual "(message)Insertion Variables")
991 :group 'message-insertion)
993 (defcustom message-citation-line-format "On %a, %b %d %Y, %N wrote:\n"
994 "Format of the \"Whomever writes:\" line.
996 The string is formatted using `format-spec'. The following constructs
997 are replaced:
999 %f The full From, e.g. \"John Doe <john.doe@example.invalid>\".
1000 %n The mail address, e.g. \"john.doe@example.invalid\".
1001 %N The real name if present, e.g.: \"John Doe\", else fall
1002 back to the mail address.
1003 %F The first name if present, e.g.: \"John\", else fall
1004 back to the mail address.
1005 %L The last name if present, e.g.: \"Doe\".
1007 All other format specifiers are passed to `format-time-string'
1008 which is called using the date from the article your replying to, but
1009 the date in the formatted string will be expressed in the author's
1010 time zone as much as possible.
1011 Extracting the first (%F) and last name (%L) is done heuristically,
1012 so you should always check it yourself.
1014 Please also read the note in the documentation of
1015 `message-citation-line-function'."
1016 :type '(choice (const :tag "Plain" "%f writes:")
1017 (const :tag "Include date" "On %a, %b %d %Y, %n wrote:")
1018 string)
1019 :link '(custom-manual "(message)Insertion Variables")
1020 :version "23.1" ;; No Gnus
1021 :group 'message-insertion)
1023 (defcustom message-yank-prefix mail-yank-prefix
1024 "Prefix inserted on the lines of yanked messages.
1025 Fix `message-cite-prefix-regexp' if it is set to an abnormal value.
1026 See also `message-yank-cited-prefix' and `message-yank-empty-prefix'."
1027 :version "23.2"
1028 :type 'string
1029 :link '(custom-manual "(message)Insertion Variables")
1030 :group 'message-insertion)
1032 (defcustom message-yank-cited-prefix ">"
1033 "Prefix inserted on cited lines of yanked messages.
1034 Fix `message-cite-prefix-regexp' if it is set to an abnormal value.
1035 See also `message-yank-prefix' and `message-yank-empty-prefix'."
1036 :version "22.1"
1037 :type 'string
1038 :link '(custom-manual "(message)Insertion Variables")
1039 :group 'message-insertion)
1041 (defcustom message-yank-empty-prefix ">"
1042 "Prefix inserted on empty lines of yanked messages.
1043 See also `message-yank-prefix' and `message-yank-cited-prefix'."
1044 :version "22.1"
1045 :type 'string
1046 :link '(custom-manual "(message)Insertion Variables")
1047 :group 'message-insertion)
1049 (defcustom message-indentation-spaces mail-indentation-spaces
1050 "Number of spaces to insert at the beginning of each cited line.
1051 Used by `message-yank-original' via `message-yank-cite'."
1052 :version "23.2"
1053 :group 'message-insertion
1054 :link '(custom-manual "(message)Insertion Variables")
1055 :type 'integer)
1057 (defcustom message-cite-function 'message-cite-original-without-signature
1058 "Function for citing an original message.
1059 Predefined functions include `message-cite-original' and
1060 `message-cite-original-without-signature'.
1061 Note that these functions use `mail-citation-hook' if that is non-nil."
1062 :type '(radio (function-item message-cite-original)
1063 (function-item message-cite-original-without-signature)
1064 (function-item sc-cite-original)
1065 (function :tag "Other"))
1066 :link '(custom-manual "(message)Insertion Variables")
1067 :version "22.3" ;; Gnus 5.10.12 (changed default)
1068 :group 'message-insertion)
1070 (defcustom message-indent-citation-function 'message-indent-citation
1071 "Function for modifying a citation just inserted in the mail buffer.
1072 This can also be a list of functions. Each function can find the
1073 citation between (point) and (mark t). And each function should leave
1074 point and mark around the citation text as modified."
1075 :type 'function
1076 :link '(custom-manual "(message)Insertion Variables")
1077 :group 'message-insertion)
1079 (defcustom message-signature mail-signature
1080 "String to be inserted at the end of the message buffer.
1081 If t, the `message-signature-file' file will be inserted instead.
1082 If a function, the result from the function will be used instead.
1083 If a form, the result from the form will be used instead."
1084 :version "23.2"
1085 :type '(choice string (const :tag "Contents of signature file" t)
1086 function
1087 sexp)
1088 :risky t
1089 :link '(custom-manual "(message)Insertion Variables")
1090 :group 'message-insertion)
1092 (defcustom message-signature-file mail-signature-file
1093 "Name of file containing the text inserted at end of message buffer.
1094 Ignored if the named file doesn't exist.
1095 If nil, don't insert a signature.
1096 If a path is specified, the value of `message-signature-directory' is ignored,
1097 even if set."
1098 :version "23.2"
1099 :type '(choice file (const :tags "None" nil))
1100 :link '(custom-manual "(message)Insertion Variables")
1101 :group 'message-insertion)
1103 (defcustom message-signature-directory nil
1104 "Name of directory containing signature files.
1105 Comes in handy if you have many such files, handled via posting styles for
1106 instance.
1107 If nil, `message-signature-file' is expected to specify the directory if
1108 needed."
1109 :type '(choice string (const :tags "None" nil))
1110 :link '(custom-manual "(message)Insertion Variables")
1111 :group 'message-insertion)
1113 (defcustom message-signature-insert-empty-line t
1114 "If non-nil, insert an empty line before the signature separator."
1115 :version "22.1"
1116 :type 'boolean
1117 :link '(custom-manual "(message)Insertion Variables")
1118 :group 'message-insertion)
1120 (defcustom message-cite-reply-position 'traditional
1121 "Where the reply should be positioned.
1122 If `traditional', reply inline.
1123 If `above', reply above quoted text.
1124 If `below', reply below quoted text.
1126 Note: Many newsgroups frown upon nontraditional reply styles. You
1127 probably want to set this variable only for specific groups,
1128 e.g. using `gnus-posting-styles':
1130 (eval (set (make-local-variable \\='message-cite-reply-position) \\='above))"
1131 :version "24.1"
1132 :type '(choice (const :tag "Reply inline" traditional)
1133 (const :tag "Reply above" above)
1134 (const :tag "Reply below" below))
1135 :group 'message-insertion)
1137 (defcustom message-cite-style nil
1138 "The overall style to be used when yanking cited text.
1139 Value is either nil (no variable overrides) or a let-style list
1140 of pairs (VARIABLE VALUE) that will be bound in
1141 `message-yank-original' to do the quoting.
1143 Presets to impersonate popular mail agents are found in the
1144 message-cite-style-* variables. This variable is intended for
1145 use in `gnus-posting-styles', such as:
1147 ((posting-from-work-p) (eval (set (make-local-variable \\='message-cite-style) message-cite-style-outlook)))"
1148 :version "24.1"
1149 :group 'message-insertion
1150 :type '(choice (const :tag "Do not override variables" :value nil)
1151 (const :tag "MS Outlook" :value message-cite-style-outlook)
1152 (const :tag "Mozilla Thunderbird" :value message-cite-style-thunderbird)
1153 (const :tag "Gmail" :value message-cite-style-gmail)
1154 (variable :tag "User-specified")))
1156 (defconst message-cite-style-outlook
1157 '((message-cite-function 'message-cite-original)
1158 (message-citation-line-function 'message-insert-formatted-citation-line)
1159 (message-cite-reply-position 'above)
1160 (message-yank-prefix "")
1161 (message-yank-cited-prefix "")
1162 (message-yank-empty-prefix "")
1163 (message-citation-line-format "\n\n-----------------------\nOn %a, %b %d %Y, %N wrote:\n"))
1164 "Message citation style used by MS Outlook. Use with message-cite-style.")
1166 (defconst message-cite-style-thunderbird
1167 '((message-cite-function 'message-cite-original)
1168 (message-citation-line-function 'message-insert-formatted-citation-line)
1169 (message-cite-reply-position 'above)
1170 (message-yank-prefix "> ")
1171 (message-yank-cited-prefix ">")
1172 (message-yank-empty-prefix ">")
1173 (message-citation-line-format "On %D %R %p, %N wrote:"))
1174 "Message citation style used by Mozilla Thunderbird. Use with message-cite-style.")
1176 (defconst message-cite-style-gmail
1177 '((message-cite-function 'message-cite-original)
1178 (message-citation-line-function 'message-insert-formatted-citation-line)
1179 (message-cite-reply-position 'above)
1180 (message-yank-prefix " ")
1181 (message-yank-cited-prefix " ")
1182 (message-yank-empty-prefix " ")
1183 (message-citation-line-format "On %e %B %Y %R, %f wrote:\n"))
1184 "Message citation style used by Gmail. Use with message-cite-style.")
1186 (defcustom message-distribution-function nil
1187 "Function called to return a Distribution header."
1188 :group 'message-news
1189 :group 'message-headers
1190 :link '(custom-manual "(message)News Headers")
1191 :type '(choice function (const nil)))
1193 (defcustom message-expires 14
1194 "Number of days before your article expires."
1195 :group 'message-news
1196 :group 'message-headers
1197 :link '(custom-manual "(message)News Headers")
1198 :type 'integer)
1200 (defcustom message-user-path nil
1201 "If nil, use the NNTP server name in the Path header.
1202 If stringp, use this; if non-nil, use no host name (user name only)."
1203 :group 'message-news
1204 :group 'message-headers
1205 :link '(custom-manual "(message)News Headers")
1206 :type '(choice (const :tag "nntp" nil)
1207 (string :tag "name")
1208 (sexp :tag "none" :format "%t" t)))
1210 ;; This can be the name of a buffer, or a cons cell (FUNCTION . ARGS)
1211 ;; for yanking the original buffer.
1212 (defvar message-reply-buffer nil)
1213 (defvar message-reply-headers nil
1214 "The headers of the current replied article.
1215 It is a vector of the following headers:
1216 [number subject from date id references chars lines xref extra].")
1217 (defvar message-newsreader nil)
1218 (defvar message-mailer nil)
1219 (defvar message-sent-message-via nil)
1220 (defvar message-checksum nil)
1221 (defvar message-send-actions nil
1222 "A list of actions to be performed upon successful sending of a message.")
1223 (defvar message-return-action nil
1224 "Action to return to the caller after sending or postponing a message.")
1225 (defvar message-exit-actions nil
1226 "A list of actions to be performed upon exiting after sending a message.")
1227 (defvar message-kill-actions nil
1228 "A list of actions to be performed before killing a message buffer.")
1229 (defvar message-postpone-actions nil
1230 "A list of actions to be performed after postponing a message.")
1232 (define-widget 'message-header-lines 'text
1233 "All header lines must be LFD terminated."
1234 :format "%{%t%}:%n%v"
1235 :valid-regexp "^\\'"
1236 :error "All header lines must be newline terminated")
1238 (defcustom message-default-headers ""
1239 "Header lines to be inserted in outgoing messages.
1240 This can be set to a string containing or a function returning
1241 header lines to be inserted before you edit the message, so you
1242 can edit or delete these lines. If set to a function, it is
1243 called and its result is inserted."
1244 :version "23.2"
1245 :group 'message-headers
1246 :link '(custom-manual "(message)Message Headers")
1247 :type '(choice
1248 (message-header-lines :tag "String")
1249 (function :tag "Function")))
1251 (defcustom message-default-mail-headers
1252 ;; Ease the transition from mail-mode to message-mode. See bugs#4431, 5555.
1253 (concat (if (and (boundp 'mail-default-reply-to)
1254 (stringp mail-default-reply-to))
1255 (format "Reply-To: %s\n" mail-default-reply-to))
1256 (if (and (boundp 'mail-self-blind)
1257 mail-self-blind)
1258 (format "Bcc: %s\n" user-mail-address))
1259 (if (and (boundp 'mail-archive-file-name)
1260 (stringp mail-archive-file-name))
1261 (format "Fcc: %s\n" mail-archive-file-name))
1262 mail-default-headers)
1263 "A string of header lines to be inserted in outgoing mails."
1264 :version "23.2"
1265 :group 'message-headers
1266 :group 'message-mail
1267 :link '(custom-manual "(message)Mail Headers")
1268 :type 'message-header-lines)
1270 (defcustom message-default-news-headers ""
1271 "A string of header lines to be inserted in outgoing news articles."
1272 :group 'message-headers
1273 :group 'message-news
1274 :link '(custom-manual "(message)News Headers")
1275 :type 'message-header-lines)
1277 ;; Note: could use /usr/ucb/mail instead of sendmail;
1278 ;; options -t, and -v if not interactive.
1279 (defcustom message-mailer-swallows-blank-line
1280 (if (and (string-match "sparc-sun-sunos\\(\\'\\|[^5]\\)"
1281 system-configuration)
1282 (file-readable-p "/etc/sendmail.cf")
1283 (with-temp-buffer
1284 (insert-file-contents "/etc/sendmail.cf")
1285 (goto-char (point-min))
1286 (let ((case-fold-search nil))
1287 (re-search-forward "^OR\\>" nil t))))
1288 ;; According to RFC822, "The field-name must be composed of printable
1289 ;; ASCII characters (i. e., characters that have decimal values between
1290 ;; 33 and 126, except colon)", i. e., any chars except ctl chars,
1291 ;; space, or colon.
1292 '(looking-at "[ \t]\\|[][!\"#$%&'()*+,-./0-9;<=>?@A-Z\\\\^_`a-z{|}~]+:"))
1293 "Set this non-nil if the system's mailer runs the header and body together.
1294 \(This problem exists on Sunos 4 when sendmail is run in remote mode.)
1295 The value should be an expression to test whether the problem will
1296 actually occur."
1297 :group 'message-sending
1298 :link '(custom-manual "(message)Mail Variables")
1299 :risky t
1300 :type 'sexp)
1302 ;;;###autoload
1303 (define-mail-user-agent 'message-user-agent
1304 'message-mail 'message-send-and-exit
1305 'message-kill-buffer 'message-send-hook)
1307 (defvar message-mh-deletable-headers '(Message-ID Date Lines Sender)
1308 "If non-nil, delete the deletable headers before feeding to mh.")
1310 (defvar message-send-method-alist
1311 '((news message-news-p message-send-via-news)
1312 (mail message-mail-p message-send-via-mail))
1313 "Alist of ways to send outgoing messages.
1314 Each element has the form
1316 (TYPE PREDICATE FUNCTION)
1318 where TYPE is a symbol that names the method; PREDICATE is a function
1319 called without any parameters to determine whether the message is
1320 a message of type TYPE; and FUNCTION is a function to be called if
1321 PREDICATE returns non-nil. FUNCTION is called with one parameter --
1322 the prefix.")
1324 (defcustom message-mail-alias-type 'abbrev
1325 "What alias expansion type to use in Message buffers.
1326 The default is `abbrev', which uses mailabbrev. `ecomplete' uses
1327 an electric completion mode. nil switches mail aliases off.
1328 This can also be a list of values."
1329 :group 'message
1330 :link '(custom-manual "(message)Mail Aliases")
1331 :type '(choice (const :tag "Use Mailabbrev" abbrev)
1332 (const :tag "Use ecomplete" ecomplete)
1333 (const :tag "No expansion" nil)))
1335 (defcustom message-self-insert-commands '(self-insert-command)
1336 "List of `self-insert-command's used to trigger ecomplete.
1337 When one of those commands is invoked to enter a character in To or Cc
1338 header, ecomplete will suggest the candidates of recipients (see also
1339 `message-mail-alias-type'). If you use some tool to enter non-ASCII
1340 text and it replaces `self-insert-command' with the other command, e.g.
1341 `egg-self-insert-command', you may want to add it to this list."
1342 :group 'message-various
1343 :type '(repeat function))
1345 (defcustom message-auto-save-directory
1346 (if (file-writable-p message-directory)
1347 (file-name-as-directory (expand-file-name "drafts" message-directory))
1348 "~/")
1349 "Directory where Message auto-saves buffers if Gnus isn't running.
1350 If nil, Message won't auto-save."
1351 :group 'message-buffers
1352 :link '(custom-manual "(message)Various Message Variables")
1353 :type '(choice directory (const :tag "Don't auto-save" nil)))
1355 (defcustom message-default-charset (and (not enable-multibyte-characters)
1356 'iso-8859-1)
1357 "Default charset used in non-MULE Emacsen.
1358 If nil, you might be asked to input the charset."
1359 :version "21.1"
1360 :group 'message
1361 :link '(custom-manual "(message)Various Message Variables")
1362 :type 'symbol)
1363 (make-obsolete-variable
1364 'message-default-charset
1365 "The default charset comes from the language environment" "26.1")
1367 (defcustom message-dont-reply-to-names mail-dont-reply-to-names
1368 "Addresses to prune when doing wide replies.
1369 This can be a regexp, a list of regexps or a predicate function.
1370 Also, a value of nil means exclude `user-mail-address' only.
1372 If a function email is passed as the argument."
1373 :version "24.3"
1374 :group 'message
1375 :link '(custom-manual "(message)Wide Reply")
1376 :type '(choice (const :tag "Yourself" nil)
1377 regexp
1378 (repeat :tag "Regexp List" regexp)))
1380 (defsubst message-dont-reply-to-names ()
1381 (if (functionp message-dont-reply-to-names)
1382 message-dont-reply-to-names
1383 (gmm-regexp-concat message-dont-reply-to-names)))
1385 (defcustom message-shoot-gnksa-feet nil
1386 "A list of GNKSA feet you are allowed to shoot.
1387 Gnus gives you all the opportunity you could possibly want for
1388 shooting yourself in the foot. Also, Gnus allows you to shoot the
1389 feet of Good Net-Keeping Seal of Approval. The following are foot
1390 candidates:
1391 `empty-article' Allow you to post an empty article;
1392 `quoted-text-only' Allow you to post quoted text only;
1393 `multiple-copies' Allow you to post multiple copies;
1394 `cancel-messages' Allow you to cancel or supersede messages from
1395 your other email addresses;
1396 `canlock-verify' Allow you to cancel messages without verifying canlock."
1397 :group 'message
1398 :type '(set (const empty-article) (const quoted-text-only)
1399 (const multiple-copies) (const cancel-messages)
1400 (const canlock-verify)))
1402 (defsubst message-gnksa-enable-p (feature)
1403 (or (not (listp message-shoot-gnksa-feet))
1404 (memq feature message-shoot-gnksa-feet)))
1406 (defcustom message-hidden-headers '("^References:" "^Face:" "^X-Face:"
1407 "^X-Draft-From:")
1408 "Regexp of headers to be hidden when composing new messages.
1409 This can also be a list of regexps to match headers. Or a list
1410 starting with `not' and followed by regexps."
1411 :version "22.1"
1412 :group 'message
1413 :link '(custom-manual "(message)Message Headers")
1414 :type '(choice
1415 :format "%{%t%}: %[Value Type%] %v"
1416 (regexp :menu-tag "regexp" :format "regexp\n%t: %v")
1417 (repeat :menu-tag "(regexp ...)" :format "(regexp ...)\n%v%i"
1418 (regexp :format "%t: %v"))
1419 (cons :menu-tag "(not regexp ...)" :format "(not regexp ...)\n%v"
1420 (const not)
1421 (repeat :format "%v%i"
1422 (regexp :format "%t: %v")))))
1424 (defcustom message-cite-articles-with-x-no-archive t
1425 "If non-nil, cite text from articles that has X-No-Archive set."
1426 :group 'message
1427 :type 'boolean)
1429 ;;; Internal variables.
1430 ;;; Well, not really internal.
1432 (defvar message-mode-syntax-table
1433 (let ((table (copy-syntax-table text-mode-syntax-table)))
1434 (modify-syntax-entry ?% ". " table)
1435 (modify-syntax-entry ?> ". " table)
1436 (modify-syntax-entry ?< ". " table)
1437 table)
1438 "Syntax table used while in Message mode.")
1440 (defface message-header-to
1441 '((((class color)
1442 (background dark))
1443 :foreground "DarkOliveGreen1" :bold t)
1444 (((class color)
1445 (background light))
1446 :foreground "MidnightBlue" :bold t)
1448 :bold t :italic t))
1449 "Face used for displaying To headers."
1450 :group 'message-faces)
1452 (defface message-header-cc
1453 '((((class color)
1454 (background dark))
1455 :foreground "chartreuse1" :bold t)
1456 (((class color)
1457 (background light))
1458 :foreground "MidnightBlue")
1460 :bold t))
1461 "Face used for displaying Cc headers."
1462 :group 'message-faces)
1464 (defface message-header-subject
1465 '((((class color)
1466 (background dark))
1467 :foreground "OliveDrab1")
1468 (((class color)
1469 (background light))
1470 :foreground "navy blue" :bold t)
1472 :bold t))
1473 "Face used for displaying Subject headers."
1474 :group 'message-faces)
1476 (defface message-header-newsgroups
1477 '((((class color)
1478 (background dark))
1479 :foreground "yellow" :bold t :italic t)
1480 (((class color)
1481 (background light))
1482 :foreground "blue4" :bold t :italic t)
1484 :bold t :italic t))
1485 "Face used for displaying Newsgroups headers."
1486 :group 'message-faces)
1488 (defface message-header-other
1489 '((((class color)
1490 (background dark))
1491 :foreground "VioletRed1")
1492 (((class color)
1493 (background light))
1494 :foreground "steel blue")
1496 :bold t :italic t))
1497 "Face used for displaying other headers."
1498 :group 'message-faces)
1500 (defface message-header-name
1501 '((((class color)
1502 (background dark))
1503 :foreground "green")
1504 (((class color)
1505 (background light))
1506 :foreground "cornflower blue")
1508 :bold t))
1509 "Face used for displaying header names."
1510 :group 'message-faces)
1512 (defface message-header-xheader
1513 '((((class color)
1514 (background dark))
1515 :foreground "DeepSkyBlue1")
1516 (((class color)
1517 (background light))
1518 :foreground "blue")
1520 :bold t))
1521 "Face used for displaying X-Header headers."
1522 :group 'message-faces)
1524 (defface message-separator
1525 '((((class color)
1526 (background dark))
1527 :foreground "LightSkyBlue1")
1528 (((class color)
1529 (background light))
1530 :foreground "brown")
1532 :bold t))
1533 "Face used for displaying the separator."
1534 :group 'message-faces)
1536 (defface message-cited-text
1537 '((((class color)
1538 (background dark))
1539 :foreground "LightPink1")
1540 (((class color)
1541 (background light))
1542 :foreground "red")
1544 :bold t))
1545 "Face used for displaying cited text names."
1546 :group 'message-faces)
1548 (defface message-mml
1549 '((((class color)
1550 (background dark))
1551 :foreground "MediumSpringGreen")
1552 (((class color)
1553 (background light))
1554 :foreground "ForestGreen")
1556 :bold t))
1557 "Face used for displaying MML."
1558 :group 'message-faces)
1560 (defun message-match-to-eoh (_limit)
1561 (let ((start (point)))
1562 (rfc822-goto-eoh)
1563 ;; Typical situation: some temporary change causes the header to be
1564 ;; incorrect, so EOH comes earlier than intended: the last lines of the
1565 ;; intended headers are now not considered part of the header any more,
1566 ;; so they don't have the multiline property set. When the change is
1567 ;; completed and the header has its correct shape again, the lack of the
1568 ;; multiline property means we won't rehighlight the last lines of
1569 ;; the header.
1570 (if (< (point) start)
1571 nil ;No header within start..limit.
1572 ;; Here we disregard LIMIT so that we may extend the area again.
1573 (set-match-data (list start (point)))
1574 (point))))
1576 (defvar message-font-lock-keywords
1577 (let ((content "[ \t]*\\(.+\\(\n[ \t].*\\)*\\)\n?"))
1578 `((message-match-to-eoh
1579 (,(concat "^\\([Tt]o:\\)" content)
1580 (progn (goto-char (match-beginning 0)) (match-end 0)) nil
1581 (1 'message-header-name)
1582 (2 'message-header-to nil t))
1583 (,(concat "^\\(^[GBF]?[Cc][Cc]:\\|^[Rr]eply-[Tt]o:\\)" content)
1584 (progn (goto-char (match-beginning 0)) (match-end 0)) nil
1585 (1 'message-header-name)
1586 (2 'message-header-cc nil t))
1587 (,(concat "^\\([Ss]ubject:\\)" content)
1588 (progn (goto-char (match-beginning 0)) (match-end 0)) nil
1589 (1 'message-header-name)
1590 (2 'message-header-subject nil t))
1591 (,(concat "^\\([Nn]ewsgroups:\\|Followup-[Tt]o:\\)" content)
1592 (progn (goto-char (match-beginning 0)) (match-end 0)) nil
1593 (1 'message-header-name)
1594 (2 'message-header-newsgroups nil t))
1595 (,(concat "^\\(X-[A-Za-z0-9-]+:\\|In-Reply-To:\\)" content)
1596 (progn (goto-char (match-beginning 0)) (match-end 0)) nil
1597 (1 'message-header-name)
1598 (2 'message-header-xheader))
1599 (,(concat "^\\([A-Z][^: \n\t]+:\\)" content)
1600 (progn (goto-char (match-beginning 0)) (match-end 0)) nil
1601 (1 'message-header-name)
1602 (2 'message-header-other nil t)))
1603 ,@(if (and mail-header-separator
1604 (not (equal mail-header-separator "")))
1605 `((,(concat "^\\(" (regexp-quote mail-header-separator) "\\)$")
1606 1 'message-separator))
1607 nil)
1608 ((lambda (limit)
1609 (re-search-forward (concat "^\\("
1610 message-cite-prefix-regexp
1611 "\\).*")
1612 limit t))
1613 (0 'message-cited-text))
1614 ("<#/?\\(multipart\\|part\\|external\\|mml\\|secure\\)[^>]*>"
1615 (0 'message-mml))))
1616 "Additional expressions to highlight in Message mode.")
1618 (defvar message-face-alist
1619 '((bold . message-bold-region)
1620 (underline . underline-region)
1621 (default . (lambda (b e)
1622 (message-unbold-region b e)
1623 (ununderline-region b e))))
1624 "Alist of mail and news faces for facemenu.
1625 The cdr of each entry is a function for applying the face to a region.")
1627 (defcustom message-send-hook nil
1628 "Hook run before sending messages.
1629 This hook is run quite early when sending."
1630 :group 'message-various
1631 :options '(ispell-message)
1632 :link '(custom-manual "(message)Various Message Variables")
1633 :type 'hook)
1635 (defcustom message-send-mail-hook nil
1636 "Hook run before sending mail messages.
1637 This hook is run very late -- just before the message is sent as
1638 mail."
1639 :group 'message-various
1640 :link '(custom-manual "(message)Various Message Variables")
1641 :type 'hook)
1643 (defcustom message-send-news-hook nil
1644 "Hook run before sending news messages.
1645 This hook is run very late -- just before the message is sent as
1646 news."
1647 :group 'message-various
1648 :link '(custom-manual "(message)Various Message Variables")
1649 :type 'hook)
1651 (defcustom message-sent-hook nil
1652 "Hook run after sending messages."
1653 :group 'message-various
1654 :type 'hook)
1656 (defvar message-send-coding-system 'binary
1657 "Coding system to encode outgoing mail.")
1659 (defvar message-draft-coding-system mm-auto-save-coding-system
1660 "Coding system to compose mail.")
1662 (defcustom message-send-mail-partially-limit nil
1663 "The limitation of messages sent as message/partial.
1664 The lower bound of message size in characters, beyond which the message
1665 should be sent in several parts. If it is nil, the size is unlimited."
1666 :version "24.1"
1667 :group 'message-buffers
1668 :link '(custom-manual "(message)Mail Variables")
1669 :type '(choice (const :tag "unlimited" nil)
1670 (integer 1000000)))
1672 (defcustom message-alternative-emails nil
1673 "Regexp or predicate function matching alternative email addresses.
1674 The first address in the To, Cc or From headers of the original
1675 article matching this variable is used as the From field of
1676 outgoing messages.
1678 If a function, an email string is passed as the argument.
1680 This variable has precedence over posting styles and anything that runs
1681 off `message-setup-hook'."
1682 :group 'message-headers
1683 :link '(custom-manual "(message)Message Headers")
1684 :type '(choice (const :tag "Always use primary" nil)
1685 regexp
1686 function))
1688 (defcustom message-hierarchical-addresses nil
1689 "A list of hierarchical mail address definitions.
1691 Inside each entry, the first address is the \"top\" address, and
1692 subsequent addresses are subaddresses; this is used to indicate that
1693 mail sent to the first address will automatically be delivered to the
1694 subaddresses. So if the first address appears in the recipient list
1695 for a message, the subaddresses will be removed (if present) before
1696 the mail is sent. All addresses in this structure should be
1697 downcased."
1698 :version "22.1"
1699 :group 'message-headers
1700 :type '(repeat (repeat string)))
1702 (defcustom message-mail-user-agent nil
1703 "Like `mail-user-agent'.
1704 Except if it is nil, use Gnus native MUA; if it is t, use
1705 `mail-user-agent'."
1706 :version "22.1"
1707 :type '(radio (const :tag "Gnus native"
1708 :format "%t\n"
1709 nil)
1710 (const :tag "`mail-user-agent'"
1711 :format "%t\n"
1713 (function-item :tag "Default Emacs mail"
1714 :format "%t\n"
1715 sendmail-user-agent)
1716 (function-item :tag "Emacs interface to MH"
1717 :format "%t\n"
1718 mh-e-user-agent)
1719 (function :tag "Other"))
1720 :version "21.1"
1721 :group 'message)
1723 (defcustom message-wide-reply-confirm-recipients nil
1724 "Whether to confirm a wide reply to multiple email recipients.
1725 If this variable is nil, don't ask whether to reply to all recipients.
1726 If this variable is non-nil, pose the question \"Reply to all
1727 recipients?\" before a wide reply to multiple recipients. If the user
1728 answers yes, reply to all recipients as usual. If the user answers
1729 no, only reply back to the author."
1730 :version "22.1"
1731 :group 'message-headers
1732 :link '(custom-manual "(message)Wide Reply")
1733 :type 'boolean)
1735 (defcustom message-user-fqdn nil
1736 "Domain part of Message-Ids."
1737 :version "22.1"
1738 :group 'message-headers
1739 :link '(custom-manual "(message)News Headers")
1740 :type '(radio (const :format "%v " nil)
1741 (string :format "FQDN: %v")))
1743 (defcustom message-use-idna t
1744 "Whether to encode non-ASCII in domain names into ASCII according to IDNA."
1745 :version "26.1"
1746 :group 'message-headers
1747 :link '(custom-manual "(message)IDNA")
1748 :type '(choice (const :tag "Ask" ask)
1749 (const :tag "Never" nil)
1750 (const :tag "Always" t)))
1752 (defcustom message-generate-hashcash (if (executable-find "hashcash") 'opportunistic)
1753 "Whether to generate X-Hashcash: headers.
1754 If t, always generate hashcash headers. If `opportunistic',
1755 only generate hashcash headers if it can be done without the user
1756 waiting (i.e., only asynchronously).
1758 You must have the \"hashcash\" binary installed, see `hashcash-path'."
1759 :version "24.1"
1760 :group 'message-headers
1761 :link '(custom-manual "(message)Mail Headers")
1762 :type '(choice (const :tag "Always" t)
1763 (const :tag "Never" nil)
1764 (const :tag "Opportunistic" opportunistic)))
1766 ;;; Internal variables.
1768 (defvar message-sending-message "Sending...")
1769 (defvar message-buffer-list nil)
1770 (defvar message-this-is-news nil)
1771 (defvar message-this-is-mail nil)
1772 (defvar message-draft-article nil)
1773 (defvar message-mime-part nil)
1774 (defvar message-posting-charset nil)
1775 (defvar message-inserted-headers nil)
1776 (defvar message-inhibit-ecomplete nil)
1778 ;; Byte-compiler warning
1779 (defvar gnus-active-hashtb)
1780 (defvar gnus-read-active-file)
1782 ;;; Regexp matching the delimiter of messages in UNIX mail format
1783 ;;; (UNIX From lines), minus the initial ^. It should be a copy
1784 ;;; of rmail.el's rmail-unix-mail-delimiter.
1785 (defvar message-unix-mail-delimiter
1786 (let ((time-zone-regexp
1787 (concat "\\([A-Z]?[A-Z]?[A-Z][A-Z]\\( DST\\)?"
1788 "\\|[-+]?[0-9][0-9][0-9][0-9]"
1789 "\\|"
1790 "\\) *")))
1791 (concat
1792 "From "
1794 ;; Many things can happen to an RFC 822 mailbox before it is put into
1795 ;; a `From' line. The leading phrase can be stripped, e.g.
1796 ;; `Joe <@w.x:joe@y.z>' -> `<@w.x:joe@y.z>'. The <> can be stripped, e.g.
1797 ;; `<@x.y:joe@y.z>' -> `@x.y:joe@y.z'. Everything starting with a CRLF
1798 ;; can be removed, e.g.
1799 ;; From: joe@y.z (Joe K
1800 ;; User)
1801 ;; can yield `From joe@y.z (Joe K Fri Mar 22 08:11:15 1996', and
1802 ;; From: Joe User
1803 ;; <joe@y.z>
1804 ;; can yield `From Joe User Fri Mar 22 08:11:15 1996'.
1805 ;; The mailbox can be removed or be replaced by white space, e.g.
1806 ;; From: "Joe User"{space}{tab}
1807 ;; <joe@y.z>
1808 ;; can yield `From {space}{tab} Fri Mar 22 08:11:15 1996',
1809 ;; where {space} and {tab} represent the Ascii space and tab characters.
1810 ;; We want to match the results of any of these manglings.
1811 ;; The following regexp rejects names whose first characters are
1812 ;; obviously bogus, but after that anything goes.
1813 "\\([^\0-\b\n-\r\^?].*\\)?"
1815 ;; The time the message was sent.
1816 "\\([^\0-\r \^?]+\\) +" ; day of the week
1817 "\\([^\0-\r \^?]+\\) +" ; month
1818 "\\([0-3]?[0-9]\\) +" ; day of month
1819 "\\([0-2][0-9]:[0-5][0-9]\\(:[0-6][0-9]\\)?\\) *" ; time of day
1821 ;; Perhaps a time zone, specified by an abbreviation, or by a
1822 ;; numeric offset.
1823 time-zone-regexp
1825 ;; The year.
1826 " \\([0-9][0-9]+\\) *"
1828 ;; On some systems the time zone can appear after the year, too.
1829 time-zone-regexp
1831 ;; Old uucp cruft.
1832 "\\(remote from .*\\)?"
1834 "\n"))
1835 "Regexp matching the delimiter of messages in UNIX mail format.")
1837 (defvar message-unsent-separator
1838 (concat "^ *---+ +Unsent message follows +---+ *$\\|"
1839 "^ *---+ +Returned message +---+ *$\\|"
1840 "^Start of returned message$\\|"
1841 "^ *---+ +Original message +---+ *$\\|"
1842 "^ *--+ +begin message +--+ *$\\|"
1843 "^ *---+ +Original message follows +---+ *$\\|"
1844 "^ *---+ +Undelivered message follows +---+ *$\\|"
1845 "^------ This is a copy of the message, including all the headers. ------ *$\\|"
1846 "^|? *---+ +Message text follows: +---+ *|?$")
1847 "A regexp that matches the separator before the text of a failed message.")
1849 (defvar message-field-fillers
1850 '((To message-fill-field-address)
1851 (Cc message-fill-field-address)
1852 (From message-fill-field-address))
1853 "Alist of header names/filler functions.")
1855 (defvar message-header-format-alist
1856 `((From)
1857 (Newsgroups)
1858 (To)
1859 (Cc)
1860 (Subject)
1861 (In-Reply-To)
1862 (Fcc)
1863 (Bcc)
1864 (Date)
1865 (Organization)
1866 (Distribution)
1867 (Lines)
1868 (Expires)
1869 (Message-ID)
1870 (References . message-shorten-references)
1871 (User-Agent))
1872 "Alist used for formatting headers.")
1874 (defvar message-options nil
1875 "Some saved answers when sending message.")
1876 (make-variable-buffer-local 'message-options)
1878 (defvar message-send-mail-real-function nil
1879 "Internal send mail function.")
1881 (defvar message-bogus-system-names "\\`localhost\\.\\|\\.local\\'"
1882 "The regexp of bogus system names.")
1884 (autoload 'gnus-alive-p "gnus-util")
1885 (autoload 'gnus-delay-article "gnus-delay")
1886 (autoload 'gnus-extract-address-components "gnus-util")
1887 (autoload 'gnus-find-method-for-group "gnus")
1888 (autoload 'gnus-group-decoded-name "gnus-group")
1889 (autoload 'gnus-group-name-charset "gnus-group")
1890 (autoload 'gnus-group-name-decode "gnus-group")
1891 (autoload 'gnus-groups-from-server "gnus")
1892 (autoload 'gnus-open-server "gnus-int")
1893 (autoload 'gnus-output-to-mail "gnus-util")
1894 (autoload 'gnus-output-to-rmail "gnus-util")
1895 (autoload 'gnus-request-post "gnus-int")
1896 (autoload 'gnus-server-string "gnus")
1897 (autoload 'message-setup-toolbar "messagexmas")
1898 (autoload 'mh-new-draft-name "mh-comp")
1899 (autoload 'mh-send-letter "mh-comp")
1900 (autoload 'nndraft-request-associate-buffer "nndraft")
1901 (autoload 'nndraft-request-expire-articles "nndraft")
1902 (autoload 'nnvirtual-find-group-art "nnvirtual")
1903 (autoload 'rmail-msg-is-pruned "rmail")
1904 (autoload 'rmail-output "rmailout")
1906 (defun message-kill-all-overlays ()
1907 (mapcar #'delete-overlay (overlays-in (point-min) (point-max))))
1912 ;;; Utility functions.
1915 (defmacro message-y-or-n-p (question show &rest text)
1916 "Ask QUESTION, displaying remaining args in a temporary buffer if SHOW."
1917 `(message-talkative-question 'y-or-n-p ,question ,show ,@text))
1919 (defmacro message-delete-line (&optional n)
1920 "Delete the current line (and the next N lines)."
1921 `(delete-region (progn (beginning-of-line) (point))
1922 (progn (forward-line ,(or n 1)) (point))))
1924 (defun message-mark-active-p ()
1925 "Non-nil means the mark and region are currently active in this buffer."
1926 mark-active)
1928 (defun message-unquote-tokens (elems)
1929 "Remove double quotes (\") from strings in list ELEMS."
1930 (mapcar (lambda (item)
1931 (while (string-match "^\\(.*\\)\"\\(.*\\)$" item)
1932 (setq item (concat (match-string 1 item)
1933 (match-string 2 item))))
1934 item)
1935 elems))
1937 (defun message-tokenize-header (header &optional separator)
1938 "Split HEADER into a list of header elements.
1939 SEPARATOR is a string of characters to be used as separators. \",\"
1940 is used by default."
1941 (if (not header)
1943 (let ((regexp (format "[%s]+" (or separator ",")))
1944 (first t)
1945 beg quoted elems paren)
1946 (with-temp-buffer
1947 (mm-enable-multibyte)
1948 (setq beg (point-min))
1949 (insert header)
1950 (goto-char (point-min))
1951 (while (not (eobp))
1952 (if first
1953 (setq first nil)
1954 (forward-char 1))
1955 (cond ((and (> (point) beg)
1956 (or (eobp)
1957 (and (looking-at regexp)
1958 (not quoted)
1959 (not paren))))
1960 (push (buffer-substring beg (point)) elems)
1961 (setq beg (match-end 0)))
1962 ((eq (char-after) ?\")
1963 (setq quoted (not quoted)))
1964 ((and (eq (char-after) ?\()
1965 (not quoted))
1966 (setq paren t))
1967 ((and (eq (char-after) ?\))
1968 (not quoted))
1969 (setq paren nil))))
1970 (nreverse elems)))))
1972 (autoload 'nnheader-insert-file-contents "nnheader")
1974 (defun message-mail-file-mbox-p (file)
1975 "Say whether FILE looks like a Unix mbox file."
1976 (when (and (file-exists-p file)
1977 (file-readable-p file)
1978 (file-regular-p file))
1979 (with-temp-buffer
1980 (nnheader-insert-file-contents file)
1981 (goto-char (point-min))
1982 (looking-at message-unix-mail-delimiter))))
1984 (defun message-fetch-field (header &optional not-all)
1985 "The same as `mail-fetch-field', only remove all newlines.
1986 The buffer is expected to be narrowed to just the header of the message;
1987 see `message-narrow-to-headers-or-head'."
1988 (let* ((inhibit-point-motion-hooks t)
1989 (value (mail-fetch-field header nil (not not-all))))
1990 (when value
1991 (while (string-match "\n[\t ]+" value)
1992 (setq value (replace-match " " t t value)))
1993 value)))
1995 (defun message-field-value (header &optional not-all)
1996 "The same as `message-fetch-field', only narrow to the headers first."
1997 (save-excursion
1998 (save-restriction
1999 (message-narrow-to-headers-or-head)
2000 (message-fetch-field header not-all))))
2002 (defun message-narrow-to-field ()
2003 "Narrow the buffer to the header on the current line."
2004 (beginning-of-line)
2005 (while (looking-at "[ \t]")
2006 (forward-line -1))
2007 (narrow-to-region
2008 (point)
2009 (progn
2010 (forward-line 1)
2011 (if (re-search-forward "^[^ \n\t]" nil t)
2012 (point-at-bol)
2013 (point-max))))
2014 (goto-char (point-min)))
2016 (defun message-add-header (&rest headers)
2017 "Add the HEADERS to the message header, skipping those already present."
2018 (while headers
2019 (let (hclean)
2020 (unless (string-match "^\\([^:]+\\):[ \t]*[^ \t]" (car headers))
2021 (error "Invalid header `%s'" (car headers)))
2022 (setq hclean (match-string 1 (car headers)))
2023 (save-restriction
2024 (message-narrow-to-headers)
2025 (unless (re-search-forward (concat "^" (regexp-quote hclean) ":") nil t)
2026 (goto-char (point-max))
2027 (if (string-match "\n$" (car headers))
2028 (insert (car headers))
2029 (insert (car headers) ?\n)))))
2030 (setq headers (cdr headers))))
2032 (defmacro message-with-reply-buffer (&rest forms)
2033 "Evaluate FORMS in the reply buffer, if it exists."
2034 `(when (and (bufferp message-reply-buffer)
2035 (buffer-name message-reply-buffer))
2036 (with-current-buffer message-reply-buffer
2037 ,@forms)))
2039 (put 'message-with-reply-buffer 'lisp-indent-function 0)
2040 (put 'message-with-reply-buffer 'edebug-form-spec '(body))
2042 (defun message-fetch-reply-field (header)
2043 "Fetch field HEADER from the message we're replying to."
2044 (message-with-reply-buffer
2045 (save-restriction
2046 (mail-narrow-to-head)
2047 (message-fetch-field header))))
2049 (defun message-strip-list-identifiers (subject)
2050 "Remove list identifiers in `gnus-list-identifiers' from string SUBJECT."
2051 (require 'gnus-sum) ; for gnus-list-identifiers
2052 (let ((regexp (if (stringp gnus-list-identifiers)
2053 gnus-list-identifiers
2054 (mapconcat 'identity gnus-list-identifiers " *\\|"))))
2055 (if (string-match (concat "\\(\\(\\(Re: +\\)?\\(" regexp
2056 " *\\)\\)+\\(Re: +\\)?\\)") subject)
2057 (concat (substring subject 0 (match-beginning 1))
2058 (or (match-string 3 subject)
2059 (match-string 5 subject))
2060 (substring subject
2061 (match-end 1)))
2062 subject)))
2064 (defun message-strip-subject-re (subject)
2065 "Remove \"Re:\" from subject lines in string SUBJECT."
2066 (if (string-match message-subject-re-regexp subject)
2067 (substring subject (match-end 0))
2068 subject))
2070 (defcustom message-replacement-char "."
2071 "Replacement character used instead of unprintable or not decodable chars."
2072 :group 'message-various
2073 :version "22.1" ;; Gnus 5.10.9
2074 :type '(choice string
2075 (const ".")
2076 (const "?")))
2078 ;; FIXME: We also should call `message-strip-subject-encoded-words'
2079 ;; when forwarding. Probably in `message-make-forward-subject' and
2080 ;; `message-forward-make-body'.
2082 (defun message-strip-subject-encoded-words (subject)
2083 "Fix non-decodable words in SUBJECT."
2084 ;; Cf. `gnus-simplify-subject-fully'.
2085 (let* ((case-fold-search t)
2086 (replacement-chars (format "[%s%s%s]"
2087 message-replacement-char
2088 message-replacement-char
2089 message-replacement-char))
2090 (enc-word-re "=\\?\\([^?]+\\)\\?\\([QB]\\)\\?\\([^?]+\\)\\(\\?=\\)")
2091 cs-string
2092 (have-marker
2093 (with-temp-buffer
2094 (insert subject)
2095 (goto-char (point-min))
2096 (when (re-search-forward enc-word-re nil t)
2097 (setq cs-string (match-string 1)))))
2098 cs-coding q-or-b word-beg word-end)
2099 (if (or (not have-marker) ;; No encoded word found...
2100 ;; ... or double encoding was correct:
2101 (and (stringp cs-string)
2102 (setq cs-string (downcase cs-string))
2103 (mm-coding-system-p (intern cs-string))
2104 (not (prog1
2105 (y-or-n-p
2106 (format "\
2107 Decoded Subject \"%s\"
2108 contains a valid encoded word. Decode again? "
2109 subject))
2110 (setq cs-coding (intern cs-string))))))
2111 subject
2112 (with-temp-buffer
2113 (insert subject)
2114 (goto-char (point-min))
2115 (while (re-search-forward enc-word-re nil t)
2116 (setq cs-string (downcase (match-string 1))
2117 q-or-b (match-string 2)
2118 word-beg (match-beginning 0)
2119 word-end (match-end 0))
2120 (setq cs-coding
2121 (if (mm-coding-system-p (intern cs-string))
2122 (setq cs-coding (intern cs-string))
2123 nil))
2124 ;; No double encoded subject? => bogus charset.
2125 (unless cs-coding
2126 (setq cs-coding
2127 (read-coding-system
2128 (format-message "\
2129 Decoded Subject \"%s\"
2130 contains an encoded word. The charset `%s' is unknown or invalid.
2131 Hit RET to replace non-decodable characters with \"%s\" or enter replacement
2132 charset: "
2133 subject cs-string message-replacement-char)))
2134 (if cs-coding
2135 (replace-match (concat "=?" (symbol-name cs-coding)
2136 "?\\2?\\3\\4\\5"))
2137 (save-excursion
2138 (goto-char word-beg)
2139 (re-search-forward "=\\?\\([^?]+\\)\\?\\([QB]\\)\\?" word-end t)
2140 (replace-match "")
2141 ;; QP or base64
2142 (if (string-match "\\`Q\\'" q-or-b)
2143 ;; QP
2144 (progn
2145 (message "Replacing non-decodable characters with \"%s\"."
2146 message-replacement-char)
2147 (while (re-search-forward "\\(=[A-F0-9][A-F0-9]\\)+"
2148 word-end t)
2149 (replace-match message-replacement-char)))
2150 ;; base64
2151 (message "Replacing non-decodable characters with \"%s\"."
2152 replacement-chars)
2153 (re-search-forward "[^?]+" word-end t)
2154 (replace-match replacement-chars))
2155 (re-search-forward "\\?=")
2156 (replace-match "")))))
2157 (rfc2047-decode-region (point-min) (point-max))
2158 (buffer-string)))))
2160 ;;; Start of functions adopted from `message-utils.el'.
2162 (defun message-strip-subject-trailing-was (subject)
2163 "Remove trailing \"(was: <old subject>)\" from SUBJECT lines.
2164 Leading \"Re: \" is not stripped by this function. Use the function
2165 `message-strip-subject-re' for this."
2167 (let ((query message-subject-trailing-was-query) new)
2168 (and query
2169 (string-match (if (eq query 'ask)
2170 message-subject-trailing-was-ask-regexp
2171 message-subject-trailing-was-regexp)
2172 subject)
2173 (setq new (substring subject 0 (match-beginning 0)))
2174 (or (not (eq query 'ask))
2175 (message-y-or-n-p
2176 "Strip `(was: <old subject>)' in subject? " t
2177 (concat
2178 "Strip `(was: <old subject>)' in subject "
2179 "and use the new one instead?\n\n"
2180 "Current subject is: \"" subject "\"\n\n"
2181 "New subject would be: \"" new "\"\n\n"
2182 "See the variable `message-subject-trailing-was-query' "
2183 "to get rid of this query.")))
2184 new))
2185 subject))
2187 ;;; Suggested by Jonas Steverud @ www.dtek.chalmers.se/~d4jonas/
2189 (defun message-change-subject (new-subject)
2190 "Ask for NEW-SUBJECT header, append (was: <Old Subject>)."
2191 (interactive
2192 (list
2193 (read-from-minibuffer "New subject: ")))
2194 (cond ((and (not (or (null new-subject) ; new subject not empty
2195 (zerop (string-width new-subject))
2196 (string-match "^[ \t]*$" new-subject))))
2197 (save-excursion
2198 (let ((old-subject
2199 (save-restriction
2200 (message-narrow-to-headers)
2201 (message-fetch-field "Subject"))))
2202 (cond ((not old-subject)
2203 (error "No current subject"))
2204 ((not (string-match
2205 (concat "^[ \t]*"
2206 (regexp-quote new-subject)
2207 "[ \t]*$")
2208 old-subject)) ; yes, it really is a new subject
2209 ;; delete eventual Re: prefix
2210 (setq old-subject
2211 (message-strip-subject-re old-subject))
2212 (message-goto-subject)
2213 (message-delete-line)
2214 (insert (concat "Subject: "
2215 new-subject
2216 " (was: "
2217 old-subject ")\n")))))))))
2219 (defun message-mark-inserted-region (beg end &optional verbatim)
2220 "Mark some region in the current article with enclosing tags.
2221 See `message-mark-insert-begin' and `message-mark-insert-end'.
2222 If VERBATIM, use slrn style verbatim marks (\"#v+\" and \"#v-\")."
2223 (interactive "r\nP")
2224 (save-excursion
2225 ;; add to the end of the region first, otherwise end would be invalid
2226 (goto-char end)
2227 (insert (if verbatim "#v-\n" message-mark-insert-end))
2228 (goto-char beg)
2229 (insert (if verbatim "#v+\n" message-mark-insert-begin))))
2231 (defun message-mark-insert-file (file &optional verbatim)
2232 "Insert FILE at point, marking it with enclosing tags.
2233 See `message-mark-insert-begin' and `message-mark-insert-end'.
2234 If VERBATIM, use slrn style verbatim marks (\"#v+\" and \"#v-\")."
2235 (interactive "fFile to insert: \nP")
2236 ;; reverse insertion to get correct result.
2237 (let ((p (point)))
2238 (insert (if verbatim "#v-\n" message-mark-insert-end))
2239 (goto-char p)
2240 (insert-file-contents file)
2241 (goto-char p)
2242 (insert (if verbatim "#v+\n" message-mark-insert-begin))))
2244 (defun message-add-archive-header ()
2245 "Insert \"X-No-Archive: Yes\" in the header and a note in the body.
2246 The note can be customized using `message-archive-note'. When called with a
2247 prefix argument, ask for a text to insert. If you don't want the note in the
2248 body, set `message-archive-note' to nil."
2249 (interactive)
2250 (if current-prefix-arg
2251 (setq message-archive-note
2252 (read-from-minibuffer "Reason for No-Archive: "
2253 (cons message-archive-note 0))))
2254 (save-excursion
2255 (if (message-goto-signature)
2256 (re-search-backward message-signature-separator))
2257 (when message-archive-note
2258 (insert message-archive-note)
2259 (newline))
2260 (message-add-header message-archive-header)
2261 (message-sort-headers)))
2263 (defun message-cross-post-followup-to-header (target-group)
2264 "Mangles FollowUp-To and Newsgroups header to point to TARGET-GROUP.
2265 With prefix-argument just set Follow-Up, don't cross-post."
2266 (interactive
2267 (list ; Completion based on Gnus
2268 (replace-regexp-in-string
2269 "\\`.*:" ""
2270 (completing-read "Followup To: "
2271 (if (boundp 'gnus-newsrc-alist)
2272 gnus-newsrc-alist)
2273 nil nil '("poster" . 0)
2274 (if (boundp 'gnus-group-history)
2275 'gnus-group-history)))))
2276 (message-remove-header "Follow[Uu]p-[Tt]o" t)
2277 (message-goto-newsgroups)
2278 (beginning-of-line)
2279 ;; if we already did a crosspost before, kill old target
2280 (if (and message-cross-post-old-target
2281 (re-search-forward
2282 (regexp-quote (concat "," message-cross-post-old-target))
2283 nil t))
2284 (replace-match ""))
2285 ;; unless (followup is to poster or user explicitly asked not
2286 ;; to cross-post, or target-group is already in Newsgroups)
2287 ;; add target-group to Newsgroups line.
2288 (cond ((and (or
2289 ;; def: cross-post, req:no
2290 (and message-cross-post-default (not current-prefix-arg))
2291 ;; def: no-cross-post, req:yes
2292 (and (not message-cross-post-default) current-prefix-arg))
2293 (not (string-match "poster" target-group))
2294 (not (string-match (regexp-quote target-group)
2295 (message-fetch-field "Newsgroups"))))
2296 (end-of-line)
2297 (insert (concat "," target-group))))
2298 (end-of-line) ; ensure Followup: comes after Newsgroups:
2299 ;; unless new followup would be identical to Newsgroups line
2300 ;; make a new Followup-To line
2301 (if (not (string-match (concat "^[ \t]*"
2302 target-group
2303 "[ \t]*$")
2304 (message-fetch-field "Newsgroups")))
2305 (insert (concat "\nFollowup-To: " target-group)))
2306 (setq message-cross-post-old-target target-group))
2308 (defun message-cross-post-insert-note (target-group cross-post in-old
2309 _old-groups)
2310 "Insert a in message body note about a set Followup or Crosspost.
2311 If there have been previous notes, delete them. TARGET-GROUP specifies the
2312 group to Followup-To. When CROSS-POST is t, insert note about
2313 crossposting. IN-OLD specifies whether TARGET-GROUP is a member of
2314 OLD-GROUPS. OLD-GROUPS lists the old-groups the posting would have
2315 been made to before the user asked for a Crosspost."
2316 ;; start scanning body for previous uses
2317 (message-goto-signature)
2318 (let ((head (re-search-backward
2319 (concat "^" mail-header-separator)
2320 nil t))) ; just search in body
2321 (message-goto-signature)
2322 (while (re-search-backward
2323 (concat "^" (regexp-quote message-cross-post-note) ".*")
2324 head t)
2325 (message-delete-line))
2326 (message-goto-signature)
2327 (while (re-search-backward
2328 (concat "^" (regexp-quote message-followup-to-note) ".*")
2329 head t)
2330 (message-delete-line))
2331 ;; insert new note
2332 (if (message-goto-signature)
2333 (re-search-backward message-signature-separator))
2334 (if (or in-old
2335 (not cross-post)
2336 (string-match "^[ \t]*poster[ \t]*$" target-group))
2337 (insert (concat message-followup-to-note target-group "\n"))
2338 (insert (concat message-cross-post-note target-group "\n")))))
2340 (defun message-cross-post-followup-to (target-group)
2341 "Crossposts message and set Followup-To to TARGET-GROUP.
2342 With prefix-argument just set Follow-Up, don't cross-post."
2343 (interactive
2344 (list ; Completion based on Gnus
2345 (replace-regexp-in-string
2346 "\\`.*:" ""
2347 (completing-read "Followup To: "
2348 (if (boundp 'gnus-newsrc-alist)
2349 gnus-newsrc-alist)
2350 nil nil '("poster" . 0)
2351 (if (boundp 'gnus-group-history)
2352 'gnus-group-history)))))
2353 (when (fboundp 'gnus-group-real-name)
2354 (setq target-group (gnus-group-real-name target-group)))
2355 (cond ((not (or (null target-group) ; new subject not empty
2356 (zerop (string-width target-group))
2357 (string-match "^[ \t]*$" target-group)))
2358 (save-excursion
2359 (let* ((old-groups (message-fetch-field "Newsgroups"))
2360 (in-old (string-match
2361 (regexp-quote target-group)
2362 (or old-groups ""))))
2363 ;; check whether target exactly matches old Newsgroups
2364 (cond ((not old-groups)
2365 (error "No current newsgroup"))
2366 ((or (not in-old)
2367 (not (string-match
2368 (concat "^[ \t]*"
2369 (regexp-quote target-group)
2370 "[ \t]*$")
2371 old-groups)))
2372 ;; yes, Newsgroups line must change
2373 (message-cross-post-followup-to-header target-group)
2374 ;; insert note whether we do cross-post or followup-to
2375 (funcall message-cross-post-note-function
2376 target-group
2377 (if (or (and message-cross-post-default
2378 (not current-prefix-arg))
2379 (and (not message-cross-post-default)
2380 current-prefix-arg)) t)
2381 in-old old-groups))))))))
2383 ;;; Reduce To: to Cc: or Bcc: header
2385 (defun message-reduce-to-to-cc ()
2386 "Replace contents of To: header with contents of Cc: or Bcc: header."
2387 (interactive)
2388 (let ((cc-content
2389 (save-restriction (message-narrow-to-headers)
2390 (message-fetch-field "cc")))
2391 (bcc nil))
2392 (if (and (not cc-content)
2393 (setq cc-content
2394 (save-restriction
2395 (message-narrow-to-headers)
2396 (message-fetch-field "bcc"))))
2397 (setq bcc t))
2398 (cond (cc-content
2399 (save-excursion
2400 (message-goto-to)
2401 (message-delete-line)
2402 (insert (concat "To: " cc-content "\n"))
2403 (save-restriction
2404 (message-narrow-to-headers)
2405 (message-remove-header (if bcc
2406 "bcc"
2407 "cc"))))))))
2409 ;;; End of functions adopted from `message-utils.el'.
2411 (defun message-remove-header (header &optional is-regexp first reverse)
2412 "Remove HEADER in the narrowed buffer.
2413 If IS-REGEXP, HEADER is a regular expression.
2414 If FIRST, only remove the first instance of the header.
2415 If REVERSE, remove headers that doesn't match HEADER.
2416 Return the number of headers removed."
2417 (goto-char (point-min))
2418 (let ((regexp (if is-regexp header (concat "^" (regexp-quote header) ":")))
2419 (number 0)
2420 (case-fold-search t)
2421 last)
2422 (while (and (not (eobp))
2423 (not last))
2424 (if (if reverse
2425 (and (not (looking-at regexp))
2426 ;; Don't remove things not looking like header.
2427 (looking-at "[!-9;-~]+:"))
2428 (looking-at regexp))
2429 (progn
2430 (cl-incf number)
2431 (when first
2432 (setq last t))
2433 (delete-region
2434 (point)
2435 ;; There might be a continuation header, so we have to search
2436 ;; until we find a new non-continuation line.
2437 (progn
2438 (forward-line 1)
2439 (if (re-search-forward "^[^ \t]" nil t)
2440 (goto-char (match-beginning 0))
2441 (point-max)))))
2442 (forward-line 1)
2443 (if (re-search-forward "^[^ \t]" nil t)
2444 (goto-char (match-beginning 0))
2445 (goto-char (point-max)))))
2446 number))
2448 (defun message-remove-first-header (header)
2449 "Remove the first instance of HEADER if there is more than one."
2450 (let ((count 0)
2451 (regexp (concat "^" (regexp-quote header) ":")))
2452 (save-excursion
2453 (goto-char (point-min))
2454 (while (re-search-forward regexp nil t)
2455 (cl-incf count)))
2456 (while (> count 1)
2457 (message-remove-header header nil t)
2458 (cl-decf count))))
2460 (defun message-narrow-to-headers ()
2461 "Narrow the buffer to the head of the message."
2462 (widen)
2463 (narrow-to-region
2464 (goto-char (point-min))
2465 (if (re-search-forward
2466 (concat "^" (regexp-quote mail-header-separator) "\n") nil t)
2467 (match-beginning 0)
2468 (point-max)))
2469 (goto-char (point-min)))
2471 (defun message-narrow-to-head-1 ()
2472 "Like `message-narrow-to-head'. Don't widen."
2473 (narrow-to-region
2474 (goto-char (point-min))
2475 (if (search-forward "\n\n" nil 1)
2476 (1- (point))
2477 (point-max)))
2478 (goto-char (point-min)))
2480 ;; FIXME: clarify difference: message-narrow-to-head,
2481 ;; message-narrow-to-headers-or-head, message-narrow-to-headers
2482 (defun message-narrow-to-head ()
2483 "Narrow the buffer to the head of the message.
2484 Point is left at the beginning of the narrowed-to region."
2485 (widen)
2486 (message-narrow-to-head-1))
2488 (defun message-narrow-to-headers-or-head ()
2489 "Narrow the buffer to the head of the message."
2490 (widen)
2491 (narrow-to-region
2492 (goto-char (point-min))
2493 (if (re-search-forward (concat "\\(\n\\)\n\\|^\\("
2494 (regexp-quote mail-header-separator)
2495 "\n\\)")
2496 nil t)
2497 (or (match-end 1) (match-beginning 2))
2498 (point-max)))
2499 (goto-char (point-min)))
2501 (defun message-news-p ()
2502 "Say whether the current buffer contains a news message."
2503 (and (not message-this-is-mail)
2504 (or message-this-is-news
2505 (save-excursion
2506 (save-restriction
2507 (message-narrow-to-headers)
2508 (and (message-fetch-field "newsgroups")
2509 (not (message-fetch-field "posted-to"))))))))
2511 (defun message-mail-p ()
2512 "Say whether the current buffer contains a mail message."
2513 (and (not message-this-is-news)
2514 (or message-this-is-mail
2515 (save-excursion
2516 (save-restriction
2517 (message-narrow-to-headers)
2518 (or (message-fetch-field "to")
2519 (message-fetch-field "cc")
2520 (message-fetch-field "bcc")))))))
2522 (defun message-subscribed-p ()
2523 "Say whether we need to insert a MFT header."
2524 (or message-subscribed-regexps
2525 message-subscribed-addresses
2526 message-subscribed-address-file
2527 message-subscribed-address-functions))
2529 (defun message-next-header ()
2530 "Go to the beginning of the next header."
2531 (beginning-of-line)
2532 (or (eobp) (forward-char 1))
2533 (not (if (re-search-forward "^[^ \t]" nil t)
2534 (beginning-of-line)
2535 (goto-char (point-max)))))
2537 (defun message-sort-headers-1 ()
2538 "Sort the buffer as headers using `message-rank' text props."
2539 (goto-char (point-min))
2540 (require 'sort)
2541 (sort-subr
2542 nil 'message-next-header
2543 (lambda ()
2544 (message-next-header)
2545 (unless (bobp)
2546 (forward-char -1)))
2547 (lambda ()
2548 (or (get-text-property (point) 'message-rank)
2549 10000))))
2551 (defun message-sort-headers ()
2552 "Sort the headers of the current message according to `message-header-format-alist'."
2553 (interactive)
2554 (save-excursion
2555 (save-restriction
2556 (let ((max (1+ (length message-header-format-alist)))
2557 rank)
2558 (message-narrow-to-headers)
2559 (while (re-search-forward "^[^ \n]+:" nil t)
2560 (put-text-property
2561 (match-beginning 0) (1+ (match-beginning 0))
2562 'message-rank
2563 (if (setq rank (length (memq (assq (intern (buffer-substring
2564 (match-beginning 0)
2565 (1- (match-end 0))))
2566 message-header-format-alist)
2567 message-header-format-alist)))
2568 (- max rank)
2569 (1+ max)))))
2570 (message-sort-headers-1))))
2572 (defun message-kill-address ()
2573 "Kill the address under point."
2574 (interactive)
2575 (let ((start (point)))
2576 (message-skip-to-next-address)
2577 (kill-region start (if (bolp) (1- (point)) (point)))))
2580 (autoload 'Info-goto-node "info")
2581 (defvar mml2015-use)
2583 (defun message-info (&optional arg)
2584 "Display the Message manual.
2586 Prefixed with one \\[universal-argument], display the Emacs MIME
2587 manual. With two \\[universal-argument]'s, display the EasyPG or
2588 PGG manual, depending on the value of `mml2015-use'."
2589 (interactive "p")
2590 (info (format "(%s)Top"
2591 (cond ((eq arg 16)
2592 (require 'mml2015)
2593 mml2015-use)
2594 ((eq arg 4) 'emacs-mime)
2595 ((and (not (booleanp arg))
2596 (symbolp arg))
2597 arg)
2599 'message)))))
2601 (defun message-all-recipients ()
2602 "Return a list of all recipients in the message, looking at TO, Cc and Bcc.
2604 Each recipient is in the format of `mail-extract-address-components'."
2605 (mapcan (lambda (header)
2606 (let ((header-value (message-fetch-field header)))
2607 (and
2608 header-value
2609 (mail-extract-address-components header-value t))))
2610 '("To" "Cc" "Bcc")))
2612 (defun message-all-epg-keys-available-p ()
2613 "Return non-nil if the pgp keyring has a public key for each recipient."
2614 (require 'epa)
2615 (let ((context (epg-make-context epa-protocol)))
2616 (catch 'break
2617 (dolist (recipient (message-all-recipients))
2618 (let ((recipient-email (cadr recipient)))
2619 (when (and recipient-email (not (epg-list-keys context recipient-email)))
2620 (throw 'break nil))))
2621 t)))
2623 (defun message-sign-encrypt-if-all-keys-available ()
2624 "Add MML tag to encrypt message when there is a key for each recipient.
2626 Consider adding this function to `message-send-hook' to
2627 systematically send encrypted emails when possible."
2628 (when (message-all-epg-keys-available-p)
2629 (mml-secure-message-sign-encrypt)))
2634 ;;; Message mode
2637 ;;; Set up keymap.
2639 (defvar message-mode-map nil)
2641 (unless message-mode-map
2642 (setq message-mode-map (make-keymap))
2643 (set-keymap-parent message-mode-map text-mode-map)
2644 (define-key message-mode-map "\C-c?" 'describe-mode)
2646 (define-key message-mode-map "\C-c\C-f\C-t" 'message-goto-to)
2647 (define-key message-mode-map "\C-c\C-f\C-o" 'message-goto-from)
2648 (define-key message-mode-map "\C-c\C-f\C-b" 'message-goto-bcc)
2649 (define-key message-mode-map "\C-c\C-f\C-w" 'message-goto-fcc)
2650 (define-key message-mode-map "\C-c\C-f\C-c" 'message-goto-cc)
2651 (define-key message-mode-map "\C-c\C-f\C-s" 'message-goto-subject)
2652 (define-key message-mode-map "\C-c\C-f\C-r" 'message-goto-reply-to)
2653 (define-key message-mode-map "\C-c\C-f\C-n" 'message-goto-newsgroups)
2654 (define-key message-mode-map "\C-c\C-f\C-d" 'message-goto-distribution)
2655 (define-key message-mode-map "\C-c\C-f\C-f" 'message-goto-followup-to)
2656 (define-key message-mode-map "\C-c\C-f\C-m" 'message-goto-mail-followup-to)
2657 (define-key message-mode-map "\C-c\C-f\C-k" 'message-goto-keywords)
2658 (define-key message-mode-map "\C-c\C-f\C-u" 'message-goto-summary)
2659 (define-key message-mode-map "\C-c\C-f\C-i"
2660 'message-insert-or-toggle-importance)
2661 (define-key message-mode-map "\C-c\C-f\C-a"
2662 'message-generate-unsubscribed-mail-followup-to)
2664 ;; modify headers (and insert notes in body)
2665 (define-key message-mode-map "\C-c\C-fs" 'message-change-subject)
2667 (define-key message-mode-map "\C-c\C-fx" 'message-cross-post-followup-to)
2668 ;; prefix+message-cross-post-followup-to = same w/o cross-post
2669 (define-key message-mode-map "\C-c\C-ft" 'message-reduce-to-to-cc)
2670 (define-key message-mode-map "\C-c\C-fa" 'message-add-archive-header)
2671 ;; mark inserted text
2672 (define-key message-mode-map "\C-c\M-m" 'message-mark-inserted-region)
2673 (define-key message-mode-map "\C-c\M-f" 'message-mark-insert-file)
2675 (define-key message-mode-map "\C-c\C-b" 'message-goto-body)
2676 (define-key message-mode-map "\C-c\C-i" 'message-goto-signature)
2678 (define-key message-mode-map "\C-c\C-t" 'message-insert-to)
2679 (define-key message-mode-map "\C-c\C-fw" 'message-insert-wide-reply)
2680 (define-key message-mode-map "\C-c\C-n" 'message-insert-newsgroups)
2681 (define-key message-mode-map "\C-c\C-l" 'message-to-list-only)
2682 (define-key message-mode-map "\C-c\C-f\C-e" 'message-insert-expires)
2684 (define-key message-mode-map "\C-c\C-u" 'message-insert-or-toggle-importance)
2685 (define-key message-mode-map "\C-c\M-n"
2686 'message-insert-disposition-notification-to)
2688 (define-key message-mode-map "\C-c\C-y" 'message-yank-original)
2689 (define-key message-mode-map "\C-c\M-\C-y" 'message-yank-buffer)
2690 (define-key message-mode-map "\C-c\C-q" 'message-fill-yanked-message)
2691 (define-key message-mode-map "\C-c\C-w" 'message-insert-signature)
2692 (define-key message-mode-map "\C-c\M-h" 'message-insert-headers)
2693 (define-key message-mode-map "\C-c\C-r" 'message-caesar-buffer-body)
2694 (define-key message-mode-map "\C-c\C-o" 'message-sort-headers)
2695 (define-key message-mode-map "\C-c\M-r" 'message-rename-buffer)
2697 (define-key message-mode-map "\C-c\C-c" 'message-send-and-exit)
2698 (define-key message-mode-map "\C-c\C-s" 'message-send)
2699 (define-key message-mode-map "\C-c\C-k" 'message-kill-buffer)
2700 (define-key message-mode-map "\C-c\C-d" 'message-dont-send)
2701 (define-key message-mode-map "\C-c\n" 'gnus-delay-article)
2703 (define-key message-mode-map "\C-c\M-k" 'message-kill-address)
2704 (define-key message-mode-map "\C-c\C-e" 'message-elide-region)
2705 (define-key message-mode-map "\C-c\C-v" 'message-delete-not-region)
2706 (define-key message-mode-map "\C-c\C-z" 'message-kill-to-signature)
2707 (define-key message-mode-map "\M-\r" 'message-newline-and-reformat)
2708 (define-key message-mode-map [remap split-line] 'message-split-line)
2710 (define-key message-mode-map "\C-c\C-a" 'mml-attach-file)
2712 (define-key message-mode-map "\C-a" 'message-beginning-of-line)
2713 (define-key message-mode-map "\t" 'message-tab)
2715 (define-key message-mode-map "\M-n" 'message-display-abbrev))
2717 (easy-menu-define
2718 message-mode-menu message-mode-map "Message Menu."
2719 `("Message"
2720 ["Yank Original" message-yank-original message-reply-buffer]
2721 ["Fill Yanked Message" message-fill-yanked-message t]
2722 ["Insert Signature" message-insert-signature t]
2723 ["Caesar (rot13) Message" message-caesar-buffer-body t]
2724 ["Caesar (rot13) Region" message-caesar-region (message-mark-active-p)]
2725 ["Elide Region" message-elide-region
2726 :active (message-mark-active-p)
2727 :help "Replace text in region with an ellipsis"]
2728 ["Delete Outside Region" message-delete-not-region
2729 :active (message-mark-active-p)
2730 :help "Delete all quoted text outside region"]
2731 ["Kill To Signature" message-kill-to-signature t]
2732 ["Newline and Reformat" message-newline-and-reformat t]
2733 ["Rename buffer" message-rename-buffer t]
2734 ["Spellcheck" ispell-message :help "Spellcheck this message"]
2735 "----"
2736 ["Insert Region Marked" message-mark-inserted-region
2737 :active (message-mark-active-p) :help "Mark region with enclosing tags"]
2738 ["Insert File Marked..." message-mark-insert-file
2739 :help "Insert file at point marked with enclosing tags"]
2740 "----"
2741 ["Send Message" message-send-and-exit :help "Send this message"]
2742 ["Postpone Message" message-dont-send
2743 :help "File this draft message and exit"]
2744 ["Send at Specific Time..." gnus-delay-article
2745 :help "Ask, then arrange to send message at that time"]
2746 ["Kill Message" message-kill-buffer
2747 :help "Delete this message without sending"]
2748 "----"
2749 ["Message manual" message-info :help "Display the Message manual"]))
2751 (easy-menu-define
2752 message-mode-field-menu message-mode-map ""
2753 `("Field"
2754 ["To" message-goto-to t]
2755 ["From" message-goto-from t]
2756 ["Subject" message-goto-subject t]
2757 ["Change subject..." message-change-subject t]
2758 ["Cc" message-goto-cc t]
2759 ["Bcc" message-goto-bcc t]
2760 ["Fcc" message-goto-fcc t]
2761 ["Reply-To" message-goto-reply-to t]
2762 ["Flag As Important" message-insert-importance-high
2763 :help "Mark this message as important"]
2764 ["Flag As Unimportant" message-insert-importance-low
2765 :help "Mark this message as unimportant"]
2766 ["Request Receipt"
2767 message-insert-disposition-notification-to
2768 :help "Request a receipt notification"]
2769 "----"
2770 ;; (typical) news stuff
2771 ["Summary" message-goto-summary t]
2772 ["Keywords" message-goto-keywords t]
2773 ["Newsgroups" message-goto-newsgroups t]
2774 ["Fetch Newsgroups" message-insert-newsgroups t]
2775 ["Followup-To" message-goto-followup-to t]
2776 ;; ["Followup-To (with note in body)" message-cross-post-followup-to t]
2777 ["Crosspost / Followup-To..." message-cross-post-followup-to t]
2778 ["Distribution" message-goto-distribution t]
2779 ["Expires" message-insert-expires t ]
2780 ["X-No-Archive" message-add-archive-header t ]
2781 "----"
2782 ;; (typical) mailing-lists stuff
2783 ["Fetch To" message-insert-to
2784 :help "Insert a To header that points to the author."]
2785 ["Fetch To and Cc" message-insert-wide-reply
2786 :help "Insert To and Cc headers as if you were doing a wide reply."]
2787 "----"
2788 ["Send to list only" message-to-list-only t]
2789 ["Mail-Followup-To" message-goto-mail-followup-to t]
2790 ["Unsubscribed list post" message-generate-unsubscribed-mail-followup-to
2791 :help "Insert a reasonable `Mail-Followup-To:' header."]
2792 ["Reduce To: to Cc:" message-reduce-to-to-cc t]
2793 "----"
2794 ["Sort Headers" message-sort-headers t]
2795 ["Encode non-ASCII domain names" message-idna-to-ascii-rhs t]
2796 ;; We hide `message-hidden-headers' by narrowing the buffer.
2797 ["Show Hidden Headers" widen t]
2798 ["Goto Body" message-goto-body t]
2799 ["Goto Signature" message-goto-signature t]))
2801 (defvar message-tool-bar-map nil)
2803 (defvar facemenu-add-face-function)
2804 (defvar facemenu-remove-face-function)
2806 ;;; Forbidden properties
2808 ;; We use `after-change-functions' to keep special text properties
2809 ;; that interfere with the normal function of message mode out of the
2810 ;; buffer.
2812 (defcustom message-strip-special-text-properties t
2813 "Strip special properties from the message buffer.
2815 Emacs has a number of special text properties which can break message
2816 composing in various ways. If this option is set, message will strip
2817 these properties from the message composition buffer. However, some
2818 packages requires these properties to be present in order to work.
2819 If you use one of these packages, turn this option off, and hope the
2820 message composition doesn't break too bad."
2821 :version "22.1"
2822 :group 'message-various
2823 :link '(custom-manual "(message)Various Message Variables")
2824 :type 'boolean)
2826 (defvar message-forbidden-properties
2827 ;; No reason this should be clutter up customize. We make it a
2828 ;; property list (rather than a list of property symbols), to be
2829 ;; directly useful for `remove-text-properties'.
2830 '(field nil read-only nil invisible nil intangible nil
2831 mouse-face nil modification-hooks nil insert-in-front-hooks nil
2832 insert-behind-hooks nil point-entered nil point-left nil)
2833 ;; Other special properties:
2834 ;; category, face, display: probably doesn't do any harm.
2835 ;; fontified: is used by font-lock.
2836 ;; syntax-table, local-map: I dunno.
2837 "Property list of with properties forbidden in message buffers.
2838 The values of the properties are ignored, only the property names are used.")
2840 (defun message-tamago-not-in-use-p (pos)
2841 "Return t when tamago version 4 is not in use at the cursor position.
2842 Tamago version 4 is a popular input method for writing Japanese text.
2843 It uses the properties `intangible', `invisible', `modification-hooks'
2844 and `read-only' when translating ascii or kana text to kanji text.
2845 These properties are essential to work, so we should never strip them."
2846 (not (and (boundp 'egg-modefull-mode)
2847 (symbol-value 'egg-modefull-mode)
2848 (or (memq (get-text-property pos 'intangible)
2849 '(its-part-1 its-part-2))
2850 (get-text-property pos 'egg-end)
2851 (get-text-property pos 'egg-lang)
2852 (get-text-property pos 'egg-start)))))
2854 (defsubst message-mail-alias-type-p (type)
2855 (if (atom message-mail-alias-type)
2856 (eq message-mail-alias-type type)
2857 (memq type message-mail-alias-type)))
2859 (defun message-strip-forbidden-properties (begin end &optional _old-length)
2860 "Strip forbidden properties between BEGIN and END, ignoring the third arg.
2861 This function is intended to be called from `after-change-functions'.
2862 See also `message-forbidden-properties'."
2863 (when (and (message-mail-alias-type-p 'ecomplete)
2864 (memq this-command message-self-insert-commands))
2865 (message-display-abbrev))
2866 (when (and message-strip-special-text-properties
2867 (message-tamago-not-in-use-p begin))
2868 (let ((inhibit-read-only t))
2869 (remove-text-properties begin end message-forbidden-properties))))
2871 (defvar message-smileys '(":-)" ":)"
2872 ":-(" ":("
2873 ";-)" ";)")
2874 "A list of recognized smiley faces in `message-mode'.")
2876 (defun message--syntax-propertize (beg end)
2877 "Syntax-propertize certain message text specially."
2878 (let ((citation-regexp (concat "^" message-cite-prefix-regexp ".*$"))
2879 (smiley-regexp (regexp-opt message-smileys)))
2880 (goto-char beg)
2881 (while (search-forward-regexp citation-regexp
2882 end 'noerror)
2883 (let ((start (match-beginning 0))
2884 (end (match-end 0)))
2885 (add-text-properties start (1+ start)
2886 `(syntax-table ,(string-to-syntax "<")))
2887 (add-text-properties end (min (1+ end) (point-max))
2888 `(syntax-table ,(string-to-syntax ">")))))
2889 (goto-char beg)
2890 (while (search-forward-regexp smiley-regexp
2891 end 'noerror)
2892 (add-text-properties (match-beginning 0) (match-end 0)
2893 `(syntax-table ,(string-to-syntax "."))))))
2895 ;;;###autoload
2896 (define-derived-mode message-mode text-mode "Message"
2897 "Major mode for editing mail and news to be sent.
2898 Like Text Mode but with these additional commands:\\<message-mode-map>
2899 C-c C-s `message-send' (send the message) C-c C-c `message-send-and-exit'
2900 C-c C-d Postpone sending the message C-c C-k Kill the message
2901 C-c C-f move to a header field (and create it if there isn't):
2902 C-c C-f C-t move to To C-c C-f C-s move to Subject
2903 C-c C-f C-c move to Cc C-c C-f C-b move to Bcc
2904 C-c C-f C-w move to Fcc C-c C-f C-r move to Reply-To
2905 C-c C-f C-u move to Summary C-c C-f C-n move to Newsgroups
2906 C-c C-f C-k move to Keywords C-c C-f C-d move to Distribution
2907 C-c C-f C-o move to From (\"Originator\")
2908 C-c C-f C-f move to Followup-To
2909 C-c C-f C-m move to Mail-Followup-To
2910 C-c C-f C-e move to Expires
2911 C-c C-f C-i cycle through Importance values
2912 C-c C-f s change subject and append \"(was: <Old Subject>)\"
2913 C-c C-f x crossposting with FollowUp-To header and note in body
2914 C-c C-f t replace To: header with contents of Cc: or Bcc:
2915 C-c C-f a Insert X-No-Archive: header and a note in the body
2916 C-c C-t `message-insert-to' (add a To header to a news followup)
2917 C-c C-l `message-to-list-only' (removes all but list address in to/cc)
2918 C-c C-n `message-insert-newsgroups' (add a Newsgroup header to a news reply)
2919 C-c C-b `message-goto-body' (move to beginning of message text).
2920 C-c C-i `message-goto-signature' (move to the beginning of the signature).
2921 C-c C-w `message-insert-signature' (insert `message-signature-file' file).
2922 C-c C-y `message-yank-original' (insert current message, if any).
2923 C-c C-q `message-fill-yanked-message' (fill what was yanked).
2924 C-c C-e `message-elide-region' (elide the text between point and mark).
2925 C-c C-v `message-delete-not-region' (remove the text outside the region).
2926 C-c C-z `message-kill-to-signature' (kill the text up to the signature).
2927 C-c C-r `message-caesar-buffer-body' (rot13 the message body).
2928 C-c C-a `mml-attach-file' (attach a file as MIME).
2929 C-c C-u `message-insert-or-toggle-importance' (insert or cycle importance).
2930 C-c M-n `message-insert-disposition-notification-to' (request receipt).
2931 C-c M-m `message-mark-inserted-region' (mark region with enclosing tags).
2932 C-c M-f `message-mark-insert-file' (insert file marked with enclosing tags).
2933 M-RET `message-newline-and-reformat' (break the line and reformat)."
2934 (set (make-local-variable 'message-reply-buffer) nil)
2935 (set (make-local-variable 'message-inserted-headers) nil)
2936 (set (make-local-variable 'message-send-actions) nil)
2937 (set (make-local-variable 'message-return-action) nil)
2938 (set (make-local-variable 'message-exit-actions) nil)
2939 (set (make-local-variable 'message-kill-actions) nil)
2940 (set (make-local-variable 'message-postpone-actions) nil)
2941 (set (make-local-variable 'message-draft-article) nil)
2942 (setq buffer-offer-save t)
2943 (set (make-local-variable 'facemenu-add-face-function)
2944 (lambda (face end)
2945 (let ((face-fun (cdr (assq face message-face-alist))))
2946 (if face-fun
2947 (funcall face-fun (point) end)
2948 (error "Face %s not configured for %s mode" face mode-name)))
2949 ""))
2950 (set (make-local-variable 'facemenu-remove-face-function) t)
2951 (set (make-local-variable 'message-reply-headers) nil)
2952 (make-local-variable 'message-newsreader)
2953 (make-local-variable 'message-mailer)
2954 (make-local-variable 'message-post-method)
2955 (set (make-local-variable 'message-sent-message-via) nil)
2956 (set (make-local-variable 'message-checksum) nil)
2957 (set (make-local-variable 'message-mime-part) 0)
2958 (message-setup-fill-variables)
2959 (when message-fill-column
2960 (setq fill-column message-fill-column)
2961 (turn-on-auto-fill))
2962 ;; Allow using comment commands to add/remove quoting.
2963 ;; (set (make-local-variable 'comment-start) message-yank-prefix)
2964 (when message-yank-prefix
2965 (set (make-local-variable 'comment-start) message-yank-prefix)
2966 (set (make-local-variable 'comment-start-skip)
2967 (concat "^" (regexp-quote message-yank-prefix) "[ \t]*")))
2968 (set (make-local-variable 'font-lock-defaults)
2969 '(message-font-lock-keywords t))
2970 (if (boundp 'tool-bar-map)
2971 (set (make-local-variable 'tool-bar-map) (message-make-tool-bar)))
2972 (easy-menu-add message-mode-menu message-mode-map)
2973 (easy-menu-add message-mode-field-menu message-mode-map)
2974 ;; Mmmm... Forbidden properties...
2975 (add-hook 'after-change-functions #'message-strip-forbidden-properties
2976 nil 'local)
2977 ;; Allow mail alias things.
2978 (cond
2979 ((message-mail-alias-type-p 'abbrev)
2980 (mail-abbrevs-setup))
2981 ((message-mail-alias-type-p 'ecomplete)
2982 (ecomplete-setup)))
2983 ;; FIXME: merge the completion tables from ecomplete/bbdb/...?
2984 ;;(add-hook 'completion-at-point-functions #'message-ecomplete-capf nil t)
2985 (add-hook 'completion-at-point-functions #'message-completion-function nil t)
2986 (unless buffer-file-name
2987 (message-set-auto-save-file-name))
2988 (unless (buffer-base-buffer)
2989 ;; Don't enable multibyte on an indirect buffer. Maybe enabling
2990 ;; multibyte is not necessary at all. -- zsh
2991 (mm-enable-multibyte))
2992 (set (make-local-variable 'indent-tabs-mode) nil) ;No tabs for indentation.
2993 (mml-mode)
2994 ;; Syntactic fontification. Helps `show-paren-mode',
2995 ;; `electric-pair-mode', and C-M-* navigation by syntactically
2996 ;; excluding citations and other artifacts.
2998 (set (make-local-variable 'syntax-propertize-function) 'message--syntax-propertize)
2999 (set (make-local-variable 'parse-sexp-ignore-comments) t))
3001 (defun message-setup-fill-variables ()
3002 "Setup message fill variables."
3003 (set (make-local-variable 'fill-paragraph-function)
3004 'message-fill-paragraph)
3005 (make-local-variable 'paragraph-separate)
3006 (make-local-variable 'paragraph-start)
3007 (make-local-variable 'adaptive-fill-regexp)
3008 (make-local-variable 'adaptive-fill-first-line-regexp)
3009 (let ((quote-prefix-regexp
3010 ;; User should change message-cite-prefix-regexp if
3011 ;; message-yank-prefix is set to an abnormal value.
3012 (concat "\\(" message-cite-prefix-regexp "\\)[ \t]*")))
3013 (setq paragraph-start
3014 (concat
3015 (regexp-quote mail-header-separator) "$\\|"
3016 "[ \t]*$\\|" ; blank lines
3017 "-- $\\|" ; signature delimiter
3018 "---+$\\|" ; delimiters for forwarded messages
3019 page-delimiter "$\\|" ; spoiler warnings
3020 ".*wrote:$\\|" ; attribution lines
3021 quote-prefix-regexp "$\\|" ; empty lines in quoted text
3022 ; mml tags
3023 "<#!*/?\\(multipart\\|part\\|external\\|mml\\|secure\\)"))
3024 (setq paragraph-separate paragraph-start)
3025 (setq adaptive-fill-regexp
3026 (concat quote-prefix-regexp "\\|" adaptive-fill-regexp))
3027 (setq adaptive-fill-first-line-regexp
3028 (concat quote-prefix-regexp "\\|"
3029 adaptive-fill-first-line-regexp)))
3030 (setq-local auto-fill-inhibit-regexp nil)
3031 (setq-local normal-auto-fill-function 'message-do-auto-fill))
3036 ;;; Message mode commands
3039 ;;; Movement commands
3041 (defun message-goto-to ()
3042 "Move point to the To header."
3043 (interactive)
3044 (push-mark)
3045 (message-position-on-field "To"))
3047 (defun message-goto-from ()
3048 "Move point to the From header."
3049 (interactive)
3050 (push-mark)
3051 (message-position-on-field "From"))
3053 (defun message-goto-subject ()
3054 "Move point to the Subject header."
3055 (interactive)
3056 (push-mark)
3057 (message-position-on-field "Subject"))
3059 (defun message-goto-cc ()
3060 "Move point to the Cc header."
3061 (interactive)
3062 (push-mark)
3063 (message-position-on-field "Cc" "To"))
3065 (defun message-goto-bcc ()
3066 "Move point to the Bcc header."
3067 (interactive)
3068 (push-mark)
3069 (message-position-on-field "Bcc" "Cc" "To"))
3071 (defun message-goto-fcc ()
3072 "Move point to the Fcc header."
3073 (interactive)
3074 (push-mark)
3075 (message-position-on-field "Fcc" "To" "Newsgroups"))
3077 (defun message-goto-reply-to ()
3078 "Move point to the Reply-To header."
3079 (interactive)
3080 (push-mark)
3081 (message-position-on-field "Reply-To" "Subject"))
3083 (defun message-goto-newsgroups ()
3084 "Move point to the Newsgroups header."
3085 (interactive)
3086 (push-mark)
3087 (message-position-on-field "Newsgroups"))
3089 (defun message-goto-distribution ()
3090 "Move point to the Distribution header."
3091 (interactive)
3092 (push-mark)
3093 (message-position-on-field "Distribution"))
3095 (defun message-goto-followup-to ()
3096 "Move point to the Followup-To header."
3097 (interactive)
3098 (push-mark)
3099 (message-position-on-field "Followup-To" "Newsgroups"))
3101 (defun message-goto-mail-followup-to ()
3102 "Move point to the Mail-Followup-To header."
3103 (interactive)
3104 (push-mark)
3105 (message-position-on-field "Mail-Followup-To" "To"))
3107 (defun message-goto-keywords ()
3108 "Move point to the Keywords header."
3109 (interactive)
3110 (push-mark)
3111 (message-position-on-field "Keywords" "Subject"))
3113 (defun message-goto-summary ()
3114 "Move point to the Summary header."
3115 (interactive)
3116 (push-mark)
3117 (message-position-on-field "Summary" "Subject"))
3119 (define-obsolete-function-alias 'message-goto-body-1 'message-goto-body "27.1")
3120 (defun message-goto-body (&optional interactive)
3121 "Move point to the beginning of the message body.
3122 Returns point."
3123 (interactive "p")
3124 (when interactive
3125 (when (looking-at "[ \t]*\n")
3126 (expand-abbrev))
3127 (push-mark))
3128 (goto-char (point-min))
3129 (or (search-forward (concat "\n" mail-header-separator "\n") nil t)
3130 ;; If the message is mangled, find the end of the headers the
3131 ;; hard way.
3132 (progn
3133 ;; Skip past all headers and continuation lines.
3134 (while (looking-at "[^\t\n :]+:\\|[\t ]+[^\t\n ]")
3135 (forward-line 1))
3136 ;; We're now at the first empty line, so perhaps move past it.
3137 (when (and (eolp)
3138 (not (eobp)))
3139 (forward-line 1))
3140 (point))))
3142 (defun message-in-body-p ()
3143 "Return t if point is in the message body."
3144 (>= (point)
3145 (save-excursion
3146 (message-goto-body))))
3148 (defun message-goto-eoh (&optional interactive)
3149 "Move point to the end of the headers."
3150 (interactive "p")
3151 (message-goto-body interactive)
3152 (forward-line -1))
3154 (defun message-goto-signature ()
3155 "Move point to the beginning of the message signature.
3156 If there is no signature in the article, go to the end and
3157 return nil."
3158 (interactive)
3159 (push-mark)
3160 (goto-char (point-min))
3161 (if (re-search-forward message-signature-separator nil t)
3162 (forward-line 1)
3163 (goto-char (point-max))
3164 nil))
3166 (defun message-generate-unsubscribed-mail-followup-to (&optional include-cc)
3167 "Insert a reasonable MFT header in a post to an unsubscribed list.
3168 When making original posts to a mailing list you are not subscribed to,
3169 you have to type in a MFT header by hand. The contents, usually, are
3170 the addresses of the list and your own address. This function inserts
3171 such a header automatically. It fetches the contents of the To: header
3172 in the current mail buffer, and appends the current `user-mail-address'.
3174 If the optional argument INCLUDE-CC is non-nil, the addresses in the
3175 Cc: header are also put into the MFT."
3177 (interactive "P")
3178 (let* (cc tos)
3179 (save-restriction
3180 (message-narrow-to-headers)
3181 (message-remove-header "Mail-Followup-To")
3182 (setq cc (and include-cc (message-fetch-field "Cc")))
3183 (setq tos (if cc
3184 (concat (message-fetch-field "To") "," cc)
3185 (message-fetch-field "To"))))
3186 (message-goto-mail-followup-to)
3187 (insert (concat tos ", " user-mail-address))))
3191 (defun message-insert-to (&optional force)
3192 "Insert a To header that points to the author of the article being replied to.
3193 If the original author requested not to be sent mail, don't insert unless the
3194 prefix FORCE is given."
3195 (interactive "P")
3196 (let* ((mct (message-fetch-reply-field "mail-copies-to"))
3197 (dont (and mct (or (equal (downcase mct) "never")
3198 (equal (downcase mct) "nobody"))))
3199 (to (or (message-fetch-reply-field "mail-reply-to")
3200 (message-fetch-reply-field "reply-to")
3201 (message-fetch-reply-field "from"))))
3202 (when (and dont to)
3203 (message
3204 (if force
3205 "Ignoring the user request not to have copies sent via mail"
3206 "Complying with the user request not to have copies sent via mail")))
3207 (when (and force (not to))
3208 (error "No mail address in the article"))
3209 (when (and to (or force (not dont)))
3210 (message-carefully-insert-headers (list (cons 'To to))))))
3212 (defun message-insert-wide-reply ()
3213 "Insert To and Cc headers as if you were doing a wide reply."
3214 (interactive)
3215 (let ((headers (message-with-reply-buffer
3216 (message-get-reply-headers t))))
3217 (message-carefully-insert-headers headers)))
3219 (defcustom message-header-synonyms
3220 '((To Cc Bcc)
3221 (Original-To))
3222 "List of lists of header synonyms.
3223 E.g., if this list contains a member list with elements `Cc' and `To',
3224 then `message-carefully-insert-headers' will not insert a `To' header
3225 when the message is already `Cc'ed to the recipient."
3226 :version "22.1"
3227 :group 'message-headers
3228 :link '(custom-manual "(message)Message Headers")
3229 :type '(repeat sexp))
3231 (defun message-carefully-insert-headers (headers)
3232 "Insert the HEADERS, an alist, into the message buffer.
3233 Does not insert the headers when they are already present there
3234 or in the synonym headers, defined by `message-header-synonyms'."
3235 ;; FIXME: Should compare only the address and not the full name. Comparison
3236 ;; should be done case-folded (and with `string=' rather than
3237 ;; `string-match').
3238 ;; (mail-strip-quoted-names "Foo Bar <foo@bar>, bla@fasel (Bla Fasel)")
3239 (dolist (header headers)
3240 (let* ((header-name (symbol-name (car header)))
3241 (new-header (cdr header))
3242 (synonyms (cl-loop for synonym in message-header-synonyms
3243 when (memq (car header) synonym) return synonym))
3244 (old-header
3245 (cl-loop for synonym in synonyms
3246 for old-header = (mail-fetch-field (symbol-name synonym))
3247 when (and old-header (string-match new-header old-header))
3248 return synonym)))
3249 (if old-header
3250 (message "already have `%s' in `%s'" new-header old-header)
3251 (when (and (message-position-on-field header-name)
3252 (setq old-header (mail-fetch-field header-name))
3253 (not (string-match "\\` *\\'" old-header)))
3254 (insert ", "))
3255 (insert new-header)))))
3257 (defun message-widen-reply ()
3258 "Widen the reply to include maximum recipients."
3259 (interactive)
3260 (let ((follow-to
3261 (and (bufferp message-reply-buffer)
3262 (buffer-name message-reply-buffer)
3263 (with-current-buffer message-reply-buffer
3264 (message-get-reply-headers t)))))
3265 (save-excursion
3266 (save-restriction
3267 (message-narrow-to-headers)
3268 (dolist (elem follow-to)
3269 (message-remove-header (symbol-name (car elem)))
3270 (goto-char (point-min))
3271 (insert (symbol-name (car elem)) ": "
3272 (cdr elem) "\n"))))))
3274 (defun message-insert-newsgroups ()
3275 "Insert the Newsgroups header from the article being replied to."
3276 (interactive)
3277 (let ((old-newsgroups (mail-fetch-field "newsgroups"))
3278 (new-newsgroups (message-fetch-reply-field "newsgroups"))
3279 (first t)
3280 insert-newsgroups)
3281 (message-position-on-field "Newsgroups")
3282 (cond
3283 ((not new-newsgroups)
3284 (error "No Newsgroups to insert"))
3285 ((not old-newsgroups)
3286 (insert new-newsgroups))
3288 (setq new-newsgroups (split-string new-newsgroups "[, ]+")
3289 old-newsgroups (split-string old-newsgroups "[, ]+"))
3290 (dolist (group new-newsgroups)
3291 (unless (member group old-newsgroups)
3292 (push group insert-newsgroups)))
3293 (if (null insert-newsgroups)
3294 (error "Newgroup%s already in the header"
3295 (if (> (length new-newsgroups) 1)
3296 "s" ""))
3297 (when old-newsgroups
3298 (setq first nil))
3299 (dolist (group insert-newsgroups)
3300 (unless first
3301 (insert ","))
3302 (setq first nil)
3303 (insert group)))))))
3307 ;;; Various commands
3309 (defun message-delete-not-region (beg end)
3310 "Delete everything in the body of the current message outside of the region."
3311 (interactive "r")
3312 (let (citeprefix)
3313 (save-excursion
3314 (goto-char beg)
3315 ;; snarf citation prefix, if appropriate
3316 (unless (eq (point) (progn (beginning-of-line) (point)))
3317 (when (looking-at message-cite-prefix-regexp)
3318 (setq citeprefix (match-string 0))))
3319 (goto-char end)
3320 (delete-region (point) (if (not (message-goto-signature))
3321 (point)
3322 (forward-line -2)
3323 (point)))
3324 (insert "\n")
3325 (goto-char beg)
3326 (delete-region beg (progn (message-goto-body)
3327 (forward-line 2)
3328 (point)))
3329 (when citeprefix
3330 (insert citeprefix))))
3331 (when (message-goto-signature)
3332 (forward-line -2)))
3334 (defun message-kill-to-signature (&optional arg)
3335 "Kill all text up to the signature.
3336 If a numeric argument or prefix arg is given, leave that number
3337 of lines before the signature intact."
3338 (interactive "P")
3339 (save-excursion
3340 (save-restriction
3341 (let ((point (point)))
3342 (narrow-to-region point (point-max))
3343 (message-goto-signature)
3344 (unless (eobp)
3345 (if (and arg (numberp arg))
3346 (forward-line (- -1 arg))
3347 (end-of-line -1)))
3348 (unless (= point (point))
3349 (kill-region point (point))
3350 (unless (bolp)
3351 (insert "\n")))))))
3353 (defun message-newline-and-reformat (&optional arg not-break)
3354 "Insert four newlines, and then reformat if inside quoted text.
3355 Prefix arg means justify as well."
3356 (interactive (list (if current-prefix-arg 'full)))
3357 (unless (message-in-body-p)
3358 (error "This command only works in the body of the message"))
3359 (let (quoted point beg end leading-space bolp fill-paragraph-function)
3360 (setq point (point))
3361 (beginning-of-line)
3362 (setq beg (point))
3363 (setq bolp (= beg point))
3364 ;; Find first line of the paragraph.
3365 (if not-break
3366 (while (and (not (eobp))
3367 (not (looking-at message-cite-prefix-regexp))
3368 (looking-at paragraph-start))
3369 (forward-line 1)))
3370 ;; Find the prefix
3371 (when (looking-at message-cite-prefix-regexp)
3372 (setq quoted (match-string 0))
3373 (goto-char (match-end 0))
3374 (looking-at "[ \t]*")
3375 (setq leading-space (match-string 0)))
3376 (if (and quoted
3377 (not not-break)
3378 (not bolp)
3379 (< (- point beg) (length quoted)))
3380 ;; break inside the cite prefix.
3381 (setq quoted nil
3382 end nil))
3383 (if quoted
3384 (progn
3385 (forward-line 1)
3386 (while (and (not (eobp))
3387 (not (looking-at paragraph-separate))
3388 (looking-at message-cite-prefix-regexp)
3389 (equal quoted (match-string 0)))
3390 (goto-char (match-end 0))
3391 (looking-at "[ \t]*")
3392 (if (> (length leading-space) (length (match-string 0)))
3393 (setq leading-space (match-string 0)))
3394 (forward-line 1))
3395 (setq end (point))
3396 (goto-char beg)
3397 (while (and (if (bobp) nil (forward-line -1) t)
3398 (not (looking-at paragraph-start))
3399 (looking-at message-cite-prefix-regexp)
3400 (equal quoted (match-string 0)))
3401 (setq beg (point))
3402 (goto-char (match-end 0))
3403 (looking-at "[ \t]*")
3404 (if (> (length leading-space) (length (match-string 0)))
3405 (setq leading-space (match-string 0)))))
3406 (while (and (not (eobp))
3407 (not (looking-at paragraph-separate))
3408 (not (looking-at message-cite-prefix-regexp)))
3409 (forward-line 1))
3410 (setq end (point))
3411 (goto-char beg)
3412 (while (and (if (bobp) nil (forward-line -1) t)
3413 (not (looking-at paragraph-start))
3414 (not (looking-at message-cite-prefix-regexp)))
3415 (setq beg (point))))
3416 (goto-char point)
3417 (save-restriction
3418 (narrow-to-region beg end)
3419 (if not-break
3420 (setq point nil)
3421 (if bolp
3422 (newline)
3423 (newline)
3424 (newline))
3425 (setq point (point))
3426 ;; (newline 2) doesn't mark both newline's as hard, so call
3427 ;; newline twice. -jas
3428 (newline)
3429 (newline)
3430 (delete-region (point) (re-search-forward "[ \t]*"))
3431 (when (and quoted (not bolp))
3432 (insert quoted leading-space)))
3433 (undo-boundary)
3434 (if quoted
3435 (let* ((adaptive-fill-regexp
3436 (regexp-quote (concat quoted leading-space)))
3437 (adaptive-fill-first-line-regexp
3438 adaptive-fill-regexp ))
3439 (fill-paragraph arg))
3440 (fill-paragraph arg))
3441 (if point (goto-char point)))))
3443 (defun message-fill-paragraph (&optional arg)
3444 "Message specific function to fill a paragraph.
3445 This function is used as the value of `fill-paragraph-function' in
3446 Message buffers and is not meant to be called directly."
3447 (interactive (list (if current-prefix-arg 'full)))
3448 (if (message-point-in-header-p)
3449 (message-fill-field)
3450 (message-newline-and-reformat arg t))
3453 (defun message-point-in-header-p ()
3454 "Return t if point is in the header."
3455 (save-excursion
3456 (save-restriction
3457 (widen)
3458 (let ((bound (+ (point-at-eol) 1)) case-fold-search)
3459 (goto-char (point-min))
3460 (not (search-forward (concat "\n" mail-header-separator "\n")
3461 bound t))))))
3463 (defun message-do-auto-fill ()
3464 "Like `do-auto-fill', but don't fill in message header."
3465 (unless (message-point-in-header-p)
3466 (let ((paragraph-separate (default-value 'paragraph-separate)))
3467 (do-auto-fill))))
3469 (defun message-insert-signature (&optional force)
3470 "Insert a signature. See documentation for variable `message-signature'."
3471 (interactive (list 0))
3472 (let* ((signature
3473 (cond
3474 ((and (null message-signature)
3475 (eq force 0))
3476 (save-excursion
3477 (goto-char (point-max))
3478 (not (re-search-backward message-signature-separator nil t))))
3479 ((and (null message-signature)
3480 force)
3482 ((functionp message-signature)
3483 (funcall message-signature))
3484 ((listp message-signature)
3485 (eval message-signature))
3486 (t message-signature)))
3487 signature-file)
3488 (setq signature
3489 (cond ((stringp signature)
3490 signature)
3491 ((and (eq t signature) message-signature-file)
3492 (setq signature-file
3493 (if (and message-signature-directory
3494 ;; don't actually use the signature directory
3495 ;; if message-signature-file contains a path.
3496 (not (file-name-directory
3497 message-signature-file)))
3498 (expand-file-name message-signature-file
3499 message-signature-directory)
3500 message-signature-file))
3501 (file-exists-p signature-file))))
3502 (when signature
3503 (goto-char (point-max))
3504 ;; Insert the signature.
3505 (unless (bolp)
3506 (newline))
3507 (when message-signature-insert-empty-line
3508 (newline))
3509 (insert "-- ")
3510 (newline)
3511 (if (eq signature t)
3512 (insert-file-contents signature-file)
3513 (insert signature))
3514 (goto-char (point-max))
3515 (or (bolp) (newline)))))
3517 (defun message-insert-importance-high ()
3518 "Insert header to mark message as important."
3519 (interactive)
3520 (save-excursion
3521 (save-restriction
3522 (message-narrow-to-headers)
3523 (message-remove-header "Importance"))
3524 (message-goto-eoh)
3525 (insert "Importance: high\n")))
3527 (defun message-insert-importance-low ()
3528 "Insert header to mark message as unimportant."
3529 (interactive)
3530 (save-excursion
3531 (save-restriction
3532 (message-narrow-to-headers)
3533 (message-remove-header "Importance"))
3534 (message-goto-eoh)
3535 (insert "Importance: low\n")))
3537 (defun message-insert-or-toggle-importance ()
3538 "Insert a \"Importance: high\" header, or cycle through the header values.
3539 The three allowed values according to RFC 1327 are `high', `normal'
3540 and `low'."
3541 (interactive)
3542 (save-excursion
3543 (let ((new "high")
3544 cur)
3545 (save-restriction
3546 (message-narrow-to-headers)
3547 (when (setq cur (message-fetch-field "Importance"))
3548 (message-remove-header "Importance")
3549 (setq new (cond ((string= cur "high")
3550 "low")
3551 ((string= cur "low")
3552 "normal")
3554 "high")))))
3555 (message-goto-eoh)
3556 (insert (format "Importance: %s\n" new)))))
3558 (defun message-insert-disposition-notification-to ()
3559 "Request a disposition notification (return receipt) to this message.
3560 Note that this should not be used in newsgroups."
3561 (interactive)
3562 (save-excursion
3563 (save-restriction
3564 (message-narrow-to-headers)
3565 (message-remove-header "Disposition-Notification-To"))
3566 (message-goto-eoh)
3567 (insert (format "Disposition-Notification-To: %s\n"
3568 (or (message-field-value "Reply-To")
3569 (message-field-value "From")
3570 (message-make-from))))))
3572 (defun message-elide-region (b e)
3573 "Elide the text in the region.
3574 An ellipsis (from `message-elide-ellipsis') will be inserted where the
3575 text was killed."
3576 (interactive "r")
3577 (let ((lines (count-lines b e))
3578 (chars (- e b)))
3579 (kill-region b e)
3580 (insert (format-spec message-elide-ellipsis
3581 `((?l . ,lines)
3582 (?c . ,chars))))))
3584 (defvar message-caesar-translation-table nil)
3586 (defun message-caesar-region (b e &optional n)
3587 "Caesar rotate region B to E by N, default 13, for decrypting netnews."
3588 (interactive
3589 (list
3590 (min (point) (or (mark t) (point)))
3591 (max (point) (or (mark t) (point)))
3592 (when current-prefix-arg
3593 (prefix-numeric-value current-prefix-arg))))
3595 (setq n (if (numberp n) (mod n 26) 13)) ;canonize N
3596 (unless (or (zerop n) ; no action needed for a rot of 0
3597 (= b e)) ; no region to rotate
3598 ;; We build the table, if necessary.
3599 (when (or (not message-caesar-translation-table)
3600 (/= (aref message-caesar-translation-table ?a) (+ ?a n)))
3601 (setq message-caesar-translation-table
3602 (message-make-caesar-translation-table n)))
3603 (translate-region b e message-caesar-translation-table)))
3605 (defun message-make-caesar-translation-table (n)
3606 "Create a rot table with offset N."
3607 (let ((i -1)
3608 (table (make-string 256 0)))
3609 (while (< (cl-incf i) 256)
3610 (aset table i i))
3611 (concat
3612 (substring table 0 ?A)
3613 (substring table (+ ?A n) (+ ?A n (- 26 n)))
3614 (substring table ?A (+ ?A n))
3615 (substring table (+ ?A 26) ?a)
3616 (substring table (+ ?a n) (+ ?a n (- 26 n)))
3617 (substring table ?a (+ ?a n))
3618 (substring table (+ ?a 26) 255))))
3620 (defun message-caesar-buffer-body (&optional rotnum wide)
3621 "Caesar rotate all letters in the current buffer by 13 places.
3622 Used to encode/decode possibly offensive messages (commonly in rec.humor).
3623 With prefix arg, specifies the number of places to rotate each letter forward.
3624 Mail and USENET news headers are not rotated unless WIDE is non-nil."
3625 (interactive (if current-prefix-arg
3626 (list (prefix-numeric-value current-prefix-arg))
3627 (list nil)))
3628 (save-excursion
3629 (save-restriction
3630 (when (and (not wide) (message-goto-body))
3631 (narrow-to-region (point) (point-max)))
3632 (message-caesar-region (point-min) (point-max) rotnum))))
3634 (defun message-pipe-buffer-body (program)
3635 "Pipe the message body in the current buffer through PROGRAM."
3636 (save-excursion
3637 (save-restriction
3638 (when (message-goto-body)
3639 (narrow-to-region (point) (point-max)))
3640 (shell-command-on-region
3641 (point-min) (point-max) program nil t))))
3643 (defun message-rename-buffer (&optional enter-string)
3644 "Rename the *message* buffer to \"*message* RECIPIENT\".
3645 If the function is run with a prefix, it will ask for a new buffer
3646 name, rather than giving an automatic name."
3647 (interactive "Pbuffer name: ")
3648 (save-excursion
3649 (save-restriction
3650 (goto-char (point-min))
3651 (narrow-to-region (point)
3652 (search-forward mail-header-separator nil 'end))
3653 (let* ((mail-to (or
3654 (if (message-news-p) (message-fetch-field "Newsgroups")
3655 (message-fetch-field "To"))
3656 ""))
3657 (mail-trimmed-to
3658 (if (string-match "," mail-to)
3659 (concat (substring mail-to 0 (match-beginning 0)) ", ...")
3660 mail-to))
3661 (name-default (concat "*message* " mail-trimmed-to))
3662 (name (if enter-string
3663 (read-string "New buffer name: " name-default)
3664 name-default)))
3665 (rename-buffer name t)))))
3667 (defun message-fill-yanked-message (&optional justifyp)
3668 "Fill the paragraphs of a message yanked into this one.
3669 Numeric argument means justify as well."
3670 (interactive "P")
3671 (save-excursion
3672 (goto-char (point-min))
3673 (search-forward (concat "\n" mail-header-separator "\n") nil t)
3674 (let ((fill-prefix message-yank-prefix))
3675 (fill-individual-paragraphs (point) (point-max) justifyp))))
3677 (defun message-indent-citation (&optional start end yank-only)
3678 "Modify text just inserted from a message to be cited.
3679 The inserted text should be the region.
3680 When this function returns, the region is again around the modified text.
3682 Normally, indent each nonblank line `message-indentation-spaces' spaces.
3683 However, if `message-yank-prefix' is non-nil, insert that prefix on each line."
3684 (unless start (setq start (point)))
3685 (unless yank-only
3686 ;; Remove unwanted headers.
3687 (when message-ignored-cited-headers
3688 (let (all-removed)
3689 (save-restriction
3690 (narrow-to-region
3691 (goto-char start)
3692 (if (search-forward "\n\n" nil t)
3693 (1- (point))
3694 (point)))
3695 (message-remove-header message-ignored-cited-headers t)
3696 (when (= (point-min) (point-max))
3697 (setq all-removed t))
3698 (goto-char (point-max)))
3699 (if all-removed
3700 (goto-char start)
3701 (forward-line 1))))
3702 ;; Delete blank lines at the start of the buffer.
3703 (while (and (point-min)
3704 (eolp)
3705 (not (eobp)))
3706 (message-delete-line))
3707 ;; Delete blank lines at the end of the buffer.
3708 (goto-char (point-max))
3709 (unless (eq (preceding-char) ?\n)
3710 (insert "\n"))
3711 (while (and (zerop (forward-line -1))
3712 (looking-at "$"))
3713 (message-delete-line)))
3714 ;; Do the indentation.
3715 (if (null message-yank-prefix)
3716 (indent-rigidly start (or end (mark t)) message-indentation-spaces)
3717 (save-excursion
3718 (goto-char start)
3719 (while (< (point) (or end (mark t)))
3720 (cond ((looking-at ">")
3721 (insert message-yank-cited-prefix))
3722 ((looking-at "^$")
3723 (insert message-yank-empty-prefix))
3725 (insert message-yank-prefix)))
3726 (forward-line 1))))
3727 (goto-char start))
3729 (defun message-remove-blank-cited-lines (&optional remove)
3730 "Remove cited lines containing only blanks.
3731 If REMOVE is non-nil, remove newlines, too.
3733 To use this automatically, you may add this function to
3734 `gnus-message-setup-hook'."
3735 (interactive "P")
3736 (let ((citexp (concat "^\\("
3737 (concat message-yank-cited-prefix "\\|")
3738 message-yank-prefix
3739 "\\)+ *\n")))
3740 (message "Removing `%s'" citexp)
3741 (save-excursion
3742 (message-goto-body)
3743 (while (re-search-forward citexp nil t)
3744 (replace-match (if remove "" "\n"))))))
3746 (defun message--yank-original-internal (arg)
3747 (let ((modified (buffer-modified-p))
3748 body-text)
3749 (when (and message-reply-buffer
3750 message-cite-function)
3751 (when (equal message-cite-reply-position 'above)
3752 (save-excursion
3753 (setq body-text
3754 (buffer-substring (message-goto-body)
3755 (point-max)))
3756 (delete-region (message-goto-body) (point-max))))
3757 (if (bufferp message-reply-buffer)
3758 (delete-windows-on message-reply-buffer t))
3759 (push-mark (save-excursion
3760 (cond
3761 ((bufferp message-reply-buffer)
3762 (insert-buffer-substring message-reply-buffer))
3763 ((and (consp message-reply-buffer)
3764 (functionp (car message-reply-buffer)))
3765 (apply (car message-reply-buffer)
3766 (cdr message-reply-buffer))))
3767 (unless (bolp)
3768 (insert ?\n))
3769 (point)))
3770 (unless arg
3771 (funcall message-cite-function)
3772 (unless (eq (char-before (mark t)) ?\n)
3773 (let ((pt (point)))
3774 (goto-char (mark t))
3775 (insert-before-markers ?\n)
3776 (goto-char pt))))
3777 (pcase message-cite-reply-position
3778 ('above
3779 (message-goto-body)
3780 (insert body-text)
3781 (insert (if (bolp) "\n" "\n\n"))
3782 (message-goto-body))
3783 ('below
3784 (message-goto-signature)))
3785 ;; Add a `message-setup-very-last-hook' here?
3786 ;; Add `gnus-article-highlight-citation' here?
3787 (unless modified
3788 (setq message-checksum (message-checksum))))))
3790 (defun message-yank-original (&optional arg)
3791 "Insert the message being replied to, if any.
3792 Puts point before the text and mark after.
3793 Normally indents each nonblank line ARG spaces (default 3). However,
3794 if `message-yank-prefix' is non-nil, insert that prefix on each line.
3796 This function uses `message-cite-function' to do the actual citing.
3798 Just \\[universal-argument] as argument means don't indent, insert no
3799 prefix, and don't delete any headers."
3800 (interactive "P")
3801 ;; eval the let forms contained in message-cite-style
3802 (eval
3803 `(let ,(if (symbolp message-cite-style)
3804 (symbol-value message-cite-style)
3805 message-cite-style)
3806 (message--yank-original-internal ',arg))))
3808 (defun message-yank-buffer (buffer)
3809 "Insert BUFFER into the current buffer and quote it."
3810 (interactive "bYank buffer: ")
3811 (let ((message-reply-buffer (get-buffer buffer)))
3812 (save-window-excursion
3813 (message-yank-original))))
3815 (defun message-buffers ()
3816 "Return a list of active message buffers."
3817 (let (buffers)
3818 (save-current-buffer
3819 (dolist (buffer (buffer-list t))
3820 (set-buffer buffer)
3821 (when (and (derived-mode-p 'message-mode)
3822 (null message-sent-message-via))
3823 (push (buffer-name buffer) buffers))))
3824 (nreverse buffers)))
3826 (defun message-cite-original-1 (strip-signature)
3827 "Cite an original message.
3828 If STRIP-SIGNATURE is non-nil, strips off the signature from the
3829 original message.
3831 This function uses `mail-citation-hook' if that is non-nil."
3832 (if (and (boundp 'mail-citation-hook)
3833 mail-citation-hook)
3834 (run-hooks 'mail-citation-hook)
3835 (let* ((start (point))
3836 (end (mark t))
3837 (x-no-archive nil)
3838 (functions
3839 (when message-indent-citation-function
3840 (if (listp message-indent-citation-function)
3841 message-indent-citation-function
3842 (list message-indent-citation-function))))
3843 ;; This function may be called by `gnus-summary-yank-message' and
3844 ;; may insert a different article from the original. So, we will
3845 ;; modify the value of `message-reply-headers' with that article.
3846 (message-reply-headers
3847 (save-restriction
3848 (narrow-to-region start end)
3849 (message-narrow-to-head-1)
3850 (setq x-no-archive (message-fetch-field "x-no-archive"))
3851 (vector 0
3852 (or (message-fetch-field "subject") "none")
3853 (or (message-fetch-field "from") "nobody")
3854 (message-fetch-field "date")
3855 (message-fetch-field "message-id" t)
3856 (message-fetch-field "references")
3857 0 0 ""))))
3858 (mml-quote-region start end)
3859 (when strip-signature
3860 ;; Allow undoing.
3861 (undo-boundary)
3862 (goto-char end)
3863 (when (re-search-backward message-signature-separator start t)
3864 ;; Also peel off any blank lines before the signature.
3865 (forward-line -1)
3866 (while (looking-at "^[ \t]*$")
3867 (forward-line -1))
3868 (forward-line 1)
3869 (delete-region (point) end)
3870 (unless (search-backward "\n\n" start t)
3871 ;; Insert a blank line if it is peeled off.
3872 (insert "\n"))))
3873 (goto-char start)
3874 (mapc 'funcall functions)
3875 (when message-citation-line-function
3876 (unless (bolp)
3877 (insert "\n"))
3878 (funcall message-citation-line-function))
3879 (when (and x-no-archive
3880 (not message-cite-articles-with-x-no-archive)
3881 (string-match "yes" x-no-archive))
3882 (undo-boundary)
3883 (delete-region (point) (mark t))
3884 (insert "> [Quoted text removed due to X-No-Archive]\n")
3885 (push-mark)
3886 (forward-line -1)))))
3888 (defun message-cite-original ()
3889 "Cite function in the standard Message manner."
3890 (message-cite-original-1 nil))
3892 (autoload 'format-spec "format-spec")
3893 (autoload 'gnus-date-get-time "gnus-util")
3895 (defun message-insert-formatted-citation-line (&optional from date tz)
3896 "Function that inserts a formatted citation line.
3897 The optional FROM, and DATE are strings containing the contents of
3898 the From header and the Date header respectively.
3900 The optional TZ is omitted or nil for Emacs local time, t for
3901 Universal Time, `wall' for system wall clock time, or a string as
3902 in the TZ environment variable. It can also be a list (as from
3903 `current-time-zone') or an integer (as from `decode-time')
3904 applied without consideration for daylight saving time.
3906 See `message-citation-line-format'."
3907 ;; The optional args are for testing/debugging. They will disappear later.
3908 ;; Example:
3909 ;; (with-temp-buffer
3910 ;; (message-insert-formatted-citation-line
3911 ;; "John Doe <john.doe@example.invalid>"
3912 ;; (message-make-date))
3913 ;; (buffer-string))
3914 (when (or message-reply-headers (and from date))
3915 (unless from
3916 (setq from (mail-header-from message-reply-headers)))
3917 (let* ((data (condition-case ()
3918 (funcall (if (boundp 'gnus-extract-address-components)
3919 gnus-extract-address-components
3920 'mail-extract-address-components)
3921 from)
3922 (error nil)))
3923 (name (car data))
3924 (fname name)
3925 (lname name)
3926 (net (car (cdr data)))
3927 (name-or-net (or (car data)
3928 (car (cdr data)) from))
3929 (time
3930 (when (string-match "%[^fnNFL]" message-citation-line-format)
3931 (cond ((numberp (car-safe date)) date) ;; backward compatibility
3932 (date (gnus-date-get-time date))
3934 (gnus-date-get-time
3935 (setq date (mail-header-date message-reply-headers)))))))
3936 (tz (or tz
3937 (when (stringp date)
3938 (nth 8 (parse-time-string date)))))
3939 (flist
3940 (let ((i ?A) lst)
3941 (when (stringp name)
3942 ;; Guess first name and last name:
3943 (let* ((names (delq
3945 (mapcar
3946 (lambda (x)
3947 (if (string-match "\\`\\(\\w\\|[-.]\\)+\\'"
3950 nil))
3951 (split-string name "[ \t]+"))))
3952 (count (length names)))
3953 (cond ((= count 1)
3954 (setq fname (car names)
3955 lname ""))
3956 ((or (= count 2) (= count 3))
3957 (setq fname (car names)
3958 lname (mapconcat 'identity (cdr names) " ")))
3959 ((> count 3)
3960 (setq fname (mapconcat 'identity
3961 (butlast names (- count 2))
3962 " ")
3963 lname (mapconcat 'identity
3964 (nthcdr 2 names)
3965 " "))))
3966 (when (string-match "\\(.*\\),\\'" fname)
3967 (let ((newlname (match-string 1 fname)))
3968 (setq fname lname lname newlname)))))
3969 ;; The following letters are not used in `format-time-string':
3970 (push ?E lst) (push "<E>" lst)
3971 (push ?F lst) (push (or fname name-or-net) lst)
3972 ;; We might want to use "" instead of "<X>" later.
3973 (push ?J lst) (push "<J>" lst)
3974 (push ?K lst) (push "<K>" lst)
3975 (push ?L lst) (push lname lst)
3976 (push ?N lst) (push name-or-net lst)
3977 (push ?O lst) (push "<O>" lst)
3978 (push ?P lst) (push "<P>" lst)
3979 (push ?Q lst) (push "<Q>" lst)
3980 (push ?f lst) (push from lst)
3981 (push ?i lst) (push "<i>" lst)
3982 (push ?n lst) (push net lst)
3983 (push ?o lst) (push "<o>" lst)
3984 (push ?q lst) (push "<q>" lst)
3985 (push ?t lst) (push "<t>" lst)
3986 (push ?v lst) (push "<v>" lst)
3987 ;; Delegate the rest to `format-time-string':
3988 (while (<= i ?z)
3989 (when (and (not (memq i lst))
3990 ;; Skip (Z,a)
3991 (or (<= i ?Z)
3992 (>= i ?a)))
3993 (push i lst)
3994 (push (condition-case nil
3995 (format-time-string (format "%%%c" i) time tz)
3996 (error (format ">%c<" i)))
3997 lst))
3998 (setq i (1+ i)))
3999 (reverse lst)))
4000 (spec (apply 'format-spec-make flist)))
4001 (insert (format-spec message-citation-line-format spec)))
4002 (newline)))
4004 (defun message-cite-original-without-signature ()
4005 "Cite function in the standard Message manner.
4006 This function strips off the signature from the original message."
4007 (message-cite-original-1 t))
4009 (defun message-insert-citation-line ()
4010 "Insert a simple citation line."
4011 (when message-reply-headers
4012 (insert (mail-header-from message-reply-headers) " writes:")
4013 (newline)
4014 (newline)))
4016 (defun message-position-on-field (header &rest afters)
4017 (let ((case-fold-search t))
4018 (save-restriction
4019 (narrow-to-region
4020 (goto-char (point-min))
4021 (progn
4022 (re-search-forward
4023 (concat "^" (regexp-quote mail-header-separator) "$"))
4024 (match-beginning 0)))
4025 (goto-char (point-min))
4026 (if (re-search-forward (concat "^" (regexp-quote header) ":") nil t)
4027 (progn
4028 (re-search-forward "^[^ \t]" nil 'move)
4029 (beginning-of-line)
4030 (skip-chars-backward "\n")
4032 (while (and afters
4033 (not (re-search-forward
4034 (concat "^" (regexp-quote (car afters)) ":")
4035 nil t)))
4036 (pop afters))
4037 (when afters
4038 (re-search-forward "^[^ \t]" nil 'move)
4039 (beginning-of-line))
4040 (insert header ": \n")
4041 (forward-char -1)
4042 nil))))
4047 ;;; Sending messages
4050 (defun message-send-and-exit (&optional arg)
4051 "Send message like `message-send', then, if no errors, exit from mail buffer.
4052 The usage of ARG is defined by the instance that called Message.
4053 It should typically alter the sending method in some way or other."
4054 (interactive "P")
4055 (let ((buf (current-buffer))
4056 (actions message-exit-actions))
4057 (when (and (message-send arg)
4058 (buffer-name buf))
4059 (message-bury buf)
4060 (if message-kill-buffer-on-exit
4061 (kill-buffer buf))
4062 (message-do-actions actions)
4063 t)))
4065 (defun message-dont-send ()
4066 "Don't send the message you have been editing.
4067 Instead, just auto-save the buffer and then bury it."
4068 (interactive)
4069 (set-buffer-modified-p t)
4070 (save-buffer)
4071 (let ((actions message-postpone-actions))
4072 (message-bury (current-buffer))
4073 (message-do-actions actions)))
4075 (defun message-kill-buffer ()
4076 "Kill the current buffer."
4077 (interactive)
4078 (when (or (not (buffer-modified-p))
4079 (not message-kill-buffer-query)
4080 (yes-or-no-p "Message modified; kill anyway? "))
4081 (let ((actions message-kill-actions)
4082 (draft-article message-draft-article)
4083 (auto-save-file-name buffer-auto-save-file-name)
4084 (file-name buffer-file-name)
4085 (modified (buffer-modified-p)))
4086 (setq buffer-file-name nil)
4087 (kill-buffer (current-buffer))
4088 (when (and (or (and auto-save-file-name
4089 (file-exists-p auto-save-file-name))
4090 (and file-name
4091 (file-exists-p file-name)))
4092 (progn
4093 ;; If the message buffer has lived in a dedicated window,
4094 ;; `kill-buffer' has killed the frame. Thus the
4095 ;; `yes-or-no-p' may show up in a lowered frame. Make sure
4096 ;; that the user can see the question by raising the
4097 ;; current frame:
4098 (raise-frame)
4099 (yes-or-no-p (format "Remove the backup file%s? "
4100 (if modified " too" "")))))
4101 (ignore-errors
4102 (delete-file auto-save-file-name))
4103 (let ((message-draft-article draft-article))
4104 (message-disassociate-draft)))
4105 (message-do-actions actions))))
4107 (defun message-bury (buffer)
4108 "Bury this mail BUFFER."
4109 ;; Note that this is not quite the same as (bury-buffer buffer),
4110 ;; since bury-buffer does extra stuff with a nil argument.
4111 ;; Eg https://lists.gnu.org/r/emacs-devel/2014-01/msg00539.html
4112 (with-current-buffer buffer (bury-buffer))
4113 (if message-return-action
4114 (apply (car message-return-action) (cdr message-return-action))))
4116 (autoload 'mml-secure-bcc-is-safe "mml-sec")
4118 (defun message-send (&optional arg)
4119 "Send the message in the current buffer.
4120 If `message-interactive' is non-nil, wait for success indication or
4121 error messages, and inform user.
4122 Otherwise any failure is reported in a message back to the user from
4123 the mailer.
4124 The usage of ARG is defined by the instance that called Message.
4125 It should typically alter the sending method in some way or other."
4126 (interactive "P")
4127 ;; Make it possible to undo the coming changes.
4128 (undo-boundary)
4129 (let ((inhibit-read-only t))
4130 (put-text-property (point-min) (point-max) 'read-only nil))
4131 (message-fix-before-sending)
4132 (run-hooks 'message-send-hook)
4133 (mml-secure-bcc-is-safe)
4134 (when message-confirm-send
4135 (or (y-or-n-p "Send message? ")
4136 (keyboard-quit)))
4137 (message message-sending-message)
4138 (let ((alist message-send-method-alist)
4139 (success t)
4140 elem sent dont-barf-on-no-method
4141 (message-options message-options))
4142 (message-options-set-recipient)
4143 (while (and success
4144 (setq elem (pop alist)))
4145 (when (funcall (cadr elem))
4146 (when (and (or (not (memq (car elem)
4147 message-sent-message-via))
4148 (message-fetch-field "supersedes")
4149 (if (or (message-gnksa-enable-p 'multiple-copies)
4150 (not (eq (car elem) 'news)))
4151 (y-or-n-p
4152 (format
4153 "Already sent message via %s; resend? "
4154 (car elem)))
4155 (error "Denied posting -- multiple copies")))
4156 (setq success (funcall (caddr elem) arg)))
4157 (setq sent t))))
4158 (unless (or sent
4159 (not success)
4160 (let ((fcc (message-fetch-field "Fcc"))
4161 (gcc (message-fetch-field "Gcc")))
4162 (when (or fcc gcc)
4163 (or (eq message-allow-no-recipients 'always)
4164 (and (not (eq message-allow-no-recipients 'never))
4165 (setq dont-barf-on-no-method
4166 (y-or-n-p
4167 (format "No receiver, perform %s anyway? "
4168 (cond ((and fcc gcc) "Fcc and Gcc")
4169 (fcc "Fcc")
4170 (t "Gcc"))))))))))
4171 (error "No methods specified to send by"))
4172 (when (or dont-barf-on-no-method
4173 (and success sent))
4174 (message-do-fcc)
4175 (save-excursion
4176 (run-hooks 'message-sent-hook))
4177 (message "Sending...done")
4178 ;; Do ecomplete address snarfing.
4179 (when (and (message-mail-alias-type-p 'ecomplete)
4180 (not message-inhibit-ecomplete))
4181 (message-put-addresses-in-ecomplete))
4182 ;; Mark the buffer as unmodified and delete auto-save.
4183 (set-buffer-modified-p nil)
4184 (delete-auto-save-file-if-necessary t)
4185 (message-disassociate-draft)
4186 ;; Delete other mail buffers and stuff.
4187 (message-do-send-housekeeping)
4188 (message-do-actions message-send-actions)
4189 ;; Return success.
4190 t)))
4192 (defun message-send-via-mail (arg)
4193 "Send the current message via mail."
4194 (message-send-mail arg))
4196 (defun message-send-via-news (arg)
4197 "Send the current message via news."
4198 (funcall message-send-news-function arg))
4200 (defmacro message-check (type &rest forms)
4201 "Eval FORMS if TYPE is to be checked."
4202 `(or (message-check-element ,type)
4203 (save-excursion
4204 ,@forms)))
4206 (put 'message-check 'lisp-indent-function 1)
4207 (put 'message-check 'edebug-form-spec '(form body))
4209 (defun message-text-with-property (prop &optional start end reverse)
4210 "Return a list of start and end positions where the text has PROP.
4211 START and END bound the search, they default to `point-min' and
4212 `point-max' respectively. If REVERSE is non-nil, find text which does
4213 not have PROP."
4214 (unless start
4215 (setq start (point-min)))
4216 (unless end
4217 (setq end (point-max)))
4218 (let (next regions)
4219 (if reverse
4220 (while (and start
4221 (setq start (text-property-any start end prop nil)))
4222 (setq next (next-single-property-change start prop nil end))
4223 (push (cons start (or next end)) regions)
4224 (setq start next))
4225 (while (and start
4226 (or (get-text-property start prop)
4227 (and (setq start (next-single-property-change
4228 start prop nil end))
4229 (get-text-property start prop))))
4230 (setq next (text-property-any start end prop nil))
4231 (push (cons start (or next end)) regions)
4232 (setq start next)))
4233 (nreverse regions)))
4235 (defcustom message-bogus-addresses
4236 '("noreply" "nospam" "invalid" "@.*@" "[^[:ascii:]].*@" "[ \t]")
4237 "List of regexps of potentially bogus mail addresses.
4238 See `message-check-recipients' how to setup checking.
4240 This list should make it possible to catch typos or warn about
4241 spam-trap addresses. It doesn't aim to verify strict RFC
4242 conformance."
4243 :version "26.1" ; @@ -> @.*@
4244 :group 'message-headers
4245 :type '(choice
4246 (const :tag "None" nil)
4247 (list
4248 (set :inline t
4249 (const "noreply")
4250 (const "nospam")
4251 (const "invalid")
4252 (const :tag "duplicate @" "@.*@")
4253 (const :tag "non-ascii local part" "[^[:ascii:]].*@")
4254 (const :tag "`_' in domain part" "@.*_")
4255 (const :tag "whitespace" "[ \t]"))
4256 (repeat :inline t
4257 :tag "Other"
4258 (regexp)))))
4260 (defun message-fix-before-sending ()
4261 "Do various things to make the message nice before sending it."
4262 ;; Make sure there's a newline at the end of the message.
4263 (goto-char (point-max))
4264 (unless (bolp)
4265 (insert "\n"))
4266 ;; Make the hidden headers visible.
4267 (widen)
4268 ;; Sort headers before sending the message.
4269 (message-sort-headers)
4270 ;; Make invisible text visible.
4271 ;; It doesn't seem as if this is useful, since the invisible property
4272 ;; is clobbered by an after-change hook anyhow.
4273 (message-check 'invisible-text
4274 (let ((regions (message-text-with-property 'invisible))
4275 from to)
4276 (when regions
4277 (while regions
4278 (setq from (caar regions)
4279 to (cdar regions)
4280 regions (cdr regions))
4281 (put-text-property from to 'invisible nil)
4282 (overlay-put (make-overlay from to) 'face 'highlight))
4283 (unless (yes-or-no-p
4284 "Invisible text found and made visible; continue sending? ")
4285 (error "Invisible text found and made visible")))))
4286 (message-check 'illegible-text
4287 (let (char found choice nul-chars)
4288 (message-goto-body)
4289 (setq nul-chars (save-excursion
4290 (search-forward "\000" nil t)))
4291 (while (progn
4292 (skip-chars-forward mm-7bit-chars)
4293 (when (get-text-property (point) 'no-illegible-text)
4294 ;; There is a signed or encrypted raw message part
4295 ;; that is considered to be safe.
4296 (goto-char (or (next-single-property-change
4297 (point) 'no-illegible-text)
4298 (point-max))))
4299 (setq char (char-after)))
4300 (when (or (< char 128)
4301 (and enable-multibyte-characters
4302 (memq (char-charset char)
4303 '(eight-bit-control eight-bit-graphic
4304 ;; Emacs 23, Bug#1770:
4305 eight-bit
4306 control-1))
4307 (not (get-text-property
4308 (point) 'untranslated-utf-8))))
4309 (overlay-put (make-overlay (point) (1+ (point))) 'face 'highlight)
4310 (setq found t))
4311 (forward-char))
4312 (when found
4313 (setq choice
4314 (car
4315 (read-multiple-choice
4316 (if nul-chars
4317 "NUL characters found, which may cause problems. Continue sending?"
4318 "Non-printable characters found. Continue sending?")
4319 `((?d "delete" "Remove non-printable characters and send")
4320 (?r "replace"
4321 ,(format
4322 "Replace non-printable characters with \"%s\" and send"
4323 message-replacement-char))
4324 (?s "send" "Send as is without removing anything")
4325 (?e "edit" "Continue editing")))))
4326 (if (eq choice ?e)
4327 (error "Non-printable characters"))
4328 (message-goto-body)
4329 (skip-chars-forward mm-7bit-chars)
4330 (while (not (eobp))
4331 (when (let ((char (char-after)))
4332 (or (< char 128)
4333 (and enable-multibyte-characters
4334 ;; FIXME: Wrong for Emacs 23 (unicode) and for
4335 ;; things like undecodable utf-8 (in Emacs 21?).
4336 ;; Should at least use find-coding-systems-region.
4337 ;; -- fx
4338 (memq (char-charset char)
4339 '(eight-bit-control eight-bit-graphic
4340 ;; Emacs 23, Bug#1770:
4341 eight-bit
4342 control-1))
4343 (not (get-text-property
4344 (point) 'untranslated-utf-8)))))
4345 (if (eq choice ?i)
4346 (message-kill-all-overlays)
4347 (delete-char 1)
4348 (when (eq choice ?r)
4349 (insert message-replacement-char))))
4350 (forward-char)
4351 (skip-chars-forward mm-7bit-chars)))))
4352 (message-check 'bogus-recipient
4353 ;; Warn before sending a mail to an invalid address.
4354 (message-check-recipients)))
4356 (defun message-bogus-recipient-p (recipients)
4357 "Check if a mail address in RECIPIENTS looks bogus.
4359 RECIPIENTS is a mail header. Return a list of potentially bogus
4360 addresses. If none is found, return nil.
4362 An address might be bogus if there's a matching entry in
4363 `message-bogus-addresses'."
4364 ;; FIXME: How about "foo@subdomain", when the MTA adds ".domain.tld"?
4365 (let (found)
4366 (mapc (lambda (address)
4367 (setq address (or (cadr address) ""))
4368 (when (or (string= "" address)
4369 (and message-bogus-addresses
4370 (let ((re
4371 (if (listp message-bogus-addresses)
4372 (mapconcat 'identity
4373 message-bogus-addresses
4374 "\\|")
4375 message-bogus-addresses)))
4376 (string-match re address))))
4377 (push address found)))
4378 (mail-extract-address-components recipients t))
4379 found))
4381 (defun message-check-recipients ()
4382 "Warn before composing or sending a mail to an invalid address.
4384 This function could be useful in `message-setup-hook'."
4385 (interactive)
4386 (save-restriction
4387 (message-narrow-to-headers)
4388 (dolist (hdr '("To" "Cc" "Bcc"))
4389 (let ((addr (message-fetch-field hdr)))
4390 (when (stringp addr)
4391 (dolist (bog (message-bogus-recipient-p addr))
4392 (and bog
4393 (not (y-or-n-p
4394 (format-message
4395 "Address `%s'%s might be bogus. Continue? "
4397 ;; If the encoded version of the email address
4398 ;; is different from the unencoded version,
4399 ;; then we likely have invisible characters or
4400 ;; the like. Display the encoded version,
4401 ;; too.
4402 (let ((encoded (rfc2047-encode-string bog)))
4403 (if (string= encoded bog)
4405 (format " (%s)" encoded))))))
4406 (user-error "Bogus address"))))))))
4408 (custom-add-option 'message-setup-hook 'message-check-recipients)
4410 (defun message-add-action (action &rest types)
4411 "Add ACTION to be performed when doing an exit of type TYPES."
4412 (while types
4413 (add-to-list (intern (format "message-%s-actions" (pop types)))
4414 action)))
4416 (defun message-delete-action (action &rest types)
4417 "Delete ACTION from lists of actions performed when doing an exit of type TYPES."
4418 (let (var)
4419 (while types
4420 (set (setq var (intern (format "message-%s-actions" (pop types))))
4421 (delq action (symbol-value var))))))
4423 (defun message-do-actions (actions)
4424 "Perform all actions in ACTIONS."
4425 ;; Now perform actions on successful sending.
4426 (dolist (action actions)
4427 (ignore-errors
4428 (cond
4429 ;; A simple function.
4430 ((functionp action)
4431 (funcall action))
4432 ;; Something to be evalled.
4434 (eval action))))))
4436 (defun message-send-mail-partially ()
4437 "Send mail as message/partial."
4438 ;; replace the header delimiter with a blank line
4439 (goto-char (point-min))
4440 (re-search-forward
4441 (concat "^" (regexp-quote mail-header-separator) "\n"))
4442 (replace-match "\n")
4443 (run-hooks 'message-send-mail-hook)
4444 (let ((p (goto-char (point-min)))
4445 (tembuf (message-generate-new-buffer-clone-locals " message temp"))
4446 (curbuf (current-buffer))
4447 (id (message-make-message-id)) (n 1)
4448 plist total header)
4449 (while (not (eobp))
4450 (if (< (point-max) (+ p message-send-mail-partially-limit))
4451 (goto-char (point-max))
4452 (goto-char (+ p message-send-mail-partially-limit))
4453 (beginning-of-line)
4454 (if (<= (point) p) (forward-line 1))) ;; In case of bad message.
4455 (push p plist)
4456 (setq p (point)))
4457 (setq total (length plist))
4458 (push (point-max) plist)
4459 (setq plist (nreverse plist))
4460 (unwind-protect
4461 (save-excursion
4462 (setq p (pop plist))
4463 (while plist
4464 (set-buffer curbuf)
4465 (copy-to-buffer tembuf p (car plist))
4466 (set-buffer tembuf)
4467 (goto-char (point-min))
4468 (if header
4469 (progn
4470 (goto-char (point-min))
4471 (narrow-to-region (point) (point))
4472 (insert header))
4473 (message-goto-eoh)
4474 (setq header (buffer-substring (point-min) (point)))
4475 (goto-char (point-min))
4476 (narrow-to-region (point) (point))
4477 (insert header)
4478 (message-remove-header "Mime-Version")
4479 (message-remove-header "Content-Type")
4480 (message-remove-header "Content-Transfer-Encoding")
4481 (message-remove-header "Message-ID")
4482 (message-remove-header "Lines")
4483 (goto-char (point-max))
4484 (insert "Mime-Version: 1.0\n")
4485 (setq header (buffer-string)))
4486 (goto-char (point-max))
4487 (insert (format "Content-Type: message/partial; id=\"%s\"; number=%d; total=%d\n\n"
4488 id n total))
4489 (forward-char -1)
4490 (let ((mail-header-separator ""))
4491 (when (memq 'Message-ID message-required-mail-headers)
4492 (insert "Message-ID: " (message-make-message-id) "\n"))
4493 (when (memq 'Lines message-required-mail-headers)
4494 (insert "Lines: " (message-make-lines) "\n"))
4495 (message-goto-subject)
4496 (end-of-line)
4497 (insert (format " (%d/%d)" n total))
4498 (widen)
4499 (if message-send-mail-real-function
4500 (funcall message-send-mail-real-function)
4501 (message-multi-smtp-send-mail)))
4502 (setq n (+ n 1))
4503 (setq p (pop plist))
4504 (erase-buffer)))
4505 (kill-buffer tembuf))))
4507 (declare-function hashcash-wait-async "hashcash" (&optional buffer))
4509 (defun message-send-mail (&optional _)
4510 (require 'mail-utils)
4511 (let* ((tembuf (message-generate-new-buffer-clone-locals " message temp"))
4512 (case-fold-search nil)
4513 (news (message-news-p))
4514 (mailbuf (current-buffer))
4515 (message-this-is-mail t)
4516 ;; gnus-setup-posting-charset is autoloaded in mml.el (FIXME
4517 ;; maybe it should not be), which this file requires. Hence
4518 ;; the fboundp test is always true. Loading it from gnus-msg
4519 ;; loads many Gnus files (Bug#5642). If
4520 ;; gnus-group-posting-charset-alist hasn't been customized,
4521 ;; this is just going to return nil anyway. FIXME it would
4522 ;; be good to improve this further, because even if g-g-p-c-a
4523 ;; has been customized, that is likely to just be for news.
4524 ;; Eg either move the definition from gnus-msg, or separate out
4525 ;; the mail and news parts.
4526 (message-posting-charset
4527 (if (and (fboundp 'gnus-setup-posting-charset)
4528 (boundp 'gnus-group-posting-charset-alist))
4529 (gnus-setup-posting-charset nil)
4530 message-posting-charset))
4531 (headers message-required-mail-headers)
4532 options)
4533 (when (and message-generate-hashcash
4534 (not (eq message-generate-hashcash 'opportunistic)))
4535 (message "Generating hashcash...")
4536 (require 'hashcash)
4537 ;; Wait for calculations already started to finish...
4538 (hashcash-wait-async)
4539 ;; ...and do calculations not already done. mail-add-payment
4540 ;; will leave existing X-Hashcash headers alone.
4541 (mail-add-payment)
4542 (message "Generating hashcash...done"))
4543 (save-restriction
4544 (message-narrow-to-headers)
4545 ;; Generate the Mail-Followup-To header if the header is not there...
4546 (if (and (message-subscribed-p)
4547 (not (mail-fetch-field "mail-followup-to")))
4548 (setq headers
4549 (cons
4550 (cons "Mail-Followup-To" (message-make-mail-followup-to))
4551 message-required-mail-headers))
4552 ;; otherwise, delete the MFT header if the field is empty
4553 (when (equal "" (mail-fetch-field "mail-followup-to"))
4554 (message-remove-header "^Mail-Followup-To:")))
4555 ;; Insert some headers.
4556 (let ((message-deletable-headers
4557 (if news nil message-deletable-headers)))
4558 (message-generate-headers headers))
4559 ;; Check continuation headers.
4560 (message-check 'continuation-headers
4561 (goto-char (point-min))
4562 (while (re-search-forward "^[^ \t\n][^ \t\n:]*[ \t\n]" nil t)
4563 (goto-char (match-beginning 0))
4564 (if (y-or-n-p "Fix continuation lines? ")
4565 (insert " ")
4566 (forward-line 1)
4567 (unless (y-or-n-p "Send anyway? ")
4568 (error "Failed to send the message")))))
4569 ;; Fold too-long header lines. They should be no longer than
4570 ;; 998 octets long.
4571 (message--fold-long-headers)
4572 ;; Let the user do all of the above.
4573 (run-hooks 'message-header-hook))
4574 (setq options message-options)
4575 (unwind-protect
4576 (with-current-buffer tembuf
4577 (erase-buffer)
4578 (setq message-options options)
4579 ;; Avoid copying text props (except hard newlines).
4580 (insert (with-current-buffer mailbuf
4581 (mml-buffer-substring-no-properties-except-some
4582 (point-min) (point-max))))
4583 ;; Remove some headers.
4584 (message-encode-message-body)
4585 (save-restriction
4586 (message-narrow-to-headers)
4587 ;; We (re)generate the Lines header.
4588 (when (memq 'Lines message-required-mail-headers)
4589 (message-generate-headers '(Lines)))
4590 ;; Remove some headers.
4591 (message-remove-header message-ignored-mail-headers t)
4592 (let ((mail-parse-charset message-default-charset))
4593 (mail-encode-encoded-word-buffer)))
4594 (goto-char (point-max))
4595 ;; require one newline at the end.
4596 (or (= (preceding-char) ?\n)
4597 (insert ?\n))
4598 (message-cleanup-headers)
4599 ;; FIXME: we're inserting the courtesy copy after encoding.
4600 ;; This is wrong if the courtesy copy string contains
4601 ;; non-ASCII characters. -- jh
4602 (when
4603 (save-restriction
4604 (message-narrow-to-headers)
4605 (and news
4606 (not (message-fetch-field "List-Post"))
4607 (not (message-fetch-field "List-ID"))
4608 (or (message-fetch-field "cc")
4609 (message-fetch-field "bcc")
4610 (message-fetch-field "to"))
4611 (let ((content-type (message-fetch-field
4612 "content-type")))
4613 (and
4615 (not content-type)
4616 (string= "text/plain"
4617 (car
4618 (mail-header-parse-content-type
4619 content-type))))
4620 (not
4621 (string= "base64"
4622 (message-fetch-field
4623 "content-transfer-encoding")))))))
4624 (message-insert-courtesy-copy
4625 (with-current-buffer mailbuf
4626 message-courtesy-message)))
4627 ;; Let's make sure we encoded all the body.
4628 (cl-assert (save-excursion
4629 (goto-char (point-min))
4630 (not (re-search-forward "[^\000-\377]" nil t))))
4631 (mm-disable-multibyte)
4632 (if (or (not message-send-mail-partially-limit)
4633 (< (buffer-size) message-send-mail-partially-limit)
4634 (not (message-y-or-n-p
4635 "The message size is too large, split? "
4638 The message size, "
4639 (/ (buffer-size) 1000) "KB, is too large.
4641 Some mail gateways (MTA's) bounce large messages. To avoid the
4642 problem, answer `y', and the message will be split into several
4643 smaller pieces, the size of each is about "
4644 (/ message-send-mail-partially-limit 1000)
4645 "KB except the last
4646 one.
4648 However, some mail readers (MUA's) can't read split messages, i.e.,
4649 mails in message/partially format. Answer `n', and the message will be
4650 sent in one piece.
4652 The size limit is controlled by `message-send-mail-partially-limit'.
4653 If you always want Gnus to send messages in one piece, set
4654 `message-send-mail-partially-limit' to nil.
4655 ")))
4656 (progn
4657 (message "Sending via mail...")
4658 (if message-send-mail-real-function
4659 (funcall message-send-mail-real-function)
4660 (message-multi-smtp-send-mail)))
4661 (message-send-mail-partially))
4662 (setq options message-options))
4663 (kill-buffer tembuf))
4664 (set-buffer mailbuf)
4665 (setq message-options options)
4666 (push 'mail message-sent-message-via)))
4668 (defun message--fold-long-headers ()
4669 (goto-char (point-min))
4670 (while (not (eobp))
4671 (when (and (looking-at "[^:]+:")
4672 (> (- (line-end-position) (point)) 998))
4673 (mail-header-fold-field))
4674 (forward-line 1)))
4676 (defvar sendmail-program)
4677 (defvar smtpmail-smtp-server)
4678 (defvar smtpmail-smtp-service)
4679 (defvar smtpmail-smtp-user)
4681 (defun message-multi-smtp-send-mail ()
4682 "Send the current buffer to `message-send-mail-function'.
4683 Or, if there's a header that specifies a different method, use
4684 that instead."
4685 (let ((method (message-field-value "X-Message-SMTP-Method")))
4686 (if (not method)
4687 (funcall message-send-mail-function)
4688 (message-remove-header "X-Message-SMTP-Method")
4689 (setq method (split-string method))
4690 (cond
4691 ((equal (car method) "sendmail")
4692 (message-send-mail-with-sendmail))
4693 ((equal (car method) "smtp")
4694 (require 'smtpmail)
4695 (let* ((smtpmail-smtp-server (nth 1 method))
4696 (service (nth 2 method))
4697 (port (string-to-number service))
4698 (smtpmail-smtp-service (if (> port 0) port service))
4699 (smtpmail-smtp-user (or (nth 3 method) smtpmail-smtp-user)))
4700 (message-smtpmail-send-it)))
4702 (error "Unknown method %s" method))))))
4704 (defun message-send-mail-with-sendmail ()
4705 "Send off the prepared buffer with sendmail."
4706 (require 'sendmail)
4707 (let ((errbuf (if message-interactive
4708 (message-generate-new-buffer-clone-locals
4709 " sendmail errors")
4711 resend-to-addresses delimline)
4712 (unwind-protect
4713 (progn
4714 (let ((case-fold-search t))
4715 (save-restriction
4716 (message-narrow-to-headers)
4717 (setq resend-to-addresses (message-fetch-field "resent-to")))
4718 ;; Change header-delimiter to be what sendmail expects.
4719 (goto-char (point-min))
4720 (re-search-forward
4721 (concat "^" (regexp-quote mail-header-separator) "\n"))
4722 (replace-match "\n")
4723 (backward-char 1)
4724 (setq delimline (point-marker))
4725 (run-hooks 'message-send-mail-hook)
4726 ;; Insert an extra newline if we need it to work around
4727 ;; Sun's bug that swallows newlines.
4728 (goto-char (1+ delimline))
4729 (when (eval message-mailer-swallows-blank-line)
4730 (newline))
4731 (when message-interactive
4732 (with-current-buffer errbuf
4733 (erase-buffer))))
4734 (let* ((default-directory "/")
4735 (coding-system-for-write message-send-coding-system)
4736 (cpr (apply
4737 'call-process-region
4738 (append
4739 (list (point-min) (point-max) sendmail-program
4740 nil errbuf nil "-oi")
4741 message-sendmail-extra-arguments
4742 ;; Always specify who from,
4743 ;; since some systems have broken sendmails.
4744 ;; But some systems are more broken with -f, so
4745 ;; we'll let users override this.
4746 (and (null message-sendmail-f-is-evil)
4747 (list "-f" (message-sendmail-envelope-from)))
4748 ;; These mean "report errors by mail"
4749 ;; and "deliver in background".
4750 (if (null message-interactive) '("-oem" "-odb"))
4751 ;; Get the addresses from the message
4752 ;; unless this is a resend.
4753 ;; We must not do that for a resend
4754 ;; because we would find the original addresses.
4755 ;; For a resend, include the specific addresses.
4756 (if resend-to-addresses
4757 (list resend-to-addresses)
4758 '("-t"))))))
4759 (unless (or (null cpr) (and (numberp cpr) (zerop cpr)))
4760 (when errbuf
4761 (pop-to-buffer errbuf)
4762 (setq errbuf nil))
4763 (error "Sending...failed with exit value %d" cpr)))
4764 (when message-interactive
4765 (with-current-buffer errbuf
4766 (goto-char (point-min))
4767 (while (re-search-forward "\n+ *" nil t)
4768 (replace-match "; "))
4769 (if (not (zerop (buffer-size)))
4770 (error "Sending...failed to %s"
4771 (buffer-string))))))
4772 (when (bufferp errbuf)
4773 (kill-buffer errbuf)))))
4775 (defun message-send-mail-with-qmail ()
4776 "Pass the prepared message buffer to qmail-inject.
4777 Refer to the documentation for the variable `message-send-mail-function'
4778 to find out how to use this."
4779 ;; replace the header delimiter with a blank line
4780 (goto-char (point-min))
4781 (re-search-forward
4782 (concat "^" (regexp-quote mail-header-separator) "\n"))
4783 (replace-match "\n")
4784 (run-hooks 'message-send-mail-hook)
4785 ;; send the message
4786 (pcase
4787 (let ((coding-system-for-write message-send-coding-system))
4788 (apply
4789 'call-process-region (point-min) (point-max)
4790 message-qmail-inject-program nil nil nil
4791 ;; qmail-inject's default behavior is to look for addresses on the
4792 ;; command line; if there're none, it scans the headers.
4793 ;; yes, it does The Right Thing w.r.t. Resent-To and its kin.
4795 ;; in general, ALL of qmail-inject's defaults are perfect for simply
4796 ;; reading a formatted (i. e., at least a To: or Resent-To header)
4797 ;; message from stdin.
4799 ;; qmail also has the advantage of not having been raped by
4800 ;; various vendors, so we don't have to allow for that, either --
4801 ;; compare this with message-send-mail-with-sendmail and weep
4802 ;; for sendmail's lost innocence.
4804 ;; all this is way cool coz it lets us keep the arguments entirely
4805 ;; free for -inject-arguments -- a big win for the user and for us
4806 ;; since we don't have to play that double-guessing game and the user
4807 ;; gets full control (no gestapo'ish -f's, for instance). --sj
4808 (if (functionp message-qmail-inject-args)
4809 (funcall message-qmail-inject-args)
4810 message-qmail-inject-args)))
4811 ;; qmail-inject doesn't say anything on its stdout/stderr,
4812 ;; we have to look at the retval instead
4813 (0 nil)
4814 (100 (error "qmail-inject reported permanent failure"))
4815 (111 (error "qmail-inject reported transient failure"))
4816 ;; should never happen
4817 (_ (error "qmail-inject reported unknown failure"))))
4819 (defvar mh-previous-window-config)
4821 (defun message-send-mail-with-mh ()
4822 "Send the prepared message buffer with mh."
4823 (let ((mh-previous-window-config nil)
4824 (name (mh-new-draft-name)))
4825 (setq buffer-file-name name)
4826 ;; MH wants to generate these headers itself.
4827 (when message-mh-deletable-headers
4828 (let ((headers message-mh-deletable-headers))
4829 (while headers
4830 (goto-char (point-min))
4831 (and (re-search-forward
4832 (concat "^" (symbol-name (car headers)) ": *") nil t)
4833 (message-delete-line))
4834 (pop headers))))
4835 (run-hooks 'message-send-mail-hook)
4836 ;; Pass it on to mh.
4837 (mh-send-letter)))
4839 (defun message-smtpmail-send-it ()
4840 "Send the prepared message buffer with `smtpmail-send-it'.
4841 The only difference from `smtpmail-send-it' is that this command
4842 evaluates `message-send-mail-hook' just before sending a message.
4843 It is useful if your ISP requires the POP-before-SMTP
4844 authentication. See the Gnus manual for details."
4845 (run-hooks 'message-send-mail-hook)
4846 ;; Change header-delimiter to be what smtpmail expects.
4847 (goto-char (point-min))
4848 (when (re-search-forward
4849 (concat "^" (regexp-quote mail-header-separator) "\n"))
4850 (replace-match "\n"))
4851 (smtpmail-send-it))
4853 (defun message-send-mail-with-mailclient ()
4854 "Send the prepared message buffer with `mailclient-send-it'.
4855 The only difference from `mailclient-send-it' is that this
4856 command evaluates `message-send-mail-hook' just before sending a message."
4857 (run-hooks 'message-send-mail-hook)
4858 (mailclient-send-it))
4860 (defun message-canlock-generate ()
4861 "Return a string that is non-trivial to guess.
4862 Do not use this for anything important, it is cryptographically weak."
4863 (sha1 (concat (message-unique-id)
4864 (format "%x%x%x" (random) (random) (random))
4865 (prin1-to-string (recent-keys))
4866 (prin1-to-string (garbage-collect)))))
4868 (defvar canlock-password)
4869 (defvar canlock-password-for-verify)
4871 (defun message-canlock-password ()
4872 "The password used by message for cancel locks.
4873 This is the value of `canlock-password', if that option is non-nil.
4874 Otherwise, generate and save a value for `canlock-password' first."
4875 (require 'canlock)
4876 (unless canlock-password
4877 (customize-save-variable 'canlock-password (message-canlock-generate))
4878 (setq canlock-password-for-verify canlock-password))
4879 canlock-password)
4881 (defun message-insert-canlock ()
4882 (when message-insert-canlock
4883 (message-canlock-password)
4884 (canlock-insert-header)))
4886 (autoload 'nnheader-get-report "nnheader")
4888 (declare-function gnus-setup-posting-charset "gnus-msg" (group))
4890 (defun message-send-news (&optional arg)
4891 (require 'gnus-msg)
4892 (let* ((tembuf (message-generate-new-buffer-clone-locals " *message temp*"))
4893 (case-fold-search nil)
4894 (method (if (functionp message-post-method)
4895 (funcall message-post-method arg)
4896 message-post-method))
4897 (newsgroups-field (save-restriction
4898 (message-narrow-to-headers-or-head)
4899 (message-fetch-field "Newsgroups")))
4900 (followup-field (save-restriction
4901 (message-narrow-to-headers-or-head)
4902 (message-fetch-field "Followup-To")))
4903 ;; BUG: We really need to get the charset for each name in the
4904 ;; Newsgroups and Followup-To lines to allow crossposting
4905 ;; between group names with incompatible character sets.
4906 ;; -- Per Abrahamsen <abraham@dina.kvl.dk> 2001-10-08.
4907 (group-field-charset
4908 (gnus-group-name-charset method newsgroups-field))
4909 (followup-field-charset
4910 (gnus-group-name-charset method (or followup-field "")))
4911 (rfc2047-header-encoding-alist
4912 (append (when group-field-charset
4913 (list (cons "Newsgroups" group-field-charset)))
4914 (when followup-field-charset
4915 (list (cons "Followup-To" followup-field-charset)))
4916 rfc2047-header-encoding-alist))
4917 (messbuf (current-buffer))
4918 (message-syntax-checks
4919 (if (and arg
4920 (listp message-syntax-checks))
4921 (cons '(existing-newsgroups . disabled)
4922 message-syntax-checks)
4923 message-syntax-checks))
4924 (message-this-is-news t)
4925 (message-posting-charset
4926 (gnus-setup-posting-charset newsgroups-field))
4927 result)
4928 (if (not (message-check-news-body-syntax))
4930 (save-restriction
4931 (message-narrow-to-headers)
4932 ;; Insert some headers.
4933 (message-generate-headers message-required-news-headers)
4934 (message-insert-canlock)
4935 ;; Let the user do all of the above.
4936 (run-hooks 'message-header-hook))
4937 ;; Note: This check will be disabled by the ".*" default value for
4938 ;; gnus-group-name-charset-group-alist. -- Pa 2001-10-07.
4939 (when (and group-field-charset
4940 (listp message-syntax-checks))
4941 (setq message-syntax-checks
4942 (cons '(valid-newsgroups . disabled)
4943 message-syntax-checks)))
4944 (message-cleanup-headers)
4945 (if (not (let ((message-post-method method))
4946 (message-check-news-syntax)))
4948 (unwind-protect
4949 (with-current-buffer tembuf
4950 (buffer-disable-undo)
4951 (erase-buffer)
4952 ;; Avoid copying text props (except hard newlines).
4953 (insert
4954 (with-current-buffer messbuf
4955 (mml-buffer-substring-no-properties-except-some
4956 (point-min) (point-max))))
4957 (message-encode-message-body)
4958 ;; Remove some headers.
4959 (save-restriction
4960 (message-narrow-to-headers)
4961 ;; We (re)generate the Lines header.
4962 (when (memq 'Lines message-required-mail-headers)
4963 (message-generate-headers '(Lines)))
4964 ;; Remove some headers.
4965 (message-remove-header message-ignored-news-headers t)
4966 (let ((mail-parse-charset message-default-charset))
4967 (mail-encode-encoded-word-buffer)))
4968 (goto-char (point-max))
4969 ;; require one newline at the end.
4970 (or (= (preceding-char) ?\n)
4971 (insert ?\n))
4972 (let ((case-fold-search t))
4973 ;; Remove the delimiter.
4974 (goto-char (point-min))
4975 (re-search-forward
4976 (concat "^" (regexp-quote mail-header-separator) "\n"))
4977 (replace-match "\n")
4978 (backward-char 1))
4979 (run-hooks 'message-send-news-hook)
4980 (gnus-open-server method)
4981 (message "Sending news via %s..." (gnus-server-string method))
4982 (setq result (let ((mail-header-separator ""))
4983 (gnus-request-post method))))
4984 (kill-buffer tembuf))
4985 (set-buffer messbuf)
4986 (if result
4987 (push 'news message-sent-message-via)
4988 (message "Couldn't send message via news: %s"
4989 (nnheader-get-report (car method)))
4990 nil)))))
4993 ;;; Header generation & syntax checking.
4996 (defun message-check-element (type)
4997 "Return non-nil if this TYPE is not to be checked."
4998 (if (eq message-syntax-checks 'dont-check-for-anything-just-trust-me)
5000 (let ((able (assq type message-syntax-checks)))
5001 (and (consp able)
5002 (eq (cdr able) 'disabled)))))
5004 (defun message-check-news-syntax ()
5005 "Check the syntax of the message."
5006 (save-excursion
5007 (save-restriction
5008 (widen)
5009 ;; We narrow to the headers and check them first.
5010 (save-excursion
5011 (save-restriction
5012 (message-narrow-to-headers)
5013 (message-check-news-header-syntax))))))
5015 (defun message-check-news-header-syntax ()
5016 (and
5017 ;; Check Newsgroups header.
5018 (message-check 'newsgroups
5019 (let ((group (message-fetch-field "newsgroups")))
5021 (and group
5022 (not (string-match "\\`[ \t]*\\'" group)))
5023 (ignore
5024 (message
5025 "The newsgroups field is empty or missing. Posting is denied.")))))
5026 ;; Check the Subject header.
5027 (message-check 'subject
5028 (let* ((case-fold-search t)
5029 (subject (message-fetch-field "subject")))
5031 (and subject
5032 (not (string-match "\\`[ \t]*\\'" subject)))
5033 (ignore
5034 (message
5035 "The subject field is empty or missing. Posting is denied.")))))
5036 ;; Check for commands in Subject.
5037 (message-check 'subject-cmsg
5038 (if (string-match "^cmsg " (message-fetch-field "subject"))
5039 (y-or-n-p
5040 "The control code \"cmsg\" is in the subject. Really post? ")
5042 ;; Check long header lines.
5043 (message-check 'long-header-lines
5044 (let ((header nil)
5045 (length 0)
5046 found)
5047 (while (and (not found)
5048 (re-search-forward "^\\([^ \t:]+\\): " nil t))
5049 (if (> (- (point) (match-beginning 0)) 998)
5050 (setq found t
5051 length (- (point) (match-beginning 0)))
5052 (setq header (match-string-no-properties 1)))
5053 (forward-line 1))
5054 (if found
5055 (y-or-n-p (format "Your %s header is too long (%d). Really post? "
5056 header length))
5057 t)))
5058 ;; Check for multiple identical headers.
5059 (message-check 'multiple-headers
5060 (let (found)
5061 (while (and (not found)
5062 (re-search-forward "^[^ \t:]+: " nil t))
5063 (save-excursion
5064 (or (re-search-forward
5065 (concat "^"
5066 (regexp-quote
5067 (setq found
5068 (buffer-substring
5069 (match-beginning 0) (- (match-end 0) 2))))
5070 ":")
5071 nil t)
5072 (setq found nil))))
5073 (if found
5074 (y-or-n-p (format "Multiple %s headers. Really post? " found))
5075 t)))
5076 ;; Check for Version and Sendsys.
5077 (message-check 'sendsys
5078 (if (re-search-forward "^Sendsys:\\|^Version:" nil t)
5079 (y-or-n-p
5080 (format "The article contains a %s command. Really post? "
5081 (buffer-substring (match-beginning 0)
5082 (1- (match-end 0)))))
5084 ;; See whether we can shorten Followup-To.
5085 (message-check 'shorten-followup-to
5086 (let ((newsgroups (message-fetch-field "newsgroups"))
5087 (followup-to (message-fetch-field "followup-to"))
5089 (when (and newsgroups
5090 (string-match "," newsgroups)
5091 (not followup-to)
5092 (not
5093 (zerop
5094 (length
5095 (setq to (completing-read
5096 "Followups to (default no Followup-To header): "
5097 (mapcar #'list
5098 (cons "poster"
5099 (message-tokenize-header
5100 newsgroups)))))))))
5101 (goto-char (point-min))
5102 (insert "Followup-To: " to "\n"))
5104 ;; Check "Shoot me".
5105 (message-check 'shoot
5106 (if (re-search-forward
5107 "Message-ID.*.i-did-not-set--mail-host-address--so-tickle-me" nil t)
5108 (y-or-n-p "You appear to have a misconfigured system. Really post? ")
5110 ;; Check for Approved.
5111 (message-check 'approved
5112 (if (re-search-forward "^Approved:" nil t)
5113 (y-or-n-p "The article contains an Approved header. Really post? ")
5115 ;; Check the Message-ID header.
5116 (message-check 'message-id
5117 (let* ((case-fold-search t)
5118 (message-id (message-fetch-field "message-id" t)))
5119 (or (not message-id)
5120 ;; Is there an @ in the ID?
5121 (and (string-match "@" message-id)
5122 ;; Is there a dot in the ID?
5123 (string-match "@[^.]*\\." message-id)
5124 ;; Does the ID end with a dot?
5125 (not (string-match "\\.>" message-id)))
5126 (y-or-n-p
5127 (format "The Message-ID looks strange: \"%s\". Really post? "
5128 message-id)))))
5129 ;; Check the Newsgroups & Followup-To headers.
5130 (message-check 'existing-newsgroups
5131 (let* ((case-fold-search t)
5132 (newsgroups (message-fetch-field "newsgroups"))
5133 (followup-to (message-fetch-field "followup-to"))
5134 (groups (message-tokenize-header
5135 (if followup-to
5136 (concat newsgroups "," followup-to)
5137 newsgroups)))
5138 (post-method (if (functionp message-post-method)
5139 (funcall message-post-method)
5140 message-post-method))
5141 ;; KLUDGE to handle nnvirtual groups. Doing this right
5142 ;; would probably involve a new nnoo function.
5143 ;; -- Per Abrahamsen <abraham@dina.kvl.dk>, 2001-10-17.
5144 (method (if (and (consp post-method)
5145 (eq (car post-method) 'nnvirtual)
5146 gnus-message-group-art)
5147 (let ((group (car (nnvirtual-find-group-art
5148 (car gnus-message-group-art)
5149 (cdr gnus-message-group-art)))))
5150 (gnus-find-method-for-group group))
5151 post-method))
5152 (known-groups
5153 (mapcar (lambda (n)
5154 (gnus-group-name-decode
5155 (gnus-group-real-name n)
5156 (gnus-group-name-charset method n)))
5157 (gnus-groups-from-server method)))
5158 errors)
5159 (while groups
5160 (when (and (not (equal (car groups) "poster"))
5161 (not (member (car groups) known-groups))
5162 (not (member (car groups) errors)))
5163 (push (car groups) errors))
5164 (pop groups))
5165 (cond
5166 ;; Gnus is not running.
5167 ((or (not (and (boundp 'gnus-active-hashtb)
5168 gnus-active-hashtb))
5169 (not (boundp 'gnus-read-active-file)))
5171 ;; We don't have all the group names.
5172 ((and (or (not gnus-read-active-file)
5173 (eq gnus-read-active-file 'some))
5174 errors)
5175 (y-or-n-p
5176 (format
5177 "Really use %s possibly unknown group%s: %s? "
5178 (if (= (length errors) 1) "this" "these")
5179 (if (= (length errors) 1) "" "s")
5180 (mapconcat 'identity errors ", "))))
5181 ;; There were no errors.
5182 ((not errors)
5184 ;; There are unknown groups.
5186 (y-or-n-p
5187 (format
5188 "Really post to %s unknown group%s: %s? "
5189 (if (= (length errors) 1) "this" "these")
5190 (if (= (length errors) 1) "" "s")
5191 (mapconcat 'identity errors ", ")))))))
5192 ;; Check continuation headers.
5193 (message-check 'continuation-headers
5194 (goto-char (point-min))
5195 (let ((do-posting t))
5196 (while (re-search-forward "^[^ \t\n][^ \t\n:]*[ \t\n]" nil t)
5197 (goto-char (match-beginning 0))
5198 (if (y-or-n-p "Fix continuation lines? ")
5199 (insert " ")
5200 (forward-line 1)
5201 (unless (y-or-n-p "Send anyway? ")
5202 (setq do-posting nil))))
5203 do-posting))
5204 ;; Check the Newsgroups & Followup-To headers for syntax errors.
5205 (message-check 'valid-newsgroups
5206 (let ((case-fold-search t)
5207 (headers '("Newsgroups" "Followup-To"))
5208 header error)
5209 (while (and headers (not error))
5210 (when (setq header (mail-fetch-field (car headers)))
5211 (if (or
5212 (not
5213 (string-match
5214 "\\`\\([-+_&.a-zA-Z0-9]+\\)?\\(,[-+_&.a-zA-Z0-9]+\\)*\\'"
5215 header))
5216 (memq
5217 nil (mapcar
5218 (lambda (g)
5219 (not (string-match "\\.\\'\\|\\.\\." g)))
5220 (message-tokenize-header header ","))))
5221 (setq error t)))
5222 (unless error
5223 (pop headers)))
5224 (if (not error)
5226 (y-or-n-p
5227 (format "The %s header looks odd: \"%s\". Really post? "
5228 (car headers) header)))))
5229 (message-check 'repeated-newsgroups
5230 (let ((case-fold-search t)
5231 (headers '("Newsgroups" "Followup-To"))
5232 header error groups group)
5233 (while (and headers
5234 (not error))
5235 (when (setq header (mail-fetch-field (pop headers)))
5236 (setq groups (message-tokenize-header header ","))
5237 (while (setq group (pop groups))
5238 (when (member group groups)
5239 (setq error group
5240 groups nil)))))
5241 (if (not error)
5243 (y-or-n-p
5244 (format "Group %s is repeated in headers. Really post? " error)))))
5245 ;; Check the From header.
5246 (message-check 'from
5247 (let* ((case-fold-search t)
5248 (from (message-fetch-field "from"))
5250 (cond
5251 ((not from)
5252 (message "There is no From line. Posting is denied.")
5253 nil)
5254 ((or (not (string-match
5255 "@[^\\.]*\\."
5256 (setq ad (nth 1 (mail-extract-address-components
5257 from))))) ;larsi@ifi
5258 (string-match "\\.\\." ad) ;larsi@ifi..uio
5259 (string-match "@\\." ad) ;larsi@.ifi.uio
5260 (string-match "\\.$" ad) ;larsi@ifi.uio.
5261 (not (string-match "^[^@]+@[^@]+$" ad)) ;larsi.ifi.uio
5262 (string-match "(.*).*(.*)" from)) ;(lars) (lars)
5263 (message
5264 "Denied posting -- the From looks strange: \"%s\"." from)
5265 nil)
5266 ((let ((addresses (rfc822-addresses from)))
5267 ;; `rfc822-addresses' returns a string if parsing fails.
5268 (while (and (consp addresses)
5269 (not (eq (string-to-char (car addresses)) ?\()))
5270 (setq addresses (cdr addresses)))
5271 addresses)
5272 (message
5273 "Denied posting -- bad From address: \"%s\"." from)
5274 nil)
5275 (t t))))
5276 ;; Check the Reply-To header.
5277 (message-check 'reply-to
5278 (let* ((case-fold-search t)
5279 (reply-to (message-fetch-field "reply-to"))
5281 (cond
5282 ((not reply-to)
5284 ((string-match "," reply-to)
5285 (y-or-n-p
5286 (format "Multiple Reply-To addresses: \"%s\". Really post? "
5287 reply-to)))
5288 ((or (not (string-match
5289 "@[^\\.]*\\."
5290 (setq ad (nth 1 (mail-extract-address-components
5291 reply-to))))) ;larsi@ifi
5292 (string-match "\\.\\." ad) ;larsi@ifi..uio
5293 (string-match "@\\." ad) ;larsi@.ifi.uio
5294 (string-match "\\.$" ad) ;larsi@ifi.uio.
5295 (not (string-match "^[^@]+@[^@]+$" ad)) ;larsi.ifi.uio
5296 (string-match "(.*).*(.*)" reply-to)) ;(lars) (lars)
5297 (y-or-n-p
5298 (format
5299 "The Reply-To looks strange: \"%s\". Really post? "
5300 reply-to)))
5301 (t t))))))
5303 (defun message-check-news-body-syntax ()
5304 (and
5305 ;; Check for long lines.
5306 (message-check 'long-lines
5307 (goto-char (point-min))
5308 (re-search-forward
5309 (concat "^" (regexp-quote mail-header-separator) "$"))
5310 (forward-line 1)
5311 (while (and
5312 (or (looking-at
5313 "<#\\(/\\)?\\(multipart\\|part\\|external\\|mml\\)")
5314 (let ((p (point)))
5315 (end-of-line)
5316 (< (- (point) p) 80)))
5317 (zerop (forward-line 1))))
5318 (or (bolp)
5319 (eobp)
5320 (y-or-n-p
5321 "You have lines longer than 79 characters. Really post? ")))
5322 ;; Check whether the article is empty.
5323 (message-check 'empty
5324 (goto-char (point-min))
5325 (re-search-forward
5326 (concat "^" (regexp-quote mail-header-separator) "$"))
5327 (forward-line 1)
5328 (let ((b (point)))
5329 (goto-char (point-max))
5330 (re-search-backward message-signature-separator nil t)
5331 (beginning-of-line)
5332 (or (re-search-backward "[^ \n\t]" b t)
5333 (if (message-gnksa-enable-p 'empty-article)
5334 (y-or-n-p "Empty article. Really post? ")
5335 (message "Denied posting -- Empty article.")
5336 nil))))
5337 ;; Check for control characters.
5338 (message-check 'control-chars
5339 (if (re-search-forward
5340 (eval-when-compile
5341 (decode-coding-string "[\000-\007\013\015-\032\034-\037\200-\237]"
5342 'binary))
5343 nil t)
5344 (y-or-n-p
5345 "The article contains control characters. Really post? ")
5347 ;; Check excessive size.
5348 (message-check 'size
5349 (if (> (buffer-size) 60000)
5350 (y-or-n-p
5351 (format "The article is %d octets long. Really post? "
5352 (buffer-size)))
5354 ;; Check whether any new text has been added.
5355 (message-check 'new-text
5357 (not message-checksum)
5358 (not (eq (message-checksum) message-checksum))
5359 (if (message-gnksa-enable-p 'quoted-text-only)
5360 (y-or-n-p
5361 "It looks like no new text has been added. Really post? ")
5362 (message "Denied posting -- no new text has been added.")
5363 nil)))
5364 ;; Check the length of the signature.
5365 (message-check 'signature
5366 (let (sig-start sig-end)
5367 (goto-char (point-max))
5368 (if (not (re-search-backward message-signature-separator nil t))
5370 (setq sig-start (1+ (point-at-eol)))
5371 (setq sig-end
5372 (if (re-search-forward
5373 "<#/?\\(multipart\\|part\\|external\\|mml\\)" nil t)
5374 (- (point-at-bol) 1)
5375 (point-max)))
5376 (if (>= (count-lines sig-start sig-end) 5)
5377 (if (message-gnksa-enable-p 'signature)
5378 (y-or-n-p
5379 (format "Signature is excessively long (%d lines). Really post? "
5380 (count-lines sig-start sig-end)))
5381 (message "Denied posting -- Excessive signature.")
5382 nil)
5383 t))))
5384 ;; Ensure that text follows last quoted portion.
5385 (message-check 'quoting-style
5386 (goto-char (point-max))
5387 (let ((no-problem t))
5388 (when (search-backward-regexp "^>[^\n]*\n" nil t)
5389 (setq no-problem (search-forward-regexp "^[ \t]*[^>\n]" nil t)))
5390 (if no-problem
5392 (if (message-gnksa-enable-p 'quoted-text-only)
5393 (y-or-n-p "Your text should follow quoted text. Really post? ")
5394 ;; Ensure that
5395 (goto-char (point-min))
5396 (re-search-forward
5397 (concat "^" (regexp-quote mail-header-separator) "$"))
5398 (if (search-forward-regexp "^[ \t]*[^>\n]" nil t)
5399 (y-or-n-p "Your text should follow quoted text. Really post? ")
5400 (message "Denied posting -- only quoted text.")
5401 nil)))))))
5403 (defun message-checksum ()
5404 "Return a \"checksum\" for the current buffer."
5405 (let ((sum 0))
5406 (save-excursion
5407 (goto-char (point-min))
5408 (re-search-forward
5409 (concat "^" (regexp-quote mail-header-separator) "$"))
5410 (while (not (eobp))
5411 (when (not (looking-at "[ \t\n]"))
5412 (setq sum (logxor (ash sum 1) (if (natnump sum) 0 1)
5413 (char-after))))
5414 (forward-char 1)))
5415 sum))
5417 (defun message-do-fcc ()
5418 "Process Fcc headers in the current buffer."
5419 (let ((case-fold-search t)
5420 (buf (current-buffer))
5421 (mml-externalize-attachments message-fcc-externalize-attachments)
5422 (file (message-field-value "fcc" t))
5423 list)
5424 (when file
5425 (with-temp-buffer
5426 (insert-buffer-substring buf)
5427 (message-clone-locals buf)
5428 (message-encode-message-body)
5429 (save-restriction
5430 (message-narrow-to-headers)
5431 (while (setq file (message-fetch-field "fcc" t))
5432 (push file list)
5433 (message-remove-header "fcc" nil t))
5434 (let ((mail-parse-charset message-default-charset)
5435 (rfc2047-header-encoding-alist
5436 (cons '("Newsgroups" . default)
5437 rfc2047-header-encoding-alist)))
5438 (mail-encode-encoded-word-buffer)))
5439 (goto-char (point-min))
5440 (when (re-search-forward
5441 (concat "^" (regexp-quote mail-header-separator) "$")
5442 nil t)
5443 (replace-match "" t t ))
5444 ;; Process Fcc operations.
5445 (while list
5446 (setq file (pop list))
5447 (if (string-match "^[ \t]*|[ \t]*\\(.*\\)[ \t]*$" file)
5448 ;; Pipe the article to the program in question.
5449 (call-shell-region (point-min) (point-max) (match-string 1 file))
5450 ;; Save the article.
5451 (setq file (expand-file-name file))
5452 (unless (file-exists-p (file-name-directory file))
5453 (make-directory (file-name-directory file) t))
5454 (if (and message-fcc-handler-function
5455 (not (eq message-fcc-handler-function 'rmail-output)))
5456 (funcall message-fcc-handler-function file)
5457 ;; FIXME this option, rmail-output (also used if
5458 ;; message-fcc-handler-function is nil) is not
5459 ;; documented anywhere AFAICS. It should work in Emacs
5460 ;; 23; I suspect it does not work in Emacs 22.
5461 ;; FIXME I don't see the need for the two different cases here.
5462 ;; mail-use-rfc822 makes no difference (in Emacs 23),and
5463 ;; the third argument just controls \"Wrote file\" message.
5464 (if (and (file-readable-p file) (mail-file-babyl-p file))
5465 (rmail-output file 1 nil t)
5466 (let ((mail-use-rfc822 t))
5467 (rmail-output file 1 t t))))))))))
5469 (defun message-output (filename)
5470 "Append this article to Unix/babyl mail file FILENAME."
5471 (if (or (and (file-readable-p filename)
5472 (mail-file-babyl-p filename))
5473 ;; gnus-output-to-mail does the wrong thing with live, mbox
5474 ;; Rmail buffers in Emacs 23.
5475 ;; http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=597255
5476 (let ((buff (find-buffer-visiting filename)))
5477 (and buff (with-current-buffer buff
5478 (eq major-mode 'rmail-mode)))))
5479 (gnus-output-to-rmail filename t)
5480 (gnus-output-to-mail filename t)))
5482 (defun message-cleanup-headers ()
5483 "Do various automatic cleanups of the headers."
5484 ;; Remove empty lines in the header.
5485 (save-restriction
5486 (message-narrow-to-headers)
5487 ;; Remove blank lines.
5488 (while (re-search-forward "^[ \t]*\n" nil t)
5489 (replace-match "" t t))
5491 ;; Correct Newsgroups and Followup-To headers: Change sequence of
5492 ;; spaces to comma and eliminate spaces around commas. Eliminate
5493 ;; embedded line breaks.
5494 (goto-char (point-min))
5495 (while (re-search-forward "^\\(Newsgroups\\|Followup-To\\): +" nil t)
5496 (save-restriction
5497 (narrow-to-region
5498 (point)
5499 (if (re-search-forward "^[^ \t]" nil t)
5500 (match-beginning 0)
5501 (forward-line 1)
5502 (point)))
5503 (goto-char (point-min))
5504 (while (re-search-forward "\n[ \t]+" nil t)
5505 (replace-match " " t t)) ;No line breaks (too confusing)
5506 (goto-char (point-min))
5507 (while (re-search-forward "[ \t\n]*,[ \t\n]*\\|[ \t]+" nil t)
5508 (replace-match "," t t))
5509 (goto-char (point-min))
5510 ;; Remove trailing commas.
5511 (when (re-search-forward ",+$" nil t)
5512 (replace-match "" t t))))))
5514 (defun message-make-date (&optional now)
5515 "Make a valid data header.
5516 If NOW, use that time instead."
5517 (let ((system-time-locale "C"))
5518 (format-time-string "%a, %d %b %Y %T %z" now)))
5520 (defun message-insert-expires (days)
5521 "Insert the Expires header. Expiry in DAYS days."
5522 (interactive "NExpire article in how many days? ")
5523 (save-excursion
5524 (message-position-on-field "Expires" "X-Draft-From")
5525 (insert (message-make-expires-date days))))
5527 (defun message-make-expires-date (days)
5528 "Make date string for the Expires header. Expiry in DAYS days.
5530 In posting styles use `(\"Expires\" (make-expires-date 30))'."
5531 (let* ((cur (decode-time))
5532 (nday (+ days (nth 3 cur))))
5533 (setf (nth 3 cur) nday)
5534 (message-make-date (apply 'encode-time cur))))
5536 (defun message-make-message-id ()
5537 "Make a unique Message-ID."
5538 (concat "<" (message-unique-id)
5539 (let ((psubject (save-excursion (message-fetch-field "subject")))
5540 (psupersedes
5541 (save-excursion (message-fetch-field "supersedes"))))
5542 (if (or
5543 (and message-reply-headers
5544 (mail-header-references message-reply-headers)
5545 (mail-header-subject message-reply-headers)
5546 psubject
5547 (not (string=
5548 (message-strip-subject-re
5549 (mail-header-subject message-reply-headers))
5550 (message-strip-subject-re psubject))))
5551 (and psupersedes
5552 (string-match "_-_@" psupersedes)))
5553 "_-_" ""))
5554 "@" (message-make-fqdn) ">"))
5556 (defvar message-unique-id-char nil)
5558 ;; If you ever change this function, make sure the new version
5559 ;; cannot generate IDs that the old version could.
5560 ;; You might for example insert a "." somewhere (not next to another dot
5561 ;; or string boundary), or modify the "fsf" string.
5562 (defun message-unique-id ()
5563 ;; Don't use microseconds from (current-time), they may be unsupported.
5564 ;; Instead we use this randomly inited counter.
5565 (setq message-unique-id-char
5566 (% (1+ (or message-unique-id-char
5567 (random (ash 1 20))))
5568 ;; (current-time) returns 16-bit ints,
5569 ;; and 2^16*25 just fits into 4 digits i base 36.
5570 (* 25 25)))
5571 (let ((tm (current-time)))
5572 (concat
5573 (if (or (eq system-type 'ms-dos)
5574 ;; message-number-base36 doesn't handle bigints.
5575 (floatp (user-uid)))
5576 (let ((user (downcase (user-login-name))))
5577 (while (string-match "[^a-z0-9_]" user)
5578 (aset user (match-beginning 0) ?_))
5579 user)
5580 (message-number-base36 (user-uid) -1))
5581 (message-number-base36 (+ (car tm)
5582 (ash (% message-unique-id-char 25) 16)) 4)
5583 (message-number-base36 (+ (nth 1 tm)
5584 (ash (/ message-unique-id-char 25) 16)) 4)
5585 ;; Append a given name, because while the generated ID is unique
5586 ;; to this newsreader, other newsreaders might otherwise generate
5587 ;; the same ID via another algorithm.
5588 ".fsf")))
5590 (defun message-number-base36 (num len)
5591 (if (if (< len 0)
5592 (<= num 0)
5593 (= len 0))
5595 (concat (message-number-base36 (/ num 36) (1- len))
5596 (char-to-string (aref "zyxwvutsrqponmlkjihgfedcba9876543210"
5597 (% num 36))))))
5599 (defun message-make-organization ()
5600 "Make an Organization header."
5601 (let* ((organization
5602 (when message-user-organization
5603 (if (functionp message-user-organization)
5604 (funcall message-user-organization)
5605 message-user-organization))))
5606 (with-temp-buffer
5607 (mm-enable-multibyte)
5608 (cond ((stringp organization)
5609 (insert organization))
5610 ((and (eq t organization)
5611 message-user-organization-file
5612 (file-exists-p message-user-organization-file))
5613 (insert-file-contents message-user-organization-file)))
5614 (goto-char (point-min))
5615 (while (re-search-forward "[\t\n]+" nil t)
5616 (replace-match "" t t))
5617 (unless (zerop (buffer-size))
5618 (buffer-string)))))
5620 (defun message-make-lines ()
5621 "Count the number of lines and return numeric string."
5622 (save-excursion
5623 (save-restriction
5624 (widen)
5625 (message-goto-body)
5626 (int-to-string (count-lines (point) (point-max))))))
5628 (defun message-make-references ()
5629 "Return the References header for this message."
5630 (when message-reply-headers
5631 (let ((message-id (mail-header-id message-reply-headers))
5632 (references (mail-header-references message-reply-headers)))
5633 (if (or references message-id)
5634 (concat (or references "") (and references " ")
5635 (or message-id ""))
5636 nil))))
5638 (defun message-make-in-reply-to ()
5639 "Return the In-Reply-To header for this message."
5640 (when message-reply-headers
5641 (let ((from (mail-header-from message-reply-headers))
5642 (date (mail-header-date message-reply-headers))
5643 (msg-id (mail-header-id message-reply-headers)))
5644 (when from
5645 (let ((name (mail-extract-address-components from)))
5646 (concat
5647 msg-id (if msg-id " (")
5648 (if (car name)
5649 (if (string-match "[^\000-\177]" (car name))
5650 ;; Quote a string containing non-ASCII characters.
5651 ;; It will make the RFC2047 encoder cause an error
5652 ;; if there are special characters.
5653 (mm-with-multibyte-buffer
5654 (insert (car name))
5655 (goto-char (point-min))
5656 (while (search-forward "\"" nil t)
5657 (when (prog2
5658 (backward-char)
5659 (zerop (% (skip-chars-backward "\\\\") 2))
5660 (goto-char (match-beginning 0)))
5661 (insert "\\"))
5662 (forward-char))
5663 ;; Those quotes will be removed by the RFC2047 encoder.
5664 (concat "\"" (buffer-string) "\""))
5665 (car name))
5666 (nth 1 name))
5667 "'s message of \""
5668 (if (or (not date) (string= date ""))
5669 "(unknown date)" date)
5670 "\"" (if msg-id ")")))))))
5672 (defun message-make-distribution ()
5673 "Make a Distribution header."
5674 (let ((orig-distribution (message-fetch-reply-field "distribution")))
5675 (cond ((functionp message-distribution-function)
5676 (funcall message-distribution-function))
5677 (t orig-distribution))))
5679 (defun message-make-expires ()
5680 "Return an Expires header based on `message-expires'."
5681 (let ((current (current-time))
5682 (future (* 1.0 message-expires 60 60 24)))
5683 ;; Add the future to current.
5684 (setcar current (+ (car current) (round (/ future (expt 2 16)))))
5685 (setcar (cdr current) (+ (nth 1 current) (% (round future) (expt 2 16))))
5686 (message-make-date current)))
5688 (defun message-make-path ()
5689 "Return uucp path."
5690 (let ((login-name (user-login-name)))
5691 (cond ((null message-user-path)
5692 (concat (system-name) "!" login-name))
5693 ((stringp message-user-path)
5694 ;; Support GENERICPATH. Suggested by vixie@decwrl.dec.com.
5695 (concat message-user-path "!" login-name))
5696 (t login-name))))
5698 (defun message-make-from (&optional name address)
5699 "Make a From header."
5700 (let* ((style message-from-style)
5701 (login (or address (message-make-address)))
5702 (fullname (or name user-full-name (user-full-name))))
5703 (when (string= fullname "&")
5704 (setq fullname (user-login-name)))
5705 (with-temp-buffer
5706 (mm-enable-multibyte)
5707 (cond
5708 ((or (null style)
5709 (equal fullname ""))
5710 (insert login))
5711 ((or (eq style 'angles)
5712 (and (not (eq style 'parens))
5713 ;; Use angles if no quoting is needed, or if parens would
5714 ;; need quoting too.
5715 (or (not (string-match "[^- !#-'*+/-9=?A-Z^-~]" fullname))
5716 (let ((tmp (concat fullname nil)))
5717 (while (string-match "([^()]*)" tmp)
5718 (aset tmp (match-beginning 0) ?-)
5719 (aset tmp (1- (match-end 0)) ?-))
5720 (string-match "[\\()]" tmp)))))
5721 (insert fullname)
5722 (goto-char (point-min))
5723 ;; Look for a character that cannot appear unquoted
5724 ;; according to RFC 822.
5725 (when (re-search-forward "[^- !#-'*+/-9=?A-Z^-~]" nil 1)
5726 ;; Quote fullname, escaping specials.
5727 (goto-char (point-min))
5728 (insert "\"")
5729 (while (re-search-forward "[\"\\]" nil 1)
5730 (replace-match "\\\\\\&" t))
5731 (insert "\""))
5732 (insert " <" login ">"))
5733 (t ; 'parens or default
5734 (insert login " (")
5735 (let ((fullname-start (point)))
5736 (insert fullname)
5737 (goto-char fullname-start)
5738 ;; RFC 822 says \ and nonmatching parentheses
5739 ;; must be escaped in comments.
5740 ;; Escape every instance of ()\ ...
5741 (while (re-search-forward "[()\\]" nil 1)
5742 (replace-match "\\\\\\&" t))
5743 ;; ... then undo escaping of matching parentheses,
5744 ;; including matching nested parentheses.
5745 (goto-char fullname-start)
5746 (while (re-search-forward
5747 "\\(\\=\\|[^\\]\\(\\\\\\\\\\)*\\)\\\\(\\(\\([^\\]\\|\\\\\\\\\\)*\\)\\\\)"
5748 nil 1)
5749 (replace-match "\\1(\\3)" t)
5750 (goto-char fullname-start)))
5751 (insert ")")))
5752 (buffer-string))))
5754 (defun message-make-sender ()
5755 "Return the \"real\" user address.
5756 This function tries to ignore all user modifications, and
5757 give as trustworthy answer as possible."
5758 (concat (user-login-name) "@" (system-name)))
5760 (defun message-make-address ()
5761 "Make the address of the user."
5762 (or (message-user-mail-address)
5763 (concat (user-login-name) "@" (message-make-domain))))
5765 (defun message-user-mail-address ()
5766 "Return the pertinent part of `user-mail-address'."
5767 (when (and user-mail-address
5768 (string-match "@.*\\." user-mail-address))
5769 (if (string-match " " user-mail-address)
5770 (nth 1 (mail-extract-address-components user-mail-address))
5771 user-mail-address)))
5773 (defun message-sendmail-envelope-from ()
5774 "Return the envelope from."
5775 (cond ((eq message-sendmail-envelope-from 'header)
5776 (nth 1 (mail-extract-address-components
5777 (message-fetch-field "from"))))
5778 ((stringp message-sendmail-envelope-from)
5779 message-sendmail-envelope-from)
5781 (message-make-address))))
5783 (defun message-make-fqdn ()
5784 "Return user's fully qualified domain name."
5785 (let* ((sysname (system-name))
5786 (user-mail (message-user-mail-address))
5787 (user-domain
5788 (if (and user-mail
5789 (string-match "@\\(.*\\)\\'" user-mail))
5790 (match-string 1 user-mail)))
5791 (case-fold-search t))
5792 (cond
5793 ((and message-user-fqdn
5794 (stringp message-user-fqdn)
5795 (not (string-match message-bogus-system-names message-user-fqdn)))
5796 ;; `message-user-fqdn' seems to be valid
5797 message-user-fqdn)
5798 ;; A system name without any dots is unlikely to be a good fully
5799 ;; qualified domain name.
5800 ((and (string-match "[.]" sysname)
5801 (not (string-match message-bogus-system-names sysname)))
5802 ;; `system-name' returned the right result.
5803 sysname)
5804 ;; Try `mail-host-address'.
5805 ((and (stringp mail-host-address)
5806 (not (string-match message-bogus-system-names mail-host-address)))
5807 mail-host-address)
5808 ;; We try `user-mail-address' as a backup.
5809 ((and user-domain
5810 (stringp user-domain)
5811 (not (string-match message-bogus-system-names user-domain)))
5812 user-domain)
5813 ;; Default to this bogus thing.
5815 (concat sysname
5816 ".i-did-not-set--mail-host-address--so-tickle-me")))))
5818 (defun message-make-domain ()
5819 "Return the domain name."
5820 (or mail-host-address
5821 (message-make-fqdn)))
5823 (defun message-to-list-only ()
5824 "Send a message to the list only.
5825 Remove all addresses but the list address from To and Cc headers."
5826 (interactive)
5827 (let ((listaddr (message-make-mail-followup-to t)))
5828 (when listaddr
5829 (save-excursion
5830 (message-remove-header "to")
5831 (message-remove-header "cc")
5832 (message-position-on-field "To" "X-Draft-From")
5833 (insert listaddr)))))
5835 (defun message-make-mail-followup-to (&optional only-show-subscribed)
5836 "Return the Mail-Followup-To header.
5837 If passed the optional argument ONLY-SHOW-SUBSCRIBED only return the
5838 subscribed address (and not the additional To and Cc header contents)."
5839 (let* ((case-fold-search t)
5840 (to (message-fetch-field "To"))
5841 (cc (message-fetch-field "cc"))
5842 (msg-recipients (concat to (and to cc ", ") cc))
5843 (recipients
5844 (mapcar 'mail-strip-quoted-names
5845 (message-tokenize-header msg-recipients)))
5846 (file-regexps
5847 (if message-subscribed-address-file
5848 (let (begin end item re)
5849 (save-excursion
5850 (with-temp-buffer
5851 (insert-file-contents message-subscribed-address-file)
5852 (while (not (eobp))
5853 (setq begin (point))
5854 (forward-line 1)
5855 (setq end (point))
5856 (if (bolp) (setq end (1- end)))
5857 (setq item (regexp-quote (buffer-substring begin end)))
5858 (if re (setq re (concat re "\\|" item))
5859 (setq re (concat "\\`\\(" item))))
5860 (and re (list (concat re "\\)\\'"))))))))
5861 (mft-regexps (apply 'append message-subscribed-regexps
5862 (mapcar 'regexp-quote
5863 message-subscribed-addresses)
5864 file-regexps
5865 (mapcar 'funcall
5866 message-subscribed-address-functions))))
5867 (save-match-data
5868 (let ((list
5869 (cl-loop for recipient in recipients
5870 when (cl-loop for regexp in mft-regexps
5871 thereis (string-match regexp recipient))
5872 return recipient)))
5873 (when list
5874 (if only-show-subscribed
5875 list
5876 msg-recipients))))))
5878 (defun message-idna-to-ascii-rhs-1 (header)
5879 "Interactively potentially IDNA encode domain names in HEADER."
5880 (let ((field (message-fetch-field header))
5881 ace)
5882 (when field
5883 (dolist (rhs
5884 (delete-dups
5885 (mapcar (lambda (rhs) (or (cadr (split-string rhs "@")) ""))
5886 (mapcar 'downcase
5887 (mapcar
5888 (lambda (elem)
5889 (or (cadr elem)
5890 ""))
5891 (mail-extract-address-components field t))))))
5892 ;; Note that `rhs' will be "" if the address does not have
5893 ;; the domain part, i.e., if it is a local user's address.
5894 (setq ace (if (string-match "\\`[[:ascii:]]*\\'" rhs)
5896 (downcase (puny-encode-domain rhs))))
5897 (when (and (not (equal rhs ace))
5898 (or (not (eq message-use-idna 'ask))
5899 (y-or-n-p (format "Replace %s with %s in %s:? "
5900 rhs ace header))))
5901 (goto-char (point-min))
5902 (while (re-search-forward (concat "^" header ":") nil t)
5903 (message-narrow-to-field)
5904 (while (search-forward (concat "@" rhs) nil t)
5905 (replace-match (concat "@" ace) t t))
5906 (goto-char (point-max))
5907 (widen)))))))
5909 (defun message-idna-to-ascii-rhs ()
5910 "Possibly IDNA encode non-ASCII domain names in From:, To: and Cc: headers.
5911 See `message-idna-encode'."
5912 (interactive)
5913 (when message-use-idna
5914 (save-excursion
5915 (save-restriction
5916 ;; `message-narrow-to-head' that recognizes only the first empty
5917 ;; line as the message header separator used to be used here.
5918 ;; However, since there is the "--text follows this line--" line
5919 ;; normally, it failed in narrowing to the headers and potentially
5920 ;; caused the IDNA encoding on lines that look like headers in
5921 ;; the message body.
5922 (message-narrow-to-headers-or-head)
5923 (message-idna-to-ascii-rhs-1 "From")
5924 (message-idna-to-ascii-rhs-1 "To")
5925 (message-idna-to-ascii-rhs-1 "Reply-To")
5926 (message-idna-to-ascii-rhs-1 "Mail-Reply-To")
5927 (message-idna-to-ascii-rhs-1 "Mail-Followup-To")
5928 (message-idna-to-ascii-rhs-1 "Cc")))))
5930 (defun message-generate-headers (headers)
5931 "Prepare article HEADERS.
5932 Headers already prepared in the buffer are not modified."
5933 (setq headers (append headers message-required-headers))
5934 (save-restriction
5935 (message-narrow-to-headers)
5936 (let* ((header-values
5937 (list 'Date (message-make-date)
5938 'Message-ID (message-make-message-id)
5939 'Organization (message-make-organization)
5940 'From (message-make-from)
5941 'Path (message-make-path)
5942 'Subject nil
5943 'Newsgroups nil
5944 'In-Reply-To (message-make-in-reply-to)
5945 'References (message-make-references)
5946 'To nil
5947 'Distribution (message-make-distribution)
5948 'Lines (message-make-lines)
5949 'User-Agent message-newsreader
5950 'Expires (message-make-expires)))
5951 (case-fold-search t)
5952 (optionalp nil)
5953 header value elem header-string)
5954 ;; First we remove any old generated headers.
5955 (let ((headers message-deletable-headers))
5956 (unless (buffer-modified-p)
5957 (setq headers (delq 'Message-ID (copy-sequence headers))))
5958 (while headers
5959 (goto-char (point-min))
5960 (and (re-search-forward
5961 (concat "^" (symbol-name (car headers)) ": *") nil t)
5962 (get-text-property (1+ (match-beginning 0)) 'message-deletable)
5963 (message-delete-line))
5964 (pop headers)))
5965 ;; Go through all the required headers and see if they are in the
5966 ;; articles already. If they are not, or are empty, they are
5967 ;; inserted automatically - except for Subject, Newsgroups and
5968 ;; Distribution.
5969 (while headers
5970 (goto-char (point-min))
5971 (setq elem (pop headers))
5972 (if (consp elem)
5973 (if (eq (car elem) 'optional)
5974 (setq header (cdr elem)
5975 optionalp t)
5976 (setq header (car elem)))
5977 (setq header elem))
5978 (setq header-string (if (stringp header)
5979 header
5980 (symbol-name header)))
5981 (when (or (not (re-search-forward
5982 (concat "^"
5983 (regexp-quote (downcase header-string))
5984 ":")
5985 nil t))
5986 (progn
5987 ;; The header was found. We insert a space after the
5988 ;; colon, if there is none.
5989 (if (/= (char-after) ? ) (insert " ") (forward-char 1))
5990 ;; Find out whether the header is empty.
5991 (looking-at "[ \t]*\n[^ \t]")))
5992 ;; So we find out what value we should insert.
5993 (setq value
5994 (cond
5995 ((and (consp elem)
5996 (eq (car elem) 'optional)
5997 (not (member header-string message-inserted-headers)))
5998 ;; This is an optional header. If the cdr of this
5999 ;; is something that is nil, then we do not insert
6000 ;; this header.
6001 (setq header (cdr elem))
6002 (or (and (functionp (cdr elem))
6003 (funcall (cdr elem)))
6004 (and (symbolp (cdr elem))
6005 (plist-get header-values (cdr elem)))))
6006 ((consp elem)
6007 ;; The element is a cons. Either the cdr is a
6008 ;; string to be inserted verbatim, or it is a
6009 ;; function, and we insert the value returned from
6010 ;; this function.
6011 (or (and (stringp (cdr elem))
6012 (cdr elem))
6013 (and (functionp (cdr elem))
6014 (funcall (cdr elem)))))
6015 ((and (symbolp header)
6016 (plist-member header-values header))
6017 ;; The element is a symbol. We insert the value of
6018 ;; this symbol, if any.
6019 (plist-get header-values header))
6020 ((not (message-check-element
6021 (intern (downcase (symbol-name header)))))
6022 ;; We couldn't generate a value for this header,
6023 ;; so we just ask the user.
6024 (read-from-minibuffer
6025 (format "Empty header for %s; enter value: " header)))))
6026 ;; Finally insert the header.
6027 (when (and value
6028 (not (equal value "")))
6029 (save-excursion
6030 (if (bolp)
6031 (progn
6032 ;; This header didn't exist, so we insert it.
6033 (goto-char (point-max))
6034 (let ((formatter
6035 (cdr (assq header message-header-format-alist))))
6036 (if formatter
6037 (funcall formatter header value)
6038 (insert header-string ": " value))
6039 (push header-string message-inserted-headers)
6040 (goto-char (message-fill-field))
6041 ;; We check whether the value was ended by a
6042 ;; newline. If not, we insert one.
6043 (unless (bolp)
6044 (insert "\n"))
6045 (forward-line -1)))
6046 ;; The value of this header was empty, so we clear
6047 ;; totally and insert the new value.
6048 (delete-region (point) (point-at-eol))
6049 ;; If the header is optional, and the header was
6050 ;; empty, we can't insert it anyway.
6051 (unless optionalp
6052 (push header-string message-inserted-headers)
6053 (insert value)
6054 (message-fill-field)))
6055 ;; Add the deletable property to the headers that require it.
6056 (and (memq header message-deletable-headers)
6057 (progn (beginning-of-line) (looking-at "[^:]+: "))
6058 (add-text-properties
6059 (point) (match-end 0)
6060 '(message-deletable t face italic) (current-buffer)))))))
6061 ;; Insert new Sender if the From is strange.
6062 (let ((from (message-fetch-field "from"))
6063 (sender (message-fetch-field "sender"))
6064 (secure-sender (message-make-sender)))
6065 (when (and from
6066 (not (message-check-element 'sender))
6067 (not (string=
6068 (downcase
6069 (cadr (mail-extract-address-components from)))
6070 (downcase secure-sender)))
6071 (or (null sender)
6072 (not
6073 (string=
6074 (downcase
6075 (cadr (mail-extract-address-components sender)))
6076 (downcase secure-sender)))))
6077 (goto-char (point-min))
6078 ;; Rename any old Sender headers to Original-Sender.
6079 (when (re-search-forward "^\\(Original-\\)*Sender:" nil t)
6080 (beginning-of-line)
6081 (insert "Original-")
6082 (beginning-of-line))
6083 (when (or (message-news-p)
6084 (string-match "@.+\\.." secure-sender))
6085 (insert "Sender: " secure-sender "\n"))))
6086 ;; Check for IDNA
6087 (message-idna-to-ascii-rhs))))
6089 (defun message-insert-courtesy-copy (message)
6090 "Insert a courtesy message in mail copies of combined messages."
6091 (let (newsgroups)
6092 (save-excursion
6093 (save-restriction
6094 (message-narrow-to-headers)
6095 (when (setq newsgroups (message-fetch-field "newsgroups"))
6096 (goto-char (point-max))
6097 (insert "Posted-To: " newsgroups "\n")))
6098 (forward-line 1)
6099 (when message
6100 (cond
6101 ((string-match "%s" message)
6102 (insert (format message newsgroups)))
6104 (insert message)))))))
6107 ;;; Setting up a message buffer
6110 (defun message-skip-to-next-address ()
6111 (let ((end (save-excursion
6112 (message-next-header)
6113 (point)))
6114 quoted char)
6115 (when (looking-at ",")
6116 (forward-char 1))
6117 (while (and (not (= (point) end))
6118 (or (not (eq char ?,))
6119 quoted))
6120 (skip-chars-forward "^,\"" end)
6121 (when (eq (setq char (following-char)) ?\")
6122 (setq quoted (not quoted)))
6123 (unless (= (point) end)
6124 (forward-char 1)))
6125 (skip-chars-forward " \t\n")))
6127 (defun message-split-line ()
6128 "Split current line, moving portion beyond point vertically down.
6129 If the current line has `message-yank-prefix', insert it on the new line."
6130 (interactive "*")
6131 (split-line message-yank-prefix))
6133 (defun message-insert-header (header value)
6134 (insert (capitalize (symbol-name header))
6135 ": "
6136 (if (consp value) (car value) value)))
6138 (defun message-field-name ()
6139 (save-excursion
6140 (goto-char (point-min))
6141 (when (looking-at "\\([^:]+\\):")
6142 (intern (capitalize (match-string 1))))))
6144 (defun message-fill-field ()
6145 (save-excursion
6146 (save-restriction
6147 (message-narrow-to-field)
6148 (let ((field-name (message-field-name)))
6149 (funcall (or (cadr (assq field-name message-field-fillers))
6150 'message-fill-field-general)))
6151 (point-max))))
6153 (defun message-fill-field-address ()
6154 (let (end last)
6155 (while (not end)
6156 (message-skip-to-next-address)
6157 (cond ((bolp)
6158 (end-of-line 0)
6159 (setq end 1))
6160 ((eobp)
6161 (setq end 0)))
6162 (when (and (> (current-column) 78)
6163 last)
6164 (save-excursion
6165 (goto-char last)
6166 (delete-char (- (skip-chars-backward " \t")))
6167 (insert "\n\t")))
6168 (setq last (point)))
6169 (forward-line end)))
6171 (defun message-fill-field-general ()
6172 (let ((begin (point))
6173 (fill-column 78)
6174 (fill-prefix "\t"))
6175 (while (and (search-forward "\n" nil t)
6176 (not (eobp)))
6177 (replace-match " " t t))
6178 (fill-region-as-paragraph begin (point-max))
6179 ;; Tapdance around looong Message-IDs.
6180 (forward-line -1)
6181 (when (looking-at "[ \t]*$")
6182 (message-delete-line))
6183 (goto-char begin)
6184 (search-forward ":" nil t)
6185 (when (looking-at "\n[ \t]+")
6186 (replace-match " " t t))
6187 (goto-char (point-max))))
6189 (defun message-shorten-1 (list cut surplus)
6190 "Cut SURPLUS elements out of LIST, beginning with CUTth one."
6191 (setcdr (nthcdr (- cut 2) list)
6192 (nthcdr (+ (- cut 2) surplus 1) list)))
6194 (defun message-shorten-references (header references)
6195 "Trim REFERENCES to be 21 Message-ID long or less, and fold them.
6196 When sending via news, also check that the REFERENCES are less
6197 than 988 characters long, and if they are not, trim them until
6198 they are."
6199 ;; 21 is the number suggested by USAGE.
6200 (let ((maxcount 21)
6201 (count 0)
6202 (cut 2)
6203 refs)
6204 (with-temp-buffer
6205 (insert references)
6206 (goto-char (point-min))
6207 ;; Cons a list of valid references. GNKSA says we must not include MIDs
6208 ;; with whitespace or missing brackets (7.a "Does not propagate broken
6209 ;; Message-IDs in original References").
6210 (while (re-search-forward "<[^ <]+@[^ <]+>" nil t)
6211 (push (match-string 0) refs))
6212 (setq refs (nreverse refs)
6213 count (length refs)))
6215 ;; If the list has more than MAXCOUNT elements, trim it by
6216 ;; removing the CUTth element and the required number of
6217 ;; elements that follow.
6218 (when (> count maxcount)
6219 (let ((surplus (- count maxcount)))
6220 (message-shorten-1 refs cut surplus)
6221 (cl-decf count surplus)))
6223 ;; When sending via news, make sure the total folded length will
6224 ;; be less than 998 characters. This is to cater to broken INN
6225 ;; 2.3 which counts the total number of characters in a header
6226 ;; rather than the physical line length of each line, as it should.
6228 ;; This hack should be removed when it's believed than INN 2.3 is
6229 ;; no longer widely used.
6231 ;; At this point the headers have not been generated, thus we use
6232 ;; message-this-is-news directly.
6233 (when message-this-is-news
6234 (while (< 998
6235 (with-temp-buffer
6236 (message-insert-header
6237 header (mapconcat #'identity refs " "))
6238 (buffer-size)))
6239 (message-shorten-1 refs cut 1)))
6240 ;; Finally, collect the references back into a string and insert
6241 ;; it into the buffer.
6242 (message-insert-header header (mapconcat #'identity refs " "))))
6244 (defun message-position-point ()
6245 "Move point to where the user probably wants to find it."
6246 (message-narrow-to-headers)
6247 (cond
6248 ((re-search-forward "^[^:]+:[ \t]*$" nil t)
6249 (search-backward ":" )
6250 (widen)
6251 (forward-char 1)
6252 (if (eq (char-after) ? )
6253 (forward-char 1)
6254 (insert " ")))
6256 (goto-char (point-max))
6257 (widen)
6258 (forward-line 1)
6259 (unless (looking-at "$")
6260 (forward-line 2)))
6261 (sit-for 0)))
6263 (defcustom message-beginning-of-line t
6264 "Whether \\<message-mode-map>\\[message-beginning-of-line]\
6265 goes to beginning of header values."
6266 :version "22.1"
6267 :group 'message-buffers
6268 :link '(custom-manual "(message)Movement")
6269 :type 'boolean)
6271 (defvar visual-line-mode)
6272 (declare-function beginning-of-visual-line "simple" (&optional n))
6274 (defun message-beginning-of-header (handle-folded)
6275 "Move point to beginning of header's value.
6277 When point is at the first header line, moves it after the colon
6278 and spaces separating header name and header value.
6280 When point is in a continuation line of a folded header (i.e. the
6281 line starts with a space), the behavior depends on HANDLE-FOLDED
6282 argument. If it's nil, function moves the point to the start of
6283 the header continuation; otherwise, function locates the
6284 beginning of the header and moves point past the colon as is the
6285 case of single-line headers.
6287 No check whether point is inside of a header or body of the
6288 message is performed.
6290 Returns point or nil if beginning of header's value could not be
6291 found. In the latter case, the point is still moved to the
6292 beginning of line (possibly after attempting to move it to the
6293 beginning of a folded header)."
6294 ;; https://www.rfc-editor.org/rfc/rfc2822.txt, section 2.2.3. says that when
6295 ;; unfolding a single WSP should be consumed. WSP is defined as a space
6296 ;; character or a horizontal tab.
6297 (beginning-of-line)
6298 (when handle-folded
6299 (while (and (> (point) (point-min))
6300 (or (eq (char-after) ?\s) (eq (char-after) ?\t)))
6301 (beginning-of-line 0)))
6302 (when (or (eq (char-after) ?\s) (eq (char-after) ?\t)
6303 (search-forward ":" (point-at-eol) t))
6304 ;; We are a bit more lacks than the RFC and allow any positive number of WSP
6305 ;; characters.
6306 (skip-chars-forward " \t" (point-at-eol))
6307 (point)))
6309 (defun message-beginning-of-line (&optional n)
6310 "Move point to beginning of header value or to beginning of line.
6311 The prefix argument N is passed directly to `beginning-of-line'.
6313 This command is identical to `beginning-of-line' if point is
6314 outside the message header or if the option
6315 `message-beginning-of-line' is nil.
6317 If point is in the message header and on a header line, move
6318 point to the beginning of the header value or the beginning of
6319 line, whichever is closer. If point is already at beginning of
6320 line, move point to beginning of header value. Therefore,
6321 repeated calls will toggle point between beginning of field and
6322 beginning of line.
6324 When called without a prefix argument, header value spanning
6325 multiple lines is treated as a single line. Otherwise, even if
6326 N is 1, when point is on a continuation header line, it will be
6327 moved to the beginning "
6328 (interactive "p")
6329 (cond
6330 ;; Go to beginning of header or beginning of line.
6331 ((and message-beginning-of-line (message-point-in-header-p))
6332 (let* ((point (point))
6333 (bol (progn (beginning-of-line n) (point)))
6334 (boh (message-beginning-of-header visual-line-mode)))
6335 (goto-char (if (and boh (or (< boh point) (= bol point))) boh bol))))
6336 ;; Go to beginning of visual line
6337 (visual-line-mode
6338 (beginning-of-visual-line n))
6339 ;; Go to beginning of line.
6340 ((beginning-of-line n))))
6342 (defun message-buffer-name (type &optional to group)
6343 "Return a new (unique) buffer name based on TYPE and TO."
6344 (cond
6345 ;; Generate a new buffer name The Message Way.
6346 ((memq message-generate-new-buffers '(unique t))
6347 (generate-new-buffer-name
6348 (concat "*" type
6349 (if to
6350 (concat " to "
6351 (or (car (mail-extract-address-components to))
6352 to) "")
6354 (if (and group (not (string= group ""))) (concat " on " group) "")
6355 "*")))
6356 ;; Check whether `message-generate-new-buffers' is a function,
6357 ;; and if so, call it.
6358 ((functionp message-generate-new-buffers)
6359 (funcall message-generate-new-buffers type to group))
6360 ((eq message-generate-new-buffers 'unsent)
6361 (generate-new-buffer-name
6362 (concat "*unsent " type
6363 (if to
6364 (concat " to "
6365 (or (car (mail-extract-address-components to))
6366 to) "")
6368 (if (and group (not (string= group ""))) (concat " on " group) "")
6369 "*")))
6370 ;; Search for the existing message buffer with the specified name.
6372 (let* ((new (if (eq message-generate-new-buffers 'standard)
6373 (generate-new-buffer-name (concat "*" type " message*"))
6374 (let ((message-generate-new-buffers 'unique))
6375 (message-buffer-name type to group))))
6376 (regexp (concat "\\`"
6377 (regexp-quote
6378 (if (string-match "<[0-9]+>\\'" new)
6379 (substring new 0 (match-beginning 0))
6380 new))
6381 "\\(?:<\\([0-9]+\\)>\\)?\\'"))
6382 (case-fold-search nil))
6383 (or (cdar
6384 (last
6385 (sort
6386 (delq nil
6387 (mapcar
6388 (lambda (b)
6389 (when (and (string-match regexp (setq b (buffer-name b)))
6390 (eq (with-current-buffer b major-mode)
6391 'message-mode))
6392 (cons (string-to-number (or (match-string 1 b) "1"))
6393 b)))
6394 (buffer-list)))
6395 'car-less-than-car)))
6396 new)))))
6398 (defun message-pop-to-buffer (name &optional switch-function)
6399 "Pop to buffer NAME, and warn if it already exists and is modified."
6400 (let ((buffer (get-buffer name)))
6401 (if (and buffer
6402 (buffer-name buffer))
6403 (let ((window (get-buffer-window buffer 0)))
6404 (if window
6405 ;; Raise the frame already displaying the message buffer.
6406 (progn
6407 (select-frame-set-input-focus (window-frame window))
6408 (select-window window))
6409 (funcall (or switch-function #'pop-to-buffer) buffer)
6410 (set-buffer buffer))
6411 (when (and (buffer-modified-p)
6412 (not (prog1
6413 (y-or-n-p
6414 "Message already being composed; erase? ")
6415 (message nil))))
6416 (error "Message being composed")))
6417 (funcall (or switch-function 'pop-to-buffer-same-window)
6418 name)
6419 (set-buffer name))
6420 (erase-buffer)
6421 (message-mode)))
6423 (defun message-do-send-housekeeping ()
6424 "Kill old message buffers."
6425 ;; We might have sent this buffer already. Delete it from the
6426 ;; list of buffers.
6427 (setq message-buffer-list (delq (current-buffer) message-buffer-list))
6428 (while (and message-max-buffers
6429 message-buffer-list
6430 (>= (length message-buffer-list) message-max-buffers))
6431 ;; Kill the oldest buffer -- unless it has been changed.
6432 (let ((buffer (pop message-buffer-list)))
6433 (when (and (buffer-name buffer)
6434 (not (buffer-modified-p buffer)))
6435 (kill-buffer buffer))))
6436 ;; Rename the buffer.
6437 (if message-send-rename-function
6438 (funcall message-send-rename-function)
6439 (message-default-send-rename-function))
6440 ;; Push the current buffer onto the list.
6441 (when message-max-buffers
6442 (setq message-buffer-list
6443 (nconc message-buffer-list (list (current-buffer))))))
6445 (defun message-default-send-rename-function ()
6446 ;; Note: mail-abbrevs of XEmacs renames buffer name behind Gnus.
6447 (when (string-match
6448 "\\`\\*\\(sent \\|unsent \\)?\\(.+\\)\\*[^\\*]*\\|\\`mail to "
6449 (buffer-name))
6450 (let ((name (match-string 2 (buffer-name)))
6451 to group)
6452 (if (not (or (null name)
6453 (string-equal name "mail")
6454 (string-equal name "posting")))
6455 (setq name (concat "*sent " name "*"))
6456 (message-narrow-to-headers)
6457 (setq to (message-fetch-field "to"))
6458 (setq group (message-fetch-field "newsgroups"))
6459 (widen)
6460 (setq name
6461 (cond
6462 (to (concat "*sent mail to "
6463 (or (car (mail-extract-address-components to))
6464 to) "*"))
6465 ((and group (not (string= group "")))
6466 (concat "*sent posting on " group "*"))
6467 (t "*sent mail*"))))
6468 (unless (string-equal name (buffer-name))
6469 (rename-buffer name t)))))
6471 (defun message-mail-user-agent ()
6472 (let ((mua (cond
6473 ((not message-mail-user-agent) nil)
6474 ((eq message-mail-user-agent t) mail-user-agent)
6475 (t message-mail-user-agent))))
6476 (if (memq mua '(message-user-agent gnus-user-agent))
6478 mua)))
6480 ;; YANK-ACTION, if non-nil, can be a buffer or a yank action of the
6481 ;; form (FUNCTION . ARGS).
6482 (defun message-setup (headers &optional yank-action actions
6483 continue switch-function return-action)
6484 (let ((mua (message-mail-user-agent))
6485 subject to field)
6486 (if (not (and message-this-is-mail mua))
6487 (message-setup-1 headers yank-action actions return-action)
6488 (setq headers (copy-sequence headers))
6489 (setq field (assq 'Subject headers))
6490 (when field
6491 (setq subject (cdr field))
6492 (setq headers (delq field headers)))
6493 (setq field (assq 'To headers))
6494 (when field
6495 (setq to (cdr field))
6496 (setq headers (delq field headers)))
6497 (let ((mail-user-agent mua))
6498 (compose-mail to subject
6499 (mapcar (lambda (item)
6500 (cons
6501 (format "%s" (car item))
6502 (cdr item)))
6503 headers)
6504 continue switch-function
6505 (if (bufferp yank-action)
6506 (list 'insert-buffer yank-action)
6507 yank-action)
6508 actions)))))
6510 (defun message-headers-to-generate (headers included-headers excluded-headers)
6511 "Return a list that includes all headers from HEADERS.
6512 If INCLUDED-HEADERS is a list, just include those headers. If it is
6513 t, include all headers. In any case, headers from EXCLUDED-HEADERS
6514 are not included."
6515 (let ((result nil)
6516 header-name)
6517 (dolist (header headers)
6518 (setq header-name (cond
6519 ((and (consp header)
6520 (eq (car header) 'optional))
6521 ;; On the form (optional . Header)
6522 (cdr header))
6523 ((consp header)
6524 ;; On the form (Header . function)
6525 (car header))
6527 ;; Just a Header.
6528 header)))
6529 (when (and (not (memq header-name excluded-headers))
6530 (or (eq included-headers t)
6531 (memq header-name included-headers)))
6532 (push header result)))
6533 (nreverse result)))
6535 (defun message-setup-1 (headers &optional yank-action actions return-action)
6536 (dolist (action actions)
6537 (condition-case nil
6538 (add-to-list 'message-send-actions
6539 `(apply ',(car action) ',(cdr action)))))
6540 (setq message-return-action return-action)
6541 (setq message-reply-buffer
6542 (if (and (consp yank-action)
6543 (eq (car yank-action) 'insert-buffer))
6544 (nth 1 yank-action)
6545 yank-action))
6546 (goto-char (point-min))
6547 ;; Insert all the headers.
6548 (mail-header-format
6549 (let ((h headers)
6550 (alist message-header-format-alist))
6551 (while h
6552 (unless (assq (caar h) message-header-format-alist)
6553 (push (list (caar h)) alist))
6554 (pop h))
6555 alist)
6556 headers)
6557 (delete-region (point) (progn (forward-line -1) (point)))
6558 (when message-default-headers
6559 (insert
6560 (if (functionp message-default-headers)
6561 (funcall message-default-headers)
6562 message-default-headers))
6563 (or (bolp) (insert ?\n)))
6564 (insert (concat mail-header-separator "\n"))
6565 (forward-line -1)
6566 ;; If a crash happens while replying, the auto-save file would *not* have a
6567 ;; `References:' header if `message-generate-headers-first' was nil.
6568 ;; Therefore, always generate it first.
6569 (let ((message-generate-headers-first
6570 (if (eq message-generate-headers-first t)
6572 (append message-generate-headers-first '(References)))))
6573 (when (message-news-p)
6574 (when message-default-news-headers
6575 (insert message-default-news-headers)
6576 (or (bolp) (insert ?\n)))
6577 (message-generate-headers
6578 (message-headers-to-generate
6579 (append message-required-news-headers
6580 message-required-headers)
6581 message-generate-headers-first
6582 '(Lines Subject))))
6583 (when (message-mail-p)
6584 (when message-default-mail-headers
6585 (insert message-default-mail-headers)
6586 (or (bolp) (insert ?\n)))
6587 (message-generate-headers
6588 (message-headers-to-generate
6589 (append message-required-mail-headers
6590 message-required-headers)
6591 message-generate-headers-first
6592 '(Lines Subject)))))
6593 (run-hooks 'message-signature-setup-hook)
6594 (message-insert-signature)
6595 (save-restriction
6596 (message-narrow-to-headers)
6597 (run-hooks 'message-header-setup-hook))
6598 (setq buffer-undo-list nil)
6599 (when message-generate-hashcash
6600 ;; Generate hashcash headers for recipients already known
6601 (mail-add-payment-async))
6602 ;; Gnus posting styles are applied via buffer-local `message-setup-hook'
6603 ;; values.
6604 (run-hooks 'message-setup-hook)
6605 ;; Do this last to give it precedence over posting styles, etc.
6606 (when (message-mail-p)
6607 (save-restriction
6608 (message-narrow-to-headers)
6609 (if message-alternative-emails
6610 (message-use-alternative-email-as-from))))
6611 (message-position-point)
6612 ;; Allow correct handling of `message-checksum' in `message-yank-original':
6613 (set-buffer-modified-p nil)
6614 (undo-boundary)
6615 ;; rmail-start-mail expects message-mail to return t (Bug#9392)
6618 (defun message-set-auto-save-file-name ()
6619 "Associate the message buffer with a file in the drafts directory."
6620 (when message-auto-save-directory
6621 (unless (file-directory-p
6622 (directory-file-name message-auto-save-directory))
6623 (make-directory message-auto-save-directory t))
6624 (if (gnus-alive-p)
6625 (setq message-draft-article
6626 (nndraft-request-associate-buffer "drafts"))
6628 ;; If Gnus were alive, draft messages would be saved in the drafts folder.
6629 ;; But Gnus is not alive, so arrange to save the draft message in a
6630 ;; regular file in message-auto-save-directory. Append a unique
6631 ;; time-based suffix to the filename to allow multiple drafts to be saved
6632 ;; simultaneously without overwriting each other (which mimics the
6633 ;; functionality of the Gnus drafts folder).
6634 (setq buffer-file-name (expand-file-name
6635 (concat
6636 (if (memq system-type
6637 '(ms-dos windows-nt cygwin))
6638 "message"
6639 "*message*")
6640 (format-time-string "-%Y%m%d-%H%M%S"))
6641 message-auto-save-directory))
6642 (setq buffer-auto-save-file-name (make-auto-save-file-name)))
6643 (clear-visited-file-modtime)
6644 (setq buffer-file-coding-system message-draft-coding-system)))
6646 (defun message-disassociate-draft ()
6647 "Disassociate the message buffer from the drafts directory."
6648 (when message-draft-article
6649 (nndraft-request-expire-articles
6650 (list message-draft-article) "drafts" nil t)))
6652 (defun message-insert-headers ()
6653 "Generate the headers for the article."
6654 (interactive)
6655 (save-excursion
6656 (save-restriction
6657 (message-narrow-to-headers)
6658 (when (message-news-p)
6659 (message-generate-headers
6660 (delq 'Lines
6661 (delq 'Subject
6662 (copy-sequence message-required-news-headers)))))
6663 (when (message-mail-p)
6664 (message-generate-headers
6665 (delq 'Lines
6666 (delq 'Subject
6667 (copy-sequence message-required-mail-headers))))))))
6672 ;;; Commands for interfacing with message
6675 ;;;###autoload
6676 (defun message-mail (&optional to subject other-headers continue
6677 switch-function yank-action send-actions
6678 return-action &rest ignored)
6679 "Start editing a mail message to be sent.
6680 OTHER-HEADERS is an alist of header/value pairs. CONTINUE says whether
6681 to continue editing a message already being composed. SWITCH-FUNCTION
6682 is a function used to switch to and display the mail buffer."
6683 (interactive)
6684 (let ((message-this-is-mail t)
6685 message-buffers)
6686 ;; Search for the existing message buffer if `continue' is non-nil.
6687 (if (and continue
6688 (setq message-buffers (message-buffers)))
6689 (pop-to-buffer (car message-buffers))
6690 ;; Start a new buffer.
6691 (unless (message-mail-user-agent)
6692 (message-pop-to-buffer (message-buffer-name "mail" to) switch-function))
6693 (message-setup
6694 (nconc
6695 `((To . ,(or to "")) (Subject . ,(or subject "")))
6696 ;; C-h f compose-mail says that headers should be specified as
6697 ;; (string . value); however all the rest of message expects
6698 ;; headers to be symbols, not strings (eg message-header-format-alist).
6699 ;; https://lists.gnu.org/r/emacs-devel/2011-01/msg00337.html
6700 ;; We need to convert any string input, eg from rmail-start-mail.
6701 (dolist (h other-headers other-headers)
6702 (if (stringp (car h)) (setcar h (intern (capitalize (car h)))))))
6703 yank-action send-actions continue switch-function
6704 return-action))))
6706 ;;;###autoload
6707 (defun message-news (&optional newsgroups subject)
6708 "Start editing a news article to be sent."
6709 (interactive)
6710 (let ((message-this-is-news t))
6711 (message-pop-to-buffer (message-buffer-name "posting" nil newsgroups))
6712 (message-setup `((Newsgroups . ,(or newsgroups ""))
6713 (Subject . ,(or subject ""))))))
6715 (defun message-alter-recipients-discard-bogus-full-name (addrcell)
6716 "Discard mail address in full names.
6717 When the full name in reply headers contains the mail
6718 address (e.g. \"foo@bar <foo@bar>\"), discard full name.
6719 ADDRCELL is a cons cell where the car is the mail address and the
6720 cdr is the complete address (full name and mail address)."
6721 (if (string-match (concat (regexp-quote (car addrcell)) ".*"
6722 (regexp-quote (car addrcell)))
6723 (cdr addrcell))
6724 (cons (car addrcell) (car addrcell))
6725 addrcell))
6727 (defcustom message-alter-recipients-function nil
6728 "Function called to allow alteration of reply header structures.
6729 It is called in `message-get-reply-headers' for each recipient.
6730 The function is called with one parameter, a cons cell ..."
6731 :type '(choice (const :tag "None" nil)
6732 (const :tag "Discard bogus full name"
6733 message-alter-recipients-discard-bogus-full-name)
6734 function)
6735 :version "23.1" ;; No Gnus
6736 :group 'message-headers)
6738 (defun message-get-reply-headers (wide &optional to-address address-headers)
6739 (let (follow-to mct never-mct to cc author mft recipients extra)
6740 ;; Find all relevant headers we need.
6741 (save-restriction
6742 (message-narrow-to-headers-or-head)
6743 ;; Gmane renames "To". Look at "Original-To", too, if it is present in
6744 ;; message-header-synonyms.
6745 (setq to (or (message-fetch-field "to")
6746 (and (cl-loop for synonym in message-header-synonyms
6747 when (memq 'Original-To synonym)
6748 return t)
6749 (message-fetch-field "original-to")))
6750 cc (message-fetch-field "cc")
6751 extra (when message-extra-wide-headers
6752 (mapconcat 'identity
6753 (mapcar 'message-fetch-field
6754 message-extra-wide-headers)
6755 ", "))
6756 mct (message-fetch-field "mail-copies-to")
6757 author (or (message-fetch-field "mail-reply-to")
6758 (message-fetch-field "reply-to"))
6759 mft (and message-use-mail-followup-to
6760 (message-fetch-field "mail-followup-to")))
6761 ;; Make sure this message goes to the author if this is a wide
6762 ;; reply, since Reply-To address may be a list address a mailing
6763 ;; list server added.
6764 (when (and wide author)
6765 (setq cc (concat author ", " cc)))
6766 (when (or wide (not author))
6767 (setq author (or (message-fetch-field "from") ""))))
6769 ;; Handle special values of Mail-Copies-To.
6770 (when mct
6771 (cond ((or (equal (downcase mct) "never")
6772 (equal (downcase mct) "nobody"))
6773 (setq never-mct t)
6774 (setq mct nil))
6775 ((or (equal (downcase mct) "always")
6776 (equal (downcase mct) "poster"))
6777 (setq mct author))))
6779 (save-match-data
6780 ;; Build (textual) list of new recipient addresses.
6781 (cond
6782 (to-address
6783 (setq recipients (concat ", " to-address))
6784 ;; If the author explicitly asked for a copy, we don't deny it to them.
6785 (if mct (setq recipients (concat recipients ", " mct))))
6786 ((not wide)
6787 (setq recipients (concat ", " author)))
6788 (address-headers
6789 (dolist (header address-headers)
6790 (let ((value (message-fetch-field header)))
6791 (when value
6792 (setq recipients (concat recipients ", " value))))))
6793 ((and mft
6794 (string-match "[^ \t,]" mft)
6795 (or (not (eq message-use-mail-followup-to 'ask))
6796 (message-y-or-n-p "Obey Mail-Followup-To? " t "\
6797 You should normally obey the Mail-Followup-To: header. In this
6798 article, it has the value of
6800 " mft "
6802 which directs your response to " (if (string-match "," mft)
6803 "the specified addresses"
6804 "that address only") ".
6806 Most commonly, Mail-Followup-To is used by a mailing list poster to
6807 express that responses should be sent to just the list, and not the
6808 poster as well.
6810 If a message is posted to several mailing lists, Mail-Followup-To may
6811 also be used to direct the following discussion to one list only,
6812 because discussions that are spread over several lists tend to be
6813 fragmented and very difficult to follow.
6815 Also, some source/announcement lists are not intended for discussion;
6816 responses here are directed to other addresses.
6818 You may customize the variable `message-use-mail-followup-to', if you
6819 want to get rid of this query permanently.")))
6820 (setq recipients (concat ", " mft)))
6822 (setq recipients (if never-mct "" (concat ", " author)))
6823 (if to (setq recipients (concat recipients ", " to)))
6824 (if cc (setq recipients (concat recipients ", " cc)))
6825 (if extra (setq recipients (concat recipients ", " extra)))
6826 (if mct (setq recipients (concat recipients ", " mct)))))
6827 (if (>= (length recipients) 2)
6828 ;; Strip the leading ", ".
6829 (setq recipients (substring recipients 2)))
6830 ;; Squeeze whitespace.
6831 (while (string-match "[ \t][ \t]+" recipients)
6832 (setq recipients (replace-match " " t t recipients)))
6833 ;; Remove addresses that match `message-dont-reply-to-names'.
6834 (setq recipients
6835 (cond ((functionp message-dont-reply-to-names)
6836 (mapconcat
6837 'identity
6838 (delq nil
6839 (mapcar (lambda (mail)
6840 (unless (funcall message-dont-reply-to-names
6841 (mail-strip-quoted-names mail))
6842 mail))
6843 (message-tokenize-header recipients)))
6844 ", "))
6845 (t (let ((mail-dont-reply-to-names (message-dont-reply-to-names)))
6846 (mail-dont-reply-to recipients)))))
6847 ;; Perhaps "Mail-Copies-To: never" removed the only address?
6848 (if (string-equal recipients "")
6849 (setq recipients author))
6850 ;; Convert string to a list of (("foo@bar" . "Name <Foo@BAR>") ...).
6851 (setq recipients
6852 (mapcar
6853 (lambda (addr)
6854 (if message-alter-recipients-function
6855 (funcall message-alter-recipients-function
6856 (cons (downcase (mail-strip-quoted-names addr))
6857 addr))
6858 (cons (downcase (mail-strip-quoted-names addr)) addr)))
6859 (message-tokenize-header recipients)))
6860 ;; Remove all duplicates.
6861 (let ((s recipients))
6862 (while s
6863 (let ((address (car (pop s))))
6864 (while (assoc address s)
6865 (setq recipients (delq (assoc address s) recipients)
6866 s (delq (assoc address s) s))))))
6868 ;; Remove hierarchical lists that are contained within each other,
6869 ;; if message-hierarchical-addresses is defined.
6870 (when message-hierarchical-addresses
6871 (let ((plain-addrs (mapcar 'car recipients))
6872 subaddrs recip)
6873 (while plain-addrs
6874 (setq subaddrs (assoc (car plain-addrs)
6875 message-hierarchical-addresses)
6876 plain-addrs (cdr plain-addrs))
6877 (when subaddrs
6878 (setq subaddrs (cdr subaddrs))
6879 (while subaddrs
6880 (setq recip (assoc (car subaddrs) recipients)
6881 subaddrs (cdr subaddrs))
6882 (if recip
6883 (setq recipients (delq recip recipients))))))))
6885 (setq recipients (message-prune-recipients recipients))
6886 (setq recipients
6887 (cl-loop for (id . address) in recipients
6888 collect (cons id (message--alter-repeat-address address))))
6890 ;; Build the header alist. Allow the user to be asked whether
6891 ;; or not to reply to all recipients in a wide reply.
6892 (setq follow-to (list (cons 'To (cdr (pop recipients)))))
6893 (when (and recipients
6894 (or (not message-wide-reply-confirm-recipients)
6895 (y-or-n-p "Reply to all recipients? ")))
6896 (setq recipients (mapconcat
6897 (lambda (addr) (cdr addr)) recipients ", "))
6898 (if (string-match "^ +" recipients)
6899 (setq recipients (substring recipients (match-end 0))))
6900 (push (cons 'Cc recipients) follow-to)))
6901 follow-to))
6903 (defun message-prune-recipients (recipients)
6904 (dolist (rule message-prune-recipient-rules)
6905 (let ((match (car rule))
6906 dup-match
6907 address)
6908 (dolist (recipient recipients)
6909 (setq address (car recipient))
6910 (when (string-match match address)
6911 (setq dup-match (replace-match (cadr rule) nil nil address))
6912 (dolist (recipient recipients)
6913 ;; Don't delete the address that triggered this.
6914 (when (and (not (eq address (car recipient)))
6915 (string-match dup-match (car recipient)))
6916 (setq recipients (delq recipient recipients))))))))
6917 recipients)
6919 (defun message--alter-repeat-address (address)
6920 "Transform an address on the form \"\"foo@bar.com\"\" <foo@bar.com>\".
6921 The first bit will be elided if a match is made."
6922 (let ((bits (gnus-extract-address-components address)))
6923 (if (equal (car bits) (cadr bits))
6924 (car bits)
6925 ;; Return the original address if we don't have repetition.
6926 address)))
6928 (defcustom message-simplify-subject-functions
6929 '(message-strip-list-identifiers
6930 message-strip-subject-re
6931 message-strip-subject-trailing-was
6932 message-strip-subject-encoded-words)
6933 "List of functions taking a string argument that simplify subjects.
6934 The functions are applied when replying to a message.
6936 Useful functions to put in this list include:
6937 `message-strip-list-identifiers', `message-strip-subject-re',
6938 `message-strip-subject-trailing-was', and
6939 `message-strip-subject-encoded-words'."
6940 :version "22.1" ;; Gnus 5.10.9
6941 :group 'message-various
6942 :type '(repeat function))
6944 (defun message-simplify-subject (subject &optional functions)
6945 "Return simplified SUBJECT."
6946 (unless functions
6947 ;; Simplify fully:
6948 (setq functions message-simplify-subject-functions))
6949 (when (and (memq 'message-strip-list-identifiers functions)
6950 gnus-list-identifiers)
6951 (setq subject (message-strip-list-identifiers subject)))
6952 (when (memq 'message-strip-subject-re functions)
6953 (setq subject (concat "Re: " (message-strip-subject-re subject))))
6954 (when (and (memq 'message-strip-subject-trailing-was functions)
6955 message-subject-trailing-was-query)
6956 (setq subject (message-strip-subject-trailing-was subject)))
6957 (when (memq 'message-strip-subject-encoded-words functions)
6958 (setq subject (message-strip-subject-encoded-words subject)))
6959 subject)
6961 ;;;###autoload
6962 (defun message-reply (&optional to-address wide switch-function)
6963 "Start editing a reply to the article in the current buffer."
6964 (interactive)
6965 (require 'gnus-sum) ; for gnus-list-identifiers
6966 (let ((cur (current-buffer))
6967 from subject date
6968 references message-id follow-to
6969 (inhibit-point-motion-hooks t)
6970 (message-this-is-mail t)
6971 gnus-warning)
6972 (save-restriction
6973 (message-narrow-to-head-1)
6974 ;; Allow customizations to have their say.
6975 (if (not wide)
6976 ;; This is a regular reply.
6977 (when (functionp message-reply-to-function)
6978 (save-excursion
6979 (setq follow-to (funcall message-reply-to-function))))
6980 ;; This is a followup.
6981 (when (functionp message-wide-reply-to-function)
6982 (save-excursion
6983 (setq follow-to
6984 (funcall message-wide-reply-to-function)))))
6985 (setq message-id (message-fetch-field "message-id" t)
6986 references (message-fetch-field "references")
6987 date (message-fetch-field "date")
6988 from (or (message-fetch-field "from") "nobody")
6989 subject (or (message-fetch-field "subject") "none"))
6991 ;; Strip list identifiers, "Re: ", and "was:"
6992 (setq subject (message-simplify-subject subject))
6994 (when (and (setq gnus-warning (message-fetch-field "gnus-warning"))
6995 (string-match "<[^>]+>" gnus-warning))
6996 (setq message-id (match-string 0 gnus-warning)))
6998 (unless follow-to
6999 (setq follow-to (message-get-reply-headers wide to-address))))
7001 (let ((headers
7002 `((Subject . ,subject)
7003 ,@follow-to)))
7004 (unless (message-mail-user-agent)
7005 (message-pop-to-buffer
7006 (message-buffer-name
7007 (if wide "wide reply" "reply") from
7008 (if wide to-address nil))
7009 switch-function))
7010 (setq message-reply-headers
7011 (vector 0 (cdr (assq 'Subject headers))
7012 from date message-id references 0 0 ""))
7013 (message-setup headers cur))))
7015 ;;;###autoload
7016 (defun message-wide-reply (&optional to-address)
7017 "Make a \"wide\" reply to the message in the current buffer."
7018 (interactive)
7019 (message-reply to-address t))
7021 ;;;###autoload
7022 (defun message-followup (&optional to-newsgroups)
7023 "Follow up to the message in the current buffer.
7024 If TO-NEWSGROUPS, use that as the new Newsgroups line."
7025 (interactive)
7026 (require 'gnus-sum) ; for gnus-list-identifiers
7027 (let ((cur (current-buffer))
7028 from subject date reply-to mrt mct
7029 references message-id follow-to
7030 (inhibit-point-motion-hooks t)
7031 (message-this-is-news t)
7032 followup-to distribution newsgroups gnus-warning posted-to)
7033 (save-restriction
7034 (narrow-to-region
7035 (goto-char (point-min))
7036 (if (search-forward "\n\n" nil t)
7037 (1- (point))
7038 (point-max)))
7039 (when (functionp message-followup-to-function)
7040 (setq follow-to
7041 (funcall message-followup-to-function)))
7042 (setq from (message-fetch-field "from")
7043 date (message-fetch-field "date")
7044 subject (or (message-fetch-field "subject") "none")
7045 references (message-fetch-field "references")
7046 message-id (message-fetch-field "message-id" t)
7047 followup-to (message-fetch-field "followup-to")
7048 newsgroups (message-fetch-field "newsgroups")
7049 posted-to (message-fetch-field "posted-to")
7050 reply-to (message-fetch-field "reply-to")
7051 mrt (message-fetch-field "mail-reply-to")
7052 distribution (message-fetch-field "distribution")
7053 mct (message-fetch-field "mail-copies-to"))
7054 (when (and (setq gnus-warning (message-fetch-field "gnus-warning"))
7055 (string-match "<[^>]+>" gnus-warning))
7056 (setq message-id (match-string 0 gnus-warning)))
7057 ;; Remove bogus distribution.
7058 (when (and (stringp distribution)
7059 (let ((case-fold-search t))
7060 (string-match "world" distribution)))
7061 (setq distribution nil))
7062 ;; Strip list identifiers, "Re: ", and "was:"
7063 (setq subject (message-simplify-subject subject))
7064 (widen))
7066 (message-pop-to-buffer (message-buffer-name "followup" from newsgroups))
7068 (setq message-reply-headers
7069 (vector 0 subject from date message-id references 0 0 ""))
7071 (message-setup
7072 `((Subject . ,subject)
7073 ,@(cond
7074 (to-newsgroups
7075 (list (cons 'Newsgroups to-newsgroups)))
7076 (follow-to follow-to)
7077 ((and followup-to message-use-followup-to)
7078 (list
7079 (cond
7080 ((equal (downcase followup-to) "poster")
7081 (if (or (eq message-use-followup-to 'use)
7082 (message-y-or-n-p "Obey Followup-To: poster? " t "\
7083 You should normally obey the Followup-To: header.
7085 `Followup-To: poster' sends your response via e-mail instead of news.
7087 A typical situation where `Followup-To: poster' is used is when the poster
7088 does not read the newsgroup, so he wouldn't see any replies sent to it.
7090 You may customize the variable `message-use-followup-to', if you
7091 want to get rid of this query permanently."))
7092 (progn
7093 (setq message-this-is-news nil)
7094 (cons 'To (or mrt reply-to from "")))
7095 (cons 'Newsgroups newsgroups)))
7097 (if (or (equal followup-to newsgroups)
7098 (not (eq message-use-followup-to 'ask))
7099 (message-y-or-n-p
7100 (concat "Obey Followup-To: " followup-to "? ") t "\
7101 You should normally obey the Followup-To: header.
7103 `Followup-To: " followup-to "'
7104 directs your response to " (if (string-match "," followup-to)
7105 "the specified newsgroups"
7106 "that newsgroup only") ".
7108 If a message is posted to several newsgroups, Followup-To is often
7109 used to direct the following discussion to one newsgroup only,
7110 because discussions that are spread over several newsgroup tend to
7111 be fragmented and very difficult to follow.
7113 Also, some source/announcement newsgroups are not intended for discussion;
7114 responses here are directed to other newsgroups.
7116 You may customize the variable `message-use-followup-to', if you
7117 want to get rid of this query permanently."))
7118 (cons 'Newsgroups followup-to)
7119 (cons 'Newsgroups newsgroups))))))
7120 (posted-to
7121 `((Newsgroups . ,posted-to)))
7123 `((Newsgroups . ,newsgroups))))
7124 ,@(and distribution (list (cons 'Distribution distribution)))
7125 ,@(when (and mct
7126 (not (or (equal (downcase mct) "never")
7127 (equal (downcase mct) "nobody"))))
7128 (list (cons 'Cc (if (or (equal (downcase mct) "always")
7129 (equal (downcase mct) "poster"))
7130 (or mrt reply-to from "")
7131 mct)))))
7133 cur)))
7135 (defun message-is-yours-p ()
7136 "Non-nil means current article is yours.
7137 If you have added `cancel-messages' to `message-shoot-gnksa-feet', all articles
7138 are yours except those that have Cancel-Lock header not belonging to you.
7139 Instead of shooting GNKSA feet, you should modify `message-alternative-emails'
7140 to match all of yours addresses."
7141 ;; Canlock-logic as suggested by Per Abrahamsen
7142 ;; <abraham@dina.kvl.dk>
7144 ;; IF article has cancel-lock THEN
7145 ;; IF we can verify it THEN
7146 ;; issue cancel
7147 ;; ELSE
7148 ;; error: cancellock: article is not yours
7149 ;; ELSE
7150 ;; Use old rules, comparing sender...
7151 (save-excursion
7152 (save-restriction
7153 (message-narrow-to-head-1)
7154 (if (and (message-fetch-field "Cancel-Lock")
7155 (message-gnksa-enable-p 'canlock-verify))
7156 (if (null (canlock-verify))
7158 (error "Failed to verify Cancel-lock: This article is not yours"))
7159 (let (sender from)
7161 (message-gnksa-enable-p 'cancel-messages)
7162 (and (setq sender (message-fetch-field "sender"))
7163 (string-equal (downcase sender)
7164 (downcase (message-make-sender))))
7165 ;; Email address in From field equals to our address
7166 (and (setq from (message-fetch-field "from"))
7167 (string-equal
7168 (downcase (car (mail-header-parse-address from)))
7169 (downcase (car (mail-header-parse-address
7170 (message-make-from))))))
7171 ;; Email address in From field matches
7172 ;; 'message-alternative-emails' regexp or function.
7173 (and from
7174 message-alternative-emails
7175 (cond ((functionp message-alternative-emails)
7176 (funcall message-alternative-emails
7177 (mail-header-parse-address from)))
7178 (t (string-match message-alternative-emails
7179 (car (mail-header-parse-address from))))))))))))
7181 ;;;###autoload
7182 (defun message-cancel-news (&optional arg)
7183 "Cancel an article you posted.
7184 If ARG, allow editing of the cancellation message."
7185 (interactive "P")
7186 (unless (message-news-p)
7187 (error "This is not a news article; canceling is impossible"))
7188 (let (from newsgroups message-id distribution buf)
7189 (save-excursion
7190 ;; Get header info from original article.
7191 (save-restriction
7192 (message-narrow-to-head-1)
7193 (setq from (message-fetch-field "from")
7194 newsgroups (message-fetch-field "newsgroups")
7195 message-id (message-fetch-field "message-id" t)
7196 distribution (message-fetch-field "distribution")))
7197 ;; Make sure that this article was written by the user.
7198 (unless (message-is-yours-p)
7199 (error "This article is not yours"))
7200 (when (yes-or-no-p "Do you really want to cancel this article? ")
7201 ;; Make control message.
7202 (if arg
7203 (message-news)
7204 (setq buf (set-buffer (get-buffer-create " *message cancel*"))))
7205 (erase-buffer)
7206 (insert "Newsgroups: " newsgroups "\n"
7207 "From: " from "\n"
7208 "Subject: cancel " message-id "\n"
7209 "Control: cancel " message-id "\n"
7210 (if distribution
7211 (concat "Distribution: " distribution "\n")
7213 mail-header-separator "\n"
7214 message-cancel-message)
7215 (run-hooks 'message-cancel-hook)
7216 (unless arg
7217 (message "Canceling your article...")
7218 (if (let ((message-syntax-checks
7219 'dont-check-for-anything-just-trust-me))
7220 (funcall message-send-news-function))
7221 (message "Canceling your article...done"))
7222 (kill-buffer buf))))))
7224 ;;;###autoload
7225 (defun message-supersede ()
7226 "Start composing a message to supersede the current message.
7227 This is done simply by taking the old article and adding a Supersedes
7228 header line with the old Message-ID."
7229 (interactive)
7230 (let ((cur (current-buffer)))
7231 ;; Check whether the user owns the article that is to be superseded.
7232 (unless (message-is-yours-p)
7233 (error "This article is not yours"))
7234 ;; Get a normal message buffer.
7235 (message-pop-to-buffer (message-buffer-name "supersede"))
7236 (insert-buffer-substring cur)
7237 (mime-to-mml)
7238 (message-narrow-to-head-1)
7239 ;; Remove unwanted headers.
7240 (when message-ignored-supersedes-headers
7241 (message-remove-header message-ignored-supersedes-headers t))
7242 (goto-char (point-min))
7243 (if (not (re-search-forward "^Message-ID: " nil t))
7244 (error "No Message-ID in this article")
7245 (replace-match "Supersedes: " t t))
7246 (goto-char (point-max))
7247 (insert mail-header-separator)
7248 (widen)
7249 (forward-line 1)))
7251 ;;;###autoload
7252 (defun message-recover ()
7253 "Reread contents of current buffer from its last auto-save file."
7254 (interactive)
7255 (let ((file-name (make-auto-save-file-name)))
7256 (cond ((save-window-excursion
7257 (with-output-to-temp-buffer "*Directory*"
7258 (with-current-buffer standard-output
7259 (fundamental-mode))
7260 (buffer-disable-undo standard-output)
7261 (let ((default-directory "/"))
7262 (call-process
7263 "ls" nil standard-output nil "-l" file-name)))
7264 (yes-or-no-p (format "Recover auto save file %s? " file-name)))
7265 (let ((buffer-read-only nil))
7266 (erase-buffer)
7267 (insert-file-contents file-name nil)))
7268 (t (error "message-recover canceled")))))
7270 ;;; Washing Subject:
7272 (defun message-wash-subject (subject)
7273 "Remove junk like \"Re:\", \"(fwd)\", etc. added to subject string SUBJECT.
7274 Previous forwarders, repliers, etc. may add it."
7275 (with-temp-buffer
7276 (insert subject)
7277 (goto-char (point-min))
7278 ;; strip Re/Fwd stuff off the beginning
7279 (while (re-search-forward
7280 "\\([Rr][Ee]:\\|[Ff][Ww][Dd]\\(\\[[0-9]*\\]\\)?:\\|[Ff][Ww]:\\)" nil t)
7281 (replace-match ""))
7283 ;; and gnus-style forwards [foo@bar.com] subject
7284 (goto-char (point-min))
7285 (while (re-search-forward "\\[[^ \t]*\\(@\\|\\.\\)[^ \t]*\\]" nil t)
7286 (replace-match ""))
7288 ;; and off the end
7289 (goto-char (point-max))
7290 (while (re-search-backward "([Ff][Ww][Dd])" nil t)
7291 (replace-match ""))
7293 ;; and finally, any whitespace that was left-over
7294 (goto-char (point-min))
7295 (while (re-search-forward "^[ \t]+" nil t)
7296 (replace-match ""))
7297 (goto-char (point-max))
7298 (while (re-search-backward "[ \t]+$" nil t)
7299 (replace-match ""))
7301 (buffer-string)))
7303 ;;; Forwarding messages.
7305 (defvar message-forward-decoded-p nil
7306 "Non-nil means the original message is decoded.")
7308 (defun message-forward-subject-name-subject (subject)
7309 "Generate a SUBJECT for a forwarded message.
7310 The form is: [Source] Subject, where if the original message was mail,
7311 Source is the name of the sender, and if the original message was
7312 news, Source is the list of newsgroups is was posted to."
7313 (let* ((group (message-fetch-field "newsgroups"))
7314 (from (message-fetch-field "from"))
7315 (prefix
7316 (if group
7317 (gnus-group-decoded-name group)
7318 (or (and from (or
7319 (car (gnus-extract-address-components from))
7320 (cadr (gnus-extract-address-components from))))
7321 "(nowhere)"))))
7322 (concat "["
7323 (if message-forward-decoded-p
7324 prefix
7325 (mail-decode-encoded-word-string prefix))
7326 "] " subject)))
7328 (defun message-forward-subject-author-subject (subject)
7329 "Generate a SUBJECT for a forwarded message.
7330 The form is: [Source] Subject, where if the original message was mail,
7331 Source is the sender, and if the original message was news, Source is
7332 the list of newsgroups is was posted to."
7333 (let* ((group (message-fetch-field "newsgroups"))
7334 (prefix
7335 (if group
7336 (gnus-group-decoded-name group)
7337 (or (message-fetch-field "from")
7338 "(nowhere)"))))
7339 (concat "["
7340 (if message-forward-decoded-p
7341 prefix
7342 (mail-decode-encoded-word-string prefix))
7343 "] " subject)))
7345 (defun message-forward-subject-fwd (subject)
7346 "Generate a SUBJECT for a forwarded message.
7347 The form is: Fwd: Subject, where Subject is the original subject of
7348 the message."
7349 (if (string-match "^Fwd: " subject)
7350 subject
7351 (concat "Fwd: " subject)))
7353 (defun message-make-forward-subject ()
7354 "Return a Subject header suitable for the message in the current buffer."
7355 (save-excursion
7356 (save-restriction
7357 (message-narrow-to-head-1)
7358 (let ((funcs message-make-forward-subject-function)
7359 (subject (message-fetch-field "Subject")))
7360 (setq subject
7361 (if subject
7362 (if message-forward-decoded-p
7363 subject
7364 (mail-decode-encoded-word-string subject))
7365 ""))
7366 (when message-wash-forwarded-subjects
7367 (setq subject (message-wash-subject subject)))
7368 ;; Make sure funcs is a list.
7369 (and funcs
7370 (not (listp funcs))
7371 (setq funcs (list funcs)))
7372 ;; Apply funcs in order, passing subject generated by previous
7373 ;; func to the next one.
7374 (dolist (func funcs)
7375 (when (functionp func)
7376 (setq subject (funcall func subject))))
7377 subject))))
7379 (defvar gnus-article-decoded-p)
7382 ;;;###autoload
7383 (defun message-forward (&optional news digest)
7384 "Forward the current message via mail.
7385 Optional NEWS will use news to forward instead of mail.
7386 Optional DIGEST will use digest to forward."
7387 (interactive "P")
7388 (let* ((cur (current-buffer))
7389 (message-forward-decoded-p
7390 (if (local-variable-p 'gnus-article-decoded-p (current-buffer))
7391 gnus-article-decoded-p ;; In an article buffer.
7392 message-forward-decoded-p))
7393 (subject (message-make-forward-subject)))
7394 (if news
7395 (message-news nil subject)
7396 (message-mail nil subject))
7397 (message-forward-make-body cur digest)))
7399 (defun message-forward-make-body-plain (forward-buffer)
7400 (insert
7401 "\n-------------------- Start of forwarded message --------------------\n")
7402 (let ((b (point))
7403 (contents (with-current-buffer forward-buffer (buffer-string)))
7405 (unless (multibyte-string-p contents)
7406 (error "Attempt to insert unibyte string from the buffer \"%s\"\
7407 to the multibyte buffer \"%s\""
7408 (if (bufferp forward-buffer)
7409 (buffer-name forward-buffer)
7410 forward-buffer)
7411 (buffer-name)))
7412 (insert (mm-with-multibyte-buffer
7413 (insert contents)
7414 (mime-to-mml)
7415 (goto-char (point-min))
7416 (when (looking-at "From ")
7417 (replace-match "X-From-Line: "))
7418 (buffer-string)))
7419 (unless (bolp) (insert "\n"))
7420 (setq e (point))
7421 (insert
7422 "-------------------- End of forwarded message --------------------\n")
7423 (message-remove-ignored-headers b e)))
7425 (defun message-remove-ignored-headers (b e)
7426 (when (or message-forward-ignored-headers
7427 message-forward-included-headers)
7428 (save-restriction
7429 (narrow-to-region b e)
7430 (goto-char b)
7431 (narrow-to-region (point)
7432 (or (search-forward "\n\n" nil t) (point)))
7433 (when message-forward-ignored-headers
7434 (let ((ignored (if (stringp message-forward-ignored-headers)
7435 (list message-forward-ignored-headers)
7436 message-forward-ignored-headers)))
7437 (dolist (elem ignored)
7438 (message-remove-header elem t))))
7439 (when message-forward-included-headers
7440 (message-remove-header
7441 (if (listp message-forward-included-headers)
7442 (mapconcat #'identity (cons "^$" message-forward-included-headers)
7443 "\\|")
7444 message-forward-included-headers)
7445 t nil t)))))
7447 (defun message-forward-make-body-mime (forward-buffer &optional beg end)
7448 (let ((b (point)))
7449 (insert "\n\n<#part type=message/rfc822 disposition=inline raw=t>\n")
7450 (save-restriction
7451 (narrow-to-region (point) (point))
7452 (insert-buffer-substring forward-buffer beg end)
7453 (mml-quote-region (point-min) (point-max))
7454 (goto-char (point-min))
7455 (when (looking-at "From ")
7456 (replace-match "X-From-Line: "))
7457 (goto-char (point-max)))
7458 (insert "<#/part>\n")
7459 ;; Consider there is no illegible text.
7460 (add-text-properties
7461 b (point)
7462 `(no-illegible-text t rear-nonsticky t start-open t))))
7464 (defun message-forward-make-body-mml (forward-buffer)
7465 (insert "\n\n<#mml type=message/rfc822 disposition=inline>\n")
7466 (let ((b (point)) e)
7467 (if (not message-forward-decoded-p)
7468 (let ((contents (with-current-buffer forward-buffer (buffer-string))))
7469 (unless (multibyte-string-p contents)
7470 (error "Attempt to insert unibyte string from the buffer \"%s\"\
7471 to the multibyte buffer \"%s\""
7472 (if (bufferp forward-buffer)
7473 (buffer-name forward-buffer)
7474 forward-buffer)
7475 (buffer-name)))
7476 (insert (mm-with-multibyte-buffer
7477 (insert contents)
7478 (mime-to-mml)
7479 (goto-char (point-min))
7480 (when (looking-at "From ")
7481 (replace-match "X-From-Line: "))
7482 (buffer-string))))
7483 (save-restriction
7484 (narrow-to-region (point) (point))
7485 (mml-insert-buffer forward-buffer)
7486 (goto-char (point-min))
7487 (when (looking-at "From ")
7488 (replace-match "X-From-Line: "))
7489 (goto-char (point-max))))
7490 (setq e (point))
7491 (insert "<#/mml>\n")
7492 (when (not message-forward-decoded-p)
7493 (message-remove-ignored-headers b e))))
7495 (defun message-forward-make-body-digest-plain (forward-buffer)
7496 (insert
7497 "\n-------------------- Start of forwarded message --------------------\n")
7498 (mml-insert-buffer forward-buffer)
7499 (insert
7500 "\n-------------------- End of forwarded message --------------------\n"))
7502 (defun message-forward-make-body-digest-mime (forward-buffer)
7503 (insert "\n<#multipart type=digest>\n")
7504 (let ((b (point)) e)
7505 (insert-buffer-substring forward-buffer)
7506 (setq e (point))
7507 (insert "<#/multipart>\n")
7508 (save-restriction
7509 (narrow-to-region b e)
7510 (goto-char b)
7511 (narrow-to-region (point)
7512 (or (search-forward "\n\n" nil t) (point)))
7513 (delete-region (point-min) (point-max)))))
7515 (defun message-forward-make-body-digest (forward-buffer)
7516 (if message-forward-as-mime
7517 (message-forward-make-body-digest-mime forward-buffer)
7518 (message-forward-make-body-digest-plain forward-buffer)))
7520 (autoload 'mm-uu-dissect-text-parts "mm-uu")
7521 (autoload 'mm-uu-dissect "mm-uu")
7523 (defun message-signed-or-encrypted-p (&optional dont-emulate-mime handles)
7524 "Say whether the current buffer contains signed or encrypted message.
7525 If DONT-EMULATE-MIME is nil, this function does the MIME emulation on
7526 messages that don't conform to PGP/MIME described in RFC2015. HANDLES
7527 is for the internal use."
7528 (unless handles
7529 (let ((mm-decrypt-option 'never)
7530 (mm-verify-option 'never))
7531 (if (setq handles (mm-dissect-buffer nil t))
7532 (unless dont-emulate-mime
7533 (mm-uu-dissect-text-parts handles))
7534 (unless dont-emulate-mime
7535 (setq handles (mm-uu-dissect))))))
7536 ;; Check text/plain message in which there is a signed or encrypted
7537 ;; body that has been encoded by B or Q.
7538 (unless (or handles dont-emulate-mime)
7539 (let ((cur (current-buffer))
7540 (mm-decrypt-option 'never)
7541 (mm-verify-option 'never))
7542 (with-temp-buffer
7543 (insert-buffer-substring cur)
7544 (when (setq handles (mm-dissect-buffer t t))
7545 (if (and (bufferp (car handles))
7546 (equal (mm-handle-media-type handles) "text/plain"))
7547 (progn
7548 (erase-buffer)
7549 (insert-buffer-substring (car handles))
7550 (mm-decode-content-transfer-encoding
7551 (mm-handle-encoding handles))
7552 (mm-destroy-parts handles)
7553 (setq handles (mm-uu-dissect)))
7554 (mm-destroy-parts handles)
7555 (setq handles nil))))))
7556 (when handles
7557 (prog1
7558 (catch 'found
7559 (dolist (handle (if (stringp (car handles))
7560 (if (member (car handles)
7561 '("multipart/signed"
7562 "multipart/encrypted"))
7563 (throw 'found t)
7564 (cdr handles))
7565 (list handles)))
7566 (if (stringp (car handle))
7567 (when (message-signed-or-encrypted-p dont-emulate-mime handle)
7568 (throw 'found t))
7569 (when (and (bufferp (car handle))
7570 (equal (mm-handle-media-type handle)
7571 "message/rfc822"))
7572 (with-current-buffer (mm-handle-buffer handle)
7573 (when (message-signed-or-encrypted-p dont-emulate-mime)
7574 (throw 'found t)))))))
7575 (mm-destroy-parts handles))))
7577 ;;;###autoload
7578 (defun message-forward-make-body (forward-buffer &optional digest)
7579 ;; Put point where we want it before inserting the forwarded
7580 ;; message.
7581 (if message-forward-before-signature
7582 (message-goto-body)
7583 (goto-char (point-max)))
7584 (if digest
7585 (message-forward-make-body-digest forward-buffer)
7586 (if message-forward-as-mime
7587 (if (and message-forward-show-mml
7588 (not (and (eq message-forward-show-mml 'best)
7589 ;; Use the raw form in the body if it contains
7590 ;; signed or encrypted message so as not to be
7591 ;; destroyed by re-encoding.
7592 (with-current-buffer forward-buffer
7593 (condition-case nil
7594 (message-signed-or-encrypted-p)
7595 (error t))))))
7596 (message-forward-make-body-mml forward-buffer)
7597 (message-forward-make-body-mime forward-buffer))
7598 (message-forward-make-body-plain forward-buffer)))
7599 (message-position-point))
7601 (declare-function rmail-toggle-header "rmail" (&optional arg))
7603 ;;;###autoload
7604 (defun message-forward-rmail-make-body (forward-buffer)
7605 (save-window-excursion
7606 (set-buffer forward-buffer)
7607 (when (rmail-msg-is-pruned)
7608 (rmail-toggle-header 0)))
7609 (message-forward-make-body forward-buffer))
7611 ;; Fixme: Should have defcustom.
7612 ;;;###autoload
7613 (defun message-insinuate-rmail ()
7614 "Let RMAIL use message to forward."
7615 (interactive)
7616 (setq rmail-enable-mime-composing t)
7617 (setq rmail-insert-mime-forwarded-message-function
7618 'message-forward-rmail-make-body))
7620 (defvar message-inhibit-body-encoding nil)
7622 ;;;###autoload
7623 (defun message-resend (address)
7624 "Resend the current article to ADDRESS."
7625 (interactive
7626 (list (message-read-from-minibuffer "Resend message to: ")))
7627 (message "Resending message to %s..." address)
7628 (save-excursion
7629 (let ((cur (current-buffer))
7630 gcc beg)
7631 ;; We first set up a normal mail buffer.
7632 (unless (message-mail-user-agent)
7633 (set-buffer (get-buffer-create " *message resend*"))
7634 (let ((inhibit-read-only t))
7635 (erase-buffer)))
7636 (let ((message-this-is-mail t)
7637 message-generate-hashcash
7638 message-setup-hook)
7639 (message-setup `((To . ,address))))
7640 ;; Insert our usual headers.
7641 (message-generate-headers '(From Date To Message-ID))
7642 (message-narrow-to-headers)
7643 (when (setq gcc (mail-fetch-field "gcc" nil t))
7644 (message-remove-header "gcc"))
7645 ;; Remove X-Draft-From header etc.
7646 (message-remove-header message-ignored-mail-headers t)
7647 ;; Rename them all to "Resent-*".
7648 (goto-char (point-min))
7649 (while (re-search-forward "^[A-Za-z]" nil t)
7650 (forward-char -1)
7651 (insert "Resent-"))
7652 (widen)
7653 (forward-line)
7654 (let ((inhibit-read-only t))
7655 (delete-region (point) (point-max)))
7656 (setq beg (point))
7657 ;; Insert the message to be resent.
7658 (insert-buffer-substring cur)
7659 (goto-char (point-min))
7660 (search-forward "\n\n")
7661 (forward-char -1)
7662 (save-restriction
7663 (narrow-to-region beg (point))
7664 (message-remove-header message-ignored-resent-headers t)
7665 (goto-char (point-max)))
7666 (insert mail-header-separator)
7667 ;; Rename all old ("Also-")Resent headers.
7668 (while (re-search-backward "^\\(Also-\\)*Resent-" beg t)
7669 (beginning-of-line)
7670 (insert "Also-"))
7671 ;; Quote any "From " lines at the beginning.
7672 (goto-char beg)
7673 (when (looking-at "From ")
7674 (replace-match "X-From-Line: "))
7675 ;; Send it.
7676 (let ((message-inhibit-body-encoding
7677 ;; Don't do any further encoding if it looks like the
7678 ;; message has already been encoded.
7679 (let ((case-fold-search t))
7680 (re-search-forward "^mime-version:" nil t)))
7681 (message-inhibit-ecomplete t)
7682 ;; We don't want smtpmail.el to encode anything, either.
7683 (sendmail-coding-system 'raw-text)
7684 (select-safe-coding-system-function nil)
7685 message-required-mail-headers
7686 message-generate-hashcash
7687 rfc2047-encode-encoded-words)
7688 (message-send-mail))
7689 (when gcc
7690 (message-goto-eoh)
7691 (insert "Gcc: " gcc "\n"))
7692 (run-hooks 'message-sent-hook)
7693 (kill-buffer (current-buffer)))
7694 (message "Resending message to %s...done" address)))
7696 ;;;###autoload
7697 (defun message-bounce ()
7698 "Re-mail the current message.
7699 This only makes sense if the current message is a bounce message that
7700 contains some mail you have written which has been bounced back to
7701 you."
7702 (interactive)
7703 (let ((handles (mm-dissect-buffer t))
7704 boundary)
7705 (message-pop-to-buffer (message-buffer-name "bounce"))
7706 (if (stringp (car handles))
7707 ;; This is a MIME bounce.
7708 (mm-insert-part (car (last handles)))
7709 ;; This is a non-MIME bounce, so we try to remove things
7710 ;; manually.
7711 (mm-insert-part handles)
7712 (undo-boundary)
7713 (goto-char (point-min))
7714 (re-search-forward "\n\n+" nil t)
7715 (setq boundary (point))
7716 ;; We remove everything before the bounced mail.
7717 (if (or (re-search-forward message-unsent-separator nil t)
7718 (progn
7719 (search-forward "\n\n" nil 'move)
7720 (re-search-backward "^Return-Path:.*\n" boundary t)))
7721 (progn
7722 (forward-line 1)
7723 (delete-region (point-min)
7724 (if (re-search-forward "^[^ \n\t]+:" nil t)
7725 (match-beginning 0)
7726 (point))))
7727 (goto-char boundary)
7728 (when (re-search-backward "^.?From .*\n" nil t)
7729 (delete-region (match-beginning 0) (match-end 0)))))
7730 (mime-to-mml)
7731 (save-restriction
7732 (message-narrow-to-head-1)
7733 (message-remove-header message-ignored-bounced-headers t)
7734 (goto-char (point-max))
7735 (insert mail-header-separator))
7736 (message-position-point)))
7739 ;;; Interactive entry points for new message buffers.
7742 ;;;###autoload
7743 (defun message-mail-other-window (&optional to subject)
7744 "Like `message-mail' command, but display mail buffer in another window."
7745 (interactive)
7746 (unless (message-mail-user-agent)
7747 (message-pop-to-buffer (message-buffer-name "mail" to)
7748 'switch-to-buffer-other-window))
7749 (let ((message-this-is-mail t))
7750 (message-setup `((To . ,(or to "")) (Subject . ,(or subject "")))
7751 nil nil nil 'switch-to-buffer-other-window)))
7753 ;;;###autoload
7754 (defun message-mail-other-frame (&optional to subject)
7755 "Like `message-mail' command, but display mail buffer in another frame."
7756 (interactive)
7757 (unless (message-mail-user-agent)
7758 (message-pop-to-buffer (message-buffer-name "mail" to)
7759 'switch-to-buffer-other-frame))
7760 (let ((message-this-is-mail t))
7761 (message-setup `((To . ,(or to "")) (Subject . ,(or subject "")))
7762 nil nil nil 'switch-to-buffer-other-frame)))
7764 ;;;###autoload
7765 (defun message-news-other-window (&optional newsgroups subject)
7766 "Start editing a news article to be sent."
7767 (interactive)
7768 (message-pop-to-buffer (message-buffer-name "posting" nil newsgroups)
7769 'switch-to-buffer-other-window)
7770 (let ((message-this-is-news t))
7771 (message-setup `((Newsgroups . ,(or newsgroups ""))
7772 (Subject . ,(or subject ""))))))
7774 ;;;###autoload
7775 (defun message-news-other-frame (&optional newsgroups subject)
7776 "Start editing a news article to be sent."
7777 (interactive)
7778 (message-pop-to-buffer (message-buffer-name "posting" nil newsgroups)
7779 'switch-to-buffer-other-frame)
7780 (let ((message-this-is-news t))
7781 (message-setup `((Newsgroups . ,(or newsgroups ""))
7782 (Subject . ,(or subject ""))))))
7784 ;;; underline.el
7786 ;; This code should be moved to underline.el (from which it is stolen).
7788 ;;;###autoload
7789 (defun message-bold-region (start end)
7790 "Bold all nonblank characters in the region.
7791 Works by overstriking characters.
7792 Called from program, takes two arguments START and END
7793 which specify the range to operate on."
7794 (interactive "r")
7795 (save-excursion
7796 (let ((end1 (make-marker)))
7797 (move-marker end1 (max start end))
7798 (goto-char (min start end))
7799 (while (< (point) end1)
7800 (or (looking-at "[_\^@- ]")
7801 (insert (char-after) "\b"))
7802 (forward-char 1)))))
7804 ;;;###autoload
7805 (defun message-unbold-region (start end)
7806 "Remove all boldness (overstruck characters) in the region.
7807 Called from program, takes two arguments START and END
7808 which specify the range to operate on."
7809 (interactive "r")
7810 (save-excursion
7811 (let ((end1 (make-marker)))
7812 (move-marker end1 (max start end))
7813 (goto-char (min start end))
7814 (while (search-forward "\b" end1 t)
7815 (if (eq (char-after) (char-after (- (point) 2)))
7816 (delete-char -2))))))
7818 (defun message-exchange-point-and-mark ()
7819 "Exchange point and mark, but don't activate region if it was inactive."
7820 (goto-char (prog1 (mark t)
7821 (set-marker (mark-marker) (point)))))
7823 ;; Support for toolbar
7824 (defvar tool-bar-mode)
7826 ;; Note: The :set function in the `message-tool-bar*' variables will only
7827 ;; affect _new_ message buffers. We might add a function that walks thru all
7828 ;; message-mode buffers and force the update.
7829 (defun message-tool-bar-update (&optional symbol value)
7830 "Update message mode toolbar.
7831 Setter function for custom variables."
7832 (setq-default message-tool-bar-map nil)
7833 (when symbol
7834 ;; When used as ":set" function:
7835 (set-default symbol value)))
7837 (defcustom message-tool-bar (if (eq gmm-tool-bar-style 'gnome)
7838 'message-tool-bar-gnome
7839 'message-tool-bar-retro)
7840 "Specifies the message mode tool bar.
7842 It can be either a list or a symbol referring to a list. See
7843 `gmm-tool-bar-from-list' for the format of the list. The
7844 default key map is `message-mode-map'.
7846 Pre-defined symbols include `message-tool-bar-gnome' and
7847 `message-tool-bar-retro'."
7848 :type '(repeat gmm-tool-bar-list-item)
7849 :type '(choice (const :tag "GNOME style" message-tool-bar-gnome)
7850 (const :tag "Retro look" message-tool-bar-retro)
7851 (repeat :tag "User defined list" gmm-tool-bar-item)
7852 (symbol))
7853 :version "23.1" ;; No Gnus
7854 :initialize 'custom-initialize-default
7855 :set 'message-tool-bar-update
7856 :group 'message)
7858 (defcustom message-tool-bar-gnome
7859 '((ispell-message "spell" nil
7860 :vert-only t
7861 :visible (not flyspell-mode))
7862 (flyspell-buffer "spell" t
7863 :vert-only t
7864 :visible flyspell-mode
7865 :help "Flyspell whole buffer")
7866 (message-send-and-exit "mail/send" t :label "Send")
7867 (message-dont-send "mail/save-draft")
7868 (mml-attach-file "attach" mml-mode-map :vert-only t)
7869 (mml-preview "mail/preview" mml-mode-map)
7870 (mml-secure-message-sign-encrypt "lock" mml-mode-map :visible nil)
7871 (message-insert-importance-high "important" nil :visible nil)
7872 (message-insert-importance-low "unimportant" nil :visible nil)
7873 (message-insert-disposition-notification-to "receipt" nil :visible nil))
7874 "List of items for the message tool bar (GNOME style).
7876 See `gmm-tool-bar-from-list' for details on the format of the list."
7877 :type '(repeat gmm-tool-bar-item)
7878 :version "23.1" ;; No Gnus
7879 :initialize 'custom-initialize-default
7880 :set 'message-tool-bar-update
7881 :group 'message)
7883 (defcustom message-tool-bar-retro
7884 '(;; Old Emacs 21 icon for consistency.
7885 (message-send-and-exit "gnus/mail-send")
7886 (message-kill-buffer "close")
7887 (message-dont-send "cancel")
7888 (mml-attach-file "attach" mml-mode-map)
7889 (ispell-message "spell")
7890 (mml-preview "preview" mml-mode-map)
7891 (message-insert-importance-high "gnus/important")
7892 (message-insert-importance-low "gnus/unimportant")
7893 (message-insert-disposition-notification-to "gnus/receipt"))
7894 "List of items for the message tool bar (retro style).
7896 See `gmm-tool-bar-from-list' for details on the format of the list."
7897 :type '(repeat gmm-tool-bar-item)
7898 :version "23.1" ;; No Gnus
7899 :initialize 'custom-initialize-default
7900 :set 'message-tool-bar-update
7901 :group 'message)
7903 (defcustom message-tool-bar-zap-list
7904 '(new-file open-file dired kill-buffer write-file
7905 print-buffer customize help)
7906 "List of icon items from the global tool bar.
7907 These items are not displayed on the message mode tool bar.
7909 See `gmm-tool-bar-from-list' for the format of the list."
7910 :type 'gmm-tool-bar-zap-list
7911 :version "23.1" ;; No Gnus
7912 :initialize 'custom-initialize-default
7913 :set 'message-tool-bar-update
7914 :group 'message)
7916 (defvar image-load-path)
7917 (declare-function image-load-path-for-library "image"
7918 (library image &optional path no-error))
7920 (defun message-make-tool-bar (&optional force)
7921 "Make a message mode tool bar from `message-tool-bar-list'.
7922 When FORCE, rebuild the tool bar."
7923 (when (and (boundp 'tool-bar-mode)
7924 tool-bar-mode
7925 (or (not message-tool-bar-map) force))
7926 (setq message-tool-bar-map
7927 (let* ((load-path
7928 (image-load-path-for-library
7929 "message" "mail/save-draft.xpm" nil t))
7930 (image-load-path (cons (car load-path) image-load-path)))
7931 (gmm-tool-bar-from-list message-tool-bar
7932 message-tool-bar-zap-list
7933 'message-mode-map))))
7934 message-tool-bar-map)
7936 ;;; Group name completion.
7938 (defcustom message-newgroups-header-regexp
7939 "^\\(Newsgroups\\|Followup-To\\|Posted-To\\|Gcc\\):"
7940 "Regexp that match headers that lists groups."
7941 :group 'message
7942 :type 'regexp)
7944 (defcustom message-completion-alist
7945 ;; FIXME: Make it possible to use the standard completion UI.
7946 (list (cons message-newgroups-header-regexp 'message-expand-group)
7947 '("^\\(Resent-\\)?\\(To\\|B?Cc\\):" . message-expand-name)
7948 '("^\\(Reply-To\\|From\\|Mail-Followup-To\\|Mail-Copies-To\\):"
7949 . message-expand-name)
7950 '("^\\(Disposition-Notification-To\\|Return-Receipt-To\\):"
7951 . message-expand-name))
7952 "Alist of (RE . FUN). Use FUN for completion on header lines matching RE."
7953 :version "22.1"
7954 :group 'message
7955 :type '(alist :key-type regexp :value-type function))
7957 (defcustom message-expand-name-databases
7958 '(bbdb eudc)
7959 "List of databases to try for name completion (`message-expand-name').
7960 Each element is a symbol and can be `bbdb' or `eudc'."
7961 :group 'message
7962 :type '(set (const bbdb) (const eudc)))
7964 (defcustom message-tab-body-function nil
7965 "Function to execute when `message-tab' (TAB) is executed in the body.
7966 If nil, the function bound in `text-mode-map' or `global-map' is executed."
7967 :version "22.1"
7968 :group 'message
7969 :link '(custom-manual "(message)Various Commands")
7970 :type '(choice (const nil)
7971 function))
7973 (declare-function mail-abbrev-in-expansion-header-p "mailabbrev" ())
7975 (defun message-tab ()
7976 "Complete names according to `message-completion-alist'.
7977 Execute function specified by `message-tab-body-function' when
7978 not in those headers. If that variable is nil, indent with the
7979 regular text mode tabbing command."
7980 (interactive)
7981 (cond
7982 ((let ((completion-fail-discreetly t))
7983 (completion-at-point))
7984 ;; Completion was performed; nothing else to do.
7985 nil)
7986 (message-tab-body-function (funcall message-tab-body-function))
7987 (t (funcall (or (lookup-key text-mode-map "\t")
7988 (lookup-key global-map "\t")
7989 'indent-relative)))))
7991 (defvar mail-abbrev-mode-regexp)
7993 (defun message-completion-function ()
7994 (let ((alist message-completion-alist))
7995 (while (and alist
7996 (let ((mail-abbrev-mode-regexp (caar alist)))
7997 (not (mail-abbrev-in-expansion-header-p))))
7998 (setq alist (cdr alist)))
7999 (when (cdar alist)
8000 (let ((fun (cdar alist)))
8001 ;; Even if completion fails, return a non-nil value, so as to avoid
8002 ;; falling back to message-tab-body-function.
8003 (lambda () (funcall fun) 'completion-attempted)))))
8005 (defun message-expand-group ()
8006 "Expand the group name under point."
8007 (let ((b (save-excursion
8008 (save-restriction
8009 (narrow-to-region
8010 (save-excursion
8011 (beginning-of-line)
8012 (skip-chars-forward "^:")
8013 (1+ (point)))
8014 (point))
8015 (skip-chars-backward "^, \t\n") (point))))
8016 (completion-ignore-case t)
8017 (e (progn (skip-chars-forward "^,\t\n ") (point)))
8018 group collection)
8019 (when (and (boundp 'gnus-active-hashtb)
8020 gnus-active-hashtb)
8021 (mapatoms
8022 (lambda (symbol)
8023 (setq group (symbol-name symbol))
8024 (push (if (string-match "[^\000-\177]" group)
8025 (gnus-group-decoded-name group)
8026 group)
8027 collection))
8028 gnus-active-hashtb))
8029 (completion-in-region b e collection)))
8031 (defun message-expand-name ()
8032 (cond ((and (memq 'eudc message-expand-name-databases)
8033 (boundp 'eudc-protocol)
8034 eudc-protocol)
8035 (eudc-expand-inline))
8036 ((and (memq 'bbdb message-expand-name-databases)
8037 (fboundp 'bbdb-complete-name))
8038 (let ((starttick (buffer-modified-tick)))
8039 (or (bbdb-complete-name)
8040 ;; Apparently, bbdb-complete-name can return nil even when
8041 ;; completion took place. So let's double check the buffer was
8042 ;; not modified.
8043 (/= starttick (buffer-modified-tick)))))
8045 (expand-abbrev))))
8047 ;;; Help stuff.
8049 (defun message-talkative-question (ask question show &rest text)
8050 "Call FUNCTION with argument QUESTION; optionally display TEXT... args.
8051 If SHOW is non-nil, the arguments TEXT... are displayed in a temp buffer.
8052 The following arguments may contain lists of values."
8053 (if (and show
8054 (setq text (message-flatten-list text)))
8055 (save-window-excursion
8056 (with-output-to-temp-buffer " *MESSAGE information message*"
8057 (with-current-buffer " *MESSAGE information message*"
8058 (fundamental-mode)
8059 (mapc 'princ text)
8060 (goto-char (point-min))))
8061 (funcall ask question))
8062 (funcall ask question)))
8064 (defun message-flatten-list (list)
8065 "Return a new, flat list that contains all elements of LIST.
8067 \(message-flatten-list \\='(1 (2 3 (4 5 (6))) 7))
8068 => (1 2 3 4 5 6 7)"
8069 (cond ((consp list)
8070 (apply 'append (mapcar 'message-flatten-list list)))
8071 (list
8072 (list list))))
8074 (defun message-generate-new-buffer-clone-locals (name &optional varstr)
8075 "Create and return a buffer with name based on NAME using `generate-new-buffer'.
8076 Then clone the local variables and values from the old buffer to the
8077 new one, cloning only the locals having a substring matching the
8078 regexp VARSTR."
8079 (let ((oldbuf (current-buffer)))
8080 (with-current-buffer (generate-new-buffer name)
8081 (message-clone-locals oldbuf varstr)
8082 (current-buffer))))
8084 (defun message-clone-locals (buffer &optional varstr)
8085 "Clone the local variables from BUFFER to the current buffer."
8086 (let ((locals (with-current-buffer buffer (buffer-local-variables)))
8087 (regexp "^gnus\\|^nn\\|^message\\|^sendmail\\|^smtp\\|^user-mail-address"))
8088 (mapcar
8089 (lambda (local)
8090 (when (and (consp local)
8091 (car local)
8092 (string-match regexp (symbol-name (car local)))
8093 (or (null varstr)
8094 (string-match varstr (symbol-name (car local)))))
8095 (ignore-errors
8096 ;; Cloning message-default-charset could cause an already
8097 ;; encoded text to be encoded again, yielding raw bytes
8098 ;; instead of characters in the message.
8099 (unless (eq 'message-default-charset (car local))
8100 (set (make-local-variable (car local))
8101 (cdr local))))))
8102 locals)))
8105 ;;; MIME functions
8108 (defun message-encode-message-body ()
8109 (unless message-inhibit-body-encoding
8110 (let ((mail-parse-charset (or mail-parse-charset
8111 message-default-charset))
8112 (case-fold-search t)
8113 lines content-type-p)
8114 (message-goto-body)
8115 (save-restriction
8116 (narrow-to-region (point) (point-max))
8117 (let ((new (mml-generate-mime)))
8118 (when new
8119 (delete-region (point-min) (point-max))
8120 (insert new)
8121 (goto-char (point-min))
8122 (if (eq (aref new 0) ?\n)
8123 (delete-char 1)
8124 (search-forward "\n\n")
8125 (setq lines (buffer-substring (point-min) (1- (point))))
8126 (delete-region (point-min) (point))))))
8127 (save-restriction
8128 (message-narrow-to-headers-or-head)
8129 (message-remove-header "Mime-Version")
8130 (goto-char (point-max))
8131 (insert "MIME-Version: 1.0\n")
8132 (when lines
8133 (insert lines))
8134 (setq content-type-p
8135 (or mml-boundary
8136 (re-search-backward "^Content-Type:" nil t))))
8137 (save-restriction
8138 (message-narrow-to-headers-or-head)
8139 (message-remove-first-header "Content-Type")
8140 (message-remove-first-header "Content-Transfer-Encoding"))
8141 ;; We always make sure that the message has a Content-Type
8142 ;; header. This is because some broken MTAs and MUAs get
8143 ;; awfully confused when confronted with a message with a
8144 ;; MIME-Version header and without a Content-Type header. For
8145 ;; instance, Solaris' /usr/bin/mail.
8146 (unless content-type-p
8147 (goto-char (point-min))
8148 ;; For unknown reason, MIME-Version doesn't exist.
8149 (when (re-search-forward "^MIME-Version:" nil t)
8150 (forward-line 1)
8151 (insert "Content-Type: text/plain; charset=us-ascii\n"))))))
8153 (defun message-read-from-minibuffer (prompt &optional initial-contents)
8154 "Read from the minibuffer while providing abbrev expansion."
8155 (let ((minibuffer-setup-hook 'mail-abbrevs-setup)
8156 (minibuffer-local-map message-minibuffer-local-map))
8157 (read-from-minibuffer prompt initial-contents)))
8159 (defun message-use-alternative-email-as-from ()
8160 "Set From field of the outgoing message to the first matching
8161 address in `message-alternative-emails', looking at To, Cc and
8162 From headers in the original article."
8163 (require 'mail-utils)
8164 (let* ((fields '("To" "Cc" "From"))
8165 (emails
8166 (message-tokenize-header
8167 (mail-strip-quoted-names
8168 (mapconcat 'message-fetch-reply-field fields ","))))
8169 (email
8170 (cond ((functionp message-alternative-emails)
8171 (car (cl-remove-if-not message-alternative-emails emails)))
8172 (t (cl-loop for email in emails
8173 if (string-match-p message-alternative-emails email)
8174 return email)))))
8175 (unless (or (not email) (equal email user-mail-address))
8176 (message-remove-header "From")
8177 (goto-char (point-max))
8178 (insert "From: " (let ((user-mail-address email)) (message-make-from))
8179 "\n"))))
8181 (defun message-options-get (symbol)
8182 (cdr (assq symbol message-options)))
8184 (defun message-options-set (symbol value)
8185 (let ((the-cons (assq symbol message-options)))
8186 (if the-cons
8187 (if value
8188 (setcdr the-cons value)
8189 (setq message-options (delq the-cons message-options)))
8190 (and value
8191 (push (cons symbol value) message-options))))
8192 value)
8194 (defun message-options-set-recipient ()
8195 (save-restriction
8196 (message-narrow-to-headers-or-head)
8197 (message-options-set 'message-sender
8198 (mail-strip-quoted-names
8199 (message-fetch-field "from")))
8200 (message-options-set 'message-recipients
8201 (mail-strip-quoted-names
8202 (let ((to (message-fetch-field "to"))
8203 (cc (message-fetch-field "cc"))
8204 (bcc (message-fetch-field "bcc")))
8205 (concat
8206 (or to "")
8207 (if (and to cc) ", ")
8208 (or cc "")
8209 (if (and (or to cc) bcc) ", ")
8210 (or bcc "")))))))
8212 (defun message-hide-headers ()
8213 "Hide headers based on the `message-hidden-headers' variable."
8214 (let ((regexps (if (stringp message-hidden-headers)
8215 (list message-hidden-headers)
8216 message-hidden-headers))
8217 (inhibit-point-motion-hooks t)
8218 (inhibit-modification-hooks t)
8219 (end-of-headers (point-min)))
8220 (when regexps
8221 (save-excursion
8222 (save-restriction
8223 (message-narrow-to-headers)
8224 (goto-char (point-min))
8225 (while (not (eobp))
8226 (if (not (message-hide-header-p regexps))
8227 (message-next-header)
8228 (let ((begin (point))
8229 header header-len)
8230 (message-next-header)
8231 (setq header (buffer-substring begin (point))
8232 header-len (- (point) begin))
8233 (delete-region begin (point))
8234 (goto-char end-of-headers)
8235 (insert header)
8236 (setq end-of-headers
8237 (+ end-of-headers header-len))))))))
8238 (narrow-to-region end-of-headers (point-max))))
8240 (defun message-hide-header-p (regexps)
8241 (let ((result nil)
8242 (reverse nil))
8243 (when (eq (car regexps) 'not)
8244 (setq reverse t)
8245 (pop regexps))
8246 (dolist (regexp regexps)
8247 (setq result (or result (looking-at regexp))))
8248 (if reverse
8249 (not result)
8250 result)))
8252 (declare-function ecomplete-add-item "ecomplete" (type key text))
8253 (declare-function ecomplete-save "ecomplete" ())
8255 (defun message-put-addresses-in-ecomplete ()
8256 (require 'ecomplete)
8257 (dolist (header '("to" "cc" "from" "reply-to"))
8258 (let ((value (message-field-value header)))
8259 (dolist (string (mail-header-parse-addresses value 'raw))
8260 (setq string
8261 (replace-regexp-in-string
8262 "\n" ""
8263 (replace-regexp-in-string "^ +\\| +$" "" string)))
8264 (ecomplete-add-item 'mail (car (mail-header-parse-address string))
8265 string))))
8266 (ecomplete-save))
8268 (autoload 'ecomplete-display-matches "ecomplete")
8270 (defun message--in-tocc-p ()
8271 (and (memq (char-after (point-at-bol)) '(?C ?T ?\t ? ))
8272 (message-point-in-header-p)
8273 (save-excursion
8274 (beginning-of-line)
8275 (while (and (memq (char-after) '(?\t ? ))
8276 (zerop (forward-line -1))))
8277 (looking-at "To:\\|Cc:"))))
8279 (defun message-display-abbrev (&optional choose)
8280 "Display the next possible abbrev for the text before point."
8281 (interactive (list t))
8282 (when (message--in-tocc-p)
8283 (let* ((end (point))
8284 (start (save-excursion
8285 (and (re-search-backward "[\n\t ]" nil t)
8286 (1+ (point)))))
8287 (word (when start (buffer-substring start end)))
8288 (match (when (and word
8289 (not (zerop (length word))))
8290 (ecomplete-display-matches 'mail word choose))))
8291 (when (and choose match)
8292 (delete-region start end)
8293 (insert match)))))
8295 (defun message-ecomplete-capf ()
8296 "Return completion data for email addresses in Ecomplete.
8297 Meant for use on `completion-at-point-functions'."
8298 (when (and (bound-and-true-p ecomplete-database)
8299 (fboundp 'ecomplete-completion-table)
8300 (message--in-tocc-p))
8301 (let ((end (save-excursion
8302 (skip-chars-forward "^, \t\n")
8303 (point)))
8304 (start (save-excursion
8305 (skip-chars-backward "^, \t\n")
8306 (point))))
8307 `(,start ,end ,(ecomplete-completion-table 'mail)))))
8309 ;; To send pre-formatted letters like the example below, you can use
8310 ;; `message-send-form-letter':
8311 ;; --8<---------------cut here---------------start------------->8---
8312 ;; To: alice@invalid.invalid
8313 ;; Subject: Verification of your contact information
8314 ;; From: Contact verification <admin@foo.invalid>
8315 ;; --text follows this line--
8316 ;; Hi Alice,
8317 ;; please verify that your contact information is still valid:
8318 ;; Alice A, A avenue 11, 1111 A town, Austria
8319 ;; ----------next form letter message follows this line----------
8320 ;; To: bob@invalid.invalid
8321 ;; Subject: Verification of your contact information
8322 ;; From: Contact verification <admin@foo.invalid>
8323 ;; --text follows this line--
8324 ;; Hi Bob,
8325 ;; please verify that your contact information is still valid:
8326 ;; Bob, B street 22, 22222 Be town, Belgium
8327 ;; ----------next form letter message follows this line----------
8328 ;; To: charlie@invalid.invalid
8329 ;; Subject: Verification of your contact information
8330 ;; From: Contact verification <admin@foo.invalid>
8331 ;; --text follows this line--
8332 ;; Hi Charlie,
8333 ;; please verify that your contact information is still valid:
8334 ;; Charlie Chaplin, C plaza 33, 33333 C town, Chile
8335 ;; --8<---------------cut here---------------end--------------->8---
8337 ;; FIXME: What is the most common term (circular letter, form letter, serial
8338 ;; letter, standard letter) for such kind of letter? See also
8339 ;; <http://en.wikipedia.org/wiki/Form_letter>
8341 ;; FIXME: Maybe extent message-mode's font-lock support to recognize
8342 ;; `message-form-letter-separator', i.e. highlight each message like a single
8343 ;; message.
8345 (defcustom message-form-letter-separator
8346 "\n----------next form letter message follows this line----------\n"
8347 "Separator for `message-send-form-letter'."
8348 ;; :group 'message-form-letter
8349 :group 'message-various
8350 :version "23.1" ;; No Gnus
8351 :type 'string)
8353 (defcustom message-send-form-letter-delay 1
8354 "Delay in seconds when sending a message with `message-send-form-letter'.
8355 Only used when `message-send-form-letter' is called with non-nil
8356 argument `force'."
8357 ;; :group 'message-form-letter
8358 :group 'message-various
8359 :version "23.1" ;; No Gnus
8360 :type 'integer)
8362 (defun message-send-form-letter (&optional force)
8363 "Sent all form letter messages from current buffer.
8364 Unless FORCE, prompt before sending.
8366 The messages are separated by `message-form-letter-separator'.
8367 Header and body are separated by `mail-header-separator'."
8368 (interactive "P")
8369 (let ((sent 0) (skipped 0)
8370 start end text
8371 buff
8372 to done)
8373 (goto-char (point-min))
8374 (while (not done)
8375 (setq start (point)
8376 end (if (search-forward message-form-letter-separator nil t)
8377 (- (point) (length message-form-letter-separator) -1)
8378 (setq done t)
8379 (point-max)))
8380 (setq text
8381 (buffer-substring-no-properties start end))
8382 (setq buff (generate-new-buffer "*mail - form letter*"))
8383 (with-current-buffer buff
8384 (insert text)
8385 (message-mode)
8386 (setq to (message-fetch-field "To"))
8387 (switch-to-buffer buff)
8388 (when force
8389 (sit-for message-send-form-letter-delay))
8390 (if (or force
8391 (y-or-n-p (format-message "Send message to `%s'? " to)))
8392 (progn
8393 (setq sent (1+ sent))
8394 (message-send-and-exit))
8395 (message "Message to `%s' skipped." to)
8396 (setq skipped (1+ skipped)))
8397 (when (buffer-live-p buff)
8398 (kill-buffer buff))))
8399 (message "%s message(s) sent, %s skipped." sent skipped)))
8401 (defun message-replace-header (header new-value &optional after force)
8402 "Remove HEADER and insert the NEW-VALUE.
8403 If AFTER, insert after this header. If FORCE, insert new field
8404 even if NEW-VALUE is empty."
8405 ;; Similar to `nnheader-replace-header' but for message buffers.
8406 (save-excursion
8407 (save-restriction
8408 (message-narrow-to-headers)
8409 (message-remove-header header))
8410 (when (or force (> (length new-value) 0))
8411 (if after
8412 (message-position-on-field header after)
8413 (message-position-on-field header))
8414 (insert new-value))))
8416 (make-obsolete-variable
8417 'message-recipients-without-full-name
8418 "Recipients are simplified by default" "27.1")
8419 (defcustom message-recipients-without-full-name
8420 (list "ding@gnus.org"
8421 "bugs@gnus.org"
8422 "emacs-devel@gnu.org"
8423 "emacs-pretest-bug@gnu.org"
8424 "bug-gnu-emacs@gnu.org")
8425 "Mail addresses that have no full name.
8426 Used in `message-simplify-recipients'."
8427 ;; Maybe the addresses could be extracted from
8428 ;; `gnus-parameter-to-list-alist'?
8429 :type '(choice (const :tag "None" nil)
8430 (repeat string))
8431 :version "23.1" ;; No Gnus
8432 :group 'message-headers)
8434 (make-obsolete 'message-simplify-recipients nil "27.1")
8435 (defun message-simplify-recipients ()
8436 (interactive)
8437 (dolist (hdr '("Cc" "To"))
8438 (message-replace-header
8440 (mapconcat
8441 (lambda (addrcomp)
8442 (if (and message-recipients-without-full-name
8443 (string-match
8444 (regexp-opt message-recipients-without-full-name)
8445 (cadr addrcomp)))
8446 (cadr addrcomp)
8447 (if (car addrcomp)
8448 (message-make-from (car addrcomp) (cadr addrcomp))
8449 (cadr addrcomp))))
8450 (when (message-fetch-field hdr)
8451 (mail-extract-address-components
8452 (message-fetch-field hdr) t))
8453 ", "))))
8455 ;;; multipart/related and HTML support.
8457 (defun message-make-html-message-with-image-files (files)
8458 "Make a message containing the current dired-marked image files."
8459 (interactive (list (dired-get-marked-files nil current-prefix-arg)))
8460 (message-mail)
8461 (message-goto-body)
8462 (insert "<#part type=text/html>\n\n")
8463 (dolist (file files)
8464 (insert (format "<img src=%S>\n\n" file)))
8465 (message-toggle-image-thumbnails)
8466 (message-goto-to))
8468 (defun message-toggle-image-thumbnails ()
8469 "For any included image files, insert a thumbnail of that image."
8470 (interactive)
8471 (let ((displayed nil))
8472 (save-excursion
8473 (goto-char (point-min))
8474 (while (not (eobp))
8475 (when-let* ((props (get-text-property (point) 'display)))
8476 (when (and (consp props)
8477 (eq (car props) 'image))
8478 (put-text-property (point) (1+ (point)) 'display nil)
8479 (setq displayed t)))
8480 (forward-char 1)))
8481 (unless displayed
8482 (save-excursion
8483 (goto-char (point-min))
8484 (while (re-search-forward "<img.*src=\"\\([^\"]+\\).*>" nil t)
8485 (let ((string (match-string 0))
8486 (file (match-string 1))
8487 (edges (window-inside-pixel-edges
8488 (get-buffer-window (current-buffer)))))
8489 (delete-region (match-beginning 0) (match-end 0))
8490 (insert-image
8491 (create-image
8492 file 'imagemagick nil
8493 :max-width (truncate
8494 (* 0.7 (- (nth 2 edges) (nth 0 edges))))
8495 :max-height (truncate
8496 (* 0.5 (- (nth 3 edges) (nth 1 edges)))))
8497 string)))))))
8499 (provide 'message)
8501 (run-hooks 'message-load-hook)
8503 ;; Local Variables:
8504 ;; coding: utf-8
8505 ;; End:
8507 ;;; message.el ends here