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