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