1 ;;; message.el --- composing mail and news messages
2 ;; Copyright (C) 1996,97,98 Free Software Foundation, Inc.
4 ;; Author: Lars Magne Ingebrigtsen <larsi@ifi.uio.no>
5 ;; Keywords: mail, news
7 ;; This file is part of GNU Emacs.
9 ;; GNU Emacs is free software; you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation; either version 2, or (at your option)
14 ;; GNU Emacs is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; GNU General Public License for more details.
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs; see the file COPYING. If not, write to the
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22 ;; Boston, MA 02111-1307, USA.
26 ;; This mode provides mail-sending facilities from within Emacs. It
27 ;; consists mainly of large chunks of code from the sendmail.el,
28 ;; gnus-msg.el and rnewspost.el files.
32 (eval-when-compile (require 'cl))
39 (if (string-match "XEmacs\\|Lucid" emacs-version)
40 (require 'mail-abbrevs)
41 (require 'mailabbrev))
43 (defgroup message '((user-mail-address custom-variable)
44 (user-full-name custom-variable))
45 "Mail and news message composing."
46 :link '(custom-manual "(message)Top")
50 (put 'user-mail-address 'custom-type 'string)
51 (put 'user-full-name 'custom-type 'string)
53 (defgroup message-various nil
54 "Various Message Variables"
55 :link '(custom-manual "(message)Various Message Variables")
58 (defgroup message-buffers nil
60 :link '(custom-manual "(message)Message Buffers")
63 (defgroup message-sending nil
65 :link '(custom-manual "(message)Sending Variables")
68 (defgroup message-interface nil
70 :link '(custom-manual "(message)Interface")
73 (defgroup message-forwarding nil
75 :link '(custom-manual "(message)Forwarding")
76 :group 'message-interface)
78 (defgroup message-insertion nil
80 :link '(custom-manual "(message)Insertion")
83 (defgroup message-headers nil
85 :link '(custom-manual "(message)Message Headers")
88 (defgroup message-news nil
89 "Composing News Messages"
92 (defgroup message-mail nil
93 "Composing Mail Messages"
96 (defgroup message-faces nil
97 "Faces used for message composing."
101 (defcustom message-directory "~/Mail/"
102 "*Directory from which all other mail file variables are derived."
103 :group 'message-various
106 (defcustom message-max-buffers 10
107 "*How many buffers to keep before starting to kill them off."
108 :group 'message-buffers
111 (defcustom message-send-rename-function nil
112 "Function called to rename the buffer after sending it."
113 :group 'message-buffers
116 (defcustom message-fcc-handler-function 'message-output
117 "*A function called to save outgoing articles.
118 This function will be called with the name of the file to store the
119 article in. The default function is `message-output' which saves in Unix
121 :type '(radio (function-item message-output)
122 (function :tag "Other"))
123 :group 'message-sending)
125 (defcustom message-courtesy-message
126 "The following message is a courtesy copy of an article\nthat has been posted to %s as well.\n\n"
127 "*This is inserted at the start of a mailed copy of a posted message.
128 If the string contains the format spec \"%s\", the Newsgroups
129 the article has been posted to will be inserted there.
130 If this variable is nil, no such courtesy message will be added."
131 :group 'message-sending
134 (defcustom message-ignored-bounced-headers "^\\(Received\\|Return-Path\\):"
135 "*Regexp that matches headers to be removed in resent bounced mail."
136 :group 'message-interface
140 (defcustom message-from-style 'default
141 "*Specifies how \"From\" headers look.
143 If `nil', they contain just the return address like:
145 If `parens', they look like:
146 king@grassland.com (Elvis Parsley)
147 If `angles', they look like:
148 Elvis Parsley <king@grassland.com>
150 Otherwise, most addresses look like `angles', but they look like
151 `parens' if `angles' would need quoting and `parens' would not."
152 :type '(choice (const :tag "simple" nil)
156 :group 'message-headers)
158 (defcustom message-syntax-checks nil
159 ; Guess this one shouldn't be easy to customize...
160 "*Controls what syntax checks should not be performed on outgoing posts.
161 To disable checking of long signatures, for instance, add
162 `(signature . disabled)' to this list.
164 Don't touch this variable unless you really know what you're doing.
166 Checks include subject-cmsg multiple-headers sendsys message-id from
167 long-lines control-chars size new-text redirected-followup signature
168 approved sender empty empty-headers message-id from subject
169 shorten-followup-to existing-newsgroups buffer-file-name unchanged."
170 :group 'message-news)
172 (defcustom message-required-news-headers
173 '(From Newsgroups Subject Date Message-ID
174 (optional . Organization) Lines
175 (optional . X-Newsreader))
176 "*Headers to be generated or prompted for when posting an article.
177 RFC977 and RFC1036 require From, Date, Newsgroups, Subject,
178 Message-ID. Organization, Lines, In-Reply-To, Expires, and
179 X-Newsreader are optional. If don't you want message to insert some
180 header, remove it from this list."
182 :group 'message-headers
183 :type '(repeat sexp))
185 (defcustom message-required-mail-headers
186 '(From Subject Date (optional . In-Reply-To) Message-ID Lines
187 (optional . X-Mailer))
188 "*Headers to be generated or prompted for when mailing a message.
189 RFC822 required that From, Date, To, Subject and Message-ID be
190 included. Organization, Lines and X-Mailer are optional."
192 :group 'message-headers
193 :type '(repeat sexp))
195 (defcustom message-deletable-headers '(Message-ID Date Lines)
196 "Headers to be deleted if they already exist and were generated by message previously."
197 :group 'message-headers
200 (defcustom message-ignored-news-headers
201 "^NNTP-Posting-Host:\\|^Xref:\\|^[BGF]cc:\\|^Resent-Fcc:"
202 "*Regexp of headers to be removed unconditionally before posting."
204 :group 'message-headers
207 (defcustom message-ignored-mail-headers "^[GF]cc:\\|^Resent-Fcc:\\|^Xref:"
208 "*Regexp of headers to be removed unconditionally before mailing."
210 :group 'message-headers
213 (defcustom message-ignored-supersedes-headers "^Path:\\|^Date\\|^NNTP-Posting-Host:\\|^Xref:\\|^Lines:\\|^Received:\\|^X-From-Line:\\|^X-Trace:\\|^X-Complaints-To:\\|Return-Path:\\|^Supersedes:"
214 "*Header lines matching this regexp will be deleted before posting.
215 It's best to delete old Path and Date headers before posting to avoid
217 :group 'message-interface
221 (defcustom message-signature-separator "^-- *$"
222 "Regexp matching the signature separator."
224 :group 'message-various)
226 (defcustom message-elide-elipsis "\n[...]\n\n"
227 "*The string which is inserted for elided text."
229 :group 'message-various)
231 (defcustom message-interactive nil
232 "Non-nil means when sending a message wait for and display errors.
233 nil means let mailer mail back a message to report errors."
234 :group 'message-sending
238 (defcustom message-generate-new-buffers t
239 "*Non-nil means that a new message buffer will be created whenever `mail-setup' is called.
240 If this is a function, call that function with three parameters: The type,
241 the to address and the group name. (Any of these may be nil.) The function
242 should return the new buffer name."
243 :group 'message-buffers
244 :type '(choice (const :tag "off" nil)
248 (defcustom message-kill-buffer-on-exit nil
249 "*Non-nil means that the message buffer will be killed after sending a message."
250 :group 'message-buffers
253 (defvar gnus-local-organization)
254 (defcustom message-user-organization
255 (or (and (boundp 'gnus-local-organization)
256 (stringp gnus-local-organization)
257 gnus-local-organization)
258 (getenv "ORGANIZATION")
260 "*String to be used as an Organization header.
261 If t, use `message-user-organization-file'."
262 :group 'message-headers
263 :type '(choice string
264 (const :tag "consult file" t)))
267 (defcustom message-user-organization-file "/usr/lib/news/organization"
268 "*Local news organization file."
270 :group 'message-headers)
272 (defcustom message-forward-start-separator
273 "------- Start of forwarded message -------\n"
274 "*Delimiter inserted before forwarded messages."
275 :group 'message-forwarding
278 (defcustom message-forward-end-separator
279 "------- End of forwarded message -------\n"
280 "*Delimiter inserted after forwarded messages."
281 :group 'message-forwarding
284 (defcustom message-signature-before-forwarded-message t
285 "*If non-nil, put the signature before any included forwarded message."
286 :group 'message-forwarding
289 (defcustom message-included-forward-headers
290 "^From:\\|^Newsgroups:\\|^Subject:\\|^Date:\\|^Followup-To:\\|^Reply-To:\\|^Organization:\\|^Summary:\\|^Keywords:\\|^To:\\|^Cc:\\|^Posted-To:\\|^Mail-Copies-To:\\|^Apparently-To:\\|^Gnus-Warning:\\|^Resent-\\|^Message-ID:\\|^References:\\|^Content-Transfer-Encoding:\\|^Content-Type:\\|^Mime-Version:"
291 "*Regexp matching headers to be included in forwarded messages."
292 :group 'message-forwarding
295 (defcustom message-ignored-resent-headers "^Return-receipt"
296 "*All headers that match this regexp will be deleted when resending a message."
297 :group 'message-interface
300 (defcustom message-ignored-cited-headers "."
301 "*Delete these headers from the messages you yank."
302 :group 'message-insertion
305 (defcustom message-cancel-message "I am canceling my own article."
306 "Message to be inserted in the cancel message."
307 :group 'message-interface
310 ;; Useful to set in site-init.el
312 (defcustom message-send-mail-function 'message-send-mail-with-sendmail
313 "Function to call to send the current buffer as mail.
314 The headers should be delimited by a line whose contents match the
315 variable `mail-header-separator'.
317 Legal values include `message-send-mail-with-sendmail' (the default),
318 `message-send-mail-with-mh', `message-send-mail-with-qmail' and
320 :type '(radio (function-item message-send-mail-with-sendmail)
321 (function-item message-send-mail-with-mh)
322 (function-item message-send-mail-with-qmail)
323 (function-item smtpmail-send-it)
324 (function :tag "Other"))
325 :group 'message-sending
326 :group 'message-mail)
328 (defcustom message-send-news-function 'message-send-news
329 "Function to call to send the current buffer as news.
330 The headers should be delimited by a line whose contents match the
331 variable `mail-header-separator'."
332 :group 'message-sending
336 (defcustom message-reply-to-function nil
337 "Function that should return a list of headers.
338 This function should pick out addresses from the To, Cc, and From headers
339 and respond with new To and Cc headers."
340 :group 'message-interface
343 (defcustom message-wide-reply-to-function nil
344 "Function that should return a list of headers.
345 This function should pick out addresses from the To, Cc, and From headers
346 and respond with new To and Cc headers."
347 :group 'message-interface
350 (defcustom message-followup-to-function nil
351 "Function that should return a list of headers.
352 This function should pick out addresses from the To, Cc, and From headers
353 and respond with new To and Cc headers."
354 :group 'message-interface
357 (defcustom message-use-followup-to 'ask
358 "*Specifies what to do with Followup-To header.
359 If nil, always ignore the header. If it is t, use its value, but
360 query before using the \"poster\" value. If it is the symbol `ask',
361 always query the user whether to use the value. If it is the symbol
362 `use', always use the value."
363 :group 'message-interface
364 :type '(choice (const :tag "ignore" nil)
368 ;; stuff relating to broken sendmail in MMDF
369 (defcustom message-sendmail-f-is-evil nil
370 "*Non-nil means that \"-f username\" should not be added to the sendmail
371 command line, because it is even more evil than leaving it out."
372 :group 'message-sending
375 ;; qmail-related stuff
376 (defcustom message-qmail-inject-program "/var/qmail/bin/qmail-inject"
377 "Location of the qmail-inject program."
378 :group 'message-sending
381 (defcustom message-qmail-inject-args nil
382 "Arguments passed to qmail-inject programs.
383 This should be a list of strings, one string for each argument.
385 For e.g., if you wish to set the envelope sender address so that bounces
386 go to the right place or to deal with listserv's usage of that address, you
387 might set this variable to '(\"-f\" \"you@some.where\")."
388 :group 'message-sending
389 :type '(repeat string))
391 (defvar gnus-post-method)
392 (defvar gnus-select-method)
393 (defcustom message-post-method
394 (cond ((and (boundp 'gnus-post-method)
397 ((boundp 'gnus-select-method)
400 "*Method used to post news.
401 Note that when posting from inside Gnus, for instance, this
402 variable isn't used."
404 :group 'message-sending
405 ;; This should be the `gnus-select-method' widget, but that might
406 ;; create a dependence to `gnus.el'.
409 (defcustom message-generate-headers-first nil
410 "*If non-nil, generate all possible headers before composing."
411 :group 'message-headers
414 (defcustom message-setup-hook nil
415 "Normal hook, run each time a new outgoing message is initialized.
416 The function `message-setup' runs this hook."
417 :group 'message-various
420 (defcustom message-signature-setup-hook nil
421 "Normal hook, run each time a new outgoing message is initialized.
422 It is run after the headers have been inserted and before
423 the signature is inserted."
424 :group 'message-various
427 (defcustom message-mode-hook nil
428 "Hook run in message mode buffers."
429 :group 'message-various
432 (defcustom message-header-hook nil
433 "Hook run in a message mode buffer narrowed to the headers."
434 :group 'message-various
437 (defcustom message-header-setup-hook nil
438 "Hook called narrowed to the headers when setting up a message buffer."
439 :group 'message-various
443 (defcustom message-citation-line-function 'message-insert-citation-line
444 "*Function called to insert the \"Whomever writes:\" line."
446 :group 'message-insertion)
449 (defcustom message-yank-prefix "> "
450 "*Prefix inserted on the lines of yanked messages.
451 nil means use indentation."
453 :group 'message-insertion)
455 (defcustom message-indentation-spaces 3
456 "*Number of spaces to insert at the beginning of each cited line.
457 Used by `message-yank-original' via `message-yank-cite'."
458 :group 'message-insertion
462 (defcustom message-cite-function
463 (if (and (boundp 'mail-citation-hook)
466 'message-cite-original)
467 "*Function for citing an original message.
468 Pre-defined functions include `message-cite-original' and
469 `message-cite-original-without-signature'."
470 :type '(radio (function-item message-cite-original)
471 (function-item message-cite-original-without-signature)
472 (function-item sc-cite-original)
473 (function :tag "Other"))
474 :group 'message-insertion)
477 (defcustom message-indent-citation-function 'message-indent-citation
478 "*Function for modifying a citation just inserted in the mail buffer.
479 This can also be a list of functions. Each function can find the
480 citation between (point) and (mark t). And each function should leave
481 point and mark around the citation text as modified."
483 :group 'message-insertion)
485 (defvar message-abbrevs-loaded nil)
488 (defcustom message-signature t
489 "*String to be inserted at the end of the message buffer.
490 If t, the `message-signature-file' file will be inserted instead.
491 If a function, the result from the function will be used instead.
492 If a form, the result from the form will be used instead."
494 :group 'message-insertion)
497 (defcustom message-signature-file "~/.signature"
498 "*File containing the text inserted at end of message buffer."
500 :group 'message-insertion)
502 (defcustom message-distribution-function nil
503 "*Function called to return a Distribution header."
505 :group 'message-headers
508 (defcustom message-expires 14
509 "Number of days before your article expires."
511 :group 'message-headers
512 :link '(custom-manual "(message)News Headers")
515 (defcustom message-user-path nil
516 "If nil, use the NNTP server name in the Path header.
517 If stringp, use this; if non-nil, use no host name (user name only)."
519 :group 'message-headers
520 :link '(custom-manual "(message)News Headers")
521 :type '(choice (const :tag "nntp" nil)
523 (sexp :tag "none" :format "%t" t)))
525 (defvar message-reply-buffer nil)
526 (defvar message-reply-headers nil)
527 (defvar message-newsreader nil)
528 (defvar message-mailer nil)
529 (defvar message-sent-message-via nil)
530 (defvar message-checksum nil)
531 (defvar message-send-actions nil
532 "A list of actions to be performed upon successful sending of a message.")
533 (defvar message-exit-actions nil
534 "A list of actions to be performed upon exiting after sending a message.")
535 (defvar message-kill-actions nil
536 "A list of actions to be performed before killing a message buffer.")
537 (defvar message-postpone-actions nil
538 "A list of actions to be performed after postponing a message.")
540 (define-widget 'message-header-lines 'text
541 "All header lines must be LFD terminated."
544 :error "All header lines must be newline terminated")
546 (defcustom message-default-headers ""
547 "*A string containing header lines to be inserted in outgoing messages.
548 It is inserted before you edit the message, so you can edit or delete
550 :group 'message-headers
551 :type 'message-header-lines)
553 (defcustom message-default-mail-headers ""
554 "*A string of header lines to be inserted in outgoing mails."
555 :group 'message-headers
557 :type 'message-header-lines)
559 (defcustom message-default-news-headers ""
560 "*A string of header lines to be inserted in outgoing news
562 :group 'message-headers
564 :type 'message-header-lines)
566 ;; Note: could use /usr/ucb/mail instead of sendmail;
567 ;; options -t, and -v if not interactive.
568 (defcustom message-mailer-swallows-blank-line
569 (if (and (string-match "sparc-sun-sunos\\(\\'\\|[^5]\\)"
570 system-configuration)
571 (file-readable-p "/etc/sendmail.cf")
572 (let ((buffer (get-buffer-create " *temp*")))
576 (insert-file-contents "/etc/sendmail.cf")
577 (goto-char (point-min))
578 (let ((case-fold-search nil))
579 (re-search-forward "^OR\\>" nil t)))
580 (kill-buffer buffer))))
581 ;; According to RFC822, "The field-name must be composed of printable
582 ;; ASCII characters (i. e., characters that have decimal values between
583 ;; 33 and 126, except colon)", i. e., any chars except ctl chars,
585 '(looking-at "[ \t]\\|[][!\"#$%&'()*+,-./0-9;<=>?@A-Z\\\\^_`a-z{|}~]+:"))
586 "*Set this non-nil if the system's mailer runs the header and body together.
587 \(This problem exists on Sunos 4 when sendmail is run in remote mode.)
588 The value should be an expression to test whether the problem will
590 :group 'message-sending
593 ;; Ignore errors in case this is used in Emacs 19.
594 ;; Don't use ignore-errors because this is copied into loaddefs.el.
597 (define-mail-user-agent 'message-user-agent
598 'message-mail 'message-send-and-exit
599 'message-kill-buffer 'message-send-hook)
602 (defvar message-mh-deletable-headers '(Message-ID Date Lines Sender)
603 "If non-nil, delete the deletable headers before feeding to mh.")
605 (defvar message-send-method-alist
606 '((news message-news-p message-send-via-news)
607 (mail message-mail-p message-send-via-mail))
608 "Alist of ways to send outgoing messages.
609 Each element has the form
611 \(TYPE PREDICATE FUNCTION)
613 where TYPE is a symbol that names the method; PREDICATE is a function
614 called without any parameters to determine whether the message is
615 a message of type TYPE; and FUNCTION is a function to be called if
616 PREDICATE returns non-nil. FUNCTION is called with one parameter --
619 (defvar message-mail-alias-type 'abbrev
620 "*What alias expansion type to use in Message buffers.
621 The default is `abbrev', which uses mailabbrev. nil switches
624 (defcustom message-autosave-directory
625 (nnheader-concat message-directory "drafts/")
626 "*Directory where Message autosaves buffers if Gnus isn't running.
627 If nil, Message won't autosave."
628 :group 'message-buffers
631 ;;; Internal variables.
632 ;;; Well, not really internal.
634 (defvar message-mode-syntax-table
635 (let ((table (copy-syntax-table text-mode-syntax-table)))
636 (modify-syntax-entry ?% ". " table)
638 "Syntax table used while in Message mode.")
640 (defvar message-mode-abbrev-table text-mode-abbrev-table
641 "Abbrev table used in Message mode buffers.
642 Defaults to `text-mode-abbrev-table'.")
643 (defgroup message-headers nil
645 :link '(custom-manual "(message)Variables")
648 (defface message-header-to-face
651 (:foreground "green2" :bold t))
654 (:foreground "MidnightBlue" :bold t))
656 (:bold t :italic t)))
657 "Face used for displaying From headers."
658 :group 'message-faces)
660 (defface message-header-cc-face
663 (:foreground "green4" :bold t))
666 (:foreground "MidnightBlue"))
669 "Face used for displaying Cc headers."
670 :group 'message-faces)
672 (defface message-header-subject-face
675 (:foreground "green3"))
678 (:foreground "navy blue" :bold t))
681 "Face used for displaying subject headers."
682 :group 'message-faces)
684 (defface message-header-newsgroups-face
687 (:foreground "yellow" :bold t :italic t))
690 (:foreground "blue4" :bold t :italic t))
692 (:bold t :italic t)))
693 "Face used for displaying newsgroups headers."
694 :group 'message-faces)
696 (defface message-header-other-face
699 (:foreground "#b00000"))
702 (:foreground "steel blue"))
704 (:bold t :italic t)))
705 "Face used for displaying newsgroups headers."
706 :group 'message-faces)
708 (defface message-header-name-face
711 (:foreground "DarkGreen"))
714 (:foreground "cornflower blue"))
717 "Face used for displaying header names."
718 :group 'message-faces)
720 (defface message-header-xheader-face
723 (:foreground "blue"))
726 (:foreground "blue"))
729 "Face used for displaying X-Header headers."
730 :group 'message-faces)
732 (defface message-separator-face
735 (:foreground "blue3"))
738 (:foreground "brown"))
741 "Face used for displaying the separator."
742 :group 'message-faces)
744 (defface message-cited-text-face
753 "Face used for displaying cited text names."
754 :group 'message-faces)
756 (defvar message-font-lock-keywords
757 (let* ((cite-prefix "A-Za-z")
758 (cite-suffix (concat cite-prefix "0-9_.@-"))
759 (content "[ \t]*\\(.+\\(\n[ \t].*\\)*\\)"))
760 `((,(concat "^\\([Tt]o:\\)" content)
761 (1 'message-header-name-face)
762 (2 'message-header-to-face nil t))
763 (,(concat "^\\(^[GBF]?[Cc][Cc]:\\|^[Rr]eply-[Tt]o:\\)" content)
764 (1 'message-header-name-face)
765 (2 'message-header-cc-face nil t))
766 (,(concat "^\\([Ss]ubject:\\)" content)
767 (1 'message-header-name-face)
768 (2 'message-header-subject-face nil t))
769 (,(concat "^\\([Nn]ewsgroups:\\|Followup-[Tt]o:\\)" content)
770 (1 'message-header-name-face)
771 (2 'message-header-newsgroups-face nil t))
772 (,(concat "^\\([A-Z][^: \n\t]+:\\)" content)
773 (1 'message-header-name-face)
774 (2 'message-header-other-face nil t))
775 (,(concat "^\\(X-[A-Za-z0-9-]+\\|In-Reply-To\\):" content)
776 (1 'message-header-name-face)
777 (2 'message-header-name-face))
778 ,@(if (and mail-header-separator
779 (not (equal mail-header-separator "")))
780 `((,(concat "^\\(" (regexp-quote mail-header-separator) "\\)$")
781 1 'message-separator-face))
784 "\\([" cite-prefix "]+[" cite-suffix "]*\\)?"
786 (0 'message-cited-text-face))))
787 "Additional expressions to highlight in Message mode.")
789 ;; XEmacs does it like this. For Emacs, we have to set the
790 ;; `font-lock-defaults' buffer-local variable.
791 (put 'message-mode 'font-lock-defaults '(message-font-lock-keywords t))
793 (defvar message-face-alist
794 '((bold . bold-region)
795 (underline . underline-region)
796 (default . (lambda (b e)
798 (ununderline-region b e))))
799 "Alist of mail and news faces for facemenu.
800 The cdr of ech entry is a function for applying the face to a region.")
802 (defcustom message-send-hook nil
803 "Hook run before sending messages."
804 :group 'message-various
805 :options '(ispell-message)
808 (defcustom message-send-mail-hook nil
809 "Hook run before sending mail messages."
810 :group 'message-various
813 (defcustom message-send-news-hook nil
814 "Hook run before sending news messages."
815 :group 'message-various
818 (defcustom message-sent-hook nil
819 "Hook run after sending messages."
820 :group 'message-various
823 ;;; Internal variables.
825 (defvar message-buffer-list nil)
826 (defvar message-this-is-news nil)
827 (defvar message-this-is-mail nil)
828 (defvar message-draft-article nil)
830 ;; Byte-compiler warning
831 (defvar gnus-active-hashtb)
832 (defvar gnus-read-active-file)
834 ;;; Regexp matching the delimiter of messages in UNIX mail format
835 ;;; (UNIX From lines), minus the initial ^. It should be a copy
836 ;;; of rmail.el's rmail-unix-mail-delimiter.
837 (defvar message-unix-mail-delimiter
838 (let ((time-zone-regexp
839 (concat "\\([A-Z]?[A-Z]?[A-Z][A-Z]\\( DST\\)?"
840 "\\|[-+]?[0-9][0-9][0-9][0-9]"
846 ;; Many things can happen to an RFC 822 mailbox before it is put into
847 ;; a `From' line. The leading phrase can be stripped, e.g.
848 ;; `Joe <@w.x:joe@y.z>' -> `<@w.x:joe@y.z>'. The <> can be stripped, e.g.
849 ;; `<@x.y:joe@y.z>' -> `@x.y:joe@y.z'. Everything starting with a CRLF
850 ;; can be removed, e.g.
851 ;; From: joe@y.z (Joe K
853 ;; can yield `From joe@y.z (Joe K Fri Mar 22 08:11:15 1996', and
856 ;; can yield `From Joe User Fri Mar 22 08:11:15 1996'.
857 ;; The mailbox can be removed or be replaced by white space, e.g.
858 ;; From: "Joe User"{space}{tab}
860 ;; can yield `From {space}{tab} Fri Mar 22 08:11:15 1996',
861 ;; where {space} and {tab} represent the Ascii space and tab characters.
862 ;; We want to match the results of any of these manglings.
863 ;; The following regexp rejects names whose first characters are
864 ;; obviously bogus, but after that anything goes.
865 "\\([^\0-\b\n-\r\^?].*\\)? "
867 ;; The time the message was sent.
868 "\\([^\0-\r \^?]+\\) +" ; day of the week
869 "\\([^\0-\r \^?]+\\) +" ; month
870 "\\([0-3]?[0-9]\\) +" ; day of month
871 "\\([0-2][0-9]:[0-5][0-9]\\(:[0-6][0-9]\\)?\\) *" ; time of day
873 ;; Perhaps a time zone, specified by an abbreviation, or by a
878 " \\([0-9][0-9]+\\) *"
880 ;; On some systems the time zone can appear after the year, too.
884 "\\(remote from .*\\)?"
887 "Regexp matching the delimiter of messages in UNIX mail format.")
889 (defvar message-unsent-separator
890 (concat "^ *---+ +Unsent message follows +---+ *$\\|"
891 "^ *---+ +Returned message +---+ *$\\|"
892 "^Start of returned message$\\|"
893 "^ *---+ +Original message +---+ *$\\|"
894 "^ *--+ +begin message +--+ *$\\|"
895 "^ *---+ +Original message follows +---+ *$\\|"
896 "^|? *---+ +Message text follows: +---+ *|?$")
897 "A regexp that matches the separator before the text of a failed message.")
899 (defvar message-header-format-alist
901 (To . message-fill-address)
902 (Cc . message-fill-address)
913 (References . message-fill-header)
916 "Alist used for formatting headers.")
919 (autoload 'message-setup-toolbar "messagexmas")
920 (autoload 'mh-new-draft-name "mh-comp")
921 (autoload 'mh-send-letter "mh-comp")
922 (autoload 'gnus-point-at-eol "gnus-util")
923 (autoload 'gnus-point-at-bol "gnus-util")
924 (autoload 'gnus-output-to-mail "gnus-util")
925 (autoload 'gnus-output-to-rmail "gnus-util")
926 (autoload 'mail-abbrev-in-expansion-header-p "mailabbrev")
927 (autoload 'nndraft-request-associate-buffer "nndraft")
928 (autoload 'nndraft-request-expire-articles "nndraft")
929 (autoload 'gnus-open-server "gnus-int")
930 (autoload 'gnus-request-post "gnus-int")
931 (autoload 'gnus-alive-p "gnus-util")
932 (autoload 'rmail-output "rmail"))
937 ;;; Utility functions.
940 (defmacro message-y-or-n-p (question show &rest text)
941 "Ask QUESTION, displaying the rest of the arguments in a temp. buffer if SHOW"
942 `(message-talkative-question 'y-or-n-p ,question ,show ,@text))
944 ;; Delete the current line (and the next N lines.);
945 (defmacro message-delete-line (&optional n)
946 `(delete-region (progn (beginning-of-line) (point))
947 (progn (forward-line ,(or n 1)) (point))))
949 (defun message-tokenize-header (header &optional separator)
950 "Split HEADER into a list of header elements.
951 \",\" is used as the separator."
954 (let ((regexp (format "[%s]+" (or separator ",")))
959 (message-set-work-buffer)
961 (goto-char (point-min))
966 (cond ((and (> (point) beg)
968 (and (looking-at regexp)
971 (push (buffer-substring beg (point)) elems)
972 (setq beg (match-end 0)))
973 ((= (following-char) ?\")
974 (setq quoted (not quoted)))
975 ((and (= (following-char) ?\()
978 ((and (= (following-char) ?\))
983 (defun message-mail-file-mbox-p (file)
984 "Say whether FILE looks like a Unix mbox file."
985 (when (and (file-exists-p file)
986 (file-readable-p file)
987 (file-regular-p file))
988 (nnheader-temp-write nil
989 (nnheader-insert-file-contents file)
990 (goto-char (point-min))
991 (looking-at message-unix-mail-delimiter))))
993 (defun message-fetch-field (header &optional not-all)
994 "The same as `mail-fetch-field', only remove all newlines."
995 (let* ((inhibit-point-motion-hooks t)
996 (value (mail-fetch-field header nil (not not-all))))
998 (nnheader-replace-chars-in-string value ?\n ? ))))
1000 (defun message-add-header (&rest headers)
1001 "Add the HEADERS to the message header, skipping those already present."
1004 (unless (string-match "^\\([^:]+\\):[ \t]*[^ \t]" (car headers))
1005 (error "Invalid header `%s'" (car headers)))
1006 (setq hclean (match-string 1 (car headers)))
1008 (message-narrow-to-headers)
1009 (unless (re-search-forward (concat "^" (regexp-quote hclean) ":") nil t)
1010 (insert (car headers) ?\n))))
1011 (setq headers (cdr headers))))
1013 (defun message-fetch-reply-field (header)
1014 "Fetch FIELD from the message we're replying to."
1015 (when (and message-reply-buffer
1016 (buffer-name message-reply-buffer))
1018 (set-buffer message-reply-buffer)
1019 (message-fetch-field header))))
1021 (defun message-set-work-buffer ()
1022 (if (get-buffer " *message work*")
1024 (set-buffer " *message work*")
1026 (set-buffer (get-buffer-create " *message work*"))
1027 (kill-all-local-variables)
1028 (buffer-disable-undo (current-buffer))))
1030 (defun message-functionp (form)
1031 "Return non-nil if FORM is funcallable."
1032 (or (and (symbolp form) (fboundp form))
1033 (and (listp form) (eq (car form) 'lambda))
1034 (byte-code-function-p form)))
1036 (defun message-strip-subject-re (subject)
1037 "Remove \"Re:\" from subject lines."
1038 (if (string-match "^[Rr][Ee]: *" subject)
1039 (substring subject (match-end 0))
1042 (defun message-remove-header (header &optional is-regexp first reverse)
1043 "Remove HEADER in the narrowed buffer.
1044 If REGEXP, HEADER is a regular expression.
1045 If FIRST, only remove the first instance of the header.
1046 Return the number of headers removed."
1047 (goto-char (point-min))
1048 (let ((regexp (if is-regexp header (concat "^" header ":")))
1050 (case-fold-search t)
1052 (while (and (not (eobp))
1055 (not (looking-at regexp))
1056 (looking-at regexp))
1063 ;; There might be a continuation header, so we have to search
1064 ;; until we find a new non-continuation line.
1067 (if (re-search-forward "^[^ \t]" nil t)
1068 (goto-char (match-beginning 0))
1071 (if (re-search-forward "^[^ \t]" nil t)
1072 (goto-char (match-beginning 0))
1076 (defun message-narrow-to-headers ()
1077 "Narrow the buffer to the head of the message."
1080 (goto-char (point-min))
1081 (if (re-search-forward
1082 (concat "^" (regexp-quote mail-header-separator) "\n") nil t)
1085 (goto-char (point-min)))
1087 (defun message-narrow-to-head ()
1088 "Narrow the buffer to the head of the message."
1091 (goto-char (point-min))
1092 (if (search-forward "\n\n" nil 1)
1095 (goto-char (point-min)))
1097 (defun message-news-p ()
1098 "Say whether the current buffer contains a news message."
1099 (and (not message-this-is-mail)
1100 (or message-this-is-news
1103 (message-narrow-to-headers)
1104 (and (message-fetch-field "newsgroups")
1105 (not (message-fetch-field "posted-to"))))))))
1107 (defun message-mail-p ()
1108 "Say whether the current buffer contains a mail message."
1109 (and (not message-this-is-news)
1110 (or message-this-is-mail
1113 (message-narrow-to-headers)
1114 (or (message-fetch-field "to")
1115 (message-fetch-field "cc")
1116 (message-fetch-field "bcc")))))))
1118 (defun message-next-header ()
1119 "Go to the beginning of the next header."
1121 (or (eobp) (forward-char 1))
1122 (not (if (re-search-forward "^[^ \t]" nil t)
1124 (goto-char (point-max)))))
1126 (defun message-sort-headers-1 ()
1127 "Sort the buffer as headers using `message-rank' text props."
1128 (goto-char (point-min))
1130 nil 'message-next-header
1132 (message-next-header)
1136 (or (get-text-property (point) 'message-rank)
1139 (defun message-sort-headers ()
1140 "Sort the headers of the current message according to `message-header-format-alist'."
1144 (let ((max (1+ (length message-header-format-alist)))
1146 (message-narrow-to-headers)
1147 (while (re-search-forward "^[^ \n]+:" nil t)
1149 (match-beginning 0) (1+ (match-beginning 0))
1151 (if (setq rank (length (memq (assq (intern (buffer-substring
1153 (1- (match-end 0))))
1154 message-header-format-alist)
1155 message-header-format-alist)))
1158 (message-sort-headers-1))))
1168 (defvar message-mode-map nil)
1170 (unless message-mode-map
1171 (setq message-mode-map (copy-keymap text-mode-map))
1172 (define-key message-mode-map "\C-c?" 'describe-mode)
1174 (define-key message-mode-map "\C-c\C-f\C-t" 'message-goto-to)
1175 (define-key message-mode-map "\C-c\C-f\C-b" 'message-goto-bcc)
1176 (define-key message-mode-map "\C-c\C-f\C-w" 'message-goto-fcc)
1177 (define-key message-mode-map "\C-c\C-f\C-c" 'message-goto-cc)
1178 (define-key message-mode-map "\C-c\C-f\C-s" 'message-goto-subject)
1179 (define-key message-mode-map "\C-c\C-f\C-r" 'message-goto-reply-to)
1180 (define-key message-mode-map "\C-c\C-f\C-n" 'message-goto-newsgroups)
1181 (define-key message-mode-map "\C-c\C-f\C-d" 'message-goto-distribution)
1182 (define-key message-mode-map "\C-c\C-f\C-f" 'message-goto-followup-to)
1183 (define-key message-mode-map "\C-c\C-f\C-k" 'message-goto-keywords)
1184 (define-key message-mode-map "\C-c\C-f\C-u" 'message-goto-summary)
1185 (define-key message-mode-map "\C-c\C-b" 'message-goto-body)
1186 (define-key message-mode-map "\C-c\C-i" 'message-goto-signature)
1188 (define-key message-mode-map "\C-c\C-t" 'message-insert-to)
1189 (define-key message-mode-map "\C-c\C-n" 'message-insert-newsgroups)
1191 (define-key message-mode-map "\C-c\C-y" 'message-yank-original)
1192 (define-key message-mode-map "\C-c\C-q" 'message-fill-yanked-message)
1193 (define-key message-mode-map "\C-c\C-w" 'message-insert-signature)
1194 (define-key message-mode-map "\C-c\C-r" 'message-caesar-buffer-body)
1195 (define-key message-mode-map "\C-c\C-o" 'message-sort-headers)
1196 (define-key message-mode-map "\C-c\M-r" 'message-rename-buffer)
1198 (define-key message-mode-map "\C-c\C-c" 'message-send-and-exit)
1199 (define-key message-mode-map "\C-c\C-s" 'message-send)
1200 (define-key message-mode-map "\C-c\C-k" 'message-kill-buffer)
1201 (define-key message-mode-map "\C-c\C-d" 'message-dont-send)
1203 (define-key message-mode-map "\C-c\C-e" 'message-elide-region)
1204 (define-key message-mode-map "\C-c\C-v" 'message-delete-not-region)
1205 (define-key message-mode-map "\C-c\C-z" 'message-kill-to-signature)
1206 (define-key message-mode-map "\M-\r" 'message-newline-and-reformat)
1208 (define-key message-mode-map "\t" 'message-tab))
1211 message-mode-menu message-mode-map "Message Menu."
1213 ["Sort Headers" message-sort-headers t]
1214 ["Yank Original" message-yank-original t]
1215 ["Fill Yanked Message" message-fill-yanked-message t]
1216 ["Insert Signature" message-insert-signature t]
1217 ["Caesar (rot13) Message" message-caesar-buffer-body t]
1218 ["Caesar (rot13) Region" message-caesar-region (mark t)]
1219 ["Elide Region" message-elide-region (mark t)]
1220 ["Delete Outside Region" message-delete-not-region (mark t)]
1221 ["Kill To Signature" message-kill-to-signature t]
1222 ["Newline and Reformat" message-newline-and-reformat t]
1223 ["Rename buffer" message-rename-buffer t]
1224 ["Spellcheck" ispell-message t]
1226 ["Send Message" message-send-and-exit t]
1227 ["Abort Message" message-dont-send t]))
1230 message-mode-field-menu message-mode-map ""
1232 ["Fetch To" message-insert-to t]
1233 ["Fetch Newsgroups" message-insert-newsgroups t]
1235 ["To" message-goto-to t]
1236 ["Subject" message-goto-subject t]
1237 ["Cc" message-goto-cc t]
1238 ["Reply-To" message-goto-reply-to t]
1239 ["Summary" message-goto-summary t]
1240 ["Keywords" message-goto-keywords t]
1241 ["Newsgroups" message-goto-newsgroups t]
1242 ["Followup-To" message-goto-followup-to t]
1243 ["Distribution" message-goto-distribution t]
1244 ["Body" message-goto-body t]
1245 ["Signature" message-goto-signature t]))
1247 (defvar facemenu-add-face-function)
1248 (defvar facemenu-remove-face-function)
1251 (defun message-mode ()
1252 "Major mode for editing mail and news to be sent.
1253 Like Text Mode but with these additional commands:
1254 C-c C-s message-send (send the message) C-c C-c message-send-and-exit
1255 C-c C-f move to a header field (and create it if there isn't):
1256 C-c C-f C-t move to To C-c C-f C-s move to Subject
1257 C-c C-f C-c move to Cc C-c C-f C-b move to Bcc
1258 C-c C-f C-w move to Fcc C-c C-f C-r move to Reply-To
1259 C-c C-f C-u move to Summary C-c C-f C-n move to Newsgroups
1260 C-c C-f C-k move to Keywords C-c C-f C-d move to Distribution
1261 C-c C-f C-f move to Followup-To
1262 C-c C-t message-insert-to (add a To header to a news followup)
1263 C-c C-n message-insert-newsgroups (add a Newsgroup header to a news reply)
1264 C-c C-b message-goto-body (move to beginning of message text).
1265 C-c C-i message-goto-signature (move to the beginning of the signature).
1266 C-c C-w message-insert-signature (insert `message-signature-file' file).
1267 C-c C-y message-yank-original (insert current message, if any).
1268 C-c C-q message-fill-yanked-message (fill what was yanked).
1269 C-c C-e message-elide-region (elide the text between point and mark).
1270 C-c C-z message-kill-to-signature (kill the text up to the signature).
1271 C-c C-r message-caesar-buffer-body (rot13 the message body)."
1273 (kill-all-local-variables)
1274 (make-local-variable 'message-reply-buffer)
1275 (setq message-reply-buffer nil)
1276 (make-local-variable 'message-send-actions)
1277 (make-local-variable 'message-exit-actions)
1278 (make-local-variable 'message-kill-actions)
1279 (make-local-variable 'message-postpone-actions)
1280 (make-local-variable 'message-draft-article)
1281 (make-local-hook 'kill-buffer-hook)
1282 (set-syntax-table message-mode-syntax-table)
1283 (use-local-map message-mode-map)
1284 (setq local-abbrev-table message-mode-abbrev-table)
1285 (setq major-mode 'message-mode)
1286 (setq mode-name "Message")
1287 (setq buffer-offer-save t)
1288 (make-local-variable 'facemenu-add-face-function)
1289 (make-local-variable 'facemenu-remove-face-function)
1290 (setq facemenu-add-face-function
1292 (let ((face-fun (cdr (assq face message-face-alist))))
1294 (funcall face-fun (point) end)
1295 (error "Face %s not configured for %s mode" face mode-name)))
1297 facemenu-remove-face-function t)
1298 (make-local-variable 'paragraph-separate)
1299 (make-local-variable 'paragraph-start)
1300 (setq paragraph-start
1301 (concat (regexp-quote mail-header-separator)
1302 "$\\|[ \t]*[-_][-_][-_]+$\\|"
1304 ;;!!! Uhm... shurely this can't be right?
1305 "[> " (regexp-quote message-yank-prefix) "]+$\\|"
1307 (setq paragraph-separate
1308 (concat (regexp-quote mail-header-separator)
1309 "$\\|[ \t]*[-_][-_][-_]+$\\|"
1311 "[> " (regexp-quote message-yank-prefix) "]+$\\|"
1312 paragraph-separate))
1313 (make-local-variable 'message-reply-headers)
1314 (setq message-reply-headers nil)
1315 (make-local-variable 'message-newsreader)
1316 (make-local-variable 'message-mailer)
1317 (make-local-variable 'message-post-method)
1318 (make-local-variable 'message-sent-message-via)
1319 (setq message-sent-message-via nil)
1320 (make-local-variable 'message-checksum)
1321 (setq message-checksum nil)
1322 ;;(when (fboundp 'mail-hist-define-keys)
1323 ;; (mail-hist-define-keys))
1324 (when (string-match "XEmacs\\|Lucid" emacs-version)
1325 (message-setup-toolbar))
1326 (easy-menu-add message-mode-menu message-mode-map)
1327 (easy-menu-add message-mode-field-menu message-mode-map)
1328 ;; Allow mail alias things.
1329 (when (eq message-mail-alias-type 'abbrev)
1330 (if (fboundp 'mail-abbrevs-setup)
1331 (mail-abbrevs-setup)
1332 (funcall (intern "mail-aliases-setup"))))
1333 (message-set-auto-save-file-name)
1334 (unless (string-match "XEmacs" emacs-version)
1335 (set (make-local-variable 'font-lock-defaults)
1336 '(message-font-lock-keywords t)))
1337 (make-local-variable 'adaptive-fill-regexp)
1338 (setq adaptive-fill-regexp
1339 (concat "[ \t]*[-a-z0-9A-Z]*>+[ \t]*\\|" adaptive-fill-regexp))
1340 (unless (boundp 'adaptive-fill-first-line-regexp)
1341 (setq adaptive-fill-first-line-regexp nil))
1342 (make-local-variable 'adaptive-fill-first-line-regexp)
1343 (setq adaptive-fill-first-line-regexp
1344 (concat "[ \t]*[-a-z0-9A-Z]*>+[ \t]*\\|"
1345 adaptive-fill-first-line-regexp))
1346 (run-hooks 'text-mode-hook 'message-mode-hook))
1351 ;;; Message mode commands
1354 ;;; Movement commands
1356 (defun message-goto-to ()
1357 "Move point to the To header."
1359 (message-position-on-field "To"))
1361 (defun message-goto-subject ()
1362 "Move point to the Subject header."
1364 (message-position-on-field "Subject"))
1366 (defun message-goto-cc ()
1367 "Move point to the Cc header."
1369 (message-position-on-field "Cc" "To"))
1371 (defun message-goto-bcc ()
1372 "Move point to the Bcc header."
1374 (message-position-on-field "Bcc" "Cc" "To"))
1376 (defun message-goto-fcc ()
1377 "Move point to the Fcc header."
1379 (message-position-on-field "Fcc" "To" "Newsgroups"))
1381 (defun message-goto-reply-to ()
1382 "Move point to the Reply-To header."
1384 (message-position-on-field "Reply-To" "Subject"))
1386 (defun message-goto-newsgroups ()
1387 "Move point to the Newsgroups header."
1389 (message-position-on-field "Newsgroups"))
1391 (defun message-goto-distribution ()
1392 "Move point to the Distribution header."
1394 (message-position-on-field "Distribution"))
1396 (defun message-goto-followup-to ()
1397 "Move point to the Followup-To header."
1399 (message-position-on-field "Followup-To" "Newsgroups"))
1401 (defun message-goto-keywords ()
1402 "Move point to the Keywords header."
1404 (message-position-on-field "Keywords" "Subject"))
1406 (defun message-goto-summary ()
1407 "Move point to the Summary header."
1409 (message-position-on-field "Summary" "Subject"))
1411 (defun message-goto-body ()
1412 "Move point to the beginning of the message body."
1414 (if (looking-at "[ \t]*\n") (expand-abbrev))
1415 (goto-char (point-min))
1416 (search-forward (concat "\n" mail-header-separator "\n") nil t))
1418 (defun message-goto-signature ()
1419 "Move point to the beginning of the message signature."
1421 (goto-char (point-min))
1422 (if (re-search-forward message-signature-separator nil t)
1424 (goto-char (point-max))))
1428 (defun message-insert-to (&optional force)
1429 "Insert a To header that points to the author of the article being replied to.
1430 If the original author requested not to be sent mail, the function signals
1432 With the prefix argument FORCE, insert the header anyway."
1434 (let ((co (message-fetch-reply-field "mail-copies-to")))
1435 (when (and (null force)
1437 (equal (downcase co) "never"))
1438 (error "The user has requested not to have copies sent via mail")))
1439 (when (and (message-position-on-field "To")
1440 (mail-fetch-field "to")
1441 (not (string-match "\\` *\\'" (mail-fetch-field "to"))))
1443 (insert (or (message-fetch-reply-field "reply-to")
1444 (message-fetch-reply-field "from") "")))
1446 (defun message-insert-newsgroups ()
1447 "Insert the Newsgroups header from the article being replied to."
1449 (when (and (message-position-on-field "Newsgroups")
1450 (mail-fetch-field "newsgroups")
1451 (not (string-match "\\` *\\'" (mail-fetch-field "newsgroups"))))
1453 (insert (or (message-fetch-reply-field "newsgroups") "")))
1457 ;;; Various commands
1459 (defun message-delete-not-region (beg end)
1460 "Delete everything in the body of the current message that is outside of the region."
1464 (delete-region (point) (progn (message-goto-signature)
1469 (delete-region beg (progn (message-goto-body)
1472 (message-goto-signature)
1475 (defun message-kill-to-signature ()
1476 "Deletes all text up to the signature."
1478 (let ((point (point)))
1479 (message-goto-signature)
1482 (kill-region point (point))
1486 (defun message-newline-and-reformat ()
1487 "Insert four newlines, and then reformat if inside quoted text."
1489 (let ((point (point))
1493 (setq quoted (looking-at (regexp-quote message-yank-prefix))))
1496 (insert message-yank-prefix))
1497 (fill-paragraph nil)
1501 (defun message-insert-signature (&optional force)
1502 "Insert a signature. See documentation for the `message-signature' variable."
1503 (interactive (list 0))
1506 ((and (null message-signature)
1509 (goto-char (point-max))
1510 (not (re-search-backward
1511 message-signature-separator nil t))))
1512 ((and (null message-signature)
1515 ((message-functionp message-signature)
1516 (funcall message-signature))
1517 ((listp message-signature)
1518 (eval message-signature))
1519 (t message-signature)))
1521 (cond ((stringp signature)
1523 ((and (eq t signature)
1524 message-signature-file
1525 (file-exists-p message-signature-file))
1528 (goto-char (point-max))
1529 ;; Insert the signature.
1533 (if (eq signature t)
1534 (insert-file-contents message-signature-file)
1536 (goto-char (point-max))
1537 (or (bolp) (insert "\n")))))
1539 (defun message-elide-region (b e)
1540 "Elide the text between point and mark.
1541 An ellipsis (from `message-elide-elipsis') will be inserted where the
1547 (insert message-elide-elipsis))
1549 (defvar message-caesar-translation-table nil)
1551 (defun message-caesar-region (b e &optional n)
1552 "Caesar rotation of region by N, default 13, for decrypting netnews."
1555 (min (point) (or (mark t) (point)))
1556 (max (point) (or (mark t) (point)))
1557 (when current-prefix-arg
1558 (prefix-numeric-value current-prefix-arg))))
1560 (setq n (if (numberp n) (mod n 26) 13)) ;canonize N
1561 (unless (or (zerop n) ; no action needed for a rot of 0
1562 (= b e)) ; no region to rotate
1563 ;; We build the table, if necessary.
1564 (when (or (not message-caesar-translation-table)
1565 (/= (aref message-caesar-translation-table ?a) (+ ?a n)))
1566 (setq message-caesar-translation-table
1567 (message-make-caesar-translation-table n)))
1568 ;; Then we translate the region. Do it this way to retain
1571 (subst-char-in-region
1572 b (1+ b) (char-after b)
1573 (aref message-caesar-translation-table (char-after b)))
1576 (defun message-make-caesar-translation-table (n)
1577 "Create a rot table with offset N."
1579 (table (make-string 256 0)))
1580 (while (< (incf i) 256)
1583 (substring table 0 ?A)
1584 (substring table (+ ?A n) (+ ?A n (- 26 n)))
1585 (substring table ?A (+ ?A n))
1586 (substring table (+ ?A 26) ?a)
1587 (substring table (+ ?a n) (+ ?a n (- 26 n)))
1588 (substring table ?a (+ ?a n))
1589 (substring table (+ ?a 26) 255))))
1591 (defun message-caesar-buffer-body (&optional rotnum)
1592 "Caesar rotates all letters in the current buffer by 13 places.
1593 Used to encode/decode possiblyun offensive messages (commonly in net.jokes).
1594 With prefix arg, specifies the number of places to rotate each letter forward.
1595 Mail and USENET news headers are not rotated."
1596 (interactive (if current-prefix-arg
1597 (list (prefix-numeric-value current-prefix-arg))
1601 (when (message-goto-body)
1602 (narrow-to-region (point) (point-max)))
1603 (message-caesar-region (point-min) (point-max) rotnum))))
1605 (defun message-pipe-buffer-body (program)
1606 "Pipe the message body in the current buffer through PROGRAM."
1609 (when (message-goto-body)
1610 (narrow-to-region (point) (point-max)))
1611 (let ((body (buffer-substring (point-min) (point-max))))
1612 (unless (equal 0 (call-process-region
1613 (point-min) (point-max) program t t))
1615 (message "%s failed." program))))))
1617 (defun message-rename-buffer (&optional enter-string)
1618 "Rename the *message* buffer to \"*message* RECIPIENT\".
1619 If the function is run with a prefix, it will ask for a new buffer
1620 name, rather than giving an automatic name."
1621 (interactive "Pbuffer name: ")
1624 (goto-char (point-min))
1625 (narrow-to-region (point)
1626 (search-forward mail-header-separator nil 'end))
1628 (if (message-news-p) (message-fetch-field "Newsgroups")
1629 (message-fetch-field "To"))
1632 (if (string-match "," mail-to)
1633 (concat (substring mail-to 0 (match-beginning 0)) ", ...")
1635 (name-default (concat "*message* " mail-trimmed-to))
1636 (name (if enter-string
1637 (read-string "New buffer name: " name-default)
1639 (rename-buffer name t)))))
1641 (defun message-fill-yanked-message (&optional justifyp)
1642 "Fill the paragraphs of a message yanked into this one.
1643 Numeric argument means justify as well."
1646 (goto-char (point-min))
1647 (search-forward (concat "\n" mail-header-separator "\n") nil t)
1648 (let ((fill-prefix message-yank-prefix))
1649 (fill-individual-paragraphs (point) (point-max) justifyp t))))
1651 (defun message-indent-citation ()
1652 "Modify text just inserted from a message to be cited.
1653 The inserted text should be the region.
1654 When this function returns, the region is again around the modified text.
1656 Normally, indent each nonblank line `message-indentation-spaces' spaces.
1657 However, if `message-yank-prefix' is non-nil, insert that prefix on each line."
1658 (let ((start (point)))
1659 ;; Remove unwanted headers.
1660 (when message-ignored-cited-headers
1665 (if (search-forward "\n\n" nil t)
1668 (message-remove-header message-ignored-cited-headers t)
1669 (when (= (point-min) (point-max))
1670 (setq all-removed t))
1671 (goto-char (point-max)))
1675 ;; Delete blank lines at the start of the buffer.
1676 (while (and (point-min)
1679 (message-delete-line))
1680 ;; Delete blank lines at the end of the buffer.
1681 (goto-char (point-max))
1684 (while (and (zerop (forward-line -1))
1686 (message-delete-line))
1687 ;; Do the indentation.
1688 (if (null message-yank-prefix)
1689 (indent-rigidly start (mark t) message-indentation-spaces)
1692 (while (< (point) (mark t))
1693 (insert message-yank-prefix)
1697 (defun message-yank-original (&optional arg)
1698 "Insert the message being replied to, if any.
1699 Puts point before the text and mark after.
1700 Normally indents each nonblank line ARG spaces (default 3). However,
1701 if `message-yank-prefix' is non-nil, insert that prefix on each line.
1703 This function uses `message-cite-function' to do the actual citing.
1705 Just \\[universal-argument] as argument means don't indent, insert no
1706 prefix, and don't delete any headers."
1708 (let ((modified (buffer-modified-p)))
1709 (when (and message-reply-buffer
1710 message-cite-function)
1711 (delete-windows-on message-reply-buffer t)
1712 (insert-buffer message-reply-buffer)
1713 (funcall message-cite-function)
1714 (message-exchange-point-and-mark)
1718 (setq message-checksum (cons (message-checksum) (buffer-size)))))))
1720 (defun message-cite-original-without-signature ()
1721 "Cite function in the standard Message manner."
1722 (let ((start (point))
1725 (when message-indent-citation-function
1726 (if (listp message-indent-citation-function)
1727 message-indent-citation-function
1728 (list message-indent-citation-function)))))
1730 (when (re-search-backward "^-- $" start t)
1731 (delete-region (point) end))
1734 (funcall (pop functions)))
1735 (when message-citation-line-function
1738 (funcall message-citation-line-function))))
1740 (defun message-cite-original ()
1741 "Cite function in the standard Message manner."
1742 (let ((start (point))
1744 (when message-indent-citation-function
1745 (if (listp message-indent-citation-function)
1746 message-indent-citation-function
1747 (list message-indent-citation-function)))))
1750 (funcall (pop functions)))
1751 (when message-citation-line-function
1754 (funcall message-citation-line-function))))
1756 (defun message-insert-citation-line ()
1757 "Function that inserts a simple citation line."
1758 (when message-reply-headers
1759 (insert (mail-header-from message-reply-headers) " writes:\n\n")))
1761 (defun message-position-on-field (header &rest afters)
1762 (let ((case-fold-search t))
1765 (goto-char (point-min))
1768 (concat "^" (regexp-quote mail-header-separator) "$"))
1769 (match-beginning 0)))
1770 (goto-char (point-min))
1771 (if (re-search-forward (concat "^" (regexp-quote header) ":") nil t)
1773 (re-search-forward "^[^ \t]" nil 'move)
1775 (skip-chars-backward "\n")
1778 (not (re-search-forward
1779 (concat "^" (regexp-quote (car afters)) ":")
1783 (re-search-forward "^[^ \t]" nil 'move)
1784 (beginning-of-line))
1785 (insert header ": \n")
1789 (defun message-remove-signature ()
1790 "Remove the signature from the text between point and mark.
1791 The text will also be indented the normal way."
1793 (let ((start (point))
1795 (if (not (re-search-forward message-signature-separator (mark t) t))
1796 ;; No signature here, so we just indent the cited text.
1797 (message-indent-citation)
1798 ;; Find the last non-empty line.
1800 (while (looking-at "[ \t]*$")
1803 (setq mark (set-marker (make-marker) (point)))
1805 (message-indent-citation)
1806 ;; Enable undoing the deletion.
1808 (delete-region mark (mark t))
1809 (set-marker mark nil)))))
1814 ;;; Sending messages
1817 (defun message-send-and-exit (&optional arg)
1818 "Send message like `message-send', then, if no errors, exit from mail buffer."
1820 (let ((buf (current-buffer))
1821 (actions message-exit-actions))
1822 (when (and (message-send arg)
1824 (if message-kill-buffer-on-exit
1827 (when (eq buf (current-buffer))
1828 (message-bury buf)))
1829 (message-do-actions actions))))
1831 (defun message-dont-send ()
1832 "Don't send the message you have been editing."
1834 (set-buffer-modified-p t)
1836 (let ((actions message-postpone-actions))
1837 (message-bury (current-buffer))
1838 (message-do-actions actions)))
1840 (defun message-kill-buffer ()
1841 "Kill the current buffer."
1843 (when (or (not (buffer-modified-p))
1844 (yes-or-no-p "Message modified; kill anyway? "))
1845 (let ((actions message-kill-actions))
1846 (setq buffer-file-name nil)
1847 (kill-buffer (current-buffer))
1848 (message-do-actions actions))))
1850 (defun message-bury (buffer)
1851 "Bury this mail buffer."
1852 (let ((newbuf (other-buffer buffer)))
1853 (bury-buffer buffer)
1854 (if (and (fboundp 'frame-parameters)
1855 (cdr (assq 'dedicated (frame-parameters)))
1856 (not (null (delq (selected-frame) (visible-frame-list)))))
1857 (delete-frame (selected-frame))
1858 (switch-to-buffer newbuf))))
1860 (defun message-send (&optional arg)
1861 "Send the message in the current buffer.
1862 If `message-interactive' is non-nil, wait for success indication
1863 or error messages, and inform user.
1864 Otherwise any failure is reported in a message back to
1865 the user from the mailer."
1868 (when (or (buffer-modified-p)
1869 (message-check-element 'unchanged)
1870 (y-or-n-p "No changes in the buffer; really send? "))
1871 ;; Make it possible to undo the coming changes.
1873 (let ((inhibit-read-only t))
1874 (put-text-property (point-min) (point-max) 'read-only nil))
1875 (message-fix-before-sending)
1876 (run-hooks 'message-send-hook)
1877 (message "Sending...")
1878 (let ((alist message-send-method-alist)
1882 (setq elem (pop alist)))
1883 (when (and (or (not (funcall (cadr elem)))
1884 (and (or (not (memq (car elem)
1885 message-sent-message-via))
1888 "Already sent message via %s; resend? "
1890 (setq success (funcall (caddr elem) arg)))))
1892 (when (and success sent)
1894 ;;(when (fboundp 'mail-hist-put-headers-into-history)
1895 ;; (mail-hist-put-headers-into-history))
1896 (run-hooks 'message-sent-hook)
1897 (message "Sending...done")
1898 ;; Mark the buffer as unmodified and delete autosave.
1899 (set-buffer-modified-p nil)
1900 (delete-auto-save-file-if-necessary t)
1901 (message-disassociate-draft)
1902 ;; Delete other mail buffers and stuff.
1903 (message-do-send-housekeeping)
1904 (message-do-actions message-send-actions)
1908 (defun message-send-via-mail (arg)
1909 "Send the current message via mail."
1910 (message-send-mail arg))
1912 (defun message-send-via-news (arg)
1913 "Send the current message via news."
1914 (funcall message-send-news-function arg))
1916 (defun message-fix-before-sending ()
1917 "Do various things to make the message nice before sending it."
1918 ;; Make sure there's a newline at the end of the message.
1919 (goto-char (point-max))
1923 (defun message-add-action (action &rest types)
1924 "Add ACTION to be performed when doing an exit of type TYPES."
1927 (set (setq var (intern (format "message-%s-actions" (pop types))))
1928 (nconc (symbol-value var) (list action))))))
1930 (defun message-do-actions (actions)
1931 "Perform all actions in ACTIONS."
1932 ;; Now perform actions on successful sending.
1936 ;; A simple function.
1937 ((message-functionp (car actions))
1938 (funcall (car actions)))
1939 ;; Something to be evaled.
1941 (eval (car actions)))))
1944 (defun message-send-mail (&optional arg)
1945 (require 'mail-utils)
1946 (let ((tembuf (message-generate-new-buffer-clone-locals " message temp"))
1947 (case-fold-search nil)
1948 (news (message-news-p))
1949 (mailbuf (current-buffer)))
1951 (message-narrow-to-headers)
1952 ;; Insert some headers.
1953 (let ((message-deletable-headers
1954 (if news nil message-deletable-headers)))
1955 (message-generate-headers message-required-mail-headers))
1956 ;; Let the user do all of the above.
1957 (run-hooks 'message-header-hook))
1962 ;; Avoid copying text props.
1964 "%s" (save-excursion
1965 (set-buffer mailbuf)
1967 ;; Remove some headers.
1969 (message-narrow-to-headers)
1970 ;; Remove some headers.
1971 (message-remove-header message-ignored-mail-headers t))
1972 (goto-char (point-max))
1973 ;; require one newline at the end.
1974 (or (= (preceding-char) ?\n)
1977 (or (message-fetch-field "cc")
1978 (message-fetch-field "to")))
1979 (message-insert-courtesy-copy))
1980 (funcall message-send-mail-function))
1981 (kill-buffer tembuf))
1982 (set-buffer mailbuf)
1983 (push 'mail message-sent-message-via)))
1985 (defun message-send-mail-with-sendmail ()
1986 "Send off the prepared buffer with sendmail."
1987 (let ((errbuf (if message-interactive
1988 (generate-new-buffer " sendmail errors")
1990 resend-to-addresses delimline)
1991 (let ((case-fold-search t))
1993 (message-narrow-to-headers)
1994 (setq resend-to-addresses (message-fetch-field "resent-to")))
1995 ;; Change header-delimiter to be what sendmail expects.
1996 (goto-char (point-min))
1998 (concat "^" (regexp-quote mail-header-separator) "\n"))
1999 (replace-match "\n")
2001 (setq delimline (point-marker))
2002 (run-hooks 'message-send-mail-hook)
2003 ;; Insert an extra newline if we need it to work around
2004 ;; Sun's bug that swallows newlines.
2005 (goto-char (1+ delimline))
2006 (when (eval message-mailer-swallows-blank-line)
2008 (when message-interactive
2012 (let ((default-directory "/")
2013 (coding-system-for-write 'binary))
2014 (apply 'call-process-region
2015 (append (list (point-min) (point-max)
2016 (if (boundp 'sendmail-program)
2018 "/usr/lib/sendmail")
2019 nil errbuf nil "-oi")
2020 ;; Always specify who from,
2021 ;; since some systems have broken sendmails.
2022 ;; But some systems are more broken with -f, so
2023 ;; we'll let users override this.
2024 (if (null message-sendmail-f-is-evil)
2025 (list "-f" (user-login-name)))
2026 ;; These mean "report errors by mail"
2027 ;; and "deliver in background".
2028 (if (null message-interactive) '("-oem" "-odb"))
2029 ;; Get the addresses from the message
2030 ;; unless this is a resend.
2031 ;; We must not do that for a resend
2032 ;; because we would find the original addresses.
2033 ;; For a resend, include the specific addresses.
2034 (if resend-to-addresses
2035 (list resend-to-addresses)
2037 (when message-interactive
2040 (goto-char (point-min))
2041 (while (re-search-forward "\n\n* *" nil t)
2042 (replace-match "; "))
2043 (if (not (zerop (buffer-size)))
2044 (error "Sending...failed to %s"
2045 (buffer-substring (point-min) (point-max)))))
2046 (when (bufferp errbuf)
2047 (kill-buffer errbuf)))))
2049 (defun message-send-mail-with-qmail ()
2050 "Pass the prepared message buffer to qmail-inject.
2051 Refer to the documentation for the variable `message-send-mail-function'
2052 to find out how to use this."
2053 ;; replace the header delimiter with a blank line
2054 (goto-char (point-min))
2056 (concat "^" (regexp-quote mail-header-separator) "\n"))
2057 (replace-match "\n")
2058 (run-hooks 'message-send-mail-hook)
2061 (let ((coding-system-for-write 'binary))
2063 'call-process-region 1 (point-max) message-qmail-inject-program
2065 ;; qmail-inject's default behaviour is to look for addresses on the
2066 ;; command line; if there're none, it scans the headers.
2067 ;; yes, it does The Right Thing w.r.t. Resent-To and it's kin.
2069 ;; in general, ALL of qmail-inject's defaults are perfect for simply
2070 ;; reading a formatted (i. e., at least a To: or Resent-To header)
2071 ;; message from stdin.
2073 ;; qmail also has the advantage of not having been raped by
2074 ;; various vendors, so we don't have to allow for that, either --
2075 ;; compare this with message-send-mail-with-sendmail and weep
2076 ;; for sendmail's lost innocence.
2078 ;; all this is way cool coz it lets us keep the arguments entirely
2079 ;; free for -inject-arguments -- a big win for the user and for us
2080 ;; since we don't have to play that double-guessing game and the user
2081 ;; gets full control (no gestapo'ish -f's, for instance). --sj
2082 message-qmail-inject-args))
2083 ;; qmail-inject doesn't say anything on it's stdout/stderr,
2084 ;; we have to look at the retval instead
2086 (1 (error "qmail-inject reported permanent failure"))
2087 (111 (error "qmail-inject reported transient failure"))
2088 ;; should never happen
2089 (t (error "qmail-inject reported unknown failure"))))
2091 (defun message-send-mail-with-mh ()
2092 "Send the prepared message buffer with mh."
2093 (let ((mh-previous-window-config nil)
2094 (name (mh-new-draft-name)))
2095 (setq buffer-file-name name)
2096 ;; MH wants to generate these headers itself.
2097 (when message-mh-deletable-headers
2098 (let ((headers message-mh-deletable-headers))
2100 (goto-char (point-min))
2101 (and (re-search-forward
2102 (concat "^" (symbol-name (car headers)) ": *") nil t)
2103 (message-delete-line))
2105 (run-hooks 'message-send-mail-hook)
2106 ;; Pass it on to mh.
2109 (defun message-send-news (&optional arg)
2110 (let ((tembuf (message-generate-new-buffer-clone-locals " *message temp*"))
2111 (case-fold-search nil)
2112 (method (if (message-functionp message-post-method)
2113 (funcall message-post-method arg)
2114 message-post-method))
2115 (messbuf (current-buffer))
2116 (message-syntax-checks
2118 (cons '(existing-newsgroups . disabled)
2119 message-syntax-checks)
2120 message-syntax-checks))
2123 (message-narrow-to-headers)
2124 ;; Insert some headers.
2125 (message-generate-headers message-required-news-headers)
2126 ;; Let the user do all of the above.
2127 (run-hooks 'message-header-hook))
2128 (message-cleanup-headers)
2129 (if (not (message-check-news-syntax))
2131 ;;(message "Posting not performed")
2136 (buffer-disable-undo (current-buffer))
2138 ;; Avoid copying text props.
2140 "%s" (save-excursion
2141 (set-buffer messbuf)
2143 ;; Remove some headers.
2145 (message-narrow-to-headers)
2146 ;; Remove some headers.
2147 (message-remove-header message-ignored-news-headers t))
2148 (goto-char (point-max))
2149 ;; require one newline at the end.
2150 (or (= (preceding-char) ?\n)
2152 (let ((case-fold-search t))
2153 ;; Remove the delimiter.
2154 (goto-char (point-min))
2156 (concat "^" (regexp-quote mail-header-separator) "\n"))
2157 (replace-match "\n")
2159 (run-hooks 'message-send-news-hook)
2160 ;;(require (car method))
2161 ;;(funcall (intern (format "%s-open-server" (car method)))
2162 ;;(cadr method) (cddr method))
2164 ;; (funcall (intern (format "%s-request-post" (car method)))
2166 (gnus-open-server method)
2167 (setq result (gnus-request-post method)))
2168 (kill-buffer tembuf))
2169 (set-buffer messbuf)
2171 (push 'news message-sent-message-via)
2172 (message "Couldn't send message via news: %s"
2173 (nnheader-get-report (car method)))
2177 ;;; Header generation & syntax checking.
2180 (defmacro message-check (type &rest forms)
2181 "Eval FORMS if TYPE is to be checked."
2182 `(or (message-check-element ,type)
2186 (put 'message-check 'lisp-indent-function 1)
2187 (put 'message-check 'edebug-form-spec '(form body))
2189 (defun message-check-element (type)
2190 "Returns non-nil if this type is not to be checked."
2191 (if (eq message-syntax-checks 'dont-check-for-anything-just-trust-me)
2193 (let ((able (assq type message-syntax-checks)))
2195 (eq (cdr able) 'disabled)))))
2197 (defun message-check-news-syntax ()
2198 "Check the syntax of the message."
2203 ;; We narrow to the headers and check them first.
2206 (message-narrow-to-headers)
2207 (message-check-news-header-syntax)))
2209 (message-check-news-body-syntax)))))
2211 (defun message-check-news-header-syntax ()
2213 ;; Check the Subject header.
2214 (message-check 'subject
2215 (let* ((case-fold-search t)
2216 (subject (message-fetch-field "subject")))
2219 (not (string-match "\\`[ \t]*\\'" subject)))
2222 "The subject field is empty or missing. Posting is denied.")))))
2223 ;; Check for commands in Subject.
2224 (message-check 'subject-cmsg
2225 (if (string-match "^cmsg " (message-fetch-field "subject"))
2227 "The control code \"cmsg\" is in the subject. Really post? ")
2229 ;; Check for multiple identical headers.
2230 (message-check 'multiple-headers
2232 (while (and (not found)
2233 (re-search-forward "^[^ \t:]+: " nil t))
2235 (or (re-search-forward
2240 (match-beginning 0) (- (match-end 0) 2))))
2245 (y-or-n-p (format "Multiple %s headers. Really post? " found))
2247 ;; Check for Version and Sendsys.
2248 (message-check 'sendsys
2249 (if (re-search-forward "^Sendsys:\\|^Version:" nil t)
2251 (format "The article contains a %s command. Really post? "
2252 (buffer-substring (match-beginning 0)
2253 (1- (match-end 0)))))
2255 ;; See whether we can shorten Followup-To.
2256 (message-check 'shorten-followup-to
2257 (let ((newsgroups (message-fetch-field "newsgroups"))
2258 (followup-to (message-fetch-field "followup-to"))
2260 (when (and newsgroups
2261 (string-match "," newsgroups)
2266 (setq to (completing-read
2267 "Followups to: (default all groups) "
2268 (mapcar (lambda (g) (list g))
2270 (message-tokenize-header
2272 (goto-char (point-min))
2273 (insert "Followup-To: " to "\n"))
2275 ;; Check "Shoot me".
2276 (message-check 'shoot
2277 (if (re-search-forward
2278 "Message-ID.*.i-did-not-set--mail-host-address--so-shoot-me" nil t)
2279 (y-or-n-p "You appear to have a misconfigured system. Really post? ")
2281 ;; Check for Approved.
2282 (message-check 'approved
2283 (if (re-search-forward "^Approved:" nil t)
2284 (y-or-n-p "The article contains an Approved header. Really post? ")
2286 ;; Check the Message-ID header.
2287 (message-check 'message-id
2288 (let* ((case-fold-search t)
2289 (message-id (message-fetch-field "message-id" t)))
2290 (or (not message-id)
2291 ;; Is there an @ in the ID?
2292 (and (string-match "@" message-id)
2293 ;; Is there a dot in the ID?
2294 (string-match "@[^.]*\\." message-id)
2295 ;; Does the ID end with a dot?
2296 (not (string-match "\\.>" message-id)))
2298 (format "The Message-ID looks strange: \"%s\". Really post? "
2300 ;; Check the Newsgroups & Followup-To headers.
2301 (message-check 'existing-newsgroups
2302 (let* ((case-fold-search t)
2303 (newsgroups (message-fetch-field "newsgroups"))
2304 (followup-to (message-fetch-field "followup-to"))
2305 (groups (message-tokenize-header
2307 (concat newsgroups "," followup-to)
2309 (hashtb (and (boundp 'gnus-active-hashtb)
2310 gnus-active-hashtb))
2312 (if (or (not hashtb)
2313 (not (boundp 'gnus-read-active-file))
2314 (not gnus-read-active-file)
2315 (eq gnus-read-active-file 'some))
2318 (when (and (not (boundp (intern (car groups) hashtb)))
2319 (not (equal (car groups) "poster")))
2320 (push (car groups) errors))
2326 "Really post to %s unknown group%s: %s "
2327 (if (= (length errors) 1) "this" "these")
2328 (if (= (length errors) 1) "" "s")
2329 (mapconcat 'identity errors ", ")))))))
2330 ;; Check the Newsgroups & Followup-To headers for syntax errors.
2331 (message-check 'valid-newsgroups
2332 (let ((case-fold-search t)
2333 (headers '("Newsgroups" "Followup-To"))
2335 (while (and headers (not error))
2336 (when (setq header (mail-fetch-field (car headers)))
2340 "\\`\\([-+_&.a-zA-Z0-9]+\\)?\\(,[-+_&.a-zA-Z0-9]+\\)*\\'"
2345 (not (string-match "\\.\\'\\|\\.\\." g)))
2346 (message-tokenize-header header ","))))
2353 (format "The %s header looks odd: \"%s\". Really post? "
2354 (car headers) header)))))
2355 (message-check 'repeated-newsgroups
2356 (let ((case-fold-search t)
2357 (headers '("Newsgroups" "Followup-To"))
2358 header error groups group)
2361 (when (setq header (mail-fetch-field (pop headers)))
2362 (setq groups (message-tokenize-header header ","))
2363 (while (setq group (pop groups))
2364 (when (member group groups)
2370 (format "Group %s is repeated in headers. Really post? " error)))))
2371 ;; Check the From header.
2372 (message-check 'from
2373 (let* ((case-fold-search t)
2374 (from (message-fetch-field "from"))
2375 (ad (nth 1 (mail-extract-address-components from))))
2378 (message "There is no From line. Posting is denied.")
2380 ((or (not (string-match "@[^\\.]*\\." ad)) ;larsi@ifi
2381 (string-match "\\.\\." ad) ;larsi@ifi..uio
2382 (string-match "@\\." ad) ;larsi@.ifi.uio
2383 (string-match "\\.$" ad) ;larsi@ifi.uio.
2384 (not (string-match "^[^@]+@[^@]+$" ad)) ;larsi.ifi.uio
2385 (string-match "(.*).*(.*)" from)) ;(lars) (lars)
2387 "Denied posting -- the From looks strange: \"%s\"." from)
2391 (defun message-check-news-body-syntax ()
2393 ;; Check for long lines.
2394 (message-check 'long-lines
2395 (goto-char (point-min))
2397 (concat "^" (regexp-quote mail-header-separator) "$"))
2401 (< (current-column) 80))
2402 (zerop (forward-line 1))))
2406 "You have lines longer than 79 characters. Really post? ")))
2407 ;; Check whether the article is empty.
2408 (message-check 'empty
2409 (goto-char (point-min))
2411 (concat "^" (regexp-quote mail-header-separator) "$"))
2414 (goto-char (point-max))
2415 (re-search-backward message-signature-separator nil t)
2417 (or (re-search-backward "[^ \n\t]" b t)
2418 (y-or-n-p "Empty article. Really post? "))))
2419 ;; Check for control characters.
2420 (message-check 'control-chars
2421 (if (re-search-forward "[\000-\007\013\015-\037\200-\237]" nil t)
2423 "The article contains control characters. Really post? ")
2425 ;; Check excessive size.
2426 (message-check 'size
2427 (if (> (buffer-size) 60000)
2429 (format "The article is %d octets long. Really post? "
2432 ;; Check whether any new text has been added.
2433 (message-check 'new-text
2435 (not message-checksum)
2436 (not (and (eq (message-checksum) (car message-checksum))
2437 (eq (buffer-size) (cdr message-checksum))))
2439 "It looks like no new text has been added. Really post? ")))
2440 ;; Check the length of the signature.
2441 (message-check 'signature
2442 (goto-char (point-max))
2443 (if (or (not (re-search-backward message-signature-separator nil t))
2444 (search-forward message-forward-end-separator nil t))
2446 (if (> (count-lines (point) (point-max)) 5)
2449 "Your .sig is %d lines; it should be max 4. Really post? "
2450 (1- (count-lines (point) (point-max)))))
2453 (defun message-checksum ()
2454 "Return a \"checksum\" for the current buffer."
2457 (goto-char (point-min))
2459 (concat "^" (regexp-quote mail-header-separator) "$"))
2461 (when (not (looking-at "[ \t\n]"))
2462 (setq sum (logxor (ash sum 1) (if (natnump sum) 0 1)
2467 (defun message-do-fcc ()
2468 "Process Fcc headers in the current buffer."
2469 (let ((case-fold-search t)
2470 (buf (current-buffer))
2473 (set-buffer (get-buffer-create " *message temp*"))
2474 (buffer-disable-undo (current-buffer))
2476 (insert-buffer-substring buf)
2478 (message-narrow-to-headers)
2479 (while (setq file (message-fetch-field "fcc"))
2481 (message-remove-header "fcc" nil t)))
2482 (goto-char (point-min))
2483 (re-search-forward (concat "^" (regexp-quote mail-header-separator) "$"))
2484 (replace-match "" t t)
2485 ;; Process FCC operations.
2487 (setq file (pop list))
2488 (if (string-match "^[ \t]*|[ \t]*\\(.*\\)[ \t]*$" file)
2489 ;; Pipe the article to the program in question.
2490 (call-process-region (point-min) (point-max) shell-file-name
2491 nil nil nil shell-command-switch
2492 (match-string 1 file))
2493 ;; Save the article.
2494 (setq file (expand-file-name file))
2495 (unless (file-exists-p (file-name-directory file))
2496 (make-directory (file-name-directory file) t))
2497 (if (and message-fcc-handler-function
2498 (not (eq message-fcc-handler-function 'rmail-output)))
2499 (funcall message-fcc-handler-function file)
2500 (if (and (file-readable-p file) (mail-file-babyl-p file))
2501 (rmail-output file 1 nil t)
2502 (let ((mail-use-rfc822 t))
2503 (rmail-output file 1 t t))))))
2505 (kill-buffer (current-buffer)))))
2507 (defun message-output (filename)
2508 "Append this article to Unix/babyl mail file.."
2509 (if (and (file-readable-p filename)
2510 (mail-file-babyl-p filename))
2511 (gnus-output-to-rmail filename t)
2512 (gnus-output-to-mail filename t)))
2514 (defun message-cleanup-headers ()
2515 "Do various automatic cleanups of the headers."
2516 ;; Remove empty lines in the header.
2518 (message-narrow-to-headers)
2519 ;; Remove blank lines.
2520 (while (re-search-forward "^[ \t]*\n" nil t)
2521 (replace-match "" t t))
2523 ;; Correct Newsgroups and Followup-To headers: Change sequence of
2524 ;; spaces to comma and eliminate spaces around commas. Eliminate
2525 ;; embedded line breaks.
2526 (goto-char (point-min))
2527 (while (re-search-forward "^\\(Newsgroups\\|Followup-To\\): +" nil t)
2531 (if (re-search-forward "^[^ \t]" nil t)
2535 (goto-char (point-min))
2536 (while (re-search-forward "\n[ \t]+" nil t)
2537 (replace-match " " t t)) ;No line breaks (too confusing)
2538 (goto-char (point-min))
2539 (while (re-search-forward "[ \t\n]*,[ \t\n]*\\|[ \t]+" nil t)
2540 (replace-match "," t t))
2541 (goto-char (point-min))
2542 ;; Remove trailing commas.
2543 (when (re-search-forward ",+$" nil t)
2544 (replace-match "" t t))))))
2546 (defun message-make-date ()
2547 "Make a valid data header."
2548 (let ((now (current-time)))
2549 (timezone-make-date-arpa-standard
2550 (current-time-string now) (current-time-zone now))))
2552 (defun message-make-message-id ()
2553 "Make a unique Message-ID."
2554 (concat "<" (message-unique-id)
2555 (let ((psubject (save-excursion (message-fetch-field "subject")))
2557 (save-excursion (message-fetch-field "supersedes"))))
2559 (and message-reply-headers
2560 (mail-header-references message-reply-headers)
2561 (mail-header-subject message-reply-headers)
2563 (mail-header-subject message-reply-headers)
2565 (message-strip-subject-re
2566 (mail-header-subject message-reply-headers))
2567 (message-strip-subject-re psubject))))
2569 (string-match "_-_@" psupersedes)))
2571 "@" (message-make-fqdn) ">"))
2573 (defvar message-unique-id-char nil)
2575 ;; If you ever change this function, make sure the new version
2576 ;; cannot generate IDs that the old version could.
2577 ;; You might for example insert a "." somewhere (not next to another dot
2578 ;; or string boundary), or modify the "fsf" string.
2579 (defun message-unique-id ()
2580 ;; Don't use microseconds from (current-time), they may be unsupported.
2581 ;; Instead we use this randomly inited counter.
2582 (setq message-unique-id-char
2583 (% (1+ (or message-unique-id-char (logand (random t) (1- (lsh 1 20)))))
2584 ;; (current-time) returns 16-bit ints,
2585 ;; and 2^16*25 just fits into 4 digits i base 36.
2587 (let ((tm (current-time)))
2589 (if (memq system-type '(ms-dos emx vax-vms))
2590 (let ((user (downcase (user-login-name))))
2591 (while (string-match "[^a-z0-9_]" user)
2592 (aset user (match-beginning 0) ?_))
2594 (message-number-base36 (user-uid) -1))
2595 (message-number-base36 (+ (car tm)
2596 (lsh (% message-unique-id-char 25) 16)) 4)
2597 (message-number-base36 (+ (nth 1 tm)
2598 (lsh (/ message-unique-id-char 25) 16)) 4)
2599 ;; Append the newsreader name, because while the generated
2600 ;; ID is unique to this newsreader, other newsreaders might
2601 ;; otherwise generate the same ID via another algorithm.
2604 (defun message-number-base36 (num len)
2609 (concat (message-number-base36 (/ num 36) (1- len))
2610 (char-to-string (aref "zyxwvutsrqponmlkjihgfedcba9876543210"
2613 (defun message-make-organization ()
2614 "Make an Organization header."
2615 (let* ((organization
2616 (when message-user-organization
2617 (if (message-functionp message-user-organization)
2618 (funcall message-user-organization)
2619 message-user-organization))))
2621 (message-set-work-buffer)
2622 (cond ((stringp organization)
2623 (insert organization))
2624 ((and (eq t organization)
2625 message-user-organization-file
2626 (file-exists-p message-user-organization-file))
2627 (insert-file-contents message-user-organization-file)))
2628 (goto-char (point-min))
2629 (while (re-search-forward "[\t\n]+" nil t)
2630 (replace-match "" t t))
2631 (unless (zerop (buffer-size))
2634 (defun message-make-lines ()
2635 "Count the number of lines and return numeric string."
2639 (goto-char (point-min))
2641 (concat "^" (regexp-quote mail-header-separator) "$"))
2643 (int-to-string (count-lines (point) (point-max))))))
2645 (defun message-make-in-reply-to ()
2646 "Return the In-Reply-To header for this message."
2647 (when message-reply-headers
2648 (let ((from (mail-header-from message-reply-headers))
2649 (date (mail-header-date message-reply-headers)))
2652 (string-match " *at \\| *@ \\| *(\\| *<" from)))
2653 (concat (if (and stop-pos
2654 (not (zerop stop-pos)))
2655 (substring from 0 stop-pos) from)
2657 (if (or (not date) (string= date ""))
2658 "(unknown date)" date)
2661 (defun message-make-distribution ()
2662 "Make a Distribution header."
2663 (let ((orig-distribution (message-fetch-reply-field "distribution")))
2664 (cond ((message-functionp message-distribution-function)
2665 (funcall message-distribution-function))
2666 (t orig-distribution))))
2668 (defun message-make-expires ()
2669 "Return an Expires header based on `message-expires'."
2670 (let ((current (current-time))
2671 (future (* 1.0 message-expires 60 60 24)))
2672 ;; Add the future to current.
2673 (setcar current (+ (car current) (round (/ future (expt 2 16)))))
2674 (setcar (cdr current) (+ (nth 1 current) (% (round future) (expt 2 16))))
2675 ;; Return the date in the future in UT.
2676 (timezone-make-date-arpa-standard
2677 (current-time-string current) (current-time-zone current) '(0 "UT"))))
2679 (defun message-make-path ()
2681 (let ((login-name (user-login-name)))
2682 (cond ((null message-user-path)
2683 (concat (system-name) "!" login-name))
2684 ((stringp message-user-path)
2685 ;; Support GENERICPATH. Suggested by vixie@decwrl.dec.com.
2686 (concat message-user-path "!" login-name))
2689 (defun message-make-from ()
2690 "Make a From header."
2691 (let* ((style message-from-style)
2692 (login (message-make-address))
2694 (or (and (boundp 'user-full-name)
2697 (when (string= fullname "&")
2698 (setq fullname (user-login-name)))
2700 (message-set-work-buffer)
2703 (equal fullname ""))
2705 ((or (eq style 'angles)
2706 (and (not (eq style 'parens))
2707 ;; Use angles if no quoting is needed, or if parens would
2708 ;; need quoting too.
2709 (or (not (string-match "[^- !#-'*+/-9=?A-Z^-~]" fullname))
2710 (let ((tmp (concat fullname nil)))
2711 (while (string-match "([^()]*)" tmp)
2712 (aset tmp (match-beginning 0) ?-)
2713 (aset tmp (1- (match-end 0)) ?-))
2714 (string-match "[\\()]" tmp)))))
2716 (goto-char (point-min))
2717 ;; Look for a character that cannot appear unquoted
2718 ;; according to RFC 822.
2719 (when (re-search-forward "[^- !#-'*+/-9=?A-Z^-~]" nil 1)
2720 ;; Quote fullname, escaping specials.
2721 (goto-char (point-min))
2723 (while (re-search-forward "[\"\\]" nil 1)
2724 (replace-match "\\\\\\&" t))
2726 (insert " <" login ">"))
2727 (t ; 'parens or default
2729 (let ((fullname-start (point)))
2731 (goto-char fullname-start)
2732 ;; RFC 822 says \ and nonmatching parentheses
2733 ;; must be escaped in comments.
2734 ;; Escape every instance of ()\ ...
2735 (while (re-search-forward "[()\\]" nil 1)
2736 (replace-match "\\\\\\&" t))
2737 ;; ... then undo escaping of matching parentheses,
2738 ;; including matching nested parentheses.
2739 (goto-char fullname-start)
2740 (while (re-search-forward
2741 "\\(\\=\\|[^\\]\\(\\\\\\\\\\)*\\)\\\\(\\(\\([^\\]\\|\\\\\\\\\\)*\\)\\\\)"
2743 (replace-match "\\1(\\3)" t)
2744 (goto-char fullname-start)))
2748 (defun message-make-sender ()
2749 "Return the \"real\" user address.
2750 This function tries to ignore all user modifications, and
2751 give as trustworthy answer as possible."
2752 (concat (user-login-name) "@" (system-name)))
2754 (defun message-make-address ()
2755 "Make the address of the user."
2756 (or (message-user-mail-address)
2757 (concat (user-login-name) "@" (message-make-domain))))
2759 (defun message-user-mail-address ()
2760 "Return the pertinent part of `user-mail-address'."
2761 (when user-mail-address
2762 (if (string-match " " user-mail-address)
2763 (nth 1 (mail-extract-address-components user-mail-address))
2764 user-mail-address)))
2766 (defun message-make-fqdn ()
2767 "Return user's fully qualified domain name."
2768 (let ((system-name (system-name))
2769 (user-mail (message-user-mail-address)))
2771 ((string-match "[^.]\\.[^.]" system-name)
2772 ;; `system-name' returned the right result.
2774 ;; Try `mail-host-address'.
2775 ((and (boundp 'mail-host-address)
2776 (stringp mail-host-address)
2777 (string-match "\\." mail-host-address))
2779 ;; We try `user-mail-address' as a backup.
2781 (string-match "\\." user-mail)
2782 (string-match "@\\(.*\\)\\'" user-mail))
2783 (match-string 1 user-mail))
2784 ;; Default to this bogus thing.
2786 (concat system-name ".i-did-not-set--mail-host-address--so-shoot-me")))))
2788 (defun message-make-host-name ()
2789 "Return the name of the host."
2790 (let ((fqdn (message-make-fqdn)))
2791 (string-match "^[^.]+\\." fqdn)
2792 (substring fqdn 0 (1- (match-end 0)))))
2794 (defun message-make-domain ()
2795 "Return the domain name."
2796 (or mail-host-address
2797 (message-make-fqdn)))
2799 (defun message-generate-headers (headers)
2800 "Prepare article HEADERS.
2801 Headers already prepared in the buffer are not modified."
2803 (message-narrow-to-headers)
2804 (let* ((Date (message-make-date))
2805 (Message-ID (message-make-message-id))
2806 (Organization (message-make-organization))
2807 (From (message-make-from))
2808 (Path (message-make-path))
2811 (In-Reply-To (message-make-in-reply-to))
2813 (Distribution (message-make-distribution))
2814 (Lines (message-make-lines))
2815 (X-Newsreader message-newsreader)
2816 (X-Mailer (and (not (message-fetch-field "X-Newsreader"))
2818 (Expires (message-make-expires))
2819 (case-fold-search t)
2821 ;; First we remove any old generated headers.
2822 (let ((headers message-deletable-headers))
2823 (unless (buffer-modified-p)
2824 (setq headers (delq 'Message-ID (copy-sequence headers))))
2826 (goto-char (point-min))
2827 (and (re-search-forward
2828 (concat "^" (symbol-name (car headers)) ": *") nil t)
2829 (get-text-property (1+ (match-beginning 0)) 'message-deletable)
2830 (message-delete-line))
2832 ;; Go through all the required headers and see if they are in the
2833 ;; articles already. If they are not, or are empty, they are
2834 ;; inserted automatically - except for Subject, Newsgroups and
2837 (goto-char (point-min))
2838 (setq elem (pop headers))
2840 (if (eq (car elem) 'optional)
2841 (setq header (cdr elem))
2842 (setq header (car elem)))
2844 (when (or (not (re-search-forward
2845 (concat "^" (downcase (symbol-name header)) ":")
2848 ;; The header was found. We insert a space after the
2849 ;; colon, if there is none.
2850 (if (/= (following-char) ? ) (insert " ") (forward-char 1))
2851 ;; Find out whether the header is empty...
2852 (looking-at "[ \t]*$")))
2853 ;; So we find out what value we should insert.
2856 ((and (consp elem) (eq (car elem) 'optional))
2857 ;; This is an optional header. If the cdr of this
2858 ;; is something that is nil, then we do not insert
2860 (setq header (cdr elem))
2861 (or (and (fboundp (cdr elem)) (funcall (cdr elem)))
2862 (and (boundp (cdr elem)) (symbol-value (cdr elem)))))
2864 ;; The element is a cons. Either the cdr is a
2865 ;; string to be inserted verbatim, or it is a
2866 ;; function, and we insert the value returned from
2868 (or (and (stringp (cdr elem)) (cdr elem))
2869 (and (fboundp (cdr elem)) (funcall (cdr elem)))))
2870 ((and (boundp header) (symbol-value header))
2871 ;; The element is a symbol. We insert the value
2872 ;; of this symbol, if any.
2873 (symbol-value header))
2875 ;; We couldn't generate a value for this header,
2876 ;; so we just ask the user.
2877 (read-from-minibuffer
2878 (format "Empty header for %s; enter value: " header)))))
2879 ;; Finally insert the header.
2881 (not (equal value "")))
2885 ;; This header didn't exist, so we insert it.
2886 (goto-char (point-max))
2887 (insert (symbol-name header) ": " value "\n")
2889 ;; The value of this header was empty, so we clear
2890 ;; totally and insert the new value.
2891 (delete-region (point) (gnus-point-at-eol))
2893 ;; Add the deletable property to the headers that require it.
2894 (and (memq header message-deletable-headers)
2895 (progn (beginning-of-line) (looking-at "[^:]+: "))
2896 (add-text-properties
2897 (point) (match-end 0)
2898 '(message-deletable t face italic) (current-buffer)))))))
2899 ;; Insert new Sender if the From is strange.
2900 (let ((from (message-fetch-field "from"))
2901 (sender (message-fetch-field "sender"))
2902 (secure-sender (message-make-sender)))
2904 (not (message-check-element 'sender))
2907 (cadr (mail-extract-address-components from)))
2908 (downcase secure-sender)))
2913 (cadr (mail-extract-address-components sender)))
2914 (downcase secure-sender)))))
2915 (goto-char (point-min))
2916 ;; Rename any old Sender headers to Original-Sender.
2917 (when (re-search-forward "^\\(Original-\\)*Sender:" nil t)
2919 (insert "Original-")
2920 (beginning-of-line))
2921 (when (or (message-news-p)
2922 (string-match "@.+\\.." secure-sender))
2923 (insert "Sender: " secure-sender "\n")))))))
2925 (defun message-insert-courtesy-copy ()
2926 "Insert a courtesy message in mail copies of combined messages."
2930 (message-narrow-to-headers)
2931 (when (setq newsgroups (message-fetch-field "newsgroups"))
2932 (goto-char (point-max))
2933 (insert "Posted-To: " newsgroups "\n")))
2935 (when message-courtesy-message
2937 ((string-match "%s" message-courtesy-message)
2938 (insert (format message-courtesy-message newsgroups)))
2940 (insert message-courtesy-message)))))))
2943 ;;; Setting up a message buffer
2946 (defun message-fill-address (header value)
2948 (narrow-to-region (point) (point))
2949 (insert (capitalize (symbol-name header))
2951 (if (consp value) (car value) value)
2953 (narrow-to-region (point-min) (1- (point-max)))
2955 (goto-char (point-min))
2957 (skip-chars-forward "^,\"" (point-max))
2958 (if (or (= (following-char) ?,)
2961 (if (and (> (current-column) 78)
2967 (setq last (1+ (point))))
2968 (setq last (1+ (point)))))
2969 (setq quoted (not quoted)))
2972 (goto-char (point-max))
2976 (defun message-fill-header (header value)
2977 (let ((begin (point))
2980 (insert (capitalize (symbol-name header))
2982 (if (consp value) (car value) value)
2985 (narrow-to-region begin (point))
2986 (fill-region-as-paragraph begin (point))
2987 ;; Tapdance around looong Message-IDs.
2989 (when (looking-at "[ \t]*$")
2990 (message-delete-line))
2992 (re-search-forward ":" nil t)
2993 (when (looking-at "\n[ \t]+")
2994 (replace-match " " t t))
2995 (goto-char (point-max)))))
2997 (defun message-position-point ()
2998 "Move point to where the user probably wants to find it."
2999 (message-narrow-to-headers)
3001 ((re-search-forward "^[^:]+:[ \t]*$" nil t)
3002 (search-backward ":" )
3005 (if (= (following-char) ? )
3009 (goto-char (point-max))
3012 (unless (looking-at "$")
3016 (defun message-buffer-name (type &optional to group)
3017 "Return a new (unique) buffer name based on TYPE and TO."
3019 ;; Check whether `message-generate-new-buffers' is a function,
3020 ;; and if so, call it.
3021 ((message-functionp message-generate-new-buffers)
3022 (funcall message-generate-new-buffers type to group))
3023 ;; Generate a new buffer name The Message Way.
3024 (message-generate-new-buffers
3025 (generate-new-buffer-name
3029 (or (car (mail-extract-address-components to))
3032 (if (and group (not (string= group ""))) (concat " on " group) "")
3034 ;; Use standard name.
3036 (format "*%s message*" type))))
3038 (defun message-pop-to-buffer (name)
3039 "Pop to buffer NAME, and warn if it already exists and is modified."
3040 (let ((buffer (get-buffer name)))
3042 (buffer-name buffer))
3044 (set-buffer (pop-to-buffer buffer))
3045 (when (and (buffer-modified-p)
3047 "Message already being composed; erase? ")))
3048 (error "Message being composed")))
3049 (set-buffer (pop-to-buffer name))))
3053 (defun message-do-send-housekeeping ()
3054 "Kill old message buffers."
3055 ;; We might have sent this buffer already. Delete it from the
3057 (setq message-buffer-list (delq (current-buffer) message-buffer-list))
3058 (while (and message-max-buffers
3060 (>= (length message-buffer-list) message-max-buffers))
3061 ;; Kill the oldest buffer -- unless it has been changed.
3062 (let ((buffer (pop message-buffer-list)))
3063 (when (and (buffer-name buffer)
3064 (not (buffer-modified-p buffer)))
3065 (kill-buffer buffer))))
3066 ;; Rename the buffer.
3067 (if message-send-rename-function
3068 (funcall message-send-rename-function)
3069 (when (string-match "\\`\\*" (buffer-name))
3071 (concat "*sent " (substring (buffer-name) (match-end 0))) t)))
3072 ;; Push the current buffer onto the list.
3073 (when message-max-buffers
3074 (setq message-buffer-list
3075 (nconc message-buffer-list (list (current-buffer))))))
3077 (defvar mc-modes-alist)
3078 (defun message-setup (headers &optional replybuffer actions)
3079 (when (and (boundp 'mc-modes-alist)
3080 (not (assq 'message-mode mc-modes-alist)))
3081 (push '(message-mode (encrypt . mc-encrypt-message)
3082 (sign . mc-sign-message))
3085 (setq message-send-actions actions))
3086 (setq message-reply-buffer replybuffer)
3087 (goto-char (point-min))
3088 ;; Insert all the headers.
3091 (alist message-header-format-alist))
3093 (unless (assq (caar h) message-header-format-alist)
3094 (push (list (caar h)) alist))
3098 (delete-region (point) (progn (forward-line -1) (point)))
3099 (when message-default-headers
3100 (insert message-default-headers)
3101 (or (bolp) (insert ?\n)))
3105 (insert mail-header-separator "\n")
3109 (when (message-news-p)
3110 (when message-default-news-headers
3111 (insert message-default-news-headers)
3112 (or (bolp) (insert ?\n)))
3113 (when message-generate-headers-first
3114 (message-generate-headers
3117 (copy-sequence message-required-news-headers))))))
3118 (when (message-mail-p)
3119 (when message-default-mail-headers
3120 (insert message-default-mail-headers)
3121 (or (bolp) (insert ?\n)))
3122 (when message-generate-headers-first
3123 (message-generate-headers
3126 (copy-sequence message-required-mail-headers))))))
3127 (run-hooks 'message-signature-setup-hook)
3128 (message-insert-signature)
3130 (message-narrow-to-headers)
3131 (run-hooks 'message-header-setup-hook))
3132 (set-buffer-modified-p nil)
3133 (setq buffer-undo-list nil)
3134 (run-hooks 'message-setup-hook)
3135 (message-position-point)
3138 (defun message-set-auto-save-file-name ()
3139 "Associate the message buffer with a file in the drafts directory."
3140 (when message-autosave-directory
3142 (setq message-draft-article
3143 (nndraft-request-associate-buffer "drafts"))
3144 (setq buffer-file-name (expand-file-name "*message*"
3145 message-autosave-directory))
3146 (setq buffer-auto-save-file-name (make-auto-save-file-name)))
3147 (clear-visited-file-modtime)))
3149 (defun message-disassociate-draft ()
3150 "Disassociate the message buffer from the drafts directory."
3151 (when message-draft-article
3152 (nndraft-request-expire-articles
3153 (list message-draft-article) "drafts" nil t)))
3158 ;;; Commands for interfacing with message
3162 (defun message-mail (&optional to subject
3163 other-headers continue switch-function
3164 yank-action send-actions)
3165 "Start editing a mail message to be sent."
3167 (let ((message-this-is-mail t))
3168 (message-pop-to-buffer (message-buffer-name "mail" to))
3171 `((To . ,(or to "")) (Subject . ,(or subject "")))
3172 (when other-headers other-headers)))))
3175 (defun message-news (&optional newsgroups subject)
3176 "Start editing a news article to be sent."
3178 (let ((message-this-is-news t))
3179 (message-pop-to-buffer (message-buffer-name "news" nil newsgroups))
3180 (message-setup `((Newsgroups . ,(or newsgroups ""))
3181 (Subject . ,(or subject ""))))))
3184 (defun message-reply (&optional to-address wide ignore-reply-to)
3185 "Start editing a reply to the article in the current buffer."
3187 (let ((cur (current-buffer))
3188 from subject date reply-to to cc
3189 references message-id follow-to
3190 (inhibit-point-motion-hooks t)
3191 mct never-mct gnus-warning)
3193 (message-narrow-to-head)
3194 ;; Allow customizations to have their say.
3196 ;; This is a regular reply.
3197 (if (message-functionp message-reply-to-function)
3198 (setq follow-to (funcall message-reply-to-function)))
3199 ;; This is a followup.
3200 (if (message-functionp message-wide-reply-to-function)
3203 (funcall message-wide-reply-to-function)))))
3204 ;; Find all relevant headers we need.
3205 (setq from (message-fetch-field "from")
3206 date (message-fetch-field "date")
3207 subject (or (message-fetch-field "subject") "none")
3208 to (message-fetch-field "to")
3209 cc (message-fetch-field "cc")
3210 mct (message-fetch-field "mail-copies-to")
3211 reply-to (unless ignore-reply-to (message-fetch-field "reply-to"))
3212 references (message-fetch-field "references")
3213 message-id (message-fetch-field "message-id" t))
3214 ;; Remove any (buggy) Re:'s that are present and make a
3216 (when (string-match "^[ \t]*[Rr][Ee]:[ \t]*" subject)
3217 (setq subject (substring subject (match-end 0))))
3218 (setq subject (concat "Re: " subject))
3220 (when (and (setq gnus-warning (message-fetch-field "gnus-warning"))
3221 (string-match "<[^>]+>" gnus-warning))
3222 (setq message-id (match-string 0 gnus-warning)))
3224 ;; Handle special values of Mail-Copies-To.
3226 (cond ((equal (downcase mct) "never")
3229 ((equal (downcase mct) "always")
3230 (setq mct (or reply-to from)))))
3236 (setq follow-to (list (cons 'To (or to-address reply-to from))))
3237 (when (and wide mct)
3238 (push (cons 'Cc mct) follow-to)))
3241 (message-set-work-buffer)
3243 (insert (or reply-to from "")))
3244 (insert (if to (concat (if (bolp) "" ", ") to "") ""))
3245 (insert (if mct (concat (if (bolp) "" ", ") mct) ""))
3246 (insert (if cc (concat (if (bolp) "" ", ") cc) ""))
3247 (goto-char (point-min))
3248 (while (re-search-forward "[ \t]+" nil t)
3249 (replace-match " " t t))
3250 ;; Remove addresses that match `rmail-dont-reply-to-names'.
3251 (insert (prog1 (rmail-dont-reply-to (buffer-string))
3253 (goto-char (point-min))
3254 ;; Perhaps Mail-Copies-To: never removed the only address?
3256 (insert (or reply-to from "")))
3260 (cons (mail-strip-quoted-names addr) addr))
3261 (message-tokenize-header (buffer-string))))
3264 (setq ccalist (delq (assoc (car (pop s)) s) ccalist)))))
3265 (setq follow-to (list (cons 'To (cdr (pop ccalist)))))
3267 (let ((ccs (cons 'Cc (mapconcat
3268 (lambda (addr) (cdr addr)) ccalist ", "))))
3269 (when (string-match "^ +" (cdr ccs))
3270 (setcdr ccs (substring (cdr ccs) (match-end 0))))
3271 (push ccs follow-to))))))
3274 (message-pop-to-buffer (message-buffer-name
3275 (if wide "wide reply" "reply") from
3276 (if wide to-address nil)))
3278 (setq message-reply-headers
3279 (vector 0 subject from date message-id references 0 0 ""))
3282 `((Subject . ,subject)
3284 ,@(if (or references message-id)
3285 `((References . ,(concat (or references "") (and references " ")
3286 (or message-id ""))))
3291 (defun message-wide-reply (&optional to-address ignore-reply-to)
3292 "Make a \"wide\" reply to the message in the current buffer."
3294 (message-reply to-address t ignore-reply-to))
3297 (defun message-followup (&optional to-newsgroups)
3298 "Follow up to the message in the current buffer.
3299 If TO-NEWSGROUPS, use that as the new Newsgroups line."
3301 (let ((cur (current-buffer))
3302 from subject date reply-to mct
3303 references message-id follow-to
3304 (inhibit-point-motion-hooks t)
3305 (message-this-is-news t)
3306 followup-to distribution newsgroups gnus-warning posted-to)
3309 (goto-char (point-min))
3310 (if (search-forward "\n\n" nil t)
3313 (when (message-functionp message-followup-to-function)
3315 (funcall message-followup-to-function)))
3316 (setq from (message-fetch-field "from")
3317 date (message-fetch-field "date")
3318 subject (or (message-fetch-field "subject") "none")
3319 references (message-fetch-field "references")
3320 message-id (message-fetch-field "message-id" t)
3321 followup-to (message-fetch-field "followup-to")
3322 newsgroups (message-fetch-field "newsgroups")
3323 posted-to (message-fetch-field "posted-to")
3324 reply-to (message-fetch-field "reply-to")
3325 distribution (message-fetch-field "distribution")
3326 mct (message-fetch-field "mail-copies-to"))
3327 (when (and (setq gnus-warning (message-fetch-field "gnus-warning"))
3328 (string-match "<[^>]+>" gnus-warning))
3329 (setq message-id (match-string 0 gnus-warning)))
3330 ;; Remove bogus distribution.
3331 (when (and (stringp distribution)
3332 (let ((case-fold-search t))
3333 (string-match "world" distribution)))
3334 (setq distribution nil))
3335 ;; Remove any (buggy) Re:'s that are present and make a
3337 (when (string-match "^[ \t]*[Rr][Ee]:[ \t]*" subject)
3338 (setq subject (substring subject (match-end 0))))
3339 (setq subject (concat "Re: " subject))
3342 (message-pop-to-buffer (message-buffer-name "followup" from newsgroups))
3345 `((Subject . ,subject)
3348 (list (cons 'Newsgroups to-newsgroups)))
3349 (follow-to follow-to)
3350 ((and followup-to message-use-followup-to)
3353 ((equal (downcase followup-to) "poster")
3354 (if (or (eq message-use-followup-to 'use)
3355 (message-y-or-n-p "Obey Followup-To: poster? " t "\
3356 You should normally obey the Followup-To: header.
3358 `Followup-To: poster' sends your response via e-mail instead of news.
3360 A typical situation where `Followup-To: poster' is used is when the poster
3361 does not read the newsgroup, so he wouldn't see any replies sent to it."))
3363 (setq message-this-is-news nil)
3364 (cons 'To (or reply-to from "")))
3365 (cons 'Newsgroups newsgroups)))
3367 (if (or (equal followup-to newsgroups)
3368 (not (eq message-use-followup-to 'ask))
3370 (concat "Obey Followup-To: " followup-to "? ") t "\
3371 You should normally obey the Followup-To: header.
3373 `Followup-To: " followup-to "'
3374 directs your response to " (if (string-match "," followup-to)
3375 "the specified newsgroups"
3376 "that newsgroup only") ".
3378 If a message is posted to several newsgroups, Followup-To is often
3379 used to direct the following discussion to one newsgroup only,
3380 because discussions that are spread over several newsgroup tend to
3381 be fragmented and very difficult to follow.
3383 Also, some source/announcement newsgroups are not indented for discussion;
3384 responses here are directed to other newsgroups."))
3385 (cons 'Newsgroups followup-to)
3386 (cons 'Newsgroups newsgroups))))))
3388 `((Newsgroups . ,posted-to)))
3390 `((Newsgroups . ,newsgroups))))
3391 ,@(and distribution (list (cons 'Distribution distribution)))
3392 ,@(if (or references message-id)
3393 `((References . ,(concat (or references "") (and references " ")
3394 (or message-id "")))))
3396 (not (equal (downcase mct) "never")))
3397 (list (cons 'Cc (if (equal (downcase mct) "always")
3398 (or reply-to from "")
3403 (setq message-reply-headers
3404 (vector 0 subject from date message-id references 0 0 ""))))
3408 (defun message-cancel-news ()
3409 "Cancel an article you posted."
3411 (unless (message-news-p)
3412 (error "This is not a news article; canceling is impossible"))
3413 (when (yes-or-no-p "Do you really want to cancel this article? ")
3414 (let (from newsgroups message-id distribution buf sender)
3416 ;; Get header info. from original article.
3418 (message-narrow-to-head)
3419 (setq from (message-fetch-field "from")
3420 sender (message-fetch-field "sender")
3421 newsgroups (message-fetch-field "newsgroups")
3422 message-id (message-fetch-field "message-id" t)
3423 distribution (message-fetch-field "distribution")))
3424 ;; Make sure that this article was written by the user.
3425 (unless (string-equal
3427 (or sender (cadr (mail-extract-address-components from))))
3428 (downcase (message-make-sender)))
3429 (error "This article is not yours"))
3430 ;; Make control message.
3431 (setq buf (set-buffer (get-buffer-create " *message cancel*")))
3432 (buffer-disable-undo (current-buffer))
3434 (insert "Newsgroups: " newsgroups "\n"
3435 "From: " (message-make-from) "\n"
3436 "Subject: cmsg cancel " message-id "\n"
3437 "Control: cancel " message-id "\n"
3439 (concat "Distribution: " distribution "\n")
3441 mail-header-separator "\n"
3442 message-cancel-message)
3443 (message "Canceling your article...")
3444 (if (let ((message-syntax-checks
3445 'dont-check-for-anything-just-trust-me))
3446 (funcall message-send-news-function))
3447 (message "Canceling your article...done"))
3448 (kill-buffer buf)))))
3451 (defun message-supersede ()
3452 "Start composing a message to supersede the current message.
3453 This is done simply by taking the old article and adding a Supersedes
3454 header line with the old Message-ID."
3456 (let ((cur (current-buffer)))
3457 ;; Check whether the user owns the article that is to be superseded.
3458 (unless (string-equal
3459 (downcase (or (message-fetch-field "sender")
3460 (cadr (mail-extract-address-components
3461 (message-fetch-field "from")))))
3462 (downcase (message-make-sender)))
3463 (error "This article is not yours"))
3464 ;; Get a normal message buffer.
3465 (message-pop-to-buffer (message-buffer-name "supersede"))
3466 (insert-buffer-substring cur)
3467 (message-narrow-to-head)
3468 ;; Remove unwanted headers.
3469 (when message-ignored-supersedes-headers
3470 (message-remove-header message-ignored-supersedes-headers t))
3471 (goto-char (point-min))
3472 (if (not (re-search-forward "^Message-ID: " nil t))
3473 (error "No Message-ID in this article")
3474 (replace-match "Supersedes: " t t))
3475 (goto-char (point-max))
3476 (insert mail-header-separator)
3481 (defun message-recover ()
3482 "Reread contents of current buffer from its last auto-save file."
3484 (let ((file-name (make-auto-save-file-name)))
3485 (cond ((save-window-excursion
3486 (if (not (eq system-type 'vax-vms))
3487 (with-output-to-temp-buffer "*Directory*"
3488 (buffer-disable-undo standard-output)
3489 (let ((default-directory "/"))
3491 "ls" nil standard-output nil "-l" file-name))))
3492 (yes-or-no-p (format "Recover auto save file %s? " file-name)))
3493 (let ((buffer-read-only nil))
3495 (insert-file-contents file-name nil)))
3496 (t (error "message-recover cancelled")))))
3498 ;;; Forwarding messages.
3500 (defun message-make-forward-subject ()
3501 "Return a Subject header suitable for the message in the current buffer."
3505 (message-narrow-to-head)
3506 (concat "[" (or (message-fetch-field
3507 (if (message-news-p) "newsgroups" "from"))
3509 "] " (or (message-fetch-field "Subject") "")))))
3512 (defun message-forward (&optional news)
3513 "Forward the current message via mail.
3514 Optional NEWS will use news to forward instead of mail."
3516 (let ((cur (current-buffer))
3517 (subject (message-make-forward-subject))
3519 (if news (message-news nil subject) (message-mail nil subject))
3520 ;; Put point where we want it before inserting the forwarded
3522 (if message-signature-before-forwarded-message
3523 (goto-char (point-max))
3524 (message-goto-body))
3525 ;; Make sure we're at the start of the line.
3528 ;; Narrow to the area we are to insert.
3529 (narrow-to-region (point) (point))
3530 ;; Insert the separators and the forwarded buffer.
3531 (insert message-forward-start-separator)
3532 (setq art-beg (point))
3533 (insert-buffer-substring cur)
3534 (goto-char (point-max))
3535 (insert message-forward-end-separator)
3536 (set-text-properties (point-min) (point-max) nil)
3537 ;; Remove all unwanted headers.
3539 (narrow-to-region (point) (if (search-forward "\n\n" nil t)
3542 (goto-char (point-min))
3543 (message-remove-header message-included-forward-headers t nil t)
3545 (message-position-point)))
3548 (defun message-resend (address)
3549 "Resend the current article to ADDRESS."
3550 (interactive "sResend message to: ")
3551 (message "Resending message to %s..." address)
3553 (let ((cur (current-buffer))
3555 ;; We first set up a normal mail buffer.
3556 (set-buffer (get-buffer-create " *message resend*"))
3557 (buffer-disable-undo (current-buffer))
3559 (message-setup `((To . ,address)))
3560 ;; Insert our usual headers.
3561 (message-generate-headers '(From Date To))
3562 (message-narrow-to-headers)
3563 ;; Rename them all to "Resent-*".
3564 (while (re-search-forward "^[A-Za-z]" nil t)
3569 (delete-region (point) (point-max))
3571 ;; Insert the message to be resent.
3572 (insert-buffer-substring cur)
3573 (goto-char (point-min))
3574 (search-forward "\n\n")
3577 (narrow-to-region beg (point))
3578 (message-remove-header message-ignored-resent-headers t)
3579 (goto-char (point-max)))
3580 (insert mail-header-separator)
3581 ;; Rename all old ("Also-")Resent headers.
3582 (while (re-search-backward "^\\(Also-\\)*Resent-" beg t)
3585 ;; Quote any "From " lines at the beginning.
3587 (when (looking-at "From ")
3588 (replace-match "X-From-Line: "))
3591 (kill-buffer (current-buffer)))
3592 (message "Resending message to %s...done" address)))
3595 (defun message-bounce ()
3596 "Re-mail the current message.
3597 This only makes sense if the current message is a bounce message than
3598 contains some mail you have written which has been bounced back to
3601 (let ((cur (current-buffer))
3603 (message-pop-to-buffer (message-buffer-name "bounce"))
3604 (insert-buffer-substring cur)
3606 (message-narrow-to-head)
3607 (if (and (message-fetch-field "Mime-Version")
3608 (setq boundary (message-fetch-field "Content-Type")))
3609 (if (string-match "boundary=\"\\([^\"]+\\)\"" boundary)
3610 (setq boundary (concat (match-string 1 boundary) " *\n"
3611 "Content-Type: message/rfc822"))
3612 (setq boundary nil)))
3614 (goto-char (point-min))
3615 (search-forward "\n\n" nil t)
3617 (re-search-forward boundary nil t)
3619 (and (re-search-forward message-unsent-separator nil t)
3621 (re-search-forward "^Return-Path:.*\n" nil t))
3622 ;; We remove everything before the bounced mail.
3625 (if (re-search-forward "^[^ \n\t]+:" nil t)
3629 (message-narrow-to-head)
3630 (message-remove-header message-ignored-bounced-headers t)
3631 (goto-char (point-max))
3632 (insert mail-header-separator))
3633 (message-position-point)))
3636 ;;; Interactive entry points for new message buffers.
3640 (defun message-mail-other-window (&optional to subject)
3641 "Like `message-mail' command, but display mail buffer in another window."
3643 (let ((pop-up-windows t)
3644 (special-display-buffer-names nil)
3645 (special-display-regexps nil)
3646 (same-window-buffer-names nil)
3647 (same-window-regexps nil))
3648 (message-pop-to-buffer (message-buffer-name "mail" to)))
3649 (message-setup `((To . ,(or to "")) (Subject . ,(or subject "")))))
3652 (defun message-mail-other-frame (&optional to subject)
3653 "Like `message-mail' command, but display mail buffer in another frame."
3655 (let ((pop-up-frames t)
3656 (special-display-buffer-names nil)
3657 (special-display-regexps nil)
3658 (same-window-buffer-names nil)
3659 (same-window-regexps nil))
3660 (message-pop-to-buffer (message-buffer-name "mail" to)))
3661 (message-setup `((To . ,(or to "")) (Subject . ,(or subject "")))))
3664 (defun message-news-other-window (&optional newsgroups subject)
3665 "Start editing a news article to be sent."
3667 (let ((pop-up-windows t)
3668 (special-display-buffer-names nil)
3669 (special-display-regexps nil)
3670 (same-window-buffer-names nil)
3671 (same-window-regexps nil))
3672 (message-pop-to-buffer (message-buffer-name "news" nil newsgroups)))
3673 (message-setup `((Newsgroups . ,(or newsgroups ""))
3674 (Subject . ,(or subject "")))))
3677 (defun message-news-other-frame (&optional newsgroups subject)
3678 "Start editing a news article to be sent."
3680 (let ((pop-up-frames t)
3681 (special-display-buffer-names nil)
3682 (special-display-regexps nil)
3683 (same-window-buffer-names nil)
3684 (same-window-regexps nil))
3685 (message-pop-to-buffer (message-buffer-name "news" nil newsgroups)))
3686 (message-setup `((Newsgroups . ,(or newsgroups ""))
3687 (Subject . ,(or subject "")))))
3691 ;; This code should be moved to underline.el (from which it is stolen).
3694 (defun bold-region (start end)
3695 "Bold all nonblank characters in the region.
3696 Works by overstriking characters.
3697 Called from program, takes two arguments START and END
3698 which specify the range to operate on."
3701 (let ((end1 (make-marker)))
3702 (move-marker end1 (max start end))
3703 (goto-char (min start end))
3704 (while (< (point) end1)
3705 (or (looking-at "[_\^@- ]")
3706 (insert (following-char) "\b"))
3707 (forward-char 1)))))
3710 (defun unbold-region (start end)
3711 "Remove all boldness (overstruck characters) in the region.
3712 Called from program, takes two arguments START and END
3713 which specify the range to operate on."
3716 (let ((end1 (make-marker)))
3717 (move-marker end1 (max start end))
3718 (goto-char (min start end))
3719 (while (re-search-forward "\b" end1 t)
3720 (if (eq (following-char) (char-after (- (point) 2)))
3721 (delete-char -2))))))
3723 (defalias 'message-exchange-point-and-mark 'exchange-point-and-mark)
3725 ;; Support for toolbar
3726 (when (string-match "XEmacs\\|Lucid" emacs-version)
3727 (require 'messagexmas))
3729 ;;; Group name completion.
3731 (defvar message-newgroups-header-regexp
3732 "^\\(Newsgroups\\|Followup-To\\|Posted-To\\|Gcc\\):"
3733 "Regexp that match headers that lists groups.")
3735 (defun message-tab ()
3736 "Expand group names in Newsgroups and Followup-To headers.
3737 Do a `tab-to-tab-stop' if not in those headers."
3739 (if (let ((mail-abbrev-mode-regexp message-newgroups-header-regexp))
3740 (mail-abbrev-in-expansion-header-p))
3741 (message-expand-group)
3744 (defvar gnus-active-hashtb)
3745 (defun message-expand-group ()
3746 "Expand the group name under point."
3747 (let* ((b (save-excursion
3752 (skip-chars-forward "^:")
3755 (skip-chars-backward "^, \t\n") (point))))
3756 (completion-ignore-case t)
3757 (string (buffer-substring b (progn (skip-chars-forward "^,\t\n ")
3759 (hashtb (and (boundp 'gnus-active-hashtb) gnus-active-hashtb))
3760 (completions (all-completions string hashtb))
3761 (cur (current-buffer))
3763 (delete-region b (point))
3765 ((= (length completions) 1)
3766 (if (string= (car completions) string)
3769 (message "Only matching group"))
3770 (insert (car completions))))
3771 ((and (setq comp (try-completion string hashtb))
3772 (not (string= comp string)))
3777 (message "No matching groups")
3778 (save-selected-window
3779 (pop-to-buffer "*Completions*")
3780 (buffer-disable-undo (current-buffer))
3781 (let ((buffer-read-only nil))
3783 (let ((standard-output (current-buffer)))
3784 (display-completion-list (sort completions 'string<)))
3785 (goto-char (point-min))
3786 (delete-region (point) (progn (forward-line 3) (point))))))))))
3790 (defun message-talkative-question (ask question show &rest text)
3791 "Call FUNCTION with argument QUESTION; optionally display TEXT... args.
3792 If SHOW is non-nil, the arguments TEXT... are displayed in a temp buffer.
3793 The following arguments may contain lists of values."
3795 (setq text (message-flatten-list text)))
3796 (save-window-excursion
3798 (with-output-to-temp-buffer " *MESSAGE information message*"
3799 (set-buffer " *MESSAGE information message*")
3800 (mapcar 'princ text)
3801 (goto-char (point-min))))
3802 (funcall ask question))
3803 (funcall ask question)))
3805 (defun message-flatten-list (list)
3806 "Return a new, flat list that contains all elements of LIST.
3808 \(message-flatten-list '(1 (2 3 (4 5 (6))) 7))
3811 (apply 'append (mapcar 'message-flatten-list list)))
3815 (defun message-generate-new-buffer-clone-locals (name &optional varstr)
3816 "Create and return a buffer with a name based on NAME using generate-new-buffer.
3817 Then clone the local variables and values from the old buffer to the
3818 new one, cloning only the locals having a substring matching the
3820 (let ((oldbuf (current-buffer)))
3822 (set-buffer (generate-new-buffer name))
3823 (message-clone-locals oldbuf)
3826 (defun message-clone-locals (buffer)
3827 "Clone the local variables from BUFFER to the current buffer."
3828 (let ((locals (save-excursion
3830 (buffer-local-variables)))
3831 (regexp "^gnus\\|^nn\\|^message"))
3834 (when (and (consp local)
3836 (string-match regexp (symbol-name (car local))))
3838 (set (make-local-variable (car local))
3842 ;;; Miscellaneous functions
3844 ;; stolen (and renamed) from nnheader.el
3845 (defun message-replace-chars-in-string (string from to)
3846 "Replace characters in STRING from FROM to TO."
3847 (let ((string (substring string 0)) ;Copy string.
3848 (len (length string))
3850 ;; Replace all occurrences of FROM with TO.
3852 (when (= (aref string idx) from)
3853 (aset string idx to))
3854 (setq idx (1+ idx)))
3857 (run-hooks 'message-load-hook)
3861 ;;; message.el ends here