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