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