1 ;;; message.el --- composing mail and news messages
2 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000
3 ;; Free Software Foundation, Inc.
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
6 ;; Keywords: mail, news
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
27 ;; This mode provides mail-sending facilities from within Emacs. It
28 ;; consists mainly of large chunks of code from the sendmail.el,
29 ;; gnus-msg.el and rnewspost.el files.
33 (eval-when-compile (require 'cl))
37 (if (string-match "XEmacs\\|Lucid" emacs-version)
38 (require 'mail-abbrevs)
39 (require 'mailabbrev))
45 (defgroup message '((user-mail-address custom-variable)
46 (user-full-name custom-variable))
47 "Mail and news message composing."
48 :link '(custom-manual "(message)Top")
52 (put 'user-mail-address 'custom-type 'string)
53 (put 'user-full-name 'custom-type 'string)
55 (defgroup message-various nil
56 "Various Message Variables"
57 :link '(custom-manual "(message)Various Message Variables")
60 (defgroup message-buffers nil
62 :link '(custom-manual "(message)Message Buffers")
65 (defgroup message-sending nil
67 :link '(custom-manual "(message)Sending Variables")
70 (defgroup message-interface nil
72 :link '(custom-manual "(message)Interface")
75 (defgroup message-forwarding nil
77 :link '(custom-manual "(message)Forwarding")
78 :group 'message-interface)
80 (defgroup message-insertion nil
82 :link '(custom-manual "(message)Insertion")
85 (defgroup message-headers nil
87 :link '(custom-manual "(message)Message Headers")
90 (defgroup message-news nil
91 "Composing News Messages"
94 (defgroup message-mail nil
95 "Composing Mail Messages"
98 (defgroup message-faces nil
99 "Faces used for message composing."
103 (defcustom message-directory "~/Mail/"
104 "*Directory from which all other mail file variables are derived."
105 :group 'message-various
108 (defcustom message-max-buffers 10
109 "*How many buffers to keep before starting to kill them off."
110 :group 'message-buffers
113 (defcustom message-send-rename-function nil
114 "Function called to rename the buffer after sending it."
115 :group 'message-buffers
118 (defcustom message-fcc-handler-function 'message-output
119 "*A function called to save outgoing articles.
120 This function will be called with the name of the file to store the
121 article in. The default function is `message-output' which saves in Unix
123 :type '(radio (function-item message-output)
124 (function :tag "Other"))
125 :group 'message-sending)
127 (defcustom message-courtesy-message
128 "The following message is a courtesy copy of an article\nthat has been posted to %s as well.\n\n"
129 "*This is inserted at the start of a mailed copy of a posted message.
130 If the string contains the format spec \"%s\", the Newsgroups
131 the article has been posted to will be inserted there.
132 If this variable is nil, no such courtesy message will be added."
133 :group 'message-sending
136 (defcustom message-ignored-bounced-headers "^\\(Received\\|Return-Path\\):"
137 "*Regexp that matches headers to be removed in resent bounced mail."
138 :group 'message-interface
142 (defcustom message-from-style 'default
143 "*Specifies how \"From\" headers look.
145 If `nil', they contain just the return address like:
147 If `parens', they look like:
148 king@grassland.com (Elvis Parsley)
149 If `angles', they look like:
150 Elvis Parsley <king@grassland.com>
152 Otherwise, most addresses look like `angles', but they look like
153 `parens' if `angles' would need quoting and `parens' would not."
154 :type '(choice (const :tag "simple" nil)
158 :group 'message-headers)
160 (defcustom message-syntax-checks nil
161 ;; Guess this one shouldn't be easy to customize...
162 "*Controls what syntax checks should not be performed on outgoing posts.
163 To disable checking of long signatures, for instance, add
164 `(signature . disabled)' to this list.
166 Don't touch this variable unless you really know what you're doing.
168 Checks include subject-cmsg multiple-headers sendsys message-id from
169 long-lines control-chars size new-text redirected-followup signature
170 approved sender empty empty-headers message-id from subject
171 shorten-followup-to existing-newsgroups buffer-file-name unchanged
173 :group 'message-news)
175 (defcustom message-required-news-headers
176 '(From Newsgroups Subject Date Message-ID
177 (optional . Organization) Lines
178 (optional . User-Agent))
179 "*Headers to be generated or prompted for when posting an article.
180 RFC977 and RFC1036 require From, Date, Newsgroups, Subject,
181 Message-ID. Organization, Lines, In-Reply-To, Expires, and
182 User-Agent are optional. If don't you want message to insert some
183 header, remove it from this list."
185 :group 'message-headers
186 :type '(repeat sexp))
188 (defcustom message-required-mail-headers
189 '(From Subject Date (optional . In-Reply-To) Message-ID Lines
190 (optional . User-Agent))
191 "*Headers to be generated or prompted for when mailing a message.
192 RFC822 required that From, Date, To, Subject and Message-ID be
193 included. Organization, Lines and User-Agent are optional."
195 :group 'message-headers
196 :type '(repeat sexp))
198 (defcustom message-deletable-headers '(Message-ID Date Lines)
199 "Headers to be deleted if they already exist and were generated by message previously."
200 :group 'message-headers
203 (defcustom message-ignored-news-headers
204 "^NNTP-Posting-Host:\\|^Xref:\\|^[BGF]cc:\\|^Resent-Fcc:"
205 "*Regexp of headers to be removed unconditionally before posting."
207 :group 'message-headers
210 (defcustom message-ignored-mail-headers "^[GF]cc:\\|^Resent-Fcc:\\|^Xref:"
211 "*Regexp of headers to be removed unconditionally before mailing."
213 :group 'message-headers
216 (defcustom message-ignored-supersedes-headers "^Path:\\|^Date\\|^NNTP-Posting-Host:\\|^Xref:\\|^Lines:\\|^Received:\\|^X-From-Line:\\|^X-Trace:\\|^X-Complaints-To:\\|Return-Path:\\|^Supersedes:\\|^NNTP-Posting-Date:\\|^X-Trace:\\|^X-Complaints-To:"
217 "*Header lines matching this regexp will be deleted before posting.
218 It's best to delete old Path and Date headers before posting to avoid
220 :group 'message-interface
223 (defcustom message-subject-re-regexp "^[ \t]*\\([Rr][Ee]:[ \t]*\\)*[ \t]*"
224 "*Regexp matching \"Re: \" in the subject line."
225 :group 'message-various
229 (defcustom message-signature-separator "^-- *$"
230 "Regexp matching the signature separator."
232 :group 'message-various)
234 (defcustom message-elide-ellipsis "\n[...]\n\n"
235 "*The string which is inserted for elided text."
237 :group 'message-various)
239 (defcustom message-interactive nil
240 "Non-nil means when sending a message wait for and display errors.
241 nil means let mailer mail back a message to report errors."
242 :group 'message-sending
246 (defcustom message-generate-new-buffers 'unique
247 "*Non-nil means that a new message buffer will be created whenever `message-setup' is called.
248 If this is a function, call that function with three parameters: The type,
249 the to address and the group name. (Any of these may be nil.) The function
250 should return the new buffer name."
251 :group 'message-buffers
252 :type '(choice (const :tag "off" nil)
253 (const :tag "unique" unique)
254 (const :tag "unsent" unsent)
257 (defcustom message-kill-buffer-on-exit nil
258 "*Non-nil means that the message buffer will be killed after sending a message."
259 :group 'message-buffers
262 (defvar gnus-local-organization)
263 (defcustom message-user-organization
264 (or (and (boundp 'gnus-local-organization)
265 (stringp gnus-local-organization)
266 gnus-local-organization)
267 (getenv "ORGANIZATION")
269 "*String to be used as an Organization header.
270 If t, use `message-user-organization-file'."
271 :group 'message-headers
272 :type '(choice string
273 (const :tag "consult file" t)))
276 (defcustom message-user-organization-file "/usr/lib/news/organization"
277 "*Local news organization file."
279 :group 'message-headers)
281 (defcustom message-make-forward-subject-function
282 'message-forward-subject-author-subject
283 "*A list of functions that are called to generate a subject header for forwarded messages.
284 The subject generated by the previous function is passed into each
287 The provided functions are:
289 * message-forward-subject-author-subject (Source of article (author or
290 newsgroup)), in brackets followed by the subject
291 * message-forward-subject-fwd (Subject of article with 'Fwd:' prepended
293 :group 'message-forwarding
294 :type '(radio (function-item message-forward-subject-author-subject)
295 (function-item message-forward-subject-fwd)))
297 (defcustom message-forward-as-mime t
298 "*If non-nil, forward messages as an inline/rfc822 MIME section. Otherwise, directly inline the old message in the forwarded message."
299 :group 'message-forwarding
302 (defcustom message-forward-before-signature t
303 "*If non-nil, put forwarded message before signature, else after."
304 :group 'message-forwarding
307 (defcustom message-wash-forwarded-subjects nil
308 "*If non-nil, try to remove as much old cruft as possible from the subject of messages before generating the new subject of a forward."
309 :group 'message-forwarding
312 (defcustom message-ignored-resent-headers "^Return-receipt\\|^X-Gnus\\|^Gnus-Warning:"
313 "*All headers that match this regexp will be deleted when resending a message."
314 :group 'message-interface
317 (defcustom message-forward-ignored-headers "Content-Transfer-Encoding"
318 "*All headers that match this regexp will be deleted when forwarding a message."
319 :group 'message-forwarding
320 :type '(choice (const :tag "None" nil)
323 (defcustom message-ignored-cited-headers "."
324 "*Delete these headers from the messages you yank."
325 :group 'message-insertion
328 (defcustom message-cancel-message "I am canceling my own article.\n"
329 "Message to be inserted in the cancel message."
330 :group 'message-interface
333 ;; Useful to set in site-init.el
335 (defcustom message-send-mail-function 'message-send-mail-with-sendmail
336 "Function to call to send the current buffer as mail.
337 The headers should be delimited by a line whose contents match the
338 variable `mail-header-separator'.
340 Valid values include `message-send-mail-with-sendmail' (the default),
341 `message-send-mail-with-mh', `message-send-mail-with-qmail' and
343 :type '(radio (function-item message-send-mail-with-sendmail)
344 (function-item message-send-mail-with-mh)
345 (function-item message-send-mail-with-qmail)
346 (function-item smtpmail-send-it)
347 (function :tag "Other"))
348 :group 'message-sending
349 :group 'message-mail)
351 (defcustom message-send-news-function 'message-send-news
352 "Function to call to send the current buffer as news.
353 The headers should be delimited by a line whose contents match the
354 variable `mail-header-separator'."
355 :group 'message-sending
359 (defcustom message-reply-to-function nil
360 "Function that should return a list of headers.
361 This function should pick out addresses from the To, Cc, and From headers
362 and respond with new To and Cc headers."
363 :group 'message-interface
366 (defcustom message-wide-reply-to-function nil
367 "Function that should return a list of headers.
368 This function should pick out addresses from the To, Cc, and From headers
369 and respond with new To and Cc headers."
370 :group 'message-interface
373 (defcustom message-followup-to-function nil
374 "Function that should return a list of headers.
375 This function should pick out addresses from the To, Cc, and From headers
376 and respond with new To and Cc headers."
377 :group 'message-interface
380 (defcustom message-use-followup-to 'ask
381 "*Specifies what to do with Followup-To header.
382 If nil, always ignore the header. If it is t, use its value, but
383 query before using the \"poster\" value. If it is the symbol `ask',
384 always query the user whether to use the value. If it is the symbol
385 `use', always use the value."
386 :group 'message-interface
387 :type '(choice (const :tag "ignore" nil)
391 (defcustom message-sendmail-f-is-evil nil
392 "*Non-nil means that \"-f username\" should not be added to the sendmail command line.
393 Doing so would be even more evil than leaving it out."
394 :group 'message-sending
397 ;; qmail-related stuff
398 (defcustom message-qmail-inject-program "/var/qmail/bin/qmail-inject"
399 "Location of the qmail-inject program."
400 :group 'message-sending
403 (defcustom message-qmail-inject-args nil
404 "Arguments passed to qmail-inject programs.
405 This should be a list of strings, one string for each argument.
407 For e.g., if you wish to set the envelope sender address so that bounces
408 go to the right place or to deal with listserv's usage of that address, you
409 might set this variable to '(\"-f\" \"you@some.where\")."
410 :group 'message-sending
411 :type '(repeat string))
413 (defvar message-cater-to-broken-inn t
414 "Non-nil means Gnus should not fold the `References' header.
415 Folding `References' makes ancient versions of INN create incorrect
418 (defvar gnus-post-method)
419 (defvar gnus-select-method)
420 (defcustom message-post-method
421 (cond ((and (boundp 'gnus-post-method)
422 (listp gnus-post-method)
425 ((boundp 'gnus-select-method)
428 "*Method used to post news.
429 Note that when posting from inside Gnus, for instance, this
430 variable isn't used."
432 :group 'message-sending
433 ;; This should be the `gnus-select-method' widget, but that might
434 ;; create a dependence to `gnus.el'.
437 (defcustom message-generate-headers-first nil
438 "*If non-nil, generate all possible headers before composing."
439 :group 'message-headers
442 (defcustom message-setup-hook nil
443 "Normal hook, run each time a new outgoing message is initialized.
444 The function `message-setup' runs this hook."
445 :group 'message-various
448 (defcustom message-cancel-hook nil
449 "Hook run when cancelling articles."
450 :group 'message-various
453 (defcustom message-signature-setup-hook nil
454 "Normal hook, run each time a new outgoing message is initialized.
455 It is run after the headers have been inserted and before
456 the signature is inserted."
457 :group 'message-various
460 (defcustom message-mode-hook nil
461 "Hook run in message mode buffers."
462 :group 'message-various
465 (defcustom message-header-hook nil
466 "Hook run in a message mode buffer narrowed to the headers."
467 :group 'message-various
470 (defcustom message-header-setup-hook nil
471 "Hook called narrowed to the headers when setting up a message buffer."
472 :group 'message-various
476 (defcustom message-citation-line-function 'message-insert-citation-line
477 "*Function called to insert the \"Whomever writes:\" line."
479 :group 'message-insertion)
482 (defcustom message-yank-prefix "> "
483 "*Prefix inserted on the lines of yanked messages."
485 :group 'message-insertion)
487 (defcustom message-indentation-spaces 3
488 "*Number of spaces to insert at the beginning of each cited line.
489 Used by `message-yank-original' via `message-yank-cite'."
490 :group 'message-insertion
494 (defcustom message-cite-function 'message-cite-original
495 "*Function for citing an original message.
496 Predefined functions include `message-cite-original' and
497 `message-cite-original-without-signature'.
498 Note that `message-cite-original' uses `mail-citation-hook' if that is non-nil."
499 :type '(radio (function-item message-cite-original)
500 (function-item message-cite-original-without-signature)
501 (function-item sc-cite-original)
502 (function :tag "Other"))
503 :group 'message-insertion)
506 (defcustom message-indent-citation-function 'message-indent-citation
507 "*Function for modifying a citation just inserted in the mail buffer.
508 This can also be a list of functions. Each function can find the
509 citation between (point) and (mark t). And each function should leave
510 point and mark around the citation text as modified."
512 :group 'message-insertion)
514 (defvar message-abbrevs-loaded nil)
517 (defcustom message-signature t
518 "*String to be inserted at the end of the message buffer.
519 If t, the `message-signature-file' file will be inserted instead.
520 If a function, the result from the function will be used instead.
521 If a form, the result from the form will be used instead."
523 :group 'message-insertion)
526 (defcustom message-signature-file "~/.signature"
527 "*File containing the text inserted at end of message buffer."
529 :group 'message-insertion)
531 (defcustom message-distribution-function nil
532 "*Function called to return a Distribution header."
534 :group 'message-headers
537 (defcustom message-expires 14
538 "Number of days before your article expires."
540 :group 'message-headers
541 :link '(custom-manual "(message)News Headers")
544 (defcustom message-user-path nil
545 "If nil, use the NNTP server name in the Path header.
546 If stringp, use this; if non-nil, use no host name (user name only)."
548 :group 'message-headers
549 :link '(custom-manual "(message)News Headers")
550 :type '(choice (const :tag "nntp" nil)
552 (sexp :tag "none" :format "%t" t)))
554 (defvar message-reply-buffer nil)
555 (defvar message-reply-headers nil)
556 (defvar message-newsreader nil)
557 (defvar message-mailer nil)
558 (defvar message-sent-message-via nil)
559 (defvar message-checksum nil)
560 (defvar message-send-actions nil
561 "A list of actions to be performed upon successful sending of a message.")
562 (defvar message-exit-actions nil
563 "A list of actions to be performed upon exiting after sending a message.")
564 (defvar message-kill-actions nil
565 "A list of actions to be performed before killing a message buffer.")
566 (defvar message-postpone-actions nil
567 "A list of actions to be performed after postponing a message.")
569 (define-widget 'message-header-lines 'text
570 "All header lines must be LFD terminated."
573 :error "All header lines must be newline terminated")
575 (defcustom message-default-headers ""
576 "*A string containing header lines to be inserted in outgoing messages.
577 It is inserted before you edit the message, so you can edit or delete
579 :group 'message-headers
580 :type 'message-header-lines)
582 (defcustom message-default-mail-headers ""
583 "*A string of header lines to be inserted in outgoing mails."
584 :group 'message-headers
586 :type 'message-header-lines)
588 (defcustom message-default-news-headers ""
589 "*A string of header lines to be inserted in outgoing news articles."
590 :group 'message-headers
592 :type 'message-header-lines)
594 ;; Note: could use /usr/ucb/mail instead of sendmail;
595 ;; options -t, and -v if not interactive.
596 (defcustom message-mailer-swallows-blank-line
597 (if (and (string-match "sparc-sun-sunos\\(\\'\\|[^5]\\)"
598 system-configuration)
599 (file-readable-p "/etc/sendmail.cf")
600 (let ((buffer (get-buffer-create " *temp*")))
604 (insert-file-contents "/etc/sendmail.cf")
605 (goto-char (point-min))
606 (let ((case-fold-search nil))
607 (re-search-forward "^OR\\>" nil t)))
608 (kill-buffer buffer))))
609 ;; According to RFC822, "The field-name must be composed of printable
610 ;; ASCII characters (i. e., characters that have decimal values between
611 ;; 33 and 126, except colon)", i. e., any chars except ctl chars,
613 '(looking-at "[ \t]\\|[][!\"#$%&'()*+,-./0-9;<=>?@A-Z\\\\^_`a-z{|}~]+:"))
614 "*Set this non-nil if the system's mailer runs the header and body together.
615 \(This problem exists on Sunos 4 when sendmail is run in remote mode.)
616 The value should be an expression to test whether the problem will
618 :group 'message-sending
621 ;; Ignore errors in case this is used in Emacs 19.
622 ;; Don't use ignore-errors because this is copied into loaddefs.el.
625 (define-mail-user-agent 'message-user-agent
626 'message-mail 'message-send-and-exit
627 'message-kill-buffer 'message-send-hook))
629 (defvar message-mh-deletable-headers '(Message-ID Date Lines Sender)
630 "If non-nil, delete the deletable headers before feeding to mh.")
632 (defvar message-send-method-alist
633 '((news message-news-p message-send-via-news)
634 (mail message-mail-p message-send-via-mail))
635 "Alist of ways to send outgoing messages.
636 Each element has the form
638 \(TYPE PREDICATE FUNCTION)
640 where TYPE is a symbol that names the method; PREDICATE is a function
641 called without any parameters to determine whether the message is
642 a message of type TYPE; and FUNCTION is a function to be called if
643 PREDICATE returns non-nil. FUNCTION is called with one parameter --
646 (defvar message-mail-alias-type 'abbrev
647 "*What alias expansion type to use in Message buffers.
648 The default is `abbrev', which uses mailabbrev. nil switches
651 (defcustom message-auto-save-directory
652 (nnheader-concat message-directory "drafts/")
653 "*Directory where Message auto-saves buffers if Gnus isn't running.
654 If nil, Message won't auto-save."
655 :group 'message-buffers
658 (defcustom message-buffer-naming-style 'unique
659 "*The way new message buffers are named.
660 Valid valued are `unique' and `unsent'."
661 :group 'message-buffers
662 :type '(choice (const :tag "unique" unique)
663 (const :tag "unsent" unsent)))
665 (defcustom message-default-charset nil
666 "Default charset used in non-MULE XEmacsen."
670 (defcustom message-dont-reply-to-names rmail-dont-reply-to-names
671 "*A regexp specifying names to prune when doing wide replies.
672 A value of nil means exclude your own name only."
674 :type '(choice (const :tag "Yourself" nil)
677 ;;; Internal variables.
678 ;;; Well, not really internal.
680 (defvar message-mode-syntax-table
681 (let ((table (copy-syntax-table text-mode-syntax-table)))
682 (modify-syntax-entry ?% ". " table)
683 (modify-syntax-entry ?> ". " table)
684 (modify-syntax-entry ?< ". " table)
686 "Syntax table used while in Message mode.")
688 (defvar message-mode-abbrev-table text-mode-abbrev-table
689 "Abbrev table used in Message mode buffers.
690 Defaults to `text-mode-abbrev-table'.")
691 (defgroup message-headers nil
693 :link '(custom-manual "(message)Variables")
696 (defface message-header-to-face
699 (:foreground "green2" :bold t))
702 (:foreground "MidnightBlue" :bold t))
704 (:bold t :italic t)))
705 "Face used for displaying From headers."
706 :group 'message-faces)
708 (defface message-header-cc-face
711 (:foreground "green4" :bold t))
714 (:foreground "MidnightBlue"))
717 "Face used for displaying Cc headers."
718 :group 'message-faces)
720 (defface message-header-subject-face
723 (:foreground "green3"))
726 (:foreground "navy blue" :bold t))
729 "Face used for displaying subject headers."
730 :group 'message-faces)
732 (defface message-header-newsgroups-face
735 (:foreground "yellow" :bold t :italic t))
738 (:foreground "blue4" :bold t :italic t))
740 (:bold t :italic t)))
741 "Face used for displaying newsgroups headers."
742 :group 'message-faces)
744 (defface message-header-other-face
747 (:foreground "#b00000"))
750 (:foreground "steel blue"))
752 (:bold t :italic t)))
753 "Face used for displaying newsgroups headers."
754 :group 'message-faces)
756 (defface message-header-name-face
759 (:foreground "DarkGreen"))
762 (:foreground "cornflower blue"))
765 "Face used for displaying header names."
766 :group 'message-faces)
768 (defface message-header-xheader-face
771 (:foreground "blue"))
774 (:foreground "blue"))
777 "Face used for displaying X-Header headers."
778 :group 'message-faces)
780 (defface message-separator-face
783 (:foreground "blue3"))
786 (:foreground "brown"))
789 "Face used for displaying the separator."
790 :group 'message-faces)
792 (defface message-cited-text-face
801 "Face used for displaying cited text names."
802 :group 'message-faces)
804 (defface message-mml-face
807 (:foreground "ForestGreen"))
810 (:foreground "ForestGreen"))
813 "Face used for displaying MML."
814 :group 'message-faces)
816 (defvar message-font-lock-keywords
817 (let* ((cite-prefix "A-Za-z")
818 (cite-suffix (concat cite-prefix "0-9_.@-"))
819 (content "[ \t]*\\(.+\\(\n[ \t].*\\)*\\)"))
820 `((,(concat "^\\([Tt]o:\\)" content)
821 (1 'message-header-name-face)
822 (2 'message-header-to-face nil t))
823 (,(concat "^\\(^[GBF]?[Cc][Cc]:\\|^[Rr]eply-[Tt]o:\\)" content)
824 (1 'message-header-name-face)
825 (2 'message-header-cc-face nil t))
826 (,(concat "^\\([Ss]ubject:\\)" content)
827 (1 'message-header-name-face)
828 (2 'message-header-subject-face nil t))
829 (,(concat "^\\([Nn]ewsgroups:\\|Followup-[Tt]o:\\)" content)
830 (1 'message-header-name-face)
831 (2 'message-header-newsgroups-face nil t))
832 (,(concat "^\\([A-Z][^: \n\t]+:\\)" content)
833 (1 'message-header-name-face)
834 (2 'message-header-other-face nil t))
835 (,(concat "^\\(X-[A-Za-z0-9-]+\\|In-Reply-To\\):" content)
836 (1 'message-header-name-face)
837 (2 'message-header-name-face))
838 ,@(if (and mail-header-separator
839 (not (equal mail-header-separator "")))
840 `((,(concat "^\\(" (regexp-quote mail-header-separator) "\\)$")
841 1 'message-separator-face))
844 "\\([" cite-prefix "]+[" cite-suffix "]*\\)?"
846 (0 'message-cited-text-face))
847 ("<#/?\\(multipart\\|part\\|external\\).*>"
848 (0 'message-mml-face))))
849 "Additional expressions to highlight in Message mode.")
851 ;; XEmacs does it like this. For Emacs, we have to set the
852 ;; `font-lock-defaults' buffer-local variable.
853 (put 'message-mode 'font-lock-defaults '(message-font-lock-keywords t))
855 (defvar message-face-alist
856 '((bold . bold-region)
857 (underline . underline-region)
858 (default . (lambda (b e)
860 (ununderline-region b e))))
861 "Alist of mail and news faces for facemenu.
862 The cdr of ech entry is a function for applying the face to a region.")
864 (defcustom message-send-hook nil
865 "Hook run before sending messages."
866 :group 'message-various
867 :options '(ispell-message)
870 (defcustom message-send-mail-hook nil
871 "Hook run before sending mail messages."
872 :group 'message-various
875 (defcustom message-send-news-hook nil
876 "Hook run before sending news messages."
877 :group 'message-various
880 (defcustom message-sent-hook nil
881 "Hook run after sending messages."
882 :group 'message-various
885 (defvar message-send-coding-system 'binary
886 "Coding system to encode outgoing mail.")
888 (defvar message-draft-coding-system
889 mm-auto-save-coding-system
890 "Coding system to compose mail.")
892 ;;; Internal variables.
894 (defvar message-buffer-list nil)
895 (defvar message-this-is-news nil)
896 (defvar message-this-is-mail nil)
897 (defvar message-draft-article nil)
898 (defvar message-mime-part nil)
899 (defvar message-posting-charset nil)
901 ;; Byte-compiler warning
902 (defvar gnus-active-hashtb)
903 (defvar gnus-read-active-file)
905 ;;; Regexp matching the delimiter of messages in UNIX mail format
906 ;;; (UNIX From lines), minus the initial ^. It should be a copy
907 ;;; of rmail.el's rmail-unix-mail-delimiter.
908 (defvar message-unix-mail-delimiter
909 (let ((time-zone-regexp
910 (concat "\\([A-Z]?[A-Z]?[A-Z][A-Z]\\( DST\\)?"
911 "\\|[-+]?[0-9][0-9][0-9][0-9]"
917 ;; Many things can happen to an RFC 822 mailbox before it is put into
918 ;; a `From' line. The leading phrase can be stripped, e.g.
919 ;; `Joe <@w.x:joe@y.z>' -> `<@w.x:joe@y.z>'. The <> can be stripped, e.g.
920 ;; `<@x.y:joe@y.z>' -> `@x.y:joe@y.z'. Everything starting with a CRLF
921 ;; can be removed, e.g.
922 ;; From: joe@y.z (Joe K
924 ;; can yield `From joe@y.z (Joe K Fri Mar 22 08:11:15 1996', and
927 ;; can yield `From Joe User Fri Mar 22 08:11:15 1996'.
928 ;; The mailbox can be removed or be replaced by white space, e.g.
929 ;; From: "Joe User"{space}{tab}
931 ;; can yield `From {space}{tab} Fri Mar 22 08:11:15 1996',
932 ;; where {space} and {tab} represent the Ascii space and tab characters.
933 ;; We want to match the results of any of these manglings.
934 ;; The following regexp rejects names whose first characters are
935 ;; obviously bogus, but after that anything goes.
936 "\\([^\0-\b\n-\r\^?].*\\)? "
938 ;; The time the message was sent.
939 "\\([^\0-\r \^?]+\\) +" ; day of the week
940 "\\([^\0-\r \^?]+\\) +" ; month
941 "\\([0-3]?[0-9]\\) +" ; day of month
942 "\\([0-2][0-9]:[0-5][0-9]\\(:[0-6][0-9]\\)?\\) *" ; time of day
944 ;; Perhaps a time zone, specified by an abbreviation, or by a
949 " \\([0-9][0-9]+\\) *"
951 ;; On some systems the time zone can appear after the year, too.
955 "\\(remote from .*\\)?"
958 "Regexp matching the delimiter of messages in UNIX mail format.")
960 (defvar message-unsent-separator
961 (concat "^ *---+ +Unsent message follows +---+ *$\\|"
962 "^ *---+ +Returned message +---+ *$\\|"
963 "^Start of returned message$\\|"
964 "^ *---+ +Original message +---+ *$\\|"
965 "^ *--+ +begin message +--+ *$\\|"
966 "^ *---+ +Original message follows +---+ *$\\|"
967 "^ *---+ +Undelivered message follows +---+ *$\\|"
968 "^|? *---+ +Message text follows: +---+ *|?$")
969 "A regexp that matches the separator before the text of a failed message.")
971 (defvar message-header-format-alist
973 (To . message-fill-address)
974 (Cc . message-fill-address)
985 (References . message-shorten-references)
987 "Alist used for formatting headers.")
990 (autoload 'message-setup-toolbar "messagexmas")
991 (autoload 'mh-new-draft-name "mh-comp")
992 (autoload 'mh-send-letter "mh-comp")
993 (autoload 'gnus-point-at-eol "gnus-util")
994 (autoload 'gnus-point-at-bol "gnus-util")
995 (autoload 'gnus-output-to-mail "gnus-util")
996 (autoload 'mail-abbrev-in-expansion-header-p "mailabbrev")
997 (autoload 'nndraft-request-associate-buffer "nndraft")
998 (autoload 'nndraft-request-expire-articles "nndraft")
999 (autoload 'gnus-open-server "gnus-int")
1000 (autoload 'gnus-request-post "gnus-int")
1001 (autoload 'gnus-alive-p "gnus-util")
1002 (autoload 'rmail-output "rmail"))
1007 ;;; Utility functions.
1010 (defmacro message-y-or-n-p (question show &rest text)
1011 "Ask QUESTION, displaying the rest of the arguments in a temp. buffer if SHOW"
1012 `(message-talkative-question 'y-or-n-p ,question ,show ,@text))
1014 ;; Delete the current line (and the next N lines.);
1015 (defmacro message-delete-line (&optional n)
1016 `(delete-region (progn (beginning-of-line) (point))
1017 (progn (forward-line ,(or n 1)) (point))))
1019 (defun message-tokenize-header (header &optional separator)
1020 "Split HEADER into a list of header elements.
1021 \",\" is used as the separator."
1024 (let ((regexp (format "[%s]+" (or separator ",")))
1029 (message-set-work-buffer)
1031 (goto-char (point-min))
1036 (cond ((and (> (point) beg)
1038 (and (looking-at regexp)
1041 (push (buffer-substring beg (point)) elems)
1042 (setq beg (match-end 0)))
1043 ((eq (char-after) ?\")
1044 (setq quoted (not quoted)))
1045 ((and (eq (char-after) ?\()
1048 ((and (eq (char-after) ?\))
1051 (nreverse elems)))))
1053 (defun message-mail-file-mbox-p (file)
1054 "Say whether FILE looks like a Unix mbox file."
1055 (when (and (file-exists-p file)
1056 (file-readable-p file)
1057 (file-regular-p file))
1059 (nnheader-insert-file-contents file)
1060 (goto-char (point-min))
1061 (looking-at message-unix-mail-delimiter))))
1063 (defun message-fetch-field (header &optional not-all)
1064 "The same as `mail-fetch-field', only remove all newlines."
1065 (let* ((inhibit-point-motion-hooks t)
1066 (case-fold-search t)
1067 (value (mail-fetch-field header nil (not not-all))))
1069 (while (string-match "\n[\t ]+" value)
1070 (setq value (replace-match " " t t value)))
1071 ;; We remove all text props.
1072 (format "%s" value))))
1074 (defun message-narrow-to-field ()
1075 "Narrow the buffer to the header on the current line."
1081 (if (re-search-forward "^[^ \n\t]" nil t)
1086 (goto-char (point-min)))
1088 (defun message-add-header (&rest headers)
1089 "Add the HEADERS to the message header, skipping those already present."
1092 (unless (string-match "^\\([^:]+\\):[ \t]*[^ \t]" (car headers))
1093 (error "Invalid header `%s'" (car headers)))
1094 (setq hclean (match-string 1 (car headers)))
1096 (message-narrow-to-headers)
1097 (unless (re-search-forward (concat "^" (regexp-quote hclean) ":") nil t)
1098 (insert (car headers) ?\n))))
1099 (setq headers (cdr headers))))
1102 (defun message-fetch-reply-field (header)
1103 "Fetch FIELD from the message we're replying to."
1104 (when (and message-reply-buffer
1105 (buffer-name message-reply-buffer))
1107 (set-buffer message-reply-buffer)
1108 (message-fetch-field header))))
1110 (defun message-set-work-buffer ()
1111 (if (get-buffer " *message work*")
1113 (set-buffer " *message work*")
1115 (set-buffer (get-buffer-create " *message work*"))
1116 (kill-all-local-variables)
1117 (mm-enable-multibyte)))
1119 (defun message-functionp (form)
1120 "Return non-nil if FORM is funcallable."
1121 (or (and (symbolp form) (fboundp form))
1122 (and (listp form) (eq (car form) 'lambda))
1123 (byte-code-function-p form)))
1125 (defun message-strip-subject-re (subject)
1126 "Remove \"Re:\" from subject lines."
1127 (if (string-match message-subject-re-regexp subject)
1128 (substring subject (match-end 0))
1131 (defun message-remove-header (header &optional is-regexp first reverse)
1132 "Remove HEADER in the narrowed buffer.
1133 If REGEXP, HEADER is a regular expression.
1134 If FIRST, only remove the first instance of the header.
1135 Return the number of headers removed."
1136 (goto-char (point-min))
1137 (let ((regexp (if is-regexp header (concat "^" (regexp-quote header) ":")))
1139 (case-fold-search t)
1141 (while (and (not (eobp))
1144 (not (looking-at regexp))
1145 (looking-at regexp))
1152 ;; There might be a continuation header, so we have to search
1153 ;; until we find a new non-continuation line.
1156 (if (re-search-forward "^[^ \t]" nil t)
1157 (goto-char (match-beginning 0))
1160 (if (re-search-forward "^[^ \t]" nil t)
1161 (goto-char (match-beginning 0))
1162 (goto-char (point-max)))))
1165 (defun message-remove-first-header (header)
1166 "Remove the first instance of HEADER if there is more than one."
1168 (regexp (concat "^" (regexp-quote header) ":")))
1170 (goto-char (point-min))
1171 (while (re-search-forward regexp nil t)
1174 (message-remove-header header nil t)
1177 (defun message-narrow-to-headers ()
1178 "Narrow the buffer to the head of the message."
1181 (goto-char (point-min))
1182 (if (re-search-forward
1183 (concat "^" (regexp-quote mail-header-separator) "\n") nil t)
1186 (goto-char (point-min)))
1188 (defun message-narrow-to-head ()
1189 "Narrow the buffer to the head of the message.
1190 Point is left at the beginning of the narrowed-to region."
1193 (goto-char (point-min))
1194 (if (search-forward "\n\n" nil 1)
1197 (goto-char (point-min)))
1199 (defun message-narrow-to-headers-or-head ()
1200 "Narrow the buffer to the head of the message."
1203 (goto-char (point-min))
1206 (concat "^" (regexp-quote mail-header-separator) "\n") nil t)
1207 (match-beginning 0))
1208 ((search-forward "\n\n" nil t)
1212 (goto-char (point-min)))
1214 (defun message-news-p ()
1215 "Say whether the current buffer contains a news message."
1216 (and (not message-this-is-mail)
1217 (or message-this-is-news
1220 (message-narrow-to-headers)
1221 (and (message-fetch-field "newsgroups")
1222 (not (message-fetch-field "posted-to"))))))))
1224 (defun message-mail-p ()
1225 "Say whether the current buffer contains a mail message."
1226 (and (not message-this-is-news)
1227 (or message-this-is-mail
1230 (message-narrow-to-headers)
1231 (or (message-fetch-field "to")
1232 (message-fetch-field "cc")
1233 (message-fetch-field "bcc")))))))
1235 (defun message-next-header ()
1236 "Go to the beginning of the next header."
1238 (or (eobp) (forward-char 1))
1239 (not (if (re-search-forward "^[^ \t]" nil t)
1241 (goto-char (point-max)))))
1243 (defun message-sort-headers-1 ()
1244 "Sort the buffer as headers using `message-rank' text props."
1245 (goto-char (point-min))
1248 nil 'message-next-header
1250 (message-next-header)
1254 (or (get-text-property (point) 'message-rank)
1257 (defun message-sort-headers ()
1258 "Sort the headers of the current message according to `message-header-format-alist'."
1262 (let ((max (1+ (length message-header-format-alist)))
1264 (message-narrow-to-headers)
1265 (while (re-search-forward "^[^ \n]+:" nil t)
1267 (match-beginning 0) (1+ (match-beginning 0))
1269 (if (setq rank (length (memq (assq (intern (buffer-substring
1271 (1- (match-end 0))))
1272 message-header-format-alist)
1273 message-header-format-alist)))
1276 (message-sort-headers-1))))
1286 (defvar message-mode-map nil)
1288 (unless message-mode-map
1289 (setq message-mode-map (make-keymap))
1290 (set-keymap-parent message-mode-map text-mode-map)
1291 (define-key message-mode-map "\C-c?" 'describe-mode)
1293 (define-key message-mode-map "\C-c\C-f\C-t" 'message-goto-to)
1294 (define-key message-mode-map "\C-c\C-f\C-b" 'message-goto-bcc)
1295 (define-key message-mode-map "\C-c\C-f\C-w" 'message-goto-fcc)
1296 (define-key message-mode-map "\C-c\C-f\C-c" 'message-goto-cc)
1297 (define-key message-mode-map "\C-c\C-f\C-s" 'message-goto-subject)
1298 (define-key message-mode-map "\C-c\C-f\C-r" 'message-goto-reply-to)
1299 (define-key message-mode-map "\C-c\C-f\C-n" 'message-goto-newsgroups)
1300 (define-key message-mode-map "\C-c\C-f\C-d" 'message-goto-distribution)
1301 (define-key message-mode-map "\C-c\C-f\C-f" 'message-goto-followup-to)
1302 (define-key message-mode-map "\C-c\C-f\C-k" 'message-goto-keywords)
1303 (define-key message-mode-map "\C-c\C-f\C-u" 'message-goto-summary)
1304 (define-key message-mode-map "\C-c\C-b" 'message-goto-body)
1305 (define-key message-mode-map "\C-c\C-i" 'message-goto-signature)
1307 (define-key message-mode-map "\C-c\C-t" 'message-insert-to)
1308 (define-key message-mode-map "\C-c\C-n" 'message-insert-newsgroups)
1310 (define-key message-mode-map "\C-c\C-y" 'message-yank-original)
1311 (define-key message-mode-map "\C-c\M-\C-y" 'message-yank-buffer)
1312 (define-key message-mode-map "\C-c\C-q" 'message-fill-yanked-message)
1313 (define-key message-mode-map "\C-c\C-w" 'message-insert-signature)
1314 (define-key message-mode-map "\C-c\M-h" 'message-insert-headers)
1315 (define-key message-mode-map "\C-c\C-r" 'message-caesar-buffer-body)
1316 (define-key message-mode-map "\C-c\C-o" 'message-sort-headers)
1317 (define-key message-mode-map "\C-c\M-r" 'message-rename-buffer)
1319 (define-key message-mode-map "\C-c\C-c" 'message-send-and-exit)
1320 (define-key message-mode-map "\C-c\C-s" 'message-send)
1321 (define-key message-mode-map "\C-c\C-k" 'message-kill-buffer)
1322 (define-key message-mode-map "\C-c\C-d" 'message-dont-send)
1324 (define-key message-mode-map "\C-c\C-e" 'message-elide-region)
1325 (define-key message-mode-map "\C-c\C-v" 'message-delete-not-region)
1326 (define-key message-mode-map "\C-c\C-z" 'message-kill-to-signature)
1327 (define-key message-mode-map "\M-\r" 'message-newline-and-reformat)
1329 (define-key message-mode-map "\C-c\C-a" 'mml-attach-file)
1331 (define-key message-mode-map "\t" 'message-tab))
1334 message-mode-menu message-mode-map "Message Menu."
1336 ["Sort Headers" message-sort-headers t]
1337 ["Yank Original" message-yank-original t]
1338 ["Fill Yanked Message" message-fill-yanked-message t]
1339 ["Insert Signature" message-insert-signature t]
1340 ["Caesar (rot13) Message" message-caesar-buffer-body t]
1341 ["Caesar (rot13) Region" message-caesar-region (mark t)]
1342 ["Elide Region" message-elide-region (mark t)]
1343 ["Delete Outside Region" message-delete-not-region (mark t)]
1344 ["Kill To Signature" message-kill-to-signature t]
1345 ["Newline and Reformat" message-newline-and-reformat t]
1346 ["Rename buffer" message-rename-buffer t]
1347 ["Spellcheck" ispell-message t]
1348 ["Attach file as MIME" mml-attach-file t]
1350 ["Send Message" message-send-and-exit t]
1351 ["Abort Message" message-dont-send t]
1352 ["Kill Message" message-kill-buffer t]))
1355 message-mode-field-menu message-mode-map ""
1357 ["Fetch To" message-insert-to t]
1358 ["Fetch Newsgroups" message-insert-newsgroups t]
1360 ["To" message-goto-to t]
1361 ["Subject" message-goto-subject t]
1362 ["Cc" message-goto-cc t]
1363 ["Reply-To" message-goto-reply-to t]
1364 ["Summary" message-goto-summary t]
1365 ["Keywords" message-goto-keywords t]
1366 ["Newsgroups" message-goto-newsgroups t]
1367 ["Followup-To" message-goto-followup-to t]
1368 ["Distribution" message-goto-distribution t]
1369 ["Body" message-goto-body t]
1370 ["Signature" message-goto-signature t]))
1372 (defvar facemenu-add-face-function)
1373 (defvar facemenu-remove-face-function)
1376 (defun message-mode ()
1377 "Major mode for editing mail and news to be sent.
1378 Like Text Mode but with these additional commands:
1379 C-c C-s message-send (send the message) C-c C-c message-send-and-exit
1380 C-c C-d Pospone sending the message C-c C-k Kill the message
1381 C-c C-f move to a header field (and create it if there isn't):
1382 C-c C-f C-t move to To C-c C-f C-s move to Subject
1383 C-c C-f C-c move to Cc C-c C-f C-b move to Bcc
1384 C-c C-f C-w move to Fcc C-c C-f C-r move to Reply-To
1385 C-c C-f C-u move to Summary C-c C-f C-n move to Newsgroups
1386 C-c C-f C-k move to Keywords C-c C-f C-d move to Distribution
1387 C-c C-f C-f move to Followup-To
1388 C-c C-t message-insert-to (add a To header to a news followup)
1389 C-c C-n message-insert-newsgroups (add a Newsgroup header to a news reply)
1390 C-c C-b message-goto-body (move to beginning of message text).
1391 C-c C-i message-goto-signature (move to the beginning of the signature).
1392 C-c C-w message-insert-signature (insert `message-signature-file' file).
1393 C-c C-y message-yank-original (insert current message, if any).
1394 C-c C-q message-fill-yanked-message (fill what was yanked).
1395 C-c C-e message-elide-region (elide the text between point and mark).
1396 C-c C-v message-delete-not-region (remove the text outside the region).
1397 C-c C-z message-kill-to-signature (kill the text up to the signature).
1398 C-c C-r message-caesar-buffer-body (rot13 the message body).
1399 C-c C-a mml-attach-file (attach a file as MIME).
1400 M-RET message-newline-and-reformat (break the line and reformat)."
1402 (kill-all-local-variables)
1403 (set (make-local-variable 'message-reply-buffer) nil)
1404 (make-local-variable 'message-send-actions)
1405 (make-local-variable 'message-exit-actions)
1406 (make-local-variable 'message-kill-actions)
1407 (make-local-variable 'message-postpone-actions)
1408 (make-local-variable 'message-draft-article)
1409 (make-local-hook 'kill-buffer-hook)
1410 (set-syntax-table message-mode-syntax-table)
1411 (use-local-map message-mode-map)
1412 (setq local-abbrev-table message-mode-abbrev-table)
1413 (setq major-mode 'message-mode)
1414 (setq mode-name "Message")
1415 (setq buffer-offer-save t)
1416 (make-local-variable 'facemenu-add-face-function)
1417 (make-local-variable 'facemenu-remove-face-function)
1418 (setq facemenu-add-face-function
1420 (let ((face-fun (cdr (assq face message-face-alist))))
1422 (funcall face-fun (point) end)
1423 (error "Face %s not configured for %s mode" face mode-name)))
1425 facemenu-remove-face-function t)
1426 (make-local-variable 'paragraph-separate)
1427 (make-local-variable 'paragraph-start)
1428 ;; `-- ' precedes the signature. `-----' appears at the start of the
1429 ;; lines that delimit forwarded messages.
1430 ;; Lines containing just >= 3 dashes, perhaps after whitespace,
1431 ;; are also sometimes used and should be separators.
1432 (setq paragraph-start
1433 (concat (regexp-quote mail-header-separator)
1434 "$\\|[ \t]*[a-z0-9A-Z]*>+[ \t]*$\\|[ \t]*$\\|"
1437 ;;!!! Uhm... shurely this can't be right?
1438 "[> " (regexp-quote message-yank-prefix) "]+$"))
1439 (setq paragraph-separate paragraph-start)
1440 (make-local-variable 'message-reply-headers)
1441 (setq message-reply-headers nil)
1442 (make-local-variable 'message-newsreader)
1443 (make-local-variable 'message-mailer)
1444 (make-local-variable 'message-post-method)
1445 (set (make-local-variable 'message-sent-message-via) nil)
1446 (set (make-local-variable 'message-checksum) nil)
1447 (set (make-local-variable 'message-mime-part) 0)
1448 ;;(when (fboundp 'mail-hist-define-keys)
1449 ;; (mail-hist-define-keys))
1450 (when (string-match "XEmacs\\|Lucid" emacs-version)
1451 (message-setup-toolbar))
1452 (easy-menu-add message-mode-menu message-mode-map)
1453 (easy-menu-add message-mode-field-menu message-mode-map)
1454 ;; Allow mail alias things.
1455 (when (eq message-mail-alias-type 'abbrev)
1456 (if (fboundp 'mail-abbrevs-setup)
1457 (mail-abbrevs-setup)
1458 (mail-aliases-setup)))
1459 (message-set-auto-save-file-name)
1460 (unless (string-match "XEmacs" emacs-version)
1461 (set (make-local-variable 'font-lock-defaults)
1462 '(message-font-lock-keywords t)))
1463 (make-local-variable 'adaptive-fill-regexp)
1464 (setq adaptive-fill-regexp
1465 (concat "[ \t]*[-a-z0-9A-Z]*\\(>[ \t]*\\)+[ \t]*\\|" adaptive-fill-regexp))
1466 (unless (boundp 'adaptive-fill-first-line-regexp)
1467 (setq adaptive-fill-first-line-regexp nil))
1468 (make-local-variable 'adaptive-fill-first-line-regexp)
1469 (setq adaptive-fill-first-line-regexp
1470 (concat "[ \t]*[-a-z0-9A-Z]*\\(>[ \t]*\\)+[ \t]*\\|"
1471 adaptive-fill-first-line-regexp))
1472 (make-local-variable 'auto-fill-inhibit-regexp)
1473 (setq auto-fill-inhibit-regexp "^[A-Z][^: \n\t]+:")
1474 (mm-enable-multibyte)
1475 (make-local-variable 'indent-tabs-mode) ;Turn off tabs for indentation.
1476 (setq indent-tabs-mode nil)
1478 (run-hooks 'text-mode-hook 'message-mode-hook))
1483 ;;; Message mode commands
1486 ;;; Movement commands
1488 (defun message-goto-to ()
1489 "Move point to the To header."
1491 (message-position-on-field "To"))
1493 (defun message-goto-subject ()
1494 "Move point to the Subject header."
1496 (message-position-on-field "Subject"))
1498 (defun message-goto-cc ()
1499 "Move point to the Cc header."
1501 (message-position-on-field "Cc" "To"))
1503 (defun message-goto-bcc ()
1504 "Move point to the Bcc header."
1506 (message-position-on-field "Bcc" "Cc" "To"))
1508 (defun message-goto-fcc ()
1509 "Move point to the Fcc header."
1511 (message-position-on-field "Fcc" "To" "Newsgroups"))
1513 (defun message-goto-reply-to ()
1514 "Move point to the Reply-To header."
1516 (message-position-on-field "Reply-To" "Subject"))
1518 (defun message-goto-newsgroups ()
1519 "Move point to the Newsgroups header."
1521 (message-position-on-field "Newsgroups"))
1523 (defun message-goto-distribution ()
1524 "Move point to the Distribution header."
1526 (message-position-on-field "Distribution"))
1528 (defun message-goto-followup-to ()
1529 "Move point to the Followup-To header."
1531 (message-position-on-field "Followup-To" "Newsgroups"))
1533 (defun message-goto-keywords ()
1534 "Move point to the Keywords header."
1536 (message-position-on-field "Keywords" "Subject"))
1538 (defun message-goto-summary ()
1539 "Move point to the Summary header."
1541 (message-position-on-field "Summary" "Subject"))
1543 (defun message-goto-body ()
1544 "Move point to the beginning of the message body."
1546 (if (looking-at "[ \t]*\n") (expand-abbrev))
1547 (goto-char (point-min))
1548 (or (search-forward (concat "\n" mail-header-separator "\n") nil t)
1549 (search-forward "\n\n" nil t)))
1551 (defun message-goto-eoh ()
1552 "Move point to the end of the headers."
1557 (defun message-goto-signature ()
1558 "Move point to the beginning of the message signature.
1559 If there is no signature in the article, go to the end and
1562 (goto-char (point-min))
1563 (if (re-search-forward message-signature-separator nil t)
1565 (goto-char (point-max))
1570 (defun message-insert-to (&optional force)
1571 "Insert a To header that points to the author of the article being replied to.
1572 If the original author requested not to be sent mail, the function signals
1574 With the prefix argument FORCE, insert the header anyway."
1576 (let ((co (message-fetch-reply-field "mail-copies-to")))
1577 (when (and (null force)
1579 (or (equal (downcase co) "never")
1580 (equal (downcase co) "nobody")))
1581 (error "The user has requested not to have copies sent via mail")))
1582 (when (and (message-position-on-field "To")
1583 (mail-fetch-field "to")
1584 (not (string-match "\\` *\\'" (mail-fetch-field "to"))))
1586 (insert (or (message-fetch-reply-field "reply-to")
1587 (message-fetch-reply-field "from") "")))
1589 (defun message-widen-reply ()
1590 "Widen the reply to include maximum recipients."
1593 (and message-reply-buffer
1594 (buffer-name message-reply-buffer)
1596 (set-buffer message-reply-buffer)
1597 (message-get-reply-headers t)))))
1600 (message-narrow-to-headers)
1601 (dolist (elem follow-to)
1602 (message-remove-header (symbol-name (car elem)))
1603 (goto-char (point-min))
1604 (insert (symbol-name (car elem)) ": "
1605 (cdr elem) "\n"))))))
1607 (defun message-insert-newsgroups ()
1608 "Insert the Newsgroups header from the article being replied to."
1610 (when (and (message-position-on-field "Newsgroups")
1611 (mail-fetch-field "newsgroups")
1612 (not (string-match "\\` *\\'" (mail-fetch-field "newsgroups"))))
1614 (insert (or (message-fetch-reply-field "newsgroups") "")))
1618 ;;; Various commands
1620 (defun message-delete-not-region (beg end)
1621 "Delete everything in the body of the current message that is outside of the region."
1625 (delete-region (point) (if (not (message-goto-signature))
1631 (delete-region beg (progn (message-goto-body)
1634 (when (message-goto-signature)
1637 (defun message-kill-to-signature ()
1638 "Deletes all text up to the signature."
1640 (let ((point (point)))
1641 (message-goto-signature)
1644 (kill-region point (point))
1648 (defun message-newline-and-reformat ()
1649 "Insert four newlines, and then reformat if inside quoted text."
1651 (let ((prefix "[]>ยป|:}+ \t]*")
1652 (supercite-thing "[-._a-zA-Z0-9]*[>]+[ \t]*")
1657 (when (looking-at (concat prefix
1659 (setq quoted (match-string 0))))
1661 (setq point (point))
1663 (delete-region (point) (re-search-forward "[ \t]*"))
1666 (fill-paragraph nil)
1670 (defun message-insert-signature (&optional force)
1671 "Insert a signature. See documentation for the `message-signature' variable."
1672 (interactive (list 0))
1675 ((and (null message-signature)
1678 (goto-char (point-max))
1679 (not (re-search-backward message-signature-separator nil t))))
1680 ((and (null message-signature)
1683 ((message-functionp message-signature)
1684 (funcall message-signature))
1685 ((listp message-signature)
1686 (eval message-signature))
1687 (t message-signature)))
1689 (cond ((stringp signature)
1691 ((and (eq t signature)
1692 message-signature-file
1693 (file-exists-p message-signature-file))
1696 (goto-char (point-max))
1697 ;; Insert the signature.