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