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