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