1 ;;; message.el --- composing mail and news messages
2 ;; Copyright (C) 1996,97 Free Software Foundation, Inc.
4 ;; Author: Lars Magne Ingebrigtsen <larsi@ifi.uio.no>
5 ;; Keywords: mail, news
7 ;; This file is part of GNU Emacs.
9 ;; GNU Emacs is free software; you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation; either version 2, or (at your option)
14 ;; GNU Emacs is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; GNU General Public License for more details.
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs; see the file COPYING. If not, write to the
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22 ;; Boston, MA 02111-1307, USA.
26 ;; This mode provides mail-sending facilities from within Emacs. It
27 ;; consists mainly of large chunks of code from the sendmail.el,
28 ;; gnus-msg.el and rnewspost.el files.
32 (eval-when-compile (require 'cl))
37 (t (message "Ignore any errors about rmail from this file")))
42 (if (string-match "XEmacs\\|Lucid" emacs-version)
43 (require 'mail-abbrevs)
44 (require 'mailabbrev))
46 (defgroup message '((user-mail-address custom-variable)
47 (user-full-name custom-variable))
48 "Mail and news message composing."
49 :link '(custom-manual "(message)Top")
53 (put 'user-mail-address 'custom-type 'string)
54 (put 'user-full-name 'custom-type 'string)
56 (defgroup message-various nil
57 "Various Message Variables"
58 :link '(custom-manual "(message)Various Message Variables")
61 (defgroup message-buffers nil
63 :link '(custom-manual "(message)Message Buffers")
66 (defgroup message-sending nil
68 :link '(custom-manual "(message)Sending Variables")
71 (defgroup message-interface nil
73 :link '(custom-manual "(message)Interface")
76 (defgroup message-forwarding nil
78 :link '(custom-manual "(message)Forwarding")
79 :group 'message-interface)
81 (defgroup message-insertion nil
83 :link '(custom-manual "(message)Insertion")
86 (defgroup message-headers nil
88 :link '(custom-manual "(message)Message Headers")
91 (defgroup message-news nil
92 "Composing News Messages"
95 (defgroup message-mail nil
96 "Composing Mail Messages"
99 (defgroup message-faces nil
100 "Faces used for message composing."
104 (defcustom message-directory "~/Mail/"
105 "*Directory from which all other mail file variables are derived."
106 :group 'message-various
109 (defcustom message-max-buffers 10
110 "*How many buffers to keep before starting to kill them off."
111 :group 'message-buffers
114 (defcustom message-send-rename-function nil
115 "Function called to rename the buffer after sending it."
116 :group 'message-buffers
119 (defcustom message-fcc-handler-function 'message-output
120 "*A function called to save outgoing articles.
121 This function will be called with the name of the file to store the
122 article in. The default function is `message-output' which saves in Unix
124 :type '(radio (function-item message-output)
125 (function :tag "Other"))
126 :group 'message-sending)
128 (defcustom message-courtesy-message
129 "The following message is a courtesy copy of an article\nthat has been posted to %s as well.\n\n"
130 "*This is inserted at the start of a mailed copy of a posted message.
131 If the string contains the format spec \"%s\", the Newsgroups
132 the article has been posted to will be inserted there.
133 If this variable is nil, no such courtesy message will be added."
134 :group 'message-sending
137 (defcustom message-ignored-bounced-headers "^\\(Received\\|Return-Path\\):"
138 "*Regexp that matches headers to be removed in resent bounced mail."
139 :group 'message-interface
143 (defcustom message-from-style 'default
144 "*Specifies how \"From\" headers look.
146 If `nil', they contain just the return address like:
148 If `parens', they look like:
149 king@grassland.com (Elvis Parsley)
150 If `angles', they look like:
151 Elvis Parsley <king@grassland.com>
153 Otherwise, most addresses look like `angles', but they look like
154 `parens' if `angles' would need quoting and `parens' would not."
155 :type '(choice (const :tag "simple" nil)
159 :group 'message-headers)
161 (defcustom message-syntax-checks nil
162 ;; Guess this one shouldn't be easy to customize...
163 "Controls what syntax checks should not be performed on outgoing posts.
164 To disable checking of long signatures, for instance, add
165 `(signature . disabled)' to this list.
167 Don't touch this variable unless you really know what you're doing.
169 Checks include subject-cmsg multiple-headers sendsys message-id from
170 long-lines control-chars size new-text redirected-followup signature
171 approved sender empty empty-headers message-id from subject
172 shorten-followup-to existing-newsgroups buffer-file-name unchanged."
173 :group 'message-news)
175 (defcustom message-required-news-headers
176 '(From Newsgroups Subject Date Message-ID
177 (optional . Organization) Lines
178 (optional . X-Newsreader))
179 "Headers to be generated or prompted for when posting an article.
180 RFC977 and RFC1036 require From, Date, Newsgroups, Subject,
181 Message-ID. Organization, Lines, In-Reply-To, Expires, and
182 X-Newsreader are optional. If don't you want message to insert some
183 header, remove it from this list."
185 :group 'message-headers
186 :type '(repeat sexp))
188 (defcustom message-required-mail-headers
189 '(From Subject Date (optional . In-Reply-To) Message-ID Lines
190 (optional . X-Mailer))
191 "Headers to be generated or prompted for when mailing a message.
192 RFC822 required that From, Date, To, Subject and Message-ID be
193 included. Organization, Lines and X-Mailer are optional."
195 :group 'message-headers
196 :type '(repeat sexp))
198 (defcustom message-deletable-headers '(Message-ID Date Lines)
199 "Headers to be deleted if they already exist and were generated by message previously."
200 :group 'message-headers
203 (defcustom message-ignored-news-headers
204 "^NNTP-Posting-Host:\\|^Xref:\\|^[BGF]cc:\\|^Resent-Fcc:"
205 "*Regexp of headers to be removed unconditionally before posting."
207 :group 'message-headers
210 (defcustom message-ignored-mail-headers "^[GF]cc:\\|^Resent-Fcc:"
211 "*Regexp of headers to be removed unconditionally before mailing."
213 :group 'message-headers
216 (defcustom message-ignored-supersedes-headers "^Path:\\|^Date\\|^NNTP-Posting-Host:\\|^Xref:\\|^Lines:\\|^Received:\\|^X-From-Line:\\|X-Trace:\\|X-Complaints-To:\\|Return-Path:\\|^Supersedes:"
217 "*Header lines matching this regexp will be deleted before posting.
218 It's best to delete old Path and Date headers before posting to avoid
220 :group 'message-interface
224 (defcustom message-signature-separator "^-- *$"
225 "Regexp matching the signature separator."
227 :group 'message-various)
229 (defcustom message-elide-elipsis "\n[...]\n\n"
230 "*The string which is inserted for elided text.")
232 (defcustom message-interactive nil
233 "Non-nil means when sending a message wait for and display errors.
234 nil means let mailer mail back a message to report errors."
235 :group 'message-sending
239 (defcustom message-generate-new-buffers t
240 "*Non-nil means that a new message buffer will be created whenever `mail-setup' is called.
241 If this is a function, call that function with three parameters: The type,
242 the to address and the group name. (Any of these may be nil.) The function
243 should return the new buffer name."
244 :group 'message-buffers
245 :type '(choice (const :tag "off" nil)
249 (defcustom message-kill-buffer-on-exit nil
250 "*Non-nil means that the message buffer will be killed after sending a message."
251 :group 'message-buffers
254 (defvar gnus-local-organization)
255 (defcustom message-user-organization
256 (or (and (boundp 'gnus-local-organization)
257 (stringp gnus-local-organization)
258 gnus-local-organization)
259 (getenv "ORGANIZATION")
261 "*String to be used as an Organization header.
262 If t, use `message-user-organization-file'."
263 :group 'message-headers
264 :type '(choice string
265 (const :tag "consult file" t)))
268 (defcustom message-user-organization-file "/usr/lib/news/organization"
269 "*Local news organization file."
271 :group 'message-headers)
273 (defcustom message-autosave-directory
274 (nnheader-concat message-directory "drafts/")
275 "*Directory where Message autosaves buffers.
276 If nil, Message won't autosave."
277 :group 'message-buffers
280 (defcustom message-forward-start-separator
281 "------- Start of forwarded message -------\n"
282 "*Delimiter inserted before forwarded messages."
283 :group 'message-forwarding
286 (defcustom message-forward-end-separator
287 "------- End of forwarded message -------\n"
288 "*Delimiter inserted after forwarded messages."
289 :group 'message-forwarding
292 (defcustom message-signature-before-forwarded-message t
293 "*If non-nil, put the signature before any included forwarded message."
294 :group 'message-forwarding
297 (defcustom message-included-forward-headers
298 "^From:\\|^Newsgroups:\\|^Subject:\\|^Date:\\|^Followup-To:\\|^Reply-To:\\|^Organization:\\|^Summary:\\|^Keywords:\\|^To:\\|^Cc:\\|^Posted-To:\\|^Mail-Copies-To:\\|^Apparently-To:\\|^Gnus-Warning:\\|^Resent-\\|^Message-ID:\\|^References:\\|^Content-Transfer-Encoding:\\|^Content-Type:\\|^Mime-Version:"
299 "*Regexp matching headers to be included in forwarded messages."
300 :group 'message-forwarding
303 (defcustom message-ignored-resent-headers "^Return-receipt"
304 "*All headers that match this regexp will be deleted when resending a message."
305 :group 'message-interface
308 (defcustom message-ignored-cited-headers "."
309 "*Delete these headers from the messages you yank."
310 :group 'message-insertion
313 (defcustom message-cancel-message "I am canceling my own article."
314 "Message to be inserted in the cancel message."
315 :group 'message-interface
318 ;; Useful to set in site-init.el
320 (defcustom message-send-mail-function 'message-send-mail-with-sendmail
321 "Function to call to send the current buffer as mail.
322 The headers should be delimited by a line whose contents match the
323 variable `mail-header-separator'.
325 Legal values include `message-send-mail-with-sendmail' (the default),
326 `message-send-mail-with-mh' and `message-send-mail-with-qmail'."
327 :type '(radio (function-item message-send-mail-with-sendmail)
328 (function-item message-send-mail-with-mh)
329 (function-item message-send-mail-with-qmail)
330 (function :tag "Other"))
331 :group 'message-sending
332 :group 'message-mail)
334 ;; 1997-09-29 by MORIOKA Tomohiko
335 (defcustom message-send-news-function 'message-send-news-with-gnus
336 "Function to call to send the current buffer as news.
337 The headers should be delimited by a line whose contents match the
338 variable `mail-header-separator'."
339 :group 'message-sending
343 (defcustom message-reply-to-function nil
344 "Function that should return a list of headers.
345 This function should pick out addresses from the To, Cc, and From headers
346 and respond with new To and Cc headers."
347 :group 'message-interface
350 (defcustom message-wide-reply-to-function nil
351 "Function that should return a list of headers.
352 This function should pick out addresses from the To, Cc, and From headers
353 and respond with new To and Cc headers."
354 :group 'message-interface
357 (defcustom message-followup-to-function nil
358 "Function that should return a list of headers.
359 This function should pick out addresses from the To, Cc, and From headers
360 and respond with new To and Cc headers."
361 :group 'message-interface
364 (defcustom message-use-followup-to 'ask
365 "*Specifies what to do with Followup-To header.
366 If nil, always ignore the header. If it is t, use its value, but
367 query before using the \"poster\" value. If it is the symbol `ask',
368 always query the user whether to use the value. If it is the symbol
369 `use', always use the value."
370 :group 'message-interface
371 :type '(choice (const :tag "ignore" nil)
375 ;; stuff relating to broken sendmail in MMDF
376 (defcustom message-sendmail-f-is-evil nil
377 "*Non-nil means that \"-f username\" should not be added to the sendmail
378 command line, because it is even more evil than leaving it out."
379 :group 'message-sending
382 ;; qmail-related stuff
383 (defcustom message-qmail-inject-program "/var/qmail/bin/qmail-inject"
384 "Location of the qmail-inject program."
385 :group 'message-sending
388 (defcustom message-qmail-inject-args nil
389 "Arguments passed to qmail-inject programs.
390 This should be a list of strings, one string for each argument.
392 For e.g., if you wish to set the envelope sender address so that bounces
393 go to the right place or to deal with listserv's usage of that address, you
394 might set this variable to '(\"-f\" \"you@some.where\")."
395 :group 'message-sending
396 :type '(repeat string))
398 (defvar gnus-post-method)
399 (defvar gnus-select-method)
400 (defcustom message-post-method
401 (cond ((and (boundp 'gnus-post-method)
404 ((boundp 'gnus-select-method)
407 "Method used to post news."
409 :group 'message-sending
410 ;; This should be the `gnus-select-method' widget, but that might
411 ;; create a dependence to `gnus.el'.
414 (defcustom message-generate-headers-first nil
415 "*If non-nil, generate all possible headers before composing."
416 :group 'message-headers
419 (defcustom message-setup-hook nil
420 "Normal hook, run each time a new outgoing message is initialized.
421 The function `message-setup' runs this hook."
422 :group 'message-various
425 (defcustom message-signature-setup-hook nil
426 "Normal hook, run each time a new outgoing message is initialized.
427 It is run after the headers have been inserted and before
428 the signature is inserted."
429 :group 'message-various
432 (defcustom message-mode-hook nil
433 "Hook run in message mode buffers."
434 :group 'message-various
437 (defcustom message-header-hook nil
438 "Hook run in a message mode buffer narrowed to the headers."
439 :group 'message-various
442 (defcustom message-header-setup-hook nil
443 "Hook called narrowed to the headers when setting up a message
445 :group 'message-various
449 (defcustom message-citation-line-function 'message-insert-citation-line
450 "*Function called to insert the \"Whomever writes:\" line."
452 :group 'message-insertion)
455 (defcustom message-yank-prefix "> "
456 "*Prefix inserted on the lines of yanked messages.
457 nil means use indentation."
459 :group 'message-insertion)
461 (defcustom message-indentation-spaces 3
462 "*Number of spaces to insert at the beginning of each cited line.
463 Used by `message-yank-original' via `message-yank-cite'."
464 :group 'message-insertion
468 (defcustom message-cite-function
469 (if (and (boundp 'mail-citation-hook)
472 'message-cite-original)
473 "*Function for citing an original message."
474 :type '(radio (function-item message-cite-original)
475 (function-item sc-cite-original)
476 (function :tag "Other"))
477 :group 'message-insertion)
480 (defcustom message-indent-citation-function 'message-indent-citation
481 "*Function for modifying a citation just inserted in the mail buffer.
482 This can also be a list of functions. Each function can find the
483 citation between (point) and (mark t). And each function should leave
484 point and mark around the citation text as modified."
486 :group 'message-insertion)
488 (defvar message-abbrevs-loaded nil)
491 (defcustom message-signature t
492 "*String to be inserted at the end of the message buffer.
493 If t, the `message-signature-file' file will be inserted instead.
494 If a function, the result from the function will be used instead.
495 If a form, the result from the form will be used instead."
497 :group 'message-insertion)
500 (defcustom message-signature-file "~/.signature"
501 "*File containing the text inserted at end of message buffer."
503 :group 'message-insertion)
505 (defcustom message-distribution-function nil
506 "*Function called to return a Distribution header."
508 :group 'message-headers
511 (defcustom message-expires 14
512 "Number of days before your article expires."
514 :group 'message-headers
515 :link '(custom-manual "(message)News Headers")
518 (defcustom message-user-path nil
519 "If nil, use the NNTP server name in the Path header.
520 If stringp, use this; if non-nil, use no host name (user name only)."
522 :group 'message-headers
523 :link '(custom-manual "(message)News Headers")
524 :type '(choice (const :tag "nntp" nil)
526 (sexp :tag "none" :format "%t" t)))
528 (defvar message-reply-buffer nil)
529 (defvar message-reply-headers nil)
530 (defvar message-newsreader nil)
531 (defvar message-mailer nil)
532 (defvar message-sent-message-via nil)
533 (defvar message-checksum nil)
534 (defvar message-send-actions nil
535 "A list of actions to be performed upon successful sending of a message.")
536 (defvar message-exit-actions nil
537 "A list of actions to be performed upon exiting after sending a message.")
538 (defvar message-kill-actions nil
539 "A list of actions to be performed before killing a message buffer.")
540 (defvar message-postpone-actions nil
541 "A list of actions to be performed after postponing a message.")
543 (define-widget 'message-header-lines 'text
544 "All header lines must be LFD terminated."
546 :error "All header lines must be newline terminated")
548 (defcustom message-default-headers ""
549 "*A string containing header lines to be inserted in outgoing messages.
550 It is inserted before you edit the message, so you can edit or delete
552 :group 'message-headers
553 :type 'message-header-lines)
555 (defcustom message-default-mail-headers ""
556 "*A string of header lines to be inserted in outgoing mails."
557 :group 'message-headers
559 :type 'message-header-lines)
561 (defcustom message-default-news-headers ""
562 "*A string of header lines to be inserted in outgoing news
564 :group 'message-headers
566 :type 'message-header-lines)
568 ;; Note: could use /usr/ucb/mail instead of sendmail;
569 ;; options -t, and -v if not interactive.
570 (defcustom message-mailer-swallows-blank-line
571 (if (and (string-match "sparc-sun-sunos\\(\\'\\|[^5]\\)"
572 system-configuration)
573 (file-readable-p "/etc/sendmail.cf")
574 (let ((buffer (get-buffer-create " *temp*")))
578 (insert-file-contents "/etc/sendmail.cf")
579 (goto-char (point-min))
580 (let ((case-fold-search nil))
581 (re-search-forward "^OR\\>" nil t)))
582 (kill-buffer buffer))))
583 ;; According to RFC822, "The field-name must be composed of printable
584 ;; ASCII characters (i. e., characters that have decimal values between
585 ;; 33 and 126, except colon)", i. e., any chars except ctl chars,
587 '(looking-at "[ \t]\\|[][!\"#$%&'()*+,-./0-9;<=>?@A-Z\\\\^_`a-z{|}~]+:"))
588 "Set this non-nil if the system's mailer runs the header and body together.
589 \(This problem exists on Sunos 4 when sendmail is run in remote mode.)
590 The value should be an expression to test whether the problem will
592 :group 'message-sending
595 ;; Ignore errors in case this is used in Emacs 19.
596 ;; Don't use ignore-errors because this is copied into loaddefs.el.
599 (define-mail-user-agent 'message-user-agent
600 'message-mail 'message-send-and-exit
601 'message-kill-buffer 'message-send-hook)
604 (defvar message-mh-deletable-headers '(Message-ID Date Lines Sender)
605 "If non-nil, delete the deletable headers before feeding to mh.")
607 (defvar message-send-method-alist
608 '((news message-news-p message-send-via-news)
609 (mail message-mail-p message-send-via-mail))
610 "Alist of ways to send outgoing messages.
611 Each element has the form
613 \(TYPE PREDICATE FUNCTION)
615 where TYPE is a symbol that names the method; PREDICATE is a function
616 called without any parameters to determine whether the message is
617 a message of type TYPE; and FUNCTION is a function to be called if
618 PREDICATE returns non-nil. FUNCTION is called with one parameter --
621 (defvar message-mail-alias-type 'abbrev
622 "*What alias expansion type to use in Message buffers.
623 The default is `abbrev', which uses mailabbrev. nil switches
626 ;;; Internal variables.
627 ;;; Well, not really internal.
629 (defvar message-mode-syntax-table
630 (let ((table (copy-syntax-table text-mode-syntax-table)))
631 (modify-syntax-entry ?% ". " table)
633 "Syntax table used while in Message mode.")
635 (defvar message-mode-abbrev-table text-mode-abbrev-table
636 "Abbrev table used in Message mode buffers.
637 Defaults to `text-mode-abbrev-table'.")
638 (defgroup message-headers nil
640 :link '(custom-manual "(message)Variables")
643 (defface message-header-to-face
646 (:foreground "green2" :bold t))
649 (:foreground "MidnightBlue" :bold t))
651 (:bold t :italic t)))
652 "Face used for displaying From headers."
653 :group 'message-faces)
655 (defface message-header-cc-face
658 (:foreground "green4" :bold t))
661 (:foreground "MidnightBlue"))
664 "Face used for displaying Cc headers."
665 :group 'message-faces)
667 (defface message-header-subject-face
670 (:foreground "green3"))
673 (:foreground "navy blue" :bold t))
676 "Face used for displaying subject headers."
677 :group 'message-faces)
679 (defface message-header-newsgroups-face
682 (:foreground "yellow" :bold t :italic t))
685 (:foreground "blue4" :bold t :italic t))
687 (:bold t :italic t)))
688 "Face used for displaying newsgroups headers."
689 :group 'message-faces)
691 (defface message-header-other-face
694 (:foreground "#b00000"))
697 (:foreground "steel blue"))
699 (:bold t :italic t)))
700 "Face used for displaying newsgroups headers."
701 :group 'message-faces)
703 (defface message-header-name-face
706 (:foreground "DarkGreen"))
709 (:foreground "cornflower blue"))
712 "Face used for displaying header names."
713 :group 'message-faces)
715 (defface message-header-xheader-face
718 (:foreground "blue"))
721 (:foreground "blue"))
724 "Face used for displaying X-Header headers."
725 :group 'message-faces)
727 (defface message-separator-face
730 (:foreground "blue3"))
733 (:foreground "brown"))
736 "Face used for displaying the separator."
737 :group 'message-faces)
739 (defface message-cited-text-face
748 "Face used for displaying cited text names."
749 :group 'message-faces)
751 (defvar message-font-lock-keywords
752 (let* ((cite-prefix "A-Za-z")
753 (cite-suffix (concat cite-prefix "0-9_.@-"))
754 (content "[ \t]*\\(.+\\(\n[ \t].*\\)*\\)"))
755 `((,(concat "^\\([Tt]o:\\)" content)
756 (1 'message-header-name-face)
757 (2 'message-header-to-face nil t))
758 (,(concat "^\\(^[GBF]?[Cc][Cc]:\\|^[Rr]eply-[Tt]o:\\)" content)
759 (1 'message-header-name-face)
760 (2 'message-header-cc-face nil t))
761 (,(concat "^\\([Ss]ubject:\\)" content)
762 (1 'message-header-name-face)
763 (2 'message-header-subject-face nil t))
764 (,(concat "^\\([Nn]ewsgroups:\\|Followup-[Tt]o:\\)" content)
765 (1 'message-header-name-face)
766 (2 'message-header-newsgroups-face nil t))
767 (,(concat "^\\([A-Z][^: \n\t]+:\\)" content)
768 (1 'message-header-name-face)
769 (2 'message-header-other-face nil t))
770 (,(concat "^\\(X-[A-Za-z0-9-]+\\|In-Reply-To\\):" content)
771 (1 'message-header-name-face)
772 (2 'message-header-name-face))
773 (,(concat "^\\(" (regexp-quote mail-header-separator) "\\)$")
774 1 'message-separator-face)
776 "\\([" cite-prefix "]+[" cite-suffix "]*\\)?"
778 (0 'message-cited-text-face))))
779 "Additional expressions to highlight in Message mode.")
781 (defvar message-face-alist
782 '((bold . bold-region)
783 (underline . underline-region)
784 (default . (lambda (b e)
786 (ununderline-region b e))))
787 "Alist of mail and news faces for facemenu.
788 The cdr of ech entry is a function for applying the face to a region.")
790 (defcustom message-send-hook nil
791 "Hook run before sending messages."
792 :group 'message-various
793 :options '(ispell-message)
796 (defcustom message-send-mail-hook nil
797 "Hook run before sending mail messages."
798 :group 'message-various
801 (defcustom message-send-news-hook nil
802 "Hook run before sending news messages."
803 :group 'message-various
806 (defcustom message-sent-hook nil
807 "Hook run after sending messages."
808 :group 'message-various
811 ;;; Internal variables.
813 (defvar message-buffer-list nil)
814 (defvar message-this-is-news nil)
815 (defvar message-this-is-mail nil)
816 (defvar message-draft-article nil)
818 ;; Byte-compiler warning
819 (defvar gnus-active-hashtb)
820 (defvar gnus-read-active-file)
822 ;;; Regexp matching the delimiter of messages in UNIX mail format
823 ;;; (UNIX From lines), minus the initial ^. It should be a copy
824 ;;; of rmail.el's rmail-unix-mail-delimiter.
825 (defvar message-unix-mail-delimiter
826 (let ((time-zone-regexp
827 (concat "\\([A-Z]?[A-Z]?[A-Z][A-Z]\\( DST\\)?"
828 "\\|[-+]?[0-9][0-9][0-9][0-9]"
834 ;; Many things can happen to an RFC 822 mailbox before it is put into
835 ;; a `From' line. The leading phrase can be stripped, e.g.
836 ;; `Joe <@w.x:joe@y.z>' -> `<@w.x:joe@y.z>'. The <> can be stripped, e.g.
837 ;; `<@x.y:joe@y.z>' -> `@x.y:joe@y.z'. Everything starting with a CRLF
838 ;; can be removed, e.g.
839 ;; From: joe@y.z (Joe K
841 ;; can yield `From joe@y.z (Joe K Fri Mar 22 08:11:15 1996', and
844 ;; can yield `From Joe User Fri Mar 22 08:11:15 1996'.
845 ;; The mailbox can be removed or be replaced by white space, e.g.
846 ;; From: "Joe User"{space}{tab}
848 ;; can yield `From {space}{tab} Fri Mar 22 08:11:15 1996',
849 ;; where {space} and {tab} represent the Ascii space and tab characters.
850 ;; We want to match the results of any of these manglings.
851 ;; The following regexp rejects names whose first characters are
852 ;; obviously bogus, but after that anything goes.
853 "\\([^\0-\b\n-\r\^?].*\\)? "
855 ;; The time the message was sent.
856 "\\([^\0-\r \^?]+\\) +" ; day of the week
857 "\\([^\0-\r \^?]+\\) +" ; month
858 "\\([0-3]?[0-9]\\) +" ; day of month
859 "\\([0-2][0-9]:[0-5][0-9]\\(:[0-6][0-9]\\)?\\) *" ; time of day
861 ;; Perhaps a time zone, specified by an abbreviation, or by a
866 " \\([0-9][0-9]+\\) *"
868 ;; On some systems the time zone can appear after the year, too.
872 "\\(remote from .*\\)?"
875 "Regexp matching the delimiter of messages in UNIX mail format.")
877 (defvar message-unsent-separator
878 (concat "^ *---+ +Unsent message follows +---+ *$\\|"
879 "^ *---+ +Returned message +---+ *$\\|"
880 "^Start of returned message$\\|"
881 "^ *---+ +Original message +---+ *$\\|"
882 "^ *--+ +begin message +--+ *$\\|"
883 "^ *---+ +Original message follows +---+ *$\\|"
884 "^|? *---+ +Message text follows: +---+ *|?$")
885 "A regexp that matches the separator before the text of a failed message.")
887 (defvar message-header-format-alist
889 (To . message-fill-address)
890 (Cc . message-fill-address)
904 "Alist used for formatting headers.")
907 (autoload 'message-setup-toolbar "messagexmas")
908 (autoload 'mh-new-draft-name "mh-comp")
909 (autoload 'mh-send-letter "mh-comp")
910 (autoload 'gnus-point-at-eol "gnus-util")
911 (autoload 'gnus-point-at-bol "gnus-util")
912 (autoload 'gnus-output-to-mail "gnus-util")
913 (autoload 'gnus-output-to-rmail "gnus-util")
914 (autoload 'mail-abbrev-in-expansion-header-p "mailabbrev")
915 (autoload 'nndraft-request-associate-buffer "nndraft")
916 (autoload 'nndraft-request-expire-articles "nndraft"))
921 ;;; Utility functions.
924 (defmacro message-y-or-n-p (question show &rest text)
925 "Ask QUESTION, displaying the rest of the arguments in a temp. buffer if SHOW"
926 `(message-talkative-question 'y-or-n-p ,question ,show ,@text))
928 ;; Delete the current line (and the next N lines.);
929 (defmacro message-delete-line (&optional n)
930 `(delete-region (progn (beginning-of-line) (point))
931 (progn (forward-line ,(or n 1)) (point))))
933 (defun message-tokenize-header (header &optional separator)
934 "Split HEADER into a list of header elements.
935 \",\" is used as the separator."
938 (let ((regexp (format "[%s]+" (or separator ",")))
943 (message-set-work-buffer)
945 (goto-char (point-min))
950 (cond ((and (> (point) beg)
952 (and (looking-at regexp)
955 (push (buffer-substring beg (point)) elems)
956 (setq beg (match-end 0)))
957 ((= (following-char) ?\")
958 (setq quoted (not quoted)))
959 ((and (= (following-char) ?\()
962 ((and (= (following-char) ?\))
967 (defun message-mail-file-mbox-p (file)
968 "Say whether FILE looks like a Unix mbox file."
969 (when (and (file-exists-p file)
970 (file-readable-p file)
971 (file-regular-p file))
972 (nnheader-temp-write nil
973 (nnheader-insert-file-contents file)
974 (goto-char (point-min))
975 (looking-at message-unix-mail-delimiter))))
977 (defun message-fetch-field (header &optional not-all)
978 "The same as `mail-fetch-field', only remove all newlines."
979 (let ((value (mail-fetch-field header nil (not not-all))))
981 (nnheader-replace-chars-in-string value ?\n ? ))))
983 (defun message-add-header (&rest headers)
984 "Add the HEADERS to the message header, skipping those already present."
987 (unless (string-match "^\\([^:]+\\):[ \t]*[^ \t]" (car headers))
988 (error "Invalid header `%s'" (car headers)))
989 (setq hclean (match-string 1 (car headers)))
991 (message-narrow-to-headers)
992 (unless (re-search-forward (concat "^" (regexp-quote hclean) ":") nil t)
993 (insert (car headers) ?\n))))
994 (setq headers (cdr headers))))
996 (defun message-fetch-reply-field (header)
997 "Fetch FIELD from the message we're replying to."
998 (when (and message-reply-buffer
999 (buffer-name message-reply-buffer))
1001 (set-buffer message-reply-buffer)
1002 (message-fetch-field header))))
1004 (defun message-set-work-buffer ()
1005 (if (get-buffer " *message work*")
1007 (set-buffer " *message work*")
1009 (set-buffer (get-buffer-create " *message work*"))
1010 (kill-all-local-variables)
1011 (buffer-disable-undo (current-buffer))))
1013 (defun message-functionp (form)
1014 "Return non-nil if FORM is funcallable."
1015 (or (and (symbolp form) (fboundp form))
1016 (and (listp form) (eq (car form) 'lambda))
1017 (byte-code-function-p form)))
1019 (defun message-strip-subject-re (subject)
1020 "Remove \"Re:\" from subject lines."
1021 (if (string-match "^[Rr][Ee]: *" subject)
1022 (substring subject (match-end 0))
1025 (defun message-remove-header (header &optional is-regexp first reverse)
1026 "Remove HEADER in the narrowed buffer.
1027 If REGEXP, HEADER is a regular expression.
1028 If FIRST, only remove the first instance of the header.
1029 Return the number of headers removed."
1030 (goto-char (point-min))
1031 (let ((regexp (if is-regexp header (concat "^" header ":")))
1033 (case-fold-search t)
1035 (while (and (not (eobp))
1038 (not (looking-at regexp))
1039 (looking-at regexp))
1046 ;; There might be a continuation header, so we have to search
1047 ;; until we find a new non-continuation line.
1050 (if (re-search-forward "^[^ \t]" nil t)
1051 (goto-char (match-beginning 0))
1054 (if (re-search-forward "^[^ \t]" nil t)
1055 (goto-char (match-beginning 0))
1059 (defun message-narrow-to-headers ()
1060 "Narrow the buffer to the head of the message."
1063 (goto-char (point-min))
1064 (if (re-search-forward
1065 (concat "^" (regexp-quote mail-header-separator) "\n") nil t)
1068 (goto-char (point-min)))
1070 (defun message-narrow-to-head ()
1071 "Narrow the buffer to the head of the message."
1074 (goto-char (point-min))
1075 (if (search-forward "\n\n" nil 1)
1078 (goto-char (point-min)))
1080 (defun message-news-p ()
1081 "Say whether the current buffer contains a news message."
1082 (or message-this-is-news
1085 (message-narrow-to-headers)
1086 (and (message-fetch-field "newsgroups")
1087 (not (message-fetch-field "posted-to")))))))
1089 (defun message-mail-p ()
1090 "Say whether the current buffer contains a mail message."
1091 (or message-this-is-mail
1094 (message-narrow-to-headers)
1095 (or (message-fetch-field "to")
1096 (message-fetch-field "cc")
1097 (message-fetch-field "bcc"))))))
1099 (defun message-next-header ()
1100 "Go to the beginning of the next header."
1102 (or (eobp) (forward-char 1))
1103 (not (if (re-search-forward "^[^ \t]" nil t)
1105 (goto-char (point-max)))))
1107 (defun message-sort-headers-1 ()
1108 "Sort the buffer as headers using `message-rank' text props."
1109 (goto-char (point-min))
1111 nil 'message-next-header
1113 (message-next-header)
1117 (or (get-text-property (point) 'message-rank)
1120 (defun message-sort-headers ()
1121 "Sort the headers of the current message according to `message-header-format-alist'."
1125 (let ((max (1+ (length message-header-format-alist)))
1127 (message-narrow-to-headers)
1128 (while (re-search-forward "^[^ \n]+:" nil t)
1130 (match-beginning 0) (1+ (match-beginning 0))
1132 (if (setq rank (length (memq (assq (intern (buffer-substring
1134 (1- (match-end 0))))
1135 message-header-format-alist)
1136 message-header-format-alist)))
1139 (message-sort-headers-1))))
1149 (defvar message-mode-map nil)
1151 (unless message-mode-map
1152 (setq message-mode-map (copy-keymap text-mode-map))
1153 (define-key message-mode-map "\C-c?" 'describe-mode)
1155 (define-key message-mode-map "\C-c\C-f\C-t" 'message-goto-to)
1156 (define-key message-mode-map "\C-c\C-f\C-b" 'message-goto-bcc)
1157 (define-key message-mode-map "\C-c\C-f\C-w" 'message-goto-fcc)
1158 (define-key message-mode-map "\C-c\C-f\C-c" 'message-goto-cc)
1159 (define-key message-mode-map "\C-c\C-f\C-s" 'message-goto-subject)
1160 (define-key message-mode-map "\C-c\C-f\C-r" 'message-goto-reply-to)
1161 (define-key message-mode-map "\C-c\C-f\C-n" 'message-goto-newsgroups)
1162 (define-key message-mode-map "\C-c\C-f\C-d" 'message-goto-distribution)
1163 (define-key message-mode-map "\C-c\C-f\C-f" 'message-goto-followup-to)
1164 (define-key message-mode-map "\C-c\C-f\C-k" 'message-goto-keywords)
1165 (define-key message-mode-map "\C-c\C-f\C-u" 'message-goto-summary)
1166 (define-key message-mode-map "\C-c\C-b" 'message-goto-body)
1167 (define-key message-mode-map "\C-c\C-i" 'message-goto-signature)
1169 (define-key message-mode-map "\C-c\C-t" 'message-insert-to)
1170 (define-key message-mode-map "\C-c\C-n" 'message-insert-newsgroups)
1172 (define-key message-mode-map "\C-c\C-y" 'message-yank-original)
1173 (define-key message-mode-map "\C-c\C-q" 'message-fill-yanked-message)
1174 (define-key message-mode-map "\C-c\C-w" 'message-insert-signature)
1175 (define-key message-mode-map "\C-c\C-r" 'message-caesar-buffer-body)
1176 (define-key message-mode-map "\C-c\C-o" 'message-sort-headers)
1177 (define-key message-mode-map "\C-c\M-r" 'message-rename-buffer)
1179 (define-key message-mode-map "\C-c\C-c" 'message-send-and-exit)
1180 (define-key message-mode-map "\C-c\C-s" 'message-send)
1181 (define-key message-mode-map "\C-c\C-k" 'message-kill-buffer)
1182 (define-key message-mode-map "\C-c\C-d" 'message-dont-send)
1184 (define-key message-mode-map "\C-c\C-e" 'message-elide-region)
1185 (define-key message-mode-map "\C-c\C-v" 'message-delete-not-region)
1186 (define-key message-mode-map "\M-\r" 'message-newline-and-reformat)
1188 (define-key message-mode-map "\t" 'message-tab))
1191 message-mode-menu message-mode-map "Message Menu."
1193 ["Sort Headers" message-sort-headers t]
1194 ["Yank Original" message-yank-original t]
1195 ["Fill Yanked Message" message-fill-yanked-message t]
1196 ["Insert Signature" message-insert-signature t]
1197 ["Caesar (rot13) Message" message-caesar-buffer-body t]
1198 ["Caesar (rot13) Region" message-caesar-region (mark t)]
1199 ["Elide Region" message-elide-region (mark t)]
1200 ["Delete Outside Region" message-delete-not-region (mark t)]
1201 ["Newline and Reformat" message-newline-and-reformat t]
1202 ["Rename buffer" message-rename-buffer t]
1203 ["Spellcheck" ispell-message t]
1205 ["Send Message" message-send-and-exit t]
1206 ["Abort Message" message-dont-send t]))
1209 message-mode-field-menu message-mode-map ""
1211 ["Fetch To" message-insert-to t]
1212 ["Fetch Newsgroups" message-insert-newsgroups t]
1214 ["To" message-goto-to t]
1215 ["Subject" message-goto-subject t]
1216 ["Cc" message-goto-cc t]
1217 ["Reply-To" message-goto-reply-to t]
1218 ["Summary" message-goto-summary t]
1219 ["Keywords" message-goto-keywords t]
1220 ["Newsgroups" message-goto-newsgroups t]
1221 ["Followup-To" message-goto-followup-to t]
1222 ["Distribution" message-goto-distribution t]
1223 ["Body" message-goto-body t]
1224 ["Signature" message-goto-signature t]))
1226 (defvar facemenu-add-face-function)
1227 (defvar facemenu-remove-face-function)
1230 (defun message-mode ()
1231 "Major mode for editing mail and news to be sent.
1232 Like Text Mode but with these additional commands:
1233 C-c C-s message-send (send the message) C-c C-c message-send-and-exit
1234 C-c C-f move to a header field (and create it if there isn't):
1235 C-c C-f C-t move to To C-c C-f C-s move to Subject
1236 C-c C-f C-c move to Cc C-c C-f C-b move to Bcc
1237 C-c C-f C-w move to Fcc C-c C-f C-r move to Reply-To
1238 C-c C-f C-u move to Summary C-c C-f C-n move to Newsgroups
1239 C-c C-f C-k move to Keywords C-c C-f C-d move to Distribution
1240 C-c C-f C-f move to Followup-To
1241 C-c C-t message-insert-to (add a To header to a news followup)
1242 C-c C-n message-insert-newsgroups (add a Newsgroup header to a news reply)
1243 C-c C-b message-goto-body (move to beginning of message text).
1244 C-c C-i message-goto-signature (move to the beginning of the signature).
1245 C-c C-w message-insert-signature (insert `message-signature-file' file).
1246 C-c C-y message-yank-original (insert current message, if any).
1247 C-c C-q message-fill-yanked-message (fill what was yanked).
1248 C-c C-e message-elide-region (elide the text between point and mark).
1249 C-c C-r message-caesar-buffer-body (rot13 the message body)."
1251 (kill-all-local-variables)
1252 (make-local-variable 'message-reply-buffer)
1253 (setq message-reply-buffer nil)
1254 (make-local-variable 'message-send-actions)
1255 (make-local-variable 'message-exit-actions)
1256 (make-local-variable 'message-kill-actions)
1257 (make-local-variable 'message-postpone-actions)
1258 (make-local-variable 'message-draft-article)
1259 (make-local-hook 'kill-buffer-hook)
1260 (set-syntax-table message-mode-syntax-table)
1261 (use-local-map message-mode-map)
1262 (setq local-abbrev-table message-mode-abbrev-table)
1263 (setq major-mode 'message-mode)
1264 (setq mode-name "Message")
1265 (setq buffer-offer-save t)
1266 (make-local-variable 'font-lock-defaults)
1267 (setq font-lock-defaults '(message-font-lock-keywords t))
1268 (make-local-variable 'facemenu-add-face-function)
1269 (make-local-variable 'facemenu-remove-face-function)
1270 (setq facemenu-add-face-function
1272 (let ((face-fun (cdr (assq face message-face-alist))))
1274 (funcall face-fun (point) end)
1275 (error "Face %s not configured for %s mode" face mode-name)))
1277 facemenu-remove-face-function t)
1278 (make-local-variable 'paragraph-separate)
1279 (make-local-variable 'paragraph-start)
1280 (setq paragraph-start
1281 (concat (regexp-quote mail-header-separator)
1282 "$\\|[ \t]*[-_][-_][-_]+$\\|"
1284 ;;!!! Uhm... shurely this can't be right.
1285 "[> " (regexp-quote message-yank-prefix) "]+$\\|"
1287 (setq paragraph-separate
1288 (concat (regexp-quote mail-header-separator)
1289 "$\\|[ \t]*[-_][-_][-_]+$\\|"
1291 "[> " (regexp-quote message-yank-prefix) "]+$\\|"
1292 paragraph-separate))
1293 (make-local-variable 'message-reply-headers)
1294 (setq message-reply-headers nil)
1295 (make-local-variable 'message-newsreader)
1296 (make-local-variable 'message-mailer)
1297 (make-local-variable 'message-post-method)
1298 (make-local-variable 'message-sent-message-via)
1299 (setq message-sent-message-via nil)
1300 (make-local-variable 'message-checksum)
1301 (setq message-checksum nil)
1302 ;;(when (fboundp 'mail-hist-define-keys)
1303 ;; (mail-hist-define-keys))
1304 (when (string-match "XEmacs\\|Lucid" emacs-version)
1305 (message-setup-toolbar))
1306 (easy-menu-add message-mode-menu message-mode-map)
1307 (easy-menu-add message-mode-field-menu message-mode-map)
1308 ;; Allow mail alias things.
1309 (when (eq message-mail-alias-type 'abbrev)
1310 (if (fboundp 'mail-abbrevs-setup)
1311 (mail-abbrevs-setup)
1312 (funcall (intern "mail-aliases-setup"))))
1313 (message-set-auto-save-file-name)
1314 (run-hooks 'text-mode-hook 'message-mode-hook))
1319 ;;; Message mode commands
1322 ;;; Movement commands
1324 (defun message-goto-to ()
1325 "Move point to the To header."
1327 (message-position-on-field "To"))
1329 (defun message-goto-subject ()
1330 "Move point to the Subject header."
1332 (message-position-on-field "Subject"))
1334 (defun message-goto-cc ()
1335 "Move point to the Cc header."
1337 (message-position-on-field "Cc" "To"))
1339 (defun message-goto-bcc ()
1340 "Move point to the Bcc header."
1342 (message-position-on-field "Bcc" "Cc" "To"))
1344 (defun message-goto-fcc ()
1345 "Move point to the Fcc header."
1347 (message-position-on-field "Fcc" "To" "Newsgroups"))
1349 (defun message-goto-reply-to ()
1350 "Move point to the Reply-To header."
1352 (message-position-on-field "Reply-To" "Subject"))
1354 (defun message-goto-newsgroups ()
1355 "Move point to the Newsgroups header."
1357 (message-position-on-field "Newsgroups"))
1359 (defun message-goto-distribution ()
1360 "Move point to the Distribution header."
1362 (message-position-on-field "Distribution"))
1364 (defun message-goto-followup-to ()
1365 "Move point to the Followup-To header."
1367 (message-position-on-field "Followup-To" "Newsgroups"))
1369 (defun message-goto-keywords ()
1370 "Move point to the Keywords header."
1372 (message-position-on-field "Keywords" "Subject"))
1374 (defun message-goto-summary ()
1375 "Move point to the Summary header."
1377 (message-position-on-field "Summary" "Subject"))
1379 (defun message-goto-body ()
1380 "Move point to the beginning of the message body."
1382 (if (looking-at "[ \t]*\n") (expand-abbrev))
1383 (goto-char (point-min))
1384 (search-forward (concat "\n" mail-header-separator "\n") nil t))
1386 (defun message-goto-signature ()
1387 "Move point to the beginning of the message signature."
1389 (goto-char (point-min))
1390 (if (re-search-forward message-signature-separator nil t)
1392 (goto-char (point-max))))
1396 (defun message-insert-to (&optional force)
1397 "Insert a To header that points to the author of the article being replied to.
1398 If the original author requested not to be sent mail, the function signals
1400 With the prefix argument FORCE, insert the header anyway."
1402 (let ((co (message-fetch-reply-field "mail-copies-to")))
1403 (when (and (null force)
1405 (equal (downcase co) "never"))
1406 (error "The user has requested not to have copies sent via mail")))
1407 (when (and (message-position-on-field "To")
1408 (mail-fetch-field "to")
1409 (not (string-match "\\` *\\'" (mail-fetch-field "to"))))
1411 (insert (or (message-fetch-reply-field "reply-to")
1412 (message-fetch-reply-field "from") "")))
1414 (defun message-insert-newsgroups ()
1415 "Insert the Newsgroups header from the article being replied to."
1417 (when (and (message-position-on-field "Newsgroups")
1418 (mail-fetch-field "newsgroups")
1419 (not (string-match "\\` *\\'" (mail-fetch-field "newsgroups"))))
1421 (insert (or (message-fetch-reply-field "newsgroups") "")))
1425 ;;; Various commands
1427 (defun message-delete-not-region (beg end)
1428 "Delete everything in the body of the current message that is outside of the region."
1432 (delete-region (point) (progn (message-goto-signature)
1437 (delete-region beg (progn (message-goto-body)
1440 (message-goto-signature)
1443 (defun message-newline-and-reformat ()
1444 "Insert four newlines, and then reformat if inside quoted text."
1446 (let ((point (point))
1450 (setq quoted (looking-at (regexp-quote message-yank-prefix))))
1453 (insert message-yank-prefix))
1454 (fill-paragraph nil)
1458 (defun message-insert-signature (&optional force)
1459 "Insert a signature. See documentation for the `message-signature' variable."
1460 (interactive (list 0))
1463 ((and (null message-signature)
1466 (goto-char (point-max))
1467 (not (re-search-backward
1468 message-signature-separator nil t))))
1469 ((and (null message-signature)
1472 ((message-functionp message-signature)
1473 (funcall message-signature))
1474 ((listp message-signature)
1475 (eval message-signature))
1476 (t message-signature)))
1478 (cond ((stringp signature)
1480 ((and (eq t signature)
1481 message-signature-file
1482 (file-exists-p message-signature-file))
1485 (goto-char (point-max))
1486 ;; Insert the signature.
1490 (if (eq signature t)
1491 (insert-file-contents message-signature-file)
1493 (goto-char (point-max))
1494 (or (bolp) (insert "\n")))))
1496 (defun message-elide-region (b e)
1497 "Elide the text between point and mark. An ellipsis (from
1498 message-elide-elipsis) will be inserted where the text was killed."
1503 (insert message-elide-elipsis))
1505 (defvar message-caesar-translation-table nil)
1507 (defun message-caesar-region (b e &optional n)
1508 "Caesar rotation of region by N, default 13, for decrypting netnews."
1511 (min (point) (or (mark t) (point)))
1512 (max (point) (or (mark t) (point)))
1513 (when current-prefix-arg
1514 (prefix-numeric-value current-prefix-arg))))
1516 (setq n (if (numberp n) (mod n 26) 13)) ;canonize N
1517 (unless (or (zerop n) ; no action needed for a rot of 0
1518 (= b e)) ; no region to rotate
1519 ;; We build the table, if necessary.
1520 (when (or (not message-caesar-translation-table)
1521 (/= (aref message-caesar-translation-table ?a) (+ ?a n)))
1522 (setq message-caesar-translation-table
1523 (message-make-caesar-translation-table n)))
1524 ;; Then we translate the region. Do it this way to retain
1527 (subst-char-in-region
1528 b (1+ b) (char-after b)
1529 (aref message-caesar-translation-table (char-after b)))
1532 (defun message-make-caesar-translation-table (n)
1533 "Create a rot table with offset N."
1535 (table (make-string 256 0)))
1536 (while (< (incf i) 256)
1539 (substring table 0 ?A)
1540 (substring table (+ ?A n) (+ ?A n (- 26 n)))
1541 (substring table ?A (+ ?A n))
1542 (substring table (+ ?A 26) ?a)
1543 (substring table (+ ?a n) (+ ?a n (- 26 n)))
1544 (substring table ?a (+ ?a n))
1545 (substring table (+ ?a 26) 255))))
1547 (defun message-caesar-buffer-body (&optional rotnum)
1548 "Caesar rotates all letters in the current buffer by 13 places.
1549 Used to encode/decode possiblyun offensive messages (commonly in net.jokes).
1550 With prefix arg, specifies the number of places to rotate each letter forward.
1551 Mail and USENET news headers are not rotated."
1552 (interactive (if current-prefix-arg
1553 (list (prefix-numeric-value current-prefix-arg))
1557 (when (message-goto-body)
1558 (narrow-to-region (point) (point-max)))
1559 (message-caesar-region (point-min) (point-max) rotnum))))
1561 (defun message-pipe-buffer-body (program)
1562 "Pipe the message body in the current buffer through PROGRAM."
1565 (when (message-goto-body)
1566 (narrow-to-region (point) (point-max)))
1567 (let ((body (buffer-substring (point-min) (point-max))))
1568 (unless (equal 0 (call-process-region
1569 (point-min) (point-max) program t t))
1571 (message "%s failed." program))))))
1573 (defun message-rename-buffer (&optional enter-string)
1574 "Rename the *message* buffer to \"*message* RECIPIENT\".
1575 If the function is run with a prefix, it will ask for a new buffer
1576 name, rather than giving an automatic name."
1577 (interactive "Pbuffer name: ")
1580 (goto-char (point-min))
1581 (narrow-to-region (point)
1582 (search-forward mail-header-separator nil 'end))
1584 (if (message-news-p) (message-fetch-field "Newsgroups")
1585 (message-fetch-field "To"))
1588 (if (string-match "," mail-to)
1589 (concat (substring mail-to 0 (match-beginning 0)) ", ...")
1591 (name-default (concat "*message* " mail-trimmed-to))
1592 (name (if enter-string
1593 (read-string "New buffer name: " name-default)
1596 (file-name-as-directory message-autosave-directory)))
1597 (rename-buffer name t)))))
1599 (defun message-fill-yanked-message (&optional justifyp)
1600 "Fill the paragraphs of a message yanked into this one.
1601 Numeric argument means justify as well."
1604 (goto-char (point-min))
1605 (search-forward (concat "\n" mail-header-separator "\n") nil t)
1606 (let ((fill-prefix message-yank-prefix))
1607 (fill-individual-paragraphs (point) (point-max) justifyp t))))
1609 (defun message-indent-citation ()
1610 "Modify text just inserted from a message to be cited.
1611 The inserted text should be the region.
1612 When this function returns, the region is again around the modified text.
1614 Normally, indent each nonblank line `message-indentation-spaces' spaces.
1615 However, if `message-yank-prefix' is non-nil, insert that prefix on each line."
1616 (let ((start (point)))
1617 ;; Remove unwanted headers.
1618 (when message-ignored-cited-headers
1623 (if (search-forward "\n\n" nil t)
1626 (message-remove-header message-ignored-cited-headers t)
1627 (when (= (point-min) (point-max))
1628 (setq all-removed t))
1629 (goto-char (point-max)))
1633 ;; Delete blank lines at the start of the buffer.
1634 (while (and (point-min)
1637 (message-delete-line))
1638 ;; Delete blank lines at the end of the buffer.
1639 (goto-char (point-max))
1642 (while (and (zerop (forward-line -1))
1644 (message-delete-line))
1645 ;; Do the indentation.
1646 (if (null message-yank-prefix)
1647 (indent-rigidly start (mark t) message-indentation-spaces)
1650 (while (< (point) (mark t))
1651 (insert message-yank-prefix)
1655 (defun message-yank-original (&optional arg)
1656 "Insert the message being replied to, if any.
1657 Puts point before the text and mark after.
1658 Normally indents each nonblank line ARG spaces (default 3). However,
1659 if `message-yank-prefix' is non-nil, insert that prefix on each line.
1661 This function uses `message-cite-function' to do the actual citing.
1663 Just \\[universal-argument] as argument means don't indent, insert no
1664 prefix, and don't delete any headers."
1666 (let ((modified (buffer-modified-p)))
1667 (when (and message-reply-buffer
1668 message-cite-function)
1669 (delete-windows-on message-reply-buffer t)
1670 (insert-buffer message-reply-buffer)
1671 (funcall message-cite-function)
1672 (message-exchange-point-and-mark)
1676 (setq message-checksum (cons (message-checksum) (buffer-size)))))))
1678 (defun message-cite-original ()
1679 "Cite function in the standard Message manner."
1680 (let ((start (point))
1682 (when message-indent-citation-function
1683 (if (listp message-indent-citation-function)
1684 message-indent-citation-function
1685 (list message-indent-citation-function)))))
1688 (funcall (pop functions)))
1689 (when message-citation-line-function
1692 (funcall message-citation-line-function))))
1694 (defun message-insert-citation-line ()
1695 "Function that inserts a simple citation line."
1696 (when message-reply-headers
1697 (insert (mail-header-from message-reply-headers) " writes:\n\n")))
1699 (defun message-position-on-field (header &rest afters)
1700 (let ((case-fold-search t))
1703 (goto-char (point-min))
1706 (concat "^" (regexp-quote mail-header-separator) "$"))
1707 (match-beginning 0)))
1708 (goto-char (point-min))
1709 (if (re-search-forward (concat "^" (regexp-quote header) ":") nil t)
1711 (re-search-forward "^[^ \t]" nil 'move)
1713 (skip-chars-backward "\n")
1716 (not (re-search-forward
1717 (concat "^" (regexp-quote (car afters)) ":")
1721 (re-search-forward "^[^ \t]" nil 'move)
1722 (beginning-of-line))
1723 (insert header ": \n")
1727 (defun message-remove-signature ()
1728 "Remove the signature from the text between point and mark.
1729 The text will also be indented the normal way."
1731 (let ((start (point))
1733 (if (not (re-search-forward message-signature-separator (mark t) t))
1734 ;; No signature here, so we just indent the cited text.
1735 (message-indent-citation)
1736 ;; Find the last non-empty line.
1738 (while (looking-at "[ \t]*$")
1741 (setq mark (set-marker (make-marker) (point)))
1743 (message-indent-citation)
1744 ;; Enable undoing the deletion.
1746 (delete-region mark (mark t))
1747 (set-marker mark nil)))))
1752 ;;; Sending messages
1755 (defun message-send-and-exit (&optional arg)
1756 "Send message like `message-send', then, if no errors, exit from mail buffer."
1758 (let ((buf (current-buffer))
1759 (actions message-exit-actions))
1760 (when (and (message-send arg)
1762 (if message-kill-buffer-on-exit
1765 (when (eq buf (current-buffer))
1766 (message-bury buf)))
1767 (message-do-actions actions))))
1769 (defun message-dont-send ()
1770 "Don't send the message you have been editing."
1772 (let ((actions message-postpone-actions))
1773 (message-bury (current-buffer))
1774 (message-do-actions actions)))
1776 (defun message-kill-buffer ()
1777 "Kill the current buffer."
1779 (when (or (not (buffer-modified-p))
1780 (yes-or-no-p "Message modified; kill anyway? "))
1781 (let ((actions message-kill-actions))
1782 (setq buffer-file-name nil)
1783 (kill-buffer (current-buffer))
1784 (message-do-actions actions))))
1786 (defun message-bury (buffer)
1787 "Bury this mail buffer."
1788 (let ((newbuf (other-buffer buffer)))
1789 (bury-buffer buffer)
1790 (if (and (fboundp 'frame-parameters)
1791 (cdr (assq 'dedicated (frame-parameters)))
1792 (not (null (delq (selected-frame) (visible-frame-list)))))
1793 (delete-frame (selected-frame))
1794 (switch-to-buffer newbuf))))
1796 (defun message-send (&optional arg)
1797 "Send the message in the current buffer.
1798 If `message-interactive' is non-nil, wait for success indication
1799 or error messages, and inform user.
1800 Otherwise any failure is reported in a message back to
1801 the user from the mailer."
1804 (when (if (and buffer-file-name
1806 (y-or-n-p (format "Send buffer contents as %s message? "
1807 (if (message-mail-p)
1808 (if (message-news-p) "mail and news" "mail")
1810 (or (buffer-modified-p)
1811 (message-check-element 'unchanged)
1812 (y-or-n-p "No changes in the buffer; really send? ")))
1813 ;; Make it possible to undo the coming changes.
1815 (let ((inhibit-read-only t))
1816 (put-text-property (point-min) (point-max) 'read-only nil))
1817 (message-fix-before-sending)
1818 (run-hooks 'message-send-hook)
1819 (message "Sending...")
1820 (let ((alist message-send-method-alist)
1824 (setq elem (pop alist)))
1825 (when (and (or (not (funcall (cadr elem)))
1826 (and (or (not (memq (car elem)
1827 message-sent-message-via))
1830 "Already sent message via %s; resend? "
1832 (setq success (funcall (caddr elem) arg)))))
1834 (when (and success sent)
1836 ;;(when (fboundp 'mail-hist-put-headers-into-history)
1837 ;; (mail-hist-put-headers-into-history))
1838 (run-hooks 'message-sent-hook)
1839 (message "Sending...done")
1840 ;; Mark the buffer as unmodified and delete autosave.
1841 (set-buffer-modified-p nil)
1842 (delete-auto-save-file-if-necessary t)
1843 (message-disassociate-draft)
1844 ;; Delete other mail buffers and stuff.
1845 (message-do-send-housekeeping)
1846 (message-do-actions message-send-actions)
1850 (defun message-send-via-mail (arg)
1851 "Send the current message via mail."
1852 (message-send-mail arg))
1854 (defun message-send-via-news (arg)
1855 "Send the current message via news."
1856 (message-send-news arg))
1858 (defun message-fix-before-sending ()
1859 "Do various things to make the message nice before sending it."
1860 ;; Make sure there's a newline at the end of the message.
1861 (goto-char (point-max))
1865 (defun message-add-action (action &rest types)
1866 "Add ACTION to be performed when doing an exit of type TYPES."
1869 (set (setq var (intern (format "message-%s-actions" (pop types))))
1870 (nconc (symbol-value var) (list action))))))
1872 (defun message-do-actions (actions)
1873 "Perform all actions in ACTIONS."
1874 ;; Now perform actions on successful sending.
1878 ;; A simple function.
1879 ((message-functionp (car actions))
1880 (funcall (car actions)))
1881 ;; Something to be evaled.
1883 (eval (car actions)))))
1886 (defun message-send-mail (&optional arg)
1887 (require 'mail-utils)
1888 (let ((tembuf (message-generate-new-buffer-clone-locals " message temp"))
1889 (case-fold-search nil)
1890 (news (message-news-p))
1891 (message-buffer (current-buffer)))
1893 (message-narrow-to-headers)
1894 ;; Insert some headers.
1895 (let ((message-deletable-headers
1896 (if news nil message-deletable-headers)))
1897 (message-generate-headers message-required-mail-headers))
1898 ;; Let the user do all of the above.
1899 (run-hooks 'message-header-hook))
1904 ;; Avoid copying text props.
1906 ;; "%s" (save-excursion
1907 ;; (set-buffer message-buffer)
1908 ;; (buffer-string))))
1909 ;; 1997-09-29 by MORIOKA Tomohiko
1910 ;; Don't avoid text properties.
1911 (insert-buffer message-buffer)
1912 ;; Remove some headers.
1914 (message-narrow-to-headers)
1915 ;; Remove some headers.
1916 (message-remove-header message-ignored-mail-headers t))
1917 (goto-char (point-max))
1918 ;; require one newline at the end.
1919 (or (= (preceding-char) ?\n)
1922 (or (message-fetch-field "cc")
1923 (message-fetch-field "to")))
1924 (message-insert-courtesy-copy))
1925 ;; 1997-09-29 by MORIOKA Tomohiko
1926 (run-hooks 'message-encode-mail-hook)
1927 (funcall message-send-mail-function))
1928 (kill-buffer tembuf))
1929 (set-buffer message-buffer)
1930 (push 'mail message-sent-message-via)))
1932 (defun message-send-mail-with-sendmail ()
1933 "Send off the prepared buffer with sendmail."
1934 (let ((errbuf (if message-interactive
1935 (generate-new-buffer " sendmail errors")
1937 resend-to-addresses delimline)
1938 (let ((case-fold-search t))
1940 (message-narrow-to-headers)
1941 (setq resend-to-addresses (message-fetch-field "resent-to")))
1942 ;; Change header-delimiter to be what sendmail expects.
1943 (goto-char (point-min))
1945 (concat "^" (regexp-quote mail-header-separator) "\n"))
1946 (replace-match "\n")
1948 (setq delimline (point-marker))
1949 (run-hooks 'message-send-mail-hook)
1950 ;; Insert an extra newline if we need it to work around
1951 ;; Sun's bug that swallows newlines.
1952 (goto-char (1+ delimline))
1953 (when (eval message-mailer-swallows-blank-line)
1955 (when message-interactive
1959 (let ((default-directory "/"))
1960 (apply 'call-process-region
1961 (append (list (point-min) (point-max)
1962 (if (boundp 'sendmail-program)
1964 "/usr/lib/sendmail")
1965 nil errbuf nil "-oi")
1966 ;; Always specify who from,
1967 ;; since some systems have broken sendmails.
1968 ;; But some systems are more broken with -f, so
1969 ;; we'll let users override this.
1970 (if (null message-sendmail-f-is-evil)
1971 (list "-f" (user-login-name)))
1972 ;; These mean "report errors by mail"
1973 ;; and "deliver in background".
1974 (if (null message-interactive) '("-oem" "-odb"))
1975 ;; Get the addresses from the message
1976 ;; unless this is a resend.
1977 ;; We must not do that for a resend
1978 ;; because we would find the original addresses.
1979 ;; For a resend, include the specific addresses.
1980 (if resend-to-addresses
1981 (list resend-to-addresses)
1983 (when message-interactive
1986 (goto-char (point-min))
1987 (while (re-search-forward "\n\n* *" nil t)
1988 (replace-match "; "))
1989 (if (not (zerop (buffer-size)))
1990 (error "Sending...failed to %s"
1991 (buffer-substring (point-min) (point-max)))))
1992 (when (bufferp errbuf)
1993 (kill-buffer errbuf)))))
1995 (defun message-send-mail-with-qmail ()
1996 "Pass the prepared message buffer to qmail-inject.
1997 Refer to the documentation for the variable `message-send-mail-function'
1998 to find out how to use this."
1999 ;; replace the header delimiter with a blank line
2000 (goto-char (point-min))
2002 (concat "^" (regexp-quote mail-header-separator) "\n"))
2003 (replace-match "\n")
2004 (run-hooks 'message-send-mail-hook)
2008 'call-process-region 1 (point-max) message-qmail-inject-program
2010 ;; qmail-inject's default behaviour is to look for addresses on the
2011 ;; command line; if there're none, it scans the headers.
2012 ;; yes, it does The Right Thing w.r.t. Resent-To and it's kin.
2014 ;; in general, ALL of qmail-inject's defaults are perfect for simply
2015 ;; reading a formatted (i. e., at least a To: or Resent-To header)
2016 ;; message from stdin.
2018 ;; qmail also has the advantage of not having been raped by
2019 ;; various vendors, so we don't have to allow for that, either --
2020 ;; compare this with message-send-mail-with-sendmail and weep
2021 ;; for sendmail's lost innocence.
2023 ;; all this is way cool coz it lets us keep the arguments entirely
2024 ;; free for -inject-arguments -- a big win for the user and for us
2025 ;; since we don't have to play that double-guessing game and the user
2026 ;; gets full control (no gestapo'ish -f's, for instance). --sj
2027 message-qmail-inject-args)
2028 ;; qmail-inject doesn't say anything on it's stdout/stderr,
2029 ;; we have to look at the retval instead
2031 (1 (error "qmail-inject reported permanent failure"))
2032 (111 (error "qmail-inject reported transient failure"))
2033 ;; should never happen
2034 (t (error "qmail-inject reported unknown failure"))))
2036 (defun message-send-mail-with-mh ()
2037 "Send the prepared message buffer with mh."
2038 (let ((mh-previous-window-config nil)
2039 (name (mh-new-draft-name)))
2040 (setq buffer-file-name name)
2041 ;; MH wants to generate these headers itself.
2042 (when message-mh-deletable-headers
2043 (let ((headers message-mh-deletable-headers))
2045 (goto-char (point-min))
2046 (and (re-search-forward
2047 (concat "^" (symbol-name (car headers)) ": *") nil t)
2048 (message-delete-line))
2050 (run-hooks 'message-send-mail-hook)
2051 ;; Pass it on to mh.
2054 (defun message-send-news (&optional arg)
2055 (let ((tembuf (message-generate-new-buffer-clone-locals " *message temp*"))
2056 (case-fold-search nil)
2057 (method (if (message-functionp message-post-method)
2058 (funcall message-post-method arg)
2059 message-post-method))
2060 (message-buffer (current-buffer))
2061 (message-syntax-checks
2063 (cons '(existing-newsgroups . disabled)
2064 message-syntax-checks)
2065 message-syntax-checks))
2068 (message-narrow-to-headers)
2069 ;; Insert some headers.
2070 (message-generate-headers message-required-news-headers)
2071 ;; Let the user do all of the above.
2072 (run-hooks 'message-header-hook))
2073 (message-cleanup-headers)
2074 (if (not (message-check-news-syntax))
2076 ;;(message "Posting not performed")
2081 (buffer-disable-undo (current-buffer))
2083 ;; Avoid copying text props.
2085 ;; "%s" (save-excursion
2086 ;; (set-buffer message-buffer)
2087 ;; (buffer-string))))
2088 ;; 1997-09-29 by MORIOKA Tomohiko
2089 ;; Don't avoid text properties.
2090 (insert-buffer message-buffer)
2091 ;; Remove some headers.
2093 (message-narrow-to-headers)
2094 ;; Remove some headers.
2095 (message-remove-header message-ignored-news-headers t))
2096 (goto-char (point-max))
2097 ;; require one newline at the end.
2098 (or (= (preceding-char) ?\n)
2100 ;; 1997-09-29 by MORIOKA Tomohiko
2101 (run-hooks 'message-encode-news-hook)
2102 (setq result (funcall message-send-news-function method)))
2103 (kill-buffer tembuf))
2104 (set-buffer message-buffer)
2106 (push 'news message-sent-message-via)
2107 (message "Couldn't send message via news: %s"
2108 (nnheader-get-report (car method)))
2111 ;; 1997-09-29 by MORIOKA Tomohiko
2112 (defun message-send-news-with-gnus (method)
2113 (let ((case-fold-search t))
2114 ;; Remove the delimiter.
2115 (goto-char (point-min))
2117 (concat "^" (regexp-quote mail-header-separator) "\n"))
2118 (replace-match "\n")
2120 (run-hooks 'message-send-news-hook)
2121 ;;(require (car method))
2122 ;;(funcall (intern (format "%s-open-server" (car method)))
2123 ;;(cadr method) (cddr method))
2125 ;; (funcall (intern (format "%s-request-post" (car method)))
2127 (gnus-open-server method)
2128 (gnus-request-post method)
2132 ;;; Header generation & syntax checking.
2135 (defmacro message-check (type &rest forms)
2136 "Eval FORMS if TYPE is to be checked."
2137 `(or (message-check-element ,type)
2141 (put 'message-check 'lisp-indent-function 1)
2142 (put 'message-check 'edebug-form-spec '(form body))
2144 (defun message-check-element (type)
2145 "Returns non-nil if this type is not to be checked."
2146 (if (eq message-syntax-checks 'dont-check-for-anything-just-trust-me)
2148 (let ((able (assq type message-syntax-checks)))
2150 (eq (cdr able) 'disabled)))))
2152 (defun message-check-news-syntax ()
2153 "Check the syntax of the message."
2158 ;; We narrow to the headers and check them first.
2161 (message-narrow-to-headers)
2162 (message-check-news-header-syntax)))
2164 (message-check-news-body-syntax)))))
2166 (defun message-check-news-header-syntax ()
2168 ;; Check the Subject header.
2169 (message-check 'subject
2170 (let* ((case-fold-search t)
2171 (subject (message-fetch-field "subject")))
2174 (not (string-match "\\`[ \t]*\\'" subject)))
2177 "The subject field is empty or missing. Posting is denied.")))))
2178 ;; Check for commands in Subject.
2179 (message-check 'subject-cmsg
2180 (if (string-match "^cmsg " (message-fetch-field "subject"))
2182 "The control code \"cmsg\" is in the subject. Really post? ")
2184 ;; Check for multiple identical headers.
2185 (message-check 'multiple-headers
2187 (while (and (not found)
2188 (re-search-forward "^[^ \t:]+: " nil t))
2190 (or (re-search-forward
2195 (match-beginning 0) (- (match-end 0) 2))))
2200 (y-or-n-p (format "Multiple %s headers. Really post? " found))
2202 ;; Check for Version and Sendsys.
2203 (message-check 'sendsys
2204 (if (re-search-forward "^Sendsys:\\|^Version:" nil t)
2206 (format "The article contains a %s command. Really post? "
2207 (buffer-substring (match-beginning 0)
2208 (1- (match-end 0)))))
2210 ;; See whether we can shorten Followup-To.
2211 (message-check 'shorten-followup-to
2212 (let ((newsgroups (message-fetch-field "newsgroups"))
2213 (followup-to (message-fetch-field "followup-to"))
2215 (when (and newsgroups
2216 (string-match "," newsgroups)
2221 (setq to (completing-read
2222 "Followups to: (default all groups) "
2223 (mapcar (lambda (g) (list g))
2225 (message-tokenize-header
2227 (goto-char (point-min))
2228 (insert "Followup-To: " to "\n"))
2230 ;; Check "Shoot me".
2231 (message-check 'shoot
2232 (if (re-search-forward
2233 "Message-ID.*.i-did-not-set--mail-host-address--so-shoot-me" nil t)
2234 (y-or-n-p "You appear to have a misconfigured system. Really post? ")
2236 ;; Check for Approved.
2237 (message-check 'approved
2238 (if (re-search-forward "^Approved:" nil t)
2239 (y-or-n-p "The article contains an Approved header. Really post? ")
2241 ;; Check the Message-ID header.
2242 (message-check 'message-id
2243 (let* ((case-fold-search t)
2244 (message-id (message-fetch-field "message-id" t)))
2245 (or (not message-id)
2246 (and (string-match "@" message-id)
2247 (string-match "@[^\\.]*\\." message-id))
2249 (format "The Message-ID looks strange: \"%s\". Really post? "
2251 ;; Check the Newsgroups & Followup-To headers.
2252 (message-check 'existing-newsgroups
2253 (let* ((case-fold-search t)
2254 (newsgroups (message-fetch-field "newsgroups"))
2255 (followup-to (message-fetch-field "followup-to"))
2256 (groups (message-tokenize-header
2258 (concat newsgroups "," followup-to)
2260 (hashtb (and (boundp 'gnus-active-hashtb)
2261 gnus-active-hashtb))
2263 (if (or (not hashtb)
2264 (not (boundp 'gnus-read-active-file))
2265 (not gnus-read-active-file)
2266 (eq gnus-read-active-file 'some))
2269 (when (and (not (boundp (intern (car groups) hashtb)))
2270 (not (equal (car groups) "poster")))
2271 (push (car groups) errors))
2277 "Really post to %s unknown group%s: %s "
2278 (if (= (length errors) 1) "this" "these")
2279 (if (= (length errors) 1) "" "s")
2280 (mapconcat 'identity errors ", ")))))))
2281 ;; Check the Newsgroups & Followup-To headers for syntax errors.
2282 (message-check 'valid-newsgroups
2283 (let ((case-fold-search t)
2284 (headers '("Newsgroups" "Followup-To"))
2286 (while (and headers (not error))
2287 (when (setq header (mail-fetch-field (car headers)))
2291 "\\`\\([-+_&.a-zA-Z0-9]+\\)?\\(,[-+_&.a-zA-Z0-9]+\\)*\\'"
2296 (not (string-match "\\.\\'\\|\\.\\." g)))
2297 (message-tokenize-header header ","))))
2304 (format "The %s header looks odd: \"%s\". Really post? "
2305 (car headers) header)))))
2306 (message-check 'repeated-newsgroups
2307 (let ((case-fold-search t)
2308 (headers '("Newsgroups" "Followup-To"))
2309 header error groups group)
2312 (when (setq header (mail-fetch-field (pop headers)))
2313 (setq groups (message-tokenize-header header ","))
2314 (while (setq group (pop groups))
2315 (when (member group groups)
2321 (format "Group %s is repeated in headers. Really post? " error)))))
2322 ;; Check the From header.
2323 (message-check 'from
2324 (let* ((case-fold-search t)
2325 (from (message-fetch-field "from"))
2326 (ad (nth 1 (mail-extract-address-components from))))
2329 (message "There is no From line. Posting is denied.")
2331 ((or (not (string-match "@[^\\.]*\\." ad)) ;larsi@ifi
2332 (string-match "\\.\\." ad) ;larsi@ifi..uio
2333 (string-match "@\\." ad) ;larsi@.ifi.uio
2334 (string-match "\\.$" ad) ;larsi@ifi.uio.
2335 (not (string-match "^[^@]+@[^@]+$" ad)) ;larsi.ifi.uio
2336 (string-match "(.*).*(.*)" from)) ;(lars) (lars)
2338 "Denied posting -- the From looks strange: \"%s\"." from)
2342 (defconst message-max-size 60000)
2344 (defun message-check-news-body-syntax ()
2346 ;; Check for long lines.
2347 (message-check 'long-lines
2348 (goto-char (point-min))
2350 (concat "^" (regexp-quote mail-header-separator) "$"))
2354 (< (current-column) 80))
2355 (zerop (forward-line 1))))
2359 "You have lines longer than 79 characters. Really post? ")))
2360 ;; Check whether the article is empty.
2361 (message-check 'empty
2362 (goto-char (point-min))
2364 (concat "^" (regexp-quote mail-header-separator) "$"))
2367 (goto-char (point-max))
2368 (re-search-backward message-signature-separator nil t)
2370 (or (re-search-backward "[^ \n\t]" b t)
2371 (y-or-n-p "Empty article. Really post? "))))
2372 ;; Check for control characters.
2373 (message-check 'control-chars
2374 (if (re-search-forward "[\000-\007\013\015-\037\200-\237]" nil t)
2376 "The article contains control characters. Really post? ")
2378 ;; Check excessive size.
2379 (message-check 'size
2380 (if (> (buffer-size) 60000)
2382 (format "The article is %d octets long. Really post? "
2385 ;; Check whether any new text has been added.
2386 (message-check 'new-text
2388 (not message-checksum)
2389 (not (and (eq (message-checksum) (car message-checksum))
2390 (eq (buffer-size) (cdr message-checksum))))
2392 "It looks like no new text has been added. Really post? ")))
2393 ;; Check the length of the signature.
2394 (message-check 'signature
2395 (goto-char (point-max))
2396 (if (or (not (re-search-backward message-signature-separator nil t))
2397 (search-forward message-forward-end-separator nil t))
2399 (if (> (count-lines (point) (point-max)) 5)
2402 "Your .sig is %d lines; it should be max 4. Really post? "
2403 (1- (count-lines (point) (point-max)))))
2406 (defun message-checksum ()
2407 "Return a \"checksum\" for the current buffer."
2410 (goto-char (point-min))
2412 (concat "^" (regexp-quote mail-header-separator) "$"))
2414 (when (not (looking-at "[ \t\n]"))
2415 (setq sum (logxor (ash sum 1) (if (natnump sum) 0 1)
2420 (defun message-do-fcc ()
2421 "Process Fcc headers in the current buffer."
2422 (let ((case-fold-search t)
2423 (buf (current-buffer))
2424 (coding-system-for-write 'raw-text)
2427 (set-buffer (get-buffer-create " *message temp*"))
2428 (buffer-disable-undo (current-buffer))
2430 (insert-buffer-substring buf)
2432 (message-narrow-to-headers)
2433 (while (setq file (message-fetch-field "fcc"))
2435 (message-remove-header "fcc" nil t)))
2436 (run-hooks 'message-before-do-fcc-hook)
2437 (goto-char (point-min))
2438 (re-search-forward (concat "^" (regexp-quote mail-header-separator) "$"))
2439 (replace-match "" t t)
2440 ;; Process FCC operations.
2442 (setq file (pop list))
2443 (if (string-match "^[ \t]*|[ \t]*\\(.*\\)[ \t]*$" file)
2444 ;; Pipe the article to the program in question.
2445 (call-process-region (point-min) (point-max) shell-file-name
2446 nil nil nil shell-command-switch
2447 (match-string 1 file))
2448 ;; Save the article.
2449 (setq file (expand-file-name file))
2450 (unless (file-exists-p (file-name-directory file))
2451 (make-directory (file-name-directory file) t))
2452 (if (and message-fcc-handler-function
2453 (not (eq message-fcc-handler-function 'rmail-output)))
2454 (funcall message-fcc-handler-function file)
2455 (if (and (file-readable-p file) (mail-file-babyl-p file))
2456 (rmail-output file 1 nil t)
2457 (let ((mail-use-rfc822 t))
2458 (rmail-output file 1 t t))))))
2460 (kill-buffer (current-buffer)))))
2462 (defun message-output (filename)
2463 "Append this article to Unix/babyl mail file.."
2464 (if (and (file-readable-p filename)
2465 (mail-file-babyl-p filename))
2466 (gnus-output-to-rmail filename t)
2467 (gnus-output-to-mail filename t)))
2469 (defun message-cleanup-headers ()
2470 "Do various automatic cleanups of the headers."
2471 ;; Remove empty lines in the header.
2473 (message-narrow-to-headers)
2474 ;; Remove blank lines.
2475 (while (re-search-forward "^[ \t]*\n" nil t)
2476 (replace-match "" t t))
2478 ;; Correct Newsgroups and Followup-To headers: Change sequence of
2479 ;; spaces to comma and eliminate spaces around commas. Eliminate
2480 ;; embedded line breaks.
2481 (goto-char (point-min))
2482 (while (re-search-forward "^\\(Newsgroups\\|Followup-To\\): +" nil t)
2486 (if (re-search-forward "^[^ \t]" nil t)
2490 (goto-char (point-min))
2491 (while (re-search-forward "\n[ \t]+" nil t)
2492 (replace-match " " t t)) ;No line breaks (too confusing)
2493 (goto-char (point-min))
2494 (while (re-search-forward "[ \t\n]*,[ \t\n]*\\|[ \t]+" nil t)
2495 (replace-match "," t t))
2496 (goto-char (point-min))
2497 ;; Remove trailing commas.
2498 (when (re-search-forward ",+$" nil t)
2499 (replace-match "" t t))))))
2501 (defun message-make-date ()
2502 "Make a valid data header."
2503 (let ((now (current-time)))
2504 (timezone-make-date-arpa-standard
2505 (current-time-string now) (current-time-zone now))))
2507 (defun message-make-message-id ()
2508 "Make a unique Message-ID."
2509 (concat "<" (message-unique-id)
2510 (let ((psubject (save-excursion (message-fetch-field "subject")))
2512 (save-excursion (message-fetch-field "supersedes"))))
2514 (and message-reply-headers
2515 (mail-header-references message-reply-headers)
2516 (mail-header-subject message-reply-headers)
2518 (mail-header-subject message-reply-headers)
2520 (message-strip-subject-re
2521 (mail-header-subject message-reply-headers))
2522 (message-strip-subject-re psubject))))
2524 (string-match "_-_@" psupersedes)))
2526 "@" (message-make-fqdn) ">"))
2528 (defvar message-unique-id-char nil)
2530 ;; If you ever change this function, make sure the new version
2531 ;; cannot generate IDs that the old version could.
2532 ;; You might for example insert a "." somewhere (not next to another dot
2533 ;; or string boundary), or modify the "fsf" string.
2534 (defun message-unique-id ()
2535 ;; Don't use microseconds from (current-time), they may be unsupported.
2536 ;; Instead we use this randomly inited counter.
2537 (setq message-unique-id-char
2538 (% (1+ (or message-unique-id-char (logand (random t) (1- (lsh 1 20)))))
2539 ;; (current-time) returns 16-bit ints,
2540 ;; and 2^16*25 just fits into 4 digits i base 36.
2542 (let ((tm (current-time)))
2544 (if (memq system-type '(ms-dos emx vax-vms))
2545 (let ((user (downcase (user-login-name))))
2546 (while (string-match "[^a-z0-9_]" user)
2547 (aset user (match-beginning 0) ?_))
2549 (message-number-base36 (user-uid) -1))
2550 (message-number-base36 (+ (car tm)
2551 (lsh (% message-unique-id-char 25) 16)) 4)
2552 (message-number-base36 (+ (nth 1 tm)
2553 (lsh (/ message-unique-id-char 25) 16)) 4)
2554 ;; Append the newsreader name, because while the generated
2555 ;; ID is unique to this newsreader, other newsreaders might
2556 ;; otherwise generate the same ID via another algorithm.
2559 (defun message-number-base36 (num len)
2564 (concat (message-number-base36 (/ num 36) (1- len))
2565 (char-to-string (aref "zyxwvutsrqponmlkjihgfedcba9876543210"
2568 (defun message-make-organization ()
2569 "Make an Organization header."
2570 (let* ((organization
2571 (when message-user-organization
2572 (if (message-functionp message-user-organization)
2573 (funcall message-user-organization)
2574 message-user-organization))))
2576 (message-set-work-buffer)
2577 (cond ((stringp organization)
2578 (insert organization))
2579 ((and (eq t organization)
2580 message-user-organization-file
2581 (file-exists-p message-user-organization-file))
2582 (insert-file-contents message-user-organization-file)))
2583 (goto-char (point-min))
2584 (while (re-search-forward "[\t\n]+" nil t)
2585 (replace-match "" t t))
2586 (unless (zerop (buffer-size))
2589 (defun message-make-lines ()
2590 "Count the number of lines and return numeric string."
2594 (goto-char (point-min))
2596 (concat "^" (regexp-quote mail-header-separator) "$"))
2598 (int-to-string (count-lines (point) (point-max))))))
2600 (defun message-make-in-reply-to ()
2601 "Return the In-Reply-To header for this message."
2602 (when message-reply-headers
2603 (let ((from (mail-header-from message-reply-headers))
2604 (date (mail-header-date message-reply-headers)))
2607 (string-match " *at \\| *@ \\| *(\\| *<" from)))
2608 (concat (if stop-pos (substring from 0 stop-pos) from)
2610 (if (or (not date) (string= date ""))
2611 "(unknown date)" date)
2614 (defun message-make-distribution ()
2615 "Make a Distribution header."
2616 (let ((orig-distribution (message-fetch-reply-field "distribution")))
2617 (cond ((message-functionp message-distribution-function)
2618 (funcall message-distribution-function))
2619 (t orig-distribution))))
2621 (defun message-make-expires ()
2622 "Return an Expires header based on `message-expires'."
2623 (let ((current (current-time))
2624 (future (* 1.0 message-expires 60 60 24)))
2625 ;; Add the future to current.
2626 (setcar current (+ (car current) (round (/ future (expt 2 16)))))
2627 (setcar (cdr current) (+ (nth 1 current) (% (round future) (expt 2 16))))
2628 ;; Return the date in the future in UT.
2629 (timezone-make-date-arpa-standard
2630 (current-time-string current) (current-time-zone current) '(0 "UT"))))
2632 (defun message-make-path ()
2634 (let ((login-name (user-login-name)))
2635 (cond ((null message-user-path)
2636 (concat (system-name) "!" login-name))
2637 ((stringp message-user-path)
2638 ;; Support GENERICPATH. Suggested by vixie@decwrl.dec.com.
2639 (concat message-user-path "!" login-name))
2642 (defun message-make-from ()
2643 "Make a From header."
2644 (let* ((style message-from-style)
2645 (login (message-make-address))
2647 (or (and (boundp 'user-full-name)
2650 (when (string= fullname "&")
2651 (setq fullname (user-login-name)))
2653 (message-set-work-buffer)
2656 (equal fullname ""))
2658 ((or (eq style 'angles)
2659 (and (not (eq style 'parens))
2660 ;; Use angles if no quoting is needed, or if parens would
2661 ;; need quoting too.
2662 (or (not (string-match "[^- !#-'*+/-9=?A-Z^-~]" fullname))
2663 (let ((tmp (concat fullname nil)))
2664 (while (string-match "([^()]*)" tmp)
2665 (aset tmp (match-beginning 0) ?-)
2666 (aset tmp (1- (match-end 0)) ?-))
2667 (string-match "[\\()]" tmp)))))
2669 (goto-char (point-min))
2670 ;; Look for a character that cannot appear unquoted
2671 ;; according to RFC 822.
2672 (when (re-search-forward "[^- !#-'*+/-9=?A-Z^-~]" nil 1)
2673 ;; Quote fullname, escaping specials.
2674 (goto-char (point-min))
2676 (while (re-search-forward "[\"\\]" nil 1)
2677 (replace-match "\\\\\\&" t))
2679 (insert " <" login ">"))
2680 (t ; 'parens or default
2682 (let ((fullname-start (point)))
2684 (goto-char fullname-start)
2685 ;; RFC 822 says \ and nonmatching parentheses
2686 ;; must be escaped in comments.
2687 ;; Escape every instance of ()\ ...
2688 (while (re-search-forward "[()\\]" nil 1)
2689 (replace-match "\\\\\\&" t))
2690 ;; ... then undo escaping of matching parentheses,
2691 ;; including matching nested parentheses.
2692 (goto-char fullname-start)
2693 (while (re-search-forward
2694 "\\(\\=\\|[^\\]\\(\\\\\\\\\\)*\\)\\\\(\\(\\([^\\]\\|\\\\\\\\\\)*\\)\\\\)"
2696 (replace-match "\\1(\\3)" t)
2697 (goto-char fullname-start)))
2701 (defun message-make-sender ()
2702 "Return the \"real\" user address.
2703 This function tries to ignore all user modifications, and
2704 give as trustworthy answer as possible."
2705 (concat (user-login-name) "@" (system-name)))
2707 (defun message-make-address ()
2708 "Make the address of the user."
2709 (or (message-user-mail-address)
2710 (concat (user-login-name) "@" (message-make-domain))))
2712 (defun message-user-mail-address ()
2713 "Return the pertinent part of `user-mail-address'."
2714 (when user-mail-address
2715 (if (string-match " " user-mail-address)
2716 (nth 1 (mail-extract-address-components user-mail-address))
2717 user-mail-address)))
2719 (defun message-make-fqdn ()
2720 "Return user's fully qualified domain name."
2721 (let ((system-name (system-name))
2722 (user-mail (message-user-mail-address)))
2724 ((string-match "[^.]\\.[^.]" system-name)
2725 ;; `system-name' returned the right result.
2727 ;; Try `mail-host-address'.
2728 ((and (boundp 'mail-host-address)
2729 (stringp mail-host-address)
2730 (string-match "\\." mail-host-address))
2732 ;; We try `user-mail-address' as a backup.
2734 (string-match "\\." user-mail)
2735 (string-match "@\\(.*\\)\\'" user-mail))
2736 (match-string 1 user-mail))
2737 ;; Default to this bogus thing.
2739 (concat system-name ".i-did-not-set--mail-host-address--so-shoot-me")))))
2741 (defun message-make-host-name ()
2742 "Return the name of the host."
2743 (let ((fqdn (message-make-fqdn)))
2744 (string-match "^[^.]+\\." fqdn)
2745 (substring fqdn 0 (1- (match-end 0)))))
2747 (defun message-make-domain ()
2748 "Return the domain name."
2749 (or mail-host-address
2750 (message-make-fqdn)))
2752 (defun message-generate-headers (headers)
2753 "Prepare article HEADERS.
2754 Headers already prepared in the buffer are not modified."
2756 (message-narrow-to-headers)
2757 (let* ((Date (message-make-date))
2758 (Message-ID (message-make-message-id))
2759 (Organization (message-make-organization))
2760 (From (message-make-from))
2761 (Path (message-make-path))
2764 (In-Reply-To (message-make-in-reply-to))
2766 (Distribution (message-make-distribution))
2767 (Lines (message-make-lines))
2768 (X-Newsreader message-newsreader)
2769 (X-Mailer (and (not (message-fetch-field "X-Newsreader"))
2771 (Expires (message-make-expires))
2772 (case-fold-search t)
2774 ;; First we remove any old generated headers.
2775 (let ((headers message-deletable-headers))
2776 (unless (buffer-modified-p)
2777 (setq headers (delq 'Message-ID (copy-sequence headers))))
2779 (goto-char (point-min))
2780 (and (re-search-forward
2781 (concat "^" (symbol-name (car headers)) ": *") nil t)
2782 (get-text-property (1+ (match-beginning 0)) 'message-deletable)
2783 (message-delete-line))
2785 ;; Go through all the required headers and see if they are in the
2786 ;; articles already. If they are not, or are empty, they are
2787 ;; inserted automatically - except for Subject, Newsgroups and
2790 (goto-char (point-min))
2791 (setq elem (pop headers))
2793 (if (eq (car elem) 'optional)
2794 (setq header (cdr elem))
2795 (setq header (car elem)))
2797 (when (or (not (re-search-forward
2798 (concat "^" (downcase (symbol-name header)) ":")
2801 ;; The header was found. We insert a space after the
2802 ;; colon, if there is none.
2803 (if (/= (following-char) ? ) (insert " ") (forward-char 1))
2804 ;; Find out whether the header is empty...
2805 (looking-at "[ \t]*$")))
2806 ;; So we find out what value we should insert.
2809 ((and (consp elem) (eq (car elem) 'optional))
2810 ;; This is an optional header. If the cdr of this
2811 ;; is something that is nil, then we do not insert
2813 (setq header (cdr elem))
2814 (or (and (fboundp (cdr elem)) (funcall (cdr elem)))
2815 (and (boundp (cdr elem)) (symbol-value (cdr elem)))))
2817 ;; The element is a cons. Either the cdr is a
2818 ;; string to be inserted verbatim, or it is a
2819 ;; function, and we insert the value returned from
2821 (or (and (stringp (cdr elem)) (cdr elem))
2822 (and (fboundp (cdr elem)) (funcall (cdr elem)))))
2823 ((and (boundp header) (symbol-value header))
2824 ;; The element is a symbol. We insert the value
2825 ;; of this symbol, if any.
2826 (symbol-value header))
2828 ;; We couldn't generate a value for this header,
2829 ;; so we just ask the user.
2830 (read-from-minibuffer
2831 (format "Empty header for %s; enter value: " header)))))
2832 ;; Finally insert the header.
2834 (not (equal value "")))
2838 ;; This header didn't exist, so we insert it.
2839 (goto-char (point-max))
2840 (insert (symbol-name header) ": " value "\n")
2842 ;; The value of this header was empty, so we clear
2843 ;; totally and insert the new value.
2844 (delete-region (point) (gnus-point-at-eol))
2846 ;; Add the deletable property to the headers that require it.
2847 (and (memq header message-deletable-headers)
2848 (progn (beginning-of-line) (looking-at "[^:]+: "))
2849 (add-text-properties
2850 (point) (match-end 0)
2851 '(message-deletable t face italic) (current-buffer)))))))
2852 ;; Insert new Sender if the From is strange.
2853 (let ((from (message-fetch-field "from"))
2854 (sender (message-fetch-field "sender"))
2855 (secure-sender (message-make-sender)))
2857 (not (message-check-element 'sender))
2860 (cadr (mail-extract-address-components from)))
2861 (downcase secure-sender)))
2866 (cadr (mail-extract-address-components sender)))
2867 (downcase secure-sender)))))
2868 (goto-char (point-min))
2869 ;; Rename any old Sender headers to Original-Sender.
2870 (when (re-search-forward "^\\(Original-\\)*Sender:" nil t)
2872 (insert "Original-")
2873 (beginning-of-line))
2874 (when (or (message-news-p)
2875 (string-match "^[^@]@.+\\..+" secure-sender))
2876 (insert "Sender: " secure-sender "\n")))))))
2878 (defun message-insert-courtesy-copy ()
2879 "Insert a courtesy message in mail copies of combined messages."
2883 (message-narrow-to-headers)
2884 (when (setq newsgroups (message-fetch-field "newsgroups"))
2885 (goto-char (point-max))
2886 (insert "Posted-To: " newsgroups "\n")))
2888 (when message-courtesy-message
2890 ((string-match "%s" message-courtesy-message)
2891 (insert (format message-courtesy-message newsgroups)))
2893 (insert message-courtesy-message)))))))
2896 ;;; Setting up a message buffer
2899 (defun message-fill-address (header value)
2901 (narrow-to-region (point) (point))
2902 (insert (capitalize (symbol-name header))
2904 (if (consp value) (car value) value)
2906 (narrow-to-region (point-min) (1- (point-max)))
2908 (goto-char (point-min))
2910 (skip-chars-forward "^,\"" (point-max))
2911 (if (or (= (following-char) ?,)
2914 (if (and (> (current-column) 78)
2920 (setq last (1+ (point))))
2921 (setq last (1+ (point)))))
2922 (setq quoted (not quoted)))
2925 (goto-char (point-max))
2929 (defun message-fill-header (header value)
2930 (let ((begin (point))
2933 (insert (capitalize (symbol-name header))
2935 (if (consp value) (car value) value)
2938 (narrow-to-region begin (point))
2939 (fill-region-as-paragraph begin (point))
2940 ;; Tapdance around looong Message-IDs.
2942 (when (looking-at "[ \t]*$")
2943 (message-delete-line))
2945 (re-search-forward ":" nil t)
2946 (when (looking-at "\n[ \t]+")
2947 (replace-match " " t t))
2948 (goto-char (point-max)))))
2950 (defun message-position-point ()
2951 "Move point to where the user probably wants to find it."
2952 (message-narrow-to-headers)
2954 ((re-search-forward "^[^:]+:[ \t]*$" nil t)
2955 (search-backward ":" )
2958 (if (= (following-char) ? )
2962 (goto-char (point-max))
2965 (unless (looking-at "$")
2969 (defun message-buffer-name (type &optional to group)
2970 "Return a new (unique) buffer name based on TYPE and TO."
2972 ;; Check whether `message-generate-new-buffers' is a function,
2973 ;; and if so, call it.
2974 ((message-functionp message-generate-new-buffers)
2975 (funcall message-generate-new-buffers type to group))
2976 ;; Generate a new buffer name The Message Way.
2977 (message-generate-new-buffers
2978 (generate-new-buffer-name
2982 (or (car (mail-extract-address-components to))
2985 (if (and group (not (string= group ""))) (concat " on " group) "")
2987 ;; Use standard name.
2989 (format "*%s message*" type))))
2991 (defun message-pop-to-buffer (name)
2992 "Pop to buffer NAME, and warn if it already exists and is modified."
2993 (let ((buffer (get-buffer name)))
2995 (buffer-name buffer))
2997 (set-buffer (pop-to-buffer buffer))
2998 (when (and (buffer-modified-p)
3000 "Message already being composed; erase? ")))
3001 (error "Message being composed")))
3002 (set-buffer (pop-to-buffer name))))
3006 (defun message-do-send-housekeeping ()
3007 "Kill old message buffers."
3008 ;; We might have sent this buffer already. Delete it from the
3010 (setq message-buffer-list (delq (current-buffer) message-buffer-list))
3011 (while (and message-max-buffers
3013 (>= (length message-buffer-list) message-max-buffers))
3014 ;; Kill the oldest buffer -- unless it has been changed.
3015 (let ((buffer (pop message-buffer-list)))
3016 (when (and (buffer-name buffer)
3017 (not (buffer-modified-p buffer)))
3018 (kill-buffer buffer))))
3019 ;; Rename the buffer.
3020 (if message-send-rename-function
3021 (funcall message-send-rename-function)
3022 (when (string-match "\\`\\*" (buffer-name))
3024 (concat "*sent " (substring (buffer-name) (match-end 0))) t)))
3025 ;; Push the current buffer onto the list.
3026 (when message-max-buffers
3027 (setq message-buffer-list
3028 (nconc message-buffer-list (list (current-buffer))))))
3030 (defvar mc-modes-alist)
3031 (defun message-setup (headers &optional replybuffer actions)
3032 (when (and (boundp 'mc-modes-alist)
3033 (not (assq 'message-mode mc-modes-alist)))
3034 (push '(message-mode (encrypt . mc-encrypt-message)
3035 (sign . mc-sign-message))
3038 (setq message-send-actions actions))
3039 (setq message-reply-buffer replybuffer)
3040 (goto-char (point-min))
3041 ;; Insert all the headers.
3044 (alist message-header-format-alist))
3046 (unless (assq (caar h) message-header-format-alist)
3047 (push (list (caar h)) alist))
3051 (delete-region (point) (progn (forward-line -1) (point)))
3052 (when message-default-headers
3053 (insert message-default-headers)
3054 (or (bolp) (insert ?\n)))
3058 (insert mail-header-separator "\n")
3062 (when (message-news-p)
3063 (when message-default-news-headers
3064 (insert message-default-news-headers)
3065 (or (bolp) (insert ?\n)))
3066 (when message-generate-headers-first
3067 (message-generate-headers
3070 (copy-sequence message-required-news-headers))))))
3071 (when (message-mail-p)
3072 (when message-default-mail-headers
3073 (insert message-default-mail-headers)
3074 (or (bolp) (insert ?\n)))
3075 (when message-generate-headers-first
3076 (message-generate-headers
3079 (copy-sequence message-required-mail-headers))))))
3080 (run-hooks 'message-signature-setup-hook)
3081 (message-insert-signature)
3083 (message-narrow-to-headers)
3084 (run-hooks 'message-header-setup-hook))
3085 (set-buffer-modified-p nil)
3086 (setq buffer-undo-list nil)
3087 (run-hooks 'message-setup-hook)
3088 (message-position-point)
3091 (defun message-set-auto-save-file-name ()
3092 "Associate the message buffer with a file in the drafts directory."
3093 (when message-autosave-directory
3094 (setq message-draft-article (nndraft-request-associate-buffer "drafts"))
3095 (clear-visited-file-modtime)))
3097 (defun message-disassociate-draft ()
3098 "Disassociate the message buffer from the drafts directory."
3099 (when message-draft-article
3100 (nndraft-request-expire-articles
3101 (list message-draft-article) "drafts" nil t)))
3106 ;;; Commands for interfacing with message
3110 (defun message-mail (&optional to subject
3111 other-headers continue switch-function
3112 yank-action send-actions)
3113 "Start editing a mail message to be sent."
3115 (let ((message-this-is-mail t))
3116 (message-pop-to-buffer (message-buffer-name "mail" to))
3119 `((To . ,(or to "")) (Subject . ,(or subject "")))
3120 (when other-headers other-headers)))))
3123 (defun message-news (&optional newsgroups subject)
3124 "Start editing a news article to be sent."
3126 (let ((message-this-is-news t))
3127 (message-pop-to-buffer (message-buffer-name "news" nil newsgroups))
3128 (message-setup `((Newsgroups . ,(or newsgroups ""))
3129 (Subject . ,(or subject ""))))))
3132 (defun message-reply (&optional to-address wide ignore-reply-to)
3133 "Start editing a reply to the article in the current buffer."
3135 (let ((cur (current-buffer))
3136 from subject date reply-to to cc
3137 references message-id follow-to
3138 (inhibit-point-motion-hooks t)
3139 mct never-mct gnus-warning)
3141 (message-narrow-to-head)
3142 ;; Allow customizations to have their say.
3144 ;; This is a regular reply.
3145 (if (message-functionp message-reply-to-function)
3146 (setq follow-to (funcall message-reply-to-function)))
3147 ;; This is a followup.
3148 (if (message-functionp message-wide-reply-to-function)
3151 (funcall message-wide-reply-to-function)))))
3152 ;; Find all relevant headers we need.
3153 (setq from (message-fetch-field "from")
3154 date (message-fetch-field "date")
3155 subject (or (message-fetch-field "subject") "none")
3156 to (message-fetch-field "to")
3157 cc (message-fetch-field "cc")
3158 mct (message-fetch-field "mail-copies-to")
3159 reply-to (unless ignore-reply-to (message-fetch-field "reply-to"))
3160 references (message-fetch-field "references")
3161 message-id (message-fetch-field "message-id" t))
3162 ;; Remove any (buggy) Re:'s that are present and make a
3164 (when (string-match "^[ \t]*[Rr][Ee]:[ \t]*" subject)
3165 (setq subject (substring subject (match-end 0))))
3166 (setq subject (concat "Re: " subject))
3168 (when (and (setq gnus-warning (message-fetch-field "gnus-warning"))
3169 (string-match "<[^>]+>" gnus-warning))
3170 (setq message-id (match-string 0 gnus-warning)))
3172 ;; Handle special values of Mail-Copies-To.
3174 (cond ((equal (downcase mct) "never")
3177 ((equal (downcase mct) "always")
3178 (setq mct (or reply-to from)))))
3184 (setq follow-to (list (cons 'To (or to-address reply-to from))))
3185 (when (and wide mct)
3186 (push (cons 'Cc mct) follow-to)))
3189 (message-set-work-buffer)
3191 (insert (or reply-to from "")))
3192 (insert (if to (concat (if (bolp) "" ", ") to "") ""))
3193 (insert (if mct (concat (if (bolp) "" ", ") mct) ""))
3194 (insert (if cc (concat (if (bolp) "" ", ") cc) ""))
3195 (goto-char (point-min))
3196 (while (re-search-forward "[ \t]+" nil t)
3197 (replace-match " " t t))
3198 ;; Remove addresses that match `rmail-dont-reply-to-names'.
3199 (insert (prog1 (rmail-dont-reply-to (buffer-string))
3201 (goto-char (point-min))
3202 ;; Perhaps Mail-Copies-To: never removed the only address?
3204 (insert (or reply-to from "")))
3208 (cons (mail-strip-quoted-names addr) addr))
3209 (message-tokenize-header (buffer-string))))
3212 (setq ccalist (delq (assoc (car (pop s)) s) ccalist)))))
3213 (setq follow-to (list (cons 'To (cdr (pop ccalist)))))
3215 (let ((ccs (cons 'Cc (mapconcat
3216 (lambda (addr) (cdr addr)) ccalist ", "))))
3217 (when (string-match "^ +" (cdr ccs))
3218 (setcdr ccs (substring (cdr ccs) (match-end 0))))
3219 (push ccs follow-to))))))
3222 (message-pop-to-buffer (message-buffer-name
3223 (if wide "wide reply" "reply") from
3224 (if wide to-address nil)))
3226 (setq message-reply-headers
3227 (vector 0 subject from date message-id references 0 0 ""))
3230 `((Subject . ,subject)
3232 ,@(if (or references message-id)
3233 `((References . ,(concat (or references "") (and references " ")
3234 (or message-id ""))))
3239 (defun message-wide-reply (&optional to-address ignore-reply-to)
3240 "Make a \"wide\" reply to the message in the current buffer."
3242 (message-reply to-address t ignore-reply-to))
3245 (defun message-followup (&optional to-newsgroups)
3246 "Follow up to the message in the current buffer.
3247 If TO-NEWSGROUPS, use that as the new Newsgroups line."
3249 (let ((cur (current-buffer))
3250 from subject date reply-to mct
3251 references message-id follow-to
3252 (inhibit-point-motion-hooks t)
3253 (message-this-is-news t)
3254 followup-to distribution newsgroups gnus-warning posted-to)
3257 (goto-char (point-min))
3258 (if (search-forward "\n\n" nil t)
3261 (when (message-functionp message-followup-to-function)
3263 (funcall message-followup-to-function)))
3264 (setq from (message-fetch-field "from")
3265 date (message-fetch-field "date")
3266 subject (or (message-fetch-field "subject") "none")
3267 references (message-fetch-field "references")
3268 message-id (message-fetch-field "message-id" t)
3269 followup-to (message-fetch-field "followup-to")
3270 newsgroups (message-fetch-field "newsgroups")
3271 posted-to (message-fetch-field "posted-to")
3272 reply-to (message-fetch-field "reply-to")
3273 distribution (message-fetch-field "distribution")
3274 mct (message-fetch-field "mail-copies-to"))
3275 (when (and (setq gnus-warning (message-fetch-field "gnus-warning"))
3276 (string-match "<[^>]+>" gnus-warning))
3277 (setq message-id (match-string 0 gnus-warning)))
3278 ;; Remove bogus distribution.
3279 (when (and (stringp distribution)
3280 (let ((case-fold-search t))
3281 (string-match "world" distribution)))
3282 (setq distribution nil))
3283 ;; Remove any (buggy) Re:'s that are present and make a
3285 (when (string-match "^[ \t]*[Rr][Ee]:[ \t]*" subject)
3286 (setq subject (substring subject (match-end 0))))
3287 (setq subject (concat "Re: " subject))
3290 (message-pop-to-buffer (message-buffer-name "followup" from newsgroups))
3293 `((Subject . ,subject)
3296 (list (cons 'Newsgroups to-newsgroups)))
3297 (follow-to follow-to)
3298 ((and followup-to message-use-followup-to)
3301 ((equal (downcase followup-to) "poster")
3302 (if (or (eq message-use-followup-to 'use)
3303 (message-y-or-n-p "Obey Followup-To: poster? " t "\
3304 You should normally obey the Followup-To: header.
3306 `Followup-To: poster' sends your response via e-mail instead of news.
3308 A typical situation where `Followup-To: poster' is used is when the poster
3309 does not read the newsgroup, so he wouldn't see any replies sent to it."))
3311 (setq message-this-is-news nil)
3312 (cons 'To (or reply-to from "")))
3313 (cons 'Newsgroups newsgroups)))
3315 (if (or (equal followup-to newsgroups)
3316 (not (eq message-use-followup-to 'ask))
3318 (concat "Obey Followup-To: " followup-to "? ") t "\
3319 You should normally obey the Followup-To: header.
3321 `Followup-To: " followup-to "'
3322 directs your response to " (if (string-match "," followup-to)
3323 "the specified newsgroups"
3324 "that newsgroup only") ".
3326 If a message is posted to several newsgroups, Followup-To is often
3327 used to direct the following discussion to one newsgroup only,
3328 because discussions that are spread over several newsgroup tend to
3329 be fragmented and very difficult to follow.
3331 Also, some source/announcement newsgroups are not indented for discussion;
3332 responses here are directed to other newsgroups."))
3333 (cons 'Newsgroups followup-to)
3334 (cons 'Newsgroups newsgroups))))))
3336 `((Newsgroups . ,posted-to)))
3338 `((Newsgroups . ,newsgroups))))
3339 ,@(and distribution (list (cons 'Distribution distribution)))
3340 ,@(if (or references message-id)
3341 `((References . ,(concat (or references "") (and references " ")
3342 (or message-id "")))))
3344 (not (equal (downcase mct) "never")))
3345 (list (cons 'Cc (if (equal (downcase mct) "always")
3346 (or reply-to from "")
3351 (setq message-reply-headers
3352 (vector 0 subject from date message-id references 0 0 ""))))
3356 (defun message-cancel-news ()
3357 "Cancel an article you posted."
3359 (unless (message-news-p)
3360 (error "This is not a news article; canceling is impossible"))
3361 (when (yes-or-no-p "Do you really want to cancel this article? ")
3362 (let (from newsgroups message-id distribution buf)
3364 ;; Get header info. from original article.
3366 (message-narrow-to-head)
3367 (setq from (message-fetch-field "from")
3368 newsgroups (message-fetch-field "newsgroups")
3369 message-id (message-fetch-field "message-id" t)
3370 distribution (message-fetch-field "distribution")))
3371 ;; Make sure that this article was written by the user.
3372 (unless (string-equal
3373 (downcase (cadr (mail-extract-address-components from)))
3374 (downcase (message-make-address)))
3375 (error "This article is not yours"))
3376 ;; Make control message.
3377 (setq buf (set-buffer (get-buffer-create " *message cancel*")))
3378 (buffer-disable-undo (current-buffer))
3380 (insert "Newsgroups: " newsgroups "\n"
3381 "From: " (message-make-from) "\n"
3382 "Subject: cmsg cancel " message-id "\n"
3383 "Control: cancel " message-id "\n"
3385 (concat "Distribution: " distribution "\n")
3387 mail-header-separator "\n"
3388 message-cancel-message)
3389 (message "Canceling your article...")
3390 (if (let ((message-syntax-checks
3391 'dont-check-for-anything-just-trust-me))
3392 (message-send-news))
3393 (message "Canceling your article...done"))
3394 (kill-buffer buf)))))
3397 (defun message-supersede ()
3398 "Start composing a message to supersede the current message.
3399 This is done simply by taking the old article and adding a Supersedes
3400 header line with the old Message-ID."
3402 (let ((cur (current-buffer)))
3403 ;; Check whether the user owns the article that is to be superseded.
3404 (unless (string-equal
3405 (downcase (cadr (mail-extract-address-components
3406 (message-fetch-field "from"))))
3407 (downcase (message-make-address)))
3408 (error "This article is not yours"))
3409 ;; Get a normal message buffer.
3410 (message-pop-to-buffer (message-buffer-name "supersede"))
3411 (insert-buffer-substring cur)
3412 (message-narrow-to-head)
3413 ;; Remove unwanted headers.
3414 (when message-ignored-supersedes-headers
3415 (message-remove-header message-ignored-supersedes-headers t))
3416 (goto-char (point-min))
3417 (if (not (re-search-forward "^Message-ID: " nil t))
3418 (error "No Message-ID in this article")
3419 (replace-match "Supersedes: " t t))
3420 (goto-char (point-max))
3421 (insert mail-header-separator)
3426 (defun message-recover ()
3427 "Reread contents of current buffer from its last auto-save file."
3429 (let ((file-name (make-auto-save-file-name)))
3430 (cond ((save-window-excursion
3431 (if (not (eq system-type 'vax-vms))
3432 (with-output-to-temp-buffer "*Directory*"
3433 (buffer-disable-undo standard-output)
3434 (let ((default-directory "/"))
3436 "ls" nil standard-output nil "-l" file-name))))
3437 (yes-or-no-p (format "Recover auto save file %s? " file-name)))
3438 (let ((buffer-read-only nil))
3440 (insert-file-contents file-name nil)))
3441 (t (error "message-recover cancelled")))))
3443 ;;; Forwarding messages.
3445 (defun message-make-forward-subject ()
3446 "Return a Subject header suitable for the message in the current buffer."
3450 (message-narrow-to-head)
3451 (concat "[" (or (message-fetch-field
3452 (if (message-news-p) "newsgroups" "from"))
3454 "] " (or (message-fetch-field "Subject") "")))))
3457 (defun message-forward (&optional news)
3458 "Forward the current message via mail.
3459 Optional NEWS will use news to forward instead of mail."
3461 (let ((cur (current-buffer))
3462 (subject (message-make-forward-subject))
3464 (if news (message-news nil subject) (message-mail nil subject))
3465 ;; Put point where we want it before inserting the forwarded
3467 (if message-signature-before-forwarded-message
3468 (goto-char (point-max))
3469 (message-goto-body))
3470 ;; Make sure we're at the start of the line.
3473 ;; Narrow to the area we are to insert.
3474 (narrow-to-region (point) (point))
3475 ;; Insert the separators and the forwarded buffer.
3476 (insert message-forward-start-separator)
3477 (setq art-beg (point))
3478 (insert-buffer-substring cur)
3479 (goto-char (point-max))
3480 (insert message-forward-end-separator)
3481 (set-text-properties (point-min) (point-max) nil)
3482 ;; Remove all unwanted headers.
3484 (narrow-to-region (point) (if (search-forward "\n\n" nil t)
3487 (goto-char (point-min))
3488 (message-remove-header message-included-forward-headers t nil t)
3490 (message-position-point)))
3493 (defun message-resend (address)
3494 "Resend the current article to ADDRESS."
3495 (interactive "sResend message to: ")
3496 (message "Resending message to %s..." address)
3498 (let ((cur (current-buffer))
3500 ;; We first set up a normal mail buffer.
3501 (set-buffer (get-buffer-create " *message resend*"))
3502 (buffer-disable-undo (current-buffer))
3504 (message-setup `((To . ,address)))
3505 ;; Insert our usual headers.
3506 (message-generate-headers '(From Date To))
3507 (message-narrow-to-headers)
3508 ;; Rename them all to "Resent-*".
3509 (while (re-search-forward "^[A-Za-z]" nil t)
3514 (delete-region (point) (point-max))
3516 ;; Insert the message to be resent.
3517 (insert-buffer-substring cur)
3518 (goto-char (point-min))
3519 (search-forward "\n\n")
3522 (narrow-to-region beg (point))
3523 (message-remove-header message-ignored-resent-headers t)
3524 (goto-char (point-max)))
3525 (insert mail-header-separator)
3526 ;; Rename all old ("Also-")Resent headers.
3527 (while (re-search-backward "^\\(Also-\\)?Resent-" beg t)
3530 ;; Quote any "From " lines at the beginning.
3532 (when (looking-at "From ")
3533 (replace-match "X-From-Line: "))
3536 (kill-buffer (current-buffer)))
3537 (message "Resending message to %s...done" address)))
3540 (defun message-bounce ()
3541 "Re-mail the current message.
3542 This only makes sense if the current message is a bounce message than
3543 contains some mail you have written which has been bounced back to
3546 (let ((cur (current-buffer))
3548 (message-pop-to-buffer (message-buffer-name "bounce"))
3549 (insert-buffer-substring cur)
3551 (message-narrow-to-head)
3552 (if (and (message-fetch-field "Mime-Version")
3553 (setq boundary (message-fetch-field "Content-Type")))
3554 (if (string-match "boundary=\"\\([^\"]+\\)\"" boundary)
3555 (setq boundary (concat (match-string 1 boundary) " *\n"
3556 "Content-Type: message/rfc822"))
3557 (setq boundary nil)))
3559 (goto-char (point-min))
3560 (search-forward "\n\n" nil t)
3562 (re-search-forward boundary nil t)
3564 (and (re-search-forward message-unsent-separator nil t)
3566 (re-search-forward "^Return-Path:.*\n" nil t))
3567 ;; We remove everything before the bounced mail.
3570 (if (re-search-forward "^[^ \n\t]+:" nil t)
3574 (message-narrow-to-head)
3575 (message-remove-header message-ignored-bounced-headers t)
3576 (goto-char (point-max))
3577 (insert mail-header-separator))
3578 (message-position-point)))
3581 ;;; Interactive entry points for new message buffers.
3585 (defun message-mail-other-window (&optional to subject)
3586 "Like `message-mail' command, but display mail buffer in another window."
3588 (let ((pop-up-windows t)
3589 (special-display-buffer-names nil)
3590 (special-display-regexps nil)
3591 (same-window-buffer-names nil)
3592 (same-window-regexps nil))
3593 (message-pop-to-buffer (message-buffer-name "mail" to)))
3594 (message-setup `((To . ,(or to "")) (Subject . ,(or subject "")))))
3597 (defun message-mail-other-frame (&optional to subject)
3598 "Like `message-mail' command, but display mail buffer in another frame."
3600 (let ((pop-up-frames t)
3601 (special-display-buffer-names nil)
3602 (special-display-regexps nil)
3603 (same-window-buffer-names nil)
3604 (same-window-regexps nil))
3605 (message-pop-to-buffer (message-buffer-name "mail" to)))
3606 (message-setup `((To . ,(or to "")) (Subject . ,(or subject "")))))
3609 (defun message-news-other-window (&optional newsgroups subject)
3610 "Start editing a news article to be sent."
3612 (let ((pop-up-windows t)
3613 (special-display-buffer-names nil)
3614 (special-display-regexps nil)
3615 (same-window-buffer-names nil)
3616 (same-window-regexps nil))
3617 (message-pop-to-buffer (message-buffer-name "news" nil newsgroups)))
3618 (message-setup `((Newsgroups . ,(or newsgroups ""))
3619 (Subject . ,(or subject "")))))
3622 (defun message-news-other-frame (&optional newsgroups subject)
3623 "Start editing a news article to be sent."
3625 (let ((pop-up-frames t)
3626 (special-display-buffer-names nil)
3627 (special-display-regexps nil)
3628 (same-window-buffer-names nil)
3629 (same-window-regexps nil))
3630 (message-pop-to-buffer (message-buffer-name "news" nil newsgroups)))
3631 (message-setup `((Newsgroups . ,(or newsgroups ""))
3632 (Subject . ,(or subject "")))))
3636 ;; This code should be moved to underline.el (from which it is stolen).
3639 (defun bold-region (start end)
3640 "Bold all nonblank characters in the region.
3641 Works by overstriking characters.
3642 Called from program, takes two arguments START and END
3643 which specify the range to operate on."
3646 (let ((end1 (make-marker)))
3647 (move-marker end1 (max start end))
3648 (goto-char (min start end))
3649 (while (< (point) end1)
3650 (or (looking-at "[_\^@- ]")
3651 (insert (following-char) "\b"))
3652 (forward-char 1)))))
3655 (defun unbold-region (start end)
3656 "Remove all boldness (overstruck characters) in the region.
3657 Called from program, takes two arguments START and END
3658 which specify the range to operate on."
3661 (let ((end1 (make-marker)))
3662 (move-marker end1 (max start end))
3663 (goto-char (min start end))
3664 (while (re-search-forward "\b" end1 t)
3665 (if (eq (following-char) (char-after (- (point) 2)))
3666 (delete-char -2))))))
3668 (defalias 'message-exchange-point-and-mark 'exchange-point-and-mark)
3670 ;; Support for toolbar
3671 (when (string-match "XEmacs\\|Lucid" emacs-version)
3672 (require 'messagexmas))
3674 ;;; Group name completion.
3676 (defvar message-newgroups-header-regexp
3677 "^\\(Newsgroups\\|Followup-To\\|Posted-To\\|Gcc\\):"
3678 "Regexp that match headers that lists groups.")
3680 (defun message-tab ()
3681 "Expand group names in Newsgroups and Followup-To headers.
3682 Do a `tab-to-tab-stop' if not in those headers."
3684 (if (let ((mail-abbrev-mode-regexp message-newgroups-header-regexp))
3685 (mail-abbrev-in-expansion-header-p))
3686 (message-expand-group)
3689 (defvar gnus-active-hashtb)
3690 (defun message-expand-group ()
3691 (let* ((b (save-excursion
3696 (skip-chars-forward "^:")
3699 (skip-chars-backward "^, \t\n") (point))))
3700 (completion-ignore-case t)
3701 (string (buffer-substring b (point)))
3702 (hashtb (and (boundp 'gnus-active-hashtb) gnus-active-hashtb))
3703 (completions (all-completions string hashtb))
3704 (cur (current-buffer))
3706 (delete-region b (point))
3708 ((= (length completions) 1)
3709 (if (string= (car completions) string)
3712 (message "Only matching group"))
3713 (insert (car completions))))
3714 ((and (setq comp (try-completion string hashtb))
3715 (not (string= comp string)))
3720 (message "No matching groups")
3721 (save-selected-window
3722 (pop-to-buffer "*Completions*")
3723 (buffer-disable-undo (current-buffer))
3724 (let ((buffer-read-only nil))
3726 (let ((standard-output (current-buffer)))
3727 (display-completion-list (sort completions 'string<)))
3728 (goto-char (point-min))
3729 (delete-region (point) (progn (forward-line 3) (point))))))))))
3733 (defun message-talkative-question (ask question show &rest text)
3734 "Call FUNCTION with argument QUESTION; optionally display TEXT... args.
3735 If SHOW is non-nil, the arguments TEXT... are displayed in a temp buffer.
3736 The following arguments may contain lists of values."
3738 (setq text (message-flatten-list text)))
3739 (save-window-excursion
3741 (with-output-to-temp-buffer " *MESSAGE information message*"
3742 (set-buffer " *MESSAGE information message*")
3743 (mapcar 'princ text)
3744 (goto-char (point-min))))
3745 (funcall ask question))
3746 (funcall ask question)))
3748 (defun message-flatten-list (list)
3749 "Return a new, flat list that contains all elements of LIST.
3751 \(message-flatten-list '(1 (2 3 (4 5 (6))) 7))
3754 (apply 'append (mapcar 'message-flatten-list list)))
3758 (defun message-generate-new-buffer-clone-locals (name &optional varstr)
3759 "Create and return a buffer with a name based on NAME using generate-new-buffer.
3760 Then clone the local variables and values from the old buffer to the
3761 new one, cloning only the locals having a substring matching the
3763 (let ((oldbuf (current-buffer)))
3765 (set-buffer (generate-new-buffer name))
3766 (message-clone-locals oldbuf)
3769 (defun message-clone-locals (buffer)
3770 "Clone the local variables from BUFFER to the current buffer."
3771 (let ((locals (save-excursion
3773 (buffer-local-variables)))
3774 (regexp "^gnus\\|^nn\\|^message"))
3777 (when (and (consp local)
3779 (string-match regexp (symbol-name (car local))))
3781 (set (make-local-variable (car local))
3785 ;;; Miscellaneous functions
3787 ;; stolen (and renamed) from nnheader.el
3788 (defun message-replace-chars-in-string (string from to)
3789 "Replace characters in STRING from FROM to TO."
3790 (let ((string (substring string 0)) ;Copy string.
3791 (len (length string))
3793 ;; Replace all occurrences of FROM with TO.
3795 (when (= (aref string idx) from)
3796 (aset string idx to))
3797 (setq idx (1+ idx)))
3800 (run-hooks 'message-load-hook)
3804 ;;; message.el ends here