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 ;; Keywords: mail, news, MIME
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
28 ;; This mode provides mail-sending facilities from within Emacs. It
29 ;; consists mainly of large chunks of code from the sendmail.el,
30 ;; gnus-msg.el and rnewspost.el files.
44 (if (string-match "XEmacs\\|Lucid" emacs-version)
45 (require 'mail-abbrevs)
46 (require 'mailabbrev))
49 (defgroup message '((user-mail-address custom-variable)
50 (user-full-name custom-variable))
51 "Mail and news message composing."
52 :link '(custom-manual "(message)Top")
56 (put 'user-mail-address 'custom-type 'string)
57 (put 'user-full-name 'custom-type 'string)
59 (defgroup message-various nil
60 "Various Message Variables"
61 :link '(custom-manual "(message)Various Message Variables")
64 (defgroup message-buffers nil
66 :link '(custom-manual "(message)Message Buffers")
69 (defgroup message-sending nil
71 :link '(custom-manual "(message)Sending Variables")
74 (defgroup message-interface nil
76 :link '(custom-manual "(message)Interface")
79 (defgroup message-forwarding nil
81 :link '(custom-manual "(message)Forwarding")
82 :group 'message-interface)
84 (defgroup message-insertion nil
86 :link '(custom-manual "(message)Insertion")
89 (defgroup message-headers nil
91 :link '(custom-manual "(message)Message Headers")
94 (defgroup message-news nil
95 "Composing News Messages"
98 (defgroup message-mail nil
99 "Composing Mail Messages"
102 (defgroup message-faces nil
103 "Faces used for message composing."
107 (defcustom message-directory "~/Mail/"
108 "*Directory from which all other mail file variables are derived."
109 :group 'message-various
112 (defcustom message-max-buffers 10
113 "*How many buffers to keep before starting to kill them off."
114 :group 'message-buffers
117 (defcustom message-send-rename-function nil
118 "Function called to rename the buffer after sending it."
119 :group 'message-buffers
122 (defcustom message-fcc-handler-function 'message-output
123 "*A function called to save outgoing articles.
124 This function will be called with the name of the file to store the
125 article in. The default function is `message-output' which saves in Unix
127 :type '(radio (function-item message-output)
128 (function :tag "Other"))
129 :group 'message-sending)
131 (defcustom message-encode-function 'message-maybe-encode
132 "*A function called to encode messages."
133 :group 'message-sending
136 (defcustom message-courtesy-message
137 "The following message is a courtesy copy of an article\nthat has been posted to %s as well.\n\n"
138 "*This is inserted at the start of a mailed copy of a posted message.
139 If the string contains the format spec \"%s\", the Newsgroups
140 the article has been posted to will be inserted there.
141 If this variable is nil, no such courtesy message will be added."
142 :group 'message-sending
145 (defcustom message-ignored-bounced-headers "^\\(Received\\|Return-Path\\):"
146 "*Regexp that matches headers to be removed in resent bounced mail."
147 :group 'message-interface
151 (defcustom message-from-style 'default
152 "*Specifies how \"From\" headers look.
154 If `nil', they contain just the return address like:
156 If `parens', they look like:
157 king@grassland.com (Elvis Parsley)
158 If `angles', they look like:
159 Elvis Parsley <king@grassland.com>
161 Otherwise, most addresses look like `angles', but they look like
162 `parens' if `angles' would need quoting and `parens' would not."
163 :type '(choice (const :tag "simple" nil)
167 :group 'message-headers)
169 (defcustom message-syntax-checks nil
170 ; Guess this one shouldn't be easy to customize...
171 "*Controls what syntax checks should not be performed on outgoing posts.
172 To disable checking of long signatures, for instance, add
173 `(signature . disabled)' to this list.
175 Don't touch this variable unless you really know what you're doing.
177 Checks include subject-cmsg multiple-headers sendsys message-id from
178 long-lines control-chars size new-text redirected-followup signature
179 approved sender empty empty-headers message-id from subject
180 shorten-followup-to existing-newsgroups buffer-file-name unchanged."
181 :group 'message-news)
183 (defcustom message-required-news-headers
184 '(From Newsgroups Subject Date Message-ID
185 (optional . Organization) Lines
186 (optional . User-Agent))
187 "*Headers to be generated or prompted for when posting an article.
188 RFC977 and RFC1036 require From, Date, Newsgroups, Subject,
189 Message-ID. Organization, Lines, In-Reply-To, Expires, and
190 User-Agent are optional. If don't you want message to insert some
191 header, remove it from this list."
193 :group 'message-headers
194 :type '(repeat sexp))
196 (defcustom message-required-mail-headers
197 '(From Subject Date (optional . In-Reply-To) Message-ID Lines
198 (optional . User-Agent))
199 "*Headers to be generated or prompted for when mailing a message.
200 RFC822 required that From, Date, To, Subject and Message-ID be
201 included. Organization, Lines and User-Agent are optional."
203 :group 'message-headers
204 :type '(repeat sexp))
206 (defcustom message-deletable-headers '(Message-ID Date Lines)
207 "Headers to be deleted if they already exist and were generated by message previously."
208 :group 'message-headers
211 (defcustom message-ignored-news-headers
212 "^NNTP-Posting-Host:\\|^Xref:\\|^[BGF]cc:\\|^Resent-Fcc:"
213 "*Regexp of headers to be removed unconditionally before posting."
215 :group 'message-headers
218 (defcustom message-ignored-mail-headers "^[GF]cc:\\|^Resent-Fcc:\\|^Xref:"
219 "*Regexp of headers to be removed unconditionally before mailing."
221 :group 'message-headers
224 (defcustom message-ignored-supersedes-headers "^Path:\\|^Date\\|^NNTP-Posting-Host:\\|^Xref:\\|^Lines:\\|^Received:\\|^X-From-Line:\\|^X-Trace:\\|^X-Complaints-To:\\|Return-Path:\\|^Supersedes:"
225 "*Header lines matching this regexp will be deleted before posting.
226 It's best to delete old Path and Date headers before posting to avoid
228 :group 'message-interface
231 (defcustom message-subject-re-regexp "^[ \t]*\\([Rr][Ee]:[ \t]*\\)*[ \t]*"
232 "*Regexp matching \"Re: \" in the subject line."
233 :group 'message-various
236 ;;; Some sender agents encode the whole subject including leading "Re: ".
237 ;;; And if followup agent does not decode it for some reason (e.g. unknown
238 ;;; charset) and just add a new "Re: " in front of the encoded-word, the
239 ;;; result will contain multiple "Re: "'s.
240 (defcustom message-subject-encoded-re-regexp
244 "[-!#$%&'*+0-9A-Z^_`a-z{|}~]+" ; charset
247 "[Bb]" (regexp-quote "?") ; B encoding
248 "\\(\\(CQk\\|CSA\\|IAk\\|ICA\\)[Jg]\\)*" ; \([ \t][ \t][ \t]\)*
250 "[Uc][km]U6" ; [Rr][Ee]:
252 "\\(C[VX]\\|I[FH]\\)J[Fl]O[g-v]" ; [ \t][Rr][Ee]:
254 "\\(CQl\\|CSB\\|IAl\\|ICB\\)[Sy][RZ]T[o-r]" ; [ \t][ \t][Rr][Ee]:
257 "[Qb]" (regexp-quote "?") ; Q encoding
258 "\\(_\\|=09\\|=20\\)*"
259 "\\([Rr]\\|=[57]2\\)\\([Ee]\\|=[46]5\\)\\(:\\|=3[Aa]\\)"
262 "*Regexp matching \"Re: \" in the subject line.
263 Unlike `message-subject-re-regexp', this regexp matches \"Re: \" within
265 :group 'message-various
268 (defcustom message-use-subject-re t
269 "*If t, remove any (buggy) \"Re: \"'s from the subject of the precursor
270 and add a new \"Re: \". If it is nil, use the subject \"as-is\". If it
271 is the symbol `guess', try to detect \"Re: \" within an encoded-word."
272 :group 'message-various
273 :type '(choice (const :tag "off" nil)
278 (defcustom message-signature-separator "^-- *$"
279 "Regexp matching the signature separator."
281 :group 'message-various)
283 (defcustom message-elide-elipsis "\n[...]\n\n"
284 "*The string which is inserted for elided text."
286 :group 'message-various)
288 (defcustom message-interactive nil
289 "Non-nil means when sending a message wait for and display errors.
290 nil means let mailer mail back a message to report errors."
291 :group 'message-sending
295 (defcustom message-generate-new-buffers t
296 "*Non-nil means that a new message buffer will be created whenever `message-setup' is called.
297 If this is a function, call that function with three parameters: The type,
298 the to address and the group name. (Any of these may be nil.) The function
299 should return the new buffer name."
300 :group 'message-buffers
301 :type '(choice (const :tag "off" nil)
305 (defcustom message-kill-buffer-on-exit nil
306 "*Non-nil means that the message buffer will be killed after sending a message."
307 :group 'message-buffers
310 (defvar gnus-local-organization)
311 (defcustom message-user-organization
312 (or (and (boundp 'gnus-local-organization)
313 (stringp gnus-local-organization)
314 gnus-local-organization)
315 (getenv "ORGANIZATION")
317 "*String to be used as an Organization header.
318 If t, use `message-user-organization-file'."
319 :group 'message-headers
320 :type '(choice string
321 (const :tag "consult file" t)))
324 (defcustom message-user-organization-file "/usr/lib/news/organization"
325 "*Local news organization file."
327 :group 'message-headers)
329 (defcustom message-forward-start-separator
330 (concat (mime-make-tag "message" "rfc822") "\n")
331 "*Delimiter inserted before forwarded messages."
332 :group 'message-forwarding
335 (defcustom message-forward-end-separator
337 "*Delimiter inserted after forwarded messages."
338 :group 'message-forwarding
341 (defcustom message-signature-before-forwarded-message t
342 "*If non-nil, put the signature before any included forwarded message."
343 :group 'message-forwarding
346 (defcustom message-included-forward-headers
347 "^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:"
348 "*Regexp matching headers to be included in forwarded messages."
349 :group 'message-forwarding
352 (defcustom message-ignored-resent-headers "^Return-Receipt"
353 "*All headers that match this regexp will be deleted when resending a message."
354 :group 'message-interface
357 (defcustom message-ignored-cited-headers "."
358 "*Delete these headers from the messages you yank."
359 :group 'message-insertion
362 (defcustom message-cancel-message "I am canceling my own article."
363 "Message to be inserted in the cancel message."
364 :group 'message-interface
367 ;; Useful to set in site-init.el
369 (defcustom message-send-mail-function 'message-send-mail-with-sendmail
370 "Function to call to send the current buffer as mail.
371 The headers should be delimited by a line whose contents match the
372 variable `mail-header-separator'.
374 Legal values include `message-send-mail-with-sendmail' (the default),
375 `message-send-mail-with-mh', `message-send-mail-with-qmail' and
376 `message-send-mail-with-smtp'."
377 :type '(radio (function-item message-send-mail-with-sendmail)
378 (function-item message-send-mail-with-mh)
379 (function-item message-send-mail-with-qmail)
380 (function-item message-send-mail-with-smtp)
381 (function :tag "Other"))
382 :group 'message-sending
383 :group 'message-mail)
385 ;; 1997-09-29 by MORIOKA Tomohiko
386 (defcustom message-send-news-function 'message-send-news-with-gnus
387 "Function to call to send the current buffer as news.
388 The headers should be delimited by a line whose contents match the
389 variable `mail-header-separator'."
390 :group 'message-sending
394 (defcustom message-reply-to-function nil
395 "Function that should return a list of headers.
396 This function should pick out addresses from the To, Cc, and From headers
397 and respond with new To and Cc headers."
398 :group 'message-interface
401 (defcustom message-wide-reply-to-function nil
402 "Function that should return a list of headers.
403 This function should pick out addresses from the To, Cc, and From headers
404 and respond with new To and Cc headers."
405 :group 'message-interface
408 (defcustom message-followup-to-function nil
409 "Function that should return a list of headers.
410 This function should pick out addresses from the To, Cc, and From headers
411 and respond with new To and Cc headers."
412 :group 'message-interface
415 (defcustom message-use-followup-to 'ask
416 "*Specifies what to do with Followup-To header.
417 If nil, always ignore the header. If it is t, use its value, but
418 query before using the \"poster\" value. If it is the symbol `ask',
419 always query the user whether to use the value. If it is the symbol
420 `use', always use the value."
421 :group 'message-interface
422 :type '(choice (const :tag "ignore" nil)
423 (const :tag "maybe" t)
424 (const :tag "always" use)
425 (const :tag "ask" ask)))
427 (defcustom message-use-mail-copies-to 'ask
428 "*Specifies what to do with Mail-Copies-To header.
429 If nil, always ignore the header. If it is t, use its value, but
430 query before using the value other than \"always\" or \"never\".
431 If it is the symbol `ask', always query the user whether to use
432 the value. If it is the symbol `use', always use the value."
433 :group 'message-interface
434 :type '(choice (const :tag "ignore" nil)
435 (const :tag "maybe" t)
436 (const :tag "always" use)
437 (const :tag "ask" ask)))
439 (defcustom message-use-mail-followup-to 'ask
440 "*Specifies what to do with Mail-Followup-To header.
441 If nil, always ignore the header. If it is the symbol `ask', always
442 query the user whether to use the value. If it is t or the symbol
443 `use', always use the value."
444 :group 'message-interface
445 :type '(choice (const :tag "ignore" nil)
446 (const :tag "maybe" t)
447 (const :tag "always" use)
448 (const :tag "ask" ask)))
450 ;;; XXX: 'ask and 'use are not implemented yet.
451 (defcustom message-use-mail-reply-to 'ask
452 "*Specifies what to do with Mail-Reply-To/Reply-To header.
453 If nil, always ignore the header. If it is t or the symbol `use', use
454 its value. If it is the symbol `ask', always query the user whether to
455 use the value. Not that if \"Reply-To\" is marked as \"broken\", its value
457 :group 'message-interface
458 :type '(choice (const :tag "ignore" nil)
459 (const :tag "maybe" t)
460 (const :tag "always" use)
461 (const :tag "ask" ask)))
463 ;; stuff relating to broken sendmail in MMDF
464 (defcustom message-sendmail-f-is-evil nil
465 "*Non-nil means that \"-f username\" should not be added to the sendmail
466 command line, because it is even more evil than leaving it out."
467 :group 'message-sending
470 ;; qmail-related stuff
471 (defcustom message-qmail-inject-program "/var/qmail/bin/qmail-inject"
472 "Location of the qmail-inject program."
473 :group 'message-sending
476 (defcustom message-qmail-inject-args nil
477 "Arguments passed to qmail-inject programs.
478 This should be a list of strings, one string for each argument.
480 For e.g., if you wish to set the envelope sender address so that bounces
481 go to the right place or to deal with listserv's usage of that address, you
482 might set this variable to '(\"-f\" \"you@some.where\")."
483 :group 'message-sending
484 :type '(repeat string))
486 (defvar gnus-post-method)
487 (defvar gnus-select-method)
488 (defcustom message-post-method
489 (cond ((and (boundp 'gnus-post-method)
492 ((boundp 'gnus-select-method)
495 "*Method used to post news.
496 Note that when posting from inside Gnus, for instance, this
497 variable isn't used."
499 :group 'message-sending
500 ;; This should be the `gnus-select-method' widget, but that might
501 ;; create a dependence to `gnus.el'.
504 (defcustom message-generate-headers-first nil
505 "*If non-nil, generate all possible headers before composing."
506 :group 'message-headers
509 (defcustom message-setup-hook
510 '(message-maybe-setup-default-charset turn-on-mime-edit)
511 "Normal hook, run each time a new outgoing message is initialized.
512 The function `message-setup' runs this hook."
513 :group 'message-various
516 (defcustom message-signature-setup-hook nil
517 "Normal hook, run each time a new outgoing message is initialized.
518 It is run after the headers have been inserted and before
519 the signature is inserted."
520 :group 'message-various
523 (defcustom message-mode-hook nil
524 "Hook run in message mode buffers."
525 :group 'message-various
528 (defcustom message-header-hook '(eword-encode-header)
529 "Hook run in a message mode buffer narrowed to the headers."
530 :group 'message-various
533 (defcustom message-header-setup-hook nil
534 "Hook called narrowed to the headers when setting up a message buffer."
535 :group 'message-various
539 (defcustom message-citation-line-function 'message-insert-citation-line
540 "*Function called to insert the \"Whomever writes:\" line."
542 :group 'message-insertion)
545 (defcustom message-yank-prefix "> "
546 "*Prefix inserted on the lines of yanked messages.
547 nil means use indentation."
549 :group 'message-insertion)
551 (defcustom message-indentation-spaces 3
552 "*Number of spaces to insert at the beginning of each cited line.
553 Used by `message-yank-original' via `message-yank-cite'."
554 :group 'message-insertion
558 (defcustom message-cite-function 'message-cite-original
559 "*Function for citing an original message.
560 Predefined functions include `message-cite-original' and
561 `message-cite-original-without-signature'.
562 Note that `message-cite-original' uses `mail-citation-hook' if that is non-nil."
563 :type '(radio (function-item message-cite-original)
564 (function-item sc-cite-original)
565 (function :tag "Other"))
566 :group 'message-insertion)
569 (defcustom message-indent-citation-function 'message-indent-citation
570 "*Function for modifying a citation just inserted in the mail buffer.
571 This can also be a list of functions. Each function can find the
572 citation between (point) and (mark t). And each function should leave
573 point and mark around the citation text as modified."
575 :group 'message-insertion)
577 (defvar message-abbrevs-loaded nil)
580 (defcustom message-signature t
581 "*String to be inserted at the end of the message buffer.
582 If t, the `message-signature-file' file will be inserted instead.
583 If a function, the result from the function will be used instead.
584 If a form, the result from the form will be used instead."
586 :group 'message-insertion)
589 (defcustom message-signature-file "~/.signature"
590 "*File containing the text inserted at end of message buffer."
592 :group 'message-insertion)
594 (defcustom message-distribution-function nil
595 "*Function called to return a Distribution header."
597 :group 'message-headers
600 (defcustom message-expires 14
601 "Number of days before your article expires."
603 :group 'message-headers
604 :link '(custom-manual "(message)News Headers")
607 (defcustom message-user-path nil
608 "If nil, use the NNTP server name in the Path header.
609 If stringp, use this; if non-nil, use no host name (user name only)."
611 :group 'message-headers
612 :link '(custom-manual "(message)News Headers")
613 :type '(choice (const :tag "nntp" nil)
615 (sexp :tag "none" :format "%t" t)))
617 (defvar message-reply-buffer nil)
618 (defvar message-reply-headers nil)
619 (defvar message-sent-message-via nil)
620 (defvar message-checksum nil)
621 (defvar message-send-actions nil
622 "A list of actions to be performed upon successful sending of a message.")
623 (defvar message-exit-actions nil
624 "A list of actions to be performed upon exiting after sending a message.")
625 (defvar message-kill-actions nil
626 "A list of actions to be performed before killing a message buffer.")
627 (defvar message-postpone-actions nil
628 "A list of actions to be performed after postponing a message.")
630 (define-widget 'message-header-lines 'text
631 "All header lines must be LFD terminated."
634 :error "All header lines must be newline terminated")
636 (defcustom message-default-headers ""
637 "*A string containing header lines to be inserted in outgoing messages.
638 It is inserted before you edit the message, so you can edit or delete
640 :group 'message-headers
641 :type 'message-header-lines)
643 (defcustom message-default-mail-headers ""
644 "*A string of header lines to be inserted in outgoing mails."
645 :group 'message-headers
647 :type 'message-header-lines)
649 (defcustom message-default-news-headers ""
650 "*A string of header lines to be inserted in outgoing news
652 :group 'message-headers
654 :type 'message-header-lines)
656 ;; Note: could use /usr/ucb/mail instead of sendmail;
657 ;; options -t, and -v if not interactive.
658 (defcustom message-mailer-swallows-blank-line
659 (if (and (string-match "sparc-sun-sunos\\(\\'\\|[^5]\\)"
660 system-configuration)
661 (file-readable-p "/etc/sendmail.cf")
662 (let ((buffer (get-buffer-create " *temp*")))
666 (insert-file-contents "/etc/sendmail.cf")
667 (goto-char (point-min))
668 (let ((case-fold-search nil))
669 (re-search-forward "^OR\\>" nil t)))
670 (kill-buffer buffer))))
671 ;; According to RFC822, "The field-name must be composed of printable
672 ;; ASCII characters (i. e., characters that have decimal values between
673 ;; 33 and 126, except colon)", i. e., any chars except ctl chars,
675 '(looking-at "[ \t]\\|[][!\"#$%&'()*+,-./0-9;<=>?@A-Z\\\\^_`a-z{|}~]+:"))
676 "*Set this non-nil if the system's mailer runs the header and body together.
677 \(This problem exists on Sunos 4 when sendmail is run in remote mode.)
678 The value should be an expression to test whether the problem will
680 :group 'message-sending
683 ;;; XXX: This symbol is overloaded! See below.
684 (defvar message-user-agent nil
685 "String of the form of PRODUCT/VERSION. Used for User-Agent header field.")
687 ;; Ignore errors in case this is used in Emacs 19.
688 ;; Don't use ignore-errors because this is copied into loaddefs.el.
691 (define-mail-user-agent 'message-user-agent
692 'message-mail 'message-send-and-exit
693 'message-kill-buffer 'message-send-hook)
696 (defvar message-mh-deletable-headers '(Message-ID Date Lines Sender)
697 "If non-nil, delete the deletable headers before feeding to mh.")
699 (defvar message-send-method-alist
700 '((news message-news-p message-send-via-news)
701 (mail message-mail-p message-send-via-mail))
702 "Alist of ways to send outgoing messages.
703 Each element has the form
705 \(TYPE PREDICATE FUNCTION)
707 where TYPE is a symbol that names the method; PREDICATE is a function
708 called without any parameters to determine whether the message is
709 a message of type TYPE; and FUNCTION is a function to be called if
710 PREDICATE returns non-nil. FUNCTION is called with one parameter --
713 (defvar message-mail-alias-type 'abbrev
714 "*What alias expansion type to use in Message buffers.
715 The default is `abbrev', which uses mailabbrev. nil switches
718 (defcustom message-autosave-directory
719 (nnheader-concat message-directory "drafts/")
720 "*Directory where Message autosaves buffers if Gnus isn't running.
721 If nil, Message won't autosave."
722 :group 'message-buffers
725 ;;; Internal variables.
726 ;;; Well, not really internal.
728 (defvar message-mode-syntax-table
729 (let ((table (copy-syntax-table text-mode-syntax-table)))
730 (modify-syntax-entry ?% ". " table)
732 "Syntax table used while in Message mode.")
734 (defvar message-mode-abbrev-table text-mode-abbrev-table
735 "Abbrev table used in Message mode buffers.
736 Defaults to `text-mode-abbrev-table'.")
737 (defgroup message-headers nil
739 :link '(custom-manual "(message)Variables")
742 (defface message-header-to-face
745 (:foreground "green2" :bold t))
748 (:foreground "MidnightBlue" :bold t))
750 (:bold t :italic t)))
751 "Face used for displaying From headers."
752 :group 'message-faces)
754 (defface message-header-cc-face
757 (:foreground "green4" :bold t))
760 (:foreground "MidnightBlue"))
763 "Face used for displaying Cc headers."
764 :group 'message-faces)
766 (defface message-header-subject-face
769 (:foreground "green3"))
772 (:foreground "navy blue" :bold t))
775 "Face used for displaying subject headers."
776 :group 'message-faces)
778 (defface message-header-newsgroups-face
781 (:foreground "yellow" :bold t :italic t))
784 (:foreground "blue4" :bold t :italic t))
786 (:bold t :italic t)))
787 "Face used for displaying newsgroups headers."
788 :group 'message-faces)
790 (defface message-header-other-face
793 (:foreground "#b00000"))
796 (:foreground "steel blue"))
798 (:bold t :italic t)))
799 "Face used for displaying newsgroups headers."
800 :group 'message-faces)
802 (defface message-header-name-face
805 (:foreground "DarkGreen"))
808 (:foreground "cornflower blue"))
811 "Face used for displaying header names."
812 :group 'message-faces)
814 (defface message-header-xheader-face
817 (:foreground "blue"))
820 (:foreground "blue"))
823 "Face used for displaying X-Header headers."
824 :group 'message-faces)
826 (defface message-separator-face
829 (:foreground "blue3"))
832 (:foreground "brown"))
835 "Face used for displaying the separator."
836 :group 'message-faces)
838 (defface message-cited-text-face
847 "Face used for displaying cited text names."
848 :group 'message-faces)
850 (defvar message-font-lock-keywords
851 (let* ((cite-prefix "A-Za-z")
852 (cite-suffix (concat cite-prefix "0-9_.@-"))
853 (content "[ \t]*\\(.+\\(\n[ \t].*\\)*\\)"))
854 `((,(concat "^\\([Tt]o:\\)" content)
855 (1 'message-header-name-face)
856 (2 'message-header-to-face nil t))
857 (,(concat "^\\([GBF]?[Cc][Cc]:\\|[Rr]eply-[Tt]o:\\|"
858 "[Mm]ail-[Cc]opies-[Tt]o:\\|"
859 "[Mm]ail-[Rr]eply-[Tt]o:\\|"
860 "[Mm]ail-[Ff]ollowup-[Tt]o:\\)" content)
861 (1 'message-header-name-face)
862 (2 'message-header-cc-face nil t))
863 (,(concat "^\\([Ss]ubject:\\)" content)
864 (1 'message-header-name-face)
865 (2 'message-header-subject-face nil t))
866 (,(concat "^\\([Nn]ewsgroups:\\|Followup-[Tt]o:\\)" content)
867 (1 'message-header-name-face)
868 (2 'message-header-newsgroups-face nil t))
869 (,(concat "^\\([A-Z][^: \n\t]+:\\)" content)
870 (1 'message-header-name-face)
871 (2 'message-header-other-face nil t))
872 (,(concat "^\\(X-[A-Za-z0-9-]+\\|In-Reply-To\\):" content)
873 (1 'message-header-name-face)
874 (2 'message-header-name-face))
875 ,@(if (and mail-header-separator
876 (not (equal mail-header-separator "")))
877 `((,(concat "^\\(" (regexp-quote mail-header-separator) "\\)$")
878 1 'message-separator-face))
881 "\\([" cite-prefix "]+[" cite-suffix "]*\\)?"
883 (0 'message-cited-text-face))))
884 "Additional expressions to highlight in Message mode.")
886 ;; XEmacs does it like this. For Emacs, we have to set the
887 ;; `font-lock-defaults' buffer-local variable.
888 (put 'message-mode 'font-lock-defaults '(message-font-lock-keywords t))
890 (defvar message-face-alist
891 '((bold . bold-region)
892 (underline . underline-region)
893 (default . (lambda (b e)
895 (ununderline-region b e))))
896 "Alist of mail and news faces for facemenu.
897 The cdr of ech entry is a function for applying the face to a region.")
899 (defcustom message-send-hook nil
900 "Hook run before sending messages."
901 :group 'message-various
902 :options '(ispell-message)
905 (defcustom message-send-mail-hook nil
906 "Hook run before sending mail messages."
907 :group 'message-various
910 (defcustom message-send-news-hook nil
911 "Hook run before sending news messages."
912 :group 'message-various
915 (defcustom message-sent-hook nil
916 "Hook run after sending messages."
917 :group 'message-various
920 ;;; Internal variables.
922 (defvar message-buffer-list nil)
923 (defvar message-this-is-news nil)
924 (defvar message-this-is-mail nil)
925 (defvar message-draft-article nil)
927 ;; Byte-compiler warning
928 (defvar gnus-active-hashtb)
929 (defvar gnus-read-active-file)
931 ;;; Regexp matching the delimiter of messages in UNIX mail format
932 ;;; (UNIX From lines), minus the initial ^. It should be a copy
933 ;;; of rmail.el's rmail-unix-mail-delimiter.
934 (defvar message-unix-mail-delimiter
935 (let ((time-zone-regexp
936 (concat "\\([A-Z]?[A-Z]?[A-Z][A-Z]\\( DST\\)?"
937 "\\|[-+]?[0-9][0-9][0-9][0-9]"
943 ;; Many things can happen to an RFC 822 mailbox before it is put into
944 ;; a `From' line. The leading phrase can be stripped, e.g.
945 ;; `Joe <@w.x:joe@y.z>' -> `<@w.x:joe@y.z>'. The <> can be stripped, e.g.
946 ;; `<@x.y:joe@y.z>' -> `@x.y:joe@y.z'. Everything starting with a CRLF
947 ;; can be removed, e.g.
948 ;; From: joe@y.z (Joe K
950 ;; can yield `From joe@y.z (Joe K Fri Mar 22 08:11:15 1996', and
953 ;; can yield `From Joe User Fri Mar 22 08:11:15 1996'.
954 ;; The mailbox can be removed or be replaced by white space, e.g.
955 ;; From: "Joe User"{space}{tab}
957 ;; can yield `From {space}{tab} Fri Mar 22 08:11:15 1996',
958 ;; where {space} and {tab} represent the Ascii space and tab characters.
959 ;; We want to match the results of any of these manglings.
960 ;; The following regexp rejects names whose first characters are
961 ;; obviously bogus, but after that anything goes.
962 "\\([^\0-\b\n-\r\^?].*\\)? "
964 ;; The time the message was sent.
965 "\\([^\0-\r \^?]+\\) +" ; day of the week
966 "\\([^\0-\r \^?]+\\) +" ; month
967 "\\([0-3]?[0-9]\\) +" ; day of month
968 "\\([0-2][0-9]:[0-5][0-9]\\(:[0-6][0-9]\\)?\\) *" ; time of day
970 ;; Perhaps a time zone, specified by an abbreviation, or by a
975 " \\([0-9][0-9]+\\) *"
977 ;; On some systems the time zone can appear after the year, too.
981 "\\(remote from .*\\)?"
984 "Regexp matching the delimiter of messages in UNIX mail format.")
986 (defvar message-unsent-separator
987 (concat "^ *---+ +Unsent message follows +---+ *$\\|"
988 "^ *---+ +Returned message +---+ *$\\|"
989 "^Start of returned message$\\|"
990 "^ *---+ +Original message +---+ *$\\|"
991 "^ *--+ +begin message +--+ *$\\|"
992 "^ *---+ +Original message follows +---+ *$\\|"
993 "^|? *---+ +Message text follows: +---+ *|?$")
994 "A regexp that matches the separator before the text of a failed message.")
996 (defvar message-header-format-alist
998 (To . message-fill-address)
999 (Cc . message-fill-address)
1010 ;; (References . message-shorten-references)
1011 (References . message-fill-header)
1013 "Alist used for formatting headers.")
1016 (autoload 'message-setup-toolbar "messagexmas")
1017 (autoload 'mh-new-draft-name "mh-comp")
1018 (autoload 'mh-send-letter "mh-comp")
1019 (autoload 'gnus-point-at-eol "gnus-util")
1020 (autoload 'gnus-point-at-bol "gnus-util")
1021 (autoload 'gnus-output-to-mail "gnus-util")
1022 (autoload 'gnus-output-to-rmail "gnus-util")
1023 (autoload 'mail-abbrev-in-expansion-header-p "mailabbrev")
1024 (autoload 'nndraft-request-associate-buffer "nndraft")
1025 (autoload 'nndraft-request-expire-articles "nndraft")
1026 (autoload 'gnus-open-server "gnus-int")
1027 (autoload 'gnus-request-post "gnus-int")
1028 (autoload 'gnus-alive-p "gnus-util")
1029 (autoload 'rmail-output "rmail"))
1034 ;;; Utility functions.
1037 (defmacro message-y-or-n-p (question show &rest text)
1038 "Ask QUESTION, displaying the rest of the arguments in a temp. buffer if SHOW"
1039 `(message-talkative-question 'y-or-n-p ,question ,show ,@text))
1041 ;; Delete the current line (and the next N lines.);
1042 (defmacro message-delete-line (&optional n)
1043 `(delete-region (progn (beginning-of-line) (point))
1044 (progn (forward-line ,(or n 1)) (point))))
1046 (defun message-tokenize-header (header &optional separator)
1047 "Split HEADER into a list of header elements.
1048 \",\" is used as the separator."
1051 (let ((regexp (format "[%s]+" (or separator ",")))
1056 (message-set-work-buffer)
1058 (goto-char (point-min))
1063 (cond ((and (> (point) beg)
1065 (and (looking-at regexp)
1068 (push (buffer-substring beg (point)) elems)
1069 (setq beg (match-end 0)))
1070 ((= (following-char) ?\")
1071 (setq quoted (not quoted)))
1072 ((and (= (following-char) ?\()
1075 ((and (= (following-char) ?\))
1078 (nreverse elems)))))
1080 (defun message-mail-file-mbox-p (file)
1081 "Say whether FILE looks like a Unix mbox file."
1082 (when (and (file-exists-p file)
1083 (file-readable-p file)
1084 (file-regular-p file))
1085 (nnheader-temp-write nil
1086 (nnheader-insert-file-contents file)
1087 (goto-char (point-min))
1088 (looking-at message-unix-mail-delimiter))))
1090 (defun message-fetch-field (header &optional not-all)
1091 "The same as `mail-fetch-field', only remove all newlines."
1092 (let* ((inhibit-point-motion-hooks t)
1093 (value (mail-fetch-field header nil (not not-all))))
1095 (nnheader-replace-chars-in-string value ?\n ? ))))
1097 (defun message-add-header (&rest headers)
1098 "Add the HEADERS to the message header, skipping those already present."
1101 (unless (string-match "^\\([^:]+\\):[ \t]*[^ \t]" (car headers))
1102 (error "Invalid header `%s'" (car headers)))
1103 (setq hclean (match-string 1 (car headers)))
1105 (message-narrow-to-headers)
1106 (unless (re-search-forward (concat "^" (regexp-quote hclean) ":") nil t)
1107 (insert (car headers) ?\n))))
1108 (setq headers (cdr headers))))
1110 (defun message-fetch-reply-field (header)
1111 "Fetch FIELD from the message we're replying to."
1112 (when (and message-reply-buffer
1113 (buffer-name message-reply-buffer))
1115 (set-buffer message-reply-buffer)
1116 (message-fetch-field header))))
1118 (defun message-set-work-buffer ()
1119 (if (get-buffer " *message work*")
1121 (set-buffer " *message work*")
1123 (set-buffer (get-buffer-create " *message work*"))
1124 (kill-all-local-variables)
1125 (buffer-disable-undo (current-buffer))))
1127 (defun message-functionp (form)
1128 "Return non-nil if FORM is funcallable."
1129 (or (and (symbolp form) (fboundp form))
1130 (and (listp form) (eq (car form) 'lambda))
1131 (byte-code-function-p form)))
1133 (defun message-strip-subject-re (subject)
1134 "Remove \"Re:\" from subject lines."
1135 (if (string-match message-subject-re-regexp subject)
1136 (substring subject (match-end 0))
1139 (defun message-remove-header (header &optional is-regexp first reverse)
1140 "Remove HEADER in the narrowed buffer.
1141 If REGEXP, HEADER is a regular expression.
1142 If FIRST, only remove the first instance of the header.
1143 Return the number of headers removed."
1144 (goto-char (point-min))
1145 (let ((regexp (if is-regexp header (concat "^" (regexp-quote header) ":")))
1147 (case-fold-search t)
1149 (while (and (not (eobp))
1152 (not (looking-at regexp))
1153 (looking-at regexp))
1160 ;; There might be a continuation header, so we have to search
1161 ;; until we find a new non-continuation line.
1164 (if (re-search-forward "^[^ \t]" nil t)
1165 (goto-char (match-beginning 0))
1168 (if (re-search-forward "^[^ \t]" nil t)
1169 (goto-char (match-beginning 0))
1173 (defun message-narrow-to-headers ()
1174 "Narrow the buffer to the head of the message."
1177 (goto-char (point-min))
1178 (if (re-search-forward
1179 (concat "^" (regexp-quote mail-header-separator) "\n") nil t)
1182 (goto-char (point-min)))
1184 (defun message-narrow-to-head ()
1185 "Narrow the buffer to the head of the message."
1188 (goto-char (point-min))
1189 (if (search-forward "\n\n" nil 1)
1192 (goto-char (point-min)))
1194 (defun message-news-p ()
1195 "Say whether the current buffer contains a news message."
1196 (and (not message-this-is-mail)
1197 (or message-this-is-news
1200 (message-narrow-to-headers)
1201 (and (message-fetch-field "newsgroups")
1202 (not (message-fetch-field "posted-to"))))))))
1204 (defun message-mail-p ()
1205 "Say whether the current buffer contains a mail message."
1206 (and (not message-this-is-news)
1207 (or message-this-is-mail
1210 (message-narrow-to-headers)
1211 (or (message-fetch-field "to")
1212 (message-fetch-field "cc")
1213 (message-fetch-field "bcc")))))))
1215 (defun message-next-header ()
1216 "Go to the beginning of the next header."
1218 (or (eobp) (forward-char 1))
1219 (not (if (re-search-forward "^[^ \t]" nil t)
1221 (goto-char (point-max)))))
1223 (defun message-sort-headers-1 ()
1224 "Sort the buffer as headers using `message-rank' text props."
1225 (goto-char (point-min))
1227 nil 'message-next-header
1229 (message-next-header)
1233 (or (get-text-property (point) 'message-rank)
1236 (defun message-sort-headers ()
1237 "Sort the headers of the current message according to `message-header-format-alist'."
1241 (let ((max (1+ (length message-header-format-alist)))
1243 (message-narrow-to-headers)
1244 (while (re-search-forward "^[^ \n]+:" nil t)
1246 (match-beginning 0) (1+ (match-beginning 0))
1248 (if (setq rank (length (memq (assq (intern (buffer-substring
1250 (1- (match-end 0))))
1251 message-header-format-alist)
1252 message-header-format-alist)))
1255 (message-sort-headers-1))))
1265 (defvar message-mode-map nil)
1267 (unless message-mode-map
1268 (setq message-mode-map (copy-keymap text-mode-map))
1269 (define-key message-mode-map "\C-c?" 'describe-mode)
1271 (define-key message-mode-map "\C-c\C-f\C-t" 'message-goto-to)
1272 (define-key message-mode-map "\C-c\C-f\C-b" 'message-goto-bcc)
1273 (define-key message-mode-map "\C-c\C-f\C-w" 'message-goto-fcc)
1274 (define-key message-mode-map "\C-c\C-f\C-c" 'message-goto-cc)
1275 (define-key message-mode-map "\C-c\C-f\C-s" 'message-goto-subject)
1276 ;; (define-key message-mode-map "\C-c\C-f\C-r" 'message-goto-reply-to)
1277 (define-key message-mode-map "\C-c\C-f\C-r" 'message-goto-mail-reply-to)
1278 (define-key message-mode-map "\C-c\C-f\C-m" 'message-goto-mail-followup-to)
1279 (define-key message-mode-map "\C-c\C-f\C-n" 'message-goto-newsgroups)
1280 (define-key message-mode-map "\C-c\C-f\C-d" 'message-goto-distribution)
1281 (define-key message-mode-map "\C-c\C-f\C-f" 'message-goto-followup-to)
1282 (define-key message-mode-map "\C-c\C-f\C-k" 'message-goto-keywords)
1283 (define-key message-mode-map "\C-c\C-f\C-u" 'message-goto-summary)
1284 (define-key message-mode-map "\C-c\C-b" 'message-goto-body)
1285 (define-key message-mode-map "\C-c\C-i" 'message-goto-signature)
1287 (define-key message-mode-map "\C-c\C-t" 'message-insert-to)
1288 (define-key message-mode-map "\C-c\C-n" 'message-insert-newsgroups)
1290 (define-key message-mode-map "\C-c\C-y" 'message-yank-original)
1291 (define-key message-mode-map "\C-c\C-q" 'message-fill-yanked-message)
1292 (define-key message-mode-map "\C-c\C-w" 'message-insert-signature)
1293 (define-key message-mode-map "\C-c\C-r" 'message-caesar-buffer-body)
1294 (define-key message-mode-map "\C-c\C-o" 'message-sort-headers)
1295 (define-key message-mode-map "\C-c\M-r" 'message-rename-buffer)
1297 (define-key message-mode-map "\C-c\C-c" 'message-send-and-exit)
1298 (define-key message-mode-map "\C-c\C-s" 'message-send)
1299 (define-key message-mode-map "\C-c\C-k" 'message-kill-buffer)
1300 (define-key message-mode-map "\C-c\C-d" 'message-dont-send)
1302 (define-key message-mode-map "\C-c\C-e" 'message-elide-region)
1303 (define-key message-mode-map "\C-c\C-v" 'message-delete-not-region)
1304 (define-key message-mode-map "\C-c\C-z" 'message-kill-to-signature)
1305 (define-key message-mode-map "\M-\r" 'message-newline-and-reformat)
1307 (define-key message-mode-map "\t" 'message-tab))
1310 message-mode-menu message-mode-map "Message Menu."
1312 ["Sort Headers" message-sort-headers t]
1313 ["Yank Original" message-yank-original t]
1314 ["Fill Yanked Message" message-fill-yanked-message t]
1315 ["Insert Signature" message-insert-signature t]
1316 ["Caesar (rot13) Message" message-caesar-buffer-body t]
1317 ["Caesar (rot13) Region" message-caesar-region (mark t)]
1318 ["Elide Region" message-elide-region (mark t)]
1319 ["Delete Outside Region" message-delete-not-region (mark t)]
1320 ["Kill To Signature" message-kill-to-signature t]
1321 ["Newline and Reformat" message-newline-and-reformat t]
1322 ["Rename buffer" message-rename-buffer t]
1323 ["Spellcheck" ispell-message t]
1325 ["Send Message" message-send-and-exit t]
1326 ["Abort Message" message-dont-send t]
1327 ["Kill Message" message-kill-buffer t]))
1330 message-mode-field-menu message-mode-map ""
1332 ["Fetch To" message-insert-to t]
1333 ["Fetch Newsgroups" message-insert-newsgroups t]
1335 ["To" message-goto-to t]
1336 ["Subject" message-goto-subject t]
1337 ["Cc" message-goto-cc t]
1338 ["Reply-To" message-goto-reply-to t]
1339 ["Mail-Reply-To" message-goto-mail-reply-to t]
1340 ["Mail-Followup-To" message-goto-mail-followup-to t]
1341 ["Mail-Copies-To" message-goto-mail-copies-to t]
1342 ["Summary" message-goto-summary t]
1343 ["Keywords" message-goto-keywords t]
1344 ["Newsgroups" message-goto-newsgroups t]
1345 ["Followup-To" message-goto-followup-to t]
1346 ["Distribution" message-goto-distribution t]
1347 ["Body" message-goto-body t]
1348 ["Signature" message-goto-signature t]))
1350 (defvar facemenu-add-face-function)
1351 (defvar facemenu-remove-face-function)
1354 (defun message-mode ()
1355 "Major mode for editing mail and news to be sent.
1356 Like Text Mode but with these additional commands:
1357 C-c C-s message-send (send the message) C-c C-c message-send-and-exit
1358 C-c C-f move to a header field (and create it if there isn't):
1359 C-c C-f C-t move to To C-c C-f C-s move to Subject
1360 C-c C-f C-c move to Cc C-c C-f C-b move to Bcc
1361 C-c C-f C-w move to Fcc C-c C-f C-r move to Reply-To
1362 C-c C-f C-u move to Summary C-c C-f C-n move to Newsgroups
1363 C-c C-f C-k move to Keywords C-c C-f C-d move to Distribution
1364 C-c C-f C-m move to Mail-Followup-To
1365 C-c C-f C-f move to Followup-To
1366 C-c C-t message-insert-to (add a To header to a news followup)
1367 C-c C-n message-insert-newsgroups (add a Newsgroup header to a news reply)
1368 C-c C-b message-goto-body (move to beginning of message text).
1369 C-c C-i message-goto-signature (move to the beginning of the signature).
1370 C-c C-w message-insert-signature (insert `message-signature-file' file).
1371 C-c C-y message-yank-original (insert current message, if any).
1372 C-c C-q message-fill-yanked-message (fill what was yanked).
1373 C-c C-e message-elide-region (elide the text between point and mark).
1374 C-c C-z message-kill-to-signature (kill the text up to the signature).
1375 C-c C-r message-caesar-buffer-body (rot13 the message body)."
1377 (kill-all-local-variables)
1378 (make-local-variable 'message-reply-buffer)
1379 (setq message-reply-buffer nil)
1380 (make-local-variable 'message-send-actions)
1381 (make-local-variable 'message-exit-actions)
1382 (make-local-variable 'message-kill-actions)
1383 (make-local-variable 'message-postpone-actions)
1384 (make-local-variable 'message-draft-article)
1385 (make-local-hook 'kill-buffer-hook)
1386 (set-syntax-table message-mode-syntax-table)
1387 (use-local-map message-mode-map)
1388 (setq local-abbrev-table message-mode-abbrev-table)
1389 (setq major-mode 'message-mode)
1390 (setq mode-name "Message")
1391 (setq buffer-offer-save t)
1392 (make-local-variable 'facemenu-add-face-function)
1393 (make-local-variable 'facemenu-remove-face-function)
1394 (setq facemenu-add-face-function
1396 (let ((face-fun (cdr (assq face message-face-alist))))
1398 (funcall face-fun (point) end)
1399 (error "Face %s not configured for %s mode" face mode-name)))
1401 facemenu-remove-face-function t)
1402 (make-local-variable 'paragraph-separate)
1403 (make-local-variable 'paragraph-start)
1404 ;; `-- ' precedes the signature. `-----' appears at the start of the
1405 ;; lines that delimit forwarded messages.
1406 ;; Lines containing just >= 3 dashes, perhaps after whitespace,
1407 ;; are also sometimes used and should be separators.
1408 (setq paragraph-start
1409 (concat (regexp-quote mail-header-separator)
1410 "$\\|[ \t]*[a-z0-9A-Z]*>+[ \t]*$\\|[ \t]*$\\|"
1413 ;;!!! Uhm... shurely this can't be right?
1414 "[> " (regexp-quote message-yank-prefix) "]+$"))
1415 (setq paragraph-separate paragraph-start)
1416 (make-local-variable 'message-reply-headers)
1417 (setq message-reply-headers nil)
1418 (make-local-variable 'message-user-agent)
1419 (make-local-variable 'message-post-method)
1420 (make-local-variable 'message-sent-message-via)
1421 (setq message-sent-message-via nil)
1422 (make-local-variable 'message-checksum)
1423 (setq message-checksum nil)
1424 ;;(when (fboundp 'mail-hist-define-keys)
1425 ;; (mail-hist-define-keys))
1426 (when (string-match "XEmacs\\|Lucid" emacs-version)
1427 (message-setup-toolbar))
1428 (easy-menu-add message-mode-menu message-mode-map)
1429 (easy-menu-add message-mode-field-menu message-mode-map)
1430 ;; Allow mail alias things.
1431 (when (eq message-mail-alias-type 'abbrev)
1432 (if (fboundp 'mail-abbrevs-setup)
1433 (mail-abbrevs-setup)
1434 (mail-aliases-setup)))
1435 (message-set-auto-save-file-name)
1436 (unless (string-match "XEmacs" emacs-version)
1437 (set (make-local-variable 'font-lock-defaults)
1438 '(message-font-lock-keywords t)))
1439 (make-local-variable 'adaptive-fill-regexp)
1440 (setq adaptive-fill-regexp
1441 (concat "[ \t]*[-a-z0-9A-Z]*>+[ \t]*\\|" adaptive-fill-regexp))
1442 (unless (boundp 'adaptive-fill-first-line-regexp)
1443 (setq adaptive-fill-first-line-regexp nil))
1444 (make-local-variable 'adaptive-fill-first-line-regexp)
1445 (setq adaptive-fill-first-line-regexp
1446 (concat "[ \t]*[-a-z0-9A-Z]*>+[ \t]*\\|"
1447 adaptive-fill-first-line-regexp))
1448 (run-hooks 'text-mode-hook 'message-mode-hook))
1453 ;;; Message mode commands
1456 ;;; Movement commands
1458 (defun message-goto-to ()
1459 "Move point to the To header."
1461 (message-position-on-field "To"))
1463 (defun message-goto-subject ()
1464 "Move point to the Subject header."
1466 (message-position-on-field "Subject"))
1468 (defun message-goto-cc ()
1469 "Move point to the Cc header."
1471 (message-position-on-field "Cc" "To"))
1473 (defun message-goto-bcc ()
1474 "Move point to the Bcc header."
1476 (message-position-on-field "Bcc" "Cc" "To"))
1478 (defun message-goto-fcc ()
1479 "Move point to the Fcc header."
1481 (message-position-on-field "Fcc" "To" "Newsgroups"))
1483 (defun message-goto-reply-to ()
1484 "Move point to the Reply-To header."
1486 (message-position-on-field "Reply-To" "Subject"))
1488 (defun message-goto-mail-reply-to ()
1489 "Move point to the Mail-Reply-To header."
1491 (message-position-on-field "Mail-Reply-To" "Subject"))
1493 (defun message-goto-mail-followup-to ()
1494 "Move point to the Mail-Followup-To header."
1496 (message-position-on-field "Mail-Followup-To" "Subject"))
1498 (defun message-goto-mail-copies-to ()
1499 "Move point to the Mail-Copies-To header."
1501 (message-position-on-field "Mail-Copies-To" "Subject"))
1503 (defun message-goto-newsgroups ()
1504 "Move point to the Newsgroups header."
1506 (message-position-on-field "Newsgroups"))
1508 (defun message-goto-distribution ()
1509 "Move point to the Distribution header."
1511 (message-position-on-field "Distribution"))
1513 (defun message-goto-followup-to ()
1514 "Move point to the Followup-To header."
1516 (message-position-on-field "Followup-To" "Newsgroups"))
1518 (defun message-goto-keywords ()
1519 "Move point to the Keywords header."
1521 (message-position-on-field "Keywords" "Subject"))
1523 (defun message-goto-summary ()
1524 "Move point to the Summary header."
1526 (message-position-on-field "Summary" "Subject"))
1528 (defun message-goto-body ()
1529 "Move point to the beginning of the message body."
1531 (if (looking-at "[ \t]*\n") (expand-abbrev))
1532 (goto-char (point-min))
1533 (search-forward (concat "\n" mail-header-separator "\n") nil t))
1535 (defun message-goto-signature ()
1536 "Move point to the beginning of the message signature."
1538 (goto-char (point-min))
1539 (if (re-search-forward message-signature-separator nil t)
1541 (goto-char (point-max))))
1545 (defun message-insert-to (&optional force)
1546 "Insert a To header that points to the author of the article being replied to.
1547 If the original author requested not to be sent mail, the function signals
1549 With the prefix argument FORCE, insert the header anyway."
1551 (let ((co (message-fetch-reply-field "mail-copies-to")))
1552 (when (and (null force)
1554 (equal (downcase co) "never"))
1555 (error "The user has requested not to have copies sent via mail")))
1556 (when (and (message-position-on-field "To")
1557 (mail-fetch-field "to")
1558 (not (string-match "\\` *\\'" (mail-fetch-field "to"))))
1560 (insert (or (message-fetch-reply-field "reply-to")
1561 (message-fetch-reply-field "from") "")))
1563 (defun message-insert-newsgroups ()
1564 "Insert the Newsgroups header from the article being replied to."
1566 (when (and (message-position-on-field "Newsgroups")
1567 (mail-fetch-field "newsgroups")
1568 (not (string-match "\\` *\\'" (mail-fetch-field "newsgroups"))))
1570 (insert (or (message-fetch-reply-field "newsgroups") "")))
1574 ;;; Various commands
1576 (defun message-delete-not-region (beg end)
1577 "Delete everything in the body of the current message that is outside of the region."
1581 (delete-region (point) (progn (message-goto-signature)
1586 (delete-region beg (progn (message-goto-body)
1589 (message-goto-signature)
1592 (defun message-kill-to-signature ()
1593 "Deletes all text up to the signature."
1595 (let ((point (point)))
1596 (message-goto-signature)
1599 (kill-region point (point))
1603 (defun message-newline-and-reformat ()
1604 "Insert four newlines, and then reformat if inside quoted text."
1606 (let ((point (point))
1610 (setq quoted (looking-at (regexp-quote message-yank-prefix))))
1613 (insert message-yank-prefix))
1614 (fill-paragraph nil)
1618 (defun message-insert-signature (&optional force)
1619 "Insert a signature. See documentation for the `message-signature' variable."
1620 (interactive (list 0))
1623 ((and (null message-signature)
1626 (goto-char (point-max))
1627 (not (re-search-backward
1628 message-signature-separator nil t))))
1629 ((and (null message-signature)
1632 ((message-functionp message-signature)
1633 (funcall message-signature))
1634 ((listp message-signature)
1635 (eval message-signature))
1636 (t message-signature)))
1638 (cond ((stringp signature)
1640 ((and (eq t signature)
1641 message-signature-file
1642 (file-exists-p message-signature-file))
1645 (goto-char (point-max))
1646 ;; Insert the signature.
1650 (if (eq signature t)
1651 (insert-file-contents message-signature-file)
1653 (goto-char (point-max))
1654 (or (bolp) (insert "\n")))))
1656 (defun message-elide-region (b e)
1657 "Elide the text between point and mark.
1658 An ellipsis (from `message-elide-elipsis') will be inserted where the
1664 (insert message-elide-elipsis))
1666 (defvar message-caesar-translation-table nil)
1668 (defun message-caesar-region (b e &optional n)
1669 "Caesar rotation of region by N, default 13, for decrypting netnews."
1672 (min (point) (or (mark t) (point)))
1673 (max (point) (or (mark t) (point)))
1674 (when current-prefix-arg
1675 (prefix-numeric-value current-prefix-arg))))
1677 (setq n (if (numberp n) (mod n 26) 13)) ;canonize N
1678 (unless (or (zerop n) ; no action needed for a rot of 0
1679 (= b e)) ; no region to rotate
1680 ;; We build the table, if necessary.
1681 (when (or (not message-caesar-translation-table)
1682 (/= (aref message-caesar-translation-table ?a) (+ ?a n)))
1683 (setq message-caesar-translation-table
1684 (message-make-caesar-translation-table n)))
1685 ;; Then we translate the region. Do it this way to retain
1688 (subst-char-in-region
1689 b (1+ b) (char-after b)
1690 (aref message-caesar-translation-table (char-after b)))
1693 (defun message-make-caesar-translation-table (n)
1694 "Create a rot table with offset N."
1696 (table (make-string 256 0)))
1697 (while (< (incf i) 256)
1700 (substring table 0 ?A)
1701 (substring table (+ ?A n) (+ ?A n (- 26 n)))
1702 (substring table ?A (+ ?A n))
1703 (substring table (+ ?A 26) ?a)
1704 (substring table (+ ?a n) (+ ?a n (- 26 n)))
1705 (substring table ?a (+ ?a n))
1706 (substring table (+ ?a 26) 255))))
1708 (defun message-caesar-buffer-body (&optional rotnum)
1709 "Caesar rotates all letters in the current buffer by 13 places.
1710 Used to encode/decode possiblyun offensive messages (commonly in net.jokes).
1711 With prefix arg, specifies the number of places to rotate each letter forward.
1712 Mail and USENET news headers are not rotated."
1713 (interactive (if current-prefix-arg
1714 (list (prefix-numeric-value current-prefix-arg))
1718 (when (message-goto-body)
1719 (narrow-to-region (point) (point-max)))
1720 (message-caesar-region (point-min) (point-max) rotnum))))
1722 (defun message-pipe-buffer-body (program)
1723 "Pipe the message body in the current buffer through PROGRAM."
1726 (when (message-goto-body)
1727 (narrow-to-region (point) (point-max)))
1728 (let ((body (buffer-substring (point-min) (point-max))))
1729 (unless (equal 0 (call-process-region
1730 (point-min) (point-max) program t t))
1732 (message "%s failed." program))))))
1734 (defun message-rename-buffer (&optional enter-string)
1735 "Rename the *message* buffer to \"*message* RECIPIENT\".
1736 If the function is run with a prefix, it will ask for a new buffer
1737 name, rather than giving an automatic name."
1738 (interactive "Pbuffer name: ")
1741 (goto-char (point-min))
1742 (narrow-to-region (point)
1743 (search-forward mail-header-separator nil 'end))
1745 (if (message-news-p) (message-fetch-field "Newsgroups")
1746 (message-fetch-field "To"))
1749 (if (string-match "," mail-to)
1750 (concat (substring mail-to 0 (match-beginning 0)) ", ...")
1752 (name-default (concat "*message* " mail-trimmed-to))
1753 (name (if enter-string
1754 (read-string "New buffer name: " name-default)
1756 (rename-buffer name t)))))
1758 (defun message-fill-yanked-message (&optional justifyp)
1759 "Fill the paragraphs of a message yanked into this one.
1760 Numeric argument means justify as well."
1763 (goto-char (point-min))
1764 (search-forward (concat "\n" mail-header-separator "\n") nil t)
1765 (let ((fill-prefix message-yank-prefix))
1766 (fill-individual-paragraphs (point) (point-max) justifyp t))))
1768 (defun message-indent-citation ()
1769 "Modify text just inserted from a message to be cited.
1770 The inserted text should be the region.
1771 When this function returns, the region is again around the modified text.
1773 Normally, indent each nonblank line `message-indentation-spaces' spaces.
1774 However, if `message-yank-prefix' is non-nil, insert that prefix on each line."
1775 (let ((start (point)))
1776 ;; Remove unwanted headers.
1777 (when message-ignored-cited-headers
1782 (if (search-forward "\n\n" nil t)
1785 (message-remove-header message-ignored-cited-headers t)
1786 (when (= (point-min) (point-max))
1787 (setq all-removed t))
1788 (goto-char (point-max)))
1792 ;; Delete blank lines at the start of the buffer.
1793 (while (and (point-min)
1796 (message-delete-line))
1797 ;; Delete blank lines at the end of the buffer.
1798 (goto-char (point-max))
1801 (while (and (zerop (forward-line -1))
1803 (message-delete-line))
1804 ;; Do the indentation.
1805 (if (null message-yank-prefix)
1806 (indent-rigidly start (mark t) message-indentation-spaces)
1809 (while (< (point) (mark t))
1810 (insert message-yank-prefix)
1814 (defun message-yank-original (&optional arg)
1815 "Insert the message being replied to, if any.
1816 Puts point before the text and mark after.
1817 Normally indents each nonblank line ARG spaces (default 3). However,
1818 if `message-yank-prefix' is non-nil, insert that prefix on each line.
1820 This function uses `message-cite-function' to do the actual citing.
1822 Just \\[universal-argument] as argument means don't indent, insert no
1823 prefix, and don't delete any headers."
1825 (let ((modified (buffer-modified-p)))
1826 (when (and message-reply-buffer
1827 message-cite-function)
1828 (delete-windows-on message-reply-buffer t)
1829 (insert-buffer message-reply-buffer)
1830 (funcall message-cite-function)
1831 (message-exchange-point-and-mark)
1835 (setq message-checksum (message-checksum))))))
1837 (defun message-cite-original-without-signature ()
1838 "Cite function in the standard Message manner."
1839 (let ((start (point))
1842 (when message-indent-citation-function
1843 (if (listp message-indent-citation-function)
1844 message-indent-citation-function
1845 (list message-indent-citation-function)))))
1847 (when (re-search-backward "^-- $" start t)
1848 (delete-region (point) end))
1851 (funcall (pop functions)))
1852 (when message-citation-line-function
1855 (funcall message-citation-line-function))))
1857 (defun message-cite-original ()
1858 "Cite function in the standard Message manner."
1859 (if (and (boundp 'mail-citation-hook)
1861 (run-hooks 'mail-citation-hook)
1862 (let ((start (point))
1864 (when message-indent-citation-function
1865 (if (listp message-indent-citation-function)
1866 message-indent-citation-function
1867 (list message-indent-citation-function)))))
1870 (funcall (pop functions)))
1871 (when message-citation-line-function
1874 (funcall message-citation-line-function)))))
1876 (defun message-insert-citation-line ()
1877 "Function that inserts a simple citation line."
1878 (when message-reply-headers
1879 (insert (mail-header-from message-reply-headers) " writes:\n\n")))
1881 (defun message-position-on-field (header &rest afters)
1882 (let ((case-fold-search t))
1885 (goto-char (point-min))
1888 (concat "^" (regexp-quote mail-header-separator) "$"))
1889 (match-beginning 0)))
1890 (goto-char (point-min))
1891 (if (re-search-forward (concat "^" (regexp-quote header) ":") nil t)
1893 (re-search-forward "^[^ \t]" nil 'move)
1895 (skip-chars-backward "\n")
1898 (not (re-search-forward
1899 (concat "^" (regexp-quote (car afters)) ":")
1903 (re-search-forward "^[^ \t]" nil 'move)
1904 (beginning-of-line))
1905 (insert header ": \n")
1909 (defun message-remove-signature ()
1910 "Remove the signature from the text between point and mark.
1911 The text will also be indented the normal way."
1913 (let ((start (point))
1915 (if (not (re-search-forward message-signature-separator (mark t) t))
1916 ;; No signature here, so we just indent the cited text.
1917 (message-indent-citation)
1918 ;; Find the last non-empty line.
1920 (while (looking-at "[ \t]*$")
1923 (setq mark (set-marker (make-marker) (point)))
1925 (message-indent-citation)
1926 ;; Enable undoing the deletion.
1928 (delete-region mark (mark t))
1929 (set-marker mark nil)))))
1934 ;;; Sending messages
1937 (defun message-send-and-exit (&optional arg)
1938 "Send message like `message-send', then, if no errors, exit from mail buffer."
1940 (let ((buf (current-buffer))
1941 (actions message-exit-actions))
1942 (when (and (message-send arg)
1944 (if message-kill-buffer-on-exit
1947 (when (eq buf (current-buffer))
1948 (message-bury buf)))
1949 (message-do-actions actions))))
1951 (defun message-dont-send ()
1952 "Don't send the message you have been editing."
1954 (set-buffer-modified-p t)
1956 (let ((actions message-postpone-actions))
1957 (message-bury (current-buffer))
1958 (message-do-actions actions)))
1960 (defun message-kill-buffer ()
1961 "Kill the current buffer."
1963 (when (or (not (buffer-modified-p))
1964 (yes-or-no-p "Message modified; kill anyway? "))
1965 (let ((actions message-kill-actions))
1966 (setq buffer-file-name nil)
1967 (kill-buffer (current-buffer))
1968 (message-do-actions actions))))
1970 (defun message-bury (buffer)
1971 "Bury this mail buffer."
1972 (let ((newbuf (other-buffer buffer)))
1973 (bury-buffer buffer)
1974 (if (and (fboundp 'frame-parameters)
1975 (cdr (assq 'dedicated (frame-parameters)))
1976 (not (null (delq (selected-frame) (visible-frame-list)))))
1977 (delete-frame (selected-frame))
1978 (switch-to-buffer newbuf))))
1980 (defun message-send (&optional arg)
1981 "Send the message in the current buffer.
1982 If `message-interactive' is non-nil, wait for success indication
1983 or error messages, and inform user.
1984 Otherwise any failure is reported in a message back to
1985 the user from the mailer."
1988 (when (or (buffer-modified-p)
1989 (message-check-element 'unchanged)
1990 (y-or-n-p "No changes in the buffer; really send? "))
1991 ;; Make it possible to undo the coming changes.
1993 (let ((inhibit-read-only t))
1994 (put-text-property (point-min) (point-max) 'read-only nil))
1995 (message-fix-before-sending)
1996 (run-hooks 'message-send-hook)
1997 (message "Sending...")
1998 (let ((message-encoding-buffer
1999 (message-generate-new-buffer-clone-locals " message encoding"))
2000 (message-edit-buffer (current-buffer))
2001 (message-mime-mode mime-edit-mode-flag)
2002 (alist message-send-method-alist)
2006 (set-buffer message-encoding-buffer)
2008 (insert-buffer message-edit-buffer)
2009 (funcall message-encode-function)
2011 (setq elem (pop alist)))
2012 (when (and (or (not (funcall (cadr elem)))
2013 (and (or (not (memq (car elem)
2014 message-sent-message-via))
2017 "Already sent message via %s; resend? "
2019 (setq success (funcall (caddr elem) arg)))))
2021 (when (and success sent)
2023 ;;(when (fboundp 'mail-hist-put-headers-into-history)
2024 ;; (mail-hist-put-headers-into-history))
2025 (run-hooks 'message-sent-hook)
2026 (message "Sending...done")
2027 ;; Mark the buffer as unmodified and delete autosave.
2028 (set-buffer-modified-p nil)
2029 (delete-auto-save-file-if-necessary t)
2030 (message-disassociate-draft)
2031 ;; Delete other mail buffers and stuff.
2032 (message-do-send-housekeeping)
2033 (message-do-actions message-send-actions)
2037 (defun message-send-via-mail (arg)
2038 "Send the current message via mail."
2039 (message-send-mail arg))
2041 (defun message-send-via-news (arg)
2042 "Send the current message via news."
2043 (message-send-news arg))
2045 (defun message-fix-before-sending ()
2046 "Do various things to make the message nice before sending it."
2047 ;; Make sure there's a newline at the end of the message.
2048 (goto-char (point-max))
2052 (defun message-add-action (action &rest types)
2053 "Add ACTION to be performed when doing an exit of type TYPES."
2056 (set (setq var (intern (format "message-%s-actions" (pop types))))
2057 (nconc (symbol-value var) (list action))))))
2059 (defun message-do-actions (actions)
2060 "Perform all actions in ACTIONS."
2061 ;; Now perform actions on successful sending.
2065 ;; A simple function.
2066 ((message-functionp (car actions))
2067 (funcall (car actions)))
2068 ;; Something to be evaled.
2070 (eval (car actions)))))
2073 (defun message-send-mail (&optional arg)
2074 (require 'mail-utils)
2075 (let ((tembuf (message-generate-new-buffer-clone-locals " message temp"))
2076 (case-fold-search nil)
2077 (news (message-news-p)))
2079 (message-narrow-to-headers)
2080 ;; Insert some headers.
2081 (let ((message-deletable-headers
2082 (if news nil message-deletable-headers)))
2083 (message-generate-headers message-required-mail-headers))
2084 ;; Let the user do all of the above.
2085 (run-hooks 'message-header-hook))
2090 (insert-buffer message-encoding-buffer)
2091 ;; Remove some headers.
2093 (message-narrow-to-headers)
2094 ;; Remove some headers.
2095 (message-remove-header message-ignored-mail-headers t))
2096 (goto-char (point-max))
2097 ;; require one newline at the end.
2098 (or (= (preceding-char) ?\n)
2101 (or (message-fetch-field "cc")
2102 (message-fetch-field "to")))
2103 (message-insert-courtesy-copy))
2104 (mime-edit-maybe-split-and-send
2108 (funcall message-send-mail-function)
2110 (funcall message-send-mail-function))
2111 (kill-buffer tembuf))
2112 (set-buffer message-edit-buffer)
2113 (push 'mail message-sent-message-via)))
2115 (defun message-send-mail-with-sendmail ()
2116 "Send off the prepared buffer with sendmail."
2117 (let ((errbuf (if message-interactive
2118 (generate-new-buffer " sendmail errors")
2120 resend-addresses delimline)
2121 (let ((case-fold-search t))
2123 (message-narrow-to-headers)
2124 ;; XXX: We need to handle Resent-CC/Resent-BCC, too.
2125 (setq resend-addresses (message-fetch-field "resent-to")))
2126 ;; Change header-delimiter to be what sendmail expects.
2127 (goto-char (point-min))
2129 (concat "^" (regexp-quote mail-header-separator) "\n"))
2130 (replace-match "\n")
2132 (setq delimline (point-marker))
2133 (run-hooks 'message-send-mail-hook)
2134 ;; Insert an extra newline if we need it to work around
2135 ;; Sun's bug that swallows newlines.
2136 (goto-char (1+ delimline))
2137 (when (eval message-mailer-swallows-blank-line)
2139 (when message-interactive
2143 (let ((default-directory "/")
2144 (coding-system-for-write 'binary))
2145 (apply 'call-process-region
2146 (append (list (point-min) (point-max)
2147 (if (boundp 'sendmail-program)
2149 "/usr/lib/sendmail")
2150 nil errbuf nil "-oi")
2151 ;; Always specify who from,
2152 ;; since some systems have broken sendmails.
2153 ;; But some systems are more broken with -f, so
2154 ;; we'll let users override this.
2155 (if (null message-sendmail-f-is-evil)
2156 (list "-f" (user-login-name)))
2157 ;; These mean "report errors by mail"
2158 ;; and "deliver in background".
2159 (if (null message-interactive) '("-oem" "-odb"))
2160 ;; Get the addresses from the message
2161 ;; unless this is a resend.
2162 ;; We must not do that for a resend
2163 ;; because we would find the original addresses.
2164 ;; For a resend, include the specific addresses.
2165 (if resend-addresses
2166 (list resend-addresses)
2168 (when message-interactive
2171 (goto-char (point-min))
2172 (while (re-search-forward "\n\n* *" nil t)
2173 (replace-match "; "))
2174 (if (not (zerop (buffer-size)))
2175 (error "Sending...failed to %s"
2176 (buffer-substring (point-min) (point-max)))))
2177 (when (bufferp errbuf)
2178 (kill-buffer errbuf)))))
2180 (defun message-send-mail-with-qmail ()
2181 "Pass the prepared message buffer to qmail-inject.
2182 Refer to the documentation for the variable `message-send-mail-function'
2183 to find out how to use this."
2184 ;; replace the header delimiter with a blank line.
2185 (goto-char (point-min))
2187 (concat "^" (regexp-quote mail-header-separator) "\n"))
2188 (replace-match "\n")
2190 (run-hooks 'message-send-mail-hook)
2193 (let ((coding-system-for-write 'binary))
2195 'call-process-region 1 (point-max) message-qmail-inject-program
2197 ;; qmail-inject's default behaviour is to look for addresses on the
2198 ;; command line; if there're none, it scans the headers.
2199 ;; yes, it does The Right Thing w.r.t. Resent-To and it's kin.
2201 ;; in general, ALL of qmail-inject's defaults are perfect for simply
2202 ;; reading a formatted (i. e., at least a To: or Resent-To header)
2203 ;; message from stdin.
2205 ;; qmail also has the advantage of not having been raped by
2206 ;; various vendors, so we don't have to allow for that, either --
2207 ;; compare this with message-send-mail-with-sendmail and weep
2208 ;; for sendmail's lost innocence.
2210 ;; all this is way cool coz it lets us keep the arguments entirely
2211 ;; free for -inject-arguments -- a big win for the user and for us
2212 ;; since we don't have to play that double-guessing game and the user
2213 ;; gets full control (no gestapo'ish -f's, for instance). --sj
2214 message-qmail-inject-args))
2215 ;; qmail-inject doesn't say anything on it's stdout/stderr,
2216 ;; we have to look at the retval instead
2218 (1 (error "qmail-inject reported permanent failure"))
2219 (111 (error "qmail-inject reported transient failure"))
2220 ;; should never happen
2221 (t (error "qmail-inject reported unknown failure"))))
2223 (defun message-send-mail-with-mh ()
2224 "Send the prepared message buffer with mh."
2225 (let ((mh-previous-window-config nil)
2226 (name (mh-new-draft-name)))
2227 (setq buffer-file-name name)
2228 ;; MH wants to generate these headers itself.
2229 (when message-mh-deletable-headers
2230 (let ((headers message-mh-deletable-headers))
2232 (goto-char (point-min))
2233 (and (re-search-forward
2234 (concat "^" (symbol-name (car headers)) ": *") nil t)
2235 (message-delete-line))
2237 (run-hooks 'message-send-mail-hook)
2238 ;; Pass it on to mh.
2241 (defun message-send-mail-with-smtp ()
2242 "Send off the prepared buffer with SMTP."
2243 (require 'smtp) ; XXX
2244 (let ((case-fold-search t)
2247 (message-narrow-to-headers)
2249 ;; XXX: Should be replaced by better one.
2250 (smtp-deduce-address-list (current-buffer)
2251 (point-min) (point-max)))
2252 ;; Remove BCC lines.
2253 (message-remove-header "bcc"))
2254 ;; replace the header delimiter with a blank line.
2255 (goto-char (point-min))
2257 (concat "^" (regexp-quote mail-header-separator) "\n"))
2258 (replace-match "\n")
2260 (run-hooks 'message-send-mail-hook)
2262 (let ((result (smtp-via-smtp user-mail-address
2265 (unless (eq result t)
2266 (error "Sending failed; " result)))
2267 (error "Sending failed; no recipients"))))
2269 (defun message-send-news (&optional arg)
2270 (let ((tembuf (message-generate-new-buffer-clone-locals " *message temp*"))
2271 (case-fold-search nil)
2272 (method (if (message-functionp message-post-method)
2273 (funcall message-post-method arg)
2274 message-post-method))
2275 (message-syntax-checks
2277 (cons '(existing-newsgroups . disabled)
2278 message-syntax-checks)
2279 message-syntax-checks))
2282 (message-narrow-to-headers)
2283 ;; Insert some headers.
2284 (message-generate-headers message-required-news-headers)
2285 ;; Let the user do all of the above.
2286 (run-hooks 'message-header-hook))
2287 (message-cleanup-headers)
2288 (if (not (message-check-news-syntax))
2290 ;;(message "Posting not performed")
2295 (buffer-disable-undo (current-buffer))
2297 (insert-buffer message-encoding-buffer)
2298 ;; Remove some headers.
2300 (message-narrow-to-headers)
2301 ;; Remove some headers.
2302 (message-remove-header message-ignored-news-headers t))
2303 (goto-char (point-max))
2304 ;; require one newline at the end.
2305 (or (= (preceding-char) ?\n)
2307 (mime-edit-maybe-split-and-send
2312 (std11-narrow-to-header mail-header-separator)
2313 (goto-char (point-min))
2314 (when (re-search-forward "^Message-Id:" nil t)
2315 (delete-region (match-end 0)(std11-field-end))
2316 (insert (concat " " (message-make-message-id)))
2318 (funcall message-send-news-function method)
2320 (setq result (funcall message-send-news-function method)))
2321 (kill-buffer tembuf))
2322 (set-buffer message-edit-buffer)
2324 (push 'news message-sent-message-via)
2325 (message "Couldn't send message via news: %s"
2326 (nnheader-get-report (car method)))
2329 ;; 1997-09-29 by MORIOKA Tomohiko
2330 (defun message-send-news-with-gnus (method)
2331 (let ((case-fold-search t))
2332 ;; Remove the delimiter.
2333 (goto-char (point-min))
2335 (concat "^" (regexp-quote mail-header-separator) "\n"))
2336 (replace-match "\n")
2338 (run-hooks 'message-send-news-hook)
2339 ;;(require (car method))
2340 ;;(funcall (intern (format "%s-open-server" (car method)))
2341 ;;(cadr method) (cddr method))
2343 ;; (funcall (intern (format "%s-request-post" (car method)))
2345 (gnus-open-server method)
2346 (gnus-request-post method)
2350 ;;; Header generation & syntax checking.
2353 (defmacro message-check (type &rest forms)
2354 "Eval FORMS if TYPE is to be checked."
2355 `(or (message-check-element ,type)
2359 (put 'message-check 'lisp-indent-function 1)
2360 (put 'message-check 'edebug-form-spec '(form body))
2362 (defun message-check-element (type)
2363 "Returns non-nil if this type is not to be checked."
2364 (if (eq message-syntax-checks 'dont-check-for-anything-just-trust-me)
2366 (let ((able (assq type message-syntax-checks)))
2368 (eq (cdr able) 'disabled)))))
2370 (defun message-check-news-syntax ()
2371 "Check the syntax of the message."
2376 ;; We narrow to the headers and check them first.
2379 (message-narrow-to-headers)
2380 (message-check-news-header-syntax)))
2383 (set-buffer message-edit-buffer)
2384 (message-check-news-body-syntax))))))
2386 (defun message-check-news-header-syntax ()
2388 ;; Check the Subject header.
2389 (message-check 'subject
2390 (let* ((case-fold-search t)
2391 (subject (message-fetch-field "subject")))
2394 (not (string-match "\\`[ \t]*\\'" subject)))
2397 "The subject field is empty or missing. Posting is denied.")))))
2398 ;; Check for commands in Subject.
2399 (message-check 'subject-cmsg
2400 (if (string-match "^cmsg " (message-fetch-field "subject"))
2402 "The control code \"cmsg\" is in the subject. Really post? ")
2404 ;; Check for multiple identical headers.
2405 (message-check 'multiple-headers
2407 (while (and (not found)
2408 (re-search-forward "^[^ \t:]+: " nil t))
2410 (or (re-search-forward
2415 (match-beginning 0) (- (match-end 0) 2))))
2420 (y-or-n-p (format "Multiple %s headers. Really post? " found))
2422 ;; Check for Version and Sendsys.
2423 (message-check 'sendsys
2424 (if (re-search-forward "^Sendsys:\\|^Version:" nil t)
2426 (format "The article contains a %s command. Really post? "
2427 (buffer-substring (match-beginning 0)
2428 (1- (match-end 0)))))
2430 ;; See whether we can shorten Followup-To.
2431 (message-check 'shorten-followup-to
2432 (let ((newsgroups (message-fetch-field "newsgroups"))
2433 (followup-to (message-fetch-field "followup-to"))
2435 (when (and newsgroups
2436 (string-match "," newsgroups)
2441 (setq to (completing-read
2442 "Followups to: (default all groups) "
2443 (mapcar (lambda (g) (list g))
2445 (message-tokenize-header
2447 (goto-char (point-min))
2448 (insert "Followup-To: " to "\n"))
2450 ;; Check "Shoot me".
2451 (message-check 'shoot
2452 (if (re-search-forward
2453 "Message-ID.*.i-did-not-set--mail-host-address--so-shoot-me" nil t)
2454 (y-or-n-p "You appear to have a misconfigured system. Really post? ")
2456 ;; Check for Approved.
2457 (message-check 'approved
2458 (if (re-search-forward "^Approved:" nil t)
2459 (y-or-n-p "The article contains an Approved header. Really post? ")
2461 ;; Check the Message-ID header.
2462 (message-check 'message-id
2463 (let* ((case-fold-search t)
2464 (message-id (message-fetch-field "message-id" t)))
2465 (or (not message-id)
2466 ;; Is there an @ in the ID?
2467 (and (string-match "@" message-id)
2468 ;; Is there a dot in the ID?
2469 (string-match "@[^.]*\\." message-id)
2470 ;; Does the ID end with a dot?
2471 (not (string-match "\\.>" message-id)))
2473 (format "The Message-ID looks strange: \"%s\". Really post? "
2475 ;; Check the Newsgroups & Followup-To headers.
2476 (message-check 'existing-newsgroups
2477 (let* ((case-fold-search t)
2478 (newsgroups (message-fetch-field "newsgroups"))
2479 (followup-to (message-fetch-field "followup-to"))
2480 (groups (message-tokenize-header
2482 (concat newsgroups "," followup-to)
2484 (hashtb (and (boundp 'gnus-active-hashtb)
2485 gnus-active-hashtb))
2487 (if (or (not hashtb)
2488 (not (boundp 'gnus-read-active-file))
2489 (not gnus-read-active-file)
2490 (eq gnus-read-active-file 'some))
2493 (when (and (not (boundp (intern (car groups) hashtb)))
2494 (not (equal (car groups) "poster")))
2495 (push (car groups) errors))
2501 "Really post to %s unknown group%s: %s "
2502 (if (= (length errors) 1) "this" "these")
2503 (if (= (length errors) 1) "" "s")
2504 (mapconcat 'identity errors ", ")))))))
2505 ;; Check the Newsgroups & Followup-To headers for syntax errors.
2506 (message-check 'valid-newsgroups
2507 (let ((case-fold-search t)
2508 (headers '("Newsgroups" "Followup-To"))
2510 (while (and headers (not error))
2511 (when (setq header (mail-fetch-field (car headers)))
2515 "\\`\\([-+_&.a-zA-Z0-9]+\\)?\\(,[-+_&.a-zA-Z0-9]+\\)*\\'"
2520 (not (string-match "\\.\\'\\|\\.\\." g)))
2521 (message-tokenize-header header ","))))
2528 (format "The %s header looks odd: \"%s\". Really post? "
2529 (car headers) header)))))
2530 (message-check 'repeated-newsgroups
2531 (let ((case-fold-search t)
2532 (headers '("Newsgroups" "Followup-To"))
2533 header error groups group)
2536 (when (setq header (mail-fetch-field (pop headers)))
2537 (setq groups (message-tokenize-header header ","))
2538 (while (setq group (pop groups))
2539 (when (member group groups)
2545 (format "Group %s is repeated in headers. Really post? " error)))))
2546 ;; Check the From header.
2547 (message-check 'from
2548 (let* ((case-fold-search t)
2549 (from (message-fetch-field "from"))
2550 (ad (nth 1 (funcall gnus-extract-address-components from))))
2553 (message "There is no From line. Posting is denied.")
2555 ((or (not (string-match "@[^\\.]*\\." ad)) ;larsi@ifi
2556 (string-match "\\.\\." ad) ;larsi@ifi..uio
2557 (string-match "@\\." ad) ;larsi@.ifi.uio
2558 (string-match "\\.$" ad) ;larsi@ifi.uio.
2559 (not (string-match "^[^@]+@[^@]+$" ad)) ;larsi.ifi.uio
2560 (string-match "(.*).*(.*)" from)) ;(lars) (lars)
2562 "Denied posting -- the From looks strange: \"%s\"." from)
2566 (defun message-check-news-body-syntax ()
2568 ;; Check for long lines.
2569 (message-check 'long-lines
2570 (goto-char (point-min))
2572 (concat "^" (regexp-quote mail-header-separator) "$"))
2576 (< (current-column) 80))
2577 (zerop (forward-line 1))))
2581 "You have lines longer than 79 characters. Really post? ")))
2582 ;; Check whether the article is empty.
2583 (message-check 'empty
2584 (goto-char (point-min))
2586 (concat "^" (regexp-quote mail-header-separator) "$"))
2589 (goto-char (point-max))
2590 (re-search-backward message-signature-separator nil t)
2592 (or (re-search-backward "[^ \n\t]" b t)
2593 (y-or-n-p "Empty article. Really post? "))))
2594 ;; Check for control characters.
2595 (message-check 'control-chars
2596 (if (re-search-forward "[\000-\007\013\015-\037\200-\237]" nil t)
2598 "The article contains control characters. Really post? ")
2600 ;; Check excessive size.
2601 (message-check 'size
2602 (if (> (buffer-size) 60000)
2604 (format "The article is %d octets long. Really post? "
2607 ;; Check whether any new text has been added.
2608 (message-check 'new-text
2610 (not message-checksum)
2611 (not (eq (message-checksum) message-checksum))
2613 "It looks like no new text has been added. Really post? ")))
2614 ;; Check the length of the signature.
2615 (message-check 'signature
2616 (goto-char (point-max))
2617 (if (or (not (re-search-backward message-signature-separator nil t))
2618 (search-forward message-forward-end-separator nil t))
2620 (if (> (count-lines (point) (point-max)) 5)
2623 "Your .sig is %d lines; it should be max 4. Really post? "
2624 (1- (count-lines (point) (point-max)))))
2627 (defun message-checksum ()
2628 "Return a \"checksum\" for the current buffer."
2631 (goto-char (point-min))
2633 (concat "^" (regexp-quote mail-header-separator) "$"))
2635 (when (not (looking-at "[ \t\n]"))
2636 (setq sum (logxor (ash sum 1) (if (natnump sum) 0 1)
2641 (defun message-do-fcc ()
2642 "Process Fcc headers in the current buffer."
2643 (let ((case-fold-search t)
2644 (coding-system-for-write 'raw-text)
2647 (set-buffer (get-buffer-create " *message temp*"))
2648 (buffer-disable-undo (current-buffer))
2650 (insert-buffer-substring message-encoding-buffer)
2652 (message-narrow-to-headers)
2653 (while (setq file (message-fetch-field "fcc"))
2655 (message-remove-header "fcc" nil t)))
2656 (run-hooks 'message-header-hook 'message-before-do-fcc-hook)
2657 (goto-char (point-min))
2658 (re-search-forward (concat "^" (regexp-quote mail-header-separator) "$"))
2659 (replace-match "" t t)
2660 ;; Process FCC operations.
2662 (setq file (pop list))
2663 (if (string-match "^[ \t]*|[ \t]*\\(.*\\)[ \t]*$" file)
2664 ;; Pipe the article to the program in question.
2665 (call-process-region (point-min) (point-max) shell-file-name
2666 nil nil nil shell-command-switch
2667 (match-string 1 file))
2668 ;; Save the article.
2669 (setq file (expand-file-name file))
2670 (unless (file-exists-p (file-name-directory file))
2671 (make-directory (file-name-directory file) t))
2672 (if (and message-fcc-handler-function
2673 (not (eq message-fcc-handler-function 'rmail-output)))
2674 (funcall message-fcc-handler-function file)
2675 (if (and (file-readable-p file) (mail-file-babyl-p file))
2676 (rmail-output file 1 nil t)
2677 (let ((mail-use-rfc822 t))
2678 (rmail-output file 1 t t))))))
2680 (kill-buffer (current-buffer)))))
2682 (defun message-output (filename)
2683 "Append this article to Unix/babyl mail file.."
2684 (if (and (file-readable-p filename)
2685 (mail-file-babyl-p filename))
2686 (gnus-output-to-rmail filename t)
2687 (gnus-output-to-mail filename t)))
2689 (defun message-cleanup-headers ()
2690 "Do various automatic cleanups of the headers."
2691 ;; Remove empty lines in the header.
2693 (message-narrow-to-headers)
2694 ;; Remove blank lines.
2695 (while (re-search-forward "^[ \t]*\n" nil t)
2696 (replace-match "" t t))
2698 ;; Correct Newsgroups and Followup-To headers: Change sequence of
2699 ;; spaces to comma and eliminate spaces around commas. Eliminate
2700 ;; embedded line breaks.
2701 (goto-char (point-min))
2702 (while (re-search-forward "^\\(Newsgroups\\|Followup-To\\): +" nil t)
2706 (if (re-search-forward "^[^ \t]" nil t)
2710 (goto-char (point-min))
2711 (while (re-search-forward "\n[ \t]+" nil t)
2712 (replace-match " " t t)) ;No line breaks (too confusing)
2713 (goto-char (point-min))
2714 (while (re-search-forward "[ \t\n]*,[ \t\n]*\\|[ \t]+" nil t)
2715 (replace-match "," t t))
2716 (goto-char (point-min))
2717 ;; Remove trailing commas.
2718 (when (re-search-forward ",+$" nil t)
2719 (replace-match "" t t))))))
2721 (defun message-make-date ()
2722 "Make a valid data header."
2723 (let ((now (current-time)))
2724 (timezone-make-date-arpa-standard
2725 (current-time-string now) (current-time-zone now))))
2727 (defun message-make-followup-subject (subject)
2728 "Make a followup Subject."
2730 ((and (eq message-use-subject-re 'guess)
2731 (string-match message-subject-encoded-re-regexp subject))
2733 (message-use-subject-re
2734 (concat "Re: " (message-strip-subject-re subject)))
2737 (defun message-make-message-id ()
2738 "Make a unique Message-ID."
2739 (concat "<" (message-unique-id)
2740 (let ((psubject (save-excursion (message-fetch-field "subject")))
2742 (save-excursion (message-fetch-field "supersedes"))))
2744 (and message-reply-headers
2745 (mail-header-references message-reply-headers)
2746 (mail-header-subject message-reply-headers)
2748 (mail-header-subject message-reply-headers)
2750 (message-strip-subject-re
2751 (mail-header-subject message-reply-headers))
2752 (message-strip-subject-re psubject))))
2754 (string-match "_-_@" psupersedes)))
2756 "@" (message-make-fqdn) ">"))
2758 (defvar message-unique-id-char nil)
2760 ;; If you ever change this function, make sure the new version
2761 ;; cannot generate IDs that the old version could.
2762 ;; You might for example insert a "." somewhere (not next to another dot
2763 ;; or string boundary), or modify the "fsf" string.
2764 (defun message-unique-id ()
2765 ;; Don't use microseconds from (current-time), they may be unsupported.
2766 ;; Instead we use this randomly inited counter.
2767 (setq message-unique-id-char
2768 (% (1+ (or message-unique-id-char (logand (random t) (1- (lsh 1 20)))))
2769 ;; (current-time) returns 16-bit ints,
2770 ;; and 2^16*25 just fits into 4 digits i base 36.
2772 (let ((tm (current-time)))
2774 (if (memq system-type '(ms-dos emx vax-vms))
2775 (let ((user (downcase (user-login-name))))
2776 (while (string-match "[^a-z0-9_]" user)
2777 (aset user (match-beginning 0) ?_))
2779 (message-number-base36 (user-uid) -1))
2780 (message-number-base36 (+ (car tm)
2781 (lsh (% message-unique-id-char 25) 16)) 4)
2782 (message-number-base36 (+ (nth 1 tm)
2783 (lsh (/ message-unique-id-char 25) 16)) 4)
2784 ;; Append the newsreader name, because while the generated
2785 ;; ID is unique to this newsreader, other newsreaders might
2786 ;; otherwise generate the same ID via another algorithm.
2789 (defun message-number-base36 (num len)
2794 (concat (message-number-base36 (/ num 36) (1- len))
2795 (char-to-string (aref "zyxwvutsrqponmlkjihgfedcba9876543210"
2798 (defun message-make-organization ()
2799 "Make an Organization header."
2800 (let* ((organization
2801 (when message-user-organization
2802 (if (message-functionp message-user-organization)
2803 (funcall message-user-organization)
2804 message-user-organization))))
2806 (message-set-work-buffer)
2807 (cond ((stringp organization)
2808 (insert organization))
2809 ((and (eq t organization)
2810 message-user-organization-file
2811 (file-exists-p message-user-organization-file))
2812 (insert-file-contents message-user-organization-file)))
2813 (goto-char (point-min))
2814 (while (re-search-forward "[\t\n]+" nil t)
2815 (replace-match "" t t))
2816 (unless (zerop (buffer-size))
2819 (defun message-make-lines ()
2820 "Count the number of lines and return numeric string."
2824 (goto-char (point-min))
2826 (concat "^" (regexp-quote mail-header-separator) "$"))
2828 (int-to-string (count-lines (point) (point-max))))))
2830 (defun message-make-in-reply-to ()
2831 "Return the In-Reply-To header for this message."
2832 (when message-reply-headers
2833 (let ((mid (mail-header-message-id message-reply-headers))
2834 (from (mail-header-from message-reply-headers))
2835 (date (mail-header-date message-reply-headers)))
2840 (string-match " *at \\| *@ \\| *(\\| *<" from)))
2842 (if stop-pos (substring from 0 stop-pos) from)
2844 (if (or (not date) (string= date ""))
2845 "(unknown date)" date)
2848 (defun message-make-distribution ()
2849 "Make a Distribution header."
2850 (let ((orig-distribution (message-fetch-reply-field "distribution")))
2851 (cond ((message-functionp message-distribution-function)
2852 (funcall message-distribution-function))
2853 (t orig-distribution))))
2855 (defun message-make-expires ()
2856 "Return an Expires header based on `message-expires'."
2857 (let ((current (current-time))
2858 (future (* 1.0 message-expires 60 60 24)))
2859 ;; Add the future to current.
2860 (setcar current (+ (car current) (round (/ future (expt 2 16)))))
2861 (setcar (cdr current) (+ (nth 1 current) (% (round future) (expt 2 16))))
2862 ;; Return the date in the future in UT.
2863 (timezone-make-date-arpa-standard
2864 (current-time-string current) (current-time-zone current) '(0 "UT"))))
2866 (defun message-make-path ()
2868 (let ((login-name (user-login-name)))
2869 (cond ((null message-user-path)
2870 (concat (system-name) "!" login-name))
2871 ((stringp message-user-path)
2872 ;; Support GENERICPATH. Suggested by vixie@decwrl.dec.com.
2873 (concat message-user-path "!" login-name))
2876 (defun message-make-from ()
2877 "Make a From header."
2878 (let* ((style message-from-style)
2879 (login (message-make-address))
2881 (or (and (boundp 'user-full-name)
2884 (when (string= fullname "&")
2885 (setq fullname (user-login-name)))
2887 (message-set-work-buffer)
2890 (equal fullname ""))
2892 ((or (eq style 'angles)
2893 (and (not (eq style 'parens))
2894 ;; Use angles if no quoting is needed, or if parens would
2895 ;; need quoting too.
2896 (or (not (string-match "[^- !#-'*+/-9=?A-Z^-~]" fullname))
2897 (let ((tmp (concat fullname nil)))
2898 (while (string-match "([^()]*)" tmp)
2899 (aset tmp (match-beginning 0) ?-)
2900 (aset tmp (1- (match-end 0)) ?-))
2901 (string-match "[\\()]" tmp)))))
2903 (goto-char (point-min))
2904 ;; Look for a character that cannot appear unquoted
2905 ;; according to RFC 822.
2906 (when (re-search-forward "[^- !#-'*+/-9=?A-Z^-~]" nil 1)
2907 ;; Quote fullname, escaping specials.
2908 (goto-char (point-min))
2910 (while (re-search-forward "[\"\\]" nil 1)
2911 (replace-match "\\\\\\&" t))
2913 (insert " <" login ">"))
2914 (t ; 'parens or default
2916 (let ((fullname-start (point)))
2918 (goto-char fullname-start)
2919 ;; RFC 822 says \ and nonmatching parentheses
2920 ;; must be escaped in comments.
2921 ;; Escape every instance of ()\ ...
2922 (while (re-search-forward "[()\\]" nil 1)
2923 (replace-match "\\\\\\&" t))
2924 ;; ... then undo escaping of matching parentheses,
2925 ;; including matching nested parentheses.
2926 (goto-char fullname-start)
2927 (while (re-search-forward
2928 "\\(\\=\\|[^\\]\\(\\\\\\\\\\)*\\)\\\\(\\(\\([^\\]\\|\\\\\\\\\\)*\\)\\\\)"
2930 (replace-match "\\1(\\3)" t)
2931 (goto-char fullname-start)))
2935 (defun message-make-sender ()
2936 "Return the \"real\" user address.
2937 This function tries to ignore all user modifications, and
2938 give as trustworthy answer as possible."
2939 (concat (user-login-name) "@" (system-name)))
2941 (defun message-make-address ()
2942 "Make the address of the user."
2943 (or (message-user-mail-address)
2944 (concat (user-login-name) "@" (message-make-domain))))
2946 (defun message-user-mail-address ()
2947 "Return the pertinent part of `user-mail-address'."
2948 (when user-mail-address
2949 (if (string-match " " user-mail-address)
2950 (nth 1 (funcall gnus-extract-address-components user-mail-address))
2951 user-mail-address)))
2953 (defun message-make-fqdn ()
2954 "Return user's fully qualified domain name."
2955 (let ((system-name (system-name))
2956 (user-mail (message-user-mail-address)))
2958 ((string-match "[^.]\\.[^.]" system-name)
2959 ;; `system-name' returned the right result.
2961 ;; Try `mail-host-address'.
2962 ((and (boundp 'mail-host-address)
2963 (stringp mail-host-address)
2964 (string-match "\\." mail-host-address))
2966 ;; We try `user-mail-address' as a backup.
2968 (string-match "\\." user-mail)
2969 (string-match "@\\(.*\\)\\'" user-mail))
2970 (match-string 1 user-mail))
2971 ;; Default to this bogus thing.
2973 (concat system-name ".i-did-not-set--mail-host-address--so-shoot-me")))))
2975 (defun message-make-host-name ()
2976 "Return the name of the host."
2977 (let ((fqdn (message-make-fqdn)))
2978 (string-match "^[^.]+\\." fqdn)
2979 (substring fqdn 0 (1- (match-end 0)))))
2981 (defun message-make-domain ()
2982 "Return the domain name."
2983 (or mail-host-address
2984 (message-make-fqdn)))
2986 (defun message-generate-headers (headers)
2987 "Prepare article HEADERS.
2988 Headers already prepared in the buffer are not modified."
2990 (message-narrow-to-headers)
2991 (let* ((Date (message-make-date))
2992 (Message-ID (message-make-message-id))
2993 (Organization (message-make-organization))
2994 (From (message-make-from))
2995 (Path (message-make-path))
2998 (In-Reply-To (message-make-in-reply-to))
3000 (Distribution (message-make-distribution))
3001 (Lines (message-make-lines))
3002 (User-Agent message-user-agent)
3003 (Expires (message-make-expires))
3004 (case-fold-search t)
3006 ;; First we remove any old generated headers.
3007 (let ((headers message-deletable-headers))
3008 (unless (buffer-modified-p)
3009 (setq headers (delq 'Message-ID (copy-sequence headers))))
3011 (goto-char (point-min))
3012 (and (re-search-forward
3013 (concat "^" (symbol-name (car headers)) ": *") nil t)
3014 (get-text-property (1+ (match-beginning 0)) 'message-deletable)
3015 (message-delete-line))
3017 ;; Go through all the required headers and see if they are in the
3018 ;; articles already. If they are not, or are empty, they are
3019 ;; inserted automatically - except for Subject, Newsgroups and
3022 (goto-char (point-min))
3023 (setq elem (pop headers))
3025 (if (eq (car elem) 'optional)
3026 (setq header (cdr elem))
3027 (setq header (car elem)))
3029 (when (or (not (re-search-forward
3033 (if (stringp header)
3035 (symbol-name header))))
3039 ;; The header was found. We insert a space after the
3040 ;; colon, if there is none.
3041 (if (/= (following-char) ? ) (insert " ") (forward-char 1))
3042 ;; Find out whether the header is empty...
3043 (looking-at "[ \t]*$")))
3044 ;; So we find out what value we should insert.
3047 ((and (consp elem) (eq (car elem) 'optional))
3048 ;; This is an optional header. If the cdr of this
3049 ;; is something that is nil, then we do not insert
3051 (setq header (cdr elem))
3052 (or (and (fboundp (cdr elem)) (funcall (cdr elem)))
3053 (and (boundp (cdr elem)) (symbol-value (cdr elem)))))
3055 ;; The element is a cons. Either the cdr is a
3056 ;; string to be inserted verbatim, or it is a
3057 ;; function, and we insert the value returned from
3059 (or (and (stringp (cdr elem)) (cdr elem))
3060 (and (fboundp (cdr elem)) (funcall (cdr elem)))))
3061 ((and (boundp header) (symbol-value header))
3062 ;; The element is a symbol. We insert the value
3063 ;; of this symbol, if any.
3064 (symbol-value header))
3066 ;; We couldn't generate a value for this header,
3067 ;; so we just ask the user.
3068 (read-from-minibuffer
3069 (format "Empty header for %s; enter value: " header)))))
3070 ;; Finally insert the header.
3072 (not (equal value "")))
3076 ;; This header didn't exist, so we insert it.
3077 (goto-char (point-max))
3078 (insert (if (stringp header) header (symbol-name header))
3081 ;; The value of this header was empty, so we clear
3082 ;; totally and insert the new value.
3083 (delete-region (point) (gnus-point-at-eol))
3085 ;; Add the deletable property to the headers that require it.
3086 (and (memq header message-deletable-headers)
3087 (progn (beginning-of-line) (looking-at "[^:]+: "))
3088 (add-text-properties
3089 (point) (match-end 0)
3090 '(message-deletable t face italic) (current-buffer)))))))
3091 ;; Insert new Sender if the From is strange.
3092 (let ((from (message-fetch-field "from"))
3093 (sender (message-fetch-field "sender"))
3094 (secure-sender (message-make-sender)))
3096 (not (message-check-element 'sender))
3099 (cadr (funcall gnus-extract-address-components
3101 (downcase secure-sender)))
3106 (cadr (funcall gnus-extract-address-components
3108 (downcase secure-sender)))))
3109 (goto-char (point-min))
3110 ;; Rename any old Sender headers to Original-Sender.
3111 (when (re-search-forward "^\\(Original-\\)*Sender:" nil t)
3113 (insert "Original-")
3114 (beginning-of-line))
3115 (when (or (message-news-p)
3116 (string-match "@.+\\.." secure-sender))
3117 (insert "Sender: " secure-sender "\n")))))))
3119 (defun message-insert-courtesy-copy ()
3120 "Insert a courtesy message in mail copies of combined messages."
3124 (message-narrow-to-headers)
3125 (when (setq newsgroups (message-fetch-field "newsgroups"))
3126 (goto-char (point-max))
3127 (insert "Posted-To: " newsgroups "\n")))
3129 (when message-courtesy-message
3131 ((string-match "%s" message-courtesy-message)
3132 (insert (format message-courtesy-message newsgroups)))
3134 (insert message-courtesy-message)))))))
3137 ;;; Setting up a message buffer
3140 (defun message-fill-address (header value)
3142 (narrow-to-region (point) (point))
3143 (insert (capitalize (symbol-name header))
3145 (if (consp value) (car value) value)
3147 (narrow-to-region (point-min) (1- (point-max)))
3149 (goto-char (point-min))
3151 (skip-chars-forward "^,\"" (point-max))
3152 (if (or (= (following-char) ?,)
3158 (looking-at "[ \t]*")
3159 (replace-match "\n " t t)))
3160 (setq last (1+ (point))))
3161 (setq quoted (not quoted)))
3164 (goto-char (point-max))
3168 (defun message-fill-header (header value)
3169 (let ((begin (point))
3172 (insert (capitalize (symbol-name header))
3174 (if (consp value) (car value) value)
3177 (narrow-to-region begin (point))
3178 (fill-region-as-paragraph begin (point))
3179 ;; Tapdance around looong Message-IDs.
3181 (when (looking-at "[ \t]*$")
3182 (message-delete-line))
3184 (re-search-forward ":" nil t)
3185 (when (looking-at "\n[ \t]+")
3186 (replace-match " " t t))
3187 (goto-char (point-max)))))
3189 (defun message-shorten-references (header references)
3190 "Limit REFERENCES to be shorter than 988 characters."
3194 (nnheader-temp-write nil
3196 (goto-char (point-min))
3197 (while (re-search-forward "<[^>]+>" nil t)
3198 (push (match-string 0) refs))
3199 (setq refs (nreverse refs))
3200 (while (> (length (mapconcat 'identity refs " ")) max)
3201 (when (< (length refs) (1+ cut))
3203 (setcdr (nthcdr cut refs) (cddr (nthcdr cut refs)))))
3204 (insert (capitalize (symbol-name header)) ": "
3205 (mapconcat 'identity refs " ") "\n")))
3207 (defun message-position-point ()
3208 "Move point to where the user probably wants to find it."
3209 (message-narrow-to-headers)
3211 ((re-search-forward "^[^:]+:[ \t]*$" nil t)
3212 (search-backward ":" )
3215 (if (= (following-char) ? )
3219 (goto-char (point-max))
3222 (unless (looking-at "$")
3226 (defun message-buffer-name (type &optional to group)
3227 "Return a new (unique) buffer name based on TYPE and TO."
3229 ;; Check whether `message-generate-new-buffers' is a function,
3230 ;; and if so, call it.
3231 ((message-functionp message-generate-new-buffers)
3232 (funcall message-generate-new-buffers type to group))
3233 ;; Generate a new buffer name The Message Way.
3234 (message-generate-new-buffers
3235 (generate-new-buffer-name
3239 (or (car (funcall gnus-extract-address-components to))
3242 (if (and group (not (string= group ""))) (concat " on " group) "")
3244 ;; Use standard name.
3246 (format "*%s message*" type))))
3248 (defun message-pop-to-buffer (name)
3249 "Pop to buffer NAME, and warn if it already exists and is modified."
3250 (let ((buffer (get-buffer name))
3251 (cur (current-buffer)))
3253 (buffer-name buffer))
3255 (set-buffer (pop-to-buffer buffer))
3256 (when (and (buffer-modified-p)
3258 "Message already being composed; erase? ")))
3259 (error "Message being composed")))
3260 (set-buffer (pop-to-buffer name)))
3264 (defun message-do-send-housekeeping ()
3265 "Kill old message buffers."
3266 ;; We might have sent this buffer already. Delete it from the
3268 (setq message-buffer-list (delq (current-buffer) message-buffer-list))
3269 (while (and message-max-buffers
3271 (>= (length message-buffer-list) message-max-buffers))
3272 ;; Kill the oldest buffer -- unless it has been changed.
3273 (let ((buffer (pop message-buffer-list)))
3274 (when (and (buffer-name buffer)
3275 (not (buffer-modified-p buffer)))
3276 (kill-buffer buffer))))
3277 ;; Rename the buffer.
3278 (if message-send-rename-function
3279 (funcall message-send-rename-function)
3280 (when (string-match "\\`\\*" (buffer-name))
3282 (concat "*sent " (substring (buffer-name) (match-end 0))) t)))
3283 ;; Push the current buffer onto the list.
3284 (when message-max-buffers
3285 (setq message-buffer-list
3286 (nconc message-buffer-list (list (current-buffer))))))
3288 (defvar mc-modes-alist)
3289 (defun message-setup (headers &optional replybuffer actions)
3290 (when (and (boundp 'mc-modes-alist)
3291 (not (assq 'message-mode mc-modes-alist)))
3292 (push '(message-mode (encrypt . mc-encrypt-message)
3293 (sign . mc-sign-message))
3296 (setq message-send-actions actions))
3297 (setq message-reply-buffer replybuffer)
3298 (goto-char (point-min))
3299 ;; Insert all the headers.
3302 (alist message-header-format-alist))
3304 (unless (assq (caar h) message-header-format-alist)
3305 (push (list (caar h)) alist))
3309 (delete-region (point) (progn (forward-line -1) (point)))
3310 (when message-default-headers
3311 (insert message-default-headers)
3312 (or (bolp) (insert ?\n)))
3316 (insert mail-header-separator "\n")
3320 (when (message-news-p)
3321 (when message-default-news-headers
3322 (insert message-default-news-headers)
3323 (or (bolp) (insert ?\n)))
3324 (when message-generate-headers-first
3325 (message-generate-headers
3328 (copy-sequence message-required-news-headers))))))
3329 (when (message-mail-p)
3330 (when message-default-mail-headers
3331 (insert message-default-mail-headers)
3332 (or (bolp) (insert ?\n)))
3333 (when message-generate-headers-first
3334 (message-generate-headers
3337 (copy-sequence message-required-mail-headers))))))
3338 (run-hooks 'message-signature-setup-hook)
3339 (message-insert-signature)
3341 (message-narrow-to-headers)
3342 (run-hooks 'message-header-setup-hook))
3343 (set-buffer-modified-p nil)
3344 (setq buffer-undo-list nil)
3345 (run-hooks 'message-setup-hook)
3346 (message-position-point)
3349 (defun message-set-auto-save-file-name ()
3350 "Associate the message buffer with a file in the drafts directory."
3351 (when message-autosave-directory
3353 (setq message-draft-article
3354 (nndraft-request-associate-buffer "drafts"))
3355 (setq buffer-file-name (expand-file-name "*message*"
3356 message-autosave-directory))
3357 (setq buffer-auto-save-file-name (make-auto-save-file-name)))
3358 (clear-visited-file-modtime)))
3360 (defun message-disassociate-draft ()
3361 "Disassociate the message buffer from the drafts directory."
3362 (when message-draft-article
3363 (nndraft-request-expire-articles
3364 (list message-draft-article) "drafts" nil t)))
3369 ;;; Commands for interfacing with message
3373 (defun message-mail (&optional to subject
3374 other-headers continue switch-function
3375 yank-action send-actions)
3376 "Start editing a mail message to be sent."
3378 (let ((message-this-is-mail t))
3379 (message-pop-to-buffer (message-buffer-name "mail" to))
3382 `((To . ,(or to "")) (Subject . ,(or subject "")))
3383 (when other-headers other-headers)))))
3386 (defun message-news (&optional newsgroups subject)
3387 "Start editing a news article to be sent."
3389 (let ((message-this-is-news t))
3390 (message-pop-to-buffer (message-buffer-name "news" nil newsgroups))
3391 (message-setup `((Newsgroups . ,(or newsgroups ""))
3392 (Subject . ,(or subject ""))))))
3395 (defun message-reply (&optional to-address wide)
3396 "Start editing a reply to the article in the current buffer."
3398 (let ((cur (current-buffer))
3399 (inhibit-point-motion-hooks t)
3400 from date subject mct mft mrt
3402 references message-id follow-to gnus-warning)
3404 (message-narrow-to-head)
3405 ;; Allow customizations to have their say.
3407 ;; This is a regular reply.
3408 (if (message-functionp message-reply-to-function)
3409 (setq follow-to (funcall message-reply-to-function)))
3410 ;; This is a followup.
3411 (if (message-functionp message-wide-reply-to-function)
3414 (funcall message-wide-reply-to-function)))))
3415 ;; Find all relevant headers we need.
3416 (setq from (message-fetch-field "from")
3417 date (message-fetch-field "date" t)
3418 subject (or (message-fetch-field "subject") "none")
3419 references (message-fetch-field "references")
3420 message-id (message-fetch-field "message-id" t)
3421 to (message-fetch-field "to")
3422 cc (message-fetch-field "cc")
3423 mct (when (and wide message-use-mail-copies-to)
3424 (message-fetch-field "mail-copies-to"))
3425 mft (when (and wide message-use-mail-followup-to)
3426 (message-fetch-field "mail-followup-to"))
3427 mrt (when message-use-mail-reply-to
3428 (or (message-fetch-field "mail-reply-to")
3429 (message-fetch-field "reply-to")))
3430 gnus-warning (message-fetch-field "gnus-warning"))
3431 (when (and gnus-warning (string-match "<[^>]+>" gnus-warning))
3432 (setq message-id (match-string 0 gnus-warning)))
3433 ;; Remove any (buggy) Re:'s that are present and make a
3435 (setq subject (message-make-followup-subject subject))
3438 ;; Handle special values of Mail-Copies-To.
3441 ((and (equal (downcase mct) "never")
3442 (or (not (eq message-use-mail-copies-to 'ask))
3444 (concat "Obey Mail-Copies-To: never? ") t "\
3445 You should normally obey the Mail-Copies-To: header.
3447 `Mail-Copies-To: never'
3448 directs you not to send your response to the author.")))
3451 ((and (equal (downcase mct) "always")
3452 (or (not (eq message-use-mail-copies-to 'ask))
3454 (concat "Obey Mail-Copies-To: always? ") t "\
3455 You should normally obey the Mail-Copies-To: header.
3457 `Mail-Copies-To: always'
3458 sends a copy of your response to the author.")))
3459 (setq mct (or mrt from)))
3460 ((and (eq message-use-mail-copies-to 'ask)
3463 (concat "Obey Mail-Copies-To: " mct " ? ") t "\
3464 You should normally obey the Mail-Copies-To: header.
3466 `Mail-Copies-To: " mct "'
3467 sends a copy of your response to " (if (string-match "," mct)
3468 "the specified addresses"
3469 "that address") ".")))
3475 (to-address (setq follow-to (list (cons 'To to-address))))
3476 ((not wide) (setq follow-to (list (cons 'To (or mrt from)))))
3477 ;; Handle Mail-Followup-To.
3479 (or (not (eq message-use-mail-followup-to 'ask))
3481 (concat "Obey Mail-Followup-To: " mft "? ") t "\
3482 You should normally obey the Mail-Followup-To: header.
3484 `Mail-Followup-To: " mft "'
3485 directs your response to " (if (string-match "," mft)
3486 "the specified addresses"
3487 "that address only") ".
3489 A typical situation where Mail-Followup-To is used is when the author thinks
3490 that further discussion should take place only in "
3491 (if (string-match "," mft)
3492 "the specified mailing lists"
3493 "that mailing list") ".")))
3494 (setq follow-to (list (cons 'To mft)))
3496 (push (cons 'Cc mct) follow-to)))
3500 (message-set-work-buffer)
3502 (insert (or mrt from "")))
3503 (insert (if to (concat (if (bolp) "" ", ") to "") ""))
3504 (insert (if mct (concat (if (bolp) "" ", ") mct) ""))
3505 (insert (if cc (concat (if (bolp) "" ", ") cc) ""))
3506 (goto-char (point-min))
3507 (while (re-search-forward "[ \t]+" nil t)
3508 (replace-match " " t t))
3509 ;; Remove addresses that match `rmail-dont-reply-to-names'.
3510 (insert (prog1 (rmail-dont-reply-to (buffer-string))
3512 (goto-char (point-min))
3513 ;; Perhaps Mail-Copies-To: never removed the only address?
3515 (insert (or mrt from "")))
3519 (cons (mail-strip-quoted-names addr) addr))
3520 (message-tokenize-header (buffer-string))))
3523 (setq ccalist (delq (assoc (car (pop s)) s) ccalist)))))
3524 (setq follow-to (list (cons 'To (cdr (pop ccalist)))))
3526 (let ((ccs (cons 'Cc (mapconcat
3527 (lambda (addr) (cdr addr)) ccalist ", "))))
3528 (when (string-match "^ +" (cdr ccs))
3529 (setcdr ccs (substring (cdr ccs) (match-end 0))))
3530 (push ccs follow-to)))))))
3532 (message-pop-to-buffer (message-buffer-name
3533 (if wide "wide reply" "reply") from
3534 (if wide to-address nil)))
3536 (setq message-reply-headers
3537 (vector 0 subject from date message-id references 0 0 ""))
3540 `((Subject . ,subject)
3542 ,@(if (or references message-id)
3543 `((References . ,(concat (or references "") (and references " ")
3544 (or message-id ""))))))
3548 (defun message-wide-reply (&optional to-address)
3549 "Make a \"wide\" reply to the message in the current buffer."
3551 (message-reply to-address t))
3554 (defun message-followup (&optional to-newsgroups)
3555 "Follow up to the message in the current buffer."
3557 (let ((cur (current-buffer))
3558 (inhibit-point-motion-hooks t)
3559 from date subject mct mft mrt
3560 (message-this-is-news t)
3561 followup-to distribution newsgroups posted-to
3562 references message-id follow-to gnus-warning)
3564 (message-narrow-to-head)
3565 ;; Allow customizations to have their say.
3566 ;; This is a followup.
3567 (when (message-functionp message-followup-to-function)
3569 (funcall message-followup-to-function)))
3570 ;; Find all relevant headers we need.
3571 (setq from (message-fetch-field "from")
3572 date (message-fetch-field "date" t)
3573 subject (or (message-fetch-field "subject") "none")
3574 references (message-fetch-field "references")
3575 message-id (message-fetch-field "message-id" t)
3576 followup-to (when message-use-followup-to
3577 (message-fetch-field "followup-to"))
3578 distribution (message-fetch-field "distribution")
3579 newsgroups (message-fetch-field "newsgroups")
3580 posted-to (message-fetch-field "posted-to")
3581 mct (when message-use-mail-copies-to
3582 (message-fetch-field "mail-copies-to"))
3583 mft (when message-use-mail-followup-to
3584 (message-fetch-field "mail-followup-to"))
3585 mrt (when message-use-mail-reply-to
3586 (or (message-fetch-field "mail-reply-to")
3587 (message-fetch-field "reply-to")))
3588 gnus-warning (message-fetch-field "gnus-warning"))
3589 (when (and gnus-warning (string-match "<[^>]+>" gnus-warning))
3590 (setq message-id (match-string 0 gnus-warning)))
3591 ;; Remove bogus distribution.
3592 (when (and (stringp distribution)
3593 (let ((case-fold-search t))
3594 (string-match "world" distribution)))
3595 (setq distribution nil))
3596 ;; Remove any (buggy) Re:'s that are present and make a
3598 (setq subject (message-make-followup-subject subject))
3601 ;; Handle special values of Mail-Copies-To.
3604 ((and (equal (downcase mct) "never")
3605 (or (not (eq message-use-mail-copies-to 'ask))
3607 (concat "Obey Mail-Copies-To: never? ") t "\
3608 You should normally obey the Mail-Copies-To: header.
3610 `Mail-Copies-To: never'
3611 directs you not to send your response to the author.")))
3613 ((and (equal (downcase mct) "always")
3614 (or (not (eq message-use-mail-copies-to 'ask))
3616 (concat "Obey Mail-Copies-To: always? ") t "\
3617 You should normally obey the Mail-Copies-To: header.
3619 `Mail-Copies-To: always'
3620 sends a copy of your response to the author.")))
3621 (setq mct (or mrt from)))
3622 ((and (eq message-use-mail-copies-to 'ask)
3625 (concat "Obey Mail-Copies-To: " mct " ? ") t "\
3626 You should normally obey the Mail-Copies-To: header.
3628 `Mail-Copies-To: " mct "'
3629 sends a copy of your response to " (if (string-match "," mct)
3630 "the specified addresses"
3631 "that address") ".")))
3637 (to-newsgroups (setq follow-to (list (cons 'Newsgroups to-newsgroups))))
3638 ;; Handle Followup-To.
3641 ((equal (downcase followup-to) "poster")
3642 (if (or (eq message-use-followup-to 'use)
3643 (message-y-or-n-p "Obey Followup-To: poster? " t "\
3644 You should normally obey the Followup-To: header.
3646 `Followup-To: poster'
3647 sends your response via e-mail instead of news.
3649 A typical situation where `Followup-To: poster' is used is when the author
3650 does not read the newsgroup, so he wouldn't see any replies sent to it."))
3651 (setq message-this-is-news nil
3653 follow-to (list (cons 'To (or mrt from ""))))
3654 (setq follow-to (list (cons 'Newsgroups newsgroups)))))
3656 (if (or (equal followup-to newsgroups)
3657 (not (eq message-use-followup-to 'ask))
3659 (concat "Obey Followup-To: " followup-to "? ") t "\
3660 You should normally obey the Followup-To: header.
3662 `Followup-To: " followup-to "'
3663 directs your response to " (if (string-match "," followup-to)
3664 "the specified newsgroups"
3665 "that newsgroup only") ".
3667 If a message is posted to several newsgroups, Followup-To is often
3668 used to direct the following discussion to one newsgroup only,
3669 because discussions that are spread over several newsgroup tend to
3670 be fragmented and very difficult to follow.
3672 Also, some source/announcement newsgroups are not indented for discussion;
3673 responses here are directed to other newsgroups."))
3674 (setq follow-to (list (cons 'Newsgroups followup-to)))
3675 (setq follow-to (list (cons 'Newsgroups newsgroups)))))))
3676 ;; Handle Mail-Followup-To, followup via e-mail.
3678 (or (not (eq message-use-mail-followup-to 'ask))
3680 (concat "Obey Mail-Followup-To: " mft "? ") t "\
3681 You should normally obey the Mail-Followup-To: header.
3683 `Mail-Followup-To: " mft "'
3684 directs your response to " (if (string-match "," mft)
3685 "the specified addresses"
3686 "that address only") " instead of news.
3688 A typical situation where Mail-Followup-To is used is when the author thinks
3689 that further discussion should take place only in "
3690 (if (string-match "," mft)
3691 "the specified mailing lists"
3692 "that mailing list") ".")))
3693 (setq message-this-is-news nil
3695 follow-to (list (cons 'To mft))))
3696 (posted-to (setq follow-to (list (cons 'Newsgroups posted-to))))
3698 (setq follow-to (list (cons 'Newsgroups newsgroups))))))
3700 (message-pop-to-buffer (message-buffer-name "followup" from newsgroups))
3702 (setq message-reply-headers
3703 (vector 0 subject from date message-id references 0 0 ""))
3706 `((Subject . ,subject)
3708 ,@(and mct (list (cons 'Cc mct)))
3709 ,@(and distribution (list (cons 'Distribution distribution)))
3710 ,@(if (or references message-id)
3711 `((References . ,(concat (or references "") (and references " ")
3712 (or message-id ""))))))
3716 (defun message-cancel-news ()
3717 "Cancel an article you posted."
3719 (unless (message-news-p)
3720 (error "This is not a news article; canceling is impossible"))
3721 (when (yes-or-no-p "Do you really want to cancel this article? ")
3722 (let (from newsgroups message-id distribution buf sender)
3724 ;; Get header info. from original article.
3726 (message-narrow-to-head)
3727 (setq from (message-fetch-field "from")
3728 sender (message-fetch-field "sender")
3729 newsgroups (message-fetch-field "newsgroups")
3730 message-id (message-fetch-field "message-id" t)
3731 distribution (message-fetch-field "distribution")))
3732 ;; Make sure that this article was written by the user.
3733 (unless (or (and sender
3736 (downcase (message-make-sender))))
3738 (downcase (cadr (funcall gnus-extract-address-components
3740 (downcase (cadr (funcall gnus-extract-address-components
3741 (message-make-from))))))
3742 (error "This article is not yours"))
3743 ;; Make control message.
3744 (setq buf (set-buffer (get-buffer-create " *message cancel*")))
3745 (buffer-disable-undo (current-buffer))
3747 (insert "Newsgroups: " newsgroups "\n"
3748 "From: " (message-make-from) "\n"
3749 "Subject: cmsg cancel " message-id "\n"
3750 "Control: cancel " message-id "\n"
3752 (concat "Distribution: " distribution "\n")
3754 mail-header-separator "\n"
3755 message-cancel-message)
3756 (message "Canceling your article...")
3757 (if (let ((message-syntax-checks
3758 'dont-check-for-anything-just-trust-me)
3759 (message-encoding-buffer (current-buffer))
3760 (message-edit-buffer (current-buffer)))
3761 (message-send-news))
3762 (message "Canceling your article...done"))
3763 (kill-buffer buf)))))
3766 (defun message-supersede ()
3767 "Start composing a message to supersede the current message.
3768 This is done simply by taking the old article and adding a Supersedes
3769 header line with the old Message-ID."
3771 (let ((cur (current-buffer)))
3772 ;; Check whether the user owns the article that is to be superseded.
3773 (unless (string-equal
3774 (downcase (or (message-fetch-field "sender")
3775 (cadr (funcall gnus-extract-address-components
3776 (message-fetch-field "from")))))
3777 (downcase (message-make-sender)))
3778 (error "This article is not yours"))
3779 ;; Get a normal message buffer.
3780 (message-pop-to-buffer (message-buffer-name "supersede"))
3781 (insert-buffer-substring cur)
3782 (message-narrow-to-head)
3783 ;; Remove unwanted headers.
3784 (when message-ignored-supersedes-headers
3785 (message-remove-header message-ignored-supersedes-headers t))
3786 (goto-char (point-min))
3787 (if (not (re-search-forward "^Message-ID: " nil t))
3788 (error "No Message-ID in this article")
3789 (replace-match "Supersedes: " t t))
3790 (goto-char (point-max))
3791 (insert mail-header-separator)
3796 (defun message-recover ()
3797 "Reread contents of current buffer from its last auto-save file."
3799 (let ((file-name (make-auto-save-file-name)))
3800 (cond ((save-window-excursion
3801 (if (not (eq system-type 'vax-vms))
3802 (with-output-to-temp-buffer "*Directory*"
3803 (buffer-disable-undo standard-output)
3804 (let ((default-directory "/"))
3806 "ls" nil standard-output nil "-l" file-name))))
3807 (yes-or-no-p (format "Recover auto save file %s? " file-name)))
3808 (let ((buffer-read-only nil))
3810 (insert-file-contents file-name nil)))
3811 (t (error "message-recover cancelled")))))
3813 ;;; Forwarding messages.
3815 (defun message-make-forward-subject ()
3816 "Return a Subject header suitable for the message in the current buffer."
3820 (message-narrow-to-head)
3821 (concat "[" (or (message-fetch-field
3822 (if (message-news-p) "newsgroups" "from"))
3824 "] " (or (eword-decode-unstructured-field-body
3825 (message-fetch-field "Subject") ""))))))
3828 (defun message-forward (&optional news)
3829 "Forward the current message via mail.
3830 Optional NEWS will use news to forward instead of mail."
3832 (let ((cur (current-buffer))
3833 (subject (message-make-forward-subject))
3835 (if news (message-news nil subject) (message-mail nil subject))
3836 ;; Put point where we want it before inserting the forwarded
3838 (if message-signature-before-forwarded-message
3839 (goto-char (point-max))
3840 (message-goto-body))
3841 ;; Make sure we're at the start of the line.
3844 ;; Narrow to the area we are to insert.
3845 (narrow-to-region (point) (point))
3846 ;; Insert the separators and the forwarded buffer.
3847 (insert message-forward-start-separator)
3848 (setq art-beg (point))
3849 (insert-buffer-substring cur)
3850 (goto-char (point-max))
3851 (insert message-forward-end-separator)
3852 (set-text-properties (point-min) (point-max) nil)
3853 ;; Remove all unwanted headers.
3855 (narrow-to-region (point) (if (search-forward "\n\n" nil t)
3858 (goto-char (point-min))
3859 (message-remove-header message-included-forward-headers t nil t)
3861 (message-position-point)))
3864 (defun message-resend (address)
3865 "Resend the current article to ADDRESS."
3866 (interactive "sResend message to: ")
3867 (message "Resending message to %s..." address)
3869 (let ((cur (current-buffer))
3871 ;; We first set up a normal mail buffer.
3872 (set-buffer (get-buffer-create " *message resend*"))
3873 (buffer-disable-undo (current-buffer))
3875 ;; avoid to turn-on-mime-edit
3876 (let (message-setup-hook)
3877 (message-setup `((To . ,address)))
3879 ;; Insert our usual headers.
3880 (message-generate-headers '(From Date To))
3881 (message-narrow-to-headers)
3882 ;; Rename them all to "Resent-*".
3883 (while (re-search-forward "^[A-Za-z]" nil t)
3888 (delete-region (point) (point-max))
3890 ;; Insert the message to be resent.
3891 (insert-buffer-substring cur)
3892 (goto-char (point-min))
3893 (search-forward "\n\n")
3896 (narrow-to-region beg (point))
3897 (message-remove-header message-ignored-resent-headers t)
3898 (goto-char (point-max)))
3899 (insert mail-header-separator)
3900 ;; Rename all old ("Also-")Resent headers.
3901 (while (re-search-backward "^\\(Also-\\)*Resent-" beg t)
3904 ;; Quote any "From " lines at the beginning.
3906 (when (looking-at "From ")
3907 (replace-match "X-From-Line: "))
3909 (let ((message-encoding-buffer (current-buffer))
3910 (message-edit-buffer (current-buffer)))
3911 (message-send-mail))
3912 (kill-buffer (current-buffer)))
3913 (message "Resending message to %s...done" address)))
3916 (defun message-bounce ()
3917 "Re-mail the current message.
3918 This only makes sense if the current message is a bounce message than
3919 contains some mail you have written which has been bounced back to
3922 (let ((cur (current-buffer))
3924 (message-pop-to-buffer (message-buffer-name "bounce"))
3925 (insert-buffer-substring cur)
3927 (message-narrow-to-head)
3928 (if (and (message-fetch-field "MIME-Version")
3929 (setq boundary (message-fetch-field "Content-Type")))
3930 (if (string-match "boundary=\"\\([^\"]+\\)\"" boundary)
3931 (setq boundary (concat (match-string 1 boundary) " *\n"
3932 "Content-Type: message/rfc822"))
3933 (setq boundary nil)))
3935 (goto-char (point-min))
3936 (search-forward "\n\n" nil t)
3938 (re-search-forward boundary nil t)
3940 (and (re-search-forward message-unsent-separator nil t)
3942 (re-search-forward "^Return-Path:.*\n" nil t))
3943 ;; We remove everything before the bounced mail.
3946 (if (re-search-forward "^[^ \n\t]+:" nil t)
3950 (message-narrow-to-head)
3951 (message-remove-header message-ignored-bounced-headers t)
3952 (goto-char (point-max))
3953 (insert mail-header-separator))
3954 (message-position-point)))
3957 ;;; Interactive entry points for new message buffers.
3961 (defun message-mail-other-window (&optional to subject)
3962 "Like `message-mail' command, but display mail buffer in another window."
3964 (let ((pop-up-windows t)
3965 (special-display-buffer-names nil)
3966 (special-display-regexps nil)
3967 (same-window-buffer-names nil)
3968 (same-window-regexps nil))
3969 (message-pop-to-buffer (message-buffer-name "mail" to)))
3970 (let ((message-this-is-mail t))
3971 (message-setup `((To . ,(or to "")) (Subject . ,(or subject ""))))))
3974 (defun message-mail-other-frame (&optional to subject)
3975 "Like `message-mail' command, but display mail buffer in another frame."
3977 (let ((pop-up-frames t)
3978 (special-display-buffer-names nil)
3979 (special-display-regexps nil)
3980 (same-window-buffer-names nil)
3981 (same-window-regexps nil))
3982 (message-pop-to-buffer (message-buffer-name "mail" to)))
3983 (let ((message-this-is-mail t))
3984 (message-setup `((To . ,(or to "")) (Subject . ,(or subject ""))))))
3987 (defun message-news-other-window (&optional newsgroups subject)
3988 "Start editing a news article to be sent."
3990 (let ((pop-up-windows t)
3991 (special-display-buffer-names nil)
3992 (special-display-regexps nil)
3993 (same-window-buffer-names nil)
3994 (same-window-regexps nil))
3995 (message-pop-to-buffer (message-buffer-name "news" nil newsgroups)))
3996 (let ((message-this-is-news t))
3997 (message-setup `((Newsgroups . ,(or newsgroups ""))
3998 (Subject . ,(or subject ""))))))
4001 (defun message-news-other-frame (&optional newsgroups subject)
4002 "Start editing a news article to be sent."
4004 (let ((pop-up-frames t)
4005 (special-display-buffer-names nil)
4006 (special-display-regexps nil)
4007 (same-window-buffer-names nil)
4008 (same-window-regexps nil))
4009 (message-pop-to-buffer (message-buffer-name "news" nil newsgroups)))
4010 (let ((message-this-is-news t))
4011 (message-setup `((Newsgroups . ,(or newsgroups ""))
4012 (Subject . ,(or subject ""))))))
4016 ;; This code should be moved to underline.el (from which it is stolen).
4019 (defun bold-region (start end)
4020 "Bold all nonblank characters in the region.
4021 Works by overstriking characters.
4022 Called from program, takes two arguments START and END
4023 which specify the range to operate on."
4026 (let ((end1 (make-marker)))
4027 (move-marker end1 (max start end))
4028 (goto-char (min start end))
4029 (while (< (point) end1)
4030 (or (looking-at "[_\^@- ]")
4031 (insert (following-char) "\b"))
4032 (forward-char 1)))))
4035 (defun unbold-region (start end)
4036 "Remove all boldness (overstruck characters) in the region.
4037 Called from program, takes two arguments START and END
4038 which specify the range to operate on."
4041 (let ((end1 (make-marker)))
4042 (move-marker end1 (max start end))
4043 (goto-char (min start end))
4044 (while (re-search-forward "\b" end1 t)
4045 (if (eq (following-char) (char-after (- (point) 2)))
4046 (delete-char -2))))))
4048 (defalias 'message-exchange-point-and-mark 'exchange-point-and-mark)
4050 ;; Support for toolbar
4051 (when (string-match "XEmacs\\|Lucid" emacs-version)
4052 (require 'messagexmas))
4054 ;;; Group name completion.
4056 (defvar message-newgroups-header-regexp
4057 "^\\(Newsgroups\\|Followup-To\\|Posted-To\\|Gcc\\):"
4058 "Regexp that match headers that lists groups.")
4060 (defun message-tab ()
4061 "Expand group names in Newsgroups and Followup-To headers.
4062 Do a `tab-to-tab-stop' if not in those headers."
4064 (if (let ((mail-abbrev-mode-regexp message-newgroups-header-regexp))
4065 (mail-abbrev-in-expansion-header-p))
4066 (message-expand-group)
4069 (defvar gnus-active-hashtb)
4070 (defun message-expand-group ()
4071 "Expand the group name under point."
4072 (let* ((b (save-excursion
4077 (skip-chars-forward "^:")
4080 (skip-chars-backward "^, \t\n") (point))))
4081 (completion-ignore-case t)
4082 (string (buffer-substring b (progn (skip-chars-forward "^,\t\n ")
4084 (hashtb (and (boundp 'gnus-active-hashtb) gnus-active-hashtb))
4085 (completions (all-completions string hashtb))
4086 (cur (current-buffer))
4088 (delete-region b (point))
4090 ((= (length completions) 1)
4091 (if (string= (car completions) string)
4094 (message "Only matching group"))
4095 (insert (car completions))))
4096 ((and (setq comp (try-completion string hashtb))
4097 (not (string= comp string)))
4102 (message "No matching groups")
4103 (save-selected-window
4104 (pop-to-buffer "*Completions*")
4105 (buffer-disable-undo (current-buffer))
4106 (let ((buffer-read-only nil))
4108 (let ((standard-output (current-buffer)))
4109 (display-completion-list (sort completions 'string<)))
4110 (goto-char (point-min))
4111 (delete-region (point) (progn (forward-line 3) (point))))))))))
4115 (defun message-talkative-question (ask question show &rest text)
4116 "Call FUNCTION with argument QUESTION; optionally display TEXT... args.
4117 If SHOW is non-nil, the arguments TEXT... are displayed in a temp buffer.
4118 The following arguments may contain lists of values."
4120 (setq text (message-flatten-list text)))
4121 (save-window-excursion
4123 (with-output-to-temp-buffer " *MESSAGE information message*"
4124 (set-buffer " *MESSAGE information message*")
4125 (mapcar 'princ text)
4126 (goto-char (point-min))))
4127 (funcall ask question))
4128 (funcall ask question)))
4130 (defun message-flatten-list (list)
4131 "Return a new, flat list that contains all elements of LIST.
4133 \(message-flatten-list '(1 (2 3 (4 5 (6))) 7))
4136 (apply 'append (mapcar 'message-flatten-list list)))
4140 (defun message-generate-new-buffer-clone-locals (name &optional varstr)
4141 "Create and return a buffer with a name based on NAME using generate-new-buffer.
4142 Then clone the local variables and values from the old buffer to the
4143 new one, cloning only the locals having a substring matching the
4145 (let ((oldbuf (current-buffer)))
4147 (set-buffer (generate-new-buffer name))
4148 (message-clone-locals oldbuf)
4151 (defun message-clone-locals (buffer)
4152 "Clone the local variables from BUFFER to the current buffer."
4153 (let ((locals (save-excursion
4155 (buffer-local-variables)))
4156 (regexp "^gnus\\|^nn\\|^message"))
4159 (when (and (consp local)
4161 (string-match regexp (symbol-name (car local))))
4163 (set (make-local-variable (car local))
4168 ;;; @ for MIME Edit mode
4171 (defun message-maybe-setup-default-charset ()
4173 (and (boundp 'gnus-summary-buffer)
4174 (buffer-live-p gnus-summary-buffer)
4176 (set-buffer gnus-summary-buffer)
4177 default-mime-charset))))
4180 (make-local-variable 'default-mime-charset)
4181 (setq default-mime-charset charset)
4184 (defun message-maybe-encode ()
4185 (when message-mime-mode
4186 (run-hooks 'mime-edit-translate-hook)
4187 (if (catch 'mime-edit-error
4189 (mime-edit-translate-body)
4191 (error "Translation error!")
4194 (run-hooks 'mime-edit-exit-hook)
4197 (defun message-mime-insert-article (&optional message)
4199 (let ((message-cite-function 'mime-edit-inserted-message-filter)
4200 (message-reply-buffer gnus-original-article-buffer)
4202 (message-yank-original nil)
4205 (set-alist 'mime-edit-message-inserter-alist
4206 'message-mode (function message-mime-insert-article))
4208 ;;; Miscellaneous functions
4210 ;; stolen (and renamed) from nnheader.el
4211 (defun message-replace-chars-in-string (string from to)
4212 "Replace characters in STRING from FROM to TO."
4213 (let ((string (substring string 0)) ;Copy string.
4214 (len (length string))
4216 ;; Replace all occurrences of FROM with TO.
4218 (when (= (aref string idx) from)
4219 (aset string idx to))
4220 (setq idx (1+ idx)))
4223 (run-hooks 'message-load-hook)
4227 ;;; message.el ends here