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