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