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