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