1 ;;; message.el --- composing mail and news messages
2 ;; Copyright (C) 1996,97,98 Free Software Foundation, Inc.
4 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
5 ;; MORIOKA Tomohiko <morioka@jaist.ac.jp>
6 ;; Shuhei KOBAYASHI <shuhei-k@jaist.ac.jp>
7 ;; Keiichi Suzuki <kei-suzu@mail.wbs.ne.jp>
8 ;; Keywords: mail, news, MIME
10 ;; This file is part of GNU Emacs.
12 ;; GNU Emacs is free software; you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation; either version 2, or (at your option)
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the
24 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
25 ;; Boston, MA 02111-1307, USA.
29 ;; This mode provides mail-sending facilities from within Emacs. It
30 ;; consists mainly of large chunks of code from the sendmail.el,
31 ;; gnus-msg.el and rnewspost.el files.
45 (if (string-match "XEmacs\\|Lucid" emacs-version)
46 (require 'mail-abbrevs)
47 (require 'mailabbrev))
50 (defgroup message '((user-mail-address custom-variable)
51 (user-full-name custom-variable))
52 "Mail and news message composing."
53 :link '(custom-manual "(message)Top")
57 (put 'user-mail-address 'custom-type 'string)
58 (put 'user-full-name 'custom-type 'string)
60 (defgroup message-various nil
61 "Various Message Variables"
62 :link '(custom-manual "(message)Various Message Variables")
65 (defgroup message-buffers nil
67 :link '(custom-manual "(message)Message Buffers")
70 (defgroup message-sending nil
72 :link '(custom-manual "(message)Sending Variables")
75 (defgroup message-interface nil
77 :link '(custom-manual "(message)Interface")
80 (defgroup message-forwarding nil
82 :link '(custom-manual "(message)Forwarding")
83 :group 'message-interface)
85 (defgroup message-insertion nil
87 :link '(custom-manual "(message)Insertion")
90 (defgroup message-headers nil
92 :link '(custom-manual "(message)Message Headers")
95 (defgroup message-news nil
96 "Composing News Messages"
99 (defgroup message-mail nil
100 "Composing Mail Messages"
103 (defgroup message-faces nil
104 "Faces used for message composing."
108 (defgroup message-frames nil
112 (defcustom message-directory "~/Mail/"
113 "*Directory from which all other mail file variables are derived."
114 :group 'message-various
117 (defcustom message-max-buffers 10
118 "*How many buffers to keep before starting to kill them off."
119 :group 'message-buffers
122 (defcustom message-send-rename-function nil
123 "Function called to rename the buffer after sending it."
124 :group 'message-buffers
127 (defcustom message-fcc-handler-function 'message-output
128 "*A function called to save outgoing articles.
129 This function will be called with the name of the file to store the
130 article in. The default function is `message-output' which saves in Unix
132 :type '(radio (function-item message-output)
133 (function :tag "Other"))
134 :group 'message-sending)
136 (defcustom message-encode-function 'message-maybe-encode
137 "*A function called to encode messages."
138 :group 'message-sending
141 (defcustom message-courtesy-message
142 "The following message is a courtesy copy of an article\nthat has been posted to %s as well.\n\n"
143 "*This is inserted at the start of a mailed copy of a posted message.
144 If the string contains the format spec \"%s\", the Newsgroups
145 the article has been posted to will be inserted there.
146 If this variable is nil, no such courtesy message will be added."
147 :group 'message-sending
150 (defcustom message-ignored-bounced-headers "^\\(Received\\|Return-Path\\):"
151 "*Regexp that matches headers to be removed in resent bounced mail."
152 :group 'message-interface
156 (defcustom message-from-style 'default
157 "*Specifies how \"From\" headers look.
159 If `nil', they contain just the return address like:
161 If `parens', they look like:
162 king@grassland.com (Elvis Parsley)
163 If `angles', they look like:
164 Elvis Parsley <king@grassland.com>
166 Otherwise, most addresses look like `angles', but they look like
167 `parens' if `angles' would need quoting and `parens' would not."
168 :type '(choice (const :tag "simple" nil)
172 :group 'message-headers)
174 (defcustom message-syntax-checks nil
175 ; Guess this one shouldn't be easy to customize...
176 "*Controls what syntax checks should not be performed on outgoing posts.
177 To disable checking of long signatures, for instance, add
178 `(signature . disabled)' to this list.
180 Don't touch this variable unless you really know what you're doing.
182 Checks include subject-cmsg multiple-headers sendsys message-id from
183 long-lines control-chars size new-text redirected-followup signature
184 approved sender empty empty-headers message-id from subject
185 shorten-followup-to existing-newsgroups buffer-file-name unchanged."
186 :group 'message-news)
188 (defcustom message-required-news-headers
189 '(From Newsgroups Subject Date Message-ID
190 (optional . Organization) Lines
191 (optional . User-Agent))
192 "*Headers to be generated or prompted for when posting an article.
193 RFC977 and RFC1036 require From, Date, Newsgroups, Subject,
194 Message-ID. Organization, Lines, In-Reply-To, Expires, and
195 User-Agent are optional. If don't you want message to insert some
196 header, remove it from this list."
198 :group 'message-headers
199 :type '(repeat sexp))
201 (defcustom message-required-mail-headers
202 '(From Subject Date (optional . In-Reply-To) Message-ID Lines
203 (optional . User-Agent))
204 "*Headers to be generated or prompted for when mailing a message.
205 RFC822 required that From, Date, To, Subject and Message-ID be
206 included. Organization, Lines and User-Agent are optional."
208 :group 'message-headers
209 :type '(repeat sexp))
211 (defcustom message-deletable-headers '(Message-ID Date Lines)
212 "Headers to be deleted if they already exist and were generated by message previously."
213 :group 'message-headers
216 (defcustom message-ignored-news-headers
217 "^NNTP-Posting-Host:\\|^Xref:\\|^[BGF]cc:\\|^Resent-Fcc:"
218 "*Regexp of headers to be removed unconditionally before posting."
220 :group 'message-headers
223 (defcustom message-ignored-mail-headers "^[GF]cc:\\|^Resent-Fcc:\\|^Xref:"
224 "*Regexp of headers to be removed unconditionally before mailing."
226 :group 'message-headers
229 (defcustom message-ignored-supersedes-headers "^Path:\\|^Date\\|^NNTP-Posting-Host:\\|^Xref:\\|^Lines:\\|^Received:\\|^X-From-Line:\\|^X-Trace:\\|^X-Complaints-To:\\|Return-Path:\\|^Supersedes:"
230 "*Header lines matching this regexp will be deleted before posting.
231 It's best to delete old Path and Date headers before posting to avoid
233 :group 'message-interface
236 (defcustom message-subject-re-regexp "^[ \t]*\\([Rr][Ee]:[ \t]*\\)*[ \t]*"
237 "*Regexp matching \"Re: \" in the subject line."
238 :group 'message-various
241 ;;; Some sender agents encode the whole subject including leading "Re: ".
242 ;;; And if followup agent does not decode it for some reason (e.g. unknown
243 ;;; charset) and just add a new "Re: " in front of the encoded-word, the
244 ;;; result will contain multiple "Re: "'s.
245 (defcustom message-subject-encoded-re-regexp
249 "[-!#$%&'*+0-9A-Z^_`a-z{|}~]+" ; charset
252 "[Bb]" (regexp-quote "?") ; B encoding
253 "\\(\\(CQk\\|CSA\\|IAk\\|ICA\\)[Jg]\\)*" ; \([ \t][ \t][ \t]\)*
255 "[Uc][km]U6" ; [Rr][Ee]:
257 "\\(C[VX]\\|I[FH]\\)J[Fl]O[g-v]" ; [ \t][Rr][Ee]:
259 "\\(CQl\\|CSB\\|IAl\\|ICB\\)[Sy][RZ]T[o-r]" ; [ \t][ \t][Rr][Ee]:
262 "[Qb]" (regexp-quote "?") ; Q encoding
263 "\\(_\\|=09\\|=20\\)*"
264 "\\([Rr]\\|=[57]2\\)\\([Ee]\\|=[46]5\\)\\(:\\|=3[Aa]\\)"
267 "*Regexp matching \"Re: \" in the subject line.
268 Unlike `message-subject-re-regexp', this regexp matches \"Re: \" within
270 :group 'message-various
273 (defcustom message-use-subject-re t
274 "*If t, remove any (buggy) \"Re: \"'s from the subject of the precursor
275 and add a new \"Re: \". If it is nil, use the subject \"as-is\". If it
276 is the symbol `guess', try to detect \"Re: \" within an encoded-word."
277 :group 'message-various
278 :type '(choice (const :tag "off" nil)
283 (defcustom message-signature-separator "^-- *$"
284 "Regexp matching the signature separator."
286 :group 'message-various)
288 (defcustom message-elide-elipsis "\n[...]\n\n"
289 "*The string which is inserted for elided text."
291 :group 'message-various)
293 (defcustom message-interactive nil
294 "Non-nil means when sending a message wait for and display errors.
295 nil means let mailer mail back a message to report errors."
296 :group 'message-sending
300 (defcustom message-generate-new-buffers t
301 "*Non-nil means that a new message buffer will be created whenever `message-setup' is called.
302 If this is a function, call that function with three parameters: The type,
303 the to address and the group name. (Any of these may be nil.) The function
304 should return the new buffer name."
305 :group 'message-buffers
306 :type '(choice (const :tag "off" nil)
310 (defcustom message-kill-buffer-on-exit nil
311 "*Non-nil means that the message buffer will be killed after sending a message."
312 :group 'message-buffers
315 (defvar gnus-local-organization)
316 (defcustom message-user-organization
317 (or (and (boundp 'gnus-local-organization)
318 (stringp gnus-local-organization)
319 gnus-local-organization)
320 (getenv "ORGANIZATION")
322 "*String to be used as an Organization header.
323 If t, use `message-user-organization-file'."
324 :group 'message-headers
325 :type '(choice string
326 (const :tag "consult file" t)))
329 (defcustom message-user-organization-file "/usr/lib/news/organization"
330 "*Local news organization file."
332 :group 'message-headers)
334 (defcustom message-forward-start-separator
335 (concat (mime-make-tag "message" "rfc822") "\n")
336 "*Delimiter inserted before forwarded messages."
337 :group 'message-forwarding
340 (defcustom message-forward-end-separator
341 (concat (mime-make-tag "text" "plain") "\n")
342 "*Delimiter inserted after forwarded messages."
343 :group 'message-forwarding
346 (defcustom message-signature-before-forwarded-message t
347 "*If non-nil, put the signature before any included forwarded message."
348 :group 'message-forwarding
351 (defcustom message-included-forward-headers
352 "^From:\\|^Newsgroups:\\|^Subject:\\|^Date:\\|^\\(Mail-\\)?Followup-To:\\|^\\(Mail-\\)?Reply-To:\\|^Mail-Copies-To:\\|^Organization:\\|^Summary:\\|^Keywords:\\|^To:\\|^Cc:\\|^Posted-To:\\|^Apparently-To:\\|^Gnus-Warning:\\|^Resent-\\|^Message-ID:\\|^References:\\|^Content-\\|^MIME-Version:"
353 "*Regexp matching headers to be included in forwarded messages."
354 :group 'message-forwarding
357 (defcustom message-make-forward-subject-function
358 'message-forward-subject-author-subject
359 "*A list of functions that are called to generate a subject header for forwarded messages.
360 The subject generated by the previous function is passed into each
363 The provided functions are:
365 * message-forward-subject-author-subject (Source of article (author or
366 newsgroup)), in brackets followed by the subject
367 * message-forward-subject-fwd (Subject of article with 'Fwd:' prepended
369 :group 'message-forwarding
370 :type '(radio (function-item message-forward-subject-author-subject)
371 (function-item message-forward-subject-fwd)))
373 (defcustom message-wash-forwarded-subjects nil
374 "*If non-nil, try to remove as much old cruft as possible from the subject of messages before generating the new subject of a forward."
375 :group 'message-forwarding
378 (defcustom message-ignored-resent-headers "^Return-Receipt"
379 "*All headers that match this regexp will be deleted when resending a message."
380 :group 'message-interface
383 (defcustom message-ignored-cited-headers "."
384 "*Delete these headers from the messages you yank."
385 :group 'message-insertion
388 (defcustom message-cancel-message "I am canceling my own article."
389 "Message to be inserted in the cancel message."
390 :group 'message-interface
393 ;; Useful to set in site-init.el
395 (defcustom message-send-mail-function 'message-send-mail-with-sendmail
396 "Function to call to send the current buffer as mail.
397 The headers should be delimited by a line whose contents match the
398 variable `mail-header-separator'.
400 Legal values include `message-send-mail-with-sendmail' (the default),
401 `message-send-mail-with-mh', `message-send-mail-with-qmail' and
402 `message-send-mail-with-smtp'."
403 :type '(radio (function-item message-send-mail-with-sendmail)
404 (function-item message-send-mail-with-mh)
405 (function-item message-send-mail-with-qmail)
406 (function-item message-send-mail-with-smtp)
407 (function :tag "Other"))
408 :group 'message-sending
409 :group 'message-mail)
411 ;; 1997-09-29 by MORIOKA Tomohiko
412 (defcustom message-send-news-function 'message-send-news-with-gnus
413 "Function to call to send the current buffer as news.
414 The headers should be delimited by a line whose contents match the
415 variable `mail-header-separator'."
416 :group 'message-sending
420 (defcustom message-reply-to-function nil
421 "Function that should return a list of headers.
422 This function should pick out addresses from the To, Cc, and From headers
423 and respond with new To and Cc headers."
424 :group 'message-interface
427 (defcustom message-wide-reply-to-function nil
428 "Function that should return a list of headers.
429 This function should pick out addresses from the To, Cc, and From headers
430 and respond with new To and Cc headers."
431 :group 'message-interface
434 (defcustom message-followup-to-function nil
435 "Function that should return a list of headers.
436 This function should pick out addresses from the To, Cc, and From headers
437 and respond with new To and Cc headers."
438 :group 'message-interface
441 (defcustom message-use-followup-to 'ask
442 "*Specifies what to do with Followup-To header.
443 If nil, always ignore the header. If it is t, use its value, but
444 query before using the \"poster\" value. If it is the symbol `ask',
445 always query the user whether to use the value. If it is the symbol
446 `use', always use the value."
447 :group 'message-interface
448 :type '(choice (const :tag "ignore" nil)
449 (const :tag "maybe" t)
450 (const :tag "always" use)
451 (const :tag "ask" ask)))
453 (defcustom message-use-mail-copies-to 'ask
454 "*Specifies what to do with Mail-Copies-To header.
455 If nil, always ignore the header. If it is t, use its value, but
456 query before using the value other than \"always\" or \"never\".
457 If it is the symbol `ask', always query the user whether to use
458 the value. If it is the symbol `use', always use the value."
459 :group 'message-interface
460 :type '(choice (const :tag "ignore" nil)
461 (const :tag "maybe" t)
462 (const :tag "always" use)
463 (const :tag "ask" ask)))
465 (defcustom message-use-mail-followup-to 'ask
466 "*Specifies what to do with Mail-Followup-To header.
467 If nil, always ignore the header. If it is the symbol `ask', always
468 query the user whether to use the value. If it is t or the symbol
469 `use', always use the value."
470 :group 'message-interface
471 :type '(choice (const :tag "ignore" nil)
472 (const :tag "maybe" t)
473 (const :tag "always" use)
474 (const :tag "ask" ask)))
476 ;;; XXX: 'ask and 'use are not implemented yet.
477 (defcustom message-use-mail-reply-to 'ask
478 "*Specifies what to do with Mail-Reply-To/Reply-To header.
479 If nil, always ignore the header. If it is t or the symbol `use', use
480 its value. If it is the symbol `ask', always query the user whether to
481 use the value. Note that if \"Reply-To\" is marked as \"broken\", its value
483 :group 'message-interface
484 :type '(choice (const :tag "ignore" nil)
485 (const :tag "maybe" t)
486 (const :tag "always" use)
487 (const :tag "ask" ask)))
489 ;; stuff relating to broken sendmail in MMDF
490 (defcustom message-sendmail-f-is-evil nil
491 "*Non-nil means that \"-f username\" should not be added to the sendmail
492 command line, because it is even more evil than leaving it out."
493 :group 'message-sending
496 ;; qmail-related stuff
497 (defcustom message-qmail-inject-program "/var/qmail/bin/qmail-inject"
498 "Location of the qmail-inject program."
499 :group 'message-sending
502 (defcustom message-qmail-inject-args nil
503 "Arguments passed to qmail-inject programs.
504 This should be a list of strings, one string for each argument.
506 For e.g., if you wish to set the envelope sender address so that bounces
507 go to the right place or to deal with listserv's usage of that address, you
508 might set this variable to '(\"-f\" \"you@some.where\")."
509 :group 'message-sending
510 :type '(repeat string))
512 (defvar gnus-post-method)
513 (defvar gnus-select-method)
514 (defcustom message-post-method
515 (cond ((and (boundp 'gnus-post-method)
516 (listp gnus-post-method)
519 ((boundp 'gnus-select-method)
522 "*Method used to post news.
523 Note that when posting from inside Gnus, for instance, this
524 variable isn't used."
526 :group 'message-sending
527 ;; This should be the `gnus-select-method' widget, but that might
528 ;; create a dependence to `gnus.el'.
531 (defcustom message-generate-headers-first nil
532 "*If non-nil, generate all possible headers before composing."
533 :group 'message-headers
536 (defcustom message-setup-hook
537 '(message-maybe-setup-default-charset turn-on-mime-edit)
538 "Normal hook, run each time a new outgoing message is initialized.
539 The function `message-setup' runs this hook."
540 :group 'message-various
543 (defcustom message-signature-setup-hook nil
544 "Normal hook, run each time a new outgoing message is initialized.
545 It is run after the headers have been inserted and before
546 the signature is inserted."
547 :group 'message-various
550 (defcustom message-mode-hook nil
551 "Hook run in message mode buffers."
552 :group 'message-various
555 (defcustom message-header-hook '(eword-encode-header)
556 "Hook run in a message mode buffer narrowed to the headers."
557 :group 'message-various
560 (defcustom message-header-setup-hook nil
561 "Hook called narrowed to the headers when setting up a message buffer."
562 :group 'message-various
566 (defcustom message-citation-line-function 'message-insert-citation-line
567 "*Function called to insert the \"Whomever writes:\" line."
569 :group 'message-insertion)
572 (defcustom message-yank-prefix "> "
573 "*Prefix inserted on the lines of yanked messages.
574 nil means use indentation."
576 :group 'message-insertion)
578 (defcustom message-indentation-spaces 3
579 "*Number of spaces to insert at the beginning of each cited line.
580 Used by `message-yank-original' via `message-yank-cite'."
581 :group 'message-insertion
585 (defcustom message-cite-function 'message-cite-original
586 "*Function for citing an original message.
587 Predefined functions include `message-cite-original' and
588 `message-cite-original-without-signature'.
589 Note that `message-cite-original' uses `mail-citation-hook' if that is non-nil."
590 :type '(radio (function-item message-cite-original)
591 (function-item sc-cite-original)
592 (function :tag "Other"))
593 :group 'message-insertion)
596 (defcustom message-indent-citation-function 'message-indent-citation
597 "*Function for modifying a citation just inserted in the mail buffer.
598 This can also be a list of functions. Each function can find the
599 citation between (point) and (mark t). And each function should leave
600 point and mark around the citation text as modified."
602 :group 'message-insertion)
604 (defvar message-abbrevs-loaded nil)
607 (defcustom message-signature t
608 "*String to be inserted at the end of the message buffer.
609 If t, the `message-signature-file' file will be inserted instead.
610 If a function, the result from the function will be used instead.
611 If a form, the result from the form will be used instead."
613 :group 'message-insertion)
616 (defcustom message-signature-file "~/.signature"
617 "*File containing the text inserted at end of message buffer."
619 :group 'message-insertion)
621 (defcustom message-distribution-function nil
622 "*Function called to return a Distribution header."
624 :group 'message-headers
627 (defcustom message-expires 14
628 "Number of days before your article expires."
630 :group 'message-headers
631 :link '(custom-manual "(message)News Headers")
634 (defcustom message-user-path nil
635 "If nil, use the NNTP server name in the Path header.
636 If stringp, use this; if non-nil, use no host name (user name only)."
638 :group 'message-headers
639 :link '(custom-manual "(message)News Headers")
640 :type '(choice (const :tag "nntp" nil)
642 (sexp :tag "none" :format "%t" t)))
644 (defvar message-reply-buffer nil)
645 (defvar message-reply-headers nil)
646 (defvar message-sent-message-via nil)
647 (defvar message-checksum nil)
648 (defvar message-send-actions nil
649 "A list of actions to be performed upon successful sending of a message.")
650 (defvar message-exit-actions nil
651 "A list of actions to be performed upon exiting after sending a message.")
652 (defvar message-kill-actions nil
653 "A list of actions to be performed before killing a message buffer.")
654 (defvar message-postpone-actions nil
655 "A list of actions to be performed after postponing a message.")
656 (defvar message-original-frame nil)
658 (define-widget 'message-header-lines 'text
659 "All header lines must be LFD terminated."
662 :error "All header lines must be newline terminated")
664 (defcustom message-default-headers ""
665 "*A string containing header lines to be inserted in outgoing messages.
666 It is inserted before you edit the message, so you can edit or delete
668 :group 'message-headers
669 :type 'message-header-lines)
671 (defcustom message-default-mail-headers ""
672 "*A string of header lines to be inserted in outgoing mails."
673 :group 'message-headers
675 :type 'message-header-lines)
677 (defcustom message-default-news-headers ""
678 "*A string of header lines to be inserted in outgoing news
680 :group 'message-headers
682 :type 'message-header-lines)
684 ;; Note: could use /usr/ucb/mail instead of sendmail;
685 ;; options -t, and -v if not interactive.
686 (defcustom message-mailer-swallows-blank-line
687 (if (and (string-match "sparc-sun-sunos\\(\\'\\|[^5]\\)"
688 system-configuration)
689 (file-readable-p "/etc/sendmail.cf")
690 (let ((buffer (get-buffer-create " *temp*")))
694 (insert-file-contents "/etc/sendmail.cf")
695 (goto-char (point-min))
696 (let ((case-fold-search nil))
697 (re-search-forward "^OR\\>" nil t)))
698 (kill-buffer buffer))))
699 ;; According to RFC822, "The field-name must be composed of printable
700 ;; ASCII characters (i. e., characters that have decimal values between
701 ;; 33 and 126, except colon)", i. e., any chars except ctl chars,
703 '(looking-at "[ \t]\\|[][!\"#$%&'()*+,-./0-9;<=>?@A-Z\\\\^_`a-z{|}~]+:"))
704 "*Set this non-nil if the system's mailer runs the header and body together.
705 \(This problem exists on Sunos 4 when sendmail is run in remote mode.)
706 The value should be an expression to test whether the problem will
708 :group 'message-sending
711 ;;; XXX: This symbol is overloaded! See below.
712 (defvar message-user-agent nil
713 "String of the form of PRODUCT/VERSION. Used for User-Agent header field.")
715 ;; Ignore errors in case this is used in Emacs 19.
716 ;; Don't use ignore-errors because this is copied into loaddefs.el.
719 (define-mail-user-agent 'message-user-agent
720 'message-mail 'message-send-and-exit
721 'message-kill-buffer 'message-send-hook)
724 (defvar message-mh-deletable-headers '(Message-ID Date Lines Sender)
725 "If non-nil, delete the deletable headers before feeding to mh.")
727 (defvar message-send-method-alist
728 '((news message-news-p message-send-via-news)
729 (mail message-mail-p message-send-via-mail))
730 "Alist of ways to send outgoing messages.
731 Each element has the form
733 \(TYPE PREDICATE FUNCTION)
735 where TYPE is a symbol that names the method; PREDICATE is a function
736 called without any parameters to determine whether the message is
737 a message of type TYPE; and FUNCTION is a function to be called if
738 PREDICATE returns non-nil. FUNCTION is called with one parameter --
741 (defvar message-mail-alias-type 'abbrev
742 "*What alias expansion type to use in Message buffers.
743 The default is `abbrev', which uses mailabbrev. nil switches
746 (defcustom message-autosave-directory
747 (nnheader-concat message-directory "drafts/")
748 "*Directory where Message autosaves buffers if Gnus isn't running.
749 If nil, Message won't autosave."
750 :group 'message-buffers
753 ;;; Internal variables.
754 ;;; Well, not really internal.
756 (defvar message-mode-syntax-table
757 (let ((table (copy-syntax-table text-mode-syntax-table)))
758 (modify-syntax-entry ?% ". " table)
760 "Syntax table used while in Message mode.")
762 (defvar message-mode-abbrev-table text-mode-abbrev-table
763 "Abbrev table used in Message mode buffers.
764 Defaults to `text-mode-abbrev-table'.")
765 (defgroup message-headers nil
767 :link '(custom-manual "(message)Variables")
770 (defface message-header-to-face
773 (:foreground "green2" :bold t))
776 (:foreground "MidnightBlue" :bold t))
778 (:bold t :italic t)))
779 "Face used for displaying From headers."
780 :group 'message-faces)
782 (defface message-header-cc-face
785 (:foreground "green4" :bold t))
788 (:foreground "MidnightBlue"))
791 "Face used for displaying Cc headers."
792 :group 'message-faces)
794 (defface message-header-subject-face
797 (:foreground "green3"))
800 (:foreground "navy blue" :bold t))
803 "Face used for displaying subject headers."
804 :group 'message-faces)
806 (defface message-header-newsgroups-face
809 (:foreground "yellow" :bold t :italic t))
812 (:foreground "blue4" :bold t :italic t))
814 (:bold t :italic t)))
815 "Face used for displaying newsgroups headers."
816 :group 'message-faces)
818 (defface message-header-other-face
821 (:foreground "#b00000"))
824 (:foreground "steel blue"))
826 (:bold t :italic t)))
827 "Face used for displaying newsgroups headers."
828 :group 'message-faces)
830 (defface message-header-name-face
833 (:foreground "DarkGreen"))
836 (:foreground "cornflower blue"))
839 "Face used for displaying header names."
840 :group 'message-faces)
842 (defface message-header-xheader-face
845 (:foreground "blue"))
848 (:foreground "blue"))
851 "Face used for displaying X-Header headers."
852 :group 'message-faces)
854 (defface message-separator-face
857 (:foreground "blue3"))
860 (:foreground "brown"))
863 "Face used for displaying the separator."
864 :group 'message-faces)
866 (defface message-cited-text-face
875 "Face used for displaying cited text names."
876 :group 'message-faces)
878 (defvar message-font-lock-keywords
879 (let* ((cite-prefix "A-Za-z")
880 (cite-suffix (concat cite-prefix "0-9_.@-"))
881 (content "[ \t]*\\(.+\\(\n[ \t].*\\)*\\)"))
882 `((,(concat "^\\([Tt]o:\\)" content)
883 (1 'message-header-name-face)
884 (2 'message-header-to-face nil t))
885 (,(concat "^\\([GBF]?[Cc][Cc]:\\|[Rr]eply-[Tt]o:\\|"
886 "[Mm]ail-[Cc]opies-[Tt]o:\\|"
887 "[Mm]ail-[Rr]eply-[Tt]o:\\|"
888 "[Mm]ail-[Ff]ollowup-[Tt]o:\\)" content)
889 (1 'message-header-name-face)
890 (2 'message-header-cc-face nil t))
891 (,(concat "^\\([Ss]ubject:\\)" content)
892 (1 'message-header-name-face)
893 (2 'message-header-subject-face nil t))
894 (,(concat "^\\([Nn]ewsgroups:\\|Followup-[Tt]o:\\)" content)
895 (1 'message-header-name-face)
896 (2 'message-header-newsgroups-face nil t))
897 (,(concat "^\\([A-Z][^: \n\t]+:\\)" content)
898 (1 'message-header-name-face)
899 (2 'message-header-other-face nil t))
900 (,(concat "^\\(X-[A-Za-z0-9-]+\\|In-Reply-To\\):" content)
901 (1 'message-header-name-face)
902 (2 'message-header-name-face))
903 ,@(if (and mail-header-separator
904 (not (equal mail-header-separator "")))
905 `((,(concat "^\\(" (regexp-quote mail-header-separator) "\\)$")
906 1 'message-separator-face))
909 "\\([" cite-prefix "]+[" cite-suffix "]*\\)?"
911 (0 'message-cited-text-face))))
912 "Additional expressions to highlight in Message mode.")
914 ;; XEmacs does it like this. For Emacs, we have to set the
915 ;; `font-lock-defaults' buffer-local variable.
916 (put 'message-mode 'font-lock-defaults '(message-font-lock-keywords t))
918 (defvar message-face-alist
919 '((bold . bold-region)
920 (underline . underline-region)
921 (default . (lambda (b e)
923 (ununderline-region b e))))
924 "Alist of mail and news faces for facemenu.
925 The cdr of ech entry is a function for applying the face to a region.")
927 (defcustom message-send-hook nil
928 "Hook run before sending messages."
929 :group 'message-various
930 :options '(ispell-message)
933 (defcustom message-send-mail-hook nil
934 "Hook run before sending mail messages."
935 :group 'message-various
938 (defcustom message-send-news-hook nil
939 "Hook run before sending news messages."
940 :group 'message-various
943 (defcustom message-sent-hook nil
944 "Hook run after sending messages."
945 :group 'message-various
948 (defcustom message-use-multi-frames nil
949 "Make new frame when sending messages."
950 :group 'message-frames
953 (defcustom message-delete-frame-on-exit nil
954 "Delete frame after sending messages."
955 :group 'message-frames
956 :type '(choice (const :tag "off" nil)
957 (const :tag "always" t)
958 (const :tag "ask" ask)))
960 (defvar message-send-coding-system 'binary
961 "Coding system to encode outgoing mail.")
963 ;;; Internal variables.
965 (defvar message-buffer-list nil)
966 (defvar message-this-is-news nil)
967 (defvar message-this-is-mail nil)
968 (defvar message-draft-article nil)
970 ;; Byte-compiler warning
971 (defvar gnus-active-hashtb)
972 (defvar gnus-read-active-file)
974 ;;; Regexp matching the delimiter of messages in UNIX mail format
975 ;;; (UNIX From lines), minus the initial ^. It should be a copy
976 ;;; of rmail.el's rmail-unix-mail-delimiter.
977 (defvar message-unix-mail-delimiter
978 (let ((time-zone-regexp
979 (concat "\\([A-Z]?[A-Z]?[A-Z][A-Z]\\( DST\\)?"
980 "\\|[-+]?[0-9][0-9][0-9][0-9]"
986 ;; Many things can happen to an RFC 822 mailbox before it is put into
987 ;; a `From' line. The leading phrase can be stripped, e.g.
988 ;; `Joe <@w.x:joe@y.z>' -> `<@w.x:joe@y.z>'. The <> can be stripped, e.g.
989 ;; `<@x.y:joe@y.z>' -> `@x.y:joe@y.z'. Everything starting with a CRLF
990 ;; can be removed, e.g.
991 ;; From: joe@y.z (Joe K
993 ;; can yield `From joe@y.z (Joe K Fri Mar 22 08:11:15 1996', and
996 ;; can yield `From Joe User Fri Mar 22 08:11:15 1996'.
997 ;; The mailbox can be removed or be replaced by white space, e.g.
998 ;; From: "Joe User"{space}{tab}
1000 ;; can yield `From {space}{tab} Fri Mar 22 08:11:15 1996',
1001 ;; where {space} and {tab} represent the Ascii space and tab characters.
1002 ;; We want to match the results of any of these manglings.
1003 ;; The following regexp rejects names whose first characters are
1004 ;; obviously bogus, but after that anything goes.
1005 "\\([^\0-\b\n-\r\^?].*\\)? "
1007 ;; The time the message was sent.
1008 "\\([^\0-\r \^?]+\\) +" ; day of the week
1009 "\\([^\0-\r \^?]+\\) +" ; month
1010 "\\([0-3]?[0-9]\\) +" ; day of month
1011 "\\([0-2][0-9]:[0-5][0-9]\\(:[0-6][0-9]\\)?\\) *" ; time of day
1013 ;; Perhaps a time zone, specified by an abbreviation, or by a
1018 " \\([0-9][0-9]+\\) *"
1020 ;; On some systems the time zone can appear after the year, too.
1024 "\\(remote from .*\\)?"
1027 "Regexp matching the delimiter of messages in UNIX mail format.")
1029 (defvar message-unsent-separator
1030 (concat "^ *---+ +Unsent message follows +---+ *$\\|"
1031 "^ *---+ +Returned message +---+ *$\\|"
1032 "^Start of returned message$\\|"
1033 "^ *---+ +Original message +---+ *$\\|"
1034 "^ *--+ +begin message +--+ *$\\|"
1035 "^ *---+ +Original message follows +---+ *$\\|"
1036 "^|? *---+ +Message text follows: +---+ *|?$")
1037 "A regexp that matches the separator before the text of a failed message.")
1039 (defvar message-header-format-alist
1041 (To . message-fill-address)
1042 (Cc . message-fill-address)
1053 ;; (References . message-shorten-references)
1054 (References . message-fill-header)
1056 "Alist used for formatting headers.")
1059 (autoload 'message-setup-toolbar "messagexmas")
1060 (autoload 'mh-new-draft-name "mh-comp")
1061 (autoload 'mh-send-letter "mh-comp")
1062 (autoload 'gnus-point-at-eol "gnus-util")
1063 (autoload 'gnus-point-at-bol "gnus-util")
1064 (autoload 'gnus-output-to-mail "gnus-util")
1065 (autoload 'gnus-output-to-rmail "gnus-util")
1066 (autoload 'mail-abbrev-in-expansion-header-p "mailabbrev")
1067 (autoload 'nndraft-request-associate-buffer "nndraft")
1068 (autoload 'nndraft-request-expire-articles "nndraft")
1069 (autoload 'gnus-open-server "gnus-int")
1070 (autoload 'gnus-request-post "gnus-int")
1071 (autoload 'gnus-copy-article-buffer "gnus-msg")
1072 (autoload 'gnus-alive-p "gnus-util")
1073 (autoload 'rmail-output "rmail"))
1078 ;;; Utility functions.
1081 (defmacro message-y-or-n-p (question show &rest text)
1082 "Ask QUESTION, displaying the rest of the arguments in a temp. buffer if SHOW"
1083 `(message-talkative-question 'y-or-n-p ,question ,show ,@text))
1085 ;; Delete the current line (and the next N lines.);
1086 (defmacro message-delete-line (&optional n)
1087 `(delete-region (progn (beginning-of-line) (point))
1088 (progn (forward-line ,(or n 1)) (point))))
1090 (defun message-tokenize-header (header &optional separator)
1091 "Split HEADER into a list of header elements.
1092 \",\" is used as the separator."
1095 (let ((regexp (format "[%s]+" (or separator ",")))
1100 (message-set-work-buffer)
1102 (goto-char (point-min))
1107 (cond ((and (> (point) beg)
1109 (and (looking-at regexp)
1112 (push (buffer-substring beg (point)) elems)
1113 (setq beg (match-end 0)))
1114 ((= (following-char) ?\")
1115 (setq quoted (not quoted)))
1116 ((and (= (following-char) ?\()
1119 ((and (= (following-char) ?\))
1122 (nreverse elems)))))
1124 (defun message-mail-file-mbox-p (file)
1125 "Say whether FILE looks like a Unix mbox file."
1126 (when (and (file-exists-p file)
1127 (file-readable-p file)
1128 (file-regular-p file))
1129 (nnheader-temp-write nil
1130 (nnheader-insert-file-contents file)
1131 (goto-char (point-min))
1132 (looking-at message-unix-mail-delimiter))))
1134 (defun message-fetch-field (header &optional not-all)
1135 "The same as `mail-fetch-field', only remove all newlines."
1136 (let* ((inhibit-point-motion-hooks t)
1137 (value (mail-fetch-field header nil (not not-all))))
1139 (nnheader-replace-chars-in-string value ?\n ? ))))
1141 (defun message-add-header (&rest headers)
1142 "Add the HEADERS to the message header, skipping those already present."
1145 (unless (string-match "^\\([^:]+\\):[ \t]*[^ \t]" (car headers))
1146 (error "Invalid header `%s'" (car headers)))
1147 (setq hclean (match-string 1 (car headers)))
1149 (message-narrow-to-headers)
1150 (unless (re-search-forward (concat "^" (regexp-quote hclean) ":") nil t)
1151 (insert (car headers) ?\n))))
1152 (setq headers (cdr headers))))
1154 (defun message-fetch-reply-field (header)
1155 "Fetch FIELD from the message we're replying to."
1156 (when (and message-reply-buffer
1157 (buffer-name message-reply-buffer))
1159 (set-buffer message-reply-buffer)
1160 (message-fetch-field header))))
1162 (defun message-set-work-buffer ()
1163 (if (get-buffer " *message work*")
1165 (set-buffer " *message work*")
1167 (set-buffer (get-buffer-create " *message work*"))
1168 (kill-all-local-variables)
1169 (buffer-disable-undo (current-buffer))))
1171 (defun message-functionp (form)
1172 "Return non-nil if FORM is funcallable."
1173 (or (and (symbolp form) (fboundp form))
1174 (and (listp form) (eq (car form) 'lambda))
1175 (byte-code-function-p form)))
1177 (defun message-strip-subject-re (subject)
1178 "Remove \"Re:\" from subject lines."
1179 (if (string-match message-subject-re-regexp subject)
1180 (substring subject (match-end 0))
1183 (defun message-remove-header (header &optional is-regexp first reverse)
1184 "Remove HEADER in the narrowed buffer.
1185 If REGEXP, HEADER is a regular expression.
1186 If FIRST, only remove the first instance of the header.
1187 Return the number of headers removed."
1188 (goto-char (point-min))
1189 (let ((regexp (if is-regexp header (concat "^" (regexp-quote header) ":")))
1191 (case-fold-search t)
1193 (while (and (not (eobp))
1196 (not (looking-at regexp))
1197 (looking-at regexp))
1204 ;; There might be a continuation header, so we have to search
1205 ;; until we find a new non-continuation line.
1208 (if (re-search-forward "^[^ \t]" nil t)
1209 (goto-char (match-beginning 0))
1212 (if (re-search-forward "^[^ \t]" nil t)
1213 (goto-char (match-beginning 0))
1217 (defun message-narrow-to-headers ()
1218 "Narrow the buffer to the head of the message."
1221 (goto-char (point-min))
1222 (if (re-search-forward
1223 (concat "^" (regexp-quote mail-header-separator) "\n") nil t)
1226 (goto-char (point-min)))
1228 (defun message-narrow-to-head ()
1229 "Narrow the buffer to the head of the message."
1232 (goto-char (point-min))
1233 (if (search-forward "\n\n" nil 1)
1236 (goto-char (point-min)))
1238 (defun message-news-p ()
1239 "Say whether the current buffer contains a news message."
1240 (and (not message-this-is-mail)
1241 (or message-this-is-news
1244 (message-narrow-to-headers)
1245 (and (message-fetch-field "newsgroups")
1246 (not (message-fetch-field "posted-to"))))))))
1248 (defun message-mail-p ()
1249 "Say whether the current buffer contains a mail message."
1250 (and (not message-this-is-news)
1251 (or message-this-is-mail
1254 (message-narrow-to-headers)
1255 (or (message-fetch-field "to")
1256 (message-fetch-field "cc")
1257 (message-fetch-field "bcc")))))))
1259 (defun message-next-header ()
1260 "Go to the beginning of the next header."
1262 (or (eobp) (forward-char 1))
1263 (not (if (re-search-forward "^[^ \t]" nil t)
1265 (goto-char (point-max)))))
1267 (defun message-sort-headers-1 ()
1268 "Sort the buffer as headers using `message-rank' text props."
1269 (goto-char (point-min))
1271 nil 'message-next-header
1273 (message-next-header)
1277 (or (get-text-property (point) 'message-rank)
1280 (defun message-sort-headers ()
1281 "Sort the headers of the current message according to `message-header-format-alist'."
1285 (let ((max (1+ (length message-header-format-alist)))
1287 (message-narrow-to-headers)
1288 (while (re-search-forward "^[^ \n]+:" nil t)
1290 (match-beginning 0) (1+ (match-beginning 0))
1292 (if (setq rank (length (memq (assq (intern (buffer-substring
1294 (1- (match-end 0))))
1295 message-header-format-alist)
1296 message-header-format-alist)))
1299 (message-sort-headers-1))))
1309 (defvar message-mode-map nil)
1311 (unless message-mode-map
1312 (setq message-mode-map (copy-keymap text-mode-map))
1313 (define-key message-mode-map "\C-c?" 'describe-mode)
1315 (define-key message-mode-map "\C-c\C-f\C-t" 'message-goto-to)
1316 (define-key message-mode-map "\C-c\C-f\C-b" 'message-goto-bcc)
1317 (define-key message-mode-map "\C-c\C-f\C-w" 'message-goto-fcc)
1318 (define-key message-mode-map "\C-c\C-f\C-c" 'message-goto-cc)
1319 (define-key message-mode-map "\C-c\C-f\C-s" 'message-goto-subject)
1320 ;; (define-key message-mode-map "\C-c\C-f\C-r" 'message-goto-reply-to)
1321 (define-key message-mode-map "\C-c\C-f\C-r" 'message-goto-mail-reply-to)
1322 (define-key message-mode-map "\C-c\C-f\C-m" 'message-goto-mail-followup-to)
1323 (define-key message-mode-map "\C-c\C-f\C-n" 'message-goto-newsgroups)
1324 (define-key message-mode-map "\C-c\C-f\C-d" 'message-goto-distribution)
1325 (define-key message-mode-map "\C-c\C-f\C-f" 'message-goto-followup-to)
1326 (define-key message-mode-map "\C-c\C-f\C-k" 'message-goto-keywords)
1327 (define-key message-mode-map "\C-c\C-f\C-u" 'message-goto-summary)
1328 (define-key message-mode-map "\C-c\C-b" 'message-goto-body)
1329 (define-key message-mode-map "\C-c\C-i" 'message-goto-signature)
1331 (define-key message-mode-map "\C-c\C-t" 'message-insert-to)
1332 (define-key message-mode-map "\C-c\C-n" 'message-insert-newsgroups)
1334 (define-key message-mode-map "\C-c\C-y" 'message-yank-original)
1335 (define-key message-mode-map "\C-c\C-q" 'message-fill-yanked-message)
1336 (define-key message-mode-map "\C-c\C-w" 'message-insert-signature)
1337 (define-key message-mode-map "\C-c\C-r" 'message-caesar-buffer-body)
1338 (define-key message-mode-map "\C-c\C-o" 'message-sort-headers)
1339 (define-key message-mode-map "\C-c\M-r" 'message-rename-buffer)
1341 (define-key message-mode-map "\C-c\C-c" 'message-send-and-exit)
1342 (define-key message-mode-map "\C-c\C-s" 'message-send)
1343 (define-key message-mode-map "\C-c\C-k" 'message-kill-buffer)
1344 (define-key message-mode-map "\C-c\C-d" 'message-dont-send)
1346 (define-key message-mode-map "\C-c\C-e" 'message-elide-region)
1347 (define-key message-mode-map "\C-c\C-v" 'message-delete-not-region)
1348 (define-key message-mode-map "\C-c\C-z" 'message-kill-to-signature)
1349 (define-key message-mode-map "\M-\r" 'message-newline-and-reformat)
1351 (define-key message-mode-map "\t" 'message-tab))
1354 message-mode-menu message-mode-map "Message Menu."
1356 ["Sort Headers" message-sort-headers t]
1357 ["Yank Original" message-yank-original t]
1358 ["Fill Yanked Message" message-fill-yanked-message t]
1359 ["Insert Signature" message-insert-signature t]
1360 ["Caesar (rot13) Message" message-caesar-buffer-body t]
1361 ["Caesar (rot13) Region" message-caesar-region (mark t)]
1362 ["Elide Region" message-elide-region (mark t)]
1363 ["Delete Outside Region" message-delete-not-region (mark t)]
1364 ["Kill To Signature" message-kill-to-signature t]
1365 ["Newline and Reformat" message-newline-and-reformat t]
1366 ["Rename buffer" message-rename-buffer t]
1367 ["Spellcheck" ispell-message t]
1369 ["Send Message" message-send-and-exit t]
1370 ["Abort Message" message-dont-send t]
1371 ["Kill Message" message-kill-buffer t]))
1374 message-mode-field-menu message-mode-map ""
1376 ["Fetch To" message-insert-to t]
1377 ["Fetch Newsgroups" message-insert-newsgroups t]
1379 ["To" message-goto-to t]
1380 ["Subject" message-goto-subject t]
1381 ["Cc" message-goto-cc t]
1382 ["Reply-To" message-goto-reply-to t]
1383 ["Mail-Reply-To" message-goto-mail-reply-to t]
1384 ["Mail-Followup-To" message-goto-mail-followup-to t]
1385 ["Mail-Copies-To" message-goto-mail-copies-to t]
1386 ["Summary" message-goto-summary t]
1387 ["Keywords" message-goto-keywords t]
1388 ["Newsgroups" message-goto-newsgroups t]
1389 ["Followup-To" message-goto-followup-to t]
1390 ["Distribution" message-goto-distribution t]
1391 ["Body" message-goto-body t]
1392 ["Signature" message-goto-signature t]))
1394 (defvar facemenu-add-face-function)
1395 (defvar facemenu-remove-face-function)
1398 (defun message-mode ()
1399 "Major mode for editing mail and news to be sent.
1400 Like Text Mode but with these additional commands:
1401 C-c C-s message-send (send the message) C-c C-c message-send-and-exit
1402 C-c C-f move to a header field (and create it if there isn't):
1403 C-c C-f C-t move to To C-c C-f C-s move to Subject
1404 C-c C-f C-c move to Cc C-c C-f C-b move to Bcc
1405 C-c C-f C-w move to Fcc C-c C-f C-r move to Reply-To
1406 C-c C-f C-u move to Summary C-c C-f C-n move to Newsgroups
1407 C-c C-f C-k move to Keywords C-c C-f C-d move to Distribution
1408 C-c C-f C-m move to Mail-Followup-To
1409 C-c C-f C-f move to Followup-To
1410 C-c C-t message-insert-to (add a To header to a news followup)
1411 C-c C-n message-insert-newsgroups (add a Newsgroup header to a news reply)
1412 C-c C-b message-goto-body (move to beginning of message text).
1413 C-c C-i message-goto-signature (move to the beginning of the signature).
1414 C-c C-w message-insert-signature (insert `message-signature-file' file).
1415 C-c C-y message-yank-original (insert current message, if any).
1416 C-c C-q message-fill-yanked-message (fill what was yanked).
1417 C-c C-e message-elide-region (elide the text between point and mark).
1418 C-c C-z message-kill-to-signature (kill the text up to the signature).
1419 C-c C-r message-caesar-buffer-body (rot13 the message body)."
1421 (kill-all-local-variables)
1422 (make-local-variable 'message-reply-buffer)
1423 (setq message-reply-buffer nil)
1424 (make-local-variable 'message-send-actions)
1425 (make-local-variable 'message-exit-actions)
1426 (make-local-variable 'message-kill-actions)
1427 (make-local-variable 'message-postpone-actions)
1428 (make-local-variable 'message-draft-article)
1429 (make-local-hook 'kill-buffer-hook)
1430 (set-syntax-table message-mode-syntax-table)
1431 (use-local-map message-mode-map)
1432 (setq local-abbrev-table message-mode-abbrev-table)
1433 (setq major-mode 'message-mode)
1434 (setq mode-name "Message")
1435 (setq buffer-offer-save t)
1436 (make-local-variable 'facemenu-add-face-function)
1437 (make-local-variable 'facemenu-remove-face-function)
1438 (setq facemenu-add-face-function
1440 (let ((face-fun (cdr (assq face message-face-alist))))
1442 (funcall face-fun (point) end)
1443 (error "Face %s not configured for %s mode" face mode-name)))
1445 facemenu-remove-face-function t)
1446 (make-local-variable 'paragraph-separate)
1447 (make-local-variable 'paragraph-start)
1448 ;; `-- ' precedes the signature. `-----' appears at the start of the
1449 ;; lines that delimit forwarded messages.
1450 ;; Lines containing just >= 3 dashes, perhaps after whitespace,
1451 ;; are also sometimes used and should be separators.
1452 (setq paragraph-start
1453 (concat (regexp-quote mail-header-separator)
1454 "$\\|[ \t]*[a-z0-9A-Z]*>+[ \t]*$\\|[ \t]*$\\|"
1457 ;;!!! Uhm... shurely this can't be right?
1458 "[> " (regexp-quote message-yank-prefix) "]+$"))
1459 (setq paragraph-separate paragraph-start)
1460 (make-local-variable 'message-reply-headers)
1461 (setq message-reply-headers nil)
1462 (make-local-variable 'message-user-agent)
1463 (make-local-variable 'message-post-method)
1464 (make-local-variable 'message-sent-message-via)
1465 (setq message-sent-message-via nil)
1466 (make-local-variable 'message-checksum)
1467 (setq message-checksum nil)
1468 ;;(when (fboundp 'mail-hist-define-keys)
1469 ;; (mail-hist-define-keys))
1470 (when (string-match "XEmacs\\|Lucid" emacs-version)
1471 (message-setup-toolbar))
1472 (easy-menu-add message-mode-menu message-mode-map)
1473 (easy-menu-add message-mode-field-menu message-mode-map)
1474 ;; Allow mail alias things.
1475 (when (eq message-mail-alias-type 'abbrev)
1476 (if (fboundp 'mail-abbrevs-setup)
1477 (mail-abbrevs-setup)
1478 (mail-aliases-setup)))
1479 (message-set-auto-save-file-name)
1480 (unless (string-match "XEmacs" emacs-version)
1481 (set (make-local-variable 'font-lock-defaults)
1482 '(message-font-lock-keywords t)))
1483 (make-local-variable 'adaptive-fill-regexp)
1484 (setq adaptive-fill-regexp
1485 (concat "[ \t]*[-a-z0-9A-Z]*>+[ \t]*\\|" adaptive-fill-regexp))
1486 (unless (boundp 'adaptive-fill-first-line-regexp)
1487 (setq adaptive-fill-first-line-regexp nil))
1488 (make-local-variable 'adaptive-fill-first-line-regexp)
1489 (setq adaptive-fill-first-line-regexp
1490 (concat "[ \t]*[-a-z0-9A-Z]*>+[ \t]*\\|"
1491 adaptive-fill-first-line-regexp))
1492 (run-hooks 'text-mode-hook 'message-mode-hook))
1497 ;;; Message mode commands
1500 ;;; Movement commands
1502 (defun message-goto-to ()
1503 "Move point to the To header."
1505 (message-position-on-field "To"))
1507 (defun message-goto-subject ()
1508 "Move point to the Subject header."
1510 (message-position-on-field "Subject"))
1512 (defun message-goto-cc ()
1513 "Move point to the Cc header."
1515 (message-position-on-field "Cc" "To"))
1517 (defun message-goto-bcc ()
1518 "Move point to the Bcc header."
1520 (message-position-on-field "Bcc" "Cc" "To"))
1522 (defun message-goto-fcc ()
1523 "Move point to the Fcc header."
1525 (message-position-on-field "Fcc" "To" "Newsgroups"))
1527 (defun message-goto-reply-to ()
1528 "Move point to the Reply-To header."
1530 (message-position-on-field "Reply-To" "Subject"))
1532 (defun message-goto-mail-reply-to ()
1533 "Move point to the Mail-Reply-To header."
1535 (message-position-on-field "Mail-Reply-To" "Subject"))
1537 (defun message-goto-mail-followup-to ()
1538 "Move point to the Mail-Followup-To header."
1540 (message-position-on-field "Mail-Followup-To" "Subject"))
1542 (defun message-goto-mail-copies-to ()
1543 "Move point to the Mail-Copies-To header."
1545 (message-position-on-field "Mail-Copies-To" "Subject"))
1547 (defun message-goto-newsgroups ()
1548 "Move point to the Newsgroups header."
1550 (message-position-on-field "Newsgroups"))
1552 (defun message-goto-distribution ()
1553 "Move point to the Distribution header."
1555 (message-position-on-field "Distribution"))
1557 (defun message-goto-followup-to ()
1558 "Move point to the Followup-To header."
1560 (message-position-on-field "Followup-To" "Newsgroups"))
1562 (defun message-goto-keywords ()
1563 "Move point to the Keywords header."
1565 (message-position-on-field "Keywords" "Subject"))
1567 (defun message-goto-summary ()
1568 "Move point to the Summary header."
1570 (message-position-on-field "Summary" "Subject"))
1572 (defun message-goto-body ()
1573 "Move point to the beginning of the message body."
1575 (if (looking-at "[ \t]*\n") (expand-abbrev))
1576 (goto-char (point-min))
1577 (search-forward (concat "\n" mail-header-separator "\n") nil t))
1579 (defun message-goto-eoh ()
1580 "Move point to the end of the headers."
1585 (defun message-goto-signature ()
1586 "Move point to the beginning of the message signature.
1587 If there is no signature in the article, go to the end and
1590 (goto-char (point-min))
1591 (if (re-search-forward message-signature-separator nil t)
1593 (goto-char (point-max))
1598 (defun message-insert-to (&optional force)
1599 "Insert a To header that points to the author of the article being replied to.
1600 If the original author requested not to be sent mail, the function signals
1602 With the prefix argument FORCE, insert the header anyway."
1604 (let ((co (message-fetch-reply-field "mail-copies-to")))
1605 (when (and (null force)
1607 (equal (downcase co) "never"))
1608 (error "The user has requested not to have copies sent via mail")))
1609 (when (and (message-position-on-field "To")
1610 (mail-fetch-field "to")
1611 (not (string-match "\\` *\\'" (mail-fetch-field "to"))))
1613 (insert (or (message-fetch-reply-field "reply-to")
1614 (message-fetch-reply-field "from") "")))
1616 (defun message-insert-newsgroups ()
1617 "Insert the Newsgroups header from the article being replied to."
1619 (when (and (message-position-on-field "Newsgroups")
1620 (mail-fetch-field "newsgroups")
1621 (not (string-match "\\` *\\'" (mail-fetch-field "newsgroups"))))
1623 (insert (or (message-fetch-reply-field "newsgroups") "")))
1627 ;;; Various commands
1629 (defun message-delete-not-region (beg end)
1630 "Delete everything in the body of the current message that is outside of the region."
1634 (delete-region (point) (if (not (message-goto-signature))
1640 (delete-region beg (progn (message-goto-body)
1643 (when (message-goto-signature)
1646 (defun message-kill-to-signature ()
1647 "Deletes all text up to the signature."
1649 (let ((point (point)))
1650 (message-goto-signature)
1653 (kill-region point (point))
1657 (defun message-newline-and-reformat ()
1658 "Insert four newlines, and then reformat if inside quoted text."
1660 (let ((point (point))
1664 (setq quoted (looking-at (regexp-quote message-yank-prefix))))
1667 (insert message-yank-prefix))
1668 (fill-paragraph nil)
1672 (defun message-insert-signature (&optional force)
1673 "Insert a signature. See documentation for the `message-signature' variable."
1674 (interactive (list 0))
1677 ((and (null message-signature)
1680 (goto-char (point-max))
1681 (not (re-search-backward
1682 message-signature-separator nil t))))
1683 ((and (null message-signature)
1686 ((message-functionp message-signature)
1687 (funcall message-signature))
1688 ((listp message-signature)
1689 (eval message-signature))
1690 (t message-signature)))
1692 (cond ((stringp signature)
1694 ((and (eq t signature)
1695 message-signature-file
1696 (file-exists-p message-signature-file))
1699 (goto-char (point-max))
1700 ;; Insert the signature.
1704 (if (eq signature t)
1705 (insert-file-contents message-signature-file)
1707 (goto-char (point-max))
1708 (or (bolp) (insert "\n")))))
1710 (defun message-elide-region (b e)
1711 "Elide the text between point and mark.
1712 An ellipsis (from `message-elide-elipsis') will be inserted where the
1718 (insert message-elide-elipsis))
1720 (defvar message-caesar-translation-table nil)
1722 (defun message-caesar-region (b e &optional n)
1723 "Caesar rotation of region by N, default 13, for decrypting netnews."
1726 (min (point) (or (mark t) (point)))
1727 (max (point) (or (mark t) (point)))
1728 (when current-prefix-arg
1729 (prefix-numeric-value current-prefix-arg))))
1731 (setq n (if (numberp n) (mod n 26) 13)) ;canonize N
1732 (unless (or (zerop n) ; no action needed for a rot of 0
1733 (= b e)) ; no region to rotate
1734 ;; We build the table, if necessary.
1735 (when (or (not message-caesar-translation-table)
1736 (/= (aref message-caesar-translation-table ?a) (+ ?a n)))
1737 (setq message-caesar-translation-table
1738 (message-make-caesar-translation-table n)))
1739 ;; Then we translate the region. Do it this way to retain
1742 (subst-char-in-region
1743 b (1+ b) (char-after b)
1744 (aref message-caesar-translation-table (char-after b)))
1747 (defun message-make-caesar-translation-table (n)
1748 "Create a rot table with offset N."
1750 (table (make-string 256 0)))
1751 (while (< (incf i) 256)
1754 (substring table 0 ?A)
1755 (substring table (+ ?A n) (+ ?A n (- 26 n)))
1756 (substring table ?A (+ ?A n))
1757 (substring table (+ ?A 26) ?a)
1758 (substring table (+ ?a n) (+ ?a n (- 26 n)))
1759 (substring table ?a (+ ?a n))
1760 (substring table (+ ?a 26) 255))))
1762 (defun message-caesar-buffer-body (&optional rotnum)
1763 "Caesar rotates all letters in the current buffer by 13 places.
1764 Used to encode/decode possiblyun offensive messages (commonly in net.jokes).
1765 With prefix arg, specifies the number of places to rotate each letter forward.
1766 Mail and USENET news headers are not rotated."
1767 (interactive (if current-prefix-arg
1768 (list (prefix-numeric-value current-prefix-arg))
1772 (when (message-goto-body)
1773 (narrow-to-region (point) (point-max)))
1774 (message-caesar-region (point-min) (point-max) rotnum))))
1776 (defun message-pipe-buffer-body (program)
1777 "Pipe the message body in the current buffer through PROGRAM."
1780 (when (message-goto-body)
1781 (narrow-to-region (point) (point-max)))
1782 (let ((body (buffer-substring (point-min) (point-max))))
1783 (unless (equal 0 (call-process-region
1784 (point-min) (point-max) program t t))
1786 (message "%s failed." program))))))
1788 (defun message-rename-buffer (&optional enter-string)
1789 "Rename the *message* buffer to \"*message* RECIPIENT\".
1790 If the function is run with a prefix, it will ask for a new buffer
1791 name, rather than giving an automatic name."
1792 (interactive "Pbuffer name: ")
1795 (goto-char (point-min))
1796 (narrow-to-region (point)
1797 (search-forward mail-header-separator nil 'end))
1799 (if (message-news-p) (message-fetch-field "Newsgroups")
1800 (message-fetch-field "To"))
1803 (if (string-match "," mail-to)
1804 (concat (substring mail-to 0 (match-beginning 0)) ", ...")
1806 (name-default (concat "*message* " mail-trimmed-to))
1807 (name (if enter-string
1808 (read-string "New buffer name: " name-default)
1810 (rename-buffer name t)))))
1812 (defun message-fill-yanked-message (&optional justifyp)
1813 "Fill the paragraphs of a message yanked into this one.
1814 Numeric argument means justify as well."
1817 (goto-char (point-min))
1818 (search-forward (concat "\n" mail-header-separator "\n") nil t)
1819 (let ((fill-prefix message-yank-prefix))
1820 (fill-individual-paragraphs (point) (point-max) justifyp t))))
1822 (defun message-indent-citation ()
1823 "Modify text just inserted from a message to be cited.
1824 The inserted text should be the region.
1825 When this function returns, the region is again around the modified text.
1827 Normally, indent each nonblank line `message-indentation-spaces' spaces.
1828 However, if `message-yank-prefix' is non-nil, insert that prefix on each line."
1829 (let ((start (point)))
1830 ;; Remove unwanted headers.
1831 (when message-ignored-cited-headers
1836 (if (search-forward "\n\n" nil t)
1839 (message-remove-header message-ignored-cited-headers t)
1840 (when (= (point-min) (point-max))
1841 (setq all-removed t))
1842 (goto-char (point-max)))
1846 ;; Delete blank lines at the start of the buffer.
1847 (while (and (point-min)
1850 (message-delete-line))
1851 ;; Delete blank lines at the end of the buffer.
1852 (goto-char (point-max))
1855 (while (and (zerop (forward-line -1))
1857 (message-delete-line))
1858 ;; Do the indentation.
1859 (if (null message-yank-prefix)
1860 (indent-rigidly start (mark t) message-indentation-spaces)
1863 (while (< (point) (mark t))
1864 (insert message-yank-prefix)
1868 (defvar gnus-article-copy)
1869 (defun message-yank-original (&optional arg)
1870 "Insert the message being replied to, if any.
1871 Puts point before the text and mark after.
1872 Normally indents each nonblank line ARG spaces (default 3). However,
1873 if `message-yank-prefix' is non-nil, insert that prefix on each line.
1875 This function uses `message-cite-function' to do the actual citing.
1877 Just \\[universal-argument] as argument means don't indent, insert no
1878 prefix, and don't delete any headers."
1880 (let ((modified (buffer-modified-p)))
1881 (when (and message-reply-buffer
1882 message-cite-function)
1883 (gnus-copy-article-buffer)
1884 (setq message-reply-buffer gnus-article-copy)
1885 (delete-windows-on message-reply-buffer t)
1886 (insert-buffer message-reply-buffer)
1887 (funcall message-cite-function)
1888 (message-exchange-point-and-mark)
1892 (setq message-checksum (message-checksum))))))
1894 (defun message-cite-original-without-signature ()
1895 "Cite function in the standard Message manner."
1896 (let ((start (point))
1899 (when message-indent-citation-function
1900 (if (listp message-indent-citation-function)
1901 message-indent-citation-function
1902 (list message-indent-citation-function)))))
1904 (when (re-search-backward "^-- $" start t)
1905 ;; Also peel off any blank lines before the signature.
1907 (while (looking-at "^[ \t]*$")
1910 (delete-region (point) end))
1913 (funcall (pop functions)))
1914 (when message-citation-line-function
1917 (funcall message-citation-line-function))))
1919 (defvar mail-citation-hook) ;Compiler directive
1920 (defun message-cite-original ()
1921 "Cite function in the standard Message manner."
1922 (if (and (boundp 'mail-citation-hook)
1924 (run-hooks 'mail-citation-hook)
1925 (let ((start (point))
1927 (when message-indent-citation-function
1928 (if (listp message-indent-citation-function)
1929 message-indent-citation-function
1930 (list message-indent-citation-function)))))
1933 (funcall (pop functions)))
1934 (when message-citation-line-function
1937 (funcall message-citation-line-function)))))
1939 (defun message-insert-citation-line ()
1940 "Function that inserts a simple citation line."
1941 (when message-reply-headers
1942 (insert (mail-header-from message-reply-headers) " writes:\n\n")))
1944 (defun message-position-on-field (header &rest afters)
1945 (let ((case-fold-search t))
1948 (goto-char (point-min))
1951 (concat "^" (regexp-quote mail-header-separator) "$"))
1952 (match-beginning 0)))
1953 (goto-char (point-min))
1954 (if (re-search-forward (concat "^" (regexp-quote header) ":") nil t)
1956 (re-search-forward "^[^ \t]" nil 'move)
1958 (skip-chars-backward "\n")
1961 (not (re-search-forward
1962 (concat "^" (regexp-quote (car afters)) ":")
1966 (re-search-forward "^[^ \t]" nil 'move)
1967 (beginning-of-line))
1968 (insert header ": \n")
1972 (defun message-remove-signature ()
1973 "Remove the signature from the text between point and mark.
1974 The text will also be indented the normal way."
1976 (let ((start (point))
1978 (if (not (re-search-forward message-signature-separator (mark t) t))
1979 ;; No signature here, so we just indent the cited text.
1980 (message-indent-citation)
1981 ;; Find the last non-empty line.
1983 (while (looking-at "[ \t]*$")
1986 (setq mark (set-marker (make-marker) (point)))
1988 (message-indent-citation)
1989 ;; Enable undoing the deletion.
1991 (delete-region mark (mark t))
1992 (set-marker mark nil)))))
1997 ;;; Sending messages
2000 ;; Avoid byte-compile warning.
2001 (defvar message-encoding-buffer nil)
2002 (defvar message-edit-buffer nil)
2003 (defvar message-mime-mode nil)
2005 (defun message-send-and-exit (&optional arg)
2006 "Send message like `message-send', then, if no errors, exit from mail buffer."
2008 (let ((buf (current-buffer))
2009 (actions message-exit-actions)
2010 (frame (selected-frame))
2011 (org-frame message-original-frame))
2012 (when (and (message-send arg)
2014 (if message-kill-buffer-on-exit
2017 (when (eq buf (current-buffer))
2018 (message-bury buf)))
2019 (message-do-actions actions)
2020 (message-delete-frame frame org-frame))))
2022 (defun message-dont-send ()
2023 "Don't send the message you have been editing."
2025 (set-buffer-modified-p t)
2027 (let ((actions message-postpone-actions))
2028 (message-bury (current-buffer))
2029 (message-do-actions actions)))
2031 (defun message-kill-buffer ()
2032 "Kill the current buffer."
2034 (when (or (not (buffer-modified-p))
2035 (yes-or-no-p "Message modified; kill anyway? "))
2036 (let ((actions message-kill-actions)
2037 (frame (selected-frame))
2038 (org-frame message-original-frame))
2039 (setq buffer-file-name nil)
2040 (kill-buffer (current-buffer))
2041 (message-do-actions actions)
2042 (message-delete-frame frame org-frame))))
2044 (defun message-delete-frame (frame org-frame)
2045 "Delete frame for editing message."
2046 (when (and (or (and (featurep 'xemacs)
2047 (not (eq 'tty (device-type))))
2049 (>= emacs-major-version 20))
2050 (or (and (eq message-delete-frame-on-exit t)
2051 (select-frame frame)
2052 (or (eq frame org-frame)
2054 (y-or-n-p "Delete this frame?")
2056 (and (eq message-delete-frame-on-exit 'ask)
2057 (select-frame frame)
2059 (y-or-n-p "Delete this frame?")
2061 (delete-frame frame)))
2063 (defun message-bury (buffer)
2064 "Bury this mail buffer."
2065 (let ((newbuf (other-buffer buffer)))
2066 (bury-buffer buffer)
2067 (if (and (fboundp 'frame-parameters)
2068 (cdr (assq 'dedicated (frame-parameters)))
2069 (not (null (delq (selected-frame) (visible-frame-list)))))
2070 (delete-frame (selected-frame))
2071 (switch-to-buffer newbuf))))
2073 (defun message-send (&optional arg)
2074 "Send the message in the current buffer.
2075 If `message-interactive' is non-nil, wait for success indication
2076 or error messages, and inform user.
2077 Otherwise any failure is reported in a message back to
2078 the user from the mailer."
2081 (when (or (buffer-modified-p)
2082 (message-check-element 'unchanged)
2083 (y-or-n-p "No changes in the buffer; really send? "))
2084 ;; Make it possible to undo the coming changes.
2086 (let ((inhibit-read-only t))
2087 (put-text-property (point-min) (point-max) 'read-only nil))
2088 (message-fix-before-sending)
2089 (run-hooks 'message-send-hook)
2090 (message "Sending...")
2091 (let ((message-encoding-buffer
2092 (message-generate-new-buffer-clone-locals " message encoding"))
2093 (message-edit-buffer (current-buffer))
2094 (message-mime-mode mime-edit-mode-flag)
2095 (alist message-send-method-alist)
2099 (set-buffer message-encoding-buffer)
2101 (insert-buffer message-edit-buffer)
2102 (funcall message-encode-function)
2104 (setq elem (pop alist)))
2105 (when (and (or (not (funcall (cadr elem)))
2106 (and (or (not (memq (car elem)
2107 message-sent-message-via))
2110 "Already sent message via %s; resend? "
2112 (setq success (funcall (caddr elem) arg)))))
2114 (when (and success sent)
2116 ;;(when (fboundp 'mail-hist-put-headers-into-history)
2117 ;; (mail-hist-put-headers-into-history))
2118 (run-hooks 'message-sent-hook)
2119 (message "Sending...done")
2120 ;; Mark the buffer as unmodified and delete autosave.
2121 (set-buffer-modified-p nil)
2122 (delete-auto-save-file-if-necessary t)
2123 (message-disassociate-draft)
2124 ;; Delete other mail buffers and stuff.
2125 (message-do-send-housekeeping)
2126 (message-do-actions message-send-actions)
2130 (defun message-send-via-mail (arg)
2131 "Send the current message via mail."
2132 (message-send-mail arg))
2134 (defun message-send-via-news (arg)
2135 "Send the current message via news."
2136 (message-send-news arg))
2138 (defun message-fix-before-sending ()
2139 "Do various things to make the message nice before sending it."
2140 ;; Make sure there's a newline at the end of the message.
2141 (goto-char (point-max))
2144 ;; Delete all invisible text.
2145 (when (text-property-any (point-min) (point-max) 'invisible t)
2146 (put-text-property (point-min) (point-max) 'invisible nil)
2147 (unless (yes-or-no-p "Invisible text found and made visible; continue posting?")
2148 (error "Invisible text found and made visible"))))
2150 (defun message-add-action (action &rest types)
2151 "Add ACTION to be performed when doing an exit of type TYPES."
2154 (set (setq var (intern (format "message-%s-actions" (pop types))))
2155 (nconc (symbol-value var) (list action))))))
2157 (defun message-do-actions (actions)
2158 "Perform all actions in ACTIONS."
2159 ;; Now perform actions on successful sending.
2163 ;; A simple function.
2164 ((message-functionp (car actions))
2165 (funcall (car actions)))
2166 ;; Something to be evaled.
2168 (eval (car actions)))))
2171 (defun message-send-mail (&optional arg)
2172 (require 'mail-utils)
2173 (let ((tembuf (message-generate-new-buffer-clone-locals " message temp"))
2174 (case-fold-search nil)
2175 (news (message-news-p)))
2177 (message-narrow-to-headers)
2178 ;; Insert some headers.
2179 (let ((message-deletable-headers
2180 (if news nil message-deletable-headers)))
2181 (message-generate-headers message-required-mail-headers))
2182 ;; Let the user do all of the above.
2183 (run-hooks 'message-header-hook))
2188 (insert-buffer message-encoding-buffer)
2189 ;; Remove some headers.
2191 (message-narrow-to-headers)
2192 ;; Remove some headers.
2193 (message-remove-header message-ignored-mail-headers t))
2194 (goto-char (point-max))
2195 ;; require one newline at the end.
2196 (or (= (preceding-char) ?\n)
2199 (or (message-fetch-field "cc")
2200 (message-fetch-field "to")))
2201 (message-insert-courtesy-copy))
2202 (mime-edit-maybe-split-and-send
2206 (funcall message-send-mail-function)
2208 (funcall message-send-mail-function))
2209 (kill-buffer tembuf))
2210 (set-buffer message-edit-buffer)
2211 (push 'mail message-sent-message-via)))
2213 (defun message-send-mail-with-sendmail ()
2214 "Send off the prepared buffer with sendmail."
2215 (let ((errbuf (if message-interactive
2216 (generate-new-buffer " sendmail errors")
2218 resend-addresses delimline)
2219 (let ((case-fold-search t))
2221 (message-narrow-to-headers)
2222 ;; XXX: We need to handle Resent-CC/Resent-BCC, too.
2223 (setq resend-addresses (message-fetch-field "resent-to")))
2224 ;; Change header-delimiter to be what sendmail expects.
2225 (goto-char (point-min))
2227 (concat "^" (regexp-quote mail-header-separator) "\n"))
2228 (replace-match "\n")
2230 (setq delimline (point-marker))
2231 (run-hooks 'message-send-mail-hook)
2232 ;; Insert an extra newline if we need it to work around
2233 ;; Sun's bug that swallows newlines.
2234 (goto-char (1+ delimline))
2235 (when (eval message-mailer-swallows-blank-line)
2237 (when message-interactive
2241 (let ((default-directory "/")
2242 (coding-system-for-write message-send-coding-system))
2243 (apply 'call-process-region
2244 (append (list (point-min) (point-max)
2245 (if (boundp 'sendmail-program)
2247 "/usr/lib/sendmail")
2248 nil errbuf nil "-oi")
2249 ;; Always specify who from,
2250 ;; since some systems have broken sendmails.
2251 ;; But some systems are more broken with -f, so
2252 ;; we'll let users override this.
2253 (if (null message-sendmail-f-is-evil)
2254 (list "-f" (user-login-name)))
2255 ;; These mean "report errors by mail"
2256 ;; and "deliver in background".
2257 (if (null message-interactive) '("-oem" "-odb"))
2258 ;; Get the addresses from the message
2259 ;; unless this is a resend.
2260 ;; We must not do that for a resend
2261 ;; because we would find the original addresses.
2262 ;; For a resend, include the specific addresses.
2263 (if resend-addresses
2264 (list resend-addresses)
2266 (when message-interactive
2269 (goto-char (point-min))
2270 (while (re-search-forward "\n\n* *" nil t)
2271 (replace-match "; "))
2272 (if (not (zerop (buffer-size)))
2273 (error "Sending...failed to %s"
2274 (buffer-substring (point-min) (point-max)))))
2275 (when (bufferp errbuf)
2276 (kill-buffer errbuf)))))
2278 (defun message-send-mail-with-qmail ()
2279 "Pass the prepared message buffer to qmail-inject.
2280 Refer to the documentation for the variable `message-send-mail-function'
2281 to find out how to use this."
2282 ;; replace the header delimiter with a blank line.
2283 (goto-char (point-min))
2285 (concat "^" (regexp-quote mail-header-separator) "\n"))
2286 (replace-match "\n")
2288 (run-hooks 'message-send-mail-hook)
2291 (let ((coding-system-for-write message-send-coding-system))
2293 'call-process-region 1 (point-max) message-qmail-inject-program
2295 ;; qmail-inject's default behaviour is to look for addresses on the
2296 ;; command line; if there're none, it scans the headers.
2297 ;; yes, it does The Right Thing w.r.t. Resent-To and it's kin.
2299 ;; in general, ALL of qmail-inject's defaults are perfect for simply
2300 ;; reading a formatted (i. e., at least a To: or Resent-To header)
2301 ;; message from stdin.
2303 ;; qmail also has the advantage of not having been raped by
2304 ;; various vendors, so we don't have to allow for that, either --
2305 ;; compare this with message-send-mail-with-sendmail and weep
2306 ;; for sendmail's lost innocence.
2308 ;; all this is way cool coz it lets us keep the arguments entirely
2309 ;; free for -inject-arguments -- a big win for the user and for us
2310 ;; since we don't have to play that double-guessing game and the user
2311 ;; gets full control (no gestapo'ish -f's, for instance). --sj
2312 message-qmail-inject-args))
2313 ;; qmail-inject doesn't say anything on it's stdout/stderr,
2314 ;; we have to look at the retval instead
2316 (1 (error "qmail-inject reported permanent failure"))
2317 (111 (error "qmail-inject reported transient failure"))
2318 ;; should never happen
2319 (t (error "qmail-inject reported unknown failure"))))
2321 (defun message-send-mail-with-mh ()
2322 "Send the prepared message buffer with mh."
2323 (let ((mh-previous-window-config nil)
2324 (name (mh-new-draft-name)))
2325 (setq buffer-file-name name)
2326 ;; MH wants to generate these headers itself.
2327 (when message-mh-deletable-headers
2328 (let ((headers message-mh-deletable-headers))
2330 (goto-char (point-min))
2331 (and (re-search-forward
2332 (concat "^" (symbol-name (car headers)) ": *") nil t)
2333 (message-delete-line))
2335 (run-hooks 'message-send-mail-hook)
2336 ;; Pass it on to mh.
2339 (defun message-send-mail-with-smtp ()
2340 "Send off the prepared buffer with SMTP."
2341 (require 'smtp) ; XXX
2342 (let ((case-fold-search t)
2345 (message-narrow-to-headers)
2347 ;; XXX: Should be replaced by better one.
2348 (smtp-deduce-address-list (current-buffer)
2349 (point-min) (point-max)))
2350 ;; Remove BCC lines.
2351 (message-remove-header "bcc"))
2352 ;; replace the header delimiter with a blank line.
2353 (goto-char (point-min))
2355 (concat "^" (regexp-quote mail-header-separator) "\n"))
2356 (replace-match "\n")
2358 (run-hooks 'message-send-mail-hook)
2360 (let ((result (smtp-via-smtp user-mail-address
2363 (unless (eq result t)
2364 (error "Sending failed; " result)))
2365 (error "Sending failed; no recipients"))))
2367 (defun message-send-news (&optional arg)
2368 (let ((tembuf (message-generate-new-buffer-clone-locals " *message temp*"))
2369 (case-fold-search nil)
2370 (method (if (message-functionp message-post-method)
2371 (funcall message-post-method arg)
2372 message-post-method))
2373 (message-syntax-checks
2375 (cons '(existing-newsgroups . disabled)
2376 message-syntax-checks)
2377 message-syntax-checks))
2380 (message-narrow-to-headers)
2381 ;; Insert some headers.
2382 (message-generate-headers message-required-news-headers)
2383 ;; Let the user do all of the above.
2384 (run-hooks 'message-header-hook))
2385 (message-cleanup-headers)
2386 (if (not (message-check-news-syntax))
2388 ;;(message "Posting not performed")
2393 (buffer-disable-undo (current-buffer))
2395 (insert-buffer message-encoding-buffer)
2396 ;; Remove some headers.
2398 (message-narrow-to-headers)
2399 ;; Remove some headers.
2400 (message-remove-header message-ignored-news-headers t))
2401 (goto-char (point-max))
2402 ;; require one newline at the end.
2403 (or (= (preceding-char) ?\n)
2405 (mime-edit-maybe-split-and-send
2410 (std11-narrow-to-header mail-header-separator)
2411 (goto-char (point-min))
2412 (when (re-search-forward "^Message-Id:" nil t)
2413 (delete-region (match-end 0)(std11-field-end))
2414 (insert (concat " " (message-make-message-id)))
2416 (funcall message-send-news-function method)
2418 (setq result (funcall message-send-news-function method)))
2419 (kill-buffer tembuf))
2420 (set-buffer message-edit-buffer)
2422 (push 'news message-sent-message-via)
2423 (message "Couldn't send message via news: %s"
2424 (nnheader-get-report (car method)))
2427 ;; 1997-09-29 by MORIOKA Tomohiko
2428 (defun message-send-news-with-gnus (method)
2429 (let ((case-fold-search t))
2430 ;; Remove the delimiter.
2431 (goto-char (point-min))
2433 (concat "^" (regexp-quote mail-header-separator) "\n"))
2434 (replace-match "\n")
2436 (run-hooks 'message-send-news-hook)
2437 ;;(require (car method))
2438 ;;(funcall (intern (format "%s-open-server" (car method)))
2439 ;;(cadr method) (cddr method))
2441 ;; (funcall (intern (format "%s-request-post" (car method)))
2443 (gnus-open-server method)
2444 (gnus-request-post method)
2448 ;;; Header generation & syntax checking.
2451 (defmacro message-check (type &rest forms)
2452 "Eval FORMS if TYPE is to be checked."
2453 `(or (message-check-element ,type)
2457 (put 'message-check 'lisp-indent-function 1)
2458 (put 'message-check 'edebug-form-spec '(form body))
2460 (defun message-check-element (type)
2461 "Returns non-nil if this type is not to be checked."
2462 (if (eq message-syntax-checks 'dont-check-for-anything-just-trust-me)
2464 (let ((able (assq type message-syntax-checks)))
2466 (eq (cdr able) 'disabled)))))
2468 (defun message-check-news-syntax ()
2469 "Check the syntax of the message."
2474 ;; We narrow to the headers and check them first.
2477 (message-narrow-to-headers)
2478 (message-check-news-header-syntax)))
2481 (set-buffer message-edit-buffer)
2482 (message-check-news-body-syntax))))))
2484 (defun message-check-news-header-syntax ()
2486 ;; Check the Subject header.
2487 (message-check 'subject
2488 (let* ((case-fold-search t)
2489 (subject (message-fetch-field "subject")))
2492 (not (string-match "\\`[ \t]*\\'" subject)))
2495 "The subject field is empty or missing. Posting is denied.")))))
2496 ;; Check for commands in Subject.
2497 (message-check 'subject-cmsg
2498 (if (string-match "^cmsg " (message-fetch-field "subject"))
2500 "The control code \"cmsg\" is in the subject. Really post? ")
2502 ;; Check for multiple identical headers.
2503 (message-check 'multiple-headers
2505 (while (and (not found)
2506 (re-search-forward "^[^ \t:]+: " nil t))
2508 (or (re-search-forward
2513 (match-beginning 0) (- (match-end 0) 2))))
2518 (y-or-n-p (format "Multiple %s headers. Really post? " found))
2520 ;; Check for Version and Sendsys.
2521 (message-check 'sendsys
2522 (if (re-search-forward "^Sendsys:\\|^Version:" nil t)
2524 (format "The article contains a %s command. Really post? "
2525 (buffer-substring (match-beginning 0)
2526 (1- (match-end 0)))))
2528 ;; See whether we can shorten Followup-To.
2529 (message-check 'shorten-followup-to
2530 (let ((newsgroups (message-fetch-field "newsgroups"))
2531 (followup-to (message-fetch-field "followup-to"))
2533 (when (and newsgroups
2534 (string-match "," newsgroups)
2539 (setq to (completing-read
2540 "Followups to: (default all groups) "
2541 (mapcar (lambda (g) (list g))
2543 (message-tokenize-header
2545 (goto-char (point-min))
2546 (insert "Followup-To: " to "\n"))
2548 ;; Check "Shoot me".
2549 (message-check 'shoot
2550 (if (re-search-forward
2551 "Message-ID.*.i-did-not-set--mail-host-address--so-shoot-me" nil t)
2552 (y-or-n-p "You appear to have a misconfigured system. Really post? ")
2554 ;; Check for Approved.
2555 (message-check 'approved
2556 (if (re-search-forward "^Approved:" nil t)
2557 (y-or-n-p "The article contains an Approved header. Really post? ")
2559 ;; Check the Message-ID header.
2560 (message-check 'message-id
2561 (let* ((case-fold-search t)
2562 (message-id (message-fetch-field "message-id" t)))
2563 (or (not message-id)
2564 ;; Is there an @ in the ID?
2565 (and (string-match "@" message-id)
2566 ;; Is there a dot in the ID?
2567 (string-match "@[^.]*\\." message-id)
2568 ;; Does the ID end with a dot?
2569 (not (string-match "\\.>" message-id)))
2571 (format "The Message-ID looks strange: \"%s\". Really post? "
2573 ;; Check the Newsgroups & Followup-To headers.
2574 (message-check 'existing-newsgroups
2575 (let* ((case-fold-search t)
2576 (newsgroups (message-fetch-field "newsgroups"))
2577 (followup-to (message-fetch-field "followup-to"))
2578 (groups (message-tokenize-header
2580 (concat newsgroups "," followup-to)
2582 (hashtb (and (boundp 'gnus-active-hashtb)
2583 gnus-active-hashtb))
2585 (if (or (not hashtb)
2586 (not (boundp 'gnus-read-active-file))
2587 (not gnus-read-active-file)
2588 (eq gnus-read-active-file 'some))
2591 (when (and (not (boundp (intern (car groups) hashtb)))
2592 (not (equal (car groups) "poster")))
2593 (push (car groups) errors))
2599 "Really post to %s unknown group%s: %s "
2600 (if (= (length errors) 1) "this" "these")
2601 (if (= (length errors) 1) "" "s")
2602 (mapconcat 'identity errors ", ")))))))
2603 ;; Check the Newsgroups & Followup-To headers for syntax errors.
2604 (message-check 'valid-newsgroups
2605 (let ((case-fold-search t)
2606 (headers '("Newsgroups" "Followup-To"))
2608 (while (and headers (not error))
2609 (when (setq header (mail-fetch-field (car headers)))
2613 "\\`\\([-+_&.a-zA-Z0-9]+\\)?\\(,[-+_&.a-zA-Z0-9]+\\)*\\'"
2618 (not (string-match "\\.\\'\\|\\.\\." g)))
2619 (message-tokenize-header header ","))))
2626 (format "The %s header looks odd: \"%s\". Really post? "
2627 (car headers) header)))))
2628 (message-check 'repeated-newsgroups
2629 (let ((case-fold-search t)
2630 (headers '("Newsgroups" "Followup-To"))
2631 header error groups group)
2634 (when (setq header (mail-fetch-field (pop headers)))
2635 (setq groups (message-tokenize-header header ","))
2636 (while (setq group (pop groups))
2637 (when (member group groups)
2643 (format "Group %s is repeated in headers. Really post? " error)))))
2644 ;; Check the From header.
2645 (message-check 'from
2646 (let* ((case-fold-search t)
2647 (from (message-fetch-field "from"))
2648 (ad (nth 1 (std11-extract-address-components from))))
2651 (message "There is no From line. Posting is denied.")
2653 ((or (not (string-match "@[^\\.]*\\." ad)) ;larsi@ifi
2654 (string-match "\\.\\." ad) ;larsi@ifi..uio
2655 (string-match "@\\." ad) ;larsi@.ifi.uio
2656 (string-match "\\.$" ad) ;larsi@ifi.uio.
2657 (not (string-match "^[^@]+@[^@]+$" ad)) ;larsi.ifi.uio
2658 (string-match "(.*).*(.*)" from)) ;(lars) (lars)
2660 "Denied posting -- the From looks strange: \"%s\"." from)
2664 (defun message-check-news-body-syntax ()
2666 ;; Check for long lines.
2667 (message-check 'long-lines
2668 (goto-char (point-min))
2670 (concat "^" (regexp-quote mail-header-separator) "$"))
2674 (< (current-column) 80))
2675 (zerop (forward-line 1))))
2679 "You have lines longer than 79 characters. Really post? ")))
2680 ;; Check whether the article is empty.
2681 (message-check 'empty
2682 (goto-char (point-min))
2684 (concat "^" (regexp-quote mail-header-separator) "$"))
2687 (goto-char (point-max))
2688 (re-search-backward message-signature-separator nil t)
2690 (or (re-search-backward "[^ \n\t]" b t)
2691 (y-or-n-p "Empty article. Really post? "))))
2692 ;; Check for control characters.
2693 (message-check 'control-chars
2694 (if (re-search-forward "[\000-\007\013\015-\037\200-\237]" nil t)
2696 "The article contains control characters. Really post? ")
2698 ;; Check excessive size.
2699 (message-check 'size
2700 (if (> (buffer-size) 60000)
2702 (format "The article is %d octets long. Really post? "
2705 ;; Check whether any new text has been added.
2706 (message-check 'new-text
2708 (not message-checksum)
2709 (not (eq (message-checksum) message-checksum))
2711 "It looks like no new text has been added. Really post? ")))
2712 ;; Check the length of the signature.
2713 (message-check 'signature
2714 (goto-char (point-max))
2715 (if (or (not (re-search-backward message-signature-separator nil t))
2716 (search-forward message-forward-end-separator nil t))
2718 (if (> (count-lines (point) (point-max)) 5)
2721 "Your .sig is %d lines; it should be max 4. Really post? "
2722 (1- (count-lines (point) (point-max)))))
2725 (defun message-checksum ()
2726 "Return a \"checksum\" for the current buffer."
2729 (goto-char (point-min))
2731 (concat "^" (regexp-quote mail-header-separator) "$"))
2733 (when (not (looking-at "[ \t\n]"))
2734 (setq sum (logxor (ash sum 1) (if (natnump sum) 0 1)
2739 (defun message-do-fcc ()
2740 "Process Fcc headers in the current buffer."
2741 (let ((case-fold-search t)
2742 (coding-system-for-write 'raw-text)
2745 (set-buffer (get-buffer-create " *message temp*"))
2746 (buffer-disable-undo (current-buffer))
2748 (insert-buffer-substring message-encoding-buffer)
2750 (message-narrow-to-headers)
2751 (while (setq file (message-fetch-field "fcc"))
2753 (message-remove-header "fcc" nil t)))
2754 (run-hooks 'message-header-hook 'message-before-do-fcc-hook)
2755 (goto-char (point-min))
2756 (re-search-forward (concat "^" (regexp-quote mail-header-separator) "$"))
2757 (replace-match "" t t)
2758 ;; Process FCC operations.
2760 (setq file (pop list))
2761 (if (string-match "^[ \t]*|[ \t]*\\(.*\\)[ \t]*$" file)
2762 ;; Pipe the article to the program in question.
2763 (call-process-region (point-min) (point-max) shell-file-name
2764 nil nil nil shell-command-switch
2765 (match-string 1 file))
2766 ;; Save the article.
2767 (setq file (expand-file-name file))
2768 (unless (file-exists-p (file-name-directory file))
2769 (make-directory (file-name-directory file) t))
2770 (if (and message-fcc-handler-function
2771 (not (eq message-fcc-handler-function 'rmail-output)))
2772 (funcall message-fcc-handler-function file)
2773 (if (and (file-readable-p file) (mail-file-babyl-p file))
2774 (rmail-output file 1 nil t)
2775 (let ((mail-use-rfc822 t))
2776 (rmail-output file 1 t t))))))
2778 (kill-buffer (current-buffer)))))
2780 (defun message-output (filename)
2781 "Append this article to Unix/babyl mail file.."
2782 (if (and (file-readable-p filename)
2783 (mail-file-babyl-p filename))
2784 (gnus-output-to-rmail filename t)
2785 (gnus-output-to-mail filename t)))
2787 (defun message-cleanup-headers ()
2788 "Do various automatic cleanups of the headers."
2789 ;; Remove empty lines in the header.
2791 (message-narrow-to-headers)
2792 ;; Remove blank lines.
2793 (while (re-search-forward "^[ \t]*\n" nil t)
2794 (replace-match "" t t))
2796 ;; Correct Newsgroups and Followup-To headers: Change sequence of
2797 ;; spaces to comma and eliminate spaces around commas. Eliminate
2798 ;; embedded line breaks.
2799 (goto-char (point-min))
2800 (while (re-search-forward "^\\(Newsgroups\\|Followup-To\\): +" nil t)
2804 (if (re-search-forward "^[^ \t]" nil t)
2808 (goto-char (point-min))
2809 (while (re-search-forward "\n[ \t]+" nil t)
2810 (replace-match " " t t)) ;No line breaks (too confusing)
2811 (goto-char (point-min))
2812 (while (re-search-forward "[ \t\n]*,[ \t\n]*\\|[ \t]+" nil t)
2813 (replace-match "," t t))
2814 (goto-char (point-min))
2815 ;; Remove trailing commas.
2816 (when (re-search-forward ",+$" nil t)
2817 (replace-match "" t t))))))
2819 (defun message-make-date ()
2820 "Make a valid data header."
2821 (let ((now (current-time)))
2822 (timezone-make-date-arpa-standard
2823 (current-time-string now) (current-time-zone now))))
2825 (defun message-make-followup-subject (subject)
2826 "Make a followup Subject."
2828 ((and (eq message-use-subject-re 'guess)
2829 (string-match message-subject-encoded-re-regexp subject))
2831 (message-use-subject-re
2832 (concat "Re: " (message-strip-subject-re subject)))
2835 (defun message-make-message-id ()
2836 "Make a unique Message-ID."
2837 (concat "<" (message-unique-id)
2838 (let ((psubject (save-excursion (message-fetch-field "subject")))
2840 (save-excursion (message-fetch-field "supersedes"))))
2842 (and message-reply-headers
2843 (mail-header-references message-reply-headers)
2844 (mail-header-subject message-reply-headers)
2846 (mail-header-subject message-reply-headers)
2848 (message-strip-subject-re
2849 (mail-header-subject message-reply-headers))
2850 (message-strip-subject-re psubject))))
2852 (string-match "_-_@" psupersedes)))
2854 "@" (message-make-fqdn) ">"))
2856 (defvar message-unique-id-char nil)
2858 ;; If you ever change this function, make sure the new version
2859 ;; cannot generate IDs that the old version could.
2860 ;; You might for example insert a "." somewhere (not next to another dot
2861 ;; or string boundary), or modify the "fsf" string.
2862 (defun message-unique-id ()
2863 ;; Don't use microseconds from (current-time), they may be unsupported.
2864 ;; Instead we use this randomly inited counter.
2865 (setq message-unique-id-char
2866 (% (1+ (or message-unique-id-char (logand (random t) (1- (lsh 1 20)))))
2867 ;; (current-time) returns 16-bit ints,
2868 ;; and 2^16*25 just fits into 4 digits i base 36.
2870 (let ((tm (current-time)))
2872 (if (memq system-type '(ms-dos emx vax-vms))
2873 (let ((user (downcase (user-login-name))))
2874 (while (string-match "[^a-z0-9_]" user)
2875 (aset user (match-beginning 0) ?_))
2877 (message-number-base36 (user-uid) -1))
2878 (message-number-base36 (+ (car tm)
2879 (lsh (% message-unique-id-char 25) 16)) 4)
2880 (message-number-base36 (+ (nth 1 tm)
2881 (lsh (/ message-unique-id-char 25) 16)) 4)
2882 ;; Append the newsreader name, because while the generated
2883 ;; ID is unique to this newsreader, other newsreaders might
2884 ;; otherwise generate the same ID via another algorithm.
2887 (defun message-number-base36 (num len)
2892 (concat (message-number-base36 (/ num 36) (1- len))
2893 (char-to-string (aref "zyxwvutsrqponmlkjihgfedcba9876543210"
2896 (defun message-make-organization ()
2897 "Make an Organization header."
2898 (let* ((organization
2899 (when message-user-organization
2900 (if (message-functionp message-user-organization)
2901 (funcall message-user-organization)
2902 message-user-organization))))
2904 (message-set-work-buffer)
2905 (cond ((stringp organization)
2906 (insert organization))
2907 ((and (eq t organization)
2908 message-user-organization-file
2909 (file-exists-p message-user-organization-file))
2910 (insert-file-contents message-user-organization-file)))
2911 (goto-char (point-min))
2912 (while (re-search-forward "[\t\n]+" nil t)
2913 (replace-match "" t t))
2914 (unless (zerop (buffer-size))
2917 (defun message-make-lines ()
2918 "Count the number of lines and return numeric string."
2922 (goto-char (point-min))
2924 (concat "^" (regexp-quote mail-header-separator) "$"))
2926 (int-to-string (count-lines (point) (point-max))))))
2928 (defun message-make-in-reply-to ()
2929 "Return the In-Reply-To header for this message."
2930 (when message-reply-headers
2931 (let ((mid (mail-header-message-id message-reply-headers))
2932 (from (mail-header-from message-reply-headers))
2933 (date (mail-header-date message-reply-headers)))
2937 (let ((pair (std11-extract-address-components from)))
2939 (or (car pair) (cadr pair))
2941 (if (or (not date) (string= date ""))
2942 "(unknown date)" date)
2945 (defun message-make-distribution ()
2946 "Make a Distribution header."
2947 (let ((orig-distribution (message-fetch-reply-field "distribution")))
2948 (cond ((message-functionp message-distribution-function)
2949 (funcall message-distribution-function))
2950 (t orig-distribution))))
2952 (defun message-make-expires ()
2953 "Return an Expires header based on `message-expires'."
2954 (let ((current (current-time))
2955 (future (* 1.0 message-expires 60 60 24)))
2956 ;; Add the future to current.
2957 (setcar current (+ (car current) (round (/ future (expt 2 16)))))
2958 (setcar (cdr current) (+ (nth 1 current) (% (round future) (expt 2 16))))
2959 ;; Return the date in the future in UT.
2960 (timezone-make-date-arpa-standard
2961 (current-time-string current) (current-time-zone current) '(0 "UT"))))
2963 (defun message-make-path ()
2965 (let ((login-name (user-login-name)))
2966 (cond ((null message-user-path)
2967 (concat (system-name) "!" login-name))
2968 ((stringp message-user-path)
2969 ;; Support GENERICPATH. Suggested by vixie@decwrl.dec.com.
2970 (concat message-user-path "!" login-name))
2973 (defun message-make-from ()
2974 "Make a From header."
2975 (let* ((style message-from-style)
2976 (login (message-make-address))
2978 (or (and (boundp 'user-full-name)
2981 (when (string= fullname "&")
2982 (setq fullname (user-login-name)))
2984 (message-set-work-buffer)
2987 (equal fullname ""))
2989 ((or (eq style 'angles)
2990 (and (not (eq style 'parens))
2991 ;; Use angles if no quoting is needed, or if parens would
2992 ;; need quoting too.
2993 (or (not (string-match "[^- !#-'*+/-9=?A-Z^-~]" fullname))
2994 (let ((tmp (concat fullname nil)))
2995 (while (string-match "([^()]*)" tmp)
2996 (aset tmp (match-beginning 0) ?-)
2997 (aset tmp (1- (match-end 0)) ?-))
2998 (string-match "[\\()]" tmp)))))
3000 (goto-char (point-min))
3001 ;; Look for a character that cannot appear unquoted
3002 ;; according to RFC 822.
3003 (when (re-search-forward "[^- !#-'*+/-9=?A-Z^-~]" nil 1)
3004 ;; Quote fullname, escaping specials.
3005 (goto-char (point-min))
3007 (while (re-search-forward "[\"\\]" nil 1)
3008 (replace-match "\\\\\\&" t))
3010 (insert " <" login ">"))
3011 (t ; 'parens or default
3013 (let ((fullname-start (point)))
3015 (goto-char fullname-start)
3016 ;; RFC 822 says \ and nonmatching parentheses
3017 ;; must be escaped in comments.
3018 ;; Escape every instance of ()\ ...
3019 (while (re-search-forward "[()\\]" nil 1)
3020 (replace-match "\\\\\\&" t))
3021 ;; ... then undo escaping of matching parentheses,
3022 ;; including matching nested parentheses.
3023 (goto-char fullname-start)
3024 (while (re-search-forward
3025 "\\(\\=\\|[^\\]\\(\\\\\\\\\\)*\\)\\\\(\\(\\([^\\]\\|\\\\\\\\\\)*\\)\\\\)"
3027 (replace-match "\\1(\\3)" t)
3028 (goto-char fullname-start)))
3032 (defun message-make-sender ()
3033 "Return the \"real\" user address.
3034 This function tries to ignore all user modifications, and
3035 give as trustworthy answer as possible."
3036 (concat (user-login-name) "@" (system-name)))
3038 (defun message-make-address ()
3039 "Make the address of the user."
3040 (or (message-user-mail-address)
3041 (concat (user-login-name) "@" (message-make-domain))))
3043 (defun message-user-mail-address ()
3044 "Return the pertinent part of `user-mail-address'."
3045 (when user-mail-address
3046 (if (string-match " " user-mail-address)
3047 (nth 1 (std11-extract-address-components user-mail-address))
3048 user-mail-address)))
3050 (defun message-make-fqdn ()
3051 "Return user's fully qualified domain name."
3052 (let ((system-name (system-name))
3053 (user-mail (message-user-mail-address)))
3055 ((string-match "[^.]\\.[^.]" system-name)
3056 ;; `system-name' returned the right result.
3058 ;; Try `mail-host-address'.
3059 ((and (boundp 'mail-host-address)
3060 (stringp mail-host-address)
3061 (string-match "\\." mail-host-address))
3063 ;; We try `user-mail-address' as a backup.
3065 (string-match "\\." user-mail)
3066 (string-match "@\\(.*\\)\\'" user-mail))
3067 (match-string 1 user-mail))
3068 ;; Default to this bogus thing.
3070 (concat system-name ".i-did-not-set--mail-host-address--so-shoot-me")))))
3072 (defun message-make-host-name ()
3073 "Return the name of the host."
3074 (let ((fqdn (message-make-fqdn)))
3075 (string-match "^[^.]+\\." fqdn)
3076 (substring fqdn 0 (1- (match-end 0)))))
3078 (defun message-make-domain ()
3079 "Return the domain name."
3080 (or mail-host-address
3081 (message-make-fqdn)))
3083 ;; Dummy to avoid byte-compile warning.
3084 (defvar mule-version)
3085 (defvar emacs-beta-version)
3086 (defvar xemacs-codename)
3088 (defun message-make-user-agent ()
3089 "Return user-agent info."
3093 (if (featurep 'xemacs)
3096 (format "XEmacs/%d.%d" emacs-major-version emacs-minor-version)
3097 (if (and (boundp 'emacs-beta-version) emacs-beta-version)
3098 (format "beta%d" emacs-beta-version)
3100 (if (and (boundp 'xemacs-codename) xemacs-codename)
3101 (concat " (" xemacs-codename ")")
3106 (format "Emacs/%d.%d" emacs-major-version emacs-minor-version)
3107 (if (>= emacs-major-version 20)
3108 (if (and (boundp 'enable-multibyte-characters)
3109 enable-multibyte-characters)
3110 "" ; Should return " (multibyte)"?
3114 (if (featurep 'mule)
3115 (if (and (boundp 'mule-version) mule-version)
3116 (concat " MULE/" mule-version)
3117 " MULE") ; no mule-version
3120 (if (featurep 'meadow)
3121 (let ((version (Meadow-version)))
3122 (if (string-match "\\`Meadow.\\([^ ]*\\)\\( (.*)\\)\\'" version)
3124 (match-string 1 version)
3125 (match-string 2 version)
3127 "Meadow")) ; unknown format
3130 (if message-user-agent
3131 (concat message-user-agent " " user-agent)
3134 (defun message-generate-headers (headers)
3135 "Prepare article HEADERS.
3136 Headers already prepared in the buffer are not modified."
3138 (message-narrow-to-headers)
3139 (let* ((Date (message-make-date))
3140 (Message-ID (message-make-message-id))
3141 (Organization (message-make-organization))
3142 (From (message-make-from))
3143 (Path (message-make-path))
3146 (In-Reply-To (message-make-in-reply-to))
3148 (Distribution (message-make-distribution))
3149 (Lines (message-make-lines))
3150 (User-Agent (message-make-user-agent))
3151 (Expires (message-make-expires))
3152 (case-fold-search t)
3154 ;; First we remove any old generated headers.
3155 (let ((headers message-deletable-headers))
3156 (unless (buffer-modified-p)
3157 (setq headers (delq 'Message-ID (copy-sequence headers))))
3159 (goto-char (point-min))
3160 (and (re-search-forward
3161 (concat "^" (symbol-name (car headers)) ": *") nil t)
3162 (get-text-property (1+ (match-beginning 0)) 'message-deletable)
3163 (message-delete-line))
3165 ;; Go through all the required headers and see if they are in the
3166 ;; articles already. If they are not, or are empty, they are
3167 ;; inserted automatically - except for Subject, Newsgroups and
3170 (goto-char (point-min))
3171 (setq elem (pop headers))
3173 (if (eq (car elem) 'optional)
3174 (setq header (cdr elem))
3175 (setq header (car elem)))
3177 (when (or (not (re-search-forward
3181 (if (stringp header)
3183 (symbol-name header))))
3187 ;; The header was found. We insert a space after the
3188 ;; colon, if there is none.
3189 (if (/= (following-char) ? ) (insert " ") (forward-char 1))
3190 ;; Find out whether the header is empty...
3191 (looking-at "[ \t]*$")))
3192 ;; So we find out what value we should insert.
3195 ((and (consp elem) (eq (car elem) 'optional))
3196 ;; This is an optional header. If the cdr of this
3197 ;; is something that is nil, then we do not insert
3199 (setq header (cdr elem))
3200 (or (and (fboundp (cdr elem)) (funcall (cdr elem)))
3201 (and (boundp (cdr elem)) (symbol-value (cdr elem)))))
3203 ;; The element is a cons. Either the cdr is a
3204 ;; string to be inserted verbatim, or it is a
3205 ;; function, and we insert the value returned from
3207 (or (and (stringp (cdr elem)) (cdr elem))
3208 (and (fboundp (cdr elem)) (funcall (cdr elem)))))
3209 ((and (boundp header) (symbol-value header))
3210 ;; The element is a symbol. We insert the value
3211 ;; of this symbol, if any.
3212 (symbol-value header))
3214 ;; We couldn't generate a value for this header,
3215 ;; so we just ask the user.
3216 (read-from-minibuffer
3217 (format "Empty header for %s; enter value: " header)))))
3218 ;; Finally insert the header.
3220 (not (equal value "")))
3224 ;; This header didn't exist, so we insert it.
3225 (goto-char (point-max))
3226 (insert (if (stringp header) header (symbol-name header))
3229 ;; The value of this header was empty, so we clear
3230 ;; totally and insert the new value.
3231 (delete-region (point) (gnus-point-at-eol))
3233 ;; Add the deletable property to the headers that require it.
3234 (and (memq header message-deletable-headers)
3235 (progn (beginning-of-line) (looking-at "[^:]+: "))
3236 (add-text-properties
3237 (point) (match-end 0)
3238 '(message-deletable t face italic) (current-buffer)))))))
3239 ;; Insert new Sender if the From is strange.
3240 (let ((from (message-fetch-field "from"))
3241 (sender (message-fetch-field "sender"))
3242 (secure-sender (message-make-sender)))
3244 (not (message-check-element 'sender))
3247 (cadr (std11-extract-address-components from)))
3248 (downcase secure-sender)))
3253 (cadr (std11-extract-address-components sender)))
3254 (downcase secure-sender)))))
3255 (goto-char (point-min))
3256 ;; Rename any old Sender headers to Original-Sender.
3257 (when (re-search-forward "^\\(Original-\\)*Sender:" nil t)
3259 (insert "Original-")
3260 (beginning-of-line))
3261 (when (or (message-news-p)
3262 (string-match "@.+\\.." secure-sender))
3263 (insert "Sender: " secure-sender "\n")))))))
3265 (defun message-insert-courtesy-copy ()
3266 "Insert a courtesy message in mail copies of combined messages."
3270 (message-narrow-to-headers)
3271 (when (setq newsgroups (message-fetch-field "newsgroups"))
3272 (goto-char (point-max))
3273 (insert "Posted-To: " newsgroups "\n")))
3275 (when message-courtesy-message
3277 ((string-match "%s" message-courtesy-message)
3278 (insert (format message-courtesy-message newsgroups)))
3280 (insert message-courtesy-message)))))))
3283 ;;; Setting up a message buffer
3286 (defun message-fill-address (header value)
3288 (narrow-to-region (point) (point))
3289 (insert (capitalize (symbol-name header))
3291 (if (consp value) (car value) value)
3293 (narrow-to-region (point-min) (1- (point-max)))
3295 (goto-char (point-min))
3297 (skip-chars-forward "^,\"" (point-max))
3298 (if (or (= (following-char) ?,)
3304 (looking-at "[ \t]*")
3305 (replace-match "\n " t t)))
3306 (setq last (1+ (point))))
3307 (setq quoted (not quoted)))
3310 (goto-char (point-max))
3314 (defun message-fill-references (header value)
3315 (insert (capitalize (symbol-name header))
3317 (std11-fill-msg-id-list-string
3318 (if (consp value) (car value) value))
3321 (defun message-fill-header (header value)
3322 (let ((begin (point))
3325 (insert (capitalize (symbol-name header))
3327 (if (consp value) (car value) value)
3330 (narrow-to-region begin (point))
3331 (fill-region-as-paragraph begin (point))
3332 ;; Tapdance around looong Message-IDs.
3334 (when (looking-at "[ \t]*$")
3335 (message-delete-line))
3337 (re-search-forward ":" nil t)
3338 (when (looking-at "\n[ \t]+")
3339 (replace-match " " t t))
3340 (goto-char (point-max)))))
3342 (defun message-shorten-references (header references)
3343 "Limit REFERENCES to be shorter than 988 characters."
3347 (nnheader-temp-write nil
3349 (goto-char (point-min))
3350 (while (re-search-forward "<[^>]+>" nil t)
3351 (push (match-string 0) refs))
3352 (setq refs (nreverse refs))
3353 (while (> (length (mapconcat 'identity refs " ")) max)
3354 (when (< (length refs) (1+ cut))
3356 (setcdr (nthcdr cut refs) (cddr (nthcdr cut refs)))))
3357 (insert (capitalize (symbol-name header)) ": "
3358 (mapconcat 'identity refs " ") "\n")))
3360 (defun message-position-point ()
3361 "Move point to where the user probably wants to find it."
3362 (message-narrow-to-headers)
3364 ((re-search-forward "^[^:]+:[ \t]*$" nil t)
3365 (search-backward ":" )
3368 (if (= (following-char) ? )
3372 (goto-char (point-max))
3375 (unless (looking-at "$")
3379 (defun message-buffer-name (type &optional to group)
3380 "Return a new (unique) buffer name based on TYPE and TO."
3382 ;; Check whether `message-generate-new-buffers' is a function,
3383 ;; and if so, call it.
3384 ((message-functionp message-generate-new-buffers)
3385 (funcall message-generate-new-buffers type to group))
3386 ;; Generate a new buffer name The Message Way.
3387 (message-generate-new-buffers
3388 (generate-new-buffer-name
3392 (or (car (std11-extract-address-components to))
3395 (if (and group (not (string= group ""))) (concat " on " group) "")
3397 ;; Use standard name.
3399 (format "*%s message*" type))))
3401 (defun message-pop-to-buffer (name)
3402 "Pop to buffer NAME, and warn if it already exists and is modified."
3403 (let ((pop-up-frames pop-up-frames)
3404 (special-display-buffer-names special-display-buffer-names)
3405 (special-display-regexps special-display-regexps)
3406 (same-window-buffer-names same-window-buffer-names)
3407 (same-window-regexps same-window-regexps)
3408 (buffer (get-buffer name))
3409 (cur (current-buffer)))
3410 (if (or (and (featurep 'xemacs)
3411 (not (eq 'tty (device-type))))
3413 (>= emacs-major-version 20))
3414 (when message-use-multi-frames
3415 (setq pop-up-frames t
3416 special-display-buffer-names nil
3417 special-display-regexps nil
3418 same-window-buffer-names nil
3419 same-window-regexps nil))
3420 (setq pop-up-frames nil))
3422 (buffer-name buffer))
3424 (set-buffer (pop-to-buffer buffer))
3425 (when (and (buffer-modified-p)
3427 "Message already being composed; erase? ")))
3428 (error "Message being composed")))
3429 (set-buffer (pop-to-buffer name)))
3433 (make-local-variable 'message-original-frame)
3434 (setq message-original-frame (selected-frame)))))
3436 (defun message-do-send-housekeeping ()
3437 "Kill old message buffers."
3438 ;; We might have sent this buffer already. Delete it from the
3440 (setq message-buffer-list (delq (current-buffer) message-buffer-list))
3441 (while (and message-max-buffers
3443 (>= (length message-buffer-list) message-max-buffers))
3444 ;; Kill the oldest buffer -- unless it has been changed.
3445 (let ((buffer (pop message-buffer-list)))
3446 (when (and (buffer-name buffer)
3447 (not (buffer-modified-p buffer)))
3448 (kill-buffer buffer))))
3449 ;; Rename the buffer.
3450 (if message-send-rename-function
3451 (funcall message-send-rename-function)
3452 (when (string-match "\\`\\*" (buffer-name))
3454 (concat "*sent " (substring (buffer-name) (match-end 0))) t)))
3455 ;; Push the current buffer onto the list.
3456 (when message-max-buffers
3457 (setq message-buffer-list
3458 (nconc message-buffer-list (list (current-buffer))))))
3460 (defvar mc-modes-alist)
3461 (defun message-setup (headers &optional replybuffer actions)
3462 (when (and (boundp 'mc-modes-alist)
3463 (not (assq 'message-mode mc-modes-alist)))
3464 (push '(message-mode (encrypt . mc-encrypt-message)
3465 (sign . mc-sign-message))
3468 (setq message-send-actions actions))
3469 (setq message-reply-buffer replybuffer)
3470 (goto-char (point-min))
3471 ;; Insert all the headers.
3474 (alist message-header-format-alist))
3476 (unless (assq (caar h) message-header-format-alist)
3477 (push (list (caar h)) alist))
3481 (delete-region (point) (progn (forward-line -1) (point)))
3482 (when message-default-headers
3483 (insert message-default-headers)
3484 (or (bolp) (insert ?\n)))
3488 (insert mail-header-separator "\n")
3492 (when (message-news-p)
3493 (when message-default-news-headers
3494 (insert message-default-news-headers)
3495 (or (bolp) (insert ?\n)))
3496 (when message-generate-headers-first
3497 (message-generate-headers
3500 (copy-sequence message-required-news-headers))))))
3501 (when (message-mail-p)
3502 (when message-default-mail-headers
3503 (insert message-default-mail-headers)
3504 (or (bolp) (insert ?\n)))
3505 (when message-generate-headers-first
3506 (message-generate-headers
3509 (copy-sequence message-required-mail-headers))))))
3510 (run-hooks 'message-signature-setup-hook)
3511 (message-insert-signature)
3513 (message-narrow-to-headers)
3514 (run-hooks 'message-header-setup-hook))
3515 (set-buffer-modified-p nil)
3516 (setq buffer-undo-list nil)
3517 (run-hooks 'message-setup-hook)
3518 (message-position-point)
3521 (defun message-set-auto-save-file-name ()
3522 "Associate the message buffer with a file in the drafts directory."
3523 (when message-autosave-directory
3525 (setq message-draft-article
3526 (nndraft-request-associate-buffer "drafts"))
3527 (setq buffer-file-name (expand-file-name "*message*"
3528 message-autosave-directory))
3529 (setq buffer-auto-save-file-name (make-auto-save-file-name)))
3530 (clear-visited-file-modtime)))
3532 (defun message-disassociate-draft ()
3533 "Disassociate the message buffer from the drafts directory."
3534 (when message-draft-article
3535 (nndraft-request-expire-articles
3536 (list message-draft-article) "drafts" nil t)))
3541 ;;; Commands for interfacing with message
3545 (defun message-mail (&optional to subject
3546 other-headers continue switch-function
3547 yank-action send-actions)
3548 "Start editing a mail message to be sent.
3549 OTHER-HEADERS is an alist of header/value pairs."
3551 (let ((message-this-is-mail t))
3552 (message-pop-to-buffer (message-buffer-name "mail" to))
3555 `((To . ,(or to "")) (Subject . ,(or subject "")))
3556 (when other-headers other-headers)))))
3559 (defun message-news (&optional newsgroups subject)
3560 "Start editing a news article to be sent."
3562 (let ((message-this-is-news t))
3563 (message-pop-to-buffer (message-buffer-name "news" nil newsgroups))
3564 (message-setup `((Newsgroups . ,(or newsgroups ""))
3565 (Subject . ,(or subject ""))))))
3568 (defun message-reply (&optional to-address wide)
3569 "Start editing a reply to the article in the current buffer."
3571 (let ((cur (current-buffer))
3572 (inhibit-point-motion-hooks t)
3573 from date subject mct mft mrt
3575 references message-id follow-to gnus-warning)
3577 (message-narrow-to-head)
3578 ;; Allow customizations to have their say.
3580 ;; This is a regular reply.
3581 (if (message-functionp message-reply-to-function)
3582 (setq follow-to (funcall message-reply-to-function)))
3583 ;; This is a followup.
3584 (if (message-functionp message-wide-reply-to-function)
3587 (funcall message-wide-reply-to-function)))))
3588 ;; Find all relevant headers we need.
3589 (setq from (message-fetch-field "from")
3590 date (message-fetch-field "date" t)
3591 subject (or (message-fetch-field "subject") "none")
3592 references (message-fetch-field "references")
3593 message-id (message-fetch-field "message-id" t)
3594 to (message-fetch-field "to")
3595 cc (message-fetch-field "cc")
3596 mct (when (and wide message-use-mail-copies-to)
3597 (message-fetch-field "mail-copies-to"))
3598 mft (when (and wide message-use-mail-followup-to)
3599 (message-fetch-field "mail-followup-to"))
3600 mrt (when message-use-mail-reply-to
3601 (or (message-fetch-field "mail-reply-to")
3602 (message-fetch-field "reply-to")))
3603 gnus-warning (message-fetch-field "gnus-warning"))
3604 (when (and gnus-warning (string-match "<[^>]+>" gnus-warning))
3605 (setq message-id (match-string 0 gnus-warning)))
3606 ;; Remove any (buggy) Re:'s that are present and make a
3608 (setq subject (message-make-followup-subject subject))
3611 ;; Handle special values of Mail-Copies-To.
3614 ((and (equal (downcase mct) "never")
3615 (or (not (eq message-use-mail-copies-to 'ask))
3617 (concat "Obey Mail-Copies-To: never? ") t "\
3618 You should normally obey the Mail-Copies-To: header.
3620 `Mail-Copies-To: never'
3621 directs you not to send your response to the author.")))
3624 ((and (equal (downcase mct) "always")
3625 (or (not (eq message-use-mail-copies-to 'ask))
3627 (concat "Obey Mail-Copies-To: always? ") t "\
3628 You should normally obey the Mail-Copies-To: header.
3630 `Mail-Copies-To: always'
3631 sends a copy of your response to the author.")))
3632 (setq mct (or mrt from)))
3633 ((and (eq message-use-mail-copies-to 'ask)
3636 (concat "Obey Mail-Copies-To: " mct " ? ") t "\
3637 You should normally obey the Mail-Copies-To: header.
3639 `Mail-Copies-To: " mct "'
3640 sends a copy of your response to " (if (string-match "," mct)
3641 "the specified addresses"
3642 "that address") ".")))
3648 (to-address (setq follow-to (list (cons 'To to-address))))
3649 ((not wide) (setq follow-to (list (cons 'To (or mrt from)))))
3650 ;; Handle Mail-Followup-To.
3652 (or (not (eq message-use-mail-followup-to 'ask))
3654 (concat "Obey Mail-Followup-To: " mft "? ") t "\
3655 You should normally obey the Mail-Followup-To: header.
3657 `Mail-Followup-To: " mft "'
3658 directs your response to " (if (string-match "," mft)
3659 "the specified addresses"
3660 "that address only") ".
3662 A typical situation where Mail-Followup-To is used is when the author thinks
3663 that further discussion should take place only in "
3664 (if (string-match "," mft)
3665 "the specified mailing lists"
3666 "that mailing list") ".")))
3667 (setq follow-to (list (cons 'To mft)))
3669 (push (cons 'Cc mct) follow-to)))
3673 (message-set-work-buffer)
3675 (insert (or mrt from "")))
3676 (insert (if to (concat (if (bolp) "" ", ") to "") ""))
3677 (insert (if mct (concat (if (bolp) "" ", ") mct) ""))
3678 (insert (if cc (concat (if (bolp) "" ", ") cc) ""))
3679 (goto-char (point-min))
3680 (while (re-search-forward "[ \t]+" nil t)
3681 (replace-match " " t t))
3682 ;; Remove addresses that match `rmail-dont-reply-to-names'.
3683 (insert (prog1 (rmail-dont-reply-to (buffer-string))
3685 (goto-char (point-min))
3686 ;; Perhaps Mail-Copies-To: never removed the only address?
3688 (insert (or mrt from "")))
3692 (cons (mail-strip-quoted-names addr) addr))
3693 (message-tokenize-header (buffer-string))))
3696 (setq ccalist (delq (assoc (car (pop s)) s) ccalist)))))
3697 (setq follow-to (list (cons 'To (cdr (pop ccalist)))))
3699 (let ((ccs (cons 'Cc (mapconcat
3700 (lambda (addr) (cdr addr)) ccalist ", "))))
3701 (when (string-match "^ +" (cdr ccs))
3702 (setcdr ccs (substring (cdr ccs) (match-end 0))))
3703 (push ccs follow-to)))))))
3705 (message-pop-to-buffer (message-buffer-name
3706 (if wide "wide reply" "reply") from
3707 (if wide to-address nil)))
3709 (setq message-reply-headers
3710 (vector 0 subject from date message-id references 0 0 ""))
3713 `((Subject . ,subject)
3715 ,@(if (or references message-id)
3716 `((References . ,(concat (or references "") (and references " ")
3717 (or message-id ""))))))
3721 (defun message-wide-reply (&optional to-address)
3722 "Make a \"wide\" reply to the message in the current buffer."
3724 (message-reply to-address t))
3727 (defun message-followup (&optional to-newsgroups)
3728 "Follow up to the message in the current buffer."
3730 (let ((cur (current-buffer))
3731 (inhibit-point-motion-hooks t)
3732 from date subject mct mft mrt
3733 (message-this-is-news t)
3734 followup-to distribution newsgroups posted-to
3735 references message-id follow-to gnus-warning)
3737 (message-narrow-to-head)
3738 ;; Allow customizations to have their say.
3739 ;; This is a followup.
3740 (when (message-functionp message-followup-to-function)
3742 (funcall message-followup-to-function)))
3743 ;; Find all relevant headers we need.
3744 (setq from (message-fetch-field "from")
3745 date (message-fetch-field "date" t)
3746 subject (or (message-fetch-field "subject") "none")
3747 references (message-fetch-field "references")
3748 message-id (message-fetch-field "message-id" t)
3749 followup-to (when message-use-followup-to
3750 (message-fetch-field "followup-to"))
3751 distribution (message-fetch-field "distribution")
3752 newsgroups (message-fetch-field "newsgroups")
3753 posted-to (message-fetch-field "posted-to")
3754 mct (when message-use-mail-copies-to
3755 (message-fetch-field "mail-copies-to"))
3756 mft (when message-use-mail-followup-to
3757 (message-fetch-field "mail-followup-to"))
3758 mrt (when message-use-mail-reply-to
3759 (or (message-fetch-field "mail-reply-to")
3760 (message-fetch-field "reply-to")))
3761 gnus-warning (message-fetch-field "gnus-warning"))
3762 (when (and gnus-warning (string-match "<[^>]+>" gnus-warning))
3763 (setq message-id (match-string 0 gnus-warning)))
3764 ;; Remove bogus distribution.
3765 (when (and (stringp distribution)
3766 (let ((case-fold-search t))
3767 (string-match "world" distribution)))
3768 (setq distribution nil))
3769 ;; Remove any (buggy) Re:'s that are present and make a
3771 (setq subject (message-make-followup-subject subject))
3774 ;; Handle special values of Mail-Copies-To.
3777 ((and (equal (downcase mct) "never")
3778 (or (not (eq message-use-mail-copies-to 'ask))
3780 (concat "Obey Mail-Copies-To: never? ") t "\
3781 You should normally obey the Mail-Copies-To: header.
3783 `Mail-Copies-To: never'
3784 directs you not to send your response to the author.")))
3786 ((and (equal (downcase mct) "always")
3787 (or (not (eq message-use-mail-copies-to 'ask))
3789 (concat "Obey Mail-Copies-To: always? ") t "\
3790 You should normally obey the Mail-Copies-To: header.
3792 `Mail-Copies-To: always'
3793 sends a copy of your response to the author.")))
3794 (setq mct (or mrt from)))
3795 ((and (eq message-use-mail-copies-to 'ask)
3798 (concat "Obey Mail-Copies-To: " mct " ? ") t "\
3799 You should normally obey the Mail-Copies-To: header.
3801 `Mail-Copies-To: " mct "'
3802 sends a copy of your response to " (if (string-match "," mct)
3803 "the specified addresses"
3804 "that address") ".")))
3810 (to-newsgroups (setq follow-to (list (cons 'Newsgroups to-newsgroups))))
3811 ;; Handle Followup-To.
3814 ((equal (downcase followup-to) "poster")
3815 (if (or (eq message-use-followup-to 'use)
3816 (message-y-or-n-p "Obey Followup-To: poster? " t "\
3817 You should normally obey the Followup-To: header.
3819 `Followup-To: poster'
3820 sends your response via e-mail instead of news.
3822 A typical situation where `Followup-To: poster' is used is when the author
3823 does not read the newsgroup, so he wouldn't see any replies sent to it."))
3824 (setq message-this-is-news nil
3826 follow-to (list (cons 'To (or mrt from ""))))
3827 (setq follow-to (list (cons 'Newsgroups newsgroups)))))
3829 (if (or (equal followup-to newsgroups)
3830 (not (eq message-use-followup-to 'ask))
3832 (concat "Obey Followup-To: " followup-to "? ") t "\
3833 You should normally obey the Followup-To: header.
3835 `Followup-To: " followup-to "'
3836 directs your response to " (if (string-match "," followup-to)
3837 "the specified newsgroups"
3838 "that newsgroup only") ".
3840 If a message is posted to several newsgroups, Followup-To is often
3841 used to direct the following discussion to one newsgroup only,
3842 because discussions that are spread over several newsgroup tend to
3843 be fragmented and very difficult to follow.
3845 Also, some source/announcement newsgroups are not indented for discussion;
3846 responses here are directed to other newsgroups."))
3847 (setq follow-to (list (cons 'Newsgroups followup-to)))
3848 (setq follow-to (list (cons 'Newsgroups newsgroups)))))))
3849 ;; Handle Mail-Followup-To, followup via e-mail.
3851 (or (not (eq message-use-mail-followup-to 'ask))
3853 (concat "Obey Mail-Followup-To: " mft "? ") t "\
3854 You should normally obey the Mail-Followup-To: header.
3856 `Mail-Followup-To: " mft "'
3857 directs your response to " (if (string-match "," mft)
3858 "the specified addresses"
3859 "that address only") " instead of news.
3861 A typical situation where Mail-Followup-To is used is when the author thinks
3862 that further discussion should take place only in "
3863 (if (string-match "," mft)
3864 "the specified mailing lists"
3865 "that mailing list") ".")))
3866 (setq message-this-is-news nil
3868 follow-to (list (cons 'To mft))))
3869 (posted-to (setq follow-to (list (cons 'Newsgroups posted-to))))
3871 (setq follow-to (list (cons 'Newsgroups newsgroups))))))
3873 (message-pop-to-buffer (message-buffer-name "followup" from newsgroups))
3875 (setq message-reply-headers
3876 (vector 0 subject from date message-id references 0 0 ""))
3879 `((Subject . ,subject)
3881 ,@(and mct (list (cons 'Cc mct)))
3882 ,@(and distribution (list (cons 'Distribution distribution)))
3883 ,@(if (or references message-id)
3884 `((References . ,(concat (or references "") (and references " ")
3885 (or message-id ""))))))
3889 (defun message-cancel-news ()
3890 "Cancel an article you posted."
3892 (unless (message-news-p)
3893 (error "This is not a news article; canceling is impossible"))
3894 (when (yes-or-no-p "Do you really want to cancel this article? ")
3895 (let (from newsgroups message-id distribution buf sender)
3897 ;; Get header info. from original article.
3899 (message-narrow-to-head)
3900 (setq from (message-fetch-field "from")
3901 sender (message-fetch-field "sender")
3902 newsgroups (message-fetch-field "newsgroups")
3903 message-id (message-fetch-field "message-id" t)
3904 distribution (message-fetch-field "distribution")))
3905 ;; Make sure that this article was written by the user.
3906 (unless (or (and sender
3909 (downcase (message-make-sender))))
3911 (downcase (cadr (std11-extract-address-components
3913 (downcase (cadr (std11-extract-address-components
3914 (message-make-from))))))
3915 (error "This article is not yours"))
3916 ;; Make control message.
3917 (setq buf (set-buffer (get-buffer-create " *message cancel*")))
3918 (buffer-disable-undo (current-buffer))
3920 (insert "Newsgroups: " newsgroups "\n"
3921 "From: " (message-make-from) "\n"
3922 "Subject: cmsg cancel " message-id "\n"
3923 "Control: cancel " message-id "\n"
3925 (concat "Distribution: " distribution "\n")
3927 mail-header-separator "\n"
3928 message-cancel-message)
3929 (message "Canceling your article...")
3930 (if (let ((message-syntax-checks
3931 'dont-check-for-anything-just-trust-me)
3932 (message-encoding-buffer (current-buffer))
3933 (message-edit-buffer (current-buffer)))
3934 (message-send-news))
3935 (message "Canceling your article...done"))
3936 (kill-buffer buf)))))
3939 (defun message-supersede ()
3940 "Start composing a message to supersede the current message.
3941 This is done simply by taking the old article and adding a Supersedes
3942 header line with the old Message-ID."
3944 (let ((cur (current-buffer))
3945 (sender (message-fetch-field "sender"))
3946 (from (message-fetch-field "from")))
3947 ;; Check whether the user owns the article that is to be superseded.
3948 (unless (or (and sender
3951 (downcase (message-make-sender))))
3953 (downcase (cadr (std11-extract-address-components from)))
3954 (downcase (cadr (std11-extract-address-components
3955 (message-make-from))))))
3956 (error "This article is not yours"))
3957 ;; Get a normal message buffer.
3958 (message-pop-to-buffer (message-buffer-name "supersede"))
3959 (insert-buffer-substring cur)
3960 (message-narrow-to-head)
3961 ;; Remove unwanted headers.
3962 (when message-ignored-supersedes-headers
3963 (message-remove-header message-ignored-supersedes-headers t))
3964 (goto-char (point-min))
3965 (if (not (re-search-forward "^Message-ID: " nil t))
3966 (error "No Message-ID in this article")
3967 (replace-match "Supersedes: " t t))
3968 (goto-char (point-max))
3969 (insert mail-header-separator)
3974 (defun message-recover ()
3975 "Reread contents of current buffer from its last auto-save file."
3977 (let ((file-name (make-auto-save-file-name)))
3978 (cond ((save-window-excursion
3979 (if (not (eq system-type 'vax-vms))
3980 (with-output-to-temp-buffer "*Directory*"
3981 (buffer-disable-undo standard-output)
3982 (let ((default-directory "/"))
3984 "ls" nil standard-output nil "-l" file-name))))
3985 (yes-or-no-p (format "Recover auto save file %s? " file-name)))
3986 (let ((buffer-read-only nil))
3988 (insert-file-contents file-name nil)))
3989 (t (error "message-recover cancelled")))))
3991 ;;; Washing Subject:
3993 (defun message-wash-subject (subject)
3994 "Remove junk like \"Re:\", \"(fwd)\", etc. that was added to the subject by previous forwarders, replyers, etc."
3995 (nnheader-temp-write nil
3996 (insert-string subject)
3997 (goto-char (point-min))
3998 ;; strip Re/Fwd stuff off the beginning
3999 (while (re-search-forward
4000 "\\([Rr][Ee]:\\|[Ff][Ww][Dd]\\(\\[[0-9]*\\]\\)?:\\|[Ff][Ww]:\\)" nil t)
4003 ;; and gnus-style forwards [foo@bar.com] subject
4004 (goto-char (point-min))
4005 (while (re-search-forward "\\[[^ \t]*\\(@\\|\\.\\)[^ \t]*\\]" nil t)
4009 (goto-char (point-max))
4010 (while (re-search-backward "([Ff][Ww][Dd])" nil t)
4013 ;; and finally, any whitespace that was left-over
4014 (goto-char (point-min))
4015 (while (re-search-forward "^[ \t]+" nil t)
4017 (goto-char (point-max))
4018 (while (re-search-backward "[ \t]+$" nil t)
4023 ;;; Forwarding messages.
4025 (defun message-forward-subject-author-subject (subject)
4026 "Generate a subject for a forwarded message.
4027 The form is: [Source] Subject, where if the original message was mail,
4028 Source is the sender, and if the original message was news, Source is
4029 the list of newsgroups is was posted to."
4031 (or (message-fetch-field
4032 (if (message-news-p) "newsgroups" "from"))
4036 (defun message-forward-subject-fwd (subject)
4037 "Generate a subject for a forwarded message.
4038 The form is: Fwd: Subject, where Subject is the original subject of
4040 (concat "Fwd: " subject))
4042 (defun message-make-forward-subject ()
4043 "Return a Subject header suitable for the message in the current buffer."
4047 (message-narrow-to-head)
4048 (let ((funcs message-make-forward-subject-function)
4049 (subject (if message-wash-forwarded-subjects
4050 (message-wash-subject
4051 (or (eword-decode-unstructured-field-body
4052 (message-fetch-field "Subject")) ""))
4053 (or (eword-decode-unstructured-field-body
4054 (message-fetch-field "Subject")) ""))))
4055 ;; Make sure funcs is a list.
4058 (setq funcs (list funcs)))
4059 ;; Apply funcs in order, passing subject generated by previous
4060 ;; func to the next one.
4062 (when (message-functionp (car funcs))
4063 (setq subject (funcall (car funcs) subject)))
4064 (setq funcs (cdr funcs)))
4068 (defun message-forward (&optional news)
4069 "Forward the current message via mail.
4070 Optional NEWS will use news to forward instead of mail."
4072 (let ((cur (current-buffer))
4073 (subject (message-make-forward-subject))
4075 (if news (message-news nil subject) (message-mail nil subject))
4076 ;; Put point where we want it before inserting the forwarded
4078 (if message-signature-before-forwarded-message
4079 (goto-char (point-max))
4080 (message-goto-body))
4081 ;; Make sure we're at the start of the line.
4084 ;; Narrow to the area we are to insert.
4085 (narrow-to-region (point) (point))
4086 ;; Insert the separators and the forwarded buffer.
4087 (insert message-forward-start-separator)
4088 (setq art-beg (point))
4089 (insert-buffer-substring cur)
4090 (goto-char (point-max))
4091 (insert message-forward-end-separator)
4092 (set-text-properties (point-min) (point-max) nil)
4093 ;; Remove all unwanted headers.
4095 (narrow-to-region (point) (if (search-forward "\n\n" nil t)
4098 (goto-char (point-min))
4099 (message-remove-header message-included-forward-headers t nil t)
4101 (message-position-point)))
4104 (defun message-resend (address)
4105 "Resend the current article to ADDRESS."
4106 (interactive "sResend message to: ")
4107 (message "Resending message to %s..." address)
4109 (let ((cur (current-buffer))
4111 ;; We first set up a normal mail buffer.
4112 (set-buffer (get-buffer-create " *message resend*"))
4113 (buffer-disable-undo (current-buffer))
4115 ;; avoid to turn-on-mime-edit
4116 (let (message-setup-hook)
4117 (message-setup `((To . ,address)))
4119 ;; Insert our usual headers.
4120 (message-generate-headers '(From Date To))
4121 (message-narrow-to-headers)
4122 ;; Rename them all to "Resent-*".
4123 (while (re-search-forward "^[A-Za-z]" nil t)
4128 (delete-region (point) (point-max))
4130 ;; Insert the message to be resent.
4131 (insert-buffer-substring cur)
4132 (goto-char (point-min))
4133 (search-forward "\n\n")
4136 (narrow-to-region beg (point))
4137 (message-remove-header message-ignored-resent-headers t)
4138 (goto-char (point-max)))
4139 (insert mail-header-separator)
4140 ;; Rename all old ("Also-")Resent headers.
4141 (while (re-search-backward "^\\(Also-\\)*Resent-" beg t)
4144 ;; Quote any "From " lines at the beginning.
4146 (when (looking-at "From ")
4147 (replace-match "X-From-Line: "))
4149 (let ((message-encoding-buffer (current-buffer))
4150 (message-edit-buffer (current-buffer)))
4151 (message-send-mail))
4152 (kill-buffer (current-buffer)))
4153 (message "Resending message to %s...done" address)))
4156 (defun message-bounce ()
4157 "Re-mail the current message.
4158 This only makes sense if the current message is a bounce message than
4159 contains some mail you have written which has been bounced back to
4162 (let ((cur (current-buffer))
4164 (message-pop-to-buffer (message-buffer-name "bounce"))
4165 (insert-buffer-substring cur)
4167 (message-narrow-to-head)
4168 (if (and (message-fetch-field "MIME-Version")
4169 (setq boundary (message-fetch-field "Content-Type")))
4170 (if (string-match "boundary=\"\\([^\"]+\\)\"" boundary)
4171 (setq boundary (concat (match-string 1 boundary) " *\n"
4172 "Content-Type: message/rfc822"))
4173 (setq boundary nil)))
4175 (goto-char (point-min))
4176 (search-forward "\n\n" nil t)
4178 (re-search-forward boundary nil t)
4180 (and (re-search-forward message-unsent-separator nil t)
4182 (re-search-forward "^Return-Path:.*\n" nil t))
4183 ;; We remove everything before the bounced mail.
4186 (if (re-search-forward "^[^ \n\t]+:" nil t)
4190 (message-narrow-to-head)
4191 (message-remove-header message-ignored-bounced-headers t)
4192 (goto-char (point-max))
4193 (insert mail-header-separator))
4194 (message-position-point)))
4197 ;;; Interactive entry points for new message buffers.
4201 (defun message-mail-other-window (&optional to subject)
4202 "Like `message-mail' command, but display mail buffer in another window."
4204 (let ((pop-up-windows t)
4205 (special-display-buffer-names nil)
4206 (special-display-regexps nil)
4207 (same-window-buffer-names nil)
4208 (same-window-regexps nil))
4209 (message-pop-to-buffer (message-buffer-name "mail" to)))
4210 (let ((message-this-is-mail t))
4211 (message-setup `((To . ,(or to "")) (Subject . ,(or subject ""))))))
4214 (defun message-mail-other-frame (&optional to subject)
4215 "Like `message-mail' command, but display mail buffer in another frame."
4217 (let ((pop-up-frames t)
4218 (special-display-buffer-names nil)
4219 (special-display-regexps nil)
4220 (same-window-buffer-names nil)
4221 (same-window-regexps nil))
4222 (message-pop-to-buffer (message-buffer-name "mail" to)))
4223 (let ((message-this-is-mail t))
4224 (message-setup `((To . ,(or to "")) (Subject . ,(or subject ""))))))
4227 (defun message-news-other-window (&optional newsgroups subject)
4228 "Start editing a news article to be sent."
4230 (let ((pop-up-windows t)
4231 (special-display-buffer-names nil)
4232 (special-display-regexps nil)
4233 (same-window-buffer-names nil)
4234 (same-window-regexps nil))
4235 (message-pop-to-buffer (message-buffer-name "news" nil newsgroups)))
4236 (let ((message-this-is-news t))
4237 (message-setup `((Newsgroups . ,(or newsgroups ""))
4238 (Subject . ,(or subject ""))))))
4241 (defun message-news-other-frame (&optional newsgroups subject)
4242 "Start editing a news article to be sent."
4244 (let ((pop-up-frames t)
4245 (special-display-buffer-names nil)
4246 (special-display-regexps nil)
4247 (same-window-buffer-names nil)
4248 (same-window-regexps nil))
4249 (message-pop-to-buffer (message-buffer-name "news" nil newsgroups)))
4250 (let ((message-this-is-news t))
4251 (message-setup `((Newsgroups . ,(or newsgroups ""))
4252 (Subject . ,(or subject ""))))))
4256 ;; This code should be moved to underline.el (from which it is stolen).
4259 (defun bold-region (start end)
4260 "Bold all nonblank characters in the region.
4261 Works by overstriking characters.
4262 Called from program, takes two arguments START and END
4263 which specify the range to operate on."
4266 (let ((end1 (make-marker)))
4267 (move-marker end1 (max start end))
4268 (goto-char (min start end))
4269 (while (< (point) end1)
4270 (or (looking-at "[_\^@- ]")
4271 (insert (following-char) "\b"))
4272 (forward-char 1)))))
4275 (defun unbold-region (start end)
4276 "Remove all boldness (overstruck characters) in the region.
4277 Called from program, takes two arguments START and END
4278 which specify the range to operate on."
4281 (let ((end1 (make-marker)))
4282 (move-marker end1 (max start end))
4283 (goto-char (min start end))
4284 (while (re-search-forward "\b" end1 t)
4285 (if (eq (following-char) (char-after (- (point) 2)))
4286 (delete-char -2))))))
4288 (defalias 'message-exchange-point-and-mark 'exchange-point-and-mark)
4290 ;; Support for toolbar
4291 (when (string-match "XEmacs\\|Lucid" emacs-version)
4292 (require 'messagexmas))
4294 ;;; Group name completion.
4296 (defvar message-newgroups-header-regexp
4297 "^\\(Newsgroups\\|Followup-To\\|Posted-To\\|Gcc\\):"
4298 "Regexp that match headers that lists groups.")
4300 (defun message-tab ()
4301 "Expand group names in Newsgroups and Followup-To headers.
4302 Do a `tab-to-tab-stop' if not in those headers."
4304 (if (let ((mail-abbrev-mode-regexp message-newgroups-header-regexp))
4305 (mail-abbrev-in-expansion-header-p))
4306 (message-expand-group)
4309 (defvar gnus-active-hashtb)
4310 (defun message-expand-group ()
4311 "Expand the group name under point."
4312 (let* ((b (save-excursion
4317 (skip-chars-forward "^:")
4320 (skip-chars-backward "^, \t\n") (point))))
4321 (completion-ignore-case t)
4322 (string (buffer-substring b (progn (skip-chars-forward "^,\t\n ")
4324 (hashtb (and (boundp 'gnus-active-hashtb) gnus-active-hashtb))
4325 (completions (all-completions string hashtb))
4327 (delete-region b (point))
4329 ((= (length completions) 1)
4330 (if (string= (car completions) string)
4333 (message "Only matching group"))
4334 (insert (car completions))))
4335 ((and (setq comp (try-completion string hashtb))
4336 (not (string= comp string)))
4341 (message "No matching groups")
4342 (save-selected-window
4343 (pop-to-buffer "*Completions*")
4344 (buffer-disable-undo (current-buffer))
4345 (let ((buffer-read-only nil))
4347 (let ((standard-output (current-buffer)))
4348 (display-completion-list (sort completions 'string<)))
4349 (goto-char (point-min))
4350 (delete-region (point) (progn (forward-line 3) (point))))))))))
4354 (defun message-talkative-question (ask question show &rest text)
4355 "Call FUNCTION with argument QUESTION; optionally display TEXT... args.
4356 If SHOW is non-nil, the arguments TEXT... are displayed in a temp buffer.
4357 The following arguments may contain lists of values."
4359 (setq text (message-flatten-list text)))
4360 (save-window-excursion
4362 (with-output-to-temp-buffer " *MESSAGE information message*"
4363 (set-buffer " *MESSAGE information message*")
4364 (mapcar 'princ text)
4365 (goto-char (point-min))))
4366 (funcall ask question))
4367 (funcall ask question)))
4369 (defun message-flatten-list (list)
4370 "Return a new, flat list that contains all elements of LIST.
4372 \(message-flatten-list '(1 (2 3 (4 5 (6))) 7))
4375 (apply 'append (mapcar 'message-flatten-list list)))
4379 (defun message-generate-new-buffer-clone-locals (name &optional varstr)
4380 "Create and return a buffer with a name based on NAME using generate-new-buffer.
4381 Then clone the local variables and values from the old buffer to the
4382 new one, cloning only the locals having a substring matching the
4384 (let ((oldbuf (current-buffer)))
4386 (set-buffer (generate-new-buffer name))
4387 (message-clone-locals oldbuf)
4390 (defun message-clone-locals (buffer)
4391 "Clone the local variables from BUFFER to the current buffer."
4392 (let ((locals (save-excursion
4394 (buffer-local-variables)))
4395 (regexp "^gnus\\|^nn\\|^message"))
4398 (when (and (consp local)
4400 (string-match regexp (symbol-name (car local))))
4402 (set (make-local-variable (car local))
4407 ;;; @ for MIME Edit mode
4410 (defun message-maybe-setup-default-charset ()
4412 (and (boundp 'gnus-summary-buffer)
4413 (buffer-live-p gnus-summary-buffer)
4415 (set-buffer gnus-summary-buffer)
4416 default-mime-charset))))
4419 (make-local-variable 'default-mime-charset)
4420 (setq default-mime-charset charset)
4423 (defun message-maybe-encode ()
4424 (when message-mime-mode
4425 (run-hooks 'mime-edit-translate-hook)
4426 (if (catch 'mime-edit-error
4428 (mime-edit-translate-body)
4430 (error "Translation error!")
4433 (run-hooks 'mime-edit-exit-hook)
4436 ;;; XXX: currently broken; message-yank-original resets message-reply-buffer.
4437 (defun message-mime-insert-article (&optional message)
4439 (let ((message-cite-function 'mime-edit-inserted-message-filter)
4440 (message-reply-buffer gnus-original-article-buffer)
4442 (message-yank-original nil)
4445 (set-alist 'mime-edit-message-inserter-alist
4446 'message-mode (function message-mime-insert-article))
4448 ;;; Miscellaneous functions
4450 ;; stolen (and renamed) from nnheader.el
4451 (defun message-replace-chars-in-string (string from to)
4452 "Replace characters in STRING from FROM to TO."
4453 (let ((string (substring string 0)) ;Copy string.
4454 (len (length string))
4456 ;; Replace all occurrences of FROM with TO.
4458 (when (= (aref string idx) from)
4459 (aset string idx to))
4460 (setq idx (1+ idx)))
4463 (run-hooks 'message-load-hook)
4467 ;;; message.el ends here