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