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.
35 (defvar gnus-list-identifiers)) ; gnus-sum is required where necessary
39 ;; This is apparently necessary even though things are autoloaded:
40 (if (featurep 'xemacs)
41 (require 'mail-abbrevs))
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 quoting-style
170 redirected-followup signature approved sender empty empty-headers
171 message-id from subject shorten-followup-to existing-newsgroups
172 buffer-file-name unchanged newsgroups."
174 :type '(repeat sexp))
176 (defcustom message-required-news-headers
177 '(From Newsgroups Subject Date Message-ID
178 (optional . Organization) Lines
179 (optional . User-Agent))
180 "*Headers to be generated or prompted for when posting an article.
181 RFC977 and RFC1036 require From, Date, Newsgroups, Subject,
182 Message-ID. Organization, Lines, In-Reply-To, Expires, and
183 User-Agent are optional. If don't you want message to insert some
184 header, remove it from this list."
186 :group 'message-headers
187 :type '(repeat sexp))
189 (defcustom message-required-mail-headers
190 '(From Subject Date (optional . In-Reply-To) Message-ID Lines
191 (optional . User-Agent))
192 "*Headers to be generated or prompted for when mailing a message.
193 RFC822 required that From, Date, To, Subject and Message-ID be
194 included. Organization, Lines and User-Agent are optional."
196 :group 'message-headers
197 :type '(repeat sexp))
199 (defcustom message-deletable-headers '(Message-ID Date Lines)
200 "Headers to be deleted if they already exist and were generated by message previously."
201 :group 'message-headers
204 (defcustom message-ignored-news-headers
205 "^NNTP-Posting-Host:\\|^Xref:\\|^[BGF]cc:\\|^Resent-Fcc:"
206 "*Regexp of headers to be removed unconditionally before posting."
208 :group 'message-headers
211 (defcustom message-ignored-mail-headers "^[GF]cc:\\|^Resent-Fcc:\\|^Xref:"
212 "*Regexp of headers to be removed unconditionally before mailing."
214 :group 'message-headers
217 (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:"
218 "*Header lines matching this regexp will be deleted before posting.
219 It's best to delete old Path and Date headers before posting to avoid
221 :group 'message-interface
224 (defcustom message-subject-re-regexp "^[ \t]*\\([Rr][Ee]:[ \t]*\\)*[ \t]*"
225 "*Regexp matching \"Re: \" in the subject line."
226 :group 'message-various
230 (defcustom message-signature-separator "^-- *$"
231 "Regexp matching the signature separator."
233 :group 'message-various)
235 (defcustom message-elide-ellipsis "\n[...]\n\n"
236 "*The string which is inserted for elided text."
238 :group 'message-various)
240 (defcustom message-interactive nil
241 "Non-nil means when sending a message wait for and display errors.
242 nil means let mailer mail back a message to report errors."
243 :group 'message-sending
247 (defcustom message-generate-new-buffers 'unique
248 "*Non-nil means that a new message buffer will be created whenever `message-setup' is called.
249 If this is a function, call that function with three parameters: The type,
250 the to address and the group name. (Any of these may be nil.) The function
251 should return the new buffer name."
252 :group 'message-buffers
253 :type '(choice (const :tag "off" nil)
254 (const :tag "unique" unique)
255 (const :tag "unsent" unsent)
258 (defcustom message-kill-buffer-on-exit nil
259 "*Non-nil means that the message buffer will be killed after sending a message."
260 :group 'message-buffers
263 (defvar gnus-local-organization)
264 (defcustom message-user-organization
265 (or (and (boundp 'gnus-local-organization)
266 (stringp gnus-local-organization)
267 gnus-local-organization)
268 (getenv "ORGANIZATION")
270 "*String to be used as an Organization header.
271 If t, use `message-user-organization-file'."
272 :group 'message-headers
273 :type '(choice string
274 (const :tag "consult file" t)))
277 (defcustom message-user-organization-file "/usr/lib/news/organization"
278 "*Local news organization file."
280 :group 'message-headers)
282 (defcustom message-make-forward-subject-function
283 'message-forward-subject-author-subject
284 "*A list of functions that are called to generate a subject header for forwarded messages.
285 The subject generated by the previous function is passed into each
288 The provided functions are:
290 * message-forward-subject-author-subject (Source of article (author or
291 newsgroup)), in brackets followed by the subject
292 * message-forward-subject-fwd (Subject of article with 'Fwd:' prepended
294 :group 'message-forwarding
295 :type '(radio (function-item message-forward-subject-author-subject)
296 (function-item message-forward-subject-fwd)))
298 (defcustom message-forward-as-mime t
299 "*If non-nil, forward messages as an inline/rfc822 MIME section. Otherwise, directly inline the old message in the forwarded message."
300 :group 'message-forwarding
303 (defcustom message-forward-show-mml t
304 "*If non-nil, forward messages are shown as mml. Otherwise, forward messages are unchanged."
305 :group 'message-forwarding
308 (defcustom message-forward-before-signature t
309 "*If non-nil, put forwarded message before signature, else after."
310 :group 'message-forwarding
313 (defcustom message-wash-forwarded-subjects nil
314 "*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."
315 :group 'message-forwarding
318 (defcustom message-ignored-resent-headers "^Return-receipt\\|^X-Gnus\\|^Gnus-Warning:"
319 "*All headers that match this regexp will be deleted when resending a message."
320 :group 'message-interface
323 (defcustom message-forward-ignored-headers "^Content-Transfer-Encoding:\\|^X-Gnus"
324 "*All headers that match this regexp will be deleted when forwarding a message."
325 :group 'message-forwarding
326 :type '(choice (const :tag "None" nil)
329 (defcustom message-ignored-cited-headers "."
330 "*Delete these headers from the messages you yank."
331 :group 'message-insertion
334 (defcustom message-cite-prefix-regexp
335 ;; ?-, ?_ or ?. MUST NOT be in syntax entry w.
336 "\\([ \t]*\\(\\w\\|[-_.]\\)+>+\\|[ \t]*[]>»|:}+]\\)+"
337 "*Regexp matching the longest possible citation prefix on a line."
338 :group 'message-insertion
341 (defcustom message-cancel-message "I am canceling my own article.\n"
342 "Message to be inserted in the cancel message."
343 :group 'message-interface
346 ;; Useful to set in site-init.el
348 (defcustom message-send-mail-function 'message-send-mail-with-sendmail
349 "Function to call to send the current buffer as mail.
350 The headers should be delimited by a line whose contents match the
351 variable `mail-header-separator'.
353 Valid values include `message-send-mail-with-sendmail' (the default),
354 `message-send-mail-with-mh', `message-send-mail-with-qmail' and
356 :type '(radio (function-item message-send-mail-with-sendmail)
357 (function-item message-send-mail-with-mh)
358 (function-item message-send-mail-with-qmail)
359 (function-item smtpmail-send-it)
360 (function :tag "Other"))
361 :group 'message-sending
362 :group 'message-mail)
364 (defcustom message-send-news-function 'message-send-news
365 "Function to call to send the current buffer as news.
366 The headers should be delimited by a line whose contents match the
367 variable `mail-header-separator'."
368 :group 'message-sending
372 (defcustom message-reply-to-function nil
373 "Function that should return a list of headers.
374 This function should pick out addresses from the To, Cc, and From headers
375 and respond with new To and Cc headers."
376 :group 'message-interface
379 (defcustom message-wide-reply-to-function nil
380 "Function that should return a list of headers.
381 This function should pick out addresses from the To, Cc, and From headers
382 and respond with new To and Cc headers."
383 :group 'message-interface
386 (defcustom message-followup-to-function nil
387 "Function that should return a list of headers.
388 This function should pick out addresses from the To, Cc, and From headers
389 and respond with new To and Cc headers."
390 :group 'message-interface
393 (defcustom message-use-followup-to 'ask
394 "*Specifies what to do with Followup-To header.
395 If nil, always ignore the header. If it is t, use its value, but
396 query before using the \"poster\" value. If it is the symbol `ask',
397 always query the user whether to use the value. If it is the symbol
398 `use', always use the value."
399 :group 'message-interface
400 :type '(choice (const :tag "ignore" nil)
404 (defcustom message-sendmail-f-is-evil nil
405 "*Non-nil means that \"-f username\" should not be added to the sendmail command line.
406 Doing so would be even more evil than leaving it out."
407 :group 'message-sending
410 ;; qmail-related stuff
411 (defcustom message-qmail-inject-program "/var/qmail/bin/qmail-inject"
412 "Location of the qmail-inject program."
413 :group 'message-sending
416 (defcustom message-qmail-inject-args nil
417 "Arguments passed to qmail-inject programs.
418 This should be a list of strings, one string for each argument.
420 For e.g., if you wish to set the envelope sender address so that bounces
421 go to the right place or to deal with listserv's usage of that address, you
422 might set this variable to '(\"-f\" \"you@some.where\")."
423 :group 'message-sending
424 :type '(repeat string))
426 (defvar message-cater-to-broken-inn t
427 "Non-nil means Gnus should not fold the `References' header.
428 Folding `References' makes ancient versions of INN create incorrect
431 (defvar gnus-post-method)
432 (defvar gnus-select-method)
433 (defcustom message-post-method
434 (cond ((and (boundp 'gnus-post-method)
435 (listp gnus-post-method)
438 ((boundp 'gnus-select-method)
441 "*Method used to post news.
442 Note that when posting from inside Gnus, for instance, this
443 variable isn't used."
445 :group 'message-sending
446 ;; This should be the `gnus-select-method' widget, but that might
447 ;; create a dependence to `gnus.el'.
450 (defcustom message-generate-headers-first nil
451 "*If non-nil, generate all possible headers before composing."
452 :group 'message-headers
455 (defcustom message-setup-hook nil
456 "Normal hook, run each time a new outgoing message is initialized.
457 The function `message-setup' runs this hook."
458 :group 'message-various
461 (defcustom message-cancel-hook nil
462 "Hook run when cancelling articles."
463 :group 'message-various
466 (defcustom message-signature-setup-hook nil
467 "Normal hook, run each time a new outgoing message is initialized.
468 It is run after the headers have been inserted and before
469 the signature is inserted."
470 :group 'message-various
473 (defcustom message-mode-hook nil
474 "Hook run in message mode buffers."
475 :group 'message-various
478 (defcustom message-header-hook nil
479 "Hook run in a message mode buffer narrowed to the headers."
480 :group 'message-various
483 (defcustom message-header-setup-hook nil
484 "Hook called narrowed to the headers when setting up a message buffer."
485 :group 'message-various
489 (defcustom message-citation-line-function 'message-insert-citation-line
490 "*Function called to insert the \"Whomever writes:\" line."
492 :group 'message-insertion)
495 (defcustom message-yank-prefix "> "
496 "*Prefix inserted on the lines of yanked messages."
498 :group 'message-insertion)
500 (defcustom message-indentation-spaces 3
501 "*Number of spaces to insert at the beginning of each cited line.
502 Used by `message-yank-original' via `message-yank-cite'."
503 :group 'message-insertion
507 (defcustom message-cite-function 'message-cite-original
508 "*Function for citing an original message.
509 Predefined functions include `message-cite-original' and
510 `message-cite-original-without-signature'.
511 Note that `message-cite-original' uses `mail-citation-hook' if that is non-nil."
512 :type '(radio (function-item message-cite-original)
513 (function-item message-cite-original-without-signature)
514 (function-item sc-cite-original)
515 (function :tag "Other"))
516 :group 'message-insertion)
519 (defcustom message-indent-citation-function 'message-indent-citation
520 "*Function for modifying a citation just inserted in the mail buffer.
521 This can also be a list of functions. Each function can find the
522 citation between (point) and (mark t). And each function should leave
523 point and mark around the citation text as modified."
525 :group 'message-insertion)
527 (defvar message-abbrevs-loaded nil)
530 (defcustom message-signature t
531 "*String to be inserted at the end of the message buffer.
532 If t, the `message-signature-file' file will be inserted instead.
533 If a function, the result from the function will be used instead.
534 If a form, the result from the form will be used instead."
536 :group 'message-insertion)
539 (defcustom message-signature-file "~/.signature"
540 "*File containing the text inserted at end of message buffer."
542 :group 'message-insertion)
544 (defcustom message-distribution-function nil
545 "*Function called to return a Distribution header."
547 :group 'message-headers
550 (defcustom message-expires 14
551 "Number of days before your article expires."
553 :group 'message-headers
554 :link '(custom-manual "(message)News Headers")
557 (defcustom message-user-path nil
558 "If nil, use the NNTP server name in the Path header.
559 If stringp, use this; if non-nil, use no host name (user name only)."
561 :group 'message-headers
562 :link '(custom-manual "(message)News Headers")
563 :type '(choice (const :tag "nntp" nil)
565 (sexp :tag "none" :format "%t" t)))
567 (defvar message-reply-buffer nil)
568 (defvar message-reply-headers nil)
569 (defvar message-newsreader nil)
570 (defvar message-mailer nil)
571 (defvar message-sent-message-via nil)
572 (defvar message-checksum nil)
573 (defvar message-send-actions nil
574 "A list of actions to be performed upon successful sending of a message.")
575 (defvar message-exit-actions nil
576 "A list of actions to be performed upon exiting after sending a message.")
577 (defvar message-kill-actions nil
578 "A list of actions to be performed before killing a message buffer.")
579 (defvar message-postpone-actions nil
580 "A list of actions to be performed after postponing a message.")
582 (define-widget 'message-header-lines 'text
583 "All header lines must be LFD terminated."
586 :error "All header lines must be newline terminated")
588 (defcustom message-default-headers ""
589 "*A string containing header lines to be inserted in outgoing messages.
590 It is inserted before you edit the message, so you can edit or delete
592 :group 'message-headers
593 :type 'message-header-lines)
595 (defcustom message-default-mail-headers ""
596 "*A string of header lines to be inserted in outgoing mails."
597 :group 'message-headers
599 :type 'message-header-lines)
601 (defcustom message-default-news-headers ""
602 "*A string of header lines to be inserted in outgoing news articles."
603 :group 'message-headers
605 :type 'message-header-lines)
607 ;; Note: could use /usr/ucb/mail instead of sendmail;
608 ;; options -t, and -v if not interactive.
609 (defcustom message-mailer-swallows-blank-line
610 (if (and (string-match "sparc-sun-sunos\\(\\'\\|[^5]\\)"
611 system-configuration)
612 (file-readable-p "/etc/sendmail.cf")
613 (let ((buffer (get-buffer-create " *temp*")))
617 (insert-file-contents "/etc/sendmail.cf")
618 (goto-char (point-min))
619 (let ((case-fold-search nil))
620 (re-search-forward "^OR\\>" nil t)))
621 (kill-buffer buffer))))
622 ;; According to RFC822, "The field-name must be composed of printable
623 ;; ASCII characters (i. e., characters that have decimal values between
624 ;; 33 and 126, except colon)", i. e., any chars except ctl chars,
626 '(looking-at "[ \t]\\|[][!\"#$%&'()*+,-./0-9;<=>?@A-Z\\\\^_`a-z{|}~]+:"))
627 "*Set this non-nil if the system's mailer runs the header and body together.
628 \(This problem exists on Sunos 4 when sendmail is run in remote mode.)
629 The value should be an expression to test whether the problem will
631 :group 'message-sending
635 (define-mail-user-agent 'message-user-agent
636 'message-mail 'message-send-and-exit
637 'message-kill-buffer 'message-send-hook)
639 (defvar message-mh-deletable-headers '(Message-ID Date Lines Sender)
640 "If non-nil, delete the deletable headers before feeding to mh.")
642 (defvar message-send-method-alist
643 '((news message-news-p message-send-via-news)
644 (mail message-mail-p message-send-via-mail))
645 "Alist of ways to send outgoing messages.
646 Each element has the form
648 \(TYPE PREDICATE FUNCTION)
650 where TYPE is a symbol that names the method; PREDICATE is a function
651 called without any parameters to determine whether the message is
652 a message of type TYPE; and FUNCTION is a function to be called if
653 PREDICATE returns non-nil. FUNCTION is called with one parameter --
656 (defvar message-mail-alias-type 'abbrev
657 "*What alias expansion type to use in Message buffers.
658 The default is `abbrev', which uses mailabbrev. nil switches
661 (defcustom message-auto-save-directory
662 (nnheader-concat message-directory "drafts/")
663 "*Directory where Message auto-saves buffers if Gnus isn't running.
664 If nil, Message won't auto-save."
665 :group 'message-buffers
668 (defcustom message-buffer-naming-style 'unique
669 "*The way new message buffers are named.
670 Valid valued are `unique' and `unsent'."
671 :group 'message-buffers
672 :type '(choice (const :tag "unique" unique)
673 (const :tag "unsent" unsent)))
675 (defcustom message-default-charset
676 (and (not (mm-multibyte-p)) 'iso-8859-1)
677 "Default charset used in non-MULE Emacsen.
678 If nil, you might be asked to input the charset."
682 (defcustom message-dont-reply-to-names
683 (and (boundp 'rmail-dont-reply-to-names) rmail-dont-reply-to-names)
684 "*A regexp specifying names to prune when doing wide replies.
685 A value of nil means exclude your own name only."
687 :type '(choice (const :tag "Yourself" nil)
690 ;;; Internal variables.
691 ;;; Well, not really internal.
693 (defvar message-mode-syntax-table
694 (let ((table (copy-syntax-table text-mode-syntax-table)))
695 (modify-syntax-entry ?% ". " table)
696 (modify-syntax-entry ?> ". " table)
697 (modify-syntax-entry ?< ". " table)
699 "Syntax table used while in Message mode.")
701 (defvar message-mode-abbrev-table text-mode-abbrev-table
702 "Abbrev table used in Message mode buffers.
703 Defaults to `text-mode-abbrev-table'.")
704 (defgroup message-headers nil
706 :link '(custom-manual "(message)Variables")
709 (defface message-header-to-face
712 (:foreground "green2" :bold t))
715 (:foreground "MidnightBlue" :bold t))
717 (:bold t :italic t)))
718 "Face used for displaying From headers."
719 :group 'message-faces)
721 (defface message-header-cc-face
724 (:foreground "green4" :bold t))
727 (:foreground "MidnightBlue"))
730 "Face used for displaying Cc headers."
731 :group 'message-faces)
733 (defface message-header-subject-face
736 (:foreground "green3"))
739 (:foreground "navy blue" :bold t))
742 "Face used for displaying subject headers."
743 :group 'message-faces)
745 (defface message-header-newsgroups-face
748 (:foreground "yellow" :bold t :italic t))
751 (:foreground "blue4" :bold t :italic t))
753 (:bold t :italic t)))
754 "Face used for displaying newsgroups headers."
755 :group 'message-faces)
757 (defface message-header-other-face
760 (:foreground "#b00000"))
763 (:foreground "steel blue"))
765 (:bold t :italic t)))
766 "Face used for displaying newsgroups headers."
767 :group 'message-faces)
769 (defface message-header-name-face
772 (:foreground "DarkGreen"))
775 (:foreground "cornflower blue"))
778 "Face used for displaying header names."
779 :group 'message-faces)
781 (defface message-header-xheader-face
784 (:foreground "blue"))
787 (:foreground "blue"))
790 "Face used for displaying X-Header headers."
791 :group 'message-faces)
793 (defface message-separator-face
796 (:foreground "blue3"))
799 (:foreground "brown"))
802 "Face used for displaying the separator."
803 :group 'message-faces)
805 (defface message-cited-text-face
814 "Face used for displaying cited text names."
815 :group 'message-faces)
817 (defface message-mml-face
820 (:foreground "ForestGreen"))
823 (:foreground "ForestGreen"))
826 "Face used for displaying MML."
827 :group 'message-faces)
829 (defvar message-font-lock-keywords
830 (let ((content "[ \t]*\\(.+\\(\n[ \t].*\\)*\\)\n?"))
831 `((,(concat "^\\([Tt]o:\\)" content)
832 (1 'message-header-name-face)
833 (2 'message-header-to-face nil t))
834 (,(concat "^\\(^[GBF]?[Cc][Cc]:\\|^[Rr]eply-[Tt]o:\\)" content)
835 (1 'message-header-name-face)
836 (2 'message-header-cc-face nil t))
837 (,(concat "^\\([Ss]ubject:\\)" content)
838 (1 'message-header-name-face)
839 (2 'message-header-subject-face nil t))
840 (,(concat "^\\([Nn]ewsgroups:\\|Followup-[Tt]o:\\)" content)
841 (1 'message-header-name-face)
842 (2 'message-header-newsgroups-face nil t))
843 (,(concat "^\\([A-Z][^: \n\t]+:\\)" content)
844 (1 'message-header-name-face)
845 (2 'message-header-other-face nil t))
846 (,(concat "^\\(X-[A-Za-z0-9-]+\\|In-Reply-To\\):" content)
847 (1 'message-header-name-face)
848 (2 'message-header-name-face))
849 ,@(if (and mail-header-separator
850 (not (equal mail-header-separator "")))
851 `((,(concat "^\\(" (regexp-quote mail-header-separator) "\\)$")
852 1 'message-separator-face))
854 (,(concat "^\\(" message-cite-prefix-regexp "\\).*")
855 (0 'message-cited-text-face))
856 ("<#/?\\(multipart\\|part\\|external\\|mml\\).*>"
857 (0 'message-mml-face))))
858 "Additional expressions to highlight in Message mode.")
860 ;; XEmacs does it like this. For Emacs, we have to set the
861 ;; `font-lock-defaults' buffer-local variable.
862 (put 'message-mode 'font-lock-defaults '(message-font-lock-keywords t))
864 (defvar message-face-alist
865 '((bold . bold-region)
866 (underline . underline-region)
867 (default . (lambda (b e)
869 (ununderline-region b e))))
870 "Alist of mail and news faces for facemenu.
871 The cdr of ech entry is a function for applying the face to a region.")
873 (defcustom message-send-hook nil
874 "Hook run before sending messages."
875 :group 'message-various
876 :options '(ispell-message)
879 (defcustom message-send-mail-hook nil
880 "Hook run before sending mail messages."
881 :group 'message-various
884 (defcustom message-send-news-hook nil
885 "Hook run before sending news messages."
886 :group 'message-various
889 (defcustom message-sent-hook nil
890 "Hook run after sending messages."
891 :group 'message-various
894 (defvar message-send-coding-system 'binary
895 "Coding system to encode outgoing mail.")
897 (defvar message-draft-coding-system
898 mm-auto-save-coding-system
899 "Coding system to compose mail.")
901 (defcustom message-send-mail-partially-limit 1000000
902 "The limitation of messages sent as message/partial.
903 The lower bound of message size in characters, beyond which the message
904 should be sent in several parts. If it is nil, the size is unlimited."
905 :group 'message-buffers
906 :type '(choice (const :tag "unlimited" nil)
909 (defcustom message-alternative-emails nil
910 "A regexp to match the alternative email addresses.
911 The first matched address (not primary one) is used in the From field."
912 :group 'message-headers
913 :type '(choice (const :tag "Always use primary" nil)
916 ;;; Internal variables.
918 (defvar message-sending-message "Sending...")
919 (defvar message-buffer-list nil)
920 (defvar message-this-is-news nil)
921 (defvar message-this-is-mail nil)
922 (defvar message-draft-article nil)
923 (defvar message-mime-part nil)
924 (defvar message-posting-charset nil)
926 ;; Byte-compiler warning
927 (defvar gnus-active-hashtb)
928 (defvar gnus-read-active-file)
930 ;;; Regexp matching the delimiter of messages in UNIX mail format
931 ;;; (UNIX From lines), minus the initial ^. It should be a copy
932 ;;; of rmail.el's rmail-unix-mail-delimiter.
933 (defvar message-unix-mail-delimiter
934 (let ((time-zone-regexp
935 (concat "\\([A-Z]?[A-Z]?[A-Z][A-Z]\\( DST\\)?"
936 "\\|[-+]?[0-9][0-9][0-9][0-9]"
942 ;; Many things can happen to an RFC 822 mailbox before it is put into
943 ;; a `From' line. The leading phrase can be stripped, e.g.
944 ;; `Joe <@w.x:joe@y.z>' -> `<@w.x:joe@y.z>'. The <> can be stripped, e.g.
945 ;; `<@x.y:joe@y.z>' -> `@x.y:joe@y.z'. Everything starting with a CRLF
946 ;; can be removed, e.g.
947 ;; From: joe@y.z (Joe K
949 ;; can yield `From joe@y.z (Joe K Fri Mar 22 08:11:15 1996', and
952 ;; can yield `From Joe User Fri Mar 22 08:11:15 1996'.
953 ;; The mailbox can be removed or be replaced by white space, e.g.
954 ;; From: "Joe User"{space}{tab}
956 ;; can yield `From {space}{tab} Fri Mar 22 08:11:15 1996',
957 ;; where {space} and {tab} represent the Ascii space and tab characters.
958 ;; We want to match the results of any of these manglings.
959 ;; The following regexp rejects names whose first characters are
960 ;; obviously bogus, but after that anything goes.
961 "\\([^\0-\b\n-\r\^?].*\\)? "
963 ;; The time the message was sent.
964 "\\([^\0-\r \^?]+\\) +" ; day of the week
965 "\\([^\0-\r \^?]+\\) +" ; month
966 "\\([0-3]?[0-9]\\) +" ; day of month
967 "\\([0-2][0-9]:[0-5][0-9]\\(:[0-6][0-9]\\)?\\) *" ; time of day
969 ;; Perhaps a time zone, specified by an abbreviation, or by a
974 " \\([0-9][0-9]+\\) *"
976 ;; On some systems the time zone can appear after the year, too.
980 "\\(remote from .*\\)?"
983 "Regexp matching the delimiter of messages in UNIX mail format.")
985 (defvar message-unsent-separator
986 (concat "^ *---+ +Unsent message follows +---+ *$\\|"
987 "^ *---+ +Returned message +---+ *$\\|"
988 "^Start of returned message$\\|"
989 "^ *---+ +Original message +---+ *$\\|"
990 "^ *--+ +begin message +--+ *$\\|"
991 "^ *---+ +Original message follows +---+ *$\\|"
992 "^ *---+ +Undelivered message follows +---+ *$\\|"
993 "^|? *---+ +Message text follows: +---+ *|?$")
994 "A regexp that matches the separator before the text of a failed message.")
996 (defvar message-header-format-alist
998 (To . message-fill-address)
999 (Cc . message-fill-address)
1010 (References . message-shorten-references)
1012 "Alist used for formatting headers.")
1014 (defvar message-options nil
1015 "Some saved answers when sending message.")
1018 (autoload 'message-setup-toolbar "messagexmas")
1019 (autoload 'mh-new-draft-name "mh-comp")
1020 (autoload 'mh-send-letter "mh-comp")
1021 (autoload 'gnus-point-at-eol "gnus-util")
1022 (autoload 'gnus-point-at-bol "gnus-util")
1023 (autoload 'gnus-output-to-rmail "gnus-util")
1024 (autoload 'gnus-output-to-mail "gnus-util")
1025 (autoload 'mail-abbrev-in-expansion-header-p "mailabbrev")
1026 (autoload 'nndraft-request-associate-buffer "nndraft")
1027 (autoload 'nndraft-request-expire-articles "nndraft")
1028 (autoload 'gnus-open-server "gnus-int")
1029 (autoload 'gnus-request-post "gnus-int")
1030 (autoload 'gnus-alive-p "gnus-util")
1031 (autoload 'gnus-group-name-charset "gnus-group")
1032 (autoload 'rmail-output "rmail"))
1037 ;;; Utility functions.
1040 (defmacro message-y-or-n-p (question show &rest text)
1041 "Ask QUESTION, displaying the rest of the arguments in a temp. buffer if SHOW"
1042 `(message-talkative-question 'y-or-n-p ,question ,show ,@text))
1044 ;; Delete the current line (and the next N lines.);
1045 (defmacro message-delete-line (&optional n)
1046 `(delete-region (progn (beginning-of-line) (point))
1047 (progn (forward-line ,(or n 1)) (point))))
1049 (defun message-unquote-tokens (elems)
1050 "Remove double quotes (\") from strings in list."
1051 (mapcar (lambda (item)
1052 (while (string-match "^\\(.*\\)\"\\(.*\\)$" item)
1053 (setq item (concat (match-string 1 item)
1054 (match-string 2 item))))
1058 (defun message-tokenize-header (header &optional separator)
1059 "Split HEADER into a list of header elements.
1060 SEPARATOR is a string of characters to be used as separators. \",\"
1061 is used by default."
1064 (let ((regexp (format "[%s]+" (or separator ",")))
1069 (message-set-work-buffer)
1071 (goto-char (point-min))
1076 (cond ((and (> (point) beg)
1078 (and (looking-at regexp)
1081 (push (buffer-substring beg (point)) elems)
1082 (setq beg (match-end 0)))
1083 ((eq (char-after) ?\")
1084 (setq quoted (not quoted)))
1085 ((and (eq (char-after) ?\()
1088 ((and (eq (char-after) ?\))
1091 (nreverse elems)))))
1093 (defun message-mail-file-mbox-p (file)
1094 "Say whether FILE looks like a Unix mbox file."
1095 (when (and (file-exists-p file)
1096 (file-readable-p file)
1097 (file-regular-p file))
1099 (nnheader-insert-file-contents file)
1100 (goto-char (point-min))
1101 (looking-at message-unix-mail-delimiter))))
1103 (defun message-fetch-field (header &optional not-all)
1104 "The same as `mail-fetch-field', only remove all newlines."
1105 (let* ((inhibit-point-motion-hooks t)
1106 (case-fold-search t)
1107 (value (mail-fetch-field header nil (not not-all))))
1109 (while (string-match "\n[\t ]+" value)
1110 (setq value (replace-match " " t t value)))
1111 (set-text-properties 0 (length value) nil value)
1114 (defun message-narrow-to-field ()
1115 "Narrow the buffer to the header on the current line."
1121 (if (re-search-forward "^[^ \n\t]" nil t)
1126 (goto-char (point-min)))
1128 (defun message-add-header (&rest headers)
1129 "Add the HEADERS to the message header, skipping those already present."
1132 (unless (string-match "^\\([^:]+\\):[ \t]*[^ \t]" (car headers))
1133 (error "Invalid header `%s'" (car headers)))
1134 (setq hclean (match-string 1 (car headers)))
1136 (message-narrow-to-headers)
1137 (unless (re-search-forward (concat "^" (regexp-quote hclean) ":") nil t)
1138 (insert (car headers) ?\n))))
1139 (setq headers (cdr headers))))
1142 (defun message-fetch-reply-field (header)
1143 "Fetch FIELD from the message we're replying to."
1144 (when (and message-reply-buffer
1145 (buffer-name message-reply-buffer))
1147 (set-buffer message-reply-buffer)
1148 (message-fetch-field header))))
1150 (defun message-set-work-buffer ()
1151 (if (get-buffer " *message work*")
1153 (set-buffer " *message work*")
1155 (set-buffer (get-buffer-create " *message work*"))
1156 (kill-all-local-variables)
1157 (mm-enable-multibyte)))
1159 (defun message-functionp (form)
1160 "Return non-nil if FORM is funcallable."
1161 (or (and (symbolp form) (fboundp form))
1162 (and (listp form) (eq (car form) 'lambda))
1163 (byte-code-function-p form)))
1165 (defun message-strip-list-identifiers (subject)
1166 "Remove list identifiers in `gnus-list-identifiers'."
1167 (require 'gnus-sum) ; for gnus-list-identifiers
1168 (let ((regexp (if (stringp gnus-list-identifiers)
1169 gnus-list-identifiers
1170 (mapconcat 'identity gnus-list-identifiers " *\\|"))))
1171 (if (string-match (concat "\\(\\(\\(Re: +\\)?\\(" regexp
1172 " *\\)\\)+\\(Re: +\\)?\\)") subject)
1173 (concat (substring subject 0 (match-beginning 1))
1174 (or (match-string 3 subject)
1175 (match-string 5 subject))
1180 (defun message-strip-subject-re (subject)
1181 "Remove \"Re:\" from subject lines."
1182 (if (string-match message-subject-re-regexp subject)
1183 (substring subject (match-end 0))
1186 (defun message-remove-header (header &optional is-regexp first reverse)
1187 "Remove HEADER in the narrowed buffer.
1188 If REGEXP, HEADER is a regular expression.
1189 If FIRST, only remove the first instance of the header.
1190 Return the number of headers removed."
1191 (goto-char (point-min))
1192 (let ((regexp (if is-regexp header (concat "^" (regexp-quote header) ":")))
1194 (case-fold-search t)
1196 (while (and (not (eobp))
1199 (not (looking-at regexp))
1200 (looking-at regexp))
1207 ;; There might be a continuation header, so we have to search
1208 ;; until we find a new non-continuation line.
1211 (if (re-search-forward "^[^ \t]" nil t)
1212 (goto-char (match-beginning 0))
1215 (if (re-search-forward "^[^ \t]" nil t)
1216 (goto-char (match-beginning 0))
1217 (goto-char (point-max)))))
1220 (defun message-remove-first-header (header)
1221 "Remove the first instance of HEADER if there is more than one."
1223 (regexp (concat "^" (regexp-quote header) ":")))
1225 (goto-char (point-min))
1226 (while (re-search-forward regexp nil t)
1229 (message-remove-header header nil t)
1232 (defun message-narrow-to-headers ()
1233 "Narrow the buffer to the head of the message."
1236 (goto-char (point-min))
1237 (if (re-search-forward
1238 (concat "^" (regexp-quote mail-header-separator) "\n") nil t)
1241 (goto-char (point-min)))
1243 (defun message-narrow-to-head ()
1244 "Narrow the buffer to the head of the message.
1245 Point is left at the beginning of the narrowed-to region."
1248 (goto-char (point-min))
1249 (if (search-forward "\n\n" nil 1)
1252 (goto-char (point-min)))
1254 (defun message-narrow-to-headers-or-head ()
1255 "Narrow the buffer to the head of the message."
1258 (goto-char (point-min))
1261 (concat "^" (regexp-quote mail-header-separator) "\n") nil t)
1262 (match-beginning 0))
1263 ((search-forward "\n\n" nil t)
1267 (goto-char (point-min)))
1269 (defun message-news-p ()
1270 "Say whether the current buffer contains a news message."
1271 (and (not message-this-is-mail)
1272 (or message-this-is-news
1275 (message-narrow-to-headers)
1276 (and (message-fetch-field "newsgroups")
1277 (not (message-fetch-field "posted-to"))))))))
1279 (defun message-mail-p ()
1280 "Say whether the current buffer contains a mail message."
1281 (and (not message-this-is-news)
1282 (or message-this-is-mail
1285 (message-narrow-to-headers)
1286 (or (message-fetch-field "to")
1287 (message-fetch-field "cc")
1288 (message-fetch-field "bcc")))))))
1290 (defun message-next-header ()
1291 "Go to the beginning of the next header."
1293 (or (eobp) (forward-char 1))
1294 (not (if (re-search-forward "^[^ \t]" nil t)
1296 (goto-char (point-max)))))
1298 (defun message-sort-headers-1 ()
1299 "Sort the buffer as headers using `message-rank' text props."
1300 (goto-char (point-min))
1303 nil 'message-next-header
1305 (message-next-header)
1309 (or (get-text-property (point) 'message-rank)
1312 (defun message-sort-headers ()
1313 "Sort the headers of the current message according to `message-header-format-alist'."
1317 (let ((max (1+ (length message-header-format-alist)))
1319 (message-narrow-to-headers)
1320 (while (re-search-forward "^[^ \n]+:" nil t)
1322 (match-beginning 0) (1+ (match-beginning 0))
1324 (if (setq rank (length (memq (assq (intern (buffer-substring
1326 (1- (match-end 0))))
1327 message-header-format-alist)
1328 message-header-format-alist)))
1331 (message-sort-headers-1))))
1341 (defvar message-mode-map nil)
1343 (unless message-mode-map
1344 (setq message-mode-map (make-keymap))
1345 (set-keymap-parent message-mode-map text-mode-map)
1346 (define-key message-mode-map "\C-c?" 'describe-mode)
1348 (define-key message-mode-map "\C-c\C-f\C-t" 'message-goto-to)
1349 (define-key message-mode-map "\C-c\C-f\C-b" 'message-goto-bcc)
1350 (define-key message-mode-map "\C-c\C-f\C-w" 'message-goto-fcc)
1351 (define-key message-mode-map "\C-c\C-f\C-c" 'message-goto-cc)
1352 (define-key message-mode-map "\C-c\C-f\C-s" 'message-goto-subject)
1353 (define-key message-mode-map "\C-c\C-f\C-r" 'message-goto-reply-to)
1354 (define-key message-mode-map "\C-c\C-f\C-n" 'message-goto-newsgroups)
1355 (define-key message-mode-map "\C-c\C-f\C-d" 'message-goto-distribution)
1356 (define-key message-mode-map "\C-c\C-f\C-f" 'message-goto-followup-to)
1357 (define-key message-mode-map "\C-c\C-f\C-k" 'message-goto-keywords)
1358 (define-key message-mode-map "\C-c\C-f\C-u" 'message-goto-summary)
1359 (define-key message-mode-map "\C-c\C-b" 'message-goto-body)
1360 (define-key message-mode-map "\C-c\C-i" 'message-goto-signature)
1362 (define-key message-mode-map "\C-c\C-t" 'message-insert-to)
1363 (define-key message-mode-map "\C-c\C-n" 'message-insert-newsgroups)
1365 (define-key message-mode-map "\C-c\C-y" 'message-yank-original)
1366 (define-key message-mode-map "\C-c\M-\C-y" 'message-yank-buffer)
1367 (define-key message-mode-map "\C-c\C-q" 'message-fill-yanked-message)
1368 (define-key message-mode-map "\C-c\C-w" 'message-insert-signature)
1369 (define-key message-mode-map "\C-c\M-h" 'message-insert-headers)
1370 (define-key message-mode-map "\C-c\C-r" 'message-caesar-buffer-body)
1371 (define-key message-mode-map "\C-c\C-o" 'message-sort-headers)
1372 (define-key message-mode-map "\C-c\M-r" 'message-rename-buffer)
1374 (define-key message-mode-map "\C-c\C-c" 'message-send-and-exit)
1375 (define-key message-mode-map "\C-c\C-s" 'message-send)
1376 (define-key message-mode-map "\C-c\C-k" 'message-kill-buffer)
1377 (define-key message-mode-map "\C-c\C-d" 'message-dont-send)
1379 (define-key message-mode-map "\C-c\C-e" 'message-elide-region)
1380 (define-key message-mode-map "\C-c\C-v" 'message-delete-not-region)
1381 (define-key message-mode-map "\C-c\C-z" 'message-kill-to-signature)
1382 (define-key message-mode-map "\M-\r" 'message-newline-and-reformat)
1384 (define-key message-mode-map "\C-c\C-a" 'mml-attach-file)
1386 (define-key message-mode-map "\t" 'message-tab))
1389 message-mode-menu message-mode-map "Message Menu."
1391 ["Sort Headers" message-sort-headers t]
1392 ["Yank Original" message-yank-original t]
1393 ["Fill Yanked Message" message-fill-yanked-message t]
1394 ["Insert Signature" message-insert-signature t]
1395 ["Caesar (rot13) Message" message-caesar-buffer-body t]
1396 ["Caesar (rot13) Region" message-caesar-region (mark t)]
1397 ["Elide Region" message-elide-region (mark t)]
1398 ["Delete Outside Region" message-delete-not-region (mark t)]
1399 ["Kill To Signature" message-kill-to-signature t]
1400 ["Newline and Reformat" message-newline-and-reformat t]
1401 ["Rename buffer" message-rename-buffer t]
1402 ["Spellcheck" ispell-message t]
1403 ["Attach file as MIME" mml-attach-file t]
1405 ["Send Message" message-send-and-exit t]
1406 ["Abort Message" message-dont-send t]
1407 ["Kill Message" message-kill-buffer t]))
1410 message-mode-field-menu message-mode-map ""
1412 ["Fetch To" message-insert-to t]
1413 ["Fetch Newsgroups" message-insert-newsgroups t]
1415 ["To" message-goto-to t]
1416 ["Subject" message-goto-subject t]
1417 ["Cc" message-goto-cc t]
1418 ["Reply-To" message-goto-reply-to t]
1419 ["Summary" message-goto-summary t]
1420 ["Keywords" message-goto-keywords t]
1421 ["Newsgroups" message-goto-newsgroups t]
1422 ["Followup-To" message-goto-followup-to t]
1423 ["Distribution" message-goto-distribution t]
1424 ["Body" message-goto-body t]
1425 ["Signature" message-goto-signature t]))
1427 (defvar facemenu-add-face-function)
1428 (defvar facemenu-remove-face-function)
1431 (defun message-mode ()
1432 "Major mode for editing mail and news to be sent.
1433 Like Text Mode but with these additional commands:
1434 C-c C-s message-send (send the message) C-c C-c message-send-and-exit
1435 C-c C-d Pospone sending the message C-c C-k Kill the message
1436 C-c C-f move to a header field (and create it if there isn't):
1437 C-c C-f C-t move to To C-c C-f C-s move to Subject
1438 C-c C-f C-c move to Cc C-c C-f C-b move to Bcc
1439 C-c C-f C-w move to Fcc C-c C-f C-r move to Reply-To
1440 C-c C-f C-u move to Summary C-c C-f C-n move to Newsgroups
1441 C-c C-f C-k move to Keywords C-c C-f C-d move to Distribution
1442 C-c C-f C-f move to Followup-To
1443 C-c C-t message-insert-to (add a To header to a news followup)
1444 C-c C-n message-insert-newsgroups (add a Newsgroup header to a news reply)
1445 C-c C-b message-goto-body (move to beginning of message text).
1446 C-c C-i message-goto-signature (move to the beginning of the signature).
1447 C-c C-w message-insert-signature (insert `message-signature-file' file).
1448 C-c C-y message-yank-original (insert current message, if any).
1449 C-c C-q message-fill-yanked-message (fill what was yanked).
1450 C-c C-e message-elide-region (elide the text between point and mark).
1451 C-c C-v message-delete-not-region (remove the text outside the region).
1452 C-c C-z message-kill-to-signature (kill the text up to the signature).
1453 C-c C-r message-caesar-buffer-body (rot13 the message body).
1454 C-c C-a mml-attach-file (attach a file as MIME).
1455 M-RET message-newline-and-reformat (break the line and reformat)."
1457 (if (local-variable-p 'mml-buffer-list (current-buffer))
1458 (mml-destroy-buffers))
1459 (kill-all-local-variables)
1460 (set (make-local-variable 'message-reply-buffer) nil)
1461 (make-local-variable 'message-send-actions)
1462 (make-local-variable 'message-exit-actions)
1463 (make-local-variable 'message-kill-actions)
1464 (make-local-variable 'message-postpone-actions)
1465 (make-local-variable 'message-draft-article)
1466 (make-local-hook 'kill-buffer-hook)
1467 (set-syntax-table message-mode-syntax-table)
1468 (use-local-map message-mode-map)
1469 (setq local-abbrev-table message-mode-abbrev-table)
1470 (setq major-mode 'message-mode)
1471 (setq mode-name "Message")
1472 (setq buffer-offer-save t)
1473 (make-local-variable 'facemenu-add-face-function)
1474 (make-local-variable 'facemenu-remove-face-function)
1475 (setq facemenu-add-face-function
1477 (let ((face-fun (cdr (assq face message-face-alist))))
1479 (funcall face-fun (point) end)
1480 (error "Face %s not configured for %s mode" face mode-name)))
1482 facemenu-remove-face-function t)
1483 (make-local-variable 'message-reply-headers)
1484 (setq message-reply-headers nil)
1485 (make-local-variable 'message-newsreader)
1486 (make-local-variable 'message-mailer)
1487 (make-local-variable 'message-post-method)
1488 (set (make-local-variable 'message-sent-message-via) nil)
1489 (set (make-local-variable 'message-checksum) nil)
1490 (set (make-local-variable 'message-mime-part) 0)
1491 (message-setup-fill-variables)
1492 ;;(when (fboundp 'mail-hist-define-keys)
1493 ;; (mail-hist-define-keys))
1494 (if (featurep 'xemacs)
1495 (message-setup-toolbar)
1496 (set (make-local-variable 'font-lock-defaults)
1497 '(message-font-lock-keywords t)))
1498 (easy-menu-add message-mode-menu message-mode-map)
1499 (easy-menu-add message-mode-field-menu message-mode-map)
1500 ;; Allow mail alias things.
1501 (when (eq message-mail-alias-type 'abbrev)
1502 (if (fboundp 'mail-abbrevs-setup)
1503 (mail-abbrevs-setup)
1504 (mail-aliases-setup)))
1505 (message-set-auto-save-file-name)
1506 (mm-enable-multibyte)
1507 (make-local-variable 'indent-tabs-mode) ;Turn off tabs for indentation.
1508 (setq indent-tabs-mode nil)
1510 (run-hooks 'text-mode-hook 'message-mode-hook))
1512 (defun message-setup-fill-variables ()
1513 "Setup message fill variables."
1514 (make-local-variable 'paragraph-separate)
1515 (make-local-variable 'paragraph-start)
1516 (make-local-variable 'adaptive-fill-regexp)
1517 (unless (boundp 'adaptive-fill-first-line-regexp)
1518 (setq adaptive-fill-first-line-regexp nil))
1519 (make-local-variable 'adaptive-fill-first-line-regexp)
1520 (make-local-variable 'auto-fill-inhibit-regexp)
1521 (let ((quote-prefix-regexp
1523 "[ \t]*" ; possible initial space
1524 "\\(\\(" (regexp-quote message-yank-prefix) "\\|" ; user's prefix
1525 "\\(\\w\\|[-_.]\\)+>\\|" ; supercite-style prefix
1526 "[|:>]" ; standard prefix
1527 "\\)[ \t]*\\)+"))) ; possible space after each prefix
1528 (setq paragraph-start
1530 (regexp-quote mail-header-separator) "$\\|"
1531 "[ \t]*$\\|" ; blank lines
1532 "-- $\\|" ; signature delimiter
1533 "---+$\\|" ; delimiters for forwarded messages
1534 page-delimiter "$\\|" ; spoiler warnings
1535 ".*wrote:$\\|" ; attribution lines
1536 quote-prefix-regexp "$")) ; empty lines in quoted text
1537 (setq paragraph-separate paragraph-start)
1538 (setq adaptive-fill-regexp
1539 (concat quote-prefix-regexp "\\|" adaptive-fill-regexp))
1540 (setq adaptive-fill-first-line-regexp
1541 (concat quote-prefix-regexp "\\|"
1542 adaptive-fill-first-line-regexp))
1543 (setq auto-fill-inhibit-regexp "^[A-Z][^: \n\t]+:")))
1548 ;;; Message mode commands
1551 ;;; Movement commands
1553 (defun message-goto-to ()
1554 "Move point to the To header."
1556 (message-position-on-field "To"))
1558 (defun message-goto-subject ()
1559 "Move point to the Subject header."
1561 (message-position-on-field "Subject"))
1563 (defun message-goto-cc ()
1564 "Move point to the Cc header."
1566 (message-position-on-field "Cc" "To"))
1568 (defun message-goto-bcc ()
1569 "Move point to the Bcc header."
1571 (message-position-on-field "Bcc" "Cc" "To"))
1573 (defun message-goto-fcc ()
1574 "Move point to the Fcc header."
1576 (message-position-on-field "Fcc" "To" "Newsgroups"))
1578 (defun message-goto-reply-to ()
1579 "Move point to the Reply-To header."
1581 (message-position-on-field "Reply-To" "Subject"))
1583 (defun message-goto-newsgroups ()
1584 "Move point to the Newsgroups header."
1586 (message-position-on-field "Newsgroups"))
1588 (defun message-goto-distribution ()
1589 "Move point to the Distribution header."
1591 (message-position-on-field "Distribution"))
1593 (defun message-goto-followup-to ()
1594 "Move point to the Followup-To header."
1596 (message-position-on-field "Followup-To" "Newsgroups"))
1598 (defun message-goto-keywords ()
1599 "Move point to the Keywords header."
1601 (message-position-on-field "Keywords" "Subject"))
1603 (defun message-goto-summary ()
1604 "Move point to the Summary header."
1606 (message-position-on-field "Summary" "Subject"))
1608 (defun message-goto-body ()
1609 "Move point to the beginning of the message body."
1611 (if (looking-at "[ \t]*\n") (expand-abbrev))
1612 (goto-char (point-min))
1613 (or (search-forward (concat "\n" mail-header-separator "\n") nil t)
1614 (search-forward "\n\n" nil t)))
1616 (defun message-goto-eoh ()
1617 "Move point to the end of the headers."
1622 (defun message-goto-signature ()
1623 "Move point to the beginning of the message signature.
1624 If there is no signature in the article, go to the end and
1627 (goto-char (point-min))
1628 (if (re-search-forward message-signature-separator nil t)
1630 (goto-char (point-max))
1635 (defun message-insert-to (&optional force)
1636 "Insert a To header that points to the author of the article being replied to.
1637 If the original author requested not to be sent mail, the function signals
1639 With the prefix argument FORCE, insert the header anyway."
1641 (let ((co (message-fetch-reply-field "mail-copies-to")))
1642 (when (and (null force)
1644 (or (equal (downcase co) "never")
1645 (equal (downcase co) "nobody")))
1646 (error "The user has requested not to have copies sent via mail")))
1647 (when (and (message-position-on-field "To")
1648 (mail-fetch-field "to")
1649 (not (string-match "\\` *\\'" (mail-fetch-field "to"))))
1651 (insert (or (message-fetch-reply-field "mail-reply-to")
1652 (message-fetch-reply-field "reply-to")
1653 (message-fetch-reply-field "from") "")))
1655 (defun message-widen-reply ()
1656 "Widen the reply to include maximum recipients."
1659 (and message-reply-buffer
1660 (buffer-name message-reply-buffer)
1662 (set-buffer message-reply-buffer)
1663 (message-get-reply-headers t)))))
1666 (message-narrow-to-headers)
1667 (dolist (elem follow-to)
1668 (message-remove-header (symbol-name (car elem)))
1669 (goto-char (point-min))
1670 (insert (symbol-name (car elem)) ": "
1671 (cdr elem) "\n"))))))
1673 (defun message-insert-newsgroups ()
1674 "Insert the Newsgroups header from the article being replied to."
1676 (when (and (message-position-on-field "Newsgroups")
1677 (mail-fetch-field "newsgroups")
1678 (not (string-match "\\` *\\'" (mail-fetch-field "newsgroups"))))
1680 (insert (or (message-fetch-reply-field "newsgroups") "")))
1684 ;;; Various commands
1686 (defun message-delete-not-region (beg end)
1687 "Delete everything in the body of the current message that is outside of the region."
1691 (delete-region (point) (if (not (message-goto-signature))
1697 (delete-region beg (progn (message-goto-body)
1700 (when (message-goto-signature)
1703 (defun message-kill-to-signature ()
1704 "Deletes all text up to the signature."
1706 (let ((point (point)))
1707 (message-goto-signature)
1710 (kill-region point (point))
1714 (defun message-newline-and-reformat ()
1715 "Insert four newlines, and then reformat if inside quoted text."
1721 (when (looking-at message-cite-prefix-regexp)
1722 (setq quoted (match-string 0))))
1724 (setq point (point))
1726 (delete-region (point) (re-search-forward "[ \t]*"))
1729 (fill-paragraph nil)
1733 (defun message-insert-signature (&optional force)
1734 "Insert a signature. See documentation for the `message-signature' variable."
1735 (interactive (list 0))
1738 ((and (null message-signature)
1741 (goto-char (point-max))
1742 (not (re-search-backward message-signature-separator nil t))))
1743 ((and (null message-signature)
1746 ((message-functionp message-signature)
1747 (funcall message-signature))
1748 ((listp message-signature)
1749 (eval message-signature))
1750 (t message-signature)))
1752 (cond ((stringp signature)
1754 ((and (eq t signature)
1755 message-signature-file
1756 (file-exists-p message-signature-file))
1759 (goto-char (point-max))
1760 ;; Insert the signature.
1764 (if (eq signature t)
1765 (insert-file-contents message-signature-file)
1767 (goto-char (point-max))
1768 (or (bolp) (insert "\n")))))
1770 (defun message-elide-region (b e)
1771 "Elide the text between point and mark.
1772 An ellipsis (from `message-elide-ellipsis') will be inserted where the
1776 (insert message-elide-ellipsis))
1778 (defvar message-caesar-translation-table nil)
1780 (defun message-caesar-region (b e &optional n)
1781 "Caesar rotation of region by N, default 13, for decrypting netnews."
1784 (min (point) (or (mark t) (point)))
1785 (max (point) (or (mark t) (point)))
1786 (when current-prefix-arg
1787 (prefix-numeric-value current-prefix-arg))))
1789 (setq n (if (numberp n) (mod n 26) 13)) ;canonize N
1790 (unless (or (zerop n) ; no action needed for a rot of 0
1791 (= b e)) ; no region to rotate
1792 ;; We build the table, if necessary.
1793 (when (or (not message-caesar-translation-table)
1794 (/= (aref message-caesar-translation-table ?a) (+ ?a n)))
1795 (setq message-caesar-translation-table
1796 (message-make-caesar-translation-table n)))
1797 (translate-region b e message-caesar-translation-table)))
1799 (defun message-make-caesar-translation-table (n)
1800 "Create a rot table with offset N."
1802 (table (make-string 256 0)))
1803 (while (< (incf i) 256)
1806 (substring table 0 ?A)
1807 (substring table (+ ?A n) (+ ?A n (- 26 n)))
1808 (substring table ?A (+ ?A n))
1809 (substring table (+ ?A 26) ?a)
1810 (substring table (+ ?a n) (+ ?a n (- 26 n)))
1811 (substring table ?a (+ ?a n))
1812 (substring table (+ ?a 26) 255))))
1814 (defun message-caesar-buffer-body (&optional rotnum)
1815 "Caesar rotates all letters in the current buffer by 13 places.
1816 Used to encode/decode possiblyun offensive messages (commonly in net.jokes).
1817 With prefix arg, specifies the number of places to rotate each letter forward.
1818 Mail and USENET news headers are not rotated."
1819 (interactive (if current-prefix-arg
1820 (list (prefix-numeric-value current-prefix-arg))
1824 (when (message-goto-body)
1825 (narrow-to-region (point) (point-max)))
1826 (message-caesar-region (point-min) (point-max) rotnum))))
1828 (defun message-pipe-buffer-body (program)
1829 "Pipe the message body in the current buffer through PROGRAM."
1832 (when (message-goto-body)
1833 (narrow-to-region (point) (point-max)))
1834 (shell-command-on-region
1835 (point-min) (point-max) program nil t))))
1837 (defun message-rename-buffer (&optional enter-string)
1838 "Rename the *message* buffer to \"*message* RECIPIENT\".
1839 If the function is run with a prefix, it will ask for a new buffer
1840 name, rather than giving an automatic name."
1841 (interactive "Pbuffer name: ")
1844 (goto-char (point-min))
1845 (narrow-to-region (point)
1846 (search-forward mail-header-separator nil 'end))
1848 (if (message-news-p) (message-fetch-field "Newsgroups")
1849 (message-fetch-field "To"))
1852 (if (string-match "," mail-to)
1853 (concat (substring mail-to 0 (match-beginning 0)) ", ...")
1855 (name-default (concat "*message* " mail-trimmed-to))
1856 (name (if enter-string
1857 (read-string "New buffer name: " name-default)
1859 (rename-buffer name t)))))
1861 (defun message-fill-yanked-message (&optional justifyp)
1862 "Fill the paragraphs of a message yanked into this one.
1863 Numeric argument means justify as well."
1866 (goto-char (point-min))
1867 (search-forward (concat "\n" mail-header-separator "\n") nil t)
1868 (let ((fill-prefix message-yank-prefix))
1869 (fill-individual-paragraphs (point) (point-max) justifyp))))
1871 (defun message-indent-citation ()
1872 "Modify text just inserted from a message to be cited.
1873 The inserted text should be the region.
1874 When this function returns, the region is again around the modified text.
1876 Normally, indent each nonblank line `message-indentation-spaces' spaces.
1877 However, if `message-yank-prefix' is non-nil, insert that prefix on each line."
1878 (let ((start (point)))
1879 ;; Remove unwanted headers.
1880 (when message-ignored-cited-headers
1885 (if (search-forward "\n\n" nil t)
1888 (message-remove-header message-ignored-cited-headers t)
1889 (when (= (point-min) (point-max))
1890 (setq all-removed t))
1891 (goto-char (point-max)))
1895 ;; Delete blank lines at the start of the buffer.
1896 (while (and (point-min)
1899 (message-delete-line))
1900 ;; Delete blank lines at the end of the buffer.
1901 (goto-char (point-max))
1904 (while (and (zerop (forward-line -1))
1906 (message-delete-line))
1907 ;; Do the indentation.
1908 (if (null message-yank-prefix)
1909 (indent-rigidly start (mark t) message-indentation-spaces)
1912 (while (< (point) (mark t))
1913 (insert message-yank-prefix)
1917 (defun message-yank-original (&optional arg)
1918 "Insert the message being replied to, if any.
1919 Puts point before the text and mark after.
1920 Normally indents each nonblank line ARG spaces (default 3). However,
1921 if `message-yank-prefix' is non-nil, insert that prefix on each line.
1923 This function uses `message-cite-function' to do the actual citing.
1925 Just \\[universal-argument] as argument means don't indent, insert no
1926 prefix, and don't delete any headers."
1928 (let ((modified (buffer-modified-p)))
1929 (when (and message-reply-buffer
1930 message-cite-function)
1931 (delete-windows-on message-reply-buffer t)
1932 (insert-buffer message-reply-buffer)
1933 (funcall message-cite-function)
1934 (message-exchange-point-and-mark)
1938 (setq message-checksum (message-checksum))))))
1940 (defun message-yank-buffer (buffer)
1941 "Insert BUFFER into the current buffer and quote it."
1942 (interactive "bYank buffer: ")
1943 (let ((message-reply-buffer buffer))
1944 (save-window-excursion
1945 (message-yank-original))))
1947 (defun message-buffers ()
1948 "Return a list of active message buffers."
1951 (dolist (buffer (buffer-list t))
1953 (when (and (eq major-mode 'message-mode)
1954 (null message-sent-message-via))
1955 (push (buffer-name buffer) buffers))))
1956 (nreverse buffers)))
1958 (defun message-cite-original-without-signature ()
1959 "Cite function in the standard Message manner."
1960 (let ((start (point))
1963 (when message-indent-citation-function
1964 (if (listp message-indent-citation-function)
1965 message-indent-citation-function
1966 (list message-indent-citation-function)))))
1967 (mml-quote-region start end)
1971 (when (re-search-backward message-signature-separator start t)
1972 ;; Also peel off any blank lines before the signature.
1974 (while (looking-at "^[ \t]*$")
1977 (delete-region (point) end))
1980 (funcall (pop functions)))
1981 (when message-citation-line-function
1984 (funcall message-citation-line-function))))
1986 (defvar mail-citation-hook) ;Compiler directive
1987 (defun message-cite-original ()
1988 "Cite function in the standard Message manner."
1989 (if (and (boundp 'mail-citation-hook)
1991 (run-hooks 'mail-citation-hook)
1992 (let ((start (point))
1995 (when message-indent-citation-function
1996 (if (listp message-indent-citation-function)
1997 message-indent-citation-function
1998 (list message-indent-citation-function)))))
1999 (mml-quote-region start end)
2002 (funcall (pop functions)))
2003 (when message-citation-line-function
2006 (funcall message-citation-line-function)))))
2008 (defun message-insert-citation-line ()
2009 "Function that inserts a simple citation line."
2010 (when message-reply-headers
2011 (insert (mail-header-from message-reply-headers) " writes:\n\n")))
2013 (defun message-position-on-field (header &rest afters)
2014 (let ((case-fold-search t))
2017 (goto-char (point-min))
2020 (concat "^" (regexp-quote mail-header-separator) "$"))
2021 (match-beginning 0)))
2022 (goto-char (point-min))
2023 (if (re-search-forward (concat "^" (regexp-quote header) ":") nil t)
2025 (re-search-forward "^[^ \t]" nil 'move)
2027 (skip-chars-backward "\n")
2030 (not (re-search-forward
2031 (concat "^" (regexp-quote (car afters)) ":")
2035 (re-search-forward "^[^ \t]" nil 'move)
2036 (beginning-of-line))
2037 (insert header ": \n")
2041 (defun message-remove-signature ()
2042 "Remove the signature from the text between point and mark.
2043 The text will also be indented the normal way."
2045 (let ((start (point))
2047 (if (not (re-search-forward message-signature-separator (mark t) t))
2048 ;; No signature here, so we just indent the cited text.
2049 (message-indent-citation)
2050 ;; Find the last non-empty line.
2052 (while (looking-at "[ \t]*$")
2055 (setq mark (set-marker (make-marker) (point)))
2057 (message-indent-citation)
2058 ;; Enable undoing the deletion.
2060 (delete-region mark (mark t))
2061 (set-marker mark nil)))))
2066 ;;; Sending messages
2069 (defun message-send-and-exit (&optional arg)
2070 "Send message like `message-send', then, if no errors, exit from mail buffer."
2072 (let ((buf (current-buffer))
2073 (actions message-exit-actions))
2074 (when (and (message-send arg)
2076 (if message-kill-buffer-on-exit
2079 (when (eq buf (current-buffer))
2080 (message-bury buf)))
2081 (message-do-actions actions)
2084 (defun message-dont-send ()
2085 "Don't send the message you have been editing."
2087 (set-buffer-modified-p t)
2089 (let ((actions message-postpone-actions))
2090 (message-bury (current-buffer))
2091 (message-do-actions actions)))
2093 (defun message-kill-buffer ()
2094 "Kill the current buffer."
2096 (when (or (not (buffer-modified-p))
2097 (yes-or-no-p "Message modified; kill anyway? "))
2098 (let ((actions message-kill-actions))
2099 (setq buffer-file-name nil)
2100 (kill-buffer (current-buffer))
2101 (message-do-actions actions))))
2103 (defun message-bury (buffer)
2104 "Bury this mail buffer."
2105 (let ((newbuf (other-buffer buffer)))
2106 (bury-buffer buffer)
2107 (if (and (fboundp 'frame-parameters)
2108 (cdr (assq 'dedicated (frame-parameters)))
2109 (not (null (delq (selected-frame) (visible-frame-list)))))
2110 (delete-frame (selected-frame))
2111 (switch-to-buffer newbuf))))
2113 (defun message-send (&optional arg)
2114 "Send the message in the current buffer.
2115 If `message-interactive' is non-nil, wait for success indication or
2116 error messages, and inform user.
2117 Otherwise any failure is reported in a message back to the user from
2119 The usage of ARG is defined by the instance that called Message.
2120 It should typically alter the sending method in some way or other."
2122 ;; Make it possible to undo the coming changes.
2124 (let ((inhibit-read-only t))
2125 (put-text-property (point-min) (point-max) 'read-only nil))
2126 (message-fix-before-sending)
2127 (run-hooks 'message-send-hook)
2128 (message message-sending-message)
2129 (let ((alist message-send-method-alist)
2132 (message-options message-options))
2133 (message-options-set-recipient)
2135 (setq elem (pop alist)))
2136 (when (funcall (cadr elem))
2137 (when (and (or (not (memq (car elem)
2138 message-sent-message-via))
2141 "Already sent message via %s; resend? "
2143 (setq success (funcall (caddr elem) arg)))
2145 (unless (or sent (not success))
2146 (error "No methods specified to send by"))
2147 (when (and success sent)
2150 (run-hooks 'message-sent-hook))
2151 (message "Sending...done")
2152 ;; Mark the buffer as unmodified and delete auto-save.
2153 (set-buffer-modified-p nil)
2154 (delete-auto-save-file-if-necessary t)
2155 (message-disassociate-draft)
2156 ;; Delete other mail buffers and stuff.
2157 (message-do-send-housekeeping)
2158 (message-do-actions message-send-actions)
2162 (defun message-send-via-mail (arg)
2163 "Send the current message via mail."
2164 (message-send-mail arg))
2166 (defun message-send-via-news (arg)
2167 "Send the current message via news."
2168 (funcall message-send-news-function arg))
2170 (defmacro message-check (type &rest forms)
2171 "Eval FORMS if TYPE is to be checked."
2172 `(or (message-check-element ,type)
2176 (put 'message-check 'lisp-indent-function 1)
2177 (put 'message-check 'edebug-form-spec '(form body))
2179 (defun message-fix-before-sending ()
2180 "Do various things to make the message nice before sending it."
2181 ;; Make sure there's a newline at the end of the message.
2182 (goto-char (point-max))
2185 ;; Delete all invisible text.
2186 (message-check 'invisible-text
2187 (when (text-property-any (point-min) (point-max) 'invisible t)
2188 (put-text-property (point-min) (point-max) 'invisible nil)
2189 (unless (yes-or-no-p
2190 "Invisible text found and made visible; continue posting? ")
2191 (error "Invisible text found and made visible")))))
2193 (defun message-add-action (action &rest types)
2194 "Add ACTION to be performed when doing an exit of type TYPES."
2197 (set (setq var (intern (format "message-%s-actions" (pop types))))
2198 (nconc (symbol-value var) (list action))))))
2200 (defun message-do-actions (actions)
2201 "Perform all actions in ACTIONS."
2202 ;; Now perform actions on successful sending.
2206 ;; A simple function.
2207 ((message-functionp (car actions))
2208 (funcall (car actions)))
2209 ;; Something to be evaled.
2211 (eval (car actions)))))
2214 (defun message-send-mail-partially ()
2215 "Sendmail as message/partial."
2216 ;; replace the header delimiter with a blank line
2217 (goto-char (point-min))
2219 (concat "^" (regexp-quote mail-header-separator) "\n"))
2220 (replace-match "\n")
2221 (run-hooks 'message-send-mail-hook)
2222 (let ((p (goto-char (point-min)))
2223 (tembuf (message-generate-new-buffer-clone-locals " message temp"))
2224 (curbuf (current-buffer))
2225 (id (message-make-message-id)) (n 1)
2226 plist total header required-mail-headers)
2228 (if (< (point-max) (+ p message-send-mail-partially-limit))
2229 (goto-char (point-max))
2230 (goto-char (+ p message-send-mail-partially-limit))
2232 (if (<= (point) p) (forward-line 1))) ;; In case of bad message.
2235 (setq total (length plist))
2236 (push (point-max) plist)
2237 (setq plist (nreverse plist))
2240 (setq p (pop plist))
2243 (copy-to-buffer tembuf p (car plist))
2245 (goto-char (point-min))
2248 (goto-char (point-min))
2249 (narrow-to-region (point) (point))
2252 (setq header (buffer-substring (point-min) (point)))
2253 (goto-char (point-min))
2254 (narrow-to-region (point) (point))
2256 (message-remove-header "Mime-Version")
2257 (message-remove-header "Content-Type")
2258 (message-remove-header "Content-Transfer-Encoding")
2259 (message-remove-header "Message-ID")
2260 (message-remove-header "Lines")
2261 (goto-char (point-max))
2262 (insert "Mime-Version: 1.0\n")
2263 (setq header (buffer-substring (point-min) (point-max))))
2264 (goto-char (point-max))
2265 (insert (format "Content-Type: message/partial; id=\"%s\"; number=%d; total=%d\n"
2267 (let ((mail-header-separator ""))
2268 (when (memq 'Message-ID message-required-mail-headers)
2269 (insert "Message-ID: " (message-make-message-id) "\n"))
2270 (when (memq 'Lines message-required-mail-headers)
2271 (let ((mail-header-separator ""))
2272 (insert "Lines: " (message-make-lines) "\n")))
2273 (message-goto-subject)
2275 (insert (format " (%d/%d)" n total))
2276 (goto-char (point-max))
2279 (mm-with-unibyte-current-buffer
2280 (funcall message-send-mail-function)))
2282 (setq p (pop plist))
2284 (kill-buffer tembuf))))
2286 (defun message-send-mail (&optional arg)
2287 (require 'mail-utils)
2288 (let* ((tembuf (message-generate-new-buffer-clone-locals " message temp"))
2289 (case-fold-search nil)
2290 (news (message-news-p))
2291 (mailbuf (current-buffer))
2292 (message-this-is-mail t)
2293 (message-posting-charset
2294 (if (fboundp 'gnus-setup-posting-charset)
2295 (gnus-setup-posting-charset nil)
2296 message-posting-charset)))
2298 (message-narrow-to-headers)
2299 ;; Insert some headers.
2300 (let ((message-deletable-headers
2301 (if news nil message-deletable-headers)))
2302 (message-generate-headers message-required-mail-headers))
2303 ;; Let the user do all of the above.
2304 (run-hooks 'message-header-hook))
2309 ;; Avoid copying text props.
2311 "%s" (save-excursion
2312 (set-buffer mailbuf)
2314 ;; Remove some headers.
2315 (message-encode-message-body)
2317 (message-narrow-to-headers)
2318 ;; We (re)generate the Lines header.
2319 (when (memq 'Lines message-required-mail-headers)
2320 (message-generate-headers '(Lines)))
2321 ;; Remove some headers.
2322 (message-remove-header message-ignored-mail-headers t)
2323 (let ((mail-parse-charset message-default-charset))
2324 (mail-encode-encoded-word-buffer)))
2325 (goto-char (point-max))
2326 ;; require one newline at the end.
2327 (or (= (preceding-char) ?\n)
2331 (message-narrow-to-headers)
2333 (or (message-fetch-field "cc")
2334 (message-fetch-field "to"))
2335 (string= "text/plain"
2337 (mail-header-parse-content-type
2338 (message-fetch-field "content-type"))))))
2339 (message-insert-courtesy-copy))
2340 (if (or (not message-send-mail-partially-limit)
2341 (< (point-max) message-send-mail-partially-limit)
2342 (not (y-or-n-p "The message size is too large, should it be sent partially?")))
2343 (mm-with-unibyte-current-buffer
2344 (funcall message-send-mail-function))
2345 (message-send-mail-partially)))
2346 (kill-buffer tembuf))
2347 (set-buffer mailbuf)
2348 (push 'mail message-sent-message-via)))
2350 (defun message-send-mail-with-sendmail ()
2351 "Send off the prepared buffer with sendmail."
2352 (let ((errbuf (if message-interactive
2353 (message-generate-new-buffer-clone-locals
2356 resend-to-addresses delimline)
2357 (let ((case-fold-search t))
2359 (message-narrow-to-headers)
2360 (setq resend-to-addresses (message-fetch-field "resent-to")))
2361 ;; Change header-delimiter to be what sendmail expects.
2362 (goto-char (point-min))
2364 (concat "^" (regexp-quote mail-header-separator) "\n"))
2365 (replace-match "\n")
2367 (setq delimline (point-marker))
2368 (run-hooks 'message-send-mail-hook)
2369 ;; Insert an extra newline if we need it to work around
2370 ;; Sun's bug that swallows newlines.
2371 (goto-char (1+ delimline))
2372 (when (eval message-mailer-swallows-blank-line)
2374 (when message-interactive
2378 (let ((default-directory "/")
2379 (coding-system-for-write message-send-coding-system))
2380 (apply 'call-process-region
2381 (append (list (point-min) (point-max)
2382 (if (boundp 'sendmail-program)
2384 "/usr/lib/sendmail")
2385 nil errbuf nil "-oi")
2386 ;; Always specify who from,
2387 ;; since some systems have broken sendmails.
2388 ;; But some systems are more broken with -f, so
2389 ;; we'll let users override this.
2390 (if (null message-sendmail-f-is-evil)
2391 (list "-f" (message-make-address)))
2392 ;; These mean "report errors by mail"
2393 ;; and "deliver in background".
2394 (if (null message-interactive) '("-oem" "-odb"))
2395 ;; Get the addresses from the message
2396 ;; unless this is a resend.
2397 ;; We must not do that for a resend
2398 ;; because we would find the original addresses.
2399 ;; For a resend, include the specific addresses.
2400 (if resend-to-addresses
2401 (list resend-to-addresses)
2403 (when message-interactive
2406 (goto-char (point-min))
2407 (while (re-search-forward "\n\n* *" nil t)
2408 (replace-match "; "))
2409 (if (not (zerop (buffer-size)))
2410 (error "Sending...failed to %s"
2411 (buffer-substring (point-min) (point-max)))))
2412 (when (bufferp errbuf)
2413 (kill-buffer errbuf)))))
2415 (defun message-send-mail-with-qmail ()
2416 "Pass the prepared message buffer to qmail-inject.
2417 Refer to the documentation for the variable `message-send-mail-function'
2418 to find out how to use this."
2419 ;; replace the header delimiter with a blank line
2420 (goto-char (point-min))
2422 (concat "^" (regexp-quote mail-header-separator) "\n"))
2423 (replace-match "\n")
2424 (run-hooks 'message-send-mail-hook)
2427 (let ((coding-system-for-write message-send-coding-system))
2429 'call-process-region 1 (point-max) message-qmail-inject-program
2431 ;; qmail-inject's default behaviour is to look for addresses on the
2432 ;; command line; if there're none, it scans the headers.
2433 ;; yes, it does The Right Thing w.r.t. Resent-To and it's kin.
2435 ;; in general, ALL of qmail-inject's defaults are perfect for simply
2436 ;; reading a formatted (i. e., at least a To: or Resent-To header)
2437 ;; message from stdin.
2439 ;; qmail also has the advantage of not having been raped by
2440 ;; various vendors, so we don't have to allow for that, either --
2441 ;; compare this with message-send-mail-with-sendmail and weep
2442 ;; for sendmail's lost innocence.
2444 ;; all this is way cool coz it lets us keep the arguments entirely
2445 ;; free for -inject-arguments -- a big win for the user and for us
2446 ;; since we don't have to play that double-guessing game and the user
2447 ;; gets full control (no gestapo'ish -f's, for instance). --sj
2448 message-qmail-inject-args))
2449 ;; qmail-inject doesn't say anything on it's stdout/stderr,
2450 ;; we have to look at the retval instead
2452 (1 (error "qmail-inject reported permanent failure"))
2453 (111 (error "qmail-inject reported transient failure"))
2454 ;; should never happen
2455 (t (error "qmail-inject reported unknown failure"))))
2457 (defun message-send-mail-with-mh ()
2458 "Send the prepared message buffer with mh."
2459 (let ((mh-previous-window-config nil)
2460 (name (mh-new-draft-name)))
2461 (setq buffer-file-name name)
2462 ;; MH wants to generate these headers itself.
2463 (when message-mh-deletable-headers
2464 (let ((headers message-mh-deletable-headers))
2466 (goto-char (point-min))
2467 (and (re-search-forward
2468 (concat "^" (symbol-name (car headers)) ": *") nil t)
2469 (message-delete-line))
2471 (run-hooks 'message-send-mail-hook)
2472 ;; Pass it on to mh.
2475 (defun message-send-news (&optional arg)
2476 (let* ((tembuf (message-generate-new-buffer-clone-locals " *message temp*"))
2477 (case-fold-search nil)
2478 (method (if (message-functionp message-post-method)
2479 (funcall message-post-method arg)
2480 message-post-method))
2481 (group-name-charset (gnus-group-name-charset method ""))
2482 (rfc2047-header-encoding-alist
2483 (if group-name-charset
2484 (cons (cons "Newsgroups" group-name-charset)
2485 rfc2047-header-encoding-alist)
2486 rfc2047-header-encoding-alist))
2487 (messbuf (current-buffer))
2488 (message-syntax-checks
2490 (cons '(existing-newsgroups . disabled)
2491 message-syntax-checks)
2492 message-syntax-checks))
2493 (message-this-is-news t)
2494 (message-posting-charset (gnus-setup-posting-charset
2496 (message-narrow-to-headers-or-head)
2497 (message-fetch-field "Newsgroups"))))
2499 (if (not (message-check-news-body-syntax))
2502 (message-narrow-to-headers)
2503 ;; Insert some headers.
2504 (message-generate-headers message-required-news-headers)
2505 ;; Let the user do all of the above.
2506 (run-hooks 'message-header-hook))
2507 (if group-name-charset
2508 (setq message-syntax-checks
2509 (cons '(valid-newsgroups . disabled)
2510 message-syntax-checks)))
2511 (message-cleanup-headers)
2512 (if (not (message-check-news-syntax))
2517 (buffer-disable-undo)
2519 ;; Avoid copying text props.
2521 "%s" (save-excursion
2522 (set-buffer messbuf)
2524 (message-encode-message-body)
2525 ;; Remove some headers.
2527 (message-narrow-to-headers)
2528 ;; We (re)generate the Lines header.
2529 (when (memq 'Lines message-required-mail-headers)
2530 (message-generate-headers '(Lines)))
2531 ;; Remove some headers.
2532 (message-remove-header message-ignored-news-headers t)
2533 (let ((mail-parse-charset message-default-charset))
2534 (mail-encode-encoded-word-buffer)))
2535 (goto-char (point-max))
2536 ;; require one newline at the end.
2537 (or (= (preceding-char) ?\n)
2539 (let ((case-fold-search t))
2540 ;; Remove the delimiter.
2541 (goto-char (point-min))
2543 (concat "^" (regexp-quote mail-header-separator) "\n"))
2544 (replace-match "\n")
2546 (run-hooks 'message-send-news-hook)
2547 (gnus-open-server method)
2548 (setq result (let ((mail-header-separator ""))
2549 (gnus-request-post method))))
2550 (kill-buffer tembuf))
2551 (set-buffer messbuf)
2553 (push 'news message-sent-message-via)
2554 (message "Couldn't send message via news: %s"
2555 (nnheader-get-report (car method)))
2559 ;;; Header generation & syntax checking.
2562 (defun message-check-element (type)
2563 "Returns non-nil if this type is not to be checked."
2564 (if (eq message-syntax-checks 'dont-check-for-anything-just-trust-me)
2566 (let ((able (assq type message-syntax-checks)))
2568 (eq (cdr able) 'disabled)))))
2570 (defun message-check-news-syntax ()
2571 "Check the syntax of the message."
2575 ;; We narrow to the headers and check them first.
2578 (message-narrow-to-headers)
2579 (message-check-news-header-syntax))))))
2581 (defun message-check-news-header-syntax ()
2583 ;; Check Newsgroups header.
2584 (message-check 'newsgroups
2585 (let ((group (message-fetch-field "newsgroups")))
2588 (not (string-match "\\`[ \t]*\\'" group)))
2591 "The newsgroups field is empty or missing. Posting is denied.")))))
2592 ;; Check the Subject header.
2593 (message-check 'subject
2594 (let* ((case-fold-search t)
2595 (subject (message-fetch-field "subject")))
2598 (not (string-match "\\`[ \t]*\\'" subject)))
2601 "The subject field is empty or missing. Posting is denied.")))))
2602 ;; Check for commands in Subject.
2603 (message-check 'subject-cmsg
2604 (if (string-match "^cmsg " (message-fetch-field "subject"))
2606 "The control code \"cmsg\" is in the subject. Really post? ")
2608 ;; Check for multiple identical headers.
2609 (message-check 'multiple-headers
2611 (while (and (not found)
2612 (re-search-forward "^[^ \t:]+: " nil t))
2614 (or (re-search-forward
2619 (match-beginning 0) (- (match-end 0) 2))))
2624 (y-or-n-p (format "Multiple %s headers. Really post? " found))
2626 ;; Check for Version and Sendsys.
2627 (message-check 'sendsys
2628 (if (re-search-forward "^Sendsys:\\|^Version:" nil t)
2630 (format "The article contains a %s command. Really post? "
2631 (buffer-substring (match-beginning 0)
2632 (1- (match-end 0)))))
2634 ;; See whether we can shorten Followup-To.
2635 (message-check 'shorten-followup-to
2636 (let ((newsgroups (message-fetch-field "newsgroups"))
2637 (followup-to (message-fetch-field "followup-to"))
2639 (when (and newsgroups
2640 (string-match "," newsgroups)
2645 (setq to (completing-read
2646 "Followups to: (default all groups) "
2647 (mapcar (lambda (g) (list g))
2649 (message-tokenize-header
2651 (goto-char (point-min))
2652 (insert "Followup-To: " to "\n"))
2654 ;; Check "Shoot me".
2655 (message-check 'shoot
2656 (if (re-search-forward
2657 "Message-ID.*.i-did-not-set--mail-host-address--so-shoot-me" nil t)
2658 (y-or-n-p "You appear to have a misconfigured system. Really post? ")
2660 ;; Check for Approved.
2661 (message-check 'approved
2662 (if (re-search-forward "^Approved:" nil t)
2663 (y-or-n-p "The article contains an Approved header. Really post? ")
2665 ;; Check the Message-ID header.
2666 (message-check 'message-id
2667 (let* ((case-fold-search t)
2668 (message-id (message-fetch-field "message-id" t)))
2669 (or (not message-id)
2670 ;; Is there an @ in the ID?
2671 (and (string-match "@" message-id)
2672 ;; Is there a dot in the ID?
2673 (string-match "@[^.]*\\." message-id)
2674 ;; Does the ID end with a dot?
2675 (not (string-match "\\.>" message-id)))
2677 (format "The Message-ID looks strange: \"%s\". Really post? "
2679 ;; Check the Newsgroups & Followup-To headers.
2680 (message-check 'existing-newsgroups
2681 (let* ((case-fold-search t)
2682 (newsgroups (message-fetch-field "newsgroups"))
2683 (followup-to (message-fetch-field "followup-to"))
2684 (groups (message-tokenize-header
2686 (concat newsgroups "," followup-to)
2688 (hashtb (and (boundp 'gnus-active-hashtb)
2689 gnus-active-hashtb))
2691 (if (or (not hashtb)
2692 (not (boundp 'gnus-read-active-file))
2693 (not gnus-read-active-file)
2694 (eq gnus-read-active-file 'some))
2697 (when (and (not (boundp (intern (car groups) hashtb)))
2698 (not (equal (car groups) "poster")))
2699 (push (car groups) errors))
2705 "Really post to %s unknown group%s: %s "
2706 (if (= (length errors) 1) "this" "these")
2707 (if (= (length errors) 1) "" "s")
2708 (mapconcat 'identity errors ", ")))))))
2709 ;; Check the Newsgroups & Followup-To headers for syntax errors.
2710 (message-check 'valid-newsgroups
2711 (let ((case-fold-search t)
2712 (headers '("Newsgroups" "Followup-To"))
2714 (while (and headers (not error))
2715 (when (setq header (mail-fetch-field (car headers)))
2719 "\\`\\([-+_&.a-zA-Z0-9]+\\)?\\(,[-+_&.a-zA-Z0-9]+\\)*\\'"
2724 (not (string-match "\\.\\'\\|\\.\\." g)))
2725 (message-tokenize-header header ","))))
2732 (format "The %s header looks odd: \"%s\". Really post? "
2733 (car headers) header)))))
2734 (message-check 'repeated-newsgroups
2735 (let ((case-fold-search t)
2736 (headers '("Newsgroups" "Followup-To"))
2737 header error groups group)
2740 (when (setq header (mail-fetch-field (pop headers)))
2741 (setq groups (message-tokenize-header header ","))
2742 (while (setq group (pop groups))
2743 (when (member group groups)
2749 (format "Group %s is repeated in headers. Really post? " error)))))
2750 ;; Check the From header.
2751 (message-check 'from
2752 (let* ((case-fold-search t)
2753 (from (message-fetch-field "from"))
2757 (message "There is no From line. Posting is denied.")
2759 ((or (not (string-match
2761 (setq ad (nth 1 (mail-extract-address-components
2762 from))))) ;larsi@ifi
2763 (string-match "\\.\\." ad) ;larsi@ifi..uio
2764 (string-match "@\\." ad) ;larsi@.ifi.uio
2765 (string-match "\\.$" ad) ;larsi@ifi.uio.
2766 (not (string-match "^[^@]+@[^@]+$" ad)) ;larsi.ifi.uio
2767 (string-match "(.*).*(.*)" from)) ;(lars) (lars)
2769 "Denied posting -- the From looks strange: \"%s\"." from)
2773 (defun message-check-news-body-syntax ()
2775 ;; Check for long lines.
2776 (message-check 'long-lines
2777 (goto-char (point-min))
2779 (concat "^" (regexp-quote mail-header-separator) "$"))
2783 (< (current-column) 80))
2784 (zerop (forward-line 1))))
2788 "You have lines longer than 79 characters. Really post? ")))
2789 ;; Check whether the article is empty.
2790 (message-check 'empty
2791 (goto-char (point-min))
2793 (concat "^" (regexp-quote mail-header-separator) "$"))
2796 (goto-char (point-max))
2797 (re-search-backward message-signature-separator nil t)
2799 (or (re-search-backward "[^ \n\t]" b t)
2800 (y-or-n-p "Empty article. Really post? "))))
2801 ;; Check for control characters.
2802 (message-check 'control-chars
2803 (if (re-search-forward "[\000-\007\013\015-\032\034-\037\200-\237]" nil t)
2805 "The article contains control characters. Really post? ")
2807 ;; Check excessive size.
2808 (message-check 'size
2809 (if (> (buffer-size) 60000)
2811 (format "The article is %d octets long. Really post? "
2814 ;; Check whether any new text has been added.
2815 (message-check 'new-text
2817 (not message-checksum)
2818 (not (eq (message-checksum) message-checksum))
2820 "It looks like no new text has been added. Really post? ")))
2821 ;; Check the length of the signature.
2822 (message-check 'signature
2823 (goto-char (point-max))
2824 (if (> (count-lines (point) (point-max)) 5)
2827 "Your .sig is %d lines; it should be max 4. Really post? "
2828 (1- (count-lines (point) (point-max)))))
2830 ;; Ensure that text follows last quoted portion.
2831 (message-check 'quoting-style
2832 (goto-char (point-max))
2833 (let ((no-problem t))
2834 (when (search-backward-regexp "^>[^\n]*\n>" nil t)
2835 (setq no-problem nil)
2837 (when (and (not (eolp)) (looking-at "[^> \t]"))
2838 (setq no-problem t))
2842 (y-or-n-p "Your text should follow quoted text. Really post? "))))))
2844 (defun message-checksum ()
2845 "Return a \"checksum\" for the current buffer."
2848 (goto-char (point-min))
2850 (concat "^" (regexp-quote mail-header-separator) "$"))
2852 (when (not (looking-at "[ \t\n]"))
2853 (setq sum (logxor (ash sum 1) (if (natnump sum) 0 1)
2858 (defun message-do-fcc ()
2859 "Process Fcc headers in the current buffer."
2860 (let ((case-fold-search t)
2861 (buf (current-buffer))
2864 (set-buffer (get-buffer-create " *message temp*"))
2866 (insert-buffer-substring buf)
2868 (message-narrow-to-headers)
2869 (while (setq file (message-fetch-field "fcc"))
2871 (message-remove-header "fcc" nil t)))
2872 (message-encode-message-body)
2874 (message-narrow-to-headers)
2875 (let ((mail-parse-charset message-default-charset)
2876 (rfc2047-header-encoding-alist
2877 (cons '("Newsgroups" . default)
2878 rfc2047-header-encoding-alist)))
2879 (mail-encode-encoded-word-buffer)))
2880 (goto-char (point-min))
2881 (when (re-search-forward
2882 (concat "^" (regexp-quote mail-header-separator) "$")
2884 (replace-match "" t t ))
2885 ;; Process FCC operations.
2887 (setq file (pop list))
2888 (if (string-match "^[ \t]*|[ \t]*\\(.*\\)[ \t]*$" file)
2889 ;; Pipe the article to the program in question.
2890 (call-process-region (point-min) (point-max) shell-file-name
2891 nil nil nil shell-command-switch
2892 (match-string 1 file))
2893 ;; Save the article.
2894 (setq file (expand-file-name file))
2895 (unless (file-exists-p (file-name-directory file))
2896 (make-directory (file-name-directory file) t))
2897 (if (and message-fcc-handler-function
2898 (not (eq message-fcc-handler-function 'rmail-output)))
2899 (funcall message-fcc-handler-function file)
2900 (if (and (file-readable-p file) (mail-file-babyl-p file))
2901 (rmail-output file 1 nil t)
2902 (let ((mail-use-rfc822 t))
2903 (rmail-output file 1 t t))))))
2904 (kill-buffer (current-buffer)))))
2906 (defun message-output (filename)
2907 "Append this article to Unix/babyl mail file.."
2908 (if (and (file-readable-p filename)
2909 (mail-file-babyl-p filename))
2910 (gnus-output-to-rmail filename t)
2911 (gnus-output-to-mail filename t)))
2913 (defun message-cleanup-headers ()
2914 "Do various automatic cleanups of the headers."
2915 ;; Remove empty lines in the header.
2917 (message-narrow-to-headers)
2918 ;; Remove blank lines.
2919 (while (re-search-forward "^[ \t]*\n" nil t)
2920 (replace-match "" t t))
2922 ;; Correct Newsgroups and Followup-To headers: Change sequence of
2923 ;; spaces to comma and eliminate spaces around commas. Eliminate
2924 ;; embedded line breaks.
2925 (goto-char (point-min))
2926 (while (re-search-forward "^\\(Newsgroups\\|Followup-To\\): +" nil t)
2930 (if (re-search-forward "^[^ \t]" nil t)
2934 (goto-char (point-min))
2935 (while (re-search-forward "\n[ \t]+" nil t)
2936 (replace-match " " t t)) ;No line breaks (too confusing)
2937 (goto-char (point-min))
2938 (while (re-search-forward "[ \t\n]*,[ \t\n]*\\|[ \t]+" nil t)
2939 (replace-match "," t t))
2940 (goto-char (point-min))
2941 ;; Remove trailing commas.
2942 (when (re-search-forward ",+$" nil t)
2943 (replace-match "" t t))))))
2945 (defun message-make-date (&optional now)
2946 "Make a valid data header.
2947 If NOW, use that time instead."
2948 (let* ((now (or now (current-time)))
2949 (zone (nth 8 (decode-time now)))
2953 (setq zone (- zone)))
2955 (format-time-string "%d" now)
2956 ;; The month name of the %b spec is locale-specific. Pfff.
2958 (capitalize (car (rassoc (nth 4 (decode-time now))
2959 parse-time-months))))
2960 (format-time-string "%Y %H:%M:%S " now)
2961 ;; We do all of this because XEmacs doesn't have the %z spec.
2962 (format "%s%02d%02d" sign (/ zone 3600) (/ (% zone 3600) 60)))))
2964 (defun message-make-message-id ()
2965 "Make a unique Message-ID."
2966 (concat "<" (message-unique-id)
2967 (let ((psubject (save-excursion (message-fetch-field "subject")))
2969 (save-excursion (message-fetch-field "supersedes"))))
2971 (and message-reply-headers
2972 (mail-header-references message-reply-headers)
2973 (mail-header-subject message-reply-headers)
2975 (mail-header-subject message-reply-headers)
2977 (message-strip-subject-re
2978 (mail-header-subject message-reply-headers))
2979 (message-strip-subject-re psubject))))
2981 (string-match "_-_@" psupersedes)))
2983 "@" (message-make-fqdn) ">"))
2985 (defvar message-unique-id-char nil)
2987 ;; If you ever change this function, make sure the new version
2988 ;; cannot generate IDs that the old version could.
2989 ;; You might for example insert a "." somewhere (not next to another dot
2990 ;; or string boundary), or modify the "fsf" string.
2991 (defun message-unique-id ()
2992 ;; Don't use microseconds from (current-time), they may be unsupported.
2993 ;; Instead we use this randomly inited counter.
2994 (setq message-unique-id-char
2995 (% (1+ (or message-unique-id-char (logand (random t) (1- (lsh 1 20)))))
2996 ;; (current-time) returns 16-bit ints,
2997 ;; and 2^16*25 just fits into 4 digits i base 36.
2999 (let ((tm (current-time)))
3001 (if (memq system-type '(ms-dos emx vax-vms))
3002 (let ((user (downcase (user-login-name))))
3003 (while (string-match "[^a-z0-9_]" user)
3004 (aset user (match-beginning 0) ?_))
3006 (message-number-base36 (user-uid) -1))
3007 (message-number-base36 (+ (car tm)
3008 (lsh (% message-unique-id-char 25) 16)) 4)
3009 (message-number-base36 (+ (nth 1 tm)
3010 (lsh (/ message-unique-id-char 25) 16)) 4)
3011 ;; Append the newsreader name, because while the generated
3012 ;; ID is unique to this newsreader, other newsreaders might
3013 ;; otherwise generate the same ID via another algorithm.
3016 (defun message-number-base36 (num len)
3021 (concat (message-number-base36 (/ num 36) (1- len))
3022 (char-to-string (aref "zyxwvutsrqponmlkjihgfedcba9876543210"
3025 (defun message-make-organization ()
3026 "Make an Organization header."
3027 (let* ((organization
3028 (when message-user-organization
3029 (if (message-functionp message-user-organization)
3030 (funcall message-user-organization)
3031 message-user-organization))))
3033 (message-set-work-buffer)
3034 (cond ((stringp organization)
3035 (insert organization))
3036 ((and (eq t organization)
3037 message-user-organization-file
3038 (file-exists-p message-user-organization-file))
3039 (insert-file-contents message-user-organization-file)))
3040 (goto-char (point-min))
3041 (while (re-search-forward "[\t\n]+" nil t)
3042 (replace-match "" t t))
3043 (unless (zerop (buffer-size))
3046 (defun message-make-lines ()
3047 "Count the number of lines and return numeric string."
3051 (goto-char (point-min))
3053 (concat "^" (regexp-quote mail-header-separator) "$"))
3055 (int-to-string (count-lines (point) (point-max))))))
3057 (defun message-make-in-reply-to ()
3058 "Return the In-Reply-To header for this message."
3059 (when message-reply-headers
3060 (mail-header-message-id message-reply-headers)))
3062 (defun message-make-distribution ()
3063 "Make a Distribution header."
3064 (let ((orig-distribution (message-fetch-reply-field "distribution")))
3065 (cond ((message-functionp message-distribution-function)
3066 (funcall message-distribution-function))
3067 (t orig-distribution))))
3069 (defun message-make-expires ()
3070 "Return an Expires header based on `message-expires'."
3071 (let ((current (current-time))
3072 (future (* 1.0 message-expires 60 60 24)))
3073 ;; Add the future to current.
3074 (setcar current (+ (car current) (round (/ future (expt 2 16)))))
3075 (setcar (cdr current) (+ (nth 1 current) (% (round future) (expt 2 16))))
3076 (message-make-date current)))
3078 (defun message-make-path ()
3080 (let ((login-name (user-login-name)))
3081 (cond ((null message-user-path)
3082 (concat (system-name) "!" login-name))
3083 ((stringp message-user-path)
3084 ;; Support GENERICPATH. Suggested by vixie@decwrl.dec.com.
3085 (concat message-user-path "!" login-name))
3088 (defun message-make-from ()
3089 "Make a From header."
3090 (let* ((style message-from-style)
3091 (login (message-make-address))
3093 (or (and (boundp 'user-full-name)
3096 (when (string= fullname "&")
3097 (setq fullname (user-login-name)))
3099 (message-set-work-buffer)
3102 (equal fullname ""))
3104 ((or (eq style 'angles)
3105 (and (not (eq style 'parens))
3106 ;; Use angles if no quoting is needed, or if parens would
3107 ;; need quoting too.
3108 (or (not (string-match "[^- !#-'*+/-9=?A-Z^-~]" fullname))
3109 (let ((tmp (concat fullname nil)))
3110 (while (string-match "([^()]*)" tmp)
3111 (aset tmp (match-beginning 0) ?-)
3112 (aset tmp (1- (match-end 0)) ?-))
3113 (string-match "[\\()]" tmp)))))
3115 (goto-char (point-min))
3116 ;; Look for a character that cannot appear unquoted
3117 ;; according to RFC 822.
3118 (when (re-search-forward "[^- !#-'*+/-9=?A-Z^-~]" nil 1)
3119 ;; Quote fullname, escaping specials.
3120 (goto-char (point-min))
3122 (while (re-search-forward "[\"\\]" nil 1)
3123 (replace-match "\\\\\\&" t))
3125 (insert " <" login ">"))
3126 (t ; 'parens or default
3128 (let ((fullname-start (point)))
3130 (goto-char fullname-start)
3131 ;; RFC 822 says \ and nonmatching parentheses
3132 ;; must be escaped in comments.
3133 ;; Escape every instance of ()\ ...
3134 (while (re-search-forward "[()\\]" nil 1)
3135 (replace-match "\\\\\\&" t))
3136 ;; ... then undo escaping of matching parentheses,
3137 ;; including matching nested parentheses.
3138 (goto-char fullname-start)
3139 (while (re-search-forward
3140 "\\(\\=\\|[^\\]\\(\\\\\\\\\\)*\\)\\\\(\\(\\([^\\]\\|\\\\\\\\\\)*\\)\\\\)"
3142 (replace-match "\\1(\\3)" t)
3143 (goto-char fullname-start)))
3147 (defun message-make-sender ()
3148 "Return the \"real\" user address.
3149 This function tries to ignore all user modifications, and
3150 give as trustworthy answer as possible."
3151 (concat (user-login-name) "@" (system-name)))
3153 (defun message-make-address ()
3154 "Make the address of the user."
3155 (or (message-user-mail-address)
3156 (concat (user-login-name) "@" (message-make-domain))))
3158 (defun message-user-mail-address ()
3159 "Return the pertinent part of `user-mail-address'."
3160 (when user-mail-address
3161 (if (string-match " " user-mail-address)
3162 (nth 1 (mail-extract-address-components user-mail-address))
3163 user-mail-address)))
3165 (defun message-make-fqdn ()
3166 "Return user's fully qualified domain name."
3167 (let ((system-name (system-name))
3168 (user-mail (message-user-mail-address)))
3170 ((string-match "[^.]\\.[^.]" system-name)
3171 ;; `system-name' returned the right result.
3173 ;; Try `mail-host-address'.
3174 ((and (boundp 'mail-host-address)
3175 (stringp mail-host-address)
3176 (string-match "\\." mail-host-address))
3178 ;; We try `user-mail-address' as a backup.
3180 (string-match "\\." user-mail)
3181 (string-match "@\\(.*\\)\\'" user-mail))
3182 (match-string 1 user-mail))
3183 ;; Default to this bogus thing.
3185 (concat system-name ".i-did-not-set--mail-host-address--so-shoot-me")))))
3187 (defun message-make-host-name ()
3188 "Return the name of the host."
3189 (let ((fqdn (message-make-fqdn)))
3190 (string-match "^[^.]+\\." fqdn)
3191 (substring fqdn 0 (1- (match-end 0)))))
3193 (defun message-make-domain ()
3194 "Return the domain name."
3195 (or mail-host-address
3196 (message-make-fqdn)))
3198 (defun message-generate-headers (headers)
3199 "Prepare article HEADERS.
3200 Headers already prepared in the buffer are not modified."
3202 (message-narrow-to-headers)
3203 (let* ((Date (message-make-date))
3204 (Message-ID (message-make-message-id))
3205 (Organization (message-make-organization))
3206 (From (message-make-from))
3207 (Path (message-make-path))
3210 (In-Reply-To (message-make-in-reply-to))
3212 (Distribution (message-make-distribution))
3213 (Lines (message-make-lines))
3214 (User-Agent message-newsreader)
3215 (Expires (message-make-expires))
3216 (case-fold-search t)
3218 ;; First we remove any old generated headers.
3219 (let ((headers message-deletable-headers))
3220 (unless (buffer-modified-p)
3221 (setq headers (delq 'Message-ID (copy-sequence headers))))
3223 (goto-char (point-min))
3224 (and (re-search-forward
3225 (concat "^" (symbol-name (car headers)) ": *") nil t)
3226 (get-text-property (1+ (match-beginning 0)) 'message-deletable)
3227 (message-delete-line))
3229 ;; Go through all the required headers and see if they are in the
3230 ;; articles already. If they are not, or are empty, they are
3231 ;; inserted automatically - except for Subject, Newsgroups and
3234 (goto-char (point-min))
3235 (setq elem (pop headers))
3237 (if (eq (car elem) 'optional)
3238 (setq header (cdr elem))
3239 (setq header (car elem)))
3241 (when (or (not (re-search-forward
3245 (if (stringp header)
3247 (symbol-name header))))
3251 ;; The header was found. We insert a space after the
3252 ;; colon, if there is none.
3253 (if (/= (char-after) ? ) (insert " ") (forward-char 1))
3254 ;; Find out whether the header is empty...
3255 (looking-at "[ \t]*\n[^ \t]")))
3256 ;; So we find out what value we should insert.
3259 ((and (consp elem) (eq (car elem) 'optional))
3260 ;; This is an optional header. If the cdr of this
3261 ;; is something that is nil, then we do not insert
3263 (setq header (cdr elem))
3264 (or (and (fboundp (cdr elem)) (funcall (cdr elem)))
3265 (and (boundp (cdr elem)) (symbol-value (cdr elem)))))
3267 ;; The element is a cons. Either the cdr is a
3268 ;; string to be inserted verbatim, or it is a
3269 ;; function, and we insert the value returned from
3271 (or (and (stringp (cdr elem)) (cdr elem))
3272 (and (fboundp (cdr elem)) (funcall (cdr elem)))))
3273 ((and (boundp header) (symbol-value header))
3274 ;; The element is a symbol. We insert the value
3275 ;; of this symbol, if any.
3276 (symbol-value header))
3277 ((not (message-check-element header))
3278 ;; We couldn't generate a value for this header,
3279 ;; so we just ask the user.
3280 (read-from-minibuffer
3281 (format "Empty header for %s; enter value: " header)))))
3282 ;; Finally insert the header.
3284 (not (equal value "")))
3288 ;; This header didn't exist, so we insert it.
3289 (goto-char (point-max))
3290 (insert (if (stringp header) header (symbol-name header))
3293 ;; The value of this header was empty, so we clear
3294 ;; totally and insert the new value.
3295 (delete-region (point) (gnus-point-at-eol))
3297 ;; Add the deletable property to the headers that require it.
3298 (and (memq header message-deletable-headers)
3299 (progn (beginning-of-line) (looking-at "[^:]+: "))
3300 (add-text-properties
3301 (point) (match-end 0)
3302 '(message-deletable t face italic) (current-buffer)))))))
3303 ;; Insert new Sender if the From is strange.
3304 (let ((from (message-fetch-field "from"))
3305 (sender (message-fetch-field "sender"))
3306 (secure-sender (message-make-sender)))
3308 (not (message-check-element 'sender))
3311 (cadr (mail-extract-address-components from)))
3312 (downcase secure-sender)))
3317 (cadr (mail-extract-address-components sender)))
3318 (downcase secure-sender)))))
3319 (goto-char (point-min))
3320 ;; Rename any old Sender headers to Original-Sender.
3321 (when (re-search-forward "^\\(Original-\\)*Sender:" nil t)
3323 (insert "Original-")
3324 (beginning-of-line))
3325 (when (or (message-news-p)
3326 (string-match "@.+\\.." secure-sender))
3327 (insert "Sender: " secure-sender "\n")))))))
3329 (defun message-insert-courtesy-copy ()
3330 "Insert a courtesy message in mail copies of combined messages."
3334 (message-narrow-to-headers)
3335 (when (setq newsgroups (message-fetch-field "newsgroups"))
3336 (goto-char (point-max))
3337 (insert "Posted-To: " newsgroups "\n")))
3339 (when message-courtesy-message
3341 ((string-match "%s" message-courtesy-message)
3342 (insert (format message-courtesy-message newsgroups)))
3344 (insert message-courtesy-message)))))))
3347 ;;; Setting up a message buffer
3350 (defun message-fill-address (header value)
3352 (narrow-to-region (point) (point))
3353 (insert (capitalize (symbol-name header))
3355 (if (consp value) (car value) value)
3357 (narrow-to-region (point-min) (1- (point-max)))
3359 (goto-char (point-min))
3361 (skip-chars-forward "^,\"" (point-max))
3362 (if (or (eq (char-after) ?,)
3365 (if (and (> (current-column) 78)
3371 (setq last (1+ (point))))
3372 (setq last (1+ (point)))))
3373 (setq quoted (not quoted)))
3376 (goto-char (point-max))
3380 (defun message-fill-header (header value)
3381 (let ((begin (point))
3384 (insert (capitalize (symbol-name header))
3386 (if (consp value) (car value) value)
3389 (narrow-to-region begin (point))
3390 (fill-region-as-paragraph begin (point))
3391 ;; Tapdance around looong Message-IDs.
3393 (when (looking-at "[ \t]*$")
3394 (message-delete-line))
3396 (re-search-forward ":" nil t)
3397 (when (looking-at "\n[ \t]+")
3398 (replace-match " " t t))
3399 (goto-char (point-max)))))
3401 (defun message-shorten-1 (list cut surplus)
3402 ;; Cut SURPLUS elements out of LIST, beginning with CUTth one.
3403 (setcdr (nthcdr (- cut 2) list)
3404 (nthcdr (+ (- cut 2) surplus 1) list)))
3406 (defun message-shorten-references (header references)
3407 "Trim REFERENCES to be less than 31 Message-ID long, and fold them.
3408 If folding is disallowed, also check that the REFERENCES are less
3409 than 988 characters long, and if they are not, trim them until they are."
3416 (goto-char (point-min))
3417 ;; Cons a list of valid references.
3418 (while (re-search-forward "<[^>]+>" nil t)
3419 (push (match-string 0) refs))
3420 (setq refs (nreverse refs)
3421 count (length refs)))
3423 ;; If the list has more than MAXCOUNT elements, trim it by
3424 ;; removing the CUTth element and the required number of
3425 ;; elements that follow.
3426 (when (> count maxcount)
3427 (let ((surplus (- count maxcount)))
3428 (message-shorten-1 refs cut surplus)
3429 (decf count surplus)))
3431 ;; If folding is disallowed, make sure the total length (including
3432 ;; the spaces between) will be less than MAXSIZE characters.
3434 ;; Only disallow folding for News messages. At this point the headers
3435 ;; have not been generated, thus we use message-this-is-news directly.
3436 (when (and message-this-is-news message-cater-to-broken-inn)
3438 (totalsize (+ (apply #'+ (mapcar #'length refs))
3441 (ptr (nthcdr (1- cut) refs)))
3442 ;; Decide how many elements to cut off...
3443 (while (> totalsize maxsize)
3444 (decf totalsize (1+ (length (car ptr))))
3446 (setq ptr (cdr ptr)))
3449 (message-shorten-1 refs cut surplus))))
3451 ;; Finally, collect the references back into a string and insert
3452 ;; it into the buffer.
3453 (let ((refstring (mapconcat #'identity refs " ")))
3454 (if (and message-this-is-news message-cater-to-broken-inn)
3455 (insert (capitalize (symbol-name header)) ": "
3457 (message-fill-header header refstring)))))
3459 (defun message-position-point ()
3460 "Move point to where the user probably wants to find it."
3461 (message-narrow-to-headers)
3463 ((re-search-forward "^[^:]+:[ \t]*$" nil t)
3464 (search-backward ":" )
3467 (if (eq (char-after) ? )
3471 (goto-char (point-max))
3474 (unless (looking-at "$")
3478 (defun message-buffer-name (type &optional to group)
3479 "Return a new (unique) buffer name based on TYPE and TO."
3481 ;; Generate a new buffer name The Message Way.
3482 ((eq message-generate-new-buffers 'unique)
3483 (generate-new-buffer-name
3487 (or (car (mail-extract-address-components to))
3490 (if (and group (not (string= group ""))) (concat " on " group) "")
3492 ;; Check whether `message-generate-new-buffers' is a function,
3493 ;; and if so, call it.
3494 ((message-functionp message-generate-new-buffers)
3495 (funcall message-generate-new-buffers type to group))
3496 ((eq message-generate-new-buffers 'unsent)
3497 (generate-new-buffer-name
3498 (concat "*unsent " type
3501 (or (car (mail-extract-address-components to))
3504 (if (and group (not (string= group ""))) (concat " on " group) "")
3506 ;; Use standard name.
3508 (format "*%s message*" type))))
3510 (defun message-pop-to-buffer (name)
3511 "Pop to buffer NAME, and warn if it already exists and is modified."
3512 (let ((buffer (get-buffer name)))
3514 (buffer-name buffer))
3516 (set-buffer (pop-to-buffer buffer))
3517 (when (and (buffer-modified-p)
3519 "Message already being composed; erase? ")))
3520 (error "Message being composed")))
3521 (set-buffer (pop-to-buffer name)))
3525 (defun message-do-send-housekeeping ()
3526 "Kill old message buffers."
3527 ;; We might have sent this buffer already. Delete it from the
3529 (setq message-buffer-list (delq (current-buffer) message-buffer-list))
3530 (while (and message-max-buffers
3532 (>= (length message-buffer-list) message-max-buffers))
3533 ;; Kill the oldest buffer -- unless it has been changed.
3534 (let ((buffer (pop message-buffer-list)))
3535 (when (and (buffer-name buffer)
3536 (not (buffer-modified-p buffer)))
3537 (kill-buffer buffer))))
3538 ;; Rename the buffer.
3539 (if message-send-rename-function
3540 (funcall message-send-rename-function)
3541 (when (string-match "\\`\\*\\(unsent \\)?" (buffer-name))
3543 (concat "*sent " (substring (buffer-name) (match-end 0))) t)))
3544 ;; Push the current buffer onto the list.
3545 (when message-max-buffers
3546 (setq message-buffer-list
3547 (nconc message-buffer-list (list (current-buffer))))))
3549 (defvar mc-modes-alist)
3550 (defun message-setup (headers &optional replybuffer actions)
3551 (when (and (boundp 'mc-modes-alist)
3552 (not (assq 'message-mode mc-modes-alist)))
3553 (push '(message-mode (encrypt . mc-encrypt-message)
3554 (sign . mc-sign-message))
3557 (setq message-send-actions actions))
3558 (setq message-reply-buffer replybuffer)
3559 (goto-char (point-min))
3560 ;; Insert all the headers.
3563 (alist message-header-format-alist))
3565 (unless (assq (caar h) message-header-format-alist)
3566 (push (list (caar h)) alist))
3570 (delete-region (point) (progn (forward-line -1) (point)))
3571 (when message-default-headers
3572 (insert message-default-headers)
3573 (or (bolp) (insert ?\n)))
3577 (insert mail-header-separator "\n")
3581 (when (message-news-p)
3582 (when message-default-news-headers
3583 (insert message-default-news-headers)
3584 (or (bolp) (insert ?\n)))
3585 (when message-generate-headers-first
3586 (message-generate-headers
3589 (copy-sequence message-required-news-headers))))))
3590 (when (message-mail-p)
3591 (when message-default-mail-headers
3592 (insert message-default-mail-headers)
3593 (or (bolp) (insert ?\n)))
3594 (when message-generate-headers-first
3595 (message-generate-headers
3598 (copy-sequence message-required-mail-headers))))))
3599 (run-hooks 'message-signature-setup-hook)
3600 (message-insert-signature)
3602 (message-narrow-to-headers)
3603 (if message-alternative-emails
3604 (message-use-alternative-email-as-from))
3605 (run-hooks 'message-header-setup-hook))
3606 (set-buffer-modified-p nil)
3607 (setq buffer-undo-list nil)
3608 (run-hooks 'message-setup-hook)
3609 (message-position-point)
3612 (defun message-set-auto-save-file-name ()
3613 "Associate the message buffer with a file in the drafts directory."
3614 (when message-auto-save-directory
3616 (setq message-draft-article
3617 (nndraft-request-associate-buffer "drafts"))
3618 (setq buffer-file-name (expand-file-name "*message*"
3619 message-auto-save-directory))
3620 (setq buffer-auto-save-file-name (make-auto-save-file-name)))
3621 (clear-visited-file-modtime)
3622 (setq buffer-file-coding-system message-draft-coding-system)))
3624 (defun message-disassociate-draft ()
3625 "Disassociate the message buffer from the drafts directory."
3626 (when message-draft-article
3627 (nndraft-request-expire-articles
3628 (list message-draft-article) "drafts" nil t)))
3630 (defun message-insert-headers ()
3631 "Generate the headers for the article."
3635 (message-narrow-to-headers)
3636 (when (message-news-p)
3637 (message-generate-headers
3640 (copy-sequence message-required-news-headers)))))
3641 (when (message-mail-p)
3642 (message-generate-headers
3645 (copy-sequence message-required-mail-headers))))))))
3650 ;;; Commands for interfacing with message
3654 (defun message-mail (&optional to subject
3655 other-headers continue switch-function
3656 yank-action send-actions)
3657 "Start editing a mail message to be sent.
3658 OTHER-HEADERS is an alist of header/value pairs."
3660 (let ((message-this-is-mail t))
3661 (message-pop-to-buffer (message-buffer-name "mail" to))
3664 `((To . ,(or to "")) (Subject . ,(or subject "")))
3665 (when other-headers other-headers)))))
3668 (defun message-news (&optional newsgroups subject)
3669 "Start editing a news article to be sent."
3671 (let ((message-this-is-news t))
3672 (message-pop-to-buffer (message-buffer-name "news" nil newsgroups))
3673 (message-setup `((Newsgroups . ,(or newsgroups ""))
3674 (Subject . ,(or subject ""))))))
3676 (defun message-get-reply-headers (wide &optional to-address)
3677 (let (follow-to mct never-mct from to cc reply-to mrt mft ccalist)
3678 ;; Find all relevant headers we need.
3679 (setq from (message-fetch-field "from")
3680 to (message-fetch-field "to")
3681 cc (message-fetch-field "cc")
3682 mct (message-fetch-field "mail-copies-to")
3683 reply-to (message-fetch-field "reply-to")
3684 mrt (message-fetch-field "mail-reply-to")
3685 mft (message-fetch-field "mail-followup-to"))
3687 ;; Handle special values of Mail-Copies-To.
3689 (cond ((or (equal (downcase mct) "never")
3690 (equal (downcase mct) "nobody"))
3693 ((or (equal (downcase mct) "always")
3694 (equal (downcase mct) "poster"))
3695 (setq mct (or mrt reply-to from)))))
3700 (setq follow-to (list (cons 'To (or to-address mrt reply-to from))))
3701 (when (and wide (or mft mct))
3702 (push (cons 'Cc (or mft mct)) follow-to)))
3705 (message-set-work-buffer)
3707 message-use-followup-to
3708 (or (not (eq message-use-followup-to 'ask))
3710 (concat "Obey Mail-Followup-To? ") t "\
3711 You should normally obey the Mail-Followup-To: header. In this
3712 article, it has the value of
3716 which directs your response to " (if (string-match "," mft)
3717 "the specified addresses"
3718 "that address only") ".
3720 If a message is posted to several mailing lists, Mail-Followup-To is
3721 often used to direct the following discussion to one list only,
3722 because discussions that are spread over several lists tend to be
3723 fragmented and very difficult to follow.
3725 Also, some source/announcement lists are not indented for discussion;
3726 responses here are directed to other addresses.")))
3729 (insert (or mrt reply-to from "")))
3730 (insert (if to (concat (if (bolp) "" ", ") to "") ""))
3731 (insert (if mct (concat (if (bolp) "" ", ") mct) ""))
3732 (insert (if cc (concat (if (bolp) "" ", ") cc) "")))
3733 (goto-char (point-min))
3734 (while (re-search-forward "[ \t]+" nil t)
3735 (replace-match " " t t))
3736 ;; Remove addresses that match `rmail-dont-reply-to-names'.
3737 (let ((rmail-dont-reply-to-names message-dont-reply-to-names))
3738 (insert (prog1 (rmail-dont-reply-to (buffer-string))
3740 (goto-char (point-min))
3741 ;; Perhaps "Mail-Copies-To: never" removed the only address?
3743 (insert (or mrt reply-to from "")))
3747 (cons (mail-strip-quoted-names addr) addr))
3748 (message-tokenize-header (buffer-string))))
3751 (setq ccalist (delq (assoc (car (pop s)) s) ccalist)))))
3752 (setq follow-to (list (cons 'To (cdr (pop ccalist)))))
3754 (let ((ccs (cons 'Cc (mapconcat
3755 (lambda (addr) (cdr addr)) ccalist ", "))))
3756 (when (string-match "^ +" (cdr ccs))
3757 (setcdr ccs (substring (cdr ccs) (match-end 0))))
3758 (push ccs follow-to)))))
3762 (defun message-reply (&optional to-address wide)
3763 "Start editing a reply to the article in the current buffer."
3765 (require 'gnus-sum) ; for gnus-list-identifiers
3766 (let ((cur (current-buffer))
3767 from subject date reply-to to cc
3768 references message-id follow-to
3769 (inhibit-point-motion-hooks t)
3770 (message-this-is-mail t)
3773 (message-narrow-to-head)
3774 ;; Allow customizations to have their say.
3776 ;; This is a regular reply.
3777 (if (message-functionp message-reply-to-function)
3778 (setq follow-to (funcall message-reply-to-function)))
3779 ;; This is a followup.
3780 (if (message-functionp message-wide-reply-to-function)
3783 (funcall message-wide-reply-to-function)))))
3784 (setq message-id (message-fetch-field "message-id" t)
3785 references (message-fetch-field "references")
3786 date (message-fetch-field "date")
3787 from (message-fetch-field "from")
3788 subject (or (message-fetch-field "subject") "none"))
3789 (if gnus-list-identifiers
3790 (setq subject (message-strip-list-identifiers subject)))
3791 (setq subject (concat "Re: " (message-strip-subject-re subject)))
3793 (when (and (setq gnus-warning (message-fetch-field "gnus-warning"))
3794 (string-match "<[^>]+>" gnus-warning))
3795 (setq message-id (match-string 0 gnus-warning)))
3798 (setq follow-to (message-get-reply-headers wide to-address))))
3800 (message-pop-to-buffer
3801 (message-buffer-name
3802 (if wide "wide reply" "reply") from
3803 (if wide to-address nil)))
3805 (setq message-reply-headers
3806 (vector 0 subject from date message-id references 0 0 ""))
3809 `((Subject . ,subject)
3811 ,@(if (or references message-id)
3812 `((References . ,(concat (or references "") (and references " ")
3813 (or message-id ""))))
3818 (defun message-wide-reply (&optional to-address)
3819 "Make a \"wide\" reply to the message in the current buffer."
3821 (message-reply to-address t))
3824 (defun message-followup (&optional to-newsgroups)
3825 "Follow up to the message in the current buffer.
3826 If TO-NEWSGROUPS, use that as the new Newsgroups line."
3828 (require 'gnus-sum) ; for gnus-list-identifiers
3829 (let ((cur (current-buffer))
3830 from subject date reply-to mrt mct
3831 references message-id follow-to
3832 (inhibit-point-motion-hooks t)
3833 (message-this-is-news t)
3834 followup-to distribution newsgroups gnus-warning posted-to)
3837 (goto-char (point-min))
3838 (if (search-forward "\n\n" nil t)
3841 (when (message-functionp message-followup-to-function)
3843 (funcall message-followup-to-function)))
3844 (setq from (message-fetch-field "from")
3845 date (message-fetch-field "date")
3846 subject (or (message-fetch-field "subject") "none")
3847 references (message-fetch-field "references")
3848 message-id (message-fetch-field "message-id" t)
3849 followup-to (message-fetch-field "followup-to")
3850 newsgroups (message-fetch-field "newsgroups")
3851 posted-to (message-fetch-field "posted-to")
3852 reply-to (message-fetch-field "reply-to")
3853 mrt (message-fetch-field "mail-reply-to")
3854 distribution (message-fetch-field "distribution")
3855 mct (message-fetch-field "mail-copies-to"))
3856 (when (and (setq gnus-warning (message-fetch-field "gnus-warning"))
3857 (string-match "<[^>]+>" gnus-warning))
3858 (setq message-id (match-string 0 gnus-warning)))
3859 ;; Remove bogus distribution.
3860 (when (and (stringp distribution)
3861 (let ((case-fold-search t))
3862 (string-match "world" distribution)))
3863 (setq distribution nil))
3864 (if gnus-list-identifiers
3865 (setq subject (message-strip-list-identifiers subject)))
3866 (setq subject (concat "Re: " (message-strip-subject-re subject)))
3869 (message-pop-to-buffer (message-buffer-name "followup" from newsgroups))
3872 `((Subject . ,subject)
3875 (list (cons 'Newsgroups to-newsgroups)))
3876 (follow-to follow-to)
3877 ((and followup-to message-use-followup-to)
3880 ((equal (downcase followup-to) "poster")
3881 (if (or (eq message-use-followup-to 'use)
3882 (message-y-or-n-p "Obey Followup-To: poster? " t "\
3883 You should normally obey the Followup-To: header.
3885 `Followup-To: poster' sends your response via e-mail instead of news.
3887 A typical situation where `Followup-To: poster' is used is when the poster
3888 does not read the newsgroup, so he wouldn't see any replies sent to it."))
3890 (setq message-this-is-news nil)
3891 (cons 'To (or mrt reply-to from "")))
3892 (cons 'Newsgroups newsgroups)))
3894 (if (or (equal followup-to newsgroups)
3895 (not (eq message-use-followup-to 'ask))
3897 (concat "Obey Followup-To: " followup-to "? ") t "\
3898 You should normally obey the Followup-To: header.
3900 `Followup-To: " followup-to "'
3901 directs your response to " (if (string-match "," followup-to)
3902 "the specified newsgroups"
3903 "that newsgroup only") ".
3905 If a message is posted to several newsgroups, Followup-To is often
3906 used to direct the following discussion to one newsgroup only,
3907 because discussions that are spread over several newsgroup tend to
3908 be fragmented and very difficult to follow.
3910 Also, some source/announcement newsgroups are not indented for discussion;
3911 responses here are directed to other newsgroups."))
3912 (cons 'Newsgroups followup-to)
3913 (cons 'Newsgroups newsgroups))))))
3915 `((Newsgroups . ,posted-to)))
3917 `((Newsgroups . ,newsgroups))))
3918 ,@(and distribution (list (cons 'Distribution distribution)))
3919 ,@(if (or references message-id)
3920 `((References . ,(concat (or references "") (and references " ")
3921 (or message-id "")))))
3923 (not (or (equal (downcase mct) "never")
3924 (equal (downcase mct) "nobody"))))
3925 (list (cons 'Cc (if (or (equal (downcase mct) "always")
3926 (equal (downcase mct) "poster"))
3927 (or mrt reply-to from "")
3932 (setq message-reply-headers
3933 (vector 0 subject from date message-id references 0 0 ""))))
3937 (defun message-cancel-news (&optional arg)
3938 "Cancel an article you posted.
3939 If ARG, allow editing of the cancellation message."
3941 (unless (message-news-p)
3942 (error "This is not a news article; canceling is impossible"))
3943 (when (yes-or-no-p "Do you really want to cancel this article? ")
3944 (let (from newsgroups message-id distribution buf sender)
3946 ;; Get header info from original article.
3948 (message-narrow-to-head)
3949 (setq from (message-fetch-field "from")
3950 sender (message-fetch-field "sender")
3951 newsgroups (message-fetch-field "newsgroups")
3952 message-id (message-fetch-field "message-id" t)
3953 distribution (message-fetch-field "distribution")))
3954 ;; Make sure that this article was written by the user.
3955 (unless (or (and sender
3958 (downcase (message-make-sender))))
3960 (downcase (cadr (mail-extract-address-components from)))
3961 (downcase (cadr (mail-extract-address-components
3962 (message-make-from))))))
3963 (error "This article is not yours"))
3964 ;; Make control message.
3967 (setq buf (set-buffer (get-buffer-create " *message cancel*"))))
3969 (insert "Newsgroups: " newsgroups "\n"
3971 "Subject: cmsg cancel " message-id "\n"
3972 "Control: cancel " message-id "\n"
3974 (concat "Distribution: " distribution "\n")
3976 mail-header-separator "\n"
3977 message-cancel-message)
3978 (run-hooks 'message-cancel-hook)
3980 (message "Canceling your article...")
3981 (if (let ((message-syntax-checks
3982 'dont-check-for-anything-just-trust-me))
3983 (funcall message-send-news-function))
3984 (message "Canceling your article...done"))
3985 (kill-buffer buf))))))
3988 (defun message-supersede ()
3989 "Start composing a message to supersede the current message.
3990 This is done simply by taking the old article and adding a Supersedes
3991 header line with the old Message-ID."
3993 (let ((cur (current-buffer))
3994 (sender (message-fetch-field "sender"))
3995 (from (message-fetch-field "from")))
3996 ;; Check whether the user owns the article that is to be superseded.
3997 (unless (or (and sender
4000 (downcase (message-make-sender))))
4002 (downcase (cadr (mail-extract-address-components from)))
4003 (downcase (cadr (mail-extract-address-components
4004 (message-make-from))))))
4005 (error "This article is not yours"))
4006 ;; Get a normal message buffer.
4007 (message-pop-to-buffer (message-buffer-name "supersede"))
4008 (insert-buffer-substring cur)
4010 (message-narrow-to-head)
4011 ;; Remove unwanted headers.
4012 (when message-ignored-supersedes-headers
4013 (message-remove-header message-ignored-supersedes-headers t))
4014 (goto-char (point-min))
4015 (if (not (re-search-forward "^Message-ID: " nil t))
4016 (error "No Message-ID in this article")
4017 (replace-match "Supersedes: " t t))
4018 (goto-char (point-max))
4019 (insert mail-header-separator)
4024 (defun message-recover ()
4025 "Reread contents of current buffer from its last auto-save file."
4027 (let ((file-name (make-auto-save-file-name)))
4028 (cond ((save-window-excursion
4029 (if (not (eq system-type 'vax-vms))
4030 (with-output-to-temp-buffer "*Directory*"
4031 (with-current-buffer standard-output
4032 (fundamental-mode)) ; for Emacs 20.4+
4033 (buffer-disable-undo standard-output)
4034 (let ((default-directory "/"))
4036 "ls" nil standard-output nil "-l" file-name))))
4037 (yes-or-no-p (format "Recover auto save file %s? " file-name)))
4038 (let ((buffer-read-only nil))
4040 (insert-file-contents file-name nil)))
4041 (t (error "message-recover cancelled")))))
4043 ;;; Washing Subject:
4045 (defun message-wash-subject (subject)
4046 "Remove junk like \"Re:\", \"(fwd)\", etc. that was added to the subject by previous forwarders, replyers, etc."
4048 (insert-string subject)
4049 (goto-char (point-min))
4050 ;; strip Re/Fwd stuff off the beginning
4051 (while (re-search-forward
4052 "\\([Rr][Ee]:\\|[Ff][Ww][Dd]\\(\\[[0-9]*\\]\\)?:\\|[Ff][Ww]:\\)" nil t)
4055 ;; and gnus-style forwards [foo@bar.com] subject
4056 (goto-char (point-min))
4057 (while (re-search-forward "\\[[^ \t]*\\(@\\|\\.\\)[^ \t]*\\]" nil t)
4061 (goto-char (point-max))
4062 (while (re-search-backward "([Ff][Ww][Dd])" nil t)
4065 ;; and finally, any whitespace that was left-over
4066 (goto-char (point-min))
4067 (while (re-search-forward "^[ \t]+" nil t)
4069 (goto-char (point-max))
4070 (while (re-search-backward "[ \t]+$" nil t)
4075 ;;; Forwarding messages.
4077 (defun message-forward-subject-author-subject (subject)
4078 "Generate a subject for a forwarded message.
4079 The form is: [Source] Subject, where if the original message was mail,
4080 Source is the sender, and if the original message was news, Source is
4081 the list of newsgroups is was posted to."
4083 (or (message-fetch-field
4084 (if (message-news-p) "newsgroups" "from"))
4088 (defun message-forward-subject-fwd (subject)
4089 "Generate a subject for a forwarded message.
4090 The form is: Fwd: Subject, where Subject is the original subject of
4092 (concat "Fwd: " subject))
4094 (defun message-make-forward-subject ()
4095 "Return a Subject header suitable for the message in the current buffer."
4099 (message-narrow-to-head)
4100 (let ((funcs message-make-forward-subject-function)
4101 (subject (if message-wash-forwarded-subjects
4102 (message-wash-subject
4103 (or (message-fetch-field "Subject") ""))
4104 (or (message-fetch-field "Subject") ""))))
4105 ;; Make sure funcs is a list.
4108 (setq funcs (list funcs)))
4109 ;; Apply funcs in order, passing subject generated by previous
4110 ;; func to the next one.
4112 (when (message-functionp (car funcs))
4113 (setq subject (funcall (car funcs) subject)))
4114 (setq funcs (cdr funcs)))
4118 (defun message-forward (&optional news digest)
4119 "Forward the current message via mail.
4120 Optional NEWS will use news to forward instead of mail.
4121 Optional DIGEST will use digest to forward."
4123 (let* ((cur (current-buffer))
4124 (subject (if message-forward-show-mml
4125 (message-make-forward-subject)
4126 (mail-decode-encoded-word-string
4127 (message-make-forward-subject))))
4130 (message-news nil subject)
4131 (message-mail nil subject))
4132 ;; Put point where we want it before inserting the forwarded
4134 (if message-forward-before-signature
4136 (goto-char (point-max)))
4137 (if message-forward-as-mime
4139 (insert "\n<#multipart type=digest>\n")
4140 (if message-forward-show-mml
4141 (insert "\n\n<#mml type=message/rfc822 disposition=inline>\n")
4142 (insert "\n\n<#part type=message/rfc822 disposition=inline raw=t>\n")))
4143 (insert "\n-------------------- Start of forwarded message --------------------\n"))
4144 (let ((b (point)) e)
4146 (if message-forward-as-mime
4147 (insert-buffer-substring cur)
4148 (mml-insert-buffer cur))
4149 (if message-forward-show-mml
4150 (insert-buffer-substring cur)
4151 (mml-insert-buffer cur)))
4153 (if message-forward-as-mime
4155 (insert "<#/multipart>\n")
4156 (if message-forward-show-mml
4157 (insert "<#/mml>\n")
4158 (insert "<#/part>\n")))
4159 (insert "\n-------------------- End of forwarded message --------------------\n"))
4160 (if (and digest message-forward-as-mime)
4162 (narrow-to-region b e)
4164 (narrow-to-region (point)
4165 (or (search-forward "\n\n" nil t) (point)))
4166 (delete-region (point-min) (point-max)))
4167 (when (and (not current-prefix-arg)
4168 message-forward-ignored-headers)
4170 (narrow-to-region b e)
4172 (narrow-to-region (point)
4173 (or (search-forward "\n\n" nil t) (point)))
4174 (message-remove-header message-forward-ignored-headers t)))))
4175 (message-position-point)))
4178 (defun message-resend (address)
4179 "Resend the current article to ADDRESS."
4181 (list (message-read-from-minibuffer "Resend message to: ")))
4182 (message "Resending message to %s..." address)
4184 (let ((cur (current-buffer))
4186 ;; We first set up a normal mail buffer.
4187 (set-buffer (get-buffer-create " *message resend*"))
4189 (message-setup `((To . ,address)))
4190 ;; Insert our usual headers.
4191 (message-generate-headers '(From Date To))
4192 (message-narrow-to-headers)
4193 ;; Rename them all to "Resent-*".
4194 (while (re-search-forward "^[A-Za-z]" nil t)
4199 (delete-region (point) (point-max))
4201 ;; Insert the message to be resent.
4202 (insert-buffer-substring cur)
4203 (goto-char (point-min))
4204 (search-forward "\n\n")
4207 (narrow-to-region beg (point))
4208 (message-remove-header message-ignored-resent-headers t)
4209 (goto-char (point-max)))
4210 (insert mail-header-separator)
4211 ;; Rename all old ("Also-")Resent headers.
4212 (while (re-search-backward "^\\(Also-\\)*Resent-" beg t)
4215 ;; Quote any "From " lines at the beginning.
4217 (when (looking-at "From ")
4218 (replace-match "X-From-Line: "))
4220 (let ((message-inhibit-body-encoding t)
4221 message-required-mail-headers)
4222 (message-send-mail))
4223 (kill-buffer (current-buffer)))
4224 (message "Resending message to %s...done" address)))
4227 (defun message-bounce ()
4228 "Re-mail the current message.
4229 This only makes sense if the current message is a bounce message that
4230 contains some mail you have written which has been bounced back to
4233 (let ((handles (mm-dissect-buffer t))
4235 (message-pop-to-buffer (message-buffer-name "bounce"))
4236 (if (stringp (car handles))
4237 ;; This is a MIME bounce.
4238 (mm-insert-part (car (last handles)))
4239 ;; This is a non-MIME bounce, so we try to remove things
4241 (mm-insert-part handles)
4243 (goto-char (point-min))
4244 (search-forward "\n\n" nil t)
4245 (or (and (re-search-forward message-unsent-separator nil t)
4247 (re-search-forward "^Return-Path:.*\n" nil t))
4248 ;; We remove everything before the bounced mail.
4251 (if (re-search-forward "^[^ \n\t]+:" nil t)
4254 (mm-enable-multibyte)
4257 (message-narrow-to-head)
4258 (message-remove-header message-ignored-bounced-headers t)
4259 (goto-char (point-max))
4260 (insert mail-header-separator))
4261 (message-position-point)))
4264 ;;; Interactive entry points for new message buffers.
4268 (defun message-mail-other-window (&optional to subject)
4269 "Like `message-mail' command, but display mail buffer in another window."
4271 (let ((pop-up-windows t)
4272 (special-display-buffer-names nil)
4273 (special-display-regexps nil)
4274 (same-window-buffer-names nil)
4275 (same-window-regexps nil))
4276 (message-pop-to-buffer (message-buffer-name "mail" to)))
4277 (let ((message-this-is-mail t))
4278 (message-setup `((To . ,(or to "")) (Subject . ,(or subject ""))))))
4281 (defun message-mail-other-frame (&optional to subject)
4282 "Like `message-mail' command, but display mail buffer in another frame."
4284 (let ((pop-up-frames t)
4285 (special-display-buffer-names nil)
4286 (special-display-regexps nil)
4287 (same-window-buffer-names nil)
4288 (same-window-regexps nil))
4289 (message-pop-to-buffer (message-buffer-name "mail" to)))
4290 (let ((message-this-is-mail t))
4291 (message-setup `((To . ,(or to "")) (Subject . ,(or subject ""))))))
4294 (defun message-news-other-window (&optional newsgroups subject)
4295 "Start editing a news article to be sent."
4297 (let ((pop-up-windows t)
4298 (special-display-buffer-names nil)
4299 (special-display-regexps nil)
4300 (same-window-buffer-names nil)
4301 (same-window-regexps nil))
4302 (message-pop-to-buffer (message-buffer-name "news" nil newsgroups)))
4303 (let ((message-this-is-news t))
4304 (message-setup `((Newsgroups . ,(or newsgroups ""))
4305 (Subject . ,(or subject ""))))))
4308 (defun message-news-other-frame (&optional newsgroups subject)
4309 "Start editing a news article to be sent."
4311 (let ((pop-up-frames t)
4312 (special-display-buffer-names nil)
4313 (special-display-regexps nil)
4314 (same-window-buffer-names nil)
4315 (same-window-regexps nil))
4316 (message-pop-to-buffer (message-buffer-name "news" nil newsgroups)))
4317 (let ((message-this-is-news t))
4318 (message-setup `((Newsgroups . ,(or newsgroups ""))
4319 (Subject . ,(or subject ""))))))
4323 ;; This code should be moved to underline.el (from which it is stolen).
4326 (defun bold-region (start end)
4327 "Bold all nonblank characters in the region.
4328 Works by overstriking characters.
4329 Called from program, takes two arguments START and END
4330 which specify the range to operate on."
4333 (let ((end1 (make-marker)))
4334 (move-marker end1 (max start end))
4335 (goto-char (min start end))
4336 (while (< (point) end1)
4337 (or (looking-at "[_\^@- ]")
4338 (insert (char-after) "\b"))
4339 (forward-char 1)))))
4342 (defun unbold-region (start end)
4343 "Remove all boldness (overstruck characters) in the region.
4344 Called from program, takes two arguments START and END
4345 which specify the range to operate on."
4348 (let ((end1 (make-marker)))
4349 (move-marker end1 (max start end))
4350 (goto-char (min start end))
4351 (while (re-search-forward "\b" end1 t)
4352 (if (eq (char-after) (char-after (- (point) 2)))
4353 (delete-char -2))))))
4355 (defalias 'message-exchange-point-and-mark 'exchange-point-and-mark)
4357 ;; Support for toolbar
4358 (when (featurep 'xemacs)
4359 (require 'messagexmas))
4361 ;;; Group name completion.
4363 (defvar message-newgroups-header-regexp
4364 "^\\(Newsgroups\\|Followup-To\\|Posted-To\\|Gcc\\):"
4365 "Regexp that match headers that lists groups.")
4367 (defun message-tab ()
4368 "Expand group names in Newsgroups and Followup-To headers.
4369 Do a `tab-to-tab-stop' if not in those headers."
4371 (if (let ((mail-abbrev-mode-regexp message-newgroups-header-regexp))
4372 (mail-abbrev-in-expansion-header-p))
4373 (message-expand-group)
4376 (defvar gnus-active-hashtb)
4377 (defun message-expand-group ()
4378 "Expand the group name under point."
4379 (let* ((b (save-excursion
4384 (skip-chars-forward "^:")
4387 (skip-chars-backward "^, \t\n") (point))))
4388 (completion-ignore-case t)
4389 (string (buffer-substring b (progn (skip-chars-forward "^,\t\n ")
4391 (hashtb (and (boundp 'gnus-active-hashtb) gnus-active-hashtb))
4392 (completions (all-completions string hashtb))
4394 (delete-region b (point))
4396 ((= (length completions) 1)
4397 (if (string= (car completions) string)
4400 (message "Only matching group"))
4401 (insert (car completions))))
4402 ((and (setq comp (try-completion string hashtb))
4403 (not (string= comp string)))
4408 (message "No matching groups")
4409 (save-selected-window
4410 (pop-to-buffer "*Completions*")
4411 (buffer-disable-undo)
4412 (let ((buffer-read-only nil))
4414 (let ((standard-output (current-buffer)))
4415 (display-completion-list (sort completions 'string<)))
4416 (goto-char (point-min))
4417 (delete-region (point) (progn (forward-line 3) (point))))))))))
4421 (defun message-talkative-question (ask question show &rest text)
4422 "Call FUNCTION with argument QUESTION; optionally display TEXT... args.
4423 If SHOW is non-nil, the arguments TEXT... are displayed in a temp buffer.
4424 The following arguments may contain lists of values."
4426 (setq text (message-flatten-list text)))
4427 (save-window-excursion
4429 (with-output-to-temp-buffer " *MESSAGE information message*"
4430 (set-buffer " *MESSAGE information message*")
4431 (fundamental-mode) ; for Emacs 20.4+
4432 (mapcar 'princ text)
4433 (goto-char (point-min))))
4434 (funcall ask question))
4435 (funcall ask question)))
4437 (defun message-flatten-list (list)
4438 "Return a new, flat list that contains all elements of LIST.
4440 \(message-flatten-list '(1 (2 3 (4 5 (6))) 7))
4443 (apply 'append (mapcar 'message-flatten-list list)))
4447 (defun message-generate-new-buffer-clone-locals (name &optional varstr)
4448 "Create and return a buffer with a name based on NAME using generate-new-buffer.
4449 Then clone the local variables and values from the old buffer to the
4450 new one, cloning only the locals having a substring matching the
4452 (let ((oldbuf (current-buffer)))
4454 (set-buffer (generate-new-buffer name))
4455 (message-clone-locals oldbuf varstr)
4458 (defun message-clone-locals (buffer &optional varstr)
4459 "Clone the local variables from BUFFER to the current buffer."
4460 (let ((locals (save-excursion
4462 (buffer-local-variables)))
4463 (regexp "^gnus\\|^nn\\|^message\\|^user-mail-address"))
4466 (when (and (consp local)
4468 (string-match regexp (symbol-name (car local)))
4470 (string-match varstr (symbol-name (car local)))))
4472 (set (make-local-variable (car local))
4476 ;;; Miscellaneous functions
4478 (defsubst message-replace-chars-in-string (string from to)
4479 (mm-subst-char-in-string from to string))
4485 (defvar message-inhibit-body-encoding nil)
4487 (defun message-encode-message-body ()
4488 (unless message-inhibit-body-encoding
4489 (let ((mail-parse-charset (or mail-parse-charset
4490 message-default-charset))
4491 (case-fold-search t)
4492 lines content-type-p)
4495 (narrow-to-region (point) (point-max))
4496 (let ((new (mml-generate-mime)))
4498 (delete-region (point-min) (point-max))
4500 (goto-char (point-min))
4501 (if (eq (aref new 0) ?\n)
4503 (search-forward "\n\n")
4504 (setq lines (buffer-substring (point-min) (1- (point))))
4505 (delete-region (point-min) (point))))))
4507 (message-narrow-to-headers-or-head)
4508 (message-remove-header "Mime-Version")
4509 (goto-char (point-max))
4510 (insert "MIME-Version: 1.0\n")
4513 (setq content-type-p
4514 (re-search-backward "^Content-Type:" nil t)))
4516 (message-narrow-to-headers-or-head)
4517 (message-remove-first-header "Content-Type")
4518 (message-remove-first-header "Content-Transfer-Encoding"))
4519 ;; We always make sure that the message has a Content-Type header.
4520 ;; This is because some broken MTAs and MUAs get awfully confused
4521 ;; when confronted with a message with a MIME-Version header and
4522 ;; without a Content-Type header. For instance, Solaris'
4524 (unless content-type-p
4525 (goto-char (point-min))
4526 (re-search-forward "^MIME-Version:")
4528 (insert "Content-Type: text/plain; charset=us-ascii\n")))))
4530 (defun message-read-from-minibuffer (prompt)
4531 "Read from the minibuffer while providing abbrev expansion."
4532 (if (fboundp 'mail-abbrevs-setup)
4533 (let ((mail-abbrev-mode-regexp "")
4534 (minibuffer-setup-hook 'mail-abbrevs-setup))
4535 (read-from-minibuffer prompt))
4536 (let ((minibuffer-setup-hook 'mail-abbrev-minibuffer-setup-hook))
4537 (read-string prompt))))
4539 (defun message-use-alternative-email-as-from ()
4540 (require 'mail-utils)
4541 (let* ((fields '("To" "Cc"))
4544 (mail-strip-quoted-names
4545 (mapconcat 'message-fetch-reply-field fields ","))
4549 (if (string-match message-alternative-emails (car emails))
4550 (setq email (car emails)
4553 (unless (or (not email) (equal email user-mail-address))
4554 (goto-char (point-max))
4555 (insert "From: " email "\n"))))
4557 (defun message-options-get (symbol)
4558 (cdr (assq symbol message-options)))
4560 (defun message-options-set (symbol value)
4561 (let ((the-cons (assq symbol message-options)))
4564 (setcdr the-cons value)
4565 (setq message-options (delq the-cons message-options)))
4567 (push (cons symbol value) message-options))))
4570 (defun message-options-set-recipient ()
4572 (message-narrow-to-headers-or-head)
4573 (message-options-set 'message-sender
4574 (mail-strip-quoted-names
4575 (message-fetch-field "from")))
4576 (message-options-set 'message-recipients
4577 (mail-strip-quoted-names
4578 (message-fetch-field "to")))))
4582 (run-hooks 'message-load-hook)
4585 ;; coding: iso-8859-1
4588 ;;; message.el ends here