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