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