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