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