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)
38 (if (string-match "XEmacs\\|Lucid" emacs-version)
39 (require 'mail-abbrevs)
40 (require 'mailabbrev))
42 (defvar message-directory "~/Mail/"
43 "*Directory from which all other mail file variables are derived.")
46 (defvar message-fcc-handler-function 'rmail-output
47 "*A function called to save outgoing articles.
48 This function will be called with the name of the file to store the
49 article in. The default function is `rmail-output' which saves in Unix
53 (defvar message-courtesy-message
54 "The following message is a courtesy copy of an article\nthat has been posted as well.\n\n"
55 "*This is inserted at the start of a mailed copy of a posted message.
56 If this variable is nil, no such courtesy message will be added.")
59 (defvar message-ignored-bounced-headers "^\\(Received\\|Return-Path\\):"
60 "*Regexp that matches headers to be removed in resent bounced mail.")
63 (defvar message-from-style 'default
64 "*Specifies how \"From\" headers look.
66 If `nil', they contain just the return address like:
68 If `parens', they look like:
69 king@grassland.com (Elvis Parsley)
70 If `angles', they look like:
71 Elvis Parsley <king@grassland.com>
73 Otherwise, most addresses look like `angles', but they look like
74 `parens' if `angles' would need quoting and `parens' would not.")
77 (defvar message-syntax-checks nil
78 "Controls what syntax checks should not be performed on outgoing posts.
79 To disable checking of long signatures, for instance, add
80 `(signature . disabled)' to this list.
82 Don't touch this variable unless you really know what you're doing.
84 Checks include subject-cmsg multiple-headers sendsys message-id from
85 long-lines control-chars size new-text redirected-followup signature
86 approved sender empty empty-headers message-id from subject.")
89 (defvar message-required-news-headers
90 '(From Newsgroups Subject Date Message-ID
91 (optional . Organization) Lines
92 (optional . X-Newsreader))
93 "*Headers to be generated or prompted for when posting an article.
94 RFC977 and RFC1036 require From, Date, Newsgroups, Subject,
95 Message-ID. Organization, Lines, In-Reply-To, Expires, and
96 X-Newsreader are optional. If don't you want message to insert some
97 header, remove it from this list.")
100 (defvar message-required-mail-headers
101 '(From Subject Date (optional . In-Reply-To) Message-ID Lines
102 (optional . X-Mailer))
103 "*Headers to be generated or prompted for when mailing a message.
104 RFC822 required that From, Date, To, Subject and Message-ID be
105 included. Organization, Lines and X-Mailer are optional.")
108 (defvar message-deletable-headers '(Message-ID Date)
109 "*Headers to be deleted if they already exist and were generated by message previously.")
112 (defvar message-ignored-news-headers
113 "^NNTP-Posting-Host:\\|^Xref:\\|^Bcc:\\|^Gcc:\\|^Fcc:"
114 "*Regexp of headers to be removed unconditionally before posting.")
117 (defvar message-ignored-mail-headers "^Gcc:\\|^Fcc:"
118 "*Regexp of headers to be removed unconditionally before mailing.")
121 (defvar message-ignored-supersedes-headers
122 "^Path:\\|^Date\\|^NNTP-Posting-Host:\\|^Xref:\\|^Lines:\\|^Received:\\|^X-From-Line:\\|Return-Path:"
123 "*Header lines matching this regexp will be deleted before posting.
124 It's best to delete old Path and Date headers before posting to avoid
128 (defvar message-signature-separator "^-- *$"
129 "Regexp matching the signature separator.")
132 (defvar message-interactive nil
133 "Non-nil means when sending a message wait for and display errors.
134 nil means let mailer mail back a message to report errors.")
137 (defvar message-generate-new-buffers nil
138 "*Non-nil means that a new message buffer will be created whenever `mail-setup' is called.")
141 (defvar message-kill-buffer-on-exit nil
142 "*Non-nil means that the message buffer will be killed after sending a message.")
144 (defvar gnus-local-organization)
146 (defvar message-user-organization
147 (or (and (boundp 'gnus-local-organization)
148 gnus-local-organization)
149 (getenv "ORGANIZATION")
151 "*String to be used as an Organization header.
152 If t, use `message-user-organization-file'.")
155 (defvar message-user-organization-file "/usr/lib/news/organization"
156 "*Local news organization file.")
159 (defvar message-autosave-directory
160 (concat (file-name-as-directory message-directory) "drafts/")
161 "*Directory where message autosaves buffers.
162 If nil, message won't autosave.")
164 (defvar message-forward-start-separator
165 "------- Start of forwarded message -------\n"
166 "*Delimiter inserted before forwarded messages.")
168 (defvar message-forward-end-separator
169 "------- End of forwarded message -------\n"
170 "*Delimiter inserted after forwarded messages.")
173 (defvar message-signature-before-forwarded-message t
174 "*If non-nil, put the signature before any included forwarded message.")
177 (defvar message-included-forward-headers
178 "^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:"
179 "*Regexp matching headers to be included in forwarded messages.")
182 (defvar message-ignored-resent-headers "^Return-receipt"
183 "*All headers that match this regexp will be deleted when resending a message.")
186 (defvar message-ignored-cited-headers "."
187 "Delete these headers from the messages you yank.")
189 ;; Useful to set in site-init.el
191 (defvar message-send-mail-function 'message-send-mail-with-sendmail
192 "Function to call to send the current buffer as mail.
193 The headers should be delimited by a line whose contents match the
194 variable `mail-header-separator'.
196 Legal values include `message-send-mail-with-mh' and
197 `message-send-mail-with-sendmail', which is the default.")
200 (defvar message-send-news-function 'message-send-news
201 "Function to call to send the current buffer as news.
202 The headers should be delimited by a line whose contents match the
203 variable `message-header-separator'.")
206 (defvar message-reply-to-function nil
207 "Function that should return a list of headers.
208 This function should pick out addresses from the To, Cc, and From headers
209 and respond with new To and Cc headers.")
212 (defvar message-wide-reply-to-function nil
213 "Function that should return a list of headers.
214 This function should pick out addresses from the To, Cc, and From headers
215 and respond with new To and Cc headers.")
218 (defvar message-followup-to-function nil
219 "Function that should return a list of headers.
220 This function should pick out addresses from the To, Cc, and From headers
221 and respond with new To and Cc headers.")
224 (defvar message-use-followup-to 'ask
225 "*Specifies what to do with Followup-To header.
226 If nil, ignore the header. If it is t, use its value, but query before
227 using the \"poster\" value. If it is the symbol `ask', query the user
228 whether to ignore the \"poster\" value. If it is the symbol `use',
229 always use the value.")
231 (defvar gnus-post-method)
232 (defvar gnus-select-method)
234 (defvar message-post-method
235 (cond ((and (boundp 'gnus-post-method)
238 ((boundp 'gnus-select-method)
241 "Method used to post news.")
244 (defvar message-generate-headers-first nil
245 "*If non-nil, generate all possible headers before composing.")
248 (defvar message-header-separator "--text follows this line--"
249 "*Line used to separate headers from text in messages being composed.")
251 (defvar message-setup-hook nil
252 "Normal hook, run each time a new outgoing message is initialized.
253 The function `message-setup' runs this hook.")
255 (defvar message-header-setup-hook nil
256 "Hook called narrowed to the headers when setting up a message buffer.")
259 (defvar message-citation-line-function 'message-insert-citation-line
260 "*Function called to insert the \"Whomever writes:\" line.")
263 (defvar message-yank-prefix "> "
264 "*Prefix inserted on the lines of yanked messages.
265 nil means use indentation.")
267 (defvar message-indentation-spaces 3
268 "*Number of spaces to insert at the beginning of each cited line.
269 Used by `message-yank-original' via `message-yank-cite'.")
272 (defvar message-cite-function 'message-cite-original
273 "*Function for citing an original message.")
276 (defvar message-indent-citation-function 'message-indent-citation
277 "*Function for modifying a citation just inserted in the mail buffer.
278 This can also be a list of functions. Each function can find the
279 citation between (point) and (mark t). And each function should leave
280 point and mark around the citation text as modified.")
282 (defvar message-abbrevs-loaded nil)
285 (defvar message-signature t
286 "*String to be inserted at the end of the message buffer.
287 If t, the `message-signature-file' file will be inserted instead.
288 If a function, the result from the function will be used instead.
289 If a form, the result from the form will be used instead.")
292 (defvar message-signature-file "~/.signature"
293 "*File containing the text inserted at end of message. buffer.")
295 (defvar message-distribution-function nil
296 "*Function called to return a Distribution header.")
298 (defvar message-expires 14
299 "*Number of days before your article expires.")
301 (defvar message-user-path nil
302 "If nil, use the NNTP server name in the Path header.
303 If stringp, use this; if non-nil, use no host name (user name only).")
305 (defvar message-reply-buffer nil)
306 (defvar message-reply-headers nil)
307 (defvar message-newsreader nil)
308 (defvar message-mailer nil)
309 (defvar message-sent-message-via nil)
310 (defvar message-checksum nil)
311 (defvar message-send-actions nil
312 "A list of actions to be performed upon successful sending of a message.")
313 (defvar message-exit-actions nil
314 "A list of actions to be performed upon exiting after sending a message.")
315 (defvar message-kill-actions nil
316 "A list of actions to be performed before killing a message buffer.")
317 (defvar message-postpone-actions nil
318 "A list of actions to be performed after postponing a message.")
321 (defvar message-default-headers nil
322 "*A string containing header lines to be inserted in outgoing messages.
323 It is inserted before you edit the message, so you can edit or delete
327 (defvar message-default-mail-headers nil
328 "*A string of header lines to be inserted in outgoing mails.")
331 (defvar message-default-news-headers nil
332 "*A string of header lines to be inserted in outgoing news articles.")
334 ;; Note: could use /usr/ucb/mail instead of sendmail;
335 ;; options -t, and -v if not interactive.
336 (defvar message-mailer-swallows-blank-line
337 (if (and (string-match "sparc-sun-sunos\\(\\'\\|[^5]\\)"
338 system-configuration)
339 (file-readable-p "/etc/sendmail.cf")
340 (let ((buffer (get-buffer-create " *temp*")))
344 (insert-file-contents "/etc/sendmail.cf")
345 (goto-char (point-min))
346 (let ((case-fold-search nil))
347 (re-search-forward "^OR\\>" nil t)))
348 (kill-buffer buffer))))
349 ;; According to RFC822, "The field-name must be composed of printable
350 ;; ASCII characters (i.e. characters that have decimal values between
351 ;; 33 and 126, except colon)", i.e. any chars except ctl chars,
353 '(looking-at "[ \t]\\|[][!\"#$%&'()*+,-./0-9;<=>?@A-Z\\\\^_`a-z{|}~]+:"))
354 "Set this non-nil if the system's mailer runs the header and body together.
355 \(This problem exists on Sunos 4 when sendmail is run in remote mode.)
356 The value should be an expression to test whether the problem will
359 (defvar message-mode-syntax-table
360 (let ((table (copy-syntax-table text-mode-syntax-table)))
361 (modify-syntax-entry ?% ". " table)
363 "Syntax table used while in Message mode.")
365 (defvar message-font-lock-keywords
366 (let* ((cite-prefix "A-Za-z") (cite-suffix (concat cite-prefix "0-9_.@-")))
367 (list '("^To:" . font-lock-function-name-face)
368 '("^[GBF]?[Cc][Cc]:\\|^Reply-To:" . font-lock-keyword-face)
369 '("^\\(Subject:\\)[ \t]*\\(.+\\)?"
370 (1 font-lock-comment-face) (2 font-lock-type-face nil t))
371 (list (concat "^\\(" (regexp-quote mail-header-separator) "\\)$")
372 1 'font-lock-comment-face)
373 (cons (concat "^[ \t]*"
374 "\\([" cite-prefix "]+[" cite-suffix "]*\\)?"
376 'font-lock-reference-face)
377 '("^\\(X-[A-Za-z0-9-]+\\|In-reply-to\\):.*"
378 . font-lock-string-face)))
379 "Additional expressions to highlight in Message mode.")
381 (defvar message-face-alist
382 '((bold . bold-region)
383 (underline . underline-region)
384 (default . (lambda (b e)
386 (ununderline-region b e))))
387 "Alist of mail and news faces for facemenu.
388 The cdr of ech entry is a function for applying the face to a region.")
390 (defvar message-send-hook nil
391 "Hook run before sending messages.")
393 (defvar message-sent-hook nil
394 "Hook run after sending messages.")
396 ;;; Internal variables.
398 ;;; Regexp matching the delimiter of messages in UNIX mail format
399 ;;; (UNIX From lines), minus the initial ^.
400 (defvar message-unix-mail-delimiter
401 (let ((time-zone-regexp
402 (concat "\\([A-Z]?[A-Z]?[A-Z][A-Z]\\( DST\\)?"
403 "\\|[-+]?[0-9][0-9][0-9][0-9]"
409 ;; Username, perhaps with a quoted section that can contain spaces.
412 "\\(\\|\".*\"[^ \n]*\\)"
416 ;; The time the message was sent.
417 "\\([^ \n]*\\) *" ; day of the week
418 "\\([^ ]*\\) *" ; month
419 "\\([0-9]*\\) *" ; day of month
420 "\\([0-9:]*\\) *" ; time of day
422 ;; Perhaps a time zone, specified by an abbreviation, or by a
427 " [0-9][0-9]\\([0-9]*\\) *"
429 ;; On some systems the time zone can appear after the year, too.
433 "\\(remote from .*\\)?"
437 (defvar message-unsent-separator
438 (concat "^ *---+ +Unsent message follows +---+ *$\\|"
439 "^ *---+ +Returned message +---+ *$\\|"
440 "^Start of returned message$\\|"
441 "^ *---+ +Original message +---+ *$\\|"
442 "^ *--+ +begin message +--+ *$\\|"
443 "^ *---+ +Original message follows +---+ *$\\|"
444 "^|? *---+ +Message text follows: +---+ *|?$")
445 "A regexp that matches the separator before the text of a failed message.")
447 (defvar message-header-format-alist
449 (To . message-fill-header)
450 (Cc . message-fill-header)
461 (References . message-fill-header)
464 "Alist used for formatting headers.")
467 (autoload 'message-setup-toolbar "message-xmas")
468 (autoload 'mh-send-letter "mh-comp"))
473 ;;; Utility functions.
476 (defun message-point-at-bol ()
477 "Return point at the beginning of the line."
484 (defun message-point-at-eol ()
485 "Return point at the end of the line."
492 ;; Delete the current line (and the next N lines.);
493 (defmacro message-delete-line (&optional n)
494 `(delete-region (progn (beginning-of-line) (point))
495 (progn (forward-line ,(or n 1)) (point))))
497 (defun message-tokenize-header (header &optional separator)
498 "Split HEADER into a list of header elements.
499 \",\" is used as the separator."
501 (separator (or separator ","))
503 (format "[ \t]*\\([^%s]+\\)?\\([%s]+\\|\\'\\)" separator separator))
505 (while (and (string-match regexp header beg)
506 (< beg (length header)))
507 (when (match-beginning 1)
508 (push (match-string 1 header) elems))
509 (setq beg (match-end 0)))
512 (defun message-fetch-field (header)
513 "The same as `mail-fetch-field', only remove all newlines."
514 (let ((value (mail-fetch-field header)))
516 (nnheader-replace-chars-in-string value ?\n ? ))))
518 (defun message-fetch-reply-field (header)
519 "Fetch FIELD from the message we're replying to."
520 (when (and message-reply-buffer
521 (buffer-name message-reply-buffer))
523 (set-buffer message-reply-buffer)
524 (message-fetch-field header))))
526 (defun message-set-work-buffer ()
527 (if (get-buffer " *message work*")
529 (set-buffer " *message work*")
531 (set-buffer (get-buffer-create " *message work*"))
532 (kill-all-local-variables)
533 (buffer-disable-undo (current-buffer))))
535 (defun message-functionp (form)
536 "Return non-nil if FORM is funcallable."
537 (or (and (symbolp form) (fboundp form))
538 (and (listp form) (eq (car form) 'lambda))))
540 (defun message-strip-subject-re (subject)
541 "Remove \"Re:\" from subject lines."
542 (if (string-match "^[Rr][Ee]: *" subject)
543 (substring subject (match-end 0))
546 (defun message-remove-header (header &optional is-regexp first reverse)
547 "Remove HEADER in the narrowed buffer.
548 If REGEXP, HEADER is a regular expression.
549 If FIRST, only remove the first instance of the header.
550 Return the number of headers removed."
551 (goto-char (point-min))
552 (let ((regexp (if is-regexp header (concat "^" header ":")))
556 (while (and (not (eobp))
559 (not (looking-at regexp))
567 ;; There might be a continuation header, so we have to search
568 ;; until we find a new non-continuation line.
571 (if (re-search-forward "^[^ \t]" nil t)
572 (goto-char (match-beginning 0))
575 (if (re-search-forward "^[^ \t]" nil t)
576 (goto-char (match-beginning 0))
580 (defun message-narrow-to-headers ()
581 "Narrow the buffer to the head of the message."
584 (goto-char (point-min))
585 (if (re-search-forward
586 (concat "^" (regexp-quote mail-header-separator) "\n") nil t)
589 (goto-char (point-min)))
591 (defun message-narrow-to-head ()
592 "Narrow the buffer to the head of the message."
595 (goto-char (point-min))
596 (if (search-forward "\n\n" nil 1)
599 (goto-char (point-min)))
601 (defun message-news-p ()
602 "Say whether the current buffer contains a news message."
605 (message-narrow-to-headers)
606 (message-fetch-field "newsgroups"))))
608 (defun message-mail-p ()
609 "Say whether the current buffer contains a mail message."
612 (message-narrow-to-headers)
613 (or (message-fetch-field "to")
614 (message-fetch-field "cc")
615 (message-fetch-field "bcc")))))
617 (defun message-next-header ()
618 "Go to the beginning of the next header."
620 (or (eobp) (forward-char 1))
621 (not (if (re-search-forward "^[^ \t]" nil t)
623 (goto-char (point-max)))))
625 (defun message-sort-headers-1 ()
626 "Sort the buffer as headers using `message-rank' text props."
627 (goto-char (point-min))
629 nil 'message-next-header
631 (message-next-header)
635 (or (get-text-property (point) 'message-rank)
638 (defun message-sort-headers ()
639 "Sort the headers of the current message according to `message-header-format-alist'."
643 (let ((max (1+ (length message-header-format-alist)))
645 (message-narrow-to-headers)
646 (while (re-search-forward "^[^ \n]+:" nil t)
648 (match-beginning 0) (1+ (match-beginning 0))
650 (if (setq rank (length (memq (assq (intern (buffer-substring
653 message-header-format-alist)
654 message-header-format-alist)))
657 (message-sort-headers-1))))
667 (defvar message-mode-map nil)
669 (unless message-mode-map
670 (setq message-mode-map (copy-keymap text-mode-map))
671 (define-key message-mode-map "\C-c?" 'describe-mode)
673 (define-key message-mode-map "\C-c\C-f\C-t" 'message-goto-to)
674 (define-key message-mode-map "\C-c\C-f\C-b" 'message-goto-bcc)
675 (define-key message-mode-map "\C-c\C-f\C-w" 'message-goto-fcc)
676 (define-key message-mode-map "\C-c\C-f\C-c" 'message-goto-cc)
677 (define-key message-mode-map "\C-c\C-f\C-s" 'message-goto-subject)
678 (define-key message-mode-map "\C-c\C-f\C-r" 'message-goto-reply-to)
679 (define-key message-mode-map "\C-c\C-f\C-n" 'message-goto-newsgroups)
680 (define-key message-mode-map "\C-c\C-f\C-d" 'message-goto-distribution)
681 (define-key message-mode-map "\C-c\C-f\C-f" 'message-goto-followup-to)
682 (define-key message-mode-map "\C-c\C-f\C-k" 'message-goto-keywords)
683 (define-key message-mode-map "\C-c\C-f\C-u" 'message-goto-summary)
684 (define-key message-mode-map "\C-c\C-b" 'message-goto-body)
685 (define-key message-mode-map "\C-c\C-i" 'message-goto-signature)
687 (define-key message-mode-map "\C-c\C-t" 'message-insert-to)
688 (define-key message-mode-map "\C-c\C-n" 'message-insert-newsgroups)
690 (define-key message-mode-map "\C-c\C-y" 'message-yank-original)
691 (define-key message-mode-map "\C-c\C-q" 'message-fill-yanked-message)
692 (define-key message-mode-map "\C-c\C-w" 'message-insert-signature)
693 (define-key message-mode-map "\C-c\C-r" 'message-caesar-buffer-body)
694 (define-key message-mode-map "\C-c\C-o" 'message-sort-headers)
695 (define-key message-mode-map "\C-c\M-r" 'message-rename-buffer)
697 (define-key message-mode-map "\C-c\C-c" 'message-send-and-exit)
698 (define-key message-mode-map "\C-c\C-s" 'message-send)
699 (define-key message-mode-map "\C-c\C-k" 'message-kill-buffer)
700 (define-key message-mode-map "\C-c\C-d" 'message-dont-send)
702 (define-key message-mode-map "\t" 'message-tab))
704 (easy-menu-define message-mode-menu message-mode-map
709 ["To" message-goto-to t]
710 ["Subject" message-goto-subject t]
711 ["Summary" message-goto-summary t]
712 ["Keywords" message-goto-keywords t]
713 ["Newsgroups" message-goto-newsgroups t]
714 ["Followup-To" message-goto-followup-to t]
715 ["Distribution" message-goto-distribution t]
716 ["Body" message-goto-body t]
717 ["Signature" message-goto-signature t]
719 "Miscellaneous Commands:"
721 ["Sort Headers" message-sort-headers t]
722 ["Yank Original" message-yank-original t]
723 ["Fill Yanked Message" message-fill-yanked-message t]
724 ;; ["Insert Signature" news-reply-signature t]
725 ["Caesar (rot13) Message" message-caesar-buffer-body t]
726 ["Rename buffer" message-rename-buffer t]
727 ["Spellcheck" ispell-message t]
729 ["Send Message" message-send-and-exit t]
730 ["Abort Message" message-dont-send t]))
733 (defun message-mode ()
734 "Major mode for editing mail and news to be sent.
735 Like Text Mode but with these additional commands:
736 C-c C-s message-send (send the message) C-c C-c message-send-and-exit
737 C-c C-f move to a header field (and create it if there isn't):
738 C-c C-f C-t move to To C-c C-f C-s move to Subject
739 C-c C-f C-c move to Cc C-c C-f C-b move to Bcc
740 C-c C-f C-f move to Fcc C-c C-f C-r move to Reply-To
741 C-c C-f C-u move to Summary C-c C-f C-n move to Newsgroups
742 C-c C-f C-k move to Keywords C-c C-f C-d move to Distribution
743 C-c C-f C-o move to Followup-To
744 C-c C-t message-insert-to (add a To header to a news followup)
745 C-c C-n message-insert-newsgroups (add a Newsgroup header to a news reply)
746 C-c C-b message-goto-body (move to beginning of message text).
747 C-c C-i message-goto-signature (move to the beginning of the signature).
748 C-c C-w message-insert-signature (insert `message-signature-file' file).
749 C-c C-y message-yank-original (insert current message, if any).
750 C-c C-q message-fill-yanked-message (fill what was yanked).
751 C-c C-r message-ceasar-buffer-body (rot13 the message body)."
753 (kill-all-local-variables)
754 (make-local-variable 'message-reply-buffer)
755 (setq message-reply-buffer nil)
756 (make-local-variable 'message-send-actions)
757 (make-local-variable 'message-exit-actions)
758 (make-local-variable 'message-kill-actions)
759 (make-local-variable 'message-postpone-actions)
760 (set-syntax-table message-mode-syntax-table)
761 (use-local-map message-mode-map)
762 (setq local-abbrev-table text-mode-abbrev-table)
763 (setq major-mode 'message-mode)
764 (setq mode-name "Message")
765 (setq buffer-offer-save t)
766 (make-local-variable 'font-lock-defaults)
767 (setq font-lock-defaults '(message-font-lock-keywords t))
768 (make-local-variable 'facemenu-add-face-function)
769 (make-local-variable 'facemenu-remove-face-function)
770 (setq facemenu-add-face-function
772 (let ((face-fun (cdr (assq face message-face-alist))))
774 (funcall face-fun (point) end)
775 (error "Face %s not configured for %s mode" face mode-name)))
777 facemenu-remove-face-function t)
778 (make-local-variable 'paragraph-separate)
779 (make-local-variable 'paragraph-start)
780 (setq paragraph-start (concat (regexp-quote mail-header-separator)
781 "$\\|[ \t]*[-_][-_][-_]+$\\|"
783 (setq paragraph-separate (concat (regexp-quote mail-header-separator)
784 "$\\|[ \t]*[-_][-_][-_]+$\\|"
786 (make-local-variable 'message-reply-headers)
787 (setq message-reply-headers nil)
788 (make-local-variable 'message-newsreader)
789 (make-local-variable 'message-mailer)
790 (make-local-variable 'message-post-method)
791 (make-local-variable 'message-sent-message-via)
792 (setq message-sent-message-via nil)
793 (make-local-variable 'message-checksum)
794 (setq message-checksum nil)
795 (when (fboundp 'mail-hist-define-keys)
796 (mail-hist-define-keys))
797 (when (string-match "XEmacs\\|Lucid" emacs-version)
798 (message-setup-toolbar))
799 (easy-menu-add message-mode-menu message-mode-map)
800 ;; Allow mail alias things.
801 (if (fboundp 'mail-abbrevs-setup)
803 (funcall (intern "mail-aliases-setup")))
804 (run-hooks 'text-mode-hook 'message-mode-hook))
809 ;;; Message mode commands
812 ;;; Movement commands
814 (defun message-goto-to ()
815 "Move point to the To header."
817 (message-position-on-field "To"))
819 (defun message-goto-subject ()
820 "Move point to the Subject header."
822 (message-position-on-field "Subject"))
824 (defun message-goto-cc ()
825 "Move point to the Cc header."
827 (message-position-on-field "Cc" "To"))
829 (defun message-goto-bcc ()
830 "Move point to the Bcc header."
832 (message-position-on-field "Bcc" "Cc" "To"))
834 (defun message-goto-fcc ()
835 "Move point to the Fcc header."
837 (message-position-on-field "Fcc" "To" "Newsgroups"))
839 (defun message-goto-reply-to ()
840 "Move point to the Reply-To header."
842 (message-position-on-field "Reply-To" "Subject"))
844 (defun message-goto-newsgroups ()
845 "Move point to the Newsgroups header."
847 (message-position-on-field "Newsgroups"))
849 (defun message-goto-distribution ()
850 "Move point to the Distribution header."
852 (message-position-on-field "Distribution"))
854 (defun message-goto-followup-to ()
855 "Move point to the Followup-To header."
857 (message-position-on-field "Followup-To" "Newsgroups"))
859 (defun message-goto-keywords ()
860 "Move point to the Keywords header."
862 (message-position-on-field "Keywords" "Subject"))
864 (defun message-goto-summary ()
865 "Move point to the Summary header."
867 (message-position-on-field "Summary" "Subject"))
869 (defun message-goto-body ()
870 "Move point to the beginning of the message body."
872 (goto-char (point-min))
873 (search-forward (concat "\n" mail-header-separator "\n") nil t))
875 (defun message-goto-signature ()
876 "Move point to the beginning of the message signature."
878 (goto-char (point-min))
879 (or (re-search-forward message-signature-separator nil t)
880 (goto-char (point-max))))
884 (defun message-insert-to ()
885 "Insert a To header that points to the author of the article being replied to."
887 (when (message-position-on-field "To")
889 (insert (or (message-fetch-reply-field "reply-to")
890 (message-fetch-reply-field "from") "")))
892 (defun message-insert-newsgroups ()
893 "Insert the Newsgroups header from the article being replied to."
895 (when (message-position-on-field "Newsgroups")
897 (insert (or (message-fetch-reply-field "newsgroups") "")))
903 (defun message-insert-signature (&optional force)
904 "Insert a signature. See documentation for the `message-signature' variable."
905 (interactive (list t))
907 (cond ((and (null message-signature)
910 ((message-functionp message-signature)
911 (funcall message-signature))
912 ((listp message-signature)
913 (eval message-signature))
914 (t message-signature)))
916 (cond ((stringp signature)
918 ((and (eq t signature)
919 message-signature-file
920 (file-exists-p message-signature-file))
923 ;; Remove blank lines at the end of the message.
924 (goto-char (point-max))
925 (skip-chars-backward " \t\n")
927 (delete-region (point) (point-max))
928 ;; Insert the signature.
931 (insert-file-contents message-signature-file)
933 (goto-char (point-max))
934 (or (bolp) (insert "\n")))))
936 (defvar message-caesar-translation-table nil)
938 (defun message-caesar-region (b e &optional n)
939 "Caesar rotation of region by N, default 13, for decrypting netnews."
942 (min (point) (or (mark t) (point)))
943 (max (point) (or (mark t) (point)))
944 (when current-prefix-arg
945 (prefix-numeric-value current-prefix-arg))))
947 (setq n (if (numberp n) (mod n 26) 13)) ;canonize N
948 (unless (or (zerop n) ; no action needed for a rot of 0
949 (= b e)) ; no region to rotate
950 ;; We build the table, if necessary.
951 (when (or (not message-caesar-translation-table)
952 (/= (aref message-caesar-translation-table ?a) (+ ?a n)))
954 (table (make-string 256 0)))
955 (while (< (incf i) 256)
959 (substring table 0 ?A)
960 (substring table (+ ?A n) (+ ?A n (- 26 n)))
961 (substring table ?A (+ ?A n))
962 (substring table (+ ?A 26) ?a)
963 (substring table (+ ?a n) (+ ?a n (- 26 n)))
964 (substring table ?a (+ ?a n))
965 (substring table (+ ?a 26) 255)))
966 (setq message-caesar-translation-table table)))
967 ;; Then we translate the region. Do it this way to retain
970 (subst-char-in-region
971 b (1+ b) (char-after b)
972 (aref message-caesar-translation-table (char-after b)))
975 (defun message-caesar-buffer-body (&optional rotnum)
976 "Caesar rotates all letters in the current buffer by 13 places.
977 Used to encode/decode possibly offensive messages (commonly in net.jokes).
978 With prefix arg, specifies the number of places to rotate each letter forward.
979 Mail and USENET news headers are not rotated."
980 (interactive (if current-prefix-arg
981 (list (prefix-numeric-value current-prefix-arg))
985 (when (message-goto-body)
986 (narrow-to-region (point) (point-max)))
987 (message-caesar-region (point-min) (point-max) rotnum))))
989 (defun message-rename-buffer (&optional enter-string)
990 "Rename the *message* buffer to \"*message* RECIPIENT\".
991 If the function is run with a prefix, it will ask for a new buffer
992 name, rather than giving an automatic name."
993 (interactive "Pbuffer name: ")
996 (goto-char (point-min))
997 (narrow-to-region (point)
998 (search-forward mail-header-separator nil 'end))
999 (let* ((mail-to (if (message-news-p) (message-fetch-field "Newsgroups")
1000 (message-fetch-field "To")))
1002 (if (string-match "," mail-to)
1003 (concat (substring mail-to 0 (match-beginning 0)) ", ...")
1005 (name-default (concat "*message* " mail-trimmed-to))
1006 (name (if enter-string
1007 (read-string "New buffer name: " name-default)
1009 (rename-buffer name t)))))
1011 (defun message-fill-yanked-message (&optional justifyp)
1012 "Fill the paragraphs of a message yanked into this one.
1013 Numeric argument means justify as well."
1016 (goto-char (point-min))
1017 (search-forward (concat "\n" mail-header-separator "\n") nil t)
1018 (let ((fill-prefix message-yank-prefix))
1019 (fill-individual-paragraphs (point) (point-max) justifyp t))))
1021 (defun message-indent-citation ()
1022 "Modify text just inserted from a message to be cited.
1023 The inserted text should be the region.
1024 When this function returns, the region is again around the modified text.
1026 Normally, indent each nonblank line `message-indentation-spaces' spaces.
1027 However, if `message-yank-prefix' is non-nil, insert that prefix on each line."
1028 (let ((start (point)))
1029 ;; Remove unwanted headers.
1030 (when message-ignored-cited-headers
1034 (if (search-forward "\n\n" nil t)
1037 (message-remove-header message-ignored-cited-headers t)))
1038 ;; Do the indentation.
1039 (if (null message-yank-prefix)
1040 (indent-rigidly start (mark t) message-indentation-spaces)
1043 (while (< (point) (mark t))
1044 (insert message-yank-prefix)
1046 (goto-char start))))
1048 (defun message-yank-original (&optional arg)
1049 "Insert the message being replied to, if any.
1050 Puts point before the text and mark after.
1051 Normally indents each nonblank line ARG spaces (default 3). However,
1052 if `message-yank-prefix' is non-nil, insert that prefix on each line.
1054 Just \\[universal-argument] as argument means don't indent, insert no
1055 prefix, and don't delete any headers."
1057 (let ((modified (buffer-modified-p)))
1058 (when (and message-reply-buffer
1059 message-cite-function)
1060 (delete-windows-on message-reply-buffer t)
1061 (insert-buffer message-reply-buffer)
1062 (funcall message-cite-function)
1063 (exchange-point-and-mark)
1067 (setq message-checksum (message-checksum))))))
1069 (defun message-cite-original ()
1070 (let ((start (point))
1072 (when message-indent-citation-function
1073 (if (listp message-indent-citation-function)
1074 message-indent-citation-function
1075 (list message-indent-citation-function)))))
1078 (funcall (pop functions)))
1079 (when message-citation-line-function
1082 (funcall message-citation-line-function))))
1084 (defun message-insert-citation-line ()
1085 "Function that inserts a simple citation line."
1086 (when message-reply-headers
1087 (insert (mail-header-from message-reply-headers) " writes:\n\n")))
1089 (defun message-position-on-field (header &rest afters)
1090 (let ((case-fold-search t))
1093 (goto-char (point-min))
1096 (concat "^" (regexp-quote mail-header-separator) "$"))
1097 (match-beginning 0)))
1098 (goto-char (point-min))
1099 (if (re-search-forward (concat "^" (regexp-quote header) ":") nil t)
1101 (re-search-forward "^[^ \t]" nil 'move)
1103 (skip-chars-backward "\n")
1106 (not (re-search-forward
1107 (concat "^" (regexp-quote (car afters)) ":")
1111 (re-search-forward "^[^ \t]" nil 'move)
1112 (beginning-of-line))
1113 (insert header ": \n")
1117 (defun message-remove-signature ()
1118 "Remove the signature from the text between point and mark.
1119 The text will also be indented the normal way."
1121 (let ((start (point))
1123 (if (not (re-search-forward message-signature-separator (mark t) t))
1124 ;; No signature here, so we just indent the cited text.
1125 (message-indent-citation)
1126 ;; Find the last non-empty line.
1128 (while (looking-at "[ \t]*$")
1131 (setq mark (set-marker (make-marker) (point)))
1133 (message-indent-citation)
1134 ;; Enable undoing the deletion.
1136 (delete-region mark (mark t))
1137 (set-marker mark nil)))))
1142 ;;; Sending messages
1145 (defun message-send-and-exit (&optional arg)
1146 "Send message like `message-send', then, if no errors, exit from mail buffer."
1148 (let ((buf (current-buffer))
1149 (actions message-exit-actions))
1150 (when (and (message-send arg)
1152 (if message-kill-buffer-on-exit
1155 (when (eq buf (current-buffer))
1156 (message-bury buf)))
1157 (message-do-actions actions))))
1159 (defun message-dont-send ()
1160 "Don't send the message you have been editing."
1162 (message-bury (current-buffer))
1163 (message-do-actions message-postpone-actions))
1165 (defun message-kill-buffer ()
1166 "Kill the current buffer."
1168 (let ((actions message-kill-actions))
1169 (kill-buffer (current-buffer))
1170 (message-do-actions actions)))
1172 (defun message-bury (buffer)
1173 "Bury this mail buffer."
1174 (let ((newbuf (other-buffer buffer)))
1175 (bury-buffer buffer)
1176 (if (and (fboundp 'frame-parameters)
1177 (cdr (assq 'dedicated (frame-parameters)))
1178 (not (null (delq (selected-frame) (visible-frame-list)))))
1179 (delete-frame (selected-frame))
1180 (switch-to-buffer newbuf))))
1182 (defun message-send (&optional arg)
1183 "Send the message in the current buffer.
1184 If `message-interactive' is non-nil, wait for success indication
1185 or error messages, and inform user.
1186 Otherwise any failure is reported in a message back to
1187 the user from the mailer."
1189 (when (if buffer-file-name
1190 (y-or-n-p (format "Send buffer contents as %s message? "
1191 (if (message-mail-p)
1192 (if (message-news-p) "mail and news" "mail")
1194 (or (buffer-modified-p)
1195 (y-or-n-p "No changes in the buffer; really send? ")))
1196 ;; Make it possible to undo the coming changes.
1198 (message-fix-before-sending)
1199 (run-hooks 'message-send-hook)
1200 (message "Sending...")
1201 (when (and (or (not (message-news-p))
1202 (and (or (not (memq 'news message-sent-message-via))
1204 "Already sent message via news; resend? "))
1205 (funcall message-send-news-function arg)))
1206 (or (not (message-mail-p))
1207 (and (or (not (memq 'mail message-sent-message-via))
1209 "Already sent message via mail; resend? "))
1210 (message-send-mail arg))))
1212 (when (fboundp 'mail-hist-put-headers-into-history)
1213 (mail-hist-put-headers-into-history))
1214 (run-hooks 'message-sent-hook)
1215 (message "Sending...done")
1216 ;; If buffer has no file, mark it as unmodified and delete autosave.
1217 (unless buffer-file-name
1218 (set-buffer-modified-p nil)
1219 (delete-auto-save-file-if-necessary t))
1220 (message-do-actions message-send-actions)
1224 (defun message-fix-before-sending ()
1225 "Do various things to make the message nice before sending it."
1226 ;; Make sure there's a newline at the end of the message.
1227 (goto-char (point-max))
1231 (defun message-add-action (action &rest types)
1232 "Add ACTION to be performed when doing an exit of type TYPES."
1235 (set (setq var (intern (format "message-%s-actions" (pop types))))
1236 (nconc (symbol-value var) (list action))))))
1238 (defun message-do-actions (actions)
1239 "Perform all actions in ACTIONS."
1240 ;; Now perform actions on successful sending.
1244 ;; A simple function.
1245 ((message-functionp (car actions))
1246 (funcall (car actions)))
1247 ;; Something to be evaled.
1249 (eval (car actions))))
1253 (defun message-send-mail (&optional arg)
1254 (require 'mail-utils)
1255 (let ((tembuf (generate-new-buffer " message temp"))
1256 (case-fold-search nil)
1257 (news (message-news-p))
1258 (mailbuf (current-buffer)))
1260 (message-narrow-to-headers)
1261 ;; Insert some headers.
1262 (let ((message-deletable-headers
1263 (if news nil message-deletable-headers)))
1264 (message-generate-headers message-required-mail-headers))
1265 ;; Let the user do all of the above.
1266 (run-hooks 'message-header-hook))
1271 (insert-buffer-substring mailbuf)
1272 ;; Remove some headers.
1274 (message-narrow-to-headers)
1275 ;; Remove some headers.
1276 (message-remove-header message-ignored-mail-headers t))
1277 (goto-char (point-max))
1278 ;; require one newline at the end.
1279 (or (= (preceding-char) ?\n)
1282 (or (message-fetch-field "cc")
1283 (message-fetch-field "to")))
1284 (message-insert-courtesy-copy))
1285 (funcall message-send-mail-function))
1286 (kill-buffer tembuf))
1287 (set-buffer mailbuf)
1288 (push 'mail message-sent-message-via)))
1290 (defun message-send-mail-with-sendmail ()
1291 "Send off the prepared buffer with sendmail."
1292 (let ((errbuf (if message-interactive
1293 (generate-new-buffer " sendmail errors")
1295 resend-to-addresses delimline)
1296 (let ((case-fold-search t))
1298 (message-narrow-to-headers)
1299 (setq resend-to-addresses (message-fetch-field "resent-to")))
1300 ;; Change header-delimiter to be what sendmail expects.
1301 (goto-char (point-min))
1303 (concat "^" (regexp-quote mail-header-separator) "\n"))
1304 (replace-match "\n")
1306 (setq delimline (point-marker))
1307 ;; Insert an extra newline if we need it to work around
1308 ;; Sun's bug that swallows newlines.
1309 (goto-char (1+ delimline))
1310 (when (eval message-mailer-swallows-blank-line)
1312 (when message-interactive
1316 (let ((default-directory "/"))
1317 (apply 'call-process-region
1318 (append (list (point-min) (point-max)
1319 (if (boundp 'sendmail-program)
1321 "/usr/lib/sendmail")
1322 nil errbuf nil "-oi")
1323 ;; Always specify who from,
1324 ;; since some systems have broken sendmails.
1325 (list "-f" (user-login-name))
1326 ;; These mean "report errors by mail"
1327 ;; and "deliver in background".
1328 (if (null message-interactive) '("-oem" "-odb"))
1329 ;; Get the addresses from the message
1330 ;; unless this is a resend.
1331 ;; We must not do that for a resend
1332 ;; because we would find the original addresses.
1333 ;; For a resend, include the specific addresses.
1334 (if resend-to-addresses
1335 (list resend-to-addresses)
1337 (when message-interactive
1340 (goto-char (point-min))
1341 (while (re-search-forward "\n\n* *" nil t)
1342 (replace-match "; "))
1343 (if (not (zerop (buffer-size)))
1344 (error "Sending...failed to %s"
1345 (buffer-substring (point-min) (point-max)))))
1346 (when (bufferp errbuf)
1347 (kill-buffer errbuf)))))
1349 (defun message-send-mail-with-mh ()
1350 "Send the prepared message buffer with mh."
1351 (let ((mh-previous-window-config nil)
1352 (name (make-temp-name
1353 (concat (file-name-as-directory message-autosave-directory)
1355 (setq buffer-file-name name)
1361 (defun message-send-news (&optional arg)
1362 (let ((tembuf (generate-new-buffer " *message temp*"))
1363 (case-fold-search nil)
1364 (method (if (message-functionp message-post-method)
1365 (funcall message-post-method arg)
1366 message-post-method))
1367 (messbuf (current-buffer))
1370 (message-narrow-to-headers)
1371 ;; Insert some headers.
1372 (message-generate-headers message-required-news-headers)
1373 ;; Let the user do all of the above.
1374 (run-hooks 'message-header-hook))
1375 (when (message-check-news-syntax)
1379 (buffer-disable-undo (current-buffer))
1381 (insert-buffer-substring messbuf)
1382 ;; Remove some headers.
1384 (message-narrow-to-headers)
1385 ;; Remove some headers.
1386 (message-remove-header message-ignored-news-headers t))
1387 (goto-char (point-max))
1388 ;; require one newline at the end.
1389 (or (= (preceding-char) ?\n)
1391 (let ((case-fold-search t))
1392 ;; Remove the delimeter.
1393 (goto-char (point-min))
1395 (concat "^" (regexp-quote mail-header-separator) "\n"))
1396 (replace-match "\n")
1398 (require (car method))
1399 (funcall (intern (format "%s-open-server" (car method)))
1400 (cadr method) (cddr method))
1402 (funcall (intern (format "%s-request-post" (car method))))))
1403 (kill-buffer tembuf))
1404 (set-buffer messbuf)
1406 (push 'news message-sent-message-via)
1407 (message "Couldn't send message via news: %s"
1408 (nnheader-get-report (car method)))
1412 ;;; Header generation & syntax checking.
1415 (defun message-check-news-syntax ()
1416 "Check the syntax of the message."
1418 ;; We narrow to the headers and check them first.
1421 (message-narrow-to-headers)
1423 ;; Check for commands in Subject.
1425 (message-check-element 'subject-cmsg)
1427 (if (string-match "^cmsg " (message-fetch-field "subject"))
1429 "The control code \"cmsg \" is in the subject. Really post? ")
1431 ;; Check for multiple identical headers.
1432 (or (message-check-element 'multiple-headers)
1435 (while (and (not found)
1436 (re-search-forward "^[^ \t:]+: " nil t))
1438 (or (re-search-forward
1439 (concat "^" (setq found
1442 (- (match-end 0) 2))))
1447 (format "Multiple %s headers. Really post? " found))
1449 ;; Check for Version and Sendsys.
1450 (or (message-check-element 'sendsys)
1452 (if (re-search-forward "^Sendsys:\\|^Version:" nil t)
1454 (format "The article contains a %s command. Really post? "
1455 (buffer-substring (match-beginning 0)
1456 (1- (match-end 0)))))
1458 ;; See whether we can shorten Followup-To.
1459 (or (message-check-element 'shorten-followup-to)
1460 (let ((newsgroups (message-fetch-field "newsgroups"))
1461 (followup-to (message-fetch-field "followup-to"))
1463 (when (and newsgroups (string-match "," newsgroups)
1468 (setq to (completing-read
1469 "Followups to: (default all groups) "
1470 (mapcar (lambda (g) (list g))
1472 (message-tokenize-header
1474 (goto-char (point-min))
1475 (insert "Followup-To: " to "\n"))
1478 ;; Check for Approved.
1479 (or (message-check-element 'approved)
1481 (if (re-search-forward "^Approved:" nil t)
1483 "The article contains an Approved header. Really post? ")
1485 ;; Check the Message-Id header.
1486 (or (message-check-element 'message-id)
1488 (let* ((case-fold-search t)
1489 (message-id (message-fetch-field "message-id")))
1490 (or (not message-id)
1491 (and (string-match "@" message-id)
1492 (string-match "@[^\\.]*\\." message-id))
1495 "The Message-ID looks strange: \"%s\". Really post? "
1497 ;; Check the Subject header.
1499 (message-check-element 'subject)
1501 (let* ((case-fold-search t)
1502 (subject (message-fetch-field "subject")))
1505 (not (string-match "\\`[ \t]*\\'" subject)))
1508 "The subject field is empty or missing. Posting is denied.")
1510 ;; Check the Newsgroups & Followup-To headers.
1512 (message-check-element 'existing-newsgroups)
1513 (let* ((case-fold-search t)
1514 (newsgroups (message-fetch-field "newsgroups"))
1515 (followup-to (message-fetch-field "followup-to"))
1516 (groups (message-tokenize-header
1518 (concat newsgroups "," followup-to)
1520 (hashtb (and (boundp 'gnus-active-hashtb)
1521 gnus-active-hashtb))
1526 (unless (boundp (intern (car groups) hashtb))
1527 (push (car groups) errors))
1533 "Really post to %s unknown group%s: %s "
1534 (if (= (length errors) 1) "this" "these")
1535 (if (= (length errors) 1) "" "s")
1536 (mapconcat 'identity errors ", ")))))))
1537 ;; Check the Newsgroups & Followup-To headers for syntax errors.
1539 (message-check-element 'valid-newsgroups)
1540 (let ((case-fold-search t)
1541 (headers '("Newsgroups" "Followup-To"))
1543 (while (and headers (not error))
1544 (when (setq header (mail-fetch-field (car headers)))
1547 "\\`\\([-.a-zA-Z0-9]+\\)?\\(,[-.a-zA-Z0-9]+\\)*\\'"
1552 (not (string-match "\\.\\'\\|\\.\\." g)))
1553 (message-tokenize-header header ","))))
1560 (format "The %s header looks odd: \"%s\". Really post? "
1561 (car headers) header)))))
1562 ;; Check the From header.
1564 (message-check-element 'from)
1566 (let* ((case-fold-search t)
1567 (from (message-fetch-field "from")))
1570 (message "There is no From line. Posting is denied.")
1572 ((not (string-match "@[^\\.]*\\." from))
1574 "Denied posting -- the From looks strange: \"%s\"." from)
1576 ((string-match "@[^@]*@" from)
1578 "Denied posting -- two \"@\"'s in the From header: %s." from)
1580 ((string-match "(.*).*(.*)" from)
1582 "Denied posting -- the From header looks strange: \"%s\"."
1586 ;; Check for long lines.
1587 (or (message-check-element 'long-lines)
1589 (goto-char (point-min))
1591 (concat "^" (regexp-quote mail-header-separator) "$"))
1595 (< (current-column) 80))
1596 (zerop (forward-line 1))))
1600 "You have lines longer than 79 characters. Really post? "))))
1601 ;; Check whether the article is empty.
1602 (or (message-check-element 'empty)
1604 (goto-char (point-min))
1606 (concat "^" (regexp-quote mail-header-separator) "$"))
1609 (or (re-search-forward message-signature-separator nil t)
1610 (goto-char (point-max)))
1612 (or (re-search-backward "[^ \n\t]" b t)
1613 (y-or-n-p "Empty article. Really post? ")))))
1614 ;; Check for control characters.
1615 (or (message-check-element 'control-chars)
1617 (if (re-search-forward "[\000-\007\013\015-\037\200-\237]" nil t)
1619 "The article contains control characters. Really post? ")
1621 ;; Check excessive size.
1622 (or (message-check-element 'size)
1623 (if (> (buffer-size) 60000)
1625 (format "The article is %d octets long. Really post? "
1628 ;; Check whether any new text has been added.
1629 (or (message-check-element 'new-text)
1630 (not message-checksum)
1631 (not (eq (message-checksum) message-checksum))
1633 "It looks like no new text has been added. Really post? "))
1634 ;; Check the length of the signature.
1636 (message-check-element 'signature)
1638 (goto-char (point-max))
1639 (if (or (not (re-search-backward "^-- $" nil t))
1640 (search-forward message-forward-end-separator nil t))
1642 (if (> (count-lines (point) (point-max)) 5)
1645 "Your .sig is %d lines; it should be max 4. Really post? "
1646 (count-lines (point) (point-max))))
1649 (defun message-check-element (type)
1650 "Returns non-nil if this type is not to be checked."
1651 (if (eq message-syntax-checks 'dont-check-for-anything-just-trust-me)
1653 (let ((able (assq type message-syntax-checks)))
1655 (eq (cdr able) 'disabled)))))
1657 (defun message-checksum ()
1658 "Return a \"checksum\" for the current buffer."
1661 (goto-char (point-min))
1663 (concat "^" (regexp-quote mail-header-separator) "$"))
1665 (setq sum (logxor sum (following-char)))
1669 (defun message-do-fcc ()
1670 "Process Fcc headers in the current buffer."
1671 (let ((case-fold-search t)
1672 (buf (current-buffer))
1675 (set-buffer (get-buffer-create " *message temp*"))
1676 (buffer-disable-undo (current-buffer))
1678 (insert-buffer-substring buf)
1680 (message-narrow-to-headers)
1681 (while (setq file (message-fetch-field "fcc"))
1683 (message-remove-header "fcc" nil t)))
1684 (goto-char (point-min))
1685 (re-search-forward (concat "^" (regexp-quote mail-header-separator) "$"))
1686 (replace-match "" t t)
1687 ;; Process FCC operations.
1689 (setq file (pop list))
1690 (if (string-match "^[ \t]*|[ \t]*\\(.*\\)[ \t]*$" file)
1691 ;; Pipe the article to the program in question.
1692 (call-process-region (point-min) (point-max) shell-file-name
1693 nil nil nil "-c" (match-string 1 file))
1694 ;; Save the article.
1695 (setq file (expand-file-name file))
1696 (unless (file-exists-p (file-name-directory file))
1697 (make-directory (file-name-directory file) t))
1698 (if (and message-fcc-handler-function
1699 (not (eq message-fcc-handler-function 'rmail-output)))
1700 (funcall message-fcc-handler-function file)
1701 (if (and (file-readable-p file) (mail-file-babyl-p file))
1702 (rmail-output file 1)
1703 (let ((mail-use-rfc822 t))
1704 (rmail-output file 1 t t))))))
1705 (kill-buffer (current-buffer)))))
1707 (defun message-cleanup-headers ()
1708 "Do various automatic cleanups of the headers."
1709 ;; Remove empty lines in the header.
1711 (message-narrow-to-headers)
1712 (while (re-search-forward "^[ \t]*\n" nil t)
1713 (replace-match "" t t)))
1715 ;; Correct Newsgroups and Followup-To headers: change sequence of
1716 ;; spaces to comma and eliminate spaces around commas. Eliminate
1717 ;; embedded line breaks.
1718 (goto-char (point-min))
1719 (while (re-search-forward "^\\(Newsgroups\\|Followup-To\\): +" nil t)
1723 (if (re-search-forward "^[^ \t]" nil t)
1727 (goto-char (point-min))
1728 (while (re-search-forward "\n[ \t]+" nil t)
1729 (replace-match " " t t)) ;No line breaks (too confusing)
1730 (goto-char (point-min))
1731 (while (re-search-forward "[ \t\n]*,[ \t\n]*\\|[ \t]+" nil t)
1732 (replace-match "," t t))
1733 (goto-char (point-min))
1734 ;; Remove trailing commas.
1735 (when (re-search-forward ",+$" nil t)
1736 (replace-match "" t t)))))
1738 (defun message-make-date ()
1739 "Make a valid data header."
1740 (let ((now (current-time)))
1741 (timezone-make-date-arpa-standard
1742 (current-time-string now) (current-time-zone now))))
1744 (defun message-make-message-id ()
1745 "Make a unique Message-ID."
1746 (concat "<" (message-unique-id)
1747 (let ((psubject (save-excursion (message-fetch-field "subject"))))
1748 (if (and message-reply-headers
1749 (mail-header-references message-reply-headers)
1750 (mail-header-subject message-reply-headers)
1752 (mail-header-subject message-reply-headers)
1754 (message-strip-subject-re
1755 (mail-header-subject message-reply-headers))
1756 (message-strip-subject-re psubject))))
1758 "@" (message-make-fqdm) ">"))
1760 (defvar message-unique-id-char nil)
1762 ;; If you ever change this function, make sure the new version
1763 ;; cannot generate IDs that the old version could.
1764 ;; You might for example insert a "." somewhere (not next to another dot
1765 ;; or string boundary), or modify the "fsf" string.
1766 (defun message-unique-id ()
1767 ;; Don't use microseconds from (current-time), they may be unsupported.
1768 ;; Instead we use this randomly inited counter.
1769 (setq message-unique-id-char
1770 (% (1+ (or message-unique-id-char (logand (random t) (1- (lsh 1 20)))))
1771 ;; (current-time) returns 16-bit ints,
1772 ;; and 2^16*25 just fits into 4 digits i base 36.
1774 (let ((tm (current-time)))
1776 (if (memq system-type '(ms-dos emx vax-vms))
1777 (let ((user (downcase (user-login-name))))
1778 (while (string-match "[^a-z0-9_]" user)
1779 (aset user (match-beginning 0) ?_))
1781 (message-number-base36 (user-uid) -1))
1782 (message-number-base36 (+ (car tm)
1783 (lsh (% message-unique-id-char 25) 16)) 4)
1784 (message-number-base36 (+ (nth 1 tm)
1785 (lsh (/ message-unique-id-char 25) 16)) 4)
1786 ;; Append the newsreader name, because while the generated
1787 ;; ID is unique to this newsreader, other newsreaders might
1788 ;; otherwise generate the same ID via another algorithm.
1791 (defun message-number-base36 (num len)
1792 (if (if (< len 0) (<= num 0) (= len 0))
1794 (concat (message-number-base36 (/ num 36) (1- len))
1795 (char-to-string (aref "zyxwvutsrqponmlkjihgfedcba9876543210"
1798 (defun message-make-organization ()
1799 "Make an Organization header."
1800 (let* ((organization
1801 (or (getenv "ORGANIZATION")
1802 (when message-user-organization
1803 (if (message-functionp message-user-organization)
1804 (funcall message-user-organization)
1805 message-user-organization)))))
1807 (message-set-work-buffer)
1808 (cond ((stringp organization)
1809 (insert organization))
1810 ((and (eq t organization)
1811 message-user-organization-file
1812 (file-exists-p message-user-organization-file))
1813 (insert-file-contents message-user-organization-file)))
1814 (goto-char (point-min))
1815 (while (re-search-forward "[\t\n]+" nil t)
1816 (replace-match "" t t))
1817 (unless (zerop (buffer-size))
1820 (defun message-make-lines ()
1821 "Count the number of lines and return numeric string."
1825 (goto-char (point-min))
1827 (concat "^" (regexp-quote mail-header-separator) "$"))
1829 (int-to-string (count-lines (point) (point-max))))))
1831 (defun message-make-in-reply-to ()
1832 "Return the In-Reply-To header for this message."
1833 (when message-reply-headers
1834 (let ((from (mail-header-from message-reply-headers))
1835 (date (mail-header-date message-reply-headers)))
1838 (string-match " *at \\| *@ \\| *(\\| *<" from)))
1839 (concat (if stop-pos (substring from 0 stop-pos) from)
1841 (if (or (not date) (string= date ""))
1842 "(unknown date)" date)))))))
1844 (defun message-make-distribution ()
1845 "Make a Distribution header."
1846 (let ((orig-distribution (message-fetch-reply-field "distribution")))
1847 (cond ((message-functionp message-distribution-function)
1848 (funcall message-distribution-function))
1849 (t orig-distribution))))
1851 (defun message-make-expires ()
1852 "Return an Expires header based on `message-expires'."
1853 (let ((current (current-time))
1854 (future (* 1.0 message-expires 60 60 24)))
1855 ;; Add the future to current.
1856 (setcar current (+ (car current) (round (/ future (expt 2 16)))))
1857 (setcar (cdr current) (+ (nth 1 current) (% (round future) (expt 2 16))))
1858 ;; Return the date in the future in UT.
1859 (timezone-make-date-arpa-standard
1860 (current-time-string current) (current-time-zone current) '(0 "UT"))))
1862 (defun message-make-path ()
1864 (let ((login-name (user-login-name)))
1865 (cond ((null message-user-path)
1866 (concat (system-name) "!" login-name))
1867 ((stringp message-user-path)
1868 ;; Support GENERICPATH. Suggested by vixie@decwrl.dec.com.
1869 (concat message-user-path "!" login-name))
1872 (defun message-make-from ()
1873 "Make a From header."
1874 (let* ((login (message-make-address))
1875 (fullname (user-full-name)))
1876 (when (string= fullname "&")
1877 (setq fullname (user-login-name)))
1879 (message-set-work-buffer)
1881 ((or (null message-from-style)
1882 (equal fullname ""))
1884 ((or (eq message-from-style 'angles)
1885 (and (not (eq message-from-style 'parens))
1886 ;; Use angles if no quoting is needed, or if parens would
1887 ;; need quoting too.
1888 (or (not (string-match "[^- !#-'*+/-9=?A-Z^-~]" fullname))
1889 (let ((tmp (concat fullname nil)))
1890 (while (string-match "([^()]*)" tmp)
1891 (aset tmp (match-beginning 0) ?-)
1892 (aset tmp (1- (match-end 0)) ?-))
1893 (string-match "[\\()]" tmp)))))
1895 (goto-char (point-min))
1896 ;; Look for a character that cannot appear unquoted
1897 ;; according to RFC 822.
1898 (when (re-search-forward "[^- !#-'*+/-9=?A-Z^-~]" nil 1)
1899 ;; Quote fullname, escaping specials.
1900 (goto-char (point-min))
1902 (while (re-search-forward "[\"\\]" nil 1)
1903 (replace-match "\\\\\\&" t))
1905 (insert " <" login ">"))
1906 (t ; 'parens or default
1908 (let ((fullname-start (point)))
1910 (goto-char fullname-start)
1911 ;; RFC 822 says \ and nonmatching parentheses
1912 ;; must be escaped in comments.
1913 ;; Escape every instance of ()\ ...
1914 (while (re-search-forward "[()\\]" nil 1)
1915 (replace-match "\\\\\\&" t))
1916 ;; ... then undo escaping of matching parentheses,
1917 ;; including matching nested parentheses.
1918 (goto-char fullname-start)
1919 (while (re-search-forward
1920 "\\(\\=\\|[^\\]\\(\\\\\\\\\\)*\\)\\\\(\\(\\([^\\]\\|\\\\\\\\\\)*\\)\\\\)"
1922 (replace-match "\\1(\\3)" t)
1923 (goto-char fullname-start)))
1927 (defun message-make-sender ()
1928 "Return the \"real\" user address.
1929 This function tries to ignore all user modifications, and
1930 give as trustworthy answer as possible."
1931 (concat (user-login-name) "@" (system-name)))
1933 (defun message-make-address ()
1934 "Make the address of the user."
1935 (or (message-user-mail-address)
1936 (concat (user-login-name) "@" (message-make-domain))))
1938 (defun message-user-mail-address ()
1939 "Return the pertinent part of `user-mail-address'."
1940 (when user-mail-address
1941 (nth 1 (mail-extract-address-components user-mail-address))))
1943 (defun message-make-fqdm ()
1944 "Return user's fully qualified domain name."
1945 (let ((system-name (system-name)))
1947 ((string-match "[^.]\\.[^.]" system-name)
1948 ;; `system-name' returned the right result.
1950 ;; We try `user-mail-address' as a backup.
1951 ((string-match "@\\(.*\\)\\'" (message-user-mail-address))
1952 (match-string 1 user-mail-address))
1953 ;; Try `mail-host-address'.
1954 ((and (boundp 'mail-host-address)
1957 ;; Default to this bogus thing.
1959 (concat system-name ".i-have-a-misconfigured-system-so-shoot-me")))))
1961 (defun message-make-host-name ()
1962 "Return the name of the host."
1963 (let ((fqdm (message-make-fqdm)))
1964 (string-match "^[^.]+\\." fqdm)
1965 (substring fqdm 0 (1- (match-end 0)))))
1967 (defun message-make-domain ()
1968 "Return the domain name."
1969 (or mail-host-address
1970 (message-make-fqdm)))
1972 (defun message-generate-headers (headers)
1973 "Prepare article HEADERS.
1974 Headers already prepared in the buffer are not modified."
1976 (message-narrow-to-headers)
1977 (let* ((Date (message-make-date))
1978 (Message-ID (message-make-message-id))
1979 (Organization (message-make-organization))
1980 (From (message-make-from))
1981 (Path (message-make-path))
1984 (In-Reply-To (message-make-in-reply-to))
1986 (Distribution (message-make-distribution))
1987 (Lines (message-make-lines))
1988 (X-Newsreader message-newsreader)
1989 (X-Mailer (and (not (message-fetch-field "X-Newsreader"))
1991 (Expires (message-make-expires))
1992 (case-fold-search t)
1994 ;; First we remove any old generated headers.
1995 (let ((headers message-deletable-headers))
1997 (goto-char (point-min))
1998 (and (re-search-forward
1999 (concat "^" (symbol-name (car headers)) ": *") nil t)
2000 (get-text-property (1+ (match-beginning 0)) 'message-deletable)
2001 (message-delete-line))
2003 ;; Go through all the required headers and see if they are in the
2004 ;; articles already. If they are not, or are empty, they are
2005 ;; inserted automatically - except for Subject, Newsgroups and
2008 (goto-char (point-min))
2009 (setq elem (pop headers))
2011 (if (eq (car elem) 'optional)
2012 (setq header (cdr elem))
2013 (setq header (car elem)))
2015 (when (or (not (re-search-forward
2016 (concat "^" (downcase (symbol-name header)) ":")
2019 ;; The header was found. We insert a space after the
2020 ;; colon, if there is none.
2021 (if (/= (following-char) ? ) (insert " ") (forward-char 1))
2022 ;; Find out whether the header is empty...
2023 (looking-at "[ \t]*$")))
2024 ;; So we find out what value we should insert.
2027 ((and (consp elem) (eq (car elem) 'optional))
2028 ;; This is an optional header. If the cdr of this
2029 ;; is something that is nil, then we do not insert
2031 (setq header (cdr elem))
2032 (or (and (fboundp (cdr elem)) (funcall (cdr elem)))
2033 (and (boundp (cdr elem)) (symbol-value (cdr elem)))))
2035 ;; The element is a cons. Either the cdr is a
2036 ;; string to be inserted verbatim, or it is a
2037 ;; function, and we insert the value returned from
2039 (or (and (stringp (cdr elem)) (cdr elem))
2040 (and (fboundp (cdr elem)) (funcall (cdr elem)))))
2041 ((and (boundp header) (symbol-value header))
2042 ;; The element is a symbol. We insert the value
2043 ;; of this symbol, if any.
2044 (symbol-value header))
2046 ;; We couldn't generate a value for this header,
2047 ;; so we just ask the user.
2048 (read-from-minibuffer
2049 (format "Empty header for %s; enter value: " header)))))
2050 ;; Finally insert the header.
2052 (not (equal value "")))
2056 ;; This header didn't exist, so we insert it.
2057 (goto-char (point-max))
2058 (insert (symbol-name header) ": " value "\n")
2060 ;; The value of this header was empty, so we clear
2061 ;; totally and insert the new value.
2062 (delete-region (point) (message-point-at-eol))
2064 ;; Add the deletable property to the headers that require it.
2065 (and (memq header message-deletable-headers)
2066 (progn (beginning-of-line) (looking-at "[^:]+: "))
2067 (add-text-properties
2068 (point) (match-end 0)
2069 '(message-deletable t face italic) (current-buffer)))))))
2070 ;; Insert new Sender if the From is strange.
2071 (let ((from (message-fetch-field "from"))
2072 (sender (message-fetch-field "sender"))
2073 (secure-sender (message-make-sender)))
2075 (not (message-check-element 'sender))
2078 (cadr (mail-extract-address-components from)))
2079 (downcase secure-sender)))
2084 (cadr (mail-extract-address-components sender)))
2085 (downcase secure-sender)))))
2086 (goto-char (point-min))
2087 ;; Rename any old Sender headers to Original-Sender.
2088 (when (re-search-forward "^Sender:" nil t)
2090 (insert "Original-")
2091 (beginning-of-line))
2092 (insert "Sender: " secure-sender "\n"))))))
2094 (defun message-insert-courtesy-copy ()
2095 "Insert a courtesy message in mail copies of combined messages."
2098 (message-narrow-to-headers)
2099 (let ((newsgroups (message-fetch-field "newsgroups")))
2101 (goto-char (point-max))
2102 (insert "Posted-To: " newsgroups "\n"))))
2104 (insert message-courtesy-message)))
2107 ;;; Setting up a message buffer
2110 (defun message-fill-header (header value)
2111 (let ((begin (point))
2114 (insert (capitalize (symbol-name header))
2116 (if (consp value) (car value) value)
2119 (narrow-to-region begin (point))
2120 (fill-region-as-paragraph begin (point))
2121 ;; Tapdance around looong Message-IDs.
2123 (when (looking-at "[ \t]*$")
2124 (message-delete-line))
2126 (re-search-forward ":" nil t)
2127 (when (looking-at "\n[ \t]+")
2128 (replace-match " " t t))
2129 (goto-char (point-max)))))
2131 (defun message-position-point ()
2132 "Move point to where the user probably wants to find it."
2133 (message-narrow-to-headers)
2135 ((re-search-forward "^[^:]+:[ \t]*$" nil t)
2136 (search-backward ":" )
2139 (if (= (following-char) ? )
2143 (goto-char (point-max))
2146 (unless (looking-at "$")
2150 (defun message-pop-to-buffer (name)
2151 "Pop to buffer NAME, and warn if it already exists and is modified."
2152 (if message-generate-new-buffers
2153 (set-buffer (pop-to-buffer (generate-new-buffer name)))
2154 (let ((buffer (get-buffer name)))
2156 (buffer-name buffer))
2158 (set-buffer (pop-to-buffer buffer))
2159 (when (and (buffer-modified-p)
2161 "Message already being composed; erase? ")))
2162 (error "Message being composed")))
2163 (set-buffer (pop-to-buffer name)))))
2167 (defun message-setup (headers &optional replybuffer actions)
2169 (setq message-send-actions actions))
2170 (setq message-reply-buffer replybuffer)
2171 (goto-char (point-min))
2172 ;; Insert all the headers.
2175 (alist message-header-format-alist))
2177 (unless (assq (caar h) message-header-format-alist)
2178 (push (list (caar h)) alist))
2183 (when message-default-headers
2184 (insert message-default-headers))
2185 (insert mail-header-separator "\n")
2187 (when (message-news-p)
2188 (when message-default-news-headers
2189 (insert message-default-news-headers))
2190 (when message-generate-headers-first
2191 (message-generate-headers
2194 (copy-sequence message-required-news-headers))))))
2195 (when (message-mail-p)
2196 (when message-default-mail-headers
2197 (insert message-default-mail-headers))
2198 (when message-generate-headers-first
2199 (message-generate-headers
2202 (copy-sequence message-required-mail-headers))))))
2203 (message-insert-signature)
2204 (message-set-auto-save-file-name)
2206 (message-narrow-to-headers)
2207 (run-hooks 'message-header-setup-hook))
2208 (set-buffer-modified-p nil)
2209 (run-hooks 'message-setup-hook)
2210 (message-position-point)
2213 (defun message-set-auto-save-file-name ()
2214 "Associate the message buffer with a file in the drafts directory."
2215 (when message-autosave-directory
2216 (unless (file-exists-p message-autosave-directory)
2217 (make-directory message-autosave-directory t))
2218 (let ((name (make-temp-name
2219 (concat (file-name-as-directory message-autosave-directory)
2221 (setq buffer-auto-save-file-name
2225 (set-buffer (get-buffer-create " *draft tmp*"))
2226 (setq buffer-file-name name)
2227 (make-auto-save-file-name))
2228 (kill-buffer (current-buffer)))))
2229 (clear-visited-file-modtime))))
2234 ;;; Commands for interfacing with message
2238 (defun message-mail (&optional to subject)
2239 "Start editing a mail message to be sent."
2241 (message-pop-to-buffer "*mail message*")
2242 (message-setup `((To . ,(or to "")) (Subject . ,(or subject "")))))
2245 (defun message-news (&optional newsgroups subject)
2246 "Start editing a news article to be sent."
2248 (message-pop-to-buffer "*news message*")
2249 (message-setup `((Newsgroups . ,(or newsgroups ""))
2250 (Subject . ,(or subject "")))))
2253 (defun message-reply (&optional to-address wide ignore-reply-to)
2254 "Start editing a reply to the article in the current buffer."
2256 (let ((cur (current-buffer))
2257 from subject date reply-to to cc
2258 references message-id follow-to
2259 mct never-mct gnus-warning)
2262 (goto-char (point-min))
2263 (if (search-forward "\n\n" nil t)
2266 ;; Allow customizations to have their say.
2268 ;; This is a regular reply.
2269 (if (message-functionp message-reply-to-function)
2270 (setq follow-to (funcall message-reply-to-function)))
2271 ;; This is a followup.
2272 (if (message-functionp message-wide-reply-to-function)
2275 (funcall message-wide-reply-to-function)))))
2276 ;; Find all relevant headers we need.
2277 (setq from (message-fetch-field "from")
2278 date (message-fetch-field "date")
2279 subject (or (message-fetch-field "subject") "none")
2280 to (message-fetch-field "to")
2281 cc (message-fetch-field "cc")
2282 mct (message-fetch-field "mail-copies-to")
2283 reply-to (unless ignore-reply-to (message-fetch-field "reply-to"))
2284 references (message-fetch-field "references")
2285 message-id (message-fetch-field "message-id"))
2286 ;; Remove any (buggy) Re:'s that are present and make a
2288 (when (string-match "^[ \t]*[Rr][Ee]:[ \t]*" subject)
2289 (setq subject (substring subject (match-end 0))))
2290 (setq subject (concat "Re: " subject))
2292 (when (and (setq gnus-warning (message-fetch-field "gnus-warning"))
2293 (string-match "<[^>]+>" gnus-warning))
2294 (setq message-id (match-string 0 gnus-warning)))
2296 ;; Handle special values of Mail-Copies-To.
2298 (cond ((equal (downcase mct) "never")
2301 ((equal (downcase mct) "always")
2302 (setq mct (or reply-to from)))))
2307 (setq follow-to (list (cons 'To (or to-address reply-to from))))
2310 (message-set-work-buffer)
2312 (insert (or reply-to from "")))
2314 (if (bolp) "" ", ") (or to "")
2315 (if mct (concat (if (bolp) "" ", ") mct) "")
2316 (if cc (concat (if (bolp) "" ", ") cc) ""))
2317 ;; Remove addresses that match `rmail-dont-reply-to-names'.
2318 (insert (prog1 (rmail-dont-reply-to (buffer-string))
2320 (goto-char (point-min))
2324 (cons (mail-strip-quoted-names addr) addr))
2325 (nreverse (mail-parse-comma-list))))
2328 (setq ccalist (delq (assoc (car (pop s)) s) ccalist)))))
2329 (setq follow-to (list (cons 'To (cdr (pop ccalist)))))
2332 (mapconcat (lambda (addr) (cdr addr)) ccalist ", "))
2336 (message-pop-to-buffer "*mail message*")
2338 (setq message-reply-headers
2339 (vector 0 subject from date message-id references 0 0 ""))
2342 `((Subject . ,subject)
2344 ,@(if (or references message-id)
2345 `((References . ,(concat (or references "") (and references " ")
2346 (or message-id ""))))
2351 (defun message-wide-reply (&optional to-address)
2353 (message-reply to-address t))
2356 (defun message-followup ()
2358 (let ((cur (current-buffer))
2359 from subject date reply-to mct
2360 references message-id follow-to
2361 followup-to distribution newsgroups gnus-warning)
2364 (goto-char (point-min))
2365 (if (search-forward "\n\n" nil t)
2368 (when (message-functionp message-followup-to-function)
2370 (funcall message-followup-to-function)))
2371 (setq from (message-fetch-field "from")
2372 date (message-fetch-field "date")
2373 subject (or (message-fetch-field "subject") "none")
2374 references (message-fetch-field "references")
2375 message-id (message-fetch-field "message-id")
2376 followup-to (message-fetch-field "followup-to")
2377 newsgroups (message-fetch-field "newsgroups")
2378 reply-to (message-fetch-field "reply-to")
2379 distribution (message-fetch-field "distribution")
2380 mct (message-fetch-field "mail-copies-to"))
2381 (when (and (setq gnus-warning (message-fetch-field "gnus-warning"))
2382 (string-match "<[^>]+>" gnus-warning))
2383 (setq message-id (match-string 0 gnus-warning)))
2384 ;; Remove bogus distribution.
2385 (and (stringp distribution)
2386 (string-match "world" distribution)
2387 (setq distribution nil))
2388 ;; Remove any (buggy) Re:'s that are present and make a
2390 (when (string-match "^[ \t]*[Rr][Ee]:[ \t]*" subject)
2391 (setq subject (substring subject (match-end 0))))
2392 (setq subject (concat "Re: " subject))
2395 (message-pop-to-buffer "*news message*")
2398 `((Subject . ,subject)
2400 (follow-to follow-to)
2401 ((and followup-to message-use-followup-to)
2404 ((equal (downcase followup-to) "poster")
2405 (if (or (eq message-use-followup-to 'use)
2406 (message-y-or-n-p "Obey Followup-To: poster? " t "\
2407 You should normally obey the Followup-To: header.
2409 `Followup-To: poster' sends your response via e-mail instead of news.
2411 A typical situation where `Followup-To: poster' is used is when the poster
2412 does not read the newsgroup, so he wouldn't see any replies sent to it."))
2413 (cons 'To (or reply-to from ""))
2414 (cons 'Newsgroups newsgroups)))
2416 (if (or (equal followup-to newsgroups)
2417 (not (eq message-use-followup-to 'ask))
2419 (concat "Obey Followup-To: " followup-to "? ") t "\
2420 You should normally obey the Followup-To: header.
2422 `Followup-To: " followup-to "'
2423 directs your response to " (if (string-match "," followup-to)
2424 "the specified newsgroups"
2425 "that newsgroup only") ".
2427 If a message is posted to several newsgroups, Followup-To is often
2428 used to direct the following discussion to one newsgroup only,
2429 because discussions that are spread over several newsgroup tend to
2430 be fragmented and very difficult to follow.
2432 Also, some source/announcment newsgroups are not indented for discussion;
2433 responses here are directed to other newsgroups."))
2434 (cons 'Newsgroups followup-to)
2435 (cons 'Newsgroups newsgroups))))))
2437 `((Newsgroups . ,newsgroups))))
2438 ,@(and distribution (list (cons 'Distribution distribution)))
2439 (References . ,(concat (or references "") (and references " ")
2440 (or message-id "")))
2442 (not (equal (downcase mct) "never")))
2443 (list (cons 'Cc (if (equal (downcase mct) "always")
2444 (or reply-to from "")
2449 (setq message-reply-headers
2450 (vector 0 subject from date message-id references 0 0 ""))))
2454 (defun message-cancel-news ()
2455 "Cancel an article you posted."
2457 (unless (message-news-p)
2458 (error "This is not a news article; canceling is impossible"))
2459 (when (yes-or-no-p "Do you really want to cancel this article? ")
2460 (let (from newsgroups message-id distribution buf)
2462 ;; Get header info. from original article.
2464 (message-narrow-to-head)
2465 (setq from (message-fetch-field "from")
2466 newsgroups (message-fetch-field "newsgroups")
2467 message-id (message-fetch-field "message-id")
2468 distribution (message-fetch-field "distribution")))
2469 ;; Make sure that this article was written by the user.
2470 (unless (string-equal
2471 (downcase (mail-strip-quoted-names from))
2472 (downcase (message-make-address)))
2473 (error "This article is not yours"))
2474 ;; Make control message.
2475 (setq buf (set-buffer (get-buffer-create " *message cancel*")))
2476 (buffer-disable-undo (current-buffer))
2478 (insert "Newsgroups: " newsgroups "\n"
2479 "From: " (message-make-from) "\n"
2480 "Subject: cmsg cancel " message-id "\n"
2481 "Control: cancel " message-id "\n"
2483 (concat "Distribution: " distribution "\n")
2485 mail-header-separator "\n"
2486 "This is a cancel message from " from ".\n")
2487 (message "Canceling your article...")
2488 (let ((message-syntax-checks 'dont-check-for-anything-just-trust-me))
2489 (funcall message-send-news-function))
2490 (message "Canceling your article...done")
2491 (kill-buffer buf)))))
2494 (defun message-supersede ()
2495 "Start composing a message to supersede the current message.
2496 This is done simply by taking the old article and adding a Supersedes
2497 header line with the old Message-ID."
2499 (let ((cur (current-buffer)))
2500 ;; Check whether the user owns the article that is to be superseded.
2501 (unless (string-equal
2502 (downcase (mail-strip-quoted-names (message-fetch-field "from")))
2503 (downcase (mail-strip-quoted-names (message-make-address))))
2504 (error "This article is not yours"))
2505 ;; Get a normal message buffer.
2506 (message-pop-to-buffer "*supersede message*")
2507 (insert-buffer-substring cur)
2508 (message-narrow-to-head)
2509 ;; Remove unwanted headers.
2510 (when message-ignored-supersedes-headers
2511 (message-remove-header message-ignored-supersedes-headers t))
2512 (goto-char (point-min))
2513 (if (not (re-search-forward "^Message-ID: " nil t))
2514 (error "No Message-ID in this article")
2515 (replace-match "Supersedes: " t t))
2516 (goto-char (point-max))
2517 (insert mail-header-separator)
2522 (defun message-recover ()
2523 "Reread contents of current buffer from its last auto-save file."
2525 (let ((file-name (make-auto-save-file-name)))
2526 (cond ((save-window-excursion
2527 (if (not (eq system-type 'vax-vms))
2528 (with-output-to-temp-buffer "*Directory*"
2529 (buffer-disable-undo standard-output)
2530 (let ((default-directory "/"))
2532 "ls" nil standard-output nil "-l" file-name))))
2533 (yes-or-no-p (format "Recover auto save file %s? " file-name)))
2534 (let ((buffer-read-only nil))
2536 (insert-file-contents file-name nil)))
2537 (t (error "message-recover cancelled")))))
2539 ;;; Forwarding messages.
2541 (defun message-make-forward-subject ()
2542 "Return a Subject header suitable for the message in the current buffer."
2543 (concat "[" (or (message-fetch-field (if (message-news-p) "newsgroups" "from"))
2545 "] " (or (message-fetch-field "Subject") "")))
2548 (defun message-forward (&optional news)
2549 "Forward the current message via mail.
2550 Optional NEWS will use news to forward instead of mail."
2552 (let ((cur (current-buffer))
2553 (subject (message-make-forward-subject)))
2554 (if news (message-news nil subject) (message-mail nil subject))
2555 ;; Put point where we want it before inserting the forwarded
2557 (if message-signature-before-forwarded-message
2558 (goto-char (point-max))
2559 (message-goto-body))
2560 ;; Narrow to the area we are to insert.
2561 (narrow-to-region (point) (point))
2562 ;; Insert the separators and the forwarded buffer.
2563 (insert message-forward-start-separator)
2564 (insert-buffer-substring cur)
2565 (goto-char (point-max))
2566 (insert message-forward-end-separator)
2567 (set-text-properties (point-min) (point-max) nil)
2568 ;; Remove all unwanted headers.
2569 (goto-char (point-min))
2571 (narrow-to-region (point) (if (search-forward "\n\n" nil t)
2574 (goto-char (point-min))
2575 (message-remove-header message-included-forward-headers t nil t)
2577 (message-position-point)))
2580 (defun message-resend (address)
2581 "Resend the current article to ADDRESS."
2582 (interactive "sResend message to: ")
2584 (let ((cur (current-buffer))
2586 ;; We first set up a normal mail buffer.
2587 (set-buffer (get-buffer-create " *message resend*"))
2588 (buffer-disable-undo (current-buffer))
2590 (message-setup `((To . ,address)))
2591 ;; Insert our usual headers.
2592 (message-generate-headers '(From Date To))
2593 (message-narrow-to-headers)
2594 ;; Rename them all to "Resent-*".
2595 (while (re-search-forward "^[A-Za-z]" nil t)
2600 (delete-region (point) (point-max))
2602 ;; Insert the message to be resent.
2603 (insert-buffer-substring cur)
2604 (goto-char (point-min))
2605 (search-forward "\n\n")
2608 (narrow-to-region beg (point))
2609 (message-remove-header message-ignored-resent-headers t)
2610 (goto-char (point-max)))
2611 (insert mail-header-separator)
2612 ;; Rename all old ("Also-")Resent headers.
2613 (while (re-search-backward "^\\(Also-\\)?Resent-" beg t)
2618 (kill-buffer (current-buffer)))))
2621 (defun message-bounce ()
2622 "Re-mail the current message.
2623 This only makes sense if the current message is a bounce message than
2624 contains some mail you have written which has been bounced back to
2627 (let ((cur (current-buffer))
2629 (message-pop-to-buffer "*mail message*")
2630 (insert-buffer-substring cur)
2632 (message-narrow-to-head)
2633 (if (and (message-fetch-field "Mime-Version")
2634 (setq boundary (message-fetch-field "Content-Type")))
2635 (if (string-match "boundary=\"\\([^\"]+\\)\"" boundary)
2636 (setq boundary (concat (match-string 1 boundary) " *\n"
2637 "Content-Type: message/rfc822"))
2638 (setq boundary nil)))
2640 (goto-char (point-min))
2641 (search-forward "\n\n" nil t)
2643 (re-search-forward boundary nil t)
2645 (and (re-search-forward message-unsent-separator nil t)
2647 (and (search-forward "\n\n" nil t)
2648 (re-search-forward "^Return-Path:.*\n" nil t)))
2649 ;; We remove everything before the bounced mail.
2652 (if (re-search-forward "[^ \t]*:" nil t)
2656 (message-narrow-to-head)
2657 (message-remove-header message-ignored-bounced-headers t)
2658 (goto-char (point-max))
2659 (insert mail-header-separator))
2660 (message-position-point)))
2663 ;;; Interactive entry points for new message buffers.
2667 (defun message-mail-other-window (&optional to subject)
2668 "Like `message-mail' command, but display mail buffer in another window."
2670 (let ((pop-up-windows t)
2671 (special-display-buffer-names nil)
2672 (special-display-regexps nil)
2673 (same-window-buffer-names nil)
2674 (same-window-regexps nil))
2675 (message-pop-to-buffer "*mail message*"))
2676 (message-setup `((To . ,(or to "")) (Subject . ,(or subject "")))))
2679 (defun message-mail-other-frame (&optional to subject)
2680 "Like `message-mail' command, but display mail buffer in another frame."
2682 (let ((pop-up-frames t)
2683 (special-display-buffer-names nil)
2684 (special-display-regexps nil)
2685 (same-window-buffer-names nil)
2686 (same-window-regexps nil))
2687 (message-pop-to-buffer "*mail message*"))
2688 (message-setup `((To . ,(or to "")) (Subject . ,(or subject "")))))
2691 (defun message-news-other-window (&optional newsgroups subject)
2692 "Start editing a news article to be sent."
2694 (let ((pop-up-windows t)
2695 (special-display-buffer-names nil)
2696 (special-display-regexps nil)
2697 (same-window-buffer-names nil)
2698 (same-window-regexps nil))
2699 (message-pop-to-buffer "*news message*"))
2700 (message-setup `((Newsgroups . ,(or newsgroups ""))
2701 (Subject . ,(or subject "")))))
2704 (defun message-news-other-frame (&optional newsgroups subject)
2705 "Start editing a news article to be sent."
2707 (let ((pop-up-frames t)
2708 (special-display-buffer-names nil)
2709 (special-display-regexps nil)
2710 (same-window-buffer-names nil)
2711 (same-window-regexps nil))
2712 (message-pop-to-buffer "*news message*"))
2713 (message-setup `((Newsgroups . ,(or newsgroups ""))
2714 (Subject . ,(or subject "")))))
2718 ;; This code should be moved to underline.el (from which it is stolen).
2721 (defun bold-region (start end)
2722 "Bold all nonblank characters in the region.
2723 Works by overstriking characters.
2724 Called from program, takes two arguments START and END
2725 which specify the range to operate on."
2728 (let ((end1 (make-marker)))
2729 (move-marker end1 (max start end))
2730 (goto-char (min start end))
2731 (while (< (point) end1)
2732 (or (looking-at "[_\^@- ]")
2733 (insert (following-char) "\b"))
2734 (forward-char 1)))))
2737 (defun unbold-region (start end)
2738 "Remove all boldness (overstruck characters) in the region.
2739 Called from program, takes two arguments START and END
2740 which specify the range to operate on."
2743 (let ((end1 (make-marker)))
2744 (move-marker end1 (max start end))
2745 (goto-char (min start end))
2746 (while (re-search-forward "\b" end1 t)
2747 (if (eq (following-char) (char-after (- (point) 2)))
2748 (delete-char -2))))))
2750 ;; Support for toolbar
2751 (when (string-match "XEmacs\\|Lucid" emacs-version)
2752 (require 'message-xmas))
2754 ;;; Group name completion.
2756 (defvar message-newgroups-header-regexp
2757 "^\\(Newsgroups\\|Followup-To\\|Posted-To\\):"
2758 "Regexp that match headers that lists groups.")
2760 (defun message-tab ()
2761 "Expand group names in Newsgroups and Followup-To headers.
2762 Do a `tab-to-tab-stop' if not in those headers."
2764 (if (let ((mail-abbrev-mode-regexp message-newgroups-header-regexp))
2765 (mail-abbrev-in-expansion-header-p))
2766 (message-expand-group)
2769 (defvar gnus-active-hashtb)
2770 (defun message-expand-group ()
2771 (let* ((b (save-excursion (skip-chars-backward "^, :\t\n") (point)))
2772 (completion-ignore-case t)
2773 (string (buffer-substring b (point)))
2774 (hashtb (and (boundp 'gnus-active-hashtb) gnus-active-hashtb))
2775 (completions (all-completions string hashtb))
2776 (cur (current-buffer))
2778 (delete-region b (point))
2780 ((= (length completions) 1)
2781 (if (string= (car completions) string)
2784 (message "Only matching group"))
2785 (insert (car completions))))
2786 ((and (setq comp (try-completion string hashtb))
2787 (not (string= comp string)))
2792 (message "No matching groups")
2793 (pop-to-buffer "*Completions*")
2794 (buffer-disable-undo (current-buffer))
2796 (let ((standard-output (current-buffer)))
2797 (display-completion-list (sort completions 'string<)))
2798 (goto-char (point-min))
2799 (pop-to-buffer cur))))))
2803 (defmacro message-y-or-n-p (question show &rest text)
2804 "Ask QUESTION, displaying the rest of the arguments in a temporary buffer."
2805 `(message-talkative-question 'y-or-n-p ,question ,show ,@text))
2807 (defun message-talkative-question (ask question show &rest text)
2808 "Call FUNCTION with argument QUESTION, displaying the rest of the arguments in a temporary buffer if SHOW.
2809 The following arguments may contain lists of values."
2811 (setq text (message-flatten-list text)))
2812 (save-window-excursion
2814 (with-output-to-temp-buffer " *MESSAGE information message*"
2815 (set-buffer " *MESSAGE information message*")
2816 (mapcar 'princ text)
2817 (goto-char (point-min))))
2818 (funcall ask question))
2819 (funcall ask question)))
2821 (defun message-flatten-list (&rest list)
2822 (message-flatten-list-1 list))
2824 (defun message-flatten-list-1 (list)
2826 (apply 'append (mapcar 'message-flatten-list-1 list)))
2832 ;;; message.el ends here