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