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