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