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)
39 (defvar message-fcc-handler-function 'rmail-output
40 "*A function called to save outgoing articles.
41 This function will be called with the name of the file to store the
42 article in. The default function is `rmail-output' which saves in Unix
46 (defvar message-courtesy-message
47 "The following message is a courtesy copy of an article\nthat has been posted as well.\n\n"
48 "*This is inserted at the start of a mailed copy of a posted message.
49 If this variable is nil, no such courtesy message will be added.")
52 (defvar message-ignored-bounced-headers "^\\(Received\\):"
53 "*Regexp that matches headers to be removed in resent bounced mail.")
56 (defvar message-from-style 'default
57 "*Specifies how \"From\" headers look.
59 If `nil', they contain just the return address like:
61 If `parens', they look like:
62 king@grassland.com (Elvis Parsley)
63 If `angles', they look like:
64 Elvis Parsley <king@grassland.com>
66 Otherwise, most addresses look like `angles', but they look like
67 `parens' if `angles' would need quoting and `parens' would not.")
70 (defvar message-syntax-checks nil
71 "Controls what syntax checks should not be performed on outgoing posts.
72 To disable checking of long signatures, for instance, add
73 `(signature . disabled)' to this list.
75 Don't touch this variable unless you really know what you're doing.
77 Checks include subject-cmsg multiple-headers sendsys message-id from
78 long-lines control-chars size new-text redirected-followup signature
79 approved sender empty empty-headers message-id from subject.")
82 (defvar message-required-news-headers
83 '(From Newsgroups Subject Date Message-ID
84 (optional . Organization) Lines
85 (optional . X-Newsreader))
86 "*Headers to be generated or prompted for when posting an article.
87 RFC977 and RFC1036 require From, Date, Newsgroups, Subject,
88 Message-ID. Organization, Lines, In-Reply-To, Expires, and
89 X-Newsreader are optional. If don't you want message to insert some
90 header, remove it from this list.")
93 (defvar message-required-mail-headers
94 '(From Subject Date (optional . In-Reply-To) Message-ID Lines
95 (optional . X-Mailer))
96 "*Headers to be generated or prompted for when mailing a message.
97 RFC822 required that From, Date, To, Subject and Message-ID be
98 included. Organization, Lines and X-Mailer are optional.")
101 (defvar message-deletable-headers '(Message-ID Date)
102 "*Headers to be deleted if they already exist and were generated by message previously.")
105 (defvar message-ignored-news-headers
106 "^NNTP-Posting-Host:\\|^Xref:\\|^Bcc:\\|^Gcc:\\|^Fcc:"
107 "*Regexp of headers to be removed unconditionally before posting.")
110 (defvar message-ignored-mail-headers "^Gcc:\\|^Fcc:"
111 "*Regexp of headers to be removed unconditionally before mailing.")
114 (defvar message-ignored-supersedes-headers
115 "^Path:\\|^Date\\|^NNTP-Posting-Host:\\|^Xref:\\|^Lines:\\|^Received:\\|^X-From-Line:\\|Return-Path:"
116 "*Header lines matching this regexp will be deleted before posting.
117 It's best to delete old Path and Date headers before posting to avoid
121 (defvar message-signature-separator "^-- *$"
122 "Regexp matching the signature separator.")
125 (defvar message-interactive nil
126 "Non-nil means when sending a message wait for and display errors.
127 nil means let mailer mail back a message to report errors.")
130 (defvar message-generate-new-buffers nil
131 "*Non-nil means that a new message buffer will be created whenever `mail-setup' is called.")
134 (defvar message-kill-buffer-on-exit nil
135 "*Non-nil means that the message buffer will be killed after sending a message.")
137 (defvar gnus-local-organization)
139 (defvar message-user-organization
140 (or (and (boundp 'gnus-local-organization)
141 gnus-local-organization)
142 (getenv "ORGANIZATION")
144 "*String to be used as an Organization header.
145 If t, use `message-user-organization-file'.")
148 (defvar message-user-organization-file "/usr/lib/news/organization"
149 "*Local news organization file.")
152 (defvar message-autosave-directory "~/Mail/drafts/"
153 "*Directory where message autosaves buffers.
154 If nil, message won't autosave.")
156 (defvar message-forward-start-separator
157 "------- Start of forwarded message -------\n"
158 "*Delimiter inserted before forwarded messages.")
160 (defvar message-forward-end-separator
161 "------- End of forwarded message -------\n"
162 "*Delimiter inserted after forwarded messages.")
165 (defvar message-signature-before-forwarded-message t
166 "*If non-nil, put the signature before any included forwarded message.")
169 (defvar message-included-forward-headers
170 "^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:"
171 "*Regexp matching headers to be included in forwarded messages.")
174 (defvar message-ignored-resent-headers "^Return-receipt"
175 "*All headers that match this regexp will be deleted when resending a message.")
178 (defvar message-ignored-cited-headers "."
179 "Delete these headers from the messages you yank.")
181 ;; Useful to set in site-init.el
183 (defvar message-send-mail-function 'message-send-mail
184 "Function to call to send the current buffer as mail.
185 The headers should be delimited by a line whose contents match the
186 variable `mail-header-separator'.")
189 (defvar message-send-news-function 'message-send-news
190 "Function to call to send the current buffer as news.
191 The headers should be delimited by a line whose contents match the
192 variable `message-header-separator'.")
195 (defvar message-reply-to-function nil
196 "Function that should return a list of headers.")
199 (defvar message-wide-reply-to-function nil
200 "Function that should return a list of headers.")
203 (defvar message-followup-to-function nil
204 "Function that should return a list of headers.")
207 (defvar message-use-followup-to 'ask
208 "*Specifies what to do with Followup-To header.
209 If nil, ignore the header. If it is t, use its value, but query before
210 using the \"poster\" value. If it is the symbol `ask', query the user
211 whether to ignore the \"poster\" value. If it is the symbol `use',
212 always use the value.")
214 (defvar gnus-post-method)
215 (defvar gnus-select-method)
217 (defvar message-post-method
218 (cond ((and (boundp 'gnus-post-method)
221 ((boundp 'gnus-select-method)
224 "Method used to post news.")
227 (defvar message-generate-headers-first nil
228 "*If non-nil, generate all possible headers before composing.")
231 (defvar message-header-separator "--text follows this line--"
232 "*Line used to separate headers from text in messages being composed.")
234 (defvar message-setup-hook nil
235 "Normal hook, run each time a new outgoing message is initialized.
236 The function `message-setup' runs this hook.")
238 (defvar message-header-setup-hook nil
239 "Hook called narrowed to the headers when setting up a message buffer.")
242 (defvar message-citation-line-function 'message-insert-citation-line
243 "*Function called to insert the \"Whomever writes:\" line.")
246 (defvar message-yank-prefix "> "
247 "*Prefix inserted on the lines of yanked messages.
248 nil means use indentation.")
250 (defvar message-indentation-spaces 3
251 "*Number of spaces to insert at the beginning of each cited line.
252 Used by `message-yank-original' via `message-yank-cite'.")
255 (defvar message-cite-function 'message-cite-original
256 "*Function for citing an original message.")
259 (defvar message-indent-citation-function 'message-indent-citation
260 "*Function for modifying a citation just inserted in the mail buffer.
261 This can also be a list of functions. Each function can find the
262 citation between (point) and (mark t). And each function should leave
263 point and mark around the citation text as modified.")
265 (defvar message-abbrevs-loaded nil)
268 (defvar message-signature t
269 "*String to be inserted at the end of the message buffer.
270 If t, the `message-signature-file' file will be inserted instead.
271 If a function, the result from the function will be used instead.
272 If a form, the result from the form will be used instead.")
275 (defvar message-signature-file "~/.signature"
276 "*File containing the text inserted at end of message. buffer.")
278 (defvar message-distribution-function nil
279 "*Function called to return a Distribution header.")
281 (defvar message-expires 14
282 "*Number of days before your article expires.")
284 (defvar message-user-path nil
285 "If nil, use the NNTP server name in the Path header.
286 If stringp, use this; if non-nil, use no host name (user name only).")
288 (defvar message-reply-buffer nil)
289 (defvar message-reply-headers nil)
290 (defvar message-newsreader nil)
291 (defvar message-mailer nil)
292 (defvar message-sent-message-via nil)
293 (defvar message-checksum nil)
294 (defvar message-send-actions nil
295 "A list of actions to be performed upon successful sending of a message.")
298 (defvar message-default-headers nil
299 "*A string containing header lines to be inserted in outgoing messages.
300 It is inserted before you edit the message, so you can edit or delete
304 (defvar message-default-mail-headers nil
305 "*A string of header lines to be inserted in outgoing mails.")
308 (defvar message-default-news-headers nil
309 "*A string of header lines to be inserted in outgoing news articles.")
311 ;; Note: could use /usr/ucb/mail instead of sendmail;
312 ;; options -t, and -v if not interactive.
313 (defvar message-mailer-swallows-blank-line
314 (if (and (string-match "sparc-sun-sunos\\(\\'\\|[^5]\\)"
315 system-configuration)
316 (file-readable-p "/etc/sendmail.cf")
317 (let ((buffer (get-buffer-create " *temp*")))
321 (insert-file-contents "/etc/sendmail.cf")
322 (goto-char (point-min))
323 (let ((case-fold-search nil))
324 (re-search-forward "^OR\\>" nil t)))
325 (kill-buffer buffer))))
326 ;; According to RFC822, "The field-name must be composed of printable
327 ;; ASCII characters (i.e. characters that have decimal values between
328 ;; 33 and 126, except colon)", i.e. any chars except ctl chars,
330 '(looking-at "[ \t]\\|[][!\"#$%&'()*+,-./0-9;<=>?@A-Z\\\\^_`a-z{|}~]+:"))
331 "Set this non-nil if the system's mailer runs the header and body together.
332 \(This problem exists on Sunos 4 when sendmail is run in remote mode.)
333 The value should be an expression to test whether the problem will
336 (defvar message-mode-syntax-table
337 (let ((table (copy-syntax-table text-mode-syntax-table)))
338 (modify-syntax-entry ?% ". " table)
340 "Syntax table used while in Message mode.")
342 (defvar message-font-lock-keywords
343 (let* ((cite-prefix "A-Za-z") (cite-suffix (concat cite-prefix "0-9_.@-")))
344 (list '("^To:" . font-lock-function-name-face)
345 '("^B?CC:\\|^Reply-To:" . font-lock-keyword-face)
346 '("^\\(Subject:\\)[ \t]*\\(.+\\)?"
347 (1 font-lock-comment-face) (2 font-lock-type-face nil t))
348 (list (concat "^\\(" (regexp-quote mail-header-separator) "\\)$")
349 1 'font-lock-comment-face)
350 (cons (concat "^[ \t]*"
351 "\\([" cite-prefix "]+[" cite-suffix "]*\\)?"
353 'font-lock-reference-face)
354 '("^\\(X-[A-Za-z0-9-]+\\|In-reply-to\\):.*"
355 . font-lock-string-face)))
356 "Additional expressions to highlight in Message mode.")
358 (defvar message-face-alist
359 '((bold . bold-region)
360 (underline . underline-region)
361 (default . (lambda (b e)
363 (ununderline-region b e))))
364 "Alist of mail and news faces for facemenu.
365 The cdr of ech entry is a function for applying the face to a region.")
367 (defvar message-send-hook nil
368 "Hook run before sending messages.")
370 (defvar message-sent-hook nil
371 "Hook run after sending messages.")
373 ;;; Internal variables.
375 ;;; Regexp matching the delimiter of messages in UNIX mail format
376 ;;; (UNIX From lines), minus the initial ^.
377 (defvar message-unix-mail-delimiter
378 (let ((time-zone-regexp
379 (concat "\\([A-Z]?[A-Z]?[A-Z][A-Z]\\( DST\\)?"
380 "\\|[-+]?[0-9][0-9][0-9][0-9]"
386 ;; Username, perhaps with a quoted section that can contain spaces.
389 "\\(\\|\".*\"[^ \n]*\\)"
393 ;; The time the message was sent.
394 "\\([^ \n]*\\) *" ; day of the week
395 "\\([^ ]*\\) *" ; month
396 "\\([0-9]*\\) *" ; day of month
397 "\\([0-9:]*\\) *" ; time of day
399 ;; Perhaps a time zone, specified by an abbreviation, or by a
404 " [0-9][0-9]\\([0-9]*\\) *"
406 ;; On some systems the time zone can appear after the year, too.
410 "\\(remote from .*\\)?"
414 (defvar message-unsent-separator
415 (concat "^ *---+ +Unsent message follows +---+ *$\\|"
416 "^ *---+ +Returned message +---+ *$\\|"
417 "^Start of returned message$\\|"
418 "^ *---+ +Original message +---+ *$\\|"
419 "^ *--+ +begin message +--+ *$\\|"
420 "^ *---+ +Original message follows +---+ *$\\|"
421 "^|? *---+ +Message text follows: +---+ *|?$")
422 "A regexp that matches the separator before the text of a failed message.")
424 (defvar message-header-format-alist
426 (To . message-fill-header)
427 (Cc . message-fill-header)
438 (References . message-fill-header)
441 "Alist used for formatting headers.")
446 ;;; Utility functions.
449 (defun message-point-at-bol ()
450 "Return point at the beginning of the line."
457 (defun message-point-at-eol ()
458 "Return point at the end of the line."
465 ;; Delete the current line (and the next N lines.);
466 (defmacro message-delete-line (&optional n)
467 `(delete-region (progn (beginning-of-line) (point))
468 (progn (forward-line ,(or n 1)) (point))))
470 (defun message-tokenize-header (header &optional separator)
471 "Split HEADER into a list of header elements.
472 \",\" is used as the separator."
474 (separator (or separator ","))
476 (format "[ \t]*\\([^%s]+\\)?\\([%s]+\\|\\'\\)" separator separator))
478 (while (and (string-match regexp header beg)
479 (< beg (length header)))
480 (when (match-beginning 1)
481 (push (match-string 1 header) elems))
482 (setq beg (match-end 0)))
485 (defun message-fetch-reply-field (header)
486 "Fetch FIELD from the message we're replying to."
487 (when (and message-reply-buffer
488 (buffer-name message-reply-buffer))
490 (set-buffer message-reply-buffer)
491 (mail-fetch-field header))))
493 (defun message-set-work-buffer ()
494 (if (get-buffer " *message work*")
496 (set-buffer " *message work*")
498 (set-buffer (get-buffer-create " *message work*"))
499 (kill-all-local-variables)
500 (buffer-disable-undo (current-buffer))))
502 (defun message-functionp (form)
503 "Return non-nil if FORM is funcallable."
504 (or (and (symbolp form) (fboundp form))
505 (and (listp form) (eq (car form) 'lambda))))
507 (defun message-strip-subject-re (subject)
508 "Remove \"Re:\" from subject lines."
509 (if (string-match "^[Rr][Ee]: *" subject)
510 (substring subject (match-end 0))
513 (defun message-remove-header (header &optional is-regexp first reverse)
514 "Remove HEADER in the narrowed buffer.
515 If REGEXP, HEADER is a regular expression.
516 If FIRST, only remove the first instance of the header.
517 Return the number of headers removed."
518 (goto-char (point-min))
519 (let ((regexp (if is-regexp header (concat "^" header ":")))
523 (while (and (not (eobp))
526 (not (looking-at regexp))
534 ;; There might be a continuation header, so we have to search
535 ;; until we find a new non-continuation line.
538 (if (re-search-forward "^[^ \t]" nil t)
539 (goto-char (match-beginning 0))
542 (if (re-search-forward "^[^ \t]" nil t)
543 (goto-char (match-beginning 0))
547 (defun message-narrow-to-headers ()
548 "Narrow the buffer to the head of the message."
551 (goto-char (point-min))
552 (if (re-search-forward
553 (concat "^" (regexp-quote mail-header-separator) "\n") nil t)
556 (goto-char (point-min)))
558 (defun message-narrow-to-head ()
559 "Narrow the buffer to the head of the message."
562 (goto-char (point-min))
563 (if (search-forward "\n\n" nil 1)
566 (goto-char (point-min)))
568 (defun message-news-p ()
569 "Say whether the current buffer contains a news message."
572 (message-narrow-to-headers)
573 (mail-fetch-field "newsgroups"))))
575 (defun message-mail-p ()
576 "Say whether the current buffer contains a mail message."
579 (message-narrow-to-headers)
580 (or (mail-fetch-field "to")
581 (mail-fetch-field "cc")
582 (mail-fetch-field "bcc")))))
584 (defun message-next-header ()
585 "Go to the beginning of the next header."
587 (or (eobp) (forward-char 1))
588 (not (if (re-search-forward "^[^ \t]" nil t)
590 (goto-char (point-max)))))
592 (defun message-sort-headers-1 ()
593 "Sort the buffer as headers using `message-rank' text props."
594 (goto-char (point-min))
596 nil 'message-next-header
598 (message-next-header)
602 (or (get-text-property (point) 'message-rank)
605 (defun message-sort-headers ()
606 "Sort the headers of the current message according to `message-header-format-alist'."
610 (let ((max (1+ (length message-header-format-alist)))
612 (message-narrow-to-headers)
613 (while (re-search-forward "^[^ ]+:" nil t)
615 (match-beginning 0) (1+ (match-beginning 0))
617 (if (setq rank (length (memq (assq (intern (buffer-substring
620 message-header-format-alist)
621 message-header-format-alist)))
624 (message-sort-headers-1))))
634 (defvar message-mode-map nil)
636 (unless message-mode-map
637 (setq message-mode-map (copy-keymap text-mode-map))
638 (define-key message-mode-map "\C-c?" 'describe-mode)
640 (define-key message-mode-map "\C-c\C-f\C-t" 'message-goto-to)
641 (define-key message-mode-map "\C-c\C-f\C-b" 'message-goto-bcc)
642 (define-key message-mode-map "\C-c\C-f\C-w" 'message-goto-fcc)
643 (define-key message-mode-map "\C-c\C-f\C-c" 'message-goto-cc)
644 (define-key message-mode-map "\C-c\C-f\C-s" 'message-goto-subject)
645 (define-key message-mode-map "\C-c\C-f\C-r" 'message-goto-reply-to)
646 (define-key message-mode-map "\C-c\C-f\C-n" 'message-goto-newsgroups)
647 (define-key message-mode-map "\C-c\C-f\C-d" 'message-goto-distribution)
648 (define-key message-mode-map "\C-c\C-f\C-f" 'message-goto-followup-to)
649 (define-key message-mode-map "\C-c\C-f\C-k" 'message-goto-keywords)
650 (define-key message-mode-map "\C-c\C-f\C-u" 'message-goto-summary)
651 (define-key message-mode-map "\C-c\C-b" 'message-goto-body)
652 (define-key message-mode-map "\C-c\C-i" 'message-goto-signature)
654 (define-key message-mode-map "\C-c\C-t" 'message-insert-to)
655 (define-key message-mode-map "\C-c\C-n" 'message-insert-newsgroups)
657 (define-key message-mode-map "\C-c\C-y" 'message-yank-original)
658 (define-key message-mode-map "\C-c\C-q" 'message-fill-yanked-message)
659 (define-key message-mode-map "\C-c\C-w" 'message-insert-signature)
660 (define-key message-mode-map "\C-c\C-r" 'message-caesar-buffer-body)
661 (define-key message-mode-map "\C-c\C-h" 'message-sort-headers)
663 (define-key message-mode-map "\C-c\C-c" 'message-send-and-exit)
664 (define-key message-mode-map "\C-c\C-s" 'message-send)
665 (define-key message-mode-map "\C-c\C-k" 'message-dont-send))
667 (defun message-make-menu-bar ()
668 (unless (boundp 'message-menu)
670 message-menu message-mode-map ""
672 ["Fill Citation" message-fill-yanked-message t]))))
675 (defun message-mode ()
676 "Major mode for editing mail and news to be sent.
677 Like Text Mode but with these additional commands:
678 C-c C-s message-send (send the message) C-c C-c message-send-and-exit
679 C-c C-f move to a header field (and create it if there isn't):
680 C-c C-f C-t move to To C-c C-f C-s move to Subject
681 C-c C-f C-c move to Cc C-c C-f C-b move to Bcc
682 C-c C-f C-f move to Fcc C-c C-f C-r move to Reply-To
683 C-c C-f C-u move to Summary C-c C-f C-n move to Newsgroups
684 C-c C-f C-k move to Keywords C-c C-f C-d move to Distribution
685 C-c C-f C-o move to Followup-To
686 C-c C-t message-insert-to (add a To header to a news followup)
687 C-c C-n message-insert-newsgroups (add a Newsgroup header to a news reply)
688 C-c C-b message-goto-body (move to beginning of message text).
689 C-c C-i message-goto-signature (move to the beginning of the signature).
690 C-c C-w message-insert-signature (insert `message-signature-file' file).
691 C-c C-y message-yank-original (insert current message, if any).
692 C-c C-q message-fill-yanked-message (fill what was yanked).
693 C-c C-r message-ceasar-buffer-body (rot13 the message body)."
695 (kill-all-local-variables)
696 (make-local-variable 'message-reply-buffer)
697 (setq message-reply-buffer nil)
698 (make-local-variable 'message-send-actions)
699 (set-syntax-table message-mode-syntax-table)
700 (use-local-map message-mode-map)
701 (setq local-abbrev-table text-mode-abbrev-table)
702 (setq major-mode 'message-mode)
703 (setq mode-name "Message")
704 (setq buffer-offer-save t)
705 (make-local-variable 'font-lock-defaults)
706 (setq font-lock-defaults '(message-font-lock-keywords t))
707 (make-local-variable 'facemenu-add-face-function)
708 (make-local-variable 'facemenu-remove-face-function)
709 (setq facemenu-add-face-function
711 (let ((face-fun (cdr (assq face message-face-alist))))
713 (funcall face-fun (point) end)
714 (error "Face %s not configured for %s mode" face mode-name)))
716 facemenu-remove-face-function t)
717 (make-local-variable 'paragraph-separate)
718 (make-local-variable 'paragraph-start)
719 (setq paragraph-start (concat (regexp-quote mail-header-separator)
720 "$\\|[ \t]*[-_][-_][-_]+$\\|"
722 (setq paragraph-separate (concat (regexp-quote mail-header-separator)
723 "$\\|[ \t]*[-_][-_][-_]+$\\|"
725 (make-local-variable 'message-reply-headers)
726 (setq message-reply-headers nil)
727 (make-local-variable 'message-newsreader)
728 (make-local-variable 'message-mailer)
729 (make-local-variable 'message-post-method)
730 (make-local-variable 'message-sent-message-via)
731 (setq message-sent-message-via nil)
732 (make-local-variable 'message-checksum)
733 (setq message-checksum nil)
734 (when (fboundp 'mail-hist-define-keys)
735 (mail-hist-define-keys))
736 (run-hooks 'text-mode-hook 'message-mode-hook))
741 ;;; Message mode commands
744 ;;; Movement commands
746 (defun message-goto-to ()
747 "Move point to the To header."
749 (message-position-on-field "To"))
751 (defun message-goto-subject ()
752 "Move point to the Subject header."
754 (message-position-on-field "Subject"))
756 (defun message-goto-cc ()
757 "Move point to the Cc header."
759 (message-position-on-field "Cc" "To"))
761 (defun message-goto-bcc ()
762 "Move point to the Bcc header."
764 (message-position-on-field "Bcc" "Cc" "To"))
766 (defun message-goto-fcc ()
767 "Move point to the Fcc header."
769 (message-position-on-field "Fcc" "To" "Newsgroups"))
771 (defun message-goto-reply-to ()
772 "Move point to the Reply-To header."
774 (message-position-on-field "Reply-To" "Subject"))
776 (defun message-goto-newsgroups ()
777 "Move point to the Newsgroups header."
779 (message-position-on-field "Newsgroups"))
781 (defun message-goto-distribution ()
782 "Move point to the Distribution header."
784 (message-position-on-field "Distribution"))
786 (defun message-goto-followup-to ()
787 "Move point to the Followup-To header."
789 (message-position-on-field "Followup-To" "Newsgroups"))
791 (defun message-goto-keywords ()
792 "Move point to the Keywords header."
794 (message-position-on-field "Keywords" "Subject"))
796 (defun message-goto-summary ()
797 "Move point to the Summary header."
799 (message-position-on-field "Summary" "Subject"))
801 (defun message-goto-body ()
802 "Move point to the beginning of the message body."
804 (goto-char (point-min))
805 (search-forward (concat "\n" mail-header-separator "\n") nil t))
807 (defun message-goto-signature ()
808 "Move point to the beginning of the message signature."
810 (goto-char (point-min))
811 (or (re-search-forward message-signature-separator nil t)
812 (goto-char (point-max))))
816 (defun message-insert-to ()
817 "Insert a To header that points to the author of the article being replied to."
819 (when (message-position-on-field "To")
821 (insert (or (message-fetch-reply-field "reply-to")
822 (message-fetch-reply-field "from") "")))
824 (defun message-insert-newsgroups ()
825 "Insert the Newsgroups header from the article being replied to."
827 (when (message-position-on-field "Newsgroups")
829 (insert (or (message-fetch-reply-field "newsgroups") "")))
835 (defun message-insert-signature (&optional force)
836 "Insert a signature. See documentation for the `message-signature' variable."
837 (interactive (list t))
839 (cond ((and (null message-signature)
842 ((message-functionp message-signature)
843 (funcall message-signature))
844 ((listp message-signature)
845 (eval message-signature))
846 (t message-signature)))
848 (cond ((stringp signature)
850 ((and (eq t signature)
851 message-signature-file
852 (file-exists-p message-signature-file))
855 ;; Remove blank lines at the end of the message.
856 (goto-char (point-max))
857 (skip-chars-backward " \t\n")
859 (delete-region (point) (point-max))
860 ;; Insert the signature.
863 (insert-file-contents message-signature-file)
865 (goto-char (point-max))
866 (or (bolp) (insert "\n")))))
868 (defvar message-caesar-translation-table nil)
870 (defun message-caesar-region (b e &optional n)
871 "Caesar rotation of region by N, default 13, for decrypting netnews."
874 (min (point) (or (mark t) (point)))
875 (max (point) (or (mark t) (point)))
876 (when current-prefix-arg
877 (prefix-numeric-value current-prefix-arg))))
879 (setq n (if (numberp n) (mod n 26) 13)) ;canonize N
880 (unless (or (zerop n) ; no action needed for a rot of 0
881 (= b e)) ; no region to rotate
882 ;; We build the table, if necessary.
883 (when (or (not message-caesar-translation-table)
884 (/= (aref message-caesar-translation-table ?a) (+ ?a n)))
886 (table (make-string 256 0)))
887 (while (< (incf i) 256)
891 (substring table 0 ?A)
892 (substring table (+ ?A n) (+ ?A n (- 26 n)))
893 (substring table ?A (+ ?A n))
894 (substring table (+ ?A 26) ?a)
895 (substring table (+ ?a n) (+ ?a n (- 26 n)))
896 (substring table ?a (+ ?a n))
897 (substring table (+ ?a 26) 255)))
898 (setq message-caesar-translation-table table)))
899 ;; Then we translate the region. Do it this way to retain
902 (subst-char-in-region
903 b (1+ b) (char-after b)
904 (aref message-caesar-translation-table (char-after b)))
907 (defun message-caesar-buffer-body (&optional rotnum)
908 "Caesar rotates all letters in the current buffer by 13 places.
909 Used to encode/decode possibly offensive messages (commonly in net.jokes).
910 With prefix arg, specifies the number of places to rotate each letter forward.
911 Mail and USENET news headers are not rotated."
912 (interactive (if current-prefix-arg
913 (list (prefix-numeric-value current-prefix-arg))
917 (when (message-goto-body)
918 (narrow-to-region (point) (point-max)))
919 (message-caesar-region (point-min) (point-max) rotnum))))
921 (defun message-fill-yanked-message (&optional justifyp)
922 "Fill the paragraphs of a message yanked into this one.
923 Numeric argument means justify as well."
926 (goto-char (point-min))
927 (search-forward (concat "\n" mail-header-separator "\n") nil t)
928 (let ((fill-prefix message-yank-prefix))
929 (fill-individual-paragraphs (point) (point-max) justifyp t))))
931 (defun message-indent-citation ()
932 "Modify text just inserted from a message to be cited.
933 The inserted text should be the region.
934 When this function returns, the region is again around the modified text.
936 Normally, indent each nonblank line `message-indentation-spaces' spaces.
937 However, if `message-yank-prefix' is non-nil, insert that prefix on each line."
938 (let ((start (point)))
939 ;; Remove unwanted headers.
940 (when message-ignored-cited-headers
944 (if (search-forward "\n\n" nil t)
947 (message-remove-header message-ignored-cited-headers t)))
948 ;; Do the indentation.
949 (if (null message-yank-prefix)
950 (indent-rigidly start (mark t) message-indentation-spaces)
953 (while (< (point) (mark t))
954 (insert message-yank-prefix)
958 (defun message-yank-original (&optional arg)
959 "Insert the message being replied to, if any.
960 Puts point before the text and mark after.
961 Normally indents each nonblank line ARG spaces (default 3). However,
962 if `message-yank-prefix' is non-nil, insert that prefix on each line.
964 Just \\[universal-argument] as argument means don't indent, insert no
965 prefix, and don't delete any headers."
967 (let ((modified (buffer-modified-p)))
968 (when (and message-reply-buffer
969 message-cite-function)
970 (delete-windows-on message-reply-buffer t)
971 (insert-buffer message-reply-buffer)
972 (funcall message-cite-function)
973 (exchange-point-and-mark)
977 (setq message-checksum (message-checksum))))))
979 (defun message-cite-original ()
980 (let ((start (point))
982 (when message-indent-citation-function
983 (if (listp message-indent-citation-function)
984 message-indent-citation-function
985 (list message-indent-citation-function)))))
988 (funcall (pop functions)))
989 (when message-citation-line-function
992 (funcall message-citation-line-function))))
994 (defun message-insert-citation-line ()
995 "Function that inserts a simple citation line."
996 (when message-reply-headers
997 (insert (mail-header-from message-reply-headers) " writes:\n\n")))
999 (defun message-position-on-field (header &rest afters)
1000 (let ((case-fold-search t))
1003 (goto-char (point-min))
1006 (concat "^" (regexp-quote mail-header-separator) "$"))
1007 (match-beginning 0)))
1008 (goto-char (point-min))
1009 (if (re-search-forward (concat "^" (regexp-quote header) ":") nil t)
1011 (re-search-forward "^[^ \t]" nil 'move)
1013 (skip-chars-backward "\n")
1016 (not (re-search-forward
1017 (concat "^" (regexp-quote (car afters)) ":")
1021 (re-search-forward "^[^ \t]" nil 'move)
1022 (beginning-of-line))
1023 (insert header ": \n")
1027 (defun message-remove-signature ()
1028 "Remove the signature from the text between point and mark.
1029 The text will also be indented the normal way."
1031 (let ((start (point))
1033 (if (not (re-search-forward message-signature-separator (mark t) t))
1034 ;; No signature here, so we just indent the cited text.
1035 (message-indent-citation)
1036 ;; Find the last non-empty line.
1038 (while (looking-at "[ \t]*$")
1041 (setq mark (set-marker (make-marker) (point)))
1043 (message-indent-citation)
1044 ;; Enable undoing the deletion.
1046 (delete-region mark (mark t))
1047 (set-marker mark nil)))))
1052 ;;; Sending messages
1055 (defun message-send-and-exit (&optional arg)
1056 "Send message like `message-send', then, if no errors, exit from mail buffer."
1058 (let ((buf (current-buffer)))
1059 (when (and (message-send arg)
1061 (if message-kill-buffer-on-exit
1064 (when (eq buf (current-buffer))
1065 (message-bury buf))))))
1067 (defun message-dont-send ()
1068 "Don't send the message you have been editing."
1070 (message-bury (current-buffer)))
1072 (defun message-bury (buffer)
1073 "Bury this mail buffer."
1074 (let ((newbuf (other-buffer buffer)))
1075 (bury-buffer buffer)
1076 (if (and (fboundp 'frame-parameters)
1077 (cdr (assq 'dedicated (frame-parameters)))
1078 (not (null (delq (selected-frame) (visible-frame-list)))))
1079 (delete-frame (selected-frame))
1080 (switch-to-buffer newbuf))))
1082 (defun message-send (&optional arg)
1083 "Send the message in the current buffer.
1084 If `message-interactive' is non-nil, wait for success indication
1085 or error messages, and inform user.
1086 Otherwise any failure is reported in a message back to
1087 the user from the mailer."
1089 (when (if buffer-file-name
1090 (y-or-n-p (format "Send buffer contents as %s message? "
1091 (if (message-mail-p)
1092 (if (message-news-p) "mail and news" "mail")
1094 (or (buffer-modified-p)
1095 (y-or-n-p "No changes in the buffer; really send? ")))
1096 ;; Make it possible to undo the coming changes.
1098 (run-hooks 'message-send-hook)
1099 (message "Sending...")
1100 (when (and (or (not (message-news-p))
1101 (and (or (not (memq 'news message-sent-message-via))
1103 "Already sent message via news; resend? "))
1104 (funcall message-send-news-function arg)))
1105 (or (not (message-mail-p))
1106 (and (or (not (memq 'mail message-sent-message-via))
1108 "Already sent message via mail; resend? "))
1109 (funcall message-send-mail-function arg))))
1111 (when (fboundp 'mail-hist-put-headers-into-history)
1112 (mail-hist-put-headers-into-history))
1113 (run-hooks 'message-sent-hook)
1114 (message "Sending...done")
1115 ;; If buffer has no file, mark it as unmodified and delete autosave.
1116 (unless buffer-file-name
1117 (set-buffer-modified-p nil)
1118 (delete-auto-save-file-if-necessary t))
1119 ;; Now perform actions on successful sending.
1120 (let ((actions message-send-actions))
1123 (apply (caar actions) (cdar actions))
1129 (defun message-send-mail (&optional arg)
1130 (require 'mail-utils)
1131 (let ((errbuf (if message-interactive
1132 (generate-new-buffer " sendmail errors")
1134 (tembuf (generate-new-buffer " message temp"))
1135 (case-fold-search nil)
1136 (news (message-news-p))
1137 resend-to-addresses delimline
1138 (mailbuf (current-buffer)))
1140 (message-narrow-to-headers)
1141 (setq resend-to-addresses (mail-fetch-field "resent-to"))
1142 ;; Insert some headers.
1143 (message-generate-headers message-required-mail-headers)
1144 ;; Let the user do all of the above.
1145 (run-hooks 'message-header-hook))
1150 (insert-buffer-substring mailbuf)
1151 ;; Remove some headers.
1153 (message-narrow-to-headers)
1154 ;; Remove some headers.
1155 (message-remove-header message-ignored-mail-headers t))
1156 (goto-char (point-max))
1157 ;; require one newline at the end.
1158 (or (= (preceding-char) ?\n)
1161 (or (mail-fetch-field "cc")
1162 (mail-fetch-field "to")))
1163 (message-insert-courtesy-copy))
1164 (let ((case-fold-search t))
1165 ;; Change header-delimiter to be what sendmail expects.
1166 (goto-char (point-min))
1168 (concat "^" (regexp-quote mail-header-separator) "\n"))
1169 (replace-match "\n")
1171 (setq delimline (point-marker))
1172 ;; Insert an extra newline if we need it to work around
1173 ;; Sun's bug that swallows newlines.
1174 (goto-char (1+ delimline))
1175 (when (eval message-mailer-swallows-blank-line)
1177 (when message-interactive
1181 (let ((default-directory "/"))
1182 (apply 'call-process-region
1183 (append (list (point-min) (point-max)
1184 (if (boundp 'sendmail-program)
1186 "/usr/lib/sendmail")
1187 nil errbuf nil "-oi")
1188 ;; Always specify who from,
1189 ;; since some systems have broken sendmails.
1190 (list "-f" (user-login-name))
1191 ;; These mean "report errors by mail"
1192 ;; and "deliver in background".
1193 (if (null message-interactive) '("-oem" "-odb"))
1194 ;; Get the addresses from the message
1195 ;; unless this is a resend.
1196 ;; We must not do that for a resend
1197 ;; because we would find the original addresses.
1198 ;; For a resend, include the specific addresses.
1199 (if resend-to-addresses
1200 (list resend-to-addresses)
1202 (when message-interactive
1205 (goto-char (point-min))
1206 (while (re-search-forward "\n\n* *" nil t)
1207 (replace-match "; "))
1208 (if (not (zerop (buffer-size)))
1209 (error "Sending...failed to %s"
1210 (buffer-substring (point-min) (point-max)))))))
1211 (kill-buffer tembuf)
1212 (when (bufferp errbuf)
1213 (kill-buffer errbuf)))
1214 (set-buffer mailbuf)
1215 (push 'mail message-sent-message-via)))
1217 (defun message-send-news (&optional arg)
1218 (let ((tembuf (generate-new-buffer " *message temp*"))
1219 (case-fold-search nil)
1220 (method (if (message-functionp message-post-method)
1221 (funcall message-post-method arg)
1222 message-post-method))
1223 (messbuf (current-buffer)))
1225 (message-narrow-to-headers)
1226 ;; Insert some headers.
1227 (message-generate-headers message-required-news-headers)
1228 ;; Let the user do all of the above.
1229 (run-hooks 'message-header-hook))
1230 (when (message-check-news-syntax)
1234 (buffer-disable-undo (current-buffer))
1236 (insert-buffer-substring messbuf)
1237 ;; Remove some headers.
1239 (message-narrow-to-headers)
1240 ;; Remove some headers.
1241 (message-remove-header message-ignored-news-headers t))
1242 (goto-char (point-max))
1243 ;; require one newline at the end.
1244 (or (= (preceding-char) ?\n)
1246 (let ((case-fold-search t))
1247 ;; Remove the delimeter.
1248 (goto-char (point-min))
1250 (concat "^" (regexp-quote mail-header-separator) "\n"))
1251 (replace-match "\n")
1253 (require (car method))
1254 (funcall (intern (format "%s-open-server" (car method)))
1255 (cadr method) (cddr method))
1256 (funcall (intern (format "%s-request-post"
1258 (kill-buffer tembuf))
1259 (set-buffer messbuf)
1260 (push 'news message-sent-message-via))))
1263 ;;; Header generation & syntax checking.
1266 (defun message-check-news-syntax ()
1267 "Check the syntax of the message."
1269 ;; We narrow to the headers and check them first.
1272 (message-narrow-to-headers)
1274 ;; Check for commands in Subject.
1276 (message-check-element 'subject-cmsg)
1278 (if (string-match "^cmsg " (mail-fetch-field "subject"))
1280 "The control code \"cmsg \" is in the subject. Really post? ")
1282 ;; Check for multiple identical headers.
1283 (or (message-check-element 'multiple-headers)
1286 (while (and (not found)
1287 (re-search-forward "^[^ \t:]+: " nil t))
1289 (or (re-search-forward
1290 (concat "^" (setq found
1293 (- (match-end 0) 2))))
1298 (format "Multiple %s headers. Really post? " found))
1300 ;; Check for Version and Sendsys.
1301 (or (message-check-element 'sendsys)
1303 (if (re-search-forward "^Sendsys:\\|^Version:" nil t)
1305 (format "The article contains a %s command. Really post? "
1306 (buffer-substring (match-beginning 0)
1307 (1- (match-end 0)))))
1309 ;; See whether we can shorten Followup-To.
1310 (or (message-check-element 'shorten-followup-to)
1311 (let ((newsgroups (mail-fetch-field "newsgroups"))
1312 (followup-to (mail-fetch-field "followup-to"))
1314 (when (and newsgroups (string-match "," newsgroups)
1319 (setq to (completing-read
1320 "Followups to: (default all groups) "
1321 (mapcar (lambda (g) (list g))
1323 (message-tokenize-header
1325 (goto-char (point-min))
1326 (insert "Followup-To: " to "\n"))
1329 ;; Check for Approved.
1330 (or (message-check-element 'approved)
1332 (if (re-search-forward "^Approved:" nil t)
1334 "The article contains an Approved header. Really post? ")
1336 ;; Check the Message-Id header.
1337 (or (message-check-element 'message-id)
1339 (let* ((case-fold-search t)
1340 (message-id (mail-fetch-field "message-id")))
1341 (or (not message-id)
1342 (and (string-match "@" message-id)
1343 (string-match "@[^\\.]*\\." message-id))
1346 "The Message-ID looks strange: \"%s\". Really post? "
1348 ;; Check the Subject header.
1350 (message-check-element 'subject)
1352 (let* ((case-fold-search t)
1353 (subject (mail-fetch-field "subject")))
1356 (not (string-match "\\`[ \t]*\\'" subject)))
1359 "The subject field is empty or missing. Posting is denied.")
1361 ;; Check the From header.
1362 (or (message-check-element 'from)
1364 (let* ((case-fold-search t)
1365 (from (mail-fetch-field "from")))
1368 (message "There is no From line. Posting is denied.")
1370 ((not (string-match "@[^\\.]*\\." from))
1372 "Denied posting -- the From looks strange: \"%s\"." from)
1374 ((string-match "@[^@]*@" from)
1376 "Denied posting -- two \"@\"'s in the From header: %s."
1379 ((string-match "(.*).*(.*)" from)
1381 "Denied posting -- the From header looks strange: \"%s\"."
1385 ;; Check for long lines.
1386 (or (message-check-element 'long-lines)
1388 (goto-char (point-min))
1390 (concat "^" (regexp-quote mail-header-separator) "$"))
1394 (< (current-column) 80))
1395 (zerop (forward-line 1))))
1399 "You have lines longer than 79 characters. Really post? "))))
1400 ;; Check whether the article is empty.
1401 (or (message-check-element 'empty)
1403 (goto-char (point-min))
1405 (concat "^" (regexp-quote mail-header-separator) "$"))
1407 (or (re-search-forward "[^ \n\t]" nil t)
1408 (y-or-n-p "Empty article. Really post?"))))
1409 ;; Check for control characters.
1410 (or (message-check-element 'control-chars)
1412 (if (re-search-forward "[\000-\007\013\015-\037\200-\237]" nil t)
1414 "The article contains control characters. Really post? ")
1416 ;; Check excessive size.
1417 (or (message-check-element 'size)
1418 (if (> (buffer-size) 60000)
1420 (format "The article is %d octets long. Really post? "
1423 ;; Check whether any new text has been added.
1424 (or (message-check-element 'new-text)
1425 (not message-checksum)
1426 (not (eq (message-checksum) message-checksum))
1428 "It looks like no new text has been added. Really post? "))
1429 ;; Check the length of the signature.
1430 (or (message-check-element 'signature)
1432 (goto-char (point-max))
1433 (if (not (re-search-backward "^-- $" nil t))
1435 (if (> (count-lines (point) (point-max)) 5)
1438 "Your .sig is %d lines; it should be max 4. Really post? "
1439 (count-lines (point) (point-max))))
1442 (defun message-check-element (type)
1443 "Returns non-nil if this type is not to be checked."
1444 (if (eq message-syntax-checks 'dont-check-for-anything-just-trust-me)
1446 (let ((able (assq type message-syntax-checks)))
1448 (eq (cdr able) 'disabled)))))
1450 (defun message-checksum ()
1451 "Return a \"checksum\" for the current buffer."
1455 (setq sum (logxor sum (following-char)))
1459 (defun message-do-fcc ()
1460 "Process Fcc headers in the current buffer."
1461 (let ((case-fold-search t)
1462 (buf (current-buffer))
1465 (set-buffer (get-buffer-create " *message temp*"))
1466 (buffer-disable-undo (current-buffer))
1468 (insert-buffer-substring buf)
1470 (message-narrow-to-headers)
1471 (while (setq file (mail-fetch-field "fcc"))
1473 (message-remove-header "fcc" nil t)))
1474 (goto-char (point-min))
1475 (re-search-forward (concat "^" (regexp-quote mail-header-separator) "$"))
1476 (replace-match "" t t)
1477 ;; Process FCC operations.
1479 (setq file (pop list))
1480 (if (string-match "^[ \t]*|[ \t]*\\(.*\\)[ \t]*$" file)
1481 ;; Pipe the article to the program in question.
1482 (call-process-region (point-min) (point-max) shell-file-name
1483 nil nil nil "-c" (match-string 1 file))
1484 ;; Save the article.
1485 (setq file (expand-file-name file))
1486 (unless (file-exists-p (file-name-directory file))
1487 (make-directory (file-name-directory file) t))
1488 (if (and message-fcc-handler-function
1489 (not (eq message-fcc-handler-function 'rmail-output)))
1490 (funcall message-fcc-handler-function file)
1491 (if (and (file-readable-p file) (mail-file-babyl-p file))
1492 (rmail-output file 1)
1493 (let ((mail-use-rfc822 t))
1494 (rmail-output file 1 t t))))))
1495 (kill-buffer (current-buffer)))))
1497 (defun message-cleanup-headers ()
1498 "Do various automatic cleanups of the headers."
1499 ;; Remove empty lines in the header.
1501 (message-narrow-to-headers)
1502 (while (re-search-forward "^[ \t]*\n" nil t)
1503 (replace-match "" t t)))
1505 ;; Correct Newsgroups and Followup-To headers: change sequence of
1506 ;; spaces to comma and eliminate spaces around commas. Eliminate
1507 ;; embedded line breaks.
1508 (goto-char (point-min))
1509 (while (re-search-forward "^\\(Newsgroups\\|Followup-To\\): +" nil t)
1513 (if (re-search-forward "^[^ \t]" nil t)
1517 (goto-char (point-min))
1518 (while (re-search-forward "\n[ \t]+" nil t)
1519 (replace-match " " t t)) ;No line breaks (too confusing)
1520 (goto-char (point-min))
1521 (while (re-search-forward "[ \t\n]*,[ \t\n]*\\|[ \t]+" nil t)
1522 (replace-match "," t t))
1523 (goto-char (point-min))
1524 ;; Remove trailing commas.
1525 (when (re-search-forward ",+$" nil t)
1526 (replace-match "" t t)))))
1528 (defun message-make-date ()
1529 "Make a valid data header."
1530 (let ((now (current-time)))
1531 (timezone-make-date-arpa-standard
1532 (current-time-string now) (current-time-zone now))))
1534 (defun message-make-message-id ()
1535 "Make a unique Message-ID."
1536 (concat "<" (message-unique-id)
1537 (let ((psubject (save-excursion (mail-fetch-field "subject"))))
1538 (if (and message-reply-headers
1539 (mail-header-references message-reply-headers)
1540 (mail-header-subject message-reply-headers)
1542 (mail-header-subject message-reply-headers)
1544 (message-strip-subject-re
1545 (mail-header-subject message-reply-headers))
1546 (message-strip-subject-re psubject))))
1548 "@" (message-make-fqdm) ">"))
1550 (defvar message-unique-id-char nil)
1552 ;; If you ever change this function, make sure the new version
1553 ;; cannot generate IDs that the old version could.
1554 ;; You might for example insert a "." somewhere (not next to another dot
1555 ;; or string boundary), or modify the "fsf" string.
1556 (defun message-unique-id ()
1557 ;; Don't use microseconds from (current-time), they may be unsupported.
1558 ;; Instead we use this randomly inited counter.
1559 (setq message-unique-id-char
1560 (% (1+ (or message-unique-id-char (logand (random t) (1- (lsh 1 20)))))
1561 ;; (current-time) returns 16-bit ints,
1562 ;; and 2^16*25 just fits into 4 digits i base 36.
1564 (let ((tm (current-time)))
1566 (if (memq system-type '(ms-dos emx vax-vms))
1567 (let ((user (downcase (user-login-name))))
1568 (while (string-match "[^a-z0-9_]" user)
1569 (aset user (match-beginning 0) ?_))
1571 (message-number-base36 (user-uid) -1))
1572 (message-number-base36 (+ (car tm)
1573 (lsh (% message-unique-id-char 25) 16)) 4)
1574 (message-number-base36 (+ (nth 1 tm)
1575 (lsh (/ message-unique-id-char 25) 16)) 4)
1576 ;; Append the newsreader name, because while the generated
1577 ;; ID is unique to this newsreader, other newsreaders might
1578 ;; otherwise generate the same ID via another algorithm.
1581 (defun message-number-base36 (num len)
1582 (if (if (< len 0) (<= num 0) (= len 0))
1584 (concat (message-number-base36 (/ num 36) (1- len))
1585 (char-to-string (aref "zyxwvutsrqponmlkjihgfedcba9876543210"
1588 (defun message-make-organization ()
1589 "Make an Organization header."
1590 (let* ((organization
1591 (or (getenv "ORGANIZATION")
1592 (when message-user-organization
1593 (if (message-functionp message-user-organization)
1594 (funcall message-user-organization)
1595 message-user-organization)))))
1597 (message-set-work-buffer)
1598 (cond ((stringp message-user-organization)
1599 (insert message-user-organization))
1600 ((and (eq t message-user-organization)
1601 message-user-organization-file
1602 (file-exists-p message-user-organization-file))
1603 (insert-file-contents message-user-organization-file)))
1604 (goto-char (point-min))
1605 (while (re-search-forward "[\t\n]+" nil t)
1606 (replace-match "" t t))
1607 (unless (zerop (buffer-size))
1610 (defun message-make-lines ()
1611 "Count the number of lines and return numeric string."
1615 (goto-char (point-min))
1617 (concat "^" (regexp-quote mail-header-separator) "$"))
1619 (int-to-string (count-lines (point) (point-max))))))
1621 (defun message-make-in-reply-to ()
1622 "Return the In-Reply-To header for this message."
1623 (when message-reply-headers
1624 (let ((from (mail-header-from message-reply-headers))
1625 (date (mail-header-date message-reply-headers)))
1628 (string-match " *at \\| *@ \\| *(\\| *<" from)))
1629 (concat (if stop-pos (substring from 0 stop-pos) from)
1631 (if (or (not date) (string= date ""))
1632 "(unknown date)" date)))))))
1634 (defun message-make-distribution ()
1635 "Make a Distribution header."
1636 (let ((orig-distribution (message-fetch-reply-field "distribution")))
1637 (cond ((message-functionp message-distribution-function)
1638 (funcall message-distribution-function))
1639 (t orig-distribution))))
1641 (defun message-make-expires ()
1642 "Return an Expires header based on `message-expires'."
1643 (let ((current (current-time))
1644 (future (* 1.0 message-expires 60 60 24)))
1645 ;; Add the future to current.
1646 (setcar current (+ (car current) (round (/ future (expt 2 16)))))
1647 (setcar (cdr current) (+ (nth 1 current) (% (round future) (expt 2 16))))
1648 ;; Return the date in the future in UT.
1649 (timezone-make-date-arpa-standard
1650 (current-time-string current) (current-time-zone current) '(0 "UT"))))
1652 (defun message-make-path ()
1654 (let ((login-name (user-login-name)))
1655 (cond ((null message-user-path)
1656 (concat (system-name) "!" login-name))
1657 ((stringp message-user-path)
1658 ;; Support GENERICPATH. Suggested by vixie@decwrl.dec.com.
1659 (concat message-user-path "!" login-name))
1662 (defun message-make-from ()
1663 "Make a From header."
1664 (let* ((login (message-make-address))
1665 (fullname (user-full-name)))
1666 (when (string= fullname "&")
1667 (setq fullname (user-login-name)))
1669 (message-set-work-buffer)
1671 ((or (null message-from-style)
1672 (equal fullname ""))
1674 ((or (eq message-from-style 'angles)
1675 (and (not (eq message-from-style 'parens))
1676 ;; Use angles if no quoting is needed, or if parens would
1677 ;; need quoting too.
1678 (or (not (string-match "[^- !#-'*+/-9=?A-Z^-~]" fullname))
1679 (let ((tmp (concat fullname nil)))
1680 (while (string-match "([^()]*)" tmp)
1681 (aset tmp (match-beginning 0) ?-)
1682 (aset tmp (1- (match-end 0)) ?-))
1683 (string-match "[\\()]" tmp)))))
1685 (goto-char (point-min))
1686 ;; Look for a character that cannot appear unquoted
1687 ;; according to RFC 822.
1688 (when (re-search-forward "[^- !#-'*+/-9=?A-Z^-~]" nil 1)
1689 ;; Quote fullname, escaping specials.
1690 (goto-char (point-min))
1692 (while (re-search-forward "[\"\\]" nil 1)
1693 (replace-match "\\\\\\&" t))
1695 (insert " <" login ">"))
1696 (t ; 'parens or default
1698 (let ((fullname-start (point)))
1700 (goto-char fullname-start)
1701 ;; RFC 822 says \ and nonmatching parentheses
1702 ;; must be escaped in comments.
1703 ;; Escape every instance of ()\ ...
1704 (while (re-search-forward "[()\\]" nil 1)
1705 (replace-match "\\\\\\&" t))
1706 ;; ... then undo escaping of matching parentheses,
1707 ;; including matching nested parentheses.
1708 (goto-char fullname-start)
1709 (while (re-search-forward
1710 "\\(\\=\\|[^\\]\\(\\\\\\\\\\)*\\)\\\\(\\(\\([^\\]\\|\\\\\\\\\\)*\\)\\\\)"
1712 (replace-match "\\1(\\3)" t)
1713 (goto-char fullname-start)))
1717 (defun message-make-sender ()
1718 "Return the \"real\" user address.
1719 This function tries to ignore all user modifications, and
1720 give as trustworthy answer as possible."
1721 (concat (user-login-name) "@" (system-name)))
1723 (defun message-make-address ()
1724 "Make the address of the user."
1725 (or (message-user-mail-address)
1726 (concat (user-login-name) "@" (message-make-domain))))
1728 (defun message-user-mail-address ()
1729 "Return the pertinent part of `user-mail-address'."
1730 (when user-mail-address
1731 (nth 1 (mail-extract-address-components user-mail-address))))
1733 (defun message-make-fqdm ()
1734 "Return user's fully qualified domain name."
1735 (let ((system-name (system-name)))
1737 ((string-match "[^.]\\.[^.]" system-name)
1738 ;; `system-name' returned the right result.
1740 ;; We try `user-mail-address' as a backup.
1741 ((string-match "@\\(.*\\)\\'" (message-user-mail-address))
1742 (match-string 1 user-mail-address))
1743 ;; Try `mail-host-address'.
1744 ((and (boundp 'mail-host-address)
1747 ;; Default to this bogus thing.
1749 (concat system-name ".i-have-a-misconfigured-system-so-shoot-me")))))
1751 (defun message-make-host-name ()
1752 "Return the name of the host."
1753 (let ((fqdm (message-make-fqdm)))
1754 (string-match "^[^.]+\\." fqdm)
1755 (substring fqdm 0 (1- (match-end 0)))))
1757 (defun message-make-domain ()
1758 "Return the domain name."
1759 (or mail-host-address
1760 (message-make-fqdm)))
1762 (defun message-generate-headers (headers)
1763 "Prepare article HEADERS.
1764 Headers already prepared in the buffer are not modified."
1766 (message-narrow-to-headers)
1767 (let* ((Date (message-make-date))
1768 (Message-ID (message-make-message-id))
1769 (Organization (message-make-organization))
1770 (From (message-make-from))
1771 (Path (message-make-path))
1774 (In-Reply-To (message-make-in-reply-to))
1776 (Distribution (message-make-distribution))
1777 (Lines (message-make-lines))
1778 (X-Newsreader message-newsreader)
1779 (X-Mailer (and (not (mail-fetch-field "X-Newsreader"))
1781 (Expires (message-make-expires))
1782 (case-fold-search t)
1784 ;; First we remove any old generated headers.
1785 (let ((headers message-deletable-headers))
1787 (goto-char (point-min))
1788 (and (re-search-forward
1789 (concat "^" (symbol-name (car headers)) ": *") nil t)
1790 (get-text-property (1+ (match-beginning 0)) 'message-deletable)
1791 (message-delete-line))
1793 ;; Go through all the required headers and see if they are in the
1794 ;; articles already. If they are not, or are empty, they are
1795 ;; inserted automatically - except for Subject, Newsgroups and
1798 (goto-char (point-min))
1799 (setq elem (pop headers))
1801 (if (eq (car elem) 'optional)
1802 (setq header (cdr elem))
1803 (setq header (car elem)))
1805 (when (or (not (re-search-forward
1806 (concat "^" (downcase (symbol-name header)) ":")
1809 ;; The header was found. We insert a space after the
1810 ;; colon, if there is none.
1811 (if (/= (following-char) ? ) (insert " ") (forward-char 1))
1812 ;; Find out whether the header is empty...
1813 (looking-at "[ \t]*$")))
1814 ;; So we find out what value we should insert.
1817 ((and (consp elem) (eq (car elem) 'optional))
1818 ;; This is an optional header. If the cdr of this
1819 ;; is something that is nil, then we do not insert
1821 (setq header (cdr elem))
1822 (or (and (fboundp (cdr elem)) (funcall (cdr elem)))
1823 (and (boundp (cdr elem)) (symbol-value (cdr elem)))))
1825 ;; The element is a cons. Either the cdr is a
1826 ;; string to be inserted verbatim, or it is a
1827 ;; function, and we insert the value returned from
1829 (or (and (stringp (cdr elem)) (cdr elem))
1830 (and (fboundp (cdr elem)) (funcall (cdr elem)))))
1831 ((and (boundp header) (symbol-value header))
1832 ;; The element is a symbol. We insert the value
1833 ;; of this symbol, if any.
1834 (symbol-value header))
1836 ;; We couldn't generate a value for this header,
1837 ;; so we just ask the user.
1838 (read-from-minibuffer
1839 (format "Empty header for %s; enter value: " header)))))
1840 ;; Finally insert the header.
1842 (not (equal value "")))
1846 ;; This header didn't exist, so we insert it.
1847 (goto-char (point-max))
1848 (insert (symbol-name header) ": " value "\n")
1850 ;; The value of this header was empty, so we clear
1851 ;; totally and insert the new value.
1852 (delete-region (point) (message-point-at-eol))
1854 ;; Add the deletable property to the headers that require it.
1855 (and (memq header message-deletable-headers)
1856 (progn (beginning-of-line) (looking-at "[^:]+: "))
1857 (add-text-properties
1858 (point) (match-end 0)
1859 '(message-deletable t face italic) (current-buffer)))))))
1860 ;; Insert new Sender if the From is strange.
1861 (let ((from (mail-fetch-field "from"))
1862 (sender (mail-fetch-field "sender"))
1863 (secure-sender (message-make-sender)))
1865 (not (message-check-element 'sender))
1868 (cadr (mail-extract-address-components from)))
1869 (downcase secure-sender)))
1874 (cadr (mail-extract-address-components sender)))
1875 (downcase secure-sender)))))
1876 (goto-char (point-min))
1877 ;; Rename any old Sender headers to Original-Sender.
1878 (when (re-search-forward "^Sender:" nil t)
1880 (insert "Original-")
1881 (beginning-of-line))
1882 (insert "Sender: " secure-sender "\n"))))))
1884 (defun message-insert-courtesy-copy ()
1885 "Insert a courtesy message in mail copies of combined messages."
1888 (message-narrow-to-headers)
1889 (let ((newsgroups (mail-fetch-field "newsgroups")))
1891 (goto-char (point-max))
1892 (insert "Posted-To: " newsgroups "\n"))))
1894 (insert message-courtesy-message)))
1897 ;;; Setting up a message buffer
1900 (defun message-fill-header (header value)
1901 (let ((begin (point))
1905 (insert (capitalize (symbol-name header))
1907 (if (consp value) (car value) value)
1910 (narrow-to-region begin (point))
1911 (fill-region-as-paragraph begin (point))
1912 ;; Tapdance around looong Message-IDs.
1914 (when (looking-at "[ \t]*$")
1915 (message-delete-line))
1917 (re-search-forward ":" nil t)
1918 (when (looking-at "\n[ \t]+")
1919 (replace-match " " t t))
1920 (goto-char (point-max)))))
1922 (defun message-position-point ()
1923 "Move point to where the user probably wants to find it."
1924 (message-narrow-to-headers)
1926 ((re-search-forward "^[^:]+:[ \t]*$" nil t)
1927 (search-backward ":" )
1930 (if (= (following-char) ? )
1934 (goto-char (point-max))
1937 (unless (looking-at "$")
1941 (defun message-pop-to-buffer (name)
1942 "Pop to buffer NAME, and warn if it already exists and is modified."
1943 (if message-generate-new-buffers
1944 (set-buffer (pop-to-buffer (generate-new-buffer name)))
1945 (let ((buffer (get-buffer name)))
1947 (buffer-name buffer))
1949 (set-buffer (pop-to-buffer buffer))
1950 (when (and (buffer-modified-p)
1952 "Message already being composed; erase? ")))
1953 (error "Message being composed")))
1954 (set-buffer (pop-to-buffer name)))))
1958 (defun message-setup (headers &optional replybuffer actions)
1959 (setq message-send-actions actions)
1960 (setq message-reply-buffer replybuffer)
1961 (goto-char (point-min))
1962 ;; Insert all the headers.
1965 (alist message-header-format-alist))
1967 (unless (assq (caar h) message-header-format-alist)
1968 (push (list (caar h)) alist))
1973 (when message-default-headers
1974 (insert message-default-headers))
1975 (insert mail-header-separator "\n")
1977 (when (message-news-p)
1978 (when message-default-news-headers
1979 (insert message-default-news-headers))
1980 (when message-generate-headers-first
1981 (message-generate-headers
1983 (copy-sequence message-required-news-headers)))))
1984 (when (message-mail-p)
1985 (when message-default-mail-headers
1986 (insert message-default-mail-headers))
1987 (when message-generate-headers-first
1988 (message-generate-headers
1990 (copy-sequence message-required-mail-headers)))))
1991 (message-insert-signature)
1992 (message-set-auto-save-file-name)
1994 (message-narrow-to-headers)
1995 (run-hooks 'message-header-setup-hook))
1996 ;; Allow mail alias things.
1997 (if (fboundp 'mail-abbrevs-setup)
1998 (mail-abbrevs-setup)
1999 (funcall (intern "mail-aliases-setup")))
2000 (set-buffer-modified-p nil)
2001 (run-hooks 'message-setup-hook)
2002 (message-position-point)
2005 (defun message-set-auto-save-file-name ()
2006 "Associate the message buffer with a file in the drafts directory."
2007 (when message-autosave-directory
2008 (unless (file-exists-p message-autosave-directory)
2009 (make-directory message-autosave-directory t))
2010 (let ((name (make-temp-name
2011 (concat (file-name-as-directory message-autosave-directory)
2013 (setq buffer-auto-save-file-name
2017 (set-buffer (get-buffer-create " *draft tmp*"))
2018 (setq buffer-file-name name)
2019 (make-auto-save-file-name))
2020 (kill-buffer (current-buffer)))))
2021 (clear-visited-file-modtime))))
2026 ;;; Commands for interfacing with message
2030 (defun message-mail (&optional to subject)
2031 "Start editing a mail message to be sent."
2033 (message-pop-to-buffer "*mail message*")
2034 (message-setup `((To . ,(or to "")) (Subject . ,(or subject "")))))
2037 (defun message-news (&optional newsgroups subject)
2038 "Start editing a news article to be sent."
2040 (message-pop-to-buffer "*news message*")
2041 (message-setup `((Newsgroups . ,(or newsgroups ""))
2042 (Subject . ,(or subject "")))))
2045 (defun message-reply (&optional to-address wide ignore-reply-to)
2046 "Start editing a reply to the article in the current buffer."
2048 (let ((cur (current-buffer))
2049 from subject date reply-to message-of to cc
2050 references message-id sender follow-to sendto elt new-cc new-to
2051 mct never-mct gnus-warning)
2054 (goto-char (point-min))
2055 (if (search-forward "\n\n" nil t)
2058 ;; Allow customizations to have their say.
2060 ;; This is a regular reply.
2061 (if (message-functionp message-reply-to-function)
2062 (setq follow-to (funcall message-reply-to-function)))
2063 ;; This is a followup.
2064 (if (message-functionp message-wide-reply-to-function)
2067 (funcall message-wide-reply-to-function)))))
2068 ;; Find all relevant headers we need.
2069 (setq from (mail-fetch-field "from")
2070 date (mail-fetch-field "date")
2071 sender (mail-fetch-field "sender")
2072 subject (or (mail-fetch-field "subject") "none")
2073 to (mail-fetch-field "to")
2074 cc (mail-fetch-field "cc")
2075 mct (mail-fetch-field "mail-copies-to")
2076 reply-to (unless ignore-reply-to (mail-fetch-field "reply-to"))
2077 references (mail-fetch-field "references")
2078 message-id (mail-fetch-field "message-id"))
2079 ;; Remove any (buggy) Re:'s that are present and make a
2081 (when (string-match "^[ \t]*[Re][Ee]:[ \t]*" subject)
2082 (setq subject (substring subject (match-end 0))))
2083 (setq subject (concat "Re: " subject))
2085 (when (and (setq gnus-warning (mail-fetch-field "gnus-warning"))
2086 (string-match "<[^>]+>" gnus-warning))
2087 (setq message-id (match-string 0 gnus-warning)))
2089 ;; Handle special values of Mail-Copies-To.
2091 (cond ((equal (downcase mct) "never")
2094 ((equal (downcase mct) "always")
2095 (setq mct (or reply-to from)))))
2100 (setq follow-to (list (cons 'To (or to-address reply-to from))))
2103 (message-set-work-buffer)
2105 (insert (or reply-to from "")))
2107 (if (bolp) "" ", ") (or to "")
2108 (if mct (concat (if (bolp) "" ", ") mct) "")
2109 (if cc (concat (if (bolp) "" ", ") cc) ""))
2110 ;; Remove addresses that match `rmail-dont-reply-to-names'.
2111 (insert (prog1 (rmail-dont-reply-to (buffer-string))
2113 (goto-char (point-min))
2117 (cons (mail-strip-quoted-names addr) addr))
2118 (nreverse (mail-parse-comma-list))))
2121 (setq ccalist (delq (assoc (car (pop s)) s) ccalist)))))
2122 (setq follow-to (list (cons 'To (cdr (pop ccalist)))))
2125 (mapconcat (lambda (addr) (cdr addr)) ccalist ", "))
2129 (message-pop-to-buffer "*mail message*")
2131 (setq message-reply-headers
2132 (vector 0 subject from date message-id references 0 0 ""))
2135 `((Subject . ,subject)
2137 ,@(if (or references message-id)
2138 `((References . ,(concat (or references "") (and references " ")
2139 (or message-id ""))))
2144 (defun message-wide-reply (&optional to-address)
2146 (message-reply to-address t))
2149 (defun message-followup ()
2151 (let ((cur (current-buffer))
2152 from subject date message-of reply-to mct
2153 references message-id follow-to sendto elt
2154 followup-to distribution newsgroups gnus-warning)
2157 (goto-char (point-min))
2158 (if (search-forward "\n\n" nil t)
2161 (when (message-functionp message-followup-to-function)
2163 (funcall message-followup-to-function)))
2164 (setq from (mail-fetch-field "from")
2165 date (mail-fetch-field "date")
2166 subject (or (mail-fetch-field "subject") "none")
2167 references (mail-fetch-field "references")
2168 message-id (mail-fetch-field "message-id")
2169 followup-to (mail-fetch-field "followup-to")
2170 newsgroups (mail-fetch-field "newsgroups")
2171 reply-to (mail-fetch-field "reply-to")
2172 distribution (mail-fetch-field "distribution")
2173 mct (mail-fetch-field "mail-copies-to"))
2174 (when (and (setq gnus-warning (mail-fetch-field "gnus-warning"))
2175 (string-match "<[^>]+>" gnus-warning))
2176 (setq message-id (match-string 0 gnus-warning)))
2177 ;; Remove bogus distribution.
2178 (and (stringp distribution)
2179 (string-match "world" distribution)
2180 (setq distribution nil))
2181 ;; Remove any (buggy) Re:'s that are present and make a
2183 (when (string-match "^[ \t]*[Re][Ee]:[ \t]*" subject)
2184 (setq subject (substring subject (match-end 0))))
2185 (setq subject (concat "Re: " subject))
2188 (message-pop-to-buffer "*news message*")
2191 `((Subject . ,subject)
2193 (follow-to follow-to)
2194 ((and followup-to message-use-followup-to)
2197 ((equal (downcase followup-to) "poster")
2198 (if (or (eq message-use-followup-to 'use)
2199 (y-or-n-p "Use Followup-To \"poster\"? "))
2200 (cons 'To (or reply-to from ""))
2201 (cons 'Newsgroups newsgroups)))
2203 (if (or (equal followup-to newsgroups)
2204 (not (eq message-use-followup-to 'ask))
2206 (format "Use Followup-To %s? " followup-to)))
2207 (cons 'Newsgroups followup-to)
2208 (cons 'Newsgroups newsgroups))))))
2210 `((Newsgroups . ,newsgroups))))
2211 ,@(and distribution (list (cons 'Distribution distribution)))
2212 (References . ,(concat (or references "") (and references " ")
2213 (or message-id "")))
2215 (not (equal (downcase mct) "never")))
2216 (list (cons 'Cc (if (equal (downcase mct) "always")
2217 (or reply-to from "")
2222 (setq message-reply-headers
2223 (vector 0 subject from date message-id references 0 0 ""))))
2227 (defun message-cancel-news ()
2228 "Cancel an article you posted."
2230 (unless (message-news-p)
2231 (error "This is not a news article; canceling is impossible"))
2232 (when (yes-or-no-p "Do you really want to cancel this article? "))
2233 (let (from newsgroups message-id distribution buf)
2235 ;; Get header info. from original article.
2237 (message-narrow-to-head)
2238 (setq from (mail-fetch-field "from")
2239 newsgroups (mail-fetch-field "newsgroups")
2240 message-id (mail-fetch-field "message-id")
2241 distribution (mail-fetch-field "distribution")))
2242 ;; Make sure that this article was written by the user.
2243 (unless (string-equal
2244 (downcase (mail-strip-quoted-names from))
2245 (downcase (message-make-address)))
2246 (error "This article is not yours"))
2247 ;; Make control message.
2248 (setq buf (set-buffer (get-buffer-create " *message cancel*")))
2249 (buffer-disable-undo (current-buffer))
2251 (insert "Newsgroups: " newsgroups "\n"
2252 "From: " (message-make-from) "\n"
2253 "Subject: cmsg cancel " message-id "\n"
2254 "Control: cancel " message-id "\n"
2256 (concat "Distribution: " distribution "\n")
2258 mail-header-separator "\n"
2259 "This is a cancel message from " from ".\n")
2260 (message "Canceling your article...")
2261 (let ((message-syntax-checks 'dont-check-for-anything-just-trust-me))
2262 (funcall message-send-news-function))
2263 (message "Canceling your article...done")
2264 (kill-buffer buf))))
2267 (defun message-supersede ()
2268 "Start composing a message to supersede the current message.
2269 This is done simply by taking the old article and adding a Supersedes
2270 header line with the old Message-ID."
2272 (let ((cur (current-buffer)))
2273 ;; Check whether the user owns the article that is to be superseded.
2274 (unless (string-equal
2275 (downcase (mail-strip-quoted-names (mail-fetch-field "from")))
2276 (downcase (mail-strip-quoted-names (message-make-address))))
2277 (error "This article is not yours"))
2278 ;; Get a normal message buffer.
2279 (message-pop-to-buffer "*supersede message*")
2280 (insert-buffer-substring cur)
2281 (message-narrow-to-head)
2282 ;; Remove unwanted headers.
2283 (when message-ignored-supersedes-headers
2284 (message-remove-header message-ignored-supersedes-headers t))
2285 (goto-char (point-min))
2286 (if (not (re-search-forward "^Message-ID: " nil t))
2287 (error "No Message-ID in this article")
2288 (replace-match "Supersedes: " t t))
2289 (goto-char (point-max))
2290 (insert mail-header-separator)
2295 (defun message-recover ()
2296 "Reread contents of current buffer from its last auto-save file."
2298 (let ((file-name (make-auto-save-file-name)))
2299 (cond ((save-window-excursion
2300 (if (not (eq system-type 'vax-vms))
2301 (with-output-to-temp-buffer "*Directory*"
2302 (buffer-disable-undo standard-output)
2303 (let ((default-directory "/"))
2305 "ls" nil standard-output nil "-l" file-name))))
2306 (yes-or-no-p (format "Recover auto save file %s? " file-name)))
2307 (let ((buffer-read-only nil))
2309 (insert-file-contents file-name nil)))
2310 (t (error "message-recover cancelled")))))
2312 ;;; Forwarding messages.
2314 (defun message-make-forward-subject ()
2315 "Return a Subject header suitable for the message in the current buffer."
2316 (concat "[" (mail-fetch-field (if (message-news-p) "newsgroups" "from"))
2317 "] " (or (mail-fetch-field "Subject") "")))
2320 (defun message-forward (&optional news)
2321 "Forward the current message via mail.
2322 Optional NEWS will use news to forward instead of mail."
2324 (let ((cur (current-buffer))
2325 (subject (message-make-forward-subject)))
2326 (if news (message-news nil subject) (message-mail nil subject))
2327 ;; Put point where we want it before inserting the forwarded
2329 (if message-signature-before-forwarded-message
2330 (goto-char (point-max))
2331 (message-goto-body))
2332 ;; Narrow to the area we are to insert.
2333 (narrow-to-region (point) (point))
2334 ;; Insert the separators and the forwarded buffer.
2335 (insert message-forward-start-separator)
2336 (insert-buffer-substring cur)
2337 (goto-char (point-max))
2338 (insert message-forward-end-separator)
2339 (set-text-properties (point-min) (point-max) nil)
2340 ;; Remove all unwanted headers.
2341 (goto-char (point-min))
2343 (narrow-to-region (point) (if (search-forward "\n\n" nil t)
2346 (goto-char (point-min))
2347 (message-remove-header message-included-forward-headers t nil t)
2349 (message-position-point)))
2352 (defun message-resend (address)
2353 "Resend the current article to ADDRESS."
2354 (interactive "sResend message to: ")
2356 (let ((cur (current-buffer))
2358 ;; We first set up a normal mail buffer.
2359 (set-buffer (get-buffer-create " *message resend*"))
2360 (buffer-disable-undo (current-buffer))
2362 (message-setup `((To . ,address)))
2363 ;; Insert our usual headers.
2364 (message-generate-headers '(From Date To))
2365 (message-narrow-to-headers)
2366 ;; Rename them all to "Resent-*".
2367 (while (re-search-forward "^[A-Za-z]" nil t)
2372 (delete-region (point) (point-max))
2374 ;; Insert the message to be resent.
2375 (insert-buffer-substring cur)
2376 (goto-char (point-min))
2377 (search-forward "\n\n")
2380 (narrow-to-region beg (point))
2381 (message-remove-header message-ignored-resent-headers t)
2382 (goto-char (point-max)))
2383 (insert mail-header-separator)
2384 ;; Rename all old ("Also-")Resent headers.
2385 (while (re-search-backward "^\\(Also-\\)?Resent-" beg t)
2389 (funcall message-send-mail-function)
2390 (kill-buffer (current-buffer)))))
2393 (defun message-bounce ()
2394 "Re-mail the current message.
2395 This only makes sense if the current message is a bounce message than
2396 contains some mail you have written which has been bounced back to
2399 (let ((cur (current-buffer))
2401 (message-pop-to-buffer "*mail message*")
2402 (insert-buffer-substring cur)
2404 (message-narrow-to-head)
2405 (if (and (mail-fetch-field "Mime-Version")
2406 (setq boundary (mail-fetch-field "Content-Type")))
2407 (if (string-match "boundary=\"\\([^\"]+\\)\"" boundary)
2408 (setq boundary (concat (match-string 1 boundary) " *\n"
2409 "Content-Type: message/rfc822"))
2410 (setq boundary nil)))
2412 (goto-char (point-min))
2413 (search-forward "\n\n" nil t)
2415 (re-search-forward boundary nil t)
2417 (and (re-search-forward message-unsent-separator nil t)
2419 (and (search-forward "\n\n" nil t)
2420 (re-search-forward "^Return-Path:.*\n" nil t)))
2421 ;; We remove everything before the bounced mail.
2424 (if (re-search-forward "[^ \t]*:" nil t)
2428 (message-narrow-to-head)
2429 (message-remove-header message-ignored-bounced-headers t)
2430 (goto-char (point-max))
2431 (insert mail-header-separator))
2432 (message-position-point)))
2435 ;;; Interactive entry points for new message buffers.
2439 (defun message-mail-other-window (&optional to subject)
2440 "Like `message-mail' command, but display mail buffer in another window."
2442 (let ((pop-up-windows t)
2443 (special-display-buffer-names nil)
2444 (special-display-regexps nil)
2445 (same-window-buffer-names nil)
2446 (same-window-regexps nil))
2447 (message-pop-to-buffer "*mail message*"))
2448 (message-setup `((To . ,(or to "")) (Subject . ,(or subject "")))))
2451 (defun message-mail-other-frame (&optional to subject)
2452 "Like `message-mail' command, but display mail buffer in another frame."
2454 (let ((pop-up-frames t)
2455 (special-display-buffer-names nil)
2456 (special-display-regexps nil)
2457 (same-window-buffer-names nil)
2458 (same-window-regexps nil))
2459 (message-pop-to-buffer "*mail message*"))
2460 (message-setup `((To . ,(or to "")) (Subject . ,(or subject "")))))
2463 (defun message-news-other-window (&optional newsgroups subject)
2464 "Start editing a news article to be sent."
2466 (let ((pop-up-windows t)
2467 (special-display-buffer-names nil)
2468 (special-display-regexps nil)
2469 (same-window-buffer-names nil)
2470 (same-window-regexps nil))
2471 (message-pop-to-buffer "*news message*"))
2472 (message-setup `((Newsgroups . ,(or newsgroups ""))
2473 (Subject . ,(or subject "")))))
2476 (defun message-news-other-frame (&optional newsgroups subject)
2477 "Start editing a news article to be sent."
2479 (let ((pop-up-frames t)
2480 (special-display-buffer-names nil)
2481 (special-display-regexps nil)
2482 (same-window-buffer-names nil)
2483 (same-window-regexps nil))
2484 (message-pop-to-buffer "*news message*"))
2485 (message-setup `((Newsgroups . ,(or newsgroups ""))
2486 (Subject . ,(or subject "")))))
2490 ;; This code should be moved to underline.el (from which it is stolen).
2493 (defun bold-region (start end)
2494 "Bold all nonblank characters in the region.
2495 Works by overstriking characters.
2496 Called from program, takes two arguments START and END
2497 which specify the range to operate on."
2500 (let ((end1 (make-marker)))
2501 (move-marker end1 (max start end))
2502 (goto-char (min start end))
2503 (while (< (point) end1)
2504 (or (looking-at "[_\^@- ]")
2505 (insert (following-char) "\b"))
2506 (forward-char 1)))))
2509 (defun unbold-region (start end)
2510 "Remove all boldness (overstruck characters) in the region.
2511 Called from program, takes two arguments START and END
2512 which specify the range to operate on."
2515 (let ((end1 (make-marker)))
2516 (move-marker end1 (max start end))
2517 (goto-char (min start end))
2518 (while (re-search-forward "\b" end1 t)
2519 (if (eq (following-char) (char-after (- (point) 2)))
2520 (delete-char -2))))))
2524 ;;; message.el ends here