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