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