1 ;;; message.el --- composing mail and news messages
2 ;; Copyright (C) 1996,97,98,99 Free Software Foundation, Inc.
4 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
5 ;; MORIOKA Tomohiko <morioka@jaist.ac.jp>
6 ;; Shuhei KOBAYASHI <shuhei-k@jaist.ac.jp>
7 ;; Keiichi Suzuki <kei-suzu@mail.wbs.ne.jp>
8 ;; Tatsuya Ichikawa <t-ichi@po.shiojiri.ne.jp>
9 ;; Katsumi Yamaoka <yamaoka@jpl.org>
10 ;; Kiyokazu SUTO <suto@merry.xmath.ous.ac.jp>
11 ;; Keywords: mail, news, MIME
13 ;; This file is part of GNU Emacs.
15 ;; GNU Emacs is free software; you can redistribute it and/or modify
16 ;; it under the terms of the GNU General Public License as published by
17 ;; the Free Software Foundation; either version 2, or (at your option)
20 ;; GNU Emacs is distributed in the hope that it will be useful,
21 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
22 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 ;; GNU General Public License for more details.
25 ;; You should have received a copy of the GNU General Public License
26 ;; along with GNU Emacs; see the file COPYING. If not, write to the
27 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
28 ;; Boston, MA 02111-1307, USA.
32 ;; This mode provides mail-sending facilities from within Emacs. It
33 ;; consists mainly of large chunks of code from the sendmail.el,
34 ;; gnus-msg.el and rnewspost.el files.
38 (eval-when-compile (require 'cl))
39 (eval-when-compile (require 'smtp))
44 (if (string-match "XEmacs\\|Lucid" emacs-version)
45 (require 'mail-abbrevs)
46 (require 'mailabbrev))
48 (eval-when-compile (require 'static))
50 ;; Avoid byte-compile warnings.
58 (defgroup message '((user-mail-address custom-variable)
59 (user-full-name custom-variable))
60 "Mail and news message composing."
61 :link '(custom-manual "(message)Top")
65 (put 'user-mail-address 'custom-type 'string)
66 (put 'user-full-name 'custom-type 'string)
68 (defgroup message-various nil
69 "Various Message Variables"
70 :link '(custom-manual "(message)Various Message Variables")
73 (defgroup message-buffers nil
75 :link '(custom-manual "(message)Message Buffers")
78 (defgroup message-sending nil
80 :link '(custom-manual "(message)Sending Variables")
83 (defgroup message-interface nil
85 :link '(custom-manual "(message)Interface")
88 (defgroup message-forwarding nil
90 :link '(custom-manual "(message)Forwarding")
91 :group 'message-interface)
93 (defgroup message-insertion nil
95 :link '(custom-manual "(message)Insertion")
98 (defgroup message-headers nil
100 :link '(custom-manual "(message)Message Headers")
103 (defgroup message-news nil
104 "Composing News Messages"
107 (defgroup message-mail nil
108 "Composing Mail Messages"
111 (defgroup message-faces nil
112 "Faces used for message composing."
116 (defgroup message-frames nil
120 (defcustom message-directory "~/Mail/"
121 "*Directory from which all other mail file variables are derived."
122 :group 'message-various
125 (defcustom message-max-buffers 10
126 "*How many buffers to keep before starting to kill them off."
127 :group 'message-buffers
130 (defcustom message-send-rename-function nil
131 "Function called to rename the buffer after sending it."
132 :group 'message-buffers
135 (defcustom message-fcc-handler-function 'message-output
136 "*A function called to save outgoing articles.
137 This function will be called with the name of the file to store the
138 article in. The default function is `message-output' which saves in Unix
140 :type '(radio (function-item message-output)
141 (function :tag "Other"))
142 :group 'message-sending)
144 (defcustom message-encode-function 'message-maybe-encode
145 "*A function called to encode messages."
146 :group 'message-sending
149 (defcustom message-8bit-encoding-list '(8bit binary)
150 "*8bit encoding type in Content-Transfer-Encoding field."
151 :group 'message-sending
152 :type '(repeat (symbol :tag "Type")))
154 (defcustom message-courtesy-message
155 "The following message is a courtesy copy of an article\nthat has been posted to %s as well.\n\n"
156 "*This is inserted at the start of a mailed copy of a posted message.
157 If the string contains the format spec \"%s\", the Newsgroups
158 the article has been posted to will be inserted there.
159 If this variable is nil, no such courtesy message will be added."
160 :group 'message-sending
163 (defcustom message-ignored-bounced-headers "^\\(Received\\|Return-Path\\):"
164 "*Regexp that matches headers to be removed in resent bounced mail."
165 :group 'message-interface
168 (defcustom message-bounce-setup-function 'message-bounce-setup-for-mime-edit
169 "Function to setup a re-sending bounced message."
170 :group 'message-sending
174 (defcustom message-from-style 'default
175 "*Specifies how \"From\" headers look.
177 If `nil', they contain just the return address like:
179 If `parens', they look like:
180 king@grassland.com (Elvis Parsley)
181 If `angles', they look like:
182 Elvis Parsley <king@grassland.com>
184 Otherwise, most addresses look like `angles', but they look like
185 `parens' if `angles' would need quoting and `parens' would not."
186 :type '(choice (const :tag "simple" nil)
190 :group 'message-headers)
192 (defcustom message-syntax-checks nil
193 ; Guess this one shouldn't be easy to customize...
194 "*Controls what syntax checks should not be performed on outgoing posts.
195 To disable checking of long signatures, for instance, add
196 `(signature . disabled)' to this list.
198 Don't touch this variable unless you really know what you're doing.
200 Checks include subject-cmsg multiple-headers sendsys message-id from
201 long-lines control-chars size new-text redirected-followup signature
202 approved sender empty empty-headers message-id from subject
203 shorten-followup-to existing-newsgroups buffer-file-name unchanged
205 :group 'message-news)
207 (defcustom message-required-news-headers
208 '(From Newsgroups Subject Date Message-ID
209 (optional . Organization) Lines
210 (optional . User-Agent))
211 "*Headers to be generated or prompted for when posting an article.
212 RFC977 and RFC1036 require From, Date, Newsgroups, Subject,
213 Message-ID. Organization, Lines, In-Reply-To, Expires, and
214 User-Agent are optional. If don't you want message to insert some
215 header, remove it from this list."
217 :group 'message-headers
218 :type '(repeat sexp))
220 (defcustom message-required-mail-headers
221 '(From Subject Date (optional . In-Reply-To) Message-ID Lines
222 (optional . User-Agent))
223 "*Headers to be generated or prompted for when mailing a message.
224 RFC822 required that From, Date, To, Subject and Message-ID be
225 included. Organization, Lines and User-Agent are optional."
227 :group 'message-headers
228 :type '(repeat sexp))
230 (defcustom message-deletable-headers '(Message-ID Date Lines)
231 "Headers to be deleted if they already exist and were generated by message previously."
232 :group 'message-headers
235 (defcustom message-ignored-news-headers
236 "^NNTP-Posting-Host:\\|^Xref:\\|^[BGF]cc:\\|^Resent-Fcc:"
237 "*Regexp of headers to be removed unconditionally before posting."
239 :group 'message-headers
242 (defcustom message-ignored-mail-headers "^[GF]cc:\\|^Resent-Fcc:\\|^Xref:"
243 "*Regexp of headers to be removed unconditionally before mailing."
245 :group 'message-headers
248 (defcustom message-ignored-supersedes-headers "^Path:\\|^Date\\|^NNTP-Posting-Host:\\|^Xref:\\|^Lines:\\|^Received:\\|^X-From-Line:\\|^X-Trace:\\|^X-Complaints-To:\\|Return-Path:\\|^Supersedes:"
249 "*Header lines matching this regexp will be deleted before posting.
250 It's best to delete old Path and Date headers before posting to avoid
252 :group 'message-interface
255 (defcustom message-supersede-setup-function
256 'message-supersede-setup-for-mime-edit
257 "Function to setup a supersede message."
258 :group 'message-sending
261 (defcustom message-subject-re-regexp "^[ \t]*\\([Rr][Ee]:[ \t]*\\)*[ \t]*"
262 "*Regexp matching \"Re: \" in the subject line."
263 :group 'message-various
266 ;;; Some sender agents encode the whole subject including leading "Re: ".
267 ;;; And if followup agent does not decode it for some reason (e.g. unknown
268 ;;; charset) and just add a new "Re: " in front of the encoded-word, the
269 ;;; result will contain multiple "Re: "'s.
270 (defcustom message-subject-encoded-re-regexp
274 "[-!#$%&'*+0-9A-Z^_`a-z{|}~]+" ; charset
277 "[Bb]" (regexp-quote "?") ; B encoding
278 "\\(\\(CQk\\|CSA\\|IAk\\|ICA\\)[Jg]\\)*" ; \([ \t][ \t][ \t]\)*
280 "[Uc][km]U6" ; [Rr][Ee]:
282 "\\(C[VX]\\|I[FH]\\)J[Fl]O[g-v]" ; [ \t][Rr][Ee]:
284 "\\(CQl\\|CSB\\|IAl\\|ICB\\)[Sy][RZ]T[o-r]" ; [ \t][ \t][Rr][Ee]:
287 "[Qb]" (regexp-quote "?") ; Q encoding
288 "\\(_\\|=09\\|=20\\)*"
289 "\\([Rr]\\|=[57]2\\)\\([Ee]\\|=[46]5\\)\\(:\\|=3[Aa]\\)"
292 "*Regexp matching \"Re: \" in the subject line.
293 Unlike `message-subject-re-regexp', this regexp matches \"Re: \" within
295 :group 'message-various
298 (defcustom message-use-subject-re t
299 "*If t, remove any (buggy) \"Re: \"'s from the subject of the precursor
300 and add a new \"Re: \". If it is nil, use the subject \"as-is\". If it
301 is the symbol `guess', try to detect \"Re: \" within an encoded-word."
302 :group 'message-various
303 :type '(choice (const :tag "off" nil)
308 (defcustom message-signature-separator "^-- *$"
309 "Regexp matching the signature separator."
311 :group 'message-various)
313 (defcustom message-elide-ellipsis "\n[...]\n\n"
314 "*The string which is inserted for elided text."
316 :group 'message-various)
318 (defcustom message-interactive nil
319 "Non-nil means when sending a message wait for and display errors.
320 nil means let mailer mail back a message to report errors."
321 :group 'message-sending
325 (defcustom message-generate-new-buffers 'unique
326 "*Non-nil means that a new message buffer will be created whenever `message-setup' is called.
327 If this is a function, call that function with three parameters: The type,
328 the to address and the group name. (Any of these may be nil.) The function
329 should return the new buffer name."
330 :group 'message-buffers
331 :type '(choice (const :tag "off" nil)
332 (const :tag "unique" unique)
333 (const :tag "unsent" unsent)
336 (defcustom message-kill-buffer-on-exit nil
337 "*Non-nil means that the message buffer will be killed after sending a message."
338 :group 'message-buffers
341 (defcustom message-kill-buffer-query-function 'yes-or-no-p
342 "*A function called to query the user whether to kill buffer anyway or not.
343 If it is t, the buffer will be killed peremptorily."
344 :type '(radio (function-item yes-or-no-p)
345 (function-item y-or-n-p)
346 (function-item nnheader-Y-or-n-p)
347 (function :tag "Other" t))
348 :group 'message-buffers)
350 (defvar gnus-local-organization)
351 (defcustom message-user-organization
352 (or (and (boundp 'gnus-local-organization)
353 (stringp gnus-local-organization)
354 gnus-local-organization)
355 (getenv "ORGANIZATION")
357 "*String to be used as an Organization header.
358 If t, use `message-user-organization-file'."
359 :group 'message-headers
360 :type '(choice string
361 (const :tag "consult file" t)))
364 (defcustom message-user-organization-file "/usr/lib/news/organization"
365 "*Local news organization file."
367 :group 'message-headers)
369 (defcustom message-forward-start-separator
370 (concat (mime-make-tag "message" "rfc822") "\n")
371 "*Delimiter inserted before forwarded messages."
372 :group 'message-forwarding
375 (defcustom message-forward-end-separator
376 (concat (mime-make-tag "text" "plain") "\n")
377 "*Delimiter inserted after forwarded messages."
378 :group 'message-forwarding
381 (defcustom message-signature-before-forwarded-message t
382 "*If non-nil, put the signature before any included forwarded message."
383 :group 'message-forwarding
386 (defcustom message-included-forward-headers
387 "^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:"
388 "*Regexp matching headers to be included in forwarded messages."
389 :group 'message-forwarding
392 (defcustom message-make-forward-subject-function
393 'message-forward-subject-author-subject
394 "*A list of functions that are called to generate a subject header for forwarded messages.
395 The subject generated by the previous function is passed into each
398 The provided functions are:
400 * message-forward-subject-author-subject (Source of article (author or
401 newsgroup)), in brackets followed by the subject
402 * message-forward-subject-fwd (Subject of article with 'Fwd:' prepended
404 :group 'message-forwarding
405 :type '(radio (function-item message-forward-subject-author-subject)
406 (function-item message-forward-subject-fwd)))
408 (defcustom message-forward-as-mime t
409 "*If non-nil, forward messages as an inline/rfc822 MIME section. Otherwise, directly inline the old message in the forwarded message."
410 :group 'message-forwarding
413 (defcustom message-wash-forwarded-subjects nil
414 "*If non-nil, try to remove as much old cruft as possible from the subject of messages before generating the new subject of a forward."
415 :group 'message-forwarding
418 (defcustom message-ignored-resent-headers "^Return-receipt\\|^X-Gnus\\|^Gnus-Warning:"
419 "*All headers that match this regexp will be deleted when resending a message."
420 :group 'message-interface
423 (defcustom message-forward-ignored-headers nil
424 "*All headers that match this regexp will be deleted when forwarding a message."
425 :group 'message-forwarding
426 :type '(choice (const :tag "None" nil)
429 (defcustom message-ignored-cited-headers "."
430 "*Delete these headers from the messages you yank."
431 :group 'message-insertion
434 (defcustom message-cancel-message "I am canceling my own article."
435 "Message to be inserted in the cancel message."
436 :group 'message-interface
439 ;; Useful to set in site-init.el
441 (defcustom message-send-mail-function 'message-send-mail-with-sendmail
442 "Function to call to send the current buffer as mail.
443 The headers should be delimited by a line whose contents match the
444 variable `mail-header-separator'.
446 Valid values include `message-send-mail-with-sendmail' (the default),
447 `message-send-mail-with-mh', `message-send-mail-with-qmail' and
448 `message-send-mail-with-smtp'."
449 :type '(radio (function-item message-send-mail-with-sendmail)
450 (function-item message-send-mail-with-mh)
451 (function-item message-send-mail-with-qmail)
452 (function-item message-send-mail-with-smtp)
453 (function :tag "Other"))
454 :group 'message-sending
455 :group 'message-mail)
457 ;; 1997-09-29 by MORIOKA Tomohiko
458 (defcustom message-send-news-function 'message-send-news-with-gnus
459 "Function to call to send the current buffer as news.
460 The headers should be delimited by a line whose contents match the
461 variable `mail-header-separator'."
462 :group 'message-sending
466 (defcustom message-reply-to-function nil
467 "Function that should return a list of headers.
468 This function should pick out addresses from the To, Cc, and From headers
469 and respond with new To and Cc headers."
470 :group 'message-interface
473 (defcustom message-wide-reply-to-function nil
474 "Function that should return a list of headers.
475 This function should pick out addresses from the To, Cc, and From headers
476 and respond with new To and Cc headers."
477 :group 'message-interface
480 (defcustom message-followup-to-function nil
481 "Function that should return a list of headers.
482 This function should pick out addresses from the To, Cc, and From headers
483 and respond with new To and Cc headers."
484 :group 'message-interface
487 (defcustom message-use-followup-to 'ask
488 "*Specifies what to do with Followup-To header.
489 If nil, always ignore the header. If it is t, use its value, but
490 query before using the \"poster\" value. If it is the symbol `ask',
491 always query the user whether to use the value. If it is the symbol
492 `use', always use the value."
493 :group 'message-interface
494 :type '(choice (const :tag "ignore" nil)
495 (const :tag "maybe" t)
496 (const :tag "always" use)
497 (const :tag "ask" ask)))
499 (defcustom message-use-mail-copies-to 'ask
500 "*Specifies what to do with Mail-Copies-To header.
501 If nil, always ignore the header. If it is t, use its value, but
502 query before using the value other than \"always\" or \"never\".
503 If it is the symbol `ask', always query the user whether to use
504 the value. If it is the symbol `use', always use the value."
505 :group 'message-interface
506 :type '(choice (const :tag "ignore" nil)
507 (const :tag "maybe" t)
508 (const :tag "always" use)
509 (const :tag "ask" ask)))
511 (defcustom message-use-mail-followup-to 'ask
512 "*Specifies what to do with Mail-Followup-To header.
513 If nil, always ignore the header. If it is the symbol `ask', always
514 query the user whether to use the value. If it is t or the symbol
515 `use', always use the value."
516 :group 'message-interface
517 :type '(choice (const :tag "ignore" nil)
518 (const :tag "maybe" t)
519 (const :tag "always" use)
520 (const :tag "ask" ask)))
522 ;;; XXX: 'ask and 'use are not implemented yet.
523 (defcustom message-use-mail-reply-to 'ask
524 "*Specifies what to do with Mail-Reply-To/Reply-To header.
525 If nil, always ignore the header. If it is t or the symbol `use', use
526 its value. If it is the symbol `ask', always query the user whether to
527 use the value. Note that if \"Reply-To\" is marked as \"broken\", its value
529 :group 'message-interface
530 :type '(choice (const :tag "ignore" nil)
531 (const :tag "maybe" t)
532 (const :tag "always" use)
533 (const :tag "ask" ask)))
535 (defcustom message-sendmail-f-is-evil nil
536 "*Non-nil means that \"-f username\" should not be added to the sendmail command line.
537 Doing so would be even more evil than leaving it out."
538 :group 'message-sending
541 ;; qmail-related stuff
542 (defcustom message-qmail-inject-program "/var/qmail/bin/qmail-inject"
543 "Location of the qmail-inject program."
544 :group 'message-sending
547 (defcustom message-qmail-inject-args nil
548 "Arguments passed to qmail-inject programs.
549 This should be a list of strings, one string for each argument.
551 For e.g., if you wish to set the envelope sender address so that bounces
552 go to the right place or to deal with listserv's usage of that address, you
553 might set this variable to '(\"-f\" \"you@some.where\")."
554 :group 'message-sending
555 :type '(repeat string))
557 (defvar message-cater-to-broken-inn t
558 "Non-nil means Gnus should not fold the `References' header.
559 Folding `References' makes ancient versions of INN create incorrect
562 (defvar gnus-post-method)
563 (defvar gnus-select-method)
564 (defcustom message-post-method
565 (cond ((and (boundp 'gnus-post-method)
566 (listp gnus-post-method)
569 ((boundp 'gnus-select-method)
572 "*Method used to post news.
573 Note that when posting from inside Gnus, for instance, this
574 variable isn't used."
576 :group 'message-sending
577 ;; This should be the `gnus-select-method' widget, but that might
578 ;; create a dependence to `gnus.el'.
581 (defcustom message-generate-headers-first nil
582 "*If non-nil, generate all possible headers before composing."
583 :group 'message-headers
586 (defcustom message-setup-hook '(turn-on-mime-edit)
587 "Normal hook, run each time a new outgoing message is initialized.
588 The function `message-setup' runs this hook."
589 :group 'message-various
592 (defcustom message-cancel-hook nil
593 "Hook run when cancelling articles."
594 :group 'message-various
597 (defcustom message-signature-setup-hook nil
598 "Normal hook, run each time a new outgoing message is initialized.
599 It is run after the headers have been inserted and before
600 the signature is inserted."
601 :group 'message-various
604 (defcustom message-bounce-setup-hook nil
605 "Normal hook, run each time a re-sending bounced message is initialized.
606 The function `message-bounce' runs this hook."
607 :group 'message-various
610 (defcustom message-supersede-setup-hook nil
611 "Normal hook, run each time a supersede message is initialized.
612 The function `message-supersede' runs this hook."
613 :group 'message-various
616 (defcustom message-mode-hook nil
617 "Hook run in message mode buffers."
618 :group 'message-various
621 (defcustom message-header-hook '((lambda () (eword-encode-header t)))
622 "Hook run in a message mode buffer narrowed to the headers."
623 :group 'message-various
626 (defcustom message-header-setup-hook nil
627 "Hook called narrowed to the headers when setting up a message buffer."
628 :group 'message-various
632 (defcustom message-citation-line-function 'message-insert-citation-line
633 "*Function called to insert the \"Whomever writes:\" line."
635 :group 'message-insertion)
638 (defcustom message-yank-prefix "> "
639 "*Prefix inserted on the lines of yanked messages."
641 :group 'message-insertion)
643 (defcustom message-yank-add-new-references t
644 "*Non-nil means new IDs will be added to \"References\" field when an
645 article is yanked by the command `message-yank-original' interactively."
646 :type '(radio (const :tag "Do not add anything" nil)
647 (const :tag "From Message-Id, References and In-Reply-To fields" t)
648 (const :tag "From only Message-Id field." message-id-only))
649 :group 'message-insertion)
651 (defcustom message-list-references-add-position nil
652 "*Integer value means position for adding to \"References\" field when
653 an article is yanked by the command `message-yank-original' interactively."
654 :type '(radio (const :tag "Add to last" nil)
655 (integer :tag "Position from last ID"))
656 :group 'message-insertion)
658 (defcustom message-indentation-spaces 3
659 "*Number of spaces to insert at the beginning of each cited line.
660 Used by `message-yank-original' via `message-yank-cite'."
661 :group 'message-insertion
665 (defcustom message-cite-function 'message-cite-original
666 "*Function for citing an original message.
667 Predefined functions include `message-cite-original' and
668 `message-cite-original-without-signature'.
669 Note that `message-cite-original' uses `mail-citation-hook' if that is non-nil."
670 :type '(radio (function-item message-cite-original)
671 (function-item message-cite-original-without-signature)
672 (function-item mu-cite-original)
673 (function-item sc-cite-original)
674 (function :tag "Other"))
675 :group 'message-insertion)
678 (defcustom message-indent-citation-function 'message-indent-citation
679 "*Function for modifying a citation just inserted in the mail buffer.
680 This can also be a list of functions. Each function can find the
681 citation between (point) and (mark t). And each function should leave
682 point and mark around the citation text as modified."
684 :group 'message-insertion)
686 (defvar message-abbrevs-loaded nil)
689 (defcustom message-signature t
690 "*String to be inserted at the end of the message buffer.
691 If t, the `message-signature-file' file will be inserted instead.
692 If a function, the result from the function will be used instead.
693 If a form, the result from the form will be used instead."
695 :group 'message-insertion)
698 (defcustom message-signature-file "~/.signature"
699 "*File containing the text inserted at end of message buffer."
701 :group 'message-insertion)
703 (defcustom message-distribution-function nil
704 "*Function called to return a Distribution header."
706 :group 'message-headers
709 (defcustom message-expires 14
710 "Number of days before your article expires."
712 :group 'message-headers
713 :link '(custom-manual "(message)News Headers")
716 (defcustom message-user-path nil
717 "If nil, use the NNTP server name in the Path header.
718 If stringp, use this; if non-nil, use no host name (user name only)."
720 :group 'message-headers
721 :link '(custom-manual "(message)News Headers")
722 :type '(choice (const :tag "nntp" nil)
724 (sexp :tag "none" :format "%t" t)))
726 (defvar message-reply-buffer nil)
727 (defvar message-reply-headers nil)
728 (defvar message-sent-message-via nil)
729 (defvar message-checksum nil)
730 (defvar message-send-actions nil
731 "A list of actions to be performed upon successful sending of a message.")
732 (defvar message-exit-actions nil
733 "A list of actions to be performed upon exiting after sending a message.")
734 (defvar message-kill-actions nil
735 "A list of actions to be performed before killing a message buffer.")
736 (defvar message-postpone-actions nil
737 "A list of actions to be performed after postponing a message.")
738 (defvar message-original-frame nil)
739 (defvar message-parameter-alist nil)
740 (defvar message-startup-parameter-alist nil)
742 (define-widget 'message-header-lines 'text
743 "All header lines must be LFD terminated."
746 :error "All header lines must be newline terminated")
748 (defcustom message-default-headers ""
749 "*A string containing header lines to be inserted in outgoing messages.
750 It is inserted before you edit the message, so you can edit or delete
752 :group 'message-headers
753 :type 'message-header-lines)
755 (defcustom message-default-mail-headers ""
756 "*A string of header lines to be inserted in outgoing mails."
757 :group 'message-headers
759 :type 'message-header-lines)
761 (defcustom message-default-news-headers ""
762 "*A string of header lines to be inserted in outgoing news
764 :group 'message-headers
766 :type 'message-header-lines)
768 ;; Note: could use /usr/ucb/mail instead of sendmail;
769 ;; options -t, and -v if not interactive.
770 (defcustom message-mailer-swallows-blank-line
771 (if (and (string-match "sparc-sun-sunos\\(\\'\\|[^5]\\)"
772 system-configuration)
773 (file-readable-p "/etc/sendmail.cf")
774 (let ((buffer (get-buffer-create " *temp*")))
778 (insert-file-contents "/etc/sendmail.cf")
779 (goto-char (point-min))
780 (let ((case-fold-search nil))
781 (re-search-forward "^OR\\>" nil t)))
782 (kill-buffer buffer))))
783 ;; According to RFC822, "The field-name must be composed of printable
784 ;; ASCII characters (i. e., characters that have decimal values between
785 ;; 33 and 126, except colon)", i. e., any chars except ctl chars,
787 '(looking-at "[ \t]\\|[][!\"#$%&'()*+,-./0-9;<=>?@A-Z\\\\^_`a-z{|}~]+:"))
788 "*Set this non-nil if the system's mailer runs the header and body together.
789 \(This problem exists on Sunos 4 when sendmail is run in remote mode.)
790 The value should be an expression to test whether the problem will
792 :group 'message-sending
795 ;;; XXX: This symbol is overloaded! See below.
796 (defvar message-user-agent nil
797 "String of the form of PRODUCT/VERSION. Used for User-Agent header field.")
799 ;; Ignore errors in case this is used in Emacs 19.
800 ;; Don't use ignore-errors because this is copied into loaddefs.el.
803 (define-mail-user-agent 'message-user-agent
804 'message-mail 'message-send-and-exit
805 'message-kill-buffer 'message-send-hook))
807 (defvar message-mh-deletable-headers '(Message-ID Date Lines Sender)
808 "If non-nil, delete the deletable headers before feeding to mh.")
810 (defvar message-send-method-alist
811 '((news message-news-p message-send-via-news)
812 (mail message-mail-p message-send-via-mail))
813 "Alist of ways to send outgoing messages.
814 Each element has the form
816 \(TYPE PREDICATE FUNCTION)
818 where TYPE is a symbol that names the method; PREDICATE is a function
819 called without any parameters to determine whether the message is
820 a message of type TYPE; and FUNCTION is a function to be called if
821 PREDICATE returns non-nil. FUNCTION is called with one parameter --
824 (defvar message-mail-alias-type 'abbrev
825 "*What alias expansion type to use in Message buffers.
826 The default is `abbrev', which uses mailabbrev. nil switches
829 (defcustom message-auto-save-directory
830 (nnheader-concat message-directory "drafts/")
831 "*Directory where Message auto-saves buffers if Gnus isn't running.
832 If nil, Message won't auto-save."
833 :group 'message-buffers
836 (defcustom message-buffer-naming-style 'unique
837 "*The way new message buffers are named.
838 Valid valued are `unique' and `unsent'."
839 :group 'message-buffers
840 :type '(choice (const :tag "unique" unique)
841 (const :tag "unsent" unsent)))
843 (defcustom message-default-charset nil
844 "Default charset used in non-MULE XEmacsen."
848 (defcustom message-dont-reply-to-names rmail-dont-reply-to-names
849 "*A regexp specifying names to prune when doing wide replies.
850 A value of nil means exclude your own name only."
852 :type '(choice (const :tag "Yourself" nil)
855 ;;; Internal variables.
856 ;;; Well, not really internal.
858 (defvar message-mode-syntax-table
859 (let ((table (copy-syntax-table text-mode-syntax-table)))
860 (modify-syntax-entry ?% ". " table)
861 (modify-syntax-entry ?> ". " table)
862 (modify-syntax-entry ?< ". " table)
864 "Syntax table used while in Message mode.")
866 (defvar message-mode-abbrev-table text-mode-abbrev-table
867 "Abbrev table used in Message mode buffers.
868 Defaults to `text-mode-abbrev-table'.")
869 (defgroup message-headers nil
871 :link '(custom-manual "(message)Variables")
874 (defface message-header-to-face
877 (:foreground "green2" :bold t))
880 (:foreground "MidnightBlue" :bold t))
882 (:bold t :italic t)))
883 "Face used for displaying From headers."
884 :group 'message-faces)
886 (defface message-header-cc-face
889 (:foreground "green4" :bold t))
892 (:foreground "MidnightBlue"))
895 "Face used for displaying Cc headers."
896 :group 'message-faces)
898 (defface message-header-subject-face
901 (:foreground "green3"))
904 (:foreground "navy blue" :bold t))
907 "Face used for displaying subject headers."
908 :group 'message-faces)
910 (defface message-header-newsgroups-face
913 (:foreground "yellow" :bold t :italic t))
916 (:foreground "blue4" :bold t :italic t))
918 (:bold t :italic t)))
919 "Face used for displaying newsgroups headers."
920 :group 'message-faces)
922 (defface message-header-other-face
925 (:foreground "#b00000"))
928 (:foreground "steel blue"))
930 (:bold t :italic t)))
931 "Face used for displaying newsgroups headers."
932 :group 'message-faces)
934 (defface message-header-name-face
937 (:foreground "DarkGreen"))
940 (:foreground "cornflower blue"))
943 "Face used for displaying header names."
944 :group 'message-faces)
946 (defface message-header-xheader-face
949 (:foreground "blue"))
952 (:foreground "blue"))
955 "Face used for displaying X-Header headers."
956 :group 'message-faces)
958 (defface message-separator-face
961 (:foreground "blue3"))
964 (:foreground "brown"))
967 "Face used for displaying the separator."
968 :group 'message-faces)
970 (defface message-cited-text-face
979 "Face used for displaying cited text names."
980 :group 'message-faces)
982 (defface message-mml-face
985 (:foreground "ForestGreen"))
988 (:foreground "ForestGreen"))
991 "Face used for displaying MML."
992 :group 'message-faces)
994 (defvar message-font-lock-fence-open-regexp "[+|]"
995 "*Regexp that matches fence open string.")
997 (defvar message-font-lock-fence-close-regexp "|"
998 "*Regexp that matches fence close string.")
1000 (defvar message-font-lock-fence-open-position nil
1001 "*Cons of SYMBOL of a function or a variable and a number of OFFSET that
1002 indicate the fence open position. If it is non-nil,
1003 `message-font-lock-fence-open-regexp' is not used for searching for the
1004 fence open position. If SYMBOL is a function, it is called with one argument
1005 last cursor position and should return the fence open position as a number
1006 or a marker. If SYMBOL is a variable symbol, the value is examined with
1007 `symbol-value'. OFFSET is added to the position to compensate the value.
1008 For example, the following combinations of variable symbol and offset value
1011 Egg v3: '(egg:*region-start* . -1)
1012 Canna: '(canna:*region-start* . 0)
1015 (defvar message-font-lock-fence-close-position nil
1016 "*Cons of SYMBOL of a function or a variable and a number of OFFSET that
1017 indicate the fence close position. If it is non-nil,
1018 `message-font-lock-fence-close-regexp' is not used for searching for the
1019 fence close position. If SYMBOL is a function, it is called with one argument
1020 last cursor position and should return the fence close position as a number
1021 or a marker. If SYMBOL is a variable symbol, the value is examined with
1022 `symbol-value'. OFFSET is added to the position to compensate the value.
1023 For example, the following combinations of variable symbol and offset value
1026 Egg v3: '(egg:*region-end* . 0)
1027 Canna: '(canna:*region-end* . 0)
1030 (defvar message-font-lock-cited-text-regexp
1031 "^[\t ]*\\([^\000- :>|}\177]*\\)[:>|}].*"
1032 "*Regexp that matches cited text. It should have a grouping for the
1033 citation prefix which is ended at the beginning of citation mark string.")
1035 (defvar message-font-lock-citation-name-max-column 10
1036 "*Maximun number of column for citation name for fontifying.")
1038 (defvar message-font-lock-last-position nil
1039 "Internal buffer local variable to save the last cursor position
1040 before fontifying.")
1042 (eval-after-load "font-lock"
1043 '(defadvice font-lock-after-change-function
1044 (before message-font-lock-save-last-position activate)
1045 "Save last cursor position before fontifying."
1046 (if (eq 'message-mode major-mode)
1047 (setq message-font-lock-last-position (point)))))
1049 (defun message-font-lock-cited-text-matcher (limit)
1050 "Search for a cited text containing `message-font-lock-cited-text-regexp'
1051 forward. Argument LIMIT bounds the search. If a cited text is found, it
1052 returns t and sets match data 1 and 2, otherwise it returns nil. Normally,
1053 match data 2 has zero length, but if the FENCE (for input method) is detected
1054 in matched text, result is divided into match data 1 and 2 across the FENCE.
1055 See also the documentations for the following variables:
1056 `message-font-lock-fence-open-regexp'
1057 `message-font-lock-fence-close-regexp'
1058 `message-font-lock-fence-open-position'
1059 `message-font-lock-fence-close-position'
1062 (when (re-search-forward message-font-lock-cited-text-regexp limit t)
1063 (let* ((start0 (match-beginning 0))
1064 (end0 (match-end 0))
1065 (cite-mark (match-end 1))
1068 (goto-char cite-mark)
1069 (<= (current-column)
1070 message-font-lock-citation-name-max-column)))
1074 message-font-lock-last-position
1075 (>= message-font-lock-last-position start0)
1076 (<= message-font-lock-last-position end0)
1078 (message-font-lock-fence-open-position
1079 (let* ((symbol (car message-font-lock-fence-open-position))
1081 (cond ((functionp symbol)
1082 (funcall symbol message-font-lock-last-position))
1083 ((and (symbolp symbol)
1085 (symbol-value symbol)))))
1086 (when (markerp open)
1087 (setq open (marker-position open)))
1091 (cdr message-font-lock-fence-open-position)))
1092 (>= message-font-lock-last-position open)
1094 (or (not message-font-lock-fence-open-regexp)
1095 (looking-at message-font-lock-fence-open-regexp))
1097 (message-font-lock-fence-open-regexp
1098 (goto-char message-font-lock-last-position)
1099 (when (re-search-backward
1100 message-font-lock-fence-open-regexp start0 t)
1101 (setq end1 (match-beginning 0)))))
1102 (setq should-fontify
1103 (and message-font-lock-fence-open-position
1104 (not (eq cite-mark end1))))
1106 (message-font-lock-fence-close-position
1107 (let* ((symbol (car message-font-lock-fence-close-position))
1109 (cond ((functionp symbol)
1110 (funcall symbol message-font-lock-last-position))
1111 ((and (symbolp symbol)
1113 (symbol-value symbol)))))
1114 (when (markerp close)
1115 (setq close (marker-position close)))
1116 (and (numberp close)
1119 (cdr message-font-lock-fence-close-position)))
1120 (<= message-font-lock-last-position close)
1121 (setq start2 close))))
1122 (message-font-lock-fence-close-regexp
1123 (goto-char message-font-lock-last-position)
1124 (when (looking-at message-font-lock-fence-close-regexp)
1125 (setq start2 (match-end 0)))))
1126 (setq should-fontify
1127 (and (not (and (not message-font-lock-fence-open-position)
1128 (eq cite-mark end1)))
1129 (not (eq cite-mark start2)))))
1131 (when should-fontify
1133 (store-match-data (list start0 end0 start0 end1 start2 end0))
1134 (store-match-data (list start0 end0 start0 end0 end0 end0)))
1136 (setq message-font-lock-last-position nil)))
1138 (defvar message-font-lock-keywords-1
1139 (let ((content "[ \t]*\\(.+\\(\n[ \t].*\\)*\\)"))
1140 `((,(concat "^\\([Tt]o:\\)" content)
1141 (1 'message-header-name-face)
1142 (2 'message-header-to-face nil t))
1143 (,(concat "^\\([GBF]?[Cc][Cc]:\\|[Rr]eply-[Tt]o:\\|"
1144 "[Mm]ail-[Cc]opies-[Tt]o:\\|"
1145 "[Mm]ail-[Rr]eply-[Tt]o:\\|"
1146 "[Mm]ail-[Ff]ollowup-[Tt]o:\\)" content)
1147 (1 'message-header-name-face)
1148 (2 'message-header-cc-face nil t))
1149 (,(concat "^\\([Ss]ubject:\\)" content)
1150 (1 'message-header-name-face)
1151 (2 'message-header-subject-face nil t))
1152 (,(concat "^\\([Nn]ewsgroups:\\|Followup-[Tt]o:\\)" content)
1153 (1 'message-header-name-face)
1154 (2 'message-header-newsgroups-face nil t))
1155 (,(concat "^\\([A-Z][^: \n\t]+:\\)" content)
1156 (1 'message-header-name-face)
1157 (2 'message-header-other-face nil t))
1158 (,(concat "^\\(X-[A-Za-z0-9-]+\\|In-Reply-To\\):" content)
1159 (1 'message-header-name-face)
1160 (2 'message-header-name-face))
1161 ,@(if (and mail-header-separator
1162 (not (equal mail-header-separator "")))
1163 `((,(concat "^\\(" (regexp-quote mail-header-separator) "\\)$")
1164 1 'message-separator-face))
1167 (defvar message-font-lock-keywords-2
1168 (append message-font-lock-keywords-1
1169 '((message-font-lock-cited-text-matcher
1170 (1 'message-cited-text-face)
1171 (2 'message-cited-text-face))
1172 ("<#/?\\(multipart\\|part\\|external\\).*>"
1173 (0 'message-mml-face)))))
1175 (defvar message-font-lock-keywords message-font-lock-keywords-2
1176 "Additional expressions to highlight in Message mode.")
1178 ;; XEmacs does it like this. For Emacs, we have to set the
1179 ;; `font-lock-defaults' buffer-local variable.
1180 (put 'message-mode 'font-lock-defaults
1181 '((message-font-lock-keywords
1182 message-font-lock-keywords-1
1183 message-font-lock-keywords-2)
1185 (font-lock-mark-block-function . mark-paragraph)))
1187 (defvar message-face-alist
1188 '((bold . bold-region)
1189 (underline . underline-region)
1190 (default . (lambda (b e)
1192 (ununderline-region b e))))
1193 "Alist of mail and news faces for facemenu.
1194 The cdr of ech entry is a function for applying the face to a region.")
1196 (defcustom message-send-hook nil
1197 "Hook run before sending messages."
1198 :group 'message-various
1199 :options '(ispell-message)
1202 (defcustom message-send-mail-hook nil
1203 "Hook run before sending mail messages."
1204 :group 'message-various
1207 (defcustom message-send-news-hook nil
1208 "Hook run before sending news messages."
1209 :group 'message-various
1212 (defcustom message-sent-hook nil
1213 "Hook run after sending messages."
1214 :group 'message-various
1217 (defcustom message-use-multi-frames nil
1218 "Make new frame when sending messages."
1219 :group 'message-frames
1222 (defcustom message-delete-frame-on-exit nil
1223 "Delete frame after sending messages."
1224 :group 'message-frames
1225 :type '(choice (const :tag "off" nil)
1226 (const :tag "always" t)
1227 (const :tag "ask" ask)))
1229 (defvar message-draft-coding-system
1231 ((boundp 'MULE) '*junet*)
1232 ((not (fboundp 'find-coding-system)) nil)
1233 ((find-coding-system 'emacs-mule)
1234 (if (memq system-type '(windows-nt ms-dos ms-windows))
1235 'emacs-mule-dos 'emacs-mule))
1236 ((find-coding-system 'escape-quoted) 'escape-quoted)
1237 ((find-coding-system 'no-conversion) 'no-conversion)
1239 "Coding system to compose mail.")
1241 ;;; Internal variables.
1243 (defvar message-buffer-list nil)
1244 (defvar message-this-is-news nil)
1245 (defvar message-this-is-mail nil)
1246 (defvar message-draft-article nil)
1247 (defvar message-mime-part nil)
1248 (defvar message-posting-charset nil)
1250 ;; Byte-compiler warning
1251 (defvar gnus-active-hashtb)
1252 (defvar gnus-read-active-file)
1254 ;;; Regexp matching the delimiter of messages in UNIX mail format
1255 ;;; (UNIX From lines), minus the initial ^. It should be a copy
1256 ;;; of rmail.el's rmail-unix-mail-delimiter.
1257 (defvar message-unix-mail-delimiter
1258 (let ((time-zone-regexp
1259 (concat "\\([A-Z]?[A-Z]?[A-Z][A-Z]\\( DST\\)?"
1260 "\\|[-+]?[0-9][0-9][0-9][0-9]"
1266 ;; Many things can happen to an RFC 822 mailbox before it is put into
1267 ;; a `From' line. The leading phrase can be stripped, e.g.
1268 ;; `Joe <@w.x:joe@y.z>' -> `<@w.x:joe@y.z>'. The <> can be stripped, e.g.
1269 ;; `<@x.y:joe@y.z>' -> `@x.y:joe@y.z'. Everything starting with a CRLF
1270 ;; can be removed, e.g.
1271 ;; From: joe@y.z (Joe K
1273 ;; can yield `From joe@y.z (Joe K Fri Mar 22 08:11:15 1996', and
1276 ;; can yield `From Joe User Fri Mar 22 08:11:15 1996'.
1277 ;; The mailbox can be removed or be replaced by white space, e.g.
1278 ;; From: "Joe User"{space}{tab}
1280 ;; can yield `From {space}{tab} Fri Mar 22 08:11:15 1996',
1281 ;; where {space} and {tab} represent the Ascii space and tab characters.
1282 ;; We want to match the results of any of these manglings.
1283 ;; The following regexp rejects names whose first characters are
1284 ;; obviously bogus, but after that anything goes.
1285 "\\([^\0-\b\n-\r\^?].*\\)? "
1287 ;; The time the message was sent.
1288 "\\([^\0-\r \^?]+\\) +" ; day of the week
1289 "\\([^\0-\r \^?]+\\) +" ; month
1290 "\\([0-3]?[0-9]\\) +" ; day of month
1291 "\\([0-2][0-9]:[0-5][0-9]\\(:[0-6][0-9]\\)?\\) *" ; time of day
1293 ;; Perhaps a time zone, specified by an abbreviation, or by a
1298 " \\([0-9][0-9]+\\) *"
1300 ;; On some systems the time zone can appear after the year, too.
1304 "\\(remote from .*\\)?"
1307 "Regexp matching the delimiter of messages in UNIX mail format.")
1309 (defvar message-unsent-separator
1310 (concat "^ *---+ +Unsent message follows +---+ *$\\|"
1311 "^ *---+ +Returned message +---+ *$\\|"
1312 "^Start of returned message$\\|"
1313 "^ *---+ +Original message +---+ *$\\|"
1314 "^ *--+ +begin message +--+ *$\\|"
1315 "^ *---+ +Original message follows +---+ *$\\|"
1316 "^ *---+ +Undelivered message follows +---+ *$\\|"
1317 "^|? *---+ +Message text follows: +---+ *|?$")
1318 "A regexp that matches the separator before the text of a failed message.")
1320 (defvar message-header-format-alist
1322 (To . message-fill-address)
1323 (Cc . message-fill-address)
1334 (References . message-shorten-references)
1336 "Alist used for formatting headers.")
1339 (autoload 'message-setup-toolbar "messagexmas")
1340 (autoload 'mh-new-draft-name "mh-comp")
1341 (autoload 'mh-send-letter "mh-comp")
1342 (autoload 'gnus-point-at-eol "gnus-util")
1343 (autoload 'gnus-point-at-bol "gnus-util")
1344 (autoload 'gnus-output-to-mail "gnus-util")
1345 (autoload 'mail-abbrev-in-expansion-header-p "mailabbrev")
1346 (autoload 'nndraft-request-associate-buffer "nndraft")
1347 (autoload 'nndraft-request-expire-articles "nndraft")
1348 (autoload 'gnus-open-server "gnus-int")
1349 (autoload 'gnus-request-post "gnus-int")
1350 (autoload 'gnus-copy-article-buffer "gnus-msg")
1351 (autoload 'gnus-alive-p "gnus-util")
1352 (autoload 'rmail-output "rmail")
1353 (autoload 'mu-cite-original "mu-cite"))
1358 ;;; Utility functions.
1360 (defun message-eval-parameter (parameter)
1362 (if (symbolp parameter)
1363 (if (functionp parameter)
1369 (defsubst message-get-parameter (key &optional alist)
1371 (setq alist message-parameter-alist))
1372 (cdr (assq key alist)))
1374 (defmacro message-get-parameter-with-eval (key &optional alist)
1375 `(message-eval-parameter (message-get-parameter ,key ,alist)))
1377 (defmacro message-y-or-n-p (question show &rest text)
1378 "Ask QUESTION, displaying the rest of the arguments in a temp. buffer if SHOW"
1379 `(message-talkative-question 'y-or-n-p ,question ,show ,@text))
1381 ;; Delete the current line (and the next N lines.);
1382 (defmacro message-delete-line (&optional n)
1383 `(delete-region (progn (beginning-of-line) (point))
1384 (progn (forward-line ,(or n 1)) (point))))
1386 (defun message-tokenize-header (header &optional separator)
1387 "Split HEADER into a list of header elements.
1388 \",\" is used as the separator."
1391 (let ((regexp (format "[%s]+" (or separator ",")))
1396 (message-set-work-buffer)
1398 (goto-char (point-min))
1403 (cond ((and (> (point) beg)
1405 (and (looking-at regexp)
1408 (push (buffer-substring beg (point)) elems)
1409 (setq beg (match-end 0)))
1410 ((eq (char-after) ?\")
1411 (setq quoted (not quoted)))
1412 ((and (eq (char-after) ?\()
1415 ((and (eq (char-after) ?\))
1418 (nreverse elems)))))
1420 (defun message-mail-file-mbox-p (file)
1421 "Say whether FILE looks like a Unix mbox file."
1422 (when (and (file-exists-p file)
1423 (file-readable-p file)
1424 (file-regular-p file))
1426 (nnheader-insert-file-contents file)
1427 (goto-char (point-min))
1428 (looking-at message-unix-mail-delimiter))))
1430 (defun message-fetch-field (header &optional not-all)
1431 "The same as `mail-fetch-field', only remove all newlines."
1432 (let* ((inhibit-point-motion-hooks t)
1433 (value (mail-fetch-field header nil (not not-all))))
1435 (while (string-match "\n[\t ]+" value)
1436 (setq value (replace-match " " t t value)))
1437 ;; We remove all text props.
1438 (format "%s" value))))
1440 (defun message-narrow-to-field ()
1441 "Narrow the buffer to the header on the current line."
1447 (if (re-search-forward "^[^ \n\t]" nil t)
1452 (goto-char (point-min)))
1454 (defun message-add-header (&rest headers)
1455 "Add the HEADERS to the message header, skipping those already present."
1458 (unless (string-match "^\\([^:]+\\):[ \t]*[^ \t]" (car headers))
1459 (error "Invalid header `%s'" (car headers)))
1460 (setq hclean (match-string 1 (car headers)))
1462 (message-narrow-to-headers)
1463 (unless (re-search-forward (concat "^" (regexp-quote hclean) ":") nil t)
1464 (insert (car headers) ?\n))))
1465 (setq headers (cdr headers))))
1468 (defun message-fetch-reply-field (header)
1469 "Fetch FIELD from the message we're replying to."
1470 (let ((buffer (message-eval-parameter message-reply-buffer)))
1472 (buffer-name buffer))
1475 (message-fetch-field header)))))
1477 (defun message-set-work-buffer ()
1478 (if (get-buffer " *message work*")
1480 (set-buffer " *message work*")
1482 (set-buffer (get-buffer-create " *message work*"))
1483 (kill-all-local-variables)))
1485 (defun message-functionp (form)
1486 "Return non-nil if FORM is funcallable."
1487 (or (and (symbolp form) (fboundp form))
1488 (and (listp form) (eq (car form) 'lambda))
1489 (byte-code-function-p form)))
1491 (defun message-strip-subject-re (subject)
1492 "Remove \"Re:\" from subject lines."
1493 (if (string-match message-subject-re-regexp subject)
1494 (substring subject (match-end 0))
1497 (defun message-remove-header (header &optional is-regexp first reverse)
1498 "Remove HEADER in the narrowed buffer.
1499 If REGEXP, HEADER is a regular expression.
1500 If FIRST, only remove the first instance of the header.
1501 Return the number of headers removed."
1502 (goto-char (point-min))
1503 (let ((regexp (if is-regexp header (concat "^" (regexp-quote header) ":")))
1505 (case-fold-search t)
1507 (while (and (not (eobp))
1510 (not (looking-at regexp))
1511 (looking-at regexp))
1518 ;; There might be a continuation header, so we have to search
1519 ;; until we find a new non-continuation line.
1522 (if (re-search-forward "^[^ \t]" nil t)
1523 (goto-char (match-beginning 0))
1526 (if (re-search-forward "^[^ \t]" nil t)
1527 (goto-char (match-beginning 0))
1528 (goto-char (point-max)))))
1531 (defun message-remove-first-header (header)
1532 "Remove the first instance of HEADER if there is more than one."
1534 (regexp (concat "^" (regexp-quote header) ":")))
1536 (goto-char (point-min))
1537 (while (re-search-forward regexp nil t)
1540 (message-remove-header header nil t)
1543 (defun message-narrow-to-headers ()
1544 "Narrow the buffer to the head of the message."
1547 (goto-char (point-min))
1548 (if (re-search-forward
1549 (concat "^" (regexp-quote mail-header-separator) "\n") nil t)
1552 (goto-char (point-min)))
1554 (defun message-narrow-to-head ()
1555 "Narrow the buffer to the head of the message.
1556 Point is left at the beginning of the narrowed-to region."
1559 (goto-char (point-min))
1560 (if (search-forward "\n\n" nil 1)
1563 (goto-char (point-min)))
1565 (defun message-narrow-to-headers-or-head ()
1566 "Narrow the buffer to the head of the message."
1569 (goto-char (point-min))
1572 (concat "^" (regexp-quote mail-header-separator) "\n") nil t)
1573 (match-beginning 0))
1574 ((search-forward "\n\n" nil t)
1578 (goto-char (point-min)))
1580 (defun message-news-p ()
1581 "Say whether the current buffer contains a news message."
1582 (and (not message-this-is-mail)
1583 (or message-this-is-news
1586 (message-narrow-to-headers)
1587 (and (message-fetch-field "newsgroups")
1588 (not (message-fetch-field "posted-to"))))))))
1590 (defun message-mail-p ()
1591 "Say whether the current buffer contains a mail message."
1592 (and (not message-this-is-news)
1593 (or message-this-is-mail
1596 (message-narrow-to-headers)
1597 (or (message-fetch-field "to")
1598 (message-fetch-field "cc")
1599 (message-fetch-field "bcc")))))))
1601 (defun message-next-header ()
1602 "Go to the beginning of the next header."
1604 (or (eobp) (forward-char 1))
1605 (not (if (re-search-forward "^[^ \t]" nil t)
1607 (goto-char (point-max)))))
1609 (defun message-sort-headers-1 ()
1610 "Sort the buffer as headers using `message-rank' text props."
1611 (goto-char (point-min))
1614 nil 'message-next-header
1616 (message-next-header)
1620 (or (get-text-property (point) 'message-rank)
1623 (defun message-sort-headers ()
1624 "Sort the headers of the current message according to `message-header-format-alist'."
1628 (let ((max (1+ (length message-header-format-alist)))
1630 (message-narrow-to-headers)
1631 (while (re-search-forward "^[^ \n]+:" nil t)
1633 (match-beginning 0) (1+ (match-beginning 0))
1635 (if (setq rank (length (memq (assq (intern (buffer-substring
1637 (1- (match-end 0))))
1638 message-header-format-alist)
1639 message-header-format-alist)))
1642 (message-sort-headers-1))))
1652 (defvar message-mode-map nil)
1654 (unless message-mode-map
1655 (setq message-mode-map (make-keymap))
1656 (set-keymap-parent message-mode-map text-mode-map)
1657 (define-key message-mode-map "\C-c?" 'describe-mode)
1659 (define-key message-mode-map "\C-c\C-f\C-t" 'message-goto-to)
1660 (define-key message-mode-map "\C-c\C-f\C-b" 'message-goto-bcc)
1661 (define-key message-mode-map "\C-c\C-f\C-w" 'message-goto-fcc)
1662 (define-key message-mode-map "\C-c\C-f\C-c" 'message-goto-cc)
1663 (define-key message-mode-map "\C-c\C-f\C-s" 'message-goto-subject)
1664 ;; (define-key message-mode-map "\C-c\C-f\C-r" 'message-goto-reply-to)
1665 (define-key message-mode-map "\C-c\C-f\C-r" 'message-goto-mail-reply-to)
1666 (define-key message-mode-map "\C-c\C-f\C-m" 'message-goto-mail-followup-to)
1667 (define-key message-mode-map "\C-c\C-f\C-n" 'message-goto-newsgroups)
1668 (define-key message-mode-map "\C-c\C-f\C-d" 'message-goto-distribution)
1669 (define-key message-mode-map "\C-c\C-f\C-f" 'message-goto-followup-to)
1670 (define-key message-mode-map "\C-c\C-f\C-k" 'message-goto-keywords)
1671 (define-key message-mode-map "\C-c\C-f\C-u" 'message-goto-summary)
1672 (define-key message-mode-map "\C-c\C-b" 'message-goto-body)
1673 (define-key message-mode-map "\C-c\C-i" 'message-goto-signature)
1675 (define-key message-mode-map "\C-c\C-t" 'message-insert-to)
1676 (define-key message-mode-map "\C-c\C-n" 'message-insert-newsgroups)
1678 (define-key message-mode-map "\C-c\C-y" 'message-yank-original)
1679 (define-key message-mode-map "\C-c\M-\C-y" 'message-yank-buffer)
1680 (define-key message-mode-map "\C-c\C-q" 'message-fill-yanked-message)
1681 (define-key message-mode-map "\C-c\C-w" 'message-insert-signature)
1682 (define-key message-mode-map "\C-c\M-h" 'message-insert-headers)
1683 (define-key message-mode-map "\C-c\C-r" 'message-caesar-buffer-body)
1684 (define-key message-mode-map "\C-c\C-o" 'message-sort-headers)
1685 (define-key message-mode-map "\C-c\M-r" 'message-rename-buffer)
1687 (define-key message-mode-map "\C-c\C-c" 'message-send-and-exit)
1688 (define-key message-mode-map "\C-c\C-s" 'message-send)
1689 (define-key message-mode-map "\C-c\C-k" 'message-kill-buffer)
1690 (define-key message-mode-map "\C-c\C-d" 'message-dont-send)
1692 (define-key message-mode-map "\C-c\C-e" 'message-elide-region)
1693 (define-key message-mode-map "\C-c\C-v" 'message-delete-not-region)
1694 (define-key message-mode-map "\C-c\C-z" 'message-kill-to-signature)
1695 (define-key message-mode-map "\M-\r" 'message-newline-and-reformat)
1697 (define-key message-mode-map "\t" 'message-tab)
1699 (define-key message-mode-map "\C-x\C-s" 'message-save-drafts)
1700 (define-key message-mode-map "\C-xk" 'message-mimic-kill-buffer))
1703 message-mode-menu message-mode-map "Message Menu."
1705 ["Sort Headers" message-sort-headers t]
1706 ["Yank Original" message-yank-original t]
1707 ["Fill Yanked Message" message-fill-yanked-message t]
1708 ["Insert Signature" message-insert-signature t]
1709 ["Caesar (rot13) Message" message-caesar-buffer-body t]
1710 ["Caesar (rot13) Region" message-caesar-region (mark t)]
1711 ["Elide Region" message-elide-region (mark t)]
1712 ["Delete Outside Region" message-delete-not-region (mark t)]
1713 ["Kill To Signature" message-kill-to-signature t]
1714 ["Newline and Reformat" message-newline-and-reformat t]
1715 ["Rename buffer" message-rename-buffer t]
1716 ["Spellcheck" ispell-message t]
1717 ["Attach file as MIME" mime-edit-insert-file t]
1719 ["Send Message" message-send-and-exit t]
1720 ["Abort Message" message-dont-send t]
1721 ["Kill Message" message-kill-buffer t]))
1724 message-mode-field-menu message-mode-map ""
1726 ["Fetch To" message-insert-to t]
1727 ["Fetch Newsgroups" message-insert-newsgroups t]
1729 ["To" message-goto-to t]
1730 ["Subject" message-goto-subject t]
1731 ["Cc" message-goto-cc t]
1732 ["Reply-To" message-goto-reply-to t]
1733 ["Mail-Reply-To" message-goto-mail-reply-to t]
1734 ["Mail-Followup-To" message-goto-mail-followup-to t]
1735 ["Mail-Copies-To" message-goto-mail-copies-to t]
1736 ["Summary" message-goto-summary t]
1737 ["Keywords" message-goto-keywords t]
1738 ["Newsgroups" message-goto-newsgroups t]
1739 ["Followup-To" message-goto-followup-to t]
1740 ["Distribution" message-goto-distribution t]
1741 ["Body" message-goto-body t]
1742 ["Signature" message-goto-signature t]))
1744 (defvar facemenu-add-face-function)
1745 (defvar facemenu-remove-face-function)
1748 (defun message-mode ()
1749 "Major mode for editing mail and news to be sent.
1750 Like Text Mode but with these additional commands:
1751 C-c C-s message-send (send the message) C-c C-c message-send-and-exit
1752 C-c C-d Pospone sending the message C-c C-k Kill the message
1753 C-c C-f move to a header field (and create it if there isn't):
1754 C-c C-f C-t move to To C-c C-f C-s move to Subject
1755 C-c C-f C-c move to Cc C-c C-f C-b move to Bcc
1756 C-c C-f C-w move to Fcc C-c C-f C-r move to Reply-To
1757 C-c C-f C-u move to Summary C-c C-f C-n move to Newsgroups
1758 C-c C-f C-k move to Keywords C-c C-f C-d move to Distribution
1759 C-c C-f C-m move to Mail-Followup-To
1760 C-c C-f C-f move to Followup-To
1761 C-c C-t message-insert-to (add a To header to a news followup)
1762 C-c C-n message-insert-newsgroups (add a Newsgroup header to a news reply)
1763 C-c C-b message-goto-body (move to beginning of message text).
1764 C-c C-i message-goto-signature (move to the beginning of the signature).
1765 C-c C-w message-insert-signature (insert `message-signature-file' file).
1766 C-c C-y message-yank-original (insert current message, if any).
1767 C-c C-q message-fill-yanked-message (fill what was yanked).
1768 C-c C-e message-elide-region (elide the text between point and mark).
1769 C-c C-v message-delete-not-region (remove the text outside the region).
1770 C-c C-z message-kill-to-signature (kill the text up to the signature).
1771 C-c C-r message-caesar-buffer-body (rot13 the message body).
1772 M-RET message-newline-and-reformat (break the line and reformat)."
1774 (kill-all-local-variables)
1775 (set (make-local-variable 'message-reply-buffer) nil)
1776 (make-local-variable 'message-send-actions)
1777 (make-local-variable 'message-exit-actions)
1778 (make-local-variable 'message-kill-actions)
1779 (make-local-variable 'message-postpone-actions)
1780 (make-local-variable 'message-draft-article)
1781 (make-local-hook 'kill-buffer-hook)
1782 (set-syntax-table message-mode-syntax-table)
1783 (use-local-map message-mode-map)
1784 (setq local-abbrev-table message-mode-abbrev-table)
1785 (setq major-mode 'message-mode)
1786 (setq mode-name "Message")
1787 (setq buffer-offer-save t)
1788 (make-local-variable 'facemenu-add-face-function)
1789 (make-local-variable 'facemenu-remove-face-function)
1790 (setq facemenu-add-face-function
1792 (let ((face-fun (cdr (assq face message-face-alist))))
1794 (funcall face-fun (point) end)
1795 (error "Face %s not configured for %s mode" face mode-name)))
1797 facemenu-remove-face-function t)
1798 (make-local-variable 'paragraph-separate)
1799 (make-local-variable 'paragraph-start)
1800 ;; `-- ' precedes the signature. `-----' appears at the start of the
1801 ;; lines that delimit forwarded messages.
1802 ;; Lines containing just >= 3 dashes, perhaps after whitespace,
1803 ;; are also sometimes used and should be separators.
1804 (setq paragraph-start
1805 (concat (regexp-quote mail-header-separator)
1806 "$\\|[ \t]*[a-z0-9A-Z]*>+[ \t]*$\\|[ \t]*$\\|"
1809 ;;!!! Uhm... shurely this can't be right?
1810 "[> " (regexp-quote message-yank-prefix) "]+$"))
1811 (setq paragraph-separate paragraph-start)
1812 (make-local-variable 'message-reply-headers)
1813 (setq message-reply-headers nil)
1814 (make-local-variable 'message-user-agent)
1815 (make-local-variable 'message-post-method)
1816 (set (make-local-variable 'message-sent-message-via) nil)
1817 (set (make-local-variable 'message-checksum) nil)
1818 (make-local-variable 'message-parameter-alist)
1819 (setq message-parameter-alist
1820 (copy-sequence message-startup-parameter-alist))
1821 ;;(when (fboundp 'mail-hist-define-keys)
1822 ;; (mail-hist-define-keys))
1823 (when (string-match "XEmacs\\|Lucid" emacs-version)
1824 (message-setup-toolbar))
1825 (easy-menu-add message-mode-menu message-mode-map)
1826 (easy-menu-add message-mode-field-menu message-mode-map)
1827 ;; Allow mail alias things.
1828 (when (eq message-mail-alias-type 'abbrev)
1829 (if (fboundp 'mail-abbrevs-setup)
1830 (mail-abbrevs-setup)
1831 (mail-aliases-setup)))
1832 (message-set-auto-save-file-name)
1833 (unless (string-match "XEmacs" emacs-version)
1834 (set (make-local-variable 'font-lock-defaults)
1835 '((message-font-lock-keywords
1836 message-font-lock-keywords-1
1837 message-font-lock-keywords-2)
1839 (font-lock-mark-block-function . mark-paragraph))))
1840 (set (make-local-variable 'message-font-lock-last-position) nil)
1841 (make-local-variable 'adaptive-fill-regexp)
1842 (setq adaptive-fill-regexp
1843 (concat "[ \t]*[-a-z0-9A-Z]*\\(>[ \t]*\\)+[ \t]*\\|"
1844 adaptive-fill-regexp))
1845 (unless (boundp 'adaptive-fill-first-line-regexp)
1846 (setq adaptive-fill-first-line-regexp nil))
1847 (make-local-variable 'adaptive-fill-first-line-regexp)
1848 (setq adaptive-fill-first-line-regexp
1849 (concat "[ \t]*[-a-z0-9A-Z]*\\(>[ \t]*\\)+[ \t]*\\|"
1850 adaptive-fill-first-line-regexp))
1851 (make-local-variable 'indent-tabs-mode) ;Turn off tabs for indentation.
1852 (setq indent-tabs-mode nil)
1853 (run-hooks 'text-mode-hook 'message-mode-hook))
1858 ;;; Message mode commands
1861 ;;; Movement commands
1863 (defun message-goto-to ()
1864 "Move point to the To header."
1866 (message-position-on-field "To"))
1868 (defun message-goto-subject ()
1869 "Move point to the Subject header."
1871 (message-position-on-field "Subject"))
1873 (defun message-goto-cc ()
1874 "Move point to the Cc header."
1876 (message-position-on-field "Cc" "To"))
1878 (defun message-goto-bcc ()
1879 "Move point to the Bcc header."
1881 (message-position-on-field "Bcc" "Cc" "To"))
1883 (defun message-goto-fcc ()
1884 "Move point to the Fcc header."
1886 (message-position-on-field "Fcc" "To" "Newsgroups"))
1888 (defun message-goto-reply-to ()
1889 "Move point to the Reply-To header."
1891 (message-position-on-field "Reply-To" "Subject"))
1893 (defun message-goto-mail-reply-to ()
1894 "Move point to the Mail-Reply-To header."
1896 (message-position-on-field "Mail-Reply-To" "Subject"))
1898 (defun message-goto-mail-followup-to ()
1899 "Move point to the Mail-Followup-To header."
1901 (message-position-on-field "Mail-Followup-To" "Subject"))
1903 (defun message-goto-mail-copies-to ()
1904 "Move point to the Mail-Copies-To header."
1906 (message-position-on-field "Mail-Copies-To" "Subject"))
1908 (defun message-goto-newsgroups ()
1909 "Move point to the Newsgroups header."
1911 (message-position-on-field "Newsgroups"))
1913 (defun message-goto-distribution ()
1914 "Move point to the Distribution header."
1916 (message-position-on-field "Distribution"))
1918 (defun message-goto-followup-to ()
1919 "Move point to the Followup-To header."
1921 (message-position-on-field "Followup-To" "Newsgroups"))
1923 (defun message-goto-keywords ()
1924 "Move point to the Keywords header."
1926 (message-position-on-field "Keywords" "Subject"))
1928 (defun message-goto-summary ()
1929 "Move point to the Summary header."
1931 (message-position-on-field "Summary" "Subject"))
1933 (defun message-goto-body ()
1934 "Move point to the beginning of the message body."
1936 (if (looking-at "[ \t]*\n") (expand-abbrev))
1937 (goto-char (point-min))
1938 (or (search-forward (concat "\n" mail-header-separator "\n") nil t)
1939 (search-forward "\n\n" nil t)))
1941 (defun message-goto-eoh ()
1942 "Move point to the end of the headers."
1947 (defun message-goto-signature ()
1948 "Move point to the beginning of the message signature.
1949 If there is no signature in the article, go to the end and
1952 (goto-char (point-min))
1953 (if (re-search-forward message-signature-separator nil t)
1955 (goto-char (point-max))
1960 (defun message-insert-to (&optional force)
1961 "Insert a To header that points to the author of the article being replied to.
1962 If the original author requested not to be sent mail, the function signals
1964 With the prefix argument FORCE, insert the header anyway."
1966 (let ((co (message-fetch-reply-field "mail-copies-to")))
1967 (when (and (null force)
1969 (or (equal (downcase co) "never")
1970 (equal (downcase co) "nobody")))
1971 (error "The user has requested not to have copies sent via mail")))
1972 (when (and (message-position-on-field "To")
1973 (mail-fetch-field "to")
1974 (not (string-match "\\` *\\'" (mail-fetch-field "to"))))
1976 (insert (or (message-fetch-reply-field "reply-to")
1977 (message-fetch-reply-field "from") "")))
1979 (defun message-insert-newsgroups ()
1980 "Insert the Newsgroups header from the article being replied to."
1982 (when (and (message-position-on-field "Newsgroups")
1983 (mail-fetch-field "newsgroups")
1984 (not (string-match "\\` *\\'" (mail-fetch-field "newsgroups"))))
1986 (insert (or (message-fetch-reply-field "newsgroups") "")))
1990 ;;; Various commands
1992 (defun message-delete-not-region (beg end)
1993 "Delete everything in the body of the current message that is outside of the region."
1997 (delete-region (point) (if (not (message-goto-signature))
2003 (delete-region beg (progn (message-goto-body)
2006 (when (message-goto-signature)
2009 (defun message-kill-to-signature ()
2010 "Deletes all text up to the signature."
2012 (let ((point (point)))
2013 (message-goto-signature)
2016 (kill-region point (point))
2020 (defun message-newline-and-reformat ()
2021 "Insert four newlines, and then reformat if inside quoted text."
2023 (let ((prefix "[]>»|:}+ \t]*")
2024 (supercite-thing "[-._a-zA-Z0-9]*[>]+[ \t]*")
2029 (when (looking-at (concat prefix
2031 (setq quoted (match-string 0))))
2033 (setq point (point))
2035 (delete-region (point) (re-search-forward "[ \t]*"))
2038 (fill-paragraph nil)
2042 (defun message-insert-signature (&optional force)
2043 "Insert a signature. See documentation for the `message-signature' variable."
2044 (interactive (list 0))
2047 ((and (null message-signature)
2050 (goto-char (point-max))
2051 (not (re-search-backward message-signature-separator nil t))))
2052 ((and (null message-signature)
2055 ((message-functionp message-signature)
2056 (funcall message-signature))
2057 ((listp message-signature)
2058 (eval message-signature))
2059 (t message-signature)))
2061 (cond ((stringp signature)
2063 ((and (eq t signature)
2064 message-signature-file
2065 (file-exists-p message-signature-file))
2068 (goto-char (point-max))
2069 ;; Insert the signature.
2073 (if (eq signature t)
2074 (insert-file-contents message-signature-file)
2076 (goto-char (point-max))
2077 (or (bolp) (insert "\n")))))
2079 (defun message-elide-region (b e)
2080 "Elide the text between point and mark.
2081 An ellipsis (from `message-elide-ellipsis') will be inserted where the
2085 (insert message-elide-ellipsis))
2087 (defvar message-caesar-translation-table nil)
2089 (defun message-caesar-region (b e &optional n)
2090 "Caesar rotation of region by N, default 13, for decrypting netnews."
2093 (min (point) (or (mark t) (point)))
2094 (max (point) (or (mark t) (point)))
2095 (when current-prefix-arg
2096 (prefix-numeric-value current-prefix-arg))))
2098 (setq n (if (numberp n) (mod n 26) 13)) ;canonize N
2099 (unless (or (zerop n) ; no action needed for a rot of 0
2100 (= b e)) ; no region to rotate
2101 ;; We build the table, if necessary.
2102 (when (or (not message-caesar-translation-table)
2103 (/= (aref message-caesar-translation-table ?a) (+ ?a n)))
2104 (setq message-caesar-translation-table
2105 (message-make-caesar-translation-table n)))
2106 ;; Then we translate the region. Do it this way to retain
2109 (when (< (char-after b) 255)
2110 (subst-char-in-region
2111 b (1+ b) (char-after b)
2112 (aref message-caesar-translation-table (char-after b))))
2115 (defun message-make-caesar-translation-table (n)
2116 "Create a rot table with offset N."
2118 (table (make-string 256 0)))
2119 (while (< (incf i) 256)
2122 (substring table 0 ?A)
2123 (substring table (+ ?A n) (+ ?A n (- 26 n)))
2124 (substring table ?A (+ ?A n))
2125 (substring table (+ ?A 26) ?a)
2126 (substring table (+ ?a n) (+ ?a n (- 26 n)))
2127 (substring table ?a (+ ?a n))
2128 (substring table (+ ?a 26) 255))))
2130 (defun message-caesar-buffer-body (&optional rotnum)
2131 "Caesar rotates all letters in the current buffer by 13 places.
2132 Used to encode/decode possiblyun offensive messages (commonly in net.jokes).
2133 With prefix arg, specifies the number of places to rotate each letter forward.
2134 Mail and USENET news headers are not rotated."
2135 (interactive (if current-prefix-arg
2136 (list (prefix-numeric-value current-prefix-arg))
2140 (when (message-goto-body)
2141 (narrow-to-region (point) (point-max)))
2142 (message-caesar-region (point-min) (point-max) rotnum))))
2144 (defun message-pipe-buffer-body (program)
2145 "Pipe the message body in the current buffer through PROGRAM."
2148 (when (message-goto-body)
2149 (narrow-to-region (point) (point-max)))
2150 (let ((body (buffer-substring (point-min) (point-max))))
2151 (unless (equal 0 (call-process-region
2152 (point-min) (point-max) program t t))
2154 (message "%s failed" program))))))
2156 (defun message-rename-buffer (&optional enter-string)
2157 "Rename the *message* buffer to \"*message* RECIPIENT\".
2158 If the function is run with a prefix, it will ask for a new buffer
2159 name, rather than giving an automatic name."
2160 (interactive "Pbuffer name: ")
2163 (goto-char (point-min))
2164 (narrow-to-region (point)
2165 (search-forward mail-header-separator nil 'end))
2167 (if (message-news-p) (message-fetch-field "Newsgroups")
2168 (message-fetch-field "To"))
2171 (if (string-match "," mail-to)
2172 (concat (substring mail-to 0 (match-beginning 0)) ", ...")
2174 (name-default (concat "*message* " mail-trimmed-to))
2175 (name (if enter-string
2176 (read-string "New buffer name: " name-default)
2178 (rename-buffer name t)))))
2180 (defun message-fill-yanked-message (&optional justifyp)
2181 "Fill the paragraphs of a message yanked into this one.
2182 Numeric argument means justify as well."
2185 (goto-char (point-min))
2186 (search-forward (concat "\n" mail-header-separator "\n") nil t)
2187 (let ((fill-prefix message-yank-prefix))
2188 (fill-individual-paragraphs (point) (point-max) justifyp))))
2190 (defun message-indent-citation ()
2191 "Modify text just inserted from a message to be cited.
2192 The inserted text should be the region.
2193 When this function returns, the region is again around the modified text.
2195 Normally, indent each nonblank line `message-indentation-spaces' spaces.
2196 However, if `message-yank-prefix' is non-nil, insert that prefix on each line."
2197 (let ((start (point)))
2198 ;; Remove unwanted headers.
2199 (when message-ignored-cited-headers
2204 (if (search-forward "\n\n" nil t)
2207 (message-remove-header message-ignored-cited-headers t)
2208 (when (= (point-min) (point-max))
2209 (setq all-removed t))
2210 (goto-char (point-max)))
2214 ;; Delete blank lines at the start of the buffer.
2215 (while (and (point-min)
2218 (message-delete-line))
2219 ;; Delete blank lines at the end of the buffer.
2220 (goto-char (point-max))
2223 (while (and (zerop (forward-line -1))
2225 (message-delete-line))
2226 ;; Do the indentation.
2227 (if (null message-yank-prefix)
2228 (indent-rigidly start (mark t) message-indentation-spaces)
2231 (while (< (point) (mark t))
2232 (insert message-yank-prefix)
2236 (defun message-list-references (refs-list &rest refs-strs)
2237 "Add `Message-ID's which appear in REFS-STRS but not in REFS-LIST,
2239 (let (refs ref id saved-id)
2240 (when (and refs-list
2241 (integerp message-list-references-add-position))
2242 (let ((pos message-list-references-add-position))
2243 (while (and refs-list
2245 (setq saved-id (cons (car refs-list) saved-id)
2246 refs-list (cdr refs-list)
2249 (setq refs (car refs-strs)
2250 refs-strs (cdr refs-strs))
2252 (setq refs (std11-parse-msg-ids (std11-lexical-analyze refs)))
2254 (setq ref (car refs)
2256 (when (eq (car ref) 'msg-id)
2257 (setq id (concat "<"
2259 (function (lambda (p) (cdr p)))
2262 (or (member id refs-list)
2263 (push id refs-list))))))
2265 (setq refs-list (cons (car saved-id) refs-list)
2266 saved-id (cdr saved-id)))
2269 (defvar gnus-article-copy)
2270 (defun message-yank-original (&optional arg)
2271 "Insert the message being replied to, if any.
2272 Puts point before the text and mark after.
2273 Normally indents each nonblank line ARG spaces (default 3). However,
2274 if `message-yank-prefix' is non-nil, insert that prefix on each line.
2276 This function uses `message-cite-function' to do the actual citing.
2278 Just \\[universal-argument] as argument means don't indent, insert no
2279 prefix, and don't delete any headers.
2281 In addition, if `message-yank-add-new-references' is non-nil and this
2282 command is called interactively, new IDs from the yanked article will
2283 be added to \"References\" field.
2284 \(See also `message-yank-add-new-references'.)"
2286 (let ((modified (buffer-modified-p))
2287 (buffer (message-eval-parameter message-reply-buffer))
2290 message-cite-function)
2291 (delete-windows-on buffer t)
2292 (insert-buffer buffer) ; mark will be set at the end of article.
2296 ;; Add new IDs to References field.
2297 (when (and message-yank-add-new-references (interactive-p))
2300 (message-narrow-to-headers)
2301 (setq refs (message-list-references
2303 (message-fetch-field "References")))
2305 (narrow-to-region start end)
2306 (std11-narrow-to-header)
2307 (when (setq refs (message-list-references
2309 (unless (eq message-yank-add-new-references
2311 (or (message-fetch-field "References")
2312 (message-fetch-field "In-Reply-To")))
2313 (message-fetch-field "Message-ID")))
2315 (message-narrow-to-headers)
2316 (goto-char (point-min))
2317 (let ((case-fold-search t))
2318 (if (re-search-forward "^References:\\([\t ]+.+\n\\)+" nil t)
2320 (goto-char (point-max))))
2322 (list (or (assq 'References message-header-format-alist)
2323 '(References . message-fill-references)))
2324 (list (cons 'References
2325 (mapconcat 'identity (nreverse refs) " "))))
2326 (backward-delete-char 1)))))
2328 (funcall message-cite-function)
2329 (message-exchange-point-and-mark)
2333 (setq message-checksum (message-checksum))))))
2335 (defun message-yank-buffer (buffer)
2336 "Insert BUFFER into the current buffer and quote it."
2337 (interactive "bYank buffer: ")
2338 (let ((message-reply-buffer buffer))
2339 (save-window-excursion
2340 (message-yank-original))))
2342 (defun message-buffers ()
2343 "Return a list of active message buffers."
2346 (dolist (buffer (buffer-list t))
2348 (when (and (eq major-mode 'message-mode)
2349 (null message-sent-message-via))
2350 (push (buffer-name buffer) buffers))))
2351 (nreverse buffers)))
2353 (defun message-cite-original-without-signature ()
2354 "Cite function in the standard Message manner."
2355 (let ((start (point))
2358 (when message-indent-citation-function
2359 (if (listp message-indent-citation-function)
2360 message-indent-citation-function
2361 (list message-indent-citation-function)))))
2363 (when (re-search-backward message-signature-separator start t)
2364 ;; Also peel off any blank lines before the signature.
2366 (while (looking-at "^[ \t]*$")
2369 (delete-region (point) end))
2372 (funcall (pop functions)))
2373 (when message-citation-line-function
2376 (funcall message-citation-line-function))))
2378 (defvar mail-citation-hook) ;Compiler directive
2379 (defun message-cite-original ()
2380 "Cite function in the standard Message manner."
2381 (if (and (boundp 'mail-citation-hook)
2383 (run-hooks 'mail-citation-hook)
2384 (let ((start (point))
2387 (when message-indent-citation-function
2388 (if (listp message-indent-citation-function)
2389 message-indent-citation-function
2390 (list message-indent-citation-function)))))
2393 (funcall (pop functions)))
2394 (when message-citation-line-function
2397 (funcall message-citation-line-function)))))
2399 (defun message-insert-citation-line ()
2400 "Function that inserts a simple citation line."
2401 (when message-reply-headers
2402 (insert (mail-header-from message-reply-headers) " writes:\n\n")))
2404 (defun message-position-on-field (header &rest afters)
2405 (let ((case-fold-search t))
2408 (goto-char (point-min))
2411 (concat "^" (regexp-quote mail-header-separator) "$"))
2412 (match-beginning 0)))
2413 (goto-char (point-min))
2414 (if (re-search-forward (concat "^" (regexp-quote header) ":") nil t)
2416 (re-search-forward "^[^ \t]" nil 'move)
2418 (skip-chars-backward "\n")
2421 (not (re-search-forward
2422 (concat "^" (regexp-quote (car afters)) ":")
2426 (re-search-forward "^[^ \t]" nil 'move)
2427 (beginning-of-line))
2428 (insert header ": \n")
2432 (defun message-remove-signature ()
2433 "Remove the signature from the text between point and mark.
2434 The text will also be indented the normal way."
2436 (let ((start (point))
2438 (if (not (re-search-forward message-signature-separator (mark t) t))
2439 ;; No signature here, so we just indent the cited text.
2440 (message-indent-citation)
2441 ;; Find the last non-empty line.
2443 (while (looking-at "[ \t]*$")
2446 (setq mark (set-marker (make-marker) (point)))
2448 (message-indent-citation)
2449 ;; Enable undoing the deletion.
2451 (delete-region mark (mark t))
2452 (set-marker mark nil)))))
2457 ;;; Sending messages
2460 ;; Avoid byte-compile warning.
2461 (defvar message-encoding-buffer nil)
2462 (defvar message-edit-buffer nil)
2463 (defvar message-mime-mode nil)
2465 (defun message-send-and-exit (&optional arg)
2466 "Send message like `message-send', then, if no errors, exit from mail buffer."
2468 (let ((buf (current-buffer))
2469 (actions message-exit-actions)
2470 (frame (selected-frame))
2471 (org-frame message-original-frame))
2472 (when (and (message-send arg)
2474 (if message-kill-buffer-on-exit
2477 (when (eq buf (current-buffer))
2478 (message-bury buf)))
2479 (message-do-actions actions)
2480 (message-delete-frame frame org-frame)
2483 (defun message-dont-send ()
2484 "Don't send the message you have been editing."
2486 (message-save-drafts)
2487 (let ((actions message-postpone-actions)
2488 (frame (selected-frame))
2489 (org-frame message-original-frame))
2490 (message-bury (current-buffer))
2491 (message-do-actions actions)
2492 (message-delete-frame frame org-frame)))
2494 (defun message-kill-buffer ()
2495 "Kill the current buffer."
2497 (when (or (not (buffer-modified-p))
2498 (eq t message-kill-buffer-query-function)
2499 (funcall message-kill-buffer-query-function
2500 "The buffer modified; kill anyway? "))
2501 (let ((actions message-kill-actions)
2502 (frame (selected-frame))
2503 (org-frame message-original-frame))
2504 (setq buffer-file-name nil)
2505 (kill-buffer (current-buffer))
2506 (message-do-actions actions)
2507 (message-delete-frame frame org-frame)))
2510 (defun message-mimic-kill-buffer ()
2511 "Kill the current buffer with query."
2513 (unless (eq 'message-mode major-mode)
2514 (error "%s must be invoked from a message buffer." this-command))
2515 (let ((command this-command)
2516 (bufname (read-buffer (format "Kill buffer: (default %s) "
2518 (if (or (not bufname)
2519 (string-equal bufname "")
2520 (string-equal bufname (buffer-name)))
2521 (message-kill-buffer)
2522 (message "%s must be invoked only for the current buffer." command))))
2524 (defun message-delete-frame (frame org-frame)
2525 "Delete frame for editing message."
2526 (when (and (or (static-if (featurep 'xemacs)
2527 (device-on-window-system-p)
2529 (>= emacs-major-version 20))
2530 (or (and (eq message-delete-frame-on-exit t)
2531 (select-frame frame)
2532 (or (eq frame org-frame)
2534 (y-or-n-p "Delete this frame?")
2536 (and (eq message-delete-frame-on-exit 'ask)
2537 (select-frame frame)
2539 (y-or-n-p "Delete this frame?")
2541 (delete-frame frame)))
2543 (defun message-bury (buffer)
2544 "Bury this mail buffer."
2545 (let ((newbuf (other-buffer buffer)))
2546 (bury-buffer buffer)
2547 (if (and (fboundp 'frame-parameters)
2548 (cdr (assq 'dedicated (frame-parameters)))
2549 (not (null (delq (selected-frame) (visible-frame-list)))))
2550 (delete-frame (selected-frame))
2551 (switch-to-buffer newbuf))))
2553 (defun message-send (&optional arg)
2554 "Send the message in the current buffer.
2555 If `message-interactive' is non-nil, wait for success indication
2556 or error messages, and inform user.
2557 Otherwise any failure is reported in a message back to
2558 the user from the mailer."
2561 (when (or (buffer-modified-p)
2562 (message-check-element 'unchanged)
2563 (y-or-n-p "No changes in the buffer; really send? "))
2564 ;; Make it possible to undo the coming changes.
2566 (let ((inhibit-read-only t))
2567 (put-text-property (point-min) (point-max) 'read-only nil))
2568 (run-hooks 'message-send-hook)
2569 (message "Sending...")
2570 (let ((message-encoding-buffer
2571 (message-generate-new-buffer-clone-locals " message encoding"))
2572 (message-edit-buffer (current-buffer))
2573 (message-mime-mode mime-edit-mode-flag)
2574 (alist message-send-method-alist)
2578 (set-buffer message-encoding-buffer)
2580 (insert-buffer message-edit-buffer)
2581 (funcall message-encode-function)
2582 (message-fix-before-sending)
2584 (setq elem (pop alist)))
2585 (when (or (not (funcall (cadr elem)))
2586 (and (or (not (memq (car elem)
2587 message-sent-message-via))
2590 "Already sent message via %s; resend? "
2592 (setq success (funcall (caddr elem) arg))))
2594 (unless (or sent (not success))
2595 (error "No methods specified to send by"))
2597 (when (and success sent)
2600 (run-hooks 'message-sent-hook))
2601 (message "Sending...done")
2602 ;; Mark the buffer as unmodified and delete autosave.
2603 (set-buffer-modified-p nil)
2604 (delete-auto-save-file-if-necessary t)
2605 (message-disassociate-draft)
2606 ;; Delete other mail buffers and stuff.
2607 (message-do-send-housekeeping)
2608 (message-do-actions message-send-actions)
2611 (kill-buffer message-encoding-buffer)))))
2613 (defun message-send-via-mail (arg)
2614 "Send the current message via mail."
2615 (message-send-mail arg))
2617 (defun message-send-via-news (arg)
2618 "Send the current message via news."
2619 (message-send-news arg))
2621 (defmacro message-check (type &rest forms)
2622 "Eval FORMS if TYPE is to be checked."
2623 `(or (message-check-element ,type)
2627 (put 'message-check 'lisp-indent-function 1)
2628 (put 'message-check 'edebug-form-spec '(form body))
2630 (defun message-fix-before-sending ()
2631 "Do various things to make the message nice before sending it."
2632 ;; Make sure there's a newline at the end of the message.
2633 (goto-char (point-max))
2636 ;; Delete all invisible text.
2637 (message-check 'invisible-text
2638 (when (text-property-any (point-min) (point-max) 'invisible t)
2639 (put-text-property (point-min) (point-max) 'invisible nil)
2640 (unless (yes-or-no-p
2641 "Invisible text found and made visible; continue posting? ")
2642 (error "Invisible text found and made visible")))))
2644 (defun message-add-action (action &rest types)
2645 "Add ACTION to be performed when doing an exit of type TYPES."
2648 (set (setq var (intern (format "message-%s-actions" (pop types))))
2649 (nconc (symbol-value var) (list action))))))
2651 (defun message-do-actions (actions)
2652 "Perform all actions in ACTIONS."
2653 ;; Now perform actions on successful sending.
2657 ;; A simple function.
2658 ((message-functionp (car actions))
2659 (funcall (car actions)))
2660 ;; Something to be evaled.
2662 (eval (car actions)))))
2665 (defsubst message-maybe-split-and-send-mail ()
2666 "Split a message if necessary, and send it via mail.
2667 Returns nil if sending succeeded, returns any string if sending failed.
2668 This sub function is for exclusive use of `message-send-mail'."
2669 (let ((mime-edit-split-ignored-field-regexp
2670 mime-edit-split-ignored-field-regexp)
2671 (case-fold-search t)
2673 (while (string-match "Message-ID" mime-edit-split-ignored-field-regexp)
2674 (setq mime-edit-split-ignored-field-regexp
2675 (concat (substring mime-edit-split-ignored-field-regexp
2676 0 (match-beginning 0))
2677 "Hey_MIME-Edit,_there_is_an_inviolable_Message_ID"
2678 "_so_don't_rape_it!"
2679 (substring mime-edit-split-ignored-field-regexp
2683 (catch 'message-sending-mail-failure
2684 (mime-edit-maybe-split-and-send
2689 (std11-narrow-to-header mail-header-separator)
2690 (goto-char (point-min))
2691 (when (re-search-forward "^Message-ID:" nil t)
2692 (delete-region (match-end 0) (std11-field-end))
2693 (insert " " (message-make-message-id))))
2695 (funcall message-send-mail-function)
2697 (throw 'message-sending-mail-failure err))))))
2701 (funcall message-send-mail-function)
2705 (if (eq 'error (car failure))
2707 (prin1-to-string failure)))))
2709 (defun message-send-mail (&optional arg)
2710 (require 'mail-utils)
2711 (let ((tembuf (message-generate-new-buffer-clone-locals " message temp"))
2712 (case-fold-search nil)
2713 (news (message-news-p))
2716 (message-narrow-to-headers)
2717 ;; Insert some headers.
2718 (let ((message-deletable-headers
2719 (if news nil message-deletable-headers)))
2720 (message-generate-headers message-required-mail-headers))
2721 ;; Let the user do all of the above.
2722 (run-hooks 'message-header-hook))
2723 (if (not (message-check-mail-syntax))
2731 (insert-buffer message-encoding-buffer)
2732 ;; Remove some headers.
2734 (message-narrow-to-headers)
2735 ;; We Semi-gnus people have no use for it.
2736 ;; ;; We (re)generate the Lines header.
2737 ;; (when (memq 'Lines message-required-mail-headers)
2738 ;; (message-generate-headers '(Lines)))
2739 ;; Remove some headers.
2740 (message-remove-header message-ignored-mail-headers t))
2741 (goto-char (point-max))
2742 ;; require one newline at the end.
2743 (or (= (preceding-char) ?\n)
2746 (or (message-fetch-field "cc")
2747 (message-fetch-field "to")))
2748 (message-insert-courtesy-copy))
2749 (setq failure (message-maybe-split-and-send-mail)))
2750 (kill-buffer tembuf))
2751 (set-buffer message-edit-buffer)
2754 (message "Couldn't send message via mail: %s" failure)
2756 (push 'mail message-sent-message-via)))))
2758 (defun message-send-mail-with-sendmail ()
2759 "Send off the prepared buffer with sendmail."
2760 (let ((errbuf (if message-interactive
2761 (message-generate-new-buffer-clone-locals " sendmail errors")
2763 resend-to-addresses delimline)
2764 (let ((case-fold-search t))
2766 (message-narrow-to-headers)
2767 (setq resend-to-addresses (message-fetch-field "resent-to")))
2768 ;; Change header-delimiter to be what sendmail expects.
2769 (goto-char (point-min))
2771 (concat "^" (regexp-quote mail-header-separator) "\n"))
2772 (replace-match "\n")
2774 (setq delimline (point-marker))
2775 (run-hooks 'message-send-mail-hook)
2776 ;; Insert an extra newline if we need it to work around
2777 ;; Sun's bug that swallows newlines.
2778 (goto-char (1+ delimline))
2779 (when (eval message-mailer-swallows-blank-line)
2781 (when message-interactive
2785 (let ((default-directory "/"))
2787 (apply 'call-process-region
2788 (append (list (point-min) (point-max)
2789 (if (boundp 'sendmail-program)
2791 "/usr/lib/sendmail")
2792 nil errbuf nil "-oi")
2793 ;; Always specify who from,
2794 ;; since some systems have broken sendmails.
2795 ;; But some systems are more broken with -f, so
2796 ;; we'll let users override this.
2797 (if (null message-sendmail-f-is-evil)
2799 (if (null user-mail-address)
2801 user-mail-address)))
2802 ;; These mean "report errors by mail"
2803 ;; and "deliver in background".
2804 (if (null message-interactive) '("-oem" "-odb"))
2805 ;; Get the addresses from the message
2806 ;; unless this is a resend.
2807 ;; We must not do that for a resend
2808 ;; because we would find the original addresses.
2809 ;; For a resend, include the specific addresses.
2810 (if resend-to-addresses
2811 (list resend-to-addresses)
2813 (when message-interactive
2816 (goto-char (point-min))
2817 (while (re-search-forward "\n\n* *" nil t)
2818 (replace-match "; "))
2819 (if (not (zerop (buffer-size)))
2820 (error "Sending...failed to %s"
2821 (buffer-substring (point-min) (point-max)))))
2822 (when (bufferp errbuf)
2823 (kill-buffer errbuf)))))
2825 (defun message-send-mail-with-qmail ()
2826 "Pass the prepared message buffer to qmail-inject.
2827 Refer to the documentation for the variable `message-send-mail-function'
2828 to find out how to use this."
2829 ;; replace the header delimiter with a blank line
2830 (goto-char (point-min))
2832 (concat "^" (regexp-quote mail-header-separator) "\n"))
2833 (replace-match "\n")
2835 (run-hooks 'message-send-mail-hook)
2840 'call-process-region 1 (point-max) message-qmail-inject-program
2842 ;; qmail-inject's default behaviour is to look for addresses on the
2843 ;; command line; if there're none, it scans the headers.
2844 ;; yes, it does The Right Thing w.r.t. Resent-To and it's kin.
2846 ;; in general, ALL of qmail-inject's defaults are perfect for simply
2847 ;; reading a formatted (i. e., at least a To: or Resent-To header)
2848 ;; message from stdin.
2850 ;; qmail also has the advantage of not having been raped by
2851 ;; various vendors, so we don't have to allow for that, either --
2852 ;; compare this with message-send-mail-with-sendmail and weep
2853 ;; for sendmail's lost innocence.
2855 ;; all this is way cool coz it lets us keep the arguments entirely
2856 ;; free for -inject-arguments -- a big win for the user and for us
2857 ;; since we don't have to play that double-guessing game and the user
2858 ;; gets full control (no gestapo'ish -f's, for instance). --sj
2859 message-qmail-inject-args))
2860 ;; qmail-inject doesn't say anything on it's stdout/stderr,
2861 ;; we have to look at the retval instead
2863 (1 (error "qmail-inject reported permanent failure"))
2864 (111 (error "qmail-inject reported transient failure"))
2865 ;; should never happen
2866 (t (error "qmail-inject reported unknown failure"))))
2868 (defun message-send-mail-with-mh ()
2869 "Send the prepared message buffer with mh."
2870 (let ((mh-previous-window-config nil)
2871 (name (mh-new-draft-name)))
2872 (setq buffer-file-name name)
2873 ;; MH wants to generate these headers itself.
2874 (when message-mh-deletable-headers
2875 (let ((headers message-mh-deletable-headers))
2877 (goto-char (point-min))
2878 (and (re-search-forward
2879 (concat "^" (symbol-name (car headers)) ": *") nil t)
2880 (message-delete-line))
2882 (run-hooks 'message-send-mail-hook)
2883 ;; Pass it on to mh.
2886 (defun message-send-mail-with-smtp ()
2887 "Send off the prepared buffer with SMTP."
2888 (require 'smtp) ; XXX
2889 (let ((case-fold-search t)
2892 (message-narrow-to-headers)
2894 ;; XXX: Should be replaced by better one.
2895 (smtp-deduce-address-list (current-buffer)
2896 (point-min) (point-max)))
2897 ;; Remove BCC lines.
2898 (message-remove-header "bcc"))
2899 ;; replace the header delimiter with a blank line.
2900 (goto-char (point-min))
2902 (concat "^" (regexp-quote mail-header-separator) "\n"))
2903 (replace-match "\n")
2905 (run-hooks 'message-send-mail-hook)
2907 (let ((result (smtp-via-smtp user-mail-address
2910 (unless (eq result t)
2911 (error "Sending failed; " result)))
2912 (error "Sending failed; no recipients"))))
2914 (defsubst message-maybe-split-and-send-news (method)
2915 "Split a message if necessary, and send it via news.
2916 Returns nil if sending succeeded, returns t if sending failed.
2917 This sub function is for exclusive use of `message-send-news'."
2918 (let ((mime-edit-split-ignored-field-regexp
2919 mime-edit-split-ignored-field-regexp)
2920 (case-fold-search t))
2921 (while (string-match "Message-ID" mime-edit-split-ignored-field-regexp)
2922 (setq mime-edit-split-ignored-field-regexp
2923 (concat (substring mime-edit-split-ignored-field-regexp
2924 0 (match-beginning 0))
2925 "Hey_MIME-Edit,_there_is_an_inviolable_Message_ID"
2926 "_so_don't_rape_it!"
2927 (substring mime-edit-split-ignored-field-regexp
2930 (catch 'message-sending-news-failure
2931 (mime-edit-maybe-split-and-send
2936 (std11-narrow-to-header mail-header-separator)
2937 (goto-char (point-min))
2938 (when (re-search-forward "^Message-ID:" nil t)
2939 (delete-region (match-end 0) (std11-field-end))
2940 (insert " " (message-make-message-id))))
2941 (unless (funcall message-send-news-function method)
2942 (throw 'message-sending-news-failure t)))))
2944 (not (funcall message-send-news-function method)))))
2946 (defun message-send-news (&optional arg)
2947 (let ((tembuf (message-generate-new-buffer-clone-locals " *message temp*"))
2948 (case-fold-search nil)
2949 (method (if (message-functionp message-post-method)
2950 (funcall message-post-method arg)
2951 message-post-method))
2952 (message-syntax-checks
2954 (cons '(existing-newsgroups . disabled)
2955 message-syntax-checks)
2956 message-syntax-checks))
2959 (message-narrow-to-headers)
2960 ;; Insert some headers.
2961 (message-generate-headers message-required-news-headers)
2962 ;; Let the user do all of the above.
2963 (run-hooks 'message-header-hook))
2964 (message-cleanup-headers)
2965 (if (not (message-check-news-syntax))
2970 (buffer-disable-undo)
2972 (insert-buffer message-encoding-buffer)
2973 ;; Remove some headers.
2975 (message-narrow-to-headers)
2976 ;; We Semi-gnus people have no use for it.
2977 ;; ;; We (re)generate the Lines header.
2978 ;; (when (memq 'Lines message-required-mail-headers)
2979 ;; (message-generate-headers '(Lines)))
2980 ;; Remove some headers.
2981 (message-remove-header message-ignored-news-headers t))
2982 (goto-char (point-max))
2983 ;; require one newline at the end.
2984 (or (= (preceding-char) ?\n)
2986 (setq result (message-maybe-split-and-send-news method)))
2987 (kill-buffer tembuf))
2988 (set-buffer message-edit-buffer)
2991 (message "Couldn't send message via news: %s"
2992 (nnheader-get-report (car method)))
2994 (push 'news message-sent-message-via)))))
2996 ;; 1997-09-29 by MORIOKA Tomohiko
2997 (defun message-send-news-with-gnus (method)
2998 (let ((case-fold-search t))
2999 ;; Remove the delimiter.
3000 (goto-char (point-min))
3002 (concat "^" (regexp-quote mail-header-separator) "\n"))
3003 (replace-match "\n")
3005 (run-hooks 'message-send-news-hook)
3006 (gnus-open-server method)
3007 (gnus-request-post method)
3011 ;;; Header generation & syntax checking.
3014 (defun message-check-element (type)
3015 "Returns non-nil if this type is not to be checked."
3016 (if (eq message-syntax-checks 'dont-check-for-anything-just-trust-me)
3018 (let ((able (assq type message-syntax-checks)))
3020 (eq (cdr able) 'disabled)))))
3022 (defun message-check-news-syntax ()
3023 "Check the syntax of the message."
3028 ;; We narrow to the headers and check them first.
3031 (message-narrow-to-headers)
3032 (message-check-news-header-syntax)))
3035 (set-buffer message-edit-buffer)
3036 (message-check-news-body-syntax))))))
3038 (defun message-check-news-header-syntax ()
3040 ;; Check Newsgroups header.
3041 (message-check 'newsgroyps
3042 (let ((group (message-fetch-field "newsgroups")))
3045 (not (string-match "\\`[ \t]*\\'" group)))
3048 "The newsgroups field is empty or missing. Posting is denied.")))))
3049 ;; Check the Subject header.
3050 (message-check 'subject
3051 (let* ((case-fold-search t)
3052 (subject (message-fetch-field "subject")))
3055 (not (string-match "\\`[ \t]*\\'" subject)))
3058 "The subject field is empty or missing. Posting is denied.")))))
3059 ;; Check for commands in Subject.
3060 (message-check 'subject-cmsg
3061 (if (string-match "^cmsg " (message-fetch-field "subject"))
3063 "The control code \"cmsg\" is in the subject. Really post? ")
3065 ;; Check for multiple identical headers.
3066 (message-check 'multiple-headers
3068 (while (and (not found)
3069 (re-search-forward "^[^ \t:]+: " nil t))
3071 (or (re-search-forward
3076 (match-beginning 0) (- (match-end 0) 2))))
3081 (y-or-n-p (format "Multiple %s headers. Really post? " found))
3083 ;; Check for Version and Sendsys.
3084 (message-check 'sendsys
3085 (if (re-search-forward "^Sendsys:\\|^Version:" nil t)
3087 (format "The article contains a %s command. Really post? "
3088 (buffer-substring (match-beginning 0)
3089 (1- (match-end 0)))))
3091 ;; See whether we can shorten Followup-To.
3092 (message-check 'shorten-followup-to
3093 (let ((newsgroups (message-fetch-field "newsgroups"))
3094 (followup-to (message-fetch-field "followup-to"))
3096 (when (and newsgroups
3097 (string-match "," newsgroups)
3102 (setq to (completing-read
3103 "Followups to: (default all groups) "
3104 (mapcar (lambda (g) (list g))
3106 (message-tokenize-header
3108 (goto-char (point-min))
3109 (insert "Followup-To: " to "\n"))
3111 ;; Check "Shoot me".
3112 (message-check 'shoot
3113 (if (re-search-forward
3114 "Message-ID.*.i-did-not-set--mail-host-address--so-shoot-me" nil t)
3115 (y-or-n-p "You appear to have a misconfigured system. Really post? ")
3117 ;; Check for Approved.
3118 (message-check 'approved
3119 (if (re-search-forward "^Approved:" nil t)
3120 (y-or-n-p "The article contains an Approved header. Really post? ")
3122 ;; Check the Message-ID header.
3123 (message-check 'message-id
3124 (let* ((case-fold-search t)
3125 (message-id (message-fetch-field "message-id" t)))
3126 (or (not message-id)
3127 ;; Is there an @ in the ID?
3128 (and (string-match "@" message-id)
3129 ;; Is there a dot in the ID?
3130 (string-match "@[^.]*\\." message-id)
3131 ;; Does the ID end with a dot?
3132 (not (string-match "\\.>" message-id)))
3134 (format "The Message-ID looks strange: \"%s\". Really post? "
3136 ;; Check the Newsgroups & Followup-To headers.
3137 (message-check 'existing-newsgroups
3138 (let* ((case-fold-search t)
3139 (newsgroups (message-fetch-field "newsgroups"))
3140 (followup-to (message-fetch-field "followup-to"))
3141 (groups (message-tokenize-header
3143 (concat newsgroups "," followup-to)
3145 (hashtb (and (boundp 'gnus-active-hashtb)
3146 gnus-active-hashtb))
3148 (if (or (not hashtb)
3149 (not (boundp 'gnus-read-active-file))
3150 (not gnus-read-active-file)
3151 (eq gnus-read-active-file 'some))
3154 (when (and (not (boundp (intern (car groups) hashtb)))
3155 (not (equal (car groups) "poster")))
3156 (push (car groups) errors))
3162 "Really post to %s unknown group%s: %s "
3163 (if (= (length errors) 1) "this" "these")
3164 (if (= (length errors) 1) "" "s")
3165 (mapconcat 'identity errors ", ")))))))
3166 ;; Check the Newsgroups & Followup-To headers for syntax errors.
3167 (message-check 'valid-newsgroups
3168 (let ((case-fold-search t)
3169 (headers '("Newsgroups" "Followup-To"))
3171 (while (and headers (not error))
3172 (when (setq header (mail-fetch-field (car headers)))
3176 "\\`\\([-+_&.a-zA-Z0-9]+\\)?\\(,[-+_&.a-zA-Z0-9]+\\)*\\'"
3181 (not (string-match "\\.\\'\\|\\.\\." g)))
3182 (message-tokenize-header header ","))))
3189 (format "The %s header looks odd: \"%s\". Really post? "
3190 (car headers) header)))))
3191 (message-check 'repeated-newsgroups
3192 (let ((case-fold-search t)
3193 (headers '("Newsgroups" "Followup-To"))
3194 header error groups group)
3197 (when (setq header (mail-fetch-field (pop headers)))
3198 (setq groups (message-tokenize-header header ","))
3199 (while (setq group (pop groups))
3200 (when (member group groups)
3206 (format "Group %s is repeated in headers. Really post? " error)))))
3207 ;; Check the From header.
3208 (message-check 'from
3209 (let* ((case-fold-search t)
3210 (from (message-fetch-field "from"))
3214 (message "There is no From line. Posting is denied.")
3216 ((or (not (string-match
3218 (setq ad (nth 1 (mail-extract-address-components
3219 from))))) ;larsi@ifi
3220 (string-match "\\.\\." ad) ;larsi@ifi..uio
3221 (string-match "@\\." ad) ;larsi@.ifi.uio
3222 (string-match "\\.$" ad) ;larsi@ifi.uio.
3223 (not (string-match "^[^@]+@[^@]+$" ad)) ;larsi.ifi.uio
3224 (string-match "(.*).*(.*)" from)) ;(lars) (lars)
3226 "Denied posting -- the From looks strange: \"%s\"." from)
3230 (defun message-check-news-body-syntax ()
3232 ;; Check for long lines.
3233 (message-check 'long-lines
3234 (goto-char (point-min))
3236 (concat "^" (regexp-quote mail-header-separator) "$"))
3240 (< (current-column) 80))
3241 (zerop (forward-line 1))))
3245 "You have lines longer than 79 characters. Really post? ")))
3246 ;; Check whether the article is empty.
3247 (message-check 'empty
3248 (goto-char (point-min))
3250 (concat "^" (regexp-quote mail-header-separator) "$"))
3253 (goto-char (point-max))
3254 (re-search-backward message-signature-separator nil t)
3256 (or (re-search-backward "[^ \n\t]" b t)
3257 (y-or-n-p "Empty article. Really post? "))))
3258 ;; Check for control characters.
3259 (message-check 'control-chars
3260 (if (re-search-forward "[\000-\007\013\015-\032\034-\037\200-\237]" nil t)
3262 "The article contains control characters. Really post? ")
3264 ;; Check 8bit characters.
3265 (message-check '8bit
3266 (message-check-8bit))
3267 ;; Check excessive size.
3268 (message-check 'size
3269 (if (> (buffer-size) 60000)
3271 (format "The article is %d octets long. Really post? "
3274 ;; Check whether any new text has been added.
3275 (message-check 'new-text
3277 (not message-checksum)
3278 (not (eq (message-checksum) message-checksum))
3280 "It looks like no new text has been added. Really post? ")))
3281 ;; Check the length of the signature.
3282 (message-check 'signature
3283 (goto-char (point-max))
3284 (if (> (count-lines (point) (point-max)) 5)
3287 "Your .sig is %d lines; it should be max 4. Really post? "
3288 (1- (count-lines (point) (point-max)))))
3291 (defun message-check-mail-syntax ()
3292 "Check the syntax of the message."
3297 ;; We narrow to the headers and check them first.
3300 (message-narrow-to-headers)
3301 (message-check-mail-header-syntax)))
3304 (set-buffer message-edit-buffer)
3305 (message-check-mail-body-syntax))))))
3307 (defun message-check-mail-header-syntax ()
3310 (defun message-check-mail-body-syntax ()
3312 ;; Check 8bit characters.
3313 (message-check '8bit
3314 (message-check-8bit)
3317 (defun message-check-8bit ()
3318 "Check the article contains 8bit characters."
3320 (set-buffer message-encoding-buffer)
3321 (message-narrow-to-headers)
3322 (let* ((case-fold-search t)
3323 (field-value (message-fetch-field "content-transfer-encoding")))
3324 (if (and field-value
3325 (member (downcase field-value) message-8bit-encoding-list))
3328 (set-buffer (get-buffer-create " message syntax"))
3330 (goto-char (point-min))
3331 (set-buffer-multibyte nil)
3332 (insert-buffer message-encoding-buffer)
3333 (goto-char (point-min))
3334 (if (re-search-forward "[^\x00-\x7f]" nil t)
3336 "The article contains 8bit characters. Really post? ")
3339 (defun message-checksum ()
3340 "Return a \"checksum\" for the current buffer."
3343 (goto-char (point-min))
3345 (concat "^" (regexp-quote mail-header-separator) "$"))
3347 (when (not (looking-at "[ \t\n]"))
3348 (setq sum (logxor (ash sum 1) (if (natnump sum) 0 1)
3353 (defun message-do-fcc ()
3354 "Process Fcc headers in the current buffer."
3355 (let ((case-fold-search t)
3356 (coding-system-for-write 'raw-text)
3357 (output-coding-system 'raw-text)
3360 (set-buffer (get-buffer-create " *message temp*"))
3362 (insert-buffer-substring message-encoding-buffer)
3364 (message-narrow-to-headers)
3365 (while (setq file (message-fetch-field "fcc"))
3367 (message-remove-header "fcc" nil t)))
3368 (goto-char (point-min))
3369 (re-search-forward (concat "^" (regexp-quote mail-header-separator) "$"))
3370 (replace-match "" t t)
3371 ;; Process FCC operations.
3373 (setq file (pop list))
3374 (if (string-match "^[ \t]*|[ \t]*\\(.*\\)[ \t]*$" file)
3375 ;; Pipe the article to the program in question.
3376 (call-process-region (point-min) (point-max) shell-file-name
3377 nil nil nil shell-command-switch
3378 (match-string 1 file))
3379 ;; Save the article.
3380 (setq file (expand-file-name file))
3381 (unless (file-exists-p (file-name-directory file))
3382 (make-directory (file-name-directory file) t))
3383 (if (and message-fcc-handler-function
3384 (not (eq message-fcc-handler-function 'rmail-output)))
3385 (funcall message-fcc-handler-function file)
3386 (if (and (file-readable-p file) (mail-file-babyl-p file))
3387 (rmail-output file 1 nil t)
3388 (let ((mail-use-rfc822 t))
3389 (rmail-output file 1 t t))))))
3390 (kill-buffer (current-buffer)))))
3392 (defun message-output (filename)
3393 "Append this article to Unix/babyl mail file.."
3394 (if (and (file-readable-p filename)
3395 (mail-file-babyl-p filename))
3396 (rmail-output-to-rmail-file filename t)
3397 (gnus-output-to-mail filename t)))
3399 (defun message-cleanup-headers ()
3400 "Do various automatic cleanups of the headers."
3401 ;; Remove empty lines in the header.
3403 (message-narrow-to-headers)
3404 ;; Remove blank lines.
3405 (while (re-search-forward "^[ \t]*\n" nil t)
3406 (replace-match "" t t))
3408 ;; Correct Newsgroups and Followup-To headers: Change sequence of
3409 ;; spaces to comma and eliminate spaces around commas. Eliminate
3410 ;; embedded line breaks.
3411 (goto-char (point-min))
3412 (while (re-search-forward "^\\(Newsgroups\\|Followup-To\\): +" nil t)
3416 (if (re-search-forward "^[^ \t]" nil t)
3420 (goto-char (point-min))
3421 (while (re-search-forward "\n[ \t]+" nil t)
3422 (replace-match " " t t)) ;No line breaks (too confusing)
3423 (goto-char (point-min))
3424 (while (re-search-forward "[ \t\n]*,[ \t\n]*\\|[ \t]+" nil t)
3425 (replace-match "," t t))
3426 (goto-char (point-min))
3427 ;; Remove trailing commas.
3428 (when (re-search-forward ",+$" nil t)
3429 (replace-match "" t t))))))
3431 (defun message-make-date (&optional now)
3432 "Make a valid data header.
3433 If NOW, use that time instead."
3434 (let* ((now (or now (current-time)))
3435 (zone (nth 8 (decode-time now)))
3439 (setq zone (- zone)))
3441 (format-time-string "%d" now)
3442 ;; The month name of the %b spec is locale-specific. Pfff.
3444 (capitalize (car (rassoc (nth 4 (decode-time now))
3445 parse-time-months))))
3446 (format-time-string "%Y %H:%M:%S " now)
3447 ;; We do all of this because XEmacs doesn't have the %z spec.
3448 (format "%s%02d%02d" sign (/ zone 3600) (/ (% zone 3600) 60)))))
3450 (defun message-make-followup-subject (subject)
3451 "Make a followup Subject."
3453 ((and (eq message-use-subject-re 'guess)
3454 (string-match message-subject-encoded-re-regexp subject))
3456 (message-use-subject-re
3457 (concat "Re: " (message-strip-subject-re subject)))
3460 (defun message-make-message-id ()
3461 "Make a unique Message-ID."
3462 (concat "<" (message-unique-id)
3463 (let ((psubject (save-excursion (message-fetch-field "subject")))
3465 (save-excursion (message-fetch-field "supersedes"))))
3467 (and message-reply-headers
3468 (mail-header-references message-reply-headers)
3469 (mail-header-subject message-reply-headers)
3471 (mail-header-subject message-reply-headers)
3473 (message-strip-subject-re
3474 (mail-header-subject message-reply-headers))
3475 (message-strip-subject-re psubject))))
3477 (string-match "_-_@" psupersedes)))
3479 "@" (message-make-fqdn) ">"))
3481 (defvar message-unique-id-char nil)
3483 ;; If you ever change this function, make sure the new version
3484 ;; cannot generate IDs that the old version could.
3485 ;; You might for example insert a "." somewhere (not next to another dot
3486 ;; or string boundary), or modify the "fsf" string.
3487 (defun message-unique-id ()
3488 ;; Don't use microseconds from (current-time), they may be unsupported.
3489 ;; Instead we use this randomly inited counter.
3490 (setq message-unique-id-char
3491 (% (1+ (or message-unique-id-char (logand (random t) (1- (lsh 1 20)))))
3492 ;; (current-time) returns 16-bit ints,
3493 ;; and 2^16*25 just fits into 4 digits i base 36.
3495 (let ((tm (current-time)))
3497 (if (memq system-type '(ms-dos emx vax-vms))
3498 (let ((user (downcase (user-login-name))))
3499 (while (string-match "[^a-z0-9_]" user)
3500 (aset user (match-beginning 0) ?_))
3502 (message-number-base36 (user-uid) -1))
3503 (message-number-base36 (+ (car tm)
3504 (lsh (% message-unique-id-char 25) 16)) 4)
3505 (message-number-base36 (+ (nth 1 tm)
3506 (lsh (/ message-unique-id-char 25) 16)) 4)
3507 ;; Append the newsreader name, because while the generated
3508 ;; ID is unique to this newsreader, other newsreaders might
3509 ;; otherwise generate the same ID via another algorithm.
3512 (defun message-number-base36 (num len)
3517 (concat (message-number-base36 (/ num 36) (1- len))
3518 (char-to-string (aref "zyxwvutsrqponmlkjihgfedcba9876543210"
3521 (defun message-make-organization ()
3522 "Make an Organization header."
3523 (let* ((organization
3524 (when message-user-organization
3525 (if (message-functionp message-user-organization)
3526 (funcall message-user-organization)
3527 message-user-organization))))
3529 (message-set-work-buffer)
3530 (cond ((stringp organization)
3531 (insert organization))
3532 ((and (eq t organization)
3533 message-user-organization-file
3534 (file-exists-p message-user-organization-file))
3535 (insert-file-contents message-user-organization-file)))
3536 (goto-char (point-min))
3537 (while (re-search-forward "[\t\n]+" nil t)
3538 (replace-match "" t t))
3539 (unless (zerop (buffer-size))
3542 (defun message-make-lines ()
3543 "Count the number of lines and return numeric string."
3547 (goto-char (point-min))
3549 (concat "^" (regexp-quote mail-header-separator) "$"))
3551 (int-to-string (count-lines (point) (point-max))))))
3553 (defun message-make-in-reply-to ()
3554 "Return the In-Reply-To header for this message."
3555 (when message-reply-headers
3556 (let ((mid (mail-header-message-id message-reply-headers))
3557 (from (mail-header-from message-reply-headers))
3558 (date (mail-header-date message-reply-headers)))
3562 (let ((pair (std11-extract-address-components from)))
3564 (or (car pair) (cadr pair))
3566 (if (or (not date) (string= date ""))
3567 "(unknown date)" date)
3570 (defun message-make-distribution ()
3571 "Make a Distribution header."
3572 (let ((orig-distribution (message-fetch-reply-field "distribution")))
3573 (cond ((message-functionp message-distribution-function)
3574 (funcall message-distribution-function))
3575 (t orig-distribution))))
3577 (defun message-make-expires ()
3578 "Return an Expires header based on `message-expires'."
3579 (let ((current (current-time))
3580 (future (* 1.0 message-expires 60 60 24)))
3581 ;; Add the future to current.
3582 (setcar current (+ (car current) (round (/ future (expt 2 16)))))
3583 (setcar (cdr current) (+ (nth 1 current) (% (round future) (expt 2 16))))
3584 (message-make-date current)))
3586 (defun message-make-path ()
3588 (let ((login-name (user-login-name)))
3589 (cond ((null message-user-path)
3590 (concat (system-name) "!" login-name))
3591 ((stringp message-user-path)
3592 ;; Support GENERICPATH. Suggested by vixie@decwrl.dec.com.
3593 (concat message-user-path "!" login-name))
3596 (defun message-make-from ()
3597 "Make a From header."
3598 (let* ((style message-from-style)
3599 (login (message-make-address))
3601 (or (and (boundp 'user-full-name)
3604 (when (string= fullname "&")
3605 (setq fullname (user-login-name)))
3607 (message-set-work-buffer)
3610 (equal fullname ""))
3612 ((or (eq style 'angles)
3613 (and (not (eq style 'parens))
3614 ;; Use angles if no quoting is needed, or if parens would
3615 ;; need quoting too.
3616 (or (not (string-match "[^- !#-'*+/-9=?A-Z^-~]" fullname))
3617 (let ((tmp (concat fullname nil)))
3618 (while (string-match "([^()]*)" tmp)
3619 (aset tmp (match-beginning 0) ?-)
3620 (aset tmp (1- (match-end 0)) ?-))
3621 (string-match "[\\()]" tmp)))))
3623 (goto-char (point-min))
3624 ;; Look for a character that cannot appear unquoted
3625 ;; according to RFC 822.
3626 (when (re-search-forward "[^- !#-'*+/-9=?A-Z^-~]" nil 1)
3627 ;; Quote fullname, escaping specials.
3628 (goto-char (point-min))
3630 (while (re-search-forward "[\"\\]" nil 1)
3631 (replace-match "\\\\\\&" t))
3633 (insert " <" login ">"))
3634 (t ; 'parens or default
3636 (let ((fullname-start (point)))
3638 (goto-char fullname-start)
3639 ;; RFC 822 says \ and nonmatching parentheses
3640 ;; must be escaped in comments.
3641 ;; Escape every instance of ()\ ...
3642 (while (re-search-forward "[()\\]" nil 1)
3643 (replace-match "\\\\\\&" t))
3644 ;; ... then undo escaping of matching parentheses,
3645 ;; including matching nested parentheses.
3646 (goto-char fullname-start)
3647 (while (re-search-forward
3648 "\\(\\=\\|[^\\]\\(\\\\\\\\\\)*\\)\\\\(\\(\\([^\\]\\|\\\\\\\\\\)*\\)\\\\)"
3650 (replace-match "\\1(\\3)" t)
3651 (goto-char fullname-start)))
3655 (defun message-make-sender ()
3656 "Return the \"real\" user address.
3657 This function tries to ignore all user modifications, and
3658 give as trustworthy answer as possible."
3659 (concat (user-login-name) "@" (system-name)))
3661 (defun message-make-address ()
3662 "Make the address of the user."
3663 (or (message-user-mail-address)
3664 (concat (user-login-name) "@" (message-make-domain))))
3666 (defun message-user-mail-address ()
3667 "Return the pertinent part of `user-mail-address'."
3668 (when user-mail-address
3669 (if (string-match " " user-mail-address)
3670 (nth 1 (std11-extract-address-components user-mail-address))
3671 user-mail-address)))
3673 (defun message-make-fqdn ()
3674 "Return user's fully qualified domain name."
3675 (let ((system-name (system-name))
3676 (user-mail (message-user-mail-address)))
3678 ((string-match "[^.]\\.[^.]" system-name)
3679 ;; `system-name' returned the right result.
3681 ;; Try `mail-host-address'.
3682 ((and (boundp 'mail-host-address)
3683 (stringp mail-host-address)
3684 (string-match "\\." mail-host-address))
3686 ;; We try `user-mail-address' as a backup.
3688 (string-match "\\." user-mail)
3689 (string-match "@\\(.*\\)\\'" user-mail))
3690 (match-string 1 user-mail))
3691 ;; Default to this bogus thing.
3693 (concat system-name ".i-did-not-set--mail-host-address--so-shoot-me")))))
3695 (defun message-make-host-name ()
3696 "Return the name of the host."
3697 (let ((fqdn (message-make-fqdn)))
3698 (string-match "^[^.]+\\." fqdn)
3699 (substring fqdn 0 (1- (match-end 0)))))
3701 (defun message-make-domain ()
3702 "Return the domain name."
3703 (or mail-host-address
3704 (message-make-fqdn)))
3706 ;; Dummy to avoid byte-compile warning.
3707 (defvar mule-version)
3708 (defvar emacs-beta-version)
3709 (defvar xemacs-codename)
3710 (defvar gnus-inviolable-extended-version)
3712 (defun message-make-user-agent ()
3713 "Return user-agent info if the value `message-user-agent' is non-nil. If the
3714 \"User-Agent\" field has already exist, it's value will be added in the return
3716 (when message-user-agent
3718 (goto-char (point-min))
3719 (let ((case-fold-search t)
3720 user-agent start p end)
3721 (if (re-search-forward "^User-Agent:[\t ]*" nil t)
3723 (setq start (match-beginning 0)
3725 end (std11-field-end)
3726 user-agent (buffer-substring-no-properties p end))
3727 (delete-region start (1+ end))
3728 (concat message-user-agent " " user-agent))
3729 message-user-agent)))))
3731 (defun message-generate-headers (headers)
3732 "Prepare article HEADERS.
3733 Headers already prepared in the buffer are not modified."
3735 (message-narrow-to-headers)
3736 (let* ((Date (message-make-date))
3737 (Message-ID (message-make-message-id))
3738 (Organization (message-make-organization))
3739 (From (message-make-from))
3740 (Path (message-make-path))
3743 (In-Reply-To (message-make-in-reply-to))
3745 (Distribution (message-make-distribution))
3746 (Lines (message-make-lines))
3747 (User-Agent (message-make-user-agent))
3748 (Expires (message-make-expires))
3749 (case-fold-search t)
3751 ;; First we remove any old generated headers.
3752 (let ((headers message-deletable-headers))
3753 (unless (buffer-modified-p)
3754 (setq headers (delq 'Message-ID (copy-sequence headers))))
3756 (goto-char (point-min))
3757 (and (re-search-forward
3758 (concat "^" (symbol-name (car headers)) ": *") nil t)
3759 (get-text-property (1+ (match-beginning 0)) 'message-deletable)
3760 (message-delete-line))
3762 ;; Go through all the required headers and see if they are in the
3763 ;; articles already. If they are not, or are empty, they are
3764 ;; inserted automatically - except for Subject, Newsgroups and
3767 (goto-char (point-min))
3768 (setq elem (pop headers))
3770 (if (eq (car elem) 'optional)
3771 (setq header (cdr elem))
3772 (setq header (car elem)))
3774 (when (or (not (re-search-forward
3778 (if (stringp header)
3780 (symbol-name header))))
3784 ;; The header was found. We insert a space after the
3785 ;; colon, if there is none.
3786 (if (/= (char-after) ? ) (insert " ") (forward-char 1))
3787 ;; Find out whether the header is empty...
3788 (looking-at "[ \t]*\n[^ \t]")))
3789 ;; So we find out what value we should insert.
3792 ((and (consp elem) (eq (car elem) 'optional))
3793 ;; This is an optional header. If the cdr of this
3794 ;; is something that is nil, then we do not insert
3796 (setq header (cdr elem))
3797 (or (and (fboundp (cdr elem)) (funcall (cdr elem)))
3798 (and (boundp (cdr elem)) (symbol-value (cdr elem)))))
3800 ;; The element is a cons. Either the cdr is a
3801 ;; string to be inserted verbatim, or it is a
3802 ;; function, and we insert the value returned from
3804 (or (and (stringp (cdr elem)) (cdr elem))
3805 (and (fboundp (cdr elem)) (funcall (cdr elem)))))
3806 ((and (boundp header) (symbol-value header))
3807 ;; The element is a symbol. We insert the value
3808 ;; of this symbol, if any.
3809 (symbol-value header))
3811 ;; We couldn't generate a value for this header,
3812 ;; so we just ask the user.
3813 (read-from-minibuffer
3814 (format "Empty header for %s; enter value: " header)))))
3815 ;; Finally insert the header.
3817 (not (equal value "")))
3821 ;; This header didn't exist, so we insert it.
3822 (goto-char (point-max))
3823 (insert (if (stringp header) header (symbol-name header))
3828 ;; The value of this header was empty, so we clear
3829 ;; totally and insert the new value.
3830 (delete-region (point) (gnus-point-at-eol))
3834 ;; Add the deletable property to the headers that require it.
3835 (and (memq header message-deletable-headers)
3836 (progn (beginning-of-line) (looking-at "[^:]+: "))
3837 (add-text-properties
3838 (point) (match-end 0)
3839 '(message-deletable t face italic) (current-buffer)))))))
3840 ;; Insert new Sender if the From is strange.
3841 (let ((from (message-fetch-field "from"))
3842 (sender (message-fetch-field "sender"))
3843 (secure-sender (message-make-sender)))
3845 (not (message-check-element 'sender))
3848 (cadr (std11-extract-address-components from)))
3849 (downcase secure-sender)))
3854 (cadr (std11-extract-address-components sender)))
3855 (downcase secure-sender)))))
3856 (goto-char (point-min))
3857 ;; Rename any old Sender headers to Original-Sender.
3858 (when (re-search-forward "^\\(Original-\\)*Sender:" nil t)
3860 (insert "Original-")
3861 (beginning-of-line))
3862 (when (or (message-news-p)
3863 (string-match "@.+\\.." secure-sender))
3864 (insert "Sender: " secure-sender "\n")))))))
3866 (defun message-insert-courtesy-copy ()
3867 "Insert a courtesy message in mail copies of combined messages."
3871 (message-narrow-to-headers)
3872 (when (setq newsgroups (message-fetch-field "newsgroups"))
3873 (goto-char (point-max))
3874 (insert "Posted-To: " newsgroups "\n")))
3876 (when message-courtesy-message
3878 ((string-match "%s" message-courtesy-message)
3879 (insert (format message-courtesy-message newsgroups)))
3881 (insert message-courtesy-message)))))))
3884 ;;; Setting up a message buffer
3887 (defun message-fill-address (header value)
3889 (narrow-to-region (point) (point))
3890 (insert (capitalize (symbol-name header))
3892 (if (consp value) (car value) value)
3894 (narrow-to-region (point-min) (1- (point-max)))
3896 (goto-char (point-min))
3898 (skip-chars-forward "^,\"" (point-max))
3899 (if (or (eq (char-after) ?,)
3902 (if (and (> (current-column) 78)
3906 (looking-at "[ \t]*")
3907 (replace-match "\n " t t)))
3908 (setq last (1+ (point))))
3909 (setq quoted (not quoted)))
3912 (goto-char (point-max))
3916 (defun message-fill-references (header value)
3917 (insert (capitalize (symbol-name header))
3919 (std11-fill-msg-id-list-string
3920 (if (consp value) (car value) value))
3923 (defun message-fill-header (header value)
3924 (let ((begin (point))
3927 (insert (capitalize (symbol-name header))
3929 (if (consp value) (car value) value)
3932 (narrow-to-region begin (point))
3933 (fill-region-as-paragraph begin (point))
3934 ;; Tapdance around looong Message-IDs.
3936 (when (looking-at "[ \t]*$")
3937 (message-delete-line))
3939 (re-search-forward ":" nil t)
3940 (when (looking-at "\n[ \t]+")
3941 (replace-match " " t t))
3942 (goto-char (point-max)))))
3944 (defun message-shorten-1 (list cut surplus)
3945 ;; Cut SURPLUS elements out of LIST, beginning with CUTth one.
3946 (setcdr (nthcdr (- cut 2) list)
3947 (nthcdr (+ (- cut 2) surplus 1) list)))
3949 (defun message-shorten-references (header references)
3950 "Trim REFERENCES to be less than 31 Message-ID long, and fold them.
3951 If folding is disallowed, also check that the REFERENCES are less
3952 than 988 characters long, and if they are not, trim them until they are."
3959 (goto-char (point-min))
3960 ;; Cons a list of valid references.
3961 (while (re-search-forward "<[^>]+>" nil t)
3962 (push (match-string 0) refs))
3963 (setq refs (nreverse refs)
3964 count (length refs)))
3966 ;; If the list has more than MAXCOUNT elements, trim it by
3967 ;; removing the CUTth element and the required number of
3968 ;; elements that follow.
3969 (when (> count maxcount)
3970 (let ((surplus (- count maxcount)))
3971 (message-shorten-1 refs cut surplus)
3972 (decf count surplus)))
3974 ;; If folding is disallowed, make sure the total length (including
3975 ;; the spaces between) will be less than MAXSIZE characters.
3976 (when message-cater-to-broken-inn
3978 (totalsize (+ (apply #'+ (mapcar #'length refs))
3981 (ptr (nthcdr (1- cut) refs)))
3982 ;; Decide how many elements to cut off...
3983 (while (> totalsize maxsize)
3984 (decf totalsize (1+ (length (car ptr))))
3986 (setq ptr (cdr ptr)))
3989 (message-shorten-1 refs cut surplus))))
3991 ;; Finally, collect the references back into a string and insert
3992 ;; it into the buffer.
3993 (let ((refstring (mapconcat #'identity refs " ")))
3994 (if message-cater-to-broken-inn
3995 (insert (capitalize (symbol-name header)) ": "
3997 (message-fill-header header refstring)))))
3999 (defun message-position-point ()
4000 "Move point to where the user probably wants to find it."
4001 (message-narrow-to-headers)
4003 ((re-search-forward "^[^:]+:[ \t]*$" nil t)
4004 (search-backward ":" )
4007 (if (eq (char-after) ? )
4011 (goto-char (point-max))
4014 (unless (looking-at "$")
4018 (defun message-buffer-name (type &optional to group)
4019 "Return a new (unique) buffer name based on TYPE and TO."
4021 ;; Generate a new buffer name The Message Way.
4022 ((eq message-generate-new-buffers 'unique)
4023 (generate-new-buffer-name
4027 (or (car (std11-extract-address-components to))
4030 (if (and group (not (string= group ""))) (concat " on " group) "")
4032 ;; Check whether `message-generate-new-buffers' is a function,
4033 ;; and if so, call it.
4034 ((message-functionp message-generate-new-buffers)
4035 (funcall message-generate-new-buffers type to group))
4036 ((eq message-generate-new-buffers 'unsent)
4037 (generate-new-buffer-name
4038 (concat "*unsent " type
4041 (or (car (mail-extract-address-components to))
4044 (if (and group (not (string= group ""))) (concat " on " group) "")
4046 ;; Use standard name.
4048 (format "*%s message*" type))))
4050 (defmacro message-pop-to-buffer-1 (buffer)
4052 (let (special-display-buffer-names
4053 special-display-regexps
4054 same-window-buffer-names
4055 same-window-regexps)
4056 (pop-to-buffer ,buffer))
4057 (pop-to-buffer ,buffer)))
4059 (defun message-pop-to-buffer (name)
4060 "Pop to buffer NAME, and warn if it already exists and is modified."
4061 (let ((buffer (get-buffer name))
4062 (pop-up-frames (and (or (static-if (featurep 'xemacs)
4063 (device-on-window-system-p)
4065 (>= emacs-major-version 20))
4066 message-use-multi-frames)))
4068 (buffer-name buffer))
4070 (message-pop-to-buffer-1 buffer)
4071 (when (and (buffer-modified-p)
4073 "Message already being composed; erase? ")))
4074 (error "Message being composed")))
4075 (message-pop-to-buffer-1 name))
4079 (set (make-local-variable 'message-original-frame) (selected-frame)))))
4081 (defun message-do-send-housekeeping ()
4082 "Kill old message buffers."
4083 ;; We might have sent this buffer already. Delete it from the
4085 (setq message-buffer-list (delq (current-buffer) message-buffer-list))
4086 (while (and message-max-buffers
4088 (>= (length message-buffer-list) message-max-buffers))
4089 ;; Kill the oldest buffer -- unless it has been changed.
4090 (let ((buffer (pop message-buffer-list)))
4091 (when (and (buffer-name buffer)
4092 (not (buffer-modified-p buffer)))
4093 (kill-buffer buffer))))
4094 ;; Rename the buffer.
4095 (if message-send-rename-function
4096 (funcall message-send-rename-function)
4097 (when (string-match "\\`\\*\\(unsent \\)?" (buffer-name))
4099 (concat "*sent " (substring (buffer-name) (match-end 0))) t)))
4100 ;; Push the current buffer onto the list.
4101 (when message-max-buffers
4102 (setq message-buffer-list
4103 (nconc message-buffer-list (list (current-buffer))))))
4105 (defvar mc-modes-alist)
4106 (defun message-setup (headers &optional replybuffer actions)
4107 (when (and (boundp 'mc-modes-alist)
4108 (not (assq 'message-mode mc-modes-alist)))
4109 (push '(message-mode (encrypt . mc-encrypt-message)
4110 (sign . mc-sign-message))
4113 (setq message-send-actions actions))
4114 (setq message-reply-buffer
4115 (or (message-get-parameter 'reply-buffer)
4117 (goto-char (point-min))
4118 ;; Insert all the headers.
4121 (alist message-header-format-alist))
4123 (unless (assq (caar h) message-header-format-alist)
4124 (push (list (caar h)) alist))
4128 (delete-region (point) (progn (forward-line -1) (point)))
4129 (when message-default-headers
4130 (insert message-default-headers)
4131 (or (bolp) (insert ?\n)))
4135 (insert mail-header-separator "\n")
4139 (when (message-news-p)
4140 (when message-default-news-headers
4141 (insert message-default-news-headers)
4142 (or (bolp) (insert ?\n)))
4143 (when message-generate-headers-first
4144 (message-generate-headers
4147 (copy-sequence message-required-news-headers))))))
4148 (when (message-mail-p)
4149 (when message-default-mail-headers
4150 (insert message-default-mail-headers)
4151 (or (bolp) (insert ?\n)))
4152 (when message-generate-headers-first
4153 (message-generate-headers
4156 (copy-sequence message-required-mail-headers))))))
4157 (run-hooks 'message-signature-setup-hook)
4158 (message-insert-signature)
4160 (message-narrow-to-headers)
4161 (run-hooks 'message-header-setup-hook))
4162 (set-buffer-modified-p nil)
4163 (setq buffer-undo-list nil)
4164 (run-hooks 'message-setup-hook)
4165 (message-position-point)
4168 (defun message-set-auto-save-file-name ()
4169 "Associate the message buffer with a file in the drafts directory."
4170 (when message-auto-save-directory
4172 (setq message-draft-article
4173 (nndraft-request-associate-buffer "drafts"))
4174 (setq buffer-file-name (expand-file-name "*message*"
4175 message-auto-save-directory))
4176 (setq buffer-auto-save-file-name (make-auto-save-file-name)))
4177 (clear-visited-file-modtime)
4178 (static-if (boundp 'MULE)
4179 (set-file-coding-system message-draft-coding-system)
4180 (setq buffer-file-coding-system message-draft-coding-system))))
4182 (defun message-disassociate-draft ()
4183 "Disassociate the message buffer from the drafts directory."
4184 (when message-draft-article
4185 (nndraft-request-expire-articles
4186 (list message-draft-article) "drafts" nil t)))
4188 (defun message-insert-headers ()
4189 "Generate the headers for the article."
4193 (message-narrow-to-headers)
4194 (when (message-news-p)
4195 (message-generate-headers
4198 (copy-sequence message-required-news-headers)))))
4199 (when (message-mail-p)
4200 (message-generate-headers
4203 (copy-sequence message-required-mail-headers))))))))
4208 ;;; Commands for interfacing with message
4212 (defun message-mail (&optional to subject
4213 other-headers continue switch-function
4214 yank-action send-actions)
4215 "Start editing a mail message to be sent.
4216 OTHER-HEADERS is an alist of header/value pairs."
4218 (let ((message-this-is-mail t))
4219 (message-pop-to-buffer (message-buffer-name "mail" to))
4222 `((To . ,(or to "")) (Subject . ,(or subject "")))
4223 (when other-headers other-headers)))))
4226 (defun message-news (&optional newsgroups subject)
4227 "Start editing a news article to be sent."
4229 (let ((message-this-is-news t))
4230 (message-pop-to-buffer (message-buffer-name "news" nil newsgroups))
4231 (message-setup `((Newsgroups . ,(or newsgroups ""))
4232 (Subject . ,(or subject ""))))))
4235 (defun message-reply (&optional to-address wide)
4236 "Start editing a reply to the article in the current buffer."
4238 (let ((cur (current-buffer))
4239 from subject date to cc
4240 references message-id follow-to
4241 (inhibit-point-motion-hooks t)
4242 (message-this-is-mail t)
4243 mct never-mct mft mrt gnus-warning in-reply-to)
4245 (message-narrow-to-head)
4246 ;; Allow customizations to have their say.
4248 ;; This is a regular reply.
4249 (if (message-functionp message-reply-to-function)
4250 (setq follow-to (funcall message-reply-to-function)))
4251 ;; This is a followup.
4252 (if (message-functionp message-wide-reply-to-function)
4255 (funcall message-wide-reply-to-function)))))
4256 ;; Find all relevant headers we need.
4257 (setq from (message-fetch-field "from")
4258 date (message-fetch-field "date" t)
4259 subject (or (message-fetch-field "subject") "none")
4260 references (message-fetch-field "references")
4261 message-id (message-fetch-field "message-id" t)
4262 to (message-fetch-field "to")
4263 cc (message-fetch-field "cc")
4264 mct (when (and wide message-use-mail-copies-to)
4265 (message-fetch-field "mail-copies-to"))
4266 mft (when (and wide message-use-mail-followup-to)
4267 (message-fetch-field "mail-followup-to"))
4268 mrt (when message-use-mail-reply-to
4269 (or (message-fetch-field "mail-reply-to")
4270 (message-fetch-field "reply-to")))
4271 gnus-warning (message-fetch-field "gnus-warning"))
4272 (when (and gnus-warning (string-match "<[^>]+>" gnus-warning))
4273 (setq message-id (match-string 0 gnus-warning)))
4274 ;; Get the references from "In-Reply-To" field if there were
4275 ;; no references and "In-Reply-To" field looks promising.
4277 (when (and (setq in-reply-to (message-fetch-field "in-reply-to"))
4278 (string-match "<[^>]+>" in-reply-to))
4279 (setq references (match-string 0 in-reply-to))))
4280 ;; Remove any (buggy) Re:'s that are present and make a
4282 (setq subject (message-make-followup-subject subject))
4285 ;; Handle special values of Mail-Copies-To.
4288 ((and (or (equal (downcase mct) "never")
4289 (equal (downcase mct) "nobody"))
4290 (or (not (eq message-use-mail-copies-to 'ask))
4292 (concat "Obey Mail-Copies-To: never? ") t "\
4293 You should normally obey the Mail-Copies-To: header.
4295 `Mail-Copies-To: never'
4296 directs you not to send your response to the author.")))
4299 ((and (or (equal (downcase mct) "always")
4300 (equal (downcase mct) "poster"))
4301 (or (not (eq message-use-mail-copies-to 'ask))
4303 (concat "Obey Mail-Copies-To: always? ") t "\
4304 You should normally obey the Mail-Copies-To: header.
4306 `Mail-Copies-To: always'
4307 sends a copy of your response to the author.")))
4308 (setq mct (or mrt from)))
4309 ((and (eq message-use-mail-copies-to 'ask)
4312 (concat "Obey Mail-Copies-To: " mct " ? ") t "\
4313 You should normally obey the Mail-Copies-To: header.
4315 `Mail-Copies-To: " mct "'
4316 sends a copy of your response to " (if (string-match "," mct)
4317 "the specified addresses"
4318 "that address") ".")))
4324 (to-address (setq follow-to (list (cons 'To to-address))))
4325 ((not wide) (setq follow-to (list (cons 'To (or mrt from)))))
4326 ;; Handle Mail-Followup-To.
4328 (or (not (eq message-use-mail-followup-to 'ask))
4330 (concat "Obey Mail-Followup-To: " mft "? ") t "\
4331 You should normally obey the Mail-Followup-To: header.
4333 `Mail-Followup-To: " mft "'
4334 directs your response to " (if (string-match "," mft)
4335 "the specified addresses"
4336 "that address only") ".
4338 A typical situation where Mail-Followup-To is used is when the author thinks
4339 that further discussion should take place only in "
4340 (if (string-match "," mft)
4341 "the specified mailing lists"
4342 "that mailing list") ".")))
4343 (setq follow-to (list (cons 'To mft)))
4345 (push (cons 'Cc mct) follow-to)))
4349 (message-set-work-buffer)
4351 (insert (or mrt from "")))
4352 (insert (if to (concat (if (bolp) "" ", ") to "") ""))
4353 (insert (if mct (concat (if (bolp) "" ", ") mct) ""))
4354 (insert (if cc (concat (if (bolp) "" ", ") cc) ""))
4355 (goto-char (point-min))
4356 (while (re-search-forward "[ \t]+" nil t)
4357 (replace-match " " t t))
4358 ;; Remove addresses that match `rmail-dont-reply-to-names'.
4359 (let ((rmail-dont-reply-to-names message-dont-reply-to-names))
4360 (insert (prog1 (rmail-dont-reply-to (buffer-string))
4362 (goto-char (point-min))
4363 ;; Perhaps Mail-Copies-To: never removed the only address?
4365 (insert (or mrt from "")))
4369 (cons (mail-strip-quoted-names addr) addr))
4370 (message-tokenize-header (buffer-string))))
4373 (setq ccalist (delq (assoc (car (pop s)) s) ccalist)))))
4374 (setq follow-to (list (cons 'To (cdr (pop ccalist)))))
4376 (let ((ccs (cons 'Cc (mapconcat
4377 (lambda (addr) (cdr addr)) ccalist ", "))))
4378 (when (string-match "^ +" (cdr ccs))
4379 (setcdr ccs (substring (cdr ccs) (match-end 0))))
4380 (push ccs follow-to)))))))
4382 (message-pop-to-buffer (message-buffer-name
4383 (if wide "wide reply" "reply") from
4384 (if wide to-address nil)))
4386 (setq message-reply-headers
4387 (make-full-mail-header-from-decoded-header
4388 0 subject from date message-id references 0 0 ""))
4391 `((Subject . ,subject)
4393 ,@(if (or references message-id)
4394 `((References . ,(concat (or references "") (and references " ")
4395 (or message-id ""))))))
4399 (defun message-wide-reply (&optional to-address)
4400 "Make a \"wide\" reply to the message in the current buffer."
4402 (message-reply to-address t))
4405 (defun message-followup (&optional to-newsgroups)
4406 "Follow up to the message in the current buffer.
4407 If TO-NEWSGROUPS, use that as the new Newsgroups line."
4409 (let ((cur (current-buffer))
4410 from subject date mct
4411 references message-id follow-to
4412 (inhibit-point-motion-hooks t)
4413 (message-this-is-news t)
4414 followup-to distribution newsgroups gnus-warning posted-to mft mrt)
4416 (message-narrow-to-head)
4417 (when (message-functionp message-followup-to-function)
4419 (funcall message-followup-to-function)))
4420 (setq from (message-fetch-field "from")
4421 date (message-fetch-field "date" t)
4422 subject (or (message-fetch-field "subject") "none")
4423 references (message-fetch-field "references")
4424 message-id (message-fetch-field "message-id" t)
4425 followup-to (when message-use-followup-to
4426 (message-fetch-field "followup-to"))
4427 distribution (message-fetch-field "distribution")
4428 newsgroups (message-fetch-field "newsgroups")
4429 posted-to (message-fetch-field "posted-to")
4430 mct (when message-use-mail-copies-to
4431 (message-fetch-field "mail-copies-to"))
4432 mft (when message-use-mail-followup-to
4433 (message-fetch-field "mail-followup-to"))
4434 mrt (when message-use-mail-reply-to
4435 (or (message-fetch-field "mail-reply-to")
4436 (message-fetch-field "reply-to")))
4437 gnus-warning (message-fetch-field "gnus-warning"))
4438 (when (and gnus-warning (string-match "<[^>]+>" gnus-warning))
4439 (setq message-id (match-string 0 gnus-warning)))
4440 ;; Remove bogus distribution.
4441 (when (and (stringp distribution)
4442 (let ((case-fold-search t))
4443 (string-match "world" distribution)))
4444 (setq distribution nil))
4445 ;; Remove any (buggy) Re:'s that are present and make a
4447 (setq subject (message-make-followup-subject subject))
4450 ;; Handle special values of Mail-Copies-To.
4453 ((and (or (equal (downcase mct) "never")
4454 (equal (downcase mct) "nobody"))
4455 (or (not (eq message-use-mail-copies-to 'ask))
4457 (concat "Obey Mail-Copies-To: never? ") t "\
4458 You should normally obey the Mail-Copies-To: header.
4460 `Mail-Copies-To: never'
4461 directs you not to send your response to the author.")))
4463 ((and (or (equal (downcase mct) "always")
4464 (equal (downcase mct) "poster"))
4465 (or (not (eq message-use-mail-copies-to 'ask))
4467 (concat "Obey Mail-Copies-To: always? ") t "\
4468 You should normally obey the Mail-Copies-To: header.
4470 `Mail-Copies-To: always'
4471 sends a copy of your response to the author.")))
4472 (setq mct (or mrt from)))
4473 ((and (eq message-use-mail-copies-to 'ask)
4476 (concat "Obey Mail-Copies-To: " mct " ? ") t "\
4477 You should normally obey the Mail-Copies-To: header.
4479 `Mail-Copies-To: " mct "'
4480 sends a copy of your response to " (if (string-match "," mct)
4481 "the specified addresses"
4482 "that address") ".")))
4488 (to-newsgroups (setq follow-to (list (cons 'Newsgroups to-newsgroups))))
4489 ;; Handle Followup-To.
4492 ((equal (downcase followup-to) "poster")
4493 (if (or (eq message-use-followup-to 'use)
4494 (message-y-or-n-p "Obey Followup-To: poster? " t "\
4495 You should normally obey the Followup-To: header.
4497 `Followup-To: poster'
4498 sends your response via e-mail instead of news.
4500 A typical situation where `Followup-To: poster' is used is when the author
4501 does not read the newsgroup, so he wouldn't see any replies sent to it."))
4502 (setq message-this-is-news nil
4504 follow-to (list (cons 'To (or mrt from ""))))
4505 (setq follow-to (list (cons 'Newsgroups newsgroups)))))
4507 (if (or (equal followup-to newsgroups)
4508 (not (eq message-use-followup-to 'ask))
4510 (concat "Obey Followup-To: " followup-to "? ") t "\
4511 You should normally obey the Followup-To: header.
4513 `Followup-To: " followup-to "'
4514 directs your response to " (if (string-match "," followup-to)
4515 "the specified newsgroups"
4516 "that newsgroup only") ".
4518 If a message is posted to several newsgroups, Followup-To is often
4519 used to direct the following discussion to one newsgroup only,
4520 because discussions that are spread over several newsgroup tend to
4521 be fragmented and very difficult to follow.
4523 Also, some source/announcement newsgroups are not indented for discussion;
4524 responses here are directed to other newsgroups."))
4525 (setq follow-to (list (cons 'Newsgroups followup-to)))
4526 (setq follow-to (list (cons 'Newsgroups newsgroups)))))))
4527 ;; Handle Mail-Followup-To, followup via e-mail.
4529 (or (not (eq message-use-mail-followup-to 'ask))
4531 (concat "Obey Mail-Followup-To: " mft "? ") t "\
4532 You should normally obey the Mail-Followup-To: header.
4534 `Mail-Followup-To: " mft "'
4535 directs your response to " (if (string-match "," mft)
4536 "the specified addresses"
4537 "that address only") " instead of news.
4539 A typical situation where Mail-Followup-To is used is when the author thinks
4540 that further discussion should take place only in "
4541 (if (string-match "," mft)
4542 "the specified mailing lists"
4543 "that mailing list") ".")))
4544 (setq message-this-is-news nil
4546 follow-to (list (cons 'To mft))))
4547 (posted-to (setq follow-to (list (cons 'Newsgroups posted-to))))
4549 (setq follow-to (list (cons 'Newsgroups newsgroups))))))
4551 (message-pop-to-buffer (message-buffer-name "followup" from newsgroups))
4553 (setq message-reply-headers
4554 (make-full-mail-header-from-decoded-header
4555 0 subject from date message-id references 0 0 ""))
4558 `((Subject . ,subject)
4560 ,@(and mct (list (cons 'Cc mct)))
4561 ,@(and distribution (list (cons 'Distribution distribution)))
4562 ,@(if (or references message-id)
4563 `((References . ,(concat (or references "") (and references " ")
4564 (or message-id ""))))))
4568 (defun message-cancel-news ()
4569 "Cancel an article you posted."
4571 (unless (message-news-p)
4572 (error "This is not a news article; canceling is impossible"))
4573 (when (yes-or-no-p "Do you really want to cancel this article? ")
4574 (let (from newsgroups message-id distribution buf sender)
4576 ;; Get header info. from original article.
4578 (message-narrow-to-head)
4579 (setq from (message-fetch-field "from")
4580 sender (message-fetch-field "sender")
4581 newsgroups (message-fetch-field "newsgroups")
4582 message-id (message-fetch-field "message-id" t)
4583 distribution (message-fetch-field "distribution")))
4584 ;; Make sure that this article was written by the user.
4585 (unless (or (and sender
4588 (downcase (message-make-sender))))
4590 (downcase (cadr (std11-extract-address-components
4592 (downcase (cadr (std11-extract-address-components
4593 (message-make-from))))))
4594 (error "This article is not yours"))
4595 ;; Make control message.
4596 (setq buf (set-buffer (get-buffer-create " *message cancel*")))
4598 (insert "Newsgroups: " newsgroups "\n"
4599 "From: " (message-make-from) "\n"
4600 "Subject: cmsg cancel " message-id "\n"
4601 "Control: cancel " message-id "\n"
4603 (concat "Distribution: " distribution "\n")
4605 mail-header-separator "\n"
4606 message-cancel-message)
4607 (run-hooks 'message-cancel-hook)
4608 (message "Canceling your article...")
4609 (if (let ((message-syntax-checks
4610 'dont-check-for-anything-just-trust-me)
4611 (message-encoding-buffer (current-buffer))
4612 (message-edit-buffer (current-buffer)))
4613 (message-send-news))
4614 (message "Canceling your article...done"))
4615 (kill-buffer buf)))))
4617 (defun message-supersede-setup-for-mime-edit ()
4618 (set (make-local-variable 'message-setup-hook) nil)
4622 (defun message-supersede ()
4623 "Start composing a message to supersede the current message.
4624 This is done simply by taking the old article and adding a Supersedes
4625 header line with the old Message-ID."
4627 (let ((cur (current-buffer))
4628 (sender (message-fetch-field "sender"))
4629 (from (message-fetch-field "from")))
4630 ;; Check whether the user owns the article that is to be superseded.
4631 (unless (or (and sender
4634 (downcase (message-make-sender))))
4636 (downcase (cadr (std11-extract-address-components from)))
4637 (downcase (cadr (std11-extract-address-components
4638 (message-make-from))))))
4639 (error "This article is not yours"))
4640 ;; Get a normal message buffer.
4641 (message-pop-to-buffer (message-buffer-name "supersede"))
4642 (insert-buffer-substring cur)
4643 (message-narrow-to-head)
4644 ;; Remove unwanted headers.
4645 (when message-ignored-supersedes-headers
4646 (message-remove-header message-ignored-supersedes-headers t))
4647 (goto-char (point-min))
4648 (if (not (re-search-forward "^Message-ID: " nil t))
4649 (error "No Message-ID in this article")
4650 (replace-match "Supersedes: " t t))
4651 (goto-char (point-max))
4652 (insert mail-header-separator)
4654 (when message-supersede-setup-function
4655 (funcall message-supersede-setup-function))
4656 (run-hooks 'message-supersede-setup-hook)
4657 (goto-char (point-min))
4658 (search-forward (concat "\n" mail-header-separator "\n") nil t)))
4661 (defun message-recover ()
4662 "Reread contents of current buffer from its last auto-save file."
4664 (let ((file-name (make-auto-save-file-name)))
4665 (cond ((save-window-excursion
4666 (if (not (eq system-type 'vax-vms))
4667 (with-output-to-temp-buffer "*Directory*"
4668 (buffer-disable-undo standard-output)
4669 (let ((default-directory "/"))
4671 "ls" nil standard-output nil "-l" file-name))))
4672 (yes-or-no-p (format "Recover auto save file %s? " file-name)))
4673 (let ((buffer-read-only nil))
4675 (insert-file-contents file-name nil)))
4676 (t (error "message-recover cancelled")))))
4678 ;;; Washing Subject:
4680 (defun message-wash-subject (subject)
4681 "Remove junk like \"Re:\", \"(fwd)\", etc. that was added to the subject by previous forwarders, replyers, etc."
4683 (insert-string subject)
4684 (goto-char (point-min))
4685 ;; strip Re/Fwd stuff off the beginning
4686 (while (re-search-forward
4687 "\\([Rr][Ee]:\\|[Ff][Ww][Dd]\\(\\[[0-9]*\\]\\)?:\\|[Ff][Ww]:\\)" nil t)
4690 ;; and gnus-style forwards [foo@bar.com] subject
4691 (goto-char (point-min))
4692 (while (re-search-forward "\\[[^ \t]*\\(@\\|\\.\\)[^ \t]*\\]" nil t)
4696 (goto-char (point-max))
4697 (while (re-search-backward "([Ff][Ww][Dd])" nil t)
4700 ;; and finally, any whitespace that was left-over
4701 (goto-char (point-min))
4702 (while (re-search-forward "^[ \t]+" nil t)
4704 (goto-char (point-max))
4705 (while (re-search-backward "[ \t]+$" nil t)
4710 ;;; Forwarding messages.
4712 (defun message-forward-subject-author-subject (subject)
4713 "Generate a subject for a forwarded message.
4714 The form is: [Source] Subject, where if the original message was mail,
4715 Source is the sender, and if the original message was news, Source is
4716 the list of newsgroups is was posted to."
4718 (or (message-fetch-field
4719 (if (message-news-p) "newsgroups" "from"))
4723 (defun message-forward-subject-fwd (subject)
4724 "Generate a subject for a forwarded message.
4725 The form is: Fwd: Subject, where Subject is the original subject of
4727 (concat "Fwd: " subject))
4729 (defun message-make-forward-subject ()
4730 "Return a Subject header suitable for the message in the current buffer."
4734 (message-narrow-to-head)
4735 (let ((funcs message-make-forward-subject-function)
4736 (subject (message-fetch-field "Subject")))
4739 (if message-wash-forwarded-subjects
4740 (message-wash-subject
4741 (nnheader-decode-subject subject))
4742 (nnheader-decode-subject subject))
4744 ;; Make sure funcs is a list.
4747 (setq funcs (list funcs)))
4748 ;; Apply funcs in order, passing subject generated by previous
4749 ;; func to the next one.
4751 (when (message-functionp (car funcs))
4752 (setq subject (funcall (car funcs) subject)))
4753 (setq funcs (cdr funcs)))
4757 (defun message-forward (&optional news)
4758 "Forward the current message via mail.
4759 Optional NEWS will use news to forward instead of mail."
4761 (let ((cur (current-buffer))
4762 (subject (message-make-forward-subject))
4765 (message-news nil subject)
4766 (message-mail nil subject))
4767 ;; Put point where we want it before inserting the forwarded
4769 (if message-signature-before-forwarded-message
4770 (goto-char (point-max))
4771 (message-goto-body))
4772 ;; Make sure we're at the start of the line.
4775 ;; Narrow to the area we are to insert.
4776 (narrow-to-region (point) (point))
4777 ;; Insert the separators and the forwarded buffer.
4778 (insert message-forward-start-separator)
4779 (setq art-beg (point))
4780 (insert-buffer-substring cur)
4781 (goto-char (point-max))
4782 (insert message-forward-end-separator)
4783 (set-text-properties (point-min) (point-max) nil)
4784 ;; Remove all unwanted headers.
4786 (narrow-to-region (point) (if (search-forward "\n\n" nil t)
4789 (goto-char (point-min))
4790 (message-remove-header message-included-forward-headers t nil t)
4792 (message-position-point)))
4795 (defun message-resend (address)
4796 "Resend the current article to ADDRESS."
4798 (list (message-read-from-minibuffer "Resend message to: ")))
4799 (message "Resending message to %s..." address)
4801 (let ((cur (current-buffer))
4803 ;; We first set up a normal mail buffer.
4804 (set-buffer (get-buffer-create " *message resend*"))
4806 ;; avoid to turn-on-mime-edit
4807 (let (message-setup-hook)
4808 (message-setup `((To . ,address)))
4810 ;; Insert our usual headers.
4811 (message-generate-headers '(From Date To))
4812 (message-narrow-to-headers)
4813 ;; Rename them all to "Resent-*".
4814 (while (re-search-forward "^[A-Za-z]" nil t)
4819 (delete-region (point) (point-max))
4821 ;; Insert the message to be resent.
4822 (insert-buffer-substring cur)
4823 (goto-char (point-min))
4824 (search-forward "\n\n")
4827 (narrow-to-region beg (point))
4828 (message-remove-header message-ignored-resent-headers t)
4829 (goto-char (point-max)))
4830 (insert mail-header-separator)
4831 ;; Rename all old ("Also-")Resent headers.
4832 (while (re-search-backward "^\\(Also-\\)*Resent-" beg t)
4835 ;; Quote any "From " lines at the beginning.
4837 (when (looking-at "From ")
4838 (replace-match "X-From-Line: "))
4840 (let ((message-encoding-buffer (current-buffer))
4841 (message-edit-buffer (current-buffer)))
4842 (let (message-required-mail-headers)
4843 (message-send-mail)))
4844 (kill-buffer (current-buffer)))
4845 (message "Resending message to %s...done" address)))
4847 (defun message-bounce-setup-for-mime-edit ()
4848 (set (make-local-variable 'message-setup-hook) nil)
4852 (defun message-bounce ()
4853 "Re-mail the current message.
4854 This only makes sense if the current message is a bounce message than
4855 contains some mail you have written which has been bounced back to
4858 (let ((cur (current-buffer))
4860 (message-pop-to-buffer (message-buffer-name "bounce"))
4861 (insert-buffer-substring cur)
4863 (message-narrow-to-head)
4864 (if (and (message-fetch-field "MIME-Version")
4865 (setq boundary (message-fetch-field "Content-Type")))
4866 (if (string-match "boundary=\"\\([^\"]+\\)\"" boundary)
4867 (setq boundary (concat (match-string 1 boundary) " *\n"
4868 "Content-Type: message/rfc822"))
4869 (setq boundary nil)))
4871 (goto-char (point-min))
4872 (search-forward "\n\n" nil t)
4874 (re-search-forward boundary nil t)
4876 (and (re-search-forward message-unsent-separator nil t)
4878 (re-search-forward "^Return-Path:.*\n" nil t))
4879 ;; We remove everything before the bounced mail.
4882 (if (re-search-forward "^[^ \n\t]+:" nil t)
4886 (message-narrow-to-head)
4887 (message-remove-header message-ignored-bounced-headers t)
4888 (goto-char (point-max))
4889 (insert mail-header-separator))
4890 (when message-bounce-setup-function
4891 (funcall message-bounce-setup-function))
4892 (run-hooks 'message-bounce-setup-hook)
4893 (message-position-point)))
4896 ;;; Interactive entry points for new message buffers.
4900 (defun message-mail-other-window (&optional to subject)
4901 "Like `message-mail' command, but display mail buffer in another window."
4903 (let ((pop-up-windows t)
4904 (special-display-buffer-names nil)
4905 (special-display-regexps nil)
4906 (same-window-buffer-names nil)
4907 (same-window-regexps nil))
4908 (message-pop-to-buffer (message-buffer-name "mail" to)))
4909 (let ((message-this-is-mail t))
4910 (message-setup `((To . ,(or to "")) (Subject . ,(or subject ""))))))
4913 (defun message-mail-other-frame (&optional to subject)
4914 "Like `message-mail' command, but display mail buffer in another frame."
4916 (let ((pop-up-frames t)
4917 (special-display-buffer-names nil)
4918 (special-display-regexps nil)
4919 (same-window-buffer-names nil)
4920 (same-window-regexps nil))
4921 (message-pop-to-buffer (message-buffer-name "mail" to)))
4922 (let ((message-this-is-mail t))
4923 (message-setup `((To . ,(or to "")) (Subject . ,(or subject ""))))))
4926 (defun message-news-other-window (&optional newsgroups subject)
4927 "Start editing a news article to be sent."
4929 (let ((pop-up-windows t)
4930 (special-display-buffer-names nil)
4931 (special-display-regexps nil)
4932 (same-window-buffer-names nil)
4933 (same-window-regexps nil))
4934 (message-pop-to-buffer (message-buffer-name "news" nil newsgroups)))
4935 (let ((message-this-is-news t))
4936 (message-setup `((Newsgroups . ,(or newsgroups ""))
4937 (Subject . ,(or subject ""))))))
4940 (defun message-news-other-frame (&optional newsgroups subject)
4941 "Start editing a news article to be sent."
4943 (let ((pop-up-frames t)
4944 (special-display-buffer-names nil)
4945 (special-display-regexps nil)
4946 (same-window-buffer-names nil)
4947 (same-window-regexps nil))
4948 (message-pop-to-buffer (message-buffer-name "news" nil newsgroups)))
4949 (let ((message-this-is-news t))
4950 (message-setup `((Newsgroups . ,(or newsgroups ""))
4951 (Subject . ,(or subject ""))))))
4955 ;; This code should be moved to underline.el (from which it is stolen).
4958 (defun bold-region (start end)
4959 "Bold all nonblank characters in the region.
4960 Works by overstriking characters.
4961 Called from program, takes two arguments START and END
4962 which specify the range to operate on."
4965 (let ((end1 (make-marker)))
4966 (move-marker end1 (max start end))
4967 (goto-char (min start end))
4968 (while (< (point) end1)
4969 (or (looking-at "[_\^@- ]")
4970 (insert (char-after) "\b"))
4971 (forward-char 1)))))
4974 (defun unbold-region (start end)
4975 "Remove all boldness (overstruck characters) in the region.
4976 Called from program, takes two arguments START and END
4977 which specify the range to operate on."
4980 (let ((end1 (make-marker)))
4981 (move-marker end1 (max start end))
4982 (goto-char (min start end))
4983 (while (re-search-forward "\b" end1 t)
4984 (if (eq (char-after) (char-after (- (point) 2)))
4985 (delete-char -2))))))
4987 (defalias 'message-exchange-point-and-mark 'exchange-point-and-mark)
4989 ;; Support for toolbar
4990 (when (string-match "XEmacs\\|Lucid" emacs-version)
4991 (require 'messagexmas))
4993 ;;; Group name completion.
4995 (defvar message-newgroups-header-regexp
4996 "^\\(Newsgroups\\|Followup-To\\|Posted-To\\|Gcc\\):"
4997 "Regexp that match headers that lists groups.")
4999 (defun message-tab ()
5000 "Expand group names in Newsgroups and Followup-To headers.
5001 Do a `tab-to-tab-stop' if not in those headers."
5003 (if (let ((mail-abbrev-mode-regexp message-newgroups-header-regexp))
5004 (mail-abbrev-in-expansion-header-p))
5005 (message-expand-group)
5008 (defvar gnus-active-hashtb)
5009 (defun message-expand-group ()
5010 "Expand the group name under point."
5011 (let* ((b (save-excursion
5016 (skip-chars-forward "^:")
5019 (skip-chars-backward "^, \t\n") (point))))
5020 (completion-ignore-case t)
5021 (string (buffer-substring b (progn (skip-chars-forward "^,\t\n ")
5023 (hashtb (and (boundp 'gnus-active-hashtb) gnus-active-hashtb))
5024 (completions (all-completions string hashtb))
5026 (delete-region b (point))
5028 ((= (length completions) 1)
5029 (if (string= (car completions) string)
5032 (message "Only matching group"))
5033 (insert (car completions))))
5034 ((and (setq comp (try-completion string hashtb))
5035 (not (string= comp string)))
5040 (message "No matching groups")
5041 (save-selected-window
5042 (pop-to-buffer "*Completions*")
5043 (buffer-disable-undo)
5044 (let ((buffer-read-only nil))
5046 (let ((standard-output (current-buffer)))
5047 (display-completion-list (sort completions 'string<)))
5048 (goto-char (point-min))
5049 (delete-region (point) (progn (forward-line 3) (point))))))))))
5053 (defun message-talkative-question (ask question show &rest text)
5054 "Call FUNCTION with argument QUESTION; optionally display TEXT... args.
5055 If SHOW is non-nil, the arguments TEXT... are displayed in a temp buffer.
5056 The following arguments may contain lists of values."
5058 (setq text (message-flatten-list text)))
5059 (save-window-excursion
5061 (with-output-to-temp-buffer " *MESSAGE information message*"
5062 (set-buffer " *MESSAGE information message*")
5063 (mapcar 'princ text)
5064 (goto-char (point-min))))
5065 (funcall ask question))
5066 (funcall ask question)))
5068 (defun message-flatten-list (list)
5069 "Return a new, flat list that contains all elements of LIST.
5071 \(message-flatten-list '(1 (2 3 (4 5 (6))) 7))
5074 (apply 'append (mapcar 'message-flatten-list list)))
5078 (defun message-generate-new-buffer-clone-locals (name &optional varstr)
5079 "Create and return a buffer with a name based on NAME using generate-new-buffer.
5080 Then clone the local variables and values from the old buffer to the
5081 new one, cloning only the locals having a substring matching the
5083 (let ((oldbuf (current-buffer)))
5085 (set-buffer (generate-new-buffer name))
5086 (message-clone-locals oldbuf varstr)
5089 (defun message-clone-locals (buffer &optional varstr)
5090 "Clone the local variables from BUFFER to the current buffer."
5091 (let ((locals (save-excursion
5093 (buffer-local-variables)))
5095 "^\\(gnus\\|nn\\|message\\|user-\\(mail-address\\|full-name\\)\\)"))
5098 (when (and (consp local)
5100 (string-match regexp (symbol-name (car local)))
5102 (string-match varstr (symbol-name (car local)))))
5104 (set (make-local-variable (car local))
5109 ;;; @ for MIME Edit mode
5112 (defun message-maybe-encode ()
5113 (when message-mime-mode
5114 ;; Inherit the buffer local variable `mime-edit-pgp-processing'.
5115 (let ((pgp-processing (with-current-buffer message-edit-buffer
5116 mime-edit-pgp-processing)))
5117 (setq mime-edit-pgp-processing pgp-processing))
5118 (run-hooks 'mime-edit-translate-hook)
5119 (if (catch 'mime-edit-error
5121 (mime-edit-pgp-enclose-buffer)
5122 (mime-edit-translate-body)
5124 (error "Translation error!")
5127 (run-hooks 'mime-edit-exit-hook)
5130 (defun message-mime-insert-article (&optional full-headers)
5132 (let ((message-cite-function 'mime-edit-inserted-message-filter)
5133 (message-reply-buffer
5134 (message-get-parameter-with-eval 'original-buffer))
5136 (message-yank-original nil)
5138 (narrow-to-region (goto-char start)
5139 (if (search-forward "\n\n" nil t)
5142 (goto-char (point-min))
5143 (let ((message-included-forward-headers
5144 (if full-headers "" message-included-forward-headers)))
5145 (message-remove-header message-included-forward-headers t nil t))
5148 (set-alist 'mime-edit-message-inserter-alist
5149 'message-mode (function message-mime-insert-article))
5151 ;;; Miscellaneous functions
5153 ;; stolen (and renamed) from nnheader.el
5154 (defun message-replace-chars-in-string (string from to)
5155 "Replace characters in STRING from FROM to TO."
5156 (let ((string (substring string 0)) ;Copy string.
5157 (len (length string))
5159 ;; Replace all occurrences of FROM with TO.
5161 (when (= (aref string idx) from)
5162 (aset string idx to))
5163 (setq idx (1+ idx)))
5170 (defvar message-inhibit-body-encoding t)
5172 (defun message-encode-message-body ()
5173 (unless message-inhibit-body-encoding
5174 (let ((mail-parse-charset (or mail-parse-charset
5175 message-default-charset
5176 message-posting-charset))
5177 (case-fold-search t)
5178 lines content-type-p)
5181 (narrow-to-region (point) (point-max))
5182 (let ((new (mml-generate-mime)))
5184 (delete-region (point-min) (point-max))
5186 (goto-char (point-min))
5187 (if (eq (aref new 0) ?\n)
5189 (search-forward "\n\n")
5190 (setq lines (buffer-substring (point-min) (1- (point))))
5191 (delete-region (point-min) (point))))))
5193 (message-narrow-to-headers-or-head)
5194 (message-remove-header "Mime-Version")
5195 (goto-char (point-max))
5196 (insert "MIME-Version: 1.0\n")
5199 (setq content-type-p
5200 (re-search-backward "^Content-Type:" nil t)))
5202 (message-narrow-to-headers-or-head)
5203 (message-remove-first-header "Content-Type")
5204 (message-remove-first-header "Content-Transfer-Encoding"))
5205 ;; We always make sure that the message has a Content-Type header.
5206 ;; This is because some broken MTAs and MUAs get awfully confused
5207 ;; when confronted with a message with a MIME-Version header and
5208 ;; without a Content-Type header. For instance, Solaris'
5210 (unless content-type-p
5211 (goto-char (point-min))
5212 (re-search-forward "^MIME-Version:")
5214 (insert "Content-Type: text/plain; charset=us-ascii\n")))))
5216 (defun message-read-from-minibuffer (prompt)
5217 "Read from the minibuffer while providing abbrev expansion."
5218 (if (fboundp 'mail-abbrevs-setup)
5219 (let ((mail-abbrev-mode-regexp "")
5220 (minibuffer-setup-hook 'mail-abbrevs-setup))
5221 (read-from-minibuffer prompt)))
5222 (let ((minibuffer-setup-hook 'mail-abbrev-minibuffer-setup-hook))
5223 (read-string prompt)))
5225 (defvar message-save-buffer " *encoding")
5226 (defun message-save-drafts ()
5228 (if (not (get-buffer message-save-buffer))
5229 (get-buffer-create message-save-buffer))
5230 (let ((filename buffer-file-name)
5231 (buffer (current-buffer))
5232 (reply-headers message-reply-headers))
5233 (set-buffer message-save-buffer)
5235 (insert-buffer buffer)
5236 (setq message-reply-headers reply-headers)
5237 (message-generate-headers '((optional . In-Reply-To)))
5238 (mime-edit-translate-buffer)
5239 (write-region (point-min) (point-max) filename)
5241 (set-buffer-modified-p nil)))
5245 (run-hooks 'message-load-hook)
5247 ;;; message.el ends here