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