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