1 ;;; message.el --- composing mail and news messages
2 ;; Copyright (C) 1996,97,98 Free Software Foundation, Inc.
4 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
5 ;; Keywords: mail, news
7 ;; This file is part of GNU Emacs.
9 ;; GNU Emacs is free software; you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation; either version 2, or (at your option)
14 ;; GNU Emacs is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; GNU General Public License for more details.
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs; see the file COPYING. If not, write to the
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22 ;; Boston, MA 02111-1307, USA.
26 ;; This mode provides mail-sending facilities from within Emacs. It
27 ;; consists mainly of large chunks of code from the sendmail.el,
28 ;; gnus-msg.el and rnewspost.el files.
32 (eval-when-compile (require 'cl))
38 (if (string-match "XEmacs\\|Lucid" emacs-version)
39 (require 'mail-abbrevs)
40 (require 'mailabbrev))
45 (defgroup message '((user-mail-address custom-variable)
46 (user-full-name custom-variable))
47 "Mail and news message composing."
48 :link '(custom-manual "(message)Top")
52 (put 'user-mail-address 'custom-type 'string)
53 (put 'user-full-name 'custom-type 'string)
55 (defgroup message-various nil
56 "Various Message Variables"
57 :link '(custom-manual "(message)Various Message Variables")
60 (defgroup message-buffers nil
62 :link '(custom-manual "(message)Message Buffers")
65 (defgroup message-sending nil
67 :link '(custom-manual "(message)Sending Variables")
70 (defgroup message-interface nil
72 :link '(custom-manual "(message)Interface")
75 (defgroup message-forwarding nil
77 :link '(custom-manual "(message)Forwarding")
78 :group 'message-interface)
80 (defgroup message-insertion nil
82 :link '(custom-manual "(message)Insertion")
85 (defgroup message-headers nil
87 :link '(custom-manual "(message)Message Headers")
90 (defgroup message-news nil
91 "Composing News Messages"
94 (defgroup message-mail nil
95 "Composing Mail Messages"
98 (defgroup message-faces nil
99 "Faces used for message composing."
103 (defcustom message-directory "~/Mail/"
104 "*Directory from which all other mail file variables are derived."
105 :group 'message-various
108 (defcustom message-max-buffers 10
109 "*How many buffers to keep before starting to kill them off."
110 :group 'message-buffers
113 (defcustom message-send-rename-function nil
114 "Function called to rename the buffer after sending it."
115 :group 'message-buffers
118 (defcustom message-fcc-handler-function 'message-output
119 "*A function called to save outgoing articles.
120 This function will be called with the name of the file to store the
121 article in. The default function is `message-output' which saves in Unix
123 :type '(radio (function-item message-output)
124 (function :tag "Other"))
125 :group 'message-sending)
127 (defcustom message-courtesy-message
128 "The following message is a courtesy copy of an article\nthat has been posted to %s as well.\n\n"
129 "*This is inserted at the start of a mailed copy of a posted message.
130 If the string contains the format spec \"%s\", the Newsgroups
131 the article has been posted to will be inserted there.
132 If this variable is nil, no such courtesy message will be added."
133 :group 'message-sending
136 (defcustom message-ignored-bounced-headers "^\\(Received\\|Return-Path\\):"
137 "*Regexp that matches headers to be removed in resent bounced mail."
138 :group 'message-interface
142 (defcustom message-from-style 'default
143 "*Specifies how \"From\" headers look.
145 If `nil', they contain just the return address like:
147 If `parens', they look like:
148 king@grassland.com (Elvis Parsley)
149 If `angles', they look like:
150 Elvis Parsley <king@grassland.com>
152 Otherwise, most addresses look like `angles', but they look like
153 `parens' if `angles' would need quoting and `parens' would not."
154 :type '(choice (const :tag "simple" nil)
158 :group 'message-headers)
160 (defcustom message-syntax-checks nil
161 ; Guess this one shouldn't be easy to customize...
162 "*Controls what syntax checks should not be performed on outgoing posts.
163 To disable checking of long signatures, for instance, add
164 `(signature . disabled)' to this list.
166 Don't touch this variable unless you really know what you're doing.
168 Checks include subject-cmsg multiple-headers sendsys message-id from
169 long-lines control-chars size new-text redirected-followup signature
170 approved sender empty empty-headers message-id from subject
171 shorten-followup-to existing-newsgroups buffer-file-name unchanged."
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:\\|^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-elipsis "\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 t
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)
255 (defcustom message-kill-buffer-on-exit nil
256 "*Non-nil means that the message buffer will be killed after sending a message."
257 :group 'message-buffers
260 (defvar gnus-local-organization)
261 (defcustom message-user-organization
262 (or (and (boundp 'gnus-local-organization)
263 (stringp gnus-local-organization)
264 gnus-local-organization)
265 (getenv "ORGANIZATION")
267 "*String to be used as an Organization header.
268 If t, use `message-user-organization-file'."
269 :group 'message-headers
270 :type '(choice string
271 (const :tag "consult file" t)))
274 (defcustom message-user-organization-file "/usr/lib/news/organization"
275 "*Local news organization file."
277 :group 'message-headers)
279 (defcustom message-forward-start-separator
280 "------- Start of forwarded message -------\n"
281 "*Delimiter inserted before forwarded messages."
282 :group 'message-forwarding
285 (defcustom message-forward-end-separator
286 "------- End of forwarded message -------\n"
287 "*Delimiter inserted after forwarded messages."
288 :group 'message-forwarding
291 (defcustom message-signature-before-forwarded-message t
292 "*If non-nil, put the signature before any included forwarded message."
293 :group 'message-forwarding
296 (defcustom message-included-forward-headers
297 "^From:\\|^Newsgroups:\\|^Subject:\\|^Date:\\|^Followup-To:\\|^Reply-To:\\|^Organization:\\|^Summary:\\|^Keywords:\\|^To:\\|^Cc:\\|^Posted-To:\\|^Mail-Copies-To:\\|^Apparently-To:\\|^Gnus-Warning:\\|^Resent-\\|^Message-ID:\\|^References:\\|^Content-Transfer-Encoding:\\|^Content-Type:\\|^Mime-Version:"
298 "*Regexp matching headers to be included in forwarded messages."
299 :group 'message-forwarding
302 (defcustom message-make-forward-subject-function
303 'message-forward-subject-author-subject
304 "*A list of functions that are called to generate a subject header for forwarded messages.
305 The subject generated by the previous function is passed into each
308 The provided functions are:
310 * message-forward-subject-author-subject (Source of article (author or
311 newsgroup)), in brackets followed by the subject
312 * message-forward-subject-fwd (Subject of article with 'Fwd:' prepended
314 :group 'message-forwarding
315 :type '(radio (function-item message-forward-subject-author-subject)
316 (function-item message-forward-subject-fwd)))
318 (defcustom message-wash-forwarded-subjects nil
319 "*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."
320 :group 'message-forwarding
323 (defcustom message-ignored-resent-headers "^Return-receipt"
324 "*All headers that match this regexp will be deleted when resending a message."
325 :group 'message-interface
328 (defcustom message-ignored-cited-headers "."
329 "*Delete these headers from the messages you yank."
330 :group 'message-insertion
333 (defcustom message-cancel-message "I am canceling my own article."
334 "Message to be inserted in the cancel message."
335 :group 'message-interface
338 ;; Useful to set in site-init.el
340 (defcustom message-send-mail-function 'message-send-mail-with-sendmail
341 "Function to call to send the current buffer as mail.
342 The headers should be delimited by a line whose contents match the
343 variable `mail-header-separator'.
345 Legal values include `message-send-mail-with-sendmail' (the default),
346 `message-send-mail-with-mh', `message-send-mail-with-qmail' and
348 :type '(radio (function-item message-send-mail-with-sendmail)
349 (function-item message-send-mail-with-mh)
350 (function-item message-send-mail-with-qmail)
351 (function-item smtpmail-send-it)
352 (function :tag "Other"))
353 :group 'message-sending
354 :group 'message-mail)
356 (defcustom message-send-news-function 'message-send-news
357 "Function to call to send the current buffer as news.
358 The headers should be delimited by a line whose contents match the
359 variable `mail-header-separator'."
360 :group 'message-sending
364 (defcustom message-reply-to-function nil
365 "Function that should return a list of headers.
366 This function should pick out addresses from the To, Cc, and From headers
367 and respond with new To and Cc headers."
368 :group 'message-interface
371 (defcustom message-wide-reply-to-function nil
372 "Function that should return a list of headers.
373 This function should pick out addresses from the To, Cc, and From headers
374 and respond with new To and Cc headers."
375 :group 'message-interface
378 (defcustom message-followup-to-function nil
379 "Function that should return a list of headers.
380 This function should pick out addresses from the To, Cc, and From headers
381 and respond with new To and Cc headers."
382 :group 'message-interface
385 (defcustom message-use-followup-to 'ask
386 "*Specifies what to do with Followup-To header.
387 If nil, always ignore the header. If it is t, use its value, but
388 query before using the \"poster\" value. If it is the symbol `ask',
389 always query the user whether to use the value. If it is the symbol
390 `use', always use the value."
391 :group 'message-interface
392 :type '(choice (const :tag "ignore" nil)
396 ;; stuff relating to broken sendmail in MMDF
397 (defcustom message-sendmail-f-is-evil nil
398 "*Non-nil means that \"-f username\" should not be added to the sendmail
399 command line, because it is even more evil than leaving it out."
400 :group 'message-sending
403 ;; qmail-related stuff
404 (defcustom message-qmail-inject-program "/var/qmail/bin/qmail-inject"
405 "Location of the qmail-inject program."
406 :group 'message-sending
409 (defcustom message-qmail-inject-args nil
410 "Arguments passed to qmail-inject programs.
411 This should be a list of strings, one string for each argument.
413 For e.g., if you wish to set the envelope sender address so that bounces
414 go to the right place or to deal with listserv's usage of that address, you
415 might set this variable to '(\"-f\" \"you@some.where\")."
416 :group 'message-sending
417 :type '(repeat string))
419 (defvar gnus-post-method)
420 (defvar gnus-select-method)
421 (defcustom message-post-method
422 (cond ((and (boundp 'gnus-post-method)
423 (listp gnus-post-method)
426 ((boundp 'gnus-select-method)
429 "*Method used to post news.
430 Note that when posting from inside Gnus, for instance, this
431 variable isn't used."
433 :group 'message-sending
434 ;; This should be the `gnus-select-method' widget, but that might
435 ;; create a dependence to `gnus.el'.
438 (defcustom message-generate-headers-first nil
439 "*If non-nil, generate all possible headers before composing."
440 :group 'message-headers
443 (defcustom message-setup-hook nil
444 "Normal hook, run each time a new outgoing message is initialized.
445 The function `message-setup' runs this hook."
446 :group 'message-various
449 (defcustom message-signature-setup-hook nil
450 "Normal hook, run each time a new outgoing message is initialized.
451 It is run after the headers have been inserted and before
452 the signature is inserted."
453 :group 'message-various
456 (defcustom message-mode-hook nil
457 "Hook run in message mode buffers."
458 :group 'message-various
461 (defcustom message-header-hook nil
462 "Hook run in a message mode buffer narrowed to the headers."
463 :group 'message-various
466 (defcustom message-header-setup-hook nil
467 "Hook called narrowed to the headers when setting up a message buffer."
468 :group 'message-various
472 (defcustom message-citation-line-function 'message-insert-citation-line
473 "*Function called to insert the \"Whomever writes:\" line."
475 :group 'message-insertion)
478 (defcustom message-yank-prefix "> "
479 "*Prefix inserted on the lines of yanked messages.
480 nil means use indentation."
482 :group 'message-insertion)
484 (defcustom message-indentation-spaces 3
485 "*Number of spaces to insert at the beginning of each cited line.
486 Used by `message-yank-original' via `message-yank-cite'."
487 :group 'message-insertion
491 (defcustom message-cite-function 'message-cite-original
492 "*Function for citing an original message.
493 Predefined functions include `message-cite-original' and
494 `message-cite-original-without-signature'.
495 Note that `message-cite-original' uses `mail-citation-hook' if that is non-nil."
496 :type '(radio (function-item message-cite-original)
497 (function-item sc-cite-original)
498 (function :tag "Other"))
499 :group 'message-insertion)
502 (defcustom message-indent-citation-function 'message-indent-citation
503 "*Function for modifying a citation just inserted in the mail buffer.
504 This can also be a list of functions. Each function can find the
505 citation between (point) and (mark t). And each function should leave
506 point and mark around the citation text as modified."
508 :group 'message-insertion)
510 (defvar message-abbrevs-loaded nil)
513 (defcustom message-signature t
514 "*String to be inserted at the end of the message buffer.
515 If t, the `message-signature-file' file will be inserted instead.
516 If a function, the result from the function will be used instead.
517 If a form, the result from the form will be used instead."
519 :group 'message-insertion)
522 (defcustom message-signature-file "~/.signature"
523 "*File containing the text inserted at end of message buffer."
525 :group 'message-insertion)
527 (defcustom message-distribution-function nil
528 "*Function called to return a Distribution header."
530 :group 'message-headers
533 (defcustom message-expires 14
534 "Number of days before your article expires."
536 :group 'message-headers
537 :link '(custom-manual "(message)News Headers")
540 (defcustom message-user-path nil
541 "If nil, use the NNTP server name in the Path header.
542 If stringp, use this; if non-nil, use no host name (user name only)."
544 :group 'message-headers
545 :link '(custom-manual "(message)News Headers")
546 :type '(choice (const :tag "nntp" nil)
548 (sexp :tag "none" :format "%t" t)))
550 (defvar message-reply-buffer nil)
551 (defvar message-reply-headers nil)
552 (defvar message-newsreader nil)
553 (defvar message-mailer nil)
554 (defvar message-sent-message-via nil)
555 (defvar message-checksum nil)
556 (defvar message-send-actions nil
557 "A list of actions to be performed upon successful sending of a message.")
558 (defvar message-exit-actions nil
559 "A list of actions to be performed upon exiting after sending a message.")
560 (defvar message-kill-actions nil
561 "A list of actions to be performed before killing a message buffer.")
562 (defvar message-postpone-actions nil
563 "A list of actions to be performed after postponing a message.")
565 (define-widget 'message-header-lines 'text
566 "All header lines must be LFD terminated."
569 :error "All header lines must be newline terminated")
571 (defcustom message-default-headers ""
572 "*A string containing header lines to be inserted in outgoing messages.
573 It is inserted before you edit the message, so you can edit or delete
575 :group 'message-headers
576 :type 'message-header-lines)
578 (defcustom message-default-mail-headers ""
579 "*A string of header lines to be inserted in outgoing mails."
580 :group 'message-headers
582 :type 'message-header-lines)
584 (defcustom message-default-news-headers ""
585 "*A string of header lines to be inserted in outgoing news
587 :group 'message-headers
589 :type 'message-header-lines)
591 ;; Note: could use /usr/ucb/mail instead of sendmail;
592 ;; options -t, and -v if not interactive.
593 (defcustom message-mailer-swallows-blank-line
594 (if (and (string-match "sparc-sun-sunos\\(\\'\\|[^5]\\)"
595 system-configuration)
596 (file-readable-p "/etc/sendmail.cf")
597 (let ((buffer (get-buffer-create " *temp*")))
601 (insert-file-contents "/etc/sendmail.cf")
602 (goto-char (point-min))
603 (let ((case-fold-search nil))
604 (re-search-forward "^OR\\>" nil t)))
605 (kill-buffer buffer))))
606 ;; According to RFC822, "The field-name must be composed of printable
607 ;; ASCII characters (i. e., characters that have decimal values between
608 ;; 33 and 126, except colon)", i. e., any chars except ctl chars,
610 '(looking-at "[ \t]\\|[][!\"#$%&'()*+,-./0-9;<=>?@A-Z\\\\^_`a-z{|}~]+:"))
611 "*Set this non-nil if the system's mailer runs the header and body together.
612 \(This problem exists on Sunos 4 when sendmail is run in remote mode.)
613 The value should be an expression to test whether the problem will
615 :group 'message-sending
618 ;; Ignore errors in case this is used in Emacs 19.
619 ;; Don't use ignore-errors because this is copied into loaddefs.el.
622 (define-mail-user-agent 'message-user-agent
623 'message-mail 'message-send-and-exit
624 'message-kill-buffer 'message-send-hook)
627 (defvar message-mh-deletable-headers '(Message-ID Date Lines Sender)
628 "If non-nil, delete the deletable headers before feeding to mh.")
630 (defvar message-send-method-alist
631 '((news message-news-p message-send-via-news)
632 (mail message-mail-p message-send-via-mail))
633 "Alist of ways to send outgoing messages.
634 Each element has the form
636 \(TYPE PREDICATE FUNCTION)
638 where TYPE is a symbol that names the method; PREDICATE is a function
639 called without any parameters to determine whether the message is
640 a message of type TYPE; and FUNCTION is a function to be called if
641 PREDICATE returns non-nil. FUNCTION is called with one parameter --
644 (defvar message-mail-alias-type 'abbrev
645 "*What alias expansion type to use in Message buffers.
646 The default is `abbrev', which uses mailabbrev. nil switches
649 (defcustom message-autosave-directory
650 (nnheader-concat message-directory "drafts/")
651 "*Directory where Message autosaves buffers if Gnus isn't running.
652 If nil, Message won't autosave."
653 :group 'message-buffers
656 ;;; Internal variables.
657 ;;; Well, not really internal.
659 (defvar message-mode-syntax-table
660 (let ((table (copy-syntax-table text-mode-syntax-table)))
661 (modify-syntax-entry ?% ". " table)
663 "Syntax table used while in Message mode.")
665 (defvar message-mode-abbrev-table text-mode-abbrev-table
666 "Abbrev table used in Message mode buffers.
667 Defaults to `text-mode-abbrev-table'.")
668 (defgroup message-headers nil
670 :link '(custom-manual "(message)Variables")
673 (defface message-header-to-face
676 (:foreground "green2" :bold t))
679 (:foreground "MidnightBlue" :bold t))
681 (:bold t :italic t)))
682 "Face used for displaying From headers."
683 :group 'message-faces)
685 (defface message-header-cc-face
688 (:foreground "green4" :bold t))
691 (:foreground "MidnightBlue"))
694 "Face used for displaying Cc headers."
695 :group 'message-faces)
697 (defface message-header-subject-face
700 (:foreground "green3"))
703 (:foreground "navy blue" :bold t))
706 "Face used for displaying subject headers."
707 :group 'message-faces)
709 (defface message-header-newsgroups-face
712 (:foreground "yellow" :bold t :italic t))
715 (:foreground "blue4" :bold t :italic t))
717 (:bold t :italic t)))
718 "Face used for displaying newsgroups headers."
719 :group 'message-faces)
721 (defface message-header-other-face
724 (:foreground "#b00000"))
727 (:foreground "steel blue"))
729 (:bold t :italic t)))
730 "Face used for displaying newsgroups headers."
731 :group 'message-faces)
733 (defface message-header-name-face
736 (:foreground "DarkGreen"))
739 (:foreground "cornflower blue"))
742 "Face used for displaying header names."
743 :group 'message-faces)
745 (defface message-header-xheader-face
748 (:foreground "blue"))
751 (:foreground "blue"))
754 "Face used for displaying X-Header headers."
755 :group 'message-faces)
757 (defface message-separator-face
760 (:foreground "blue3"))
763 (:foreground "brown"))
766 "Face used for displaying the separator."
767 :group 'message-faces)
769 (defface message-cited-text-face
778 "Face used for displaying cited text names."
779 :group 'message-faces)
781 (defvar message-font-lock-keywords
782 (let* ((cite-prefix "A-Za-z")
783 (cite-suffix (concat cite-prefix "0-9_.@-"))
784 (content "[ \t]*\\(.+\\(\n[ \t].*\\)*\\)"))
785 `((,(concat "^\\([Tt]o:\\)" content)
786 (1 'message-header-name-face)
787 (2 'message-header-to-face nil t))
788 (,(concat "^\\(^[GBF]?[Cc][Cc]:\\|^[Rr]eply-[Tt]o:\\)" content)
789 (1 'message-header-name-face)
790 (2 'message-header-cc-face nil t))
791 (,(concat "^\\([Ss]ubject:\\)" content)
792 (1 'message-header-name-face)
793 (2 'message-header-subject-face nil t))
794 (,(concat "^\\([Nn]ewsgroups:\\|Followup-[Tt]o:\\)" content)
795 (1 'message-header-name-face)
796 (2 'message-header-newsgroups-face nil t))
797 (,(concat "^\\([A-Z][^: \n\t]+:\\)" content)
798 (1 'message-header-name-face)
799 (2 'message-header-other-face nil t))
800 (,(concat "^\\(X-[A-Za-z0-9-]+\\|In-Reply-To\\):" content)
801 (1 'message-header-name-face)
802 (2 'message-header-name-face))
803 ,@(if (and mail-header-separator
804 (not (equal mail-header-separator "")))
805 `((,(concat "^\\(" (regexp-quote mail-header-separator) "\\)$")
806 1 'message-separator-face))
809 "\\([" cite-prefix "]+[" cite-suffix "]*\\)?"
811 (0 'message-cited-text-face))))
812 "Additional expressions to highlight in Message mode.")
814 ;; XEmacs does it like this. For Emacs, we have to set the
815 ;; `font-lock-defaults' buffer-local variable.
816 (put 'message-mode 'font-lock-defaults '(message-font-lock-keywords t))
818 (defvar message-face-alist
819 '((bold . bold-region)
820 (underline . underline-region)
821 (default . (lambda (b e)
823 (ununderline-region b e))))
824 "Alist of mail and news faces for facemenu.
825 The cdr of ech entry is a function for applying the face to a region.")
827 (defcustom message-send-hook nil
828 "Hook run before sending messages."
829 :group 'message-various
830 :options '(ispell-message)
833 (defcustom message-send-mail-hook nil
834 "Hook run before sending mail messages."
835 :group 'message-various
838 (defcustom message-send-news-hook nil
839 "Hook run before sending news messages."
840 :group 'message-various
843 (defcustom message-sent-hook nil
844 "Hook run after sending messages."
845 :group 'message-various
848 (defvar message-send-coding-system 'binary
849 "Coding system to encode outgoing mail.")
851 ;;; Internal variables.
853 (defvar message-default-charset nil)
854 (defvar message-buffer-list nil)
855 (defvar message-this-is-news nil)
856 (defvar message-this-is-mail nil)
857 (defvar message-draft-article nil)
859 ;; Byte-compiler warning
860 (defvar gnus-active-hashtb)
861 (defvar gnus-read-active-file)
863 ;;; Regexp matching the delimiter of messages in UNIX mail format
864 ;;; (UNIX From lines), minus the initial ^. It should be a copy
865 ;;; of rmail.el's rmail-unix-mail-delimiter.
866 (defvar message-unix-mail-delimiter
867 (let ((time-zone-regexp
868 (concat "\\([A-Z]?[A-Z]?[A-Z][A-Z]\\( DST\\)?"
869 "\\|[-+]?[0-9][0-9][0-9][0-9]"
875 ;; Many things can happen to an RFC 822 mailbox before it is put into
876 ;; a `From' line. The leading phrase can be stripped, e.g.
877 ;; `Joe <@w.x:joe@y.z>' -> `<@w.x:joe@y.z>'. The <> can be stripped, e.g.
878 ;; `<@x.y:joe@y.z>' -> `@x.y:joe@y.z'. Everything starting with a CRLF
879 ;; can be removed, e.g.
880 ;; From: joe@y.z (Joe K
882 ;; can yield `From joe@y.z (Joe K Fri Mar 22 08:11:15 1996', and
885 ;; can yield `From Joe User Fri Mar 22 08:11:15 1996'.
886 ;; The mailbox can be removed or be replaced by white space, e.g.
887 ;; From: "Joe User"{space}{tab}
889 ;; can yield `From {space}{tab} Fri Mar 22 08:11:15 1996',
890 ;; where {space} and {tab} represent the Ascii space and tab characters.
891 ;; We want to match the results of any of these manglings.
892 ;; The following regexp rejects names whose first characters are
893 ;; obviously bogus, but after that anything goes.
894 "\\([^\0-\b\n-\r\^?].*\\)? "
896 ;; The time the message was sent.
897 "\\([^\0-\r \^?]+\\) +" ; day of the week
898 "\\([^\0-\r \^?]+\\) +" ; month
899 "\\([0-3]?[0-9]\\) +" ; day of month
900 "\\([0-2][0-9]:[0-5][0-9]\\(:[0-6][0-9]\\)?\\) *" ; time of day
902 ;; Perhaps a time zone, specified by an abbreviation, or by a
907 " \\([0-9][0-9]+\\) *"
909 ;; On some systems the time zone can appear after the year, too.
913 "\\(remote from .*\\)?"
916 "Regexp matching the delimiter of messages in UNIX mail format.")
918 (defvar message-unsent-separator
919 (concat "^ *---+ +Unsent message follows +---+ *$\\|"
920 "^ *---+ +Returned message +---+ *$\\|"
921 "^Start of returned message$\\|"
922 "^ *---+ +Original message +---+ *$\\|"
923 "^ *--+ +begin message +--+ *$\\|"
924 "^ *---+ +Original message follows +---+ *$\\|"
925 "^|? *---+ +Message text follows: +---+ *|?$")
926 "A regexp that matches the separator before the text of a failed message.")
928 (defvar message-header-format-alist
930 (To . message-fill-address)
931 (Cc . message-fill-address)
942 (References . message-shorten-references)
944 "Alist used for formatting headers.")
947 (autoload 'message-setup-toolbar "messagexmas")
948 (autoload 'mh-new-draft-name "mh-comp")
949 (autoload 'mh-send-letter "mh-comp")
950 (autoload 'gnus-point-at-eol "gnus-util")
951 (autoload 'gnus-point-at-bol "gnus-util")
952 (autoload 'gnus-output-to-mail "gnus-util")
953 (autoload 'mail-abbrev-in-expansion-header-p "mailabbrev")
954 (autoload 'nndraft-request-associate-buffer "nndraft")
955 (autoload 'nndraft-request-expire-articles "nndraft")
956 (autoload 'gnus-open-server "gnus-int")
957 (autoload 'gnus-request-post "gnus-int")
958 (autoload 'gnus-alive-p "gnus-util")
959 (autoload 'rmail-output "rmail"))
964 ;;; Utility functions.
967 (defmacro message-y-or-n-p (question show &rest text)
968 "Ask QUESTION, displaying the rest of the arguments in a temp. buffer if SHOW"
969 `(message-talkative-question 'y-or-n-p ,question ,show ,@text))
971 ;; Delete the current line (and the next N lines.);
972 (defmacro message-delete-line (&optional n)
973 `(delete-region (progn (beginning-of-line) (point))
974 (progn (forward-line ,(or n 1)) (point))))
976 (defun message-tokenize-header (header &optional separator)
977 "Split HEADER into a list of header elements.
978 \",\" is used as the separator."
981 (let ((regexp (format "[%s]+" (or separator ",")))
986 (message-set-work-buffer)
988 (goto-char (point-min))
993 (cond ((and (> (point) beg)
995 (and (looking-at regexp)
998 (push (buffer-substring beg (point)) elems)
999 (setq beg (match-end 0)))
1000 ((= (following-char) ?\")
1001 (setq quoted (not quoted)))
1002 ((and (= (following-char) ?\()
1005 ((and (= (following-char) ?\))
1008 (nreverse elems)))))
1010 (defun message-mail-file-mbox-p (file)
1011 "Say whether FILE looks like a Unix mbox file."
1012 (when (and (file-exists-p file)
1013 (file-readable-p file)
1014 (file-regular-p file))
1016 (nnheader-insert-file-contents file)
1017 (goto-char (point-min))
1018 (looking-at message-unix-mail-delimiter))))
1020 (defun message-fetch-field (header &optional not-all)
1021 "The same as `mail-fetch-field', only remove all newlines."
1022 (let* ((inhibit-point-motion-hooks t)
1023 (value (mail-fetch-field header nil (not not-all))))
1025 (nnheader-replace-chars-in-string value ?\n ? ))))
1027 (defun message-narrow-to-field ()
1028 "Narrow the buffer to the header on the current line."
1034 (if (re-search-forward "^[^ \n\t]" nil t)
1039 (goto-char (point-min)))
1041 (defun message-add-header (&rest headers)
1042 "Add the HEADERS to the message header, skipping those already present."
1045 (unless (string-match "^\\([^:]+\\):[ \t]*[^ \t]" (car headers))
1046 (error "Invalid header `%s'" (car headers)))
1047 (setq hclean (match-string 1 (car headers)))
1049 (message-narrow-to-headers)
1050 (unless (re-search-forward (concat "^" (regexp-quote hclean) ":") nil t)
1051 (insert (car headers) ?\n))))
1052 (setq headers (cdr headers))))
1054 (defun message-fetch-reply-field (header)
1055 "Fetch FIELD from the message we're replying to."
1056 (when (and message-reply-buffer
1057 (buffer-name message-reply-buffer))
1059 (set-buffer message-reply-buffer)
1060 (message-fetch-field header))))
1062 (defun message-set-work-buffer ()
1063 (if (get-buffer " *message work*")
1065 (set-buffer " *message work*")
1067 (set-buffer (get-buffer-create " *message work*"))
1068 (kill-all-local-variables)
1069 (mm-enable-multibyte)))
1071 (defun message-functionp (form)
1072 "Return non-nil if FORM is funcallable."
1073 (or (and (symbolp form) (fboundp form))
1074 (and (listp form) (eq (car form) 'lambda))
1075 (byte-code-function-p form)))
1077 (defun message-strip-subject-re (subject)
1078 "Remove \"Re:\" from subject lines."
1079 (if (string-match message-subject-re-regexp subject)
1080 (substring subject (match-end 0))
1083 (defun message-remove-header (header &optional is-regexp first reverse)
1084 "Remove HEADER in the narrowed buffer.
1085 If REGEXP, HEADER is a regular expression.
1086 If FIRST, only remove the first instance of the header.
1087 Return the number of headers removed."
1088 (goto-char (point-min))
1089 (let ((regexp (if is-regexp header (concat "^" (regexp-quote header) ":")))
1091 (case-fold-search t)
1093 (while (and (not (eobp))
1096 (not (looking-at regexp))
1097 (looking-at regexp))
1104 ;; There might be a continuation header, so we have to search
1105 ;; until we find a new non-continuation line.
1108 (if (re-search-forward "^[^ \t]" nil t)
1109 (goto-char (match-beginning 0))
1112 (if (re-search-forward "^[^ \t]" nil t)
1113 (goto-char (match-beginning 0))
1117 (defun message-narrow-to-headers ()
1118 "Narrow the buffer to the head of the message."
1121 (goto-char (point-min))
1122 (if (re-search-forward
1123 (concat "^" (regexp-quote mail-header-separator) "\n") nil t)
1126 (goto-char (point-min)))
1128 (defun message-narrow-to-head ()
1129 "Narrow the buffer to the head of the message.
1130 Point is left at the beginning of the narrowed-to region."
1133 (goto-char (point-min))
1134 (if (search-forward "\n\n" nil 1)
1137 (goto-char (point-min)))
1139 (defun message-narrow-to-headers-or-head ()
1140 "Narrow the buffer to the head of the message."
1143 (goto-char (point-min))
1146 (concat "^" (regexp-quote mail-header-separator) "\n") nil t)
1147 (match-beginning 0))
1148 ((search-forward "\n\n" nil t)
1152 (goto-char (point-min)))
1154 (defun message-news-p ()
1155 "Say whether the current buffer contains a news message."
1156 (and (not message-this-is-mail)
1157 (or message-this-is-news
1160 (message-narrow-to-headers)
1161 (and (message-fetch-field "newsgroups")
1162 (not (message-fetch-field "posted-to"))))))))
1164 (defun message-mail-p ()
1165 "Say whether the current buffer contains a mail message."
1166 (and (not message-this-is-news)
1167 (or message-this-is-mail
1170 (message-narrow-to-headers)
1171 (or (message-fetch-field "to")
1172 (message-fetch-field "cc")
1173 (message-fetch-field "bcc")))))))
1175 (defun message-next-header ()
1176 "Go to the beginning of the next header."
1178 (or (eobp) (forward-char 1))
1179 (not (if (re-search-forward "^[^ \t]" nil t)
1181 (goto-char (point-max)))))
1183 (defun message-sort-headers-1 ()
1184 "Sort the buffer as headers using `message-rank' text props."
1185 (goto-char (point-min))
1187 nil 'message-next-header
1189 (message-next-header)
1193 (or (get-text-property (point) 'message-rank)
1196 (defun message-sort-headers ()
1197 "Sort the headers of the current message according to `message-header-format-alist'."
1201 (let ((max (1+ (length message-header-format-alist)))
1203 (message-narrow-to-headers)
1204 (while (re-search-forward "^[^ \n]+:" nil t)
1206 (match-beginning 0) (1+ (match-beginning 0))
1208 (if (setq rank (length (memq (assq (intern (buffer-substring
1210 (1- (match-end 0))))
1211 message-header-format-alist)
1212 message-header-format-alist)))
1215 (message-sort-headers-1))))
1225 (defvar message-mode-map nil)
1227 (unless message-mode-map
1228 (setq message-mode-map (copy-keymap text-mode-map))
1229 (define-key message-mode-map "\C-c?" 'describe-mode)
1231 (define-key message-mode-map "\C-c\C-f\C-t" 'message-goto-to)
1232 (define-key message-mode-map "\C-c\C-f\C-b" 'message-goto-bcc)
1233 (define-key message-mode-map "\C-c\C-f\C-w" 'message-goto-fcc)
1234 (define-key message-mode-map "\C-c\C-f\C-c" 'message-goto-cc)
1235 (define-key message-mode-map "\C-c\C-f\C-s" 'message-goto-subject)
1236 (define-key message-mode-map "\C-c\C-f\C-r" 'message-goto-reply-to)
1237 (define-key message-mode-map "\C-c\C-f\C-n" 'message-goto-newsgroups)
1238 (define-key message-mode-map "\C-c\C-f\C-d" 'message-goto-distribution)
1239 (define-key message-mode-map "\C-c\C-f\C-f" 'message-goto-followup-to)
1240 (define-key message-mode-map "\C-c\C-f\C-k" 'message-goto-keywords)
1241 (define-key message-mode-map "\C-c\C-f\C-u" 'message-goto-summary)
1242 (define-key message-mode-map "\C-c\C-b" 'message-goto-body)
1243 (define-key message-mode-map "\C-c\C-i" 'message-goto-signature)
1245 (define-key message-mode-map "\C-c\C-t" 'message-insert-to)
1246 (define-key message-mode-map "\C-c\C-n" 'message-insert-newsgroups)
1248 (define-key message-mode-map "\C-c\C-y" 'message-yank-original)
1249 (define-key message-mode-map "\C-c\C-q" 'message-fill-yanked-message)
1250 (define-key message-mode-map "\C-c\C-w" 'message-insert-signature)
1251 (define-key message-mode-map "\C-c\C-r" 'message-caesar-buffer-body)
1252 (define-key message-mode-map "\C-c\C-o" 'message-sort-headers)
1253 (define-key message-mode-map "\C-c\M-r" 'message-rename-buffer)
1255 (define-key message-mode-map "\C-c\C-c" 'message-send-and-exit)
1256 (define-key message-mode-map "\C-c\C-s" 'message-send)
1257 (define-key message-mode-map "\C-c\C-k" 'message-kill-buffer)
1258 (define-key message-mode-map "\C-c\C-d" 'message-dont-send)
1260 (define-key message-mode-map "\C-c\C-e" 'message-elide-region)
1261 (define-key message-mode-map "\C-c\C-v" 'message-delete-not-region)
1262 (define-key message-mode-map "\C-c\C-z" 'message-kill-to-signature)
1263 (define-key message-mode-map "\M-\r" 'message-newline-and-reformat)
1265 (define-key message-mode-map "\t" 'message-tab))
1268 message-mode-menu message-mode-map "Message Menu."
1270 ["Sort Headers" message-sort-headers t]
1271 ["Yank Original" message-yank-original t]
1272 ["Fill Yanked Message" message-fill-yanked-message t]
1273 ["Insert Signature" message-insert-signature t]
1274 ["Caesar (rot13) Message" message-caesar-buffer-body t]
1275 ["Caesar (rot13) Region" message-caesar-region (mark t)]
1276 ["Elide Region" message-elide-region (mark t)]
1277 ["Delete Outside Region" message-delete-not-region (mark t)]
1278 ["Kill To Signature" message-kill-to-signature t]
1279 ["Newline and Reformat" message-newline-and-reformat t]
1280 ["Rename buffer" message-rename-buffer t]
1281 ["Spellcheck" ispell-message t]
1283 ["Send Message" message-send-and-exit t]
1284 ["Abort Message" message-dont-send t]
1285 ["Kill Message" message-kill-buffer t]))
1288 message-mode-field-menu message-mode-map ""
1290 ["Fetch To" message-insert-to t]
1291 ["Fetch Newsgroups" message-insert-newsgroups t]
1293 ["To" message-goto-to t]
1294 ["Subject" message-goto-subject t]
1295 ["Cc" message-goto-cc t]
1296 ["Reply-To" message-goto-reply-to t]
1297 ["Summary" message-goto-summary t]
1298 ["Keywords" message-goto-keywords t]
1299 ["Newsgroups" message-goto-newsgroups t]
1300 ["Followup-To" message-goto-followup-to t]
1301 ["Distribution" message-goto-distribution t]
1302 ["Body" message-goto-body t]
1303 ["Signature" message-goto-signature t]))
1305 (defvar facemenu-add-face-function)
1306 (defvar facemenu-remove-face-function)
1309 (defun message-mode ()
1310 "Major mode for editing mail and news to be sent.
1311 Like Text Mode but with these additional commands:
1312 C-c C-s message-send (send the message) C-c C-c message-send-and-exit
1313 C-c C-f move to a header field (and create it if there isn't):
1314 C-c C-f C-t move to To C-c C-f C-s move to Subject
1315 C-c C-f C-c move to Cc C-c C-f C-b move to Bcc
1316 C-c C-f C-w move to Fcc C-c C-f C-r move to Reply-To
1317 C-c C-f C-u move to Summary C-c C-f C-n move to Newsgroups
1318 C-c C-f C-k move to Keywords C-c C-f C-d move to Distribution
1319 C-c C-f C-f move to Followup-To
1320 C-c C-t message-insert-to (add a To header to a news followup)
1321 C-c C-n message-insert-newsgroups (add a Newsgroup header to a news reply)
1322 C-c C-b message-goto-body (move to beginning of message text).
1323 C-c C-i message-goto-signature (move to the beginning of the signature).
1324 C-c C-w message-insert-signature (insert `message-signature-file' file).
1325 C-c C-y message-yank-original (insert current message, if any).
1326 C-c C-q message-fill-yanked-message (fill what was yanked).
1327 C-c C-e message-elide-region (elide the text between point and mark).
1328 C-c C-z message-kill-to-signature (kill the text up to the signature).
1329 C-c C-r message-caesar-buffer-body (rot13 the message body)."
1331 (kill-all-local-variables)
1332 (make-local-variable 'message-reply-buffer)
1333 (setq message-reply-buffer nil)
1334 (make-local-variable 'message-send-actions)
1335 (make-local-variable 'message-exit-actions)
1336 (make-local-variable 'message-kill-actions)
1337 (make-local-variable 'message-postpone-actions)
1338 (make-local-variable 'message-draft-article)
1339 (make-local-hook 'kill-buffer-hook)
1340 (set-syntax-table message-mode-syntax-table)
1341 (use-local-map message-mode-map)
1342 (setq local-abbrev-table message-mode-abbrev-table)
1343 (setq major-mode 'message-mode)
1344 (setq mode-name "Message")
1345 (setq buffer-offer-save t)
1346 (make-local-variable 'facemenu-add-face-function)
1347 (make-local-variable 'facemenu-remove-face-function)
1348 (setq facemenu-add-face-function
1350 (let ((face-fun (cdr (assq face message-face-alist))))
1352 (funcall face-fun (point) end)
1353 (error "Face %s not configured for %s mode" face mode-name)))
1355 facemenu-remove-face-function t)
1356 (make-local-variable 'paragraph-separate)
1357 (make-local-variable 'paragraph-start)
1358 ;; `-- ' precedes the signature. `-----' appears at the start of the
1359 ;; lines that delimit forwarded messages.
1360 ;; Lines containing just >= 3 dashes, perhaps after whitespace,
1361 ;; are also sometimes used and should be separators.
1362 (setq paragraph-start
1363 (concat (regexp-quote mail-header-separator)
1364 "$\\|[ \t]*[a-z0-9A-Z]*>+[ \t]*$\\|[ \t]*$\\|"
1367 ;;!!! Uhm... shurely this can't be right?
1368 "[> " (regexp-quote message-yank-prefix) "]+$"))
1369 (setq paragraph-separate paragraph-start)
1370 (make-local-variable 'message-reply-headers)
1371 (setq message-reply-headers nil)
1372 (make-local-variable 'message-newsreader)
1373 (make-local-variable 'message-mailer)
1374 (make-local-variable 'message-post-method)
1375 (make-local-variable 'message-sent-message-via)
1376 (setq message-sent-message-via nil)
1377 (make-local-variable 'message-checksum)
1378 (setq message-checksum nil)
1379 ;;(when (fboundp 'mail-hist-define-keys)
1380 ;; (mail-hist-define-keys))
1381 (when (string-match "XEmacs\\|Lucid" emacs-version)
1382 (message-setup-toolbar))
1383 (easy-menu-add message-mode-menu message-mode-map)
1384 (easy-menu-add message-mode-field-menu message-mode-map)
1385 ;; Allow mail alias things.
1386 (when (eq message-mail-alias-type 'abbrev)
1387 (if (fboundp 'mail-abbrevs-setup)
1388 (mail-abbrevs-setup)
1389 (mail-aliases-setup)))
1390 (message-set-auto-save-file-name)
1391 (unless (string-match "XEmacs" emacs-version)
1392 (set (make-local-variable 'font-lock-defaults)
1393 '(message-font-lock-keywords t)))
1394 (make-local-variable 'adaptive-fill-regexp)
1395 (setq adaptive-fill-regexp
1396 (concat "[ \t]*[-a-z0-9A-Z]*>+[ \t]*\\|" adaptive-fill-regexp))
1397 (unless (boundp 'adaptive-fill-first-line-regexp)
1398 (setq adaptive-fill-first-line-regexp nil))
1399 (make-local-variable 'adaptive-fill-first-line-regexp)
1400 (setq adaptive-fill-first-line-regexp
1401 (concat "[ \t]*[-a-z0-9A-Z]*>+[ \t]*\\|"
1402 adaptive-fill-first-line-regexp))
1403 (mm-enable-multibyte)
1404 (run-hooks 'text-mode-hook 'message-mode-hook))
1409 ;;; Message mode commands
1412 ;;; Movement commands
1414 (defun message-goto-to ()
1415 "Move point to the To header."
1417 (message-position-on-field "To"))
1419 (defun message-goto-subject ()
1420 "Move point to the Subject header."
1422 (message-position-on-field "Subject"))
1424 (defun message-goto-cc ()
1425 "Move point to the Cc header."
1427 (message-position-on-field "Cc" "To"))
1429 (defun message-goto-bcc ()
1430 "Move point to the Bcc header."
1432 (message-position-on-field "Bcc" "Cc" "To"))
1434 (defun message-goto-fcc ()
1435 "Move point to the Fcc header."
1437 (message-position-on-field "Fcc" "To" "Newsgroups"))
1439 (defun message-goto-reply-to ()
1440 "Move point to the Reply-To header."
1442 (message-position-on-field "Reply-To" "Subject"))
1444 (defun message-goto-newsgroups ()
1445 "Move point to the Newsgroups header."
1447 (message-position-on-field "Newsgroups"))
1449 (defun message-goto-distribution ()
1450 "Move point to the Distribution header."
1452 (message-position-on-field "Distribution"))
1454 (defun message-goto-followup-to ()
1455 "Move point to the Followup-To header."
1457 (message-position-on-field "Followup-To" "Newsgroups"))
1459 (defun message-goto-keywords ()
1460 "Move point to the Keywords header."
1462 (message-position-on-field "Keywords" "Subject"))
1464 (defun message-goto-summary ()
1465 "Move point to the Summary header."
1467 (message-position-on-field "Summary" "Subject"))
1469 (defun message-goto-body ()
1470 "Move point to the beginning of the message body."
1472 (if (looking-at "[ \t]*\n") (expand-abbrev))
1473 (goto-char (point-min))
1474 (search-forward (concat "\n" mail-header-separator "\n") nil t))
1476 (defun message-goto-eoh ()
1477 "Move point to the end of the headers."
1482 (defun message-goto-signature ()
1483 "Move point to the beginning of the message signature.
1484 If there is no signature in the article, go to the end and
1487 (goto-char (point-min))
1488 (if (re-search-forward message-signature-separator nil t)
1490 (goto-char (point-max))
1495 (defun message-insert-to (&optional force)
1496 "Insert a To header that points to the author of the article being replied to.
1497 If the original author requested not to be sent mail, the function signals
1499 With the prefix argument FORCE, insert the header anyway."
1501 (let ((co (message-fetch-reply-field "mail-copies-to")))
1502 (when (and (null force)
1504 (equal (downcase co) "never"))
1505 (error "The user has requested not to have copies sent via mail")))
1506 (when (and (message-position-on-field "To")
1507 (mail-fetch-field "to")
1508 (not (string-match "\\` *\\'" (mail-fetch-field "to"))))
1510 (insert (or (message-fetch-reply-field "reply-to")
1511 (message-fetch-reply-field "from") "")))
1513 (defun message-insert-newsgroups ()
1514 "Insert the Newsgroups header from the article being replied to."
1516 (when (and (message-position-on-field "Newsgroups")
1517 (mail-fetch-field "newsgroups")
1518 (not (string-match "\\` *\\'" (mail-fetch-field "newsgroups"))))
1520 (insert (or (message-fetch-reply-field "newsgroups") "")))
1524 ;;; Various commands
1526 (defun message-delete-not-region (beg end)
1527 "Delete everything in the body of the current message that is outside of the region."
1531 (delete-region (point) (if (not (message-goto-signature))
1537 (delete-region beg (progn (message-goto-body)
1540 (when (message-goto-signature)
1543 (defun message-kill-to-signature ()
1544 "Deletes all text up to the signature."
1546 (let ((point (point)))
1547 (message-goto-signature)
1550 (kill-region point (point))
1554 (defun message-newline-and-reformat ()
1555 "Insert four newlines, and then reformat if inside quoted text."
1557 (let ((point (point))
1561 (setq quoted (looking-at (regexp-quote message-yank-prefix))))
1564 (insert message-yank-prefix))
1565 (fill-paragraph nil)
1569 (defun message-insert-signature (&optional force)
1570 "Insert a signature. See documentation for the `message-signature' variable."
1571 (interactive (list 0))
1574 ((and (null message-signature)
1577 (goto-char (point-max))
1578 (not (re-search-backward
1579 message-signature-separator nil t))))
1580 ((and (null message-signature)
1583 ((message-functionp message-signature)
1584 (funcall message-signature))
1585 ((listp message-signature)
1586 (eval message-signature))
1587 (t message-signature)))
1589 (cond ((stringp signature)
1591 ((and (eq t signature)
1592 message-signature-file
1593 (file-exists-p message-signature-file))
1596 (goto-char (point-max))
1597 ;; Insert the signature.
1601 (if (eq signature t)
1602 (insert-file-contents message-signature-file)
1604 (goto-char (point-max))
1605 (or (bolp) (insert "\n")))))
1607 (defun message-elide-region (b e)
1608 "Elide the text between point and mark.
1609 An ellipsis (from `message-elide-elipsis') will be inserted where the
1615 (insert message-elide-elipsis))
1617 (defvar message-caesar-translation-table nil)
1619 (defun message-caesar-region (b e &optional n)
1620 "Caesar rotation of region by N, default 13, for decrypting netnews."
1623 (min (point) (or (mark t) (point)))
1624 (max (point) (or (mark t) (point)))
1625 (when current-prefix-arg
1626 (prefix-numeric-value current-prefix-arg))))
1628 (setq n (if (numberp n) (mod n 26) 13)) ;canonize N
1629 (unless (or (zerop n) ; no action needed for a rot of 0
1630 (= b e)) ; no region to rotate
1631 ;; We build the table, if necessary.
1632 (when (or (not message-caesar-translation-table)
1633 (/= (aref message-caesar-translation-table ?a) (+ ?a n)))
1634 (setq message-caesar-translation-table
1635 (message-make-caesar-translation-table n)))
1636 ;; Then we translate the region. Do it this way to retain
1639 (when (< (char-after b) 255)
1640 (subst-char-in-region
1641 b (1+ b) (char-after b)
1642 (aref message-caesar-translation-table (char-after b))))
1645 (defun message-make-caesar-translation-table (n)
1646 "Create a rot table with offset N."
1648 (table (make-string 256 0)))
1649 (while (< (incf i) 256)
1652 (substring table 0 ?A)
1653 (substring table (+ ?A n) (+ ?A n (- 26 n)))
1654 (substring table ?A (+ ?A n))
1655 (substring table (+ ?A 26) ?a)
1656 (substring table (+ ?a n) (+ ?a n (- 26 n)))
1657 (substring table ?a (+ ?a n))
1658 (substring table (+ ?a 26) 255))))
1660 (defun message-caesar-buffer-body (&optional rotnum)
1661 "Caesar rotates all letters in the current buffer by 13 places.
1662 Used to encode/decode possiblyun offensive messages (commonly in net.jokes).
1663 With prefix arg, specifies the number of places to rotate each letter forward.
1664 Mail and USENET news headers are not rotated."
1665 (interactive (if current-prefix-arg
1666 (list (prefix-numeric-value current-prefix-arg))
1670 (when (message-goto-body)
1671 (narrow-to-region (point) (point-max)))
1672 (message-caesar-region (point-min) (point-max) rotnum))))
1674 (defun message-pipe-buffer-body (program)
1675 "Pipe the message body in the current buffer through PROGRAM."
1678 (when (message-goto-body)
1679 (narrow-to-region (point) (point-max)))
1680 (let ((body (buffer-substring (point-min) (point-max))))
1681 (unless (equal 0 (call-process-region
1682 (point-min) (point-max) program t t))
1684 (message "%s failed." program))))))
1686 (defun message-rename-buffer (&optional enter-string)
1687 "Rename the *message* buffer to \"*message* RECIPIENT\".
1688 If the function is run with a prefix, it will ask for a new buffer
1689 name, rather than giving an automatic name."
1690 (interactive "Pbuffer name: ")
1693 (goto-char (point-min))
1694 (narrow-to-region (point)
1695 (search-forward mail-header-separator nil 'end))
1697 (if (message-news-p) (message-fetch-field "Newsgroups")
1698 (message-fetch-field "To"))
1701 (if (string-match "," mail-to)
1702 (concat (substring mail-to 0 (match-beginning 0)) ", ...")
1704 (name-default (concat "*message* " mail-trimmed-to))
1705 (name (if enter-string
1706 (read-string "New buffer name: " name-default)
1708 (rename-buffer name t)))))
1710 (defun message-fill-yanked-message (&optional justifyp)
1711 "Fill the paragraphs of a message yanked into this one.
1712 Numeric argument means justify as well."
1715 (goto-char (point-min))
1716 (search-forward (concat "\n" mail-header-separator "\n") nil t)
1717 (let ((fill-prefix message-yank-prefix))
1718 (fill-individual-paragraphs (point) (point-max) justifyp t))))
1720 (defun message-indent-citation ()
1721 "Modify text just inserted from a message to be cited.
1722 The inserted text should be the region.
1723 When this function returns, the region is again around the modified text.
1725 Normally, indent each nonblank line `message-indentation-spaces' spaces.
1726 However, if `message-yank-prefix' is non-nil, insert that prefix on each line."
1727 (let ((start (point)))
1728 ;; Remove unwanted headers.
1729 (when message-ignored-cited-headers
1734 (if (search-forward "\n\n" nil t)
1737 (message-remove-header message-ignored-cited-headers t)
1738 (when (= (point-min) (point-max))
1739 (setq all-removed t))
1740 (goto-char (point-max)))
1744 ;; Delete blank lines at the start of the buffer.
1745 (while (and (point-min)
1748 (message-delete-line))
1749 ;; Delete blank lines at the end of the buffer.
1750 (goto-char (point-max))
1753 (while (and (zerop (forward-line -1))
1755 (message-delete-line))
1756 ;; Do the indentation.
1757 (if (null message-yank-prefix)
1758 (indent-rigidly start (mark t) message-indentation-spaces)
1761 (while (< (point) (mark t))
1762 (insert message-yank-prefix)
1766 (defun message-yank-original (&optional arg)
1767 "Insert the message being replied to, if any.
1768 Puts point before the text and mark after.
1769 Normally indents each nonblank line ARG spaces (default 3). However,
1770 if `message-yank-prefix' is non-nil, insert that prefix on each line.
1772 This function uses `message-cite-function' to do the actual citing.
1774 Just \\[universal-argument] as argument means don't indent, insert no
1775 prefix, and don't delete any headers."
1777 (let ((modified (buffer-modified-p)))
1778 (when (and message-reply-buffer
1779 message-cite-function)
1780 (delete-windows-on message-reply-buffer t)
1781 (insert-buffer message-reply-buffer)
1782 (funcall message-cite-function)
1783 (message-exchange-point-and-mark)
1787 (setq message-checksum (message-checksum))))))
1789 (defun message-cite-original-without-signature ()
1790 "Cite function in the standard Message manner."
1791 (let ((start (point))
1794 (when message-indent-citation-function
1795 (if (listp message-indent-citation-function)
1796 message-indent-citation-function
1797 (list message-indent-citation-function)))))
1799 (when (re-search-backward "^-- $" start t)
1800 ;; Also peel off any blank lines before the signature.
1802 (while (looking-at "^[ \t]*$")
1805 (delete-region (point) end))
1808 (funcall (pop functions)))
1809 (when message-citation-line-function
1812 (funcall message-citation-line-function))))
1814 (defvar mail-citation-hook) ;Compiler directive
1815 (defun message-cite-original ()
1816 "Cite function in the standard Message manner."
1817 (if (and (boundp 'mail-citation-hook)
1819 (run-hooks 'mail-citation-hook)
1820 (let ((start (point))
1822 (when message-indent-citation-function
1823 (if (listp message-indent-citation-function)
1824 message-indent-citation-function
1825 (list message-indent-citation-function)))))
1828 (funcall (pop functions)))
1829 (when message-citation-line-function
1832 (funcall message-citation-line-function)))))
1834 (defun message-insert-citation-line ()
1835 "Function that inserts a simple citation line."
1836 (when message-reply-headers
1837 (insert (mail-header-from message-reply-headers) " writes:\n\n")))
1839 (defun message-position-on-field (header &rest afters)
1840 (let ((case-fold-search t))
1843 (goto-char (point-min))
1846 (concat "^" (regexp-quote mail-header-separator) "$"))
1847 (match-beginning 0)))
1848 (goto-char (point-min))
1849 (if (re-search-forward (concat "^" (regexp-quote header) ":") nil t)
1851 (re-search-forward "^[^ \t]" nil 'move)
1853 (skip-chars-backward "\n")
1856 (not (re-search-forward
1857 (concat "^" (regexp-quote (car afters)) ":")
1861 (re-search-forward "^[^ \t]" nil 'move)
1862 (beginning-of-line))
1863 (insert header ": \n")
1867 (defun message-remove-signature ()
1868 "Remove the signature from the text between point and mark.
1869 The text will also be indented the normal way."
1871 (let ((start (point))
1873 (if (not (re-search-forward message-signature-separator (mark t) t))
1874 ;; No signature here, so we just indent the cited text.
1875 (message-indent-citation)
1876 ;; Find the last non-empty line.
1878 (while (looking-at "[ \t]*$")
1881 (setq mark (set-marker (make-marker) (point)))
1883 (message-indent-citation)
1884 ;; Enable undoing the deletion.
1886 (delete-region mark (mark t))
1887 (set-marker mark nil)))))
1892 ;;; Sending messages
1895 (defun message-send-and-exit (&optional arg)
1896 "Send message like `message-send', then, if no errors, exit from mail buffer."
1898 (let ((buf (current-buffer))
1899 (actions message-exit-actions))
1900 (when (and (message-send arg)
1902 (if message-kill-buffer-on-exit
1905 (when (eq buf (current-buffer))
1906 (message-bury buf)))
1907 (message-do-actions actions)
1910 (defun message-dont-send ()
1911 "Don't send the message you have been editing."
1913 (set-buffer-modified-p t)
1915 (let ((actions message-postpone-actions))
1916 (message-bury (current-buffer))
1917 (message-do-actions actions)))
1919 (defun message-kill-buffer ()
1920 "Kill the current buffer."
1922 (when (or (not (buffer-modified-p))
1923 (yes-or-no-p "Message modified; kill anyway? "))
1924 (let ((actions message-kill-actions))
1925 (setq buffer-file-name nil)
1926 (kill-buffer (current-buffer))
1927 (message-do-actions actions))))
1929 (defun message-bury (buffer)
1930 "Bury this mail buffer."
1931 (let ((newbuf (other-buffer buffer)))
1932 (bury-buffer buffer)
1933 (if (and (fboundp 'frame-parameters)
1934 (cdr (assq 'dedicated (frame-parameters)))
1935 (not (null (delq (selected-frame) (visible-frame-list)))))
1936 (delete-frame (selected-frame))
1937 (switch-to-buffer newbuf))))
1939 (defun message-send (&optional arg)
1940 "Send the message in the current buffer.
1941 If `message-interactive' is non-nil, wait for success indication
1942 or error messages, and inform user.
1943 Otherwise any failure is reported in a message back to
1944 the user from the mailer."
1947 (when (or (buffer-modified-p)
1948 (message-check-element 'unchanged)
1949 (y-or-n-p "No changes in the buffer; really send? "))
1950 ;; Make it possible to undo the coming changes.
1952 (let ((inhibit-read-only t))
1953 (put-text-property (point-min) (point-max) 'read-only nil))
1954 (message-fix-before-sending)
1955 (run-hooks 'message-send-hook)
1956 (message "Sending...")
1957 (let ((alist message-send-method-alist)
1961 (setq elem (pop alist)))
1962 (when (and (or (not (funcall (cadr elem)))
1963 (and (or (not (memq (car elem)
1964 message-sent-message-via))
1967 "Already sent message via %s; resend? "
1969 (setq success (funcall (caddr elem) arg)))))
1971 (when (and success sent)
1973 ;;(when (fboundp 'mail-hist-put-headers-into-history)
1974 ;; (mail-hist-put-headers-into-history))
1975 (run-hooks 'message-sent-hook)
1976 (message "Sending...done")
1977 ;; Mark the buffer as unmodified and delete autosave.
1978 (set-buffer-modified-p nil)
1979 (delete-auto-save-file-if-necessary t)
1980 (message-disassociate-draft)
1981 ;; Delete other mail buffers and stuff.
1982 (message-do-send-housekeeping)
1983 (message-do-actions message-send-actions)
1987 (defun message-send-via-mail (arg)
1988 "Send the current message via mail."
1989 (message-send-mail arg))
1991 (defun message-send-via-news (arg)
1992 "Send the current message via news."
1993 (funcall message-send-news-function arg))
1995 (defun message-fix-before-sending ()
1996 "Do various things to make the message nice before sending it."
1997 ;; Make sure there's a newline at the end of the message.
1998 (goto-char (point-max))
2001 ;; Delete all invisible text.
2002 (message-check 'invisible-text
2003 (when (text-property-any (point-min) (point-max) 'invisible t)
2004 (put-text-property (point-min) (point-max) 'invisible nil)
2005 (unless (yes-or-no-p "Invisible text found and made visible; continue posting?")
2006 (error "Invisible text found and made visible")))))
2008 (defun message-add-action (action &rest types)
2009 "Add ACTION to be performed when doing an exit of type TYPES."
2012 (set (setq var (intern (format "message-%s-actions" (pop types))))
2013 (nconc (symbol-value var) (list action))))))
2015 (defun message-do-actions (actions)
2016 "Perform all actions in ACTIONS."
2017 ;; Now perform actions on successful sending.
2021 ;; A simple function.
2022 ((message-functionp (car actions))
2023 (funcall (car actions)))
2024 ;; Something to be evaled.
2026 (eval (car actions)))))
2029 (defun message-send-mail (&optional arg)
2030 (require 'mail-utils)
2031 (let ((tembuf (message-generate-new-buffer-clone-locals " message temp"))
2032 (case-fold-search nil)
2033 (news (message-news-p))
2034 (mailbuf (current-buffer)))
2036 (message-narrow-to-headers)
2037 ;; Insert some headers.
2038 (let ((message-deletable-headers
2039 (if news nil message-deletable-headers)))
2040 (message-generate-headers message-required-mail-headers))
2041 (mail-encode-encoded-word-buffer)
2042 ;; Let the user do all of the above.
2043 (run-hooks 'message-header-hook))
2044 (message-encode-message-body)
2049 ;; Avoid copying text props.
2051 "%s" (save-excursion
2052 (set-buffer mailbuf)
2054 ;; Remove some headers.
2056 (message-narrow-to-headers)
2057 ;; Remove some headers.
2058 (message-remove-header message-ignored-mail-headers t))
2059 (goto-char (point-max))
2060 ;; require one newline at the end.
2061 (or (= (preceding-char) ?\n)
2064 (or (message-fetch-field "cc")
2065 (message-fetch-field "to")))
2066 (message-insert-courtesy-copy))
2067 (funcall message-send-mail-function))
2068 (kill-buffer tembuf))
2069 (set-buffer mailbuf)
2070 (push 'mail message-sent-message-via)))
2072 (defun message-send-mail-with-sendmail ()
2073 "Send off the prepared buffer with sendmail."
2074 (let ((errbuf (if message-interactive
2075 (generate-new-buffer " sendmail errors")
2077 resend-to-addresses delimline)
2078 (let ((case-fold-search t))
2080 (message-narrow-to-headers)
2081 (setq resend-to-addresses (message-fetch-field "resent-to")))
2082 ;; Change header-delimiter to be what sendmail expects.
2083 (goto-char (point-min))
2085 (concat "^" (regexp-quote mail-header-separator) "\n"))
2086 (replace-match "\n")
2088 (setq delimline (point-marker))
2089 (run-hooks 'message-send-mail-hook)
2090 ;; Insert an extra newline if we need it to work around
2091 ;; Sun's bug that swallows newlines.
2092 (goto-char (1+ delimline))
2093 (when (eval message-mailer-swallows-blank-line)
2095 (when message-interactive
2099 (let ((default-directory "/")
2100 (coding-system-for-write message-send-coding-system))
2101 (apply 'call-process-region
2102 (append (list (point-min) (point-max)
2103 (if (boundp 'sendmail-program)
2105 "/usr/lib/sendmail")
2106 nil errbuf nil "-oi")
2107 ;; Always specify who from,
2108 ;; since some systems have broken sendmails.
2109 ;; But some systems are more broken with -f, so
2110 ;; we'll let users override this.
2111 (if (null message-sendmail-f-is-evil)
2112 (list "-f" (user-login-name)))
2113 ;; These mean "report errors by mail"
2114 ;; and "deliver in background".
2115 (if (null message-interactive) '("-oem" "-odb"))
2116 ;; Get the addresses from the message
2117 ;; unless this is a resend.
2118 ;; We must not do that for a resend
2119 ;; because we would find the original addresses.
2120 ;; For a resend, include the specific addresses.
2121 (if resend-to-addresses
2122 (list resend-to-addresses)
2124 (when message-interactive
2127 (goto-char (point-min))
2128 (while (re-search-forward "\n\n* *" nil t)
2129 (replace-match "; "))
2130 (if (not (zerop (buffer-size)))
2131 (error "Sending...failed to %s"
2132 (buffer-substring (point-min) (point-max)))))
2133 (when (bufferp errbuf)
2134 (kill-buffer errbuf)))))
2136 (defun message-send-mail-with-qmail ()
2137 "Pass the prepared message buffer to qmail-inject.
2138 Refer to the documentation for the variable `message-send-mail-function'
2139 to find out how to use this."
2140 ;; replace the header delimiter with a blank line
2141 (goto-char (point-min))
2143 (concat "^" (regexp-quote mail-header-separator) "\n"))
2144 (replace-match "\n")
2145 (run-hooks 'message-send-mail-hook)
2148 (let ((coding-system-for-write message-send-coding-system))
2150 'call-process-region 1 (point-max) message-qmail-inject-program
2152 ;; qmail-inject's default behaviour is to look for addresses on the
2153 ;; command line; if there're none, it scans the headers.
2154 ;; yes, it does The Right Thing w.r.t. Resent-To and it's kin.
2156 ;; in general, ALL of qmail-inject's defaults are perfect for simply
2157 ;; reading a formatted (i. e., at least a To: or Resent-To header)
2158 ;; message from stdin.
2160 ;; qmail also has the advantage of not having been raped by
2161 ;; various vendors, so we don't have to allow for that, either --
2162 ;; compare this with message-send-mail-with-sendmail and weep
2163 ;; for sendmail's lost innocence.
2165 ;; all this is way cool coz it lets us keep the arguments entirely
2166 ;; free for -inject-arguments -- a big win for the user and for us
2167 ;; since we don't have to play that double-guessing game and the user
2168 ;; gets full control (no gestapo'ish -f's, for instance). --sj
2169 message-qmail-inject-args))
2170 ;; qmail-inject doesn't say anything on it's stdout/stderr,
2171 ;; we have to look at the retval instead
2173 (1 (error "qmail-inject reported permanent failure"))
2174 (111 (error "qmail-inject reported transient failure"))
2175 ;; should never happen
2176 (t (error "qmail-inject reported unknown failure"))))
2178 (defun message-send-mail-with-mh ()
2179 "Send the prepared message buffer with mh."
2180 (let ((mh-previous-window-config nil)
2181 (name (mh-new-draft-name)))
2182 (setq buffer-file-name name)
2183 ;; MH wants to generate these headers itself.
2184 (when message-mh-deletable-headers
2185 (let ((headers message-mh-deletable-headers))
2187 (goto-char (point-min))
2188 (and (re-search-forward
2189 (concat "^" (symbol-name (car headers)) ": *") nil t)
2190 (message-delete-line))
2192 (run-hooks 'message-send-mail-hook)
2193 ;; Pass it on to mh.
2196 (defun message-send-news (&optional arg)
2197 (let ((tembuf (message-generate-new-buffer-clone-locals " *message temp*"))
2198 (case-fold-search nil)
2199 (method (if (message-functionp message-post-method)
2200 (funcall message-post-method arg)
2201 message-post-method))
2202 (messbuf (current-buffer))
2203 (message-syntax-checks
2205 (cons '(existing-newsgroups . disabled)
2206 message-syntax-checks)
2207 message-syntax-checks))
2210 (message-narrow-to-headers)
2211 ;; Insert some headers.
2212 (message-generate-headers message-required-news-headers)
2213 (mail-encode-encoded-word-buffer)
2214 ;; Let the user do all of the above.
2215 (run-hooks 'message-header-hook))
2216 (message-cleanup-headers)
2217 (if (not (message-check-news-syntax))
2219 (message-encode-message-body)
2223 (buffer-disable-undo (current-buffer))
2225 ;; Avoid copying text props.
2227 "%s" (save-excursion
2228 (set-buffer messbuf)
2230 ;; Remove some headers.
2232 (message-narrow-to-headers)
2233 ;; Remove some headers.
2234 (message-remove-header message-ignored-news-headers t))
2235 (goto-char (point-max))
2236 ;; require one newline at the end.
2237 (or (= (preceding-char) ?\n)
2239 (let ((case-fold-search t))
2240 ;; Remove the delimiter.
2241 (goto-char (point-min))
2243 (concat "^" (regexp-quote mail-header-separator) "\n"))
2244 (replace-match "\n")
2246 (run-hooks 'message-send-news-hook)
2247 ;;(require (car method))
2248 ;;(funcall (intern (format "%s-open-server" (car method)))
2249 ;;(cadr method) (cddr method))
2251 ;; (funcall (intern (format "%s-request-post" (car method)))
2253 (gnus-open-server method)
2254 (setq result (gnus-request-post method)))
2255 (kill-buffer tembuf))
2256 (set-buffer messbuf)
2258 (push 'news message-sent-message-via)
2259 (message "Couldn't send message via news: %s"
2260 (nnheader-get-report (car method)))
2264 ;;; Header generation & syntax checking.
2267 (defmacro message-check (type &rest forms)
2268 "Eval FORMS if TYPE is to be checked."
2269 `(or (message-check-element ,type)
2273 (put 'message-check 'lisp-indent-function 1)
2274 (put 'message-check 'edebug-form-spec '(form body))
2276 (defun message-check-element (type)
2277 "Returns non-nil if this type is not to be checked."
2278 (if (eq message-syntax-checks 'dont-check-for-anything-just-trust-me)
2280 (let ((able (assq type message-syntax-checks)))
2282 (eq (cdr able) 'disabled)))))
2284 (defun message-check-news-syntax ()
2285 "Check the syntax of the message."
2290 ;; We narrow to the headers and check them first.
2293 (message-narrow-to-headers)
2294 (message-check-news-header-syntax)))
2296 (message-check-news-body-syntax)))))
2298 (defun message-check-news-header-syntax ()
2300 ;; Check the Subject header.
2301 (message-check 'subject
2302 (let* ((case-fold-search t)
2303 (subject (message-fetch-field "subject")))
2306 (not (string-match "\\`[ \t]*\\'" subject)))
2309 "The subject field is empty or missing. Posting is denied.")))))
2310 ;; Check for commands in Subject.
2311 (message-check 'subject-cmsg
2312 (if (string-match "^cmsg " (message-fetch-field "subject"))
2314 "The control code \"cmsg\" is in the subject. Really post? ")
2316 ;; Check for multiple identical headers.
2317 (message-check 'multiple-headers
2319 (while (and (not found)
2320 (re-search-forward "^[^ \t:]+: " nil t))
2322 (or (re-search-forward
2327 (match-beginning 0) (- (match-end 0) 2))))
2332 (y-or-n-p (format "Multiple %s headers. Really post? " found))
2334 ;; Check for Version and Sendsys.
2335 (message-check 'sendsys
2336 (if (re-search-forward "^Sendsys:\\|^Version:" nil t)
2338 (format "The article contains a %s command. Really post? "
2339 (buffer-substring (match-beginning 0)
2340 (1- (match-end 0)))))
2342 ;; See whether we can shorten Followup-To.
2343 (message-check 'shorten-followup-to
2344 (let ((newsgroups (message-fetch-field "newsgroups"))
2345 (followup-to (message-fetch-field "followup-to"))
2347 (when (and newsgroups
2348 (string-match "," newsgroups)
2353 (setq to (completing-read
2354 "Followups to: (default all groups) "
2355 (mapcar (lambda (g) (list g))
2357 (message-tokenize-header
2359 (goto-char (point-min))
2360 (insert "Followup-To: " to "\n"))
2362 ;; Check "Shoot me".
2363 (message-check 'shoot
2364 (if (re-search-forward
2365 "Message-ID.*.i-did-not-set--mail-host-address--so-shoot-me" nil t)
2366 (y-or-n-p "You appear to have a misconfigured system. Really post? ")
2368 ;; Check for Approved.
2369 (message-check 'approved
2370 (if (re-search-forward "^Approved:" nil t)
2371 (y-or-n-p "The article contains an Approved header. Really post? ")
2373 ;; Check the Message-ID header.
2374 (message-check 'message-id
2375 (let* ((case-fold-search t)
2376 (message-id (message-fetch-field "message-id" t)))
2377 (or (not message-id)
2378 ;; Is there an @ in the ID?
2379 (and (string-match "@" message-id)
2380 ;; Is there a dot in the ID?
2381 (string-match "@[^.]*\\." message-id)
2382 ;; Does the ID end with a dot?
2383 (not (string-match "\\.>" message-id)))
2385 (format "The Message-ID looks strange: \"%s\". Really post? "
2387 ;; Check the Newsgroups & Followup-To headers.
2388 (message-check 'existing-newsgroups
2389 (let* ((case-fold-search t)
2390 (newsgroups (message-fetch-field "newsgroups"))
2391 (followup-to (message-fetch-field "followup-to"))
2392 (groups (message-tokenize-header
2394 (concat newsgroups "," followup-to)
2396 (hashtb (and (boundp 'gnus-active-hashtb)
2397 gnus-active-hashtb))
2399 (if (or (not hashtb)
2400 (not (boundp 'gnus-read-active-file))
2401 (not gnus-read-active-file)
2402 (eq gnus-read-active-file 'some))
2405 (when (and (not (boundp (intern (car groups) hashtb)))
2406 (not (equal (car groups) "poster")))
2407 (push (car groups) errors))
2413 "Really post to %s unknown group%s: %s "
2414 (if (= (length errors) 1) "this" "these")
2415 (if (= (length errors) 1) "" "s")
2416 (mapconcat 'identity errors ", ")))))))
2417 ;; Check the Newsgroups & Followup-To headers for syntax errors.
2418 (message-check 'valid-newsgroups
2419 (let ((case-fold-search t)
2420 (headers '("Newsgroups" "Followup-To"))
2422 (while (and headers (not error))
2423 (when (setq header (mail-fetch-field (car headers)))
2427 "\\`\\([-+_&.a-zA-Z0-9]+\\)?\\(,[-+_&.a-zA-Z0-9]+\\)*\\'"
2432 (not (string-match "\\.\\'\\|\\.\\." g)))
2433 (message-tokenize-header header ","))))
2440 (format "The %s header looks odd: \"%s\". Really post? "
2441 (car headers) header)))))
2442 (message-check 'repeated-newsgroups
2443 (let ((case-fold-search t)
2444 (headers '("Newsgroups" "Followup-To"))
2445 header error groups group)
2448 (when (setq header (mail-fetch-field (pop headers)))
2449 (setq groups (message-tokenize-header header ","))
2450 (while (setq group (pop groups))
2451 (when (member group groups)
2457 (format "Group %s is repeated in headers. Really post? " error)))))
2458 ;; Check the From header.
2459 (message-check 'from
2460 (let* ((case-fold-search t)
2461 (from (message-fetch-field "from"))
2462 (ad (nth 1 (mail-extract-address-components from))))
2465 (message "There is no From line. Posting is denied.")
2467 ((or (not (string-match "@[^\\.]*\\." ad)) ;larsi@ifi
2468 (string-match "\\.\\." ad) ;larsi@ifi..uio
2469 (string-match "@\\." ad) ;larsi@.ifi.uio
2470 (string-match "\\.$" ad) ;larsi@ifi.uio.
2471 (not (string-match "^[^@]+@[^@]+$" ad)) ;larsi.ifi.uio
2472 (string-match "(.*).*(.*)" from)) ;(lars) (lars)
2474 "Denied posting -- the From looks strange: \"%s\"." from)
2478 (defun message-check-news-body-syntax ()
2480 ;; Check for long lines.
2481 (message-check 'long-lines
2482 (goto-char (point-min))
2484 (concat "^" (regexp-quote mail-header-separator) "$"))
2488 (< (current-column) 80))
2489 (zerop (forward-line 1))))
2493 "You have lines longer than 79 characters. Really post? ")))
2494 ;; Check whether the article is empty.
2495 (message-check 'empty
2496 (goto-char (point-min))
2498 (concat "^" (regexp-quote mail-header-separator) "$"))
2501 (goto-char (point-max))
2502 (re-search-backward message-signature-separator nil t)
2504 (or (re-search-backward "[^ \n\t]" b t)
2505 (y-or-n-p "Empty article. Really post? "))))
2506 ;; Check for control characters.
2507 (message-check 'control-chars
2508 (if (re-search-forward "[\000-\007\013\015-\032\034-\037\200-\237]" nil t)
2510 "The article contains control characters. Really post? ")
2512 ;; Check excessive size.
2513 (message-check 'size
2514 (if (> (buffer-size) 60000)
2516 (format "The article is %d octets long. Really post? "
2519 ;; Check whether any new text has been added.
2520 (message-check 'new-text
2522 (not message-checksum)
2523 (not (eq (message-checksum) message-checksum))
2525 "It looks like no new text has been added. Really post? ")))
2526 ;; Check the length of the signature.
2527 (message-check 'signature
2528 (goto-char (point-max))
2529 (if (or (not (re-search-backward message-signature-separator nil t))
2530 (search-forward message-forward-end-separator nil t))
2532 (if (> (count-lines (point) (point-max)) 5)
2535 "Your .sig is %d lines; it should be max 4. Really post? "
2536 (1- (count-lines (point) (point-max)))))
2539 (defun message-checksum ()
2540 "Return a \"checksum\" for the current buffer."
2543 (goto-char (point-min))
2545 (concat "^" (regexp-quote mail-header-separator) "$"))
2547 (when (not (looking-at "[ \t\n]"))
2548 (setq sum (logxor (ash sum 1) (if (natnump sum) 0 1)
2553 (defun message-do-fcc ()
2554 "Process Fcc headers in the current buffer."
2555 (let ((case-fold-search t)
2556 (buf (current-buffer))
2559 (set-buffer (get-buffer-create " *message temp*"))
2561 (insert-buffer-substring buf)
2563 (message-narrow-to-headers)
2564 (while (setq file (message-fetch-field "fcc"))
2566 (message-remove-header "fcc" nil t)))
2567 (goto-char (point-min))
2568 (re-search-forward (concat "^" (regexp-quote mail-header-separator) "$"))
2569 (replace-match "" t t)
2570 ;; Process FCC operations.
2572 (setq file (pop list))
2573 (if (string-match "^[ \t]*|[ \t]*\\(.*\\)[ \t]*$" file)
2574 ;; Pipe the article to the program in question.
2575 (call-process-region (point-min) (point-max) shell-file-name
2576 nil nil nil shell-command-switch
2577 (match-string 1 file))
2578 ;; Save the article.
2579 (setq file (expand-file-name file))
2580 (unless (file-exists-p (file-name-directory file))
2581 (make-directory (file-name-directory file) t))
2582 (if (and message-fcc-handler-function
2583 (not (eq message-fcc-handler-function 'rmail-output)))
2584 (funcall message-fcc-handler-function file)
2585 (if (and (file-readable-p file) (mail-file-babyl-p file))
2586 (rmail-output file 1 nil t)
2587 (let ((mail-use-rfc822 t))
2588 (rmail-output file 1 t t))))))
2590 (kill-buffer (current-buffer)))))
2592 (defun message-output (filename)
2593 "Append this article to Unix/babyl mail file.."
2594 (if (and (file-readable-p filename)
2595 (mail-file-babyl-p filename))
2596 (rmail-output-to-rmail-file filename t)
2597 (gnus-output-to-mail filename t)))
2599 (defun message-cleanup-headers ()
2600 "Do various automatic cleanups of the headers."
2601 ;; Remove empty lines in the header.
2603 (message-narrow-to-headers)
2604 ;; Remove blank lines.
2605 (while (re-search-forward "^[ \t]*\n" nil t)
2606 (replace-match "" t t))
2608 ;; Correct Newsgroups and Followup-To headers: Change sequence of
2609 ;; spaces to comma and eliminate spaces around commas. Eliminate
2610 ;; embedded line breaks.
2611 (goto-char (point-min))
2612 (while (re-search-forward "^\\(Newsgroups\\|Followup-To\\): +" nil t)
2616 (if (re-search-forward "^[^ \t]" nil t)
2620 (goto-char (point-min))
2621 (while (re-search-forward "\n[ \t]+" nil t)
2622 (replace-match " " t t)) ;No line breaks (too confusing)
2623 (goto-char (point-min))
2624 (while (re-search-forward "[ \t\n]*,[ \t\n]*\\|[ \t]+" nil t)
2625 (replace-match "," t t))
2626 (goto-char (point-min))
2627 ;; Remove trailing commas.
2628 (when (re-search-forward ",+$" nil t)
2629 (replace-match "" t t))))))
2631 (defun message-make-date (&optional now)
2632 "Make a valid data header.
2633 If NOW, use that time instead."
2634 (let* ((now (or now (current-time)))
2635 (zone (nth 8 (decode-time now)))
2639 ;; We do all of this because XEmacs doesn't have the %z spec.
2640 (concat (format-time-string "%d %b %Y %H:%M:%S " (or now (current-time)))
2641 (format "%s%02d%02d"
2645 (defun message-make-message-id ()
2646 "Make a unique Message-ID."
2647 (concat "<" (message-unique-id)
2648 (let ((psubject (save-excursion (message-fetch-field "subject")))
2650 (save-excursion (message-fetch-field "supersedes"))))
2652 (and message-reply-headers
2653 (mail-header-references message-reply-headers)
2654 (mail-header-subject message-reply-headers)
2656 (mail-header-subject message-reply-headers)
2658 (message-strip-subject-re
2659 (mail-header-subject message-reply-headers))
2660 (message-strip-subject-re psubject))))
2662 (string-match "_-_@" psupersedes)))
2664 "@" (message-make-fqdn) ">"))
2666 (defvar message-unique-id-char nil)
2668 ;; If you ever change this function, make sure the new version
2669 ;; cannot generate IDs that the old version could.
2670 ;; You might for example insert a "." somewhere (not next to another dot
2671 ;; or string boundary), or modify the "fsf" string.
2672 (defun message-unique-id ()
2673 ;; Don't use microseconds from (current-time), they may be unsupported.
2674 ;; Instead we use this randomly inited counter.
2675 (setq message-unique-id-char
2676 (% (1+ (or message-unique-id-char (logand (random t) (1- (lsh 1 20)))))
2677 ;; (current-time) returns 16-bit ints,
2678 ;; and 2^16*25 just fits into 4 digits i base 36.
2680 (let ((tm (current-time)))
2682 (if (memq system-type '(ms-dos emx vax-vms))
2683 (let ((user (downcase (user-login-name))))
2684 (while (string-match "[^a-z0-9_]" user)
2685 (aset user (match-beginning 0) ?_))
2687 (message-number-base36 (user-uid) -1))
2688 (message-number-base36 (+ (car tm)
2689 (lsh (% message-unique-id-char 25) 16)) 4)
2690 (message-number-base36 (+ (nth 1 tm)
2691 (lsh (/ message-unique-id-char 25) 16)) 4)
2692 ;; Append the newsreader name, because while the generated
2693 ;; ID is unique to this newsreader, other newsreaders might
2694 ;; otherwise generate the same ID via another algorithm.
2697 (defun message-number-base36 (num len)
2702 (concat (message-number-base36 (/ num 36) (1- len))
2703 (char-to-string (aref "zyxwvutsrqponmlkjihgfedcba9876543210"
2706 (defun message-make-organization ()
2707 "Make an Organization header."
2708 (let* ((organization
2709 (when message-user-organization
2710 (if (message-functionp message-user-organization)
2711 (funcall message-user-organization)
2712 message-user-organization))))
2714 (message-set-work-buffer)
2715 (cond ((stringp organization)
2716 (insert organization))
2717 ((and (eq t organization)
2718 message-user-organization-file
2719 (file-exists-p message-user-organization-file))
2720 (insert-file-contents message-user-organization-file)))
2721 (goto-char (point-min))
2722 (while (re-search-forward "[\t\n]+" nil t)
2723 (replace-match "" t t))
2724 (unless (zerop (buffer-size))
2727 (defun message-make-lines ()
2728 "Count the number of lines and return numeric string."
2732 (goto-char (point-min))
2734 (concat "^" (regexp-quote mail-header-separator) "$"))
2736 (int-to-string (count-lines (point) (point-max))))))
2738 (defun message-make-in-reply-to ()
2739 "Return the In-Reply-To header for this message."
2740 (when message-reply-headers
2741 (let ((from (mail-header-from message-reply-headers))
2742 (date (mail-header-date message-reply-headers)))
2745 (string-match " *at \\| *@ \\| *(\\| *<" from)))
2746 (concat (if (and stop-pos
2747 (not (zerop stop-pos)))
2748 (substring from 0 stop-pos) from)
2750 (if (or (not date) (string= date ""))
2751 "(unknown date)" date)
2754 (defun message-make-distribution ()
2755 "Make a Distribution header."
2756 (let ((orig-distribution (message-fetch-reply-field "distribution")))
2757 (cond ((message-functionp message-distribution-function)
2758 (funcall message-distribution-function))
2759 (t orig-distribution))))
2761 (defun message-make-expires ()
2762 "Return an Expires header based on `message-expires'."
2763 (let ((current (current-time))
2764 (future (* 1.0 message-expires 60 60 24)))
2765 ;; Add the future to current.
2766 (setcar current (+ (car current) (round (/ future (expt 2 16)))))
2767 (setcar (cdr current) (+ (nth 1 current) (% (round future) (expt 2 16))))
2768 (message-make-date current)))
2770 (defun message-make-path ()
2772 (let ((login-name (user-login-name)))
2773 (cond ((null message-user-path)
2774 (concat (system-name) "!" login-name))
2775 ((stringp message-user-path)
2776 ;; Support GENERICPATH. Suggested by vixie@decwrl.dec.com.
2777 (concat message-user-path "!" login-name))
2780 (defun message-make-from ()
2781 "Make a From header."
2782 (let* ((style message-from-style)
2783 (login (message-make-address))
2785 (or (and (boundp 'user-full-name)
2788 (when (string= fullname "&")
2789 (setq fullname (user-login-name)))
2791 (message-set-work-buffer)
2794 (equal fullname ""))
2796 ((or (eq style 'angles)
2797 (and (not (eq style 'parens))
2798 ;; Use angles if no quoting is needed, or if parens would
2799 ;; need quoting too.
2800 (or (not (string-match "[^- !#-'*+/-9=?A-Z^-~]" fullname))
2801 (let ((tmp (concat fullname nil)))
2802 (while (string-match "([^()]*)" tmp)
2803 (aset tmp (match-beginning 0) ?-)
2804 (aset tmp (1- (match-end 0)) ?-))
2805 (string-match "[\\()]" tmp)))))
2807 (goto-char (point-min))
2808 ;; Look for a character that cannot appear unquoted
2809 ;; according to RFC 822.
2810 (when (re-search-forward "[^- !#-'*+/-9=?A-Z^-~]" nil 1)
2811 ;; Quote fullname, escaping specials.
2812 (goto-char (point-min))
2814 (while (re-search-forward "[\"\\]" nil 1)
2815 (replace-match "\\\\\\&" t))
2817 (insert " <" login ">"))
2818 (t ; 'parens or default
2820 (let ((fullname-start (point)))
2822 (goto-char fullname-start)
2823 ;; RFC 822 says \ and nonmatching parentheses
2824 ;; must be escaped in comments.
2825 ;; Escape every instance of ()\ ...
2826 (while (re-search-forward "[()\\]" nil 1)
2827 (replace-match "\\\\\\&" t))
2828 ;; ... then undo escaping of matching parentheses,
2829 ;; including matching nested parentheses.
2830 (goto-char fullname-start)
2831 (while (re-search-forward
2832 "\\(\\=\\|[^\\]\\(\\\\\\\\\\)*\\)\\\\(\\(\\([^\\]\\|\\\\\\\\\\)*\\)\\\\)"
2834 (replace-match "\\1(\\3)" t)
2835 (goto-char fullname-start)))
2839 (defun message-make-sender ()
2840 "Return the \"real\" user address.
2841 This function tries to ignore all user modifications, and
2842 give as trustworthy answer as possible."
2843 (concat (user-login-name) "@" (system-name)))
2845 (defun message-make-address ()
2846 "Make the address of the user."
2847 (or (message-user-mail-address)
2848 (concat (user-login-name) "@" (message-make-domain))))
2850 (defun message-user-mail-address ()
2851 "Return the pertinent part of `user-mail-address'."
2852 (when user-mail-address
2853 (if (string-match " " user-mail-address)
2854 (nth 1 (mail-extract-address-components user-mail-address))
2855 user-mail-address)))
2857 (defun message-make-fqdn ()
2858 "Return user's fully qualified domain name."
2859 (let ((system-name (system-name))
2860 (user-mail (message-user-mail-address)))
2862 ((string-match "[^.]\\.[^.]" system-name)
2863 ;; `system-name' returned the right result.
2865 ;; Try `mail-host-address'.
2866 ((and (boundp 'mail-host-address)
2867 (stringp mail-host-address)
2868 (string-match "\\." mail-host-address))
2870 ;; We try `user-mail-address' as a backup.
2872 (string-match "\\." user-mail)
2873 (string-match "@\\(.*\\)\\'" user-mail))
2874 (match-string 1 user-mail))
2875 ;; Default to this bogus thing.
2877 (concat system-name ".i-did-not-set--mail-host-address--so-shoot-me")))))
2879 (defun message-make-host-name ()
2880 "Return the name of the host."
2881 (let ((fqdn (message-make-fqdn)))
2882 (string-match "^[^.]+\\." fqdn)
2883 (substring fqdn 0 (1- (match-end 0)))))
2885 (defun message-make-domain ()
2886 "Return the domain name."
2887 (or mail-host-address
2888 (message-make-fqdn)))
2890 (defun message-generate-headers (headers)
2891 "Prepare article HEADERS.
2892 Headers already prepared in the buffer are not modified."
2894 (message-narrow-to-headers)
2895 (let* ((Date (message-make-date))
2896 (Message-ID (message-make-message-id))
2897 (Organization (message-make-organization))
2898 (From (message-make-from))
2899 (Path (message-make-path))
2902 (In-Reply-To (message-make-in-reply-to))
2904 (Distribution (message-make-distribution))
2905 (Lines (message-make-lines))
2906 (User-Agent message-newsreader)
2907 (Expires (message-make-expires))
2908 (case-fold-search t)
2910 ;; First we remove any old generated headers.
2911 (let ((headers message-deletable-headers))
2912 (unless (buffer-modified-p)
2913 (setq headers (delq 'Message-ID (copy-sequence headers))))
2915 (goto-char (point-min))
2916 (and (re-search-forward
2917 (concat "^" (symbol-name (car headers)) ": *") nil t)
2918 (get-text-property (1+ (match-beginning 0)) 'message-deletable)
2919 (message-delete-line))
2921 ;; Go through all the required headers and see if they are in the
2922 ;; articles already. If they are not, or are empty, they are
2923 ;; inserted automatically - except for Subject, Newsgroups and
2926 (goto-char (point-min))
2927 (setq elem (pop headers))
2929 (if (eq (car elem) 'optional)
2930 (setq header (cdr elem))
2931 (setq header (car elem)))
2933 (when (or (not (re-search-forward
2937 (if (stringp header)
2939 (symbol-name header))))
2943 ;; The header was found. We insert a space after the
2944 ;; colon, if there is none.
2945 (if (/= (following-char) ? ) (insert " ") (forward-char 1))
2946 ;; Find out whether the header is empty...
2947 (looking-at "[ \t]*$")))
2948 ;; So we find out what value we should insert.
2951 ((and (consp elem) (eq (car elem) 'optional))
2952 ;; This is an optional header. If the cdr of this
2953 ;; is something that is nil, then we do not insert
2955 (setq header (cdr elem))
2956 (or (and (fboundp (cdr elem)) (funcall (cdr elem)))
2957 (and (boundp (cdr elem)) (symbol-value (cdr elem)))))
2959 ;; The element is a cons. Either the cdr is a
2960 ;; string to be inserted verbatim, or it is a
2961 ;; function, and we insert the value returned from
2963 (or (and (stringp (cdr elem)) (cdr elem))
2964 (and (fboundp (cdr elem)) (funcall (cdr elem)))))
2965 ((and (boundp header) (symbol-value header))
2966 ;; The element is a symbol. We insert the value
2967 ;; of this symbol, if any.
2968 (symbol-value header))
2970 ;; We couldn't generate a value for this header,
2971 ;; so we just ask the user.
2972 (read-from-minibuffer
2973 (format "Empty header for %s; enter value: " header)))))
2974 ;; Finally insert the header.
2976 (not (equal value "")))
2980 ;; This header didn't exist, so we insert it.
2981 (goto-char (point-max))
2982 (insert (if (stringp header) header (symbol-name header))
2985 ;; The value of this header was empty, so we clear
2986 ;; totally and insert the new value.
2987 (delete-region (point) (gnus-point-at-eol))
2989 ;; Add the deletable property to the headers that require it.
2990 (and (memq header message-deletable-headers)
2991 (progn (beginning-of-line) (looking-at "[^:]+: "))
2992 (add-text-properties
2993 (point) (match-end 0)
2994 '(message-deletable t face italic) (current-buffer)))))))
2995 ;; Insert new Sender if the From is strange.
2996 (let ((from (message-fetch-field "from"))
2997 (sender (message-fetch-field "sender"))
2998 (secure-sender (message-make-sender)))
3000 (not (message-check-element 'sender))
3003 (cadr (mail-extract-address-components from)))
3004 (downcase secure-sender)))
3009 (cadr (mail-extract-address-components sender)))
3010 (downcase secure-sender)))))
3011 (goto-char (point-min))
3012 ;; Rename any old Sender headers to Original-Sender.
3013 (when (re-search-forward "^\\(Original-\\)*Sender:" nil t)
3015 (insert "Original-")
3016 (beginning-of-line))
3017 (when (or (message-news-p)
3018 (string-match "@.+\\.." secure-sender))
3019 (insert "Sender: " secure-sender "\n")))))))
3021 (defun message-insert-courtesy-copy ()
3022 "Insert a courtesy message in mail copies of combined messages."
3026 (message-narrow-to-headers)
3027 (when (setq newsgroups (message-fetch-field "newsgroups"))
3028 (goto-char (point-max))
3029 (insert "Posted-To: " newsgroups "\n")))
3031 (when message-courtesy-message
3033 ((string-match "%s" message-courtesy-message)
3034 (insert (format message-courtesy-message newsgroups)))
3036 (insert message-courtesy-message)))))))
3039 ;;; Setting up a message buffer
3042 (defun message-fill-address (header value)
3044 (narrow-to-region (point) (point))
3045 (insert (capitalize (symbol-name header))
3047 (if (consp value) (car value) value)
3049 (narrow-to-region (point-min) (1- (point-max)))
3051 (goto-char (point-min))
3053 (skip-chars-forward "^,\"" (point-max))
3054 (if (or (= (following-char) ?,)
3057 (if (and (> (current-column) 78)
3063 (setq last (1+ (point))))
3064 (setq last (1+ (point)))))
3065 (setq quoted (not quoted)))
3068 (goto-char (point-max))
3072 (defun message-fill-header (header value)
3073 (let ((begin (point))
3076 (insert (capitalize (symbol-name header))
3078 (if (consp value) (car value) value)
3081 (narrow-to-region begin (point))
3082 (fill-region-as-paragraph begin (point))
3083 ;; Tapdance around looong Message-IDs.
3085 (when (looking-at "[ \t]*$")
3086 (message-delete-line))
3088 (re-search-forward ":" nil t)
3089 (when (looking-at "\n[ \t]+")
3090 (replace-match " " t t))
3091 (goto-char (point-max)))))
3093 (defun message-shorten-references (header references)
3094 "Limit REFERENCES to be shorter than 988 characters."
3100 (goto-char (point-min))
3101 (while (re-search-forward "<[^>]+>" nil t)
3102 (push (match-string 0) refs))
3103 (setq refs (nreverse refs))
3104 (while (> (length (mapconcat 'identity refs " ")) max)
3105 (when (< (length refs) (1+ cut))
3107 (setcdr (nthcdr cut refs) (cddr (nthcdr cut refs)))))
3108 (insert (capitalize (symbol-name header)) ": "
3109 (mapconcat 'identity refs " ") "\n")))
3111 (defun message-position-point ()
3112 "Move point to where the user probably wants to find it."
3113 (message-narrow-to-headers)
3115 ((re-search-forward "^[^:]+:[ \t]*$" nil t)
3116 (search-backward ":" )
3119 (if (= (following-char) ? )
3123 (goto-char (point-max))
3126 (unless (looking-at "$")
3130 (defun message-buffer-name (type &optional to group)
3131 "Return a new (unique) buffer name based on TYPE and TO."
3133 ;; Check whether `message-generate-new-buffers' is a function,
3134 ;; and if so, call it.
3135 ((message-functionp message-generate-new-buffers)
3136 (funcall message-generate-new-buffers type to group))
3137 ;; Generate a new buffer name The Message Way.
3138 (message-generate-new-buffers
3139 (generate-new-buffer-name
3143 (or (car (mail-extract-address-components to))
3146 (if (and group (not (string= group ""))) (concat " on " group) "")
3148 ;; Use standard name.
3150 (format "*%s message*" type))))
3152 (defun message-pop-to-buffer (name)
3153 "Pop to buffer NAME, and warn if it already exists and is modified."
3154 (let ((buffer (get-buffer name)))
3156 (buffer-name buffer))
3158 (set-buffer (pop-to-buffer buffer))
3159 (when (and (buffer-modified-p)
3161 "Message already being composed; erase? ")))
3162 (error "Message being composed")))
3163 (set-buffer (pop-to-buffer name)))
3167 (defun message-do-send-housekeeping ()
3168 "Kill old message buffers."
3169 ;; We might have sent this buffer already. Delete it from the
3171 (setq message-buffer-list (delq (current-buffer) message-buffer-list))
3172 (while (and message-max-buffers
3174 (>= (length message-buffer-list) message-max-buffers))
3175 ;; Kill the oldest buffer -- unless it has been changed.
3176 (let ((buffer (pop message-buffer-list)))
3177 (when (and (buffer-name buffer)
3178 (not (buffer-modified-p buffer)))
3179 (kill-buffer buffer))))
3180 ;; Rename the buffer.
3181 (if message-send-rename-function
3182 (funcall message-send-rename-function)
3183 (when (string-match "\\`\\*" (buffer-name))
3185 (concat "*sent " (substring (buffer-name) (match-end 0))) t)))
3186 ;; Push the current buffer onto the list.
3187 (when message-max-buffers
3188 (setq message-buffer-list
3189 (nconc message-buffer-list (list (current-buffer))))))
3191 (defvar mc-modes-alist)
3192 (defun message-setup (headers &optional replybuffer actions)
3193 (when (and (boundp 'mc-modes-alist)
3194 (not (assq 'message-mode mc-modes-alist)))
3195 (push '(message-mode (encrypt . mc-encrypt-message)
3196 (sign . mc-sign-message))
3199 (setq message-send-actions actions))
3200 (setq message-reply-buffer replybuffer)
3201 (goto-char (point-min))
3202 ;; Insert all the headers.
3205 (alist message-header-format-alist))
3207 (unless (assq (caar h) message-header-format-alist)
3208 (push (list (caar h)) alist))
3212 (delete-region (point) (progn (forward-line -1) (point)))
3213 (when message-default-headers
3214 (insert message-default-headers)
3215 (or (bolp) (insert ?\n)))
3219 (insert mail-header-separator "\n")
3223 (when (message-news-p)
3224 (when message-default-news-headers
3225 (insert message-default-news-headers)
3226 (or (bolp) (insert ?\n)))
3227 (when message-generate-headers-first
3228 (message-generate-headers
3231 (copy-sequence message-required-news-headers))))))
3232 (when (message-mail-p)
3233 (when message-default-mail-headers
3234 (insert message-default-mail-headers)
3235 (or (bolp) (insert ?\n)))
3236 (when message-generate-headers-first
3237 (message-generate-headers
3240 (copy-sequence message-required-mail-headers))))))
3241 (run-hooks 'message-signature-setup-hook)
3242 (message-insert-signature)
3244 (message-narrow-to-headers)
3245 (run-hooks 'message-header-setup-hook))
3246 (set-buffer-modified-p nil)
3247 (setq buffer-undo-list nil)
3248 (run-hooks 'message-setup-hook)
3249 (message-position-point)
3252 (defun message-set-auto-save-file-name ()
3253 "Associate the message buffer with a file in the drafts directory."
3254 (when message-autosave-directory
3256 (setq message-draft-article
3257 (nndraft-request-associate-buffer "drafts"))
3258 (setq buffer-file-name (expand-file-name "*message*"
3259 message-autosave-directory))
3260 (setq buffer-auto-save-file-name (make-auto-save-file-name)))
3261 (clear-visited-file-modtime)))
3263 (defun message-disassociate-draft ()
3264 "Disassociate the message buffer from the drafts directory."
3265 (when message-draft-article
3266 (nndraft-request-expire-articles
3267 (list message-draft-article) "drafts" nil t)))
3272 ;;; Commands for interfacing with message
3276 (defun message-mail (&optional to subject
3277 other-headers continue switch-function
3278 yank-action send-actions)
3279 "Start editing a mail message to be sent.
3280 OTHER-HEADERS is an alist of header/value pairs."
3282 (let ((message-this-is-mail t))
3283 (message-pop-to-buffer (message-buffer-name "mail" to))
3286 `((To . ,(or to "")) (Subject . ,(or subject "")))
3287 (when other-headers other-headers)))))
3290 (defun message-news (&optional newsgroups subject)
3291 "Start editing a news article to be sent."
3293 (let ((message-this-is-news t))
3294 (message-pop-to-buffer (message-buffer-name "news" nil newsgroups))
3295 (message-setup `((Newsgroups . ,(or newsgroups ""))
3296 (Subject . ,(or subject ""))))))
3299 (defun message-reply (&optional to-address wide)
3300 "Start editing a reply to the article in the current buffer."
3302 (let ((cur (current-buffer))
3303 from subject date reply-to to cc
3304 references message-id follow-to
3305 (inhibit-point-motion-hooks t)
3306 mct never-mct gnus-warning)
3308 (message-narrow-to-head)
3309 ;; Allow customizations to have their say.
3311 ;; This is a regular reply.
3312 (if (message-functionp message-reply-to-function)
3313 (setq follow-to (funcall message-reply-to-function)))
3314 ;; This is a followup.
3315 (if (message-functionp message-wide-reply-to-function)
3318 (funcall message-wide-reply-to-function)))))
3319 ;; Find all relevant headers we need.
3320 (setq from (message-fetch-field "from")
3321 date (message-fetch-field "date")
3322 subject (or (message-fetch-field "subject") "none")
3323 to (message-fetch-field "to")
3324 cc (message-fetch-field "cc")
3325 mct (message-fetch-field "mail-copies-to")
3326 reply-to (message-fetch-field "reply-to")
3327 references (message-fetch-field "references")
3328 message-id (message-fetch-field "message-id" t))
3329 ;; Remove any (buggy) Re:'s that are present and make a
3331 (when (string-match message-subject-re-regexp subject)
3332 (setq subject (substring subject (match-end 0))))
3333 (setq subject (concat "Re: " subject))
3335 (when (and (setq gnus-warning (message-fetch-field "gnus-warning"))
3336 (string-match "<[^>]+>" gnus-warning))
3337 (setq message-id (match-string 0 gnus-warning)))
3339 ;; Handle special values of Mail-Copies-To.
3341 (cond ((equal (downcase mct) "never")
3344 ((equal (downcase mct) "always")
3345 (setq mct (or reply-to from)))))
3351 (setq follow-to (list (cons 'To (or to-address reply-to from))))
3352 (when (and wide mct)
3353 (push (cons 'Cc mct) follow-to)))
3356 (message-set-work-buffer)
3358 (insert (or reply-to from "")))
3359 (insert (if to (concat (if (bolp) "" ", ") to "") ""))
3360 (insert (if mct (concat (if (bolp) "" ", ") mct) ""))
3361 (insert (if cc (concat (if (bolp) "" ", ") cc) ""))
3362 (goto-char (point-min))
3363 (while (re-search-forward "[ \t]+" nil t)
3364 (replace-match " " t t))
3365 ;; Remove addresses that match `rmail-dont-reply-to-names'.
3366 (insert (prog1 (rmail-dont-reply-to (buffer-string))
3368 (goto-char (point-min))
3369 ;; Perhaps Mail-Copies-To: never removed the only address?
3371 (insert (or reply-to from "")))
3375 (cons (mail-strip-quoted-names addr) addr))
3376 (message-tokenize-header (buffer-string))))
3379 (setq ccalist (delq (assoc (car (pop s)) s) ccalist)))))
3380 (setq follow-to (list (cons 'To (cdr (pop ccalist)))))
3382 (let ((ccs (cons 'Cc (mapconcat
3383 (lambda (addr) (cdr addr)) ccalist ", "))))
3384 (when (string-match "^ +" (cdr ccs))
3385 (setcdr ccs (substring (cdr ccs) (match-end 0))))
3386 (push ccs follow-to))))))
3389 (message-pop-to-buffer (message-buffer-name
3390 (if wide "wide reply" "reply") from
3391 (if wide to-address nil)))
3393 (setq message-reply-headers
3394 (vector 0 subject from date message-id references 0 0 ""))
3397 `((Subject . ,subject)
3399 ,@(if (or references message-id)
3400 `((References . ,(concat (or references "") (and references " ")
3401 (or message-id ""))))
3406 (defun message-wide-reply (&optional to-address)
3407 "Make a \"wide\" reply to the message in the current buffer."
3409 (message-reply to-address t))
3412 (defun message-followup (&optional to-newsgroups)
3413 "Follow up to the message in the current buffer.
3414 If TO-NEWSGROUPS, use that as the new Newsgroups line."
3416 (let ((cur (current-buffer))
3417 from subject date reply-to mct
3418 references message-id follow-to
3419 (inhibit-point-motion-hooks t)
3420 (message-this-is-news t)
3421 followup-to distribution newsgroups gnus-warning posted-to)
3424 (goto-char (point-min))
3425 (if (search-forward "\n\n" nil t)
3428 (when (message-functionp message-followup-to-function)
3430 (funcall message-followup-to-function)))
3431 (setq from (message-fetch-field "from")
3432 date (message-fetch-field "date")
3433 subject (or (message-fetch-field "subject") "none")
3434 references (message-fetch-field "references")
3435 message-id (message-fetch-field "message-id" t)
3436 followup-to (message-fetch-field "followup-to")
3437 newsgroups (message-fetch-field "newsgroups")
3438 posted-to (message-fetch-field "posted-to")
3439 reply-to (message-fetch-field "reply-to")
3440 distribution (message-fetch-field "distribution")
3441 mct (message-fetch-field "mail-copies-to"))
3442 (when (and (setq gnus-warning (message-fetch-field "gnus-warning"))
3443 (string-match "<[^>]+>" gnus-warning))
3444 (setq message-id (match-string 0 gnus-warning)))
3445 ;; Remove bogus distribution.
3446 (when (and (stringp distribution)
3447 (let ((case-fold-search t))
3448 (string-match "world" distribution)))
3449 (setq distribution nil))
3450 ;; Remove any (buggy) Re:'s that are present and make a
3452 (when (string-match message-subject-re-regexp subject)
3453 (setq subject (substring subject (match-end 0))))
3454 (setq subject (concat "Re: " subject))
3457 (message-pop-to-buffer (message-buffer-name "followup" from newsgroups))
3460 `((Subject . ,subject)
3463 (list (cons 'Newsgroups to-newsgroups)))
3464 (follow-to follow-to)
3465 ((and followup-to message-use-followup-to)
3468 ((equal (downcase followup-to) "poster")
3469 (if (or (eq message-use-followup-to 'use)
3470 (message-y-or-n-p "Obey Followup-To: poster? " t "\
3471 You should normally obey the Followup-To: header.
3473 `Followup-To: poster' sends your response via e-mail instead of news.
3475 A typical situation where `Followup-To: poster' is used is when the poster
3476 does not read the newsgroup, so he wouldn't see any replies sent to it."))
3478 (setq message-this-is-news nil)
3479 (cons 'To (or reply-to from "")))
3480 (cons 'Newsgroups newsgroups)))
3482 (if (or (equal followup-to newsgroups)
3483 (not (eq message-use-followup-to 'ask))
3485 (concat "Obey Followup-To: " followup-to "? ") t "\
3486 You should normally obey the Followup-To: header.
3488 `Followup-To: " followup-to "'
3489 directs your response to " (if (string-match "," followup-to)
3490 "the specified newsgroups"
3491 "that newsgroup only") ".
3493 If a message is posted to several newsgroups, Followup-To is often
3494 used to direct the following discussion to one newsgroup only,
3495 because discussions that are spread over several newsgroup tend to
3496 be fragmented and very difficult to follow.
3498 Also, some source/announcement newsgroups are not indented for discussion;
3499 responses here are directed to other newsgroups."))
3500 (cons 'Newsgroups followup-to)
3501 (cons 'Newsgroups newsgroups))))))
3503 `((Newsgroups . ,posted-to)))
3505 `((Newsgroups . ,newsgroups))))
3506 ,@(and distribution (list (cons 'Distribution distribution)))
3507 ,@(if (or references message-id)
3508 `((References . ,(concat (or references "") (and references " ")
3509 (or message-id "")))))
3511 (not (equal (downcase mct) "never")))
3512 (list (cons 'Cc (if (equal (downcase mct) "always")
3513 (or reply-to from "")
3518 (setq message-reply-headers
3519 (vector 0 subject from date message-id references 0 0 ""))))
3523 (defun message-cancel-news ()
3524 "Cancel an article you posted."
3526 (unless (message-news-p)
3527 (error "This is not a news article; canceling is impossible"))
3528 (when (yes-or-no-p "Do you really want to cancel this article? ")
3529 (let (from newsgroups message-id distribution buf sender)
3531 ;; Get header info. from original article.
3533 (message-narrow-to-head)
3534 (setq from (message-fetch-field "from")
3535 sender (message-fetch-field "sender")
3536 newsgroups (message-fetch-field "newsgroups")
3537 message-id (message-fetch-field "message-id" t)
3538 distribution (message-fetch-field "distribution")))
3539 ;; Make sure that this article was written by the user.
3540 (unless (or (and sender
3543 (downcase (message-make-sender))))
3545 (downcase (cadr (mail-extract-address-components from)))
3546 (downcase (cadr (mail-extract-address-components
3547 (message-make-from))))))
3548 (error "This article is not yours"))
3549 ;; Make control message.
3550 (setq buf (set-buffer (get-buffer-create " *message cancel*")))
3552 (insert "Newsgroups: " newsgroups "\n"
3553 "From: " (message-make-from) "\n"
3554 "Subject: cmsg cancel " message-id "\n"
3555 "Control: cancel " message-id "\n"
3557 (concat "Distribution: " distribution "\n")
3559 mail-header-separator "\n"
3560 message-cancel-message)
3561 (message "Canceling your article...")
3562 (if (let ((message-syntax-checks
3563 'dont-check-for-anything-just-trust-me))
3564 (funcall message-send-news-function))
3565 (message "Canceling your article...done"))
3566 (kill-buffer buf)))))
3569 (defun message-supersede ()
3570 "Start composing a message to supersede the current message.
3571 This is done simply by taking the old article and adding a Supersedes
3572 header line with the old Message-ID."
3574 (let ((cur (current-buffer))
3575 (sender (message-fetch-field "sender"))
3576 (from (message-fetch-field "from")))
3577 ;; Check whether the user owns the article that is to be superseded.
3578 (unless (or (and sender
3581 (downcase (message-make-sender))))
3583 (downcase (cadr (mail-extract-address-components from)))
3584 (downcase (cadr (mail-extract-address-components
3585 (message-make-from))))))
3586 (error "This article is not yours"))
3587 ;; Get a normal message buffer.
3588 (message-pop-to-buffer (message-buffer-name "supersede"))
3589 (insert-buffer-substring cur)
3590 (message-narrow-to-head)
3591 ;; Remove unwanted headers.
3592 (when message-ignored-supersedes-headers
3593 (message-remove-header message-ignored-supersedes-headers t))
3594 (goto-char (point-min))
3595 (if (not (re-search-forward "^Message-ID: " nil t))
3596 (error "No Message-ID in this article")
3597 (replace-match "Supersedes: " t t))
3598 (goto-char (point-max))
3599 (insert mail-header-separator)
3604 (defun message-recover ()
3605 "Reread contents of current buffer from its last auto-save file."
3607 (let ((file-name (make-auto-save-file-name)))
3608 (cond ((save-window-excursion
3609 (if (not (eq system-type 'vax-vms))
3610 (with-output-to-temp-buffer "*Directory*"
3611 (buffer-disable-undo standard-output)
3612 (let ((default-directory "/"))
3614 "ls" nil standard-output nil "-l" file-name))))
3615 (yes-or-no-p (format "Recover auto save file %s? " file-name)))
3616 (let ((buffer-read-only nil))
3618 (insert-file-contents file-name nil)))
3619 (t (error "message-recover cancelled")))))
3621 ;;; Washing Subject:
3623 (defun message-wash-subject (subject)
3624 "Remove junk like \"Re:\", \"(fwd)\", etc. that was added to the subject by previous forwarders, replyers, etc."
3626 (insert-string subject)
3627 (goto-char (point-min))
3628 ;; strip Re/Fwd stuff off the beginning
3629 (while (re-search-forward
3630 "\\([Rr][Ee]:\\|[Ff][Ww][Dd]\\(\\[[0-9]*\\]\\)?:\\|[Ff][Ww]:\\)" nil t)
3633 ;; and gnus-style forwards [foo@bar.com] subject
3634 (goto-char (point-min))
3635 (while (re-search-forward "\\[[^ \t]*\\(@\\|\\.\\)[^ \t]*\\]" nil t)
3639 (goto-char (point-max))
3640 (while (re-search-backward "([Ff][Ww][Dd])" nil t)
3643 ;; and finally, any whitespace that was left-over
3644 (goto-char (point-min))
3645 (while (re-search-forward "^[ \t]+" nil t)
3647 (goto-char (point-max))
3648 (while (re-search-backward "[ \t]+$" nil t)
3653 ;;; Forwarding messages.
3655 (defun message-forward-subject-author-subject (subject)
3656 "Generate a subject for a forwarded message.
3657 The form is: [Source] Subject, where if the original message was mail,
3658 Source is the sender, and if the original message was news, Source is
3659 the list of newsgroups is was posted to."
3661 (or (message-fetch-field
3662 (if (message-news-p) "newsgroups" "from"))
3666 (defun message-forward-subject-fwd (subject)
3667 "Generate a subject for a forwarded message.
3668 The form is: Fwd: Subject, where Subject is the original subject of
3670 (concat "Fwd: " subject))
3672 (defun message-make-forward-subject ()
3673 "Return a Subject header suitable for the message in the current buffer."
3677 (message-narrow-to-head)
3678 (let ((funcs message-make-forward-subject-function)
3679 (subject (if message-wash-forwarded-subjects
3680 (message-wash-subject
3681 (or (message-fetch-field "Subject") ""))
3682 (or (message-fetch-field "Subject") ""))))
3683 ;; Make sure funcs is a list.
3686 (setq funcs (list funcs)))
3687 ;; Apply funcs in order, passing subject generated by previous
3688 ;; func to the next one.
3690 (when (message-functionp (car funcs))
3691 (setq subject (funcall (car funcs) subject)))
3692 (setq funcs (cdr funcs)))
3696 (defun message-forward (&optional news)
3697 "Forward the current message via mail.
3698 Optional NEWS will use news to forward instead of mail."
3700 (let ((cur (current-buffer))
3701 (subject (message-make-forward-subject))
3703 (if news (message-news nil subject) (message-mail nil subject))
3704 ;; Put point where we want it before inserting the forwarded
3706 (if message-signature-before-forwarded-message
3707 (goto-char (point-max))
3708 (message-goto-body))
3709 ;; Make sure we're at the start of the line.
3712 ;; Narrow to the area we are to insert.
3713 (narrow-to-region (point) (point))
3714 ;; Insert the separators and the forwarded buffer.
3715 (insert message-forward-start-separator)
3716 (setq art-beg (point))
3717 (insert-buffer-substring cur)
3718 (goto-char (point-max))
3719 (insert message-forward-end-separator)
3720 (set-text-properties (point-min) (point-max) nil)
3721 ;; Remove all unwanted headers.
3723 (narrow-to-region (point) (if (search-forward "\n\n" nil t)
3726 (goto-char (point-min))
3727 (message-remove-header message-included-forward-headers t nil t)
3729 (message-position-point)))
3732 (defun message-resend (address)
3733 "Resend the current article to ADDRESS."
3734 (interactive "sResend message to: ")
3735 (message "Resending message to %s..." address)
3737 (let ((cur (current-buffer))
3739 ;; We first set up a normal mail buffer.
3740 (set-buffer (get-buffer-create " *message resend*"))
3742 (message-setup `((To . ,address)))
3743 ;; Insert our usual headers.
3744 (message-generate-headers '(From Date To))
3745 (message-narrow-to-headers)
3746 ;; Rename them all to "Resent-*".
3747 (while (re-search-forward "^[A-Za-z]" nil t)
3752 (delete-region (point) (point-max))
3754 ;; Insert the message to be resent.
3755 (insert-buffer-substring cur)
3756 (goto-char (point-min))
3757 (search-forward "\n\n")
3760 (narrow-to-region beg (point))
3761 (message-remove-header message-ignored-resent-headers t)
3762 (goto-char (point-max)))
3763 (insert mail-header-separator)
3764 ;; Rename all old ("Also-")Resent headers.
3765 (while (re-search-backward "^\\(Also-\\)*Resent-" beg t)
3768 ;; Quote any "From " lines at the beginning.
3770 (when (looking-at "From ")
3771 (replace-match "X-From-Line: "))
3774 (kill-buffer (current-buffer)))
3775 (message "Resending message to %s...done" address)))
3778 (defun message-bounce ()
3779 "Re-mail the current message.
3780 This only makes sense if the current message is a bounce message than
3781 contains some mail you have written which has been bounced back to
3784 (let ((cur (current-buffer))
3786 (message-pop-to-buffer (message-buffer-name "bounce"))
3787 (insert-buffer-substring cur)
3789 (message-narrow-to-head)
3790 (if (and (message-fetch-field "Mime-Version")
3791 (setq boundary (message-fetch-field "Content-Type")))
3792 (if (string-match "boundary=\"\\([^\"]+\\)\"" boundary)
3793 (setq boundary (concat (match-string 1 boundary) " *\n"
3794 "Content-Type: message/rfc822"))
3795 (setq boundary nil)))
3797 (goto-char (point-min))
3798 (search-forward "\n\n" nil t)
3800 (re-search-forward boundary nil t)
3802 (and (re-search-forward message-unsent-separator nil t)
3804 (re-search-forward "^Return-Path:.*\n" nil t))
3805 ;; We remove everything before the bounced mail.
3808 (if (re-search-forward "^[^ \n\t]+:" nil t)
3812 (message-narrow-to-head)
3813 (message-remove-header message-ignored-bounced-headers t)
3814 (goto-char (point-max))
3815 (insert mail-header-separator))
3816 (message-position-point)))
3819 ;;; Interactive entry points for new message buffers.
3823 (defun message-mail-other-window (&optional to subject)
3824 "Like `message-mail' command, but display mail buffer in another window."
3826 (let ((pop-up-windows t)
3827 (special-display-buffer-names nil)
3828 (special-display-regexps nil)
3829 (same-window-buffer-names nil)
3830 (same-window-regexps nil))
3831 (message-pop-to-buffer (message-buffer-name "mail" to)))
3832 (let ((message-this-is-mail t))
3833 (message-setup `((To . ,(or to "")) (Subject . ,(or subject ""))))))
3836 (defun message-mail-other-frame (&optional to subject)
3837 "Like `message-mail' command, but display mail buffer in another frame."
3839 (let ((pop-up-frames t)
3840 (special-display-buffer-names nil)
3841 (special-display-regexps nil)
3842 (same-window-buffer-names nil)
3843 (same-window-regexps nil))
3844 (message-pop-to-buffer (message-buffer-name "mail" to)))
3845 (let ((message-this-is-mail t))
3846 (message-setup `((To . ,(or to "")) (Subject . ,(or subject ""))))))
3849 (defun message-news-other-window (&optional newsgroups subject)
3850 "Start editing a news article to be sent."
3852 (let ((pop-up-windows t)
3853 (special-display-buffer-names nil)
3854 (special-display-regexps nil)
3855 (same-window-buffer-names nil)
3856 (same-window-regexps nil))
3857 (message-pop-to-buffer (message-buffer-name "news" nil newsgroups)))
3858 (let ((message-this-is-news t))
3859 (message-setup `((Newsgroups . ,(or newsgroups ""))
3860 (Subject . ,(or subject ""))))))
3863 (defun message-news-other-frame (&optional newsgroups subject)
3864 "Start editing a news article to be sent."
3866 (let ((pop-up-frames t)
3867 (special-display-buffer-names nil)
3868 (special-display-regexps nil)
3869 (same-window-buffer-names nil)
3870 (same-window-regexps nil))
3871 (message-pop-to-buffer (message-buffer-name "news" nil newsgroups)))
3872 (let ((message-this-is-news t))
3873 (message-setup `((Newsgroups . ,(or newsgroups ""))
3874 (Subject . ,(or subject ""))))))
3878 ;; This code should be moved to underline.el (from which it is stolen).
3881 (defun bold-region (start end)
3882 "Bold all nonblank characters in the region.
3883 Works by overstriking characters.
3884 Called from program, takes two arguments START and END
3885 which specify the range to operate on."
3888 (let ((end1 (make-marker)))
3889 (move-marker end1 (max start end))
3890 (goto-char (min start end))
3891 (while (< (point) end1)
3892 (or (looking-at "[_\^@- ]")
3893 (insert (following-char) "\b"))
3894 (forward-char 1)))))
3897 (defun unbold-region (start end)
3898 "Remove all boldness (overstruck characters) in the region.
3899 Called from program, takes two arguments START and END
3900 which specify the range to operate on."
3903 (let ((end1 (make-marker)))
3904 (move-marker end1 (max start end))
3905 (goto-char (min start end))
3906 (while (re-search-forward "\b" end1 t)
3907 (if (eq (following-char) (char-after (- (point) 2)))
3908 (delete-char -2))))))
3910 (defalias 'message-exchange-point-and-mark 'exchange-point-and-mark)
3912 ;; Support for toolbar
3913 (when (string-match "XEmacs\\|Lucid" emacs-version)
3914 (require 'messagexmas))
3916 ;;; Group name completion.
3918 (defvar message-newgroups-header-regexp
3919 "^\\(Newsgroups\\|Followup-To\\|Posted-To\\|Gcc\\):"
3920 "Regexp that match headers that lists groups.")
3922 (defun message-tab ()
3923 "Expand group names in Newsgroups and Followup-To headers.
3924 Do a `tab-to-tab-stop' if not in those headers."
3926 (if (let ((mail-abbrev-mode-regexp message-newgroups-header-regexp))
3927 (mail-abbrev-in-expansion-header-p))
3928 (message-expand-group)
3931 (defvar gnus-active-hashtb)
3932 (defun message-expand-group ()
3933 "Expand the group name under point."
3934 (let* ((b (save-excursion
3939 (skip-chars-forward "^:")
3942 (skip-chars-backward "^, \t\n") (point))))
3943 (completion-ignore-case t)
3944 (string (buffer-substring b (progn (skip-chars-forward "^,\t\n ")
3946 (hashtb (and (boundp 'gnus-active-hashtb) gnus-active-hashtb))
3947 (completions (all-completions string hashtb))
3949 (delete-region b (point))
3951 ((= (length completions) 1)
3952 (if (string= (car completions) string)
3955 (message "Only matching group"))
3956 (insert (car completions))))
3957 ((and (setq comp (try-completion string hashtb))
3958 (not (string= comp string)))
3963 (message "No matching groups")
3964 (save-selected-window
3965 (pop-to-buffer "*Completions*")
3966 (buffer-disable-undo (current-buffer))
3967 (let ((buffer-read-only nil))
3969 (let ((standard-output (current-buffer)))
3970 (display-completion-list (sort completions 'string<)))
3971 (goto-char (point-min))
3972 (delete-region (point) (progn (forward-line 3) (point))))))))))
3976 (defun message-talkative-question (ask question show &rest text)
3977 "Call FUNCTION with argument QUESTION; optionally display TEXT... args.
3978 If SHOW is non-nil, the arguments TEXT... are displayed in a temp buffer.
3979 The following arguments may contain lists of values."
3981 (setq text (message-flatten-list text)))
3982 (save-window-excursion
3984 (with-output-to-temp-buffer " *MESSAGE information message*"
3985 (set-buffer " *MESSAGE information message*")
3986 (mapcar 'princ text)
3987 (goto-char (point-min))))
3988 (funcall ask question))
3989 (funcall ask question)))
3991 (defun message-flatten-list (list)
3992 "Return a new, flat list that contains all elements of LIST.
3994 \(message-flatten-list '(1 (2 3 (4 5 (6))) 7))
3997 (apply 'append (mapcar 'message-flatten-list list)))
4001 (defun message-generate-new-buffer-clone-locals (name &optional varstr)
4002 "Create and return a buffer with a name based on NAME using generate-new-buffer.
4003 Then clone the local variables and values from the old buffer to the
4004 new one, cloning only the locals having a substring matching the
4006 (let ((oldbuf (current-buffer)))
4008 (set-buffer (generate-new-buffer name))
4009 (message-clone-locals oldbuf)
4012 (defun message-clone-locals (buffer)
4013 "Clone the local variables from BUFFER to the current buffer."
4014 (let ((locals (save-excursion
4016 (buffer-local-variables)))
4017 (regexp "^gnus\\|^nn\\|^message"))
4020 (when (and (consp local)
4022 (string-match regexp (symbol-name (car local))))
4024 (set (make-local-variable (car local))
4028 ;;; Miscellaneous functions
4030 ;; stolen (and renamed) from nnheader.el
4031 (defun message-replace-chars-in-string (string from to)
4032 "Replace characters in STRING from FROM to TO."
4033 (let ((string (substring string 0)) ;Copy string.
4034 (len (length string))
4036 ;; Replace all occurrences of FROM with TO.
4038 (when (= (aref string idx) from)
4039 (aset string idx to))
4040 (setq idx (1+ idx)))
4047 (defun message-encode-message-body ()
4048 "Examine the message body, encode it, and add the requisite headers."
4049 (when (featurep 'mule)
4052 (message-narrow-to-headers-or-head)
4053 (message-remove-header
4054 "^Content-Transfer-Encoding:\\|^Content-Type:\\|^Mime-Version:" t)
4055 (goto-char (point-max))
4057 (narrow-to-region (point) (point-max))
4058 (let* ((charset (mm-encode-body))
4059 (encoding (mm-body-encoding)))
4060 (when (consp charset)
4061 (error "Can't encode messages with multiple charsets (yet)"))
4063 (message-narrow-to-headers-or-head)
4064 (goto-char (point-max))
4065 (setq charset (or charset (mm-mule-charset-to-mime-charset 'ascii)))
4066 ;; We don't insert MIME headers if they only say the default.
4067 (unless (and (eq charset 'us-ascii)
4068 (eq encoding '7bit))
4069 (mm-insert-rfc822-headers charset encoding))
4070 (mm-encode-body))))))
4072 (run-hooks 'message-load-hook)
4076 ;;; message.el ends here