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.
40 (if (string-match "XEmacs\\|Lucid" emacs-version)
41 (require 'mail-abbrevs)
42 (require 'mailabbrev))
44 (defgroup message '((user-mail-address custom-variable)
45 (user-full-name custom-variable))
46 "Mail and news message composing."
47 :link '(custom-manual "(message)Top")
50 (put 'user-mail-address 'custom-type 'string)
51 (put 'user-full-name 'custom-type 'string)
53 (defgroup message-various nil
54 "Various Message Variables"
55 :link '(custom-manual "(message)Various Message Variables")
58 (defgroup message-buffers nil
60 :link '(custom-manual "(message)Message Buffers")
63 (defgroup message-sending nil
65 :link '(custom-manual "(message)Sending Variables")
68 (defgroup message-interface nil
70 :link '(custom-manual "(message)Interface")
73 (defgroup message-forwarding nil
75 :link '(custom-manual "(message)Forwarding")
76 :group 'message-interface)
78 (defgroup message-insertion nil
80 :link '(custom-manual "(message)Insertion")
83 (defgroup message-headers nil
85 :link '(custom-manual "(message)Message Headers")
88 (defgroup message-news nil
89 "Composing News Messages"
92 (defgroup message-mail nil
93 "Composing Mail Messages"
96 (defcustom message-directory "~/Mail/"
97 "*Directory from which all other mail file variables are derived."
98 :group 'message-various
101 (defcustom message-max-buffers 10
102 "*How many buffers to keep before starting to kill them off."
103 :group 'message-buffers
106 (defcustom message-send-rename-function nil
107 "Function called to rename the buffer after sending it."
108 :group 'message-buffers
112 (defcustom message-fcc-handler-function 'message-output
113 "*A function called to save outgoing articles.
114 This function will be called with the name of the file to store the
115 article in. The default function is `message-output' which saves in Unix
117 :type '(radio (function-item message-output)
118 (function :tag "Other"))
119 :group 'message-sending)
121 (defcustom message-courtesy-message
122 "The following message is a courtesy copy of an article\nthat has been posted to %s as well.\n\n"
123 "*This is inserted at the start of a mailed copy of a posted message.
124 If the string contains the format spec \"%s\", the Newsgroups
125 the article has been posted to will be inserted there.
126 If this variable is nil, no such courtesy message will be added."
127 :group 'message-sending
130 (defcustom message-ignored-bounced-headers "^\\(Received\\|Return-Path\\):"
131 "*Regexp that matches headers to be removed in resent bounced mail."
132 :group 'message-interface
136 (defcustom message-from-style 'default
137 "*Specifies how \"From\" headers look.
139 If `nil', they contain just the return address like:
141 If `parens', they look like:
142 king@grassland.com (Elvis Parsley)
143 If `angles', they look like:
144 Elvis Parsley <king@grassland.com>
146 Otherwise, most addresses look like `angles', but they look like
147 `parens' if `angles' would need quoting and `parens' would not."
148 :type '(choice (const :tag "simple" nil)
152 :group 'message-headers)
154 (defcustom message-syntax-checks nil
155 ;; Guess this one shouldn't be easy to customize...
156 "Controls what syntax checks should not be performed on outgoing posts.
157 To disable checking of long signatures, for instance, add
158 `(signature . disabled)' to this list.
160 Don't touch this variable unless you really know what you're doing.
162 Checks include subject-cmsg multiple-headers sendsys message-id from
163 long-lines control-chars size new-text redirected-followup signature
164 approved sender empty empty-headers message-id from subject
165 shorten-followup-to existing-newsgroups."
166 :group 'message-news)
168 (defcustom message-required-news-headers
169 '(From Newsgroups Subject Date Message-ID
170 (optional . Organization) Lines
171 (optional . X-Newsreader))
172 "Headers to be generated or prompted for when posting an article.
173 RFC977 and RFC1036 require From, Date, Newsgroups, Subject,
174 Message-ID. Organization, Lines, In-Reply-To, Expires, and
175 X-Newsreader are optional. If don't you want message to insert some
176 header, remove it from this list."
178 :group 'message-headers
179 :type '(repeat sexp))
181 (defcustom message-required-mail-headers
182 '(From Subject Date (optional . In-Reply-To) Message-ID Lines
183 (optional . X-Mailer))
184 "Headers to be generated or prompted for when mailing a message.
185 RFC822 required that From, Date, To, Subject and Message-ID be
186 included. Organization, Lines and X-Mailer are optional."
188 :group 'message-headers
189 :type '(repeat sexp))
191 (defcustom message-deletable-headers '(Message-ID Date Lines)
192 "Headers to be deleted if they already exist and were generated by message previously."
193 :group 'message-headers
196 (defcustom message-ignored-news-headers
197 "^NNTP-Posting-Host:\\|^Xref:\\|^Bcc:\\|^Gcc:\\|^Fcc:\\|^Resent-Fcc:"
198 "*Regexp of headers to be removed unconditionally before posting."
200 :group 'message-headers
203 (defcustom message-ignored-mail-headers "^Gcc:\\|^Fcc:\\|^Resent-Fcc:"
204 "*Regexp of headers to be removed unconditionally before mailing."
206 :group 'message-headers
209 (defcustom message-ignored-supersedes-headers "^Path:\\|^Date\\|^NNTP-Posting-Host:\\|^Xref:\\|^Lines:\\|^Received:\\|^X-From-Line:\\|Return-Path:\\|^Supersedes:"
210 "*Header lines matching this regexp will be deleted before posting.
211 It's best to delete old Path and Date headers before posting to avoid
213 :group 'message-interface
217 (defcustom message-signature-separator "^-- *$"
218 "Regexp matching the signature separator."
220 :group 'message-various)
222 (defcustom message-elide-elipsis "\n[...]\n\n"
223 "*The string which is inserted for elided text.")
225 (defcustom message-interactive nil
226 "Non-nil means when sending a message wait for and display errors.
227 nil means let mailer mail back a message to report errors."
228 :group 'message-sending
232 (defcustom message-generate-new-buffers t
233 "*Non-nil means that a new message buffer will be created whenever `mail-setup' is called.
234 If this is a function, call that function with three parameters: The type,
235 the to address and the group name. (Any of these may be nil.) The function
236 should return the new buffer name."
237 :group 'message-buffers
238 :type '(choice (const :tag "off" nil)
242 (defcustom message-kill-buffer-on-exit nil
243 "*Non-nil means that the message buffer will be killed after sending a message."
244 :group 'message-buffers
247 (defvar gnus-local-organization)
248 (defcustom message-user-organization
249 (or (and (boundp 'gnus-local-organization)
250 (stringp gnus-local-organization)
251 gnus-local-organization)
252 (getenv "ORGANIZATION")
254 "*String to be used as an Organization header.
255 If t, use `message-user-organization-file'."
256 :group 'message-headers
257 :type '(choice string
258 (const :tag "consult file" t)))
261 (defcustom message-user-organization-file "/usr/lib/news/organization"
262 "*Local news organization file."
264 :group 'message-headers)
266 (defcustom message-autosave-directory "~/"
267 ; (concat (file-name-as-directory message-directory) "drafts/")
268 "*Directory where message autosaves buffers.
269 If nil, message won't autosave."
270 :group 'message-buffers
273 (defcustom message-forward-start-separator
274 "------- Start of forwarded message -------\n"
275 "*Delimiter inserted before forwarded messages."
276 :group 'message-forwarding
279 (defcustom message-forward-end-separator
280 "------- End of forwarded message -------\n"
281 "*Delimiter inserted after forwarded messages."
282 :group 'message-forwarding
285 (defcustom message-signature-before-forwarded-message t
286 "*If non-nil, put the signature before any included forwarded message."
287 :group 'message-forwarding
290 (defcustom message-included-forward-headers
291 "^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:"
292 "*Regexp matching headers to be included in forwarded messages."
293 :group 'message-forwarding
296 (defcustom message-ignored-resent-headers "^Return-receipt"
297 "*All headers that match this regexp will be deleted when resending a message."
298 :group 'message-interface
301 (defcustom message-ignored-cited-headers "."
302 "*Delete these headers from the messages you yank."
303 :group 'message-insertion
306 (defcustom message-cancel-message "I am canceling my own article."
307 "Message to be inserted in the cancel message."
308 :group 'message-interface
311 ;; Useful to set in site-init.el
313 (defcustom message-send-mail-function 'message-send-mail-with-sendmail
314 "Function to call to send the current buffer as mail.
315 The headers should be delimited by a line whose contents match the
316 variable `mail-header-separator'.
318 Legal values include `message-send-mail-with-sendmail' (the default),
319 `message-send-mail-with-mh' and `message-send-mail-with-qmail'."
320 :type '(radio (function-item message-send-mail-with-sendmail)
321 (function-item message-send-mail-with-mh)
322 (function-item message-send-mail-with-qmail)
323 (function :tag "Other"))
324 :group 'message-sending
325 :group 'message-mail)
327 (defcustom message-send-news-function 'message-send-news
328 "Function to call to send the current buffer as news.
329 The headers should be delimited by a line whose contents match the
330 variable `mail-header-separator'."
331 :group 'message-sending
335 (defcustom message-reply-to-function nil
336 "Function that should return a list of headers.
337 This function should pick out addresses from the To, Cc, and From headers
338 and respond with new To and Cc headers."
339 :group 'message-interface
342 (defcustom message-wide-reply-to-function nil
343 "Function that should return a list of headers.
344 This function should pick out addresses from the To, Cc, and From headers
345 and respond with new To and Cc headers."
346 :group 'message-interface
349 (defcustom message-followup-to-function nil
350 "Function that should return a list of headers.
351 This function should pick out addresses from the To, Cc, and From headers
352 and respond with new To and Cc headers."
353 :group 'message-interface
356 (defcustom message-use-followup-to 'ask
357 "*Specifies what to do with Followup-To header.
358 If nil, always ignore the header. If it is t, use its value, but
359 query before using the \"poster\" value. If it is the symbol `ask',
360 always query the user whether to use the value. If it is the symbol
361 `use', always use the value."
362 :group 'message-interface
363 :type '(choice (const :tag "ignore" nil)
367 ;; stuff relating to broken sendmail in MMDF
368 (defcustom message-sendmail-f-is-evil nil
369 "*Non-nil means that \"-f username\" should not be added to the sendmail
370 command line, because it is even more evil than leaving it out."
371 :group 'message-sending
374 ;; qmail-related stuff
375 (defcustom message-qmail-inject-program "/var/qmail/bin/qmail-inject"
376 "Location of the qmail-inject program."
377 :group 'message-sending
380 (defcustom message-qmail-inject-args nil
381 "Arguments passed to qmail-inject programs.
382 This should be a list of strings, one string for each argument.
384 For e.g., if you wish to set the envelope sender address so that bounces
385 go to the right place or to deal with listserv's usage of that address, you
386 might set this variable to '(\"-f\" \"you@some.where\")."
387 :group 'message-sending
388 :type '(repeat string))
390 (defvar gnus-post-method)
391 (defvar gnus-select-method)
392 (defcustom message-post-method
393 (cond ((and (boundp 'gnus-post-method)
396 ((boundp 'gnus-select-method)
399 "Method used to post news."
401 :group 'mesage-sending
402 ;; This should be the `gnus-select-method' widget, but that might
403 ;; create a dependence to `gnus.el'.
406 (defcustom message-generate-headers-first nil
407 "*If non-nil, generate all possible headers before composing."
408 :group 'message-headers
411 (defcustom message-setup-hook nil
412 "Normal hook, run each time a new outgoing message is initialized.
413 The function `message-setup' runs this hook."
414 :group 'message-various
417 (defcustom message-signature-setup-hook nil
418 "Normal hook, run each time a new outgoing message is initialized.
419 It is run after the headers have been inserted and before
420 the signature is inserted."
421 :group 'message-various
424 (defcustom message-mode-hook nil
425 "Hook run in message mode buffers."
426 :group 'message-various
429 (defcustom message-header-hook nil
430 "Hook run in a message mode buffer narrowed to the headers."
431 :group 'message-various
434 (defcustom message-header-setup-hook nil
435 "Hook called narrowed to the headers when setting up a message
437 :group 'message-various
441 (defcustom message-citation-line-function 'message-insert-citation-line
442 "*Function called to insert the \"Whomever writes:\" line."
444 :group 'message-insertion)
447 (defcustom message-yank-prefix "> "
448 "*Prefix inserted on the lines of yanked messages.
449 nil means use indentation."
451 :group 'message-insertion)
453 (defcustom message-indentation-spaces 3
454 "*Number of spaces to insert at the beginning of each cited line.
455 Used by `message-yank-original' via `message-yank-cite'."
456 :group 'message-insertion
460 (defcustom message-cite-function
461 (if (and (boundp 'mail-citation-hook)
464 'message-cite-original)
465 "*Function for citing an original message."
466 :type '(radio (function-item message-cite-original)
467 (function-item sc-cite-original)
468 (function :tag "Other"))
469 :group 'message-insertion)
472 (defcustom message-indent-citation-function 'message-indent-citation
473 "*Function for modifying a citation just inserted in the mail buffer.
474 This can also be a list of functions. Each function can find the
475 citation between (point) and (mark t). And each function should leave
476 point and mark around the citation text as modified."
478 :group 'message-insertion)
480 (defvar message-abbrevs-loaded nil)
483 (defcustom message-signature t
484 "*String to be inserted at the end of the message buffer.
485 If t, the `message-signature-file' file will be inserted instead.
486 If a function, the result from the function will be used instead.
487 If a form, the result from the form will be used instead."
489 :group 'message-insertion)
492 (defcustom message-signature-file "~/.signature"
493 "*File containing the text inserted at end of message buffer."
495 :group 'message-insertion)
497 (defcustom message-distribution-function nil
498 "*Function called to return a Distribution header."
500 :group 'message-headers
503 (defcustom message-expires 14
504 "Number of days before your article expires."
506 :group 'message-headers
507 :link '(custom-manual "(message)News Headers")
510 (defcustom message-user-path nil
511 "If nil, use the NNTP server name in the Path header.
512 If stringp, use this; if non-nil, use no host name (user name only)."
514 :group 'message-headers
515 :link '(custom-manual "(message)News Headers")
516 :type '(choice (const :tag "nntp" nil)
518 (sexp :tag "none" :format "%t" t)))
520 (defvar message-reply-buffer nil)
521 (defvar message-reply-headers nil)
522 (defvar message-newsreader nil)
523 (defvar message-mailer nil)
524 (defvar message-sent-message-via nil)
525 (defvar message-checksum nil)
526 (defvar message-send-actions nil
527 "A list of actions to be performed upon successful sending of a message.")
528 (defvar message-exit-actions nil
529 "A list of actions to be performed upon exiting after sending a message.")
530 (defvar message-kill-actions nil
531 "A list of actions to be performed before killing a message buffer.")
532 (defvar message-postpone-actions nil
533 "A list of actions to be performed after postponing a message.")
535 (defcustom message-default-headers ""
536 "*A string containing header lines to be inserted in outgoing messages.
537 It is inserted before you edit the message, so you can edit or delete
539 :group 'message-headers
542 (defcustom message-default-mail-headers ""
543 "*A string of header lines to be inserted in outgoing mails."
544 :group 'message-headers
548 (defcustom message-default-news-headers ""
549 "*A string of header lines to be inserted in outgoing news
551 :group 'message-headers
555 ;; Note: could use /usr/ucb/mail instead of sendmail;
556 ;; options -t, and -v if not interactive.
557 (defcustom message-mailer-swallows-blank-line
558 (if (and (string-match "sparc-sun-sunos\\(\\'\\|[^5]\\)"
559 system-configuration)
560 (file-readable-p "/etc/sendmail.cf")
561 (let ((buffer (get-buffer-create " *temp*")))
565 (insert-file-contents "/etc/sendmail.cf")
566 (goto-char (point-min))
567 (let ((case-fold-search nil))
568 (re-search-forward "^OR\\>" nil t)))
569 (kill-buffer buffer))))
570 ;; According to RFC822, "The field-name must be composed of printable
571 ;; ASCII characters (i. e., characters that have decimal values between
572 ;; 33 and 126, except colon)", i. e., any chars except ctl chars,
574 '(looking-at "[ \t]\\|[][!\"#$%&'()*+,-./0-9;<=>?@A-Z\\\\^_`a-z{|}~]+:"))
575 "Set this non-nil if the system's mailer runs the header and body together.
576 \(This problem exists on Sunos 4 when sendmail is run in remote mode.)
577 The value should be an expression to test whether the problem will
579 :group 'message-sending
583 (define-mail-user-agent 'message-user-agent
584 'message-mail 'message-send-and-exit
585 'message-kill-buffer 'message-send-hook))
587 (defvar message-mh-deletable-headers '(Message-ID Date Lines Sender)
588 "If non-nil, delete the deletable headers before feeding to mh.")
590 ;;; Internal variables.
591 ;;; Well, not really internal.
593 (defvar message-mode-syntax-table
594 (let ((table (copy-syntax-table text-mode-syntax-table)))
595 (modify-syntax-entry ?% ". " table)
597 "Syntax table used while in Message mode.")
599 (defvar message-mode-abbrev-table text-mode-abbrev-table
600 "Abbrev table used in Message mode buffers.
601 Defaults to `text-mode-abbrev-table'.")
603 (defvar message-font-lock-keywords
604 (let* ((cite-prefix "A-Za-z") (cite-suffix (concat cite-prefix "0-9_.@-")))
605 (list '("^To:" . font-lock-function-name-face)
606 '("^[GBF]?[Cc][Cc]:\\|^Reply-To:" . font-lock-keyword-face)
607 '("^\\(Subject:\\)[ \t]*\\(.+\\)?"
608 (1 font-lock-comment-face) (2 font-lock-type-face nil t))
609 (list (concat "^\\(" (regexp-quote mail-header-separator) "\\)$")
610 1 'font-lock-comment-face)
611 (cons (concat "^[ \t]*"
612 "\\([" cite-prefix "]+[" cite-suffix "]*\\)?"
614 'font-lock-reference-face)
615 '("^\\(X-[A-Za-z0-9-]+\\|In-Reply-To\\):.*"
616 . font-lock-string-face)))
617 "Additional expressions to highlight in Message mode.")
619 (defvar message-face-alist
620 '((bold . bold-region)
621 (underline . underline-region)
622 (default . (lambda (b e)
624 (ununderline-region b e))))
625 "Alist of mail and news faces for facemenu.
626 The cdr of ech entry is a function for applying the face to a region.")
628 (defcustom message-send-hook nil
629 "Hook run before sending messages."
630 :group 'message-various
631 :options '(ispell-message)
634 (defcustom message-send-mail-hook nil
635 "Hook run before sending mail messages."
636 :group 'message-various
639 (defcustom message-send-news-hook nil
640 "Hook run before sending news messages."
641 :group 'message-various
644 (defcustom message-sent-hook nil
645 "Hook run after sending messages."
646 :group 'message-various
649 ;;; Internal variables.
651 (defvar message-buffer-list nil)
652 (defvar message-this-is-news nil)
653 (defvar message-this-is-mail nil)
655 ;; Byte-compiler warning
656 (defvar gnus-active-hashtb)
657 (defvar gnus-read-active-file)
659 ;;; Regexp matching the delimiter of messages in UNIX mail format
660 ;;; (UNIX From lines), minus the initial ^.
661 (defvar message-unix-mail-delimiter
662 (let ((time-zone-regexp
663 (concat "\\([A-Z]?[A-Z]?[A-Z][A-Z]\\( DST\\)?"
664 "\\|[-+]?[0-9][0-9][0-9][0-9]"
670 ;; Username, perhaps with a quoted section that can contain spaces.
673 "\\(\\|\".*\"[^ \n]*\\)"
677 ;; The time the message was sent.
678 "\\([^ \n]*\\) *" ; day of the week
679 "\\([^ ]*\\) *" ; month
680 "\\([0-9]*\\) *" ; day of month
681 "\\([0-9:]*\\) *" ; time of day
683 ;; Perhaps a time zone, specified by an abbreviation, or by a
688 " [0-9][0-9]\\([0-9]*\\) *"
690 ;; On some systems the time zone can appear after the year, too.
694 "\\(remote from .*\\)?"
698 (defvar message-unsent-separator
699 (concat "^ *---+ +Unsent message follows +---+ *$\\|"
700 "^ *---+ +Returned message +---+ *$\\|"
701 "^Start of returned message$\\|"
702 "^ *---+ +Original message +---+ *$\\|"
703 "^ *--+ +begin message +--+ *$\\|"
704 "^ *---+ +Original message follows +---+ *$\\|"
705 "^|? *---+ +Message text follows: +---+ *|?$")
706 "A regexp that matches the separator before the text of a failed message.")
708 (defvar message-header-format-alist
710 (To . message-fill-address)
711 (Cc . message-fill-address)
725 "Alist used for formatting headers.")
728 (autoload 'message-setup-toolbar "messagexmas")
729 (autoload 'mh-send-letter "mh-comp")
730 (autoload 'gnus-output-to-mail "gnus-util")
731 (autoload 'gnus-output-to-rmail "gnus-util"))
736 ;;; Utility functions.
739 (defun message-point-at-bol ()
740 "Return point at the beginning of the line."
747 (defun message-point-at-eol ()
748 "Return point at the end of the line."
755 (defmacro message-y-or-n-p (question show &rest text)
756 "Ask QUESTION, displaying the rest of the arguments in a temp. buffer if SHOW"
757 `(message-talkative-question 'y-or-n-p ,question ,show ,@text))
759 ;; Delete the current line (and the next N lines.);
760 (defmacro message-delete-line (&optional n)
761 `(delete-region (progn (beginning-of-line) (point))
762 (progn (forward-line ,(or n 1)) (point))))
764 (defun message-tokenize-header (header &optional separator)
765 "Split HEADER into a list of header elements.
766 \",\" is used as the separator."
769 (let ((regexp (format "[%s]+" (or separator ",")))
774 (message-set-work-buffer)
776 (goto-char (point-min))
781 (cond ((and (> (point) beg)
783 (and (looking-at regexp)
786 (push (buffer-substring beg (point)) elems)
787 (setq beg (match-end 0)))
788 ((= (following-char) ?\")
789 (setq quoted (not quoted)))
790 ((and (= (following-char) ?\()
793 ((and (= (following-char) ?\))
798 (defun message-fetch-field (header &optional not-all)
799 "The same as `mail-fetch-field', only remove all newlines."
800 (let ((value (mail-fetch-field header nil (not not-all))))
802 (nnheader-replace-chars-in-string value ?\n ? ))))
804 (defun message-fetch-reply-field (header)
805 "Fetch FIELD from the message we're replying to."
806 (when (and message-reply-buffer
807 (buffer-name message-reply-buffer))
809 (set-buffer message-reply-buffer)
810 (message-fetch-field header))))
812 (defun message-set-work-buffer ()
813 (if (get-buffer " *message work*")
815 (set-buffer " *message work*")
817 (set-buffer (get-buffer-create " *message work*"))
818 (kill-all-local-variables)
819 (buffer-disable-undo (current-buffer))))
821 (defun message-functionp (form)
822 "Return non-nil if FORM is funcallable."
823 (or (and (symbolp form) (fboundp form))
824 (and (listp form) (eq (car form) 'lambda))))
826 (defun message-strip-subject-re (subject)
827 "Remove \"Re:\" from subject lines."
828 (if (string-match "^[Rr][Ee]: *" subject)
829 (substring subject (match-end 0))
832 (defun message-remove-header (header &optional is-regexp first reverse)
833 "Remove HEADER in the narrowed buffer.
834 If REGEXP, HEADER is a regular expression.
835 If FIRST, only remove the first instance of the header.
836 Return the number of headers removed."
837 (goto-char (point-min))
838 (let ((regexp (if is-regexp header (concat "^" header ":")))
842 (while (and (not (eobp))
845 (not (looking-at regexp))
853 ;; There might be a continuation header, so we have to search
854 ;; until we find a new non-continuation line.
857 (if (re-search-forward "^[^ \t]" nil t)
858 (goto-char (match-beginning 0))
861 (if (re-search-forward "^[^ \t]" nil t)
862 (goto-char (match-beginning 0))
866 (defun message-narrow-to-headers ()
867 "Narrow the buffer to the head of the message."
870 (goto-char (point-min))
871 (if (re-search-forward
872 (concat "^" (regexp-quote mail-header-separator) "\n") nil t)
875 (goto-char (point-min)))
877 (defun message-narrow-to-head ()
878 "Narrow the buffer to the head of the message."
881 (goto-char (point-min))
882 (if (search-forward "\n\n" nil 1)
885 (goto-char (point-min)))
887 (defun message-news-p ()
888 "Say whether the current buffer contains a news message."
889 (or message-this-is-news
892 (message-narrow-to-headers)
893 (message-fetch-field "newsgroups")))))
895 (defun message-mail-p ()
896 "Say whether the current buffer contains a mail message."
897 (or message-this-is-mail
900 (message-narrow-to-headers)
901 (or (message-fetch-field "to")
902 (message-fetch-field "cc")
903 (message-fetch-field "bcc"))))))
905 (defun message-next-header ()
906 "Go to the beginning of the next header."
908 (or (eobp) (forward-char 1))
909 (not (if (re-search-forward "^[^ \t]" nil t)
911 (goto-char (point-max)))))
913 (defun message-sort-headers-1 ()
914 "Sort the buffer as headers using `message-rank' text props."
915 (goto-char (point-min))
917 nil 'message-next-header
919 (message-next-header)
923 (or (get-text-property (point) 'message-rank)
926 (defun message-sort-headers ()
927 "Sort the headers of the current message according to `message-header-format-alist'."
931 (let ((max (1+ (length message-header-format-alist)))
933 (message-narrow-to-headers)
934 (while (re-search-forward "^[^ \n]+:" nil t)
936 (match-beginning 0) (1+ (match-beginning 0))
938 (if (setq rank (length (memq (assq (intern (buffer-substring
941 message-header-format-alist)
942 message-header-format-alist)))
945 (message-sort-headers-1))))
955 (defvar message-mode-map nil)
957 (unless message-mode-map
958 (setq message-mode-map (copy-keymap text-mode-map))
959 (define-key message-mode-map "\C-c?" 'describe-mode)
961 (define-key message-mode-map "\C-c\C-f\C-t" 'message-goto-to)
962 (define-key message-mode-map "\C-c\C-f\C-b" 'message-goto-bcc)
963 (define-key message-mode-map "\C-c\C-f\C-w" 'message-goto-fcc)
964 (define-key message-mode-map "\C-c\C-f\C-c" 'message-goto-cc)
965 (define-key message-mode-map "\C-c\C-f\C-s" 'message-goto-subject)
966 (define-key message-mode-map "\C-c\C-f\C-r" 'message-goto-reply-to)
967 (define-key message-mode-map "\C-c\C-f\C-n" 'message-goto-newsgroups)
968 (define-key message-mode-map "\C-c\C-f\C-d" 'message-goto-distribution)
969 (define-key message-mode-map "\C-c\C-f\C-f" 'message-goto-followup-to)
970 (define-key message-mode-map "\C-c\C-f\C-k" 'message-goto-keywords)
971 (define-key message-mode-map "\C-c\C-f\C-u" 'message-goto-summary)
972 (define-key message-mode-map "\C-c\C-b" 'message-goto-body)
973 (define-key message-mode-map "\C-c\C-i" 'message-goto-signature)
975 (define-key message-mode-map "\C-c\C-t" 'message-insert-to)
976 (define-key message-mode-map "\C-c\C-n" 'message-insert-newsgroups)
978 (define-key message-mode-map "\C-c\C-y" 'message-yank-original)
979 (define-key message-mode-map "\C-c\C-q" 'message-fill-yanked-message)
980 (define-key message-mode-map "\C-c\C-w" 'message-insert-signature)
981 (define-key message-mode-map "\C-c\C-r" 'message-caesar-buffer-body)
982 (define-key message-mode-map "\C-c\C-o" 'message-sort-headers)
983 (define-key message-mode-map "\C-c\M-r" 'message-rename-buffer)
985 (define-key message-mode-map "\C-c\C-c" 'message-send-and-exit)
986 (define-key message-mode-map "\C-c\C-s" 'message-send)
987 (define-key message-mode-map "\C-c\C-k" 'message-kill-buffer)
988 (define-key message-mode-map "\C-c\C-d" 'message-dont-send)
990 (define-key message-mode-map "\C-c\C-e" 'message-elide-region)
992 (define-key message-mode-map "\t" 'message-tab))
995 message-mode-menu message-mode-map "Message Menu."
997 ["Sort Headers" message-sort-headers t]
998 ["Yank Original" message-yank-original t]
999 ["Fill Yanked Message" message-fill-yanked-message t]
1000 ["Insert Signature" message-insert-signature t]
1001 ["Caesar (rot13) Message" message-caesar-buffer-body t]
1002 ["Caesar (rot13) Region" message-caesar-region (mark t)]
1003 ["Elide Region" message-elide-region (mark t)]
1004 ["Rename buffer" message-rename-buffer t]
1005 ["Spellcheck" ispell-message t]
1007 ["Send Message" message-send-and-exit t]
1008 ["Abort Message" message-dont-send t]))
1011 message-mode-field-menu message-mode-map ""
1013 ["Fetch To" message-insert-to t]
1014 ["Fetch Newsgroups" message-insert-newsgroups t]
1016 ["To" message-goto-to t]
1017 ["Subject" message-goto-subject t]
1018 ["Cc" message-goto-cc t]
1019 ["Reply-To" message-goto-reply-to t]
1020 ["Summary" message-goto-summary t]
1021 ["Keywords" message-goto-keywords t]
1022 ["Newsgroups" message-goto-newsgroups t]
1023 ["Followup-To" message-goto-followup-to t]
1024 ["Distribution" message-goto-distribution t]
1025 ["Body" message-goto-body t]
1026 ["Signature" message-goto-signature t]))
1028 (defvar facemenu-add-face-function)
1029 (defvar facemenu-remove-face-function)
1032 (defun message-mode ()
1033 "Major mode for editing mail and news to be sent.
1034 Like Text Mode but with these additional commands:
1035 C-c C-s message-send (send the message) C-c C-c message-send-and-exit
1036 C-c C-f move to a header field (and create it if there isn't):
1037 C-c C-f C-t move to To C-c C-f C-s move to Subject
1038 C-c C-f C-c move to Cc C-c C-f C-b move to Bcc
1039 C-c C-f C-w move to Fcc C-c C-f C-r move to Reply-To
1040 C-c C-f C-u move to Summary C-c C-f C-n move to Newsgroups
1041 C-c C-f C-k move to Keywords C-c C-f C-d move to Distribution
1042 C-c C-f C-f move to Followup-To
1043 C-c C-t message-insert-to (add a To header to a news followup)
1044 C-c C-n message-insert-newsgroups (add a Newsgroup header to a news reply)
1045 C-c C-b message-goto-body (move to beginning of message text).
1046 C-c C-i message-goto-signature (move to the beginning of the signature).
1047 C-c C-w message-insert-signature (insert `message-signature-file' file).
1048 C-c C-y message-yank-original (insert current message, if any).
1049 C-c C-q message-fill-yanked-message (fill what was yanked).
1050 C-c C-e message-elide-region (elide the text between point and mark).
1051 C-c C-r message-caesar-buffer-body (rot13 the message body)."
1053 (kill-all-local-variables)
1054 (make-local-variable 'message-reply-buffer)
1055 (setq message-reply-buffer nil)
1056 (set (make-local-variable 'message-send-actions) nil)
1057 (set (make-local-variable 'message-exit-actions) nil)
1058 (set (make-local-variable 'message-kill-actions) nil)
1059 (set (make-local-variable 'message-postpone-actions) nil)
1060 (set-syntax-table message-mode-syntax-table)
1061 (use-local-map message-mode-map)
1062 (setq local-abbrev-table message-mode-abbrev-table)
1063 (setq major-mode 'message-mode)
1064 (setq mode-name "Message")
1065 (setq buffer-offer-save t)
1066 (make-local-variable 'font-lock-defaults)
1067 (setq font-lock-defaults '(message-font-lock-keywords t))
1068 (make-local-variable 'facemenu-add-face-function)
1069 (make-local-variable 'facemenu-remove-face-function)
1070 (setq facemenu-add-face-function
1072 (let ((face-fun (cdr (assq face message-face-alist))))
1074 (funcall face-fun (point) end)
1075 (error "Face %s not configured for %s mode" face mode-name)))
1077 facemenu-remove-face-function t)
1078 (make-local-variable 'paragraph-separate)
1079 (make-local-variable 'paragraph-start)
1080 (setq paragraph-start (concat (regexp-quote mail-header-separator)
1081 "$\\|[ \t]*[-_][-_][-_]+$\\|"
1084 (setq paragraph-separate (concat (regexp-quote mail-header-separator)
1085 "$\\|[ \t]*[-_][-_][-_]+$\\|"
1087 paragraph-separate))
1088 (make-local-variable 'message-reply-headers)
1089 (setq message-reply-headers nil)
1090 (make-local-variable 'message-newsreader)
1091 (make-local-variable 'message-mailer)
1092 (make-local-variable 'message-post-method)
1093 (make-local-variable 'message-sent-message-via)
1094 (setq message-sent-message-via nil)
1095 (make-local-variable 'message-checksum)
1096 (setq message-checksum nil)
1097 ;;(when (fboundp 'mail-hist-define-keys)
1098 ;; (mail-hist-define-keys))
1099 (when (string-match "XEmacs\\|Lucid" emacs-version)
1100 (message-setup-toolbar))
1101 (easy-menu-add message-mode-menu message-mode-map)
1102 (easy-menu-add message-mode-field-menu message-mode-map)
1103 ;; Allow mail alias things.
1104 (if (fboundp 'mail-abbrevs-setup)
1105 (mail-abbrevs-setup)
1106 (funcall (intern "mail-aliases-setup")))
1107 (run-hooks 'text-mode-hook 'message-mode-hook))
1112 ;;; Message mode commands
1115 ;;; Movement commands
1117 (defun message-goto-to ()
1118 "Move point to the To header."
1120 (message-position-on-field "To"))
1122 (defun message-goto-subject ()
1123 "Move point to the Subject header."
1125 (message-position-on-field "Subject"))
1127 (defun message-goto-cc ()
1128 "Move point to the Cc header."
1130 (message-position-on-field "Cc" "To"))
1132 (defun message-goto-bcc ()
1133 "Move point to the Bcc header."
1135 (message-position-on-field "Bcc" "Cc" "To"))
1137 (defun message-goto-fcc ()
1138 "Move point to the Fcc header."
1140 (message-position-on-field "Fcc" "To" "Newsgroups"))
1142 (defun message-goto-reply-to ()
1143 "Move point to the Reply-To header."
1145 (message-position-on-field "Reply-To" "Subject"))
1147 (defun message-goto-newsgroups ()
1148 "Move point to the Newsgroups header."
1150 (message-position-on-field "Newsgroups"))
1152 (defun message-goto-distribution ()
1153 "Move point to the Distribution header."
1155 (message-position-on-field "Distribution"))
1157 (defun message-goto-followup-to ()
1158 "Move point to the Followup-To header."
1160 (message-position-on-field "Followup-To" "Newsgroups"))
1162 (defun message-goto-keywords ()
1163 "Move point to the Keywords header."
1165 (message-position-on-field "Keywords" "Subject"))
1167 (defun message-goto-summary ()
1168 "Move point to the Summary header."
1170 (message-position-on-field "Summary" "Subject"))
1172 (defun message-goto-body ()
1173 "Move point to the beginning of the message body."
1175 (if (looking-at "[ \t]*\n") (expand-abbrev))
1176 (goto-char (point-min))
1177 (search-forward (concat "\n" mail-header-separator "\n") nil t))
1179 (defun message-goto-signature ()
1180 "Move point to the beginning of the message signature."
1182 (goto-char (point-min))
1183 (if (re-search-forward message-signature-separator nil t)
1185 (goto-char (point-max))))
1189 (defun message-insert-to ()
1190 "Insert a To header that points to the author of the article being replied to."
1192 (let ((co (message-fetch-field "courtesy-copies-to")))
1194 (equal (downcase co) "never"))
1195 (error "The user has requested not to have copies sent via mail")))
1196 (when (and (message-position-on-field "To")
1197 (mail-fetch-field "to")
1198 (not (string-match "\\` *\\'" (mail-fetch-field "to"))))
1200 (insert (or (message-fetch-reply-field "reply-to")
1201 (message-fetch-reply-field "from") "")))
1203 (defun message-insert-newsgroups ()
1204 "Insert the Newsgroups header from the article being replied to."
1206 (when (and (message-position-on-field "Newsgroups")
1207 (mail-fetch-field "newsgroups")
1208 (not (string-match "\\` *\\'" (mail-fetch-field "newsgroups"))))
1210 (insert (or (message-fetch-reply-field "newsgroups") "")))
1214 ;;; Various commands
1216 (defun message-insert-signature (&optional force)
1217 "Insert a signature. See documentation for the `message-signature' variable."
1218 (interactive (list 0))
1221 ((and (null message-signature)
1224 (goto-char (point-max))
1225 (not (re-search-backward
1226 message-signature-separator nil t))))
1227 ((and (null message-signature)
1230 ((message-functionp message-signature)
1231 (funcall message-signature))
1232 ((listp message-signature)
1233 (eval message-signature))
1234 (t message-signature)))
1236 (cond ((stringp signature)
1238 ((and (eq t signature)
1239 message-signature-file
1240 (file-exists-p message-signature-file))
1243 (goto-char (point-max))
1244 ;; Insert the signature.
1248 (if (eq signature t)
1249 (insert-file-contents message-signature-file)
1251 (goto-char (point-max))
1252 (or (bolp) (insert "\n")))))
1254 (defun message-elide-region (b e)
1255 "Elide the text between point and mark. An ellipsis (from
1256 message-elide-elipsis) will be inserted where the text was killed."
1261 (insert message-elide-elipsis))
1263 (defvar message-caesar-translation-table nil)
1265 (defun message-caesar-region (b e &optional n)
1266 "Caesar rotation of region by N, default 13, for decrypting netnews."
1269 (min (point) (or (mark t) (point)))
1270 (max (point) (or (mark t) (point)))
1271 (when current-prefix-arg
1272 (prefix-numeric-value current-prefix-arg))))
1274 (setq n (if (numberp n) (mod n 26) 13)) ;canonize N
1275 (unless (or (zerop n) ; no action needed for a rot of 0
1276 (= b e)) ; no region to rotate
1277 ;; We build the table, if necessary.
1278 (when (or (not message-caesar-translation-table)
1279 (/= (aref message-caesar-translation-table ?a) (+ ?a n)))
1281 (table (make-string 256 0)))
1282 (while (< (incf i) 256)
1286 (substring table 0 ?A)
1287 (substring table (+ ?A n) (+ ?A n (- 26 n)))
1288 (substring table ?A (+ ?A n))
1289 (substring table (+ ?A 26) ?a)
1290 (substring table (+ ?a n) (+ ?a n (- 26 n)))
1291 (substring table ?a (+ ?a n))
1292 (substring table (+ ?a 26) 255)))
1293 (setq message-caesar-translation-table table)))
1294 ;; Then we translate the region. Do it this way to retain
1297 (subst-char-in-region
1298 b (1+ b) (char-after b)
1299 (aref message-caesar-translation-table (char-after b)))
1302 (defun message-caesar-buffer-body (&optional rotnum)
1303 "Caesar rotates all letters in the current buffer by 13 places.
1304 Used to encode/decode possibly offensive messages (commonly in net.jokes).
1305 With prefix arg, specifies the number of places to rotate each letter forward.
1306 Mail and USENET news headers are not rotated."
1307 (interactive (if current-prefix-arg
1308 (list (prefix-numeric-value current-prefix-arg))
1312 (when (message-goto-body)
1313 (narrow-to-region (point) (point-max)))
1314 (message-caesar-region (point-min) (point-max) rotnum))))
1316 (defun message-pipe-buffer-body (program)
1317 "Pipe the message body in the current buffer through PROGRAM."
1320 (when (message-goto-body)
1321 (narrow-to-region (point) (point-max)))
1322 (let ((body (buffer-substring (point-min) (point-max))))
1323 (unless (equal 0 (call-process-region
1324 (point-min) (point-max) program t t))
1326 (gnus-message 1 "%s failed." program))))))
1328 (defun message-rename-buffer (&optional enter-string)
1329 "Rename the *message* buffer to \"*message* RECIPIENT\".
1330 If the function is run with a prefix, it will ask for a new buffer
1331 name, rather than giving an automatic name."
1332 (interactive "Pbuffer name: ")
1335 (goto-char (point-min))
1336 (narrow-to-region (point)
1337 (search-forward mail-header-separator nil 'end))
1339 (if (message-news-p) (message-fetch-field "Newsgroups")
1340 (message-fetch-field "To"))
1343 (if (string-match "," mail-to)
1344 (concat (substring mail-to 0 (match-beginning 0)) ", ...")
1346 (name-default (concat "*message* " mail-trimmed-to))
1347 (name (if enter-string
1348 (read-string "New buffer name: " name-default)
1351 (file-name-as-directory message-autosave-directory)))
1352 (rename-buffer name t)))))
1354 (defun message-fill-yanked-message (&optional justifyp)
1355 "Fill the paragraphs of a message yanked into this one.
1356 Numeric argument means justify as well."
1359 (goto-char (point-min))
1360 (search-forward (concat "\n" mail-header-separator "\n") nil t)
1361 (let ((fill-prefix message-yank-prefix))
1362 (fill-individual-paragraphs (point) (point-max) justifyp t))))
1364 (defun message-indent-citation ()
1365 "Modify text just inserted from a message to be cited.
1366 The inserted text should be the region.
1367 When this function returns, the region is again around the modified text.
1369 Normally, indent each nonblank line `message-indentation-spaces' spaces.
1370 However, if `message-yank-prefix' is non-nil, insert that prefix on each line."
1371 (let ((start (point)))
1372 ;; Remove unwanted headers.
1373 (when message-ignored-cited-headers
1377 (if (search-forward "\n\n" nil t)
1380 (message-remove-header message-ignored-cited-headers t)
1381 (goto-char (point-max))))
1382 ;; Delete blank lines at the start of the buffer.
1383 (while (and (point-min)
1386 (message-delete-line))
1387 ;; Delete blank lines at the end of the buffer.
1388 (goto-char (point-max))
1391 (while (and (zerop (forward-line -1))
1393 (message-delete-line))
1394 ;; Do the indentation.
1395 (if (null message-yank-prefix)
1396 (indent-rigidly start (mark t) message-indentation-spaces)
1399 (while (< (point) (mark t))
1400 (insert message-yank-prefix)
1404 (defun message-yank-original (&optional arg)
1405 "Insert the message being replied to, if any.
1406 Puts point before the text and mark after.
1407 Normally indents each nonblank line ARG spaces (default 3). However,
1408 if `message-yank-prefix' is non-nil, insert that prefix on each line.
1410 This function uses `message-cite-function' to do the actual citing.
1412 Just \\[universal-argument] as argument means don't indent, insert no
1413 prefix, and don't delete any headers."
1415 (let ((modified (buffer-modified-p)))
1416 (when (and message-reply-buffer
1417 message-cite-function)
1418 (delete-windows-on message-reply-buffer t)
1419 (insert-buffer message-reply-buffer)
1420 (funcall message-cite-function)
1421 (message-exchange-point-and-mark)
1425 (setq message-checksum (cons (message-checksum) (buffer-size)))))))
1427 (defun message-cite-original ()
1428 "Cite function in the standard Message manner."
1429 (let ((start (point))
1431 (when message-indent-citation-function
1432 (if (listp message-indent-citation-function)
1433 message-indent-citation-function
1434 (list message-indent-citation-function)))))
1437 (funcall (pop functions)))
1438 (when message-citation-line-function
1441 (funcall message-citation-line-function))))
1443 (defun message-insert-citation-line ()
1444 "Function that inserts a simple citation line."
1445 (when message-reply-headers
1446 (insert (mail-header-from message-reply-headers) " writes:\n\n")))
1448 (defun message-position-on-field (header &rest afters)
1449 (let ((case-fold-search t))
1452 (goto-char (point-min))
1455 (concat "^" (regexp-quote mail-header-separator) "$"))
1456 (match-beginning 0)))
1457 (goto-char (point-min))
1458 (if (re-search-forward (concat "^" (regexp-quote header) ":") nil t)
1460 (re-search-forward "^[^ \t]" nil 'move)
1462 (skip-chars-backward "\n")
1465 (not (re-search-forward
1466 (concat "^" (regexp-quote (car afters)) ":")
1470 (re-search-forward "^[^ \t]" nil 'move)
1471 (beginning-of-line))
1472 (insert header ": \n")
1476 (defun message-remove-signature ()
1477 "Remove the signature from the text between point and mark.
1478 The text will also be indented the normal way."
1480 (let ((start (point))
1482 (if (not (re-search-forward message-signature-separator (mark t) t))
1483 ;; No signature here, so we just indent the cited text.
1484 (message-indent-citation)
1485 ;; Find the last non-empty line.
1487 (while (looking-at "[ \t]*$")
1490 (setq mark (set-marker (make-marker) (point)))
1492 (message-indent-citation)
1493 ;; Enable undoing the deletion.
1495 (delete-region mark (mark t))
1496 (set-marker mark nil)))))
1501 ;;; Sending messages
1504 (defun message-send-and-exit (&optional arg)
1505 "Send message like `message-send', then, if no errors, exit from mail buffer."
1507 (let ((buf (current-buffer))
1508 (actions message-exit-actions))
1509 (when (and (message-send arg)
1511 (if message-kill-buffer-on-exit
1514 (when (eq buf (current-buffer))
1515 (message-bury buf)))
1516 (message-do-actions actions))))
1518 (defun message-dont-send ()
1519 "Don't send the message you have been editing."
1521 (let ((actions message-postpone-actions))
1522 (message-bury (current-buffer))
1523 (message-do-actions actions)))
1525 (defun message-kill-buffer ()
1526 "Kill the current buffer."
1528 (let ((actions message-kill-actions))
1529 (kill-buffer (current-buffer))
1530 (message-do-actions actions)))
1532 (defun message-bury (buffer)
1533 "Bury this mail buffer."
1534 (let ((newbuf (other-buffer buffer)))
1535 (bury-buffer buffer)
1536 (if (and (fboundp 'frame-parameters)
1537 (cdr (assq 'dedicated (frame-parameters)))
1538 (not (null (delq (selected-frame) (visible-frame-list)))))
1539 (delete-frame (selected-frame))
1540 (switch-to-buffer newbuf))))
1542 (defun message-send (&optional arg)
1543 "Send the message in the current buffer.
1544 If `message-interactive' is non-nil, wait for success indication
1545 or error messages, and inform user.
1546 Otherwise any failure is reported in a message back to
1547 the user from the mailer."
1549 (when (if buffer-file-name
1550 (y-or-n-p (format "Send buffer contents as %s message? "
1551 (if (message-mail-p)
1552 (if (message-news-p) "mail and news" "mail")
1554 (or (buffer-modified-p)
1555 (y-or-n-p "No changes in the buffer; really send? ")))
1556 ;; Make it possible to undo the coming changes.
1558 (let ((inhibit-read-only t))
1559 (put-text-property (point-min) (point-max) 'read-only nil))
1560 (message-fix-before-sending)
1561 (run-hooks 'message-send-hook)
1562 (message "Sending...")
1563 (when (and (or (not (message-news-p))
1564 (and (or (not (memq 'news message-sent-message-via))
1566 "Already sent message via news; resend? "))
1567 (funcall message-send-news-function arg)))
1568 (or (not (message-mail-p))
1569 (and (or (not (memq 'mail message-sent-message-via))
1571 "Already sent message via mail; resend? "))
1572 (message-send-mail arg))))
1574 ;;(when (fboundp 'mail-hist-put-headers-into-history)
1575 ;; (mail-hist-put-headers-into-history))
1576 (run-hooks 'message-sent-hook)
1577 (message "Sending...done")
1578 ;; If buffer has no file, mark it as unmodified and delete autosave.
1579 (unless buffer-file-name
1580 (set-buffer-modified-p nil)
1581 (delete-auto-save-file-if-necessary t))
1582 ;; Delete other mail buffers and stuff.
1583 (message-do-send-housekeeping)
1584 (message-do-actions message-send-actions)
1588 (defun message-fix-before-sending ()
1589 "Do various things to make the message nice before sending it."
1590 ;; Make sure there's a newline at the end of the message.
1591 (goto-char (point-max))
1595 (defun message-add-action (action &rest types)
1596 "Add ACTION to be performed when doing an exit of type TYPES."
1599 (set (setq var (intern (format "message-%s-actions" (pop types))))
1600 (nconc (symbol-value var) (list action))))))
1602 (defun message-do-actions (actions)
1603 "Perform all actions in ACTIONS."
1604 ;; Now perform actions on successful sending.
1608 ;; A simple function.
1609 ((message-functionp (car actions))
1610 (funcall (car actions)))
1611 ;; Something to be evaled.
1613 (eval (car actions)))))
1616 (defun message-send-mail (&optional arg)
1617 (require 'mail-utils)
1618 (let ((tembuf (message-generate-new-buffer-clone-locals " message temp"))
1619 (case-fold-search nil)
1620 (news (message-news-p))
1621 (mailbuf (current-buffer)))
1623 (message-narrow-to-headers)
1624 ;; Insert some headers.
1625 (let ((message-deletable-headers
1626 (if news nil message-deletable-headers)))
1627 (message-generate-headers message-required-mail-headers))
1628 ;; Let the user do all of the above.
1629 (run-hooks 'message-header-hook))
1634 ;; Avoid copying text props.
1636 "%s" (save-excursion
1637 (set-buffer mailbuf)
1639 ;; Remove some headers.
1641 (message-narrow-to-headers)
1642 ;; Remove some headers.
1643 (message-remove-header message-ignored-mail-headers t))
1644 (goto-char (point-max))
1645 ;; require one newline at the end.
1646 (or (= (preceding-char) ?\n)
1649 (or (message-fetch-field "cc")
1650 (message-fetch-field "to")))
1651 (message-insert-courtesy-copy))
1652 (funcall message-send-mail-function))
1653 (kill-buffer tembuf))
1654 (set-buffer mailbuf)
1655 (push 'mail message-sent-message-via)))
1657 (defun message-send-mail-with-sendmail ()
1658 "Send off the prepared buffer with sendmail."
1659 (let ((errbuf (if message-interactive
1660 (generate-new-buffer " sendmail errors")
1662 resend-to-addresses delimline)
1663 (let ((case-fold-search t))
1665 (message-narrow-to-headers)
1666 (setq resend-to-addresses (message-fetch-field "resent-to")))
1667 ;; Change header-delimiter to be what sendmail expects.
1668 (goto-char (point-min))
1670 (concat "^" (regexp-quote mail-header-separator) "\n"))
1671 (replace-match "\n")
1673 (setq delimline (point-marker))
1674 (run-hooks 'message-send-mail-hook)
1675 ;; Insert an extra newline if we need it to work around
1676 ;; Sun's bug that swallows newlines.
1677 (goto-char (1+ delimline))
1678 (when (eval message-mailer-swallows-blank-line)
1680 (when message-interactive
1684 (let ((default-directory "/"))
1685 (apply 'call-process-region
1686 (append (list (point-min) (point-max)
1687 (if (boundp 'sendmail-program)
1689 "/usr/lib/sendmail")
1690 nil errbuf nil "-oi")
1691 ;; Always specify who from,
1692 ;; since some systems have broken sendmails.
1693 ;; But some systems are more broken with -f, so
1694 ;; we'll let users override this.
1695 (if (null message-sendmail-f-is-evil)
1696 (list "-f" (user-login-name)))
1697 ;; These mean "report errors by mail"
1698 ;; and "deliver in background".
1699 (if (null message-interactive) '("-oem" "-odb"))
1700 ;; Get the addresses from the message
1701 ;; unless this is a resend.
1702 ;; We must not do that for a resend
1703 ;; because we would find the original addresses.
1704 ;; For a resend, include the specific addresses.
1705 (if resend-to-addresses
1706 (list resend-to-addresses)
1708 (when message-interactive
1711 (goto-char (point-min))
1712 (while (re-search-forward "\n\n* *" nil t)
1713 (replace-match "; "))
1714 (if (not (zerop (buffer-size)))
1715 (error "Sending...failed to %s"
1716 (buffer-substring (point-min) (point-max)))))
1717 (when (bufferp errbuf)
1718 (kill-buffer errbuf)))))
1720 (defun message-send-mail-with-qmail ()
1721 "Pass the prepared message buffer to qmail-inject.
1722 Refer to the documentation for the variable `message-send-mail-function'
1723 to find out how to use this."
1724 ;; replace the header delimiter with a blank line
1725 (goto-char (point-min))
1727 (concat "^" (regexp-quote mail-header-separator) "\n"))
1728 (replace-match "\n")
1729 (run-hooks 'message-send-mail-hook)
1733 'call-process-region 1 (point-max) message-qmail-inject-program
1735 ;; qmail-inject's default behaviour is to look for addresses on the
1736 ;; command line; if there're none, it scans the headers.
1737 ;; yes, it does The Right Thing w.r.t. Resent-To and it's kin.
1739 ;; in general, ALL of qmail-inject's defaults are perfect for simply
1740 ;; reading a formatted (i. e., at least a To: or Resent-To header)
1741 ;; message from stdin.
1743 ;; qmail also has the advantage of not having been raped by
1744 ;; various vendors, so we don't have to allow for that, either --
1745 ;; compare this with message-send-mail-with-sendmail and weep
1746 ;; for sendmail's lost innocence.
1748 ;; all this is way cool coz it lets us keep the arguments entirely
1749 ;; free for -inject-arguments -- a big win for the user and for us
1750 ;; since we don't have to play that double-guessing game and the user
1751 ;; gets full control (no gestapo'ish -f's, for instance). --sj
1752 message-qmail-inject-args)
1753 ;; qmail-inject doesn't say anything on it's stdout/stderr,
1754 ;; we have to look at the retval instead
1756 (1 (error "qmail-inject reported permanent failure."))
1757 (111 (error "qmail-inject reported transient failure."))
1758 ;; should never happen
1759 (t (error "qmail-inject reported unknown failure."))))
1761 (defun message-send-mail-with-mh ()
1762 "Send the prepared message buffer with mh."
1763 (let ((mh-previous-window-config nil)
1764 (name (make-temp-name
1765 (concat (file-name-as-directory
1766 (expand-file-name message-autosave-directory))
1768 (setq buffer-file-name name)
1769 ;; MH wants to generate these headers itself.
1770 (when message-mh-deletable-headers
1771 (let ((headers message-mh-deletable-headers))
1773 (goto-char (point-min))
1774 (and (re-search-forward
1775 (concat "^" (symbol-name (car headers)) ": *") nil t)
1776 (message-delete-line))
1778 (run-hooks 'message-send-mail-hook)
1779 ;; Pass it on to mh.
1782 (defun message-send-news (&optional arg)
1783 (let ((tembuf (message-generate-new-buffer-clone-locals " *message temp*"))
1784 (case-fold-search nil)
1785 (method (if (message-functionp message-post-method)
1786 (funcall message-post-method arg)
1787 message-post-method))
1788 (messbuf (current-buffer))
1789 (message-syntax-checks
1791 (cons '(existing-newsgroups . disabled)
1792 message-syntax-checks)
1793 message-syntax-checks))
1796 (message-narrow-to-headers)
1797 ;; Insert some headers.
1798 (message-generate-headers message-required-news-headers)
1799 ;; Let the user do all of the above.
1800 (run-hooks 'message-header-hook))
1801 (message-cleanup-headers)
1802 (if (not (message-check-news-syntax))
1804 ;;(message "Posting not performed")
1809 (buffer-disable-undo (current-buffer))
1811 ;; Avoid copying text props.
1813 "%s" (save-excursion
1814 (set-buffer messbuf)
1816 ;; Remove some headers.
1818 (message-narrow-to-headers)
1819 ;; Remove some headers.
1820 (message-remove-header message-ignored-news-headers t))
1821 (goto-char (point-max))
1822 ;; require one newline at the end.
1823 (or (= (preceding-char) ?\n)
1825 (let ((case-fold-search t))
1826 ;; Remove the delimiter.
1827 (goto-char (point-min))
1829 (concat "^" (regexp-quote mail-header-separator) "\n"))
1830 (replace-match "\n")
1832 (run-hooks 'message-send-news-hook)
1833 (require (car method))
1834 (funcall (intern (format "%s-open-server" (car method)))
1835 (cadr method) (cddr method))
1837 (funcall (intern (format "%s-request-post" (car method))))))
1838 (kill-buffer tembuf))
1839 (set-buffer messbuf)
1841 (push 'news message-sent-message-via)
1842 (message "Couldn't send message via news: %s"
1843 (nnheader-get-report (car method)))
1847 ;;; Header generation & syntax checking.
1850 (defmacro message-check (type &rest forms)
1851 "Eval FORMS if TYPE is to be checked."
1852 `(or (message-check-element ,type)
1856 (put 'message-check 'lisp-indent-function 1)
1857 (put 'message-check 'edebug-form-spec '(form body))
1859 (defun message-check-element (type)
1860 "Returns non-nil if this type is not to be checked."
1861 (if (eq message-syntax-checks 'dont-check-for-anything-just-trust-me)
1863 (let ((able (assq type message-syntax-checks)))
1865 (eq (cdr able) 'disabled)))))
1867 (defun message-check-news-syntax ()
1868 "Check the syntax of the message."
1873 ;; We narrow to the headers and check them first.
1876 (message-narrow-to-headers)
1877 (message-check-news-header-syntax)))
1879 (message-check-news-body-syntax)))))
1881 (defun message-check-news-header-syntax ()
1883 ;; Check for commands in Subject.
1884 (message-check 'subject-cmsg
1885 (if (string-match "^cmsg " (message-fetch-field "subject"))
1887 "The control code \"cmsg\" is in the subject. Really post? ")
1889 ;; Check for multiple identical headers.
1890 (message-check 'multiple-headers
1892 (while (and (not found)
1893 (re-search-forward "^[^ \t:]+: " nil t))
1895 (or (re-search-forward
1900 (match-beginning 0) (- (match-end 0) 2))))
1905 (y-or-n-p (format "Multiple %s headers. Really post? " found))
1907 ;; Check for Version and Sendsys.
1908 (message-check 'sendsys
1909 (if (re-search-forward "^Sendsys:\\|^Version:" nil t)
1911 (format "The article contains a %s command. Really post? "
1912 (buffer-substring (match-beginning 0)
1913 (1- (match-end 0)))))
1915 ;; See whether we can shorten Followup-To.
1916 (message-check 'shorten-followup-to
1917 (let ((newsgroups (message-fetch-field "newsgroups"))
1918 (followup-to (message-fetch-field "followup-to"))
1920 (when (and newsgroups
1921 (string-match "," newsgroups)
1926 (setq to (completing-read
1927 "Followups to: (default all groups) "
1928 (mapcar (lambda (g) (list g))
1930 (message-tokenize-header
1932 (goto-char (point-min))
1933 (insert "Followup-To: " to "\n"))
1935 ;; Check "Shoot me".
1936 (message-check 'shoot
1937 (if (re-search-forward
1938 "Message-ID.*.i-did-not-set--mail-host-address--so-shoot-me" nil t)
1939 (y-or-n-p "You appear to have a misconfigured system. Really post? ")
1941 ;; Check for Approved.
1942 (message-check 'approved
1943 (if (re-search-forward "^Approved:" nil t)
1944 (y-or-n-p "The article contains an Approved header. Really post? ")
1946 ;; Check the Message-ID header.
1947 (message-check 'message-id
1948 (let* ((case-fold-search t)
1949 (message-id (message-fetch-field "message-id" t)))
1950 (or (not message-id)
1951 (and (string-match "@" message-id)
1952 (string-match "@[^\\.]*\\." message-id))
1954 (format "The Message-ID looks strange: \"%s\". Really post? "
1956 ;; Check the Subject header.
1957 (message-check 'subject
1958 (let* ((case-fold-search t)
1959 (subject (message-fetch-field "subject")))
1962 (not (string-match "\\`[ \t]*\\'" subject)))
1965 "The subject field is empty or missing. Posting is denied.")))))
1966 ;; Check the Newsgroups & Followup-To headers.
1967 (message-check 'existing-newsgroups
1968 (let* ((case-fold-search t)
1969 (newsgroups (message-fetch-field "newsgroups"))
1970 (followup-to (message-fetch-field "followup-to"))
1971 (groups (message-tokenize-header
1973 (concat newsgroups "," followup-to)
1975 (hashtb (and (boundp 'gnus-active-hashtb)
1976 gnus-active-hashtb))
1978 (if (or (not hashtb)
1979 (not (boundp 'gnus-read-active-file))
1980 (not gnus-read-active-file)
1981 (eq gnus-read-active-file 'some))
1984 (when (and (not (boundp (intern (car groups) hashtb)))
1985 (not (equal (car groups) "poster")))
1986 (push (car groups) errors))
1992 "Really post to %s unknown group%s: %s "
1993 (if (= (length errors) 1) "this" "these")
1994 (if (= (length errors) 1) "" "s")
1995 (mapconcat 'identity errors ", ")))))))
1996 ;; Check the Newsgroups & Followup-To headers for syntax errors.
1997 (message-check 'valid-newsgroups
1998 (let ((case-fold-search t)
1999 (headers '("Newsgroups" "Followup-To"))
2001 (while (and headers (not error))
2002 (when (setq header (mail-fetch-field (car headers)))
2006 "\\`\\([-+_&.a-zA-Z0-9]+\\)?\\(,[-+_&.a-zA-Z0-9]+\\)*\\'"
2011 (not (string-match "\\.\\'\\|\\.\\." g)))
2012 (message-tokenize-header header ","))))
2019 (format "The %s header looks odd: \"%s\". Really post? "
2020 (car headers) header)))))
2021 ;; Check the From header.
2022 (message-check 'from
2023 (let* ((case-fold-search t)
2024 (from (message-fetch-field "from"))
2025 (ad (nth 1 (mail-extract-address-components from))))
2028 (message "There is no From line. Posting is denied.")
2030 ((or (not (string-match "@[^\\.]*\\." ad)) ;larsi@ifi
2031 (string-match "\\.\\." ad) ;larsi@ifi..uio
2032 (string-match "@\\." ad) ;larsi@.ifi.uio
2033 (string-match "\\.$" ad) ;larsi@ifi.uio.
2034 (not (string-match "^[^@]+@[^@]+$" ad)) ;larsi.ifi.uio
2035 (string-match "(.*).*(.*)" from)) ;(lars) (lars)
2037 "Denied posting -- the From looks strange: \"%s\"." from)
2041 (defun message-check-news-body-syntax ()
2043 ;; Check for long lines.
2044 (message-check 'long-lines
2045 (goto-char (point-min))
2047 (concat "^" (regexp-quote mail-header-separator) "$"))
2051 (< (current-column) 80))
2052 (zerop (forward-line 1))))
2056 "You have lines longer than 79 characters. Really post? ")))
2057 ;; Check whether the article is empty.
2058 (message-check 'empty
2059 (goto-char (point-min))
2061 (concat "^" (regexp-quote mail-header-separator) "$"))
2064 (goto-char (point-max))
2065 (re-search-backward message-signature-separator nil t)
2067 (or (re-search-backward "[^ \n\t]" b t)
2068 (y-or-n-p "Empty article. Really post? "))))
2069 ;; Check for control characters.
2070 (message-check 'control-chars
2071 (if (re-search-forward "[\000-\007\013\015-\037\200-\237]" nil t)
2073 "The article contains control characters. Really post? ")
2075 ;; Check excessive size.
2076 (message-check 'size
2077 (if (> (buffer-size) 60000)
2079 (format "The article is %d octets long. Really post? "
2082 ;; Check whether any new text has been added.
2083 (message-check 'new-text
2085 (not message-checksum)
2086 (not (and (eq (message-checksum) (car message-checksum))
2087 (eq (buffer-size) (cdr message-checksum))))
2089 "It looks like no new text has been added. Really post? ")))
2090 ;; Check the length of the signature.
2091 (message-check 'signature
2092 (goto-char (point-max))
2093 (if (or (not (re-search-backward message-signature-separator nil t))
2094 (search-forward message-forward-end-separator nil t))
2096 (if (> (count-lines (point) (point-max)) 5)
2099 "Your .sig is %d lines; it should be max 4. Really post? "
2100 (1- (count-lines (point) (point-max)))))
2103 (defun message-checksum ()
2104 "Return a \"checksum\" for the current buffer."
2107 (goto-char (point-min))
2109 (concat "^" (regexp-quote mail-header-separator) "$"))
2111 (when (not (looking-at "[ \t\n]"))
2112 (setq sum (logxor (ash sum 1) (following-char))))
2116 (defun message-do-fcc ()
2117 "Process Fcc headers in the current buffer."
2118 (let ((case-fold-search t)
2119 (buf (current-buffer))
2122 (set-buffer (get-buffer-create " *message temp*"))
2123 (buffer-disable-undo (current-buffer))
2125 (insert-buffer-substring buf)
2127 (message-narrow-to-headers)
2128 (while (setq file (message-fetch-field "fcc"))
2130 (message-remove-header "fcc" nil t)))
2131 (goto-char (point-min))
2132 (re-search-forward (concat "^" (regexp-quote mail-header-separator) "$"))
2133 (replace-match "" t t)
2134 ;; Process FCC operations.
2136 (setq file (pop list))
2137 (if (string-match "^[ \t]*|[ \t]*\\(.*\\)[ \t]*$" file)
2138 ;; Pipe the article to the program in question.
2139 (call-process-region (point-min) (point-max) shell-file-name
2140 nil nil nil shell-command-switch
2141 (match-string 1 file))
2142 ;; Save the article.
2143 (setq file (expand-file-name file))
2144 (unless (file-exists-p (file-name-directory file))
2145 (make-directory (file-name-directory file) t))
2146 (if (and message-fcc-handler-function
2147 (not (eq message-fcc-handler-function 'rmail-output)))
2148 (funcall message-fcc-handler-function file)
2149 (if (and (file-readable-p file) (mail-file-babyl-p file))
2150 (rmail-output file 1 nil t)
2151 (let ((mail-use-rfc822 t))
2152 (rmail-output file 1 t t))))))
2154 (kill-buffer (current-buffer)))))
2156 (defun message-output (filename)
2157 "Append this article to Unix/babyl mail file.."
2158 (if (and (file-readable-p filename)
2159 (mail-file-babyl-p filename))
2160 (gnus-output-to-rmail filename t)
2161 (gnus-output-to-mail filename t)))
2163 (defun message-cleanup-headers ()
2164 "Do various automatic cleanups of the headers."
2165 ;; Remove empty lines in the header.
2167 (message-narrow-to-headers)
2168 (while (re-search-forward "^[ \t]*\n" nil t)
2169 (replace-match "" t t)))
2171 ;; Correct Newsgroups and Followup-To headers: change sequence of
2172 ;; spaces to comma and eliminate spaces around commas. Eliminate
2173 ;; embedded line breaks.
2174 (goto-char (point-min))
2175 (while (re-search-forward "^\\(Newsgroups\\|Followup-To\\): +" nil t)
2179 (if (re-search-forward "^[^ \t]" nil t)
2183 (goto-char (point-min))
2184 (while (re-search-forward "\n[ \t]+" nil t)
2185 (replace-match " " t t)) ;No line breaks (too confusing)
2186 (goto-char (point-min))
2187 (while (re-search-forward "[ \t\n]*,[ \t\n]*\\|[ \t]+" nil t)
2188 (replace-match "," t t))
2189 (goto-char (point-min))
2190 ;; Remove trailing commas.
2191 (when (re-search-forward ",+$" nil t)
2192 (replace-match "" t t)))))
2194 (defun message-make-date ()
2195 "Make a valid data header."
2196 (let ((now (current-time)))
2197 (timezone-make-date-arpa-standard
2198 (current-time-string now) (current-time-zone now))))
2200 (defun message-make-message-id ()
2201 "Make a unique Message-ID."
2202 (concat "<" (message-unique-id)
2203 (let ((psubject (save-excursion (message-fetch-field "subject"))))
2204 (if (and message-reply-headers
2205 (mail-header-references message-reply-headers)
2206 (mail-header-subject message-reply-headers)
2208 (mail-header-subject message-reply-headers)
2210 (message-strip-subject-re
2211 (mail-header-subject message-reply-headers))
2212 (message-strip-subject-re psubject))))
2214 "@" (message-make-fqdn) ">"))
2216 (defvar message-unique-id-char nil)
2218 ;; If you ever change this function, make sure the new version
2219 ;; cannot generate IDs that the old version could.
2220 ;; You might for example insert a "." somewhere (not next to another dot
2221 ;; or string boundary), or modify the "fsf" string.
2222 (defun message-unique-id ()
2223 ;; Don't use microseconds from (current-time), they may be unsupported.
2224 ;; Instead we use this randomly inited counter.
2225 (setq message-unique-id-char
2226 (% (1+ (or message-unique-id-char (logand (random t) (1- (lsh 1 20)))))
2227 ;; (current-time) returns 16-bit ints,
2228 ;; and 2^16*25 just fits into 4 digits i base 36.
2230 (let ((tm (current-time)))
2232 (if (memq system-type '(ms-dos emx vax-vms))
2233 (let ((user (downcase (user-login-name))))
2234 (while (string-match "[^a-z0-9_]" user)
2235 (aset user (match-beginning 0) ?_))
2237 (message-number-base36 (user-uid) -1))
2238 (message-number-base36 (+ (car tm)
2239 (lsh (% message-unique-id-char 25) 16)) 4)
2240 (message-number-base36 (+ (nth 1 tm)
2241 (lsh (/ message-unique-id-char 25) 16)) 4)
2242 ;; Append the newsreader name, because while the generated
2243 ;; ID is unique to this newsreader, other newsreaders might
2244 ;; otherwise generate the same ID via another algorithm.
2247 (defun message-number-base36 (num len)
2248 (if (if (< len 0) (<= num 0) (= len 0))
2250 (concat (message-number-base36 (/ num 36) (1- len))
2251 (char-to-string (aref "zyxwvutsrqponmlkjihgfedcba9876543210"
2254 (defun message-make-organization ()
2255 "Make an Organization header."
2256 (let* ((organization
2257 (or (getenv "ORGANIZATION")
2258 (when message-user-organization
2259 (if (message-functionp message-user-organization)
2260 (funcall message-user-organization)
2261 message-user-organization)))))
2263 (message-set-work-buffer)
2264 (cond ((stringp organization)
2265 (insert organization))
2266 ((and (eq t organization)
2267 message-user-organization-file
2268 (file-exists-p message-user-organization-file))
2269 (insert-file-contents message-user-organization-file)))
2270 (goto-char (point-min))
2271 (while (re-search-forward "[\t\n]+" nil t)
2272 (replace-match "" t t))
2273 (unless (zerop (buffer-size))
2276 (defun message-make-lines ()
2277 "Count the number of lines and return numeric string."
2281 (goto-char (point-min))
2283 (concat "^" (regexp-quote mail-header-separator) "$"))
2285 (int-to-string (count-lines (point) (point-max))))))
2287 (defun message-make-in-reply-to ()
2288 "Return the In-Reply-To header for this message."
2289 (when message-reply-headers
2290 (let ((from (mail-header-from message-reply-headers))
2291 (date (mail-header-date message-reply-headers)))
2294 (string-match " *at \\| *@ \\| *(\\| *<" from)))
2295 (concat (if stop-pos (substring from 0 stop-pos) from)
2297 (if (or (not date) (string= date ""))
2298 "(unknown date)" date)))))))
2300 (defun message-make-distribution ()
2301 "Make a Distribution header."
2302 (let ((orig-distribution (message-fetch-reply-field "distribution")))
2303 (cond ((message-functionp message-distribution-function)
2304 (funcall message-distribution-function))
2305 (t orig-distribution))))
2307 (defun message-make-expires ()
2308 "Return an Expires header based on `message-expires'."
2309 (let ((current (current-time))
2310 (future (* 1.0 message-expires 60 60 24)))
2311 ;; Add the future to current.
2312 (setcar current (+ (car current) (round (/ future (expt 2 16)))))
2313 (setcar (cdr current) (+ (nth 1 current) (% (round future) (expt 2 16))))
2314 ;; Return the date in the future in UT.
2315 (timezone-make-date-arpa-standard
2316 (current-time-string current) (current-time-zone current) '(0 "UT"))))
2318 (defun message-make-path ()
2320 (let ((login-name (user-login-name)))
2321 (cond ((null message-user-path)
2322 (concat (system-name) "!" login-name))
2323 ((stringp message-user-path)
2324 ;; Support GENERICPATH. Suggested by vixie@decwrl.dec.com.
2325 (concat message-user-path "!" login-name))
2328 (defun message-make-from ()
2329 "Make a From header."
2330 (let* ((login (message-make-address))
2332 (or (and (boundp 'user-full-name)
2335 (when (string= fullname "&")
2336 (setq fullname (user-login-name)))
2338 (message-set-work-buffer)
2340 ((or (null message-from-style)
2341 (equal fullname ""))
2343 ((or (eq message-from-style 'angles)
2344 (and (not (eq message-from-style 'parens))
2345 ;; Use angles if no quoting is needed, or if parens would
2346 ;; need quoting too.
2347 (or (not (string-match "[^- !#-'*+/-9=?A-Z^-~]" fullname))
2348 (let ((tmp (concat fullname nil)))
2349 (while (string-match "([^()]*)" tmp)
2350 (aset tmp (match-beginning 0) ?-)
2351 (aset tmp (1- (match-end 0)) ?-))
2352 (string-match "[\\()]" tmp)))))
2354 (goto-char (point-min))
2355 ;; Look for a character that cannot appear unquoted
2356 ;; according to RFC 822.
2357 (when (re-search-forward "[^- !#-'*+/-9=?A-Z^-~]" nil 1)
2358 ;; Quote fullname, escaping specials.
2359 (goto-char (point-min))
2361 (while (re-search-forward "[\"\\]" nil 1)
2362 (replace-match "\\\\\\&" t))
2364 (insert " <" login ">"))
2365 (t ; 'parens or default
2367 (let ((fullname-start (point)))
2369 (goto-char fullname-start)
2370 ;; RFC 822 says \ and nonmatching parentheses
2371 ;; must be escaped in comments.
2372 ;; Escape every instance of ()\ ...
2373 (while (re-search-forward "[()\\]" nil 1)
2374 (replace-match "\\\\\\&" t))
2375 ;; ... then undo escaping of matching parentheses,
2376 ;; including matching nested parentheses.
2377 (goto-char fullname-start)
2378 (while (re-search-forward
2379 "\\(\\=\\|[^\\]\\(\\\\\\\\\\)*\\)\\\\(\\(\\([^\\]\\|\\\\\\\\\\)*\\)\\\\)"
2381 (replace-match "\\1(\\3)" t)
2382 (goto-char fullname-start)))
2386 (defun message-make-sender ()
2387 "Return the \"real\" user address.
2388 This function tries to ignore all user modifications, and
2389 give as trustworthy answer as possible."
2390 (concat (user-login-name) "@" (system-name)))
2392 (defun message-make-address ()
2393 "Make the address of the user."
2394 (or (message-user-mail-address)
2395 (concat (user-login-name) "@" (message-make-domain))))
2397 (defun message-user-mail-address ()
2398 "Return the pertinent part of `user-mail-address'."
2399 (when user-mail-address
2400 (if (string-match " " user-mail-address)
2401 (nth 1 (mail-extract-address-components user-mail-address))
2402 user-mail-address)))
2404 (defun message-make-fqdn ()
2405 "Return user's fully qualified domain name."
2406 (let ((system-name (system-name))
2407 (user-mail (message-user-mail-address)))
2409 ((string-match "[^.]\\.[^.]" system-name)
2410 ;; `system-name' returned the right result.
2412 ;; Try `mail-host-address'.
2413 ((and (boundp 'mail-host-address)
2414 (stringp mail-host-address)
2415 (string-match "\\." mail-host-address))
2417 ;; We try `user-mail-address' as a backup.
2418 ((and (string-match "\\." user-mail)
2419 (string-match "@\\(.*\\)\\'" user-mail))
2420 (match-string 1 user-mail))
2421 ;; Default to this bogus thing.
2423 (concat system-name ".i-did-not-set--mail-host-address--so-shoot-me")))))
2425 (defun message-make-host-name ()
2426 "Return the name of the host."
2427 (let ((fqdn (message-make-fqdn)))
2428 (string-match "^[^.]+\\." fqdn)
2429 (substring fqdn 0 (1- (match-end 0)))))
2431 (defun message-make-domain ()
2432 "Return the domain name."
2433 (or mail-host-address
2434 (message-make-fqdn)))
2436 (defun message-generate-headers (headers)
2437 "Prepare article HEADERS.
2438 Headers already prepared in the buffer are not modified."
2440 (message-narrow-to-headers)
2441 (let* ((Date (message-make-date))
2442 (Message-ID (message-make-message-id))
2443 (Organization (message-make-organization))
2444 (From (message-make-from))
2445 (Path (message-make-path))
2448 (In-Reply-To (message-make-in-reply-to))
2450 (Distribution (message-make-distribution))
2451 (Lines (message-make-lines))
2452 (X-Newsreader message-newsreader)
2453 (X-Mailer (and (not (message-fetch-field "X-Newsreader"))
2455 (Expires (message-make-expires))
2456 (case-fold-search t)
2458 ;; First we remove any old generated headers.
2459 (let ((headers message-deletable-headers))
2461 (goto-char (point-min))
2462 (and (re-search-forward
2463 (concat "^" (symbol-name (car headers)) ": *") nil t)
2464 (get-text-property (1+ (match-beginning 0)) 'message-deletable)
2465 (message-delete-line))
2467 ;; Go through all the required headers and see if they are in the
2468 ;; articles already. If they are not, or are empty, they are
2469 ;; inserted automatically - except for Subject, Newsgroups and
2472 (goto-char (point-min))
2473 (setq elem (pop headers))
2475 (if (eq (car elem) 'optional)
2476 (setq header (cdr elem))
2477 (setq header (car elem)))
2479 (when (or (not (re-search-forward
2480 (concat "^" (downcase (symbol-name header)) ":")
2483 ;; The header was found. We insert a space after the
2484 ;; colon, if there is none.
2485 (if (/= (following-char) ? ) (insert " ") (forward-char 1))
2486 ;; Find out whether the header is empty...
2487 (looking-at "[ \t]*$")))
2488 ;; So we find out what value we should insert.
2491 ((and (consp elem) (eq (car elem) 'optional))
2492 ;; This is an optional header. If the cdr of this
2493 ;; is something that is nil, then we do not insert
2495 (setq header (cdr elem))
2496 (or (and (fboundp (cdr elem)) (funcall (cdr elem)))
2497 (and (boundp (cdr elem)) (symbol-value (cdr elem)))))
2499 ;; The element is a cons. Either the cdr is a
2500 ;; string to be inserted verbatim, or it is a
2501 ;; function, and we insert the value returned from
2503 (or (and (stringp (cdr elem)) (cdr elem))
2504 (and (fboundp (cdr elem)) (funcall (cdr elem)))))
2505 ((and (boundp header) (symbol-value header))
2506 ;; The element is a symbol. We insert the value
2507 ;; of this symbol, if any.
2508 (symbol-value header))
2510 ;; We couldn't generate a value for this header,
2511 ;; so we just ask the user.
2512 (read-from-minibuffer
2513 (format "Empty header for %s; enter value: " header)))))
2514 ;; Finally insert the header.
2516 (not (equal value "")))
2520 ;; This header didn't exist, so we insert it.
2521 (goto-char (point-max))
2522 (insert (symbol-name header) ": " value "\n")
2524 ;; The value of this header was empty, so we clear
2525 ;; totally and insert the new value.
2526 (delete-region (point) (message-point-at-eol))
2528 ;; Add the deletable property to the headers that require it.
2529 (and (memq header message-deletable-headers)
2530 (progn (beginning-of-line) (looking-at "[^:]+: "))
2531 (add-text-properties
2532 (point) (match-end 0)
2533 '(message-deletable t face italic) (current-buffer)))))))
2534 ;; Insert new Sender if the From is strange.
2535 (let ((from (message-fetch-field "from"))
2536 (sender (message-fetch-field "sender"))
2537 (secure-sender (message-make-sender)))
2539 (not (message-check-element 'sender))
2542 (cadr (mail-extract-address-components from)))
2543 (downcase secure-sender)))
2548 (cadr (mail-extract-address-components sender)))
2549 (downcase secure-sender)))))
2550 (goto-char (point-min))
2551 ;; Rename any old Sender headers to Original-Sender.
2552 (when (re-search-forward "^\\(Original-\\)*Sender:" nil t)
2554 (insert "Original-")
2555 (beginning-of-line))
2556 (insert "Sender: " secure-sender "\n"))))))
2558 (defun message-insert-courtesy-copy ()
2559 "Insert a courtesy message in mail copies of combined messages."
2563 (message-narrow-to-headers)
2564 (when (setq newsgroups (message-fetch-field "newsgroups"))
2565 (goto-char (point-max))
2566 (insert "Posted-To: " newsgroups "\n")))
2568 (when message-courtesy-message
2570 ((string-match "%s" message-courtesy-message)
2571 (insert (format message-courtesy-message newsgroups)))
2573 (insert message-courtesy-message)))))))
2576 ;;; Setting up a message buffer
2579 (defun message-fill-address (header value)
2581 (narrow-to-region (point) (point))
2582 (insert (capitalize (symbol-name header))
2584 (if (consp value) (car value) value)
2586 (narrow-to-region (point-min) (1- (point-max)))
2588 (goto-char (point-min))
2590 (skip-chars-forward "^,\"" (point-max))
2591 (if (or (= (following-char) ?,)
2594 (if (and (> (current-column) 78)
2600 (setq last (1+ (point))))
2601 (setq last (1+ (point)))))
2602 (setq quoted (not quoted)))
2605 (goto-char (point-max))
2609 (defun message-fill-header (header value)
2610 (let ((begin (point))
2613 (insert (capitalize (symbol-name header))
2615 (if (consp value) (car value) value)
2618 (narrow-to-region begin (point))
2619 (fill-region-as-paragraph begin (point))
2620 ;; Tapdance around looong Message-IDs.
2622 (when (looking-at "[ \t]*$")
2623 (message-delete-line))
2625 (re-search-forward ":" nil t)
2626 (when (looking-at "\n[ \t]+")
2627 (replace-match " " t t))
2628 (goto-char (point-max)))))
2630 (defun message-position-point ()
2631 "Move point to where the user probably wants to find it."
2632 (message-narrow-to-headers)
2634 ((re-search-forward "^[^:]+:[ \t]*$" nil t)
2635 (search-backward ":" )
2638 (if (= (following-char) ? )
2642 (goto-char (point-max))
2645 (unless (looking-at "$")
2649 (defun message-buffer-name (type &optional to group)
2650 "Return a new (unique) buffer name based on TYPE and TO."
2652 ;; Check whether `message-generate-new-buffers' is a function,
2653 ;; and if so, call it.
2654 ((message-functionp message-generate-new-buffers)
2655 (funcall message-generate-new-buffers type to group))
2656 ;; Generate a new buffer name The Message Way.
2657 (message-generate-new-buffers
2658 (generate-new-buffer-name
2662 (or (car (mail-extract-address-components to))
2665 (if (and group (not (string= group ""))) (concat " on " group) "")
2667 ;; Use standard name.
2669 (format "*%s message*" type))))
2671 (defun message-pop-to-buffer (name)
2672 "Pop to buffer NAME, and warn if it already exists and is modified."
2673 (let ((buffer (get-buffer name)))
2675 (buffer-name buffer))
2677 (set-buffer (pop-to-buffer buffer))
2678 (when (and (buffer-modified-p)
2680 "Message already being composed; erase? ")))
2681 (error "Message being composed")))
2682 (set-buffer (pop-to-buffer name))))
2686 (defun message-do-send-housekeeping ()
2687 "Kill old message buffers."
2688 ;; We might have sent this buffer already. Delete it from the
2690 (setq message-buffer-list (delq (current-buffer) message-buffer-list))
2691 (while (and message-max-buffers
2693 (>= (length message-buffer-list) message-max-buffers))
2694 ;; Kill the oldest buffer -- unless it has been changed.
2695 (let ((buffer (pop message-buffer-list)))
2696 (when (and (buffer-name buffer)
2697 (not (buffer-modified-p buffer)))
2698 (kill-buffer buffer))))
2699 ;; Rename the buffer.
2700 (if message-send-rename-function
2701 (funcall message-send-rename-function)
2702 (when (string-match "\\`\\*" (buffer-name))
2704 (concat "*sent " (substring (buffer-name) (match-end 0))) t)))
2705 ;; Push the current buffer onto the list.
2706 (when message-max-buffers
2707 (setq message-buffer-list
2708 (nconc message-buffer-list (list (current-buffer))))))
2710 (defvar mc-modes-alist)
2711 (defun message-setup (headers &optional replybuffer actions)
2712 (when (and (boundp 'mc-modes-alist)
2713 (not (assq 'message-mode mc-modes-alist)))
2714 (push '(message-mode (encrypt . mc-encrypt-message)
2715 (sign . mc-sign-message))
2718 (setq message-send-actions actions))
2719 (setq message-reply-buffer replybuffer)
2720 (goto-char (point-min))
2721 ;; Insert all the headers.
2724 (alist message-header-format-alist))
2726 (unless (assq (caar h) message-header-format-alist)
2727 (push (list (caar h)) alist))
2731 (delete-region (point) (progn (forward-line -1) (point)))
2732 (when message-default-headers
2733 (insert message-default-headers))
2737 (insert mail-header-separator "\n")
2741 (when (message-news-p)
2742 (when message-default-news-headers
2743 (insert message-default-news-headers))
2744 (when message-generate-headers-first
2745 (message-generate-headers
2748 (copy-sequence message-required-news-headers))))))
2749 (when (message-mail-p)
2750 (when message-default-mail-headers
2751 (insert message-default-mail-headers))
2752 (when message-generate-headers-first
2753 (message-generate-headers
2756 (copy-sequence message-required-mail-headers))))))
2757 (run-hooks 'message-signature-setup-hook)
2758 (message-insert-signature)
2759 (message-set-auto-save-file-name)
2761 (message-narrow-to-headers)
2762 (run-hooks 'message-header-setup-hook))
2763 (set-buffer-modified-p nil)
2764 (run-hooks 'message-setup-hook)
2765 (message-position-point)
2768 (defun message-set-auto-save-file-name ()
2769 "Associate the message buffer with a file in the drafts directory."
2770 (when message-autosave-directory
2771 (unless (file-exists-p message-autosave-directory)
2772 (make-directory message-autosave-directory t))
2773 (let ((name (make-temp-name
2774 (concat (file-name-as-directory message-autosave-directory)
2776 (setq buffer-auto-save-file-name
2780 (set-buffer (get-buffer-create " *draft tmp*"))
2781 (setq buffer-file-name name)
2782 (make-auto-save-file-name))
2783 (kill-buffer (current-buffer)))))
2784 (clear-visited-file-modtime))))
2789 ;;; Commands for interfacing with message
2793 (defun message-mail (&optional to subject
2794 other-headers continue switch-function
2795 yank-action send-actions)
2796 "Start editing a mail message to be sent."
2798 (let ((message-this-is-mail t))
2799 (message-pop-to-buffer (message-buffer-name "mail" to))
2802 `((To . ,(or to "")) (Subject . ,(or subject "")))
2803 (when other-headers (list other-headers))))))
2806 (defun message-news (&optional newsgroups subject)
2807 "Start editing a news article to be sent."
2809 (let ((message-this-is-news t))
2810 (message-pop-to-buffer (message-buffer-name "news" nil newsgroups))
2811 (message-setup `((Newsgroups . ,(or newsgroups ""))
2812 (Subject . ,(or subject ""))))))
2815 (defun message-reply (&optional to-address wide ignore-reply-to)
2816 "Start editing a reply to the article in the current buffer."
2818 (let ((cur (current-buffer))
2819 from subject date reply-to to cc
2820 references message-id follow-to
2821 (inhibit-point-motion-hooks t)
2822 mct never-mct gnus-warning)
2824 (message-narrow-to-head)
2825 ;; Allow customizations to have their say.
2827 ;; This is a regular reply.
2828 (if (message-functionp message-reply-to-function)
2829 (setq follow-to (funcall message-reply-to-function)))
2830 ;; This is a followup.
2831 (if (message-functionp message-wide-reply-to-function)
2834 (funcall message-wide-reply-to-function)))))
2835 ;; Find all relevant headers we need.
2836 (setq from (message-fetch-field "from")
2837 date (message-fetch-field "date")
2838 subject (or (message-fetch-field "subject") "none")
2839 to (message-fetch-field "to")
2840 cc (message-fetch-field "cc")
2841 mct (message-fetch-field "mail-copies-to")
2842 reply-to (unless ignore-reply-to (message-fetch-field "reply-to"))
2843 references (message-fetch-field "references")
2844 message-id (message-fetch-field "message-id" t))
2845 ;; Remove any (buggy) Re:'s that are present and make a
2847 (when (string-match "^[ \t]*[Rr][Ee]:[ \t]*" subject)
2848 (setq subject (substring subject (match-end 0))))
2849 (setq subject (concat "Re: " subject))
2851 (when (and (setq gnus-warning (message-fetch-field "gnus-warning"))
2852 (string-match "<[^>]+>" gnus-warning))
2853 (setq message-id (match-string 0 gnus-warning)))
2855 ;; Handle special values of Mail-Copies-To.
2857 (cond ((equal (downcase mct) "never")
2860 ((equal (downcase mct) "always")
2861 (setq mct (or reply-to from)))))
2866 (setq follow-to (list (cons 'To (or to-address reply-to from))))
2869 (message-set-work-buffer)
2871 (insert (or reply-to from "")))
2872 (insert (if (bolp) "" ", ") (or to ""))
2873 (insert (if mct (concat (if (bolp) "" ", ") mct) ""))
2874 (insert (if cc (concat (if (bolp) "" ", ") cc) ""))
2875 ;; Remove addresses that match `rmail-dont-reply-to-names'.
2876 (insert (prog1 (rmail-dont-reply-to (buffer-string))
2878 (goto-char (point-min))
2879 ;; Perhaps Mail-Copies-To: never removed the only address?
2881 (insert (or reply-to from "")))
2885 (cons (mail-strip-quoted-names addr) addr))
2886 (message-tokenize-header (buffer-string))))
2889 (setq ccalist (delq (assoc (car (pop s)) s) ccalist)))))
2890 (setq follow-to (list (cons 'To (cdr (pop ccalist)))))
2892 (let ((ccs (cons 'Cc (mapconcat
2893 (lambda (addr) (cdr addr)) ccalist ", "))))
2894 (when (string-match "^ +" (cdr ccs))
2895 (setcdr ccs (substring (cdr ccs) (match-end 0))))
2896 (push ccs follow-to))))))
2899 (message-pop-to-buffer (message-buffer-name
2900 (if wide "wide reply" "reply") from
2901 (if wide to-address nil)))
2903 (setq message-reply-headers
2904 (vector 0 subject from date message-id references 0 0 ""))
2907 `((Subject . ,subject)
2909 ,@(if (or references message-id)
2910 `((References . ,(concat (or references "") (and references " ")
2911 (or message-id ""))))
2916 (defun message-wide-reply (&optional to-address)
2917 "Make a \"wide\" reply to the message in the current buffer."
2919 (message-reply to-address t))
2922 (defun message-followup (&optional to-newsgroups)
2923 "Follow up to the message in the current buffer.
2924 If TO-NEWSGROUPS, use that as the new Newsgroups line."
2926 (let ((cur (current-buffer))
2927 from subject date reply-to mct
2928 references message-id follow-to
2929 (inhibit-point-motion-hooks t)
2930 (message-this-is-news t)
2931 followup-to distribution newsgroups gnus-warning)
2934 (goto-char (point-min))
2935 (if (search-forward "\n\n" nil t)
2938 (when (message-functionp message-followup-to-function)
2940 (funcall message-followup-to-function)))
2941 (setq from (message-fetch-field "from")
2942 date (message-fetch-field "date")
2943 subject (or (message-fetch-field "subject") "none")
2944 references (message-fetch-field "references")
2945 message-id (message-fetch-field "message-id" t)
2946 followup-to (message-fetch-field "followup-to")
2947 newsgroups (message-fetch-field "newsgroups")
2948 reply-to (message-fetch-field "reply-to")
2949 distribution (message-fetch-field "distribution")
2950 mct (message-fetch-field "mail-copies-to"))
2951 (when (and (setq gnus-warning (message-fetch-field "gnus-warning"))
2952 (string-match "<[^>]+>" gnus-warning))
2953 (setq message-id (match-string 0 gnus-warning)))
2954 ;; Remove bogus distribution.
2955 (when (and (stringp distribution)
2956 (let ((case-fold-search t))
2957 (string-match "world" distribution)))
2958 (setq distribution nil))
2959 ;; Remove any (buggy) Re:'s that are present and make a
2961 (when (string-match "^[ \t]*[Rr][Ee]:[ \t]*" subject)
2962 (setq subject (substring subject (match-end 0))))
2963 (setq subject (concat "Re: " subject))
2966 (message-pop-to-buffer (message-buffer-name "followup" from newsgroups))
2969 `((Subject . ,subject)
2972 (list (cons 'Newsgroups to-newsgroups)))
2973 (follow-to follow-to)
2974 ((and followup-to message-use-followup-to)
2977 ((equal (downcase followup-to) "poster")
2978 (if (or (eq message-use-followup-to 'use)
2979 (message-y-or-n-p "Obey Followup-To: poster? " t "\
2980 You should normally obey the Followup-To: header.
2982 `Followup-To: poster' sends your response via e-mail instead of news.
2984 A typical situation where `Followup-To: poster' is used is when the poster
2985 does not read the newsgroup, so he wouldn't see any replies sent to it."))
2986 (cons 'To (or reply-to from ""))
2987 (cons 'Newsgroups newsgroups)))
2989 (if (or (equal followup-to newsgroups)
2990 (not (eq message-use-followup-to 'ask))
2992 (concat "Obey Followup-To: " followup-to "? ") t "\
2993 You should normally obey the Followup-To: header.
2995 `Followup-To: " followup-to "'
2996 directs your response to " (if (string-match "," followup-to)
2997 "the specified newsgroups"
2998 "that newsgroup only") ".
3000 If a message is posted to several newsgroups, Followup-To is often
3001 used to direct the following discussion to one newsgroup only,
3002 because discussions that are spread over several newsgroup tend to
3003 be fragmented and very difficult to follow.
3005 Also, some source/announcement newsgroups are not indented for discussion;
3006 responses here are directed to other newsgroups."))
3007 (cons 'Newsgroups followup-to)
3008 (cons 'Newsgroups newsgroups))))))
3010 `((Newsgroups . ,newsgroups))))
3011 ,@(and distribution (list (cons 'Distribution distribution)))
3012 ,@(if (or references message-id)
3013 `((References . ,(concat (or references "") (and references " ")
3014 (or message-id "")))))
3016 (not (equal (downcase mct) "never")))
3017 (list (cons 'Cc (if (equal (downcase mct) "always")
3018 (or reply-to from "")
3023 (setq message-reply-headers
3024 (vector 0 subject from date message-id references 0 0 ""))))
3028 (defun message-cancel-news ()
3029 "Cancel an article you posted."
3031 (unless (message-news-p)
3032 (error "This is not a news article; canceling is impossible"))
3033 (when (yes-or-no-p "Do you really want to cancel this article? ")
3034 (let (from newsgroups message-id distribution buf)
3036 ;; Get header info. from original article.
3038 (message-narrow-to-head)
3039 (setq from (message-fetch-field "from")
3040 newsgroups (message-fetch-field "newsgroups")
3041 message-id (message-fetch-field "message-id" t)
3042 distribution (message-fetch-field "distribution")))
3043 ;; Make sure that this article was written by the user.
3044 (unless (string-equal
3045 (downcase (cadr (mail-extract-address-components from)))
3046 (downcase (message-make-address)))
3047 (error "This article is not yours"))
3048 ;; Make control message.
3049 (setq buf (set-buffer (get-buffer-create " *message cancel*")))
3050 (buffer-disable-undo (current-buffer))
3052 (insert "Newsgroups: " newsgroups "\n"
3053 "From: " (message-make-from) "\n"
3054 "Subject: cmsg cancel " message-id "\n"
3055 "Control: cancel " message-id "\n"
3057 (concat "Distribution: " distribution "\n")
3059 mail-header-separator "\n"
3060 message-cancel-message)
3061 (message "Canceling your article...")
3062 (let ((message-syntax-checks 'dont-check-for-anything-just-trust-me))
3063 (funcall message-send-news-function))
3064 (message "Canceling your article...done")
3065 (kill-buffer buf)))))
3068 (defun message-supersede ()
3069 "Start composing a message to supersede the current message.
3070 This is done simply by taking the old article and adding a Supersedes
3071 header line with the old Message-ID."
3073 (let ((cur (current-buffer)))
3074 ;; Check whether the user owns the article that is to be superseded.
3075 (unless (string-equal
3076 (downcase (cadr (mail-extract-address-components
3077 (message-fetch-field "from"))))
3078 (downcase (message-make-address)))
3079 (error "This article is not yours"))
3080 ;; Get a normal message buffer.
3081 (message-pop-to-buffer (message-buffer-name "supersede"))
3082 (insert-buffer-substring cur)
3083 (message-narrow-to-head)
3084 ;; Remove unwanted headers.
3085 (when message-ignored-supersedes-headers
3086 (message-remove-header message-ignored-supersedes-headers t))
3087 (goto-char (point-min))
3088 (if (not (re-search-forward "^Message-ID: " nil t))
3089 (error "No Message-ID in this article")
3090 (replace-match "Supersedes: " t t))
3091 (goto-char (point-max))
3092 (insert mail-header-separator)
3097 (defun message-recover ()
3098 "Reread contents of current buffer from its last auto-save file."
3100 (let ((file-name (make-auto-save-file-name)))
3101 (cond ((save-window-excursion
3102 (if (not (eq system-type 'vax-vms))
3103 (with-output-to-temp-buffer "*Directory*"
3104 (buffer-disable-undo standard-output)
3105 (let ((default-directory "/"))
3107 "ls" nil standard-output nil "-l" file-name))))
3108 (yes-or-no-p (format "Recover auto save file %s? " file-name)))
3109 (let ((buffer-read-only nil))
3111 (insert-file-contents file-name nil)))
3112 (t (error "message-recover cancelled")))))
3114 ;;; Forwarding messages.
3116 (defun message-make-forward-subject ()
3117 "Return a Subject header suitable for the message in the current buffer."
3121 (message-narrow-to-head)
3122 (concat "[" (or (message-fetch-field
3123 (if (message-news-p) "newsgroups" "from"))
3125 "] " (or (message-fetch-field "Subject") "")))))
3128 (defun message-forward (&optional news)
3129 "Forward the current message via mail.
3130 Optional NEWS will use news to forward instead of mail."
3132 (let ((cur (current-buffer))
3133 (subject (message-make-forward-subject))
3135 (if news (message-news nil subject) (message-mail nil subject))
3136 ;; Put point where we want it before inserting the forwarded
3138 (if message-signature-before-forwarded-message
3139 (goto-char (point-max))
3140 (message-goto-body))
3141 ;; Make sure we're at the start of the line.
3144 ;; Narrow to the area we are to insert.
3145 (narrow-to-region (point) (point))
3146 ;; Insert the separators and the forwarded buffer.
3147 (insert message-forward-start-separator)
3148 (setq art-beg (point))
3149 (insert-buffer-substring cur)
3150 (goto-char (point-max))
3151 (insert message-forward-end-separator)
3152 (set-text-properties (point-min) (point-max) nil)
3153 ;; Remove all unwanted headers.
3155 (narrow-to-region (point) (if (search-forward "\n\n" nil t)
3158 (goto-char (point-min))
3159 (message-remove-header message-included-forward-headers t nil t)
3161 (message-position-point)))
3164 (defun message-resend (address)
3165 "Resend the current article to ADDRESS."
3166 (interactive "sResend message to: ")
3167 (message "Resending message to %s..." address)
3169 (let ((cur (current-buffer))
3171 ;; We first set up a normal mail buffer.
3172 (set-buffer (get-buffer-create " *message resend*"))
3173 (buffer-disable-undo (current-buffer))
3175 (message-setup `((To . ,address)))
3176 ;; Insert our usual headers.
3177 (message-generate-headers '(From Date To))
3178 (message-narrow-to-headers)
3179 ;; Rename them all to "Resent-*".
3180 (while (re-search-forward "^[A-Za-z]" nil t)
3185 (delete-region (point) (point-max))
3187 ;; Insert the message to be resent.
3188 (insert-buffer-substring cur)
3189 (goto-char (point-min))
3190 (search-forward "\n\n")
3193 (narrow-to-region beg (point))
3194 (message-remove-header message-ignored-resent-headers t)
3195 (goto-char (point-max)))
3196 (insert mail-header-separator)
3197 ;; Rename all old ("Also-")Resent headers.
3198 (while (re-search-backward "^\\(Also-\\)?Resent-" beg t)
3201 ;; Quote any "From " lines at the beginning.
3203 (when (looking-at "From ")
3204 (replace-match "X-From-Line: "))
3207 (kill-buffer (current-buffer)))
3208 (message "Resending message to %s...done" address)))
3211 (defun message-bounce ()
3212 "Re-mail the current message.
3213 This only makes sense if the current message is a bounce message than
3214 contains some mail you have written which has been bounced back to
3217 (let ((cur (current-buffer))
3219 (message-pop-to-buffer (message-buffer-name "bounce"))
3220 (insert-buffer-substring cur)
3222 (message-narrow-to-head)
3223 (if (and (message-fetch-field "Mime-Version")
3224 (setq boundary (message-fetch-field "Content-Type")))
3225 (if (string-match "boundary=\"\\([^\"]+\\)\"" boundary)
3226 (setq boundary (concat (match-string 1 boundary) " *\n"
3227 "Content-Type: message/rfc822"))
3228 (setq boundary nil)))
3230 (goto-char (point-min))
3231 (search-forward "\n\n" nil t)
3233 (re-search-forward boundary nil t)
3235 (and (re-search-forward message-unsent-separator nil t)
3237 (and (search-forward "\n\n" nil t)
3238 (re-search-forward "^Return-Path:.*\n" nil t)))
3239 ;; We remove everything before the bounced mail.
3242 (if (re-search-forward "^[^ \n\t]+:" nil t)
3246 (message-narrow-to-head)
3247 (message-remove-header message-ignored-bounced-headers t)
3248 (goto-char (point-max))
3249 (insert mail-header-separator))
3250 (message-position-point)))
3253 ;;; Interactive entry points for new message buffers.
3257 (defun message-mail-other-window (&optional to subject)
3258 "Like `message-mail' command, but display mail buffer in another window."
3260 (let ((pop-up-windows t)
3261 (special-display-buffer-names nil)
3262 (special-display-regexps nil)
3263 (same-window-buffer-names nil)
3264 (same-window-regexps nil))
3265 (message-pop-to-buffer (message-buffer-name "mail" to)))
3266 (message-setup `((To . ,(or to "")) (Subject . ,(or subject "")))))
3269 (defun message-mail-other-frame (&optional to subject)
3270 "Like `message-mail' command, but display mail buffer in another frame."
3272 (let ((pop-up-frames t)
3273 (special-display-buffer-names nil)
3274 (special-display-regexps nil)
3275 (same-window-buffer-names nil)
3276 (same-window-regexps nil))
3277 (message-pop-to-buffer (message-buffer-name "mail" to)))
3278 (message-setup `((To . ,(or to "")) (Subject . ,(or subject "")))))
3281 (defun message-news-other-window (&optional newsgroups subject)
3282 "Start editing a news article to be sent."
3284 (let ((pop-up-windows t)
3285 (special-display-buffer-names nil)
3286 (special-display-regexps nil)
3287 (same-window-buffer-names nil)
3288 (same-window-regexps nil))
3289 (message-pop-to-buffer (message-buffer-name "news" nil newsgroups)))
3290 (message-setup `((Newsgroups . ,(or newsgroups ""))
3291 (Subject . ,(or subject "")))))
3294 (defun message-news-other-frame (&optional newsgroups subject)
3295 "Start editing a news article to be sent."
3297 (let ((pop-up-frames t)
3298 (special-display-buffer-names nil)
3299 (special-display-regexps nil)
3300 (same-window-buffer-names nil)
3301 (same-window-regexps nil))
3302 (message-pop-to-buffer (message-buffer-name "news" nil newsgroups)))
3303 (message-setup `((Newsgroups . ,(or newsgroups ""))
3304 (Subject . ,(or subject "")))))
3308 ;; This code should be moved to underline.el (from which it is stolen).
3311 (defun bold-region (start end)
3312 "Bold all nonblank characters in the region.
3313 Works by overstriking characters.
3314 Called from program, takes two arguments START and END
3315 which specify the range to operate on."
3318 (let ((end1 (make-marker)))
3319 (move-marker end1 (max start end))
3320 (goto-char (min start end))
3321 (while (< (point) end1)
3322 (or (looking-at "[_\^@- ]")
3323 (insert (following-char) "\b"))
3324 (forward-char 1)))))
3327 (defun unbold-region (start end)
3328 "Remove all boldness (overstruck characters) in the region.
3329 Called from program, takes two arguments START and END
3330 which specify the range to operate on."
3333 (let ((end1 (make-marker)))
3334 (move-marker end1 (max start end))
3335 (goto-char (min start end))
3336 (while (re-search-forward "\b" end1 t)
3337 (if (eq (following-char) (char-after (- (point) 2)))
3338 (delete-char -2))))))
3340 (defalias 'message-exchange-point-and-mark 'exchange-point-and-mark)
3342 ;; Support for toolbar
3343 (when (string-match "XEmacs\\|Lucid" emacs-version)
3344 (require 'messagexmas))
3346 ;;; Group name completion.
3348 (defvar message-newgroups-header-regexp
3349 "^\\(Newsgroups\\|Followup-To\\|Posted-To\\):"
3350 "Regexp that match headers that lists groups.")
3352 (defun message-tab ()
3353 "Expand group names in Newsgroups and Followup-To headers.
3354 Do a `tab-to-tab-stop' if not in those headers."
3356 (if (let ((mail-abbrev-mode-regexp message-newgroups-header-regexp))
3357 (mail-abbrev-in-expansion-header-p))
3358 (message-expand-group)
3361 (defvar gnus-active-hashtb)
3362 (defun message-expand-group ()
3363 (let* ((b (save-excursion
3368 (skip-chars-forward "^:")
3371 (skip-chars-backward "^, \t\n") (point))))
3372 (completion-ignore-case t)
3373 (string (buffer-substring b (point)))
3374 (hashtb (and (boundp 'gnus-active-hashtb) gnus-active-hashtb))
3375 (completions (all-completions string hashtb))
3376 (cur (current-buffer))
3378 (delete-region b (point))
3380 ((= (length completions) 1)
3381 (if (string= (car completions) string)
3384 (message "Only matching group"))
3385 (insert (car completions))))
3386 ((and (setq comp (try-completion string hashtb))
3387 (not (string= comp string)))
3392 (message "No matching groups")
3393 (pop-to-buffer "*Completions*")
3394 (buffer-disable-undo (current-buffer))
3395 (let ((buffer-read-only nil))
3397 (let ((standard-output (current-buffer)))
3398 (display-completion-list (sort completions 'string<)))
3399 (goto-char (point-min))
3400 (pop-to-buffer cur)))))))
3404 (defun message-talkative-question (ask question show &rest text)
3405 "Call FUNCTION with argument QUESTION, displaying the rest of the arguments in a temporary buffer if SHOW.
3406 The following arguments may contain lists of values."
3408 (setq text (message-flatten-list text)))
3409 (save-window-excursion
3411 (with-output-to-temp-buffer " *MESSAGE information message*"
3412 (set-buffer " *MESSAGE information message*")
3413 (mapcar 'princ text)
3414 (goto-char (point-min))))
3415 (funcall ask question))
3416 (funcall ask question)))
3418 (defun message-flatten-list (list)
3419 "Return a new, flat list that contains all elements of LIST.
3421 \(message-flatten-list '(1 (2 3 (4 5 (6))) 7))
3424 (apply 'append (mapcar 'message-flatten-list list)))
3428 (defun message-generate-new-buffer-clone-locals (name &optional varstr)
3429 "Create and return a buffer with a name based on NAME using generate-new-buffer.
3430 Then clone the local variables and values from the old buffer to the
3431 new one, cloning only the locals having a substring matching the
3433 (let ((oldlocals (buffer-local-variables)))
3435 (set-buffer (generate-new-buffer name))
3436 (mapcar (lambda (dude)
3437 (when (and (car dude)
3439 (string-match varstr (symbol-name (car dude)))))
3441 (set (make-local-variable (car dude))
3446 (run-hooks 'message-load-hook)
3450 ;;; message.el ends here