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