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 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, or (at your option)
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; see the file COPYING. If not, write to the
23 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
24 ;; Boston, MA 02110-1301, USA.
28 ;; This mode provides mail-sending facilities from within Emacs. It
29 ;; consists mainly of large chunks of code from the sendmail.el,
30 ;; gnus-msg.el and rnewspost.el files.
35 (unless (fboundp 'declare-function) (defmacro declare-function (&rest r))))
44 ;; This is apparently necessary even though things are autoloaded.
45 ;; Because we dynamically bind mail-abbrev-mode-regexp, we'd better
46 ;; require mailabbrev here.
47 (if (featurep 'xemacs)
48 (require 'mail-abbrevs)
49 (require 'mailabbrev))
55 (autoload 'mailclient-send-it "mailclient") ;; Emacs 22 or contrib/
57 (defvar gnus-message-group-art)
58 (defvar gnus-list-identifiers) ; gnus-sum is required where necessary
59 (defvar rmail-enable-mime-composing)
61 (defgroup message '((user-mail-address custom-variable)
62 (user-full-name custom-variable))
63 "Mail and news message composing."
64 :link '(custom-manual "(message)Top")
68 (put 'user-mail-address 'custom-type 'string)
69 (put 'user-full-name 'custom-type 'string)
71 (defgroup message-various nil
72 "Various Message Variables."
73 :link '(custom-manual "(message)Various Message Variables")
76 (defgroup message-buffers nil
78 :link '(custom-manual "(message)Message Buffers")
81 (defgroup message-sending nil
83 :link '(custom-manual "(message)Sending Variables")
86 (defgroup message-interface nil
88 :link '(custom-manual "(message)Interface")
91 (defgroup message-forwarding nil
93 :link '(custom-manual "(message)Forwarding")
94 :group 'message-interface)
96 (defgroup message-insertion nil
98 :link '(custom-manual "(message)Insertion")
101 (defgroup message-headers nil
103 :link '(custom-manual "(message)Message Headers")
106 (defgroup message-news nil
107 "Composing News Messages."
110 (defgroup message-mail nil
111 "Composing Mail Messages."
114 (defgroup message-faces nil
115 "Faces used for message composing."
119 (defcustom message-directory "~/Mail/"
120 "*Directory from which all other mail file variables are derived."
121 :group 'message-various
124 (defcustom message-max-buffers 10
125 "*How many buffers to keep before starting to kill them off."
126 :group 'message-buffers
129 (defcustom message-send-rename-function nil
130 "Function called to rename the buffer after sending it."
131 :group 'message-buffers
132 :type '(choice function (const nil)))
134 (defcustom message-fcc-handler-function 'message-output
135 "*A function called to save outgoing articles.
136 This function will be called with the name of the file to store the
137 article in. The default function is `message-output' which saves in Unix
139 :type '(radio (function-item message-output)
140 (function :tag "Other"))
141 :group 'message-sending)
143 (defcustom message-fcc-externalize-attachments nil
144 "If non-nil, attachments are included as external parts in Fcc copies."
147 :group 'message-sending)
149 (defcustom message-courtesy-message
150 "The following message is a courtesy copy of an article\nthat has been posted to %s as well.\n\n"
151 "*This is inserted at the start of a mailed copy of a posted message.
152 If the string contains the format spec \"%s\", the Newsgroups
153 the article has been posted to will be inserted there.
154 If this variable is nil, no such courtesy message will be added."
155 :group 'message-sending
156 :type '(radio string (const nil)))
158 (defcustom message-ignored-bounced-headers
159 "^\\(Received\\|Return-Path\\|Delivered-To\\):"
160 "*Regexp that matches headers to be removed in resent bounced mail."
161 :group 'message-interface
164 (defcustom message-from-style 'default
165 "*Specifies how \"From\" headers look.
167 If nil, they contain just the return address like:
169 If `parens', they look like:
170 king@grassland.com (Elvis Parsley)
171 If `angles', they look like:
172 Elvis Parsley <king@grassland.com>
174 Otherwise, most addresses look like `angles', but they look like
175 `parens' if `angles' would need quoting and `parens' would not."
176 :type '(choice (const :tag "simple" nil)
180 :group 'message-headers)
182 (defcustom message-insert-canlock t
183 "Whether to insert a Cancel-Lock header in news postings."
185 :group 'message-headers
188 (defcustom message-syntax-checks
189 (if message-insert-canlock '((sender . disabled)) nil)
190 ;; Guess this one shouldn't be easy to customize...
191 "*Controls what syntax checks should not be performed on outgoing posts.
192 To disable checking of long signatures, for instance, add
193 `(signature . disabled)' to this list.
195 Don't touch this variable unless you really know what you're doing.
197 Checks include `approved', `bogus-recipient', `continuation-headers',
198 `control-chars', `empty', `existing-newsgroups', `from', `illegible-text',
199 `invisible-text', `long-header-lines', `long-lines', `message-id',
200 `multiple-headers', `new-text', `newsgroups', `quoting-style',
201 `repeated-newsgroups', `reply-to', `sender', `sendsys', `shoot',
202 `shorten-followup-to', `signature', `size', `subject', `subject-cmsg'
203 and `valid-newsgroups'."
205 :type '(repeat sexp)) ; Fixme: improve this
207 (defcustom message-required-headers '((optional . References)
209 "*Headers to be generated or prompted for when sending a message.
210 Also see `message-required-news-headers' and
211 `message-required-mail-headers'."
214 :group 'message-headers
215 :link '(custom-manual "(message)Message Headers")
216 :type '(repeat sexp))
218 (defcustom message-draft-headers '(References From Date)
219 "*Headers to be generated when saving a draft message."
222 :group 'message-headers
223 :link '(custom-manual "(message)Message Headers")
224 :type '(repeat sexp))
226 (defcustom message-required-news-headers
227 '(From Newsgroups Subject Date Message-ID
228 (optional . Organization)
229 (optional . User-Agent))
230 "*Headers to be generated or prompted for when posting an article.
231 RFC977 and RFC1036 require From, Date, Newsgroups, Subject,
232 Message-ID. Organization, Lines, In-Reply-To, Expires, and
233 User-Agent are optional. If you don't want message to insert some
234 header, remove it from this list."
236 :group 'message-headers
237 :link '(custom-manual "(message)Message Headers")
238 :type '(repeat sexp))
240 (defcustom message-required-mail-headers
241 '(From Subject Date (optional . In-Reply-To) Message-ID
242 (optional . User-Agent))
243 "*Headers to be generated or prompted for when mailing a message.
244 It is recommended that From, Date, To, Subject and Message-ID be
245 included. Organization and User-Agent are optional."
247 :group 'message-headers
248 :link '(custom-manual "(message)Message Headers")
249 :type '(repeat sexp))
251 (defcustom message-deletable-headers '(Message-ID Date Lines)
252 "Headers to be deleted if they already exist and were generated by message previously."
253 :group 'message-headers
254 :link '(custom-manual "(message)Message Headers")
257 (defcustom message-ignored-news-headers
258 "^NNTP-Posting-Host:\\|^Xref:\\|^[BGF]cc:\\|^Resent-Fcc:\\|^X-Draft-From:\\|^X-Gnus-Agent-Meta-Information:"
259 "*Regexp of headers to be removed unconditionally before posting."
261 :group 'message-headers
262 :link '(custom-manual "(message)Message Headers")
263 :type '(repeat :value-to-internal (lambda (widget value)
264 (custom-split-regexp-maybe value))
265 :match (lambda (widget value)
267 (widget-editable-list-match widget value)))
270 (defcustom message-ignored-mail-headers
271 "^[GF]cc:\\|^Resent-Fcc:\\|^Xref:\\|^X-Draft-From:\\|^X-Gnus-Agent-Meta-Information:"
272 "*Regexp of headers to be removed unconditionally before mailing."
274 :group 'message-headers
275 :link '(custom-manual "(message)Mail Headers")
278 (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:"
279 "*Header lines matching this regexp will be deleted before posting.
280 It's best to delete old Path and Date headers before posting to avoid
282 :group 'message-interface
283 :link '(custom-manual "(message)Superseding")
284 :type '(repeat :value-to-internal (lambda (widget value)
285 (custom-split-regexp-maybe value))
286 :match (lambda (widget value)
288 (widget-editable-list-match widget value)))
291 (defcustom message-subject-re-regexp
292 "^[ \t]*\\([Rr][Ee]\\(\\[[0-9]*\\]\\)*:[ \t]*\\)*[ \t]*"
293 "*Regexp matching \"Re: \" in the subject line."
294 :group 'message-various
295 :link '(custom-manual "(message)Message Headers")
298 ;;; Start of variables adopted from `message-utils.el'.
300 (defcustom message-subject-trailing-was-query 'ask
301 "*What to do with trailing \"(was: <old subject>)\" in subject lines.
302 If nil, leave the subject unchanged. If it is the symbol `ask', query
303 the user what do do. In this case, the subject is matched against
304 `message-subject-trailing-was-ask-regexp'. If
305 `message-subject-trailing-was-query' is t, always strip the trailing
306 old subject. In this case, `message-subject-trailing-was-regexp' is
309 :type '(choice (const :tag "never" nil)
310 (const :tag "always strip" t)
312 :link '(custom-manual "(message)Message Headers")
313 :group 'message-various)
315 (defcustom message-subject-trailing-was-ask-regexp
316 "[ \t]*\\([[(]+[Ww][Aa][Ss][ \t]*.*[\])]+\\)"
317 "*Regexp matching \"(was: <old subject>)\" in the subject line.
319 The function `message-strip-subject-trailing-was' uses this regexp if
320 `message-subject-trailing-was-query' is set to the symbol `ask'. If
321 the variable is t instead of `ask', use
322 `message-subject-trailing-was-regexp' instead.
324 It is okay to create some false positives here, as the user is asked."
326 :group 'message-various
327 :link '(custom-manual "(message)Message Headers")
330 (defcustom message-subject-trailing-was-regexp
331 "[ \t]*\\((*[Ww][Aa][Ss]:[ \t]*.*)\\)"
332 "*Regexp matching \"(was: <old subject>)\" in the subject line.
334 If `message-subject-trailing-was-query' is set to t, the subject is
335 matched against `message-subject-trailing-was-regexp' in
336 `message-strip-subject-trailing-was'. You should use a regexp creating very
337 few false positives here."
339 :group 'message-various
340 :link '(custom-manual "(message)Message Headers")
343 ;;; marking inserted text
345 (defcustom message-mark-insert-begin
346 "--8<---------------cut here---------------start------------->8---\n"
347 "How to mark the beginning of some inserted text."
350 :link '(custom-manual "(message)Insertion Variables")
351 :group 'message-various)
353 (defcustom message-mark-insert-end
354 "--8<---------------cut here---------------end--------------->8---\n"
355 "How to mark the end of some inserted text."
358 :link '(custom-manual "(message)Insertion Variables")
359 :group 'message-various)
361 (defcustom message-archive-header "X-No-Archive: Yes\n"
362 "Header to insert when you don't want your article to be archived.
363 Archives \(such as groups.google.com\) respect this header."
366 :link '(custom-manual "(message)Header Commands")
367 :group 'message-various)
369 (defcustom message-archive-note
370 "X-No-Archive: Yes - save http://groups.google.com/"
371 "Note to insert why you wouldn't want this posting archived.
372 If nil, don't insert any text in the body."
374 :type '(radio string (const nil))
375 :link '(custom-manual "(message)Header Commands")
376 :group 'message-various)
378 ;;; Crossposts and Followups
379 ;; inspired by JoH-followup-to by Jochem Huhman <joh at gmx.de>
380 ;; new suggestions by R. Weikusat <rw at another.de>
382 (defvar message-cross-post-old-target nil
383 "Old target for cross-posts or follow-ups.")
384 (make-variable-buffer-local 'message-cross-post-old-target)
386 (defcustom message-cross-post-default t
387 "When non-nil `message-cross-post-followup-to' will perform a crosspost.
388 If nil, `message-cross-post-followup-to' will only do a followup. Note that
389 you can explicitly override this setting by calling
390 `message-cross-post-followup-to' with a prefix."
393 :group 'message-various)
395 (defcustom message-cross-post-note "Crosspost & Followup-To: "
396 "Note to insert before signature to notify of cross-post and follow-up."
399 :group 'message-various)
401 (defcustom message-followup-to-note "Followup-To: "
402 "Note to insert before signature to notify of follow-up only."
405 :group 'message-various)
407 (defcustom message-cross-post-note-function 'message-cross-post-insert-note
408 "Function to use to insert note about Crosspost or Followup-To.
409 The function will be called with four arguments. The function should not only
410 insert a note, but also ensure old notes are deleted. See the documentation
411 for `message-cross-post-insert-note'."
414 :group 'message-various)
416 ;;; End of variables adopted from `message-utils.el'.
418 (defcustom message-signature-separator "^-- *$"
419 "Regexp matching the signature separator."
421 :link '(custom-manual "(message)Various Message Variables")
422 :group 'message-various)
424 (defcustom message-elide-ellipsis "\n[...]\n\n"
425 "*The string which is inserted for elided text."
427 :link '(custom-manual "(message)Various Commands")
428 :group 'message-various)
430 (defcustom message-interactive t
431 "Non-nil means when sending a message wait for and display errors.
432 nil means let mailer mail back a message to report errors."
433 :group 'message-sending
435 :link '(custom-manual "(message)Sending Variables")
438 (defcustom message-generate-new-buffers 'unique
439 "*Say whether to create a new message buffer to compose a message.
440 Valid values include:
443 Generate the buffer name in the Message way (e.g., *mail*, *news*,
444 *mail to whom*, *news on group*, etc.) and continue editing in the
445 existing buffer of that name. If there is no such buffer, it will
449 Create the new buffer with the name generated in the Message way.
452 Similar to `unique' but the buffer name begins with \"*unsent \".
455 Similar to nil but the buffer name is simpler like *mail message*.
458 If this is a function, call that function with three parameters:
459 The type, the To address and the group name (any of these may be nil).
460 The function should return the new buffer name."
461 :group 'message-buffers
462 :link '(custom-manual "(message)Message Buffers")
463 :type '(choice (const nil)
464 (sexp :tag "unique" :format "unique\n" :value unique
465 :match (lambda (widget value) (memq value '(unique t))))
468 (function :format "\n %{%t%}: %v")))
470 (defcustom message-kill-buffer-on-exit nil
471 "*Non-nil means that the message buffer will be killed after sending a message."
472 :group 'message-buffers
473 :link '(custom-manual "(message)Message Buffers")
476 (defcustom message-kill-buffer-query t
477 "*Non-nil means that killing a modified message buffer has to be confirmed.
478 This is used by `message-kill-buffer'."
479 :version "23.1" ;; No Gnus
480 :group 'message-buffers
483 (defvar gnus-local-organization)
484 (defcustom message-user-organization
485 (or (and (boundp 'gnus-local-organization)
486 (stringp gnus-local-organization)
487 gnus-local-organization)
488 (getenv "ORGANIZATION")
490 "*String to be used as an Organization header.
491 If t, use `message-user-organization-file'."
492 :group 'message-headers
493 :type '(choice string
494 (const :tag "consult file" t)))
496 (defcustom message-user-organization-file
498 (dolist (f (list "/etc/organization"
499 "/etc/news/organization"
500 "/usr/lib/news/organization"))
501 (when (file-readable-p f)
504 "*Local news organization file."
506 :link '(custom-manual "(message)News Headers")
507 :group 'message-headers)
509 (defcustom message-make-forward-subject-function
510 #'message-forward-subject-name-subject
511 "*List of functions called to generate subject headers for forwarded messages.
512 The subject generated by the previous function is passed into each
515 The provided functions are:
517 * `message-forward-subject-author-subject' Source of article (author or
518 newsgroup), in brackets followed by the subject
519 * `message-forward-subject-name-subject' Source of article (name of author
520 or newsgroup), in brackets followed by the subject
521 * `message-forward-subject-fwd' Subject of article with 'Fwd:' prepended
523 :group 'message-forwarding
524 :link '(custom-manual "(message)Forwarding")
525 :type '(radio (function-item message-forward-subject-author-subject)
526 (function-item message-forward-subject-fwd)
527 (function-item message-forward-subject-name-subject)
528 (repeat :tag "List of functions" function)))
530 (defcustom message-forward-as-mime t
531 "*Non-nil means forward messages as an inline/rfc822 MIME section.
532 Otherwise, directly inline the old message in the forwarded message."
534 :group 'message-forwarding
535 :link '(custom-manual "(message)Forwarding")
538 (defcustom message-forward-show-mml 'best
539 "*Non-nil means show forwarded messages as MML (decoded from MIME).
540 Otherwise, forwarded messages are unchanged.
541 Can also be the symbol `best' to indicate that MML should be
542 used, except when it is a bad idea to use MML. One example where
543 it is a bad idea is when forwarding a signed or encrypted
544 message, because converting MIME to MML would invalidate the
547 :group 'message-forwarding
548 :type '(choice (const :tag "use MML" t)
549 (const :tag "don't use MML " nil)
550 (const :tag "use MML when appropriate" best)))
552 (defcustom message-forward-before-signature t
553 "*Non-nil means put forwarded message before signature, else after."
554 :group 'message-forwarding
557 (defcustom message-wash-forwarded-subjects nil
558 "*Non-nil means try to remove as much cruft as possible from the subject.
559 Done before generating the new subject of a forward."
560 :group 'message-forwarding
561 :link '(custom-manual "(message)Forwarding")
564 (defcustom message-ignored-resent-headers "^Return-receipt\\|^X-Gnus\\|^Gnus-Warning:\\|^>?From "
565 "*All headers that match this regexp will be deleted when resending a message."
566 :group 'message-interface
567 :link '(custom-manual "(message)Resending")
568 :type '(repeat :value-to-internal (lambda (widget value)
569 (custom-split-regexp-maybe value))
570 :match (lambda (widget value)
572 (widget-editable-list-match widget value)))
575 (defcustom message-forward-ignored-headers "^Content-Transfer-Encoding:\\|^X-Gnus"
576 "*All headers that match this regexp will be deleted when forwarding a message."
578 :group 'message-forwarding
579 :type '(repeat :value-to-internal (lambda (widget value)
580 (custom-split-regexp-maybe value))
581 :match (lambda (widget value)
583 (widget-editable-list-match widget value)))
586 (defcustom message-ignored-cited-headers "."
587 "*Delete these headers from the messages you yank."
588 :group 'message-insertion
589 :link '(custom-manual "(message)Insertion Variables")
592 (defcustom message-cite-prefix-regexp
593 (if (string-match "[[:digit:]]" "1")
594 ;; Support POSIX? XEmacs 21.5.27 doesn't.
595 "\\([ \t]*[_.[:word:]]+>+\\|[ \t]*[]>|}]\\)+"
596 ;; ?-, ?_ or ?. MUST NOT be in syntax entry w.
597 (let (non-word-constituents)
598 (with-syntax-table text-mode-syntax-table
599 (setq non-word-constituents
601 (if (string-match "\\w" "_") "" "_")
602 (if (string-match "\\w" ".") "" "."))))
603 (if (equal non-word-constituents "")
604 "\\([ \t]*\\(\\w\\)+>+\\|[ \t]*[]>|}]\\)+"
605 (concat "\\([ \t]*\\(\\w\\|["
606 non-word-constituents
607 "]\\)+>+\\|[ \t]*[]>|}]\\)+"))))
608 "*Regexp matching the longest possible citation prefix on a line."
610 :group 'message-insertion
611 :link '(custom-manual "(message)Insertion Variables")
613 :set (lambda (symbol value)
615 (custom-set-default symbol value)
616 (if (boundp 'gnus-message-cite-prefix-regexp)
617 (setq gnus-message-cite-prefix-regexp
618 (concat "^\\(?:" value "\\)"))))))
620 (defcustom message-cancel-message "I am canceling my own article.\n"
621 "Message to be inserted in the cancel message."
622 :group 'message-interface
623 :link '(custom-manual "(message)Canceling News")
626 (defvar smtpmail-default-smtp-server)
628 (defun message-send-mail-function ()
629 "Return suitable value for the variable `message-send-mail-function'."
630 (cond ((and (require 'sendmail)
631 (boundp 'sendmail-program)
633 (executable-find sendmail-program))
634 'message-send-mail-with-sendmail)
635 ((and (locate-library "smtpmail")
637 smtpmail-default-smtp-server)
638 'message-smtpmail-send-it)
639 ((locate-library "mailclient")
640 'message-send-mail-with-mailclient)
643 (error "Don't know how to send mail. Please customize `message-send-mail-function'")))))
645 ;; Useful to set in site-init.el
646 (defcustom message-send-mail-function (message-send-mail-function)
647 "Function to call to send the current buffer as mail.
648 The headers should be delimited by a line whose contents match the
649 variable `mail-header-separator'.
651 Valid values include `message-send-mail-with-sendmail'
652 `message-send-mail-with-mh', `message-send-mail-with-qmail',
653 `message-smtpmail-send-it', `smtpmail-send-it',
654 `feedmail-send-it' and `message-send-mail-with-mailclient'. The
655 default is system dependent and determined by the function
656 `message-send-mail-function'.
658 See also `send-mail-function'."
659 :type '(radio (function-item message-send-mail-with-sendmail)
660 (function-item message-send-mail-with-mh)
661 (function-item message-send-mail-with-qmail)
662 (function-item message-smtpmail-send-it)
663 (function-item smtpmail-send-it)
664 (function-item feedmail-send-it)
665 (function-item message-send-mail-with-mailclient
666 :tag "Use Mailclient package")
667 (function :tag "Other"))
668 :group 'message-sending
669 :version "23.1" ;; No Gnus
670 :initialize 'custom-initialize-default
671 :link '(custom-manual "(message)Mail Variables")
672 :group 'message-mail)
674 (defcustom message-send-news-function 'message-send-news
675 "Function to call to send the current buffer as news.
676 The headers should be delimited by a line whose contents match the
677 variable `mail-header-separator'."
678 :group 'message-sending
680 :link '(custom-manual "(message)News Variables")
683 (defcustom message-reply-to-function nil
684 "If non-nil, function that should return a list of headers.
685 This function should pick out addresses from the To, Cc, and From headers
686 and respond with new To and Cc headers."
687 :group 'message-interface
688 :link '(custom-manual "(message)Reply")
689 :type '(choice function (const nil)))
691 (defcustom message-wide-reply-to-function nil
692 "If non-nil, function that should return a list of headers.
693 This function should pick out addresses from the To, Cc, and From headers
694 and respond with new To and Cc headers."
695 :group 'message-interface
696 :link '(custom-manual "(message)Wide Reply")
697 :type '(choice function (const nil)))
699 (defcustom message-followup-to-function nil
700 "If non-nil, function that should return a list of headers.
701 This function should pick out addresses from the To, Cc, and From headers
702 and respond with new To and Cc headers."
703 :group 'message-interface
704 :link '(custom-manual "(message)Followup")
705 :type '(choice function (const nil)))
707 (defcustom message-extra-wide-headers nil
708 "If non-nil, a list of additional address headers.
709 These are used when composing a wide reply."
710 :group 'message-sending
711 :type '(repeat string))
713 (defcustom message-use-followup-to 'ask
714 "*Specifies what to do with Followup-To header.
715 If nil, always ignore the header. If it is t, use its value, but
716 query before using the \"poster\" value. If it is the symbol `ask',
717 always query the user whether to use the value. If it is the symbol
718 `use', always use the value."
719 :group 'message-interface
720 :link '(custom-manual "(message)Followup")
721 :type '(choice (const :tag "ignore" nil)
722 (const :tag "use & query" t)
726 (defcustom message-use-mail-followup-to 'use
727 "*Specifies what to do with Mail-Followup-To header.
728 If nil, always ignore the header. If it is the symbol `ask', always
729 query the user whether to use the value. If it is the symbol `use',
730 always use the value."
732 :group 'message-interface
733 :link '(custom-manual "(message)Mailing Lists")
734 :type '(choice (const :tag "ignore" nil)
738 (defcustom message-subscribed-address-functions nil
739 "*Specifies functions for determining list subscription.
740 If nil, do not attempt to determine list subscription with functions.
741 If non-nil, this variable contains a list of functions which return
742 regular expressions to match lists. These functions can be used in
743 conjunction with `message-subscribed-regexps' and
744 `message-subscribed-addresses'."
746 :group 'message-interface
747 :link '(custom-manual "(message)Mailing Lists")
748 :type '(repeat sexp))
750 (defcustom message-subscribed-address-file nil
751 "*A file containing addresses the user is subscribed to.
752 If nil, do not look at any files to determine list subscriptions. If
753 non-nil, each line of this file should be a mailing list address."
755 :group 'message-interface
756 :link '(custom-manual "(message)Mailing Lists")
757 :type '(radio file (const nil)))
759 (defcustom message-subscribed-addresses nil
760 "*Specifies a list of addresses the user is subscribed to.
761 If nil, do not use any predefined list subscriptions. This list of
762 addresses can be used in conjunction with
763 `message-subscribed-address-functions' and `message-subscribed-regexps'."
765 :group 'message-interface
766 :link '(custom-manual "(message)Mailing Lists")
767 :type '(repeat string))
769 (defcustom message-subscribed-regexps nil
770 "*Specifies a list of addresses the user is subscribed to.
771 If nil, do not use any predefined list subscriptions. This list of
772 regular expressions can be used in conjunction with
773 `message-subscribed-address-functions' and `message-subscribed-addresses'."
775 :group 'message-interface
776 :link '(custom-manual "(message)Mailing Lists")
777 :type '(repeat regexp))
779 (defcustom message-allow-no-recipients 'ask
780 "Specifies what to do when there are no recipients other than Gcc/Fcc.
781 If it is the symbol `always', the posting is allowed. If it is the
782 symbol `never', the posting is not allowed. If it is the symbol
783 `ask', you are prompted."
785 :group 'message-interface
786 :link '(custom-manual "(message)Message Headers")
787 :type '(choice (const always)
791 (defcustom message-sendmail-f-is-evil nil
792 "*Non-nil means don't add \"-f username\" to the sendmail command line.
793 Doing so would be even more evil than leaving it out."
794 :group 'message-sending
795 :link '(custom-manual "(message)Mail Variables")
798 (defcustom message-sendmail-envelope-from nil
799 "*Envelope-from when sending mail with sendmail.
800 If this is nil, use `user-mail-address'. If it is the symbol
801 `header', use the From: header of the message."
803 :type '(choice (string :tag "From name")
804 (const :tag "Use From: header from message" header)
805 (const :tag "Use `user-mail-address'" nil))
806 :link '(custom-manual "(message)Mail Variables")
807 :group 'message-sending)
809 (defcustom message-sendmail-extra-arguments nil
810 "Additional arguments to `sendmail-program'."
811 ;; E.g. '("-a" "account") for msmtp
812 :version "23.1" ;; No Gnus
813 :type '(repeat string)
814 ;; :link '(custom-manual "(message)Mail Variables")
815 :group 'message-sending)
817 ;; qmail-related stuff
818 (defcustom message-qmail-inject-program "/var/qmail/bin/qmail-inject"
819 "Location of the qmail-inject program."
820 :group 'message-sending
821 :link '(custom-manual "(message)Mail Variables")
824 (defcustom message-qmail-inject-args nil
825 "Arguments passed to qmail-inject programs.
826 This should be a list of strings, one string for each argument. It
827 may also be a function.
829 For e.g., if you wish to set the envelope sender address so that bounces
830 go to the right place or to deal with listserv's usage of that address, you
831 might set this variable to '(\"-f\" \"you@some.where\")."
832 :group 'message-sending
833 :link '(custom-manual "(message)Mail Variables")
834 :type '(choice (function)
837 (defvar gnus-post-method)
838 (defvar gnus-select-method)
839 (defcustom message-post-method
840 (cond ((and (boundp 'gnus-post-method)
841 (listp gnus-post-method)
844 ((boundp 'gnus-select-method)
847 "*Method used to post news.
848 Note that when posting from inside Gnus, for instance, this
849 variable isn't used."
851 :group 'message-sending
852 ;; This should be the `gnus-select-method' widget, but that might
853 ;; create a dependence to `gnus.el'.
856 ;; FIXME: This should be a temporary workaround until someone implements a
857 ;; proper solution. If a crash happens while replying, the auto-save file
858 ;; will *not* have a `References:' header if `message-generate-headers-first'
859 ;; is nil. See: http://article.gmane.org/gmane.emacs.gnus.general/51138
860 (defcustom message-generate-headers-first '(references)
861 "Which headers should be generated before starting to compose a message.
862 If t, generate all required headers. This can also be a list of headers to
863 generate. The variables `message-required-news-headers' and
864 `message-required-mail-headers' specify which headers to generate.
866 Note that the variable `message-deletable-headers' specifies headers which
867 are to be deleted and then re-generated before sending, so this variable
868 will not have a visible effect for those headers."
869 :group 'message-headers
870 :link '(custom-manual "(message)Message Headers")
871 :type '(choice (const :tag "None" nil)
872 (const :tag "References" '(references))
874 (repeat (sexp :tag "Header"))))
876 (defcustom message-fill-column 72
877 "Column beyond which automatic line-wrapping should happen.
878 Local value for message buffers. If non-nil, also turn on
879 auto-fill in message buffers."
880 :group 'message-various
881 ;; :link '(custom-manual "(message)Message Headers")
882 :type '(choice (const :tag "Don't turn on auto fill" nil)
885 (defcustom message-setup-hook nil
886 "Normal hook, run each time a new outgoing message is initialized.
887 The function `message-setup' runs this hook."
888 :group 'message-various
889 :link '(custom-manual "(message)Various Message Variables")
892 (defcustom message-cancel-hook nil
893 "Hook run when cancelling articles."
894 :group 'message-various
895 :link '(custom-manual "(message)Various Message Variables")
898 (defcustom message-signature-setup-hook nil
899 "Normal hook, run each time a new outgoing message is initialized.
900 It is run after the headers have been inserted and before
901 the signature is inserted."
902 :group 'message-various
903 :link '(custom-manual "(message)Various Message Variables")
906 (defcustom message-mode-hook nil
907 "Hook run in message mode buffers."
908 :group 'message-various
911 (defcustom message-header-hook nil
912 "Hook run in a message mode buffer narrowed to the headers."
913 :group 'message-various
916 (defcustom message-header-setup-hook nil
917 "Hook called narrowed to the headers when setting up a message buffer."
918 :group 'message-various
919 :link '(custom-manual "(message)Various Message Variables")
922 (defcustom message-minibuffer-local-map
923 (let ((map (make-sparse-keymap 'message-minibuffer-local-map)))
924 (set-keymap-parent map minibuffer-local-map)
926 "Keymap for `message-read-from-minibuffer'."
928 :group 'message-various)
930 (defcustom message-citation-line-function 'message-insert-citation-line
931 "*Function called to insert the \"Whomever writes:\" line.
933 Predefined functions include `message-insert-citation-line' and
934 `message-insert-formatted-citation-line' (see the variable
935 `message-citation-line-format').
937 Note that Gnus provides a feature where the reader can click on
938 `writes:' to hide the cited text. If you change this line too much,
939 people who read your message will have to change their Gnus
940 configuration. See the variable `gnus-cite-attribution-suffix'."
942 (function-item :tag "plain" message-insert-citation-line)
943 (function-item :tag "formatted" message-insert-formatted-citation-line)
944 (function :tag "Other"))
945 :link '(custom-manual "(message)Insertion Variables")
946 :group 'message-insertion)
948 (defcustom message-citation-line-format "On %a, %b %d %Y, %N wrote:\n"
949 "Format of the \"Whomever writes:\" line.
951 The string is formatted using `format-spec'. The following
952 constructs are replaced:
954 %f The full From, e.g. \"John Doe <john.doe@example.invalid>\".
955 %n The mail address, e.g. \"john.doe@example.invalid\".
956 %N The real name if present, e.g.: \"John Doe\", else fall
957 back to the mail address.
958 %F The first name if present, e.g.: \"John\".
959 %L The last name if present, e.g.: \"Doe\".
961 All other format specifiers are passed to `format-time-string'
962 which is called using the date from the article your replying to.
963 Extracting the first (%F) and last name (%L) is done
964 heuristically, so you should always check it yourself.
966 Please also read the note in the documentation of
967 `message-citation-line-function'."
968 :type '(choice (const :tag "Plain" "%f writes:")
969 (const :tag "Include date" "On %a, %b %d %Y, %n wrote:")
971 :link '(custom-manual "(message)Insertion Variables")
972 :version "23.1" ;; No Gnus
973 :group 'message-insertion)
975 (defcustom message-yank-prefix "> "
976 "*Prefix inserted on the lines of yanked messages.
977 Fix `message-cite-prefix-regexp' if it is set to an abnormal value.
978 See also `message-yank-cited-prefix' and `message-yank-empty-prefix'."
980 :link '(custom-manual "(message)Insertion Variables")
981 :group 'message-insertion)
983 (defcustom message-yank-cited-prefix ">"
984 "*Prefix inserted on cited lines of yanked messages.
985 Fix `message-cite-prefix-regexp' if it is set to an abnormal value.
986 See also `message-yank-prefix' and `message-yank-empty-prefix'."
989 :link '(custom-manual "(message)Insertion Variables")
990 :group 'message-insertion)
992 (defcustom message-yank-empty-prefix ">"
993 "*Prefix inserted on empty lines of yanked messages.
994 See also `message-yank-prefix' and `message-yank-cited-prefix'."
997 :link '(custom-manual "(message)Insertion Variables")
998 :group 'message-insertion)
1000 (defcustom message-indentation-spaces 3
1001 "*Number of spaces to insert at the beginning of each cited line.
1002 Used by `message-yank-original' via `message-yank-cite'."
1003 :group 'message-insertion
1004 :link '(custom-manual "(message)Insertion Variables")
1007 (defcustom message-cite-function 'message-cite-original
1008 "*Function for citing an original message.
1009 Predefined functions include `message-cite-original' and
1010 `message-cite-original-without-signature'.
1011 Note that these functions use `mail-citation-hook' if that is non-nil."
1012 :type '(radio (function-item message-cite-original)
1013 (function-item message-cite-original-without-signature)
1014 (function-item sc-cite-original)
1015 (function :tag "Other"))
1016 :link '(custom-manual "(message)Insertion Variables")
1017 :group 'message-insertion)
1019 (defcustom message-indent-citation-function 'message-indent-citation
1020 "*Function for modifying a citation just inserted in the mail buffer.
1021 This can also be a list of functions. Each function can find the
1022 citation between (point) and (mark t). And each function should leave
1023 point and mark around the citation text as modified."
1025 :link '(custom-manual "(message)Insertion Variables")
1026 :group 'message-insertion)
1028 (defcustom message-signature t
1029 "*String to be inserted at the end of the message buffer.
1030 If t, the `message-signature-file' file will be inserted instead.
1031 If a function, the result from the function will be used instead.
1032 If a form, the result from the form will be used instead."
1034 :link '(custom-manual "(message)Insertion Variables")
1035 :group 'message-insertion)
1037 (defcustom message-signature-file "~/.signature"
1038 "*Name of file containing the text inserted at end of message buffer.
1039 Ignored if the named file doesn't exist.
1040 If nil, don't insert a signature.
1041 If a path is specified, the value of `message-signature-directory' is ignored,
1043 :type '(choice file (const :tags "None" nil))
1044 :link '(custom-manual "(message)Insertion Variables")
1045 :group 'message-insertion)
1047 (defcustom message-signature-directory nil
1048 "*Name of directory containing signature files.
1049 Comes in handy if you have many such files, handled via posting styles for
1051 If nil, `message-signature-file' is expected to specify the directory if
1053 :type '(choice string (const :tags "None" nil))
1054 :link '(custom-manual "(message)Insertion Variables")
1055 :group 'message-insertion)
1057 (defcustom message-signature-insert-empty-line t
1058 "*If non-nil, insert an empty line before the signature separator."
1061 :link '(custom-manual "(message)Insertion Variables")
1062 :group 'message-insertion)
1064 (defcustom message-distribution-function nil
1065 "*Function called to return a Distribution header."
1066 :group 'message-news
1067 :group 'message-headers
1068 :link '(custom-manual "(message)News Headers")
1069 :type '(choice function (const nil)))
1071 (defcustom message-expires 14
1072 "Number of days before your article expires."
1073 :group 'message-news
1074 :group 'message-headers
1075 :link '(custom-manual "(message)News Headers")
1078 (defcustom message-user-path nil
1079 "If nil, use the NNTP server name in the Path header.
1080 If stringp, use this; if non-nil, use no host name (user name only)."
1081 :group 'message-news
1082 :group 'message-headers
1083 :link '(custom-manual "(message)News Headers")
1084 :type '(choice (const :tag "nntp" nil)
1085 (string :tag "name")
1086 (sexp :tag "none" :format "%t" t)))
1088 (defvar message-reply-buffer nil)
1089 (defvar message-reply-headers nil
1090 "The headers of the current replied article.
1091 It is a vector of the following headers:
1092 \[number subject from date id references chars lines xref extra].")
1093 (defvar message-newsreader nil)
1094 (defvar message-mailer nil)
1095 (defvar message-sent-message-via nil)
1096 (defvar message-checksum nil)
1097 (defvar message-send-actions nil
1098 "A list of actions to be performed upon successful sending of a message.")
1099 (defvar message-exit-actions nil
1100 "A list of actions to be performed upon exiting after sending a message.")
1101 (defvar message-kill-actions nil
1102 "A list of actions to be performed before killing a message buffer.")
1103 (defvar message-postpone-actions nil
1104 "A list of actions to be performed after postponing a message.")
1106 (define-widget 'message-header-lines 'text
1107 "All header lines must be LFD terminated."
1108 :format "%{%t%}:%n%v"
1109 :valid-regexp "^\\'"
1110 :error "All header lines must be newline terminated")
1112 (defcustom message-default-headers ""
1113 "*A string containing header lines to be inserted in outgoing messages.
1114 It is inserted before you edit the message, so you can edit or delete
1116 :group 'message-headers
1117 :link '(custom-manual "(message)Message Headers")
1118 :type 'message-header-lines)
1120 (defcustom message-default-mail-headers ""
1121 "*A string of header lines to be inserted in outgoing mails."
1122 :group 'message-headers
1123 :group 'message-mail
1124 :link '(custom-manual "(message)Mail Headers")
1125 :type 'message-header-lines)
1127 (defcustom message-default-news-headers ""
1128 "*A string of header lines to be inserted in outgoing news articles."
1129 :group 'message-headers
1130 :group 'message-news
1131 :link '(custom-manual "(message)News Headers")
1132 :type 'message-header-lines)
1134 ;; Note: could use /usr/ucb/mail instead of sendmail;
1135 ;; options -t, and -v if not interactive.
1136 (defcustom message-mailer-swallows-blank-line
1137 (if (and (string-match "sparc-sun-sunos\\(\\'\\|[^5]\\)"
1138 system-configuration)
1139 (file-readable-p "/etc/sendmail.cf")
1140 (let ((buffer (get-buffer-create " *temp*")))
1142 (with-current-buffer buffer
1143 (insert-file-contents "/etc/sendmail.cf")
1144 (goto-char (point-min))
1145 (let ((case-fold-search nil))
1146 (re-search-forward "^OR\\>" nil t)))
1147 (kill-buffer buffer))))
1148 ;; According to RFC822, "The field-name must be composed of printable
1149 ;; ASCII characters (i. e., characters that have decimal values between
1150 ;; 33 and 126, except colon)", i. e., any chars except ctl chars,
1152 '(looking-at "[ \t]\\|[][!\"#$%&'()*+,-./0-9;<=>?@A-Z\\\\^_`a-z{|}~]+:"))
1153 "*Set this non-nil if the system's mailer runs the header and body together.
1154 \(This problem exists on Sunos 4 when sendmail is run in remote mode.)
1155 The value should be an expression to test whether the problem will
1157 :group 'message-sending
1158 :link '(custom-manual "(message)Mail Variables")
1162 (define-mail-user-agent 'message-user-agent
1163 'message-mail 'message-send-and-exit
1164 'message-kill-buffer 'message-send-hook)
1166 (defvar message-mh-deletable-headers '(Message-ID Date Lines Sender)
1167 "If non-nil, delete the deletable headers before feeding to mh.")
1169 (defvar message-send-method-alist
1170 '((news message-news-p message-send-via-news)
1171 (mail message-mail-p message-send-via-mail))
1172 "Alist of ways to send outgoing messages.
1173 Each element has the form
1175 \(TYPE PREDICATE FUNCTION)
1177 where TYPE is a symbol that names the method; PREDICATE is a function
1178 called without any parameters to determine whether the message is
1179 a message of type TYPE; and FUNCTION is a function to be called if
1180 PREDICATE returns non-nil. FUNCTION is called with one parameter --
1183 (defcustom message-mail-alias-type 'abbrev
1184 "*What alias expansion type to use in Message buffers.
1185 The default is `abbrev', which uses mailabbrev. `ecomplete' uses
1186 an electric completion mode. nil switches mail aliases off.
1187 This can also be a list of values."
1189 :link '(custom-manual "(message)Mail Aliases")
1190 :type '(choice (const :tag "Use Mailabbrev" abbrev)
1191 (const :tag "Use ecomplete" ecomplete)
1192 (const :tag "No expansion" nil)))
1194 (defcustom message-self-insert-commands '(self-insert-command)
1195 "List of `self-insert-command's used to trigger ecomplete.
1196 When one of those commands is invoked to enter a character in To or Cc
1197 header, ecomplete will suggest the candidates of recipients (see also
1198 `message-mail-alias-type'). If you use some tool to enter non-ASCII
1199 text and it replaces `self-insert-command' with the other command, e.g.
1200 `egg-self-insert-command', you may want to add it to this list."
1201 :group 'message-various
1202 :type '(repeat function))
1204 (defcustom message-auto-save-directory
1205 (file-name-as-directory (nnheader-concat message-directory "drafts"))
1206 "*Directory where Message auto-saves buffers if Gnus isn't running.
1207 If nil, Message won't auto-save."
1208 :group 'message-buffers
1209 :link '(custom-manual "(message)Various Message Variables")
1210 :type '(choice directory (const :tag "Don't auto-save" nil)))
1212 (defcustom message-default-charset
1213 (and (not (mm-multibyte-p)) 'iso-8859-1)
1214 "Default charset used in non-MULE Emacsen.
1215 If nil, you might be asked to input the charset."
1218 :link '(custom-manual "(message)Various Message Variables")
1221 (defcustom message-dont-reply-to-names
1222 (and (boundp 'rmail-dont-reply-to-names) rmail-dont-reply-to-names)
1223 "*Addresses to prune when doing wide replies.
1224 This can be a regexp or a list of regexps. Also, a value of nil means
1225 exclude your own user name only."
1228 :link '(custom-manual "(message)Wide Reply")
1229 :type '(choice (const :tag "Yourself" nil)
1231 (repeat :tag "Regexp List" regexp)))
1233 (defsubst message-dont-reply-to-names ()
1234 (gmm-regexp-concat message-dont-reply-to-names))
1236 (defvar message-shoot-gnksa-feet nil
1237 "*A list of GNKSA feet you are allowed to shoot.
1238 Gnus gives you all the opportunity you could possibly want for
1239 shooting yourself in the foot. Also, Gnus allows you to shoot the
1240 feet of Good Net-Keeping Seal of Approval. The following are foot
1242 `empty-article' Allow you to post an empty article;
1243 `quoted-text-only' Allow you to post quoted text only;
1244 `multiple-copies' Allow you to post multiple copies;
1245 `cancel-messages' Allow you to cancel or supersede messages from
1246 your other email addresses.")
1248 (defsubst message-gnksa-enable-p (feature)
1249 (or (not (listp message-shoot-gnksa-feet))
1250 (memq feature message-shoot-gnksa-feet)))
1252 (defcustom message-hidden-headers '("^References:" "^Face:" "^X-Face:"
1254 "Regexp of headers to be hidden when composing new messages.
1255 This can also be a list of regexps to match headers. Or a list
1256 starting with `not' and followed by regexps."
1259 :link '(custom-manual "(message)Message Headers")
1261 :format "%{%t%}: %[Value Type%] %v"
1262 (regexp :menu-tag "regexp" :format "regexp\n%t: %v")
1263 (repeat :menu-tag "(regexp ...)" :format "(regexp ...)\n%v%i"
1264 (regexp :format "%t: %v"))
1265 (cons :menu-tag "(not regexp ...)" :format "(not regexp ...)\n%v"
1267 (repeat :format "%v%i"
1268 (regexp :format "%t: %v")))))
1270 (defcustom message-cite-articles-with-x-no-archive t
1271 "If non-nil, cite text from articles that has X-No-Archive set."
1275 ;;; Internal variables.
1276 ;;; Well, not really internal.
1278 (defvar message-mode-syntax-table
1279 (let ((table (copy-syntax-table text-mode-syntax-table)))
1280 (modify-syntax-entry ?% ". " table)
1281 (modify-syntax-entry ?> ". " table)
1282 (modify-syntax-entry ?< ". " table)
1284 "Syntax table used while in Message mode.")
1286 (defface message-header-to
1289 (:foreground "DarkOliveGreen1" :bold t))
1292 (:foreground "MidnightBlue" :bold t))
1294 (:bold t :italic t)))
1295 "Face used for displaying From headers."
1296 :group 'message-faces)
1297 ;; backward-compatibility alias
1298 (put 'message-header-to-face 'face-alias 'message-header-to)
1300 (defface message-header-cc
1303 (:foreground "chartreuse1" :bold t))
1306 (:foreground "MidnightBlue"))
1309 "Face used for displaying Cc headers."
1310 :group 'message-faces)
1311 ;; backward-compatibility alias
1312 (put 'message-header-cc-face 'face-alias 'message-header-cc)
1314 (defface message-header-subject
1317 (:foreground "OliveDrab1"))
1320 (:foreground "navy blue" :bold t))
1323 "Face used for displaying subject headers."
1324 :group 'message-faces)
1325 ;; backward-compatibility alias
1326 (put 'message-header-subject-face 'face-alias 'message-header-subject)
1328 (defface message-header-newsgroups
1331 (:foreground "yellow" :bold t :italic t))
1334 (:foreground "blue4" :bold t :italic t))
1336 (:bold t :italic t)))
1337 "Face used for displaying newsgroups headers."
1338 :group 'message-faces)
1339 ;; backward-compatibility alias
1340 (put 'message-header-newsgroups-face 'face-alias 'message-header-newsgroups)
1342 (defface message-header-other
1345 (:foreground "VioletRed1"))
1348 (:foreground "steel blue"))
1350 (:bold t :italic t)))
1351 "Face used for displaying newsgroups headers."
1352 :group 'message-faces)
1353 ;; backward-compatibility alias
1354 (put 'message-header-other-face 'face-alias 'message-header-other)
1356 (defface message-header-name
1359 (:foreground "green"))
1362 (:foreground "cornflower blue"))
1365 "Face used for displaying header names."
1366 :group 'message-faces)
1367 ;; backward-compatibility alias
1368 (put 'message-header-name-face 'face-alias 'message-header-name)
1370 (defface message-header-xheader
1373 (:foreground "DeepSkyBlue1"))
1376 (:foreground "blue"))
1379 "Face used for displaying X-Header headers."
1380 :group 'message-faces)
1381 ;; backward-compatibility alias
1382 (put 'message-header-xheader-face 'face-alias 'message-header-xheader)
1384 (defface message-separator
1387 (:foreground "LightSkyBlue1"))
1390 (:foreground "brown"))
1393 "Face used for displaying the separator."
1394 :group 'message-faces)
1395 ;; backward-compatibility alias
1396 (put 'message-separator-face 'face-alias 'message-separator)
1398 (defface message-cited-text
1401 (:foreground "LightPink1"))
1404 (:foreground "red"))
1407 "Face used for displaying cited text names."
1408 :group 'message-faces)
1409 ;; backward-compatibility alias
1410 (put 'message-cited-text-face 'face-alias 'message-cited-text)
1412 (defface message-mml
1415 (:foreground "MediumSpringGreen"))
1418 (:foreground "ForestGreen"))
1421 "Face used for displaying MML."
1422 :group 'message-faces)
1423 ;; backward-compatibility alias
1424 (put 'message-mml-face 'face-alias 'message-mml)
1426 (defun message-font-lock-make-header-matcher (regexp)
1429 (let ((start (point)))
1432 (goto-char (point-min))
1433 (if (re-search-forward
1434 (concat "^" (regexp-quote mail-header-separator) "$")
1436 (setq limit (min limit (match-beginning 0))))
1438 (and (< start limit)
1439 (re-search-forward ,regexp limit t))))))
1440 (if (featurep 'bytecomp)
1444 (defvar message-font-lock-keywords
1445 (let ((content "[ \t]*\\(.+\\(\n[ \t].*\\)*\\)\n?"))
1446 `((,(message-font-lock-make-header-matcher
1447 (concat "^\\([Tt]o:\\)" content))
1448 (1 'message-header-name)
1449 (2 'message-header-to nil t))
1450 (,(message-font-lock-make-header-matcher
1451 (concat "^\\(^[GBF]?[Cc][Cc]:\\|^[Rr]eply-[Tt]o:\\)" content))
1452 (1 'message-header-name)
1453 (2 'message-header-cc nil t))
1454 (,(message-font-lock-make-header-matcher
1455 (concat "^\\([Ss]ubject:\\)" content))
1456 (1 'message-header-name)
1457 (2 'message-header-subject nil t))
1458 (,(message-font-lock-make-header-matcher
1459 (concat "^\\([Nn]ewsgroups:\\|Followup-[Tt]o:\\)" content))
1460 (1 'message-header-name)
1461 (2 'message-header-newsgroups nil t))
1462 (,(message-font-lock-make-header-matcher
1463 (concat "^\\(X-[A-Za-z0-9-]+:\\|In-Reply-To:\\)" content))
1464 (1 'message-header-name)
1465 (2 'message-header-xheader))
1466 (,(message-font-lock-make-header-matcher
1467 (concat "^\\([A-Z][^: \n\t]+:\\)" content))
1468 (1 'message-header-name)
1469 (2 'message-header-other nil t))
1470 ,@(if (and mail-header-separator
1471 (not (equal mail-header-separator "")))
1472 `((,(concat "^\\(" (regexp-quote mail-header-separator) "\\)$")
1473 1 'message-separator))
1476 (re-search-forward (concat "^\\("
1477 message-cite-prefix-regexp
1480 (0 'message-cited-text))
1481 ("<#/?\\(multipart\\|part\\|external\\|mml\\|secure\\)[^>]*>"
1483 "Additional expressions to highlight in Message mode.")
1486 ;; XEmacs does it like this. For Emacs, we have to set the
1487 ;; `font-lock-defaults' buffer-local variable.
1488 (put 'message-mode 'font-lock-defaults '(message-font-lock-keywords t))
1490 (defvar message-face-alist
1491 '((bold . message-bold-region)
1492 (underline . underline-region)
1493 (default . (lambda (b e)
1494 (message-unbold-region b e)
1495 (ununderline-region b e))))
1496 "Alist of mail and news faces for facemenu.
1497 The cdr of each entry is a function for applying the face to a region.")
1499 (defcustom message-send-hook nil
1500 "Hook run before sending messages.
1501 This hook is run quite early when sending."
1502 :group 'message-various
1503 :options '(ispell-message)
1504 :link '(custom-manual "(message)Various Message Variables")
1507 (defcustom message-send-mail-hook nil
1508 "Hook run before sending mail messages.
1509 This hook is run very late -- just before the message is sent as
1511 :group 'message-various
1512 :link '(custom-manual "(message)Various Message Variables")
1515 (defcustom message-send-news-hook nil
1516 "Hook run before sending news messages.
1517 This hook is run very late -- just before the message is sent as
1519 :group 'message-various
1520 :link '(custom-manual "(message)Various Message Variables")
1523 (defcustom message-sent-hook nil
1524 "Hook run after sending messages."
1525 :group 'message-various
1528 (defvar message-send-coding-system 'binary
1529 "Coding system to encode outgoing mail.")
1531 (defvar message-draft-coding-system
1532 mm-auto-save-coding-system
1533 "*Coding system to compose mail.
1534 If you'd like to make it possible to share draft files between XEmacs
1535 and Emacs, you may use `iso-2022-7bit' for this value at your own risk.
1536 Note that the coding-system `iso-2022-7bit' isn't suitable to all data.")
1538 (defcustom message-send-mail-partially-limit 1000000
1539 "The limitation of messages sent as message/partial.
1540 The lower bound of message size in characters, beyond which the message
1541 should be sent in several parts. If it is nil, the size is unlimited."
1543 :group 'message-buffers
1544 :link '(custom-manual "(message)Mail Variables")
1545 :type '(choice (const :tag "unlimited" nil)
1548 (defcustom message-alternative-emails nil
1549 "*Regexp matching alternative email addresses.
1550 The first address in the To, Cc or From headers of the original
1551 article matching this variable is used as the From field of
1554 This variable has precedence over posting styles and anything that runs
1555 off `message-setup-hook'."
1556 :group 'message-headers
1557 :link '(custom-manual "(message)Message Headers")
1558 :type '(choice (const :tag "Always use primary" nil)
1561 (defcustom message-hierarchical-addresses nil
1562 "A list of hierarchical mail address definitions.
1564 Inside each entry, the first address is the \"top\" address, and
1565 subsequent addresses are subaddresses; this is used to indicate that
1566 mail sent to the first address will automatically be delivered to the
1567 subaddresses. So if the first address appears in the recipient list
1568 for a message, the subaddresses will be removed (if present) before
1569 the mail is sent. All addresses in this structure should be
1572 :group 'message-headers
1573 :type '(repeat (repeat string)))
1575 (defcustom message-mail-user-agent nil
1576 "Like `mail-user-agent'.
1577 Except if it is nil, use Gnus native MUA; if it is t, use
1580 :type '(radio (const :tag "Gnus native"
1583 (const :tag "`mail-user-agent'"
1586 (function-item :tag "Default Emacs mail"
1588 sendmail-user-agent)
1589 (function-item :tag "Emacs interface to MH"
1592 (function :tag "Other"))
1596 (defcustom message-wide-reply-confirm-recipients nil
1597 "Whether to confirm a wide reply to multiple email recipients.
1598 If this variable is nil, don't ask whether to reply to all recipients.
1599 If this variable is non-nil, pose the question \"Reply to all
1600 recipients?\" before a wide reply to multiple recipients. If the user
1601 answers yes, reply to all recipients as usual. If the user answers
1602 no, only reply back to the author."
1604 :group 'message-headers
1605 :link '(custom-manual "(message)Wide Reply")
1608 (defcustom message-user-fqdn nil
1609 "*Domain part of Message-Ids."
1611 :group 'message-headers
1612 :link '(custom-manual "(message)News Headers")
1613 :type '(radio (const :format "%v " nil)
1614 (string :format "FQDN: %v")))
1616 (defcustom message-use-idna (and (condition-case nil (require 'idna)
1618 (mm-coding-system-p 'utf-8)
1619 (executable-find idna-program)
1620 (string= (idna-to-ascii "räksmörgås")
1621 "xn--rksmrgs-5wao1o")
1623 "Whether to encode non-ASCII in domain names into ASCII according to IDNA.
1624 GNU Libidn, and in particular the elisp package \"idna.el\" and
1625 the external program \"idn\", must be installed for this
1626 functionality to work."
1628 :group 'message-headers
1629 :link '(custom-manual "(message)IDNA")
1630 :type '(choice (const :tag "Ask" ask)
1631 (const :tag "Never" nil)
1632 (const :tag "Always" t)))
1634 (defcustom message-generate-hashcash (if (executable-find "hashcash") t)
1635 "*Whether to generate X-Hashcash: headers.
1636 If t, always generate hashcash headers. If `opportunistic',
1637 only generate hashcash headers if it can be done without the user
1638 waiting (i.e., only asynchronously).
1640 You must have the \"hashcash\" binary installed, see `hashcash-path'."
1641 :group 'message-headers
1642 :link '(custom-manual "(message)Mail Headers")
1643 :type '(choice (const :tag "Always" t)
1644 (const :tag "Never" nil)
1645 (const :tag "Opportunistic" opportunistic)))
1647 ;;; Internal variables.
1649 (defvar message-sending-message "Sending...")
1650 (defvar message-buffer-list nil)
1651 (defvar message-this-is-news nil)
1652 (defvar message-this-is-mail nil)
1653 (defvar message-draft-article nil)
1654 (defvar message-mime-part nil)
1655 (defvar message-posting-charset nil)
1656 (defvar message-inserted-headers nil)
1658 ;; Byte-compiler warning
1659 (defvar gnus-active-hashtb)
1660 (defvar gnus-read-active-file)
1662 ;;; Regexp matching the delimiter of messages in UNIX mail format
1663 ;;; (UNIX From lines), minus the initial ^. It should be a copy
1664 ;;; of rmail.el's rmail-unix-mail-delimiter.
1665 (defvar message-unix-mail-delimiter
1666 (let ((time-zone-regexp
1667 (concat "\\([A-Z]?[A-Z]?[A-Z][A-Z]\\( DST\\)?"
1668 "\\|[-+]?[0-9][0-9][0-9][0-9]"
1674 ;; Many things can happen to an RFC 822 mailbox before it is put into
1675 ;; a `From' line. The leading phrase can be stripped, e.g.
1676 ;; `Joe <@w.x:joe@y.z>' -> `<@w.x:joe@y.z>'. The <> can be stripped, e.g.
1677 ;; `<@x.y:joe@y.z>' -> `@x.y:joe@y.z'. Everything starting with a CRLF
1678 ;; can be removed, e.g.
1679 ;; From: joe@y.z (Joe K
1681 ;; can yield `From joe@y.z (Joe K Fri Mar 22 08:11:15 1996', and
1684 ;; can yield `From Joe User Fri Mar 22 08:11:15 1996'.
1685 ;; The mailbox can be removed or be replaced by white space, e.g.
1686 ;; From: "Joe User"{space}{tab}
1688 ;; can yield `From {space}{tab} Fri Mar 22 08:11:15 1996',
1689 ;; where {space} and {tab} represent the Ascii space and tab characters.
1690 ;; We want to match the results of any of these manglings.
1691 ;; The following regexp rejects names whose first characters are
1692 ;; obviously bogus, but after that anything goes.
1693 "\\([^\0-\b\n-\r\^?].*\\)?"
1695 ;; The time the message was sent.
1696 "\\([^\0-\r \^?]+\\) +" ; day of the week
1697 "\\([^\0-\r \^?]+\\) +" ; month
1698 "\\([0-3]?[0-9]\\) +" ; day of month
1699 "\\([0-2][0-9]:[0-5][0-9]\\(:[0-6][0-9]\\)?\\) *" ; time of day
1701 ;; Perhaps a time zone, specified by an abbreviation, or by a
1706 " \\([0-9][0-9]+\\) *"
1708 ;; On some systems the time zone can appear after the year, too.
1712 "\\(remote from .*\\)?"
1715 "Regexp matching the delimiter of messages in UNIX mail format.")
1717 (defvar message-unsent-separator
1718 (concat "^ *---+ +Unsent message follows +---+ *$\\|"
1719 "^ *---+ +Returned message +---+ *$\\|"
1720 "^Start of returned message$\\|"
1721 "^ *---+ +Original message +---+ *$\\|"
1722 "^ *--+ +begin message +--+ *$\\|"
1723 "^ *---+ +Original message follows +---+ *$\\|"
1724 "^ *---+ +Undelivered message follows +---+ *$\\|"
1725 "^------ This is a copy of the message, including all the headers. ------ *$\\|"
1726 "^|? *---+ +Message text follows: +---+ *|?$")
1727 "A regexp that matches the separator before the text of a failed message.")
1729 (defvar message-field-fillers
1730 '((To message-fill-field-address)
1731 (Cc message-fill-field-address)
1732 (From message-fill-field-address))
1733 "Alist of header names/filler functions.")
1735 (defvar message-header-format-alist
1750 (References . message-shorten-references)
1752 "Alist used for formatting headers.")
1754 (defvar message-options nil
1755 "Some saved answers when sending message.")
1757 (defvar message-send-mail-real-function nil
1758 "Internal send mail function.")
1760 (defvar message-bogus-system-names "^localhost\\.\\|\\.local$"
1761 "The regexp of bogus system names.")
1763 (defcustom message-valid-fqdn-regexp
1764 (concat "[a-z0-9][-.a-z0-9]+\\." ;; [hostname.subdomain.]domain.
1766 "\\([a-z][a-z]\\|" ;; two letter country TDLs
1767 "aero\\|arpa\\|bitnet\\|biz\\|bofh\\|"
1768 "cat\\|com\\|coop\\|edu\\|gov\\|"
1769 "info\\|int\\|jobs\\|"
1770 "mil\\|mobi\\|museum\\|name\\|net\\|"
1771 "org\\|pro\\|travel\\|uucp\\)")
1772 ;; http://en.wikipedia.org/wiki/List_of_Internet_top-level_domains
1773 ;; http://en.wikipedia.org/wiki/GTLD
1774 ;; `in the process of being approved': .asia .post .tel .sex
1775 ;; "dead" nato bitnet uucp
1776 "Regular expression that matches a valid FQDN."
1777 ;; see also: gnus-button-valid-fqdn-regexp
1779 :group 'message-headers
1783 (autoload 'gnus-alive-p "gnus-util")
1784 (autoload 'gnus-delay-article "gnus-delay")
1785 (autoload 'gnus-extract-address-components "gnus-util")
1786 (autoload 'gnus-find-method-for-group "gnus")
1787 (autoload 'gnus-group-decoded-name "gnus-group")
1788 (autoload 'gnus-group-name-charset "gnus-group")
1789 (autoload 'gnus-group-name-decode "gnus-group")
1790 (autoload 'gnus-groups-from-server "gnus")
1791 (autoload 'gnus-make-local-hook "gnus-util")
1792 (autoload 'gnus-open-server "gnus-int")
1793 (autoload 'gnus-output-to-mail "gnus-util")
1794 (autoload 'gnus-output-to-rmail "gnus-util")
1795 (autoload 'gnus-request-post "gnus-int")
1796 (autoload 'gnus-select-frame-set-input-focus "gnus-util")
1797 (autoload 'gnus-server-string "gnus")
1798 (autoload 'idna-to-ascii "idna")
1799 (autoload 'message-setup-toolbar "messagexmas")
1800 (autoload 'mh-new-draft-name "mh-comp")
1801 (autoload 'mh-send-letter "mh-comp")
1802 (autoload 'nndraft-request-associate-buffer "nndraft")
1803 (autoload 'nndraft-request-expire-articles "nndraft")
1804 (autoload 'nnvirtual-find-group-art "nnvirtual")
1805 (autoload 'rmail-dont-reply-to "mail-utils")
1806 (autoload 'rmail-msg-is-pruned "rmail")
1807 (autoload 'rmail-msg-restore-non-pruned-header "rmail")
1808 (autoload 'rmail-output "rmailout"))
1813 ;;; Utility functions.
1816 (defmacro message-y-or-n-p (question show &rest text)
1817 "Ask QUESTION, displaying remaining args in a temporary buffer if SHOW."
1818 `(message-talkative-question 'y-or-n-p ,question ,show ,@text))
1820 (defmacro message-delete-line (&optional n)
1821 "Delete the current line (and the next N lines)."
1822 `(delete-region (progn (beginning-of-line) (point))
1823 (progn (forward-line ,(or n 1)) (point))))
1825 (defun message-mark-active-p ()
1826 "Non-nil means the mark and region are currently active in this buffer."
1829 (defun message-unquote-tokens (elems)
1830 "Remove double quotes (\") from strings in list ELEMS."
1831 (mapcar (lambda (item)
1832 (while (string-match "^\\(.*\\)\"\\(.*\\)$" item)
1833 (setq item (concat (match-string 1 item)
1834 (match-string 2 item))))
1838 (defun message-tokenize-header (header &optional separator)
1839 "Split HEADER into a list of header elements.
1840 SEPARATOR is a string of characters to be used as separators. \",\"
1841 is used by default."
1844 (let ((regexp (format "[%s]+" (or separator ",")))
1846 beg quoted elems paren)
1848 (mm-enable-multibyte)
1849 (setq beg (point-min))
1851 (goto-char (point-min))
1856 (cond ((and (> (point) beg)
1858 (and (looking-at regexp)
1861 (push (buffer-substring beg (point)) elems)
1862 (setq beg (match-end 0)))
1863 ((eq (char-after) ?\")
1864 (setq quoted (not quoted)))
1865 ((and (eq (char-after) ?\()
1868 ((and (eq (char-after) ?\))
1871 (nreverse elems)))))
1873 (defun message-mail-file-mbox-p (file)
1874 "Say whether FILE looks like a Unix mbox file."
1875 (when (and (file-exists-p file)
1876 (file-readable-p file)
1877 (file-regular-p file))
1879 (nnheader-insert-file-contents file)
1880 (goto-char (point-min))
1881 (looking-at message-unix-mail-delimiter))))
1883 (defun message-fetch-field (header &optional not-all)
1884 "The same as `mail-fetch-field', only remove all newlines.
1885 The buffer is expected to be narrowed to just the header of the message;
1886 see `message-narrow-to-headers-or-head'."
1887 (let* ((inhibit-point-motion-hooks t)
1888 (value (mail-fetch-field header nil (not not-all))))
1890 (while (string-match "\n[\t ]+" value)
1891 (setq value (replace-match " " t t value)))
1894 (defun message-field-value (header &optional not-all)
1895 "The same as `message-fetch-field', only narrow to the headers first."
1898 (message-narrow-to-headers-or-head)
1899 (message-fetch-field header not-all))))
1901 (defun message-narrow-to-field ()
1902 "Narrow the buffer to the header on the current line."
1904 (while (looking-at "[ \t]")
1910 (if (re-search-forward "^[^ \n\t]" nil t)
1913 (goto-char (point-min)))
1915 (defun message-add-header (&rest headers)
1916 "Add the HEADERS to the message header, skipping those already present."
1919 (unless (string-match "^\\([^:]+\\):[ \t]*[^ \t]" (car headers))
1920 (error "Invalid header `%s'" (car headers)))
1921 (setq hclean (match-string 1 (car headers)))
1923 (message-narrow-to-headers)
1924 (unless (re-search-forward (concat "^" (regexp-quote hclean) ":") nil t)
1925 (goto-char (point-max))
1926 (if (string-match "\n$" (car headers))
1927 (insert (car headers))
1928 (insert (car headers) ?\n)))))
1929 (setq headers (cdr headers))))
1931 (defmacro message-with-reply-buffer (&rest forms)
1932 "Evaluate FORMS in the reply buffer, if it exists."
1933 `(when (and message-reply-buffer
1934 (buffer-name message-reply-buffer))
1935 (with-current-buffer message-reply-buffer
1938 (put 'message-with-reply-buffer 'lisp-indent-function 0)
1939 (put 'message-with-reply-buffer 'edebug-form-spec '(body))
1941 (defun message-fetch-reply-field (header)
1942 "Fetch field HEADER from the message we're replying to."
1943 (message-with-reply-buffer
1945 (mail-narrow-to-head)
1946 (message-fetch-field header))))
1948 (defun message-strip-list-identifiers (subject)
1949 "Remove list identifiers in `gnus-list-identifiers' from string SUBJECT."
1950 (require 'gnus-sum) ; for gnus-list-identifiers
1951 (let ((regexp (if (stringp gnus-list-identifiers)
1952 gnus-list-identifiers
1953 (mapconcat 'identity gnus-list-identifiers " *\\|"))))
1954 (if (string-match (concat "\\(\\(\\(Re: +\\)?\\(" regexp
1955 " *\\)\\)+\\(Re: +\\)?\\)") subject)
1956 (concat (substring subject 0 (match-beginning 1))
1957 (or (match-string 3 subject)
1958 (match-string 5 subject))
1963 (defun message-strip-subject-re (subject)
1964 "Remove \"Re:\" from subject lines in string SUBJECT."
1965 (if (string-match message-subject-re-regexp subject)
1966 (substring subject (match-end 0))
1969 (defcustom message-replacement-char "."
1970 "Replacement character used instead of unprintable or not decodable chars."
1971 :group 'message-various
1972 :version "22.1" ;; Gnus 5.10.9
1973 :type '(choice string
1977 ;; FIXME: We also should call `message-strip-subject-encoded-words'
1978 ;; when forwarding. Probably in `message-make-forward-subject' and
1979 ;; `message-forward-make-body'.
1981 (defun message-strip-subject-encoded-words (subject)
1982 "Fix non-decodable words in SUBJECT."
1983 ;; Cf. `gnus-simplify-subject-fully'.
1984 (let* ((case-fold-search t)
1985 (replacement-chars (format "[%s%s%s]"
1986 message-replacement-char
1987 message-replacement-char
1988 message-replacement-char))
1989 (enc-word-re "=\\?\\([^?]+\\)\\?\\([QB]\\)\\?\\([^?]+\\)\\(\\?=\\)")
1994 (goto-char (point-min))
1995 (when (re-search-forward enc-word-re nil t)
1996 (setq cs-string (match-string 1)))))
1997 cs-coding q-or-b word-beg word-end)
1998 (if (or (not have-marker) ;; No encoded word found...
1999 ;; ... or double encoding was correct:
2000 (and (stringp cs-string)
2001 (setq cs-string (downcase cs-string))
2002 (mm-coding-system-p (intern cs-string))
2006 Decoded Subject \"%s\"
2007 contains a valid encoded word. Decode again? "
2009 (setq cs-coding (intern cs-string))))))
2013 (goto-char (point-min))
2014 (while (re-search-forward enc-word-re nil t)
2015 (setq cs-string (downcase (match-string 1))
2016 q-or-b (match-string 2)
2017 word-beg (match-beginning 0)
2018 word-end (match-end 0))
2020 (if (mm-coding-system-p (intern cs-string))
2021 (setq cs-coding (intern cs-string))
2023 ;; No double encoded subject? => bogus charset.
2026 (mm-read-coding-system
2028 Decoded Subject \"%s\"
2029 contains an encoded word. The charset `%s' is unknown or invalid.
2030 Hit RET to replace non-decodable characters with \"%s\" or enter replacement
2032 subject cs-string message-replacement-char)))
2034 (replace-match (concat "=?" (symbol-name cs-coding)
2037 (goto-char word-beg)
2038 (re-search-forward "=\\?\\([^?]+\\)\\?\\([QB]\\)\\?" word-end t)
2041 (if (string-match "\\`Q\\'" q-or-b)
2044 (message "Replacing non-decodable characters with \"%s\"."
2045 message-replacement-char)
2046 (while (re-search-forward "\\(=[A-F0-9][A-F0-9]\\)+"
2048 (replace-match message-replacement-char)))
2050 (message "Replacing non-decodable characters with \"%s\"."
2052 (re-search-forward "[^?]+" word-end t)
2053 (replace-match replacement-chars))
2054 (re-search-forward "\\?=")
2055 (replace-match "")))))
2056 (rfc2047-decode-region (point-min) (point-max))
2059 ;;; Start of functions adopted from `message-utils.el'.
2061 (defun message-strip-subject-trailing-was (subject)
2062 "Remove trailing \"(was: <old subject>)\" from SUBJECT lines.
2063 Leading \"Re: \" is not stripped by this function. Use the function
2064 `message-strip-subject-re' for this."
2065 (let* ((query message-subject-trailing-was-query)
2070 message-subject-trailing-was-ask-regexp
2071 message-subject-trailing-was-regexp)
2074 (setq new (substring subject 0 (match-beginning 0))))
2075 (if (or (not found) (eq query nil))
2078 (if (message-y-or-n-p
2079 "Strip `(was: <old subject>)' in subject? " t
2081 "Strip `(was: <old subject>)' in subject "
2082 "and use the new one instead?\n\n"
2083 "Current subject is: \""
2085 "New subject would be: \""
2087 "See the variable `message-subject-trailing-was-query' "
2088 "to get rid of this query."
2093 ;;; Suggested by Jonas Steverud @ www.dtek.chalmers.se/~d4jonas/
2095 (defun message-change-subject (new-subject)
2096 "Ask for NEW-SUBJECT header, append (was: <Old Subject>)."
2097 ;; <URL:http://www.landfield.com/usefor/drafts/draft-ietf-usefor-useage--1.02.unpaged>
2100 (read-from-minibuffer "New subject: ")))
2101 (cond ((and (not (or (null new-subject) ; new subject not empty
2102 (zerop (string-width new-subject))
2103 (string-match "^[ \t]*$" new-subject))))
2107 (message-narrow-to-headers)
2108 (message-fetch-field "Subject"))))
2109 (cond ((not old-subject)
2110 (error "No current subject"))
2113 (regexp-quote new-subject)
2115 old-subject)) ; yes, it really is a new subject
2116 ;; delete eventual Re: prefix
2118 (message-strip-subject-re old-subject))
2119 (message-goto-subject)
2120 (message-delete-line)
2121 (insert (concat "Subject: "
2124 old-subject ")\n")))))))))
2126 (defun message-mark-inserted-region (beg end &optional verbatim)
2127 "Mark some region in the current article with enclosing tags.
2128 See `message-mark-insert-begin' and `message-mark-insert-end'.
2129 If VERBATIM, use slrn style verbatim marks (\"#v+\" and \"#v-\")."
2130 (interactive "r\nP")
2132 ;; add to the end of the region first, otherwise end would be invalid
2134 (insert (if verbatim "#v-\n" message-mark-insert-end))
2136 (insert (if verbatim "#v+\n" message-mark-insert-begin))))
2138 (defun message-mark-insert-file (file &optional verbatim)
2139 "Insert FILE at point, marking it with enclosing tags.
2140 See `message-mark-insert-begin' and `message-mark-insert-end'.
2141 If VERBATIM, use slrn style verbatim marks (\"#v+\" and \"#v-\")."
2142 (interactive "fFile to insert: \nP")
2143 ;; reverse insertion to get correct result.
2145 (insert (if verbatim "#v-\n" message-mark-insert-end))
2147 (insert-file-contents file)
2149 (insert (if verbatim "#v+\n" message-mark-insert-begin))))
2151 (defun message-add-archive-header ()
2152 "Insert \"X-No-Archive: Yes\" in the header and a note in the body.
2153 The note can be customized using `message-archive-note'. When called with a
2154 prefix argument, ask for a text to insert. If you don't want the note in the
2155 body, set `message-archive-note' to nil."
2157 (if current-prefix-arg
2158 (setq message-archive-note
2159 (read-from-minibuffer "Reason for No-Archive: "
2160 (cons message-archive-note 0))))
2162 (if (message-goto-signature)
2163 (re-search-backward message-signature-separator))
2164 (when message-archive-note
2165 (insert message-archive-note)
2167 (message-add-header message-archive-header)
2168 (message-sort-headers)))
2170 (defun message-cross-post-followup-to-header (target-group)
2171 "Mangles FollowUp-To and Newsgroups header to point to TARGET-GROUP.
2172 With prefix-argument just set Follow-Up, don't cross-post."
2174 (list ; Completion based on Gnus
2175 (completing-read "Followup To: "
2176 (if (boundp 'gnus-newsrc-alist)
2178 nil nil '("poster" . 0)
2179 (if (boundp 'gnus-group-history)
2180 'gnus-group-history))))
2181 (message-remove-header "Follow[Uu]p-[Tt]o" t)
2182 (message-goto-newsgroups)
2184 ;; if we already did a crosspost before, kill old target
2185 (if (and message-cross-post-old-target
2187 (regexp-quote (concat "," message-cross-post-old-target))
2190 ;; unless (followup is to poster or user explicitly asked not
2191 ;; to cross-post, or target-group is already in Newsgroups)
2192 ;; add target-group to Newsgroups line.
2194 ;; def: cross-post, req:no
2195 (and message-cross-post-default (not current-prefix-arg))
2196 ;; def: no-cross-post, req:yes
2197 (and (not message-cross-post-default) current-prefix-arg))
2198 (not (string-match "poster" target-group))
2199 (not (string-match (regexp-quote target-group)
2200 (message-fetch-field "Newsgroups"))))
2202 (insert (concat "," target-group))))
2203 (end-of-line) ; ensure Followup: comes after Newsgroups:
2204 ;; unless new followup would be identical to Newsgroups line
2205 ;; make a new Followup-To line
2206 (if (not (string-match (concat "^[ \t]*"
2209 (message-fetch-field "Newsgroups")))
2210 (insert (concat "\nFollowup-To: " target-group)))
2211 (setq message-cross-post-old-target target-group))
2213 (defun message-cross-post-insert-note (target-group cross-post in-old
2215 "Insert a in message body note about a set Followup or Crosspost.
2216 If there have been previous notes, delete them. TARGET-GROUP specifies the
2217 group to Followup-To. When CROSS-POST is t, insert note about
2218 crossposting. IN-OLD specifies whether TARGET-GROUP is a member of
2219 OLD-GROUPS. OLD-GROUPS lists the old-groups the posting would have
2220 been made to before the user asked for a Crosspost."
2221 ;; start scanning body for previous uses
2222 (message-goto-signature)
2223 (let ((head (re-search-backward
2224 (concat "^" mail-header-separator)
2225 nil t))) ; just search in body
2226 (message-goto-signature)
2227 (while (re-search-backward
2228 (concat "^" (regexp-quote message-cross-post-note) ".*")
2230 (message-delete-line))
2231 (message-goto-signature)
2232 (while (re-search-backward
2233 (concat "^" (regexp-quote message-followup-to-note) ".*")
2235 (message-delete-line))
2237 (if (message-goto-signature)
2238 (re-search-backward message-signature-separator))
2241 (string-match "^[ \t]*poster[ \t]*$" target-group))
2242 (insert (concat message-followup-to-note target-group "\n"))
2243 (insert (concat message-cross-post-note target-group "\n")))))
2245 (defun message-cross-post-followup-to (target-group)
2246 "Crossposts message and set Followup-To to TARGET-GROUP.
2247 With prefix-argument just set Follow-Up, don't cross-post."
2249 (list ; Completion based on Gnus
2250 (completing-read "Followup To: "
2251 (if (boundp 'gnus-newsrc-alist)
2253 nil nil '("poster" . 0)
2254 (if (boundp 'gnus-group-history)
2255 'gnus-group-history))))
2256 (cond ((not (or (null target-group) ; new subject not empty
2257 (zerop (string-width target-group))
2258 (string-match "^[ \t]*$" target-group)))
2260 (let* ((old-groups (message-fetch-field "Newsgroups"))
2261 (in-old (string-match
2262 (regexp-quote target-group)
2263 (or old-groups ""))))
2264 ;; check whether target exactly matches old Newsgroups
2265 (cond ((not old-groups)
2266 (error "No current newsgroup"))
2270 (regexp-quote target-group)
2273 ;; yes, Newsgroups line must change
2274 (message-cross-post-followup-to-header target-group)
2275 ;; insert note whether we do cross-post or followup-to
2276 (funcall message-cross-post-note-function
2278 (if (or (and message-cross-post-default
2279 (not current-prefix-arg))
2280 (and (not message-cross-post-default)
2281 current-prefix-arg)) t)
2282 in-old old-groups))))))))
2284 ;;; Reduce To: to Cc: or Bcc: header
2286 (defun message-reduce-to-to-cc ()
2287 "Replace contents of To: header with contents of Cc: or Bcc: header."
2290 (save-restriction (message-narrow-to-headers)
2291 (message-fetch-field "cc")))
2293 (if (and (not cc-content)
2296 (message-narrow-to-headers)
2297 (message-fetch-field "bcc"))))
2302 (message-delete-line)
2303 (insert (concat "To: " cc-content "\n"))
2305 (message-narrow-to-headers)
2306 (message-remove-header (if bcc
2310 ;;; End of functions adopted from `message-utils.el'.
2312 (defun message-remove-header (header &optional is-regexp first reverse)
2313 "Remove HEADER in the narrowed buffer.
2314 If IS-REGEXP, HEADER is a regular expression.
2315 If FIRST, only remove the first instance of the header.
2316 Return the number of headers removed."
2317 (goto-char (point-min))
2318 (let ((regexp (if is-regexp header (concat "^" (regexp-quote header) ":")))
2320 (case-fold-search t)
2322 (while (and (not (eobp))
2325 (not (looking-at regexp))
2326 (looking-at regexp))
2333 ;; There might be a continuation header, so we have to search
2334 ;; until we find a new non-continuation line.
2337 (if (re-search-forward "^[^ \t]" nil t)
2338 (goto-char (match-beginning 0))
2341 (if (re-search-forward "^[^ \t]" nil t)
2342 (goto-char (match-beginning 0))
2343 (goto-char (point-max)))))
2346 (defun message-remove-first-header (header)
2347 "Remove the first instance of HEADER if there is more than one."
2349 (regexp (concat "^" (regexp-quote header) ":")))
2351 (goto-char (point-min))
2352 (while (re-search-forward regexp nil t)
2355 (message-remove-header header nil t)
2358 (defun message-narrow-to-headers ()
2359 "Narrow the buffer to the head of the message."
2362 (goto-char (point-min))
2363 (if (re-search-forward
2364 (concat "^" (regexp-quote mail-header-separator) "\n") nil t)
2367 (goto-char (point-min)))
2369 (defun message-narrow-to-head-1 ()
2370 "Like `message-narrow-to-head'. Don't widen."
2372 (goto-char (point-min))
2373 (if (search-forward "\n\n" nil 1)
2376 (goto-char (point-min)))
2378 (defun message-narrow-to-head ()
2379 "Narrow the buffer to the head of the message.
2380 Point is left at the beginning of the narrowed-to region."
2382 (message-narrow-to-head-1))
2384 (defun message-narrow-to-headers-or-head ()
2385 "Narrow the buffer to the head of the message."
2388 (goto-char (point-min))
2389 (if (re-search-forward (concat "\\(\n\\)\n\\|^\\("
2390 (regexp-quote mail-header-separator)
2393 (or (match-end 1) (match-beginning 2))
2395 (goto-char (point-min)))
2397 (defun message-news-p ()
2398 "Say whether the current buffer contains a news message."
2399 (and (not message-this-is-mail)
2400 (or message-this-is-news
2403 (message-narrow-to-headers)
2404 (and (message-fetch-field "newsgroups")
2405 (not (message-fetch-field "posted-to"))))))))
2407 (defun message-mail-p ()
2408 "Say whether the current buffer contains a mail message."
2409 (and (not message-this-is-news)
2410 (or message-this-is-mail
2413 (message-narrow-to-headers)
2414 (or (message-fetch-field "to")
2415 (message-fetch-field "cc")
2416 (message-fetch-field "bcc")))))))
2418 (defun message-subscribed-p ()
2419 "Say whether we need to insert a MFT header."
2420 (or message-subscribed-regexps
2421 message-subscribed-addresses
2422 message-subscribed-address-file
2423 message-subscribed-address-functions))
2425 (defun message-next-header ()
2426 "Go to the beginning of the next header."
2428 (or (eobp) (forward-char 1))
2429 (not (if (re-search-forward "^[^ \t]" nil t)
2431 (goto-char (point-max)))))
2433 (defun message-sort-headers-1 ()
2434 "Sort the buffer as headers using `message-rank' text props."
2435 (goto-char (point-min))
2438 nil 'message-next-header
2440 (message-next-header)
2444 (or (get-text-property (point) 'message-rank)
2447 (defun message-sort-headers ()
2448 "Sort the headers of the current message according to `message-header-format-alist'."
2452 (let ((max (1+ (length message-header-format-alist)))
2454 (message-narrow-to-headers)
2455 (while (re-search-forward "^[^ \n]+:" nil t)
2457 (match-beginning 0) (1+ (match-beginning 0))
2459 (if (setq rank (length (memq (assq (intern (buffer-substring
2461 (1- (match-end 0))))
2462 message-header-format-alist)
2463 message-header-format-alist)))
2466 (message-sort-headers-1))))
2468 (defun message-kill-address ()
2469 "Kill the address under point."
2471 (let ((start (point)))
2472 (message-skip-to-next-address)
2473 (kill-region start (point))))
2476 (autoload 'Info-goto-node "info")
2478 (defun message-info (&optional arg)
2479 "Display the Message manual.
2481 Prefixed with one \\[universal-argument], display the Emacs MIME
2482 manual. With two \\[universal-argument]'s, display the EasyPG or
2483 PGG manual, depending on the value of `mml2015-use'."
2485 (Info-goto-node (format "(%s)Top"
2486 (cond ((eq arg 16) mml2015-use)
2487 ((eq arg 4) 'emacs-mime)
2488 ;; `booleanp' only available in Emacs 22+
2489 ((and (not (memq arg '(nil t)))
2503 (defvar message-mode-map nil)
2505 (unless message-mode-map
2506 (setq message-mode-map (make-keymap))
2507 (set-keymap-parent message-mode-map text-mode-map)
2508 (define-key message-mode-map "\C-c?" 'describe-mode)
2510 (define-key message-mode-map "\C-c\C-f\C-t" 'message-goto-to)
2511 (define-key message-mode-map "\C-c\C-f\C-o" 'message-goto-from)
2512 (define-key message-mode-map "\C-c\C-f\C-b" 'message-goto-bcc)
2513 (define-key message-mode-map "\C-c\C-f\C-w" 'message-goto-fcc)
2514 (define-key message-mode-map "\C-c\C-f\C-c" 'message-goto-cc)
2515 (define-key message-mode-map "\C-c\C-f\C-s" 'message-goto-subject)
2516 (define-key message-mode-map "\C-c\C-f\C-r" 'message-goto-reply-to)
2517 (define-key message-mode-map "\C-c\C-f\C-n" 'message-goto-newsgroups)
2518 (define-key message-mode-map "\C-c\C-f\C-d" 'message-goto-distribution)
2519 (define-key message-mode-map "\C-c\C-f\C-f" 'message-goto-followup-to)
2520 (define-key message-mode-map "\C-c\C-f\C-m" 'message-goto-mail-followup-to)
2521 (define-key message-mode-map "\C-c\C-f\C-k" 'message-goto-keywords)
2522 (define-key message-mode-map "\C-c\C-f\C-u" 'message-goto-summary)
2523 (define-key message-mode-map "\C-c\C-f\C-i"
2524 'message-insert-or-toggle-importance)
2525 (define-key message-mode-map "\C-c\C-f\C-a"
2526 'message-generate-unsubscribed-mail-followup-to)
2528 ;; modify headers (and insert notes in body)
2529 (define-key message-mode-map "\C-c\C-fs" 'message-change-subject)
2531 (define-key message-mode-map "\C-c\C-fx" 'message-cross-post-followup-to)
2532 ;; prefix+message-cross-post-followup-to = same w/o cross-post
2533 (define-key message-mode-map "\C-c\C-ft" 'message-reduce-to-to-cc)
2534 (define-key message-mode-map "\C-c\C-fa" 'message-add-archive-header)
2535 ;; mark inserted text
2536 (define-key message-mode-map "\C-c\M-m" 'message-mark-inserted-region)
2537 (define-key message-mode-map "\C-c\M-f" 'message-mark-insert-file)
2539 (define-key message-mode-map "\C-c\C-b" 'message-goto-body)
2540 (define-key message-mode-map "\C-c\C-i" 'message-goto-signature)
2542 (define-key message-mode-map "\C-c\C-t" 'message-insert-to)
2543 (define-key message-mode-map "\C-c\C-fw" 'message-insert-wide-reply)
2544 (define-key message-mode-map "\C-c\C-n" 'message-insert-newsgroups)
2545 (define-key message-mode-map "\C-c\C-l" 'message-to-list-only)
2546 (define-key message-mode-map "\C-c\C-f\C-e" 'message-insert-expires)
2548 (define-key message-mode-map "\C-c\C-u" 'message-insert-or-toggle-importance)
2549 (define-key message-mode-map "\C-c\M-n"
2550 'message-insert-disposition-notification-to)
2552 (define-key message-mode-map "\C-c\C-y" 'message-yank-original)
2553 (define-key message-mode-map "\C-c\M-\C-y" 'message-yank-buffer)
2554 (define-key message-mode-map "\C-c\C-q" 'message-fill-yanked-message)
2555 (define-key message-mode-map "\C-c\C-w" 'message-insert-signature)
2556 (define-key message-mode-map "\C-c\M-h" 'message-insert-headers)
2557 (define-key message-mode-map "\C-c\C-r" 'message-caesar-buffer-body)
2558 (define-key message-mode-map "\C-c\C-o" 'message-sort-headers)
2559 (define-key message-mode-map "\C-c\M-r" 'message-rename-buffer)
2561 (define-key message-mode-map "\C-c\C-c" 'message-send-and-exit)
2562 (define-key message-mode-map "\C-c\C-s" 'message-send)
2563 (define-key message-mode-map "\C-c\C-k" 'message-kill-buffer)
2564 (define-key message-mode-map "\C-c\C-d" 'message-dont-send)
2565 (define-key message-mode-map "\C-c\n" 'gnus-delay-article)
2567 (define-key message-mode-map "\C-c\M-k" 'message-kill-address)
2568 (define-key message-mode-map "\C-c\C-e" 'message-elide-region)
2569 (define-key message-mode-map "\C-c\C-v" 'message-delete-not-region)
2570 (define-key message-mode-map "\C-c\C-z" 'message-kill-to-signature)
2571 (define-key message-mode-map "\M-\r" 'message-newline-and-reformat)
2572 (define-key message-mode-map [remap split-line] 'message-split-line)
2574 (define-key message-mode-map "\C-c\C-a" 'mml-attach-file)
2576 (define-key message-mode-map "\C-a" 'message-beginning-of-line)
2577 (define-key message-mode-map "\t" 'message-tab)
2578 (define-key message-mode-map "\M-;" 'comment-region)
2580 (define-key message-mode-map "\M-n" 'message-display-abbrev))
2583 message-mode-menu message-mode-map "Message Menu."
2585 ["Yank Original" message-yank-original message-reply-buffer]
2586 ["Fill Yanked Message" message-fill-yanked-message t]
2587 ["Insert Signature" message-insert-signature t]
2588 ["Caesar (rot13) Message" message-caesar-buffer-body t]
2589 ["Caesar (rot13) Region" message-caesar-region (message-mark-active-p)]
2590 ["Elide Region" message-elide-region
2591 :active (message-mark-active-p)
2592 ,@(if (featurep 'xemacs) nil
2593 '(:help "Replace text in region with an ellipsis"))]
2594 ["Delete Outside Region" message-delete-not-region
2595 :active (message-mark-active-p)
2596 ,@(if (featurep 'xemacs) nil
2597 '(:help "Delete all quoted text outside region"))]
2598 ["Kill To Signature" message-kill-to-signature t]
2599 ["Newline and Reformat" message-newline-and-reformat t]
2600 ["Rename buffer" message-rename-buffer t]
2601 ["Spellcheck" ispell-message
2602 ,@(if (featurep 'xemacs) '(t)
2603 '(:help "Spellcheck this message"))]
2605 ["Insert Region Marked" message-mark-inserted-region
2606 :active (message-mark-active-p)
2607 ,@(if (featurep 'xemacs) nil
2608 '(:help "Mark region with enclosing tags"))]
2609 ["Insert File Marked..." message-mark-insert-file
2610 ,@(if (featurep 'xemacs) '(t)
2611 '(:help "Insert file at point marked with enclosing tags"))]
2613 ["Send Message" message-send-and-exit
2614 ,@(if (featurep 'xemacs) '(t)
2615 '(:help "Send this message"))]
2616 ["Postpone Message" message-dont-send
2617 ,@(if (featurep 'xemacs) '(t)
2618 '(:help "File this draft message and exit"))]
2619 ["Send at Specific Time..." gnus-delay-article
2620 ,@(if (featurep 'xemacs) '(t)
2621 '(:help "Ask, then arrange to send message at that time"))]
2622 ["Kill Message" message-kill-buffer
2623 ,@(if (featurep 'xemacs) '(t)
2624 '(:help "Delete this message without sending"))]
2626 ["Message manual" message-info
2627 ,@(if (featurep 'xemacs) '(t)
2628 '(:help "Display the Message manual"))]))
2631 message-mode-field-menu message-mode-map ""
2633 ["To" message-goto-to t]
2634 ["From" message-goto-from t]
2635 ["Subject" message-goto-subject t]
2636 ["Change subject..." message-change-subject t]
2637 ["Cc" message-goto-cc t]
2638 ["Bcc" message-goto-bcc t]
2639 ["Fcc" message-goto-fcc t]
2640 ["Reply-To" message-goto-reply-to t]
2641 ["Flag As Important" message-insert-importance-high
2642 ,@(if (featurep 'xemacs) '(t)
2643 '(:help "Mark this message as important"))]
2644 ["Flag As Unimportant" message-insert-importance-low
2645 ,@(if (featurep 'xemacs) '(t)
2646 '(:help "Mark this message as unimportant"))]
2648 message-insert-disposition-notification-to
2649 ,@(if (featurep 'xemacs) '(t)
2650 '(:help "Request a receipt notification"))]
2652 ;; (typical) news stuff
2653 ["Summary" message-goto-summary t]
2654 ["Keywords" message-goto-keywords t]
2655 ["Newsgroups" message-goto-newsgroups t]
2656 ["Fetch Newsgroups" message-insert-newsgroups t]
2657 ["Followup-To" message-goto-followup-to t]
2658 ;; ["Followup-To (with note in body)" message-cross-post-followup-to t]
2659 ["Crosspost / Followup-To..." message-cross-post-followup-to t]
2660 ["Distribution" message-goto-distribution t]
2661 ["Expires" message-insert-expires t ]
2662 ["X-No-Archive" message-add-archive-header t ]
2664 ;; (typical) mailing-lists stuff
2665 ["Fetch To" message-insert-to
2666 ,@(if (featurep 'xemacs) '(t)
2667 '(:help "Insert a To header that points to the author."))]
2668 ["Fetch To and Cc" message-insert-wide-reply
2669 ,@(if (featurep 'xemacs) '(t)
2671 "Insert To and Cc headers as if you were doing a wide reply."))]
2673 ["Send to list only" message-to-list-only t]
2674 ["Mail-Followup-To" message-goto-mail-followup-to t]
2675 ["Unsubscribed list post" message-generate-unsubscribed-mail-followup-to
2676 ,@(if (featurep 'xemacs) '(t)
2677 '(:help "Insert a reasonable `Mail-Followup-To:' header."))]
2678 ["Reduce To: to Cc:" message-reduce-to-to-cc t]
2680 ["Sort Headers" message-sort-headers t]
2681 ["Encode non-ASCII domain names" message-idna-to-ascii-rhs t]
2682 ;; We hide `message-hidden-headers' by narrowing the buffer.
2683 ["Show Hidden Headers" widen t]
2684 ["Goto Body" message-goto-body t]
2685 ["Goto Signature" message-goto-signature t]))
2687 (defvar message-tool-bar-map nil)
2689 (defvar facemenu-add-face-function)
2690 (defvar facemenu-remove-face-function)
2692 ;;; Forbidden properties
2694 ;; We use `after-change-functions' to keep special text properties
2695 ;; that interfer with the normal function of message mode out of the
2698 (defcustom message-strip-special-text-properties t
2699 "Strip special properties from the message buffer.
2701 Emacs has a number of special text properties which can break message
2702 composing in various ways. If this option is set, message will strip
2703 these properties from the message composition buffer. However, some
2704 packages requires these properties to be present in order to work.
2705 If you use one of these packages, turn this option off, and hope the
2706 message composition doesn't break too bad."
2708 :group 'message-various
2709 :link '(custom-manual "(message)Various Message Variables")
2712 (defconst message-forbidden-properties
2713 ;; No reason this should be clutter up customize. We make it a
2714 ;; property list (rather than a list of property symbols), to be
2715 ;; directly useful for `remove-text-properties'.
2716 '(field nil read-only nil invisible nil intangible nil
2717 mouse-face nil modification-hooks nil insert-in-front-hooks nil
2718 insert-behind-hooks nil point-entered nil point-left nil)
2719 ;; Other special properties:
2720 ;; category, face, display: probably doesn't do any harm.
2721 ;; fontified: is used by font-lock.
2722 ;; syntax-table, local-map: I dunno.
2723 ;; We need to add XEmacs names to the list.
2724 "Property list of with properties forbidden in message buffers.
2725 The values of the properties are ignored, only the property names are used.")
2727 (defun message-tamago-not-in-use-p (pos)
2728 "Return t when tamago version 4 is not in use at the cursor position.
2729 Tamago version 4 is a popular input method for writing Japanese text.
2730 It uses the properties `intangible', `invisible', `modification-hooks'
2731 and `read-only' when translating ascii or kana text to kanji text.
2732 These properties are essential to work, so we should never strip them."
2733 (not (and (boundp 'egg-modefull-mode)
2734 (symbol-value 'egg-modefull-mode)
2735 (or (memq (get-text-property pos 'intangible)
2736 '(its-part-1 its-part-2))
2737 (get-text-property pos 'egg-end)
2738 (get-text-property pos 'egg-lang)
2739 (get-text-property pos 'egg-start)))))
2741 (defsubst message-mail-alias-type-p (type)
2742 (if (atom message-mail-alias-type)
2743 (eq message-mail-alias-type type)
2744 (memq type message-mail-alias-type)))
2746 (defun message-strip-forbidden-properties (begin end &optional old-length)
2747 "Strip forbidden properties between BEGIN and END, ignoring the third arg.
2748 This function is intended to be called from `after-change-functions'.
2749 See also `message-forbidden-properties'."
2750 (when (and (message-mail-alias-type-p 'ecomplete)
2751 (memq this-command message-self-insert-commands))
2752 (message-display-abbrev))
2753 (when (and message-strip-special-text-properties
2754 (message-tamago-not-in-use-p begin))
2755 (let ((buffer-read-only nil)
2756 (inhibit-read-only t))
2757 (remove-text-properties begin end message-forbidden-properties))))
2760 (define-derived-mode message-mode text-mode "Message"
2761 "Major mode for editing mail and news to be sent.
2762 Like Text Mode but with these additional commands:\\<message-mode-map>
2763 C-c C-s `message-send' (send the message) C-c C-c `message-send-and-exit'
2764 C-c C-d Postpone sending the message C-c C-k Kill the message
2765 C-c C-f move to a header field (and create it if there isn't):
2766 C-c C-f C-t move to To C-c C-f C-s move to Subject
2767 C-c C-f C-c move to Cc C-c C-f C-b move to Bcc
2768 C-c C-f C-w move to Fcc C-c C-f C-r move to Reply-To
2769 C-c C-f C-u move to Summary C-c C-f C-n move to Newsgroups
2770 C-c C-f C-k move to Keywords C-c C-f C-d move to Distribution
2771 C-c C-f C-o move to From (\"Originator\")
2772 C-c C-f C-f move to Followup-To
2773 C-c C-f C-m move to Mail-Followup-To
2774 C-c C-f C-e move to Expires
2775 C-c C-f C-i cycle through Importance values
2776 C-c C-f s change subject and append \"(was: <Old Subject>)\"
2777 C-c C-f x crossposting with FollowUp-To header and note in body
2778 C-c C-f t replace To: header with contents of Cc: or Bcc:
2779 C-c C-f a Insert X-No-Archive: header and a note in the body
2780 C-c C-t `message-insert-to' (add a To header to a news followup)
2781 C-c C-l `message-to-list-only' (removes all but list address in to/cc)
2782 C-c C-n `message-insert-newsgroups' (add a Newsgroup header to a news reply)
2783 C-c C-b `message-goto-body' (move to beginning of message text).
2784 C-c C-i `message-goto-signature' (move to the beginning of the signature).
2785 C-c C-w `message-insert-signature' (insert `message-signature-file' file).
2786 C-c C-y `message-yank-original' (insert current message, if any).
2787 C-c C-q `message-fill-yanked-message' (fill what was yanked).
2788 C-c C-e `message-elide-region' (elide the text between point and mark).
2789 C-c C-v `message-delete-not-region' (remove the text outside the region).
2790 C-c C-z `message-kill-to-signature' (kill the text up to the signature).
2791 C-c C-r `message-caesar-buffer-body' (rot13 the message body).
2792 C-c C-a `mml-attach-file' (attach a file as MIME).
2793 C-c C-u `message-insert-or-toggle-importance' (insert or cycle importance).
2794 C-c M-n `message-insert-disposition-notification-to' (request receipt).
2795 C-c M-m `message-mark-inserted-region' (mark region with enclosing tags).
2796 C-c M-f `message-mark-insert-file' (insert file marked with enclosing tags).
2797 M-RET `message-newline-and-reformat' (break the line and reformat)."
2798 (setq local-abbrev-table text-mode-abbrev-table)
2799 (set (make-local-variable 'message-reply-buffer) nil)
2800 (set (make-local-variable 'message-inserted-headers) nil)
2801 (set (make-local-variable 'message-send-actions) nil)
2802 (set (make-local-variable 'message-exit-actions) nil)
2803 (set (make-local-variable 'message-kill-actions) nil)
2804 (set (make-local-variable 'message-postpone-actions) nil)
2805 (set (make-local-variable 'message-draft-article) nil)
2806 (setq buffer-offer-save t)
2807 (set (make-local-variable 'facemenu-add-face-function)
2809 (let ((face-fun (cdr (assq face message-face-alist))))
2811 (funcall face-fun (point) end)
2812 (error "Face %s not configured for %s mode" face mode-name)))
2814 (set (make-local-variable 'facemenu-remove-face-function) t)
2815 (set (make-local-variable 'message-reply-headers) nil)
2816 (make-local-variable 'message-newsreader)
2817 (make-local-variable 'message-mailer)
2818 (make-local-variable 'message-post-method)
2819 (set (make-local-variable 'message-sent-message-via) nil)
2820 (set (make-local-variable 'message-checksum) nil)
2821 (set (make-local-variable 'message-mime-part) 0)
2822 (message-setup-fill-variables)
2823 (when message-fill-column
2824 (setq fill-column message-fill-column)
2825 (turn-on-auto-fill))
2826 ;; Allow using comment commands to add/remove quoting.
2827 ;; (set (make-local-variable 'comment-start) message-yank-prefix)
2828 (when message-yank-prefix
2829 (set (make-local-variable 'comment-start) message-yank-prefix)
2830 (set (make-local-variable 'comment-start-skip)
2831 (concat "^" (regexp-quote message-yank-prefix) "[ \t]*")))
2832 (if (featurep 'xemacs)
2833 (message-setup-toolbar)
2834 (set (make-local-variable 'font-lock-defaults)
2835 '(message-font-lock-keywords t))
2836 (if (boundp 'tool-bar-map)
2837 (set (make-local-variable 'tool-bar-map) (message-make-tool-bar))))
2838 (easy-menu-add message-mode-menu message-mode-map)
2839 (easy-menu-add message-mode-field-menu message-mode-map)
2840 (gnus-make-local-hook 'after-change-functions)
2841 ;; Mmmm... Forbidden properties...
2842 (add-hook 'after-change-functions 'message-strip-forbidden-properties
2844 ;; Allow mail alias things.
2846 ((message-mail-alias-type-p 'abbrev)
2847 (if (fboundp 'mail-abbrevs-setup)
2848 (mail-abbrevs-setup)
2849 (if (fboundp 'mail-aliases-setup) ; warning avoidance
2850 (mail-aliases-setup))))
2851 ((message-mail-alias-type-p 'ecomplete)
2853 (unless buffer-file-name
2854 (message-set-auto-save-file-name))
2855 (unless (buffer-base-buffer)
2856 ;; Don't enable multibyte on an indirect buffer. Maybe enabling
2857 ;; multibyte is not necessary at all. -- zsh
2858 (mm-enable-multibyte))
2859 (set (make-local-variable 'indent-tabs-mode) nil) ;No tabs for indentation.
2862 (defun message-setup-fill-variables ()
2863 "Setup message fill variables."
2864 (set (make-local-variable 'fill-paragraph-function)
2865 'message-fill-paragraph)
2866 (make-local-variable 'paragraph-separate)
2867 (make-local-variable 'paragraph-start)
2868 (make-local-variable 'adaptive-fill-regexp)
2869 (unless (boundp 'adaptive-fill-first-line-regexp)
2870 (setq adaptive-fill-first-line-regexp nil))
2871 (make-local-variable 'adaptive-fill-first-line-regexp)
2872 (let ((quote-prefix-regexp
2873 ;; User should change message-cite-prefix-regexp if
2874 ;; message-yank-prefix is set to an abnormal value.
2875 (concat "\\(" message-cite-prefix-regexp "\\)[ \t]*")))
2876 (setq paragraph-start
2878 (regexp-quote mail-header-separator) "$\\|"
2879 "[ \t]*$\\|" ; blank lines
2880 "-- $\\|" ; signature delimiter
2881 "---+$\\|" ; delimiters for forwarded messages
2882 page-delimiter "$\\|" ; spoiler warnings
2883 ".*wrote:$\\|" ; attribution lines
2884 quote-prefix-regexp "$\\|" ; empty lines in quoted text
2886 "<#!*/?\\(multipart\\|part\\|external\\|mml\\|secure\\)"))
2887 (setq paragraph-separate paragraph-start)
2888 (setq adaptive-fill-regexp
2889 (concat quote-prefix-regexp "\\|" adaptive-fill-regexp))
2890 (setq adaptive-fill-first-line-regexp
2891 (concat quote-prefix-regexp "\\|"
2892 adaptive-fill-first-line-regexp)))
2893 (make-local-variable 'auto-fill-inhibit-regexp)
2894 ;;(setq auto-fill-inhibit-regexp "^[A-Z][^: \n\t]+:")
2895 (setq auto-fill-inhibit-regexp nil)
2896 (make-local-variable 'normal-auto-fill-function)
2897 (setq normal-auto-fill-function 'message-do-auto-fill)
2898 ;; KLUDGE: auto fill might already be turned on in `text-mode-hook'.
2899 ;; In that case, ensure that it uses the right function. The real
2900 ;; solution would be not to use `define-derived-mode', and run
2901 ;; `text-mode-hook' ourself at the end of the mode.
2902 ;; -- Per Abrahamsen <abraham@dina.kvl.dk> Date: 2001-10-19.
2903 ;; This kludge is unneeded in Emacs>=21 since define-derived-mode is
2904 ;; now careful to run parent hooks after the body. --Stef
2905 (when auto-fill-function
2906 (setq auto-fill-function normal-auto-fill-function)))
2911 ;;; Message mode commands
2914 ;;; Movement commands
2916 (defun message-goto-to ()
2917 "Move point to the To header."
2919 (message-position-on-field "To"))
2921 (defun message-goto-from ()
2922 "Move point to the From header."
2924 (message-position-on-field "From"))
2926 (defun message-goto-subject ()
2927 "Move point to the Subject header."
2929 (message-position-on-field "Subject"))
2931 (defun message-goto-cc ()
2932 "Move point to the Cc header."
2934 (message-position-on-field "Cc" "To"))
2936 (defun message-goto-bcc ()
2937 "Move point to the Bcc header."
2939 (message-position-on-field "Bcc" "Cc" "To"))
2941 (defun message-goto-fcc ()
2942 "Move point to the Fcc header."
2944 (message-position-on-field "Fcc" "To" "Newsgroups"))
2946 (defun message-goto-reply-to ()
2947 "Move point to the Reply-To header."
2949 (message-position-on-field "Reply-To" "Subject"))
2951 (defun message-goto-newsgroups ()
2952 "Move point to the Newsgroups header."
2954 (message-position-on-field "Newsgroups"))
2956 (defun message-goto-distribution ()
2957 "Move point to the Distribution header."
2959 (message-position-on-field "Distribution"))
2961 (defun message-goto-followup-to ()
2962 "Move point to the Followup-To header."
2964 (message-position-on-field "Followup-To" "Newsgroups"))
2966 (defun message-goto-mail-followup-to ()
2967 "Move point to the Mail-Followup-To header."
2969 (message-position-on-field "Mail-Followup-To" "To"))
2971 (defun message-goto-keywords ()
2972 "Move point to the Keywords header."
2974 (message-position-on-field "Keywords" "Subject"))
2976 (defun message-goto-summary ()
2977 "Move point to the Summary header."
2979 (message-position-on-field "Summary" "Subject"))
2981 (defun message-goto-body (&optional interactivep)
2982 "Move point to the beginning of the message body."
2983 (interactive (list t))
2984 (when (and interactivep
2985 (looking-at "[ \t]*\n"))
2987 (goto-char (point-min))
2988 (or (search-forward (concat "\n" mail-header-separator "\n") nil t)
2989 (search-forward-regexp "[^:]+:\\([^\n]\\|\n[ \t]\\)+\n\n" nil t)))
2991 (defun message-in-body-p ()
2992 "Return t if point is in the message body."
2993 (let ((body (save-excursion (message-goto-body) (point))))
2996 (defun message-goto-eoh ()
2997 "Move point to the end of the headers."
3002 (defun message-goto-signature ()
3003 "Move point to the beginning of the message signature.
3004 If there is no signature in the article, go to the end and
3007 (goto-char (point-min))
3008 (if (re-search-forward message-signature-separator nil t)
3010 (goto-char (point-max))
3013 (defun message-generate-unsubscribed-mail-followup-to (&optional include-cc)
3014 "Insert a reasonable MFT header in a post to an unsubscribed list.
3015 When making original posts to a mailing list you are not subscribed to,
3016 you have to type in a MFT header by hand. The contents, usually, are
3017 the addresses of the list and your own address. This function inserts
3018 such a header automatically. It fetches the contents of the To: header
3019 in the current mail buffer, and appends the current `user-mail-address'.
3021 If the optional argument INCLUDE-CC is non-nil, the addresses in the
3022 Cc: header are also put into the MFT."
3027 (message-narrow-to-headers)
3028 (message-remove-header "Mail-Followup-To")
3029 (setq cc (and include-cc (message-fetch-field "Cc")))
3031 (concat (message-fetch-field "To") "," cc)
3032 (message-fetch-field "To"))))
3033 (message-goto-mail-followup-to)
3034 (insert (concat tos ", " user-mail-address))))
3038 (defun message-insert-to (&optional force)
3039 "Insert a To header that points to the author of the article being replied to.
3040 If the original author requested not to be sent mail, don't insert unless the
3041 prefix FORCE is given."
3043 (let* ((mct (message-fetch-reply-field "mail-copies-to"))
3044 (dont (and mct (or (equal (downcase mct) "never")
3045 (equal (downcase mct) "nobody"))))
3046 (to (or (message-fetch-reply-field "mail-reply-to")
3047 (message-fetch-reply-field "reply-to")
3048 (message-fetch-reply-field "from"))))
3052 "Ignoring the user request not to have copies sent via mail"
3053 "Complying with the user request not to have copies sent via mail")))
3054 (when (and force (not to))
3055 (error "No mail address in the article"))
3056 (when (and to (or force (not dont)))
3057 (message-carefully-insert-headers (list (cons 'To to))))))
3059 (defun message-insert-wide-reply ()
3060 "Insert To and Cc headers as if you were doing a wide reply."
3062 (let ((headers (message-with-reply-buffer
3063 (message-get-reply-headers t))))
3064 (message-carefully-insert-headers headers)))
3066 (defcustom message-header-synonyms
3069 "List of lists of header synonyms.
3070 E.g., if this list contains a member list with elements `Cc' and `To',
3071 then `message-carefully-insert-headers' will not insert a `To' header
3072 when the message is already `Cc'ed to the recipient."
3074 :group 'message-headers
3075 :link '(custom-manual "(message)Message Headers")
3076 :type '(repeat sexp))
3078 (defun message-carefully-insert-headers (headers)
3079 "Insert the HEADERS, an alist, into the message buffer.
3080 Does not insert the headers when they are already present there
3081 or in the synonym headers, defined by `message-header-synonyms'."
3082 ;; FIXME: Should compare only the address and not the full name. Comparison
3083 ;; should be done case-folded (and with `string=' rather than
3085 ;; (mail-strip-quoted-names "Foo Bar <foo@bar>, bla@fasel (Bla Fasel)")
3086 (dolist (header headers)
3087 (let* ((header-name (symbol-name (car header)))
3088 (new-header (cdr header))
3089 (synonyms (loop for synonym in message-header-synonyms
3090 when (memq (car header) synonym) return synonym))
3092 (loop for synonym in synonyms
3093 for old-header = (mail-fetch-field (symbol-name synonym))
3094 when (and old-header (string-match new-header old-header))
3097 (message "already have `%s' in `%s'" new-header old-header)
3098 (when (and (message-position-on-field header-name)
3099 (setq old-header (mail-fetch-field header-name))
3100 (not (string-match "\\` *\\'" old-header)))
3102 (insert new-header)))))
3104 (defun message-widen-reply ()
3105 "Widen the reply to include maximum recipients."
3108 (and message-reply-buffer
3109 (buffer-name message-reply-buffer)
3110 (with-current-buffer message-reply-buffer
3111 (message-get-reply-headers t)))))
3114 (message-narrow-to-headers)
3115 (dolist (elem follow-to)
3116 (message-remove-header (symbol-name (car elem)))
3117 (goto-char (point-min))
3118 (insert (symbol-name (car elem)) ": "
3119 (cdr elem) "\n"))))))
3121 (defun message-insert-newsgroups ()
3122 "Insert the Newsgroups header from the article being replied to."
3124 (when (and (message-position-on-field "Newsgroups")
3125 (mail-fetch-field "newsgroups")
3126 (not (string-match "\\` *\\'" (mail-fetch-field "newsgroups"))))
3128 (insert (or (message-fetch-reply-field "newsgroups") "")))
3132 ;;; Various commands
3134 (defun message-delete-not-region (beg end)
3135 "Delete everything in the body of the current message outside of the region."
3140 ;; snarf citation prefix, if appropriate
3141 (unless (eq (point) (progn (beginning-of-line) (point)))
3142 (when (looking-at message-cite-prefix-regexp)
3143 (setq citeprefix (match-string 0))))
3145 (delete-region (point) (if (not (message-goto-signature))
3151 (delete-region beg (progn (message-goto-body)
3155 (insert citeprefix))))
3156 (when (message-goto-signature)
3159 (defun message-kill-to-signature (&optional arg)
3160 "Kill all text up to the signature.
3161 If a numberic argument or prefix arg is given, leave that number
3162 of lines before the signature intact."
3166 (let ((point (point)))
3167 (narrow-to-region point (point-max))
3168 (message-goto-signature)
3170 (if (and arg (numberp arg))
3171 (forward-line (- -1 arg))
3173 (unless (= point (point))
3174 (kill-region point (point))
3178 (defun message-newline-and-reformat (&optional arg not-break)
3179 "Insert four newlines, and then reformat if inside quoted text.
3180 Prefix arg means justify as well."
3181 (interactive (list (if current-prefix-arg 'full)))
3182 (let (quoted point beg end leading-space bolp fill-paragraph-function)
3183 (setq point (point))
3186 (setq bolp (= beg point))
3187 ;; Find first line of the paragraph.
3189 (while (and (not (eobp))
3190 (not (looking-at message-cite-prefix-regexp))
3191 (looking-at paragraph-start))
3194 (when (looking-at message-cite-prefix-regexp)
3195 (setq quoted (match-string 0))
3196 (goto-char (match-end 0))
3197 (looking-at "[ \t]*")
3198 (setq leading-space (match-string 0)))
3202 (< (- point beg) (length quoted)))
3203 ;; break inside the cite prefix.
3209 (while (and (not (eobp))
3210 (not (looking-at paragraph-separate))
3211 (looking-at message-cite-prefix-regexp)
3212 (equal quoted (match-string 0)))
3213 (goto-char (match-end 0))
3214 (looking-at "[ \t]*")
3215 (if (> (length leading-space) (length (match-string 0)))
3216 (setq leading-space (match-string 0)))
3220 (while (and (if (bobp) nil (forward-line -1) t)
3221 (not (looking-at paragraph-start))
3222 (looking-at message-cite-prefix-regexp)
3223 (equal quoted (match-string 0)))
3225 (goto-char (match-end 0))
3226 (looking-at "[ \t]*")
3227 (if (> (length leading-space) (length (match-string 0)))
3228 (setq leading-space (match-string 0)))))
3229 (while (and (not (eobp))
3230 (not (looking-at paragraph-separate))
3231 (not (looking-at message-cite-prefix-regexp)))
3235 (while (and (if (bobp) nil (forward-line -1) t)
3236 (not (looking-at paragraph-start))
3237 (not (looking-at message-cite-prefix-regexp)))
3238 (setq beg (point))))
3241 (narrow-to-region beg end)
3248 (setq point (point))
3249 ;; (newline 2) doesn't mark both newline's as hard, so call
3250 ;; newline twice. -jas
3253 (delete-region (point) (re-search-forward "[ \t]*"))
3254 (when (and quoted (not bolp))
3255 (insert quoted leading-space)))
3258 (let* ((adaptive-fill-regexp
3259 (regexp-quote (concat quoted leading-space)))
3260 (adaptive-fill-first-line-regexp
3261 adaptive-fill-regexp ))
3262 (fill-paragraph arg))
3263 (fill-paragraph arg))
3264 (if point (goto-char point)))))
3266 (defun message-fill-paragraph (&optional arg)
3267 "Message specific function to fill a paragraph.
3268 This function is used as the value of `fill-paragraph-function' in
3269 Message buffers and is not meant to be called directly."
3270 (interactive (list (if current-prefix-arg 'full)))
3271 (if (if (boundp 'filladapt-mode) filladapt-mode)
3273 (if (message-point-in-header-p)
3274 (message-fill-field)
3275 (message-newline-and-reformat arg t))
3278 (defun message-point-in-header-p ()
3279 "Return t if point is in the header."
3281 (not (re-search-backward
3282 (concat "^" (regexp-quote mail-header-separator) "\n") nil t))))
3284 (defun message-do-auto-fill ()
3285 "Like `do-auto-fill', but don't fill in message header."
3286 (unless (message-point-in-header-p)
3289 (defun message-insert-signature (&optional force)
3290 "Insert a signature. See documentation for variable `message-signature'."
3291 (interactive (list 0))
3294 ((and (null message-signature)
3297 (goto-char (point-max))
3298 (not (re-search-backward message-signature-separator nil t))))
3299 ((and (null message-signature)
3302 ((functionp message-signature)
3303 (funcall message-signature))
3304 ((listp message-signature)
3305 (eval message-signature))
3306 (t message-signature)))
3309 (cond ((stringp signature)
3311 ((and (eq t signature) message-signature-file)
3312 (setq signature-file
3313 (if (and message-signature-directory
3314 ;; don't actually use the signature directory
3315 ;; if message-signature-file contains a path.
3316 (not (file-name-directory
3317 message-signature-file)))
3318 (nnheader-concat message-signature-directory
3319 message-signature-file)
3320 message-signature-file))
3321 (file-exists-p signature-file))))
3323 (goto-char (point-max))
3324 ;; Insert the signature.
3327 (when message-signature-insert-empty-line
3330 (if (eq signature t)
3331 (insert-file-contents signature-file)
3333 (goto-char (point-max))
3334 (or (bolp) (insert "\n")))))
3336 (defun message-insert-importance-high ()
3337 "Insert header to mark message as important."
3341 (message-narrow-to-headers)
3342 (message-remove-header "Importance"))
3344 (insert "Importance: high\n")))
3346 (defun message-insert-importance-low ()
3347 "Insert header to mark message as unimportant."
3351 (message-narrow-to-headers)
3352 (message-remove-header "Importance"))
3354 (insert "Importance: low\n")))
3356 (defun message-insert-or-toggle-importance ()
3357 "Insert a \"Importance: high\" header, or cycle through the header values.
3358 The three allowed values according to RFC 1327 are `high', `normal'
3365 (message-narrow-to-headers)
3366 (when (setq cur (message-fetch-field "Importance"))
3367 (message-remove-header "Importance")
3368 (setq new (cond ((string= cur "high")
3370 ((string= cur "low")
3375 (insert (format "Importance: %s\n" new)))))
3377 (defun message-insert-disposition-notification-to ()
3378 "Request a disposition notification (return receipt) to this message.
3379 Note that this should not be used in newsgroups."
3383 (message-narrow-to-headers)
3384 (message-remove-header "Disposition-Notification-To"))
3386 (insert (format "Disposition-Notification-To: %s\n"
3387 (or (message-field-value "Reply-to")
3388 (message-field-value "From")
3389 (message-make-from))))))
3391 (defun message-elide-region (b e)
3392 "Elide the text in the region.
3393 An ellipsis (from `message-elide-ellipsis') will be inserted where the
3397 (insert message-elide-ellipsis))
3399 (defvar message-caesar-translation-table nil)
3401 (defun message-caesar-region (b e &optional n)
3402 "Caesar rotate region B to E by N, default 13, for decrypting netnews."
3405 (min (point) (or (mark t) (point)))
3406 (max (point) (or (mark t) (point)))
3407 (when current-prefix-arg
3408 (prefix-numeric-value current-prefix-arg))))
3410 (setq n (if (numberp n) (mod n 26) 13)) ;canonize N
3411 (unless (or (zerop n) ; no action needed for a rot of 0
3412 (= b e)) ; no region to rotate
3413 ;; We build the table, if necessary.
3414 (when (or (not message-caesar-translation-table)
3415 (/= (aref message-caesar-translation-table ?a) (+ ?a n)))
3416 (setq message-caesar-translation-table
3417 (message-make-caesar-translation-table n)))
3418 (translate-region b e message-caesar-translation-table)))
3420 (defun message-make-caesar-translation-table (n)
3421 "Create a rot table with offset N."
3423 (table (make-string 256 0)))
3424 (while (< (incf i) 256)
3427 (substring table 0 ?A)
3428 (substring table (+ ?A n) (+ ?A n (- 26 n)))
3429 (substring table ?A (+ ?A n))
3430 (substring table (+ ?A 26) ?a)
3431 (substring table (+ ?a n) (+ ?a n (- 26 n)))
3432 (substring table ?a (+ ?a n))
3433 (substring table (+ ?a 26) 255))))
3435 (defun message-caesar-buffer-body (&optional rotnum wide)
3436 "Caesar rotate all letters in the current buffer by 13 places.
3437 Used to encode/decode possibly offensive messages (commonly in rec.humor).
3438 With prefix arg, specifies the number of places to rotate each letter forward.
3439 Mail and USENET news headers are not rotated unless WIDE is non-nil."
3440 (interactive (if current-prefix-arg
3441 (list (prefix-numeric-value current-prefix-arg))
3445 (when (and (not wide) (message-goto-body))
3446 (narrow-to-region (point) (point-max)))
3447 (message-caesar-region (point-min) (point-max) rotnum))))
3449 (defun message-pipe-buffer-body (program)
3450 "Pipe the message body in the current buffer through PROGRAM."
3453 (when (message-goto-body)
3454 (narrow-to-region (point) (point-max)))
3455 (shell-command-on-region
3456 (point-min) (point-max) program nil t))))
3458 (defun message-rename-buffer (&optional enter-string)
3459 "Rename the *message* buffer to \"*message* RECIPIENT\".
3460 If the function is run with a prefix, it will ask for a new buffer
3461 name, rather than giving an automatic name."
3462 (interactive "Pbuffer name: ")
3465 (goto-char (point-min))
3466 (narrow-to-region (point)
3467 (search-forward mail-header-separator nil 'end))
3469 (if (message-news-p) (message-fetch-field "Newsgroups")
3470 (message-fetch-field "To"))
3473 (if (string-match "," mail-to)
3474 (concat (substring mail-to 0 (match-beginning 0)) ", ...")
3476 (name-default (concat "*message* " mail-trimmed-to))
3477 (name (if enter-string
3478 (read-string "New buffer name: " name-default)
3480 (rename-buffer name t)))))
3482 (defun message-fill-yanked-message (&optional justifyp)
3483 "Fill the paragraphs of a message yanked into this one.
3484 Numeric argument means justify as well."
3487 (goto-char (point-min))
3488 (search-forward (concat "\n" mail-header-separator "\n") nil t)
3489 (let ((fill-prefix message-yank-prefix))
3490 (fill-individual-paragraphs (point) (point-max) justifyp))))
3492 (defun message-indent-citation (&optional start end yank-only)
3493 "Modify text just inserted from a message to be cited.
3494 The inserted text should be the region.
3495 When this function returns, the region is again around the modified text.
3497 Normally, indent each nonblank line `message-indentation-spaces' spaces.
3498 However, if `message-yank-prefix' is non-nil, insert that prefix on each line."
3499 (unless start (setq start (point)))
3501 ;; Remove unwanted headers.
3502 (when message-ignored-cited-headers
3507 (if (search-forward "\n\n" nil t)
3510 (message-remove-header message-ignored-cited-headers t)
3511 (when (= (point-min) (point-max))
3512 (setq all-removed t))
3513 (goto-char (point-max)))
3517 ;; Delete blank lines at the start of the buffer.
3518 (while (and (point-min)
3521 (message-delete-line))
3522 ;; Delete blank lines at the end of the buffer.
3523 (goto-char (point-max))
3526 (while (and (zerop (forward-line -1))
3528 (message-delete-line)))
3529 ;; Do the indentation.
3530 (if (null message-yank-prefix)
3531 (indent-rigidly start (or end (mark t)) message-indentation-spaces)
3534 (while (< (point) (or end (mark t)))
3535 (cond ((looking-at ">")
3536 (insert message-yank-cited-prefix))
3538 (insert message-yank-empty-prefix))
3540 (insert message-yank-prefix)))
3544 (defun message-remove-blank-cited-lines (&optional remove)
3545 "Remove cited lines containing only blanks.
3546 If REMOVE is non-nil, remove newlines, too.
3548 To use this automatically, you may add this function to
3549 `gnus-message-setup-hook'."
3554 (when (boundp 'message-yank-cited-prefix)
3555 (concat message-yank-cited-prefix "\\|"))
3559 (gnus-message 8 "removing `%s'" citexp)
3562 (while (re-search-forward citexp nil t)
3563 (replace-match (if remove "" "\n"))))))
3565 (defvar message-cite-reply-above nil
3566 "If non-nil, start own text above the quote.
3568 Note: Top posting is bad netiquette. Don't use it unless you
3569 really must. You probably want to set variable only for specific
3570 groups, e.g. using `gnus-posting-styles':
3572 (eval (set (make-local-variable 'message-cite-reply-above) t))
3574 This variable has no effect in news postings.")
3576 (defun message-yank-original (&optional arg)
3577 "Insert the message being replied to, if any.
3578 Puts point before the text and mark after.
3579 Normally indents each nonblank line ARG spaces (default 3). However,
3580 if `message-yank-prefix' is non-nil, insert that prefix on each line.
3582 This function uses `message-cite-function' to do the actual citing.
3584 Just \\[universal-argument] as argument means don't indent, insert no
3585 prefix, and don't delete any headers."
3587 (let ((modified (buffer-modified-p))
3589 (when (and message-reply-buffer
3590 message-cite-function)
3591 (when message-cite-reply-above
3592 (if (and (not (message-news-p))
3593 (or (eq message-cite-reply-above 'is-evil)
3595 Top posting is bad netiquette. Please don't top post unless you really must.
3596 Really top post? ")))
3599 (buffer-substring (message-goto-body)
3601 (delete-region (message-goto-body) (point-max)))
3602 (set (make-local-variable 'message-cite-reply-above) nil)))
3603 (delete-windows-on message-reply-buffer t)
3604 (push-mark (save-excursion
3605 (insert-buffer-substring message-reply-buffer)
3610 (funcall message-cite-function)
3611 (unless (eq (char-before (mark t)) ?\n)
3613 (goto-char (mark t))
3614 (insert-before-markers ?\n)
3616 (when message-cite-reply-above
3619 (insert (if (bolp) "\n" "\n\n"))
3620 (message-goto-body))
3621 ;; Add a `message-setup-very-last-hook' here?
3622 ;; Add `gnus-article-highlight-citation' here?
3624 (setq message-checksum (message-checksum))))))
3626 (defun message-yank-buffer (buffer)
3627 "Insert BUFFER into the current buffer and quote it."
3628 (interactive "bYank buffer: ")
3629 (let ((message-reply-buffer (get-buffer buffer)))
3630 (save-window-excursion
3631 (message-yank-original))))
3633 (defun message-buffers ()
3634 "Return a list of active message buffers."
3636 (save-current-buffer
3637 (dolist (buffer (buffer-list t))
3639 (when (and (eq major-mode 'message-mode)
3640 (null message-sent-message-via))
3641 (push (buffer-name buffer) buffers))))
3642 (nreverse buffers)))
3644 (defun message-cite-original-1 (strip-signature)
3645 "Cite an original message.
3646 If STRIP-SIGNATURE is non-nil, strips off the signature from the
3649 This function uses `mail-citation-hook' if that is non-nil."
3650 (if (and (boundp 'mail-citation-hook)
3652 (run-hooks 'mail-citation-hook)
3653 (let* ((start (point))
3657 (when message-indent-citation-function
3658 (if (listp message-indent-citation-function)
3659 message-indent-citation-function
3660 (list message-indent-citation-function))))
3661 ;; This function may be called by `gnus-summary-yank-message' and
3662 ;; may insert a different article from the original. So, we will
3663 ;; modify the value of `message-reply-headers' with that article.
3664 (message-reply-headers
3666 (narrow-to-region start end)
3667 (message-narrow-to-head-1)
3668 (setq x-no-archive (message-fetch-field "x-no-archive"))
3670 (or (message-fetch-field "subject") "none")
3671 (or (message-fetch-field "from") "nobody")
3672 (message-fetch-field "date")
3673 (message-fetch-field "message-id" t)
3674 (message-fetch-field "references")
3676 (mml-quote-region start end)
3677 (when strip-signature
3681 (when (re-search-backward message-signature-separator start t)
3682 ;; Also peel off any blank lines before the signature.
3684 (while (looking-at "^[ \t]*$")
3687 (delete-region (point) end)
3688 (unless (search-backward "\n\n" start t)
3689 ;; Insert a blank line if it is peeled off.
3692 (mapc 'funcall functions)
3693 (when message-citation-line-function
3696 (funcall message-citation-line-function))
3697 (when (and x-no-archive
3698 (not message-cite-articles-with-x-no-archive)
3699 (string-match "yes" x-no-archive))
3701 (delete-region (point) (mark t))
3702 (insert "> [Quoted text removed due to X-No-Archive]\n")
3704 (forward-line -1)))))
3706 (defun message-cite-original ()
3707 "Cite function in the standard Message manner."
3708 (message-cite-original-1 nil))
3710 (defvar gnus-extract-address-components)
3712 (autoload 'format-spec "format-spec")
3714 (defun message-insert-formatted-citation-line (&optional from date)
3715 "Function that inserts a formatted citation line.
3717 See `message-citation-line-format'."
3718 ;; The optional args are for testing/debugging. They will disappear later.
3720 ;; (with-temp-buffer
3721 ;; (message-insert-formatted-citation-line
3722 ;; "John Doe <john.doe@example.invalid>"
3725 (when (or message-reply-headers (and from date))
3727 (setq from (mail-header-from message-reply-headers)))
3728 (let* ((data (condition-case ()
3729 (funcall (if (boundp gnus-extract-address-components)
3730 gnus-extract-address-components
3731 'mail-extract-address-components)
3737 (net (car (cdr data)))
3738 (name-or-net (or (car data)
3739 (car (cdr data)) from))
3743 ;; We need Gnus functionality if the user wants date or time from
3744 ;; the original article:
3745 (when (string-match "%[^fnNFL]" message-citation-line-format)
3746 (autoload 'gnus-date-get-time "gnus-util")
3747 (gnus-date-get-time (mail-header-date message-reply-headers)))))
3750 (when (stringp name)
3751 ;; Guess first name and last name:
3752 (cond ((string-match
3753 "\\`\\(\\w\\|[-.]\\)+ \\(\\w\\|[-.]\\)+\\'" name)
3754 (setq fname (nth 0 (split-string name "[ \t]+"))
3755 lname (nth 1 (split-string name "[ \t]+"))))
3757 "\\`\\(\\w\\|[-.]\\)+, \\(\\w\\|[-.]\\)+\\'" name)
3758 (setq fname (nth 1 (split-string name "[ \t,]+"))
3759 lname (nth 0 (split-string name "[ \t,]+"))))
3761 "\\`\\(\\w\\|[-.]\\)+\\'" name)
3764 ;; The following letters are not used in `format-time-string':
3765 (push ?E lst) (push "<E>" lst)
3766 (push ?F lst) (push fname lst)
3767 ;; We might want to use "" instead of "<X>" later.
3768 (push ?J lst) (push "<J>" lst)
3769 (push ?K lst) (push "<K>" lst)
3770 (push ?L lst) (push lname lst)
3771 (push ?N lst) (push name-or-net lst)
3772 (push ?O lst) (push "<O>" lst)
3773 (push ?P lst) (push "<P>" lst)
3774 (push ?Q lst) (push "<Q>" lst)
3775 (push ?f lst) (push from lst)
3776 (push ?i lst) (push "<i>" lst)
3777 (push ?n lst) (push net lst)
3778 (push ?o lst) (push "<o>" lst)
3779 (push ?q lst) (push "<q>" lst)
3780 (push ?t lst) (push "<t>" lst)
3781 (push ?v lst) (push "<v>" lst)
3782 ;; Delegate the rest to `format-time-string':
3784 (when (and (not (memq i lst))
3789 (push (condition-case nil
3790 (progn (format-time-string (format "%%%c" i)
3796 (spec (apply 'format-spec-make flist)))
3797 (insert (format-spec message-citation-line-format spec)))
3800 (defun message-cite-original-without-signature ()
3801 "Cite function in the standard Message manner.
3802 This function strips off the signature from the original message."
3803 (message-cite-original-1 t))
3805 (defun message-insert-citation-line ()
3806 "Insert a simple citation line."
3807 (when message-reply-headers
3808 (insert (mail-header-from message-reply-headers) " writes:")
3812 (defun message-position-on-field (header &rest afters)
3813 (let ((case-fold-search t))
3816 (goto-char (point-min))
3819 (concat "^" (regexp-quote mail-header-separator) "$"))
3820 (match-beginning 0)))
3821 (goto-char (point-min))
3822 (if (re-search-forward (concat "^" (regexp-quote header) ":") nil t)
3824 (re-search-forward "^[^ \t]" nil 'move)
3826 (skip-chars-backward "\n")
3829 (not (re-search-forward
3830 (concat "^" (regexp-quote (car afters)) ":")
3834 (re-search-forward "^[^ \t]" nil 'move)
3835 (beginning-of-line))
3836 (insert header ": \n")
3840 (defun message-remove-signature ()
3841 "Remove the signature from the text between point and mark.
3842 The text will also be indented the normal way."
3844 (let ((start (point))
3846 (if (not (re-search-forward message-signature-separator (mark t) t))
3847 ;; No signature here, so we just indent the cited text.
3848 (message-indent-citation)
3849 ;; Find the last non-empty line.
3851 (while (looking-at "[ \t]*$")
3854 (setq mark (set-marker (make-marker) (point)))
3856 (message-indent-citation)
3857 ;; Enable undoing the deletion.
3859 (delete-region mark (mark t))
3860 (set-marker mark nil)))))
3865 ;;; Sending messages
3868 (defun message-send-and-exit (&optional arg)
3869 "Send message like `message-send', then, if no errors, exit from mail buffer."
3871 (let ((buf (current-buffer))
3872 (actions message-exit-actions))
3873 (when (and (message-send arg)
3875 (if message-kill-buffer-on-exit
3878 (when (eq buf (current-buffer))
3879 (message-bury buf)))
3880 (message-do-actions actions)
3883 (defun message-dont-send ()
3884 "Don't send the message you have been editing.
3885 Instead, just auto-save the buffer and then bury it."
3887 (set-buffer-modified-p t)
3889 (let ((actions message-postpone-actions))
3890 (message-bury (current-buffer))
3891 (message-do-actions actions)))
3893 (defun message-kill-buffer ()
3894 "Kill the current buffer."
3896 (when (or (not (buffer-modified-p))
3897 (not message-kill-buffer-query)
3898 (yes-or-no-p "Message modified; kill anyway? "))
3899 (let ((actions message-kill-actions)
3900 (draft-article message-draft-article)
3901 (auto-save-file-name buffer-auto-save-file-name)
3902 (file-name buffer-file-name)
3903 (modified (buffer-modified-p)))
3904 (setq buffer-file-name nil)
3905 (kill-buffer (current-buffer))
3906 (when (and (or (and auto-save-file-name
3907 (file-exists-p auto-save-file-name))
3909 (file-exists-p file-name)))
3911 ;; If the message buffer has lived in a dedicated window,
3912 ;; `kill-buffer' has killed the frame. Thus the
3913 ;; `yes-or-no-p' may show up in a lowered frame. Make sure
3914 ;; that the user can see the question by raising the
3917 (yes-or-no-p (format "Remove the backup file%s? "
3918 (if modified " too" "")))))
3920 (delete-file auto-save-file-name))
3921 (let ((message-draft-article draft-article))
3922 (message-disassociate-draft)))
3923 (message-do-actions actions))))
3925 (defun message-bury (buffer)
3926 "Bury this mail BUFFER."
3927 (let ((newbuf (other-buffer buffer)))
3928 (bury-buffer buffer)
3929 (if (and (window-dedicated-p (selected-window))
3930 (not (null (delq (selected-frame) (visible-frame-list)))))
3931 (delete-frame (selected-frame))
3932 (switch-to-buffer newbuf))))
3934 (defun message-send (&optional arg)
3935 "Send the message in the current buffer.
3936 If `message-interactive' is non-nil, wait for success indication or
3937 error messages, and inform user.
3938 Otherwise any failure is reported in a message back to the user from
3940 The usage of ARG is defined by the instance that called Message.
3941 It should typically alter the sending method in some way or other."
3943 ;; Make it possible to undo the coming changes.
3945 (let ((inhibit-read-only t))
3946 (put-text-property (point-min) (point-max) 'read-only nil))
3947 (message-fix-before-sending)
3948 (run-hooks 'message-send-hook)
3949 (message message-sending-message)
3950 (let ((alist message-send-method-alist)
3952 elem sent dont-barf-on-no-method
3953 (message-options message-options))
3954 (message-options-set-recipient)
3956 (setq elem (pop alist)))
3957 (when (funcall (cadr elem))
3958 (when (and (or (not (memq (car elem)
3959 message-sent-message-via))
3960 (message-fetch-field "supersedes")
3961 (if (or (message-gnksa-enable-p 'multiple-copies)
3962 (not (eq (car elem) 'news)))
3965 "Already sent message via %s; resend? "
3967 (error "Denied posting -- multiple copies")))
3968 (setq success (funcall (caddr elem) arg)))
3972 (let ((fcc (message-fetch-field "Fcc"))
3973 (gcc (message-fetch-field "Gcc")))
3975 (or (eq message-allow-no-recipients 'always)
3976 (and (not (eq message-allow-no-recipients 'never))
3977 (setq dont-barf-on-no-method
3979 (format "No receiver, perform %s anyway? "
3980 (cond ((and fcc gcc) "Fcc and Gcc")
3983 (error "No methods specified to send by"))
3984 (when (or dont-barf-on-no-method
3988 (run-hooks 'message-sent-hook))
3989 (message "Sending...done")
3990 ;; Do ecomplete address snarfing.
3991 (when (message-mail-alias-type-p 'ecomplete)
3992 (message-put-addresses-in-ecomplete))
3993 ;; Mark the buffer as unmodified and delete auto-save.
3994 (set-buffer-modified-p nil)
3995 (delete-auto-save-file-if-necessary t)
3996 (message-disassociate-draft)
3997 ;; Delete other mail buffers and stuff.
3998 (message-do-send-housekeeping)
3999 (message-do-actions message-send-actions)
4003 (defun message-send-via-mail (arg)
4004 "Send the current message via mail."
4005 (message-send-mail arg))
4007 (defun message-send-via-news (arg)
4008 "Send the current message via news."
4009 (funcall message-send-news-function arg))
4011 (defmacro message-check (type &rest forms)
4012 "Eval FORMS if TYPE is to be checked."
4013 `(or (message-check-element ,type)
4017 (put 'message-check 'lisp-indent-function 1)
4018 (put 'message-check 'edebug-form-spec '(form body))
4020 (defun message-text-with-property (prop &optional start end reverse)
4021 "Return a list of start and end positions where the text has PROP.
4022 START and END bound the search, they default to `point-min' and
4023 `point-max' respectively. If REVERSE is non-nil, find text which does
4026 (setq start (point-min)))
4028 (setq end (point-max)))
4032 (setq start (text-property-any start end prop nil)))
4033 (setq next (next-single-property-change start prop nil end))
4034 (push (cons start (or next end)) regions)
4037 (or (get-text-property start prop)
4038 (and (setq start (next-single-property-change
4039 start prop nil end))
4040 (get-text-property start prop))))
4041 (setq next (text-property-any start end prop nil))
4042 (push (cons start (or next end)) regions)
4044 (nreverse regions)))
4046 (defcustom message-bogus-address-regexp nil ;; "noreply\\|nospam\\|invalid"
4047 "Regexp of potentially bogus mail addresses."
4048 :version "23.1" ;; No Gnus
4049 :group 'message-headers
4052 (defun message-fix-before-sending ()
4053 "Do various things to make the message nice before sending it."
4054 ;; Make sure there's a newline at the end of the message.
4055 (goto-char (point-max))
4058 ;; Make the hidden headers visible.
4060 ;; Sort headers before sending the message.
4061 (message-sort-headers)
4062 ;; Make invisible text visible.
4063 ;; It doesn't seem as if this is useful, since the invisible property
4064 ;; is clobbered by an after-change hook anyhow.
4065 (message-check 'invisible-text
4066 (let ((regions (message-text-with-property 'invisible))
4070 (setq from (caar regions)
4072 regions (cdr regions))
4073 (put-text-property from to 'invisible nil)
4074 (message-overlay-put (message-make-overlay from to)
4076 (unless (yes-or-no-p
4077 "Invisible text found and made visible; continue sending? ")
4078 (error "Invisible text found and made visible")))))
4079 (message-check 'illegible-text
4080 (let (char found choice)
4083 (skip-chars-forward mm-7bit-chars)
4084 (when (get-text-property (point) 'no-illegible-text)
4085 ;; There is a signed or encrypted raw message part
4086 ;; that is considered to be safe.
4087 (goto-char (or (next-single-property-change
4088 (point) 'no-illegible-text)
4090 (setq char (char-after)))
4091 (when (or (< (mm-char-int char) 128)
4092 (and (mm-multibyte-p)
4093 (memq (char-charset char)
4094 '(eight-bit-control eight-bit-graphic
4096 (not (get-text-property
4097 (point) 'untranslated-utf-8))))
4098 (message-overlay-put (message-make-overlay (point) (1+ (point)))
4104 (gnus-multiple-choice
4105 "Non-printable characters found. Continue sending?"
4106 `((?d "Remove non-printable characters and send")
4108 "Replace non-printable characters with \"%s\" and send"
4109 message-replacement-char))
4110 (?i "Ignore non-printable characters and send")
4111 (?e "Continue editing"))))
4113 (error "Non-printable characters"))
4115 (skip-chars-forward mm-7bit-chars)
4117 (when (let ((char (char-after)))
4118 (or (< (mm-char-int char) 128)
4119 (and (mm-multibyte-p)
4120 ;; FIXME: Wrong for Emacs 23 (unicode) and for
4121 ;; things like undecable utf-8. Should at least
4122 ;; use find-coding-systems-region.
4123 (memq (char-charset char)
4124 '(eight-bit-control eight-bit-graphic
4126 (not (get-text-property
4127 (point) 'untranslated-utf-8)))))
4129 (message-kill-all-overlays)
4131 (when (eq choice ?r)
4132 (insert message-replacement-char))))
4134 (skip-chars-forward mm-7bit-chars)))))
4135 (message-check 'bogus-recipient
4136 ;; Warn before composing or sending a mail to an invalid address.
4137 (message-check-recipients)))
4139 (defun message-bogus-recipient-p (recipients)
4140 "Check if a mail address in RECIPIENTS looks bogus.
4142 RECIPIENTS is a mail header. Return a list of potentially bogus
4143 addresses. If none is found, return nil.
4145 An addresses might be bogus if the domain part is not fully
4146 qualified, see `message-valid-fqdn-regexp', or if it matches
4147 `message-bogus-address-regexp'."
4148 ;; FIXME: How about "foo@subdomain", when the MTA adds ".domain.tld"?
4150 (mapc (lambda (address)
4151 (setq address (cadr address))
4155 (not (string-match "@" address))
4158 message-valid-fqdn-regexp "\\)\\'") address)))
4159 (and (stringp message-bogus-address-regexp)
4160 (string-match message-bogus-address-regexp address)))
4161 (push address found)))
4163 (mail-extract-address-components recipients t))
4166 (defun message-check-recipients ()
4167 "Warn before composing or sending a mail to an invalid address.
4169 This function could be useful in `message-setup-hook'."
4172 (message-narrow-to-headers)
4173 (dolist (hdr '("To" "Cc" "Bcc"))
4174 (let ((addr (message-fetch-field hdr)))
4175 (when (stringp addr)
4176 (dolist (bog (message-bogus-recipient-p addr))
4180 "Address `%s' might be bogus. Continue? " bog)))
4181 (error "Bogus address."))))))))
4183 (defun message-add-action (action &rest types)
4184 "Add ACTION to be performed when doing an exit of type TYPES."
4186 (add-to-list (intern (format "message-%s-actions" (pop types)))
4189 (defun message-delete-action (action &rest types)
4190 "Delete ACTION from lists of actions performed when doing an exit of type TYPES."
4193 (set (setq var (intern (format "message-%s-actions" (pop types))))
4194 (delq action (symbol-value var))))))
4196 (defun message-do-actions (actions)
4197 "Perform all actions in ACTIONS."
4198 ;; Now perform actions on successful sending.
4199 (dolist (action actions)
4202 ;; A simple function.
4205 ;; Something to be evaled.
4209 (defun message-send-mail-partially ()
4210 "Send mail as message/partial."
4211 ;; replace the header delimiter with a blank line
4212 (goto-char (point-min))
4214 (concat "^" (regexp-quote mail-header-separator) "\n"))
4215 (replace-match "\n")
4216 (run-hooks 'message-send-mail-hook)
4217 (let ((p (goto-char (point-min)))
4218 (tembuf (message-generate-new-buffer-clone-locals " message temp"))
4219 (curbuf (current-buffer))
4220 (id (message-make-message-id)) (n 1)
4221 plist total header required-mail-headers)
4223 (if (< (point-max) (+ p message-send-mail-partially-limit))
4224 (goto-char (point-max))
4225 (goto-char (+ p message-send-mail-partially-limit))
4227 (if (<= (point) p) (forward-line 1))) ;; In case of bad message.
4230 (setq total (length plist))
4231 (push (point-max) plist)
4232 (setq plist (nreverse plist))
4235 (setq p (pop plist))
4238 (copy-to-buffer tembuf p (car plist))
4240 (goto-char (point-min))
4243 (goto-char (point-min))
4244 (narrow-to-region (point) (point))
4247 (setq header (buffer-substring (point-min) (point)))
4248 (goto-char (point-min))
4249 (narrow-to-region (point) (point))
4251 (message-remove-header "Mime-Version")
4252 (message-remove-header "Content-Type")
4253 (message-remove-header "Content-Transfer-Encoding")
4254 (message-remove-header "Message-ID")
4255 (message-remove-header "Lines")
4256 (goto-char (point-max))
4257 (insert "Mime-Version: 1.0\n")
4258 (setq header (buffer-string)))
4259 (goto-char (point-max))
4260 (insert (format "Content-Type: message/partial; id=\"%s\"; number=%d; total=%d\n\n"
4263 (let ((mail-header-separator ""))
4264 (when (memq 'Message-ID message-required-mail-headers)
4265 (insert "Message-ID: " (message-make-message-id) "\n"))
4266 (when (memq 'Lines message-required-mail-headers)
4267 (insert "Lines: " (message-make-lines) "\n"))
4268 (message-goto-subject)
4270 (insert (format " (%d/%d)" n total))
4272 (mm-with-unibyte-current-buffer
4273 (funcall (or message-send-mail-real-function
4274 message-send-mail-function))))
4276 (setq p (pop plist))
4278 (kill-buffer tembuf))))
4280 (defun message-send-mail (&optional arg)
4281 (require 'mail-utils)
4282 (let* ((tembuf (message-generate-new-buffer-clone-locals " message temp"))
4283 (case-fold-search nil)
4284 (news (message-news-p))
4285 (mailbuf (current-buffer))
4286 (message-this-is-mail t)
4287 (message-posting-charset
4288 (if (fboundp 'gnus-setup-posting-charset)
4289 (gnus-setup-posting-charset nil)
4290 message-posting-charset))
4291 (headers message-required-mail-headers))
4292 (when (and message-generate-hashcash
4293 (not (eq message-generate-hashcash 'opportunistic)))
4294 (message "Generating hashcash...")
4295 ;; Wait for calculations already started to finish...
4296 (hashcash-wait-async)
4297 ;; ...and do calculations not already done. mail-add-payment
4298 ;; will leave existing X-Hashcash headers alone.
4300 (message "Generating hashcash...done"))
4302 (message-narrow-to-headers)
4303 ;; Generate the Mail-Followup-To header if the header is not there...
4304 (if (and (message-subscribed-p)
4305 (not (mail-fetch-field "mail-followup-to")))
4308 (cons "Mail-Followup-To" (message-make-mail-followup-to))
4309 message-required-mail-headers))
4310 ;; otherwise, delete the MFT header if the field is empty
4311 (when (equal "" (mail-fetch-field "mail-followup-to"))
4312 (message-remove-header "^Mail-Followup-To:")))
4313 ;; Insert some headers.
4314 (let ((message-deletable-headers
4315 (if news nil message-deletable-headers)))
4316 (message-generate-headers headers))
4317 ;; Check continuation headers.
4318 (message-check 'continuation-headers
4319 (goto-char (point-min))
4320 (while (re-search-forward "^[^ \t\n][^ \t\n:]*[ \t\n]" nil t)
4321 (goto-char (match-beginning 0))
4322 (if (y-or-n-p "Fix continuation lines? ")
4325 (unless (y-or-n-p "Send anyway? ")
4326 (error "Failed to send the message")))))
4327 ;; Let the user do all of the above.
4328 (run-hooks 'message-header-hook))
4330 (with-current-buffer tembuf
4332 ;; Avoid copying text props (except hard newlines).
4333 (insert (with-current-buffer mailbuf
4334 (mml-buffer-substring-no-properties-except-hard-newlines
4335 (point-min) (point-max))))
4336 ;; Remove some headers.
4337 (message-encode-message-body)
4339 (message-narrow-to-headers)
4340 ;; We (re)generate the Lines header.
4341 (when (memq 'Lines message-required-mail-headers)
4342 (message-generate-headers '(Lines)))
4343 ;; Remove some headers.
4344 (message-remove-header message-ignored-mail-headers t)
4345 (let ((mail-parse-charset message-default-charset))
4346 (mail-encode-encoded-word-buffer)))
4347 (goto-char (point-max))
4348 ;; require one newline at the end.
4349 (or (= (preceding-char) ?\n)
4351 (message-cleanup-headers)
4352 ;; FIXME: we're inserting the courtesy copy after encoding.
4353 ;; This is wrong if the courtesy copy string contains
4354 ;; non-ASCII characters. -- jh
4357 (message-narrow-to-headers)
4359 (or (message-fetch-field "cc")
4360 (message-fetch-field "bcc")
4361 (message-fetch-field "to"))
4362 (let ((content-type (message-fetch-field
4367 (string= "text/plain"
4369 (mail-header-parse-content-type
4373 (message-fetch-field
4374 "content-transfer-encoding")))))))
4375 (message-insert-courtesy-copy))
4376 (if (or (not message-send-mail-partially-limit)
4377 (< (buffer-size) message-send-mail-partially-limit)
4378 (not (message-y-or-n-p
4379 "The message size is too large, split? "
4383 (/ (buffer-size) 1000) "KB, is too large.
4385 Some mail gateways (MTA's) bounce large messages. To avoid the
4386 problem, answer `y', and the message will be split into several
4387 smaller pieces, the size of each is about "
4388 (/ message-send-mail-partially-limit 1000)
4392 However, some mail readers (MUA's) can't read split messages, i.e.,
4393 mails in message/partially format. Answer `n', and the message will be
4396 The size limit is controlled by `message-send-mail-partially-limit'.
4397 If you always want Gnus to send messages in one piece, set
4398 `message-send-mail-partially-limit' to nil.
4400 (mm-with-unibyte-current-buffer
4401 (message "Sending via mail...")
4402 (funcall (or message-send-mail-real-function
4403 message-send-mail-function)))
4404 (message-send-mail-partially)))
4405 (kill-buffer tembuf))
4406 (set-buffer mailbuf)
4407 (push 'mail message-sent-message-via)))
4409 (defun message-send-mail-with-sendmail ()
4410 "Send off the prepared buffer with sendmail."
4411 (let ((errbuf (if message-interactive
4412 (message-generate-new-buffer-clone-locals
4415 resend-to-addresses delimline)
4418 (let ((case-fold-search t))
4420 (message-narrow-to-headers)
4421 (setq resend-to-addresses (message-fetch-field "resent-to")))
4422 ;; Change header-delimiter to be what sendmail expects.
4423 (goto-char (point-min))
4425 (concat "^" (regexp-quote mail-header-separator) "\n"))
4426 (replace-match "\n")
4428 (setq delimline (point-marker))
4429 (run-hooks 'message-send-mail-hook)
4430 ;; Insert an extra newline if we need it to work around
4431 ;; Sun's bug that swallows newlines.
4432 (goto-char (1+ delimline))
4433 (when (eval message-mailer-swallows-blank-line)
4435 (when message-interactive
4436 (with-current-buffer errbuf
4438 (let* ((default-directory "/")
4439 (coding-system-for-write message-send-coding-system)
4441 'call-process-region
4443 (list (point-min) (point-max)
4444 (cond ((boundp 'sendmail-program)
4446 ((file-exists-p "/usr/sbin/sendmail")
4447 "/usr/sbin/sendmail")
4448 ((file-exists-p "/usr/lib/sendmail")
4449 "/usr/lib/sendmail")
4450 ((file-exists-p "/usr/ucblib/sendmail")
4451 "/usr/ucblib/sendmail")
4453 nil errbuf nil "-oi")
4454 message-sendmail-extra-arguments
4455 ;; Always specify who from,
4456 ;; since some systems have broken sendmails.
4457 ;; But some systems are more broken with -f, so
4458 ;; we'll let users override this.
4459 (if (null message-sendmail-f-is-evil)
4460 (list "-f" (message-sendmail-envelope-from)))
4461 ;; These mean "report errors by mail"
4462 ;; and "deliver in background".
4463 (if (null message-interactive) '("-oem" "-odb"))
4464 ;; Get the addresses from the message
4465 ;; unless this is a resend.
4466 ;; We must not do that for a resend
4467 ;; because we would find the original addresses.
4468 ;; For a resend, include the specific addresses.
4469 (if resend-to-addresses
4470 (list resend-to-addresses)
4472 (unless (or (null cpr) (and (numberp cpr) (zerop cpr)))
4473 (error "Sending...failed with exit value %d" cpr)))
4474 (when message-interactive
4475 (with-current-buffer errbuf
4476 (goto-char (point-min))
4477 (while (re-search-forward "\n+ *" nil t)
4478 (replace-match "; "))
4479 (if (not (zerop (buffer-size)))
4480 (error "Sending...failed to %s"
4481 (buffer-string))))))
4482 (when (bufferp errbuf)
4483 (kill-buffer errbuf)))))
4485 (defun message-send-mail-with-qmail ()
4486 "Pass the prepared message buffer to qmail-inject.
4487 Refer to the documentation for the variable `message-send-mail-function'
4488 to find out how to use this."
4489 ;; replace the header delimiter with a blank line
4490 (goto-char (point-min))
4492 (concat "^" (regexp-quote mail-header-separator) "\n"))
4493 (replace-match "\n")
4494 (run-hooks 'message-send-mail-hook)
4497 (let ((coding-system-for-write message-send-coding-system))
4499 'call-process-region (point-min) (point-max)
4500 message-qmail-inject-program nil nil nil
4501 ;; qmail-inject's default behaviour is to look for addresses on the
4502 ;; command line; if there're none, it scans the headers.
4503 ;; yes, it does The Right Thing w.r.t. Resent-To and it's kin.
4505 ;; in general, ALL of qmail-inject's defaults are perfect for simply
4506 ;; reading a formatted (i. e., at least a To: or Resent-To header)
4507 ;; message from stdin.
4509 ;; qmail also has the advantage of not having been raped by
4510 ;; various vendors, so we don't have to allow for that, either --
4511 ;; compare this with message-send-mail-with-sendmail and weep
4512 ;; for sendmail's lost innocence.
4514 ;; all this is way cool coz it lets us keep the arguments entirely
4515 ;; free for -inject-arguments -- a big win for the user and for us
4516 ;; since we don't have to play that double-guessing game and the user
4517 ;; gets full control (no gestapo'ish -f's, for instance). --sj
4518 (if (functionp message-qmail-inject-args)
4519 (funcall message-qmail-inject-args)
4520 message-qmail-inject-args)))
4521 ;; qmail-inject doesn't say anything on it's stdout/stderr,
4522 ;; we have to look at the retval instead
4524 (100 (error "qmail-inject reported permanent failure"))
4525 (111 (error "qmail-inject reported transient failure"))
4526 ;; should never happen
4527 (t (error "qmail-inject reported unknown failure"))))
4529 (defun message-send-mail-with-mh ()
4530 "Send the prepared message buffer with mh."
4531 (let ((mh-previous-window-config nil)
4532 (name (mh-new-draft-name)))
4533 (setq buffer-file-name name)
4534 ;; MH wants to generate these headers itself.
4535 (when message-mh-deletable-headers
4536 (let ((headers message-mh-deletable-headers))
4538 (goto-char (point-min))
4539 (and (re-search-forward
4540 (concat "^" (symbol-name (car headers)) ": *") nil t)
4541 (message-delete-line))
4543 (run-hooks 'message-send-mail-hook)
4544 ;; Pass it on to mh.
4547 (defun message-smtpmail-send-it ()
4548 "Send the prepared message buffer with `smtpmail-send-it'.
4549 This only differs from `smtpmail-send-it' that this command evaluates
4550 `message-send-mail-hook' just before sending a message. It is useful
4551 if your ISP requires the POP-before-SMTP authentication. See the Gnus
4552 manual for details."
4553 (run-hooks 'message-send-mail-hook)
4556 (defun message-send-mail-with-mailclient ()
4557 "Send the prepared message buffer with `mailclient-send-it'.
4558 This only differs from `smtpmail-send-it' that this command evaluates
4559 `message-send-mail-hook' just before sending a message."
4560 (run-hooks 'message-send-mail-hook)
4561 (mailclient-send-it))
4563 (defun message-canlock-generate ()
4564 "Return a string that is non-trivial to guess.
4565 Do not use this for anything important, it is cryptographically weak."
4567 (let (sha1-maximum-internal-length)
4568 (sha1 (concat (message-unique-id)
4569 (format "%x%x%x" (random) (random t) (random))
4570 (prin1-to-string (recent-keys))
4571 (prin1-to-string (garbage-collect))))))
4573 (defun message-canlock-password ()
4574 "The password used by message for cancel locks.
4575 This is the value of `canlock-password', if that option is non-nil.
4576 Otherwise, generate and save a value for `canlock-password' first."
4577 (unless canlock-password
4578 (customize-save-variable 'canlock-password (message-canlock-generate))
4579 (setq canlock-password-for-verify canlock-password))
4582 (defun message-insert-canlock ()
4583 (when message-insert-canlock
4584 (message-canlock-password)
4585 (canlock-insert-header)))
4587 (defun message-send-news (&optional arg)
4588 (let* ((tembuf (message-generate-new-buffer-clone-locals " *message temp*"))
4589 (case-fold-search nil)
4590 (method (if (functionp message-post-method)
4591 (funcall message-post-method arg)
4592 message-post-method))
4593 (newsgroups-field (save-restriction
4594 (message-narrow-to-headers-or-head)
4595 (message-fetch-field "Newsgroups")))
4596 (followup-field (save-restriction
4597 (message-narrow-to-headers-or-head)
4598 (message-fetch-field "Followup-To")))
4599 ;; BUG: We really need to get the charset for each name in the
4600 ;; Newsgroups and Followup-To lines to allow crossposting
4601 ;; between group namess with incompatible character sets.
4602 ;; -- Per Abrahamsen <abraham@dina.kvl.dk> 2001-10-08.
4603 (group-field-charset
4604 (gnus-group-name-charset method newsgroups-field))
4605 (followup-field-charset
4606 (gnus-group-name-charset method (or followup-field "")))
4607 (rfc2047-header-encoding-alist
4608 (append (when group-field-charset
4609 (list (cons "Newsgroups" group-field-charset)))
4610 (when followup-field-charset
4611 (list (cons "Followup-To" followup-field-charset)))
4612 rfc2047-header-encoding-alist))
4613 (messbuf (current-buffer))
4614 (message-syntax-checks
4616 (listp message-syntax-checks))
4617 (cons '(existing-newsgroups . disabled)
4618 message-syntax-checks)
4619 message-syntax-checks))
4620 (message-this-is-news t)
4621 (message-posting-charset
4622 (gnus-setup-posting-charset newsgroups-field))
4624 (if (not (message-check-news-body-syntax))
4627 (message-narrow-to-headers)
4628 ;; Insert some headers.
4629 (message-generate-headers message-required-news-headers)
4630 (message-insert-canlock)
4631 ;; Let the user do all of the above.
4632 (run-hooks 'message-header-hook))
4633 ;; Note: This check will be disabled by the ".*" default value for
4634 ;; gnus-group-name-charset-group-alist. -- Pa 2001-10-07.
4635 (when (and group-field-charset
4636 (listp message-syntax-checks))
4637 (setq message-syntax-checks
4638 (cons '(valid-newsgroups . disabled)
4639 message-syntax-checks)))
4640 (message-cleanup-headers)
4641 (if (not (let ((message-post-method method))
4642 (message-check-news-syntax)))
4645 (with-current-buffer tembuf
4646 (buffer-disable-undo)
4648 ;; Avoid copying text props (except hard newlines).
4650 (with-current-buffer messbuf
4651 (mml-buffer-substring-no-properties-except-hard-newlines
4652 (point-min) (point-max))))
4653 (message-encode-message-body)
4654 ;; Remove some headers.
4656 (message-narrow-to-headers)
4657 ;; We (re)generate the Lines header.
4658 (when (memq 'Lines message-required-mail-headers)
4659 (message-generate-headers '(Lines)))
4660 ;; Remove some headers.
4661 (message-remove-header message-ignored-news-headers t)
4662 (let ((mail-parse-charset message-default-charset))
4663 (mail-encode-encoded-word-buffer)))
4664 (goto-char (point-max))
4665 ;; require one newline at the end.
4666 (or (= (preceding-char) ?\n)
4668 (let ((case-fold-search t))
4669 ;; Remove the delimiter.
4670 (goto-char (point-min))
4672 (concat "^" (regexp-quote mail-header-separator) "\n"))
4673 (replace-match "\n")
4675 (run-hooks 'message-send-news-hook)
4676 (gnus-open-server method)
4677 (message "Sending news via %s..." (gnus-server-string method))
4678 (setq result (let ((mail-header-separator ""))
4679 (gnus-request-post method))))
4680 (kill-buffer tembuf))
4681 (set-buffer messbuf)
4683 (push 'news message-sent-message-via)
4684 (message "Couldn't send message via news: %s"
4685 (nnheader-get-report (car method)))
4689 ;;; Header generation & syntax checking.
4692 (defun message-check-element (type)
4693 "Return non-nil if this TYPE is not to be checked."
4694 (if (eq message-syntax-checks 'dont-check-for-anything-just-trust-me)
4696 (let ((able (assq type message-syntax-checks)))
4698 (eq (cdr able) 'disabled)))))
4700 (defun message-check-news-syntax ()
4701 "Check the syntax of the message."
4705 ;; We narrow to the headers and check them first.
4708 (message-narrow-to-headers)
4709 (message-check-news-header-syntax))))))
4711 (defun message-check-news-header-syntax ()
4713 ;; Check Newsgroups header.
4714 (message-check 'newsgroups
4715 (let ((group (message-fetch-field "newsgroups")))
4718 (not (string-match "\\`[ \t]*\\'" group)))
4721 "The newsgroups field is empty or missing. Posting is denied.")))))
4722 ;; Check the Subject header.
4723 (message-check 'subject
4724 (let* ((case-fold-search t)
4725 (subject (message-fetch-field "subject")))
4728 (not (string-match "\\`[ \t]*\\'" subject)))
4731 "The subject field is empty or missing. Posting is denied.")))))
4732 ;; Check for commands in Subject.
4733 (message-check 'subject-cmsg
4734 (if (string-match "^cmsg " (message-fetch-field "subject"))
4736 "The control code \"cmsg\" is in the subject. Really post? ")
4738 ;; Check long header lines.
4739 (message-check 'long-header-lines
4740 (let ((start (point))
4744 (while (and (not found)
4745 (re-search-forward "^\\([^ \t:]+\\): " nil t))
4746 (if (> (- (point) (match-beginning 0)) 998)
4748 length (- (point) (match-beginning 0)))
4749 (setq header (match-string-no-properties 1)))
4750 (setq start (match-beginning 0))
4753 (y-or-n-p (format "Your %s header is too long (%d). Really post? "
4756 ;; Check for multiple identical headers.
4757 (message-check 'multiple-headers
4759 (while (and (not found)
4760 (re-search-forward "^[^ \t:]+: " nil t))
4762 (or (re-search-forward
4767 (match-beginning 0) (- (match-end 0) 2))))
4772 (y-or-n-p (format "Multiple %s headers. Really post? " found))
4774 ;; Check for Version and Sendsys.
4775 (message-check 'sendsys
4776 (if (re-search-forward "^Sendsys:\\|^Version:" nil t)
4778 (format "The article contains a %s command. Really post? "
4779 (buffer-substring (match-beginning 0)
4780 (1- (match-end 0)))))
4782 ;; See whether we can shorten Followup-To.
4783 (message-check 'shorten-followup-to
4784 (let ((newsgroups (message-fetch-field "newsgroups"))
4785 (followup-to (message-fetch-field "followup-to"))
4787 (when (and newsgroups
4788 (string-match "," newsgroups)
4793 (setq to (completing-read
4794 "Followups to (default no Followup-To header): "
4797 (message-tokenize-header
4799 (goto-char (point-min))
4800 (insert "Followup-To: " to "\n"))
4802 ;; Check "Shoot me".
4803 (message-check 'shoot
4804 (if (re-search-forward
4805 "Message-ID.*.i-did-not-set--mail-host-address--so-tickle-me" nil t)
4806 (y-or-n-p "You appear to have a misconfigured system. Really post? ")
4808 ;; Check for Approved.
4809 (message-check 'approved
4810 (if (re-search-forward "^Approved:" nil t)
4811 (y-or-n-p "The article contains an Approved header. Really post? ")
4813 ;; Check the Message-ID header.
4814 (message-check 'message-id
4815 (let* ((case-fold-search t)
4816 (message-id (message-fetch-field "message-id" t)))
4817 (or (not message-id)
4818 ;; Is there an @ in the ID?
4819 (and (string-match "@" message-id)
4820 ;; Is there a dot in the ID?
4821 (string-match "@[^.]*\\." message-id)
4822 ;; Does the ID end with a dot?
4823 (not (string-match "\\.>" message-id)))
4825 (format "The Message-ID looks strange: \"%s\". Really post? "
4827 ;; Check the Newsgroups & Followup-To headers.
4828 (message-check 'existing-newsgroups
4829 (let* ((case-fold-search t)
4830 (newsgroups (message-fetch-field "newsgroups"))
4831 (followup-to (message-fetch-field "followup-to"))
4832 (groups (message-tokenize-header
4834 (concat newsgroups "," followup-to)
4836 (post-method (if (functionp message-post-method)
4837 (funcall message-post-method)
4838 message-post-method))
4839 ;; KLUDGE to handle nnvirtual groups. Doing this right
4840 ;; would probably involve a new nnoo function.
4841 ;; -- Per Abrahamsen <abraham@dina.kvl.dk>, 2001-10-17.
4842 (method (if (and (consp post-method)
4843 (eq (car post-method) 'nnvirtual)
4844 gnus-message-group-art)
4845 (let ((group (car (nnvirtual-find-group-art
4846 (car gnus-message-group-art)
4847 (cdr gnus-message-group-art)))))
4848 (gnus-find-method-for-group group))
4852 (gnus-group-name-decode
4853 (gnus-group-real-name n)
4854 (gnus-group-name-charset method n)))
4855 (gnus-groups-from-server method)))
4858 (when (and (not (equal (car groups) "poster"))
4859 (not (member (car groups) known-groups))
4860 (not (member (car groups) errors)))
4861 (push (car groups) errors))
4864 ;; Gnus is not running.
4865 ((or (not (and (boundp 'gnus-active-hashtb)
4866 gnus-active-hashtb))
4867 (not (boundp 'gnus-read-active-file)))
4869 ;; We don't have all the group names.
4870 ((and (or (not gnus-read-active-file)
4871 (eq gnus-read-active-file 'some))
4875 "Really use %s possibly unknown group%s: %s? "
4876 (if (= (length errors) 1) "this" "these")
4877 (if (= (length errors) 1) "" "s")
4878 (mapconcat 'identity errors ", "))))
4879 ;; There were no errors.
4882 ;; There are unknown groups.
4886 "Really post to %s unknown group%s: %s? "
4887 (if (= (length errors) 1) "this" "these")
4888 (if (= (length errors) 1) "" "s")
4889 (mapconcat 'identity errors ", ")))))))
4890 ;; Check continuation headers.
4891 (message-check 'continuation-headers
4892 (goto-char (point-min))
4893 (let ((do-posting t))
4894 (while (re-search-forward "^[^ \t\n][^ \t\n:]*[ \t\n]" nil t)
4895 (goto-char (match-beginning 0))
4896 (if (y-or-n-p "Fix continuation lines? ")
4899 (unless (y-or-n-p "Send anyway? ")
4900 (setq do-posting nil))))
4902 ;; Check the Newsgroups & Followup-To headers for syntax errors.
4903 (message-check 'valid-newsgroups
4904 (let ((case-fold-search t)
4905 (headers '("Newsgroups" "Followup-To"))
4907 (while (and headers (not error))
4908 (when (setq header (mail-fetch-field (car headers)))
4912 "\\`\\([-+_&.a-zA-Z0-9]+\\)?\\(,[-+_&.a-zA-Z0-9]+\\)*\\'"
4917 (not (string-match "\\.\\'\\|\\.\\." g)))
4918 (message-tokenize-header header ","))))
4925 (format "The %s header looks odd: \"%s\". Really post? "
4926 (car headers) header)))))
4927 (message-check 'repeated-newsgroups
4928 (let ((case-fold-search t)
4929 (headers '("Newsgroups" "Followup-To"))
4930 header error groups group)
4933 (when (setq header (mail-fetch-field (pop headers)))
4934 (setq groups (message-tokenize-header header ","))
4935 (while (setq group (pop groups))
4936 (when (member group groups)
4942 (format "Group %s is repeated in headers. Really post? " error)))))
4943 ;; Check the From header.
4944 (message-check 'from
4945 (let* ((case-fold-search t)
4946 (from (message-fetch-field "from"))
4950 (message "There is no From line. Posting is denied.")
4952 ((or (not (string-match
4954 (setq ad (nth 1 (mail-extract-address-components
4955 from))))) ;larsi@ifi
4956 (string-match "\\.\\." ad) ;larsi@ifi..uio
4957 (string-match "@\\." ad) ;larsi@.ifi.uio
4958 (string-match "\\.$" ad) ;larsi@ifi.uio.
4959 (not (string-match "^[^@]+@[^@]+$" ad)) ;larsi.ifi.uio
4960 (string-match "(.*).*(.*)" from)) ;(lars) (lars)
4962 "Denied posting -- the From looks strange: \"%s\"." from)
4964 ((let ((addresses (rfc822-addresses from)))
4965 (while (and addresses
4966 (not (eq (string-to-char (car addresses)) ?\()))
4967 (setq addresses (cdr addresses)))
4970 "Denied posting -- bad From address: \"%s\"." from)
4973 ;; Check the Reply-To header.
4974 (message-check 'reply-to
4975 (let* ((case-fold-search t)
4976 (reply-to (message-fetch-field "reply-to"))
4981 ((string-match "," reply-to)
4983 (format "Multiple Reply-To addresses: \"%s\". Really post? "
4985 ((or (not (string-match
4987 (setq ad (nth 1 (mail-extract-address-components
4988 reply-to))))) ;larsi@ifi
4989 (string-match "\\.\\." ad) ;larsi@ifi..uio
4990 (string-match "@\\." ad) ;larsi@.ifi.uio
4991 (string-match "\\.$" ad) ;larsi@ifi.uio.
4992 (not (string-match "^[^@]+@[^@]+$" ad)) ;larsi.ifi.uio
4993 (string-match "(.*).*(.*)" reply-to)) ;(lars) (lars)
4996 "The Reply-To looks strange: \"%s\". Really post? "
5000 (defun message-check-news-body-syntax ()
5002 ;; Check for long lines.
5003 (message-check 'long-lines
5004 (goto-char (point-min))
5006 (concat "^" (regexp-quote mail-header-separator) "$"))
5010 "<#\\(/\\)?\\(multipart\\|part\\|external\\|mml\\)")
5013 (< (- (point) p) 80)))
5014 (zerop (forward-line 1))))
5018 "You have lines longer than 79 characters. Really post? ")))
5019 ;; Check whether the article is empty.
5020 (message-check 'empty
5021 (goto-char (point-min))
5023 (concat "^" (regexp-quote mail-header-separator) "$"))
5026 (goto-char (point-max))
5027 (re-search-backward message-signature-separator nil t)
5029 (or (re-search-backward "[^ \n\t]" b t)
5030 (if (message-gnksa-enable-p 'empty-article)
5031 (y-or-n-p "Empty article. Really post? ")
5032 (message "Denied posting -- Empty article.")
5034 ;; Check for control characters.
5035 (message-check 'control-chars
5036 (if (re-search-forward
5037 (mm-string-to-multibyte "[\000-\007\013\015-\032\034-\037\200-\237]")
5040 "The article contains control characters. Really post? ")
5042 ;; Check excessive size.
5043 (message-check 'size
5044 (if (> (buffer-size) 60000)
5046 (format "The article is %d octets long. Really post? "
5049 ;; Check whether any new text has been added.
5050 (message-check 'new-text
5052 (not message-checksum)
5053 (not (eq (message-checksum) message-checksum))
5054 (if (message-gnksa-enable-p 'quoted-text-only)
5056 "It looks like no new text has been added. Really post? ")
5057 (message "Denied posting -- no new text has been added.")
5059 ;; Check the length of the signature.
5060 (message-check 'signature
5061 (goto-char (point-max))
5062 (if (> (count-lines (point) (point-max)) 5)
5065 "Your .sig is %d lines; it should be max 4. Really post? "
5066 (1- (count-lines (point) (point-max)))))
5068 ;; Ensure that text follows last quoted portion.
5069 (message-check 'quoting-style
5070 (goto-char (point-max))
5071 (let ((no-problem t))
5072 (when (search-backward-regexp "^>[^\n]*\n" nil t)
5073 (setq no-problem (search-forward-regexp "^[ \t]*[^>\n]" nil t)))
5076 (if (message-gnksa-enable-p 'quoted-text-only)
5077 (y-or-n-p "Your text should follow quoted text. Really post? ")
5079 (goto-char (point-min))
5081 (concat "^" (regexp-quote mail-header-separator) "$"))
5082 (if (search-forward-regexp "^[ \t]*[^>\n]" nil t)
5083 (y-or-n-p "Your text should follow quoted text. Really post? ")
5084 (message "Denied posting -- only quoted text.")
5087 (defun message-checksum ()
5088 "Return a \"checksum\" for the current buffer."
5091 (goto-char (point-min))
5093 (concat "^" (regexp-quote mail-header-separator) "$"))
5095 (when (not (looking-at "[ \t\n]"))
5096 (setq sum (logxor (ash sum 1) (if (natnump sum) 0 1)
5101 (defun message-do-fcc ()
5102 "Process Fcc headers in the current buffer."
5103 (let ((case-fold-search t)
5104 (buf (current-buffer))
5106 (mml-externalize-attachments message-fcc-externalize-attachments))
5109 (message-narrow-to-headers)
5110 (setq file (message-fetch-field "fcc" t)))
5112 (set-buffer (get-buffer-create " *message temp*"))
5114 (insert-buffer-substring buf)
5115 (message-encode-message-body)
5117 (message-narrow-to-headers)
5118 (while (setq file (message-fetch-field "fcc" t))
5120 (message-remove-header "fcc" nil t))
5121 (let ((mail-parse-charset message-default-charset)
5122 (rfc2047-header-encoding-alist
5123 (cons '("Newsgroups" . default)
5124 rfc2047-header-encoding-alist)))
5125 (mail-encode-encoded-word-buffer)))
5126 (goto-char (point-min))
5127 (when (re-search-forward
5128 (concat "^" (regexp-quote mail-header-separator) "$")
5130 (replace-match "" t t ))
5131 ;; Process FCC operations.
5133 (setq file (pop list))
5134 (if (string-match "^[ \t]*|[ \t]*\\(.*\\)[ \t]*$" file)
5135 ;; Pipe the article to the program in question.
5136 (call-process-region (point-min) (point-max) shell-file-name
5137 nil nil nil shell-command-switch
5138 (match-string 1 file))
5139 ;; Save the article.
5140 (setq file (expand-file-name file))
5141 (unless (file-exists-p (file-name-directory file))
5142 (make-directory (file-name-directory file) t))
5143 (if (and message-fcc-handler-function
5144 (not (eq message-fcc-handler-function 'rmail-output)))
5145 (funcall message-fcc-handler-function file)
5146 (if (and (file-readable-p file) (mail-file-babyl-p file))
5147 (rmail-output file 1 nil t)
5148 (let ((mail-use-rfc822 t))
5149 (rmail-output file 1 t t))))))
5150 (kill-buffer (current-buffer))))))
5152 (defun message-output (filename)
5153 "Append this article to Unix/babyl mail file FILENAME."
5154 (if (and (file-readable-p filename)
5155 (mail-file-babyl-p filename))
5156 (gnus-output-to-rmail filename t)
5157 (gnus-output-to-mail filename t)))
5159 (defun message-cleanup-headers ()
5160 "Do various automatic cleanups of the headers."
5161 ;; Remove empty lines in the header.
5163 (message-narrow-to-headers)
5164 ;; Remove blank lines.
5165 (while (re-search-forward "^[ \t]*\n" nil t)
5166 (replace-match "" t t))
5168 ;; Correct Newsgroups and Followup-To headers: Change sequence of
5169 ;; spaces to comma and eliminate spaces around commas. Eliminate
5170 ;; embedded line breaks.
5171 (goto-char (point-min))
5172 (while (re-search-forward "^\\(Newsgroups\\|Followup-To\\): +" nil t)
5176 (if (re-search-forward "^[^ \t]" nil t)
5180 (goto-char (point-min))
5181 (while (re-search-forward "\n[ \t]+" nil t)
5182 (replace-match " " t t)) ;No line breaks (too confusing)
5183 (goto-char (point-min))
5184 (while (re-search-forward "[ \t\n]*,[ \t\n]*\\|[ \t]+" nil t)
5185 (replace-match "," t t))
5186 (goto-char (point-min))
5187 ;; Remove trailing commas.
5188 (when (re-search-forward ",+$" nil t)
5189 (replace-match "" t t))))))
5191 (defun message-make-date (&optional now)
5192 "Make a valid data header.
5193 If NOW, use that time instead."
5194 (let ((system-time-locale "C"))
5195 (format-time-string "%a, %d %b %Y %T %z" now)))
5197 (defun message-insert-expires (days)
5198 "Insert the Expires header. Expiry in DAYS days."
5199 (interactive "NExpire article in how many days? ")
5201 (message-position-on-field "Expires" "X-Draft-From")
5202 (insert (message-make-expires-date days))))
5204 (defun message-make-expires-date (days)
5205 "Make date string for the Expires header. Expiry in DAYS days.
5207 In posting styles use `(\"Expires\" (make-expires-date 30))'."
5208 (let* ((cur (decode-time (current-time)))
5209 (nday (+ days (nth 3 cur))))
5210 (setf (nth 3 cur) nday)
5211 (message-make-date (apply 'encode-time cur))))
5213 (defun message-make-message-id ()
5214 "Make a unique Message-ID."
5215 (concat "<" (message-unique-id)
5216 (let ((psubject (save-excursion (message-fetch-field "subject")))
5218 (save-excursion (message-fetch-field "supersedes"))))
5220 (and message-reply-headers
5221 (mail-header-references message-reply-headers)
5222 (mail-header-subject message-reply-headers)
5225 (message-strip-subject-re
5226 (mail-header-subject message-reply-headers))
5227 (message-strip-subject-re psubject))))
5229 (string-match "_-_@" psupersedes)))
5231 "@" (message-make-fqdn) ">"))
5233 (defvar message-unique-id-char nil)
5235 ;; If you ever change this function, make sure the new version
5236 ;; cannot generate IDs that the old version could.
5237 ;; You might for example insert a "." somewhere (not next to another dot
5238 ;; or string boundary), or modify the "fsf" string.
5239 (defun message-unique-id ()
5240 ;; Don't use microseconds from (current-time), they may be unsupported.
5241 ;; Instead we use this randomly inited counter.
5242 (setq message-unique-id-char
5243 (% (1+ (or message-unique-id-char (logand (random t) (1- (lsh 1 20)))))
5244 ;; (current-time) returns 16-bit ints,
5245 ;; and 2^16*25 just fits into 4 digits i base 36.
5247 (let ((tm (current-time)))
5249 (if (or (memq system-type '(ms-dos emx vax-vms))
5250 ;; message-number-base36 doesn't handle bigints.
5251 (floatp (user-uid)))
5252 (let ((user (downcase (user-login-name))))
5253 (while (string-match "[^a-z0-9_]" user)
5254 (aset user (match-beginning 0) ?_))
5256 (message-number-base36 (user-uid) -1))
5257 (message-number-base36 (+ (car tm)
5258 (lsh (% message-unique-id-char 25) 16)) 4)
5259 (message-number-base36 (+ (nth 1 tm)
5260 (lsh (/ message-unique-id-char 25) 16)) 4)
5261 ;; Append a given name, because while the generated ID is unique
5262 ;; to this newsreader, other newsreaders might otherwise generate
5263 ;; the same ID via another algorithm.
5266 (defun message-number-base36 (num len)
5271 (concat (message-number-base36 (/ num 36) (1- len))
5272 (char-to-string (aref "zyxwvutsrqponmlkjihgfedcba9876543210"
5275 (defun message-make-organization ()
5276 "Make an Organization header."
5277 (let* ((organization
5278 (when message-user-organization
5279 (if (functionp message-user-organization)
5280 (funcall message-user-organization)
5281 message-user-organization))))
5283 (mm-enable-multibyte)
5284 (cond ((stringp organization)
5285 (insert organization))
5286 ((and (eq t organization)
5287 message-user-organization-file
5288 (file-exists-p message-user-organization-file))
5289 (insert-file-contents message-user-organization-file)))
5290 (goto-char (point-min))
5291 (while (re-search-forward "[\t\n]+" nil t)
5292 (replace-match "" t t))
5293 (unless (zerop (buffer-size))
5296 (defun message-make-lines ()
5297 "Count the number of lines and return numeric string."
5302 (int-to-string (count-lines (point) (point-max))))))
5304 (defun message-make-references ()
5305 "Return the References header for this message."
5306 (when message-reply-headers
5307 (let ((message-id (mail-header-message-id message-reply-headers))
5308 (references (mail-header-references message-reply-headers)))
5309 (if (or references message-id)
5310 (concat (or references "") (and references " ")
5314 (defun message-make-in-reply-to ()
5315 "Return the In-Reply-To header for this message."
5316 (when message-reply-headers
5317 (let ((from (mail-header-from message-reply-headers))
5318 (date (mail-header-date message-reply-headers))
5319 (msg-id (mail-header-message-id message-reply-headers)))
5321 (let ((name (mail-extract-address-components from)))
5323 msg-id (if msg-id " (")
5325 (if (string-match "[^\000-\177]" (car name))
5326 ;; Quote a string containing non-ASCII characters.
5327 ;; It will make the RFC2047 encoder cause an error
5328 ;; if there are special characters.
5329 (let ((default-enable-multibyte-characters t))
5332 (goto-char (point-min))
5333 (while (search-forward "\"" nil t)
5336 (zerop (% (skip-chars-backward "\\\\") 2))
5337 (goto-char (match-beginning 0)))
5340 ;; Those quotes will be removed by the RFC2047 encoder.
5341 (concat "\"" (buffer-string) "\"")))
5345 (if (or (not date) (string= date ""))
5346 "(unknown date)" date)
5347 "\"" (if msg-id ")")))))))
5349 (defun message-make-distribution ()
5350 "Make a Distribution header."
5351 (let ((orig-distribution (message-fetch-reply-field "distribution")))
5352 (cond ((functionp message-distribution-function)
5353 (funcall message-distribution-function))
5354 (t orig-distribution))))
5356 (defun message-make-expires ()
5357 "Return an Expires header based on `message-expires'."
5358 (let ((current (current-time))
5359 (future (* 1.0 message-expires 60 60 24)))
5360 ;; Add the future to current.
5361 (setcar current (+ (car current) (round (/ future (expt 2 16)))))
5362 (setcar (cdr current) (+ (nth 1 current) (% (round future) (expt 2 16))))
5363 (message-make-date current)))
5365 (defun message-make-path ()
5367 (let ((login-name (user-login-name)))
5368 (cond ((null message-user-path)
5369 (concat (system-name) "!" login-name))
5370 ((stringp message-user-path)
5371 ;; Support GENERICPATH. Suggested by vixie@decwrl.dec.com.
5372 (concat message-user-path "!" login-name))
5375 (defun message-make-from (&optional name address)
5376 "Make a From header."
5377 (let* ((style message-from-style)
5378 (login (or address (message-make-address)))
5380 (and (boundp 'user-full-name)
5383 (when (string= fullname "&")
5384 (setq fullname (user-login-name)))
5386 (mm-enable-multibyte)
5389 (equal fullname ""))
5391 ((or (eq style 'angles)
5392 (and (not (eq style 'parens))
5393 ;; Use angles if no quoting is needed, or if parens would
5394 ;; need quoting too.
5395 (or (not (string-match "[^- !#-'*+/-9=?A-Z^-~]" fullname))
5396 (let ((tmp (concat fullname nil)))
5397 (while (string-match "([^()]*)" tmp)
5398 (aset tmp (match-beginning 0) ?-)
5399 (aset tmp (1- (match-end 0)) ?-))
5400 (string-match "[\\()]" tmp)))))
5402 (goto-char (point-min))
5403 ;; Look for a character that cannot appear unquoted
5404 ;; according to RFC 822.
5405 (when (re-search-forward "[^- !#-'*+/-9=?A-Z^-~]" nil 1)
5406 ;; Quote fullname, escaping specials.
5407 (goto-char (point-min))
5409 (while (re-search-forward "[\"\\]" nil 1)
5410 (replace-match "\\\\\\&" t))
5412 (insert " <" login ">"))
5413 (t ; 'parens or default
5415 (let ((fullname-start (point)))
5417 (goto-char fullname-start)
5418 ;; RFC 822 says \ and nonmatching parentheses
5419 ;; must be escaped in comments.
5420 ;; Escape every instance of ()\ ...
5421 (while (re-search-forward "[()\\]" nil 1)
5422 (replace-match "\\\\\\&" t))
5423 ;; ... then undo escaping of matching parentheses,
5424 ;; including matching nested parentheses.
5425 (goto-char fullname-start)
5426 (while (re-search-forward
5427 "\\(\\=\\|[^\\]\\(\\\\\\\\\\)*\\)\\\\(\\(\\([^\\]\\|\\\\\\\\\\)*\\)\\\\)"
5429 (replace-match "\\1(\\3)" t)
5430 (goto-char fullname-start)))
5434 (defun message-make-sender ()
5435 "Return the \"real\" user address.
5436 This function tries to ignore all user modifications, and
5437 give as trustworthy answer as possible."
5438 (concat (user-login-name) "@" (system-name)))
5440 (defun message-make-address ()
5441 "Make the address of the user."
5442 (or (message-user-mail-address)
5443 (concat (user-login-name) "@" (message-make-domain))))
5445 (defun message-user-mail-address ()
5446 "Return the pertinent part of `user-mail-address'."
5447 (when (and user-mail-address
5448 (string-match "@.*\\." user-mail-address))
5449 (if (string-match " " user-mail-address)
5450 (nth 1 (mail-extract-address-components user-mail-address))
5451 user-mail-address)))
5453 (defun message-sendmail-envelope-from ()
5454 "Return the envelope from."
5455 (cond ((eq message-sendmail-envelope-from 'header)
5456 (nth 1 (mail-extract-address-components
5457 (message-fetch-field "from"))))
5458 ((stringp message-sendmail-envelope-from)
5459 message-sendmail-envelope-from)
5461 (message-make-address))))
5463 (defun message-make-fqdn ()
5464 "Return user's fully qualified domain name."
5465 (let* ((system-name (system-name))
5466 (user-mail (message-user-mail-address))
5469 (string-match "@\\(.*\\)\\'" user-mail))
5470 (match-string 1 user-mail)))
5471 (case-fold-search t))
5473 ((and message-user-fqdn
5474 (stringp message-user-fqdn)
5475 (string-match message-valid-fqdn-regexp message-user-fqdn)
5476 (not (string-match message-bogus-system-names message-user-fqdn)))
5477 ;; `message-user-fqdn' seems to be valid
5479 ((and (string-match message-valid-fqdn-regexp system-name)
5480 (not (string-match message-bogus-system-names system-name)))
5481 ;; `system-name' returned the right result.
5483 ;; Try `mail-host-address'.
5484 ((and (boundp 'mail-host-address)
5485 (stringp mail-host-address)
5486 (string-match message-valid-fqdn-regexp mail-host-address)
5487 (not (string-match message-bogus-system-names mail-host-address)))
5489 ;; We try `user-mail-address' as a backup.
5491 (stringp user-domain)
5492 (string-match message-valid-fqdn-regexp user-domain)
5493 (not (string-match message-bogus-system-names user-domain)))
5495 ;; Default to this bogus thing.
5498 ".i-did-not-set--mail-host-address--so-tickle-me")))))
5500 (defun message-make-host-name ()
5501 "Return the name of the host."
5502 (let ((fqdn (message-make-fqdn)))
5503 (string-match "^[^.]+\\." fqdn)
5504 (substring fqdn 0 (1- (match-end 0)))))
5506 (defun message-make-domain ()
5507 "Return the domain name."
5508 (or mail-host-address
5509 (message-make-fqdn)))
5511 (defun message-to-list-only ()
5512 "Send a message to the list only.
5513 Remove all addresses but the list address from To and Cc headers."
5515 (let ((listaddr (message-make-mail-followup-to t)))
5518 (message-remove-header "to")
5519 (message-remove-header "cc")
5520 (message-position-on-field "To" "X-Draft-From")
5521 (insert listaddr)))))
5523 (defun message-make-mail-followup-to (&optional only-show-subscribed)
5524 "Return the Mail-Followup-To header.
5525 If passed the optional argument ONLY-SHOW-SUBSCRIBED only return the
5526 subscribed address (and not the additional To and Cc header contents)."
5527 (let* ((case-fold-search t)
5528 (to (message-fetch-field "To"))
5529 (cc (message-fetch-field "cc"))
5530 (msg-recipients (concat to (and to cc ", ") cc))
5532 (mapcar 'mail-strip-quoted-names
5533 (message-tokenize-header msg-recipients)))
5535 (if message-subscribed-address-file
5536 (let (begin end item re)
5539 (insert-file-contents message-subscribed-address-file)
5541 (setq begin (point))
5544 (if (bolp) (setq end (1- end)))
5545 (setq item (regexp-quote (buffer-substring begin end)))
5546 (if re (setq re (concat re "\\|" item))
5547 (setq re (concat "\\`\\(" item))))
5548 (and re (list (concat re "\\)\\'"))))))))
5549 (mft-regexps (apply 'append message-subscribed-regexps
5550 (mapcar 'regexp-quote
5551 message-subscribed-addresses)
5554 message-subscribed-address-functions))))
5557 (loop for recipient in recipients
5558 when (loop for regexp in mft-regexps
5559 when (string-match regexp recipient) return t)
5562 (if only-show-subscribed
5564 msg-recipients))))))
5566 (defun message-idna-to-ascii-rhs-1 (header)
5567 "Interactively potentially IDNA encode domain names in HEADER."
5568 (let ((field (message-fetch-field header))
5572 (mm-delete-duplicates
5573 (mapcar (lambda (rhs) (or (cadr (split-string rhs "@")) ""))
5576 'car (mail-header-parse-addresses field))))))
5577 (setq ace (if (string-match "\\`[[:ascii:]]+\\'" rhs)
5579 (downcase (idna-to-ascii rhs))))
5580 (when (and (not (equal rhs ace))
5581 (or (not (eq message-use-idna 'ask))
5582 (y-or-n-p (format "Replace %s with %s in %s:? "
5584 (goto-char (point-min))
5585 (while (re-search-forward (concat "^" header ":") nil t)
5586 (message-narrow-to-field)
5587 (while (search-forward (concat "@" rhs) nil t)
5588 (replace-match (concat "@" ace) t t))
5589 (goto-char (point-max))
5592 (defun message-idna-to-ascii-rhs ()
5593 "Possibly IDNA encode non-ASCII domain names in From:, To: and Cc: headers.
5594 See `message-idna-encode'."
5596 (when message-use-idna
5599 (message-narrow-to-head)
5600 (message-idna-to-ascii-rhs-1 "From")
5601 (message-idna-to-ascii-rhs-1 "To")
5602 (message-idna-to-ascii-rhs-1 "Reply-To")
5603 (message-idna-to-ascii-rhs-1 "Mail-Reply-To")
5604 (message-idna-to-ascii-rhs-1 "Mail-Followup-To")
5605 (message-idna-to-ascii-rhs-1 "Cc")))))
5607 (defun message-generate-headers (headers)
5608 "Prepare article HEADERS.
5609 Headers already prepared in the buffer are not modified."
5610 (setq headers (append headers message-required-headers))
5612 (message-narrow-to-headers)
5613 (let* ((Date (message-make-date))
5614 (Message-ID (message-make-message-id))
5615 (Organization (message-make-organization))
5616 (From (message-make-from))
5617 (Path (message-make-path))
5620 (In-Reply-To (message-make-in-reply-to))
5621 (References (message-make-references))
5623 (Distribution (message-make-distribution))
5624 (Lines (message-make-lines))
5625 (User-Agent message-newsreader)
5626 (Expires (message-make-expires))
5627 (case-fold-search t)
5629 header value elem header-string)
5630 ;; First we remove any old generated headers.
5631 (let ((headers message-deletable-headers))
5632 (unless (buffer-modified-p)
5633 (setq headers (delq 'Message-ID (copy-sequence headers))))
5635 (goto-char (point-min))
5636 (and (re-search-forward
5637 (concat "^" (symbol-name (car headers)) ": *") nil t)
5638 (get-text-property (1+ (match-beginning 0)) 'message-deletable)
5639 (message-delete-line))
5641 ;; Go through all the required headers and see if they are in the
5642 ;; articles already. If they are not, or are empty, they are
5643 ;; inserted automatically - except for Subject, Newsgroups and
5646 (goto-char (point-min))
5647 (setq elem (pop headers))
5649 (if (eq (car elem) 'optional)
5650 (setq header (cdr elem)
5652 (setq header (car elem)))
5654 (setq header-string (if (stringp header)
5656 (symbol-name header)))
5657 (when (or (not (re-search-forward
5659 (regexp-quote (downcase header-string))
5663 ;; The header was found. We insert a space after the
5664 ;; colon, if there is none.
5665 (if (/= (char-after) ? ) (insert " ") (forward-char 1))
5666 ;; Find out whether the header is empty.
5667 (looking-at "[ \t]*\n[^ \t]")))
5668 ;; So we find out what value we should insert.
5672 (eq (car elem) 'optional)
5673 (not (member header-string message-inserted-headers)))
5674 ;; This is an optional header. If the cdr of this
5675 ;; is something that is nil, then we do not insert
5677 (setq header (cdr elem))
5678 (or (and (functionp (cdr elem))
5679 (funcall (cdr elem)))
5680 (and (boundp (cdr elem))
5681 (symbol-value (cdr elem)))))
5683 ;; The element is a cons. Either the cdr is a
5684 ;; string to be inserted verbatim, or it is a
5685 ;; function, and we insert the value returned from
5687 (or (and (stringp (cdr elem))
5689 (and (functionp (cdr elem))
5690 (funcall (cdr elem)))))
5691 ((and (boundp header)
5692 (symbol-value header))
5693 ;; The element is a symbol. We insert the value
5694 ;; of this symbol, if any.
5695 (symbol-value header))
5696 ((not (message-check-element
5697 (intern (downcase (symbol-name header)))))
5698 ;; We couldn't generate a value for this header,
5699 ;; so we just ask the user.
5700 (read-from-minibuffer
5701 (format "Empty header for %s; enter value: " header)))))
5702 ;; Finally insert the header.
5704 (not (equal value "")))
5708 ;; This header didn't exist, so we insert it.
5709 (goto-char (point-max))
5711 (cdr (assq header message-header-format-alist))))
5713 (funcall formatter header value)
5714 (insert header-string ": " value))
5715 (goto-char (message-fill-field))
5716 ;; We check whether the value was ended by a
5717 ;; newline. If not, we insert one.
5721 ;; The value of this header was empty, so we clear
5722 ;; totally and insert the new value.
5723 (delete-region (point) (point-at-eol))
5724 ;; If the header is optional, and the header was
5725 ;; empty, we can't insert it anyway.
5727 (push header-string message-inserted-headers)
5729 (message-fill-field)))
5730 ;; Add the deletable property to the headers that require it.
5731 (and (memq header message-deletable-headers)
5732 (progn (beginning-of-line) (looking-at "[^:]+: "))
5733 (add-text-properties
5734 (point) (match-end 0)
5735 '(message-deletable t face italic) (current-buffer)))))))
5736 ;; Insert new Sender if the From is strange.
5737 (let ((from (message-fetch-field "from"))
5738 (sender (message-fetch-field "sender"))
5739 (secure-sender (message-make-sender)))
5741 (not (message-check-element 'sender))
5744 (cadr (mail-extract-address-components from)))
5745 (downcase secure-sender)))
5750 (cadr (mail-extract-address-components sender)))
5751 (downcase secure-sender)))))
5752 (goto-char (point-min))
5753 ;; Rename any old Sender headers to Original-Sender.
5754 (when (re-search-forward "^\\(Original-\\)*Sender:" nil t)
5756 (insert "Original-")
5757 (beginning-of-line))
5758 (when (or (message-news-p)
5759 (string-match "@.+\\.." secure-sender))
5760 (insert "Sender: " secure-sender "\n"))))
5762 (message-idna-to-ascii-rhs))))
5764 (defun message-insert-courtesy-copy ()
5765 "Insert a courtesy message in mail copies of combined messages."
5769 (message-narrow-to-headers)
5770 (when (setq newsgroups (message-fetch-field "newsgroups"))
5771 (goto-char (point-max))
5772 (insert "Posted-To: " newsgroups "\n")))
5774 (when message-courtesy-message
5776 ((string-match "%s" message-courtesy-message)
5777 (insert (format message-courtesy-message newsgroups)))
5779 (insert message-courtesy-message)))))))
5782 ;;; Setting up a message buffer
5785 (defun message-skip-to-next-address ()
5786 (let ((end (save-excursion
5787 (message-next-header)
5790 (when (looking-at ",")
5792 (while (and (not (= (point) end))
5793 (or (not (eq char ?,))
5795 (skip-chars-forward "^,\"" (point-max))
5796 (when (eq (setq char (following-char)) ?\")
5797 (setq quoted (not quoted)))
5798 (unless (= (point) end)
5800 (skip-chars-forward " \t\n")))
5802 (defun message-fill-address (header value)
5803 (insert (capitalize (symbol-name header))
5805 (if (consp value) (car value) value)
5807 (message-fill-field-address))
5809 (defun message-split-line ()
5810 "Split current line, moving portion beyond point vertically down.
5811 If the current line has `message-yank-prefix', insert it on the new line."
5814 (split-line message-yank-prefix) ;; Emacs 22.1+ supports arg.
5818 (defun message-insert-header (header value)
5819 (insert (capitalize (symbol-name header))
5821 (if (consp value) (car value) value)))
5823 (defun message-field-name ()
5825 (goto-char (point-min))
5826 (when (looking-at "\\([^:]+\\):")
5827 (intern (capitalize (match-string 1))))))
5829 (defun message-fill-field ()
5832 (message-narrow-to-field)
5833 (let ((field-name (message-field-name)))
5834 (funcall (or (cadr (assq field-name message-field-fillers))
5835 'message-fill-field-general)))
5838 (defun message-fill-field-address ()
5840 (message-skip-to-next-address)
5842 (if (and (> (current-column) 78)
5848 (setq last (1+ (point))))
5849 (setq last (1+ (point)))))))
5851 (defun message-fill-field-general ()
5852 (let ((begin (point))
5855 (while (and (search-forward "\n" nil t)
5857 (replace-match " " t t))
5858 (fill-region-as-paragraph begin (point-max))
5859 ;; Tapdance around looong Message-IDs.
5861 (when (looking-at "[ \t]*$")
5862 (message-delete-line))
5864 (search-forward ":" nil t)
5865 (when (looking-at "\n[ \t]+")
5866 (replace-match " " t t))
5867 (goto-char (point-max))))
5869 (defun message-shorten-1 (list cut surplus)
5870 "Cut SURPLUS elements out of LIST, beginning with CUTth one."
5871 (setcdr (nthcdr (- cut 2) list)
5872 (nthcdr (+ (- cut 2) surplus 1) list)))
5874 (defun message-shorten-references (header references)
5875 "Trim REFERENCES to be 21 Message-ID long or less, and fold them.
5876 When sending via news, also check that the REFERENCES are less
5877 than 988 characters long, and if they are not, trim them until
5885 (goto-char (point-min))
5886 ;; Cons a list of valid references.
5887 (while (re-search-forward "<[^>]+>" nil t)
5888 (push (match-string 0) refs))
5889 (setq refs (nreverse refs)
5890 count (length refs)))
5892 ;; If the list has more than MAXCOUNT elements, trim it by
5893 ;; removing the CUTth element and the required number of
5894 ;; elements that follow.
5895 (when (> count maxcount)
5896 (let ((surplus (- count maxcount)))
5897 (message-shorten-1 refs cut surplus)
5898 (decf count surplus)))
5900 ;; When sending via news, make sure the total folded length will
5901 ;; be less than 998 characters. This is to cater to broken INN
5902 ;; 2.3 which counts the total number of characters in a header
5903 ;; rather than the physical line length of each line, as it should.
5905 ;; This hack should be removed when it's believed than INN 2.3 is
5906 ;; no longer widely used.
5908 ;; At this point the headers have not been generated, thus we use
5909 ;; message-this-is-news directly.
5910 (when message-this-is-news
5913 (message-insert-header
5914 header (mapconcat #'identity refs " "))
5916 (message-shorten-1 refs cut 1)))
5917 ;; Finally, collect the references back into a string and insert
5918 ;; it into the buffer.
5919 (message-insert-header header (mapconcat #'identity refs " "))))
5921 (defun message-position-point ()
5922 "Move point to where the user probably wants to find it."
5923 (message-narrow-to-headers)
5925 ((re-search-forward "^[^:]+:[ \t]*$" nil t)
5926 (search-backward ":" )
5929 (if (eq (char-after) ? )
5933 (goto-char (point-max))
5936 (unless (looking-at "$")
5940 (defcustom message-beginning-of-line t
5941 "Whether \\<message-mode-map>\\[message-beginning-of-line]\
5942 goes to beginning of header values."
5944 :group 'message-buffers
5945 :link '(custom-manual "(message)Movement")
5948 (defun message-beginning-of-line (&optional n)
5949 "Move point to beginning of header value or to beginning of line.
5950 The prefix argument N is passed directly to `beginning-of-line'.
5952 This command is identical to `beginning-of-line' if point is
5953 outside the message header or if the option `message-beginning-of-line'
5956 If point is in the message header and on a (non-continued) header
5957 line, move point to the beginning of the header value or the beginning of line,
5958 whichever is closer. If point is already at beginning of line, move point to
5959 beginning of header value. Therefore, repeated calls will toggle point
5960 between beginning of field and beginning of line."
5962 (let ((zrs 'zmacs-region-stays))
5963 (when (and (featurep 'xemacs) (interactive-p) (boundp zrs))
5965 (if (and message-beginning-of-line
5966 (message-point-in-header-p))
5967 (let* ((here (point))
5968 (bol (progn (beginning-of-line n) (point)))
5969 (eol (point-at-eol))
5970 (eoh (re-search-forward ": *" eol t)))
5972 (if (and eoh (or (< eoh here) (= bol here)))
5974 (beginning-of-line n)))
5976 (defun message-buffer-name (type &optional to group)
5977 "Return a new (unique) buffer name based on TYPE and TO."
5979 ;; Generate a new buffer name The Message Way.
5980 ((memq message-generate-new-buffers '(unique t))
5981 (generate-new-buffer-name
5985 (or (car (mail-extract-address-components to))
5988 (if (and group (not (string= group ""))) (concat " on " group) "")
5990 ;; Check whether `message-generate-new-buffers' is a function,
5991 ;; and if so, call it.
5992 ((functionp message-generate-new-buffers)
5993 (funcall message-generate-new-buffers type to group))
5994 ((eq message-generate-new-buffers 'unsent)
5995 (generate-new-buffer-name
5996 (concat "*unsent " type
5999 (or (car (mail-extract-address-components to))
6002 (if (and group (not (string= group ""))) (concat " on " group) "")
6004 ;; Search for the existing message buffer with the specified name.
6006 (let* ((new (if (eq message-generate-new-buffers 'standard)
6007 (generate-new-buffer-name (concat "*" type " message*"))
6008 (let ((message-generate-new-buffers 'unique))
6009 (message-buffer-name type to group))))
6010 (regexp (concat "\\`"
6012 (if (string-match "<[0-9]+>\\'" new)
6013 (substring new 0 (match-beginning 0))
6015 "\\(?:<\\([0-9]+\\)>\\)?\\'"))
6016 (case-fold-search nil))
6023 (when (and (string-match regexp (setq b (buffer-name b)))
6024 (eq (with-current-buffer b major-mode)
6026 (cons (string-to-number (or (match-string 1 b) "1"))
6029 'car-less-than-car)))
6032 (defun message-pop-to-buffer (name &optional switch-function)
6033 "Pop to buffer NAME, and warn if it already exists and is modified."
6034 (let ((buffer (get-buffer name)))
6036 (buffer-name buffer))
6037 (let ((window (get-buffer-window buffer 0)))
6039 ;; Raise the frame already displaying the message buffer.
6041 (gnus-select-frame-set-input-focus (window-frame window))
6042 (select-window window))
6043 (funcall (or switch-function 'pop-to-buffer) buffer)
6044 (set-buffer buffer))
6045 (when (and (buffer-modified-p)
6048 "Message already being composed; erase? ")
6050 (error "Message being composed")))
6051 (funcall (or switch-function 'pop-to-buffer) name)
6056 (defun message-do-send-housekeeping ()
6057 "Kill old message buffers."
6058 ;; We might have sent this buffer already. Delete it from the
6060 (setq message-buffer-list (delq (current-buffer) message-buffer-list))
6061 (while (and message-max-buffers
6063 (>= (length message-buffer-list) message-max-buffers))
6064 ;; Kill the oldest buffer -- unless it has been changed.
6065 (let ((buffer (pop message-buffer-list)))
6066 (when (and (buffer-name buffer)
6067 (not (buffer-modified-p buffer)))
6068 (kill-buffer buffer))))
6069 ;; Rename the buffer.
6070 (if message-send-rename-function
6071 (funcall message-send-rename-function)
6072 ;; Note: mail-abbrevs of XEmacs renames buffer name behind Gnus.
6074 "\\`\\*\\(sent \\|unsent \\)?\\(.+\\)\\*[^\\*]*\\|\\`mail to "
6076 (let ((name (match-string 2 (buffer-name)))
6078 (if (not (or (null name)
6079 (string-equal name "mail")
6080 (string-equal name "posting")))
6081 (setq name (concat "*sent " name "*"))
6082 (message-narrow-to-headers)
6083 (setq to (message-fetch-field "to"))
6084 (setq group (message-fetch-field "newsgroups"))
6088 (to (concat "*sent mail to "
6089 (or (car (mail-extract-address-components to))
6091 ((and group (not (string= group "")))
6092 (concat "*sent posting on " group "*"))
6093 (t "*sent mail*"))))
6094 (unless (string-equal name (buffer-name))
6095 (rename-buffer name t)))))
6096 ;; Push the current buffer onto the list.
6097 (when message-max-buffers
6098 (setq message-buffer-list
6099 (nconc message-buffer-list (list (current-buffer))))))
6101 (defun message-mail-user-agent ()
6103 ((not message-mail-user-agent) nil)
6104 ((eq message-mail-user-agent t) mail-user-agent)
6105 (t message-mail-user-agent))))
6106 (if (memq mua '(message-user-agent gnus-user-agent))
6110 (defun message-setup (headers &optional replybuffer actions
6111 continue switch-function)
6112 (let ((mua (message-mail-user-agent))
6113 subject to field yank-action)
6114 (if (not (and message-this-is-mail mua))
6115 (message-setup-1 headers replybuffer actions)
6117 (setq yank-action (list 'insert-buffer replybuffer)))
6118 (setq headers (copy-sequence headers))
6119 (setq field (assq 'Subject headers))
6121 (setq subject (cdr field))
6122 (setq headers (delq field headers)))
6123 (setq field (assq 'To headers))
6125 (setq to (cdr field))
6126 (setq headers (delq field headers)))
6127 (let ((mail-user-agent mua))
6128 (compose-mail to subject
6129 (mapcar (lambda (item)
6131 (format "%s" (car item))
6134 continue switch-function yank-action actions)))))
6136 (defun message-headers-to-generate (headers included-headers excluded-headers)
6137 "Return a list that includes all headers from HEADERS.
6138 If INCLUDED-HEADERS is a list, just include those headers. If it is
6139 t, include all headers. In any case, headers from EXCLUDED-HEADERS
6143 (dolist (header headers)
6144 (setq header-name (cond
6145 ((and (consp header)
6146 (eq (car header) 'optional))
6147 ;; On the form (optional . Header)
6150 ;; On the form (Header . function)
6155 (when (and (not (memq header-name excluded-headers))
6156 (or (eq included-headers t)
6157 (memq header-name included-headers)))
6158 (push header result)))
6161 (defun message-setup-1 (headers &optional replybuffer actions)
6162 (dolist (action actions)
6164 (add-to-list 'message-send-actions
6165 `(apply ',(car action) ',(cdr action)))))
6166 (setq message-reply-buffer replybuffer)
6167 (goto-char (point-min))
6168 ;; Insert all the headers.
6171 (alist message-header-format-alist))
6173 (unless (assq (caar h) message-header-format-alist)
6174 (push (list (caar h)) alist))
6178 (delete-region (point) (progn (forward-line -1) (point)))
6179 (when message-default-headers
6180 (insert message-default-headers)
6181 (or (bolp) (insert ?\n)))
6182 (insert mail-header-separator "\n")
6184 (when (message-news-p)
6185 (when message-default-news-headers
6186 (insert message-default-news-headers)
6187 (or (bolp) (insert ?\n)))
6188 (when message-generate-headers-first
6189 (message-generate-headers
6190 (message-headers-to-generate
6191 (append message-required-news-headers
6192 message-required-headers)
6193 message-generate-headers-first
6194 '(Lines Subject)))))
6195 (when (message-mail-p)
6196 (when message-default-mail-headers
6197 (insert message-default-mail-headers)
6198 (or (bolp) (insert ?\n)))
6199 (when message-generate-headers-first
6200 (message-generate-headers
6201 (message-headers-to-generate
6202 (append message-required-mail-headers
6203 message-required-headers)
6204 message-generate-headers-first
6205 '(Lines Subject)))))
6206 (run-hooks 'message-signature-setup-hook)
6207 (message-insert-signature)
6209 (message-narrow-to-headers)
6210 (run-hooks 'message-header-setup-hook))
6211 (set-buffer-modified-p nil)
6212 (setq buffer-undo-list nil)
6213 (when message-generate-hashcash
6214 ;; Generate hashcash headers for recipients already known
6215 (mail-add-payment-async))
6216 (run-hooks 'message-setup-hook)
6217 ;; Do this last to give it precedence over posting styles, etc.
6218 (when (message-mail-p)
6220 (message-narrow-to-headers)
6221 (if message-alternative-emails
6222 (message-use-alternative-email-as-from))))
6223 (message-position-point)
6226 (defun message-set-auto-save-file-name ()
6227 "Associate the message buffer with a file in the drafts directory."
6228 (when message-auto-save-directory
6229 (unless (file-directory-p
6230 (directory-file-name message-auto-save-directory))
6231 (make-directory message-auto-save-directory t))
6233 (setq message-draft-article
6234 (nndraft-request-associate-buffer "drafts"))
6235 (setq buffer-file-name (expand-file-name
6236 (if (memq system-type
6237 '(ms-dos ms-windows windows-nt
6238 cygwin cygwin32 win32 w32
6242 message-auto-save-directory))
6243 (setq buffer-auto-save-file-name (make-auto-save-file-name)))
6244 (clear-visited-file-modtime)
6245 (setq buffer-file-coding-system message-draft-coding-system)))
6247 (defun message-disassociate-draft ()
6248 "Disassociate the message buffer from the drafts directory."
6249 (when message-draft-article
6250 (nndraft-request-expire-articles
6251 (list message-draft-article) "nndraft:drafts" nil t)))
6253 (defun message-insert-headers ()
6254 "Generate the headers for the article."
6258 (message-narrow-to-headers)
6259 (when (message-news-p)
6260 (message-generate-headers
6263 (copy-sequence message-required-news-headers)))))
6264 (when (message-mail-p)
6265 (message-generate-headers
6268 (copy-sequence message-required-mail-headers))))))))
6273 ;;; Commands for interfacing with message
6277 (defun message-mail (&optional to subject
6278 other-headers continue switch-function
6279 yank-action send-actions)
6280 "Start editing a mail message to be sent.
6281 OTHER-HEADERS is an alist of header/value pairs. CONTINUE says whether
6282 to continue editing a message already being composed. SWITCH-FUNCTION
6283 is a function used to switch to and display the mail buffer."
6285 (let ((message-this-is-mail t) replybuffer)
6286 (unless (message-mail-user-agent)
6287 (message-pop-to-buffer
6288 ;; Search for the existing message buffer if `continue' is non-nil.
6289 (let ((message-generate-new-buffers
6290 (when (or (not continue)
6291 (eq message-generate-new-buffers 'standard)
6292 (functionp message-generate-new-buffers))
6293 message-generate-new-buffers)))
6294 (message-buffer-name "mail" to))
6296 ;; FIXME: message-mail should do something if YANK-ACTION is not
6298 (and (consp yank-action) (eq (car yank-action) 'insert-buffer)
6299 (setq replybuffer (nth 1 yank-action)))
6302 `((To . ,(or to "")) (Subject . ,(or subject "")))
6303 (when other-headers other-headers))
6304 replybuffer send-actions continue switch-function)
6305 ;; FIXME: Should return nil if failure.
6309 (defun message-news (&optional newsgroups subject)
6310 "Start editing a news article to be sent."
6312 (let ((message-this-is-news t))
6313 (message-pop-to-buffer (message-buffer-name "posting" nil newsgroups))
6314 (message-setup `((Newsgroups . ,(or newsgroups ""))
6315 (Subject . ,(or subject ""))))))
6317 (defun message-alter-recipients-discard-bogus-full-name (addrcell)
6318 "Discard mail address in full names.
6319 When the full name in reply headers contains the mail
6320 address (e.g. \"foo@bar <foo@bar>\"), discard full name.
6321 ADDRCELL is a cons cell where the car is the mail address and the
6322 cdr is the complete address (full name and mail address)."
6323 (if (string-match (concat (regexp-quote (car addrcell)) ".*"
6324 (regexp-quote (car addrcell)))
6326 (cons (car addrcell) (car addrcell))
6329 (defcustom message-alter-recipients-function nil
6330 "Function called to allow alteration of reply header structures.
6331 It is called in `message-get-reply-headers' for each recipient.
6332 The function is called with one parameter, a cons cell ..."
6333 :type '(choice (const :tag "None" nil)
6334 (const :tag "Discard bogus full name"
6335 message-alter-recipients-discard-bogus-full-name)
6337 :version "23.1" ;; No Gnus
6338 :group 'message-headers)
6340 (defun message-get-reply-headers (wide &optional to-address address-headers)
6341 (let (follow-to mct never-mct to cc author mft recipients extra)
6342 ;; Find all relevant headers we need.
6344 (message-narrow-to-headers-or-head)
6345 ;; Gmane renames "To". Look at "Original-To", too, if it is present in
6346 ;; message-header-synonyms.
6347 (setq to (or (message-fetch-field "to")
6348 (and (loop for synonym in message-header-synonyms
6349 when (memq 'Original-To synonym)
6351 (message-fetch-field "original-to")))
6352 cc (message-fetch-field "cc")
6353 extra (when message-extra-wide-headers
6354 (mapconcat 'identity
6355 (mapcar 'message-fetch-field
6356 message-extra-wide-headers)
6358 mct (message-fetch-field "mail-copies-to")
6359 author (or (message-fetch-field "mail-reply-to")
6360 (message-fetch-field "reply-to")
6361 (message-fetch-field "from")
6363 mft (and message-use-mail-followup-to
6364 (message-fetch-field "mail-followup-to"))))
6366 ;; Handle special values of Mail-Copies-To.
6368 (cond ((or (equal (downcase mct) "never")
6369 (equal (downcase mct) "nobody"))
6372 ((or (equal (downcase mct) "always")
6373 (equal (downcase mct) "poster"))
6374 (setq mct author))))
6377 ;; Build (textual) list of new recipient addresses.
6380 (setq recipients (concat ", " author)))
6382 (dolist (header address-headers)
6383 (let ((value (message-fetch-field header)))
6385 (setq recipients (concat recipients ", " value))))))
6387 (string-match "[^ \t,]" mft)
6388 (or (not (eq message-use-mail-followup-to 'ask))
6389 (message-y-or-n-p "Obey Mail-Followup-To? " t "\
6390 You should normally obey the Mail-Followup-To: header. In this
6391 article, it has the value of
6395 which directs your response to " (if (string-match "," mft)
6396 "the specified addresses"
6397 "that address only") ".
6399 Most commonly, Mail-Followup-To is used by a mailing list poster to
6400 express that responses should be sent to just the list, and not the
6403 If a message is posted to several mailing lists, Mail-Followup-To may
6404 also be used to direct the following discussion to one list only,
6405 because discussions that are spread over several lists tend to be
6406 fragmented and very difficult to follow.
6408 Also, some source/announcement lists are not intended for discussion;
6409 responses here are directed to other addresses.
6411 You may customize the variable `message-use-mail-followup-to', if you
6412 want to get rid of this query permanently.")))
6413 (setq recipients (concat ", " mft)))
6415 (setq recipients (concat ", " to-address))
6416 ;; If the author explicitly asked for a copy, we don't deny it to them.
6417 (if mct (setq recipients (concat recipients ", " mct))))
6419 (setq recipients (if never-mct "" (concat ", " author)))
6420 (if to (setq recipients (concat recipients ", " to)))
6421 (if cc (setq recipients (concat recipients ", " cc)))
6422 (if extra (setq recipients (concat recipients ", " extra)))
6423 (if mct (setq recipients (concat recipients ", " mct)))))
6424 (if (>= (length recipients) 2)
6425 ;; Strip the leading ", ".
6426 (setq recipients (substring recipients 2)))
6427 ;; Squeeze whitespace.
6428 (while (string-match "[ \t][ \t]+" recipients)
6429 (setq recipients (replace-match " " t t recipients)))
6430 ;; Remove addresses that match `rmail-dont-reply-to-names'.
6431 (let ((rmail-dont-reply-to-names (message-dont-reply-to-names)))
6432 (setq recipients (rmail-dont-reply-to recipients)))
6433 ;; Perhaps "Mail-Copies-To: never" removed the only address?
6434 (if (string-equal recipients "")
6435 (setq recipients author))
6436 ;; Convert string to a list of (("foo@bar" . "Name <Foo@BAR>") ...).
6440 (if message-alter-recipients-function
6441 (funcall message-alter-recipients-function
6442 (cons (downcase (mail-strip-quoted-names addr))
6444 (cons (downcase (mail-strip-quoted-names addr)) addr)))
6445 (message-tokenize-header recipients)))
6446 ;; Remove first duplicates. (Why not all duplicates? Is this a bug?)
6447 (let ((s recipients))
6449 (setq recipients (delq (assoc (car (pop s)) s) recipients))))
6451 ;; Remove hierarchical lists that are contained within each other,
6452 ;; if message-hierarchical-addresses is defined.
6453 (when message-hierarchical-addresses
6454 (let ((plain-addrs (mapcar 'car recipients))
6457 (setq subaddrs (assoc (car plain-addrs)
6458 message-hierarchical-addresses)
6459 plain-addrs (cdr plain-addrs))
6461 (setq subaddrs (cdr subaddrs))
6463 (setq recip (assoc (car subaddrs) recipients)
6464 subaddrs (cdr subaddrs))
6466 (setq recipients (delq recip recipients))))))))
6468 ;; Build the header alist. Allow the user to be asked whether
6469 ;; or not to reply to all recipients in a wide reply.
6470 (setq follow-to (list (cons 'To (cdr (pop recipients)))))
6471 (when (and recipients
6472 (or (not message-wide-reply-confirm-recipients)
6473 (y-or-n-p "Reply to all recipients? ")))
6474 (setq recipients (mapconcat
6475 (lambda (addr) (cdr addr)) recipients ", "))
6476 (if (string-match "^ +" recipients)
6477 (setq recipients (substring recipients (match-end 0))))
6478 (push (cons 'Cc recipients) follow-to)))
6481 (defcustom message-simplify-subject-functions
6482 '(message-strip-list-identifiers
6483 message-strip-subject-re
6484 message-strip-subject-trailing-was
6485 message-strip-subject-encoded-words)
6486 "List of functions taking a string argument that simplify subjects.
6487 The functions are applied when replying to a message.
6489 Useful functions to put in this list include:
6490 `message-strip-list-identifiers', `message-strip-subject-re',
6491 `message-strip-subject-trailing-was', and
6492 `message-strip-subject-encoded-words'."
6493 :version "22.1" ;; Gnus 5.10.9
6494 :group 'message-various
6495 :type '(repeat function))
6497 (defun message-simplify-subject (subject &optional functions)
6498 "Return simplified SUBJECT."
6501 (setq functions message-simplify-subject-functions))
6502 (when (and (memq 'message-strip-list-identifiers functions)
6503 gnus-list-identifiers)
6504 (setq subject (message-strip-list-identifiers subject)))
6505 (when (memq 'message-strip-subject-re functions)
6506 (setq subject (concat "Re: " (message-strip-subject-re subject))))
6507 (when (and (memq 'message-strip-subject-trailing-was functions)
6508 message-subject-trailing-was-query)
6509 (setq subject (message-strip-subject-trailing-was subject)))
6510 (when (memq 'message-strip-subject-encoded-words functions)
6511 (setq subject (message-strip-subject-encoded-words subject)))
6515 (defun message-reply (&optional to-address wide)
6516 "Start editing a reply to the article in the current buffer."
6518 (require 'gnus-sum) ; for gnus-list-identifiers
6519 (let ((cur (current-buffer))
6520 from subject date reply-to to cc
6521 references message-id follow-to
6522 (inhibit-point-motion-hooks t)
6523 (message-this-is-mail t)
6526 (message-narrow-to-head-1)
6527 ;; Allow customizations to have their say.
6529 ;; This is a regular reply.
6530 (when (functionp message-reply-to-function)
6532 (setq follow-to (funcall message-reply-to-function))))
6533 ;; This is a followup.
6534 (when (functionp message-wide-reply-to-function)
6537 (funcall message-wide-reply-to-function)))))
6538 (setq message-id (message-fetch-field "message-id" t)
6539 references (message-fetch-field "references")
6540 date (message-fetch-field "date")
6541 from (or (message-fetch-field "from") "nobody")
6542 subject (or (message-fetch-field "subject") "none"))
6544 ;; Strip list identifiers, "Re: ", and "was:"
6545 (setq subject (message-simplify-subject subject))
6547 (when (and (setq gnus-warning (message-fetch-field "gnus-warning"))
6548 (string-match "<[^>]+>" gnus-warning))
6549 (setq message-id (match-string 0 gnus-warning)))
6552 (setq follow-to (message-get-reply-headers wide to-address))))
6554 (unless (message-mail-user-agent)
6555 (message-pop-to-buffer
6556 (message-buffer-name
6557 (if wide "wide reply" "reply") from
6558 (if wide to-address nil))))
6560 (setq message-reply-headers
6561 (vector 0 subject from date message-id references 0 0 ""))
6564 `((Subject . ,subject)
6569 (defun message-wide-reply (&optional to-address)
6570 "Make a \"wide\" reply to the message in the current buffer."
6572 (message-reply to-address t))
6575 (defun message-followup (&optional to-newsgroups)
6576 "Follow up to the message in the current buffer.
6577 If TO-NEWSGROUPS, use that as the new Newsgroups line."
6579 (require 'gnus-sum) ; for gnus-list-identifiers
6580 (let ((cur (current-buffer))
6581 from subject date reply-to mrt mct
6582 references message-id follow-to
6583 (inhibit-point-motion-hooks t)
6584 (message-this-is-news t)
6585 followup-to distribution newsgroups gnus-warning posted-to)
6588 (goto-char (point-min))
6589 (if (search-forward "\n\n" nil t)
6592 (when (functionp message-followup-to-function)
6594 (funcall message-followup-to-function)))
6595 (setq from (message-fetch-field "from")
6596 date (message-fetch-field "date")
6597 subject (or (message-fetch-field "subject") "none")
6598 references (message-fetch-field "references")
6599 message-id (message-fetch-field "message-id" t)
6600 followup-to (message-fetch-field "followup-to")
6601 newsgroups (message-fetch-field "newsgroups")
6602 posted-to (message-fetch-field "posted-to")
6603 reply-to (message-fetch-field "reply-to")
6604 mrt (message-fetch-field "mail-reply-to")
6605 distribution (message-fetch-field "distribution")
6606 mct (message-fetch-field "mail-copies-to"))
6607 (when (and (setq gnus-warning (message-fetch-field "gnus-warning"))
6608 (string-match "<[^>]+>" gnus-warning))
6609 (setq message-id (match-string 0 gnus-warning)))
6610 ;; Remove bogus distribution.
6611 (when (and (stringp distribution)
6612 (let ((case-fold-search t))
6613 (string-match "world" distribution)))
6614 (setq distribution nil))
6615 ;; Strip list identifiers, "Re: ", and "was:"
6616 (setq subject (message-simplify-subject subject))
6619 (message-pop-to-buffer (message-buffer-name "followup" from newsgroups))
6621 (setq message-reply-headers
6622 (vector 0 subject from date message-id references 0 0 ""))
6625 `((Subject . ,subject)
6628 (list (cons 'Newsgroups to-newsgroups)))
6629 (follow-to follow-to)
6630 ((and followup-to message-use-followup-to)
6633 ((equal (downcase followup-to) "poster")
6634 (if (or (eq message-use-followup-to 'use)
6635 (message-y-or-n-p "Obey Followup-To: poster? " t "\
6636 You should normally obey the Followup-To: header.
6638 `Followup-To: poster' sends your response via e-mail instead of news.
6640 A typical situation where `Followup-To: poster' is used is when the poster
6641 does not read the newsgroup, so he wouldn't see any replies sent to it.
6643 You may customize the variable `message-use-followup-to', if you
6644 want to get rid of this query permanently."))
6646 (setq message-this-is-news nil)
6647 (cons 'To (or mrt reply-to from "")))
6648 (cons 'Newsgroups newsgroups)))
6650 (if (or (equal followup-to newsgroups)
6651 (not (eq message-use-followup-to 'ask))
6653 (concat "Obey Followup-To: " followup-to "? ") t "\
6654 You should normally obey the Followup-To: header.
6656 `Followup-To: " followup-to "'
6657 directs your response to " (if (string-match "," followup-to)
6658 "the specified newsgroups"
6659 "that newsgroup only") ".
6661 If a message is posted to several newsgroups, Followup-To is often
6662 used to direct the following discussion to one newsgroup only,
6663 because discussions that are spread over several newsgroup tend to
6664 be fragmented and very difficult to follow.
6666 Also, some source/announcement newsgroups are not intended for discussion;
6667 responses here are directed to other newsgroups.
6669 You may customize the variable `message-use-followup-to', if you
6670 want to get rid of this query permanently."))
6671 (cons 'Newsgroups followup-to)
6672 (cons 'Newsgroups newsgroups))))))
6674 `((Newsgroups . ,posted-to)))
6676 `((Newsgroups . ,newsgroups))))
6677 ,@(and distribution (list (cons 'Distribution distribution)))
6679 (not (or (equal (downcase mct) "never")
6680 (equal (downcase mct) "nobody"))))
6681 (list (cons 'Cc (if (or (equal (downcase mct) "always")
6682 (equal (downcase mct) "poster"))
6683 (or mrt reply-to from "")
6688 (defun message-is-yours-p ()
6689 "Non-nil means current article is yours.
6690 If you have added 'cancel-messages to `message-shoot-gnksa-feet', all articles
6691 are yours except those that have Cancel-Lock header not belonging to you.
6692 Instead of shooting GNKSA feet, you should modify `message-alternative-emails'
6693 regexp to match all of yours addresses."
6694 ;; Canlock-logic as suggested by Per Abrahamsen
6695 ;; <abraham@dina.kvl.dk>
6697 ;; IF article has cancel-lock THEN
6698 ;; IF we can verify it THEN
6701 ;; error: cancellock: article is not yours
6703 ;; Use old rules, comparing sender...
6706 (message-narrow-to-head-1)
6707 (if (message-fetch-field "Cancel-Lock")
6708 (if (null (canlock-verify))
6710 (error "Failed to verify Cancel-lock: This article is not yours"))
6713 (message-gnksa-enable-p 'cancel-messages)
6714 (and (setq sender (message-fetch-field "sender"))
6715 (string-equal (downcase sender)
6716 (downcase (message-make-sender))))
6717 ;; Email address in From field equals to our address
6718 (and (setq from (message-fetch-field "from"))
6720 (downcase (car (mail-header-parse-address from)))
6721 (downcase (car (mail-header-parse-address
6722 (message-make-from))))))
6723 ;; Email address in From field matches
6724 ;; 'message-alternative-emails' regexp
6726 message-alternative-emails
6728 message-alternative-emails
6729 (car (mail-header-parse-address from))))))))))
6732 (defun message-cancel-news (&optional arg)
6733 "Cancel an article you posted.
6734 If ARG, allow editing of the cancellation message."
6736 (unless (message-news-p)
6737 (error "This is not a news article; canceling is impossible"))
6738 (let (from newsgroups message-id distribution buf)
6740 ;; Get header info from original article.
6742 (message-narrow-to-head-1)
6743 (setq from (message-fetch-field "from")
6744 newsgroups (message-fetch-field "newsgroups")
6745 message-id (message-fetch-field "message-id" t)
6746 distribution (message-fetch-field "distribution")))
6747 ;; Make sure that this article was written by the user.
6748 (unless (message-is-yours-p)
6749 (error "This article is not yours"))
6750 (when (yes-or-no-p "Do you really want to cancel this article? ")
6751 ;; Make control message.
6754 (setq buf (set-buffer (get-buffer-create " *message cancel*"))))
6756 (insert "Newsgroups: " newsgroups "\n"
6758 "Subject: cmsg cancel " message-id "\n"
6759 "Control: cancel " message-id "\n"
6761 (concat "Distribution: " distribution "\n")
6763 mail-header-separator "\n"
6764 message-cancel-message)
6765 (run-hooks 'message-cancel-hook)
6767 (message "Canceling your article...")
6768 (if (let ((message-syntax-checks
6769 'dont-check-for-anything-just-trust-me))
6770 (funcall message-send-news-function))
6771 (message "Canceling your article...done"))
6772 (kill-buffer buf))))))
6775 (defun message-supersede ()
6776 "Start composing a message to supersede the current message.
6777 This is done simply by taking the old article and adding a Supersedes
6778 header line with the old Message-ID."
6780 (let ((cur (current-buffer)))
6781 ;; Check whether the user owns the article that is to be superseded.
6782 (unless (message-is-yours-p)
6783 (error "This article is not yours"))
6784 ;; Get a normal message buffer.
6785 (message-pop-to-buffer (message-buffer-name "supersede"))
6786 (insert-buffer-substring cur)
6788 (message-narrow-to-head-1)
6789 ;; Remove unwanted headers.
6790 (when message-ignored-supersedes-headers
6791 (message-remove-header message-ignored-supersedes-headers t))
6792 (goto-char (point-min))
6793 (if (not (re-search-forward "^Message-ID: " nil t))
6794 (error "No Message-ID in this article")
6795 (replace-match "Supersedes: " t t))
6796 (goto-char (point-max))
6797 (insert mail-header-separator)
6802 (defun message-recover ()
6803 "Reread contents of current buffer from its last auto-save file."
6805 (let ((file-name (make-auto-save-file-name)))
6806 (cond ((save-window-excursion
6807 (if (not (eq system-type 'vax-vms))
6808 (with-output-to-temp-buffer "*Directory*"
6809 (with-current-buffer standard-output
6810 (fundamental-mode)) ; for Emacs 20.4+
6811 (buffer-disable-undo standard-output)
6812 (let ((default-directory "/"))
6814 "ls" nil standard-output nil "-l" file-name))))
6815 (yes-or-no-p (format "Recover auto save file %s? " file-name)))
6816 (let ((buffer-read-only nil))
6818 (insert-file-contents file-name nil)))
6819 (t (error "message-recover cancelled")))))
6821 ;;; Washing Subject:
6823 (defun message-wash-subject (subject)
6824 "Remove junk like \"Re:\", \"(fwd)\", etc. added to subject string SUBJECT.
6825 Previous forwarders, replyers, etc. may add it."
6828 (goto-char (point-min))
6829 ;; strip Re/Fwd stuff off the beginning
6830 (while (re-search-forward
6831 "\\([Rr][Ee]:\\|[Ff][Ww][Dd]\\(\\[[0-9]*\\]\\)?:\\|[Ff][Ww]:\\)" nil t)
6834 ;; and gnus-style forwards [foo@bar.com] subject
6835 (goto-char (point-min))
6836 (while (re-search-forward "\\[[^ \t]*\\(@\\|\\.\\)[^ \t]*\\]" nil t)
6840 (goto-char (point-max))
6841 (while (re-search-backward "([Ff][Ww][Dd])" nil t)
6844 ;; and finally, any whitespace that was left-over
6845 (goto-char (point-min))
6846 (while (re-search-forward "^[ \t]+" nil t)
6848 (goto-char (point-max))
6849 (while (re-search-backward "[ \t]+$" nil t)
6854 ;;; Forwarding messages.
6856 (defvar message-forward-decoded-p nil
6857 "Non-nil means the original message is decoded.")
6859 (defun message-forward-subject-name-subject (subject)
6860 "Generate a SUBJECT for a forwarded message.
6861 The form is: [Source] Subject, where if the original message was mail,
6862 Source is the name of the sender, and if the original message was
6863 news, Source is the list of newsgroups is was posted to."
6864 (let* ((group (message-fetch-field "newsgroups"))
6865 (from (message-fetch-field "from"))
6868 (gnus-group-decoded-name group)
6870 (car (gnus-extract-address-components from))
6871 (cadr (gnus-extract-address-components from))))
6874 (if message-forward-decoded-p
6876 (mail-decode-encoded-word-string prefix))
6879 (defun message-forward-subject-author-subject (subject)
6880 "Generate a SUBJECT for a forwarded message.
6881 The form is: [Source] Subject, where if the original message was mail,
6882 Source is the sender, and if the original message was news, Source is
6883 the list of newsgroups is was posted to."
6884 (let* ((group (message-fetch-field "newsgroups"))
6887 (gnus-group-decoded-name group)
6888 (or (message-fetch-field "from")
6891 (if message-forward-decoded-p
6893 (mail-decode-encoded-word-string prefix))
6896 (defun message-forward-subject-fwd (subject)
6897 "Generate a SUBJECT for a forwarded message.
6898 The form is: Fwd: Subject, where Subject is the original subject of
6900 (if (string-match "^Fwd: " subject)
6902 (concat "Fwd: " subject)))
6904 (defun message-make-forward-subject ()
6905 "Return a Subject header suitable for the message in the current buffer."
6908 (message-narrow-to-head-1)
6909 (let ((funcs message-make-forward-subject-function)
6910 (subject (message-fetch-field "Subject")))
6913 (if message-forward-decoded-p
6915 (mail-decode-encoded-word-string subject))
6917 (when message-wash-forwarded-subjects
6918 (setq subject (message-wash-subject subject)))
6919 ;; Make sure funcs is a list.
6922 (setq funcs (list funcs)))
6923 ;; Apply funcs in order, passing subject generated by previous
6924 ;; func to the next one.
6925 (dolist (func funcs)
6926 (when (functionp func)
6927 (setq subject (funcall func subject))))
6930 (defvar gnus-article-decoded-p)
6934 (defun message-forward (&optional news digest)
6935 "Forward the current message via mail.
6936 Optional NEWS will use news to forward instead of mail.
6937 Optional DIGEST will use digest to forward."
6939 (let* ((cur (current-buffer))
6940 (message-forward-decoded-p
6941 (if (local-variable-p 'gnus-article-decoded-p (current-buffer))
6942 gnus-article-decoded-p ;; In an article buffer.
6943 message-forward-decoded-p))
6944 (subject (message-make-forward-subject)))
6946 (message-news nil subject)
6947 (message-mail nil subject))
6948 (message-forward-make-body cur digest)))
6950 (defun message-forward-make-body-plain (forward-buffer)
6952 "\n-------------------- Start of forwarded message --------------------\n")
6953 (let ((b (point)) e)
6956 (mm-disable-multibyte)
6958 (with-current-buffer forward-buffer
6959 (mm-with-unibyte-current-buffer (buffer-string))))
6960 (mm-enable-multibyte)
6962 (goto-char (point-min))
6963 (when (looking-at "From ")
6964 (replace-match "X-From-Line: "))
6968 "\n-------------------- End of forwarded message --------------------\n")
6969 (message-remove-ignored-headers b e)))
6971 (defun message-remove-ignored-headers (b e)
6972 (when message-forward-ignored-headers
6974 (narrow-to-region b e)
6976 (narrow-to-region (point)
6977 (or (search-forward "\n\n" nil t) (point)))
6978 (let ((ignored (if (stringp message-forward-ignored-headers)
6979 (list message-forward-ignored-headers)
6980 message-forward-ignored-headers)))
6981 (dolist (elem ignored)
6982 (message-remove-header elem t))))))
6984 (defun message-forward-make-body-mime (forward-buffer)
6986 (insert "\n\n<#part type=message/rfc822 disposition=inline raw=t>\n")
6988 (narrow-to-region (point) (point))
6989 (mml-insert-buffer forward-buffer)
6990 (goto-char (point-min))
6991 (when (looking-at "From ")
6992 (replace-match "X-From-Line: "))
6993 (goto-char (point-max)))
6994 (insert "<#/part>\n")
6995 ;; Consider there is no illegible text.
6996 (add-text-properties
6998 `(no-illegible-text t rear-nonsticky t start-open t))))
7000 (defun message-forward-make-body-mml (forward-buffer)
7001 (insert "\n\n<#mml type=message/rfc822 disposition=inline>\n")
7002 (let ((b (point)) e)
7003 (if (not message-forward-decoded-p)
7006 (mm-disable-multibyte)
7008 (with-current-buffer forward-buffer
7009 (mm-with-unibyte-current-buffer (buffer-string))))
7010 (mm-enable-multibyte)
7012 (goto-char (point-min))
7013 (when (looking-at "From ")
7014 (replace-match "X-From-Line: "))
7017 (narrow-to-region (point) (point))
7018 (mml-insert-buffer forward-buffer)
7019 (goto-char (point-min))
7020 (when (looking-at "From ")
7021 (replace-match "X-From-Line: "))
7022 (goto-char (point-max))))
7024 (insert "<#/mml>\n")
7025 (when (and (not message-forward-decoded-p)
7026 message-forward-ignored-headers)
7027 (message-remove-ignored-headers b e))))
7029 (defun message-forward-make-body-digest-plain (forward-buffer)
7031 "\n-------------------- Start of forwarded message --------------------\n")
7032 (let ((b (point)) e)
7033 (mml-insert-buffer forward-buffer)
7036 "\n-------------------- End of forwarded message --------------------\n")))
7038 (defun message-forward-make-body-digest-mime (forward-buffer)
7039 (insert "\n<#multipart type=digest>\n")
7040 (let ((b (point)) e)
7041 (insert-buffer-substring forward-buffer)
7043 (insert "<#/multipart>\n")
7045 (narrow-to-region b e)
7047 (narrow-to-region (point)
7048 (or (search-forward "\n\n" nil t) (point)))
7049 (delete-region (point-min) (point-max)))))
7051 (defun message-forward-make-body-digest (forward-buffer)
7052 (if message-forward-as-mime
7053 (message-forward-make-body-digest-mime forward-buffer)
7054 (message-forward-make-body-digest-plain forward-buffer)))
7057 (autoload 'mm-uu-dissect-text-parts "mm-uu")
7058 (autoload 'mm-uu-dissect "mm-uu"))
7060 (defun message-signed-or-encrypted-p (&optional dont-emulate-mime handles)
7061 "Say whether the current buffer contains signed or encrypted message.
7062 If DONT-EMULATE-MIME is nil, this function does the MIME emulation on
7063 messages that don't conform to PGP/MIME described in RFC2015. HANDLES
7064 is for the internal use."
7066 (let ((mm-decrypt-option 'never)
7067 (mm-verify-option 'never))
7068 (if (setq handles (mm-dissect-buffer nil t))
7069 (unless dont-emulate-mime
7070 (mm-uu-dissect-text-parts handles))
7071 (unless dont-emulate-mime
7072 (setq handles (mm-uu-dissect))))))
7073 ;; Check text/plain message in which there is a signed or encrypted
7074 ;; body that has been encoded by B or Q.
7075 (unless (or handles dont-emulate-mime)
7076 (let ((cur (current-buffer))
7077 (mm-decrypt-option 'never)
7078 (mm-verify-option 'never))
7080 (insert-buffer-substring cur)
7081 (when (setq handles (mm-dissect-buffer t t))
7083 (bufferp (car handles))
7084 (mm-destroy-parts handles))
7085 (equal (mm-handle-media-type handles) "text/plain"))
7087 (mm-decode-content-transfer-encoding
7088 (mm-handle-encoding handles))
7089 (setq handles (mm-uu-dissect)))
7090 (setq handles nil))))))
7094 (dolist (handle (if (stringp (car handles))
7095 (if (member (car handles)
7096 '("multipart/signed"
7097 "multipart/encrypted"))
7101 (if (stringp (car handle))
7102 (when (message-signed-or-encrypted-p dont-emulate-mime handle)
7104 (when (and (bufferp (car handle))
7105 (equal (mm-handle-media-type handle)
7107 (with-current-buffer (mm-handle-buffer handle)
7108 (when (message-signed-or-encrypted-p dont-emulate-mime)
7109 (throw 'found t)))))))
7110 (mm-destroy-parts handles))))
7113 (defun message-forward-make-body (forward-buffer &optional digest)
7114 ;; Put point where we want it before inserting the forwarded
7116 (if message-forward-before-signature
7118 (goto-char (point-max)))
7120 (message-forward-make-body-digest forward-buffer)
7121 (if message-forward-as-mime
7122 (if (and message-forward-show-mml
7123 (not (and (eq message-forward-show-mml 'best)
7124 ;; Use the raw form in the body if it contains
7125 ;; signed or encrypted message so as not to be
7126 ;; destroyed by re-encoding.
7127 (with-current-buffer forward-buffer
7129 (message-signed-or-encrypted-p)
7131 (message-forward-make-body-mml forward-buffer)
7132 (message-forward-make-body-mime forward-buffer))
7133 (message-forward-make-body-plain forward-buffer)))
7134 (message-position-point))
7137 (defun message-forward-rmail-make-body (forward-buffer)
7138 (save-window-excursion
7139 (set-buffer forward-buffer)
7140 (if (rmail-msg-is-pruned)
7141 (rmail-msg-restore-non-pruned-header)))
7142 (message-forward-make-body forward-buffer))
7144 ;; Fixme: Should have defcustom.
7146 (defun message-insinuate-rmail ()
7147 "Let RMAIL use message to forward."
7149 (setq rmail-enable-mime-composing t)
7150 (setq rmail-insert-mime-forwarded-message-function
7151 'message-forward-rmail-make-body))
7154 (defun message-resend (address)
7155 "Resend the current article to ADDRESS."
7157 (list (message-read-from-minibuffer "Resend message to: ")))
7158 (message "Resending message to %s..." address)
7160 (let ((cur (current-buffer))
7162 ;; We first set up a normal mail buffer.
7163 (unless (message-mail-user-agent)
7164 (set-buffer (get-buffer-create " *message resend*"))
7166 (let ((message-this-is-mail t)
7167 message-generate-hashcash
7169 (message-setup `((To . ,address))))
7170 ;; Insert our usual headers.
7171 (message-generate-headers '(From Date To Message-ID))
7172 (message-narrow-to-headers)
7173 ;; Remove X-Draft-From header etc.
7174 (message-remove-header message-ignored-mail-headers t)
7175 ;; Rename them all to "Resent-*".
7176 (goto-char (point-min))
7177 (while (re-search-forward "^[A-Za-z]" nil t)
7182 (delete-region (point) (point-max))
7184 ;; Insert the message to be resent.
7185 (insert-buffer-substring cur)
7186 (goto-char (point-min))
7187 (search-forward "\n\n")
7190 (narrow-to-region beg (point))
7191 (message-remove-header message-ignored-resent-headers t)
7192 (goto-char (point-max)))
7193 (insert mail-header-separator)
7194 ;; Rename all old ("Also-")Resent headers.
7195 (while (re-search-backward "^\\(Also-\\)*Resent-" beg t)
7198 ;; Quote any "From " lines at the beginning.
7200 (when (looking-at "From ")
7201 (replace-match "X-From-Line: "))
7203 (let ((message-inhibit-body-encoding t)
7204 message-required-mail-headers
7205 message-generate-hashcash
7206 rfc2047-encode-encoded-words)
7207 (message-send-mail))
7208 (kill-buffer (current-buffer)))
7209 (message "Resending message to %s...done" address)))
7212 (defun message-bounce ()
7213 "Re-mail the current message.
7214 This only makes sense if the current message is a bounce message that
7215 contains some mail you have written which has been bounced back to
7218 (let ((handles (mm-dissect-buffer t))
7220 (message-pop-to-buffer (message-buffer-name "bounce"))
7221 (if (stringp (car handles))
7222 ;; This is a MIME bounce.
7223 (mm-insert-part (car (last handles)))
7224 ;; This is a non-MIME bounce, so we try to remove things
7226 (mm-insert-part handles)
7228 (goto-char (point-min))
7229 (re-search-forward "\n\n+" nil t)
7230 (setq boundary (point))
7231 ;; We remove everything before the bounced mail.
7232 (if (or (re-search-forward message-unsent-separator nil t)
7234 (search-forward "\n\n" nil 'move)
7235 (re-search-backward "^Return-Path:.*\n" boundary t)))
7238 (delete-region (point-min)
7239 (if (re-search-forward "^[^ \n\t]+:" nil t)
7242 (goto-char boundary)
7243 (when (re-search-backward "^.?From .*\n" nil t)
7244 (delete-region (match-beginning 0) (match-end 0)))))
7247 (message-narrow-to-head-1)
7248 (message-remove-header message-ignored-bounced-headers t)
7249 (goto-char (point-max))
7250 (insert mail-header-separator))
7251 (message-position-point)))
7254 ;;; Interactive entry points for new message buffers.
7258 (defun message-mail-other-window (&optional to subject)
7259 "Like `message-mail' command, but display mail buffer in another window."
7261 (unless (message-mail-user-agent)
7262 (let ((pop-up-windows t)
7263 (special-display-buffer-names nil)
7264 (special-display-regexps nil)
7265 (same-window-buffer-names nil)
7266 (same-window-regexps nil))
7267 (message-pop-to-buffer (message-buffer-name "mail" to))))
7268 (let ((message-this-is-mail t))
7269 (message-setup `((To . ,(or to "")) (Subject . ,(or subject "")))
7270 nil nil nil 'switch-to-buffer-other-window)))
7273 (defun message-mail-other-frame (&optional to subject)
7274 "Like `message-mail' command, but display mail buffer in another frame."
7276 (unless (message-mail-user-agent)
7277 (let ((pop-up-frames t)
7278 (special-display-buffer-names nil)
7279 (special-display-regexps nil)
7280 (same-window-buffer-names nil)
7281 (same-window-regexps nil))
7282 (message-pop-to-buffer (message-buffer-name "mail" to))))
7283 (let ((message-this-is-mail t))
7284 (message-setup `((To . ,(or to "")) (Subject . ,(or subject "")))
7285 nil nil nil 'switch-to-buffer-other-frame)))
7288 (defun message-news-other-window (&optional newsgroups subject)
7289 "Start editing a news article to be sent."
7291 (let ((pop-up-windows t)
7292 (special-display-buffer-names nil)
7293 (special-display-regexps nil)
7294 (same-window-buffer-names nil)
7295 (same-window-regexps nil))
7296 (message-pop-to-buffer (message-buffer-name "posting" nil newsgroups)))
7297 (let ((message-this-is-news t))
7298 (message-setup `((Newsgroups . ,(or newsgroups ""))
7299 (Subject . ,(or subject ""))))))
7302 (defun message-news-other-frame (&optional newsgroups subject)
7303 "Start editing a news article to be sent."
7305 (let ((pop-up-frames t)
7306 (special-display-buffer-names nil)
7307 (special-display-regexps nil)
7308 (same-window-buffer-names nil)
7309 (same-window-regexps nil))
7310 (message-pop-to-buffer (message-buffer-name "posting" nil newsgroups)))
7311 (let ((message-this-is-news t))
7312 (message-setup `((Newsgroups . ,(or newsgroups ""))
7313 (Subject . ,(or subject ""))))))
7317 ;; This code should be moved to underline.el (from which it is stolen).
7320 (defun message-bold-region (start end)
7321 "Bold all nonblank characters in the region.
7322 Works by overstriking characters.
7323 Called from program, takes two arguments START and END
7324 which specify the range to operate on."
7327 (let ((end1 (make-marker)))
7328 (move-marker end1 (max start end))
7329 (goto-char (min start end))
7330 (while (< (point) end1)
7331 (or (looking-at "[_\^@- ]")
7332 (insert (char-after) "\b"))
7333 (forward-char 1)))))
7336 (defun message-unbold-region (start end)
7337 "Remove all boldness (overstruck characters) in the region.
7338 Called from program, takes two arguments START and END
7339 which specify the range to operate on."
7342 (let ((end1 (make-marker)))
7343 (move-marker end1 (max start end))
7344 (goto-char (min start end))
7345 (while (search-forward "\b" end1 t)
7346 (if (eq (char-after) (char-after (- (point) 2)))
7347 (delete-char -2))))))
7349 (defun message-exchange-point-and-mark ()
7350 "Exchange point and mark, but don't activate region if it was inactive."
7352 (message-mark-active-p)
7353 (exchange-point-and-mark))
7354 (setq mark-active nil)))
7356 (defalias 'message-make-overlay 'make-overlay)
7357 (defalias 'message-delete-overlay 'delete-overlay)
7358 (defalias 'message-overlay-put 'overlay-put)
7359 (defun message-kill-all-overlays ()
7360 (if (featurep 'xemacs)
7361 (map-extents (lambda (extent ignore) (delete-extent extent)))
7362 (mapcar #'delete-overlay (overlays-in (point-min) (point-max)))))
7364 ;; Support for toolbar
7365 (defvar tool-bar-mode)
7367 ;; Note: The :set function in the `message-tool-bar*' variables will only
7368 ;; affect _new_ message buffers. We might add a function that walks thru all
7369 ;; message-mode buffers and force the update.
7370 (defun message-tool-bar-update (&optional symbol value)
7371 "Update message mode toolbar.
7372 Setter function for custom variables."
7373 (setq-default message-tool-bar-map nil)
7375 ;; When used as ":set" function:
7376 (set-default symbol value)))
7378 (defcustom message-tool-bar (if (eq gmm-tool-bar-style 'gnome)
7379 'message-tool-bar-gnome
7380 'message-tool-bar-retro)
7381 "Specifies the message mode tool bar.
7383 It can be either a list or a symbol refering to a list. See
7384 `gmm-tool-bar-from-list' for the format of the list. The
7385 default key map is `message-mode-map'.
7387 Pre-defined symbols include `message-tool-bar-gnome' and
7388 `message-tool-bar-retro'."
7389 :type '(repeat gmm-tool-bar-list-item)
7390 :type '(choice (const :tag "GNOME style" message-tool-bar-gnome)
7391 (const :tag "Retro look" message-tool-bar-retro)
7392 (repeat :tag "User defined list" gmm-tool-bar-item)
7394 :version "23.1" ;; No Gnus
7395 :initialize 'custom-initialize-default
7396 :set 'message-tool-bar-update
7399 (defcustom message-tool-bar-gnome
7400 '((ispell-message "spell" nil
7401 :visible (or (not (boundp 'flyspell-mode))
7402 (not flyspell-mode)))
7403 (flyspell-buffer "spell" t
7404 :visible (and (boundp 'flyspell-mode)
7406 :help "Flyspell whole buffer")
7407 (gmm-ignore "separator")
7408 (message-send-and-exit "mail/send")
7409 (message-dont-send "mail/save-draft")
7410 (message-kill-buffer "close") ;; stock_cancel
7411 (mml-attach-file "attach" mml-mode-map)
7412 (mml-preview "mail/preview" mml-mode-map)
7413 (mml-secure-message-sign-encrypt "lock" mml-mode-map :visible nil)
7414 (message-insert-importance-high "important" nil :visible nil)
7415 (message-insert-importance-low "unimportant" nil :visible nil)
7416 (message-insert-disposition-notification-to "receipt" nil :visible nil)
7417 (gmm-customize-mode "preferences" t :help "Edit mode preferences")
7418 (message-info "help" t :help "Message manual"))
7419 "List of items for the message tool bar (GNOME style).
7421 See `gmm-tool-bar-from-list' for details on the format of the list."
7422 :type '(repeat gmm-tool-bar-item)
7423 :version "23.1" ;; No Gnus
7424 :initialize 'custom-initialize-default
7425 :set 'message-tool-bar-update
7428 (defcustom message-tool-bar-retro
7429 '(;; Old Emacs 21 icon for consistency.
7430 (message-send-and-exit "gnus/mail-send")
7431 (message-kill-buffer "close")
7432 (message-dont-send "cancel")
7433 (mml-attach-file "attach" mml-mode-map)
7434 (ispell-message "spell")
7435 (mml-preview "preview" mml-mode-map)
7436 (message-insert-importance-high "gnus/important")
7437 (message-insert-importance-low "gnus/unimportant")
7438 (message-insert-disposition-notification-to "gnus/receipt"))
7439 "List of items for the message tool bar (retro style).
7441 See `gmm-tool-bar-from-list' for details on the format of the list."
7442 :type '(repeat gmm-tool-bar-item)
7443 :version "23.1" ;; No Gnus
7444 :initialize 'custom-initialize-default
7445 :set 'message-tool-bar-update
7448 (defcustom message-tool-bar-zap-list
7449 '(new-file open-file dired kill-buffer write-file
7450 print-buffer customize help)
7451 "List of icon items from the global tool bar.
7452 These items are not displayed on the message mode tool bar.
7454 See `gmm-tool-bar-from-list' for the format of the list."
7455 :type 'gmm-tool-bar-zap-list
7456 :version "23.1" ;; No Gnus
7457 :initialize 'custom-initialize-default
7458 :set 'message-tool-bar-update
7461 (defvar image-load-path)
7463 (defun message-make-tool-bar (&optional force)
7464 "Make a message mode tool bar from `message-tool-bar-list'.
7465 When FORCE, rebuild the tool bar."
7466 (when (and (not (featurep 'xemacs))
7467 (boundp 'tool-bar-mode)
7469 (or (not message-tool-bar-map) force))
7470 (setq message-tool-bar-map
7472 (gmm-image-load-path-for-library "message"
7473 "mail/save-draft.xpm"
7475 (image-load-path (cons (car load-path)
7476 (when (boundp 'image-load-path)
7478 (gmm-tool-bar-from-list message-tool-bar
7479 message-tool-bar-zap-list
7480 'message-mode-map))))
7481 message-tool-bar-map)
7483 ;;; Group name completion.
7485 (defcustom message-newgroups-header-regexp
7486 "^\\(Newsgroups\\|Followup-To\\|Posted-To\\|Gcc\\):"
7487 "Regexp that match headers that lists groups."
7491 (defcustom message-completion-alist
7492 (list (cons message-newgroups-header-regexp 'message-expand-group)
7493 '("^\\(Resent-\\)?\\(To\\|B?Cc\\):" . message-expand-name)
7494 '("^\\(Reply-To\\|From\\|Mail-Followup-To\\|Mail-Copies-To\\):"
7495 . message-expand-name)
7496 '("^\\(Disposition-Notification-To\\|Return-Receipt-To\\):"
7497 . message-expand-name))
7498 "Alist of (RE . FUN). Use FUN for completion on header lines matching RE."
7501 :type '(alist :key-type regexp :value-type function))
7503 (defcustom message-expand-name-databases
7505 "List of databases to try for name completion (`message-expand-name').
7506 Each element is a symbol and can be `bbdb' or `eudc'."
7508 :type '(set (const bbdb) (const eudc)))
7510 (defcustom message-tab-body-function nil
7511 "*Function to execute when `message-tab' (TAB) is executed in the body.
7512 If nil, the function bound in `text-mode-map' or `global-map' is executed."
7515 :link '(custom-manual "(message)Various Commands")
7516 :type '(choice (const nil)
7519 (declare-function mail-abbrev-in-expansion-header-p "mailabbrev" ())
7521 (defun message-tab ()
7522 "Complete names according to `message-completion-alist'.
7523 Execute function specified by `message-tab-body-function' when not in
7526 (let ((alist message-completion-alist))
7528 (let ((mail-abbrev-mode-regexp (caar alist)))
7529 (not (mail-abbrev-in-expansion-header-p))))
7530 (setq alist (cdr alist)))
7531 (funcall (or (cdar alist) message-tab-body-function
7532 (lookup-key text-mode-map "\t")
7533 (lookup-key global-map "\t")
7534 'indent-relative))))
7539 (let ((standard-output (current-buffer)))
7540 (eval '(display-completion-list nil "")))
7541 (defalias 'message-display-completion-list 'display-completion-list))
7542 (error ;; Don't use `wrong-number-of-arguments' here because of XEmacs.
7543 (defun message-display-completion-list (completions &optional ignore)
7544 "Display the list of completions, COMPLETIONS, using `standard-output'."
7545 (display-completion-list completions)))))
7547 (defun message-expand-group ()
7548 "Expand the group name under point."
7549 (let* ((b (save-excursion
7554 (skip-chars-forward "^:")
7557 (skip-chars-backward "^, \t\n") (point))))
7558 (completion-ignore-case t)
7559 (string (buffer-substring b (progn (skip-chars-forward "^,\t\n ")
7561 (hashtb (and (boundp 'gnus-active-hashtb) gnus-active-hashtb))
7562 (completions (all-completions string hashtb))
7564 (delete-region b (point))
7566 ((= (length completions) 1)
7567 (if (string= (car completions) string)
7570 (message "Only matching group"))
7571 (insert (car completions))))
7572 ((and (setq comp (try-completion string hashtb))
7573 (not (string= comp string)))
7578 (message "No matching groups")
7579 (save-selected-window
7580 (pop-to-buffer "*Completions*")
7581 (buffer-disable-undo)
7582 (let ((buffer-read-only nil))
7584 (let ((standard-output (current-buffer)))
7585 (message-display-completion-list (sort completions 'string<)
7587 (setq buffer-read-only nil)
7588 (goto-char (point-min))
7589 (delete-region (point) (progn (forward-line 3) (point))))))))))
7591 (defun message-expand-name ()
7592 (cond ((and (memq 'eudc message-expand-name-databases)
7593 (boundp 'eudc-protocol)
7595 (eudc-expand-inline))
7596 ((and (memq 'bbdb message-expand-name-databases)
7597 (fboundp 'bbdb-complete-name))
7598 (bbdb-complete-name))
7604 (defun message-talkative-question (ask question show &rest text)
7605 "Call FUNCTION with argument QUESTION; optionally display TEXT... args.
7606 If SHOW is non-nil, the arguments TEXT... are displayed in a temp buffer.
7607 The following arguments may contain lists of values."
7609 (setq text (message-flatten-list text)))
7610 (save-window-excursion
7611 (with-output-to-temp-buffer " *MESSAGE information message*"
7612 (with-current-buffer " *MESSAGE information message*"
7613 (fundamental-mode) ; for Emacs 20.4+
7615 (goto-char (point-min))))
7616 (funcall ask question))
7617 (funcall ask question)))
7619 (defun message-flatten-list (list)
7620 "Return a new, flat list that contains all elements of LIST.
7622 \(message-flatten-list '(1 (2 3 (4 5 (6))) 7))
7625 (apply 'append (mapcar 'message-flatten-list list)))
7629 (defun message-generate-new-buffer-clone-locals (name &optional varstr)
7630 "Create and return a buffer with name based on NAME using `generate-new-buffer'.
7631 Then clone the local variables and values from the old buffer to the
7632 new one, cloning only the locals having a substring matching the
7634 (let ((oldbuf (current-buffer)))
7635 (with-current-buffer (generate-new-buffer name)
7636 (message-clone-locals oldbuf varstr)
7639 (defun message-clone-locals (buffer &optional varstr)
7640 "Clone the local variables from BUFFER to the current buffer."
7641 (let ((locals (with-current-buffer buffer (buffer-local-variables)))
7642 (regexp "^gnus\\|^nn\\|^message\\|^sendmail\\|^smtp\\|^user-mail-address"))
7645 (when (and (consp local)
7647 (string-match regexp (symbol-name (car local)))
7649 (string-match varstr (symbol-name (car local)))))
7651 (set (make-local-variable (car local))
7659 (defvar message-inhibit-body-encoding nil)
7661 (defun message-encode-message-body ()
7662 (unless message-inhibit-body-encoding
7663 (let ((mail-parse-charset (or mail-parse-charset
7664 message-default-charset))
7665 (case-fold-search t)
7666 lines content-type-p)
7669 (narrow-to-region (point) (point-max))
7670 (let ((new (mml-generate-mime)))
7672 (delete-region (point-min) (point-max))
7674 (goto-char (point-min))
7675 (if (eq (aref new 0) ?\n)
7677 (search-forward "\n\n")
7678 (setq lines (buffer-substring (point-min) (1- (point))))
7679 (delete-region (point-min) (point))))))
7681 (message-narrow-to-headers-or-head)
7682 (message-remove-header "Mime-Version")
7683 (goto-char (point-max))
7684 (insert "MIME-Version: 1.0\n")
7687 (setq content-type-p
7689 (re-search-backward "^Content-Type:" nil t))))
7691 (message-narrow-to-headers-or-head)
7692 (message-remove-first-header "Content-Type")
7693 (message-remove-first-header "Content-Transfer-Encoding"))
7694 ;; We always make sure that the message has a Content-Type
7695 ;; header. This is because some broken MTAs and MUAs get
7696 ;; awfully confused when confronted with a message with a
7697 ;; MIME-Version header and without a Content-Type header. For
7698 ;; instance, Solaris' /usr/bin/mail.
7699 (unless content-type-p
7700 (goto-char (point-min))
7701 ;; For unknown reason, MIME-Version doesn't exist.
7702 (when (re-search-forward "^MIME-Version:" nil t)
7704 (insert "Content-Type: text/plain; charset=us-ascii\n"))))))
7706 (defun message-read-from-minibuffer (prompt &optional initial-contents)
7707 "Read from the minibuffer while providing abbrev expansion."
7708 (if (fboundp 'mail-abbrevs-setup)
7709 (let ((mail-abbrev-mode-regexp "")
7710 (minibuffer-setup-hook 'mail-abbrevs-setup)
7711 (minibuffer-local-map message-minibuffer-local-map))
7712 (read-from-minibuffer prompt initial-contents))
7713 (let ((minibuffer-setup-hook 'mail-abbrev-minibuffer-setup-hook)
7714 (minibuffer-local-map message-minibuffer-local-map))
7715 (read-string prompt initial-contents))))
7717 (defun message-use-alternative-email-as-from ()
7718 "Set From field of the outgoing message to the first matching
7719 address in `message-alternative-emails', looking at To, Cc and
7720 From headers in the original article."
7721 (require 'mail-utils)
7722 (let* ((fields '("To" "Cc" "From"))
7725 (mail-strip-quoted-names
7726 (mapconcat 'message-fetch-reply-field fields ","))
7730 (if (string-match message-alternative-emails (car emails))
7731 (setq email (car emails)
7734 (unless (or (not email) (equal email user-mail-address))
7735 (message-remove-header "From")
7736 (goto-char (point-max))
7737 (insert "From: " (let ((user-mail-address email)) (message-make-from))
7740 (defun message-options-get (symbol)
7741 (cdr (assq symbol message-options)))
7743 (defun message-options-set (symbol value)
7744 (let ((the-cons (assq symbol message-options)))
7747 (setcdr the-cons value)
7748 (setq message-options (delq the-cons message-options)))
7750 (push (cons symbol value) message-options))))
7753 (defun message-options-set-recipient ()
7755 (message-narrow-to-headers-or-head)
7756 (message-options-set 'message-sender
7757 (mail-strip-quoted-names
7758 (message-fetch-field "from")))
7759 (message-options-set 'message-recipients
7760 (mail-strip-quoted-names
7761 (let ((to (message-fetch-field "to"))
7762 (cc (message-fetch-field "cc"))
7763 (bcc (message-fetch-field "bcc")))
7766 (if (and to cc) ", ")
7768 (if (and (or to cc) bcc) ", ")
7771 (defun message-hide-headers ()
7772 "Hide headers based on the `message-hidden-headers' variable."
7773 (let ((regexps (if (stringp message-hidden-headers)
7774 (list message-hidden-headers)
7775 message-hidden-headers))
7776 (inhibit-point-motion-hooks t)
7777 (after-change-functions nil)
7778 (end-of-headers (point-min)))
7782 (message-narrow-to-headers)
7783 (goto-char (point-min))
7785 (if (not (message-hide-header-p regexps))
7786 (message-next-header)
7787 (let ((begin (point))
7789 (message-next-header)
7790 (setq header (buffer-substring begin (point))
7791 header-len (- (point) begin))
7792 (delete-region begin (point))
7793 (goto-char end-of-headers)
7795 (setq end-of-headers
7796 (+ end-of-headers header-len))))))))
7797 (narrow-to-region end-of-headers (point-max))))
7799 (defun message-hide-header-p (regexps)
7802 (when (eq (car regexps) 'not)
7805 (dolist (regexp regexps)
7806 (setq result (or result (looking-at regexp))))
7811 (defun message-put-addresses-in-ecomplete ()
7812 (dolist (header '("to" "cc" "from" "reply-to"))
7813 (let ((value (message-field-value header)))
7814 (dolist (string (mail-header-parse-addresses value 'raw))
7816 (gnus-replace-in-string
7817 (gnus-replace-in-string string "^ +\\| +$" "") "\n" ""))
7818 (ecomplete-add-item 'mail (car (mail-header-parse-address string))
7822 (defun message-display-abbrev (&optional choose)
7823 "Display the next possible abbrev for the text before point."
7824 (interactive (list t))
7825 (when (and (memq (char-after (point-at-bol)) '(?C ?T ?\t ? ))
7826 (message-point-in-header-p)
7829 (while (and (memq (char-after) '(?\t ? ))
7830 (zerop (forward-line -1))))
7831 (looking-at "To:\\|Cc:")))
7832 (let* ((end (point))
7833 (start (save-excursion
7834 (and (re-search-backward "[\n\t ]" nil t)
7836 (word (when start (buffer-substring start end)))
7837 (match (when (and word
7838 (not (zerop (length word))))
7839 (ecomplete-display-matches 'mail word choose))))
7840 (when (and choose match)
7841 (delete-region start end)
7844 ;; To send pre-formatted letters like the example below, you can use
7845 ;; `message-send-form-letter':
7846 ;; --8<---------------cut here---------------start------------->8---
7847 ;; To: alice@invalid.invalid
7848 ;; Subject: Verification of your contact information
7849 ;; From: Contact verification <admin@foo.invalid>
7850 ;; --text follows this line--
7852 ;; please verify that your contact information is still valid:
7853 ;; Alice A, A avenue 11, 1111 A town, Austria
7854 ;; ----------next form letter message follows this line----------
7855 ;; To: bob@invalid.invalid
7856 ;; Subject: Verification of your contact information
7857 ;; From: Contact verification <admin@foo.invalid>
7858 ;; --text follows this line--
7860 ;; please verify that your contact information is still valid:
7861 ;; Bob, B street 22, 22222 Be town, Belgium
7862 ;; ----------next form letter message follows this line----------
7863 ;; To: charlie@invalid.invalid
7864 ;; Subject: Verification of your contact information
7865 ;; From: Contact verification <admin@foo.invalid>
7866 ;; --text follows this line--
7868 ;; please verify that your contact information is still valid:
7869 ;; Charlie Chaplin, C plaza 33, 33333 C town, Chile
7870 ;; --8<---------------cut here---------------end--------------->8---
7872 ;; FIXME: What is the most common term (circular letter, form letter, serial
7873 ;; letter, standard letter) for such kind of letter? See also
7874 ;; <http://en.wikipedia.org/wiki/Form_letter>
7876 ;; FIXME: Maybe extent message-mode's font-lock support to recognize
7877 ;; `message-form-letter-separator', i.e. highlight each message like a single
7880 (defcustom message-form-letter-separator
7881 "\n----------next form letter message follows this line----------\n"
7882 "Separator for `message-send-form-letter'."
7883 ;; :group 'message-form-letter
7884 :group 'message-various
7885 :version "23.1" ;; No Gnus
7888 (defcustom message-send-form-letter-delay 1
7889 "Delay in seconds when sending a message with `message-send-form-letter'.
7890 Only used when `message-send-form-letter' is called with non-nil
7892 ;; :group 'message-form-letter
7893 :group 'message-various
7894 :version "23.1" ;; No Gnus
7897 (defun message-send-form-letter (&optional force)
7898 "Sent all form letter messages from current buffer.
7899 Unless FORCE, prompt before sending.
7901 The messages are separated by `message-form-letter-separator'.
7902 Header and body are separated by `mail-header-separator'."
7904 (let ((sent 0) (skipped 0)
7908 (goto-char (point-min))
7911 end (if (search-forward message-form-letter-separator nil t)
7912 (- (point) (length message-form-letter-separator) -1)
7916 (buffer-substring-no-properties start end))
7917 (setq buff (generate-new-buffer "*mail - form letter*"))
7918 (with-current-buffer buff
7921 (setq to (message-fetch-field "To"))
7922 (switch-to-buffer buff)
7924 (sit-for message-send-form-letter-delay))
7926 (y-or-n-p (format "Send message to `%s'? " to)))
7928 (setq sent (1+ sent))
7929 (message-send-and-exit))
7930 (message (format "Message to `%s' skipped." to))
7931 (setq skipped (1+ skipped)))
7932 (when (buffer-live-p buff)
7933 (kill-buffer buff))))
7934 (message "%s message(s) sent, %s skipped." sent skipped)))
7936 (defun message-replace-header (header new-value &optional after force)
7937 "Remove HEADER and insert the NEW-VALUE.
7938 If AFTER, insert after this header. If FORCE, insert new field
7939 even if NEW-VALUE is empty."
7940 ;; Similar to `nnheader-replace-header' but for message buffers.
7943 (message-narrow-to-headers)
7944 (message-remove-header header))
7945 (when (or force (> (length new-value) 0))
7947 (message-position-on-field header after)
7948 (message-position-on-field header))
7949 (insert new-value))))
7951 (defcustom message-recipients-without-full-name
7952 (list "ding@gnus.org"
7954 "emacs-devel@gnu.org"
7955 "emacs-pretest-bug@gnu.org"
7956 "bug-gnu-emacs@gnu.org")
7957 "Mail addresses that have no full name.
7958 Used in `message-simplify-recipients'."
7959 ;; Maybe the addresses could be extracted from
7960 ;; `gnus-parameter-to-list-alist'?
7961 :type '(choice (const :tag "None" nil)
7963 :version "23.1" ;; No Gnus
7964 :group 'message-headers)
7966 (defun message-simplify-recipients ()
7968 (dolist (hdr '("Cc" "To"))
7969 (message-replace-header
7973 (if (and message-recipients-without-full-name
7975 (regexp-opt message-recipients-without-full-name)
7979 (message-make-from (car addrcomp) (cadr addrcomp))
7981 (when (message-fetch-field hdr)
7982 (mail-extract-address-components
7983 (message-fetch-field hdr) t))
7986 (when (featurep 'xemacs)
7987 (require 'messagexmas)
7988 (message-xmas-redefine))
7992 (run-hooks 'message-load-hook)
7995 ;; coding: iso-8859-1
7998 ;; arch-tag: 94b32cac-4504-4b6c-8181-030ebf380ee0
7999 ;;; message.el ends here