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