1 ;;; message.el --- composing mail and news messages
2 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000
3 ;; Free Software Foundation, Inc.
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
6 ;; Keywords: mail, news
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
27 ;; This mode provides mail-sending facilities from within Emacs. It
28 ;; consists mainly of large chunks of code from the sendmail.el,
29 ;; gnus-msg.el and rnewspost.el files.
33 (eval-when-compile (require 'cl))
37 (if (string-match "XEmacs\\|Lucid" emacs-version)
38 (require 'mail-abbrevs)
39 (require 'mailabbrev))
45 (defgroup message '((user-mail-address custom-variable)
46 (user-full-name custom-variable))
47 "Mail and news message composing."
48 :link '(custom-manual "(message)Top")
52 (put 'user-mail-address 'custom-type 'string)
53 (put 'user-full-name 'custom-type 'string)
55 (defgroup message-various nil
56 "Various Message Variables"
57 :link '(custom-manual "(message)Various Message Variables")
60 (defgroup message-buffers nil
62 :link '(custom-manual "(message)Message Buffers")
65 (defgroup message-sending nil
67 :link '(custom-manual "(message)Sending Variables")
70 (defgroup message-interface nil
72 :link '(custom-manual "(message)Interface")
75 (defgroup message-forwarding nil
77 :link '(custom-manual "(message)Forwarding")
78 :group 'message-interface)
80 (defgroup message-insertion nil
82 :link '(custom-manual "(message)Insertion")
85 (defgroup message-headers nil
87 :link '(custom-manual "(message)Message Headers")
90 (defgroup message-news nil
91 "Composing News Messages"
94 (defgroup message-mail nil
95 "Composing Mail Messages"
98 (defgroup message-faces nil
99 "Faces used for message composing."
103 (defcustom message-directory "~/Mail/"
104 "*Directory from which all other mail file variables are derived."
105 :group 'message-various
108 (defcustom message-max-buffers 10
109 "*How many buffers to keep before starting to kill them off."
110 :group 'message-buffers
113 (defcustom message-send-rename-function nil
114 "Function called to rename the buffer after sending it."
115 :group 'message-buffers
118 (defcustom message-fcc-handler-function 'message-output
119 "*A function called to save outgoing articles.
120 This function will be called with the name of the file to store the
121 article in. The default function is `message-output' which saves in Unix
123 :type '(radio (function-item message-output)
124 (function :tag "Other"))
125 :group 'message-sending)
127 (defcustom message-courtesy-message
128 "The following message is a courtesy copy of an article\nthat has been posted to %s as well.\n\n"
129 "*This is inserted at the start of a mailed copy of a posted message.
130 If the string contains the format spec \"%s\", the Newsgroups
131 the article has been posted to will be inserted there.
132 If this variable is nil, no such courtesy message will be added."
133 :group 'message-sending
136 (defcustom message-ignored-bounced-headers "^\\(Received\\|Return-Path\\):"
137 "*Regexp that matches headers to be removed in resent bounced mail."
138 :group 'message-interface
142 (defcustom message-from-style 'default
143 "*Specifies how \"From\" headers look.
145 If `nil', they contain just the return address like:
147 If `parens', they look like:
148 king@grassland.com (Elvis Parsley)
149 If `angles', they look like:
150 Elvis Parsley <king@grassland.com>
152 Otherwise, most addresses look like `angles', but they look like
153 `parens' if `angles' would need quoting and `parens' would not."
154 :type '(choice (const :tag "simple" nil)
158 :group 'message-headers)
160 (defcustom message-syntax-checks nil
161 ;; Guess this one shouldn't be easy to customize...
162 "*Controls what syntax checks should not be performed on outgoing posts.
163 To disable checking of long signatures, for instance, add
164 `(signature . disabled)' to this list.
166 Don't touch this variable unless you really know what you're doing.
168 Checks include subject-cmsg multiple-headers sendsys message-id from
169 long-lines control-chars size new-text redirected-followup signature
170 approved sender empty empty-headers message-id from subject
171 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-ellipsis "\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-make-forward-subject-function
282 'message-forward-subject-author-subject
283 "*A list of functions that are called to generate a subject header for forwarded messages.
284 The subject generated by the previous function is passed into each
287 The provided functions are:
289 * message-forward-subject-author-subject (Source of article (author or
290 newsgroup)), in brackets followed by the subject
291 * message-forward-subject-fwd (Subject of article with 'Fwd:' prepended
293 :group 'message-forwarding
294 :type '(radio (function-item message-forward-subject-author-subject)
295 (function-item message-forward-subject-fwd)))
297 (defcustom message-forward-as-mime t
298 "*If non-nil, forward messages as an inline/rfc822 MIME section. Otherwise, directly inline the old message in the forwarded message."
299 :group 'message-forwarding
302 (defcustom message-forward-before-signature t
303 "*If non-nil, put forwarded message before signature, else after."
304 :group 'message-forwarding
307 (defcustom message-wash-forwarded-subjects nil
308 "*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."
309 :group 'message-forwarding
312 (defcustom message-ignored-resent-headers "^Return-receipt\\|^X-Gnus\\|^Gnus-Warning:"
313 "*All headers that match this regexp will be deleted when resending a message."
314 :group 'message-interface
317 (defcustom message-forward-ignored-headers "Content-Transfer-Encoding"
318 "*All headers that match this regexp will be deleted when forwarding a message."
319 :group 'message-forwarding
320 :type '(choice (const :tag "None" nil)
323 (defcustom message-ignored-cited-headers "."
324 "*Delete these headers from the messages you yank."
325 :group 'message-insertion
328 (defcustom message-cancel-message "I am canceling my own article.\n"
329 "Message to be inserted in the cancel message."
330 :group 'message-interface
333 ;; Useful to set in site-init.el
335 (defcustom message-send-mail-function 'message-send-mail-with-sendmail
336 "Function to call to send the current buffer as mail.
337 The headers should be delimited by a line whose contents match the
338 variable `mail-header-separator'.
340 Valid values include `message-send-mail-with-sendmail' (the default),
341 `message-send-mail-with-mh', `message-send-mail-with-qmail' and
343 :type '(radio (function-item message-send-mail-with-sendmail)
344 (function-item message-send-mail-with-mh)
345 (function-item message-send-mail-with-qmail)
346 (function-item smtpmail-send-it)
347 (function :tag "Other"))
348 :group 'message-sending
349 :group 'message-mail)
351 (defcustom message-send-news-function 'message-send-news
352 "Function to call to send the current buffer as news.
353 The headers should be delimited by a line whose contents match the
354 variable `mail-header-separator'."
355 :group 'message-sending
359 (defcustom message-reply-to-function nil
360 "Function that should return a list of headers.
361 This function should pick out addresses from the To, Cc, and From headers
362 and respond with new To and Cc headers."
363 :group 'message-interface
366 (defcustom message-wide-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-followup-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-use-followup-to 'ask
381 "*Specifies what to do with Followup-To header.
382 If nil, always ignore the header. If it is t, use its value, but
383 query before using the \"poster\" value. If it is the symbol `ask',
384 always query the user whether to use the value. If it is the symbol
385 `use', always use the value."
386 :group 'message-interface
387 :type '(choice (const :tag "ignore" nil)
391 (defcustom message-sendmail-f-is-evil nil
392 "*Non-nil means that \"-f username\" should not be added to the sendmail command line.
393 Doing so would be even more evil than leaving it out."
394 :group 'message-sending
397 ;; qmail-related stuff
398 (defcustom message-qmail-inject-program "/var/qmail/bin/qmail-inject"
399 "Location of the qmail-inject program."
400 :group 'message-sending
403 (defcustom message-qmail-inject-args nil
404 "Arguments passed to qmail-inject programs.
405 This should be a list of strings, one string for each argument.
407 For e.g., if you wish to set the envelope sender address so that bounces
408 go to the right place or to deal with listserv's usage of that address, you
409 might set this variable to '(\"-f\" \"you@some.where\")."
410 :group 'message-sending
411 :type '(repeat string))
413 (defvar message-cater-to-broken-inn t
414 "Non-nil means Gnus should not fold the `References' header.
415 Folding `References' makes ancient versions of INN create incorrect
418 (defvar gnus-post-method)
419 (defvar gnus-select-method)
420 (defcustom message-post-method
421 (cond ((and (boundp 'gnus-post-method)
422 (listp gnus-post-method)
425 ((boundp 'gnus-select-method)
428 "*Method used to post news.
429 Note that when posting from inside Gnus, for instance, this
430 variable isn't used."
432 :group 'message-sending
433 ;; This should be the `gnus-select-method' widget, but that might
434 ;; create a dependence to `gnus.el'.
437 (defcustom message-generate-headers-first nil
438 "*If non-nil, generate all possible headers before composing."
439 :group 'message-headers
442 (defcustom message-setup-hook nil
443 "Normal hook, run each time a new outgoing message is initialized.
444 The function `message-setup' runs this hook."
445 :group 'message-various
448 (defcustom message-cancel-hook nil
449 "Hook run when cancelling articles."
450 :group 'message-various
453 (defcustom message-signature-setup-hook nil
454 "Normal hook, run each time a new outgoing message is initialized.
455 It is run after the headers have been inserted and before
456 the signature is inserted."
457 :group 'message-various
460 (defcustom message-mode-hook nil
461 "Hook run in message mode buffers."
462 :group 'message-various
465 (defcustom message-header-hook nil
466 "Hook run in a message mode buffer narrowed to the headers."
467 :group 'message-various
470 (defcustom message-header-setup-hook nil
471 "Hook called narrowed to the headers when setting up a message buffer."
472 :group 'message-various
476 (defcustom message-citation-line-function 'message-insert-citation-line
477 "*Function called to insert the \"Whomever writes:\" line."
479 :group 'message-insertion)
482 (defcustom message-yank-prefix "> "
483 "*Prefix inserted on the lines of yanked messages."
485 :group 'message-insertion)
487 (defcustom message-indentation-spaces 3
488 "*Number of spaces to insert at the beginning of each cited line.
489 Used by `message-yank-original' via `message-yank-cite'."
490 :group 'message-insertion
494 (defcustom message-cite-function 'message-cite-original
495 "*Function for citing an original message.
496 Predefined functions include `message-cite-original' and
497 `message-cite-original-without-signature'.
498 Note that `message-cite-original' uses `mail-citation-hook' if that is non-nil."
499 :type '(radio (function-item message-cite-original)
500 (function-item message-cite-original-without-signature)
501 (function-item sc-cite-original)
502 (function :tag "Other"))
503 :group 'message-insertion)
506 (defcustom message-indent-citation-function 'message-indent-citation
507 "*Function for modifying a citation just inserted in the mail buffer.
508 This can also be a list of functions. Each function can find the
509 citation between (point) and (mark t). And each function should leave
510 point and mark around the citation text as modified."
512 :group 'message-insertion)
514 (defvar message-abbrevs-loaded nil)
517 (defcustom message-signature t
518 "*String to be inserted at the end of the message buffer.
519 If t, the `message-signature-file' file will be inserted instead.
520 If a function, the result from the function will be used instead.
521 If a form, the result from the form will be used instead."
523 :group 'message-insertion)
526 (defcustom message-signature-file "~/.signature"
527 "*File containing the text inserted at end of message buffer."
529 :group 'message-insertion)
531 (defcustom message-distribution-function nil
532 "*Function called to return a Distribution header."
534 :group 'message-headers
537 (defcustom message-expires 14
538 "Number of days before your article expires."
540 :group 'message-headers
541 :link '(custom-manual "(message)News Headers")
544 (defcustom message-user-path nil
545 "If nil, use the NNTP server name in the Path header.
546 If stringp, use this; if non-nil, use no host name (user name only)."
548 :group 'message-headers
549 :link '(custom-manual "(message)News Headers")
550 :type '(choice (const :tag "nntp" nil)
552 (sexp :tag "none" :format "%t" t)))
554 (defvar message-reply-buffer nil)
555 (defvar message-reply-headers nil)
556 (defvar message-newsreader nil)
557 (defvar message-mailer nil)
558 (defvar message-sent-message-via nil)
559 (defvar message-checksum nil)
560 (defvar message-send-actions nil
561 "A list of actions to be performed upon successful sending of a message.")
562 (defvar message-exit-actions nil
563 "A list of actions to be performed upon exiting after sending a message.")
564 (defvar message-kill-actions nil
565 "A list of actions to be performed before killing a message buffer.")
566 (defvar message-postpone-actions nil
567 "A list of actions to be performed after postponing a message.")
569 (define-widget 'message-header-lines 'text
570 "All header lines must be LFD terminated."
573 :error "All header lines must be newline terminated")
575 (defcustom message-default-headers ""
576 "*A string containing header lines to be inserted in outgoing messages.
577 It is inserted before you edit the message, so you can edit or delete
579 :group 'message-headers
580 :type 'message-header-lines)
582 (defcustom message-default-mail-headers ""
583 "*A string of header lines to be inserted in outgoing mails."
584 :group 'message-headers
586 :type 'message-header-lines)
588 (defcustom message-default-news-headers ""
589 "*A string of header lines to be inserted in outgoing news articles."
590 :group 'message-headers
592 :type 'message-header-lines)
594 ;; Note: could use /usr/ucb/mail instead of sendmail;
595 ;; options -t, and -v if not interactive.
596 (defcustom message-mailer-swallows-blank-line
597 (if (and (string-match "sparc-sun-sunos\\(\\'\\|[^5]\\)"
598 system-configuration)
599 (file-readable-p "/etc/sendmail.cf")
600 (let ((buffer (get-buffer-create " *temp*")))
604 (insert-file-contents "/etc/sendmail.cf")
605 (goto-char (point-min))
606 (let ((case-fold-search nil))
607 (re-search-forward "^OR\\>" nil t)))
608 (kill-buffer buffer))))
609 ;; According to RFC822, "The field-name must be composed of printable
610 ;; ASCII characters (i. e., characters that have decimal values between
611 ;; 33 and 126, except colon)", i. e., any chars except ctl chars,
613 '(looking-at "[ \t]\\|[][!\"#$%&'()*+,-./0-9;<=>?@A-Z\\\\^_`a-z{|}~]+:"))
614 "*Set this non-nil if the system's mailer runs the header and body together.
615 \(This problem exists on Sunos 4 when sendmail is run in remote mode.)
616 The value should be an expression to test whether the problem will
618 :group 'message-sending
621 ;; Ignore errors in case this is used in Emacs 19.
622 ;; Don't use ignore-errors because this is copied into loaddefs.el.
625 (define-mail-user-agent 'message-user-agent
626 'message-mail 'message-send-and-exit
627 'message-kill-buffer 'message-send-hook))
629 (defvar message-mh-deletable-headers '(Message-ID Date Lines Sender)
630 "If non-nil, delete the deletable headers before feeding to mh.")
632 (defvar message-send-method-alist
633 '((news message-news-p message-send-via-news)
634 (mail message-mail-p message-send-via-mail))
635 "Alist of ways to send outgoing messages.
636 Each element has the form
638 \(TYPE PREDICATE FUNCTION)
640 where TYPE is a symbol that names the method; PREDICATE is a function
641 called without any parameters to determine whether the message is
642 a message of type TYPE; and FUNCTION is a function to be called if
643 PREDICATE returns non-nil. FUNCTION is called with one parameter --
646 (defvar message-mail-alias-type 'abbrev
647 "*What alias expansion type to use in Message buffers.
648 The default is `abbrev', which uses mailabbrev. nil switches
651 (defcustom message-auto-save-directory
652 (nnheader-concat message-directory "drafts/")
653 "*Directory where Message auto-saves buffers if Gnus isn't running.
654 If nil, Message won't auto-save."
655 :group 'message-buffers
658 (defcustom message-buffer-naming-style 'unique
659 "*The way new message buffers are named.
660 Valid valued are `unique' and `unsent'."
661 :group 'message-buffers
662 :type '(choice (const :tag "unique" unique)
663 (const :tag "unsent" unsent)))
665 (defcustom message-default-charset nil
666 "Default charset used in non-MULE XEmacsen."
670 (defcustom message-dont-reply-to-names rmail-dont-reply-to-names
671 "*A regexp specifying names to prune when doing wide replies.
672 A value of nil means exclude your own name only."
674 :type '(choice (const :tag "Yourself" nil)
677 ;;; Internal variables.
678 ;;; Well, not really internal.
680 (defvar message-mode-syntax-table
681 (let ((table (copy-syntax-table text-mode-syntax-table)))
682 (modify-syntax-entry ?% ". " table)
683 (modify-syntax-entry ?> ". " table)
684 (modify-syntax-entry ?< ". " table)
686 "Syntax table used while in Message mode.")
688 (defvar message-mode-abbrev-table text-mode-abbrev-table
689 "Abbrev table used in Message mode buffers.
690 Defaults to `text-mode-abbrev-table'.")
691 (defgroup message-headers nil
693 :link '(custom-manual "(message)Variables")
696 (defface message-header-to-face
699 (:foreground "green2" :bold t))
702 (:foreground "MidnightBlue" :bold t))
704 (:bold t :italic t)))
705 "Face used for displaying From headers."
706 :group 'message-faces)
708 (defface message-header-cc-face
711 (:foreground "green4" :bold t))
714 (:foreground "MidnightBlue"))
717 "Face used for displaying Cc headers."
718 :group 'message-faces)
720 (defface message-header-subject-face
723 (:foreground "green3"))
726 (:foreground "navy blue" :bold t))
729 "Face used for displaying subject headers."
730 :group 'message-faces)
732 (defface message-header-newsgroups-face
735 (:foreground "yellow" :bold t :italic t))
738 (:foreground "blue4" :bold t :italic t))
740 (:bold t :italic t)))
741 "Face used for displaying newsgroups headers."
742 :group 'message-faces)
744 (defface message-header-other-face
747 (:foreground "#b00000"))
750 (:foreground "steel blue"))
752 (:bold t :italic t)))
753 "Face used for displaying newsgroups headers."
754 :group 'message-faces)
756 (defface message-header-name-face
759 (:foreground "DarkGreen"))
762 (:foreground "cornflower blue"))
765 "Face used for displaying header names."
766 :group 'message-faces)
768 (defface message-header-xheader-face
771 (:foreground "blue"))
774 (:foreground "blue"))
777 "Face used for displaying X-Header headers."
778 :group 'message-faces)
780 (defface message-separator-face
783 (:foreground "blue3"))
786 (:foreground "brown"))
789 "Face used for displaying the separator."
790 :group 'message-faces)
792 (defface message-cited-text-face
801 "Face used for displaying cited text names."
802 :group 'message-faces)
804 (defface message-mml-face
807 (:foreground "ForestGreen"))
810 (:foreground "ForestGreen"))
813 "Face used for displaying MML."
814 :group 'message-faces)
816 (defvar message-font-lock-keywords
817 (let* ((cite-prefix "A-Za-z")
818 (cite-suffix (concat cite-prefix "0-9_.@-"))
819 (content "[ \t]*\\(.+\\(\n[ \t].*\\)*\\)"))
820 `((,(concat "^\\([Tt]o:\\)" content)
821 (1 'message-header-name-face)
822 (2 'message-header-to-face nil t))
823 (,(concat "^\\(^[GBF]?[Cc][Cc]:\\|^[Rr]eply-[Tt]o:\\)" content)
824 (1 'message-header-name-face)
825 (2 'message-header-cc-face nil t))
826 (,(concat "^\\([Ss]ubject:\\)" content)
827 (1 'message-header-name-face)
828 (2 'message-header-subject-face nil t))
829 (,(concat "^\\([Nn]ewsgroups:\\|Followup-[Tt]o:\\)" content)
830 (1 'message-header-name-face)
831 (2 'message-header-newsgroups-face nil t))
832 (,(concat "^\\([A-Z][^: \n\t]+:\\)" content)
833 (1 'message-header-name-face)
834 (2 'message-header-other-face nil t))
835 (,(concat "^\\(X-[A-Za-z0-9-]+\\|In-Reply-To\\):" content)
836 (1 'message-header-name-face)
837 (2 'message-header-name-face))
838 ,@(if (and mail-header-separator
839 (not (equal mail-header-separator "")))
840 `((,(concat "^\\(" (regexp-quote mail-header-separator) "\\)$")
841 1 'message-separator-face))
844 "\\([" cite-prefix "]+[" cite-suffix "]*\\)?"
846 (0 'message-cited-text-face))
847 ("<#/?\\(multipart\\|part\\|external\\).*>"
848 (0 'message-mml-face))))
849 "Additional expressions to highlight in Message mode.")
851 ;; XEmacs does it like this. For Emacs, we have to set the
852 ;; `font-lock-defaults' buffer-local variable.
853 (put 'message-mode 'font-lock-defaults '(message-font-lock-keywords t))
855 (defvar message-face-alist
856 '((bold . bold-region)
857 (underline . underline-region)
858 (default . (lambda (b e)
860 (ununderline-region b e))))
861 "Alist of mail and news faces for facemenu.
862 The cdr of ech entry is a function for applying the face to a region.")
864 (defcustom message-send-hook nil
865 "Hook run before sending messages."
866 :group 'message-various
867 :options '(ispell-message)
870 (defcustom message-send-mail-hook nil
871 "Hook run before sending mail messages."
872 :group 'message-various
875 (defcustom message-send-news-hook nil
876 "Hook run before sending news messages."
877 :group 'message-various
880 (defcustom message-sent-hook nil
881 "Hook run after sending messages."
882 :group 'message-various
885 (defvar message-send-coding-system 'binary
886 "Coding system to encode outgoing mail.")
888 (defvar message-draft-coding-system
889 mm-auto-save-coding-system
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 "^ *---+ +Undelivered message follows +---+ *$\\|"
968 "^|? *---+ +Message text follows: +---+ *|?$")
969 "A regexp that matches the separator before the text of a failed message.")
971 (defvar message-header-format-alist
973 (To . message-fill-address)
974 (Cc . message-fill-address)
985 (References . message-shorten-references)
987 "Alist used for formatting headers.")
990 (autoload 'message-setup-toolbar "messagexmas")
991 (autoload 'mh-new-draft-name "mh-comp")
992 (autoload 'mh-send-letter "mh-comp")
993 (autoload 'gnus-point-at-eol "gnus-util")
994 (autoload 'gnus-point-at-bol "gnus-util")
995 (autoload 'gnus-output-to-mail "gnus-util")
996 (autoload 'mail-abbrev-in-expansion-header-p "mailabbrev")
997 (autoload 'nndraft-request-associate-buffer "nndraft")
998 (autoload 'nndraft-request-expire-articles "nndraft")
999 (autoload 'gnus-open-server "gnus-int")
1000 (autoload 'gnus-request-post "gnus-int")
1001 (autoload 'gnus-alive-p "gnus-util")
1002 (autoload 'rmail-output "rmail"))
1007 ;;; Utility functions.
1010 (defmacro message-y-or-n-p (question show &rest text)
1011 "Ask QUESTION, displaying the rest of the arguments in a temp. buffer if SHOW"
1012 `(message-talkative-question 'y-or-n-p ,question ,show ,@text))
1014 ;; Delete the current line (and the next N lines.);
1015 (defmacro message-delete-line (&optional n)
1016 `(delete-region (progn (beginning-of-line) (point))
1017 (progn (forward-line ,(or n 1)) (point))))
1019 (defun message-tokenize-header (header &optional separator)
1020 "Split HEADER into a list of header elements.
1021 \",\" is used as the separator."
1024 (let ((regexp (format "[%s]+" (or separator ",")))
1029 (message-set-work-buffer)
1031 (goto-char (point-min))
1036 (cond ((and (> (point) beg)
1038 (and (looking-at regexp)
1041 (push (buffer-substring beg (point)) elems)
1042 (setq beg (match-end 0)))
1043 ((eq (char-after) ?\")
1044 (setq quoted (not quoted)))
1045 ((and (eq (char-after) ?\()
1048 ((and (eq (char-after) ?\))
1051 (nreverse elems)))))
1053 (defun message-mail-file-mbox-p (file)
1054 "Say whether FILE looks like a Unix mbox file."
1055 (when (and (file-exists-p file)
1056 (file-readable-p file)
1057 (file-regular-p file))
1059 (nnheader-insert-file-contents file)
1060 (goto-char (point-min))
1061 (looking-at message-unix-mail-delimiter))))
1063 (defun message-fetch-field (header &optional not-all)
1064 "The same as `mail-fetch-field', only remove all newlines."
1065 (let* ((inhibit-point-motion-hooks t)
1066 (case-fold-search t)
1067 (value (mail-fetch-field header nil (not not-all))))
1069 (while (string-match "\n[\t ]+" value)
1070 (setq value (replace-match " " t t value)))
1071 ;; We remove all text props.
1072 (format "%s" value))))
1074 (defun message-narrow-to-field ()
1075 "Narrow the buffer to the header on the current line."
1081 (if (re-search-forward "^[^ \n\t]" nil t)
1086 (goto-char (point-min)))
1088 (defun message-add-header (&rest headers)
1089 "Add the HEADERS to the message header, skipping those already present."
1092 (unless (string-match "^\\([^:]+\\):[ \t]*[^ \t]" (car headers))
1093 (error "Invalid header `%s'" (car headers)))
1094 (setq hclean (match-string 1 (car headers)))
1096 (message-narrow-to-headers)
1097 (unless (re-search-forward (concat "^" (regexp-quote hclean) ":") nil t)
1098 (insert (car headers) ?\n))))
1099 (setq headers (cdr headers))))
1102 (defun message-fetch-reply-field (header)
1103 "Fetch FIELD from the message we're replying to."
1104 (when (and message-reply-buffer
1105 (buffer-name message-reply-buffer))
1107 (set-buffer message-reply-buffer)
1108 (message-fetch-field header))))
1110 (defun message-set-work-buffer ()
1111 (if (get-buffer " *message work*")
1113 (set-buffer " *message work*")
1115 (set-buffer (get-buffer-create " *message work*"))
1116 (kill-all-local-variables)
1117 (mm-enable-multibyte)))
1119 (defun message-functionp (form)
1120 "Return non-nil if FORM is funcallable."
1121 (or (and (symbolp form) (fboundp form))
1122 (and (listp form) (eq (car form) 'lambda))
1123 (byte-code-function-p form)))
1125 (defun message-strip-subject-re (subject)
1126 "Remove \"Re:\" from subject lines."
1127 (if (string-match message-subject-re-regexp subject)
1128 (substring subject (match-end 0))
1131 (defun message-remove-header (header &optional is-regexp first reverse)
1132 "Remove HEADER in the narrowed buffer.
1133 If REGEXP, HEADER is a regular expression.
1134 If FIRST, only remove the first instance of the header.
1135 Return the number of headers removed."
1136 (goto-char (point-min))
1137 (let ((regexp (if is-regexp header (concat "^" (regexp-quote header) ":")))
1139 (case-fold-search t)
1141 (while (and (not (eobp))
1144 (not (looking-at regexp))
1145 (looking-at regexp))
1152 ;; There might be a continuation header, so we have to search
1153 ;; until we find a new non-continuation line.
1156 (if (re-search-forward "^[^ \t]" nil t)
1157 (goto-char (match-beginning 0))
1160 (if (re-search-forward "^[^ \t]" nil t)
1161 (goto-char (match-beginning 0))
1162 (goto-char (point-max)))))
1165 (defun message-remove-first-header (header)
1166 "Remove the first instance of HEADER if there is more than one."
1168 (regexp (concat "^" (regexp-quote header) ":")))
1170 (goto-char (point-min))
1171 (while (re-search-forward regexp nil t)
1174 (message-remove-header header nil t)
1177 (defun message-narrow-to-headers ()
1178 "Narrow the buffer to the head of the message."
1181 (goto-char (point-min))
1182 (if (re-search-forward
1183 (concat "^" (regexp-quote mail-header-separator) "\n") nil t)
1186 (goto-char (point-min)))
1188 (defun message-narrow-to-head ()
1189 "Narrow the buffer to the head of the message.
1190 Point is left at the beginning of the narrowed-to region."
1193 (goto-char (point-min))
1194 (if (search-forward "\n\n" nil 1)
1197 (goto-char (point-min)))
1199 (defun message-narrow-to-headers-or-head ()
1200 "Narrow the buffer to the head of the message."
1203 (goto-char (point-min))
1206 (concat "^" (regexp-quote mail-header-separator) "\n") nil t)
1207 (match-beginning 0))
1208 ((search-forward "\n\n" nil t)
1212 (goto-char (point-min)))
1214 (defun message-news-p ()
1215 "Say whether the current buffer contains a news message."
1216 (and (not message-this-is-mail)
1217 (or message-this-is-news
1220 (message-narrow-to-headers)
1221 (and (message-fetch-field "newsgroups")
1222 (not (message-fetch-field "posted-to"))))))))
1224 (defun message-mail-p ()
1225 "Say whether the current buffer contains a mail message."
1226 (and (not message-this-is-news)
1227 (or message-this-is-mail
1230 (message-narrow-to-headers)
1231 (or (message-fetch-field "to")
1232 (message-fetch-field "cc")
1233 (message-fetch-field "bcc")))))))
1235 (defun message-next-header ()
1236 "Go to the beginning of the next header."
1238 (or (eobp) (forward-char 1))
1239 (not (if (re-search-forward "^[^ \t]" nil t)
1241 (goto-char (point-max)))))
1243 (defun message-sort-headers-1 ()
1244 "Sort the buffer as headers using `message-rank' text props."
1245 (goto-char (point-min))
1248 nil 'message-next-header
1250 (message-next-header)
1254 (or (get-text-property (point) 'message-rank)
1257 (defun message-sort-headers ()
1258 "Sort the headers of the current message according to `message-header-format-alist'."
1262 (let ((max (1+ (length message-header-format-alist)))
1264 (message-narrow-to-headers)
1265 (while (re-search-forward "^[^ \n]+:" nil t)
1267 (match-beginning 0) (1+ (match-beginning 0))
1269 (if (setq rank (length (memq (assq (intern (buffer-substring
1271 (1- (match-end 0))))
1272 message-header-format-alist)
1273 message-header-format-alist)))
1276 (message-sort-headers-1))))
1286 (defvar message-mode-map nil)
1288 (unless message-mode-map
1289 (setq message-mode-map (make-keymap))
1290 (set-keymap-parent message-mode-map text-mode-map)
1291 (define-key message-mode-map "\C-c?" 'describe-mode)
1293 (define-key message-mode-map "\C-c\C-f\C-t" 'message-goto-to)
1294 (define-key message-mode-map "\C-c\C-f\C-b" 'message-goto-bcc)
1295 (define-key message-mode-map "\C-c\C-f\C-w" 'message-goto-fcc)
1296 (define-key message-mode-map "\C-c\C-f\C-c" 'message-goto-cc)
1297 (define-key message-mode-map "\C-c\C-f\C-s" 'message-goto-subject)
1298 (define-key message-mode-map "\C-c\C-f\C-r" 'message-goto-reply-to)
1299 (define-key message-mode-map "\C-c\C-f\C-n" 'message-goto-newsgroups)
1300 (define-key message-mode-map "\C-c\C-f\C-d" 'message-goto-distribution)
1301 (define-key message-mode-map "\C-c\C-f\C-f" 'message-goto-followup-to)
1302 (define-key message-mode-map "\C-c\C-f\C-k" 'message-goto-keywords)
1303 (define-key message-mode-map "\C-c\C-f\C-u" 'message-goto-summary)
1304 (define-key message-mode-map "\C-c\C-b" 'message-goto-body)
1305 (define-key message-mode-map "\C-c\C-i" 'message-goto-signature)
1307 (define-key message-mode-map "\C-c\C-t" 'message-insert-to)
1308 (define-key message-mode-map "\C-c\C-n" 'message-insert-newsgroups)
1310 (define-key message-mode-map "\C-c\C-y" 'message-yank-original)
1311 (define-key message-mode-map "\C-c\M-\C-y" 'message-yank-buffer)
1312 (define-key message-mode-map "\C-c\C-q" 'message-fill-yanked-message)
1313 (define-key message-mode-map "\C-c\C-w" 'message-insert-signature)
1314 (define-key message-mode-map "\C-c\M-h" 'message-insert-headers)
1315 (define-key message-mode-map "\C-c\C-r" 'message-caesar-buffer-body)
1316 (define-key message-mode-map "\C-c\C-o" 'message-sort-headers)
1317 (define-key message-mode-map "\C-c\M-r" 'message-rename-buffer)
1319 (define-key message-mode-map "\C-c\C-c" 'message-send-and-exit)
1320 (define-key message-mode-map "\C-c\C-s" 'message-send)
1321 (define-key message-mode-map "\C-c\C-k" 'message-kill-buffer)
1322 (define-key message-mode-map "\C-c\C-d" 'message-dont-send)
1324 (define-key message-mode-map "\C-c\C-e" 'message-elide-region)
1325 (define-key message-mode-map "\C-c\C-v" 'message-delete-not-region)
1326 (define-key message-mode-map "\C-c\C-z" 'message-kill-to-signature)
1327 (define-key message-mode-map "\M-\r" 'message-newline-and-reformat)
1329 (define-key message-mode-map "\C-c\C-a" 'mml-attach-file)
1331 (define-key message-mode-map "\t" 'message-tab))
1334 message-mode-menu message-mode-map "Message Menu."
1336 ["Sort Headers" message-sort-headers t]
1337 ["Yank Original" message-yank-original t]
1338 ["Fill Yanked Message" message-fill-yanked-message t]
1339 ["Insert Signature" message-insert-signature t]
1340 ["Caesar (rot13) Message" message-caesar-buffer-body t]
1341 ["Caesar (rot13) Region" message-caesar-region (mark t)]
1342 ["Elide Region" message-elide-region (mark t)]
1343 ["Delete Outside Region" message-delete-not-region (mark t)]
1344 ["Kill To Signature" message-kill-to-signature t]
1345 ["Newline and Reformat" message-newline-and-reformat t]
1346 ["Rename buffer" message-rename-buffer t]
1347 ["Spellcheck" ispell-message t]
1348 ["Attach file as MIME" mml-attach-file t]
1350 ["Send Message" message-send-and-exit t]
1351 ["Abort Message" message-dont-send t]
1352 ["Kill Message" message-kill-buffer t]))
1355 message-mode-field-menu message-mode-map ""
1357 ["Fetch To" message-insert-to t]
1358 ["Fetch Newsgroups" message-insert-newsgroups t]
1360 ["To" message-goto-to t]
1361 ["Subject" message-goto-subject t]
1362 ["Cc" message-goto-cc t]
1363 ["Reply-To" message-goto-reply-to t]
1364 ["Summary" message-goto-summary t]
1365 ["Keywords" message-goto-keywords t]
1366 ["Newsgroups" message-goto-newsgroups t]
1367 ["Followup-To" message-goto-followup-to t]
1368 ["Distribution" message-goto-distribution t]
1369 ["Body" message-goto-body t]
1370 ["Signature" message-goto-signature t]))
1372 (defvar facemenu-add-face-function)
1373 (defvar facemenu-remove-face-function)
1376 (defun message-mode ()
1377 "Major mode for editing mail and news to be sent.
1378 Like Text Mode but with these additional commands:
1379 C-c C-s message-send (send the message) C-c C-c message-send-and-exit
1380 C-c C-d Pospone sending the message C-c C-k Kill the message
1381 C-c C-f move to a header field (and create it if there isn't):
1382 C-c C-f C-t move to To C-c C-f C-s move to Subject
1383 C-c C-f C-c move to Cc C-c C-f C-b move to Bcc
1384 C-c C-f C-w move to Fcc C-c C-f C-r move to Reply-To
1385 C-c C-f C-u move to Summary C-c C-f C-n move to Newsgroups
1386 C-c C-f C-k move to Keywords C-c C-f C-d move to Distribution
1387 C-c C-f C-f move to Followup-To
1388 C-c C-t message-insert-to (add a To header to a news followup)
1389 C-c C-n message-insert-newsgroups (add a Newsgroup header to a news reply)
1390 C-c C-b message-goto-body (move to beginning of message text).
1391 C-c C-i message-goto-signature (move to the beginning of the signature).
1392 C-c C-w message-insert-signature (insert `message-signature-file' file).
1393 C-c C-y message-yank-original (insert current message, if any).
1394 C-c C-q message-fill-yanked-message (fill what was yanked).
1395 C-c C-e message-elide-region (elide the text between point and mark).
1396 C-c C-v message-delete-not-region (remove the text outside the region).
1397 C-c C-z message-kill-to-signature (kill the text up to the signature).
1398 C-c C-r message-caesar-buffer-body (rot13 the message body).
1399 C-c C-a mml-attach-file (attach a file as MIME).
1400 M-RET message-newline-and-reformat (break the line and reformat)."
1402 (kill-all-local-variables)
1403 (set (make-local-variable 'message-reply-buffer) nil)
1404 (make-local-variable 'message-send-actions)
1405 (make-local-variable 'message-exit-actions)
1406 (make-local-variable 'message-kill-actions)
1407 (make-local-variable 'message-postpone-actions)
1408 (make-local-variable 'message-draft-article)
1409 (make-local-hook 'kill-buffer-hook)
1410 (set-syntax-table message-mode-syntax-table)
1411 (use-local-map message-mode-map)
1412 (setq local-abbrev-table message-mode-abbrev-table)
1413 (setq major-mode 'message-mode)
1414 (setq mode-name "Message")
1415 (setq buffer-offer-save t)
1416 (make-local-variable 'facemenu-add-face-function)
1417 (make-local-variable 'facemenu-remove-face-function)
1418 (setq facemenu-add-face-function
1420 (let ((face-fun (cdr (assq face message-face-alist))))
1422 (funcall face-fun (point) end)
1423 (error "Face %s not configured for %s mode" face mode-name)))
1425 facemenu-remove-face-function t)
1426 (make-local-variable 'paragraph-separate)
1427 (make-local-variable 'paragraph-start)
1428 ;; `-- ' precedes the signature. `-----' appears at the start of the
1429 ;; lines that delimit forwarded messages.
1430 ;; Lines containing just >= 3 dashes, perhaps after whitespace,
1431 ;; are also sometimes used and should be separators.
1432 (setq paragraph-start
1433 (concat (regexp-quote mail-header-separator)
1434 "$\\|[ \t]*[a-z0-9A-Z]*>+[ \t]*$\\|[ \t]*$\\|"
1437 ;;!!! Uhm... shurely this can't be right?
1438 "[> " (regexp-quote message-yank-prefix) "]+$"))
1439 (setq paragraph-separate paragraph-start)
1440 (make-local-variable 'message-reply-headers)
1441 (setq message-reply-headers nil)
1442 (make-local-variable 'message-newsreader)
1443 (make-local-variable 'message-mailer)
1444 (make-local-variable 'message-post-method)
1445 (set (make-local-variable 'message-sent-message-via) nil)
1446 (set (make-local-variable 'message-checksum) nil)
1447 (set (make-local-variable 'message-mime-part) 0)
1448 ;;(when (fboundp 'mail-hist-define-keys)
1449 ;; (mail-hist-define-keys))
1450 (when (string-match "XEmacs\\|Lucid" emacs-version)
1451 (message-setup-toolbar))
1452 (easy-menu-add message-mode-menu message-mode-map)
1453 (easy-menu-add message-mode-field-menu message-mode-map)
1454 ;; Allow mail alias things.
1455 (when (eq message-mail-alias-type 'abbrev)
1456 (if (fboundp 'mail-abbrevs-setup)
1457 (mail-abbrevs-setup)
1458 (mail-aliases-setup)))
1459 (message-set-auto-save-file-name)
1460 (unless (string-match "XEmacs" emacs-version)
1461 (set (make-local-variable 'font-lock-defaults)
1462 '(message-font-lock-keywords t)))
1463 (make-local-variable 'adaptive-fill-regexp)
1464 (setq adaptive-fill-regexp
1465 (concat "[ \t]*[-a-z0-9A-Z]*\\(>[ \t]*\\)+[ \t]*\\|" adaptive-fill-regexp))
1466 (unless (boundp 'adaptive-fill-first-line-regexp)
1467 (setq adaptive-fill-first-line-regexp nil))
1468 (make-local-variable 'adaptive-fill-first-line-regexp)
1469 (setq adaptive-fill-first-line-regexp
1470 (concat "[ \t]*[-a-z0-9A-Z]*\\(>[ \t]*\\)+[ \t]*\\|"
1471 adaptive-fill-first-line-regexp))
1472 (make-local-variable 'auto-fill-inhibit-regexp)
1473 (setq auto-fill-inhibit-regexp "^[A-Z][^: \n\t]+:")
1474 (mm-enable-multibyte)
1475 (make-local-variable 'indent-tabs-mode) ;Turn off tabs for indentation.
1476 (setq indent-tabs-mode nil)
1478 (run-hooks 'text-mode-hook 'message-mode-hook))
1483 ;;; Message mode commands
1486 ;;; Movement commands
1488 (defun message-goto-to ()
1489 "Move point to the To header."
1491 (message-position-on-field "To"))
1493 (defun message-goto-subject ()
1494 "Move point to the Subject header."
1496 (message-position-on-field "Subject"))
1498 (defun message-goto-cc ()
1499 "Move point to the Cc header."
1501 (message-position-on-field "Cc" "To"))
1503 (defun message-goto-bcc ()
1504 "Move point to the Bcc header."
1506 (message-position-on-field "Bcc" "Cc" "To"))
1508 (defun message-goto-fcc ()
1509 "Move point to the Fcc header."
1511 (message-position-on-field "Fcc" "To" "Newsgroups"))
1513 (defun message-goto-reply-to ()
1514 "Move point to the Reply-To header."
1516 (message-position-on-field "Reply-To" "Subject"))
1518 (defun message-goto-newsgroups ()
1519 "Move point to the Newsgroups header."
1521 (message-position-on-field "Newsgroups"))
1523 (defun message-goto-distribution ()
1524 "Move point to the Distribution header."
1526 (message-position-on-field "Distribution"))
1528 (defun message-goto-followup-to ()
1529 "Move point to the Followup-To header."
1531 (message-position-on-field "Followup-To" "Newsgroups"))
1533 (defun message-goto-keywords ()
1534 "Move point to the Keywords header."
1536 (message-position-on-field "Keywords" "Subject"))
1538 (defun message-goto-summary ()
1539 "Move point to the Summary header."
1541 (message-position-on-field "Summary" "Subject"))
1543 (defun message-goto-body ()
1544 "Move point to the beginning of the message body."
1546 (if (looking-at "[ \t]*\n") (expand-abbrev))
1547 (goto-char (point-min))
1548 (or (search-forward (concat "\n" mail-header-separator "\n") nil t)
1549 (search-forward "\n\n" nil t)))
1551 (defun message-goto-eoh ()
1552 "Move point to the end of the headers."
1557 (defun message-goto-signature ()
1558 "Move point to the beginning of the message signature.
1559 If there is no signature in the article, go to the end and
1562 (goto-char (point-min))
1563 (if (re-search-forward message-signature-separator nil t)
1565 (goto-char (point-max))
1570 (defun message-insert-to (&optional force)
1571 "Insert a To header that points to the author of the article being replied to.
1572 If the original author requested not to be sent mail, the function signals
1574 With the prefix argument FORCE, insert the header anyway."
1576 (let ((co (message-fetch-reply-field "mail-copies-to")))
1577 (when (and (null force)
1579 (or (equal (downcase co) "never")
1580 (equal (downcase co) "nobody")))
1581 (error "The user has requested not to have copies sent via mail")))
1582 (when (and (message-position-on-field "To")
1583 (mail-fetch-field "to")
1584 (not (string-match "\\` *\\'" (mail-fetch-field "to"))))
1586 (insert (or (message-fetch-reply-field "reply-to")
1587 (message-fetch-reply-field "from") "")))
1589 (defun message-widen-reply ()
1590 "Widen the reply to include maximum recipients."
1593 (and message-reply-buffer
1594 (buffer-name message-reply-buffer)
1596 (set-buffer message-reply-buffer)
1597 (message-get-reply-headers t)))))
1600 (message-narrow-to-headers)
1601 (dolist (elem follow-to)
1602 (message-remove-header (symbol-name (car elem)))
1603 (goto-char (point-min))
1604 (insert (symbol-name (car elem)) ": "
1605 (cdr elem) "\n"))))))
1607 (defun message-insert-newsgroups ()
1608 "Insert the Newsgroups header from the article being replied to."
1610 (when (and (message-position-on-field "Newsgroups")
1611 (mail-fetch-field "newsgroups")
1612 (not (string-match "\\` *\\'" (mail-fetch-field "newsgroups"))))
1614 (insert (or (message-fetch-reply-field "newsgroups") "")))
1618 ;;; Various commands
1620 (defun message-delete-not-region (beg end)
1621 "Delete everything in the body of the current message that is outside of the region."
1625 (delete-region (point) (if (not (message-goto-signature))
1631 (delete-region beg (progn (message-goto-body)
1634 (when (message-goto-signature)
1637 (defun message-kill-to-signature ()
1638 "Deletes all text up to the signature."
1640 (let ((point (point)))
1641 (message-goto-signature)
1644 (kill-region point (point))
1648 (defun message-newline-and-reformat ()
1649 "Insert four newlines, and then reformat if inside quoted text."
1651 (let ((prefix "[]>»|:}+ \t]*")
1652 (supercite-thing "[-._a-zA-Z0-9]*[>]+[ \t]*")
1657 (when (looking-at (concat prefix
1659 (setq quoted (match-string 0))))
1661 (setq point (point))
1663 (delete-region (point) (re-search-forward "[ \t]*"))
1666 (fill-paragraph nil)
1670 (defun message-insert-signature (&optional force)
1671 "Insert a signature. See documentation for the `message-signature' variable."
1672 (interactive (list 0))
1675 ((and (null message-signature)
1678 (goto-char (point-max))
1679 (not (re-search-backward message-signature-separator nil t))))
1680 ((and (null message-signature)
1683 ((message-functionp message-signature)
1684 (funcall message-signature))
1685 ((listp message-signature)
1686 (eval message-signature))
1687 (t message-signature)))
1689 (cond ((stringp signature)
1691 ((and (eq t signature)
1692 message-signature-file
1693 (file-exists-p message-signature-file))
1696 (goto-char (point-max))
1697 ;; Insert the signature.
1701 (if (eq signature t)
1702 (insert-file-contents message-signature-file)
1704 (goto-char (point-max))
1705 (or (bolp) (insert "\n")))))
1707 (defun message-elide-region (b e)
1708 "Elide the text between point and mark.
1709 An ellipsis (from `message-elide-ellipsis') will be inserted where the
1713 (insert message-elide-ellipsis))
1715 (defvar message-caesar-translation-table nil)
1717 (defun message-caesar-region (b e &optional n)
1718 "Caesar rotation of region by N, default 13, for decrypting netnews."
1721 (min (point) (or (mark t) (point)))
1722 (max (point) (or (mark t) (point)))
1723 (when current-prefix-arg
1724 (prefix-numeric-value current-prefix-arg))))
1726 (setq n (if (numberp n) (mod n 26) 13)) ;canonize N
1727 (unless (or (zerop n) ; no action needed for a rot of 0
1728 (= b e)) ; no region to rotate
1729 ;; We build the table, if necessary.
1730 (when (or (not message-caesar-translation-table)
1731 (/= (aref message-caesar-translation-table ?a) (+ ?a n)))
1732 (setq message-caesar-translation-table
1733 (message-make-caesar-translation-table n)))
1734 (translate-region b e message-caesar-translation-table)))
1736 (defun message-make-caesar-translation-table (n)
1737 "Create a rot table with offset N."
1739 (table (make-string 256 0)))
1740 (while (< (incf i) 256)
1743 (substring table 0 ?A)
1744 (substring table (+ ?A n) (+ ?A n (- 26 n)))
1745 (substring table ?A (+ ?A n))
1746 (substring table (+ ?A 26) ?a)
1747 (substring table (+ ?a n) (+ ?a n (- 26 n)))
1748 (substring table ?a (+ ?a n))
1749 (substring table (+ ?a 26) 255))))
1751 (defun message-caesar-buffer-body (&optional rotnum)
1752 "Caesar rotates all letters in the current buffer by 13 places.
1753 Used to encode/decode possiblyun offensive messages (commonly in net.jokes).
1754 With prefix arg, specifies the number of places to rotate each letter forward.
1755 Mail and USENET news headers are not rotated."
1756 (interactive (if current-prefix-arg
1757 (list (prefix-numeric-value current-prefix-arg))
1761 (when (message-goto-body)
1762 (narrow-to-region (point) (point-max)))
1763 (message-caesar-region (point-min) (point-max) rotnum))))
1765 (defun message-pipe-buffer-body (program)
1766 "Pipe the message body in the current buffer through PROGRAM."
1769 (when (message-goto-body)
1770 (narrow-to-region (point) (point-max)))
1771 (shell-command-on-region
1772 (point-min) (point-max) program nil t))))
1774 (defun message-rename-buffer (&optional enter-string)
1775 "Rename the *message* buffer to \"*message* RECIPIENT\".
1776 If the function is run with a prefix, it will ask for a new buffer
1777 name, rather than giving an automatic name."
1778 (interactive "Pbuffer name: ")
1781 (goto-char (point-min))
1782 (narrow-to-region (point)
1783 (search-forward mail-header-separator nil 'end))
1785 (if (message-news-p) (message-fetch-field "Newsgroups")
1786 (message-fetch-field "To"))
1789 (if (string-match "," mail-to)
1790 (concat (substring mail-to 0 (match-beginning 0)) ", ...")
1792 (name-default (concat "*message* " mail-trimmed-to))
1793 (name (if enter-string
1794 (read-string "New buffer name: " name-default)
1796 (rename-buffer name t)))))
1798 (defun message-fill-yanked-message (&optional justifyp)
1799 "Fill the paragraphs of a message yanked into this one.
1800 Numeric argument means justify as well."
1803 (goto-char (point-min))
1804 (search-forward (concat "\n" mail-header-separator "\n") nil t)
1805 (let ((fill-prefix message-yank-prefix))
1806 (fill-individual-paragraphs (point) (point-max) justifyp))))
1808 (defun message-indent-citation ()
1809 "Modify text just inserted from a message to be cited.
1810 The inserted text should be the region.
1811 When this function returns, the region is again around the modified text.
1813 Normally, indent each nonblank line `message-indentation-spaces' spaces.
1814 However, if `message-yank-prefix' is non-nil, insert that prefix on each line."
1815 (let ((start (point)))
1816 ;; Remove unwanted headers.
1817 (when message-ignored-cited-headers
1822 (if (search-forward "\n\n" nil t)
1825 (message-remove-header message-ignored-cited-headers t)
1826 (when (= (point-min) (point-max))
1827 (setq all-removed t))
1828 (goto-char (point-max)))
1832 ;; Delete blank lines at the start of the buffer.
1833 (while (and (point-min)
1836 (message-delete-line))
1837 ;; Delete blank lines at the end of the buffer.
1838 (goto-char (point-max))
1841 (while (and (zerop (forward-line -1))
1843 (message-delete-line))
1844 ;; Do the indentation.
1845 (if (null message-yank-prefix)
1846 (indent-rigidly start (mark t) message-indentation-spaces)
1849 (while (< (point) (mark t))
1850 (insert message-yank-prefix)
1854 (defun message-yank-original (&optional arg)
1855 "Insert the message being replied to, if any.
1856 Puts point before the text and mark after.
1857 Normally indents each nonblank line ARG spaces (default 3). However,
1858 if `message-yank-prefix' is non-nil, insert that prefix on each line.
1860 This function uses `message-cite-function' to do the actual citing.
1862 Just \\[universal-argument] as argument means don't indent, insert no
1863 prefix, and don't delete any headers."
1865 (let ((modified (buffer-modified-p)))
1866 (when (and message-reply-buffer
1867 message-cite-function)
1868 (delete-windows-on message-reply-buffer t)
1869 (insert-buffer message-reply-buffer)
1870 (funcall message-cite-function)
1871 (message-exchange-point-and-mark)
1875 (setq message-checksum (message-checksum))))))
1877 (defun message-yank-buffer (buffer)
1878 "Insert BUFFER into the current buffer and quote it."
1879 (interactive "bYank buffer: ")
1880 (let ((message-reply-buffer buffer))
1881 (save-window-excursion
1882 (message-yank-original))))
1884 (defun message-buffers ()
1885 "Return a list of active message buffers."
1888 (dolist (buffer (buffer-list t))
1890 (when (and (eq major-mode 'message-mode)
1891 (null message-sent-message-via))
1892 (push (buffer-name buffer) buffers))))
1893 (nreverse buffers)))
1895 (defun message-cite-original-without-signature ()
1896 "Cite function in the standard Message manner."
1897 (let ((start (point))
1900 (when message-indent-citation-function
1901 (if (listp message-indent-citation-function)
1902 message-indent-citation-function
1903 (list message-indent-citation-function)))))
1904 (mml-quote-region start end)
1908 (when (re-search-backward message-signature-separator start t)
1909 ;; Also peel off any blank lines before the signature.
1911 (while (looking-at "^[ \t]*$")
1914 (delete-region (point) end))
1917 (funcall (pop functions)))
1918 (when message-citation-line-function
1921 (funcall message-citation-line-function))))
1923 (defvar mail-citation-hook) ;Compiler directive
1924 (defun message-cite-original ()
1925 "Cite function in the standard Message manner."
1926 (if (and (boundp 'mail-citation-hook)
1928 (run-hooks 'mail-citation-hook)
1929 (let ((start (point))
1932 (when message-indent-citation-function
1933 (if (listp message-indent-citation-function)
1934 message-indent-citation-function
1935 (list message-indent-citation-function)))))
1936 (mml-quote-region start end)
1939 (funcall (pop functions)))
1940 (when message-citation-line-function
1943 (funcall message-citation-line-function)))))
1945 (defun message-insert-citation-line ()
1946 "Function that inserts a simple citation line."
1947 (when message-reply-headers
1948 (insert (mail-header-from message-reply-headers) " writes:\n\n")))
1950 (defun message-position-on-field (header &rest afters)
1951 (let ((case-fold-search t))
1954 (goto-char (point-min))
1957 (concat "^" (regexp-quote mail-header-separator) "$"))
1958 (match-beginning 0)))
1959 (goto-char (point-min))
1960 (if (re-search-forward (concat "^" (regexp-quote header) ":") nil t)
1962 (re-search-forward "^[^ \t]" nil 'move)
1964 (skip-chars-backward "\n")
1967 (not (re-search-forward
1968 (concat "^" (regexp-quote (car afters)) ":")
1972 (re-search-forward "^[^ \t]" nil 'move)
1973 (beginning-of-line))
1974 (insert header ": \n")
1978 (defun message-remove-signature ()
1979 "Remove the signature from the text between point and mark.
1980 The text will also be indented the normal way."
1982 (let ((start (point))
1984 (if (not (re-search-forward message-signature-separator (mark t) t))
1985 ;; No signature here, so we just indent the cited text.
1986 (message-indent-citation)
1987 ;; Find the last non-empty line.
1989 (while (looking-at "[ \t]*$")
1992 (setq mark (set-marker (make-marker) (point)))
1994 (message-indent-citation)
1995 ;; Enable undoing the deletion.
1997 (delete-region mark (mark t))
1998 (set-marker mark nil)))))
2003 ;;; Sending messages
2006 (defun message-send-and-exit (&optional arg)
2007 "Send message like `message-send', then, if no errors, exit from mail buffer."
2009 (let ((buf (current-buffer))
2010 (actions message-exit-actions))
2011 (when (and (message-send arg)
2013 (if message-kill-buffer-on-exit
2016 (when (eq buf (current-buffer))
2017 (message-bury buf)))
2018 (message-do-actions actions)
2021 (defun message-dont-send ()
2022 "Don't send the message you have been editing."
2024 (set-buffer-modified-p t)
2026 (let ((actions message-postpone-actions))
2027 (message-bury (current-buffer))
2028 (message-do-actions actions)))
2030 (defun message-kill-buffer ()
2031 "Kill the current buffer."
2033 (when (or (not (buffer-modified-p))
2034 (yes-or-no-p "Message modified; kill anyway? "))
2035 (let ((actions message-kill-actions))
2036 (setq buffer-file-name nil)
2037 (kill-buffer (current-buffer))
2038 (message-do-actions actions))))
2040 (defun message-bury (buffer)
2041 "Bury this mail buffer."
2042 (let ((newbuf (other-buffer buffer)))
2043 (bury-buffer buffer)
2044 (if (and (fboundp 'frame-parameters)
2045 (cdr (assq 'dedicated (frame-parameters)))
2046 (not (null (delq (selected-frame) (visible-frame-list)))))
2047 (delete-frame (selected-frame))
2048 (switch-to-buffer newbuf))))
2050 (defun message-send (&optional arg)
2051 "Send the message in the current buffer.
2052 If `message-interactive' is non-nil, wait for success indication or
2053 error messages, and inform user.
2054 Otherwise any failure is reported in a message back to the user from
2056 The usage of ARG is defined by the instance that called Message.
2057 It should typically alter the sending method in some way or other."
2059 ;; Make it possible to undo the coming changes.
2061 (let ((inhibit-read-only t))
2062 (put-text-property (point-min) (point-max) 'read-only nil))
2063 (message-fix-before-sending)
2064 (run-hooks 'message-send-hook)
2065 (message "Sending...")
2066 (let ((alist message-send-method-alist)
2070 (setq elem (pop alist)))
2071 (when (or (not (funcall (cadr elem)))
2072 (and (or (not (memq (car elem)
2073 message-sent-message-via))
2076 "Already sent message via %s; resend? "
2078 (setq success (funcall (caddr elem) arg))))
2080 (unless (or sent (not success))
2081 (error "No methods specified to send by"))
2082 (when (and success sent)
2085 (run-hooks 'message-sent-hook))
2086 (message "Sending...done")
2087 ;; Mark the buffer as unmodified and delete auto-save.
2088 (set-buffer-modified-p nil)
2089 (delete-auto-save-file-if-necessary t)
2090 (message-disassociate-draft)
2091 ;; Delete other mail buffers and stuff.
2092 (message-do-send-housekeeping)
2093 (message-do-actions message-send-actions)
2097 (defun message-send-via-mail (arg)
2098 "Send the current message via mail."
2099 (message-send-mail arg))
2101 (defun message-send-via-news (arg)
2102 "Send the current message via news."
2103 (funcall message-send-news-function arg))
2105 (defmacro message-check (type &rest forms)
2106 "Eval FORMS if TYPE is to be checked."
2107 `(or (message-check-element ,type)
2111 (put 'message-check 'lisp-indent-function 1)
2112 (put 'message-check 'edebug-form-spec '(form body))
2114 (defun message-fix-before-sending ()
2115 "Do various things to make the message nice before sending it."
2116 ;; Make sure there's a newline at the end of the message.
2117 (goto-char (point-max))
2120 ;; Delete all invisible text.
2121 (message-check 'invisible-text
2122 (when (text-property-any (point-min) (point-max) 'invisible t)
2123 (put-text-property (point-min) (point-max) 'invisible nil)
2124 (unless (yes-or-no-p
2125 "Invisible text found and made visible; continue posting? ")
2126 (error "Invisible text found and made visible")))))
2128 (defun message-add-action (action &rest types)
2129 "Add ACTION to be performed when doing an exit of type TYPES."
2132 (set (setq var (intern (format "message-%s-actions" (pop types))))
2133 (nconc (symbol-value var) (list action))))))
2135 (defun message-do-actions (actions)
2136 "Perform all actions in ACTIONS."
2137 ;; Now perform actions on successful sending.
2141 ;; A simple function.
2142 ((message-functionp (car actions))
2143 (funcall (car actions)))
2144 ;; Something to be evaled.
2146 (eval (car actions)))))
2149 (defun message-send-mail (&optional arg)
2150 (require 'mail-utils)
2151 (let* ((tembuf (message-generate-new-buffer-clone-locals " message temp"))
2152 (case-fold-search nil)
2153 (news (message-news-p))
2154 (mailbuf (current-buffer))
2155 (message-this-is-mail t)
2156 (message-posting-charset
2157 (if (fboundp 'gnus-setup-posting-charset)
2158 (gnus-setup-posting-charset nil)
2159 message-posting-charset)))
2161 (message-narrow-to-headers)
2162 ;; Insert some headers.
2163 (let ((message-deletable-headers
2164 (if news nil message-deletable-headers)))
2165 (message-generate-headers message-required-mail-headers))
2166 ;; Let the user do all of the above.
2167 (run-hooks 'message-header-hook))
2172 ;; Avoid copying text props.
2174 "%s" (save-excursion
2175 (set-buffer mailbuf)
2177 ;; Remove some headers.
2178 (message-encode-message-body)
2180 (message-narrow-to-headers)
2181 ;; We (re)generate the Lines header.
2182 (when (memq 'Lines message-required-mail-headers)
2183 (message-generate-headers '(Lines)))
2184 ;; Remove some headers.
2185 (message-remove-header message-ignored-mail-headers t)
2186 (mail-encode-encoded-word-buffer))
2187 (goto-char (point-max))
2188 ;; require one newline at the end.
2189 (or (= (preceding-char) ?\n)
2192 (or (message-fetch-field "cc")
2193 (message-fetch-field "to")))
2194 (message-insert-courtesy-copy))
2195 (funcall message-send-mail-function))
2196 (kill-buffer tembuf))
2197 (set-buffer mailbuf)
2198 (push 'mail message-sent-message-via)))
2200 (defun message-send-mail-with-sendmail ()
2201 "Send off the prepared buffer with sendmail."
2202 (let ((errbuf (if message-interactive
2203 (message-generate-new-buffer-clone-locals
2206 resend-to-addresses delimline)
2207 (let ((case-fold-search t))
2209 (message-narrow-to-headers)
2210 (setq resend-to-addresses (message-fetch-field "resent-to")))
2211 ;; Change header-delimiter to be what sendmail expects.
2212 (goto-char (point-min))
2214 (concat "^" (regexp-quote mail-header-separator) "\n"))
2215 (replace-match "\n")
2217 (setq delimline (point-marker))
2218 (run-hooks 'message-send-mail-hook)
2219 ;; Insert an extra newline if we need it to work around
2220 ;; Sun's bug that swallows newlines.
2221 (goto-char (1+ delimline))
2222 (when (eval message-mailer-swallows-blank-line)
2224 (when message-interactive
2228 (let ((default-directory "/")
2229 (coding-system-for-write message-send-coding-system))
2230 (apply 'call-process-region
2231 (append (list (point-min) (point-max)
2232 (if (boundp 'sendmail-program)
2234 "/usr/lib/sendmail")
2235 nil errbuf nil "-oi")
2236 ;; Always specify who from,
2237 ;; since some systems have broken sendmails.
2238 ;; But some systems are more broken with -f, so
2239 ;; we'll let users override this.
2240 (if (null message-sendmail-f-is-evil)
2241 (list "-f" (message-make-address)))
2242 ;; These mean "report errors by mail"
2243 ;; and "deliver in background".
2244 (if (null message-interactive) '("-oem" "-odb"))
2245 ;; Get the addresses from the message
2246 ;; unless this is a resend.
2247 ;; We must not do that for a resend
2248 ;; because we would find the original addresses.
2249 ;; For a resend, include the specific addresses.
2250 (if resend-to-addresses
2251 (list resend-to-addresses)
2253 (when message-interactive
2256 (goto-char (point-min))
2257 (while (re-search-forward "\n\n* *" nil t)
2258 (replace-match "; "))
2259 (if (not (zerop (buffer-size)))
2260 (error "Sending...failed to %s"
2261 (buffer-substring (point-min) (point-max)))))
2262 (when (bufferp errbuf)
2263 (kill-buffer errbuf)))))
2265 (defun message-send-mail-with-qmail ()
2266 "Pass the prepared message buffer to qmail-inject.
2267 Refer to the documentation for the variable `message-send-mail-function'
2268 to find out how to use this."
2269 ;; replace the header delimiter with a blank line
2270 (goto-char (point-min))
2272 (concat "^" (regexp-quote mail-header-separator) "\n"))
2273 (replace-match "\n")
2274 (run-hooks 'message-send-mail-hook)
2277 (let ((coding-system-for-write message-send-coding-system))
2279 'call-process-region 1 (point-max) message-qmail-inject-program
2281 ;; qmail-inject's default behaviour is to look for addresses on the
2282 ;; command line; if there're none, it scans the headers.
2283 ;; yes, it does The Right Thing w.r.t. Resent-To and it's kin.
2285 ;; in general, ALL of qmail-inject's defaults are perfect for simply
2286 ;; reading a formatted (i. e., at least a To: or Resent-To header)
2287 ;; message from stdin.
2289 ;; qmail also has the advantage of not having been raped by
2290 ;; various vendors, so we don't have to allow for that, either --
2291 ;; compare this with message-send-mail-with-sendmail and weep
2292 ;; for sendmail's lost innocence.
2294 ;; all this is way cool coz it lets us keep the arguments entirely
2295 ;; free for -inject-arguments -- a big win for the user and for us
2296 ;; since we don't have to play that double-guessing game and the user
2297 ;; gets full control (no gestapo'ish -f's, for instance). --sj
2298 message-qmail-inject-args))
2299 ;; qmail-inject doesn't say anything on it's stdout/stderr,
2300 ;; we have to look at the retval instead
2302 (1 (error "qmail-inject reported permanent failure"))
2303 (111 (error "qmail-inject reported transient failure"))
2304 ;; should never happen
2305 (t (error "qmail-inject reported unknown failure"))))
2307 (defun message-send-mail-with-mh ()
2308 "Send the prepared message buffer with mh."
2309 (let ((mh-previous-window-config nil)
2310 (name (mh-new-draft-name)))
2311 (setq buffer-file-name name)
2312 ;; MH wants to generate these headers itself.
2313 (when message-mh-deletable-headers
2314 (let ((headers message-mh-deletable-headers))
2316 (goto-char (point-min))
2317 (and (re-search-forward
2318 (concat "^" (symbol-name (car headers)) ": *") nil t)
2319 (message-delete-line))
2321 (run-hooks 'message-send-mail-hook)
2322 ;; Pass it on to mh.
2325 (defun message-send-news (&optional arg)
2326 (let* ((tembuf (message-generate-new-buffer-clone-locals " *message temp*"))
2327 (case-fold-search nil)
2328 (method (if (message-functionp message-post-method)
2329 (funcall message-post-method arg)
2330 message-post-method))
2331 (messbuf (current-buffer))
2332 (message-syntax-checks
2334 (cons '(existing-newsgroups . disabled)
2335 message-syntax-checks)
2336 message-syntax-checks))
2337 (message-this-is-news t)
2338 (message-posting-charset (gnus-setup-posting-charset
2339 (message-fetch-field "Newsgroups")))
2341 (if (not (message-check-news-body-syntax))
2344 (message-narrow-to-headers)
2345 ;; Insert some headers.
2346 (message-generate-headers message-required-news-headers)
2347 ;; Let the user do all of the above.
2348 (run-hooks 'message-header-hook))
2349 (message-cleanup-headers)
2350 (if (not (message-check-news-syntax))
2355 (buffer-disable-undo)
2357 ;; Avoid copying text props.
2359 "%s" (save-excursion
2360 (set-buffer messbuf)
2362 (message-encode-message-body)
2363 ;; Remove some headers.
2365 (message-narrow-to-headers)
2366 ;; We (re)generate the Lines header.
2367 (when (memq 'Lines message-required-mail-headers)
2368 (message-generate-headers '(Lines)))
2369 ;; Remove some headers.
2370 (message-remove-header message-ignored-news-headers t)
2371 (let ((mail-parse-charset (car message-posting-charset)))
2372 (mail-encode-encoded-word-buffer)))
2373 (goto-char (point-max))
2374 ;; require one newline at the end.
2375 (or (= (preceding-char) ?\n)
2377 (let ((case-fold-search t))
2378 ;; Remove the delimiter.
2379 (goto-char (point-min))
2381 (concat "^" (regexp-quote mail-header-separator) "\n"))
2382 (replace-match "\n")
2384 (run-hooks 'message-send-news-hook)
2385 (gnus-open-server method)
2386 (setq result (let ((mail-header-separator ""))
2387 (gnus-request-post method))))
2388 (kill-buffer tembuf))
2389 (set-buffer messbuf)
2391 (push 'news message-sent-message-via)
2392 (message "Couldn't send message via news: %s"
2393 (nnheader-get-report (car method)))
2397 ;;; Header generation & syntax checking.
2400 (defun message-check-element (type)
2401 "Returns non-nil if this type is not to be checked."
2402 (if (eq message-syntax-checks 'dont-check-for-anything-just-trust-me)
2404 (let ((able (assq type message-syntax-checks)))
2406 (eq (cdr able) 'disabled)))))
2408 (defun message-check-news-syntax ()
2409 "Check the syntax of the message."
2413 ;; We narrow to the headers and check them first.
2416 (message-narrow-to-headers)
2417 (message-check-news-header-syntax))))))
2419 (defun message-check-news-header-syntax ()
2421 ;; Check Newsgroups header.
2422 (message-check 'newsgroups
2423 (let ((group (message-fetch-field "newsgroups")))
2426 (not (string-match "\\`[ \t]*\\'" group)))
2429 "The newsgroups field is empty or missing. Posting is denied.")))))
2430 ;; Check the Subject header.
2431 (message-check 'subject
2432 (let* ((case-fold-search t)
2433 (subject (message-fetch-field "subject")))
2436 (not (string-match "\\`[ \t]*\\'" subject)))
2439 "The subject field is empty or missing. Posting is denied.")))))
2440 ;; Check for commands in Subject.
2441 (message-check 'subject-cmsg
2442 (if (string-match "^cmsg " (message-fetch-field "subject"))
2444 "The control code \"cmsg\" is in the subject. Really post? ")
2446 ;; Check for multiple identical headers.
2447 (message-check 'multiple-headers
2449 (while (and (not found)
2450 (re-search-forward "^[^ \t:]+: " nil t))
2452 (or (re-search-forward
2457 (match-beginning 0) (- (match-end 0) 2))))
2462 (y-or-n-p (format "Multiple %s headers. Really post? " found))
2464 ;; Check for Version and Sendsys.
2465 (message-check 'sendsys
2466 (if (re-search-forward "^Sendsys:\\|^Version:" nil t)
2468 (format "The article contains a %s command. Really post? "
2469 (buffer-substring (match-beginning 0)
2470 (1- (match-end 0)))))
2472 ;; See whether we can shorten Followup-To.
2473 (message-check 'shorten-followup-to
2474 (let ((newsgroups (message-fetch-field "newsgroups"))
2475 (followup-to (message-fetch-field "followup-to"))
2477 (when (and newsgroups
2478 (string-match "," newsgroups)
2483 (setq to (completing-read
2484 "Followups to: (default all groups) "
2485 (mapcar (lambda (g) (list g))
2487 (message-tokenize-header
2489 (goto-char (point-min))
2490 (insert "Followup-To: " to "\n"))
2492 ;; Check "Shoot me".
2493 (message-check 'shoot
2494 (if (re-search-forward
2495 "Message-ID.*.i-did-not-set--mail-host-address--so-shoot-me" nil t)
2496 (y-or-n-p "You appear to have a misconfigured system. Really post? ")
2498 ;; Check for Approved.
2499 (message-check 'approved
2500 (if (re-search-forward "^Approved:" nil t)
2501 (y-or-n-p "The article contains an Approved header. Really post? ")
2503 ;; Check the Message-ID header.
2504 (message-check 'message-id
2505 (let* ((case-fold-search t)
2506 (message-id (message-fetch-field "message-id" t)))
2507 (or (not message-id)
2508 ;; Is there an @ in the ID?
2509 (and (string-match "@" message-id)
2510 ;; Is there a dot in the ID?
2511 (string-match "@[^.]*\\." message-id)
2512 ;; Does the ID end with a dot?
2513 (not (string-match "\\.>" message-id)))
2515 (format "The Message-ID looks strange: \"%s\". Really post? "
2517 ;; Check the Newsgroups & Followup-To headers.
2518 (message-check 'existing-newsgroups
2519 (let* ((case-fold-search t)
2520 (newsgroups (message-fetch-field "newsgroups"))
2521 (followup-to (message-fetch-field "followup-to"))
2522 (groups (message-tokenize-header
2524 (concat newsgroups "," followup-to)
2526 (hashtb (and (boundp 'gnus-active-hashtb)
2527 gnus-active-hashtb))
2529 (if (or (not hashtb)
2530 (not (boundp 'gnus-read-active-file))
2531 (not gnus-read-active-file)
2532 (eq gnus-read-active-file 'some))
2535 (when (and (not (boundp (intern (car groups) hashtb)))
2536 (not (equal (car groups) "poster")))
2537 (push (car groups) errors))
2543 "Really post to %s unknown group%s: %s "
2544 (if (= (length errors) 1) "this" "these")
2545 (if (= (length errors) 1) "" "s")
2546 (mapconcat 'identity errors ", ")))))))
2547 ;; Check the Newsgroups & Followup-To headers for syntax errors.
2548 (message-check 'valid-newsgroups
2549 (let ((case-fold-search t)
2550 (headers '("Newsgroups" "Followup-To"))
2552 (while (and headers (not error))
2553 (when (setq header (mail-fetch-field (car headers)))
2557 "\\`\\([-+_&.a-zA-Z0-9]+\\)?\\(,[-+_&.a-zA-Z0-9]+\\)*\\'"
2562 (not (string-match "\\.\\'\\|\\.\\." g)))
2563 (message-tokenize-header header ","))))
2570 (format "The %s header looks odd: \"%s\". Really post? "
2571 (car headers) header)))))
2572 (message-check 'repeated-newsgroups
2573 (let ((case-fold-search t)
2574 (headers '("Newsgroups" "Followup-To"))
2575 header error groups group)
2578 (when (setq header (mail-fetch-field (pop headers)))
2579 (setq groups (message-tokenize-header header ","))
2580 (while (setq group (pop groups))
2581 (when (member group groups)
2587 (format "Group %s is repeated in headers. Really post? " error)))))
2588 ;; Check the From header.
2589 (message-check 'from
2590 (let* ((case-fold-search t)
2591 (from (message-fetch-field "from"))
2595 (message "There is no From line. Posting is denied.")
2597 ((or (not (string-match
2599 (setq ad (nth 1 (mail-extract-address-components
2600 from))))) ;larsi@ifi
2601 (string-match "\\.\\." ad) ;larsi@ifi..uio
2602 (string-match "@\\." ad) ;larsi@.ifi.uio
2603 (string-match "\\.$" ad) ;larsi@ifi.uio.
2604 (not (string-match "^[^@]+@[^@]+$" ad)) ;larsi.ifi.uio
2605 (string-match "(.*).*(.*)" from)) ;(lars) (lars)
2607 "Denied posting -- the From looks strange: \"%s\"." from)
2611 (defun message-check-news-body-syntax ()
2613 ;; Check for long lines.
2614 (message-check 'long-lines
2615 (goto-char (point-min))
2617 (concat "^" (regexp-quote mail-header-separator) "$"))
2621 (< (current-column) 80))
2622 (zerop (forward-line 1))))
2626 "You have lines longer than 79 characters. Really post? ")))
2627 ;; Check whether the article is empty.
2628 (message-check 'empty
2629 (goto-char (point-min))
2631 (concat "^" (regexp-quote mail-header-separator) "$"))
2634 (goto-char (point-max))
2635 (re-search-backward message-signature-separator nil t)
2637 (or (re-search-backward "[^ \n\t]" b t)
2638 (y-or-n-p "Empty article. Really post? "))))
2639 ;; Check for control characters.
2640 (message-check 'control-chars
2641 (if (re-search-forward "[\000-\007\013\015-\032\034-\037\200-\237]" nil t)
2643 "The article contains control characters. Really post? ")
2645 ;; Check excessive size.
2646 (message-check 'size
2647 (if (> (buffer-size) 60000)
2649 (format "The article is %d octets long. Really post? "
2652 ;; Check whether any new text has been added.
2653 (message-check 'new-text
2655 (not message-checksum)
2656 (not (eq (message-checksum) message-checksum))
2658 "It looks like no new text has been added. Really post? ")))
2659 ;; Check the length of the signature.
2660 (message-check 'signature
2661 (goto-char (point-max))
2662 (if (> (count-lines (point) (point-max)) 5)
2665 "Your .sig is %d lines; it should be max 4. Really post? "
2666 (1- (count-lines (point) (point-max)))))
2669 (defun message-checksum ()
2670 "Return a \"checksum\" for the current buffer."
2673 (goto-char (point-min))
2675 (concat "^" (regexp-quote mail-header-separator) "$"))
2677 (when (not (looking-at "[ \t\n]"))
2678 (setq sum (logxor (ash sum 1) (if (natnump sum) 0 1)
2683 (defun message-do-fcc ()
2684 "Process Fcc headers in the current buffer."
2685 (let ((case-fold-search t)
2686 (buf (current-buffer))
2689 (set-buffer (get-buffer-create " *message temp*"))
2691 (insert-buffer-substring buf)
2693 (message-narrow-to-headers)
2694 (while (setq file (message-fetch-field "fcc"))
2696 (message-remove-header "fcc" nil t)))
2697 (goto-char (point-min))
2698 (re-search-forward (concat "^" (regexp-quote mail-header-separator) "$"))
2699 (replace-match "" t t)
2700 ;; Process FCC operations.
2702 (setq file (pop list))
2703 (if (string-match "^[ \t]*|[ \t]*\\(.*\\)[ \t]*$" file)
2704 ;; Pipe the article to the program in question.
2705 (call-process-region (point-min) (point-max) shell-file-name
2706 nil nil nil shell-command-switch
2707 (match-string 1 file))
2708 ;; Save the article.
2709 (setq file (expand-file-name file))
2710 (unless (file-exists-p (file-name-directory file))
2711 (make-directory (file-name-directory file) t))
2712 (if (and message-fcc-handler-function
2713 (not (eq message-fcc-handler-function 'rmail-output)))
2714 (funcall message-fcc-handler-function file)
2715 (if (and (file-readable-p file) (mail-file-babyl-p file))
2716 (rmail-output file 1 nil t)
2717 (let ((mail-use-rfc822 t))
2718 (rmail-output file 1 t t))))))
2720 (kill-buffer (current-buffer)))))
2722 (defun message-output (filename)
2723 "Append this article to Unix/babyl mail file.."
2724 (if (and (file-readable-p filename)
2725 (mail-file-babyl-p filename))
2726 (rmail-output-to-rmail-file filename t)
2727 (gnus-output-to-mail filename t)))
2729 (defun message-cleanup-headers ()
2730 "Do various automatic cleanups of the headers."
2731 ;; Remove empty lines in the header.
2733 (message-narrow-to-headers)
2734 ;; Remove blank lines.
2735 (while (re-search-forward "^[ \t]*\n" nil t)
2736 (replace-match "" t t))
2738 ;; Correct Newsgroups and Followup-To headers: Change sequence of
2739 ;; spaces to comma and eliminate spaces around commas. Eliminate
2740 ;; embedded line breaks.
2741 (goto-char (point-min))
2742 (while (re-search-forward "^\\(Newsgroups\\|Followup-To\\): +" nil t)
2746 (if (re-search-forward "^[^ \t]" nil t)
2750 (goto-char (point-min))
2751 (while (re-search-forward "\n[ \t]+" nil t)
2752 (replace-match " " t t)) ;No line breaks (too confusing)
2753 (goto-char (point-min))
2754 (while (re-search-forward "[ \t\n]*,[ \t\n]*\\|[ \t]+" nil t)
2755 (replace-match "," t t))
2756 (goto-char (point-min))
2757 ;; Remove trailing commas.
2758 (when (re-search-forward ",+$" nil t)
2759 (replace-match "" t t))))))
2761 (defun message-make-date (&optional now)
2762 "Make a valid data header.
2763 If NOW, use that time instead."
2764 (let* ((now (or now (current-time)))
2765 (zone (nth 8 (decode-time now)))
2769 (setq zone (- zone)))
2771 (format-time-string "%d" now)
2772 ;; The month name of the %b spec is locale-specific. Pfff.
2774 (capitalize (car (rassoc (nth 4 (decode-time now))
2775 parse-time-months))))
2776 (format-time-string "%Y %H:%M:%S " now)
2777 ;; We do all of this because XEmacs doesn't have the %z spec.
2778 (format "%s%02d%02d" sign (/ zone 3600) (/ (% zone 3600) 60)))))
2780 (defun message-make-message-id ()
2781 "Make a unique Message-ID."
2782 (concat "<" (message-unique-id)
2783 (let ((psubject (save-excursion (message-fetch-field "subject")))
2785 (save-excursion (message-fetch-field "supersedes"))))
2787 (and message-reply-headers
2788 (mail-header-references message-reply-headers)
2789 (mail-header-subject message-reply-headers)
2791 (mail-header-subject message-reply-headers)
2793 (message-strip-subject-re
2794 (mail-header-subject message-reply-headers))
2795 (message-strip-subject-re psubject))))
2797 (string-match "_-_@" psupersedes)))
2799 "@" (message-make-fqdn) ">"))
2801 (defvar message-unique-id-char nil)
2803 ;; If you ever change this function, make sure the new version
2804 ;; cannot generate IDs that the old version could.
2805 ;; You might for example insert a "." somewhere (not next to another dot
2806 ;; or string boundary), or modify the "fsf" string.
2807 (defun message-unique-id ()
2808 ;; Don't use microseconds from (current-time), they may be unsupported.
2809 ;; Instead we use this randomly inited counter.
2810 (setq message-unique-id-char
2811 (% (1+ (or message-unique-id-char (logand (random t) (1- (lsh 1 20)))))
2812 ;; (current-time) returns 16-bit ints,
2813 ;; and 2^16*25 just fits into 4 digits i base 36.
2815 (let ((tm (current-time)))
2817 (if (memq system-type '(ms-dos emx vax-vms))
2818 (let ((user (downcase (user-login-name))))
2819 (while (string-match "[^a-z0-9_]" user)
2820 (aset user (match-beginning 0) ?_))
2822 (message-number-base36 (user-uid) -1))
2823 (message-number-base36 (+ (car tm)
2824 (lsh (% message-unique-id-char 25) 16)) 4)
2825 (message-number-base36 (+ (nth 1 tm)
2826 (lsh (/ message-unique-id-char 25) 16)) 4)
2827 ;; Append the newsreader name, because while the generated
2828 ;; ID is unique to this newsreader, other newsreaders might
2829 ;; otherwise generate the same ID via another algorithm.
2832 (defun message-number-base36 (num len)
2837 (concat (message-number-base36 (/ num 36) (1- len))
2838 (char-to-string (aref "zyxwvutsrqponmlkjihgfedcba9876543210"
2841 (defun message-make-organization ()
2842 "Make an Organization header."
2843 (let* ((organization
2844 (when message-user-organization
2845 (if (message-functionp message-user-organization)
2846 (funcall message-user-organization)
2847 message-user-organization))))
2849 (message-set-work-buffer)
2850 (cond ((stringp organization)
2851 (insert organization))
2852 ((and (eq t organization)
2853 message-user-organization-file
2854 (file-exists-p message-user-organization-file))
2855 (insert-file-contents message-user-organization-file)))
2856 (goto-char (point-min))
2857 (while (re-search-forward "[\t\n]+" nil t)
2858 (replace-match "" t t))
2859 (unless (zerop (buffer-size))
2862 (defun message-make-lines ()
2863 "Count the number of lines and return numeric string."
2867 (goto-char (point-min))
2869 (concat "^" (regexp-quote mail-header-separator) "$"))
2871 (int-to-string (count-lines (point) (point-max))))))
2873 (defun message-make-in-reply-to ()
2874 "Return the In-Reply-To header for this message."
2875 (when message-reply-headers
2876 (let ((from (mail-header-from message-reply-headers))
2877 (date (mail-header-date message-reply-headers)))
2880 (string-match " *at \\| *@ \\| *(\\| *<" from)))
2881 (concat (if (and stop-pos
2882 (not (zerop stop-pos)))
2883 (substring from 0 stop-pos) from)
2885 (if (or (not date) (string= date ""))
2886 "(unknown date)" date)
2889 (defun message-make-distribution ()
2890 "Make a Distribution header."
2891 (let ((orig-distribution (message-fetch-reply-field "distribution")))
2892 (cond ((message-functionp message-distribution-function)
2893 (funcall message-distribution-function))
2894 (t orig-distribution))))
2896 (defun message-make-expires ()
2897 "Return an Expires header based on `message-expires'."
2898 (let ((current (current-time))
2899 (future (* 1.0 message-expires 60 60 24)))
2900 ;; Add the future to current.
2901 (setcar current (+ (car current) (round (/ future (expt 2 16)))))
2902 (setcar (cdr current) (+ (nth 1 current) (% (round future) (expt 2 16))))
2903 (message-make-date current)))
2905 (defun message-make-path ()
2907 (let ((login-name (user-login-name)))
2908 (cond ((null message-user-path)
2909 (concat (system-name) "!" login-name))
2910 ((stringp message-user-path)
2911 ;; Support GENERICPATH. Suggested by vixie@decwrl.dec.com.
2912 (concat message-user-path "!" login-name))
2915 (defun message-make-from ()
2916 "Make a From header."
2917 (let* ((style message-from-style)
2918 (login (message-make-address))
2920 (or (and (boundp 'user-full-name)
2923 (when (string= fullname "&")
2924 (setq fullname (user-login-name)))
2926 (message-set-work-buffer)
2929 (equal fullname ""))
2931 ((or (eq style 'angles)
2932 (and (not (eq style 'parens))
2933 ;; Use angles if no quoting is needed, or if parens would
2934 ;; need quoting too.
2935 (or (not (string-match "[^- !#-'*+/-9=?A-Z^-~]" fullname))
2936 (let ((tmp (concat fullname nil)))
2937 (while (string-match "([^()]*)" tmp)
2938 (aset tmp (match-beginning 0) ?-)
2939 (aset tmp (1- (match-end 0)) ?-))
2940 (string-match "[\\()]" tmp)))))
2942 (goto-char (point-min))
2943 ;; Look for a character that cannot appear unquoted
2944 ;; according to RFC 822.
2945 (when (re-search-forward "[^- !#-'*+/-9=?A-Z^-~]" nil 1)
2946 ;; Quote fullname, escaping specials.
2947 (goto-char (point-min))
2949 (while (re-search-forward "[\"\\]" nil 1)
2950 (replace-match "\\\\\\&" t))
2952 (insert " <" login ">"))
2953 (t ; 'parens or default
2955 (let ((fullname-start (point)))
2957 (goto-char fullname-start)
2958 ;; RFC 822 says \ and nonmatching parentheses
2959 ;; must be escaped in comments.
2960 ;; Escape every instance of ()\ ...
2961 (while (re-search-forward "[()\\]" nil 1)
2962 (replace-match "\\\\\\&" t))
2963 ;; ... then undo escaping of matching parentheses,
2964 ;; including matching nested parentheses.
2965 (goto-char fullname-start)
2966 (while (re-search-forward
2967 "\\(\\=\\|[^\\]\\(\\\\\\\\\\)*\\)\\\\(\\(\\([^\\]\\|\\\\\\\\\\)*\\)\\\\)"
2969 (replace-match "\\1(\\3)" t)
2970 (goto-char fullname-start)))
2974 (defun message-make-sender ()
2975 "Return the \"real\" user address.
2976 This function tries to ignore all user modifications, and
2977 give as trustworthy answer as possible."
2978 (concat (user-login-name) "@" (system-name)))
2980 (defun message-make-address ()
2981 "Make the address of the user."
2982 (or (message-user-mail-address)
2983 (concat (user-login-name) "@" (message-make-domain))))
2985 (defun message-user-mail-address ()
2986 "Return the pertinent part of `user-mail-address'."
2987 (when user-mail-address
2988 (if (string-match " " user-mail-address)
2989 (nth 1 (mail-extract-address-components user-mail-address))
2990 user-mail-address)))
2992 (defun message-make-fqdn ()
2993 "Return user's fully qualified domain name."
2994 (let ((system-name (system-name))
2995 (user-mail (message-user-mail-address)))
2997 ((string-match "[^.]\\.[^.]" system-name)
2998 ;; `system-name' returned the right result.
3000 ;; Try `mail-host-address'.
3001 ((and (boundp 'mail-host-address)
3002 (stringp mail-host-address)
3003 (string-match "\\." mail-host-address))
3005 ;; We try `user-mail-address' as a backup.
3007 (string-match "\\." user-mail)
3008 (string-match "@\\(.*\\)\\'" user-mail))
3009 (match-string 1 user-mail))
3010 ;; Default to this bogus thing.
3012 (concat system-name ".i-did-not-set--mail-host-address--so-shoot-me")))))
3014 (defun message-make-host-name ()
3015 "Return the name of the host."
3016 (let ((fqdn (message-make-fqdn)))
3017 (string-match "^[^.]+\\." fqdn)
3018 (substring fqdn 0 (1- (match-end 0)))))
3020 (defun message-make-domain ()
3021 "Return the domain name."
3022 (or mail-host-address
3023 (message-make-fqdn)))
3025 (defun message-generate-headers (headers)
3026 "Prepare article HEADERS.
3027 Headers already prepared in the buffer are not modified."
3029 (message-narrow-to-headers)
3030 (let* ((Date (message-make-date))
3031 (Message-ID (message-make-message-id))
3032 (Organization (message-make-organization))
3033 (From (message-make-from))
3034 (Path (message-make-path))
3037 (In-Reply-To (message-make-in-reply-to))
3039 (Distribution (message-make-distribution))
3040 (Lines (message-make-lines))
3041 (User-Agent message-newsreader)
3042 (Expires (message-make-expires))
3043 (case-fold-search t)
3045 ;; First we remove any old generated headers.
3046 (let ((headers message-deletable-headers))
3047 (unless (buffer-modified-p)
3048 (setq headers (delq 'Message-ID (copy-sequence headers))))
3050 (goto-char (point-min))
3051 (and (re-search-forward
3052 (concat "^" (symbol-name (car headers)) ": *") nil t)
3053 (get-text-property (1+ (match-beginning 0)) 'message-deletable)
3054 (message-delete-line))
3056 ;; Go through all the required headers and see if they are in the
3057 ;; articles already. If they are not, or are empty, they are
3058 ;; inserted automatically - except for Subject, Newsgroups and
3061 (goto-char (point-min))
3062 (setq elem (pop headers))
3064 (if (eq (car elem) 'optional)
3065 (setq header (cdr elem))
3066 (setq header (car elem)))
3068 (when (or (not (re-search-forward
3072 (if (stringp header)
3074 (symbol-name header))))
3078 ;; The header was found. We insert a space after the
3079 ;; colon, if there is none.
3080 (if (/= (char-after) ? ) (insert " ") (forward-char 1))
3081 ;; Find out whether the header is empty...
3082 (looking-at "[ \t]*\n[^ \t]")))
3083 ;; So we find out what value we should insert.
3086 ((and (consp elem) (eq (car elem) 'optional))
3087 ;; This is an optional header. If the cdr of this
3088 ;; is something that is nil, then we do not insert
3090 (setq header (cdr elem))
3091 (or (and (fboundp (cdr elem)) (funcall (cdr elem)))
3092 (and (boundp (cdr elem)) (symbol-value (cdr elem)))))
3094 ;; The element is a cons. Either the cdr is a
3095 ;; string to be inserted verbatim, or it is a
3096 ;; function, and we insert the value returned from
3098 (or (and (stringp (cdr elem)) (cdr elem))
3099 (and (fboundp (cdr elem)) (funcall (cdr elem)))))
3100 ((and (boundp header) (symbol-value header))
3101 ;; The element is a symbol. We insert the value
3102 ;; of this symbol, if any.
3103 (symbol-value header))
3104 ((not (message-check-element header))
3105 ;; We couldn't generate a value for this header,
3106 ;; so we just ask the user.
3107 (read-from-minibuffer
3108 (format "Empty header for %s; enter value: " header)))))
3109 ;; Finally insert the header.
3111 (not (equal value "")))
3115 ;; This header didn't exist, so we insert it.
3116 (goto-char (point-max))
3117 (insert (if (stringp header) header (symbol-name header))
3120 ;; The value of this header was empty, so we clear
3121 ;; totally and insert the new value.
3122 (delete-region (point) (gnus-point-at-eol))
3124 ;; Add the deletable property to the headers that require it.
3125 (and (memq header message-deletable-headers)
3126 (progn (beginning-of-line) (looking-at "[^:]+: "))
3127 (add-text-properties
3128 (point) (match-end 0)
3129 '(message-deletable t face italic) (current-buffer)))))))
3130 ;; Insert new Sender if the From is strange.
3131 (let ((from (message-fetch-field "from"))
3132 (sender (message-fetch-field "sender"))
3133 (secure-sender (message-make-sender)))
3135 (not (message-check-element 'sender))
3138 (cadr (mail-extract-address-components from)))
3139 (downcase secure-sender)))
3144 (cadr (mail-extract-address-components sender)))
3145 (downcase secure-sender)))))
3146 (goto-char (point-min))
3147 ;; Rename any old Sender headers to Original-Sender.
3148 (when (re-search-forward "^\\(Original-\\)*Sender:" nil t)
3150 (insert "Original-")
3151 (beginning-of-line))
3152 (when (or (message-news-p)
3153 (string-match "@.+\\.." secure-sender))
3154 (insert "Sender: " secure-sender "\n")))))))
3156 (defun message-insert-courtesy-copy ()
3157 "Insert a courtesy message in mail copies of combined messages."
3161 (message-narrow-to-headers)
3162 (when (setq newsgroups (message-fetch-field "newsgroups"))
3163 (goto-char (point-max))
3164 (insert "Posted-To: " newsgroups "\n")))
3166 (when message-courtesy-message
3168 ((string-match "%s" message-courtesy-message)
3169 (insert (format message-courtesy-message newsgroups)))
3171 (insert message-courtesy-message)))))))
3174 ;;; Setting up a message buffer
3177 (defun message-fill-address (header value)
3179 (narrow-to-region (point) (point))
3180 (insert (capitalize (symbol-name header))
3182 (if (consp value) (car value) value)
3184 (narrow-to-region (point-min) (1- (point-max)))
3186 (goto-char (point-min))
3188 (skip-chars-forward "^,\"" (point-max))
3189 (if (or (eq (char-after) ?,)
3192 (if (and (> (current-column) 78)
3198 (setq last (1+ (point))))
3199 (setq last (1+ (point)))))
3200 (setq quoted (not quoted)))
3203 (goto-char (point-max))
3207 (defun message-fill-header (header value)
3208 (let ((begin (point))
3211 (insert (capitalize (symbol-name header))
3213 (if (consp value) (car value) value)
3216 (narrow-to-region begin (point))
3217 (fill-region-as-paragraph begin (point))
3218 ;; Tapdance around looong Message-IDs.
3220 (when (looking-at "[ \t]*$")
3221 (message-delete-line))
3223 (re-search-forward ":" nil t)
3224 (when (looking-at "\n[ \t]+")
3225 (replace-match " " t t))
3226 (goto-char (point-max)))))
3228 (defun message-shorten-1 (list cut surplus)
3229 ;; Cut SURPLUS elements out of LIST, beginning with CUTth one.
3230 (setcdr (nthcdr (- cut 2) list)
3231 (nthcdr (+ (- cut 2) surplus 1) list)))
3233 (defun message-shorten-references (header references)
3234 "Trim REFERENCES to be less than 31 Message-ID long, and fold them.
3235 If folding is disallowed, also check that the REFERENCES are less
3236 than 988 characters long, and if they are not, trim them until they are."
3243 (goto-char (point-min))
3244 ;; Cons a list of valid references.
3245 (while (re-search-forward "<[^>]+>" nil t)
3246 (push (match-string 0) refs))
3247 (setq refs (nreverse refs)
3248 count (length refs)))
3250 ;; If the list has more than MAXCOUNT elements, trim it by
3251 ;; removing the CUTth element and the required number of
3252 ;; elements that follow.
3253 (when (> count maxcount)
3254 (let ((surplus (- count maxcount)))
3255 (message-shorten-1 refs cut surplus)
3256 (decf count surplus)))
3258 ;; If folding is disallowed, make sure the total length (including
3259 ;; the spaces between) will be less than MAXSIZE characters.
3261 ;; Only disallow folding for News messages. At this point the headers
3262 ;; have not been generated, thus we use message-this-is-news directly.
3263 (when (and message-this-is-news message-cater-to-broken-inn)
3265 (totalsize (+ (apply #'+ (mapcar #'length refs))
3268 (ptr (nthcdr (1- cut) refs)))
3269 ;; Decide how many elements to cut off...
3270 (while (> totalsize maxsize)
3271 (decf totalsize (1+ (length (car ptr))))
3273 (setq ptr (cdr ptr)))
3276 (message-shorten-1 refs cut surplus))))
3278 ;; Finally, collect the references back into a string and insert
3279 ;; it into the buffer.
3280 (let ((refstring (mapconcat #'identity refs " ")))
3281 (if (and message-this-is-news message-cater-to-broken-inn)
3282 (insert (capitalize (symbol-name header)) ": "
3284 (message-fill-header header refstring)))))
3286 (defun message-position-point ()
3287 "Move point to where the user probably wants to find it."
3288 (message-narrow-to-headers)
3290 ((re-search-forward "^[^:]+:[ \t]*$" nil t)
3291 (search-backward ":" )
3294 (if (eq (char-after) ? )
3298 (goto-char (point-max))
3301 (unless (looking-at "$")
3305 (defun message-buffer-name (type &optional to group)
3306 "Return a new (unique) buffer name based on TYPE and TO."
3308 ;; Generate a new buffer name The Message Way.
3309 ((eq message-generate-new-buffers 'unique)
3310 (generate-new-buffer-name
3314 (or (car (mail-extract-address-components to))
3317 (if (and group (not (string= group ""))) (concat " on " group) "")
3319 ;; Check whether `message-generate-new-buffers' is a function,
3320 ;; and if so, call it.
3321 ((message-functionp message-generate-new-buffers)
3322 (funcall message-generate-new-buffers type to group))
3323 ((eq message-generate-new-buffers 'unsent)
3324 (generate-new-buffer-name
3325 (concat "*unsent " type
3328 (or (car (mail-extract-address-components to))
3331 (if (and group (not (string= group ""))) (concat " on " group) "")
3333 ;; Use standard name.
3335 (format "*%s message*" type))))
3337 (defun message-pop-to-buffer (name)
3338 "Pop to buffer NAME, and warn if it already exists and is modified."
3339 (let ((buffer (get-buffer name)))
3341 (buffer-name buffer))
3343 (set-buffer (pop-to-buffer buffer))
3344 (when (and (buffer-modified-p)
3346 "Message already being composed; erase? ")))
3347 (error "Message being composed")))
3348 (set-buffer (pop-to-buffer name)))
3352 (defun message-do-send-housekeeping ()
3353 "Kill old message buffers."
3354 ;; We might have sent this buffer already. Delete it from the
3356 (setq message-buffer-list (delq (current-buffer) message-buffer-list))
3357 (while (and message-max-buffers
3359 (>= (length message-buffer-list) message-max-buffers))
3360 ;; Kill the oldest buffer -- unless it has been changed.
3361 (let ((buffer (pop message-buffer-list)))
3362 (when (and (buffer-name buffer)
3363 (not (buffer-modified-p buffer)))
3364 (kill-buffer buffer))))
3365 ;; Rename the buffer.
3366 (if message-send-rename-function
3367 (funcall message-send-rename-function)
3368 (when (string-match "\\`\\*\\(unsent \\)?" (buffer-name))
3370 (concat "*sent " (substring (buffer-name) (match-end 0))) t)))
3371 ;; Push the current buffer onto the list.
3372 (when message-max-buffers
3373 (setq message-buffer-list
3374 (nconc message-buffer-list (list (current-buffer))))))
3376 (defvar mc-modes-alist)
3377 (defun message-setup (headers &optional replybuffer actions)
3378 (when (and (boundp 'mc-modes-alist)
3379 (not (assq 'message-mode mc-modes-alist)))
3380 (push '(message-mode (encrypt . mc-encrypt-message)
3381 (sign . mc-sign-message))
3384 (setq message-send-actions actions))
3385 (setq message-reply-buffer replybuffer)
3386 (goto-char (point-min))
3387 ;; Insert all the headers.
3390 (alist message-header-format-alist))
3392 (unless (assq (caar h) message-header-format-alist)
3393 (push (list (caar h)) alist))
3397 (delete-region (point) (progn (forward-line -1) (point)))
3398 (when message-default-headers
3399 (insert message-default-headers)
3400 (or (bolp) (insert ?\n)))
3404 (insert mail-header-separator "\n")
3408 (when (message-news-p)
3409 (when message-default-news-headers
3410 (insert message-default-news-headers)
3411 (or (bolp) (insert ?\n)))
3412 (when message-generate-headers-first
3413 (message-generate-headers
3416 (copy-sequence message-required-news-headers))))))
3417 (when (message-mail-p)
3418 (when message-default-mail-headers
3419 (insert message-default-mail-headers)
3420 (or (bolp) (insert ?\n)))
3421 (when message-generate-headers-first
3422 (message-generate-headers
3425 (copy-sequence message-required-mail-headers))))))
3426 (run-hooks 'message-signature-setup-hook)
3427 (message-insert-signature)
3429 (message-narrow-to-headers)
3430 (run-hooks 'message-header-setup-hook))
3431 (set-buffer-modified-p nil)
3432 (setq buffer-undo-list nil)
3433 (run-hooks 'message-setup-hook)
3434 (message-position-point)
3437 (defun message-set-auto-save-file-name ()
3438 "Associate the message buffer with a file in the drafts directory."
3439 (when message-auto-save-directory
3441 (setq message-draft-article
3442 (nndraft-request-associate-buffer "drafts"))
3443 (setq buffer-file-name (expand-file-name "*message*"
3444 message-auto-save-directory))
3445 (setq buffer-auto-save-file-name (make-auto-save-file-name)))
3446 (clear-visited-file-modtime)
3447 (setq buffer-file-coding-system message-draft-coding-system)))
3449 (defun message-disassociate-draft ()
3450 "Disassociate the message buffer from the drafts directory."
3451 (when message-draft-article
3452 (nndraft-request-expire-articles
3453 (list message-draft-article) "drafts" nil t)))
3455 (defun message-insert-headers ()
3456 "Generate the headers for the article."
3460 (message-narrow-to-headers)
3461 (when (message-news-p)
3462 (message-generate-headers
3465 (copy-sequence message-required-news-headers)))))
3466 (when (message-mail-p)
3467 (message-generate-headers
3470 (copy-sequence message-required-mail-headers))))))))
3475 ;;; Commands for interfacing with message
3479 (defun message-mail (&optional to subject
3480 other-headers continue switch-function
3481 yank-action send-actions)
3482 "Start editing a mail message to be sent.
3483 OTHER-HEADERS is an alist of header/value pairs."
3485 (let ((message-this-is-mail t))
3486 (message-pop-to-buffer (message-buffer-name "mail" to))
3489 `((To . ,(or to "")) (Subject . ,(or subject "")))
3490 (when other-headers other-headers)))))
3493 (defun message-news (&optional newsgroups subject)
3494 "Start editing a news article to be sent."
3496 (let ((message-this-is-news t))
3497 (message-pop-to-buffer (message-buffer-name "news" nil newsgroups))
3498 (message-setup `((Newsgroups . ,(or newsgroups ""))
3499 (Subject . ,(or subject ""))))))
3501 (defun message-get-reply-headers (wide &optional to-address)
3502 (let (follow-to mct never-mct from to cc reply-to ccalist)
3503 ;; Find all relevant headers we need.
3504 (setq from (message-fetch-field "from")
3505 to (message-fetch-field "to")
3506 cc (message-fetch-field "cc")
3507 mct (message-fetch-field "mail-copies-to")
3508 reply-to (message-fetch-field "reply-to"))
3510 ;; Handle special values of Mail-Copies-To.
3512 (cond ((or (equal (downcase mct) "never")
3513 (equal (downcase mct) "nobody"))
3516 ((or (equal (downcase mct) "always")
3517 (equal (downcase mct) "poster"))
3518 (setq mct (or reply-to from)))))
3523 (setq follow-to (list (cons 'To (or to-address reply-to from))))
3524 (when (and wide mct)
3525 (push (cons 'Cc mct) follow-to)))
3528 (message-set-work-buffer)
3530 (insert (or reply-to from "")))
3531 (insert (if to (concat (if (bolp) "" ", ") to "") ""))
3532 (insert (if mct (concat (if (bolp) "" ", ") mct) ""))
3533 (insert (if cc (concat (if (bolp) "" ", ") cc) ""))
3534 (goto-char (point-min))
3535 (while (re-search-forward "[ \t]+" nil t)
3536 (replace-match " " t t))
3537 ;; Remove addresses that match `rmail-dont-reply-to-names'.
3538 (let ((rmail-dont-reply-to-names message-dont-reply-to-names))
3539 (insert (prog1 (rmail-dont-reply-to (buffer-string))
3541 (goto-char (point-min))
3542 ;; Perhaps "Mail-Copies-To: never" removed the only address?
3544 (insert (or reply-to from "")))
3548 (cons (mail-strip-quoted-names addr) addr))
3549 (message-tokenize-header (buffer-string))))
3552 (setq ccalist (delq (assoc (car (pop s)) s) ccalist)))))
3553 (setq follow-to (list (cons 'To (cdr (pop ccalist)))))
3555 (let ((ccs (cons 'Cc (mapconcat
3556 (lambda (addr) (cdr addr)) ccalist ", "))))
3557 (when (string-match "^ +" (cdr ccs))
3558 (setcdr ccs (substring (cdr ccs) (match-end 0))))
3559 (push ccs follow-to)))))
3564 (defun message-reply (&optional to-address wide)
3565 "Start editing a reply to the article in the current buffer."
3567 (let ((cur (current-buffer))
3568 from subject date reply-to to cc
3569 references message-id follow-to
3570 (inhibit-point-motion-hooks t)
3571 (message-this-is-mail t)
3574 (message-narrow-to-head)
3575 ;; Allow customizations to have their say.
3577 ;; This is a regular reply.
3578 (if (message-functionp message-reply-to-function)
3579 (setq follow-to (funcall message-reply-to-function)))
3580 ;; This is a followup.
3581 (if (message-functionp message-wide-reply-to-function)
3584 (funcall message-wide-reply-to-function)))))
3585 (setq message-id (message-fetch-field "message-id" t)
3586 references (message-fetch-field "references")
3587 date (message-fetch-field "date")
3588 from (message-fetch-field "from")
3589 subject (or (message-fetch-field "subject") "none"))
3590 ;; Remove any (buggy) Re:'s that are present and make a
3592 (when (string-match message-subject-re-regexp subject)
3593 (setq subject (substring subject (match-end 0))))
3594 (setq subject (concat "Re: " subject))
3596 (when (and (setq gnus-warning (message-fetch-field "gnus-warning"))
3597 (string-match "<[^>]+>" gnus-warning))
3598 (setq message-id (match-string 0 gnus-warning)))
3601 (setq follow-to (message-get-reply-headers wide to-address))))
3603 (message-pop-to-buffer
3604 (message-buffer-name
3605 (if wide "wide reply" "reply") from
3606 (if wide to-address nil)))
3608 (setq message-reply-headers
3609 (vector 0 subject from date message-id references 0 0 ""))
3612 `((Subject . ,subject)
3614 ,@(if (or references message-id)
3615 `((References . ,(concat (or references "") (and references " ")
3616 (or message-id ""))))
3621 (defun message-wide-reply (&optional to-address)
3622 "Make a \"wide\" reply to the message in the current buffer."
3624 (message-reply to-address t))
3627 (defun message-followup (&optional to-newsgroups)
3628 "Follow up to the message in the current buffer.
3629 If TO-NEWSGROUPS, use that as the new Newsgroups line."
3631 (let ((cur (current-buffer))
3632 from subject date reply-to mct
3633 references message-id follow-to
3634 (inhibit-point-motion-hooks t)
3635 (message-this-is-news t)
3636 followup-to distribution newsgroups gnus-warning posted-to)
3639 (goto-char (point-min))
3640 (if (search-forward "\n\n" nil t)
3643 (when (message-functionp message-followup-to-function)
3645 (funcall message-followup-to-function)))
3646 (setq from (message-fetch-field "from")
3647 date (message-fetch-field "date")
3648 subject (or (message-fetch-field "subject") "none")
3649 references (message-fetch-field "references")
3650 message-id (message-fetch-field "message-id" t)
3651 followup-to (message-fetch-field "followup-to")
3652 newsgroups (message-fetch-field "newsgroups")
3653 posted-to (message-fetch-field "posted-to")
3654 reply-to (message-fetch-field "reply-to")
3655 distribution (message-fetch-field "distribution")
3656 mct (message-fetch-field "mail-copies-to"))
3657 (when (and (setq gnus-warning (message-fetch-field "gnus-warning"))
3658 (string-match "<[^>]+>" gnus-warning))
3659 (setq message-id (match-string 0 gnus-warning)))
3660 ;; Remove bogus distribution.
3661 (when (and (stringp distribution)
3662 (let ((case-fold-search t))
3663 (string-match "world" distribution)))
3664 (setq distribution nil))
3665 ;; Remove any (buggy) Re:'s that are present and make a
3667 (when (string-match message-subject-re-regexp subject)
3668 (setq subject (substring subject (match-end 0))))
3669 (setq subject (concat "Re: " subject))
3672 (message-pop-to-buffer (message-buffer-name "followup" from newsgroups))
3675 `((Subject . ,subject)
3678 (list (cons 'Newsgroups to-newsgroups)))
3679 (follow-to follow-to)
3680 ((and followup-to message-use-followup-to)
3683 ((equal (downcase followup-to) "poster")
3684 (if (or (eq message-use-followup-to 'use)
3685 (message-y-or-n-p "Obey Followup-To: poster? " t "\
3686 You should normally obey the Followup-To: header.
3688 `Followup-To: poster' sends your response via e-mail instead of news.
3690 A typical situation where `Followup-To: poster' is used is when the poster
3691 does not read the newsgroup, so he wouldn't see any replies sent to it."))
3693 (setq message-this-is-news nil)
3694 (cons 'To (or reply-to from "")))
3695 (cons 'Newsgroups newsgroups)))
3697 (if (or (equal followup-to newsgroups)
3698 (not (eq message-use-followup-to 'ask))
3700 (concat "Obey Followup-To: " followup-to "? ") t "\
3701 You should normally obey the Followup-To: header.
3703 `Followup-To: " followup-to "'
3704 directs your response to " (if (string-match "," followup-to)
3705 "the specified newsgroups"
3706 "that newsgroup only") ".
3708 If a message is posted to several newsgroups, Followup-To is often
3709 used to direct the following discussion to one newsgroup only,
3710 because discussions that are spread over several newsgroup tend to
3711 be fragmented and very difficult to follow.
3713 Also, some source/announcement newsgroups are not indented for discussion;
3714 responses here are directed to other newsgroups."))
3715 (cons 'Newsgroups followup-to)
3716 (cons 'Newsgroups newsgroups))))))
3718 `((Newsgroups . ,posted-to)))
3720 `((Newsgroups . ,newsgroups))))
3721 ,@(and distribution (list (cons 'Distribution distribution)))
3722 ,@(if (or references message-id)
3723 `((References . ,(concat (or references "") (and references " ")
3724 (or message-id "")))))
3726 (not (or (equal (downcase mct) "never")
3727 (equal (downcase mct) "nobody"))))
3728 (list (cons 'Cc (if (or (equal (downcase mct) "always")
3729 (equal (downcase mct) "poster"))
3730 (or reply-to from "")
3735 (setq message-reply-headers
3736 (vector 0 subject from date message-id references 0 0 ""))))
3740 (defun message-cancel-news (&optional arg)
3741 "Cancel an article you posted.
3742 If ARG, allow editing of the cancellation message."
3744 (unless (message-news-p)
3745 (error "This is not a news article; canceling is impossible"))
3746 (when (yes-or-no-p "Do you really want to cancel this article? ")
3747 (let (from newsgroups message-id distribution buf sender)
3749 ;; Get header info from original article.
3751 (message-narrow-to-head)
3752 (setq from (message-fetch-field "from")
3753 sender (message-fetch-field "sender")
3754 newsgroups (message-fetch-field "newsgroups")
3755 message-id (message-fetch-field "message-id" t)
3756 distribution (message-fetch-field "distribution")))
3757 ;; Make sure that this article was written by the user.
3758 (unless (or (and sender
3761 (downcase (message-make-sender))))
3763 (downcase (cadr (mail-extract-address-components from)))
3764 (downcase (cadr (mail-extract-address-components
3765 (message-make-from))))))
3766 (error "This article is not yours"))
3767 ;; Make control message.
3770 (setq buf (set-buffer (get-buffer-create " *message cancel*"))))
3772 (insert "Newsgroups: " newsgroups "\n"
3773 "From: " (message-make-from) "\n"
3774 "Subject: cmsg cancel " message-id "\n"
3775 "Control: cancel " message-id "\n"
3777 (concat "Distribution: " distribution "\n")
3779 mail-header-separator "\n"
3780 message-cancel-message)
3781 (run-hooks 'message-cancel-hook)
3783 (message "Canceling your article...")
3784 (if (let ((message-syntax-checks
3785 'dont-check-for-anything-just-trust-me))
3786 (funcall message-send-news-function))
3787 (message "Canceling your article...done"))
3788 (kill-buffer buf))))))
3791 (defun message-supersede ()
3792 "Start composing a message to supersede the current message.
3793 This is done simply by taking the old article and adding a Supersedes
3794 header line with the old Message-ID."
3796 (let ((cur (current-buffer))
3797 (sender (message-fetch-field "sender"))
3798 (from (message-fetch-field "from")))
3799 ;; Check whether the user owns the article that is to be superseded.
3800 (unless (or (and sender
3803 (downcase (message-make-sender))))
3805 (downcase (cadr (mail-extract-address-components from)))
3806 (downcase (cadr (mail-extract-address-components
3807 (message-make-from))))))
3808 (error "This article is not yours"))
3809 ;; Get a normal message buffer.
3810 (message-pop-to-buffer (message-buffer-name "supersede"))
3811 (insert-buffer-substring cur)
3812 (message-narrow-to-head)
3813 ;; Remove unwanted headers.
3814 (when message-ignored-supersedes-headers
3815 (message-remove-header message-ignored-supersedes-headers t))
3816 (goto-char (point-min))
3817 (if (not (re-search-forward "^Message-ID: " nil t))
3818 (error "No Message-ID in this article")
3819 (replace-match "Supersedes: " t t))
3820 (goto-char (point-max))
3821 (insert mail-header-separator)
3826 (defun message-recover ()
3827 "Reread contents of current buffer from its last auto-save file."
3829 (let ((file-name (make-auto-save-file-name)))
3830 (cond ((save-window-excursion
3831 (if (not (eq system-type 'vax-vms))
3832 (with-output-to-temp-buffer "*Directory*"
3833 (with-current-buffer standard-output
3834 (fundamental-mode)) ; for Emacs 20.4+
3835 (buffer-disable-undo standard-output)
3836 (let ((default-directory "/"))
3838 "ls" nil standard-output nil "-l" file-name))))
3839 (yes-or-no-p (format "Recover auto save file %s? " file-name)))
3840 (let ((buffer-read-only nil))
3842 (insert-file-contents file-name nil)))
3843 (t (error "message-recover cancelled")))))
3845 ;;; Washing Subject:
3847 (defun message-wash-subject (subject)
3848 "Remove junk like \"Re:\", \"(fwd)\", etc. that was added to the subject by previous forwarders, replyers, etc."
3850 (insert-string subject)
3851 (goto-char (point-min))
3852 ;; strip Re/Fwd stuff off the beginning
3853 (while (re-search-forward
3854 "\\([Rr][Ee]:\\|[Ff][Ww][Dd]\\(\\[[0-9]*\\]\\)?:\\|[Ff][Ww]:\\)" nil t)
3857 ;; and gnus-style forwards [foo@bar.com] subject
3858 (goto-char (point-min))
3859 (while (re-search-forward "\\[[^ \t]*\\(@\\|\\.\\)[^ \t]*\\]" nil t)
3863 (goto-char (point-max))
3864 (while (re-search-backward "([Ff][Ww][Dd])" nil t)
3867 ;; and finally, any whitespace that was left-over
3868 (goto-char (point-min))
3869 (while (re-search-forward "^[ \t]+" nil t)
3871 (goto-char (point-max))
3872 (while (re-search-backward "[ \t]+$" nil t)
3877 ;;; Forwarding messages.
3879 (defun message-forward-subject-author-subject (subject)
3880 "Generate a subject for a forwarded message.
3881 The form is: [Source] Subject, where if the original message was mail,
3882 Source is the sender, and if the original message was news, Source is
3883 the list of newsgroups is was posted to."
3885 (or (message-fetch-field
3886 (if (message-news-p) "newsgroups" "from"))
3890 (defun message-forward-subject-fwd (subject)
3891 "Generate a subject for a forwarded message.
3892 The form is: Fwd: Subject, where Subject is the original subject of
3894 (concat "Fwd: " subject))
3896 (defun message-make-forward-subject ()
3897 "Return a Subject header suitable for the message in the current buffer."
3901 (message-narrow-to-head)
3902 (let ((funcs message-make-forward-subject-function)
3903 (subject (if message-wash-forwarded-subjects
3904 (message-wash-subject
3905 (or (message-fetch-field "Subject") ""))
3906 (or (message-fetch-field "Subject") ""))))
3907 ;; Make sure funcs is a list.
3910 (setq funcs (list funcs)))
3911 ;; Apply funcs in order, passing subject generated by previous
3912 ;; func to the next one.
3914 (when (message-functionp (car funcs))
3915 (setq subject (funcall (car funcs) subject)))
3916 (setq funcs (cdr funcs)))
3920 (defun message-forward (&optional news)
3921 "Forward the current message via mail.
3922 Optional NEWS will use news to forward instead of mail."
3924 (let ((cur (current-buffer))
3925 (subject (message-make-forward-subject))
3928 (message-news nil subject)
3929 (message-mail nil subject))
3930 ;; Put point where we want it before inserting the forwarded
3932 (if message-forward-before-signature
3934 (goto-char (point-max)))
3935 (if message-forward-as-mime
3936 (insert "\n\n<#part type=message/rfc822 disposition=inline>\n")
3937 (insert "\n-------------------- Start of forwarded message --------------------\n"))
3940 (mml-insert-buffer cur)
3942 (if message-forward-as-mime
3943 (insert "<#/part>\n")
3944 (insert "\n-------------------- End of forwarded message --------------------\n"))
3945 (when (and (not current-prefix-arg)
3946 message-forward-ignored-headers)
3948 (narrow-to-region b e)
3950 (narrow-to-region (point) (or (search-forward "\n\n" nil t) (point)))
3951 (message-remove-header message-forward-ignored-headers t))))
3952 (message-position-point)))
3955 (defun message-resend (address)
3956 "Resend the current article to ADDRESS."
3958 (list (message-read-from-minibuffer "Resend message to: ")))
3959 (message "Resending message to %s..." address)
3961 (let ((cur (current-buffer))
3963 ;; We first set up a normal mail buffer.
3964 (set-buffer (get-buffer-create " *message resend*"))
3966 (message-setup `((To . ,address)))
3967 ;; Insert our usual headers.
3968 (message-generate-headers '(From Date To))
3969 (message-narrow-to-headers)
3970 ;; Rename them all to "Resent-*".
3971 (while (re-search-forward "^[A-Za-z]" nil t)
3976 (delete-region (point) (point-max))
3978 ;; Insert the message to be resent.
3979 (insert-buffer-substring cur)
3980 (goto-char (point-min))
3981 (search-forward "\n\n")
3984 (narrow-to-region beg (point))
3985 (message-remove-header message-ignored-resent-headers t)
3986 (goto-char (point-max)))
3987 (insert mail-header-separator)
3988 ;; Rename all old ("Also-")Resent headers.
3989 (while (re-search-backward "^\\(Also-\\)*Resent-" beg t)
3992 ;; Quote any "From " lines at the beginning.
3994 (when (looking-at "From ")
3995 (replace-match "X-From-Line: "))
3997 (let ((message-inhibit-body-encoding t)
3998 message-required-mail-headers)
3999 (message-send-mail))
4000 (kill-buffer (current-buffer)))
4001 (message "Resending message to %s...done" address)))
4004 (defun message-bounce ()
4005 "Re-mail the current message.
4006 This only makes sense if the current message is a bounce message than
4007 contains some mail you have written which has been bounced back to
4010 (let ((handles (mm-dissect-buffer t))
4012 (message-pop-to-buffer (message-buffer-name "bounce"))
4013 (if (stringp (car handles))
4014 ;; This is a MIME bounce.
4015 (mm-insert-part (car (last handles)))
4016 ;; This is a non-MIME bounce, so we try to remove things
4018 (mm-insert-part handles)
4020 (goto-char (point-min))
4021 (search-forward "\n\n" nil t)
4022 (or (and (re-search-forward message-unsent-separator nil t)
4024 (re-search-forward "^Return-Path:.*\n" nil t))
4025 ;; We remove everything before the bounced mail.
4028 (if (re-search-forward "^[^ \n\t]+:" nil t)
4032 (message-narrow-to-head)
4033 (message-remove-header message-ignored-bounced-headers t)
4034 (goto-char (point-max))
4035 (insert mail-header-separator))
4036 (message-position-point)))
4039 ;;; Interactive entry points for new message buffers.
4043 (defun message-mail-other-window (&optional to subject)
4044 "Like `message-mail' command, but display mail buffer in another window."
4046 (let ((pop-up-windows t)
4047 (special-display-buffer-names nil)
4048 (special-display-regexps nil)
4049 (same-window-buffer-names nil)
4050 (same-window-regexps nil))
4051 (message-pop-to-buffer (message-buffer-name "mail" to)))
4052 (let ((message-this-is-mail t))
4053 (message-setup `((To . ,(or to "")) (Subject . ,(or subject ""))))))
4056 (defun message-mail-other-frame (&optional to subject)
4057 "Like `message-mail' command, but display mail buffer in another frame."
4059 (let ((pop-up-frames t)
4060 (special-display-buffer-names nil)
4061 (special-display-regexps nil)
4062 (same-window-buffer-names nil)
4063 (same-window-regexps nil))
4064 (message-pop-to-buffer (message-buffer-name "mail" to)))
4065 (let ((message-this-is-mail t))
4066 (message-setup `((To . ,(or to "")) (Subject . ,(or subject ""))))))
4069 (defun message-news-other-window (&optional newsgroups subject)
4070 "Start editing a news article to be sent."
4072 (let ((pop-up-windows t)
4073 (special-display-buffer-names nil)
4074 (special-display-regexps nil)
4075 (same-window-buffer-names nil)
4076 (same-window-regexps nil))
4077 (message-pop-to-buffer (message-buffer-name "news" nil newsgroups)))
4078 (let ((message-this-is-news t))
4079 (message-setup `((Newsgroups . ,(or newsgroups ""))
4080 (Subject . ,(or subject ""))))))
4083 (defun message-news-other-frame (&optional newsgroups subject)
4084 "Start editing a news article to be sent."
4086 (let ((pop-up-frames t)
4087 (special-display-buffer-names nil)
4088 (special-display-regexps nil)
4089 (same-window-buffer-names nil)
4090 (same-window-regexps nil))
4091 (message-pop-to-buffer (message-buffer-name "news" nil newsgroups)))
4092 (let ((message-this-is-news t))
4093 (message-setup `((Newsgroups . ,(or newsgroups ""))
4094 (Subject . ,(or subject ""))))))
4098 ;; This code should be moved to underline.el (from which it is stolen).
4101 (defun bold-region (start end)
4102 "Bold all nonblank characters in the region.
4103 Works by overstriking characters.
4104 Called from program, takes two arguments START and END
4105 which specify the range to operate on."
4108 (let ((end1 (make-marker)))
4109 (move-marker end1 (max start end))
4110 (goto-char (min start end))
4111 (while (< (point) end1)
4112 (or (looking-at "[_\^@- ]")
4113 (insert (char-after) "\b"))
4114 (forward-char 1)))))
4117 (defun unbold-region (start end)
4118 "Remove all boldness (overstruck characters) in the region.
4119 Called from program, takes two arguments START and END
4120 which specify the range to operate on."
4123 (let ((end1 (make-marker)))
4124 (move-marker end1 (max start end))
4125 (goto-char (min start end))
4126 (while (re-search-forward "\b" end1 t)
4127 (if (eq (char-after) (char-after (- (point) 2)))
4128 (delete-char -2))))))
4130 (defalias 'message-exchange-point-and-mark 'exchange-point-and-mark)
4132 ;; Support for toolbar
4133 (when (string-match "XEmacs\\|Lucid" emacs-version)
4134 (require 'messagexmas))
4136 ;;; Group name completion.
4138 (defvar message-newgroups-header-regexp
4139 "^\\(Newsgroups\\|Followup-To\\|Posted-To\\|Gcc\\):"
4140 "Regexp that match headers that lists groups.")
4142 (defun message-tab ()
4143 "Expand group names in Newsgroups and Followup-To headers.
4144 Do a `tab-to-tab-stop' if not in those headers."
4146 (if (let ((mail-abbrev-mode-regexp message-newgroups-header-regexp))
4147 (mail-abbrev-in-expansion-header-p))
4148 (message-expand-group)
4151 (defvar gnus-active-hashtb)
4152 (defun message-expand-group ()
4153 "Expand the group name under point."
4154 (let* ((b (save-excursion
4159 (skip-chars-forward "^:")
4162 (skip-chars-backward "^, \t\n") (point))))
4163 (completion-ignore-case t)
4164 (string (buffer-substring b (progn (skip-chars-forward "^,\t\n ")
4166 (hashtb (and (boundp 'gnus-active-hashtb) gnus-active-hashtb))
4167 (completions (all-completions string hashtb))
4169 (delete-region b (point))
4171 ((= (length completions) 1)
4172 (if (string= (car completions) string)
4175 (message "Only matching group"))
4176 (insert (car completions))))
4177 ((and (setq comp (try-completion string hashtb))
4178 (not (string= comp string)))
4183 (message "No matching groups")
4184 (save-selected-window
4185 (pop-to-buffer "*Completions*")
4186 (buffer-disable-undo)
4187 (let ((buffer-read-only nil))
4189 (let ((standard-output (current-buffer)))
4190 (display-completion-list (sort completions 'string<)))
4191 (goto-char (point-min))
4192 (delete-region (point) (progn (forward-line 3) (point))))))))))
4196 (defun message-talkative-question (ask question show &rest text)
4197 "Call FUNCTION with argument QUESTION; optionally display TEXT... args.
4198 If SHOW is non-nil, the arguments TEXT... are displayed in a temp buffer.
4199 The following arguments may contain lists of values."
4201 (setq text (message-flatten-list text)))
4202 (save-window-excursion
4204 (with-output-to-temp-buffer " *MESSAGE information message*"
4205 (set-buffer " *MESSAGE information message*")
4206 (fundamental-mode) ; for Emacs 20.4+
4207 (mapcar 'princ text)
4208 (goto-char (point-min))))
4209 (funcall ask question))
4210 (funcall ask question)))
4212 (defun message-flatten-list (list)
4213 "Return a new, flat list that contains all elements of LIST.
4215 \(message-flatten-list '(1 (2 3 (4 5 (6))) 7))
4218 (apply 'append (mapcar 'message-flatten-list list)))
4222 (defun message-generate-new-buffer-clone-locals (name &optional varstr)
4223 "Create and return a buffer with a name based on NAME using generate-new-buffer.
4224 Then clone the local variables and values from the old buffer to the
4225 new one, cloning only the locals having a substring matching the
4227 (let ((oldbuf (current-buffer)))
4229 (set-buffer (generate-new-buffer name))
4230 (message-clone-locals oldbuf varstr)
4233 (defun message-clone-locals (buffer &optional varstr)
4234 "Clone the local variables from BUFFER to the current buffer."
4235 (let ((locals (save-excursion
4237 (buffer-local-variables)))
4238 (regexp "^gnus\\|^nn\\|^message\\|^user-mail-address"))
4241 (when (and (consp local)
4243 (string-match regexp (symbol-name (car local)))
4245 (string-match varstr (symbol-name (car local)))))
4247 (set (make-local-variable (car local))
4251 ;;; Miscellaneous functions
4253 ;; stolen (and renamed) from nnheader.el
4254 (defun message-replace-chars-in-string (string from to)
4255 "Replace characters in STRING from FROM to TO."
4256 (let ((string (substring string 0)) ;Copy string.
4257 (len (length string))
4259 ;; Replace all occurrences of FROM with TO.
4261 (when (= (aref string idx) from)
4262 (aset string idx to))
4263 (setq idx (1+ idx)))
4270 (defvar message-inhibit-body-encoding nil)
4272 (defun message-encode-message-body ()
4273 (unless message-inhibit-body-encoding
4274 (let ((mail-parse-charset (or mail-parse-charset
4275 message-default-charset))
4276 (case-fold-search t)
4277 lines content-type-p)
4280 (narrow-to-region (point) (point-max))
4281 (let ((new (mml-generate-mime)))
4283 (delete-region (point-min) (point-max))
4285 (goto-char (point-min))
4286 (if (eq (aref new 0) ?\n)
4288 (search-forward "\n\n")
4289 (setq lines (buffer-substring (point-min) (1- (point))))
4290 (delete-region (point-min) (point))))))
4292 (message-narrow-to-headers-or-head)
4293 (message-remove-header "Mime-Version")
4294 (goto-char (point-max))
4295 (insert "MIME-Version: 1.0\n")
4298 (setq content-type-p
4299 (re-search-backward "^Content-Type:" nil t)))
4301 (message-narrow-to-headers-or-head)
4302 (message-remove-first-header "Content-Type")
4303 (message-remove-first-header "Content-Transfer-Encoding"))
4304 ;; We always make sure that the message has a Content-Type header.
4305 ;; This is because some broken MTAs and MUAs get awfully confused
4306 ;; when confronted with a message with a MIME-Version header and
4307 ;; without a Content-Type header. For instance, Solaris'
4309 (unless content-type-p
4310 (goto-char (point-min))
4311 (re-search-forward "^MIME-Version:")
4313 (insert "Content-Type: text/plain; charset=us-ascii\n")))))
4315 (defun message-read-from-minibuffer (prompt)
4316 "Read from the minibuffer while providing abbrev expansion."
4317 (if (fboundp 'mail-abbrevs-setup)
4318 (let ((mail-abbrev-mode-regexp "")
4319 (minibuffer-setup-hook 'mail-abbrevs-setup))
4320 (read-from-minibuffer prompt)))
4321 (let ((minibuffer-setup-hook 'mail-abbrev-minibuffer-setup-hook))
4322 (read-string prompt)))
4326 (run-hooks 'message-load-hook)
4329 ;; coding: iso-8859-1
4332 ;;; message.el ends here