1 ;;; message.el --- composing mail and news messages
2 ;; Copyright (C) 1996-2000 Free Software Foundation, Inc.
4 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
5 ;; Keywords: mail, news
7 ;; This file is part of GNU Emacs.
9 ;; GNU Emacs is free software; you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation; either version 2, or (at your option)
14 ;; GNU Emacs is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; GNU General Public License for more details.
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs; see the file COPYING. If not, write to the
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22 ;; Boston, MA 02111-1307, USA.
26 ;; This mode provides mail-sending facilities from within Emacs. It
27 ;; consists mainly of large chunks of code from the sendmail.el,
28 ;; gnus-msg.el and rnewspost.el files.
32 (eval-when-compile (require 'cl))
36 (if (string-match "XEmacs\\|Lucid" emacs-version)
37 (require 'mail-abbrevs)
38 (require 'mailabbrev))
44 (defgroup message '((user-mail-address custom-variable)
45 (user-full-name custom-variable))
46 "Mail and news message composing."
47 :link '(custom-manual "(message)Top")
51 (put 'user-mail-address 'custom-type 'string)
52 (put 'user-full-name 'custom-type 'string)
54 (defgroup message-various nil
55 "Various Message Variables"
56 :link '(custom-manual "(message)Various Message Variables")
59 (defgroup message-buffers nil
61 :link '(custom-manual "(message)Message Buffers")
64 (defgroup message-sending nil
66 :link '(custom-manual "(message)Sending Variables")
69 (defgroup message-interface nil
71 :link '(custom-manual "(message)Interface")
74 (defgroup message-forwarding nil
76 :link '(custom-manual "(message)Forwarding")
77 :group 'message-interface)
79 (defgroup message-insertion nil
81 :link '(custom-manual "(message)Insertion")
84 (defgroup message-headers nil
86 :link '(custom-manual "(message)Message Headers")
89 (defgroup message-news nil
90 "Composing News Messages"
93 (defgroup message-mail nil
94 "Composing Mail Messages"
97 (defgroup message-faces nil
98 "Faces used for message composing."
102 (defcustom message-directory "~/Mail/"
103 "*Directory from which all other mail file variables are derived."
104 :group 'message-various
107 (defcustom message-max-buffers 10
108 "*How many buffers to keep before starting to kill them off."
109 :group 'message-buffers
112 (defcustom message-send-rename-function nil
113 "Function called to rename the buffer after sending it."
114 :group 'message-buffers
117 (defcustom message-fcc-handler-function 'message-output
118 "*A function called to save outgoing articles.
119 This function will be called with the name of the file to store the
120 article in. The default function is `message-output' which saves in Unix
122 :type '(radio (function-item message-output)
123 (function :tag "Other"))
124 :group 'message-sending)
126 (defcustom message-courtesy-message
127 "The following message is a courtesy copy of an article\nthat has been posted to %s as well.\n\n"
128 "*This is inserted at the start of a mailed copy of a posted message.
129 If the string contains the format spec \"%s\", the Newsgroups
130 the article has been posted to will be inserted there.
131 If this variable is nil, no such courtesy message will be added."
132 :group 'message-sending
135 (defcustom message-ignored-bounced-headers "^\\(Received\\|Return-Path\\):"
136 "*Regexp that matches headers to be removed in resent bounced mail."
137 :group 'message-interface
141 (defcustom message-from-style 'default
142 "*Specifies how \"From\" headers look.
144 If `nil', they contain just the return address like:
146 If `parens', they look like:
147 king@grassland.com (Elvis Parsley)
148 If `angles', they look like:
149 Elvis Parsley <king@grassland.com>
151 Otherwise, most addresses look like `angles', but they look like
152 `parens' if `angles' would need quoting and `parens' would not."
153 :type '(choice (const :tag "simple" nil)
157 :group 'message-headers)
159 (defcustom message-syntax-checks nil
160 ;; Guess this one shouldn't be easy to customize...
161 "*Controls what syntax checks should not be performed on outgoing posts.
162 To disable checking of long signatures, for instance, add
163 `(signature . disabled)' to this list.
165 Don't touch this variable unless you really know what you're doing.
167 Checks include subject-cmsg multiple-headers sendsys message-id from
168 long-lines control-chars size new-text redirected-followup signature
169 approved sender empty empty-headers message-id from subject
170 shorten-followup-to existing-newsgroups buffer-file-name unchanged
172 :group 'message-news)
174 (defcustom message-required-news-headers
175 '(From Newsgroups Subject Date Message-ID
176 (optional . Organization) Lines
177 (optional . User-Agent))
178 "*Headers to be generated or prompted for when posting an article.
179 RFC977 and RFC1036 require From, Date, Newsgroups, Subject,
180 Message-ID. Organization, Lines, In-Reply-To, Expires, and
181 User-Agent are optional. If don't you want message to insert some
182 header, remove it from this list."
184 :group 'message-headers
185 :type '(repeat sexp))
187 (defcustom message-required-mail-headers
188 '(From Subject Date (optional . In-Reply-To) Message-ID Lines
189 (optional . User-Agent))
190 "*Headers to be generated or prompted for when mailing a message.
191 RFC822 required that From, Date, To, Subject and Message-ID be
192 included. Organization, Lines and User-Agent are optional."
194 :group 'message-headers
195 :type '(repeat sexp))
197 (defcustom message-deletable-headers '(Message-ID Date Lines)
198 "Headers to be deleted if they already exist and were generated by message previously."
199 :group 'message-headers
202 (defcustom message-ignored-news-headers
203 "^NNTP-Posting-Host:\\|^Xref:\\|^[BGF]cc:\\|^Resent-Fcc:"
204 "*Regexp of headers to be removed unconditionally before posting."
206 :group 'message-headers
209 (defcustom message-ignored-mail-headers "^[GF]cc:\\|^Resent-Fcc:\\|^Xref:"
210 "*Regexp of headers to be removed unconditionally before mailing."
212 :group 'message-headers
215 (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:"
216 "*Header lines matching this regexp will be deleted before posting.
217 It's best to delete old Path and Date headers before posting to avoid
219 :group 'message-interface
222 (defcustom message-subject-re-regexp "^[ \t]*\\([Rr][Ee]:[ \t]*\\)*[ \t]*"
223 "*Regexp matching \"Re: \" in the subject line."
224 :group 'message-various
228 (defcustom message-signature-separator "^-- *$"
229 "Regexp matching the signature separator."
231 :group 'message-various)
233 (defcustom message-elide-ellipsis "\n[...]\n\n"
234 "*The string which is inserted for elided text."
236 :group 'message-various)
238 (defcustom message-interactive nil
239 "Non-nil means when sending a message wait for and display errors.
240 nil means let mailer mail back a message to report errors."
241 :group 'message-sending
245 (defcustom message-generate-new-buffers 'unique
246 "*Non-nil means that a new message buffer will be created whenever `message-setup' is called.
247 If this is a function, call that function with three parameters: The type,
248 the to address and the group name. (Any of these may be nil.) The function
249 should return the new buffer name."
250 :group 'message-buffers
251 :type '(choice (const :tag "off" nil)
252 (const :tag "unique" unique)
253 (const :tag "unsent" unsent)
256 (defcustom message-kill-buffer-on-exit nil
257 "*Non-nil means that the message buffer will be killed after sending a message."
258 :group 'message-buffers
261 (defvar gnus-local-organization)
262 (defcustom message-user-organization
263 (or (and (boundp 'gnus-local-organization)
264 (stringp gnus-local-organization)
265 gnus-local-organization)
266 (getenv "ORGANIZATION")
268 "*String to be used as an Organization header.
269 If t, use `message-user-organization-file'."
270 :group 'message-headers
271 :type '(choice string
272 (const :tag "consult file" t)))
275 (defcustom message-user-organization-file "/usr/lib/news/organization"
276 "*Local news organization file."
278 :group 'message-headers)
280 (defcustom message-make-forward-subject-function
281 'message-forward-subject-author-subject
282 "*A list of functions that are called to generate a subject header for forwarded messages.
283 The subject generated by the previous function is passed into each
286 The provided functions are:
288 * message-forward-subject-author-subject (Source of article (author or
289 newsgroup)), in brackets followed by the subject
290 * message-forward-subject-fwd (Subject of article with 'Fwd:' prepended
292 :group 'message-forwarding
293 :type '(radio (function-item message-forward-subject-author-subject)
294 (function-item message-forward-subject-fwd)))
296 (defcustom message-forward-as-mime t
297 "*If non-nil, forward messages as an inline/rfc822 MIME section. Otherwise, directly inline the old message in the forwarded message."
298 :group 'message-forwarding
301 (defcustom message-forward-before-signature t
302 "*If non-nil, put forwarded message before signature, else after."
303 :group 'message-forwarding
306 (defcustom message-wash-forwarded-subjects nil
307 "*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."
308 :group 'message-forwarding
311 (defcustom message-ignored-resent-headers "^Return-receipt\\|^X-Gnus\\|^Gnus-Warning:"
312 "*All headers that match this regexp will be deleted when resending a message."
313 :group 'message-interface
316 (defcustom message-forward-ignored-headers "Content-Transfer-Encoding"
317 "*All headers that match this regexp will be deleted when forwarding a message."
318 :group 'message-forwarding
319 :type '(choice (const :tag "None" nil)
322 (defcustom message-ignored-cited-headers "."
323 "*Delete these headers from the messages you yank."
324 :group 'message-insertion
327 (defcustom message-cancel-message "I am canceling my own article.\n"
328 "Message to be inserted in the cancel message."
329 :group 'message-interface
332 ;; Useful to set in site-init.el
334 (defcustom message-send-mail-function 'message-send-mail-with-sendmail
335 "Function to call to send the current buffer as mail.
336 The headers should be delimited by a line whose contents match the
337 variable `mail-header-separator'.
339 Valid values include `message-send-mail-with-sendmail' (the default),
340 `message-send-mail-with-mh', `message-send-mail-with-qmail' and
342 :type '(radio (function-item message-send-mail-with-sendmail)
343 (function-item message-send-mail-with-mh)
344 (function-item message-send-mail-with-qmail)
345 (function-item smtpmail-send-it)
346 (function :tag "Other"))
347 :group 'message-sending
348 :group 'message-mail)
350 (defcustom message-send-news-function 'message-send-news
351 "Function to call to send the current buffer as news.
352 The headers should be delimited by a line whose contents match the
353 variable `mail-header-separator'."
354 :group 'message-sending
358 (defcustom message-reply-to-function nil
359 "Function that should return a list of headers.
360 This function should pick out addresses from the To, Cc, and From headers
361 and respond with new To and Cc headers."
362 :group 'message-interface
365 (defcustom message-wide-reply-to-function nil
366 "Function that should return a list of headers.
367 This function should pick out addresses from the To, Cc, and From headers
368 and respond with new To and Cc headers."
369 :group 'message-interface
372 (defcustom message-followup-to-function nil
373 "Function that should return a list of headers.
374 This function should pick out addresses from the To, Cc, and From headers
375 and respond with new To and Cc headers."
376 :group 'message-interface
379 (defcustom message-use-followup-to 'ask
380 "*Specifies what to do with Followup-To header.
381 If nil, always ignore the header. If it is t, use its value, but
382 query before using the \"poster\" value. If it is the symbol `ask',
383 always query the user whether to use the value. If it is the symbol
384 `use', always use the value."
385 :group 'message-interface
386 :type '(choice (const :tag "ignore" nil)
390 (defcustom message-sendmail-f-is-evil nil
391 "*Non-nil means that \"-f username\" should not be added to the sendmail command line.
392 Doing so would be even more evil than leaving it out."
393 :group 'message-sending
396 ;; qmail-related stuff
397 (defcustom message-qmail-inject-program "/var/qmail/bin/qmail-inject"
398 "Location of the qmail-inject program."
399 :group 'message-sending
402 (defcustom message-qmail-inject-args nil
403 "Arguments passed to qmail-inject programs.
404 This should be a list of strings, one string for each argument.
406 For e.g., if you wish to set the envelope sender address so that bounces
407 go to the right place or to deal with listserv's usage of that address, you
408 might set this variable to '(\"-f\" \"you@some.where\")."
409 :group 'message-sending
410 :type '(repeat string))
412 (defvar message-cater-to-broken-inn t
413 "Non-nil means Gnus should not fold the `References' header.
414 Folding `References' makes ancient versions of INN create incorrect
417 (defvar gnus-post-method)
418 (defvar gnus-select-method)
419 (defcustom message-post-method
420 (cond ((and (boundp 'gnus-post-method)
421 (listp gnus-post-method)
424 ((boundp 'gnus-select-method)
427 "*Method used to post news.
428 Note that when posting from inside Gnus, for instance, this
429 variable isn't used."
431 :group 'message-sending
432 ;; This should be the `gnus-select-method' widget, but that might
433 ;; create a dependence to `gnus.el'.
436 (defcustom message-generate-headers-first nil
437 "*If non-nil, generate all possible headers before composing."
438 :group 'message-headers
441 (defcustom message-setup-hook nil
442 "Normal hook, run each time a new outgoing message is initialized.
443 The function `message-setup' runs this hook."
444 :group 'message-various
447 (defcustom message-cancel-hook nil
448 "Hook run when cancelling articles."
449 :group 'message-various
452 (defcustom message-signature-setup-hook nil
453 "Normal hook, run each time a new outgoing message is initialized.
454 It is run after the headers have been inserted and before
455 the signature is inserted."
456 :group 'message-various
459 (defcustom message-mode-hook nil
460 "Hook run in message mode buffers."
461 :group 'message-various
464 (defcustom message-header-hook nil
465 "Hook run in a message mode buffer narrowed to the headers."
466 :group 'message-various
469 (defcustom message-header-setup-hook nil
470 "Hook called narrowed to the headers when setting up a message buffer."
471 :group 'message-various
475 (defcustom message-citation-line-function 'message-insert-citation-line
476 "*Function called to insert the \"Whomever writes:\" line."
478 :group 'message-insertion)
481 (defcustom message-yank-prefix "> "
482 "*Prefix inserted on the lines of yanked messages."
484 :group 'message-insertion)
486 (defcustom message-indentation-spaces 3
487 "*Number of spaces to insert at the beginning of each cited line.
488 Used by `message-yank-original' via `message-yank-cite'."
489 :group 'message-insertion
493 (defcustom message-cite-function 'message-cite-original
494 "*Function for citing an original message.
495 Predefined functions include `message-cite-original' and
496 `message-cite-original-without-signature'.
497 Note that `message-cite-original' uses `mail-citation-hook' if that is non-nil."
498 :type '(radio (function-item message-cite-original)
499 (function-item message-cite-original-without-signature)
500 (function-item sc-cite-original)
501 (function :tag "Other"))
502 :group 'message-insertion)
505 (defcustom message-indent-citation-function 'message-indent-citation
506 "*Function for modifying a citation just inserted in the mail buffer.
507 This can also be a list of functions. Each function can find the
508 citation between (point) and (mark t). And each function should leave
509 point and mark around the citation text as modified."
511 :group 'message-insertion)
513 (defvar message-abbrevs-loaded nil)
516 (defcustom message-signature t
517 "*String to be inserted at the end of the message buffer.
518 If t, the `message-signature-file' file will be inserted instead.
519 If a function, the result from the function will be used instead.
520 If a form, the result from the form will be used instead."
522 :group 'message-insertion)
525 (defcustom message-signature-file "~/.signature"
526 "*File containing the text inserted at end of message buffer."
528 :group 'message-insertion)
530 (defcustom message-distribution-function nil
531 "*Function called to return a Distribution header."
533 :group 'message-headers
536 (defcustom message-expires 14
537 "Number of days before your article expires."
539 :group 'message-headers
540 :link '(custom-manual "(message)News Headers")
543 (defcustom message-user-path nil
544 "If nil, use the NNTP server name in the Path header.
545 If stringp, use this; if non-nil, use no host name (user name only)."
547 :group 'message-headers
548 :link '(custom-manual "(message)News Headers")
549 :type '(choice (const :tag "nntp" nil)
551 (sexp :tag "none" :format "%t" t)))
553 (defvar message-reply-buffer nil)
554 (defvar message-reply-headers nil)
555 (defvar message-newsreader nil)
556 (defvar message-mailer nil)
557 (defvar message-sent-message-via nil)
558 (defvar message-checksum nil)
559 (defvar message-send-actions nil
560 "A list of actions to be performed upon successful sending of a message.")
561 (defvar message-exit-actions nil
562 "A list of actions to be performed upon exiting after sending a message.")
563 (defvar message-kill-actions nil
564 "A list of actions to be performed before killing a message buffer.")
565 (defvar message-postpone-actions nil
566 "A list of actions to be performed after postponing a message.")
568 (define-widget 'message-header-lines 'text
569 "All header lines must be LFD terminated."
572 :error "All header lines must be newline terminated")
574 (defcustom message-default-headers ""
575 "*A string containing header lines to be inserted in outgoing messages.
576 It is inserted before you edit the message, so you can edit or delete
578 :group 'message-headers
579 :type 'message-header-lines)
581 (defcustom message-default-mail-headers ""
582 "*A string of header lines to be inserted in outgoing mails."
583 :group 'message-headers
585 :type 'message-header-lines)
587 (defcustom message-default-news-headers ""
588 "*A string of header lines to be inserted in outgoing news articles."
589 :group 'message-headers
591 :type 'message-header-lines)
593 ;; Note: could use /usr/ucb/mail instead of sendmail;
594 ;; options -t, and -v if not interactive.
595 (defcustom message-mailer-swallows-blank-line
596 (if (and (string-match "sparc-sun-sunos\\(\\'\\|[^5]\\)"
597 system-configuration)
598 (file-readable-p "/etc/sendmail.cf")
599 (let ((buffer (get-buffer-create " *temp*")))
603 (insert-file-contents "/etc/sendmail.cf")
604 (goto-char (point-min))
605 (let ((case-fold-search nil))
606 (re-search-forward "^OR\\>" nil t)))
607 (kill-buffer buffer))))
608 ;; According to RFC822, "The field-name must be composed of printable
609 ;; ASCII characters (i. e., characters that have decimal values between
610 ;; 33 and 126, except colon)", i. e., any chars except ctl chars,
612 '(looking-at "[ \t]\\|[][!\"#$%&'()*+,-./0-9;<=>?@A-Z\\\\^_`a-z{|}~]+:"))
613 "*Set this non-nil if the system's mailer runs the header and body together.
614 \(This problem exists on Sunos 4 when sendmail is run in remote mode.)
615 The value should be an expression to test whether the problem will
617 :group 'message-sending
620 ;; Ignore errors in case this is used in Emacs 19.
621 ;; Don't use ignore-errors because this is copied into loaddefs.el.
624 (define-mail-user-agent 'message-user-agent
625 'message-mail 'message-send-and-exit
626 'message-kill-buffer 'message-send-hook))
628 (defvar message-mh-deletable-headers '(Message-ID Date Lines Sender)
629 "If non-nil, delete the deletable headers before feeding to mh.")
631 (defvar message-send-method-alist
632 '((news message-news-p message-send-via-news)
633 (mail message-mail-p message-send-via-mail))
634 "Alist of ways to send outgoing messages.
635 Each element has the form
637 \(TYPE PREDICATE FUNCTION)
639 where TYPE is a symbol that names the method; PREDICATE is a function
640 called without any parameters to determine whether the message is
641 a message of type TYPE; and FUNCTION is a function to be called if
642 PREDICATE returns non-nil. FUNCTION is called with one parameter --
645 (defvar message-mail-alias-type 'abbrev
646 "*What alias expansion type to use in Message buffers.
647 The default is `abbrev', which uses mailabbrev. nil switches
650 (defcustom message-auto-save-directory
651 (nnheader-concat message-directory "drafts/")
652 "*Directory where Message auto-saves buffers if Gnus isn't running.
653 If nil, Message won't auto-save."
654 :group 'message-buffers
657 (defcustom message-buffer-naming-style 'unique
658 "*The way new message buffers are named.
659 Valid valued are `unique' and `unsent'."
660 :group 'message-buffers
661 :type '(choice (const :tag "unique" unique)
662 (const :tag "unsent" unsent)))
664 (defcustom message-default-charset nil
665 "Default charset used in non-MULE XEmacsen."
669 (defcustom message-dont-reply-to-names rmail-dont-reply-to-names
670 "*A regexp specifying names to prune when doing wide replies.
671 A value of nil means exclude your own name only."
673 :type '(choice (const :tag "Yourself" nil)
676 ;;; Internal variables.
677 ;;; Well, not really internal.
679 (defvar message-mode-syntax-table
680 (let ((table (copy-syntax-table text-mode-syntax-table)))
681 (modify-syntax-entry ?% ". " table)
682 (modify-syntax-entry ?> ". " table)
683 (modify-syntax-entry ?< ". " table)
685 "Syntax table used while in Message mode.")
687 (defvar message-mode-abbrev-table text-mode-abbrev-table
688 "Abbrev table used in Message mode buffers.
689 Defaults to `text-mode-abbrev-table'.")
690 (defgroup message-headers nil
692 :link '(custom-manual "(message)Variables")
695 (defface message-header-to-face
698 (:foreground "green2" :bold t))
701 (:foreground "MidnightBlue" :bold t))
703 (:bold t :italic t)))
704 "Face used for displaying From headers."
705 :group 'message-faces)
707 (defface message-header-cc-face
710 (:foreground "green4" :bold t))
713 (:foreground "MidnightBlue"))
716 "Face used for displaying Cc headers."
717 :group 'message-faces)
719 (defface message-header-subject-face
722 (:foreground "green3"))
725 (:foreground "navy blue" :bold t))
728 "Face used for displaying subject headers."
729 :group 'message-faces)
731 (defface message-header-newsgroups-face
734 (:foreground "yellow" :bold t :italic t))
737 (:foreground "blue4" :bold t :italic t))
739 (:bold t :italic t)))
740 "Face used for displaying newsgroups headers."
741 :group 'message-faces)
743 (defface message-header-other-face
746 (:foreground "#b00000"))
749 (:foreground "steel blue"))
751 (:bold t :italic t)))
752 "Face used for displaying newsgroups headers."
753 :group 'message-faces)
755 (defface message-header-name-face
758 (:foreground "DarkGreen"))
761 (:foreground "cornflower blue"))
764 "Face used for displaying header names."
765 :group 'message-faces)
767 (defface message-header-xheader-face
770 (:foreground "blue"))
773 (:foreground "blue"))
776 "Face used for displaying X-Header headers."
777 :group 'message-faces)
779 (defface message-separator-face
782 (:foreground "blue3"))
785 (:foreground "brown"))
788 "Face used for displaying the separator."
789 :group 'message-faces)
791 (defface message-cited-text-face
800 "Face used for displaying cited text names."
801 :group 'message-faces)
803 (defface message-mml-face
806 (:foreground "ForestGreen"))
809 (:foreground "ForestGreen"))
812 "Face used for displaying MML."
813 :group 'message-faces)
815 (defvar message-font-lock-keywords
816 (let* ((cite-prefix "A-Za-z")
817 (cite-suffix (concat cite-prefix "0-9_.@-"))
818 (content "[ \t]*\\(.+\\(\n[ \t].*\\)*\\)"))
819 `((,(concat "^\\([Tt]o:\\)" content)
820 (1 'message-header-name-face)
821 (2 'message-header-to-face nil t))
822 (,(concat "^\\(^[GBF]?[Cc][Cc]:\\|^[Rr]eply-[Tt]o:\\)" content)
823 (1 'message-header-name-face)
824 (2 'message-header-cc-face nil t))
825 (,(concat "^\\([Ss]ubject:\\)" content)
826 (1 'message-header-name-face)
827 (2 'message-header-subject-face nil t))
828 (,(concat "^\\([Nn]ewsgroups:\\|Followup-[Tt]o:\\)" content)
829 (1 'message-header-name-face)
830 (2 'message-header-newsgroups-face nil t))
831 (,(concat "^\\([A-Z][^: \n\t]+:\\)" content)
832 (1 'message-header-name-face)
833 (2 'message-header-other-face nil t))
834 (,(concat "^\\(X-[A-Za-z0-9-]+\\|In-Reply-To\\):" content)
835 (1 'message-header-name-face)
836 (2 'message-header-name-face))
837 ,@(if (and mail-header-separator
838 (not (equal mail-header-separator "")))
839 `((,(concat "^\\(" (regexp-quote mail-header-separator) "\\)$")
840 1 'message-separator-face))
843 "\\([" cite-prefix "]+[" cite-suffix "]*\\)?"
845 (0 'message-cited-text-face))
846 ("<#/?\\(multipart\\|part\\|external\\).*>"
847 (0 'message-mml-face))))
848 "Additional expressions to highlight in Message mode.")
850 ;; XEmacs does it like this. For Emacs, we have to set the
851 ;; `font-lock-defaults' buffer-local variable.
852 (put 'message-mode 'font-lock-defaults '(message-font-lock-keywords t))
854 (defvar message-face-alist
855 '((bold . bold-region)
856 (underline . underline-region)
857 (default . (lambda (b e)
859 (ununderline-region b e))))
860 "Alist of mail and news faces for facemenu.
861 The cdr of ech entry is a function for applying the face to a region.")
863 (defcustom message-send-hook nil
864 "Hook run before sending messages."
865 :group 'message-various
866 :options '(ispell-message)
869 (defcustom message-send-mail-hook nil
870 "Hook run before sending mail messages."
871 :group 'message-various
874 (defcustom message-send-news-hook nil
875 "Hook run before sending news messages."
876 :group 'message-various
879 (defcustom message-sent-hook nil
880 "Hook run after sending messages."
881 :group 'message-various
884 (defvar message-send-coding-system 'binary
885 "Coding system to encode outgoing mail.")
887 (defvar message-draft-coding-system
888 mm-auto-save-coding-system
889 "Coding system to compose mail.")
891 ;;; Internal variables.
893 (defvar message-buffer-list nil)
894 (defvar message-this-is-news nil)
895 (defvar message-this-is-mail nil)
896 (defvar message-draft-article nil)
897 (defvar message-mime-part nil)
898 (defvar message-posting-charset nil)
900 ;; Byte-compiler warning
901 (defvar gnus-active-hashtb)
902 (defvar gnus-read-active-file)
904 ;;; Regexp matching the delimiter of messages in UNIX mail format
905 ;;; (UNIX From lines), minus the initial ^. It should be a copy
906 ;;; of rmail.el's rmail-unix-mail-delimiter.
907 (defvar message-unix-mail-delimiter
908 (let ((time-zone-regexp
909 (concat "\\([A-Z]?[A-Z]?[A-Z][A-Z]\\( DST\\)?"
910 "\\|[-+]?[0-9][0-9][0-9][0-9]"
916 ;; Many things can happen to an RFC 822 mailbox before it is put into
917 ;; a `From' line. The leading phrase can be stripped, e.g.
918 ;; `Joe <@w.x:joe@y.z>' -> `<@w.x:joe@y.z>'. The <> can be stripped, e.g.
919 ;; `<@x.y:joe@y.z>' -> `@x.y:joe@y.z'. Everything starting with a CRLF
920 ;; can be removed, e.g.
921 ;; From: joe@y.z (Joe K
923 ;; can yield `From joe@y.z (Joe K Fri Mar 22 08:11:15 1996', and
926 ;; can yield `From Joe User Fri Mar 22 08:11:15 1996'.
927 ;; The mailbox can be removed or be replaced by white space, e.g.
928 ;; From: "Joe User"{space}{tab}
930 ;; can yield `From {space}{tab} Fri Mar 22 08:11:15 1996',
931 ;; where {space} and {tab} represent the Ascii space and tab characters.
932 ;; We want to match the results of any of these manglings.
933 ;; The following regexp rejects names whose first characters are
934 ;; obviously bogus, but after that anything goes.
935 "\\([^\0-\b\n-\r\^?].*\\)? "
937 ;; The time the message was sent.
938 "\\([^\0-\r \^?]+\\) +" ; day of the week
939 "\\([^\0-\r \^?]+\\) +" ; month
940 "\\([0-3]?[0-9]\\) +" ; day of month
941 "\\([0-2][0-9]:[0-5][0-9]\\(:[0-6][0-9]\\)?\\) *" ; time of day
943 ;; Perhaps a time zone, specified by an abbreviation, or by a
948 " \\([0-9][0-9]+\\) *"
950 ;; On some systems the time zone can appear after the year, too.
954 "\\(remote from .*\\)?"
957 "Regexp matching the delimiter of messages in UNIX mail format.")
959 (defvar message-unsent-separator
960 (concat "^ *---+ +Unsent message follows +---+ *$\\|"
961 "^ *---+ +Returned message +---+ *$\\|"
962 "^Start of returned message$\\|"
963 "^ *---+ +Original message +---+ *$\\|"
964 "^ *--+ +begin message +--+ *$\\|"
965 "^ *---+ +Original message follows +---+ *$\\|"
966 "^ *---+ +Undelivered message follows +---+ *$\\|"
967 "^|? *---+ +Message text follows: +---+ *|?$")
968 "A regexp that matches the separator before the text of a failed message.")
970 (defvar message-header-format-alist
972 (To . message-fill-address)
973 (Cc . message-fill-address)
984 (References . message-shorten-references)
986 "Alist used for formatting headers.")
989 (autoload 'message-setup-toolbar "messagexmas")
990 (autoload 'mh-new-draft-name "mh-comp")
991 (autoload 'mh-send-letter "mh-comp")
992 (autoload 'gnus-point-at-eol "gnus-util")
993 (autoload 'gnus-point-at-bol "gnus-util")
994 (autoload 'gnus-output-to-mail "gnus-util")
995 (autoload 'mail-abbrev-in-expansion-header-p "mailabbrev")
996 (autoload 'nndraft-request-associate-buffer "nndraft")
997 (autoload 'nndraft-request-expire-articles "nndraft")
998 (autoload 'gnus-open-server "gnus-int")
999 (autoload 'gnus-request-post "gnus-int")
1000 (autoload 'gnus-alive-p "gnus-util")
1001 (autoload 'rmail-output "rmail"))
1006 ;;; Utility functions.
1009 (defmacro message-y-or-n-p (question show &rest text)
1010 "Ask QUESTION, displaying the rest of the arguments in a temp. buffer if SHOW"
1011 `(message-talkative-question 'y-or-n-p ,question ,show ,@text))
1013 ;; Delete the current line (and the next N lines.);
1014 (defmacro message-delete-line (&optional n)
1015 `(delete-region (progn (beginning-of-line) (point))
1016 (progn (forward-line ,(or n 1)) (point))))
1018 (defun message-tokenize-header (header &optional separator)
1019 "Split HEADER into a list of header elements.
1020 \",\" is used as the separator."
1023 (let ((regexp (format "[%s]+" (or separator ",")))
1028 (message-set-work-buffer)
1030 (goto-char (point-min))
1035 (cond ((and (> (point) beg)
1037 (and (looking-at regexp)
1040 (push (buffer-substring beg (point)) elems)
1041 (setq beg (match-end 0)))
1042 ((eq (char-after) ?\")
1043 (setq quoted (not quoted)))
1044 ((and (eq (char-after) ?\()
1047 ((and (eq (char-after) ?\))
1050 (nreverse elems)))))
1052 (defun message-mail-file-mbox-p (file)
1053 "Say whether FILE looks like a Unix mbox file."
1054 (when (and (file-exists-p file)
1055 (file-readable-p file)
1056 (file-regular-p file))
1058 (nnheader-insert-file-contents file)
1059 (goto-char (point-min))
1060 (looking-at message-unix-mail-delimiter))))
1062 (defun message-fetch-field (header &optional not-all)
1063 "The same as `mail-fetch-field', only remove all newlines."
1064 (let* ((inhibit-point-motion-hooks t)
1065 (case-fold-search t)
1066 (value (mail-fetch-field header nil (not not-all))))
1068 (while (string-match "\n[\t ]+" value)
1069 (setq value (replace-match " " t t value)))
1070 ;; We remove all text props.
1071 (format "%s" value))))
1073 (defun message-narrow-to-field ()
1074 "Narrow the buffer to the header on the current line."
1080 (if (re-search-forward "^[^ \n\t]" nil t)
1085 (goto-char (point-min)))
1087 (defun message-add-header (&rest headers)
1088 "Add the HEADERS to the message header, skipping those already present."
1091 (unless (string-match "^\\([^:]+\\):[ \t]*[^ \t]" (car headers))
1092 (error "Invalid header `%s'" (car headers)))
1093 (setq hclean (match-string 1 (car headers)))
1095 (message-narrow-to-headers)
1096 (unless (re-search-forward (concat "^" (regexp-quote hclean) ":") nil t)
1097 (insert (car headers) ?\n))))
1098 (setq headers (cdr headers))))
1101 (defun message-fetch-reply-field (header)
1102 "Fetch FIELD from the message we're replying to."
1103 (when (and message-reply-buffer
1104 (buffer-name message-reply-buffer))
1106 (set-buffer message-reply-buffer)
1107 (message-fetch-field header))))
1109 (defun message-set-work-buffer ()
1110 (if (get-buffer " *message work*")
1112 (set-buffer " *message work*")
1114 (set-buffer (get-buffer-create " *message work*"))
1115 (kill-all-local-variables)
1116 (mm-enable-multibyte)))
1118 (defun message-functionp (form)
1119 "Return non-nil if FORM is funcallable."
1120 (or (and (symbolp form) (fboundp form))
1121 (and (listp form) (eq (car form) 'lambda))
1122 (byte-code-function-p form)))
1124 (defun message-strip-subject-re (subject)
1125 "Remove \"Re:\" from subject lines."
1126 (if (string-match message-subject-re-regexp subject)
1127 (substring subject (match-end 0))
1130 (defun message-remove-header (header &optional is-regexp first reverse)
1131 "Remove HEADER in the narrowed buffer.
1132 If REGEXP, HEADER is a regular expression.
1133 If FIRST, only remove the first instance of the header.
1134 Return the number of headers removed."
1135 (goto-char (point-min))
1136 (let ((regexp (if is-regexp header (concat "^" (regexp-quote header) ":")))
1138 (case-fold-search t)
1140 (while (and (not (eobp))
1143 (not (looking-at regexp))
1144 (looking-at regexp))
1151 ;; There might be a continuation header, so we have to search
1152 ;; until we find a new non-continuation line.
1155 (if (re-search-forward "^[^ \t]" nil t)
1156 (goto-char (match-beginning 0))
1159 (if (re-search-forward "^[^ \t]" nil t)
1160 (goto-char (match-beginning 0))
1161 (goto-char (point-max)))))
1164 (defun message-remove-first-header (header)
1165 "Remove the first instance of HEADER if there is more than one."
1167 (regexp (concat "^" (regexp-quote header) ":")))
1169 (goto-char (point-min))
1170 (while (re-search-forward regexp nil t)
1173 (message-remove-header header nil t)
1176 (defun message-narrow-to-headers ()
1177 "Narrow the buffer to the head of the message."
1180 (goto-char (point-min))
1181 (if (re-search-forward
1182 (concat "^" (regexp-quote mail-header-separator) "\n") nil t)
1185 (goto-char (point-min)))
1187 (defun message-narrow-to-head ()
1188 "Narrow the buffer to the head of the message.
1189 Point is left at the beginning of the narrowed-to region."
1192 (goto-char (point-min))
1193 (if (search-forward "\n\n" nil 1)
1196 (goto-char (point-min)))
1198 (defun message-narrow-to-headers-or-head ()
1199 "Narrow the buffer to the head of the message."
1202 (goto-char (point-min))
1205 (concat "^" (regexp-quote mail-header-separator) "\n") nil t)
1206 (match-beginning 0))
1207 ((search-forward "\n\n" nil t)
1211 (goto-char (point-min)))
1213 (defun message-news-p ()
1214 "Say whether the current buffer contains a news message."
1215 (and (not message-this-is-mail)
1216 (or message-this-is-news
1219 (message-narrow-to-headers)
1220 (and (message-fetch-field "newsgroups")
1221 (not (message-fetch-field "posted-to"))))))))
1223 (defun message-mail-p ()
1224 "Say whether the current buffer contains a mail message."
1225 (and (not message-this-is-news)
1226 (or message-this-is-mail
1229 (message-narrow-to-headers)
1230 (or (message-fetch-field "to")
1231 (message-fetch-field "cc")
1232 (message-fetch-field "bcc")))))))
1234 (defun message-next-header ()
1235 "Go to the beginning of the next header."
1237 (or (eobp) (forward-char 1))
1238 (not (if (re-search-forward "^[^ \t]" nil t)
1240 (goto-char (point-max)))))
1242 (defun message-sort-headers-1 ()
1243 "Sort the buffer as headers using `message-rank' text props."
1244 (goto-char (point-min))
1247 nil 'message-next-header
1249 (message-next-header)
1253 (or (get-text-property (point) 'message-rank)
1256 (defun message-sort-headers ()
1257 "Sort the headers of the current message according to `message-header-format-alist'."
1261 (let ((max (1+ (length message-header-format-alist)))
1263 (message-narrow-to-headers)
1264 (while (re-search-forward "^[^ \n]+:" nil t)
1266 (match-beginning 0) (1+ (match-beginning 0))
1268 (if (setq rank (length (memq (assq (intern (buffer-substring
1270 (1- (match-end 0))))
1271 message-header-format-alist)
1272 message-header-format-alist)))
1275 (message-sort-headers-1))))
1285 (defvar message-mode-map nil)
1287 (unless message-mode-map
1288 (setq message-mode-map (make-keymap))
1289 (set-keymap-parent message-mode-map text-mode-map)
1290 (define-key message-mode-map "\C-c?" 'describe-mode)
1292 (define-key message-mode-map "\C-c\C-f\C-t" 'message-goto-to)
1293 (define-key message-mode-map "\C-c\C-f\C-b" 'message-goto-bcc)
1294 (define-key message-mode-map "\C-c\C-f\C-w" 'message-goto-fcc)
1295 (define-key message-mode-map "\C-c\C-f\C-c" 'message-goto-cc)
1296 (define-key message-mode-map "\C-c\C-f\C-s" 'message-goto-subject)
1297 (define-key message-mode-map "\C-c\C-f\C-r" 'message-goto-reply-to)
1298 (define-key message-mode-map "\C-c\C-f\C-n" 'message-goto-newsgroups)
1299 (define-key message-mode-map "\C-c\C-f\C-d" 'message-goto-distribution)
1300 (define-key message-mode-map "\C-c\C-f\C-f" 'message-goto-followup-to)
1301 (define-key message-mode-map "\C-c\C-f\C-k" 'message-goto-keywords)
1302 (define-key message-mode-map "\C-c\C-f\C-u" 'message-goto-summary)
1303 (define-key message-mode-map "\C-c\C-b" 'message-goto-body)
1304 (define-key message-mode-map "\C-c\C-i" 'message-goto-signature)
1306 (define-key message-mode-map "\C-c\C-t" 'message-insert-to)
1307 (define-key message-mode-map "\C-c\C-n" 'message-insert-newsgroups)
1309 (define-key message-mode-map "\C-c\C-y" 'message-yank-original)
1310 (define-key message-mode-map "\C-c\M-\C-y" 'message-yank-buffer)
1311 (define-key message-mode-map "\C-c\C-q" 'message-fill-yanked-message)
1312 (define-key message-mode-map "\C-c\C-w" 'message-insert-signature)
1313 (define-key message-mode-map "\C-c\M-h" 'message-insert-headers)
1314 (define-key message-mode-map "\C-c\C-r" 'message-caesar-buffer-body)
1315 (define-key message-mode-map "\C-c\C-o" 'message-sort-headers)
1316 (define-key message-mode-map "\C-c\M-r" 'message-rename-buffer)
1318 (define-key message-mode-map "\C-c\C-c" 'message-send-and-exit)
1319 (define-key message-mode-map "\C-c\C-s" 'message-send)
1320 (define-key message-mode-map "\C-c\C-k" 'message-kill-buffer)
1321 (define-key message-mode-map "\C-c\C-d" 'message-dont-send)
1323 (define-key message-mode-map "\C-c\C-e" 'message-elide-region)
1324 (define-key message-mode-map "\C-c\C-v" 'message-delete-not-region)
1325 (define-key message-mode-map "\C-c\C-z" 'message-kill-to-signature)
1326 (define-key message-mode-map "\M-\r" 'message-newline-and-reformat)
1328 (define-key message-mode-map "\C-c\C-a" 'mml-attach-file)
1330 (define-key message-mode-map "\t" 'message-tab))
1333 message-mode-menu message-mode-map "Message Menu."
1335 ["Sort Headers" message-sort-headers t]
1336 ["Yank Original" message-yank-original t]
1337 ["Fill Yanked Message" message-fill-yanked-message t]
1338 ["Insert Signature" message-insert-signature t]
1339 ["Caesar (rot13) Message" message-caesar-buffer-body t]
1340 ["Caesar (rot13) Region" message-caesar-region (mark t)]
1341 ["Elide Region" message-elide-region (mark t)]
1342 ["Delete Outside Region" message-delete-not-region (mark t)]
1343 ["Kill To Signature" message-kill-to-signature t]
1344 ["Newline and Reformat" message-newline-and-reformat t]
1345 ["Rename buffer" message-rename-buffer t]
1346 ["Spellcheck" ispell-message t]
1347 ["Attach file as MIME" mml-attach-file t]
1349 ["Send Message" message-send-and-exit t]
1350 ["Abort Message" message-dont-send t]
1351 ["Kill Message" message-kill-buffer t]))
1354 message-mode-field-menu message-mode-map ""
1356 ["Fetch To" message-insert-to t]
1357 ["Fetch Newsgroups" message-insert-newsgroups t]
1359 ["To" message-goto-to t]
1360 ["Subject" message-goto-subject t]
1361 ["Cc" message-goto-cc t]
1362 ["Reply-To" message-goto-reply-to t]
1363 ["Summary" message-goto-summary t]
1364 ["Keywords" message-goto-keywords t]
1365 ["Newsgroups" message-goto-newsgroups t]
1366 ["Followup-To" message-goto-followup-to t]
1367 ["Distribution" message-goto-distribution t]
1368 ["Body" message-goto-body t]
1369 ["Signature" message-goto-signature t]))
1371 (defvar facemenu-add-face-function)
1372 (defvar facemenu-remove-face-function)
1375 (defun message-mode ()
1376 "Major mode for editing mail and news to be sent.
1377 Like Text Mode but with these additional commands:
1378 C-c C-s message-send (send the message) C-c C-c message-send-and-exit
1379 C-c C-d Pospone sending the message C-c C-k Kill the message
1380 C-c C-f move to a header field (and create it if there isn't):
1381 C-c C-f C-t move to To C-c C-f C-s move to Subject
1382 C-c C-f C-c move to Cc C-c C-f C-b move to Bcc
1383 C-c C-f C-w move to Fcc C-c C-f C-r move to Reply-To
1384 C-c C-f C-u move to Summary C-c C-f C-n move to Newsgroups
1385 C-c C-f C-k move to Keywords C-c C-f C-d move to Distribution
1386 C-c C-f C-f move to Followup-To
1387 C-c C-t message-insert-to (add a To header to a news followup)
1388 C-c C-n message-insert-newsgroups (add a Newsgroup header to a news reply)
1389 C-c C-b message-goto-body (move to beginning of message text).
1390 C-c C-i message-goto-signature (move to the beginning of the signature).
1391 C-c C-w message-insert-signature (insert `message-signature-file' file).
1392 C-c C-y message-yank-original (insert current message, if any).
1393 C-c C-q message-fill-yanked-message (fill what was yanked).
1394 C-c C-e message-elide-region (elide the text between point and mark).
1395 C-c C-v message-delete-not-region (remove the text outside the region).
1396 C-c C-z message-kill-to-signature (kill the text up to the signature).
1397 C-c C-r message-caesar-buffer-body (rot13 the message body).
1398 C-c C-a mml-attach-file (attach a file as MIME).
1399 M-RET message-newline-and-reformat (break the line and reformat)."
1401 (kill-all-local-variables)
1402 (set (make-local-variable 'message-reply-buffer) nil)
1403 (make-local-variable 'message-send-actions)
1404 (make-local-variable 'message-exit-actions)
1405 (make-local-variable 'message-kill-actions)
1406 (make-local-variable 'message-postpone-actions)
1407 (make-local-variable 'message-draft-article)
1408 (make-local-hook 'kill-buffer-hook)
1409 (set-syntax-table message-mode-syntax-table)
1410 (use-local-map message-mode-map)
1411 (setq local-abbrev-table message-mode-abbrev-table)
1412 (setq major-mode 'message-mode)
1413 (setq mode-name "Message")
1414 (setq buffer-offer-save t)
1415 (make-local-variable 'facemenu-add-face-function)
1416 (make-local-variable 'facemenu-remove-face-function)
1417 (setq facemenu-add-face-function
1419 (let ((face-fun (cdr (assq face message-face-alist))))
1421 (funcall face-fun (point) end)
1422 (error "Face %s not configured for %s mode" face mode-name)))
1424 facemenu-remove-face-function t)
1425 (make-local-variable 'paragraph-separate)
1426 (make-local-variable 'paragraph-start)
1427 ;; `-- ' precedes the signature. `-----' appears at the start of the
1428 ;; lines that delimit forwarded messages.
1429 ;; Lines containing just >= 3 dashes, perhaps after whitespace,
1430 ;; are also sometimes used and should be separators.
1431 (setq paragraph-start
1432 (concat (regexp-quote mail-header-separator)
1433 "$\\|[ \t]*[a-z0-9A-Z]*>+[ \t]*$\\|[ \t]*$\\|"
1436 ;;!!! Uhm... shurely this can't be right?
1437 "[> " (regexp-quote message-yank-prefix) "]+$"))
1438 (setq paragraph-separate paragraph-start)
1439 (make-local-variable 'message-reply-headers)
1440 (setq message-reply-headers nil)
1441 (make-local-variable 'message-newsreader)
1442 (make-local-variable 'message-mailer)
1443 (make-local-variable 'message-post-method)
1444 (set (make-local-variable 'message-sent-message-via) nil)
1445 (set (make-local-variable 'message-checksum) nil)
1446 (set (make-local-variable 'message-mime-part) 0)
1447 ;;(when (fboundp 'mail-hist-define-keys)
1448 ;; (mail-hist-define-keys))
1449 (when (string-match "XEmacs\\|Lucid" emacs-version)
1450 (message-setup-toolbar))
1451 (easy-menu-add message-mode-menu message-mode-map)
1452 (easy-menu-add message-mode-field-menu message-mode-map)
1453 ;; Allow mail alias things.
1454 (when (eq message-mail-alias-type 'abbrev)
1455 (if (fboundp 'mail-abbrevs-setup)
1456 (mail-abbrevs-setup)
1457 (mail-aliases-setup)))
1458 (message-set-auto-save-file-name)
1459 (unless (string-match "XEmacs" emacs-version)
1460 (set (make-local-variable 'font-lock-defaults)
1461 '(message-font-lock-keywords t)))
1462 (make-local-variable 'adaptive-fill-regexp)
1463 (setq adaptive-fill-regexp
1464 (concat "[ \t]*[-a-z0-9A-Z]*\\(>[ \t]*\\)+[ \t]*\\|" adaptive-fill-regexp))
1465 (unless (boundp 'adaptive-fill-first-line-regexp)
1466 (setq adaptive-fill-first-line-regexp nil))
1467 (make-local-variable 'adaptive-fill-first-line-regexp)
1468 (setq adaptive-fill-first-line-regexp
1469 (concat "[ \t]*[-a-z0-9A-Z]*\\(>[ \t]*\\)+[ \t]*\\|"
1470 adaptive-fill-first-line-regexp))
1471 (make-local-variable 'auto-fill-inhibit-regexp)
1472 (setq auto-fill-inhibit-regexp "^[A-Z][^: \n\t]+:")
1473 (mm-enable-multibyte)
1474 (make-local-variable 'indent-tabs-mode) ;Turn off tabs for indentation.
1475 (setq indent-tabs-mode nil)
1477 (run-hooks 'text-mode-hook 'message-mode-hook))
1482 ;;; Message mode commands
1485 ;;; Movement commands
1487 (defun message-goto-to ()
1488 "Move point to the To header."
1490 (message-position-on-field "To"))
1492 (defun message-goto-subject ()
1493 "Move point to the Subject header."
1495 (message-position-on-field "Subject"))
1497 (defun message-goto-cc ()
1498 "Move point to the Cc header."
1500 (message-position-on-field "Cc" "To"))
1502 (defun message-goto-bcc ()
1503 "Move point to the Bcc header."
1505 (message-position-on-field "Bcc" "Cc" "To"))
1507 (defun message-goto-fcc ()
1508 "Move point to the Fcc header."
1510 (message-position-on-field "Fcc" "To" "Newsgroups"))
1512 (defun message-goto-reply-to ()
1513 "Move point to the Reply-To header."
1515 (message-position-on-field "Reply-To" "Subject"))
1517 (defun message-goto-newsgroups ()
1518 "Move point to the Newsgroups header."
1520 (message-position-on-field "Newsgroups"))
1522 (defun message-goto-distribution ()
1523 "Move point to the Distribution header."
1525 (message-position-on-field "Distribution"))
1527 (defun message-goto-followup-to ()
1528 "Move point to the Followup-To header."
1530 (message-position-on-field "Followup-To" "Newsgroups"))
1532 (defun message-goto-keywords ()
1533 "Move point to the Keywords header."
1535 (message-position-on-field "Keywords" "Subject"))
1537 (defun message-goto-summary ()
1538 "Move point to the Summary header."
1540 (message-position-on-field "Summary" "Subject"))
1542 (defun message-goto-body ()
1543 "Move point to the beginning of the message body."
1545 (if (looking-at "[ \t]*\n") (expand-abbrev))
1546 (goto-char (point-min))
1547 (or (search-forward (concat "\n" mail-header-separator "\n") nil t)
1548 (search-forward "\n\n" nil t)))
1550 (defun message-goto-eoh ()
1551 "Move point to the end of the headers."
1556 (defun message-goto-signature ()
1557 "Move point to the beginning of the message signature.
1558 If there is no signature in the article, go to the end and
1561 (goto-char (point-min))
1562 (if (re-search-forward message-signature-separator nil t)
1564 (goto-char (point-max))
1569 (defun message-insert-to (&optional force)
1570 "Insert a To header that points to the author of the article being replied to.
1571 If the original author requested not to be sent mail, the function signals
1573 With the prefix argument FORCE, insert the header anyway."
1575 (let ((co (message-fetch-reply-field "mail-copies-to")))
1576 (when (and (null force)
1578 (or (equal (downcase co) "never")
1579 (equal (downcase co) "nobody")))
1580 (error "The user has requested not to have copies sent via mail")))
1581 (when (and (message-position-on-field "To")
1582 (mail-fetch-field "to")
1583 (not (string-match "\\` *\\'" (mail-fetch-field "to"))))
1585 (insert (or (message-fetch-reply-field "reply-to")
1586 (message-fetch-reply-field "from") "")))
1588 (defun message-insert-newsgroups ()
1589 "Insert the Newsgroups header from the article being replied to."
1591 (when (and (message-position-on-field "Newsgroups")
1592 (mail-fetch-field "newsgroups")
1593 (not (string-match "\\` *\\'" (mail-fetch-field "newsgroups"))))
1595 (insert (or (message-fetch-reply-field "newsgroups") "")))
1599 ;;; Various commands
1601 (defun message-delete-not-region (beg end)
1602 "Delete everything in the body of the current message that is outside of the region."
1606 (delete-region (point) (if (not (message-goto-signature))
1612 (delete-region beg (progn (message-goto-body)
1615 (when (message-goto-signature)
1618 (defun message-kill-to-signature ()
1619 "Deletes all text up to the signature."
1621 (let ((point (point)))
1622 (message-goto-signature)
1625 (kill-region point (point))
1629 (defun message-newline-and-reformat ()
1630 "Insert four newlines, and then reformat if inside quoted text."
1632 (let ((prefix "[]>»|:}+ \t]*")
1633 (supercite-thing "[-._a-zA-Z0-9]*[>]+[ \t]*")
1638 (when (looking-at (concat prefix
1640 (setq quoted (match-string 0))))
1642 (setq point (point))
1644 (delete-region (point) (re-search-forward "[ \t]*"))
1647 (fill-paragraph nil)
1651 (defun message-insert-signature (&optional force)
1652 "Insert a signature. See documentation for the `message-signature' variable."
1653 (interactive (list 0))
1656 ((and (null message-signature)
1659 (goto-char (point-max))
1660 (not (re-search-backward message-signature-separator nil t))))
1661 ((and (null message-signature)
1664 ((message-functionp message-signature)
1665 (funcall message-signature))
1666 ((listp message-signature)
1667 (eval message-signature))
1668 (t message-signature)))
1670 (cond ((stringp signature)
1672 ((and (eq t signature)
1673 message-signature-file
1674 (file-exists-p message-signature-file))
1677 (goto-char (point-max))
1678 ;; Insert the signature.
1682 (if (eq signature t)
1683 (insert-file-contents message-signature-file)
1685 (goto-char (point-max))
1686 (or (bolp) (insert "\n")))))
1688 (defun message-elide-region (b e)
1689 "Elide the text between point and mark.
1690 An ellipsis (from `message-elide-ellipsis') will be inserted where the
1694 (insert message-elide-ellipsis))
1696 (defvar message-caesar-translation-table nil)
1698 (defun message-caesar-region (b e &optional n)
1699 "Caesar rotation of region by N, default 13, for decrypting netnews."
1702 (min (point) (or (mark t) (point)))
1703 (max (point) (or (mark t) (point)))
1704 (when current-prefix-arg
1705 (prefix-numeric-value current-prefix-arg))))
1707 (setq n (if (numberp n) (mod n 26) 13)) ;canonize N
1708 (unless (or (zerop n) ; no action needed for a rot of 0
1709 (= b e)) ; no region to rotate
1710 ;; We build the table, if necessary.
1711 (when (or (not message-caesar-translation-table)
1712 (/= (aref message-caesar-translation-table ?a) (+ ?a n)))
1713 (setq message-caesar-translation-table
1714 (message-make-caesar-translation-table n)))
1715 (translate-region b e message-caesar-translation-table)))
1717 (defun message-make-caesar-translation-table (n)
1718 "Create a rot table with offset N."
1720 (table (make-string 256 0)))
1721 (while (< (incf i) 256)
1724 (substring table 0 ?A)
1725 (substring table (+ ?A n) (+ ?A n (- 26 n)))
1726 (substring table ?A (+ ?A n))
1727 (substring table (+ ?A 26) ?a)
1728 (substring table (+ ?a n) (+ ?a n (- 26 n)))
1729 (substring table ?a (+ ?a n))
1730 (substring table (+ ?a 26) 255))))
1732 (defun message-caesar-buffer-body (&optional rotnum)
1733 "Caesar rotates all letters in the current buffer by 13 places.
1734 Used to encode/decode possiblyun offensive messages (commonly in net.jokes).
1735 With prefix arg, specifies the number of places to rotate each letter forward.
1736 Mail and USENET news headers are not rotated."
1737 (interactive (if current-prefix-arg
1738 (list (prefix-numeric-value current-prefix-arg))
1742 (when (message-goto-body)
1743 (narrow-to-region (point) (point-max)))
1744 (message-caesar-region (point-min) (point-max) rotnum))))
1746 (defun message-pipe-buffer-body (program)
1747 "Pipe the message body in the current buffer through PROGRAM."
1750 (when (message-goto-body)
1751 (narrow-to-region (point) (point-max)))
1752 (shell-command-on-region
1753 (point-min) (point-max) program nil t))))
1755 (defun message-rename-buffer (&optional enter-string)
1756 "Rename the *message* buffer to \"*message* RECIPIENT\".
1757 If the function is run with a prefix, it will ask for a new buffer
1758 name, rather than giving an automatic name."
1759 (interactive "Pbuffer name: ")
1762 (goto-char (point-min))
1763 (narrow-to-region (point)
1764 (search-forward mail-header-separator nil 'end))
1766 (if (message-news-p) (message-fetch-field "Newsgroups")
1767 (message-fetch-field "To"))
1770 (if (string-match "," mail-to)
1771 (concat (substring mail-to 0 (match-beginning 0)) ", ...")
1773 (name-default (concat "*message* " mail-trimmed-to))
1774 (name (if enter-string
1775 (read-string "New buffer name: " name-default)
1777 (rename-buffer name t)))))
1779 (defun message-fill-yanked-message (&optional justifyp)
1780 "Fill the paragraphs of a message yanked into this one.
1781 Numeric argument means justify as well."
1784 (goto-char (point-min))
1785 (search-forward (concat "\n" mail-header-separator "\n") nil t)
1786 (let ((fill-prefix message-yank-prefix))
1787 (fill-individual-paragraphs (point) (point-max) justifyp))))
1789 (defun message-indent-citation ()
1790 "Modify text just inserted from a message to be cited.
1791 The inserted text should be the region.
1792 When this function returns, the region is again around the modified text.
1794 Normally, indent each nonblank line `message-indentation-spaces' spaces.
1795 However, if `message-yank-prefix' is non-nil, insert that prefix on each line."
1796 (let ((start (point)))
1797 ;; Remove unwanted headers.
1798 (when message-ignored-cited-headers
1803 (if (search-forward "\n\n" nil t)
1806 (message-remove-header message-ignored-cited-headers t)
1807 (when (= (point-min) (point-max))
1808 (setq all-removed t))
1809 (goto-char (point-max)))
1813 ;; Delete blank lines at the start of the buffer.
1814 (while (and (point-min)
1817 (message-delete-line))
1818 ;; Delete blank lines at the end of the buffer.
1819 (goto-char (point-max))
1822 (while (and (zerop (forward-line -1))
1824 (message-delete-line))
1825 ;; Do the indentation.
1826 (if (null message-yank-prefix)
1827 (indent-rigidly start (mark t) message-indentation-spaces)
1830 (while (< (point) (mark t))
1831 (insert message-yank-prefix)
1835 (defun message-yank-original (&optional arg)
1836 "Insert the message being replied to, if any.
1837 Puts point before the text and mark after.
1838 Normally indents each nonblank line ARG spaces (default 3). However,
1839 if `message-yank-prefix' is non-nil, insert that prefix on each line.
1841 This function uses `message-cite-function' to do the actual citing.
1843 Just \\[universal-argument] as argument means don't indent, insert no
1844 prefix, and don't delete any headers."
1846 (let ((modified (buffer-modified-p)))
1847 (when (and message-reply-buffer
1848 message-cite-function)
1849 (delete-windows-on message-reply-buffer t)
1850 (insert-buffer message-reply-buffer)
1851 (funcall message-cite-function)
1852 (message-exchange-point-and-mark)
1856 (setq message-checksum (message-checksum))))))
1858 (defun message-yank-buffer (buffer)
1859 "Insert BUFFER into the current buffer and quote it."
1860 (interactive "bYank buffer: ")
1861 (let ((message-reply-buffer buffer))
1862 (save-window-excursion
1863 (message-yank-original))))
1865 (defun message-buffers ()
1866 "Return a list of active message buffers."
1869 (dolist (buffer (buffer-list t))
1871 (when (and (eq major-mode 'message-mode)
1872 (null message-sent-message-via))
1873 (push (buffer-name buffer) buffers))))
1874 (nreverse buffers)))
1876 (defun message-cite-original-without-signature ()
1877 "Cite function in the standard Message manner."
1878 (let ((start (point))
1881 (when message-indent-citation-function
1882 (if (listp message-indent-citation-function)
1883 message-indent-citation-function
1884 (list message-indent-citation-function)))))
1885 (mml-quote-region start end)
1889 (when (re-search-backward message-signature-separator start t)
1890 ;; Also peel off any blank lines before the signature.
1892 (while (looking-at "^[ \t]*$")
1895 (delete-region (point) end))
1898 (funcall (pop functions)))
1899 (when message-citation-line-function
1902 (funcall message-citation-line-function))))
1904 (defvar mail-citation-hook) ;Compiler directive
1905 (defun message-cite-original ()
1906 "Cite function in the standard Message manner."
1907 (if (and (boundp 'mail-citation-hook)
1909 (run-hooks 'mail-citation-hook)
1910 (let ((start (point))
1913 (when message-indent-citation-function
1914 (if (listp message-indent-citation-function)
1915 message-indent-citation-function
1916 (list message-indent-citation-function)))))
1917 (mml-quote-region start end)
1920 (funcall (pop functions)))
1921 (when message-citation-line-function
1924 (funcall message-citation-line-function)))))
1926 (defun message-insert-citation-line ()
1927 "Function that inserts a simple citation line."
1928 (when message-reply-headers
1929 (insert (mail-header-from message-reply-headers) " writes:\n\n")))
1931 (defun message-position-on-field (header &rest afters)
1932 (let ((case-fold-search t))
1935 (goto-char (point-min))
1938 (concat "^" (regexp-quote mail-header-separator) "$"))
1939 (match-beginning 0)))
1940 (goto-char (point-min))
1941 (if (re-search-forward (concat "^" (regexp-quote header) ":") nil t)
1943 (re-search-forward "^[^ \t]" nil 'move)
1945 (skip-chars-backward "\n")
1948 (not (re-search-forward
1949 (concat "^" (regexp-quote (car afters)) ":")
1953 (re-search-forward "^[^ \t]" nil 'move)
1954 (beginning-of-line))
1955 (insert header ": \n")
1959 (defun message-remove-signature ()
1960 "Remove the signature from the text between point and mark.
1961 The text will also be indented the normal way."
1963 (let ((start (point))
1965 (if (not (re-search-forward message-signature-separator (mark t) t))
1966 ;; No signature here, so we just indent the cited text.
1967 (message-indent-citation)
1968 ;; Find the last non-empty line.
1970 (while (looking-at "[ \t]*$")
1973 (setq mark (set-marker (make-marker) (point)))
1975 (message-indent-citation)
1976 ;; Enable undoing the deletion.
1978 (delete-region mark (mark t))
1979 (set-marker mark nil)))))
1984 ;;; Sending messages
1987 (defun message-send-and-exit (&optional arg)
1988 "Send message like `message-send', then, if no errors, exit from mail buffer."
1990 (let ((buf (current-buffer))
1991 (actions message-exit-actions))
1992 (when (and (message-send arg)
1994 (if message-kill-buffer-on-exit
1997 (when (eq buf (current-buffer))
1998 (message-bury buf)))
1999 (message-do-actions actions)
2002 (defun message-dont-send ()
2003 "Don't send the message you have been editing."
2005 (set-buffer-modified-p t)
2007 (let ((actions message-postpone-actions))
2008 (message-bury (current-buffer))
2009 (message-do-actions actions)))
2011 (defun message-kill-buffer ()
2012 "Kill the current buffer."
2014 (when (or (not (buffer-modified-p))
2015 (yes-or-no-p "Message modified; kill anyway? "))
2016 (let ((actions message-kill-actions))
2017 (setq buffer-file-name nil)
2018 (kill-buffer (current-buffer))
2019 (message-do-actions actions))))
2021 (defun message-bury (buffer)
2022 "Bury this mail buffer."
2023 (let ((newbuf (other-buffer buffer)))
2024 (bury-buffer buffer)
2025 (if (and (fboundp 'frame-parameters)
2026 (cdr (assq 'dedicated (frame-parameters)))
2027 (not (null (delq (selected-frame) (visible-frame-list)))))
2028 (delete-frame (selected-frame))
2029 (switch-to-buffer newbuf))))
2031 (defun message-send (&optional arg)
2032 "Send the message in the current buffer.
2033 If `message-interactive' is non-nil, wait for success indication or
2034 error messages, and inform user.
2035 Otherwise any failure is reported in a message back to the user from
2037 The usage of ARG is defined by the instance that called Message.
2038 It should typically alter the sending method in some way or other."
2040 ;; Make it possible to undo the coming changes.
2042 (let ((inhibit-read-only t))
2043 (put-text-property (point-min) (point-max) 'read-only nil))
2044 (message-fix-before-sending)
2045 (run-hooks 'message-send-hook)
2046 (message "Sending...")
2047 (let ((alist message-send-method-alist)
2051 (setq elem (pop alist)))
2052 (when (or (not (funcall (cadr elem)))
2053 (and (or (not (memq (car elem)
2054 message-sent-message-via))
2057 "Already sent message via %s; resend? "
2059 (setq success (funcall (caddr elem) arg))))
2061 (unless (or sent (not success))
2062 (error "No methods specified to send by"))
2063 (when (and success sent)
2066 (run-hooks 'message-sent-hook))
2067 (message "Sending...done")
2068 ;; Mark the buffer as unmodified and delete auto-save.
2069 (set-buffer-modified-p nil)
2070 (delete-auto-save-file-if-necessary t)
2071 (message-disassociate-draft)
2072 ;; Delete other mail buffers and stuff.
2073 (message-do-send-housekeeping)
2074 (message-do-actions message-send-actions)
2078 (defun message-send-via-mail (arg)
2079 "Send the current message via mail."
2080 (message-send-mail arg))
2082 (defun message-send-via-news (arg)
2083 "Send the current message via news."
2084 (funcall message-send-news-function arg))
2086 (defmacro message-check (type &rest forms)
2087 "Eval FORMS if TYPE is to be checked."
2088 `(or (message-check-element ,type)
2092 (put 'message-check 'lisp-indent-function 1)
2093 (put 'message-check 'edebug-form-spec '(form body))
2095 (defun message-fix-before-sending ()
2096 "Do various things to make the message nice before sending it."
2097 ;; Make sure there's a newline at the end of the message.
2098 (goto-char (point-max))
2101 ;; Delete all invisible text.
2102 (message-check 'invisible-text
2103 (when (text-property-any (point-min) (point-max) 'invisible t)
2104 (put-text-property (point-min) (point-max) 'invisible nil)
2105 (unless (yes-or-no-p
2106 "Invisible text found and made visible; continue posting? ")
2107 (error "Invisible text found and made visible")))))
2109 (defun message-add-action (action &rest types)
2110 "Add ACTION to be performed when doing an exit of type TYPES."
2113 (set (setq var (intern (format "message-%s-actions" (pop types))))
2114 (nconc (symbol-value var) (list action))))))
2116 (defun message-do-actions (actions)
2117 "Perform all actions in ACTIONS."
2118 ;; Now perform actions on successful sending.
2122 ;; A simple function.
2123 ((message-functionp (car actions))
2124 (funcall (car actions)))
2125 ;; Something to be evaled.
2127 (eval (car actions)))))
2130 (defun message-send-mail (&optional arg)
2131 (require 'mail-utils)
2132 (let* ((tembuf (message-generate-new-buffer-clone-locals " message temp"))
2133 (case-fold-search nil)
2134 (news (message-news-p))
2135 (mailbuf (current-buffer))
2136 (message-this-is-mail t)
2137 (message-posting-charset
2138 (if (fboundp 'gnus-setup-posting-charset)
2139 (gnus-setup-posting-charset nil)
2140 message-posting-charset)))
2142 (message-narrow-to-headers)
2143 ;; Insert some headers.
2144 (let ((message-deletable-headers
2145 (if news nil message-deletable-headers)))
2146 (message-generate-headers message-required-mail-headers))
2147 ;; Let the user do all of the above.
2148 (run-hooks 'message-header-hook))
2153 ;; Avoid copying text props.
2155 "%s" (save-excursion
2156 (set-buffer mailbuf)
2158 ;; Remove some headers.
2159 (message-encode-message-body)
2161 (message-narrow-to-headers)
2162 ;; We (re)generate the Lines header.
2163 (when (memq 'Lines message-required-mail-headers)
2164 (message-generate-headers '(Lines)))
2165 ;; Remove some headers.
2166 (message-remove-header message-ignored-mail-headers t)
2167 (mail-encode-encoded-word-buffer))
2168 (goto-char (point-max))
2169 ;; require one newline at the end.
2170 (or (= (preceding-char) ?\n)
2173 (or (message-fetch-field "cc")
2174 (message-fetch-field "to")))
2175 (message-insert-courtesy-copy))
2176 (funcall message-send-mail-function))
2177 (kill-buffer tembuf))
2178 (set-buffer mailbuf)
2179 (push 'mail message-sent-message-via)))
2181 (defun message-send-mail-with-sendmail ()
2182 "Send off the prepared buffer with sendmail."
2183 (let ((errbuf (if message-interactive
2184 (message-generate-new-buffer-clone-locals
2187 resend-to-addresses delimline)
2188 (let ((case-fold-search t))
2190 (message-narrow-to-headers)
2191 (setq resend-to-addresses (message-fetch-field "resent-to")))
2192 ;; Change header-delimiter to be what sendmail expects.
2193 (goto-char (point-min))
2195 (concat "^" (regexp-quote mail-header-separator) "\n"))
2196 (replace-match "\n")
2198 (setq delimline (point-marker))
2199 (run-hooks 'message-send-mail-hook)
2200 ;; Insert an extra newline if we need it to work around
2201 ;; Sun's bug that swallows newlines.
2202 (goto-char (1+ delimline))
2203 (when (eval message-mailer-swallows-blank-line)
2205 (when message-interactive
2209 (let ((default-directory "/")
2210 (coding-system-for-write message-send-coding-system))
2211 (apply 'call-process-region
2212 (append (list (point-min) (point-max)
2213 (if (boundp 'sendmail-program)
2215 "/usr/lib/sendmail")
2216 nil errbuf nil "-oi")
2217 ;; Always specify who from,
2218 ;; since some systems have broken sendmails.
2219 ;; But some systems are more broken with -f, so
2220 ;; we'll let users override this.
2221 (if (null message-sendmail-f-is-evil)
2222 (list "-f" (message-make-address)))
2223 ;; These mean "report errors by mail"
2224 ;; and "deliver in background".
2225 (if (null message-interactive) '("-oem" "-odb"))
2226 ;; Get the addresses from the message
2227 ;; unless this is a resend.
2228 ;; We must not do that for a resend
2229 ;; because we would find the original addresses.
2230 ;; For a resend, include the specific addresses.
2231 (if resend-to-addresses
2232 (list resend-to-addresses)
2234 (when message-interactive
2237 (goto-char (point-min))
2238 (while (re-search-forward "\n\n* *" nil t)
2239 (replace-match "; "))
2240 (if (not (zerop (buffer-size)))
2241 (error "Sending...failed to %s"
2242 (buffer-substring (point-min) (point-max)))))
2243 (when (bufferp errbuf)
2244 (kill-buffer errbuf)))))
2246 (defun message-send-mail-with-qmail ()
2247 "Pass the prepared message buffer to qmail-inject.
2248 Refer to the documentation for the variable `message-send-mail-function'
2249 to find out how to use this."
2250 ;; replace the header delimiter with a blank line
2251 (goto-char (point-min))
2253 (concat "^" (regexp-quote mail-header-separator) "\n"))
2254 (replace-match "\n")
2255 (run-hooks 'message-send-mail-hook)
2258 (let ((coding-system-for-write message-send-coding-system))
2260 'call-process-region 1 (point-max) message-qmail-inject-program
2262 ;; qmail-inject's default behaviour is to look for addresses on the
2263 ;; command line; if there're none, it scans the headers.
2264 ;; yes, it does The Right Thing w.r.t. Resent-To and it's kin.
2266 ;; in general, ALL of qmail-inject's defaults are perfect for simply
2267 ;; reading a formatted (i. e., at least a To: or Resent-To header)
2268 ;; message from stdin.
2270 ;; qmail also has the advantage of not having been raped by
2271 ;; various vendors, so we don't have to allow for that, either --
2272 ;; compare this with message-send-mail-with-sendmail and weep
2273 ;; for sendmail's lost innocence.
2275 ;; all this is way cool coz it lets us keep the arguments entirely
2276 ;; free for -inject-arguments -- a big win for the user and for us
2277 ;; since we don't have to play that double-guessing game and the user
2278 ;; gets full control (no gestapo'ish -f's, for instance). --sj
2279 message-qmail-inject-args))
2280 ;; qmail-inject doesn't say anything on it's stdout/stderr,
2281 ;; we have to look at the retval instead
2283 (1 (error "qmail-inject reported permanent failure"))
2284 (111 (error "qmail-inject reported transient failure"))
2285 ;; should never happen
2286 (t (error "qmail-inject reported unknown failure"))))
2288 (defun message-send-mail-with-mh ()
2289 "Send the prepared message buffer with mh."
2290 (let ((mh-previous-window-config nil)
2291 (name (mh-new-draft-name)))
2292 (setq buffer-file-name name)
2293 ;; MH wants to generate these headers itself.
2294 (when message-mh-deletable-headers
2295 (let ((headers message-mh-deletable-headers))
2297 (goto-char (point-min))
2298 (and (re-search-forward
2299 (concat "^" (symbol-name (car headers)) ": *") nil t)
2300 (message-delete-line))
2302 (run-hooks 'message-send-mail-hook)
2303 ;; Pass it on to mh.
2306 (defun message-send-news (&optional arg)
2307 (let* ((tembuf (message-generate-new-buffer-clone-locals " *message temp*"))
2308 (case-fold-search nil)
2309 (method (if (message-functionp message-post-method)
2310 (funcall message-post-method arg)
2311 message-post-method))
2312 (messbuf (current-buffer))
2313 (message-syntax-checks
2315 (cons '(existing-newsgroups . disabled)
2316 message-syntax-checks)
2317 message-syntax-checks))
2318 (message-this-is-news t)
2319 (message-posting-charset (gnus-setup-posting-charset
2320 (message-fetch-field "Newsgroups")))
2322 (if (not (message-check-news-body-syntax))
2325 (message-narrow-to-headers)
2326 ;; Insert some headers.
2327 (message-generate-headers message-required-news-headers)
2328 ;; Let the user do all of the above.
2329 (run-hooks 'message-header-hook))
2330 (message-cleanup-headers)
2331 (if (not (message-check-news-syntax))
2336 (buffer-disable-undo)
2338 ;; Avoid copying text props.
2340 "%s" (save-excursion
2341 (set-buffer messbuf)
2343 (message-encode-message-body)
2344 ;; Remove some headers.
2346 (message-narrow-to-headers)
2347 ;; We (re)generate the Lines header.
2348 (when (memq 'Lines message-required-mail-headers)
2349 (message-generate-headers '(Lines)))
2350 ;; Remove some headers.
2351 (message-remove-header message-ignored-news-headers t)
2352 (let ((mail-parse-charset (car message-posting-charset)))
2353 (mail-encode-encoded-word-buffer)))
2354 (goto-char (point-max))
2355 ;; require one newline at the end.
2356 (or (= (preceding-char) ?\n)
2358 (let ((case-fold-search t))
2359 ;; Remove the delimiter.
2360 (goto-char (point-min))
2362 (concat "^" (regexp-quote mail-header-separator) "\n"))
2363 (replace-match "\n")
2365 (run-hooks 'message-send-news-hook)
2366 (gnus-open-server method)
2367 (setq result (let ((mail-header-separator ""))
2368 (gnus-request-post method))))
2369 (kill-buffer tembuf))
2370 (set-buffer messbuf)
2372 (push 'news message-sent-message-via)
2373 (message "Couldn't send message via news: %s"
2374 (nnheader-get-report (car method)))
2378 ;;; Header generation & syntax checking.
2381 (defun message-check-element (type)
2382 "Returns non-nil if this type is not to be checked."
2383 (if (eq message-syntax-checks 'dont-check-for-anything-just-trust-me)
2385 (let ((able (assq type message-syntax-checks)))
2387 (eq (cdr able) 'disabled)))))
2389 (defun message-check-news-syntax ()
2390 "Check the syntax of the message."
2394 ;; We narrow to the headers and check them first.
2397 (message-narrow-to-headers)
2398 (message-check-news-header-syntax))))))
2400 (defun message-check-news-header-syntax ()
2402 ;; Check Newsgroups header.
2403 (message-check 'newsgroups
2404 (let ((group (message-fetch-field "newsgroups")))
2407 (not (string-match "\\`[ \t]*\\'" group)))
2410 "The newsgroups field is empty or missing. Posting is denied.")))))
2411 ;; Check the Subject header.
2412 (message-check 'subject
2413 (let* ((case-fold-search t)
2414 (subject (message-fetch-field "subject")))
2417 (not (string-match "\\`[ \t]*\\'" subject)))
2420 "The subject field is empty or missing. Posting is denied.")))))
2421 ;; Check for commands in Subject.
2422 (message-check 'subject-cmsg
2423 (if (string-match "^cmsg " (message-fetch-field "subject"))
2425 "The control code \"cmsg\" is in the subject. Really post? ")
2427 ;; Check for multiple identical headers.
2428 (message-check 'multiple-headers
2430 (while (and (not found)
2431 (re-search-forward "^[^ \t:]+: " nil t))
2433 (or (re-search-forward
2438 (match-beginning 0) (- (match-end 0) 2))))
2443 (y-or-n-p (format "Multiple %s headers. Really post? " found))
2445 ;; Check for Version and Sendsys.
2446 (message-check 'sendsys
2447 (if (re-search-forward "^Sendsys:\\|^Version:" nil t)
2449 (format "The article contains a %s command. Really post? "
2450 (buffer-substring (match-beginning 0)
2451 (1- (match-end 0)))))
2453 ;; See whether we can shorten Followup-To.
2454 (message-check 'shorten-followup-to
2455 (let ((newsgroups (message-fetch-field "newsgroups"))
2456 (followup-to (message-fetch-field "followup-to"))
2458 (when (and newsgroups
2459 (string-match "," newsgroups)
2464 (setq to (completing-read
2465 "Followups to: (default all groups) "
2466 (mapcar (lambda (g) (list g))
2468 (message-tokenize-header
2470 (goto-char (point-min))
2471 (insert "Followup-To: " to "\n"))
2473 ;; Check "Shoot me".
2474 (message-check 'shoot
2475 (if (re-search-forward
2476 "Message-ID.*.i-did-not-set--mail-host-address--so-shoot-me" nil t)
2477 (y-or-n-p "You appear to have a misconfigured system. Really post? ")
2479 ;; Check for Approved.
2480 (message-check 'approved
2481 (if (re-search-forward "^Approved:" nil t)
2482 (y-or-n-p "The article contains an Approved header. Really post? ")
2484 ;; Check the Message-ID header.
2485 (message-check 'message-id
2486 (let* ((case-fold-search t)
2487 (message-id (message-fetch-field "message-id" t)))
2488 (or (not message-id)
2489 ;; Is there an @ in the ID?
2490 (and (string-match "@" message-id)
2491 ;; Is there a dot in the ID?
2492 (string-match "@[^.]*\\." message-id)
2493 ;; Does the ID end with a dot?
2494 (not (string-match "\\.>" message-id)))
2496 (format "The Message-ID looks strange: \"%s\". Really post? "
2498 ;; Check the Newsgroups & Followup-To headers.
2499 (message-check 'existing-newsgroups
2500 (let* ((case-fold-search t)
2501 (newsgroups (message-fetch-field "newsgroups"))
2502 (followup-to (message-fetch-field "followup-to"))
2503 (groups (message-tokenize-header
2505 (concat newsgroups "," followup-to)
2507 (hashtb (and (boundp 'gnus-active-hashtb)
2508 gnus-active-hashtb))
2510 (if (or (not hashtb)
2511 (not (boundp 'gnus-read-active-file))
2512 (not gnus-read-active-file)
2513 (eq gnus-read-active-file 'some))
2516 (when (and (not (boundp (intern (car groups) hashtb)))
2517 (not (equal (car groups) "poster")))
2518 (push (car groups) errors))
2524 "Really post to %s unknown group%s: %s "
2525 (if (= (length errors) 1) "this" "these")
2526 (if (= (length errors) 1) "" "s")
2527 (mapconcat 'identity errors ", ")))))))
2528 ;; Check the Newsgroups & Followup-To headers for syntax errors.
2529 (message-check 'valid-newsgroups
2530 (let ((case-fold-search t)
2531 (headers '("Newsgroups" "Followup-To"))
2533 (while (and headers (not error))
2534 (when (setq header (mail-fetch-field (car headers)))
2538 "\\`\\([-+_&.a-zA-Z0-9]+\\)?\\(,[-+_&.a-zA-Z0-9]+\\)*\\'"
2543 (not (string-match "\\.\\'\\|\\.\\." g)))
2544 (message-tokenize-header header ","))))
2551 (format "The %s header looks odd: \"%s\". Really post? "
2552 (car headers) header)))))
2553 (message-check 'repeated-newsgroups
2554 (let ((case-fold-search t)
2555 (headers '("Newsgroups" "Followup-To"))
2556 header error groups group)
2559 (when (setq header (mail-fetch-field (pop headers)))
2560 (setq groups (message-tokenize-header header ","))
2561 (while (setq group (pop groups))
2562 (when (member group groups)
2568 (format "Group %s is repeated in headers. Really post? " error)))))
2569 ;; Check the From header.
2570 (message-check 'from
2571 (let* ((case-fold-search t)
2572 (from (message-fetch-field "from"))
2576 (message "There is no From line. Posting is denied.")
2578 ((or (not (string-match
2580 (setq ad (nth 1 (mail-extract-address-components
2581 from))))) ;larsi@ifi
2582 (string-match "\\.\\." ad) ;larsi@ifi..uio
2583 (string-match "@\\." ad) ;larsi@.ifi.uio
2584 (string-match "\\.$" ad) ;larsi@ifi.uio.
2585 (not (string-match "^[^@]+@[^@]+$" ad)) ;larsi.ifi.uio
2586 (string-match "(.*).*(.*)" from)) ;(lars) (lars)
2588 "Denied posting -- the From looks strange: \"%s\"." from)
2592 (defun message-check-news-body-syntax ()
2594 ;; Check for long lines.
2595 (message-check 'long-lines
2596 (goto-char (point-min))
2598 (concat "^" (regexp-quote mail-header-separator) "$"))
2602 (< (current-column) 80))
2603 (zerop (forward-line 1))))
2607 "You have lines longer than 79 characters. Really post? ")))
2608 ;; Check whether the article is empty.
2609 (message-check 'empty
2610 (goto-char (point-min))
2612 (concat "^" (regexp-quote mail-header-separator) "$"))
2615 (goto-char (point-max))
2616 (re-search-backward message-signature-separator nil t)
2618 (or (re-search-backward "[^ \n\t]" b t)
2619 (y-or-n-p "Empty article. Really post? "))))
2620 ;; Check for control characters.
2621 (message-check 'control-chars
2622 (if (re-search-forward "[\000-\007\013\015-\032\034-\037\200-\237]" nil t)
2624 "The article contains control characters. Really post? ")
2626 ;; Check excessive size.
2627 (message-check 'size
2628 (if (> (buffer-size) 60000)
2630 (format "The article is %d octets long. Really post? "
2633 ;; Check whether any new text has been added.
2634 (message-check 'new-text
2636 (not message-checksum)
2637 (not (eq (message-checksum) message-checksum))
2639 "It looks like no new text has been added. Really post? ")))
2640 ;; Check the length of the signature.
2641 (message-check 'signature
2642 (goto-char (point-max))
2643 (if (> (count-lines (point) (point-max)) 5)
2646 "Your .sig is %d lines; it should be max 4. Really post? "
2647 (1- (count-lines (point) (point-max)))))
2650 (defun message-checksum ()
2651 "Return a \"checksum\" for the current buffer."
2654 (goto-char (point-min))
2656 (concat "^" (regexp-quote mail-header-separator) "$"))
2658 (when (not (looking-at "[ \t\n]"))
2659 (setq sum (logxor (ash sum 1) (if (natnump sum) 0 1)
2664 (defun message-do-fcc ()
2665 "Process Fcc headers in the current buffer."
2666 (let ((case-fold-search t)
2667 (buf (current-buffer))
2670 (set-buffer (get-buffer-create " *message temp*"))
2672 (insert-buffer-substring buf)
2674 (message-narrow-to-headers)
2675 (while (setq file (message-fetch-field "fcc"))
2677 (message-remove-header "fcc" nil t)))
2678 (goto-char (point-min))
2679 (re-search-forward (concat "^" (regexp-quote mail-header-separator) "$"))
2680 (replace-match "" t t)
2681 ;; Process FCC operations.
2683 (setq file (pop list))
2684 (if (string-match "^[ \t]*|[ \t]*\\(.*\\)[ \t]*$" file)
2685 ;; Pipe the article to the program in question.
2686 (call-process-region (point-min) (point-max) shell-file-name
2687 nil nil nil shell-command-switch
2688 (match-string 1 file))
2689 ;; Save the article.
2690 (setq file (expand-file-name file))
2691 (unless (file-exists-p (file-name-directory file))
2692 (make-directory (file-name-directory file) t))
2693 (if (and message-fcc-handler-function
2694 (not (eq message-fcc-handler-function 'rmail-output)))
2695 (funcall message-fcc-handler-function file)
2696 (if (and (file-readable-p file) (mail-file-babyl-p file))
2697 (rmail-output file 1 nil t)
2698 (let ((mail-use-rfc822 t))
2699 (rmail-output file 1 t t))))))
2701 (kill-buffer (current-buffer)))))
2703 (defun message-output (filename)
2704 "Append this article to Unix/babyl mail file.."
2705 (if (and (file-readable-p filename)
2706 (mail-file-babyl-p filename))
2707 (rmail-output-to-rmail-file filename t)
2708 (gnus-output-to-mail filename t)))
2710 (defun message-cleanup-headers ()
2711 "Do various automatic cleanups of the headers."
2712 ;; Remove empty lines in the header.
2714 (message-narrow-to-headers)
2715 ;; Remove blank lines.
2716 (while (re-search-forward "^[ \t]*\n" nil t)
2717 (replace-match "" t t))
2719 ;; Correct Newsgroups and Followup-To headers: Change sequence of
2720 ;; spaces to comma and eliminate spaces around commas. Eliminate
2721 ;; embedded line breaks.
2722 (goto-char (point-min))
2723 (while (re-search-forward "^\\(Newsgroups\\|Followup-To\\): +" nil t)
2727 (if (re-search-forward "^[^ \t]" nil t)
2731 (goto-char (point-min))
2732 (while (re-search-forward "\n[ \t]+" nil t)
2733 (replace-match " " t t)) ;No line breaks (too confusing)
2734 (goto-char (point-min))
2735 (while (re-search-forward "[ \t\n]*,[ \t\n]*\\|[ \t]+" nil t)
2736 (replace-match "," t t))
2737 (goto-char (point-min))
2738 ;; Remove trailing commas.
2739 (when (re-search-forward ",+$" nil t)
2740 (replace-match "" t t))))))
2742 (defun message-make-date (&optional now)
2743 "Make a valid data header.
2744 If NOW, use that time instead."
2745 (let* ((now (or now (current-time)))
2746 (zone (nth 8 (decode-time now)))
2750 (setq zone (- zone)))
2752 (format-time-string "%d" now)
2753 ;; The month name of the %b spec is locale-specific. Pfff.
2755 (capitalize (car (rassoc (nth 4 (decode-time now))
2756 parse-time-months))))
2757 (format-time-string "%Y %H:%M:%S " now)
2758 ;; We do all of this because XEmacs doesn't have the %z spec.
2759 (format "%s%02d%02d" sign (/ zone 3600) (/ (% zone 3600) 60)))))
2761 (defun message-make-message-id ()
2762 "Make a unique Message-ID."
2763 (concat "<" (message-unique-id)
2764 (let ((psubject (save-excursion (message-fetch-field "subject")))
2766 (save-excursion (message-fetch-field "supersedes"))))
2768 (and message-reply-headers
2769 (mail-header-references message-reply-headers)
2770 (mail-header-subject message-reply-headers)
2772 (mail-header-subject message-reply-headers)
2774 (message-strip-subject-re
2775 (mail-header-subject message-reply-headers))
2776 (message-strip-subject-re psubject))))
2778 (string-match "_-_@" psupersedes)))
2780 "@" (message-make-fqdn) ">"))
2782 (defvar message-unique-id-char nil)
2784 ;; If you ever change this function, make sure the new version
2785 ;; cannot generate IDs that the old version could.
2786 ;; You might for example insert a "." somewhere (not next to another dot
2787 ;; or string boundary), or modify the "fsf" string.
2788 (defun message-unique-id ()
2789 ;; Don't use microseconds from (current-time), they may be unsupported.
2790 ;; Instead we use this randomly inited counter.
2791 (setq message-unique-id-char
2792 (% (1+ (or message-unique-id-char (logand (random t) (1- (lsh 1 20)))))
2793 ;; (current-time) returns 16-bit ints,
2794 ;; and 2^16*25 just fits into 4 digits i base 36.
2796 (let ((tm (current-time)))
2798 (if (memq system-type '(ms-dos emx vax-vms))
2799 (let ((user (downcase (user-login-name))))
2800 (while (string-match "[^a-z0-9_]" user)
2801 (aset user (match-beginning 0) ?_))
2803 (message-number-base36 (user-uid) -1))
2804 (message-number-base36 (+ (car tm)
2805 (lsh (% message-unique-id-char 25) 16)) 4)
2806 (message-number-base36 (+ (nth 1 tm)
2807 (lsh (/ message-unique-id-char 25) 16)) 4)
2808 ;; Append the newsreader name, because while the generated
2809 ;; ID is unique to this newsreader, other newsreaders might
2810 ;; otherwise generate the same ID via another algorithm.
2813 (defun message-number-base36 (num len)
2818 (concat (message-number-base36 (/ num 36) (1- len))
2819 (char-to-string (aref "zyxwvutsrqponmlkjihgfedcba9876543210"
2822 (defun message-make-organization ()
2823 "Make an Organization header."
2824 (let* ((organization
2825 (when message-user-organization
2826 (if (message-functionp message-user-organization)
2827 (funcall message-user-organization)
2828 message-user-organization))))
2830 (message-set-work-buffer)
2831 (cond ((stringp organization)
2832 (insert organization))
2833 ((and (eq t organization)
2834 message-user-organization-file
2835 (file-exists-p message-user-organization-file))
2836 (insert-file-contents message-user-organization-file)))
2837 (goto-char (point-min))
2838 (while (re-search-forward "[\t\n]+" nil t)
2839 (replace-match "" t t))
2840 (unless (zerop (buffer-size))
2843 (defun message-make-lines ()
2844 "Count the number of lines and return numeric string."
2848 (goto-char (point-min))
2850 (concat "^" (regexp-quote mail-header-separator) "$"))
2852 (int-to-string (count-lines (point) (point-max))))))
2854 (defun message-make-in-reply-to ()
2855 "Return the In-Reply-To header for this message."
2856 (when message-reply-headers
2857 (let ((from (mail-header-from message-reply-headers))
2858 (date (mail-header-date message-reply-headers)))
2861 (string-match " *at \\| *@ \\| *(\\| *<" from)))
2862 (concat (if (and stop-pos
2863 (not (zerop stop-pos)))
2864 (substring from 0 stop-pos) from)
2866 (if (or (not date) (string= date ""))
2867 "(unknown date)" date)
2870 (defun message-make-distribution ()
2871 "Make a Distribution header."
2872 (let ((orig-distribution (message-fetch-reply-field "distribution")))
2873 (cond ((message-functionp message-distribution-function)
2874 (funcall message-distribution-function))
2875 (t orig-distribution))))
2877 (defun message-make-expires ()
2878 "Return an Expires header based on `message-expires'."
2879 (let ((current (current-time))
2880 (future (* 1.0 message-expires 60 60 24)))
2881 ;; Add the future to current.
2882 (setcar current (+ (car current) (round (/ future (expt 2 16)))))
2883 (setcar (cdr current) (+ (nth 1 current) (% (round future) (expt 2 16))))
2884 (message-make-date current)))
2886 (defun message-make-path ()
2888 (let ((login-name (user-login-name)))
2889 (cond ((null message-user-path)
2890 (concat (system-name) "!" login-name))
2891 ((stringp message-user-path)
2892 ;; Support GENERICPATH. Suggested by vixie@decwrl.dec.com.
2893 (concat message-user-path "!" login-name))
2896 (defun message-make-from ()
2897 "Make a From header."
2898 (let* ((style message-from-style)
2899 (login (message-make-address))
2901 (or (and (boundp 'user-full-name)
2904 (when (string= fullname "&")
2905 (setq fullname (user-login-name)))
2907 (message-set-work-buffer)
2910 (equal fullname ""))
2912 ((or (eq style 'angles)
2913 (and (not (eq style 'parens))
2914 ;; Use angles if no quoting is needed, or if parens would
2915 ;; need quoting too.
2916 (or (not (string-match "[^- !#-'*+/-9=?A-Z^-~]" fullname))
2917 (let ((tmp (concat fullname nil)))
2918 (while (string-match "([^()]*)" tmp)
2919 (aset tmp (match-beginning 0) ?-)
2920 (aset tmp (1- (match-end 0)) ?-))
2921 (string-match "[\\()]" tmp)))))
2923 (goto-char (point-min))
2924 ;; Look for a character that cannot appear unquoted
2925 ;; according to RFC 822.
2926 (when (re-search-forward "[^- !#-'*+/-9=?A-Z^-~]" nil 1)
2927 ;; Quote fullname, escaping specials.
2928 (goto-char (point-min))
2930 (while (re-search-forward "[\"\\]" nil 1)
2931 (replace-match "\\\\\\&" t))
2933 (insert " <" login ">"))
2934 (t ; 'parens or default
2936 (let ((fullname-start (point)))
2938 (goto-char fullname-start)
2939 ;; RFC 822 says \ and nonmatching parentheses
2940 ;; must be escaped in comments.
2941 ;; Escape every instance of ()\ ...
2942 (while (re-search-forward "[()\\]" nil 1)
2943 (replace-match "\\\\\\&" t))
2944 ;; ... then undo escaping of matching parentheses,
2945 ;; including matching nested parentheses.
2946 (goto-char fullname-start)
2947 (while (re-search-forward
2948 "\\(\\=\\|[^\\]\\(\\\\\\\\\\)*\\)\\\\(\\(\\([^\\]\\|\\\\\\\\\\)*\\)\\\\)"
2950 (replace-match "\\1(\\3)" t)
2951 (goto-char fullname-start)))
2955 (defun message-make-sender ()
2956 "Return the \"real\" user address.
2957 This function tries to ignore all user modifications, and
2958 give as trustworthy answer as possible."
2959 (concat (user-login-name) "@" (system-name)))
2961 (defun message-make-address ()
2962 "Make the address of the user."
2963 (or (message-user-mail-address)
2964 (concat (user-login-name) "@" (message-make-domain))))
2966 (defun message-user-mail-address ()
2967 "Return the pertinent part of `user-mail-address'."
2968 (when user-mail-address
2969 (if (string-match " " user-mail-address)
2970 (nth 1 (mail-extract-address-components user-mail-address))
2971 user-mail-address)))
2973 (defun message-make-fqdn ()
2974 "Return user's fully qualified domain name."
2975 (let ((system-name (system-name))
2976 (user-mail (message-user-mail-address)))
2978 ((string-match "[^.]\\.[^.]" system-name)
2979 ;; `system-name' returned the right result.
2981 ;; Try `mail-host-address'.
2982 ((and (boundp 'mail-host-address)
2983 (stringp mail-host-address)
2984 (string-match "\\." mail-host-address))
2986 ;; We try `user-mail-address' as a backup.
2988 (string-match "\\." user-mail)
2989 (string-match "@\\(.*\\)\\'" user-mail))
2990 (match-string 1 user-mail))
2991 ;; Default to this bogus thing.
2993 (concat system-name ".i-did-not-set--mail-host-address--so-shoot-me")))))
2995 (defun message-make-host-name ()
2996 "Return the name of the host."
2997 (let ((fqdn (message-make-fqdn)))
2998 (string-match "^[^.]+\\." fqdn)
2999 (substring fqdn 0 (1- (match-end 0)))))
3001 (defun message-make-domain ()
3002 "Return the domain name."
3003 (or mail-host-address
3004 (message-make-fqdn)))
3006 (defun message-generate-headers (headers)
3007 "Prepare article HEADERS.
3008 Headers already prepared in the buffer are not modified."
3010 (message-narrow-to-headers)
3011 (let* ((Date (message-make-date))
3012 (Message-ID (message-make-message-id))
3013 (Organization (message-make-organization))
3014 (From (message-make-from))
3015 (Path (message-make-path))
3018 (In-Reply-To (message-make-in-reply-to))
3020 (Distribution (message-make-distribution))
3021 (Lines (message-make-lines))
3022 (User-Agent message-newsreader)
3023 (Expires (message-make-expires))
3024 (case-fold-search t)
3026 ;; First we remove any old generated headers.
3027 (let ((headers message-deletable-headers))
3028 (unless (buffer-modified-p)
3029 (setq headers (delq 'Message-ID (copy-sequence headers))))
3031 (goto-char (point-min))
3032 (and (re-search-forward
3033 (concat "^" (symbol-name (car headers)) ": *") nil t)
3034 (get-text-property (1+ (match-beginning 0)) 'message-deletable)
3035 (message-delete-line))
3037 ;; Go through all the required headers and see if they are in the
3038 ;; articles already. If they are not, or are empty, they are
3039 ;; inserted automatically - except for Subject, Newsgroups and
3042 (goto-char (point-min))
3043 (setq elem (pop headers))
3045 (if (eq (car elem) 'optional)
3046 (setq header (cdr elem))
3047 (setq header (car elem)))
3049 (when (or (not (re-search-forward
3053 (if (stringp header)
3055 (symbol-name header))))
3059 ;; The header was found. We insert a space after the
3060 ;; colon, if there is none.
3061 (if (/= (char-after) ? ) (insert " ") (forward-char 1))
3062 ;; Find out whether the header is empty...
3063 (looking-at "[ \t]*\n[^ \t]")))
3064 ;; So we find out what value we should insert.
3067 ((and (consp elem) (eq (car elem) 'optional))
3068 ;; This is an optional header. If the cdr of this
3069 ;; is something that is nil, then we do not insert
3071 (setq header (cdr elem))
3072 (or (and (fboundp (cdr elem)) (funcall (cdr elem)))
3073 (and (boundp (cdr elem)) (symbol-value (cdr elem)))))
3075 ;; The element is a cons. Either the cdr is a
3076 ;; string to be inserted verbatim, or it is a
3077 ;; function, and we insert the value returned from
3079 (or (and (stringp (cdr elem)) (cdr elem))
3080 (and (fboundp (cdr elem)) (funcall (cdr elem)))))
3081 ((and (boundp header) (symbol-value header))
3082 ;; The element is a symbol. We insert the value
3083 ;; of this symbol, if any.
3084 (symbol-value header))
3085 ((not (message-check-element header))
3086 ;; We couldn't generate a value for this header,
3087 ;; so we just ask the user.
3088 (read-from-minibuffer
3089 (format "Empty header for %s; enter value: " header)))))
3090 ;; Finally insert the header.
3092 (not (equal value "")))
3096 ;; This header didn't exist, so we insert it.
3097 (goto-char (point-max))
3098 (insert (if (stringp header) header (symbol-name header))
3101 ;; The value of this header was empty, so we clear
3102 ;; totally and insert the new value.
3103 (delete-region (point) (gnus-point-at-eol))
3105 ;; Add the deletable property to the headers that require it.
3106 (and (memq header message-deletable-headers)
3107 (progn (beginning-of-line) (looking-at "[^:]+: "))
3108 (add-text-properties
3109 (point) (match-end 0)
3110 '(message-deletable t face italic) (current-buffer)))))))
3111 ;; Insert new Sender if the From is strange.
3112 (let ((from (message-fetch-field "from"))
3113 (sender (message-fetch-field "sender"))
3114 (secure-sender (message-make-sender)))
3116 (not (message-check-element 'sender))
3119 (cadr (mail-extract-address-components from)))
3120 (downcase secure-sender)))
3125 (cadr (mail-extract-address-components sender)))
3126 (downcase secure-sender)))))
3127 (goto-char (point-min))
3128 ;; Rename any old Sender headers to Original-Sender.
3129 (when (re-search-forward "^\\(Original-\\)*Sender:" nil t)
3131 (insert "Original-")
3132 (beginning-of-line))
3133 (when (or (message-news-p)
3134 (string-match "@.+\\.." secure-sender))
3135 (insert "Sender: " secure-sender "\n")))))))
3137 (defun message-insert-courtesy-copy ()
3138 "Insert a courtesy message in mail copies of combined messages."
3142 (message-narrow-to-headers)
3143 (when (setq newsgroups (message-fetch-field "newsgroups"))
3144 (goto-char (point-max))
3145 (insert "Posted-To: " newsgroups "\n")))
3147 (when message-courtesy-message
3149 ((string-match "%s" message-courtesy-message)
3150 (insert (format message-courtesy-message newsgroups)))
3152 (insert message-courtesy-message)))))))
3155 ;;; Setting up a message buffer
3158 (defun message-fill-address (header value)
3160 (narrow-to-region (point) (point))
3161 (insert (capitalize (symbol-name header))
3163 (if (consp value) (car value) value)
3165 (narrow-to-region (point-min) (1- (point-max)))
3167 (goto-char (point-min))
3169 (skip-chars-forward "^,\"" (point-max))
3170 (if (or (eq (char-after) ?,)
3173 (if (and (> (current-column) 78)
3179 (setq last (1+ (point))))
3180 (setq last (1+ (point)))))
3181 (setq quoted (not quoted)))
3184 (goto-char (point-max))
3188 (defun message-fill-header (header value)
3189 (let ((begin (point))
3192 (insert (capitalize (symbol-name header))
3194 (if (consp value) (car value) value)
3197 (narrow-to-region begin (point))
3198 (fill-region-as-paragraph begin (point))
3199 ;; Tapdance around looong Message-IDs.
3201 (when (looking-at "[ \t]*$")
3202 (message-delete-line))
3204 (re-search-forward ":" nil t)
3205 (when (looking-at "\n[ \t]+")
3206 (replace-match " " t t))
3207 (goto-char (point-max)))))
3209 (defun message-shorten-1 (list cut surplus)
3210 ;; Cut SURPLUS elements out of LIST, beginning with CUTth one.
3211 (setcdr (nthcdr (- cut 2) list)
3212 (nthcdr (+ (- cut 2) surplus 1) list)))
3214 (defun message-shorten-references (header references)
3215 "Trim REFERENCES to be less than 31 Message-ID long, and fold them.
3216 If folding is disallowed, also check that the REFERENCES are less
3217 than 988 characters long, and if they are not, trim them until they are."
3224 (goto-char (point-min))
3225 ;; Cons a list of valid references.
3226 (while (re-search-forward "<[^>]+>" nil t)
3227 (push (match-string 0) refs))
3228 (setq refs (nreverse refs)
3229 count (length refs)))
3231 ;; If the list has more than MAXCOUNT elements, trim it by
3232 ;; removing the CUTth element and the required number of
3233 ;; elements that follow.
3234 (when (> count maxcount)
3235 (let ((surplus (- count maxcount)))
3236 (message-shorten-1 refs cut surplus)
3237 (decf count surplus)))
3239 ;; If folding is disallowed, make sure the total length (including
3240 ;; the spaces between) will be less than MAXSIZE characters.
3242 ;; Only disallow folding for News messages. At this point the headers
3243 ;; have not been generated, thus we use message-this-is-news directly.
3244 (when (and message-this-is-news message-cater-to-broken-inn)
3246 (totalsize (+ (apply #'+ (mapcar #'length refs))
3249 (ptr (nthcdr (1- cut) refs)))
3250 ;; Decide how many elements to cut off...
3251 (while (> totalsize maxsize)
3252 (decf totalsize (1+ (length (car ptr))))
3254 (setq ptr (cdr ptr)))
3257 (message-shorten-1 refs cut surplus))))
3259 ;; Finally, collect the references back into a string and insert
3260 ;; it into the buffer.
3261 (let ((refstring (mapconcat #'identity refs " ")))
3262 (if (and message-this-is-news message-cater-to-broken-inn)
3263 (insert (capitalize (symbol-name header)) ": "
3265 (message-fill-header header refstring)))))
3267 (defun message-position-point ()
3268 "Move point to where the user probably wants to find it."
3269 (message-narrow-to-headers)
3271 ((re-search-forward "^[^:]+:[ \t]*$" nil t)
3272 (search-backward ":" )
3275 (if (eq (char-after) ? )
3279 (goto-char (point-max))
3282 (unless (looking-at "$")
3286 (defun message-buffer-name (type &optional to group)
3287 "Return a new (unique) buffer name based on TYPE and TO."
3289 ;; Generate a new buffer name The Message Way.
3290 ((eq message-generate-new-buffers 'unique)
3291 (generate-new-buffer-name
3295 (or (car (mail-extract-address-components to))
3298 (if (and group (not (string= group ""))) (concat " on " group) "")
3300 ;; Check whether `message-generate-new-buffers' is a function,
3301 ;; and if so, call it.
3302 ((message-functionp message-generate-new-buffers)
3303 (funcall message-generate-new-buffers type to group))
3304 ((eq message-generate-new-buffers 'unsent)
3305 (generate-new-buffer-name
3306 (concat "*unsent " type
3309 (or (car (mail-extract-address-components to))
3312 (if (and group (not (string= group ""))) (concat " on " group) "")
3314 ;; Use standard name.
3316 (format "*%s message*" type))))
3318 (defun message-pop-to-buffer (name)
3319 "Pop to buffer NAME, and warn if it already exists and is modified."
3320 (let ((buffer (get-buffer name)))
3322 (buffer-name buffer))
3324 (set-buffer (pop-to-buffer buffer))
3325 (when (and (buffer-modified-p)
3327 "Message already being composed; erase? ")))
3328 (error "Message being composed")))
3329 (set-buffer (pop-to-buffer name)))
3333 (defun message-do-send-housekeeping ()
3334 "Kill old message buffers."
3335 ;; We might have sent this buffer already. Delete it from the
3337 (setq message-buffer-list (delq (current-buffer) message-buffer-list))
3338 (while (and message-max-buffers
3340 (>= (length message-buffer-list) message-max-buffers))
3341 ;; Kill the oldest buffer -- unless it has been changed.
3342 (let ((buffer (pop message-buffer-list)))
3343 (when (and (buffer-name buffer)
3344 (not (buffer-modified-p buffer)))
3345 (kill-buffer buffer))))
3346 ;; Rename the buffer.
3347 (if message-send-rename-function
3348 (funcall message-send-rename-function)
3349 (when (string-match "\\`\\*\\(unsent \\)?" (buffer-name))
3351 (concat "*sent " (substring (buffer-name) (match-end 0))) t)))
3352 ;; Push the current buffer onto the list.
3353 (when message-max-buffers
3354 (setq message-buffer-list
3355 (nconc message-buffer-list (list (current-buffer))))))
3357 (defvar mc-modes-alist)
3358 (defun message-setup (headers &optional replybuffer actions)
3359 (when (and (boundp 'mc-modes-alist)
3360 (not (assq 'message-mode mc-modes-alist)))
3361 (push '(message-mode (encrypt . mc-encrypt-message)
3362 (sign . mc-sign-message))
3365 (setq message-send-actions actions))
3366 (setq message-reply-buffer replybuffer)
3367 (goto-char (point-min))
3368 ;; Insert all the headers.
3371 (alist message-header-format-alist))
3373 (unless (assq (caar h) message-header-format-alist)
3374 (push (list (caar h)) alist))
3378 (delete-region (point) (progn (forward-line -1) (point)))
3379 (when message-default-headers
3380 (insert message-default-headers)
3381 (or (bolp) (insert ?\n)))
3385 (insert mail-header-separator "\n")
3389 (when (message-news-p)
3390 (when message-default-news-headers
3391 (insert message-default-news-headers)
3392 (or (bolp) (insert ?\n)))
3393 (when message-generate-headers-first
3394 (message-generate-headers
3397 (copy-sequence message-required-news-headers))))))
3398 (when (message-mail-p)
3399 (when message-default-mail-headers
3400 (insert message-default-mail-headers)
3401 (or (bolp) (insert ?\n)))
3402 (when message-generate-headers-first
3403 (message-generate-headers
3406 (copy-sequence message-required-mail-headers))))))
3407 (run-hooks 'message-signature-setup-hook)
3408 (message-insert-signature)
3410 (message-narrow-to-headers)
3411 (run-hooks 'message-header-setup-hook))
3412 (set-buffer-modified-p nil)
3413 (setq buffer-undo-list nil)
3414 (run-hooks 'message-setup-hook)
3415 (message-position-point)
3418 (defun message-set-auto-save-file-name ()
3419 "Associate the message buffer with a file in the drafts directory."
3420 (when message-auto-save-directory
3422 (setq message-draft-article
3423 (nndraft-request-associate-buffer "drafts"))
3424 (setq buffer-file-name (expand-file-name "*message*"
3425 message-auto-save-directory))
3426 (setq buffer-auto-save-file-name (make-auto-save-file-name)))
3427 (clear-visited-file-modtime)
3428 (setq buffer-file-coding-system message-draft-coding-system)))
3430 (defun message-disassociate-draft ()
3431 "Disassociate the message buffer from the drafts directory."
3432 (when message-draft-article
3433 (nndraft-request-expire-articles
3434 (list message-draft-article) "drafts" nil t)))
3436 (defun message-insert-headers ()
3437 "Generate the headers for the article."
3441 (message-narrow-to-headers)
3442 (when (message-news-p)
3443 (message-generate-headers
3446 (copy-sequence message-required-news-headers)))))
3447 (when (message-mail-p)
3448 (message-generate-headers
3451 (copy-sequence message-required-mail-headers))))))))
3456 ;;; Commands for interfacing with message
3460 (defun message-mail (&optional to subject
3461 other-headers continue switch-function
3462 yank-action send-actions)
3463 "Start editing a mail message to be sent.
3464 OTHER-HEADERS is an alist of header/value pairs."
3466 (let ((message-this-is-mail t))
3467 (message-pop-to-buffer (message-buffer-name "mail" to))
3470 `((To . ,(or to "")) (Subject . ,(or subject "")))
3471 (when other-headers other-headers)))))
3474 (defun message-news (&optional newsgroups subject)
3475 "Start editing a news article to be sent."
3477 (let ((message-this-is-news t))
3478 (message-pop-to-buffer (message-buffer-name "news" nil newsgroups))
3479 (message-setup `((Newsgroups . ,(or newsgroups ""))
3480 (Subject . ,(or subject ""))))))
3483 (defun message-reply (&optional to-address wide)
3484 "Start editing a reply to the article in the current buffer."
3486 (let ((cur (current-buffer))
3487 from subject date reply-to to cc
3488 references message-id follow-to
3489 (inhibit-point-motion-hooks t)
3490 (message-this-is-mail t)
3491 mct never-mct gnus-warning)
3493 (message-narrow-to-head)
3494 ;; Allow customizations to have their say.
3496 ;; This is a regular reply.
3497 (if (message-functionp message-reply-to-function)
3498 (setq follow-to (funcall message-reply-to-function)))
3499 ;; This is a followup.
3500 (if (message-functionp message-wide-reply-to-function)
3503 (funcall message-wide-reply-to-function)))))
3504 ;; Find all relevant headers we need.
3505 (setq from (message-fetch-field "from")
3506 date (message-fetch-field "date")
3507 subject (or (message-fetch-field "subject") "none")
3508 to (message-fetch-field "to")
3509 cc (message-fetch-field "cc")
3510 mct (message-fetch-field "mail-copies-to")
3511 reply-to (message-fetch-field "reply-to")
3512 references (message-fetch-field "references")
3513 message-id (message-fetch-field "message-id" t))
3514 ;; Remove any (buggy) Re:'s that are present and make a
3516 (when (string-match message-subject-re-regexp subject)
3517 (setq subject (substring subject (match-end 0))))
3518 (setq subject (concat "Re: " subject))
3520 (when (and (setq gnus-warning (message-fetch-field "gnus-warning"))
3521 (string-match "<[^>]+>" gnus-warning))
3522 (setq message-id (match-string 0 gnus-warning)))
3524 ;; Handle special values of Mail-Copies-To.
3526 (cond ((or (equal (downcase mct) "never")
3527 (equal (downcase mct) "nobody"))
3530 ((or (equal (downcase mct) "always")
3531 (equal (downcase mct) "poster"))
3532 (setq mct (or reply-to from)))))
3538 (setq follow-to (list (cons 'To (or to-address reply-to from))))
3539 (when (and wide mct)
3540 (push (cons 'Cc mct) follow-to)))
3543 (message-set-work-buffer)
3545 (insert (or reply-to from "")))
3546 (insert (if to (concat (if (bolp) "" ", ") to "") ""))
3547 (insert (if mct (concat (if (bolp) "" ", ") mct) ""))
3548 (insert (if cc (concat (if (bolp) "" ", ") cc) ""))
3549 (goto-char (point-min))
3550 (while (re-search-forward "[ \t]+" nil t)
3551 (replace-match " " t t))
3552 ;; Remove addresses that match `rmail-dont-reply-to-names'.
3553 (let ((rmail-dont-reply-to-names message-dont-reply-to-names))
3554 (insert (prog1 (rmail-dont-reply-to (buffer-string))
3556 (goto-char (point-min))
3557 ;; Perhaps Mail-Copies-To: never removed the only address?
3559 (insert (or reply-to from "")))
3563 (cons (mail-strip-quoted-names addr) addr))
3564 (message-tokenize-header (buffer-string))))
3567 (setq ccalist (delq (assoc (car (pop s)) s) ccalist)))))
3568 (setq follow-to (list (cons 'To (cdr (pop ccalist)))))
3570 (let ((ccs (cons 'Cc (mapconcat
3571 (lambda (addr) (cdr addr)) ccalist ", "))))
3572 (when (string-match "^ +" (cdr ccs))
3573 (setcdr ccs (substring (cdr ccs) (match-end 0))))
3574 (push ccs follow-to))))))
3577 (message-pop-to-buffer (message-buffer-name
3578 (if wide "wide reply" "reply") from
3579 (if wide to-address nil)))
3581 (setq message-reply-headers
3582 (vector 0 subject from date message-id references 0 0 ""))
3585 `((Subject . ,subject)
3587 ,@(if (or references message-id)
3588 `((References . ,(concat (or references "") (and references " ")
3589 (or message-id ""))))
3594 (defun message-wide-reply (&optional to-address)
3595 "Make a \"wide\" reply to the message in the current buffer."
3597 (message-reply to-address t))
3600 (defun message-followup (&optional to-newsgroups)
3601 "Follow up to the message in the current buffer.
3602 If TO-NEWSGROUPS, use that as the new Newsgroups line."
3604 (let ((cur (current-buffer))
3605 from subject date reply-to mct
3606 references message-id follow-to
3607 (inhibit-point-motion-hooks t)
3608 (message-this-is-news t)
3609 followup-to distribution newsgroups gnus-warning posted-to)
3612 (goto-char (point-min))
3613 (if (search-forward "\n\n" nil t)
3616 (when (message-functionp message-followup-to-function)
3618 (funcall message-followup-to-function)))
3619 (setq from (message-fetch-field "from")
3620 date (message-fetch-field "date")
3621 subject (or (message-fetch-field "subject") "none")
3622 references (message-fetch-field "references")
3623 message-id (message-fetch-field "message-id" t)
3624 followup-to (message-fetch-field "followup-to")
3625 newsgroups (message-fetch-field "newsgroups")
3626 posted-to (message-fetch-field "posted-to")
3627 reply-to (message-fetch-field "reply-to")
3628 distribution (message-fetch-field "distribution")
3629 mct (message-fetch-field "mail-copies-to"))
3630 (when (and (setq gnus-warning (message-fetch-field "gnus-warning"))
3631 (string-match "<[^>]+>" gnus-warning))
3632 (setq message-id (match-string 0 gnus-warning)))
3633 ;; Remove bogus distribution.
3634 (when (and (stringp distribution)
3635 (let ((case-fold-search t))
3636 (string-match "world" distribution)))
3637 (setq distribution nil))
3638 ;; Remove any (buggy) Re:'s that are present and make a
3640 (when (string-match message-subject-re-regexp subject)
3641 (setq subject (substring subject (match-end 0))))
3642 (setq subject (concat "Re: " subject))
3645 (message-pop-to-buffer (message-buffer-name "followup" from newsgroups))
3648 `((Subject . ,subject)
3651 (list (cons 'Newsgroups to-newsgroups)))
3652 (follow-to follow-to)
3653 ((and followup-to message-use-followup-to)
3656 ((equal (downcase followup-to) "poster")
3657 (if (or (eq message-use-followup-to 'use)
3658 (message-y-or-n-p "Obey Followup-To: poster? " t "\
3659 You should normally obey the Followup-To: header.
3661 `Followup-To: poster' sends your response via e-mail instead of news.
3663 A typical situation where `Followup-To: poster' is used is when the poster
3664 does not read the newsgroup, so he wouldn't see any replies sent to it."))
3666 (setq message-this-is-news nil)
3667 (cons 'To (or reply-to from "")))
3668 (cons 'Newsgroups newsgroups)))
3670 (if (or (equal followup-to newsgroups)
3671 (not (eq message-use-followup-to 'ask))
3673 (concat "Obey Followup-To: " followup-to "? ") t "\
3674 You should normally obey the Followup-To: header.
3676 `Followup-To: " followup-to "'
3677 directs your response to " (if (string-match "," followup-to)
3678 "the specified newsgroups"
3679 "that newsgroup only") ".
3681 If a message is posted to several newsgroups, Followup-To is often
3682 used to direct the following discussion to one newsgroup only,
3683 because discussions that are spread over several newsgroup tend to
3684 be fragmented and very difficult to follow.
3686 Also, some source/announcement newsgroups are not indented for discussion;
3687 responses here are directed to other newsgroups."))
3688 (cons 'Newsgroups followup-to)
3689 (cons 'Newsgroups newsgroups))))))
3691 `((Newsgroups . ,posted-to)))
3693 `((Newsgroups . ,newsgroups))))
3694 ,@(and distribution (list (cons 'Distribution distribution)))
3695 ,@(if (or references message-id)
3696 `((References . ,(concat (or references "") (and references " ")
3697 (or message-id "")))))
3699 (not (or (equal (downcase mct) "never")
3700 (equal (downcase mct) "nobody"))))
3701 (list (cons 'Cc (if (or (equal (downcase mct) "always")
3702 (equal (downcase mct) "poster"))
3703 (or reply-to from "")
3708 (setq message-reply-headers
3709 (vector 0 subject from date message-id references 0 0 ""))))
3713 (defun message-cancel-news (&optional arg)
3714 "Cancel an article you posted.
3715 If ARG, allow editing of the cancellation message."
3717 (unless (message-news-p)
3718 (error "This is not a news article; canceling is impossible"))
3719 (when (yes-or-no-p "Do you really want to cancel this article? ")
3720 (let (from newsgroups message-id distribution buf sender)
3722 ;; Get header info from original article.
3724 (message-narrow-to-head)
3725 (setq from (message-fetch-field "from")
3726 sender (message-fetch-field "sender")
3727 newsgroups (message-fetch-field "newsgroups")
3728 message-id (message-fetch-field "message-id" t)
3729 distribution (message-fetch-field "distribution")))
3730 ;; Make sure that this article was written by the user.
3731 (unless (or (and sender
3734 (downcase (message-make-sender))))
3736 (downcase (cadr (mail-extract-address-components from)))
3737 (downcase (cadr (mail-extract-address-components
3738 (message-make-from))))))
3739 (error "This article is not yours"))
3740 ;; Make control message.
3743 (setq buf (set-buffer (get-buffer-create " *message cancel*"))))
3745 (insert "Newsgroups: " newsgroups "\n"
3746 "From: " (message-make-from) "\n"
3747 "Subject: cmsg cancel " message-id "\n"
3748 "Control: cancel " message-id "\n"
3750 (concat "Distribution: " distribution "\n")
3752 mail-header-separator "\n"
3753 message-cancel-message)
3754 (run-hooks 'message-cancel-hook)
3756 (message "Canceling your article...")
3757 (if (let ((message-syntax-checks
3758 'dont-check-for-anything-just-trust-me))
3759 (funcall message-send-news-function))
3760 (message "Canceling your article...done"))
3761 (kill-buffer buf))))))
3764 (defun message-supersede ()
3765 "Start composing a message to supersede the current message.
3766 This is done simply by taking the old article and adding a Supersedes
3767 header line with the old Message-ID."
3769 (let ((cur (current-buffer))
3770 (sender (message-fetch-field "sender"))
3771 (from (message-fetch-field "from")))
3772 ;; Check whether the user owns the article that is to be superseded.
3773 (unless (or (and sender
3776 (downcase (message-make-sender))))
3778 (downcase (cadr (mail-extract-address-components from)))
3779 (downcase (cadr (mail-extract-address-components
3780 (message-make-from))))))
3781 (error "This article is not yours"))
3782 ;; Get a normal message buffer.
3783 (message-pop-to-buffer (message-buffer-name "supersede"))
3784 (insert-buffer-substring cur)
3785 (message-narrow-to-head)
3786 ;; Remove unwanted headers.
3787 (when message-ignored-supersedes-headers
3788 (message-remove-header message-ignored-supersedes-headers t))
3789 (goto-char (point-min))
3790 (if (not (re-search-forward "^Message-ID: " nil t))
3791 (error "No Message-ID in this article")
3792 (replace-match "Supersedes: " t t))
3793 (goto-char (point-max))
3794 (insert mail-header-separator)
3799 (defun message-recover ()
3800 "Reread contents of current buffer from its last auto-save file."
3802 (let ((file-name (make-auto-save-file-name)))
3803 (cond ((save-window-excursion
3804 (if (not (eq system-type 'vax-vms))
3805 (with-output-to-temp-buffer "*Directory*"
3806 (with-current-buffer standard-output
3807 (fundamental-mode)) ; for Emacs 20.4+
3808 (buffer-disable-undo standard-output)
3809 (let ((default-directory "/"))
3811 "ls" nil standard-output nil "-l" file-name))))
3812 (yes-or-no-p (format "Recover auto save file %s? " file-name)))
3813 (let ((buffer-read-only nil))
3815 (insert-file-contents file-name nil)))
3816 (t (error "message-recover cancelled")))))
3818 ;;; Washing Subject:
3820 (defun message-wash-subject (subject)
3821 "Remove junk like \"Re:\", \"(fwd)\", etc. that was added to the subject by previous forwarders, replyers, etc."
3823 (insert-string subject)
3824 (goto-char (point-min))
3825 ;; strip Re/Fwd stuff off the beginning
3826 (while (re-search-forward
3827 "\\([Rr][Ee]:\\|[Ff][Ww][Dd]\\(\\[[0-9]*\\]\\)?:\\|[Ff][Ww]:\\)" nil t)
3830 ;; and gnus-style forwards [foo@bar.com] subject
3831 (goto-char (point-min))
3832 (while (re-search-forward "\\[[^ \t]*\\(@\\|\\.\\)[^ \t]*\\]" nil t)
3836 (goto-char (point-max))
3837 (while (re-search-backward "([Ff][Ww][Dd])" nil t)
3840 ;; and finally, any whitespace that was left-over
3841 (goto-char (point-min))
3842 (while (re-search-forward "^[ \t]+" nil t)
3844 (goto-char (point-max))
3845 (while (re-search-backward "[ \t]+$" nil t)
3850 ;;; Forwarding messages.
3852 (defun message-forward-subject-author-subject (subject)
3853 "Generate a subject for a forwarded message.
3854 The form is: [Source] Subject, where if the original message was mail,
3855 Source is the sender, and if the original message was news, Source is
3856 the list of newsgroups is was posted to."
3858 (or (message-fetch-field
3859 (if (message-news-p) "newsgroups" "from"))
3863 (defun message-forward-subject-fwd (subject)
3864 "Generate a subject for a forwarded message.
3865 The form is: Fwd: Subject, where Subject is the original subject of
3867 (concat "Fwd: " subject))
3869 (defun message-make-forward-subject ()
3870 "Return a Subject header suitable for the message in the current buffer."
3874 (message-narrow-to-head)
3875 (let ((funcs message-make-forward-subject-function)
3876 (subject (if message-wash-forwarded-subjects
3877 (message-wash-subject
3878 (or (message-fetch-field "Subject") ""))
3879 (or (message-fetch-field "Subject") ""))))
3880 ;; Make sure funcs is a list.
3883 (setq funcs (list funcs)))
3884 ;; Apply funcs in order, passing subject generated by previous
3885 ;; func to the next one.
3887 (when (message-functionp (car funcs))
3888 (setq subject (funcall (car funcs) subject)))
3889 (setq funcs (cdr funcs)))
3893 (defun message-forward (&optional news)
3894 "Forward the current message via mail.
3895 Optional NEWS will use news to forward instead of mail."
3897 (let ((cur (current-buffer))
3898 (subject (message-make-forward-subject))
3901 (message-news nil subject)
3902 (message-mail nil subject))
3903 ;; Put point where we want it before inserting the forwarded
3905 (if message-forward-before-signature
3907 (goto-char (point-max)))
3908 (if message-forward-as-mime
3909 (insert "\n\n<#part type=message/rfc822 disposition=inline>\n")
3910 (insert "\n-------------------- Start of forwarded message --------------------\n"))
3913 (mml-insert-buffer cur)
3915 (if message-forward-as-mime
3916 (insert "<#/part>\n")
3917 (insert "\n-------------------- End of forwarded message --------------------\n"))
3918 (when (and (not current-prefix-arg)
3919 message-forward-ignored-headers)
3921 (narrow-to-region b e)
3923 (narrow-to-region (point) (or (search-forward "\n\n" nil t) (point)))
3924 (message-remove-header message-forward-ignored-headers t))))
3925 (message-position-point)))
3928 (defun message-resend (address)
3929 "Resend the current article to ADDRESS."
3931 (list (message-read-from-minibuffer "Resend message to: ")))
3932 (message "Resending message to %s..." address)
3934 (let ((cur (current-buffer))
3936 ;; We first set up a normal mail buffer.
3937 (set-buffer (get-buffer-create " *message resend*"))
3939 (message-setup `((To . ,address)))
3940 ;; Insert our usual headers.
3941 (message-generate-headers '(From Date To))
3942 (message-narrow-to-headers)
3943 ;; Rename them all to "Resent-*".
3944 (while (re-search-forward "^[A-Za-z]" nil t)
3949 (delete-region (point) (point-max))
3951 ;; Insert the message to be resent.
3952 (insert-buffer-substring cur)
3953 (goto-char (point-min))
3954 (search-forward "\n\n")
3957 (narrow-to-region beg (point))
3958 (message-remove-header message-ignored-resent-headers t)
3959 (goto-char (point-max)))
3960 (insert mail-header-separator)
3961 ;; Rename all old ("Also-")Resent headers.
3962 (while (re-search-backward "^\\(Also-\\)*Resent-" beg t)
3965 ;; Quote any "From " lines at the beginning.
3967 (when (looking-at "From ")
3968 (replace-match "X-From-Line: "))
3970 (let ((message-inhibit-body-encoding t)
3971 message-required-mail-headers)
3972 (message-send-mail))
3973 (kill-buffer (current-buffer)))
3974 (message "Resending message to %s...done" address)))
3977 (defun message-bounce ()
3978 "Re-mail the current message.
3979 This only makes sense if the current message is a bounce message than
3980 contains some mail you have written which has been bounced back to
3983 (let ((handles (mm-dissect-buffer t))
3985 (message-pop-to-buffer (message-buffer-name "bounce"))
3986 (if (stringp (car handles))
3987 ;; This is a MIME bounce.
3988 (mm-insert-part (car (last handles)))
3989 ;; This is a non-MIME bounce, so we try to remove things
3991 (mm-insert-part handles)
3993 (goto-char (point-min))
3994 (search-forward "\n\n" nil t)
3995 (or (and (re-search-forward message-unsent-separator nil t)
3997 (re-search-forward "^Return-Path:.*\n" nil t))
3998 ;; We remove everything before the bounced mail.
4001 (if (re-search-forward "^[^ \n\t]+:" nil t)
4005 (message-narrow-to-head)
4006 (message-remove-header message-ignored-bounced-headers t)
4007 (goto-char (point-max))
4008 (insert mail-header-separator))
4009 (message-position-point)))
4012 ;;; Interactive entry points for new message buffers.
4016 (defun message-mail-other-window (&optional to subject)
4017 "Like `message-mail' command, but display mail buffer in another window."
4019 (let ((pop-up-windows t)
4020 (special-display-buffer-names nil)
4021 (special-display-regexps nil)
4022 (same-window-buffer-names nil)
4023 (same-window-regexps nil))
4024 (message-pop-to-buffer (message-buffer-name "mail" to)))
4025 (let ((message-this-is-mail t))
4026 (message-setup `((To . ,(or to "")) (Subject . ,(or subject ""))))))
4029 (defun message-mail-other-frame (&optional to subject)
4030 "Like `message-mail' command, but display mail buffer in another frame."
4032 (let ((pop-up-frames t)
4033 (special-display-buffer-names nil)
4034 (special-display-regexps nil)
4035 (same-window-buffer-names nil)
4036 (same-window-regexps nil))
4037 (message-pop-to-buffer (message-buffer-name "mail" to)))
4038 (let ((message-this-is-mail t))
4039 (message-setup `((To . ,(or to "")) (Subject . ,(or subject ""))))))
4042 (defun message-news-other-window (&optional newsgroups subject)
4043 "Start editing a news article to be sent."
4045 (let ((pop-up-windows t)
4046 (special-display-buffer-names nil)
4047 (special-display-regexps nil)
4048 (same-window-buffer-names nil)
4049 (same-window-regexps nil))
4050 (message-pop-to-buffer (message-buffer-name "news" nil newsgroups)))
4051 (let ((message-this-is-news t))
4052 (message-setup `((Newsgroups . ,(or newsgroups ""))
4053 (Subject . ,(or subject ""))))))
4056 (defun message-news-other-frame (&optional newsgroups subject)
4057 "Start editing a news article to be sent."
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 "news" nil newsgroups)))
4065 (let ((message-this-is-news t))
4066 (message-setup `((Newsgroups . ,(or newsgroups ""))
4067 (Subject . ,(or subject ""))))))
4071 ;; This code should be moved to underline.el (from which it is stolen).
4074 (defun bold-region (start end)
4075 "Bold all nonblank characters in the region.
4076 Works by overstriking characters.
4077 Called from program, takes two arguments START and END
4078 which specify the range to operate on."
4081 (let ((end1 (make-marker)))
4082 (move-marker end1 (max start end))
4083 (goto-char (min start end))
4084 (while (< (point) end1)
4085 (or (looking-at "[_\^@- ]")
4086 (insert (char-after) "\b"))
4087 (forward-char 1)))))
4090 (defun unbold-region (start end)
4091 "Remove all boldness (overstruck characters) in the region.
4092 Called from program, takes two arguments START and END
4093 which specify the range to operate on."
4096 (let ((end1 (make-marker)))
4097 (move-marker end1 (max start end))
4098 (goto-char (min start end))
4099 (while (re-search-forward "\b" end1 t)
4100 (if (eq (char-after) (char-after (- (point) 2)))
4101 (delete-char -2))))))
4103 (defalias 'message-exchange-point-and-mark 'exchange-point-and-mark)
4105 ;; Support for toolbar
4106 (when (string-match "XEmacs\\|Lucid" emacs-version)
4107 (require 'messagexmas))
4109 ;;; Group name completion.
4111 (defvar message-newgroups-header-regexp
4112 "^\\(Newsgroups\\|Followup-To\\|Posted-To\\|Gcc\\):"
4113 "Regexp that match headers that lists groups.")
4115 (defun message-tab ()
4116 "Expand group names in Newsgroups and Followup-To headers.
4117 Do a `tab-to-tab-stop' if not in those headers."
4119 (if (let ((mail-abbrev-mode-regexp message-newgroups-header-regexp))
4120 (mail-abbrev-in-expansion-header-p))
4121 (message-expand-group)
4124 (defvar gnus-active-hashtb)
4125 (defun message-expand-group ()
4126 "Expand the group name under point."
4127 (let* ((b (save-excursion
4132 (skip-chars-forward "^:")
4135 (skip-chars-backward "^, \t\n") (point))))
4136 (completion-ignore-case t)
4137 (string (buffer-substring b (progn (skip-chars-forward "^,\t\n ")
4139 (hashtb (and (boundp 'gnus-active-hashtb) gnus-active-hashtb))
4140 (completions (all-completions string hashtb))
4142 (delete-region b (point))
4144 ((= (length completions) 1)
4145 (if (string= (car completions) string)
4148 (message "Only matching group"))
4149 (insert (car completions))))
4150 ((and (setq comp (try-completion string hashtb))
4151 (not (string= comp string)))
4156 (message "No matching groups")
4157 (save-selected-window
4158 (pop-to-buffer "*Completions*")
4159 (buffer-disable-undo)
4160 (let ((buffer-read-only nil))
4162 (let ((standard-output (current-buffer)))
4163 (display-completion-list (sort completions 'string<)))
4164 (goto-char (point-min))
4165 (delete-region (point) (progn (forward-line 3) (point))))))))))
4169 (defun message-talkative-question (ask question show &rest text)
4170 "Call FUNCTION with argument QUESTION; optionally display TEXT... args.
4171 If SHOW is non-nil, the arguments TEXT... are displayed in a temp buffer.
4172 The following arguments may contain lists of values."
4174 (setq text (message-flatten-list text)))
4175 (save-window-excursion
4177 (with-output-to-temp-buffer " *MESSAGE information message*"
4178 (set-buffer " *MESSAGE information message*")
4179 (fundamental-mode) ; for Emacs 20.4+
4180 (mapcar 'princ text)
4181 (goto-char (point-min))))
4182 (funcall ask question))
4183 (funcall ask question)))
4185 (defun message-flatten-list (list)
4186 "Return a new, flat list that contains all elements of LIST.
4188 \(message-flatten-list '(1 (2 3 (4 5 (6))) 7))
4191 (apply 'append (mapcar 'message-flatten-list list)))
4195 (defun message-generate-new-buffer-clone-locals (name &optional varstr)
4196 "Create and return a buffer with a name based on NAME using generate-new-buffer.
4197 Then clone the local variables and values from the old buffer to the
4198 new one, cloning only the locals having a substring matching the
4200 (let ((oldbuf (current-buffer)))
4202 (set-buffer (generate-new-buffer name))
4203 (message-clone-locals oldbuf varstr)
4206 (defun message-clone-locals (buffer &optional varstr)
4207 "Clone the local variables from BUFFER to the current buffer."
4208 (let ((locals (save-excursion
4210 (buffer-local-variables)))
4211 (regexp "^gnus\\|^nn\\|^message\\|^user-mail-address"))
4214 (when (and (consp local)
4216 (string-match regexp (symbol-name (car local)))
4218 (string-match varstr (symbol-name (car local)))))
4220 (set (make-local-variable (car local))
4224 ;;; Miscellaneous functions
4226 ;; stolen (and renamed) from nnheader.el
4227 (defun message-replace-chars-in-string (string from to)
4228 "Replace characters in STRING from FROM to TO."
4229 (let ((string (substring string 0)) ;Copy string.
4230 (len (length string))
4232 ;; Replace all occurrences of FROM with TO.
4234 (when (= (aref string idx) from)
4235 (aset string idx to))
4236 (setq idx (1+ idx)))
4243 (defvar message-inhibit-body-encoding nil)
4245 (defun message-encode-message-body ()
4246 (unless message-inhibit-body-encoding
4247 (let ((mail-parse-charset (or mail-parse-charset
4248 message-default-charset))
4249 (case-fold-search t)
4250 lines content-type-p)
4253 (narrow-to-region (point) (point-max))
4254 (let ((new (mml-generate-mime)))
4256 (delete-region (point-min) (point-max))
4258 (goto-char (point-min))
4259 (if (eq (aref new 0) ?\n)
4261 (search-forward "\n\n")
4262 (setq lines (buffer-substring (point-min) (1- (point))))
4263 (delete-region (point-min) (point))))))
4265 (message-narrow-to-headers-or-head)
4266 (message-remove-header "Mime-Version")
4267 (goto-char (point-max))
4268 (insert "MIME-Version: 1.0\n")
4271 (setq content-type-p
4272 (re-search-backward "^Content-Type:" nil t)))
4274 (message-narrow-to-headers-or-head)
4275 (message-remove-first-header "Content-Type")
4276 (message-remove-first-header "Content-Transfer-Encoding"))
4277 ;; We always make sure that the message has a Content-Type header.
4278 ;; This is because some broken MTAs and MUAs get awfully confused
4279 ;; when confronted with a message with a MIME-Version header and
4280 ;; without a Content-Type header. For instance, Solaris'
4282 (unless content-type-p
4283 (goto-char (point-min))
4284 (re-search-forward "^MIME-Version:")
4286 (insert "Content-Type: text/plain; charset=us-ascii\n")))))
4288 (defun message-read-from-minibuffer (prompt)
4289 "Read from the minibuffer while providing abbrev expansion."
4290 (if (fboundp 'mail-abbrevs-setup)
4291 (let ((mail-abbrev-mode-regexp "")
4292 (minibuffer-setup-hook 'mail-abbrevs-setup))
4293 (read-from-minibuffer prompt)))
4294 (let ((minibuffer-setup-hook 'mail-abbrev-minibuffer-setup-hook))
4295 (read-string prompt)))
4299 (run-hooks 'message-load-hook)
4302 ;; coding: iso-8859-1
4305 ;;; message.el ends here