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