1 ;;; message.el --- composing mail and news messages
2 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000
3 ;; Free Software Foundation, Inc.
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
6 ;; MORIOKA Tomohiko <morioka@jaist.ac.jp>
7 ;; Shuhei KOBAYASHI <shuhei-k@jaist.ac.jp>
8 ;; Keiichi Suzuki <kei-suzu@mail.wbs.ne.jp>
9 ;; Tatsuya Ichikawa <t-ichi@po.shiojiri.ne.jp>
10 ;; Katsumi Yamaoka <yamaoka@jpl.org>
11 ;; Kiyokazu SUTO <suto@merry.xmath.ous.ac.jp>
12 ;; Keywords: mail, news, MIME
14 ;; This file is part of GNU Emacs.
16 ;; GNU Emacs is free software; you can redistribute it and/or modify
17 ;; it under the terms of the GNU General Public License as published by
18 ;; the Free Software Foundation; either version 2, or (at your option)
21 ;; GNU Emacs is distributed in the hope that it will be useful,
22 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
23 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 ;; GNU General Public License for more details.
26 ;; You should have received a copy of the GNU General Public License
27 ;; along with GNU Emacs; see the file COPYING. If not, write to the
28 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
29 ;; Boston, MA 02111-1307, USA.
33 ;; This mode provides mail-sending facilities from within Emacs. It
34 ;; consists mainly of large chunks of code from the sendmail.el,
35 ;; gnus-msg.el and rnewspost.el files.
42 (defvar gnus-list-identifiers)) ; gnus-sum is required where necessary
46 ;; This is apparently necessary even though things are autoloaded:
47 (if (featurep 'xemacs)
48 (require 'mail-abbrevs))
50 (eval-when-compile (require 'static))
52 ;; Avoid byte-compile warnings.
57 (defgroup message '((user-mail-address custom-variable)
58 (user-full-name custom-variable))
59 "Mail and news message composing."
60 :link '(custom-manual "(message)Top")
64 (put 'user-mail-address 'custom-type 'string)
65 (put 'user-full-name 'custom-type 'string)
67 (defgroup message-various nil
68 "Various Message Variables"
69 :link '(custom-manual "(message)Various Message Variables")
72 (defgroup message-buffers nil
74 :link '(custom-manual "(message)Message Buffers")
77 (defgroup message-sending nil
79 :link '(custom-manual "(message)Sending Variables")
82 (defgroup message-interface nil
84 :link '(custom-manual "(message)Interface")
87 (defgroup message-forwarding nil
89 :link '(custom-manual "(message)Forwarding")
90 :group 'message-interface)
92 (defgroup message-insertion nil
94 :link '(custom-manual "(message)Insertion")
97 (defgroup message-headers nil
99 :link '(custom-manual "(message)Message Headers")
102 (defgroup message-news nil
103 "Composing News Messages"
106 (defgroup message-mail nil
107 "Composing Mail Messages"
110 (defgroup message-faces nil
111 "Faces used for message composing."
115 (defgroup message-frames nil
119 (defcustom message-directory "~/Mail/"
120 "*Directory from which all other mail file variables are derived."
121 :group 'message-various
124 (defcustom message-max-buffers 10
125 "*How many buffers to keep before starting to kill them off."
126 :group 'message-buffers
129 (defcustom message-send-rename-function nil
130 "Function called to rename the buffer after sending it."
131 :group 'message-buffers
134 (defcustom message-fcc-handler-function 'message-output
135 "*A function called to save outgoing articles.
136 This function will be called with the name of the file to store the
137 article in. The default function is `message-output' which saves in Unix
139 :type '(radio (function-item message-output)
140 (function :tag "Other"))
141 :group 'message-sending)
143 (defcustom message-encode-function 'message-maybe-encode
144 "*A function called to encode messages."
145 :group 'message-sending
148 (defcustom message-8bit-encoding-list '(8bit binary)
149 "*8bit encoding type in Content-Transfer-Encoding field."
150 :group 'message-sending
151 :type '(repeat (symbol :tag "Type")))
153 (defcustom message-courtesy-message
154 "The following message is a courtesy copy of an article\nthat has been posted to %s as well.\n\n"
155 "*This is inserted at the start of a mailed copy of a posted message.
156 If the string contains the format spec \"%s\", the Newsgroups
157 the article has been posted to will be inserted there.
158 If this variable is nil, no such courtesy message will be added."
159 :group 'message-sending
162 (defcustom message-ignored-bounced-headers "^\\(Received\\|Return-Path\\):"
163 "*Regexp that matches headers to be removed in resent bounced mail."
164 :group 'message-interface
167 (defcustom message-bounce-setup-function 'message-bounce-setup-for-mime-edit
168 "Function to setup a re-sending bounced message."
169 :group 'message-sending
173 (defcustom message-from-style 'default
174 "*Specifies how \"From\" headers look.
176 If `nil', they contain just the return address like:
178 If `parens', they look like:
179 king@grassland.com (Elvis Parsley)
180 If `angles', they look like:
181 Elvis Parsley <king@grassland.com>
183 Otherwise, most addresses look like `angles', but they look like
184 `parens' if `angles' would need quoting and `parens' would not."
185 :type '(choice (const :tag "simple" nil)
189 :group 'message-headers)
191 (defcustom message-syntax-checks nil
192 ;; Guess this one shouldn't be easy to customize...
193 "*Controls what syntax checks should not be performed on outgoing posts.
194 To disable checking of long signatures, for instance, add
195 `(signature . disabled)' to this list.
197 Don't touch this variable unless you really know what you're doing.
199 Checks include subject-cmsg multiple-headers sendsys message-id from
200 long-lines control-chars size new-text quoting-style
201 redirected-followup signature approved sender empty empty-headers
202 message-id from subject shorten-followup-to existing-newsgroups
203 buffer-file-name unchanged newsgroups."
205 :type '(repeat sexp))
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:\\|^NNTP-Posting-Date:\\|^X-Trace:\\|^X-Complaints-To:"
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-included-forward-headers
382 "^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:"
383 "*Regexp matching headers to be included in forwarded messages."
384 :group 'message-forwarding
387 (defcustom message-make-forward-subject-function
388 'message-forward-subject-author-subject
389 "*A list of functions that are called to generate a subject header for forwarded messages.
390 The subject generated by the previous function is passed into each
393 The provided functions are:
395 * message-forward-subject-author-subject (Source of article (author or
396 newsgroup)), in brackets followed by the subject
397 * message-forward-subject-fwd (Subject of article with 'Fwd:' prepended
399 :group 'message-forwarding
400 :type '(radio (function-item message-forward-subject-author-subject)
401 (function-item message-forward-subject-fwd)))
403 (defcustom message-forward-as-mime t
404 "*If non-nil, forward messages as an inline/rfc822 MIME section. Otherwise, directly inline the old message in the forwarded message."
405 :group 'message-forwarding
408 (defcustom message-forward-show-mml t
409 "*If non-nil, forward messages are shown as mml. Otherwise, forward messages are unchanged."
410 :group 'message-forwarding
413 (defcustom message-forward-before-signature t
414 "*If non-nil, put forwarded message before signature, else after."
415 :group 'message-forwarding
418 (defcustom message-wash-forwarded-subjects nil
419 "*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."
420 :group 'message-forwarding
423 (defcustom message-ignored-resent-headers "^Return-receipt\\|^X-Gnus\\|^Gnus-Warning:"
424 "*All headers that match this regexp will be deleted when resending a message."
425 :group 'message-interface
428 (defcustom message-forward-ignored-headers "^Content-Transfer-Encoding:\\|^X-Gnus"
429 "*All headers that match this regexp will be deleted when forwarding a message."
430 :group 'message-forwarding
431 :type '(choice (const :tag "None" nil)
434 (defcustom message-ignored-cited-headers "."
435 "*Delete these headers from the messages you yank."
436 :group 'message-insertion
439 (defcustom message-cancel-message "I am canceling my own article.\n"
440 "Message to be inserted in the cancel message."
441 :group 'message-interface
444 ;; Useful to set in site-init.el
446 (defcustom message-send-mail-function 'message-send-mail-with-sendmail
447 "Function to call to send the current buffer as mail.
448 The headers should be delimited by a line whose contents match the
449 variable `mail-header-separator'.
451 Valid values include `message-send-mail-with-sendmail' (the default),
452 `message-send-mail-with-mh', `message-send-mail-with-qmail' and
453 `message-send-mail-with-smtp'."
454 :type '(radio (function-item message-send-mail-with-sendmail)
455 (function-item message-send-mail-with-mh)
456 (function-item message-send-mail-with-qmail)
457 (function-item message-send-mail-with-smtp)
458 (function :tag "Other"))
459 :group 'message-sending
460 :group 'message-mail)
462 ;; 1997-09-29 by MORIOKA Tomohiko
463 (defcustom message-send-news-function 'message-send-news-with-gnus
464 "Function to call to send the current buffer as news.
465 The headers should be delimited by a line whose contents match the
466 variable `mail-header-separator'."
467 :group 'message-sending
471 (defcustom message-reply-to-function nil
472 "Function that should return a list of headers.
473 This function should pick out addresses from the To, Cc, and From headers
474 and respond with new To and Cc headers."
475 :group 'message-interface
478 (defcustom message-wide-reply-to-function nil
479 "Function that should return a list of headers.
480 This function should pick out addresses from the To, Cc, and From headers
481 and respond with new To and Cc headers."
482 :group 'message-interface
485 (defcustom message-followup-to-function nil
486 "Function that should return a list of headers.
487 This function should pick out addresses from the To, Cc, and From headers
488 and respond with new To and Cc headers."
489 :group 'message-interface
492 (defcustom message-use-followup-to 'ask
493 "*Specifies what to do with Followup-To header.
494 If nil, always ignore the header. If it is t, use its value, but
495 query before using the \"poster\" value. If it is the symbol `ask',
496 always query the user whether to use the value. If it is the symbol
497 `use', always use the value."
498 :group 'message-interface
499 :type '(choice (const :tag "ignore" nil)
500 (const :tag "maybe" t)
501 (const :tag "always" use)
502 (const :tag "ask" ask)))
504 (defcustom message-use-mail-copies-to 'ask
505 "*Specifies what to do with Mail-Copies-To header.
506 If nil, always ignore the header. If it is t, use its value, but
507 query before using the value other than \"always\" or \"never\".
508 If it is the symbol `ask', always query the user whether to use
509 the value. If it is the symbol `use', always use the value."
510 :group 'message-interface
511 :type '(choice (const :tag "ignore" nil)
512 (const :tag "maybe" t)
513 (const :tag "always" use)
514 (const :tag "ask" ask)))
516 (defcustom message-use-mail-followup-to 'ask
517 "*Specifies what to do with Mail-Followup-To header.
518 If nil, always ignore the header. If it is the symbol `ask', always
519 query the user whether to use the value. If it is t or the symbol
520 `use', always use the value."
521 :group 'message-interface
522 :type '(choice (const :tag "ignore" nil)
523 (const :tag "maybe" t)
524 (const :tag "always" use)
525 (const :tag "ask" ask)))
527 ;;; XXX: 'ask and 'use are not implemented yet.
528 (defcustom message-use-mail-reply-to 'ask
529 "*Specifies what to do with Mail-Reply-To/Reply-To header.
530 If nil, always ignore the header. If it is t or the symbol `use', use
531 its value. If it is the symbol `ask', always query the user whether to
532 use the value. Note that if \"Reply-To\" is marked as \"broken\", its value
534 :group 'message-interface
535 :type '(choice (const :tag "ignore" nil)
536 (const :tag "maybe" t)
537 (const :tag "always" use)
538 (const :tag "ask" ask)))
540 (defcustom message-sendmail-f-is-evil nil
541 "*Non-nil means that \"-f username\" should not be added to the sendmail command line.
542 Doing so would be even more evil than leaving it out."
543 :group 'message-sending
546 ;; qmail-related stuff
547 (defcustom message-qmail-inject-program "/var/qmail/bin/qmail-inject"
548 "Location of the qmail-inject program."
549 :group 'message-sending
552 (defcustom message-qmail-inject-args nil
553 "Arguments passed to qmail-inject programs.
554 This should be a list of strings, one string for each argument.
556 For e.g., if you wish to set the envelope sender address so that bounces
557 go to the right place or to deal with listserv's usage of that address, you
558 might set this variable to '(\"-f\" \"you@some.where\")."
559 :group 'message-sending
560 :type '(repeat string))
562 (defvar message-cater-to-broken-inn t
563 "Non-nil means Gnus should not fold the `References' header.
564 Folding `References' makes ancient versions of INN create incorrect
567 (defvar gnus-post-method)
568 (defvar gnus-select-method)
569 (defcustom message-post-method
570 (cond ((and (boundp 'gnus-post-method)
571 (listp gnus-post-method)
574 ((boundp 'gnus-select-method)
577 "*Method used to post news.
578 Note that when posting from inside Gnus, for instance, this
579 variable isn't used."
581 :group 'message-sending
582 ;; This should be the `gnus-select-method' widget, but that might
583 ;; create a dependence to `gnus.el'.
586 (defcustom message-generate-headers-first nil
587 "*If non-nil, generate all possible headers before composing."
588 :group 'message-headers
591 (defcustom message-setup-hook '(turn-on-mime-edit)
592 "Normal hook, run each time a new outgoing message is initialized.
593 The function `message-setup' runs this hook."
594 :group 'message-various
597 (defcustom message-cancel-hook nil
598 "Hook run when cancelling articles."
599 :group 'message-various
602 (defcustom message-signature-setup-hook nil
603 "Normal hook, run each time a new outgoing message is initialized.
604 It is run after the headers have been inserted and before
605 the signature is inserted."
606 :group 'message-various
609 (defcustom message-bounce-setup-hook nil
610 "Normal hook, run each time a re-sending bounced message is initialized.
611 The function `message-bounce' runs this hook."
612 :group 'message-various
615 (defcustom message-supersede-setup-hook nil
616 "Normal hook, run each time a supersede message is initialized.
617 The function `message-supersede' runs this hook."
618 :group 'message-various
621 (defcustom message-mode-hook nil
622 "Hook run in message mode buffers."
623 :group 'message-various
626 (defcustom message-header-hook '((lambda () (eword-encode-header t)))
627 "Hook run in a message mode buffer narrowed to the headers."
628 :group 'message-various
631 (defcustom message-header-setup-hook nil
632 "Hook called narrowed to the headers when setting up a message buffer."
633 :group 'message-various
637 (defcustom message-citation-line-function 'message-insert-citation-line
638 "*Function called to insert the \"Whomever writes:\" line."
640 :group 'message-insertion)
643 (defcustom message-yank-prefix "> "
644 "*Prefix inserted on the lines of yanked messages."
646 :group 'message-insertion)
648 (defcustom message-yank-add-new-references t
649 "Non-nil means new IDs will be added to \"References\" field when an
650 article is yanked by the command `message-yank-original' interactively.
651 If it is a symbol `message-id-only', only an ID from \"Message-ID\" field
652 is used, otherwise IDs extracted from \"References\", \"In-Reply-To\" and
653 \"Message-ID\" fields are used."
654 :type '(radio (const :tag "Do not add anything" nil)
655 (const :tag "From Message-Id, References and In-Reply-To fields" t)
656 (const :tag "From only Message-Id field." message-id-only))
657 :group 'message-insertion)
659 (defcustom message-list-references-add-position nil
660 "Integer value means position for adding to \"References\" field when
661 an article is yanked by the command `message-yank-original' interactively."
662 :type '(radio (const :tag "Add to last" nil)
663 (integer :tag "Position from last ID"))
664 :group 'message-insertion)
666 (defcustom message-indentation-spaces 3
667 "*Number of spaces to insert at the beginning of each cited line.
668 Used by `message-yank-original' via `message-yank-cite'."
669 :group 'message-insertion
673 (defcustom message-cite-function 'message-cite-original
674 "*Function for citing an original message.
675 Predefined functions include `message-cite-original' and
676 `message-cite-original-without-signature'.
677 Note that `message-cite-original' uses `mail-citation-hook' if that is non-nil."
678 :type '(radio (function-item message-cite-original)
679 (function-item message-cite-original-without-signature)
680 (function-item mu-cite-original)
681 (function-item sc-cite-original)
682 (function :tag "Other"))
683 :group 'message-insertion)
686 (defcustom message-indent-citation-function 'message-indent-citation
687 "*Function for modifying a citation just inserted in the mail buffer.
688 This can also be a list of functions. Each function can find the
689 citation between (point) and (mark t). And each function should leave
690 point and mark around the citation text as modified."
692 :group 'message-insertion)
694 (defvar message-abbrevs-loaded nil)
697 (defcustom message-signature t
698 "*String to be inserted at the end of the message buffer.
699 If t, the `message-signature-file' file will be inserted instead.
700 If a function, the result from the function will be used instead.
701 If a form, the result from the form will be used instead."
703 :group 'message-insertion)
706 (defcustom message-signature-file "~/.signature"
707 "*File containing the text inserted at end of message buffer."
709 :group 'message-insertion)
711 (defcustom message-distribution-function nil
712 "*Function called to return a Distribution header."
714 :group 'message-headers
717 (defcustom message-expires 14
718 "Number of days before your article expires."
720 :group 'message-headers
721 :link '(custom-manual "(message)News Headers")
724 (defcustom message-user-path nil
725 "If nil, use the NNTP server name in the Path header.
726 If stringp, use this; if non-nil, use no host name (user name only)."
728 :group 'message-headers
729 :link '(custom-manual "(message)News Headers")
730 :type '(choice (const :tag "nntp" nil)
732 (sexp :tag "none" :format "%t" t)))
734 (defvar message-reply-buffer nil)
735 (defvar message-reply-headers nil)
736 (defvar message-sent-message-via nil)
737 (defvar message-checksum nil)
738 (defvar message-send-actions nil
739 "A list of actions to be performed upon successful sending of a message.")
740 (defvar message-exit-actions nil
741 "A list of actions to be performed upon exiting after sending a message.")
742 (defvar message-kill-actions nil
743 "A list of actions to be performed before killing a message buffer.")
744 (defvar message-postpone-actions nil
745 "A list of actions to be performed after postponing a message.")
746 (defvar message-original-frame nil)
747 (defvar message-parameter-alist nil)
748 (defvar message-startup-parameter-alist nil)
750 (define-widget 'message-header-lines 'text
751 "All header lines must be LFD terminated."
754 :error "All header lines must be newline terminated")
756 (defcustom message-default-headers ""
757 "*A string containing header lines to be inserted in outgoing messages.
758 It is inserted before you edit the message, so you can edit or delete
760 :group 'message-headers
761 :type 'message-header-lines)
763 (defcustom message-default-mail-headers ""
764 "*A string of header lines to be inserted in outgoing mails."
765 :group 'message-headers
767 :type 'message-header-lines)
769 (defcustom message-default-news-headers ""
770 "*A string of header lines to be inserted in outgoing news articles."
771 :group 'message-headers
773 :type 'message-header-lines)
775 ;; Note: could use /usr/ucb/mail instead of sendmail;
776 ;; options -t, and -v if not interactive.
777 (defcustom message-mailer-swallows-blank-line
778 (if (and (string-match "sparc-sun-sunos\\(\\'\\|[^5]\\)"
779 system-configuration)
780 (file-readable-p "/etc/sendmail.cf")
781 (let ((buffer (get-buffer-create " *temp*")))
785 (insert-file-contents "/etc/sendmail.cf")
786 (goto-char (point-min))
787 (let ((case-fold-search nil))
788 (re-search-forward "^OR\\>" nil t)))
789 (kill-buffer buffer))))
790 ;; According to RFC822, "The field-name must be composed of printable
791 ;; ASCII characters (i. e., characters that have decimal values between
792 ;; 33 and 126, except colon)", i. e., any chars except ctl chars,
794 '(looking-at "[ \t]\\|[][!\"#$%&'()*+,-./0-9;<=>?@A-Z\\\\^_`a-z{|}~]+:"))
795 "*Set this non-nil if the system's mailer runs the header and body together.
796 \(This problem exists on Sunos 4 when sendmail is run in remote mode.)
797 The value should be an expression to test whether the problem will
799 :group 'message-sending
802 ;;; XXX: This symbol is overloaded! See below.
803 (defvar message-user-agent nil
804 "String of the form of PRODUCT/VERSION. Used for User-Agent header field.")
806 (static-when (boundp 'MULE)
807 (require 'reporter));; `define-mail-user-agent' is here.
810 (define-mail-user-agent 'message-user-agent
811 'message-mail 'message-send-and-exit
812 'message-kill-buffer 'message-send-hook)
814 (defvar message-mh-deletable-headers '(Message-ID Date Lines Sender)
815 "If non-nil, delete the deletable headers before feeding to mh.")
817 (defvar message-send-method-alist
818 '((news message-news-p message-send-via-news)
819 (mail message-mail-p message-send-via-mail))
820 "Alist of ways to send outgoing messages.
821 Each element has the form
823 \(TYPE PREDICATE FUNCTION)
825 where TYPE is a symbol that names the method; PREDICATE is a function
826 called without any parameters to determine whether the message is
827 a message of type TYPE; and FUNCTION is a function to be called if
828 PREDICATE returns non-nil. FUNCTION is called with one parameter --
831 (defvar message-mail-alias-type 'abbrev
832 "*What alias expansion type to use in Message buffers.
833 The default is `abbrev', which uses mailabbrev. nil switches
836 (defcustom message-auto-save-directory
837 (nnheader-concat message-directory "drafts/")
838 "*Directory where Message auto-saves buffers if Gnus isn't running.
839 If nil, Message won't auto-save."
840 :group 'message-buffers
843 (defcustom message-buffer-naming-style 'unique
844 "*The way new message buffers are named.
845 Valid valued are `unique' and `unsent'."
846 :group 'message-buffers
847 :type '(choice (const :tag "unique" unique)
848 (const :tag "unsent" unsent)))
850 (defcustom message-default-charset
851 (and (featurep 'xemacs) (not (featurep 'mule)) 'iso-8859-1)
852 "Default charset used in non-MULE XEmacsen."
856 (defcustom message-dont-reply-to-names
857 (and (boundp 'rmail-dont-reply-to-names) rmail-dont-reply-to-names)
858 "*A regexp specifying names to prune when doing wide replies.
859 A value of nil means exclude your own name only."
861 :type '(choice (const :tag "Yourself" nil)
864 ;;; Internal variables.
865 ;;; Well, not really internal.
867 (defvar message-mode-syntax-table
868 (let ((table (copy-syntax-table text-mode-syntax-table)))
869 (modify-syntax-entry ?% ". " table)
870 (modify-syntax-entry ?> ". " table)
871 (modify-syntax-entry ?< ". " table)
873 "Syntax table used while in Message mode.")
875 (defvar message-mode-abbrev-table text-mode-abbrev-table
876 "Abbrev table used in Message mode buffers.
877 Defaults to `text-mode-abbrev-table'.")
878 (defgroup message-headers nil
880 :link '(custom-manual "(message)Variables")
883 (defface message-header-to-face
886 (:foreground "green2" :bold t))
889 (:foreground "MidnightBlue" :bold t))
891 (:bold t :italic t)))
892 "Face used for displaying From headers."
893 :group 'message-faces)
895 (defface message-header-cc-face
898 (:foreground "green4" :bold t))
901 (:foreground "MidnightBlue"))
904 "Face used for displaying Cc headers."
905 :group 'message-faces)
907 (defface message-header-subject-face
910 (:foreground "green3"))
913 (:foreground "navy blue" :bold t))
916 "Face used for displaying subject headers."
917 :group 'message-faces)
919 (defface message-header-newsgroups-face
922 (:foreground "yellow" :bold t :italic t))
925 (:foreground "blue4" :bold t :italic t))
927 (:bold t :italic t)))
928 "Face used for displaying newsgroups headers."
929 :group 'message-faces)
931 (defface message-header-other-face
934 (:foreground "#b00000"))
937 (:foreground "steel blue"))
939 (:bold t :italic t)))
940 "Face used for displaying newsgroups headers."
941 :group 'message-faces)
943 (defface message-header-name-face
946 (:foreground "DarkGreen"))
949 (:foreground "cornflower blue"))
952 "Face used for displaying header names."
953 :group 'message-faces)
955 (defface message-header-xheader-face
958 (:foreground "blue"))
961 (:foreground "blue"))
964 "Face used for displaying X-Header headers."
965 :group 'message-faces)
967 (defface message-separator-face
970 (:foreground "blue3"))
973 (:foreground "brown"))
976 "Face used for displaying the separator."
977 :group 'message-faces)
979 (defface message-cited-text-face
988 "Face used for displaying cited text names."
989 :group 'message-faces)
991 (defface message-mml-face
994 (:foreground "ForestGreen"))
997 (:foreground "ForestGreen"))
1000 "Face used for displaying MML."
1001 :group 'message-faces)
1003 (defvar message-font-lock-fence-open-regexp "[+|]"
1004 "*Regexp that matches fence open string.")
1006 (defvar message-font-lock-fence-close-regexp "|"
1007 "*Regexp that matches fence close string.")
1009 (defvar message-font-lock-fence-open-position nil
1010 "*Cons of SYMBOL of a function or a variable and a number of OFFSET that
1011 indicate the fence open position. If it is non-nil,
1012 `message-font-lock-fence-open-regexp' is not used for searching for the
1013 fence open position. If SYMBOL is a function, it is called with one argument
1014 last cursor position and should return the fence open position as a number
1015 or a marker. If SYMBOL is a variable symbol, the value is examined with
1016 `symbol-value'. OFFSET is added to the position to compensate the value.
1017 For example, the following combinations of variable symbol and offset value
1020 Egg v3: '(egg:*region-start* . -1)
1021 Canna: '(canna:*region-start* . 0)
1024 (defvar message-font-lock-fence-close-position nil
1025 "*Cons of SYMBOL of a function or a variable and a number of OFFSET that
1026 indicate the fence close position. If it is non-nil,
1027 `message-font-lock-fence-close-regexp' is not used for searching for the
1028 fence close position. If SYMBOL is a function, it is called with one argument
1029 last cursor position and should return the fence close position as a number
1030 or a marker. If SYMBOL is a variable symbol, the value is examined with
1031 `symbol-value'. OFFSET is added to the position to compensate the value.
1032 For example, the following combinations of variable symbol and offset value
1035 Egg v3: '(egg:*region-end* . 0)
1036 Canna: '(canna:*region-end* . 0)
1039 (defvar message-font-lock-cited-text-regexp
1040 "^[\t ]*\\([^\000- :>|}\177]*\\)[:>|}].*"
1041 "*Regexp that matches cited text. It should have a grouping for the
1042 citation prefix which is ended at the beginning of citation mark string.")
1044 (defvar message-font-lock-citation-name-max-column 10
1045 "*Maximun number of column for citation name for fontifying.")
1047 (defvar message-font-lock-last-position nil
1048 "Internal buffer local variable to save the last cursor position
1049 before fontifying.")
1051 (eval-after-load "font-lock"
1052 '(defadvice font-lock-after-change-function
1053 (before message-font-lock-save-last-position activate)
1054 "Save last cursor position before fontifying."
1055 (if (eq 'message-mode major-mode)
1056 (setq message-font-lock-last-position (point)))))
1058 (defun message-font-lock-cited-text-matcher (limit)
1059 "Search for a cited text containing `message-font-lock-cited-text-regexp'
1060 forward. Argument LIMIT bounds the search. If a cited text is found, it
1061 returns t and sets match data 1 and 2, otherwise it returns nil. Normally,
1062 match data 2 has zero length, but if the FENCE (for input method) is detected
1063 in matched text, result is divided into match data 1 and 2 across the FENCE.
1064 See also the documentations for the following variables:
1065 `message-font-lock-fence-open-regexp'
1066 `message-font-lock-fence-close-regexp'
1067 `message-font-lock-fence-open-position'
1068 `message-font-lock-fence-close-position'
1071 (when (re-search-forward message-font-lock-cited-text-regexp limit t)
1072 (let* ((start0 (match-beginning 0))
1073 (end0 (match-end 0))
1074 (cite-mark (match-end 1))
1077 (goto-char cite-mark)
1078 (<= (current-column)
1079 message-font-lock-citation-name-max-column)))
1083 message-font-lock-last-position
1084 (>= message-font-lock-last-position start0)
1085 (<= message-font-lock-last-position end0)
1087 (message-font-lock-fence-open-position
1088 (let* ((symbol (car message-font-lock-fence-open-position))
1090 (cond ((functionp symbol)
1091 (funcall symbol message-font-lock-last-position))
1092 ((and (symbolp symbol)
1094 (symbol-value symbol)))))
1095 (when (markerp open)
1096 (setq open (marker-position open)))
1100 (cdr message-font-lock-fence-open-position)))
1101 (>= message-font-lock-last-position open)
1103 (or (not message-font-lock-fence-open-regexp)
1104 (looking-at message-font-lock-fence-open-regexp))
1106 (message-font-lock-fence-open-regexp
1107 (goto-char message-font-lock-last-position)
1108 (when (re-search-backward
1109 message-font-lock-fence-open-regexp start0 t)
1110 (setq end1 (match-beginning 0)))))
1111 (setq should-fontify
1112 (and message-font-lock-fence-open-position
1113 (not (eq cite-mark end1))))
1115 (message-font-lock-fence-close-position
1116 (let* ((symbol (car message-font-lock-fence-close-position))
1118 (cond ((functionp symbol)
1119 (funcall symbol message-font-lock-last-position))
1120 ((and (symbolp symbol)
1122 (symbol-value symbol)))))
1123 (when (markerp close)
1124 (setq close (marker-position close)))
1125 (and (numberp close)
1128 (cdr message-font-lock-fence-close-position)))
1129 (<= message-font-lock-last-position close)
1130 (setq start2 close))))
1131 (message-font-lock-fence-close-regexp
1132 (goto-char message-font-lock-last-position)
1133 (when (looking-at message-font-lock-fence-close-regexp)
1134 (setq start2 (match-end 0)))))
1135 (setq should-fontify
1136 (and (not (and (not message-font-lock-fence-open-position)
1137 (eq cite-mark end1)))
1138 (not (eq cite-mark start2)))))
1140 (when should-fontify
1142 (store-match-data (list start0 end0 start0 end1 start2 end0))
1143 (store-match-data (list start0 end0 start0 end0 end0 end0)))
1145 (setq message-font-lock-last-position nil)))
1147 (defvar message-font-lock-keywords-1
1148 (let ((content "[ \t]*\\(.+\\(\n[ \t].*\\)*\\)"))
1149 `((,(concat "^\\([Tt]o:\\)" content)
1150 (1 'message-header-name-face)
1151 (2 'message-header-to-face nil t))
1152 (,(concat "^\\([GBF]?[Cc][Cc]:\\|[Rr]eply-[Tt]o:\\|"
1153 "[Mm]ail-[Cc]opies-[Tt]o:\\|"
1154 "[Mm]ail-[Rr]eply-[Tt]o:\\|"
1155 "[Mm]ail-[Ff]ollowup-[Tt]o:\\)" content)
1156 (1 'message-header-name-face)
1157 (2 'message-header-cc-face nil t))
1158 (,(concat "^\\([Ss]ubject:\\)" content)
1159 (1 'message-header-name-face)
1160 (2 'message-header-subject-face nil t))
1161 (,(concat "^\\([Nn]ewsgroups:\\|Followup-[Tt]o:\\)" content)
1162 (1 'message-header-name-face)
1163 (2 'message-header-newsgroups-face nil t))
1164 (,(concat "^\\([A-Z][^: \n\t]+:\\)" content)
1165 (1 'message-header-name-face)
1166 (2 'message-header-other-face nil t))
1167 (,(concat "^\\(X-[A-Za-z0-9-]+\\|In-Reply-To\\):" content)
1168 (1 'message-header-name-face)
1169 (2 'message-header-name-face))
1170 ,@(if (and mail-header-separator
1171 (not (equal mail-header-separator "")))
1172 `((,(concat "^\\(" (regexp-quote mail-header-separator) "\\)$")
1173 1 'message-separator-face))
1176 (defvar message-font-lock-keywords-2
1177 (append message-font-lock-keywords-1
1178 '((message-font-lock-cited-text-matcher
1179 (1 'message-cited-text-face)
1180 (2 'message-cited-text-face))
1181 ("<#/?\\(multipart\\|part\\|external\\).*>"
1182 (0 'message-mml-face)))))
1184 (defvar message-font-lock-keywords message-font-lock-keywords-2
1185 "Additional expressions to highlight in Message mode.")
1187 ;; XEmacs does it like this. For Emacs, we have to set the
1188 ;; `font-lock-defaults' buffer-local variable.
1189 (put 'message-mode 'font-lock-defaults
1190 '((message-font-lock-keywords
1191 message-font-lock-keywords-1
1192 message-font-lock-keywords-2)
1194 (font-lock-mark-block-function . mark-paragraph)))
1196 (defvar message-face-alist
1197 '((bold . bold-region)
1198 (underline . underline-region)
1199 (default . (lambda (b e)
1201 (ununderline-region b e))))
1202 "Alist of mail and news faces for facemenu.
1203 The cdr of ech entry is a function for applying the face to a region.")
1205 (defcustom message-send-hook nil
1206 "Hook run before sending messages."
1207 :group 'message-various
1208 :options '(ispell-message)
1211 (defcustom message-send-mail-hook nil
1212 "Hook run before sending mail messages."
1213 :group 'message-various
1216 (defcustom message-send-news-hook nil
1217 "Hook run before sending news messages."
1218 :group 'message-various
1221 (defcustom message-sent-hook nil
1222 "Hook run after sending messages."
1223 :group 'message-various
1226 (defcustom message-use-multi-frames nil
1227 "Make new frame when sending messages."
1228 :group 'message-frames
1231 (defcustom message-delete-frame-on-exit nil
1232 "Delete frame after sending messages."
1233 :group 'message-frames
1234 :type '(choice (const :tag "off" nil)
1235 (const :tag "always" t)
1236 (const :tag "ask" ask)))
1238 (defvar message-draft-coding-system
1240 ((boundp 'MULE) '*junet*)
1241 ((not (fboundp 'find-coding-system)) nil)
1242 ((find-coding-system 'emacs-mule)
1243 (if (memq system-type '(windows-nt ms-dos ms-windows))
1244 'emacs-mule-dos 'emacs-mule))
1245 ((find-coding-system 'escape-quoted) 'escape-quoted)
1246 ((find-coding-system 'no-conversion) 'no-conversion)
1248 "Coding system to compose mail.")
1250 (defcustom message-send-mail-partially-limit 1000000
1251 "The limitation of messages sent as message/partial.
1252 The lower bound of message size in characters, beyond which the message
1253 should be sent in several parts. If it is nil, the size is unlimited."
1254 :group 'message-buffers
1255 :type '(choice (const :tag "unlimited" nil)
1258 (defcustom message-alternative-emails nil
1259 "A regexp to match the alternative email addresses.
1260 The first matched address (not primary one) is used in the From field."
1261 :group 'message-headers
1262 :type '(choice (const :tag "Always use primary" nil)
1265 ;;; Internal variables.
1267 (defvar message-sending-message "Sending...")
1268 (defvar message-buffer-list nil)
1269 (defvar message-this-is-news nil)
1270 (defvar message-this-is-mail nil)
1271 (defvar message-draft-article nil)
1272 (defvar message-mime-part nil)
1273 (defvar message-posting-charset nil)
1275 ;; Byte-compiler warning
1276 (defvar gnus-active-hashtb)
1277 (defvar gnus-read-active-file)
1279 ;;; Regexp matching the delimiter of messages in UNIX mail format
1280 ;;; (UNIX From lines), minus the initial ^. It should be a copy
1281 ;;; of rmail.el's rmail-unix-mail-delimiter.
1282 (defvar message-unix-mail-delimiter
1283 (let ((time-zone-regexp
1284 (concat "\\([A-Z]?[A-Z]?[A-Z][A-Z]\\( DST\\)?"
1285 "\\|[-+]?[0-9][0-9][0-9][0-9]"
1291 ;; Many things can happen to an RFC 822 mailbox before it is put into
1292 ;; a `From' line. The leading phrase can be stripped, e.g.
1293 ;; `Joe <@w.x:joe@y.z>' -> `<@w.x:joe@y.z>'. The <> can be stripped, e.g.
1294 ;; `<@x.y:joe@y.z>' -> `@x.y:joe@y.z'. Everything starting with a CRLF
1295 ;; can be removed, e.g.
1296 ;; From: joe@y.z (Joe K
1298 ;; can yield `From joe@y.z (Joe K Fri Mar 22 08:11:15 1996', and
1301 ;; can yield `From Joe User Fri Mar 22 08:11:15 1996'.
1302 ;; The mailbox can be removed or be replaced by white space, e.g.
1303 ;; From: "Joe User"{space}{tab}
1305 ;; can yield `From {space}{tab} Fri Mar 22 08:11:15 1996',
1306 ;; where {space} and {tab} represent the Ascii space and tab characters.
1307 ;; We want to match the results of any of these manglings.
1308 ;; The following regexp rejects names whose first characters are
1309 ;; obviously bogus, but after that anything goes.
1310 "\\([^\0-\b\n-\r\^?].*\\)? "
1312 ;; The time the message was sent.
1313 "\\([^\0-\r \^?]+\\) +" ; day of the week
1314 "\\([^\0-\r \^?]+\\) +" ; month
1315 "\\([0-3]?[0-9]\\) +" ; day of month
1316 "\\([0-2][0-9]:[0-5][0-9]\\(:[0-6][0-9]\\)?\\) *" ; time of day
1318 ;; Perhaps a time zone, specified by an abbreviation, or by a
1323 " \\([0-9][0-9]+\\) *"
1325 ;; On some systems the time zone can appear after the year, too.
1329 "\\(remote from .*\\)?"
1332 "Regexp matching the delimiter of messages in UNIX mail format.")
1334 (defvar message-unsent-separator
1335 (concat "^ *---+ +Unsent message follows +---+ *$\\|"
1336 "^ *---+ +Returned message +---+ *$\\|"
1337 "^Start of returned message$\\|"
1338 "^ *---+ +Original message +---+ *$\\|"
1339 "^ *--+ +begin message +--+ *$\\|"
1340 "^ *---+ +Original message follows +---+ *$\\|"
1341 "^ *---+ +Undelivered message follows +---+ *$\\|"
1342 "^|? *---+ +Message text follows: +---+ *|?$")
1343 "A regexp that matches the separator before the text of a failed message.")
1345 (defvar message-header-format-alist
1347 (To . message-fill-address)
1348 (Cc . message-fill-address)
1359 (References . message-shorten-references)
1361 "Alist used for formatting headers.")
1364 (autoload 'message-setup-toolbar "messagexmas")
1365 (autoload 'mh-new-draft-name "mh-comp")
1366 (autoload 'mh-send-letter "mh-comp")
1367 (autoload 'gnus-point-at-eol "gnus-util")
1368 (autoload 'gnus-point-at-bol "gnus-util")
1369 (autoload 'gnus-output-to-rmail "gnus-util")
1370 (autoload 'gnus-output-to-mail "gnus-util")
1371 (autoload 'mail-abbrev-in-expansion-header-p "mailabbrev")
1372 (autoload 'nndraft-request-associate-buffer "nndraft")
1373 (autoload 'nndraft-request-expire-articles "nndraft")
1374 (autoload 'gnus-open-server "gnus-int")
1375 (autoload 'gnus-request-post "gnus-int")
1376 (autoload 'gnus-copy-article-buffer "gnus-msg")
1377 (autoload 'gnus-alive-p "gnus-util")
1378 (autoload 'gnus-group-name-charset "gnus-group")
1379 (autoload 'rmail-output "rmail")
1380 (autoload 'mu-cite-original "mu-cite"))
1385 ;;; Utility functions.
1387 (defun message-eval-parameter (parameter)
1389 (if (symbolp parameter)
1390 (if (functionp parameter)
1396 (defsubst message-get-parameter (key &optional alist)
1398 (setq alist message-parameter-alist))
1399 (cdr (assq key alist)))
1401 (defmacro message-get-parameter-with-eval (key &optional alist)
1402 `(message-eval-parameter (message-get-parameter ,key ,alist)))
1404 (defmacro message-y-or-n-p (question show &rest text)
1405 "Ask QUESTION, displaying the rest of the arguments in a temp. buffer if SHOW"
1406 `(message-talkative-question 'y-or-n-p ,question ,show ,@text))
1408 ;; Delete the current line (and the next N lines.);
1409 (defmacro message-delete-line (&optional n)
1410 `(delete-region (progn (beginning-of-line) (point))
1411 (progn (forward-line ,(or n 1)) (point))))
1413 (defun message-unquote-tokens (elems)
1414 "Remove double quotes (\") from strings in list."
1415 (mapcar (lambda (item)
1416 (while (string-match "^\\(.*\\)\"\\(.*\\)$" item)
1417 (setq item (concat (match-string 1 item)
1418 (match-string 2 item))))
1422 (defun message-tokenize-header (header &optional separator)
1423 "Split HEADER into a list of header elements.
1424 SEPARATOR is a string of characters to be used as separators. \",\"
1425 is used by default."
1428 (let ((regexp (format "[%s]+" (or separator ",")))
1433 (message-set-work-buffer)
1435 (goto-char (point-min))
1440 (cond ((and (> (point) beg)
1442 (and (looking-at regexp)
1445 (push (buffer-substring beg (point)) elems)
1446 (setq beg (match-end 0)))
1447 ((eq (char-after) ?\")
1448 (setq quoted (not quoted)))
1449 ((and (eq (char-after) ?\()
1452 ((and (eq (char-after) ?\))
1455 (nreverse elems)))))
1457 (defun message-mail-file-mbox-p (file)
1458 "Say whether FILE looks like a Unix mbox file."
1459 (when (and (file-exists-p file)
1460 (file-readable-p file)
1461 (file-regular-p file))
1463 (nnheader-insert-file-contents file)
1464 (goto-char (point-min))
1465 (looking-at message-unix-mail-delimiter))))
1467 (defun message-fetch-field (header &optional not-all)
1468 "The same as `mail-fetch-field', only remove all newlines."
1469 (let* ((inhibit-point-motion-hooks t)
1470 (case-fold-search t)
1471 (value (mail-fetch-field header nil (not not-all))))
1473 (while (string-match "\n[\t ]+" value)
1474 (setq value (replace-match " " t t value)))
1475 (set-text-properties 0 (length value) nil value)
1478 (defun message-narrow-to-field ()
1479 "Narrow the buffer to the header on the current line."
1485 (if (re-search-forward "^[^ \n\t]" nil t)
1490 (goto-char (point-min)))
1492 (defun message-add-header (&rest headers)
1493 "Add the HEADERS to the message header, skipping those already present."
1496 (unless (string-match "^\\([^:]+\\):[ \t]*[^ \t]" (car headers))
1497 (error "Invalid header `%s'" (car headers)))
1498 (setq hclean (match-string 1 (car headers)))
1500 (message-narrow-to-headers)
1501 (unless (re-search-forward (concat "^" (regexp-quote hclean) ":") nil t)
1502 (insert (car headers) ?\n))))
1503 (setq headers (cdr headers))))
1506 (defun message-fetch-reply-field (header)
1507 "Fetch FIELD from the message we're replying to."
1508 (let ((buffer (message-eval-parameter message-reply-buffer)))
1510 (buffer-name buffer))
1513 (message-fetch-field header)))))
1515 (defun message-set-work-buffer ()
1516 (if (get-buffer " *message work*")
1518 (set-buffer " *message work*")
1520 (set-buffer (get-buffer-create " *message work*"))
1521 (kill-all-local-variables)))
1523 (defun message-functionp (form)
1524 "Return non-nil if FORM is funcallable."
1525 (or (and (symbolp form) (fboundp form))
1526 (and (listp form) (eq (car form) 'lambda))
1527 (byte-code-function-p form)))
1529 (defun message-strip-list-identifiers (subject)
1530 "Remove list identifiers in `gnus-list-identifiers'."
1531 (require 'gnus-sum) ; for gnus-list-identifiers
1532 (let ((regexp (if (stringp gnus-list-identifiers)
1533 gnus-list-identifiers
1534 (mapconcat 'identity gnus-list-identifiers " *\\|"))))
1535 (if (string-match (concat "\\(\\(\\(Re: +\\)?\\(" regexp
1536 " *\\)\\)+\\(Re: +\\)?\\)") subject)
1537 (concat (substring subject 0 (match-beginning 1))
1538 (or (match-string 3 subject)
1539 (match-string 5 subject))
1544 (defun message-strip-subject-re (subject)
1545 "Remove \"Re:\" from subject lines."
1546 (if (string-match message-subject-re-regexp subject)
1547 (substring subject (match-end 0))
1550 (defun message-remove-header (header &optional is-regexp first reverse)
1551 "Remove HEADER in the narrowed buffer.
1552 If REGEXP, HEADER is a regular expression.
1553 If FIRST, only remove the first instance of the header.
1554 Return the number of headers removed."
1555 (goto-char (point-min))
1556 (let ((regexp (if is-regexp header (concat "^" (regexp-quote header) ":")))
1558 (case-fold-search t)
1560 (while (and (not (eobp))
1563 (not (looking-at regexp))
1564 (looking-at regexp))
1571 ;; There might be a continuation header, so we have to search
1572 ;; until we find a new non-continuation line.
1575 (if (re-search-forward "^[^ \t]" nil t)
1576 (goto-char (match-beginning 0))
1579 (if (re-search-forward "^[^ \t]" nil t)
1580 (goto-char (match-beginning 0))
1581 (goto-char (point-max)))))
1584 (defun message-remove-first-header (header)
1585 "Remove the first instance of HEADER if there is more than one."
1587 (regexp (concat "^" (regexp-quote header) ":")))
1589 (goto-char (point-min))
1590 (while (re-search-forward regexp nil t)
1593 (message-remove-header header nil t)
1596 (defun message-narrow-to-headers ()
1597 "Narrow the buffer to the head of the message."
1600 (goto-char (point-min))
1601 (if (re-search-forward
1602 (concat "^" (regexp-quote mail-header-separator) "\n") nil t)
1605 (goto-char (point-min)))
1607 (defun message-narrow-to-head ()
1608 "Narrow the buffer to the head of the message.
1609 Point is left at the beginning of the narrowed-to region."
1612 (goto-char (point-min))
1613 (if (search-forward "\n\n" nil 1)
1616 (goto-char (point-min)))
1618 (defun message-narrow-to-headers-or-head ()
1619 "Narrow the buffer to the head of the message."
1622 (goto-char (point-min))
1625 (concat "^" (regexp-quote mail-header-separator) "\n") nil t)
1626 (match-beginning 0))
1627 ((search-forward "\n\n" nil t)
1631 (goto-char (point-min)))
1633 (defun message-news-p ()
1634 "Say whether the current buffer contains a news message."
1635 (and (not message-this-is-mail)
1636 (or message-this-is-news
1639 (message-narrow-to-headers)
1640 (and (message-fetch-field "newsgroups")
1641 (not (message-fetch-field "posted-to"))))))))
1643 (defun message-mail-p ()
1644 "Say whether the current buffer contains a mail message."
1645 (and (not message-this-is-news)
1646 (or message-this-is-mail
1649 (message-narrow-to-headers)
1650 (or (message-fetch-field "to")
1651 (message-fetch-field "cc")
1652 (message-fetch-field "bcc")))))))
1654 (defun message-next-header ()
1655 "Go to the beginning of the next header."
1657 (or (eobp) (forward-char 1))
1658 (not (if (re-search-forward "^[^ \t]" nil t)
1660 (goto-char (point-max)))))
1662 (defun message-sort-headers-1 ()
1663 "Sort the buffer as headers using `message-rank' text props."
1664 (goto-char (point-min))
1667 nil 'message-next-header
1669 (message-next-header)
1673 (or (get-text-property (point) 'message-rank)
1676 (defun message-sort-headers ()
1677 "Sort the headers of the current message according to `message-header-format-alist'."
1681 (let ((max (1+ (length message-header-format-alist)))
1683 (message-narrow-to-headers)
1684 (while (re-search-forward "^[^ \n]+:" nil t)
1686 (match-beginning 0) (1+ (match-beginning 0))
1688 (if (setq rank (length (memq (assq (intern (buffer-substring
1690 (1- (match-end 0))))
1691 message-header-format-alist)
1692 message-header-format-alist)))
1695 (message-sort-headers-1))))
1705 (defvar message-mode-map nil)
1707 (unless message-mode-map
1708 (setq message-mode-map (make-keymap))
1709 (set-keymap-parent message-mode-map text-mode-map)
1710 (define-key message-mode-map "\C-c?" 'describe-mode)
1712 (define-key message-mode-map "\C-c\C-f\C-t" 'message-goto-to)
1713 (define-key message-mode-map "\C-c\C-f\C-b" 'message-goto-bcc)
1714 (define-key message-mode-map "\C-c\C-f\C-w" 'message-goto-fcc)
1715 (define-key message-mode-map "\C-c\C-f\C-c" 'message-goto-cc)
1716 (define-key message-mode-map "\C-c\C-f\C-s" 'message-goto-subject)
1717 ;; (define-key message-mode-map "\C-c\C-f\C-r" 'message-goto-reply-to)
1718 (define-key message-mode-map "\C-c\C-f\C-r" 'message-goto-mail-reply-to)
1719 (define-key message-mode-map "\C-c\C-f\C-m" 'message-goto-mail-followup-to)
1720 (define-key message-mode-map "\C-c\C-f\C-n" 'message-goto-newsgroups)
1721 (define-key message-mode-map "\C-c\C-f\C-d" 'message-goto-distribution)
1722 (define-key message-mode-map "\C-c\C-f\C-f" 'message-goto-followup-to)
1723 (define-key message-mode-map "\C-c\C-f\C-k" 'message-goto-keywords)
1724 (define-key message-mode-map "\C-c\C-f\C-u" 'message-goto-summary)
1725 (define-key message-mode-map "\C-c\C-b" 'message-goto-body)
1726 (define-key message-mode-map "\C-c\C-i" 'message-goto-signature)
1727 (define-key message-mode-map "\C-c\C-fc" 'message-goto-mail-copies-to)
1729 (define-key message-mode-map "\C-c\C-t" 'message-insert-to)
1730 (define-key message-mode-map "\C-c\C-n" 'message-insert-newsgroups)
1732 (define-key message-mode-map "\C-c\C-y" 'message-yank-original)
1733 (define-key message-mode-map "\C-c\M-\C-y" 'message-yank-buffer)
1734 (define-key message-mode-map "\C-c\C-q" 'message-fill-yanked-message)
1735 (define-key message-mode-map "\C-c\C-w" 'message-insert-signature)
1736 (define-key message-mode-map "\C-c\M-h" 'message-insert-headers)
1737 (define-key message-mode-map "\C-c\C-r" 'message-caesar-buffer-body)
1738 (define-key message-mode-map "\C-c\C-o" 'message-sort-headers)
1739 (define-key message-mode-map "\C-c\M-r" 'message-rename-buffer)
1741 (define-key message-mode-map "\C-c\C-c" 'message-send-and-exit)
1742 (define-key message-mode-map "\C-c\C-s" 'message-send)
1743 (define-key message-mode-map "\C-c\C-k" 'message-kill-buffer)
1744 (define-key message-mode-map "\C-c\C-d" 'message-dont-send)
1746 (define-key message-mode-map "\C-c\C-e" 'message-elide-region)
1747 (define-key message-mode-map "\C-c\C-v" 'message-delete-not-region)
1748 (define-key message-mode-map "\C-c\C-z" 'message-kill-to-signature)
1749 (define-key message-mode-map "\M-\r" 'message-newline-and-reformat)
1751 (define-key message-mode-map "\t" 'message-tab)
1753 (define-key message-mode-map "\C-x\C-s" 'message-save-drafts)
1754 (define-key message-mode-map "\C-xk" 'message-mimic-kill-buffer))
1757 message-mode-menu message-mode-map "Message Menu."
1759 ["Sort Headers" message-sort-headers t]
1760 ["Yank Original" message-yank-original t]
1761 ["Fill Yanked Message" message-fill-yanked-message t]
1762 ["Insert Signature" message-insert-signature t]
1763 ["Caesar (rot13) Message" message-caesar-buffer-body t]
1764 ["Caesar (rot13) Region" message-caesar-region (mark t)]
1765 ["Elide Region" message-elide-region (mark t)]
1766 ["Delete Outside Region" message-delete-not-region (mark t)]
1767 ["Kill To Signature" message-kill-to-signature t]
1768 ["Newline and Reformat" message-newline-and-reformat t]
1769 ["Rename buffer" message-rename-buffer t]
1770 ["Spellcheck" ispell-message t]
1771 ["Attach file as MIME" mime-edit-insert-file t]
1773 ["Send Message" message-send-and-exit t]
1774 ["Abort Message" message-dont-send t]
1775 ["Kill Message" message-kill-buffer t]))
1778 message-mode-field-menu message-mode-map ""
1780 ["Fetch To" message-insert-to t]
1781 ["Fetch Newsgroups" message-insert-newsgroups t]
1783 ["To" message-goto-to t]
1784 ["Subject" message-goto-subject t]
1785 ["Cc" message-goto-cc t]
1786 ["Reply-To" message-goto-reply-to t]
1787 ["Mail-Reply-To" message-goto-mail-reply-to t]
1788 ["Mail-Followup-To" message-goto-mail-followup-to t]
1789 ["Mail-Copies-To" message-goto-mail-copies-to t]
1790 ["Summary" message-goto-summary t]
1791 ["Keywords" message-goto-keywords t]
1792 ["Newsgroups" message-goto-newsgroups t]
1793 ["Followup-To" message-goto-followup-to t]
1794 ["Distribution" message-goto-distribution t]
1795 ["Body" message-goto-body t]
1796 ["Signature" message-goto-signature t]))
1798 (defvar facemenu-add-face-function)
1799 (defvar facemenu-remove-face-function)
1802 (defun message-mode ()
1803 "Major mode for editing mail and news to be sent.
1804 Like Text Mode but with these additional commands:
1805 C-c C-s message-send (send the message) C-c C-c message-send-and-exit
1806 C-c C-d Pospone sending the message C-c C-k Kill the message
1807 C-c C-f move to a header field (and create it if there isn't):
1808 C-c C-f C-t move to To C-c C-f C-s move to Subject
1809 C-c C-f C-c move to Cc C-c C-f C-b move to Bcc
1810 C-c C-f C-w move to Fcc C-c C-f C-r move to Reply-To
1811 C-c C-f C-u move to Summary C-c C-f C-n move to Newsgroups
1812 C-c C-f C-k move to Keywords C-c C-f C-d move to Distribution
1813 C-c C-f C-m move to Mail-Followup-To
1814 C-c C-f C-f move to Followup-To
1815 C-c C-t message-insert-to (add a To header to a news followup)
1816 C-c C-n message-insert-newsgroups (add a Newsgroup header to a news reply)
1817 C-c C-b message-goto-body (move to beginning of message text).
1818 C-c C-i message-goto-signature (move to the beginning of the signature).
1819 C-c C-w message-insert-signature (insert `message-signature-file' file).
1820 C-c C-y message-yank-original (insert current message, if any).
1821 C-c C-q message-fill-yanked-message (fill what was yanked).
1822 C-c C-e message-elide-region (elide the text between point and mark).
1823 C-c C-v message-delete-not-region (remove the text outside the region).
1824 C-c C-z message-kill-to-signature (kill the text up to the signature).
1825 C-c C-r message-caesar-buffer-body (rot13 the message body).
1826 M-RET message-newline-and-reformat (break the line and reformat)."
1828 (kill-all-local-variables)
1829 (set (make-local-variable 'message-reply-buffer) nil)
1830 (make-local-variable 'message-send-actions)
1831 (make-local-variable 'message-exit-actions)
1832 (make-local-variable 'message-kill-actions)
1833 (make-local-variable 'message-postpone-actions)
1834 (make-local-variable 'message-draft-article)
1835 (make-local-hook 'kill-buffer-hook)
1836 (set-syntax-table message-mode-syntax-table)
1837 (use-local-map message-mode-map)
1838 (setq local-abbrev-table message-mode-abbrev-table)
1839 (setq major-mode 'message-mode)
1840 (setq mode-name "Message")
1841 (setq buffer-offer-save t)
1842 (make-local-variable 'facemenu-add-face-function)
1843 (make-local-variable 'facemenu-remove-face-function)
1844 (setq facemenu-add-face-function
1846 (let ((face-fun (cdr (assq face message-face-alist))))
1848 (funcall face-fun (point) end)
1849 (error "Face %s not configured for %s mode" face mode-name)))
1851 facemenu-remove-face-function t)
1852 (make-local-variable 'message-reply-headers)
1853 (setq message-reply-headers nil)
1854 (make-local-variable 'message-user-agent)
1855 (make-local-variable 'message-post-method)
1856 (set (make-local-variable 'message-sent-message-via) nil)
1857 (set (make-local-variable 'message-checksum) nil)
1858 (make-local-variable 'message-parameter-alist)
1859 (setq message-parameter-alist
1860 (copy-sequence message-startup-parameter-alist))
1861 (message-setup-fill-variables)
1862 ;;(when (fboundp 'mail-hist-define-keys)
1863 ;; (mail-hist-define-keys))
1864 (if (featurep 'xemacs)
1865 (message-setup-toolbar)
1866 (set (make-local-variable 'font-lock-defaults)
1867 '((message-font-lock-keywords
1868 message-font-lock-keywords-1
1869 message-font-lock-keywords-2)
1871 (font-lock-mark-block-function . mark-paragraph))))
1872 (set (make-local-variable 'message-font-lock-last-position) nil)
1873 (easy-menu-add message-mode-menu message-mode-map)
1874 (easy-menu-add message-mode-field-menu message-mode-map)
1875 ;; Allow mail alias things.
1876 (when (eq message-mail-alias-type 'abbrev)
1877 (if (fboundp 'mail-abbrevs-setup)
1878 (mail-abbrevs-setup)
1879 (mail-aliases-setup)))
1880 (message-set-auto-save-file-name)
1881 (make-local-variable 'indent-tabs-mode) ;Turn off tabs for indentation.
1882 (setq indent-tabs-mode nil)
1883 (run-hooks 'text-mode-hook 'message-mode-hook))
1885 (defun message-setup-fill-variables ()
1886 "Setup message fill variables."
1887 (make-local-variable 'paragraph-separate)
1888 (make-local-variable 'paragraph-start)
1889 (make-local-variable 'adaptive-fill-regexp)
1890 (unless (boundp 'adaptive-fill-first-line-regexp)
1891 (setq adaptive-fill-first-line-regexp nil))
1892 (make-local-variable 'adaptive-fill-first-line-regexp)
1893 (make-local-variable 'auto-fill-inhibit-regexp)
1894 (let ((quote-prefix-regexp
1896 "[ \t]*" ; possible initial space
1897 "\\(\\(" (regexp-quote message-yank-prefix) "\\|" ; user's prefix
1898 "\\w+>\\|" ; supercite-style prefix
1899 "[|:>]" ; standard prefix
1900 "\\)[ \t]*\\)+"))) ; possible space after each prefix
1901 (setq paragraph-start
1903 (regexp-quote mail-header-separator) "$\\|"
1904 "[ \t]*$\\|" ; blank lines
1905 "-- $\\|" ; signature delimiter
1906 "---+$\\|" ; delimiters for forwarded messages
1907 page-delimiter "$\\|" ; spoiler warnings
1908 ".*wrote:$\\|" ; attribution lines
1909 quote-prefix-regexp "$")) ; empty lines in quoted text
1910 (setq paragraph-separate paragraph-start)
1911 (setq adaptive-fill-regexp
1912 (concat quote-prefix-regexp "\\|" adaptive-fill-regexp))
1913 (setq adaptive-fill-first-line-regexp
1914 (concat quote-prefix-regexp "\\|"
1915 adaptive-fill-first-line-regexp))
1916 (setq auto-fill-inhibit-regexp "^[A-Z][^: \n\t]+:")))
1921 ;;; Message mode commands
1924 ;;; Movement commands
1926 (defun message-goto-to ()
1927 "Move point to the To header."
1929 (message-position-on-field "To"))
1931 (defun message-goto-subject ()
1932 "Move point to the Subject header."
1934 (message-position-on-field "Subject"))
1936 (defun message-goto-cc ()
1937 "Move point to the Cc header."
1939 (message-position-on-field "Cc" "To"))
1941 (defun message-goto-bcc ()
1942 "Move point to the Bcc header."
1944 (message-position-on-field "Bcc" "Cc" "To"))
1946 (defun message-goto-fcc ()
1947 "Move point to the Fcc header."
1949 (message-position-on-field "Fcc" "To" "Newsgroups"))
1951 (defun message-goto-reply-to ()
1952 "Move point to the Reply-To header."
1954 (message-position-on-field "Reply-To" "Subject"))
1956 (defun message-goto-mail-reply-to ()
1957 "Move point to the Mail-Reply-To header."
1959 (message-position-on-field "Mail-Reply-To" "Subject"))
1961 (defun message-goto-mail-followup-to ()
1962 "Move point to the Mail-Followup-To header. If the header is newly created
1963 and To field contains only one address, the address is inserted in default."
1965 (unless (message-position-on-field "Mail-Followup-To" "Subject")
1966 (let ((start (point))
1969 (message-narrow-to-headers)
1970 (setq addresses (split-string (mail-strip-quoted-names
1971 (or (std11-fetch-field "to") ""))
1973 (when (eq 1 (length addresses))
1975 (insert (car addresses))
1976 (goto-char start))))))
1978 (defun message-goto-mail-copies-to ()
1979 "Move point to the Mail-Copies-To header. If the header is newly created,
1980 a string \"never\" is inserted in default."
1982 (unless (message-position-on-field "Mail-Copies-To" "Subject")
1986 (defun message-goto-newsgroups ()
1987 "Move point to the Newsgroups header."
1989 (message-position-on-field "Newsgroups"))
1991 (defun message-goto-distribution ()
1992 "Move point to the Distribution header."
1994 (message-position-on-field "Distribution"))
1996 (defun message-goto-followup-to ()
1997 "Move point to the Followup-To header."
1999 (message-position-on-field "Followup-To" "Newsgroups"))
2001 (defun message-goto-keywords ()
2002 "Move point to the Keywords header."
2004 (message-position-on-field "Keywords" "Subject"))
2006 (defun message-goto-summary ()
2007 "Move point to the Summary header."
2009 (message-position-on-field "Summary" "Subject"))
2011 (defun message-goto-body ()
2012 "Move point to the beginning of the message body."
2014 (if (looking-at "[ \t]*\n") (expand-abbrev))
2015 (goto-char (point-min))
2016 (or (search-forward (concat "\n" mail-header-separator "\n") nil t)
2017 (search-forward "\n\n" nil t)))
2019 (defun message-goto-eoh ()
2020 "Move point to the end of the headers."
2025 (defun message-goto-signature ()
2026 "Move point to the beginning of the message signature.
2027 If there is no signature in the article, go to the end and
2030 (goto-char (point-min))
2031 (if (re-search-forward message-signature-separator nil t)
2033 (goto-char (point-max))
2038 (defun message-insert-to (&optional force)
2039 "Insert a To header that points to the author of the article being replied to.
2040 If the original author requested not to be sent mail, the function signals
2042 With the prefix argument FORCE, insert the header anyway."
2044 (let ((co (message-fetch-reply-field "mail-copies-to")))
2045 (when (and (null force)
2047 (or (equal (downcase co) "never")
2048 (equal (downcase co) "nobody")))
2049 (error "The user has requested not to have copies sent via mail")))
2050 (when (and (message-position-on-field "To")
2051 (mail-fetch-field "to")
2052 (not (string-match "\\` *\\'" (mail-fetch-field "to"))))
2054 (insert (or (message-fetch-reply-field "reply-to")
2055 (message-fetch-reply-field "from") "")))
2057 (defun message-widen-reply ()
2058 "Widen the reply to include maximum recipients."
2061 (and message-reply-buffer
2062 (buffer-name message-reply-buffer)
2064 (set-buffer message-reply-buffer)
2065 (message-get-reply-headers t)))))
2068 (message-narrow-to-headers)
2069 (dolist (elem follow-to)
2070 (message-remove-header (symbol-name (car elem)))
2071 (goto-char (point-min))
2072 (insert (symbol-name (car elem)) ": "
2073 (cdr elem) "\n"))))))
2075 (defun message-insert-newsgroups ()
2076 "Insert the Newsgroups header from the article being replied to."
2078 (when (and (message-position-on-field "Newsgroups")
2079 (mail-fetch-field "newsgroups")
2080 (not (string-match "\\` *\\'" (mail-fetch-field "newsgroups"))))
2082 (insert (or (message-fetch-reply-field "newsgroups") "")))
2086 ;;; Various commands
2088 (defun message-delete-not-region (beg end)
2089 "Delete everything in the body of the current message that is outside of the region."
2093 (delete-region (point) (if (not (message-goto-signature))
2099 (delete-region beg (progn (message-goto-body)
2102 (when (message-goto-signature)
2105 (defun message-kill-to-signature ()
2106 "Deletes all text up to the signature."
2108 (let ((point (point)))
2109 (message-goto-signature)
2112 (kill-region point (point))
2116 (defun message-newline-and-reformat ()
2117 "Insert four newlines, and then reformat if inside quoted text."
2119 (let ((prefix "[]>»|:}+ \t]*")
2120 (supercite-thing "[-._a-zA-Z0-9]*[>]+[ \t]*")
2125 (when (looking-at (concat prefix
2127 (setq quoted (match-string 0))))
2129 (setq point (point))
2131 (delete-region (point) (re-search-forward "[ \t]*"))
2134 (fill-paragraph nil)
2138 (defun message-insert-signature (&optional force)
2139 "Insert a signature. See documentation for the `message-signature' variable."
2140 (interactive (list 0))
2143 ((and (null message-signature)
2146 (goto-char (point-max))
2147 (not (re-search-backward message-signature-separator nil t))))
2148 ((and (null message-signature)
2151 ((message-functionp message-signature)
2152 (funcall message-signature))
2153 ((listp message-signature)
2154 (eval message-signature))
2155 (t message-signature)))
2157 (cond ((stringp signature)
2159 ((and (eq t signature)
2160 message-signature-file
2161 (file-exists-p message-signature-file))
2164 (goto-char (point-max))
2165 ;; Insert the signature.
2169 (if (eq signature t)
2170 (insert-file-contents message-signature-file)
2172 (goto-char (point-max))
2173 (or (bolp) (insert "\n")))))
2175 (defun message-elide-region (b e)
2176 "Elide the text between point and mark.
2177 An ellipsis (from `message-elide-ellipsis') will be inserted where the
2181 (insert message-elide-ellipsis))
2183 (defvar message-caesar-translation-table nil)
2185 (defun message-caesar-region (b e &optional n)
2186 "Caesar rotation of region by N, default 13, for decrypting netnews."
2189 (min (point) (or (mark t) (point)))
2190 (max (point) (or (mark t) (point)))
2191 (when current-prefix-arg
2192 (prefix-numeric-value current-prefix-arg))))
2194 (setq n (if (numberp n) (mod n 26) 13)) ;canonize N
2195 (unless (or (zerop n) ; no action needed for a rot of 0
2196 (= b e)) ; no region to rotate
2197 ;; We build the table, if necessary.
2198 (when (or (not message-caesar-translation-table)
2199 (/= (aref message-caesar-translation-table ?a) (+ ?a n)))
2200 (setq message-caesar-translation-table
2201 (message-make-caesar-translation-table n)))
2202 (translate-region b e message-caesar-translation-table)))
2204 (defun message-make-caesar-translation-table (n)
2205 "Create a rot table with offset N."
2207 (table (make-string 256 0)))
2208 (while (< (incf i) 256)
2211 (substring table 0 ?A)
2212 (substring table (+ ?A n) (+ ?A n (- 26 n)))
2213 (substring table ?A (+ ?A n))
2214 (substring table (+ ?A 26) ?a)
2215 (substring table (+ ?a n) (+ ?a n (- 26 n)))
2216 (substring table ?a (+ ?a n))
2217 (substring table (+ ?a 26) 255))))
2219 (defun message-caesar-buffer-body (&optional rotnum)
2220 "Caesar rotates all letters in the current buffer by 13 places.
2221 Used to encode/decode possiblyun offensive messages (commonly in net.jokes).
2222 With prefix arg, specifies the number of places to rotate each letter forward.
2223 Mail and USENET news headers are not rotated."
2224 (interactive (if current-prefix-arg
2225 (list (prefix-numeric-value current-prefix-arg))
2229 (when (message-goto-body)
2230 (narrow-to-region (point) (point-max)))
2231 (message-caesar-region (point-min) (point-max) rotnum))))
2233 (defun message-pipe-buffer-body (program)
2234 "Pipe the message body in the current buffer through PROGRAM."
2237 (when (message-goto-body)
2238 (narrow-to-region (point) (point-max)))
2239 (shell-command-on-region
2240 (point-min) (point-max) program nil t))))
2242 (defun message-rename-buffer (&optional enter-string)
2243 "Rename the *message* buffer to \"*message* RECIPIENT\".
2244 If the function is run with a prefix, it will ask for a new buffer
2245 name, rather than giving an automatic name."
2246 (interactive "Pbuffer name: ")
2249 (goto-char (point-min))
2250 (narrow-to-region (point)
2251 (search-forward mail-header-separator nil 'end))
2253 (if (message-news-p) (message-fetch-field "Newsgroups")
2254 (message-fetch-field "To"))
2257 (if (string-match "," mail-to)
2258 (concat (substring mail-to 0 (match-beginning 0)) ", ...")
2260 (name-default (concat "*message* " mail-trimmed-to))
2261 (name (if enter-string
2262 (read-string "New buffer name: " name-default)
2264 (rename-buffer name t)))))
2266 (defun message-fill-yanked-message (&optional justifyp)
2267 "Fill the paragraphs of a message yanked into this one.
2268 Numeric argument means justify as well."
2271 (goto-char (point-min))
2272 (search-forward (concat "\n" mail-header-separator "\n") nil t)
2273 (let ((fill-prefix message-yank-prefix))
2274 (fill-individual-paragraphs (point) (point-max) justifyp))))
2276 (defun message-indent-citation ()
2277 "Modify text just inserted from a message to be cited.
2278 The inserted text should be the region.
2279 When this function returns, the region is again around the modified text.
2281 Normally, indent each nonblank line `message-indentation-spaces' spaces.
2282 However, if `message-yank-prefix' is non-nil, insert that prefix on each line."
2283 (let ((start (point)))
2284 ;; Remove unwanted headers.
2285 (when message-ignored-cited-headers
2290 (if (search-forward "\n\n" nil t)
2293 (message-remove-header message-ignored-cited-headers t)
2294 (when (= (point-min) (point-max))
2295 (setq all-removed t))
2296 (goto-char (point-max)))
2300 ;; Delete blank lines at the start of the buffer.
2301 (while (and (point-min)
2304 (message-delete-line))
2305 ;; Delete blank lines at the end of the buffer.
2306 (goto-char (point-max))
2309 (while (and (zerop (forward-line -1))
2311 (message-delete-line))
2312 ;; Do the indentation.
2313 (if (null message-yank-prefix)
2314 (indent-rigidly start (mark t) message-indentation-spaces)
2317 (while (< (point) (mark t))
2318 (insert message-yank-prefix)
2322 (defun message-list-references (refs-list &rest refs-strs)
2323 "Add `Message-ID's which appear in REFS-STRS but not in REFS-LIST,
2325 (let (refs ref id saved-id)
2326 (when (and refs-list
2327 (integerp message-list-references-add-position))
2328 (let ((pos message-list-references-add-position))
2329 (while (and refs-list
2331 (push (pop refs-list) saved-id)
2332 (setq pos (1- pos)))))
2334 (when (setq refs (pop refs-strs))
2335 (setq refs (std11-parse-msg-ids (std11-lexical-analyze refs)))
2337 (when (eq (car (setq ref (pop refs))) 'msg-id)
2338 (setq id (concat "<" (mapconcat 'cdr (cdr ref) "") ">"))
2339 (or (member id refs-list)
2340 (member id saved-id)
2341 (push id refs-list))))))
2343 (push (pop saved-id) refs-list))
2346 (defvar gnus-article-copy)
2347 (defun message-yank-original (&optional arg)
2348 "Insert the message being replied to, if any.
2349 Puts point before the text and mark after.
2350 Normally indents each nonblank line ARG spaces (default 3). However,
2351 if `message-yank-prefix' is non-nil, insert that prefix on each line.
2353 This function uses `message-cite-function' to do the actual citing.
2355 Just \\[universal-argument] as argument means don't indent, insert no
2356 prefix, and don't delete any headers.
2358 In addition, if `message-yank-add-new-references' is non-nil and this
2359 command is called interactively, new IDs from the yanked article will
2360 be added to \"References\" field.
2361 \(See also `message-yank-add-new-references'.)"
2363 (let ((modified (buffer-modified-p))
2364 (buffer (message-eval-parameter message-reply-buffer))
2367 message-cite-function)
2368 (delete-windows-on buffer t)
2369 (insert-buffer buffer) ; mark will be set at the end of article.
2373 ;; Add new IDs to References field.
2374 (when (and message-yank-add-new-references (interactive-p))
2377 (message-narrow-to-headers)
2378 (setq refs (message-list-references
2380 (message-fetch-field "References")))
2382 (narrow-to-region start end)
2383 (std11-narrow-to-header)
2384 (when (setq refs (message-list-references
2386 (unless (eq message-yank-add-new-references
2388 (or (message-fetch-field "References")
2389 (message-fetch-field "In-Reply-To")))
2390 (message-fetch-field "Message-ID")))
2392 (message-narrow-to-headers)
2393 (goto-char (point-min))
2394 (let ((case-fold-search t))
2395 (if (re-search-forward "^References:\\([\t ]+.+\n\\)+" nil t)
2397 (goto-char (point-max))))
2399 (list (or (assq 'References message-header-format-alist)
2400 '(References . message-fill-references)))
2401 (list (cons 'References
2402 (mapconcat 'identity (nreverse refs) " "))))
2403 (backward-delete-char 1)))))
2405 (funcall message-cite-function)
2406 (message-exchange-point-and-mark)
2410 (setq message-checksum (message-checksum))))))
2412 (defun message-yank-buffer (buffer)
2413 "Insert BUFFER into the current buffer and quote it."
2414 (interactive "bYank buffer: ")
2415 (let ((message-reply-buffer buffer))
2416 (save-window-excursion
2417 (message-yank-original))))
2419 (defun message-buffers ()
2420 "Return a list of active message buffers."
2423 (dolist (buffer (buffer-list t))
2425 (when (and (eq major-mode 'message-mode)
2426 (null message-sent-message-via))
2427 (push (buffer-name buffer) buffers))))
2428 (nreverse buffers)))
2430 (defun message-cite-original-without-signature ()
2431 "Cite function in the standard Message manner."
2432 (let ((start (point))
2435 (when message-indent-citation-function
2436 (if (listp message-indent-citation-function)
2437 message-indent-citation-function
2438 (list message-indent-citation-function)))))
2442 (when (re-search-backward message-signature-separator start t)
2443 ;; Also peel off any blank lines before the signature.
2445 (while (looking-at "^[ \t]*$")
2448 (delete-region (point) end))
2451 (funcall (pop functions)))
2452 (when message-citation-line-function
2455 (funcall message-citation-line-function))))
2457 (defvar mail-citation-hook) ;Compiler directive
2458 (defun message-cite-original ()
2459 "Cite function in the standard Message manner."
2460 (if (and (boundp 'mail-citation-hook)
2462 (run-hooks 'mail-citation-hook)
2463 (let ((start (point))
2466 (when message-indent-citation-function
2467 (if (listp message-indent-citation-function)
2468 message-indent-citation-function
2469 (list message-indent-citation-function))))
2470 (message-reply-headers (or message-reply-headers
2471 (make-mail-header))))
2472 (mail-header-set-from message-reply-headers
2476 (if (search-forward "\n\n" nil t)
2479 (or (message-fetch-field "from")
2483 (funcall (pop functions)))
2484 (when message-citation-line-function
2487 (funcall message-citation-line-function)))))
2489 (defun message-insert-citation-line ()
2490 "Function that inserts a simple citation line."
2491 (when message-reply-headers
2492 (insert (mail-header-from message-reply-headers) " writes:\n\n")))
2494 (defun message-position-on-field (header &rest afters)
2495 (let ((case-fold-search t))
2498 (goto-char (point-min))
2501 (concat "^" (regexp-quote mail-header-separator) "$"))
2502 (match-beginning 0)))
2503 (goto-char (point-min))
2504 (if (re-search-forward (concat "^" (regexp-quote header) ":") nil t)
2506 (re-search-forward "^[^ \t]" nil 'move)
2508 (skip-chars-backward "\n")
2511 (not (re-search-forward
2512 (concat "^" (regexp-quote (car afters)) ":")
2516 (re-search-forward "^[^ \t]" nil 'move)
2517 (beginning-of-line))
2518 (insert header ": \n")
2522 (defun message-remove-signature ()
2523 "Remove the signature from the text between point and mark.
2524 The text will also be indented the normal way."
2526 (let ((start (point))
2528 (if (not (re-search-forward message-signature-separator (mark t) t))
2529 ;; No signature here, so we just indent the cited text.
2530 (message-indent-citation)
2531 ;; Find the last non-empty line.
2533 (while (looking-at "[ \t]*$")
2536 (setq mark (set-marker (make-marker) (point)))
2538 (message-indent-citation)
2539 ;; Enable undoing the deletion.
2541 (delete-region mark (mark t))
2542 (set-marker mark nil)))))
2547 ;;; Sending messages
2550 ;; Avoid byte-compile warning.
2551 (defvar message-encoding-buffer nil)
2552 (defvar message-edit-buffer nil)
2553 (defvar message-mime-mode nil)
2555 (defun message-send-and-exit (&optional arg)
2556 "Send message like `message-send', then, if no errors, exit from mail buffer."
2558 (let ((buf (current-buffer))
2559 (actions message-exit-actions)
2560 (frame (selected-frame))
2561 (org-frame message-original-frame))
2562 (when (and (message-send arg)
2564 (if message-kill-buffer-on-exit
2567 (when (eq buf (current-buffer))
2568 (message-bury buf)))
2569 (message-do-actions actions)
2570 (message-delete-frame frame org-frame)
2573 (defun message-dont-send ()
2574 "Don't send the message you have been editing."
2576 (message-save-drafts)
2577 (let ((actions message-postpone-actions)
2578 (frame (selected-frame))
2579 (org-frame message-original-frame))
2580 (message-bury (current-buffer))
2581 (message-do-actions actions)
2582 (message-delete-frame frame org-frame)))
2584 (defun message-kill-buffer ()
2585 "Kill the current buffer."
2587 (when (or (not (buffer-modified-p))
2588 (eq t message-kill-buffer-query-function)
2589 (funcall message-kill-buffer-query-function
2590 "The buffer modified; kill anyway? "))
2591 (let ((actions message-kill-actions)
2592 (frame (selected-frame))
2593 (org-frame message-original-frame))
2594 (setq buffer-file-name nil)
2595 (kill-buffer (current-buffer))
2596 (message-do-actions actions)
2597 (message-delete-frame frame org-frame)))
2600 (defun message-mimic-kill-buffer ()
2601 "Kill the current buffer with query."
2603 (unless (eq 'message-mode major-mode)
2604 (error "%s must be invoked from a message buffer." this-command))
2605 (let ((command this-command)
2606 (bufname (read-buffer (format "Kill buffer: (default %s) "
2608 (if (or (not bufname)
2609 (string-equal bufname "")
2610 (string-equal bufname (buffer-name)))
2611 (message-kill-buffer)
2612 (message "%s must be invoked only for the current buffer." command))))
2614 (defun message-delete-frame (frame org-frame)
2615 "Delete frame for editing message."
2616 (when (and (or (static-if (featurep 'xemacs)
2617 (device-on-window-system-p)
2619 (>= emacs-major-version 20))
2620 (or (and (eq message-delete-frame-on-exit t)
2621 (select-frame frame)
2622 (or (eq frame org-frame)
2624 (y-or-n-p "Delete this frame?")
2626 (and (eq message-delete-frame-on-exit 'ask)
2627 (select-frame frame)
2629 (y-or-n-p "Delete this frame?")
2631 (delete-frame frame)))
2633 (defun message-bury (buffer)
2634 "Bury this mail buffer."
2635 (let ((newbuf (other-buffer buffer)))
2636 (bury-buffer buffer)
2637 (if (and (fboundp 'frame-parameters)
2638 (cdr (assq 'dedicated (frame-parameters)))
2639 (not (null (delq (selected-frame) (visible-frame-list)))))
2640 (delete-frame (selected-frame))
2641 (switch-to-buffer newbuf))))
2643 (defun message-send (&optional arg)
2644 "Send the message in the current buffer.
2645 If `message-interactive' is non-nil, wait for success indication or
2646 error messages, and inform user.
2647 Otherwise any failure is reported in a message back to the user from
2649 The usage of ARG is defined by the instance that called Message.
2650 It should typically alter the sending method in some way or other."
2653 (when (or (buffer-modified-p)
2654 (message-check-element 'unchanged)
2655 (y-or-n-p "No changes in the buffer; really send? "))
2656 ;; Make it possible to undo the coming changes.
2658 (let ((inhibit-read-only t))
2659 (put-text-property (point-min) (point-max) 'read-only nil))
2660 (run-hooks 'message-send-hook)
2661 (message-fix-before-sending)
2662 (message message-sending-message)
2663 (let ((message-encoding-buffer
2664 (message-generate-new-buffer-clone-locals " message encoding"))
2665 (message-edit-buffer (current-buffer))
2666 (message-mime-mode mime-edit-mode-flag)
2667 (alist message-send-method-alist)
2671 (set-buffer message-encoding-buffer)
2673 (insert-buffer message-edit-buffer)
2674 (funcall message-encode-function)
2676 (setq elem (pop alist)))
2677 (when (funcall (cadr elem))
2678 (when (and (or (not (memq (car elem)
2679 message-sent-message-via))
2682 "Already sent message via %s; resend? "
2684 (setq success (funcall (caddr elem) arg)))
2686 (unless (or sent (not success))
2687 (error "No methods specified to send by"))
2689 (when (and success sent)
2692 (run-hooks 'message-sent-hook))
2693 (message "Sending...done")
2694 ;; Mark the buffer as unmodified and delete autosave.
2695 (set-buffer-modified-p nil)
2696 (delete-auto-save-file-if-necessary t)
2697 (message-disassociate-draft)
2698 ;; Delete other mail buffers and stuff.
2699 (message-do-send-housekeeping)
2700 (message-do-actions message-send-actions)
2703 (kill-buffer message-encoding-buffer)))))
2705 (defun message-send-via-mail (arg)
2706 "Send the current message via mail."
2707 (message-send-mail arg))
2709 (defun message-send-via-news (arg)
2710 "Send the current message via news."
2711 (message-send-news arg))
2713 (defmacro message-check (type &rest forms)
2714 "Eval FORMS if TYPE is to be checked."
2715 `(or (message-check-element ,type)
2719 (put 'message-check 'lisp-indent-function 1)
2720 (put 'message-check 'edebug-form-spec '(form body))
2722 ;; This function will be used by MIME-Edit when inserting invisible parts.
2723 (defun message-invisible-region (start end)
2724 (if (featurep 'xemacs)
2727 (eq (following-char) ?\n))
2728 (setq start (1+ start)))
2730 (goto-char (1- end))
2731 (eq (following-char) ?\n))
2732 (setq end (1- end))))
2733 (put-text-property start end 'invisible t)
2734 (if (eq 'message-mode major-mode)
2735 (put-text-property start end 'message-invisible t)))
2737 (eval-after-load "invisible"
2738 '(defalias 'invisible-region 'message-invisible-region))
2740 (defun message-fix-before-sending ()
2741 "Do various things to make the message nice before sending it."
2742 ;; Make sure there's a newline at the end of the message.
2744 (goto-char (point-max))
2747 ;; Expose all invisible text with the property `message-invisible'.
2748 ;; We should believe that the things might be created by MIME-Edit.
2750 (while (setq start (text-property-any (point-min) (point-max)
2751 'message-invisible t))
2752 (remove-text-properties start
2753 (or (text-property-not-all start (point-max)
2754 'message-invisible t)
2756 '(invisible nil message-invisible nil))))
2757 ;; Expose all invisible text.
2758 (message-check 'invisible-text
2759 (when (text-property-any (point-min) (point-max) 'invisible t)
2760 (put-text-property (point-min) (point-max) 'invisible nil)
2761 (unless (yes-or-no-p
2762 "Invisible text found and made visible; continue posting? ")
2763 (error "Invisible text found and made visible")))))
2765 (defun message-add-action (action &rest types)
2766 "Add ACTION to be performed when doing an exit of type TYPES."
2769 (set (setq var (intern (format "message-%s-actions" (pop types))))
2770 (nconc (symbol-value var) (list action))))))
2772 (defun message-do-actions (actions)
2773 "Perform all actions in ACTIONS."
2774 ;; Now perform actions on successful sending.
2778 ;; A simple function.
2779 ((message-functionp (car actions))
2780 (funcall (car actions)))
2781 ;; Something to be evaled.
2783 (eval (car actions)))))
2786 (defsubst message-maybe-split-and-send-mail ()
2787 "Split a message if necessary, and send it via mail.
2788 Returns nil if sending succeeded, returns any string if sending failed.
2789 This sub function is for exclusive use of `message-send-mail'."
2790 (let ((mime-edit-split-ignored-field-regexp
2791 mime-edit-split-ignored-field-regexp)
2792 (case-fold-search t)
2794 (while (string-match "Message-ID" mime-edit-split-ignored-field-regexp)
2795 (setq mime-edit-split-ignored-field-regexp
2796 (concat (substring mime-edit-split-ignored-field-regexp
2797 0 (match-beginning 0))
2798 "Hey_MIME-Edit,_there_is_an_inviolable_Message_ID"
2799 "_so_don't_rape_it!"
2800 (substring mime-edit-split-ignored-field-regexp
2804 (catch 'message-sending-mail-failure
2805 (mime-edit-maybe-split-and-send
2810 (std11-narrow-to-header mail-header-separator)
2811 (goto-char (point-min))
2812 (when (re-search-forward "^Message-ID:" nil t)
2813 (delete-region (match-end 0) (std11-field-end))
2814 (insert " " (message-make-message-id))))
2816 (funcall message-send-mail-function)
2818 (throw 'message-sending-mail-failure err))))))
2822 (funcall message-send-mail-function)
2826 (if (eq 'error (car failure))
2828 (prin1-to-string failure)))))
2830 (defun message-send-mail-partially ()
2831 "Sendmail as message/partial."
2832 ;; replace the header delimiter with a blank line
2833 (goto-char (point-min))
2835 (concat "^" (regexp-quote mail-header-separator) "\n"))
2836 (replace-match "\n")
2837 (run-hooks 'message-send-mail-hook)
2838 (let ((p (goto-char (point-min)))
2839 (tembuf (message-generate-new-buffer-clone-locals " message temp"))
2840 (curbuf (current-buffer))
2841 (id (message-make-message-id)) (n 1)
2842 plist total header required-mail-headers)
2844 (if (< (point-max) (+ p message-send-mail-partially-limit))
2845 (goto-char (point-max))
2846 (goto-char (+ p message-send-mail-partially-limit))
2848 (if (<= (point) p) (forward-line 1))) ;; In case of bad message.
2851 (setq total (length plist))
2852 (push (point-max) plist)
2853 (setq plist (nreverse plist))
2856 (setq p (pop plist))
2859 (copy-to-buffer tembuf p (car plist))
2861 (goto-char (point-min))
2864 (goto-char (point-min))
2865 (narrow-to-region (point) (point))
2868 (setq header (buffer-substring (point-min) (point)))
2869 (goto-char (point-min))
2870 (narrow-to-region (point) (point))
2872 (message-remove-header "Mime-Version")
2873 (message-remove-header "Content-Type")
2874 (message-remove-header "Content-Transfer-Encoding")
2875 (message-remove-header "Message-ID")
2876 (message-remove-header "Lines")
2877 (goto-char (point-max))
2878 (insert "Mime-Version: 1.0\n")
2879 (setq header (buffer-substring (point-min) (point-max))))
2880 (goto-char (point-max))
2881 (insert (format "Content-Type: message/partial; id=\"%s\"; number=%d; total=%d\n"
2883 (let ((mail-header-separator ""))
2884 (when (memq 'Message-ID message-required-mail-headers)
2885 (insert "Message-ID: " (message-make-message-id) "\n"))
2886 (when (memq 'Lines message-required-mail-headers)
2887 (let ((mail-header-separator ""))
2888 (insert "Lines: " (message-make-lines) "\n")))
2889 (message-goto-subject)
2891 (insert (format " (%d/%d)" n total))
2892 (goto-char (point-max))
2895 (mm-with-unibyte-current-buffer
2896 (funcall message-send-mail-function)))
2898 (setq p (pop plist))
2900 (kill-buffer tembuf))))
2902 (defun message-send-mail (&optional arg)
2903 (require 'mail-utils)
2904 (let* ((tembuf (message-generate-new-buffer-clone-locals " message temp"))
2905 (case-fold-search nil)
2906 (news (message-news-p))
2907 (message-this-is-mail t)
2910 (message-narrow-to-headers)
2911 ;; Insert some headers.
2912 (let ((message-deletable-headers
2913 (if news nil message-deletable-headers)))
2914 (message-generate-headers message-required-mail-headers))
2915 ;; Let the user do all of the above.
2916 (run-hooks 'message-header-hook))
2917 (if (not (message-check-mail-syntax))
2925 (insert-buffer message-encoding-buffer)
2926 ;; Remove some headers.
2928 (message-narrow-to-headers)
2929 ;; We Semi-gnus people have no use for it.
2930 ;; ;; We (re)generate the Lines header.
2931 ;; (when (memq 'Lines message-required-mail-headers)
2932 ;; (message-generate-headers '(Lines)))
2933 ;; Remove some headers.
2934 (message-remove-header message-ignored-mail-headers t))
2935 (goto-char (point-max))
2936 ;; require one newline at the end.
2937 (or (= (preceding-char) ?\n)
2941 (message-narrow-to-headers)
2943 (or (message-fetch-field "cc")
2944 (message-fetch-field "to"))
2945 (let ((ct (mime-read-Content-Type)))
2946 (and (eq 'text (cdr (assq 'type ct)))
2947 (eq 'plain (cdr (assq 'subtype ct)))))))
2948 (message-insert-courtesy-copy))
2949 (setq failure (message-maybe-split-and-send-mail)))
2950 (kill-buffer tembuf))
2951 (set-buffer message-edit-buffer)
2954 (message "Couldn't send message via mail: %s" failure)
2956 (push 'mail message-sent-message-via)))))
2958 (defun message-send-mail-with-sendmail ()
2959 "Send off the prepared buffer with sendmail."
2960 (let ((errbuf (if message-interactive
2961 (message-generate-new-buffer-clone-locals
2964 resend-to-addresses delimline)
2965 (let ((case-fold-search t))
2967 (message-narrow-to-headers)
2968 (setq resend-to-addresses (message-fetch-field "resent-to")))
2969 ;; Change header-delimiter to be what sendmail expects.
2970 (goto-char (point-min))
2972 (concat "^" (regexp-quote mail-header-separator) "\n"))
2973 (replace-match "\n")
2975 (setq delimline (point-marker))
2976 (run-hooks 'message-send-mail-hook)
2977 ;; Insert an extra newline if we need it to work around
2978 ;; Sun's bug that swallows newlines.
2979 (goto-char (1+ delimline))
2980 (when (eval message-mailer-swallows-blank-line)
2982 (when message-interactive
2986 (let ((default-directory "/"))
2988 (apply 'call-process-region
2989 (append (list (point-min) (point-max)
2990 (if (boundp 'sendmail-program)
2992 "/usr/lib/sendmail")
2993 nil errbuf nil "-oi")
2994 ;; Always specify who from,
2995 ;; since some systems have broken sendmails.
2996 ;; But some systems are more broken with -f, so
2997 ;; we'll let users override this.
2998 (if (null message-sendmail-f-is-evil)
2999 (list "-f" (message-make-address)))
3000 ;; These mean "report errors by mail"
3001 ;; and "deliver in background".
3002 (if (null message-interactive) '("-oem" "-odb"))
3003 ;; Get the addresses from the message
3004 ;; unless this is a resend.
3005 ;; We must not do that for a resend
3006 ;; because we would find the original addresses.
3007 ;; For a resend, include the specific addresses.
3008 (if resend-to-addresses
3009 (list resend-to-addresses)
3011 (when message-interactive
3014 (goto-char (point-min))
3015 (while (re-search-forward "\n\n* *" nil t)
3016 (replace-match "; "))
3017 (if (not (zerop (buffer-size)))
3018 (error "Sending...failed to %s"
3019 (buffer-substring (point-min) (point-max)))))
3020 (when (bufferp errbuf)
3021 (kill-buffer errbuf)))))
3023 (defun message-send-mail-with-qmail ()
3024 "Pass the prepared message buffer to qmail-inject.
3025 Refer to the documentation for the variable `message-send-mail-function'
3026 to find out how to use this."
3027 ;; replace the header delimiter with a blank line
3028 (goto-char (point-min))
3030 (concat "^" (regexp-quote mail-header-separator) "\n"))
3031 (replace-match "\n")
3033 (run-hooks 'message-send-mail-hook)
3038 'call-process-region 1 (point-max) message-qmail-inject-program
3040 ;; qmail-inject's default behaviour is to look for addresses on the
3041 ;; command line; if there're none, it scans the headers.
3042 ;; yes, it does The Right Thing w.r.t. Resent-To and it's kin.
3044 ;; in general, ALL of qmail-inject's defaults are perfect for simply
3045 ;; reading a formatted (i. e., at least a To: or Resent-To header)
3046 ;; message from stdin.
3048 ;; qmail also has the advantage of not having been raped by
3049 ;; various vendors, so we don't have to allow for that, either --
3050 ;; compare this with message-send-mail-with-sendmail and weep
3051 ;; for sendmail's lost innocence.
3053 ;; all this is way cool coz it lets us keep the arguments entirely
3054 ;; free for -inject-arguments -- a big win for the user and for us
3055 ;; since we don't have to play that double-guessing game and the user
3056 ;; gets full control (no gestapo'ish -f's, for instance). --sj
3057 message-qmail-inject-args))
3058 ;; qmail-inject doesn't say anything on it's stdout/stderr,
3059 ;; we have to look at the retval instead
3061 (1 (error "qmail-inject reported permanent failure"))
3062 (111 (error "qmail-inject reported transient failure"))
3063 ;; should never happen
3064 (t (error "qmail-inject reported unknown failure"))))
3066 (defun message-send-mail-with-mh ()
3067 "Send the prepared message buffer with mh."
3068 (let ((mh-previous-window-config nil)
3069 (name (mh-new-draft-name)))
3070 (setq buffer-file-name name)
3071 ;; MH wants to generate these headers itself.
3072 (when message-mh-deletable-headers
3073 (let ((headers message-mh-deletable-headers))
3075 (goto-char (point-min))
3076 (and (re-search-forward
3077 (concat "^" (symbol-name (car headers)) ": *") nil t)
3078 (message-delete-line))
3080 (run-hooks 'message-send-mail-hook)
3081 ;; Pass it on to mh.
3084 (defun message-send-mail-with-smtp ()
3085 "Send off the prepared buffer with SMTP."
3086 (require 'smtp) ; XXX
3087 (let ((case-fold-search t)
3090 (message-narrow-to-headers)
3092 ;; XXX: Should be replaced by better one.
3093 (smtp-deduce-address-list (current-buffer)
3094 (point-min) (point-max)))
3095 ;; Remove BCC lines.
3096 (message-remove-header "bcc"))
3097 ;; replace the header delimiter with a blank line.
3098 (goto-char (point-min))
3100 (concat "^" (regexp-quote mail-header-separator) "\n"))
3101 (replace-match "\n")
3103 (run-hooks 'message-send-mail-hook)
3105 (let ((result (smtp-via-smtp user-mail-address
3108 (unless (eq result t)
3109 (error "Sending failed; " result)))
3110 (error "Sending failed; no recipients"))))
3112 (defsubst message-maybe-split-and-send-news (method)
3113 "Split a message if necessary, and send it via news.
3114 Returns nil if sending succeeded, returns t if sending failed.
3115 This sub function is for exclusive use of `message-send-news'."
3116 (let ((mime-edit-split-ignored-field-regexp
3117 mime-edit-split-ignored-field-regexp)
3118 (case-fold-search t))
3119 (while (string-match "Message-ID" mime-edit-split-ignored-field-regexp)
3120 (setq mime-edit-split-ignored-field-regexp
3121 (concat (substring mime-edit-split-ignored-field-regexp
3122 0 (match-beginning 0))
3123 "Hey_MIME-Edit,_there_is_an_inviolable_Message_ID"
3124 "_so_don't_rape_it!"
3125 (substring mime-edit-split-ignored-field-regexp
3128 (catch 'message-sending-news-failure
3129 (mime-edit-maybe-split-and-send
3134 (std11-narrow-to-header mail-header-separator)
3135 (goto-char (point-min))
3136 (when (re-search-forward "^Message-ID:" nil t)
3137 (delete-region (match-end 0) (std11-field-end))
3138 (insert " " (message-make-message-id))))
3139 (unless (funcall message-send-news-function method)
3140 (throw 'message-sending-news-failure t)))))
3142 (not (funcall message-send-news-function method)))))
3144 (defun message-send-news (&optional arg)
3145 (let* ((tembuf (message-generate-new-buffer-clone-locals " *message temp*"))
3146 (case-fold-search nil)
3147 (method (if (message-functionp message-post-method)
3148 (funcall message-post-method arg)
3149 message-post-method))
3150 (group-name-charset (gnus-group-name-charset method ""))
3151 (message-syntax-checks
3153 (cons '(existing-newsgroups . disabled)
3154 message-syntax-checks)
3155 message-syntax-checks))
3156 (message-this-is-news t)
3159 (message-narrow-to-headers)
3160 ;; Insert some headers.
3161 (message-generate-headers message-required-news-headers)
3162 ;; Let the user do all of the above.
3163 (run-hooks 'message-header-hook))
3164 (if group-name-charset
3165 (setq message-syntax-checks
3166 (cons '(valid-newsgroups . disabled)
3167 message-syntax-checks)))
3168 (message-cleanup-headers)
3169 (if (not (message-check-news-syntax))
3174 (buffer-disable-undo)
3176 (insert-buffer message-encoding-buffer)
3177 ;; Remove some headers.
3179 (message-narrow-to-headers)
3180 ;; We Semi-gnus people have no use for it.
3181 ;; ;; We (re)generate the Lines header.
3182 ;; (when (memq 'Lines message-required-mail-headers)
3183 ;; (message-generate-headers '(Lines)))
3184 ;; Remove some headers.
3185 (message-remove-header message-ignored-news-headers t))
3186 (goto-char (point-max))
3187 ;; require one newline at the end.
3188 (or (= (preceding-char) ?\n)
3190 (setq result (message-maybe-split-and-send-news method)))
3191 (kill-buffer tembuf))
3192 (set-buffer message-edit-buffer)
3195 (message "Couldn't send message via news: %s"
3196 (nnheader-get-report (car method)))
3198 (push 'news message-sent-message-via)))))
3200 ;; 1997-09-29 by MORIOKA Tomohiko
3201 (defun message-send-news-with-gnus (method)
3202 (let ((case-fold-search t))
3203 ;; Remove the delimiter.
3204 (goto-char (point-min))
3206 (concat "^" (regexp-quote mail-header-separator) "\n"))
3207 (replace-match "\n")
3209 (run-hooks 'message-send-news-hook)
3210 (gnus-open-server method)
3211 (gnus-request-post method)
3215 ;;; Header generation & syntax checking.
3218 (defun message-check-element (type)
3219 "Returns non-nil if this type is not to be checked."
3220 (if (eq message-syntax-checks 'dont-check-for-anything-just-trust-me)
3222 (let ((able (assq type message-syntax-checks)))
3224 (eq (cdr able) 'disabled)))))
3226 (defun message-check-news-syntax ()
3227 "Check the syntax of the message."
3232 ;; We narrow to the headers and check them first.
3235 (message-narrow-to-headers)
3236 (message-check-news-header-syntax)))
3239 (set-buffer message-edit-buffer)
3240 (message-check-news-body-syntax))))))
3242 (defun message-check-news-header-syntax ()
3244 ;; Check Newsgroups header.
3245 (message-check 'newsgroups
3246 (let ((group (message-fetch-field "newsgroups")))
3249 (not (string-match "\\`[ \t]*\\'" group)))
3252 "The newsgroups field is empty or missing. Posting is denied.")))))
3253 ;; Check the Subject header.
3254 (message-check 'subject
3255 (let* ((case-fold-search t)
3256 (subject (message-fetch-field "subject")))
3259 (not (string-match "\\`[ \t]*\\'" subject)))
3262 "The subject field is empty or missing. Posting is denied.")))))
3263 ;; Check for commands in Subject.
3264 (message-check 'subject-cmsg
3265 (if (string-match "^cmsg " (message-fetch-field "subject"))
3267 "The control code \"cmsg\" is in the subject. Really post? ")
3269 ;; Check for multiple identical headers.
3270 (message-check 'multiple-headers
3272 (while (and (not found)
3273 (re-search-forward "^[^ \t:]+: " nil t))
3275 (or (re-search-forward
3280 (match-beginning 0) (- (match-end 0) 2))))
3285 (y-or-n-p (format "Multiple %s headers. Really post? " found))
3287 ;; Check for Version and Sendsys.
3288 (message-check 'sendsys
3289 (if (re-search-forward "^Sendsys:\\|^Version:" nil t)
3291 (format "The article contains a %s command. Really post? "
3292 (buffer-substring (match-beginning 0)
3293 (1- (match-end 0)))))
3295 ;; See whether we can shorten Followup-To.
3296 (message-check 'shorten-followup-to
3297 (let ((newsgroups (message-fetch-field "newsgroups"))
3298 (followup-to (message-fetch-field "followup-to"))
3300 (when (and newsgroups
3301 (string-match "," newsgroups)
3306 (setq to (completing-read
3307 "Followups to: (default all groups) "
3308 (mapcar (lambda (g) (list g))
3310 (message-tokenize-header
3312 (goto-char (point-min))
3313 (insert "Followup-To: " to "\n"))
3315 ;; Check "Shoot me".
3316 (message-check 'shoot
3317 (if (re-search-forward
3318 "Message-ID.*.i-did-not-set--mail-host-address--so-shoot-me" nil t)
3319 (y-or-n-p "You appear to have a misconfigured system. Really post? ")
3321 ;; Check for Approved.
3322 (message-check 'approved
3323 (if (re-search-forward "^Approved:" nil t)
3324 (y-or-n-p "The article contains an Approved header. Really post? ")
3326 ;; Check the Message-ID header.
3327 (message-check 'message-id
3328 (let* ((case-fold-search t)
3329 (message-id (message-fetch-field "message-id" t)))
3330 (or (not message-id)
3331 ;; Is there an @ in the ID?
3332 (and (string-match "@" message-id)
3333 ;; Is there a dot in the ID?
3334 (string-match "@[^.]*\\." message-id)
3335 ;; Does the ID end with a dot?
3336 (not (string-match "\\.>" message-id)))
3338 (format "The Message-ID looks strange: \"%s\". Really post? "
3340 ;; Check the Newsgroups & Followup-To headers.
3341 (message-check 'existing-newsgroups
3342 (let* ((case-fold-search t)
3343 (newsgroups (message-fetch-field "newsgroups"))
3344 (followup-to (message-fetch-field "followup-to"))
3345 (groups (message-tokenize-header
3347 (concat newsgroups "," followup-to)
3349 (hashtb (and (boundp 'gnus-active-hashtb)
3350 gnus-active-hashtb))
3352 (if (or (not hashtb)
3353 (not (boundp 'gnus-read-active-file))
3354 (not gnus-read-active-file)
3355 (eq gnus-read-active-file 'some))
3358 (when (and (not (boundp (intern (car groups) hashtb)))
3359 (not (equal (car groups) "poster")))
3360 (push (car groups) errors))
3366 "Really post to %s unknown group%s: %s "
3367 (if (= (length errors) 1) "this" "these")
3368 (if (= (length errors) 1) "" "s")
3369 (mapconcat 'identity errors ", ")))))))
3370 ;; Check the Newsgroups & Followup-To headers for syntax errors.
3371 (message-check 'valid-newsgroups
3372 (let ((case-fold-search t)
3373 (headers '("Newsgroups" "Followup-To"))
3375 (while (and headers (not error))
3376 (when (setq header (mail-fetch-field (car headers)))
3380 "\\`\\([-+_&.a-zA-Z0-9]+\\)?\\(,[-+_&.a-zA-Z0-9]+\\)*\\'"
3385 (not (string-match "\\.\\'\\|\\.\\." g)))
3386 (message-tokenize-header header ","))))
3393 (format "The %s header looks odd: \"%s\". Really post? "
3394 (car headers) header)))))
3395 (message-check 'repeated-newsgroups
3396 (let ((case-fold-search t)
3397 (headers '("Newsgroups" "Followup-To"))
3398 header error groups group)
3401 (when (setq header (mail-fetch-field (pop headers)))
3402 (setq groups (message-tokenize-header header ","))
3403 (while (setq group (pop groups))
3404 (when (member group groups)
3410 (format "Group %s is repeated in headers. Really post? " error)))))
3411 ;; Check the From header.
3412 (message-check 'from
3413 (let* ((case-fold-search t)
3414 (from (message-fetch-field "from"))
3418 (message "There is no From line. Posting is denied.")
3420 ((or (not (string-match
3422 (setq ad (nth 1 (mail-extract-address-components
3423 from))))) ;larsi@ifi
3424 (string-match "\\.\\." ad) ;larsi@ifi..uio
3425 (string-match "@\\." ad) ;larsi@.ifi.uio
3426 (string-match "\\.$" ad) ;larsi@ifi.uio.
3427 (not (string-match "^[^@]+@[^@]+$" ad)) ;larsi.ifi.uio
3428 (string-match "(.*).*(.*)" from)) ;(lars) (lars)
3430 "Denied posting -- the From looks strange: \"%s\"." from)
3434 (defun message-check-news-body-syntax ()
3436 ;; Check for long lines.
3437 (message-check 'long-lines
3438 (goto-char (point-min))
3440 (concat "^" (regexp-quote mail-header-separator) "$"))
3444 (< (current-column) 80))
3445 (zerop (forward-line 1))))
3449 "You have lines longer than 79 characters. Really post? ")))
3450 ;; Check whether the article is empty.
3451 (message-check 'empty
3452 (goto-char (point-min))
3454 (concat "^" (regexp-quote mail-header-separator) "$"))
3457 (goto-char (point-max))
3458 (re-search-backward message-signature-separator nil t)
3460 (or (re-search-backward "[^ \n\t]" b t)
3461 (y-or-n-p "Empty article. Really post? "))))
3462 ;; Check for control characters.
3463 (message-check 'control-chars
3464 (if (re-search-forward "[\000-\007\013\015-\032\034-\037\200-\237]" nil t)
3466 "The article contains control characters. Really post? ")
3468 ;; Check 8bit characters.
3469 (message-check '8bit
3470 (message-check-8bit))
3471 ;; Check excessive size.
3472 (message-check 'size
3473 (if (> (buffer-size) 60000)
3475 (format "The article is %d octets long. Really post? "
3478 ;; Check whether any new text has been added.
3479 (message-check 'new-text
3481 (not message-checksum)
3482 (not (eq (message-checksum) message-checksum))
3484 "It looks like no new text has been added. Really post? ")))
3485 ;; Check the length of the signature.
3486 (message-check 'signature
3487 (goto-char (point-max))
3488 (if (> (count-lines (point) (point-max)) 5)
3491 "Your .sig is %d lines; it should be max 4. Really post? "
3492 (1- (count-lines (point) (point-max)))))
3494 ;; Ensure that text follows last quoted portion.
3495 (message-check 'quoting-style
3496 (goto-char (point-max))
3497 (let ((no-problem t))
3498 (when (search-backward-regexp "^>[^\n]*\n>" nil t)
3499 (setq no-problem nil)
3501 (when (and (not (eolp)) (looking-at "[^> \t]"))
3502 (setq no-problem t))
3506 (y-or-n-p "Your text should follow quoted text. Really post? "))))))
3508 (defun message-check-mail-syntax ()
3509 "Check the syntax of the message."
3514 ;; We narrow to the headers and check them first.
3517 (message-narrow-to-headers)
3518 (message-check-mail-header-syntax)))
3521 (set-buffer message-edit-buffer)
3522 (message-check-mail-body-syntax))))))
3524 (defun message-check-mail-header-syntax ()
3527 (defun message-check-mail-body-syntax ()
3529 ;; Check 8bit characters.
3530 (message-check '8bit
3531 (message-check-8bit)
3534 (defun message-check-8bit ()
3535 "Check the article contains 8bit characters."
3537 (set-buffer message-encoding-buffer)
3538 (message-narrow-to-headers)
3539 (let* ((case-fold-search t)
3540 (field-value (message-fetch-field "content-transfer-encoding")))
3541 (if (and field-value
3542 (member (downcase field-value) message-8bit-encoding-list))
3545 (set-buffer (get-buffer-create " message syntax"))
3547 (goto-char (point-min))
3548 (set-buffer-multibyte nil)
3549 (insert-buffer message-encoding-buffer)
3550 (goto-char (point-min))
3551 (if (re-search-forward "[^\x00-\x7f]" nil t)
3553 "The article contains 8bit characters. Really post? ")
3556 (defun message-checksum ()
3557 "Return a \"checksum\" for the current buffer."
3560 (goto-char (point-min))
3562 (concat "^" (regexp-quote mail-header-separator) "$"))
3564 (when (not (looking-at "[ \t\n]"))
3565 (setq sum (logxor (ash sum 1) (if (natnump sum) 0 1)
3570 (defun message-do-fcc ()
3571 "Process Fcc headers in the current buffer."
3572 (let ((case-fold-search t)
3573 (coding-system-for-write 'raw-text)
3574 (output-coding-system 'raw-text)
3577 (set-buffer (get-buffer-create " *message temp*"))
3579 (insert-buffer-substring message-encoding-buffer)
3581 (message-narrow-to-headers)
3582 (while (setq file (message-fetch-field "fcc"))
3584 (message-remove-header "fcc" nil t)))
3585 (goto-char (point-min))
3586 (re-search-forward (concat "^" (regexp-quote mail-header-separator) "$"))
3587 (replace-match "" t t)
3588 ;; Process FCC operations.
3590 (setq file (pop list))
3591 (if (string-match "^[ \t]*|[ \t]*\\(.*\\)[ \t]*$" file)
3592 ;; Pipe the article to the program in question.
3593 (call-process-region (point-min) (point-max) shell-file-name
3594 nil nil nil shell-command-switch
3595 (match-string 1 file))
3596 ;; Save the article.
3597 (setq file (expand-file-name file))
3598 (unless (file-exists-p (file-name-directory file))
3599 (make-directory (file-name-directory file) t))
3600 (if (and message-fcc-handler-function
3601 (not (eq message-fcc-handler-function 'rmail-output)))
3602 (funcall message-fcc-handler-function file)
3603 (if (and (file-readable-p file) (mail-file-babyl-p file))
3604 (rmail-output file 1 nil t)
3605 (let ((mail-use-rfc822 t))
3606 (rmail-output file 1 t t))))))
3607 (kill-buffer (current-buffer)))))
3609 (defun message-output (filename)
3610 "Append this article to Unix/babyl mail file.."
3611 (if (and (file-readable-p filename)
3612 (mail-file-babyl-p filename))
3613 (gnus-output-to-rmail filename t)
3614 (gnus-output-to-mail filename t)))
3616 (defun message-cleanup-headers ()
3617 "Do various automatic cleanups of the headers."
3618 ;; Remove empty lines in the header.
3620 (message-narrow-to-headers)
3621 ;; Remove blank lines.
3622 (while (re-search-forward "^[ \t]*\n" nil t)
3623 (replace-match "" t t))
3625 ;; Correct Newsgroups and Followup-To headers: Change sequence of
3626 ;; spaces to comma and eliminate spaces around commas. Eliminate
3627 ;; embedded line breaks.
3628 (goto-char (point-min))
3629 (while (re-search-forward "^\\(Newsgroups\\|Followup-To\\): +" nil t)
3633 (if (re-search-forward "^[^ \t]" nil t)
3637 (goto-char (point-min))
3638 (while (re-search-forward "\n[ \t]+" nil t)
3639 (replace-match " " t t)) ;No line breaks (too confusing)
3640 (goto-char (point-min))
3641 (while (re-search-forward "[ \t\n]*,[ \t\n]*\\|[ \t]+" nil t)
3642 (replace-match "," t t))
3643 (goto-char (point-min))
3644 ;; Remove trailing commas.
3645 (when (re-search-forward ",+$" nil t)
3646 (replace-match "" t t))))))
3648 (defun message-make-date (&optional now)
3649 "Make a valid data header.
3650 If NOW, use that time instead."
3651 (let* ((now (or now (current-time)))
3652 (zone (nth 8 (decode-time now)))
3656 (setq zone (- zone)))
3658 (format-time-string "%d" now)
3659 ;; The month name of the %b spec is locale-specific. Pfff.
3661 (capitalize (car (rassoc (nth 4 (decode-time now))
3662 parse-time-months))))
3663 (format-time-string "%Y %H:%M:%S " now)
3664 ;; We do all of this because XEmacs doesn't have the %z spec.
3665 (format "%s%02d%02d" sign (/ zone 3600) (/ (% zone 3600) 60)))))
3667 (defun message-make-followup-subject (subject)
3668 "Make a followup Subject."
3670 ((and (eq message-use-subject-re 'guess)
3671 (string-match message-subject-encoded-re-regexp subject))
3673 (message-use-subject-re
3674 (concat "Re: " (message-strip-subject-re subject)))
3677 (defun message-make-message-id ()
3678 "Make a unique Message-ID."
3679 (concat "<" (message-unique-id)
3680 (let ((psubject (save-excursion (message-fetch-field "subject")))
3682 (save-excursion (message-fetch-field "supersedes"))))
3684 (and message-reply-headers
3685 (mail-header-references message-reply-headers)
3686 (mail-header-subject message-reply-headers)
3688 (mail-header-subject message-reply-headers)
3690 (message-strip-subject-re
3691 (mail-header-subject message-reply-headers))
3692 (message-strip-subject-re psubject))))
3694 (string-match "_-_@" psupersedes)))
3696 "@" (message-make-fqdn) ">"))
3698 (defvar message-unique-id-char nil)
3700 ;; If you ever change this function, make sure the new version
3701 ;; cannot generate IDs that the old version could.
3702 ;; You might for example insert a "." somewhere (not next to another dot
3703 ;; or string boundary), or modify the "fsf" string.
3704 (defun message-unique-id ()
3705 ;; Don't use microseconds from (current-time), they may be unsupported.
3706 ;; Instead we use this randomly inited counter.
3707 (setq message-unique-id-char
3708 (% (1+ (or message-unique-id-char (logand (random t) (1- (lsh 1 20)))))
3709 ;; (current-time) returns 16-bit ints,
3710 ;; and 2^16*25 just fits into 4 digits i base 36.
3712 (let ((tm (current-time)))
3714 (if (memq system-type '(ms-dos emx vax-vms))
3715 (let ((user (downcase (user-login-name))))
3716 (while (string-match "[^a-z0-9_]" user)
3717 (aset user (match-beginning 0) ?_))
3719 (message-number-base36 (user-uid) -1))
3720 (message-number-base36 (+ (car tm)
3721 (lsh (% message-unique-id-char 25) 16)) 4)
3722 (message-number-base36 (+ (nth 1 tm)
3723 (lsh (/ message-unique-id-char 25) 16)) 4)
3724 ;; Append the newsreader name, because while the generated
3725 ;; ID is unique to this newsreader, other newsreaders might
3726 ;; otherwise generate the same ID via another algorithm.
3729 (defun message-number-base36 (num len)
3734 (concat (message-number-base36 (/ num 36) (1- len))
3735 (char-to-string (aref "zyxwvutsrqponmlkjihgfedcba9876543210"
3738 (defun message-make-organization ()
3739 "Make an Organization header."
3740 (let* ((organization
3741 (when message-user-organization
3742 (if (message-functionp message-user-organization)
3743 (funcall message-user-organization)
3744 message-user-organization))))
3746 (message-set-work-buffer)
3747 (cond ((stringp organization)
3748 (insert organization))
3749 ((and (eq t organization)
3750 message-user-organization-file
3751 (file-exists-p message-user-organization-file))
3752 (insert-file-contents message-user-organization-file)))
3753 (goto-char (point-min))
3754 (while (re-search-forward "[\t\n]+" nil t)
3755 (replace-match "" t t))
3756 (unless (zerop (buffer-size))
3759 (defun message-make-lines ()
3760 "Count the number of lines and return numeric string."
3764 (goto-char (point-min))
3766 (concat "^" (regexp-quote mail-header-separator) "$"))
3768 (int-to-string (count-lines (point) (point-max))))))
3770 (defun message-make-in-reply-to ()
3771 "Return the In-Reply-To header for this message."
3772 (when message-reply-headers
3773 (let ((mid (mail-header-message-id message-reply-headers))
3774 (from (mail-header-from message-reply-headers))
3775 (date (mail-header-date message-reply-headers)))
3779 (let ((pair (std11-extract-address-components from)))
3781 (or (car pair) (cadr pair))
3783 (if (or (not date) (string= date ""))
3784 "(unknown date)" date)
3787 (defun message-make-distribution ()
3788 "Make a Distribution header."
3789 (let ((orig-distribution (message-fetch-reply-field "distribution")))
3790 (cond ((message-functionp message-distribution-function)
3791 (funcall message-distribution-function))
3792 (t orig-distribution))))
3794 (defun message-make-expires ()
3795 "Return an Expires header based on `message-expires'."
3796 (let ((current (current-time))
3797 (future (* 1.0 message-expires 60 60 24)))
3798 ;; Add the future to current.
3799 (setcar current (+ (car current) (round (/ future (expt 2 16)))))
3800 (setcar (cdr current) (+ (nth 1 current) (% (round future) (expt 2 16))))
3801 (message-make-date current)))
3803 (defun message-make-path ()
3805 (let ((login-name (user-login-name)))
3806 (cond ((null message-user-path)
3807 (concat (system-name) "!" login-name))
3808 ((stringp message-user-path)
3809 ;; Support GENERICPATH. Suggested by vixie@decwrl.dec.com.
3810 (concat message-user-path "!" login-name))
3813 (defun message-make-from ()
3814 "Make a From header."
3815 (let* ((style message-from-style)
3816 (login (message-make-address))
3818 (or (and (boundp 'user-full-name)
3821 (when (string= fullname "&")
3822 (setq fullname (user-login-name)))
3824 (message-set-work-buffer)
3827 (equal fullname ""))
3829 ((or (eq style 'angles)
3830 (and (not (eq style 'parens))
3831 ;; Use angles if no quoting is needed, or if parens would
3832 ;; need quoting too.
3833 (or (not (string-match "[^- !#-'*+/-9=?A-Z^-~]" fullname))
3834 (let ((tmp (concat fullname nil)))
3835 (while (string-match "([^()]*)" tmp)
3836 (aset tmp (match-beginning 0) ?-)
3837 (aset tmp (1- (match-end 0)) ?-))
3838 (string-match "[\\()]" tmp)))))
3840 (goto-char (point-min))
3841 ;; Look for a character that cannot appear unquoted
3842 ;; according to RFC 822.
3843 (when (re-search-forward "[^- !#-'*+/-9=?A-Z^-~]" nil 1)
3844 ;; Quote fullname, escaping specials.
3845 (goto-char (point-min))
3847 (while (re-search-forward "[\"\\]" nil 1)
3848 (replace-match "\\\\\\&" t))
3850 (insert " <" login ">"))
3851 (t ; 'parens or default
3853 (let ((fullname-start (point)))
3855 (goto-char fullname-start)
3856 ;; RFC 822 says \ and nonmatching parentheses
3857 ;; must be escaped in comments.
3858 ;; Escape every instance of ()\ ...
3859 (while (re-search-forward "[()\\]" nil 1)
3860 (replace-match "\\\\\\&" t))
3861 ;; ... then undo escaping of matching parentheses,
3862 ;; including matching nested parentheses.
3863 (goto-char fullname-start)
3864 (while (re-search-forward
3865 "\\(\\=\\|[^\\]\\(\\\\\\\\\\)*\\)\\\\(\\(\\([^\\]\\|\\\\\\\\\\)*\\)\\\\)"
3867 (replace-match "\\1(\\3)" t)
3868 (goto-char fullname-start)))
3872 (defun message-make-sender ()
3873 "Return the \"real\" user address.
3874 This function tries to ignore all user modifications, and
3875 give as trustworthy answer as possible."
3876 (concat (user-login-name) "@" (system-name)))
3878 (defun message-make-address ()
3879 "Make the address of the user."
3880 (or (message-user-mail-address)
3881 (concat (user-login-name) "@" (message-make-domain))))
3883 (defun message-user-mail-address ()
3884 "Return the pertinent part of `user-mail-address'."
3885 (when user-mail-address
3886 (if (string-match " " user-mail-address)
3887 (nth 1 (std11-extract-address-components user-mail-address))
3888 user-mail-address)))
3890 (defun message-make-fqdn ()
3891 "Return user's fully qualified domain name."
3892 (let ((system-name (system-name))
3893 (user-mail (message-user-mail-address)))
3895 ((string-match "[^.]\\.[^.]" system-name)
3896 ;; `system-name' returned the right result.
3898 ;; Try `mail-host-address'.
3899 ((and (boundp 'mail-host-address)
3900 (stringp mail-host-address)
3901 (string-match "\\." mail-host-address))
3903 ;; We try `user-mail-address' as a backup.
3905 (string-match "\\." user-mail)
3906 (string-match "@\\(.*\\)\\'" user-mail))
3907 (match-string 1 user-mail))
3908 ;; Default to this bogus thing.
3910 (concat system-name ".i-did-not-set--mail-host-address--so-shoot-me")))))
3912 (defun message-make-host-name ()
3913 "Return the name of the host."
3914 (let ((fqdn (message-make-fqdn)))
3915 (string-match "^[^.]+\\." fqdn)
3916 (substring fqdn 0 (1- (match-end 0)))))
3918 (defun message-make-domain ()
3919 "Return the domain name."
3920 (or mail-host-address
3921 (message-make-fqdn)))
3923 ;; Dummy to avoid byte-compile warning.
3924 (defvar mule-version)
3925 (defvar emacs-beta-version)
3926 (defvar xemacs-codename)
3927 (defvar gnus-inviolable-extended-version)
3929 (defun message-make-user-agent ()
3930 "Return user-agent info if the value `message-user-agent' is non-nil. If the
3931 \"User-Agent\" field has already exist, it's value will be added in the return
3933 (when message-user-agent
3935 (goto-char (point-min))
3936 (let ((case-fold-search t)
3937 user-agent start p end)
3938 (if (re-search-forward "^User-Agent:[\t ]*" nil t)
3940 (setq start (match-beginning 0)
3942 end (std11-field-end)
3943 user-agent (buffer-substring-no-properties p end))
3944 (delete-region start (1+ end))
3945 (concat message-user-agent " " user-agent))
3946 message-user-agent)))))
3948 (defun message-generate-headers (headers)
3949 "Prepare article HEADERS.
3950 Headers already prepared in the buffer are not modified."
3952 (message-narrow-to-headers)
3953 (let* ((Date (message-make-date))
3954 (Message-ID (message-make-message-id))
3955 (Organization (message-make-organization))
3956 (From (message-make-from))
3957 (Path (message-make-path))
3960 (In-Reply-To (message-make-in-reply-to))
3962 (Distribution (message-make-distribution))
3963 (Lines (message-make-lines))
3964 (User-Agent (message-make-user-agent))
3965 (Expires (message-make-expires))
3966 (case-fold-search t)
3968 ;; First we remove any old generated headers.
3969 (let ((headers message-deletable-headers))
3970 (unless (buffer-modified-p)
3971 (setq headers (delq 'Message-ID (copy-sequence headers))))
3973 (goto-char (point-min))
3974 (and (re-search-forward
3975 (concat "^" (symbol-name (car headers)) ": *") nil t)
3976 (get-text-property (1+ (match-beginning 0)) 'message-deletable)
3977 (message-delete-line))
3979 ;; Go through all the required headers and see if they are in the
3980 ;; articles already. If they are not, or are empty, they are
3981 ;; inserted automatically - except for Subject, Newsgroups and
3984 (goto-char (point-min))
3985 (setq elem (pop headers))
3987 (if (eq (car elem) 'optional)
3988 (setq header (cdr elem))
3989 (setq header (car elem)))
3991 (when (or (not (re-search-forward
3995 (if (stringp header)
3997 (symbol-name header))))
4001 ;; The header was found. We insert a space after the
4002 ;; colon, if there is none.
4003 (if (/= (char-after) ? ) (insert " ") (forward-char 1))
4004 ;; Find out whether the header is empty...
4005 (looking-at "[ \t]*\n[^ \t]")))
4006 ;; So we find out what value we should insert.
4009 ((and (consp elem) (eq (car elem) 'optional))
4010 ;; This is an optional header. If the cdr of this
4011 ;; is something that is nil, then we do not insert
4013 (setq header (cdr elem))
4014 (or (and (fboundp (cdr elem)) (funcall (cdr elem)))
4015 (and (boundp (cdr elem)) (symbol-value (cdr elem)))))
4017 ;; The element is a cons. Either the cdr is a
4018 ;; string to be inserted verbatim, or it is a
4019 ;; function, and we insert the value returned from
4021 (or (and (stringp (cdr elem)) (cdr elem))
4022 (and (fboundp (cdr elem)) (funcall (cdr elem)))))
4023 ((and (boundp header) (symbol-value header))
4024 ;; The element is a symbol. We insert the value
4025 ;; of this symbol, if any.
4026 (symbol-value header))
4027 ((not (message-check-element header))
4028 ;; We couldn't generate a value for this header,
4029 ;; so we just ask the user.
4030 (read-from-minibuffer
4031 (format "Empty header for %s; enter value: " header)))))
4032 ;; Finally insert the header.
4034 (not (equal value "")))
4038 ;; This header didn't exist, so we insert it.
4039 (goto-char (point-max))
4040 (insert (if (stringp header) header (symbol-name header))
4045 ;; The value of this header was empty, so we clear
4046 ;; totally and insert the new value.
4047 (delete-region (point) (gnus-point-at-eol))
4051 ;; Add the deletable property to the headers that require it.
4052 (and (memq header message-deletable-headers)
4053 (progn (beginning-of-line) (looking-at "[^:]+: "))
4054 (add-text-properties
4055 (point) (match-end 0)
4056 '(message-deletable t face italic) (current-buffer)))))))
4057 ;; Insert new Sender if the From is strange.
4058 (let ((from (message-fetch-field "from"))
4059 (sender (message-fetch-field "sender"))
4060 (secure-sender (message-make-sender)))
4062 (not (message-check-element 'sender))
4065 (cadr (std11-extract-address-components from)))
4066 (downcase secure-sender)))
4071 (cadr (std11-extract-address-components sender)))
4072 (downcase secure-sender)))))
4073 (goto-char (point-min))
4074 ;; Rename any old Sender headers to Original-Sender.
4075 (when (re-search-forward "^\\(Original-\\)*Sender:" nil t)
4077 (insert "Original-")
4078 (beginning-of-line))
4079 (when (or (message-news-p)
4080 (string-match "@.+\\.." secure-sender))
4081 (insert "Sender: " secure-sender "\n")))))))
4083 (defun message-insert-courtesy-copy ()
4084 "Insert a courtesy message in mail copies of combined messages."
4088 (message-narrow-to-headers)
4089 (when (setq newsgroups (message-fetch-field "newsgroups"))
4090 (goto-char (point-max))
4091 (insert "Posted-To: " newsgroups "\n")))
4093 (when message-courtesy-message
4095 ((string-match "%s" message-courtesy-message)
4096 (insert (format message-courtesy-message newsgroups)))
4098 (insert message-courtesy-message)))))))
4101 ;;; Setting up a message buffer
4104 (defun message-fill-address (header value)
4106 (narrow-to-region (point) (point))
4107 (insert (capitalize (symbol-name header))
4109 (if (consp value) (car value) value)
4111 (narrow-to-region (point-min) (1- (point-max)))
4113 (goto-char (point-min))
4115 (skip-chars-forward "^,\"" (point-max))
4116 (if (or (eq (char-after) ?,)
4119 (if (and (> (current-column) 78)
4123 (looking-at "[ \t]*")
4124 (replace-match "\n " t t)))
4125 (setq last (1+ (point))))
4126 (setq quoted (not quoted)))
4129 (goto-char (point-max))
4133 (defun message-fill-references (header value)
4134 (insert (capitalize (symbol-name header))
4136 (std11-fill-msg-id-list-string
4137 (if (consp value) (car value) value))
4140 (defun message-fill-header (header value)
4141 (let ((begin (point))
4144 (insert (capitalize (symbol-name header))
4146 (if (consp value) (car value) value)
4149 (narrow-to-region begin (point))
4150 (fill-region-as-paragraph begin (point))
4151 ;; Tapdance around looong Message-IDs.
4153 (when (looking-at "[ \t]*$")
4154 (message-delete-line))
4156 (re-search-forward ":" nil t)
4157 (when (looking-at "\n[ \t]+")
4158 (replace-match " " t t))
4159 (goto-char (point-max)))))
4161 (defun message-shorten-1 (list cut surplus)
4162 ;; Cut SURPLUS elements out of LIST, beginning with CUTth one.
4163 (setcdr (nthcdr (- cut 2) list)
4164 (nthcdr (+ (- cut 2) surplus 1) list)))
4166 (defun message-shorten-references (header references)
4167 "Trim REFERENCES to be less than 31 Message-ID long, and fold them.
4168 If folding is disallowed, also check that the REFERENCES are less
4169 than 988 characters long, and if they are not, trim them until they are."
4176 (goto-char (point-min))
4177 ;; Cons a list of valid references.
4178 (while (re-search-forward "<[^>]+>" nil t)
4179 (push (match-string 0) refs))
4180 (setq refs (nreverse refs)
4181 count (length refs)))
4183 ;; If the list has more than MAXCOUNT elements, trim it by
4184 ;; removing the CUTth element and the required number of
4185 ;; elements that follow.
4186 (when (> count maxcount)
4187 (let ((surplus (- count maxcount)))
4188 (message-shorten-1 refs cut surplus)
4189 (decf count surplus)))
4191 ;; If folding is disallowed, make sure the total length (including
4192 ;; the spaces between) will be less than MAXSIZE characters.
4194 ;; Only disallow folding for News messages. At this point the headers
4195 ;; have not been generated, thus we use message-this-is-news directly.
4196 (when (and message-this-is-news message-cater-to-broken-inn)
4198 (totalsize (+ (apply #'+ (mapcar #'length refs))
4201 (ptr (nthcdr (1- cut) refs)))
4202 ;; Decide how many elements to cut off...
4203 (while (> totalsize maxsize)
4204 (decf totalsize (1+ (length (car ptr))))
4206 (setq ptr (cdr ptr)))
4209 (message-shorten-1 refs cut surplus))))
4211 ;; Finally, collect the references back into a string and insert
4212 ;; it into the buffer.
4213 (let ((refstring (mapconcat #'identity refs " ")))
4214 (if (and message-this-is-news message-cater-to-broken-inn)
4215 (insert (capitalize (symbol-name header)) ": "
4217 (message-fill-header header refstring)))))
4219 (defun message-position-point ()
4220 "Move point to where the user probably wants to find it."
4221 (message-narrow-to-headers)
4223 ((re-search-forward "^[^:]+:[ \t]*$" nil t)
4224 (search-backward ":" )
4227 (if (eq (char-after) ? )
4231 (goto-char (point-max))
4234 (unless (looking-at "$")
4238 (defun message-buffer-name (type &optional to group)
4239 "Return a new (unique) buffer name based on TYPE and TO."
4241 ;; Generate a new buffer name The Message Way.
4242 ((eq message-generate-new-buffers 'unique)
4243 (generate-new-buffer-name
4247 (or (car (std11-extract-address-components to))
4250 (if (and group (not (string= group ""))) (concat " on " group) "")
4252 ;; Check whether `message-generate-new-buffers' is a function,
4253 ;; and if so, call it.
4254 ((message-functionp message-generate-new-buffers)
4255 (funcall message-generate-new-buffers type to group))
4256 ((eq message-generate-new-buffers 'unsent)
4257 (generate-new-buffer-name
4258 (concat "*unsent " type
4261 (or (car (mail-extract-address-components to))
4264 (if (and group (not (string= group ""))) (concat " on " group) "")
4266 ;; Use standard name.
4268 (format "*%s message*" type))))
4270 (defmacro message-pop-to-buffer-1 (buffer)
4272 (let (special-display-buffer-names
4273 special-display-regexps
4274 same-window-buffer-names
4275 same-window-regexps)
4276 (pop-to-buffer ,buffer))
4277 (pop-to-buffer ,buffer)))
4279 (defun message-pop-to-buffer (name)
4280 "Pop to buffer NAME, and warn if it already exists and is modified."
4281 (let ((buffer (get-buffer name))
4282 (pop-up-frames (and (or (static-if (featurep 'xemacs)
4283 (device-on-window-system-p)
4285 (>= emacs-major-version 20))
4286 message-use-multi-frames)))
4288 (buffer-name buffer))
4290 (message-pop-to-buffer-1 buffer)
4291 (when (and (buffer-modified-p)
4293 "Message already being composed; erase? ")))
4294 (error "Message being composed")))
4295 (message-pop-to-buffer-1 name))
4299 (set (make-local-variable 'message-original-frame) (selected-frame)))))
4301 (defun message-do-send-housekeeping ()
4302 "Kill old message buffers."
4303 ;; We might have sent this buffer already. Delete it from the
4305 (setq message-buffer-list (delq (current-buffer) message-buffer-list))
4306 (while (and message-max-buffers
4308 (>= (length message-buffer-list) message-max-buffers))
4309 ;; Kill the oldest buffer -- unless it has been changed.
4310 (let ((buffer (pop message-buffer-list)))
4311 (when (and (buffer-name buffer)
4312 (not (buffer-modified-p buffer)))
4313 (kill-buffer buffer))))
4314 ;; Rename the buffer.
4315 (if message-send-rename-function
4316 (funcall message-send-rename-function)
4317 (when (string-match "\\`\\*\\(unsent \\)?" (buffer-name))
4319 (concat "*sent " (substring (buffer-name) (match-end 0))) t)))
4320 ;; Push the current buffer onto the list.
4321 (when message-max-buffers
4322 (setq message-buffer-list
4323 (nconc message-buffer-list (list (current-buffer))))))
4325 (defvar mc-modes-alist)
4326 (defun message-setup (headers &optional replybuffer actions)
4327 (when (and (boundp 'mc-modes-alist)
4328 (not (assq 'message-mode mc-modes-alist)))
4329 (push '(message-mode (encrypt . mc-encrypt-message)
4330 (sign . mc-sign-message))
4333 (setq message-send-actions actions))
4334 (setq message-reply-buffer
4335 (or (message-get-parameter 'reply-buffer)
4337 (goto-char (point-min))
4338 ;; Insert all the headers.
4341 (alist message-header-format-alist))
4343 (unless (assq (caar h) message-header-format-alist)
4344 (push (list (caar h)) alist))
4348 (delete-region (point) (progn (forward-line -1) (point)))
4349 (when message-default-headers
4350 (insert message-default-headers)
4351 (or (bolp) (insert ?\n)))
4355 (insert mail-header-separator "\n")
4359 (when (message-news-p)
4360 (when message-default-news-headers
4361 (insert message-default-news-headers)
4362 (or (bolp) (insert ?\n)))
4363 (when message-generate-headers-first
4364 (message-generate-headers
4367 (copy-sequence message-required-news-headers))))))
4368 (when (message-mail-p)
4369 (when message-default-mail-headers
4370 (insert message-default-mail-headers)
4371 (or (bolp) (insert ?\n)))
4372 (when message-generate-headers-first
4373 (message-generate-headers
4376 (copy-sequence message-required-mail-headers))))))
4377 (run-hooks 'message-signature-setup-hook)
4378 (message-insert-signature)
4380 (message-narrow-to-headers)
4381 (if message-alternative-emails
4382 (message-use-alternative-email-as-from))
4383 (run-hooks 'message-header-setup-hook))
4384 (set-buffer-modified-p nil)
4385 (setq buffer-undo-list nil)
4386 (run-hooks 'message-setup-hook)
4387 (message-position-point)
4390 (defun message-set-auto-save-file-name ()
4391 "Associate the message buffer with a file in the drafts directory."
4392 (when message-auto-save-directory
4394 (setq message-draft-article
4395 (nndraft-request-associate-buffer "drafts"))
4396 (setq buffer-file-name (expand-file-name "*message*"
4397 message-auto-save-directory))
4398 (setq buffer-auto-save-file-name (make-auto-save-file-name)))
4399 (clear-visited-file-modtime)
4400 (static-if (boundp 'MULE)
4401 (set-file-coding-system message-draft-coding-system)
4402 (setq buffer-file-coding-system message-draft-coding-system))))
4404 (defun message-disassociate-draft ()
4405 "Disassociate the message buffer from the drafts directory."
4406 (when message-draft-article
4407 (nndraft-request-expire-articles
4408 (list message-draft-article) "drafts" nil t)))
4410 (defun message-insert-headers ()
4411 "Generate the headers for the article."
4415 (message-narrow-to-headers)
4416 (when (message-news-p)
4417 (message-generate-headers
4420 (copy-sequence message-required-news-headers)))))
4421 (when (message-mail-p)
4422 (message-generate-headers
4425 (copy-sequence message-required-mail-headers))))))))
4430 ;;; Commands for interfacing with message
4434 (defun message-mail (&optional to subject
4435 other-headers continue switch-function
4436 yank-action send-actions)
4437 "Start editing a mail message to be sent.
4438 OTHER-HEADERS is an alist of header/value pairs."
4440 (let ((message-this-is-mail t))
4441 (message-pop-to-buffer (message-buffer-name "mail" to))
4444 `((To . ,(or to "")) (Subject . ,(or subject "")))
4445 (when other-headers other-headers)))))
4448 (defun message-news (&optional newsgroups subject)
4449 "Start editing a news article to be sent."
4451 (let ((message-this-is-news t))
4452 (message-pop-to-buffer (message-buffer-name "news" nil newsgroups))
4453 (message-setup `((Newsgroups . ,(or newsgroups ""))
4454 (Subject . ,(or subject ""))))))
4456 (defun message-get-reply-headers (wide &optional to-address)
4457 (let (follow-to mct never-mct from to cc reply-to mft)
4458 ;; Find all relevant headers we need.
4459 (setq from (message-fetch-field "from")
4460 to (message-fetch-field "to")
4461 cc (message-fetch-field "cc")
4462 mct (when message-use-mail-copies-to
4463 (message-fetch-field "mail-copies-to"))
4464 reply-to (when message-use-mail-reply-to
4465 (or (message-fetch-field "mail-reply-to")
4466 (message-fetch-field "reply-to")))
4467 mft (when (and (not to-address)
4469 message-use-mail-followup-to)
4470 (message-fetch-field "mail-followup-to")))
4472 ;; Handle special values of Mail-Copies-To.
4475 ((and (or (equal (downcase mct) "never")
4476 (equal (downcase mct) "nobody"))
4477 (or (not (eq message-use-mail-copies-to 'ask))
4479 (concat "Obey Mail-Copies-To: never? ") t "\
4480 You should normally obey the Mail-Copies-To: header.
4482 `Mail-Copies-To: never'
4483 directs you not to send your response to the author.")))
4486 ((and (or (equal (downcase mct) "always")
4487 (equal (downcase mct) "poster"))
4488 (or (not (eq message-use-mail-copies-to 'ask))
4490 (concat "Obey Mail-Copies-To: always? ") t "\
4491 You should normally obey the Mail-Copies-To: header.
4493 `Mail-Copies-To: always'
4494 sends a copy of your response to the author.")))
4495 (setq mct (or reply-to from)))
4496 ((and (eq message-use-mail-copies-to 'ask)
4499 (concat "Obey Mail-Copies-To: " mct " ? ") t "\
4500 You should normally obey the Mail-Copies-To: header.
4502 `Mail-Copies-To: " mct "'
4503 sends a copy of your response to " (if (string-match "," mct)
4504 "the specified addresses"
4505 "that address") ".")))
4508 ;; Handle Mail-Followup-To.
4510 (eq message-use-mail-followup-to 'ask)
4511 (not (message-y-or-n-p
4512 (concat "Obey Mail-Followup-To: " mft "? ") t "\
4513 You should normally obey the Mail-Followup-To: header.
4515 `Mail-Followup-To: " mft "'
4516 directs your response to " (if (string-match "," mft)
4517 "the specified addresses"
4518 "that address only") ".
4520 A typical situation where Mail-Followup-To is used is when the author thinks
4521 that further discussion should take place only in "
4522 (if (string-match "," mft)
4523 "the specified mailing lists"
4524 "that mailing list") ".")))
4530 (setq follow-to (list (cons 'To (or to-address reply-to mft from))))
4531 (when (and wide mct)
4532 (push (cons 'Cc mct) follow-to)))
4535 (message-set-work-buffer)
4537 (insert (or reply-to from "")))
4538 (insert (if mft (concat (if (bolp) "" ", ") mft "") ""))
4539 (insert (if to (concat (if (bolp) "" ", ") to "") ""))
4540 (insert (if mct (concat (if (bolp) "" ", ") mct) ""))
4541 (insert (if cc (concat (if (bolp) "" ", ") cc) ""))
4542 (goto-char (point-min))
4543 (while (re-search-forward "[ \t]+" nil t)
4544 (replace-match " " t t))
4545 ;; Remove addresses that match `rmail-dont-reply-to-names'.
4546 (let ((rmail-dont-reply-to-names message-dont-reply-to-names))
4547 (insert (prog1 (rmail-dont-reply-to (buffer-string))
4549 (goto-char (point-min))
4550 ;; Perhaps "Mail-Copies-To: never" removed the only address?
4552 (insert (or reply-to from "")))
4556 (cons (mail-strip-quoted-names addr) addr))
4557 (message-tokenize-header (buffer-string))))
4560 (setq ccalist (delq (assoc (car (pop s)) s) ccalist)))))
4561 (setq follow-to (list (cons 'To (cdr (pop ccalist)))))
4563 (let ((ccs (cons 'Cc (mapconcat
4564 (lambda (addr) (cdr addr)) ccalist ", "))))
4565 (when (string-match "^ +" (cdr ccs))
4566 (setcdr ccs (substring (cdr ccs) (match-end 0))))
4567 (push ccs follow-to)))))
4571 (defun message-reply (&optional to-address wide)
4572 "Start editing a reply to the article in the current buffer."
4574 (require 'gnus-sum) ; for gnus-list-identifiers
4575 (let ((cur (current-buffer))
4577 references message-id follow-to
4578 (inhibit-point-motion-hooks t)
4579 (message-this-is-mail t)
4580 gnus-warning in-reply-to)
4582 (message-narrow-to-head)
4583 ;; Allow customizations to have their say.
4585 ;; This is a regular reply.
4586 (if (message-functionp message-reply-to-function)
4587 (setq follow-to (funcall message-reply-to-function)))
4588 ;; This is a followup.
4589 (if (message-functionp message-wide-reply-to-function)
4592 (funcall message-wide-reply-to-function)))))
4593 (setq message-id (message-fetch-field "message-id" t)
4594 references (message-fetch-field "references")
4595 date (message-fetch-field "date")
4596 from (message-fetch-field "from")
4597 subject (or (message-fetch-field "subject") "none"))
4598 (if gnus-list-identifiers
4599 (setq subject (message-strip-list-identifiers subject)))
4600 (setq subject (message-make-followup-subject subject))
4602 (when (and (setq gnus-warning (message-fetch-field "gnus-warning"))
4603 (string-match "<[^>]+>" gnus-warning))
4604 (setq message-id (match-string 0 gnus-warning)))
4607 (setq follow-to (message-get-reply-headers wide to-address)))
4609 ;; Get the references from "In-Reply-To" field if there were
4610 ;; no references and "In-Reply-To" field looks promising.
4612 (when (and (setq in-reply-to (message-fetch-field "in-reply-to"))
4613 (string-match "<[^>]+>" in-reply-to))
4614 (setq references (match-string 0 in-reply-to)))))
4616 (message-pop-to-buffer
4617 (message-buffer-name
4618 (if wide "wide reply" "reply") from
4619 (if wide to-address nil)))
4621 (setq message-reply-headers
4622 (make-full-mail-header-from-decoded-header
4623 0 subject from date message-id references 0 0 ""))
4626 `((Subject . ,subject)
4628 ,@(if (or references message-id)
4629 `((References . ,(concat (or references "") (and references " ")
4630 (or message-id ""))))
4635 (defun message-wide-reply (&optional to-address)
4636 "Make a \"wide\" reply to the message in the current buffer."
4638 (message-reply to-address t))
4641 (defun message-followup (&optional to-newsgroups)
4642 "Follow up to the message in the current buffer.
4643 If TO-NEWSGROUPS, use that as the new Newsgroups line."
4645 (let ((cur (current-buffer))
4646 from subject date mct
4647 references message-id follow-to
4648 (inhibit-point-motion-hooks t)
4649 (message-this-is-news t)
4650 followup-to distribution newsgroups gnus-warning posted-to mft mrt)
4652 (message-narrow-to-head)
4653 (when (message-functionp message-followup-to-function)
4655 (funcall message-followup-to-function)))
4656 (setq from (message-fetch-field "from")
4657 date (message-fetch-field "date" t)
4658 subject (or (message-fetch-field "subject") "none")
4659 references (message-fetch-field "references")
4660 message-id (message-fetch-field "message-id" t)
4661 followup-to (when message-use-followup-to
4662 (message-fetch-field "followup-to"))
4663 distribution (message-fetch-field "distribution")
4664 newsgroups (message-fetch-field "newsgroups")
4665 posted-to (message-fetch-field "posted-to")
4666 mct (when message-use-mail-copies-to
4667 (message-fetch-field "mail-copies-to"))
4668 mft (when message-use-mail-followup-to
4669 (message-fetch-field "mail-followup-to"))
4670 mrt (when message-use-mail-reply-to
4671 (or (message-fetch-field "mail-reply-to")
4672 (message-fetch-field "reply-to")))
4673 gnus-warning (message-fetch-field "gnus-warning"))
4674 (when (and gnus-warning (string-match "<[^>]+>" gnus-warning))
4675 (setq message-id (match-string 0 gnus-warning)))
4676 ;; Remove bogus distribution.
4677 (when (and (stringp distribution)
4678 (let ((case-fold-search t))
4679 (string-match "world" distribution)))
4680 (setq distribution nil))
4681 (if gnus-list-identifiers
4682 (setq subject (message-strip-list-identifiers subject)))
4683 (setq subject (message-make-followup-subject subject))
4686 ;; Handle special values of Mail-Copies-To.
4689 ((and (or (equal (downcase mct) "never")
4690 (equal (downcase mct) "nobody"))
4691 (or (not (eq message-use-mail-copies-to 'ask))
4693 (concat "Obey Mail-Copies-To: never? ") t "\
4694 You should normally obey the Mail-Copies-To: header.
4696 `Mail-Copies-To: never'
4697 directs you not to send your response to the author.")))
4699 ((and (or (equal (downcase mct) "always")
4700 (equal (downcase mct) "poster"))
4701 (or (not (eq message-use-mail-copies-to 'ask))
4703 (concat "Obey Mail-Copies-To: always? ") t "\
4704 You should normally obey the Mail-Copies-To: header.
4706 `Mail-Copies-To: always'
4707 sends a copy of your response to the author.")))
4708 (setq mct (or mrt from)))
4709 ((and (eq message-use-mail-copies-to 'ask)
4712 (concat "Obey Mail-Copies-To: " mct " ? ") t "\
4713 You should normally obey the Mail-Copies-To: header.
4715 `Mail-Copies-To: " mct "'
4716 sends a copy of your response to " (if (string-match "," mct)
4717 "the specified addresses"
4718 "that address") ".")))
4724 (to-newsgroups (setq follow-to (list (cons 'Newsgroups to-newsgroups))))
4725 ;; Handle Followup-To.
4728 ((equal (downcase followup-to) "poster")
4729 (if (or (eq message-use-followup-to 'use)
4730 (message-y-or-n-p "Obey Followup-To: poster? " t "\
4731 You should normally obey the Followup-To: header.
4733 `Followup-To: poster'
4734 sends your response via e-mail instead of news.
4736 A typical situation where `Followup-To: poster' is used is when the author
4737 does not read the newsgroup, so he wouldn't see any replies sent to it."))
4738 (setq message-this-is-news nil
4740 follow-to (list (cons 'To (or mrt from ""))))
4741 (setq follow-to (list (cons 'Newsgroups newsgroups)))))
4743 (if (or (equal followup-to newsgroups)
4744 (not (eq message-use-followup-to 'ask))
4746 (concat "Obey Followup-To: " followup-to "? ") t "\
4747 You should normally obey the Followup-To: header.
4749 `Followup-To: " followup-to "'
4750 directs your response to " (if (string-match "," followup-to)
4751 "the specified newsgroups"
4752 "that newsgroup only") ".
4754 If a message is posted to several newsgroups, Followup-To is often
4755 used to direct the following discussion to one newsgroup only,
4756 because discussions that are spread over several newsgroup tend to
4757 be fragmented and very difficult to follow.
4759 Also, some source/announcement newsgroups are not indented for discussion;
4760 responses here are directed to other newsgroups."))
4761 (setq follow-to (list (cons 'Newsgroups followup-to)))
4762 (setq follow-to (list (cons 'Newsgroups newsgroups)))))))
4763 ;; Handle Mail-Followup-To, followup via e-mail.
4765 (or (not (eq message-use-mail-followup-to 'ask))
4767 (concat "Obey Mail-Followup-To: " mft "? ") t "\
4768 You should normally obey the Mail-Followup-To: header.
4770 `Mail-Followup-To: " mft "'
4771 directs your response to " (if (string-match "," mft)
4772 "the specified addresses"
4773 "that address only") " instead of news.
4775 A typical situation where Mail-Followup-To is used is when the author thinks
4776 that further discussion should take place only in "
4777 (if (string-match "," mft)
4778 "the specified mailing lists"
4779 "that mailing list") ".")))
4780 (setq message-this-is-news nil
4782 follow-to (list (cons 'To mft))))
4783 (posted-to (setq follow-to (list (cons 'Newsgroups posted-to))))
4785 (setq follow-to (list (cons 'Newsgroups newsgroups))))))
4787 (message-pop-to-buffer (message-buffer-name "followup" from newsgroups))
4789 (setq message-reply-headers
4790 (make-full-mail-header-from-decoded-header
4791 0 subject from date message-id references 0 0 ""))
4794 `((Subject . ,subject)
4796 ,@(and mct (list (cons 'Cc mct)))
4797 ,@(and distribution (list (cons 'Distribution distribution)))
4798 ,@(if (or references message-id)
4799 `((References . ,(concat (or references "") (and references " ")
4800 (or message-id ""))))))
4804 (defun message-cancel-news (&optional arg)
4805 "Cancel an article you posted.
4806 If ARG, allow editing of the cancellation message."
4808 (unless (message-news-p)
4809 (error "This is not a news article; canceling is impossible"))
4810 (when (yes-or-no-p "Do you really want to cancel this article? ")
4811 (let (from newsgroups message-id distribution buf sender)
4813 ;; Get header info from original article.
4815 (message-narrow-to-head)
4816 (setq from (message-fetch-field "from")
4817 sender (message-fetch-field "sender")
4818 newsgroups (message-fetch-field "newsgroups")
4819 message-id (message-fetch-field "message-id" t)
4820 distribution (message-fetch-field "distribution")))
4821 ;; Make sure that this article was written by the user.
4822 (unless (or (and sender
4825 (downcase (message-make-sender))))
4827 (downcase (cadr (std11-extract-address-components
4829 (downcase (cadr (std11-extract-address-components
4830 (message-make-from))))))
4831 (error "This article is not yours"))
4832 ;; Make control message.
4835 (setq buf (set-buffer (get-buffer-create " *message cancel*"))))
4837 (insert "Newsgroups: " newsgroups "\n"
4839 "Subject: cmsg cancel " message-id "\n"
4840 "Control: cancel " message-id "\n"
4842 (concat "Distribution: " distribution "\n")
4844 mail-header-separator "\n"
4845 message-cancel-message)
4846 (run-hooks 'message-cancel-hook)
4847 (message "Canceling your article...")
4849 (if (let ((message-syntax-checks
4850 'dont-check-for-anything-just-trust-me)
4851 (message-encoding-buffer (current-buffer))
4852 (message-edit-buffer (current-buffer)))
4853 (message-send-news))
4854 (message "Canceling your article...done"))
4855 (kill-buffer buf))))))
4857 (defun message-supersede-setup-for-mime-edit ()
4858 (set (make-local-variable 'message-setup-hook) nil)
4862 (defun message-supersede ()
4863 "Start composing a message to supersede the current message.
4864 This is done simply by taking the old article and adding a Supersedes
4865 header line with the old Message-ID."
4867 (let ((cur (current-buffer))
4868 (sender (message-fetch-field "sender"))
4869 (from (message-fetch-field "from")))
4870 ;; Check whether the user owns the article that is to be superseded.
4871 (unless (or (and sender
4874 (downcase (message-make-sender))))
4876 (downcase (cadr (std11-extract-address-components from)))
4877 (downcase (cadr (std11-extract-address-components
4878 (message-make-from))))))
4879 (error "This article is not yours"))
4880 ;; Get a normal message buffer.
4881 (message-pop-to-buffer (message-buffer-name "supersede"))
4882 (insert-buffer-substring cur)
4883 (message-narrow-to-head)
4884 ;; Remove unwanted headers.
4885 (when message-ignored-supersedes-headers
4886 (message-remove-header message-ignored-supersedes-headers t))
4887 (goto-char (point-min))
4888 (if (not (re-search-forward "^Message-ID: " nil t))
4889 (error "No Message-ID in this article")
4890 (replace-match "Supersedes: " t t))
4891 (goto-char (point-max))
4892 (insert mail-header-separator)
4894 (when message-supersede-setup-function
4895 (funcall message-supersede-setup-function))
4896 (run-hooks 'message-supersede-setup-hook)
4897 (goto-char (point-min))
4898 (search-forward (concat "\n" mail-header-separator "\n") nil t)))
4901 (defun message-recover ()
4902 "Reread contents of current buffer from its last auto-save file."
4904 (let ((file-name (make-auto-save-file-name)))
4905 (cond ((save-window-excursion
4906 (if (not (eq system-type 'vax-vms))
4907 (with-output-to-temp-buffer "*Directory*"
4908 (with-current-buffer standard-output
4909 (fundamental-mode)) ; for Emacs 20.4+
4910 (buffer-disable-undo standard-output)
4911 (let ((default-directory "/"))
4913 "ls" nil standard-output nil "-l" file-name))))
4914 (yes-or-no-p (format "Recover auto save file %s? " file-name)))
4915 (let ((buffer-read-only nil))
4917 (insert-file-contents file-name nil)))
4918 (t (error "message-recover cancelled")))))
4920 ;;; Washing Subject:
4922 (defun message-wash-subject (subject)
4923 "Remove junk like \"Re:\", \"(fwd)\", etc. that was added to the subject by previous forwarders, replyers, etc."
4925 (insert-string subject)
4926 (goto-char (point-min))
4927 ;; strip Re/Fwd stuff off the beginning
4928 (while (re-search-forward
4929 "\\([Rr][Ee]:\\|[Ff][Ww][Dd]\\(\\[[0-9]*\\]\\)?:\\|[Ff][Ww]:\\)" nil t)
4932 ;; and gnus-style forwards [foo@bar.com] subject
4933 (goto-char (point-min))
4934 (while (re-search-forward "\\[[^ \t]*\\(@\\|\\.\\)[^ \t]*\\]" nil t)
4938 (goto-char (point-max))
4939 (while (re-search-backward "([Ff][Ww][Dd])" nil t)
4942 ;; and finally, any whitespace that was left-over
4943 (goto-char (point-min))
4944 (while (re-search-forward "^[ \t]+" nil t)
4946 (goto-char (point-max))
4947 (while (re-search-backward "[ \t]+$" nil t)
4952 ;;; Forwarding messages.
4954 (defun message-forward-subject-author-subject (subject)
4955 "Generate a subject for a forwarded message.
4956 The form is: [Source] Subject, where if the original message was mail,
4957 Source is the sender, and if the original message was news, Source is
4958 the list of newsgroups is was posted to."
4960 (or (message-fetch-field
4961 (if (message-news-p) "newsgroups" "from"))
4965 (defun message-forward-subject-fwd (subject)
4966 "Generate a subject for a forwarded message.
4967 The form is: Fwd: Subject, where Subject is the original subject of
4969 (concat "Fwd: " subject))
4971 (defun message-make-forward-subject ()
4972 "Return a Subject header suitable for the message in the current buffer."
4975 (message-narrow-to-head)
4976 (let ((funcs message-make-forward-subject-function)
4977 (subject (message-fetch-field "Subject")))
4980 (if message-wash-forwarded-subjects
4981 (message-wash-subject
4982 (nnheader-decode-subject subject))
4983 (nnheader-decode-subject subject))
4985 ;; Make sure funcs is a list.
4988 (setq funcs (list funcs)))
4989 ;; Apply funcs in order, passing subject generated by previous
4990 ;; func to the next one.
4992 (when (message-functionp (car funcs))
4993 (setq subject (funcall (car funcs) subject)))
4994 (setq funcs (cdr funcs)))
4998 (defun message-forward (&optional news)
4999 "Forward the current message via mail.
5000 Optional NEWS will use news to forward instead of mail."
5002 (let ((cur (current-buffer))
5003 (subject (message-make-forward-subject))
5006 (message-news nil subject)
5007 (message-mail nil subject))
5008 ;; Put point where we want it before inserting the forwarded
5010 (if message-forward-before-signature
5012 (goto-char (point-max)))
5013 ;; Make sure we're at the start of the line.
5016 ;; Narrow to the area we are to insert.
5017 (narrow-to-region (point) (point))
5018 ;; Insert the separators and the forwarded buffer.
5019 (insert message-forward-start-separator)
5020 (setq art-beg (point))
5021 (insert-buffer-substring cur)
5022 (goto-char (point-max))
5023 (insert message-forward-end-separator)
5024 (set-text-properties (point-min) (point-max) nil)
5025 ;; Remove all unwanted headers.
5027 (narrow-to-region (point) (if (search-forward "\n\n" nil t)
5030 (goto-char (point-min))
5031 (message-remove-header message-included-forward-headers t nil t)
5033 (message-position-point)))
5036 (defun message-resend (address)
5037 "Resend the current article to ADDRESS."
5039 (list (message-read-from-minibuffer "Resend message to: ")))
5040 (message "Resending message to %s..." address)
5042 (let ((cur (current-buffer))
5044 ;; We first set up a normal mail buffer.
5045 (set-buffer (get-buffer-create " *message resend*"))
5047 ;; avoid to turn-on-mime-edit
5048 (let (message-setup-hook)
5049 (message-setup `((To . ,address)))
5051 ;; Insert our usual headers.
5052 (message-generate-headers '(From Date To))
5053 (message-narrow-to-headers)
5054 ;; Rename them all to "Resent-*".
5055 (while (re-search-forward "^[A-Za-z]" nil t)
5060 (delete-region (point) (point-max))
5062 ;; Insert the message to be resent.
5063 (insert-buffer-substring cur)
5064 (goto-char (point-min))
5065 (search-forward "\n\n")
5068 (narrow-to-region beg (point))
5069 (message-remove-header message-ignored-resent-headers t)
5070 (goto-char (point-max)))
5071 (insert mail-header-separator)
5072 ;; Rename all old ("Also-")Resent headers.
5073 (while (re-search-backward "^\\(Also-\\)*Resent-" beg t)
5076 ;; Quote any "From " lines at the beginning.
5078 (when (looking-at "From ")
5079 (replace-match "X-From-Line: "))
5081 (let ((message-encoding-buffer (current-buffer))
5082 (message-edit-buffer (current-buffer)))
5083 (let (message-required-mail-headers)
5084 (message-send-mail)))
5085 (kill-buffer (current-buffer)))
5086 (message "Resending message to %s...done" address)))
5088 (defun message-bounce-setup-for-mime-edit ()
5089 (set (make-local-variable 'message-setup-hook) nil)
5093 (defun message-bounce ()
5094 "Re-mail the current message.
5095 This only makes sense if the current message is a bounce message that
5096 contains some mail you have written which has been bounced back to
5099 (let ((cur (current-buffer))
5101 (message-pop-to-buffer (message-buffer-name "bounce"))
5102 (insert-buffer-substring cur)
5104 (message-narrow-to-head)
5105 (if (and (message-fetch-field "MIME-Version")
5106 (setq boundary (message-fetch-field "Content-Type")))
5107 (if (string-match "boundary=\"\\([^\"]+\\)\"" boundary)
5108 (setq boundary (concat (match-string 1 boundary) " *\n"
5109 "Content-Type: message/rfc822"))
5110 (setq boundary nil)))
5112 (goto-char (point-min))
5113 (search-forward "\n\n" nil t)
5115 (re-search-forward boundary nil t)
5117 (and (re-search-forward message-unsent-separator nil t)
5119 (re-search-forward "^Return-Path:.*\n" nil t))
5120 ;; We remove everything before the bounced mail.
5123 (if (re-search-forward "^[^ \n\t]+:" nil t)
5127 (message-narrow-to-head)
5128 (message-remove-header message-ignored-bounced-headers t)
5129 (goto-char (point-max))
5130 (insert mail-header-separator))
5131 (when message-bounce-setup-function
5132 (funcall message-bounce-setup-function))
5133 (run-hooks 'message-bounce-setup-hook)
5134 (message-position-point)))
5137 ;;; Interactive entry points for new message buffers.
5141 (defun message-mail-other-window (&optional to subject)
5142 "Like `message-mail' command, but display mail buffer in another window."
5144 (let ((pop-up-windows t)
5145 (special-display-buffer-names nil)
5146 (special-display-regexps nil)
5147 (same-window-buffer-names nil)
5148 (same-window-regexps nil))
5149 (message-pop-to-buffer (message-buffer-name "mail" to)))
5150 (let ((message-this-is-mail t))
5151 (message-setup `((To . ,(or to "")) (Subject . ,(or subject ""))))))
5154 (defun message-mail-other-frame (&optional to subject)
5155 "Like `message-mail' command, but display mail buffer in another frame."
5157 (let ((pop-up-frames t)
5158 (special-display-buffer-names nil)
5159 (special-display-regexps nil)
5160 (same-window-buffer-names nil)
5161 (same-window-regexps nil))
5162 (message-pop-to-buffer (message-buffer-name "mail" to)))
5163 (let ((message-this-is-mail t))
5164 (message-setup `((To . ,(or to "")) (Subject . ,(or subject ""))))))
5167 (defun message-news-other-window (&optional newsgroups subject)
5168 "Start editing a news article to be sent."
5170 (let ((pop-up-windows t)
5171 (special-display-buffer-names nil)
5172 (special-display-regexps nil)
5173 (same-window-buffer-names nil)
5174 (same-window-regexps nil))
5175 (message-pop-to-buffer (message-buffer-name "news" nil newsgroups)))
5176 (let ((message-this-is-news t))
5177 (message-setup `((Newsgroups . ,(or newsgroups ""))
5178 (Subject . ,(or subject ""))))))
5181 (defun message-news-other-frame (&optional newsgroups subject)
5182 "Start editing a news article to be sent."
5184 (let ((pop-up-frames t)
5185 (special-display-buffer-names nil)
5186 (special-display-regexps nil)
5187 (same-window-buffer-names nil)
5188 (same-window-regexps nil))
5189 (message-pop-to-buffer (message-buffer-name "news" nil newsgroups)))
5190 (let ((message-this-is-news t))
5191 (message-setup `((Newsgroups . ,(or newsgroups ""))
5192 (Subject . ,(or subject ""))))))
5196 ;; This code should be moved to underline.el (from which it is stolen).
5199 (defun bold-region (start end)
5200 "Bold all nonblank characters in the region.
5201 Works by overstriking characters.
5202 Called from program, takes two arguments START and END
5203 which specify the range to operate on."
5206 (let ((end1 (make-marker)))
5207 (move-marker end1 (max start end))
5208 (goto-char (min start end))
5209 (while (< (point) end1)
5210 (or (looking-at "[_\^@- ]")
5211 (insert (char-after) "\b"))
5212 (forward-char 1)))))
5215 (defun unbold-region (start end)
5216 "Remove all boldness (overstruck characters) in the region.
5217 Called from program, takes two arguments START and END
5218 which specify the range to operate on."
5221 (let ((end1 (make-marker)))
5222 (move-marker end1 (max start end))
5223 (goto-char (min start end))
5224 (while (re-search-forward "\b" end1 t)
5225 (if (eq (char-after) (char-after (- (point) 2)))
5226 (delete-char -2))))))
5228 (defalias 'message-exchange-point-and-mark 'exchange-point-and-mark)
5230 ;; Support for toolbar
5231 (when (featurep 'xemacs)
5232 (require 'messagexmas))
5234 ;;; Group name completion.
5236 (defvar message-newgroups-header-regexp
5237 "^\\(Newsgroups\\|Followup-To\\|Posted-To\\|Gcc\\):"
5238 "Regexp that match headers that lists groups.")
5240 (defun message-tab ()
5241 "Expand group names in Newsgroups and Followup-To headers.
5242 Do a `tab-to-tab-stop' if not in those headers."
5244 (if (let ((mail-abbrev-mode-regexp message-newgroups-header-regexp))
5245 (mail-abbrev-in-expansion-header-p))
5246 (message-expand-group)
5249 (defvar gnus-active-hashtb)
5250 (defun message-expand-group ()
5251 "Expand the group name under point."
5252 (let* ((b (save-excursion
5257 (skip-chars-forward "^:")
5260 (skip-chars-backward "^, \t\n") (point))))
5261 (completion-ignore-case t)
5262 (string (buffer-substring b (progn (skip-chars-forward "^,\t\n ")
5264 (hashtb (and (boundp 'gnus-active-hashtb) gnus-active-hashtb))
5265 (completions (all-completions string hashtb))
5267 (delete-region b (point))
5269 ((= (length completions) 1)
5270 (if (string= (car completions) string)
5273 (message "Only matching group"))
5274 (insert (car completions))))
5275 ((and (setq comp (try-completion string hashtb))
5276 (not (string= comp string)))
5281 (message "No matching groups")
5282 (save-selected-window
5283 (pop-to-buffer "*Completions*")
5284 (buffer-disable-undo)
5285 (let ((buffer-read-only nil))
5287 (let ((standard-output (current-buffer)))
5288 (display-completion-list (sort completions 'string<)))
5289 (goto-char (point-min))
5290 (delete-region (point) (progn (forward-line 3) (point))))))))))
5294 (defun message-talkative-question (ask question show &rest text)
5295 "Call FUNCTION with argument QUESTION; optionally display TEXT... args.
5296 If SHOW is non-nil, the arguments TEXT... are displayed in a temp buffer.
5297 The following arguments may contain lists of values."
5299 (setq text (message-flatten-list text)))
5300 (save-window-excursion
5302 (with-output-to-temp-buffer " *MESSAGE information message*"
5303 (set-buffer " *MESSAGE information message*")
5304 (fundamental-mode) ; for Emacs 20.4+
5305 (mapcar 'princ text)
5306 (goto-char (point-min))))
5307 (funcall ask question))
5308 (funcall ask question)))
5310 (defun message-flatten-list (list)
5311 "Return a new, flat list that contains all elements of LIST.
5313 \(message-flatten-list '(1 (2 3 (4 5 (6))) 7))
5316 (apply 'append (mapcar 'message-flatten-list list)))
5320 (defun message-generate-new-buffer-clone-locals (name &optional varstr)
5321 "Create and return a buffer with a name based on NAME using generate-new-buffer.
5322 Then clone the local variables and values from the old buffer to the
5323 new one, cloning only the locals having a substring matching the
5325 (let ((oldbuf (current-buffer)))
5327 (set-buffer (generate-new-buffer name))
5328 (message-clone-locals oldbuf varstr)
5331 (defun message-clone-locals (buffer &optional varstr)
5332 "Clone the local variables from BUFFER to the current buffer."
5333 (let ((locals (save-excursion
5335 (buffer-local-variables)))
5337 "^\\(gnus\\|nn\\|message\\|user-\\(mail-address\\|full-name\\)\\)"))
5340 (when (and (consp local)
5342 (string-match regexp (symbol-name (car local)))
5344 (string-match varstr (symbol-name (car local)))))
5346 (set (make-local-variable (car local))
5351 ;;; @ for MIME Edit mode
5354 (defun message-maybe-encode ()
5355 (when message-mime-mode
5356 ;; Inherit the buffer local variable `mime-edit-pgp-processing'.
5357 (let ((pgp-processing (with-current-buffer message-edit-buffer
5358 mime-edit-pgp-processing)))
5359 (setq mime-edit-pgp-processing pgp-processing))
5360 (run-hooks 'mime-edit-translate-hook)
5361 (if (catch 'mime-edit-error
5363 (mime-edit-pgp-enclose-buffer)
5364 (mime-edit-translate-body)
5366 (error "Translation error!")
5369 (run-hooks 'mime-edit-exit-hook)
5372 (defun message-mime-insert-article (&optional full-headers)
5374 (let ((message-cite-function 'mime-edit-inserted-message-filter)
5375 (message-reply-buffer
5376 (message-get-parameter-with-eval 'original-buffer))
5378 (message-yank-original nil)
5380 (narrow-to-region (goto-char start)
5381 (if (search-forward "\n\n" nil t)
5384 (goto-char (point-min))
5385 (let ((message-included-forward-headers
5386 (if full-headers "" message-included-forward-headers)))
5387 (message-remove-header message-included-forward-headers t nil t))
5390 (set-alist 'mime-edit-message-inserter-alist
5391 'message-mode (function message-mime-insert-article))
5393 ;;; Miscellaneous functions
5395 ;; stolen (and renamed) from nnheader.el
5396 (static-if (fboundp 'subst-char-in-string)
5397 (defsubst message-replace-chars-in-string (string from to)
5398 (subst-char-in-string from to string))
5399 (defun message-replace-chars-in-string (string from to)
5400 "Replace characters in STRING from FROM to TO."
5401 (let ((string (substring string 0)) ;Copy string.
5402 (len (length string))
5404 ;; Replace all occurrences of FROM with TO.
5406 (when (= (aref string idx) from)
5407 (aset string idx to))
5408 (setq idx (1+ idx)))
5415 (defvar message-inhibit-body-encoding t)
5417 (defun message-encode-message-body ()
5418 (unless message-inhibit-body-encoding
5419 (let ((mail-parse-charset (or mail-parse-charset
5420 message-default-charset))
5421 (case-fold-search t)
5422 lines content-type-p)
5425 (narrow-to-region (point) (point-max))
5426 (let ((new (mml-generate-mime)))
5428 (delete-region (point-min) (point-max))
5430 (goto-char (point-min))
5431 (if (eq (aref new 0) ?\n)
5433 (search-forward "\n\n")
5434 (setq lines (buffer-substring (point-min) (1- (point))))
5435 (delete-region (point-min) (point))))))
5437 (message-narrow-to-headers-or-head)
5438 (message-remove-header "Mime-Version")
5439 (goto-char (point-max))
5440 (insert "MIME-Version: 1.0\n")
5443 (setq content-type-p
5444 (re-search-backward "^Content-Type:" nil t)))
5446 (message-narrow-to-headers-or-head)
5447 (message-remove-first-header "Content-Type")
5448 (message-remove-first-header "Content-Transfer-Encoding"))
5449 ;; We always make sure that the message has a Content-Type header.
5450 ;; This is because some broken MTAs and MUAs get awfully confused
5451 ;; when confronted with a message with a MIME-Version header and
5452 ;; without a Content-Type header. For instance, Solaris'
5454 (unless content-type-p
5455 (goto-char (point-min))
5456 (re-search-forward "^MIME-Version:")
5458 (insert "Content-Type: text/plain; charset=us-ascii\n")))))
5460 (defun message-read-from-minibuffer (prompt)
5461 "Read from the minibuffer while providing abbrev expansion."
5462 (if (fboundp 'mail-abbrevs-setup)
5463 (let ((mail-abbrev-mode-regexp "")
5464 (minibuffer-setup-hook 'mail-abbrevs-setup))
5465 (read-from-minibuffer prompt))
5466 (let ((minibuffer-setup-hook 'mail-abbrev-minibuffer-setup-hook))
5467 (read-string prompt))))
5469 (defun message-use-alternative-email-as-from ()
5470 (require 'mail-utils)
5471 (let* ((fields '("To" "Cc"))
5474 (mail-strip-quoted-names
5475 (mapconcat 'message-fetch-reply-field fields ","))
5479 (if (string-match message-alternative-emails (car emails))
5480 (setq email (car emails)
5483 (unless (or (not email) (equal email user-mail-address))
5484 (goto-char (point-max))
5485 (insert "From: " email "\n"))))
5487 (defun message-save-drafts ()
5488 "Postponing the message."
5490 (message "Saving %s..." buffer-file-name)
5491 (let ((reply-headers message-reply-headers)
5492 (msg (buffer-substring-no-properties (point-min) (point-max))))
5493 (with-temp-file buffer-file-name
5495 (setq message-reply-headers reply-headers)
5496 (message-generate-headers '((optional . In-Reply-To)))
5497 (mime-edit-translate-buffer))
5498 (set-buffer-modified-p nil))
5499 (message "Saving %s...done" buffer-file-name))
5503 (run-hooks 'message-load-hook)
5506 ;; coding: iso-8859-1
5509 ;;; message.el ends here