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