1 ;;; message.el --- composing mail and news messages
3 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
4 ;; 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
6 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
7 ;; Keywords: mail, news
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software: you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation, either version 3 of the License, or
14 ;; (at your option) any later version.
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
26 ;; This mode provides mail-sending facilities from within Emacs. It
27 ;; consists mainly of large chunks of code from the sendmail.el,
28 ;; gnus-msg.el and rnewspost.el files.
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-fcc-handler-function 'message-output
133 "*A function called to save outgoing articles.
134 This function will be called with the name of the file to store the
135 article in. The default function is `message-output' which saves in Unix
137 :type '(radio (function-item message-output)
138 (function :tag "Other"))
139 :group 'message-sending)
141 (defcustom message-fcc-externalize-attachments nil
142 "If non-nil, attachments are included as external parts in Fcc copies."
145 :group 'message-sending)
147 (defcustom message-courtesy-message
148 "The following message is a courtesy copy of an article\nthat has been posted to %s as well.\n\n"
149 "*This is inserted at the start of a mailed copy of a posted message.
150 If the string contains the format spec \"%s\", the Newsgroups
151 the article has been posted to will be inserted there.
152 If this variable is nil, no such courtesy message will be added."
153 :group 'message-sending
154 :type '(radio string (const nil)))
156 (defcustom message-ignored-bounced-headers
157 "^\\(Received\\|Return-Path\\|Delivered-To\\):"
158 "*Regexp that matches headers to be removed in resent bounced mail."
159 :group 'message-interface
162 (defcustom message-from-style 'default
163 "*Specifies how \"From\" headers look.
165 If nil, they contain just the return address like:
167 If `parens', they look like:
168 king@grassland.com (Elvis Parsley)
169 If `angles', they look like:
170 Elvis Parsley <king@grassland.com>
172 Otherwise, most addresses look like `angles', but they look like
173 `parens' if `angles' would need quoting and `parens' would not."
175 :type '(choice (const :tag "simple" nil)
179 :group 'message-headers)
181 (defcustom message-insert-canlock t
182 "Whether to insert a Cancel-Lock header in news postings."
184 :group 'message-headers
187 (defcustom message-syntax-checks
188 (if message-insert-canlock '((sender . disabled)) nil)
189 ;; Guess this one shouldn't be easy to customize...
190 "*Controls what syntax checks should not be performed on outgoing posts.
191 To disable checking of long signatures, for instance, add
192 `(signature . disabled)' to this list.
194 Don't touch this variable unless you really know what you're doing.
196 Checks include `approved', `bogus-recipient', `continuation-headers',
197 `control-chars', `empty', `existing-newsgroups', `from', `illegible-text',
198 `invisible-text', `long-header-lines', `long-lines', `message-id',
199 `multiple-headers', `new-text', `newsgroups', `quoting-style',
200 `repeated-newsgroups', `reply-to', `sender', `sendsys', `shoot',
201 `shorten-followup-to', `signature', `size', `subject', `subject-cmsg'
202 and `valid-newsgroups'."
204 :type '(repeat sexp)) ; Fixme: improve this
206 (defcustom message-required-headers '((optional . References)
208 "*Headers to be generated or prompted for when sending a message.
209 Also see `message-required-news-headers' and
210 `message-required-mail-headers'."
213 :group 'message-headers
214 :link '(custom-manual "(message)Message Headers")
215 :type '(repeat sexp))
217 (defcustom message-draft-headers '(References From Date)
218 "*Headers to be generated when saving a draft message."
221 :group 'message-headers
222 :link '(custom-manual "(message)Message Headers")
223 :type '(repeat sexp))
225 (defcustom message-required-news-headers
226 '(From Newsgroups Subject Date Message-ID
227 (optional . Organization)
228 (optional . User-Agent))
229 "*Headers to be generated or prompted for when posting an article.
230 RFC977 and RFC1036 require From, Date, Newsgroups, Subject,
231 Message-ID. Organization, Lines, In-Reply-To, Expires, and
232 User-Agent are optional. If you don't want message to insert some
233 header, remove it from this list."
235 :group 'message-headers
236 :link '(custom-manual "(message)Message Headers")
237 :type '(repeat sexp))
239 (defcustom message-required-mail-headers
240 '(From Subject Date (optional . In-Reply-To) Message-ID
241 (optional . User-Agent))
242 "*Headers to be generated or prompted for when mailing a message.
243 It is recommended that From, Date, To, Subject and Message-ID be
244 included. Organization and User-Agent are optional."
246 :group 'message-headers
247 :link '(custom-manual "(message)Message Headers")
248 :type '(repeat sexp))
250 (defcustom message-deletable-headers '(Message-ID Date Lines)
251 "Headers to be deleted if they already exist and were generated by message previously."
252 :group 'message-headers
253 :link '(custom-manual "(message)Message Headers")
256 (defcustom message-ignored-news-headers
257 "^NNTP-Posting-Host:\\|^Xref:\\|^[BGF]cc:\\|^Resent-Fcc:\\|^X-Draft-From:\\|^X-Gnus-Agent-Meta-Information:"
258 "*Regexp of headers to be removed unconditionally before posting."
260 :group 'message-headers
261 :link '(custom-manual "(message)Message Headers")
262 :type '(repeat :value-to-internal (lambda (widget value)
263 (custom-split-regexp-maybe value))
264 :match (lambda (widget value)
266 (widget-editable-list-match widget value)))
269 (defcustom message-ignored-mail-headers
270 "^[GF]cc:\\|^Resent-Fcc:\\|^Xref:\\|^X-Draft-From:\\|^X-Gnus-Agent-Meta-Information:"
271 "*Regexp of headers to be removed unconditionally before mailing."
273 :group 'message-headers
274 :link '(custom-manual "(message)Mail Headers")
277 (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:"
278 "*Header lines matching this regexp will be deleted before posting.
279 It's best to delete old Path and Date headers before posting to avoid
281 :group 'message-interface
282 :link '(custom-manual "(message)Superseding")
283 :type '(repeat :value-to-internal (lambda (widget value)
284 (custom-split-regexp-maybe value))
285 :match (lambda (widget value)
287 (widget-editable-list-match widget value)))
290 (defcustom message-subject-re-regexp
291 "^[ \t]*\\([Rr][Ee]\\(\\[[0-9]*\\]\\)*:[ \t]*\\)*[ \t]*"
292 "*Regexp matching \"Re: \" in the subject line."
293 :group 'message-various
294 :link '(custom-manual "(message)Message Headers")
297 ;;; Start of variables adopted from `message-utils.el'.
299 (defcustom message-subject-trailing-was-query 'ask
300 "*What to do with trailing \"(was: <old subject>)\" in subject lines.
301 If nil, leave the subject unchanged. If it is the symbol `ask', query
302 the user what do do. In this case, the subject is matched against
303 `message-subject-trailing-was-ask-regexp'. If
304 `message-subject-trailing-was-query' is t, always strip the trailing
305 old subject. In this case, `message-subject-trailing-was-regexp' is
308 :type '(choice (const :tag "never" nil)
309 (const :tag "always strip" t)
311 :link '(custom-manual "(message)Message Headers")
312 :group 'message-various)
314 (defcustom message-subject-trailing-was-ask-regexp
315 "[ \t]*\\([[(]+[Ww][Aa][Ss][ \t]*.*[\])]+\\)"
316 "*Regexp matching \"(was: <old subject>)\" in the subject line.
318 The function `message-strip-subject-trailing-was' uses this regexp if
319 `message-subject-trailing-was-query' is set to the symbol `ask'. If
320 the variable is t instead of `ask', use
321 `message-subject-trailing-was-regexp' instead.
323 It is okay to create some false positives here, as the user is asked."
325 :group 'message-various
326 :link '(custom-manual "(message)Message Headers")
329 (defcustom message-subject-trailing-was-regexp
330 "[ \t]*\\((*[Ww][Aa][Ss]:[ \t]*.*)\\)"
331 "*Regexp matching \"(was: <old subject>)\" in the subject line.
333 If `message-subject-trailing-was-query' is set to t, the subject is
334 matched against `message-subject-trailing-was-regexp' in
335 `message-strip-subject-trailing-was'. You should use a regexp creating very
336 few false positives here."
338 :group 'message-various
339 :link '(custom-manual "(message)Message Headers")
342 ;;; marking inserted text
344 (defcustom message-mark-insert-begin
345 "--8<---------------cut here---------------start------------->8---\n"
346 "How to mark the beginning of some inserted text."
349 :link '(custom-manual "(message)Insertion Variables")
350 :group 'message-various)
352 (defcustom message-mark-insert-end
353 "--8<---------------cut here---------------end--------------->8---\n"
354 "How to mark the end of some inserted text."
357 :link '(custom-manual "(message)Insertion Variables")
358 :group 'message-various)
360 (defcustom message-archive-header "X-No-Archive: Yes\n"
361 "Header to insert when you don't want your article to be archived.
362 Archives \(such as groups.google.com\) respect this header."
365 :link '(custom-manual "(message)Header Commands")
366 :group 'message-various)
368 (defcustom message-archive-note
369 "X-No-Archive: Yes - save http://groups.google.com/"
370 "Note to insert why you wouldn't want this posting archived.
371 If nil, don't insert any text in the body."
373 :type '(radio string (const nil))
374 :link '(custom-manual "(message)Header Commands")
375 :group 'message-various)
377 ;;; Crossposts and Followups
378 ;; inspired by JoH-followup-to by Jochem Huhman <joh at gmx.de>
379 ;; new suggestions by R. Weikusat <rw at another.de>
381 (defvar message-cross-post-old-target nil
382 "Old target for cross-posts or follow-ups.")
383 (make-variable-buffer-local 'message-cross-post-old-target)
385 (defcustom message-cross-post-default t
386 "When non-nil `message-cross-post-followup-to' will perform a crosspost.
387 If nil, `message-cross-post-followup-to' will only do a followup. Note that
388 you can explicitly override this setting by calling
389 `message-cross-post-followup-to' with a prefix."
392 :group 'message-various)
394 (defcustom message-cross-post-note "Crosspost & Followup-To: "
395 "Note to insert before signature to notify of cross-post and follow-up."
398 :group 'message-various)
400 (defcustom message-followup-to-note "Followup-To: "
401 "Note to insert before signature to notify of follow-up only."
404 :group 'message-various)
406 (defcustom message-cross-post-note-function 'message-cross-post-insert-note
407 "Function to use to insert note about Crosspost or Followup-To.
408 The function will be called with four arguments. The function should not only
409 insert a note, but also ensure old notes are deleted. See the documentation
410 for `message-cross-post-insert-note'."
413 :group 'message-various)
415 ;;; End of variables adopted from `message-utils.el'.
417 (defcustom message-signature-separator "^-- $"
418 "Regexp matching the signature separator.
419 This variable is used to strip off the signature from quoted text
420 when `message-cite-function' is
421 `message-cite-original-without-signature'. Most useful values
422 are \"^-- $\" (strict) and \"^-- *$\" (loose; allow missing
424 :type '(choice (const :tag "strict" "^-- $")
425 (const :tag "loose" "^-- *$")
427 :version "22.3" ;; Gnus 5.10.12 (changed default)
428 :link '(custom-manual "(message)Various Message Variables")
429 :group 'message-various)
431 (defcustom message-elide-ellipsis "\n[...]\n\n"
432 "*The string which is inserted for elided text."
434 :link '(custom-manual "(message)Various Commands")
435 :group 'message-various)
437 (defcustom message-interactive t
438 "Non-nil means when sending a message wait for and display errors.
439 A value of nil means let mailer mail back a message to report errors."
441 :group 'message-sending
443 :link '(custom-manual "(message)Sending Variables")
446 (defcustom message-confirm-send nil
447 "When non-nil, ask for confirmation when sending a message."
448 :group 'message-sending
450 :version "23.1" ;; No Gnus
451 :link '(custom-manual "(message)Sending Variables")
454 (defcustom message-generate-new-buffers 'unique
455 "*Say whether to create a new message buffer to compose a message.
456 Valid values include:
459 Generate the buffer name in the Message way (e.g., *mail*, *news*,
460 *mail to whom*, *news on group*, etc.) and continue editing in the
461 existing buffer of that name. If there is no such buffer, it will
465 Create the new buffer with the name generated in the Message way.
468 Similar to `unique' but the buffer name begins with \"*unsent \".
471 Similar to nil but the buffer name is simpler like *mail message*.
474 If this is a function, call that function with three parameters:
475 The type, the To address and the group name (any of these may be nil).
476 The function should return the new buffer name."
477 :group 'message-buffers
478 :link '(custom-manual "(message)Message Buffers")
479 :type '(choice (const nil)
480 (sexp :tag "unique" :format "unique\n" :value unique
481 :match (lambda (widget value) (memq value '(unique t))))
484 (function :format "\n %{%t%}: %v")))
486 (defcustom message-kill-buffer-on-exit nil
487 "*Non-nil means that the message buffer will be killed after sending a message."
488 :group 'message-buffers
489 :link '(custom-manual "(message)Message Buffers")
492 (defcustom message-kill-buffer-query t
493 "*Non-nil means that killing a modified message buffer has to be confirmed.
494 This is used by `message-kill-buffer'."
495 :version "23.1" ;; No Gnus
496 :group 'message-buffers
499 (defvar gnus-local-organization)
500 (defcustom message-user-organization
501 (or (and (boundp 'gnus-local-organization)
502 (stringp gnus-local-organization)
503 gnus-local-organization)
504 (getenv "ORGANIZATION")
506 "*String to be used as an Organization header.
507 If t, use `message-user-organization-file'."
508 :group 'message-headers
509 :type '(choice string
510 (const :tag "consult file" t)))
512 (defcustom message-user-organization-file
514 (dolist (f (list "/etc/organization"
515 "/etc/news/organization"
516 "/usr/lib/news/organization"))
517 (when (file-readable-p f)
520 "*Local news organization file."
522 :link '(custom-manual "(message)News Headers")
523 :group 'message-headers)
525 (defcustom message-make-forward-subject-function
526 #'message-forward-subject-name-subject
527 "*List of functions called to generate subject headers for forwarded messages.
528 The subject generated by the previous function is passed into each
531 The provided functions are:
533 * `message-forward-subject-author-subject' Source of article (author or
534 newsgroup), in brackets followed by the subject
535 * `message-forward-subject-name-subject' Source of article (name of author
536 or newsgroup), in brackets followed by the subject
537 * `message-forward-subject-fwd' Subject of article with 'Fwd:' prepended
539 :group 'message-forwarding
540 :link '(custom-manual "(message)Forwarding")
541 :type '(radio (function-item message-forward-subject-author-subject)
542 (function-item message-forward-subject-fwd)
543 (function-item message-forward-subject-name-subject)
544 (repeat :tag "List of functions" function)))
546 (defcustom message-forward-as-mime t
547 "*Non-nil means forward messages as an inline/rfc822 MIME section.
548 Otherwise, directly inline the old message in the forwarded message."
550 :group 'message-forwarding
551 :link '(custom-manual "(message)Forwarding")
554 (defcustom message-forward-show-mml 'best
555 "*Non-nil means show forwarded messages as MML (decoded from MIME).
556 Otherwise, forwarded messages are unchanged.
557 Can also be the symbol `best' to indicate that MML should be
558 used, except when it is a bad idea to use MML. One example where
559 it is a bad idea is when forwarding a signed or encrypted
560 message, because converting MIME to MML would invalidate the
563 :group 'message-forwarding
564 :type '(choice (const :tag "use MML" t)
565 (const :tag "don't use MML " nil)
566 (const :tag "use MML when appropriate" best)))
568 (defcustom message-forward-before-signature t
569 "*Non-nil means put forwarded message before signature, else after."
570 :group 'message-forwarding
573 (defcustom message-wash-forwarded-subjects nil
574 "*Non-nil means try to remove as much cruft as possible from the subject.
575 Done before generating the new subject of a forward."
576 :group 'message-forwarding
577 :link '(custom-manual "(message)Forwarding")
580 (defcustom message-ignored-resent-headers
581 ;; `Delivered-To' needs to be removed because some mailers use it to
582 ;; detect loops, so if you resend a message to an address that ultimately
583 ;; comes back to you (e.g. a mailing-list to which you subscribe, in which
584 ;; case you may be removed from the list on the grounds that mail to you
585 ;; bounced with a "mailing loop" error).
586 "^Return-receipt\\|^X-Gnus\\|^Gnus-Warning:\\|^>?From \\|^Delivered-To:"
587 "*All headers that match this regexp will be deleted when resending a message."
588 :group 'message-interface
589 :link '(custom-manual "(message)Resending")
590 :type '(repeat :value-to-internal (lambda (widget value)
591 (custom-split-regexp-maybe value))
592 :match (lambda (widget value)
594 (widget-editable-list-match widget value)))
597 (defcustom message-forward-ignored-headers "^Content-Transfer-Encoding:\\|^X-Gnus"
598 "*All headers that match this regexp will be deleted when forwarding a message."
600 :group 'message-forwarding
601 :type '(repeat :value-to-internal (lambda (widget value)
602 (custom-split-regexp-maybe value))
603 :match (lambda (widget value)
605 (widget-editable-list-match widget value)))
608 (defcustom message-ignored-cited-headers "."
609 "*Delete these headers from the messages you yank."
610 :group 'message-insertion
611 :link '(custom-manual "(message)Insertion Variables")
614 (defcustom message-cite-prefix-regexp
615 (if (string-match "[[:digit:]]" "1")
616 ;; Support POSIX? XEmacs 21.5.27 doesn't.
617 "\\([ \t]*[_.[:word:]]+>+\\|[ \t]*[]>|}]\\)+"
618 ;; ?-, ?_ or ?. MUST NOT be in syntax entry w.
619 (let (non-word-constituents)
620 (with-syntax-table text-mode-syntax-table
621 (setq non-word-constituents
623 (if (string-match "\\w" "_") "" "_")
624 (if (string-match "\\w" ".") "" "."))))
625 (if (equal non-word-constituents "")
626 "\\([ \t]*\\(\\w\\)+>+\\|[ \t]*[]>|}]\\)+"
627 (concat "\\([ \t]*\\(\\w\\|["
628 non-word-constituents
629 "]\\)+>+\\|[ \t]*[]>|}]\\)+"))))
630 "*Regexp matching the longest possible citation prefix on a line."
632 :group 'message-insertion
633 :link '(custom-manual "(message)Insertion Variables")
635 :set (lambda (symbol value)
637 (custom-set-default symbol value)
638 (if (boundp 'gnus-message-cite-prefix-regexp)
639 (setq gnus-message-cite-prefix-regexp
640 (concat "^\\(?:" value "\\)"))))))
642 (defcustom message-cancel-message "I am canceling my own article.\n"
643 "Message to be inserted in the cancel message."
644 :group 'message-interface
645 :link '(custom-manual "(message)Canceling News")
648 (defun message-send-mail-function ()
649 "Return suitable value for the variable `message-send-mail-function'."
650 (cond ((and (require 'sendmail)
651 (boundp 'sendmail-program)
653 (executable-find sendmail-program))
654 'message-send-mail-with-sendmail)
655 ((and (locate-library "smtpmail")
656 (boundp 'smtpmail-default-smtp-server)
657 smtpmail-default-smtp-server)
658 'message-smtpmail-send-it)
659 ((locate-library "mailclient")
660 'message-send-mail-with-mailclient)
662 (error "Don't know how to send mail. Please customize `message-send-mail-function'"))))
664 ;; Useful to set in site-init.el
665 (defcustom message-send-mail-function
666 (cond ((eq send-mail-function 'smtpmail-send-it) 'message-smtpmail-send-it)
667 ((eq send-mail-function 'feedmail-send-it) 'feedmail-send-it)
668 ((eq send-mail-function 'mailclient-send-it)
669 'message-send-mail-with-mailclient)
670 (t (message-send-mail-function)))
671 "Function to call to send the current buffer as mail.
672 The headers should be delimited by a line whose contents match the
673 variable `mail-header-separator'.
675 Valid values include `message-send-mail-with-sendmail'
676 `message-send-mail-with-mh', `message-send-mail-with-qmail',
677 `message-smtpmail-send-it', `smtpmail-send-it',
678 `feedmail-send-it' and `message-send-mail-with-mailclient'. The
679 default is system dependent and determined by the function
680 `message-send-mail-function'.
682 See also `send-mail-function'."
683 :type '(radio (function-item message-send-mail-with-sendmail)
684 (function-item message-send-mail-with-mh)
685 (function-item message-send-mail-with-qmail)
686 (function-item message-smtpmail-send-it)
687 (function-item smtpmail-send-it)
688 (function-item feedmail-send-it)
689 (function-item message-send-mail-with-mailclient
690 :tag "Use Mailclient package")
691 (function :tag "Other"))
692 :group 'message-sending
694 :initialize 'custom-initialize-default
695 :link '(custom-manual "(message)Mail Variables")
696 :group 'message-mail)
698 (defcustom message-send-news-function 'message-send-news
699 "Function to call to send the current buffer as news.
700 The headers should be delimited by a line whose contents match the
701 variable `mail-header-separator'."
702 :group 'message-sending
704 :link '(custom-manual "(message)News Variables")
707 (defcustom message-reply-to-function nil
708 "If non-nil, function that should return a list of headers.
709 This function should pick out addresses from the To, Cc, and From headers
710 and respond with new To and Cc headers."
711 :group 'message-interface
712 :link '(custom-manual "(message)Reply")
713 :type '(choice function (const nil)))
715 (defcustom message-wide-reply-to-function nil
716 "If non-nil, function that should return a list of headers.
717 This function should pick out addresses from the To, Cc, and From headers
718 and respond with new To and Cc headers."
719 :group 'message-interface
720 :link '(custom-manual "(message)Wide Reply")
721 :type '(choice function (const nil)))
723 (defcustom message-followup-to-function nil
724 "If non-nil, function that should return a list of headers.
725 This function should pick out addresses from the To, Cc, and From headers
726 and respond with new To and Cc headers."
727 :group 'message-interface
728 :link '(custom-manual "(message)Followup")
729 :type '(choice function (const nil)))
731 (defcustom message-extra-wide-headers nil
732 "If non-nil, a list of additional address headers.
733 These are used when composing a wide reply."
734 :group 'message-sending
735 :type '(repeat string))
737 (defcustom message-use-followup-to 'ask
738 "*Specifies what to do with Followup-To header.
739 If nil, always ignore the header. If it is t, use its value, but
740 query before using the \"poster\" value. If it is the symbol `ask',
741 always query the user whether to use the value. If it is the symbol
742 `use', always use the value."
743 :group 'message-interface
744 :link '(custom-manual "(message)Followup")
745 :type '(choice (const :tag "ignore" nil)
746 (const :tag "use & query" t)
750 (defcustom message-use-mail-followup-to 'use
751 "*Specifies what to do with Mail-Followup-To header.
752 If nil, always ignore the header. If it is the symbol `ask', always
753 query the user whether to use the value. If it is the symbol `use',
754 always use the value."
756 :group 'message-interface
757 :link '(custom-manual "(message)Mailing Lists")
758 :type '(choice (const :tag "ignore" nil)
762 (defcustom message-subscribed-address-functions nil
763 "*Specifies functions for determining list subscription.
764 If nil, do not attempt to determine list subscription with functions.
765 If non-nil, this variable contains a list of functions which return
766 regular expressions to match lists. These functions can be used in
767 conjunction with `message-subscribed-regexps' and
768 `message-subscribed-addresses'."
770 :group 'message-interface
771 :link '(custom-manual "(message)Mailing Lists")
772 :type '(repeat sexp))
774 (defcustom message-subscribed-address-file nil
775 "*A file containing addresses the user is subscribed to.
776 If nil, do not look at any files to determine list subscriptions. If
777 non-nil, each line of this file should be a mailing list address."
779 :group 'message-interface
780 :link '(custom-manual "(message)Mailing Lists")
781 :type '(radio file (const nil)))
783 (defcustom message-subscribed-addresses nil
784 "*Specifies a list of addresses the user is subscribed to.
785 If nil, do not use any predefined list subscriptions. This list of
786 addresses can be used in conjunction with
787 `message-subscribed-address-functions' and `message-subscribed-regexps'."
789 :group 'message-interface
790 :link '(custom-manual "(message)Mailing Lists")
791 :type '(repeat string))
793 (defcustom message-subscribed-regexps nil
794 "*Specifies a list of addresses the user is subscribed to.
795 If nil, do not use any predefined list subscriptions. This list of
796 regular expressions can be used in conjunction with
797 `message-subscribed-address-functions' and `message-subscribed-addresses'."
799 :group 'message-interface
800 :link '(custom-manual "(message)Mailing Lists")
801 :type '(repeat regexp))
803 (defcustom message-allow-no-recipients 'ask
804 "Specifies what to do when there are no recipients other than Gcc/Fcc.
805 If it is the symbol `always', the posting is allowed. If it is the
806 symbol `never', the posting is not allowed. If it is the symbol
807 `ask', you are prompted."
809 :group 'message-interface
810 :link '(custom-manual "(message)Message Headers")
811 :type '(choice (const always)
815 (defcustom message-sendmail-f-is-evil nil
816 "*Non-nil means don't add \"-f username\" to the sendmail command line.
817 Doing so would be even more evil than leaving it out."
818 :group 'message-sending
819 :link '(custom-manual "(message)Mail Variables")
822 (defcustom message-sendmail-envelope-from nil
823 "*Envelope-from when sending mail with sendmail.
824 If this is nil, use `user-mail-address'. If it is the symbol
825 `header', use the From: header of the message."
827 :type '(choice (string :tag "From name")
828 (const :tag "Use From: header from message" header)
829 (const :tag "Use `user-mail-address'" nil))
830 :link '(custom-manual "(message)Mail Variables")
831 :group 'message-sending)
833 (defcustom message-sendmail-extra-arguments nil
834 "Additional arguments to `sendmail-program'."
835 ;; E.g. '("-a" "account") for msmtp
836 :version "23.1" ;; No Gnus
837 :type '(repeat string)
838 ;; :link '(custom-manual "(message)Mail Variables")
839 :group 'message-sending)
841 ;; qmail-related stuff
842 (defcustom message-qmail-inject-program "/var/qmail/bin/qmail-inject"
843 "Location of the qmail-inject program."
844 :group 'message-sending
845 :link '(custom-manual "(message)Mail Variables")
848 (defcustom message-qmail-inject-args nil
849 "Arguments passed to qmail-inject programs.
850 This should be a list of strings, one string for each argument.
851 It may also be a function.
853 For e.g., if you wish to set the envelope sender address so that bounces
854 go to the right place or to deal with listserv's usage of that address, you
855 might set this variable to '(\"-f\" \"you@some.where\")."
856 :group 'message-sending
857 :link '(custom-manual "(message)Mail Variables")
858 :type '(choice (function)
861 (defvar gnus-post-method)
862 (defvar gnus-select-method)
863 (defcustom message-post-method
864 (cond ((and (boundp 'gnus-post-method)
865 (listp gnus-post-method)
868 ((boundp 'gnus-select-method)
871 "*Method used to post news.
872 Note that when posting from inside Gnus, for instance, this
873 variable isn't used."
875 :group 'message-sending
876 ;; This should be the `gnus-select-method' widget, but that might
877 ;; create a dependence to `gnus.el'.
880 ;; FIXME: This should be a temporary workaround until someone implements a
881 ;; proper solution. If a crash happens while replying, the auto-save file
882 ;; will *not* have a `References:' header if `message-generate-headers-first'
883 ;; is nil. See: http://article.gmane.org/gmane.emacs.gnus.general/51138
884 (defcustom message-generate-headers-first '(references)
885 "Which headers should be generated before starting to compose a message.
886 If t, generate all required headers. This can also be a list of headers to
887 generate. The variables `message-required-news-headers' and
888 `message-required-mail-headers' specify which headers to generate.
890 Note that the variable `message-deletable-headers' specifies headers which
891 are to be deleted and then re-generated before sending, so this variable
892 will not have a visible effect for those headers."
893 :group 'message-headers
894 :link '(custom-manual "(message)Message Headers")
895 :type '(choice (const :tag "None" nil)
896 (const :tag "References" '(references))
898 (repeat (sexp :tag "Header"))))
900 (defcustom message-fill-column 72
901 "Column beyond which automatic line-wrapping should happen.
902 Local value for message buffers. If non-nil, also turn on
903 auto-fill in message buffers."
904 :group 'message-various
905 ;; :link '(custom-manual "(message)Message Headers")
906 :type '(choice (const :tag "Don't turn on auto fill" nil)
909 (defcustom message-setup-hook nil
910 "Normal hook, run each time a new outgoing message is initialized.
911 The function `message-setup' runs this hook."
912 :group 'message-various
913 :link '(custom-manual "(message)Various Message Variables")
916 (defcustom message-cancel-hook nil
917 "Hook run when cancelling articles."
918 :group 'message-various
919 :link '(custom-manual "(message)Various Message Variables")
922 (defcustom message-signature-setup-hook nil
923 "Normal hook, run each time a new outgoing message is initialized.
924 It is run after the headers have been inserted and before
925 the signature is inserted."
926 :group 'message-various
927 :link '(custom-manual "(message)Various Message Variables")
930 (defcustom message-mode-hook nil
931 "Hook run in message mode buffers."
932 :group 'message-various
935 (defcustom message-header-hook nil
936 "Hook run in a message mode buffer narrowed to the headers."
937 :group 'message-various
940 (defcustom message-header-setup-hook nil
941 "Hook called narrowed to the headers when setting up a message buffer."
942 :group 'message-various
943 :link '(custom-manual "(message)Various Message Variables")
946 (defcustom message-minibuffer-local-map
947 (let ((map (make-sparse-keymap 'message-minibuffer-local-map)))
948 (set-keymap-parent map minibuffer-local-map)
950 "Keymap for `message-read-from-minibuffer'."
952 :group 'message-various)
954 (defcustom message-citation-line-function 'message-insert-citation-line
955 "*Function called to insert the \"Whomever writes:\" line.
957 Predefined functions include `message-insert-citation-line' and
958 `message-insert-formatted-citation-line' (see the variable
959 `message-citation-line-format').
961 Note that Gnus provides a feature where the reader can click on
962 `writes:' to hide the cited text. If you change this line too much,
963 people who read your message will have to change their Gnus
964 configuration. See the variable `gnus-cite-attribution-suffix'."
966 (function-item :tag "plain" message-insert-citation-line)
967 (function-item :tag "formatted" message-insert-formatted-citation-line)
968 (function :tag "Other"))
969 :link '(custom-manual "(message)Insertion Variables")
970 :group 'message-insertion)
972 (defcustom message-citation-line-format "On %a, %b %d %Y, %N wrote:\n"
973 "Format of the \"Whomever writes:\" line.
975 The string is formatted using `format-spec'. The following
976 constructs are replaced:
978 %f The full From, e.g. \"John Doe <john.doe@example.invalid>\".
979 %n The mail address, e.g. \"john.doe@example.invalid\".
980 %N The real name if present, e.g.: \"John Doe\", else fall
981 back to the mail address.
982 %F The first name if present, e.g.: \"John\".
983 %L The last name if present, e.g.: \"Doe\".
985 All other format specifiers are passed to `format-time-string'
986 which is called using the date from the article your replying to.
987 Extracting the first (%F) and last name (%L) is done
988 heuristically, so you should always check it yourself.
990 Please also read the note in the documentation of
991 `message-citation-line-function'."
992 :type '(choice (const :tag "Plain" "%f writes:")
993 (const :tag "Include date" "On %a, %b %d %Y, %n wrote:")
995 :link '(custom-manual "(message)Insertion Variables")
996 :version "23.1" ;; No Gnus
997 :group 'message-insertion)
999 (defcustom message-yank-prefix "> "
1000 "*Prefix inserted on the lines of yanked messages.
1001 Fix `message-cite-prefix-regexp' if it is set to an abnormal value.
1002 See also `message-yank-cited-prefix' and `message-yank-empty-prefix'."
1005 :link '(custom-manual "(message)Insertion Variables")
1006 :group 'message-insertion)
1008 (defcustom message-yank-cited-prefix ">"
1009 "*Prefix inserted on cited lines of yanked messages.
1010 Fix `message-cite-prefix-regexp' if it is set to an abnormal value.
1011 See also `message-yank-prefix' and `message-yank-empty-prefix'."
1014 :link '(custom-manual "(message)Insertion Variables")
1015 :group 'message-insertion)
1017 (defcustom message-yank-empty-prefix ">"
1018 "*Prefix inserted on empty lines of yanked messages.
1019 See also `message-yank-prefix' and `message-yank-cited-prefix'."
1022 :link '(custom-manual "(message)Insertion Variables")
1023 :group 'message-insertion)
1025 (defcustom message-indentation-spaces 3
1026 "*Number of spaces to insert at the beginning of each cited line.
1027 Used by `message-yank-original' via `message-yank-cite'."
1029 :group 'message-insertion
1030 :link '(custom-manual "(message)Insertion Variables")
1033 (defcustom message-cite-function 'message-cite-original-without-signature
1034 "*Function for citing an original message.
1035 Predefined functions include `message-cite-original' and
1036 `message-cite-original-without-signature'.
1037 Note that these functions use `mail-citation-hook' if that is non-nil."
1038 :type '(radio (function-item message-cite-original)
1039 (function-item message-cite-original-without-signature)
1040 (function-item sc-cite-original)
1041 (function :tag "Other"))
1042 :link '(custom-manual "(message)Insertion Variables")
1043 :version "22.3" ;; Gnus 5.10.12 (changed default)
1044 :group 'message-insertion)
1046 (defcustom message-indent-citation-function 'message-indent-citation
1047 "*Function for modifying a citation just inserted in the mail buffer.
1048 This can also be a list of functions. Each function can find the
1049 citation between (point) and (mark t). And each function should leave
1050 point and mark around the citation text as modified."
1052 :link '(custom-manual "(message)Insertion Variables")
1053 :group 'message-insertion)
1055 (defcustom message-signature t
1056 "*String to be inserted at the end of the message buffer.
1057 If t, the `message-signature-file' file will be inserted instead.
1058 If a function, the result from the function will be used instead.
1059 If a form, the result from the form will be used instead."
1062 :link '(custom-manual "(message)Insertion Variables")
1063 :group 'message-insertion)
1065 (defcustom message-signature-file "~/.signature"
1066 "*Name of file containing the text inserted at end of message buffer.
1067 Ignored if the named file doesn't exist.
1068 If nil, don't insert a signature.
1069 If a path is specified, the value of `message-signature-directory' is ignored,
1072 :type '(choice file (const :tags "None" nil))
1073 :link '(custom-manual "(message)Insertion Variables")
1074 :group 'message-insertion)
1076 (defcustom message-signature-directory nil
1077 "*Name of directory containing signature files.
1078 Comes in handy if you have many such files, handled via posting styles for
1080 If nil, `message-signature-file' is expected to specify the directory if
1082 :type '(choice string (const :tags "None" nil))
1083 :link '(custom-manual "(message)Insertion Variables")
1084 :group 'message-insertion)
1086 (defcustom message-signature-insert-empty-line t
1087 "*If non-nil, insert an empty line before the signature separator."
1090 :link '(custom-manual "(message)Insertion Variables")
1091 :group 'message-insertion)
1093 (defcustom message-distribution-function nil
1094 "*Function called to return a Distribution header."
1095 :group 'message-news
1096 :group 'message-headers
1097 :link '(custom-manual "(message)News Headers")
1098 :type '(choice function (const nil)))
1100 (defcustom message-expires 14
1101 "Number of days before your article expires."
1102 :group 'message-news
1103 :group 'message-headers
1104 :link '(custom-manual "(message)News Headers")
1107 (defcustom message-user-path nil
1108 "If nil, use the NNTP server name in the Path header.
1109 If stringp, use this; if non-nil, use no host name (user name only)."
1110 :group 'message-news
1111 :group 'message-headers
1112 :link '(custom-manual "(message)News Headers")
1113 :type '(choice (const :tag "nntp" nil)
1114 (string :tag "name")
1115 (sexp :tag "none" :format "%t" t)))
1117 ;; This can be the name of a buffer, or a cons cell (FUNCTION . ARGS)
1118 ;; for yanking the original buffer.
1119 (defvar message-reply-buffer nil)
1120 (defvar message-reply-headers nil
1121 "The headers of the current replied article.
1122 It is a vector of the following headers:
1123 \[number subject from date id references chars lines xref extra].")
1124 (defvar message-newsreader nil)
1125 (defvar message-mailer nil)
1126 (defvar message-sent-message-via nil)
1127 (defvar message-checksum nil)
1128 (defvar message-send-actions nil
1129 "A list of actions to be performed upon successful sending of a message.")
1130 (defvar message-exit-actions nil
1131 "A list of actions to be performed upon exiting after sending a message.")
1132 (defvar message-kill-actions nil
1133 "A list of actions to be performed before killing a message buffer.")
1134 (defvar message-postpone-actions nil
1135 "A list of actions to be performed after postponing a message.")
1137 (define-widget 'message-header-lines 'text
1138 "All header lines must be LFD terminated."
1139 :format "%{%t%}:%n%v"
1140 :valid-regexp "^\\'"
1141 :error "All header lines must be newline terminated")
1143 (defcustom message-default-headers ""
1144 "*A string containing header lines to be inserted in outgoing messages.
1145 It is inserted before you edit the message, so you can edit or delete
1148 :group 'message-headers
1149 :link '(custom-manual "(message)Message Headers")
1150 :type 'message-header-lines)
1152 (defcustom message-default-mail-headers
1153 ;; Ease the transition from mail-mode to message-mode. See bugs#4431, 5555.
1154 (concat (if (and (boundp 'mail-default-reply-to)
1155 (stringp mail-default-reply-to))
1156 (format "Reply-to: %s\n" mail-default-reply-to))
1157 (if (and (boundp 'mail-self-blind)
1159 (format "BCC: %s\n" user-mail-address))
1160 (if (and (boundp 'mail-archive-file-name)
1161 (stringp mail-archive-file-name))
1162 (format "FCC: %s\n" mail-archive-file-name))
1163 ;; Use the value of `mail-default-headers' if available.
1164 ;; Note: as for Emacs 21, XEmacs 21.4 and 21.5, it is
1165 ;; unavailable unless sendmail.el is loaded.
1166 (if (boundp 'mail-default-headers)
1167 mail-default-headers))
1168 "*A string of header lines to be inserted in outgoing mails."
1170 :group 'message-headers
1171 :group 'message-mail
1172 :link '(custom-manual "(message)Mail Headers")
1173 :type 'message-header-lines)
1175 (defcustom message-default-news-headers ""
1176 "*A string of header lines to be inserted in outgoing news articles."
1177 :group 'message-headers
1178 :group 'message-news
1179 :link '(custom-manual "(message)News Headers")
1180 :type 'message-header-lines)
1182 ;; Note: could use /usr/ucb/mail instead of sendmail;
1183 ;; options -t, and -v if not interactive.
1184 (defcustom message-mailer-swallows-blank-line
1185 (if (and (string-match "sparc-sun-sunos\\(\\'\\|[^5]\\)"
1186 system-configuration)
1187 (file-readable-p "/etc/sendmail.cf")
1188 (let ((buffer (get-buffer-create " *temp*")))
1190 (with-current-buffer buffer
1191 (insert-file-contents "/etc/sendmail.cf")
1192 (goto-char (point-min))
1193 (let ((case-fold-search nil))
1194 (re-search-forward "^OR\\>" nil t)))
1195 (kill-buffer buffer))))
1196 ;; According to RFC822, "The field-name must be composed of printable
1197 ;; ASCII characters (i. e., characters that have decimal values between
1198 ;; 33 and 126, except colon)", i. e., any chars except ctl chars,
1200 '(looking-at "[ \t]\\|[][!\"#$%&'()*+,-./0-9;<=>?@A-Z\\\\^_`a-z{|}~]+:"))
1201 "*Set this non-nil if the system's mailer runs the header and body together.
1202 \(This problem exists on Sunos 4 when sendmail is run in remote mode.)
1203 The value should be an expression to test whether the problem will
1205 :group 'message-sending
1206 :link '(custom-manual "(message)Mail Variables")
1210 (define-mail-user-agent 'message-user-agent
1211 'message-mail 'message-send-and-exit
1212 'message-kill-buffer 'message-send-hook)
1214 (defvar message-mh-deletable-headers '(Message-ID Date Lines Sender)
1215 "If non-nil, delete the deletable headers before feeding to mh.")
1217 (defvar message-send-method-alist
1218 '((news message-news-p message-send-via-news)
1219 (mail message-mail-p message-send-via-mail))
1220 "Alist of ways to send outgoing messages.
1221 Each element has the form
1223 \(TYPE PREDICATE FUNCTION)
1225 where TYPE is a symbol that names the method; PREDICATE is a function
1226 called without any parameters to determine whether the message is
1227 a message of type TYPE; and FUNCTION is a function to be called if
1228 PREDICATE returns non-nil. FUNCTION is called with one parameter --
1231 (defcustom message-mail-alias-type 'abbrev
1232 "*What alias expansion type to use in Message buffers.
1233 The default is `abbrev', which uses mailabbrev. `ecomplete' uses
1234 an electric completion mode. nil switches mail aliases off.
1235 This can also be a list of values."
1237 :link '(custom-manual "(message)Mail Aliases")
1238 :type '(choice (const :tag "Use Mailabbrev" abbrev)
1239 (const :tag "Use ecomplete" ecomplete)
1240 (const :tag "No expansion" nil)))
1242 (defcustom message-self-insert-commands '(self-insert-command)
1243 "List of `self-insert-command's used to trigger ecomplete.
1244 When one of those commands is invoked to enter a character in To or Cc
1245 header, ecomplete will suggest the candidates of recipients (see also
1246 `message-mail-alias-type'). If you use some tool to enter non-ASCII
1247 text and it replaces `self-insert-command' with the other command, e.g.
1248 `egg-self-insert-command', you may want to add it to this list."
1249 :group 'message-various
1250 :type '(repeat function))
1252 (defcustom message-auto-save-directory
1253 (file-name-as-directory (expand-file-name "drafts" message-directory))
1254 "*Directory where Message auto-saves buffers if Gnus isn't running.
1255 If nil, Message won't auto-save."
1256 :group 'message-buffers
1257 :link '(custom-manual "(message)Various Message Variables")
1258 :type '(choice directory (const :tag "Don't auto-save" nil)))
1260 (defcustom message-default-charset
1261 (and (not (mm-multibyte-p)) 'iso-8859-1)
1262 "Default charset used in non-MULE Emacsen.
1263 If nil, you might be asked to input the charset."
1266 :link '(custom-manual "(message)Various Message Variables")
1269 (defcustom message-dont-reply-to-names
1270 (and (boundp 'rmail-dont-reply-to-names) rmail-dont-reply-to-names)
1271 "*Addresses to prune when doing wide replies.
1272 This can be a regexp or a list of regexps. Also, a value of nil means
1273 exclude your own user name only."
1276 :link '(custom-manual "(message)Wide Reply")
1277 :type '(choice (const :tag "Yourself" nil)
1279 (repeat :tag "Regexp List" regexp)))
1281 (defsubst message-dont-reply-to-names ()
1282 (gmm-regexp-concat message-dont-reply-to-names))
1284 (defvar message-shoot-gnksa-feet nil
1285 "*A list of GNKSA feet you are allowed to shoot.
1286 Gnus gives you all the opportunity you could possibly want for
1287 shooting yourself in the foot. Also, Gnus allows you to shoot the
1288 feet of Good Net-Keeping Seal of Approval. The following are foot
1290 `empty-article' Allow you to post an empty article;
1291 `quoted-text-only' Allow you to post quoted text only;
1292 `multiple-copies' Allow you to post multiple copies;
1293 `cancel-messages' Allow you to cancel or supersede messages from
1294 your other email addresses.")
1296 (defsubst message-gnksa-enable-p (feature)
1297 (or (not (listp message-shoot-gnksa-feet))
1298 (memq feature message-shoot-gnksa-feet)))
1300 (defcustom message-hidden-headers '("^References:" "^Face:" "^X-Face:"
1302 "Regexp of headers to be hidden when composing new messages.
1303 This can also be a list of regexps to match headers. Or a list
1304 starting with `not' and followed by regexps."
1307 :link '(custom-manual "(message)Message Headers")
1309 :format "%{%t%}: %[Value Type%] %v"
1310 (regexp :menu-tag "regexp" :format "regexp\n%t: %v")
1311 (repeat :menu-tag "(regexp ...)" :format "(regexp ...)\n%v%i"
1312 (regexp :format "%t: %v"))
1313 (cons :menu-tag "(not regexp ...)" :format "(not regexp ...)\n%v"
1315 (repeat :format "%v%i"
1316 (regexp :format "%t: %v")))))
1318 (defcustom message-cite-articles-with-x-no-archive t
1319 "If non-nil, cite text from articles that has X-No-Archive set."
1323 ;;; Internal variables.
1324 ;;; Well, not really internal.
1326 (defvar message-mode-syntax-table
1327 (let ((table (copy-syntax-table text-mode-syntax-table)))
1328 (modify-syntax-entry ?% ". " table)
1329 (modify-syntax-entry ?> ". " table)
1330 (modify-syntax-entry ?< ". " table)
1332 "Syntax table used while in Message mode.")
1334 (defface message-header-to
1337 (:foreground "DarkOliveGreen1" :bold t))
1340 (:foreground "MidnightBlue" :bold t))
1342 (:bold t :italic t)))
1343 "Face used for displaying From headers."
1344 :group 'message-faces)
1345 ;; backward-compatibility alias
1346 (put 'message-header-to-face 'face-alias 'message-header-to)
1347 (put 'message-header-to-face 'obsolete-face "22.1")
1349 (defface message-header-cc
1352 (:foreground "chartreuse1" :bold t))
1355 (:foreground "MidnightBlue"))
1358 "Face used for displaying Cc headers."
1359 :group 'message-faces)
1360 ;; backward-compatibility alias
1361 (put 'message-header-cc-face 'face-alias 'message-header-cc)
1362 (put 'message-header-cc-face 'obsolete-face "22.1")
1364 (defface message-header-subject
1367 (:foreground "OliveDrab1"))
1370 (:foreground "navy blue" :bold t))
1373 "Face used for displaying subject headers."
1374 :group 'message-faces)
1375 ;; backward-compatibility alias
1376 (put 'message-header-subject-face 'face-alias 'message-header-subject)
1377 (put 'message-header-subject-face 'obsolete-face "22.1")
1379 (defface message-header-newsgroups
1382 (:foreground "yellow" :bold t :italic t))
1385 (:foreground "blue4" :bold t :italic t))
1387 (:bold t :italic t)))
1388 "Face used for displaying newsgroups headers."
1389 :group 'message-faces)
1390 ;; backward-compatibility alias
1391 (put 'message-header-newsgroups-face 'face-alias 'message-header-newsgroups)
1392 (put 'message-header-newsgroups-face 'obsolete-face "22.1")
1394 (defface message-header-other
1397 (:foreground "VioletRed1"))
1400 (:foreground "steel blue"))
1402 (:bold t :italic t)))
1403 "Face used for displaying newsgroups headers."
1404 :group 'message-faces)
1405 ;; backward-compatibility alias
1406 (put 'message-header-other-face 'face-alias 'message-header-other)
1407 (put 'message-header-other-face 'obsolete-face "22.1")
1409 (defface message-header-name
1412 (:foreground "green"))
1415 (:foreground "cornflower blue"))
1418 "Face used for displaying header names."
1419 :group 'message-faces)
1420 ;; backward-compatibility alias
1421 (put 'message-header-name-face 'face-alias 'message-header-name)
1422 (put 'message-header-name-face 'obsolete-face "22.1")
1424 (defface message-header-xheader
1427 (:foreground "DeepSkyBlue1"))
1430 (:foreground "blue"))
1433 "Face used for displaying X-Header headers."
1434 :group 'message-faces)
1435 ;; backward-compatibility alias
1436 (put 'message-header-xheader-face 'face-alias 'message-header-xheader)
1437 (put 'message-header-xheader-face 'obsolete-face "22.1")
1439 (defface message-separator
1442 (:foreground "LightSkyBlue1"))
1445 (:foreground "brown"))
1448 "Face used for displaying the separator."
1449 :group 'message-faces)
1450 ;; backward-compatibility alias
1451 (put 'message-separator-face 'face-alias 'message-separator)
1452 (put 'message-separator-face 'obsolete-face "22.1")
1454 (defface message-cited-text
1457 (:foreground "LightPink1"))
1460 (:foreground "red"))
1463 "Face used for displaying cited text names."
1464 :group 'message-faces)
1465 ;; backward-compatibility alias
1466 (put 'message-cited-text-face 'face-alias 'message-cited-text)
1467 (put 'message-cited-text-face 'obsolete-face "22.1")
1469 (defface message-mml
1472 (:foreground "MediumSpringGreen"))
1475 (:foreground "ForestGreen"))
1478 "Face used for displaying MML."
1479 :group 'message-faces)
1480 ;; backward-compatibility alias
1481 (put 'message-mml-face 'face-alias 'message-mml)
1482 (put 'message-mml-face 'obsolete-face "22.1")
1484 (defun message-font-lock-make-header-matcher (regexp)
1487 (let ((start (point)))
1490 (goto-char (point-min))
1491 (if (re-search-forward
1492 (concat "^" (regexp-quote mail-header-separator) "$")
1494 (setq limit (min limit (match-beginning 0))))
1496 (and (< start limit)
1497 (re-search-forward ,regexp limit t))))))
1498 (if (featurep 'bytecomp)
1502 (defvar message-font-lock-keywords
1503 (let ((content "[ \t]*\\(.+\\(\n[ \t].*\\)*\\)\n?"))
1504 `((,(message-font-lock-make-header-matcher
1505 (concat "^\\([Tt]o:\\)" content))
1506 (1 'message-header-name)
1507 (2 'message-header-to nil t))
1508 (,(message-font-lock-make-header-matcher
1509 (concat "^\\(^[GBF]?[Cc][Cc]:\\|^[Rr]eply-[Tt]o:\\)" content))
1510 (1 'message-header-name)
1511 (2 'message-header-cc nil t))
1512 (,(message-font-lock-make-header-matcher
1513 (concat "^\\([Ss]ubject:\\)" content))
1514 (1 'message-header-name)
1515 (2 'message-header-subject nil t))
1516 (,(message-font-lock-make-header-matcher
1517 (concat "^\\([Nn]ewsgroups:\\|Followup-[Tt]o:\\)" content))
1518 (1 'message-header-name)
1519 (2 'message-header-newsgroups nil t))
1520 (,(message-font-lock-make-header-matcher
1521 (concat "^\\(X-[A-Za-z0-9-]+:\\|In-Reply-To:\\)" content))
1522 (1 'message-header-name)
1523 (2 'message-header-xheader))
1524 (,(message-font-lock-make-header-matcher
1525 (concat "^\\([A-Z][^: \n\t]+:\\)" content))
1526 (1 'message-header-name)
1527 (2 'message-header-other nil t))
1528 ,@(if (and mail-header-separator
1529 (not (equal mail-header-separator "")))
1530 `((,(concat "^\\(" (regexp-quote mail-header-separator) "\\)$")
1531 1 'message-separator))
1534 (re-search-forward (concat "^\\("
1535 message-cite-prefix-regexp
1538 (0 'message-cited-text))
1539 ("<#/?\\(multipart\\|part\\|external\\|mml\\|secure\\)[^>]*>"
1541 "Additional expressions to highlight in Message mode.")
1544 ;; XEmacs does it like this. For Emacs, we have to set the
1545 ;; `font-lock-defaults' buffer-local variable.
1546 (put 'message-mode 'font-lock-defaults '(message-font-lock-keywords t))
1548 (defvar message-face-alist
1549 '((bold . message-bold-region)
1550 (underline . underline-region)
1551 (default . (lambda (b e)
1552 (message-unbold-region b e)
1553 (ununderline-region b e))))
1554 "Alist of mail and news faces for facemenu.
1555 The cdr of each entry is a function for applying the face to a region.")
1557 (defcustom message-send-hook nil
1558 "Hook run before sending messages.
1559 This hook is run quite early when sending."
1560 :group 'message-various
1561 :options '(ispell-message)
1562 :link '(custom-manual "(message)Various Message Variables")
1565 (defcustom message-send-mail-hook nil
1566 "Hook run before sending mail messages.
1567 This hook is run very late -- just before the message is sent as
1569 :group 'message-various
1570 :link '(custom-manual "(message)Various Message Variables")
1573 (defcustom message-send-news-hook nil
1574 "Hook run before sending news messages.
1575 This hook is run very late -- just before the message is sent as
1577 :group 'message-various
1578 :link '(custom-manual "(message)Various Message Variables")
1581 (defcustom message-sent-hook nil
1582 "Hook run after sending messages."
1583 :group 'message-various
1586 (defvar message-send-coding-system 'binary
1587 "Coding system to encode outgoing mail.")
1589 (defvar message-draft-coding-system
1590 mm-auto-save-coding-system
1591 "*Coding system to compose mail.
1592 If you'd like to make it possible to share draft files between XEmacs
1593 and Emacs, you may use `iso-2022-7bit' for this value at your own risk.
1594 Note that the coding-system `iso-2022-7bit' isn't suitable to all data.")
1596 (defcustom message-send-mail-partially-limit nil
1597 "The limitation of messages sent as message/partial.
1598 The lower bound of message size in characters, beyond which the message
1599 should be sent in several parts. If it is nil, the size is unlimited."
1601 :group 'message-buffers
1602 :link '(custom-manual "(message)Mail Variables")
1603 :type '(choice (const :tag "unlimited" nil)
1606 (defcustom message-alternative-emails nil
1607 "*Regexp matching alternative email addresses.
1608 The first address in the To, Cc or From headers of the original
1609 article matching this variable is used as the From field of
1612 This variable has precedence over posting styles and anything that runs
1613 off `message-setup-hook'."
1614 :group 'message-headers
1615 :link '(custom-manual "(message)Message Headers")
1616 :type '(choice (const :tag "Always use primary" nil)
1619 (defcustom message-hierarchical-addresses nil
1620 "A list of hierarchical mail address definitions.
1622 Inside each entry, the first address is the \"top\" address, and
1623 subsequent addresses are subaddresses; this is used to indicate that
1624 mail sent to the first address will automatically be delivered to the
1625 subaddresses. So if the first address appears in the recipient list
1626 for a message, the subaddresses will be removed (if present) before
1627 the mail is sent. All addresses in this structure should be
1630 :group 'message-headers
1631 :type '(repeat (repeat string)))
1633 (defcustom message-mail-user-agent nil
1634 "Like `mail-user-agent'.
1635 Except if it is nil, use Gnus native MUA; if it is t, use
1638 :type '(radio (const :tag "Gnus native"
1641 (const :tag "`mail-user-agent'"
1644 (function-item :tag "Default Emacs mail"
1646 sendmail-user-agent)
1647 (function-item :tag "Emacs interface to MH"
1650 (function :tag "Other"))
1654 (defcustom message-wide-reply-confirm-recipients nil
1655 "Whether to confirm a wide reply to multiple email recipients.
1656 If this variable is nil, don't ask whether to reply to all recipients.
1657 If this variable is non-nil, pose the question \"Reply to all
1658 recipients?\" before a wide reply to multiple recipients. If the user
1659 answers yes, reply to all recipients as usual. If the user answers
1660 no, only reply back to the author."
1662 :group 'message-headers
1663 :link '(custom-manual "(message)Wide Reply")
1666 (defcustom message-user-fqdn nil
1667 "*Domain part of Message-Ids."
1669 :group 'message-headers
1670 :link '(custom-manual "(message)News Headers")
1671 :type '(radio (const :format "%v " nil)
1672 (string :format "FQDN: %v")))
1674 (defcustom message-use-idna (and (condition-case nil (require 'idna)
1676 (mm-coding-system-p 'utf-8)
1677 (executable-find idna-program)
1678 (string= (idna-to-ascii "räksmörgås")
1679 "xn--rksmrgs-5wao1o")
1681 "Whether to encode non-ASCII in domain names into ASCII according to IDNA.
1682 GNU Libidn, and in particular the elisp package \"idna.el\" and
1683 the external program \"idn\", must be installed for this
1684 functionality to work."
1686 :group 'message-headers
1687 :link '(custom-manual "(message)IDNA")
1688 :type '(choice (const :tag "Ask" ask)
1689 (const :tag "Never" nil)
1690 (const :tag "Always" t)))
1692 (defcustom message-generate-hashcash (if (executable-find "hashcash") t)
1693 "*Whether to generate X-Hashcash: headers.
1694 If t, always generate hashcash headers. If `opportunistic',
1695 only generate hashcash headers if it can be done without the user
1696 waiting (i.e., only asynchronously).
1698 You must have the \"hashcash\" binary installed, see `hashcash-path'."
1699 :group 'message-headers
1700 :link '(custom-manual "(message)Mail Headers")
1701 :type '(choice (const :tag "Always" t)
1702 (const :tag "Never" nil)
1703 (const :tag "Opportunistic" opportunistic)))
1705 ;;; Internal variables.
1707 (defvar message-sending-message "Sending...")
1708 (defvar message-buffer-list nil)
1709 (defvar message-this-is-news nil)
1710 (defvar message-this-is-mail nil)
1711 (defvar message-draft-article nil)
1712 (defvar message-mime-part nil)
1713 (defvar message-posting-charset nil)
1714 (defvar message-inserted-headers nil)
1715 (defvar message-inhibit-ecomplete nil)
1717 ;; Byte-compiler warning
1718 (defvar gnus-active-hashtb)
1719 (defvar gnus-read-active-file)
1721 ;;; Regexp matching the delimiter of messages in UNIX mail format
1722 ;;; (UNIX From lines), minus the initial ^. It should be a copy
1723 ;;; of rmail.el's rmail-unix-mail-delimiter.
1724 (defvar message-unix-mail-delimiter
1725 (let ((time-zone-regexp
1726 (concat "\\([A-Z]?[A-Z]?[A-Z][A-Z]\\( DST\\)?"
1727 "\\|[-+]?[0-9][0-9][0-9][0-9]"
1733 ;; Many things can happen to an RFC 822 mailbox before it is put into
1734 ;; a `From' line. The leading phrase can be stripped, e.g.
1735 ;; `Joe <@w.x:joe@y.z>' -> `<@w.x:joe@y.z>'. The <> can be stripped, e.g.
1736 ;; `<@x.y:joe@y.z>' -> `@x.y:joe@y.z'. Everything starting with a CRLF
1737 ;; can be removed, e.g.
1738 ;; From: joe@y.z (Joe K
1740 ;; can yield `From joe@y.z (Joe K Fri Mar 22 08:11:15 1996', and
1743 ;; can yield `From Joe User Fri Mar 22 08:11:15 1996'.
1744 ;; The mailbox can be removed or be replaced by white space, e.g.
1745 ;; From: "Joe User"{space}{tab}
1747 ;; can yield `From {space}{tab} Fri Mar 22 08:11:15 1996',
1748 ;; where {space} and {tab} represent the Ascii space and tab characters.
1749 ;; We want to match the results of any of these manglings.
1750 ;; The following regexp rejects names whose first characters are
1751 ;; obviously bogus, but after that anything goes.
1752 "\\([^\0-\b\n-\r\^?].*\\)?"
1754 ;; The time the message was sent.
1755 "\\([^\0-\r \^?]+\\) +" ; day of the week
1756 "\\([^\0-\r \^?]+\\) +" ; month
1757 "\\([0-3]?[0-9]\\) +" ; day of month
1758 "\\([0-2][0-9]:[0-5][0-9]\\(:[0-6][0-9]\\)?\\) *" ; time of day
1760 ;; Perhaps a time zone, specified by an abbreviation, or by a
1765 " \\([0-9][0-9]+\\) *"
1767 ;; On some systems the time zone can appear after the year, too.
1771 "\\(remote from .*\\)?"
1774 "Regexp matching the delimiter of messages in UNIX mail format.")
1776 (defvar message-unsent-separator
1777 (concat "^ *---+ +Unsent message follows +---+ *$\\|"
1778 "^ *---+ +Returned message +---+ *$\\|"
1779 "^Start of returned message$\\|"
1780 "^ *---+ +Original message +---+ *$\\|"
1781 "^ *--+ +begin message +--+ *$\\|"
1782 "^ *---+ +Original message follows +---+ *$\\|"
1783 "^ *---+ +Undelivered message follows +---+ *$\\|"
1784 "^------ This is a copy of the message, including all the headers. ------ *$\\|"
1785 "^|? *---+ +Message text follows: +---+ *|?$")
1786 "A regexp that matches the separator before the text of a failed message.")
1788 (defvar message-field-fillers
1789 '((To message-fill-field-address)
1790 (Cc message-fill-field-address)
1791 (From message-fill-field-address))
1792 "Alist of header names/filler functions.")
1794 (defvar message-header-format-alist
1809 (References . message-shorten-references)
1811 "Alist used for formatting headers.")
1813 (defvar message-options nil
1814 "Some saved answers when sending message.")
1816 (defvar message-send-mail-real-function nil
1817 "Internal send mail function.")
1819 (defvar message-bogus-system-names "^localhost\\.\\|\\.local$"
1820 "The regexp of bogus system names.")
1822 (defcustom message-valid-fqdn-regexp
1823 (concat "[a-z0-9][-.a-z0-9]+\\." ;; [hostname.subdomain.]domain.
1825 "\\([a-z][a-z]\\|" ;; two letter country TDLs
1826 "aero\\|arpa\\|bitnet\\|biz\\|bofh\\|"
1827 "cat\\|com\\|coop\\|edu\\|gov\\|"
1828 "info\\|int\\|jobs\\|"
1829 "mil\\|mobi\\|museum\\|name\\|net\\|"
1830 "org\\|pro\\|travel\\|uucp\\)")
1831 ;; http://en.wikipedia.org/wiki/List_of_Internet_top-level_domains
1832 ;; http://en.wikipedia.org/wiki/GTLD
1833 ;; `in the process of being approved': .asia .post .tel .sex
1834 ;; "dead" nato bitnet uucp
1835 "Regular expression that matches a valid FQDN."
1836 ;; see also: gnus-button-valid-fqdn-regexp
1838 :group 'message-headers
1841 (autoload 'gnus-alive-p "gnus-util")
1842 (autoload 'gnus-delay-article "gnus-delay")
1843 (autoload 'gnus-extract-address-components "gnus-util")
1844 (autoload 'gnus-find-method-for-group "gnus")
1845 (autoload 'gnus-group-decoded-name "gnus-group")
1846 (autoload 'gnus-group-name-charset "gnus-group")
1847 (autoload 'gnus-group-name-decode "gnus-group")
1848 (autoload 'gnus-groups-from-server "gnus")
1849 (autoload 'gnus-make-local-hook "gnus-util")
1850 (autoload 'gnus-open-server "gnus-int")
1851 (autoload 'gnus-output-to-mail "gnus-util")
1852 (autoload 'gnus-output-to-rmail "gnus-util")
1853 (autoload 'gnus-request-post "gnus-int")
1854 (autoload 'gnus-select-frame-set-input-focus "gnus-util")
1855 (autoload 'gnus-server-string "gnus")
1856 (autoload 'idna-to-ascii "idna")
1857 (autoload 'message-setup-toolbar "messagexmas")
1858 (autoload 'mh-new-draft-name "mh-comp")
1859 (autoload 'mh-send-letter "mh-comp")
1860 (autoload 'nndraft-request-associate-buffer "nndraft")
1861 (autoload 'nndraft-request-expire-articles "nndraft")
1862 (autoload 'nnvirtual-find-group-art "nnvirtual")
1863 (autoload 'rmail-dont-reply-to "mail-utils")
1864 (autoload 'rmail-msg-is-pruned "rmail")
1865 (autoload 'rmail-output "rmailout")
1870 ;;; Utility functions.
1873 (defmacro message-y-or-n-p (question show &rest text)
1874 "Ask QUESTION, displaying remaining args in a temporary buffer if SHOW."
1875 `(message-talkative-question 'y-or-n-p ,question ,show ,@text))
1877 (defmacro message-delete-line (&optional n)
1878 "Delete the current line (and the next N lines)."
1879 `(delete-region (progn (beginning-of-line) (point))
1880 (progn (forward-line ,(or n 1)) (point))))
1882 (defun message-mark-active-p ()
1883 "Non-nil means the mark and region are currently active in this buffer."
1886 (defun message-unquote-tokens (elems)
1887 "Remove double quotes (\") from strings in list ELEMS."
1888 (mapcar (lambda (item)
1889 (while (string-match "^\\(.*\\)\"\\(.*\\)$" item)
1890 (setq item (concat (match-string 1 item)
1891 (match-string 2 item))))
1895 (defun message-tokenize-header (header &optional separator)
1896 "Split HEADER into a list of header elements.
1897 SEPARATOR is a string of characters to be used as separators. \",\"
1898 is used by default."
1901 (let ((regexp (format "[%s]+" (or separator ",")))
1903 beg quoted elems paren)
1905 (mm-enable-multibyte)
1906 (setq beg (point-min))
1908 (goto-char (point-min))
1913 (cond ((and (> (point) beg)
1915 (and (looking-at regexp)
1918 (push (buffer-substring beg (point)) elems)
1919 (setq beg (match-end 0)))
1920 ((eq (char-after) ?\")
1921 (setq quoted (not quoted)))
1922 ((and (eq (char-after) ?\()
1925 ((and (eq (char-after) ?\))
1928 (nreverse elems)))))
1930 (autoload 'nnheader-insert-file-contents "nnheader")
1932 (defun message-mail-file-mbox-p (file)
1933 "Say whether FILE looks like a Unix mbox file."
1934 (when (and (file-exists-p file)
1935 (file-readable-p file)
1936 (file-regular-p file))
1938 (nnheader-insert-file-contents file)
1939 (goto-char (point-min))
1940 (looking-at message-unix-mail-delimiter))))
1942 (defun message-fetch-field (header &optional not-all)
1943 "The same as `mail-fetch-field', only remove all newlines.
1944 The buffer is expected to be narrowed to just the header of the message;
1945 see `message-narrow-to-headers-or-head'."
1946 (let* ((inhibit-point-motion-hooks t)
1947 (value (mail-fetch-field header nil (not not-all))))
1949 (while (string-match "\n[\t ]+" value)
1950 (setq value (replace-match " " t t value)))
1953 (defun message-field-value (header &optional not-all)
1954 "The same as `message-fetch-field', only narrow to the headers first."
1957 (message-narrow-to-headers-or-head)
1958 (message-fetch-field header not-all))))
1960 (defun message-narrow-to-field ()
1961 "Narrow the buffer to the header on the current line."
1963 (while (looking-at "[ \t]")
1969 (if (re-search-forward "^[^ \n\t]" nil t)
1972 (goto-char (point-min)))
1974 (defun message-add-header (&rest headers)
1975 "Add the HEADERS to the message header, skipping those already present."
1978 (unless (string-match "^\\([^:]+\\):[ \t]*[^ \t]" (car headers))
1979 (error "Invalid header `%s'" (car headers)))
1980 (setq hclean (match-string 1 (car headers)))
1982 (message-narrow-to-headers)
1983 (unless (re-search-forward (concat "^" (regexp-quote hclean) ":") nil t)
1984 (goto-char (point-max))
1985 (if (string-match "\n$" (car headers))
1986 (insert (car headers))
1987 (insert (car headers) ?\n)))))
1988 (setq headers (cdr headers))))
1990 (defmacro message-with-reply-buffer (&rest forms)
1991 "Evaluate FORMS in the reply buffer, if it exists."
1992 `(when (and (bufferp message-reply-buffer)
1993 (buffer-name message-reply-buffer))
1994 (with-current-buffer message-reply-buffer
1997 (put 'message-with-reply-buffer 'lisp-indent-function 0)
1998 (put 'message-with-reply-buffer 'edebug-form-spec '(body))
2000 (defun message-fetch-reply-field (header)
2001 "Fetch field HEADER from the message we're replying to."
2002 (message-with-reply-buffer
2004 (mail-narrow-to-head)
2005 (message-fetch-field header))))
2007 (defun message-strip-list-identifiers (subject)
2008 "Remove list identifiers in `gnus-list-identifiers' from string SUBJECT."
2009 (require 'gnus-sum) ; for gnus-list-identifiers
2010 (let ((regexp (if (stringp gnus-list-identifiers)
2011 gnus-list-identifiers
2012 (mapconcat 'identity gnus-list-identifiers " *\\|"))))
2013 (if (string-match (concat "\\(\\(\\(Re: +\\)?\\(" regexp
2014 " *\\)\\)+\\(Re: +\\)?\\)") subject)
2015 (concat (substring subject 0 (match-beginning 1))
2016 (or (match-string 3 subject)
2017 (match-string 5 subject))
2022 (defun message-strip-subject-re (subject)
2023 "Remove \"Re:\" from subject lines in string SUBJECT."
2024 (if (string-match message-subject-re-regexp subject)
2025 (substring subject (match-end 0))
2028 (defcustom message-replacement-char "."
2029 "Replacement character used instead of unprintable or not decodable chars."
2030 :group 'message-various
2031 :version "22.1" ;; Gnus 5.10.9
2032 :type '(choice string
2036 ;; FIXME: We also should call `message-strip-subject-encoded-words'
2037 ;; when forwarding. Probably in `message-make-forward-subject' and
2038 ;; `message-forward-make-body'.
2040 (defun message-strip-subject-encoded-words (subject)
2041 "Fix non-decodable words in SUBJECT."
2042 ;; Cf. `gnus-simplify-subject-fully'.
2043 (let* ((case-fold-search t)
2044 (replacement-chars (format "[%s%s%s]"
2045 message-replacement-char
2046 message-replacement-char
2047 message-replacement-char))
2048 (enc-word-re "=\\?\\([^?]+\\)\\?\\([QB]\\)\\?\\([^?]+\\)\\(\\?=\\)")
2053 (goto-char (point-min))
2054 (when (re-search-forward enc-word-re nil t)
2055 (setq cs-string (match-string 1)))))
2056 cs-coding q-or-b word-beg word-end)
2057 (if (or (not have-marker) ;; No encoded word found...
2058 ;; ... or double encoding was correct:
2059 (and (stringp cs-string)
2060 (setq cs-string (downcase cs-string))
2061 (mm-coding-system-p (intern cs-string))
2065 Decoded Subject \"%s\"
2066 contains a valid encoded word. Decode again? "
2068 (setq cs-coding (intern cs-string))))))
2072 (goto-char (point-min))
2073 (while (re-search-forward enc-word-re nil t)
2074 (setq cs-string (downcase (match-string 1))
2075 q-or-b (match-string 2)
2076 word-beg (match-beginning 0)
2077 word-end (match-end 0))
2079 (if (mm-coding-system-p (intern cs-string))
2080 (setq cs-coding (intern cs-string))
2082 ;; No double encoded subject? => bogus charset.
2085 (mm-read-coding-system
2087 Decoded Subject \"%s\"
2088 contains an encoded word. The charset `%s' is unknown or invalid.
2089 Hit RET to replace non-decodable characters with \"%s\" or enter replacement
2091 subject cs-string message-replacement-char)))
2093 (replace-match (concat "=?" (symbol-name cs-coding)
2096 (goto-char word-beg)
2097 (re-search-forward "=\\?\\([^?]+\\)\\?\\([QB]\\)\\?" word-end t)
2100 (if (string-match "\\`Q\\'" q-or-b)
2103 (message "Replacing non-decodable characters with \"%s\"."
2104 message-replacement-char)
2105 (while (re-search-forward "\\(=[A-F0-9][A-F0-9]\\)+"
2107 (replace-match message-replacement-char)))
2109 (message "Replacing non-decodable characters with \"%s\"."
2111 (re-search-forward "[^?]+" word-end t)
2112 (replace-match replacement-chars))
2113 (re-search-forward "\\?=")
2114 (replace-match "")))))
2115 (rfc2047-decode-region (point-min) (point-max))
2118 ;;; Start of functions adopted from `message-utils.el'.
2120 (defun message-strip-subject-trailing-was (subject)
2121 "Remove trailing \"(was: <old subject>)\" from SUBJECT lines.
2122 Leading \"Re: \" is not stripped by this function. Use the function
2123 `message-strip-subject-re' for this."
2124 (let* ((query message-subject-trailing-was-query)
2129 message-subject-trailing-was-ask-regexp
2130 message-subject-trailing-was-regexp)
2133 (setq new (substring subject 0 (match-beginning 0))))
2134 (if (or (not found) (eq query nil))
2137 (if (message-y-or-n-p
2138 "Strip `(was: <old subject>)' in subject? " t
2140 "Strip `(was: <old subject>)' in subject "
2141 "and use the new one instead?\n\n"
2142 "Current subject is: \""
2144 "New subject would be: \""
2146 "See the variable `message-subject-trailing-was-query' "
2147 "to get rid of this query."
2152 ;;; Suggested by Jonas Steverud @ www.dtek.chalmers.se/~d4jonas/
2154 (defun message-change-subject (new-subject)
2155 "Ask for NEW-SUBJECT header, append (was: <Old Subject>)."
2156 ;; <URL:http://www.landfield.com/usefor/drafts/draft-ietf-usefor-useage--1.02.unpaged>
2159 (read-from-minibuffer "New subject: ")))
2160 (cond ((and (not (or (null new-subject) ; new subject not empty
2161 (zerop (string-width new-subject))
2162 (string-match "^[ \t]*$" new-subject))))
2166 (message-narrow-to-headers)
2167 (message-fetch-field "Subject"))))
2168 (cond ((not old-subject)
2169 (error "No current subject"))
2172 (regexp-quote new-subject)
2174 old-subject)) ; yes, it really is a new subject
2175 ;; delete eventual Re: prefix
2177 (message-strip-subject-re old-subject))
2178 (message-goto-subject)
2179 (message-delete-line)
2180 (insert (concat "Subject: "
2183 old-subject ")\n")))))))))
2185 (defun message-mark-inserted-region (beg end &optional verbatim)
2186 "Mark some region in the current article with enclosing tags.
2187 See `message-mark-insert-begin' and `message-mark-insert-end'.
2188 If VERBATIM, use slrn style verbatim marks (\"#v+\" and \"#v-\")."
2189 (interactive "r\nP")
2191 ;; add to the end of the region first, otherwise end would be invalid
2193 (insert (if verbatim "#v-\n" message-mark-insert-end))
2195 (insert (if verbatim "#v+\n" message-mark-insert-begin))))
2197 (defun message-mark-insert-file (file &optional verbatim)
2198 "Insert FILE at point, marking it with enclosing tags.
2199 See `message-mark-insert-begin' and `message-mark-insert-end'.
2200 If VERBATIM, use slrn style verbatim marks (\"#v+\" and \"#v-\")."
2201 (interactive "fFile to insert: \nP")
2202 ;; reverse insertion to get correct result.
2204 (insert (if verbatim "#v-\n" message-mark-insert-end))
2206 (insert-file-contents file)
2208 (insert (if verbatim "#v+\n" message-mark-insert-begin))))
2210 (defun message-add-archive-header ()
2211 "Insert \"X-No-Archive: Yes\" in the header and a note in the body.
2212 The note can be customized using `message-archive-note'. When called with a
2213 prefix argument, ask for a text to insert. If you don't want the note in the
2214 body, set `message-archive-note' to nil."
2216 (if current-prefix-arg
2217 (setq message-archive-note
2218 (read-from-minibuffer "Reason for No-Archive: "
2219 (cons message-archive-note 0))))
2221 (if (message-goto-signature)
2222 (re-search-backward message-signature-separator))
2223 (when message-archive-note
2224 (insert message-archive-note)
2226 (message-add-header message-archive-header)
2227 (message-sort-headers)))
2229 (defun message-cross-post-followup-to-header (target-group)
2230 "Mangles FollowUp-To and Newsgroups header to point to TARGET-GROUP.
2231 With prefix-argument just set Follow-Up, don't cross-post."
2233 (list ; Completion based on Gnus
2234 (completing-read "Followup To: "
2235 (if (boundp 'gnus-newsrc-alist)
2237 nil nil '("poster" . 0)
2238 (if (boundp 'gnus-group-history)
2239 'gnus-group-history))))
2240 (message-remove-header "Follow[Uu]p-[Tt]o" t)
2241 (message-goto-newsgroups)
2243 ;; if we already did a crosspost before, kill old target
2244 (if (and message-cross-post-old-target
2246 (regexp-quote (concat "," message-cross-post-old-target))
2249 ;; unless (followup is to poster or user explicitly asked not
2250 ;; to cross-post, or target-group is already in Newsgroups)
2251 ;; add target-group to Newsgroups line.
2253 ;; def: cross-post, req:no
2254 (and message-cross-post-default (not current-prefix-arg))
2255 ;; def: no-cross-post, req:yes
2256 (and (not message-cross-post-default) current-prefix-arg))
2257 (not (string-match "poster" target-group))
2258 (not (string-match (regexp-quote target-group)
2259 (message-fetch-field "Newsgroups"))))
2261 (insert (concat "," target-group))))
2262 (end-of-line) ; ensure Followup: comes after Newsgroups:
2263 ;; unless new followup would be identical to Newsgroups line
2264 ;; make a new Followup-To line
2265 (if (not (string-match (concat "^[ \t]*"
2268 (message-fetch-field "Newsgroups")))
2269 (insert (concat "\nFollowup-To: " target-group)))
2270 (setq message-cross-post-old-target target-group))
2272 (defun message-cross-post-insert-note (target-group cross-post in-old
2274 "Insert a in message body note about a set Followup or Crosspost.
2275 If there have been previous notes, delete them. TARGET-GROUP specifies the
2276 group to Followup-To. When CROSS-POST is t, insert note about
2277 crossposting. IN-OLD specifies whether TARGET-GROUP is a member of
2278 OLD-GROUPS. OLD-GROUPS lists the old-groups the posting would have
2279 been made to before the user asked for a Crosspost."
2280 ;; start scanning body for previous uses
2281 (message-goto-signature)
2282 (let ((head (re-search-backward
2283 (concat "^" mail-header-separator)
2284 nil t))) ; just search in body
2285 (message-goto-signature)
2286 (while (re-search-backward
2287 (concat "^" (regexp-quote message-cross-post-note) ".*")
2289 (message-delete-line))
2290 (message-goto-signature)
2291 (while (re-search-backward
2292 (concat "^" (regexp-quote message-followup-to-note) ".*")
2294 (message-delete-line))
2296 (if (message-goto-signature)
2297 (re-search-backward message-signature-separator))
2300 (string-match "^[ \t]*poster[ \t]*$" target-group))
2301 (insert (concat message-followup-to-note target-group "\n"))
2302 (insert (concat message-cross-post-note target-group "\n")))))
2304 (defun message-cross-post-followup-to (target-group)
2305 "Crossposts message and set Followup-To to TARGET-GROUP.
2306 With prefix-argument just set Follow-Up, don't cross-post."
2308 (list ; Completion based on Gnus
2309 (completing-read "Followup To: "
2310 (if (boundp 'gnus-newsrc-alist)
2312 nil nil '("poster" . 0)
2313 (if (boundp 'gnus-group-history)
2314 'gnus-group-history))))
2315 (cond ((not (or (null target-group) ; new subject not empty
2316 (zerop (string-width target-group))
2317 (string-match "^[ \t]*$" target-group)))
2319 (let* ((old-groups (message-fetch-field "Newsgroups"))
2320 (in-old (string-match
2321 (regexp-quote target-group)
2322 (or old-groups ""))))
2323 ;; check whether target exactly matches old Newsgroups
2324 (cond ((not old-groups)
2325 (error "No current newsgroup"))
2329 (regexp-quote target-group)
2332 ;; yes, Newsgroups line must change
2333 (message-cross-post-followup-to-header target-group)
2334 ;; insert note whether we do cross-post or followup-to
2335 (funcall message-cross-post-note-function
2337 (if (or (and message-cross-post-default
2338 (not current-prefix-arg))
2339 (and (not message-cross-post-default)
2340 current-prefix-arg)) t)
2341 in-old old-groups))))))))
2343 ;;; Reduce To: to Cc: or Bcc: header
2345 (defun message-reduce-to-to-cc ()
2346 "Replace contents of To: header with contents of Cc: or Bcc: header."
2349 (save-restriction (message-narrow-to-headers)
2350 (message-fetch-field "cc")))
2352 (if (and (not cc-content)
2355 (message-narrow-to-headers)
2356 (message-fetch-field "bcc"))))
2361 (message-delete-line)
2362 (insert (concat "To: " cc-content "\n"))
2364 (message-narrow-to-headers)
2365 (message-remove-header (if bcc
2369 ;;; End of functions adopted from `message-utils.el'.
2371 (defun message-remove-header (header &optional is-regexp first reverse)
2372 "Remove HEADER in the narrowed buffer.
2373 If IS-REGEXP, HEADER is a regular expression.
2374 If FIRST, only remove the first instance of the header.
2375 Return the number of headers removed."
2376 (goto-char (point-min))
2377 (let ((regexp (if is-regexp header (concat "^" (regexp-quote header) ":")))
2379 (case-fold-search t)
2381 (while (and (not (eobp))
2384 (not (looking-at regexp))
2385 (looking-at regexp))
2392 ;; There might be a continuation header, so we have to search
2393 ;; until we find a new non-continuation line.
2396 (if (re-search-forward "^[^ \t]" nil t)
2397 (goto-char (match-beginning 0))
2400 (if (re-search-forward "^[^ \t]" nil t)
2401 (goto-char (match-beginning 0))
2402 (goto-char (point-max)))))
2405 (defun message-remove-first-header (header)
2406 "Remove the first instance of HEADER if there is more than one."
2408 (regexp (concat "^" (regexp-quote header) ":")))
2410 (goto-char (point-min))
2411 (while (re-search-forward regexp nil t)
2414 (message-remove-header header nil t)
2417 (defun message-narrow-to-headers ()
2418 "Narrow the buffer to the head of the message."
2421 (goto-char (point-min))
2422 (if (re-search-forward
2423 (concat "^" (regexp-quote mail-header-separator) "\n") nil t)
2426 (goto-char (point-min)))
2428 (defun message-narrow-to-head-1 ()
2429 "Like `message-narrow-to-head'. Don't widen."
2431 (goto-char (point-min))
2432 (if (search-forward "\n\n" nil 1)
2435 (goto-char (point-min)))
2437 ;; FIXME: clarify diffference: message-narrow-to-head,
2438 ;; message-narrow-to-headers-or-head, message-narrow-to-headers
2439 (defun message-narrow-to-head ()
2440 "Narrow the buffer to the head of the message.
2441 Point is left at the beginning of the narrowed-to region."
2443 (message-narrow-to-head-1))
2445 (defun message-narrow-to-headers-or-head ()
2446 "Narrow the buffer to the head of the message."
2449 (goto-char (point-min))
2450 (if (re-search-forward (concat "\\(\n\\)\n\\|^\\("
2451 (regexp-quote mail-header-separator)
2454 (or (match-end 1) (match-beginning 2))
2456 (goto-char (point-min)))
2458 (defun message-news-p ()
2459 "Say whether the current buffer contains a news message."
2460 (and (not message-this-is-mail)
2461 (or message-this-is-news
2464 (message-narrow-to-headers)
2465 (and (message-fetch-field "newsgroups")
2466 (not (message-fetch-field "posted-to"))))))))
2468 (defun message-mail-p ()
2469 "Say whether the current buffer contains a mail message."
2470 (and (not message-this-is-news)
2471 (or message-this-is-mail
2474 (message-narrow-to-headers)
2475 (or (message-fetch-field "to")
2476 (message-fetch-field "cc")
2477 (message-fetch-field "bcc")))))))
2479 (defun message-subscribed-p ()
2480 "Say whether we need to insert a MFT header."
2481 (or message-subscribed-regexps
2482 message-subscribed-addresses
2483 message-subscribed-address-file
2484 message-subscribed-address-functions))
2486 (defun message-next-header ()
2487 "Go to the beginning of the next header."
2489 (or (eobp) (forward-char 1))
2490 (not (if (re-search-forward "^[^ \t]" nil t)
2492 (goto-char (point-max)))))
2494 (defun message-sort-headers-1 ()
2495 "Sort the buffer as headers using `message-rank' text props."
2496 (goto-char (point-min))
2499 nil 'message-next-header
2501 (message-next-header)
2505 (or (get-text-property (point) 'message-rank)
2508 (defun message-sort-headers ()
2509 "Sort the headers of the current message according to `message-header-format-alist'."
2513 (let ((max (1+ (length message-header-format-alist)))
2515 (message-narrow-to-headers)
2516 (while (re-search-forward "^[^ \n]+:" nil t)
2518 (match-beginning 0) (1+ (match-beginning 0))
2520 (if (setq rank (length (memq (assq (intern (buffer-substring
2522 (1- (match-end 0))))
2523 message-header-format-alist)
2524 message-header-format-alist)))
2527 (message-sort-headers-1))))
2529 (defun message-kill-address ()
2530 "Kill the address under point."
2532 (let ((start (point)))
2533 (message-skip-to-next-address)
2534 (kill-region start (point))))
2537 (autoload 'Info-goto-node "info")
2538 (defvar mml2015-use)
2540 (defun message-info (&optional arg)
2541 "Display the Message manual.
2543 Prefixed with one \\[universal-argument], display the Emacs MIME
2544 manual. With two \\[universal-argument]'s, display the EasyPG or
2545 PGG manual, depending on the value of `mml2015-use'."
2547 ;; Don't use `info' because support for `(filename)nodename' is not
2548 ;; available in XEmacs < 21.5.12.
2549 (Info-goto-node (format "(%s)Top"
2553 ((eq arg 4) 'emacs-mime)
2554 ;; `booleanp' only available in Emacs 22+
2555 ((and (not (memq arg '(nil t)))
2569 (defvar message-mode-map nil)
2571 (unless message-mode-map
2572 (setq message-mode-map (make-keymap))
2573 (set-keymap-parent message-mode-map text-mode-map)
2574 (define-key message-mode-map "\C-c?" 'describe-mode)
2576 (define-key message-mode-map "\C-c\C-f\C-t" 'message-goto-to)
2577 (define-key message-mode-map "\C-c\C-f\C-o" 'message-goto-from)
2578 (define-key message-mode-map "\C-c\C-f\C-b" 'message-goto-bcc)
2579 (define-key message-mode-map "\C-c\C-f\C-w" 'message-goto-fcc)
2580 (define-key message-mode-map "\C-c\C-f\C-c" 'message-goto-cc)
2581 (define-key message-mode-map "\C-c\C-f\C-s" 'message-goto-subject)
2582 (define-key message-mode-map "\C-c\C-f\C-r" 'message-goto-reply-to)
2583 (define-key message-mode-map "\C-c\C-f\C-n" 'message-goto-newsgroups)
2584 (define-key message-mode-map "\C-c\C-f\C-d" 'message-goto-distribution)
2585 (define-key message-mode-map "\C-c\C-f\C-f" 'message-goto-followup-to)
2586 (define-key message-mode-map "\C-c\C-f\C-m" 'message-goto-mail-followup-to)
2587 (define-key message-mode-map "\C-c\C-f\C-k" 'message-goto-keywords)
2588 (define-key message-mode-map "\C-c\C-f\C-u" 'message-goto-summary)
2589 (define-key message-mode-map "\C-c\C-f\C-i"
2590 'message-insert-or-toggle-importance)
2591 (define-key message-mode-map "\C-c\C-f\C-a"
2592 'message-generate-unsubscribed-mail-followup-to)
2594 ;; modify headers (and insert notes in body)
2595 (define-key message-mode-map "\C-c\C-fs" 'message-change-subject)
2597 (define-key message-mode-map "\C-c\C-fx" 'message-cross-post-followup-to)
2598 ;; prefix+message-cross-post-followup-to = same w/o cross-post
2599 (define-key message-mode-map "\C-c\C-ft" 'message-reduce-to-to-cc)
2600 (define-key message-mode-map "\C-c\C-fa" 'message-add-archive-header)
2601 ;; mark inserted text
2602 (define-key message-mode-map "\C-c\M-m" 'message-mark-inserted-region)
2603 (define-key message-mode-map "\C-c\M-f" 'message-mark-insert-file)
2605 (define-key message-mode-map "\C-c\C-b" 'message-goto-body)
2606 (define-key message-mode-map "\C-c\C-i" 'message-goto-signature)
2608 (define-key message-mode-map "\C-c\C-t" 'message-insert-to)
2609 (define-key message-mode-map "\C-c\C-fw" 'message-insert-wide-reply)
2610 (define-key message-mode-map "\C-c\C-n" 'message-insert-newsgroups)
2611 (define-key message-mode-map "\C-c\C-l" 'message-to-list-only)
2612 (define-key message-mode-map "\C-c\C-f\C-e" 'message-insert-expires)
2614 (define-key message-mode-map "\C-c\C-u" 'message-insert-or-toggle-importance)
2615 (define-key message-mode-map "\C-c\M-n"
2616 'message-insert-disposition-notification-to)
2618 (define-key message-mode-map "\C-c\C-y" 'message-yank-original)
2619 (define-key message-mode-map "\C-c\M-\C-y" 'message-yank-buffer)
2620 (define-key message-mode-map "\C-c\C-q" 'message-fill-yanked-message)
2621 (define-key message-mode-map "\C-c\C-w" 'message-insert-signature)
2622 (define-key message-mode-map "\C-c\M-h" 'message-insert-headers)
2623 (define-key message-mode-map "\C-c\C-r" 'message-caesar-buffer-body)
2624 (define-key message-mode-map "\C-c\C-o" 'message-sort-headers)
2625 (define-key message-mode-map "\C-c\M-r" 'message-rename-buffer)
2627 (define-key message-mode-map "\C-c\C-c" 'message-send-and-exit)
2628 (define-key message-mode-map "\C-c\C-s" 'message-send)
2629 (define-key message-mode-map "\C-c\C-k" 'message-kill-buffer)
2630 (define-key message-mode-map "\C-c\C-d" 'message-dont-send)
2631 (define-key message-mode-map "\C-c\n" 'gnus-delay-article)
2633 (define-key message-mode-map "\C-c\M-k" 'message-kill-address)
2634 (define-key message-mode-map "\C-c\C-e" 'message-elide-region)
2635 (define-key message-mode-map "\C-c\C-v" 'message-delete-not-region)
2636 (define-key message-mode-map "\C-c\C-z" 'message-kill-to-signature)
2637 (define-key message-mode-map "\M-\r" 'message-newline-and-reformat)
2638 (define-key message-mode-map [remap split-line] 'message-split-line)
2640 (define-key message-mode-map "\C-c\C-a" 'mml-attach-file)
2642 (define-key message-mode-map "\C-a" 'message-beginning-of-line)
2643 (define-key message-mode-map "\t" 'message-tab)
2644 (define-key message-mode-map "\M-;" 'comment-region)
2646 (define-key message-mode-map "\M-n" 'message-display-abbrev))
2649 message-mode-menu message-mode-map "Message Menu."
2651 ["Yank Original" message-yank-original message-reply-buffer]
2652 ["Fill Yanked Message" message-fill-yanked-message t]
2653 ["Insert Signature" message-insert-signature t]
2654 ["Caesar (rot13) Message" message-caesar-buffer-body t]
2655 ["Caesar (rot13) Region" message-caesar-region (message-mark-active-p)]
2656 ["Elide Region" message-elide-region
2657 :active (message-mark-active-p)
2658 ,@(if (featurep 'xemacs) nil
2659 '(:help "Replace text in region with an ellipsis"))]
2660 ["Delete Outside Region" message-delete-not-region
2661 :active (message-mark-active-p)
2662 ,@(if (featurep 'xemacs) nil
2663 '(:help "Delete all quoted text outside region"))]
2664 ["Kill To Signature" message-kill-to-signature t]
2665 ["Newline and Reformat" message-newline-and-reformat t]
2666 ["Rename buffer" message-rename-buffer t]
2667 ["Spellcheck" ispell-message
2668 ,@(if (featurep 'xemacs) '(t)
2669 '(:help "Spellcheck this message"))]
2671 ["Insert Region Marked" message-mark-inserted-region
2672 :active (message-mark-active-p)
2673 ,@(if (featurep 'xemacs) nil
2674 '(:help "Mark region with enclosing tags"))]
2675 ["Insert File Marked..." message-mark-insert-file
2676 ,@(if (featurep 'xemacs) '(t)
2677 '(:help "Insert file at point marked with enclosing tags"))]
2679 ["Send Message" message-send-and-exit
2680 ,@(if (featurep 'xemacs) '(t)
2681 '(:help "Send this message"))]
2682 ["Postpone Message" message-dont-send
2683 ,@(if (featurep 'xemacs) '(t)
2684 '(:help "File this draft message and exit"))]
2685 ["Send at Specific Time..." gnus-delay-article
2686 ,@(if (featurep 'xemacs) '(t)
2687 '(:help "Ask, then arrange to send message at that time"))]
2688 ["Kill Message" message-kill-buffer
2689 ,@(if (featurep 'xemacs) '(t)
2690 '(:help "Delete this message without sending"))]
2692 ["Message manual" message-info
2693 ,@(if (featurep 'xemacs) '(t)
2694 '(:help "Display the Message manual"))]))
2697 message-mode-field-menu message-mode-map ""
2699 ["To" message-goto-to t]
2700 ["From" message-goto-from t]
2701 ["Subject" message-goto-subject t]
2702 ["Change subject..." message-change-subject t]
2703 ["Cc" message-goto-cc t]
2704 ["Bcc" message-goto-bcc t]
2705 ["Fcc" message-goto-fcc t]
2706 ["Reply-To" message-goto-reply-to t]
2707 ["Flag As Important" message-insert-importance-high
2708 ,@(if (featurep 'xemacs) '(t)
2709 '(:help "Mark this message as important"))]
2710 ["Flag As Unimportant" message-insert-importance-low
2711 ,@(if (featurep 'xemacs) '(t)
2712 '(:help "Mark this message as unimportant"))]
2714 message-insert-disposition-notification-to
2715 ,@(if (featurep 'xemacs) '(t)
2716 '(:help "Request a receipt notification"))]
2718 ;; (typical) news stuff
2719 ["Summary" message-goto-summary t]
2720 ["Keywords" message-goto-keywords t]
2721 ["Newsgroups" message-goto-newsgroups t]
2722 ["Fetch Newsgroups" message-insert-newsgroups t]
2723 ["Followup-To" message-goto-followup-to t]
2724 ;; ["Followup-To (with note in body)" message-cross-post-followup-to t]
2725 ["Crosspost / Followup-To..." message-cross-post-followup-to t]
2726 ["Distribution" message-goto-distribution t]
2727 ["Expires" message-insert-expires t ]
2728 ["X-No-Archive" message-add-archive-header t ]
2730 ;; (typical) mailing-lists stuff
2731 ["Fetch To" message-insert-to
2732 ,@(if (featurep 'xemacs) '(t)
2733 '(:help "Insert a To header that points to the author."))]
2734 ["Fetch To and Cc" message-insert-wide-reply
2735 ,@(if (featurep 'xemacs) '(t)
2737 "Insert To and Cc headers as if you were doing a wide reply."))]
2739 ["Send to list only" message-to-list-only t]
2740 ["Mail-Followup-To" message-goto-mail-followup-to t]
2741 ["Unsubscribed list post" message-generate-unsubscribed-mail-followup-to
2742 ,@(if (featurep 'xemacs) '(t)
2743 '(:help "Insert a reasonable `Mail-Followup-To:' header."))]
2744 ["Reduce To: to Cc:" message-reduce-to-to-cc t]
2746 ["Sort Headers" message-sort-headers t]
2747 ["Encode non-ASCII domain names" message-idna-to-ascii-rhs t]
2748 ;; We hide `message-hidden-headers' by narrowing the buffer.
2749 ["Show Hidden Headers" widen t]
2750 ["Goto Body" message-goto-body t]
2751 ["Goto Signature" message-goto-signature t]))
2753 (defvar message-tool-bar-map nil)
2755 (defvar facemenu-add-face-function)
2756 (defvar facemenu-remove-face-function)
2758 ;;; Forbidden properties
2760 ;; We use `after-change-functions' to keep special text properties
2761 ;; that interfere with the normal function of message mode out of the
2764 (defcustom message-strip-special-text-properties t
2765 "Strip special properties from the message buffer.
2767 Emacs has a number of special text properties which can break message
2768 composing in various ways. If this option is set, message will strip
2769 these properties from the message composition buffer. However, some
2770 packages requires these properties to be present in order to work.
2771 If you use one of these packages, turn this option off, and hope the
2772 message composition doesn't break too bad."
2774 :group 'message-various
2775 :link '(custom-manual "(message)Various Message Variables")
2778 (defconst message-forbidden-properties
2779 ;; No reason this should be clutter up customize. We make it a
2780 ;; property list (rather than a list of property symbols), to be
2781 ;; directly useful for `remove-text-properties'.
2782 '(field nil read-only nil invisible nil intangible nil
2783 mouse-face nil modification-hooks nil insert-in-front-hooks nil
2784 insert-behind-hooks nil point-entered nil point-left nil)
2785 ;; Other special properties:
2786 ;; category, face, display: probably doesn't do any harm.
2787 ;; fontified: is used by font-lock.
2788 ;; syntax-table, local-map: I dunno.
2789 ;; We need to add XEmacs names to the list.
2790 "Property list of with properties forbidden in message buffers.
2791 The values of the properties are ignored, only the property names are used.")
2793 (defun message-tamago-not-in-use-p (pos)
2794 "Return t when tamago version 4 is not in use at the cursor position.
2795 Tamago version 4 is a popular input method for writing Japanese text.
2796 It uses the properties `intangible', `invisible', `modification-hooks'
2797 and `read-only' when translating ascii or kana text to kanji text.
2798 These properties are essential to work, so we should never strip them."
2799 (not (and (boundp 'egg-modefull-mode)
2800 (symbol-value 'egg-modefull-mode)
2801 (or (memq (get-text-property pos 'intangible)
2802 '(its-part-1 its-part-2))
2803 (get-text-property pos 'egg-end)
2804 (get-text-property pos 'egg-lang)
2805 (get-text-property pos 'egg-start)))))
2807 (defsubst message-mail-alias-type-p (type)
2808 (if (atom message-mail-alias-type)
2809 (eq message-mail-alias-type type)
2810 (memq type message-mail-alias-type)))
2812 (defun message-strip-forbidden-properties (begin end &optional old-length)
2813 "Strip forbidden properties between BEGIN and END, ignoring the third arg.
2814 This function is intended to be called from `after-change-functions'.
2815 See also `message-forbidden-properties'."
2816 (when (and (message-mail-alias-type-p 'ecomplete)
2817 (memq this-command message-self-insert-commands))
2818 (message-display-abbrev))
2819 (when (and message-strip-special-text-properties
2820 (message-tamago-not-in-use-p begin))
2821 (let ((buffer-read-only nil)
2822 (inhibit-read-only t))
2823 (remove-text-properties begin end message-forbidden-properties))))
2825 (autoload 'ecomplete-setup "ecomplete") ;; for Emacs <23.
2828 (define-derived-mode message-mode text-mode "Message"
2829 "Major mode for editing mail and news to be sent.
2830 Like Text Mode but with these additional commands:\\<message-mode-map>
2831 C-c C-s `message-send' (send the message) C-c C-c `message-send-and-exit'
2832 C-c C-d Postpone sending the message C-c C-k Kill the message
2833 C-c C-f move to a header field (and create it if there isn't):
2834 C-c C-f C-t move to To C-c C-f C-s move to Subject
2835 C-c C-f C-c move to Cc C-c C-f C-b move to Bcc
2836 C-c C-f C-w move to Fcc C-c C-f C-r move to Reply-To
2837 C-c C-f C-u move to Summary C-c C-f C-n move to Newsgroups
2838 C-c C-f C-k move to Keywords C-c C-f C-d move to Distribution
2839 C-c C-f C-o move to From (\"Originator\")
2840 C-c C-f C-f move to Followup-To
2841 C-c C-f C-m move to Mail-Followup-To
2842 C-c C-f C-e move to Expires
2843 C-c C-f C-i cycle through Importance values
2844 C-c C-f s change subject and append \"(was: <Old Subject>)\"
2845 C-c C-f x crossposting with FollowUp-To header and note in body
2846 C-c C-f t replace To: header with contents of Cc: or Bcc:
2847 C-c C-f a Insert X-No-Archive: header and a note in the body
2848 C-c C-t `message-insert-to' (add a To header to a news followup)
2849 C-c C-l `message-to-list-only' (removes all but list address in to/cc)
2850 C-c C-n `message-insert-newsgroups' (add a Newsgroup header to a news reply)
2851 C-c C-b `message-goto-body' (move to beginning of message text).
2852 C-c C-i `message-goto-signature' (move to the beginning of the signature).
2853 C-c C-w `message-insert-signature' (insert `message-signature-file' file).
2854 C-c C-y `message-yank-original' (insert current message, if any).
2855 C-c C-q `message-fill-yanked-message' (fill what was yanked).
2856 C-c C-e `message-elide-region' (elide the text between point and mark).
2857 C-c C-v `message-delete-not-region' (remove the text outside the region).
2858 C-c C-z `message-kill-to-signature' (kill the text up to the signature).
2859 C-c C-r `message-caesar-buffer-body' (rot13 the message body).
2860 C-c C-a `mml-attach-file' (attach a file as MIME).
2861 C-c C-u `message-insert-or-toggle-importance' (insert or cycle importance).
2862 C-c M-n `message-insert-disposition-notification-to' (request receipt).
2863 C-c M-m `message-mark-inserted-region' (mark region with enclosing tags).
2864 C-c M-f `message-mark-insert-file' (insert file marked with enclosing tags).
2865 M-RET `message-newline-and-reformat' (break the line and reformat)."
2866 (setq local-abbrev-table text-mode-abbrev-table)
2867 (set (make-local-variable 'message-reply-buffer) nil)
2868 (set (make-local-variable 'message-inserted-headers) nil)
2869 (set (make-local-variable 'message-send-actions) nil)
2870 (set (make-local-variable 'message-exit-actions) nil)
2871 (set (make-local-variable 'message-kill-actions) nil)
2872 (set (make-local-variable 'message-postpone-actions) nil)
2873 (set (make-local-variable 'message-draft-article) nil)
2874 (setq buffer-offer-save t)
2875 (set (make-local-variable 'facemenu-add-face-function)
2877 (let ((face-fun (cdr (assq face message-face-alist))))
2879 (funcall face-fun (point) end)
2880 (error "Face %s not configured for %s mode" face mode-name)))
2882 (set (make-local-variable 'facemenu-remove-face-function) t)
2883 (set (make-local-variable 'message-reply-headers) nil)
2884 (make-local-variable 'message-newsreader)
2885 (make-local-variable 'message-mailer)
2886 (make-local-variable 'message-post-method)
2887 (set (make-local-variable 'message-sent-message-via) nil)
2888 (set (make-local-variable 'message-checksum) nil)
2889 (set (make-local-variable 'message-mime-part) 0)
2890 (message-setup-fill-variables)
2891 (when message-fill-column
2892 (setq fill-column message-fill-column)
2893 (turn-on-auto-fill))
2894 ;; Allow using comment commands to add/remove quoting.
2895 ;; (set (make-local-variable 'comment-start) message-yank-prefix)
2896 (when message-yank-prefix
2897 (set (make-local-variable 'comment-start) message-yank-prefix)
2898 (set (make-local-variable 'comment-start-skip)
2899 (concat "^" (regexp-quote message-yank-prefix) "[ \t]*")))
2900 (if (featurep 'xemacs)
2901 (message-setup-toolbar)
2902 (set (make-local-variable 'font-lock-defaults)
2903 '(message-font-lock-keywords t))
2904 (if (boundp 'tool-bar-map)
2905 (set (make-local-variable 'tool-bar-map) (message-make-tool-bar))))
2906 (easy-menu-add message-mode-menu message-mode-map)
2907 (easy-menu-add message-mode-field-menu message-mode-map)
2908 (gnus-make-local-hook 'after-change-functions)
2909 ;; Mmmm... Forbidden properties...
2910 (add-hook 'after-change-functions 'message-strip-forbidden-properties
2912 ;; Allow mail alias things.
2914 ((message-mail-alias-type-p 'abbrev)
2915 (if (fboundp 'mail-abbrevs-setup)
2916 (mail-abbrevs-setup)
2917 (if (fboundp 'mail-aliases-setup) ; warning avoidance
2918 (mail-aliases-setup))))
2919 ((message-mail-alias-type-p 'ecomplete)
2921 (unless buffer-file-name
2922 (message-set-auto-save-file-name))
2923 (unless (buffer-base-buffer)
2924 ;; Don't enable multibyte on an indirect buffer. Maybe enabling
2925 ;; multibyte is not necessary at all. -- zsh
2926 (mm-enable-multibyte))
2927 (set (make-local-variable 'indent-tabs-mode) nil) ;No tabs for indentation.
2930 (defun message-setup-fill-variables ()
2931 "Setup message fill variables."
2932 (set (make-local-variable 'fill-paragraph-function)
2933 'message-fill-paragraph)
2934 (make-local-variable 'paragraph-separate)
2935 (make-local-variable 'paragraph-start)
2936 (make-local-variable 'adaptive-fill-regexp)
2937 (unless (boundp 'adaptive-fill-first-line-regexp)
2938 (setq adaptive-fill-first-line-regexp nil))
2939 (make-local-variable 'adaptive-fill-first-line-regexp)
2940 (let ((quote-prefix-regexp
2941 ;; User should change message-cite-prefix-regexp if
2942 ;; message-yank-prefix is set to an abnormal value.
2943 (concat "\\(" message-cite-prefix-regexp "\\)[ \t]*")))
2944 (setq paragraph-start
2946 (regexp-quote mail-header-separator) "$\\|"
2947 "[ \t]*$\\|" ; blank lines
2948 "-- $\\|" ; signature delimiter
2949 "---+$\\|" ; delimiters for forwarded messages
2950 page-delimiter "$\\|" ; spoiler warnings
2951 ".*wrote:$\\|" ; attribution lines
2952 quote-prefix-regexp "$\\|" ; empty lines in quoted text
2954 "<#!*/?\\(multipart\\|part\\|external\\|mml\\|secure\\)"))
2955 (setq paragraph-separate paragraph-start)
2956 (setq adaptive-fill-regexp
2957 (concat quote-prefix-regexp "\\|" adaptive-fill-regexp))
2958 (setq adaptive-fill-first-line-regexp
2959 (concat quote-prefix-regexp "\\|"
2960 adaptive-fill-first-line-regexp)))
2961 (make-local-variable 'auto-fill-inhibit-regexp)
2962 ;;(setq auto-fill-inhibit-regexp "^[A-Z][^: \n\t]+:")
2963 (setq auto-fill-inhibit-regexp nil)
2964 (make-local-variable 'normal-auto-fill-function)
2965 (setq normal-auto-fill-function 'message-do-auto-fill)
2966 ;; KLUDGE: auto fill might already be turned on in `text-mode-hook'.
2967 ;; In that case, ensure that it uses the right function. The real
2968 ;; solution would be not to use `define-derived-mode', and run
2969 ;; `text-mode-hook' ourself at the end of the mode.
2970 ;; -- Per Abrahamsen <abraham@dina.kvl.dk> Date: 2001-10-19.
2971 ;; This kludge is unneeded in Emacs>=21 since define-derived-mode is
2972 ;; now careful to run parent hooks after the body. --Stef
2973 (when auto-fill-function
2974 (setq auto-fill-function normal-auto-fill-function)))
2979 ;;; Message mode commands
2982 ;;; Movement commands
2984 (defun message-goto-to ()
2985 "Move point to the To header."
2987 (message-position-on-field "To"))
2989 (defun message-goto-from ()
2990 "Move point to the From header."
2992 (message-position-on-field "From"))
2994 (defun message-goto-subject ()
2995 "Move point to the Subject header."
2997 (message-position-on-field "Subject"))
2999 (defun message-goto-cc ()
3000 "Move point to the Cc header."
3002 (message-position-on-field "Cc" "To"))
3004 (defun message-goto-bcc ()
3005 "Move point to the Bcc header."
3007 (message-position-on-field "Bcc" "Cc" "To"))
3009 (defun message-goto-fcc ()
3010 "Move point to the Fcc header."
3012 (message-position-on-field "Fcc" "To" "Newsgroups"))
3014 (defun message-goto-reply-to ()
3015 "Move point to the Reply-To header."
3017 (message-position-on-field "Reply-To" "Subject"))
3019 (defun message-goto-newsgroups ()
3020 "Move point to the Newsgroups header."
3022 (message-position-on-field "Newsgroups"))
3024 (defun message-goto-distribution ()
3025 "Move point to the Distribution header."
3027 (message-position-on-field "Distribution"))
3029 (defun message-goto-followup-to ()
3030 "Move point to the Followup-To header."
3032 (message-position-on-field "Followup-To" "Newsgroups"))
3034 (defun message-goto-mail-followup-to ()
3035 "Move point to the Mail-Followup-To header."
3037 (message-position-on-field "Mail-Followup-To" "To"))
3039 (defun message-goto-keywords ()
3040 "Move point to the Keywords header."
3042 (message-position-on-field "Keywords" "Subject"))
3044 (defun message-goto-summary ()
3045 "Move point to the Summary header."
3047 (message-position-on-field "Summary" "Subject"))
3049 (defun message-goto-body (&optional interactivep)
3050 "Move point to the beginning of the message body."
3051 (interactive (list t))
3052 (when (and interactivep
3053 (looking-at "[ \t]*\n"))
3055 (goto-char (point-min))
3056 (or (search-forward (concat "\n" mail-header-separator "\n") nil t)
3057 (search-forward-regexp "[^:]+:\\([^\n]\\|\n[ \t]\\)+\n\n" nil t)))
3059 (defun message-in-body-p ()
3060 "Return t if point is in the message body."
3061 (let ((body (save-excursion (message-goto-body) (point))))
3064 (defun message-goto-eoh ()
3065 "Move point to the end of the headers."
3070 (defun message-goto-signature ()
3071 "Move point to the beginning of the message signature.
3072 If there is no signature in the article, go to the end and
3075 (goto-char (point-min))
3076 (if (re-search-forward message-signature-separator nil t)
3078 (goto-char (point-max))
3081 (defun message-generate-unsubscribed-mail-followup-to (&optional include-cc)
3082 "Insert a reasonable MFT header in a post to an unsubscribed list.
3083 When making original posts to a mailing list you are not subscribed to,
3084 you have to type in a MFT header by hand. The contents, usually, are
3085 the addresses of the list and your own address. This function inserts
3086 such a header automatically. It fetches the contents of the To: header
3087 in the current mail buffer, and appends the current `user-mail-address'.
3089 If the optional argument INCLUDE-CC is non-nil, the addresses in the
3090 Cc: header are also put into the MFT."
3095 (message-narrow-to-headers)
3096 (message-remove-header "Mail-Followup-To")
3097 (setq cc (and include-cc (message-fetch-field "Cc")))
3099 (concat (message-fetch-field "To") "," cc)
3100 (message-fetch-field "To"))))
3101 (message-goto-mail-followup-to)
3102 (insert (concat tos ", " user-mail-address))))
3106 (defun message-insert-to (&optional force)
3107 "Insert a To header that points to the author of the article being replied to.
3108 If the original author requested not to be sent mail, don't insert unless the
3109 prefix FORCE is given."
3111 (let* ((mct (message-fetch-reply-field "mail-copies-to"))
3112 (dont (and mct (or (equal (downcase mct) "never")
3113 (equal (downcase mct) "nobody"))))
3114 (to (or (message-fetch-reply-field "mail-reply-to")
3115 (message-fetch-reply-field "reply-to")
3116 (message-fetch-reply-field "from"))))
3120 "Ignoring the user request not to have copies sent via mail"
3121 "Complying with the user request not to have copies sent via mail")))
3122 (when (and force (not to))
3123 (error "No mail address in the article"))
3124 (when (and to (or force (not dont)))
3125 (message-carefully-insert-headers (list (cons 'To to))))))
3127 (defun message-insert-wide-reply ()
3128 "Insert To and Cc headers as if you were doing a wide reply."
3130 (let ((headers (message-with-reply-buffer
3131 (message-get-reply-headers t))))
3132 (message-carefully-insert-headers headers)))
3134 (defcustom message-header-synonyms
3137 "List of lists of header synonyms.
3138 E.g., if this list contains a member list with elements `Cc' and `To',
3139 then `message-carefully-insert-headers' will not insert a `To' header
3140 when the message is already `Cc'ed to the recipient."
3142 :group 'message-headers
3143 :link '(custom-manual "(message)Message Headers")
3144 :type '(repeat sexp))
3146 (defun message-carefully-insert-headers (headers)
3147 "Insert the HEADERS, an alist, into the message buffer.
3148 Does not insert the headers when they are already present there
3149 or in the synonym headers, defined by `message-header-synonyms'."
3150 ;; FIXME: Should compare only the address and not the full name. Comparison
3151 ;; should be done case-folded (and with `string=' rather than
3153 ;; (mail-strip-quoted-names "Foo Bar <foo@bar>, bla@fasel (Bla Fasel)")
3154 (dolist (header headers)
3155 (let* ((header-name (symbol-name (car header)))
3156 (new-header (cdr header))
3157 (synonyms (loop for synonym in message-header-synonyms
3158 when (memq (car header) synonym) return synonym))
3160 (loop for synonym in synonyms
3161 for old-header = (mail-fetch-field (symbol-name synonym))
3162 when (and old-header (string-match new-header old-header))
3165 (message "already have `%s' in `%s'" new-header old-header)
3166 (when (and (message-position-on-field header-name)
3167 (setq old-header (mail-fetch-field header-name))
3168 (not (string-match "\\` *\\'" old-header)))
3170 (insert new-header)))))
3172 (defun message-widen-reply ()
3173 "Widen the reply to include maximum recipients."
3176 (and (bufferp message-reply-buffer)
3177 (buffer-name message-reply-buffer)
3178 (with-current-buffer message-reply-buffer
3179 (message-get-reply-headers t)))))
3182 (message-narrow-to-headers)
3183 (dolist (elem follow-to)
3184 (message-remove-header (symbol-name (car elem)))
3185 (goto-char (point-min))
3186 (insert (symbol-name (car elem)) ": "
3187 (cdr elem) "\n"))))))
3189 (defun message-insert-newsgroups ()
3190 "Insert the Newsgroups header from the article being replied to."
3192 (when (and (message-position-on-field "Newsgroups")
3193 (mail-fetch-field "newsgroups")
3194 (not (string-match "\\` *\\'" (mail-fetch-field "newsgroups"))))
3196 (insert (or (message-fetch-reply-field "newsgroups") "")))
3200 ;;; Various commands
3202 (defun message-delete-not-region (beg end)
3203 "Delete everything in the body of the current message outside of the region."
3208 ;; snarf citation prefix, if appropriate
3209 (unless (eq (point) (progn (beginning-of-line) (point)))
3210 (when (looking-at message-cite-prefix-regexp)
3211 (setq citeprefix (match-string 0))))
3213 (delete-region (point) (if (not (message-goto-signature))
3219 (delete-region beg (progn (message-goto-body)
3223 (insert citeprefix))))
3224 (when (message-goto-signature)
3227 (defun message-kill-to-signature (&optional arg)
3228 "Kill all text up to the signature.
3229 If a numeric argument or prefix arg is given, leave that number
3230 of lines before the signature intact."
3234 (let ((point (point)))
3235 (narrow-to-region point (point-max))
3236 (message-goto-signature)
3238 (if (and arg (numberp arg))
3239 (forward-line (- -1 arg))
3241 (unless (= point (point))
3242 (kill-region point (point))
3246 (defun message-newline-and-reformat (&optional arg not-break)
3247 "Insert four newlines, and then reformat if inside quoted text.
3248 Prefix arg means justify as well."
3249 (interactive (list (if current-prefix-arg 'full)))
3250 (let (quoted point beg end leading-space bolp fill-paragraph-function)
3251 (setq point (point))
3254 (setq bolp (= beg point))
3255 ;; Find first line of the paragraph.
3257 (while (and (not (eobp))
3258 (not (looking-at message-cite-prefix-regexp))
3259 (looking-at paragraph-start))
3262 (when (looking-at message-cite-prefix-regexp)
3263 (setq quoted (match-string 0))
3264 (goto-char (match-end 0))
3265 (looking-at "[ \t]*")
3266 (setq leading-space (match-string 0)))
3270 (< (- point beg) (length quoted)))
3271 ;; break inside the cite prefix.
3277 (while (and (not (eobp))
3278 (not (looking-at paragraph-separate))
3279 (looking-at message-cite-prefix-regexp)
3280 (equal quoted (match-string 0)))
3281 (goto-char (match-end 0))
3282 (looking-at "[ \t]*")
3283 (if (> (length leading-space) (length (match-string 0)))
3284 (setq leading-space (match-string 0)))
3288 (while (and (if (bobp) nil (forward-line -1) t)
3289 (not (looking-at paragraph-start))
3290 (looking-at message-cite-prefix-regexp)
3291 (equal quoted (match-string 0)))
3293 (goto-char (match-end 0))
3294 (looking-at "[ \t]*")
3295 (if (> (length leading-space) (length (match-string 0)))
3296 (setq leading-space (match-string 0)))))
3297 (while (and (not (eobp))
3298 (not (looking-at paragraph-separate))
3299 (not (looking-at message-cite-prefix-regexp)))
3303 (while (and (if (bobp) nil (forward-line -1) t)
3304 (not (looking-at paragraph-start))
3305 (not (looking-at message-cite-prefix-regexp)))
3306 (setq beg (point))))
3309 (narrow-to-region beg end)
3316 (setq point (point))
3317 ;; (newline 2) doesn't mark both newline's as hard, so call
3318 ;; newline twice. -jas
3321 (delete-region (point) (re-search-forward "[ \t]*"))
3322 (when (and quoted (not bolp))
3323 (insert quoted leading-space)))
3326 (let* ((adaptive-fill-regexp
3327 (regexp-quote (concat quoted leading-space)))
3328 (adaptive-fill-first-line-regexp
3329 adaptive-fill-regexp ))
3330 (fill-paragraph arg))
3331 (fill-paragraph arg))
3332 (if point (goto-char point)))))
3334 (defun message-fill-paragraph (&optional arg)
3335 "Message specific function to fill a paragraph.
3336 This function is used as the value of `fill-paragraph-function' in
3337 Message buffers and is not meant to be called directly."
3338 (interactive (list (if current-prefix-arg 'full)))
3339 (if (if (boundp 'filladapt-mode) filladapt-mode)
3341 (if (message-point-in-header-p)
3342 (message-fill-field)
3343 (message-newline-and-reformat arg t))
3346 (defun message-point-in-header-p ()
3347 "Return t if point is in the header."
3349 (not (re-search-backward
3350 (concat "^" (regexp-quote mail-header-separator) "\n") nil t))))
3352 (defun message-do-auto-fill ()
3353 "Like `do-auto-fill', but don't fill in message header."
3354 (unless (message-point-in-header-p)
3357 (defun message-insert-signature (&optional force)
3358 "Insert a signature. See documentation for variable `message-signature'."
3359 (interactive (list 0))
3362 ((and (null message-signature)
3365 (goto-char (point-max))
3366 (not (re-search-backward message-signature-separator nil t))))
3367 ((and (null message-signature)
3370 ((functionp message-signature)
3371 (funcall message-signature))
3372 ((listp message-signature)
3373 (eval message-signature))
3374 (t message-signature)))
3377 (cond ((stringp signature)
3379 ((and (eq t signature) message-signature-file)
3380 (setq signature-file
3381 (if (and message-signature-directory
3382 ;; don't actually use the signature directory
3383 ;; if message-signature-file contains a path.
3384 (not (file-name-directory
3385 message-signature-file)))
3386 (expand-file-name message-signature-file
3387 message-signature-directory)
3388 message-signature-file))
3389 (file-exists-p signature-file))))
3391 (goto-char (point-max))
3392 ;; Insert the signature.
3395 (when message-signature-insert-empty-line
3398 (if (eq signature t)
3399 (insert-file-contents signature-file)
3401 (goto-char (point-max))
3402 (or (bolp) (insert "\n")))))
3404 (defun message-insert-importance-high ()
3405 "Insert header to mark message as important."
3409 (message-narrow-to-headers)
3410 (message-remove-header "Importance"))
3412 (insert "Importance: high\n")))
3414 (defun message-insert-importance-low ()
3415 "Insert header to mark message as unimportant."
3419 (message-narrow-to-headers)
3420 (message-remove-header "Importance"))
3422 (insert "Importance: low\n")))
3424 (defun message-insert-or-toggle-importance ()
3425 "Insert a \"Importance: high\" header, or cycle through the header values.
3426 The three allowed values according to RFC 1327 are `high', `normal'
3433 (message-narrow-to-headers)
3434 (when (setq cur (message-fetch-field "Importance"))
3435 (message-remove-header "Importance")
3436 (setq new (cond ((string= cur "high")
3438 ((string= cur "low")
3443 (insert (format "Importance: %s\n" new)))))
3445 (defun message-insert-disposition-notification-to ()
3446 "Request a disposition notification (return receipt) to this message.
3447 Note that this should not be used in newsgroups."
3451 (message-narrow-to-headers)
3452 (message-remove-header "Disposition-Notification-To"))
3454 (insert (format "Disposition-Notification-To: %s\n"
3455 (or (message-field-value "Reply-to")
3456 (message-field-value "From")
3457 (message-make-from))))))
3459 (defun message-elide-region (b e)
3460 "Elide the text in the region.
3461 An ellipsis (from `message-elide-ellipsis') will be inserted where the
3465 (insert message-elide-ellipsis))
3467 (defvar message-caesar-translation-table nil)
3469 (defun message-caesar-region (b e &optional n)
3470 "Caesar rotate region B to E by N, default 13, for decrypting netnews."
3473 (min (point) (or (mark t) (point)))
3474 (max (point) (or (mark t) (point)))
3475 (when current-prefix-arg
3476 (prefix-numeric-value current-prefix-arg))))
3478 (setq n (if (numberp n) (mod n 26) 13)) ;canonize N
3479 (unless (or (zerop n) ; no action needed for a rot of 0
3480 (= b e)) ; no region to rotate
3481 ;; We build the table, if necessary.
3482 (when (or (not message-caesar-translation-table)
3483 (/= (aref message-caesar-translation-table ?a) (+ ?a n)))
3484 (setq message-caesar-translation-table
3485 (message-make-caesar-translation-table n)))
3486 (translate-region b e message-caesar-translation-table)))
3488 (defun message-make-caesar-translation-table (n)
3489 "Create a rot table with offset N."
3491 (table (make-string 256 0)))
3492 (while (< (incf i) 256)
3495 (substring table 0 ?A)
3496 (substring table (+ ?A n) (+ ?A n (- 26 n)))
3497 (substring table ?A (+ ?A n))
3498 (substring table (+ ?A 26) ?a)
3499 (substring table (+ ?a n) (+ ?a n (- 26 n)))
3500 (substring table ?a (+ ?a n))
3501 (substring table (+ ?a 26) 255))))
3503 (defun message-caesar-buffer-body (&optional rotnum wide)
3504 "Caesar rotate all letters in the current buffer by 13 places.
3505 Used to encode/decode possibly offensive messages (commonly in rec.humor).
3506 With prefix arg, specifies the number of places to rotate each letter forward.
3507 Mail and USENET news headers are not rotated unless WIDE is non-nil."
3508 (interactive (if current-prefix-arg
3509 (list (prefix-numeric-value current-prefix-arg))
3513 (when (and (not wide) (message-goto-body))
3514 (narrow-to-region (point) (point-max)))
3515 (message-caesar-region (point-min) (point-max) rotnum))))
3517 (defun message-pipe-buffer-body (program)
3518 "Pipe the message body in the current buffer through PROGRAM."
3521 (when (message-goto-body)
3522 (narrow-to-region (point) (point-max)))
3523 (shell-command-on-region
3524 (point-min) (point-max) program nil t))))
3526 (defun message-rename-buffer (&optional enter-string)
3527 "Rename the *message* buffer to \"*message* RECIPIENT\".
3528 If the function is run with a prefix, it will ask for a new buffer
3529 name, rather than giving an automatic name."
3530 (interactive "Pbuffer name: ")
3533 (goto-char (point-min))
3534 (narrow-to-region (point)
3535 (search-forward mail-header-separator nil 'end))
3537 (if (message-news-p) (message-fetch-field "Newsgroups")
3538 (message-fetch-field "To"))
3541 (if (string-match "," mail-to)
3542 (concat (substring mail-to 0 (match-beginning 0)) ", ...")
3544 (name-default (concat "*message* " mail-trimmed-to))
3545 (name (if enter-string
3546 (read-string "New buffer name: " name-default)
3548 (rename-buffer name t)))))
3550 (defun message-fill-yanked-message (&optional justifyp)
3551 "Fill the paragraphs of a message yanked into this one.
3552 Numeric argument means justify as well."
3555 (goto-char (point-min))
3556 (search-forward (concat "\n" mail-header-separator "\n") nil t)
3557 (let ((fill-prefix message-yank-prefix))
3558 (fill-individual-paragraphs (point) (point-max) justifyp))))
3560 (defun message-indent-citation (&optional start end yank-only)
3561 "Modify text just inserted from a message to be cited.
3562 The inserted text should be the region.
3563 When this function returns, the region is again around the modified text.
3565 Normally, indent each nonblank line `message-indentation-spaces' spaces.
3566 However, if `message-yank-prefix' is non-nil, insert that prefix on each line."
3567 (unless start (setq start (point)))
3569 ;; Remove unwanted headers.
3570 (when message-ignored-cited-headers
3575 (if (search-forward "\n\n" nil t)
3578 (message-remove-header message-ignored-cited-headers t)
3579 (when (= (point-min) (point-max))
3580 (setq all-removed t))
3581 (goto-char (point-max)))
3585 ;; Delete blank lines at the start of the buffer.
3586 (while (and (point-min)
3589 (message-delete-line))
3590 ;; Delete blank lines at the end of the buffer.
3591 (goto-char (point-max))
3594 (while (and (zerop (forward-line -1))
3596 (message-delete-line)))
3597 ;; Do the indentation.
3598 (if (null message-yank-prefix)
3599 (indent-rigidly start (or end (mark t)) message-indentation-spaces)
3602 (while (< (point) (or end (mark t)))
3603 (cond ((looking-at ">")
3604 (insert message-yank-cited-prefix))
3606 (insert message-yank-empty-prefix))
3608 (insert message-yank-prefix)))
3612 (defun message-remove-blank-cited-lines (&optional remove)
3613 "Remove cited lines containing only blanks.
3614 If REMOVE is non-nil, remove newlines, too.
3616 To use this automatically, you may add this function to
3617 `gnus-message-setup-hook'."
3622 (when (boundp 'message-yank-cited-prefix)
3623 (concat message-yank-cited-prefix "\\|"))
3627 (gnus-message 8 "removing `%s'" citexp)
3630 (while (re-search-forward citexp nil t)
3631 (replace-match (if remove "" "\n"))))))
3633 (defvar message-cite-reply-above nil
3634 "If non-nil, start own text above the quote.
3636 Note: Top posting is bad netiquette. Don't use it unless you
3637 really must. You probably want to set variable only for specific
3638 groups, e.g. using `gnus-posting-styles':
3640 (eval (set (make-local-variable 'message-cite-reply-above) t))
3642 This variable has no effect in news postings.")
3644 (defun message-yank-original (&optional arg)
3645 "Insert the message being replied to, if any.
3646 Puts point before the text and mark after.
3647 Normally indents each nonblank line ARG spaces (default 3). However,
3648 if `message-yank-prefix' is non-nil, insert that prefix on each line.
3650 This function uses `message-cite-function' to do the actual citing.
3652 Just \\[universal-argument] as argument means don't indent, insert no
3653 prefix, and don't delete any headers."
3655 (let ((modified (buffer-modified-p))
3657 (when (and message-reply-buffer
3658 message-cite-function)
3659 (when message-cite-reply-above
3660 (if (and (not (message-news-p))
3661 (or (eq message-cite-reply-above 'is-evil)
3663 Top posting is bad netiquette. Please don't top post unless you really must.
3664 Really top post? ")))
3667 (buffer-substring (message-goto-body)
3669 (delete-region (message-goto-body) (point-max)))
3670 (set (make-local-variable 'message-cite-reply-above) nil)))
3671 (if (bufferp message-reply-buffer)
3672 (delete-windows-on message-reply-buffer t))
3673 (push-mark (save-excursion
3675 ((bufferp message-reply-buffer)
3676 (insert-buffer-substring message-reply-buffer))
3677 ((and (consp message-reply-buffer)
3678 (functionp (car message-reply-buffer)))
3679 (apply (car message-reply-buffer)
3680 (cdr message-reply-buffer))))
3685 (funcall message-cite-function)
3686 (unless (eq (char-before (mark t)) ?\n)
3688 (goto-char (mark t))
3689 (insert-before-markers ?\n)
3691 (when message-cite-reply-above
3694 (insert (if (bolp) "\n" "\n\n"))
3695 (message-goto-body))
3696 ;; Add a `message-setup-very-last-hook' here?
3697 ;; Add `gnus-article-highlight-citation' here?
3699 (setq message-checksum (message-checksum))))))
3701 (defun message-yank-buffer (buffer)
3702 "Insert BUFFER into the current buffer and quote it."
3703 (interactive "bYank buffer: ")
3704 (let ((message-reply-buffer (get-buffer buffer)))
3705 (save-window-excursion
3706 (message-yank-original))))
3708 (defun message-buffers ()
3709 "Return a list of active message buffers."
3711 (save-current-buffer
3712 (dolist (buffer (buffer-list t))
3714 (when (and (eq major-mode 'message-mode)
3715 (null message-sent-message-via))
3716 (push (buffer-name buffer) buffers))))
3717 (nreverse buffers)))
3719 (defun message-cite-original-1 (strip-signature)
3720 "Cite an original message.
3721 If STRIP-SIGNATURE is non-nil, strips off the signature from the
3724 This function uses `mail-citation-hook' if that is non-nil."
3725 (if (and (boundp 'mail-citation-hook)
3727 (run-hooks 'mail-citation-hook)
3728 (let* ((start (point))
3732 (when message-indent-citation-function
3733 (if (listp message-indent-citation-function)
3734 message-indent-citation-function
3735 (list message-indent-citation-function))))
3736 ;; This function may be called by `gnus-summary-yank-message' and
3737 ;; may insert a different article from the original. So, we will
3738 ;; modify the value of `message-reply-headers' with that article.
3739 (message-reply-headers
3741 (narrow-to-region start end)
3742 (message-narrow-to-head-1)
3743 (setq x-no-archive (message-fetch-field "x-no-archive"))
3745 (or (message-fetch-field "subject") "none")
3746 (or (message-fetch-field "from") "nobody")
3747 (message-fetch-field "date")
3748 (message-fetch-field "message-id" t)
3749 (message-fetch-field "references")
3751 (mml-quote-region start end)
3752 (when strip-signature
3756 (when (re-search-backward message-signature-separator start t)
3757 ;; Also peel off any blank lines before the signature.
3759 (while (looking-at "^[ \t]*$")
3762 (delete-region (point) end)
3763 (unless (search-backward "\n\n" start t)
3764 ;; Insert a blank line if it is peeled off.
3767 (mapc 'funcall functions)
3768 (when message-citation-line-function
3771 (funcall message-citation-line-function))
3772 (when (and x-no-archive
3773 (not message-cite-articles-with-x-no-archive)
3774 (string-match "yes" x-no-archive))
3776 (delete-region (point) (mark t))
3777 (insert "> [Quoted text removed due to X-No-Archive]\n")
3779 (forward-line -1)))))
3781 (defun message-cite-original ()
3782 "Cite function in the standard Message manner."
3783 (message-cite-original-1 nil))
3785 (defvar gnus-extract-address-components)
3787 (autoload 'format-spec "format-spec")
3789 (defun message-insert-formatted-citation-line (&optional from date)
3790 "Function that inserts a formatted citation line.
3792 See `message-citation-line-format'."
3793 ;; The optional args are for testing/debugging. They will disappear later.
3795 ;; (with-temp-buffer
3796 ;; (message-insert-formatted-citation-line
3797 ;; "John Doe <john.doe@example.invalid>"
3800 (when (or message-reply-headers (and from date))
3802 (setq from (mail-header-from message-reply-headers)))
3803 (let* ((data (condition-case ()
3804 (funcall (if (boundp gnus-extract-address-components)
3805 gnus-extract-address-components
3806 'mail-extract-address-components)
3812 (net (car (cdr data)))
3813 (name-or-net (or (car data)
3814 (car (cdr data)) from))
3818 ;; We need Gnus functionality if the user wants date or time from
3819 ;; the original article:
3820 (when (string-match "%[^fnNFL]" message-citation-line-format)
3821 (autoload 'gnus-date-get-time "gnus-util")
3822 (gnus-date-get-time (mail-header-date message-reply-headers)))))
3825 (when (stringp name)
3826 ;; Guess first name and last name:
3827 (cond ((string-match
3828 "\\`\\(\\w\\|[-.]\\)+ \\(\\w\\|[-.]\\)+\\'" name)
3829 (setq fname (nth 0 (split-string name "[ \t]+"))
3830 lname (nth 1 (split-string name "[ \t]+"))))
3832 "\\`\\(\\w\\|[-.]\\)+, \\(\\w\\|[-.]\\)+\\'" name)
3833 (setq fname (nth 1 (split-string name "[ \t,]+"))
3834 lname (nth 0 (split-string name "[ \t,]+"))))
3836 "\\`\\(\\w\\|[-.]\\)+\\'" name)
3839 ;; The following letters are not used in `format-time-string':
3840 (push ?E lst) (push "<E>" lst)
3841 (push ?F lst) (push fname lst)
3842 ;; We might want to use "" instead of "<X>" later.
3843 (push ?J lst) (push "<J>" lst)
3844 (push ?K lst) (push "<K>" lst)
3845 (push ?L lst) (push lname lst)
3846 (push ?N lst) (push name-or-net lst)
3847 (push ?O lst) (push "<O>" lst)
3848 (push ?P lst) (push "<P>" lst)
3849 (push ?Q lst) (push "<Q>" lst)
3850 (push ?f lst) (push from lst)
3851 (push ?i lst) (push "<i>" lst)
3852 (push ?n lst) (push net lst)
3853 (push ?o lst) (push "<o>" lst)
3854 (push ?q lst) (push "<q>" lst)
3855 (push ?t lst) (push "<t>" lst)
3856 (push ?v lst) (push "<v>" lst)
3857 ;; Delegate the rest to `format-time-string':
3859 (when (and (not (memq i lst))
3864 (push (condition-case nil
3865 (format-time-string (format "%%%c" i) replydate)
3866 (error (format ">%c<" i)))
3870 (spec (apply 'format-spec-make flist)))
3871 (insert (format-spec message-citation-line-format spec)))
3874 (defun message-cite-original-without-signature ()
3875 "Cite function in the standard Message manner.
3876 This function strips off the signature from the original message."
3877 (message-cite-original-1 t))
3879 (defun message-insert-citation-line ()
3880 "Insert a simple citation line."
3881 (when message-reply-headers
3882 (insert (mail-header-from message-reply-headers) " writes:")
3886 (defun message-position-on-field (header &rest afters)
3887 (let ((case-fold-search t))
3890 (goto-char (point-min))
3893 (concat "^" (regexp-quote mail-header-separator) "$"))
3894 (match-beginning 0)))
3895 (goto-char (point-min))
3896 (if (re-search-forward (concat "^" (regexp-quote header) ":") nil t)
3898 (re-search-forward "^[^ \t]" nil 'move)
3900 (skip-chars-backward "\n")
3903 (not (re-search-forward
3904 (concat "^" (regexp-quote (car afters)) ":")
3908 (re-search-forward "^[^ \t]" nil 'move)
3909 (beginning-of-line))
3910 (insert header ": \n")
3914 (defun message-remove-signature ()
3915 "Remove the signature from the text between point and mark.
3916 The text will also be indented the normal way."
3918 (let ((start (point))
3920 (if (not (re-search-forward message-signature-separator (mark t) t))
3921 ;; No signature here, so we just indent the cited text.
3922 (message-indent-citation)
3923 ;; Find the last non-empty line.
3925 (while (looking-at "[ \t]*$")
3928 (setq mark (set-marker (make-marker) (point)))
3930 (message-indent-citation)
3931 ;; Enable undoing the deletion.
3933 (delete-region mark (mark t))
3934 (set-marker mark nil)))))
3939 ;;; Sending messages
3942 (defun message-send-and-exit (&optional arg)
3943 "Send message like `message-send', then, if no errors, exit from mail buffer."
3945 (let ((buf (current-buffer))
3946 (actions message-exit-actions))
3947 (when (and (message-send arg)
3949 (if message-kill-buffer-on-exit
3952 (when (eq buf (current-buffer))
3953 (message-bury buf)))
3954 (message-do-actions actions)
3957 (defun message-dont-send ()
3958 "Don't send the message you have been editing.
3959 Instead, just auto-save the buffer and then bury it."
3961 (set-buffer-modified-p t)
3963 (let ((actions message-postpone-actions))
3964 (message-bury (current-buffer))
3965 (message-do-actions actions)))
3967 (defun message-kill-buffer ()
3968 "Kill the current buffer."
3970 (when (or (not (buffer-modified-p))
3971 (not message-kill-buffer-query)
3972 (yes-or-no-p "Message modified; kill anyway? "))
3973 (let ((actions message-kill-actions)
3974 (draft-article message-draft-article)
3975 (auto-save-file-name buffer-auto-save-file-name)
3976 (file-name buffer-file-name)
3977 (modified (buffer-modified-p)))
3978 (setq buffer-file-name nil)
3979 (kill-buffer (current-buffer))
3980 (when (and (or (and auto-save-file-name
3981 (file-exists-p auto-save-file-name))
3983 (file-exists-p file-name)))
3985 ;; If the message buffer has lived in a dedicated window,
3986 ;; `kill-buffer' has killed the frame. Thus the
3987 ;; `yes-or-no-p' may show up in a lowered frame. Make sure
3988 ;; that the user can see the question by raising the
3991 (yes-or-no-p (format "Remove the backup file%s? "
3992 (if modified " too" "")))))
3994 (delete-file auto-save-file-name))
3995 (let ((message-draft-article draft-article))
3996 (message-disassociate-draft)))
3997 (message-do-actions actions))))
3999 (defun message-bury (buffer)
4000 "Bury this mail BUFFER."
4001 (let ((newbuf (other-buffer buffer)))
4002 (bury-buffer buffer)
4003 (if (and (window-dedicated-p (selected-window))
4004 (not (null (delq (selected-frame) (visible-frame-list)))))
4005 (delete-frame (selected-frame))
4006 (switch-to-buffer newbuf))))
4008 (defun message-send (&optional arg)
4009 "Send the message in the current buffer.
4010 If `message-interactive' is non-nil, wait for success indication or
4011 error messages, and inform user.
4012 Otherwise any failure is reported in a message back to the user from
4014 The usage of ARG is defined by the instance that called Message.
4015 It should typically alter the sending method in some way or other."
4017 ;; Make it possible to undo the coming changes.
4019 (let ((inhibit-read-only t))
4020 (put-text-property (point-min) (point-max) 'read-only nil))
4021 (message-fix-before-sending)
4022 (run-hooks 'message-send-hook)
4023 (when message-confirm-send
4024 (or (y-or-n-p "Send message? ")
4026 (message message-sending-message)
4027 (let ((alist message-send-method-alist)
4029 elem sent dont-barf-on-no-method
4030 (message-options message-options))
4031 (message-options-set-recipient)
4033 (setq elem (pop alist)))
4034 (when (funcall (cadr elem))
4035 (when (and (or (not (memq (car elem)
4036 message-sent-message-via))
4037 (message-fetch-field "supersedes")
4038 (if (or (message-gnksa-enable-p 'multiple-copies)
4039 (not (eq (car elem) 'news)))
4042 "Already sent message via %s; resend? "
4044 (error "Denied posting -- multiple copies")))
4045 (setq success (funcall (caddr elem) arg)))
4049 (let ((fcc (message-fetch-field "Fcc"))
4050 (gcc (message-fetch-field "Gcc")))
4052 (or (eq message-allow-no-recipients 'always)
4053 (and (not (eq message-allow-no-recipients 'never))
4054 (setq dont-barf-on-no-method
4056 (format "No receiver, perform %s anyway? "
4057 (cond ((and fcc gcc) "Fcc and Gcc")
4060 (error "No methods specified to send by"))
4061 (when (or dont-barf-on-no-method
4065 (run-hooks 'message-sent-hook))
4066 (message "Sending...done")
4067 ;; Do ecomplete address snarfing.
4068 (when (and (message-mail-alias-type-p 'ecomplete)
4069 (not message-inhibit-ecomplete))
4070 (message-put-addresses-in-ecomplete))
4071 ;; Mark the buffer as unmodified and delete auto-save.
4072 (set-buffer-modified-p nil)
4073 (delete-auto-save-file-if-necessary t)
4074 (message-disassociate-draft)
4075 ;; Delete other mail buffers and stuff.
4076 (message-do-send-housekeeping)
4077 (message-do-actions message-send-actions)
4081 (defun message-send-via-mail (arg)
4082 "Send the current message via mail."
4083 (message-send-mail arg))
4085 (defun message-send-via-news (arg)
4086 "Send the current message via news."
4087 (funcall message-send-news-function arg))
4089 (defmacro message-check (type &rest forms)
4090 "Eval FORMS if TYPE is to be checked."
4091 `(or (message-check-element ,type)
4095 (put 'message-check 'lisp-indent-function 1)
4096 (put 'message-check 'edebug-form-spec '(form body))
4098 (defun message-text-with-property (prop &optional start end reverse)
4099 "Return a list of start and end positions where the text has PROP.
4100 START and END bound the search, they default to `point-min' and
4101 `point-max' respectively. If REVERSE is non-nil, find text which does
4104 (setq start (point-min)))
4106 (setq end (point-max)))
4110 (setq start (text-property-any start end prop nil)))
4111 (setq next (next-single-property-change start prop nil end))
4112 (push (cons start (or next end)) regions)
4115 (or (get-text-property start prop)
4116 (and (setq start (next-single-property-change
4117 start prop nil end))
4118 (get-text-property start prop))))
4119 (setq next (text-property-any start end prop nil))
4120 (push (cons start (or next end)) regions)
4122 (nreverse regions)))
4124 (defcustom message-bogus-addresses
4125 ;; '("noreply" "nospam" "invalid")
4126 '("noreply" "nospam" "invalid" "@@" "[^[:ascii:]].*@" "[ \t]")
4127 "List of regexps of potentially bogus mail addresses.
4128 See `message-check-recipients' how to setup checking.
4130 This list should make it possible to catch typos or warn about
4131 spam-trap addresses. It doesn't aim to verify strict RFC
4133 :version "23.1" ;; No Gnus
4134 :group 'message-headers
4136 (const :tag "None" nil)
4142 (const :tag "duplicate @" "@@")
4143 (const :tag "non-ascii local part" "[^[:ascii:]].*@")
4144 ;; Already caught by `message-valid-fqdn-regexp'
4145 ;; (const :tag "`_' in domain part" "@.*_")
4146 (const :tag "whitespace" "[ \t]"))
4151 (defun message-fix-before-sending ()
4152 "Do various things to make the message nice before sending it."
4153 ;; Make sure there's a newline at the end of the message.
4154 (goto-char (point-max))
4157 ;; Make the hidden headers visible.
4159 ;; Sort headers before sending the message.
4160 (message-sort-headers)
4161 ;; Make invisible text visible.
4162 ;; It doesn't seem as if this is useful, since the invisible property
4163 ;; is clobbered by an after-change hook anyhow.
4164 (message-check 'invisible-text
4165 (let ((regions (message-text-with-property 'invisible))
4169 (setq from (caar regions)
4171 regions (cdr regions))
4172 (put-text-property from to 'invisible nil)
4173 (message-overlay-put (message-make-overlay from to)
4175 (unless (yes-or-no-p
4176 "Invisible text found and made visible; continue sending? ")
4177 (error "Invisible text found and made visible")))))
4178 (message-check 'illegible-text
4179 (let (char found choice)
4182 (skip-chars-forward mm-7bit-chars)
4183 (when (get-text-property (point) 'no-illegible-text)
4184 ;; There is a signed or encrypted raw message part
4185 ;; that is considered to be safe.
4186 (goto-char (or (next-single-property-change
4187 (point) 'no-illegible-text)
4189 (setq char (char-after)))
4190 (when (or (< (mm-char-int char) 128)
4191 (and (mm-multibyte-p)
4192 (memq (char-charset char)
4193 '(eight-bit-control eight-bit-graphic
4194 ;; Emacs 23, Bug#1770:
4197 (not (get-text-property
4198 (point) 'untranslated-utf-8))))
4199 (message-overlay-put (message-make-overlay (point) (1+ (point)))
4205 (gnus-multiple-choice
4206 "Non-printable characters found. Continue sending?"
4207 `((?d "Remove non-printable characters and send")
4209 "Replace non-printable characters with \"%s\" and send"
4210 message-replacement-char))
4211 (?i "Ignore non-printable characters and send")
4212 (?e "Continue editing"))))
4214 (error "Non-printable characters"))
4216 (skip-chars-forward mm-7bit-chars)
4218 (when (let ((char (char-after)))
4219 (or (< (mm-char-int char) 128)
4220 (and (mm-multibyte-p)
4221 ;; FIXME: Wrong for Emacs 23 (unicode) and for
4222 ;; things like undecodable utf-8 (in Emacs 21?).
4223 ;; Should at least use find-coding-systems-region.
4225 (memq (char-charset char)
4226 '(eight-bit-control eight-bit-graphic
4227 ;; Emacs 23, Bug#1770:
4230 (not (get-text-property
4231 (point) 'untranslated-utf-8)))))
4233 (message-kill-all-overlays)
4235 (when (eq choice ?r)
4236 (insert message-replacement-char))))
4238 (skip-chars-forward mm-7bit-chars)))))
4239 (message-check 'bogus-recipient
4240 ;; Warn before sending a mail to an invalid address.
4241 (message-check-recipients)))
4243 (defun message-bogus-recipient-p (recipients)
4244 "Check if a mail address in RECIPIENTS looks bogus.
4246 RECIPIENTS is a mail header. Return a list of potentially bogus
4247 addresses. If none is found, return nil.
4249 An address might be bogus if the domain part is not fully
4250 qualified, see `message-valid-fqdn-regexp', or if there's a
4251 matching entry in `message-bogus-addresses'."
4252 ;; FIXME: How about "foo@subdomain", when the MTA adds ".domain.tld"?
4254 (mapc (lambda (address)
4255 (setq address (cadr address))
4259 (not (string-match "@" address))
4262 message-valid-fqdn-regexp "\\)\\'") address)))
4263 (and message-bogus-addresses
4265 (if (listp message-bogus-addresses)
4266 (mapconcat 'identity
4267 message-bogus-addresses
4269 message-bogus-addresses)))
4270 (string-match re address))))
4271 (push address found)))
4273 (mail-extract-address-components recipients t))
4276 (defun message-check-recipients ()
4277 "Warn before composing or sending a mail to an invalid address.
4279 This function could be useful in `message-setup-hook'."
4282 (message-narrow-to-headers)
4283 (dolist (hdr '("To" "Cc" "Bcc"))
4284 (let ((addr (message-fetch-field hdr)))
4285 (when (stringp addr)
4286 (dolist (bog (message-bogus-recipient-p addr))
4290 "Address `%s' might be bogus. Continue? " bog)))
4291 (error "Bogus address"))))))))
4293 (custom-add-option 'message-setup-hook 'message-check-recipients)
4295 (defun message-add-action (action &rest types)
4296 "Add ACTION to be performed when doing an exit of type TYPES."
4298 (add-to-list (intern (format "message-%s-actions" (pop types)))
4301 (defun message-delete-action (action &rest types)
4302 "Delete ACTION from lists of actions performed when doing an exit of type TYPES."
4305 (set (setq var (intern (format "message-%s-actions" (pop types))))
4306 (delq action (symbol-value var))))))
4308 (defun message-do-actions (actions)
4309 "Perform all actions in ACTIONS."
4310 ;; Now perform actions on successful sending.
4311 (dolist (action actions)
4314 ;; A simple function.
4317 ;; Something to be evaled.
4321 (defun message-send-mail-partially ()
4322 "Send mail as message/partial."
4323 ;; replace the header delimiter with a blank line
4324 (goto-char (point-min))
4326 (concat "^" (regexp-quote mail-header-separator) "\n"))
4327 (replace-match "\n")
4328 (run-hooks 'message-send-mail-hook)
4329 (let ((p (goto-char (point-min)))
4330 (tembuf (message-generate-new-buffer-clone-locals " message temp"))
4331 (curbuf (current-buffer))
4332 (id (message-make-message-id)) (n 1)
4333 plist total header required-mail-headers)
4335 (if (< (point-max) (+ p message-send-mail-partially-limit))
4336 (goto-char (point-max))
4337 (goto-char (+ p message-send-mail-partially-limit))
4339 (if (<= (point) p) (forward-line 1))) ;; In case of bad message.
4342 (setq total (length plist))
4343 (push (point-max) plist)
4344 (setq plist (nreverse plist))
4347 (setq p (pop plist))
4350 (copy-to-buffer tembuf p (car plist))
4352 (goto-char (point-min))
4355 (goto-char (point-min))
4356 (narrow-to-region (point) (point))
4359 (setq header (buffer-substring (point-min) (point)))
4360 (goto-char (point-min))
4361 (narrow-to-region (point) (point))
4363 (message-remove-header "Mime-Version")
4364 (message-remove-header "Content-Type")
4365 (message-remove-header "Content-Transfer-Encoding")
4366 (message-remove-header "Message-ID")
4367 (message-remove-header "Lines")
4368 (goto-char (point-max))
4369 (insert "Mime-Version: 1.0\n")
4370 (setq header (buffer-string)))
4371 (goto-char (point-max))
4372 (insert (format "Content-Type: message/partial; id=\"%s\"; number=%d; total=%d\n\n"
4375 (let ((mail-header-separator ""))
4376 (when (memq 'Message-ID message-required-mail-headers)
4377 (insert "Message-ID: " (message-make-message-id) "\n"))
4378 (when (memq 'Lines message-required-mail-headers)
4379 (insert "Lines: " (message-make-lines) "\n"))
4380 (message-goto-subject)
4382 (insert (format " (%d/%d)" n total))
4384 (funcall (or message-send-mail-real-function
4385 message-send-mail-function)))
4387 (setq p (pop plist))
4389 (kill-buffer tembuf))))
4391 (declare-function hashcash-wait-async "hashcash" (&optional buffer))
4393 (defun message-send-mail (&optional arg)
4394 (require 'mail-utils)
4395 (let* ((tembuf (message-generate-new-buffer-clone-locals " message temp"))
4396 (case-fold-search nil)
4397 (news (message-news-p))
4398 (mailbuf (current-buffer))
4399 (message-this-is-mail t)
4400 ;; gnus-setup-posting-charset is autoloaded in mml.el (FIXME
4401 ;; maybe it should not be), which this file requires. Hence
4402 ;; the fboundp test is always true. Loading it from gnus-msg
4403 ;; loads many Gnus files (Bug#5642). If
4404 ;; gnus-group-posting-charset-alist hasn't been customized,
4405 ;; this is just going to return nil anyway. FIXME it would
4406 ;; be good to improve this further, because even if g-g-p-c-a
4407 ;; has been customized, that is likely to just be for news.
4408 ;; Eg either move the definition from gnus-msg, or separate out
4409 ;; the mail and news parts.
4410 (message-posting-charset
4411 (if (and (fboundp 'gnus-setup-posting-charset)
4412 (boundp 'gnus-group-posting-charset-alist))
4413 (gnus-setup-posting-charset nil)
4414 message-posting-charset))
4415 (headers message-required-mail-headers))
4416 (when (and message-generate-hashcash
4417 (not (eq message-generate-hashcash 'opportunistic)))
4418 (message "Generating hashcash...")
4420 ;; Wait for calculations already started to finish...
4421 (hashcash-wait-async)
4422 ;; ...and do calculations not already done. mail-add-payment
4423 ;; will leave existing X-Hashcash headers alone.
4425 (message "Generating hashcash...done"))
4427 (message-narrow-to-headers)
4428 ;; Generate the Mail-Followup-To header if the header is not there...
4429 (if (and (message-subscribed-p)
4430 (not (mail-fetch-field "mail-followup-to")))
4433 (cons "Mail-Followup-To" (message-make-mail-followup-to))
4434 message-required-mail-headers))
4435 ;; otherwise, delete the MFT header if the field is empty
4436 (when (equal "" (mail-fetch-field "mail-followup-to"))
4437 (message-remove-header "^Mail-Followup-To:")))
4438 ;; Insert some headers.
4439 (let ((message-deletable-headers
4440 (if news nil message-deletable-headers)))
4441 (message-generate-headers headers))
4442 ;; Check continuation headers.
4443 (message-check 'continuation-headers
4444 (goto-char (point-min))
4445 (while (re-search-forward "^[^ \t\n][^ \t\n:]*[ \t\n]" nil t)
4446 (goto-char (match-beginning 0))
4447 (if (y-or-n-p "Fix continuation lines? ")
4450 (unless (y-or-n-p "Send anyway? ")
4451 (error "Failed to send the message")))))
4452 ;; Let the user do all of the above.
4453 (run-hooks 'message-header-hook))
4455 (with-current-buffer tembuf
4457 ;; Avoid copying text props (except hard newlines).
4458 (insert (with-current-buffer mailbuf
4459 (mml-buffer-substring-no-properties-except-hard-newlines
4460 (point-min) (point-max))))
4461 ;; Remove some headers.
4462 (message-encode-message-body)
4464 (message-narrow-to-headers)
4465 ;; We (re)generate the Lines header.
4466 (when (memq 'Lines message-required-mail-headers)
4467 (message-generate-headers '(Lines)))
4468 ;; Remove some headers.
4469 (message-remove-header message-ignored-mail-headers t)
4470 (let ((mail-parse-charset message-default-charset))
4471 (mail-encode-encoded-word-buffer)))
4472 (goto-char (point-max))
4473 ;; require one newline at the end.
4474 (or (= (preceding-char) ?\n)
4476 (message-cleanup-headers)
4477 ;; FIXME: we're inserting the courtesy copy after encoding.
4478 ;; This is wrong if the courtesy copy string contains
4479 ;; non-ASCII characters. -- jh
4482 (message-narrow-to-headers)
4484 (or (message-fetch-field "cc")
4485 (message-fetch-field "bcc")
4486 (message-fetch-field "to"))
4487 (let ((content-type (message-fetch-field
4492 (string= "text/plain"
4494 (mail-header-parse-content-type
4498 (message-fetch-field
4499 "content-transfer-encoding")))))))
4500 (message-insert-courtesy-copy))
4501 ;; Let's make sure we encoded all the body.
4502 (assert (save-excursion
4503 (goto-char (point-min))
4504 (not (re-search-forward "[^\000-\377]" nil t))))
4505 (mm-disable-multibyte)
4506 (if (or (not message-send-mail-partially-limit)
4507 (< (buffer-size) message-send-mail-partially-limit)
4508 (not (message-y-or-n-p
4509 "The message size is too large, split? "
4513 (/ (buffer-size) 1000) "KB, is too large.
4515 Some mail gateways (MTA's) bounce large messages. To avoid the
4516 problem, answer `y', and the message will be split into several
4517 smaller pieces, the size of each is about "
4518 (/ message-send-mail-partially-limit 1000)
4522 However, some mail readers (MUA's) can't read split messages, i.e.,
4523 mails in message/partially format. Answer `n', and the message will be
4526 The size limit is controlled by `message-send-mail-partially-limit'.
4527 If you always want Gnus to send messages in one piece, set
4528 `message-send-mail-partially-limit' to nil.
4531 (message "Sending via mail...")
4532 (funcall (or message-send-mail-real-function
4533 message-send-mail-function)))
4534 (message-send-mail-partially)))
4535 (kill-buffer tembuf))
4536 (set-buffer mailbuf)
4537 (push 'mail message-sent-message-via)))
4539 (defun message-send-mail-with-sendmail ()
4540 "Send off the prepared buffer with sendmail."
4542 (let ((errbuf (if message-interactive
4543 (message-generate-new-buffer-clone-locals
4546 resend-to-addresses delimline)
4549 (let ((case-fold-search t))
4551 (message-narrow-to-headers)
4552 (setq resend-to-addresses (message-fetch-field "resent-to")))
4553 ;; Change header-delimiter to be what sendmail expects.
4554 (goto-char (point-min))
4556 (concat "^" (regexp-quote mail-header-separator) "\n"))
4557 (replace-match "\n")
4559 (setq delimline (point-marker))
4560 (run-hooks 'message-send-mail-hook)
4561 ;; Insert an extra newline if we need it to work around
4562 ;; Sun's bug that swallows newlines.
4563 (goto-char (1+ delimline))
4564 (when (eval message-mailer-swallows-blank-line)
4566 (when message-interactive
4567 (with-current-buffer errbuf
4569 (let* ((default-directory "/")
4570 (coding-system-for-write message-send-coding-system)
4572 'call-process-region
4574 (list (point-min) (point-max)
4575 (cond ((boundp 'sendmail-program)
4577 ((file-exists-p "/usr/sbin/sendmail")
4578 "/usr/sbin/sendmail")
4579 ((file-exists-p "/usr/lib/sendmail")
4580 "/usr/lib/sendmail")
4581 ((file-exists-p "/usr/ucblib/sendmail")
4582 "/usr/ucblib/sendmail")
4584 nil errbuf nil "-oi")
4585 message-sendmail-extra-arguments
4586 ;; Always specify who from,
4587 ;; since some systems have broken sendmails.
4588 ;; But some systems are more broken with -f, so
4589 ;; we'll let users override this.
4590 (and (null message-sendmail-f-is-evil)
4591 (list "-f" (message-sendmail-envelope-from)))
4592 ;; These mean "report errors by mail"
4593 ;; and "deliver in background".
4594 (if (null message-interactive) '("-oem" "-odb"))
4595 ;; Get the addresses from the message
4596 ;; unless this is a resend.
4597 ;; We must not do that for a resend
4598 ;; because we would find the original addresses.
4599 ;; For a resend, include the specific addresses.
4600 (if resend-to-addresses
4601 (list resend-to-addresses)
4603 (unless (or (null cpr) (and (numberp cpr) (zerop cpr)))
4604 (if errbuf (pop-to-buffer errbuf))
4605 (error "Sending...failed with exit value %d" cpr)))
4606 (when message-interactive
4607 (with-current-buffer errbuf
4608 (goto-char (point-min))
4609 (while (re-search-forward "\n+ *" nil t)
4610 (replace-match "; "))
4611 (if (not (zerop (buffer-size)))
4612 (error "Sending...failed to %s"
4613 (buffer-string))))))
4614 (when (bufferp errbuf)
4615 (kill-buffer errbuf)))))
4617 (defun message-send-mail-with-qmail ()
4618 "Pass the prepared message buffer to qmail-inject.
4619 Refer to the documentation for the variable `message-send-mail-function'
4620 to find out how to use this."
4621 ;; replace the header delimiter with a blank line
4622 (goto-char (point-min))
4624 (concat "^" (regexp-quote mail-header-separator) "\n"))
4625 (replace-match "\n")
4626 (run-hooks 'message-send-mail-hook)
4629 (let ((coding-system-for-write message-send-coding-system))
4631 'call-process-region (point-min) (point-max)
4632 message-qmail-inject-program nil nil nil
4633 ;; qmail-inject's default behavior is to look for addresses on the
4634 ;; command line; if there're none, it scans the headers.
4635 ;; yes, it does The Right Thing w.r.t. Resent-To and it's kin.
4637 ;; in general, ALL of qmail-inject's defaults are perfect for simply
4638 ;; reading a formatted (i. e., at least a To: or Resent-To header)
4639 ;; message from stdin.
4641 ;; qmail also has the advantage of not having been raped by
4642 ;; various vendors, so we don't have to allow for that, either --
4643 ;; compare this with message-send-mail-with-sendmail and weep
4644 ;; for sendmail's lost innocence.
4646 ;; all this is way cool coz it lets us keep the arguments entirely
4647 ;; free for -inject-arguments -- a big win for the user and for us
4648 ;; since we don't have to play that double-guessing game and the user
4649 ;; gets full control (no gestapo'ish -f's, for instance). --sj
4650 (if (functionp message-qmail-inject-args)
4651 (funcall message-qmail-inject-args)
4652 message-qmail-inject-args)))
4653 ;; qmail-inject doesn't say anything on it's stdout/stderr,
4654 ;; we have to look at the retval instead
4656 (100 (error "qmail-inject reported permanent failure"))
4657 (111 (error "qmail-inject reported transient failure"))
4658 ;; should never happen
4659 (t (error "qmail-inject reported unknown failure"))))
4661 (defun message-send-mail-with-mh ()
4662 "Send the prepared message buffer with mh."
4663 (let ((mh-previous-window-config nil)
4664 (name (mh-new-draft-name)))
4665 (setq buffer-file-name name)
4666 ;; MH wants to generate these headers itself.
4667 (when message-mh-deletable-headers
4668 (let ((headers message-mh-deletable-headers))
4670 (goto-char (point-min))
4671 (and (re-search-forward
4672 (concat "^" (symbol-name (car headers)) ": *") nil t)
4673 (message-delete-line))
4675 (run-hooks 'message-send-mail-hook)
4676 ;; Pass it on to mh.
4679 (defun message-smtpmail-send-it ()
4680 "Send the prepared message buffer with `smtpmail-send-it'.
4681 The only difference from `smtpmail-send-it' is that this command
4682 evaluates `message-send-mail-hook' just before sending a message.
4683 It is useful if your ISP requires the POP-before-SMTP
4684 authentication. See the Gnus manual for details."
4685 (run-hooks 'message-send-mail-hook)
4688 (defun message-send-mail-with-mailclient ()
4689 "Send the prepared message buffer with `mailclient-send-it'.
4690 The only difference from `mailclient-send-it' is that this
4691 command evaluates `message-send-mail-hook' just before sending a message."
4692 (run-hooks 'message-send-mail-hook)
4693 (mailclient-send-it))
4695 (defun message-canlock-generate ()
4696 "Return a string that is non-trivial to guess.
4697 Do not use this for anything important, it is cryptographically weak."
4699 (let (sha1-maximum-internal-length)
4700 (sha1 (concat (message-unique-id)
4701 (format "%x%x%x" (random) (random t) (random))
4702 (prin1-to-string (recent-keys))
4703 (prin1-to-string (garbage-collect))))))
4705 (defvar canlock-password)
4706 (defvar canlock-password-for-verify)
4708 (defun message-canlock-password ()
4709 "The password used by message for cancel locks.
4710 This is the value of `canlock-password', if that option is non-nil.
4711 Otherwise, generate and save a value for `canlock-password' first."
4713 (unless canlock-password
4714 (customize-save-variable 'canlock-password (message-canlock-generate))
4715 (setq canlock-password-for-verify canlock-password))
4718 (defun message-insert-canlock ()
4719 (when message-insert-canlock
4720 (message-canlock-password)
4721 (canlock-insert-header)))
4723 (autoload 'nnheader-get-report "nnheader")
4725 (declare-function gnus-setup-posting-charset "gnus-msg" (group))
4727 (defun message-send-news (&optional arg)
4729 (let* ((tembuf (message-generate-new-buffer-clone-locals " *message temp*"))
4730 (case-fold-search nil)
4731 (method (if (functionp message-post-method)
4732 (funcall message-post-method arg)
4733 message-post-method))
4734 (newsgroups-field (save-restriction
4735 (message-narrow-to-headers-or-head)
4736 (message-fetch-field "Newsgroups")))
4737 (followup-field (save-restriction
4738 (message-narrow-to-headers-or-head)
4739 (message-fetch-field "Followup-To")))
4740 ;; BUG: We really need to get the charset for each name in the
4741 ;; Newsgroups and Followup-To lines to allow crossposting
4742 ;; between group namess with incompatible character sets.
4743 ;; -- Per Abrahamsen <abraham@dina.kvl.dk> 2001-10-08.
4744 (group-field-charset
4745 (gnus-group-name-charset method newsgroups-field))
4746 (followup-field-charset
4747 (gnus-group-name-charset method (or followup-field "")))
4748 (rfc2047-header-encoding-alist
4749 (append (when group-field-charset
4750 (list (cons "Newsgroups" group-field-charset)))
4751 (when followup-field-charset
4752 (list (cons "Followup-To" followup-field-charset)))
4753 rfc2047-header-encoding-alist))
4754 (messbuf (current-buffer))
4755 (message-syntax-checks
4757 (listp message-syntax-checks))
4758 (cons '(existing-newsgroups . disabled)
4759 message-syntax-checks)
4760 message-syntax-checks))
4761 (message-this-is-news t)
4762 (message-posting-charset
4763 (gnus-setup-posting-charset newsgroups-field))
4765 (if (not (message-check-news-body-syntax))
4768 (message-narrow-to-headers)
4769 ;; Insert some headers.
4770 (message-generate-headers message-required-news-headers)
4771 (message-insert-canlock)
4772 ;; Let the user do all of the above.
4773 (run-hooks 'message-header-hook))
4774 ;; Note: This check will be disabled by the ".*" default value for
4775 ;; gnus-group-name-charset-group-alist. -- Pa 2001-10-07.
4776 (when (and group-field-charset
4777 (listp message-syntax-checks))
4778 (setq message-syntax-checks
4779 (cons '(valid-newsgroups . disabled)
4780 message-syntax-checks)))
4781 (message-cleanup-headers)
4782 (if (not (let ((message-post-method method))
4783 (message-check-news-syntax)))
4786 (with-current-buffer tembuf
4787 (buffer-disable-undo)
4789 ;; Avoid copying text props (except hard newlines).
4791 (with-current-buffer messbuf
4792 (mml-buffer-substring-no-properties-except-hard-newlines
4793 (point-min) (point-max))))
4794 (message-encode-message-body)
4795 ;; Remove some headers.
4797 (message-narrow-to-headers)
4798 ;; We (re)generate the Lines header.
4799 (when (memq 'Lines message-required-mail-headers)
4800 (message-generate-headers '(Lines)))
4801 ;; Remove some headers.
4802 (message-remove-header message-ignored-news-headers t)
4803 (let ((mail-parse-charset message-default-charset))
4804 (mail-encode-encoded-word-buffer)))
4805 (goto-char (point-max))
4806 ;; require one newline at the end.
4807 (or (= (preceding-char) ?\n)
4809 (let ((case-fold-search t))
4810 ;; Remove the delimiter.
4811 (goto-char (point-min))
4813 (concat "^" (regexp-quote mail-header-separator) "\n"))
4814 (replace-match "\n")
4816 (run-hooks 'message-send-news-hook)
4817 (gnus-open-server method)
4818 (message "Sending news via %s..." (gnus-server-string method))
4819 (setq result (let ((mail-header-separator ""))
4820 (gnus-request-post method))))
4821 (kill-buffer tembuf))
4822 (set-buffer messbuf)
4824 (push 'news message-sent-message-via)
4825 (message "Couldn't send message via news: %s"
4826 (nnheader-get-report (car method)))
4830 ;;; Header generation & syntax checking.
4833 (defun message-check-element (type)
4834 "Return non-nil if this TYPE is not to be checked."
4835 (if (eq message-syntax-checks 'dont-check-for-anything-just-trust-me)
4837 (let ((able (assq type message-syntax-checks)))
4839 (eq (cdr able) 'disabled)))))
4841 (defun message-check-news-syntax ()
4842 "Check the syntax of the message."
4846 ;; We narrow to the headers and check them first.
4849 (message-narrow-to-headers)
4850 (message-check-news-header-syntax))))))
4852 (defun message-check-news-header-syntax ()
4854 ;; Check Newsgroups header.
4855 (message-check 'newsgroups
4856 (let ((group (message-fetch-field "newsgroups")))
4859 (not (string-match "\\`[ \t]*\\'" group)))
4862 "The newsgroups field is empty or missing. Posting is denied.")))))
4863 ;; Check the Subject header.
4864 (message-check 'subject
4865 (let* ((case-fold-search t)
4866 (subject (message-fetch-field "subject")))
4869 (not (string-match "\\`[ \t]*\\'" subject)))
4872 "The subject field is empty or missing. Posting is denied.")))))
4873 ;; Check for commands in Subject.
4874 (message-check 'subject-cmsg
4875 (if (string-match "^cmsg " (message-fetch-field "subject"))
4877 "The control code \"cmsg\" is in the subject. Really post? ")
4879 ;; Check long header lines.
4880 (message-check 'long-header-lines
4881 (let ((start (point))
4885 (while (and (not found)
4886 (re-search-forward "^\\([^ \t:]+\\): " nil t))
4887 (if (> (- (point) (match-beginning 0)) 998)
4889 length (- (point) (match-beginning 0)))
4890 (setq header (match-string-no-properties 1)))
4891 (setq start (match-beginning 0))
4894 (y-or-n-p (format "Your %s header is too long (%d). Really post? "
4897 ;; Check for multiple identical headers.
4898 (message-check 'multiple-headers
4900 (while (and (not found)
4901 (re-search-forward "^[^ \t:]+: " nil t))
4903 (or (re-search-forward
4908 (match-beginning 0) (- (match-end 0) 2))))
4913 (y-or-n-p (format "Multiple %s headers. Really post? " found))
4915 ;; Check for Version and Sendsys.
4916 (message-check 'sendsys
4917 (if (re-search-forward "^Sendsys:\\|^Version:" nil t)
4919 (format "The article contains a %s command. Really post? "
4920 (buffer-substring (match-beginning 0)
4921 (1- (match-end 0)))))
4923 ;; See whether we can shorten Followup-To.
4924 (message-check 'shorten-followup-to
4925 (let ((newsgroups (message-fetch-field "newsgroups"))
4926 (followup-to (message-fetch-field "followup-to"))
4928 (when (and newsgroups
4929 (string-match "," newsgroups)
4934 (setq to (completing-read
4935 "Followups to (default no Followup-To header): "
4938 (message-tokenize-header
4940 (goto-char (point-min))
4941 (insert "Followup-To: " to "\n"))
4943 ;; Check "Shoot me".
4944 (message-check 'shoot
4945 (if (re-search-forward
4946 "Message-ID.*.i-did-not-set--mail-host-address--so-tickle-me" nil t)
4947 (y-or-n-p "You appear to have a misconfigured system. Really post? ")
4949 ;; Check for Approved.
4950 (message-check 'approved
4951 (if (re-search-forward "^Approved:" nil t)
4952 (y-or-n-p "The article contains an Approved header. Really post? ")
4954 ;; Check the Message-ID header.
4955 (message-check 'message-id
4956 (let* ((case-fold-search t)
4957 (message-id (message-fetch-field "message-id" t)))
4958 (or (not message-id)
4959 ;; Is there an @ in the ID?
4960 (and (string-match "@" message-id)
4961 ;; Is there a dot in the ID?
4962 (string-match "@[^.]*\\." message-id)
4963 ;; Does the ID end with a dot?
4964 (not (string-match "\\.>" message-id)))
4966 (format "The Message-ID looks strange: \"%s\". Really post? "
4968 ;; Check the Newsgroups & Followup-To headers.
4969 (message-check 'existing-newsgroups
4970 (let* ((case-fold-search t)
4971 (newsgroups (message-fetch-field "newsgroups"))
4972 (followup-to (message-fetch-field "followup-to"))
4973 (groups (message-tokenize-header
4975 (concat newsgroups "," followup-to)
4977 (post-method (if (functionp message-post-method)
4978 (funcall message-post-method)
4979 message-post-method))
4980 ;; KLUDGE to handle nnvirtual groups. Doing this right
4981 ;; would probably involve a new nnoo function.
4982 ;; -- Per Abrahamsen <abraham@dina.kvl.dk>, 2001-10-17.
4983 (method (if (and (consp post-method)
4984 (eq (car post-method) 'nnvirtual)
4985 gnus-message-group-art)
4986 (let ((group (car (nnvirtual-find-group-art
4987 (car gnus-message-group-art)
4988 (cdr gnus-message-group-art)))))
4989 (gnus-find-method-for-group group))
4993 (gnus-group-name-decode
4994 (gnus-group-real-name n)
4995 (gnus-group-name-charset method n)))
4996 (gnus-groups-from-server method)))
4999 (when (and (not (equal (car groups) "poster"))
5000 (not (member (car groups) known-groups))
5001 (not (member (car groups) errors)))
5002 (push (car groups) errors))
5005 ;; Gnus is not running.
5006 ((or (not (and (boundp 'gnus-active-hashtb)
5007 gnus-active-hashtb))
5008 (not (boundp 'gnus-read-active-file)))
5010 ;; We don't have all the group names.
5011 ((and (or (not gnus-read-active-file)
5012 (eq gnus-read-active-file 'some))
5016 "Really use %s possibly unknown group%s: %s? "
5017 (if (= (length errors) 1) "this" "these")
5018 (if (= (length errors) 1) "" "s")
5019 (mapconcat 'identity errors ", "))))
5020 ;; There were no errors.
5023 ;; There are unknown groups.
5027 "Really post to %s unknown group%s: %s? "
5028 (if (= (length errors) 1) "this" "these")
5029 (if (= (length errors) 1) "" "s")
5030 (mapconcat 'identity errors ", ")))))))
5031 ;; Check continuation headers.
5032 (message-check 'continuation-headers
5033 (goto-char (point-min))
5034 (let ((do-posting t))
5035 (while (re-search-forward "^[^ \t\n][^ \t\n:]*[ \t\n]" nil t)
5036 (goto-char (match-beginning 0))
5037 (if (y-or-n-p "Fix continuation lines? ")
5040 (unless (y-or-n-p "Send anyway? ")
5041 (setq do-posting nil))))
5043 ;; Check the Newsgroups & Followup-To headers for syntax errors.
5044 (message-check 'valid-newsgroups
5045 (let ((case-fold-search t)
5046 (headers '("Newsgroups" "Followup-To"))
5048 (while (and headers (not error))
5049 (when (setq header (mail-fetch-field (car headers)))
5053 "\\`\\([-+_&.a-zA-Z0-9]+\\)?\\(,[-+_&.a-zA-Z0-9]+\\)*\\'"
5058 (not (string-match "\\.\\'\\|\\.\\." g)))
5059 (message-tokenize-header header ","))))
5066 (format "The %s header looks odd: \"%s\". Really post? "
5067 (car headers) header)))))
5068 (message-check 'repeated-newsgroups
5069 (let ((case-fold-search t)
5070 (headers '("Newsgroups" "Followup-To"))
5071 header error groups group)
5074 (when (setq header (mail-fetch-field (pop headers)))
5075 (setq groups (message-tokenize-header header ","))
5076 (while (setq group (pop groups))
5077 (when (member group groups)
5083 (format "Group %s is repeated in headers. Really post? " error)))))
5084 ;; Check the From header.
5085 (message-check 'from
5086 (let* ((case-fold-search t)
5087 (from (message-fetch-field "from"))
5091 (message "There is no From line. Posting is denied.")
5093 ((or (not (string-match
5095 (setq ad (nth 1 (mail-extract-address-components
5096 from))))) ;larsi@ifi
5097 (string-match "\\.\\." ad) ;larsi@ifi..uio
5098 (string-match "@\\." ad) ;larsi@.ifi.uio
5099 (string-match "\\.$" ad) ;larsi@ifi.uio.
5100 (not (string-match "^[^@]+@[^@]+$" ad)) ;larsi.ifi.uio
5101 (string-match "(.*).*(.*)" from)) ;(lars) (lars)
5103 "Denied posting -- the From looks strange: \"%s\"." from)
5105 ((let ((addresses (rfc822-addresses from)))
5106 ;; `rfc822-addresses' returns a string if parsing fails.
5107 (while (and (consp addresses)
5108 (not (eq (string-to-char (car addresses)) ?\()))
5109 (setq addresses (cdr addresses)))
5112 "Denied posting -- bad From address: \"%s\"." from)
5115 ;; Check the Reply-To header.
5116 (message-check 'reply-to
5117 (let* ((case-fold-search t)
5118 (reply-to (message-fetch-field "reply-to"))
5123 ((string-match "," reply-to)
5125 (format "Multiple Reply-To addresses: \"%s\". Really post? "
5127 ((or (not (string-match
5129 (setq ad (nth 1 (mail-extract-address-components
5130 reply-to))))) ;larsi@ifi
5131 (string-match "\\.\\." ad) ;larsi@ifi..uio
5132 (string-match "@\\." ad) ;larsi@.ifi.uio
5133 (string-match "\\.$" ad) ;larsi@ifi.uio.
5134 (not (string-match "^[^@]+@[^@]+$" ad)) ;larsi.ifi.uio
5135 (string-match "(.*).*(.*)" reply-to)) ;(lars) (lars)
5138 "The Reply-To looks strange: \"%s\". Really post? "
5142 (defun message-check-news-body-syntax ()
5144 ;; Check for long lines.
5145 (message-check 'long-lines
5146 (goto-char (point-min))
5148 (concat "^" (regexp-quote mail-header-separator) "$"))
5152 "<#\\(/\\)?\\(multipart\\|part\\|external\\|mml\\)")
5155 (< (- (point) p) 80)))
5156 (zerop (forward-line 1))))
5160 "You have lines longer than 79 characters. Really post? ")))
5161 ;; Check whether the article is empty.
5162 (message-check 'empty
5163 (goto-char (point-min))
5165 (concat "^" (regexp-quote mail-header-separator) "$"))
5168 (goto-char (point-max))
5169 (re-search-backward message-signature-separator nil t)
5171 (or (re-search-backward "[^ \n\t]" b t)
5172 (if (message-gnksa-enable-p 'empty-article)
5173 (y-or-n-p "Empty article. Really post? ")
5174 (message "Denied posting -- Empty article.")
5176 ;; Check for control characters.
5177 (message-check 'control-chars
5178 (if (re-search-forward
5179 (mm-string-to-multibyte "[\000-\007\013\015-\032\034-\037\200-\237]")
5182 "The article contains control characters. Really post? ")
5184 ;; Check excessive size.
5185 (message-check 'size
5186 (if (> (buffer-size) 60000)
5188 (format "The article is %d octets long. Really post? "
5191 ;; Check whether any new text has been added.
5192 (message-check 'new-text
5194 (not message-checksum)
5195 (not (eq (message-checksum) message-checksum))
5196 (if (message-gnksa-enable-p 'quoted-text-only)
5198 "It looks like no new text has been added. Really post? ")
5199 (message "Denied posting -- no new text has been added.")
5201 ;; Check the length of the signature.
5202 (message-check 'signature
5203 (let (sig-start sig-end)
5204 (goto-char (point-max))
5205 (if (not (re-search-backward message-signature-separator nil t))
5207 (setq sig-start (1+ (point-at-eol)))
5209 (if (re-search-forward
5210 "<#/?\\(multipart\\|part\\|external\\|mml\\)" nil t)
5211 (- (point-at-bol) 1)
5213 (if (>= (count-lines sig-start sig-end) 5)
5214 (if (message-gnksa-enable-p 'signature)
5216 (format "Signature is excessively long (%d lines). Really post? "
5217 (count-lines sig-start sig-end)))
5218 (message "Denied posting -- Excessive signature.")
5221 ;; Ensure that text follows last quoted portion.
5222 (message-check 'quoting-style
5223 (goto-char (point-max))
5224 (let ((no-problem t))
5225 (when (search-backward-regexp "^>[^\n]*\n" nil t)
5226 (setq no-problem (search-forward-regexp "^[ \t]*[^>\n]" nil t)))
5229 (if (message-gnksa-enable-p 'quoted-text-only)
5230 (y-or-n-p "Your text should follow quoted text. Really post? ")
5232 (goto-char (point-min))
5234 (concat "^" (regexp-quote mail-header-separator) "$"))
5235 (if (search-forward-regexp "^[ \t]*[^>\n]" nil t)
5236 (y-or-n-p "Your text should follow quoted text. Really post? ")
5237 (message "Denied posting -- only quoted text.")
5240 (defun message-checksum ()
5241 "Return a \"checksum\" for the current buffer."
5244 (goto-char (point-min))
5246 (concat "^" (regexp-quote mail-header-separator) "$"))
5248 (when (not (looking-at "[ \t\n]"))
5249 (setq sum (logxor (ash sum 1) (if (natnump sum) 0 1)
5254 (defun message-do-fcc ()
5255 "Process Fcc headers in the current buffer."
5256 (let ((case-fold-search t)
5257 (buf (current-buffer))
5259 (mml-externalize-attachments message-fcc-externalize-attachments))
5262 (message-narrow-to-headers)
5263 (setq file (message-fetch-field "fcc" t)))
5265 (set-buffer (get-buffer-create " *message temp*"))
5267 (insert-buffer-substring buf)
5268 (message-encode-message-body)
5270 (message-narrow-to-headers)
5271 (while (setq file (message-fetch-field "fcc" t))
5273 (message-remove-header "fcc" nil t))
5274 (let ((mail-parse-charset message-default-charset)
5275 (rfc2047-header-encoding-alist
5276 (cons '("Newsgroups" . default)
5277 rfc2047-header-encoding-alist)))
5278 (mail-encode-encoded-word-buffer)))
5279 (goto-char (point-min))
5280 (when (re-search-forward
5281 (concat "^" (regexp-quote mail-header-separator) "$")
5283 (replace-match "" t t ))
5284 ;; Process FCC operations.
5286 (setq file (pop list))
5287 (if (string-match "^[ \t]*|[ \t]*\\(.*\\)[ \t]*$" file)
5288 ;; Pipe the article to the program in question.
5289 (call-process-region (point-min) (point-max) shell-file-name
5290 nil nil nil shell-command-switch
5291 (match-string 1 file))
5292 ;; Save the article.
5293 (setq file (expand-file-name file))
5294 (unless (file-exists-p (file-name-directory file))
5295 (make-directory (file-name-directory file) t))
5296 (if (and message-fcc-handler-function
5297 (not (eq message-fcc-handler-function 'rmail-output)))
5298 (funcall message-fcc-handler-function file)
5299 ;; FIXME this option, rmail-output (also used if
5300 ;; message-fcc-handler-function is nil) is not
5301 ;; documented anywhere AFAICS. It should work in Emacs
5302 ;; 23; I suspect it does not work in Emacs 22.
5303 ;; FIXME I don't see the need for the two different cases here.
5304 ;; mail-use-rfc822 makes no difference (in Emacs 23),and
5305 ;; the third argument just controls \"Wrote file\" message.
5306 (if (and (file-readable-p file) (mail-file-babyl-p file))
5307 (rmail-output file 1 nil t)
5308 (let ((mail-use-rfc822 t))
5309 (rmail-output file 1 t t))))))
5310 (kill-buffer (current-buffer))))))
5312 (defun message-output (filename)
5313 "Append this article to Unix/babyl mail file FILENAME."
5314 (if (and (file-readable-p filename)
5315 (mail-file-babyl-p filename))
5316 (gnus-output-to-rmail filename t)
5317 (gnus-output-to-mail filename t)))
5319 (defun message-cleanup-headers ()
5320 "Do various automatic cleanups of the headers."
5321 ;; Remove empty lines in the header.
5323 (message-narrow-to-headers)
5324 ;; Remove blank lines.
5325 (while (re-search-forward "^[ \t]*\n" nil t)
5326 (replace-match "" t t))
5328 ;; Correct Newsgroups and Followup-To headers: Change sequence of
5329 ;; spaces to comma and eliminate spaces around commas. Eliminate
5330 ;; embedded line breaks.
5331 (goto-char (point-min))
5332 (while (re-search-forward "^\\(Newsgroups\\|Followup-To\\): +" nil t)
5336 (if (re-search-forward "^[^ \t]" nil t)
5340 (goto-char (point-min))
5341 (while (re-search-forward "\n[ \t]+" nil t)
5342 (replace-match " " t t)) ;No line breaks (too confusing)
5343 (goto-char (point-min))
5344 (while (re-search-forward "[ \t\n]*,[ \t\n]*\\|[ \t]+" nil t)
5345 (replace-match "," t t))
5346 (goto-char (point-min))
5347 ;; Remove trailing commas.
5348 (when (re-search-forward ",+$" nil t)
5349 (replace-match "" t t))))))
5351 (defun message-make-date (&optional now)
5352 "Make a valid data header.
5353 If NOW, use that time instead."
5354 (let ((system-time-locale "C"))
5355 (format-time-string "%a, %d %b %Y %T %z" now)))
5357 (defun message-insert-expires (days)
5358 "Insert the Expires header. Expiry in DAYS days."
5359 (interactive "NExpire article in how many days? ")
5361 (message-position-on-field "Expires" "X-Draft-From")
5362 (insert (message-make-expires-date days))))
5364 (defun message-make-expires-date (days)
5365 "Make date string for the Expires header. Expiry in DAYS days.
5367 In posting styles use `(\"Expires\" (make-expires-date 30))'."
5368 (let* ((cur (decode-time (current-time)))
5369 (nday (+ days (nth 3 cur))))
5370 (setf (nth 3 cur) nday)
5371 (message-make-date (apply 'encode-time cur))))
5373 (defun message-make-message-id ()
5374 "Make a unique Message-ID."
5375 (concat "<" (message-unique-id)
5376 (let ((psubject (save-excursion (message-fetch-field "subject")))
5378 (save-excursion (message-fetch-field "supersedes"))))
5380 (and message-reply-headers
5381 (mail-header-references message-reply-headers)
5382 (mail-header-subject message-reply-headers)
5385 (message-strip-subject-re
5386 (mail-header-subject message-reply-headers))
5387 (message-strip-subject-re psubject))))
5389 (string-match "_-_@" psupersedes)))
5391 "@" (message-make-fqdn) ">"))
5393 (defvar message-unique-id-char nil)
5395 ;; If you ever change this function, make sure the new version
5396 ;; cannot generate IDs that the old version could.
5397 ;; You might for example insert a "." somewhere (not next to another dot
5398 ;; or string boundary), or modify the "fsf" string.
5399 (defun message-unique-id ()
5400 ;; Don't use microseconds from (current-time), they may be unsupported.
5401 ;; Instead we use this randomly inited counter.
5402 (setq message-unique-id-char
5403 (% (1+ (or message-unique-id-char (logand (random t) (1- (lsh 1 20)))))
5404 ;; (current-time) returns 16-bit ints,
5405 ;; and 2^16*25 just fits into 4 digits i base 36.
5407 (let ((tm (current-time)))
5409 (if (or (memq system-type '(ms-dos emx))
5410 ;; message-number-base36 doesn't handle bigints.
5411 (floatp (user-uid)))
5412 (let ((user (downcase (user-login-name))))
5413 (while (string-match "[^a-z0-9_]" user)
5414 (aset user (match-beginning 0) ?_))
5416 (message-number-base36 (user-uid) -1))
5417 (message-number-base36 (+ (car tm)
5418 (lsh (% message-unique-id-char 25) 16)) 4)
5419 (message-number-base36 (+ (nth 1 tm)
5420 (lsh (/ message-unique-id-char 25) 16)) 4)
5421 ;; Append a given name, because while the generated ID is unique
5422 ;; to this newsreader, other newsreaders might otherwise generate
5423 ;; the same ID via another algorithm.
5426 (defun message-number-base36 (num len)
5431 (concat (message-number-base36 (/ num 36) (1- len))
5432 (char-to-string (aref "zyxwvutsrqponmlkjihgfedcba9876543210"
5435 (defun message-make-organization ()
5436 "Make an Organization header."
5437 (let* ((organization
5438 (when message-user-organization
5439 (if (functionp message-user-organization)
5440 (funcall message-user-organization)
5441 message-user-organization))))
5443 (mm-enable-multibyte)
5444 (cond ((stringp organization)
5445 (insert organization))
5446 ((and (eq t organization)
5447 message-user-organization-file
5448 (file-exists-p message-user-organization-file))
5449 (insert-file-contents message-user-organization-file)))
5450 (goto-char (point-min))
5451 (while (re-search-forward "[\t\n]+" nil t)
5452 (replace-match "" t t))
5453 (unless (zerop (buffer-size))
5456 (defun message-make-lines ()
5457 "Count the number of lines and return numeric string."
5462 (int-to-string (count-lines (point) (point-max))))))
5464 (defun message-make-references ()
5465 "Return the References header for this message."
5466 (when message-reply-headers
5467 (let ((message-id (mail-header-id message-reply-headers))
5468 (references (mail-header-references message-reply-headers)))
5469 (if (or references message-id)
5470 (concat (or references "") (and references " ")
5474 (defun message-make-in-reply-to ()
5475 "Return the In-Reply-To header for this message."
5476 (when message-reply-headers
5477 (let ((from (mail-header-from message-reply-headers))
5478 (date (mail-header-date message-reply-headers))
5479 (msg-id (mail-header-id message-reply-headers)))
5481 (let ((name (mail-extract-address-components from)))
5483 msg-id (if msg-id " (")
5485 (if (string-match "[^\000-\177]" (car name))
5486 ;; Quote a string containing non-ASCII characters.
5487 ;; It will make the RFC2047 encoder cause an error
5488 ;; if there are special characters.
5489 (mm-with-multibyte-buffer
5491 (goto-char (point-min))
5492 (while (search-forward "\"" nil t)
5495 (zerop (% (skip-chars-backward "\\\\") 2))
5496 (goto-char (match-beginning 0)))
5499 ;; Those quotes will be removed by the RFC2047 encoder.
5500 (concat "\"" (buffer-string) "\""))
5504 (if (or (not date) (string= date ""))
5505 "(unknown date)" date)
5506 "\"" (if msg-id ")")))))))
5508 (defun message-make-distribution ()
5509 "Make a Distribution header."
5510 (let ((orig-distribution (message-fetch-reply-field "distribution")))
5511 (cond ((functionp message-distribution-function)
5512 (funcall message-distribution-function))
5513 (t orig-distribution))))
5515 (defun message-make-expires ()
5516 "Return an Expires header based on `message-expires'."
5517 (let ((current (current-time))
5518 (future (* 1.0 message-expires 60 60 24)))
5519 ;; Add the future to current.
5520 (setcar current (+ (car current) (round (/ future (expt 2 16)))))
5521 (setcar (cdr current) (+ (nth 1 current) (% (round future) (expt 2 16))))
5522 (message-make-date current)))
5524 (defun message-make-path ()
5526 (let ((login-name (user-login-name)))
5527 (cond ((null message-user-path)
5528 (concat (system-name) "!" login-name))
5529 ((stringp message-user-path)
5530 ;; Support GENERICPATH. Suggested by vixie@decwrl.dec.com.
5531 (concat message-user-path "!" login-name))
5534 (defun message-make-from (&optional name address)
5535 "Make a From header."
5536 (let* ((style message-from-style)
5537 (login (or address (message-make-address)))
5539 (and (boundp 'user-full-name)
5542 (when (string= fullname "&")
5543 (setq fullname (user-login-name)))
5545 (mm-enable-multibyte)
5548 (equal fullname ""))
5550 ((or (eq style 'angles)
5551 (and (not (eq style 'parens))
5552 ;; Use angles if no quoting is needed, or if parens would
5553 ;; need quoting too.
5554 (or (not (string-match "[^- !#-'*+/-9=?A-Z^-~]" fullname))
5555 (let ((tmp (concat fullname nil)))
5556 (while (string-match "([^()]*)" tmp)
5557 (aset tmp (match-beginning 0) ?-)
5558 (aset tmp (1- (match-end 0)) ?-))
5559 (string-match "[\\()]" tmp)))))
5561 (goto-char (point-min))
5562 ;; Look for a character that cannot appear unquoted
5563 ;; according to RFC 822.
5564 (when (re-search-forward "[^- !#-'*+/-9=?A-Z^-~]" nil 1)
5565 ;; Quote fullname, escaping specials.
5566 (goto-char (point-min))
5568 (while (re-search-forward "[\"\\]" nil 1)
5569 (replace-match "\\\\\\&" t))
5571 (insert " <" login ">"))
5572 (t ; 'parens or default
5574 (let ((fullname-start (point)))
5576 (goto-char fullname-start)
5577 ;; RFC 822 says \ and nonmatching parentheses
5578 ;; must be escaped in comments.
5579 ;; Escape every instance of ()\ ...
5580 (while (re-search-forward "[()\\]" nil 1)
5581 (replace-match "\\\\\\&" t))
5582 ;; ... then undo escaping of matching parentheses,
5583 ;; including matching nested parentheses.
5584 (goto-char fullname-start)
5585 (while (re-search-forward
5586 "\\(\\=\\|[^\\]\\(\\\\\\\\\\)*\\)\\\\(\\(\\([^\\]\\|\\\\\\\\\\)*\\)\\\\)"
5588 (replace-match "\\1(\\3)" t)
5589 (goto-char fullname-start)))
5593 (defun message-make-sender ()
5594 "Return the \"real\" user address.
5595 This function tries to ignore all user modifications, and
5596 give as trustworthy answer as possible."
5597 (concat (user-login-name) "@" (system-name)))
5599 (defun message-make-address ()
5600 "Make the address of the user."
5601 (or (message-user-mail-address)
5602 (concat (user-login-name) "@" (message-make-domain))))
5604 (defun message-user-mail-address ()
5605 "Return the pertinent part of `user-mail-address'."
5606 (when (and user-mail-address
5607 (string-match "@.*\\." user-mail-address))
5608 (if (string-match " " user-mail-address)
5609 (nth 1 (mail-extract-address-components user-mail-address))
5610 user-mail-address)))
5612 (defun message-sendmail-envelope-from ()
5613 "Return the envelope from."
5614 (cond ((eq message-sendmail-envelope-from 'header)
5615 (nth 1 (mail-extract-address-components
5616 (message-fetch-field "from"))))
5617 ((stringp message-sendmail-envelope-from)
5618 message-sendmail-envelope-from)
5620 (message-make-address))))
5622 (defun message-make-fqdn ()
5623 "Return user's fully qualified domain name."
5624 (let* ((system-name (system-name))
5625 (user-mail (message-user-mail-address))
5628 (string-match "@\\(.*\\)\\'" user-mail))
5629 (match-string 1 user-mail)))
5630 (case-fold-search t))
5632 ((and message-user-fqdn
5633 (stringp message-user-fqdn)
5634 (string-match message-valid-fqdn-regexp message-user-fqdn)
5635 (not (string-match message-bogus-system-names message-user-fqdn)))
5636 ;; `message-user-fqdn' seems to be valid
5638 ((and (string-match message-valid-fqdn-regexp system-name)
5639 (not (string-match message-bogus-system-names system-name)))
5640 ;; `system-name' returned the right result.
5642 ;; Try `mail-host-address'.
5643 ((and (boundp 'mail-host-address)
5644 (stringp mail-host-address)
5645 (string-match message-valid-fqdn-regexp mail-host-address)
5646 (not (string-match message-bogus-system-names mail-host-address)))
5648 ;; We try `user-mail-address' as a backup.
5650 (stringp user-domain)
5651 (string-match message-valid-fqdn-regexp user-domain)
5652 (not (string-match message-bogus-system-names user-domain)))
5654 ;; Default to this bogus thing.
5657 ".i-did-not-set--mail-host-address--so-tickle-me")))))
5659 (defun message-make-host-name ()
5660 "Return the name of the host."
5661 (let ((fqdn (message-make-fqdn)))
5662 (string-match "^[^.]+\\." fqdn)
5663 (substring fqdn 0 (1- (match-end 0)))))
5665 (defun message-make-domain ()
5666 "Return the domain name."
5667 (or mail-host-address
5668 (message-make-fqdn)))
5670 (defun message-to-list-only ()
5671 "Send a message to the list only.
5672 Remove all addresses but the list address from To and Cc headers."
5674 (let ((listaddr (message-make-mail-followup-to t)))
5677 (message-remove-header "to")
5678 (message-remove-header "cc")
5679 (message-position-on-field "To" "X-Draft-From")
5680 (insert listaddr)))))
5682 (defun message-make-mail-followup-to (&optional only-show-subscribed)
5683 "Return the Mail-Followup-To header.
5684 If passed the optional argument ONLY-SHOW-SUBSCRIBED only return the
5685 subscribed address (and not the additional To and Cc header contents)."
5686 (let* ((case-fold-search t)
5687 (to (message-fetch-field "To"))
5688 (cc (message-fetch-field "cc"))
5689 (msg-recipients (concat to (and to cc ", ") cc))
5691 (mapcar 'mail-strip-quoted-names
5692 (message-tokenize-header msg-recipients)))
5694 (if message-subscribed-address-file
5695 (let (begin end item re)
5698 (insert-file-contents message-subscribed-address-file)
5700 (setq begin (point))
5703 (if (bolp) (setq end (1- end)))
5704 (setq item (regexp-quote (buffer-substring begin end)))
5705 (if re (setq re (concat re "\\|" item))
5706 (setq re (concat "\\`\\(" item))))
5707 (and re (list (concat re "\\)\\'"))))))))
5708 (mft-regexps (apply 'append message-subscribed-regexps
5709 (mapcar 'regexp-quote
5710 message-subscribed-addresses)
5713 message-subscribed-address-functions))))
5716 (loop for recipient in recipients
5717 when (loop for regexp in mft-regexps
5718 when (string-match regexp recipient) return t)
5721 (if only-show-subscribed
5723 msg-recipients))))))
5725 (defun message-idna-to-ascii-rhs-1 (header)
5726 "Interactively potentially IDNA encode domain names in HEADER."
5727 (let ((field (message-fetch-field header))
5731 (mm-delete-duplicates
5732 (mapcar (lambda (rhs) (or (cadr (split-string rhs "@")) ""))
5736 (mail-extract-address-components field t))))))
5737 ;; Note that `rhs' will be "" if the address does not have
5738 ;; the domain part, i.e., if it is a local user's address.
5739 (setq ace (if (string-match "\\`[[:ascii:]]*\\'" rhs)
5741 (downcase (idna-to-ascii rhs))))
5742 (when (and (not (equal rhs ace))
5743 (or (not (eq message-use-idna 'ask))
5744 (y-or-n-p (format "Replace %s with %s in %s:? "
5746 (goto-char (point-min))
5747 (while (re-search-forward (concat "^" header ":") nil t)
5748 (message-narrow-to-field)
5749 (while (search-forward (concat "@" rhs) nil t)
5750 (replace-match (concat "@" ace) t t))
5751 (goto-char (point-max))
5754 (defun message-idna-to-ascii-rhs ()
5755 "Possibly IDNA encode non-ASCII domain names in From:, To: and Cc: headers.
5756 See `message-idna-encode'."
5758 (when message-use-idna
5761 ;; `message-narrow-to-head' that recognizes only the first empty
5762 ;; line as the message header separator used to be used here.
5763 ;; However, since there is the "--text follows this line--" line
5764 ;; normally, it failed in narrowing to the headers and potentially
5765 ;; caused the IDNA encoding on lines that look like headers in
5766 ;; the message body.
5767 (message-narrow-to-headers-or-head)
5768 (message-idna-to-ascii-rhs-1 "From")
5769 (message-idna-to-ascii-rhs-1 "To")
5770 (message-idna-to-ascii-rhs-1 "Reply-To")
5771 (message-idna-to-ascii-rhs-1 "Mail-Reply-To")
5772 (message-idna-to-ascii-rhs-1 "Mail-Followup-To")
5773 (message-idna-to-ascii-rhs-1 "Cc")))))
5775 (defun message-generate-headers (headers)
5776 "Prepare article HEADERS.
5777 Headers already prepared in the buffer are not modified."
5778 (setq headers (append headers message-required-headers))
5780 (message-narrow-to-headers)
5781 (let* ((Date (message-make-date))
5782 (Message-ID (message-make-message-id))
5783 (Organization (message-make-organization))
5784 (From (message-make-from))
5785 (Path (message-make-path))
5788 (In-Reply-To (message-make-in-reply-to))
5789 (References (message-make-references))
5791 (Distribution (message-make-distribution))
5792 (Lines (message-make-lines))
5793 (User-Agent message-newsreader)
5794 (Expires (message-make-expires))
5795 (case-fold-search t)
5797 header value elem header-string)
5798 ;; First we remove any old generated headers.
5799 (let ((headers message-deletable-headers))
5800 (unless (buffer-modified-p)
5801 (setq headers (delq 'Message-ID (copy-sequence headers))))
5803 (goto-char (point-min))
5804 (and (re-search-forward
5805 (concat "^" (symbol-name (car headers)) ": *") nil t)
5806 (get-text-property (1+ (match-beginning 0)) 'message-deletable)
5807 (message-delete-line))
5809 ;; Go through all the required headers and see if they are in the
5810 ;; articles already. If they are not, or are empty, they are
5811 ;; inserted automatically - except for Subject, Newsgroups and
5814 (goto-char (point-min))
5815 (setq elem (pop headers))
5817 (if (eq (car elem) 'optional)
5818 (setq header (cdr elem)
5820 (setq header (car elem)))
5822 (setq header-string (if (stringp header)
5824 (symbol-name header)))
5825 (when (or (not (re-search-forward
5827 (regexp-quote (downcase header-string))
5831 ;; The header was found. We insert a space after the
5832 ;; colon, if there is none.
5833 (if (/= (char-after) ? ) (insert " ") (forward-char 1))
5834 ;; Find out whether the header is empty.
5835 (looking-at "[ \t]*\n[^ \t]")))
5836 ;; So we find out what value we should insert.
5840 (eq (car elem) 'optional)
5841 (not (member header-string message-inserted-headers)))
5842 ;; This is an optional header. If the cdr of this
5843 ;; is something that is nil, then we do not insert
5845 (setq header (cdr elem))
5846 (or (and (functionp (cdr elem))
5847 (funcall (cdr elem)))
5848 (and (boundp (cdr elem))
5849 (symbol-value (cdr elem)))))
5851 ;; The element is a cons. Either the cdr is a
5852 ;; string to be inserted verbatim, or it is a
5853 ;; function, and we insert the value returned from
5855 (or (and (stringp (cdr elem))
5857 (and (functionp (cdr elem))
5858 (funcall (cdr elem)))))
5859 ((and (boundp header)
5860 (symbol-value header))
5861 ;; The element is a symbol. We insert the value
5862 ;; of this symbol, if any.
5863 (symbol-value header))
5864 ((not (message-check-element
5865 (intern (downcase (symbol-name header)))))
5866 ;; We couldn't generate a value for this header,
5867 ;; so we just ask the user.
5868 (read-from-minibuffer
5869 (format "Empty header for %s; enter value: " header)))))
5870 ;; Finally insert the header.
5872 (not (equal value "")))
5876 ;; This header didn't exist, so we insert it.
5877 (goto-char (point-max))
5879 (cdr (assq header message-header-format-alist))))
5881 (funcall formatter header value)
5882 (insert header-string ": " value))
5883 (push header-string message-inserted-headers)
5884 (goto-char (message-fill-field))
5885 ;; We check whether the value was ended by a
5886 ;; newline. If not, we insert one.
5890 ;; The value of this header was empty, so we clear
5891 ;; totally and insert the new value.
5892 (delete-region (point) (point-at-eol))
5893 ;; If the header is optional, and the header was
5894 ;; empty, we can't insert it anyway.
5896 (push header-string message-inserted-headers)
5898 (message-fill-field)))
5899 ;; Add the deletable property to the headers that require it.
5900 (and (memq header message-deletable-headers)
5901 (progn (beginning-of-line) (looking-at "[^:]+: "))
5902 (add-text-properties
5903 (point) (match-end 0)
5904 '(message-deletable t face italic) (current-buffer)))))))
5905 ;; Insert new Sender if the From is strange.
5906 (let ((from (message-fetch-field "from"))
5907 (sender (message-fetch-field "sender"))
5908 (secure-sender (message-make-sender)))
5910 (not (message-check-element 'sender))
5913 (cadr (mail-extract-address-components from)))
5914 (downcase secure-sender)))
5919 (cadr (mail-extract-address-components sender)))
5920 (downcase secure-sender)))))
5921 (goto-char (point-min))
5922 ;; Rename any old Sender headers to Original-Sender.
5923 (when (re-search-forward "^\\(Original-\\)*Sender:" nil t)
5925 (insert "Original-")
5926 (beginning-of-line))
5927 (when (or (message-news-p)
5928 (string-match "@.+\\.." secure-sender))
5929 (insert "Sender: " secure-sender "\n"))))
5931 (message-idna-to-ascii-rhs))))
5933 (defun message-insert-courtesy-copy ()
5934 "Insert a courtesy message in mail copies of combined messages."
5938 (message-narrow-to-headers)
5939 (when (setq newsgroups (message-fetch-field "newsgroups"))
5940 (goto-char (point-max))
5941 (insert "Posted-To: " newsgroups "\n")))
5943 (when message-courtesy-message
5945 ((string-match "%s" message-courtesy-message)
5946 (insert (format message-courtesy-message newsgroups)))
5948 (insert message-courtesy-message)))))))
5951 ;;; Setting up a message buffer
5954 (defun message-skip-to-next-address ()
5955 (let ((end (save-excursion
5956 (message-next-header)
5959 (when (looking-at ",")
5961 (while (and (not (= (point) end))
5962 (or (not (eq char ?,))
5964 (skip-chars-forward "^,\"" (point-max))
5965 (when (eq (setq char (following-char)) ?\")
5966 (setq quoted (not quoted)))
5967 (unless (= (point) end)
5969 (skip-chars-forward " \t\n")))
5971 (defun message-fill-address (header value)
5972 (insert (capitalize (symbol-name header))
5974 (if (consp value) (car value) value)
5976 (message-fill-field-address))
5978 (defun message-split-line ()
5979 "Split current line, moving portion beyond point vertically down.
5980 If the current line has `message-yank-prefix', insert it on the new line."
5983 (split-line message-yank-prefix) ;; Emacs 22.1+ supports arg.
5987 (defun message-insert-header (header value)
5988 (insert (capitalize (symbol-name header))
5990 (if (consp value) (car value) value)))
5992 (defun message-field-name ()
5994 (goto-char (point-min))
5995 (when (looking-at "\\([^:]+\\):")
5996 (intern (capitalize (match-string 1))))))
5998 (defun message-fill-field ()
6001 (message-narrow-to-field)
6002 (let ((field-name (message-field-name)))
6003 (funcall (or (cadr (assq field-name message-field-fillers))
6004 'message-fill-field-general)))
6007 (defun message-fill-field-address ()
6009 (message-skip-to-next-address)
6011 (if (and (> (current-column) 78)
6017 (setq last (1+ (point))))
6018 (setq last (1+ (point)))))))
6020 (defun message-fill-field-general ()
6021 (let ((begin (point))
6024 (while (and (search-forward "\n" nil t)
6026 (replace-match " " t t))
6027 (fill-region-as-paragraph begin (point-max))
6028 ;; Tapdance around looong Message-IDs.
6030 (when (looking-at "[ \t]*$")
6031 (message-delete-line))
6033 (search-forward ":" nil t)
6034 (when (looking-at "\n[ \t]+")
6035 (replace-match " " t t))
6036 (goto-char (point-max))))
6038 (defun message-shorten-1 (list cut surplus)
6039 "Cut SURPLUS elements out of LIST, beginning with CUTth one."
6040 (setcdr (nthcdr (- cut 2) list)
6041 (nthcdr (+ (- cut 2) surplus 1) list)))
6043 (defun message-shorten-references (header references)
6044 "Trim REFERENCES to be 21 Message-ID long or less, and fold them.
6045 When sending via news, also check that the REFERENCES are less
6046 than 988 characters long, and if they are not, trim them until
6054 (goto-char (point-min))
6055 ;; Cons a list of valid references. GNKSA says we must not include MIDs
6056 ;; with whitespace or missing brackets (7.a "Does not propagate broken
6057 ;; Message-IDs in original References").
6058 (while (re-search-forward "<[^ <]+@[^ <]+>" nil t)
6059 (push (match-string 0) refs))
6060 (setq refs (nreverse refs)
6061 count (length refs)))
6063 ;; If the list has more than MAXCOUNT elements, trim it by
6064 ;; removing the CUTth element and the required number of
6065 ;; elements that follow.
6066 (when (> count maxcount)
6067 (let ((surplus (- count maxcount)))
6068 (message-shorten-1 refs cut surplus)
6069 (decf count surplus)))
6071 ;; When sending via news, make sure the total folded length will
6072 ;; be less than 998 characters. This is to cater to broken INN
6073 ;; 2.3 which counts the total number of characters in a header
6074 ;; rather than the physical line length of each line, as it should.
6076 ;; This hack should be removed when it's believed than INN 2.3 is
6077 ;; no longer widely used.
6079 ;; At this point the headers have not been generated, thus we use
6080 ;; message-this-is-news directly.
6081 (when message-this-is-news
6084 (message-insert-header
6085 header (mapconcat #'identity refs " "))
6087 (message-shorten-1 refs cut 1)))
6088 ;; Finally, collect the references back into a string and insert
6089 ;; it into the buffer.
6090 (message-insert-header header (mapconcat #'identity refs " "))))
6092 (defun message-position-point ()
6093 "Move point to where the user probably wants to find it."
6094 (message-narrow-to-headers)
6096 ((re-search-forward "^[^:]+:[ \t]*$" nil t)
6097 (search-backward ":" )
6100 (if (eq (char-after) ? )
6104 (goto-char (point-max))
6107 (unless (looking-at "$")
6111 (defcustom message-beginning-of-line t
6112 "Whether \\<message-mode-map>\\[message-beginning-of-line]\
6113 goes to beginning of header values."
6115 :group 'message-buffers
6116 :link '(custom-manual "(message)Movement")
6119 (defun message-beginning-of-line (&optional n)
6120 "Move point to beginning of header value or to beginning of line.
6121 The prefix argument N is passed directly to `beginning-of-line'.
6123 This command is identical to `beginning-of-line' if point is
6124 outside the message header or if the option `message-beginning-of-line'
6127 If point is in the message header and on a (non-continued) header
6128 line, move point to the beginning of the header value or the beginning of line,
6129 whichever is closer. If point is already at beginning of line, move point to
6130 beginning of header value. Therefore, repeated calls will toggle point
6131 between beginning of field and beginning of line."
6133 (let ((zrs 'zmacs-region-stays))
6134 (when (and (featurep 'xemacs) (interactive-p) (boundp zrs))
6136 (if (and message-beginning-of-line
6137 (message-point-in-header-p))
6138 (let* ((here (point))
6139 (bol (progn (beginning-of-line n) (point)))
6140 (eol (point-at-eol))
6141 (eoh (re-search-forward ": *" eol t)))
6143 (if (and eoh (or (< eoh here) (= bol here)))
6145 (beginning-of-line n)))
6147 (defun message-buffer-name (type &optional to group)
6148 "Return a new (unique) buffer name based on TYPE and TO."
6150 ;; Generate a new buffer name The Message Way.
6151 ((memq message-generate-new-buffers '(unique t))
6152 (generate-new-buffer-name
6156 (or (car (mail-extract-address-components to))
6159 (if (and group (not (string= group ""))) (concat " on " group) "")
6161 ;; Check whether `message-generate-new-buffers' is a function,
6162 ;; and if so, call it.
6163 ((functionp message-generate-new-buffers)
6164 (funcall message-generate-new-buffers type to group))
6165 ((eq message-generate-new-buffers 'unsent)
6166 (generate-new-buffer-name
6167 (concat "*unsent " type
6170 (or (car (mail-extract-address-components to))
6173 (if (and group (not (string= group ""))) (concat " on " group) "")
6175 ;; Search for the existing message buffer with the specified name.
6177 (let* ((new (if (eq message-generate-new-buffers 'standard)
6178 (generate-new-buffer-name (concat "*" type " message*"))
6179 (let ((message-generate-new-buffers 'unique))
6180 (message-buffer-name type to group))))
6181 (regexp (concat "\\`"
6183 (if (string-match "<[0-9]+>\\'" new)
6184 (substring new 0 (match-beginning 0))
6186 "\\(?:<\\([0-9]+\\)>\\)?\\'"))
6187 (case-fold-search nil))
6194 (when (and (string-match regexp (setq b (buffer-name b)))
6195 (eq (with-current-buffer b major-mode)
6197 (cons (string-to-number (or (match-string 1 b) "1"))
6200 'car-less-than-car)))
6203 (defun message-pop-to-buffer (name &optional switch-function)
6204 "Pop to buffer NAME, and warn if it already exists and is modified."
6205 (let ((buffer (get-buffer name)))
6207 (buffer-name buffer))
6208 (let ((window (get-buffer-window buffer 0)))
6210 ;; Raise the frame already displaying the message buffer.
6212 (gnus-select-frame-set-input-focus (window-frame window))
6213 (select-window window))
6214 (funcall (or switch-function 'pop-to-buffer) buffer)
6215 (set-buffer buffer))
6216 (when (and (buffer-modified-p)
6219 "Message already being composed; erase? ")
6221 (error "Message being composed")))
6222 (funcall (or switch-function 'pop-to-buffer) name)
6227 (defun message-do-send-housekeeping ()
6228 "Kill old message buffers."
6229 ;; We might have sent this buffer already. Delete it from the
6231 (setq message-buffer-list (delq (current-buffer) message-buffer-list))
6232 (while (and message-max-buffers
6234 (>= (length message-buffer-list) message-max-buffers))
6235 ;; Kill the oldest buffer -- unless it has been changed.
6236 (let ((buffer (pop message-buffer-list)))
6237 (when (and (buffer-name buffer)
6238 (not (buffer-modified-p buffer)))
6239 (kill-buffer buffer))))
6240 ;; Rename the buffer.
6241 (if message-send-rename-function
6242 (funcall message-send-rename-function)
6243 ;; Note: mail-abbrevs of XEmacs renames buffer name behind Gnus.
6245 "\\`\\*\\(sent \\|unsent \\)?\\(.+\\)\\*[^\\*]*\\|\\`mail to "
6247 (let ((name (match-string 2 (buffer-name)))
6249 (if (not (or (null name)
6250 (string-equal name "mail")
6251 (string-equal name "posting")))
6252 (setq name (concat "*sent " name "*"))
6253 (message-narrow-to-headers)
6254 (setq to (message-fetch-field "to"))
6255 (setq group (message-fetch-field "newsgroups"))
6259 (to (concat "*sent mail to "
6260 (or (car (mail-extract-address-components to))
6262 ((and group (not (string= group "")))
6263 (concat "*sent posting on " group "*"))
6264 (t "*sent mail*"))))
6265 (unless (string-equal name (buffer-name))
6266 (rename-buffer name t)))))
6267 ;; Push the current buffer onto the list.
6268 (when message-max-buffers
6269 (setq message-buffer-list
6270 (nconc message-buffer-list (list (current-buffer))))))
6272 (defun message-mail-user-agent ()
6274 ((not message-mail-user-agent) nil)
6275 ((eq message-mail-user-agent t) mail-user-agent)
6276 (t message-mail-user-agent))))
6277 (if (memq mua '(message-user-agent gnus-user-agent))
6281 ;; YANK-ACTION, if non-nil, can be a buffer or a yank action of the
6282 ;; form (FUNCTION . ARGS).
6283 (defun message-setup (headers &optional yank-action actions
6284 continue switch-function)
6285 (let ((mua (message-mail-user-agent))
6287 (if (not (and message-this-is-mail mua))
6288 (message-setup-1 headers yank-action actions)
6289 (setq headers (copy-sequence headers))
6290 (setq field (assq 'Subject headers))
6292 (setq subject (cdr field))
6293 (setq headers (delq field headers)))
6294 (setq field (assq 'To headers))
6296 (setq to (cdr field))
6297 (setq headers (delq field headers)))
6298 (let ((mail-user-agent mua))
6299 (compose-mail to subject
6300 (mapcar (lambda (item)
6302 (format "%s" (car item))
6305 continue switch-function
6306 (if (bufferp yank-action)
6307 (list 'insert-buffer yank-action)
6311 (defun message-headers-to-generate (headers included-headers excluded-headers)
6312 "Return a list that includes all headers from HEADERS.
6313 If INCLUDED-HEADERS is a list, just include those headers. If it is
6314 t, include all headers. In any case, headers from EXCLUDED-HEADERS
6318 (dolist (header headers)
6319 (setq header-name (cond
6320 ((and (consp header)
6321 (eq (car header) 'optional))
6322 ;; On the form (optional . Header)
6325 ;; On the form (Header . function)
6330 (when (and (not (memq header-name excluded-headers))
6331 (or (eq included-headers t)
6332 (memq header-name included-headers)))
6333 (push header result)))
6336 (defun message-setup-1 (headers &optional yank-action actions)
6337 (dolist (action actions)
6339 (add-to-list 'message-send-actions
6340 `(apply ',(car action) ',(cdr action)))))
6341 (setq message-reply-buffer
6342 (if (and (consp yank-action)
6343 (eq (car yank-action) 'insert-buffer))
6346 (goto-char (point-min))
6347 ;; Insert all the headers.
6350 (alist message-header-format-alist))
6352 (unless (assq (caar h) message-header-format-alist)
6353 (push (list (caar h)) alist))
6357 (delete-region (point) (progn (forward-line -1) (point)))
6358 (when message-default-headers
6359 (insert message-default-headers)
6360 (or (bolp) (insert ?\n)))
6361 (insert mail-header-separator "\n")
6363 (when (message-news-p)
6364 (when message-default-news-headers
6365 (insert message-default-news-headers)
6366 (or (bolp) (insert ?\n)))
6367 (when message-generate-headers-first
6368 (message-generate-headers
6369 (message-headers-to-generate
6370 (append message-required-news-headers
6371 message-required-headers)
6372 message-generate-headers-first
6373 '(Lines Subject)))))
6374 (when (message-mail-p)
6375 (when message-default-mail-headers
6376 (insert message-default-mail-headers)
6377 (or (bolp) (insert ?\n)))
6378 (when message-generate-headers-first
6379 (message-generate-headers
6380 (message-headers-to-generate
6381 (append message-required-mail-headers
6382 message-required-headers)
6383 message-generate-headers-first
6384 '(Lines Subject)))))
6385 (run-hooks 'message-signature-setup-hook)
6386 (message-insert-signature)
6388 (message-narrow-to-headers)
6389 (run-hooks 'message-header-setup-hook))
6390 (setq buffer-undo-list nil)
6391 (when message-generate-hashcash
6392 ;; Generate hashcash headers for recipients already known
6393 (mail-add-payment-async))
6394 ;; Gnus posting styles are applied via buffer-local `message-setup-hook'
6396 (run-hooks 'message-setup-hook)
6397 ;; Do this last to give it precedence over posting styles, etc.
6398 (when (message-mail-p)
6400 (message-narrow-to-headers)
6401 (if message-alternative-emails
6402 (message-use-alternative-email-as-from))))
6403 (message-position-point)
6404 ;; Allow correct handling of `message-checksum' in `message-yank-original':
6405 (set-buffer-modified-p nil)
6408 (defun message-set-auto-save-file-name ()
6409 "Associate the message buffer with a file in the drafts directory."
6410 (when message-auto-save-directory
6411 (unless (file-directory-p
6412 (directory-file-name message-auto-save-directory))
6413 (make-directory message-auto-save-directory t))
6415 (setq message-draft-article
6416 (nndraft-request-associate-buffer "drafts"))
6418 ;; If Gnus were alive, draft messages would be saved in the drafts folder.
6419 ;; But Gnus is not alive, so arrange to save the draft message in a
6420 ;; regular file in message-auto-save-directory. Append a unique
6421 ;; time-based suffix to the filename to allow multiple drafts to be saved
6422 ;; simultaneously without overwriting each other (which mimics the
6423 ;; functionality of the Gnus drafts folder).
6424 (setq buffer-file-name (expand-file-name
6426 (if (memq system-type
6427 '(ms-dos ms-windows windows-nt
6428 cygwin cygwin32 win32 w32
6432 (format-time-string "-%Y%m%d-%H%M%S"))
6433 message-auto-save-directory))
6434 (setq buffer-auto-save-file-name (make-auto-save-file-name)))
6435 (clear-visited-file-modtime)
6436 (setq buffer-file-coding-system message-draft-coding-system)))
6438 (defun message-disassociate-draft ()
6439 "Disassociate the message buffer from the drafts directory."
6440 (when message-draft-article
6441 (nndraft-request-expire-articles
6442 (list message-draft-article) "drafts" nil t)))
6444 (defun message-insert-headers ()
6445 "Generate the headers for the article."
6449 (message-narrow-to-headers)
6450 (when (message-news-p)
6451 (message-generate-headers
6454 (copy-sequence message-required-news-headers)))))
6455 (when (message-mail-p)
6456 (message-generate-headers
6459 (copy-sequence message-required-mail-headers))))))))
6464 ;;; Commands for interfacing with message
6468 (defun message-mail (&optional to subject
6469 other-headers continue switch-function
6470 yank-action send-actions)
6471 "Start editing a mail message to be sent.
6472 OTHER-HEADERS is an alist of header/value pairs. CONTINUE says whether
6473 to continue editing a message already being composed. SWITCH-FUNCTION
6474 is a function used to switch to and display the mail buffer."
6476 (let ((message-this-is-mail t))
6477 (unless (message-mail-user-agent)
6478 (message-pop-to-buffer
6479 ;; Search for the existing message buffer if `continue' is non-nil.
6480 (let ((message-generate-new-buffers
6481 (when (or (not continue)
6482 (eq message-generate-new-buffers 'standard)
6483 (functionp message-generate-new-buffers))
6484 message-generate-new-buffers)))
6485 (message-buffer-name "mail" to))
6489 `((To . ,(or to "")) (Subject . ,(or subject "")))
6490 (when other-headers other-headers))
6491 yank-action send-actions continue switch-function)
6492 ;; FIXME: Should return nil if failure.
6496 (defun message-news (&optional newsgroups subject)
6497 "Start editing a news article to be sent."
6499 (let ((message-this-is-news t))
6500 (message-pop-to-buffer (message-buffer-name "posting" nil newsgroups))
6501 (message-setup `((Newsgroups . ,(or newsgroups ""))
6502 (Subject . ,(or subject ""))))))
6504 (defun message-alter-recipients-discard-bogus-full-name (addrcell)
6505 "Discard mail address in full names.
6506 When the full name in reply headers contains the mail
6507 address (e.g. \"foo@bar <foo@bar>\"), discard full name.
6508 ADDRCELL is a cons cell where the car is the mail address and the
6509 cdr is the complete address (full name and mail address)."
6510 (if (string-match (concat (regexp-quote (car addrcell)) ".*"
6511 (regexp-quote (car addrcell)))
6513 (cons (car addrcell) (car addrcell))
6516 (defcustom message-alter-recipients-function nil
6517 "Function called to allow alteration of reply header structures.
6518 It is called in `message-get-reply-headers' for each recipient.
6519 The function is called with one parameter, a cons cell ..."
6520 :type '(choice (const :tag "None" nil)
6521 (const :tag "Discard bogus full name"
6522 message-alter-recipients-discard-bogus-full-name)
6524 :version "23.1" ;; No Gnus
6525 :group 'message-headers)
6527 (defun message-get-reply-headers (wide &optional to-address address-headers)
6528 (let (follow-to mct never-mct to cc author mft recipients extra)
6529 ;; Find all relevant headers we need.
6531 (message-narrow-to-headers-or-head)
6532 ;; Gmane renames "To". Look at "Original-To", too, if it is present in
6533 ;; message-header-synonyms.
6534 (setq to (or (message-fetch-field "to")
6535 (and (loop for synonym in message-header-synonyms
6536 when (memq 'Original-To synonym)
6538 (message-fetch-field "original-to")))
6539 cc (message-fetch-field "cc")
6540 extra (when message-extra-wide-headers
6541 (mapconcat 'identity
6542 (mapcar 'message-fetch-field
6543 message-extra-wide-headers)
6545 mct (message-fetch-field "mail-copies-to")
6546 author (or (message-fetch-field "mail-reply-to")
6547 (message-fetch-field "reply-to")
6548 (message-fetch-field "from")
6550 mft (and message-use-mail-followup-to
6551 (message-fetch-field "mail-followup-to"))))
6553 ;; Handle special values of Mail-Copies-To.
6555 (cond ((or (equal (downcase mct) "never")
6556 (equal (downcase mct) "nobody"))
6559 ((or (equal (downcase mct) "always")
6560 (equal (downcase mct) "poster"))
6561 (setq mct author))))
6564 ;; Build (textual) list of new recipient addresses.
6567 (setq recipients (concat ", " author)))
6569 (dolist (header address-headers)
6570 (let ((value (message-fetch-field header)))
6572 (setq recipients (concat recipients ", " value))))))
6574 (string-match "[^ \t,]" mft)
6575 (or (not (eq message-use-mail-followup-to 'ask))
6576 (message-y-or-n-p "Obey Mail-Followup-To? " t "\
6577 You should normally obey the Mail-Followup-To: header. In this
6578 article, it has the value of
6582 which directs your response to " (if (string-match "," mft)
6583 "the specified addresses"
6584 "that address only") ".
6586 Most commonly, Mail-Followup-To is used by a mailing list poster to
6587 express that responses should be sent to just the list, and not the
6590 If a message is posted to several mailing lists, Mail-Followup-To may
6591 also be used to direct the following discussion to one list only,
6592 because discussions that are spread over several lists tend to be
6593 fragmented and very difficult to follow.
6595 Also, some source/announcement lists are not intended for discussion;
6596 responses here are directed to other addresses.
6598 You may customize the variable `message-use-mail-followup-to', if you
6599 want to get rid of this query permanently.")))
6600 (setq recipients (concat ", " mft)))
6602 (setq recipients (concat ", " to-address))
6603 ;; If the author explicitly asked for a copy, we don't deny it to them.
6604 (if mct (setq recipients (concat recipients ", " mct))))
6606 (setq recipients (if never-mct "" (concat ", " author)))
6607 (if to (setq recipients (concat recipients ", " to)))
6608 (if cc (setq recipients (concat recipients ", " cc)))
6609 (if extra (setq recipients (concat recipients ", " extra)))
6610 (if mct (setq recipients (concat recipients ", " mct)))))
6611 (if (>= (length recipients) 2)
6612 ;; Strip the leading ", ".
6613 (setq recipients (substring recipients 2)))
6614 ;; Squeeze whitespace.
6615 (while (string-match "[ \t][ \t]+" recipients)
6616 (setq recipients (replace-match " " t t recipients)))
6617 ;; Remove addresses that match `rmail-dont-reply-to-names'.
6618 (let ((rmail-dont-reply-to-names (message-dont-reply-to-names)))
6619 (setq recipients (rmail-dont-reply-to recipients)))
6620 ;; Perhaps "Mail-Copies-To: never" removed the only address?
6621 (if (string-equal recipients "")
6622 (setq recipients author))
6623 ;; Convert string to a list of (("foo@bar" . "Name <Foo@BAR>") ...).
6627 (if message-alter-recipients-function
6628 (funcall message-alter-recipients-function
6629 (cons (downcase (mail-strip-quoted-names addr))
6631 (cons (downcase (mail-strip-quoted-names addr)) addr)))
6632 (message-tokenize-header recipients)))
6633 ;; Remove first duplicates. (Why not all duplicates? Is this a bug?)
6634 (let ((s recipients))
6636 (setq recipients (delq (assoc (car (pop s)) s) recipients))))
6638 ;; Remove hierarchical lists that are contained within each other,
6639 ;; if message-hierarchical-addresses is defined.
6640 (when message-hierarchical-addresses
6641 (let ((plain-addrs (mapcar 'car recipients))
6644 (setq subaddrs (assoc (car plain-addrs)
6645 message-hierarchical-addresses)
6646 plain-addrs (cdr plain-addrs))
6648 (setq subaddrs (cdr subaddrs))
6650 (setq recip (assoc (car subaddrs) recipients)
6651 subaddrs (cdr subaddrs))
6653 (setq recipients (delq recip recipients))))))))
6655 ;; Build the header alist. Allow the user to be asked whether
6656 ;; or not to reply to all recipients in a wide reply.
6657 (setq follow-to (list (cons 'To (cdr (pop recipients)))))
6658 (when (and recipients
6659 (or (not message-wide-reply-confirm-recipients)
6660 (y-or-n-p "Reply to all recipients? ")))
6661 (setq recipients (mapconcat
6662 (lambda (addr) (cdr addr)) recipients ", "))
6663 (if (string-match "^ +" recipients)
6664 (setq recipients (substring recipients (match-end 0))))
6665 (push (cons 'Cc recipients) follow-to)))
6668 (defcustom message-simplify-subject-functions
6669 '(message-strip-list-identifiers
6670 message-strip-subject-re
6671 message-strip-subject-trailing-was
6672 message-strip-subject-encoded-words)
6673 "List of functions taking a string argument that simplify subjects.
6674 The functions are applied when replying to a message.
6676 Useful functions to put in this list include:
6677 `message-strip-list-identifiers', `message-strip-subject-re',
6678 `message-strip-subject-trailing-was', and
6679 `message-strip-subject-encoded-words'."
6680 :version "22.1" ;; Gnus 5.10.9
6681 :group 'message-various
6682 :type '(repeat function))
6684 (defun message-simplify-subject (subject &optional functions)
6685 "Return simplified SUBJECT."
6688 (setq functions message-simplify-subject-functions))
6689 (when (and (memq 'message-strip-list-identifiers functions)
6690 gnus-list-identifiers)
6691 (setq subject (message-strip-list-identifiers subject)))
6692 (when (memq 'message-strip-subject-re functions)
6693 (setq subject (concat "Re: " (message-strip-subject-re subject))))
6694 (when (and (memq 'message-strip-subject-trailing-was functions)
6695 message-subject-trailing-was-query)
6696 (setq subject (message-strip-subject-trailing-was subject)))
6697 (when (memq 'message-strip-subject-encoded-words functions)
6698 (setq subject (message-strip-subject-encoded-words subject)))
6702 (defun message-reply (&optional to-address wide)
6703 "Start editing a reply to the article in the current buffer."
6705 (require 'gnus-sum) ; for gnus-list-identifiers
6706 (let ((cur (current-buffer))
6707 from subject date reply-to to cc
6708 references message-id follow-to
6709 (inhibit-point-motion-hooks t)
6710 (message-this-is-mail t)
6713 (message-narrow-to-head-1)
6714 ;; Allow customizations to have their say.
6716 ;; This is a regular reply.
6717 (when (functionp message-reply-to-function)
6719 (setq follow-to (funcall message-reply-to-function))))
6720 ;; This is a followup.
6721 (when (functionp message-wide-reply-to-function)
6724 (funcall message-wide-reply-to-function)))))
6725 (setq message-id (message-fetch-field "message-id" t)
6726 references (message-fetch-field "references")
6727 date (message-fetch-field "date")
6728 from (or (message-fetch-field "from") "nobody")
6729 subject (or (message-fetch-field "subject") "none"))
6731 ;; Strip list identifiers, "Re: ", and "was:"
6732 (setq subject (message-simplify-subject subject))
6734 (when (and (setq gnus-warning (message-fetch-field "gnus-warning"))
6735 (string-match "<[^>]+>" gnus-warning))
6736 (setq message-id (match-string 0 gnus-warning)))
6739 (setq follow-to (message-get-reply-headers wide to-address))))
6741 (unless (message-mail-user-agent)
6742 (message-pop-to-buffer
6743 (message-buffer-name
6744 (if wide "wide reply" "reply") from
6745 (if wide to-address nil))))
6747 (setq message-reply-headers
6748 (vector 0 subject from date message-id references 0 0 ""))
6751 `((Subject . ,subject)
6756 (defun message-wide-reply (&optional to-address)
6757 "Make a \"wide\" reply to the message in the current buffer."
6759 (message-reply to-address t))
6762 (defun message-followup (&optional to-newsgroups)
6763 "Follow up to the message in the current buffer.
6764 If TO-NEWSGROUPS, use that as the new Newsgroups line."
6766 (require 'gnus-sum) ; for gnus-list-identifiers
6767 (let ((cur (current-buffer))
6768 from subject date reply-to mrt mct
6769 references message-id follow-to
6770 (inhibit-point-motion-hooks t)
6771 (message-this-is-news t)
6772 followup-to distribution newsgroups gnus-warning posted-to)
6775 (goto-char (point-min))
6776 (if (search-forward "\n\n" nil t)
6779 (when (functionp message-followup-to-function)
6781 (funcall message-followup-to-function)))
6782 (setq from (message-fetch-field "from")
6783 date (message-fetch-field "date")
6784 subject (or (message-fetch-field "subject") "none")
6785 references (message-fetch-field "references")
6786 message-id (message-fetch-field "message-id" t)
6787 followup-to (message-fetch-field "followup-to")
6788 newsgroups (message-fetch-field "newsgroups")
6789 posted-to (message-fetch-field "posted-to")
6790 reply-to (message-fetch-field "reply-to")
6791 mrt (message-fetch-field "mail-reply-to")
6792 distribution (message-fetch-field "distribution")
6793 mct (message-fetch-field "mail-copies-to"))
6794 (when (and (setq gnus-warning (message-fetch-field "gnus-warning"))
6795 (string-match "<[^>]+>" gnus-warning))
6796 (setq message-id (match-string 0 gnus-warning)))
6797 ;; Remove bogus distribution.
6798 (when (and (stringp distribution)
6799 (let ((case-fold-search t))
6800 (string-match "world" distribution)))
6801 (setq distribution nil))
6802 ;; Strip list identifiers, "Re: ", and "was:"
6803 (setq subject (message-simplify-subject subject))
6806 (message-pop-to-buffer (message-buffer-name "followup" from newsgroups))
6808 (setq message-reply-headers
6809 (vector 0 subject from date message-id references 0 0 ""))
6812 `((Subject . ,subject)
6815 (list (cons 'Newsgroups to-newsgroups)))
6816 (follow-to follow-to)
6817 ((and followup-to message-use-followup-to)
6820 ((equal (downcase followup-to) "poster")
6821 (if (or (eq message-use-followup-to 'use)
6822 (message-y-or-n-p "Obey Followup-To: poster? " t "\
6823 You should normally obey the Followup-To: header.
6825 `Followup-To: poster' sends your response via e-mail instead of news.
6827 A typical situation where `Followup-To: poster' is used is when the poster
6828 does not read the newsgroup, so he wouldn't see any replies sent to it.
6830 You may customize the variable `message-use-followup-to', if you
6831 want to get rid of this query permanently."))
6833 (setq message-this-is-news nil)
6834 (cons 'To (or mrt reply-to from "")))
6835 (cons 'Newsgroups newsgroups)))
6837 (if (or (equal followup-to newsgroups)
6838 (not (eq message-use-followup-to 'ask))
6840 (concat "Obey Followup-To: " followup-to "? ") t "\
6841 You should normally obey the Followup-To: header.
6843 `Followup-To: " followup-to "'
6844 directs your response to " (if (string-match "," followup-to)
6845 "the specified newsgroups"
6846 "that newsgroup only") ".
6848 If a message is posted to several newsgroups, Followup-To is often
6849 used to direct the following discussion to one newsgroup only,
6850 because discussions that are spread over several newsgroup tend to
6851 be fragmented and very difficult to follow.
6853 Also, some source/announcement newsgroups are not intended for discussion;
6854 responses here are directed to other newsgroups.
6856 You may customize the variable `message-use-followup-to', if you
6857 want to get rid of this query permanently."))
6858 (cons 'Newsgroups followup-to)
6859 (cons 'Newsgroups newsgroups))))))
6861 `((Newsgroups . ,posted-to)))
6863 `((Newsgroups . ,newsgroups))))
6864 ,@(and distribution (list (cons 'Distribution distribution)))
6866 (not (or (equal (downcase mct) "never")
6867 (equal (downcase mct) "nobody"))))
6868 (list (cons 'Cc (if (or (equal (downcase mct) "always")
6869 (equal (downcase mct) "poster"))
6870 (or mrt reply-to from "")
6875 (defun message-is-yours-p ()
6876 "Non-nil means current article is yours.
6877 If you have added 'cancel-messages to `message-shoot-gnksa-feet', all articles
6878 are yours except those that have Cancel-Lock header not belonging to you.
6879 Instead of shooting GNKSA feet, you should modify `message-alternative-emails'
6880 regexp to match all of yours addresses."
6881 ;; Canlock-logic as suggested by Per Abrahamsen
6882 ;; <abraham@dina.kvl.dk>
6884 ;; IF article has cancel-lock THEN
6885 ;; IF we can verify it THEN
6888 ;; error: cancellock: article is not yours
6890 ;; Use old rules, comparing sender...
6893 (message-narrow-to-head-1)
6894 (if (message-fetch-field "Cancel-Lock")
6895 (if (null (canlock-verify))
6897 (error "Failed to verify Cancel-lock: This article is not yours"))
6900 (message-gnksa-enable-p 'cancel-messages)
6901 (and (setq sender (message-fetch-field "sender"))
6902 (string-equal (downcase sender)
6903 (downcase (message-make-sender))))
6904 ;; Email address in From field equals to our address
6905 (and (setq from (message-fetch-field "from"))
6907 (downcase (car (mail-header-parse-address from)))
6908 (downcase (car (mail-header-parse-address
6909 (message-make-from))))))
6910 ;; Email address in From field matches
6911 ;; 'message-alternative-emails' regexp
6913 message-alternative-emails
6915 message-alternative-emails
6916 (car (mail-header-parse-address from))))))))))
6919 (defun message-cancel-news (&optional arg)
6920 "Cancel an article you posted.
6921 If ARG, allow editing of the cancellation message."
6923 (unless (message-news-p)
6924 (error "This is not a news article; canceling is impossible"))
6925 (let (from newsgroups message-id distribution buf)
6927 ;; Get header info from original article.
6929 (message-narrow-to-head-1)
6930 (setq from (message-fetch-field "from")
6931 newsgroups (message-fetch-field "newsgroups")
6932 message-id (message-fetch-field "message-id" t)
6933 distribution (message-fetch-field "distribution")))
6934 ;; Make sure that this article was written by the user.
6935 (unless (message-is-yours-p)
6936 (error "This article is not yours"))
6937 (when (yes-or-no-p "Do you really want to cancel this article? ")
6938 ;; Make control message.
6941 (setq buf (set-buffer (get-buffer-create " *message cancel*"))))
6943 (insert "Newsgroups: " newsgroups "\n"
6945 "Subject: cmsg cancel " message-id "\n"
6946 "Control: cancel " message-id "\n"
6948 (concat "Distribution: " distribution "\n")
6950 mail-header-separator "\n"
6951 message-cancel-message)
6952 (run-hooks 'message-cancel-hook)
6954 (message "Canceling your article...")
6955 (if (let ((message-syntax-checks
6956 'dont-check-for-anything-just-trust-me))
6957 (funcall message-send-news-function))
6958 (message "Canceling your article...done"))
6959 (kill-buffer buf))))))
6962 (defun message-supersede ()
6963 "Start composing a message to supersede the current message.
6964 This is done simply by taking the old article and adding a Supersedes
6965 header line with the old Message-ID."
6967 (let ((cur (current-buffer)))
6968 ;; Check whether the user owns the article that is to be superseded.
6969 (unless (message-is-yours-p)
6970 (error "This article is not yours"))
6971 ;; Get a normal message buffer.
6972 (message-pop-to-buffer (message-buffer-name "supersede"))
6973 (insert-buffer-substring cur)
6975 (message-narrow-to-head-1)
6976 ;; Remove unwanted headers.
6977 (when message-ignored-supersedes-headers
6978 (message-remove-header message-ignored-supersedes-headers t))
6979 (goto-char (point-min))
6980 (if (not (re-search-forward "^Message-ID: " nil t))
6981 (error "No Message-ID in this article")
6982 (replace-match "Supersedes: " t t))
6983 (goto-char (point-max))
6984 (insert mail-header-separator)
6989 (defun message-recover ()
6990 "Reread contents of current buffer from its last auto-save file."
6992 (let ((file-name (make-auto-save-file-name)))
6993 (cond ((save-window-excursion
6994 (with-output-to-temp-buffer "*Directory*"
6995 (with-current-buffer standard-output
6996 (fundamental-mode)) ; for Emacs 20.4+
6997 (buffer-disable-undo standard-output)
6998 (let ((default-directory "/"))
7000 "ls" nil standard-output nil "-l" file-name)))
7001 (yes-or-no-p (format "Recover auto save file %s? " file-name)))
7002 (let ((buffer-read-only nil))
7004 (insert-file-contents file-name nil)))
7005 (t (error "message-recover cancelled")))))
7007 ;;; Washing Subject:
7009 (defun message-wash-subject (subject)
7010 "Remove junk like \"Re:\", \"(fwd)\", etc. added to subject string SUBJECT.
7011 Previous forwarders, replyers, etc. may add it."
7014 (goto-char (point-min))
7015 ;; strip Re/Fwd stuff off the beginning
7016 (while (re-search-forward
7017 "\\([Rr][Ee]:\\|[Ff][Ww][Dd]\\(\\[[0-9]*\\]\\)?:\\|[Ff][Ww]:\\)" nil t)
7020 ;; and gnus-style forwards [foo@bar.com] subject
7021 (goto-char (point-min))
7022 (while (re-search-forward "\\[[^ \t]*\\(@\\|\\.\\)[^ \t]*\\]" nil t)
7026 (goto-char (point-max))
7027 (while (re-search-backward "([Ff][Ww][Dd])" nil t)
7030 ;; and finally, any whitespace that was left-over
7031 (goto-char (point-min))
7032 (while (re-search-forward "^[ \t]+" nil t)
7034 (goto-char (point-max))
7035 (while (re-search-backward "[ \t]+$" nil t)
7040 ;;; Forwarding messages.
7042 (defvar message-forward-decoded-p nil
7043 "Non-nil means the original message is decoded.")
7045 (defun message-forward-subject-name-subject (subject)
7046 "Generate a SUBJECT for a forwarded message.
7047 The form is: [Source] Subject, where if the original message was mail,
7048 Source is the name of the sender, and if the original message was
7049 news, Source is the list of newsgroups is was posted to."
7050 (let* ((group (message-fetch-field "newsgroups"))
7051 (from (message-fetch-field "from"))
7054 (gnus-group-decoded-name group)
7056 (car (gnus-extract-address-components from))
7057 (cadr (gnus-extract-address-components from))))
7060 (if message-forward-decoded-p
7062 (mail-decode-encoded-word-string prefix))
7065 (defun message-forward-subject-author-subject (subject)
7066 "Generate a SUBJECT for a forwarded message.
7067 The form is: [Source] Subject, where if the original message was mail,
7068 Source is the sender, and if the original message was news, Source is
7069 the list of newsgroups is was posted to."
7070 (let* ((group (message-fetch-field "newsgroups"))
7073 (gnus-group-decoded-name group)
7074 (or (message-fetch-field "from")
7077 (if message-forward-decoded-p
7079 (mail-decode-encoded-word-string prefix))
7082 (defun message-forward-subject-fwd (subject)
7083 "Generate a SUBJECT for a forwarded message.
7084 The form is: Fwd: Subject, where Subject is the original subject of
7086 (if (string-match "^Fwd: " subject)
7088 (concat "Fwd: " subject)))
7090 (defun message-make-forward-subject ()
7091 "Return a Subject header suitable for the message in the current buffer."
7094 (message-narrow-to-head-1)
7095 (let ((funcs message-make-forward-subject-function)
7096 (subject (message-fetch-field "Subject")))
7099 (if message-forward-decoded-p
7101 (mail-decode-encoded-word-string subject))
7103 (when message-wash-forwarded-subjects
7104 (setq subject (message-wash-subject subject)))
7105 ;; Make sure funcs is a list.
7108 (setq funcs (list funcs)))
7109 ;; Apply funcs in order, passing subject generated by previous
7110 ;; func to the next one.
7111 (dolist (func funcs)
7112 (when (functionp func)
7113 (setq subject (funcall func subject))))
7116 (defvar gnus-article-decoded-p)
7120 (defun message-forward (&optional news digest)
7121 "Forward the current message via mail.
7122 Optional NEWS will use news to forward instead of mail.
7123 Optional DIGEST will use digest to forward."
7125 (let* ((cur (current-buffer))
7126 (message-forward-decoded-p
7127 (if (local-variable-p 'gnus-article-decoded-p (current-buffer))
7128 gnus-article-decoded-p ;; In an article buffer.
7129 message-forward-decoded-p))
7130 (subject (message-make-forward-subject)))
7132 (message-news nil subject)
7133 (message-mail nil subject))
7134 (message-forward-make-body cur digest)))
7136 (defun message-forward-make-body-plain (forward-buffer)
7138 "\n-------------------- Start of forwarded message --------------------\n")
7140 (contents (with-current-buffer forward-buffer (buffer-string)))
7142 (unless (featurep 'xemacs)
7143 (unless (mm-multibyte-string-p contents)
7144 (error "Attempt to insert unibyte string from the buffer \"%s\"\
7145 to the multibyte buffer \"%s\""
7146 (if (bufferp forward-buffer)
7147 (buffer-name forward-buffer)
7150 (insert (mm-with-multibyte-buffer
7153 (goto-char (point-min))
7154 (when (looking-at "From ")
7155 (replace-match "X-From-Line: "))
7157 (unless (bolp) (insert "\n"))
7160 "-------------------- End of forwarded message --------------------\n")
7161 (message-remove-ignored-headers b e)))
7163 (defun message-remove-ignored-headers (b e)
7164 (when message-forward-ignored-headers
7166 (narrow-to-region b e)
7168 (narrow-to-region (point)
7169 (or (search-forward "\n\n" nil t) (point)))
7170 (let ((ignored (if (stringp message-forward-ignored-headers)
7171 (list message-forward-ignored-headers)
7172 message-forward-ignored-headers)))
7173 (dolist (elem ignored)
7174 (message-remove-header elem t))))))
7176 (defun message-forward-make-body-mime (forward-buffer)
7178 (insert "\n\n<#part type=message/rfc822 disposition=inline raw=t>\n")
7180 (narrow-to-region (point) (point))
7181 (mml-insert-buffer forward-buffer)
7182 (goto-char (point-min))
7183 (when (looking-at "From ")
7184 (replace-match "X-From-Line: "))
7185 (goto-char (point-max)))
7186 (insert "<#/part>\n")
7187 ;; Consider there is no illegible text.
7188 (add-text-properties
7190 `(no-illegible-text t rear-nonsticky t start-open t))))
7192 (defun message-forward-make-body-mml (forward-buffer)
7193 (insert "\n\n<#mml type=message/rfc822 disposition=inline>\n")
7194 (let ((b (point)) e)
7195 (if (not message-forward-decoded-p)
7196 (let ((contents (with-current-buffer forward-buffer (buffer-string))))
7197 (unless (featurep 'xemacs)
7198 (unless (mm-multibyte-string-p contents)
7199 (error "Attempt to insert unibyte string from the buffer \"%s\"\
7200 to the multibyte buffer \"%s\""
7201 (if (bufferp forward-buffer)
7202 (buffer-name forward-buffer)
7205 (insert (mm-with-multibyte-buffer
7208 (goto-char (point-min))
7209 (when (looking-at "From ")
7210 (replace-match "X-From-Line: "))
7213 (narrow-to-region (point) (point))
7214 (mml-insert-buffer forward-buffer)
7215 (goto-char (point-min))
7216 (when (looking-at "From ")
7217 (replace-match "X-From-Line: "))
7218 (goto-char (point-max))))
7220 (insert "<#/mml>\n")
7221 (when (and (not message-forward-decoded-p)
7222 message-forward-ignored-headers)
7223 (message-remove-ignored-headers b e))))
7225 (defun message-forward-make-body-digest-plain (forward-buffer)
7227 "\n-------------------- Start of forwarded message --------------------\n")
7228 (let ((b (point)) e)
7229 (mml-insert-buffer forward-buffer)
7232 "\n-------------------- End of forwarded message --------------------\n")))
7234 (defun message-forward-make-body-digest-mime (forward-buffer)
7235 (insert "\n<#multipart type=digest>\n")
7236 (let ((b (point)) e)
7237 (insert-buffer-substring forward-buffer)
7239 (insert "<#/multipart>\n")
7241 (narrow-to-region b e)
7243 (narrow-to-region (point)
7244 (or (search-forward "\n\n" nil t) (point)))
7245 (delete-region (point-min) (point-max)))))
7247 (defun message-forward-make-body-digest (forward-buffer)
7248 (if message-forward-as-mime
7249 (message-forward-make-body-digest-mime forward-buffer)
7250 (message-forward-make-body-digest-plain forward-buffer)))
7252 (autoload 'mm-uu-dissect-text-parts "mm-uu")
7253 (autoload 'mm-uu-dissect "mm-uu")
7255 (defun message-signed-or-encrypted-p (&optional dont-emulate-mime handles)
7256 "Say whether the current buffer contains signed or encrypted message.
7257 If DONT-EMULATE-MIME is nil, this function does the MIME emulation on
7258 messages that don't conform to PGP/MIME described in RFC2015. HANDLES
7259 is for the internal use."
7261 (let ((mm-decrypt-option 'never)
7262 (mm-verify-option 'never))
7263 (if (setq handles (mm-dissect-buffer nil t))
7264 (unless dont-emulate-mime
7265 (mm-uu-dissect-text-parts handles))
7266 (unless dont-emulate-mime
7267 (setq handles (mm-uu-dissect))))))
7268 ;; Check text/plain message in which there is a signed or encrypted
7269 ;; body that has been encoded by B or Q.
7270 (unless (or handles dont-emulate-mime)
7271 (let ((cur (current-buffer))
7272 (mm-decrypt-option 'never)
7273 (mm-verify-option 'never))
7275 (insert-buffer-substring cur)
7276 (when (setq handles (mm-dissect-buffer t t))
7278 (bufferp (car handles))
7279 (mm-destroy-parts handles))
7280 (equal (mm-handle-media-type handles) "text/plain"))
7282 (mm-decode-content-transfer-encoding
7283 (mm-handle-encoding handles))
7284 (setq handles (mm-uu-dissect)))
7285 (setq handles nil))))))
7289 (dolist (handle (if (stringp (car handles))
7290 (if (member (car handles)
7291 '("multipart/signed"
7292 "multipart/encrypted"))
7296 (if (stringp (car handle))
7297 (when (message-signed-or-encrypted-p dont-emulate-mime handle)
7299 (when (and (bufferp (car handle))
7300 (equal (mm-handle-media-type handle)
7302 (with-current-buffer (mm-handle-buffer handle)
7303 (when (message-signed-or-encrypted-p dont-emulate-mime)
7304 (throw 'found t)))))))
7305 (mm-destroy-parts handles))))
7308 (defun message-forward-make-body (forward-buffer &optional digest)
7309 ;; Put point where we want it before inserting the forwarded
7311 (if message-forward-before-signature
7313 (goto-char (point-max)))
7315 (message-forward-make-body-digest forward-buffer)
7316 (if message-forward-as-mime
7317 (if (and message-forward-show-mml
7318 (not (and (eq message-forward-show-mml 'best)
7319 ;; Use the raw form in the body if it contains
7320 ;; signed or encrypted message so as not to be
7321 ;; destroyed by re-encoding.
7322 (with-current-buffer forward-buffer
7324 (message-signed-or-encrypted-p)
7326 (message-forward-make-body-mml forward-buffer)
7327 (message-forward-make-body-mime forward-buffer))
7328 (message-forward-make-body-plain forward-buffer)))
7329 (message-position-point))
7331 (declare-function rmail-toggle-header "rmail" (&optional arg))
7334 (defun message-forward-rmail-make-body (forward-buffer)
7335 (save-window-excursion
7336 (set-buffer forward-buffer)
7337 (if (rmail-msg-is-pruned)
7338 (if (fboundp 'rmail-msg-restore-non-pruned-header)
7339 (rmail-msg-restore-non-pruned-header) ; Emacs 22
7340 (rmail-toggle-header 0)))) ; Emacs 23
7341 (message-forward-make-body forward-buffer))
7343 ;; Fixme: Should have defcustom.
7345 (defun message-insinuate-rmail ()
7346 "Let RMAIL use message to forward."
7348 (setq rmail-enable-mime-composing t)
7349 (setq rmail-insert-mime-forwarded-message-function
7350 'message-forward-rmail-make-body))
7353 (defun message-resend (address)
7354 "Resend the current article to ADDRESS."
7356 (list (message-read-from-minibuffer "Resend message to: ")))
7357 (message "Resending message to %s..." address)
7359 (let ((cur (current-buffer))
7361 ;; We first set up a normal mail buffer.
7362 (unless (message-mail-user-agent)
7363 (set-buffer (get-buffer-create " *message resend*"))
7365 (let ((message-this-is-mail t)
7366 message-generate-hashcash
7368 (message-setup `((To . ,address))))
7369 ;; Insert our usual headers.
7370 (message-generate-headers '(From Date To Message-ID))
7371 (message-narrow-to-headers)
7372 ;; Remove X-Draft-From header etc.
7373 (message-remove-header message-ignored-mail-headers t)
7374 ;; Rename them all to "Resent-*".
7375 (goto-char (point-min))
7376 (while (re-search-forward "^[A-Za-z]" nil t)
7381 (delete-region (point) (point-max))
7383 ;; Insert the message to be resent.
7384 (insert-buffer-substring cur)
7385 (goto-char (point-min))
7386 (search-forward "\n\n")
7389 (narrow-to-region beg (point))
7390 (message-remove-header message-ignored-resent-headers t)
7391 (goto-char (point-max)))
7392 (insert mail-header-separator)
7393 ;; Rename all old ("Also-")Resent headers.
7394 (while (re-search-backward "^\\(Also-\\)*Resent-" beg t)
7397 ;; Quote any "From " lines at the beginning.
7399 (when (looking-at "From ")
7400 (replace-match "X-From-Line: "))
7402 (let ((message-inhibit-body-encoding t)
7403 (message-inhibit-ecomplete t)
7404 message-required-mail-headers
7405 message-generate-hashcash
7406 rfc2047-encode-encoded-words)
7407 (message-send-mail))
7408 (kill-buffer (current-buffer)))
7409 (message "Resending message to %s...done" address)))
7412 (defun message-bounce ()
7413 "Re-mail the current message.
7414 This only makes sense if the current message is a bounce message that
7415 contains some mail you have written which has been bounced back to
7418 (let ((handles (mm-dissect-buffer t))
7420 (message-pop-to-buffer (message-buffer-name "bounce"))
7421 (if (stringp (car handles))
7422 ;; This is a MIME bounce.
7423 (mm-insert-part (car (last handles)))
7424 ;; This is a non-MIME bounce, so we try to remove things
7426 (mm-insert-part handles)
7428 (goto-char (point-min))
7429 (re-search-forward "\n\n+" nil t)
7430 (setq boundary (point))
7431 ;; We remove everything before the bounced mail.
7432 (if (or (re-search-forward message-unsent-separator nil t)
7434 (search-forward "\n\n" nil 'move)
7435 (re-search-backward "^Return-Path:.*\n" boundary t)))
7438 (delete-region (point-min)
7439 (if (re-search-forward "^[^ \n\t]+:" nil t)
7442 (goto-char boundary)
7443 (when (re-search-backward "^.?From .*\n" nil t)
7444 (delete-region (match-beginning 0) (match-end 0)))))
7447 (message-narrow-to-head-1)
7448 (message-remove-header message-ignored-bounced-headers t)
7449 (goto-char (point-max))
7450 (insert mail-header-separator))
7451 (message-position-point)))
7454 ;;; Interactive entry points for new message buffers.
7458 (defun message-mail-other-window (&optional to subject)
7459 "Like `message-mail' command, but display mail buffer in another window."
7461 (unless (message-mail-user-agent)
7462 (let ((pop-up-windows t)
7463 (special-display-buffer-names nil)
7464 (special-display-regexps nil)
7465 (same-window-buffer-names nil)
7466 (same-window-regexps nil))
7467 (message-pop-to-buffer (message-buffer-name "mail" to))))
7468 (let ((message-this-is-mail t))
7469 (message-setup `((To . ,(or to "")) (Subject . ,(or subject "")))
7470 nil nil nil 'switch-to-buffer-other-window)))
7473 (defun message-mail-other-frame (&optional to subject)
7474 "Like `message-mail' command, but display mail buffer in another frame."
7476 (unless (message-mail-user-agent)
7477 (let ((pop-up-frames t)
7478 (special-display-buffer-names nil)
7479 (special-display-regexps nil)
7480 (same-window-buffer-names nil)
7481 (same-window-regexps nil))
7482 (message-pop-to-buffer (message-buffer-name "mail" to))))
7483 (let ((message-this-is-mail t))
7484 (message-setup `((To . ,(or to "")) (Subject . ,(or subject "")))
7485 nil nil nil 'switch-to-buffer-other-frame)))
7488 (defun message-news-other-window (&optional newsgroups subject)
7489 "Start editing a news article to be sent."
7491 (let ((pop-up-windows t)
7492 (special-display-buffer-names nil)
7493 (special-display-regexps nil)
7494 (same-window-buffer-names nil)
7495 (same-window-regexps nil))
7496 (message-pop-to-buffer (message-buffer-name "posting" nil newsgroups)))
7497 (let ((message-this-is-news t))
7498 (message-setup `((Newsgroups . ,(or newsgroups ""))
7499 (Subject . ,(or subject ""))))))
7502 (defun message-news-other-frame (&optional newsgroups subject)
7503 "Start editing a news article to be sent."
7505 (let ((pop-up-frames t)
7506 (special-display-buffer-names nil)
7507 (special-display-regexps nil)
7508 (same-window-buffer-names nil)
7509 (same-window-regexps nil))
7510 (message-pop-to-buffer (message-buffer-name "posting" nil newsgroups)))
7511 (let ((message-this-is-news t))
7512 (message-setup `((Newsgroups . ,(or newsgroups ""))
7513 (Subject . ,(or subject ""))))))
7517 ;; This code should be moved to underline.el (from which it is stolen).
7520 (defun message-bold-region (start end)
7521 "Bold all nonblank characters in the region.
7522 Works by overstriking characters.
7523 Called from program, takes two arguments START and END
7524 which specify the range to operate on."
7527 (let ((end1 (make-marker)))
7528 (move-marker end1 (max start end))
7529 (goto-char (min start end))
7530 (while (< (point) end1)
7531 (or (looking-at "[_\^@- ]")
7532 (insert (char-after) "\b"))
7533 (forward-char 1)))))
7536 (defun message-unbold-region (start end)
7537 "Remove all boldness (overstruck characters) in the region.
7538 Called from program, takes two arguments START and END
7539 which specify the range to operate on."
7542 (let ((end1 (make-marker)))
7543 (move-marker end1 (max start end))
7544 (goto-char (min start end))
7545 (while (search-forward "\b" end1 t)
7546 (if (eq (char-after) (char-after (- (point) 2)))
7547 (delete-char -2))))))
7549 (defun message-exchange-point-and-mark ()
7550 "Exchange point and mark, but don't activate region if it was inactive."
7551 (goto-char (prog1 (mark t)
7552 (set-marker (mark-marker) (point)))))
7554 (defalias 'message-make-overlay 'make-overlay)
7555 (defalias 'message-delete-overlay 'delete-overlay)
7556 (defalias 'message-overlay-put 'overlay-put)
7557 (defun message-kill-all-overlays ()
7558 (if (featurep 'xemacs)
7559 (map-extents (lambda (extent ignore) (delete-extent extent)))
7560 (mapcar #'delete-overlay (overlays-in (point-min) (point-max)))))
7562 ;; Support for toolbar
7563 (defvar tool-bar-mode)
7565 ;; Note: The :set function in the `message-tool-bar*' variables will only
7566 ;; affect _new_ message buffers. We might add a function that walks thru all
7567 ;; message-mode buffers and force the update.
7568 (defun message-tool-bar-update (&optional symbol value)
7569 "Update message mode toolbar.
7570 Setter function for custom variables."
7571 (setq-default message-tool-bar-map nil)
7573 ;; When used as ":set" function:
7574 (set-default symbol value)))
7576 (defcustom message-tool-bar (if (eq gmm-tool-bar-style 'gnome)
7577 'message-tool-bar-gnome
7578 'message-tool-bar-retro)
7579 "Specifies the message mode tool bar.
7581 It can be either a list or a symbol refering to a list. See
7582 `gmm-tool-bar-from-list' for the format of the list. The
7583 default key map is `message-mode-map'.
7585 Pre-defined symbols include `message-tool-bar-gnome' and
7586 `message-tool-bar-retro'."
7587 :type '(repeat gmm-tool-bar-list-item)
7588 :type '(choice (const :tag "GNOME style" message-tool-bar-gnome)
7589 (const :tag "Retro look" message-tool-bar-retro)
7590 (repeat :tag "User defined list" gmm-tool-bar-item)
7592 :version "23.1" ;; No Gnus
7593 :initialize 'custom-initialize-default
7594 :set 'message-tool-bar-update
7597 (defcustom message-tool-bar-gnome
7598 '((ispell-message "spell" nil
7599 :visible (or (not (boundp 'flyspell-mode))
7600 (not flyspell-mode)))
7601 (flyspell-buffer "spell" t
7602 :visible (and (boundp 'flyspell-mode)
7604 :help "Flyspell whole buffer")
7605 (gmm-ignore "separator")
7606 (message-send-and-exit "mail/send")
7607 (message-dont-send "mail/save-draft")
7608 (message-kill-buffer "close") ;; stock_cancel
7609 (mml-attach-file "attach" mml-mode-map)
7610 (mml-preview "mail/preview" mml-mode-map)
7611 (mml-secure-message-sign-encrypt "lock" mml-mode-map :visible nil)
7612 (message-insert-importance-high "important" nil :visible nil)
7613 (message-insert-importance-low "unimportant" nil :visible nil)
7614 (message-insert-disposition-notification-to "receipt" nil :visible nil)
7615 (gmm-customize-mode "preferences" t :help "Edit mode preferences")
7616 (message-info "help" t :help "Message manual"))
7617 "List of items for the message tool bar (GNOME style).
7619 See `gmm-tool-bar-from-list' for details on the format of the list."
7620 :type '(repeat gmm-tool-bar-item)
7621 :version "23.1" ;; No Gnus
7622 :initialize 'custom-initialize-default
7623 :set 'message-tool-bar-update
7626 (defcustom message-tool-bar-retro
7627 '(;; Old Emacs 21 icon for consistency.
7628 (message-send-and-exit "gnus/mail-send")
7629 (message-kill-buffer "close")
7630 (message-dont-send "cancel")
7631 (mml-attach-file "attach" mml-mode-map)
7632 (ispell-message "spell")
7633 (mml-preview "preview" mml-mode-map)
7634 (message-insert-importance-high "gnus/important")
7635 (message-insert-importance-low "gnus/unimportant")
7636 (message-insert-disposition-notification-to "gnus/receipt"))
7637 "List of items for the message tool bar (retro style).
7639 See `gmm-tool-bar-from-list' for details on the format of the list."
7640 :type '(repeat gmm-tool-bar-item)
7641 :version "23.1" ;; No Gnus
7642 :initialize 'custom-initialize-default
7643 :set 'message-tool-bar-update
7646 (defcustom message-tool-bar-zap-list
7647 '(new-file open-file dired kill-buffer write-file
7648 print-buffer customize help)
7649 "List of icon items from the global tool bar.
7650 These items are not displayed on the message mode tool bar.
7652 See `gmm-tool-bar-from-list' for the format of the list."
7653 :type 'gmm-tool-bar-zap-list
7654 :version "23.1" ;; No Gnus
7655 :initialize 'custom-initialize-default
7656 :set 'message-tool-bar-update
7659 (defvar image-load-path)
7661 (defun message-make-tool-bar (&optional force)
7662 "Make a message mode tool bar from `message-tool-bar-list'.
7663 When FORCE, rebuild the tool bar."
7664 (when (and (not (featurep 'xemacs))
7665 (boundp 'tool-bar-mode)
7667 (or (not message-tool-bar-map) force))
7668 (setq message-tool-bar-map
7670 (gmm-image-load-path-for-library "message"
7671 "mail/save-draft.xpm"
7673 (image-load-path (cons (car load-path)
7674 (when (boundp 'image-load-path)
7676 (gmm-tool-bar-from-list message-tool-bar
7677 message-tool-bar-zap-list
7678 'message-mode-map))))
7679 message-tool-bar-map)
7681 ;;; Group name completion.
7683 (defcustom message-newgroups-header-regexp
7684 "^\\(Newsgroups\\|Followup-To\\|Posted-To\\|Gcc\\):"
7685 "Regexp that match headers that lists groups."
7689 (defcustom message-completion-alist
7690 (list (cons message-newgroups-header-regexp 'message-expand-group)
7691 '("^\\(Resent-\\)?\\(To\\|B?Cc\\):" . message-expand-name)
7692 '("^\\(Reply-To\\|From\\|Mail-Followup-To\\|Mail-Copies-To\\):"
7693 . message-expand-name)
7694 '("^\\(Disposition-Notification-To\\|Return-Receipt-To\\):"
7695 . message-expand-name))
7696 "Alist of (RE . FUN). Use FUN for completion on header lines matching RE."
7699 :type '(alist :key-type regexp :value-type function))
7701 (defcustom message-expand-name-databases
7703 "List of databases to try for name completion (`message-expand-name').
7704 Each element is a symbol and can be `bbdb' or `eudc'."
7706 :type '(set (const bbdb) (const eudc)))
7708 (defcustom message-tab-body-function nil
7709 "*Function to execute when `message-tab' (TAB) is executed in the body.
7710 If nil, the function bound in `text-mode-map' or `global-map' is executed."
7713 :link '(custom-manual "(message)Various Commands")
7714 :type '(choice (const nil)
7717 (declare-function mail-abbrev-in-expansion-header-p "mailabbrev" ())
7719 (defun message-tab ()
7720 "Complete names according to `message-completion-alist'.
7721 Execute function specified by `message-tab-body-function' when not in
7724 (let ((alist message-completion-alist))
7726 (let ((mail-abbrev-mode-regexp (caar alist)))
7727 (not (mail-abbrev-in-expansion-header-p))))
7728 (setq alist (cdr alist)))
7729 (funcall (or (cdar alist) message-tab-body-function
7730 (lookup-key text-mode-map "\t")
7731 (lookup-key global-map "\t")
7732 'indent-relative))))
7737 (let ((standard-output (current-buffer)))
7738 (eval '(display-completion-list nil "")))
7739 (defalias 'message-display-completion-list 'display-completion-list))
7740 (error ;; Don't use `wrong-number-of-arguments' here because of XEmacs.
7741 (defun message-display-completion-list (completions &optional ignore)
7742 "Display the list of completions, COMPLETIONS, using `standard-output'."
7743 (display-completion-list completions)))))
7745 (defun message-expand-group ()
7746 "Expand the group name under point."
7747 (let* ((b (save-excursion
7752 (skip-chars-forward "^:")
7755 (skip-chars-backward "^, \t\n") (point))))
7756 (completion-ignore-case t)
7757 (e (progn (skip-chars-forward "^,\t\n ") (point)))
7758 (hashtb (and (boundp 'gnus-active-hashtb) gnus-active-hashtb)))
7759 (message-completion-in-region e b hashtb)))
7761 (defalias 'message-completion-in-region
7762 (if (fboundp 'completion-in-region)
7763 'completion-in-region
7764 (lambda (e b hashtb)
7765 (let* ((string (buffer-substring b e))
7766 (completions (all-completions string hashtb))
7768 (delete-region b (point))
7770 ((= (length completions) 1)
7771 (if (string= (car completions) string)
7774 (message "Only matching group"))
7775 (insert (car completions))))
7776 ((and (setq comp (try-completion string hashtb))
7777 (not (string= comp string)))
7782 (message "No matching groups")
7783 (save-selected-window
7784 (pop-to-buffer "*Completions*")
7785 (buffer-disable-undo)
7786 (let ((buffer-read-only nil))
7788 (let ((standard-output (current-buffer)))
7789 (message-display-completion-list (sort completions 'string<)
7791 (setq buffer-read-only nil)
7792 (goto-char (point-min))
7793 (delete-region (point)
7794 (progn (forward-line 3) (point))))))))))))
7796 (defun message-expand-name ()
7797 (cond ((and (memq 'eudc message-expand-name-databases)
7798 (boundp 'eudc-protocol)
7800 (eudc-expand-inline))
7801 ((and (memq 'bbdb message-expand-name-databases)
7802 (fboundp 'bbdb-complete-name))
7803 (bbdb-complete-name))
7809 (defun message-talkative-question (ask question show &rest text)
7810 "Call FUNCTION with argument QUESTION; optionally display TEXT... args.
7811 If SHOW is non-nil, the arguments TEXT... are displayed in a temp buffer.
7812 The following arguments may contain lists of values."
7814 (setq text (message-flatten-list text)))
7815 (save-window-excursion
7816 (with-output-to-temp-buffer " *MESSAGE information message*"
7817 (with-current-buffer " *MESSAGE information message*"
7818 (fundamental-mode) ; for Emacs 20.4+
7820 (goto-char (point-min))))
7821 (funcall ask question))
7822 (funcall ask question)))
7824 (defun message-flatten-list (list)
7825 "Return a new, flat list that contains all elements of LIST.
7827 \(message-flatten-list '(1 (2 3 (4 5 (6))) 7))
7830 (apply 'append (mapcar 'message-flatten-list list)))
7834 (defun message-generate-new-buffer-clone-locals (name &optional varstr)
7835 "Create and return a buffer with name based on NAME using `generate-new-buffer'.
7836 Then clone the local variables and values from the old buffer to the
7837 new one, cloning only the locals having a substring matching the
7839 (let ((oldbuf (current-buffer)))
7840 (with-current-buffer (generate-new-buffer name)
7841 (message-clone-locals oldbuf varstr)
7844 (defun message-clone-locals (buffer &optional varstr)
7845 "Clone the local variables from BUFFER to the current buffer."
7846 (let ((locals (with-current-buffer buffer (buffer-local-variables)))
7847 (regexp "^gnus\\|^nn\\|^message\\|^sendmail\\|^smtp\\|^user-mail-address"))
7850 (when (and (consp local)
7852 (string-match regexp (symbol-name (car local)))
7854 (string-match varstr (symbol-name (car local)))))
7856 (set (make-local-variable (car local))
7864 (defvar message-inhibit-body-encoding nil)
7866 (defun message-encode-message-body ()
7867 (unless message-inhibit-body-encoding
7868 (let ((mail-parse-charset (or mail-parse-charset
7869 message-default-charset))
7870 (case-fold-search t)
7871 lines content-type-p)
7874 (narrow-to-region (point) (point-max))
7875 (let ((new (mml-generate-mime)))
7877 (delete-region (point-min) (point-max))
7879 (goto-char (point-min))
7880 (if (eq (aref new 0) ?\n)
7882 (search-forward "\n\n")
7883 (setq lines (buffer-substring (point-min) (1- (point))))
7884 (delete-region (point-min) (point))))))
7886 (message-narrow-to-headers-or-head)
7887 (message-remove-header "Mime-Version")
7888 (goto-char (point-max))
7889 (insert "MIME-Version: 1.0\n")
7892 (setq content-type-p
7894 (re-search-backward "^Content-Type:" nil t))))
7896 (message-narrow-to-headers-or-head)
7897 (message-remove-first-header "Content-Type")
7898 (message-remove-first-header "Content-Transfer-Encoding"))
7899 ;; We always make sure that the message has a Content-Type
7900 ;; header. This is because some broken MTAs and MUAs get
7901 ;; awfully confused when confronted with a message with a
7902 ;; MIME-Version header and without a Content-Type header. For
7903 ;; instance, Solaris' /usr/bin/mail.
7904 (unless content-type-p
7905 (goto-char (point-min))
7906 ;; For unknown reason, MIME-Version doesn't exist.
7907 (when (re-search-forward "^MIME-Version:" nil t)
7909 (insert "Content-Type: text/plain; charset=us-ascii\n"))))))
7911 (defun message-read-from-minibuffer (prompt &optional initial-contents)
7912 "Read from the minibuffer while providing abbrev expansion."
7913 (if (fboundp 'mail-abbrevs-setup)
7914 (let ((mail-abbrev-mode-regexp "")
7915 (minibuffer-setup-hook 'mail-abbrevs-setup)
7916 (minibuffer-local-map message-minibuffer-local-map))
7917 (read-from-minibuffer prompt initial-contents))
7918 (let ((minibuffer-setup-hook 'mail-abbrev-minibuffer-setup-hook)
7919 (minibuffer-local-map message-minibuffer-local-map))
7920 (read-string prompt initial-contents))))
7922 (defun message-use-alternative-email-as-from ()
7923 "Set From field of the outgoing message to the first matching
7924 address in `message-alternative-emails', looking at To, Cc and
7925 From headers in the original article."
7926 (require 'mail-utils)
7927 (let* ((fields '("To" "Cc" "From"))
7930 (mail-strip-quoted-names
7931 (mapconcat 'message-fetch-reply-field fields ","))
7935 (if (string-match message-alternative-emails (car emails))
7936 (setq email (car emails)
7939 (unless (or (not email) (equal email user-mail-address))
7940 (message-remove-header "From")
7941 (goto-char (point-max))
7942 (insert "From: " (let ((user-mail-address email)) (message-make-from))
7945 (defun message-options-get (symbol)
7946 (cdr (assq symbol message-options)))
7948 (defun message-options-set (symbol value)
7949 (let ((the-cons (assq symbol message-options)))
7952 (setcdr the-cons value)
7953 (setq message-options (delq the-cons message-options)))
7955 (push (cons symbol value) message-options))))
7958 (defun message-options-set-recipient ()
7960 (message-narrow-to-headers-or-head)
7961 (message-options-set 'message-sender
7962 (mail-strip-quoted-names
7963 (message-fetch-field "from")))
7964 (message-options-set 'message-recipients
7965 (mail-strip-quoted-names
7966 (let ((to (message-fetch-field "to"))
7967 (cc (message-fetch-field "cc"))
7968 (bcc (message-fetch-field "bcc")))
7971 (if (and to cc) ", ")
7973 (if (and (or to cc) bcc) ", ")
7976 (defun message-hide-headers ()
7977 "Hide headers based on the `message-hidden-headers' variable."
7978 (let ((regexps (if (stringp message-hidden-headers)
7979 (list message-hidden-headers)
7980 message-hidden-headers))
7981 (inhibit-point-motion-hooks t)
7982 (after-change-functions nil)
7983 (end-of-headers (point-min)))
7987 (message-narrow-to-headers)
7988 (goto-char (point-min))
7990 (if (not (message-hide-header-p regexps))
7991 (message-next-header)
7992 (let ((begin (point))
7994 (message-next-header)
7995 (setq header (buffer-substring begin (point))
7996 header-len (- (point) begin))
7997 (delete-region begin (point))
7998 (goto-char end-of-headers)
8000 (setq end-of-headers
8001 (+ end-of-headers header-len))))))))
8002 (narrow-to-region end-of-headers (point-max))))
8004 (defun message-hide-header-p (regexps)
8007 (when (eq (car regexps) 'not)
8010 (dolist (regexp regexps)
8011 (setq result (or result (looking-at regexp))))
8016 (declare-function ecomplete-add-item "ecomplete" (type key text))
8017 (declare-function ecomplete-save "ecomplete" ())
8019 (defun message-put-addresses-in-ecomplete ()
8020 (require 'ecomplete)
8021 (dolist (header '("to" "cc" "from" "reply-to"))
8022 (let ((value (message-field-value header)))
8023 (dolist (string (mail-header-parse-addresses value 'raw))
8025 (gnus-replace-in-string
8026 (gnus-replace-in-string string "^ +\\| +$" "") "\n" ""))
8027 (ecomplete-add-item 'mail (car (mail-header-parse-address string))
8031 (autoload 'ecomplete-display-matches "ecomplete")
8033 (defun message-display-abbrev (&optional choose)
8034 "Display the next possible abbrev for the text before point."
8035 (interactive (list t))
8036 (when (and (memq (char-after (point-at-bol)) '(?C ?T ?\t ? ))
8037 (message-point-in-header-p)
8040 (while (and (memq (char-after) '(?\t ? ))
8041 (zerop (forward-line -1))))
8042 (looking-at "To:\\|Cc:")))
8043 (let* ((end (point))
8044 (start (save-excursion
8045 (and (re-search-backward "[\n\t ]" nil t)
8047 (word (when start (buffer-substring start end)))
8048 (match (when (and word
8049 (not (zerop (length word))))
8050 (ecomplete-display-matches 'mail word choose))))
8051 (when (and choose match)
8052 (delete-region start end)
8055 ;; To send pre-formatted letters like the example below, you can use
8056 ;; `message-send-form-letter':
8057 ;; --8<---------------cut here---------------start------------->8---
8058 ;; To: alice@invalid.invalid
8059 ;; Subject: Verification of your contact information
8060 ;; From: Contact verification <admin@foo.invalid>
8061 ;; --text follows this line--
8063 ;; please verify that your contact information is still valid:
8064 ;; Alice A, A avenue 11, 1111 A town, Austria
8065 ;; ----------next form letter message follows this line----------
8066 ;; To: bob@invalid.invalid
8067 ;; Subject: Verification of your contact information
8068 ;; From: Contact verification <admin@foo.invalid>
8069 ;; --text follows this line--
8071 ;; please verify that your contact information is still valid:
8072 ;; Bob, B street 22, 22222 Be town, Belgium
8073 ;; ----------next form letter message follows this line----------
8074 ;; To: charlie@invalid.invalid
8075 ;; Subject: Verification of your contact information
8076 ;; From: Contact verification <admin@foo.invalid>
8077 ;; --text follows this line--
8079 ;; please verify that your contact information is still valid:
8080 ;; Charlie Chaplin, C plaza 33, 33333 C town, Chile
8081 ;; --8<---------------cut here---------------end--------------->8---
8083 ;; FIXME: What is the most common term (circular letter, form letter, serial
8084 ;; letter, standard letter) for such kind of letter? See also
8085 ;; <http://en.wikipedia.org/wiki/Form_letter>
8087 ;; FIXME: Maybe extent message-mode's font-lock support to recognize
8088 ;; `message-form-letter-separator', i.e. highlight each message like a single
8091 (defcustom message-form-letter-separator
8092 "\n----------next form letter message follows this line----------\n"
8093 "Separator for `message-send-form-letter'."
8094 ;; :group 'message-form-letter
8095 :group 'message-various
8096 :version "23.1" ;; No Gnus
8099 (defcustom message-send-form-letter-delay 1
8100 "Delay in seconds when sending a message with `message-send-form-letter'.
8101 Only used when `message-send-form-letter' is called with non-nil
8103 ;; :group 'message-form-letter
8104 :group 'message-various
8105 :version "23.1" ;; No Gnus
8108 (defun message-send-form-letter (&optional force)
8109 "Sent all form letter messages from current buffer.
8110 Unless FORCE, prompt before sending.
8112 The messages are separated by `message-form-letter-separator'.
8113 Header and body are separated by `mail-header-separator'."
8115 (let ((sent 0) (skipped 0)
8119 (goto-char (point-min))
8122 end (if (search-forward message-form-letter-separator nil t)
8123 (- (point) (length message-form-letter-separator) -1)
8127 (buffer-substring-no-properties start end))
8128 (setq buff (generate-new-buffer "*mail - form letter*"))
8129 (with-current-buffer buff
8132 (setq to (message-fetch-field "To"))
8133 (switch-to-buffer buff)
8135 (sit-for message-send-form-letter-delay))
8137 (y-or-n-p (format "Send message to `%s'? " to)))
8139 (setq sent (1+ sent))
8140 (message-send-and-exit))
8141 (message (format "Message to `%s' skipped." to))
8142 (setq skipped (1+ skipped)))
8143 (when (buffer-live-p buff)
8144 (kill-buffer buff))))
8145 (message "%s message(s) sent, %s skipped." sent skipped)))
8147 (defun message-replace-header (header new-value &optional after force)
8148 "Remove HEADER and insert the NEW-VALUE.
8149 If AFTER, insert after this header. If FORCE, insert new field
8150 even if NEW-VALUE is empty."
8151 ;; Similar to `nnheader-replace-header' but for message buffers.
8154 (message-narrow-to-headers)
8155 (message-remove-header header))
8156 (when (or force (> (length new-value) 0))
8158 (message-position-on-field header after)
8159 (message-position-on-field header))
8160 (insert new-value))))
8162 (defcustom message-recipients-without-full-name
8163 (list "ding@gnus.org"
8165 "emacs-devel@gnu.org"
8166 "emacs-pretest-bug@gnu.org"
8167 "bug-gnu-emacs@gnu.org")
8168 "Mail addresses that have no full name.
8169 Used in `message-simplify-recipients'."
8170 ;; Maybe the addresses could be extracted from
8171 ;; `gnus-parameter-to-list-alist'?
8172 :type '(choice (const :tag "None" nil)
8174 :version "23.1" ;; No Gnus
8175 :group 'message-headers)
8177 (defun message-simplify-recipients ()
8179 (dolist (hdr '("Cc" "To"))
8180 (message-replace-header
8184 (if (and message-recipients-without-full-name
8186 (regexp-opt message-recipients-without-full-name)
8190 (message-make-from (car addrcomp) (cadr addrcomp))
8192 (when (message-fetch-field hdr)
8193 (mail-extract-address-components
8194 (message-fetch-field hdr) t))
8197 (when (featurep 'xemacs)
8198 (require 'messagexmas)
8199 (message-xmas-redefine))
8203 (run-hooks 'message-load-hook)
8206 ;; coding: iso-8859-1
8209 ;; arch-tag: 94b32cac-4504-4b6c-8181-030ebf380ee0
8210 ;;; message.el ends here