1 ;;; message.el --- composing mail and news messages
2 ;; Copyright (C) 1996,97,98,99 Free Software Foundation, Inc.
4 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
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))
38 (if (string-match "XEmacs\\|Lucid" emacs-version)
39 (require 'mail-abbrevs)
40 (require 'mailabbrev))
46 (defgroup message '((user-mail-address custom-variable)
47 (user-full-name custom-variable))
48 "Mail and news message composing."
49 :link '(custom-manual "(message)Top")
53 (put 'user-mail-address 'custom-type 'string)
54 (put 'user-full-name 'custom-type 'string)
56 (defgroup message-various nil
57 "Various Message Variables"
58 :link '(custom-manual "(message)Various Message Variables")
61 (defgroup message-buffers nil
63 :link '(custom-manual "(message)Message Buffers")
66 (defgroup message-sending nil
68 :link '(custom-manual "(message)Sending Variables")
71 (defgroup message-interface nil
73 :link '(custom-manual "(message)Interface")
76 (defgroup message-forwarding nil
78 :link '(custom-manual "(message)Forwarding")
79 :group 'message-interface)
81 (defgroup message-insertion nil
83 :link '(custom-manual "(message)Insertion")
86 (defgroup message-headers nil
88 :link '(custom-manual "(message)Message Headers")
91 (defgroup message-news nil
92 "Composing News Messages"
95 (defgroup message-mail nil
96 "Composing Mail Messages"
99 (defgroup message-faces nil
100 "Faces used for message composing."
104 (defcustom message-directory "~/Mail/"
105 "*Directory from which all other mail file variables are derived."
106 :group 'message-various
109 (defcustom message-max-buffers 10
110 "*How many buffers to keep before starting to kill them off."
111 :group 'message-buffers
114 (defcustom message-send-rename-function nil
115 "Function called to rename the buffer after sending it."
116 :group 'message-buffers
119 (defcustom message-fcc-handler-function 'message-output
120 "*A function called to save outgoing articles.
121 This function will be called with the name of the file to store the
122 article in. The default function is `message-output' which saves in Unix
124 :type '(radio (function-item message-output)
125 (function :tag "Other"))
126 :group 'message-sending)
128 (defcustom message-courtesy-message
129 "The following message is a courtesy copy of an article\nthat has been posted to %s as well.\n\n"
130 "*This is inserted at the start of a mailed copy of a posted message.
131 If the string contains the format spec \"%s\", the Newsgroups
132 the article has been posted to will be inserted there.
133 If this variable is nil, no such courtesy message will be added."
134 :group 'message-sending
137 (defcustom message-ignored-bounced-headers "^\\(Received\\|Return-Path\\):"
138 "*Regexp that matches headers to be removed in resent bounced mail."
139 :group 'message-interface
143 (defcustom message-from-style 'default
144 "*Specifies how \"From\" headers look.
146 If `nil', they contain just the return address like:
148 If `parens', they look like:
149 king@grassland.com (Elvis Parsley)
150 If `angles', they look like:
151 Elvis Parsley <king@grassland.com>
153 Otherwise, most addresses look like `angles', but they look like
154 `parens' if `angles' would need quoting and `parens' would not."
155 :type '(choice (const :tag "simple" nil)
159 :group 'message-headers)
161 (defcustom message-syntax-checks nil
162 ; Guess this one shouldn't be easy to customize...
163 "*Controls what syntax checks should not be performed on outgoing posts.
164 To disable checking of long signatures, for instance, add
165 `(signature . disabled)' to this list.
167 Don't touch this variable unless you really know what you're doing.
169 Checks include subject-cmsg multiple-headers sendsys message-id from
170 long-lines control-chars size new-text redirected-followup signature
171 approved sender empty empty-headers message-id from subject
172 shorten-followup-to existing-newsgroups buffer-file-name unchanged."
173 :group 'message-news)
175 (defcustom message-required-news-headers
176 '(From Newsgroups Subject Date Message-ID
177 (optional . Organization) Lines
178 (optional . User-Agent))
179 "*Headers to be generated or prompted for when posting an article.
180 RFC977 and RFC1036 require From, Date, Newsgroups, Subject,
181 Message-ID. Organization, Lines, In-Reply-To, Expires, and
182 User-Agent are optional. If don't you want message to insert some
183 header, remove it from this list."
185 :group 'message-headers
186 :type '(repeat sexp))
188 (defcustom message-required-mail-headers
189 '(From Subject Date (optional . In-Reply-To) Message-ID Lines
190 (optional . User-Agent))
191 "*Headers to be generated or prompted for when mailing a message.
192 RFC822 required that From, Date, To, Subject and Message-ID be
193 included. Organization, Lines and User-Agent are optional."
195 :group 'message-headers
196 :type '(repeat sexp))
198 (defcustom message-deletable-headers '(Message-ID Date Lines)
199 "Headers to be deleted if they already exist and were generated by message previously."
200 :group 'message-headers
203 (defcustom message-ignored-news-headers
204 "^NNTP-Posting-Host:\\|^Xref:\\|^[BGF]cc:\\|^Resent-Fcc:"
205 "*Regexp of headers to be removed unconditionally before posting."
207 :group 'message-headers
210 (defcustom message-ignored-mail-headers "^[GF]cc:\\|^Resent-Fcc:\\|^Xref:"
211 "*Regexp of headers to be removed unconditionally before mailing."
213 :group 'message-headers
216 (defcustom message-ignored-supersedes-headers "^Path:\\|^Date\\|^NNTP-Posting-Host:\\|^Xref:\\|^Lines:\\|^Received:\\|^X-From-Line:\\|^X-Trace:\\|^X-Complaints-To:\\|Return-Path:\\|^Supersedes:\\|^NNTP-Posting-Date:\\|^X-Trace:\\|^X-Complaints-To:"
217 "*Header lines matching this regexp will be deleted before posting.
218 It's best to delete old Path and Date headers before posting to avoid
220 :group 'message-interface
223 (defcustom message-subject-re-regexp "^[ \t]*\\([Rr][Ee]:[ \t]*\\)*[ \t]*"
224 "*Regexp matching \"Re: \" in the subject line."
225 :group 'message-various
229 (defcustom message-signature-separator "^-- *$"
230 "Regexp matching the signature separator."
232 :group 'message-various)
234 (defcustom message-elide-elipsis "\n[...]\n\n"
235 "*The string which is inserted for elided text."
237 :group 'message-various)
239 (defcustom message-interactive nil
240 "Non-nil means when sending a message wait for and display errors.
241 nil means let mailer mail back a message to report errors."
242 :group 'message-sending
246 (defcustom message-generate-new-buffers 'unique
247 "*Non-nil means that a new message buffer will be created whenever `message-setup' is called.
248 If this is a function, call that function with three parameters: The type,
249 the to address and the group name. (Any of these may be nil.) The function
250 should return the new buffer name."
251 :group 'message-buffers
252 :type '(choice (const :tag "off" nil)
253 (const :tag "unique" unique)
254 (const :tag "unsent" unsent)
257 (defcustom message-kill-buffer-on-exit nil
258 "*Non-nil means that the message buffer will be killed after sending a message."
259 :group 'message-buffers
262 (defvar gnus-local-organization)
263 (defcustom message-user-organization
264 (or (and (boundp 'gnus-local-organization)
265 (stringp gnus-local-organization)
266 gnus-local-organization)
267 (getenv "ORGANIZATION")
269 "*String to be used as an Organization header.
270 If t, use `message-user-organization-file'."
271 :group 'message-headers
272 :type '(choice string
273 (const :tag "consult file" t)))
276 (defcustom message-user-organization-file "/usr/lib/news/organization"
277 "*Local news organization file."
279 :group 'message-headers)
281 (defcustom message-forward-start-separator
282 "------- Start of forwarded message -------\n"
283 "*Delimiter inserted before forwarded messages."
284 :group 'message-forwarding
287 (defcustom message-forward-end-separator
288 "------- End of forwarded message -------\n"
289 "*Delimiter inserted after forwarded messages."
290 :group 'message-forwarding
293 (defcustom message-signature-before-forwarded-message t
294 "*If non-nil, put the signature before any included forwarded message."
295 :group 'message-forwarding
298 (defcustom message-included-forward-headers
299 "^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:"
300 "*Regexp matching headers to be included in forwarded messages."
301 :group 'message-forwarding
304 (defcustom message-make-forward-subject-function
305 'message-forward-subject-author-subject
306 "*A list of functions that are called to generate a subject header for forwarded messages.
307 The subject generated by the previous function is passed into each
310 The provided functions are:
312 * message-forward-subject-author-subject (Source of article (author or
313 newsgroup)), in brackets followed by the subject
314 * message-forward-subject-fwd (Subject of article with 'Fwd:' prepended
316 :group 'message-forwarding
317 :type '(radio (function-item message-forward-subject-author-subject)
318 (function-item message-forward-subject-fwd)))
320 (defcustom message-wash-forwarded-subjects nil
321 "*If non-nil, try to remove as much old cruft as possible from the subject of messages before generating the new subject of a forward."
322 :group 'message-forwarding
325 (defcustom message-ignored-resent-headers "^Return-receipt\\|^X-Gnus\\|^Gnus-Warning:"
326 "*All headers that match this regexp will be deleted when resending a message."
327 :group 'message-interface
330 (defcustom message-ignored-cited-headers "."
331 "*Delete these headers from the messages you yank."
332 :group 'message-insertion
335 (defcustom message-cancel-message "I am canceling my own article."
336 "Message to be inserted in the cancel message."
337 :group 'message-interface
340 ;; Useful to set in site-init.el
342 (defcustom message-send-mail-function 'message-send-mail-with-sendmail
343 "Function to call to send the current buffer as mail.
344 The headers should be delimited by a line whose contents match the
345 variable `mail-header-separator'.
347 Legal values include `message-send-mail-with-sendmail' (the default),
348 `message-send-mail-with-mh', `message-send-mail-with-qmail' and
350 :type '(radio (function-item message-send-mail-with-sendmail)
351 (function-item message-send-mail-with-mh)
352 (function-item message-send-mail-with-qmail)
353 (function-item smtpmail-send-it)
354 (function :tag "Other"))
355 :group 'message-sending
356 :group 'message-mail)
358 (defcustom message-send-news-function 'message-send-news
359 "Function to call to send the current buffer as news.
360 The headers should be delimited by a line whose contents match the
361 variable `mail-header-separator'."
362 :group 'message-sending
366 (defcustom message-reply-to-function nil
367 "Function that should return a list of headers.
368 This function should pick out addresses from the To, Cc, and From headers
369 and respond with new To and Cc headers."
370 :group 'message-interface
373 (defcustom message-wide-reply-to-function nil
374 "Function that should return a list of headers.
375 This function should pick out addresses from the To, Cc, and From headers
376 and respond with new To and Cc headers."
377 :group 'message-interface
380 (defcustom message-followup-to-function nil
381 "Function that should return a list of headers.
382 This function should pick out addresses from the To, Cc, and From headers
383 and respond with new To and Cc headers."
384 :group 'message-interface
387 (defcustom message-use-followup-to 'ask
388 "*Specifies what to do with Followup-To header.
389 If nil, always ignore the header. If it is t, use its value, but
390 query before using the \"poster\" value. If it is the symbol `ask',
391 always query the user whether to use the value. If it is the symbol
392 `use', always use the value."
393 :group 'message-interface
394 :type '(choice (const :tag "ignore" nil)
398 ;; stuff relating to broken sendmail in MMDF
399 (defcustom message-sendmail-f-is-evil nil
400 "*Non-nil means that \"-f username\" should not be added to the sendmail
401 command line, because it is even more evil than leaving it out."
402 :group 'message-sending
405 ;; qmail-related stuff
406 (defcustom message-qmail-inject-program "/var/qmail/bin/qmail-inject"
407 "Location of the qmail-inject program."
408 :group 'message-sending
411 (defcustom message-qmail-inject-args nil
412 "Arguments passed to qmail-inject programs.
413 This should be a list of strings, one string for each argument.
415 For e.g., if you wish to set the envelope sender address so that bounces
416 go to the right place or to deal with listserv's usage of that address, you
417 might set this variable to '(\"-f\" \"you@some.where\")."
418 :group 'message-sending
419 :type '(repeat string))
421 (defvar gnus-post-method)
422 (defvar gnus-select-method)
423 (defcustom message-post-method
424 (cond ((and (boundp 'gnus-post-method)
425 (listp gnus-post-method)
428 ((boundp 'gnus-select-method)
431 "*Method used to post news.
432 Note that when posting from inside Gnus, for instance, this
433 variable isn't used."
435 :group 'message-sending
436 ;; This should be the `gnus-select-method' widget, but that might
437 ;; create a dependence to `gnus.el'.
440 (defcustom message-generate-headers-first nil
441 "*If non-nil, generate all possible headers before composing."
442 :group 'message-headers
445 (defcustom message-setup-hook nil
446 "Normal hook, run each time a new outgoing message is initialized.
447 The function `message-setup' runs this hook."
448 :group 'message-various
451 (defcustom message-cancel-hook nil
452 "Hook run when cancelling articles."
453 :group 'message-various
456 (defcustom message-signature-setup-hook nil
457 "Normal hook, run each time a new outgoing message is initialized.
458 It is run after the headers have been inserted and before
459 the signature is inserted."
460 :group 'message-various
463 (defcustom message-mode-hook nil
464 "Hook run in message mode buffers."
465 :group 'message-various
468 (defcustom message-header-hook nil
469 "Hook run in a message mode buffer narrowed to the headers."
470 :group 'message-various
473 (defcustom message-header-setup-hook nil
474 "Hook called narrowed to the headers when setting up a message buffer."
475 :group 'message-various
479 (defcustom message-citation-line-function 'message-insert-citation-line
480 "*Function called to insert the \"Whomever writes:\" line."
482 :group 'message-insertion)
485 (defcustom message-yank-prefix "> "
486 "*Prefix inserted on the lines of yanked messages."
488 :group 'message-insertion)
490 (defcustom message-indentation-spaces 3
491 "*Number of spaces to insert at the beginning of each cited line.
492 Used by `message-yank-original' via `message-yank-cite'."
493 :group 'message-insertion
497 (defcustom message-cite-function 'message-cite-original
498 "*Function for citing an original message.
499 Predefined functions include `message-cite-original' and
500 `message-cite-original-without-signature'.
501 Note that `message-cite-original' uses `mail-citation-hook' if that is non-nil."
502 :type '(radio (function-item message-cite-original)
503 (function-item sc-cite-original)
504 (function :tag "Other"))
505 :group 'message-insertion)
508 (defcustom message-indent-citation-function 'message-indent-citation
509 "*Function for modifying a citation just inserted in the mail buffer.
510 This can also be a list of functions. Each function can find the
511 citation between (point) and (mark t). And each function should leave
512 point and mark around the citation text as modified."
514 :group 'message-insertion)
516 (defvar message-abbrevs-loaded nil)
519 (defcustom message-signature t
520 "*String to be inserted at the end of the message buffer.
521 If t, the `message-signature-file' file will be inserted instead.
522 If a function, the result from the function will be used instead.
523 If a form, the result from the form will be used instead."
525 :group 'message-insertion)
528 (defcustom message-signature-file "~/.signature"
529 "*File containing the text inserted at end of message buffer."
531 :group 'message-insertion)
533 (defcustom message-distribution-function nil
534 "*Function called to return a Distribution header."
536 :group 'message-headers
539 (defcustom message-expires 14
540 "Number of days before your article expires."
542 :group 'message-headers
543 :link '(custom-manual "(message)News Headers")
546 (defcustom message-user-path nil
547 "If nil, use the NNTP server name in the Path header.
548 If stringp, use this; if non-nil, use no host name (user name only)."
550 :group 'message-headers
551 :link '(custom-manual "(message)News Headers")
552 :type '(choice (const :tag "nntp" nil)
554 (sexp :tag "none" :format "%t" t)))
556 (defvar message-reply-buffer nil)
557 (defvar message-reply-headers nil)
558 (defvar message-newsreader nil)
559 (defvar message-mailer nil)
560 (defvar message-sent-message-via nil)
561 (defvar message-checksum nil)
562 (defvar message-send-actions nil
563 "A list of actions to be performed upon successful sending of a message.")
564 (defvar message-exit-actions nil
565 "A list of actions to be performed upon exiting after sending a message.")
566 (defvar message-kill-actions nil
567 "A list of actions to be performed before killing a message buffer.")
568 (defvar message-postpone-actions nil
569 "A list of actions to be performed after postponing a message.")
571 (define-widget 'message-header-lines 'text
572 "All header lines must be LFD terminated."
575 :error "All header lines must be newline terminated")
577 (defcustom message-default-headers ""
578 "*A string containing header lines to be inserted in outgoing messages.
579 It is inserted before you edit the message, so you can edit or delete
581 :group 'message-headers
582 :type 'message-header-lines)
584 (defcustom message-default-mail-headers ""
585 "*A string of header lines to be inserted in outgoing mails."
586 :group 'message-headers
588 :type 'message-header-lines)
590 (defcustom message-default-news-headers ""
591 "*A string of header lines to be inserted in outgoing news
593 :group 'message-headers
595 :type 'message-header-lines)
597 ;; Note: could use /usr/ucb/mail instead of sendmail;
598 ;; options -t, and -v if not interactive.
599 (defcustom message-mailer-swallows-blank-line
600 (if (and (string-match "sparc-sun-sunos\\(\\'\\|[^5]\\)"
601 system-configuration)
602 (file-readable-p "/etc/sendmail.cf")
603 (let ((buffer (get-buffer-create " *temp*")))
607 (insert-file-contents "/etc/sendmail.cf")
608 (goto-char (point-min))
609 (let ((case-fold-search nil))
610 (re-search-forward "^OR\\>" nil t)))
611 (kill-buffer buffer))))
612 ;; According to RFC822, "The field-name must be composed of printable
613 ;; ASCII characters (i. e., characters that have decimal values between
614 ;; 33 and 126, except colon)", i. e., any chars except ctl chars,
616 '(looking-at "[ \t]\\|[][!\"#$%&'()*+,-./0-9;<=>?@A-Z\\\\^_`a-z{|}~]+:"))
617 "*Set this non-nil if the system's mailer runs the header and body together.
618 \(This problem exists on Sunos 4 when sendmail is run in remote mode.)
619 The value should be an expression to test whether the problem will
621 :group 'message-sending
624 ;; Ignore errors in case this is used in Emacs 19.
625 ;; Don't use ignore-errors because this is copied into loaddefs.el.
628 (define-mail-user-agent 'message-user-agent
629 'message-mail 'message-send-and-exit
630 'message-kill-buffer 'message-send-hook)
633 (defvar message-mh-deletable-headers '(Message-ID Date Lines Sender)
634 "If non-nil, delete the deletable headers before feeding to mh.")
636 (defvar message-send-method-alist
637 '((news message-news-p message-send-via-news)
638 (mail message-mail-p message-send-via-mail))
639 "Alist of ways to send outgoing messages.
640 Each element has the form
642 \(TYPE PREDICATE FUNCTION)
644 where TYPE is a symbol that names the method; PREDICATE is a function
645 called without any parameters to determine whether the message is
646 a message of type TYPE; and FUNCTION is a function to be called if
647 PREDICATE returns non-nil. FUNCTION is called with one parameter --
650 (defvar message-mail-alias-type 'abbrev
651 "*What alias expansion type to use in Message buffers.
652 The default is `abbrev', which uses mailabbrev. nil switches
655 (defcustom message-auto-save-directory
656 (nnheader-concat message-directory "drafts/")
657 "*Directory where Message auto-saves buffers if Gnus isn't running.
658 If nil, Message won't auto-save."
659 :group 'message-buffers
662 (defcustom message-buffer-naming-style 'unique
663 "*The way new message buffers are named.
664 Valid valued are `unique' and `unsent'."
665 :group 'message-buffers
666 :type '(choice (const :tag "unique" unique)
667 (const :tag "unsent" unsent)))
669 (defcustom message-default-charset nil
670 "Default charset used in non-MULE XEmacsen.")
672 ;;; Internal variables.
673 ;;; Well, not really internal.
675 (defvar message-mode-syntax-table
676 (let ((table (copy-syntax-table text-mode-syntax-table)))
677 (modify-syntax-entry ?% ". " table)
678 (modify-syntax-entry ?> ". " table)
679 (modify-syntax-entry ?< ". " table)
681 "Syntax table used while in Message mode.")
683 (defvar message-mode-abbrev-table text-mode-abbrev-table
684 "Abbrev table used in Message mode buffers.
685 Defaults to `text-mode-abbrev-table'.")
686 (defgroup message-headers nil
688 :link '(custom-manual "(message)Variables")
691 (defface message-header-to-face
694 (:foreground "green2" :bold t))
697 (:foreground "MidnightBlue" :bold t))
699 (:bold t :italic t)))
700 "Face used for displaying From headers."
701 :group 'message-faces)
703 (defface message-header-cc-face
706 (:foreground "green4" :bold t))
709 (:foreground "MidnightBlue"))
712 "Face used for displaying Cc headers."
713 :group 'message-faces)
715 (defface message-header-subject-face
718 (:foreground "green3"))
721 (:foreground "navy blue" :bold t))
724 "Face used for displaying subject headers."
725 :group 'message-faces)
727 (defface message-header-newsgroups-face
730 (:foreground "yellow" :bold t :italic t))
733 (:foreground "blue4" :bold t :italic t))
735 (:bold t :italic t)))
736 "Face used for displaying newsgroups headers."
737 :group 'message-faces)
739 (defface message-header-other-face
742 (:foreground "#b00000"))
745 (:foreground "steel blue"))
747 (:bold t :italic t)))
748 "Face used for displaying newsgroups headers."
749 :group 'message-faces)
751 (defface message-header-name-face
754 (:foreground "DarkGreen"))
757 (:foreground "cornflower blue"))
760 "Face used for displaying header names."
761 :group 'message-faces)
763 (defface message-header-xheader-face
766 (:foreground "blue"))
769 (:foreground "blue"))
772 "Face used for displaying X-Header headers."
773 :group 'message-faces)
775 (defface message-separator-face
778 (:foreground "blue3"))
781 (:foreground "brown"))
784 "Face used for displaying the separator."
785 :group 'message-faces)
787 (defface message-cited-text-face
796 "Face used for displaying cited text names."
797 :group 'message-faces)
799 (defface message-mml-face
802 (:foreground "ForestGreen"))
805 (:foreground "ForestGreen"))
808 "Face used for displaying MML."
809 :group 'message-faces)
811 (defvar message-font-lock-keywords
812 (let* ((cite-prefix "A-Za-z")
813 (cite-suffix (concat cite-prefix "0-9_.@-"))
814 (content "[ \t]*\\(.+\\(\n[ \t].*\\)*\\)"))
815 `((,(concat "^\\([Tt]o:\\)" content)
816 (1 'message-header-name-face)
817 (2 'message-header-to-face nil t))
818 (,(concat "^\\(^[GBF]?[Cc][Cc]:\\|^[Rr]eply-[Tt]o:\\)" content)
819 (1 'message-header-name-face)
820 (2 'message-header-cc-face nil t))
821 (,(concat "^\\([Ss]ubject:\\)" content)
822 (1 'message-header-name-face)
823 (2 'message-header-subject-face nil t))
824 (,(concat "^\\([Nn]ewsgroups:\\|Followup-[Tt]o:\\)" content)
825 (1 'message-header-name-face)
826 (2 'message-header-newsgroups-face nil t))
827 (,(concat "^\\([A-Z][^: \n\t]+:\\)" content)
828 (1 'message-header-name-face)
829 (2 'message-header-other-face nil t))
830 (,(concat "^\\(X-[A-Za-z0-9-]+\\|In-Reply-To\\):" content)
831 (1 'message-header-name-face)
832 (2 'message-header-name-face))
833 ,@(if (and mail-header-separator
834 (not (equal mail-header-separator "")))
835 `((,(concat "^\\(" (regexp-quote mail-header-separator) "\\)$")
836 1 'message-separator-face))
839 "\\([" cite-prefix "]+[" cite-suffix "]*\\)?"
841 (0 'message-cited-text-face))
842 ("<#/?\\(multipart\\|part\\|external\\).*>"
843 (0 'message-mml-face))))
844 "Additional expressions to highlight in Message mode.")
846 ;; XEmacs does it like this. For Emacs, we have to set the
847 ;; `font-lock-defaults' buffer-local variable.
848 (put 'message-mode 'font-lock-defaults '(message-font-lock-keywords t))
850 (defvar message-face-alist
851 '((bold . bold-region)
852 (underline . underline-region)
853 (default . (lambda (b e)
855 (ununderline-region b e))))
856 "Alist of mail and news faces for facemenu.
857 The cdr of ech entry is a function for applying the face to a region.")
859 (defcustom message-send-hook nil
860 "Hook run before sending messages."
861 :group 'message-various
862 :options '(ispell-message)
865 (defcustom message-send-mail-hook nil
866 "Hook run before sending mail messages."
867 :group 'message-various
870 (defcustom message-send-news-hook nil
871 "Hook run before sending news messages."
872 :group 'message-various
875 (defcustom message-sent-hook nil
876 "Hook run after sending messages."
877 :group 'message-various
880 (defvar message-send-coding-system 'binary
881 "Coding system to encode outgoing mail.")
883 (defvar message-draft-coding-system
885 ((not (fboundp 'coding-system-p)) nil)
886 ((coding-system-p 'emacs-mule) 'emacs-mule)
887 ((coding-system-p 'escape-quoted) 'escape-quoted)
888 ((coding-system-p 'no-conversion) 'no-conversion)
890 "Coding system to compose mail.")
892 ;;; Internal variables.
894 (defvar message-buffer-list nil)
895 (defvar message-this-is-news nil)
896 (defvar message-this-is-mail nil)
897 (defvar message-draft-article nil)
898 (defvar message-mime-part nil)
899 (defvar message-posting-charset nil)
901 ;; Byte-compiler warning
902 (defvar gnus-active-hashtb)
903 (defvar gnus-read-active-file)
905 ;;; Regexp matching the delimiter of messages in UNIX mail format
906 ;;; (UNIX From lines), minus the initial ^. It should be a copy
907 ;;; of rmail.el's rmail-unix-mail-delimiter.
908 (defvar message-unix-mail-delimiter
909 (let ((time-zone-regexp
910 (concat "\\([A-Z]?[A-Z]?[A-Z][A-Z]\\( DST\\)?"
911 "\\|[-+]?[0-9][0-9][0-9][0-9]"
917 ;; Many things can happen to an RFC 822 mailbox before it is put into
918 ;; a `From' line. The leading phrase can be stripped, e.g.
919 ;; `Joe <@w.x:joe@y.z>' -> `<@w.x:joe@y.z>'. The <> can be stripped, e.g.
920 ;; `<@x.y:joe@y.z>' -> `@x.y:joe@y.z'. Everything starting with a CRLF
921 ;; can be removed, e.g.
922 ;; From: joe@y.z (Joe K
924 ;; can yield `From joe@y.z (Joe K Fri Mar 22 08:11:15 1996', and
927 ;; can yield `From Joe User Fri Mar 22 08:11:15 1996'.
928 ;; The mailbox can be removed or be replaced by white space, e.g.
929 ;; From: "Joe User"{space}{tab}
931 ;; can yield `From {space}{tab} Fri Mar 22 08:11:15 1996',
932 ;; where {space} and {tab} represent the Ascii space and tab characters.
933 ;; We want to match the results of any of these manglings.
934 ;; The following regexp rejects names whose first characters are
935 ;; obviously bogus, but after that anything goes.
936 "\\([^\0-\b\n-\r\^?].*\\)? "
938 ;; The time the message was sent.
939 "\\([^\0-\r \^?]+\\) +" ; day of the week
940 "\\([^\0-\r \^?]+\\) +" ; month
941 "\\([0-3]?[0-9]\\) +" ; day of month
942 "\\([0-2][0-9]:[0-5][0-9]\\(:[0-6][0-9]\\)?\\) *" ; time of day
944 ;; Perhaps a time zone, specified by an abbreviation, or by a
949 " \\([0-9][0-9]+\\) *"
951 ;; On some systems the time zone can appear after the year, too.
955 "\\(remote from .*\\)?"
958 "Regexp matching the delimiter of messages in UNIX mail format.")
960 (defvar message-unsent-separator
961 (concat "^ *---+ +Unsent message follows +---+ *$\\|"
962 "^ *---+ +Returned message +---+ *$\\|"
963 "^Start of returned message$\\|"
964 "^ *---+ +Original message +---+ *$\\|"
965 "^ *--+ +begin message +--+ *$\\|"
966 "^ *---+ +Original message follows +---+ *$\\|"
967 "^|? *---+ +Message text follows: +---+ *|?$")
968 "A regexp that matches the separator before the text of a failed message.")
970 (defvar message-header-format-alist
972 (To . message-fill-address)
973 (Cc . message-fill-address)
984 (References . message-shorten-references)
986 "Alist used for formatting headers.")
989 (autoload 'message-setup-toolbar "messagexmas")
990 (autoload 'mh-new-draft-name "mh-comp")
991 (autoload 'mh-send-letter "mh-comp")
992 (autoload 'gnus-point-at-eol "gnus-util")
993 (autoload 'gnus-point-at-bol "gnus-util")
994 (autoload 'gnus-output-to-mail "gnus-util")
995 (autoload 'mail-abbrev-in-expansion-header-p "mailabbrev")
996 (autoload 'nndraft-request-associate-buffer "nndraft")
997 (autoload 'nndraft-request-expire-articles "nndraft")
998 (autoload 'gnus-open-server "gnus-int")
999 (autoload 'gnus-request-post "gnus-int")
1000 (autoload 'gnus-alive-p "gnus-util")
1001 (autoload 'rmail-output "rmail"))
1006 ;;; Utility functions.
1009 (defmacro message-y-or-n-p (question show &rest text)
1010 "Ask QUESTION, displaying the rest of the arguments in a temp. buffer if SHOW"
1011 `(message-talkative-question 'y-or-n-p ,question ,show ,@text))
1013 ;; Delete the current line (and the next N lines.);
1014 (defmacro message-delete-line (&optional n)
1015 `(delete-region (progn (beginning-of-line) (point))
1016 (progn (forward-line ,(or n 1)) (point))))
1018 (defun message-tokenize-header (header &optional separator)
1019 "Split HEADER into a list of header elements.
1020 \",\" is used as the separator."
1023 (let ((regexp (format "[%s]+" (or separator ",")))
1028 (message-set-work-buffer)
1030 (goto-char (point-min))
1035 (cond ((and (> (point) beg)
1037 (and (looking-at regexp)
1040 (push (buffer-substring beg (point)) elems)
1041 (setq beg (match-end 0)))
1042 ((eq (char-after) ?\")
1043 (setq quoted (not quoted)))
1044 ((and (eq (char-after) ?\()
1047 ((and (eq (char-after) ?\))
1050 (nreverse elems)))))
1052 (defun message-mail-file-mbox-p (file)
1053 "Say whether FILE looks like a Unix mbox file."
1054 (when (and (file-exists-p file)
1055 (file-readable-p file)
1056 (file-regular-p file))
1058 (nnheader-insert-file-contents file)
1059 (goto-char (point-min))
1060 (looking-at message-unix-mail-delimiter))))
1062 (defun message-fetch-field (header &optional not-all)
1063 "The same as `mail-fetch-field', only remove all newlines."
1064 (let* ((inhibit-point-motion-hooks t)
1065 (value (mail-fetch-field header nil (not not-all))))
1067 (while (string-match "\n[\t ]+" value)
1068 (setq value (replace-match " " t t value)))
1069 ;; We remove all text props.delete-region
1070 (format "%s" value))))
1072 (defun message-narrow-to-field ()
1073 "Narrow the buffer to the header on the current line."
1079 (if (re-search-forward "^[^ \n\t]" nil t)
1084 (goto-char (point-min)))
1086 (defun message-add-header (&rest headers)
1087 "Add the HEADERS to the message header, skipping those already present."
1090 (unless (string-match "^\\([^:]+\\):[ \t]*[^ \t]" (car headers))
1091 (error "Invalid header `%s'" (car headers)))
1092 (setq hclean (match-string 1 (car headers)))
1094 (message-narrow-to-headers)
1095 (unless (re-search-forward (concat "^" (regexp-quote hclean) ":") nil t)
1096 (insert (car headers) ?\n))))
1097 (setq headers (cdr headers))))
1099 (defun message-fetch-reply-field (header)
1100 "Fetch FIELD from the message we're replying to."
1101 (when (and message-reply-buffer
1102 (buffer-name message-reply-buffer))
1104 (set-buffer message-reply-buffer)
1105 (message-fetch-field header))))
1107 (defun message-set-work-buffer ()
1108 (if (get-buffer " *message work*")
1110 (set-buffer " *message work*")
1112 (set-buffer (get-buffer-create " *message work*"))
1113 (kill-all-local-variables)
1114 (mm-enable-multibyte)))
1116 (defun message-functionp (form)
1117 "Return non-nil if FORM is funcallable."
1118 (or (and (symbolp form) (fboundp form))
1119 (and (listp form) (eq (car form) 'lambda))
1120 (byte-code-function-p form)))
1122 (defun message-strip-subject-re (subject)
1123 "Remove \"Re:\" from subject lines."
1124 (if (string-match message-subject-re-regexp subject)
1125 (substring subject (match-end 0))
1128 (defun message-remove-header (header &optional is-regexp first reverse)
1129 "Remove HEADER in the narrowed buffer.
1130 If REGEXP, HEADER is a regular expression.
1131 If FIRST, only remove the first instance of the header.
1132 Return the number of headers removed."
1133 (goto-char (point-min))
1134 (let ((regexp (if is-regexp header (concat "^" (regexp-quote header) ":")))
1136 (case-fold-search t)
1138 (while (and (not (eobp))
1141 (not (looking-at regexp))
1142 (looking-at regexp))
1149 ;; There might be a continuation header, so we have to search
1150 ;; until we find a new non-continuation line.
1153 (if (re-search-forward "^[^ \t]" nil t)
1154 (goto-char (match-beginning 0))
1157 (if (re-search-forward "^[^ \t]" nil t)
1158 (goto-char (match-beginning 0))
1159 (goto-char (point-max)))))
1162 (defun message-remove-first-header (header)
1163 "Remove the first instance of HEADER if there is more than one."
1165 (regexp (concat "^" (regexp-quote header) ":")))
1167 (goto-char (point-min))
1168 (while (re-search-forward regexp nil t)
1171 (message-remove-header header nil t)
1174 (defun message-narrow-to-headers ()
1175 "Narrow the buffer to the head of the message."
1178 (goto-char (point-min))
1179 (if (re-search-forward
1180 (concat "^" (regexp-quote mail-header-separator) "\n") nil t)
1183 (goto-char (point-min)))
1185 (defun message-narrow-to-head ()
1186 "Narrow the buffer to the head of the message.
1187 Point is left at the beginning of the narrowed-to region."
1190 (goto-char (point-min))
1191 (if (search-forward "\n\n" nil 1)
1194 (goto-char (point-min)))
1196 (defun message-narrow-to-headers-or-head ()
1197 "Narrow the buffer to the head of the message."
1200 (goto-char (point-min))
1203 (concat "^" (regexp-quote mail-header-separator) "\n") nil t)
1204 (match-beginning 0))
1205 ((search-forward "\n\n" nil t)
1209 (goto-char (point-min)))
1211 (defun message-news-p ()
1212 "Say whether the current buffer contains a news message."
1213 (and (not message-this-is-mail)
1214 (or message-this-is-news
1217 (message-narrow-to-headers)
1218 (and (message-fetch-field "newsgroups")
1219 (not (message-fetch-field "posted-to"))))))))
1221 (defun message-mail-p ()
1222 "Say whether the current buffer contains a mail message."
1223 (and (not message-this-is-news)
1224 (or message-this-is-mail
1227 (message-narrow-to-headers)
1228 (or (message-fetch-field "to")
1229 (message-fetch-field "cc")
1230 (message-fetch-field "bcc")))))))
1232 (defun message-next-header ()
1233 "Go to the beginning of the next header."
1235 (or (eobp) (forward-char 1))
1236 (not (if (re-search-forward "^[^ \t]" nil t)
1238 (goto-char (point-max)))))
1240 (defun message-sort-headers-1 ()
1241 "Sort the buffer as headers using `message-rank' text props."
1242 (goto-char (point-min))
1244 nil 'message-next-header
1246 (message-next-header)
1250 (or (get-text-property (point) 'message-rank)
1253 (defun message-sort-headers ()
1254 "Sort the headers of the current message according to `message-header-format-alist'."
1258 (let ((max (1+ (length message-header-format-alist)))
1260 (message-narrow-to-headers)
1261 (while (re-search-forward "^[^ \n]+:" nil t)
1263 (match-beginning 0) (1+ (match-beginning 0))
1265 (if (setq rank (length (memq (assq (intern (buffer-substring
1267 (1- (match-end 0))))
1268 message-header-format-alist)
1269 message-header-format-alist)))
1272 (message-sort-headers-1))))
1282 (defvar message-mode-map nil)
1284 (unless message-mode-map
1285 (setq message-mode-map (make-keymap))
1286 (set-keymap-parent message-mode-map text-mode-map)
1287 (define-key message-mode-map "\C-c?" 'describe-mode)
1289 (define-key message-mode-map "\C-c\C-f\C-t" 'message-goto-to)
1290 (define-key message-mode-map "\C-c\C-f\C-b" 'message-goto-bcc)
1291 (define-key message-mode-map "\C-c\C-f\C-w" 'message-goto-fcc)
1292 (define-key message-mode-map "\C-c\C-f\C-c" 'message-goto-cc)
1293 (define-key message-mode-map "\C-c\C-f\C-s" 'message-goto-subject)
1294 (define-key message-mode-map "\C-c\C-f\C-r" 'message-goto-reply-to)
1295 (define-key message-mode-map "\C-c\C-f\C-n" 'message-goto-newsgroups)
1296 (define-key message-mode-map "\C-c\C-f\C-d" 'message-goto-distribution)
1297 (define-key message-mode-map "\C-c\C-f\C-f" 'message-goto-followup-to)
1298 (define-key message-mode-map "\C-c\C-f\C-k" 'message-goto-keywords)
1299 (define-key message-mode-map "\C-c\C-f\C-u" 'message-goto-summary)
1300 (define-key message-mode-map "\C-c\C-b" 'message-goto-body)
1301 (define-key message-mode-map "\C-c\C-i" 'message-goto-signature)
1303 (define-key message-mode-map "\C-c\C-t" 'message-insert-to)
1304 (define-key message-mode-map "\C-c\C-n" 'message-insert-newsgroups)
1306 (define-key message-mode-map "\C-c\C-y" 'message-yank-original)
1307 (define-key message-mode-map "\C-c\C-q" 'message-fill-yanked-message)
1308 (define-key message-mode-map "\C-c\C-w" 'message-insert-signature)
1309 (define-key message-mode-map "\C-c\M-h" 'message-insert-headers)
1310 (define-key message-mode-map "\C-c\C-r" 'message-caesar-buffer-body)
1311 (define-key message-mode-map "\C-c\C-o" 'message-sort-headers)
1312 (define-key message-mode-map "\C-c\M-r" 'message-rename-buffer)
1314 (define-key message-mode-map "\C-c\C-c" 'message-send-and-exit)
1315 (define-key message-mode-map "\C-c\C-s" 'message-send)
1316 (define-key message-mode-map "\C-c\C-k" 'message-kill-buffer)
1317 (define-key message-mode-map "\C-c\C-d" 'message-dont-send)
1319 (define-key message-mode-map "\C-c\C-e" 'message-elide-region)
1320 (define-key message-mode-map "\C-c\C-v" 'message-delete-not-region)
1321 (define-key message-mode-map "\C-c\C-z" 'message-kill-to-signature)
1322 (define-key message-mode-map "\M-\r" 'message-newline-and-reformat)
1324 (define-key message-mode-map "\C-c\C-a" 'message-mime-attach-file)
1325 (define-key message-mode-map "\C-c\C-m\C-a" 'message-mime-attach-file)
1326 (define-key message-mode-map "\C-c\C-m\C-e" 'message-mime-attach-external)
1327 (define-key message-mode-map "\C-c\C-m\C-q" 'mml-quote-region)
1329 (define-key message-mode-map "\t" 'message-tab))
1332 message-mode-menu message-mode-map "Message Menu."
1334 ["Sort Headers" message-sort-headers t]
1335 ["Yank Original" message-yank-original t]
1336 ["Fill Yanked Message" message-fill-yanked-message t]
1337 ["Insert Signature" message-insert-signature t]
1338 ["Caesar (rot13) Message" message-caesar-buffer-body t]
1339 ["Caesar (rot13) Region" message-caesar-region (mark t)]
1340 ["Elide Region" message-elide-region (mark t)]
1341 ["Delete Outside Region" message-delete-not-region (mark t)]
1342 ["Kill To Signature" message-kill-to-signature t]
1343 ["Newline and Reformat" message-newline-and-reformat t]
1344 ["Rename buffer" message-rename-buffer t]
1345 ["Spellcheck" ispell-message t]
1347 ["Send Message" message-send-and-exit t]
1348 ["Abort Message" message-dont-send t]
1349 ["Kill Message" message-kill-buffer t]))
1352 message-mode-field-menu message-mode-map ""
1354 ["Fetch To" message-insert-to t]
1355 ["Fetch Newsgroups" message-insert-newsgroups t]
1357 ["To" message-goto-to t]
1358 ["Subject" message-goto-subject t]
1359 ["Cc" message-goto-cc t]
1360 ["Reply-To" message-goto-reply-to t]
1361 ["Summary" message-goto-summary t]
1362 ["Keywords" message-goto-keywords t]
1363 ["Newsgroups" message-goto-newsgroups t]
1364 ["Followup-To" message-goto-followup-to t]
1365 ["Distribution" message-goto-distribution t]
1366 ["Body" message-goto-body t]
1367 ["Signature" message-goto-signature t]))
1369 (defvar facemenu-add-face-function)
1370 (defvar facemenu-remove-face-function)
1373 (defun message-mode ()
1374 "Major mode for editing mail and news to be sent.
1375 Like Text Mode but with these additional commands:
1376 C-c C-s message-send (send the message) C-c C-c message-send-and-exit
1377 C-c C-f move to a header field (and create it if there isn't):
1378 C-c C-f C-t move to To C-c C-f C-s move to Subject
1379 C-c C-f C-c move to Cc C-c C-f C-b move to Bcc
1380 C-c C-f C-w move to Fcc C-c C-f C-r move to Reply-To
1381 C-c C-f C-u move to Summary C-c C-f C-n move to Newsgroups
1382 C-c C-f C-k move to Keywords C-c C-f C-d move to Distribution
1383 C-c C-f C-f move to Followup-To
1384 C-c C-t message-insert-to (add a To header to a news followup)
1385 C-c C-n message-insert-newsgroups (add a Newsgroup header to a news reply)
1386 C-c C-b message-goto-body (move to beginning of message text).
1387 C-c C-i message-goto-signature (move to the beginning of the signature).
1388 C-c C-w message-insert-signature (insert `message-signature-file' file).
1389 C-c C-y message-yank-original (insert current message, if any).
1390 C-c C-q message-fill-yanked-message (fill what was yanked).
1391 C-c C-e message-elide-region (elide the text between point and mark).
1392 C-c C-v message-delete-not-region (remove the text outside the region).
1393 C-c C-z message-kill-to-signature (kill the text up to the signature).
1394 C-c C-r message-caesar-buffer-body (rot13 the message body)."
1396 (kill-all-local-variables)
1397 (set (make-local-variable 'message-reply-buffer) nil)
1398 (make-local-variable 'message-send-actions)
1399 (make-local-variable 'message-exit-actions)
1400 (make-local-variable 'message-kill-actions)
1401 (make-local-variable 'message-postpone-actions)
1402 (make-local-variable 'message-draft-article)
1403 (make-local-hook 'kill-buffer-hook)
1404 (set-syntax-table message-mode-syntax-table)
1405 (use-local-map message-mode-map)
1406 (setq local-abbrev-table message-mode-abbrev-table)
1407 (setq major-mode 'message-mode)
1408 (setq mode-name "Message")
1409 (setq buffer-offer-save t)
1410 (make-local-variable 'facemenu-add-face-function)
1411 (make-local-variable 'facemenu-remove-face-function)
1412 (setq facemenu-add-face-function
1414 (let ((face-fun (cdr (assq face message-face-alist))))
1416 (funcall face-fun (point) end)
1417 (error "Face %s not configured for %s mode" face mode-name)))
1419 facemenu-remove-face-function t)
1420 (make-local-variable 'paragraph-separate)
1421 (make-local-variable 'paragraph-start)
1422 ;; `-- ' precedes the signature. `-----' appears at the start of the
1423 ;; lines that delimit forwarded messages.
1424 ;; Lines containing just >= 3 dashes, perhaps after whitespace,
1425 ;; are also sometimes used and should be separators.
1426 (setq paragraph-start
1427 (concat (regexp-quote mail-header-separator)
1428 "$\\|[ \t]*[a-z0-9A-Z]*>+[ \t]*$\\|[ \t]*$\\|"
1431 ;;!!! Uhm... shurely this can't be right?
1432 "[> " (regexp-quote message-yank-prefix) "]+$"))
1433 (setq paragraph-separate paragraph-start)
1434 (make-local-variable 'message-reply-headers)
1435 (setq message-reply-headers nil)
1436 (make-local-variable 'message-newsreader)
1437 (make-local-variable 'message-mailer)
1438 (make-local-variable 'message-post-method)
1439 (set (make-local-variable 'message-sent-message-via) nil)
1440 (set (make-local-variable 'message-checksum) nil)
1441 (set (make-local-variable 'message-mime-part) 0)
1442 ;;(when (fboundp 'mail-hist-define-keys)
1443 ;; (mail-hist-define-keys))
1444 (when (string-match "XEmacs\\|Lucid" emacs-version)
1445 (message-setup-toolbar))
1446 (easy-menu-add message-mode-menu message-mode-map)
1447 (easy-menu-add message-mode-field-menu message-mode-map)
1448 ;; Allow mail alias things.
1449 (when (eq message-mail-alias-type 'abbrev)
1450 (if (fboundp 'mail-abbrevs-setup)
1451 (mail-abbrevs-setup)
1452 (mail-aliases-setup)))
1453 (message-set-auto-save-file-name)
1454 (unless (string-match "XEmacs" emacs-version)
1455 (set (make-local-variable 'font-lock-defaults)
1456 '(message-font-lock-keywords t)))
1457 (make-local-variable 'adaptive-fill-regexp)
1458 (setq adaptive-fill-regexp
1459 (concat "[ \t]*[-a-z0-9A-Z]*>+[ \t]*\\|" adaptive-fill-regexp))
1460 (unless (boundp 'adaptive-fill-first-line-regexp)
1461 (setq adaptive-fill-first-line-regexp nil))
1462 (make-local-variable 'adaptive-fill-first-line-regexp)
1463 (setq adaptive-fill-first-line-regexp
1464 (concat "[ \t]*[-a-z0-9A-Z]*>+[ \t]*\\|"
1465 adaptive-fill-first-line-regexp))
1466 (mm-enable-multibyte)
1467 (run-hooks 'text-mode-hook 'message-mode-hook))
1472 ;;; Message mode commands
1475 ;;; Movement commands
1477 (defun message-goto-to ()
1478 "Move point to the To header."
1480 (message-position-on-field "To"))
1482 (defun message-goto-subject ()
1483 "Move point to the Subject header."
1485 (message-position-on-field "Subject"))
1487 (defun message-goto-cc ()
1488 "Move point to the Cc header."
1490 (message-position-on-field "Cc" "To"))
1492 (defun message-goto-bcc ()
1493 "Move point to the Bcc header."
1495 (message-position-on-field "Bcc" "Cc" "To"))
1497 (defun message-goto-fcc ()
1498 "Move point to the Fcc header."
1500 (message-position-on-field "Fcc" "To" "Newsgroups"))
1502 (defun message-goto-reply-to ()
1503 "Move point to the Reply-To header."
1505 (message-position-on-field "Reply-To" "Subject"))
1507 (defun message-goto-newsgroups ()
1508 "Move point to the Newsgroups header."
1510 (message-position-on-field "Newsgroups"))
1512 (defun message-goto-distribution ()
1513 "Move point to the Distribution header."
1515 (message-position-on-field "Distribution"))
1517 (defun message-goto-followup-to ()
1518 "Move point to the Followup-To header."
1520 (message-position-on-field "Followup-To" "Newsgroups"))
1522 (defun message-goto-keywords ()
1523 "Move point to the Keywords header."
1525 (message-position-on-field "Keywords" "Subject"))
1527 (defun message-goto-summary ()
1528 "Move point to the Summary header."
1530 (message-position-on-field "Summary" "Subject"))
1532 (defun message-goto-body ()
1533 "Move point to the beginning of the message body."
1535 (if (looking-at "[ \t]*\n") (expand-abbrev))
1536 (goto-char (point-min))
1537 (search-forward (concat "\n" mail-header-separator "\n") nil t))
1539 (defun message-goto-eoh ()
1540 "Move point to the end of the headers."
1545 (defun message-goto-signature ()
1546 "Move point to the beginning of the message signature.
1547 If there is no signature in the article, go to the end and
1550 (goto-char (point-min))
1551 (if (re-search-forward message-signature-separator nil t)
1553 (goto-char (point-max))
1558 (defun message-insert-to (&optional force)
1559 "Insert a To header that points to the author of the article being replied to.
1560 If the original author requested not to be sent mail, the function signals
1562 With the prefix argument FORCE, insert the header anyway."
1564 (let ((co (message-fetch-reply-field "mail-copies-to")))
1565 (when (and (null force)
1567 (or (equal (downcase co) "never")
1568 (equal (downcase co) "nobody")))
1569 (error "The user has requested not to have copies sent via mail")))
1570 (when (and (message-position-on-field "To")
1571 (mail-fetch-field "to")
1572 (not (string-match "\\` *\\'" (mail-fetch-field "to"))))
1574 (insert (or (message-fetch-reply-field "reply-to")
1575 (message-fetch-reply-field "from") "")))
1577 (defun message-insert-newsgroups ()
1578 "Insert the Newsgroups header from the article being replied to."
1580 (when (and (message-position-on-field "Newsgroups")
1581 (mail-fetch-field "newsgroups")
1582 (not (string-match "\\` *\\'" (mail-fetch-field "newsgroups"))))
1584 (insert (or (message-fetch-reply-field "newsgroups") "")))
1588 ;;; Various commands
1590 (defun message-delete-not-region (beg end)
1591 "Delete everything in the body of the current message that is outside of the region."
1595 (delete-region (point) (if (not (message-goto-signature))
1601 (delete-region beg (progn (message-goto-body)
1604 (when (message-goto-signature)
1607 (defun message-kill-to-signature ()
1608 "Deletes all text up to the signature."
1610 (let ((point (point)))
1611 (message-goto-signature)
1614 (kill-region point (point))
1618 (defun message-newline-and-reformat ()
1619 "Insert four newlines, and then reformat if inside quoted text."
1621 (let ((point (point))
1625 (setq quoted (looking-at (regexp-quote message-yank-prefix))))
1628 (insert message-yank-prefix))
1629 (fill-paragraph nil)
1633 (defun message-insert-signature (&optional force)
1634 "Insert a signature. See documentation for the `message-signature' variable."
1635 (interactive (list 0))
1638 ((and (null message-signature)
1641 (goto-char (point-max))
1642 (not (re-search-backward message-signature-separator nil t))))
1643 ((and (null message-signature)
1646 ((message-functionp message-signature)
1647 (funcall message-signature))
1648 ((listp message-signature)
1649 (eval message-signature))
1650 (t message-signature)))
1652 (cond ((stringp signature)
1654 ((and (eq t signature)
1655 message-signature-file
1656 (file-exists-p message-signature-file))
1659 (goto-char (point-max))
1660 ;; Insert the signature.
1664 (if (eq signature t)
1665 (insert-file-contents message-signature-file)
1667 (goto-char (point-max))
1668 (or (bolp) (insert "\n")))))
1670 (defun message-elide-region (b e)
1671 "Elide the text between point and mark.
1672 An ellipsis (from `message-elide-elipsis') will be inserted where the
1678 (insert message-elide-elipsis))
1680 (defvar message-caesar-translation-table nil)
1682 (defun message-caesar-region (b e &optional n)
1683 "Caesar rotation of region by N, default 13, for decrypting netnews."
1686 (min (point) (or (mark t) (point)))
1687 (max (point) (or (mark t) (point)))
1688 (when current-prefix-arg
1689 (prefix-numeric-value current-prefix-arg))))
1691 (setq n (if (numberp n) (mod n 26) 13)) ;canonize N
1692 (unless (or (zerop n) ; no action needed for a rot of 0
1693 (= b e)) ; no region to rotate
1694 ;; We build the table, if necessary.
1695 (when (or (not message-caesar-translation-table)
1696 (/= (aref message-caesar-translation-table ?a) (+ ?a n)))
1697 (setq message-caesar-translation-table
1698 (message-make-caesar-translation-table n)))
1699 ;; Then we translate the region. Do it this way to retain
1702 (when (< (char-after b) 255)
1703 (subst-char-in-region
1704 b (1+ b) (char-after b)
1705 (aref message-caesar-translation-table (char-after b))))
1708 (defun message-make-caesar-translation-table (n)
1709 "Create a rot table with offset N."
1711 (table (make-string 256 0)))
1712 (while (< (incf i) 256)
1715 (substring table 0 ?A)
1716 (substring table (+ ?A n) (+ ?A n (- 26 n)))
1717 (substring table ?A (+ ?A n))
1718 (substring table (+ ?A 26) ?a)
1719 (substring table (+ ?a n) (+ ?a n (- 26 n)))
1720 (substring table ?a (+ ?a n))
1721 (substring table (+ ?a 26) 255))))
1723 (defun message-caesar-buffer-body (&optional rotnum)
1724 "Caesar rotates all letters in the current buffer by 13 places.
1725 Used to encode/decode possiblyun offensive messages (commonly in net.jokes).
1726 With prefix arg, specifies the number of places to rotate each letter forward.
1727 Mail and USENET news headers are not rotated."
1728 (interactive (if current-prefix-arg
1729 (list (prefix-numeric-value current-prefix-arg))
1733 (when (message-goto-body)
1734 (narrow-to-region (point) (point-max)))
1735 (message-caesar-region (point-min) (point-max) rotnum))))
1737 (defun message-pipe-buffer-body (program)
1738 "Pipe the message body in the current buffer through PROGRAM."
1741 (when (message-goto-body)
1742 (narrow-to-region (point) (point-max)))
1743 (let ((body (buffer-substring (point-min) (point-max))))
1744 (unless (equal 0 (call-process-region
1745 (point-min) (point-max) program t t))
1747 (message "%s failed." program))))))
1749 (defun message-rename-buffer (&optional enter-string)
1750 "Rename the *message* buffer to \"*message* RECIPIENT\".
1751 If the function is run with a prefix, it will ask for a new buffer
1752 name, rather than giving an automatic name."
1753 (interactive "Pbuffer name: ")
1756 (goto-char (point-min))
1757 (narrow-to-region (point)
1758 (search-forward mail-header-separator nil 'end))
1760 (if (message-news-p) (message-fetch-field "Newsgroups")
1761 (message-fetch-field "To"))
1764 (if (string-match "," mail-to)
1765 (concat (substring mail-to 0 (match-beginning 0)) ", ...")
1767 (name-default (concat "*message* " mail-trimmed-to))
1768 (name (if enter-string
1769 (read-string "New buffer name: " name-default)
1771 (rename-buffer name t)))))
1773 (defun message-fill-yanked-message (&optional justifyp)
1774 "Fill the paragraphs of a message yanked into this one.
1775 Numeric argument means justify as well."
1778 (goto-char (point-min))
1779 (search-forward (concat "\n" mail-header-separator "\n") nil t)
1780 (let ((fill-prefix message-yank-prefix))
1781 (fill-individual-paragraphs (point) (point-max) justifyp t))))
1783 (defun message-indent-citation ()
1784 "Modify text just inserted from a message to be cited.
1785 The inserted text should be the region.
1786 When this function returns, the region is again around the modified text.
1788 Normally, indent each nonblank line `message-indentation-spaces' spaces.
1789 However, if `message-yank-prefix' is non-nil, insert that prefix on each line."
1790 (let ((start (point)))
1791 ;; Remove unwanted headers.
1792 (when message-ignored-cited-headers
1797 (if (search-forward "\n\n" nil t)
1800 (message-remove-header message-ignored-cited-headers t)
1801 (when (= (point-min) (point-max))
1802 (setq all-removed t))
1803 (goto-char (point-max)))
1807 ;; Delete blank lines at the start of the buffer.
1808 (while (and (point-min)
1811 (message-delete-line))
1812 ;; Delete blank lines at the end of the buffer.
1813 (goto-char (point-max))
1816 (while (and (zerop (forward-line -1))
1818 (message-delete-line))
1819 ;; Do the indentation.
1820 (if (null message-yank-prefix)
1821 (indent-rigidly start (mark t) message-indentation-spaces)
1824 (while (< (point) (mark t))
1825 (insert message-yank-prefix)
1829 (defun message-yank-original (&optional arg)
1830 "Insert the message being replied to, if any.
1831 Puts point before the text and mark after.
1832 Normally indents each nonblank line ARG spaces (default 3). However,
1833 if `message-yank-prefix' is non-nil, insert that prefix on each line.
1835 This function uses `message-cite-function' to do the actual citing.
1837 Just \\[universal-argument] as argument means don't indent, insert no
1838 prefix, and don't delete any headers."
1840 (let ((modified (buffer-modified-p)))
1841 (when (and message-reply-buffer
1842 message-cite-function)
1843 (delete-windows-on message-reply-buffer t)
1844 (insert-buffer message-reply-buffer)
1845 (funcall message-cite-function)
1846 (message-exchange-point-and-mark)
1850 (setq message-checksum (message-checksum))))))
1852 (defun message-cite-original-without-signature ()
1853 "Cite function in the standard Message manner."
1854 (let ((start (point))
1857 (when message-indent-citation-function
1858 (if (listp message-indent-citation-function)
1859 message-indent-citation-function
1860 (list message-indent-citation-function)))))
1861 (mml-quote-region start end)
1863 (when (re-search-backward message-signature-separator start t)
1864 ;; Also peel off any blank lines before the signature.
1866 (while (looking-at "^[ \t]*$")
1869 (delete-region (point) end))
1872 (funcall (pop functions)))
1873 (when message-citation-line-function
1876 (funcall message-citation-line-function))))
1878 (defvar mail-citation-hook) ;Compiler directive
1879 (defun message-cite-original ()
1880 "Cite function in the standard Message manner."
1881 (if (and (boundp 'mail-citation-hook)
1883 (run-hooks 'mail-citation-hook)
1884 (let ((start (point))
1887 (when message-indent-citation-function
1888 (if (listp message-indent-citation-function)
1889 message-indent-citation-function
1890 (list message-indent-citation-function)))))
1891 (mml-quote-region start end)
1894 (funcall (pop functions)))
1895 (when message-citation-line-function
1898 (funcall message-citation-line-function)))))
1900 (defun message-insert-citation-line ()
1901 "Function that inserts a simple citation line."
1902 (when message-reply-headers
1903 (insert (mail-header-from message-reply-headers) " writes:\n\n")))
1905 (defun message-position-on-field (header &rest afters)
1906 (let ((case-fold-search t))
1909 (goto-char (point-min))
1912 (concat "^" (regexp-quote mail-header-separator) "$"))
1913 (match-beginning 0)))
1914 (goto-char (point-min))
1915 (if (re-search-forward (concat "^" (regexp-quote header) ":") nil t)
1917 (re-search-forward "^[^ \t]" nil 'move)
1919 (skip-chars-backward "\n")
1922 (not (re-search-forward
1923 (concat "^" (regexp-quote (car afters)) ":")
1927 (re-search-forward "^[^ \t]" nil 'move)
1928 (beginning-of-line))
1929 (insert header ": \n")
1933 (defun message-remove-signature ()
1934 "Remove the signature from the text between point and mark.
1935 The text will also be indented the normal way."
1937 (let ((start (point))
1939 (if (not (re-search-forward message-signature-separator (mark t) t))
1940 ;; No signature here, so we just indent the cited text.
1941 (message-indent-citation)
1942 ;; Find the last non-empty line.
1944 (while (looking-at "[ \t]*$")
1947 (setq mark (set-marker (make-marker) (point)))
1949 (message-indent-citation)
1950 ;; Enable undoing the deletion.
1952 (delete-region mark (mark t))
1953 (set-marker mark nil)))))
1958 ;;; Sending messages
1961 (defun message-send-and-exit (&optional arg)
1962 "Send message like `message-send', then, if no errors, exit from mail buffer."
1964 (let ((buf (current-buffer))
1965 (actions message-exit-actions))
1966 (when (and (message-send arg)
1968 (if message-kill-buffer-on-exit
1971 (when (eq buf (current-buffer))
1972 (message-bury buf)))
1973 (message-do-actions actions)
1976 (defun message-dont-send ()
1977 "Don't send the message you have been editing."
1979 (set-buffer-modified-p t)
1981 (let ((actions message-postpone-actions))
1982 (message-bury (current-buffer))
1983 (message-do-actions actions)))
1985 (defun message-kill-buffer ()
1986 "Kill the current buffer."
1988 (when (or (not (buffer-modified-p))
1989 (yes-or-no-p "Message modified; kill anyway? "))
1990 (let ((actions message-kill-actions))
1991 (setq buffer-file-name nil)
1992 (kill-buffer (current-buffer))
1993 (message-do-actions actions))))
1995 (defun message-bury (buffer)
1996 "Bury this mail buffer."
1997 (let ((newbuf (other-buffer buffer)))
1998 (bury-buffer buffer)
1999 (if (and (fboundp 'frame-parameters)
2000 (cdr (assq 'dedicated (frame-parameters)))
2001 (not (null (delq (selected-frame) (visible-frame-list)))))
2002 (delete-frame (selected-frame))
2003 (switch-to-buffer newbuf))))
2005 (defun message-send (&optional arg)
2006 "Send the message in the current buffer.
2007 If `message-interactive' is non-nil, wait for success indication
2008 or error messages, and inform user.
2009 Otherwise any failure is reported in a message back to
2010 the user from the mailer."
2012 ;; Make it possible to undo the coming changes.
2014 (let ((inhibit-read-only t))
2015 (put-text-property (point-min) (point-max) 'read-only nil))
2016 (message-fix-before-sending)
2017 (run-hooks 'message-send-hook)
2018 (message "Sending...")
2019 (let ((alist message-send-method-alist)
2023 (setq elem (pop alist)))
2024 (when (and (or (not (funcall (cadr elem)))
2025 (and (or (not (memq (car elem)
2026 message-sent-message-via))
2029 "Already sent message via %s; resend? "
2031 (setq success (funcall (caddr elem) arg)))))
2033 (when (and success sent)
2035 ;;(when (fboundp 'mail-hist-put-headers-into-history)
2036 ;; (mail-hist-put-headers-into-history))
2038 (run-hooks 'message-sent-hook))
2039 (message "Sending...done")
2040 ;; Mark the buffer as unmodified and delete auto-save.
2041 (set-buffer-modified-p nil)
2042 (delete-auto-save-file-if-necessary t)
2043 (message-disassociate-draft)
2044 ;; Delete other mail buffers and stuff.
2045 (message-do-send-housekeeping)
2046 (message-do-actions message-send-actions)
2050 (defun message-send-via-mail (arg)
2051 "Send the current message via mail."
2052 (message-send-mail arg))
2054 (defun message-send-via-news (arg)
2055 "Send the current message via news."
2056 (funcall message-send-news-function arg))
2058 (defmacro message-check (type &rest forms)
2059 "Eval FORMS if TYPE is to be checked."
2060 `(or (message-check-element ,type)
2064 (put 'message-check 'lisp-indent-function 1)
2065 (put 'message-check 'edebug-form-spec '(form body))
2067 (defun message-fix-before-sending ()
2068 "Do various things to make the message nice before sending it."
2069 ;; Make sure there's a newline at the end of the message.
2070 (goto-char (point-max))
2073 ;; Delete all invisible text.
2074 (message-check 'invisible-text
2075 (when (text-property-any (point-min) (point-max) 'invisible t)
2076 (put-text-property (point-min) (point-max) 'invisible nil)
2077 (unless (yes-or-no-p "Invisible text found and made visible; continue posting? ")
2078 (error "Invisible text found and made visible")))))
2080 (defun message-add-action (action &rest types)
2081 "Add ACTION to be performed when doing an exit of type TYPES."
2084 (set (setq var (intern (format "message-%s-actions" (pop types))))
2085 (nconc (symbol-value var) (list action))))))
2087 (defun message-do-actions (actions)
2088 "Perform all actions in ACTIONS."
2089 ;; Now perform actions on successful sending.
2093 ;; A simple function.
2094 ((message-functionp (car actions))
2095 (funcall (car actions)))
2096 ;; Something to be evaled.
2098 (eval (car actions)))))
2101 (defun message-send-mail (&optional arg)
2102 (require 'mail-utils)
2103 (let ((tembuf (message-generate-new-buffer-clone-locals " message temp"))
2104 (case-fold-search nil)
2105 (news (message-news-p))
2106 (mailbuf (current-buffer)))
2107 (message-encode-message-body)
2109 (message-narrow-to-headers)
2110 ;; Insert some headers.
2111 (let ((message-deletable-headers
2112 (if news nil message-deletable-headers)))
2113 (message-generate-headers message-required-mail-headers))
2114 (let ((mail-parse-charset message-posting-charset))
2115 (mail-encode-encoded-word-buffer))
2116 ;; Let the user do all of the above.
2117 (run-hooks 'message-header-hook))
2122 ;; Avoid copying text props.
2124 "%s" (save-excursion
2125 (set-buffer mailbuf)
2127 ;; Remove some headers.
2129 (message-narrow-to-headers)
2130 ;; Remove some headers.
2131 (message-remove-header message-ignored-mail-headers t))
2132 (goto-char (point-max))
2133 ;; require one newline at the end.
2134 (or (= (preceding-char) ?\n)
2137 (or (message-fetch-field "cc")
2138 (message-fetch-field "to")))
2139 (message-insert-courtesy-copy))
2140 (funcall message-send-mail-function))
2141 (kill-buffer tembuf))
2142 (set-buffer mailbuf)
2143 (push 'mail message-sent-message-via)))
2145 (defun message-send-mail-with-sendmail ()
2146 "Send off the prepared buffer with sendmail."
2147 (let ((errbuf (if message-interactive
2148 (generate-new-buffer " sendmail errors")
2150 resend-to-addresses delimline)
2151 (let ((case-fold-search t))
2153 (message-narrow-to-headers)
2154 (setq resend-to-addresses (message-fetch-field "resent-to")))
2155 ;; Change header-delimiter to be what sendmail expects.
2156 (goto-char (point-min))
2158 (concat "^" (regexp-quote mail-header-separator) "\n"))
2159 (replace-match "\n")
2161 (setq delimline (point-marker))
2162 (run-hooks 'message-send-mail-hook)
2163 ;; Insert an extra newline if we need it to work around
2164 ;; Sun's bug that swallows newlines.
2165 (goto-char (1+ delimline))
2166 (when (eval message-mailer-swallows-blank-line)
2168 (when message-interactive
2172 (let ((default-directory "/")
2173 (coding-system-for-write message-send-coding-system))
2174 (apply 'call-process-region
2175 (append (list (point-min) (point-max)
2176 (if (boundp 'sendmail-program)
2178 "/usr/lib/sendmail")
2179 nil errbuf nil "-oi")
2180 ;; Always specify who from,
2181 ;; since some systems have broken sendmails.
2182 ;; But some systems are more broken with -f, so
2183 ;; we'll let users override this.
2184 (if (null message-sendmail-f-is-evil)
2185 (list "-f" (user-login-name)))
2186 ;; These mean "report errors by mail"
2187 ;; and "deliver in background".
2188 (if (null message-interactive) '("-oem" "-odb"))
2189 ;; Get the addresses from the message
2190 ;; unless this is a resend.
2191 ;; We must not do that for a resend
2192 ;; because we would find the original addresses.
2193 ;; For a resend, include the specific addresses.
2194 (if resend-to-addresses
2195 (list resend-to-addresses)
2197 (when message-interactive
2200 (goto-char (point-min))
2201 (while (re-search-forward "\n\n* *" nil t)
2202 (replace-match "; "))
2203 (if (not (zerop (buffer-size)))
2204 (error "Sending...failed to %s"
2205 (buffer-substring (point-min) (point-max)))))
2206 (when (bufferp errbuf)
2207 (kill-buffer errbuf)))))
2209 (defun message-send-mail-with-qmail ()
2210 "Pass the prepared message buffer to qmail-inject.
2211 Refer to the documentation for the variable `message-send-mail-function'
2212 to find out how to use this."
2213 ;; replace the header delimiter with a blank line
2214 (goto-char (point-min))
2216 (concat "^" (regexp-quote mail-header-separator) "\n"))
2217 (replace-match "\n")
2218 (run-hooks 'message-send-mail-hook)
2221 (let ((coding-system-for-write message-send-coding-system))
2223 'call-process-region 1 (point-max) message-qmail-inject-program
2225 ;; qmail-inject's default behaviour is to look for addresses on the
2226 ;; command line; if there're none, it scans the headers.
2227 ;; yes, it does The Right Thing w.r.t. Resent-To and it's kin.
2229 ;; in general, ALL of qmail-inject's defaults are perfect for simply
2230 ;; reading a formatted (i. e., at least a To: or Resent-To header)
2231 ;; message from stdin.
2233 ;; qmail also has the advantage of not having been raped by
2234 ;; various vendors, so we don't have to allow for that, either --
2235 ;; compare this with message-send-mail-with-sendmail and weep
2236 ;; for sendmail's lost innocence.
2238 ;; all this is way cool coz it lets us keep the arguments entirely
2239 ;; free for -inject-arguments -- a big win for the user and for us
2240 ;; since we don't have to play that double-guessing game and the user
2241 ;; gets full control (no gestapo'ish -f's, for instance). --sj
2242 message-qmail-inject-args))
2243 ;; qmail-inject doesn't say anything on it's stdout/stderr,
2244 ;; we have to look at the retval instead
2246 (1 (error "qmail-inject reported permanent failure"))
2247 (111 (error "qmail-inject reported transient failure"))
2248 ;; should never happen
2249 (t (error "qmail-inject reported unknown failure"))))
2251 (defun message-send-mail-with-mh ()
2252 "Send the prepared message buffer with mh."
2253 (let ((mh-previous-window-config nil)
2254 (name (mh-new-draft-name)))
2255 (setq buffer-file-name name)
2256 ;; MH wants to generate these headers itself.
2257 (when message-mh-deletable-headers
2258 (let ((headers message-mh-deletable-headers))
2260 (goto-char (point-min))
2261 (and (re-search-forward
2262 (concat "^" (symbol-name (car headers)) ": *") nil t)
2263 (message-delete-line))
2265 (run-hooks 'message-send-mail-hook)
2266 ;; Pass it on to mh.
2269 (defun message-send-news (&optional arg)
2270 (let ((tembuf (message-generate-new-buffer-clone-locals " *message temp*"))
2271 (case-fold-search nil)
2272 (method (if (message-functionp message-post-method)
2273 (funcall message-post-method arg)
2274 message-post-method))
2275 (messbuf (current-buffer))
2276 (message-syntax-checks
2278 (cons '(existing-newsgroups . disabled)
2279 message-syntax-checks)
2280 message-syntax-checks))
2282 (if (not (message-check-news-body-syntax))
2284 (message-encode-message-body)
2286 (message-narrow-to-headers)
2287 ;; Insert some headers.
2288 (message-generate-headers message-required-news-headers)
2289 (let ((mail-parse-charset message-posting-charset))
2290 (mail-encode-encoded-word-buffer))
2291 ;; Let the user do all of the above.
2292 (run-hooks 'message-header-hook))
2293 (message-cleanup-headers)
2294 (if (not (message-check-news-syntax))
2299 (buffer-disable-undo)
2301 ;; Avoid copying text props.
2303 "%s" (save-excursion
2304 (set-buffer messbuf)
2306 ;; Remove some headers.
2308 (message-narrow-to-headers)
2309 ;; Remove some headers.
2310 (message-remove-header message-ignored-news-headers t))
2311 (goto-char (point-max))
2312 ;; require one newline at the end.
2313 (or (= (preceding-char) ?\n)
2315 (let ((case-fold-search t))
2316 ;; Remove the delimiter.
2317 (goto-char (point-min))
2319 (concat "^" (regexp-quote mail-header-separator) "\n"))
2320 (replace-match "\n")
2322 (run-hooks 'message-send-news-hook)
2323 ;;(require (car method))
2324 ;;(funcall (intern (format "%s-open-server" (car method)))
2325 ;;(cadr method) (cddr method))
2327 ;; (funcall (intern (format "%s-request-post" (car method)))
2329 (gnus-open-server method)
2330 (setq result (let ((mail-header-separator ""))
2331 (gnus-request-post method))))
2332 (kill-buffer tembuf))
2333 (set-buffer messbuf)
2335 (push 'news message-sent-message-via)
2336 (message "Couldn't send message via news: %s"
2337 (nnheader-get-report (car method)))
2341 ;;; Header generation & syntax checking.
2344 (defun message-check-element (type)
2345 "Returns non-nil if this type is not to be checked."
2346 (if (eq message-syntax-checks 'dont-check-for-anything-just-trust-me)
2348 (let ((able (assq type message-syntax-checks)))
2350 (eq (cdr able) 'disabled)))))
2352 (defun message-check-news-syntax ()
2353 "Check the syntax of the message."
2357 ;; We narrow to the headers and check them first.
2360 (message-narrow-to-headers)
2361 (message-check-news-header-syntax))))))
2363 (defun message-check-news-header-syntax ()
2365 ;; Check the Subject header.
2366 (message-check 'subject
2367 (let* ((case-fold-search t)
2368 (subject (message-fetch-field "subject")))
2371 (not (string-match "\\`[ \t]*\\'" subject)))
2374 "The subject field is empty or missing. Posting is denied.")))))
2375 ;; Check for commands in Subject.
2376 (message-check 'subject-cmsg
2377 (if (string-match "^cmsg " (message-fetch-field "subject"))
2379 "The control code \"cmsg\" is in the subject. Really post? ")
2381 ;; Check for multiple identical headers.
2382 (message-check 'multiple-headers
2384 (while (and (not found)
2385 (re-search-forward "^[^ \t:]+: " nil t))
2387 (or (re-search-forward
2392 (match-beginning 0) (- (match-end 0) 2))))
2397 (y-or-n-p (format "Multiple %s headers. Really post? " found))
2399 ;; Check for Version and Sendsys.
2400 (message-check 'sendsys
2401 (if (re-search-forward "^Sendsys:\\|^Version:" nil t)
2403 (format "The article contains a %s command. Really post? "
2404 (buffer-substring (match-beginning 0)
2405 (1- (match-end 0)))))
2407 ;; See whether we can shorten Followup-To.
2408 (message-check 'shorten-followup-to
2409 (let ((newsgroups (message-fetch-field "newsgroups"))
2410 (followup-to (message-fetch-field "followup-to"))
2412 (when (and newsgroups
2413 (string-match "," newsgroups)
2418 (setq to (completing-read
2419 "Followups to: (default all groups) "
2420 (mapcar (lambda (g) (list g))
2422 (message-tokenize-header
2424 (goto-char (point-min))
2425 (insert "Followup-To: " to "\n"))
2427 ;; Check "Shoot me".
2428 (message-check 'shoot
2429 (if (re-search-forward
2430 "Message-ID.*.i-did-not-set--mail-host-address--so-shoot-me" nil t)
2431 (y-or-n-p "You appear to have a misconfigured system. Really post? ")
2433 ;; Check for Approved.
2434 (message-check 'approved
2435 (if (re-search-forward "^Approved:" nil t)
2436 (y-or-n-p "The article contains an Approved header. Really post? ")
2438 ;; Check the Message-ID header.
2439 (message-check 'message-id
2440 (let* ((case-fold-search t)
2441 (message-id (message-fetch-field "message-id" t)))
2442 (or (not message-id)
2443 ;; Is there an @ in the ID?
2444 (and (string-match "@" message-id)
2445 ;; Is there a dot in the ID?
2446 (string-match "@[^.]*\\." message-id)
2447 ;; Does the ID end with a dot?
2448 (not (string-match "\\.>" message-id)))
2450 (format "The Message-ID looks strange: \"%s\". Really post? "
2452 ;; Check the Newsgroups & Followup-To headers.
2453 (message-check 'existing-newsgroups
2454 (let* ((case-fold-search t)
2455 (newsgroups (message-fetch-field "newsgroups"))
2456 (followup-to (message-fetch-field "followup-to"))
2457 (groups (message-tokenize-header
2459 (concat newsgroups "," followup-to)
2461 (hashtb (and (boundp 'gnus-active-hashtb)
2462 gnus-active-hashtb))
2464 (if (or (not hashtb)
2465 (not (boundp 'gnus-read-active-file))
2466 (not gnus-read-active-file)
2467 (eq gnus-read-active-file 'some))
2470 (when (and (not (boundp (intern (car groups) hashtb)))
2471 (not (equal (car groups) "poster")))
2472 (push (car groups) errors))
2478 "Really post to %s unknown group%s: %s "
2479 (if (= (length errors) 1) "this" "these")
2480 (if (= (length errors) 1) "" "s")
2481 (mapconcat 'identity errors ", ")))))))
2482 ;; Check the Newsgroups & Followup-To headers for syntax errors.
2483 (message-check 'valid-newsgroups
2484 (let ((case-fold-search t)
2485 (headers '("Newsgroups" "Followup-To"))
2487 (while (and headers (not error))
2488 (when (setq header (mail-fetch-field (car headers)))
2492 "\\`\\([-+_&.a-zA-Z0-9]+\\)?\\(,[-+_&.a-zA-Z0-9]+\\)*\\'"
2497 (not (string-match "\\.\\'\\|\\.\\." g)))
2498 (message-tokenize-header header ","))))
2505 (format "The %s header looks odd: \"%s\". Really post? "
2506 (car headers) header)))))
2507 (message-check 'repeated-newsgroups
2508 (let ((case-fold-search t)
2509 (headers '("Newsgroups" "Followup-To"))
2510 header error groups group)
2513 (when (setq header (mail-fetch-field (pop headers)))
2514 (setq groups (message-tokenize-header header ","))
2515 (while (setq group (pop groups))
2516 (when (member group groups)
2522 (format "Group %s is repeated in headers. Really post? " error)))))
2523 ;; Check the From header.
2524 (message-check 'from
2525 (let* ((case-fold-search t)
2526 (from (message-fetch-field "from"))
2527 (ad (nth 1 (mail-extract-address-components from))))
2530 (message "There is no From line. Posting is denied.")
2532 ((or (not (string-match "@[^\\.]*\\." ad)) ;larsi@ifi
2533 (string-match "\\.\\." ad) ;larsi@ifi..uio
2534 (string-match "@\\." ad) ;larsi@.ifi.uio
2535 (string-match "\\.$" ad) ;larsi@ifi.uio.
2536 (not (string-match "^[^@]+@[^@]+$" ad)) ;larsi.ifi.uio
2537 (string-match "(.*).*(.*)" from)) ;(lars) (lars)
2539 "Denied posting -- the From looks strange: \"%s\"." from)
2543 (defun message-check-news-body-syntax ()
2545 ;; Check for long lines.
2546 (message-check 'long-lines
2547 (goto-char (point-min))
2549 (concat "^" (regexp-quote mail-header-separator) "$"))
2553 (< (current-column) 80))
2554 (zerop (forward-line 1))))
2558 "You have lines longer than 79 characters. Really post? ")))
2559 ;; Check whether the article is empty.
2560 (message-check 'empty
2561 (goto-char (point-min))
2563 (concat "^" (regexp-quote mail-header-separator) "$"))
2566 (goto-char (point-max))
2567 (re-search-backward message-signature-separator nil t)
2569 (or (re-search-backward "[^ \n\t]" b t)
2570 (y-or-n-p "Empty article. Really post? "))))
2571 ;; Check for control characters.
2572 (message-check 'control-chars
2573 (if (re-search-forward "[\000-\007\013\015-\032\034-\037\200-\237]" nil t)
2575 "The article contains control characters. Really post? ")
2577 ;; Check excessive size.
2578 (message-check 'size
2579 (if (> (buffer-size) 60000)
2581 (format "The article is %d octets long. Really post? "
2584 ;; Check whether any new text has been added.
2585 (message-check 'new-text
2587 (not message-checksum)
2588 (not (eq (message-checksum) message-checksum))
2590 "It looks like no new text has been added. Really post? ")))
2591 ;; Check the length of the signature.
2592 (message-check 'signature
2593 (goto-char (point-max))
2594 (if (or (not (re-search-backward message-signature-separator nil t))
2595 (search-forward message-forward-end-separator nil t))
2597 (if (> (count-lines (point) (point-max)) 5)
2600 "Your .sig is %d lines; it should be max 4. Really post? "
2601 (1- (count-lines (point) (point-max)))))
2604 (defun message-checksum ()
2605 "Return a \"checksum\" for the current buffer."
2608 (goto-char (point-min))
2610 (concat "^" (regexp-quote mail-header-separator) "$"))
2612 (when (not (looking-at "[ \t\n]"))
2613 (setq sum (logxor (ash sum 1) (if (natnump sum) 0 1)
2618 (defun message-do-fcc ()
2619 "Process Fcc headers in the current buffer."
2620 (let ((case-fold-search t)
2621 (buf (current-buffer))
2624 (set-buffer (get-buffer-create " *message temp*"))
2626 (insert-buffer-substring buf)
2628 (message-narrow-to-headers)
2629 (while (setq file (message-fetch-field "fcc"))
2631 (message-remove-header "fcc" nil t)))
2632 (goto-char (point-min))
2633 (re-search-forward (concat "^" (regexp-quote mail-header-separator) "$"))
2634 (replace-match "" t t)
2635 ;; Process FCC operations.
2637 (setq file (pop list))
2638 (if (string-match "^[ \t]*|[ \t]*\\(.*\\)[ \t]*$" file)
2639 ;; Pipe the article to the program in question.
2640 (call-process-region (point-min) (point-max) shell-file-name
2641 nil nil nil shell-command-switch
2642 (match-string 1 file))
2643 ;; Save the article.
2644 (setq file (expand-file-name file))
2645 (unless (file-exists-p (file-name-directory file))
2646 (make-directory (file-name-directory file) t))
2647 (if (and message-fcc-handler-function
2648 (not (eq message-fcc-handler-function 'rmail-output)))
2649 (funcall message-fcc-handler-function file)
2650 (if (and (file-readable-p file) (mail-file-babyl-p file))
2651 (rmail-output file 1 nil t)
2652 (let ((mail-use-rfc822 t))
2653 (rmail-output file 1 t t))))))
2655 (kill-buffer (current-buffer)))))
2657 (defun message-output (filename)
2658 "Append this article to Unix/babyl mail file.."
2659 (if (and (file-readable-p filename)
2660 (mail-file-babyl-p filename))
2661 (rmail-output-to-rmail-file filename t)
2662 (gnus-output-to-mail filename t)))
2664 (defun message-cleanup-headers ()
2665 "Do various automatic cleanups of the headers."
2666 ;; Remove empty lines in the header.
2668 (message-narrow-to-headers)
2669 ;; Remove blank lines.
2670 (while (re-search-forward "^[ \t]*\n" nil t)
2671 (replace-match "" t t))
2673 ;; Correct Newsgroups and Followup-To headers: Change sequence of
2674 ;; spaces to comma and eliminate spaces around commas. Eliminate
2675 ;; embedded line breaks.
2676 (goto-char (point-min))
2677 (while (re-search-forward "^\\(Newsgroups\\|Followup-To\\): +" nil t)
2681 (if (re-search-forward "^[^ \t]" nil t)
2685 (goto-char (point-min))
2686 (while (re-search-forward "\n[ \t]+" nil t)
2687 (replace-match " " t t)) ;No line breaks (too confusing)
2688 (goto-char (point-min))
2689 (while (re-search-forward "[ \t\n]*,[ \t\n]*\\|[ \t]+" nil t)
2690 (replace-match "," t t))
2691 (goto-char (point-min))
2692 ;; Remove trailing commas.
2693 (when (re-search-forward ",+$" nil t)
2694 (replace-match "" t t))))))
2696 (defun message-make-date (&optional now)
2697 "Make a valid data header.
2698 If NOW, use that time instead."
2699 (let* ((now (or now (current-time)))
2700 (zone (nth 8 (decode-time now)))
2704 (setq zone (- zone)))
2706 (format-time-string "%d" now)
2707 ;; The month name of the %b spec is locale-specific. Pfff.
2709 (capitalize (car (rassoc (nth 4 (decode-time now))
2710 parse-time-months))))
2711 (format-time-string "%Y %H:%M:%S " now)
2712 ;; We do all of this because XEmacs doesn't have the %z spec.
2713 (format "%s%02d%02d" sign (/ zone 3600) (% zone 3600)))))
2715 (defun message-make-message-id ()
2716 "Make a unique Message-ID."
2717 (concat "<" (message-unique-id)
2718 (let ((psubject (save-excursion (message-fetch-field "subject")))
2720 (save-excursion (message-fetch-field "supersedes"))))
2722 (and message-reply-headers
2723 (mail-header-references message-reply-headers)
2724 (mail-header-subject message-reply-headers)
2726 (mail-header-subject message-reply-headers)
2728 (message-strip-subject-re
2729 (mail-header-subject message-reply-headers))
2730 (message-strip-subject-re psubject))))
2732 (string-match "_-_@" psupersedes)))
2734 "@" (message-make-fqdn) ">"))
2736 (defvar message-unique-id-char nil)
2738 ;; If you ever change this function, make sure the new version
2739 ;; cannot generate IDs that the old version could.
2740 ;; You might for example insert a "." somewhere (not next to another dot
2741 ;; or string boundary), or modify the "fsf" string.
2742 (defun message-unique-id ()
2743 ;; Don't use microseconds from (current-time), they may be unsupported.
2744 ;; Instead we use this randomly inited counter.
2745 (setq message-unique-id-char
2746 (% (1+ (or message-unique-id-char (logand (random t) (1- (lsh 1 20)))))
2747 ;; (current-time) returns 16-bit ints,
2748 ;; and 2^16*25 just fits into 4 digits i base 36.
2750 (let ((tm (current-time)))
2752 (if (memq system-type '(ms-dos emx vax-vms))
2753 (let ((user (downcase (user-login-name))))
2754 (while (string-match "[^a-z0-9_]" user)
2755 (aset user (match-beginning 0) ?_))
2757 (message-number-base36 (user-uid) -1))
2758 (message-number-base36 (+ (car tm)
2759 (lsh (% message-unique-id-char 25) 16)) 4)
2760 (message-number-base36 (+ (nth 1 tm)
2761 (lsh (/ message-unique-id-char 25) 16)) 4)
2762 ;; Append the newsreader name, because while the generated
2763 ;; ID is unique to this newsreader, other newsreaders might
2764 ;; otherwise generate the same ID via another algorithm.
2767 (defun message-number-base36 (num len)
2772 (concat (message-number-base36 (/ num 36) (1- len))
2773 (char-to-string (aref "zyxwvutsrqponmlkjihgfedcba9876543210"
2776 (defun message-make-organization ()
2777 "Make an Organization header."
2778 (let* ((organization
2779 (when message-user-organization
2780 (if (message-functionp message-user-organization)
2781 (funcall message-user-organization)
2782 message-user-organization))))
2784 (message-set-work-buffer)
2785 (cond ((stringp organization)
2786 (insert organization))
2787 ((and (eq t organization)
2788 message-user-organization-file
2789 (file-exists-p message-user-organization-file))
2790 (insert-file-contents message-user-organization-file)))
2791 (goto-char (point-min))
2792 (while (re-search-forward "[\t\n]+" nil t)
2793 (replace-match "" t t))
2794 (unless (zerop (buffer-size))
2797 (defun message-make-lines ()
2798 "Count the number of lines and return numeric string."
2802 (goto-char (point-min))
2804 (concat "^" (regexp-quote mail-header-separator) "$"))
2806 (int-to-string (count-lines (point) (point-max))))))
2808 (defun message-make-in-reply-to ()
2809 "Return the In-Reply-To header for this message."
2810 (when message-reply-headers
2811 (let ((from (mail-header-from message-reply-headers))
2812 (date (mail-header-date message-reply-headers)))
2815 (string-match " *at \\| *@ \\| *(\\| *<" from)))
2816 (concat (if (and stop-pos
2817 (not (zerop stop-pos)))
2818 (substring from 0 stop-pos) from)
2820 (if (or (not date) (string= date ""))
2821 "(unknown date)" date)
2824 (defun message-make-distribution ()
2825 "Make a Distribution header."
2826 (let ((orig-distribution (message-fetch-reply-field "distribution")))
2827 (cond ((message-functionp message-distribution-function)
2828 (funcall message-distribution-function))
2829 (t orig-distribution))))
2831 (defun message-make-expires ()
2832 "Return an Expires header based on `message-expires'."
2833 (let ((current (current-time))
2834 (future (* 1.0 message-expires 60 60 24)))
2835 ;; Add the future to current.
2836 (setcar current (+ (car current) (round (/ future (expt 2 16)))))
2837 (setcar (cdr current) (+ (nth 1 current) (% (round future) (expt 2 16))))
2838 (message-make-date current)))
2840 (defun message-make-path ()
2842 (let ((login-name (user-login-name)))
2843 (cond ((null message-user-path)
2844 (concat (system-name) "!" login-name))
2845 ((stringp message-user-path)
2846 ;; Support GENERICPATH. Suggested by vixie@decwrl.dec.com.
2847 (concat message-user-path "!" login-name))
2850 (defun message-make-from ()
2851 "Make a From header."
2852 (let* ((style message-from-style)
2853 (login (message-make-address))
2855 (or (and (boundp 'user-full-name)
2858 (when (string= fullname "&")
2859 (setq fullname (user-login-name)))
2861 (message-set-work-buffer)
2864 (equal fullname ""))
2866 ((or (eq style 'angles)
2867 (and (not (eq style 'parens))
2868 ;; Use angles if no quoting is needed, or if parens would
2869 ;; need quoting too.
2870 (or (not (string-match "[^- !#-'*+/-9=?A-Z^-~]" fullname))
2871 (let ((tmp (concat fullname nil)))
2872 (while (string-match "([^()]*)" tmp)
2873 (aset tmp (match-beginning 0) ?-)
2874 (aset tmp (1- (match-end 0)) ?-))
2875 (string-match "[\\()]" tmp)))))
2877 (goto-char (point-min))
2878 ;; Look for a character that cannot appear unquoted
2879 ;; according to RFC 822.
2880 (when (re-search-forward "[^- !#-'*+/-9=?A-Z^-~]" nil 1)
2881 ;; Quote fullname, escaping specials.
2882 (goto-char (point-min))
2884 (while (re-search-forward "[\"\\]" nil 1)
2885 (replace-match "\\\\\\&" t))
2887 (insert " <" login ">"))
2888 (t ; 'parens or default
2890 (let ((fullname-start (point)))
2892 (goto-char fullname-start)
2893 ;; RFC 822 says \ and nonmatching parentheses
2894 ;; must be escaped in comments.
2895 ;; Escape every instance of ()\ ...
2896 (while (re-search-forward "[()\\]" nil 1)
2897 (replace-match "\\\\\\&" t))
2898 ;; ... then undo escaping of matching parentheses,
2899 ;; including matching nested parentheses.
2900 (goto-char fullname-start)
2901 (while (re-search-forward
2902 "\\(\\=\\|[^\\]\\(\\\\\\\\\\)*\\)\\\\(\\(\\([^\\]\\|\\\\\\\\\\)*\\)\\\\)"
2904 (replace-match "\\1(\\3)" t)
2905 (goto-char fullname-start)))
2909 (defun message-make-sender ()
2910 "Return the \"real\" user address.
2911 This function tries to ignore all user modifications, and
2912 give as trustworthy answer as possible."
2913 (concat (user-login-name) "@" (system-name)))
2915 (defun message-make-address ()
2916 "Make the address of the user."
2917 (or (message-user-mail-address)
2918 (concat (user-login-name) "@" (message-make-domain))))
2920 (defun message-user-mail-address ()
2921 "Return the pertinent part of `user-mail-address'."
2922 (when user-mail-address
2923 (if (string-match " " user-mail-address)
2924 (nth 1 (mail-extract-address-components user-mail-address))
2925 user-mail-address)))
2927 (defun message-make-fqdn ()
2928 "Return user's fully qualified domain name."
2929 (let ((system-name (system-name))
2930 (user-mail (message-user-mail-address)))
2932 ((string-match "[^.]\\.[^.]" system-name)
2933 ;; `system-name' returned the right result.
2935 ;; Try `mail-host-address'.
2936 ((and (boundp 'mail-host-address)
2937 (stringp mail-host-address)
2938 (string-match "\\." mail-host-address))
2940 ;; We try `user-mail-address' as a backup.
2942 (string-match "\\." user-mail)
2943 (string-match "@\\(.*\\)\\'" user-mail))
2944 (match-string 1 user-mail))
2945 ;; Default to this bogus thing.
2947 (concat system-name ".i-did-not-set--mail-host-address--so-shoot-me")))))
2949 (defun message-make-host-name ()
2950 "Return the name of the host."
2951 (let ((fqdn (message-make-fqdn)))
2952 (string-match "^[^.]+\\." fqdn)
2953 (substring fqdn 0 (1- (match-end 0)))))
2955 (defun message-make-domain ()
2956 "Return the domain name."
2957 (or mail-host-address
2958 (message-make-fqdn)))
2960 (defun message-generate-headers (headers)
2961 "Prepare article HEADERS.
2962 Headers already prepared in the buffer are not modified."
2964 (message-narrow-to-headers)
2965 (let* ((Date (message-make-date))
2966 (Message-ID (message-make-message-id))
2967 (Organization (message-make-organization))
2968 (From (message-make-from))
2969 (Path (message-make-path))
2972 (In-Reply-To (message-make-in-reply-to))
2974 (Distribution (message-make-distribution))
2975 (Lines (message-make-lines))
2976 (User-Agent message-newsreader)
2977 (Expires (message-make-expires))
2978 (case-fold-search t)
2980 ;; First we remove any old generated headers.
2981 (let ((headers message-deletable-headers))
2982 (unless (buffer-modified-p)
2983 (setq headers (delq 'Message-ID (copy-sequence headers))))
2985 (goto-char (point-min))
2986 (and (re-search-forward
2987 (concat "^" (symbol-name (car headers)) ": *") nil t)
2988 (get-text-property (1+ (match-beginning 0)) 'message-deletable)
2989 (message-delete-line))
2991 ;; Go through all the required headers and see if they are in the
2992 ;; articles already. If they are not, or are empty, they are
2993 ;; inserted automatically - except for Subject, Newsgroups and
2996 (goto-char (point-min))
2997 (setq elem (pop headers))
2999 (if (eq (car elem) 'optional)
3000 (setq header (cdr elem))
3001 (setq header (car elem)))
3003 (when (or (not (re-search-forward
3007 (if (stringp header)
3009 (symbol-name header))))
3013 ;; The header was found. We insert a space after the
3014 ;; colon, if there is none.
3015 (if (/= (char-after) ? ) (insert " ") (forward-char 1))
3016 ;; Find out whether the header is empty...
3017 (looking-at "[ \t]*$")))
3018 ;; So we find out what value we should insert.
3021 ((and (consp elem) (eq (car elem) 'optional))
3022 ;; This is an optional header. If the cdr of this
3023 ;; is something that is nil, then we do not insert
3025 (setq header (cdr elem))
3026 (or (and (fboundp (cdr elem)) (funcall (cdr elem)))
3027 (and (boundp (cdr elem)) (symbol-value (cdr elem)))))
3029 ;; The element is a cons. Either the cdr is a
3030 ;; string to be inserted verbatim, or it is a
3031 ;; function, and we insert the value returned from
3033 (or (and (stringp (cdr elem)) (cdr elem))
3034 (and (fboundp (cdr elem)) (funcall (cdr elem)))))
3035 ((and (boundp header) (symbol-value header))
3036 ;; The element is a symbol. We insert the value
3037 ;; of this symbol, if any.
3038 (symbol-value header))
3040 ;; We couldn't generate a value for this header,
3041 ;; so we just ask the user.
3042 (read-from-minibuffer
3043 (format "Empty header for %s; enter value: " header)))))
3044 ;; Finally insert the header.
3046 (not (equal value "")))
3050 ;; This header didn't exist, so we insert it.
3051 (goto-char (point-max))
3052 (insert (if (stringp header) header (symbol-name header))
3055 ;; The value of this header was empty, so we clear
3056 ;; totally and insert the new value.
3057 (delete-region (point) (gnus-point-at-eol))
3059 ;; Add the deletable property to the headers that require it.
3060 (and (memq header message-deletable-headers)
3061 (progn (beginning-of-line) (looking-at "[^:]+: "))
3062 (add-text-properties
3063 (point) (match-end 0)
3064 '(message-deletable t face italic) (current-buffer)))))))
3065 ;; Insert new Sender if the From is strange.
3066 (let ((from (message-fetch-field "from"))
3067 (sender (message-fetch-field "sender"))
3068 (secure-sender (message-make-sender)))
3070 (not (message-check-element 'sender))
3073 (cadr (mail-extract-address-components from)))
3074 (downcase secure-sender)))
3079 (cadr (mail-extract-address-components sender)))
3080 (downcase secure-sender)))))
3081 (goto-char (point-min))
3082 ;; Rename any old Sender headers to Original-Sender.
3083 (when (re-search-forward "^\\(Original-\\)*Sender:" nil t)
3085 (insert "Original-")
3086 (beginning-of-line))
3087 (when (or (message-news-p)
3088 (string-match "@.+\\.." secure-sender))
3089 (insert "Sender: " secure-sender "\n")))))))
3091 (defun message-insert-courtesy-copy ()
3092 "Insert a courtesy message in mail copies of combined messages."
3096 (message-narrow-to-headers)
3097 (when (setq newsgroups (message-fetch-field "newsgroups"))
3098 (goto-char (point-max))
3099 (insert "Posted-To: " newsgroups "\n")))
3101 (when message-courtesy-message
3103 ((string-match "%s" message-courtesy-message)
3104 (insert (format message-courtesy-message newsgroups)))
3106 (insert message-courtesy-message)))))))
3109 ;;; Setting up a message buffer
3112 (defun message-fill-address (header value)
3114 (narrow-to-region (point) (point))
3115 (insert (capitalize (symbol-name header))
3117 (if (consp value) (car value) value)
3119 (narrow-to-region (point-min) (1- (point-max)))
3121 (goto-char (point-min))
3123 (skip-chars-forward "^,\"" (point-max))
3124 (if (or (eq (char-after) ?,)
3127 (if (and (> (current-column) 78)
3133 (setq last (1+ (point))))
3134 (setq last (1+ (point)))))
3135 (setq quoted (not quoted)))
3138 (goto-char (point-max))
3142 (defun message-fill-header (header value)
3143 (let ((begin (point))
3146 (insert (capitalize (symbol-name header))
3148 (if (consp value) (car value) value)
3151 (narrow-to-region begin (point))
3152 (fill-region-as-paragraph begin (point))
3153 ;; Tapdance around looong Message-IDs.
3155 (when (looking-at "[ \t]*$")
3156 (message-delete-line))
3158 (re-search-forward ":" nil t)
3159 (when (looking-at "\n[ \t]+")
3160 (replace-match " " t t))
3161 (goto-char (point-max)))))
3163 (defun message-shorten-references (header references)
3164 "Limit REFERENCES to be shorter than 988 characters."
3170 (goto-char (point-min))
3171 (while (re-search-forward "<[^>]+>" nil t)
3172 (push (match-string 0) refs))
3173 (setq refs (nreverse refs))
3174 (while (> (length (mapconcat 'identity refs " ")) max)
3175 (when (< (length refs) (1+ cut))
3177 (setcdr (nthcdr cut refs) (cddr (nthcdr cut refs)))))
3178 (insert (capitalize (symbol-name header)) ": "
3179 (mapconcat 'identity refs " ") "\n")))
3181 (defun message-position-point ()
3182 "Move point to where the user probably wants to find it."
3183 (message-narrow-to-headers)
3185 ((re-search-forward "^[^:]+:[ \t]*$" nil t)
3186 (search-backward ":" )
3189 (if (eq (char-after) ? )
3193 (goto-char (point-max))
3196 (unless (looking-at "$")
3200 (defun message-buffer-name (type &optional to group)
3201 "Return a new (unique) buffer name based on TYPE and TO."
3203 ;; Generate a new buffer name The Message Way.
3204 ((eq message-generate-new-buffers 'unique)
3205 (generate-new-buffer-name
3209 (or (car (mail-extract-address-components to))
3212 (if (and group (not (string= group ""))) (concat " on " group) "")
3214 ;; Check whether `message-generate-new-buffers' is a function,
3215 ;; and if so, call it.
3216 ((message-functionp message-generate-new-buffers)
3217 (funcall message-generate-new-buffers type to group))
3218 ((eq message-generate-new-buffers 'unsent)
3219 (generate-new-buffer-name
3220 (concat "*unsent " type
3223 (or (car (mail-extract-address-components to))
3226 (if (and group (not (string= group ""))) (concat " on " group) "")
3228 ;; Use standard name.
3230 (format "*%s message*" type))))
3232 (defun message-pop-to-buffer (name)
3233 "Pop to buffer NAME, and warn if it already exists and is modified."
3234 (let ((buffer (get-buffer name)))
3236 (buffer-name buffer))
3238 (set-buffer (pop-to-buffer buffer))
3239 (when (and (buffer-modified-p)
3241 "Message already being composed; erase? ")))
3242 (error "Message being composed")))
3243 (set-buffer (pop-to-buffer name)))
3247 (defun message-do-send-housekeeping ()
3248 "Kill old message buffers."
3249 ;; We might have sent this buffer already. Delete it from the
3251 (setq message-buffer-list (delq (current-buffer) message-buffer-list))
3252 (while (and message-max-buffers
3254 (>= (length message-buffer-list) message-max-buffers))
3255 ;; Kill the oldest buffer -- unless it has been changed.
3256 (let ((buffer (pop message-buffer-list)))
3257 (when (and (buffer-name buffer)
3258 (not (buffer-modified-p buffer)))
3259 (kill-buffer buffer))))
3260 ;; Rename the buffer.
3261 (if message-send-rename-function
3262 (funcall message-send-rename-function)
3263 (when (string-match "\\`\\*\\(unsent \\)?" (buffer-name))
3265 (concat "*sent " (substring (buffer-name) (match-end 0))) t)))
3266 ;; Push the current buffer onto the list.
3267 (when message-max-buffers
3268 (setq message-buffer-list
3269 (nconc message-buffer-list (list (current-buffer))))))
3271 (defvar mc-modes-alist)
3272 (defun message-setup (headers &optional replybuffer actions)
3273 (when (and (boundp 'mc-modes-alist)
3274 (not (assq 'message-mode mc-modes-alist)))
3275 (push '(message-mode (encrypt . mc-encrypt-message)
3276 (sign . mc-sign-message))
3279 (setq message-send-actions actions))
3280 (setq message-reply-buffer replybuffer)
3281 (goto-char (point-min))
3282 ;; Insert all the headers.
3285 (alist message-header-format-alist))
3287 (unless (assq (caar h) message-header-format-alist)
3288 (push (list (caar h)) alist))
3292 (delete-region (point) (progn (forward-line -1) (point)))
3293 (when message-default-headers
3294 (insert message-default-headers)
3295 (or (bolp) (insert ?\n)))
3299 (insert mail-header-separator "\n")
3303 (when (message-news-p)
3304 (when message-default-news-headers
3305 (insert message-default-news-headers)
3306 (or (bolp) (insert ?\n)))
3307 (when message-generate-headers-first
3308 (message-generate-headers
3311 (copy-sequence message-required-news-headers))))))
3312 (when (message-mail-p)
3313 (when message-default-mail-headers
3314 (insert message-default-mail-headers)
3315 (or (bolp) (insert ?\n)))
3316 (when message-generate-headers-first
3317 (message-generate-headers
3320 (copy-sequence message-required-mail-headers))))))
3321 (run-hooks 'message-signature-setup-hook)
3322 (message-insert-signature)
3324 (message-narrow-to-headers)
3325 (run-hooks 'message-header-setup-hook))
3326 (set-buffer-modified-p nil)
3327 (setq buffer-undo-list nil)
3328 (run-hooks 'message-setup-hook)
3329 (message-position-point)
3332 (defun message-set-auto-save-file-name ()
3333 "Associate the message buffer with a file in the drafts directory."
3334 (when message-auto-save-directory
3336 (setq message-draft-article
3337 (nndraft-request-associate-buffer "drafts"))
3338 (setq buffer-file-name (expand-file-name "*message*"
3339 message-auto-save-directory))
3340 (setq buffer-auto-save-file-name (make-auto-save-file-name)))
3341 (clear-visited-file-modtime)
3342 (setq buffer-file-coding-system message-draft-coding-system)))
3344 (defun message-disassociate-draft ()
3345 "Disassociate the message buffer from the drafts directory."
3346 (when message-draft-article
3347 (nndraft-request-expire-articles
3348 (list message-draft-article) "drafts" nil t)))
3350 (defun message-insert-headers ()
3351 "Generate the headers for the article."
3355 (message-narrow-to-headers)
3356 (when (message-news-p)
3357 (message-generate-headers
3360 (copy-sequence message-required-news-headers)))))
3361 (when (message-mail-p)
3362 (message-generate-headers
3365 (copy-sequence message-required-mail-headers))))))))
3370 ;;; Commands for interfacing with message
3374 (defun message-mail (&optional to subject
3375 other-headers continue switch-function
3376 yank-action send-actions)
3377 "Start editing a mail message to be sent.
3378 OTHER-HEADERS is an alist of header/value pairs."
3380 (let ((message-this-is-mail t))
3381 (message-pop-to-buffer (message-buffer-name "mail" to))
3384 `((To . ,(or to "")) (Subject . ,(or subject "")))
3385 (when other-headers other-headers)))))
3388 (defun message-news (&optional newsgroups subject)
3389 "Start editing a news article to be sent."
3391 (let ((message-this-is-news t))
3392 (message-pop-to-buffer (message-buffer-name "news" nil newsgroups))
3393 (message-setup `((Newsgroups . ,(or newsgroups ""))
3394 (Subject . ,(or subject ""))))))
3397 (defun message-reply (&optional to-address wide)
3398 "Start editing a reply to the article in the current buffer."
3400 (let ((cur (current-buffer))
3401 from subject date reply-to to cc
3402 references message-id follow-to
3403 (inhibit-point-motion-hooks t)
3404 mct never-mct gnus-warning)
3406 (message-narrow-to-head)
3407 ;; Allow customizations to have their say.
3409 ;; This is a regular reply.
3410 (if (message-functionp message-reply-to-function)
3411 (setq follow-to (funcall message-reply-to-function)))
3412 ;; This is a followup.
3413 (if (message-functionp message-wide-reply-to-function)
3416 (funcall message-wide-reply-to-function)))))
3417 ;; Find all relevant headers we need.
3418 (setq from (message-fetch-field "from")
3419 date (message-fetch-field "date")
3420 subject (or (message-fetch-field "subject") "none")
3421 to (message-fetch-field "to")
3422 cc (message-fetch-field "cc")
3423 mct (message-fetch-field "mail-copies-to")
3424 reply-to (message-fetch-field "reply-to")
3425 references (message-fetch-field "references")
3426 message-id (message-fetch-field "message-id" t))
3427 ;; Remove any (buggy) Re:'s that are present and make a
3429 (when (string-match message-subject-re-regexp subject)
3430 (setq subject (substring subject (match-end 0))))
3431 (setq subject (concat "Re: " subject))
3433 (when (and (setq gnus-warning (message-fetch-field "gnus-warning"))
3434 (string-match "<[^>]+>" gnus-warning))
3435 (setq message-id (match-string 0 gnus-warning)))
3437 ;; Handle special values of Mail-Copies-To.
3439 (cond ((or (equal (downcase mct) "never")
3440 (equal (downcase mct) "nobody"))
3443 ((or (equal (downcase mct) "always")
3444 (equal (downcase mct) "poster"))
3445 (setq mct (or reply-to from)))))
3451 (setq follow-to (list (cons 'To (or to-address reply-to from))))
3452 (when (and wide mct)
3453 (push (cons 'Cc mct) follow-to)))
3456 (message-set-work-buffer)
3458 (insert (or reply-to from "")))
3459 (insert (if to (concat (if (bolp) "" ", ") to "") ""))
3460 (insert (if mct (concat (if (bolp) "" ", ") mct) ""))
3461 (insert (if cc (concat (if (bolp) "" ", ") cc) ""))
3462 (goto-char (point-min))
3463 (while (re-search-forward "[ \t]+" nil t)
3464 (replace-match " " t t))
3465 ;; Remove addresses that match `rmail-dont-reply-to-names'.
3466 (insert (prog1 (rmail-dont-reply-to (buffer-string))
3468 (goto-char (point-min))
3469 ;; Perhaps Mail-Copies-To: never removed the only address?
3471 (insert (or reply-to from "")))
3475 (cons (mail-strip-quoted-names addr) addr))
3476 (message-tokenize-header (buffer-string))))
3479 (setq ccalist (delq (assoc (car (pop s)) s) ccalist)))))
3480 (setq follow-to (list (cons 'To (cdr (pop ccalist)))))
3482 (let ((ccs (cons 'Cc (mapconcat
3483 (lambda (addr) (cdr addr)) ccalist ", "))))
3484 (when (string-match "^ +" (cdr ccs))
3485 (setcdr ccs (substring (cdr ccs) (match-end 0))))
3486 (push ccs follow-to))))))
3489 (message-pop-to-buffer (message-buffer-name
3490 (if wide "wide reply" "reply") from
3491 (if wide to-address nil)))
3493 (setq message-reply-headers
3494 (vector 0 subject from date message-id references 0 0 ""))
3497 `((Subject . ,subject)
3499 ,@(if (or references message-id)
3500 `((References . ,(concat (or references "") (and references " ")
3501 (or message-id ""))))
3506 (defun message-wide-reply (&optional to-address)
3507 "Make a \"wide\" reply to the message in the current buffer."
3509 (message-reply to-address t))
3512 (defun message-followup (&optional to-newsgroups)
3513 "Follow up to the message in the current buffer.
3514 If TO-NEWSGROUPS, use that as the new Newsgroups line."
3516 (let ((cur (current-buffer))
3517 from subject date reply-to mct
3518 references message-id follow-to
3519 (inhibit-point-motion-hooks t)
3520 (message-this-is-news t)
3521 followup-to distribution newsgroups gnus-warning posted-to)
3524 (goto-char (point-min))
3525 (if (search-forward "\n\n" nil t)
3528 (when (message-functionp message-followup-to-function)
3530 (funcall message-followup-to-function)))
3531 (setq from (message-fetch-field "from")
3532 date (message-fetch-field "date")
3533 subject (or (message-fetch-field "subject") "none")
3534 references (message-fetch-field "references")
3535 message-id (message-fetch-field "message-id" t)
3536 followup-to (message-fetch-field "followup-to")
3537 newsgroups (message-fetch-field "newsgroups")
3538 posted-to (message-fetch-field "posted-to")
3539 reply-to (message-fetch-field "reply-to")
3540 distribution (message-fetch-field "distribution")
3541 mct (message-fetch-field "mail-copies-to"))
3542 (when (and (setq gnus-warning (message-fetch-field "gnus-warning"))
3543 (string-match "<[^>]+>" gnus-warning))
3544 (setq message-id (match-string 0 gnus-warning)))
3545 ;; Remove bogus distribution.
3546 (when (and (stringp distribution)
3547 (let ((case-fold-search t))
3548 (string-match "world" distribution)))
3549 (setq distribution nil))
3550 ;; Remove any (buggy) Re:'s that are present and make a
3552 (when (string-match message-subject-re-regexp subject)
3553 (setq subject (substring subject (match-end 0))))
3554 (setq subject (concat "Re: " subject))
3557 (message-pop-to-buffer (message-buffer-name "followup" from newsgroups))
3560 `((Subject . ,subject)
3563 (list (cons 'Newsgroups to-newsgroups)))
3564 (follow-to follow-to)
3565 ((and followup-to message-use-followup-to)
3568 ((equal (downcase followup-to) "poster")
3569 (if (or (eq message-use-followup-to 'use)
3570 (message-y-or-n-p "Obey Followup-To: poster? " t "\
3571 You should normally obey the Followup-To: header.
3573 `Followup-To: poster' sends your response via e-mail instead of news.
3575 A typical situation where `Followup-To: poster' is used is when the poster
3576 does not read the newsgroup, so he wouldn't see any replies sent to it."))
3578 (setq message-this-is-news nil)
3579 (cons 'To (or reply-to from "")))
3580 (cons 'Newsgroups newsgroups)))
3582 (if (or (equal followup-to newsgroups)
3583 (not (eq message-use-followup-to 'ask))
3585 (concat "Obey Followup-To: " followup-to "? ") t "\
3586 You should normally obey the Followup-To: header.
3588 `Followup-To: " followup-to "'
3589 directs your response to " (if (string-match "," followup-to)
3590 "the specified newsgroups"
3591 "that newsgroup only") ".
3593 If a message is posted to several newsgroups, Followup-To is often
3594 used to direct the following discussion to one newsgroup only,
3595 because discussions that are spread over several newsgroup tend to
3596 be fragmented and very difficult to follow.
3598 Also, some source/announcement newsgroups are not indented for discussion;
3599 responses here are directed to other newsgroups."))
3600 (cons 'Newsgroups followup-to)
3601 (cons 'Newsgroups newsgroups))))))
3603 `((Newsgroups . ,posted-to)))
3605 `((Newsgroups . ,newsgroups))))
3606 ,@(and distribution (list (cons 'Distribution distribution)))
3607 ,@(if (or references message-id)
3608 `((References . ,(concat (or references "") (and references " ")
3609 (or message-id "")))))
3611 (not (or (equal (downcase mct) "never")
3612 (equal (downcase mct) "nobody"))))
3613 (list (cons 'Cc (if (or (equal (downcase mct) "always")
3614 (equal (downcase mct) "poster"))
3615 (or reply-to from "")
3620 (setq message-reply-headers
3621 (vector 0 subject from date message-id references 0 0 ""))))
3625 (defun message-cancel-news ()
3626 "Cancel an article you posted."
3628 (unless (message-news-p)
3629 (error "This is not a news article; canceling is impossible"))
3630 (when (yes-or-no-p "Do you really want to cancel this article? ")
3631 (let (from newsgroups message-id distribution buf sender)
3633 ;; Get header info. from original article.
3635 (message-narrow-to-head)
3636 (setq from (message-fetch-field "from")
3637 sender (message-fetch-field "sender")
3638 newsgroups (message-fetch-field "newsgroups")
3639 message-id (message-fetch-field "message-id" t)
3640 distribution (message-fetch-field "distribution")))
3641 ;; Make sure that this article was written by the user.
3642 (unless (or (and sender
3645 (downcase (message-make-sender))))
3647 (downcase (cadr (mail-extract-address-components from)))
3648 (downcase (cadr (mail-extract-address-components
3649 (message-make-from))))))
3650 (error "This article is not yours"))
3651 ;; Make control message.
3652 (setq buf (set-buffer (get-buffer-create " *message cancel*")))
3654 (insert "Newsgroups: " newsgroups "\n"
3655 "From: " (message-make-from) "\n"
3656 "Subject: cmsg cancel " message-id "\n"
3657 "Control: cancel " message-id "\n"
3659 (concat "Distribution: " distribution "\n")
3661 mail-header-separator "\n"
3662 message-cancel-message)
3663 (run-hooks 'message-cancel-hook)
3664 (message "Canceling your article...")
3665 (if (let ((message-syntax-checks
3666 'dont-check-for-anything-just-trust-me))
3667 (funcall message-send-news-function))
3668 (message "Canceling your article...done"))
3669 (kill-buffer buf)))))
3672 (defun message-supersede ()
3673 "Start composing a message to supersede the current message.
3674 This is done simply by taking the old article and adding a Supersedes
3675 header line with the old Message-ID."
3677 (let ((cur (current-buffer))
3678 (sender (message-fetch-field "sender"))
3679 (from (message-fetch-field "from")))
3680 ;; Check whether the user owns the article that is to be superseded.
3681 (unless (or (and sender
3684 (downcase (message-make-sender))))
3686 (downcase (cadr (mail-extract-address-components from)))
3687 (downcase (cadr (mail-extract-address-components
3688 (message-make-from))))))
3689 (error "This article is not yours"))
3690 ;; Get a normal message buffer.
3691 (message-pop-to-buffer (message-buffer-name "supersede"))
3692 (insert-buffer-substring cur)
3693 (message-narrow-to-head)
3694 ;; Remove unwanted headers.
3695 (when message-ignored-supersedes-headers
3696 (message-remove-header message-ignored-supersedes-headers t))
3697 (goto-char (point-min))
3698 (if (not (re-search-forward "^Message-ID: " nil t))
3699 (error "No Message-ID in this article")
3700 (replace-match "Supersedes: " t t))
3701 (goto-char (point-max))
3702 (insert mail-header-separator)
3707 (defun message-recover ()
3708 "Reread contents of current buffer from its last auto-save file."
3710 (let ((file-name (make-auto-save-file-name)))
3711 (cond ((save-window-excursion
3712 (if (not (eq system-type 'vax-vms))
3713 (with-output-to-temp-buffer "*Directory*"
3714 (buffer-disable-undo standard-output)
3715 (let ((default-directory "/"))
3717 "ls" nil standard-output nil "-l" file-name))))
3718 (yes-or-no-p (format "Recover auto save file %s? " file-name)))
3719 (let ((buffer-read-only nil))
3721 (insert-file-contents file-name nil)))
3722 (t (error "message-recover cancelled")))))
3724 ;;; Washing Subject:
3726 (defun message-wash-subject (subject)
3727 "Remove junk like \"Re:\", \"(fwd)\", etc. that was added to the subject by previous forwarders, replyers, etc."
3729 (insert-string subject)
3730 (goto-char (point-min))
3731 ;; strip Re/Fwd stuff off the beginning
3732 (while (re-search-forward
3733 "\\([Rr][Ee]:\\|[Ff][Ww][Dd]\\(\\[[0-9]*\\]\\)?:\\|[Ff][Ww]:\\)" nil t)
3736 ;; and gnus-style forwards [foo@bar.com] subject
3737 (goto-char (point-min))
3738 (while (re-search-forward "\\[[^ \t]*\\(@\\|\\.\\)[^ \t]*\\]" nil t)
3742 (goto-char (point-max))
3743 (while (re-search-backward "([Ff][Ww][Dd])" nil t)
3746 ;; and finally, any whitespace that was left-over
3747 (goto-char (point-min))
3748 (while (re-search-forward "^[ \t]+" nil t)
3750 (goto-char (point-max))
3751 (while (re-search-backward "[ \t]+$" nil t)
3756 ;;; Forwarding messages.
3758 (defun message-forward-subject-author-subject (subject)
3759 "Generate a subject for a forwarded message.
3760 The form is: [Source] Subject, where if the original message was mail,
3761 Source is the sender, and if the original message was news, Source is
3762 the list of newsgroups is was posted to."
3764 (or (message-fetch-field
3765 (if (message-news-p) "newsgroups" "from"))
3769 (defun message-forward-subject-fwd (subject)
3770 "Generate a subject for a forwarded message.
3771 The form is: Fwd: Subject, where Subject is the original subject of
3773 (concat "Fwd: " subject))
3775 (defun message-make-forward-subject ()
3776 "Return a Subject header suitable for the message in the current buffer."
3780 (message-narrow-to-head)
3781 (let ((funcs message-make-forward-subject-function)
3782 (subject (if message-wash-forwarded-subjects
3783 (message-wash-subject
3784 (or (message-fetch-field "Subject") ""))
3785 (or (message-fetch-field "Subject") ""))))
3786 ;; Make sure funcs is a list.
3789 (setq funcs (list funcs)))
3790 ;; Apply funcs in order, passing subject generated by previous
3791 ;; func to the next one.
3793 (when (message-functionp (car funcs))
3794 (setq subject (funcall (car funcs) subject)))
3795 (setq funcs (cdr funcs)))
3799 (defun message-forward (&optional news)
3800 "Forward the current message via mail.
3801 Optional NEWS will use news to forward instead of mail."
3803 (let ((cur (current-buffer))
3804 (subject (message-make-forward-subject))
3806 (if news (message-news nil subject) (message-mail nil subject))
3807 ;; Put point where we want it before inserting the forwarded
3809 (if message-signature-before-forwarded-message
3810 (goto-char (point-max))
3811 (message-goto-body))
3812 ;; Make sure we're at the start of the line.
3815 ;; Narrow to the area we are to insert.
3816 (narrow-to-region (point) (point))
3817 ;; Insert the separators and the forwarded buffer.
3818 (insert message-forward-start-separator)
3819 (setq art-beg (point))
3820 (insert-buffer-substring cur)
3821 (goto-char (point-max))
3822 (insert message-forward-end-separator)
3823 (set-text-properties (point-min) (point-max) nil)
3824 ;; Remove all unwanted headers.
3826 (narrow-to-region (point) (if (search-forward "\n\n" nil t)
3829 (goto-char (point-min))
3830 (message-remove-header message-included-forward-headers t nil t)
3832 (message-position-point)))
3835 (defun message-resend (address)
3836 "Resend the current article to ADDRESS."
3837 (interactive "sResend message to: ")
3838 (message "Resending message to %s..." address)
3840 (let ((cur (current-buffer))
3842 ;; We first set up a normal mail buffer.
3843 (set-buffer (get-buffer-create " *message resend*"))
3845 (message-setup `((To . ,address)))
3846 ;; Insert our usual headers.
3847 (message-generate-headers '(From Date To))
3848 (message-narrow-to-headers)
3849 ;; Rename them all to "Resent-*".
3850 (while (re-search-forward "^[A-Za-z]" nil t)
3855 (delete-region (point) (point-max))
3857 ;; Insert the message to be resent.
3858 (insert-buffer-substring cur)
3859 (goto-char (point-min))
3860 (search-forward "\n\n")
3863 (narrow-to-region beg (point))
3864 (message-remove-header message-ignored-resent-headers t)
3865 (goto-char (point-max)))
3866 (insert mail-header-separator)
3867 ;; Rename all old ("Also-")Resent headers.
3868 (while (re-search-backward "^\\(Also-\\)*Resent-" beg t)
3871 ;; Quote any "From " lines at the beginning.
3873 (when (looking-at "From ")
3874 (replace-match "X-From-Line: "))
3876 (let (message-required-mail-headers)
3877 (message-send-mail))
3878 (kill-buffer (current-buffer)))
3879 (message "Resending message to %s...done" address)))
3882 (defun message-bounce ()
3883 "Re-mail the current message.
3884 This only makes sense if the current message is a bounce message than
3885 contains some mail you have written which has been bounced back to
3888 (let ((cur (current-buffer))
3890 (message-pop-to-buffer (message-buffer-name "bounce"))
3891 (insert-buffer-substring cur)
3893 (message-narrow-to-head)
3894 (if (and (message-fetch-field "Mime-Version")
3895 (setq boundary (message-fetch-field "Content-Type")))
3896 (if (string-match "boundary=\"\\([^\"]+\\)\"" boundary)
3897 (setq boundary (concat (match-string 1 boundary) " *\n"
3898 "Content-Type: message/rfc822"))
3899 (setq boundary nil)))
3901 (goto-char (point-min))
3902 (search-forward "\n\n" nil t)
3904 (re-search-forward boundary nil t)
3906 (and (re-search-forward message-unsent-separator nil t)
3908 (re-search-forward "^Return-Path:.*\n" nil t))
3909 ;; We remove everything before the bounced mail.
3912 (if (re-search-forward "^[^ \n\t]+:" nil t)
3916 (message-narrow-to-head)
3917 (message-remove-header message-ignored-bounced-headers t)
3918 (goto-char (point-max))
3919 (insert mail-header-separator))
3920 (message-position-point)))
3923 ;;; Interactive entry points for new message buffers.
3927 (defun message-mail-other-window (&optional to subject)
3928 "Like `message-mail' command, but display mail buffer in another window."
3930 (let ((pop-up-windows t)
3931 (special-display-buffer-names nil)
3932 (special-display-regexps nil)
3933 (same-window-buffer-names nil)
3934 (same-window-regexps nil))
3935 (message-pop-to-buffer (message-buffer-name "mail" to)))
3936 (let ((message-this-is-mail t))
3937 (message-setup `((To . ,(or to "")) (Subject . ,(or subject ""))))))
3940 (defun message-mail-other-frame (&optional to subject)
3941 "Like `message-mail' command, but display mail buffer in another frame."
3943 (let ((pop-up-frames t)
3944 (special-display-buffer-names nil)
3945 (special-display-regexps nil)
3946 (same-window-buffer-names nil)
3947 (same-window-regexps nil))
3948 (message-pop-to-buffer (message-buffer-name "mail" to)))
3949 (let ((message-this-is-mail t))
3950 (message-setup `((To . ,(or to "")) (Subject . ,(or subject ""))))))
3953 (defun message-news-other-window (&optional newsgroups subject)
3954 "Start editing a news article to be sent."
3956 (let ((pop-up-windows t)
3957 (special-display-buffer-names nil)
3958 (special-display-regexps nil)
3959 (same-window-buffer-names nil)
3960 (same-window-regexps nil))
3961 (message-pop-to-buffer (message-buffer-name "news" nil newsgroups)))
3962 (let ((message-this-is-news t))
3963 (message-setup `((Newsgroups . ,(or newsgroups ""))
3964 (Subject . ,(or subject ""))))))
3967 (defun message-news-other-frame (&optional newsgroups subject)
3968 "Start editing a news article to be sent."
3970 (let ((pop-up-frames t)
3971 (special-display-buffer-names nil)
3972 (special-display-regexps nil)
3973 (same-window-buffer-names nil)
3974 (same-window-regexps nil))
3975 (message-pop-to-buffer (message-buffer-name "news" nil newsgroups)))
3976 (let ((message-this-is-news t))
3977 (message-setup `((Newsgroups . ,(or newsgroups ""))
3978 (Subject . ,(or subject ""))))))
3982 ;; This code should be moved to underline.el (from which it is stolen).
3985 (defun bold-region (start end)
3986 "Bold all nonblank characters in the region.
3987 Works by overstriking characters.
3988 Called from program, takes two arguments START and END
3989 which specify the range to operate on."
3992 (let ((end1 (make-marker)))
3993 (move-marker end1 (max start end))
3994 (goto-char (min start end))
3995 (while (< (point) end1)
3996 (or (looking-at "[_\^@- ]")
3997 (insert (char-after) "\b"))
3998 (forward-char 1)))))
4001 (defun unbold-region (start end)
4002 "Remove all boldness (overstruck characters) in the region.
4003 Called from program, takes two arguments START and END
4004 which specify the range to operate on."
4007 (let ((end1 (make-marker)))
4008 (move-marker end1 (max start end))
4009 (goto-char (min start end))
4010 (while (re-search-forward "\b" end1 t)
4011 (if (eq (char-after) (char-after (- (point) 2)))
4012 (delete-char -2))))))
4014 (defalias 'message-exchange-point-and-mark 'exchange-point-and-mark)
4016 ;; Support for toolbar
4017 (when (string-match "XEmacs\\|Lucid" emacs-version)
4018 (require 'messagexmas))
4020 ;;; Group name completion.
4022 (defvar message-newgroups-header-regexp
4023 "^\\(Newsgroups\\|Followup-To\\|Posted-To\\|Gcc\\):"
4024 "Regexp that match headers that lists groups.")
4026 (defun message-tab ()
4027 "Expand group names in Newsgroups and Followup-To headers.
4028 Do a `tab-to-tab-stop' if not in those headers."
4030 (if (let ((mail-abbrev-mode-regexp message-newgroups-header-regexp))
4031 (mail-abbrev-in-expansion-header-p))
4032 (message-expand-group)
4035 (defvar gnus-active-hashtb)
4036 (defun message-expand-group ()
4037 "Expand the group name under point."
4038 (let* ((b (save-excursion
4043 (skip-chars-forward "^:")
4046 (skip-chars-backward "^, \t\n") (point))))
4047 (completion-ignore-case t)
4048 (string (buffer-substring b (progn (skip-chars-forward "^,\t\n ")
4050 (hashtb (and (boundp 'gnus-active-hashtb) gnus-active-hashtb))
4051 (completions (all-completions string hashtb))
4053 (delete-region b (point))
4055 ((= (length completions) 1)
4056 (if (string= (car completions) string)
4059 (message "Only matching group"))
4060 (insert (car completions))))
4061 ((and (setq comp (try-completion string hashtb))
4062 (not (string= comp string)))
4067 (message "No matching groups")
4068 (save-selected-window
4069 (pop-to-buffer "*Completions*")
4070 (buffer-disable-undo)
4071 (let ((buffer-read-only nil))
4073 (let ((standard-output (current-buffer)))
4074 (display-completion-list (sort completions 'string<)))
4075 (goto-char (point-min))
4076 (delete-region (point) (progn (forward-line 3) (point))))))))))
4080 (defun message-talkative-question (ask question show &rest text)
4081 "Call FUNCTION with argument QUESTION; optionally display TEXT... args.
4082 If SHOW is non-nil, the arguments TEXT... are displayed in a temp buffer.
4083 The following arguments may contain lists of values."
4085 (setq text (message-flatten-list text)))
4086 (save-window-excursion
4088 (with-output-to-temp-buffer " *MESSAGE information message*"
4089 (set-buffer " *MESSAGE information message*")
4090 (mapcar 'princ text)
4091 (goto-char (point-min))))
4092 (funcall ask question))
4093 (funcall ask question)))
4095 (defun message-flatten-list (list)
4096 "Return a new, flat list that contains all elements of LIST.
4098 \(message-flatten-list '(1 (2 3 (4 5 (6))) 7))
4101 (apply 'append (mapcar 'message-flatten-list list)))
4105 (defun message-generate-new-buffer-clone-locals (name &optional varstr)
4106 "Create and return a buffer with a name based on NAME using generate-new-buffer.
4107 Then clone the local variables and values from the old buffer to the
4108 new one, cloning only the locals having a substring matching the
4110 (let ((oldbuf (current-buffer)))
4112 (set-buffer (generate-new-buffer name))
4113 (message-clone-locals oldbuf)
4116 (defun message-clone-locals (buffer)
4117 "Clone the local variables from BUFFER to the current buffer."
4118 (let ((locals (save-excursion
4120 (buffer-local-variables)))
4121 (regexp "^gnus\\|^nn\\|^message"))
4124 (when (and (consp local)
4126 (string-match regexp (symbol-name (car local))))
4128 (set (make-local-variable (car local))
4132 ;;; Miscellaneous functions
4134 ;; stolen (and renamed) from nnheader.el
4135 (defun message-replace-chars-in-string (string from to)
4136 "Replace characters in STRING from FROM to TO."
4137 (let ((string (substring string 0)) ;Copy string.
4138 (len (length string))
4140 ;; Replace all occurrences of FROM with TO.
4142 (when (= (aref string idx) from)
4143 (aset string idx to))
4144 (setq idx (1+ idx)))
4151 (defun message-mime-query-file (prompt)
4152 (let ((file (read-file-name prompt nil nil t)))
4153 ;; Prevent some common errors. This is inspired by similar code in
4155 (when (file-directory-p file)
4156 (error "%s is a directory, cannot attach" file))
4157 (unless (file-exists-p file)
4158 (error "No such file: %s" file))
4159 (unless (file-readable-p file)
4160 (error "Permission denied: %s" file))
4163 (defun message-mime-query-type (file)
4164 (let* ((default (or (mm-default-file-encoding file)
4165 ;; Perhaps here we should check what the file
4166 ;; looks like, and offer text/plain if it looks
4168 "application/octet-stream"))
4169 (string (completing-read
4170 (format "Content type (default %s): " default)
4172 (mapcar (lambda (m) (list (cdr m))) mailcap-mime-extensions)
4174 (if (not (equal string ""))
4178 (defun message-mime-query-description ()
4179 (let ((description (read-string "One line description: ")))
4180 (when (string-match "\\`[ \t]*\\'" description)
4181 (setq description nil))
4184 (defun message-mime-attach-file (file &optional type description)
4185 "Attach a file to the outgoing MIME message.
4186 The file is not inserted or encoded until you send the message with
4187 `\\[message-send-and-exit]' or `\\[message-send]'.
4189 FILE is the name of the file to attach. TYPE is its content-type, a
4190 string of the form \"type/subtype\". DESCRIPTION is a one-line
4191 description of the attachment."
4193 (let* ((file (message-mime-query-file "Attach file: "))
4194 (type (message-mime-query-type file))
4195 (description (message-mime-query-description)))
4196 (list file type description)))
4198 "<#part type=%s filename=%s%s disposition=attachment><#/part>\n"
4199 type (prin1-to-string file)
4201 (format " description=%s" (prin1-to-string description))
4204 (defun message-mime-attach-external (file &optional type description)
4205 "Attach an external file into the buffer.
4206 FILE is an ange-ftp/efs specification of the part location.
4207 TYPE is the MIME type to use."
4209 (let* ((file (message-mime-query-file "Attach external file: "))
4210 (type (message-mime-query-type file))
4211 (description (message-mime-query-description)))
4212 (list file type description)))
4214 "<#external type=%s name=%s disposition=attachment><#/external>\n"
4215 type (prin1-to-string file))))
4217 (defun message-encode-message-body ()
4218 (let ((mail-parse-charset message-default-charset)
4219 (case-fold-search t)
4220 lines multipart-p content-type-p)
4223 (narrow-to-region (point) (point-max))
4224 (let ((new (mml-generate-mime)))
4226 (delete-region (point-min) (point-max))
4228 (goto-char (point-min))
4229 (if (eq (aref new 0) ?\n)
4231 (search-forward "\n\n")
4232 (setq lines (buffer-substring (point-min) (1- (point))))
4233 (delete-region (point-min) (point))))))
4235 (message-narrow-to-headers-or-head)
4236 (message-remove-header "Mime-Version")
4237 (goto-char (point-max))
4238 (insert "MIME-Version: 1.0\n")
4242 (re-search-backward "^Content-Type: multipart/" nil t))
4243 (goto-char (point-max))
4244 (setq content-type-p
4245 (re-search-backward "^Content-Type:" nil t)))
4247 (message-narrow-to-headers-or-head)
4248 (message-remove-first-header "Content-Type")
4249 (message-remove-first-header "Content-Transfer-Encoding"))
4252 (insert "This is a MIME multipart message. If you are reading\n")
4253 (insert "this, you shouldn't.\n"))
4254 ;; We always make sure that the message has a Content-Type header.
4255 ;; This is because some broken MTAs and MUAs get awfully confused
4256 ;; when confronted with a message with a MIME-Version header and
4257 ;; without a Content-Type header. For instance, Solaris'
4259 (unless content-type-p
4260 (goto-char (point-min))
4261 (re-search-forward "^MIME-Version:")
4263 (insert "Content-Type: text/plain; charset=us-ascii\n"))))
4267 (run-hooks 'message-load-hook)
4269 ;;; message.el ends here