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