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