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