1 ;;; message.el --- composing mail and news messages
3 ;; Copyright (C) 1996-2011 Free Software Foundation, Inc.
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
6 ;; Keywords: mail, news
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is free software: you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation, either version 3 of the License, or
13 ;; (at your option) any later version.
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
25 ;; This mode provides mail-sending facilities from within Emacs. It
26 ;; consists mainly of large chunks of code from the sendmail.el,
27 ;; gnus-msg.el and rnewspost.el files.
31 ;; For Emacs <22.2 and XEmacs.
33 (unless (fboundp 'declare-function) (defmacro declare-function (&rest r))))
40 ;; Only for the trivial macros mail-header-from, mail-header-date
41 ;; mail-header-references, mail-header-subject, mail-header-id
42 (eval-when-compile (require 'nnheader))
43 ;; This is apparently necessary even though things are autoloaded.
44 ;; Because we dynamically bind mail-abbrev-mode-regexp, we'd better
45 ;; require mailabbrev here.
46 (if (featurep 'xemacs)
47 (require 'mail-abbrevs)
48 (require 'mailabbrev))
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")
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")
74 (defgroup message-buffers nil
76 :link '(custom-manual "(message)Message Buffers")
79 (defgroup message-sending nil
81 :link '(custom-manual "(message)Sending Variables")
84 (defgroup message-interface nil
86 :link '(custom-manual "(message)Interface")
89 (defgroup message-forwarding nil
91 :link '(custom-manual "(message)Forwarding")
92 :group 'message-interface)
94 (defgroup message-insertion nil
96 :link '(custom-manual "(message)Insertion")
99 (defgroup message-headers nil
101 :link '(custom-manual "(message)Message Headers")
104 (defgroup message-news nil
105 "Composing News Messages."
108 (defgroup message-mail nil
109 "Composing Mail Messages."
112 (defgroup message-faces nil
113 "Faces used for message composing."
117 (defcustom message-directory "~/Mail/"
118 "*Directory from which all other mail file variables are derived."
119 :group 'message-various
122 (defcustom message-max-buffers 10
123 "*How many buffers to keep before starting to kill them off."
124 :group 'message-buffers
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-cite-style nil
133 "The overall style to be used when yanking cited text.
134 Values are either `traditional' (cited text first),
135 `top-post' (cited text at the bottom), or nil (don't override the
136 individual message variables)."
138 :group 'message-various
139 :type '(choice (const :tag "None" :value nil)
140 (const :tag "Traditional" :value traditional)
141 (const :tag "Top-post" :value top-post)))
143 (defcustom message-fcc-handler-function 'message-output
144 "*A function called to save outgoing articles.
145 This function will be called with the name of the file to store the
146 article in. The default function is `message-output' which saves in Unix
148 :type '(radio (function-item message-output)
149 (function :tag "Other"))
150 :group 'message-sending)
152 (defcustom message-fcc-externalize-attachments nil
153 "If non-nil, attachments are included as external parts in Fcc copies."
156 :group 'message-sending)
158 (defcustom message-courtesy-message
159 "The following message is a courtesy copy of an article\nthat has been posted to %s as well.\n\n"
160 "*This is inserted at the start of a mailed copy of a posted message.
161 If the string contains the format spec \"%s\", the Newsgroups
162 the article has been posted to will be inserted there.
163 If this variable is nil, no such courtesy message will be added."
164 :group 'message-sending
165 :type '(radio string (const nil)))
167 (defcustom message-ignored-bounced-headers
168 "^\\(Received\\|Return-Path\\|Delivered-To\\):"
169 "*Regexp that matches headers to be removed in resent bounced mail."
170 :group 'message-interface
173 (defcustom message-from-style 'default
174 ;; In Emacs 24.1 this defaults to the value of `mail-from-style'
176 ;; `angles' in Emacs 22.1~23.1, XEmacs 21.4, 21.5, and SXEmacs 22.1;
177 ;; `system-default' in Emacs 23.2, and 24.1
178 "Specifies how \"From\" headers look.
180 If nil, they contain just the return address like:
182 If `parens', they look like:
183 king@grassland.com (Elvis Parsley)
184 If `angles', they look like:
185 Elvis Parsley <king@grassland.com>
187 Otherwise, most addresses look like `angles', but they look like
188 `parens' if `angles' would need quoting and `parens' would not."
190 :type '(choice (const :tag "simple" nil)
194 :group 'message-headers)
196 (defcustom message-insert-canlock t
197 "Whether to insert a Cancel-Lock header in news postings."
199 :group 'message-headers
202 (defcustom message-syntax-checks
203 (if message-insert-canlock '((sender . disabled)) nil)
204 ;; Guess this one shouldn't be easy to customize...
205 "*Controls what syntax checks should not be performed on outgoing posts.
206 To disable checking of long signatures, for instance, add
207 `(signature . disabled)' to this list.
209 Don't touch this variable unless you really know what you're doing.
211 Checks include `approved', `bogus-recipient', `continuation-headers',
212 `control-chars', `empty', `existing-newsgroups', `from', `illegible-text',
213 `invisible-text', `long-header-lines', `long-lines', `message-id',
214 `multiple-headers', `new-text', `newsgroups', `quoting-style',
215 `repeated-newsgroups', `reply-to', `sender', `sendsys', `shoot',
216 `shorten-followup-to', `signature', `size', `subject', `subject-cmsg'
217 and `valid-newsgroups'."
219 :type '(repeat sexp)) ; Fixme: improve this
221 (defcustom message-required-headers '((optional . References)
223 "*Headers to be generated or prompted for when sending a message.
224 Also see `message-required-news-headers' and
225 `message-required-mail-headers'."
228 :group 'message-headers
229 :link '(custom-manual "(message)Message Headers")
230 :type '(repeat sexp))
232 (defcustom message-draft-headers '(References From Date)
233 "*Headers to be generated when saving a draft message."
236 :group 'message-headers
237 :link '(custom-manual "(message)Message Headers")
238 :type '(repeat sexp))
240 (defcustom message-required-news-headers
241 '(From Newsgroups Subject Date Message-ID
242 (optional . Organization)
243 (optional . User-Agent))
244 "*Headers to be generated or prompted for when posting an article.
245 RFC977 and RFC1036 require From, Date, Newsgroups, Subject,
246 Message-ID. Organization, Lines, In-Reply-To, Expires, and
247 User-Agent are optional. If you don't want message to insert some
248 header, remove it from this list."
250 :group 'message-headers
251 :link '(custom-manual "(message)Message Headers")
252 :type '(repeat sexp))
254 (defcustom message-required-mail-headers
255 '(From Subject Date (optional . In-Reply-To) Message-ID
256 (optional . User-Agent))
257 "*Headers to be generated or prompted for when mailing a message.
258 It is recommended that From, Date, To, Subject and Message-ID be
259 included. Organization and User-Agent are optional."
261 :group 'message-headers
262 :link '(custom-manual "(message)Message Headers")
263 :type '(repeat sexp))
265 (defcustom message-prune-recipient-rules nil
266 "Rules for how to prune the list of recipients when doing wide replies.
267 This is a list of regexps and regexp matches."
270 :group 'message-headers
271 :link '(custom-manual "(message)Wide Reply")
272 :type '(repeat regexp))
274 (defcustom message-deletable-headers '(Message-ID Date Lines)
275 "Headers to be deleted if they already exist and were generated by message previously."
276 :group 'message-headers
277 :link '(custom-manual "(message)Message Headers")
280 (defcustom message-ignored-news-headers
281 "^NNTP-Posting-Host:\\|^Xref:\\|^[BGF]cc:\\|^Resent-Fcc:\\|^X-Draft-From:\\|^X-Gnus-Agent-Meta-Information:"
282 "*Regexp of headers to be removed unconditionally before posting."
284 :group 'message-headers
285 :link '(custom-manual "(message)Message Headers")
286 :type '(repeat :value-to-internal (lambda (widget value)
287 (custom-split-regexp-maybe value))
288 :match (lambda (widget value)
290 (widget-editable-list-match widget value)))
293 (defcustom message-ignored-mail-headers
294 "^\\([GF]cc\\|Resent-Fcc\\|Xref\\|X-Draft-From\\|X-Gnus-Agent-Meta-Information\\):"
295 "*Regexp of headers to be removed unconditionally before mailing."
297 :group 'message-headers
298 :link '(custom-manual "(message)Mail Headers")
301 (defcustom message-ignored-supersedes-headers "^Path:\\|^Date\\|^NNTP-Posting-Host:\\|^Xref:\\|^Lines:\\|^Received:\\|^X-From-Line:\\|^X-Trace:\\|^X-ID:\\|^X-Complaints-To:\\|Return-Path:\\|^Supersedes:\\|^NNTP-Posting-Date:\\|^X-Trace:\\|^X-Complaints-To:\\|^Cancel-Lock:\\|^Cancel-Key:\\|^X-Hashcash:\\|^X-Payment:\\|^Approved:\\|^Injection-Date:\\|^Injection-Info:"
302 "*Header lines matching this regexp will be deleted before posting.
303 It's best to delete old Path and Date headers before posting to avoid
305 :group 'message-interface
306 :link '(custom-manual "(message)Superseding")
307 :type '(repeat :value-to-internal (lambda (widget value)
308 (custom-split-regexp-maybe value))
309 :match (lambda (widget value)
311 (widget-editable-list-match widget value)))
314 (defcustom message-subject-re-regexp
315 "^[ \t]*\\([Rr][Ee]\\(\\[[0-9]*\\]\\)*:[ \t]*\\)*[ \t]*"
316 "*Regexp matching \"Re: \" in the subject line."
317 :group 'message-various
318 :link '(custom-manual "(message)Message Headers")
321 ;;; Start of variables adopted from `message-utils.el'.
323 (defcustom message-subject-trailing-was-query t
324 "*What to do with trailing \"(was: <old subject>)\" in subject lines.
325 If nil, leave the subject unchanged. If it is the symbol `ask', query
326 the user what do do. In this case, the subject is matched against
327 `message-subject-trailing-was-ask-regexp'. If
328 `message-subject-trailing-was-query' is t, always strip the trailing
329 old subject. In this case, `message-subject-trailing-was-regexp' is
332 :type '(choice (const :tag "never" nil)
333 (const :tag "always strip" t)
335 :link '(custom-manual "(message)Message Headers")
336 :group 'message-various)
338 (defcustom message-subject-trailing-was-ask-regexp
339 "[ \t]*\\([[(]+[Ww][Aa][Ss]:?[ \t]*.*[])]+\\)"
340 "*Regexp matching \"(was: <old subject>)\" in the subject line.
342 The function `message-strip-subject-trailing-was' uses this regexp if
343 `message-subject-trailing-was-query' is set to the symbol `ask'. If
344 the variable is t instead of `ask', use
345 `message-subject-trailing-was-regexp' instead.
347 It is okay to create some false positives here, as the user is asked."
349 :group 'message-various
350 :link '(custom-manual "(message)Message Headers")
353 (defcustom message-subject-trailing-was-regexp
354 "[ \t]*\\((*[Ww][Aa][Ss]:[ \t]*.*)\\)"
355 "*Regexp matching \"(was: <old subject>)\" in the subject line.
357 If `message-subject-trailing-was-query' is set to t, the subject is
358 matched against `message-subject-trailing-was-regexp' in
359 `message-strip-subject-trailing-was'. You should use a regexp creating very
360 few false positives here."
362 :group 'message-various
363 :link '(custom-manual "(message)Message Headers")
366 ;;; marking inserted text
368 (defcustom message-mark-insert-begin
369 "--8<---------------cut here---------------start------------->8---\n"
370 "How to mark the beginning of some inserted text."
373 :link '(custom-manual "(message)Insertion Variables")
374 :group 'message-various)
376 (defcustom message-mark-insert-end
377 "--8<---------------cut here---------------end--------------->8---\n"
378 "How to mark the end of some inserted text."
381 :link '(custom-manual "(message)Insertion Variables")
382 :group 'message-various)
384 (defcustom message-archive-header "X-No-Archive: Yes\n"
385 "Header to insert when you don't want your article to be archived.
386 Archives \(such as groups.google.com\) respect this header."
389 :link '(custom-manual "(message)Header Commands")
390 :group 'message-various)
392 (defcustom message-archive-note
393 "X-No-Archive: Yes - save http://groups.google.com/"
394 "Note to insert why you wouldn't want this posting archived.
395 If nil, don't insert any text in the body."
397 :type '(radio string (const nil))
398 :link '(custom-manual "(message)Header Commands")
399 :group 'message-various)
401 ;;; Crossposts and Followups
402 ;; inspired by JoH-followup-to by Jochem Huhman <joh at gmx.de>
403 ;; new suggestions by R. Weikusat <rw at another.de>
405 (defvar message-cross-post-old-target nil
406 "Old target for cross-posts or follow-ups.")
407 (make-variable-buffer-local 'message-cross-post-old-target)
409 (defcustom message-cross-post-default t
410 "When non-nil `message-cross-post-followup-to' will perform a crosspost.
411 If nil, `message-cross-post-followup-to' will only do a followup. Note that
412 you can explicitly override this setting by calling
413 `message-cross-post-followup-to' with a prefix."
416 :group 'message-various)
418 (defcustom message-cross-post-note "Crosspost & Followup-To: "
419 "Note to insert before signature to notify of cross-post and follow-up."
422 :group 'message-various)
424 (defcustom message-followup-to-note "Followup-To: "
425 "Note to insert before signature to notify of follow-up only."
428 :group 'message-various)
430 (defcustom message-cross-post-note-function 'message-cross-post-insert-note
431 "Function to use to insert note about Crosspost or Followup-To.
432 The function will be called with four arguments. The function should not only
433 insert a note, but also ensure old notes are deleted. See the documentation
434 for `message-cross-post-insert-note'."
437 :group 'message-various)
439 ;;; End of variables adopted from `message-utils.el'.
441 (defcustom message-signature-separator "^-- $"
442 "Regexp matching the signature separator.
443 This variable is used to strip off the signature from quoted text
444 when `message-cite-function' is
445 `message-cite-original-without-signature'. Most useful values
446 are \"^-- $\" (strict) and \"^-- *$\" (loose; allow missing
448 :type '(choice (const :tag "strict" "^-- $")
449 (const :tag "loose" "^-- *$")
451 :version "22.3" ;; Gnus 5.10.12 (changed default)
452 :link '(custom-manual "(message)Various Message Variables")
453 :group 'message-various)
455 (defcustom message-elide-ellipsis "\n[...]\n\n"
456 "*The string which is inserted for elided text."
458 :link '(custom-manual "(message)Various Commands")
459 :group 'message-various)
461 (defcustom message-interactive t
462 ;; In Emacs 24.1 this defaults to the value of `mail-interactive'
464 ;; `nil' in Emacs 22.1~22.3, XEmacs 21.4, 21.5, and SXEmacs 22.1;
465 ;; `t' in Emacs 23.1~24.1
466 "Non-nil means when sending a message wait for and display errors.
467 A value of nil means let mailer mail back a message to report errors."
469 :group 'message-sending
471 :link '(custom-manual "(message)Sending Variables")
474 (defcustom message-confirm-send nil
475 "When non-nil, ask for confirmation when sending a message."
476 :group 'message-sending
478 :version "23.1" ;; No Gnus
479 :link '(custom-manual "(message)Sending Variables")
482 (defcustom message-generate-new-buffers 'unsent
483 "*Say whether to create a new message buffer to compose a message.
484 Valid values include:
487 Generate the buffer name in the Message way (e.g., *mail*, *news*,
488 *mail to whom*, *news on group*, etc.) and continue editing in the
489 existing buffer of that name. If there is no such buffer, it will
493 Create the new buffer with the name generated in the Message way.
496 Similar to `unique' but the buffer name begins with \"*unsent \".
499 Similar to nil but the buffer name is simpler like *mail message*.
502 If this is a function, call that function with three parameters:
503 The type, the To address and the group name (any of these may be nil).
504 The function should return the new buffer name."
506 :group 'message-buffers
507 :link '(custom-manual "(message)Message Buffers")
508 :type '(choice (const nil)
509 (sexp :tag "unique" :format "unique\n" :value unique
510 :match (lambda (widget value) (memq value '(unique t))))
513 (function :format "\n %{%t%}: %v")))
515 (defcustom message-kill-buffer-on-exit nil
516 "*Non-nil means that the message buffer will be killed after sending a message."
517 :group 'message-buffers
518 :link '(custom-manual "(message)Message Buffers")
521 (defcustom message-kill-buffer-query t
522 "*Non-nil means that killing a modified message buffer has to be confirmed.
523 This is used by `message-kill-buffer'."
524 :version "23.1" ;; No Gnus
525 :group 'message-buffers
528 (defcustom message-user-organization
529 (or (getenv "ORGANIZATION") t)
530 "String to be used as an Organization header.
531 If t, use `message-user-organization-file'."
532 :group 'message-headers
533 :type '(choice string
534 (const :tag "consult file" t)))
536 (defcustom message-user-organization-file
538 (dolist (f (list "/etc/organization"
539 "/etc/news/organization"
540 "/usr/lib/news/organization"))
541 (when (file-readable-p f)
544 "*Local news organization file."
546 :link '(custom-manual "(message)News Headers")
547 :group 'message-headers)
549 (defcustom message-make-forward-subject-function
550 #'message-forward-subject-name-subject
551 "*List of functions called to generate subject headers for forwarded messages.
552 The subject generated by the previous function is passed into each
555 The provided functions are:
557 * `message-forward-subject-author-subject' Source of article (author or
558 newsgroup), in brackets followed by the subject
559 * `message-forward-subject-name-subject' Source of article (name of author
560 or newsgroup), in brackets followed by the subject
561 * `message-forward-subject-fwd' Subject of article with 'Fwd:' prepended
563 :group 'message-forwarding
564 :link '(custom-manual "(message)Forwarding")
565 :type '(radio (function-item message-forward-subject-author-subject)
566 (function-item message-forward-subject-fwd)
567 (function-item message-forward-subject-name-subject)
568 (repeat :tag "List of functions" function)))
570 (defcustom message-forward-as-mime t
571 "*Non-nil means forward messages as an inline/rfc822 MIME section.
572 Otherwise, directly inline the old message in the forwarded message."
574 :group 'message-forwarding
575 :link '(custom-manual "(message)Forwarding")
578 (defcustom message-forward-show-mml 'best
579 "*Non-nil means show forwarded messages as MML (decoded from MIME).
580 Otherwise, forwarded messages are unchanged.
581 Can also be the symbol `best' to indicate that MML should be
582 used, except when it is a bad idea to use MML. One example where
583 it is a bad idea is when forwarding a signed or encrypted
584 message, because converting MIME to MML would invalidate the
587 :group 'message-forwarding
588 :type '(choice (const :tag "use MML" t)
589 (const :tag "don't use MML " nil)
590 (const :tag "use MML when appropriate" best)))
592 (defcustom message-forward-before-signature t
593 "*Non-nil means put forwarded message before signature, else after."
594 :group 'message-forwarding
597 (defcustom message-wash-forwarded-subjects nil
598 "*Non-nil means try to remove as much cruft as possible from the subject.
599 Done before generating the new subject of a forward."
600 :group 'message-forwarding
601 :link '(custom-manual "(message)Forwarding")
604 (defcustom message-ignored-resent-headers
605 ;; `Delivered-To' needs to be removed because some mailers use it to
606 ;; detect loops, so if you resend a message to an address that ultimately
607 ;; comes back to you (e.g. a mailing-list to which you subscribe, in which
608 ;; case you may be removed from the list on the grounds that mail to you
609 ;; bounced with a "mailing loop" error).
610 "^Return-receipt\\|^X-Gnus\\|^Gnus-Warning:\\|^>?From \\|^Delivered-To:"
611 "*All headers that match this regexp will be deleted when resending a message."
612 :group 'message-interface
613 :link '(custom-manual "(message)Resending")
614 :type '(repeat :value-to-internal (lambda (widget value)
615 (custom-split-regexp-maybe value))
616 :match (lambda (widget value)
618 (widget-editable-list-match widget value)))
621 (defcustom message-forward-ignored-headers "^Content-Transfer-Encoding:\\|^X-Gnus"
622 "*All headers that match this regexp will be deleted when forwarding a message."
624 :group 'message-forwarding
625 :type '(repeat :value-to-internal (lambda (widget value)
626 (custom-split-regexp-maybe value))
627 :match (lambda (widget value)
629 (widget-editable-list-match widget value)))
632 (defcustom message-ignored-cited-headers "."
633 "*Delete these headers from the messages you yank."
634 :group 'message-insertion
635 :link '(custom-manual "(message)Insertion Variables")
638 (defcustom message-cite-prefix-regexp
639 ;; In Emacs 24.1 this defaults to the value of
640 ;; `mail-citation-prefix-regexp'; the default value varies according
641 ;; to the Emacs version. In XEmacs 21.4 and 21.5, sendmail.el
643 (if (string-match "[[:digit:]]" "1")
644 ;; Support POSIX? XEmacs 21.5.27 doesn't.
645 "\\([ \t]*[_.[:word:]]+>+\\|[ \t]*[]>|]\\)+"
646 ;; ?-, ?_ or ?. MUST NOT be in syntax entry w.
647 (let (non-word-constituents)
648 (with-syntax-table text-mode-syntax-table
649 (setq non-word-constituents
651 (if (string-match "\\w" "_") "" "_")
652 (if (string-match "\\w" ".") "" "."))))
653 (if (equal non-word-constituents "")
654 "\\([ \t]*\\(\\w\\)+>+\\|[ \t]*[]>|]\\)+"
655 (concat "\\([ \t]*\\(\\w\\|["
656 non-word-constituents
657 "]\\)+>+\\|[ \t]*[]>|]\\)+"))))
658 "*Regexp matching the longest possible citation prefix on a line."
660 :group 'message-insertion
661 :link '(custom-manual "(message)Insertion Variables")
663 :set (lambda (symbol value)
665 (custom-set-default symbol value)
666 (if (boundp 'gnus-message-cite-prefix-regexp)
667 (setq gnus-message-cite-prefix-regexp
668 (concat "^\\(?:" value "\\)"))))))
670 (defcustom message-cancel-message "I am canceling my own article.\n"
671 "Message to be inserted in the cancel message."
672 :group 'message-interface
673 :link '(custom-manual "(message)Canceling News")
676 (defun message-send-mail-function ()
677 "Return suitable value for the variable `message-send-mail-function'."
678 (cond ((and (require 'sendmail)
679 (boundp 'sendmail-program)
681 (executable-find sendmail-program))
682 'message-send-mail-with-sendmail)
683 ((and (locate-library "smtpmail")
684 (boundp 'smtpmail-default-smtp-server)
685 smtpmail-default-smtp-server)
686 'message-smtpmail-send-it)
687 ((locate-library "mailclient")
688 'message-send-mail-with-mailclient)
690 (error "Don't know how to send mail. Please customize `message-send-mail-function'"))))
692 ;; Useful to set in site-init.el
693 (defcustom message-send-mail-function
694 (cond ((eq send-mail-function 'smtpmail-send-it) 'message-smtpmail-send-it)
695 ((eq send-mail-function 'feedmail-send-it) 'feedmail-send-it)
696 ((eq send-mail-function 'mailclient-send-it)
697 'message-send-mail-with-mailclient)
698 (t (message-send-mail-function)))
699 "Function to call to send the current buffer as mail.
700 The headers should be delimited by a line whose contents match the
701 variable `mail-header-separator'.
703 Valid values include `message-send-mail-with-sendmail'
704 `message-send-mail-with-mh', `message-send-mail-with-qmail',
705 `message-smtpmail-send-it', `smtpmail-send-it',
706 `feedmail-send-it' and `message-send-mail-with-mailclient'. The
707 default is system dependent and determined by the function
708 `message-send-mail-function'.
710 See also `send-mail-function'."
711 :type '(radio (function-item message-send-mail-with-sendmail)
712 (function-item message-send-mail-with-mh)
713 (function-item message-send-mail-with-qmail)
714 (function-item message-smtpmail-send-it)
715 (function-item smtpmail-send-it)
716 (function-item feedmail-send-it)
717 (function-item message-send-mail-with-mailclient
718 :tag "Use Mailclient package")
719 (function :tag "Other"))
720 :group 'message-sending
722 :initialize 'custom-initialize-default
723 :link '(custom-manual "(message)Mail Variables")
724 :group 'message-mail)
726 (defcustom message-send-news-function 'message-send-news
727 "Function to call to send the current buffer as news.
728 The headers should be delimited by a line whose contents match the
729 variable `mail-header-separator'."
730 :group 'message-sending
732 :link '(custom-manual "(message)News Variables")
735 (defcustom message-reply-to-function nil
736 "If non-nil, function that should return a list of headers.
737 This function should pick out addresses from the To, Cc, and From headers
738 and respond with new To and Cc headers."
739 :group 'message-interface
740 :link '(custom-manual "(message)Reply")
741 :type '(choice function (const nil)))
743 (defcustom message-wide-reply-to-function nil
744 "If non-nil, function that should return a list of headers.
745 This function should pick out addresses from the To, Cc, and From headers
746 and respond with new To and Cc headers."
747 :group 'message-interface
748 :link '(custom-manual "(message)Wide Reply")
749 :type '(choice function (const nil)))
751 (defcustom message-followup-to-function nil
752 "If non-nil, function that should return a list of headers.
753 This function should pick out addresses from the To, Cc, and From headers
754 and respond with new To and Cc headers."
755 :group 'message-interface
756 :link '(custom-manual "(message)Followup")
757 :type '(choice function (const nil)))
759 (defcustom message-extra-wide-headers nil
760 "If non-nil, a list of additional address headers.
761 These are used when composing a wide reply."
762 :group 'message-sending
763 :type '(repeat string))
765 (defcustom message-use-followup-to 'ask
766 "*Specifies what to do with Followup-To header.
767 If nil, always ignore the header. If it is t, use its value, but
768 query before using the \"poster\" value. If it is the symbol `ask',
769 always query the user whether to use the value. If it is the symbol
770 `use', always use the value."
771 :group 'message-interface
772 :link '(custom-manual "(message)Followup")
773 :type '(choice (const :tag "ignore" nil)
774 (const :tag "use & query" t)
778 (defcustom message-use-mail-followup-to 'use
779 "*Specifies what to do with Mail-Followup-To header.
780 If nil, always ignore the header. If it is the symbol `ask', always
781 query the user whether to use the value. If it is the symbol `use',
782 always use the value."
784 :group 'message-interface
785 :link '(custom-manual "(message)Mailing Lists")
786 :type '(choice (const :tag "ignore" nil)
790 (defcustom message-subscribed-address-functions nil
791 "*Specifies functions for determining list subscription.
792 If nil, do not attempt to determine list subscription with functions.
793 If non-nil, this variable contains a list of functions which return
794 regular expressions to match lists. These functions can be used in
795 conjunction with `message-subscribed-regexps' and
796 `message-subscribed-addresses'."
798 :group 'message-interface
799 :link '(custom-manual "(message)Mailing Lists")
800 :type '(repeat sexp))
802 (defcustom message-subscribed-address-file nil
803 "*A file containing addresses the user is subscribed to.
804 If nil, do not look at any files to determine list subscriptions. If
805 non-nil, each line of this file should be a mailing list address."
807 :group 'message-interface
808 :link '(custom-manual "(message)Mailing Lists")
809 :type '(radio file (const nil)))
811 (defcustom message-subscribed-addresses nil
812 "*Specifies a list of addresses the user is subscribed to.
813 If nil, do not use any predefined list subscriptions. This list of
814 addresses can be used in conjunction with
815 `message-subscribed-address-functions' and `message-subscribed-regexps'."
817 :group 'message-interface
818 :link '(custom-manual "(message)Mailing Lists")
819 :type '(repeat string))
821 (defcustom message-subscribed-regexps nil
822 "*Specifies a list of addresses the user is subscribed to.
823 If nil, do not use any predefined list subscriptions. This list of
824 regular expressions can be used in conjunction with
825 `message-subscribed-address-functions' and `message-subscribed-addresses'."
827 :group 'message-interface
828 :link '(custom-manual "(message)Mailing Lists")
829 :type '(repeat regexp))
831 (defcustom message-allow-no-recipients 'ask
832 "Specifies what to do when there are no recipients other than Gcc/Fcc.
833 If it is the symbol `always', the posting is allowed. If it is the
834 symbol `never', the posting is not allowed. If it is the symbol
835 `ask', you are prompted."
837 :group 'message-interface
838 :link '(custom-manual "(message)Message Headers")
839 :type '(choice (const always)
843 (defcustom message-sendmail-f-is-evil nil
844 "*Non-nil means don't add \"-f username\" to the sendmail command line.
845 Doing so would be even more evil than leaving it out."
846 :group 'message-sending
847 :link '(custom-manual "(message)Mail Variables")
850 (defcustom message-sendmail-envelope-from nil
851 ;; In Emacs 24.1 this defaults to the value of `mail-envelope-from'
852 ;; if it is available, or defaults to nil. sendmail.el provides it;
853 ;; the default value is nil in all (X)Emacsen that Gnus supports.
854 "*Envelope-from when sending mail with sendmail.
855 If this is nil, use `user-mail-address'. If it is the symbol
856 `header', use the From: header of the message."
858 :type '(choice (string :tag "From name")
859 (const :tag "Use From: header from message" header)
860 (const :tag "Use `user-mail-address'" nil))
861 :link '(custom-manual "(message)Mail Variables")
862 :group 'message-sending)
864 (defcustom message-sendmail-extra-arguments nil
865 "Additional arguments to `sendmail-program'."
866 ;; E.g. '("-a" "account") for msmtp
867 :version "23.1" ;; No Gnus
868 :type '(repeat string)
869 ;; :link '(custom-manual "(message)Mail Variables")
870 :group 'message-sending)
872 ;; qmail-related stuff
873 (defcustom message-qmail-inject-program "/var/qmail/bin/qmail-inject"
874 "Location of the qmail-inject program."
875 :group 'message-sending
876 :link '(custom-manual "(message)Mail Variables")
879 (defcustom message-qmail-inject-args nil
880 "Arguments passed to qmail-inject programs.
881 This should be a list of strings, one string for each argument.
882 It may also be a function.
884 For e.g., if you wish to set the envelope sender address so that bounces
885 go to the right place or to deal with listserv's usage of that address, you
886 might set this variable to '(\"-f\" \"you@some.where\")."
887 :group 'message-sending
888 :link '(custom-manual "(message)Mail Variables")
889 :type '(choice (function)
892 (defvar gnus-post-method)
893 (defvar gnus-select-method)
894 (defcustom message-post-method
895 (cond ((and (boundp 'gnus-post-method)
896 (listp gnus-post-method)
899 ((boundp 'gnus-select-method)
902 "*Method used to post news.
903 Note that when posting from inside Gnus, for instance, this
904 variable isn't used."
906 :group 'message-sending
907 ;; This should be the `gnus-select-method' widget, but that might
908 ;; create a dependence to `gnus.el'.
911 (defcustom message-generate-headers-first nil
912 "Which headers should be generated before starting to compose a message.
913 If t, generate all required headers. This can also be a list of headers to
914 generate. The variables `message-required-news-headers' and
915 `message-required-mail-headers' specify which headers to generate.
917 Note that the variable `message-deletable-headers' specifies headers which
918 are to be deleted and then re-generated before sending, so this variable
919 will not have a visible effect for those headers."
920 :group 'message-headers
921 :link '(custom-manual "(message)Message Headers")
922 :type '(choice (const :tag "None" nil)
924 (repeat (sexp :tag "Header"))))
926 (defcustom message-fill-column 72
927 "Column beyond which automatic line-wrapping should happen.
928 Local value for message buffers. If non-nil, also turn on
929 auto-fill in message buffers."
930 :group 'message-various
931 ;; :link '(custom-manual "(message)Message Headers")
932 :type '(choice (const :tag "Don't turn on auto fill" nil)
935 (defcustom message-setup-hook nil
936 "Normal hook, run each time a new outgoing message is initialized.
937 The function `message-setup' runs this hook."
938 :group 'message-various
939 :link '(custom-manual "(message)Various Message Variables")
942 (defcustom message-cancel-hook nil
943 "Hook run when cancelling articles."
944 :group 'message-various
945 :link '(custom-manual "(message)Various Message Variables")
948 (defcustom message-signature-setup-hook nil
949 "Normal hook, run each time a new outgoing message is initialized.
950 It is run after the headers have been inserted and before
951 the signature is inserted."
952 :group 'message-various
953 :link '(custom-manual "(message)Various Message Variables")
956 (defcustom message-mode-hook nil
957 "Hook run in message mode buffers."
958 :group 'message-various
961 (defcustom message-header-hook nil
962 "Hook run in a message mode buffer narrowed to the headers."
963 :group 'message-various
966 (defcustom message-header-setup-hook nil
967 "Hook called narrowed to the headers when setting up a message buffer."
968 :group 'message-various
969 :link '(custom-manual "(message)Various Message Variables")
972 (defcustom message-minibuffer-local-map
973 (let ((map (make-sparse-keymap 'message-minibuffer-local-map)))
974 (set-keymap-parent map minibuffer-local-map)
976 "Keymap for `message-read-from-minibuffer'."
978 :group 'message-various)
980 (defcustom message-citation-line-function 'message-insert-citation-line
981 "*Function called to insert the \"Whomever writes:\" line.
983 Predefined functions include `message-insert-citation-line' and
984 `message-insert-formatted-citation-line' (see the variable
985 `message-citation-line-format').
987 Note that Gnus provides a feature where the reader can click on
988 `writes:' to hide the cited text. If you change this line too much,
989 people who read your message will have to change their Gnus
990 configuration. See the variable `gnus-cite-attribution-suffix'."
992 (function-item :tag "plain" message-insert-citation-line)
993 (function-item :tag "formatted" message-insert-formatted-citation-line)
994 (function :tag "Other"))
995 :link '(custom-manual "(message)Insertion Variables")
996 :group 'message-insertion)
998 (defcustom message-citation-line-format "On %a, %b %d %Y, %N wrote:\n"
999 "Format of the \"Whomever writes:\" line.
1001 The string is formatted using `format-spec'. The following
1002 constructs are replaced:
1004 %f The full From, e.g. \"John Doe <john.doe@example.invalid>\".
1005 %n The mail address, e.g. \"john.doe@example.invalid\".
1006 %N The real name if present, e.g.: \"John Doe\", else fall
1007 back to the mail address.
1008 %F The first name if present, e.g.: \"John\".
1009 %L The last name if present, e.g.: \"Doe\".
1011 All other format specifiers are passed to `format-time-string'
1012 which is called using the date from the article your replying to.
1013 Extracting the first (%F) and last name (%L) is done
1014 heuristically, so you should always check it yourself.
1016 Please also read the note in the documentation of
1017 `message-citation-line-function'."
1018 :type '(choice (const :tag "Plain" "%f writes:")
1019 (const :tag "Include date" "On %a, %b %d %Y, %n wrote:")
1021 :link '(custom-manual "(message)Insertion Variables")
1022 :version "23.1" ;; No Gnus
1023 :group 'message-insertion)
1025 (defcustom message-yank-prefix "> "
1026 ;; In Emacs 24.1 this defaults to the value of `mail-yank-prefix'
1027 ;; that defaults to:
1028 ;; `nil' in Emacs 22.1~23.1;
1029 ;; "> " in Emacs 23.2, 24.1, XEmacs 21.4, 21.5, and SXEmacs 22.1
1030 "*Prefix inserted on the lines of yanked messages.
1031 Fix `message-cite-prefix-regexp' if it is set to an abnormal value.
1032 See also `message-yank-cited-prefix' and `message-yank-empty-prefix'."
1035 :link '(custom-manual "(message)Insertion Variables")
1036 :group 'message-insertion)
1038 (defcustom message-yank-cited-prefix ">"
1039 "*Prefix inserted on cited lines of yanked messages.
1040 Fix `message-cite-prefix-regexp' if it is set to an abnormal value.
1041 See also `message-yank-prefix' and `message-yank-empty-prefix'."
1044 :link '(custom-manual "(message)Insertion Variables")
1045 :group 'message-insertion)
1047 (defcustom message-yank-empty-prefix ">"
1048 "*Prefix inserted on empty lines of yanked messages.
1049 See also `message-yank-prefix' and `message-yank-cited-prefix'."
1052 :link '(custom-manual "(message)Insertion Variables")
1053 :group 'message-insertion)
1055 (defcustom message-indentation-spaces 3
1056 ;; In Emacs 24.1 this defaults to the value of
1057 ;; `mail-indentation-spaces' that defaults to `3' in Emacs 22.1~24.1,
1058 ;; and SXEmacs 22.1. In XEmacs 21.4 and 21.5, sendmail.el provides
1059 ;; it; the defalut value is `3'.
1060 "*Number of spaces to insert at the beginning of each cited line.
1061 Used by `message-yank-original' via `message-yank-cite'."
1063 :group 'message-insertion
1064 :link '(custom-manual "(message)Insertion Variables")
1067 (defcustom message-cite-function 'message-cite-original-without-signature
1068 "*Function for citing an original message.
1069 Predefined functions include `message-cite-original' and
1070 `message-cite-original-without-signature'.
1071 Note that these functions use `mail-citation-hook' if that is non-nil."
1072 :type '(radio (function-item message-cite-original)
1073 (function-item message-cite-original-without-signature)
1074 (function-item sc-cite-original)
1075 (function :tag "Other"))
1076 :link '(custom-manual "(message)Insertion Variables")
1077 :version "22.3" ;; Gnus 5.10.12 (changed default)
1078 :group 'message-insertion)
1080 (defcustom message-indent-citation-function 'message-indent-citation
1081 "*Function for modifying a citation just inserted in the mail buffer.
1082 This can also be a list of functions. Each function can find the
1083 citation between (point) and (mark t). And each function should leave
1084 point and mark around the citation text as modified."
1086 :link '(custom-manual "(message)Insertion Variables")
1087 :group 'message-insertion)
1089 (defcustom message-signature t
1090 ;; In Emacs 24.1 this defaults to the value of `mail-signature' that
1092 ;; `nil' in Emacs 22.1~23.1, XEmacs 21.4, 21.5, and SXEmacs 22.1;
1093 ;; `t' in Emacs 23.2, and 24.1
1094 "*String to be inserted at the end of the message buffer.
1095 If t, the `message-signature-file' file will be inserted instead.
1096 If a function, the result from the function will be used instead.
1097 If a form, the result from the form will be used instead."
1100 :link '(custom-manual "(message)Insertion Variables")
1101 :group 'message-insertion)
1103 (defcustom message-signature-file "~/.signature"
1104 ;; In Emacs 24.1 this defaults to the value of `mail-signature-file'
1105 ;; that defaults to "~/.signature" in Emacs 22.1~24.1, and SXEmacs
1106 ;; 22.1. In XEmacs 21.4 and 21.5, sendmail.el provides it;
1107 ;; the defalut value is "~/.signature".
1108 "*Name of file containing the text inserted at end of message buffer.
1109 Ignored if the named file doesn't exist.
1110 If nil, don't insert a signature.
1111 If a path is specified, the value of `message-signature-directory' is ignored,
1114 :type '(choice file (const :tags "None" nil))
1115 :link '(custom-manual "(message)Insertion Variables")
1116 :group 'message-insertion)
1118 (defcustom message-signature-directory nil
1119 "*Name of directory containing signature files.
1120 Comes in handy if you have many such files, handled via posting styles for
1122 If nil, `message-signature-file' is expected to specify the directory if
1124 :type '(choice string (const :tags "None" nil))
1125 :link '(custom-manual "(message)Insertion Variables")
1126 :group 'message-insertion)
1128 (defcustom message-signature-insert-empty-line t
1129 "*If non-nil, insert an empty line before the signature separator."
1132 :link '(custom-manual "(message)Insertion Variables")
1133 :group 'message-insertion)
1135 (defcustom message-distribution-function nil
1136 "*Function called to return a Distribution header."
1137 :group 'message-news
1138 :group 'message-headers
1139 :link '(custom-manual "(message)News Headers")
1140 :type '(choice function (const nil)))
1142 (defcustom message-expires 14
1143 "Number of days before your article expires."
1144 :group 'message-news
1145 :group 'message-headers
1146 :link '(custom-manual "(message)News Headers")
1149 (defcustom message-user-path nil
1150 "If nil, use the NNTP server name in the Path header.
1151 If stringp, use this; if non-nil, use no host name (user name only)."
1152 :group 'message-news
1153 :group 'message-headers
1154 :link '(custom-manual "(message)News Headers")
1155 :type '(choice (const :tag "nntp" nil)
1156 (string :tag "name")
1157 (sexp :tag "none" :format "%t" t)))
1159 ;; This can be the name of a buffer, or a cons cell (FUNCTION . ARGS)
1160 ;; for yanking the original buffer.
1161 (defvar message-reply-buffer nil)
1162 (defvar message-reply-headers nil
1163 "The headers of the current replied article.
1164 It is a vector of the following headers:
1165 \[number subject from date id references chars lines xref extra].")
1166 (defvar message-newsreader nil)
1167 (defvar message-mailer nil)
1168 (defvar message-sent-message-via nil)
1169 (defvar message-checksum nil)
1170 (defvar message-send-actions nil
1171 "A list of actions to be performed upon successful sending of a message.")
1172 (defvar message-return-action nil
1173 "Action to return to the caller after sending or postphoning a message.")
1174 (defvar message-exit-actions nil
1175 "A list of actions to be performed upon exiting after sending a message.")
1176 (defvar message-kill-actions nil
1177 "A list of actions to be performed before killing a message buffer.")
1178 (defvar message-postpone-actions nil
1179 "A list of actions to be performed after postponing a message.")
1181 (define-widget 'message-header-lines 'text
1182 "All header lines must be LFD terminated."
1183 :format "%{%t%}:%n%v"
1184 :valid-regexp "^\\'"
1185 :error "All header lines must be newline terminated")
1187 (defcustom message-default-headers ""
1188 "Header lines to be inserted in outgoing messages.
1189 This can be set to a string containing or a function returning
1190 header lines to be inserted before you edit the message, so you
1191 can edit or delete these lines. If set to a function, it is
1192 called and its result is inserted."
1194 :group 'message-headers
1195 :link '(custom-manual "(message)Message Headers")
1197 (message-header-lines :tag "String")
1198 (function :tag "Function")))
1200 (defcustom message-default-mail-headers
1201 ;; Ease the transition from mail-mode to message-mode. See bugs#4431, 5555.
1202 (concat (if (and (boundp 'mail-default-reply-to)
1203 (stringp mail-default-reply-to))
1204 (format "Reply-to: %s\n" mail-default-reply-to))
1205 (if (and (boundp 'mail-self-blind)
1207 (format "BCC: %s\n" user-mail-address))
1208 (if (and (boundp 'mail-archive-file-name)
1209 (stringp mail-archive-file-name))
1210 (format "FCC: %s\n" mail-archive-file-name))
1211 ;; Use the value of `mail-default-headers' if available.
1212 ;; Note: as for XEmacs 21.4 and 21.5, it is unavailable
1213 ;; unless sendmail.el is loaded.
1214 (if (boundp 'mail-default-headers)
1215 mail-default-headers))
1216 "*A string of header lines to be inserted in outgoing mails."
1218 :group 'message-headers
1219 :group 'message-mail
1220 :link '(custom-manual "(message)Mail Headers")
1221 :type 'message-header-lines)
1223 (defcustom message-default-news-headers ""
1224 "*A string of header lines to be inserted in outgoing news articles."
1225 :group 'message-headers
1226 :group 'message-news
1227 :link '(custom-manual "(message)News Headers")
1228 :type 'message-header-lines)
1230 ;; Note: could use /usr/ucb/mail instead of sendmail;
1231 ;; options -t, and -v if not interactive.
1232 (defcustom message-mailer-swallows-blank-line
1233 (if (and (string-match "sparc-sun-sunos\\(\\'\\|[^5]\\)"
1234 system-configuration)
1235 (file-readable-p "/etc/sendmail.cf")
1237 (insert-file-contents "/etc/sendmail.cf")
1238 (goto-char (point-min))
1239 (let ((case-fold-search nil))
1240 (re-search-forward "^OR\\>" nil t))))
1241 ;; According to RFC822, "The field-name must be composed of printable
1242 ;; ASCII characters (i. e., characters that have decimal values between
1243 ;; 33 and 126, except colon)", i. e., any chars except ctl chars,
1245 '(looking-at "[ \t]\\|[][!\"#$%&'()*+,-./0-9;<=>?@A-Z\\\\^_`a-z{|}~]+:"))
1246 "*Set this non-nil if the system's mailer runs the header and body together.
1247 \(This problem exists on Sunos 4 when sendmail is run in remote mode.)
1248 The value should be an expression to test whether the problem will
1250 :group 'message-sending
1251 :link '(custom-manual "(message)Mail Variables")
1255 (define-mail-user-agent 'message-user-agent
1256 'message-mail 'message-send-and-exit
1257 'message-kill-buffer 'message-send-hook)
1259 (defvar message-mh-deletable-headers '(Message-ID Date Lines Sender)
1260 "If non-nil, delete the deletable headers before feeding to mh.")
1262 (defvar message-send-method-alist
1263 '((news message-news-p message-send-via-news)
1264 (mail message-mail-p message-send-via-mail))
1265 "Alist of ways to send outgoing messages.
1266 Each element has the form
1268 \(TYPE PREDICATE FUNCTION)
1270 where TYPE is a symbol that names the method; PREDICATE is a function
1271 called without any parameters to determine whether the message is
1272 a message of type TYPE; and FUNCTION is a function to be called if
1273 PREDICATE returns non-nil. FUNCTION is called with one parameter --
1276 (defcustom message-mail-alias-type 'abbrev
1277 "*What alias expansion type to use in Message buffers.
1278 The default is `abbrev', which uses mailabbrev. `ecomplete' uses
1279 an electric completion mode. nil switches mail aliases off.
1280 This can also be a list of values."
1282 :link '(custom-manual "(message)Mail Aliases")
1283 :type '(choice (const :tag "Use Mailabbrev" abbrev)
1284 (const :tag "Use ecomplete" ecomplete)
1285 (const :tag "No expansion" nil)))
1287 (defcustom message-self-insert-commands '(self-insert-command)
1288 "List of `self-insert-command's used to trigger ecomplete.
1289 When one of those commands is invoked to enter a character in To or Cc
1290 header, ecomplete will suggest the candidates of recipients (see also
1291 `message-mail-alias-type'). If you use some tool to enter non-ASCII
1292 text and it replaces `self-insert-command' with the other command, e.g.
1293 `egg-self-insert-command', you may want to add it to this list."
1294 :group 'message-various
1295 :type '(repeat function))
1297 (defcustom message-auto-save-directory
1298 (file-name-as-directory (expand-file-name "drafts" message-directory))
1299 "*Directory where Message auto-saves buffers if Gnus isn't running.
1300 If nil, Message won't auto-save."
1301 :group 'message-buffers
1302 :link '(custom-manual "(message)Various Message Variables")
1303 :type '(choice directory (const :tag "Don't auto-save" nil)))
1305 (defcustom message-default-charset
1306 (and (not (mm-multibyte-p)) 'iso-8859-1)
1307 "Default charset used in non-MULE Emacsen.
1308 If nil, you might be asked to input the charset."
1311 :link '(custom-manual "(message)Various Message Variables")
1314 (defcustom message-dont-reply-to-names
1315 (and (boundp 'rmail-dont-reply-to-names) rmail-dont-reply-to-names)
1316 "*Addresses to prune when doing wide replies.
1317 This can be a regexp or a list of regexps. Also, a value of nil means
1318 exclude your own user name only."
1321 :link '(custom-manual "(message)Wide Reply")
1322 :type '(choice (const :tag "Yourself" nil)
1324 (repeat :tag "Regexp List" regexp)))
1326 (defsubst message-dont-reply-to-names ()
1327 (gmm-regexp-concat message-dont-reply-to-names))
1329 (defvar message-shoot-gnksa-feet nil
1330 "*A list of GNKSA feet you are allowed to shoot.
1331 Gnus gives you all the opportunity you could possibly want for
1332 shooting yourself in the foot. Also, Gnus allows you to shoot the
1333 feet of Good Net-Keeping Seal of Approval. The following are foot
1335 `empty-article' Allow you to post an empty article;
1336 `quoted-text-only' Allow you to post quoted text only;
1337 `multiple-copies' Allow you to post multiple copies;
1338 `cancel-messages' Allow you to cancel or supersede messages from
1339 your other email addresses.")
1341 (defsubst message-gnksa-enable-p (feature)
1342 (or (not (listp message-shoot-gnksa-feet))
1343 (memq feature message-shoot-gnksa-feet)))
1345 (defcustom message-hidden-headers '("^References:" "^Face:" "^X-Face:"
1347 "Regexp of headers to be hidden when composing new messages.
1348 This can also be a list of regexps to match headers. Or a list
1349 starting with `not' and followed by regexps."
1352 :link '(custom-manual "(message)Message Headers")
1354 :format "%{%t%}: %[Value Type%] %v"
1355 (regexp :menu-tag "regexp" :format "regexp\n%t: %v")
1356 (repeat :menu-tag "(regexp ...)" :format "(regexp ...)\n%v%i"
1357 (regexp :format "%t: %v"))
1358 (cons :menu-tag "(not regexp ...)" :format "(not regexp ...)\n%v"
1360 (repeat :format "%v%i"
1361 (regexp :format "%t: %v")))))
1363 (defcustom message-cite-articles-with-x-no-archive t
1364 "If non-nil, cite text from articles that has X-No-Archive set."
1368 ;;; Internal variables.
1369 ;;; Well, not really internal.
1371 (defvar message-mode-syntax-table
1372 (let ((table (copy-syntax-table text-mode-syntax-table)))
1373 (modify-syntax-entry ?% ". " table)
1374 (modify-syntax-entry ?> ". " table)
1375 (modify-syntax-entry ?< ". " table)
1377 "Syntax table used while in Message mode.")
1379 (defface message-header-to
1382 (:foreground "DarkOliveGreen1" :bold t))
1385 (:foreground "MidnightBlue" :bold t))
1387 (:bold t :italic t)))
1388 "Face used for displaying From headers."
1389 :group 'message-faces)
1390 ;; backward-compatibility alias
1391 (put 'message-header-to-face 'face-alias 'message-header-to)
1392 (put 'message-header-to-face 'obsolete-face "22.1")
1394 (defface message-header-cc
1397 (:foreground "chartreuse1" :bold t))
1400 (:foreground "MidnightBlue"))
1403 "Face used for displaying Cc headers."
1404 :group 'message-faces)
1405 ;; backward-compatibility alias
1406 (put 'message-header-cc-face 'face-alias 'message-header-cc)
1407 (put 'message-header-cc-face 'obsolete-face "22.1")
1409 (defface message-header-subject
1412 (:foreground "OliveDrab1"))
1415 (:foreground "navy blue" :bold t))
1418 "Face used for displaying subject headers."
1419 :group 'message-faces)
1420 ;; backward-compatibility alias
1421 (put 'message-header-subject-face 'face-alias 'message-header-subject)
1422 (put 'message-header-subject-face 'obsolete-face "22.1")
1424 (defface message-header-newsgroups
1427 (:foreground "yellow" :bold t :italic t))
1430 (:foreground "blue4" :bold t :italic t))
1432 (:bold t :italic t)))
1433 "Face used for displaying newsgroups headers."
1434 :group 'message-faces)
1435 ;; backward-compatibility alias
1436 (put 'message-header-newsgroups-face 'face-alias 'message-header-newsgroups)
1437 (put 'message-header-newsgroups-face 'obsolete-face "22.1")
1439 (defface message-header-other
1442 (:foreground "VioletRed1"))
1445 (:foreground "steel blue"))
1447 (:bold t :italic t)))
1448 "Face used for displaying newsgroups headers."
1449 :group 'message-faces)
1450 ;; backward-compatibility alias
1451 (put 'message-header-other-face 'face-alias 'message-header-other)
1452 (put 'message-header-other-face 'obsolete-face "22.1")
1454 (defface message-header-name
1457 (:foreground "green"))
1460 (:foreground "cornflower blue"))
1463 "Face used for displaying header names."
1464 :group 'message-faces)
1465 ;; backward-compatibility alias
1466 (put 'message-header-name-face 'face-alias 'message-header-name)
1467 (put 'message-header-name-face 'obsolete-face "22.1")
1469 (defface message-header-xheader
1472 (:foreground "DeepSkyBlue1"))
1475 (:foreground "blue"))
1478 "Face used for displaying X-Header headers."
1479 :group 'message-faces)
1480 ;; backward-compatibility alias
1481 (put 'message-header-xheader-face 'face-alias 'message-header-xheader)
1482 (put 'message-header-xheader-face 'obsolete-face "22.1")
1484 (defface message-separator
1487 (:foreground "LightSkyBlue1"))
1490 (:foreground "brown"))
1493 "Face used for displaying the separator."
1494 :group 'message-faces)
1495 ;; backward-compatibility alias
1496 (put 'message-separator-face 'face-alias 'message-separator)
1497 (put 'message-separator-face 'obsolete-face "22.1")
1499 (defface message-cited-text
1502 (:foreground "LightPink1"))
1505 (:foreground "red"))
1508 "Face used for displaying cited text names."
1509 :group 'message-faces)
1510 ;; backward-compatibility alias
1511 (put 'message-cited-text-face 'face-alias 'message-cited-text)
1512 (put 'message-cited-text-face 'obsolete-face "22.1")
1514 (defface message-mml
1517 (:foreground "MediumSpringGreen"))
1520 (:foreground "ForestGreen"))
1523 "Face used for displaying MML."
1524 :group 'message-faces)
1525 ;; backward-compatibility alias
1526 (put 'message-mml-face 'face-alias 'message-mml)
1527 (put 'message-mml-face 'obsolete-face "22.1")
1529 (defun message-font-lock-make-header-matcher (regexp)
1532 (let ((start (point)))
1535 (goto-char (point-min))
1536 (if (re-search-forward
1537 (concat "^" (regexp-quote mail-header-separator) "$")
1539 (setq limit (min limit (match-beginning 0))))
1541 (and (< start limit)
1542 (re-search-forward ,regexp limit t))))))
1543 (if (featurep 'bytecomp)
1547 (defvar message-font-lock-keywords
1548 (let ((content "[ \t]*\\(.+\\(\n[ \t].*\\)*\\)\n?"))
1549 `((,(message-font-lock-make-header-matcher
1550 (concat "^\\([Tt]o:\\)" content))
1551 (1 'message-header-name)
1552 (2 'message-header-to nil t))
1553 (,(message-font-lock-make-header-matcher
1554 (concat "^\\(^[GBF]?[Cc][Cc]:\\|^[Rr]eply-[Tt]o:\\)" content))
1555 (1 'message-header-name)
1556 (2 'message-header-cc nil t))
1557 (,(message-font-lock-make-header-matcher
1558 (concat "^\\([Ss]ubject:\\)" content))
1559 (1 'message-header-name)
1560 (2 'message-header-subject nil t))
1561 (,(message-font-lock-make-header-matcher
1562 (concat "^\\([Nn]ewsgroups:\\|Followup-[Tt]o:\\)" content))
1563 (1 'message-header-name)
1564 (2 'message-header-newsgroups nil t))
1565 (,(message-font-lock-make-header-matcher
1566 (concat "^\\(X-[A-Za-z0-9-]+:\\|In-Reply-To:\\)" content))
1567 (1 'message-header-name)
1568 (2 'message-header-xheader))
1569 (,(message-font-lock-make-header-matcher
1570 (concat "^\\([A-Z][^: \n\t]+:\\)" content))
1571 (1 'message-header-name)
1572 (2 'message-header-other nil t))
1573 ,@(if (and mail-header-separator
1574 (not (equal mail-header-separator "")))
1575 `((,(concat "^\\(" (regexp-quote mail-header-separator) "\\)$")
1576 1 'message-separator))
1579 (re-search-forward (concat "^\\("
1580 message-cite-prefix-regexp
1583 (0 'message-cited-text))
1584 ("<#/?\\(multipart\\|part\\|external\\|mml\\|secure\\)[^>]*>"
1586 "Additional expressions to highlight in Message mode.")
1589 ;; XEmacs does it like this. For Emacs, we have to set the
1590 ;; `font-lock-defaults' buffer-local variable.
1591 (put 'message-mode 'font-lock-defaults '(message-font-lock-keywords t))
1593 (defvar message-face-alist
1594 '((bold . message-bold-region)
1595 (underline . underline-region)
1596 (default . (lambda (b e)
1597 (message-unbold-region b e)
1598 (ununderline-region b e))))
1599 "Alist of mail and news faces for facemenu.
1600 The cdr of each entry is a function for applying the face to a region.")
1602 (defcustom message-send-hook nil
1603 "Hook run before sending messages.
1604 This hook is run quite early when sending."
1605 :group 'message-various
1606 :options '(ispell-message)
1607 :link '(custom-manual "(message)Various Message Variables")
1610 (defcustom message-send-mail-hook nil
1611 "Hook run before sending mail messages.
1612 This hook is run very late -- just before the message is sent as
1614 :group 'message-various
1615 :link '(custom-manual "(message)Various Message Variables")
1618 (defcustom message-send-news-hook nil
1619 "Hook run before sending news messages.
1620 This hook is run very late -- just before the message is sent as
1622 :group 'message-various
1623 :link '(custom-manual "(message)Various Message Variables")
1626 (defcustom message-sent-hook nil
1627 "Hook run after sending messages."
1628 :group 'message-various
1631 (defvar message-send-coding-system 'binary
1632 "Coding system to encode outgoing mail.")
1634 (defvar message-draft-coding-system
1635 mm-auto-save-coding-system
1636 "*Coding system to compose mail.
1637 If you'd like to make it possible to share draft files between XEmacs
1638 and Emacs, you may use `iso-2022-7bit' for this value at your own risk.
1639 Note that the coding-system `iso-2022-7bit' isn't suitable to all data.")
1641 (defcustom message-send-mail-partially-limit nil
1642 "The limitation of messages sent as message/partial.
1643 The lower bound of message size in characters, beyond which the message
1644 should be sent in several parts. If it is nil, the size is unlimited."
1646 :group 'message-buffers
1647 :link '(custom-manual "(message)Mail Variables")
1648 :type '(choice (const :tag "unlimited" nil)
1651 (defcustom message-alternative-emails nil
1652 "*Regexp matching alternative email addresses.
1653 The first address in the To, Cc or From headers of the original
1654 article matching this variable is used as the From field of
1657 This variable has precedence over posting styles and anything that runs
1658 off `message-setup-hook'."
1659 :group 'message-headers
1660 :link '(custom-manual "(message)Message Headers")
1661 :type '(choice (const :tag "Always use primary" nil)
1664 (defcustom message-hierarchical-addresses nil
1665 "A list of hierarchical mail address definitions.
1667 Inside each entry, the first address is the \"top\" address, and
1668 subsequent addresses are subaddresses; this is used to indicate that
1669 mail sent to the first address will automatically be delivered to the
1670 subaddresses. So if the first address appears in the recipient list
1671 for a message, the subaddresses will be removed (if present) before
1672 the mail is sent. All addresses in this structure should be
1675 :group 'message-headers
1676 :type '(repeat (repeat string)))
1678 (defcustom message-mail-user-agent nil
1679 "Like `mail-user-agent'.
1680 Except if it is nil, use Gnus native MUA; if it is t, use
1683 :type '(radio (const :tag "Gnus native"
1686 (const :tag "`mail-user-agent'"
1689 (function-item :tag "Default Emacs mail"
1691 sendmail-user-agent)
1692 (function-item :tag "Emacs interface to MH"
1695 (function :tag "Other"))
1699 (defcustom message-wide-reply-confirm-recipients nil
1700 "Whether to confirm a wide reply to multiple email recipients.
1701 If this variable is nil, don't ask whether to reply to all recipients.
1702 If this variable is non-nil, pose the question \"Reply to all
1703 recipients?\" before a wide reply to multiple recipients. If the user
1704 answers yes, reply to all recipients as usual. If the user answers
1705 no, only reply back to the author."
1707 :group 'message-headers
1708 :link '(custom-manual "(message)Wide Reply")
1711 (defcustom message-user-fqdn nil
1712 "*Domain part of Message-Ids."
1714 :group 'message-headers
1715 :link '(custom-manual "(message)News Headers")
1716 :type '(radio (const :format "%v " nil)
1717 (string :format "FQDN: %v")))
1719 (defcustom message-use-idna (and (condition-case nil (require 'idna)
1721 (mm-coding-system-p 'utf-8)
1722 (executable-find idna-program)
1723 (string= (idna-to-ascii "räksmörgås")
1724 "xn--rksmrgs-5wao1o")
1726 "Whether to encode non-ASCII in domain names into ASCII according to IDNA.
1727 GNU Libidn, and in particular the elisp package \"idna.el\" and
1728 the external program \"idn\", must be installed for this
1729 functionality to work."
1731 :group 'message-headers
1732 :link '(custom-manual "(message)IDNA")
1733 :type '(choice (const :tag "Ask" ask)
1734 (const :tag "Never" nil)
1735 (const :tag "Always" t)))
1737 (defcustom message-generate-hashcash (if (executable-find "hashcash") 'opportunistic)
1738 "*Whether to generate X-Hashcash: headers.
1739 If t, always generate hashcash headers. If `opportunistic',
1740 only generate hashcash headers if it can be done without the user
1741 waiting (i.e., only asynchronously).
1743 You must have the \"hashcash\" binary installed, see `hashcash-path'."
1745 :group 'message-headers
1746 :link '(custom-manual "(message)Mail Headers")
1747 :type '(choice (const :tag "Always" t)
1748 (const :tag "Never" nil)
1749 (const :tag "Opportunistic" opportunistic)))
1751 ;;; Internal variables.
1753 (defvar message-sending-message "Sending...")
1754 (defvar message-buffer-list nil)
1755 (defvar message-this-is-news nil)
1756 (defvar message-this-is-mail nil)
1757 (defvar message-draft-article nil)
1758 (defvar message-mime-part nil)
1759 (defvar message-posting-charset nil)
1760 (defvar message-inserted-headers nil)
1761 (defvar message-inhibit-ecomplete nil)
1763 ;; Byte-compiler warning
1764 (defvar gnus-active-hashtb)
1765 (defvar gnus-read-active-file)
1767 ;;; Regexp matching the delimiter of messages in UNIX mail format
1768 ;;; (UNIX From lines), minus the initial ^. It should be a copy
1769 ;;; of rmail.el's rmail-unix-mail-delimiter.
1770 (defvar message-unix-mail-delimiter
1771 (let ((time-zone-regexp
1772 (concat "\\([A-Z]?[A-Z]?[A-Z][A-Z]\\( DST\\)?"
1773 "\\|[-+]?[0-9][0-9][0-9][0-9]"
1779 ;; Many things can happen to an RFC 822 mailbox before it is put into
1780 ;; a `From' line. The leading phrase can be stripped, e.g.
1781 ;; `Joe <@w.x:joe@y.z>' -> `<@w.x:joe@y.z>'. The <> can be stripped, e.g.
1782 ;; `<@x.y:joe@y.z>' -> `@x.y:joe@y.z'. Everything starting with a CRLF
1783 ;; can be removed, e.g.
1784 ;; From: joe@y.z (Joe K
1786 ;; can yield `From joe@y.z (Joe K Fri Mar 22 08:11:15 1996', and
1789 ;; can yield `From Joe User Fri Mar 22 08:11:15 1996'.
1790 ;; The mailbox can be removed or be replaced by white space, e.g.
1791 ;; From: "Joe User"{space}{tab}
1793 ;; can yield `From {space}{tab} Fri Mar 22 08:11:15 1996',
1794 ;; where {space} and {tab} represent the Ascii space and tab characters.
1795 ;; We want to match the results of any of these manglings.
1796 ;; The following regexp rejects names whose first characters are
1797 ;; obviously bogus, but after that anything goes.
1798 "\\([^\0-\b\n-\r\^?].*\\)?"
1800 ;; The time the message was sent.
1801 "\\([^\0-\r \^?]+\\) +" ; day of the week
1802 "\\([^\0-\r \^?]+\\) +" ; month
1803 "\\([0-3]?[0-9]\\) +" ; day of month
1804 "\\([0-2][0-9]:[0-5][0-9]\\(:[0-6][0-9]\\)?\\) *" ; time of day
1806 ;; Perhaps a time zone, specified by an abbreviation, or by a
1811 " \\([0-9][0-9]+\\) *"
1813 ;; On some systems the time zone can appear after the year, too.
1817 "\\(remote from .*\\)?"
1820 "Regexp matching the delimiter of messages in UNIX mail format.")
1822 (defvar message-unsent-separator
1823 (concat "^ *---+ +Unsent message follows +---+ *$\\|"
1824 "^ *---+ +Returned message +---+ *$\\|"
1825 "^Start of returned message$\\|"
1826 "^ *---+ +Original message +---+ *$\\|"
1827 "^ *--+ +begin message +--+ *$\\|"
1828 "^ *---+ +Original message follows +---+ *$\\|"
1829 "^ *---+ +Undelivered message follows +---+ *$\\|"
1830 "^------ This is a copy of the message, including all the headers. ------ *$\\|"
1831 "^|? *---+ +Message text follows: +---+ *|?$")
1832 "A regexp that matches the separator before the text of a failed message.")
1834 (defvar message-field-fillers
1835 '((To message-fill-field-address)
1836 (Cc message-fill-field-address)
1837 (From message-fill-field-address))
1838 "Alist of header names/filler functions.")
1840 (defvar message-header-format-alist
1855 (References . message-shorten-references)
1857 "Alist used for formatting headers.")
1859 (defvar message-options nil
1860 "Some saved answers when sending message.")
1861 (make-variable-buffer-local 'message-options)
1863 (defvar message-send-mail-real-function nil
1864 "Internal send mail function.")
1866 (defvar message-bogus-system-names "^localhost\\.\\|\\.local$"
1867 "The regexp of bogus system names.")
1869 (defcustom message-valid-fqdn-regexp
1870 (concat "[a-z0-9][-.a-z0-9]+\\." ;; [hostname.subdomain.]domain.
1872 "\\([a-z][a-z]\\|" ;; two letter country TDLs
1873 "aero\\|arpa\\|bitnet\\|biz\\|bofh\\|"
1874 "cat\\|com\\|coop\\|edu\\|gov\\|"
1875 "info\\|int\\|jobs\\|"
1876 "mil\\|mobi\\|museum\\|name\\|net\\|"
1877 "org\\|pro\\|travel\\|uucp\\)")
1878 ;; http://en.wikipedia.org/wiki/List_of_Internet_top-level_domains
1879 ;; http://en.wikipedia.org/wiki/GTLD
1880 ;; `in the process of being approved': .asia .post .tel .sex
1881 ;; "dead" nato bitnet uucp
1882 "Regular expression that matches a valid FQDN."
1883 ;; see also: gnus-button-valid-fqdn-regexp
1885 :group 'message-headers
1888 (autoload 'gnus-alive-p "gnus-util")
1889 (autoload 'gnus-delay-article "gnus-delay")
1890 (autoload 'gnus-extract-address-components "gnus-util")
1891 (autoload 'gnus-find-method-for-group "gnus")
1892 (autoload 'gnus-group-decoded-name "gnus-group")
1893 (autoload 'gnus-group-name-charset "gnus-group")
1894 (autoload 'gnus-group-name-decode "gnus-group")
1895 (autoload 'gnus-groups-from-server "gnus")
1896 (autoload 'gnus-make-local-hook "gnus-util")
1897 (autoload 'gnus-open-server "gnus-int")
1898 (autoload 'gnus-output-to-mail "gnus-util")
1899 (autoload 'gnus-output-to-rmail "gnus-util")
1900 (autoload 'gnus-request-post "gnus-int")
1901 (autoload 'gnus-select-frame-set-input-focus "gnus-util")
1902 (autoload 'gnus-server-string "gnus")
1903 (autoload 'idna-to-ascii "idna")
1904 (autoload 'message-setup-toolbar "messagexmas")
1905 (autoload 'mh-new-draft-name "mh-comp")
1906 (autoload 'mh-send-letter "mh-comp")
1907 (autoload 'nndraft-request-associate-buffer "nndraft")
1908 (autoload 'nndraft-request-expire-articles "nndraft")
1909 (autoload 'nnvirtual-find-group-art "nnvirtual")
1910 (autoload 'rmail-dont-reply-to "mail-utils")
1911 (autoload 'rmail-msg-is-pruned "rmail")
1912 (autoload 'rmail-output "rmailout")
1917 ;;; Utility functions.
1920 (defmacro message-y-or-n-p (question show &rest text)
1921 "Ask QUESTION, displaying remaining args in a temporary buffer if SHOW."
1922 `(message-talkative-question 'y-or-n-p ,question ,show ,@text))
1924 (defmacro message-delete-line (&optional n)
1925 "Delete the current line (and the next N lines)."
1926 `(delete-region (progn (beginning-of-line) (point))
1927 (progn (forward-line ,(or n 1)) (point))))
1929 (defun message-mark-active-p ()
1930 "Non-nil means the mark and region are currently active in this buffer."
1933 (defun message-unquote-tokens (elems)
1934 "Remove double quotes (\") from strings in list ELEMS."
1935 (mapcar (lambda (item)
1936 (while (string-match "^\\(.*\\)\"\\(.*\\)$" item)
1937 (setq item (concat (match-string 1 item)
1938 (match-string 2 item))))
1942 (defun message-tokenize-header (header &optional separator)
1943 "Split HEADER into a list of header elements.
1944 SEPARATOR is a string of characters to be used as separators. \",\"
1945 is used by default."
1948 (let ((regexp (format "[%s]+" (or separator ",")))
1950 beg quoted elems paren)
1952 (mm-enable-multibyte)
1953 (setq beg (point-min))
1955 (goto-char (point-min))
1960 (cond ((and (> (point) beg)
1962 (and (looking-at regexp)
1965 (push (buffer-substring beg (point)) elems)
1966 (setq beg (match-end 0)))
1967 ((eq (char-after) ?\")
1968 (setq quoted (not quoted)))
1969 ((and (eq (char-after) ?\()
1972 ((and (eq (char-after) ?\))
1975 (nreverse elems)))))
1977 (autoload 'nnheader-insert-file-contents "nnheader")
1979 (defun message-mail-file-mbox-p (file)
1980 "Say whether FILE looks like a Unix mbox file."
1981 (when (and (file-exists-p file)
1982 (file-readable-p file)
1983 (file-regular-p file))
1985 (nnheader-insert-file-contents file)
1986 (goto-char (point-min))
1987 (looking-at message-unix-mail-delimiter))))
1989 (defun message-fetch-field (header &optional not-all)
1990 "The same as `mail-fetch-field', only remove all newlines.
1991 The buffer is expected to be narrowed to just the header of the message;
1992 see `message-narrow-to-headers-or-head'."
1993 (let* ((inhibit-point-motion-hooks t)
1994 (value (mail-fetch-field header nil (not not-all))))
1996 (while (string-match "\n[\t ]+" value)
1997 (setq value (replace-match " " t t value)))
2000 (defun message-field-value (header &optional not-all)
2001 "The same as `message-fetch-field', only narrow to the headers first."
2004 (message-narrow-to-headers-or-head)
2005 (message-fetch-field header not-all))))
2007 (defun message-narrow-to-field ()
2008 "Narrow the buffer to the header on the current line."
2010 (while (looking-at "[ \t]")
2016 (if (re-search-forward "^[^ \n\t]" nil t)
2019 (goto-char (point-min)))
2021 (defun message-add-header (&rest headers)
2022 "Add the HEADERS to the message header, skipping those already present."
2025 (unless (string-match "^\\([^:]+\\):[ \t]*[^ \t]" (car headers))
2026 (error "Invalid header `%s'" (car headers)))
2027 (setq hclean (match-string 1 (car headers)))
2029 (message-narrow-to-headers)
2030 (unless (re-search-forward (concat "^" (regexp-quote hclean) ":") nil t)
2031 (goto-char (point-max))
2032 (if (string-match "\n$" (car headers))
2033 (insert (car headers))
2034 (insert (car headers) ?\n)))))
2035 (setq headers (cdr headers))))
2037 (defmacro message-with-reply-buffer (&rest forms)
2038 "Evaluate FORMS in the reply buffer, if it exists."
2039 `(when (and (bufferp message-reply-buffer)
2040 (buffer-name message-reply-buffer))
2041 (with-current-buffer message-reply-buffer
2044 (put 'message-with-reply-buffer 'lisp-indent-function 0)
2045 (put 'message-with-reply-buffer 'edebug-form-spec '(body))
2047 (defun message-fetch-reply-field (header)
2048 "Fetch field HEADER from the message we're replying to."
2049 (message-with-reply-buffer
2051 (mail-narrow-to-head)
2052 (message-fetch-field header))))
2054 (defun message-strip-list-identifiers (subject)
2055 "Remove list identifiers in `gnus-list-identifiers' from string SUBJECT."
2056 (require 'gnus-sum) ; for gnus-list-identifiers
2057 (let ((regexp (if (stringp gnus-list-identifiers)
2058 gnus-list-identifiers
2059 (mapconcat 'identity gnus-list-identifiers " *\\|"))))
2060 (if (string-match (concat "\\(\\(\\(Re: +\\)?\\(" regexp
2061 " *\\)\\)+\\(Re: +\\)?\\)") subject)
2062 (concat (substring subject 0 (match-beginning 1))
2063 (or (match-string 3 subject)
2064 (match-string 5 subject))
2069 (defun message-strip-subject-re (subject)
2070 "Remove \"Re:\" from subject lines in string SUBJECT."
2071 (if (string-match message-subject-re-regexp subject)
2072 (substring subject (match-end 0))
2075 (defcustom message-replacement-char "."
2076 "Replacement character used instead of unprintable or not decodable chars."
2077 :group 'message-various
2078 :version "22.1" ;; Gnus 5.10.9
2079 :type '(choice string
2083 ;; FIXME: We also should call `message-strip-subject-encoded-words'
2084 ;; when forwarding. Probably in `message-make-forward-subject' and
2085 ;; `message-forward-make-body'.
2087 (defun message-strip-subject-encoded-words (subject)
2088 "Fix non-decodable words in SUBJECT."
2089 ;; Cf. `gnus-simplify-subject-fully'.
2090 (let* ((case-fold-search t)
2091 (replacement-chars (format "[%s%s%s]"
2092 message-replacement-char
2093 message-replacement-char
2094 message-replacement-char))
2095 (enc-word-re "=\\?\\([^?]+\\)\\?\\([QB]\\)\\?\\([^?]+\\)\\(\\?=\\)")
2100 (goto-char (point-min))
2101 (when (re-search-forward enc-word-re nil t)
2102 (setq cs-string (match-string 1)))))
2103 cs-coding q-or-b word-beg word-end)
2104 (if (or (not have-marker) ;; No encoded word found...
2105 ;; ... or double encoding was correct:
2106 (and (stringp cs-string)
2107 (setq cs-string (downcase cs-string))
2108 (mm-coding-system-p (intern cs-string))
2112 Decoded Subject \"%s\"
2113 contains a valid encoded word. Decode again? "
2115 (setq cs-coding (intern cs-string))))))
2119 (goto-char (point-min))
2120 (while (re-search-forward enc-word-re nil t)
2121 (setq cs-string (downcase (match-string 1))
2122 q-or-b (match-string 2)
2123 word-beg (match-beginning 0)
2124 word-end (match-end 0))
2126 (if (mm-coding-system-p (intern cs-string))
2127 (setq cs-coding (intern cs-string))
2129 ;; No double encoded subject? => bogus charset.
2132 (mm-read-coding-system
2134 Decoded Subject \"%s\"
2135 contains an encoded word. The charset `%s' is unknown or invalid.
2136 Hit RET to replace non-decodable characters with \"%s\" or enter replacement
2138 subject cs-string message-replacement-char)))
2140 (replace-match (concat "=?" (symbol-name cs-coding)
2143 (goto-char word-beg)
2144 (re-search-forward "=\\?\\([^?]+\\)\\?\\([QB]\\)\\?" word-end t)
2147 (if (string-match "\\`Q\\'" q-or-b)
2150 (message "Replacing non-decodable characters with \"%s\"."
2151 message-replacement-char)
2152 (while (re-search-forward "\\(=[A-F0-9][A-F0-9]\\)+"
2154 (replace-match message-replacement-char)))
2156 (message "Replacing non-decodable characters with \"%s\"."
2158 (re-search-forward "[^?]+" word-end t)
2159 (replace-match replacement-chars))
2160 (re-search-forward "\\?=")
2161 (replace-match "")))))
2162 (rfc2047-decode-region (point-min) (point-max))
2165 ;;; Start of functions adopted from `message-utils.el'.
2167 (defun message-strip-subject-trailing-was (subject)
2168 "Remove trailing \"(was: <old subject>)\" from SUBJECT lines.
2169 Leading \"Re: \" is not stripped by this function. Use the function
2170 `message-strip-subject-re' for this."
2171 (let* ((query message-subject-trailing-was-query)
2176 message-subject-trailing-was-ask-regexp
2177 message-subject-trailing-was-regexp)
2180 (setq new (substring subject 0 (match-beginning 0))))
2181 (if (or (not found) (eq query nil))
2184 (if (message-y-or-n-p
2185 "Strip `(was: <old subject>)' in subject? " t
2187 "Strip `(was: <old subject>)' in subject "
2188 "and use the new one instead?\n\n"
2189 "Current subject is: \""
2191 "New subject would be: \""
2193 "See the variable `message-subject-trailing-was-query' "
2194 "to get rid of this query."
2199 ;;; Suggested by Jonas Steverud @ www.dtek.chalmers.se/~d4jonas/
2201 (defun message-change-subject (new-subject)
2202 "Ask for NEW-SUBJECT header, append (was: <Old Subject>)."
2205 (read-from-minibuffer "New subject: ")))
2206 (cond ((and (not (or (null new-subject) ; new subject not empty
2207 (zerop (string-width new-subject))
2208 (string-match "^[ \t]*$" new-subject))))
2212 (message-narrow-to-headers)
2213 (message-fetch-field "Subject"))))
2214 (cond ((not old-subject)
2215 (error "No current subject"))
2218 (regexp-quote new-subject)
2220 old-subject)) ; yes, it really is a new subject
2221 ;; delete eventual Re: prefix
2223 (message-strip-subject-re old-subject))
2224 (message-goto-subject)
2225 (message-delete-line)
2226 (insert (concat "Subject: "
2229 old-subject ")\n")))))))))
2231 (defun message-mark-inserted-region (beg end &optional verbatim)
2232 "Mark some region in the current article with enclosing tags.
2233 See `message-mark-insert-begin' and `message-mark-insert-end'.
2234 If VERBATIM, use slrn style verbatim marks (\"#v+\" and \"#v-\")."
2235 (interactive "r\nP")
2237 ;; add to the end of the region first, otherwise end would be invalid
2239 (insert (if verbatim "#v-\n" message-mark-insert-end))
2241 (insert (if verbatim "#v+\n" message-mark-insert-begin))))
2243 (defun message-mark-insert-file (file &optional verbatim)
2244 "Insert FILE at point, marking it with enclosing tags.
2245 See `message-mark-insert-begin' and `message-mark-insert-end'.
2246 If VERBATIM, use slrn style verbatim marks (\"#v+\" and \"#v-\")."
2247 (interactive "fFile to insert: \nP")
2248 ;; reverse insertion to get correct result.
2250 (insert (if verbatim "#v-\n" message-mark-insert-end))
2252 (insert-file-contents file)
2254 (insert (if verbatim "#v+\n" message-mark-insert-begin))))
2256 (defun message-add-archive-header ()
2257 "Insert \"X-No-Archive: Yes\" in the header and a note in the body.
2258 The note can be customized using `message-archive-note'. When called with a
2259 prefix argument, ask for a text to insert. If you don't want the note in the
2260 body, set `message-archive-note' to nil."
2262 (if current-prefix-arg
2263 (setq message-archive-note
2264 (read-from-minibuffer "Reason for No-Archive: "
2265 (cons message-archive-note 0))))
2267 (if (message-goto-signature)
2268 (re-search-backward message-signature-separator))
2269 (when message-archive-note
2270 (insert message-archive-note)
2272 (message-add-header message-archive-header)
2273 (message-sort-headers)))
2275 (defun message-cross-post-followup-to-header (target-group)
2276 "Mangles FollowUp-To and Newsgroups header to point to TARGET-GROUP.
2277 With prefix-argument just set Follow-Up, don't cross-post."
2279 (list ; Completion based on Gnus
2280 (completing-read "Followup To: "
2281 (if (boundp 'gnus-newsrc-alist)
2283 nil nil '("poster" . 0)
2284 (if (boundp 'gnus-group-history)
2285 'gnus-group-history))))
2286 (message-remove-header "Follow[Uu]p-[Tt]o" t)
2287 (message-goto-newsgroups)
2289 ;; if we already did a crosspost before, kill old target
2290 (if (and message-cross-post-old-target
2292 (regexp-quote (concat "," message-cross-post-old-target))
2295 ;; unless (followup is to poster or user explicitly asked not
2296 ;; to cross-post, or target-group is already in Newsgroups)
2297 ;; add target-group to Newsgroups line.
2299 ;; def: cross-post, req:no
2300 (and message-cross-post-default (not current-prefix-arg))
2301 ;; def: no-cross-post, req:yes
2302 (and (not message-cross-post-default) current-prefix-arg))
2303 (not (string-match "poster" target-group))
2304 (not (string-match (regexp-quote target-group)
2305 (message-fetch-field "Newsgroups"))))
2307 (insert (concat "," target-group))))
2308 (end-of-line) ; ensure Followup: comes after Newsgroups:
2309 ;; unless new followup would be identical to Newsgroups line
2310 ;; make a new Followup-To line
2311 (if (not (string-match (concat "^[ \t]*"
2314 (message-fetch-field "Newsgroups")))
2315 (insert (concat "\nFollowup-To: " target-group)))
2316 (setq message-cross-post-old-target target-group))
2318 (defun message-cross-post-insert-note (target-group cross-post in-old
2320 "Insert a in message body note about a set Followup or Crosspost.
2321 If there have been previous notes, delete them. TARGET-GROUP specifies the
2322 group to Followup-To. When CROSS-POST is t, insert note about
2323 crossposting. IN-OLD specifies whether TARGET-GROUP is a member of
2324 OLD-GROUPS. OLD-GROUPS lists the old-groups the posting would have
2325 been made to before the user asked for a Crosspost."
2326 ;; start scanning body for previous uses
2327 (message-goto-signature)
2328 (let ((head (re-search-backward
2329 (concat "^" mail-header-separator)
2330 nil t))) ; just search in body
2331 (message-goto-signature)
2332 (while (re-search-backward
2333 (concat "^" (regexp-quote message-cross-post-note) ".*")
2335 (message-delete-line))
2336 (message-goto-signature)
2337 (while (re-search-backward
2338 (concat "^" (regexp-quote message-followup-to-note) ".*")
2340 (message-delete-line))
2342 (if (message-goto-signature)
2343 (re-search-backward message-signature-separator))
2346 (string-match "^[ \t]*poster[ \t]*$" target-group))
2347 (insert (concat message-followup-to-note target-group "\n"))
2348 (insert (concat message-cross-post-note target-group "\n")))))
2350 (defun message-cross-post-followup-to (target-group)
2351 "Crossposts message and set Followup-To to TARGET-GROUP.
2352 With prefix-argument just set Follow-Up, don't cross-post."
2354 (list ; Completion based on Gnus
2355 (completing-read "Followup To: "
2356 (if (boundp 'gnus-newsrc-alist)
2358 nil nil '("poster" . 0)
2359 (if (boundp 'gnus-group-history)
2360 'gnus-group-history))))
2361 (cond ((not (or (null target-group) ; new subject not empty
2362 (zerop (string-width target-group))
2363 (string-match "^[ \t]*$" target-group)))
2365 (let* ((old-groups (message-fetch-field "Newsgroups"))
2366 (in-old (string-match
2367 (regexp-quote target-group)
2368 (or old-groups ""))))
2369 ;; check whether target exactly matches old Newsgroups
2370 (cond ((not old-groups)
2371 (error "No current newsgroup"))
2375 (regexp-quote target-group)
2378 ;; yes, Newsgroups line must change
2379 (message-cross-post-followup-to-header target-group)
2380 ;; insert note whether we do cross-post or followup-to
2381 (funcall message-cross-post-note-function
2383 (if (or (and message-cross-post-default
2384 (not current-prefix-arg))
2385 (and (not message-cross-post-default)
2386 current-prefix-arg)) t)
2387 in-old old-groups))))))))
2389 ;;; Reduce To: to Cc: or Bcc: header
2391 (defun message-reduce-to-to-cc ()
2392 "Replace contents of To: header with contents of Cc: or Bcc: header."
2395 (save-restriction (message-narrow-to-headers)
2396 (message-fetch-field "cc")))
2398 (if (and (not cc-content)
2401 (message-narrow-to-headers)
2402 (message-fetch-field "bcc"))))
2407 (message-delete-line)
2408 (insert (concat "To: " cc-content "\n"))
2410 (message-narrow-to-headers)
2411 (message-remove-header (if bcc
2415 ;;; End of functions adopted from `message-utils.el'.
2417 (defun message-remove-header (header &optional is-regexp first reverse)
2418 "Remove HEADER in the narrowed buffer.
2419 If IS-REGEXP, HEADER is a regular expression.
2420 If FIRST, only remove the first instance of the header.
2421 Return the number of headers removed."
2422 (goto-char (point-min))
2423 (let ((regexp (if is-regexp header (concat "^" (regexp-quote header) ":")))
2425 (case-fold-search t)
2427 (while (and (not (eobp))
2430 (not (looking-at regexp))
2431 (looking-at regexp))
2438 ;; There might be a continuation header, so we have to search
2439 ;; until we find a new non-continuation line.
2442 (if (re-search-forward "^[^ \t]" nil t)
2443 (goto-char (match-beginning 0))
2446 (if (re-search-forward "^[^ \t]" nil t)
2447 (goto-char (match-beginning 0))
2448 (goto-char (point-max)))))
2451 (defun message-remove-first-header (header)
2452 "Remove the first instance of HEADER if there is more than one."
2454 (regexp (concat "^" (regexp-quote header) ":")))
2456 (goto-char (point-min))
2457 (while (re-search-forward regexp nil t)
2460 (message-remove-header header nil t)
2463 (defun message-narrow-to-headers ()
2464 "Narrow the buffer to the head of the message."
2467 (goto-char (point-min))
2468 (if (re-search-forward
2469 (concat "^" (regexp-quote mail-header-separator) "\n") nil t)
2472 (goto-char (point-min)))
2474 (defun message-narrow-to-head-1 ()
2475 "Like `message-narrow-to-head'. Don't widen."
2477 (goto-char (point-min))
2478 (if (search-forward "\n\n" nil 1)
2481 (goto-char (point-min)))
2483 ;; FIXME: clarify diffference: message-narrow-to-head,
2484 ;; message-narrow-to-headers-or-head, message-narrow-to-headers
2485 (defun message-narrow-to-head ()
2486 "Narrow the buffer to the head of the message.
2487 Point is left at the beginning of the narrowed-to region."
2489 (message-narrow-to-head-1))
2491 (defun message-narrow-to-headers-or-head ()
2492 "Narrow the buffer to the head of the message."
2495 (goto-char (point-min))
2496 (if (re-search-forward (concat "\\(\n\\)\n\\|^\\("
2497 (regexp-quote mail-header-separator)
2500 (or (match-end 1) (match-beginning 2))
2502 (goto-char (point-min)))
2504 (defun message-news-p ()
2505 "Say whether the current buffer contains a news message."
2506 (and (not message-this-is-mail)
2507 (or message-this-is-news
2510 (message-narrow-to-headers)
2511 (and (message-fetch-field "newsgroups")
2512 (not (message-fetch-field "posted-to"))))))))
2514 (defun message-mail-p ()
2515 "Say whether the current buffer contains a mail message."
2516 (and (not message-this-is-news)
2517 (or message-this-is-mail
2520 (message-narrow-to-headers)
2521 (or (message-fetch-field "to")
2522 (message-fetch-field "cc")
2523 (message-fetch-field "bcc")))))))
2525 (defun message-subscribed-p ()
2526 "Say whether we need to insert a MFT header."
2527 (or message-subscribed-regexps
2528 message-subscribed-addresses
2529 message-subscribed-address-file
2530 message-subscribed-address-functions))
2532 (defun message-next-header ()
2533 "Go to the beginning of the next header."
2535 (or (eobp) (forward-char 1))
2536 (not (if (re-search-forward "^[^ \t]" nil t)
2538 (goto-char (point-max)))))
2540 (defun message-sort-headers-1 ()
2541 "Sort the buffer as headers using `message-rank' text props."
2542 (goto-char (point-min))
2545 nil 'message-next-header
2547 (message-next-header)
2551 (or (get-text-property (point) 'message-rank)
2554 (defun message-sort-headers ()
2555 "Sort the headers of the current message according to `message-header-format-alist'."
2559 (let ((max (1+ (length message-header-format-alist)))
2561 (message-narrow-to-headers)
2562 (while (re-search-forward "^[^ \n]+:" nil t)
2564 (match-beginning 0) (1+ (match-beginning 0))
2566 (if (setq rank (length (memq (assq (intern (buffer-substring
2568 (1- (match-end 0))))
2569 message-header-format-alist)
2570 message-header-format-alist)))
2573 (message-sort-headers-1))))
2575 (defun message-kill-address ()
2576 "Kill the address under point."
2578 (let ((start (point)))
2579 (message-skip-to-next-address)
2580 (kill-region start (point))))
2583 (autoload 'Info-goto-node "info")
2584 (defvar mml2015-use)
2586 (defun message-info (&optional arg)
2587 "Display the Message manual.
2589 Prefixed with one \\[universal-argument], display the Emacs MIME
2590 manual. With two \\[universal-argument]'s, display the EasyPG or
2591 PGG manual, depending on the value of `mml2015-use'."
2593 ;; Don't use `info' because support for `(filename)nodename' is not
2594 ;; available in XEmacs < 21.5.12.
2595 (Info-goto-node (format "(%s)Top"
2599 ((eq arg 4) 'emacs-mime)
2600 ;; `booleanp' only available in Emacs 22+
2601 ((and (not (memq arg '(nil t)))
2615 (defvar message-mode-map nil)
2617 (unless message-mode-map
2618 (setq message-mode-map (make-keymap))
2619 (set-keymap-parent message-mode-map text-mode-map)
2620 (define-key message-mode-map "\C-c?" 'describe-mode)
2622 (define-key message-mode-map "\C-c\C-f\C-t" 'message-goto-to)
2623 (define-key message-mode-map "\C-c\C-f\C-o" 'message-goto-from)
2624 (define-key message-mode-map "\C-c\C-f\C-b" 'message-goto-bcc)
2625 (define-key message-mode-map "\C-c\C-f\C-w" 'message-goto-fcc)
2626 (define-key message-mode-map "\C-c\C-f\C-c" 'message-goto-cc)
2627 (define-key message-mode-map "\C-c\C-f\C-s" 'message-goto-subject)
2628 (define-key message-mode-map "\C-c\C-f\C-r" 'message-goto-reply-to)
2629 (define-key message-mode-map "\C-c\C-f\C-n" 'message-goto-newsgroups)
2630 (define-key message-mode-map "\C-c\C-f\C-d" 'message-goto-distribution)
2631 (define-key message-mode-map "\C-c\C-f\C-f" 'message-goto-followup-to)
2632 (define-key message-mode-map "\C-c\C-f\C-m" 'message-goto-mail-followup-to)
2633 (define-key message-mode-map "\C-c\C-f\C-k" 'message-goto-keywords)
2634 (define-key message-mode-map "\C-c\C-f\C-u" 'message-goto-summary)
2635 (define-key message-mode-map "\C-c\C-f\C-i"
2636 'message-insert-or-toggle-importance)
2637 (define-key message-mode-map "\C-c\C-f\C-a"
2638 'message-generate-unsubscribed-mail-followup-to)
2640 ;; modify headers (and insert notes in body)
2641 (define-key message-mode-map "\C-c\C-fs" 'message-change-subject)
2643 (define-key message-mode-map "\C-c\C-fx" 'message-cross-post-followup-to)
2644 ;; prefix+message-cross-post-followup-to = same w/o cross-post
2645 (define-key message-mode-map "\C-c\C-ft" 'message-reduce-to-to-cc)
2646 (define-key message-mode-map "\C-c\C-fa" 'message-add-archive-header)
2647 ;; mark inserted text
2648 (define-key message-mode-map "\C-c\M-m" 'message-mark-inserted-region)
2649 (define-key message-mode-map "\C-c\M-f" 'message-mark-insert-file)
2651 (define-key message-mode-map "\C-c\C-b" 'message-goto-body)
2652 (define-key message-mode-map "\C-c\C-i" 'message-goto-signature)
2654 (define-key message-mode-map "\C-c\C-t" 'message-insert-to)
2655 (define-key message-mode-map "\C-c\C-fw" 'message-insert-wide-reply)
2656 (define-key message-mode-map "\C-c\C-n" 'message-insert-newsgroups)
2657 (define-key message-mode-map "\C-c\C-l" 'message-to-list-only)
2658 (define-key message-mode-map "\C-c\C-f\C-e" 'message-insert-expires)
2660 (define-key message-mode-map "\C-c\C-u" 'message-insert-or-toggle-importance)
2661 (define-key message-mode-map "\C-c\M-n"
2662 'message-insert-disposition-notification-to)
2664 (define-key message-mode-map "\C-c\C-y" 'message-yank-original)
2665 (define-key message-mode-map "\C-c\M-\C-y" 'message-yank-buffer)
2666 (define-key message-mode-map "\C-c\C-q" 'message-fill-yanked-message)
2667 (define-key message-mode-map "\C-c\C-w" 'message-insert-signature)
2668 (define-key message-mode-map "\C-c\M-h" 'message-insert-headers)
2669 (define-key message-mode-map "\C-c\C-r" 'message-caesar-buffer-body)
2670 (define-key message-mode-map "\C-c\C-o" 'message-sort-headers)
2671 (define-key message-mode-map "\C-c\M-r" 'message-rename-buffer)
2673 (define-key message-mode-map "\C-c\C-c" 'message-send-and-exit)
2674 (define-key message-mode-map "\C-c\C-s" 'message-send)
2675 (define-key message-mode-map "\C-c\C-k" 'message-kill-buffer)
2676 (define-key message-mode-map "\C-c\C-d" 'message-dont-send)
2677 (define-key message-mode-map "\C-c\n" 'gnus-delay-article)
2679 (define-key message-mode-map "\C-c\M-k" 'message-kill-address)
2680 (define-key message-mode-map "\C-c\C-e" 'message-elide-region)
2681 (define-key message-mode-map "\C-c\C-v" 'message-delete-not-region)
2682 (define-key message-mode-map "\C-c\C-z" 'message-kill-to-signature)
2683 (define-key message-mode-map "\M-\r" 'message-newline-and-reformat)
2684 (define-key message-mode-map [remap split-line] 'message-split-line)
2686 (define-key message-mode-map "\C-c\C-a" 'mml-attach-file)
2688 (define-key message-mode-map "\C-a" 'message-beginning-of-line)
2689 (define-key message-mode-map "\t" 'message-tab)
2691 (define-key message-mode-map "\M-n" 'message-display-abbrev))
2694 message-mode-menu message-mode-map "Message Menu."
2696 ["Yank Original" message-yank-original message-reply-buffer]
2697 ["Fill Yanked Message" message-fill-yanked-message t]
2698 ["Insert Signature" message-insert-signature t]
2699 ["Caesar (rot13) Message" message-caesar-buffer-body t]
2700 ["Caesar (rot13) Region" message-caesar-region (message-mark-active-p)]
2701 ["Elide Region" message-elide-region
2702 :active (message-mark-active-p)
2703 ,@(if (featurep 'xemacs) nil
2704 '(:help "Replace text in region with an ellipsis"))]
2705 ["Delete Outside Region" message-delete-not-region
2706 :active (message-mark-active-p)
2707 ,@(if (featurep 'xemacs) nil
2708 '(:help "Delete all quoted text outside region"))]
2709 ["Kill To Signature" message-kill-to-signature t]
2710 ["Newline and Reformat" message-newline-and-reformat t]
2711 ["Rename buffer" message-rename-buffer t]
2712 ["Spellcheck" ispell-message
2713 ,@(if (featurep 'xemacs) '(t)
2714 '(:help "Spellcheck this message"))]
2716 ["Insert Region Marked" message-mark-inserted-region
2717 :active (message-mark-active-p)
2718 ,@(if (featurep 'xemacs) nil
2719 '(:help "Mark region with enclosing tags"))]
2720 ["Insert File Marked..." message-mark-insert-file
2721 ,@(if (featurep 'xemacs) '(t)
2722 '(:help "Insert file at point marked with enclosing tags"))]
2724 ["Send Message" message-send-and-exit
2725 ,@(if (featurep 'xemacs) '(t)
2726 '(:help "Send this message"))]
2727 ["Postpone Message" message-dont-send
2728 ,@(if (featurep 'xemacs) '(t)
2729 '(:help "File this draft message and exit"))]
2730 ["Send at Specific Time..." gnus-delay-article
2731 ,@(if (featurep 'xemacs) '(t)
2732 '(:help "Ask, then arrange to send message at that time"))]
2733 ["Kill Message" message-kill-buffer
2734 ,@(if (featurep 'xemacs) '(t)
2735 '(:help "Delete this message without sending"))]
2737 ["Message manual" message-info
2738 ,@(if (featurep 'xemacs) '(t)
2739 '(:help "Display the Message manual"))]))
2742 message-mode-field-menu message-mode-map ""
2744 ["To" message-goto-to t]
2745 ["From" message-goto-from t]
2746 ["Subject" message-goto-subject t]
2747 ["Change subject..." message-change-subject t]
2748 ["Cc" message-goto-cc t]
2749 ["Bcc" message-goto-bcc t]
2750 ["Fcc" message-goto-fcc t]
2751 ["Reply-To" message-goto-reply-to t]
2752 ["Flag As Important" message-insert-importance-high
2753 ,@(if (featurep 'xemacs) '(t)
2754 '(:help "Mark this message as important"))]
2755 ["Flag As Unimportant" message-insert-importance-low
2756 ,@(if (featurep 'xemacs) '(t)
2757 '(:help "Mark this message as unimportant"))]
2759 message-insert-disposition-notification-to
2760 ,@(if (featurep 'xemacs) '(t)
2761 '(:help "Request a receipt notification"))]
2763 ;; (typical) news stuff
2764 ["Summary" message-goto-summary t]
2765 ["Keywords" message-goto-keywords t]
2766 ["Newsgroups" message-goto-newsgroups t]
2767 ["Fetch Newsgroups" message-insert-newsgroups t]
2768 ["Followup-To" message-goto-followup-to t]
2769 ;; ["Followup-To (with note in body)" message-cross-post-followup-to t]
2770 ["Crosspost / Followup-To..." message-cross-post-followup-to t]
2771 ["Distribution" message-goto-distribution t]
2772 ["Expires" message-insert-expires t ]
2773 ["X-No-Archive" message-add-archive-header t ]
2775 ;; (typical) mailing-lists stuff
2776 ["Fetch To" message-insert-to
2777 ,@(if (featurep 'xemacs) '(t)
2778 '(:help "Insert a To header that points to the author."))]
2779 ["Fetch To and Cc" message-insert-wide-reply
2780 ,@(if (featurep 'xemacs) '(t)
2782 "Insert To and Cc headers as if you were doing a wide reply."))]
2784 ["Send to list only" message-to-list-only t]
2785 ["Mail-Followup-To" message-goto-mail-followup-to t]
2786 ["Unsubscribed list post" message-generate-unsubscribed-mail-followup-to
2787 ,@(if (featurep 'xemacs) '(t)
2788 '(:help "Insert a reasonable `Mail-Followup-To:' header."))]
2789 ["Reduce To: to Cc:" message-reduce-to-to-cc t]
2791 ["Sort Headers" message-sort-headers t]
2792 ["Encode non-ASCII domain names" message-idna-to-ascii-rhs t]
2793 ;; We hide `message-hidden-headers' by narrowing the buffer.
2794 ["Show Hidden Headers" widen t]
2795 ["Goto Body" message-goto-body t]
2796 ["Goto Signature" message-goto-signature t]))
2798 (defvar message-tool-bar-map nil)
2800 (defvar facemenu-add-face-function)
2801 (defvar facemenu-remove-face-function)
2803 ;;; Forbidden properties
2805 ;; We use `after-change-functions' to keep special text properties
2806 ;; that interfere with the normal function of message mode out of the
2809 (defcustom message-strip-special-text-properties t
2810 "Strip special properties from the message buffer.
2812 Emacs has a number of special text properties which can break message
2813 composing in various ways. If this option is set, message will strip
2814 these properties from the message composition buffer. However, some
2815 packages requires these properties to be present in order to work.
2816 If you use one of these packages, turn this option off, and hope the
2817 message composition doesn't break too bad."
2819 :group 'message-various
2820 :link '(custom-manual "(message)Various Message Variables")
2823 (defvar message-forbidden-properties
2824 ;; No reason this should be clutter up customize. We make it a
2825 ;; property list (rather than a list of property symbols), to be
2826 ;; directly useful for `remove-text-properties'.
2827 '(field nil read-only nil invisible nil intangible nil
2828 mouse-face nil modification-hooks nil insert-in-front-hooks nil
2829 insert-behind-hooks nil point-entered nil point-left nil)
2830 ;; Other special properties:
2831 ;; category, face, display: probably doesn't do any harm.
2832 ;; fontified: is used by font-lock.
2833 ;; syntax-table, local-map: I dunno.
2834 ;; We need to add XEmacs names to the list.
2835 "Property list of with properties forbidden in message buffers.
2836 The values of the properties are ignored, only the property names are used.")
2838 (defun message-tamago-not-in-use-p (pos)
2839 "Return t when tamago version 4 is not in use at the cursor position.
2840 Tamago version 4 is a popular input method for writing Japanese text.
2841 It uses the properties `intangible', `invisible', `modification-hooks'
2842 and `read-only' when translating ascii or kana text to kanji text.
2843 These properties are essential to work, so we should never strip them."
2844 (not (and (boundp 'egg-modefull-mode)
2845 (symbol-value 'egg-modefull-mode)
2846 (or (memq (get-text-property pos 'intangible)
2847 '(its-part-1 its-part-2))
2848 (get-text-property pos 'egg-end)
2849 (get-text-property pos 'egg-lang)
2850 (get-text-property pos 'egg-start)))))
2852 (defsubst message-mail-alias-type-p (type)
2853 (if (atom message-mail-alias-type)
2854 (eq message-mail-alias-type type)
2855 (memq type message-mail-alias-type)))
2857 (defun message-strip-forbidden-properties (begin end &optional old-length)
2858 "Strip forbidden properties between BEGIN and END, ignoring the third arg.
2859 This function is intended to be called from `after-change-functions'.
2860 See also `message-forbidden-properties'."
2861 (when (and (message-mail-alias-type-p 'ecomplete)
2862 (memq this-command message-self-insert-commands))
2863 (message-display-abbrev))
2864 (when (and message-strip-special-text-properties
2865 (message-tamago-not-in-use-p begin))
2866 (let ((buffer-read-only nil)
2867 (inhibit-read-only t))
2868 (remove-text-properties begin end message-forbidden-properties))))
2870 (autoload 'ecomplete-setup "ecomplete") ;; for Emacs <23.
2873 (define-derived-mode message-mode text-mode "Message"
2874 "Major mode for editing mail and news to be sent.
2875 Like Text Mode but with these additional commands:\\<message-mode-map>
2876 C-c C-s `message-send' (send the message) C-c C-c `message-send-and-exit'
2877 C-c C-d Postpone sending the message C-c C-k Kill the message
2878 C-c C-f move to a header field (and create it if there isn't):
2879 C-c C-f C-t move to To C-c C-f C-s move to Subject
2880 C-c C-f C-c move to Cc C-c C-f C-b move to Bcc
2881 C-c C-f C-w move to Fcc C-c C-f C-r move to Reply-To
2882 C-c C-f C-u move to Summary C-c C-f C-n move to Newsgroups
2883 C-c C-f C-k move to Keywords C-c C-f C-d move to Distribution
2884 C-c C-f C-o move to From (\"Originator\")
2885 C-c C-f C-f move to Followup-To
2886 C-c C-f C-m move to Mail-Followup-To
2887 C-c C-f C-e move to Expires
2888 C-c C-f C-i cycle through Importance values
2889 C-c C-f s change subject and append \"(was: <Old Subject>)\"
2890 C-c C-f x crossposting with FollowUp-To header and note in body
2891 C-c C-f t replace To: header with contents of Cc: or Bcc:
2892 C-c C-f a Insert X-No-Archive: header and a note in the body
2893 C-c C-t `message-insert-to' (add a To header to a news followup)
2894 C-c C-l `message-to-list-only' (removes all but list address in to/cc)
2895 C-c C-n `message-insert-newsgroups' (add a Newsgroup header to a news reply)
2896 C-c C-b `message-goto-body' (move to beginning of message text).
2897 C-c C-i `message-goto-signature' (move to the beginning of the signature).
2898 C-c C-w `message-insert-signature' (insert `message-signature-file' file).
2899 C-c C-y `message-yank-original' (insert current message, if any).
2900 C-c C-q `message-fill-yanked-message' (fill what was yanked).
2901 C-c C-e `message-elide-region' (elide the text between point and mark).
2902 C-c C-v `message-delete-not-region' (remove the text outside the region).
2903 C-c C-z `message-kill-to-signature' (kill the text up to the signature).
2904 C-c C-r `message-caesar-buffer-body' (rot13 the message body).
2905 C-c C-a `mml-attach-file' (attach a file as MIME).
2906 C-c C-u `message-insert-or-toggle-importance' (insert or cycle importance).
2907 C-c M-n `message-insert-disposition-notification-to' (request receipt).
2908 C-c M-m `message-mark-inserted-region' (mark region with enclosing tags).
2909 C-c M-f `message-mark-insert-file' (insert file marked with enclosing tags).
2910 M-RET `message-newline-and-reformat' (break the line and reformat)."
2911 (setq local-abbrev-table text-mode-abbrev-table)
2912 (set (make-local-variable 'message-reply-buffer) nil)
2913 (set (make-local-variable 'message-inserted-headers) nil)
2914 (set (make-local-variable 'message-send-actions) nil)
2915 (set (make-local-variable 'message-return-action) nil)
2916 (set (make-local-variable 'message-exit-actions) nil)
2917 (set (make-local-variable 'message-kill-actions) nil)
2918 (set (make-local-variable 'message-postpone-actions) nil)
2919 (set (make-local-variable 'message-draft-article) nil)
2920 (setq buffer-offer-save t)
2921 (set (make-local-variable 'facemenu-add-face-function)
2923 (let ((face-fun (cdr (assq face message-face-alist))))
2925 (funcall face-fun (point) end)
2926 (error "Face %s not configured for %s mode" face mode-name)))
2928 (set (make-local-variable 'facemenu-remove-face-function) t)
2929 (set (make-local-variable 'message-reply-headers) nil)
2930 (make-local-variable 'message-newsreader)
2931 (make-local-variable 'message-mailer)
2932 (make-local-variable 'message-post-method)
2933 (set (make-local-variable 'message-sent-message-via) nil)
2934 (set (make-local-variable 'message-checksum) nil)
2935 (set (make-local-variable 'message-mime-part) 0)
2936 (message-setup-fill-variables)
2937 (when message-fill-column
2938 (setq fill-column message-fill-column)
2939 (turn-on-auto-fill))
2940 ;; Allow using comment commands to add/remove quoting.
2941 ;; (set (make-local-variable 'comment-start) message-yank-prefix)
2942 (when message-yank-prefix
2943 (set (make-local-variable 'comment-start) message-yank-prefix)
2944 (set (make-local-variable 'comment-start-skip)
2945 (concat "^" (regexp-quote message-yank-prefix) "[ \t]*")))
2946 (if (featurep 'xemacs)
2947 (message-setup-toolbar)
2948 (set (make-local-variable 'font-lock-defaults)
2949 '(message-font-lock-keywords t))
2950 (if (boundp 'tool-bar-map)
2951 (set (make-local-variable 'tool-bar-map) (message-make-tool-bar))))
2952 (easy-menu-add message-mode-menu message-mode-map)
2953 (easy-menu-add message-mode-field-menu message-mode-map)
2954 (gnus-make-local-hook 'after-change-functions)
2955 ;; Mmmm... Forbidden properties...
2956 (add-hook 'after-change-functions 'message-strip-forbidden-properties
2958 ;; Allow mail alias things.
2960 ((message-mail-alias-type-p 'abbrev)
2961 (if (fboundp 'mail-abbrevs-setup)
2962 (mail-abbrevs-setup)
2963 (if (fboundp 'mail-aliases-setup) ; warning avoidance
2964 (mail-aliases-setup))))
2965 ((message-mail-alias-type-p 'ecomplete)
2967 (add-hook 'completion-at-point-functions 'message-completion-function nil t)
2968 (unless buffer-file-name
2969 (message-set-auto-save-file-name))
2970 (unless (buffer-base-buffer)
2971 ;; Don't enable multibyte on an indirect buffer. Maybe enabling
2972 ;; multibyte is not necessary at all. -- zsh
2973 (mm-enable-multibyte))
2974 (set (make-local-variable 'indent-tabs-mode) nil) ;No tabs for indentation.
2977 (defun message-setup-fill-variables ()
2978 "Setup message fill variables."
2979 (set (make-local-variable 'fill-paragraph-function)
2980 'message-fill-paragraph)
2981 (make-local-variable 'paragraph-separate)
2982 (make-local-variable 'paragraph-start)
2983 (make-local-variable 'adaptive-fill-regexp)
2984 (unless (boundp 'adaptive-fill-first-line-regexp)
2985 (setq adaptive-fill-first-line-regexp nil))
2986 (make-local-variable 'adaptive-fill-first-line-regexp)
2987 (let ((quote-prefix-regexp
2988 ;; User should change message-cite-prefix-regexp if
2989 ;; message-yank-prefix is set to an abnormal value.
2990 (concat "\\(" message-cite-prefix-regexp "\\)[ \t]*")))
2991 (setq paragraph-start
2993 (regexp-quote mail-header-separator) "$\\|"
2994 "[ \t]*$\\|" ; blank lines
2995 "-- $\\|" ; signature delimiter
2996 "---+$\\|" ; delimiters for forwarded messages
2997 page-delimiter "$\\|" ; spoiler warnings
2998 ".*wrote:$\\|" ; attribution lines
2999 quote-prefix-regexp "$\\|" ; empty lines in quoted text
3001 "<#!*/?\\(multipart\\|part\\|external\\|mml\\|secure\\)"))
3002 (setq paragraph-separate paragraph-start)
3003 (setq adaptive-fill-regexp
3004 (concat quote-prefix-regexp "\\|" adaptive-fill-regexp))
3005 (setq adaptive-fill-first-line-regexp
3006 (concat quote-prefix-regexp "\\|"
3007 adaptive-fill-first-line-regexp)))
3008 (make-local-variable 'auto-fill-inhibit-regexp)
3009 ;;(setq auto-fill-inhibit-regexp "^[A-Z][^: \n\t]+:")
3010 (setq auto-fill-inhibit-regexp nil)
3011 (make-local-variable 'normal-auto-fill-function)
3012 (setq normal-auto-fill-function 'message-do-auto-fill)
3013 ;; KLUDGE: auto fill might already be turned on in `text-mode-hook'.
3014 ;; In that case, ensure that it uses the right function. The real
3015 ;; solution would be not to use `define-derived-mode', and run
3016 ;; `text-mode-hook' ourself at the end of the mode.
3017 ;; -- Per Abrahamsen <abraham@dina.kvl.dk> Date: 2001-10-19.
3018 ;; This kludge is unneeded in Emacs>=21 since define-derived-mode is
3019 ;; now careful to run parent hooks after the body. --Stef
3020 (when auto-fill-function
3021 (setq auto-fill-function normal-auto-fill-function)))
3026 ;;; Message mode commands
3029 ;;; Movement commands
3031 (defun message-goto-to ()
3032 "Move point to the To header."
3034 (message-position-on-field "To"))
3036 (defun message-goto-from ()
3037 "Move point to the From header."
3039 (message-position-on-field "From"))
3041 (defun message-goto-subject ()
3042 "Move point to the Subject header."
3044 (message-position-on-field "Subject"))
3046 (defun message-goto-cc ()
3047 "Move point to the Cc header."
3049 (message-position-on-field "Cc" "To"))
3051 (defun message-goto-bcc ()
3052 "Move point to the Bcc header."
3054 (message-position-on-field "Bcc" "Cc" "To"))
3056 (defun message-goto-fcc ()
3057 "Move point to the Fcc header."
3059 (message-position-on-field "Fcc" "To" "Newsgroups"))
3061 (defun message-goto-reply-to ()
3062 "Move point to the Reply-To header."
3064 (message-position-on-field "Reply-To" "Subject"))
3066 (defun message-goto-newsgroups ()
3067 "Move point to the Newsgroups header."
3069 (message-position-on-field "Newsgroups"))
3071 (defun message-goto-distribution ()
3072 "Move point to the Distribution header."
3074 (message-position-on-field "Distribution"))
3076 (defun message-goto-followup-to ()
3077 "Move point to the Followup-To header."
3079 (message-position-on-field "Followup-To" "Newsgroups"))
3081 (defun message-goto-mail-followup-to ()
3082 "Move point to the Mail-Followup-To header."
3084 (message-position-on-field "Mail-Followup-To" "To"))
3086 (defun message-goto-keywords ()
3087 "Move point to the Keywords header."
3089 (message-position-on-field "Keywords" "Subject"))
3091 (defun message-goto-summary ()
3092 "Move point to the Summary header."
3094 (message-position-on-field "Summary" "Subject"))
3097 (defmacro message-called-interactively-p (kind)
3100 (eval '(called-interactively-p 'any))
3102 `(called-interactively-p ,kind))
3104 (wrong-number-of-arguments '(called-interactively-p))
3106 (void-function '(interactive-p)))))
3108 (defun message-goto-body ()
3109 "Move point to the beginning of the message body."
3111 (when (and (message-called-interactively-p 'any)
3112 (looking-at "[ \t]*\n"))
3114 (goto-char (point-min))
3115 (or (search-forward (concat "\n" mail-header-separator "\n") nil t)
3116 (search-forward-regexp "[^:]+:\\([^\n]\\|\n[ \t]\\)+\n\n" nil t)))
3118 (defun message-in-body-p ()
3119 "Return t if point is in the message body."
3120 (let ((body (save-excursion (message-goto-body))))
3123 (defun message-goto-eoh ()
3124 "Move point to the end of the headers."
3129 (defun message-goto-signature ()
3130 "Move point to the beginning of the message signature.
3131 If there is no signature in the article, go to the end and
3134 (goto-char (point-min))
3135 (if (re-search-forward message-signature-separator nil t)
3137 (goto-char (point-max))
3140 (defun message-generate-unsubscribed-mail-followup-to (&optional include-cc)
3141 "Insert a reasonable MFT header in a post to an unsubscribed list.
3142 When making original posts to a mailing list you are not subscribed to,
3143 you have to type in a MFT header by hand. The contents, usually, are
3144 the addresses of the list and your own address. This function inserts
3145 such a header automatically. It fetches the contents of the To: header
3146 in the current mail buffer, and appends the current `user-mail-address'.
3148 If the optional argument INCLUDE-CC is non-nil, the addresses in the
3149 Cc: header are also put into the MFT."
3154 (message-narrow-to-headers)
3155 (message-remove-header "Mail-Followup-To")
3156 (setq cc (and include-cc (message-fetch-field "Cc")))
3158 (concat (message-fetch-field "To") "," cc)
3159 (message-fetch-field "To"))))
3160 (message-goto-mail-followup-to)
3161 (insert (concat tos ", " user-mail-address))))
3165 (defun message-insert-to (&optional force)
3166 "Insert a To header that points to the author of the article being replied to.
3167 If the original author requested not to be sent mail, don't insert unless the
3168 prefix FORCE is given."
3170 (let* ((mct (message-fetch-reply-field "mail-copies-to"))
3171 (dont (and mct (or (equal (downcase mct) "never")
3172 (equal (downcase mct) "nobody"))))
3173 (to (or (message-fetch-reply-field "mail-reply-to")
3174 (message-fetch-reply-field "reply-to")
3175 (message-fetch-reply-field "from"))))
3179 "Ignoring the user request not to have copies sent via mail"
3180 "Complying with the user request not to have copies sent via mail")))
3181 (when (and force (not to))
3182 (error "No mail address in the article"))
3183 (when (and to (or force (not dont)))
3184 (message-carefully-insert-headers (list (cons 'To to))))))
3186 (defun message-insert-wide-reply ()
3187 "Insert To and Cc headers as if you were doing a wide reply."
3189 (let ((headers (message-with-reply-buffer
3190 (message-get-reply-headers t))))
3191 (message-carefully-insert-headers headers)))
3193 (defcustom message-header-synonyms
3196 "List of lists of header synonyms.
3197 E.g., if this list contains a member list with elements `Cc' and `To',
3198 then `message-carefully-insert-headers' will not insert a `To' header
3199 when the message is already `Cc'ed to the recipient."
3201 :group 'message-headers
3202 :link '(custom-manual "(message)Message Headers")
3203 :type '(repeat sexp))
3205 (defun message-carefully-insert-headers (headers)
3206 "Insert the HEADERS, an alist, into the message buffer.
3207 Does not insert the headers when they are already present there
3208 or in the synonym headers, defined by `message-header-synonyms'."
3209 ;; FIXME: Should compare only the address and not the full name. Comparison
3210 ;; should be done case-folded (and with `string=' rather than
3212 ;; (mail-strip-quoted-names "Foo Bar <foo@bar>, bla@fasel (Bla Fasel)")
3213 (dolist (header headers)
3214 (let* ((header-name (symbol-name (car header)))
3215 (new-header (cdr header))
3216 (synonyms (loop for synonym in message-header-synonyms
3217 when (memq (car header) synonym) return synonym))
3219 (loop for synonym in synonyms
3220 for old-header = (mail-fetch-field (symbol-name synonym))
3221 when (and old-header (string-match new-header old-header))
3224 (message "already have `%s' in `%s'" new-header old-header)
3225 (when (and (message-position-on-field header-name)
3226 (setq old-header (mail-fetch-field header-name))
3227 (not (string-match "\\` *\\'" old-header)))
3229 (insert new-header)))))
3231 (defun message-widen-reply ()
3232 "Widen the reply to include maximum recipients."
3235 (and (bufferp message-reply-buffer)
3236 (buffer-name message-reply-buffer)
3237 (with-current-buffer message-reply-buffer
3238 (message-get-reply-headers t)))))
3241 (message-narrow-to-headers)
3242 (dolist (elem follow-to)
3243 (message-remove-header (symbol-name (car elem)))
3244 (goto-char (point-min))
3245 (insert (symbol-name (car elem)) ": "
3246 (cdr elem) "\n"))))))
3248 (defun message-insert-newsgroups ()
3249 "Insert the Newsgroups header from the article being replied to."
3251 (when (and (message-position-on-field "Newsgroups")
3252 (mail-fetch-field "newsgroups")
3253 (not (string-match "\\` *\\'" (mail-fetch-field "newsgroups"))))
3255 (insert (or (message-fetch-reply-field "newsgroups") "")))
3259 ;;; Various commands
3261 (defun message-delete-not-region (beg end)
3262 "Delete everything in the body of the current message outside of the region."
3267 ;; snarf citation prefix, if appropriate
3268 (unless (eq (point) (progn (beginning-of-line) (point)))
3269 (when (looking-at message-cite-prefix-regexp)
3270 (setq citeprefix (match-string 0))))
3272 (delete-region (point) (if (not (message-goto-signature))
3278 (delete-region beg (progn (message-goto-body)
3282 (insert citeprefix))))
3283 (when (message-goto-signature)
3286 (defun message-kill-to-signature (&optional arg)
3287 "Kill all text up to the signature.
3288 If a numeric argument or prefix arg is given, leave that number
3289 of lines before the signature intact."
3293 (let ((point (point)))
3294 (narrow-to-region point (point-max))
3295 (message-goto-signature)
3297 (if (and arg (numberp arg))
3298 (forward-line (- -1 arg))
3300 (unless (= point (point))
3301 (kill-region point (point))
3305 (defun message-newline-and-reformat (&optional arg not-break)
3306 "Insert four newlines, and then reformat if inside quoted text.
3307 Prefix arg means justify as well."
3308 (interactive (list (if current-prefix-arg 'full)))
3309 (let (quoted point beg end leading-space bolp fill-paragraph-function)
3310 (setq point (point))
3313 (setq bolp (= beg point))
3314 ;; Find first line of the paragraph.
3316 (while (and (not (eobp))
3317 (not (looking-at message-cite-prefix-regexp))
3318 (looking-at paragraph-start))
3321 (when (looking-at message-cite-prefix-regexp)
3322 (setq quoted (match-string 0))
3323 (goto-char (match-end 0))
3324 (looking-at "[ \t]*")
3325 (setq leading-space (match-string 0)))
3329 (< (- point beg) (length quoted)))
3330 ;; break inside the cite prefix.
3336 (while (and (not (eobp))
3337 (not (looking-at paragraph-separate))
3338 (looking-at message-cite-prefix-regexp)
3339 (equal quoted (match-string 0)))
3340 (goto-char (match-end 0))
3341 (looking-at "[ \t]*")
3342 (if (> (length leading-space) (length (match-string 0)))
3343 (setq leading-space (match-string 0)))
3347 (while (and (if (bobp) nil (forward-line -1) t)
3348 (not (looking-at paragraph-start))
3349 (looking-at message-cite-prefix-regexp)
3350 (equal quoted (match-string 0)))
3352 (goto-char (match-end 0))
3353 (looking-at "[ \t]*")
3354 (if (> (length leading-space) (length (match-string 0)))
3355 (setq leading-space (match-string 0)))))
3356 (while (and (not (eobp))
3357 (not (looking-at paragraph-separate))
3358 (not (looking-at message-cite-prefix-regexp)))
3362 (while (and (if (bobp) nil (forward-line -1) t)
3363 (not (looking-at paragraph-start))
3364 (not (looking-at message-cite-prefix-regexp)))
3365 (setq beg (point))))
3368 (narrow-to-region beg end)
3375 (setq point (point))
3376 ;; (newline 2) doesn't mark both newline's as hard, so call
3377 ;; newline twice. -jas
3380 (delete-region (point) (re-search-forward "[ \t]*"))
3381 (when (and quoted (not bolp))
3382 (insert quoted leading-space)))
3385 (let* ((adaptive-fill-regexp
3386 (regexp-quote (concat quoted leading-space)))
3387 (adaptive-fill-first-line-regexp
3388 adaptive-fill-regexp ))
3389 (fill-paragraph arg))
3390 (fill-paragraph arg))
3391 (if point (goto-char point)))))
3393 (defun message-fill-paragraph (&optional arg)
3394 "Message specific function to fill a paragraph.
3395 This function is used as the value of `fill-paragraph-function' in
3396 Message buffers and is not meant to be called directly."
3397 (interactive (list (if current-prefix-arg 'full)))
3398 (if (if (boundp 'filladapt-mode) filladapt-mode)
3400 (if (message-point-in-header-p)
3401 (message-fill-field)
3402 (message-newline-and-reformat arg t))
3405 (defun message-point-in-header-p ()
3406 "Return t if point is in the header."
3408 (not (re-search-backward
3409 (concat "^" (regexp-quote mail-header-separator) "\n") nil t))))
3411 (defun message-do-auto-fill ()
3412 "Like `do-auto-fill', but don't fill in message header."
3413 (unless (message-point-in-header-p)
3416 (defun message-insert-signature (&optional force)
3417 "Insert a signature. See documentation for variable `message-signature'."
3418 (interactive (list 0))
3421 ((and (null message-signature)
3424 (goto-char (point-max))
3425 (not (re-search-backward message-signature-separator nil t))))
3426 ((and (null message-signature)
3429 ((functionp message-signature)
3430 (funcall message-signature))
3431 ((listp message-signature)
3432 (eval message-signature))
3433 (t message-signature)))
3436 (cond ((stringp signature)
3438 ((and (eq t signature) message-signature-file)
3439 (setq signature-file
3440 (if (and message-signature-directory
3441 ;; don't actually use the signature directory
3442 ;; if message-signature-file contains a path.
3443 (not (file-name-directory
3444 message-signature-file)))
3445 (expand-file-name message-signature-file
3446 message-signature-directory)
3447 message-signature-file))
3448 (file-exists-p signature-file))))
3450 (goto-char (point-max))
3451 ;; Insert the signature.
3454 (when message-signature-insert-empty-line
3457 (if (eq signature t)
3458 (insert-file-contents signature-file)
3460 (goto-char (point-max))
3461 (or (bolp) (insert "\n")))))
3463 (defun message-insert-importance-high ()
3464 "Insert header to mark message as important."
3468 (message-narrow-to-headers)
3469 (message-remove-header "Importance"))
3471 (insert "Importance: high\n")))
3473 (defun message-insert-importance-low ()
3474 "Insert header to mark message as unimportant."
3478 (message-narrow-to-headers)
3479 (message-remove-header "Importance"))
3481 (insert "Importance: low\n")))
3483 (defun message-insert-or-toggle-importance ()
3484 "Insert a \"Importance: high\" header, or cycle through the header values.
3485 The three allowed values according to RFC 1327 are `high', `normal'
3492 (message-narrow-to-headers)
3493 (when (setq cur (message-fetch-field "Importance"))
3494 (message-remove-header "Importance")
3495 (setq new (cond ((string= cur "high")
3497 ((string= cur "low")
3502 (insert (format "Importance: %s\n" new)))))
3504 (defun message-insert-disposition-notification-to ()
3505 "Request a disposition notification (return receipt) to this message.
3506 Note that this should not be used in newsgroups."
3510 (message-narrow-to-headers)
3511 (message-remove-header "Disposition-Notification-To"))
3513 (insert (format "Disposition-Notification-To: %s\n"
3514 (or (message-field-value "Reply-to")
3515 (message-field-value "From")
3516 (message-make-from))))))
3518 (defun message-elide-region (b e)
3519 "Elide the text in the region.
3520 An ellipsis (from `message-elide-ellipsis') will be inserted where the
3524 (insert message-elide-ellipsis))
3526 (defvar message-caesar-translation-table nil)
3528 (defun message-caesar-region (b e &optional n)
3529 "Caesar rotate region B to E by N, default 13, for decrypting netnews."
3532 (min (point) (or (mark t) (point)))
3533 (max (point) (or (mark t) (point)))
3534 (when current-prefix-arg
3535 (prefix-numeric-value current-prefix-arg))))
3537 (setq n (if (numberp n) (mod n 26) 13)) ;canonize N
3538 (unless (or (zerop n) ; no action needed for a rot of 0
3539 (= b e)) ; no region to rotate
3540 ;; We build the table, if necessary.
3541 (when (or (not message-caesar-translation-table)
3542 (/= (aref message-caesar-translation-table ?a) (+ ?a n)))
3543 (setq message-caesar-translation-table
3544 (message-make-caesar-translation-table n)))
3545 (translate-region b e message-caesar-translation-table)))
3547 (defun message-make-caesar-translation-table (n)
3548 "Create a rot table with offset N."
3550 (table (make-string 256 0)))
3551 (while (< (incf i) 256)
3554 (substring table 0 ?A)
3555 (substring table (+ ?A n) (+ ?A n (- 26 n)))
3556 (substring table ?A (+ ?A n))
3557 (substring table (+ ?A 26) ?a)
3558 (substring table (+ ?a n) (+ ?a n (- 26 n)))
3559 (substring table ?a (+ ?a n))
3560 (substring table (+ ?a 26) 255))))
3562 (defun message-caesar-buffer-body (&optional rotnum wide)
3563 "Caesar rotate all letters in the current buffer by 13 places.
3564 Used to encode/decode possibly offensive messages (commonly in rec.humor).
3565 With prefix arg, specifies the number of places to rotate each letter forward.
3566 Mail and USENET news headers are not rotated unless WIDE is non-nil."
3567 (interactive (if current-prefix-arg
3568 (list (prefix-numeric-value current-prefix-arg))
3572 (when (and (not wide) (message-goto-body))
3573 (narrow-to-region (point) (point-max)))
3574 (message-caesar-region (point-min) (point-max) rotnum))))
3576 (defun message-pipe-buffer-body (program)
3577 "Pipe the message body in the current buffer through PROGRAM."
3580 (when (message-goto-body)
3581 (narrow-to-region (point) (point-max)))
3582 (shell-command-on-region
3583 (point-min) (point-max) program nil t))))
3585 (defun message-rename-buffer (&optional enter-string)
3586 "Rename the *message* buffer to \"*message* RECIPIENT\".
3587 If the function is run with a prefix, it will ask for a new buffer
3588 name, rather than giving an automatic name."
3589 (interactive "Pbuffer name: ")
3592 (goto-char (point-min))
3593 (narrow-to-region (point)
3594 (search-forward mail-header-separator nil 'end))
3596 (if (message-news-p) (message-fetch-field "Newsgroups")
3597 (message-fetch-field "To"))
3600 (if (string-match "," mail-to)
3601 (concat (substring mail-to 0 (match-beginning 0)) ", ...")
3603 (name-default (concat "*message* " mail-trimmed-to))
3604 (name (if enter-string
3605 (read-string "New buffer name: " name-default)
3607 (rename-buffer name t)))))
3609 (defun message-fill-yanked-message (&optional justifyp)
3610 "Fill the paragraphs of a message yanked into this one.
3611 Numeric argument means justify as well."
3614 (goto-char (point-min))
3615 (search-forward (concat "\n" mail-header-separator "\n") nil t)
3616 (let ((fill-prefix message-yank-prefix))
3617 (fill-individual-paragraphs (point) (point-max) justifyp))))
3619 (defun message-indent-citation (&optional start end yank-only)
3620 "Modify text just inserted from a message to be cited.
3621 The inserted text should be the region.
3622 When this function returns, the region is again around the modified text.
3624 Normally, indent each nonblank line `message-indentation-spaces' spaces.
3625 However, if `message-yank-prefix' is non-nil, insert that prefix on each line."
3626 (unless start (setq start (point)))
3628 ;; Remove unwanted headers.
3629 (when message-ignored-cited-headers
3634 (if (search-forward "\n\n" nil t)
3637 (message-remove-header message-ignored-cited-headers t)
3638 (when (= (point-min) (point-max))
3639 (setq all-removed t))
3640 (goto-char (point-max)))
3644 ;; Delete blank lines at the start of the buffer.
3645 (while (and (point-min)
3648 (message-delete-line))
3649 ;; Delete blank lines at the end of the buffer.
3650 (goto-char (point-max))
3653 (while (and (zerop (forward-line -1))
3655 (message-delete-line)))
3656 ;; Do the indentation.
3657 (if (null message-yank-prefix)
3658 (indent-rigidly start (or end (mark t)) message-indentation-spaces)
3661 (while (< (point) (or end (mark t)))
3662 (cond ((looking-at ">")
3663 (insert message-yank-cited-prefix))
3665 (insert message-yank-empty-prefix))
3667 (insert message-yank-prefix)))
3671 (defun message-remove-blank-cited-lines (&optional remove)
3672 "Remove cited lines containing only blanks.
3673 If REMOVE is non-nil, remove newlines, too.
3675 To use this automatically, you may add this function to
3676 `gnus-message-setup-hook'."
3681 (when (boundp 'message-yank-cited-prefix)
3682 (concat message-yank-cited-prefix "\\|"))
3686 (gnus-message 8 "removing `%s'" citexp)
3689 (while (re-search-forward citexp nil t)
3690 (replace-match (if remove "" "\n"))))))
3692 (defvar message-cite-reply-above nil
3693 "If non-nil, start own text above the quote.
3695 Note: Top posting is bad netiquette. Don't use it unless you
3696 really must. You probably want to set variable only for specific
3697 groups, e.g. using `gnus-posting-styles':
3699 (eval (set (make-local-variable 'message-cite-reply-above) t))
3701 This variable has no effect in news postings.")
3703 (defun message-yank-original (&optional arg)
3704 "Insert the message being replied to, if any.
3705 Puts point before the text and mark after.
3706 Normally indents each nonblank line ARG spaces (default 3). However,
3707 if `message-yank-prefix' is non-nil, insert that prefix on each line.
3709 This function uses `message-cite-function' to do the actual citing.
3711 Just \\[universal-argument] as argument means don't indent, insert no
3712 prefix, and don't delete any headers."
3714 (let ((modified (buffer-modified-p))
3716 (when (and message-reply-buffer
3717 message-cite-function)
3718 (when message-cite-reply-above
3719 (if (and (not (message-news-p))
3720 (or (eq message-cite-reply-above 'is-evil)
3722 Top posting is bad netiquette. Please don't top post unless you really must.
3723 Really top post? ")))
3726 (buffer-substring (message-goto-body)
3728 (delete-region (message-goto-body) (point-max)))
3729 (set (make-local-variable 'message-cite-reply-above) nil)))
3730 (if (bufferp message-reply-buffer)
3731 (delete-windows-on message-reply-buffer t))
3732 (push-mark (save-excursion
3734 ((bufferp message-reply-buffer)
3735 (insert-buffer-substring message-reply-buffer))
3736 ((and (consp message-reply-buffer)
3737 (functionp (car message-reply-buffer)))
3738 (apply (car message-reply-buffer)
3739 (cdr message-reply-buffer))))
3744 (funcall message-cite-function)
3745 (unless (eq (char-before (mark t)) ?\n)
3747 (goto-char (mark t))
3748 (insert-before-markers ?\n)
3750 (when message-cite-reply-above
3753 (insert (if (bolp) "\n" "\n\n"))
3754 (message-goto-body))
3755 ;; Add a `message-setup-very-last-hook' here?
3756 ;; Add `gnus-article-highlight-citation' here?
3758 (setq message-checksum (message-checksum))))))
3760 (defun message-yank-buffer (buffer)
3761 "Insert BUFFER into the current buffer and quote it."
3762 (interactive "bYank buffer: ")
3763 (let ((message-reply-buffer (get-buffer buffer)))
3764 (save-window-excursion
3765 (message-yank-original))))
3767 (defun message-buffers ()
3768 "Return a list of active message buffers."
3770 (save-current-buffer
3771 (dolist (buffer (buffer-list t))
3773 (when (and (eq major-mode 'message-mode)
3774 (null message-sent-message-via))
3775 (push (buffer-name buffer) buffers))))
3776 (nreverse buffers)))
3778 (defun message-cite-original-1 (strip-signature)
3779 "Cite an original message.
3780 If STRIP-SIGNATURE is non-nil, strips off the signature from the
3783 This function uses `mail-citation-hook' if that is non-nil."
3784 (if (and (boundp 'mail-citation-hook)
3786 (run-hooks 'mail-citation-hook)
3787 (let* ((start (point))
3791 (when message-indent-citation-function
3792 (if (listp message-indent-citation-function)
3793 message-indent-citation-function
3794 (list message-indent-citation-function))))
3795 ;; This function may be called by `gnus-summary-yank-message' and
3796 ;; may insert a different article from the original. So, we will
3797 ;; modify the value of `message-reply-headers' with that article.
3798 (message-reply-headers
3800 (narrow-to-region start end)
3801 (message-narrow-to-head-1)
3802 (setq x-no-archive (message-fetch-field "x-no-archive"))
3804 (or (message-fetch-field "subject") "none")
3805 (or (message-fetch-field "from") "nobody")
3806 (message-fetch-field "date")
3807 (message-fetch-field "message-id" t)
3808 (message-fetch-field "references")
3810 (mml-quote-region start end)
3811 (when strip-signature
3815 (when (re-search-backward message-signature-separator start t)
3816 ;; Also peel off any blank lines before the signature.
3818 (while (looking-at "^[ \t]*$")
3821 (delete-region (point) end)
3822 (unless (search-backward "\n\n" start t)
3823 ;; Insert a blank line if it is peeled off.
3826 (mapc 'funcall functions)
3827 (when message-citation-line-function
3830 (funcall message-citation-line-function))
3831 (when (and x-no-archive
3832 (not message-cite-articles-with-x-no-archive)
3833 (string-match "yes" x-no-archive))
3835 (delete-region (point) (mark t))
3836 (insert "> [Quoted text removed due to X-No-Archive]\n")
3838 (forward-line -1)))))
3840 (defun message-cite-original ()
3841 "Cite function in the standard Message manner."
3842 (message-cite-original-1 nil))
3844 (defvar gnus-extract-address-components)
3846 (autoload 'format-spec "format-spec")
3848 (defun message-insert-formatted-citation-line (&optional from date)
3849 "Function that inserts a formatted citation line.
3851 See `message-citation-line-format'."
3852 ;; The optional args are for testing/debugging. They will disappear later.
3854 ;; (with-temp-buffer
3855 ;; (message-insert-formatted-citation-line
3856 ;; "John Doe <john.doe@example.invalid>"
3859 (when (or message-reply-headers (and from date))
3861 (setq from (mail-header-from message-reply-headers)))
3862 (let* ((data (condition-case ()
3863 (funcall (if (boundp gnus-extract-address-components)
3864 gnus-extract-address-components
3865 'mail-extract-address-components)
3871 (net (car (cdr data)))
3872 (name-or-net (or (car data)
3873 (car (cdr data)) from))
3877 ;; We need Gnus functionality if the user wants date or time from
3878 ;; the original article:
3879 (when (string-match "%[^fnNFL]" message-citation-line-format)
3880 (autoload 'gnus-date-get-time "gnus-util")
3881 (gnus-date-get-time (mail-header-date message-reply-headers)))))
3884 (when (stringp name)
3885 ;; Guess first name and last name:
3886 (cond ((string-match
3887 "\\`\\(\\w\\|[-.]\\)+ \\(\\w\\|[-.]\\)+\\'" name)
3888 (setq fname (nth 0 (split-string name "[ \t]+"))
3889 lname (nth 1 (split-string name "[ \t]+"))))
3891 "\\`\\(\\w\\|[-.]\\)+, \\(\\w\\|[-.]\\)+\\'" name)
3892 (setq fname (nth 1 (split-string name "[ \t,]+"))
3893 lname (nth 0 (split-string name "[ \t,]+"))))
3895 "\\`\\(\\w\\|[-.]\\)+\\'" name)
3898 ;; The following letters are not used in `format-time-string':
3899 (push ?E lst) (push "<E>" lst)
3900 (push ?F lst) (push fname lst)
3901 ;; We might want to use "" instead of "<X>" later.
3902 (push ?J lst) (push "<J>" lst)
3903 (push ?K lst) (push "<K>" lst)
3904 (push ?L lst) (push lname lst)
3905 (push ?N lst) (push name-or-net lst)
3906 (push ?O lst) (push "<O>" lst)
3907 (push ?P lst) (push "<P>" lst)
3908 (push ?Q lst) (push "<Q>" lst)
3909 (push ?f lst) (push from lst)
3910 (push ?i lst) (push "<i>" lst)
3911 (push ?n lst) (push net lst)
3912 (push ?o lst) (push "<o>" lst)
3913 (push ?q lst) (push "<q>" lst)
3914 (push ?t lst) (push "<t>" lst)
3915 (push ?v lst) (push "<v>" lst)
3916 ;; Delegate the rest to `format-time-string':
3918 (when (and (not (memq i lst))
3923 (push (condition-case nil
3924 (format-time-string (format "%%%c" i) replydate)
3925 (error (format ">%c<" i)))
3929 (spec (apply 'format-spec-make flist)))
3930 (insert (format-spec message-citation-line-format spec)))
3933 (defun message-cite-original-without-signature ()
3934 "Cite function in the standard Message manner.
3935 This function strips off the signature from the original message."
3936 (message-cite-original-1 t))
3938 (defun message-insert-citation-line ()
3939 "Insert a simple citation line."
3940 (when message-reply-headers
3941 (insert (mail-header-from message-reply-headers) " writes:")
3945 (defun message-position-on-field (header &rest afters)
3946 (let ((case-fold-search t))
3949 (goto-char (point-min))
3952 (concat "^" (regexp-quote mail-header-separator) "$"))
3953 (match-beginning 0)))
3954 (goto-char (point-min))
3955 (if (re-search-forward (concat "^" (regexp-quote header) ":") nil t)
3957 (re-search-forward "^[^ \t]" nil 'move)
3959 (skip-chars-backward "\n")
3962 (not (re-search-forward
3963 (concat "^" (regexp-quote (car afters)) ":")
3967 (re-search-forward "^[^ \t]" nil 'move)
3968 (beginning-of-line))
3969 (insert header ": \n")
3973 (defun message-remove-signature ()
3974 "Remove the signature from the text between point and mark.
3975 The text will also be indented the normal way."
3977 (let ((start (point))
3979 (if (not (re-search-forward message-signature-separator (mark t) t))
3980 ;; No signature here, so we just indent the cited text.
3981 (message-indent-citation)
3982 ;; Find the last non-empty line.
3984 (while (looking-at "[ \t]*$")
3987 (setq mark (set-marker (make-marker) (point)))
3989 (message-indent-citation)
3990 ;; Enable undoing the deletion.
3992 (delete-region mark (mark t))
3993 (set-marker mark nil)))))
3998 ;;; Sending messages
4001 (defun message-send-and-exit (&optional arg)
4002 "Send message like `message-send', then, if no errors, exit from mail buffer."
4004 (let ((buf (current-buffer))
4005 (actions message-exit-actions))
4006 (when (and (message-send arg)
4009 (if message-kill-buffer-on-exit
4011 (message-do-actions actions)
4014 (defun message-dont-send ()
4015 "Don't send the message you have been editing.
4016 Instead, just auto-save the buffer and then bury it."
4018 (set-buffer-modified-p t)
4020 (let ((actions message-postpone-actions))
4021 (message-bury (current-buffer))
4022 (message-do-actions actions)))
4024 (defun message-kill-buffer ()
4025 "Kill the current buffer."
4027 (when (or (not (buffer-modified-p))
4028 (not message-kill-buffer-query)
4029 (yes-or-no-p "Message modified; kill anyway? "))
4030 (let ((actions message-kill-actions)
4031 (draft-article message-draft-article)
4032 (auto-save-file-name buffer-auto-save-file-name)
4033 (file-name buffer-file-name)
4034 (modified (buffer-modified-p)))
4035 (setq buffer-file-name nil)
4036 (kill-buffer (current-buffer))
4037 (when (and (or (and auto-save-file-name
4038 (file-exists-p auto-save-file-name))
4040 (file-exists-p file-name)))
4042 ;; If the message buffer has lived in a dedicated window,
4043 ;; `kill-buffer' has killed the frame. Thus the
4044 ;; `yes-or-no-p' may show up in a lowered frame. Make sure
4045 ;; that the user can see the question by raising the
4048 (yes-or-no-p (format "Remove the backup file%s? "
4049 (if modified " too" "")))))
4051 (delete-file auto-save-file-name))
4052 (let ((message-draft-article draft-article))
4053 (message-disassociate-draft)))
4054 (message-do-actions actions))))
4056 (defun message-bury (buffer)
4057 "Bury this mail BUFFER."
4058 (let ((newbuf (other-buffer buffer)))
4059 (bury-buffer buffer)
4060 (if message-return-action
4061 (apply (car message-return-action) (cdr message-return-action))
4062 (switch-to-buffer newbuf))))
4064 (defun message-send (&optional arg)
4065 "Send the message in the current buffer.
4066 If `message-interactive' is non-nil, wait for success indication or
4067 error messages, and inform user.
4068 Otherwise any failure is reported in a message back to the user from
4070 The usage of ARG is defined by the instance that called Message.
4071 It should typically alter the sending method in some way or other."
4073 ;; Make it possible to undo the coming changes.
4075 (let ((inhibit-read-only t))
4076 (put-text-property (point-min) (point-max) 'read-only nil))
4077 (message-fix-before-sending)
4078 (run-hooks 'message-send-hook)
4079 (when message-confirm-send
4080 (or (y-or-n-p "Send message? ")
4082 (message message-sending-message)
4083 (let ((alist message-send-method-alist)
4085 elem sent dont-barf-on-no-method
4086 (message-options message-options))
4087 (message-options-set-recipient)
4089 (setq elem (pop alist)))
4090 (when (funcall (cadr elem))
4091 (when (and (or (not (memq (car elem)
4092 message-sent-message-via))
4093 (message-fetch-field "supersedes")
4094 (if (or (message-gnksa-enable-p 'multiple-copies)
4095 (not (eq (car elem) 'news)))
4098 "Already sent message via %s; resend? "
4100 (error "Denied posting -- multiple copies")))
4101 (setq success (funcall (caddr elem) arg)))
4105 (let ((fcc (message-fetch-field "Fcc"))
4106 (gcc (message-fetch-field "Gcc")))
4108 (or (eq message-allow-no-recipients 'always)
4109 (and (not (eq message-allow-no-recipients 'never))
4110 (setq dont-barf-on-no-method
4112 (format "No receiver, perform %s anyway? "
4113 (cond ((and fcc gcc) "Fcc and Gcc")
4116 (error "No methods specified to send by"))
4117 (when (or dont-barf-on-no-method
4121 (run-hooks 'message-sent-hook))
4122 (message "Sending...done")
4123 ;; Do ecomplete address snarfing.
4124 (when (and (message-mail-alias-type-p 'ecomplete)
4125 (not message-inhibit-ecomplete))
4126 (message-put-addresses-in-ecomplete))
4127 ;; Mark the buffer as unmodified and delete auto-save.
4128 (set-buffer-modified-p nil)
4129 (delete-auto-save-file-if-necessary t)
4130 (message-disassociate-draft)
4131 ;; Delete other mail buffers and stuff.
4132 (message-do-send-housekeeping)
4133 (message-do-actions message-send-actions)
4137 (defun message-send-via-mail (arg)
4138 "Send the current message via mail."
4139 (message-send-mail arg))
4141 (defun message-send-via-news (arg)
4142 "Send the current message via news."
4143 (funcall message-send-news-function arg))
4145 (defmacro message-check (type &rest forms)
4146 "Eval FORMS if TYPE is to be checked."
4147 `(or (message-check-element ,type)
4151 (put 'message-check 'lisp-indent-function 1)
4152 (put 'message-check 'edebug-form-spec '(form body))
4154 (defun message-text-with-property (prop &optional start end reverse)
4155 "Return a list of start and end positions where the text has PROP.
4156 START and END bound the search, they default to `point-min' and
4157 `point-max' respectively. If REVERSE is non-nil, find text which does
4160 (setq start (point-min)))
4162 (setq end (point-max)))
4166 (setq start (text-property-any start end prop nil)))
4167 (setq next (next-single-property-change start prop nil end))
4168 (push (cons start (or next end)) regions)
4171 (or (get-text-property start prop)
4172 (and (setq start (next-single-property-change
4173 start prop nil end))
4174 (get-text-property start prop))))
4175 (setq next (text-property-any start end prop nil))
4176 (push (cons start (or next end)) regions)
4178 (nreverse regions)))
4180 (defcustom message-bogus-addresses
4181 '("noreply" "nospam" "invalid" "@@" "[^[:ascii:]].*@" "[ \t]")
4182 "List of regexps of potentially bogus mail addresses.
4183 See `message-check-recipients' how to setup checking.
4185 This list should make it possible to catch typos or warn about
4186 spam-trap addresses. It doesn't aim to verify strict RFC
4188 :version "23.1" ;; No Gnus
4189 :group 'message-headers
4191 (const :tag "None" nil)
4197 (const :tag "duplicate @" "@@")
4198 (const :tag "non-ascii local part" "[^[:ascii:]].*@")
4199 ;; Already caught by `message-valid-fqdn-regexp'
4200 ;; (const :tag "`_' in domain part" "@.*_")
4201 (const :tag "whitespace" "[ \t]"))
4206 (defun message-fix-before-sending ()
4207 "Do various things to make the message nice before sending it."
4208 ;; Make sure there's a newline at the end of the message.
4209 (goto-char (point-max))
4212 ;; Make the hidden headers visible.
4214 ;; Sort headers before sending the message.
4215 (message-sort-headers)
4216 ;; Make invisible text visible.
4217 ;; It doesn't seem as if this is useful, since the invisible property
4218 ;; is clobbered by an after-change hook anyhow.
4219 (message-check 'invisible-text
4220 (let ((regions (message-text-with-property 'invisible))
4224 (setq from (caar regions)
4226 regions (cdr regions))
4227 (put-text-property from to 'invisible nil)
4228 (message-overlay-put (message-make-overlay from to)
4230 (unless (yes-or-no-p
4231 "Invisible text found and made visible; continue sending? ")
4232 (error "Invisible text found and made visible")))))
4233 (message-check 'illegible-text
4234 (let (char found choice)
4237 (skip-chars-forward mm-7bit-chars)
4238 (when (get-text-property (point) 'no-illegible-text)
4239 ;; There is a signed or encrypted raw message part
4240 ;; that is considered to be safe.
4241 (goto-char (or (next-single-property-change
4242 (point) 'no-illegible-text)
4244 (setq char (char-after)))
4245 (when (or (< (mm-char-int char) 128)
4246 (and (mm-multibyte-p)
4247 (memq (char-charset char)
4248 '(eight-bit-control eight-bit-graphic
4249 ;; Emacs 23, Bug#1770:
4252 (not (get-text-property
4253 (point) 'untranslated-utf-8))))
4254 (message-overlay-put (message-make-overlay (point) (1+ (point)))
4260 (gnus-multiple-choice
4261 "Non-printable characters found. Continue sending?"
4262 `((?d "Remove non-printable characters and send")
4264 "Replace non-printable characters with \"%s\" and send"
4265 message-replacement-char))
4266 (?s "Send as is without removing anything")
4267 (?e "Continue editing"))))
4269 (error "Non-printable characters"))
4271 (skip-chars-forward mm-7bit-chars)
4273 (when (let ((char (char-after)))
4274 (or (< (mm-char-int char) 128)
4275 (and (mm-multibyte-p)
4276 ;; FIXME: Wrong for Emacs 23 (unicode) and for
4277 ;; things like undecodable utf-8 (in Emacs 21?).
4278 ;; Should at least use find-coding-systems-region.
4280 (memq (char-charset char)
4281 '(eight-bit-control eight-bit-graphic
4282 ;; Emacs 23, Bug#1770:
4285 (not (get-text-property
4286 (point) 'untranslated-utf-8)))))
4288 (message-kill-all-overlays)
4290 (when (eq choice ?r)
4291 (insert message-replacement-char))))
4293 (skip-chars-forward mm-7bit-chars)))))
4294 (message-check 'bogus-recipient
4295 ;; Warn before sending a mail to an invalid address.
4296 (message-check-recipients)))
4298 (defun message-bogus-recipient-p (recipients)
4299 "Check if a mail address in RECIPIENTS looks bogus.
4301 RECIPIENTS is a mail header. Return a list of potentially bogus
4302 addresses. If none is found, return nil.
4304 An address might be bogus if the domain part is not fully
4305 qualified, see `message-valid-fqdn-regexp', or if there's a
4306 matching entry in `message-bogus-addresses'."
4307 ;; FIXME: How about "foo@subdomain", when the MTA adds ".domain.tld"?
4309 (mapc (lambda (address)
4310 (setq address (or (cadr address) ""))
4312 (or (string= "" address)
4315 (not (string-match "@" address))
4318 message-valid-fqdn-regexp "\\)\\'") address)))
4319 (and message-bogus-addresses
4321 (if (listp message-bogus-addresses)
4322 (mapconcat 'identity
4323 message-bogus-addresses
4325 message-bogus-addresses)))
4326 (string-match re address))))
4327 (push address found)))
4329 (mail-extract-address-components recipients t))
4332 (defun message-check-recipients ()
4333 "Warn before composing or sending a mail to an invalid address.
4335 This function could be useful in `message-setup-hook'."
4338 (message-narrow-to-headers)
4339 (dolist (hdr '("To" "Cc" "Bcc"))
4340 (let ((addr (message-fetch-field hdr)))
4341 (when (stringp addr)
4342 (dolist (bog (message-bogus-recipient-p addr))
4346 "Address `%s'%s might be bogus. Continue? "
4348 ;; If the encoded version of the email address
4349 ;; is different from the unencoded version,
4350 ;; then we likely have invisible characters or
4351 ;; the like. Display the encoded version,
4353 (let ((encoded (rfc2047-encode-string bog)))
4354 (if (string= encoded bog)
4356 (format " (%s)" encoded))))))
4357 (error "Bogus address"))))))))
4359 (custom-add-option 'message-setup-hook 'message-check-recipients)
4361 (defun message-add-action (action &rest types)
4362 "Add ACTION to be performed when doing an exit of type TYPES."
4364 (add-to-list (intern (format "message-%s-actions" (pop types)))
4367 (defun message-delete-action (action &rest types)
4368 "Delete ACTION from lists of actions performed when doing an exit of type TYPES."
4371 (set (setq var (intern (format "message-%s-actions" (pop types))))
4372 (delq action (symbol-value var))))))
4374 (defun message-do-actions (actions)
4375 "Perform all actions in ACTIONS."
4376 ;; Now perform actions on successful sending.
4377 (dolist (action actions)
4380 ;; A simple function.
4383 ;; Something to be evaled.
4387 (defun message-send-mail-partially ()
4388 "Send mail as message/partial."
4389 ;; replace the header delimiter with a blank line
4390 (goto-char (point-min))
4392 (concat "^" (regexp-quote mail-header-separator) "\n"))
4393 (replace-match "\n")
4394 (run-hooks 'message-send-mail-hook)
4395 (let ((p (goto-char (point-min)))
4396 (tembuf (message-generate-new-buffer-clone-locals " message temp"))
4397 (curbuf (current-buffer))
4398 (id (message-make-message-id)) (n 1)
4401 (if (< (point-max) (+ p message-send-mail-partially-limit))
4402 (goto-char (point-max))
4403 (goto-char (+ p message-send-mail-partially-limit))
4405 (if (<= (point) p) (forward-line 1))) ;; In case of bad message.
4408 (setq total (length plist))
4409 (push (point-max) plist)
4410 (setq plist (nreverse plist))
4413 (setq p (pop plist))
4416 (copy-to-buffer tembuf p (car plist))
4418 (goto-char (point-min))
4421 (goto-char (point-min))
4422 (narrow-to-region (point) (point))
4425 (setq header (buffer-substring (point-min) (point)))
4426 (goto-char (point-min))
4427 (narrow-to-region (point) (point))
4429 (message-remove-header "Mime-Version")
4430 (message-remove-header "Content-Type")
4431 (message-remove-header "Content-Transfer-Encoding")
4432 (message-remove-header "Message-ID")
4433 (message-remove-header "Lines")
4434 (goto-char (point-max))
4435 (insert "Mime-Version: 1.0\n")
4436 (setq header (buffer-string)))
4437 (goto-char (point-max))
4438 (insert (format "Content-Type: message/partial; id=\"%s\"; number=%d; total=%d\n\n"
4441 (let ((mail-header-separator ""))
4442 (when (memq 'Message-ID message-required-mail-headers)
4443 (insert "Message-ID: " (message-make-message-id) "\n"))
4444 (when (memq 'Lines message-required-mail-headers)
4445 (insert "Lines: " (message-make-lines) "\n"))
4446 (message-goto-subject)
4448 (insert (format " (%d/%d)" n total))
4450 (funcall (or message-send-mail-real-function
4451 message-send-mail-function)))
4453 (setq p (pop plist))
4455 (kill-buffer tembuf))))
4457 (declare-function hashcash-wait-async "hashcash" (&optional buffer))
4459 (defun message-send-mail (&optional arg)
4460 (require 'mail-utils)
4461 (let* ((tembuf (message-generate-new-buffer-clone-locals " message temp"))
4462 (case-fold-search nil)
4463 (news (message-news-p))
4464 (mailbuf (current-buffer))
4465 (message-this-is-mail t)
4466 ;; gnus-setup-posting-charset is autoloaded in mml.el (FIXME
4467 ;; maybe it should not be), which this file requires. Hence
4468 ;; the fboundp test is always true. Loading it from gnus-msg
4469 ;; loads many Gnus files (Bug#5642). If
4470 ;; gnus-group-posting-charset-alist hasn't been customized,
4471 ;; this is just going to return nil anyway. FIXME it would
4472 ;; be good to improve this further, because even if g-g-p-c-a
4473 ;; has been customized, that is likely to just be for news.
4474 ;; Eg either move the definition from gnus-msg, or separate out
4475 ;; the mail and news parts.
4476 (message-posting-charset
4477 (if (and (fboundp 'gnus-setup-posting-charset)
4478 (boundp 'gnus-group-posting-charset-alist))
4479 (gnus-setup-posting-charset nil)
4480 message-posting-charset))
4481 (headers message-required-mail-headers))
4482 (when (and message-generate-hashcash
4483 (not (eq message-generate-hashcash 'opportunistic)))
4484 (message "Generating hashcash...")
4486 ;; Wait for calculations already started to finish...
4487 (hashcash-wait-async)
4488 ;; ...and do calculations not already done. mail-add-payment
4489 ;; will leave existing X-Hashcash headers alone.
4491 (message "Generating hashcash...done"))
4493 (message-narrow-to-headers)
4494 ;; Generate the Mail-Followup-To header if the header is not there...
4495 (if (and (message-subscribed-p)
4496 (not (mail-fetch-field "mail-followup-to")))
4499 (cons "Mail-Followup-To" (message-make-mail-followup-to))
4500 message-required-mail-headers))
4501 ;; otherwise, delete the MFT header if the field is empty
4502 (when (equal "" (mail-fetch-field "mail-followup-to"))
4503 (message-remove-header "^Mail-Followup-To:")))
4504 ;; Insert some headers.
4505 (let ((message-deletable-headers
4506 (if news nil message-deletable-headers)))
4507 (message-generate-headers headers))
4508 ;; Check continuation headers.
4509 (message-check 'continuation-headers
4510 (goto-char (point-min))
4511 (while (re-search-forward "^[^ \t\n][^ \t\n:]*[ \t\n]" nil t)
4512 (goto-char (match-beginning 0))
4513 (if (y-or-n-p "Fix continuation lines? ")
4516 (unless (y-or-n-p "Send anyway? ")
4517 (error "Failed to send the message")))))
4518 ;; Let the user do all of the above.
4519 (run-hooks 'message-header-hook))
4521 (with-current-buffer tembuf
4523 ;; Avoid copying text props (except hard newlines).
4524 (insert (with-current-buffer mailbuf
4525 (mml-buffer-substring-no-properties-except-hard-newlines
4526 (point-min) (point-max))))
4527 ;; Remove some headers.
4528 (message-encode-message-body)
4530 (message-narrow-to-headers)
4531 ;; We (re)generate the Lines header.
4532 (when (memq 'Lines message-required-mail-headers)
4533 (message-generate-headers '(Lines)))
4534 ;; Remove some headers.
4535 (message-remove-header message-ignored-mail-headers t)
4536 (let ((mail-parse-charset message-default-charset))
4537 (mail-encode-encoded-word-buffer)))
4538 (goto-char (point-max))
4539 ;; require one newline at the end.
4540 (or (= (preceding-char) ?\n)
4542 (message-cleanup-headers)
4543 ;; FIXME: we're inserting the courtesy copy after encoding.
4544 ;; This is wrong if the courtesy copy string contains
4545 ;; non-ASCII characters. -- jh
4548 (message-narrow-to-headers)
4550 (not (message-fetch-field "List-Post"))
4551 (not (message-fetch-field "List-ID"))
4552 (or (message-fetch-field "cc")
4553 (message-fetch-field "bcc")
4554 (message-fetch-field "to"))
4555 (let ((content-type (message-fetch-field
4560 (string= "text/plain"
4562 (mail-header-parse-content-type
4566 (message-fetch-field
4567 "content-transfer-encoding")))))))
4568 (message-insert-courtesy-copy
4569 (with-current-buffer mailbuf
4570 message-courtesy-message)))
4571 ;; Let's make sure we encoded all the body.
4572 (assert (save-excursion
4573 (goto-char (point-min))
4574 (not (re-search-forward "[^\000-\377]" nil t))))
4575 (mm-disable-multibyte)
4576 (if (or (not message-send-mail-partially-limit)
4577 (< (buffer-size) message-send-mail-partially-limit)
4578 (not (message-y-or-n-p
4579 "The message size is too large, split? "
4583 (/ (buffer-size) 1000) "KB, is too large.
4585 Some mail gateways (MTA's) bounce large messages. To avoid the
4586 problem, answer `y', and the message will be split into several
4587 smaller pieces, the size of each is about "
4588 (/ message-send-mail-partially-limit 1000)
4592 However, some mail readers (MUA's) can't read split messages, i.e.,
4593 mails in message/partially format. Answer `n', and the message will be
4596 The size limit is controlled by `message-send-mail-partially-limit'.
4597 If you always want Gnus to send messages in one piece, set
4598 `message-send-mail-partially-limit' to nil.
4601 (message "Sending via mail...")
4602 (funcall (or message-send-mail-real-function
4603 message-send-mail-function)))
4604 (message-send-mail-partially)))
4605 (kill-buffer tembuf))
4606 (set-buffer mailbuf)
4607 (push 'mail message-sent-message-via)))
4609 (defun message-send-mail-with-sendmail ()
4610 "Send off the prepared buffer with sendmail."
4612 (let ((errbuf (if message-interactive
4613 (message-generate-new-buffer-clone-locals
4616 resend-to-addresses delimline)
4619 (let ((case-fold-search t))
4621 (message-narrow-to-headers)
4622 (setq resend-to-addresses (message-fetch-field "resent-to")))
4623 ;; Change header-delimiter to be what sendmail expects.
4624 (goto-char (point-min))
4626 (concat "^" (regexp-quote mail-header-separator) "\n"))
4627 (replace-match "\n")
4629 (setq delimline (point-marker))
4630 (run-hooks 'message-send-mail-hook)
4631 ;; Insert an extra newline if we need it to work around
4632 ;; Sun's bug that swallows newlines.
4633 (goto-char (1+ delimline))
4634 (when (eval message-mailer-swallows-blank-line)
4636 (when message-interactive
4637 (with-current-buffer errbuf
4639 (let* ((default-directory "/")
4640 (coding-system-for-write message-send-coding-system)
4642 'call-process-region
4644 (list (point-min) (point-max)
4645 (cond ((boundp 'sendmail-program)
4647 ((file-exists-p "/usr/sbin/sendmail")
4648 "/usr/sbin/sendmail")
4649 ((file-exists-p "/usr/lib/sendmail")
4650 "/usr/lib/sendmail")
4651 ((file-exists-p "/usr/ucblib/sendmail")
4652 "/usr/ucblib/sendmail")
4654 nil errbuf nil "-oi")
4655 message-sendmail-extra-arguments
4656 ;; Always specify who from,
4657 ;; since some systems have broken sendmails.
4658 ;; But some systems are more broken with -f, so
4659 ;; we'll let users override this.
4660 (and (null message-sendmail-f-is-evil)
4661 (list "-f" (message-sendmail-envelope-from)))
4662 ;; These mean "report errors by mail"
4663 ;; and "deliver in background".
4664 (if (null message-interactive) '("-oem" "-odb"))
4665 ;; Get the addresses from the message
4666 ;; unless this is a resend.
4667 ;; We must not do that for a resend
4668 ;; because we would find the original addresses.
4669 ;; For a resend, include the specific addresses.
4670 (if resend-to-addresses
4671 (list resend-to-addresses)
4673 (unless (or (null cpr) (and (numberp cpr) (zerop cpr)))
4674 (if errbuf (pop-to-buffer errbuf))
4675 (error "Sending...failed with exit value %d" cpr)))
4676 (when message-interactive
4677 (with-current-buffer errbuf
4678 (goto-char (point-min))
4679 (while (re-search-forward "\n+ *" nil t)
4680 (replace-match "; "))
4681 (if (not (zerop (buffer-size)))
4682 (error "Sending...failed to %s"
4683 (buffer-string))))))
4684 (when (bufferp errbuf)
4685 (kill-buffer errbuf)))))
4687 (defun message-send-mail-with-qmail ()
4688 "Pass the prepared message buffer to qmail-inject.
4689 Refer to the documentation for the variable `message-send-mail-function'
4690 to find out how to use this."
4691 ;; replace the header delimiter with a blank line
4692 (goto-char (point-min))
4694 (concat "^" (regexp-quote mail-header-separator) "\n"))
4695 (replace-match "\n")
4696 (run-hooks 'message-send-mail-hook)
4699 (let ((coding-system-for-write message-send-coding-system))
4701 'call-process-region (point-min) (point-max)
4702 message-qmail-inject-program nil nil nil
4703 ;; qmail-inject's default behavior is to look for addresses on the
4704 ;; command line; if there're none, it scans the headers.
4705 ;; yes, it does The Right Thing w.r.t. Resent-To and it's kin.
4707 ;; in general, ALL of qmail-inject's defaults are perfect for simply
4708 ;; reading a formatted (i. e., at least a To: or Resent-To header)
4709 ;; message from stdin.
4711 ;; qmail also has the advantage of not having been raped by
4712 ;; various vendors, so we don't have to allow for that, either --
4713 ;; compare this with message-send-mail-with-sendmail and weep
4714 ;; for sendmail's lost innocence.
4716 ;; all this is way cool coz it lets us keep the arguments entirely
4717 ;; free for -inject-arguments -- a big win for the user and for us
4718 ;; since we don't have to play that double-guessing game and the user
4719 ;; gets full control (no gestapo'ish -f's, for instance). --sj
4720 (if (functionp message-qmail-inject-args)
4721 (funcall message-qmail-inject-args)
4722 message-qmail-inject-args)))
4723 ;; qmail-inject doesn't say anything on it's stdout/stderr,
4724 ;; we have to look at the retval instead
4726 (100 (error "qmail-inject reported permanent failure"))
4727 (111 (error "qmail-inject reported transient failure"))
4728 ;; should never happen
4729 (t (error "qmail-inject reported unknown failure"))))
4731 (defvar mh-previous-window-config)
4733 (defun message-send-mail-with-mh ()
4734 "Send the prepared message buffer with mh."
4735 (let ((mh-previous-window-config nil)
4736 (name (mh-new-draft-name)))
4737 (setq buffer-file-name name)
4738 ;; MH wants to generate these headers itself.
4739 (when message-mh-deletable-headers
4740 (let ((headers message-mh-deletable-headers))
4742 (goto-char (point-min))
4743 (and (re-search-forward
4744 (concat "^" (symbol-name (car headers)) ": *") nil t)
4745 (message-delete-line))
4747 (run-hooks 'message-send-mail-hook)
4748 ;; Pass it on to mh.
4751 (defun message-smtpmail-send-it ()
4752 "Send the prepared message buffer with `smtpmail-send-it'.
4753 The only difference from `smtpmail-send-it' is that this command
4754 evaluates `message-send-mail-hook' just before sending a message.
4755 It is useful if your ISP requires the POP-before-SMTP
4756 authentication. See the Gnus manual for details."
4757 (run-hooks 'message-send-mail-hook)
4760 (defun message-send-mail-with-mailclient ()
4761 "Send the prepared message buffer with `mailclient-send-it'.
4762 The only difference from `mailclient-send-it' is that this
4763 command evaluates `message-send-mail-hook' just before sending a message."
4764 (run-hooks 'message-send-mail-hook)
4765 (mailclient-send-it))
4767 (defun message-canlock-generate ()
4768 "Return a string that is non-trivial to guess.
4769 Do not use this for anything important, it is cryptographically weak."
4771 (let (sha1-maximum-internal-length)
4772 (sha1 (concat (message-unique-id)
4773 (format "%x%x%x" (random) (random t) (random))
4774 (prin1-to-string (recent-keys))
4775 (prin1-to-string (garbage-collect))))))
4777 (defvar canlock-password)
4778 (defvar canlock-password-for-verify)
4780 (defun message-canlock-password ()
4781 "The password used by message for cancel locks.
4782 This is the value of `canlock-password', if that option is non-nil.
4783 Otherwise, generate and save a value for `canlock-password' first."
4785 (unless canlock-password
4786 (customize-save-variable 'canlock-password (message-canlock-generate))
4787 (setq canlock-password-for-verify canlock-password))
4790 (defun message-insert-canlock ()
4791 (when message-insert-canlock
4792 (message-canlock-password)
4793 (canlock-insert-header)))
4795 (autoload 'nnheader-get-report "nnheader")
4797 (declare-function gnus-setup-posting-charset "gnus-msg" (group))
4799 (defun message-send-news (&optional arg)
4801 (let* ((tembuf (message-generate-new-buffer-clone-locals " *message temp*"))
4802 (case-fold-search nil)
4803 (method (if (functionp message-post-method)
4804 (funcall message-post-method arg)
4805 message-post-method))
4806 (newsgroups-field (save-restriction
4807 (message-narrow-to-headers-or-head)
4808 (message-fetch-field "Newsgroups")))
4809 (followup-field (save-restriction
4810 (message-narrow-to-headers-or-head)
4811 (message-fetch-field "Followup-To")))
4812 ;; BUG: We really need to get the charset for each name in the
4813 ;; Newsgroups and Followup-To lines to allow crossposting
4814 ;; between group namess with incompatible character sets.
4815 ;; -- Per Abrahamsen <abraham@dina.kvl.dk> 2001-10-08.
4816 (group-field-charset
4817 (gnus-group-name-charset method newsgroups-field))
4818 (followup-field-charset
4819 (gnus-group-name-charset method (or followup-field "")))
4820 (rfc2047-header-encoding-alist
4821 (append (when group-field-charset
4822 (list (cons "Newsgroups" group-field-charset)))
4823 (when followup-field-charset
4824 (list (cons "Followup-To" followup-field-charset)))
4825 rfc2047-header-encoding-alist))
4826 (messbuf (current-buffer))
4827 (message-syntax-checks
4829 (listp message-syntax-checks))
4830 (cons '(existing-newsgroups . disabled)
4831 message-syntax-checks)
4832 message-syntax-checks))
4833 (message-this-is-news t)
4834 (message-posting-charset
4835 (gnus-setup-posting-charset newsgroups-field))
4837 (if (not (message-check-news-body-syntax))
4840 (message-narrow-to-headers)
4841 ;; Insert some headers.
4842 (message-generate-headers message-required-news-headers)
4843 (message-insert-canlock)
4844 ;; Let the user do all of the above.
4845 (run-hooks 'message-header-hook))
4846 ;; Note: This check will be disabled by the ".*" default value for
4847 ;; gnus-group-name-charset-group-alist. -- Pa 2001-10-07.
4848 (when (and group-field-charset
4849 (listp message-syntax-checks))
4850 (setq message-syntax-checks
4851 (cons '(valid-newsgroups . disabled)
4852 message-syntax-checks)))
4853 (message-cleanup-headers)
4854 (if (not (let ((message-post-method method))
4855 (message-check-news-syntax)))
4858 (with-current-buffer tembuf
4859 (buffer-disable-undo)
4861 ;; Avoid copying text props (except hard newlines).
4863 (with-current-buffer messbuf
4864 (mml-buffer-substring-no-properties-except-hard-newlines
4865 (point-min) (point-max))))
4866 (message-encode-message-body)
4867 ;; Remove some headers.
4869 (message-narrow-to-headers)
4870 ;; We (re)generate the Lines header.
4871 (when (memq 'Lines message-required-mail-headers)
4872 (message-generate-headers '(Lines)))
4873 ;; Remove some headers.
4874 (message-remove-header message-ignored-news-headers t)
4875 (let ((mail-parse-charset message-default-charset))
4876 (mail-encode-encoded-word-buffer)))
4877 (goto-char (point-max))
4878 ;; require one newline at the end.
4879 (or (= (preceding-char) ?\n)
4881 (let ((case-fold-search t))
4882 ;; Remove the delimiter.
4883 (goto-char (point-min))
4885 (concat "^" (regexp-quote mail-header-separator) "\n"))
4886 (replace-match "\n")
4888 (run-hooks 'message-send-news-hook)
4889 (gnus-open-server method)
4890 (message "Sending news via %s..." (gnus-server-string method))
4891 (setq result (let ((mail-header-separator ""))
4892 (gnus-request-post method))))
4893 (kill-buffer tembuf))
4894 (set-buffer messbuf)
4896 (push 'news message-sent-message-via)
4897 (message "Couldn't send message via news: %s"
4898 (nnheader-get-report (car method)))
4902 ;;; Header generation & syntax checking.
4905 (defun message-check-element (type)
4906 "Return non-nil if this TYPE is not to be checked."
4907 (if (eq message-syntax-checks 'dont-check-for-anything-just-trust-me)
4909 (let ((able (assq type message-syntax-checks)))
4911 (eq (cdr able) 'disabled)))))
4913 (defun message-check-news-syntax ()
4914 "Check the syntax of the message."
4918 ;; We narrow to the headers and check them first.
4921 (message-narrow-to-headers)
4922 (message-check-news-header-syntax))))))
4924 (defun message-check-news-header-syntax ()
4926 ;; Check Newsgroups header.
4927 (message-check 'newsgroups
4928 (let ((group (message-fetch-field "newsgroups")))
4931 (not (string-match "\\`[ \t]*\\'" group)))
4934 "The newsgroups field is empty or missing. Posting is denied.")))))
4935 ;; Check the Subject header.
4936 (message-check 'subject
4937 (let* ((case-fold-search t)
4938 (subject (message-fetch-field "subject")))
4941 (not (string-match "\\`[ \t]*\\'" subject)))
4944 "The subject field is empty or missing. Posting is denied.")))))
4945 ;; Check for commands in Subject.
4946 (message-check 'subject-cmsg
4947 (if (string-match "^cmsg " (message-fetch-field "subject"))
4949 "The control code \"cmsg\" is in the subject. Really post? ")
4951 ;; Check long header lines.
4952 (message-check 'long-header-lines
4956 (while (and (not found)
4957 (re-search-forward "^\\([^ \t:]+\\): " nil t))
4958 (if (> (- (point) (match-beginning 0)) 998)
4960 length (- (point) (match-beginning 0)))
4961 (setq header (match-string-no-properties 1)))
4964 (y-or-n-p (format "Your %s header is too long (%d). Really post? "
4967 ;; Check for multiple identical headers.
4968 (message-check 'multiple-headers
4970 (while (and (not found)
4971 (re-search-forward "^[^ \t:]+: " nil t))
4973 (or (re-search-forward
4978 (match-beginning 0) (- (match-end 0) 2))))
4983 (y-or-n-p (format "Multiple %s headers. Really post? " found))
4985 ;; Check for Version and Sendsys.
4986 (message-check 'sendsys
4987 (if (re-search-forward "^Sendsys:\\|^Version:" nil t)
4989 (format "The article contains a %s command. Really post? "
4990 (buffer-substring (match-beginning 0)
4991 (1- (match-end 0)))))
4993 ;; See whether we can shorten Followup-To.
4994 (message-check 'shorten-followup-to
4995 (let ((newsgroups (message-fetch-field "newsgroups"))
4996 (followup-to (message-fetch-field "followup-to"))
4998 (when (and newsgroups
4999 (string-match "," newsgroups)
5004 (setq to (completing-read
5005 "Followups to (default no Followup-To header): "
5008 (message-tokenize-header
5010 (goto-char (point-min))
5011 (insert "Followup-To: " to "\n"))
5013 ;; Check "Shoot me".
5014 (message-check 'shoot
5015 (if (re-search-forward
5016 "Message-ID.*.i-did-not-set--mail-host-address--so-tickle-me" nil t)
5017 (y-or-n-p "You appear to have a misconfigured system. Really post? ")
5019 ;; Check for Approved.
5020 (message-check 'approved
5021 (if (re-search-forward "^Approved:" nil t)
5022 (y-or-n-p "The article contains an Approved header. Really post? ")
5024 ;; Check the Message-ID header.
5025 (message-check 'message-id
5026 (let* ((case-fold-search t)
5027 (message-id (message-fetch-field "message-id" t)))
5028 (or (not message-id)
5029 ;; Is there an @ in the ID?
5030 (and (string-match "@" message-id)
5031 ;; Is there a dot in the ID?
5032 (string-match "@[^.]*\\." message-id)
5033 ;; Does the ID end with a dot?
5034 (not (string-match "\\.>" message-id)))
5036 (format "The Message-ID looks strange: \"%s\". Really post? "
5038 ;; Check the Newsgroups & Followup-To headers.
5039 (message-check 'existing-newsgroups
5040 (let* ((case-fold-search t)
5041 (newsgroups (message-fetch-field "newsgroups"))
5042 (followup-to (message-fetch-field "followup-to"))
5043 (groups (message-tokenize-header
5045 (concat newsgroups "," followup-to)
5047 (post-method (if (functionp message-post-method)
5048 (funcall message-post-method)
5049 message-post-method))
5050 ;; KLUDGE to handle nnvirtual groups. Doing this right
5051 ;; would probably involve a new nnoo function.
5052 ;; -- Per Abrahamsen <abraham@dina.kvl.dk>, 2001-10-17.
5053 (method (if (and (consp post-method)
5054 (eq (car post-method) 'nnvirtual)
5055 gnus-message-group-art)
5056 (let ((group (car (nnvirtual-find-group-art
5057 (car gnus-message-group-art)
5058 (cdr gnus-message-group-art)))))
5059 (gnus-find-method-for-group group))
5063 (gnus-group-name-decode
5064 (gnus-group-real-name n)
5065 (gnus-group-name-charset method n)))
5066 (gnus-groups-from-server method)))
5069 (when (and (not (equal (car groups) "poster"))
5070 (not (member (car groups) known-groups))
5071 (not (member (car groups) errors)))
5072 (push (car groups) errors))
5075 ;; Gnus is not running.
5076 ((or (not (and (boundp 'gnus-active-hashtb)
5077 gnus-active-hashtb))
5078 (not (boundp 'gnus-read-active-file)))
5080 ;; We don't have all the group names.
5081 ((and (or (not gnus-read-active-file)
5082 (eq gnus-read-active-file 'some))
5086 "Really use %s possibly unknown group%s: %s? "
5087 (if (= (length errors) 1) "this" "these")
5088 (if (= (length errors) 1) "" "s")
5089 (mapconcat 'identity errors ", "))))
5090 ;; There were no errors.
5093 ;; There are unknown groups.
5097 "Really post to %s unknown group%s: %s? "
5098 (if (= (length errors) 1) "this" "these")
5099 (if (= (length errors) 1) "" "s")
5100 (mapconcat 'identity errors ", ")))))))
5101 ;; Check continuation headers.
5102 (message-check 'continuation-headers
5103 (goto-char (point-min))
5104 (let ((do-posting t))
5105 (while (re-search-forward "^[^ \t\n][^ \t\n:]*[ \t\n]" nil t)
5106 (goto-char (match-beginning 0))
5107 (if (y-or-n-p "Fix continuation lines? ")
5110 (unless (y-or-n-p "Send anyway? ")
5111 (setq do-posting nil))))
5113 ;; Check the Newsgroups & Followup-To headers for syntax errors.
5114 (message-check 'valid-newsgroups
5115 (let ((case-fold-search t)
5116 (headers '("Newsgroups" "Followup-To"))
5118 (while (and headers (not error))
5119 (when (setq header (mail-fetch-field (car headers)))
5123 "\\`\\([-+_&.a-zA-Z0-9]+\\)?\\(,[-+_&.a-zA-Z0-9]+\\)*\\'"
5128 (not (string-match "\\.\\'\\|\\.\\." g)))
5129 (message-tokenize-header header ","))))
5136 (format "The %s header looks odd: \"%s\". Really post? "
5137 (car headers) header)))))
5138 (message-check 'repeated-newsgroups
5139 (let ((case-fold-search t)
5140 (headers '("Newsgroups" "Followup-To"))
5141 header error groups group)
5144 (when (setq header (mail-fetch-field (pop headers)))
5145 (setq groups (message-tokenize-header header ","))
5146 (while (setq group (pop groups))
5147 (when (member group groups)
5153 (format "Group %s is repeated in headers. Really post? " error)))))
5154 ;; Check the From header.
5155 (message-check 'from
5156 (let* ((case-fold-search t)
5157 (from (message-fetch-field "from"))
5161 (message "There is no From line. Posting is denied.")
5163 ((or (not (string-match
5165 (setq ad (nth 1 (mail-extract-address-components
5166 from))))) ;larsi@ifi
5167 (string-match "\\.\\." ad) ;larsi@ifi..uio
5168 (string-match "@\\." ad) ;larsi@.ifi.uio
5169 (string-match "\\.$" ad) ;larsi@ifi.uio.
5170 (not (string-match "^[^@]+@[^@]+$" ad)) ;larsi.ifi.uio
5171 (string-match "(.*).*(.*)" from)) ;(lars) (lars)
5173 "Denied posting -- the From looks strange: \"%s\"." from)
5175 ((let ((addresses (rfc822-addresses from)))
5176 ;; `rfc822-addresses' returns a string if parsing fails.
5177 (while (and (consp addresses)
5178 (not (eq (string-to-char (car addresses)) ?\()))
5179 (setq addresses (cdr addresses)))
5182 "Denied posting -- bad From address: \"%s\"." from)
5185 ;; Check the Reply-To header.
5186 (message-check 'reply-to
5187 (let* ((case-fold-search t)
5188 (reply-to (message-fetch-field "reply-to"))
5193 ((string-match "," reply-to)
5195 (format "Multiple Reply-To addresses: \"%s\". Really post? "
5197 ((or (not (string-match
5199 (setq ad (nth 1 (mail-extract-address-components
5200 reply-to))))) ;larsi@ifi
5201 (string-match "\\.\\." ad) ;larsi@ifi..uio
5202 (string-match "@\\." ad) ;larsi@.ifi.uio
5203 (string-match "\\.$" ad) ;larsi@ifi.uio.
5204 (not (string-match "^[^@]+@[^@]+$" ad)) ;larsi.ifi.uio
5205 (string-match "(.*).*(.*)" reply-to)) ;(lars) (lars)
5208 "The Reply-To looks strange: \"%s\". Really post? "
5212 (defun message-check-news-body-syntax ()
5214 ;; Check for long lines.
5215 (message-check 'long-lines
5216 (goto-char (point-min))
5218 (concat "^" (regexp-quote mail-header-separator) "$"))
5222 "<#\\(/\\)?\\(multipart\\|part\\|external\\|mml\\)")
5225 (< (- (point) p) 80)))
5226 (zerop (forward-line 1))))
5230 "You have lines longer than 79 characters. Really post? ")))
5231 ;; Check whether the article is empty.
5232 (message-check 'empty
5233 (goto-char (point-min))
5235 (concat "^" (regexp-quote mail-header-separator) "$"))
5238 (goto-char (point-max))
5239 (re-search-backward message-signature-separator nil t)
5241 (or (re-search-backward "[^ \n\t]" b t)
5242 (if (message-gnksa-enable-p 'empty-article)
5243 (y-or-n-p "Empty article. Really post? ")
5244 (message "Denied posting -- Empty article.")
5246 ;; Check for control characters.
5247 (message-check 'control-chars
5248 (if (re-search-forward
5249 (mm-string-to-multibyte "[\000-\007\013\015-\032\034-\037\200-\237]")
5252 "The article contains control characters. Really post? ")
5254 ;; Check excessive size.
5255 (message-check 'size
5256 (if (> (buffer-size) 60000)
5258 (format "The article is %d octets long. Really post? "
5261 ;; Check whether any new text has been added.
5262 (message-check 'new-text
5264 (not message-checksum)
5265 (not (eq (message-checksum) message-checksum))
5266 (if (message-gnksa-enable-p 'quoted-text-only)
5268 "It looks like no new text has been added. Really post? ")
5269 (message "Denied posting -- no new text has been added.")
5271 ;; Check the length of the signature.
5272 (message-check 'signature
5273 (let (sig-start sig-end)
5274 (goto-char (point-max))
5275 (if (not (re-search-backward message-signature-separator nil t))
5277 (setq sig-start (1+ (point-at-eol)))
5279 (if (re-search-forward
5280 "<#/?\\(multipart\\|part\\|external\\|mml\\)" nil t)
5281 (- (point-at-bol) 1)
5283 (if (>= (count-lines sig-start sig-end) 5)
5284 (if (message-gnksa-enable-p 'signature)
5286 (format "Signature is excessively long (%d lines). Really post? "
5287 (count-lines sig-start sig-end)))
5288 (message "Denied posting -- Excessive signature.")
5291 ;; Ensure that text follows last quoted portion.
5292 (message-check 'quoting-style
5293 (goto-char (point-max))
5294 (let ((no-problem t))
5295 (when (search-backward-regexp "^>[^\n]*\n" nil t)
5296 (setq no-problem (search-forward-regexp "^[ \t]*[^>\n]" nil t)))
5299 (if (message-gnksa-enable-p 'quoted-text-only)
5300 (y-or-n-p "Your text should follow quoted text. Really post? ")
5302 (goto-char (point-min))
5304 (concat "^" (regexp-quote mail-header-separator) "$"))
5305 (if (search-forward-regexp "^[ \t]*[^>\n]" nil t)
5306 (y-or-n-p "Your text should follow quoted text. Really post? ")
5307 (message "Denied posting -- only quoted text.")
5310 (defun message-checksum ()
5311 "Return a \"checksum\" for the current buffer."
5314 (goto-char (point-min))
5316 (concat "^" (regexp-quote mail-header-separator) "$"))
5318 (when (not (looking-at "[ \t\n]"))
5319 (setq sum (logxor (ash sum 1) (if (natnump sum) 0 1)
5324 (defun message-do-fcc ()
5325 "Process Fcc headers in the current buffer."
5326 (let ((case-fold-search t)
5327 (buf (current-buffer))
5329 (mml-externalize-attachments message-fcc-externalize-attachments))
5332 (message-narrow-to-headers)
5333 (setq file (message-fetch-field "fcc" t)))
5335 (set-buffer (get-buffer-create " *message temp*"))
5337 (insert-buffer-substring buf)
5338 (message-encode-message-body)
5340 (message-narrow-to-headers)
5341 (while (setq file (message-fetch-field "fcc" t))
5343 (message-remove-header "fcc" nil t))
5344 (let ((mail-parse-charset message-default-charset)
5345 (rfc2047-header-encoding-alist
5346 (cons '("Newsgroups" . default)
5347 rfc2047-header-encoding-alist)))
5348 (mail-encode-encoded-word-buffer)))
5349 (goto-char (point-min))
5350 (when (re-search-forward
5351 (concat "^" (regexp-quote mail-header-separator) "$")
5353 (replace-match "" t t ))
5354 ;; Process FCC operations.
5356 (setq file (pop list))
5357 (if (string-match "^[ \t]*|[ \t]*\\(.*\\)[ \t]*$" file)
5358 ;; Pipe the article to the program in question.
5359 (call-process-region (point-min) (point-max) shell-file-name
5360 nil nil nil shell-command-switch
5361 (match-string 1 file))
5362 ;; Save the article.
5363 (setq file (expand-file-name file))
5364 (unless (file-exists-p (file-name-directory file))
5365 (make-directory (file-name-directory file) t))
5366 (if (and message-fcc-handler-function
5367 (not (eq message-fcc-handler-function 'rmail-output)))
5368 (funcall message-fcc-handler-function file)
5369 ;; FIXME this option, rmail-output (also used if
5370 ;; message-fcc-handler-function is nil) is not
5371 ;; documented anywhere AFAICS. It should work in Emacs
5372 ;; 23; I suspect it does not work in Emacs 22.
5373 ;; FIXME I don't see the need for the two different cases here.
5374 ;; mail-use-rfc822 makes no difference (in Emacs 23),and
5375 ;; the third argument just controls \"Wrote file\" message.
5376 (if (and (file-readable-p file) (mail-file-babyl-p file))
5377 (rmail-output file 1 nil t)
5378 (let ((mail-use-rfc822 t))
5379 (rmail-output file 1 t t))))))
5380 (kill-buffer (current-buffer))))))
5382 (defun message-output (filename)
5383 "Append this article to Unix/babyl mail file FILENAME."
5384 (if (or (and (file-readable-p filename)
5385 (mail-file-babyl-p filename))
5386 ;; gnus-output-to-mail does the wrong thing with live, mbox
5387 ;; Rmail buffers in Emacs 23.
5388 ;; http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=597255
5389 (let ((buff (find-buffer-visiting filename)))
5390 (and buff (with-current-buffer buff
5391 (eq major-mode 'rmail-mode)))))
5392 (gnus-output-to-rmail filename t)
5393 (gnus-output-to-mail filename t)))
5395 (defun message-cleanup-headers ()
5396 "Do various automatic cleanups of the headers."
5397 ;; Remove empty lines in the header.
5399 (message-narrow-to-headers)
5400 ;; Remove blank lines.
5401 (while (re-search-forward "^[ \t]*\n" nil t)
5402 (replace-match "" t t))
5404 ;; Correct Newsgroups and Followup-To headers: Change sequence of
5405 ;; spaces to comma and eliminate spaces around commas. Eliminate
5406 ;; embedded line breaks.
5407 (goto-char (point-min))
5408 (while (re-search-forward "^\\(Newsgroups\\|Followup-To\\): +" nil t)
5412 (if (re-search-forward "^[^ \t]" nil t)
5416 (goto-char (point-min))
5417 (while (re-search-forward "\n[ \t]+" nil t)
5418 (replace-match " " t t)) ;No line breaks (too confusing)
5419 (goto-char (point-min))
5420 (while (re-search-forward "[ \t\n]*,[ \t\n]*\\|[ \t]+" nil t)
5421 (replace-match "," t t))
5422 (goto-char (point-min))
5423 ;; Remove trailing commas.
5424 (when (re-search-forward ",+$" nil t)
5425 (replace-match "" t t))))))
5427 (defun message-make-date (&optional now)
5428 "Make a valid data header.
5429 If NOW, use that time instead."
5430 (let ((system-time-locale "C"))
5431 (format-time-string "%a, %d %b %Y %T %z" now)))
5433 (defun message-insert-expires (days)
5434 "Insert the Expires header. Expiry in DAYS days."
5435 (interactive "NExpire article in how many days? ")
5437 (message-position-on-field "Expires" "X-Draft-From")
5438 (insert (message-make-expires-date days))))
5440 (defun message-make-expires-date (days)
5441 "Make date string for the Expires header. Expiry in DAYS days.
5443 In posting styles use `(\"Expires\" (make-expires-date 30))'."
5444 (let* ((cur (decode-time (current-time)))
5445 (nday (+ days (nth 3 cur))))
5446 (setf (nth 3 cur) nday)
5447 (message-make-date (apply 'encode-time cur))))
5449 (defun message-make-message-id ()
5450 "Make a unique Message-ID."
5451 (concat "<" (message-unique-id)
5452 (let ((psubject (save-excursion (message-fetch-field "subject")))
5454 (save-excursion (message-fetch-field "supersedes"))))
5456 (and message-reply-headers
5457 (mail-header-references message-reply-headers)
5458 (mail-header-subject message-reply-headers)
5461 (message-strip-subject-re
5462 (mail-header-subject message-reply-headers))
5463 (message-strip-subject-re psubject))))
5465 (string-match "_-_@" psupersedes)))
5467 "@" (message-make-fqdn) ">"))
5469 (defvar message-unique-id-char nil)
5471 ;; If you ever change this function, make sure the new version
5472 ;; cannot generate IDs that the old version could.
5473 ;; You might for example insert a "." somewhere (not next to another dot
5474 ;; or string boundary), or modify the "fsf" string.
5475 (defun message-unique-id ()
5476 ;; Don't use microseconds from (current-time), they may be unsupported.
5477 ;; Instead we use this randomly inited counter.
5478 (setq message-unique-id-char
5479 (% (1+ (or message-unique-id-char (logand (random t) (1- (lsh 1 20)))))
5480 ;; (current-time) returns 16-bit ints,
5481 ;; and 2^16*25 just fits into 4 digits i base 36.
5483 (let ((tm (current-time)))
5485 (if (or (eq system-type 'ms-dos)
5486 ;; message-number-base36 doesn't handle bigints.
5487 (floatp (user-uid)))
5488 (let ((user (downcase (user-login-name))))
5489 (while (string-match "[^a-z0-9_]" user)
5490 (aset user (match-beginning 0) ?_))
5492 (message-number-base36 (user-uid) -1))
5493 (message-number-base36 (+ (car tm)
5494 (lsh (% message-unique-id-char 25) 16)) 4)
5495 (message-number-base36 (+ (nth 1 tm)
5496 (lsh (/ message-unique-id-char 25) 16)) 4)
5497 ;; Append a given name, because while the generated ID is unique
5498 ;; to this newsreader, other newsreaders might otherwise generate
5499 ;; the same ID via another algorithm.
5502 (defun message-number-base36 (num len)
5507 (concat (message-number-base36 (/ num 36) (1- len))
5508 (char-to-string (aref "zyxwvutsrqponmlkjihgfedcba9876543210"
5511 (defun message-make-organization ()
5512 "Make an Organization header."
5513 (let* ((organization
5514 (when message-user-organization
5515 (if (functionp message-user-organization)
5516 (funcall message-user-organization)
5517 message-user-organization))))
5519 (mm-enable-multibyte)
5520 (cond ((stringp organization)
5521 (insert organization))
5522 ((and (eq t organization)
5523 message-user-organization-file
5524 (file-exists-p message-user-organization-file))
5525 (insert-file-contents message-user-organization-file)))
5526 (goto-char (point-min))
5527 (while (re-search-forward "[\t\n]+" nil t)
5528 (replace-match "" t t))
5529 (unless (zerop (buffer-size))
5532 (defun message-make-lines ()
5533 "Count the number of lines and return numeric string."
5538 (int-to-string (count-lines (point) (point-max))))))
5540 (defun message-make-references ()
5541 "Return the References header for this message."
5542 (when message-reply-headers
5543 (let ((message-id (mail-header-id message-reply-headers))
5544 (references (mail-header-references message-reply-headers)))
5545 (if (or references message-id)
5546 (concat (or references "") (and references " ")
5550 (defun message-make-in-reply-to ()
5551 "Return the In-Reply-To header for this message."
5552 (when message-reply-headers
5553 (let ((from (mail-header-from message-reply-headers))
5554 (date (mail-header-date message-reply-headers))
5555 (msg-id (mail-header-id message-reply-headers)))
5557 (let ((name (mail-extract-address-components from)))
5559 msg-id (if msg-id " (")
5561 (if (string-match "[^\000-\177]" (car name))
5562 ;; Quote a string containing non-ASCII characters.
5563 ;; It will make the RFC2047 encoder cause an error
5564 ;; if there are special characters.
5565 (mm-with-multibyte-buffer
5567 (goto-char (point-min))
5568 (while (search-forward "\"" nil t)
5571 (zerop (% (skip-chars-backward "\\\\") 2))
5572 (goto-char (match-beginning 0)))
5575 ;; Those quotes will be removed by the RFC2047 encoder.
5576 (concat "\"" (buffer-string) "\""))
5580 (if (or (not date) (string= date ""))
5581 "(unknown date)" date)
5582 "\"" (if msg-id ")")))))))
5584 (defun message-make-distribution ()
5585 "Make a Distribution header."
5586 (let ((orig-distribution (message-fetch-reply-field "distribution")))
5587 (cond ((functionp message-distribution-function)
5588 (funcall message-distribution-function))
5589 (t orig-distribution))))
5591 (defun message-make-expires ()
5592 "Return an Expires header based on `message-expires'."
5593 (let ((current (current-time))
5594 (future (* 1.0 message-expires 60 60 24)))
5595 ;; Add the future to current.
5596 (setcar current (+ (car current) (round (/ future (expt 2 16)))))
5597 (setcar (cdr current) (+ (nth 1 current) (% (round future) (expt 2 16))))
5598 (message-make-date current)))
5600 (defun message-make-path ()
5602 (let ((login-name (user-login-name)))
5603 (cond ((null message-user-path)
5604 (concat (system-name) "!" login-name))
5605 ((stringp message-user-path)
5606 ;; Support GENERICPATH. Suggested by vixie@decwrl.dec.com.
5607 (concat message-user-path "!" login-name))
5610 (defun message-make-from (&optional name address)
5611 "Make a From header."
5612 (let* ((style message-from-style)
5613 (login (or address (message-make-address)))
5615 (and (boundp 'user-full-name)
5618 (when (string= fullname "&")
5619 (setq fullname (user-login-name)))
5621 (mm-enable-multibyte)
5624 (equal fullname ""))
5626 ((or (eq style 'angles)
5627 (and (not (eq style 'parens))
5628 ;; Use angles if no quoting is needed, or if parens would
5629 ;; need quoting too.
5630 (or (not (string-match "[^- !#-'*+/-9=?A-Z^-~]" fullname))
5631 (let ((tmp (concat fullname nil)))
5632 (while (string-match "([^()]*)" tmp)
5633 (aset tmp (match-beginning 0) ?-)
5634 (aset tmp (1- (match-end 0)) ?-))
5635 (string-match "[\\()]" tmp)))))
5637 (goto-char (point-min))
5638 ;; Look for a character that cannot appear unquoted
5639 ;; according to RFC 822.
5640 (when (re-search-forward "[^- !#-'*+/-9=?A-Z^-~]" nil 1)
5641 ;; Quote fullname, escaping specials.
5642 (goto-char (point-min))
5644 (while (re-search-forward "[\"\\]" nil 1)
5645 (replace-match "\\\\\\&" t))
5647 (insert " <" login ">"))
5648 (t ; 'parens or default
5650 (let ((fullname-start (point)))
5652 (goto-char fullname-start)
5653 ;; RFC 822 says \ and nonmatching parentheses
5654 ;; must be escaped in comments.
5655 ;; Escape every instance of ()\ ...
5656 (while (re-search-forward "[()\\]" nil 1)
5657 (replace-match "\\\\\\&" t))
5658 ;; ... then undo escaping of matching parentheses,
5659 ;; including matching nested parentheses.
5660 (goto-char fullname-start)
5661 (while (re-search-forward
5662 "\\(\\=\\|[^\\]\\(\\\\\\\\\\)*\\)\\\\(\\(\\([^\\]\\|\\\\\\\\\\)*\\)\\\\)"
5664 (replace-match "\\1(\\3)" t)
5665 (goto-char fullname-start)))
5669 (defun message-make-sender ()
5670 "Return the \"real\" user address.
5671 This function tries to ignore all user modifications, and
5672 give as trustworthy answer as possible."
5673 (concat (user-login-name) "@" (system-name)))
5675 (defun message-make-address ()
5676 "Make the address of the user."
5677 (or (message-user-mail-address)
5678 (concat (user-login-name) "@" (message-make-domain))))
5680 (defun message-user-mail-address ()
5681 "Return the pertinent part of `user-mail-address'."
5682 (when (and user-mail-address
5683 (string-match "@.*\\." user-mail-address))
5684 (if (string-match " " user-mail-address)
5685 (nth 1 (mail-extract-address-components user-mail-address))
5686 user-mail-address)))
5688 (defun message-sendmail-envelope-from ()
5689 "Return the envelope from."
5690 (cond ((eq message-sendmail-envelope-from 'header)
5691 (nth 1 (mail-extract-address-components
5692 (message-fetch-field "from"))))
5693 ((stringp message-sendmail-envelope-from)
5694 message-sendmail-envelope-from)
5696 (message-make-address))))
5698 (defun message-make-fqdn ()
5699 "Return user's fully qualified domain name."
5700 (let* ((system-name (system-name))
5701 (user-mail (message-user-mail-address))
5704 (string-match "@\\(.*\\)\\'" user-mail))
5705 (match-string 1 user-mail)))
5706 (case-fold-search t))
5708 ((and message-user-fqdn
5709 (stringp message-user-fqdn)
5710 (string-match message-valid-fqdn-regexp message-user-fqdn)
5711 (not (string-match message-bogus-system-names message-user-fqdn)))
5712 ;; `message-user-fqdn' seems to be valid
5714 ((and (string-match message-valid-fqdn-regexp system-name)
5715 (not (string-match message-bogus-system-names system-name)))
5716 ;; `system-name' returned the right result.
5718 ;; Try `mail-host-address'.
5719 ((and (boundp 'mail-host-address)
5720 (stringp mail-host-address)
5721 (string-match message-valid-fqdn-regexp mail-host-address)
5722 (not (string-match message-bogus-system-names mail-host-address)))
5724 ;; We try `user-mail-address' as a backup.
5726 (stringp user-domain)
5727 (string-match message-valid-fqdn-regexp user-domain)
5728 (not (string-match message-bogus-system-names user-domain)))
5730 ;; Default to this bogus thing.
5733 ".i-did-not-set--mail-host-address--so-tickle-me")))))
5735 (defun message-make-host-name ()
5736 "Return the name of the host."
5737 (let ((fqdn (message-make-fqdn)))
5738 (string-match "^[^.]+\\." fqdn)
5739 (substring fqdn 0 (1- (match-end 0)))))
5741 (defun message-make-domain ()
5742 "Return the domain name."
5743 (or mail-host-address
5744 (message-make-fqdn)))
5746 (defun message-to-list-only ()
5747 "Send a message to the list only.
5748 Remove all addresses but the list address from To and Cc headers."
5750 (let ((listaddr (message-make-mail-followup-to t)))
5753 (message-remove-header "to")
5754 (message-remove-header "cc")
5755 (message-position-on-field "To" "X-Draft-From")
5756 (insert listaddr)))))
5758 (defun message-make-mail-followup-to (&optional only-show-subscribed)
5759 "Return the Mail-Followup-To header.
5760 If passed the optional argument ONLY-SHOW-SUBSCRIBED only return the
5761 subscribed address (and not the additional To and Cc header contents)."
5762 (let* ((case-fold-search t)
5763 (to (message-fetch-field "To"))
5764 (cc (message-fetch-field "cc"))
5765 (msg-recipients (concat to (and to cc ", ") cc))
5767 (mapcar 'mail-strip-quoted-names
5768 (message-tokenize-header msg-recipients)))
5770 (if message-subscribed-address-file
5771 (let (begin end item re)
5774 (insert-file-contents message-subscribed-address-file)
5776 (setq begin (point))
5779 (if (bolp) (setq end (1- end)))
5780 (setq item (regexp-quote (buffer-substring begin end)))
5781 (if re (setq re (concat re "\\|" item))
5782 (setq re (concat "\\`\\(" item))))
5783 (and re (list (concat re "\\)\\'"))))))))
5784 (mft-regexps (apply 'append message-subscribed-regexps
5785 (mapcar 'regexp-quote
5786 message-subscribed-addresses)
5789 message-subscribed-address-functions))))
5792 (loop for recipient in recipients
5793 when (loop for regexp in mft-regexps
5794 when (string-match regexp recipient) return t)
5797 (if only-show-subscribed
5799 msg-recipients))))))
5801 (defun message-idna-to-ascii-rhs-1 (header)
5802 "Interactively potentially IDNA encode domain names in HEADER."
5803 (let ((field (message-fetch-field header))
5807 (mm-delete-duplicates
5808 (mapcar (lambda (rhs) (or (cadr (split-string rhs "@")) ""))
5814 (mail-extract-address-components field t))))))
5815 ;; Note that `rhs' will be "" if the address does not have
5816 ;; the domain part, i.e., if it is a local user's address.
5817 (setq ace (if (string-match "\\`[[:ascii:]]*\\'" rhs)
5819 (downcase (idna-to-ascii rhs))))
5820 (when (and (not (equal rhs ace))
5821 (or (not (eq message-use-idna 'ask))
5822 (y-or-n-p (format "Replace %s with %s in %s:? "
5824 (goto-char (point-min))
5825 (while (re-search-forward (concat "^" header ":") nil t)
5826 (message-narrow-to-field)
5827 (while (search-forward (concat "@" rhs) nil t)
5828 (replace-match (concat "@" ace) t t))
5829 (goto-char (point-max))
5832 (defun message-idna-to-ascii-rhs ()
5833 "Possibly IDNA encode non-ASCII domain names in From:, To: and Cc: headers.
5834 See `message-idna-encode'."
5836 (when message-use-idna
5839 ;; `message-narrow-to-head' that recognizes only the first empty
5840 ;; line as the message header separator used to be used here.
5841 ;; However, since there is the "--text follows this line--" line
5842 ;; normally, it failed in narrowing to the headers and potentially
5843 ;; caused the IDNA encoding on lines that look like headers in
5844 ;; the message body.
5845 (message-narrow-to-headers-or-head)
5846 (message-idna-to-ascii-rhs-1 "From")
5847 (message-idna-to-ascii-rhs-1 "To")
5848 (message-idna-to-ascii-rhs-1 "Reply-To")
5849 (message-idna-to-ascii-rhs-1 "Mail-Reply-To")
5850 (message-idna-to-ascii-rhs-1 "Mail-Followup-To")
5851 (message-idna-to-ascii-rhs-1 "Cc")))))
5855 (defvar Organization)
5860 (defvar In-Reply-To)
5863 (defvar Distribution)
5868 (defun message-generate-headers (headers)
5869 "Prepare article HEADERS.
5870 Headers already prepared in the buffer are not modified."
5871 (setq headers (append headers message-required-headers))
5873 (message-narrow-to-headers)
5874 (let* ((Date (message-make-date))
5875 (Message-ID (message-make-message-id))
5876 (Organization (message-make-organization))
5877 (From (message-make-from))
5878 (Path (message-make-path))
5881 (In-Reply-To (message-make-in-reply-to))
5882 (References (message-make-references))
5884 (Distribution (message-make-distribution))
5885 (Lines (message-make-lines))
5886 (User-Agent message-newsreader)
5887 (Expires (message-make-expires))
5888 (case-fold-search t)
5890 header value elem header-string)
5891 ;; First we remove any old generated headers.
5892 (let ((headers message-deletable-headers))
5893 (unless (buffer-modified-p)
5894 (setq headers (delq 'Message-ID (copy-sequence headers))))
5896 (goto-char (point-min))
5897 (and (re-search-forward
5898 (concat "^" (symbol-name (car headers)) ": *") nil t)
5899 (get-text-property (1+ (match-beginning 0)) 'message-deletable)
5900 (message-delete-line))
5902 ;; Go through all the required headers and see if they are in the
5903 ;; articles already. If they are not, or are empty, they are
5904 ;; inserted automatically - except for Subject, Newsgroups and
5907 (goto-char (point-min))
5908 (setq elem (pop headers))
5910 (if (eq (car elem) 'optional)
5911 (setq header (cdr elem)
5913 (setq header (car elem)))
5915 (setq header-string (if (stringp header)
5917 (symbol-name header)))
5918 (when (or (not (re-search-forward
5920 (regexp-quote (downcase header-string))
5924 ;; The header was found. We insert a space after the
5925 ;; colon, if there is none.
5926 (if (/= (char-after) ? ) (insert " ") (forward-char 1))
5927 ;; Find out whether the header is empty.
5928 (looking-at "[ \t]*\n[^ \t]")))
5929 ;; So we find out what value we should insert.
5933 (eq (car elem) 'optional)
5934 (not (member header-string message-inserted-headers)))
5935 ;; This is an optional header. If the cdr of this
5936 ;; is something that is nil, then we do not insert
5938 (setq header (cdr elem))
5939 (or (and (functionp (cdr elem))
5940 (funcall (cdr elem)))
5941 (and (boundp (cdr elem))
5942 (symbol-value (cdr elem)))))
5944 ;; The element is a cons. Either the cdr is a
5945 ;; string to be inserted verbatim, or it is a
5946 ;; function, and we insert the value returned from
5948 (or (and (stringp (cdr elem))
5950 (and (functionp (cdr elem))
5951 (funcall (cdr elem)))))
5952 ((and (boundp header)
5953 (symbol-value header))
5954 ;; The element is a symbol. We insert the value
5955 ;; of this symbol, if any.
5956 (symbol-value header))
5957 ((not (message-check-element
5958 (intern (downcase (symbol-name header)))))
5959 ;; We couldn't generate a value for this header,
5960 ;; so we just ask the user.
5961 (read-from-minibuffer
5962 (format "Empty header for %s; enter value: " header)))))
5963 ;; Finally insert the header.
5965 (not (equal value "")))
5969 ;; This header didn't exist, so we insert it.
5970 (goto-char (point-max))
5972 (cdr (assq header message-header-format-alist))))
5974 (funcall formatter header value)
5975 (insert header-string ": " value))
5976 (push header-string message-inserted-headers)
5977 (goto-char (message-fill-field))
5978 ;; We check whether the value was ended by a
5979 ;; newline. If not, we insert one.
5983 ;; The value of this header was empty, so we clear
5984 ;; totally and insert the new value.
5985 (delete-region (point) (point-at-eol))
5986 ;; If the header is optional, and the header was
5987 ;; empty, we can't insert it anyway.
5989 (push header-string message-inserted-headers)
5991 (message-fill-field)))
5992 ;; Add the deletable property to the headers that require it.
5993 (and (memq header message-deletable-headers)
5994 (progn (beginning-of-line) (looking-at "[^:]+: "))
5995 (add-text-properties
5996 (point) (match-end 0)
5997 '(message-deletable t face italic) (current-buffer)))))))
5998 ;; Insert new Sender if the From is strange.
5999 (let ((from (message-fetch-field "from"))
6000 (sender (message-fetch-field "sender"))
6001 (secure-sender (message-make-sender)))
6003 (not (message-check-element 'sender))
6006 (cadr (mail-extract-address-components from)))
6007 (downcase secure-sender)))
6012 (cadr (mail-extract-address-components sender)))
6013 (downcase secure-sender)))))
6014 (goto-char (point-min))
6015 ;; Rename any old Sender headers to Original-Sender.
6016 (when (re-search-forward "^\\(Original-\\)*Sender:" nil t)
6018 (insert "Original-")
6019 (beginning-of-line))
6020 (when (or (message-news-p)
6021 (string-match "@.+\\.." secure-sender))
6022 (insert "Sender: " secure-sender "\n"))))
6024 (message-idna-to-ascii-rhs))))
6026 (defun message-insert-courtesy-copy (message)
6027 "Insert a courtesy message in mail copies of combined messages."
6031 (message-narrow-to-headers)
6032 (when (setq newsgroups (message-fetch-field "newsgroups"))
6033 (goto-char (point-max))
6034 (insert "Posted-To: " newsgroups "\n")))
6038 ((string-match "%s" message)
6039 (insert (format message newsgroups)))
6041 (insert message)))))))
6044 ;;; Setting up a message buffer
6047 (defun message-skip-to-next-address ()
6048 (let ((end (save-excursion
6049 (message-next-header)
6052 (when (looking-at ",")
6054 (while (and (not (= (point) end))
6055 (or (not (eq char ?,))
6057 (skip-chars-forward "^,\"" (point-max))
6058 (when (eq (setq char (following-char)) ?\")
6059 (setq quoted (not quoted)))
6060 (unless (= (point) end)
6062 (skip-chars-forward " \t\n")))
6064 (defun message-fill-address (header value)
6065 (insert (capitalize (symbol-name header))
6067 (if (consp value) (car value) value)
6069 (message-fill-field-address))
6071 (defun message-split-line ()
6072 "Split current line, moving portion beyond point vertically down.
6073 If the current line has `message-yank-prefix', insert it on the new line."
6076 (split-line message-yank-prefix) ;; Emacs 22.1+ supports arg.
6080 (defun message-insert-header (header value)
6081 (insert (capitalize (symbol-name header))
6083 (if (consp value) (car value) value)))
6085 (defun message-field-name ()
6087 (goto-char (point-min))
6088 (when (looking-at "\\([^:]+\\):")
6089 (intern (capitalize (match-string 1))))))
6091 (defun message-fill-field ()
6094 (message-narrow-to-field)
6095 (let ((field-name (message-field-name)))
6096 (funcall (or (cadr (assq field-name message-field-fillers))
6097 'message-fill-field-general)))
6100 (defun message-fill-field-address ()
6102 (message-skip-to-next-address)
6104 (if (and (> (current-column) 78)
6110 (setq last (1+ (point))))
6111 (setq last (1+ (point)))))))
6113 (defun message-fill-field-general ()
6114 (let ((begin (point))
6117 (while (and (search-forward "\n" nil t)
6119 (replace-match " " t t))
6120 (fill-region-as-paragraph begin (point-max))
6121 ;; Tapdance around looong Message-IDs.
6123 (when (looking-at "[ \t]*$")
6124 (message-delete-line))
6126 (search-forward ":" nil t)
6127 (when (looking-at "\n[ \t]+")
6128 (replace-match " " t t))
6129 (goto-char (point-max))))
6131 (defun message-shorten-1 (list cut surplus)
6132 "Cut SURPLUS elements out of LIST, beginning with CUTth one."
6133 (setcdr (nthcdr (- cut 2) list)
6134 (nthcdr (+ (- cut 2) surplus 1) list)))
6136 (defun message-shorten-references (header references)
6137 "Trim REFERENCES to be 21 Message-ID long or less, and fold them.
6138 When sending via news, also check that the REFERENCES are less
6139 than 988 characters long, and if they are not, trim them until
6141 ;; 21 is the number suggested by USEAGE.
6148 (goto-char (point-min))
6149 ;; Cons a list of valid references. GNKSA says we must not include MIDs
6150 ;; with whitespace or missing brackets (7.a "Does not propagate broken
6151 ;; Message-IDs in original References").
6152 (while (re-search-forward "<[^ <]+@[^ <]+>" nil t)
6153 (push (match-string 0) refs))
6154 (setq refs (nreverse refs)
6155 count (length refs)))
6157 ;; If the list has more than MAXCOUNT elements, trim it by
6158 ;; removing the CUTth element and the required number of
6159 ;; elements that follow.
6160 (when (> count maxcount)
6161 (let ((surplus (- count maxcount)))
6162 (message-shorten-1 refs cut surplus)
6163 (decf count surplus)))
6165 ;; When sending via news, make sure the total folded length will
6166 ;; be less than 998 characters. This is to cater to broken INN
6167 ;; 2.3 which counts the total number of characters in a header
6168 ;; rather than the physical line length of each line, as it should.
6170 ;; This hack should be removed when it's believed than INN 2.3 is
6171 ;; no longer widely used.
6173 ;; At this point the headers have not been generated, thus we use
6174 ;; message-this-is-news directly.
6175 (when message-this-is-news
6178 (message-insert-header
6179 header (mapconcat #'identity refs " "))
6181 (message-shorten-1 refs cut 1)))
6182 ;; Finally, collect the references back into a string and insert
6183 ;; it into the buffer.
6184 (message-insert-header header (mapconcat #'identity refs " "))))
6186 (defun message-position-point ()
6187 "Move point to where the user probably wants to find it."
6188 (message-narrow-to-headers)
6190 ((re-search-forward "^[^:]+:[ \t]*$" nil t)
6191 (search-backward ":" )
6194 (if (eq (char-after) ? )
6198 (goto-char (point-max))
6201 (unless (looking-at "$")
6205 (defcustom message-beginning-of-line t
6206 "Whether \\<message-mode-map>\\[message-beginning-of-line]\
6207 goes to beginning of header values."
6209 :group 'message-buffers
6210 :link '(custom-manual "(message)Movement")
6213 (defun message-beginning-of-line (&optional n)
6214 "Move point to beginning of header value or to beginning of line.
6215 The prefix argument N is passed directly to `beginning-of-line'.
6217 This command is identical to `beginning-of-line' if point is
6218 outside the message header or if the option `message-beginning-of-line'
6221 If point is in the message header and on a (non-continued) header
6222 line, move point to the beginning of the header value or the beginning of line,
6223 whichever is closer. If point is already at beginning of line, move point to
6224 beginning of header value. Therefore, repeated calls will toggle point
6225 between beginning of field and beginning of line."
6227 (let ((zrs 'zmacs-region-stays))
6228 (when (and (featurep 'xemacs) (interactive-p) (boundp zrs))
6230 (if (and message-beginning-of-line
6231 (message-point-in-header-p))
6232 (let* ((here (point))
6233 (bol (progn (beginning-of-line n) (point)))
6234 (eol (point-at-eol))
6235 (eoh (re-search-forward ": *" eol t)))
6237 (if (and eoh (or (< eoh here) (= bol here)))
6239 (beginning-of-line n)))
6241 (defun message-buffer-name (type &optional to group)
6242 "Return a new (unique) buffer name based on TYPE and TO."
6244 ;; Generate a new buffer name The Message Way.
6245 ((memq message-generate-new-buffers '(unique t))
6246 (generate-new-buffer-name
6250 (or (car (mail-extract-address-components to))
6253 (if (and group (not (string= group ""))) (concat " on " group) "")
6255 ;; Check whether `message-generate-new-buffers' is a function,
6256 ;; and if so, call it.
6257 ((functionp message-generate-new-buffers)
6258 (funcall message-generate-new-buffers type to group))
6259 ((eq message-generate-new-buffers 'unsent)
6260 (generate-new-buffer-name
6261 (concat "*unsent " type
6264 (or (car (mail-extract-address-components to))
6267 (if (and group (not (string= group ""))) (concat " on " group) "")
6269 ;; Search for the existing message buffer with the specified name.
6271 (let* ((new (if (eq message-generate-new-buffers 'standard)
6272 (generate-new-buffer-name (concat "*" type " message*"))
6273 (let ((message-generate-new-buffers 'unique))
6274 (message-buffer-name type to group))))
6275 (regexp (concat "\\`"
6277 (if (string-match "<[0-9]+>\\'" new)
6278 (substring new 0 (match-beginning 0))
6280 "\\(?:<\\([0-9]+\\)>\\)?\\'"))
6281 (case-fold-search nil))
6288 (when (and (string-match regexp (setq b (buffer-name b)))
6289 (eq (with-current-buffer b major-mode)
6291 (cons (string-to-number (or (match-string 1 b) "1"))
6294 'car-less-than-car)))
6297 (defun message-pop-to-buffer (name &optional switch-function)
6298 "Pop to buffer NAME, and warn if it already exists and is modified."
6299 (let ((buffer (get-buffer name)))
6301 (buffer-name buffer))
6302 (let ((window (get-buffer-window buffer 0)))
6304 ;; Raise the frame already displaying the message buffer.
6306 (gnus-select-frame-set-input-focus (window-frame window))
6307 (select-window window))
6308 (funcall (or switch-function 'pop-to-buffer) buffer)
6309 (set-buffer buffer))
6310 (when (and (buffer-modified-p)
6313 "Message already being composed; erase? ")
6315 (error "Message being composed")))
6316 (funcall (or switch-function 'pop-to-buffer) name)
6321 (defun message-do-send-housekeeping ()
6322 "Kill old message buffers."
6323 ;; We might have sent this buffer already. Delete it from the
6325 (setq message-buffer-list (delq (current-buffer) message-buffer-list))
6326 (while (and message-max-buffers
6328 (>= (length message-buffer-list) message-max-buffers))
6329 ;; Kill the oldest buffer -- unless it has been changed.
6330 (let ((buffer (pop message-buffer-list)))
6331 (when (and (buffer-name buffer)
6332 (not (buffer-modified-p buffer)))
6333 (kill-buffer buffer))))
6334 ;; Rename the buffer.
6335 (if message-send-rename-function
6336 (funcall message-send-rename-function)
6337 ;; Note: mail-abbrevs of XEmacs renames buffer name behind Gnus.
6339 "\\`\\*\\(sent \\|unsent \\)?\\(.+\\)\\*[^\\*]*\\|\\`mail to "
6341 (let ((name (match-string 2 (buffer-name)))
6343 (if (not (or (null name)
6344 (string-equal name "mail")
6345 (string-equal name "posting")))
6346 (setq name (concat "*sent " name "*"))
6347 (message-narrow-to-headers)
6348 (setq to (message-fetch-field "to"))
6349 (setq group (message-fetch-field "newsgroups"))
6353 (to (concat "*sent mail to "
6354 (or (car (mail-extract-address-components to))
6356 ((and group (not (string= group "")))
6357 (concat "*sent posting on " group "*"))
6358 (t "*sent mail*"))))
6359 (unless (string-equal name (buffer-name))
6360 (rename-buffer name t)))))
6361 ;; Push the current buffer onto the list.
6362 (when message-max-buffers
6363 (setq message-buffer-list
6364 (nconc message-buffer-list (list (current-buffer))))))
6366 (defun message-mail-user-agent ()
6368 ((not message-mail-user-agent) nil)
6369 ((eq message-mail-user-agent t) mail-user-agent)
6370 (t message-mail-user-agent))))
6371 (if (memq mua '(message-user-agent gnus-user-agent))
6375 ;; YANK-ACTION, if non-nil, can be a buffer or a yank action of the
6376 ;; form (FUNCTION . ARGS).
6377 (defun message-setup (headers &optional yank-action actions
6378 continue switch-function return-action)
6379 (let ((mua (message-mail-user-agent))
6381 (if (not (and message-this-is-mail mua))
6382 (message-setup-1 headers yank-action actions return-action)
6383 (setq headers (copy-sequence headers))
6384 (setq field (assq 'Subject headers))
6386 (setq subject (cdr field))
6387 (setq headers (delq field headers)))
6388 (setq field (assq 'To headers))
6390 (setq to (cdr field))
6391 (setq headers (delq field headers)))
6392 (let ((mail-user-agent mua))
6393 (compose-mail to subject
6394 (mapcar (lambda (item)
6396 (format "%s" (car item))
6399 continue switch-function
6400 (if (bufferp yank-action)
6401 (list 'insert-buffer yank-action)
6405 (defun message-headers-to-generate (headers included-headers excluded-headers)
6406 "Return a list that includes all headers from HEADERS.
6407 If INCLUDED-HEADERS is a list, just include those headers. If it is
6408 t, include all headers. In any case, headers from EXCLUDED-HEADERS
6412 (dolist (header headers)
6413 (setq header-name (cond
6414 ((and (consp header)
6415 (eq (car header) 'optional))
6416 ;; On the form (optional . Header)
6419 ;; On the form (Header . function)
6424 (when (and (not (memq header-name excluded-headers))
6425 (or (eq included-headers t)
6426 (memq header-name included-headers)))
6427 (push header result)))
6430 (defun message-setup-1 (headers &optional yank-action actions return-action)
6431 (dolist (action actions)
6433 (add-to-list 'message-send-actions
6434 `(apply ',(car action) ',(cdr action)))))
6435 (setq message-return-action return-action)
6436 (setq message-reply-buffer
6437 (if (and (consp yank-action)
6438 (eq (car yank-action) 'insert-buffer))
6441 (goto-char (point-min))
6442 ;; Insert all the headers.
6445 (alist message-header-format-alist))
6447 (unless (assq (caar h) message-header-format-alist)
6448 (push (list (caar h)) alist))
6452 (delete-region (point) (progn (forward-line -1) (point)))
6453 (when message-default-headers
6455 (if (functionp message-default-headers)
6456 (funcall message-default-headers)
6457 message-default-headers))
6458 (or (bolp) (insert ?\n)))
6459 (insert (concat mail-header-separator "\n"))
6461 ;; If a crash happens while replying, the auto-save file would *not* have a
6462 ;; `References:' header if `message-generate-headers-first' was nil.
6463 ;; Therefore, always generate it first.
6464 (let ((message-generate-headers-first
6465 (if (eq message-generate-headers-first t)
6467 (append message-generate-headers-first '(References)))))
6468 (when (message-news-p)
6469 (when message-default-news-headers
6470 (insert message-default-news-headers)
6471 (or (bolp) (insert ?\n)))
6472 (message-generate-headers
6473 (message-headers-to-generate
6474 (append message-required-news-headers
6475 message-required-headers)
6476 message-generate-headers-first
6478 (when (message-mail-p)
6479 (when message-default-mail-headers
6480 (insert message-default-mail-headers)
6481 (or (bolp) (insert ?\n)))
6482 (message-generate-headers
6483 (message-headers-to-generate
6484 (append message-required-mail-headers
6485 message-required-headers)
6486 message-generate-headers-first
6487 '(Lines Subject)))))
6488 (run-hooks 'message-signature-setup-hook)
6489 (message-insert-signature)
6491 (message-narrow-to-headers)
6492 (run-hooks 'message-header-setup-hook))
6493 (setq buffer-undo-list nil)
6494 (when message-generate-hashcash
6495 ;; Generate hashcash headers for recipients already known
6496 (mail-add-payment-async))
6497 ;; Gnus posting styles are applied via buffer-local `message-setup-hook'
6499 (run-hooks 'message-setup-hook)
6500 ;; Do this last to give it precedence over posting styles, etc.
6501 (when (message-mail-p)
6503 (message-narrow-to-headers)
6504 (if message-alternative-emails
6505 (message-use-alternative-email-as-from))))
6506 (message-position-point)
6507 ;; Allow correct handling of `message-checksum' in `message-yank-original':
6508 (set-buffer-modified-p nil)
6511 (defun message-set-auto-save-file-name ()
6512 "Associate the message buffer with a file in the drafts directory."
6513 (when message-auto-save-directory
6514 (unless (file-directory-p
6515 (directory-file-name message-auto-save-directory))
6516 (make-directory message-auto-save-directory t))
6518 (setq message-draft-article
6519 (nndraft-request-associate-buffer "drafts"))
6521 ;; If Gnus were alive, draft messages would be saved in the drafts folder.
6522 ;; But Gnus is not alive, so arrange to save the draft message in a
6523 ;; regular file in message-auto-save-directory. Append a unique
6524 ;; time-based suffix to the filename to allow multiple drafts to be saved
6525 ;; simultaneously without overwriting each other (which mimics the
6526 ;; functionality of the Gnus drafts folder).
6527 (setq buffer-file-name (expand-file-name
6529 (if (memq system-type
6530 '(ms-dos windows-nt cygwin))
6533 (format-time-string "-%Y%m%d-%H%M%S"))
6534 message-auto-save-directory))
6535 (setq buffer-auto-save-file-name (make-auto-save-file-name)))
6536 (clear-visited-file-modtime)
6537 (setq buffer-file-coding-system message-draft-coding-system)))
6539 (defun message-disassociate-draft ()
6540 "Disassociate the message buffer from the drafts directory."
6541 (when message-draft-article
6542 (nndraft-request-expire-articles
6543 (list message-draft-article) "drafts" nil t)))
6545 (defun message-insert-headers ()
6546 "Generate the headers for the article."
6550 (message-narrow-to-headers)
6551 (when (message-news-p)
6552 (message-generate-headers
6555 (copy-sequence message-required-news-headers)))))
6556 (when (message-mail-p)
6557 (message-generate-headers
6560 (copy-sequence message-required-mail-headers))))))))
6565 ;;; Commands for interfacing with message
6569 (defun message-mail (&optional to subject other-headers continue
6570 switch-function yank-action send-actions
6571 return-action &rest ignored)
6572 "Start editing a mail message to be sent.
6573 OTHER-HEADERS is an alist of header/value pairs. CONTINUE says whether
6574 to continue editing a message already being composed. SWITCH-FUNCTION
6575 is a function used to switch to and display the mail buffer."
6577 (let ((message-this-is-mail t))
6578 (unless (message-mail-user-agent)
6579 (message-pop-to-buffer
6580 ;; Search for the existing message buffer if `continue' is non-nil.
6581 (let ((message-generate-new-buffers
6582 (when (or (not continue)
6583 (eq message-generate-new-buffers 'standard)
6584 (functionp message-generate-new-buffers))
6585 message-generate-new-buffers)))
6586 (message-buffer-name "mail" to))
6590 `((To . ,(or to "")) (Subject . ,(or subject "")))
6591 ;; C-h f compose-mail says that headers should be specified as
6592 ;; (string . value); however all the rest of message expects
6593 ;; headers to be symbols, not strings (eg message-header-format-alist).
6594 ;; http://lists.gnu.org/archive/html/emacs-devel/2011-01/msg00337.html
6595 ;; We need to convert any string input, eg from rmail-start-mail.
6596 (dolist (h other-headers other-headers)
6597 (if (stringp (car h)) (setcar h (intern (capitalize (car h)))))))
6598 yank-action send-actions continue switch-function
6602 (defun message-news (&optional newsgroups subject)
6603 "Start editing a news article to be sent."
6605 (let ((message-this-is-news t))
6606 (message-pop-to-buffer (message-buffer-name "posting" nil newsgroups))
6607 (message-setup `((Newsgroups . ,(or newsgroups ""))
6608 (Subject . ,(or subject ""))))))
6610 (defun message-alter-recipients-discard-bogus-full-name (addrcell)
6611 "Discard mail address in full names.
6612 When the full name in reply headers contains the mail
6613 address (e.g. \"foo@bar <foo@bar>\"), discard full name.
6614 ADDRCELL is a cons cell where the car is the mail address and the
6615 cdr is the complete address (full name and mail address)."
6616 (if (string-match (concat (regexp-quote (car addrcell)) ".*"
6617 (regexp-quote (car addrcell)))
6619 (cons (car addrcell) (car addrcell))
6622 (defcustom message-alter-recipients-function nil
6623 "Function called to allow alteration of reply header structures.
6624 It is called in `message-get-reply-headers' for each recipient.
6625 The function is called with one parameter, a cons cell ..."
6626 :type '(choice (const :tag "None" nil)
6627 (const :tag "Discard bogus full name"
6628 message-alter-recipients-discard-bogus-full-name)
6630 :version "23.1" ;; No Gnus
6631 :group 'message-headers)
6633 (defun message-get-reply-headers (wide &optional to-address address-headers)
6634 (let (follow-to mct never-mct to cc author mft recipients extra)
6635 ;; Find all relevant headers we need.
6637 (message-narrow-to-headers-or-head)
6638 ;; Gmane renames "To". Look at "Original-To", too, if it is present in
6639 ;; message-header-synonyms.
6640 (setq to (or (message-fetch-field "to")
6641 (and (loop for synonym in message-header-synonyms
6642 when (memq 'Original-To synonym)
6644 (message-fetch-field "original-to")))
6645 cc (message-fetch-field "cc")
6646 extra (when message-extra-wide-headers
6647 (mapconcat 'identity
6648 (mapcar 'message-fetch-field
6649 message-extra-wide-headers)
6651 mct (message-fetch-field "mail-copies-to")
6652 author (or (message-fetch-field "mail-reply-to")
6653 (message-fetch-field "reply-to")
6654 (message-fetch-field "from")
6656 mft (and message-use-mail-followup-to
6657 (message-fetch-field "mail-followup-to"))))
6659 ;; Handle special values of Mail-Copies-To.
6661 (cond ((or (equal (downcase mct) "never")
6662 (equal (downcase mct) "nobody"))
6665 ((or (equal (downcase mct) "always")
6666 (equal (downcase mct) "poster"))
6667 (setq mct author))))
6670 ;; Build (textual) list of new recipient addresses.
6673 (setq recipients (concat ", " to-address))
6674 ;; If the author explicitly asked for a copy, we don't deny it to them.
6675 (if mct (setq recipients (concat recipients ", " mct))))
6677 (setq recipients (concat ", " author)))
6679 (dolist (header address-headers)
6680 (let ((value (message-fetch-field header)))
6682 (setq recipients (concat recipients ", " value))))))
6684 (string-match "[^ \t,]" mft)
6685 (or (not (eq message-use-mail-followup-to 'ask))
6686 (message-y-or-n-p "Obey Mail-Followup-To? " t "\
6687 You should normally obey the Mail-Followup-To: header. In this
6688 article, it has the value of
6692 which directs your response to " (if (string-match "," mft)
6693 "the specified addresses"
6694 "that address only") ".
6696 Most commonly, Mail-Followup-To is used by a mailing list poster to
6697 express that responses should be sent to just the list, and not the
6700 If a message is posted to several mailing lists, Mail-Followup-To may
6701 also be used to direct the following discussion to one list only,
6702 because discussions that are spread over several lists tend to be
6703 fragmented and very difficult to follow.
6705 Also, some source/announcement lists are not intended for discussion;
6706 responses here are directed to other addresses.
6708 You may customize the variable `message-use-mail-followup-to', if you
6709 want to get rid of this query permanently.")))
6710 (setq recipients (concat ", " mft)))
6712 (setq recipients (if never-mct "" (concat ", " author)))
6713 (if to (setq recipients (concat recipients ", " to)))
6714 (if cc (setq recipients (concat recipients ", " cc)))
6715 (if extra (setq recipients (concat recipients ", " extra)))
6716 (if mct (setq recipients (concat recipients ", " mct)))))
6717 (if (>= (length recipients) 2)
6718 ;; Strip the leading ", ".
6719 (setq recipients (substring recipients 2)))
6720 ;; Squeeze whitespace.
6721 (while (string-match "[ \t][ \t]+" recipients)
6722 (setq recipients (replace-match " " t t recipients)))
6723 ;; Remove addresses that match `rmail-dont-reply-to-names'.
6724 (let ((rmail-dont-reply-to-names (message-dont-reply-to-names)))
6725 (setq recipients (rmail-dont-reply-to recipients)))
6726 ;; Perhaps "Mail-Copies-To: never" removed the only address?
6727 (if (string-equal recipients "")
6728 (setq recipients author))
6729 ;; Convert string to a list of (("foo@bar" . "Name <Foo@BAR>") ...).
6733 (if message-alter-recipients-function
6734 (funcall message-alter-recipients-function
6735 (cons (downcase (mail-strip-quoted-names addr))
6737 (cons (downcase (mail-strip-quoted-names addr)) addr)))
6738 (message-tokenize-header recipients)))
6739 ;; Remove first duplicates. (Why not all duplicates? Is this a bug?)
6740 (let ((s recipients))
6742 (setq recipients (delq (assoc (car (pop s)) s) recipients))))
6744 ;; Remove hierarchical lists that are contained within each other,
6745 ;; if message-hierarchical-addresses is defined.
6746 (when message-hierarchical-addresses
6747 (let ((plain-addrs (mapcar 'car recipients))
6750 (setq subaddrs (assoc (car plain-addrs)
6751 message-hierarchical-addresses)
6752 plain-addrs (cdr plain-addrs))
6754 (setq subaddrs (cdr subaddrs))
6756 (setq recip (assoc (car subaddrs) recipients)
6757 subaddrs (cdr subaddrs))
6759 (setq recipients (delq recip recipients))))))))
6761 (setq recipients (message-prune-recipients recipients))
6763 ;; Build the header alist. Allow the user to be asked whether
6764 ;; or not to reply to all recipients in a wide reply.
6765 (setq follow-to (list (cons 'To (cdr (pop recipients)))))
6766 (when (and recipients
6767 (or (not message-wide-reply-confirm-recipients)
6768 (y-or-n-p "Reply to all recipients? ")))
6769 (setq recipients (mapconcat
6770 (lambda (addr) (cdr addr)) recipients ", "))
6771 (if (string-match "^ +" recipients)
6772 (setq recipients (substring recipients (match-end 0))))
6773 (push (cons 'Cc recipients) follow-to)))
6776 (defun message-prune-recipients (recipients)
6777 (dolist (rule message-prune-recipient-rules)
6778 (let ((match (car rule))
6781 (dolist (recipient recipients)
6782 (setq address (car recipient))
6783 (when (string-match match address)
6784 (setq dup-match (replace-match (cadr rule) nil nil address))
6785 (dolist (recipient recipients)
6786 ;; Don't delete the address that triggered this.
6787 (when (and (not (eq address (car recipient)))
6788 (string-match dup-match (car recipient)))
6789 (setq recipients (delq recipient recipients))))))))
6792 (defcustom message-simplify-subject-functions
6793 '(message-strip-list-identifiers
6794 message-strip-subject-re
6795 message-strip-subject-trailing-was
6796 message-strip-subject-encoded-words)
6797 "List of functions taking a string argument that simplify subjects.
6798 The functions are applied when replying to a message.
6800 Useful functions to put in this list include:
6801 `message-strip-list-identifiers', `message-strip-subject-re',
6802 `message-strip-subject-trailing-was', and
6803 `message-strip-subject-encoded-words'."
6804 :version "22.1" ;; Gnus 5.10.9
6805 :group 'message-various
6806 :type '(repeat function))
6808 (defun message-simplify-subject (subject &optional functions)
6809 "Return simplified SUBJECT."
6812 (setq functions message-simplify-subject-functions))
6813 (when (and (memq 'message-strip-list-identifiers functions)
6814 gnus-list-identifiers)
6815 (setq subject (message-strip-list-identifiers subject)))
6816 (when (memq 'message-strip-subject-re functions)
6817 (setq subject (concat "Re: " (message-strip-subject-re subject))))
6818 (when (and (memq 'message-strip-subject-trailing-was functions)
6819 message-subject-trailing-was-query)
6820 (setq subject (message-strip-subject-trailing-was subject)))
6821 (when (memq 'message-strip-subject-encoded-words functions)
6822 (setq subject (message-strip-subject-encoded-words subject)))
6826 (defun message-reply (&optional to-address wide)
6827 "Start editing a reply to the article in the current buffer."
6829 (require 'gnus-sum) ; for gnus-list-identifiers
6830 (let ((cur (current-buffer))
6832 references message-id follow-to
6833 (inhibit-point-motion-hooks t)
6834 (message-this-is-mail t)
6837 (message-narrow-to-head-1)
6838 ;; Allow customizations to have their say.
6840 ;; This is a regular reply.
6841 (when (functionp message-reply-to-function)
6843 (setq follow-to (funcall message-reply-to-function))))
6844 ;; This is a followup.
6845 (when (functionp message-wide-reply-to-function)
6848 (funcall message-wide-reply-to-function)))))
6849 (setq message-id (message-fetch-field "message-id" t)
6850 references (message-fetch-field "references")
6851 date (message-fetch-field "date")
6852 from (or (message-fetch-field "from") "nobody")
6853 subject (or (message-fetch-field "subject") "none"))
6855 ;; Strip list identifiers, "Re: ", and "was:"
6856 (setq subject (message-simplify-subject subject))
6858 (when (and (setq gnus-warning (message-fetch-field "gnus-warning"))
6859 (string-match "<[^>]+>" gnus-warning))
6860 (setq message-id (match-string 0 gnus-warning)))
6863 (setq follow-to (message-get-reply-headers wide to-address))))
6865 (unless (message-mail-user-agent)
6866 (message-pop-to-buffer
6867 (message-buffer-name
6868 (if wide "wide reply" "reply") from
6869 (if wide to-address nil))))
6871 (setq message-reply-headers
6872 (vector 0 subject from date message-id references 0 0 ""))
6875 `((Subject . ,subject)
6880 (defun message-wide-reply (&optional to-address)
6881 "Make a \"wide\" reply to the message in the current buffer."
6883 (message-reply to-address t))
6886 (defun message-followup (&optional to-newsgroups)
6887 "Follow up to the message in the current buffer.
6888 If TO-NEWSGROUPS, use that as the new Newsgroups line."
6890 (require 'gnus-sum) ; for gnus-list-identifiers
6891 (let ((cur (current-buffer))
6892 from subject date reply-to mrt mct
6893 references message-id follow-to
6894 (inhibit-point-motion-hooks t)
6895 (message-this-is-news t)
6896 followup-to distribution newsgroups gnus-warning posted-to)
6899 (goto-char (point-min))
6900 (if (search-forward "\n\n" nil t)
6903 (when (functionp message-followup-to-function)
6905 (funcall message-followup-to-function)))
6906 (setq from (message-fetch-field "from")
6907 date (message-fetch-field "date")
6908 subject (or (message-fetch-field "subject") "none")
6909 references (message-fetch-field "references")
6910 message-id (message-fetch-field "message-id" t)
6911 followup-to (message-fetch-field "followup-to")
6912 newsgroups (message-fetch-field "newsgroups")
6913 posted-to (message-fetch-field "posted-to")
6914 reply-to (message-fetch-field "reply-to")
6915 mrt (message-fetch-field "mail-reply-to")
6916 distribution (message-fetch-field "distribution")
6917 mct (message-fetch-field "mail-copies-to"))
6918 (when (and (setq gnus-warning (message-fetch-field "gnus-warning"))
6919 (string-match "<[^>]+>" gnus-warning))
6920 (setq message-id (match-string 0 gnus-warning)))
6921 ;; Remove bogus distribution.
6922 (when (and (stringp distribution)
6923 (let ((case-fold-search t))
6924 (string-match "world" distribution)))
6925 (setq distribution nil))
6926 ;; Strip list identifiers, "Re: ", and "was:"
6927 (setq subject (message-simplify-subject subject))
6930 (message-pop-to-buffer (message-buffer-name "followup" from newsgroups))
6932 (setq message-reply-headers
6933 (vector 0 subject from date message-id references 0 0 ""))
6936 `((Subject . ,subject)
6939 (list (cons 'Newsgroups to-newsgroups)))
6940 (follow-to follow-to)
6941 ((and followup-to message-use-followup-to)
6944 ((equal (downcase followup-to) "poster")
6945 (if (or (eq message-use-followup-to 'use)
6946 (message-y-or-n-p "Obey Followup-To: poster? " t "\
6947 You should normally obey the Followup-To: header.
6949 `Followup-To: poster' sends your response via e-mail instead of news.
6951 A typical situation where `Followup-To: poster' is used is when the poster
6952 does not read the newsgroup, so he wouldn't see any replies sent to it.
6954 You may customize the variable `message-use-followup-to', if you
6955 want to get rid of this query permanently."))
6957 (setq message-this-is-news nil)
6958 (cons 'To (or mrt reply-to from "")))
6959 (cons 'Newsgroups newsgroups)))
6961 (if (or (equal followup-to newsgroups)
6962 (not (eq message-use-followup-to 'ask))
6964 (concat "Obey Followup-To: " followup-to "? ") t "\
6965 You should normally obey the Followup-To: header.
6967 `Followup-To: " followup-to "'
6968 directs your response to " (if (string-match "," followup-to)
6969 "the specified newsgroups"
6970 "that newsgroup only") ".
6972 If a message is posted to several newsgroups, Followup-To is often
6973 used to direct the following discussion to one newsgroup only,
6974 because discussions that are spread over several newsgroup tend to
6975 be fragmented and very difficult to follow.
6977 Also, some source/announcement newsgroups are not intended for discussion;
6978 responses here are directed to other newsgroups.
6980 You may customize the variable `message-use-followup-to', if you
6981 want to get rid of this query permanently."))
6982 (cons 'Newsgroups followup-to)
6983 (cons 'Newsgroups newsgroups))))))
6985 `((Newsgroups . ,posted-to)))
6987 `((Newsgroups . ,newsgroups))))
6988 ,@(and distribution (list (cons 'Distribution distribution)))
6990 (not (or (equal (downcase mct) "never")
6991 (equal (downcase mct) "nobody"))))
6992 (list (cons 'Cc (if (or (equal (downcase mct) "always")
6993 (equal (downcase mct) "poster"))
6994 (or mrt reply-to from "")
6999 (defun message-is-yours-p ()
7000 "Non-nil means current article is yours.
7001 If you have added 'cancel-messages to `message-shoot-gnksa-feet', all articles
7002 are yours except those that have Cancel-Lock header not belonging to you.
7003 Instead of shooting GNKSA feet, you should modify `message-alternative-emails'
7004 regexp to match all of yours addresses."
7005 ;; Canlock-logic as suggested by Per Abrahamsen
7006 ;; <abraham@dina.kvl.dk>
7008 ;; IF article has cancel-lock THEN
7009 ;; IF we can verify it THEN
7012 ;; error: cancellock: article is not yours
7014 ;; Use old rules, comparing sender...
7017 (message-narrow-to-head-1)
7018 (if (message-fetch-field "Cancel-Lock")
7019 (if (null (canlock-verify))
7021 (error "Failed to verify Cancel-lock: This article is not yours"))
7024 (message-gnksa-enable-p 'cancel-messages)
7025 (and (setq sender (message-fetch-field "sender"))
7026 (string-equal (downcase sender)
7027 (downcase (message-make-sender))))
7028 ;; Email address in From field equals to our address
7029 (and (setq from (message-fetch-field "from"))
7031 (downcase (car (mail-header-parse-address from)))
7032 (downcase (car (mail-header-parse-address
7033 (message-make-from))))))
7034 ;; Email address in From field matches
7035 ;; 'message-alternative-emails' regexp
7037 message-alternative-emails
7039 message-alternative-emails
7040 (car (mail-header-parse-address from))))))))))
7043 (defun message-cancel-news (&optional arg)
7044 "Cancel an article you posted.
7045 If ARG, allow editing of the cancellation message."
7047 (unless (message-news-p)
7048 (error "This is not a news article; canceling is impossible"))
7049 (let (from newsgroups message-id distribution buf)
7051 ;; Get header info from original article.
7053 (message-narrow-to-head-1)
7054 (setq from (message-fetch-field "from")
7055 newsgroups (message-fetch-field "newsgroups")
7056 message-id (message-fetch-field "message-id" t)
7057 distribution (message-fetch-field "distribution")))
7058 ;; Make sure that this article was written by the user.
7059 (unless (message-is-yours-p)
7060 (error "This article is not yours"))
7061 (when (yes-or-no-p "Do you really want to cancel this article? ")
7062 ;; Make control message.
7065 (setq buf (set-buffer (get-buffer-create " *message cancel*"))))
7067 (insert "Newsgroups: " newsgroups "\n"
7069 "Subject: cmsg cancel " message-id "\n"
7070 "Control: cancel " message-id "\n"
7072 (concat "Distribution: " distribution "\n")
7074 mail-header-separator "\n"
7075 message-cancel-message)
7076 (run-hooks 'message-cancel-hook)
7078 (message "Canceling your article...")
7079 (if (let ((message-syntax-checks
7080 'dont-check-for-anything-just-trust-me))
7081 (funcall message-send-news-function))
7082 (message "Canceling your article...done"))
7083 (kill-buffer buf))))))
7086 (defun message-supersede ()
7087 "Start composing a message to supersede the current message.
7088 This is done simply by taking the old article and adding a Supersedes
7089 header line with the old Message-ID."
7091 (let ((cur (current-buffer)))
7092 ;; Check whether the user owns the article that is to be superseded.
7093 (unless (message-is-yours-p)
7094 (error "This article is not yours"))
7095 ;; Get a normal message buffer.
7096 (message-pop-to-buffer (message-buffer-name "supersede"))
7097 (insert-buffer-substring cur)
7099 (message-narrow-to-head-1)
7100 ;; Remove unwanted headers.
7101 (when message-ignored-supersedes-headers
7102 (message-remove-header message-ignored-supersedes-headers t))
7103 (goto-char (point-min))
7104 (if (not (re-search-forward "^Message-ID: " nil t))
7105 (error "No Message-ID in this article")
7106 (replace-match "Supersedes: " t t))
7107 (goto-char (point-max))
7108 (insert mail-header-separator)
7113 (defun message-recover ()
7114 "Reread contents of current buffer from its last auto-save file."
7116 (let ((file-name (make-auto-save-file-name)))
7117 (cond ((save-window-excursion
7118 (with-output-to-temp-buffer "*Directory*"
7119 (with-current-buffer standard-output
7120 (fundamental-mode)) ; for Emacs 20.4+
7121 (buffer-disable-undo standard-output)
7122 (let ((default-directory "/"))
7124 "ls" nil standard-output nil "-l" file-name)))
7125 (yes-or-no-p (format "Recover auto save file %s? " file-name)))
7126 (let ((buffer-read-only nil))
7128 (insert-file-contents file-name nil)))
7129 (t (error "message-recover cancelled")))))
7131 ;;; Washing Subject:
7133 (defun message-wash-subject (subject)
7134 "Remove junk like \"Re:\", \"(fwd)\", etc. added to subject string SUBJECT.
7135 Previous forwarders, replyers, etc. may add it."
7138 (goto-char (point-min))
7139 ;; strip Re/Fwd stuff off the beginning
7140 (while (re-search-forward
7141 "\\([Rr][Ee]:\\|[Ff][Ww][Dd]\\(\\[[0-9]*\\]\\)?:\\|[Ff][Ww]:\\)" nil t)
7144 ;; and gnus-style forwards [foo@bar.com] subject
7145 (goto-char (point-min))
7146 (while (re-search-forward "\\[[^ \t]*\\(@\\|\\.\\)[^ \t]*\\]" nil t)
7150 (goto-char (point-max))
7151 (while (re-search-backward "([Ff][Ww][Dd])" nil t)
7154 ;; and finally, any whitespace that was left-over
7155 (goto-char (point-min))
7156 (while (re-search-forward "^[ \t]+" nil t)
7158 (goto-char (point-max))
7159 (while (re-search-backward "[ \t]+$" nil t)
7164 ;;; Forwarding messages.
7166 (defvar message-forward-decoded-p nil
7167 "Non-nil means the original message is decoded.")
7169 (defun message-forward-subject-name-subject (subject)
7170 "Generate a SUBJECT for a forwarded message.
7171 The form is: [Source] Subject, where if the original message was mail,
7172 Source is the name of the sender, and if the original message was
7173 news, Source is the list of newsgroups is was posted to."
7174 (let* ((group (message-fetch-field "newsgroups"))
7175 (from (message-fetch-field "from"))
7178 (gnus-group-decoded-name group)
7180 (car (gnus-extract-address-components from))
7181 (cadr (gnus-extract-address-components from))))
7184 (if message-forward-decoded-p
7186 (mail-decode-encoded-word-string prefix))
7189 (defun message-forward-subject-author-subject (subject)
7190 "Generate a SUBJECT for a forwarded message.
7191 The form is: [Source] Subject, where if the original message was mail,
7192 Source is the sender, and if the original message was news, Source is
7193 the list of newsgroups is was posted to."
7194 (let* ((group (message-fetch-field "newsgroups"))
7197 (gnus-group-decoded-name group)
7198 (or (message-fetch-field "from")
7201 (if message-forward-decoded-p
7203 (mail-decode-encoded-word-string prefix))
7206 (defun message-forward-subject-fwd (subject)
7207 "Generate a SUBJECT for a forwarded message.
7208 The form is: Fwd: Subject, where Subject is the original subject of
7210 (if (string-match "^Fwd: " subject)
7212 (concat "Fwd: " subject)))
7214 (defun message-make-forward-subject ()
7215 "Return a Subject header suitable for the message in the current buffer."
7218 (message-narrow-to-head-1)
7219 (let ((funcs message-make-forward-subject-function)
7220 (subject (message-fetch-field "Subject")))
7223 (if message-forward-decoded-p
7225 (mail-decode-encoded-word-string subject))
7227 (when message-wash-forwarded-subjects
7228 (setq subject (message-wash-subject subject)))
7229 ;; Make sure funcs is a list.
7232 (setq funcs (list funcs)))
7233 ;; Apply funcs in order, passing subject generated by previous
7234 ;; func to the next one.
7235 (dolist (func funcs)
7236 (when (functionp func)
7237 (setq subject (funcall func subject))))
7240 (defvar gnus-article-decoded-p)
7244 (defun message-forward (&optional news digest)
7245 "Forward the current message via mail.
7246 Optional NEWS will use news to forward instead of mail.
7247 Optional DIGEST will use digest to forward."
7249 (let* ((cur (current-buffer))
7250 (message-forward-decoded-p
7251 (if (local-variable-p 'gnus-article-decoded-p (current-buffer))
7252 gnus-article-decoded-p ;; In an article buffer.
7253 message-forward-decoded-p))
7254 (subject (message-make-forward-subject)))
7256 (message-news nil subject)
7257 (message-mail nil subject))
7258 (message-forward-make-body cur digest)))
7260 (defun message-forward-make-body-plain (forward-buffer)
7262 "\n-------------------- Start of forwarded message --------------------\n")
7264 (contents (with-current-buffer forward-buffer (buffer-string)))
7266 (unless (featurep 'xemacs)
7267 (unless (mm-multibyte-string-p contents)
7268 (error "Attempt to insert unibyte string from the buffer \"%s\"\
7269 to the multibyte buffer \"%s\""
7270 (if (bufferp forward-buffer)
7271 (buffer-name forward-buffer)
7274 (insert (mm-with-multibyte-buffer
7277 (goto-char (point-min))
7278 (when (looking-at "From ")
7279 (replace-match "X-From-Line: "))
7281 (unless (bolp) (insert "\n"))
7284 "-------------------- End of forwarded message --------------------\n")
7285 (message-remove-ignored-headers b e)))
7287 (defun message-remove-ignored-headers (b e)
7288 (when message-forward-ignored-headers
7290 (narrow-to-region b e)
7292 (narrow-to-region (point)
7293 (or (search-forward "\n\n" nil t) (point)))
7294 (let ((ignored (if (stringp message-forward-ignored-headers)
7295 (list message-forward-ignored-headers)
7296 message-forward-ignored-headers)))
7297 (dolist (elem ignored)
7298 (message-remove-header elem t))))))
7300 (defun message-forward-make-body-mime (forward-buffer)
7302 (insert "\n\n<#part type=message/rfc822 disposition=inline raw=t>\n")
7304 (narrow-to-region (point) (point))
7305 (mml-insert-buffer forward-buffer)
7306 (goto-char (point-min))
7307 (when (looking-at "From ")
7308 (replace-match "X-From-Line: "))
7309 (goto-char (point-max)))
7310 (insert "<#/part>\n")
7311 ;; Consider there is no illegible text.
7312 (add-text-properties
7314 `(no-illegible-text t rear-nonsticky t start-open t))))
7316 (defun message-forward-make-body-mml (forward-buffer)
7317 (insert "\n\n<#mml type=message/rfc822 disposition=inline>\n")
7318 (let ((b (point)) e)
7319 (if (not message-forward-decoded-p)
7320 (let ((contents (with-current-buffer forward-buffer (buffer-string))))
7321 (unless (featurep 'xemacs)
7322 (unless (mm-multibyte-string-p contents)
7323 (error "Attempt to insert unibyte string from the buffer \"%s\"\
7324 to the multibyte buffer \"%s\""
7325 (if (bufferp forward-buffer)
7326 (buffer-name forward-buffer)
7329 (insert (mm-with-multibyte-buffer
7332 (goto-char (point-min))
7333 (when (looking-at "From ")
7334 (replace-match "X-From-Line: "))
7337 (narrow-to-region (point) (point))
7338 (mml-insert-buffer forward-buffer)
7339 (goto-char (point-min))
7340 (when (looking-at "From ")
7341 (replace-match "X-From-Line: "))
7342 (goto-char (point-max))))
7344 (insert "<#/mml>\n")
7345 (when (and (not message-forward-decoded-p)
7346 message-forward-ignored-headers)
7347 (message-remove-ignored-headers b e))))
7349 (defun message-forward-make-body-digest-plain (forward-buffer)
7351 "\n-------------------- Start of forwarded message --------------------\n")
7352 (mml-insert-buffer forward-buffer)
7354 "\n-------------------- End of forwarded message --------------------\n"))
7356 (defun message-forward-make-body-digest-mime (forward-buffer)
7357 (insert "\n<#multipart type=digest>\n")
7358 (let ((b (point)) e)
7359 (insert-buffer-substring forward-buffer)
7361 (insert "<#/multipart>\n")
7363 (narrow-to-region b e)
7365 (narrow-to-region (point)
7366 (or (search-forward "\n\n" nil t) (point)))
7367 (delete-region (point-min) (point-max)))))
7369 (defun message-forward-make-body-digest (forward-buffer)
7370 (if message-forward-as-mime
7371 (message-forward-make-body-digest-mime forward-buffer)
7372 (message-forward-make-body-digest-plain forward-buffer)))
7374 (autoload 'mm-uu-dissect-text-parts "mm-uu")
7375 (autoload 'mm-uu-dissect "mm-uu")
7377 (defun message-signed-or-encrypted-p (&optional dont-emulate-mime handles)
7378 "Say whether the current buffer contains signed or encrypted message.
7379 If DONT-EMULATE-MIME is nil, this function does the MIME emulation on
7380 messages that don't conform to PGP/MIME described in RFC2015. HANDLES
7381 is for the internal use."
7383 (let ((mm-decrypt-option 'never)
7384 (mm-verify-option 'never))
7385 (if (setq handles (mm-dissect-buffer nil t))
7386 (unless dont-emulate-mime
7387 (mm-uu-dissect-text-parts handles))
7388 (unless dont-emulate-mime
7389 (setq handles (mm-uu-dissect))))))
7390 ;; Check text/plain message in which there is a signed or encrypted
7391 ;; body that has been encoded by B or Q.
7392 (unless (or handles dont-emulate-mime)
7393 (let ((cur (current-buffer))
7394 (mm-decrypt-option 'never)
7395 (mm-verify-option 'never))
7397 (insert-buffer-substring cur)
7398 (when (setq handles (mm-dissect-buffer t t))
7400 (bufferp (car handles))
7401 (mm-destroy-parts handles))
7402 (equal (mm-handle-media-type handles) "text/plain"))
7404 (mm-decode-content-transfer-encoding
7405 (mm-handle-encoding handles))
7406 (setq handles (mm-uu-dissect)))
7407 (setq handles nil))))))
7411 (dolist (handle (if (stringp (car handles))
7412 (if (member (car handles)
7413 '("multipart/signed"
7414 "multipart/encrypted"))
7418 (if (stringp (car handle))
7419 (when (message-signed-or-encrypted-p dont-emulate-mime handle)
7421 (when (and (bufferp (car handle))
7422 (equal (mm-handle-media-type handle)
7424 (with-current-buffer (mm-handle-buffer handle)
7425 (when (message-signed-or-encrypted-p dont-emulate-mime)
7426 (throw 'found t)))))))
7427 (mm-destroy-parts handles))))
7430 (defun message-forward-make-body (forward-buffer &optional digest)
7431 ;; Put point where we want it before inserting the forwarded
7433 (if message-forward-before-signature
7435 (goto-char (point-max)))
7437 (message-forward-make-body-digest forward-buffer)
7438 (if message-forward-as-mime
7439 (if (and message-forward-show-mml
7440 (not (and (eq message-forward-show-mml 'best)
7441 ;; Use the raw form in the body if it contains
7442 ;; signed or encrypted message so as not to be
7443 ;; destroyed by re-encoding.
7444 (with-current-buffer forward-buffer
7446 (message-signed-or-encrypted-p)
7448 (message-forward-make-body-mml forward-buffer)
7449 (message-forward-make-body-mime forward-buffer))
7450 (message-forward-make-body-plain forward-buffer)))
7451 (message-position-point))
7453 (declare-function rmail-toggle-header "rmail" (&optional arg))
7456 (defun message-forward-rmail-make-body (forward-buffer)
7457 (save-window-excursion
7458 (set-buffer forward-buffer)
7459 (if (rmail-msg-is-pruned)
7460 (if (fboundp 'rmail-msg-restore-non-pruned-header)
7461 (rmail-msg-restore-non-pruned-header) ; Emacs 22
7462 (rmail-toggle-header 0)))) ; Emacs 23
7463 (message-forward-make-body forward-buffer))
7465 ;; Fixme: Should have defcustom.
7467 (defun message-insinuate-rmail ()
7468 "Let RMAIL use message to forward."
7470 (setq rmail-enable-mime-composing t)
7471 (setq rmail-insert-mime-forwarded-message-function
7472 'message-forward-rmail-make-body))
7474 (defvar message-inhibit-body-encoding nil)
7477 (defun message-resend (address)
7478 "Resend the current article to ADDRESS."
7480 (list (message-read-from-minibuffer "Resend message to: ")))
7481 (message "Resending message to %s..." address)
7483 (let ((cur (current-buffer))
7485 ;; We first set up a normal mail buffer.
7486 (unless (message-mail-user-agent)
7487 (set-buffer (get-buffer-create " *message resend*"))
7488 (let ((inhibit-read-only t))
7490 (let ((message-this-is-mail t)
7491 message-generate-hashcash
7493 (message-setup `((To . ,address))))
7494 ;; Insert our usual headers.
7495 (message-generate-headers '(From Date To Message-ID))
7496 (message-narrow-to-headers)
7497 ;; Remove X-Draft-From header etc.
7498 (message-remove-header message-ignored-mail-headers t)
7499 ;; Rename them all to "Resent-*".
7500 (goto-char (point-min))
7501 (while (re-search-forward "^[A-Za-z]" nil t)
7506 (let ((inhibit-read-only t))
7507 (delete-region (point) (point-max)))
7509 ;; Insert the message to be resent.
7510 (insert-buffer-substring cur)
7511 (goto-char (point-min))
7512 (search-forward "\n\n")
7515 (narrow-to-region beg (point))
7516 (message-remove-header message-ignored-resent-headers t)
7517 (goto-char (point-max)))
7518 (insert mail-header-separator)
7519 ;; Rename all old ("Also-")Resent headers.
7520 (while (re-search-backward "^\\(Also-\\)*Resent-" beg t)
7523 ;; Quote any "From " lines at the beginning.
7525 (when (looking-at "From ")
7526 (replace-match "X-From-Line: "))
7528 (let ((message-inhibit-body-encoding
7529 ;; Don't do any further encoding if it looks like the
7530 ;; message has already been encoded.
7531 (let ((case-fold-search t))
7532 (re-search-forward "^mime-version:" nil t)))
7533 (message-inhibit-ecomplete t)
7534 message-required-mail-headers
7535 message-generate-hashcash
7536 rfc2047-encode-encoded-words)
7537 (message-send-mail))
7538 (kill-buffer (current-buffer)))
7539 (message "Resending message to %s...done" address)))
7542 (defun message-bounce ()
7543 "Re-mail the current message.
7544 This only makes sense if the current message is a bounce message that
7545 contains some mail you have written which has been bounced back to
7548 (let ((handles (mm-dissect-buffer t))
7550 (message-pop-to-buffer (message-buffer-name "bounce"))
7551 (if (stringp (car handles))
7552 ;; This is a MIME bounce.
7553 (mm-insert-part (car (last handles)))
7554 ;; This is a non-MIME bounce, so we try to remove things
7556 (mm-insert-part handles)
7558 (goto-char (point-min))
7559 (re-search-forward "\n\n+" nil t)
7560 (setq boundary (point))
7561 ;; We remove everything before the bounced mail.
7562 (if (or (re-search-forward message-unsent-separator nil t)
7564 (search-forward "\n\n" nil 'move)
7565 (re-search-backward "^Return-Path:.*\n" boundary t)))
7568 (delete-region (point-min)
7569 (if (re-search-forward "^[^ \n\t]+:" nil t)
7572 (goto-char boundary)
7573 (when (re-search-backward "^.?From .*\n" nil t)
7574 (delete-region (match-beginning 0) (match-end 0)))))
7577 (message-narrow-to-head-1)
7578 (message-remove-header message-ignored-bounced-headers t)
7579 (goto-char (point-max))
7580 (insert mail-header-separator))
7581 (message-position-point)))
7584 ;;; Interactive entry points for new message buffers.
7588 (defun message-mail-other-window (&optional to subject)
7589 "Like `message-mail' command, but display mail buffer in another window."
7591 (unless (message-mail-user-agent)
7592 (let ((pop-up-windows t)
7593 (special-display-buffer-names nil)
7594 (special-display-regexps nil)
7595 (same-window-buffer-names nil)
7596 (same-window-regexps nil))
7597 (message-pop-to-buffer (message-buffer-name "mail" to))))
7598 (let ((message-this-is-mail t))
7599 (message-setup `((To . ,(or to "")) (Subject . ,(or subject "")))
7600 nil nil nil 'switch-to-buffer-other-window)))
7603 (defun message-mail-other-frame (&optional to subject)
7604 "Like `message-mail' command, but display mail buffer in another frame."
7606 (unless (message-mail-user-agent)
7607 (let ((pop-up-frames t)
7608 (special-display-buffer-names nil)
7609 (special-display-regexps nil)
7610 (same-window-buffer-names nil)
7611 (same-window-regexps nil))
7612 (message-pop-to-buffer (message-buffer-name "mail" to))))
7613 (let ((message-this-is-mail t))
7614 (message-setup `((To . ,(or to "")) (Subject . ,(or subject "")))
7615 nil nil nil 'switch-to-buffer-other-frame)))
7618 (defun message-news-other-window (&optional newsgroups subject)
7619 "Start editing a news article to be sent."
7621 (let ((pop-up-windows t)
7622 (special-display-buffer-names nil)
7623 (special-display-regexps nil)
7624 (same-window-buffer-names nil)
7625 (same-window-regexps nil))
7626 (message-pop-to-buffer (message-buffer-name "posting" nil newsgroups)))
7627 (let ((message-this-is-news t))
7628 (message-setup `((Newsgroups . ,(or newsgroups ""))
7629 (Subject . ,(or subject ""))))))
7632 (defun message-news-other-frame (&optional newsgroups subject)
7633 "Start editing a news article to be sent."
7635 (let ((pop-up-frames t)
7636 (special-display-buffer-names nil)
7637 (special-display-regexps nil)
7638 (same-window-buffer-names nil)
7639 (same-window-regexps nil))
7640 (message-pop-to-buffer (message-buffer-name "posting" nil newsgroups)))
7641 (let ((message-this-is-news t))
7642 (message-setup `((Newsgroups . ,(or newsgroups ""))
7643 (Subject . ,(or subject ""))))))
7647 ;; This code should be moved to underline.el (from which it is stolen).
7650 (defun message-bold-region (start end)
7651 "Bold all nonblank characters in the region.
7652 Works by overstriking characters.
7653 Called from program, takes two arguments START and END
7654 which specify the range to operate on."
7657 (let ((end1 (make-marker)))
7658 (move-marker end1 (max start end))
7659 (goto-char (min start end))
7660 (while (< (point) end1)
7661 (or (looking-at "[_\^@- ]")
7662 (insert (char-after) "\b"))
7663 (forward-char 1)))))
7666 (defun message-unbold-region (start end)
7667 "Remove all boldness (overstruck characters) in the region.
7668 Called from program, takes two arguments START and END
7669 which specify the range to operate on."
7672 (let ((end1 (make-marker)))
7673 (move-marker end1 (max start end))
7674 (goto-char (min start end))
7675 (while (search-forward "\b" end1 t)
7676 (if (eq (char-after) (char-after (- (point) 2)))
7677 (delete-char -2))))))
7679 (defun message-exchange-point-and-mark ()
7680 "Exchange point and mark, but don't activate region if it was inactive."
7681 (goto-char (prog1 (mark t)
7682 (set-marker (mark-marker) (point)))))
7684 (defalias 'message-make-overlay 'make-overlay)
7685 (defalias 'message-delete-overlay 'delete-overlay)
7686 (defalias 'message-overlay-put 'overlay-put)
7687 (defun message-kill-all-overlays ()
7688 (if (featurep 'xemacs)
7689 (map-extents (lambda (extent ignore) (delete-extent extent)))
7690 (mapcar #'delete-overlay (overlays-in (point-min) (point-max)))))
7692 ;; Support for toolbar
7693 (defvar tool-bar-mode)
7695 ;; Note: The :set function in the `message-tool-bar*' variables will only
7696 ;; affect _new_ message buffers. We might add a function that walks thru all
7697 ;; message-mode buffers and force the update.
7698 (defun message-tool-bar-update (&optional symbol value)
7699 "Update message mode toolbar.
7700 Setter function for custom variables."
7701 (setq-default message-tool-bar-map nil)
7703 ;; When used as ":set" function:
7704 (set-default symbol value)))
7706 (defcustom message-tool-bar (if (eq gmm-tool-bar-style 'gnome)
7707 'message-tool-bar-gnome
7708 'message-tool-bar-retro)
7709 "Specifies the message mode tool bar.
7711 It can be either a list or a symbol refering to a list. See
7712 `gmm-tool-bar-from-list' for the format of the list. The
7713 default key map is `message-mode-map'.
7715 Pre-defined symbols include `message-tool-bar-gnome' and
7716 `message-tool-bar-retro'."
7717 :type '(repeat gmm-tool-bar-list-item)
7718 :type '(choice (const :tag "GNOME style" message-tool-bar-gnome)
7719 (const :tag "Retro look" message-tool-bar-retro)
7720 (repeat :tag "User defined list" gmm-tool-bar-item)
7722 :version "23.1" ;; No Gnus
7723 :initialize 'custom-initialize-default
7724 :set 'message-tool-bar-update
7727 (defcustom message-tool-bar-gnome
7728 '((ispell-message "spell" nil
7730 :visible (or (not (boundp 'flyspell-mode))
7731 (not flyspell-mode)))
7732 (flyspell-buffer "spell" t
7734 :visible (and (boundp 'flyspell-mode)
7736 :help "Flyspell whole buffer")
7737 (message-send-and-exit "mail/send" t :label "Send")
7738 (message-dont-send "mail/save-draft")
7739 (mml-attach-file "attach" mml-mode-map :vert-only t)
7740 (mml-preview "mail/preview" mml-mode-map)
7741 (mml-secure-message-sign-encrypt "lock" mml-mode-map :visible nil)
7742 (message-insert-importance-high "important" nil :visible nil)
7743 (message-insert-importance-low "unimportant" nil :visible nil)
7744 (message-insert-disposition-notification-to "receipt" nil :visible nil))
7745 "List of items for the message tool bar (GNOME style).
7747 See `gmm-tool-bar-from-list' for details on the format of the list."
7748 :type '(repeat gmm-tool-bar-item)
7749 :version "23.1" ;; No Gnus
7750 :initialize 'custom-initialize-default
7751 :set 'message-tool-bar-update
7754 (defcustom message-tool-bar-retro
7755 '(;; Old Emacs 21 icon for consistency.
7756 (message-send-and-exit "gnus/mail-send")
7757 (message-kill-buffer "close")
7758 (message-dont-send "cancel")
7759 (mml-attach-file "attach" mml-mode-map)
7760 (ispell-message "spell")
7761 (mml-preview "preview" mml-mode-map)
7762 (message-insert-importance-high "gnus/important")
7763 (message-insert-importance-low "gnus/unimportant")
7764 (message-insert-disposition-notification-to "gnus/receipt"))
7765 "List of items for the message tool bar (retro style).
7767 See `gmm-tool-bar-from-list' for details on the format of the list."
7768 :type '(repeat gmm-tool-bar-item)
7769 :version "23.1" ;; No Gnus
7770 :initialize 'custom-initialize-default
7771 :set 'message-tool-bar-update
7774 (defcustom message-tool-bar-zap-list
7775 '(new-file open-file dired kill-buffer write-file
7776 print-buffer customize help)
7777 "List of icon items from the global tool bar.
7778 These items are not displayed on the message mode tool bar.
7780 See `gmm-tool-bar-from-list' for the format of the list."
7781 :type 'gmm-tool-bar-zap-list
7782 :version "23.1" ;; No Gnus
7783 :initialize 'custom-initialize-default
7784 :set 'message-tool-bar-update
7787 (defvar image-load-path)
7789 (defun message-make-tool-bar (&optional force)
7790 "Make a message mode tool bar from `message-tool-bar-list'.
7791 When FORCE, rebuild the tool bar."
7792 (when (and (not (featurep 'xemacs))
7793 (boundp 'tool-bar-mode)
7795 (or (not message-tool-bar-map) force))
7796 (setq message-tool-bar-map
7798 (gmm-image-load-path-for-library "message"
7799 "mail/save-draft.xpm"
7801 (image-load-path (cons (car load-path)
7802 (when (boundp 'image-load-path)
7804 (gmm-tool-bar-from-list message-tool-bar
7805 message-tool-bar-zap-list
7806 'message-mode-map))))
7807 message-tool-bar-map)
7809 ;;; Group name completion.
7811 (defcustom message-newgroups-header-regexp
7812 "^\\(Newsgroups\\|Followup-To\\|Posted-To\\|Gcc\\):"
7813 "Regexp that match headers that lists groups."
7817 (defcustom message-completion-alist
7818 (list (cons message-newgroups-header-regexp 'message-expand-group)
7819 '("^\\(Resent-\\)?\\(To\\|B?Cc\\):" . message-expand-name)
7820 '("^\\(Reply-To\\|From\\|Mail-Followup-To\\|Mail-Copies-To\\):"
7821 . message-expand-name)
7822 '("^\\(Disposition-Notification-To\\|Return-Receipt-To\\):"
7823 . message-expand-name))
7824 "Alist of (RE . FUN). Use FUN for completion on header lines matching RE."
7827 :type '(alist :key-type regexp :value-type function))
7829 (defcustom message-expand-name-databases
7831 "List of databases to try for name completion (`message-expand-name').
7832 Each element is a symbol and can be `bbdb' or `eudc'."
7834 :type '(set (const bbdb) (const eudc)))
7836 (defcustom message-tab-body-function nil
7837 "*Function to execute when `message-tab' (TAB) is executed in the body.
7838 If nil, the function bound in `text-mode-map' or `global-map' is executed."
7841 :link '(custom-manual "(message)Various Commands")
7842 :type '(choice (const nil)
7845 (declare-function mail-abbrev-in-expansion-header-p "mailabbrev" ())
7847 (defun message-tab ()
7848 "Complete names according to `message-completion-alist'.
7849 Execute function specified by `message-tab-body-function' when not in
7853 ((if (and (boundp 'completion-fail-discreetly)
7854 (fboundp 'completion-at-point))
7855 (let ((completion-fail-discreetly t)) (completion-at-point))
7856 (funcall (or (message-completion-function) #'ignore)))
7857 ;; Completion was performed; nothing else to do.
7859 (message-tab-body-function (funcall message-tab-body-function))
7860 (t (funcall (or (lookup-key text-mode-map "\t")
7861 (lookup-key global-map "\t")
7862 'indent-relative)))))
7864 (defvar mail-abbrev-mode-regexp)
7866 (defun message-completion-function ()
7867 (let ((alist message-completion-alist))
7869 (let ((mail-abbrev-mode-regexp (caar alist)))
7870 (not (mail-abbrev-in-expansion-header-p))))
7871 (setq alist (cdr alist)))
7877 (let ((standard-output (current-buffer)))
7878 (eval '(display-completion-list nil "")))
7879 (defalias 'message-display-completion-list 'display-completion-list))
7880 (error ;; Don't use `wrong-number-of-arguments' here because of XEmacs.
7881 (defun message-display-completion-list (completions &optional ignore)
7882 "Display the list of completions, COMPLETIONS, using `standard-output'."
7883 (display-completion-list completions)))))
7885 (defun message-expand-group ()
7886 "Expand the group name under point."
7887 (let* ((b (save-excursion
7892 (skip-chars-forward "^:")
7895 (skip-chars-backward "^, \t\n") (point))))
7896 (completion-ignore-case t)
7897 (e (progn (skip-chars-forward "^,\t\n ") (point)))
7898 (hashtb (and (boundp 'gnus-active-hashtb) gnus-active-hashtb)))
7899 (message-completion-in-region e b hashtb)))
7901 (defalias 'message-completion-in-region
7902 (if (fboundp 'completion-in-region)
7903 'completion-in-region
7904 (lambda (e b hashtb)
7905 (let* ((string (buffer-substring b e))
7906 (completions (all-completions string hashtb))
7908 (delete-region b (point))
7910 ((= (length completions) 1)
7911 (if (string= (car completions) string)
7914 (message "Only matching group"))
7915 (insert (car completions))))
7916 ((and (setq comp (try-completion string hashtb))
7917 (not (string= comp string)))
7922 (message "No matching groups")
7923 (save-selected-window
7924 (pop-to-buffer "*Completions*")
7925 (buffer-disable-undo)
7926 (let ((buffer-read-only nil))
7928 (let ((standard-output (current-buffer)))
7929 (message-display-completion-list (sort completions 'string<)
7931 (setq buffer-read-only nil)
7932 (goto-char (point-min))
7933 (delete-region (point)
7934 (progn (forward-line 3) (point))))))))))))
7936 (defun message-expand-name ()
7937 (cond ((and (memq 'eudc message-expand-name-databases)
7938 (boundp 'eudc-protocol)
7940 (eudc-expand-inline))
7941 ((and (memq 'bbdb message-expand-name-databases)
7942 (fboundp 'bbdb-complete-name))
7943 (let ((starttick (buffer-modified-tick)))
7944 (or (bbdb-complete-name)
7945 ;; Apparently, bbdb-complete-name can return nil even when
7946 ;; completion took place. So let's double check the buffer was
7948 (/= starttick (buffer-modified-tick)))))
7954 (defun message-talkative-question (ask question show &rest text)
7955 "Call FUNCTION with argument QUESTION; optionally display TEXT... args.
7956 If SHOW is non-nil, the arguments TEXT... are displayed in a temp buffer.
7957 The following arguments may contain lists of values."
7959 (setq text (message-flatten-list text)))
7960 (save-window-excursion
7961 (with-output-to-temp-buffer " *MESSAGE information message*"
7962 (with-current-buffer " *MESSAGE information message*"
7963 (fundamental-mode) ; for Emacs 20.4+
7965 (goto-char (point-min))))
7966 (funcall ask question))
7967 (funcall ask question)))
7969 (defun message-flatten-list (list)
7970 "Return a new, flat list that contains all elements of LIST.
7972 \(message-flatten-list '(1 (2 3 (4 5 (6))) 7))
7975 (apply 'append (mapcar 'message-flatten-list list)))
7979 (defun message-generate-new-buffer-clone-locals (name &optional varstr)
7980 "Create and return a buffer with name based on NAME using `generate-new-buffer'.
7981 Then clone the local variables and values from the old buffer to the
7982 new one, cloning only the locals having a substring matching the
7984 (let ((oldbuf (current-buffer)))
7985 (with-current-buffer (generate-new-buffer name)
7986 (message-clone-locals oldbuf varstr)
7989 (defun message-clone-locals (buffer &optional varstr)
7990 "Clone the local variables from BUFFER to the current buffer."
7991 (let ((locals (with-current-buffer buffer (buffer-local-variables)))
7992 (regexp "^gnus\\|^nn\\|^message\\|^sendmail\\|^smtp\\|^user-mail-address"))
7995 (when (and (consp local)
7997 (string-match regexp (symbol-name (car local)))
7999 (string-match varstr (symbol-name (car local)))))
8001 (set (make-local-variable (car local))
8009 (defun message-encode-message-body ()
8010 (unless message-inhibit-body-encoding
8011 (let ((mail-parse-charset (or mail-parse-charset
8012 message-default-charset))
8013 (case-fold-search t)
8014 lines content-type-p)
8017 (narrow-to-region (point) (point-max))
8018 (let ((new (mml-generate-mime)))
8020 (delete-region (point-min) (point-max))
8022 (goto-char (point-min))
8023 (if (eq (aref new 0) ?\n)
8025 (search-forward "\n\n")
8026 (setq lines (buffer-substring (point-min) (1- (point))))
8027 (delete-region (point-min) (point))))))
8029 (message-narrow-to-headers-or-head)
8030 (message-remove-header "Mime-Version")
8031 (goto-char (point-max))
8032 (insert "MIME-Version: 1.0\n")
8035 (setq content-type-p
8037 (re-search-backward "^Content-Type:" nil t))))
8039 (message-narrow-to-headers-or-head)
8040 (message-remove-first-header "Content-Type")
8041 (message-remove-first-header "Content-Transfer-Encoding"))
8042 ;; We always make sure that the message has a Content-Type
8043 ;; header. This is because some broken MTAs and MUAs get
8044 ;; awfully confused when confronted with a message with a
8045 ;; MIME-Version header and without a Content-Type header. For
8046 ;; instance, Solaris' /usr/bin/mail.
8047 (unless content-type-p
8048 (goto-char (point-min))
8049 ;; For unknown reason, MIME-Version doesn't exist.
8050 (when (re-search-forward "^MIME-Version:" nil t)
8052 (insert "Content-Type: text/plain; charset=us-ascii\n"))))))
8054 (defun message-read-from-minibuffer (prompt &optional initial-contents)
8055 "Read from the minibuffer while providing abbrev expansion."
8056 (if (fboundp 'mail-abbrevs-setup)
8057 (let ((mail-abbrev-mode-regexp "")
8058 (minibuffer-setup-hook 'mail-abbrevs-setup)
8059 (minibuffer-local-map message-minibuffer-local-map))
8060 (read-from-minibuffer prompt initial-contents))
8061 (let ((minibuffer-setup-hook 'mail-abbrev-minibuffer-setup-hook)
8062 (minibuffer-local-map message-minibuffer-local-map))
8063 (read-string prompt initial-contents))))
8065 (defun message-use-alternative-email-as-from ()
8066 "Set From field of the outgoing message to the first matching
8067 address in `message-alternative-emails', looking at To, Cc and
8068 From headers in the original article."
8069 (require 'mail-utils)
8070 (let* ((fields '("To" "Cc" "From"))
8073 (mail-strip-quoted-names
8074 (mapconcat 'message-fetch-reply-field fields ","))
8078 (if (string-match message-alternative-emails (car emails))
8079 (setq email (car emails)
8082 (unless (or (not email) (equal email user-mail-address))
8083 (message-remove-header "From")
8084 (goto-char (point-max))
8085 (insert "From: " (let ((user-mail-address email)) (message-make-from))
8088 (defun message-options-get (symbol)
8089 (cdr (assq symbol message-options)))
8091 (defun message-options-set (symbol value)
8092 (let ((the-cons (assq symbol message-options)))
8095 (setcdr the-cons value)
8096 (setq message-options (delq the-cons message-options)))
8098 (push (cons symbol value) message-options))))
8101 (defun message-options-set-recipient ()
8103 (message-narrow-to-headers-or-head)
8104 (message-options-set 'message-sender
8105 (mail-strip-quoted-names
8106 (message-fetch-field "from")))
8107 (message-options-set 'message-recipients
8108 (mail-strip-quoted-names
8109 (let ((to (message-fetch-field "to"))
8110 (cc (message-fetch-field "cc"))
8111 (bcc (message-fetch-field "bcc")))
8114 (if (and to cc) ", ")
8116 (if (and (or to cc) bcc) ", ")
8119 (defun message-hide-headers ()
8120 "Hide headers based on the `message-hidden-headers' variable."
8121 (let ((regexps (if (stringp message-hidden-headers)
8122 (list message-hidden-headers)
8123 message-hidden-headers))
8124 (inhibit-point-motion-hooks t)
8125 (after-change-functions nil)
8126 (end-of-headers (point-min)))
8130 (message-narrow-to-headers)
8131 (goto-char (point-min))
8133 (if (not (message-hide-header-p regexps))
8134 (message-next-header)
8135 (let ((begin (point))
8137 (message-next-header)
8138 (setq header (buffer-substring begin (point))
8139 header-len (- (point) begin))
8140 (delete-region begin (point))
8141 (goto-char end-of-headers)
8143 (setq end-of-headers
8144 (+ end-of-headers header-len))))))))
8145 (narrow-to-region end-of-headers (point-max))))
8147 (defun message-hide-header-p (regexps)
8150 (when (eq (car regexps) 'not)
8153 (dolist (regexp regexps)
8154 (setq result (or result (looking-at regexp))))
8159 (declare-function ecomplete-add-item "ecomplete" (type key text))
8160 (declare-function ecomplete-save "ecomplete" ())
8162 (defun message-put-addresses-in-ecomplete ()
8163 (require 'ecomplete)
8164 (dolist (header '("to" "cc" "from" "reply-to"))
8165 (let ((value (message-field-value header)))
8166 (dolist (string (mail-header-parse-addresses value 'raw))
8168 (gnus-replace-in-string
8169 (gnus-replace-in-string string "^ +\\| +$" "") "\n" ""))
8170 (ecomplete-add-item 'mail (car (mail-header-parse-address string))
8174 (autoload 'ecomplete-display-matches "ecomplete")
8176 (defun message-display-abbrev (&optional choose)
8177 "Display the next possible abbrev for the text before point."
8178 (interactive (list t))
8179 (when (and (memq (char-after (point-at-bol)) '(?C ?T ?\t ? ))
8180 (message-point-in-header-p)
8183 (while (and (memq (char-after) '(?\t ? ))
8184 (zerop (forward-line -1))))
8185 (looking-at "To:\\|Cc:")))
8186 (let* ((end (point))
8187 (start (save-excursion
8188 (and (re-search-backward "[\n\t ]" nil t)
8190 (word (when start (buffer-substring start end)))
8191 (match (when (and word
8192 (not (zerop (length word))))
8193 (ecomplete-display-matches 'mail word choose))))
8194 (when (and choose match)
8195 (delete-region start end)
8198 ;; To send pre-formatted letters like the example below, you can use
8199 ;; `message-send-form-letter':
8200 ;; --8<---------------cut here---------------start------------->8---
8201 ;; To: alice@invalid.invalid
8202 ;; Subject: Verification of your contact information
8203 ;; From: Contact verification <admin@foo.invalid>
8204 ;; --text follows this line--
8206 ;; please verify that your contact information is still valid:
8207 ;; Alice A, A avenue 11, 1111 A town, Austria
8208 ;; ----------next form letter message follows this line----------
8209 ;; To: bob@invalid.invalid
8210 ;; Subject: Verification of your contact information
8211 ;; From: Contact verification <admin@foo.invalid>
8212 ;; --text follows this line--
8214 ;; please verify that your contact information is still valid:
8215 ;; Bob, B street 22, 22222 Be town, Belgium
8216 ;; ----------next form letter message follows this line----------
8217 ;; To: charlie@invalid.invalid
8218 ;; Subject: Verification of your contact information
8219 ;; From: Contact verification <admin@foo.invalid>
8220 ;; --text follows this line--
8222 ;; please verify that your contact information is still valid:
8223 ;; Charlie Chaplin, C plaza 33, 33333 C town, Chile
8224 ;; --8<---------------cut here---------------end--------------->8---
8226 ;; FIXME: What is the most common term (circular letter, form letter, serial
8227 ;; letter, standard letter) for such kind of letter? See also
8228 ;; <http://en.wikipedia.org/wiki/Form_letter>
8230 ;; FIXME: Maybe extent message-mode's font-lock support to recognize
8231 ;; `message-form-letter-separator', i.e. highlight each message like a single
8234 (defcustom message-form-letter-separator
8235 "\n----------next form letter message follows this line----------\n"
8236 "Separator for `message-send-form-letter'."
8237 ;; :group 'message-form-letter
8238 :group 'message-various
8239 :version "23.1" ;; No Gnus
8242 (defcustom message-send-form-letter-delay 1
8243 "Delay in seconds when sending a message with `message-send-form-letter'.
8244 Only used when `message-send-form-letter' is called with non-nil
8246 ;; :group 'message-form-letter
8247 :group 'message-various
8248 :version "23.1" ;; No Gnus
8251 (defun message-send-form-letter (&optional force)
8252 "Sent all form letter messages from current buffer.
8253 Unless FORCE, prompt before sending.
8255 The messages are separated by `message-form-letter-separator'.
8256 Header and body are separated by `mail-header-separator'."
8258 (let ((sent 0) (skipped 0)
8262 (goto-char (point-min))
8265 end (if (search-forward message-form-letter-separator nil t)
8266 (- (point) (length message-form-letter-separator) -1)
8270 (buffer-substring-no-properties start end))
8271 (setq buff (generate-new-buffer "*mail - form letter*"))
8272 (with-current-buffer buff
8275 (setq to (message-fetch-field "To"))
8276 (switch-to-buffer buff)
8278 (sit-for message-send-form-letter-delay))
8280 (y-or-n-p (format "Send message to `%s'? " to)))
8282 (setq sent (1+ sent))
8283 (message-send-and-exit))
8284 (message (format "Message to `%s' skipped." to))
8285 (setq skipped (1+ skipped)))
8286 (when (buffer-live-p buff)
8287 (kill-buffer buff))))
8288 (message "%s message(s) sent, %s skipped." sent skipped)))
8290 (defun message-replace-header (header new-value &optional after force)
8291 "Remove HEADER and insert the NEW-VALUE.
8292 If AFTER, insert after this header. If FORCE, insert new field
8293 even if NEW-VALUE is empty."
8294 ;; Similar to `nnheader-replace-header' but for message buffers.
8297 (message-narrow-to-headers)
8298 (message-remove-header header))
8299 (when (or force (> (length new-value) 0))
8301 (message-position-on-field header after)
8302 (message-position-on-field header))
8303 (insert new-value))))
8305 (defcustom message-recipients-without-full-name
8306 (list "ding@gnus.org"
8308 "emacs-devel@gnu.org"
8309 "emacs-pretest-bug@gnu.org"
8310 "bug-gnu-emacs@gnu.org")
8311 "Mail addresses that have no full name.
8312 Used in `message-simplify-recipients'."
8313 ;; Maybe the addresses could be extracted from
8314 ;; `gnus-parameter-to-list-alist'?
8315 :type '(choice (const :tag "None" nil)
8317 :version "23.1" ;; No Gnus
8318 :group 'message-headers)
8320 (defun message-simplify-recipients ()
8322 (dolist (hdr '("Cc" "To"))
8323 (message-replace-header
8327 (if (and message-recipients-without-full-name
8329 (regexp-opt message-recipients-without-full-name)
8333 (message-make-from (car addrcomp) (cadr addrcomp))
8335 (when (message-fetch-field hdr)
8336 (mail-extract-address-components
8337 (message-fetch-field hdr) t))
8340 (when (featurep 'xemacs)
8341 (require 'messagexmas)
8342 (message-xmas-redefine))
8346 (run-hooks 'message-load-hook)
8349 ;; coding: iso-8859-1
8352 ;;; message.el ends here