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