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