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