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