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 1000000
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)
1716 ;; Byte-compiler warning
1717 (defvar gnus-active-hashtb)
1718 (defvar gnus-read-active-file)
1720 ;;; Regexp matching the delimiter of messages in UNIX mail format
1721 ;;; (UNIX From lines), minus the initial ^. It should be a copy
1722 ;;; of rmail.el's rmail-unix-mail-delimiter.
1723 (defvar message-unix-mail-delimiter
1724 (let ((time-zone-regexp
1725 (concat "\\([A-Z]?[A-Z]?[A-Z][A-Z]\\( DST\\)?"
1726 "\\|[-+]?[0-9][0-9][0-9][0-9]"
1732 ;; Many things can happen to an RFC 822 mailbox before it is put into
1733 ;; a `From' line. The leading phrase can be stripped, e.g.
1734 ;; `Joe <@w.x:joe@y.z>' -> `<@w.x:joe@y.z>'. The <> can be stripped, e.g.
1735 ;; `<@x.y:joe@y.z>' -> `@x.y:joe@y.z'. Everything starting with a CRLF
1736 ;; can be removed, e.g.
1737 ;; From: joe@y.z (Joe K
1739 ;; can yield `From joe@y.z (Joe K Fri Mar 22 08:11:15 1996', and
1742 ;; can yield `From Joe User Fri Mar 22 08:11:15 1996'.
1743 ;; The mailbox can be removed or be replaced by white space, e.g.
1744 ;; From: "Joe User"{space}{tab}
1746 ;; can yield `From {space}{tab} Fri Mar 22 08:11:15 1996',
1747 ;; where {space} and {tab} represent the Ascii space and tab characters.
1748 ;; We want to match the results of any of these manglings.
1749 ;; The following regexp rejects names whose first characters are
1750 ;; obviously bogus, but after that anything goes.
1751 "\\([^\0-\b\n-\r\^?].*\\)?"
1753 ;; The time the message was sent.
1754 "\\([^\0-\r \^?]+\\) +" ; day of the week
1755 "\\([^\0-\r \^?]+\\) +" ; month
1756 "\\([0-3]?[0-9]\\) +" ; day of month
1757 "\\([0-2][0-9]:[0-5][0-9]\\(:[0-6][0-9]\\)?\\) *" ; time of day
1759 ;; Perhaps a time zone, specified by an abbreviation, or by a
1764 " \\([0-9][0-9]+\\) *"
1766 ;; On some systems the time zone can appear after the year, too.
1770 "\\(remote from .*\\)?"
1773 "Regexp matching the delimiter of messages in UNIX mail format.")
1775 (defvar message-unsent-separator
1776 (concat "^ *---+ +Unsent message follows +---+ *$\\|"
1777 "^ *---+ +Returned message +---+ *$\\|"
1778 "^Start of returned message$\\|"
1779 "^ *---+ +Original message +---+ *$\\|"
1780 "^ *--+ +begin message +--+ *$\\|"
1781 "^ *---+ +Original message follows +---+ *$\\|"
1782 "^ *---+ +Undelivered message follows +---+ *$\\|"
1783 "^------ This is a copy of the message, including all the headers. ------ *$\\|"
1784 "^|? *---+ +Message text follows: +---+ *|?$")
1785 "A regexp that matches the separator before the text of a failed message.")
1787 (defvar message-field-fillers
1788 '((To message-fill-field-address)
1789 (Cc message-fill-field-address)
1790 (From message-fill-field-address))
1791 "Alist of header names/filler functions.")
1793 (defvar message-header-format-alist
1808 (References . message-shorten-references)
1810 "Alist used for formatting headers.")
1812 (defvar message-options nil
1813 "Some saved answers when sending message.")
1815 (defvar message-send-mail-real-function nil
1816 "Internal send mail function.")
1818 (defvar message-bogus-system-names "^localhost\\.\\|\\.local$"
1819 "The regexp of bogus system names.")
1821 (defcustom message-valid-fqdn-regexp
1822 (concat "[a-z0-9][-.a-z0-9]+\\." ;; [hostname.subdomain.]domain.
1824 "\\([a-z][a-z]\\|" ;; two letter country TDLs
1825 "aero\\|arpa\\|bitnet\\|biz\\|bofh\\|"
1826 "cat\\|com\\|coop\\|edu\\|gov\\|"
1827 "info\\|int\\|jobs\\|"
1828 "mil\\|mobi\\|museum\\|name\\|net\\|"
1829 "org\\|pro\\|travel\\|uucp\\)")
1830 ;; http://en.wikipedia.org/wiki/List_of_Internet_top-level_domains
1831 ;; http://en.wikipedia.org/wiki/GTLD
1832 ;; `in the process of being approved': .asia .post .tel .sex
1833 ;; "dead" nato bitnet uucp
1834 "Regular expression that matches a valid FQDN."
1835 ;; see also: gnus-button-valid-fqdn-regexp
1837 :group 'message-headers
1840 (autoload 'gnus-alive-p "gnus-util")
1841 (autoload 'gnus-delay-article "gnus-delay")
1842 (autoload 'gnus-extract-address-components "gnus-util")
1843 (autoload 'gnus-find-method-for-group "gnus")
1844 (autoload 'gnus-group-decoded-name "gnus-group")
1845 (autoload 'gnus-group-name-charset "gnus-group")
1846 (autoload 'gnus-group-name-decode "gnus-group")
1847 (autoload 'gnus-groups-from-server "gnus")
1848 (autoload 'gnus-make-local-hook "gnus-util")
1849 (autoload 'gnus-open-server "gnus-int")
1850 (autoload 'gnus-output-to-mail "gnus-util")
1851 (autoload 'gnus-output-to-rmail "gnus-util")
1852 (autoload 'gnus-request-post "gnus-int")
1853 (autoload 'gnus-select-frame-set-input-focus "gnus-util")
1854 (autoload 'gnus-server-string "gnus")
1855 (autoload 'idna-to-ascii "idna")
1856 (autoload 'message-setup-toolbar "messagexmas")
1857 (autoload 'mh-new-draft-name "mh-comp")
1858 (autoload 'mh-send-letter "mh-comp")
1859 (autoload 'nndraft-request-associate-buffer "nndraft")
1860 (autoload 'nndraft-request-expire-articles "nndraft")
1861 (autoload 'nnvirtual-find-group-art "nnvirtual")
1862 (autoload 'rmail-dont-reply-to "mail-utils")
1863 (autoload 'rmail-msg-is-pruned "rmail")
1864 (autoload 'rmail-output "rmailout")
1869 ;;; Utility functions.
1872 (defmacro message-y-or-n-p (question show &rest text)
1873 "Ask QUESTION, displaying remaining args in a temporary buffer if SHOW."
1874 `(message-talkative-question 'y-or-n-p ,question ,show ,@text))
1876 (defmacro message-delete-line (&optional n)
1877 "Delete the current line (and the next N lines)."
1878 `(delete-region (progn (beginning-of-line) (point))
1879 (progn (forward-line ,(or n 1)) (point))))
1881 (defun message-mark-active-p ()
1882 "Non-nil means the mark and region are currently active in this buffer."
1885 (defun message-unquote-tokens (elems)
1886 "Remove double quotes (\") from strings in list ELEMS."
1887 (mapcar (lambda (item)
1888 (while (string-match "^\\(.*\\)\"\\(.*\\)$" item)
1889 (setq item (concat (match-string 1 item)
1890 (match-string 2 item))))
1894 (defun message-tokenize-header (header &optional separator)
1895 "Split HEADER into a list of header elements.
1896 SEPARATOR is a string of characters to be used as separators. \",\"
1897 is used by default."
1900 (let ((regexp (format "[%s]+" (or separator ",")))
1902 beg quoted elems paren)
1904 (mm-enable-multibyte)
1905 (setq beg (point-min))
1907 (goto-char (point-min))
1912 (cond ((and (> (point) beg)
1914 (and (looking-at regexp)
1917 (push (buffer-substring beg (point)) elems)
1918 (setq beg (match-end 0)))
1919 ((eq (char-after) ?\")
1920 (setq quoted (not quoted)))
1921 ((and (eq (char-after) ?\()
1924 ((and (eq (char-after) ?\))
1927 (nreverse elems)))))
1929 (autoload 'nnheader-insert-file-contents "nnheader")
1931 (defun message-mail-file-mbox-p (file)
1932 "Say whether FILE looks like a Unix mbox file."
1933 (when (and (file-exists-p file)
1934 (file-readable-p file)
1935 (file-regular-p file))
1937 (nnheader-insert-file-contents file)
1938 (goto-char (point-min))
1939 (looking-at message-unix-mail-delimiter))))
1941 (defun message-fetch-field (header &optional not-all)
1942 "The same as `mail-fetch-field', only remove all newlines.
1943 The buffer is expected to be narrowed to just the header of the message;
1944 see `message-narrow-to-headers-or-head'."
1945 (let* ((inhibit-point-motion-hooks t)
1946 (value (mail-fetch-field header nil (not not-all))))
1948 (while (string-match "\n[\t ]+" value)
1949 (setq value (replace-match " " t t value)))
1952 (defun message-field-value (header &optional not-all)
1953 "The same as `message-fetch-field', only narrow to the headers first."
1956 (message-narrow-to-headers-or-head)
1957 (message-fetch-field header not-all))))
1959 (defun message-narrow-to-field ()
1960 "Narrow the buffer to the header on the current line."
1962 (while (looking-at "[ \t]")
1968 (if (re-search-forward "^[^ \n\t]" nil t)
1971 (goto-char (point-min)))
1973 (defun message-add-header (&rest headers)
1974 "Add the HEADERS to the message header, skipping those already present."
1977 (unless (string-match "^\\([^:]+\\):[ \t]*[^ \t]" (car headers))
1978 (error "Invalid header `%s'" (car headers)))
1979 (setq hclean (match-string 1 (car headers)))
1981 (message-narrow-to-headers)
1982 (unless (re-search-forward (concat "^" (regexp-quote hclean) ":") nil t)
1983 (goto-char (point-max))
1984 (if (string-match "\n$" (car headers))
1985 (insert (car headers))
1986 (insert (car headers) ?\n)))))
1987 (setq headers (cdr headers))))
1989 (defmacro message-with-reply-buffer (&rest forms)
1990 "Evaluate FORMS in the reply buffer, if it exists."
1991 `(when (and (bufferp message-reply-buffer)
1992 (buffer-name message-reply-buffer))
1993 (with-current-buffer message-reply-buffer
1996 (put 'message-with-reply-buffer 'lisp-indent-function 0)
1997 (put 'message-with-reply-buffer 'edebug-form-spec '(body))
1999 (defun message-fetch-reply-field (header)
2000 "Fetch field HEADER from the message we're replying to."
2001 (message-with-reply-buffer
2003 (mail-narrow-to-head)
2004 (message-fetch-field header))))
2006 (defun message-strip-list-identifiers (subject)
2007 "Remove list identifiers in `gnus-list-identifiers' from string SUBJECT."
2008 (require 'gnus-sum) ; for gnus-list-identifiers
2009 (let ((regexp (if (stringp gnus-list-identifiers)
2010 gnus-list-identifiers
2011 (mapconcat 'identity gnus-list-identifiers " *\\|"))))
2012 (if (string-match (concat "\\(\\(\\(Re: +\\)?\\(" regexp
2013 " *\\)\\)+\\(Re: +\\)?\\)") subject)
2014 (concat (substring subject 0 (match-beginning 1))
2015 (or (match-string 3 subject)
2016 (match-string 5 subject))
2021 (defun message-strip-subject-re (subject)
2022 "Remove \"Re:\" from subject lines in string SUBJECT."
2023 (if (string-match message-subject-re-regexp subject)
2024 (substring subject (match-end 0))
2027 (defcustom message-replacement-char "."
2028 "Replacement character used instead of unprintable or not decodable chars."
2029 :group 'message-various
2030 :version "22.1" ;; Gnus 5.10.9
2031 :type '(choice string
2035 ;; FIXME: We also should call `message-strip-subject-encoded-words'
2036 ;; when forwarding. Probably in `message-make-forward-subject' and
2037 ;; `message-forward-make-body'.
2039 (defun message-strip-subject-encoded-words (subject)
2040 "Fix non-decodable words in SUBJECT."
2041 ;; Cf. `gnus-simplify-subject-fully'.
2042 (let* ((case-fold-search t)
2043 (replacement-chars (format "[%s%s%s]"
2044 message-replacement-char
2045 message-replacement-char
2046 message-replacement-char))
2047 (enc-word-re "=\\?\\([^?]+\\)\\?\\([QB]\\)\\?\\([^?]+\\)\\(\\?=\\)")
2052 (goto-char (point-min))
2053 (when (re-search-forward enc-word-re nil t)
2054 (setq cs-string (match-string 1)))))
2055 cs-coding q-or-b word-beg word-end)
2056 (if (or (not have-marker) ;; No encoded word found...
2057 ;; ... or double encoding was correct:
2058 (and (stringp cs-string)
2059 (setq cs-string (downcase cs-string))
2060 (mm-coding-system-p (intern cs-string))
2064 Decoded Subject \"%s\"
2065 contains a valid encoded word. Decode again? "
2067 (setq cs-coding (intern cs-string))))))
2071 (goto-char (point-min))
2072 (while (re-search-forward enc-word-re nil t)
2073 (setq cs-string (downcase (match-string 1))
2074 q-or-b (match-string 2)
2075 word-beg (match-beginning 0)
2076 word-end (match-end 0))
2078 (if (mm-coding-system-p (intern cs-string))
2079 (setq cs-coding (intern cs-string))
2081 ;; No double encoded subject? => bogus charset.
2084 (mm-read-coding-system
2086 Decoded Subject \"%s\"
2087 contains an encoded word. The charset `%s' is unknown or invalid.
2088 Hit RET to replace non-decodable characters with \"%s\" or enter replacement
2090 subject cs-string message-replacement-char)))
2092 (replace-match (concat "=?" (symbol-name cs-coding)
2095 (goto-char word-beg)
2096 (re-search-forward "=\\?\\([^?]+\\)\\?\\([QB]\\)\\?" word-end t)
2099 (if (string-match "\\`Q\\'" q-or-b)
2102 (message "Replacing non-decodable characters with \"%s\"."
2103 message-replacement-char)
2104 (while (re-search-forward "\\(=[A-F0-9][A-F0-9]\\)+"
2106 (replace-match message-replacement-char)))
2108 (message "Replacing non-decodable characters with \"%s\"."
2110 (re-search-forward "[^?]+" word-end t)
2111 (replace-match replacement-chars))
2112 (re-search-forward "\\?=")
2113 (replace-match "")))))
2114 (rfc2047-decode-region (point-min) (point-max))
2117 ;;; Start of functions adopted from `message-utils.el'.
2119 (defun message-strip-subject-trailing-was (subject)
2120 "Remove trailing \"(was: <old subject>)\" from SUBJECT lines.
2121 Leading \"Re: \" is not stripped by this function. Use the function
2122 `message-strip-subject-re' for this."
2123 (let* ((query message-subject-trailing-was-query)
2128 message-subject-trailing-was-ask-regexp
2129 message-subject-trailing-was-regexp)
2132 (setq new (substring subject 0 (match-beginning 0))))
2133 (if (or (not found) (eq query nil))
2136 (if (message-y-or-n-p
2137 "Strip `(was: <old subject>)' in subject? " t
2139 "Strip `(was: <old subject>)' in subject "
2140 "and use the new one instead?\n\n"
2141 "Current subject is: \""
2143 "New subject would be: \""
2145 "See the variable `message-subject-trailing-was-query' "
2146 "to get rid of this query."
2151 ;;; Suggested by Jonas Steverud @ www.dtek.chalmers.se/~d4jonas/
2153 (defun message-change-subject (new-subject)
2154 "Ask for NEW-SUBJECT header, append (was: <Old Subject>)."
2155 ;; <URL:http://www.landfield.com/usefor/drafts/draft-ietf-usefor-useage--1.02.unpaged>
2158 (read-from-minibuffer "New subject: ")))
2159 (cond ((and (not (or (null new-subject) ; new subject not empty
2160 (zerop (string-width new-subject))
2161 (string-match "^[ \t]*$" new-subject))))
2165 (message-narrow-to-headers)
2166 (message-fetch-field "Subject"))))
2167 (cond ((not old-subject)
2168 (error "No current subject"))
2171 (regexp-quote new-subject)
2173 old-subject)) ; yes, it really is a new subject
2174 ;; delete eventual Re: prefix
2176 (message-strip-subject-re old-subject))
2177 (message-goto-subject)
2178 (message-delete-line)
2179 (insert (concat "Subject: "
2182 old-subject ")\n")))))))))
2184 (defun message-mark-inserted-region (beg end &optional verbatim)
2185 "Mark some region in the current article with enclosing tags.
2186 See `message-mark-insert-begin' and `message-mark-insert-end'.
2187 If VERBATIM, use slrn style verbatim marks (\"#v+\" and \"#v-\")."
2188 (interactive "r\nP")
2190 ;; add to the end of the region first, otherwise end would be invalid
2192 (insert (if verbatim "#v-\n" message-mark-insert-end))
2194 (insert (if verbatim "#v+\n" message-mark-insert-begin))))
2196 (defun message-mark-insert-file (file &optional verbatim)
2197 "Insert FILE at point, marking it with enclosing tags.
2198 See `message-mark-insert-begin' and `message-mark-insert-end'.
2199 If VERBATIM, use slrn style verbatim marks (\"#v+\" and \"#v-\")."
2200 (interactive "fFile to insert: \nP")
2201 ;; reverse insertion to get correct result.
2203 (insert (if verbatim "#v-\n" message-mark-insert-end))
2205 (insert-file-contents file)
2207 (insert (if verbatim "#v+\n" message-mark-insert-begin))))
2209 (defun message-add-archive-header ()
2210 "Insert \"X-No-Archive: Yes\" in the header and a note in the body.
2211 The note can be customized using `message-archive-note'. When called with a
2212 prefix argument, ask for a text to insert. If you don't want the note in the
2213 body, set `message-archive-note' to nil."
2215 (if current-prefix-arg
2216 (setq message-archive-note
2217 (read-from-minibuffer "Reason for No-Archive: "
2218 (cons message-archive-note 0))))
2220 (if (message-goto-signature)
2221 (re-search-backward message-signature-separator))
2222 (when message-archive-note
2223 (insert message-archive-note)
2225 (message-add-header message-archive-header)
2226 (message-sort-headers)))
2228 (defun message-cross-post-followup-to-header (target-group)
2229 "Mangles FollowUp-To and Newsgroups header to point to TARGET-GROUP.
2230 With prefix-argument just set Follow-Up, don't cross-post."
2232 (list ; Completion based on Gnus
2233 (completing-read "Followup To: "
2234 (if (boundp 'gnus-newsrc-alist)
2236 nil nil '("poster" . 0)
2237 (if (boundp 'gnus-group-history)
2238 'gnus-group-history))))
2239 (message-remove-header "Follow[Uu]p-[Tt]o" t)
2240 (message-goto-newsgroups)
2242 ;; if we already did a crosspost before, kill old target
2243 (if (and message-cross-post-old-target
2245 (regexp-quote (concat "," message-cross-post-old-target))
2248 ;; unless (followup is to poster or user explicitly asked not
2249 ;; to cross-post, or target-group is already in Newsgroups)
2250 ;; add target-group to Newsgroups line.
2252 ;; def: cross-post, req:no
2253 (and message-cross-post-default (not current-prefix-arg))
2254 ;; def: no-cross-post, req:yes
2255 (and (not message-cross-post-default) current-prefix-arg))
2256 (not (string-match "poster" target-group))
2257 (not (string-match (regexp-quote target-group)
2258 (message-fetch-field "Newsgroups"))))
2260 (insert (concat "," target-group))))
2261 (end-of-line) ; ensure Followup: comes after Newsgroups:
2262 ;; unless new followup would be identical to Newsgroups line
2263 ;; make a new Followup-To line
2264 (if (not (string-match (concat "^[ \t]*"
2267 (message-fetch-field "Newsgroups")))
2268 (insert (concat "\nFollowup-To: " target-group)))
2269 (setq message-cross-post-old-target target-group))
2271 (defun message-cross-post-insert-note (target-group cross-post in-old
2273 "Insert a in message body note about a set Followup or Crosspost.
2274 If there have been previous notes, delete them. TARGET-GROUP specifies the
2275 group to Followup-To. When CROSS-POST is t, insert note about
2276 crossposting. IN-OLD specifies whether TARGET-GROUP is a member of
2277 OLD-GROUPS. OLD-GROUPS lists the old-groups the posting would have
2278 been made to before the user asked for a Crosspost."
2279 ;; start scanning body for previous uses
2280 (message-goto-signature)
2281 (let ((head (re-search-backward
2282 (concat "^" mail-header-separator)
2283 nil t))) ; just search in body
2284 (message-goto-signature)
2285 (while (re-search-backward
2286 (concat "^" (regexp-quote message-cross-post-note) ".*")
2288 (message-delete-line))
2289 (message-goto-signature)
2290 (while (re-search-backward
2291 (concat "^" (regexp-quote message-followup-to-note) ".*")
2293 (message-delete-line))
2295 (if (message-goto-signature)
2296 (re-search-backward message-signature-separator))
2299 (string-match "^[ \t]*poster[ \t]*$" target-group))
2300 (insert (concat message-followup-to-note target-group "\n"))
2301 (insert (concat message-cross-post-note target-group "\n")))))
2303 (defun message-cross-post-followup-to (target-group)
2304 "Crossposts message and set Followup-To to TARGET-GROUP.
2305 With prefix-argument just set Follow-Up, don't cross-post."
2307 (list ; Completion based on Gnus
2308 (completing-read "Followup To: "
2309 (if (boundp 'gnus-newsrc-alist)
2311 nil nil '("poster" . 0)
2312 (if (boundp 'gnus-group-history)
2313 'gnus-group-history))))
2314 (cond ((not (or (null target-group) ; new subject not empty
2315 (zerop (string-width target-group))
2316 (string-match "^[ \t]*$" target-group)))
2318 (let* ((old-groups (message-fetch-field "Newsgroups"))
2319 (in-old (string-match
2320 (regexp-quote target-group)
2321 (or old-groups ""))))
2322 ;; check whether target exactly matches old Newsgroups
2323 (cond ((not old-groups)
2324 (error "No current newsgroup"))
2328 (regexp-quote target-group)
2331 ;; yes, Newsgroups line must change
2332 (message-cross-post-followup-to-header target-group)
2333 ;; insert note whether we do cross-post or followup-to
2334 (funcall message-cross-post-note-function
2336 (if (or (and message-cross-post-default
2337 (not current-prefix-arg))
2338 (and (not message-cross-post-default)
2339 current-prefix-arg)) t)
2340 in-old old-groups))))))))
2342 ;;; Reduce To: to Cc: or Bcc: header
2344 (defun message-reduce-to-to-cc ()
2345 "Replace contents of To: header with contents of Cc: or Bcc: header."
2348 (save-restriction (message-narrow-to-headers)
2349 (message-fetch-field "cc")))
2351 (if (and (not cc-content)
2354 (message-narrow-to-headers)
2355 (message-fetch-field "bcc"))))
2360 (message-delete-line)
2361 (insert (concat "To: " cc-content "\n"))
2363 (message-narrow-to-headers)
2364 (message-remove-header (if bcc
2368 ;;; End of functions adopted from `message-utils.el'.
2370 (defun message-remove-header (header &optional is-regexp first reverse)
2371 "Remove HEADER in the narrowed buffer.
2372 If IS-REGEXP, HEADER is a regular expression.
2373 If FIRST, only remove the first instance of the header.
2374 Return the number of headers removed."
2375 (goto-char (point-min))
2376 (let ((regexp (if is-regexp header (concat "^" (regexp-quote header) ":")))
2378 (case-fold-search t)
2380 (while (and (not (eobp))
2383 (not (looking-at regexp))
2384 (looking-at regexp))
2391 ;; There might be a continuation header, so we have to search
2392 ;; until we find a new non-continuation line.
2395 (if (re-search-forward "^[^ \t]" nil t)
2396 (goto-char (match-beginning 0))
2399 (if (re-search-forward "^[^ \t]" nil t)
2400 (goto-char (match-beginning 0))
2401 (goto-char (point-max)))))
2404 (defun message-remove-first-header (header)
2405 "Remove the first instance of HEADER if there is more than one."
2407 (regexp (concat "^" (regexp-quote header) ":")))
2409 (goto-char (point-min))
2410 (while (re-search-forward regexp nil t)
2413 (message-remove-header header nil t)
2416 (defun message-narrow-to-headers ()
2417 "Narrow the buffer to the head of the message."
2420 (goto-char (point-min))
2421 (if (re-search-forward
2422 (concat "^" (regexp-quote mail-header-separator) "\n") nil t)
2425 (goto-char (point-min)))
2427 (defun message-narrow-to-head-1 ()
2428 "Like `message-narrow-to-head'. Don't widen."
2430 (goto-char (point-min))
2431 (if (search-forward "\n\n" nil 1)
2434 (goto-char (point-min)))
2436 ;; FIXME: clarify diffference: message-narrow-to-head,
2437 ;; message-narrow-to-headers-or-head, message-narrow-to-headers
2438 (defun message-narrow-to-head ()
2439 "Narrow the buffer to the head of the message.
2440 Point is left at the beginning of the narrowed-to region."
2442 (message-narrow-to-head-1))
2444 (defun message-narrow-to-headers-or-head ()
2445 "Narrow the buffer to the head of the message."
2448 (goto-char (point-min))
2449 (if (re-search-forward (concat "\\(\n\\)\n\\|^\\("
2450 (regexp-quote mail-header-separator)
2453 (or (match-end 1) (match-beginning 2))
2455 (goto-char (point-min)))
2457 (defun message-news-p ()
2458 "Say whether the current buffer contains a news message."
2459 (and (not message-this-is-mail)
2460 (or message-this-is-news
2463 (message-narrow-to-headers)
2464 (and (message-fetch-field "newsgroups")
2465 (not (message-fetch-field "posted-to"))))))))
2467 (defun message-mail-p ()
2468 "Say whether the current buffer contains a mail message."
2469 (and (not message-this-is-news)
2470 (or message-this-is-mail
2473 (message-narrow-to-headers)
2474 (or (message-fetch-field "to")
2475 (message-fetch-field "cc")
2476 (message-fetch-field "bcc")))))))
2478 (defun message-subscribed-p ()
2479 "Say whether we need to insert a MFT header."
2480 (or message-subscribed-regexps
2481 message-subscribed-addresses
2482 message-subscribed-address-file
2483 message-subscribed-address-functions))
2485 (defun message-next-header ()
2486 "Go to the beginning of the next header."
2488 (or (eobp) (forward-char 1))
2489 (not (if (re-search-forward "^[^ \t]" nil t)
2491 (goto-char (point-max)))))
2493 (defun message-sort-headers-1 ()
2494 "Sort the buffer as headers using `message-rank' text props."
2495 (goto-char (point-min))
2498 nil 'message-next-header
2500 (message-next-header)
2504 (or (get-text-property (point) 'message-rank)
2507 (defun message-sort-headers ()
2508 "Sort the headers of the current message according to `message-header-format-alist'."
2512 (let ((max (1+ (length message-header-format-alist)))
2514 (message-narrow-to-headers)
2515 (while (re-search-forward "^[^ \n]+:" nil t)
2517 (match-beginning 0) (1+ (match-beginning 0))
2519 (if (setq rank (length (memq (assq (intern (buffer-substring
2521 (1- (match-end 0))))
2522 message-header-format-alist)
2523 message-header-format-alist)))
2526 (message-sort-headers-1))))
2528 (defun message-kill-address ()
2529 "Kill the address under point."
2531 (let ((start (point)))
2532 (message-skip-to-next-address)
2533 (kill-region start (point))))
2536 (autoload 'Info-goto-node "info")
2537 (defvar mml2015-use)
2539 (defun message-info (&optional arg)
2540 "Display the Message manual.
2542 Prefixed with one \\[universal-argument], display the Emacs MIME
2543 manual. With two \\[universal-argument]'s, display the EasyPG or
2544 PGG manual, depending on the value of `mml2015-use'."
2546 ;; Don't use `info' because support for `(filename)nodename' is not
2547 ;; available in XEmacs < 21.5.12.
2548 (Info-goto-node (format "(%s)Top"
2552 ((eq arg 4) 'emacs-mime)
2553 ;; `booleanp' only available in Emacs 22+
2554 ((and (not (memq arg '(nil t)))
2568 (defvar message-mode-map nil)
2570 (unless message-mode-map
2571 (setq message-mode-map (make-keymap))
2572 (set-keymap-parent message-mode-map text-mode-map)
2573 (define-key message-mode-map "\C-c?" 'describe-mode)
2575 (define-key message-mode-map "\C-c\C-f\C-t" 'message-goto-to)
2576 (define-key message-mode-map "\C-c\C-f\C-o" 'message-goto-from)
2577 (define-key message-mode-map "\C-c\C-f\C-b" 'message-goto-bcc)
2578 (define-key message-mode-map "\C-c\C-f\C-w" 'message-goto-fcc)
2579 (define-key message-mode-map "\C-c\C-f\C-c" 'message-goto-cc)
2580 (define-key message-mode-map "\C-c\C-f\C-s" 'message-goto-subject)
2581 (define-key message-mode-map "\C-c\C-f\C-r" 'message-goto-reply-to)
2582 (define-key message-mode-map "\C-c\C-f\C-n" 'message-goto-newsgroups)
2583 (define-key message-mode-map "\C-c\C-f\C-d" 'message-goto-distribution)
2584 (define-key message-mode-map "\C-c\C-f\C-f" 'message-goto-followup-to)
2585 (define-key message-mode-map "\C-c\C-f\C-m" 'message-goto-mail-followup-to)
2586 (define-key message-mode-map "\C-c\C-f\C-k" 'message-goto-keywords)
2587 (define-key message-mode-map "\C-c\C-f\C-u" 'message-goto-summary)
2588 (define-key message-mode-map "\C-c\C-f\C-i"
2589 'message-insert-or-toggle-importance)
2590 (define-key message-mode-map "\C-c\C-f\C-a"
2591 'message-generate-unsubscribed-mail-followup-to)
2593 ;; modify headers (and insert notes in body)
2594 (define-key message-mode-map "\C-c\C-fs" 'message-change-subject)
2596 (define-key message-mode-map "\C-c\C-fx" 'message-cross-post-followup-to)
2597 ;; prefix+message-cross-post-followup-to = same w/o cross-post
2598 (define-key message-mode-map "\C-c\C-ft" 'message-reduce-to-to-cc)
2599 (define-key message-mode-map "\C-c\C-fa" 'message-add-archive-header)
2600 ;; mark inserted text
2601 (define-key message-mode-map "\C-c\M-m" 'message-mark-inserted-region)
2602 (define-key message-mode-map "\C-c\M-f" 'message-mark-insert-file)
2604 (define-key message-mode-map "\C-c\C-b" 'message-goto-body)
2605 (define-key message-mode-map "\C-c\C-i" 'message-goto-signature)
2607 (define-key message-mode-map "\C-c\C-t" 'message-insert-to)
2608 (define-key message-mode-map "\C-c\C-fw" 'message-insert-wide-reply)
2609 (define-key message-mode-map "\C-c\C-n" 'message-insert-newsgroups)
2610 (define-key message-mode-map "\C-c\C-l" 'message-to-list-only)
2611 (define-key message-mode-map "\C-c\C-f\C-e" 'message-insert-expires)
2613 (define-key message-mode-map "\C-c\C-u" 'message-insert-or-toggle-importance)
2614 (define-key message-mode-map "\C-c\M-n"
2615 'message-insert-disposition-notification-to)
2617 (define-key message-mode-map "\C-c\C-y" 'message-yank-original)
2618 (define-key message-mode-map "\C-c\M-\C-y" 'message-yank-buffer)
2619 (define-key message-mode-map "\C-c\C-q" 'message-fill-yanked-message)
2620 (define-key message-mode-map "\C-c\C-w" 'message-insert-signature)
2621 (define-key message-mode-map "\C-c\M-h" 'message-insert-headers)
2622 (define-key message-mode-map "\C-c\C-r" 'message-caesar-buffer-body)
2623 (define-key message-mode-map "\C-c\C-o" 'message-sort-headers)
2624 (define-key message-mode-map "\C-c\M-r" 'message-rename-buffer)
2626 (define-key message-mode-map "\C-c\C-c" 'message-send-and-exit)
2627 (define-key message-mode-map "\C-c\C-s" 'message-send)
2628 (define-key message-mode-map "\C-c\C-k" 'message-kill-buffer)
2629 (define-key message-mode-map "\C-c\C-d" 'message-dont-send)
2630 (define-key message-mode-map "\C-c\n" 'gnus-delay-article)
2632 (define-key message-mode-map "\C-c\M-k" 'message-kill-address)
2633 (define-key message-mode-map "\C-c\C-e" 'message-elide-region)
2634 (define-key message-mode-map "\C-c\C-v" 'message-delete-not-region)
2635 (define-key message-mode-map "\C-c\C-z" 'message-kill-to-signature)
2636 (define-key message-mode-map "\M-\r" 'message-newline-and-reformat)
2637 (define-key message-mode-map [remap split-line] 'message-split-line)
2639 (define-key message-mode-map "\C-c\C-a" 'mml-attach-file)
2641 (define-key message-mode-map "\C-a" 'message-beginning-of-line)
2642 (define-key message-mode-map "\t" 'message-tab)
2643 (define-key message-mode-map "\M-;" 'comment-region)
2645 (define-key message-mode-map "\M-n" 'message-display-abbrev))
2648 message-mode-menu message-mode-map "Message Menu."
2650 ["Yank Original" message-yank-original message-reply-buffer]
2651 ["Fill Yanked Message" message-fill-yanked-message t]
2652 ["Insert Signature" message-insert-signature t]
2653 ["Caesar (rot13) Message" message-caesar-buffer-body t]
2654 ["Caesar (rot13) Region" message-caesar-region (message-mark-active-p)]
2655 ["Elide Region" message-elide-region
2656 :active (message-mark-active-p)
2657 ,@(if (featurep 'xemacs) nil
2658 '(:help "Replace text in region with an ellipsis"))]
2659 ["Delete Outside Region" message-delete-not-region
2660 :active (message-mark-active-p)
2661 ,@(if (featurep 'xemacs) nil
2662 '(:help "Delete all quoted text outside region"))]
2663 ["Kill To Signature" message-kill-to-signature t]
2664 ["Newline and Reformat" message-newline-and-reformat t]
2665 ["Rename buffer" message-rename-buffer t]
2666 ["Spellcheck" ispell-message
2667 ,@(if (featurep 'xemacs) '(t)
2668 '(:help "Spellcheck this message"))]
2670 ["Insert Region Marked" message-mark-inserted-region
2671 :active (message-mark-active-p)
2672 ,@(if (featurep 'xemacs) nil
2673 '(:help "Mark region with enclosing tags"))]
2674 ["Insert File Marked..." message-mark-insert-file
2675 ,@(if (featurep 'xemacs) '(t)
2676 '(:help "Insert file at point marked with enclosing tags"))]
2678 ["Send Message" message-send-and-exit
2679 ,@(if (featurep 'xemacs) '(t)
2680 '(:help "Send this message"))]
2681 ["Postpone Message" message-dont-send
2682 ,@(if (featurep 'xemacs) '(t)
2683 '(:help "File this draft message and exit"))]
2684 ["Send at Specific Time..." gnus-delay-article
2685 ,@(if (featurep 'xemacs) '(t)
2686 '(:help "Ask, then arrange to send message at that time"))]
2687 ["Kill Message" message-kill-buffer
2688 ,@(if (featurep 'xemacs) '(t)
2689 '(:help "Delete this message without sending"))]
2691 ["Message manual" message-info
2692 ,@(if (featurep 'xemacs) '(t)
2693 '(:help "Display the Message manual"))]))
2696 message-mode-field-menu message-mode-map ""
2698 ["To" message-goto-to t]
2699 ["From" message-goto-from t]
2700 ["Subject" message-goto-subject t]
2701 ["Change subject..." message-change-subject t]
2702 ["Cc" message-goto-cc t]
2703 ["Bcc" message-goto-bcc t]
2704 ["Fcc" message-goto-fcc t]
2705 ["Reply-To" message-goto-reply-to t]
2706 ["Flag As Important" message-insert-importance-high
2707 ,@(if (featurep 'xemacs) '(t)
2708 '(:help "Mark this message as important"))]
2709 ["Flag As Unimportant" message-insert-importance-low
2710 ,@(if (featurep 'xemacs) '(t)
2711 '(:help "Mark this message as unimportant"))]
2713 message-insert-disposition-notification-to
2714 ,@(if (featurep 'xemacs) '(t)
2715 '(:help "Request a receipt notification"))]
2717 ;; (typical) news stuff
2718 ["Summary" message-goto-summary t]
2719 ["Keywords" message-goto-keywords t]
2720 ["Newsgroups" message-goto-newsgroups t]
2721 ["Fetch Newsgroups" message-insert-newsgroups t]
2722 ["Followup-To" message-goto-followup-to t]
2723 ;; ["Followup-To (with note in body)" message-cross-post-followup-to t]
2724 ["Crosspost / Followup-To..." message-cross-post-followup-to t]
2725 ["Distribution" message-goto-distribution t]
2726 ["Expires" message-insert-expires t ]
2727 ["X-No-Archive" message-add-archive-header t ]
2729 ;; (typical) mailing-lists stuff
2730 ["Fetch To" message-insert-to
2731 ,@(if (featurep 'xemacs) '(t)
2732 '(:help "Insert a To header that points to the author."))]
2733 ["Fetch To and Cc" message-insert-wide-reply
2734 ,@(if (featurep 'xemacs) '(t)
2736 "Insert To and Cc headers as if you were doing a wide reply."))]
2738 ["Send to list only" message-to-list-only t]
2739 ["Mail-Followup-To" message-goto-mail-followup-to t]
2740 ["Unsubscribed list post" message-generate-unsubscribed-mail-followup-to
2741 ,@(if (featurep 'xemacs) '(t)
2742 '(:help "Insert a reasonable `Mail-Followup-To:' header."))]
2743 ["Reduce To: to Cc:" message-reduce-to-to-cc t]
2745 ["Sort Headers" message-sort-headers t]
2746 ["Encode non-ASCII domain names" message-idna-to-ascii-rhs t]
2747 ;; We hide `message-hidden-headers' by narrowing the buffer.
2748 ["Show Hidden Headers" widen t]
2749 ["Goto Body" message-goto-body t]
2750 ["Goto Signature" message-goto-signature t]))
2752 (defvar message-tool-bar-map nil)
2754 (defvar facemenu-add-face-function)
2755 (defvar facemenu-remove-face-function)
2757 ;;; Forbidden properties
2759 ;; We use `after-change-functions' to keep special text properties
2760 ;; that interfere with the normal function of message mode out of the
2763 (defcustom message-strip-special-text-properties t
2764 "Strip special properties from the message buffer.
2766 Emacs has a number of special text properties which can break message
2767 composing in various ways. If this option is set, message will strip
2768 these properties from the message composition buffer. However, some
2769 packages requires these properties to be present in order to work.
2770 If you use one of these packages, turn this option off, and hope the
2771 message composition doesn't break too bad."
2773 :group 'message-various
2774 :link '(custom-manual "(message)Various Message Variables")
2777 (defconst message-forbidden-properties
2778 ;; No reason this should be clutter up customize. We make it a
2779 ;; property list (rather than a list of property symbols), to be
2780 ;; directly useful for `remove-text-properties'.
2781 '(field nil read-only nil invisible nil intangible nil
2782 mouse-face nil modification-hooks nil insert-in-front-hooks nil
2783 insert-behind-hooks nil point-entered nil point-left nil)
2784 ;; Other special properties:
2785 ;; category, face, display: probably doesn't do any harm.
2786 ;; fontified: is used by font-lock.
2787 ;; syntax-table, local-map: I dunno.
2788 ;; We need to add XEmacs names to the list.
2789 "Property list of with properties forbidden in message buffers.
2790 The values of the properties are ignored, only the property names are used.")
2792 (defun message-tamago-not-in-use-p (pos)
2793 "Return t when tamago version 4 is not in use at the cursor position.
2794 Tamago version 4 is a popular input method for writing Japanese text.
2795 It uses the properties `intangible', `invisible', `modification-hooks'
2796 and `read-only' when translating ascii or kana text to kanji text.
2797 These properties are essential to work, so we should never strip them."
2798 (not (and (boundp 'egg-modefull-mode)
2799 (symbol-value 'egg-modefull-mode)
2800 (or (memq (get-text-property pos 'intangible)
2801 '(its-part-1 its-part-2))
2802 (get-text-property pos 'egg-end)
2803 (get-text-property pos 'egg-lang)
2804 (get-text-property pos 'egg-start)))))
2806 (defsubst message-mail-alias-type-p (type)
2807 (if (atom message-mail-alias-type)
2808 (eq message-mail-alias-type type)
2809 (memq type message-mail-alias-type)))
2811 (defun message-strip-forbidden-properties (begin end &optional old-length)
2812 "Strip forbidden properties between BEGIN and END, ignoring the third arg.
2813 This function is intended to be called from `after-change-functions'.
2814 See also `message-forbidden-properties'."
2815 (when (and (message-mail-alias-type-p 'ecomplete)
2816 (memq this-command message-self-insert-commands))
2817 (message-display-abbrev))
2818 (when (and message-strip-special-text-properties
2819 (message-tamago-not-in-use-p begin))
2820 (let ((buffer-read-only nil)
2821 (inhibit-read-only t))
2822 (remove-text-properties begin end message-forbidden-properties))))
2824 (autoload 'ecomplete-setup "ecomplete") ;; for Emacs <23.
2827 (define-derived-mode message-mode text-mode "Message"
2828 "Major mode for editing mail and news to be sent.
2829 Like Text Mode but with these additional commands:\\<message-mode-map>
2830 C-c C-s `message-send' (send the message) C-c C-c `message-send-and-exit'
2831 C-c C-d Postpone sending the message C-c C-k Kill the message
2832 C-c C-f move to a header field (and create it if there isn't):
2833 C-c C-f C-t move to To C-c C-f C-s move to Subject
2834 C-c C-f C-c move to Cc C-c C-f C-b move to Bcc
2835 C-c C-f C-w move to Fcc C-c C-f C-r move to Reply-To
2836 C-c C-f C-u move to Summary C-c C-f C-n move to Newsgroups
2837 C-c C-f C-k move to Keywords C-c C-f C-d move to Distribution
2838 C-c C-f C-o move to From (\"Originator\")
2839 C-c C-f C-f move to Followup-To
2840 C-c C-f C-m move to Mail-Followup-To
2841 C-c C-f C-e move to Expires
2842 C-c C-f C-i cycle through Importance values
2843 C-c C-f s change subject and append \"(was: <Old Subject>)\"
2844 C-c C-f x crossposting with FollowUp-To header and note in body
2845 C-c C-f t replace To: header with contents of Cc: or Bcc:
2846 C-c C-f a Insert X-No-Archive: header and a note in the body
2847 C-c C-t `message-insert-to' (add a To header to a news followup)
2848 C-c C-l `message-to-list-only' (removes all but list address in to/cc)
2849 C-c C-n `message-insert-newsgroups' (add a Newsgroup header to a news reply)
2850 C-c C-b `message-goto-body' (move to beginning of message text).
2851 C-c C-i `message-goto-signature' (move to the beginning of the signature).
2852 C-c C-w `message-insert-signature' (insert `message-signature-file' file).
2853 C-c C-y `message-yank-original' (insert current message, if any).
2854 C-c C-q `message-fill-yanked-message' (fill what was yanked).
2855 C-c C-e `message-elide-region' (elide the text between point and mark).
2856 C-c C-v `message-delete-not-region' (remove the text outside the region).
2857 C-c C-z `message-kill-to-signature' (kill the text up to the signature).
2858 C-c C-r `message-caesar-buffer-body' (rot13 the message body).
2859 C-c C-a `mml-attach-file' (attach a file as MIME).
2860 C-c C-u `message-insert-or-toggle-importance' (insert or cycle importance).
2861 C-c M-n `message-insert-disposition-notification-to' (request receipt).
2862 C-c M-m `message-mark-inserted-region' (mark region with enclosing tags).
2863 C-c M-f `message-mark-insert-file' (insert file marked with enclosing tags).
2864 M-RET `message-newline-and-reformat' (break the line and reformat)."
2865 (setq local-abbrev-table text-mode-abbrev-table)
2866 (set (make-local-variable 'message-reply-buffer) nil)
2867 (set (make-local-variable 'message-inserted-headers) nil)
2868 (set (make-local-variable 'message-send-actions) nil)
2869 (set (make-local-variable 'message-exit-actions) nil)
2870 (set (make-local-variable 'message-kill-actions) nil)
2871 (set (make-local-variable 'message-postpone-actions) nil)
2872 (set (make-local-variable 'message-draft-article) nil)
2873 (setq buffer-offer-save t)
2874 (set (make-local-variable 'facemenu-add-face-function)
2876 (let ((face-fun (cdr (assq face message-face-alist))))
2878 (funcall face-fun (point) end)
2879 (error "Face %s not configured for %s mode" face mode-name)))
2881 (set (make-local-variable 'facemenu-remove-face-function) t)
2882 (set (make-local-variable 'message-reply-headers) nil)
2883 (make-local-variable 'message-newsreader)
2884 (make-local-variable 'message-mailer)
2885 (make-local-variable 'message-post-method)
2886 (set (make-local-variable 'message-sent-message-via) nil)
2887 (set (make-local-variable 'message-checksum) nil)
2888 (set (make-local-variable 'message-mime-part) 0)
2889 (message-setup-fill-variables)
2890 (when message-fill-column
2891 (setq fill-column message-fill-column)
2892 (turn-on-auto-fill))
2893 ;; Allow using comment commands to add/remove quoting.
2894 ;; (set (make-local-variable 'comment-start) message-yank-prefix)
2895 (when message-yank-prefix
2896 (set (make-local-variable 'comment-start) message-yank-prefix)
2897 (set (make-local-variable 'comment-start-skip)
2898 (concat "^" (regexp-quote message-yank-prefix) "[ \t]*")))
2899 (if (featurep 'xemacs)
2900 (message-setup-toolbar)
2901 (set (make-local-variable 'font-lock-defaults)
2902 '(message-font-lock-keywords t))
2903 (if (boundp 'tool-bar-map)
2904 (set (make-local-variable 'tool-bar-map) (message-make-tool-bar))))
2905 (easy-menu-add message-mode-menu message-mode-map)
2906 (easy-menu-add message-mode-field-menu message-mode-map)
2907 (gnus-make-local-hook 'after-change-functions)
2908 ;; Mmmm... Forbidden properties...
2909 (add-hook 'after-change-functions 'message-strip-forbidden-properties
2911 ;; Allow mail alias things.
2913 ((message-mail-alias-type-p 'abbrev)
2914 (if (fboundp 'mail-abbrevs-setup)
2915 (mail-abbrevs-setup)
2916 (if (fboundp 'mail-aliases-setup) ; warning avoidance
2917 (mail-aliases-setup))))
2918 ((message-mail-alias-type-p 'ecomplete)
2920 (unless buffer-file-name
2921 (message-set-auto-save-file-name))
2922 (unless (buffer-base-buffer)
2923 ;; Don't enable multibyte on an indirect buffer. Maybe enabling
2924 ;; multibyte is not necessary at all. -- zsh
2925 (mm-enable-multibyte))
2926 (set (make-local-variable 'indent-tabs-mode) nil) ;No tabs for indentation.
2929 (defun message-setup-fill-variables ()
2930 "Setup message fill variables."
2931 (set (make-local-variable 'fill-paragraph-function)
2932 'message-fill-paragraph)
2933 (make-local-variable 'paragraph-separate)
2934 (make-local-variable 'paragraph-start)
2935 (make-local-variable 'adaptive-fill-regexp)
2936 (unless (boundp 'adaptive-fill-first-line-regexp)
2937 (setq adaptive-fill-first-line-regexp nil))
2938 (make-local-variable 'adaptive-fill-first-line-regexp)
2939 (let ((quote-prefix-regexp
2940 ;; User should change message-cite-prefix-regexp if
2941 ;; message-yank-prefix is set to an abnormal value.
2942 (concat "\\(" message-cite-prefix-regexp "\\)[ \t]*")))
2943 (setq paragraph-start
2945 (regexp-quote mail-header-separator) "$\\|"
2946 "[ \t]*$\\|" ; blank lines
2947 "-- $\\|" ; signature delimiter
2948 "---+$\\|" ; delimiters for forwarded messages
2949 page-delimiter "$\\|" ; spoiler warnings
2950 ".*wrote:$\\|" ; attribution lines
2951 quote-prefix-regexp "$\\|" ; empty lines in quoted text
2953 "<#!*/?\\(multipart\\|part\\|external\\|mml\\|secure\\)"))
2954 (setq paragraph-separate paragraph-start)
2955 (setq adaptive-fill-regexp
2956 (concat quote-prefix-regexp "\\|" adaptive-fill-regexp))
2957 (setq adaptive-fill-first-line-regexp
2958 (concat quote-prefix-regexp "\\|"
2959 adaptive-fill-first-line-regexp)))
2960 (make-local-variable 'auto-fill-inhibit-regexp)
2961 ;;(setq auto-fill-inhibit-regexp "^[A-Z][^: \n\t]+:")
2962 (setq auto-fill-inhibit-regexp nil)
2963 (make-local-variable 'normal-auto-fill-function)
2964 (setq normal-auto-fill-function 'message-do-auto-fill)
2965 ;; KLUDGE: auto fill might already be turned on in `text-mode-hook'.
2966 ;; In that case, ensure that it uses the right function. The real
2967 ;; solution would be not to use `define-derived-mode', and run
2968 ;; `text-mode-hook' ourself at the end of the mode.
2969 ;; -- Per Abrahamsen <abraham@dina.kvl.dk> Date: 2001-10-19.
2970 ;; This kludge is unneeded in Emacs>=21 since define-derived-mode is
2971 ;; now careful to run parent hooks after the body. --Stef
2972 (when auto-fill-function
2973 (setq auto-fill-function normal-auto-fill-function)))
2978 ;;; Message mode commands
2981 ;;; Movement commands
2983 (defun message-goto-to ()
2984 "Move point to the To header."
2986 (message-position-on-field "To"))
2988 (defun message-goto-from ()
2989 "Move point to the From header."
2991 (message-position-on-field "From"))
2993 (defun message-goto-subject ()
2994 "Move point to the Subject header."
2996 (message-position-on-field "Subject"))
2998 (defun message-goto-cc ()
2999 "Move point to the Cc header."
3001 (message-position-on-field "Cc" "To"))
3003 (defun message-goto-bcc ()
3004 "Move point to the Bcc header."
3006 (message-position-on-field "Bcc" "Cc" "To"))
3008 (defun message-goto-fcc ()
3009 "Move point to the Fcc header."
3011 (message-position-on-field "Fcc" "To" "Newsgroups"))
3013 (defun message-goto-reply-to ()
3014 "Move point to the Reply-To header."
3016 (message-position-on-field "Reply-To" "Subject"))
3018 (defun message-goto-newsgroups ()
3019 "Move point to the Newsgroups header."
3021 (message-position-on-field "Newsgroups"))
3023 (defun message-goto-distribution ()
3024 "Move point to the Distribution header."
3026 (message-position-on-field "Distribution"))
3028 (defun message-goto-followup-to ()
3029 "Move point to the Followup-To header."
3031 (message-position-on-field "Followup-To" "Newsgroups"))
3033 (defun message-goto-mail-followup-to ()
3034 "Move point to the Mail-Followup-To header."
3036 (message-position-on-field "Mail-Followup-To" "To"))
3038 (defun message-goto-keywords ()
3039 "Move point to the Keywords header."
3041 (message-position-on-field "Keywords" "Subject"))
3043 (defun message-goto-summary ()
3044 "Move point to the Summary header."
3046 (message-position-on-field "Summary" "Subject"))
3048 (defun message-goto-body (&optional interactivep)
3049 "Move point to the beginning of the message body."
3050 (interactive (list t))
3051 (when (and interactivep
3052 (looking-at "[ \t]*\n"))
3054 (goto-char (point-min))
3055 (or (search-forward (concat "\n" mail-header-separator "\n") nil t)
3056 (search-forward-regexp "[^:]+:\\([^\n]\\|\n[ \t]\\)+\n\n" nil t)))
3058 (defun message-in-body-p ()
3059 "Return t if point is in the message body."
3060 (let ((body (save-excursion (message-goto-body) (point))))
3063 (defun message-goto-eoh ()
3064 "Move point to the end of the headers."
3069 (defun message-goto-signature ()
3070 "Move point to the beginning of the message signature.
3071 If there is no signature in the article, go to the end and
3074 (goto-char (point-min))
3075 (if (re-search-forward message-signature-separator nil t)
3077 (goto-char (point-max))
3080 (defun message-generate-unsubscribed-mail-followup-to (&optional include-cc)
3081 "Insert a reasonable MFT header in a post to an unsubscribed list.
3082 When making original posts to a mailing list you are not subscribed to,
3083 you have to type in a MFT header by hand. The contents, usually, are
3084 the addresses of the list and your own address. This function inserts
3085 such a header automatically. It fetches the contents of the To: header
3086 in the current mail buffer, and appends the current `user-mail-address'.
3088 If the optional argument INCLUDE-CC is non-nil, the addresses in the
3089 Cc: header are also put into the MFT."
3094 (message-narrow-to-headers)
3095 (message-remove-header "Mail-Followup-To")
3096 (setq cc (and include-cc (message-fetch-field "Cc")))
3098 (concat (message-fetch-field "To") "," cc)
3099 (message-fetch-field "To"))))
3100 (message-goto-mail-followup-to)
3101 (insert (concat tos ", " user-mail-address))))
3105 (defun message-insert-to (&optional force)
3106 "Insert a To header that points to the author of the article being replied to.
3107 If the original author requested not to be sent mail, don't insert unless the
3108 prefix FORCE is given."
3110 (let* ((mct (message-fetch-reply-field "mail-copies-to"))
3111 (dont (and mct (or (equal (downcase mct) "never")
3112 (equal (downcase mct) "nobody"))))
3113 (to (or (message-fetch-reply-field "mail-reply-to")
3114 (message-fetch-reply-field "reply-to")
3115 (message-fetch-reply-field "from"))))
3119 "Ignoring the user request not to have copies sent via mail"
3120 "Complying with the user request not to have copies sent via mail")))
3121 (when (and force (not to))
3122 (error "No mail address in the article"))
3123 (when (and to (or force (not dont)))
3124 (message-carefully-insert-headers (list (cons 'To to))))))
3126 (defun message-insert-wide-reply ()
3127 "Insert To and Cc headers as if you were doing a wide reply."
3129 (let ((headers (message-with-reply-buffer
3130 (message-get-reply-headers t))))
3131 (message-carefully-insert-headers headers)))
3133 (defcustom message-header-synonyms
3136 "List of lists of header synonyms.
3137 E.g., if this list contains a member list with elements `Cc' and `To',
3138 then `message-carefully-insert-headers' will not insert a `To' header
3139 when the message is already `Cc'ed to the recipient."
3141 :group 'message-headers
3142 :link '(custom-manual "(message)Message Headers")
3143 :type '(repeat sexp))
3145 (defun message-carefully-insert-headers (headers)
3146 "Insert the HEADERS, an alist, into the message buffer.
3147 Does not insert the headers when they are already present there
3148 or in the synonym headers, defined by `message-header-synonyms'."
3149 ;; FIXME: Should compare only the address and not the full name. Comparison
3150 ;; should be done case-folded (and with `string=' rather than
3152 ;; (mail-strip-quoted-names "Foo Bar <foo@bar>, bla@fasel (Bla Fasel)")
3153 (dolist (header headers)
3154 (let* ((header-name (symbol-name (car header)))
3155 (new-header (cdr header))
3156 (synonyms (loop for synonym in message-header-synonyms
3157 when (memq (car header) synonym) return synonym))
3159 (loop for synonym in synonyms
3160 for old-header = (mail-fetch-field (symbol-name synonym))
3161 when (and old-header (string-match new-header old-header))
3164 (message "already have `%s' in `%s'" new-header old-header)
3165 (when (and (message-position-on-field header-name)
3166 (setq old-header (mail-fetch-field header-name))
3167 (not (string-match "\\` *\\'" old-header)))
3169 (insert new-header)))))
3171 (defun message-widen-reply ()
3172 "Widen the reply to include maximum recipients."
3175 (and (bufferp message-reply-buffer)
3176 (buffer-name message-reply-buffer)
3177 (with-current-buffer message-reply-buffer
3178 (message-get-reply-headers t)))))
3181 (message-narrow-to-headers)
3182 (dolist (elem follow-to)
3183 (message-remove-header (symbol-name (car elem)))
3184 (goto-char (point-min))
3185 (insert (symbol-name (car elem)) ": "
3186 (cdr elem) "\n"))))))
3188 (defun message-insert-newsgroups ()
3189 "Insert the Newsgroups header from the article being replied to."
3191 (when (and (message-position-on-field "Newsgroups")
3192 (mail-fetch-field "newsgroups")
3193 (not (string-match "\\` *\\'" (mail-fetch-field "newsgroups"))))
3195 (insert (or (message-fetch-reply-field "newsgroups") "")))
3199 ;;; Various commands
3201 (defun message-delete-not-region (beg end)
3202 "Delete everything in the body of the current message outside of the region."
3207 ;; snarf citation prefix, if appropriate
3208 (unless (eq (point) (progn (beginning-of-line) (point)))
3209 (when (looking-at message-cite-prefix-regexp)
3210 (setq citeprefix (match-string 0))))
3212 (delete-region (point) (if (not (message-goto-signature))
3218 (delete-region beg (progn (message-goto-body)
3222 (insert citeprefix))))
3223 (when (message-goto-signature)
3226 (defun message-kill-to-signature (&optional arg)
3227 "Kill all text up to the signature.
3228 If a numeric argument or prefix arg is given, leave that number
3229 of lines before the signature intact."
3233 (let ((point (point)))
3234 (narrow-to-region point (point-max))
3235 (message-goto-signature)
3237 (if (and arg (numberp arg))
3238 (forward-line (- -1 arg))
3240 (unless (= point (point))
3241 (kill-region point (point))
3245 (defun message-newline-and-reformat (&optional arg not-break)
3246 "Insert four newlines, and then reformat if inside quoted text.
3247 Prefix arg means justify as well."
3248 (interactive (list (if current-prefix-arg 'full)))
3249 (let (quoted point beg end leading-space bolp fill-paragraph-function)
3250 (setq point (point))
3253 (setq bolp (= beg point))
3254 ;; Find first line of the paragraph.
3256 (while (and (not (eobp))
3257 (not (looking-at message-cite-prefix-regexp))
3258 (looking-at paragraph-start))
3261 (when (looking-at message-cite-prefix-regexp)
3262 (setq quoted (match-string 0))
3263 (goto-char (match-end 0))
3264 (looking-at "[ \t]*")
3265 (setq leading-space (match-string 0)))
3269 (< (- point beg) (length quoted)))
3270 ;; break inside the cite prefix.
3276 (while (and (not (eobp))
3277 (not (looking-at paragraph-separate))
3278 (looking-at message-cite-prefix-regexp)
3279 (equal quoted (match-string 0)))
3280 (goto-char (match-end 0))
3281 (looking-at "[ \t]*")
3282 (if (> (length leading-space) (length (match-string 0)))
3283 (setq leading-space (match-string 0)))
3287 (while (and (if (bobp) nil (forward-line -1) t)
3288 (not (looking-at paragraph-start))
3289 (looking-at message-cite-prefix-regexp)
3290 (equal quoted (match-string 0)))
3292 (goto-char (match-end 0))
3293 (looking-at "[ \t]*")
3294 (if (> (length leading-space) (length (match-string 0)))
3295 (setq leading-space (match-string 0)))))
3296 (while (and (not (eobp))
3297 (not (looking-at paragraph-separate))
3298 (not (looking-at message-cite-prefix-regexp)))
3302 (while (and (if (bobp) nil (forward-line -1) t)
3303 (not (looking-at paragraph-start))
3304 (not (looking-at message-cite-prefix-regexp)))
3305 (setq beg (point))))
3308 (narrow-to-region beg end)
3315 (setq point (point))
3316 ;; (newline 2) doesn't mark both newline's as hard, so call
3317 ;; newline twice. -jas
3320 (delete-region (point) (re-search-forward "[ \t]*"))
3321 (when (and quoted (not bolp))
3322 (insert quoted leading-space)))
3325 (let* ((adaptive-fill-regexp
3326 (regexp-quote (concat quoted leading-space)))
3327 (adaptive-fill-first-line-regexp
3328 adaptive-fill-regexp ))
3329 (fill-paragraph arg))
3330 (fill-paragraph arg))
3331 (if point (goto-char point)))))
3333 (defun message-fill-paragraph (&optional arg)
3334 "Message specific function to fill a paragraph.
3335 This function is used as the value of `fill-paragraph-function' in
3336 Message buffers and is not meant to be called directly."
3337 (interactive (list (if current-prefix-arg 'full)))
3338 (if (if (boundp 'filladapt-mode) filladapt-mode)
3340 (if (message-point-in-header-p)
3341 (message-fill-field)
3342 (message-newline-and-reformat arg t))
3345 (defun message-point-in-header-p ()
3346 "Return t if point is in the header."
3348 (not (re-search-backward
3349 (concat "^" (regexp-quote mail-header-separator) "\n") nil t))))
3351 (defun message-do-auto-fill ()
3352 "Like `do-auto-fill', but don't fill in message header."
3353 (unless (message-point-in-header-p)
3356 (defun message-insert-signature (&optional force)
3357 "Insert a signature. See documentation for variable `message-signature'."
3358 (interactive (list 0))
3361 ((and (null message-signature)
3364 (goto-char (point-max))
3365 (not (re-search-backward message-signature-separator nil t))))
3366 ((and (null message-signature)
3369 ((functionp message-signature)
3370 (funcall message-signature))
3371 ((listp message-signature)
3372 (eval message-signature))
3373 (t message-signature)))
3376 (cond ((stringp signature)
3378 ((and (eq t signature) message-signature-file)
3379 (setq signature-file
3380 (if (and message-signature-directory
3381 ;; don't actually use the signature directory
3382 ;; if message-signature-file contains a path.
3383 (not (file-name-directory
3384 message-signature-file)))
3385 (expand-file-name message-signature-file
3386 message-signature-directory)
3387 message-signature-file))
3388 (file-exists-p signature-file))))
3390 (goto-char (point-max))
3391 ;; Insert the signature.
3394 (when message-signature-insert-empty-line
3397 (if (eq signature t)
3398 (insert-file-contents signature-file)
3400 (goto-char (point-max))
3401 (or (bolp) (insert "\n")))))
3403 (defun message-insert-importance-high ()
3404 "Insert header to mark message as important."
3408 (message-narrow-to-headers)
3409 (message-remove-header "Importance"))
3411 (insert "Importance: high\n")))
3413 (defun message-insert-importance-low ()
3414 "Insert header to mark message as unimportant."
3418 (message-narrow-to-headers)
3419 (message-remove-header "Importance"))
3421 (insert "Importance: low\n")))
3423 (defun message-insert-or-toggle-importance ()
3424 "Insert a \"Importance: high\" header, or cycle through the header values.
3425 The three allowed values according to RFC 1327 are `high', `normal'
3432 (message-narrow-to-headers)
3433 (when (setq cur (message-fetch-field "Importance"))
3434 (message-remove-header "Importance")
3435 (setq new (cond ((string= cur "high")
3437 ((string= cur "low")
3442 (insert (format "Importance: %s\n" new)))))
3444 (defun message-insert-disposition-notification-to ()
3445 "Request a disposition notification (return receipt) to this message.
3446 Note that this should not be used in newsgroups."
3450 (message-narrow-to-headers)
3451 (message-remove-header "Disposition-Notification-To"))
3453 (insert (format "Disposition-Notification-To: %s\n"
3454 (or (message-field-value "Reply-to")
3455 (message-field-value "From")
3456 (message-make-from))))))
3458 (defun message-elide-region (b e)
3459 "Elide the text in the region.
3460 An ellipsis (from `message-elide-ellipsis') will be inserted where the
3464 (insert message-elide-ellipsis))
3466 (defvar message-caesar-translation-table nil)
3468 (defun message-caesar-region (b e &optional n)
3469 "Caesar rotate region B to E by N, default 13, for decrypting netnews."
3472 (min (point) (or (mark t) (point)))
3473 (max (point) (or (mark t) (point)))
3474 (when current-prefix-arg
3475 (prefix-numeric-value current-prefix-arg))))
3477 (setq n (if (numberp n) (mod n 26) 13)) ;canonize N
3478 (unless (or (zerop n) ; no action needed for a rot of 0
3479 (= b e)) ; no region to rotate
3480 ;; We build the table, if necessary.
3481 (when (or (not message-caesar-translation-table)
3482 (/= (aref message-caesar-translation-table ?a) (+ ?a n)))
3483 (setq message-caesar-translation-table
3484 (message-make-caesar-translation-table n)))
3485 (translate-region b e message-caesar-translation-table)))
3487 (defun message-make-caesar-translation-table (n)
3488 "Create a rot table with offset N."
3490 (table (make-string 256 0)))
3491 (while (< (incf i) 256)
3494 (substring table 0 ?A)
3495 (substring table (+ ?A n) (+ ?A n (- 26 n)))
3496 (substring table ?A (+ ?A n))
3497 (substring table (+ ?A 26) ?a)
3498 (substring table (+ ?a n) (+ ?a n (- 26 n)))
3499 (substring table ?a (+ ?a n))
3500 (substring table (+ ?a 26) 255))))
3502 (defun message-caesar-buffer-body (&optional rotnum wide)
3503 "Caesar rotate all letters in the current buffer by 13 places.
3504 Used to encode/decode possibly offensive messages (commonly in rec.humor).
3505 With prefix arg, specifies the number of places to rotate each letter forward.
3506 Mail and USENET news headers are not rotated unless WIDE is non-nil."
3507 (interactive (if current-prefix-arg
3508 (list (prefix-numeric-value current-prefix-arg))
3512 (when (and (not wide) (message-goto-body))
3513 (narrow-to-region (point) (point-max)))
3514 (message-caesar-region (point-min) (point-max) rotnum))))
3516 (defun message-pipe-buffer-body (program)
3517 "Pipe the message body in the current buffer through PROGRAM."
3520 (when (message-goto-body)
3521 (narrow-to-region (point) (point-max)))
3522 (shell-command-on-region
3523 (point-min) (point-max) program nil t))))
3525 (defun message-rename-buffer (&optional enter-string)
3526 "Rename the *message* buffer to \"*message* RECIPIENT\".
3527 If the function is run with a prefix, it will ask for a new buffer
3528 name, rather than giving an automatic name."
3529 (interactive "Pbuffer name: ")
3532 (goto-char (point-min))
3533 (narrow-to-region (point)
3534 (search-forward mail-header-separator nil 'end))
3536 (if (message-news-p) (message-fetch-field "Newsgroups")
3537 (message-fetch-field "To"))
3540 (if (string-match "," mail-to)
3541 (concat (substring mail-to 0 (match-beginning 0)) ", ...")
3543 (name-default (concat "*message* " mail-trimmed-to))
3544 (name (if enter-string
3545 (read-string "New buffer name: " name-default)
3547 (rename-buffer name t)))))
3549 (defun message-fill-yanked-message (&optional justifyp)
3550 "Fill the paragraphs of a message yanked into this one.
3551 Numeric argument means justify as well."
3554 (goto-char (point-min))
3555 (search-forward (concat "\n" mail-header-separator "\n") nil t)
3556 (let ((fill-prefix message-yank-prefix))
3557 (fill-individual-paragraphs (point) (point-max) justifyp))))
3559 (defun message-indent-citation (&optional start end yank-only)
3560 "Modify text just inserted from a message to be cited.
3561 The inserted text should be the region.
3562 When this function returns, the region is again around the modified text.
3564 Normally, indent each nonblank line `message-indentation-spaces' spaces.
3565 However, if `message-yank-prefix' is non-nil, insert that prefix on each line."
3566 (unless start (setq start (point)))
3568 ;; Remove unwanted headers.
3569 (when message-ignored-cited-headers
3574 (if (search-forward "\n\n" nil t)
3577 (message-remove-header message-ignored-cited-headers t)
3578 (when (= (point-min) (point-max))
3579 (setq all-removed t))
3580 (goto-char (point-max)))
3584 ;; Delete blank lines at the start of the buffer.
3585 (while (and (point-min)
3588 (message-delete-line))
3589 ;; Delete blank lines at the end of the buffer.
3590 (goto-char (point-max))
3593 (while (and (zerop (forward-line -1))
3595 (message-delete-line)))
3596 ;; Do the indentation.
3597 (if (null message-yank-prefix)
3598 (indent-rigidly start (or end (mark t)) message-indentation-spaces)
3601 (while (< (point) (or end (mark t)))
3602 (cond ((looking-at ">")
3603 (insert message-yank-cited-prefix))
3605 (insert message-yank-empty-prefix))
3607 (insert message-yank-prefix)))
3611 (defun message-remove-blank-cited-lines (&optional remove)
3612 "Remove cited lines containing only blanks.
3613 If REMOVE is non-nil, remove newlines, too.
3615 To use this automatically, you may add this function to
3616 `gnus-message-setup-hook'."
3621 (when (boundp 'message-yank-cited-prefix)
3622 (concat message-yank-cited-prefix "\\|"))
3626 (gnus-message 8 "removing `%s'" citexp)
3629 (while (re-search-forward citexp nil t)
3630 (replace-match (if remove "" "\n"))))))
3632 (defvar message-cite-reply-above nil
3633 "If non-nil, start own text above the quote.
3635 Note: Top posting is bad netiquette. Don't use it unless you
3636 really must. You probably want to set variable only for specific
3637 groups, e.g. using `gnus-posting-styles':
3639 (eval (set (make-local-variable 'message-cite-reply-above) t))
3641 This variable has no effect in news postings.")
3643 (defun message-yank-original (&optional arg)
3644 "Insert the message being replied to, if any.
3645 Puts point before the text and mark after.
3646 Normally indents each nonblank line ARG spaces (default 3). However,
3647 if `message-yank-prefix' is non-nil, insert that prefix on each line.
3649 This function uses `message-cite-function' to do the actual citing.
3651 Just \\[universal-argument] as argument means don't indent, insert no
3652 prefix, and don't delete any headers."
3654 (let ((modified (buffer-modified-p))
3656 (when (and message-reply-buffer
3657 message-cite-function)
3658 (when message-cite-reply-above
3659 (if (and (not (message-news-p))
3660 (or (eq message-cite-reply-above 'is-evil)
3662 Top posting is bad netiquette. Please don't top post unless you really must.
3663 Really top post? ")))
3666 (buffer-substring (message-goto-body)
3668 (delete-region (message-goto-body) (point-max)))
3669 (set (make-local-variable 'message-cite-reply-above) nil)))
3670 (if (bufferp message-reply-buffer)
3671 (delete-windows-on message-reply-buffer t))
3672 (push-mark (save-excursion
3674 ((bufferp message-reply-buffer)
3675 (insert-buffer-substring message-reply-buffer))
3676 ((and (consp message-reply-buffer)
3677 (functionp (car message-reply-buffer)))
3678 (apply (car message-reply-buffer)
3679 (cdr message-reply-buffer))))
3684 (funcall message-cite-function)
3685 (unless (eq (char-before (mark t)) ?\n)
3687 (goto-char (mark t))
3688 (insert-before-markers ?\n)
3690 (when message-cite-reply-above
3693 (insert (if (bolp) "\n" "\n\n"))
3694 (message-goto-body))
3695 ;; Add a `message-setup-very-last-hook' here?
3696 ;; Add `gnus-article-highlight-citation' here?
3698 (setq message-checksum (message-checksum))))))
3700 (defun message-yank-buffer (buffer)
3701 "Insert BUFFER into the current buffer and quote it."
3702 (interactive "bYank buffer: ")
3703 (let ((message-reply-buffer (get-buffer buffer)))
3704 (save-window-excursion
3705 (message-yank-original))))
3707 (defun message-buffers ()
3708 "Return a list of active message buffers."
3710 (save-current-buffer
3711 (dolist (buffer (buffer-list t))
3713 (when (and (eq major-mode 'message-mode)
3714 (null message-sent-message-via))
3715 (push (buffer-name buffer) buffers))))
3716 (nreverse buffers)))
3718 (defun message-cite-original-1 (strip-signature)
3719 "Cite an original message.
3720 If STRIP-SIGNATURE is non-nil, strips off the signature from the
3723 This function uses `mail-citation-hook' if that is non-nil."
3724 (if (and (boundp 'mail-citation-hook)
3726 (run-hooks 'mail-citation-hook)
3727 (let* ((start (point))
3731 (when message-indent-citation-function
3732 (if (listp message-indent-citation-function)
3733 message-indent-citation-function
3734 (list message-indent-citation-function))))
3735 ;; This function may be called by `gnus-summary-yank-message' and
3736 ;; may insert a different article from the original. So, we will
3737 ;; modify the value of `message-reply-headers' with that article.
3738 (message-reply-headers
3740 (narrow-to-region start end)
3741 (message-narrow-to-head-1)
3742 (setq x-no-archive (message-fetch-field "x-no-archive"))
3744 (or (message-fetch-field "subject") "none")
3745 (or (message-fetch-field "from") "nobody")
3746 (message-fetch-field "date")
3747 (message-fetch-field "message-id" t)
3748 (message-fetch-field "references")
3750 (mml-quote-region start end)
3751 (when strip-signature
3755 (when (re-search-backward message-signature-separator start t)
3756 ;; Also peel off any blank lines before the signature.
3758 (while (looking-at "^[ \t]*$")
3761 (delete-region (point) end)
3762 (unless (search-backward "\n\n" start t)
3763 ;; Insert a blank line if it is peeled off.
3766 (mapc 'funcall functions)
3767 (when message-citation-line-function
3770 (funcall message-citation-line-function))
3771 (when (and x-no-archive
3772 (not message-cite-articles-with-x-no-archive)
3773 (string-match "yes" x-no-archive))
3775 (delete-region (point) (mark t))
3776 (insert "> [Quoted text removed due to X-No-Archive]\n")
3778 (forward-line -1)))))
3780 (defun message-cite-original ()
3781 "Cite function in the standard Message manner."
3782 (message-cite-original-1 nil))
3784 (defvar gnus-extract-address-components)
3786 (autoload 'format-spec "format-spec")
3788 (defun message-insert-formatted-citation-line (&optional from date)
3789 "Function that inserts a formatted citation line.
3791 See `message-citation-line-format'."
3792 ;; The optional args are for testing/debugging. They will disappear later.
3794 ;; (with-temp-buffer
3795 ;; (message-insert-formatted-citation-line
3796 ;; "John Doe <john.doe@example.invalid>"
3799 (when (or message-reply-headers (and from date))
3801 (setq from (mail-header-from message-reply-headers)))
3802 (let* ((data (condition-case ()
3803 (funcall (if (boundp gnus-extract-address-components)
3804 gnus-extract-address-components
3805 'mail-extract-address-components)
3811 (net (car (cdr data)))
3812 (name-or-net (or (car data)
3813 (car (cdr data)) from))
3817 ;; We need Gnus functionality if the user wants date or time from
3818 ;; the original article:
3819 (when (string-match "%[^fnNFL]" message-citation-line-format)
3820 (autoload 'gnus-date-get-time "gnus-util")
3821 (gnus-date-get-time (mail-header-date message-reply-headers)))))
3824 (when (stringp name)
3825 ;; Guess first name and last name:
3826 (cond ((string-match
3827 "\\`\\(\\w\\|[-.]\\)+ \\(\\w\\|[-.]\\)+\\'" name)
3828 (setq fname (nth 0 (split-string name "[ \t]+"))
3829 lname (nth 1 (split-string name "[ \t]+"))))
3831 "\\`\\(\\w\\|[-.]\\)+, \\(\\w\\|[-.]\\)+\\'" name)
3832 (setq fname (nth 1 (split-string name "[ \t,]+"))
3833 lname (nth 0 (split-string name "[ \t,]+"))))
3835 "\\`\\(\\w\\|[-.]\\)+\\'" name)
3838 ;; The following letters are not used in `format-time-string':
3839 (push ?E lst) (push "<E>" lst)
3840 (push ?F lst) (push fname lst)
3841 ;; We might want to use "" instead of "<X>" later.
3842 (push ?J lst) (push "<J>" lst)
3843 (push ?K lst) (push "<K>" lst)
3844 (push ?L lst) (push lname lst)
3845 (push ?N lst) (push name-or-net lst)
3846 (push ?O lst) (push "<O>" lst)
3847 (push ?P lst) (push "<P>" lst)
3848 (push ?Q lst) (push "<Q>" lst)
3849 (push ?f lst) (push from lst)
3850 (push ?i lst) (push "<i>" lst)
3851 (push ?n lst) (push net lst)
3852 (push ?o lst) (push "<o>" lst)
3853 (push ?q lst) (push "<q>" lst)
3854 (push ?t lst) (push "<t>" lst)
3855 (push ?v lst) (push "<v>" lst)
3856 ;; Delegate the rest to `format-time-string':
3858 (when (and (not (memq i lst))
3863 (push (condition-case nil
3864 (format-time-string (format "%%%c" i) replydate)
3865 (error (format ">%c<" i)))
3869 (spec (apply 'format-spec-make flist)))
3870 (insert (format-spec message-citation-line-format spec)))
3873 (defun message-cite-original-without-signature ()
3874 "Cite function in the standard Message manner.
3875 This function strips off the signature from the original message."
3876 (message-cite-original-1 t))
3878 (defun message-insert-citation-line ()
3879 "Insert a simple citation line."
3880 (when message-reply-headers
3881 (insert (mail-header-from message-reply-headers) " writes:")
3885 (defun message-position-on-field (header &rest afters)
3886 (let ((case-fold-search t))
3889 (goto-char (point-min))
3892 (concat "^" (regexp-quote mail-header-separator) "$"))
3893 (match-beginning 0)))
3894 (goto-char (point-min))
3895 (if (re-search-forward (concat "^" (regexp-quote header) ":") nil t)
3897 (re-search-forward "^[^ \t]" nil 'move)
3899 (skip-chars-backward "\n")
3902 (not (re-search-forward
3903 (concat "^" (regexp-quote (car afters)) ":")
3907 (re-search-forward "^[^ \t]" nil 'move)
3908 (beginning-of-line))
3909 (insert header ": \n")
3913 (defun message-remove-signature ()
3914 "Remove the signature from the text between point and mark.
3915 The text will also be indented the normal way."
3917 (let ((start (point))
3919 (if (not (re-search-forward message-signature-separator (mark t) t))
3920 ;; No signature here, so we just indent the cited text.
3921 (message-indent-citation)
3922 ;; Find the last non-empty line.
3924 (while (looking-at "[ \t]*$")
3927 (setq mark (set-marker (make-marker) (point)))
3929 (message-indent-citation)
3930 ;; Enable undoing the deletion.
3932 (delete-region mark (mark t))
3933 (set-marker mark nil)))))
3938 ;;; Sending messages
3941 (defun message-send-and-exit (&optional arg)
3942 "Send message like `message-send', then, if no errors, exit from mail buffer."
3944 (let ((buf (current-buffer))
3945 (actions message-exit-actions))
3946 (when (and (message-send arg)
3948 (if message-kill-buffer-on-exit
3951 (when (eq buf (current-buffer))
3952 (message-bury buf)))
3953 (message-do-actions actions)
3956 (defun message-dont-send ()
3957 "Don't send the message you have been editing.
3958 Instead, just auto-save the buffer and then bury it."
3960 (set-buffer-modified-p t)
3962 (let ((actions message-postpone-actions))
3963 (message-bury (current-buffer))
3964 (message-do-actions actions)))
3966 (defun message-kill-buffer ()
3967 "Kill the current buffer."
3969 (when (or (not (buffer-modified-p))
3970 (not message-kill-buffer-query)
3971 (yes-or-no-p "Message modified; kill anyway? "))
3972 (let ((actions message-kill-actions)
3973 (draft-article message-draft-article)
3974 (auto-save-file-name buffer-auto-save-file-name)
3975 (file-name buffer-file-name)
3976 (modified (buffer-modified-p)))
3977 (setq buffer-file-name nil)
3978 (kill-buffer (current-buffer))
3979 (when (and (or (and auto-save-file-name
3980 (file-exists-p auto-save-file-name))
3982 (file-exists-p file-name)))
3984 ;; If the message buffer has lived in a dedicated window,
3985 ;; `kill-buffer' has killed the frame. Thus the
3986 ;; `yes-or-no-p' may show up in a lowered frame. Make sure
3987 ;; that the user can see the question by raising the
3990 (yes-or-no-p (format "Remove the backup file%s? "
3991 (if modified " too" "")))))
3993 (delete-file auto-save-file-name))
3994 (let ((message-draft-article draft-article))
3995 (message-disassociate-draft)))
3996 (message-do-actions actions))))
3998 (defun message-bury (buffer)
3999 "Bury this mail BUFFER."
4000 (let ((newbuf (other-buffer buffer)))
4001 (bury-buffer buffer)
4002 (if (and (window-dedicated-p (selected-window))
4003 (not (null (delq (selected-frame) (visible-frame-list)))))
4004 (delete-frame (selected-frame))
4005 (switch-to-buffer newbuf))))
4007 (defun message-send (&optional arg)
4008 "Send the message in the current buffer.
4009 If `message-interactive' is non-nil, wait for success indication or
4010 error messages, and inform user.
4011 Otherwise any failure is reported in a message back to the user from
4013 The usage of ARG is defined by the instance that called Message.
4014 It should typically alter the sending method in some way or other."
4016 ;; Make it possible to undo the coming changes.
4018 (let ((inhibit-read-only t))
4019 (put-text-property (point-min) (point-max) 'read-only nil))
4020 (message-fix-before-sending)
4021 (run-hooks 'message-send-hook)
4022 (when message-confirm-send
4023 (or (y-or-n-p "Send message? ")
4025 (message message-sending-message)
4026 (let ((alist message-send-method-alist)
4028 elem sent dont-barf-on-no-method
4029 (message-options message-options))
4030 (message-options-set-recipient)
4032 (setq elem (pop alist)))
4033 (when (funcall (cadr elem))
4034 (when (and (or (not (memq (car elem)
4035 message-sent-message-via))
4036 (message-fetch-field "supersedes")
4037 (if (or (message-gnksa-enable-p 'multiple-copies)
4038 (not (eq (car elem) 'news)))
4041 "Already sent message via %s; resend? "
4043 (error "Denied posting -- multiple copies")))
4044 (setq success (funcall (caddr elem) arg)))
4048 (let ((fcc (message-fetch-field "Fcc"))
4049 (gcc (message-fetch-field "Gcc")))
4051 (or (eq message-allow-no-recipients 'always)
4052 (and (not (eq message-allow-no-recipients 'never))
4053 (setq dont-barf-on-no-method
4055 (format "No receiver, perform %s anyway? "
4056 (cond ((and fcc gcc) "Fcc and Gcc")
4059 (error "No methods specified to send by"))
4060 (when (or dont-barf-on-no-method
4064 (run-hooks 'message-sent-hook))
4065 (message "Sending...done")
4066 ;; Do ecomplete address snarfing.
4067 (when (message-mail-alias-type-p 'ecomplete)
4068 (message-put-addresses-in-ecomplete))
4069 ;; Mark the buffer as unmodified and delete auto-save.
4070 (set-buffer-modified-p nil)
4071 (delete-auto-save-file-if-necessary t)
4072 (message-disassociate-draft)
4073 ;; Delete other mail buffers and stuff.
4074 (message-do-send-housekeeping)
4075 (message-do-actions message-send-actions)
4079 (defun message-send-via-mail (arg)
4080 "Send the current message via mail."
4081 (message-send-mail arg))
4083 (defun message-send-via-news (arg)
4084 "Send the current message via news."
4085 (funcall message-send-news-function arg))
4087 (defmacro message-check (type &rest forms)
4088 "Eval FORMS if TYPE is to be checked."
4089 `(or (message-check-element ,type)
4093 (put 'message-check 'lisp-indent-function 1)
4094 (put 'message-check 'edebug-form-spec '(form body))
4096 (defun message-text-with-property (prop &optional start end reverse)
4097 "Return a list of start and end positions where the text has PROP.
4098 START and END bound the search, they default to `point-min' and
4099 `point-max' respectively. If REVERSE is non-nil, find text which does
4102 (setq start (point-min)))
4104 (setq end (point-max)))
4108 (setq start (text-property-any start end prop nil)))
4109 (setq next (next-single-property-change start prop nil end))
4110 (push (cons start (or next end)) regions)
4113 (or (get-text-property start prop)
4114 (and (setq start (next-single-property-change
4115 start prop nil end))
4116 (get-text-property start prop))))
4117 (setq next (text-property-any start end prop nil))
4118 (push (cons start (or next end)) regions)
4120 (nreverse regions)))
4122 (defcustom message-bogus-addresses
4123 ;; '("noreply" "nospam" "invalid")
4124 '("noreply" "nospam" "invalid" "@@" "[^[:ascii:]].*@" "[ \t]")
4125 "List of regexps of potentially bogus mail addresses.
4126 See `message-check-recipients' how to setup checking.
4128 This list should make it possible to catch typos or warn about
4129 spam-trap addresses. It doesn't aim to verify strict RFC
4131 :version "23.1" ;; No Gnus
4132 :group 'message-headers
4134 (const :tag "None" nil)
4140 (const :tag "duplicate @" "@@")
4141 (const :tag "non-ascii local part" "[^[:ascii:]].*@")
4142 ;; Already caught by `message-valid-fqdn-regexp'
4143 ;; (const :tag "`_' in domain part" "@.*_")
4144 (const :tag "whitespace" "[ \t]"))
4149 (defun message-fix-before-sending ()
4150 "Do various things to make the message nice before sending it."
4151 ;; Make sure there's a newline at the end of the message.
4152 (goto-char (point-max))
4155 ;; Make the hidden headers visible.
4157 ;; Sort headers before sending the message.
4158 (message-sort-headers)
4159 ;; Make invisible text visible.
4160 ;; It doesn't seem as if this is useful, since the invisible property
4161 ;; is clobbered by an after-change hook anyhow.
4162 (message-check 'invisible-text
4163 (let ((regions (message-text-with-property 'invisible))
4167 (setq from (caar regions)
4169 regions (cdr regions))
4170 (put-text-property from to 'invisible nil)
4171 (message-overlay-put (message-make-overlay from to)
4173 (unless (yes-or-no-p
4174 "Invisible text found and made visible; continue sending? ")
4175 (error "Invisible text found and made visible")))))
4176 (message-check 'illegible-text
4177 (let (char found choice)
4180 (skip-chars-forward mm-7bit-chars)
4181 (when (get-text-property (point) 'no-illegible-text)
4182 ;; There is a signed or encrypted raw message part
4183 ;; that is considered to be safe.
4184 (goto-char (or (next-single-property-change
4185 (point) 'no-illegible-text)
4187 (setq char (char-after)))
4188 (when (or (< (mm-char-int char) 128)
4189 (and (mm-multibyte-p)
4190 (memq (char-charset char)
4191 '(eight-bit-control eight-bit-graphic
4192 ;; Emacs 23, Bug#1770:
4195 (not (get-text-property
4196 (point) 'untranslated-utf-8))))
4197 (message-overlay-put (message-make-overlay (point) (1+ (point)))
4203 (gnus-multiple-choice
4204 "Non-printable characters found. Continue sending?"
4205 `((?d "Remove non-printable characters and send")
4207 "Replace non-printable characters with \"%s\" and send"
4208 message-replacement-char))
4209 (?i "Ignore non-printable characters and send")
4210 (?e "Continue editing"))))
4212 (error "Non-printable characters"))
4214 (skip-chars-forward mm-7bit-chars)
4216 (when (let ((char (char-after)))
4217 (or (< (mm-char-int char) 128)
4218 (and (mm-multibyte-p)
4219 ;; FIXME: Wrong for Emacs 23 (unicode) and for
4220 ;; things like undecodable utf-8 (in Emacs 21?).
4221 ;; Should at least use find-coding-systems-region.
4223 (memq (char-charset char)
4224 '(eight-bit-control eight-bit-graphic
4225 ;; Emacs 23, Bug#1770:
4228 (not (get-text-property
4229 (point) 'untranslated-utf-8)))))
4231 (message-kill-all-overlays)
4233 (when (eq choice ?r)
4234 (insert message-replacement-char))))
4236 (skip-chars-forward mm-7bit-chars)))))
4237 (message-check 'bogus-recipient
4238 ;; Warn before sending a mail to an invalid address.
4239 (message-check-recipients)))
4241 (defun message-bogus-recipient-p (recipients)
4242 "Check if a mail address in RECIPIENTS looks bogus.
4244 RECIPIENTS is a mail header. Return a list of potentially bogus
4245 addresses. If none is found, return nil.
4247 An address might be bogus if the domain part is not fully
4248 qualified, see `message-valid-fqdn-regexp', or if there's a
4249 matching entry in `message-bogus-addresses'."
4250 ;; FIXME: How about "foo@subdomain", when the MTA adds ".domain.tld"?
4252 (mapc (lambda (address)
4253 (setq address (cadr address))
4257 (not (string-match "@" address))
4260 message-valid-fqdn-regexp "\\)\\'") address)))
4261 (and message-bogus-addresses
4263 (if (listp message-bogus-addresses)
4264 (mapconcat 'identity
4265 message-bogus-addresses
4267 message-bogus-addresses)))
4268 (string-match re address))))
4269 (push address found)))
4271 (mail-extract-address-components recipients t))
4274 (defun message-check-recipients ()
4275 "Warn before composing or sending a mail to an invalid address.
4277 This function could be useful in `message-setup-hook'."
4280 (message-narrow-to-headers)
4281 (dolist (hdr '("To" "Cc" "Bcc"))
4282 (let ((addr (message-fetch-field hdr)))
4283 (when (stringp addr)
4284 (dolist (bog (message-bogus-recipient-p addr))
4288 "Address `%s' might be bogus. Continue? " bog)))
4289 (error "Bogus address"))))))))
4291 (custom-add-option 'message-setup-hook 'message-check-recipients)
4293 (defun message-add-action (action &rest types)
4294 "Add ACTION to be performed when doing an exit of type TYPES."
4296 (add-to-list (intern (format "message-%s-actions" (pop types)))
4299 (defun message-delete-action (action &rest types)
4300 "Delete ACTION from lists of actions performed when doing an exit of type TYPES."
4303 (set (setq var (intern (format "message-%s-actions" (pop types))))
4304 (delq action (symbol-value var))))))
4306 (defun message-do-actions (actions)
4307 "Perform all actions in ACTIONS."
4308 ;; Now perform actions on successful sending.
4309 (dolist (action actions)
4312 ;; A simple function.
4315 ;; Something to be evaled.
4319 (defun message-send-mail-partially ()
4320 "Send mail as message/partial."
4321 ;; replace the header delimiter with a blank line
4322 (goto-char (point-min))
4324 (concat "^" (regexp-quote mail-header-separator) "\n"))
4325 (replace-match "\n")
4326 (run-hooks 'message-send-mail-hook)
4327 (let ((p (goto-char (point-min)))
4328 (tembuf (message-generate-new-buffer-clone-locals " message temp"))
4329 (curbuf (current-buffer))
4330 (id (message-make-message-id)) (n 1)
4331 plist total header required-mail-headers)
4333 (if (< (point-max) (+ p message-send-mail-partially-limit))
4334 (goto-char (point-max))
4335 (goto-char (+ p message-send-mail-partially-limit))
4337 (if (<= (point) p) (forward-line 1))) ;; In case of bad message.
4340 (setq total (length plist))
4341 (push (point-max) plist)
4342 (setq plist (nreverse plist))
4345 (setq p (pop plist))
4348 (copy-to-buffer tembuf p (car plist))
4350 (goto-char (point-min))
4353 (goto-char (point-min))
4354 (narrow-to-region (point) (point))
4357 (setq header (buffer-substring (point-min) (point)))
4358 (goto-char (point-min))
4359 (narrow-to-region (point) (point))
4361 (message-remove-header "Mime-Version")
4362 (message-remove-header "Content-Type")
4363 (message-remove-header "Content-Transfer-Encoding")
4364 (message-remove-header "Message-ID")
4365 (message-remove-header "Lines")
4366 (goto-char (point-max))
4367 (insert "Mime-Version: 1.0\n")
4368 (setq header (buffer-string)))
4369 (goto-char (point-max))
4370 (insert (format "Content-Type: message/partial; id=\"%s\"; number=%d; total=%d\n\n"
4373 (let ((mail-header-separator ""))
4374 (when (memq 'Message-ID message-required-mail-headers)
4375 (insert "Message-ID: " (message-make-message-id) "\n"))
4376 (when (memq 'Lines message-required-mail-headers)
4377 (insert "Lines: " (message-make-lines) "\n"))
4378 (message-goto-subject)
4380 (insert (format " (%d/%d)" n total))
4382 (funcall (or message-send-mail-real-function
4383 message-send-mail-function)))
4385 (setq p (pop plist))
4387 (kill-buffer tembuf))))
4389 (declare-function hashcash-wait-async "hashcash" (&optional buffer))
4391 (defun message-send-mail (&optional arg)
4392 (require 'mail-utils)
4393 (let* ((tembuf (message-generate-new-buffer-clone-locals " message temp"))
4394 (case-fold-search nil)
4395 (news (message-news-p))
4396 (mailbuf (current-buffer))
4397 (message-this-is-mail t)
4398 ;; gnus-setup-posting-charset is autoloaded in mml.el (FIXME
4399 ;; maybe it should not be), which this file requires. Hence
4400 ;; the fboundp test is always true. Loading it from gnus-msg
4401 ;; loads many Gnus files (Bug#5642). If
4402 ;; gnus-group-posting-charset-alist hasn't been customized,
4403 ;; this is just going to return nil anyway. FIXME it would
4404 ;; be good to improve this further, because even if g-g-p-c-a
4405 ;; has been customized, that is likely to just be for news.
4406 ;; Eg either move the definition from gnus-msg, or separate out
4407 ;; the mail and news parts.
4408 (message-posting-charset
4409 (if (and (fboundp 'gnus-setup-posting-charset)
4410 (boundp 'gnus-group-posting-charset-alist))
4411 (gnus-setup-posting-charset nil)
4412 message-posting-charset))
4413 (headers message-required-mail-headers))
4414 (when (and message-generate-hashcash
4415 (not (eq message-generate-hashcash 'opportunistic)))
4416 (message "Generating hashcash...")
4418 ;; Wait for calculations already started to finish...
4419 (hashcash-wait-async)
4420 ;; ...and do calculations not already done. mail-add-payment
4421 ;; will leave existing X-Hashcash headers alone.
4423 (message "Generating hashcash...done"))
4425 (message-narrow-to-headers)
4426 ;; Generate the Mail-Followup-To header if the header is not there...
4427 (if (and (message-subscribed-p)
4428 (not (mail-fetch-field "mail-followup-to")))
4431 (cons "Mail-Followup-To" (message-make-mail-followup-to))
4432 message-required-mail-headers))
4433 ;; otherwise, delete the MFT header if the field is empty
4434 (when (equal "" (mail-fetch-field "mail-followup-to"))
4435 (message-remove-header "^Mail-Followup-To:")))
4436 ;; Insert some headers.
4437 (let ((message-deletable-headers
4438 (if news nil message-deletable-headers)))
4439 (message-generate-headers headers))
4440 ;; Check continuation headers.
4441 (message-check 'continuation-headers
4442 (goto-char (point-min))
4443 (while (re-search-forward "^[^ \t\n][^ \t\n:]*[ \t\n]" nil t)
4444 (goto-char (match-beginning 0))
4445 (if (y-or-n-p "Fix continuation lines? ")
4448 (unless (y-or-n-p "Send anyway? ")
4449 (error "Failed to send the message")))))
4450 ;; Let the user do all of the above.
4451 (run-hooks 'message-header-hook))
4453 (with-current-buffer tembuf
4455 ;; Avoid copying text props (except hard newlines).
4456 (insert (with-current-buffer mailbuf
4457 (mml-buffer-substring-no-properties-except-hard-newlines
4458 (point-min) (point-max))))
4459 ;; Remove some headers.
4460 (message-encode-message-body)
4462 (message-narrow-to-headers)
4463 ;; We (re)generate the Lines header.
4464 (when (memq 'Lines message-required-mail-headers)
4465 (message-generate-headers '(Lines)))
4466 ;; Remove some headers.
4467 (message-remove-header message-ignored-mail-headers t)
4468 (let ((mail-parse-charset message-default-charset))
4469 (mail-encode-encoded-word-buffer)))
4470 (goto-char (point-max))
4471 ;; require one newline at the end.
4472 (or (= (preceding-char) ?\n)
4474 (message-cleanup-headers)
4475 ;; FIXME: we're inserting the courtesy copy after encoding.
4476 ;; This is wrong if the courtesy copy string contains
4477 ;; non-ASCII characters. -- jh
4480 (message-narrow-to-headers)
4482 (or (message-fetch-field "cc")
4483 (message-fetch-field "bcc")
4484 (message-fetch-field "to"))
4485 (let ((content-type (message-fetch-field
4490 (string= "text/plain"
4492 (mail-header-parse-content-type
4496 (message-fetch-field
4497 "content-transfer-encoding")))))))
4498 (message-insert-courtesy-copy))
4499 ;; Let's make sure we encoded all the body.
4500 (assert (save-excursion
4501 (goto-char (point-min))
4502 (not (re-search-forward "[^\000-\377]" nil t))))
4503 (mm-disable-multibyte)
4504 (if (or (not message-send-mail-partially-limit)
4505 (< (buffer-size) message-send-mail-partially-limit)
4506 (not (message-y-or-n-p
4507 "The message size is too large, split? "
4511 (/ (buffer-size) 1000) "KB, is too large.
4513 Some mail gateways (MTA's) bounce large messages. To avoid the
4514 problem, answer `y', and the message will be split into several
4515 smaller pieces, the size of each is about "
4516 (/ message-send-mail-partially-limit 1000)
4520 However, some mail readers (MUA's) can't read split messages, i.e.,
4521 mails in message/partially format. Answer `n', and the message will be
4524 The size limit is controlled by `message-send-mail-partially-limit'.
4525 If you always want Gnus to send messages in one piece, set
4526 `message-send-mail-partially-limit' to nil.
4529 (message "Sending via mail...")
4530 (funcall (or message-send-mail-real-function
4531 message-send-mail-function)))
4532 (message-send-mail-partially)))
4533 (kill-buffer tembuf))
4534 (set-buffer mailbuf)
4535 (push 'mail message-sent-message-via)))
4537 (defun message-send-mail-with-sendmail ()
4538 "Send off the prepared buffer with sendmail."
4540 (let ((errbuf (if message-interactive
4541 (message-generate-new-buffer-clone-locals
4544 resend-to-addresses delimline)
4547 (let ((case-fold-search t))
4549 (message-narrow-to-headers)
4550 (setq resend-to-addresses (message-fetch-field "resent-to")))
4551 ;; Change header-delimiter to be what sendmail expects.
4552 (goto-char (point-min))
4554 (concat "^" (regexp-quote mail-header-separator) "\n"))
4555 (replace-match "\n")
4557 (setq delimline (point-marker))
4558 (run-hooks 'message-send-mail-hook)
4559 ;; Insert an extra newline if we need it to work around
4560 ;; Sun's bug that swallows newlines.
4561 (goto-char (1+ delimline))
4562 (when (eval message-mailer-swallows-blank-line)
4564 (when message-interactive
4565 (with-current-buffer errbuf
4567 (let* ((default-directory "/")
4568 (coding-system-for-write message-send-coding-system)
4570 'call-process-region
4572 (list (point-min) (point-max)
4573 (cond ((boundp 'sendmail-program)
4575 ((file-exists-p "/usr/sbin/sendmail")
4576 "/usr/sbin/sendmail")
4577 ((file-exists-p "/usr/lib/sendmail")
4578 "/usr/lib/sendmail")
4579 ((file-exists-p "/usr/ucblib/sendmail")
4580 "/usr/ucblib/sendmail")
4582 nil errbuf nil "-oi")
4583 message-sendmail-extra-arguments
4584 ;; Always specify who from,
4585 ;; since some systems have broken sendmails.
4586 ;; But some systems are more broken with -f, so
4587 ;; we'll let users override this.
4588 (and (null message-sendmail-f-is-evil)
4589 (list "-f" (message-sendmail-envelope-from)))
4590 ;; These mean "report errors by mail"
4591 ;; and "deliver in background".
4592 (if (null message-interactive) '("-oem" "-odb"))
4593 ;; Get the addresses from the message
4594 ;; unless this is a resend.
4595 ;; We must not do that for a resend
4596 ;; because we would find the original addresses.
4597 ;; For a resend, include the specific addresses.
4598 (if resend-to-addresses
4599 (list resend-to-addresses)
4601 (unless (or (null cpr) (and (numberp cpr) (zerop cpr)))
4602 (if errbuf (pop-to-buffer errbuf))
4603 (error "Sending...failed with exit value %d" cpr)))
4604 (when message-interactive
4605 (with-current-buffer errbuf
4606 (goto-char (point-min))
4607 (while (re-search-forward "\n+ *" nil t)
4608 (replace-match "; "))
4609 (if (not (zerop (buffer-size)))
4610 (error "Sending...failed to %s"
4611 (buffer-string))))))
4612 (when (bufferp errbuf)
4613 (kill-buffer errbuf)))))
4615 (defun message-send-mail-with-qmail ()
4616 "Pass the prepared message buffer to qmail-inject.
4617 Refer to the documentation for the variable `message-send-mail-function'
4618 to find out how to use this."
4619 ;; replace the header delimiter with a blank line
4620 (goto-char (point-min))
4622 (concat "^" (regexp-quote mail-header-separator) "\n"))
4623 (replace-match "\n")
4624 (run-hooks 'message-send-mail-hook)
4627 (let ((coding-system-for-write message-send-coding-system))
4629 'call-process-region (point-min) (point-max)
4630 message-qmail-inject-program nil nil nil
4631 ;; qmail-inject's default behavior is to look for addresses on the
4632 ;; command line; if there're none, it scans the headers.
4633 ;; yes, it does The Right Thing w.r.t. Resent-To and it's kin.
4635 ;; in general, ALL of qmail-inject's defaults are perfect for simply
4636 ;; reading a formatted (i. e., at least a To: or Resent-To header)
4637 ;; message from stdin.
4639 ;; qmail also has the advantage of not having been raped by
4640 ;; various vendors, so we don't have to allow for that, either --
4641 ;; compare this with message-send-mail-with-sendmail and weep
4642 ;; for sendmail's lost innocence.
4644 ;; all this is way cool coz it lets us keep the arguments entirely
4645 ;; free for -inject-arguments -- a big win for the user and for us
4646 ;; since we don't have to play that double-guessing game and the user
4647 ;; gets full control (no gestapo'ish -f's, for instance). --sj
4648 (if (functionp message-qmail-inject-args)
4649 (funcall message-qmail-inject-args)
4650 message-qmail-inject-args)))
4651 ;; qmail-inject doesn't say anything on it's stdout/stderr,
4652 ;; we have to look at the retval instead
4654 (100 (error "qmail-inject reported permanent failure"))
4655 (111 (error "qmail-inject reported transient failure"))
4656 ;; should never happen
4657 (t (error "qmail-inject reported unknown failure"))))
4659 (defun message-send-mail-with-mh ()
4660 "Send the prepared message buffer with mh."
4661 (let ((mh-previous-window-config nil)
4662 (name (mh-new-draft-name)))
4663 (setq buffer-file-name name)
4664 ;; MH wants to generate these headers itself.
4665 (when message-mh-deletable-headers
4666 (let ((headers message-mh-deletable-headers))
4668 (goto-char (point-min))
4669 (and (re-search-forward
4670 (concat "^" (symbol-name (car headers)) ": *") nil t)
4671 (message-delete-line))
4673 (run-hooks 'message-send-mail-hook)
4674 ;; Pass it on to mh.
4677 (defun message-smtpmail-send-it ()
4678 "Send the prepared message buffer with `smtpmail-send-it'.
4679 The only difference from `smtpmail-send-it' is that this command
4680 evaluates `message-send-mail-hook' just before sending a message.
4681 It is useful if your ISP requires the POP-before-SMTP
4682 authentication. See the Gnus manual for details."
4683 (run-hooks 'message-send-mail-hook)
4686 (defun message-send-mail-with-mailclient ()
4687 "Send the prepared message buffer with `mailclient-send-it'.
4688 The only difference from `mailclient-send-it' is that this
4689 command evaluates `message-send-mail-hook' just before sending a message."
4690 (run-hooks 'message-send-mail-hook)
4691 (mailclient-send-it))
4693 (defun message-canlock-generate ()
4694 "Return a string that is non-trivial to guess.
4695 Do not use this for anything important, it is cryptographically weak."
4697 (let (sha1-maximum-internal-length)
4698 (sha1 (concat (message-unique-id)
4699 (format "%x%x%x" (random) (random t) (random))
4700 (prin1-to-string (recent-keys))
4701 (prin1-to-string (garbage-collect))))))
4703 (defvar canlock-password)
4704 (defvar canlock-password-for-verify)
4706 (defun message-canlock-password ()
4707 "The password used by message for cancel locks.
4708 This is the value of `canlock-password', if that option is non-nil.
4709 Otherwise, generate and save a value for `canlock-password' first."
4711 (unless canlock-password
4712 (customize-save-variable 'canlock-password (message-canlock-generate))
4713 (setq canlock-password-for-verify canlock-password))
4716 (defun message-insert-canlock ()
4717 (when message-insert-canlock
4718 (message-canlock-password)
4719 (canlock-insert-header)))
4721 (autoload 'nnheader-get-report "nnheader")
4723 (declare-function gnus-setup-posting-charset "gnus-msg" (group))
4725 (defun message-send-news (&optional arg)
4727 (let* ((tembuf (message-generate-new-buffer-clone-locals " *message temp*"))
4728 (case-fold-search nil)
4729 (method (if (functionp message-post-method)
4730 (funcall message-post-method arg)
4731 message-post-method))
4732 (newsgroups-field (save-restriction
4733 (message-narrow-to-headers-or-head)
4734 (message-fetch-field "Newsgroups")))
4735 (followup-field (save-restriction
4736 (message-narrow-to-headers-or-head)
4737 (message-fetch-field "Followup-To")))
4738 ;; BUG: We really need to get the charset for each name in the
4739 ;; Newsgroups and Followup-To lines to allow crossposting
4740 ;; between group namess with incompatible character sets.
4741 ;; -- Per Abrahamsen <abraham@dina.kvl.dk> 2001-10-08.
4742 (group-field-charset
4743 (gnus-group-name-charset method newsgroups-field))
4744 (followup-field-charset
4745 (gnus-group-name-charset method (or followup-field "")))
4746 (rfc2047-header-encoding-alist
4747 (append (when group-field-charset
4748 (list (cons "Newsgroups" group-field-charset)))
4749 (when followup-field-charset
4750 (list (cons "Followup-To" followup-field-charset)))
4751 rfc2047-header-encoding-alist))
4752 (messbuf (current-buffer))
4753 (message-syntax-checks
4755 (listp message-syntax-checks))
4756 (cons '(existing-newsgroups . disabled)
4757 message-syntax-checks)
4758 message-syntax-checks))
4759 (message-this-is-news t)
4760 (message-posting-charset
4761 (gnus-setup-posting-charset newsgroups-field))
4763 (if (not (message-check-news-body-syntax))
4766 (message-narrow-to-headers)
4767 ;; Insert some headers.
4768 (message-generate-headers message-required-news-headers)
4769 (message-insert-canlock)
4770 ;; Let the user do all of the above.
4771 (run-hooks 'message-header-hook))
4772 ;; Note: This check will be disabled by the ".*" default value for
4773 ;; gnus-group-name-charset-group-alist. -- Pa 2001-10-07.
4774 (when (and group-field-charset
4775 (listp message-syntax-checks))
4776 (setq message-syntax-checks
4777 (cons '(valid-newsgroups . disabled)
4778 message-syntax-checks)))
4779 (message-cleanup-headers)
4780 (if (not (let ((message-post-method method))
4781 (message-check-news-syntax)))
4784 (with-current-buffer tembuf
4785 (buffer-disable-undo)
4787 ;; Avoid copying text props (except hard newlines).
4789 (with-current-buffer messbuf
4790 (mml-buffer-substring-no-properties-except-hard-newlines
4791 (point-min) (point-max))))
4792 (message-encode-message-body)
4793 ;; Remove some headers.
4795 (message-narrow-to-headers)
4796 ;; We (re)generate the Lines header.
4797 (when (memq 'Lines message-required-mail-headers)
4798 (message-generate-headers '(Lines)))
4799 ;; Remove some headers.
4800 (message-remove-header message-ignored-news-headers t)
4801 (let ((mail-parse-charset message-default-charset))
4802 (mail-encode-encoded-word-buffer)))
4803 (goto-char (point-max))
4804 ;; require one newline at the end.
4805 (or (= (preceding-char) ?\n)
4807 (let ((case-fold-search t))
4808 ;; Remove the delimiter.
4809 (goto-char (point-min))
4811 (concat "^" (regexp-quote mail-header-separator) "\n"))
4812 (replace-match "\n")
4814 (run-hooks 'message-send-news-hook)
4815 (gnus-open-server method)
4816 (message "Sending news via %s..." (gnus-server-string method))
4817 (setq result (let ((mail-header-separator ""))
4818 (gnus-request-post method))))
4819 (kill-buffer tembuf))
4820 (set-buffer messbuf)
4822 (push 'news message-sent-message-via)
4823 (message "Couldn't send message via news: %s"
4824 (nnheader-get-report (car method)))
4828 ;;; Header generation & syntax checking.
4831 (defun message-check-element (type)
4832 "Return non-nil if this TYPE is not to be checked."
4833 (if (eq message-syntax-checks 'dont-check-for-anything-just-trust-me)
4835 (let ((able (assq type message-syntax-checks)))
4837 (eq (cdr able) 'disabled)))))
4839 (defun message-check-news-syntax ()
4840 "Check the syntax of the message."
4844 ;; We narrow to the headers and check them first.
4847 (message-narrow-to-headers)
4848 (message-check-news-header-syntax))))))
4850 (defun message-check-news-header-syntax ()
4852 ;; Check Newsgroups header.
4853 (message-check 'newsgroups
4854 (let ((group (message-fetch-field "newsgroups")))
4857 (not (string-match "\\`[ \t]*\\'" group)))
4860 "The newsgroups field is empty or missing. Posting is denied.")))))
4861 ;; Check the Subject header.
4862 (message-check 'subject
4863 (let* ((case-fold-search t)
4864 (subject (message-fetch-field "subject")))
4867 (not (string-match "\\`[ \t]*\\'" subject)))
4870 "The subject field is empty or missing. Posting is denied.")))))
4871 ;; Check for commands in Subject.
4872 (message-check 'subject-cmsg
4873 (if (string-match "^cmsg " (message-fetch-field "subject"))
4875 "The control code \"cmsg\" is in the subject. Really post? ")
4877 ;; Check long header lines.
4878 (message-check 'long-header-lines
4879 (let ((start (point))
4883 (while (and (not found)
4884 (re-search-forward "^\\([^ \t:]+\\): " nil t))
4885 (if (> (- (point) (match-beginning 0)) 998)
4887 length (- (point) (match-beginning 0)))
4888 (setq header (match-string-no-properties 1)))
4889 (setq start (match-beginning 0))
4892 (y-or-n-p (format "Your %s header is too long (%d). Really post? "
4895 ;; Check for multiple identical headers.
4896 (message-check 'multiple-headers
4898 (while (and (not found)
4899 (re-search-forward "^[^ \t:]+: " nil t))
4901 (or (re-search-forward
4906 (match-beginning 0) (- (match-end 0) 2))))
4911 (y-or-n-p (format "Multiple %s headers. Really post? " found))
4913 ;; Check for Version and Sendsys.
4914 (message-check 'sendsys
4915 (if (re-search-forward "^Sendsys:\\|^Version:" nil t)
4917 (format "The article contains a %s command. Really post? "
4918 (buffer-substring (match-beginning 0)
4919 (1- (match-end 0)))))
4921 ;; See whether we can shorten Followup-To.
4922 (message-check 'shorten-followup-to
4923 (let ((newsgroups (message-fetch-field "newsgroups"))
4924 (followup-to (message-fetch-field "followup-to"))
4926 (when (and newsgroups
4927 (string-match "," newsgroups)
4932 (setq to (completing-read
4933 "Followups to (default no Followup-To header): "
4936 (message-tokenize-header
4938 (goto-char (point-min))
4939 (insert "Followup-To: " to "\n"))
4941 ;; Check "Shoot me".
4942 (message-check 'shoot
4943 (if (re-search-forward
4944 "Message-ID.*.i-did-not-set--mail-host-address--so-tickle-me" nil t)
4945 (y-or-n-p "You appear to have a misconfigured system. Really post? ")
4947 ;; Check for Approved.
4948 (message-check 'approved
4949 (if (re-search-forward "^Approved:" nil t)
4950 (y-or-n-p "The article contains an Approved header. Really post? ")
4952 ;; Check the Message-ID header.
4953 (message-check 'message-id
4954 (let* ((case-fold-search t)
4955 (message-id (message-fetch-field "message-id" t)))
4956 (or (not message-id)
4957 ;; Is there an @ in the ID?
4958 (and (string-match "@" message-id)
4959 ;; Is there a dot in the ID?
4960 (string-match "@[^.]*\\." message-id)
4961 ;; Does the ID end with a dot?
4962 (not (string-match "\\.>" message-id)))
4964 (format "The Message-ID looks strange: \"%s\". Really post? "
4966 ;; Check the Newsgroups & Followup-To headers.
4967 (message-check 'existing-newsgroups
4968 (let* ((case-fold-search t)
4969 (newsgroups (message-fetch-field "newsgroups"))
4970 (followup-to (message-fetch-field "followup-to"))
4971 (groups (message-tokenize-header
4973 (concat newsgroups "," followup-to)
4975 (post-method (if (functionp message-post-method)
4976 (funcall message-post-method)
4977 message-post-method))
4978 ;; KLUDGE to handle nnvirtual groups. Doing this right
4979 ;; would probably involve a new nnoo function.
4980 ;; -- Per Abrahamsen <abraham@dina.kvl.dk>, 2001-10-17.
4981 (method (if (and (consp post-method)
4982 (eq (car post-method) 'nnvirtual)
4983 gnus-message-group-art)
4984 (let ((group (car (nnvirtual-find-group-art
4985 (car gnus-message-group-art)
4986 (cdr gnus-message-group-art)))))
4987 (gnus-find-method-for-group group))
4991 (gnus-group-name-decode
4992 (gnus-group-real-name n)
4993 (gnus-group-name-charset method n)))
4994 (gnus-groups-from-server method)))
4997 (when (and (not (equal (car groups) "poster"))
4998 (not (member (car groups) known-groups))
4999 (not (member (car groups) errors)))
5000 (push (car groups) errors))
5003 ;; Gnus is not running.
5004 ((or (not (and (boundp 'gnus-active-hashtb)
5005 gnus-active-hashtb))
5006 (not (boundp 'gnus-read-active-file)))
5008 ;; We don't have all the group names.
5009 ((and (or (not gnus-read-active-file)
5010 (eq gnus-read-active-file 'some))
5014 "Really use %s possibly unknown group%s: %s? "
5015 (if (= (length errors) 1) "this" "these")
5016 (if (= (length errors) 1) "" "s")
5017 (mapconcat 'identity errors ", "))))
5018 ;; There were no errors.
5021 ;; There are unknown groups.
5025 "Really post to %s unknown group%s: %s? "
5026 (if (= (length errors) 1) "this" "these")
5027 (if (= (length errors) 1) "" "s")
5028 (mapconcat 'identity errors ", ")))))))
5029 ;; Check continuation headers.
5030 (message-check 'continuation-headers
5031 (goto-char (point-min))
5032 (let ((do-posting t))
5033 (while (re-search-forward "^[^ \t\n][^ \t\n:]*[ \t\n]" nil t)
5034 (goto-char (match-beginning 0))
5035 (if (y-or-n-p "Fix continuation lines? ")
5038 (unless (y-or-n-p "Send anyway? ")
5039 (setq do-posting nil))))
5041 ;; Check the Newsgroups & Followup-To headers for syntax errors.
5042 (message-check 'valid-newsgroups
5043 (let ((case-fold-search t)
5044 (headers '("Newsgroups" "Followup-To"))
5046 (while (and headers (not error))
5047 (when (setq header (mail-fetch-field (car headers)))
5051 "\\`\\([-+_&.a-zA-Z0-9]+\\)?\\(,[-+_&.a-zA-Z0-9]+\\)*\\'"
5056 (not (string-match "\\.\\'\\|\\.\\." g)))
5057 (message-tokenize-header header ","))))
5064 (format "The %s header looks odd: \"%s\". Really post? "
5065 (car headers) header)))))
5066 (message-check 'repeated-newsgroups
5067 (let ((case-fold-search t)
5068 (headers '("Newsgroups" "Followup-To"))
5069 header error groups group)
5072 (when (setq header (mail-fetch-field (pop headers)))
5073 (setq groups (message-tokenize-header header ","))
5074 (while (setq group (pop groups))
5075 (when (member group groups)
5081 (format "Group %s is repeated in headers. Really post? " error)))))
5082 ;; Check the From header.
5083 (message-check 'from
5084 (let* ((case-fold-search t)
5085 (from (message-fetch-field "from"))
5089 (message "There is no From line. Posting is denied.")
5091 ((or (not (string-match
5093 (setq ad (nth 1 (mail-extract-address-components
5094 from))))) ;larsi@ifi
5095 (string-match "\\.\\." ad) ;larsi@ifi..uio
5096 (string-match "@\\." ad) ;larsi@.ifi.uio
5097 (string-match "\\.$" ad) ;larsi@ifi.uio.
5098 (not (string-match "^[^@]+@[^@]+$" ad)) ;larsi.ifi.uio
5099 (string-match "(.*).*(.*)" from)) ;(lars) (lars)
5101 "Denied posting -- the From looks strange: \"%s\"." from)
5103 ((let ((addresses (rfc822-addresses from)))
5104 ;; `rfc822-addresses' returns a string if parsing fails.
5105 (while (and (consp addresses)
5106 (not (eq (string-to-char (car addresses)) ?\()))
5107 (setq addresses (cdr addresses)))
5110 "Denied posting -- bad From address: \"%s\"." from)
5113 ;; Check the Reply-To header.
5114 (message-check 'reply-to
5115 (let* ((case-fold-search t)
5116 (reply-to (message-fetch-field "reply-to"))
5121 ((string-match "," reply-to)
5123 (format "Multiple Reply-To addresses: \"%s\". Really post? "
5125 ((or (not (string-match
5127 (setq ad (nth 1 (mail-extract-address-components
5128 reply-to))))) ;larsi@ifi
5129 (string-match "\\.\\." ad) ;larsi@ifi..uio
5130 (string-match "@\\." ad) ;larsi@.ifi.uio
5131 (string-match "\\.$" ad) ;larsi@ifi.uio.
5132 (not (string-match "^[^@]+@[^@]+$" ad)) ;larsi.ifi.uio
5133 (string-match "(.*).*(.*)" reply-to)) ;(lars) (lars)
5136 "The Reply-To looks strange: \"%s\". Really post? "
5140 (defun message-check-news-body-syntax ()
5142 ;; Check for long lines.
5143 (message-check 'long-lines
5144 (goto-char (point-min))
5146 (concat "^" (regexp-quote mail-header-separator) "$"))
5150 "<#\\(/\\)?\\(multipart\\|part\\|external\\|mml\\)")
5153 (< (- (point) p) 80)))
5154 (zerop (forward-line 1))))
5158 "You have lines longer than 79 characters. Really post? ")))
5159 ;; Check whether the article is empty.
5160 (message-check 'empty
5161 (goto-char (point-min))
5163 (concat "^" (regexp-quote mail-header-separator) "$"))
5166 (goto-char (point-max))
5167 (re-search-backward message-signature-separator nil t)
5169 (or (re-search-backward "[^ \n\t]" b t)
5170 (if (message-gnksa-enable-p 'empty-article)
5171 (y-or-n-p "Empty article. Really post? ")
5172 (message "Denied posting -- Empty article.")
5174 ;; Check for control characters.
5175 (message-check 'control-chars
5176 (if (re-search-forward
5177 (mm-string-to-multibyte "[\000-\007\013\015-\032\034-\037\200-\237]")
5180 "The article contains control characters. Really post? ")
5182 ;; Check excessive size.
5183 (message-check 'size
5184 (if (> (buffer-size) 60000)
5186 (format "The article is %d octets long. Really post? "
5189 ;; Check whether any new text has been added.
5190 (message-check 'new-text
5192 (not message-checksum)
5193 (not (eq (message-checksum) message-checksum))
5194 (if (message-gnksa-enable-p 'quoted-text-only)
5196 "It looks like no new text has been added. Really post? ")
5197 (message "Denied posting -- no new text has been added.")
5199 ;; Check the length of the signature.
5200 (message-check 'signature
5201 (let (sig-start sig-end)
5202 (goto-char (point-max))
5203 (if (not (re-search-backward message-signature-separator nil t))
5205 (setq sig-start (1+ (point-at-eol)))
5207 (if (re-search-forward
5208 "<#/?\\(multipart\\|part\\|external\\|mml\\)" nil t)
5209 (- (point-at-bol) 1)
5211 (if (>= (count-lines sig-start sig-end) 5)
5212 (if (message-gnksa-enable-p 'signature)
5214 (format "Signature is excessively long (%d lines). Really post? "
5215 (count-lines sig-start sig-end)))
5216 (message "Denied posting -- Excessive signature.")
5219 ;; Ensure that text follows last quoted portion.
5220 (message-check 'quoting-style
5221 (goto-char (point-max))
5222 (let ((no-problem t))
5223 (when (search-backward-regexp "^>[^\n]*\n" nil t)
5224 (setq no-problem (search-forward-regexp "^[ \t]*[^>\n]" nil t)))
5227 (if (message-gnksa-enable-p 'quoted-text-only)
5228 (y-or-n-p "Your text should follow quoted text. Really post? ")
5230 (goto-char (point-min))
5232 (concat "^" (regexp-quote mail-header-separator) "$"))
5233 (if (search-forward-regexp "^[ \t]*[^>\n]" nil t)
5234 (y-or-n-p "Your text should follow quoted text. Really post? ")
5235 (message "Denied posting -- only quoted text.")
5238 (defun message-checksum ()
5239 "Return a \"checksum\" for the current buffer."
5242 (goto-char (point-min))
5244 (concat "^" (regexp-quote mail-header-separator) "$"))
5246 (when (not (looking-at "[ \t\n]"))
5247 (setq sum (logxor (ash sum 1) (if (natnump sum) 0 1)
5252 (defun message-do-fcc ()
5253 "Process Fcc headers in the current buffer."
5254 (let ((case-fold-search t)
5255 (buf (current-buffer))
5257 (mml-externalize-attachments message-fcc-externalize-attachments))
5260 (message-narrow-to-headers)
5261 (setq file (message-fetch-field "fcc" t)))
5263 (set-buffer (get-buffer-create " *message temp*"))
5265 (insert-buffer-substring buf)
5266 (message-encode-message-body)
5268 (message-narrow-to-headers)
5269 (while (setq file (message-fetch-field "fcc" t))
5271 (message-remove-header "fcc" nil t))
5272 (let ((mail-parse-charset message-default-charset)
5273 (rfc2047-header-encoding-alist
5274 (cons '("Newsgroups" . default)
5275 rfc2047-header-encoding-alist)))
5276 (mail-encode-encoded-word-buffer)))
5277 (goto-char (point-min))
5278 (when (re-search-forward
5279 (concat "^" (regexp-quote mail-header-separator) "$")
5281 (replace-match "" t t ))
5282 ;; Process FCC operations.
5284 (setq file (pop list))
5285 (if (string-match "^[ \t]*|[ \t]*\\(.*\\)[ \t]*$" file)
5286 ;; Pipe the article to the program in question.
5287 (call-process-region (point-min) (point-max) shell-file-name
5288 nil nil nil shell-command-switch
5289 (match-string 1 file))
5290 ;; Save the article.
5291 (setq file (expand-file-name file))
5292 (unless (file-exists-p (file-name-directory file))
5293 (make-directory (file-name-directory file) t))
5294 (if (and message-fcc-handler-function
5295 (not (eq message-fcc-handler-function 'rmail-output)))
5296 (funcall message-fcc-handler-function file)
5297 ;; FIXME this option, rmail-output (also used if
5298 ;; message-fcc-handler-function is nil) is not
5299 ;; documented anywhere AFAICS. It should work in Emacs
5300 ;; 23; I suspect it does not work in Emacs 22.
5301 ;; FIXME I don't see the need for the two different cases here.
5302 ;; mail-use-rfc822 makes no difference (in Emacs 23),and
5303 ;; the third argument just controls \"Wrote file\" message.
5304 (if (and (file-readable-p file) (mail-file-babyl-p file))
5305 (rmail-output file 1 nil t)
5306 (let ((mail-use-rfc822 t))
5307 (rmail-output file 1 t t))))))
5308 (kill-buffer (current-buffer))))))
5310 (defun message-output (filename)
5311 "Append this article to Unix/babyl mail file FILENAME."
5312 (if (and (file-readable-p filename)
5313 (mail-file-babyl-p filename))
5314 (gnus-output-to-rmail filename t)
5315 (gnus-output-to-mail filename t)))
5317 (defun message-cleanup-headers ()
5318 "Do various automatic cleanups of the headers."
5319 ;; Remove empty lines in the header.
5321 (message-narrow-to-headers)
5322 ;; Remove blank lines.
5323 (while (re-search-forward "^[ \t]*\n" nil t)
5324 (replace-match "" t t))
5326 ;; Correct Newsgroups and Followup-To headers: Change sequence of
5327 ;; spaces to comma and eliminate spaces around commas. Eliminate
5328 ;; embedded line breaks.
5329 (goto-char (point-min))
5330 (while (re-search-forward "^\\(Newsgroups\\|Followup-To\\): +" nil t)
5334 (if (re-search-forward "^[^ \t]" nil t)
5338 (goto-char (point-min))
5339 (while (re-search-forward "\n[ \t]+" nil t)
5340 (replace-match " " t t)) ;No line breaks (too confusing)
5341 (goto-char (point-min))
5342 (while (re-search-forward "[ \t\n]*,[ \t\n]*\\|[ \t]+" nil t)
5343 (replace-match "," t t))
5344 (goto-char (point-min))
5345 ;; Remove trailing commas.
5346 (when (re-search-forward ",+$" nil t)
5347 (replace-match "" t t))))))
5349 (defun message-make-date (&optional now)
5350 "Make a valid data header.
5351 If NOW, use that time instead."
5352 (let ((system-time-locale "C"))
5353 (format-time-string "%a, %d %b %Y %T %z" now)))
5355 (defun message-insert-expires (days)
5356 "Insert the Expires header. Expiry in DAYS days."
5357 (interactive "NExpire article in how many days? ")
5359 (message-position-on-field "Expires" "X-Draft-From")
5360 (insert (message-make-expires-date days))))
5362 (defun message-make-expires-date (days)
5363 "Make date string for the Expires header. Expiry in DAYS days.
5365 In posting styles use `(\"Expires\" (make-expires-date 30))'."
5366 (let* ((cur (decode-time (current-time)))
5367 (nday (+ days (nth 3 cur))))
5368 (setf (nth 3 cur) nday)
5369 (message-make-date (apply 'encode-time cur))))
5371 (defun message-make-message-id ()
5372 "Make a unique Message-ID."
5373 (concat "<" (message-unique-id)
5374 (let ((psubject (save-excursion (message-fetch-field "subject")))
5376 (save-excursion (message-fetch-field "supersedes"))))
5378 (and message-reply-headers
5379 (mail-header-references message-reply-headers)
5380 (mail-header-subject message-reply-headers)
5383 (message-strip-subject-re
5384 (mail-header-subject message-reply-headers))
5385 (message-strip-subject-re psubject))))
5387 (string-match "_-_@" psupersedes)))
5389 "@" (message-make-fqdn) ">"))
5391 (defvar message-unique-id-char nil)
5393 ;; If you ever change this function, make sure the new version
5394 ;; cannot generate IDs that the old version could.
5395 ;; You might for example insert a "." somewhere (not next to another dot
5396 ;; or string boundary), or modify the "fsf" string.
5397 (defun message-unique-id ()
5398 ;; Don't use microseconds from (current-time), they may be unsupported.
5399 ;; Instead we use this randomly inited counter.
5400 (setq message-unique-id-char
5401 (% (1+ (or message-unique-id-char (logand (random t) (1- (lsh 1 20)))))
5402 ;; (current-time) returns 16-bit ints,
5403 ;; and 2^16*25 just fits into 4 digits i base 36.
5405 (let ((tm (current-time)))
5407 (if (or (memq system-type '(ms-dos emx))
5408 ;; message-number-base36 doesn't handle bigints.
5409 (floatp (user-uid)))
5410 (let ((user (downcase (user-login-name))))
5411 (while (string-match "[^a-z0-9_]" user)
5412 (aset user (match-beginning 0) ?_))
5414 (message-number-base36 (user-uid) -1))
5415 (message-number-base36 (+ (car tm)
5416 (lsh (% message-unique-id-char 25) 16)) 4)
5417 (message-number-base36 (+ (nth 1 tm)
5418 (lsh (/ message-unique-id-char 25) 16)) 4)
5419 ;; Append a given name, because while the generated ID is unique
5420 ;; to this newsreader, other newsreaders might otherwise generate
5421 ;; the same ID via another algorithm.
5424 (defun message-number-base36 (num len)
5429 (concat (message-number-base36 (/ num 36) (1- len))
5430 (char-to-string (aref "zyxwvutsrqponmlkjihgfedcba9876543210"
5433 (defun message-make-organization ()
5434 "Make an Organization header."
5435 (let* ((organization
5436 (when message-user-organization
5437 (if (functionp message-user-organization)
5438 (funcall message-user-organization)
5439 message-user-organization))))
5441 (mm-enable-multibyte)
5442 (cond ((stringp organization)
5443 (insert organization))
5444 ((and (eq t organization)
5445 message-user-organization-file
5446 (file-exists-p message-user-organization-file))
5447 (insert-file-contents message-user-organization-file)))
5448 (goto-char (point-min))
5449 (while (re-search-forward "[\t\n]+" nil t)
5450 (replace-match "" t t))
5451 (unless (zerop (buffer-size))
5454 (defun message-make-lines ()
5455 "Count the number of lines and return numeric string."
5460 (int-to-string (count-lines (point) (point-max))))))
5462 (defun message-make-references ()
5463 "Return the References header for this message."
5464 (when message-reply-headers
5465 (let ((message-id (mail-header-id message-reply-headers))
5466 (references (mail-header-references message-reply-headers)))
5467 (if (or references message-id)
5468 (concat (or references "") (and references " ")
5472 (defun message-make-in-reply-to ()
5473 "Return the In-Reply-To header for this message."
5474 (when message-reply-headers
5475 (let ((from (mail-header-from message-reply-headers))
5476 (date (mail-header-date message-reply-headers))
5477 (msg-id (mail-header-id message-reply-headers)))
5479 (let ((name (mail-extract-address-components from)))
5481 msg-id (if msg-id " (")
5483 (if (string-match "[^\000-\177]" (car name))
5484 ;; Quote a string containing non-ASCII characters.
5485 ;; It will make the RFC2047 encoder cause an error
5486 ;; if there are special characters.
5487 (mm-with-multibyte-buffer
5489 (goto-char (point-min))
5490 (while (search-forward "\"" nil t)
5493 (zerop (% (skip-chars-backward "\\\\") 2))
5494 (goto-char (match-beginning 0)))
5497 ;; Those quotes will be removed by the RFC2047 encoder.
5498 (concat "\"" (buffer-string) "\""))
5502 (if (or (not date) (string= date ""))
5503 "(unknown date)" date)
5504 "\"" (if msg-id ")")))))))
5506 (defun message-make-distribution ()
5507 "Make a Distribution header."
5508 (let ((orig-distribution (message-fetch-reply-field "distribution")))
5509 (cond ((functionp message-distribution-function)
5510 (funcall message-distribution-function))
5511 (t orig-distribution))))
5513 (defun message-make-expires ()
5514 "Return an Expires header based on `message-expires'."
5515 (let ((current (current-time))
5516 (future (* 1.0 message-expires 60 60 24)))
5517 ;; Add the future to current.
5518 (setcar current (+ (car current) (round (/ future (expt 2 16)))))
5519 (setcar (cdr current) (+ (nth 1 current) (% (round future) (expt 2 16))))
5520 (message-make-date current)))
5522 (defun message-make-path ()
5524 (let ((login-name (user-login-name)))
5525 (cond ((null message-user-path)
5526 (concat (system-name) "!" login-name))
5527 ((stringp message-user-path)
5528 ;; Support GENERICPATH. Suggested by vixie@decwrl.dec.com.
5529 (concat message-user-path "!" login-name))
5532 (defun message-make-from (&optional name address)
5533 "Make a From header."
5534 (let* ((style message-from-style)
5535 (login (or address (message-make-address)))
5537 (and (boundp 'user-full-name)
5540 (when (string= fullname "&")
5541 (setq fullname (user-login-name)))
5543 (mm-enable-multibyte)
5546 (equal fullname ""))
5548 ((or (eq style 'angles)
5549 (and (not (eq style 'parens))
5550 ;; Use angles if no quoting is needed, or if parens would
5551 ;; need quoting too.
5552 (or (not (string-match "[^- !#-'*+/-9=?A-Z^-~]" fullname))
5553 (let ((tmp (concat fullname nil)))
5554 (while (string-match "([^()]*)" tmp)
5555 (aset tmp (match-beginning 0) ?-)
5556 (aset tmp (1- (match-end 0)) ?-))
5557 (string-match "[\\()]" tmp)))))
5559 (goto-char (point-min))
5560 ;; Look for a character that cannot appear unquoted
5561 ;; according to RFC 822.
5562 (when (re-search-forward "[^- !#-'*+/-9=?A-Z^-~]" nil 1)
5563 ;; Quote fullname, escaping specials.
5564 (goto-char (point-min))
5566 (while (re-search-forward "[\"\\]" nil 1)
5567 (replace-match "\\\\\\&" t))
5569 (insert " <" login ">"))
5570 (t ; 'parens or default
5572 (let ((fullname-start (point)))
5574 (goto-char fullname-start)
5575 ;; RFC 822 says \ and nonmatching parentheses
5576 ;; must be escaped in comments.
5577 ;; Escape every instance of ()\ ...
5578 (while (re-search-forward "[()\\]" nil 1)
5579 (replace-match "\\\\\\&" t))
5580 ;; ... then undo escaping of matching parentheses,
5581 ;; including matching nested parentheses.
5582 (goto-char fullname-start)
5583 (while (re-search-forward
5584 "\\(\\=\\|[^\\]\\(\\\\\\\\\\)*\\)\\\\(\\(\\([^\\]\\|\\\\\\\\\\)*\\)\\\\)"
5586 (replace-match "\\1(\\3)" t)
5587 (goto-char fullname-start)))
5591 (defun message-make-sender ()
5592 "Return the \"real\" user address.
5593 This function tries to ignore all user modifications, and
5594 give as trustworthy answer as possible."
5595 (concat (user-login-name) "@" (system-name)))
5597 (defun message-make-address ()
5598 "Make the address of the user."
5599 (or (message-user-mail-address)
5600 (concat (user-login-name) "@" (message-make-domain))))
5602 (defun message-user-mail-address ()
5603 "Return the pertinent part of `user-mail-address'."
5604 (when (and user-mail-address
5605 (string-match "@.*\\." user-mail-address))
5606 (if (string-match " " user-mail-address)
5607 (nth 1 (mail-extract-address-components user-mail-address))
5608 user-mail-address)))
5610 (defun message-sendmail-envelope-from ()
5611 "Return the envelope from."
5612 (cond ((eq message-sendmail-envelope-from 'header)
5613 (nth 1 (mail-extract-address-components
5614 (message-fetch-field "from"))))
5615 ((stringp message-sendmail-envelope-from)
5616 message-sendmail-envelope-from)
5618 (message-make-address))))
5620 (defun message-make-fqdn ()
5621 "Return user's fully qualified domain name."
5622 (let* ((system-name (system-name))
5623 (user-mail (message-user-mail-address))
5626 (string-match "@\\(.*\\)\\'" user-mail))
5627 (match-string 1 user-mail)))
5628 (case-fold-search t))
5630 ((and message-user-fqdn
5631 (stringp message-user-fqdn)
5632 (string-match message-valid-fqdn-regexp message-user-fqdn)
5633 (not (string-match message-bogus-system-names message-user-fqdn)))
5634 ;; `message-user-fqdn' seems to be valid
5636 ((and (string-match message-valid-fqdn-regexp system-name)
5637 (not (string-match message-bogus-system-names system-name)))
5638 ;; `system-name' returned the right result.
5640 ;; Try `mail-host-address'.
5641 ((and (boundp 'mail-host-address)
5642 (stringp mail-host-address)
5643 (string-match message-valid-fqdn-regexp mail-host-address)
5644 (not (string-match message-bogus-system-names mail-host-address)))
5646 ;; We try `user-mail-address' as a backup.
5648 (stringp user-domain)
5649 (string-match message-valid-fqdn-regexp user-domain)
5650 (not (string-match message-bogus-system-names user-domain)))
5652 ;; Default to this bogus thing.
5655 ".i-did-not-set--mail-host-address--so-tickle-me")))))
5657 (defun message-make-host-name ()
5658 "Return the name of the host."
5659 (let ((fqdn (message-make-fqdn)))
5660 (string-match "^[^.]+\\." fqdn)
5661 (substring fqdn 0 (1- (match-end 0)))))
5663 (defun message-make-domain ()
5664 "Return the domain name."
5665 (or mail-host-address
5666 (message-make-fqdn)))
5668 (defun message-to-list-only ()
5669 "Send a message to the list only.
5670 Remove all addresses but the list address from To and Cc headers."
5672 (let ((listaddr (message-make-mail-followup-to t)))
5675 (message-remove-header "to")
5676 (message-remove-header "cc")
5677 (message-position-on-field "To" "X-Draft-From")
5678 (insert listaddr)))))
5680 (defun message-make-mail-followup-to (&optional only-show-subscribed)
5681 "Return the Mail-Followup-To header.
5682 If passed the optional argument ONLY-SHOW-SUBSCRIBED only return the
5683 subscribed address (and not the additional To and Cc header contents)."
5684 (let* ((case-fold-search t)
5685 (to (message-fetch-field "To"))
5686 (cc (message-fetch-field "cc"))
5687 (msg-recipients (concat to (and to cc ", ") cc))
5689 (mapcar 'mail-strip-quoted-names
5690 (message-tokenize-header msg-recipients)))
5692 (if message-subscribed-address-file
5693 (let (begin end item re)
5696 (insert-file-contents message-subscribed-address-file)
5698 (setq begin (point))
5701 (if (bolp) (setq end (1- end)))
5702 (setq item (regexp-quote (buffer-substring begin end)))
5703 (if re (setq re (concat re "\\|" item))
5704 (setq re (concat "\\`\\(" item))))
5705 (and re (list (concat re "\\)\\'"))))))))
5706 (mft-regexps (apply 'append message-subscribed-regexps
5707 (mapcar 'regexp-quote
5708 message-subscribed-addresses)
5711 message-subscribed-address-functions))))
5714 (loop for recipient in recipients
5715 when (loop for regexp in mft-regexps
5716 when (string-match regexp recipient) return t)
5719 (if only-show-subscribed
5721 msg-recipients))))))
5723 (defun message-idna-to-ascii-rhs-1 (header)
5724 "Interactively potentially IDNA encode domain names in HEADER."
5725 (let ((field (message-fetch-field header))
5729 (mm-delete-duplicates
5730 (mapcar (lambda (rhs) (or (cadr (split-string rhs "@")) ""))
5734 (mail-extract-address-components field t))))))
5735 ;; Note that `rhs' will be "" if the address does not have
5736 ;; the domain part, i.e., if it is a local user's address.
5737 (setq ace (if (string-match "\\`[[:ascii:]]*\\'" rhs)
5739 (downcase (idna-to-ascii rhs))))
5740 (when (and (not (equal rhs ace))
5741 (or (not (eq message-use-idna 'ask))
5742 (y-or-n-p (format "Replace %s with %s in %s:? "
5744 (goto-char (point-min))
5745 (while (re-search-forward (concat "^" header ":") nil t)
5746 (message-narrow-to-field)
5747 (while (search-forward (concat "@" rhs) nil t)
5748 (replace-match (concat "@" ace) t t))
5749 (goto-char (point-max))
5752 (defun message-idna-to-ascii-rhs ()
5753 "Possibly IDNA encode non-ASCII domain names in From:, To: and Cc: headers.
5754 See `message-idna-encode'."
5756 (when message-use-idna
5759 ;; `message-narrow-to-head' that recognizes only the first empty
5760 ;; line as the message header separator used to be used here.
5761 ;; However, since there is the "--text follows this line--" line
5762 ;; normally, it failed in narrowing to the headers and potentially
5763 ;; caused the IDNA encoding on lines that look like headers in
5764 ;; the message body.
5765 (message-narrow-to-headers-or-head)
5766 (message-idna-to-ascii-rhs-1 "From")
5767 (message-idna-to-ascii-rhs-1 "To")
5768 (message-idna-to-ascii-rhs-1 "Reply-To")
5769 (message-idna-to-ascii-rhs-1 "Mail-Reply-To")
5770 (message-idna-to-ascii-rhs-1 "Mail-Followup-To")
5771 (message-idna-to-ascii-rhs-1 "Cc")))))
5773 (defun message-generate-headers (headers)
5774 "Prepare article HEADERS.
5775 Headers already prepared in the buffer are not modified."
5776 (setq headers (append headers message-required-headers))
5778 (message-narrow-to-headers)
5779 (let* ((Date (message-make-date))
5780 (Message-ID (message-make-message-id))
5781 (Organization (message-make-organization))
5782 (From (message-make-from))
5783 (Path (message-make-path))
5786 (In-Reply-To (message-make-in-reply-to))
5787 (References (message-make-references))
5789 (Distribution (message-make-distribution))
5790 (Lines (message-make-lines))
5791 (User-Agent message-newsreader)
5792 (Expires (message-make-expires))
5793 (case-fold-search t)
5795 header value elem header-string)
5796 ;; First we remove any old generated headers.
5797 (let ((headers message-deletable-headers))
5798 (unless (buffer-modified-p)
5799 (setq headers (delq 'Message-ID (copy-sequence headers))))
5801 (goto-char (point-min))
5802 (and (re-search-forward
5803 (concat "^" (symbol-name (car headers)) ": *") nil t)
5804 (get-text-property (1+ (match-beginning 0)) 'message-deletable)
5805 (message-delete-line))
5807 ;; Go through all the required headers and see if they are in the
5808 ;; articles already. If they are not, or are empty, they are
5809 ;; inserted automatically - except for Subject, Newsgroups and
5812 (goto-char (point-min))
5813 (setq elem (pop headers))
5815 (if (eq (car elem) 'optional)
5816 (setq header (cdr elem)
5818 (setq header (car elem)))
5820 (setq header-string (if (stringp header)
5822 (symbol-name header)))
5823 (when (or (not (re-search-forward
5825 (regexp-quote (downcase header-string))
5829 ;; The header was found. We insert a space after the
5830 ;; colon, if there is none.
5831 (if (/= (char-after) ? ) (insert " ") (forward-char 1))
5832 ;; Find out whether the header is empty.
5833 (looking-at "[ \t]*\n[^ \t]")))
5834 ;; So we find out what value we should insert.
5838 (eq (car elem) 'optional)
5839 (not (member header-string message-inserted-headers)))
5840 ;; This is an optional header. If the cdr of this
5841 ;; is something that is nil, then we do not insert
5843 (setq header (cdr elem))
5844 (or (and (functionp (cdr elem))
5845 (funcall (cdr elem)))
5846 (and (boundp (cdr elem))
5847 (symbol-value (cdr elem)))))
5849 ;; The element is a cons. Either the cdr is a
5850 ;; string to be inserted verbatim, or it is a
5851 ;; function, and we insert the value returned from
5853 (or (and (stringp (cdr elem))
5855 (and (functionp (cdr elem))
5856 (funcall (cdr elem)))))
5857 ((and (boundp header)
5858 (symbol-value header))
5859 ;; The element is a symbol. We insert the value
5860 ;; of this symbol, if any.
5861 (symbol-value header))
5862 ((not (message-check-element
5863 (intern (downcase (symbol-name header)))))
5864 ;; We couldn't generate a value for this header,
5865 ;; so we just ask the user.
5866 (read-from-minibuffer
5867 (format "Empty header for %s; enter value: " header)))))
5868 ;; Finally insert the header.
5870 (not (equal value "")))
5874 ;; This header didn't exist, so we insert it.
5875 (goto-char (point-max))
5877 (cdr (assq header message-header-format-alist))))
5879 (funcall formatter header value)
5880 (insert header-string ": " value))
5881 (push header-string message-inserted-headers)
5882 (goto-char (message-fill-field))
5883 ;; We check whether the value was ended by a
5884 ;; newline. If not, we insert one.
5888 ;; The value of this header was empty, so we clear
5889 ;; totally and insert the new value.
5890 (delete-region (point) (point-at-eol))
5891 ;; If the header is optional, and the header was
5892 ;; empty, we can't insert it anyway.
5894 (push header-string message-inserted-headers)
5896 (message-fill-field)))
5897 ;; Add the deletable property to the headers that require it.
5898 (and (memq header message-deletable-headers)
5899 (progn (beginning-of-line) (looking-at "[^:]+: "))
5900 (add-text-properties
5901 (point) (match-end 0)
5902 '(message-deletable t face italic) (current-buffer)))))))
5903 ;; Insert new Sender if the From is strange.
5904 (let ((from (message-fetch-field "from"))
5905 (sender (message-fetch-field "sender"))
5906 (secure-sender (message-make-sender)))
5908 (not (message-check-element 'sender))
5911 (cadr (mail-extract-address-components from)))
5912 (downcase secure-sender)))
5917 (cadr (mail-extract-address-components sender)))
5918 (downcase secure-sender)))))
5919 (goto-char (point-min))
5920 ;; Rename any old Sender headers to Original-Sender.
5921 (when (re-search-forward "^\\(Original-\\)*Sender:" nil t)
5923 (insert "Original-")
5924 (beginning-of-line))
5925 (when (or (message-news-p)
5926 (string-match "@.+\\.." secure-sender))
5927 (insert "Sender: " secure-sender "\n"))))
5929 (message-idna-to-ascii-rhs))))
5931 (defun message-insert-courtesy-copy ()
5932 "Insert a courtesy message in mail copies of combined messages."
5936 (message-narrow-to-headers)
5937 (when (setq newsgroups (message-fetch-field "newsgroups"))
5938 (goto-char (point-max))
5939 (insert "Posted-To: " newsgroups "\n")))
5941 (when message-courtesy-message
5943 ((string-match "%s" message-courtesy-message)
5944 (insert (format message-courtesy-message newsgroups)))
5946 (insert message-courtesy-message)))))))
5949 ;;; Setting up a message buffer
5952 (defun message-skip-to-next-address ()
5953 (let ((end (save-excursion
5954 (message-next-header)
5957 (when (looking-at ",")
5959 (while (and (not (= (point) end))
5960 (or (not (eq char ?,))
5962 (skip-chars-forward "^,\"" (point-max))
5963 (when (eq (setq char (following-char)) ?\")
5964 (setq quoted (not quoted)))
5965 (unless (= (point) end)
5967 (skip-chars-forward " \t\n")))
5969 (defun message-fill-address (header value)
5970 (insert (capitalize (symbol-name header))
5972 (if (consp value) (car value) value)
5974 (message-fill-field-address))
5976 (defun message-split-line ()
5977 "Split current line, moving portion beyond point vertically down.
5978 If the current line has `message-yank-prefix', insert it on the new line."
5981 (split-line message-yank-prefix) ;; Emacs 22.1+ supports arg.
5985 (defun message-insert-header (header value)
5986 (insert (capitalize (symbol-name header))
5988 (if (consp value) (car value) value)))
5990 (defun message-field-name ()
5992 (goto-char (point-min))
5993 (when (looking-at "\\([^:]+\\):")
5994 (intern (capitalize (match-string 1))))))
5996 (defun message-fill-field ()
5999 (message-narrow-to-field)
6000 (let ((field-name (message-field-name)))
6001 (funcall (or (cadr (assq field-name message-field-fillers))
6002 'message-fill-field-general)))
6005 (defun message-fill-field-address ()
6007 (message-skip-to-next-address)
6009 (if (and (> (current-column) 78)
6015 (setq last (1+ (point))))
6016 (setq last (1+ (point)))))))
6018 (defun message-fill-field-general ()
6019 (let ((begin (point))
6022 (while (and (search-forward "\n" nil t)
6024 (replace-match " " t t))
6025 (fill-region-as-paragraph begin (point-max))
6026 ;; Tapdance around looong Message-IDs.
6028 (when (looking-at "[ \t]*$")
6029 (message-delete-line))
6031 (search-forward ":" nil t)
6032 (when (looking-at "\n[ \t]+")
6033 (replace-match " " t t))
6034 (goto-char (point-max))))
6036 (defun message-shorten-1 (list cut surplus)
6037 "Cut SURPLUS elements out of LIST, beginning with CUTth one."
6038 (setcdr (nthcdr (- cut 2) list)
6039 (nthcdr (+ (- cut 2) surplus 1) list)))
6041 (defun message-shorten-references (header references)
6042 "Trim REFERENCES to be 21 Message-ID long or less, and fold them.
6043 When sending via news, also check that the REFERENCES are less
6044 than 988 characters long, and if they are not, trim them until
6052 (goto-char (point-min))
6053 ;; Cons a list of valid references. GNKSA says we must not include MIDs
6054 ;; with whitespace or missing brackets (7.a "Does not propagate broken
6055 ;; Message-IDs in original References").
6056 (while (re-search-forward "<[^ <]+@[^ <]+>" nil t)
6057 (push (match-string 0) refs))
6058 (setq refs (nreverse refs)
6059 count (length refs)))
6061 ;; If the list has more than MAXCOUNT elements, trim it by
6062 ;; removing the CUTth element and the required number of
6063 ;; elements that follow.
6064 (when (> count maxcount)
6065 (let ((surplus (- count maxcount)))
6066 (message-shorten-1 refs cut surplus)
6067 (decf count surplus)))
6069 ;; When sending via news, make sure the total folded length will
6070 ;; be less than 998 characters. This is to cater to broken INN
6071 ;; 2.3 which counts the total number of characters in a header
6072 ;; rather than the physical line length of each line, as it should.
6074 ;; This hack should be removed when it's believed than INN 2.3 is
6075 ;; no longer widely used.
6077 ;; At this point the headers have not been generated, thus we use
6078 ;; message-this-is-news directly.
6079 (when message-this-is-news
6082 (message-insert-header
6083 header (mapconcat #'identity refs " "))
6085 (message-shorten-1 refs cut 1)))
6086 ;; Finally, collect the references back into a string and insert
6087 ;; it into the buffer.
6088 (message-insert-header header (mapconcat #'identity refs " "))))
6090 (defun message-position-point ()
6091 "Move point to where the user probably wants to find it."
6092 (message-narrow-to-headers)
6094 ((re-search-forward "^[^:]+:[ \t]*$" nil t)
6095 (search-backward ":" )
6098 (if (eq (char-after) ? )
6102 (goto-char (point-max))
6105 (unless (looking-at "$")
6109 (defcustom message-beginning-of-line t
6110 "Whether \\<message-mode-map>\\[message-beginning-of-line]\
6111 goes to beginning of header values."
6113 :group 'message-buffers
6114 :link '(custom-manual "(message)Movement")
6117 (defun message-beginning-of-line (&optional n)
6118 "Move point to beginning of header value or to beginning of line.
6119 The prefix argument N is passed directly to `beginning-of-line'.
6121 This command is identical to `beginning-of-line' if point is
6122 outside the message header or if the option `message-beginning-of-line'
6125 If point is in the message header and on a (non-continued) header
6126 line, move point to the beginning of the header value or the beginning of line,
6127 whichever is closer. If point is already at beginning of line, move point to
6128 beginning of header value. Therefore, repeated calls will toggle point
6129 between beginning of field and beginning of line."
6131 (let ((zrs 'zmacs-region-stays))
6132 (when (and (featurep 'xemacs) (interactive-p) (boundp zrs))
6134 (if (and message-beginning-of-line
6135 (message-point-in-header-p))
6136 (let* ((here (point))
6137 (bol (progn (beginning-of-line n) (point)))
6138 (eol (point-at-eol))
6139 (eoh (re-search-forward ": *" eol t)))
6141 (if (and eoh (or (< eoh here) (= bol here)))
6143 (beginning-of-line n)))
6145 (defun message-buffer-name (type &optional to group)
6146 "Return a new (unique) buffer name based on TYPE and TO."
6148 ;; Generate a new buffer name The Message Way.
6149 ((memq message-generate-new-buffers '(unique t))
6150 (generate-new-buffer-name
6154 (or (car (mail-extract-address-components to))
6157 (if (and group (not (string= group ""))) (concat " on " group) "")
6159 ;; Check whether `message-generate-new-buffers' is a function,
6160 ;; and if so, call it.
6161 ((functionp message-generate-new-buffers)
6162 (funcall message-generate-new-buffers type to group))
6163 ((eq message-generate-new-buffers 'unsent)
6164 (generate-new-buffer-name
6165 (concat "*unsent " type
6168 (or (car (mail-extract-address-components to))
6171 (if (and group (not (string= group ""))) (concat " on " group) "")
6173 ;; Search for the existing message buffer with the specified name.
6175 (let* ((new (if (eq message-generate-new-buffers 'standard)
6176 (generate-new-buffer-name (concat "*" type " message*"))
6177 (let ((message-generate-new-buffers 'unique))
6178 (message-buffer-name type to group))))
6179 (regexp (concat "\\`"
6181 (if (string-match "<[0-9]+>\\'" new)
6182 (substring new 0 (match-beginning 0))
6184 "\\(?:<\\([0-9]+\\)>\\)?\\'"))
6185 (case-fold-search nil))
6192 (when (and (string-match regexp (setq b (buffer-name b)))
6193 (eq (with-current-buffer b major-mode)
6195 (cons (string-to-number (or (match-string 1 b) "1"))
6198 'car-less-than-car)))
6201 (defun message-pop-to-buffer (name &optional switch-function)
6202 "Pop to buffer NAME, and warn if it already exists and is modified."
6203 (let ((buffer (get-buffer name)))
6205 (buffer-name buffer))
6206 (let ((window (get-buffer-window buffer 0)))
6208 ;; Raise the frame already displaying the message buffer.
6210 (gnus-select-frame-set-input-focus (window-frame window))
6211 (select-window window))
6212 (funcall (or switch-function 'pop-to-buffer) buffer)
6213 (set-buffer buffer))
6214 (when (and (buffer-modified-p)
6217 "Message already being composed; erase? ")
6219 (error "Message being composed")))
6220 (funcall (or switch-function 'pop-to-buffer) name)
6225 (defun message-do-send-housekeeping ()
6226 "Kill old message buffers."
6227 ;; We might have sent this buffer already. Delete it from the
6229 (setq message-buffer-list (delq (current-buffer) message-buffer-list))
6230 (while (and message-max-buffers
6232 (>= (length message-buffer-list) message-max-buffers))
6233 ;; Kill the oldest buffer -- unless it has been changed.
6234 (let ((buffer (pop message-buffer-list)))
6235 (when (and (buffer-name buffer)
6236 (not (buffer-modified-p buffer)))
6237 (kill-buffer buffer))))
6238 ;; Rename the buffer.
6239 (if message-send-rename-function
6240 (funcall message-send-rename-function)
6241 ;; Note: mail-abbrevs of XEmacs renames buffer name behind Gnus.
6243 "\\`\\*\\(sent \\|unsent \\)?\\(.+\\)\\*[^\\*]*\\|\\`mail to "
6245 (let ((name (match-string 2 (buffer-name)))
6247 (if (not (or (null name)
6248 (string-equal name "mail")
6249 (string-equal name "posting")))
6250 (setq name (concat "*sent " name "*"))
6251 (message-narrow-to-headers)
6252 (setq to (message-fetch-field "to"))
6253 (setq group (message-fetch-field "newsgroups"))
6257 (to (concat "*sent mail to "
6258 (or (car (mail-extract-address-components to))
6260 ((and group (not (string= group "")))
6261 (concat "*sent posting on " group "*"))
6262 (t "*sent mail*"))))
6263 (unless (string-equal name (buffer-name))
6264 (rename-buffer name t)))))
6265 ;; Push the current buffer onto the list.
6266 (when message-max-buffers
6267 (setq message-buffer-list
6268 (nconc message-buffer-list (list (current-buffer))))))
6270 (defun message-mail-user-agent ()
6272 ((not message-mail-user-agent) nil)
6273 ((eq message-mail-user-agent t) mail-user-agent)
6274 (t message-mail-user-agent))))
6275 (if (memq mua '(message-user-agent gnus-user-agent))
6279 ;; YANK-ACTION, if non-nil, can be a buffer or a yank action of the
6280 ;; form (FUNCTION . ARGS).
6281 (defun message-setup (headers &optional yank-action actions
6282 continue switch-function)
6283 (let ((mua (message-mail-user-agent))
6285 (if (not (and message-this-is-mail mua))
6286 (message-setup-1 headers yank-action actions)
6287 (setq headers (copy-sequence headers))
6288 (setq field (assq 'Subject headers))
6290 (setq subject (cdr field))
6291 (setq headers (delq field headers)))
6292 (setq field (assq 'To headers))
6294 (setq to (cdr field))
6295 (setq headers (delq field headers)))
6296 (let ((mail-user-agent mua))
6297 (compose-mail to subject
6298 (mapcar (lambda (item)
6300 (format "%s" (car item))
6303 continue switch-function
6304 (if (bufferp yank-action)
6305 (list 'insert-buffer yank-action)
6309 (defun message-headers-to-generate (headers included-headers excluded-headers)
6310 "Return a list that includes all headers from HEADERS.
6311 If INCLUDED-HEADERS is a list, just include those headers. If it is
6312 t, include all headers. In any case, headers from EXCLUDED-HEADERS
6316 (dolist (header headers)
6317 (setq header-name (cond
6318 ((and (consp header)
6319 (eq (car header) 'optional))
6320 ;; On the form (optional . Header)
6323 ;; On the form (Header . function)
6328 (when (and (not (memq header-name excluded-headers))
6329 (or (eq included-headers t)
6330 (memq header-name included-headers)))
6331 (push header result)))
6334 (defun message-setup-1 (headers &optional yank-action actions)
6335 (dolist (action actions)
6337 (add-to-list 'message-send-actions
6338 `(apply ',(car action) ',(cdr action)))))
6339 (setq message-reply-buffer
6340 (if (and (consp yank-action)
6341 (eq (car yank-action) 'insert-buffer))
6344 (goto-char (point-min))
6345 ;; Insert all the headers.
6348 (alist message-header-format-alist))
6350 (unless (assq (caar h) message-header-format-alist)
6351 (push (list (caar h)) alist))
6355 (delete-region (point) (progn (forward-line -1) (point)))
6356 (when message-default-headers
6357 (insert message-default-headers)
6358 (or (bolp) (insert ?\n)))
6359 (insert mail-header-separator "\n")
6361 (when (message-news-p)
6362 (when message-default-news-headers
6363 (insert message-default-news-headers)
6364 (or (bolp) (insert ?\n)))
6365 (when message-generate-headers-first
6366 (message-generate-headers
6367 (message-headers-to-generate
6368 (append message-required-news-headers
6369 message-required-headers)
6370 message-generate-headers-first
6371 '(Lines Subject)))))
6372 (when (message-mail-p)
6373 (when message-default-mail-headers
6374 (insert message-default-mail-headers)
6375 (or (bolp) (insert ?\n)))
6376 (when message-generate-headers-first
6377 (message-generate-headers
6378 (message-headers-to-generate
6379 (append message-required-mail-headers
6380 message-required-headers)
6381 message-generate-headers-first
6382 '(Lines Subject)))))
6383 (run-hooks 'message-signature-setup-hook)
6384 (message-insert-signature)
6386 (message-narrow-to-headers)
6387 (run-hooks 'message-header-setup-hook))
6388 (setq buffer-undo-list nil)
6389 (when message-generate-hashcash
6390 ;; Generate hashcash headers for recipients already known
6391 (mail-add-payment-async))
6392 ;; Gnus posting styles are applied via buffer-local `message-setup-hook'
6394 (run-hooks 'message-setup-hook)
6395 ;; Do this last to give it precedence over posting styles, etc.
6396 (when (message-mail-p)
6398 (message-narrow-to-headers)
6399 (if message-alternative-emails
6400 (message-use-alternative-email-as-from))))
6401 (message-position-point)
6402 ;; Allow correct handling of `message-checksum' in `message-yank-original':
6403 (set-buffer-modified-p nil)
6406 (defun message-set-auto-save-file-name ()
6407 "Associate the message buffer with a file in the drafts directory."
6408 (when message-auto-save-directory
6409 (unless (file-directory-p
6410 (directory-file-name message-auto-save-directory))
6411 (make-directory message-auto-save-directory t))
6413 (setq message-draft-article
6414 (nndraft-request-associate-buffer "drafts"))
6416 ;; If Gnus were alive, draft messages would be saved in the drafts folder.
6417 ;; But Gnus is not alive, so arrange to save the draft message in a
6418 ;; regular file in message-auto-save-directory. Append a unique
6419 ;; time-based suffix to the filename to allow multiple drafts to be saved
6420 ;; simultaneously without overwriting each other (which mimics the
6421 ;; functionality of the Gnus drafts folder).
6422 (setq buffer-file-name (expand-file-name
6424 (if (memq system-type
6425 '(ms-dos ms-windows windows-nt
6426 cygwin cygwin32 win32 w32
6430 (format-time-string "-%Y%m%d-%H%M%S"))
6431 message-auto-save-directory))
6432 (setq buffer-auto-save-file-name (make-auto-save-file-name)))
6433 (clear-visited-file-modtime)
6434 (setq buffer-file-coding-system message-draft-coding-system)))
6436 (defun message-disassociate-draft ()
6437 "Disassociate the message buffer from the drafts directory."
6438 (when message-draft-article
6439 (nndraft-request-expire-articles
6440 (list message-draft-article) "drafts" nil t)))
6442 (defun message-insert-headers ()
6443 "Generate the headers for the article."
6447 (message-narrow-to-headers)
6448 (when (message-news-p)
6449 (message-generate-headers
6452 (copy-sequence message-required-news-headers)))))
6453 (when (message-mail-p)
6454 (message-generate-headers
6457 (copy-sequence message-required-mail-headers))))))))
6462 ;;; Commands for interfacing with message
6466 (defun message-mail (&optional to subject
6467 other-headers continue switch-function
6468 yank-action send-actions)
6469 "Start editing a mail message to be sent.
6470 OTHER-HEADERS is an alist of header/value pairs. CONTINUE says whether
6471 to continue editing a message already being composed. SWITCH-FUNCTION
6472 is a function used to switch to and display the mail buffer."
6474 (let ((message-this-is-mail t))
6475 (unless (message-mail-user-agent)
6476 (message-pop-to-buffer
6477 ;; Search for the existing message buffer if `continue' is non-nil.
6478 (let ((message-generate-new-buffers
6479 (when (or (not continue)
6480 (eq message-generate-new-buffers 'standard)
6481 (functionp message-generate-new-buffers))
6482 message-generate-new-buffers)))
6483 (message-buffer-name "mail" to))
6487 `((To . ,(or to "")) (Subject . ,(or subject "")))
6488 (when other-headers other-headers))
6489 yank-action send-actions continue switch-function)
6490 ;; FIXME: Should return nil if failure.
6494 (defun message-news (&optional newsgroups subject)
6495 "Start editing a news article to be sent."
6497 (let ((message-this-is-news t))
6498 (message-pop-to-buffer (message-buffer-name "posting" nil newsgroups))
6499 (message-setup `((Newsgroups . ,(or newsgroups ""))
6500 (Subject . ,(or subject ""))))))
6502 (defun message-alter-recipients-discard-bogus-full-name (addrcell)
6503 "Discard mail address in full names.
6504 When the full name in reply headers contains the mail
6505 address (e.g. \"foo@bar <foo@bar>\"), discard full name.
6506 ADDRCELL is a cons cell where the car is the mail address and the
6507 cdr is the complete address (full name and mail address)."
6508 (if (string-match (concat (regexp-quote (car addrcell)) ".*"
6509 (regexp-quote (car addrcell)))
6511 (cons (car addrcell) (car addrcell))
6514 (defcustom message-alter-recipients-function nil
6515 "Function called to allow alteration of reply header structures.
6516 It is called in `message-get-reply-headers' for each recipient.
6517 The function is called with one parameter, a cons cell ..."
6518 :type '(choice (const :tag "None" nil)
6519 (const :tag "Discard bogus full name"
6520 message-alter-recipients-discard-bogus-full-name)
6522 :version "23.1" ;; No Gnus
6523 :group 'message-headers)
6525 (defun message-get-reply-headers (wide &optional to-address address-headers)
6526 (let (follow-to mct never-mct to cc author mft recipients extra)
6527 ;; Find all relevant headers we need.
6529 (message-narrow-to-headers-or-head)
6530 ;; Gmane renames "To". Look at "Original-To", too, if it is present in
6531 ;; message-header-synonyms.
6532 (setq to (or (message-fetch-field "to")
6533 (and (loop for synonym in message-header-synonyms
6534 when (memq 'Original-To synonym)
6536 (message-fetch-field "original-to")))
6537 cc (message-fetch-field "cc")
6538 extra (when message-extra-wide-headers
6539 (mapconcat 'identity
6540 (mapcar 'message-fetch-field
6541 message-extra-wide-headers)
6543 mct (message-fetch-field "mail-copies-to")
6544 author (or (message-fetch-field "mail-reply-to")
6545 (message-fetch-field "reply-to")
6546 (message-fetch-field "from")
6548 mft (and message-use-mail-followup-to
6549 (message-fetch-field "mail-followup-to"))))
6551 ;; Handle special values of Mail-Copies-To.
6553 (cond ((or (equal (downcase mct) "never")
6554 (equal (downcase mct) "nobody"))
6557 ((or (equal (downcase mct) "always")
6558 (equal (downcase mct) "poster"))
6559 (setq mct author))))
6562 ;; Build (textual) list of new recipient addresses.
6565 (setq recipients (concat ", " author)))
6567 (dolist (header address-headers)
6568 (let ((value (message-fetch-field header)))
6570 (setq recipients (concat recipients ", " value))))))
6572 (string-match "[^ \t,]" mft)
6573 (or (not (eq message-use-mail-followup-to 'ask))
6574 (message-y-or-n-p "Obey Mail-Followup-To? " t "\
6575 You should normally obey the Mail-Followup-To: header. In this
6576 article, it has the value of
6580 which directs your response to " (if (string-match "," mft)
6581 "the specified addresses"
6582 "that address only") ".
6584 Most commonly, Mail-Followup-To is used by a mailing list poster to
6585 express that responses should be sent to just the list, and not the
6588 If a message is posted to several mailing lists, Mail-Followup-To may
6589 also be used to direct the following discussion to one list only,
6590 because discussions that are spread over several lists tend to be
6591 fragmented and very difficult to follow.
6593 Also, some source/announcement lists are not intended for discussion;
6594 responses here are directed to other addresses.
6596 You may customize the variable `message-use-mail-followup-to', if you
6597 want to get rid of this query permanently.")))
6598 (setq recipients (concat ", " mft)))
6600 (setq recipients (concat ", " to-address))
6601 ;; If the author explicitly asked for a copy, we don't deny it to them.
6602 (if mct (setq recipients (concat recipients ", " mct))))
6604 (setq recipients (if never-mct "" (concat ", " author)))
6605 (if to (setq recipients (concat recipients ", " to)))
6606 (if cc (setq recipients (concat recipients ", " cc)))
6607 (if extra (setq recipients (concat recipients ", " extra)))
6608 (if mct (setq recipients (concat recipients ", " mct)))))
6609 (if (>= (length recipients) 2)
6610 ;; Strip the leading ", ".
6611 (setq recipients (substring recipients 2)))
6612 ;; Squeeze whitespace.
6613 (while (string-match "[ \t][ \t]+" recipients)
6614 (setq recipients (replace-match " " t t recipients)))
6615 ;; Remove addresses that match `rmail-dont-reply-to-names'.
6616 (let ((rmail-dont-reply-to-names (message-dont-reply-to-names)))
6617 (setq recipients (rmail-dont-reply-to recipients)))
6618 ;; Perhaps "Mail-Copies-To: never" removed the only address?
6619 (if (string-equal recipients "")
6620 (setq recipients author))
6621 ;; Convert string to a list of (("foo@bar" . "Name <Foo@BAR>") ...).
6625 (if message-alter-recipients-function
6626 (funcall message-alter-recipients-function
6627 (cons (downcase (mail-strip-quoted-names addr))
6629 (cons (downcase (mail-strip-quoted-names addr)) addr)))
6630 (message-tokenize-header recipients)))
6631 ;; Remove first duplicates. (Why not all duplicates? Is this a bug?)
6632 (let ((s recipients))
6634 (setq recipients (delq (assoc (car (pop s)) s) recipients))))
6636 ;; Remove hierarchical lists that are contained within each other,
6637 ;; if message-hierarchical-addresses is defined.
6638 (when message-hierarchical-addresses
6639 (let ((plain-addrs (mapcar 'car recipients))
6642 (setq subaddrs (assoc (car plain-addrs)
6643 message-hierarchical-addresses)
6644 plain-addrs (cdr plain-addrs))
6646 (setq subaddrs (cdr subaddrs))
6648 (setq recip (assoc (car subaddrs) recipients)
6649 subaddrs (cdr subaddrs))
6651 (setq recipients (delq recip recipients))))))))
6653 ;; Build the header alist. Allow the user to be asked whether
6654 ;; or not to reply to all recipients in a wide reply.
6655 (setq follow-to (list (cons 'To (cdr (pop recipients)))))
6656 (when (and recipients
6657 (or (not message-wide-reply-confirm-recipients)
6658 (y-or-n-p "Reply to all recipients? ")))
6659 (setq recipients (mapconcat
6660 (lambda (addr) (cdr addr)) recipients ", "))
6661 (if (string-match "^ +" recipients)
6662 (setq recipients (substring recipients (match-end 0))))
6663 (push (cons 'Cc recipients) follow-to)))
6666 (defcustom message-simplify-subject-functions
6667 '(message-strip-list-identifiers
6668 message-strip-subject-re
6669 message-strip-subject-trailing-was
6670 message-strip-subject-encoded-words)
6671 "List of functions taking a string argument that simplify subjects.
6672 The functions are applied when replying to a message.
6674 Useful functions to put in this list include:
6675 `message-strip-list-identifiers', `message-strip-subject-re',
6676 `message-strip-subject-trailing-was', and
6677 `message-strip-subject-encoded-words'."
6678 :version "22.1" ;; Gnus 5.10.9
6679 :group 'message-various
6680 :type '(repeat function))
6682 (defun message-simplify-subject (subject &optional functions)
6683 "Return simplified SUBJECT."
6686 (setq functions message-simplify-subject-functions))
6687 (when (and (memq 'message-strip-list-identifiers functions)
6688 gnus-list-identifiers)
6689 (setq subject (message-strip-list-identifiers subject)))
6690 (when (memq 'message-strip-subject-re functions)
6691 (setq subject (concat "Re: " (message-strip-subject-re subject))))
6692 (when (and (memq 'message-strip-subject-trailing-was functions)
6693 message-subject-trailing-was-query)
6694 (setq subject (message-strip-subject-trailing-was subject)))
6695 (when (memq 'message-strip-subject-encoded-words functions)
6696 (setq subject (message-strip-subject-encoded-words subject)))
6700 (defun message-reply (&optional to-address wide)
6701 "Start editing a reply to the article in the current buffer."
6703 (require 'gnus-sum) ; for gnus-list-identifiers
6704 (let ((cur (current-buffer))
6705 from subject date reply-to to cc
6706 references message-id follow-to
6707 (inhibit-point-motion-hooks t)
6708 (message-this-is-mail t)
6711 (message-narrow-to-head-1)
6712 ;; Allow customizations to have their say.
6714 ;; This is a regular reply.
6715 (when (functionp message-reply-to-function)
6717 (setq follow-to (funcall message-reply-to-function))))
6718 ;; This is a followup.
6719 (when (functionp message-wide-reply-to-function)
6722 (funcall message-wide-reply-to-function)))))
6723 (setq message-id (message-fetch-field "message-id" t)
6724 references (message-fetch-field "references")
6725 date (message-fetch-field "date")
6726 from (or (message-fetch-field "from") "nobody")
6727 subject (or (message-fetch-field "subject") "none"))
6729 ;; Strip list identifiers, "Re: ", and "was:"
6730 (setq subject (message-simplify-subject subject))
6732 (when (and (setq gnus-warning (message-fetch-field "gnus-warning"))
6733 (string-match "<[^>]+>" gnus-warning))
6734 (setq message-id (match-string 0 gnus-warning)))
6737 (setq follow-to (message-get-reply-headers wide to-address))))
6739 (unless (message-mail-user-agent)
6740 (message-pop-to-buffer
6741 (message-buffer-name
6742 (if wide "wide reply" "reply") from
6743 (if wide to-address nil))))
6745 (setq message-reply-headers
6746 (vector 0 subject from date message-id references 0 0 ""))
6749 `((Subject . ,subject)
6754 (defun message-wide-reply (&optional to-address)
6755 "Make a \"wide\" reply to the message in the current buffer."
6757 (message-reply to-address t))
6760 (defun message-followup (&optional to-newsgroups)
6761 "Follow up to the message in the current buffer.
6762 If TO-NEWSGROUPS, use that as the new Newsgroups line."
6764 (require 'gnus-sum) ; for gnus-list-identifiers
6765 (let ((cur (current-buffer))
6766 from subject date reply-to mrt mct
6767 references message-id follow-to
6768 (inhibit-point-motion-hooks t)
6769 (message-this-is-news t)
6770 followup-to distribution newsgroups gnus-warning posted-to)
6773 (goto-char (point-min))
6774 (if (search-forward "\n\n" nil t)
6777 (when (functionp message-followup-to-function)
6779 (funcall message-followup-to-function)))
6780 (setq from (message-fetch-field "from")
6781 date (message-fetch-field "date")
6782 subject (or (message-fetch-field "subject") "none")
6783 references (message-fetch-field "references")
6784 message-id (message-fetch-field "message-id" t)
6785 followup-to (message-fetch-field "followup-to")
6786 newsgroups (message-fetch-field "newsgroups")
6787 posted-to (message-fetch-field "posted-to")
6788 reply-to (message-fetch-field "reply-to")
6789 mrt (message-fetch-field "mail-reply-to")
6790 distribution (message-fetch-field "distribution")
6791 mct (message-fetch-field "mail-copies-to"))
6792 (when (and (setq gnus-warning (message-fetch-field "gnus-warning"))
6793 (string-match "<[^>]+>" gnus-warning))
6794 (setq message-id (match-string 0 gnus-warning)))
6795 ;; Remove bogus distribution.
6796 (when (and (stringp distribution)
6797 (let ((case-fold-search t))
6798 (string-match "world" distribution)))
6799 (setq distribution nil))
6800 ;; Strip list identifiers, "Re: ", and "was:"
6801 (setq subject (message-simplify-subject subject))
6804 (message-pop-to-buffer (message-buffer-name "followup" from newsgroups))
6806 (setq message-reply-headers
6807 (vector 0 subject from date message-id references 0 0 ""))
6810 `((Subject . ,subject)
6813 (list (cons 'Newsgroups to-newsgroups)))
6814 (follow-to follow-to)
6815 ((and followup-to message-use-followup-to)
6818 ((equal (downcase followup-to) "poster")
6819 (if (or (eq message-use-followup-to 'use)
6820 (message-y-or-n-p "Obey Followup-To: poster? " t "\
6821 You should normally obey the Followup-To: header.
6823 `Followup-To: poster' sends your response via e-mail instead of news.
6825 A typical situation where `Followup-To: poster' is used is when the poster
6826 does not read the newsgroup, so he wouldn't see any replies sent to it.
6828 You may customize the variable `message-use-followup-to', if you
6829 want to get rid of this query permanently."))
6831 (setq message-this-is-news nil)
6832 (cons 'To (or mrt reply-to from "")))
6833 (cons 'Newsgroups newsgroups)))
6835 (if (or (equal followup-to newsgroups)
6836 (not (eq message-use-followup-to 'ask))
6838 (concat "Obey Followup-To: " followup-to "? ") t "\
6839 You should normally obey the Followup-To: header.
6841 `Followup-To: " followup-to "'
6842 directs your response to " (if (string-match "," followup-to)
6843 "the specified newsgroups"
6844 "that newsgroup only") ".
6846 If a message is posted to several newsgroups, Followup-To is often
6847 used to direct the following discussion to one newsgroup only,
6848 because discussions that are spread over several newsgroup tend to
6849 be fragmented and very difficult to follow.
6851 Also, some source/announcement newsgroups are not intended for discussion;
6852 responses here are directed to other newsgroups.
6854 You may customize the variable `message-use-followup-to', if you
6855 want to get rid of this query permanently."))
6856 (cons 'Newsgroups followup-to)
6857 (cons 'Newsgroups newsgroups))))))
6859 `((Newsgroups . ,posted-to)))
6861 `((Newsgroups . ,newsgroups))))
6862 ,@(and distribution (list (cons 'Distribution distribution)))
6864 (not (or (equal (downcase mct) "never")
6865 (equal (downcase mct) "nobody"))))
6866 (list (cons 'Cc (if (or (equal (downcase mct) "always")
6867 (equal (downcase mct) "poster"))
6868 (or mrt reply-to from "")
6873 (defun message-is-yours-p ()
6874 "Non-nil means current article is yours.
6875 If you have added 'cancel-messages to `message-shoot-gnksa-feet', all articles
6876 are yours except those that have Cancel-Lock header not belonging to you.
6877 Instead of shooting GNKSA feet, you should modify `message-alternative-emails'
6878 regexp to match all of yours addresses."
6879 ;; Canlock-logic as suggested by Per Abrahamsen
6880 ;; <abraham@dina.kvl.dk>
6882 ;; IF article has cancel-lock THEN
6883 ;; IF we can verify it THEN
6886 ;; error: cancellock: article is not yours
6888 ;; Use old rules, comparing sender...
6891 (message-narrow-to-head-1)
6892 (if (message-fetch-field "Cancel-Lock")
6893 (if (null (canlock-verify))
6895 (error "Failed to verify Cancel-lock: This article is not yours"))
6898 (message-gnksa-enable-p 'cancel-messages)
6899 (and (setq sender (message-fetch-field "sender"))
6900 (string-equal (downcase sender)
6901 (downcase (message-make-sender))))
6902 ;; Email address in From field equals to our address
6903 (and (setq from (message-fetch-field "from"))
6905 (downcase (car (mail-header-parse-address from)))
6906 (downcase (car (mail-header-parse-address
6907 (message-make-from))))))
6908 ;; Email address in From field matches
6909 ;; 'message-alternative-emails' regexp
6911 message-alternative-emails
6913 message-alternative-emails
6914 (car (mail-header-parse-address from))))))))))
6917 (defun message-cancel-news (&optional arg)
6918 "Cancel an article you posted.
6919 If ARG, allow editing of the cancellation message."
6921 (unless (message-news-p)
6922 (error "This is not a news article; canceling is impossible"))
6923 (let (from newsgroups message-id distribution buf)
6925 ;; Get header info from original article.
6927 (message-narrow-to-head-1)
6928 (setq from (message-fetch-field "from")
6929 newsgroups (message-fetch-field "newsgroups")
6930 message-id (message-fetch-field "message-id" t)
6931 distribution (message-fetch-field "distribution")))
6932 ;; Make sure that this article was written by the user.
6933 (unless (message-is-yours-p)
6934 (error "This article is not yours"))
6935 (when (yes-or-no-p "Do you really want to cancel this article? ")
6936 ;; Make control message.
6939 (setq buf (set-buffer (get-buffer-create " *message cancel*"))))
6941 (insert "Newsgroups: " newsgroups "\n"
6943 "Subject: cmsg cancel " message-id "\n"
6944 "Control: cancel " message-id "\n"
6946 (concat "Distribution: " distribution "\n")
6948 mail-header-separator "\n"
6949 message-cancel-message)
6950 (run-hooks 'message-cancel-hook)
6952 (message "Canceling your article...")
6953 (if (let ((message-syntax-checks
6954 'dont-check-for-anything-just-trust-me))
6955 (funcall message-send-news-function))
6956 (message "Canceling your article...done"))
6957 (kill-buffer buf))))))
6960 (defun message-supersede ()
6961 "Start composing a message to supersede the current message.
6962 This is done simply by taking the old article and adding a Supersedes
6963 header line with the old Message-ID."
6965 (let ((cur (current-buffer)))
6966 ;; Check whether the user owns the article that is to be superseded.
6967 (unless (message-is-yours-p)
6968 (error "This article is not yours"))
6969 ;; Get a normal message buffer.
6970 (message-pop-to-buffer (message-buffer-name "supersede"))
6971 (insert-buffer-substring cur)
6973 (message-narrow-to-head-1)
6974 ;; Remove unwanted headers.
6975 (when message-ignored-supersedes-headers
6976 (message-remove-header message-ignored-supersedes-headers t))
6977 (goto-char (point-min))
6978 (if (not (re-search-forward "^Message-ID: " nil t))
6979 (error "No Message-ID in this article")
6980 (replace-match "Supersedes: " t t))
6981 (goto-char (point-max))
6982 (insert mail-header-separator)
6987 (defun message-recover ()
6988 "Reread contents of current buffer from its last auto-save file."
6990 (let ((file-name (make-auto-save-file-name)))
6991 (cond ((save-window-excursion
6992 (with-output-to-temp-buffer "*Directory*"
6993 (with-current-buffer standard-output
6994 (fundamental-mode)) ; for Emacs 20.4+
6995 (buffer-disable-undo standard-output)
6996 (let ((default-directory "/"))
6998 "ls" nil standard-output nil "-l" file-name)))
6999 (yes-or-no-p (format "Recover auto save file %s? " file-name)))
7000 (let ((buffer-read-only nil))
7002 (insert-file-contents file-name nil)))
7003 (t (error "message-recover cancelled")))))
7005 ;;; Washing Subject:
7007 (defun message-wash-subject (subject)
7008 "Remove junk like \"Re:\", \"(fwd)\", etc. added to subject string SUBJECT.
7009 Previous forwarders, replyers, etc. may add it."
7012 (goto-char (point-min))
7013 ;; strip Re/Fwd stuff off the beginning
7014 (while (re-search-forward
7015 "\\([Rr][Ee]:\\|[Ff][Ww][Dd]\\(\\[[0-9]*\\]\\)?:\\|[Ff][Ww]:\\)" nil t)
7018 ;; and gnus-style forwards [foo@bar.com] subject
7019 (goto-char (point-min))
7020 (while (re-search-forward "\\[[^ \t]*\\(@\\|\\.\\)[^ \t]*\\]" nil t)
7024 (goto-char (point-max))
7025 (while (re-search-backward "([Ff][Ww][Dd])" nil t)
7028 ;; and finally, any whitespace that was left-over
7029 (goto-char (point-min))
7030 (while (re-search-forward "^[ \t]+" nil t)
7032 (goto-char (point-max))
7033 (while (re-search-backward "[ \t]+$" nil t)
7038 ;;; Forwarding messages.
7040 (defvar message-forward-decoded-p nil
7041 "Non-nil means the original message is decoded.")
7043 (defun message-forward-subject-name-subject (subject)
7044 "Generate a SUBJECT for a forwarded message.
7045 The form is: [Source] Subject, where if the original message was mail,
7046 Source is the name of the sender, and if the original message was
7047 news, Source is the list of newsgroups is was posted to."
7048 (let* ((group (message-fetch-field "newsgroups"))
7049 (from (message-fetch-field "from"))
7052 (gnus-group-decoded-name group)
7054 (car (gnus-extract-address-components from))
7055 (cadr (gnus-extract-address-components from))))
7058 (if message-forward-decoded-p
7060 (mail-decode-encoded-word-string prefix))
7063 (defun message-forward-subject-author-subject (subject)
7064 "Generate a SUBJECT for a forwarded message.
7065 The form is: [Source] Subject, where if the original message was mail,
7066 Source is the sender, and if the original message was news, Source is
7067 the list of newsgroups is was posted to."
7068 (let* ((group (message-fetch-field "newsgroups"))
7071 (gnus-group-decoded-name group)
7072 (or (message-fetch-field "from")
7075 (if message-forward-decoded-p
7077 (mail-decode-encoded-word-string prefix))
7080 (defun message-forward-subject-fwd (subject)
7081 "Generate a SUBJECT for a forwarded message.
7082 The form is: Fwd: Subject, where Subject is the original subject of
7084 (if (string-match "^Fwd: " subject)
7086 (concat "Fwd: " subject)))
7088 (defun message-make-forward-subject ()
7089 "Return a Subject header suitable for the message in the current buffer."
7092 (message-narrow-to-head-1)
7093 (let ((funcs message-make-forward-subject-function)
7094 (subject (message-fetch-field "Subject")))
7097 (if message-forward-decoded-p
7099 (mail-decode-encoded-word-string subject))
7101 (when message-wash-forwarded-subjects
7102 (setq subject (message-wash-subject subject)))
7103 ;; Make sure funcs is a list.
7106 (setq funcs (list funcs)))
7107 ;; Apply funcs in order, passing subject generated by previous
7108 ;; func to the next one.
7109 (dolist (func funcs)
7110 (when (functionp func)
7111 (setq subject (funcall func subject))))
7114 (defvar gnus-article-decoded-p)
7118 (defun message-forward (&optional news digest)
7119 "Forward the current message via mail.
7120 Optional NEWS will use news to forward instead of mail.
7121 Optional DIGEST will use digest to forward."
7123 (let* ((cur (current-buffer))
7124 (message-forward-decoded-p
7125 (if (local-variable-p 'gnus-article-decoded-p (current-buffer))
7126 gnus-article-decoded-p ;; In an article buffer.
7127 message-forward-decoded-p))
7128 (subject (message-make-forward-subject)))
7130 (message-news nil subject)
7131 (message-mail nil subject))
7132 (message-forward-make-body cur digest)))
7134 (defun message-forward-make-body-plain (forward-buffer)
7136 "\n-------------------- Start of forwarded message --------------------\n")
7137 (let ((b (point)) e)
7140 (mm-disable-multibyte)
7142 (with-current-buffer forward-buffer
7143 (mm-with-unibyte-current-buffer (buffer-string))))
7144 (mm-enable-multibyte)
7146 (goto-char (point-min))
7147 (when (looking-at "From ")
7148 (replace-match "X-From-Line: "))
7152 "\n-------------------- End of forwarded message --------------------\n")
7153 (message-remove-ignored-headers b e)))
7155 (defun message-remove-ignored-headers (b e)
7156 (when message-forward-ignored-headers
7158 (narrow-to-region b e)
7160 (narrow-to-region (point)
7161 (or (search-forward "\n\n" nil t) (point)))
7162 (let ((ignored (if (stringp message-forward-ignored-headers)
7163 (list message-forward-ignored-headers)
7164 message-forward-ignored-headers)))
7165 (dolist (elem ignored)
7166 (message-remove-header elem t))))))
7168 (defun message-forward-make-body-mime (forward-buffer)
7170 (insert "\n\n<#part type=message/rfc822 disposition=inline raw=t>\n")
7172 (narrow-to-region (point) (point))
7173 (mml-insert-buffer forward-buffer)
7174 (goto-char (point-min))
7175 (when (looking-at "From ")
7176 (replace-match "X-From-Line: "))
7177 (goto-char (point-max)))
7178 (insert "<#/part>\n")
7179 ;; Consider there is no illegible text.
7180 (add-text-properties
7182 `(no-illegible-text t rear-nonsticky t start-open t))))
7184 (defun message-forward-make-body-mml (forward-buffer)
7185 (insert "\n\n<#mml type=message/rfc822 disposition=inline>\n")
7186 (let ((b (point)) e)
7187 (if (not message-forward-decoded-p)
7190 (mm-disable-multibyte)
7192 (with-current-buffer forward-buffer
7193 (mm-with-unibyte-current-buffer (buffer-string))))
7194 (mm-enable-multibyte)
7196 (goto-char (point-min))
7197 (when (looking-at "From ")
7198 (replace-match "X-From-Line: "))
7201 (narrow-to-region (point) (point))
7202 (mml-insert-buffer forward-buffer)
7203 (goto-char (point-min))
7204 (when (looking-at "From ")
7205 (replace-match "X-From-Line: "))
7206 (goto-char (point-max))))
7208 (insert "<#/mml>\n")
7209 (when (and (not message-forward-decoded-p)
7210 message-forward-ignored-headers)
7211 (message-remove-ignored-headers b e))))
7213 (defun message-forward-make-body-digest-plain (forward-buffer)
7215 "\n-------------------- Start of forwarded message --------------------\n")
7216 (let ((b (point)) e)
7217 (mml-insert-buffer forward-buffer)
7220 "\n-------------------- End of forwarded message --------------------\n")))
7222 (defun message-forward-make-body-digest-mime (forward-buffer)
7223 (insert "\n<#multipart type=digest>\n")
7224 (let ((b (point)) e)
7225 (insert-buffer-substring forward-buffer)
7227 (insert "<#/multipart>\n")
7229 (narrow-to-region b e)
7231 (narrow-to-region (point)
7232 (or (search-forward "\n\n" nil t) (point)))
7233 (delete-region (point-min) (point-max)))))
7235 (defun message-forward-make-body-digest (forward-buffer)
7236 (if message-forward-as-mime
7237 (message-forward-make-body-digest-mime forward-buffer)
7238 (message-forward-make-body-digest-plain forward-buffer)))
7240 (autoload 'mm-uu-dissect-text-parts "mm-uu")
7241 (autoload 'mm-uu-dissect "mm-uu")
7243 (defun message-signed-or-encrypted-p (&optional dont-emulate-mime handles)
7244 "Say whether the current buffer contains signed or encrypted message.
7245 If DONT-EMULATE-MIME is nil, this function does the MIME emulation on
7246 messages that don't conform to PGP/MIME described in RFC2015. HANDLES
7247 is for the internal use."
7249 (let ((mm-decrypt-option 'never)
7250 (mm-verify-option 'never))
7251 (if (setq handles (mm-dissect-buffer nil t))
7252 (unless dont-emulate-mime
7253 (mm-uu-dissect-text-parts handles))
7254 (unless dont-emulate-mime
7255 (setq handles (mm-uu-dissect))))))
7256 ;; Check text/plain message in which there is a signed or encrypted
7257 ;; body that has been encoded by B or Q.
7258 (unless (or handles dont-emulate-mime)
7259 (let ((cur (current-buffer))
7260 (mm-decrypt-option 'never)
7261 (mm-verify-option 'never))
7263 (insert-buffer-substring cur)
7264 (when (setq handles (mm-dissect-buffer t t))
7266 (bufferp (car handles))
7267 (mm-destroy-parts handles))
7268 (equal (mm-handle-media-type handles) "text/plain"))
7270 (mm-decode-content-transfer-encoding
7271 (mm-handle-encoding handles))
7272 (setq handles (mm-uu-dissect)))
7273 (setq handles nil))))))
7277 (dolist (handle (if (stringp (car handles))
7278 (if (member (car handles)
7279 '("multipart/signed"
7280 "multipart/encrypted"))
7284 (if (stringp (car handle))
7285 (when (message-signed-or-encrypted-p dont-emulate-mime handle)
7287 (when (and (bufferp (car handle))
7288 (equal (mm-handle-media-type handle)
7290 (with-current-buffer (mm-handle-buffer handle)
7291 (when (message-signed-or-encrypted-p dont-emulate-mime)
7292 (throw 'found t)))))))
7293 (mm-destroy-parts handles))))
7296 (defun message-forward-make-body (forward-buffer &optional digest)
7297 ;; Put point where we want it before inserting the forwarded
7299 (if message-forward-before-signature
7301 (goto-char (point-max)))
7303 (message-forward-make-body-digest forward-buffer)
7304 (if message-forward-as-mime
7305 (if (and message-forward-show-mml
7306 (not (and (eq message-forward-show-mml 'best)
7307 ;; Use the raw form in the body if it contains
7308 ;; signed or encrypted message so as not to be
7309 ;; destroyed by re-encoding.
7310 (with-current-buffer forward-buffer
7312 (message-signed-or-encrypted-p)
7314 (message-forward-make-body-mml forward-buffer)
7315 (message-forward-make-body-mime forward-buffer))
7316 (message-forward-make-body-plain forward-buffer)))
7317 (message-position-point))
7319 (declare-function rmail-toggle-header "rmail" (&optional arg))
7322 (defun message-forward-rmail-make-body (forward-buffer)
7323 (save-window-excursion
7324 (set-buffer forward-buffer)
7325 (if (rmail-msg-is-pruned)
7326 (if (fboundp 'rmail-msg-restore-non-pruned-header)
7327 (rmail-msg-restore-non-pruned-header) ; Emacs 22
7328 (rmail-toggle-header 0)))) ; Emacs 23
7329 (message-forward-make-body forward-buffer))
7331 ;; Fixme: Should have defcustom.
7333 (defun message-insinuate-rmail ()
7334 "Let RMAIL use message to forward."
7336 (setq rmail-enable-mime-composing t)
7337 (setq rmail-insert-mime-forwarded-message-function
7338 'message-forward-rmail-make-body))
7341 (defun message-resend (address)
7342 "Resend the current article to ADDRESS."
7344 (list (message-read-from-minibuffer "Resend message to: ")))
7345 (message "Resending message to %s..." address)
7347 (let ((cur (current-buffer))
7349 ;; We first set up a normal mail buffer.
7350 (unless (message-mail-user-agent)
7351 (set-buffer (get-buffer-create " *message resend*"))
7353 (let ((message-this-is-mail t)
7354 message-generate-hashcash
7356 (message-setup `((To . ,address))))
7357 ;; Insert our usual headers.
7358 (message-generate-headers '(From Date To Message-ID))
7359 (message-narrow-to-headers)
7360 ;; Remove X-Draft-From header etc.
7361 (message-remove-header message-ignored-mail-headers t)
7362 ;; Rename them all to "Resent-*".
7363 (goto-char (point-min))
7364 (while (re-search-forward "^[A-Za-z]" nil t)
7369 (delete-region (point) (point-max))
7371 ;; Insert the message to be resent.
7372 (insert-buffer-substring cur)
7373 (goto-char (point-min))
7374 (search-forward "\n\n")
7377 (narrow-to-region beg (point))
7378 (message-remove-header message-ignored-resent-headers t)
7379 (goto-char (point-max)))
7380 (insert mail-header-separator)
7381 ;; Rename all old ("Also-")Resent headers.
7382 (while (re-search-backward "^\\(Also-\\)*Resent-" beg t)
7385 ;; Quote any "From " lines at the beginning.
7387 (when (looking-at "From ")
7388 (replace-match "X-From-Line: "))
7390 (let ((message-inhibit-body-encoding t)
7391 message-required-mail-headers
7392 message-generate-hashcash
7393 rfc2047-encode-encoded-words)
7394 (message-send-mail))
7395 (kill-buffer (current-buffer)))
7396 (message "Resending message to %s...done" address)))
7399 (defun message-bounce ()
7400 "Re-mail the current message.
7401 This only makes sense if the current message is a bounce message that
7402 contains some mail you have written which has been bounced back to
7405 (let ((handles (mm-dissect-buffer t))
7407 (message-pop-to-buffer (message-buffer-name "bounce"))
7408 (if (stringp (car handles))
7409 ;; This is a MIME bounce.
7410 (mm-insert-part (car (last handles)))
7411 ;; This is a non-MIME bounce, so we try to remove things
7413 (mm-insert-part handles)
7415 (goto-char (point-min))
7416 (re-search-forward "\n\n+" nil t)
7417 (setq boundary (point))
7418 ;; We remove everything before the bounced mail.
7419 (if (or (re-search-forward message-unsent-separator nil t)
7421 (search-forward "\n\n" nil 'move)
7422 (re-search-backward "^Return-Path:.*\n" boundary t)))
7425 (delete-region (point-min)
7426 (if (re-search-forward "^[^ \n\t]+:" nil t)
7429 (goto-char boundary)
7430 (when (re-search-backward "^.?From .*\n" nil t)
7431 (delete-region (match-beginning 0) (match-end 0)))))
7434 (message-narrow-to-head-1)
7435 (message-remove-header message-ignored-bounced-headers t)
7436 (goto-char (point-max))
7437 (insert mail-header-separator))
7438 (message-position-point)))
7441 ;;; Interactive entry points for new message buffers.
7445 (defun message-mail-other-window (&optional to subject)
7446 "Like `message-mail' command, but display mail buffer in another window."
7448 (unless (message-mail-user-agent)
7449 (let ((pop-up-windows t)
7450 (special-display-buffer-names nil)
7451 (special-display-regexps nil)
7452 (same-window-buffer-names nil)
7453 (same-window-regexps nil))
7454 (message-pop-to-buffer (message-buffer-name "mail" to))))
7455 (let ((message-this-is-mail t))
7456 (message-setup `((To . ,(or to "")) (Subject . ,(or subject "")))
7457 nil nil nil 'switch-to-buffer-other-window)))
7460 (defun message-mail-other-frame (&optional to subject)
7461 "Like `message-mail' command, but display mail buffer in another frame."
7463 (unless (message-mail-user-agent)
7464 (let ((pop-up-frames t)
7465 (special-display-buffer-names nil)
7466 (special-display-regexps nil)
7467 (same-window-buffer-names nil)
7468 (same-window-regexps nil))
7469 (message-pop-to-buffer (message-buffer-name "mail" to))))
7470 (let ((message-this-is-mail t))
7471 (message-setup `((To . ,(or to "")) (Subject . ,(or subject "")))
7472 nil nil nil 'switch-to-buffer-other-frame)))
7475 (defun message-news-other-window (&optional newsgroups subject)
7476 "Start editing a news article to be sent."
7478 (let ((pop-up-windows t)
7479 (special-display-buffer-names nil)
7480 (special-display-regexps nil)
7481 (same-window-buffer-names nil)
7482 (same-window-regexps nil))
7483 (message-pop-to-buffer (message-buffer-name "posting" nil newsgroups)))
7484 (let ((message-this-is-news t))
7485 (message-setup `((Newsgroups . ,(or newsgroups ""))
7486 (Subject . ,(or subject ""))))))
7489 (defun message-news-other-frame (&optional newsgroups subject)
7490 "Start editing a news article to be sent."
7492 (let ((pop-up-frames t)
7493 (special-display-buffer-names nil)
7494 (special-display-regexps nil)
7495 (same-window-buffer-names nil)
7496 (same-window-regexps nil))
7497 (message-pop-to-buffer (message-buffer-name "posting" nil newsgroups)))
7498 (let ((message-this-is-news t))
7499 (message-setup `((Newsgroups . ,(or newsgroups ""))
7500 (Subject . ,(or subject ""))))))
7504 ;; This code should be moved to underline.el (from which it is stolen).
7507 (defun message-bold-region (start end)
7508 "Bold all nonblank characters in the region.
7509 Works by overstriking characters.
7510 Called from program, takes two arguments START and END
7511 which specify the range to operate on."
7514 (let ((end1 (make-marker)))
7515 (move-marker end1 (max start end))
7516 (goto-char (min start end))
7517 (while (< (point) end1)
7518 (or (looking-at "[_\^@- ]")
7519 (insert (char-after) "\b"))
7520 (forward-char 1)))))
7523 (defun message-unbold-region (start end)
7524 "Remove all boldness (overstruck characters) in the region.
7525 Called from program, takes two arguments START and END
7526 which specify the range to operate on."
7529 (let ((end1 (make-marker)))
7530 (move-marker end1 (max start end))
7531 (goto-char (min start end))
7532 (while (search-forward "\b" end1 t)
7533 (if (eq (char-after) (char-after (- (point) 2)))
7534 (delete-char -2))))))
7536 (defun message-exchange-point-and-mark ()
7537 "Exchange point and mark, but don't activate region if it was inactive."
7538 (goto-char (prog1 (mark t)
7539 (set-marker (mark-marker) (point)))))
7541 (defalias 'message-make-overlay 'make-overlay)
7542 (defalias 'message-delete-overlay 'delete-overlay)
7543 (defalias 'message-overlay-put 'overlay-put)
7544 (defun message-kill-all-overlays ()
7545 (if (featurep 'xemacs)
7546 (map-extents (lambda (extent ignore) (delete-extent extent)))
7547 (mapcar #'delete-overlay (overlays-in (point-min) (point-max)))))
7549 ;; Support for toolbar
7550 (defvar tool-bar-mode)
7552 ;; Note: The :set function in the `message-tool-bar*' variables will only
7553 ;; affect _new_ message buffers. We might add a function that walks thru all
7554 ;; message-mode buffers and force the update.
7555 (defun message-tool-bar-update (&optional symbol value)
7556 "Update message mode toolbar.
7557 Setter function for custom variables."
7558 (setq-default message-tool-bar-map nil)
7560 ;; When used as ":set" function:
7561 (set-default symbol value)))
7563 (defcustom message-tool-bar (if (eq gmm-tool-bar-style 'gnome)
7564 'message-tool-bar-gnome
7565 'message-tool-bar-retro)
7566 "Specifies the message mode tool bar.
7568 It can be either a list or a symbol refering to a list. See
7569 `gmm-tool-bar-from-list' for the format of the list. The
7570 default key map is `message-mode-map'.
7572 Pre-defined symbols include `message-tool-bar-gnome' and
7573 `message-tool-bar-retro'."
7574 :type '(repeat gmm-tool-bar-list-item)
7575 :type '(choice (const :tag "GNOME style" message-tool-bar-gnome)
7576 (const :tag "Retro look" message-tool-bar-retro)
7577 (repeat :tag "User defined list" gmm-tool-bar-item)
7579 :version "23.1" ;; No Gnus
7580 :initialize 'custom-initialize-default
7581 :set 'message-tool-bar-update
7584 (defcustom message-tool-bar-gnome
7585 '((ispell-message "spell" nil
7586 :visible (or (not (boundp 'flyspell-mode))
7587 (not flyspell-mode)))
7588 (flyspell-buffer "spell" t
7589 :visible (and (boundp 'flyspell-mode)
7591 :help "Flyspell whole buffer")
7592 (gmm-ignore "separator")
7593 (message-send-and-exit "mail/send")
7594 (message-dont-send "mail/save-draft")
7595 (message-kill-buffer "close") ;; stock_cancel
7596 (mml-attach-file "attach" mml-mode-map)
7597 (mml-preview "mail/preview" mml-mode-map)
7598 (mml-secure-message-sign-encrypt "lock" mml-mode-map :visible nil)
7599 (message-insert-importance-high "important" nil :visible nil)
7600 (message-insert-importance-low "unimportant" nil :visible nil)
7601 (message-insert-disposition-notification-to "receipt" nil :visible nil)
7602 (gmm-customize-mode "preferences" t :help "Edit mode preferences")
7603 (message-info "help" t :help "Message manual"))
7604 "List of items for the message tool bar (GNOME style).
7606 See `gmm-tool-bar-from-list' for details on the format of the list."
7607 :type '(repeat gmm-tool-bar-item)
7608 :version "23.1" ;; No Gnus
7609 :initialize 'custom-initialize-default
7610 :set 'message-tool-bar-update
7613 (defcustom message-tool-bar-retro
7614 '(;; Old Emacs 21 icon for consistency.
7615 (message-send-and-exit "gnus/mail-send")
7616 (message-kill-buffer "close")
7617 (message-dont-send "cancel")
7618 (mml-attach-file "attach" mml-mode-map)
7619 (ispell-message "spell")
7620 (mml-preview "preview" mml-mode-map)
7621 (message-insert-importance-high "gnus/important")
7622 (message-insert-importance-low "gnus/unimportant")
7623 (message-insert-disposition-notification-to "gnus/receipt"))
7624 "List of items for the message tool bar (retro style).
7626 See `gmm-tool-bar-from-list' for details on the format of the list."
7627 :type '(repeat gmm-tool-bar-item)
7628 :version "23.1" ;; No Gnus
7629 :initialize 'custom-initialize-default
7630 :set 'message-tool-bar-update
7633 (defcustom message-tool-bar-zap-list
7634 '(new-file open-file dired kill-buffer write-file
7635 print-buffer customize help)
7636 "List of icon items from the global tool bar.
7637 These items are not displayed on the message mode tool bar.
7639 See `gmm-tool-bar-from-list' for the format of the list."
7640 :type 'gmm-tool-bar-zap-list
7641 :version "23.1" ;; No Gnus
7642 :initialize 'custom-initialize-default
7643 :set 'message-tool-bar-update
7646 (defvar image-load-path)
7648 (defun message-make-tool-bar (&optional force)
7649 "Make a message mode tool bar from `message-tool-bar-list'.
7650 When FORCE, rebuild the tool bar."
7651 (when (and (not (featurep 'xemacs))
7652 (boundp 'tool-bar-mode)
7654 (or (not message-tool-bar-map) force))
7655 (setq message-tool-bar-map
7657 (gmm-image-load-path-for-library "message"
7658 "mail/save-draft.xpm"
7660 (image-load-path (cons (car load-path)
7661 (when (boundp 'image-load-path)
7663 (gmm-tool-bar-from-list message-tool-bar
7664 message-tool-bar-zap-list
7665 'message-mode-map))))
7666 message-tool-bar-map)
7668 ;;; Group name completion.
7670 (defcustom message-newgroups-header-regexp
7671 "^\\(Newsgroups\\|Followup-To\\|Posted-To\\|Gcc\\):"
7672 "Regexp that match headers that lists groups."
7676 (defcustom message-completion-alist
7677 (list (cons message-newgroups-header-regexp 'message-expand-group)
7678 '("^\\(Resent-\\)?\\(To\\|B?Cc\\):" . message-expand-name)
7679 '("^\\(Reply-To\\|From\\|Mail-Followup-To\\|Mail-Copies-To\\):"
7680 . message-expand-name)
7681 '("^\\(Disposition-Notification-To\\|Return-Receipt-To\\):"
7682 . message-expand-name))
7683 "Alist of (RE . FUN). Use FUN for completion on header lines matching RE."
7686 :type '(alist :key-type regexp :value-type function))
7688 (defcustom message-expand-name-databases
7690 "List of databases to try for name completion (`message-expand-name').
7691 Each element is a symbol and can be `bbdb' or `eudc'."
7693 :type '(set (const bbdb) (const eudc)))
7695 (defcustom message-tab-body-function nil
7696 "*Function to execute when `message-tab' (TAB) is executed in the body.
7697 If nil, the function bound in `text-mode-map' or `global-map' is executed."
7700 :link '(custom-manual "(message)Various Commands")
7701 :type '(choice (const nil)
7704 (declare-function mail-abbrev-in-expansion-header-p "mailabbrev" ())
7706 (defun message-tab ()
7707 "Complete names according to `message-completion-alist'.
7708 Execute function specified by `message-tab-body-function' when not in
7711 (let ((alist message-completion-alist))
7713 (let ((mail-abbrev-mode-regexp (caar alist)))
7714 (not (mail-abbrev-in-expansion-header-p))))
7715 (setq alist (cdr alist)))
7716 (funcall (or (cdar alist) message-tab-body-function
7717 (lookup-key text-mode-map "\t")
7718 (lookup-key global-map "\t")
7719 'indent-relative))))
7724 (let ((standard-output (current-buffer)))
7725 (eval '(display-completion-list nil "")))
7726 (defalias 'message-display-completion-list 'display-completion-list))
7727 (error ;; Don't use `wrong-number-of-arguments' here because of XEmacs.
7728 (defun message-display-completion-list (completions &optional ignore)
7729 "Display the list of completions, COMPLETIONS, using `standard-output'."
7730 (display-completion-list completions)))))
7732 (defun message-expand-group ()
7733 "Expand the group name under point."
7734 (let* ((b (save-excursion
7739 (skip-chars-forward "^:")
7742 (skip-chars-backward "^, \t\n") (point))))
7743 (completion-ignore-case t)
7744 (e (progn (skip-chars-forward "^,\t\n ") (point)))
7745 (hashtb (and (boundp 'gnus-active-hashtb) gnus-active-hashtb)))
7746 (message-completion-in-region e b hashtb)))
7748 (defalias 'message-completion-in-region
7749 (if (fboundp 'completion-in-region)
7750 'completion-in-region
7751 (lambda (e b hashtb)
7752 (let* ((string (buffer-substring b e))
7753 (completions (all-completions string hashtb))
7755 (delete-region b (point))
7757 ((= (length completions) 1)
7758 (if (string= (car completions) string)
7761 (message "Only matching group"))
7762 (insert (car completions))))
7763 ((and (setq comp (try-completion string hashtb))
7764 (not (string= comp string)))
7769 (message "No matching groups")
7770 (save-selected-window
7771 (pop-to-buffer "*Completions*")
7772 (buffer-disable-undo)
7773 (let ((buffer-read-only nil))
7775 (let ((standard-output (current-buffer)))
7776 (message-display-completion-list (sort completions 'string<)
7778 (setq buffer-read-only nil)
7779 (goto-char (point-min))
7780 (delete-region (point)
7781 (progn (forward-line 3) (point))))))))))))
7783 (defun message-expand-name ()
7784 (cond ((and (memq 'eudc message-expand-name-databases)
7785 (boundp 'eudc-protocol)
7787 (eudc-expand-inline))
7788 ((and (memq 'bbdb message-expand-name-databases)
7789 (fboundp 'bbdb-complete-name))
7790 (bbdb-complete-name))
7796 (defun message-talkative-question (ask question show &rest text)
7797 "Call FUNCTION with argument QUESTION; optionally display TEXT... args.
7798 If SHOW is non-nil, the arguments TEXT... are displayed in a temp buffer.
7799 The following arguments may contain lists of values."
7801 (setq text (message-flatten-list text)))
7802 (save-window-excursion
7803 (with-output-to-temp-buffer " *MESSAGE information message*"
7804 (with-current-buffer " *MESSAGE information message*"
7805 (fundamental-mode) ; for Emacs 20.4+
7807 (goto-char (point-min))))
7808 (funcall ask question))
7809 (funcall ask question)))
7811 (defun message-flatten-list (list)
7812 "Return a new, flat list that contains all elements of LIST.
7814 \(message-flatten-list '(1 (2 3 (4 5 (6))) 7))
7817 (apply 'append (mapcar 'message-flatten-list list)))
7821 (defun message-generate-new-buffer-clone-locals (name &optional varstr)
7822 "Create and return a buffer with name based on NAME using `generate-new-buffer'.
7823 Then clone the local variables and values from the old buffer to the
7824 new one, cloning only the locals having a substring matching the
7826 (let ((oldbuf (current-buffer)))
7827 (with-current-buffer (generate-new-buffer name)
7828 (message-clone-locals oldbuf varstr)
7831 (defun message-clone-locals (buffer &optional varstr)
7832 "Clone the local variables from BUFFER to the current buffer."
7833 (let ((locals (with-current-buffer buffer (buffer-local-variables)))
7834 (regexp "^gnus\\|^nn\\|^message\\|^sendmail\\|^smtp\\|^user-mail-address"))
7837 (when (and (consp local)
7839 (string-match regexp (symbol-name (car local)))
7841 (string-match varstr (symbol-name (car local)))))
7843 (set (make-local-variable (car local))
7851 (defvar message-inhibit-body-encoding nil)
7853 (defun message-encode-message-body ()
7854 (unless message-inhibit-body-encoding
7855 (let ((mail-parse-charset (or mail-parse-charset
7856 message-default-charset))
7857 (case-fold-search t)
7858 lines content-type-p)
7861 (narrow-to-region (point) (point-max))
7862 (let ((new (mml-generate-mime)))
7864 (delete-region (point-min) (point-max))
7866 (goto-char (point-min))
7867 (if (eq (aref new 0) ?\n)
7869 (search-forward "\n\n")
7870 (setq lines (buffer-substring (point-min) (1- (point))))
7871 (delete-region (point-min) (point))))))
7873 (message-narrow-to-headers-or-head)
7874 (message-remove-header "Mime-Version")
7875 (goto-char (point-max))
7876 (insert "MIME-Version: 1.0\n")
7879 (setq content-type-p
7881 (re-search-backward "^Content-Type:" nil t))))
7883 (message-narrow-to-headers-or-head)
7884 (message-remove-first-header "Content-Type")
7885 (message-remove-first-header "Content-Transfer-Encoding"))
7886 ;; We always make sure that the message has a Content-Type
7887 ;; header. This is because some broken MTAs and MUAs get
7888 ;; awfully confused when confronted with a message with a
7889 ;; MIME-Version header and without a Content-Type header. For
7890 ;; instance, Solaris' /usr/bin/mail.
7891 (unless content-type-p
7892 (goto-char (point-min))
7893 ;; For unknown reason, MIME-Version doesn't exist.
7894 (when (re-search-forward "^MIME-Version:" nil t)
7896 (insert "Content-Type: text/plain; charset=us-ascii\n"))))))
7898 (defun message-read-from-minibuffer (prompt &optional initial-contents)
7899 "Read from the minibuffer while providing abbrev expansion."
7900 (if (fboundp 'mail-abbrevs-setup)
7901 (let ((mail-abbrev-mode-regexp "")
7902 (minibuffer-setup-hook 'mail-abbrevs-setup)
7903 (minibuffer-local-map message-minibuffer-local-map))
7904 (read-from-minibuffer prompt initial-contents))
7905 (let ((minibuffer-setup-hook 'mail-abbrev-minibuffer-setup-hook)
7906 (minibuffer-local-map message-minibuffer-local-map))
7907 (read-string prompt initial-contents))))
7909 (defun message-use-alternative-email-as-from ()
7910 "Set From field of the outgoing message to the first matching
7911 address in `message-alternative-emails', looking at To, Cc and
7912 From headers in the original article."
7913 (require 'mail-utils)
7914 (let* ((fields '("To" "Cc" "From"))
7917 (mail-strip-quoted-names
7918 (mapconcat 'message-fetch-reply-field fields ","))
7922 (if (string-match message-alternative-emails (car emails))
7923 (setq email (car emails)
7926 (unless (or (not email) (equal email user-mail-address))
7927 (message-remove-header "From")
7928 (goto-char (point-max))
7929 (insert "From: " (let ((user-mail-address email)) (message-make-from))
7932 (defun message-options-get (symbol)
7933 (cdr (assq symbol message-options)))
7935 (defun message-options-set (symbol value)
7936 (let ((the-cons (assq symbol message-options)))
7939 (setcdr the-cons value)
7940 (setq message-options (delq the-cons message-options)))
7942 (push (cons symbol value) message-options))))
7945 (defun message-options-set-recipient ()
7947 (message-narrow-to-headers-or-head)
7948 (message-options-set 'message-sender
7949 (mail-strip-quoted-names
7950 (message-fetch-field "from")))
7951 (message-options-set 'message-recipients
7952 (mail-strip-quoted-names
7953 (let ((to (message-fetch-field "to"))
7954 (cc (message-fetch-field "cc"))
7955 (bcc (message-fetch-field "bcc")))
7958 (if (and to cc) ", ")
7960 (if (and (or to cc) bcc) ", ")
7963 (defun message-hide-headers ()
7964 "Hide headers based on the `message-hidden-headers' variable."
7965 (let ((regexps (if (stringp message-hidden-headers)
7966 (list message-hidden-headers)
7967 message-hidden-headers))
7968 (inhibit-point-motion-hooks t)
7969 (after-change-functions nil)
7970 (end-of-headers (point-min)))
7974 (message-narrow-to-headers)
7975 (goto-char (point-min))
7977 (if (not (message-hide-header-p regexps))
7978 (message-next-header)
7979 (let ((begin (point))
7981 (message-next-header)
7982 (setq header (buffer-substring begin (point))
7983 header-len (- (point) begin))
7984 (delete-region begin (point))
7985 (goto-char end-of-headers)
7987 (setq end-of-headers
7988 (+ end-of-headers header-len))))))))
7989 (narrow-to-region end-of-headers (point-max))))
7991 (defun message-hide-header-p (regexps)
7994 (when (eq (car regexps) 'not)
7997 (dolist (regexp regexps)
7998 (setq result (or result (looking-at regexp))))
8003 (declare-function ecomplete-add-item "ecomplete" (type key text))
8004 (declare-function ecomplete-save "ecomplete" ())
8006 (defun message-put-addresses-in-ecomplete ()
8007 (require 'ecomplete)
8008 (dolist (header '("to" "cc" "from" "reply-to"))
8009 (let ((value (message-field-value header)))
8010 (dolist (string (mail-header-parse-addresses value 'raw))
8012 (gnus-replace-in-string
8013 (gnus-replace-in-string string "^ +\\| +$" "") "\n" ""))
8014 (ecomplete-add-item 'mail (car (mail-header-parse-address string))
8018 (autoload 'ecomplete-display-matches "ecomplete")
8020 (defun message-display-abbrev (&optional choose)
8021 "Display the next possible abbrev for the text before point."
8022 (interactive (list t))
8023 (when (and (memq (char-after (point-at-bol)) '(?C ?T ?\t ? ))
8024 (message-point-in-header-p)
8027 (while (and (memq (char-after) '(?\t ? ))
8028 (zerop (forward-line -1))))
8029 (looking-at "To:\\|Cc:")))
8030 (let* ((end (point))
8031 (start (save-excursion
8032 (and (re-search-backward "[\n\t ]" nil t)
8034 (word (when start (buffer-substring start end)))
8035 (match (when (and word
8036 (not (zerop (length word))))
8037 (ecomplete-display-matches 'mail word choose))))
8038 (when (and choose match)
8039 (delete-region start end)
8042 ;; To send pre-formatted letters like the example below, you can use
8043 ;; `message-send-form-letter':
8044 ;; --8<---------------cut here---------------start------------->8---
8045 ;; To: alice@invalid.invalid
8046 ;; Subject: Verification of your contact information
8047 ;; From: Contact verification <admin@foo.invalid>
8048 ;; --text follows this line--
8050 ;; please verify that your contact information is still valid:
8051 ;; Alice A, A avenue 11, 1111 A town, Austria
8052 ;; ----------next form letter message follows this line----------
8053 ;; To: bob@invalid.invalid
8054 ;; Subject: Verification of your contact information
8055 ;; From: Contact verification <admin@foo.invalid>
8056 ;; --text follows this line--
8058 ;; please verify that your contact information is still valid:
8059 ;; Bob, B street 22, 22222 Be town, Belgium
8060 ;; ----------next form letter message follows this line----------
8061 ;; To: charlie@invalid.invalid
8062 ;; Subject: Verification of your contact information
8063 ;; From: Contact verification <admin@foo.invalid>
8064 ;; --text follows this line--
8066 ;; please verify that your contact information is still valid:
8067 ;; Charlie Chaplin, C plaza 33, 33333 C town, Chile
8068 ;; --8<---------------cut here---------------end--------------->8---
8070 ;; FIXME: What is the most common term (circular letter, form letter, serial
8071 ;; letter, standard letter) for such kind of letter? See also
8072 ;; <http://en.wikipedia.org/wiki/Form_letter>
8074 ;; FIXME: Maybe extent message-mode's font-lock support to recognize
8075 ;; `message-form-letter-separator', i.e. highlight each message like a single
8078 (defcustom message-form-letter-separator
8079 "\n----------next form letter message follows this line----------\n"
8080 "Separator for `message-send-form-letter'."
8081 ;; :group 'message-form-letter
8082 :group 'message-various
8083 :version "23.1" ;; No Gnus
8086 (defcustom message-send-form-letter-delay 1
8087 "Delay in seconds when sending a message with `message-send-form-letter'.
8088 Only used when `message-send-form-letter' is called with non-nil
8090 ;; :group 'message-form-letter
8091 :group 'message-various
8092 :version "23.1" ;; No Gnus
8095 (defun message-send-form-letter (&optional force)
8096 "Sent all form letter messages from current buffer.
8097 Unless FORCE, prompt before sending.
8099 The messages are separated by `message-form-letter-separator'.
8100 Header and body are separated by `mail-header-separator'."
8102 (let ((sent 0) (skipped 0)
8106 (goto-char (point-min))
8109 end (if (search-forward message-form-letter-separator nil t)
8110 (- (point) (length message-form-letter-separator) -1)
8114 (buffer-substring-no-properties start end))
8115 (setq buff (generate-new-buffer "*mail - form letter*"))
8116 (with-current-buffer buff
8119 (setq to (message-fetch-field "To"))
8120 (switch-to-buffer buff)
8122 (sit-for message-send-form-letter-delay))
8124 (y-or-n-p (format "Send message to `%s'? " to)))
8126 (setq sent (1+ sent))
8127 (message-send-and-exit))
8128 (message (format "Message to `%s' skipped." to))
8129 (setq skipped (1+ skipped)))
8130 (when (buffer-live-p buff)
8131 (kill-buffer buff))))
8132 (message "%s message(s) sent, %s skipped." sent skipped)))
8134 (defun message-replace-header (header new-value &optional after force)
8135 "Remove HEADER and insert the NEW-VALUE.
8136 If AFTER, insert after this header. If FORCE, insert new field
8137 even if NEW-VALUE is empty."
8138 ;; Similar to `nnheader-replace-header' but for message buffers.
8141 (message-narrow-to-headers)
8142 (message-remove-header header))
8143 (when (or force (> (length new-value) 0))
8145 (message-position-on-field header after)
8146 (message-position-on-field header))
8147 (insert new-value))))
8149 (defcustom message-recipients-without-full-name
8150 (list "ding@gnus.org"
8152 "emacs-devel@gnu.org"
8153 "emacs-pretest-bug@gnu.org"
8154 "bug-gnu-emacs@gnu.org")
8155 "Mail addresses that have no full name.
8156 Used in `message-simplify-recipients'."
8157 ;; Maybe the addresses could be extracted from
8158 ;; `gnus-parameter-to-list-alist'?
8159 :type '(choice (const :tag "None" nil)
8161 :version "23.1" ;; No Gnus
8162 :group 'message-headers)
8164 (defun message-simplify-recipients ()
8166 (dolist (hdr '("Cc" "To"))
8167 (message-replace-header
8171 (if (and message-recipients-without-full-name
8173 (regexp-opt message-recipients-without-full-name)
8177 (message-make-from (car addrcomp) (cadr addrcomp))
8179 (when (message-fetch-field hdr)
8180 (mail-extract-address-components
8181 (message-fetch-field hdr) t))
8184 (when (featurep 'xemacs)
8185 (require 'messagexmas)
8186 (message-xmas-redefine))
8190 (run-hooks 'message-load-hook)
8193 ;; coding: iso-8859-1
8196 ;; arch-tag: 94b32cac-4504-4b6c-8181-030ebf380ee0
8197 ;;; message.el ends here