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