1 ;;; message.el --- composing mail and news messages
2 ;; Copyright (C) 1996,97,98 Free Software Foundation, Inc.
4 ;; Author: Lars Magne Ingebrigtsen <larsi@ifi.uio.no>
5 ;; MORIOKA Tomohiko <morioka@jaist.ac.jp>
6 ;; Keywords: mail, news, MIME
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
27 ;; This mode provides mail-sending facilities from within Emacs. It
28 ;; consists mainly of large chunks of code from the sendmail.el,
29 ;; gnus-msg.el and rnewspost.el files.
43 (if (string-match "XEmacs\\|Lucid" emacs-version)
44 (require 'mail-abbrevs)
45 (require 'mailabbrev))
48 (defgroup message '((user-mail-address custom-variable)
49 (user-full-name custom-variable))
50 "Mail and news message composing."
51 :link '(custom-manual "(message)Top")
55 (put 'user-mail-address 'custom-type 'string)
56 (put 'user-full-name 'custom-type 'string)
58 (defgroup message-various nil
59 "Various Message Variables"
60 :link '(custom-manual "(message)Various Message Variables")
63 (defgroup message-buffers nil
65 :link '(custom-manual "(message)Message Buffers")
68 (defgroup message-sending nil
70 :link '(custom-manual "(message)Sending Variables")
73 (defgroup message-interface nil
75 :link '(custom-manual "(message)Interface")
78 (defgroup message-forwarding nil
80 :link '(custom-manual "(message)Forwarding")
81 :group 'message-interface)
83 (defgroup message-insertion nil
85 :link '(custom-manual "(message)Insertion")
88 (defgroup message-headers nil
90 :link '(custom-manual "(message)Message Headers")
93 (defgroup message-news nil
94 "Composing News Messages"
97 (defgroup message-mail nil
98 "Composing Mail Messages"
101 (defgroup message-faces nil
102 "Faces used for message composing."
106 (defcustom message-directory "~/Mail/"
107 "*Directory from which all other mail file variables are derived."
108 :group 'message-various
111 (defcustom message-max-buffers 10
112 "*How many buffers to keep before starting to kill them off."
113 :group 'message-buffers
116 (defcustom message-send-rename-function nil
117 "Function called to rename the buffer after sending it."
118 :group 'message-buffers
121 (defcustom message-fcc-handler-function 'message-output
122 "*A function called to save outgoing articles.
123 This function will be called with the name of the file to store the
124 article in. The default function is `message-output' which saves in Unix
126 :type '(radio (function-item message-output)
127 (function :tag "Other"))
128 :group 'message-sending)
130 (defcustom message-encode-function 'message-maybe-encode
131 "*A function called to encode messages."
132 :group 'message-sending
135 (defcustom message-courtesy-message
136 "The following message is a courtesy copy of an article\nthat has been posted to %s as well.\n\n"
137 "*This is inserted at the start of a mailed copy of a posted message.
138 If the string contains the format spec \"%s\", the Newsgroups
139 the article has been posted to will be inserted there.
140 If this variable is nil, no such courtesy message will be added."
141 :group 'message-sending
144 (defcustom message-ignored-bounced-headers "^\\(Received\\|Return-Path\\):"
145 "*Regexp that matches headers to be removed in resent bounced mail."
146 :group 'message-interface
150 (defcustom message-from-style 'default
151 "*Specifies how \"From\" headers look.
153 If `nil', they contain just the return address like:
155 If `parens', they look like:
156 king@grassland.com (Elvis Parsley)
157 If `angles', they look like:
158 Elvis Parsley <king@grassland.com>
160 Otherwise, most addresses look like `angles', but they look like
161 `parens' if `angles' would need quoting and `parens' would not."
162 :type '(choice (const :tag "simple" nil)
166 :group 'message-headers)
168 (defcustom message-syntax-checks nil
169 ; Guess this one shouldn't be easy to customize...
170 "*Controls what syntax checks should not be performed on outgoing posts.
171 To disable checking of long signatures, for instance, add
172 `(signature . disabled)' to this list.
174 Don't touch this variable unless you really know what you're doing.
176 Checks include subject-cmsg multiple-headers sendsys message-id from
177 long-lines control-chars size new-text redirected-followup signature
178 approved sender empty empty-headers message-id from subject
179 shorten-followup-to existing-newsgroups buffer-file-name unchanged."
180 :group 'message-news)
182 (defcustom message-required-news-headers
183 '(From Newsgroups Subject Date Message-ID
184 (optional . Organization) Lines
185 (optional . X-Newsreader))
186 "*Headers to be generated or prompted for when posting an article.
187 RFC977 and RFC1036 require From, Date, Newsgroups, Subject,
188 Message-ID. Organization, Lines, In-Reply-To, Expires, and
189 X-Newsreader are optional. If don't you want message to insert some
190 header, remove it from this list."
192 :group 'message-headers
193 :type '(repeat sexp))
195 (defcustom message-required-mail-headers
196 '(From Subject Date (optional . In-Reply-To) Message-ID Lines
197 (optional . X-Mailer))
198 "*Headers to be generated or prompted for when mailing a message.
199 RFC822 required that From, Date, To, Subject and Message-ID be
200 included. Organization, Lines and X-Mailer are optional."
202 :group 'message-headers
203 :type '(repeat sexp))
205 (defcustom message-deletable-headers '(Message-ID Date Lines)
206 "Headers to be deleted if they already exist and were generated by message previously."
207 :group 'message-headers
210 (defcustom message-ignored-news-headers
211 "^NNTP-Posting-Host:\\|^Xref:\\|^[BGF]cc:\\|^Resent-Fcc:"
212 "*Regexp of headers to be removed unconditionally before posting."
214 :group 'message-headers
217 (defcustom message-ignored-mail-headers "^[GF]cc:\\|^Resent-Fcc:\\|^Xref:"
218 "*Regexp of headers to be removed unconditionally before mailing."
220 :group 'message-headers
223 (defcustom message-ignored-supersedes-headers "^Path:\\|^Date\\|^NNTP-Posting-Host:\\|^Xref:\\|^Lines:\\|^Received:\\|^X-From-Line:\\|^X-Trace:\\|^X-Complaints-To:\\|Return-Path:\\|^Supersedes:"
224 "*Header lines matching this regexp will be deleted before posting.
225 It's best to delete old Path and Date headers before posting to avoid
227 :group 'message-interface
231 (defcustom message-signature-separator "^-- *$"
232 "Regexp matching the signature separator."
234 :group 'message-various)
236 (defcustom message-elide-elipsis "\n[...]\n\n"
237 "*The string which is inserted for elided text."
239 :group 'message-various)
241 (defcustom message-interactive nil
242 "Non-nil means when sending a message wait for and display errors.
243 nil means let mailer mail back a message to report errors."
244 :group 'message-sending
248 (defcustom message-generate-new-buffers t
249 "*Non-nil means that a new message buffer will be created whenever `mail-setup' is called.
250 If this is a function, call that function with three parameters: The type,
251 the to address and the group name. (Any of these may be nil.) The function
252 should return the new buffer name."
253 :group 'message-buffers
254 :type '(choice (const :tag "off" nil)
258 (defcustom message-kill-buffer-on-exit nil
259 "*Non-nil means that the message buffer will be killed after sending a message."
260 :group 'message-buffers
263 (defvar gnus-local-organization)
264 (defcustom message-user-organization
265 (or (and (boundp 'gnus-local-organization)
266 (stringp gnus-local-organization)
267 gnus-local-organization)
268 (getenv "ORGANIZATION")
270 "*String to be used as an Organization header.
271 If t, use `message-user-organization-file'."
272 :group 'message-headers
273 :type '(choice string
274 (const :tag "consult file" t)))
277 (defcustom message-user-organization-file "/usr/lib/news/organization"
278 "*Local news organization file."
280 :group 'message-headers)
282 (defcustom message-forward-start-separator
283 (concat (mime-make-tag "message" "rfc822") "\n")
284 "*Delimiter inserted before forwarded messages."
285 :group 'message-forwarding
288 (defcustom message-forward-end-separator
290 "*Delimiter inserted after forwarded messages."
291 :group 'message-forwarding
294 (defcustom message-signature-before-forwarded-message t
295 "*If non-nil, put the signature before any included forwarded message."
296 :group 'message-forwarding
299 (defcustom message-included-forward-headers
300 "^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:"
301 "*Regexp matching headers to be included in forwarded messages."
302 :group 'message-forwarding
305 (defcustom message-ignored-resent-headers "^Return-receipt"
306 "*All headers that match this regexp will be deleted when resending a message."
307 :group 'message-interface
310 (defcustom message-ignored-cited-headers "."
311 "*Delete these headers from the messages you yank."
312 :group 'message-insertion
315 (defcustom message-cancel-message "I am canceling my own article."
316 "Message to be inserted in the cancel message."
317 :group 'message-interface
320 ;; Useful to set in site-init.el
322 (defcustom message-send-mail-function 'message-send-mail-with-sendmail
323 "Function to call to send the current buffer as mail.
324 The headers should be delimited by a line whose contents match the
325 variable `mail-header-separator'.
327 Legal values include `message-send-mail-with-sendmail' (the default),
328 `message-send-mail-with-mh', `message-send-mail-with-qmail' and
329 `message-send-mail-with-smtp'."
330 :type '(radio (function-item message-send-mail-with-sendmail)
331 (function-item message-send-mail-with-mh)
332 (function-item message-send-mail-with-qmail)
333 (function-item message-send-mail-with-smtp)
334 (function :tag "Other"))
335 :group 'message-sending
336 :group 'message-mail)
338 ;; 1997-09-29 by MORIOKA Tomohiko
339 (defcustom message-send-news-function 'message-send-news-with-gnus
340 "Function to call to send the current buffer as news.
341 The headers should be delimited by a line whose contents match the
342 variable `mail-header-separator'."
343 :group 'message-sending
347 (defcustom message-reply-to-function nil
348 "Function that should return a list of headers.
349 This function should pick out addresses from the To, Cc, and From headers
350 and respond with new To and Cc headers."
351 :group 'message-interface
354 (defcustom message-wide-reply-to-function nil
355 "Function that should return a list of headers.
356 This function should pick out addresses from the To, Cc, and From headers
357 and respond with new To and Cc headers."
358 :group 'message-interface
361 (defcustom message-followup-to-function nil
362 "Function that should return a list of headers.
363 This function should pick out addresses from the To, Cc, and From headers
364 and respond with new To and Cc headers."
365 :group 'message-interface
368 (defcustom message-use-followup-to 'ask
369 "*Specifies what to do with Followup-To header.
370 If nil, always ignore the header. If it is t, use its value, but
371 query before using the \"poster\" value. If it is the symbol `ask',
372 always query the user whether to use the value. If it is the symbol
373 `use', always use the value."
374 :group 'message-interface
375 :type '(choice (const :tag "ignore" nil)
379 ;; stuff relating to broken sendmail in MMDF
380 (defcustom message-sendmail-f-is-evil nil
381 "*Non-nil means that \"-f username\" should not be added to the sendmail
382 command line, because it is even more evil than leaving it out."
383 :group 'message-sending
386 ;; qmail-related stuff
387 (defcustom message-qmail-inject-program "/var/qmail/bin/qmail-inject"
388 "Location of the qmail-inject program."
389 :group 'message-sending
392 (defcustom message-qmail-inject-args nil
393 "Arguments passed to qmail-inject programs.
394 This should be a list of strings, one string for each argument.
396 For e.g., if you wish to set the envelope sender address so that bounces
397 go to the right place or to deal with listserv's usage of that address, you
398 might set this variable to '(\"-f\" \"you@some.where\")."
399 :group 'message-sending
400 :type '(repeat string))
402 (defvar gnus-post-method)
403 (defvar gnus-select-method)
404 (defcustom message-post-method
405 (cond ((and (boundp 'gnus-post-method)
408 ((boundp 'gnus-select-method)
411 "*Method used to post news."
413 :group 'message-sending
414 ;; This should be the `gnus-select-method' widget, but that might
415 ;; create a dependence to `gnus.el'.
418 (defcustom message-generate-headers-first nil
419 "*If non-nil, generate all possible headers before composing."
420 :group 'message-headers
423 (defcustom message-setup-hook
424 '(message-maybe-setup-default-charset turn-on-mime-edit)
425 "Normal hook, run each time a new outgoing message is initialized.
426 The function `message-setup' runs this hook."
427 :group 'message-various
430 (defcustom message-signature-setup-hook nil
431 "Normal hook, run each time a new outgoing message is initialized.
432 It is run after the headers have been inserted and before
433 the signature is inserted."
434 :group 'message-various
437 (defcustom message-mode-hook nil
438 "Hook run in message mode buffers."
439 :group 'message-various
442 (defcustom message-header-hook '(eword-encode-header)
443 "Hook run in a message mode buffer narrowed to the headers."
444 :group 'message-various
447 (defcustom message-header-setup-hook nil
448 "Hook called narrowed to the headers when setting up a message buffer."
449 :group 'message-various
453 (defcustom message-citation-line-function 'message-insert-citation-line
454 "*Function called to insert the \"Whomever writes:\" line."
456 :group 'message-insertion)
459 (defcustom message-yank-prefix "> "
460 "*Prefix inserted on the lines of yanked messages.
461 nil means use indentation."
463 :group 'message-insertion)
465 (defcustom message-indentation-spaces 3
466 "*Number of spaces to insert at the beginning of each cited line.
467 Used by `message-yank-original' via `message-yank-cite'."
468 :group 'message-insertion
472 (defcustom message-cite-function
473 (if (and (boundp 'mail-citation-hook)
476 'message-cite-original)
477 "*Function for citing an original message.
478 Pre-defined functions include `message-cite-original' and
479 `message-cite-original-without-signature'."
480 :type '(radio (function-item message-cite-original)
481 (function-item message-cite-original-without-signature)
482 (function-item sc-cite-original)
483 (function :tag "Other"))
484 :group 'message-insertion)
487 (defcustom message-indent-citation-function 'message-indent-citation
488 "*Function for modifying a citation just inserted in the mail buffer.
489 This can also be a list of functions. Each function can find the
490 citation between (point) and (mark t). And each function should leave
491 point and mark around the citation text as modified."
493 :group 'message-insertion)
495 (defvar message-abbrevs-loaded nil)
498 (defcustom message-signature t
499 "*String to be inserted at the end of the message buffer.
500 If t, the `message-signature-file' file will be inserted instead.
501 If a function, the result from the function will be used instead.
502 If a form, the result from the form will be used instead."
504 :group 'message-insertion)
507 (defcustom message-signature-file "~/.signature"
508 "*File containing the text inserted at end of message buffer."
510 :group 'message-insertion)
512 (defcustom message-distribution-function nil
513 "*Function called to return a Distribution header."
515 :group 'message-headers
518 (defcustom message-expires 14
519 "Number of days before your article expires."
521 :group 'message-headers
522 :link '(custom-manual "(message)News Headers")
525 (defcustom message-user-path nil
526 "If nil, use the NNTP server name in the Path header.
527 If stringp, use this; if non-nil, use no host name (user name only)."
529 :group 'message-headers
530 :link '(custom-manual "(message)News Headers")
531 :type '(choice (const :tag "nntp" nil)
533 (sexp :tag "none" :format "%t" t)))
535 (defvar message-reply-buffer nil)
536 (defvar message-reply-headers nil)
537 (defvar message-newsreader nil)
538 (defvar message-mailer nil)
539 (defvar message-sent-message-via nil)
540 (defvar message-checksum nil)
541 (defvar message-send-actions nil
542 "A list of actions to be performed upon successful sending of a message.")
543 (defvar message-exit-actions nil
544 "A list of actions to be performed upon exiting after sending a message.")
545 (defvar message-kill-actions nil
546 "A list of actions to be performed before killing a message buffer.")
547 (defvar message-postpone-actions nil
548 "A list of actions to be performed after postponing a message.")
550 (define-widget 'message-header-lines 'text
551 "All header lines must be LFD terminated."
554 :error "All header lines must be newline terminated")
556 (defcustom message-default-headers ""
557 "*A string containing header lines to be inserted in outgoing messages.
558 It is inserted before you edit the message, so you can edit or delete
560 :group 'message-headers
561 :type 'message-header-lines)
563 (defcustom message-default-mail-headers ""
564 "*A string of header lines to be inserted in outgoing mails."
565 :group 'message-headers
567 :type 'message-header-lines)
569 (defcustom message-default-news-headers ""
570 "*A string of header lines to be inserted in outgoing news
572 :group 'message-headers
574 :type 'message-header-lines)
576 ;; Note: could use /usr/ucb/mail instead of sendmail;
577 ;; options -t, and -v if not interactive.
578 (defcustom message-mailer-swallows-blank-line
579 (if (and (string-match "sparc-sun-sunos\\(\\'\\|[^5]\\)"
580 system-configuration)
581 (file-readable-p "/etc/sendmail.cf")
582 (let ((buffer (get-buffer-create " *temp*")))
586 (insert-file-contents "/etc/sendmail.cf")
587 (goto-char (point-min))
588 (let ((case-fold-search nil))
589 (re-search-forward "^OR\\>" nil t)))
590 (kill-buffer buffer))))
591 ;; According to RFC822, "The field-name must be composed of printable
592 ;; ASCII characters (i. e., characters that have decimal values between
593 ;; 33 and 126, except colon)", i. e., any chars except ctl chars,
595 '(looking-at "[ \t]\\|[][!\"#$%&'()*+,-./0-9;<=>?@A-Z\\\\^_`a-z{|}~]+:"))
596 "*Set this non-nil if the system's mailer runs the header and body together.
597 \(This problem exists on Sunos 4 when sendmail is run in remote mode.)
598 The value should be an expression to test whether the problem will
600 :group 'message-sending
603 ;; Ignore errors in case this is used in Emacs 19.
604 ;; Don't use ignore-errors because this is copied into loaddefs.el.
607 (define-mail-user-agent 'message-user-agent
608 'message-mail 'message-send-and-exit
609 'message-kill-buffer 'message-send-hook)
612 (defvar message-mh-deletable-headers '(Message-ID Date Lines Sender)
613 "If non-nil, delete the deletable headers before feeding to mh.")
615 (defvar message-send-method-alist
616 '((news message-news-p message-send-via-news)
617 (mail message-mail-p message-send-via-mail))
618 "Alist of ways to send outgoing messages.
619 Each element has the form
621 \(TYPE PREDICATE FUNCTION)
623 where TYPE is a symbol that names the method; PREDICATE is a function
624 called without any parameters to determine whether the message is
625 a message of type TYPE; and FUNCTION is a function to be called if
626 PREDICATE returns non-nil. FUNCTION is called with one parameter --
629 (defvar message-mail-alias-type 'abbrev
630 "*What alias expansion type to use in Message buffers.
631 The default is `abbrev', which uses mailabbrev. nil switches
634 (defcustom message-autosave-directory
635 (nnheader-concat message-directory "drafts/")
636 "*Directory where Message autosaves buffers if Gnus isn't running.
637 If nil, Message won't autosave."
638 :group 'message-buffers
641 ;;; Internal variables.
642 ;;; Well, not really internal.
644 (defvar message-mode-syntax-table
645 (let ((table (copy-syntax-table text-mode-syntax-table)))
646 (modify-syntax-entry ?% ". " table)
648 "Syntax table used while in Message mode.")
650 (defvar message-mode-abbrev-table text-mode-abbrev-table
651 "Abbrev table used in Message mode buffers.
652 Defaults to `text-mode-abbrev-table'.")
653 (defgroup message-headers nil
655 :link '(custom-manual "(message)Variables")
658 (defface message-header-to-face
661 (:foreground "green2" :bold t))
664 (:foreground "MidnightBlue" :bold t))
666 (:bold t :italic t)))
667 "Face used for displaying From headers."
668 :group 'message-faces)
670 (defface message-header-cc-face
673 (:foreground "green4" :bold t))
676 (:foreground "MidnightBlue"))
679 "Face used for displaying Cc headers."
680 :group 'message-faces)
682 (defface message-header-subject-face
685 (:foreground "green3"))
688 (:foreground "navy blue" :bold t))
691 "Face used for displaying subject headers."
692 :group 'message-faces)
694 (defface message-header-newsgroups-face
697 (:foreground "yellow" :bold t :italic t))
700 (:foreground "blue4" :bold t :italic t))
702 (:bold t :italic t)))
703 "Face used for displaying newsgroups headers."
704 :group 'message-faces)
706 (defface message-header-other-face
709 (:foreground "#b00000"))
712 (:foreground "steel blue"))
714 (:bold t :italic t)))
715 "Face used for displaying newsgroups headers."
716 :group 'message-faces)
718 (defface message-header-name-face
721 (:foreground "DarkGreen"))
724 (:foreground "cornflower blue"))
727 "Face used for displaying header names."
728 :group 'message-faces)
730 (defface message-header-xheader-face
733 (:foreground "blue"))
736 (:foreground "blue"))
739 "Face used for displaying X-Header headers."
740 :group 'message-faces)
742 (defface message-separator-face
745 (:foreground "blue3"))
748 (:foreground "brown"))
751 "Face used for displaying the separator."
752 :group 'message-faces)
754 (defface message-cited-text-face
763 "Face used for displaying cited text names."
764 :group 'message-faces)
766 (defvar message-font-lock-keywords
767 (let* ((cite-prefix "A-Za-z")
768 (cite-suffix (concat cite-prefix "0-9_.@-"))
769 (content "[ \t]*\\(.+\\(\n[ \t].*\\)*\\)"))
770 `((,(concat "^\\([Tt]o:\\)" content)
771 (1 'message-header-name-face)
772 (2 'message-header-to-face nil t))
773 (,(concat "^\\(^[GBF]?[Cc][Cc]:\\|^[Rr]eply-[Tt]o:\\)" content)
774 (1 'message-header-name-face)
775 (2 'message-header-cc-face nil t))
776 (,(concat "^\\([Ss]ubject:\\)" content)
777 (1 'message-header-name-face)
778 (2 'message-header-subject-face nil t))
779 (,(concat "^\\([Nn]ewsgroups:\\|Followup-[Tt]o:\\)" content)
780 (1 'message-header-name-face)
781 (2 'message-header-newsgroups-face nil t))
782 (,(concat "^\\([A-Z][^: \n\t]+:\\)" content)
783 (1 'message-header-name-face)
784 (2 'message-header-other-face nil t))
785 (,(concat "^\\(X-[A-Za-z0-9-]+\\|In-Reply-To\\):" content)
786 (1 'message-header-name-face)
787 (2 'message-header-name-face))
788 ,@(if (and mail-header-separator
789 (not (equal mail-header-separator "")))
790 `((,(concat "^\\(" (regexp-quote mail-header-separator) "\\)$")
791 1 'message-separator-face))
794 "\\([" cite-prefix "]+[" cite-suffix "]*\\)?"
796 (0 'message-cited-text-face))))
797 "Additional expressions to highlight in Message mode.")
799 ;; XEmacs does it like this. For Emacs, we have to set the
800 ;; `font-lock-defaults' buffer-local variable.
801 (put 'message-mode 'font-lock-defaults '(message-font-lock-keywords t))
803 (defvar message-face-alist
804 '((bold . bold-region)
805 (underline . underline-region)
806 (default . (lambda (b e)
808 (ununderline-region b e))))
809 "Alist of mail and news faces for facemenu.
810 The cdr of ech entry is a function for applying the face to a region.")
812 (defcustom message-send-hook nil
813 "Hook run before sending messages."
814 :group 'message-various
815 :options '(ispell-message)
818 (defcustom message-send-mail-hook nil
819 "Hook run before sending mail messages."
820 :group 'message-various
823 (defcustom message-send-news-hook nil
824 "Hook run before sending news messages."
825 :group 'message-various
828 (defcustom message-sent-hook nil
829 "Hook run after sending messages."
830 :group 'message-various
833 ;;; Internal variables.
835 (defvar message-buffer-list nil)
836 (defvar message-this-is-news nil)
837 (defvar message-this-is-mail nil)
838 (defvar message-draft-article nil)
840 ;; Byte-compiler warning
841 (defvar gnus-active-hashtb)
842 (defvar gnus-read-active-file)
844 ;;; Regexp matching the delimiter of messages in UNIX mail format
845 ;;; (UNIX From lines), minus the initial ^. It should be a copy
846 ;;; of rmail.el's rmail-unix-mail-delimiter.
847 (defvar message-unix-mail-delimiter
848 (let ((time-zone-regexp
849 (concat "\\([A-Z]?[A-Z]?[A-Z][A-Z]\\( DST\\)?"
850 "\\|[-+]?[0-9][0-9][0-9][0-9]"
856 ;; Many things can happen to an RFC 822 mailbox before it is put into
857 ;; a `From' line. The leading phrase can be stripped, e.g.
858 ;; `Joe <@w.x:joe@y.z>' -> `<@w.x:joe@y.z>'. The <> can be stripped, e.g.
859 ;; `<@x.y:joe@y.z>' -> `@x.y:joe@y.z'. Everything starting with a CRLF
860 ;; can be removed, e.g.
861 ;; From: joe@y.z (Joe K
863 ;; can yield `From joe@y.z (Joe K Fri Mar 22 08:11:15 1996', and
866 ;; can yield `From Joe User Fri Mar 22 08:11:15 1996'.
867 ;; The mailbox can be removed or be replaced by white space, e.g.
868 ;; From: "Joe User"{space}{tab}
870 ;; can yield `From {space}{tab} Fri Mar 22 08:11:15 1996',
871 ;; where {space} and {tab} represent the Ascii space and tab characters.
872 ;; We want to match the results of any of these manglings.
873 ;; The following regexp rejects names whose first characters are
874 ;; obviously bogus, but after that anything goes.
875 "\\([^\0-\b\n-\r\^?].*\\)? "
877 ;; The time the message was sent.
878 "\\([^\0-\r \^?]+\\) +" ; day of the week
879 "\\([^\0-\r \^?]+\\) +" ; month
880 "\\([0-3]?[0-9]\\) +" ; day of month
881 "\\([0-2][0-9]:[0-5][0-9]\\(:[0-6][0-9]\\)?\\) *" ; time of day
883 ;; Perhaps a time zone, specified by an abbreviation, or by a
888 " \\([0-9][0-9]+\\) *"
890 ;; On some systems the time zone can appear after the year, too.
894 "\\(remote from .*\\)?"
897 "Regexp matching the delimiter of messages in UNIX mail format.")
899 (defvar message-unsent-separator
900 (concat "^ *---+ +Unsent message follows +---+ *$\\|"
901 "^ *---+ +Returned message +---+ *$\\|"
902 "^Start of returned message$\\|"
903 "^ *---+ +Original message +---+ *$\\|"
904 "^ *--+ +begin message +--+ *$\\|"
905 "^ *---+ +Original message follows +---+ *$\\|"
906 "^|? *---+ +Message text follows: +---+ *|?$")
907 "A regexp that matches the separator before the text of a failed message.")
909 (defvar message-header-format-alist
911 (To . message-fill-address)
912 (Cc . message-fill-address)
923 (References . message-fill-references)
926 "Alist used for formatting headers.")
929 (autoload 'message-setup-toolbar "messagexmas")
930 (autoload 'mh-new-draft-name "mh-comp")
931 (autoload 'mh-send-letter "mh-comp")
932 (autoload 'gnus-point-at-eol "gnus-util")
933 (autoload 'gnus-point-at-bol "gnus-util")
934 (autoload 'gnus-output-to-mail "gnus-util")
935 (autoload 'gnus-output-to-rmail "gnus-util")
936 (autoload 'mail-abbrev-in-expansion-header-p "mailabbrev")
937 (autoload 'nndraft-request-associate-buffer "nndraft")
938 (autoload 'nndraft-request-expire-articles "nndraft")
939 (autoload 'gnus-open-server "gnus-int")
940 (autoload 'gnus-request-post "gnus-int")
941 (autoload 'gnus-alive-p "gnus-util")
942 (autoload 'rmail-output "rmail"))
947 ;;; Utility functions.
950 (defmacro message-y-or-n-p (question show &rest text)
951 "Ask QUESTION, displaying the rest of the arguments in a temp. buffer if SHOW"
952 `(message-talkative-question 'y-or-n-p ,question ,show ,@text))
954 ;; Delete the current line (and the next N lines.);
955 (defmacro message-delete-line (&optional n)
956 `(delete-region (progn (beginning-of-line) (point))
957 (progn (forward-line ,(or n 1)) (point))))
959 (defun message-tokenize-header (header &optional separator)
960 "Split HEADER into a list of header elements.
961 \",\" is used as the separator."
964 (let ((regexp (format "[%s]+" (or separator ",")))
969 (message-set-work-buffer)
971 (goto-char (point-min))
976 (cond ((and (> (point) beg)
978 (and (looking-at regexp)
981 (push (buffer-substring beg (point)) elems)
982 (setq beg (match-end 0)))
983 ((= (following-char) ?\")
984 (setq quoted (not quoted)))
985 ((and (= (following-char) ?\()
988 ((and (= (following-char) ?\))
993 (defun message-mail-file-mbox-p (file)
994 "Say whether FILE looks like a Unix mbox file."
995 (when (and (file-exists-p file)
996 (file-readable-p file)
997 (file-regular-p file))
998 (nnheader-temp-write nil
999 (nnheader-insert-file-contents file)
1000 (goto-char (point-min))
1001 (looking-at message-unix-mail-delimiter))))
1003 (defun message-fetch-field (header &optional not-all)
1004 "The same as `mail-fetch-field', only remove all newlines."
1005 (let ((value (mail-fetch-field header nil (not not-all))))
1007 (nnheader-replace-chars-in-string value ?\n ? ))))
1009 (defun message-add-header (&rest headers)
1010 "Add the HEADERS to the message header, skipping those already present."
1013 (unless (string-match "^\\([^:]+\\):[ \t]*[^ \t]" (car headers))
1014 (error "Invalid header `%s'" (car headers)))
1015 (setq hclean (match-string 1 (car headers)))
1017 (message-narrow-to-headers)
1018 (unless (re-search-forward (concat "^" (regexp-quote hclean) ":") nil t)
1019 (insert (car headers) ?\n))))
1020 (setq headers (cdr headers))))
1022 (defun message-fetch-reply-field (header)
1023 "Fetch FIELD from the message we're replying to."
1024 (when (and message-reply-buffer
1025 (buffer-name message-reply-buffer))
1027 (set-buffer message-reply-buffer)
1028 (message-fetch-field header))))
1030 (defun message-set-work-buffer ()
1031 (if (get-buffer " *message work*")
1033 (set-buffer " *message work*")
1035 (set-buffer (get-buffer-create " *message work*"))
1036 (kill-all-local-variables)
1037 (buffer-disable-undo (current-buffer))))
1039 (defun message-functionp (form)
1040 "Return non-nil if FORM is funcallable."
1041 (or (and (symbolp form) (fboundp form))
1042 (and (listp form) (eq (car form) 'lambda))
1043 (byte-code-function-p form)))
1045 (defun message-strip-subject-re (subject)
1046 "Remove \"Re:\" from subject lines."
1047 (if (string-match "^[Rr][Ee]: *" subject)
1048 (substring subject (match-end 0))
1051 (defun message-remove-header (header &optional is-regexp first reverse)
1052 "Remove HEADER in the narrowed buffer.
1053 If REGEXP, HEADER is a regular expression.
1054 If FIRST, only remove the first instance of the header.
1055 Return the number of headers removed."
1056 (goto-char (point-min))
1057 (let ((regexp (if is-regexp header (concat "^" header ":")))
1059 (case-fold-search t)
1061 (while (and (not (eobp))
1064 (not (looking-at regexp))
1065 (looking-at regexp))
1072 ;; There might be a continuation header, so we have to search
1073 ;; until we find a new non-continuation line.
1076 (if (re-search-forward "^[^ \t]" nil t)
1077 (goto-char (match-beginning 0))
1080 (if (re-search-forward "^[^ \t]" nil t)
1081 (goto-char (match-beginning 0))
1085 (defun message-narrow-to-headers ()
1086 "Narrow the buffer to the head of the message."
1089 (goto-char (point-min))
1090 (if (re-search-forward
1091 (concat "^" (regexp-quote mail-header-separator) "\n") nil t)
1094 (goto-char (point-min)))
1096 (defun message-narrow-to-head ()
1097 "Narrow the buffer to the head of the message."
1100 (goto-char (point-min))
1101 (if (search-forward "\n\n" nil 1)
1104 (goto-char (point-min)))
1106 (defun message-news-p ()
1107 "Say whether the current buffer contains a news message."
1108 (or message-this-is-news
1111 (message-narrow-to-headers)
1112 (and (message-fetch-field "newsgroups")
1113 (not (message-fetch-field "posted-to")))))))
1115 (defun message-mail-p ()
1116 "Say whether the current buffer contains a mail message."
1117 (or message-this-is-mail
1120 (message-narrow-to-headers)
1121 (or (message-fetch-field "to")
1122 (message-fetch-field "cc")
1123 (message-fetch-field "bcc"))))))
1125 (defun message-next-header ()
1126 "Go to the beginning of the next header."
1128 (or (eobp) (forward-char 1))
1129 (not (if (re-search-forward "^[^ \t]" nil t)
1131 (goto-char (point-max)))))
1133 (defun message-sort-headers-1 ()
1134 "Sort the buffer as headers using `message-rank' text props."
1135 (goto-char (point-min))
1137 nil 'message-next-header
1139 (message-next-header)
1143 (or (get-text-property (point) 'message-rank)
1146 (defun message-sort-headers ()
1147 "Sort the headers of the current message according to `message-header-format-alist'."
1151 (let ((max (1+ (length message-header-format-alist)))
1153 (message-narrow-to-headers)
1154 (while (re-search-forward "^[^ \n]+:" nil t)
1156 (match-beginning 0) (1+ (match-beginning 0))
1158 (if (setq rank (length (memq (assq (intern (buffer-substring
1160 (1- (match-end 0))))
1161 message-header-format-alist)
1162 message-header-format-alist)))
1165 (message-sort-headers-1))))
1175 (defvar message-mode-map nil)
1177 (unless message-mode-map
1178 (setq message-mode-map (copy-keymap text-mode-map))
1179 (define-key message-mode-map "\C-c?" 'describe-mode)
1181 (define-key message-mode-map "\C-c\C-f\C-t" 'message-goto-to)
1182 (define-key message-mode-map "\C-c\C-f\C-b" 'message-goto-bcc)
1183 (define-key message-mode-map "\C-c\C-f\C-w" 'message-goto-fcc)
1184 (define-key message-mode-map "\C-c\C-f\C-c" 'message-goto-cc)
1185 (define-key message-mode-map "\C-c\C-f\C-s" 'message-goto-subject)
1186 (define-key message-mode-map "\C-c\C-f\C-r" 'message-goto-reply-to)
1187 (define-key message-mode-map "\C-c\C-f\C-n" 'message-goto-newsgroups)
1188 (define-key message-mode-map "\C-c\C-f\C-d" 'message-goto-distribution)
1189 (define-key message-mode-map "\C-c\C-f\C-f" 'message-goto-followup-to)
1190 (define-key message-mode-map "\C-c\C-f\C-k" 'message-goto-keywords)
1191 (define-key message-mode-map "\C-c\C-f\C-u" 'message-goto-summary)
1192 (define-key message-mode-map "\C-c\C-b" 'message-goto-body)
1193 (define-key message-mode-map "\C-c\C-i" 'message-goto-signature)
1195 (define-key message-mode-map "\C-c\C-t" 'message-insert-to)
1196 (define-key message-mode-map "\C-c\C-n" 'message-insert-newsgroups)
1198 (define-key message-mode-map "\C-c\C-y" 'message-yank-original)
1199 (define-key message-mode-map "\C-c\C-q" 'message-fill-yanked-message)
1200 (define-key message-mode-map "\C-c\C-w" 'message-insert-signature)
1201 (define-key message-mode-map "\C-c\C-r" 'message-caesar-buffer-body)
1202 (define-key message-mode-map "\C-c\C-o" 'message-sort-headers)
1203 (define-key message-mode-map "\C-c\M-r" 'message-rename-buffer)
1205 (define-key message-mode-map "\C-c\C-c" 'message-send-and-exit)
1206 (define-key message-mode-map "\C-c\C-s" 'message-send)
1207 (define-key message-mode-map "\C-c\C-k" 'message-kill-buffer)
1208 (define-key message-mode-map "\C-c\C-d" 'message-dont-send)
1210 (define-key message-mode-map "\C-c\C-e" 'message-elide-region)
1211 (define-key message-mode-map "\C-c\C-v" 'message-delete-not-region)
1212 (define-key message-mode-map "\C-c\C-z" 'message-kill-to-signature)
1213 (define-key message-mode-map "\M-\r" 'message-newline-and-reformat)
1215 (define-key message-mode-map "\t" 'message-tab))
1218 message-mode-menu message-mode-map "Message Menu."
1220 ["Sort Headers" message-sort-headers t]
1221 ["Yank Original" message-yank-original t]
1222 ["Fill Yanked Message" message-fill-yanked-message t]
1223 ["Insert Signature" message-insert-signature t]
1224 ["Caesar (rot13) Message" message-caesar-buffer-body t]
1225 ["Caesar (rot13) Region" message-caesar-region (mark t)]
1226 ["Elide Region" message-elide-region (mark t)]
1227 ["Delete Outside Region" message-delete-not-region (mark t)]
1228 ["Kill To Signature" message-kill-to-signature t]
1229 ["Newline and Reformat" message-newline-and-reformat t]
1230 ["Rename buffer" message-rename-buffer t]
1231 ["Spellcheck" ispell-message t]
1233 ["Send Message" message-send-and-exit t]
1234 ["Abort Message" message-dont-send t]))
1237 message-mode-field-menu message-mode-map ""
1239 ["Fetch To" message-insert-to t]
1240 ["Fetch Newsgroups" message-insert-newsgroups t]
1242 ["To" message-goto-to t]
1243 ["Subject" message-goto-subject t]
1244 ["Cc" message-goto-cc t]
1245 ["Reply-To" message-goto-reply-to t]
1246 ["Summary" message-goto-summary t]
1247 ["Keywords" message-goto-keywords t]
1248 ["Newsgroups" message-goto-newsgroups t]
1249 ["Followup-To" message-goto-followup-to t]
1250 ["Distribution" message-goto-distribution t]
1251 ["Body" message-goto-body t]
1252 ["Signature" message-goto-signature t]))
1254 (defvar facemenu-add-face-function)
1255 (defvar facemenu-remove-face-function)
1258 (defun message-mode ()
1259 "Major mode for editing mail and news to be sent.
1260 Like Text Mode but with these additional commands:
1261 C-c C-s message-send (send the message) C-c C-c message-send-and-exit
1262 C-c C-f move to a header field (and create it if there isn't):
1263 C-c C-f C-t move to To C-c C-f C-s move to Subject
1264 C-c C-f C-c move to Cc C-c C-f C-b move to Bcc
1265 C-c C-f C-w move to Fcc C-c C-f C-r move to Reply-To
1266 C-c C-f C-u move to Summary C-c C-f C-n move to Newsgroups
1267 C-c C-f C-k move to Keywords C-c C-f C-d move to Distribution
1268 C-c C-f C-f move to Followup-To
1269 C-c C-t message-insert-to (add a To header to a news followup)
1270 C-c C-n message-insert-newsgroups (add a Newsgroup header to a news reply)
1271 C-c C-b message-goto-body (move to beginning of message text).
1272 C-c C-i message-goto-signature (move to the beginning of the signature).
1273 C-c C-w message-insert-signature (insert `message-signature-file' file).
1274 C-c C-y message-yank-original (insert current message, if any).
1275 C-c C-q message-fill-yanked-message (fill what was yanked).
1276 C-c C-e message-elide-region (elide the text between point and mark).
1277 C-c C-z message-kill-to-signature (kill the text up to the signature).
1278 C-c C-r message-caesar-buffer-body (rot13 the message body)."
1280 (kill-all-local-variables)
1281 (make-local-variable 'message-reply-buffer)
1282 (setq message-reply-buffer nil)
1283 (make-local-variable 'message-send-actions)
1284 (make-local-variable 'message-exit-actions)
1285 (make-local-variable 'message-kill-actions)
1286 (make-local-variable 'message-postpone-actions)
1287 (make-local-variable 'message-draft-article)
1288 (make-local-hook 'kill-buffer-hook)
1289 (set-syntax-table message-mode-syntax-table)
1290 (use-local-map message-mode-map)
1291 (setq local-abbrev-table message-mode-abbrev-table)
1292 (setq major-mode 'message-mode)
1293 (setq mode-name "Message")
1294 (setq buffer-offer-save t)
1295 (make-local-variable 'facemenu-add-face-function)
1296 (make-local-variable 'facemenu-remove-face-function)
1297 (setq facemenu-add-face-function
1299 (let ((face-fun (cdr (assq face message-face-alist))))
1301 (funcall face-fun (point) end)
1302 (error "Face %s not configured for %s mode" face mode-name)))
1304 facemenu-remove-face-function t)
1305 (make-local-variable 'paragraph-separate)
1306 (make-local-variable 'paragraph-start)
1307 (setq paragraph-start
1308 (concat (regexp-quote mail-header-separator)
1309 "$\\|[ \t]*[-_][-_][-_]+$\\|"
1311 ;;!!! Uhm... shurely this can't be right?
1312 "[> " (regexp-quote message-yank-prefix) "]+$\\|"
1314 (setq paragraph-separate
1315 (concat (regexp-quote mail-header-separator)
1316 "$\\|[ \t]*[-_][-_][-_]+$\\|"
1318 "[> " (regexp-quote message-yank-prefix) "]+$\\|"
1319 paragraph-separate))
1320 (make-local-variable 'message-reply-headers)
1321 (setq message-reply-headers nil)
1322 (make-local-variable 'message-newsreader)
1323 (make-local-variable 'message-mailer)
1324 (make-local-variable 'message-post-method)
1325 (make-local-variable 'message-sent-message-via)
1326 (setq message-sent-message-via nil)
1327 (make-local-variable 'message-checksum)
1328 (setq message-checksum nil)
1329 ;;(when (fboundp 'mail-hist-define-keys)
1330 ;; (mail-hist-define-keys))
1331 (when (string-match "XEmacs\\|Lucid" emacs-version)
1332 (message-setup-toolbar))
1333 (easy-menu-add message-mode-menu message-mode-map)
1334 (easy-menu-add message-mode-field-menu message-mode-map)
1335 ;; Allow mail alias things.
1336 (when (eq message-mail-alias-type 'abbrev)
1337 (if (fboundp 'mail-abbrevs-setup)
1338 (mail-abbrevs-setup)
1339 (funcall (intern "mail-aliases-setup"))))
1340 (message-set-auto-save-file-name)
1341 (unless (string-match "XEmacs" emacs-version)
1342 (set (make-local-variable 'font-lock-defaults)
1343 '(message-font-lock-keywords t)))
1344 (make-local-variable 'adaptive-fill-regexp)
1345 (setq adaptive-fill-regexp
1346 (concat "[ \t]*[-a-z0-9A-Z]*>+[ \t]*\\|" adaptive-fill-regexp))
1347 (unless (boundp 'adaptive-fill-first-line-regexp)
1348 (setq adaptive-fill-first-line-regexp nil))
1349 (make-local-variable 'adaptive-fill-first-line-regexp)
1350 (setq adaptive-fill-first-line-regexp
1351 (concat "[ \t]*[-a-z0-9A-Z]*>+[ \t]*\\|"
1352 adaptive-fill-first-line-regexp))
1353 (run-hooks 'text-mode-hook 'message-mode-hook))
1358 ;;; Message mode commands
1361 ;;; Movement commands
1363 (defun message-goto-to ()
1364 "Move point to the To header."
1366 (message-position-on-field "To"))
1368 (defun message-goto-subject ()
1369 "Move point to the Subject header."
1371 (message-position-on-field "Subject"))
1373 (defun message-goto-cc ()
1374 "Move point to the Cc header."
1376 (message-position-on-field "Cc" "To"))
1378 (defun message-goto-bcc ()
1379 "Move point to the Bcc header."
1381 (message-position-on-field "Bcc" "Cc" "To"))
1383 (defun message-goto-fcc ()
1384 "Move point to the Fcc header."
1386 (message-position-on-field "Fcc" "To" "Newsgroups"))
1388 (defun message-goto-reply-to ()
1389 "Move point to the Reply-To header."
1391 (message-position-on-field "Reply-To" "Subject"))
1393 (defun message-goto-newsgroups ()
1394 "Move point to the Newsgroups header."
1396 (message-position-on-field "Newsgroups"))
1398 (defun message-goto-distribution ()
1399 "Move point to the Distribution header."
1401 (message-position-on-field "Distribution"))
1403 (defun message-goto-followup-to ()
1404 "Move point to the Followup-To header."
1406 (message-position-on-field "Followup-To" "Newsgroups"))
1408 (defun message-goto-keywords ()
1409 "Move point to the Keywords header."
1411 (message-position-on-field "Keywords" "Subject"))
1413 (defun message-goto-summary ()
1414 "Move point to the Summary header."
1416 (message-position-on-field "Summary" "Subject"))
1418 (defun message-goto-body ()
1419 "Move point to the beginning of the message body."
1421 (if (looking-at "[ \t]*\n") (expand-abbrev))
1422 (goto-char (point-min))
1423 (search-forward (concat "\n" mail-header-separator "\n") nil t))
1425 (defun message-goto-signature ()
1426 "Move point to the beginning of the message signature."
1428 (goto-char (point-min))
1429 (if (re-search-forward message-signature-separator nil t)
1431 (goto-char (point-max))))
1435 (defun message-insert-to (&optional force)
1436 "Insert a To header that points to the author of the article being replied to.
1437 If the original author requested not to be sent mail, the function signals
1439 With the prefix argument FORCE, insert the header anyway."
1441 (let ((co (message-fetch-reply-field "mail-copies-to")))
1442 (when (and (null force)
1444 (equal (downcase co) "never"))
1445 (error "The user has requested not to have copies sent via mail")))
1446 (when (and (message-position-on-field "To")
1447 (mail-fetch-field "to")
1448 (not (string-match "\\` *\\'" (mail-fetch-field "to"))))
1450 (insert (or (message-fetch-reply-field "reply-to")
1451 (message-fetch-reply-field "from") "")))
1453 (defun message-insert-newsgroups ()
1454 "Insert the Newsgroups header from the article being replied to."
1456 (when (and (message-position-on-field "Newsgroups")
1457 (mail-fetch-field "newsgroups")
1458 (not (string-match "\\` *\\'" (mail-fetch-field "newsgroups"))))
1460 (insert (or (message-fetch-reply-field "newsgroups") "")))
1464 ;;; Various commands
1466 (defun message-delete-not-region (beg end)
1467 "Delete everything in the body of the current message that is outside of the region."
1471 (delete-region (point) (progn (message-goto-signature)
1476 (delete-region beg (progn (message-goto-body)
1479 (message-goto-signature)
1482 (defun message-kill-to-signature ()
1483 "Deletes all text up to the signature."
1485 (let ((point (point)))
1486 (message-goto-signature)
1489 (kill-region point (point))
1493 (defun message-newline-and-reformat ()
1494 "Insert four newlines, and then reformat if inside quoted text."
1496 (let ((point (point))
1500 (setq quoted (looking-at (regexp-quote message-yank-prefix))))
1503 (insert message-yank-prefix))
1504 (fill-paragraph nil)
1508 (defun message-insert-signature (&optional force)
1509 "Insert a signature. See documentation for the `message-signature' variable."
1510 (interactive (list 0))
1513 ((and (null message-signature)
1516 (goto-char (point-max))
1517 (not (re-search-backward
1518 message-signature-separator nil t))))
1519 ((and (null message-signature)
1522 ((message-functionp message-signature)
1523 (funcall message-signature))
1524 ((listp message-signature)
1525 (eval message-signature))
1526 (t message-signature)))
1528 (cond ((stringp signature)
1530 ((and (eq t signature)
1531 message-signature-file
1532 (file-exists-p message-signature-file))
1535 (goto-char (point-max))
1536 ;; Insert the signature.
1540 (if (eq signature t)
1541 (insert-file-contents message-signature-file)
1543 (goto-char (point-max))
1544 (or (bolp) (insert "\n")))))
1546 (defun message-elide-region (b e)
1547 "Elide the text between point and mark.
1548 An ellipsis (from `message-elide-elipsis') will be inserted where the
1554 (insert message-elide-elipsis))
1556 (defvar message-caesar-translation-table nil)
1558 (defun message-caesar-region (b e &optional n)
1559 "Caesar rotation of region by N, default 13, for decrypting netnews."
1562 (min (point) (or (mark t) (point)))
1563 (max (point) (or (mark t) (point)))
1564 (when current-prefix-arg
1565 (prefix-numeric-value current-prefix-arg))))
1567 (setq n (if (numberp n) (mod n 26) 13)) ;canonize N
1568 (unless (or (zerop n) ; no action needed for a rot of 0
1569 (= b e)) ; no region to rotate
1570 ;; We build the table, if necessary.
1571 (when (or (not message-caesar-translation-table)
1572 (/= (aref message-caesar-translation-table ?a) (+ ?a n)))
1573 (setq message-caesar-translation-table
1574 (message-make-caesar-translation-table n)))
1575 ;; Then we translate the region. Do it this way to retain
1578 (subst-char-in-region
1579 b (1+ b) (char-after b)
1580 (aref message-caesar-translation-table (char-after b)))
1583 (defun message-make-caesar-translation-table (n)
1584 "Create a rot table with offset N."
1586 (table (make-string 256 0)))
1587 (while (< (incf i) 256)
1590 (substring table 0 ?A)
1591 (substring table (+ ?A n) (+ ?A n (- 26 n)))
1592 (substring table ?A (+ ?A n))
1593 (substring table (+ ?A 26) ?a)
1594 (substring table (+ ?a n) (+ ?a n (- 26 n)))
1595 (substring table ?a (+ ?a n))
1596 (substring table (+ ?a 26) 255))))
1598 (defun message-caesar-buffer-body (&optional rotnum)
1599 "Caesar rotates all letters in the current buffer by 13 places.
1600 Used to encode/decode possiblyun offensive messages (commonly in net.jokes).
1601 With prefix arg, specifies the number of places to rotate each letter forward.
1602 Mail and USENET news headers are not rotated."
1603 (interactive (if current-prefix-arg
1604 (list (prefix-numeric-value current-prefix-arg))
1608 (when (message-goto-body)
1609 (narrow-to-region (point) (point-max)))
1610 (message-caesar-region (point-min) (point-max) rotnum))))
1612 (defun message-pipe-buffer-body (program)
1613 "Pipe the message body in the current buffer through PROGRAM."
1616 (when (message-goto-body)
1617 (narrow-to-region (point) (point-max)))
1618 (let ((body (buffer-substring (point-min) (point-max))))
1619 (unless (equal 0 (call-process-region
1620 (point-min) (point-max) program t t))
1622 (message "%s failed." program))))))
1624 (defun message-rename-buffer (&optional enter-string)
1625 "Rename the *message* buffer to \"*message* RECIPIENT\".
1626 If the function is run with a prefix, it will ask for a new buffer
1627 name, rather than giving an automatic name."
1628 (interactive "Pbuffer name: ")
1631 (goto-char (point-min))
1632 (narrow-to-region (point)
1633 (search-forward mail-header-separator nil 'end))
1635 (if (message-news-p) (message-fetch-field "Newsgroups")
1636 (message-fetch-field "To"))
1639 (if (string-match "," mail-to)
1640 (concat (substring mail-to 0 (match-beginning 0)) ", ...")
1642 (name-default (concat "*message* " mail-trimmed-to))
1643 (name (if enter-string
1644 (read-string "New buffer name: " name-default)
1646 (rename-buffer name t)))))
1648 (defun message-fill-yanked-message (&optional justifyp)
1649 "Fill the paragraphs of a message yanked into this one.
1650 Numeric argument means justify as well."
1653 (goto-char (point-min))
1654 (search-forward (concat "\n" mail-header-separator "\n") nil t)
1655 (let ((fill-prefix message-yank-prefix))
1656 (fill-individual-paragraphs (point) (point-max) justifyp t))))
1658 (defun message-indent-citation ()
1659 "Modify text just inserted from a message to be cited.
1660 The inserted text should be the region.
1661 When this function returns, the region is again around the modified text.
1663 Normally, indent each nonblank line `message-indentation-spaces' spaces.
1664 However, if `message-yank-prefix' is non-nil, insert that prefix on each line."
1665 (let ((start (point)))
1666 ;; Remove unwanted headers.
1667 (when message-ignored-cited-headers
1672 (if (search-forward "\n\n" nil t)
1675 (message-remove-header message-ignored-cited-headers t)
1676 (when (= (point-min) (point-max))
1677 (setq all-removed t))
1678 (goto-char (point-max)))
1682 ;; Delete blank lines at the start of the buffer.
1683 (while (and (point-min)
1686 (message-delete-line))
1687 ;; Delete blank lines at the end of the buffer.
1688 (goto-char (point-max))
1691 (while (and (zerop (forward-line -1))
1693 (message-delete-line))
1694 ;; Do the indentation.
1695 (if (null message-yank-prefix)
1696 (indent-rigidly start (mark t) message-indentation-spaces)
1699 (while (< (point) (mark t))
1700 (insert message-yank-prefix)
1704 (defun message-yank-original (&optional arg)
1705 "Insert the message being replied to, if any.
1706 Puts point before the text and mark after.
1707 Normally indents each nonblank line ARG spaces (default 3). However,
1708 if `message-yank-prefix' is non-nil, insert that prefix on each line.
1710 This function uses `message-cite-function' to do the actual citing.
1712 Just \\[universal-argument] as argument means don't indent, insert no
1713 prefix, and don't delete any headers."
1715 (let ((modified (buffer-modified-p)))
1716 (when (and message-reply-buffer
1717 message-cite-function)
1718 (delete-windows-on message-reply-buffer t)
1719 (insert-buffer message-reply-buffer)
1720 (funcall message-cite-function)
1721 (message-exchange-point-and-mark)
1725 (setq message-checksum (cons (message-checksum) (buffer-size)))))))
1727 (defun message-cite-original-without-signature ()
1728 "Cite function in the standard Message manner."
1729 (let ((start (point))
1732 (when message-indent-citation-function
1733 (if (listp message-indent-citation-function)
1734 message-indent-citation-function
1735 (list message-indent-citation-function)))))
1737 (when (re-search-backward "^-- $" start t)
1738 (delete-region (point) end))
1741 (funcall (pop functions)))
1742 (when message-citation-line-function
1745 (funcall message-citation-line-function))))
1747 (defun message-cite-original ()
1748 "Cite function in the standard Message manner."
1749 (let ((start (point))
1751 (when message-indent-citation-function
1752 (if (listp message-indent-citation-function)
1753 message-indent-citation-function
1754 (list message-indent-citation-function)))))
1757 (funcall (pop functions)))
1758 (when message-citation-line-function
1761 (funcall message-citation-line-function))))
1763 (defun message-insert-citation-line ()
1764 "Function that inserts a simple citation line."
1765 (when message-reply-headers
1766 (insert (mail-header-from message-reply-headers) " writes:\n\n")))
1768 (defun message-position-on-field (header &rest afters)
1769 (let ((case-fold-search t))
1772 (goto-char (point-min))
1775 (concat "^" (regexp-quote mail-header-separator) "$"))
1776 (match-beginning 0)))
1777 (goto-char (point-min))
1778 (if (re-search-forward (concat "^" (regexp-quote header) ":") nil t)
1780 (re-search-forward "^[^ \t]" nil 'move)
1782 (skip-chars-backward "\n")
1785 (not (re-search-forward
1786 (concat "^" (regexp-quote (car afters)) ":")
1790 (re-search-forward "^[^ \t]" nil 'move)
1791 (beginning-of-line))
1792 (insert header ": \n")
1796 (defun message-remove-signature ()
1797 "Remove the signature from the text between point and mark.
1798 The text will also be indented the normal way."
1800 (let ((start (point))
1802 (if (not (re-search-forward message-signature-separator (mark t) t))
1803 ;; No signature here, so we just indent the cited text.
1804 (message-indent-citation)
1805 ;; Find the last non-empty line.
1807 (while (looking-at "[ \t]*$")
1810 (setq mark (set-marker (make-marker) (point)))
1812 (message-indent-citation)
1813 ;; Enable undoing the deletion.
1815 (delete-region mark (mark t))
1816 (set-marker mark nil)))))
1821 ;;; Sending messages
1824 (defun message-send-and-exit (&optional arg)
1825 "Send message like `message-send', then, if no errors, exit from mail buffer."
1827 (let ((buf (current-buffer))
1828 (actions message-exit-actions))
1829 (when (and (message-send arg)
1831 (if message-kill-buffer-on-exit
1834 (when (eq buf (current-buffer))
1835 (message-bury buf)))
1836 (message-do-actions actions))))
1838 (defun message-dont-send ()
1839 "Don't send the message you have been editing."
1841 (set-buffer-modified-p t)
1843 (let ((actions message-postpone-actions))
1844 (message-bury (current-buffer))
1845 (message-do-actions actions)))
1847 (defun message-kill-buffer ()
1848 "Kill the current buffer."
1850 (when (or (not (buffer-modified-p))
1851 (yes-or-no-p "Message modified; kill anyway? "))
1852 (let ((actions message-kill-actions))
1853 (setq buffer-file-name nil)
1854 (kill-buffer (current-buffer))
1855 (message-do-actions actions))))
1857 (defun message-bury (buffer)
1858 "Bury this mail buffer."
1859 (let ((newbuf (other-buffer buffer)))
1860 (bury-buffer buffer)
1861 (if (and (fboundp 'frame-parameters)
1862 (cdr (assq 'dedicated (frame-parameters)))
1863 (not (null (delq (selected-frame) (visible-frame-list)))))
1864 (delete-frame (selected-frame))
1865 (switch-to-buffer newbuf))))
1867 (defun message-send (&optional arg)
1868 "Send the message in the current buffer.
1869 If `message-interactive' is non-nil, wait for success indication
1870 or error messages, and inform user.
1871 Otherwise any failure is reported in a message back to
1872 the user from the mailer."
1875 (when (or (buffer-modified-p)
1876 (message-check-element 'unchanged)
1877 (y-or-n-p "No changes in the buffer; really send? "))
1878 ;; Make it possible to undo the coming changes.
1880 (let ((inhibit-read-only t))
1881 (put-text-property (point-min) (point-max) 'read-only nil))
1882 (message-fix-before-sending)
1883 (run-hooks 'message-send-hook)
1884 (message "Sending...")
1885 (let ((message-encoding-buffer
1886 (message-generate-new-buffer-clone-locals " message encoding"))
1887 (message-edit-buffer (current-buffer))
1888 (message-mime-mode mime-edit-mode-flag)
1889 (alist message-send-method-alist)
1893 (set-buffer message-encoding-buffer)
1895 (insert-buffer message-edit-buffer)
1896 (funcall message-encode-function)
1898 (setq elem (pop alist)))
1899 (when (and (or (not (funcall (cadr elem)))
1900 (and (or (not (memq (car elem)
1901 message-sent-message-via))
1904 "Already sent message via %s; resend? "
1906 (setq success (funcall (caddr elem) arg)))))
1908 (when (and success sent)
1910 ;;(when (fboundp 'mail-hist-put-headers-into-history)
1911 ;; (mail-hist-put-headers-into-history))
1912 (run-hooks 'message-sent-hook)
1913 (message "Sending...done")
1914 ;; Mark the buffer as unmodified and delete autosave.
1915 (set-buffer-modified-p nil)
1916 (delete-auto-save-file-if-necessary t)
1917 (message-disassociate-draft)
1918 ;; Delete other mail buffers and stuff.
1919 (message-do-send-housekeeping)
1920 (message-do-actions message-send-actions)
1924 (defun message-send-via-mail (arg)
1925 "Send the current message via mail."
1926 (message-send-mail arg))
1928 (defun message-send-via-news (arg)
1929 "Send the current message via news."
1930 (message-send-news arg))
1932 (defun message-fix-before-sending ()
1933 "Do various things to make the message nice before sending it."
1934 ;; Make sure there's a newline at the end of the message.
1935 (goto-char (point-max))
1939 (defun message-add-action (action &rest types)
1940 "Add ACTION to be performed when doing an exit of type TYPES."
1943 (set (setq var (intern (format "message-%s-actions" (pop types))))
1944 (nconc (symbol-value var) (list action))))))
1946 (defun message-do-actions (actions)
1947 "Perform all actions in ACTIONS."
1948 ;; Now perform actions on successful sending.
1952 ;; A simple function.
1953 ((message-functionp (car actions))
1954 (funcall (car actions)))
1955 ;; Something to be evaled.
1957 (eval (car actions)))))
1960 (defun message-send-mail (&optional arg)
1961 (require 'mail-utils)
1962 (let ((tembuf (message-generate-new-buffer-clone-locals " message temp"))
1963 (case-fold-search nil)
1964 (news (message-news-p)))
1966 (message-narrow-to-headers)
1967 ;; Insert some headers.
1968 (let ((message-deletable-headers
1969 (if news nil message-deletable-headers)))
1970 (message-generate-headers message-required-mail-headers))
1971 ;; Let the user do all of the above.
1972 (run-hooks 'message-header-hook))
1977 (insert-buffer message-encoding-buffer)
1978 ;; Remove some headers.
1980 (message-narrow-to-headers)
1981 ;; Remove some headers.
1982 (message-remove-header message-ignored-mail-headers t))
1983 (goto-char (point-max))
1984 ;; require one newline at the end.
1985 (or (= (preceding-char) ?\n)
1988 (or (message-fetch-field "cc")
1989 (message-fetch-field "to")))
1990 (message-insert-courtesy-copy))
1991 (mime-edit-maybe-split-and-send
1995 (funcall message-send-mail-function)
1997 (funcall message-send-mail-function))
1998 (kill-buffer tembuf))
1999 (set-buffer message-edit-buffer)
2000 (push 'mail message-sent-message-via)))
2002 (defun message-send-mail-with-sendmail ()
2003 "Send off the prepared buffer with sendmail."
2004 (let ((errbuf (if message-interactive
2005 (generate-new-buffer " sendmail errors")
2007 resend-to-addresses delimline)
2008 (let ((case-fold-search t))
2010 (message-narrow-to-headers)
2011 (setq resend-to-addresses (message-fetch-field "resent-to")))
2012 ;; Change header-delimiter to be what sendmail expects.
2013 (goto-char (point-min))
2015 (concat "^" (regexp-quote mail-header-separator) "\n"))
2016 (replace-match "\n")
2018 (setq delimline (point-marker))
2019 (run-hooks 'message-send-mail-hook)
2020 ;; Insert an extra newline if we need it to work around
2021 ;; Sun's bug that swallows newlines.
2022 (goto-char (1+ delimline))
2023 (when (eval message-mailer-swallows-blank-line)
2025 (when message-interactive
2029 (let ((default-directory "/")
2030 (coding-system-for-write 'binary))
2031 (apply 'call-process-region
2032 (append (list (point-min) (point-max)
2033 (if (boundp 'sendmail-program)
2035 "/usr/lib/sendmail")
2036 nil errbuf nil "-oi")
2037 ;; Always specify who from,
2038 ;; since some systems have broken sendmails.
2039 ;; But some systems are more broken with -f, so
2040 ;; we'll let users override this.
2041 (if (null message-sendmail-f-is-evil)
2042 (list "-f" (user-login-name)))
2043 ;; These mean "report errors by mail"
2044 ;; and "deliver in background".
2045 (if (null message-interactive) '("-oem" "-odb"))
2046 ;; Get the addresses from the message
2047 ;; unless this is a resend.
2048 ;; We must not do that for a resend
2049 ;; because we would find the original addresses.
2050 ;; For a resend, include the specific addresses.
2051 (if resend-to-addresses
2052 (list resend-to-addresses)
2054 (when message-interactive
2057 (goto-char (point-min))
2058 (while (re-search-forward "\n\n* *" nil t)
2059 (replace-match "; "))
2060 (if (not (zerop (buffer-size)))
2061 (error "Sending...failed to %s"
2062 (buffer-substring (point-min) (point-max)))))
2063 (when (bufferp errbuf)
2064 (kill-buffer errbuf)))))
2066 (defun message-send-mail-with-qmail ()
2067 "Pass the prepared message buffer to qmail-inject.
2068 Refer to the documentation for the variable `message-send-mail-function'
2069 to find out how to use this."
2070 ;; replace the header delimiter with a blank line
2071 (goto-char (point-min))
2073 (concat "^" (regexp-quote mail-header-separator) "\n"))
2074 (replace-match "\n")
2075 (run-hooks 'message-send-mail-hook)
2078 (let ((coding-system-for-write 'binary))
2080 'call-process-region 1 (point-max) message-qmail-inject-program
2082 ;; qmail-inject's default behaviour is to look for addresses on the
2083 ;; command line; if there're none, it scans the headers.
2084 ;; yes, it does The Right Thing w.r.t. Resent-To and it's kin.
2086 ;; in general, ALL of qmail-inject's defaults are perfect for simply
2087 ;; reading a formatted (i. e., at least a To: or Resent-To header)
2088 ;; message from stdin.
2090 ;; qmail also has the advantage of not having been raped by
2091 ;; various vendors, so we don't have to allow for that, either --
2092 ;; compare this with message-send-mail-with-sendmail and weep
2093 ;; for sendmail's lost innocence.
2095 ;; all this is way cool coz it lets us keep the arguments entirely
2096 ;; free for -inject-arguments -- a big win for the user and for us
2097 ;; since we don't have to play that double-guessing game and the user
2098 ;; gets full control (no gestapo'ish -f's, for instance). --sj
2099 message-qmail-inject-args))
2100 ;; qmail-inject doesn't say anything on it's stdout/stderr,
2101 ;; we have to look at the retval instead
2103 (1 (error "qmail-inject reported permanent failure"))
2104 (111 (error "qmail-inject reported transient failure"))
2105 ;; should never happen
2106 (t (error "qmail-inject reported unknown failure"))))
2108 (defun message-send-mail-with-mh ()
2109 "Send the prepared message buffer with mh."
2110 (let ((mh-previous-window-config nil)
2111 (name (mh-new-draft-name)))
2112 (setq buffer-file-name name)
2113 ;; MH wants to generate these headers itself.
2114 (when message-mh-deletable-headers
2115 (let ((headers message-mh-deletable-headers))
2117 (goto-char (point-min))
2118 (and (re-search-forward
2119 (concat "^" (symbol-name (car headers)) ": *") nil t)
2120 (message-delete-line))
2122 (run-hooks 'message-send-mail-hook)
2123 ;; Pass it on to mh.
2126 (defun message-send-mail-with-smtp ()
2127 "Send the prepared message buffer with SMTP."
2129 (let ((errbuf (if mail-interactive
2130 (generate-new-buffer " smtp errors")
2132 (case-fold-search nil)
2137 (goto-char (point-max))
2138 ;; require one newline at the end.
2139 (or (= (preceding-char) ?\n)
2141 ;; Change header-delimiter to be what sendmail expects.
2142 (goto-char (point-min))
2144 (concat "^" (regexp-quote mail-header-separator) "\n"))
2145 (replace-match "\n")
2147 (setq delimline (point-marker))
2148 (run-hooks 'message-send-mail-hook)
2149 ;; (sendmail-synch-aliases)
2151 ;; (expand-mail-aliases (point-min) delimline))
2152 (goto-char (point-min))
2153 ;; ignore any blank lines in the header
2154 (while (and (re-search-forward "\n\n\n*" delimline t)
2155 (< (point) delimline))
2156 (replace-match "\n"))
2157 (let ((case-fold-search t))
2158 (goto-char (point-min))
2159 (goto-char (point-min))
2160 (while (re-search-forward "^Resent-to:" delimline t)
2161 (setq resend-to-addresses
2163 (narrow-to-region (point)
2167 (append (mail-parse-comma-list)
2168 resend-to-addresses))))
2169 ;;; Apparently this causes a duplicate Sender.
2170 ;;; ;; If the From is different than current user, insert Sender.
2171 ;;; (goto-char (point-min))
2172 ;;; (and (re-search-forward "^From:" delimline t)
2174 ;;; (require 'mail-utils)
2175 ;;; (not (string-equal
2176 ;;; (mail-strip-quoted-names
2177 ;;; (save-restriction
2178 ;;; (narrow-to-region (point-min) delimline)
2179 ;;; (mail-fetch-field "From")))
2180 ;;; (user-login-name))))
2182 ;;; (forward-line 1)
2183 ;;; (insert "Sender: " (user-login-name) "\n")))
2184 ;; Don't send out a blank subject line
2185 (goto-char (point-min))
2186 (if (re-search-forward "^Subject:[ \t]*\n" delimline t)
2188 ;; Put the "From:" field in unless for some odd reason
2189 ;; they put one in themselves.
2190 (goto-char (point-min))
2191 (if (not (re-search-forward "^From:" delimline t))
2192 (let* ((login user-mail-address)
2193 (fullname (user-full-name)))
2194 (cond ((eq mail-from-style 'angles)
2195 (insert "From: " fullname)
2196 (let ((fullname-start (+ (point-min) 6))
2197 (fullname-end (point-marker)))
2198 (goto-char fullname-start)
2199 ;; Look for a character that cannot appear unquoted
2200 ;; according to RFC 822.
2201 (if (re-search-forward "[^- !#-'*+/-9=?A-Z^-~]"
2204 ;; Quote fullname, escaping specials.
2205 (goto-char fullname-start)
2207 (while (re-search-forward "[\"\\]"
2209 (replace-match "\\\\\\&" t))
2211 (insert " <" login ">\n"))
2212 ((eq mail-from-style 'parens)
2213 (insert "From: " login " (")
2214 (let ((fullname-start (point)))
2216 (let ((fullname-end (point-marker)))
2217 (goto-char fullname-start)
2218 ;; RFC 822 says \ and nonmatching parentheses
2219 ;; must be escaped in comments.
2220 ;; Escape every instance of ()\ ...
2221 (while (re-search-forward "[()\\]" fullname-end 1)
2222 (replace-match "\\\\\\&" t))
2223 ;; ... then undo escaping of matching parentheses,
2224 ;; including matching nested parentheses.
2225 (goto-char fullname-start)
2226 (while (re-search-forward
2227 "\\(\\=\\|[^\\]\\(\\\\\\\\\\)*\\)\\\\(\\(\\([^\\]\\|\\\\\\\\\\)*\\)\\\\)"
2229 (replace-match "\\1(\\3)" t)
2230 (goto-char fullname-start))))
2232 ((null mail-from-style)
2233 (insert "From: " login "\n")))))
2234 ;; Insert an extra newline if we need it to work around
2235 ;; Sun's bug that swallows newlines.
2236 (goto-char (1+ delimline))
2237 (if (eval mail-mailer-swallows-blank-line)
2239 ;; Find and handle any FCC fields.
2240 (goto-char (point-min))
2241 (if (re-search-forward "^FCC:" delimline t)
2242 (mail-do-fcc delimline))
2243 (if mail-interactive
2250 (let ((recipient-address-list
2251 (or resend-to-addresses
2252 (smtp-deduce-address-list (current-buffer)
2253 (point-min) delimline))))
2254 (smtp-do-bcc delimline)
2256 (if recipient-address-list
2257 (if (not (smtp-via-smtp recipient-address-list
2259 (error "Sending failed; SMTP protocol error"))
2260 (error "Sending failed; no recipients"))
2262 (if (bufferp errbuf)
2263 (kill-buffer errbuf)))))
2265 (defun message-send-news (&optional arg)
2266 (let ((tembuf (message-generate-new-buffer-clone-locals " *message temp*"))
2267 (case-fold-search nil)
2268 (method (if (message-functionp message-post-method)
2269 (funcall message-post-method arg)
2270 message-post-method))
2271 (message-syntax-checks
2273 (cons '(existing-newsgroups . disabled)
2274 message-syntax-checks)
2275 message-syntax-checks))
2278 (message-narrow-to-headers)
2279 ;; Insert some headers.
2280 (message-generate-headers message-required-news-headers)
2281 ;; Let the user do all of the above.
2282 (run-hooks 'message-header-hook))
2283 (message-cleanup-headers)
2284 (if (not (message-check-news-syntax))
2286 ;;(message "Posting not performed")
2291 (buffer-disable-undo (current-buffer))
2293 (insert-buffer message-encoding-buffer)
2294 ;; Remove some headers.
2296 (message-narrow-to-headers)
2297 ;; Remove some headers.
2298 (message-remove-header message-ignored-news-headers t))
2299 (goto-char (point-max))
2300 ;; require one newline at the end.
2301 (or (= (preceding-char) ?\n)
2303 (mime-edit-maybe-split-and-send
2308 (std11-narrow-to-header mail-header-separator)
2309 (goto-char (point-min))
2310 (when (re-search-forward "^Message-Id:" nil t)
2311 (delete-region (match-end 0)(std11-field-end))
2312 (insert (concat " " (message-make-message-id)))
2314 (funcall message-send-news-function method)
2316 (setq result (funcall message-send-news-function method)))
2317 (kill-buffer tembuf))
2318 (set-buffer message-edit-buffer)
2320 (push 'news message-sent-message-via)
2321 (message "Couldn't send message via news: %s"
2322 (nnheader-get-report (car method)))
2325 ;; 1997-09-29 by MORIOKA Tomohiko
2326 (defun message-send-news-with-gnus (method)
2327 (let ((case-fold-search t))
2328 ;; Remove the delimiter.
2329 (goto-char (point-min))
2331 (concat "^" (regexp-quote mail-header-separator) "\n"))
2332 (replace-match "\n")
2334 (run-hooks 'message-send-news-hook)
2335 ;;(require (car method))
2336 ;;(funcall (intern (format "%s-open-server" (car method)))
2337 ;;(cadr method) (cddr method))
2339 ;; (funcall (intern (format "%s-request-post" (car method)))
2341 (gnus-open-server method)
2342 (gnus-request-post method)
2346 ;;; Header generation & syntax checking.
2349 (defmacro message-check (type &rest forms)
2350 "Eval FORMS if TYPE is to be checked."
2351 `(or (message-check-element ,type)
2355 (put 'message-check 'lisp-indent-function 1)
2356 (put 'message-check 'edebug-form-spec '(form body))
2358 (defun message-check-element (type)
2359 "Returns non-nil if this type is not to be checked."
2360 (if (eq message-syntax-checks 'dont-check-for-anything-just-trust-me)
2362 (let ((able (assq type message-syntax-checks)))
2364 (eq (cdr able) 'disabled)))))
2366 (defun message-check-news-syntax ()
2367 "Check the syntax of the message."
2372 ;; We narrow to the headers and check them first.
2375 (message-narrow-to-headers)
2376 (message-check-news-header-syntax)))
2379 (set-buffer message-edit-buffer)
2380 (message-check-news-body-syntax))))))
2382 (defun message-check-news-header-syntax ()
2384 ;; Check the Subject header.
2385 (message-check 'subject
2386 (let* ((case-fold-search t)
2387 (subject (message-fetch-field "subject")))
2390 (not (string-match "\\`[ \t]*\\'" subject)))
2393 "The subject field is empty or missing. Posting is denied.")))))
2394 ;; Check for commands in Subject.
2395 (message-check 'subject-cmsg
2396 (if (string-match "^cmsg " (message-fetch-field "subject"))
2398 "The control code \"cmsg\" is in the subject. Really post? ")
2400 ;; Check for multiple identical headers.
2401 (message-check 'multiple-headers
2403 (while (and (not found)
2404 (re-search-forward "^[^ \t:]+: " nil t))
2406 (or (re-search-forward
2411 (match-beginning 0) (- (match-end 0) 2))))
2416 (y-or-n-p (format "Multiple %s headers. Really post? " found))
2418 ;; Check for Version and Sendsys.
2419 (message-check 'sendsys
2420 (if (re-search-forward "^Sendsys:\\|^Version:" nil t)
2422 (format "The article contains a %s command. Really post? "
2423 (buffer-substring (match-beginning 0)
2424 (1- (match-end 0)))))
2426 ;; See whether we can shorten Followup-To.
2427 (message-check 'shorten-followup-to
2428 (let ((newsgroups (message-fetch-field "newsgroups"))
2429 (followup-to (message-fetch-field "followup-to"))
2431 (when (and newsgroups
2432 (string-match "," newsgroups)
2437 (setq to (completing-read
2438 "Followups to: (default all groups) "
2439 (mapcar (lambda (g) (list g))
2441 (message-tokenize-header
2443 (goto-char (point-min))
2444 (insert "Followup-To: " to "\n"))
2446 ;; Check "Shoot me".
2447 (message-check 'shoot
2448 (if (re-search-forward
2449 "Message-ID.*.i-did-not-set--mail-host-address--so-shoot-me" nil t)
2450 (y-or-n-p "You appear to have a misconfigured system. Really post? ")
2452 ;; Check for Approved.
2453 (message-check 'approved
2454 (if (re-search-forward "^Approved:" nil t)
2455 (y-or-n-p "The article contains an Approved header. Really post? ")
2457 ;; Check the Message-ID header.
2458 (message-check 'message-id
2459 (let* ((case-fold-search t)
2460 (message-id (message-fetch-field "message-id" t)))
2461 (or (not message-id)
2462 ;; Is there an @ in the ID?
2463 (and (string-match "@" message-id)
2464 ;; Is there a dot in the ID?
2465 (string-match "@[^.]*\\." message-id)
2466 ;; Does the ID end with a dot?
2467 (not (string-match "\\.>" message-id)))
2469 (format "The Message-ID looks strange: \"%s\". Really post? "
2471 ;; Check the Newsgroups & Followup-To headers.
2472 (message-check 'existing-newsgroups
2473 (let* ((case-fold-search t)
2474 (newsgroups (message-fetch-field "newsgroups"))
2475 (followup-to (message-fetch-field "followup-to"))
2476 (groups (message-tokenize-header
2478 (concat newsgroups "," followup-to)
2480 (hashtb (and (boundp 'gnus-active-hashtb)
2481 gnus-active-hashtb))
2483 (if (or (not hashtb)
2484 (not (boundp 'gnus-read-active-file))
2485 (not gnus-read-active-file)
2486 (eq gnus-read-active-file 'some))
2489 (when (and (not (boundp (intern (car groups) hashtb)))
2490 (not (equal (car groups) "poster")))
2491 (push (car groups) errors))
2497 "Really post to %s unknown group%s: %s "
2498 (if (= (length errors) 1) "this" "these")
2499 (if (= (length errors) 1) "" "s")
2500 (mapconcat 'identity errors ", ")))))))
2501 ;; Check the Newsgroups & Followup-To headers for syntax errors.
2502 (message-check 'valid-newsgroups
2503 (let ((case-fold-search t)
2504 (headers '("Newsgroups" "Followup-To"))
2506 (while (and headers (not error))
2507 (when (setq header (mail-fetch-field (car headers)))
2511 "\\`\\([-+_&.a-zA-Z0-9]+\\)?\\(,[-+_&.a-zA-Z0-9]+\\)*\\'"
2516 (not (string-match "\\.\\'\\|\\.\\." g)))
2517 (message-tokenize-header header ","))))
2524 (format "The %s header looks odd: \"%s\". Really post? "
2525 (car headers) header)))))
2526 (message-check 'repeated-newsgroups
2527 (let ((case-fold-search t)
2528 (headers '("Newsgroups" "Followup-To"))
2529 header error groups group)
2532 (when (setq header (mail-fetch-field (pop headers)))
2533 (setq groups (message-tokenize-header header ","))
2534 (while (setq group (pop groups))
2535 (when (member group groups)
2541 (format "Group %s is repeated in headers. Really post? " error)))))
2542 ;; Check the From header.
2543 (message-check 'from
2544 (let* ((case-fold-search t)
2545 (from (message-fetch-field "from"))
2546 (ad (nth 1 (mail-extract-address-components from))))
2549 (message "There is no From line. Posting is denied.")
2551 ((or (not (string-match "@[^\\.]*\\." ad)) ;larsi@ifi
2552 (string-match "\\.\\." ad) ;larsi@ifi..uio
2553 (string-match "@\\." ad) ;larsi@.ifi.uio
2554 (string-match "\\.$" ad) ;larsi@ifi.uio.
2555 (not (string-match "^[^@]+@[^@]+$" ad)) ;larsi.ifi.uio
2556 (string-match "(.*).*(.*)" from)) ;(lars) (lars)
2558 "Denied posting -- the From looks strange: \"%s\"." from)
2562 (defun message-check-news-body-syntax ()
2564 ;; Check for long lines.
2565 (message-check 'long-lines
2566 (goto-char (point-min))
2568 (concat "^" (regexp-quote mail-header-separator) "$"))
2572 (< (current-column) 80))
2573 (zerop (forward-line 1))))
2577 "You have lines longer than 79 characters. Really post? ")))
2578 ;; Check whether the article is empty.
2579 (message-check 'empty
2580 (goto-char (point-min))
2582 (concat "^" (regexp-quote mail-header-separator) "$"))
2585 (goto-char (point-max))
2586 (re-search-backward message-signature-separator nil t)
2588 (or (re-search-backward "[^ \n\t]" b t)
2589 (y-or-n-p "Empty article. Really post? "))))
2590 ;; Check for control characters.
2591 (message-check 'control-chars
2592 (if (re-search-forward "[\000-\007\013\015-\037\200-\237]" nil t)
2594 "The article contains control characters. Really post? ")
2596 ;; Check excessive size.
2597 (message-check 'size
2598 (if (> (buffer-size) 60000)
2600 (format "The article is %d octets long. Really post? "
2603 ;; Check whether any new text has been added.
2604 (message-check 'new-text
2606 (not message-checksum)
2607 (not (and (eq (message-checksum) (car message-checksum))
2608 (eq (buffer-size) (cdr message-checksum))))
2610 "It looks like no new text has been added. Really post? ")))
2611 ;; Check the length of the signature.
2612 (message-check 'signature
2613 (goto-char (point-max))
2614 (if (or (not (re-search-backward message-signature-separator nil t))
2615 (search-forward message-forward-end-separator nil t))
2617 (if (> (count-lines (point) (point-max)) 5)
2620 "Your .sig is %d lines; it should be max 4. Really post? "
2621 (1- (count-lines (point) (point-max)))))
2624 (defun message-checksum ()
2625 "Return a \"checksum\" for the current buffer."
2628 (goto-char (point-min))
2630 (concat "^" (regexp-quote mail-header-separator) "$"))
2632 (when (not (looking-at "[ \t\n]"))
2633 (setq sum (logxor (ash sum 1) (if (natnump sum) 0 1)
2638 (defun message-do-fcc ()
2639 "Process Fcc headers in the current buffer."
2640 (let ((case-fold-search t)
2641 (coding-system-for-write 'raw-text)
2644 (set-buffer (get-buffer-create " *message temp*"))
2645 (buffer-disable-undo (current-buffer))
2647 (insert-buffer-substring message-encoding-buffer)
2649 (message-narrow-to-headers)
2650 (while (setq file (message-fetch-field "fcc"))
2652 (message-remove-header "fcc" nil t)))
2653 (run-hooks 'message-header-hook 'message-before-do-fcc-hook)
2654 (goto-char (point-min))
2655 (re-search-forward (concat "^" (regexp-quote mail-header-separator) "$"))
2656 (replace-match "" t t)
2657 ;; Process FCC operations.
2659 (setq file (pop list))
2660 (if (string-match "^[ \t]*|[ \t]*\\(.*\\)[ \t]*$" file)
2661 ;; Pipe the article to the program in question.
2662 (call-process-region (point-min) (point-max) shell-file-name
2663 nil nil nil shell-command-switch
2664 (match-string 1 file))
2665 ;; Save the article.
2666 (setq file (expand-file-name file))
2667 (unless (file-exists-p (file-name-directory file))
2668 (make-directory (file-name-directory file) t))
2669 (if (and message-fcc-handler-function
2670 (not (eq message-fcc-handler-function 'rmail-output)))
2671 (funcall message-fcc-handler-function file)
2672 (if (and (file-readable-p file) (mail-file-babyl-p file))
2673 (rmail-output file 1 nil t)
2674 (let ((mail-use-rfc822 t))
2675 (rmail-output file 1 t t))))))
2677 (kill-buffer (current-buffer)))))
2679 (defun message-output (filename)
2680 "Append this article to Unix/babyl mail file.."
2681 (if (and (file-readable-p filename)
2682 (mail-file-babyl-p filename))
2683 (gnus-output-to-rmail filename t)
2684 (gnus-output-to-mail filename t)))
2686 (defun message-cleanup-headers ()
2687 "Do various automatic cleanups of the headers."
2688 ;; Remove empty lines in the header.
2690 (message-narrow-to-headers)
2691 ;; Remove blank lines.
2692 (while (re-search-forward "^[ \t]*\n" nil t)
2693 (replace-match "" t t))
2695 ;; Correct Newsgroups and Followup-To headers: Change sequence of
2696 ;; spaces to comma and eliminate spaces around commas. Eliminate
2697 ;; embedded line breaks.
2698 (goto-char (point-min))
2699 (while (re-search-forward "^\\(Newsgroups\\|Followup-To\\): +" nil t)
2703 (if (re-search-forward "^[^ \t]" nil t)
2707 (goto-char (point-min))
2708 (while (re-search-forward "\n[ \t]+" nil t)
2709 (replace-match " " t t)) ;No line breaks (too confusing)
2710 (goto-char (point-min))
2711 (while (re-search-forward "[ \t\n]*,[ \t\n]*\\|[ \t]+" nil t)
2712 (replace-match "," t t))
2713 (goto-char (point-min))
2714 ;; Remove trailing commas.
2715 (when (re-search-forward ",+$" nil t)
2716 (replace-match "" t t))))))
2718 (defun message-make-date ()
2719 "Make a valid data header."
2720 (let ((now (current-time)))
2721 (timezone-make-date-arpa-standard
2722 (current-time-string now) (current-time-zone now))))
2724 (defun message-make-message-id ()
2725 "Make a unique Message-ID."
2726 (concat "<" (message-unique-id)
2727 (let ((psubject (save-excursion (message-fetch-field "subject")))
2729 (save-excursion (message-fetch-field "supersedes"))))
2731 (and message-reply-headers
2732 (mail-header-references message-reply-headers)
2733 (mail-header-subject message-reply-headers)
2735 (mail-header-subject message-reply-headers)
2737 (message-strip-subject-re
2738 (mail-header-subject message-reply-headers))
2739 (message-strip-subject-re psubject))))
2741 (string-match "_-_@" psupersedes)))
2743 "@" (message-make-fqdn) ">"))
2745 (defvar message-unique-id-char nil)
2747 ;; If you ever change this function, make sure the new version
2748 ;; cannot generate IDs that the old version could.
2749 ;; You might for example insert a "." somewhere (not next to another dot
2750 ;; or string boundary), or modify the "fsf" string.
2751 (defun message-unique-id ()
2752 ;; Don't use microseconds from (current-time), they may be unsupported.
2753 ;; Instead we use this randomly inited counter.
2754 (setq message-unique-id-char
2755 (% (1+ (or message-unique-id-char (logand (random t) (1- (lsh 1 20)))))
2756 ;; (current-time) returns 16-bit ints,
2757 ;; and 2^16*25 just fits into 4 digits i base 36.
2759 (let ((tm (current-time)))
2761 (if (memq system-type '(ms-dos emx vax-vms))
2762 (let ((user (downcase (user-login-name))))
2763 (while (string-match "[^a-z0-9_]" user)
2764 (aset user (match-beginning 0) ?_))
2766 (message-number-base36 (user-uid) -1))
2767 (message-number-base36 (+ (car tm)
2768 (lsh (% message-unique-id-char 25) 16)) 4)
2769 (message-number-base36 (+ (nth 1 tm)
2770 (lsh (/ message-unique-id-char 25) 16)) 4)
2771 ;; Append the newsreader name, because while the generated
2772 ;; ID is unique to this newsreader, other newsreaders might
2773 ;; otherwise generate the same ID via another algorithm.
2776 (defun message-number-base36 (num len)
2781 (concat (message-number-base36 (/ num 36) (1- len))
2782 (char-to-string (aref "zyxwvutsrqponmlkjihgfedcba9876543210"
2785 (defun message-make-organization ()
2786 "Make an Organization header."
2787 (let* ((organization
2788 (when message-user-organization
2789 (if (message-functionp message-user-organization)
2790 (funcall message-user-organization)
2791 message-user-organization))))
2793 (message-set-work-buffer)
2794 (cond ((stringp organization)
2795 (insert organization))
2796 ((and (eq t organization)
2797 message-user-organization-file
2798 (file-exists-p message-user-organization-file))
2799 (insert-file-contents message-user-organization-file)))
2800 (goto-char (point-min))
2801 (while (re-search-forward "[\t\n]+" nil t)
2802 (replace-match "" t t))
2803 (unless (zerop (buffer-size))
2806 (defun message-make-lines ()
2807 "Count the number of lines and return numeric string."
2811 (goto-char (point-min))
2813 (concat "^" (regexp-quote mail-header-separator) "$"))
2815 (int-to-string (count-lines (point) (point-max))))))
2817 (defun message-make-in-reply-to ()
2818 "Return the In-Reply-To header for this message."
2819 (when message-reply-headers
2820 (let ((from (mail-header-from message-reply-headers))
2821 (date (mail-header-date message-reply-headers)))
2824 (string-match " *at \\| *@ \\| *(\\| *<" from)))
2825 (concat (if (and stop-pos
2826 (not (zerop stop-pos)))
2827 (substring from 0 stop-pos) from)
2829 (if (or (not date) (string= date ""))
2830 "(unknown date)" date)
2833 (defun message-make-distribution ()
2834 "Make a Distribution header."
2835 (let ((orig-distribution (message-fetch-reply-field "distribution")))
2836 (cond ((message-functionp message-distribution-function)
2837 (funcall message-distribution-function))
2838 (t orig-distribution))))
2840 (defun message-make-expires ()
2841 "Return an Expires header based on `message-expires'."
2842 (let ((current (current-time))
2843 (future (* 1.0 message-expires 60 60 24)))
2844 ;; Add the future to current.
2845 (setcar current (+ (car current) (round (/ future (expt 2 16)))))
2846 (setcar (cdr current) (+ (nth 1 current) (% (round future) (expt 2 16))))
2847 ;; Return the date in the future in UT.
2848 (timezone-make-date-arpa-standard
2849 (current-time-string current) (current-time-zone current) '(0 "UT"))))
2851 (defun message-make-path ()
2853 (let ((login-name (user-login-name)))
2854 (cond ((null message-user-path)
2855 (concat (system-name) "!" login-name))
2856 ((stringp message-user-path)
2857 ;; Support GENERICPATH. Suggested by vixie@decwrl.dec.com.
2858 (concat message-user-path "!" login-name))
2861 (defun message-make-from ()
2862 "Make a From header."
2863 (let* ((style message-from-style)
2864 (login (message-make-address))
2866 (or (and (boundp 'user-full-name)
2869 (when (string= fullname "&")
2870 (setq fullname (user-login-name)))
2872 (message-set-work-buffer)
2875 (equal fullname ""))
2877 ((or (eq style 'angles)
2878 (and (not (eq style 'parens))
2879 ;; Use angles if no quoting is needed, or if parens would
2880 ;; need quoting too.
2881 (or (not (string-match "[^- !#-'*+/-9=?A-Z^-~]" fullname))
2882 (let ((tmp (concat fullname nil)))
2883 (while (string-match "([^()]*)" tmp)
2884 (aset tmp (match-beginning 0) ?-)
2885 (aset tmp (1- (match-end 0)) ?-))
2886 (string-match "[\\()]" tmp)))))
2888 (goto-char (point-min))
2889 ;; Look for a character that cannot appear unquoted
2890 ;; according to RFC 822.
2891 (when (re-search-forward "[^- !#-'*+/-9=?A-Z^-~]" nil 1)
2892 ;; Quote fullname, escaping specials.
2893 (goto-char (point-min))
2895 (while (re-search-forward "[\"\\]" nil 1)
2896 (replace-match "\\\\\\&" t))
2898 (insert " <" login ">"))
2899 (t ; 'parens or default
2901 (let ((fullname-start (point)))
2903 (goto-char fullname-start)
2904 ;; RFC 822 says \ and nonmatching parentheses
2905 ;; must be escaped in comments.
2906 ;; Escape every instance of ()\ ...
2907 (while (re-search-forward "[()\\]" nil 1)
2908 (replace-match "\\\\\\&" t))
2909 ;; ... then undo escaping of matching parentheses,
2910 ;; including matching nested parentheses.
2911 (goto-char fullname-start)
2912 (while (re-search-forward
2913 "\\(\\=\\|[^\\]\\(\\\\\\\\\\)*\\)\\\\(\\(\\([^\\]\\|\\\\\\\\\\)*\\)\\\\)"
2915 (replace-match "\\1(\\3)" t)
2916 (goto-char fullname-start)))
2920 (defun message-make-sender ()
2921 "Return the \"real\" user address.
2922 This function tries to ignore all user modifications, and
2923 give as trustworthy answer as possible."
2924 (concat (user-login-name) "@" (system-name)))
2926 (defun message-make-address ()
2927 "Make the address of the user."
2928 (or (message-user-mail-address)
2929 (concat (user-login-name) "@" (message-make-domain))))
2931 (defun message-user-mail-address ()
2932 "Return the pertinent part of `user-mail-address'."
2933 (when user-mail-address
2934 (if (string-match " " user-mail-address)
2935 (nth 1 (mail-extract-address-components user-mail-address))
2936 user-mail-address)))
2938 (defun message-make-fqdn ()
2939 "Return user's fully qualified domain name."
2940 (let ((system-name (system-name))
2941 (user-mail (message-user-mail-address)))
2943 ((string-match "[^.]\\.[^.]" system-name)
2944 ;; `system-name' returned the right result.
2946 ;; Try `mail-host-address'.
2947 ((and (boundp 'mail-host-address)
2948 (stringp mail-host-address)
2949 (string-match "\\." mail-host-address))
2951 ;; We try `user-mail-address' as a backup.
2953 (string-match "\\." user-mail)
2954 (string-match "@\\(.*\\)\\'" user-mail))
2955 (match-string 1 user-mail))
2956 ;; Default to this bogus thing.
2958 (concat system-name ".i-did-not-set--mail-host-address--so-shoot-me")))))
2960 (defun message-make-host-name ()
2961 "Return the name of the host."
2962 (let ((fqdn (message-make-fqdn)))
2963 (string-match "^[^.]+\\." fqdn)
2964 (substring fqdn 0 (1- (match-end 0)))))
2966 (defun message-make-domain ()
2967 "Return the domain name."
2968 (or mail-host-address
2969 (message-make-fqdn)))
2971 (defun message-generate-headers (headers)
2972 "Prepare article HEADERS.
2973 Headers already prepared in the buffer are not modified."
2975 (message-narrow-to-headers)
2976 (let* ((Date (message-make-date))
2977 (Message-ID (message-make-message-id))
2978 (Organization (message-make-organization))
2979 (From (message-make-from))
2980 (Path (message-make-path))
2983 (In-Reply-To (message-make-in-reply-to))
2985 (Distribution (message-make-distribution))
2986 (Lines (message-make-lines))
2987 (X-Newsreader message-newsreader)
2988 (X-Mailer (and (not (message-fetch-field "X-Newsreader"))
2990 (Expires (message-make-expires))
2991 (case-fold-search t)
2993 ;; First we remove any old generated headers.
2994 (let ((headers message-deletable-headers))
2995 (unless (buffer-modified-p)
2996 (setq headers (delq 'Message-ID (copy-sequence headers))))
2998 (goto-char (point-min))
2999 (and (re-search-forward
3000 (concat "^" (symbol-name (car headers)) ": *") nil t)
3001 (get-text-property (1+ (match-beginning 0)) 'message-deletable)
3002 (message-delete-line))
3004 ;; Go through all the required headers and see if they are in the
3005 ;; articles already. If they are not, or are empty, they are
3006 ;; inserted automatically - except for Subject, Newsgroups and
3009 (goto-char (point-min))
3010 (setq elem (pop headers))
3012 (if (eq (car elem) 'optional)
3013 (setq header (cdr elem))
3014 (setq header (car elem)))
3016 (when (or (not (re-search-forward
3017 (concat "^" (downcase (symbol-name header)) ":")
3020 ;; The header was found. We insert a space after the
3021 ;; colon, if there is none.
3022 (if (/= (following-char) ? ) (insert " ") (forward-char 1))
3023 ;; Find out whether the header is empty...
3024 (looking-at "[ \t]*$")))
3025 ;; So we find out what value we should insert.
3028 ((and (consp elem) (eq (car elem) 'optional))
3029 ;; This is an optional header. If the cdr of this
3030 ;; is something that is nil, then we do not insert
3032 (setq header (cdr elem))
3033 (or (and (fboundp (cdr elem)) (funcall (cdr elem)))
3034 (and (boundp (cdr elem)) (symbol-value (cdr elem)))))
3036 ;; The element is a cons. Either the cdr is a
3037 ;; string to be inserted verbatim, or it is a
3038 ;; function, and we insert the value returned from
3040 (or (and (stringp (cdr elem)) (cdr elem))
3041 (and (fboundp (cdr elem)) (funcall (cdr elem)))))
3042 ((and (boundp header) (symbol-value header))
3043 ;; The element is a symbol. We insert the value
3044 ;; of this symbol, if any.
3045 (symbol-value header))
3047 ;; We couldn't generate a value for this header,
3048 ;; so we just ask the user.
3049 (read-from-minibuffer
3050 (format "Empty header for %s; enter value: " header)))))
3051 ;; Finally insert the header.
3053 (not (equal value "")))
3057 ;; This header didn't exist, so we insert it.
3058 (goto-char (point-max))
3059 (insert (symbol-name header) ": " value "\n")
3061 ;; The value of this header was empty, so we clear
3062 ;; totally and insert the new value.
3063 (delete-region (point) (gnus-point-at-eol))
3065 ;; Add the deletable property to the headers that require it.
3066 (and (memq header message-deletable-headers)
3067 (progn (beginning-of-line) (looking-at "[^:]+: "))
3068 (add-text-properties
3069 (point) (match-end 0)
3070 '(message-deletable t face italic) (current-buffer)))))))
3071 ;; Insert new Sender if the From is strange.
3072 (let ((from (message-fetch-field "from"))
3073 (sender (message-fetch-field "sender"))
3074 (secure-sender (message-make-sender)))
3076 (not (message-check-element 'sender))
3079 (cadr (mail-extract-address-components from)))
3080 (downcase secure-sender)))
3085 (cadr (mail-extract-address-components sender)))
3086 (downcase secure-sender)))))
3087 (goto-char (point-min))
3088 ;; Rename any old Sender headers to Original-Sender.
3089 (when (re-search-forward "^\\(Original-\\)*Sender:" nil t)
3091 (insert "Original-")
3092 (beginning-of-line))
3093 (when (or (message-news-p)
3094 (string-match "^[^@]+@.+\\..+" secure-sender))
3095 (insert "Sender: " secure-sender "\n")))))))
3097 (defun message-insert-courtesy-copy ()
3098 "Insert a courtesy message in mail copies of combined messages."
3102 (message-narrow-to-headers)
3103 (when (setq newsgroups (message-fetch-field "newsgroups"))
3104 (goto-char (point-max))
3105 (insert "Posted-To: " newsgroups "\n")))
3107 (when message-courtesy-message
3109 ((string-match "%s" message-courtesy-message)
3110 (insert (format message-courtesy-message newsgroups)))
3112 (insert message-courtesy-message)))))))
3115 ;;; Setting up a message buffer
3118 (defun message-fill-address (header value)
3120 (narrow-to-region (point) (point))
3121 (insert (capitalize (symbol-name header))
3123 (if (consp value) (car value) value)
3125 (narrow-to-region (point-min) (1- (point-max)))
3127 (goto-char (point-min))
3129 (skip-chars-forward "^,\"" (point-max))
3130 (if (or (= (following-char) ?,)
3133 (if (and (> (current-column) 78)
3139 (setq last (1+ (point))))
3140 (setq last (1+ (point)))))
3141 (setq quoted (not quoted)))
3144 (goto-char (point-max))
3148 (defun message-fill-references (header value)
3149 (insert (capitalize (symbol-name header))
3151 (std11-fill-msg-id-list-string
3152 (if (consp value) (car value) value))
3155 (defun message-fill-header (header value)
3156 (let ((begin (point))
3159 (insert (capitalize (symbol-name header))
3161 (if (consp value) (car value) value)
3164 (narrow-to-region begin (point))
3165 (fill-region-as-paragraph begin (point))
3166 ;; Tapdance around looong Message-IDs.
3168 (when (looking-at "[ \t]*$")
3169 (message-delete-line))
3171 (re-search-forward ":" nil t)
3172 (when (looking-at "\n[ \t]+")
3173 (replace-match " " t t))
3174 (goto-char (point-max)))))
3176 (defun message-position-point ()
3177 "Move point to where the user probably wants to find it."
3178 (message-narrow-to-headers)
3180 ((re-search-forward "^[^:]+:[ \t]*$" nil t)
3181 (search-backward ":" )
3184 (if (= (following-char) ? )
3188 (goto-char (point-max))
3191 (unless (looking-at "$")
3195 (defun message-buffer-name (type &optional to group)
3196 "Return a new (unique) buffer name based on TYPE and TO."
3198 ;; Check whether `message-generate-new-buffers' is a function,
3199 ;; and if so, call it.
3200 ((message-functionp message-generate-new-buffers)
3201 (funcall message-generate-new-buffers type to group))
3202 ;; Generate a new buffer name The Message Way.
3203 (message-generate-new-buffers
3204 (generate-new-buffer-name
3208 (or (car (mail-extract-address-components to))
3211 (if (and group (not (string= group ""))) (concat " on " group) "")
3213 ;; Use standard name.
3215 (format "*%s message*" type))))
3217 (defun message-pop-to-buffer (name)
3218 "Pop to buffer NAME, and warn if it already exists and is modified."
3219 (let ((buffer (get-buffer name)))
3221 (buffer-name buffer))
3223 (set-buffer (pop-to-buffer buffer))
3224 (when (and (buffer-modified-p)
3226 "Message already being composed; erase? ")))
3227 (error "Message being composed")))
3228 (set-buffer (pop-to-buffer name))))
3232 (defun message-do-send-housekeeping ()
3233 "Kill old message buffers."
3234 ;; We might have sent this buffer already. Delete it from the
3236 (setq message-buffer-list (delq (current-buffer) message-buffer-list))
3237 (while (and message-max-buffers
3239 (>= (length message-buffer-list) message-max-buffers))
3240 ;; Kill the oldest buffer -- unless it has been changed.
3241 (let ((buffer (pop message-buffer-list)))
3242 (when (and (buffer-name buffer)
3243 (not (buffer-modified-p buffer)))
3244 (kill-buffer buffer))))
3245 ;; Rename the buffer.
3246 (if message-send-rename-function
3247 (funcall message-send-rename-function)
3248 (when (string-match "\\`\\*" (buffer-name))
3250 (concat "*sent " (substring (buffer-name) (match-end 0))) t)))
3251 ;; Push the current buffer onto the list.
3252 (when message-max-buffers
3253 (setq message-buffer-list
3254 (nconc message-buffer-list (list (current-buffer))))))
3256 (defvar mc-modes-alist)
3257 (defun message-setup (headers &optional replybuffer actions)
3258 (when (and (boundp 'mc-modes-alist)
3259 (not (assq 'message-mode mc-modes-alist)))
3260 (push '(message-mode (encrypt . mc-encrypt-message)
3261 (sign . mc-sign-message))
3264 (setq message-send-actions actions))
3265 (setq message-reply-buffer replybuffer)
3266 (goto-char (point-min))
3267 ;; Insert all the headers.
3270 (alist message-header-format-alist))
3272 (unless (assq (caar h) message-header-format-alist)
3273 (push (list (caar h)) alist))
3277 (delete-region (point) (progn (forward-line -1) (point)))
3278 (when message-default-headers
3279 (insert message-default-headers)
3280 (or (bolp) (insert ?\n)))
3284 (insert mail-header-separator "\n")
3288 (when (message-news-p)
3289 (when message-default-news-headers
3290 (insert message-default-news-headers)
3291 (or (bolp) (insert ?\n)))
3292 (when message-generate-headers-first
3293 (message-generate-headers
3296 (copy-sequence message-required-news-headers))))))
3297 (when (message-mail-p)
3298 (when message-default-mail-headers
3299 (insert message-default-mail-headers)
3300 (or (bolp) (insert ?\n)))
3301 (when message-generate-headers-first
3302 (message-generate-headers
3305 (copy-sequence message-required-mail-headers))))))
3306 (run-hooks 'message-signature-setup-hook)
3307 (message-insert-signature)
3309 (message-narrow-to-headers)
3310 (run-hooks 'message-header-setup-hook))
3311 (set-buffer-modified-p nil)
3312 (setq buffer-undo-list nil)
3313 (run-hooks 'message-setup-hook)
3314 (message-position-point)
3317 (defun message-set-auto-save-file-name ()
3318 "Associate the message buffer with a file in the drafts directory."
3319 (when message-autosave-directory
3321 (setq message-draft-article
3322 (nndraft-request-associate-buffer "drafts"))
3323 (setq buffer-file-name (expand-file-name "*message*"
3324 message-autosave-directory))
3325 (setq buffer-auto-save-file-name (make-auto-save-file-name)))
3326 (clear-visited-file-modtime)))
3328 (defun message-disassociate-draft ()
3329 "Disassociate the message buffer from the drafts directory."
3330 (when message-draft-article
3331 (nndraft-request-expire-articles
3332 (list message-draft-article) "drafts" nil t)))
3337 ;;; Commands for interfacing with message
3341 (defun message-mail (&optional to subject
3342 other-headers continue switch-function
3343 yank-action send-actions)
3344 "Start editing a mail message to be sent."
3346 (let ((message-this-is-mail t))
3347 (message-pop-to-buffer (message-buffer-name "mail" to))
3350 `((To . ,(or to "")) (Subject . ,(or subject "")))
3351 (when other-headers other-headers)))))
3354 (defun message-news (&optional newsgroups subject)
3355 "Start editing a news article to be sent."
3357 (let ((message-this-is-news t))
3358 (message-pop-to-buffer (message-buffer-name "news" nil newsgroups))
3359 (message-setup `((Newsgroups . ,(or newsgroups ""))
3360 (Subject . ,(or subject ""))))))
3363 (defun message-reply (&optional to-address wide ignore-reply-to)
3364 "Start editing a reply to the article in the current buffer."
3366 (let ((cur (current-buffer))
3367 from subject date reply-to to cc
3368 references message-id follow-to
3369 (inhibit-point-motion-hooks t)
3370 mct never-mct gnus-warning)
3372 (message-narrow-to-head)
3373 ;; Allow customizations to have their say.
3375 ;; This is a regular reply.
3376 (if (message-functionp message-reply-to-function)
3377 (setq follow-to (funcall message-reply-to-function)))
3378 ;; This is a followup.
3379 (if (message-functionp message-wide-reply-to-function)
3382 (funcall message-wide-reply-to-function)))))
3383 ;; Find all relevant headers we need.
3384 (setq from (message-fetch-field "from")
3385 date (message-fetch-field "date")
3386 subject (or (message-fetch-field "subject") "none")
3387 to (message-fetch-field "to")
3388 cc (message-fetch-field "cc")
3389 mct (message-fetch-field "mail-copies-to")
3390 reply-to (unless ignore-reply-to (message-fetch-field "reply-to"))
3391 references (message-fetch-field "references")
3392 message-id (message-fetch-field "message-id" t))
3393 ;; Remove any (buggy) Re:'s that are present and make a
3395 (when (string-match "^[ \t]*[Rr][Ee]:[ \t]*" subject)
3396 (setq subject (substring subject (match-end 0))))
3397 (setq subject (concat "Re: " subject))
3399 (when (and (setq gnus-warning (message-fetch-field "gnus-warning"))
3400 (string-match "<[^>]+>" gnus-warning))
3401 (setq message-id (match-string 0 gnus-warning)))
3403 ;; Handle special values of Mail-Copies-To.
3405 (cond ((equal (downcase mct) "never")
3408 ((equal (downcase mct) "always")
3409 (setq mct (or reply-to from)))))
3415 (setq follow-to (list (cons 'To (or to-address reply-to from))))
3416 (when (and wide mct)
3417 (push (cons 'Cc mct) follow-to)))
3420 (message-set-work-buffer)
3422 (insert (or reply-to from "")))
3423 (insert (if to (concat (if (bolp) "" ", ") to "") ""))
3424 (insert (if mct (concat (if (bolp) "" ", ") mct) ""))
3425 (insert (if cc (concat (if (bolp) "" ", ") cc) ""))
3426 (goto-char (point-min))
3427 (while (re-search-forward "[ \t]+" nil t)
3428 (replace-match " " t t))
3429 ;; Remove addresses that match `rmail-dont-reply-to-names'.
3430 (insert (prog1 (rmail-dont-reply-to (buffer-string))
3432 (goto-char (point-min))
3433 ;; Perhaps Mail-Copies-To: never removed the only address?
3435 (insert (or reply-to from "")))
3439 (cons (mail-strip-quoted-names addr) addr))
3440 (message-tokenize-header (buffer-string))))
3443 (setq ccalist (delq (assoc (car (pop s)) s) ccalist)))))
3444 (setq follow-to (list (cons 'To (cdr (pop ccalist)))))
3446 (let ((ccs (cons 'Cc (mapconcat
3447 (lambda (addr) (cdr addr)) ccalist ", "))))
3448 (when (string-match "^ +" (cdr ccs))
3449 (setcdr ccs (substring (cdr ccs) (match-end 0))))
3450 (push ccs follow-to))))))
3453 (message-pop-to-buffer (message-buffer-name
3454 (if wide "wide reply" "reply") from
3455 (if wide to-address nil)))
3457 (setq message-reply-headers
3458 (vector 0 subject from date message-id references 0 0 ""))
3461 `((Subject . ,subject)
3463 ,@(if (or references message-id)
3464 `((References . ,(concat (or references "") (and references " ")
3465 (or message-id ""))))
3470 (defun message-wide-reply (&optional to-address ignore-reply-to)
3471 "Make a \"wide\" reply to the message in the current buffer."
3473 (message-reply to-address t ignore-reply-to))
3476 (defun message-followup (&optional to-newsgroups)
3477 "Follow up to the message in the current buffer.
3478 If TO-NEWSGROUPS, use that as the new Newsgroups line."
3480 (let ((cur (current-buffer))
3481 from subject date reply-to mct
3482 references message-id follow-to
3483 (inhibit-point-motion-hooks t)
3484 (message-this-is-news t)
3485 followup-to distribution newsgroups gnus-warning posted-to)
3488 (goto-char (point-min))
3489 (if (search-forward "\n\n" nil t)
3492 (when (message-functionp message-followup-to-function)
3494 (funcall message-followup-to-function)))
3495 (setq from (message-fetch-field "from")
3496 date (message-fetch-field "date")
3497 subject (or (message-fetch-field "subject") "none")
3498 references (message-fetch-field "references")
3499 message-id (message-fetch-field "message-id" t)
3500 followup-to (message-fetch-field "followup-to")
3501 newsgroups (message-fetch-field "newsgroups")
3502 posted-to (message-fetch-field "posted-to")
3503 reply-to (message-fetch-field "reply-to")
3504 distribution (message-fetch-field "distribution")
3505 mct (message-fetch-field "mail-copies-to"))
3506 (when (and (setq gnus-warning (message-fetch-field "gnus-warning"))
3507 (string-match "<[^>]+>" gnus-warning))
3508 (setq message-id (match-string 0 gnus-warning)))
3509 ;; Remove bogus distribution.
3510 (when (and (stringp distribution)
3511 (let ((case-fold-search t))
3512 (string-match "world" distribution)))
3513 (setq distribution nil))
3514 ;; Remove any (buggy) Re:'s that are present and make a
3516 (when (string-match "^[ \t]*[Rr][Ee]:[ \t]*" subject)
3517 (setq subject (substring subject (match-end 0))))
3518 (setq subject (concat "Re: " subject))
3521 (message-pop-to-buffer (message-buffer-name "followup" from newsgroups))
3524 `((Subject . ,subject)
3527 (list (cons 'Newsgroups to-newsgroups)))
3528 (follow-to follow-to)
3529 ((and followup-to message-use-followup-to)
3532 ((equal (downcase followup-to) "poster")
3533 (if (or (eq message-use-followup-to 'use)
3534 (message-y-or-n-p "Obey Followup-To: poster? " t "\
3535 You should normally obey the Followup-To: header.
3537 `Followup-To: poster' sends your response via e-mail instead of news.
3539 A typical situation where `Followup-To: poster' is used is when the poster
3540 does not read the newsgroup, so he wouldn't see any replies sent to it."))
3542 (setq message-this-is-news nil)
3543 (cons 'To (or reply-to from "")))
3544 (cons 'Newsgroups newsgroups)))
3546 (if (or (equal followup-to newsgroups)
3547 (not (eq message-use-followup-to 'ask))
3549 (concat "Obey Followup-To: " followup-to "? ") t "\
3550 You should normally obey the Followup-To: header.
3552 `Followup-To: " followup-to "'
3553 directs your response to " (if (string-match "," followup-to)
3554 "the specified newsgroups"
3555 "that newsgroup only") ".
3557 If a message is posted to several newsgroups, Followup-To is often
3558 used to direct the following discussion to one newsgroup only,
3559 because discussions that are spread over several newsgroup tend to
3560 be fragmented and very difficult to follow.
3562 Also, some source/announcement newsgroups are not indented for discussion;
3563 responses here are directed to other newsgroups."))
3564 (cons 'Newsgroups followup-to)
3565 (cons 'Newsgroups newsgroups))))))
3567 `((Newsgroups . ,posted-to)))
3569 `((Newsgroups . ,newsgroups))))
3570 ,@(and distribution (list (cons 'Distribution distribution)))
3571 ,@(if (or references message-id)
3572 `((References . ,(concat (or references "") (and references " ")
3573 (or message-id "")))))
3575 (not (equal (downcase mct) "never")))
3576 (list (cons 'Cc (if (equal (downcase mct) "always")
3577 (or reply-to from "")
3582 (setq message-reply-headers
3583 (vector 0 subject from date message-id references 0 0 ""))))
3587 (defun message-cancel-news ()
3588 "Cancel an article you posted."
3590 (unless (message-news-p)
3591 (error "This is not a news article; canceling is impossible"))
3592 (when (yes-or-no-p "Do you really want to cancel this article? ")
3593 (let (from newsgroups message-id distribution buf sender)
3595 ;; Get header info. from original article.
3597 (message-narrow-to-head)
3598 (setq from (message-fetch-field "from")
3599 sender (message-fetch-field "sender")
3600 newsgroups (message-fetch-field "newsgroups")
3601 message-id (message-fetch-field "message-id" t)
3602 distribution (message-fetch-field "distribution")))
3603 ;; Make sure that this article was written by the user.
3604 (unless (string-equal
3606 (or sender (cadr (std11-extract-address-components from))))
3607 (downcase (message-make-address)))
3608 (error "This article is not yours"))
3609 ;; Make control message.
3610 (setq buf (set-buffer (get-buffer-create " *message cancel*")))
3611 (buffer-disable-undo (current-buffer))
3613 (insert "Newsgroups: " newsgroups "\n"
3614 "From: " (message-make-from) "\n"
3615 "Subject: cmsg cancel " message-id "\n"
3616 "Control: cancel " message-id "\n"
3618 (concat "Distribution: " distribution "\n")
3620 mail-header-separator "\n"
3621 message-cancel-message)
3622 (message "Canceling your article...")
3623 (if (let ((message-syntax-checks
3624 'dont-check-for-anything-just-trust-me)
3625 (message-encoding-buffer (current-buffer))
3626 (message-edit-buffer (current-buffer)))
3627 (message-send-news))
3628 (message "Canceling your article...done"))
3629 (kill-buffer buf)))))
3632 (defun message-supersede ()
3633 "Start composing a message to supersede the current message.
3634 This is done simply by taking the old article and adding a Supersedes
3635 header line with the old Message-ID."
3637 (let ((cur (current-buffer)))
3638 ;; Check whether the user owns the article that is to be superseded.
3639 (unless (string-equal
3640 (downcase (or (message-fetch-field "sender")
3641 (cadr (mail-extract-address-components
3642 (message-fetch-field "from")))))
3643 (downcase (message-make-sender)))
3644 (error "This article is not yours"))
3645 ;; Get a normal message buffer.
3646 (message-pop-to-buffer (message-buffer-name "supersede"))
3647 (insert-buffer-substring cur)
3648 (message-narrow-to-head)
3649 ;; Remove unwanted headers.
3650 (when message-ignored-supersedes-headers
3651 (message-remove-header message-ignored-supersedes-headers t))
3652 (goto-char (point-min))
3653 (if (not (re-search-forward "^Message-ID: " nil t))
3654 (error "No Message-ID in this article")
3655 (replace-match "Supersedes: " t t))
3656 (goto-char (point-max))
3657 (insert mail-header-separator)
3662 (defun message-recover ()
3663 "Reread contents of current buffer from its last auto-save file."
3665 (let ((file-name (make-auto-save-file-name)))
3666 (cond ((save-window-excursion
3667 (if (not (eq system-type 'vax-vms))
3668 (with-output-to-temp-buffer "*Directory*"
3669 (buffer-disable-undo standard-output)
3670 (let ((default-directory "/"))
3672 "ls" nil standard-output nil "-l" file-name))))
3673 (yes-or-no-p (format "Recover auto save file %s? " file-name)))
3674 (let ((buffer-read-only nil))
3676 (insert-file-contents file-name nil)))
3677 (t (error "message-recover cancelled")))))
3679 ;;; Forwarding messages.
3681 (defun message-make-forward-subject ()
3682 "Return a Subject header suitable for the message in the current buffer."
3686 (message-narrow-to-head)
3687 (concat "[" (or (message-fetch-field
3688 (if (message-news-p) "newsgroups" "from"))
3690 "] " (or (eword-decode-unstructured-field-body
3691 (message-fetch-field "Subject") ""))))))
3694 (defun message-forward (&optional news)
3695 "Forward the current message via mail.
3696 Optional NEWS will use news to forward instead of mail."
3698 (let ((cur (current-buffer))
3699 (subject (message-make-forward-subject))
3701 (if news (message-news nil subject) (message-mail nil subject))
3702 ;; Put point where we want it before inserting the forwarded
3704 (if message-signature-before-forwarded-message
3705 (goto-char (point-max))
3706 (message-goto-body))
3707 ;; Make sure we're at the start of the line.
3710 ;; Narrow to the area we are to insert.
3711 (narrow-to-region (point) (point))
3712 ;; Insert the separators and the forwarded buffer.
3713 (insert message-forward-start-separator)
3714 (setq art-beg (point))
3715 (insert-buffer-substring cur)
3716 (goto-char (point-max))
3717 (insert message-forward-end-separator)
3718 (set-text-properties (point-min) (point-max) nil)
3719 ;; Remove all unwanted headers.
3721 (narrow-to-region (point) (if (search-forward "\n\n" nil t)
3724 (goto-char (point-min))
3725 (message-remove-header message-included-forward-headers t nil t)
3727 (message-position-point)))
3730 (defun message-resend (address)
3731 "Resend the current article to ADDRESS."
3732 (interactive "sResend message to: ")
3733 (message "Resending message to %s..." address)
3735 (let ((cur (current-buffer))
3737 ;; We first set up a normal mail buffer.
3738 (set-buffer (get-buffer-create " *message resend*"))
3739 (buffer-disable-undo (current-buffer))
3741 ;; avoid to turn-on-mime-edit
3742 (let (message-setup-hook)
3743 (message-setup `((To . ,address)))
3745 ;; Insert our usual headers.
3746 (message-generate-headers '(From Date To))
3747 (message-narrow-to-headers)
3748 ;; Rename them all to "Resent-*".
3749 (while (re-search-forward "^[A-Za-z]" nil t)
3754 (delete-region (point) (point-max))
3756 ;; Insert the message to be resent.
3757 (insert-buffer-substring cur)
3758 (goto-char (point-min))
3759 (search-forward "\n\n")
3762 (narrow-to-region beg (point))
3763 (message-remove-header message-ignored-resent-headers t)
3764 (goto-char (point-max)))
3765 (insert mail-header-separator)
3766 ;; Rename all old ("Also-")Resent headers.
3767 (while (re-search-backward "^\\(Also-\\)*Resent-" beg t)
3770 ;; Quote any "From " lines at the beginning.
3772 (when (looking-at "From ")
3773 (replace-match "X-From-Line: "))
3775 (let ((message-encoding-buffer (current-buffer))
3776 (message-edit-buffer (current-buffer)))
3777 (message-send-mail))
3778 (kill-buffer (current-buffer)))
3779 (message "Resending message to %s...done" address)))
3782 (defun message-bounce ()
3783 "Re-mail the current message.
3784 This only makes sense if the current message is a bounce message than
3785 contains some mail you have written which has been bounced back to
3788 (let ((cur (current-buffer))
3790 (message-pop-to-buffer (message-buffer-name "bounce"))
3791 (insert-buffer-substring cur)
3793 (message-narrow-to-head)
3794 (if (and (message-fetch-field "Mime-Version")
3795 (setq boundary (message-fetch-field "Content-Type")))
3796 (if (string-match "boundary=\"\\([^\"]+\\)\"" boundary)
3797 (setq boundary (concat (match-string 1 boundary) " *\n"
3798 "Content-Type: message/rfc822"))
3799 (setq boundary nil)))
3801 (goto-char (point-min))
3802 (search-forward "\n\n" nil t)
3804 (re-search-forward boundary nil t)
3806 (and (re-search-forward message-unsent-separator nil t)
3808 (re-search-forward "^Return-Path:.*\n" nil t))
3809 ;; We remove everything before the bounced mail.
3812 (if (re-search-forward "^[^ \n\t]+:" nil t)
3816 (message-narrow-to-head)
3817 (message-remove-header message-ignored-bounced-headers t)
3818 (goto-char (point-max))
3819 (insert mail-header-separator))
3820 (message-position-point)))
3823 ;;; Interactive entry points for new message buffers.
3827 (defun message-mail-other-window (&optional to subject)
3828 "Like `message-mail' command, but display mail buffer in another window."
3830 (let ((pop-up-windows t)
3831 (special-display-buffer-names nil)
3832 (special-display-regexps nil)
3833 (same-window-buffer-names nil)
3834 (same-window-regexps nil))
3835 (message-pop-to-buffer (message-buffer-name "mail" to)))
3836 (message-setup `((To . ,(or to "")) (Subject . ,(or subject "")))))
3839 (defun message-mail-other-frame (&optional to subject)
3840 "Like `message-mail' command, but display mail buffer in another frame."
3842 (let ((pop-up-frames t)
3843 (special-display-buffer-names nil)
3844 (special-display-regexps nil)
3845 (same-window-buffer-names nil)
3846 (same-window-regexps nil))
3847 (message-pop-to-buffer (message-buffer-name "mail" to)))
3848 (message-setup `((To . ,(or to "")) (Subject . ,(or subject "")))))
3851 (defun message-news-other-window (&optional newsgroups subject)
3852 "Start editing a news article to be sent."
3854 (let ((pop-up-windows t)
3855 (special-display-buffer-names nil)
3856 (special-display-regexps nil)
3857 (same-window-buffer-names nil)
3858 (same-window-regexps nil))
3859 (message-pop-to-buffer (message-buffer-name "news" nil newsgroups)))
3860 (message-setup `((Newsgroups . ,(or newsgroups ""))
3861 (Subject . ,(or subject "")))))
3864 (defun message-news-other-frame (&optional newsgroups subject)
3865 "Start editing a news article to be sent."
3867 (let ((pop-up-frames t)
3868 (special-display-buffer-names nil)
3869 (special-display-regexps nil)
3870 (same-window-buffer-names nil)
3871 (same-window-regexps nil))
3872 (message-pop-to-buffer (message-buffer-name "news" nil newsgroups)))
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))
3948 (cur (current-buffer))
3950 (delete-region b (point))
3952 ((= (length completions) 1)
3953 (if (string= (car completions) string)
3956 (message "Only matching group"))
3957 (insert (car completions))))
3958 ((and (setq comp (try-completion string hashtb))
3959 (not (string= comp string)))
3964 (message "No matching groups")
3965 (save-selected-window
3966 (pop-to-buffer "*Completions*")
3967 (buffer-disable-undo (current-buffer))
3968 (let ((buffer-read-only nil))
3970 (let ((standard-output (current-buffer)))
3971 (display-completion-list (sort completions 'string<)))
3972 (goto-char (point-min))
3973 (delete-region (point) (progn (forward-line 3) (point))))))))))
3977 (defun message-talkative-question (ask question show &rest text)
3978 "Call FUNCTION with argument QUESTION; optionally display TEXT... args.
3979 If SHOW is non-nil, the arguments TEXT... are displayed in a temp buffer.
3980 The following arguments may contain lists of values."
3982 (setq text (message-flatten-list text)))
3983 (save-window-excursion
3985 (with-output-to-temp-buffer " *MESSAGE information message*"
3986 (set-buffer " *MESSAGE information message*")
3987 (mapcar 'princ text)
3988 (goto-char (point-min))))
3989 (funcall ask question))
3990 (funcall ask question)))
3992 (defun message-flatten-list (list)
3993 "Return a new, flat list that contains all elements of LIST.
3995 \(message-flatten-list '(1 (2 3 (4 5 (6))) 7))
3998 (apply 'append (mapcar 'message-flatten-list list)))
4002 (defun message-generate-new-buffer-clone-locals (name &optional varstr)
4003 "Create and return a buffer with a name based on NAME using generate-new-buffer.
4004 Then clone the local variables and values from the old buffer to the
4005 new one, cloning only the locals having a substring matching the
4007 (let ((oldbuf (current-buffer)))
4009 (set-buffer (generate-new-buffer name))
4010 (message-clone-locals oldbuf)
4013 (defun message-clone-locals (buffer)
4014 "Clone the local variables from BUFFER to the current buffer."
4015 (let ((locals (save-excursion
4017 (buffer-local-variables)))
4018 (regexp "^gnus\\|^nn\\|^message"))
4021 (when (and (consp local)
4023 (string-match regexp (symbol-name (car local))))
4025 (set (make-local-variable (car local))
4030 ;;; @ for MIME Edit mode
4033 (defun message-maybe-setup-default-charset ()
4035 (and (boundp 'gnus-summary-buffer)
4036 (buffer-live-p gnus-summary-buffer)
4038 (set-buffer gnus-summary-buffer)
4039 default-mime-charset))))
4042 (make-local-variable 'default-mime-charset)
4043 (setq default-mime-charset charset)
4046 (defun message-maybe-encode ()
4047 (when message-mime-mode
4048 (run-hooks 'mime-edit-translate-hook)
4049 (if (catch 'mime-edit-error
4051 (mime-edit-translate-body)
4053 (error "Translation error!")
4056 (run-hooks 'mime-edit-exit-hook)
4059 (defun message-mime-insert-article (&optional message)
4061 (let ((message-cite-function 'mime-edit-inserted-message-filter)
4062 (message-reply-buffer gnus-original-article-buffer)
4064 (message-yank-original nil)
4067 (set-alist 'mime-edit-message-inserter-alist
4068 'message-mode (function message-mime-insert-article))
4070 ;;; Miscellaneous functions
4072 ;; stolen (and renamed) from nnheader.el
4073 (defun message-replace-chars-in-string (string from to)
4074 "Replace characters in STRING from FROM to TO."
4075 (let ((string (substring string 0)) ;Copy string.
4076 (len (length string))
4078 ;; Replace all occurrences of FROM with TO.
4080 (when (= (aref string idx) from)
4081 (aset string idx to))
4082 (setq idx (1+ idx)))
4085 (run-hooks 'message-load-hook)
4089 ;;; message.el ends here