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