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