1 ;;; message.el --- composing mail and news messages
2 ;; Copyright (C) 1996 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.
34 (require 'mail-header)
40 (defvar message-fcc-handler-function 'rmail-output
41 "*A function called to save outgoing articles.
42 This function will be called with the name of the file to store the
43 article in. The default function is `rmail-output' which saves in Unix
47 (defvar message-courtesy-message
48 "The following message is a courtesy copy of an article\nthat has been posted as well.\n\n"
49 "*This is inserted at the start of a mailed copy of a posted message.
50 If this variable is nil, no such courtesy message will be added.")
53 (defvar message-ignored-bounced-headers "^\\(Received\\|Return-Path\\):"
54 "*Regexp that matches headers to be removed in resent bounced mail.")
57 (defvar message-from-style 'default
58 "*Specifies how \"From\" headers look.
60 If `nil', they contain just the return address like:
62 If `parens', they look like:
63 king@grassland.com (Elvis Parsley)
64 If `angles', they look like:
65 Elvis Parsley <king@grassland.com>
67 Otherwise, most addresses look like `angles', but they look like
68 `parens' if `angles' would need quoting and `parens' would not.")
71 (defvar message-syntax-checks nil
72 "Controls what syntax checks should not be performed on outgoing posts.
73 To disable checking of long signatures, for instance, add
74 `(signature . disabled)' to this list.
76 Don't touch this variable unless you really know what you're doing.
78 Checks include subject-cmsg multiple-headers sendsys message-id from
79 long-lines control-chars size new-text redirected-followup signature
80 approved sender empty empty-headers message-id from subject.")
83 (defvar message-required-news-headers
84 '(From Newsgroups Subject Date Message-ID
85 (optional . Organization) Lines
86 (optional . X-Newsreader))
87 "*Headers to be generated or prompted for when posting an article.
88 RFC977 and RFC1036 require From, Date, Newsgroups, Subject,
89 Message-ID. Organization, Lines, In-Reply-To, Expires, and
90 X-Newsreader are optional. If don't you want message to insert some
91 header, remove it from this list.")
94 (defvar message-required-mail-headers
95 '(From Subject Date (optional . In-Reply-To) Message-ID Lines
96 (optional . X-Mailer))
97 "*Headers to be generated or prompted for when mailing a message.
98 RFC822 required that From, Date, To, Subject and Message-ID be
99 included. Organization, Lines and X-Mailer are optional.")
102 (defvar message-deletable-headers '(Message-ID Date)
103 "*Headers to be deleted if they already exist and were generated by message previously.")
106 (defvar message-ignored-news-headers
107 "^NNTP-Posting-Host:\\|^Xref:\\|^Bcc:\\|^Gcc:\\|^Fcc:"
108 "*Regexp of headers to be removed unconditionally before posting.")
111 (defvar message-ignored-mail-headers "^Gcc:\\|^Fcc:"
112 "*Regexp of headers to be removed unconditionally before mailing.")
115 (defvar message-ignored-supersedes-headers
116 "^Path:\\|^Date\\|^NNTP-Posting-Host:\\|^Xref:\\|^Lines:\\|^Received:\\|^X-From-Line:\\|Return-Path:"
117 "*Header lines matching this regexp will be deleted before posting.
118 It's best to delete old Path and Date headers before posting to avoid
122 (defvar message-signature-separator "^-- *$"
123 "Regexp matching the signature separator.")
126 (defvar message-interactive nil
127 "Non-nil means when sending a message wait for and display errors.
128 nil means let mailer mail back a message to report errors.")
131 (defvar message-generate-new-buffers nil
132 "*Non-nil means that a new message buffer will be created whenever `mail-setup' is called.")
135 (defvar message-kill-buffer-on-exit nil
136 "*Non-nil means that the message buffer will be killed after sending a message.")
138 (defvar gnus-local-organization)
140 (defvar message-user-organization
141 (or (and (boundp 'gnus-local-organization)
142 gnus-local-organization)
143 (getenv "ORGANIZATION")
145 "*String to be used as an Organization header.
146 If t, use `message-user-organization-file'.")
149 (defvar message-user-organization-file "/usr/lib/news/organization"
150 "*Local news organization file.")
153 (defvar message-autosave-directory "~/Mail/drafts/"
154 "*Directory where message autosaves buffers.
155 If nil, message won't autosave.")
157 (defvar message-forward-start-separator
158 "------- Start of forwarded message -------\n"
159 "*Delimiter inserted before forwarded messages.")
161 (defvar message-forward-end-separator
162 "------- End of forwarded message -------\n"
163 "*Delimiter inserted after forwarded messages.")
166 (defvar message-signature-before-forwarded-message t
167 "*If non-nil, put the signature before any included forwarded message.")
170 (defvar message-included-forward-headers
171 "^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:"
172 "*Regexp matching headers to be included in forwarded messages.")
175 (defvar message-ignored-resent-headers "^Return-receipt"
176 "*All headers that match this regexp will be deleted when resending a message.")
179 (defvar message-ignored-cited-headers "."
180 "Delete these headers from the messages you yank.")
182 ;; Useful to set in site-init.el
184 (defvar message-send-mail-function 'message-send-mail
185 "Function to call to send the current buffer as mail.
186 The headers should be delimited by a line whose contents match the
187 variable `mail-header-separator'.")
190 (defvar message-send-news-function 'message-send-news
191 "Function to call to send the current buffer as news.
192 The headers should be delimited by a line whose contents match the
193 variable `message-header-separator'.")
196 (defvar message-reply-to-function nil
197 "Function that should return a list of headers.
198 This function should pick out addresses from the To, Cc, and From headers
199 and respond with new To and Cc headers.")
202 (defvar message-wide-reply-to-function nil
203 "Function that should return a list of headers.
204 This function should pick out addresses from the To, Cc, and From headers
205 and respond with new To and Cc headers.")
208 (defvar message-followup-to-function nil
209 "Function that should return a list of headers.
210 This function should pick out addresses from the To, Cc, and From headers
211 and respond with new To and Cc headers.")
214 (defvar message-use-followup-to 'ask
215 "*Specifies what to do with Followup-To header.
216 If nil, ignore the header. If it is t, use its value, but query before
217 using the \"poster\" value. If it is the symbol `ask', query the user
218 whether to ignore the \"poster\" value. If it is the symbol `use',
219 always use the value.")
221 (defvar gnus-post-method)
222 (defvar gnus-select-method)
224 (defvar message-post-method
225 (cond ((and (boundp 'gnus-post-method)
228 ((boundp 'gnus-select-method)
231 "Method used to post news.")
234 (defvar message-generate-headers-first nil
235 "*If non-nil, generate all possible headers before composing.")
238 (defvar message-header-separator "--text follows this line--"
239 "*Line used to separate headers from text in messages being composed.")
241 (defvar message-setup-hook nil
242 "Normal hook, run each time a new outgoing message is initialized.
243 The function `message-setup' runs this hook.")
245 (defvar message-header-setup-hook nil
246 "Hook called narrowed to the headers when setting up a message buffer.")
249 (defvar message-citation-line-function 'message-insert-citation-line
250 "*Function called to insert the \"Whomever writes:\" line.")
253 (defvar message-yank-prefix "> "
254 "*Prefix inserted on the lines of yanked messages.
255 nil means use indentation.")
257 (defvar message-indentation-spaces 3
258 "*Number of spaces to insert at the beginning of each cited line.
259 Used by `message-yank-original' via `message-yank-cite'.")
262 (defvar message-cite-function 'message-cite-original
263 "*Function for citing an original message.")
266 (defvar message-indent-citation-function 'message-indent-citation
267 "*Function for modifying a citation just inserted in the mail buffer.
268 This can also be a list of functions. Each function can find the
269 citation between (point) and (mark t). And each function should leave
270 point and mark around the citation text as modified.")
272 (defvar message-abbrevs-loaded nil)
275 (defvar message-signature t
276 "*String to be inserted at the end of the message buffer.
277 If t, the `message-signature-file' file will be inserted instead.
278 If a function, the result from the function will be used instead.
279 If a form, the result from the form will be used instead.")
282 (defvar message-signature-file "~/.signature"
283 "*File containing the text inserted at end of message. buffer.")
285 (defvar message-distribution-function nil
286 "*Function called to return a Distribution header.")
288 (defvar message-expires 14
289 "*Number of days before your article expires.")
291 (defvar message-user-path nil
292 "If nil, use the NNTP server name in the Path header.
293 If stringp, use this; if non-nil, use no host name (user name only).")
295 (defvar message-reply-buffer nil)
296 (defvar message-reply-headers nil)
297 (defvar message-newsreader nil)
298 (defvar message-mailer nil)
299 (defvar message-sent-message-via nil)
300 (defvar message-checksum nil)
301 (defvar message-send-actions nil
302 "A list of actions to be performed upon successful sending of a message.")
305 (defvar message-default-headers nil
306 "*A string containing header lines to be inserted in outgoing messages.
307 It is inserted before you edit the message, so you can edit or delete
311 (defvar message-default-mail-headers nil
312 "*A string of header lines to be inserted in outgoing mails.")
315 (defvar message-default-news-headers nil
316 "*A string of header lines to be inserted in outgoing news articles.")
318 ;; Note: could use /usr/ucb/mail instead of sendmail;
319 ;; options -t, and -v if not interactive.
320 (defvar message-mailer-swallows-blank-line
321 (if (and (string-match "sparc-sun-sunos\\(\\'\\|[^5]\\)"
322 system-configuration)
323 (file-readable-p "/etc/sendmail.cf")
324 (let ((buffer (get-buffer-create " *temp*")))
328 (insert-file-contents "/etc/sendmail.cf")
329 (goto-char (point-min))
330 (let ((case-fold-search nil))
331 (re-search-forward "^OR\\>" nil t)))
332 (kill-buffer buffer))))
333 ;; According to RFC822, "The field-name must be composed of printable
334 ;; ASCII characters (i.e. characters that have decimal values between
335 ;; 33 and 126, except colon)", i.e. any chars except ctl chars,
337 '(looking-at "[ \t]\\|[][!\"#$%&'()*+,-./0-9;<=>?@A-Z\\\\^_`a-z{|}~]+:"))
338 "Set this non-nil if the system's mailer runs the header and body together.
339 \(This problem exists on Sunos 4 when sendmail is run in remote mode.)
340 The value should be an expression to test whether the problem will
343 (defvar message-mode-syntax-table
344 (let ((table (copy-syntax-table text-mode-syntax-table)))
345 (modify-syntax-entry ?% ". " table)
347 "Syntax table used while in Message mode.")
349 (defvar message-font-lock-keywords
350 (let* ((cite-prefix "A-Za-z") (cite-suffix (concat cite-prefix "0-9_.@-")))
351 (list '("^To:" . font-lock-function-name-face)
352 '("^[GBF]?[Cc][Cc]:\\|^Reply-To:" . font-lock-keyword-face)
353 '("^\\(Subject:\\)[ \t]*\\(.+\\)?"
354 (1 font-lock-comment-face) (2 font-lock-type-face nil t))
355 (list (concat "^\\(" (regexp-quote mail-header-separator) "\\)$")
356 1 'font-lock-comment-face)
357 (cons (concat "^[ \t]*"
358 "\\([" cite-prefix "]+[" cite-suffix "]*\\)?"
360 'font-lock-reference-face)
361 '("^\\(X-[A-Za-z0-9-]+\\|In-reply-to\\):.*"
362 . font-lock-string-face)))
363 "Additional expressions to highlight in Message mode.")
365 (defvar message-face-alist
366 '((bold . bold-region)
367 (underline . underline-region)
368 (default . (lambda (b e)
370 (ununderline-region b e))))
371 "Alist of mail and news faces for facemenu.
372 The cdr of ech entry is a function for applying the face to a region.")
374 (defvar message-send-hook nil
375 "Hook run before sending messages.")
377 (defvar message-sent-hook nil
378 "Hook run after sending messages.")
380 ;;; Internal variables.
382 ;;; Regexp matching the delimiter of messages in UNIX mail format
383 ;;; (UNIX From lines), minus the initial ^.
384 (defvar message-unix-mail-delimiter
385 (let ((time-zone-regexp
386 (concat "\\([A-Z]?[A-Z]?[A-Z][A-Z]\\( DST\\)?"
387 "\\|[-+]?[0-9][0-9][0-9][0-9]"
393 ;; Username, perhaps with a quoted section that can contain spaces.
396 "\\(\\|\".*\"[^ \n]*\\)"
400 ;; The time the message was sent.
401 "\\([^ \n]*\\) *" ; day of the week
402 "\\([^ ]*\\) *" ; month
403 "\\([0-9]*\\) *" ; day of month
404 "\\([0-9:]*\\) *" ; time of day
406 ;; Perhaps a time zone, specified by an abbreviation, or by a
411 " [0-9][0-9]\\([0-9]*\\) *"
413 ;; On some systems the time zone can appear after the year, too.
417 "\\(remote from .*\\)?"
421 (defvar message-unsent-separator
422 (concat "^ *---+ +Unsent message follows +---+ *$\\|"
423 "^ *---+ +Returned message +---+ *$\\|"
424 "^Start of returned message$\\|"
425 "^ *---+ +Original message +---+ *$\\|"
426 "^ *--+ +begin message +--+ *$\\|"
427 "^ *---+ +Original message follows +---+ *$\\|"
428 "^|? *---+ +Message text follows: +---+ *|?$")
429 "A regexp that matches the separator before the text of a failed message.")
431 (defvar message-header-format-alist
433 (To . message-fill-header)
434 (Cc . message-fill-header)
445 (References . message-fill-header)
448 "Alist used for formatting headers.")
451 (autoload 'message-setup-toolbar "message-xmas"))
456 ;;; Utility functions.
459 (defun message-point-at-bol ()
460 "Return point at the beginning of the line."
467 (defun message-point-at-eol ()
468 "Return point at the end of the line."
475 ;; Delete the current line (and the next N lines.);
476 (defmacro message-delete-line (&optional n)
477 `(delete-region (progn (beginning-of-line) (point))
478 (progn (forward-line ,(or n 1)) (point))))
480 (defun message-tokenize-header (header &optional separator)
481 "Split HEADER into a list of header elements.
482 \",\" is used as the separator."
484 (separator (or separator ","))
486 (format "[ \t]*\\([^%s]+\\)?\\([%s]+\\|\\'\\)" separator separator))
488 (while (and (string-match regexp header beg)
489 (< beg (length header)))
490 (when (match-beginning 1)
491 (push (match-string 1 header) elems))
492 (setq beg (match-end 0)))
495 (defun message-fetch-reply-field (header)
496 "Fetch FIELD from the message we're replying to."
497 (when (and message-reply-buffer
498 (buffer-name message-reply-buffer))
500 (set-buffer message-reply-buffer)
501 (mail-fetch-field header))))
503 (defun message-set-work-buffer ()
504 (if (get-buffer " *message work*")
506 (set-buffer " *message work*")
508 (set-buffer (get-buffer-create " *message work*"))
509 (kill-all-local-variables)
510 (buffer-disable-undo (current-buffer))))
512 (defun message-functionp (form)
513 "Return non-nil if FORM is funcallable."
514 (or (and (symbolp form) (fboundp form))
515 (and (listp form) (eq (car form) 'lambda))))
517 (defun message-strip-subject-re (subject)
518 "Remove \"Re:\" from subject lines."
519 (if (string-match "^[Rr][Ee]: *" subject)
520 (substring subject (match-end 0))
523 (defun message-remove-header (header &optional is-regexp first reverse)
524 "Remove HEADER in the narrowed buffer.
525 If REGEXP, HEADER is a regular expression.
526 If FIRST, only remove the first instance of the header.
527 Return the number of headers removed."
528 (goto-char (point-min))
529 (let ((regexp (if is-regexp header (concat "^" header ":")))
533 (while (and (not (eobp))
536 (not (looking-at regexp))
544 ;; There might be a continuation header, so we have to search
545 ;; until we find a new non-continuation line.
548 (if (re-search-forward "^[^ \t]" nil t)
549 (goto-char (match-beginning 0))
552 (if (re-search-forward "^[^ \t]" nil t)
553 (goto-char (match-beginning 0))
557 (defun message-narrow-to-headers ()
558 "Narrow the buffer to the head of the message."
561 (goto-char (point-min))
562 (if (re-search-forward
563 (concat "^" (regexp-quote mail-header-separator) "\n") nil t)
566 (goto-char (point-min)))
568 (defun message-narrow-to-head ()
569 "Narrow the buffer to the head of the message."
572 (goto-char (point-min))
573 (if (search-forward "\n\n" nil 1)
576 (goto-char (point-min)))
578 (defun message-news-p ()
579 "Say whether the current buffer contains a news message."
582 (message-narrow-to-headers)
583 (mail-fetch-field "newsgroups"))))
585 (defun message-mail-p ()
586 "Say whether the current buffer contains a mail message."
589 (message-narrow-to-headers)
590 (or (mail-fetch-field "to")
591 (mail-fetch-field "cc")
592 (mail-fetch-field "bcc")))))
594 (defun message-next-header ()
595 "Go to the beginning of the next header."
597 (or (eobp) (forward-char 1))
598 (not (if (re-search-forward "^[^ \t]" nil t)
600 (goto-char (point-max)))))
602 (defun message-sort-headers-1 ()
603 "Sort the buffer as headers using `message-rank' text props."
604 (goto-char (point-min))
606 nil 'message-next-header
608 (message-next-header)
612 (or (get-text-property (point) 'message-rank)
615 (defun message-sort-headers ()
616 "Sort the headers of the current message according to `message-header-format-alist'."
620 (let ((max (1+ (length message-header-format-alist)))
622 (message-narrow-to-headers)
623 (while (re-search-forward "^[^ ]+:" nil t)
625 (match-beginning 0) (1+ (match-beginning 0))
627 (if (setq rank (length (memq (assq (intern (buffer-substring
630 message-header-format-alist)
631 message-header-format-alist)))
634 (message-sort-headers-1))))
644 (defvar message-mode-map nil)
646 (unless message-mode-map
647 (setq message-mode-map (copy-keymap text-mode-map))
648 (define-key message-mode-map "\C-c?" 'describe-mode)
650 (define-key message-mode-map "\C-c\C-f\C-t" 'message-goto-to)
651 (define-key message-mode-map "\C-c\C-f\C-b" 'message-goto-bcc)
652 (define-key message-mode-map "\C-c\C-f\C-w" 'message-goto-fcc)
653 (define-key message-mode-map "\C-c\C-f\C-c" 'message-goto-cc)
654 (define-key message-mode-map "\C-c\C-f\C-s" 'message-goto-subject)
655 (define-key message-mode-map "\C-c\C-f\C-r" 'message-goto-reply-to)
656 (define-key message-mode-map "\C-c\C-f\C-n" 'message-goto-newsgroups)
657 (define-key message-mode-map "\C-c\C-f\C-d" 'message-goto-distribution)
658 (define-key message-mode-map "\C-c\C-f\C-f" 'message-goto-followup-to)
659 (define-key message-mode-map "\C-c\C-f\C-k" 'message-goto-keywords)
660 (define-key message-mode-map "\C-c\C-f\C-u" 'message-goto-summary)
661 (define-key message-mode-map "\C-c\C-b" 'message-goto-body)
662 (define-key message-mode-map "\C-c\C-i" 'message-goto-signature)
664 (define-key message-mode-map "\C-c\C-t" 'message-insert-to)
665 (define-key message-mode-map "\C-c\C-n" 'message-insert-newsgroups)
667 (define-key message-mode-map "\C-c\C-y" 'message-yank-original)
668 (define-key message-mode-map "\C-c\C-q" 'message-fill-yanked-message)
669 (define-key message-mode-map "\C-c\C-w" 'message-insert-signature)
670 (define-key message-mode-map "\C-c\C-r" 'message-caesar-buffer-body)
671 (define-key message-mode-map "\C-c\C-o" 'message-sort-headers)
673 (define-key message-mode-map "\C-c\C-c" 'message-send-and-exit)
674 (define-key message-mode-map "\C-c\C-s" 'message-send)
675 (define-key message-mode-map "\C-c\C-k" 'message-dont-send))
677 (easy-menu-define message-mode-menu message-mode-map
682 ["To:" message-goto-to t]
683 ["Subject:" message-goto-subject t]
684 ["Summary:" message-goto-summary t]
685 ["Keywords:" message-goto-keywords t]
686 ["Newsgroups:" message-goto-newsgroups t]
687 ["Followup-To:" message-goto-followup-to t]
688 ["Distribution:" message-goto-distribution t]
689 ["Body" message-goto-body t]
690 ["Signature" message-goto-signature t]
692 "Miscellaneous Commands:"
694 ["Sort Headers" message-sort-headers t]
695 ["Yank Original" message-yank-original t]
696 ["Fill Yanked Message" message-fill-yanked-message t]
697 ;; ["Insert Signature" news-reply-signature t]
698 ["Caesar (rot13) Message" message-caesar-buffer-body t]
700 ["Post Message" message-send-and-exit t]
701 ["Abort Message" message-dont-send t]))
704 (defun message-mode ()
705 "Major mode for editing mail and news to be sent.
706 Like Text Mode but with these additional commands:
707 C-c C-s message-send (send the message) C-c C-c message-send-and-exit
708 C-c C-f move to a header field (and create it if there isn't):
709 C-c C-f C-t move to To C-c C-f C-s move to Subject
710 C-c C-f C-c move to Cc C-c C-f C-b move to Bcc
711 C-c C-f C-f move to Fcc C-c C-f C-r move to Reply-To
712 C-c C-f C-u move to Summary C-c C-f C-n move to Newsgroups
713 C-c C-f C-k move to Keywords C-c C-f C-d move to Distribution
714 C-c C-f C-o move to Followup-To
715 C-c C-t message-insert-to (add a To header to a news followup)
716 C-c C-n message-insert-newsgroups (add a Newsgroup header to a news reply)
717 C-c C-b message-goto-body (move to beginning of message text).
718 C-c C-i message-goto-signature (move to the beginning of the signature).
719 C-c C-w message-insert-signature (insert `message-signature-file' file).
720 C-c C-y message-yank-original (insert current message, if any).
721 C-c C-q message-fill-yanked-message (fill what was yanked).
722 C-c C-r message-ceasar-buffer-body (rot13 the message body)."
724 (kill-all-local-variables)
725 (make-local-variable 'message-reply-buffer)
726 (setq message-reply-buffer nil)
727 (make-local-variable 'message-send-actions)
728 (set-syntax-table message-mode-syntax-table)
729 (use-local-map message-mode-map)
730 (setq local-abbrev-table text-mode-abbrev-table)
731 (setq major-mode 'message-mode)
732 (setq mode-name "Message")
733 (setq buffer-offer-save t)
734 (make-local-variable 'font-lock-defaults)
735 (setq font-lock-defaults '(message-font-lock-keywords t))
736 (make-local-variable 'facemenu-add-face-function)
737 (make-local-variable 'facemenu-remove-face-function)
738 (setq facemenu-add-face-function
740 (let ((face-fun (cdr (assq face message-face-alist))))
742 (funcall face-fun (point) end)
743 (error "Face %s not configured for %s mode" face mode-name)))
745 facemenu-remove-face-function t)
746 (make-local-variable 'paragraph-separate)
747 (make-local-variable 'paragraph-start)
748 (setq paragraph-start (concat (regexp-quote mail-header-separator)
749 "$\\|[ \t]*[-_][-_][-_]+$\\|"
751 (setq paragraph-separate (concat (regexp-quote mail-header-separator)
752 "$\\|[ \t]*[-_][-_][-_]+$\\|"
754 (make-local-variable 'message-reply-headers)
755 (setq message-reply-headers nil)
756 (make-local-variable 'message-newsreader)
757 (make-local-variable 'message-mailer)
758 (make-local-variable 'message-post-method)
759 (make-local-variable 'message-sent-message-via)
760 (setq message-sent-message-via nil)
761 (make-local-variable 'message-checksum)
762 (setq message-checksum nil)
763 (when (fboundp 'mail-hist-define-keys)
764 (mail-hist-define-keys))
765 (when (string-match "XEmacs\\|Lucid" emacs-version)
766 (message-setup-toolbar))
767 (easy-menu-add message-mode-menu message-mode-map)
768 (run-hooks 'text-mode-hook 'message-mode-hook))
773 ;;; Message mode commands
776 ;;; Movement commands
778 (defun message-goto-to ()
779 "Move point to the To header."
781 (message-position-on-field "To"))
783 (defun message-goto-subject ()
784 "Move point to the Subject header."
786 (message-position-on-field "Subject"))
788 (defun message-goto-cc ()
789 "Move point to the Cc header."
791 (message-position-on-field "Cc" "To"))
793 (defun message-goto-bcc ()
794 "Move point to the Bcc header."
796 (message-position-on-field "Bcc" "Cc" "To"))
798 (defun message-goto-fcc ()
799 "Move point to the Fcc header."
801 (message-position-on-field "Fcc" "To" "Newsgroups"))
803 (defun message-goto-reply-to ()
804 "Move point to the Reply-To header."
806 (message-position-on-field "Reply-To" "Subject"))
808 (defun message-goto-newsgroups ()
809 "Move point to the Newsgroups header."
811 (message-position-on-field "Newsgroups"))
813 (defun message-goto-distribution ()
814 "Move point to the Distribution header."
816 (message-position-on-field "Distribution"))
818 (defun message-goto-followup-to ()
819 "Move point to the Followup-To header."
821 (message-position-on-field "Followup-To" "Newsgroups"))
823 (defun message-goto-keywords ()
824 "Move point to the Keywords header."
826 (message-position-on-field "Keywords" "Subject"))
828 (defun message-goto-summary ()
829 "Move point to the Summary header."
831 (message-position-on-field "Summary" "Subject"))
833 (defun message-goto-body ()
834 "Move point to the beginning of the message body."
836 (goto-char (point-min))
837 (search-forward (concat "\n" mail-header-separator "\n") nil t))
839 (defun message-goto-signature ()
840 "Move point to the beginning of the message signature."
842 (goto-char (point-min))
843 (or (re-search-forward message-signature-separator nil t)
844 (goto-char (point-max))))
848 (defun message-insert-to ()
849 "Insert a To header that points to the author of the article being replied to."
851 (when (message-position-on-field "To")
853 (insert (or (message-fetch-reply-field "reply-to")
854 (message-fetch-reply-field "from") "")))
856 (defun message-insert-newsgroups ()
857 "Insert the Newsgroups header from the article being replied to."
859 (when (message-position-on-field "Newsgroups")
861 (insert (or (message-fetch-reply-field "newsgroups") "")))
867 (defun message-insert-signature (&optional force)
868 "Insert a signature. See documentation for the `message-signature' variable."
869 (interactive (list t))
871 (cond ((and (null message-signature)
874 ((message-functionp message-signature)
875 (funcall message-signature))
876 ((listp message-signature)
877 (eval message-signature))
878 (t message-signature)))
880 (cond ((stringp signature)
882 ((and (eq t signature)
883 message-signature-file
884 (file-exists-p message-signature-file))
887 ;; Remove blank lines at the end of the message.
888 (goto-char (point-max))
889 (skip-chars-backward " \t\n")
891 (delete-region (point) (point-max))
892 ;; Insert the signature.
895 (insert-file-contents message-signature-file)
897 (goto-char (point-max))
898 (or (bolp) (insert "\n")))))
900 (defvar message-caesar-translation-table nil)
902 (defun message-caesar-region (b e &optional n)
903 "Caesar rotation of region by N, default 13, for decrypting netnews."
906 (min (point) (or (mark t) (point)))
907 (max (point) (or (mark t) (point)))
908 (when current-prefix-arg
909 (prefix-numeric-value current-prefix-arg))))
911 (setq n (if (numberp n) (mod n 26) 13)) ;canonize N
912 (unless (or (zerop n) ; no action needed for a rot of 0
913 (= b e)) ; no region to rotate
914 ;; We build the table, if necessary.
915 (when (or (not message-caesar-translation-table)
916 (/= (aref message-caesar-translation-table ?a) (+ ?a n)))
918 (table (make-string 256 0)))
919 (while (< (incf i) 256)
923 (substring table 0 ?A)
924 (substring table (+ ?A n) (+ ?A n (- 26 n)))
925 (substring table ?A (+ ?A n))
926 (substring table (+ ?A 26) ?a)
927 (substring table (+ ?a n) (+ ?a n (- 26 n)))
928 (substring table ?a (+ ?a n))
929 (substring table (+ ?a 26) 255)))
930 (setq message-caesar-translation-table table)))
931 ;; Then we translate the region. Do it this way to retain
934 (subst-char-in-region
935 b (1+ b) (char-after b)
936 (aref message-caesar-translation-table (char-after b)))
939 (defun message-caesar-buffer-body (&optional rotnum)
940 "Caesar rotates all letters in the current buffer by 13 places.
941 Used to encode/decode possibly offensive messages (commonly in net.jokes).
942 With prefix arg, specifies the number of places to rotate each letter forward.
943 Mail and USENET news headers are not rotated."
944 (interactive (if current-prefix-arg
945 (list (prefix-numeric-value current-prefix-arg))
949 (when (message-goto-body)
950 (narrow-to-region (point) (point-max)))
951 (message-caesar-region (point-min) (point-max) rotnum))))
953 (defun message-fill-yanked-message (&optional justifyp)
954 "Fill the paragraphs of a message yanked into this one.
955 Numeric argument means justify as well."
958 (goto-char (point-min))
959 (search-forward (concat "\n" mail-header-separator "\n") nil t)
960 (let ((fill-prefix message-yank-prefix))
961 (fill-individual-paragraphs (point) (point-max) justifyp t))))
963 (defun message-indent-citation ()
964 "Modify text just inserted from a message to be cited.
965 The inserted text should be the region.
966 When this function returns, the region is again around the modified text.
968 Normally, indent each nonblank line `message-indentation-spaces' spaces.
969 However, if `message-yank-prefix' is non-nil, insert that prefix on each line."
970 (let ((start (point)))
971 ;; Remove unwanted headers.
972 (when message-ignored-cited-headers
976 (if (search-forward "\n\n" nil t)
979 (message-remove-header message-ignored-cited-headers t)))
980 ;; Do the indentation.
981 (if (null message-yank-prefix)
982 (indent-rigidly start (mark t) message-indentation-spaces)
985 (while (< (point) (mark t))
986 (insert message-yank-prefix)
990 (defun message-yank-original (&optional arg)
991 "Insert the message being replied to, if any.
992 Puts point before the text and mark after.
993 Normally indents each nonblank line ARG spaces (default 3). However,
994 if `message-yank-prefix' is non-nil, insert that prefix on each line.
996 Just \\[universal-argument] as argument means don't indent, insert no
997 prefix, and don't delete any headers."
999 (let ((modified (buffer-modified-p)))
1000 (when (and message-reply-buffer
1001 message-cite-function)
1002 (delete-windows-on message-reply-buffer t)
1003 (insert-buffer message-reply-buffer)
1004 (funcall message-cite-function)
1005 (exchange-point-and-mark)
1009 (setq message-checksum (message-checksum))))))
1011 (defun message-cite-original ()
1012 (let ((start (point))
1014 (when message-indent-citation-function
1015 (if (listp message-indent-citation-function)
1016 message-indent-citation-function
1017 (list message-indent-citation-function)))))
1020 (funcall (pop functions)))
1021 (when message-citation-line-function
1024 (funcall message-citation-line-function))))
1026 (defun message-insert-citation-line ()
1027 "Function that inserts a simple citation line."
1028 (when message-reply-headers
1029 (insert (mail-header-from message-reply-headers) " writes:\n\n")))
1031 (defun message-position-on-field (header &rest afters)
1032 (let ((case-fold-search t))
1035 (goto-char (point-min))
1038 (concat "^" (regexp-quote mail-header-separator) "$"))
1039 (match-beginning 0)))
1040 (goto-char (point-min))
1041 (if (re-search-forward (concat "^" (regexp-quote header) ":") nil t)
1043 (re-search-forward "^[^ \t]" nil 'move)
1045 (skip-chars-backward "\n")
1048 (not (re-search-forward
1049 (concat "^" (regexp-quote (car afters)) ":")
1053 (re-search-forward "^[^ \t]" nil 'move)
1054 (beginning-of-line))
1055 (insert header ": \n")
1059 (defun message-remove-signature ()
1060 "Remove the signature from the text between point and mark.
1061 The text will also be indented the normal way."
1063 (let ((start (point))
1065 (if (not (re-search-forward message-signature-separator (mark t) t))
1066 ;; No signature here, so we just indent the cited text.
1067 (message-indent-citation)
1068 ;; Find the last non-empty line.
1070 (while (looking-at "[ \t]*$")
1073 (setq mark (set-marker (make-marker) (point)))
1075 (message-indent-citation)
1076 ;; Enable undoing the deletion.
1078 (delete-region mark (mark t))
1079 (set-marker mark nil)))))
1084 ;;; Sending messages
1087 (defun message-send-and-exit (&optional arg)
1088 "Send message like `message-send', then, if no errors, exit from mail buffer."
1090 (let ((buf (current-buffer)))
1091 (when (and (message-send arg)
1093 (if message-kill-buffer-on-exit
1096 (when (eq buf (current-buffer))
1097 (message-bury buf))))))
1099 (defun message-dont-send ()
1100 "Don't send the message you have been editing."
1102 (message-bury (current-buffer)))
1104 (defun message-bury (buffer)
1105 "Bury this mail buffer."
1106 (let ((newbuf (other-buffer buffer)))
1107 (bury-buffer buffer)
1108 (if (and (fboundp 'frame-parameters)
1109 (cdr (assq 'dedicated (frame-parameters)))
1110 (not (null (delq (selected-frame) (visible-frame-list)))))
1111 (delete-frame (selected-frame))
1112 (switch-to-buffer newbuf))))
1114 (defun message-send (&optional arg)
1115 "Send the message in the current buffer.
1116 If `message-interactive' is non-nil, wait for success indication
1117 or error messages, and inform user.
1118 Otherwise any failure is reported in a message back to
1119 the user from the mailer."
1121 (when (if buffer-file-name
1122 (y-or-n-p (format "Send buffer contents as %s message? "
1123 (if (message-mail-p)
1124 (if (message-news-p) "mail and news" "mail")
1126 (or (buffer-modified-p)
1127 (y-or-n-p "No changes in the buffer; really send? ")))
1128 ;; Make it possible to undo the coming changes.
1130 (run-hooks 'message-send-hook)
1131 (message "Sending...")
1132 (when (and (or (not (message-news-p))
1133 (and (or (not (memq 'news message-sent-message-via))
1135 "Already sent message via news; resend? "))
1136 (funcall message-send-news-function arg)))
1137 (or (not (message-mail-p))
1138 (and (or (not (memq 'mail message-sent-message-via))
1140 "Already sent message via mail; resend? "))
1141 (funcall message-send-mail-function arg))))
1143 (when (fboundp 'mail-hist-put-headers-into-history)
1144 (mail-hist-put-headers-into-history))
1145 (run-hooks 'message-sent-hook)
1146 (message "Sending...done")
1147 ;; If buffer has no file, mark it as unmodified and delete autosave.
1148 (unless buffer-file-name
1149 (set-buffer-modified-p nil)
1150 (delete-auto-save-file-if-necessary t))
1151 ;; Now perform actions on successful sending.
1152 (let ((actions message-send-actions))
1155 (apply (caar actions) (cdar actions))
1161 (defun message-send-mail (&optional arg)
1162 (require 'mail-utils)
1163 (let ((errbuf (if message-interactive
1164 (generate-new-buffer " sendmail errors")
1166 (tembuf (generate-new-buffer " message temp"))
1167 (case-fold-search nil)
1168 (news (message-news-p))
1169 resend-to-addresses delimline
1170 (mailbuf (current-buffer)))
1172 (message-narrow-to-headers)
1173 (setq resend-to-addresses (mail-fetch-field "resent-to"))
1174 ;; Insert some headers.
1175 (message-generate-headers message-required-mail-headers)
1176 ;; Let the user do all of the above.
1177 (run-hooks 'message-header-hook))
1182 (insert-buffer-substring mailbuf)
1183 ;; Remove some headers.
1185 (message-narrow-to-headers)
1186 ;; Remove some headers.
1187 (message-remove-header message-ignored-mail-headers t))
1188 (goto-char (point-max))
1189 ;; require one newline at the end.
1190 (or (= (preceding-char) ?\n)
1193 (or (mail-fetch-field "cc")
1194 (mail-fetch-field "to")))
1195 (message-insert-courtesy-copy))
1196 (let ((case-fold-search t))
1197 ;; Change header-delimiter to be what sendmail expects.
1198 (goto-char (point-min))
1200 (concat "^" (regexp-quote mail-header-separator) "\n"))
1201 (replace-match "\n")
1203 (setq delimline (point-marker))
1204 ;; Insert an extra newline if we need it to work around
1205 ;; Sun's bug that swallows newlines.
1206 (goto-char (1+ delimline))
1207 (when (eval message-mailer-swallows-blank-line)
1209 (when message-interactive
1213 (let ((default-directory "/"))
1214 (apply 'call-process-region
1215 (append (list (point-min) (point-max)
1216 (if (boundp 'sendmail-program)
1218 "/usr/lib/sendmail")
1219 nil errbuf nil "-oi")
1220 ;; Always specify who from,
1221 ;; since some systems have broken sendmails.
1222 (list "-f" (user-login-name))
1223 ;; These mean "report errors by mail"
1224 ;; and "deliver in background".
1225 (if (null message-interactive) '("-oem" "-odb"))
1226 ;; Get the addresses from the message
1227 ;; unless this is a resend.
1228 ;; We must not do that for a resend
1229 ;; because we would find the original addresses.
1230 ;; For a resend, include the specific addresses.
1231 (if resend-to-addresses
1232 (list resend-to-addresses)
1234 (when message-interactive
1237 (goto-char (point-min))
1238 (while (re-search-forward "\n\n* *" nil t)
1239 (replace-match "; "))
1240 (if (not (zerop (buffer-size)))
1241 (error "Sending...failed to %s"
1242 (buffer-substring (point-min) (point-max)))))))
1243 (kill-buffer tembuf)
1244 (when (bufferp errbuf)
1245 (kill-buffer errbuf)))
1246 (set-buffer mailbuf)
1247 (push 'mail message-sent-message-via)))
1249 (defun message-send-news (&optional arg)
1250 (let ((tembuf (generate-new-buffer " *message temp*"))
1251 (case-fold-search nil)
1252 (method (if (message-functionp message-post-method)
1253 (funcall message-post-method arg)
1254 message-post-method))
1255 (messbuf (current-buffer)))
1257 (message-narrow-to-headers)
1258 ;; Insert some headers.
1259 (message-generate-headers message-required-news-headers)
1260 ;; Let the user do all of the above.
1261 (run-hooks 'message-header-hook))
1262 (when (message-check-news-syntax)
1266 (buffer-disable-undo (current-buffer))
1268 (insert-buffer-substring messbuf)
1269 ;; Remove some headers.
1271 (message-narrow-to-headers)
1272 ;; Remove some headers.
1273 (message-remove-header message-ignored-news-headers t))
1274 (goto-char (point-max))
1275 ;; require one newline at the end.
1276 (or (= (preceding-char) ?\n)
1278 (let ((case-fold-search t))
1279 ;; Remove the delimeter.
1280 (goto-char (point-min))
1282 (concat "^" (regexp-quote mail-header-separator) "\n"))
1283 (replace-match "\n")
1285 (require (car method))
1286 (funcall (intern (format "%s-open-server" (car method)))
1287 (cadr method) (cddr method))
1288 (funcall (intern (format "%s-request-post"
1290 (kill-buffer tembuf))
1291 (set-buffer messbuf)
1292 (push 'news message-sent-message-via))))
1295 ;;; Header generation & syntax checking.
1298 (defun message-check-news-syntax ()
1299 "Check the syntax of the message."
1301 ;; We narrow to the headers and check them first.
1304 (message-narrow-to-headers)
1306 ;; Check for commands in Subject.
1308 (message-check-element 'subject-cmsg)
1310 (if (string-match "^cmsg " (mail-fetch-field "subject"))
1312 "The control code \"cmsg \" is in the subject. Really post? ")
1314 ;; Check for multiple identical headers.
1315 (or (message-check-element 'multiple-headers)
1318 (while (and (not found)
1319 (re-search-forward "^[^ \t:]+: " nil t))
1321 (or (re-search-forward
1322 (concat "^" (setq found
1325 (- (match-end 0) 2))))
1330 (format "Multiple %s headers. Really post? " found))
1332 ;; Check for Version and Sendsys.
1333 (or (message-check-element 'sendsys)
1335 (if (re-search-forward "^Sendsys:\\|^Version:" nil t)
1337 (format "The article contains a %s command. Really post? "
1338 (buffer-substring (match-beginning 0)
1339 (1- (match-end 0)))))
1341 ;; See whether we can shorten Followup-To.
1342 (or (message-check-element 'shorten-followup-to)
1343 (let ((newsgroups (mail-fetch-field "newsgroups"))
1344 (followup-to (mail-fetch-field "followup-to"))
1346 (when (and newsgroups (string-match "," newsgroups)
1351 (setq to (completing-read
1352 "Followups to: (default all groups) "
1353 (mapcar (lambda (g) (list g))
1355 (message-tokenize-header
1357 (goto-char (point-min))
1358 (insert "Followup-To: " to "\n"))
1361 ;; Check for Approved.
1362 (or (message-check-element 'approved)
1364 (if (re-search-forward "^Approved:" nil t)
1366 "The article contains an Approved header. Really post? ")
1368 ;; Check the Message-Id header.
1369 (or (message-check-element 'message-id)
1371 (let* ((case-fold-search t)
1372 (message-id (mail-fetch-field "message-id")))
1373 (or (not message-id)
1374 (and (string-match "@" message-id)
1375 (string-match "@[^\\.]*\\." message-id))
1378 "The Message-ID looks strange: \"%s\". Really post? "
1380 ;; Check the Subject header.
1382 (message-check-element 'subject)
1384 (let* ((case-fold-search t)
1385 (subject (mail-fetch-field "subject")))
1388 (not (string-match "\\`[ \t]*\\'" subject)))
1391 "The subject field is empty or missing. Posting is denied.")
1393 ;; Check the From header.
1394 (or (message-check-element 'from)
1396 (let* ((case-fold-search t)
1397 (from (mail-fetch-field "from")))
1400 (message "There is no From line. Posting is denied.")
1402 ((not (string-match "@[^\\.]*\\." from))
1404 "Denied posting -- the From looks strange: \"%s\"." from)
1406 ((string-match "@[^@]*@" from)
1408 "Denied posting -- two \"@\"'s in the From header: %s."
1411 ((string-match "(.*).*(.*)" from)
1413 "Denied posting -- the From header looks strange: \"%s\"."
1417 ;; Check for long lines.
1418 (or (message-check-element 'long-lines)
1420 (goto-char (point-min))
1422 (concat "^" (regexp-quote mail-header-separator) "$"))
1426 (< (current-column) 80))
1427 (zerop (forward-line 1))))
1431 "You have lines longer than 79 characters. Really post? "))))
1432 ;; Check whether the article is empty.
1433 (or (message-check-element 'empty)
1435 (goto-char (point-min))
1437 (concat "^" (regexp-quote mail-header-separator) "$"))
1440 (or (re-search-forward message-signature-separator nil t)
1441 (goto-char (point-max)))
1443 (or (re-search-backward "[^ \n\t]" b t)
1444 (y-or-n-p "Empty article. Really post? ")))))
1445 ;; Check for control characters.
1446 (or (message-check-element 'control-chars)
1448 (if (re-search-forward "[\000-\007\013\015-\037\200-\237]" nil t)
1450 "The article contains control characters. Really post? ")
1452 ;; Check excessive size.
1453 (or (message-check-element 'size)
1454 (if (> (buffer-size) 60000)
1456 (format "The article is %d octets long. Really post? "
1459 ;; Check whether any new text has been added.
1460 (or (message-check-element 'new-text)
1461 (not message-checksum)
1462 (not (eq (message-checksum) message-checksum))
1464 "It looks like no new text has been added. Really post? "))
1465 ;; Check the length of the signature.
1466 (or (message-check-element 'signature)
1468 (goto-char (point-max))
1469 (if (not (re-search-backward "^-- $" nil t))
1471 (if (> (count-lines (point) (point-max)) 5)
1474 "Your .sig is %d lines; it should be max 4. Really post? "
1475 (count-lines (point) (point-max))))
1478 (defun message-check-element (type)
1479 "Returns non-nil if this type is not to be checked."
1480 (if (eq message-syntax-checks 'dont-check-for-anything-just-trust-me)
1482 (let ((able (assq type message-syntax-checks)))
1484 (eq (cdr able) 'disabled)))))
1486 (defun message-checksum ()
1487 "Return a \"checksum\" for the current buffer."
1490 (goto-char (point-min))
1492 (concat "^" (regexp-quote mail-header-separator) "$"))
1494 (setq sum (logxor sum (following-char)))
1498 (defun message-do-fcc ()
1499 "Process Fcc headers in the current buffer."
1500 (let ((case-fold-search t)
1501 (buf (current-buffer))
1504 (set-buffer (get-buffer-create " *message temp*"))
1505 (buffer-disable-undo (current-buffer))
1507 (insert-buffer-substring buf)
1509 (message-narrow-to-headers)
1510 (while (setq file (mail-fetch-field "fcc"))
1512 (message-remove-header "fcc" nil t)))
1513 (goto-char (point-min))
1514 (re-search-forward (concat "^" (regexp-quote mail-header-separator) "$"))
1515 (replace-match "" t t)
1516 ;; Process FCC operations.
1518 (setq file (pop list))
1519 (if (string-match "^[ \t]*|[ \t]*\\(.*\\)[ \t]*$" file)
1520 ;; Pipe the article to the program in question.
1521 (call-process-region (point-min) (point-max) shell-file-name
1522 nil nil nil "-c" (match-string 1 file))
1523 ;; Save the article.
1524 (setq file (expand-file-name file))
1525 (unless (file-exists-p (file-name-directory file))
1526 (make-directory (file-name-directory file) t))
1527 (if (and message-fcc-handler-function
1528 (not (eq message-fcc-handler-function 'rmail-output)))
1529 (funcall message-fcc-handler-function file)
1530 (if (and (file-readable-p file) (mail-file-babyl-p file))
1531 (rmail-output file 1)
1532 (let ((mail-use-rfc822 t))
1533 (rmail-output file 1 t t))))))
1534 (kill-buffer (current-buffer)))))
1536 (defun message-cleanup-headers ()
1537 "Do various automatic cleanups of the headers."
1538 ;; Remove empty lines in the header.
1540 (message-narrow-to-headers)
1541 (while (re-search-forward "^[ \t]*\n" nil t)
1542 (replace-match "" t t)))
1544 ;; Correct Newsgroups and Followup-To headers: change sequence of
1545 ;; spaces to comma and eliminate spaces around commas. Eliminate
1546 ;; embedded line breaks.
1547 (goto-char (point-min))
1548 (while (re-search-forward "^\\(Newsgroups\\|Followup-To\\): +" nil t)
1552 (if (re-search-forward "^[^ \t]" nil t)
1556 (goto-char (point-min))
1557 (while (re-search-forward "\n[ \t]+" nil t)
1558 (replace-match " " t t)) ;No line breaks (too confusing)
1559 (goto-char (point-min))
1560 (while (re-search-forward "[ \t\n]*,[ \t\n]*\\|[ \t]+" nil t)
1561 (replace-match "," t t))
1562 (goto-char (point-min))
1563 ;; Remove trailing commas.
1564 (when (re-search-forward ",+$" nil t)
1565 (replace-match "" t t)))))
1567 (defun message-make-date ()
1568 "Make a valid data header."
1569 (let ((now (current-time)))
1570 (timezone-make-date-arpa-standard
1571 (current-time-string now) (current-time-zone now))))
1573 (defun message-make-message-id ()
1574 "Make a unique Message-ID."
1575 (concat "<" (message-unique-id)
1576 (let ((psubject (save-excursion (mail-fetch-field "subject"))))
1577 (if (and message-reply-headers
1578 (mail-header-references message-reply-headers)
1579 (mail-header-subject message-reply-headers)
1581 (mail-header-subject message-reply-headers)
1583 (message-strip-subject-re
1584 (mail-header-subject message-reply-headers))
1585 (message-strip-subject-re psubject))))
1587 "@" (message-make-fqdm) ">"))
1589 (defvar message-unique-id-char nil)
1591 ;; If you ever change this function, make sure the new version
1592 ;; cannot generate IDs that the old version could.
1593 ;; You might for example insert a "." somewhere (not next to another dot
1594 ;; or string boundary), or modify the "fsf" string.
1595 (defun message-unique-id ()
1596 ;; Don't use microseconds from (current-time), they may be unsupported.
1597 ;; Instead we use this randomly inited counter.
1598 (setq message-unique-id-char
1599 (% (1+ (or message-unique-id-char (logand (random t) (1- (lsh 1 20)))))
1600 ;; (current-time) returns 16-bit ints,
1601 ;; and 2^16*25 just fits into 4 digits i base 36.
1603 (let ((tm (current-time)))
1605 (if (memq system-type '(ms-dos emx vax-vms))
1606 (let ((user (downcase (user-login-name))))
1607 (while (string-match "[^a-z0-9_]" user)
1608 (aset user (match-beginning 0) ?_))
1610 (message-number-base36 (user-uid) -1))
1611 (message-number-base36 (+ (car tm)
1612 (lsh (% message-unique-id-char 25) 16)) 4)
1613 (message-number-base36 (+ (nth 1 tm)
1614 (lsh (/ message-unique-id-char 25) 16)) 4)
1615 ;; Append the newsreader name, because while the generated
1616 ;; ID is unique to this newsreader, other newsreaders might
1617 ;; otherwise generate the same ID via another algorithm.
1620 (defun message-number-base36 (num len)
1621 (if (if (< len 0) (<= num 0) (= len 0))
1623 (concat (message-number-base36 (/ num 36) (1- len))
1624 (char-to-string (aref "zyxwvutsrqponmlkjihgfedcba9876543210"
1627 (defun message-make-organization ()
1628 "Make an Organization header."
1629 (let* ((organization
1630 (or (getenv "ORGANIZATION")
1631 (when message-user-organization
1632 (if (message-functionp message-user-organization)
1633 (funcall message-user-organization)
1634 message-user-organization)))))
1636 (message-set-work-buffer)
1637 (cond ((stringp organization)
1638 (insert organization))
1639 ((and (eq t organization)
1640 message-user-organization-file
1641 (file-exists-p message-user-organization-file))
1642 (insert-file-contents message-user-organization-file)))
1643 (goto-char (point-min))
1644 (while (re-search-forward "[\t\n]+" nil t)
1645 (replace-match "" t t))
1646 (unless (zerop (buffer-size))
1649 (defun message-make-lines ()
1650 "Count the number of lines and return numeric string."
1654 (goto-char (point-min))
1656 (concat "^" (regexp-quote mail-header-separator) "$"))
1658 (int-to-string (count-lines (point) (point-max))))))
1660 (defun message-make-in-reply-to ()
1661 "Return the In-Reply-To header for this message."
1662 (when message-reply-headers
1663 (let ((from (mail-header-from message-reply-headers))
1664 (date (mail-header-date message-reply-headers)))
1667 (string-match " *at \\| *@ \\| *(\\| *<" from)))
1668 (concat (if stop-pos (substring from 0 stop-pos) from)
1670 (if (or (not date) (string= date ""))
1671 "(unknown date)" date)))))))
1673 (defun message-make-distribution ()
1674 "Make a Distribution header."
1675 (let ((orig-distribution (message-fetch-reply-field "distribution")))
1676 (cond ((message-functionp message-distribution-function)
1677 (funcall message-distribution-function))
1678 (t orig-distribution))))
1680 (defun message-make-expires ()
1681 "Return an Expires header based on `message-expires'."
1682 (let ((current (current-time))
1683 (future (* 1.0 message-expires 60 60 24)))
1684 ;; Add the future to current.
1685 (setcar current (+ (car current) (round (/ future (expt 2 16)))))
1686 (setcar (cdr current) (+ (nth 1 current) (% (round future) (expt 2 16))))
1687 ;; Return the date in the future in UT.
1688 (timezone-make-date-arpa-standard
1689 (current-time-string current) (current-time-zone current) '(0 "UT"))))
1691 (defun message-make-path ()
1693 (let ((login-name (user-login-name)))
1694 (cond ((null message-user-path)
1695 (concat (system-name) "!" login-name))
1696 ((stringp message-user-path)
1697 ;; Support GENERICPATH. Suggested by vixie@decwrl.dec.com.
1698 (concat message-user-path "!" login-name))
1701 (defun message-make-from ()
1702 "Make a From header."
1703 (let* ((login (message-make-address))
1704 (fullname (user-full-name)))
1705 (when (string= fullname "&")
1706 (setq fullname (user-login-name)))
1708 (message-set-work-buffer)
1710 ((or (null message-from-style)
1711 (equal fullname ""))
1713 ((or (eq message-from-style 'angles)
1714 (and (not (eq message-from-style 'parens))
1715 ;; Use angles if no quoting is needed, or if parens would
1716 ;; need quoting too.
1717 (or (not (string-match "[^- !#-'*+/-9=?A-Z^-~]" fullname))
1718 (let ((tmp (concat fullname nil)))
1719 (while (string-match "([^()]*)" tmp)
1720 (aset tmp (match-beginning 0) ?-)
1721 (aset tmp (1- (match-end 0)) ?-))
1722 (string-match "[\\()]" tmp)))))
1724 (goto-char (point-min))
1725 ;; Look for a character that cannot appear unquoted
1726 ;; according to RFC 822.
1727 (when (re-search-forward "[^- !#-'*+/-9=?A-Z^-~]" nil 1)
1728 ;; Quote fullname, escaping specials.
1729 (goto-char (point-min))
1731 (while (re-search-forward "[\"\\]" nil 1)
1732 (replace-match "\\\\\\&" t))
1734 (insert " <" login ">"))
1735 (t ; 'parens or default
1737 (let ((fullname-start (point)))
1739 (goto-char fullname-start)
1740 ;; RFC 822 says \ and nonmatching parentheses
1741 ;; must be escaped in comments.
1742 ;; Escape every instance of ()\ ...
1743 (while (re-search-forward "[()\\]" nil 1)
1744 (replace-match "\\\\\\&" t))
1745 ;; ... then undo escaping of matching parentheses,
1746 ;; including matching nested parentheses.
1747 (goto-char fullname-start)
1748 (while (re-search-forward
1749 "\\(\\=\\|[^\\]\\(\\\\\\\\\\)*\\)\\\\(\\(\\([^\\]\\|\\\\\\\\\\)*\\)\\\\)"
1751 (replace-match "\\1(\\3)" t)
1752 (goto-char fullname-start)))
1756 (defun message-make-sender ()
1757 "Return the \"real\" user address.
1758 This function tries to ignore all user modifications, and
1759 give as trustworthy answer as possible."
1760 (concat (user-login-name) "@" (system-name)))
1762 (defun message-make-address ()
1763 "Make the address of the user."
1764 (or (message-user-mail-address)
1765 (concat (user-login-name) "@" (message-make-domain))))
1767 (defun message-user-mail-address ()
1768 "Return the pertinent part of `user-mail-address'."
1769 (when user-mail-address
1770 (nth 1 (mail-extract-address-components user-mail-address))))
1772 (defun message-make-fqdm ()
1773 "Return user's fully qualified domain name."
1774 (let ((system-name (system-name)))
1776 ((string-match "[^.]\\.[^.]" system-name)
1777 ;; `system-name' returned the right result.
1779 ;; We try `user-mail-address' as a backup.
1780 ((string-match "@\\(.*\\)\\'" (message-user-mail-address))
1781 (match-string 1 user-mail-address))
1782 ;; Try `mail-host-address'.
1783 ((and (boundp 'mail-host-address)
1786 ;; Default to this bogus thing.
1788 (concat system-name ".i-have-a-misconfigured-system-so-shoot-me")))))
1790 (defun message-make-host-name ()
1791 "Return the name of the host."
1792 (let ((fqdm (message-make-fqdm)))
1793 (string-match "^[^.]+\\." fqdm)
1794 (substring fqdm 0 (1- (match-end 0)))))
1796 (defun message-make-domain ()
1797 "Return the domain name."
1798 (or mail-host-address
1799 (message-make-fqdm)))
1801 (defun message-generate-headers (headers)
1802 "Prepare article HEADERS.
1803 Headers already prepared in the buffer are not modified."
1805 (message-narrow-to-headers)
1806 (let* ((Date (message-make-date))
1807 (Message-ID (message-make-message-id))
1808 (Organization (message-make-organization))
1809 (From (message-make-from))
1810 (Path (message-make-path))
1813 (In-Reply-To (message-make-in-reply-to))
1815 (Distribution (message-make-distribution))
1816 (Lines (message-make-lines))
1817 (X-Newsreader message-newsreader)
1818 (X-Mailer (and (not (mail-fetch-field "X-Newsreader"))
1820 (Expires (message-make-expires))
1821 (case-fold-search t)
1823 ;; First we remove any old generated headers.
1824 (let ((headers message-deletable-headers))
1826 (goto-char (point-min))
1827 (and (re-search-forward
1828 (concat "^" (symbol-name (car headers)) ": *") nil t)
1829 (get-text-property (1+ (match-beginning 0)) 'message-deletable)
1830 (message-delete-line))
1832 ;; Go through all the required headers and see if they are in the
1833 ;; articles already. If they are not, or are empty, they are
1834 ;; inserted automatically - except for Subject, Newsgroups and
1837 (goto-char (point-min))
1838 (setq elem (pop headers))
1840 (if (eq (car elem) 'optional)
1841 (setq header (cdr elem))
1842 (setq header (car elem)))
1844 (when (or (not (re-search-forward
1845 (concat "^" (downcase (symbol-name header)) ":")
1848 ;; The header was found. We insert a space after the
1849 ;; colon, if there is none.
1850 (if (/= (following-char) ? ) (insert " ") (forward-char 1))
1851 ;; Find out whether the header is empty...
1852 (looking-at "[ \t]*$")))
1853 ;; So we find out what value we should insert.
1856 ((and (consp elem) (eq (car elem) 'optional))
1857 ;; This is an optional header. If the cdr of this
1858 ;; is something that is nil, then we do not insert
1860 (setq header (cdr elem))
1861 (or (and (fboundp (cdr elem)) (funcall (cdr elem)))
1862 (and (boundp (cdr elem)) (symbol-value (cdr elem)))))
1864 ;; The element is a cons. Either the cdr is a
1865 ;; string to be inserted verbatim, or it is a
1866 ;; function, and we insert the value returned from
1868 (or (and (stringp (cdr elem)) (cdr elem))
1869 (and (fboundp (cdr elem)) (funcall (cdr elem)))))
1870 ((and (boundp header) (symbol-value header))
1871 ;; The element is a symbol. We insert the value
1872 ;; of this symbol, if any.
1873 (symbol-value header))
1875 ;; We couldn't generate a value for this header,
1876 ;; so we just ask the user.
1877 (read-from-minibuffer
1878 (format "Empty header for %s; enter value: " header)))))
1879 ;; Finally insert the header.
1881 (not (equal value "")))
1885 ;; This header didn't exist, so we insert it.
1886 (goto-char (point-max))
1887 (insert (symbol-name header) ": " value "\n")
1889 ;; The value of this header was empty, so we clear
1890 ;; totally and insert the new value.
1891 (delete-region (point) (message-point-at-eol))
1893 ;; Add the deletable property to the headers that require it.
1894 (and (memq header message-deletable-headers)
1895 (progn (beginning-of-line) (looking-at "[^:]+: "))
1896 (add-text-properties
1897 (point) (match-end 0)
1898 '(message-deletable t face italic) (current-buffer)))))))
1899 ;; Insert new Sender if the From is strange.
1900 (let ((from (mail-fetch-field "from"))
1901 (sender (mail-fetch-field "sender"))
1902 (secure-sender (message-make-sender)))
1904 (not (message-check-element 'sender))
1907 (cadr (mail-extract-address-components from)))
1908 (downcase secure-sender)))
1913 (cadr (mail-extract-address-components sender)))
1914 (downcase secure-sender)))))
1915 (goto-char (point-min))
1916 ;; Rename any old Sender headers to Original-Sender.
1917 (when (re-search-forward "^Sender:" nil t)
1919 (insert "Original-")
1920 (beginning-of-line))
1921 (insert "Sender: " secure-sender "\n"))))))
1923 (defun message-insert-courtesy-copy ()
1924 "Insert a courtesy message in mail copies of combined messages."
1927 (message-narrow-to-headers)
1928 (let ((newsgroups (mail-fetch-field "newsgroups")))
1930 (goto-char (point-max))
1931 (insert "Posted-To: " newsgroups "\n"))))
1933 (insert message-courtesy-message)))
1936 ;;; Setting up a message buffer
1939 (defun message-fill-header (header value)
1940 (let ((begin (point))
1943 (insert (capitalize (symbol-name header))
1945 (if (consp value) (car value) value)
1948 (narrow-to-region begin (point))
1949 (fill-region-as-paragraph begin (point))
1950 ;; Tapdance around looong Message-IDs.
1952 (when (looking-at "[ \t]*$")
1953 (message-delete-line))
1955 (re-search-forward ":" nil t)
1956 (when (looking-at "\n[ \t]+")
1957 (replace-match " " t t))
1958 (goto-char (point-max)))))
1960 (defun message-position-point ()
1961 "Move point to where the user probably wants to find it."
1962 (message-narrow-to-headers)
1964 ((re-search-forward "^[^:]+:[ \t]*$" nil t)
1965 (search-backward ":" )
1968 (if (= (following-char) ? )
1972 (goto-char (point-max))
1975 (unless (looking-at "$")
1979 (defun message-pop-to-buffer (name)
1980 "Pop to buffer NAME, and warn if it already exists and is modified."
1981 (if message-generate-new-buffers
1982 (set-buffer (pop-to-buffer (generate-new-buffer name)))
1983 (let ((buffer (get-buffer name)))
1985 (buffer-name buffer))
1987 (set-buffer (pop-to-buffer buffer))
1988 (when (and (buffer-modified-p)
1990 "Message already being composed; erase? ")))
1991 (error "Message being composed")))
1992 (set-buffer (pop-to-buffer name)))))
1996 (defun message-setup (headers &optional replybuffer actions)
1997 (setq message-send-actions actions)
1998 (setq message-reply-buffer replybuffer)
1999 (goto-char (point-min))
2000 ;; Insert all the headers.
2003 (alist message-header-format-alist))
2005 (unless (assq (caar h) message-header-format-alist)
2006 (push (list (caar h)) alist))
2011 (when message-default-headers
2012 (insert message-default-headers))
2013 (insert mail-header-separator "\n")
2015 (when (message-news-p)
2016 (when message-default-news-headers
2017 (insert message-default-news-headers))
2018 (when message-generate-headers-first
2019 (message-generate-headers
2022 (copy-sequence message-required-news-headers))))))
2023 (when (message-mail-p)
2024 (when message-default-mail-headers
2025 (insert message-default-mail-headers))
2026 (when message-generate-headers-first
2027 (message-generate-headers
2030 (copy-sequence message-required-mail-headers))))))
2031 (message-insert-signature)
2032 (message-set-auto-save-file-name)
2034 (message-narrow-to-headers)
2035 (run-hooks 'message-header-setup-hook))
2036 ;; Allow mail alias things.
2037 (if (fboundp 'mail-abbrevs-setup)
2038 (mail-abbrevs-setup)
2039 (funcall (intern "mail-aliases-setup")))
2040 (set-buffer-modified-p nil)
2041 (run-hooks 'message-setup-hook)
2042 (message-position-point)
2045 (defun message-set-auto-save-file-name ()
2046 "Associate the message buffer with a file in the drafts directory."
2047 (when message-autosave-directory
2048 (unless (file-exists-p message-autosave-directory)
2049 (make-directory message-autosave-directory t))
2050 (let ((name (make-temp-name
2051 (concat (file-name-as-directory message-autosave-directory)
2053 (setq buffer-auto-save-file-name
2057 (set-buffer (get-buffer-create " *draft tmp*"))
2058 (setq buffer-file-name name)
2059 (make-auto-save-file-name))
2060 (kill-buffer (current-buffer)))))
2061 (clear-visited-file-modtime))))
2066 ;;; Commands for interfacing with message
2070 (defun message-mail (&optional to subject)
2071 "Start editing a mail message to be sent."
2073 (message-pop-to-buffer "*mail message*")
2074 (message-setup `((To . ,(or to "")) (Subject . ,(or subject "")))))
2077 (defun message-news (&optional newsgroups subject)
2078 "Start editing a news article to be sent."
2080 (message-pop-to-buffer "*news message*")
2081 (message-setup `((Newsgroups . ,(or newsgroups ""))
2082 (Subject . ,(or subject "")))))
2085 (defun message-reply (&optional to-address wide ignore-reply-to)
2086 "Start editing a reply to the article in the current buffer."
2088 (let ((cur (current-buffer))
2089 from subject date reply-to to cc
2090 references message-id follow-to
2091 mct never-mct gnus-warning)
2094 (goto-char (point-min))
2095 (if (search-forward "\n\n" nil t)
2098 ;; Allow customizations to have their say.
2100 ;; This is a regular reply.
2101 (if (message-functionp message-reply-to-function)
2102 (setq follow-to (funcall message-reply-to-function)))
2103 ;; This is a followup.
2104 (if (message-functionp message-wide-reply-to-function)
2107 (funcall message-wide-reply-to-function)))))
2108 ;; Find all relevant headers we need.
2109 (setq from (mail-fetch-field "from")
2110 date (mail-fetch-field "date")
2111 subject (or (mail-fetch-field "subject") "none")
2112 to (mail-fetch-field "to")
2113 cc (mail-fetch-field "cc")
2114 mct (mail-fetch-field "mail-copies-to")
2115 reply-to (unless ignore-reply-to (mail-fetch-field "reply-to"))
2116 references (mail-fetch-field "references")
2117 message-id (mail-fetch-field "message-id"))
2118 ;; Remove any (buggy) Re:'s that are present and make a
2120 (when (string-match "^[ \t]*[Rr][Ee]:[ \t]*" subject)
2121 (setq subject (substring subject (match-end 0))))
2122 (setq subject (concat "Re: " subject))
2124 (when (and (setq gnus-warning (mail-fetch-field "gnus-warning"))
2125 (string-match "<[^>]+>" gnus-warning))
2126 (setq message-id (match-string 0 gnus-warning)))
2128 ;; Handle special values of Mail-Copies-To.
2130 (cond ((equal (downcase mct) "never")
2133 ((equal (downcase mct) "always")
2134 (setq mct (or reply-to from)))))
2139 (setq follow-to (list (cons 'To (or to-address reply-to from))))
2142 (message-set-work-buffer)
2144 (insert (or reply-to from "")))
2146 (if (bolp) "" ", ") (or to "")
2147 (if mct (concat (if (bolp) "" ", ") mct) "")
2148 (if cc (concat (if (bolp) "" ", ") cc) ""))
2149 ;; Remove addresses that match `rmail-dont-reply-to-names'.
2150 (insert (prog1 (rmail-dont-reply-to (buffer-string))
2152 (goto-char (point-min))
2156 (cons (mail-strip-quoted-names addr) addr))
2157 (nreverse (mail-parse-comma-list))))
2160 (setq ccalist (delq (assoc (car (pop s)) s) ccalist)))))
2161 (setq follow-to (list (cons 'To (cdr (pop ccalist)))))
2164 (mapconcat (lambda (addr) (cdr addr)) ccalist ", "))
2168 (message-pop-to-buffer "*mail message*")
2170 (setq message-reply-headers
2171 (vector 0 subject from date message-id references 0 0 ""))
2174 `((Subject . ,subject)
2176 ,@(if (or references message-id)
2177 `((References . ,(concat (or references "") (and references " ")
2178 (or message-id ""))))
2183 (defun message-wide-reply (&optional to-address)
2185 (message-reply to-address t))
2188 (defun message-followup ()
2190 (let ((cur (current-buffer))
2191 from subject date reply-to mct
2192 references message-id follow-to
2193 followup-to distribution newsgroups gnus-warning)
2196 (goto-char (point-min))
2197 (if (search-forward "\n\n" nil t)
2200 (when (message-functionp message-followup-to-function)
2202 (funcall message-followup-to-function)))
2203 (setq from (mail-fetch-field "from")
2204 date (mail-fetch-field "date")
2205 subject (or (mail-fetch-field "subject") "none")
2206 references (mail-fetch-field "references")
2207 message-id (mail-fetch-field "message-id")
2208 followup-to (mail-fetch-field "followup-to")
2209 newsgroups (mail-fetch-field "newsgroups")
2210 reply-to (mail-fetch-field "reply-to")
2211 distribution (mail-fetch-field "distribution")
2212 mct (mail-fetch-field "mail-copies-to"))
2213 (when (and (setq gnus-warning (mail-fetch-field "gnus-warning"))
2214 (string-match "<[^>]+>" gnus-warning))
2215 (setq message-id (match-string 0 gnus-warning)))
2216 ;; Remove bogus distribution.
2217 (and (stringp distribution)
2218 (string-match "world" distribution)
2219 (setq distribution nil))
2220 ;; Remove any (buggy) Re:'s that are present and make a
2222 (when (string-match "^[ \t]*[Rr][Ee]:[ \t]*" subject)
2223 (setq subject (substring subject (match-end 0))))
2224 (setq subject (concat "Re: " subject))
2227 (message-pop-to-buffer "*news message*")
2230 `((Subject . ,subject)
2232 (follow-to follow-to)
2233 ((and followup-to message-use-followup-to)
2236 ((equal (downcase followup-to) "poster")
2237 (if (or (eq message-use-followup-to 'use)
2238 (y-or-n-p "Use Followup-To \"poster\"? "))
2239 (cons 'To (or reply-to from ""))
2240 (cons 'Newsgroups newsgroups)))
2242 (if (or (equal followup-to newsgroups)
2243 (not (eq message-use-followup-to 'ask))
2245 (format "Use Followup-To %s? " followup-to)))
2246 (cons 'Newsgroups followup-to)
2247 (cons 'Newsgroups newsgroups))))))
2249 `((Newsgroups . ,newsgroups))))
2250 ,@(and distribution (list (cons 'Distribution distribution)))
2251 (References . ,(concat (or references "") (and references " ")
2252 (or message-id "")))
2254 (not (equal (downcase mct) "never")))
2255 (list (cons 'Cc (if (equal (downcase mct) "always")
2256 (or reply-to from "")
2261 (setq message-reply-headers
2262 (vector 0 subject from date message-id references 0 0 ""))))
2266 (defun message-cancel-news ()
2267 "Cancel an article you posted."
2269 (unless (message-news-p)
2270 (error "This is not a news article; canceling is impossible"))
2271 (when (yes-or-no-p "Do you really want to cancel this article? "))
2272 (let (from newsgroups message-id distribution buf)
2274 ;; Get header info. from original article.
2276 (message-narrow-to-head)
2277 (setq from (mail-fetch-field "from")
2278 newsgroups (mail-fetch-field "newsgroups")
2279 message-id (mail-fetch-field "message-id")
2280 distribution (mail-fetch-field "distribution")))
2281 ;; Make sure that this article was written by the user.
2282 (unless (string-equal
2283 (downcase (mail-strip-quoted-names from))
2284 (downcase (message-make-address)))
2285 (error "This article is not yours"))
2286 ;; Make control message.
2287 (setq buf (set-buffer (get-buffer-create " *message cancel*")))
2288 (buffer-disable-undo (current-buffer))
2290 (insert "Newsgroups: " newsgroups "\n"
2291 "From: " (message-make-from) "\n"
2292 "Subject: cmsg cancel " message-id "\n"
2293 "Control: cancel " message-id "\n"
2295 (concat "Distribution: " distribution "\n")
2297 mail-header-separator "\n"
2298 "This is a cancel message from " from ".\n")
2299 (message "Canceling your article...")
2300 (let ((message-syntax-checks 'dont-check-for-anything-just-trust-me))
2301 (funcall message-send-news-function))
2302 (message "Canceling your article...done")
2303 (kill-buffer buf))))
2306 (defun message-supersede ()
2307 "Start composing a message to supersede the current message.
2308 This is done simply by taking the old article and adding a Supersedes
2309 header line with the old Message-ID."
2311 (let ((cur (current-buffer)))
2312 ;; Check whether the user owns the article that is to be superseded.
2313 (unless (string-equal
2314 (downcase (mail-strip-quoted-names (mail-fetch-field "from")))
2315 (downcase (mail-strip-quoted-names (message-make-address))))
2316 (error "This article is not yours"))
2317 ;; Get a normal message buffer.
2318 (message-pop-to-buffer "*supersede message*")
2319 (insert-buffer-substring cur)
2320 (message-narrow-to-head)
2321 ;; Remove unwanted headers.
2322 (when message-ignored-supersedes-headers
2323 (message-remove-header message-ignored-supersedes-headers t))
2324 (goto-char (point-min))
2325 (if (not (re-search-forward "^Message-ID: " nil t))
2326 (error "No Message-ID in this article")
2327 (replace-match "Supersedes: " t t))
2328 (goto-char (point-max))
2329 (insert mail-header-separator)
2334 (defun message-recover ()
2335 "Reread contents of current buffer from its last auto-save file."
2337 (let ((file-name (make-auto-save-file-name)))
2338 (cond ((save-window-excursion
2339 (if (not (eq system-type 'vax-vms))
2340 (with-output-to-temp-buffer "*Directory*"
2341 (buffer-disable-undo standard-output)
2342 (let ((default-directory "/"))
2344 "ls" nil standard-output nil "-l" file-name))))
2345 (yes-or-no-p (format "Recover auto save file %s? " file-name)))
2346 (let ((buffer-read-only nil))
2348 (insert-file-contents file-name nil)))
2349 (t (error "message-recover cancelled")))))
2351 ;;; Forwarding messages.
2353 (defun message-make-forward-subject ()
2354 "Return a Subject header suitable for the message in the current buffer."
2355 (concat "[" (mail-fetch-field (if (message-news-p) "newsgroups" "from"))
2356 "] " (or (mail-fetch-field "Subject") "")))
2359 (defun message-forward (&optional news)
2360 "Forward the current message via mail.
2361 Optional NEWS will use news to forward instead of mail."
2363 (let ((cur (current-buffer))
2364 (subject (message-make-forward-subject)))
2365 (if news (message-news nil subject) (message-mail nil subject))
2366 ;; Put point where we want it before inserting the forwarded
2368 (if message-signature-before-forwarded-message
2369 (goto-char (point-max))
2370 (message-goto-body))
2371 ;; Narrow to the area we are to insert.
2372 (narrow-to-region (point) (point))
2373 ;; Insert the separators and the forwarded buffer.
2374 (insert message-forward-start-separator)
2375 (insert-buffer-substring cur)
2376 (goto-char (point-max))
2377 (insert message-forward-end-separator)
2378 (set-text-properties (point-min) (point-max) nil)
2379 ;; Remove all unwanted headers.
2380 (goto-char (point-min))
2382 (narrow-to-region (point) (if (search-forward "\n\n" nil t)
2385 (goto-char (point-min))
2386 (message-remove-header message-included-forward-headers t nil t)
2388 (message-position-point)))
2391 (defun message-resend (address)
2392 "Resend the current article to ADDRESS."
2393 (interactive "sResend message to: ")
2395 (let ((cur (current-buffer))
2397 ;; We first set up a normal mail buffer.
2398 (set-buffer (get-buffer-create " *message resend*"))
2399 (buffer-disable-undo (current-buffer))
2401 (message-setup `((To . ,address)))
2402 ;; Insert our usual headers.
2403 (message-generate-headers '(From Date To))
2404 (message-narrow-to-headers)
2405 ;; Rename them all to "Resent-*".
2406 (while (re-search-forward "^[A-Za-z]" nil t)
2411 (delete-region (point) (point-max))
2413 ;; Insert the message to be resent.
2414 (insert-buffer-substring cur)
2415 (goto-char (point-min))
2416 (search-forward "\n\n")
2419 (narrow-to-region beg (point))
2420 (message-remove-header message-ignored-resent-headers t)
2421 (goto-char (point-max)))
2422 (insert mail-header-separator)
2423 ;; Rename all old ("Also-")Resent headers.
2424 (while (re-search-backward "^\\(Also-\\)?Resent-" beg t)
2428 (funcall message-send-mail-function)
2429 (kill-buffer (current-buffer)))))
2432 (defun message-bounce ()
2433 "Re-mail the current message.
2434 This only makes sense if the current message is a bounce message than
2435 contains some mail you have written which has been bounced back to
2438 (let ((cur (current-buffer))
2440 (message-pop-to-buffer "*mail message*")
2441 (insert-buffer-substring cur)
2443 (message-narrow-to-head)
2444 (if (and (mail-fetch-field "Mime-Version")
2445 (setq boundary (mail-fetch-field "Content-Type")))
2446 (if (string-match "boundary=\"\\([^\"]+\\)\"" boundary)
2447 (setq boundary (concat (match-string 1 boundary) " *\n"
2448 "Content-Type: message/rfc822"))
2449 (setq boundary nil)))
2451 (goto-char (point-min))
2452 (search-forward "\n\n" nil t)
2454 (re-search-forward boundary nil t)
2456 (and (re-search-forward message-unsent-separator nil t)
2458 (and (search-forward "\n\n" nil t)
2459 (re-search-forward "^Return-Path:.*\n" nil t)))
2460 ;; We remove everything before the bounced mail.
2463 (if (re-search-forward "[^ \t]*:" nil t)
2467 (message-narrow-to-head)
2468 (message-remove-header message-ignored-bounced-headers t)
2469 (goto-char (point-max))
2470 (insert mail-header-separator))
2471 (message-position-point)))
2474 ;;; Interactive entry points for new message buffers.
2478 (defun message-mail-other-window (&optional to subject)
2479 "Like `message-mail' command, but display mail buffer in another window."
2481 (let ((pop-up-windows t)
2482 (special-display-buffer-names nil)
2483 (special-display-regexps nil)
2484 (same-window-buffer-names nil)
2485 (same-window-regexps nil))
2486 (message-pop-to-buffer "*mail message*"))
2487 (message-setup `((To . ,(or to "")) (Subject . ,(or subject "")))))
2490 (defun message-mail-other-frame (&optional to subject)
2491 "Like `message-mail' command, but display mail buffer in another frame."
2493 (let ((pop-up-frames t)
2494 (special-display-buffer-names nil)
2495 (special-display-regexps nil)
2496 (same-window-buffer-names nil)
2497 (same-window-regexps nil))
2498 (message-pop-to-buffer "*mail message*"))
2499 (message-setup `((To . ,(or to "")) (Subject . ,(or subject "")))))
2502 (defun message-news-other-window (&optional newsgroups subject)
2503 "Start editing a news article to be sent."
2505 (let ((pop-up-windows t)
2506 (special-display-buffer-names nil)
2507 (special-display-regexps nil)
2508 (same-window-buffer-names nil)
2509 (same-window-regexps nil))
2510 (message-pop-to-buffer "*news message*"))
2511 (message-setup `((Newsgroups . ,(or newsgroups ""))
2512 (Subject . ,(or subject "")))))
2515 (defun message-news-other-frame (&optional newsgroups subject)
2516 "Start editing a news article to be sent."
2518 (let ((pop-up-frames t)
2519 (special-display-buffer-names nil)
2520 (special-display-regexps nil)
2521 (same-window-buffer-names nil)
2522 (same-window-regexps nil))
2523 (message-pop-to-buffer "*news message*"))
2524 (message-setup `((Newsgroups . ,(or newsgroups ""))
2525 (Subject . ,(or subject "")))))
2529 ;; This code should be moved to underline.el (from which it is stolen).
2532 (defun bold-region (start end)
2533 "Bold all nonblank characters in the region.
2534 Works by overstriking characters.
2535 Called from program, takes two arguments START and END
2536 which specify the range to operate on."
2539 (let ((end1 (make-marker)))
2540 (move-marker end1 (max start end))
2541 (goto-char (min start end))
2542 (while (< (point) end1)
2543 (or (looking-at "[_\^@- ]")
2544 (insert (following-char) "\b"))
2545 (forward-char 1)))))
2548 (defun unbold-region (start end)
2549 "Remove all boldness (overstruck characters) in the region.
2550 Called from program, takes two arguments START and END
2551 which specify the range to operate on."
2554 (let ((end1 (make-marker)))
2555 (move-marker end1 (max start end))
2556 (goto-char (min start end))
2557 (while (re-search-forward "\b" end1 t)
2558 (if (eq (following-char) (char-after (- (point) 2)))
2559 (delete-char -2))))))
2561 ;; Support for toolbar
2562 (when (string-match "XEmacs\\|Lucid" emacs-version)
2563 (require 'message-xmas))
2567 ;;; message.el ends here