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