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