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