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