1 ;;; message.el --- composing mail and news messages -*- coding: iso-latin-1 -*-
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
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 (defvar message-shoot-gnksa-feet nil
865 "*A list of GNKSA feet you are allowed to shoot.
866 Gnus gives you all the opportunity you could possibly want for
867 shooting yourself in the foot. Also, Gnus allows you to shoot the
868 feet of Good Net-Keeping Seal of Approval. The following are foot
870 `empty-article' Allow you to post an empty article;
871 `quoted-text-only' Allow you to post quoted text only;
872 `multiple-copies' Allow you to post multiple copies.")
874 (defsubst message-gnksa-enable-p (feature)
875 (or (not (listp message-shoot-gnksa-feet))
876 (memq feature message-shoot-gnksa-feet)))
878 ;;; Internal variables.
879 ;;; Well, not really internal.
881 (defvar message-mode-syntax-table
882 (let ((table (copy-syntax-table text-mode-syntax-table)))
883 (modify-syntax-entry ?% ". " table)
884 (modify-syntax-entry ?> ". " table)
885 (modify-syntax-entry ?< ". " table)
887 "Syntax table used while in Message mode.")
889 (defvar message-mode-abbrev-table text-mode-abbrev-table
890 "Abbrev table used in Message mode buffers.
891 Defaults to `text-mode-abbrev-table'.")
892 (defgroup message-headers nil
894 :link '(custom-manual "(message)Variables")
897 (defface message-header-to-face
900 (:foreground "green2" :bold t))
903 (:foreground "MidnightBlue" :bold t))
905 (:bold t :italic t)))
906 "Face used for displaying From headers."
907 :group 'message-faces)
909 (defface message-header-cc-face
912 (:foreground "green4" :bold t))
915 (:foreground "MidnightBlue"))
918 "Face used for displaying Cc headers."
919 :group 'message-faces)
921 (defface message-header-subject-face
924 (:foreground "green3"))
927 (:foreground "navy blue" :bold t))
930 "Face used for displaying subject headers."
931 :group 'message-faces)
933 (defface message-header-newsgroups-face
936 (:foreground "yellow" :bold t :italic t))
939 (:foreground "blue4" :bold t :italic t))
941 (:bold t :italic t)))
942 "Face used for displaying newsgroups headers."
943 :group 'message-faces)
945 (defface message-header-other-face
948 (:foreground "#b00000"))
951 (:foreground "steel blue"))
953 (:bold t :italic t)))
954 "Face used for displaying newsgroups headers."
955 :group 'message-faces)
957 (defface message-header-name-face
960 (:foreground "DarkGreen"))
963 (:foreground "cornflower blue"))
966 "Face used for displaying header names."
967 :group 'message-faces)
969 (defface message-header-xheader-face
972 (:foreground "blue"))
975 (:foreground "blue"))
978 "Face used for displaying X-Header headers."
979 :group 'message-faces)
981 (defface message-separator-face
984 (:foreground "blue3"))
987 (:foreground "brown"))
990 "Face used for displaying the separator."
991 :group 'message-faces)
993 (defface message-cited-text-face
1002 "Face used for displaying cited text names."
1003 :group 'message-faces)
1005 (defface message-mml-face
1008 (:foreground "ForestGreen"))
1011 (:foreground "ForestGreen"))
1014 "Face used for displaying MML."
1015 :group 'message-faces)
1017 (defvar message-font-lock-fence-open-regexp "[+|]"
1018 "*Regexp that matches fence open string.")
1020 (defvar message-font-lock-fence-close-regexp "|"
1021 "*Regexp that matches fence close string.")
1023 (defvar message-font-lock-fence-open-position nil
1024 "*Cons of SYMBOL of a function or a variable and a number of OFFSET that
1025 indicate the fence open position. If it is non-nil,
1026 `message-font-lock-fence-open-regexp' is not used for searching for the
1027 fence open position. If SYMBOL is a function, it is called with one argument
1028 last cursor position and should return the fence open position as a number
1029 or a marker. If SYMBOL is a variable symbol, the value is examined with
1030 `symbol-value'. OFFSET is added to the position to compensate the value.
1031 For example, the following combinations of variable symbol and offset value
1034 Egg v3: '(egg:*region-start* . -1)
1035 Canna: '(canna:*region-start* . 0)
1038 (defvar message-font-lock-fence-close-position nil
1039 "*Cons of SYMBOL of a function or a variable and a number of OFFSET that
1040 indicate the fence close position. If it is non-nil,
1041 `message-font-lock-fence-close-regexp' is not used for searching for the
1042 fence close position. If SYMBOL is a function, it is called with one argument
1043 last cursor position and should return the fence close position as a number
1044 or a marker. If SYMBOL is a variable symbol, the value is examined with
1045 `symbol-value'. OFFSET is added to the position to compensate the value.
1046 For example, the following combinations of variable symbol and offset value
1049 Egg v3: '(egg:*region-end* . 0)
1050 Canna: '(canna:*region-end* . 0)
1053 (defvar message-font-lock-cited-text-regexp
1054 "^[\t ]*\\([^\000- :>|}\177]*\\)[:>|}].*"
1055 "*Regexp that matches cited text. It should have a grouping for the
1056 citation prefix which is ended at the beginning of citation mark string.")
1058 (defvar message-font-lock-citation-name-max-column 10
1059 "*Maximun number of column for citation name for fontifying.")
1061 (defvar message-font-lock-last-position nil
1062 "Internal buffer local variable to save the last cursor position
1063 before fontifying.")
1065 (eval-after-load "font-lock"
1066 '(defadvice font-lock-after-change-function
1067 (before message-font-lock-save-last-position activate)
1068 "Save last cursor position before fontifying."
1069 (if (eq 'message-mode major-mode)
1070 (setq message-font-lock-last-position (point)))))
1072 (defun message-font-lock-cited-text-matcher (limit)
1073 "Search for a cited text containing `message-font-lock-cited-text-regexp'
1074 forward. Argument LIMIT bounds the search. If a cited text is found, it
1075 returns t and sets match data 1 and 2, otherwise it returns nil. Normally,
1076 match data 2 has zero length, but if the FENCE (for input method) is detected
1077 in matched text, result is divided into match data 1 and 2 across the FENCE.
1078 See also the documentations for the following variables:
1079 `message-font-lock-fence-open-regexp'
1080 `message-font-lock-fence-close-regexp'
1081 `message-font-lock-fence-open-position'
1082 `message-font-lock-fence-close-position'
1085 (when (re-search-forward message-font-lock-cited-text-regexp limit t)
1086 (let* ((start0 (match-beginning 0))
1087 (end0 (match-end 0))
1088 (cite-mark (match-end 1))
1091 (goto-char cite-mark)
1092 (<= (current-column)
1093 message-font-lock-citation-name-max-column)))
1097 message-font-lock-last-position
1098 (>= message-font-lock-last-position start0)
1099 (<= message-font-lock-last-position end0)
1101 (message-font-lock-fence-open-position
1102 (let* ((symbol (car message-font-lock-fence-open-position))
1104 (cond ((functionp symbol)
1105 (funcall symbol message-font-lock-last-position))
1106 ((and (symbolp symbol)
1108 (symbol-value symbol)))))
1109 (when (markerp open)
1110 (setq open (marker-position open)))
1114 (cdr message-font-lock-fence-open-position)))
1115 (>= message-font-lock-last-position open)
1117 (or (not message-font-lock-fence-open-regexp)
1118 (looking-at message-font-lock-fence-open-regexp))
1120 (message-font-lock-fence-open-regexp
1121 (goto-char message-font-lock-last-position)
1122 (when (re-search-backward
1123 message-font-lock-fence-open-regexp start0 t)
1124 (setq end1 (match-beginning 0)))))
1125 (setq should-fontify
1126 (and message-font-lock-fence-open-position
1127 (not (eq cite-mark end1))))
1129 (message-font-lock-fence-close-position
1130 (let* ((symbol (car message-font-lock-fence-close-position))
1132 (cond ((functionp symbol)
1133 (funcall symbol message-font-lock-last-position))
1134 ((and (symbolp symbol)
1136 (symbol-value symbol)))))
1137 (when (markerp close)
1138 (setq close (marker-position close)))
1139 (and (numberp close)
1142 (cdr message-font-lock-fence-close-position)))
1143 (<= message-font-lock-last-position close)
1144 (setq start2 close))))
1145 (message-font-lock-fence-close-regexp
1146 (goto-char message-font-lock-last-position)
1147 (when (looking-at message-font-lock-fence-close-regexp)
1148 (setq start2 (match-end 0)))))
1149 (setq should-fontify
1150 (and (not (and (not message-font-lock-fence-open-position)
1151 (eq cite-mark end1)))
1152 (not (eq cite-mark start2)))))
1154 (when should-fontify
1156 (store-match-data (list start0 end0 start0 end1 start2 end0))
1157 (store-match-data (list start0 end0 start0 end0 end0 end0)))
1159 (setq message-font-lock-last-position nil)))
1161 (defvar message-font-lock-keywords-1
1162 (let ((content "[ \t]*\\(.+\\(\n[ \t].*\\)*\\)\n?"))
1163 `((,(concat "^\\([Tt]o:\\)" content)
1164 (1 'message-header-name-face)
1165 (2 'message-header-to-face nil t))
1166 (,(concat "^\\([GBF]?[Cc][Cc]:\\|[Rr]eply-[Tt]o:\\|"
1167 "[Mm]ail-[Cc]opies-[Tt]o:\\|"
1168 "[Mm]ail-[Rr]eply-[Tt]o:\\|"
1169 "[Mm]ail-[Ff]ollowup-[Tt]o:\\)" content)
1170 (1 'message-header-name-face)
1171 (2 'message-header-cc-face nil t))
1172 (,(concat "^\\([Ss]ubject:\\)" content)
1173 (1 'message-header-name-face)
1174 (2 'message-header-subject-face nil t))
1175 (,(concat "^\\([Nn]ewsgroups:\\|Followup-[Tt]o:\\)" content)
1176 (1 'message-header-name-face)
1177 (2 'message-header-newsgroups-face nil t))
1178 (,(concat "^\\([A-Z][^: \n\t]+:\\)" content)
1179 (1 'message-header-name-face)
1180 (2 'message-header-other-face nil t))
1181 (,(concat "^\\(X-[A-Za-z0-9-]+\\|In-Reply-To\\):" content)
1182 (1 'message-header-name-face)
1183 (2 'message-header-name-face))
1184 ,@(if (and mail-header-separator
1185 (not (equal mail-header-separator "")))
1186 `((,(concat "^\\(" (regexp-quote mail-header-separator) "\\)$")
1187 1 'message-separator-face))
1190 (defvar message-font-lock-keywords-2
1191 (append message-font-lock-keywords-1
1192 '((message-font-lock-cited-text-matcher
1193 (1 'message-cited-text-face)
1194 (2 'message-cited-text-face))
1195 ("<#/?\\(multipart\\|part\\|external\\).*>"
1196 (0 'message-mml-face)))))
1198 (defvar message-font-lock-keywords message-font-lock-keywords-2
1199 "Additional expressions to highlight in Message mode.")
1201 ;; XEmacs does it like this. For Emacs, we have to set the
1202 ;; `font-lock-defaults' buffer-local variable.
1203 (put 'message-mode 'font-lock-defaults
1204 '((message-font-lock-keywords
1205 message-font-lock-keywords-1
1206 message-font-lock-keywords-2)
1208 (font-lock-mark-block-function . mark-paragraph)))
1210 (defvar message-face-alist
1211 '((bold . bold-region)
1212 (underline . underline-region)
1213 (default . (lambda (b e)
1215 (ununderline-region b e))))
1216 "Alist of mail and news faces for facemenu.
1217 The cdr of ech entry is a function for applying the face to a region.")
1219 (defcustom message-send-hook nil
1220 "Hook run before sending messages."
1221 :group 'message-various
1222 :options '(ispell-message)
1225 (defcustom message-send-mail-hook nil
1226 "Hook run before sending mail messages."
1227 :group 'message-various
1230 (defcustom message-send-news-hook nil
1231 "Hook run before sending news messages."
1232 :group 'message-various
1235 (defcustom message-sent-hook nil
1236 "Hook run after sending messages."
1237 :group 'message-various
1240 (defcustom message-use-multi-frames nil
1241 "Make new frame when sending messages."
1242 :group 'message-frames
1245 (defcustom message-delete-frame-on-exit nil
1246 "Delete frame after sending messages."
1247 :group 'message-frames
1248 :type '(choice (const :tag "off" nil)
1249 (const :tag "always" t)
1250 (const :tag "ask" ask)))
1252 (defvar message-draft-coding-system
1254 ((boundp 'MULE) '*junet*)
1255 ((not (fboundp 'find-coding-system)) nil)
1256 ((find-coding-system 'emacs-mule)
1257 (if (memq system-type '(windows-nt ms-dos ms-windows))
1258 'emacs-mule-dos 'emacs-mule))
1259 ((find-coding-system 'escape-quoted) 'escape-quoted)
1260 ((find-coding-system 'no-conversion) 'no-conversion)
1262 "Coding system to compose mail.")
1264 (defcustom message-send-mail-partially-limit 1000000
1265 "The limitation of messages sent as message/partial.
1266 The lower bound of message size in characters, beyond which the message
1267 should be sent in several parts. If it is nil, the size is unlimited."
1268 :group 'message-buffers
1269 :type '(choice (const :tag "unlimited" nil)
1272 (defcustom message-alternative-emails nil
1273 "A regexp to match the alternative email addresses.
1274 The first matched address (not primary one) is used in the From field."
1275 :group 'message-headers
1276 :type '(choice (const :tag "Always use primary" nil)
1279 ;;; Internal variables.
1281 (defvar message-sending-message "Sending...")
1282 (defvar message-buffer-list nil)
1283 (defvar message-this-is-news nil)
1284 (defvar message-this-is-mail nil)
1285 (defvar message-draft-article nil)
1286 (defvar message-mime-part nil)
1287 (defvar message-posting-charset nil)
1289 ;; Byte-compiler warning
1290 (defvar gnus-active-hashtb)
1291 (defvar gnus-read-active-file)
1293 ;;; Regexp matching the delimiter of messages in UNIX mail format
1294 ;;; (UNIX From lines), minus the initial ^. It should be a copy
1295 ;;; of rmail.el's rmail-unix-mail-delimiter.
1296 (defvar message-unix-mail-delimiter
1297 (let ((time-zone-regexp
1298 (concat "\\([A-Z]?[A-Z]?[A-Z][A-Z]\\( DST\\)?"
1299 "\\|[-+]?[0-9][0-9][0-9][0-9]"
1305 ;; Many things can happen to an RFC 822 mailbox before it is put into
1306 ;; a `From' line. The leading phrase can be stripped, e.g.
1307 ;; `Joe <@w.x:joe@y.z>' -> `<@w.x:joe@y.z>'. The <> can be stripped, e.g.
1308 ;; `<@x.y:joe@y.z>' -> `@x.y:joe@y.z'. Everything starting with a CRLF
1309 ;; can be removed, e.g.
1310 ;; From: joe@y.z (Joe K
1312 ;; can yield `From joe@y.z (Joe K Fri Mar 22 08:11:15 1996', and
1315 ;; can yield `From Joe User Fri Mar 22 08:11:15 1996'.
1316 ;; The mailbox can be removed or be replaced by white space, e.g.
1317 ;; From: "Joe User"{space}{tab}
1319 ;; can yield `From {space}{tab} Fri Mar 22 08:11:15 1996',
1320 ;; where {space} and {tab} represent the Ascii space and tab characters.
1321 ;; We want to match the results of any of these manglings.
1322 ;; The following regexp rejects names whose first characters are
1323 ;; obviously bogus, but after that anything goes.
1324 "\\([^\0-\b\n-\r\^?].*\\)? "
1326 ;; The time the message was sent.
1327 "\\([^\0-\r \^?]+\\) +" ; day of the week
1328 "\\([^\0-\r \^?]+\\) +" ; month
1329 "\\([0-3]?[0-9]\\) +" ; day of month
1330 "\\([0-2][0-9]:[0-5][0-9]\\(:[0-6][0-9]\\)?\\) *" ; time of day
1332 ;; Perhaps a time zone, specified by an abbreviation, or by a
1337 " \\([0-9][0-9]+\\) *"
1339 ;; On some systems the time zone can appear after the year, too.
1343 "\\(remote from .*\\)?"
1346 "Regexp matching the delimiter of messages in UNIX mail format.")
1348 (defvar message-unsent-separator
1349 (concat "^ *---+ +Unsent message follows +---+ *$\\|"
1350 "^ *---+ +Returned message +---+ *$\\|"
1351 "^Start of returned message$\\|"
1352 "^ *---+ +Original message +---+ *$\\|"
1353 "^ *--+ +begin message +--+ *$\\|"
1354 "^ *---+ +Original message follows +---+ *$\\|"
1355 "^ *---+ +Undelivered message follows +---+ *$\\|"
1356 "^|? *---+ +Message text follows: +---+ *|?$")
1357 "A regexp that matches the separator before the text of a failed message.")
1359 (defvar message-header-format-alist
1361 (To . message-fill-address)
1362 (Cc . message-fill-address)
1373 (References . message-shorten-references)
1375 "Alist used for formatting headers.")
1377 (defvar message-options nil
1378 "Some saved answers when sending message.")
1381 (autoload 'message-setup-toolbar "messagexmas")
1382 (autoload 'mh-new-draft-name "mh-comp")
1383 (autoload 'mh-send-letter "mh-comp")
1384 (autoload 'gnus-point-at-eol "gnus-util")
1385 (autoload 'gnus-point-at-bol "gnus-util")
1386 (autoload 'gnus-output-to-rmail "gnus-util")
1387 (autoload 'gnus-output-to-mail "gnus-util")
1388 (autoload 'mail-abbrev-in-expansion-header-p "mailabbrev")
1389 (autoload 'nndraft-request-associate-buffer "nndraft")
1390 (autoload 'nndraft-request-expire-articles "nndraft")
1391 (autoload 'gnus-open-server "gnus-int")
1392 (autoload 'gnus-request-post "gnus-int")
1393 (autoload 'gnus-copy-article-buffer "gnus-msg")
1394 (autoload 'gnus-alive-p "gnus-util")
1395 (autoload 'gnus-group-name-charset "gnus-group")
1396 (autoload 'rmail-output "rmail")
1397 (autoload 'mu-cite-original "mu-cite"))
1402 ;;; Utility functions.
1404 (defun message-eval-parameter (parameter)
1406 (if (symbolp parameter)
1407 (if (functionp parameter)
1413 (defsubst message-get-parameter (key &optional alist)
1415 (setq alist message-parameter-alist))
1416 (cdr (assq key alist)))
1418 (defmacro message-get-parameter-with-eval (key &optional alist)
1419 `(message-eval-parameter (message-get-parameter ,key ,alist)))
1421 (defmacro message-y-or-n-p (question show &rest text)
1422 "Ask QUESTION, displaying the rest of the arguments in a temp. buffer if SHOW"
1423 `(message-talkative-question 'y-or-n-p ,question ,show ,@text))
1425 ;; Delete the current line (and the next N lines.);
1426 (defmacro message-delete-line (&optional n)
1427 `(delete-region (progn (beginning-of-line) (point))
1428 (progn (forward-line ,(or n 1)) (point))))
1430 (defun message-unquote-tokens (elems)
1431 "Remove double quotes (\") from strings in list."
1432 (mapcar (lambda (item)
1433 (while (string-match "^\\(.*\\)\"\\(.*\\)$" item)
1434 (setq item (concat (match-string 1 item)
1435 (match-string 2 item))))
1439 (defun message-tokenize-header (header &optional separator)
1440 "Split HEADER into a list of header elements.
1441 SEPARATOR is a string of characters to be used as separators. \",\"
1442 is used by default."
1445 (let ((regexp (format "[%s]+" (or separator ",")))
1450 (message-set-work-buffer)
1452 (goto-char (point-min))
1457 (cond ((and (> (point) beg)
1459 (and (looking-at regexp)
1462 (push (buffer-substring beg (point)) elems)
1463 (setq beg (match-end 0)))
1464 ((eq (char-after) ?\")
1465 (setq quoted (not quoted)))
1466 ((and (eq (char-after) ?\()
1469 ((and (eq (char-after) ?\))
1472 (nreverse elems)))))
1474 (defun message-mail-file-mbox-p (file)
1475 "Say whether FILE looks like a Unix mbox file."
1476 (when (and (file-exists-p file)
1477 (file-readable-p file)
1478 (file-regular-p file))
1480 (nnheader-insert-file-contents file)
1481 (goto-char (point-min))
1482 (looking-at message-unix-mail-delimiter))))
1484 (defun message-fetch-field (header &optional not-all)
1485 "The same as `mail-fetch-field', only remove all newlines."
1486 (let* ((inhibit-point-motion-hooks t)
1487 (case-fold-search t)
1488 (value (mail-fetch-field header nil (not not-all))))
1490 (while (string-match "\n[\t ]+" value)
1491 (setq value (replace-match " " t t value)))
1492 (set-text-properties 0 (length value) nil value)
1495 (defun message-narrow-to-field ()
1496 "Narrow the buffer to the header on the current line."
1502 (if (re-search-forward "^[^ \n\t]" nil t)
1507 (goto-char (point-min)))
1509 (defun message-add-header (&rest headers)
1510 "Add the HEADERS to the message header, skipping those already present."
1513 (unless (string-match "^\\([^:]+\\):[ \t]*[^ \t]" (car headers))
1514 (error "Invalid header `%s'" (car headers)))
1515 (setq hclean (match-string 1 (car headers)))
1517 (message-narrow-to-headers)
1518 (unless (re-search-forward (concat "^" (regexp-quote hclean) ":") nil t)
1519 (insert (car headers) ?\n))))
1520 (setq headers (cdr headers))))
1523 (defun message-fetch-reply-field (header)
1524 "Fetch FIELD from the message we're replying to."
1525 (let ((buffer (message-eval-parameter message-reply-buffer)))
1527 (buffer-name buffer))
1530 (message-fetch-field header)))))
1532 (defun message-set-work-buffer ()
1533 (if (get-buffer " *message work*")
1535 (set-buffer " *message work*")
1537 (set-buffer (get-buffer-create " *message work*"))
1538 (kill-all-local-variables)))
1540 (defun message-functionp (form)
1541 "Return non-nil if FORM is funcallable."
1542 (or (and (symbolp form) (fboundp form))
1543 (and (listp form) (eq (car form) 'lambda))
1544 (byte-code-function-p form)))
1546 (defun message-strip-list-identifiers (subject)
1547 "Remove list identifiers in `gnus-list-identifiers'."
1548 (require 'gnus-sum) ; for gnus-list-identifiers
1549 (let ((regexp (if (stringp gnus-list-identifiers)
1550 gnus-list-identifiers
1551 (mapconcat 'identity gnus-list-identifiers " *\\|"))))
1552 (if (string-match (concat "\\(\\(\\(Re: +\\)?\\(" regexp
1553 " *\\)\\)+\\(Re: +\\)?\\)") subject)
1554 (concat (substring subject 0 (match-beginning 1))
1555 (or (match-string 3 subject)
1556 (match-string 5 subject))
1561 (defun message-strip-subject-re (subject)
1562 "Remove \"Re:\" from subject lines."
1563 (if (string-match message-subject-re-regexp subject)
1564 (substring subject (match-end 0))
1567 (defun message-remove-header (header &optional is-regexp first reverse)
1568 "Remove HEADER in the narrowed buffer.
1569 If REGEXP, HEADER is a regular expression.
1570 If FIRST, only remove the first instance of the header.
1571 Return the number of headers removed."
1572 (goto-char (point-min))
1573 (let ((regexp (if is-regexp header (concat "^" (regexp-quote header) ":")))
1575 (case-fold-search t)
1577 (while (and (not (eobp))
1580 (not (looking-at regexp))
1581 (looking-at regexp))
1588 ;; There might be a continuation header, so we have to search
1589 ;; until we find a new non-continuation line.
1592 (if (re-search-forward "^[^ \t]" nil t)
1593 (goto-char (match-beginning 0))
1596 (if (re-search-forward "^[^ \t]" nil t)
1597 (goto-char (match-beginning 0))
1598 (goto-char (point-max)))))
1601 (defun message-remove-first-header (header)
1602 "Remove the first instance of HEADER if there is more than one."
1604 (regexp (concat "^" (regexp-quote header) ":")))
1606 (goto-char (point-min))
1607 (while (re-search-forward regexp nil t)
1610 (message-remove-header header nil t)
1613 (defun message-narrow-to-headers ()
1614 "Narrow the buffer to the head of the message."
1617 (goto-char (point-min))
1618 (if (re-search-forward
1619 (concat "^" (regexp-quote mail-header-separator) "\n") nil t)
1622 (goto-char (point-min)))
1624 (defun message-narrow-to-head ()
1625 "Narrow the buffer to the head of the message.
1626 Point is left at the beginning of the narrowed-to region."
1629 (goto-char (point-min))
1630 (if (search-forward "\n\n" nil 1)
1633 (goto-char (point-min)))
1635 (defun message-narrow-to-headers-or-head ()
1636 "Narrow the buffer to the head of the message."
1639 (goto-char (point-min))
1642 (concat "^" (regexp-quote mail-header-separator) "\n") nil t)
1643 (match-beginning 0))
1644 ((search-forward "\n\n" nil t)
1648 (goto-char (point-min)))
1650 (defun message-news-p ()
1651 "Say whether the current buffer contains a news message."
1652 (and (not message-this-is-mail)
1653 (or message-this-is-news
1656 (message-narrow-to-headers)
1657 (and (message-fetch-field "newsgroups")
1658 (not (message-fetch-field "posted-to"))))))))
1660 (defun message-mail-p ()
1661 "Say whether the current buffer contains a mail message."
1662 (and (not message-this-is-news)
1663 (or message-this-is-mail
1666 (message-narrow-to-headers)
1667 (or (message-fetch-field "to")
1668 (message-fetch-field "cc")
1669 (message-fetch-field "bcc")))))))
1671 (defun message-next-header ()
1672 "Go to the beginning of the next header."
1674 (or (eobp) (forward-char 1))
1675 (not (if (re-search-forward "^[^ \t]" nil t)
1677 (goto-char (point-max)))))
1679 (defun message-sort-headers-1 ()
1680 "Sort the buffer as headers using `message-rank' text props."
1681 (goto-char (point-min))
1684 nil 'message-next-header
1686 (message-next-header)
1690 (or (get-text-property (point) 'message-rank)
1693 (defun message-sort-headers ()
1694 "Sort the headers of the current message according to `message-header-format-alist'."
1698 (let ((max (1+ (length message-header-format-alist)))
1700 (message-narrow-to-headers)
1701 (while (re-search-forward "^[^ \n]+:" nil t)
1703 (match-beginning 0) (1+ (match-beginning 0))
1705 (if (setq rank (length (memq (assq (intern (buffer-substring
1707 (1- (match-end 0))))
1708 message-header-format-alist)
1709 message-header-format-alist)))
1712 (message-sort-headers-1))))
1722 (defvar message-mode-map nil)
1724 (unless message-mode-map
1725 (setq message-mode-map (make-keymap))
1726 (set-keymap-parent message-mode-map text-mode-map)
1727 (define-key message-mode-map "\C-c?" 'describe-mode)
1729 (define-key message-mode-map "\C-c\C-f\C-t" 'message-goto-to)
1730 (define-key message-mode-map "\C-c\C-f\C-b" 'message-goto-bcc)
1731 (define-key message-mode-map "\C-c\C-f\C-w" 'message-goto-fcc)
1732 (define-key message-mode-map "\C-c\C-f\C-c" 'message-goto-cc)
1733 (define-key message-mode-map "\C-c\C-f\C-s" 'message-goto-subject)
1734 ;; (define-key message-mode-map "\C-c\C-f\C-r" 'message-goto-reply-to)
1735 (define-key message-mode-map "\C-c\C-f\C-r" 'message-goto-mail-reply-to)
1736 (define-key message-mode-map "\C-c\C-f\C-m" 'message-goto-mail-followup-to)
1737 (define-key message-mode-map "\C-c\C-f\C-n" 'message-goto-newsgroups)
1738 (define-key message-mode-map "\C-c\C-f\C-d" 'message-goto-distribution)
1739 (define-key message-mode-map "\C-c\C-f\C-f" 'message-goto-followup-to)
1740 (define-key message-mode-map "\C-c\C-f\C-k" 'message-goto-keywords)
1741 (define-key message-mode-map "\C-c\C-f\C-u" 'message-goto-summary)
1742 (define-key message-mode-map "\C-c\C-b" 'message-goto-body)
1743 (define-key message-mode-map "\C-c\C-i" 'message-goto-signature)
1744 (define-key message-mode-map "\C-c\C-fc" 'message-goto-mail-copies-to)
1746 (define-key message-mode-map "\C-c\C-t" 'message-insert-to)
1747 (define-key message-mode-map "\C-c\C-n" 'message-insert-newsgroups)
1749 (define-key message-mode-map "\C-c\C-y" 'message-yank-original)
1750 (define-key message-mode-map "\C-c\M-\C-y" 'message-yank-buffer)
1751 (define-key message-mode-map "\C-c\C-q" 'message-fill-yanked-message)
1752 (define-key message-mode-map "\C-c\C-w" 'message-insert-signature)
1753 (define-key message-mode-map "\C-c\M-h" 'message-insert-headers)
1754 (define-key message-mode-map "\C-c\C-r" 'message-caesar-buffer-body)
1755 (define-key message-mode-map "\C-c\C-o" 'message-sort-headers)
1756 (define-key message-mode-map "\C-c\M-r" 'message-rename-buffer)
1758 (define-key message-mode-map "\C-c\C-c" 'message-send-and-exit)
1759 (define-key message-mode-map "\C-c\C-s" 'message-send)
1760 (define-key message-mode-map "\C-c\C-k" 'message-kill-buffer)
1761 (define-key message-mode-map "\C-c\C-d" 'message-dont-send)
1763 (define-key message-mode-map "\C-c\C-e" 'message-elide-region)
1764 (define-key message-mode-map "\C-c\C-v" 'message-delete-not-region)
1765 (define-key message-mode-map "\C-c\C-z" 'message-kill-to-signature)
1766 (define-key message-mode-map "\M-\r" 'message-newline-and-reformat)
1768 (define-key message-mode-map "\t" 'message-tab)
1770 (define-key message-mode-map "\C-x\C-s" 'message-save-drafts)
1771 (define-key message-mode-map "\C-xk" 'message-mimic-kill-buffer))
1774 message-mode-menu message-mode-map "Message Menu."
1776 ["Sort Headers" message-sort-headers t]
1777 ["Yank Original" message-yank-original t]
1778 ["Fill Yanked Message" message-fill-yanked-message t]
1779 ["Insert Signature" message-insert-signature t]
1780 ["Caesar (rot13) Message" message-caesar-buffer-body t]
1781 ["Caesar (rot13) Region" message-caesar-region (mark t)]
1782 ["Elide Region" message-elide-region (mark t)]
1783 ["Delete Outside Region" message-delete-not-region (mark t)]
1784 ["Kill To Signature" message-kill-to-signature t]
1785 ["Newline and Reformat" message-newline-and-reformat t]
1786 ["Rename buffer" message-rename-buffer t]
1787 ["Spellcheck" ispell-message t]
1788 ["Attach file as MIME" mime-edit-insert-file t]
1790 ["Send Message" message-send-and-exit t]
1791 ["Abort Message" message-dont-send t]
1792 ["Kill Message" message-kill-buffer t]))
1795 message-mode-field-menu message-mode-map ""
1797 ["Fetch To" message-insert-to t]
1798 ["Fetch Newsgroups" message-insert-newsgroups t]
1800 ["To" message-goto-to t]
1801 ["Subject" message-goto-subject t]
1802 ["Cc" message-goto-cc t]
1803 ["Reply-To" message-goto-reply-to t]
1804 ["Mail-Reply-To" message-goto-mail-reply-to t]
1805 ["Mail-Followup-To" message-goto-mail-followup-to t]
1806 ["Mail-Copies-To" message-goto-mail-copies-to t]
1807 ["Summary" message-goto-summary t]
1808 ["Keywords" message-goto-keywords t]
1809 ["Newsgroups" message-goto-newsgroups t]
1810 ["Followup-To" message-goto-followup-to t]
1811 ["Distribution" message-goto-distribution t]
1812 ["Body" message-goto-body t]
1813 ["Signature" message-goto-signature t]))
1815 (defvar facemenu-add-face-function)
1816 (defvar facemenu-remove-face-function)
1819 (defun message-mode ()
1820 "Major mode for editing mail and news to be sent.
1821 Like Text Mode but with these additional commands:
1822 C-c C-s message-send (send the message) C-c C-c message-send-and-exit
1823 C-c C-d Pospone sending the message C-c C-k Kill the message
1824 C-c C-f move to a header field (and create it if there isn't):
1825 C-c C-f C-t move to To C-c C-f C-s move to Subject
1826 C-c C-f C-c move to Cc C-c C-f C-b move to Bcc
1827 C-c C-f C-w move to Fcc C-c C-f C-r move to Reply-To
1828 C-c C-f C-u move to Summary C-c C-f C-n move to Newsgroups
1829 C-c C-f C-k move to Keywords C-c C-f C-d move to Distribution
1830 C-c C-f C-m move to Mail-Followup-To
1831 C-c C-f C-f move to Followup-To
1832 C-c C-t message-insert-to (add a To header to a news followup)
1833 C-c C-n message-insert-newsgroups (add a Newsgroup header to a news reply)
1834 C-c C-b message-goto-body (move to beginning of message text).
1835 C-c C-i message-goto-signature (move to the beginning of the signature).
1836 C-c C-w message-insert-signature (insert `message-signature-file' file).
1837 C-c C-y message-yank-original (insert current message, if any).
1838 C-c C-q message-fill-yanked-message (fill what was yanked).
1839 C-c C-e message-elide-region (elide the text between point and mark).
1840 C-c C-v message-delete-not-region (remove the text outside the region).
1841 C-c C-z message-kill-to-signature (kill the text up to the signature).
1842 C-c C-r message-caesar-buffer-body (rot13 the message body).
1843 M-RET message-newline-and-reformat (break the line and reformat)."
1845 (kill-all-local-variables)
1846 (set (make-local-variable 'message-reply-buffer) nil)
1847 (make-local-variable 'message-send-actions)
1848 (make-local-variable 'message-exit-actions)
1849 (make-local-variable 'message-kill-actions)
1850 (make-local-variable 'message-postpone-actions)
1851 (make-local-variable 'message-draft-article)
1852 (make-local-hook 'kill-buffer-hook)
1853 (set-syntax-table message-mode-syntax-table)
1854 (use-local-map message-mode-map)
1855 (setq local-abbrev-table message-mode-abbrev-table)
1856 (setq major-mode 'message-mode)
1857 (setq mode-name "Message")
1858 (setq buffer-offer-save t)
1859 (make-local-variable 'facemenu-add-face-function)
1860 (make-local-variable 'facemenu-remove-face-function)
1861 (setq facemenu-add-face-function
1863 (let ((face-fun (cdr (assq face message-face-alist))))
1865 (funcall face-fun (point) end)
1866 (error "Face %s not configured for %s mode" face mode-name)))
1868 facemenu-remove-face-function t)
1869 (make-local-variable 'message-reply-headers)
1870 (setq message-reply-headers nil)
1871 (make-local-variable 'message-user-agent)
1872 (make-local-variable 'message-post-method)
1873 (set (make-local-variable 'message-sent-message-via) nil)
1874 (set (make-local-variable 'message-checksum) nil)
1875 (make-local-variable 'message-parameter-alist)
1876 (setq message-parameter-alist
1877 (copy-sequence message-startup-parameter-alist))
1878 (message-setup-fill-variables)
1879 ;;(when (fboundp 'mail-hist-define-keys)
1880 ;; (mail-hist-define-keys))
1881 (if (featurep 'xemacs)
1882 (message-setup-toolbar)
1883 (set (make-local-variable 'font-lock-defaults)
1884 '((message-font-lock-keywords
1885 message-font-lock-keywords-1
1886 message-font-lock-keywords-2)
1888 (font-lock-mark-block-function . mark-paragraph))))
1889 (set (make-local-variable 'message-font-lock-last-position) nil)
1890 (easy-menu-add message-mode-menu message-mode-map)
1891 (easy-menu-add message-mode-field-menu message-mode-map)
1892 ;; Allow mail alias things.
1893 (when (eq message-mail-alias-type 'abbrev)
1894 (if (fboundp 'mail-abbrevs-setup)
1895 (mail-abbrevs-setup)
1896 (mail-aliases-setup)))
1897 (message-set-auto-save-file-name)
1898 (make-local-variable 'indent-tabs-mode) ;Turn off tabs for indentation.
1899 (setq indent-tabs-mode nil)
1900 (run-hooks 'text-mode-hook 'message-mode-hook))
1902 (defun message-setup-fill-variables ()
1903 "Setup message fill variables."
1904 (make-local-variable 'paragraph-separate)
1905 (make-local-variable 'paragraph-start)
1906 (make-local-variable 'adaptive-fill-regexp)
1907 (unless (boundp 'adaptive-fill-first-line-regexp)
1908 (setq adaptive-fill-first-line-regexp nil))
1909 (make-local-variable 'adaptive-fill-first-line-regexp)
1910 (make-local-variable 'auto-fill-inhibit-regexp)
1911 (let ((quote-prefix-regexp
1913 "[ \t]*" ; possible initial space
1914 "\\(\\(" (regexp-quote message-yank-prefix) "\\|" ; user's prefix
1915 "\\w+>\\|" ; supercite-style prefix
1916 "[|:>]" ; standard prefix
1917 "\\)[ \t]*\\)+"))) ; possible space after each prefix
1918 (setq paragraph-start
1920 (regexp-quote mail-header-separator) "$\\|"
1921 "[ \t]*$\\|" ; blank lines
1922 "-- $\\|" ; signature delimiter
1923 "---+$\\|" ; delimiters for forwarded messages
1924 page-delimiter "$\\|" ; spoiler warnings
1925 ".*wrote:$\\|" ; attribution lines
1926 quote-prefix-regexp "$")) ; empty lines in quoted text
1927 (setq paragraph-separate paragraph-start)
1928 (setq adaptive-fill-regexp
1929 (concat quote-prefix-regexp "\\|" adaptive-fill-regexp))
1930 (setq adaptive-fill-first-line-regexp
1931 (concat quote-prefix-regexp "\\|"
1932 adaptive-fill-first-line-regexp))
1933 (setq auto-fill-inhibit-regexp "^[A-Z][^: \n\t]+:")))
1938 ;;; Message mode commands
1941 ;;; Movement commands
1943 (defun message-goto-to ()
1944 "Move point to the To header."
1946 (message-position-on-field "To"))
1948 (defun message-goto-subject ()
1949 "Move point to the Subject header."
1951 (message-position-on-field "Subject"))
1953 (defun message-goto-cc ()
1954 "Move point to the Cc header."
1956 (message-position-on-field "Cc" "To"))
1958 (defun message-goto-bcc ()
1959 "Move point to the Bcc header."
1961 (message-position-on-field "Bcc" "Cc" "To"))
1963 (defun message-goto-fcc ()
1964 "Move point to the Fcc header."
1966 (message-position-on-field "Fcc" "To" "Newsgroups"))
1968 (defun message-goto-reply-to ()
1969 "Move point to the Reply-To header."
1971 (message-position-on-field "Reply-To" "Subject"))
1973 (defun message-goto-mail-reply-to ()
1974 "Move point to the Mail-Reply-To header."
1976 (message-position-on-field "Mail-Reply-To" "Subject"))
1978 (defun message-goto-mail-followup-to ()
1979 "Move point to the Mail-Followup-To header. If the header is newly created
1980 and To field contains only one address, the address is inserted in default."
1982 (unless (message-position-on-field "Mail-Followup-To" "Subject")
1983 (let ((start (point))
1986 (message-narrow-to-headers)
1987 (setq addresses (split-string (mail-strip-quoted-names
1988 (or (std11-fetch-field "to") ""))
1990 (when (eq 1 (length addresses))
1992 (insert (car addresses))
1993 (goto-char start))))))
1995 (defun message-goto-mail-copies-to ()
1996 "Move point to the Mail-Copies-To header. If the header is newly created,
1997 a string \"never\" is inserted in default."
1999 (unless (message-position-on-field "Mail-Copies-To" "Subject")
2003 (defun message-goto-newsgroups ()
2004 "Move point to the Newsgroups header."
2006 (message-position-on-field "Newsgroups"))
2008 (defun message-goto-distribution ()
2009 "Move point to the Distribution header."
2011 (message-position-on-field "Distribution"))
2013 (defun message-goto-followup-to ()
2014 "Move point to the Followup-To header."
2016 (message-position-on-field "Followup-To" "Newsgroups"))
2018 (defun message-goto-keywords ()
2019 "Move point to the Keywords header."
2021 (message-position-on-field "Keywords" "Subject"))
2023 (defun message-goto-summary ()
2024 "Move point to the Summary header."
2026 (message-position-on-field "Summary" "Subject"))
2028 (defun message-goto-body ()
2029 "Move point to the beginning of the message body."
2031 (if (looking-at "[ \t]*\n") (expand-abbrev))
2032 (goto-char (point-min))
2033 (or (search-forward (concat "\n" mail-header-separator "\n") nil t)
2034 (search-forward "\n\n" nil t)))
2036 (defun message-goto-eoh ()
2037 "Move point to the end of the headers."
2042 (defun message-goto-signature ()
2043 "Move point to the beginning of the message signature.
2044 If there is no signature in the article, go to the end and
2047 (goto-char (point-min))
2048 (if (re-search-forward message-signature-separator nil t)
2050 (goto-char (point-max))
2055 (defun message-insert-to (&optional force)
2056 "Insert a To header that points to the author of the article being replied to.
2057 If the original author requested not to be sent mail, the function signals
2059 With the prefix argument FORCE, insert the header anyway."
2061 (let ((co (message-fetch-reply-field "mail-copies-to")))
2062 (when (and (null force)
2064 (or (equal (downcase co) "never")
2065 (equal (downcase co) "nobody")))
2066 (error "The user has requested not to have copies sent via mail")))
2067 (when (and (message-position-on-field "To")
2068 (mail-fetch-field "to")
2069 (not (string-match "\\` *\\'" (mail-fetch-field "to"))))
2071 (insert (or (message-fetch-reply-field "mail-reply-to")
2072 (message-fetch-reply-field "reply-to")
2073 (message-fetch-reply-field "from") "")))
2075 (defun message-widen-reply ()
2076 "Widen the reply to include maximum recipients."
2079 (and message-reply-buffer
2080 (buffer-name message-reply-buffer)
2082 (set-buffer message-reply-buffer)
2083 (message-get-reply-headers t)))))
2086 (message-narrow-to-headers)
2087 (dolist (elem follow-to)
2088 (message-remove-header (symbol-name (car elem)))
2089 (goto-char (point-min))
2090 (insert (symbol-name (car elem)) ": "
2091 (cdr elem) "\n"))))))
2093 (defun message-insert-newsgroups ()
2094 "Insert the Newsgroups header from the article being replied to."
2096 (when (and (message-position-on-field "Newsgroups")
2097 (mail-fetch-field "newsgroups")
2098 (not (string-match "\\` *\\'" (mail-fetch-field "newsgroups"))))
2100 (insert (or (message-fetch-reply-field "newsgroups") "")))
2104 ;;; Various commands
2106 (defun message-delete-not-region (beg end)
2107 "Delete everything in the body of the current message that is outside of the region."
2111 (delete-region (point) (if (not (message-goto-signature))
2117 (delete-region beg (progn (message-goto-body)
2120 (when (message-goto-signature)
2123 (defun message-kill-to-signature ()
2124 "Deletes all text up to the signature."
2126 (let ((point (point)))
2127 (message-goto-signature)
2130 (kill-region point (point))
2134 (defun message-newline-and-reformat ()
2135 "Insert four newlines, and then reformat if inside quoted text."
2137 (let ((prefix "[]>»|:}+ \t]*")
2138 (supercite-thing "[-._a-zA-Z0-9]*[>]+[ \t]*")
2143 (when (looking-at (concat prefix
2145 (setq quoted (match-string 0))))
2147 (setq point (point))
2149 (delete-region (point) (re-search-forward "[ \t]*"))
2152 (fill-paragraph nil)
2156 (defun message-insert-signature (&optional force)
2157 "Insert a signature. See documentation for the `message-signature' variable."
2158 (interactive (list 0))
2161 ((and (null message-signature)
2164 (goto-char (point-max))
2165 (not (re-search-backward message-signature-separator nil t))))
2166 ((and (null message-signature)
2169 ((message-functionp message-signature)
2170 (funcall message-signature))
2171 ((listp message-signature)
2172 (eval message-signature))
2173 (t message-signature)))
2175 (cond ((stringp signature)
2177 ((and (eq t signature)
2178 message-signature-file
2179 (file-exists-p message-signature-file))
2182 (goto-char (point-max))
2183 ;; Insert the signature.
2187 (if (eq signature t)
2188 (insert-file-contents message-signature-file)
2190 (goto-char (point-max))
2191 (or (bolp) (insert "\n")))))
2193 (defun message-elide-region (b e)
2194 "Elide the text between point and mark.
2195 An ellipsis (from `message-elide-ellipsis') will be inserted where the
2199 (insert message-elide-ellipsis))
2201 (defvar message-caesar-translation-table nil)
2203 (defun message-caesar-region (b e &optional n)
2204 "Caesar rotation of region by N, default 13, for decrypting netnews."
2207 (min (point) (or (mark t) (point)))
2208 (max (point) (or (mark t) (point)))
2209 (when current-prefix-arg
2210 (prefix-numeric-value current-prefix-arg))))
2212 (setq n (if (numberp n) (mod n 26) 13)) ;canonize N
2213 (unless (or (zerop n) ; no action needed for a rot of 0
2214 (= b e)) ; no region to rotate
2215 ;; We build the table, if necessary.
2216 (when (or (not message-caesar-translation-table)
2217 (/= (aref message-caesar-translation-table ?a) (+ ?a n)))
2218 (setq message-caesar-translation-table
2219 (message-make-caesar-translation-table n)))
2220 (translate-region b e message-caesar-translation-table)))
2222 (defun message-make-caesar-translation-table (n)
2223 "Create a rot table with offset N."
2225 (table (make-string 256 0)))
2226 (while (< (incf i) 256)
2229 (substring table 0 ?A)
2230 (substring table (+ ?A n) (+ ?A n (- 26 n)))
2231 (substring table ?A (+ ?A n))
2232 (substring table (+ ?A 26) ?a)
2233 (substring table (+ ?a n) (+ ?a n (- 26 n)))
2234 (substring table ?a (+ ?a n))
2235 (substring table (+ ?a 26) 255))))
2237 (defun message-caesar-buffer-body (&optional rotnum)
2238 "Caesar rotates all letters in the current buffer by 13 places.
2239 Used to encode/decode possiblyun offensive messages (commonly in net.jokes).
2240 With prefix arg, specifies the number of places to rotate each letter forward.
2241 Mail and USENET news headers are not rotated."
2242 (interactive (if current-prefix-arg
2243 (list (prefix-numeric-value current-prefix-arg))
2247 (when (message-goto-body)
2248 (narrow-to-region (point) (point-max)))
2249 (message-caesar-region (point-min) (point-max) rotnum))))
2251 (defun message-pipe-buffer-body (program)
2252 "Pipe the message body in the current buffer through PROGRAM."
2255 (when (message-goto-body)
2256 (narrow-to-region (point) (point-max)))
2257 (shell-command-on-region
2258 (point-min) (point-max) program nil t))))
2260 (defun message-rename-buffer (&optional enter-string)
2261 "Rename the *message* buffer to \"*message* RECIPIENT\".
2262 If the function is run with a prefix, it will ask for a new buffer
2263 name, rather than giving an automatic name."
2264 (interactive "Pbuffer name: ")
2267 (goto-char (point-min))
2268 (narrow-to-region (point)
2269 (search-forward mail-header-separator nil 'end))
2271 (if (message-news-p) (message-fetch-field "Newsgroups")
2272 (message-fetch-field "To"))
2275 (if (string-match "," mail-to)
2276 (concat (substring mail-to 0 (match-beginning 0)) ", ...")
2278 (name-default (concat "*message* " mail-trimmed-to))
2279 (name (if enter-string
2280 (read-string "New buffer name: " name-default)
2282 (rename-buffer name t)))))
2284 (defun message-fill-yanked-message (&optional justifyp)
2285 "Fill the paragraphs of a message yanked into this one.
2286 Numeric argument means justify as well."
2289 (goto-char (point-min))
2290 (search-forward (concat "\n" mail-header-separator "\n") nil t)
2291 (let ((fill-prefix message-yank-prefix))
2292 (fill-individual-paragraphs (point) (point-max) justifyp))))
2294 (defun message-indent-citation ()
2295 "Modify text just inserted from a message to be cited.
2296 The inserted text should be the region.
2297 When this function returns, the region is again around the modified text.
2299 Normally, indent each nonblank line `message-indentation-spaces' spaces.
2300 However, if `message-yank-prefix' is non-nil, insert that prefix on each line."
2301 (let ((start (point)))
2302 ;; Remove unwanted headers.
2303 (when message-ignored-cited-headers
2308 (if (search-forward "\n\n" nil t)
2311 (message-remove-header message-ignored-cited-headers t)
2312 (when (= (point-min) (point-max))
2313 (setq all-removed t))
2314 (goto-char (point-max)))
2318 ;; Delete blank lines at the start of the buffer.
2319 (while (and (point-min)
2322 (message-delete-line))
2323 ;; Delete blank lines at the end of the buffer.
2324 (goto-char (point-max))
2327 (while (and (zerop (forward-line -1))
2329 (message-delete-line))
2330 ;; Do the indentation.
2331 (if (null message-yank-prefix)
2332 (indent-rigidly start (mark t) message-indentation-spaces)
2335 (while (< (point) (mark t))
2336 (insert message-yank-prefix)
2340 (defun message-list-references (refs-list &rest refs-strs)
2341 "Add `Message-ID's which appear in REFS-STRS but not in REFS-LIST,
2343 (let (refs ref id saved-id)
2344 (when (and refs-list
2345 (integerp message-list-references-add-position))
2346 (let ((pos message-list-references-add-position))
2347 (while (and refs-list
2349 (push (pop refs-list) saved-id)
2350 (setq pos (1- pos)))))
2352 (when (setq refs (pop refs-strs))
2353 (setq refs (std11-parse-msg-ids (std11-lexical-analyze refs)))
2355 (when (eq (car (setq ref (pop refs))) 'msg-id)
2356 (setq id (concat "<" (mapconcat 'cdr (cdr ref) "") ">"))
2357 (or (member id refs-list)
2358 (member id saved-id)
2359 (push id refs-list))))))
2361 (push (pop saved-id) refs-list))
2364 (defvar gnus-article-copy)
2365 (defun message-yank-original (&optional arg)
2366 "Insert the message being replied to, if any.
2367 Puts point before the text and mark after.
2368 Normally indents each nonblank line ARG spaces (default 3). However,
2369 if `message-yank-prefix' is non-nil, insert that prefix on each line.
2371 This function uses `message-cite-function' to do the actual citing.
2373 Just \\[universal-argument] as argument means don't indent, insert no
2374 prefix, and don't delete any headers.
2376 In addition, if `message-yank-add-new-references' is non-nil and this
2377 command is called interactively, new IDs from the yanked article will
2378 be added to \"References\" field.
2379 \(See also `message-yank-add-new-references'.)"
2381 (let ((modified (buffer-modified-p))
2382 (buffer (message-eval-parameter message-reply-buffer))
2385 message-cite-function)
2386 (delete-windows-on buffer t)
2387 (insert-buffer buffer) ; mark will be set at the end of article.
2391 ;; Add new IDs to References field.
2392 (when (and message-yank-add-new-references (interactive-p))
2395 (message-narrow-to-headers)
2396 (setq refs (message-list-references
2398 (message-fetch-field "References")))
2400 (narrow-to-region start end)
2401 (std11-narrow-to-header)
2402 (when (setq refs (message-list-references
2404 (unless (eq message-yank-add-new-references
2406 (or (message-fetch-field "References")
2407 (message-fetch-field "In-Reply-To")))
2408 (message-fetch-field "Message-ID")))
2410 (message-narrow-to-headers)
2411 (goto-char (point-min))
2412 (let ((case-fold-search t))
2413 (if (re-search-forward "^References:\\([\t ]+.+\n\\)+" nil t)
2415 (goto-char (point-max))))
2417 (list (or (assq 'References message-header-format-alist)
2418 '(References . message-fill-references)))
2419 (list (cons 'References
2420 (mapconcat 'identity (nreverse refs) " "))))
2421 (backward-delete-char 1)))))
2423 (funcall message-cite-function)
2424 (message-exchange-point-and-mark)
2428 (setq message-checksum (message-checksum))))))
2430 (defun message-yank-buffer (buffer)
2431 "Insert BUFFER into the current buffer and quote it."
2432 (interactive "bYank buffer: ")
2433 (let ((message-reply-buffer buffer))
2434 (save-window-excursion
2435 (message-yank-original))))
2437 (defun message-buffers ()
2438 "Return a list of active message buffers."
2441 (dolist (buffer (buffer-list t))
2443 (when (and (eq major-mode 'message-mode)
2444 (null message-sent-message-via))
2445 (push (buffer-name buffer) buffers))))
2446 (nreverse buffers)))
2448 (defun message-cite-original-without-signature ()
2449 "Cite function in the standard Message manner."
2450 (let ((start (point))
2453 (when message-indent-citation-function
2454 (if (listp message-indent-citation-function)
2455 message-indent-citation-function
2456 (list message-indent-citation-function)))))
2460 (when (re-search-backward message-signature-separator start t)
2461 ;; Also peel off any blank lines before the signature.
2463 (while (looking-at "^[ \t]*$")
2466 (delete-region (point) end))
2469 (funcall (pop functions)))
2470 (when message-citation-line-function
2473 (funcall message-citation-line-function))))
2475 (defvar mail-citation-hook) ;Compiler directive
2476 (defun message-cite-original ()
2477 "Cite function in the standard Message manner."
2478 (if (and (boundp 'mail-citation-hook)
2480 (run-hooks 'mail-citation-hook)
2481 (let ((start (point))
2484 (when message-indent-citation-function
2485 (if (listp message-indent-citation-function)
2486 message-indent-citation-function
2487 (list message-indent-citation-function))))
2488 (message-reply-headers (or message-reply-headers
2489 (make-mail-header))))
2490 (mail-header-set-from message-reply-headers
2494 (if (search-forward "\n\n" nil t)
2497 (or (message-fetch-field "from")
2501 (funcall (pop functions)))
2502 (when message-citation-line-function
2505 (funcall message-citation-line-function)))))
2507 (defun message-insert-citation-line ()
2508 "Function that inserts a simple citation line."
2509 (when message-reply-headers
2510 (insert (mail-header-from message-reply-headers) " writes:\n\n")))
2512 (defun message-position-on-field (header &rest afters)
2513 (let ((case-fold-search t))
2516 (goto-char (point-min))
2519 (concat "^" (regexp-quote mail-header-separator) "$"))
2520 (match-beginning 0)))
2521 (goto-char (point-min))
2522 (if (re-search-forward (concat "^" (regexp-quote header) ":") nil t)
2524 (re-search-forward "^[^ \t]" nil 'move)
2526 (skip-chars-backward "\n")
2529 (not (re-search-forward
2530 (concat "^" (regexp-quote (car afters)) ":")
2534 (re-search-forward "^[^ \t]" nil 'move)
2535 (beginning-of-line))
2536 (insert header ": \n")
2540 (defun message-remove-signature ()
2541 "Remove the signature from the text between point and mark.
2542 The text will also be indented the normal way."
2544 (let ((start (point))
2546 (if (not (re-search-forward message-signature-separator (mark t) t))
2547 ;; No signature here, so we just indent the cited text.
2548 (message-indent-citation)
2549 ;; Find the last non-empty line.
2551 (while (looking-at "[ \t]*$")
2554 (setq mark (set-marker (make-marker) (point)))
2556 (message-indent-citation)
2557 ;; Enable undoing the deletion.
2559 (delete-region mark (mark t))
2560 (set-marker mark nil)))))
2565 ;;; Sending messages
2568 ;; Avoid byte-compile warning.
2569 (defvar message-encoding-buffer nil)
2570 (defvar message-edit-buffer nil)
2571 (defvar message-mime-mode nil)
2573 (defun message-send-and-exit (&optional arg)
2574 "Send message like `message-send', then, if no errors, exit from mail buffer."
2576 (let ((buf (current-buffer))
2577 (actions message-exit-actions)
2578 (frame (selected-frame))
2579 (org-frame message-original-frame))
2580 (when (and (message-send arg)
2582 (if message-kill-buffer-on-exit
2585 (when (eq buf (current-buffer))
2586 (message-bury buf)))
2587 (message-do-actions actions)
2588 (message-delete-frame frame org-frame)
2591 (defun message-dont-send ()
2592 "Don't send the message you have been editing."
2594 (message-save-drafts)
2595 (let ((actions message-postpone-actions)
2596 (frame (selected-frame))
2597 (org-frame message-original-frame))
2598 (message-bury (current-buffer))
2599 (message-do-actions actions)
2600 (message-delete-frame frame org-frame)))
2602 (defun message-kill-buffer ()
2603 "Kill the current buffer."
2605 (when (or (not (buffer-modified-p))
2606 (eq t message-kill-buffer-query-function)
2607 (funcall message-kill-buffer-query-function
2608 "The buffer modified; kill anyway? "))
2609 (let ((actions message-kill-actions)
2610 (frame (selected-frame))
2611 (org-frame message-original-frame))
2612 (setq buffer-file-name nil)
2613 (kill-buffer (current-buffer))
2614 (message-do-actions actions)
2615 (message-delete-frame frame org-frame)))
2618 (defun message-mimic-kill-buffer ()
2619 "Kill the current buffer with query."
2621 (unless (eq 'message-mode major-mode)
2622 (error "%s must be invoked from a message buffer." this-command))
2623 (let ((command this-command)
2624 (bufname (read-buffer (format "Kill buffer: (default %s) "
2626 (if (or (not bufname)
2627 (string-equal bufname "")
2628 (string-equal bufname (buffer-name)))
2629 (message-kill-buffer)
2630 (message "%s must be invoked only for the current buffer." command))))
2632 (defun message-delete-frame (frame org-frame)
2633 "Delete frame for editing message."
2634 (when (and (or (static-if (featurep 'xemacs)
2635 (device-on-window-system-p)
2637 (>= emacs-major-version 20))
2638 (or (and (eq message-delete-frame-on-exit t)
2639 (select-frame frame)
2640 (or (eq frame org-frame)
2642 (y-or-n-p "Delete this frame?")
2644 (and (eq message-delete-frame-on-exit 'ask)
2645 (select-frame frame)
2647 (y-or-n-p "Delete this frame?")
2649 (delete-frame frame)))
2651 (defun message-bury (buffer)
2652 "Bury this mail buffer."
2653 (let ((newbuf (other-buffer buffer)))
2654 (bury-buffer buffer)
2655 (if (and (fboundp 'frame-parameters)
2656 (cdr (assq 'dedicated (frame-parameters)))
2657 (not (null (delq (selected-frame) (visible-frame-list)))))
2658 (delete-frame (selected-frame))
2659 (switch-to-buffer newbuf))))
2661 (defun message-send (&optional arg)
2662 "Send the message in the current buffer.
2663 If `message-interactive' is non-nil, wait for success indication or
2664 error messages, and inform user.
2665 Otherwise any failure is reported in a message back to the user from
2667 The usage of ARG is defined by the instance that called Message.
2668 It should typically alter the sending method in some way or other."
2671 (when (or (buffer-modified-p)
2672 (message-check-element 'unchanged)
2673 (y-or-n-p "No changes in the buffer; really send? "))
2674 ;; Make it possible to undo the coming changes.
2676 (let ((inhibit-read-only t))
2677 (put-text-property (point-min) (point-max) 'read-only nil))
2678 (run-hooks 'message-send-hook)
2679 (message-fix-before-sending)
2680 (message message-sending-message)
2681 (let ((message-encoding-buffer
2682 (message-generate-new-buffer-clone-locals " message encoding"))
2683 (message-edit-buffer (current-buffer))
2684 (message-mime-mode mime-edit-mode-flag)
2685 (alist message-send-method-alist)
2688 (message-options message-options))
2689 (message-options-set-recipient)
2691 (set-buffer message-encoding-buffer)
2693 ;; Avoid copying text props.
2694 (insert (with-current-buffer message-edit-buffer
2695 (buffer-substring-no-properties (point-min) (point-max))))
2696 (funcall message-encode-function)
2698 (setq elem (pop alist)))
2699 (when (funcall (cadr elem))
2700 (when (and (or (not (memq (car elem)
2701 message-sent-message-via))
2702 (if (or (message-gnksa-enable-p 'multiple-copies)
2703 (not (eq (car elem) 'news)))
2706 "Already sent message via %s; resend? "
2708 (error "Denied posting -- multiple copies.")))
2709 (setq success (funcall (caddr elem) arg)))
2711 (unless (or sent (not success))
2712 (error "No methods specified to send by"))
2714 (when (and success sent)
2717 (run-hooks 'message-sent-hook))
2718 (message "Sending...done")
2719 ;; Mark the buffer as unmodified and delete auto-save.
2720 (set-buffer-modified-p nil)
2721 (delete-auto-save-file-if-necessary t)
2722 (message-disassociate-draft)
2723 ;; Delete other mail buffers and stuff.
2724 (message-do-send-housekeeping)
2725 (message-do-actions message-send-actions)
2728 (kill-buffer message-encoding-buffer)))))
2730 (defun message-send-via-mail (arg)
2731 "Send the current message via mail."
2732 (message-send-mail arg))
2734 (defun message-send-via-news (arg)
2735 "Send the current message via news."
2736 (message-send-news arg))
2738 (defmacro message-check (type &rest forms)
2739 "Eval FORMS if TYPE is to be checked."
2740 `(or (message-check-element ,type)
2744 (put 'message-check 'lisp-indent-function 1)
2745 (put 'message-check 'edebug-form-spec '(form body))
2747 ;; This function will be used by MIME-Edit when inserting invisible parts.
2748 (defun message-invisible-region (start end)
2749 (if (featurep 'xemacs)
2752 (eq (following-char) ?\n))
2753 (setq start (1+ start)))
2755 (goto-char (1- end))
2756 (eq (following-char) ?\n))
2757 (setq end (1- end))))
2758 (put-text-property start end 'invisible t)
2759 (if (eq 'message-mode major-mode)
2760 (put-text-property start end 'message-invisible t)))
2762 (eval-after-load "invisible"
2763 '(defalias 'invisible-region 'message-invisible-region))
2765 (defun message-fix-before-sending ()
2766 "Do various things to make the message nice before sending it."
2767 ;; Make sure there's a newline at the end of the message.
2769 (goto-char (point-max))
2772 ;; Expose all invisible text with the property `message-invisible'.
2773 ;; We should believe that the things might be created by MIME-Edit.
2775 (while (setq start (text-property-any (point-min) (point-max)
2776 'message-invisible t))
2777 (remove-text-properties start
2778 (or (text-property-not-all start (point-max)
2779 'message-invisible t)
2781 '(invisible nil message-invisible nil))))
2782 ;; Expose all invisible text.
2783 (message-check 'invisible-text
2784 (when (text-property-any (point-min) (point-max) 'invisible t)
2785 (put-text-property (point-min) (point-max) 'invisible nil)
2786 (unless (yes-or-no-p
2787 "Invisible text found and made visible; continue posting? ")
2788 (error "Invisible text found and made visible")))))
2790 (defun message-add-action (action &rest types)
2791 "Add ACTION to be performed when doing an exit of type TYPES."
2794 (set (setq var (intern (format "message-%s-actions" (pop types))))
2795 (nconc (symbol-value var) (list action))))))
2797 (defun message-do-actions (actions)
2798 "Perform all actions in ACTIONS."
2799 ;; Now perform actions on successful sending.
2803 ;; A simple function.
2804 ((message-functionp (car actions))
2805 (funcall (car actions)))
2806 ;; Something to be evaled.
2808 (eval (car actions)))))
2811 (defsubst message-maybe-split-and-send-mail ()
2812 "Split a message if necessary, and send it via mail.
2813 Returns nil if sending succeeded, returns any string if sending failed.
2814 This sub function is for exclusive use of `message-send-mail'."
2815 (let ((mime-edit-split-ignored-field-regexp
2816 mime-edit-split-ignored-field-regexp)
2817 (case-fold-search t)
2819 (while (string-match "Message-ID" mime-edit-split-ignored-field-regexp)
2820 (setq mime-edit-split-ignored-field-regexp
2821 (concat (substring mime-edit-split-ignored-field-regexp
2822 0 (match-beginning 0))
2823 "Hey_MIME-Edit,_there_is_an_inviolable_Message_ID"
2824 "_so_don't_rape_it!"
2825 (substring mime-edit-split-ignored-field-regexp
2829 (catch 'message-sending-mail-failure
2830 (mime-edit-maybe-split-and-send
2835 (std11-narrow-to-header mail-header-separator)
2836 (goto-char (point-min))
2837 (when (re-search-forward "^Message-ID:" nil t)
2838 (delete-region (match-end 0) (std11-field-end))
2839 (insert " " (message-make-message-id))))
2841 (funcall message-send-mail-function)
2843 (throw 'message-sending-mail-failure err))))))
2847 (funcall message-send-mail-function)
2851 (if (eq 'error (car failure))
2853 (prin1-to-string failure)))))
2855 (defun message-send-mail-partially ()
2856 "Sendmail as message/partial."
2857 ;; replace the header delimiter with a blank line
2858 (goto-char (point-min))
2860 (concat "^" (regexp-quote mail-header-separator) "\n"))
2861 (replace-match "\n")
2862 (run-hooks 'message-send-mail-hook)
2863 (let ((p (goto-char (point-min)))
2864 (tembuf (message-generate-new-buffer-clone-locals " message temp"))
2865 (curbuf (current-buffer))
2866 (id (message-make-message-id)) (n 1)
2867 plist total header required-mail-headers)
2869 (if (< (point-max) (+ p message-send-mail-partially-limit))
2870 (goto-char (point-max))
2871 (goto-char (+ p message-send-mail-partially-limit))
2873 (if (<= (point) p) (forward-line 1))) ;; In case of bad message.
2876 (setq total (length plist))
2877 (push (point-max) plist)
2878 (setq plist (nreverse plist))
2881 (setq p (pop plist))
2884 (copy-to-buffer tembuf p (car plist))
2886 (goto-char (point-min))
2889 (goto-char (point-min))
2890 (narrow-to-region (point) (point))
2893 (setq header (buffer-substring (point-min) (point)))
2894 (goto-char (point-min))
2895 (narrow-to-region (point) (point))
2897 (message-remove-header "Mime-Version")
2898 (message-remove-header "Content-Type")
2899 (message-remove-header "Content-Transfer-Encoding")
2900 (message-remove-header "Message-ID")
2901 (message-remove-header "Lines")
2902 (goto-char (point-max))
2903 (insert "Mime-Version: 1.0\n")
2904 (setq header (buffer-substring (point-min) (point-max))))
2905 (goto-char (point-max))
2906 (insert (format "Content-Type: message/partial; id=\"%s\"; number=%d; total=%d\n"
2908 (let ((mail-header-separator ""))
2909 (when (memq 'Message-ID message-required-mail-headers)
2910 (insert "Message-ID: " (message-make-message-id) "\n"))
2911 (when (memq 'Lines message-required-mail-headers)
2912 (let ((mail-header-separator ""))
2913 (insert "Lines: " (message-make-lines) "\n")))
2914 (message-goto-subject)
2916 (insert (format " (%d/%d)" n total))
2917 (goto-char (point-max))
2920 (mm-with-unibyte-current-buffer
2921 (funcall message-send-mail-function)))
2923 (setq p (pop plist))
2925 (kill-buffer tembuf))))
2927 (defun message-send-mail (&optional arg)
2928 (require 'mail-utils)
2929 (let* ((tembuf (message-generate-new-buffer-clone-locals " message temp"))
2930 (case-fold-search nil)
2931 (news (message-news-p))
2932 (message-this-is-mail t)
2935 (message-narrow-to-headers)
2936 ;; Insert some headers.
2937 (let ((message-deletable-headers
2938 (if news nil message-deletable-headers)))
2939 (message-generate-headers message-required-mail-headers))
2940 ;; Let the user do all of the above.
2941 (run-hooks 'message-header-hook))
2942 (if (not (message-check-mail-syntax))
2950 (insert-buffer message-encoding-buffer)
2951 ;; Remove some headers.
2953 (message-narrow-to-headers)
2954 ;; We Semi-gnus people have no use for it.
2955 ;; ;; We (re)generate the Lines header.
2956 ;; (when (memq 'Lines message-required-mail-headers)
2957 ;; (message-generate-headers '(Lines)))
2958 ;; Remove some headers.
2959 (message-remove-header message-ignored-mail-headers t))
2960 (goto-char (point-max))
2961 ;; require one newline at the end.
2962 (or (= (preceding-char) ?\n)
2966 (message-narrow-to-headers)
2968 (or (message-fetch-field "cc")
2969 (message-fetch-field "to"))
2970 (let ((ct (mime-read-Content-Type)))
2971 (and (eq 'text (cdr (assq 'type ct)))
2972 (eq 'plain (cdr (assq 'subtype ct)))))))
2973 (message-insert-courtesy-copy))
2974 (setq failure (message-maybe-split-and-send-mail)))
2975 (kill-buffer tembuf))
2976 (set-buffer message-edit-buffer)
2979 (message "Couldn't send message via mail: %s" failure)
2981 (push 'mail message-sent-message-via)))))
2983 (defun message-send-mail-with-sendmail ()
2984 "Send off the prepared buffer with sendmail."
2985 (let ((errbuf (if message-interactive
2986 (message-generate-new-buffer-clone-locals
2989 resend-to-addresses delimline)
2990 (let ((case-fold-search t))
2992 (message-narrow-to-headers)
2993 (setq resend-to-addresses (message-fetch-field "resent-to")))
2994 ;; Change header-delimiter to be what sendmail expects.
2995 (goto-char (point-min))
2997 (concat "^" (regexp-quote mail-header-separator) "\n"))
2998 (replace-match "\n")
3000 (setq delimline (point-marker))
3001 (run-hooks 'message-send-mail-hook)
3002 ;; Insert an extra newline if we need it to work around
3003 ;; Sun's bug that swallows newlines.
3004 (goto-char (1+ delimline))
3005 (when (eval message-mailer-swallows-blank-line)
3007 (when message-interactive
3011 (let ((default-directory "/"))
3013 (apply 'call-process-region
3014 (append (list (point-min) (point-max)
3015 (if (boundp 'sendmail-program)
3017 "/usr/lib/sendmail")
3018 nil errbuf nil "-oi")
3019 ;; Always specify who from,
3020 ;; since some systems have broken sendmails.
3021 ;; But some systems are more broken with -f, so
3022 ;; we'll let users override this.
3023 (if (null message-sendmail-f-is-evil)
3024 (list "-f" (message-make-address)))
3025 ;; These mean "report errors by mail"
3026 ;; and "deliver in background".
3027 (if (null message-interactive) '("-oem" "-odb"))
3028 ;; Get the addresses from the message
3029 ;; unless this is a resend.
3030 ;; We must not do that for a resend
3031 ;; because we would find the original addresses.
3032 ;; For a resend, include the specific addresses.
3033 (if resend-to-addresses
3034 (list resend-to-addresses)
3036 (when message-interactive
3039 (goto-char (point-min))
3040 (while (re-search-forward "\n\n* *" nil t)
3041 (replace-match "; "))
3042 (if (not (zerop (buffer-size)))
3043 (error "Sending...failed to %s"
3044 (buffer-substring (point-min) (point-max)))))
3045 (when (bufferp errbuf)
3046 (kill-buffer errbuf)))))
3048 (defun message-send-mail-with-qmail ()
3049 "Pass the prepared message buffer to qmail-inject.
3050 Refer to the documentation for the variable `message-send-mail-function'
3051 to find out how to use this."
3052 ;; replace the header delimiter with a blank line
3053 (goto-char (point-min))
3055 (concat "^" (regexp-quote mail-header-separator) "\n"))
3056 (replace-match "\n")
3058 (run-hooks 'message-send-mail-hook)
3063 'call-process-region 1 (point-max) message-qmail-inject-program
3065 ;; qmail-inject's default behaviour is to look for addresses on the
3066 ;; command line; if there're none, it scans the headers.
3067 ;; yes, it does The Right Thing w.r.t. Resent-To and it's kin.
3069 ;; in general, ALL of qmail-inject's defaults are perfect for simply
3070 ;; reading a formatted (i. e., at least a To: or Resent-To header)
3071 ;; message from stdin.
3073 ;; qmail also has the advantage of not having been raped by
3074 ;; various vendors, so we don't have to allow for that, either --
3075 ;; compare this with message-send-mail-with-sendmail and weep
3076 ;; for sendmail's lost innocence.
3078 ;; all this is way cool coz it lets us keep the arguments entirely
3079 ;; free for -inject-arguments -- a big win for the user and for us
3080 ;; since we don't have to play that double-guessing game and the user
3081 ;; gets full control (no gestapo'ish -f's, for instance). --sj
3082 message-qmail-inject-args))
3083 ;; qmail-inject doesn't say anything on it's stdout/stderr,
3084 ;; we have to look at the retval instead
3086 (1 (error "qmail-inject reported permanent failure"))
3087 (111 (error "qmail-inject reported transient failure"))
3088 ;; should never happen
3089 (t (error "qmail-inject reported unknown failure"))))
3091 (defun message-send-mail-with-mh ()
3092 "Send the prepared message buffer with mh."
3093 (let ((mh-previous-window-config nil)
3094 (name (mh-new-draft-name)))
3095 (setq buffer-file-name name)
3096 ;; MH wants to generate these headers itself.
3097 (when message-mh-deletable-headers
3098 (let ((headers message-mh-deletable-headers))
3100 (goto-char (point-min))
3101 (and (re-search-forward
3102 (concat "^" (symbol-name (car headers)) ": *") nil t)
3103 (message-delete-line))
3105 (run-hooks 'message-send-mail-hook)
3106 ;; Pass it on to mh.
3109 (defun message-send-mail-with-smtp ()
3110 "Send off the prepared buffer with SMTP."
3111 (require 'smtp) ; XXX
3112 (let ((case-fold-search t)
3115 (message-narrow-to-headers)
3117 ;; XXX: Should be replaced by better one.
3118 (smtp-deduce-address-list (current-buffer)
3119 (point-min) (point-max)))
3120 ;; Remove BCC lines.
3121 (message-remove-header "bcc"))
3122 ;; replace the header delimiter with a blank line.
3123 (goto-char (point-min))
3125 (concat "^" (regexp-quote mail-header-separator) "\n"))
3126 (replace-match "\n")
3128 (run-hooks 'message-send-mail-hook)
3130 (static-if (fboundp 'smtp-send-buffer)
3131 (smtp-send-buffer user-mail-address recipients
3133 (let ((result (smtp-via-smtp user-mail-address recipients
3135 (unless (eq result t)
3136 (error "Sending failed; %s" result))))
3137 (error "Sending failed; no recipients"))))
3139 (defsubst message-maybe-split-and-send-news (method)
3140 "Split a message if necessary, and send it via news.
3141 Returns nil if sending succeeded, returns t if sending failed.
3142 This sub function is for exclusive use of `message-send-news'."
3143 (let ((mime-edit-split-ignored-field-regexp
3144 mime-edit-split-ignored-field-regexp)
3145 (case-fold-search t))
3146 (while (string-match "Message-ID" mime-edit-split-ignored-field-regexp)
3147 (setq mime-edit-split-ignored-field-regexp
3148 (concat (substring mime-edit-split-ignored-field-regexp
3149 0 (match-beginning 0))
3150 "Hey_MIME-Edit,_there_is_an_inviolable_Message_ID"
3151 "_so_don't_rape_it!"
3152 (substring mime-edit-split-ignored-field-regexp
3155 (catch 'message-sending-news-failure
3156 (mime-edit-maybe-split-and-send
3161 (std11-narrow-to-header mail-header-separator)
3162 (goto-char (point-min))
3163 (when (re-search-forward "^Message-ID:" nil t)
3164 (delete-region (match-end 0) (std11-field-end))
3165 (insert " " (message-make-message-id))))
3166 (unless (funcall message-send-news-function method)
3167 (throw 'message-sending-news-failure t)))))
3169 (not (funcall message-send-news-function method)))))
3171 (defun message-send-news (&optional arg)
3172 (let* ((tembuf (message-generate-new-buffer-clone-locals " *message temp*"))
3173 (case-fold-search nil)
3174 (method (if (message-functionp message-post-method)
3175 (funcall message-post-method arg)
3176 message-post-method))
3177 (group-name-charset (gnus-group-name-charset method ""))
3178 (message-syntax-checks
3180 (cons '(existing-newsgroups . disabled)
3181 message-syntax-checks)
3182 message-syntax-checks))
3183 (message-this-is-news t)
3186 (message-narrow-to-headers)
3187 ;; Insert some headers.
3188 (message-generate-headers message-required-news-headers)
3189 ;; Let the user do all of the above.
3190 (run-hooks 'message-header-hook))
3191 (if group-name-charset
3192 (setq message-syntax-checks
3193 (cons '(valid-newsgroups . disabled)
3194 message-syntax-checks)))
3195 (message-cleanup-headers)
3196 (if (not (message-check-news-syntax))
3201 (buffer-disable-undo)
3203 (insert-buffer message-encoding-buffer)
3204 ;; Remove some headers.
3206 (message-narrow-to-headers)
3207 ;; We Semi-gnus people have no use for it.
3208 ;; ;; We (re)generate the Lines header.
3209 ;; (when (memq 'Lines message-required-mail-headers)
3210 ;; (message-generate-headers '(Lines)))
3211 ;; Remove some headers.
3212 (message-remove-header message-ignored-news-headers t))
3213 (goto-char (point-max))
3214 ;; require one newline at the end.
3215 (or (= (preceding-char) ?\n)
3217 (setq result (message-maybe-split-and-send-news method)))
3218 (kill-buffer tembuf))
3219 (set-buffer message-edit-buffer)
3222 (message "Couldn't send message via news: %s"
3223 (nnheader-get-report (car method)))
3225 (push 'news message-sent-message-via)))))
3227 ;; 1997-09-29 by MORIOKA Tomohiko
3228 (defun message-send-news-with-gnus (method)
3229 (let ((case-fold-search t))
3230 ;; Remove the delimiter.
3231 (goto-char (point-min))
3233 (concat "^" (regexp-quote mail-header-separator) "\n"))
3234 (replace-match "\n")
3236 (run-hooks 'message-send-news-hook)
3237 (gnus-open-server method)
3238 (gnus-request-post method)
3242 ;;; Header generation & syntax checking.
3245 (defun message-check-element (type)
3246 "Returns non-nil if this type is not to be checked."
3247 (if (eq message-syntax-checks 'dont-check-for-anything-just-trust-me)
3249 (let ((able (assq type message-syntax-checks)))
3251 (eq (cdr able) 'disabled)))))
3253 (defun message-check-news-syntax ()
3254 "Check the syntax of the message."
3259 ;; We narrow to the headers and check them first.
3262 (message-narrow-to-headers)
3263 (message-check-news-header-syntax)))
3266 (set-buffer message-edit-buffer)
3267 (message-check-news-body-syntax))))))
3269 (defun message-check-news-header-syntax ()
3271 ;; Check Newsgroups header.
3272 (message-check 'newsgroups
3273 (let ((group (message-fetch-field "newsgroups")))
3276 (not (string-match "\\`[ \t]*\\'" group)))
3279 "The newsgroups field is empty or missing. Posting is denied.")))))
3280 ;; Check the Subject header.
3281 (message-check 'subject
3282 (let* ((case-fold-search t)
3283 (subject (message-fetch-field "subject")))
3286 (not (string-match "\\`[ \t]*\\'" subject)))
3289 "The subject field is empty or missing. Posting is denied.")))))
3290 ;; Check for commands in Subject.
3291 (message-check 'subject-cmsg
3292 (if (string-match "^cmsg " (message-fetch-field "subject"))
3294 "The control code \"cmsg\" is in the subject. Really post? ")
3296 ;; Check for multiple identical headers.
3297 (message-check 'multiple-headers
3299 (while (and (not found)
3300 (re-search-forward "^[^ \t:]+: " nil t))
3302 (or (re-search-forward
3307 (match-beginning 0) (- (match-end 0) 2))))
3312 (y-or-n-p (format "Multiple %s headers. Really post? " found))
3314 ;; Check for Version and Sendsys.
3315 (message-check 'sendsys
3316 (if (re-search-forward "^Sendsys:\\|^Version:" nil t)
3318 (format "The article contains a %s command. Really post? "
3319 (buffer-substring (match-beginning 0)
3320 (1- (match-end 0)))))
3322 ;; See whether we can shorten Followup-To.
3323 (message-check 'shorten-followup-to
3324 (let ((newsgroups (message-fetch-field "newsgroups"))
3325 (followup-to (message-fetch-field "followup-to"))
3327 (when (and newsgroups
3328 (string-match "," newsgroups)
3333 (setq to (completing-read
3334 "Followups to: (default all groups) "
3335 (mapcar (lambda (g) (list g))
3337 (message-tokenize-header
3339 (goto-char (point-min))
3340 (insert "Followup-To: " to "\n"))
3342 ;; Check "Shoot me".
3343 (message-check 'shoot
3344 (if (re-search-forward
3345 "Message-ID.*.i-did-not-set--mail-host-address--so-shoot-me" nil t)
3346 (y-or-n-p "You appear to have a misconfigured system. Really post? ")
3348 ;; Check for Approved.
3349 (message-check 'approved
3350 (if (re-search-forward "^Approved:" nil t)
3351 (y-or-n-p "The article contains an Approved header. Really post? ")
3353 ;; Check the Message-ID header.
3354 (message-check 'message-id
3355 (let* ((case-fold-search t)
3356 (message-id (message-fetch-field "message-id" t)))
3357 (or (not message-id)
3358 ;; Is there an @ in the ID?
3359 (and (string-match "@" message-id)
3360 ;; Is there a dot in the ID?
3361 (string-match "@[^.]*\\." message-id)
3362 ;; Does the ID end with a dot?
3363 (not (string-match "\\.>" message-id)))
3365 (format "The Message-ID looks strange: \"%s\". Really post? "
3367 ;; Check the Newsgroups & Followup-To headers.
3368 (message-check 'existing-newsgroups
3369 (let* ((case-fold-search t)
3370 (newsgroups (message-fetch-field "newsgroups"))
3371 (followup-to (message-fetch-field "followup-to"))
3372 (groups (message-tokenize-header
3374 (concat newsgroups "," followup-to)
3376 (hashtb (and (boundp 'gnus-active-hashtb)
3377 gnus-active-hashtb))
3379 (if (or (not hashtb)
3380 (not (boundp 'gnus-read-active-file))
3381 (not gnus-read-active-file)
3382 (eq gnus-read-active-file 'some))
3385 (when (and (not (boundp (intern (car groups) hashtb)))
3386 (not (equal (car groups) "poster")))
3387 (push (car groups) errors))
3393 "Really post to %s unknown group%s: %s "
3394 (if (= (length errors) 1) "this" "these")
3395 (if (= (length errors) 1) "" "s")
3396 (mapconcat 'identity errors ", ")))))))
3397 ;; Check the Newsgroups & Followup-To headers for syntax errors.
3398 (message-check 'valid-newsgroups
3399 (let ((case-fold-search t)
3400 (headers '("Newsgroups" "Followup-To"))
3402 (while (and headers (not error))
3403 (when (setq header (mail-fetch-field (car headers)))
3407 "\\`\\([-+_&.a-zA-Z0-9]+\\)?\\(,[-+_&.a-zA-Z0-9]+\\)*\\'"
3412 (not (string-match "\\.\\'\\|\\.\\." g)))
3413 (message-tokenize-header header ","))))
3420 (format "The %s header looks odd: \"%s\". Really post? "
3421 (car headers) header)))))
3422 (message-check 'repeated-newsgroups
3423 (let ((case-fold-search t)
3424 (headers '("Newsgroups" "Followup-To"))
3425 header error groups group)
3428 (when (setq header (mail-fetch-field (pop headers)))
3429 (setq groups (message-tokenize-header header ","))
3430 (while (setq group (pop groups))
3431 (when (member group groups)
3437 (format "Group %s is repeated in headers. Really post? " error)))))
3438 ;; Check the From header.
3439 (message-check 'from
3440 (let* ((case-fold-search t)
3441 (from (message-fetch-field "from"))
3445 (message "There is no From line. Posting is denied.")
3447 ((or (not (string-match
3449 (setq ad (nth 1 (mail-extract-address-components
3450 from))))) ;larsi@ifi
3451 (string-match "\\.\\." ad) ;larsi@ifi..uio
3452 (string-match "@\\." ad) ;larsi@.ifi.uio
3453 (string-match "\\.$" ad) ;larsi@ifi.uio.
3454 (not (string-match "^[^@]+@[^@]+$" ad)) ;larsi.ifi.uio
3455 (string-match "(.*).*(.*)" from)) ;(lars) (lars)
3457 "Denied posting -- the From looks strange: \"%s\"." from)
3461 (defun message-check-news-body-syntax ()
3463 ;; Check for long lines.
3464 (message-check 'long-lines
3465 (goto-char (point-min))
3467 (concat "^" (regexp-quote mail-header-separator) "$"))
3471 (< (current-column) 80))
3472 (zerop (forward-line 1))))
3476 "You have lines longer than 79 characters. Really post? ")))
3477 ;; Check whether the article is empty.
3478 (message-check 'empty
3479 (goto-char (point-min))
3481 (concat "^" (regexp-quote mail-header-separator) "$"))
3484 (goto-char (point-max))
3485 (re-search-backward message-signature-separator nil t)
3487 (or (re-search-backward "[^ \n\t]" b t)
3488 (if (message-gnksa-enable-p 'empty-article)
3489 (y-or-n-p "Empty article. Really post? ")
3490 (message "Denied posting -- Empty article.")
3492 ;; Check for control characters.
3493 (message-check 'control-chars
3494 (if (re-search-forward "[\000-\007\013\015-\032\034-\037\200-\237]" nil t)
3496 "The article contains control characters. Really post? ")
3498 ;; Check 8bit characters.
3499 (message-check '8bit
3500 (message-check-8bit))
3501 ;; Check excessive size.
3502 (message-check 'size
3503 (if (> (buffer-size) 60000)
3505 (format "The article is %d octets long. Really post? "
3508 ;; Check whether any new text has been added.
3509 (message-check 'new-text
3511 (not message-checksum)
3512 (not (eq (message-checksum) message-checksum))
3513 (if (message-gnksa-enable-p 'quoted-text-only)
3515 "It looks like no new text has been added. Really post? ")
3516 (message "Denied posting -- no new text has been added.")
3518 ;; Check the length of the signature.
3519 (message-check 'signature
3520 (goto-char (point-max))
3521 (if (> (count-lines (point) (point-max)) 5)
3524 "Your .sig is %d lines; it should be max 4. Really post? "
3525 (1- (count-lines (point) (point-max)))))
3527 ;; Ensure that text follows last quoted portion.
3528 (message-check 'quoting-style
3529 (goto-char (point-max))
3530 (let ((no-problem t))
3531 (when (search-backward-regexp "^>[^\n]*\n" nil t)
3532 (setq no-problem (search-forward-regexp "^[ \t]*[^>\n]" nil t)))
3535 (if (message-gnksa-enable-p 'quoted-text-only)
3536 (y-or-n-p "Your text should follow quoted text. Really post? ")
3538 (goto-char (point-min))
3540 (concat "^" (regexp-quote mail-header-separator) "$"))
3541 (if (search-forward-regexp "^[ \t]*[^>\n]" nil t)
3542 (y-or-n-p "Your text should follow quoted text. Really post? ")
3543 (message "Denied posting -- only quoted text.")
3546 (defun message-check-mail-syntax ()
3547 "Check the syntax of the message."
3552 ;; We narrow to the headers and check them first.
3555 (message-narrow-to-headers)
3556 (message-check-mail-header-syntax)))
3559 (set-buffer message-edit-buffer)
3560 (message-check-mail-body-syntax))))))
3562 (defun message-check-mail-header-syntax ()
3565 (defun message-check-mail-body-syntax ()
3567 ;; Check 8bit characters.
3568 (message-check '8bit
3569 (message-check-8bit)
3572 (defun message-check-8bit ()
3573 "Check the article contains 8bit characters."
3575 (set-buffer message-encoding-buffer)
3576 (message-narrow-to-headers)
3577 (let* ((case-fold-search t)
3578 (field-value (message-fetch-field "content-transfer-encoding")))
3579 (if (and field-value
3580 (member (downcase field-value) message-8bit-encoding-list))
3583 (set-buffer (get-buffer-create " message syntax"))
3585 (goto-char (point-min))
3586 (set-buffer-multibyte nil)
3587 (insert-buffer message-encoding-buffer)
3588 (goto-char (point-min))
3589 (if (re-search-forward "[^\x00-\x7f]" nil t)
3591 "The article contains 8bit characters. Really post? ")
3594 (defun message-checksum ()
3595 "Return a \"checksum\" for the current buffer."
3598 (goto-char (point-min))
3600 (concat "^" (regexp-quote mail-header-separator) "$"))
3602 (when (not (looking-at "[ \t\n]"))
3603 (setq sum (logxor (ash sum 1) (if (natnump sum) 0 1)
3608 (defun message-do-fcc ()
3609 "Process Fcc headers in the current buffer."
3610 (let ((case-fold-search t)
3611 (coding-system-for-write 'raw-text)
3612 (output-coding-system 'raw-text)
3615 (set-buffer (get-buffer-create " *message temp*"))
3617 (insert-buffer-substring message-encoding-buffer)
3619 (message-narrow-to-headers)
3620 (while (setq file (message-fetch-field "fcc"))
3622 (message-remove-header "fcc" nil t)))
3623 (goto-char (point-min))
3624 (re-search-forward (concat "^" (regexp-quote mail-header-separator) "$"))
3625 (replace-match "" t t)
3626 ;; Process FCC operations.
3628 (setq file (pop list))
3629 (if (string-match "^[ \t]*|[ \t]*\\(.*\\)[ \t]*$" file)
3630 ;; Pipe the article to the program in question.
3631 (call-process-region (point-min) (point-max) shell-file-name
3632 nil nil nil shell-command-switch
3633 (match-string 1 file))
3634 ;; Save the article.
3635 (setq file (expand-file-name file))
3636 (unless (file-exists-p (file-name-directory file))
3637 (make-directory (file-name-directory file) t))
3638 (if (and message-fcc-handler-function
3639 (not (eq message-fcc-handler-function 'rmail-output)))
3640 (funcall message-fcc-handler-function file)
3641 (if (and (file-readable-p file) (mail-file-babyl-p file))
3642 (rmail-output file 1 nil t)
3643 (let ((mail-use-rfc822 t))
3644 (rmail-output file 1 t t))))))
3645 (kill-buffer (current-buffer)))))
3647 (defun message-output (filename)
3648 "Append this article to Unix/babyl mail file.."
3649 (if (and (file-readable-p filename)
3650 (mail-file-babyl-p filename))
3651 (gnus-output-to-rmail filename t)
3652 (gnus-output-to-mail filename t)))
3654 (defun message-cleanup-headers ()
3655 "Do various automatic cleanups of the headers."
3656 ;; Remove empty lines in the header.
3658 (message-narrow-to-headers)
3659 ;; Remove blank lines.
3660 (while (re-search-forward "^[ \t]*\n" nil t)
3661 (replace-match "" t t))
3663 ;; Correct Newsgroups and Followup-To headers: Change sequence of
3664 ;; spaces to comma and eliminate spaces around commas. Eliminate
3665 ;; embedded line breaks.
3666 (goto-char (point-min))
3667 (while (re-search-forward "^\\(Newsgroups\\|Followup-To\\): +" nil t)
3671 (if (re-search-forward "^[^ \t]" nil t)
3675 (goto-char (point-min))
3676 (while (re-search-forward "\n[ \t]+" nil t)
3677 (replace-match " " t t)) ;No line breaks (too confusing)
3678 (goto-char (point-min))
3679 (while (re-search-forward "[ \t\n]*,[ \t\n]*\\|[ \t]+" nil t)
3680 (replace-match "," t t))
3681 (goto-char (point-min))
3682 ;; Remove trailing commas.
3683 (when (re-search-forward ",+$" nil t)
3684 (replace-match "" t t))))))
3686 (defun message-make-date (&optional now)
3687 "Make a valid data header.
3688 If NOW, use that time instead."
3689 (let* ((now (or now (current-time)))
3690 (zone (nth 8 (decode-time now)))
3694 (setq zone (- zone)))
3696 (format-time-string "%d" now)
3697 ;; The month name of the %b spec is locale-specific. Pfff.
3699 (capitalize (car (rassoc (nth 4 (decode-time now))
3700 parse-time-months))))
3701 (format-time-string "%Y %H:%M:%S " now)
3702 ;; We do all of this because XEmacs doesn't have the %z spec.
3703 (format "%s%02d%02d" sign (/ zone 3600) (/ (% zone 3600) 60)))))
3705 (defun message-make-followup-subject (subject)
3706 "Make a followup Subject."
3708 ((and (eq message-use-subject-re 'guess)
3709 (string-match message-subject-encoded-re-regexp subject))
3711 (message-use-subject-re
3712 (concat "Re: " (message-strip-subject-re subject)))
3715 (defun message-make-message-id ()
3716 "Make a unique Message-ID."
3717 (concat "<" (message-unique-id)
3718 (let ((psubject (save-excursion (message-fetch-field "subject")))
3720 (save-excursion (message-fetch-field "supersedes"))))
3722 (and message-reply-headers
3723 (mail-header-references message-reply-headers)
3724 (mail-header-subject message-reply-headers)
3727 (message-strip-subject-re
3728 (mail-header-subject message-reply-headers))
3729 (message-strip-subject-re psubject))))
3731 (string-match "_-_@" psupersedes)))
3733 "@" (message-make-fqdn) ">"))
3735 (defvar message-unique-id-char nil)
3737 ;; If you ever change this function, make sure the new version
3738 ;; cannot generate IDs that the old version could.
3739 ;; You might for example insert a "." somewhere (not next to another dot
3740 ;; or string boundary), or modify the "fsf" string.
3741 (defun message-unique-id ()
3742 ;; Don't use microseconds from (current-time), they may be unsupported.
3743 ;; Instead we use this randomly inited counter.
3744 (setq message-unique-id-char
3745 (% (1+ (or message-unique-id-char (logand (random t) (1- (lsh 1 20)))))
3746 ;; (current-time) returns 16-bit ints,
3747 ;; and 2^16*25 just fits into 4 digits i base 36.
3749 (let ((tm (current-time)))
3751 (if (memq system-type '(ms-dos emx vax-vms))
3752 (let ((user (downcase (user-login-name))))
3753 (while (string-match "[^a-z0-9_]" user)
3754 (aset user (match-beginning 0) ?_))
3756 (message-number-base36 (user-uid) -1))
3757 (message-number-base36 (+ (car tm)
3758 (lsh (% message-unique-id-char 25) 16)) 4)
3759 (message-number-base36 (+ (nth 1 tm)
3760 (lsh (/ message-unique-id-char 25) 16)) 4)
3761 ;; Append the newsreader name, because while the generated
3762 ;; ID is unique to this newsreader, other newsreaders might
3763 ;; otherwise generate the same ID via another algorithm.
3766 (defun message-number-base36 (num len)
3771 (concat (message-number-base36 (/ num 36) (1- len))
3772 (char-to-string (aref "zyxwvutsrqponmlkjihgfedcba9876543210"
3775 (defun message-make-organization ()
3776 "Make an Organization header."
3777 (let* ((organization
3778 (when message-user-organization
3779 (if (message-functionp message-user-organization)
3780 (funcall message-user-organization)
3781 message-user-organization))))
3783 (message-set-work-buffer)
3784 (cond ((stringp organization)
3785 (insert organization))
3786 ((and (eq t organization)
3787 message-user-organization-file
3788 (file-exists-p message-user-organization-file))
3789 (insert-file-contents message-user-organization-file)))
3790 (goto-char (point-min))
3791 (while (re-search-forward "[\t\n]+" nil t)
3792 (replace-match "" t t))
3793 (unless (zerop (buffer-size))
3796 (defun message-make-lines ()
3797 "Count the number of lines and return numeric string."
3801 (goto-char (point-min))
3803 (concat "^" (regexp-quote mail-header-separator) "$"))
3805 (int-to-string (count-lines (point) (point-max))))))
3807 (defun message-make-in-reply-to ()
3808 "Return the In-Reply-To header for this message."
3809 (when message-reply-headers
3810 (let ((mid (mail-header-message-id message-reply-headers))
3811 (from (mail-header-from message-reply-headers))
3812 (date (mail-header-date message-reply-headers)))
3816 (let ((pair (std11-extract-address-components from)))
3818 (or (car pair) (cadr pair))
3820 (if (or (not date) (string= date ""))
3821 "(unknown date)" date)
3824 (defun message-make-distribution ()
3825 "Make a Distribution header."
3826 (let ((orig-distribution (message-fetch-reply-field "distribution")))
3827 (cond ((message-functionp message-distribution-function)
3828 (funcall message-distribution-function))
3829 (t orig-distribution))))
3831 (defun message-make-expires ()
3832 "Return an Expires header based on `message-expires'."
3833 (let ((current (current-time))
3834 (future (* 1.0 message-expires 60 60 24)))
3835 ;; Add the future to current.
3836 (setcar current (+ (car current) (round (/ future (expt 2 16)))))
3837 (setcar (cdr current) (+ (nth 1 current) (% (round future) (expt 2 16))))
3838 (message-make-date current)))
3840 (defun message-make-path ()
3842 (let ((login-name (user-login-name)))
3843 (cond ((null message-user-path)
3844 (concat (system-name) "!" login-name))
3845 ((stringp message-user-path)
3846 ;; Support GENERICPATH. Suggested by vixie@decwrl.dec.com.
3847 (concat message-user-path "!" login-name))
3850 (defun message-make-from ()
3851 "Make a From header."
3852 (let* ((style message-from-style)
3853 (login (message-make-address))
3855 (or (and (boundp 'user-full-name)
3858 (when (string= fullname "&")
3859 (setq fullname (user-login-name)))
3861 (message-set-work-buffer)
3864 (equal fullname ""))
3866 ((or (eq style 'angles)
3867 (and (not (eq style 'parens))
3868 ;; Use angles if no quoting is needed, or if parens would
3869 ;; need quoting too.
3870 (or (not (string-match "[^- !#-'*+/-9=?A-Z^-~]" fullname))
3871 (let ((tmp (concat fullname nil)))
3872 (while (string-match "([^()]*)" tmp)
3873 (aset tmp (match-beginning 0) ?-)
3874 (aset tmp (1- (match-end 0)) ?-))
3875 (string-match "[\\()]" tmp)))))
3877 (goto-char (point-min))
3878 ;; Look for a character that cannot appear unquoted
3879 ;; according to RFC 822.
3880 (when (re-search-forward "[^- !#-'*+/-9=?A-Z^-~]" nil 1)
3881 ;; Quote fullname, escaping specials.
3882 (goto-char (point-min))
3884 (while (re-search-forward "[\"\\]" nil 1)
3885 (replace-match "\\\\\\&" t))
3887 (insert " <" login ">"))
3888 (t ; 'parens or default
3890 (let ((fullname-start (point)))
3892 (goto-char fullname-start)
3893 ;; RFC 822 says \ and nonmatching parentheses
3894 ;; must be escaped in comments.
3895 ;; Escape every instance of ()\ ...
3896 (while (re-search-forward "[()\\]" nil 1)
3897 (replace-match "\\\\\\&" t))
3898 ;; ... then undo escaping of matching parentheses,
3899 ;; including matching nested parentheses.
3900 (goto-char fullname-start)
3901 (while (re-search-forward
3902 "\\(\\=\\|[^\\]\\(\\\\\\\\\\)*\\)\\\\(\\(\\([^\\]\\|\\\\\\\\\\)*\\)\\\\)"
3904 (replace-match "\\1(\\3)" t)
3905 (goto-char fullname-start)))
3909 (defun message-make-sender ()
3910 "Return the \"real\" user address.
3911 This function tries to ignore all user modifications, and
3912 give as trustworthy answer as possible."
3913 (concat (user-login-name) "@" (system-name)))
3915 (defun message-make-address ()
3916 "Make the address of the user."
3917 (or (message-user-mail-address)
3918 (concat (user-login-name) "@" (message-make-domain))))
3920 (defun message-user-mail-address ()
3921 "Return the pertinent part of `user-mail-address'."
3922 (when user-mail-address
3923 (if (string-match " " user-mail-address)
3924 (nth 1 (std11-extract-address-components user-mail-address))
3925 user-mail-address)))
3927 (defun message-make-fqdn ()
3928 "Return user's fully qualified domain name."
3929 (let ((system-name (system-name))
3930 (user-mail (message-user-mail-address)))
3932 ((string-match "[^.]\\.[^.]" system-name)
3933 ;; `system-name' returned the right result.
3935 ;; Try `mail-host-address'.
3936 ((and (boundp 'mail-host-address)
3937 (stringp mail-host-address)
3938 (string-match "\\." mail-host-address))
3940 ;; We try `user-mail-address' as a backup.
3942 (string-match "\\." user-mail)
3943 (string-match "@\\(.*\\)\\'" user-mail))
3944 (match-string 1 user-mail))
3945 ;; Default to this bogus thing.
3947 (concat system-name ".i-did-not-set--mail-host-address--so-shoot-me")))))
3949 (defun message-make-host-name ()
3950 "Return the name of the host."
3951 (let ((fqdn (message-make-fqdn)))
3952 (string-match "^[^.]+\\." fqdn)
3953 (substring fqdn 0 (1- (match-end 0)))))
3955 (defun message-make-domain ()
3956 "Return the domain name."
3957 (or mail-host-address
3958 (message-make-fqdn)))
3960 ;; Dummy to avoid byte-compile warning.
3961 (defvar mule-version)
3962 (defvar emacs-beta-version)
3963 (defvar xemacs-codename)
3964 (defvar gnus-inviolable-extended-version)
3966 (defun message-make-user-agent ()
3967 "Return user-agent info if the value `message-user-agent' is non-nil. If the
3968 \"User-Agent\" field has already exist, it's value will be added in the return
3970 (when message-user-agent
3972 (goto-char (point-min))
3973 (let ((case-fold-search t)
3974 user-agent start p end)
3975 (if (re-search-forward "^User-Agent:[\t ]*" nil t)
3977 (setq start (match-beginning 0)
3979 end (std11-field-end)
3980 user-agent (buffer-substring-no-properties p end))
3981 (delete-region start (1+ end))
3982 (concat message-user-agent " " user-agent))
3983 message-user-agent)))))
3985 (defun message-generate-headers (headers)
3986 "Prepare article HEADERS.
3987 Headers already prepared in the buffer are not modified."
3989 (message-narrow-to-headers)
3990 (let* ((Date (message-make-date))
3991 (Message-ID (message-make-message-id))
3992 (Organization (message-make-organization))
3993 (From (message-make-from))
3994 (Path (message-make-path))
3997 (In-Reply-To (message-make-in-reply-to))
3999 (Distribution (message-make-distribution))
4000 (Lines (message-make-lines))
4001 (User-Agent (message-make-user-agent))
4002 (Expires (message-make-expires))
4003 (case-fold-search t)
4005 ;; First we remove any old generated headers.
4006 (let ((headers message-deletable-headers))
4007 (unless (buffer-modified-p)
4008 (setq headers (delq 'Message-ID (copy-sequence headers))))
4010 (goto-char (point-min))
4011 (and (re-search-forward
4012 (concat "^" (symbol-name (car headers)) ": *") nil t)
4013 (get-text-property (1+ (match-beginning 0)) 'message-deletable)
4014 (message-delete-line))
4016 ;; Go through all the required headers and see if they are in the
4017 ;; articles already. If they are not, or are empty, they are
4018 ;; inserted automatically - except for Subject, Newsgroups and
4021 (goto-char (point-min))
4022 (setq elem (pop headers))
4024 (if (eq (car elem) 'optional)
4025 (setq header (cdr elem))
4026 (setq header (car elem)))
4028 (when (or (not (re-search-forward
4032 (if (stringp header)
4034 (symbol-name header))))
4038 ;; The header was found. We insert a space after the
4039 ;; colon, if there is none.
4040 (if (/= (char-after) ? ) (insert " ") (forward-char 1))
4041 ;; Find out whether the header is empty...
4042 (looking-at "[ \t]*\n[^ \t]")))
4043 ;; So we find out what value we should insert.
4046 ((and (consp elem) (eq (car elem) 'optional))
4047 ;; This is an optional header. If the cdr of this
4048 ;; is something that is nil, then we do not insert
4050 (setq header (cdr elem))
4051 (or (and (fboundp (cdr elem)) (funcall (cdr elem)))
4052 (and (boundp (cdr elem)) (symbol-value (cdr elem)))))
4054 ;; The element is a cons. Either the cdr is a
4055 ;; string to be inserted verbatim, or it is a
4056 ;; function, and we insert the value returned from
4058 (or (and (stringp (cdr elem)) (cdr elem))
4059 (and (fboundp (cdr elem)) (funcall (cdr elem)))))
4060 ((and (boundp header) (symbol-value header))
4061 ;; The element is a symbol. We insert the value
4062 ;; of this symbol, if any.
4063 (symbol-value header))
4064 ((not (message-check-element header))
4065 ;; We couldn't generate a value for this header,
4066 ;; so we just ask the user.
4067 (read-from-minibuffer
4068 (format "Empty header for %s; enter value: " header)))))
4069 ;; Finally insert the header.
4071 (not (equal value "")))
4075 ;; This header didn't exist, so we insert it.
4076 (goto-char (point-max))
4077 (insert (if (stringp header) header (symbol-name header))
4082 ;; The value of this header was empty, so we clear
4083 ;; totally and insert the new value.
4084 (delete-region (point) (gnus-point-at-eol))
4088 ;; Add the deletable property to the headers that require it.
4089 (and (memq header message-deletable-headers)
4090 (progn (beginning-of-line) (looking-at "[^:]+: "))
4091 (add-text-properties
4092 (point) (match-end 0)
4093 '(message-deletable t face italic) (current-buffer)))))))
4094 ;; Insert new Sender if the From is strange.
4095 (let ((from (message-fetch-field "from"))
4096 (sender (message-fetch-field "sender"))
4097 (secure-sender (message-make-sender)))
4099 (not (message-check-element 'sender))
4102 (cadr (std11-extract-address-components from)))
4103 (downcase secure-sender)))
4108 (cadr (std11-extract-address-components sender)))
4109 (downcase secure-sender)))))
4110 (goto-char (point-min))
4111 ;; Rename any old Sender headers to Original-Sender.
4112 (when (re-search-forward "^\\(Original-\\)*Sender:" nil t)
4114 (insert "Original-")
4115 (beginning-of-line))
4116 (when (or (message-news-p)
4117 (string-match "@.+\\.." secure-sender))
4118 (insert "Sender: " secure-sender "\n")))))))
4120 (defun message-insert-courtesy-copy ()
4121 "Insert a courtesy message in mail copies of combined messages."
4125 (message-narrow-to-headers)
4126 (when (setq newsgroups (message-fetch-field "newsgroups"))
4127 (goto-char (point-max))
4128 (insert "Posted-To: " newsgroups "\n")))
4130 (when message-courtesy-message
4132 ((string-match "%s" message-courtesy-message)
4133 (insert (format message-courtesy-message newsgroups)))
4135 (insert message-courtesy-message)))))))
4138 ;;; Setting up a message buffer
4141 (defun message-fill-address (header value)
4143 (narrow-to-region (point) (point))
4144 (insert (capitalize (symbol-name header))
4146 (if (consp value) (car value) value)
4148 (narrow-to-region (point-min) (1- (point-max)))
4150 (goto-char (point-min))
4152 (skip-chars-forward "^,\"" (point-max))
4153 (if (or (eq (char-after) ?,)
4156 (if (and (> (current-column) 78)
4160 (looking-at "[ \t]*")
4161 (replace-match "\n " t t)))
4162 (setq last (1+ (point))))
4163 (setq quoted (not quoted)))
4166 (goto-char (point-max))
4170 (defun message-fill-references (header value)
4171 (insert (capitalize (symbol-name header))
4173 (std11-fill-msg-id-list-string
4174 (if (consp value) (car value) value))
4177 (defun message-fill-header (header value)
4178 (let ((begin (point))
4181 (insert (capitalize (symbol-name header))
4183 (if (consp value) (car value) value)
4186 (narrow-to-region begin (point))
4187 (fill-region-as-paragraph begin (point))
4188 ;; Tapdance around looong Message-IDs.
4190 (when (looking-at "[ \t]*$")
4191 (message-delete-line))
4193 (re-search-forward ":" nil t)
4194 (when (looking-at "\n[ \t]+")
4195 (replace-match " " t t))
4196 (goto-char (point-max)))))
4198 (defun message-shorten-1 (list cut surplus)
4199 ;; Cut SURPLUS elements out of LIST, beginning with CUTth one.
4200 (setcdr (nthcdr (- cut 2) list)
4201 (nthcdr (+ (- cut 2) surplus 1) list)))
4203 (defun message-shorten-references (header references)
4204 "Trim REFERENCES to be less than 31 Message-ID long, and fold them.
4205 If folding is disallowed, also check that the REFERENCES are less
4206 than 988 characters long, and if they are not, trim them until they are."
4213 (goto-char (point-min))
4214 ;; Cons a list of valid references.
4215 (while (re-search-forward "<[^>]+>" nil t)
4216 (push (match-string 0) refs))
4217 (setq refs (nreverse refs)
4218 count (length refs)))
4220 ;; If the list has more than MAXCOUNT elements, trim it by
4221 ;; removing the CUTth element and the required number of
4222 ;; elements that follow.
4223 (when (> count maxcount)
4224 (let ((surplus (- count maxcount)))
4225 (message-shorten-1 refs cut surplus)
4226 (decf count surplus)))
4228 ;; If folding is disallowed, make sure the total length (including
4229 ;; the spaces between) will be less than MAXSIZE characters.
4231 ;; Only disallow folding for News messages. At this point the headers
4232 ;; have not been generated, thus we use message-this-is-news directly.
4233 (when (and message-this-is-news message-cater-to-broken-inn)
4235 (totalsize (+ (apply #'+ (mapcar #'length refs))
4238 (ptr (nthcdr (1- cut) refs)))
4239 ;; Decide how many elements to cut off...
4240 (while (> totalsize maxsize)
4241 (decf totalsize (1+ (length (car ptr))))
4243 (setq ptr (cdr ptr)))
4246 (message-shorten-1 refs cut surplus))))
4248 ;; Finally, collect the references back into a string and insert
4249 ;; it into the buffer.
4250 (let ((refstring (mapconcat #'identity refs " ")))
4251 (if (and message-this-is-news message-cater-to-broken-inn)
4252 (insert (capitalize (symbol-name header)) ": "
4254 (message-fill-header header refstring)))))
4256 (defun message-position-point ()
4257 "Move point to where the user probably wants to find it."
4258 (message-narrow-to-headers)
4260 ((re-search-forward "^[^:]+:[ \t]*$" nil t)
4261 (search-backward ":" )
4264 (if (eq (char-after) ? )
4268 (goto-char (point-max))
4271 (unless (looking-at "$")
4275 (defun message-buffer-name (type &optional to group)
4276 "Return a new (unique) buffer name based on TYPE and TO."
4278 ;; Generate a new buffer name The Message Way.
4279 ((eq message-generate-new-buffers 'unique)
4280 (generate-new-buffer-name
4284 (or (car (std11-extract-address-components to))
4287 (if (and group (not (string= group ""))) (concat " on " group) "")
4289 ;; Check whether `message-generate-new-buffers' is a function,
4290 ;; and if so, call it.
4291 ((message-functionp message-generate-new-buffers)
4292 (funcall message-generate-new-buffers type to group))
4293 ((eq message-generate-new-buffers 'unsent)
4294 (generate-new-buffer-name
4295 (concat "*unsent " type
4298 (or (car (mail-extract-address-components to))
4301 (if (and group (not (string= group ""))) (concat " on " group) "")
4303 ;; Use standard name.
4305 (format "*%s message*" type))))
4307 (defmacro message-pop-to-buffer-1 (buffer)
4309 (let (special-display-buffer-names
4310 special-display-regexps
4311 same-window-buffer-names
4312 same-window-regexps)
4313 (pop-to-buffer ,buffer))
4314 (pop-to-buffer ,buffer)))
4316 (defun message-pop-to-buffer (name)
4317 "Pop to buffer NAME, and warn if it already exists and is modified."
4318 (let ((buffer (get-buffer name))
4319 (pop-up-frames (and (or (static-if (featurep 'xemacs)
4320 (device-on-window-system-p)
4322 (>= emacs-major-version 20))
4323 message-use-multi-frames)))
4325 (buffer-name buffer))
4327 (message-pop-to-buffer-1 buffer)
4328 (when (and (buffer-modified-p)
4330 "Message already being composed; erase? ")))
4331 (error "Message being composed")))
4332 (message-pop-to-buffer-1 name))
4336 (set (make-local-variable 'message-original-frame) (selected-frame)))))
4338 (defun message-do-send-housekeeping ()
4339 "Kill old message buffers."
4340 ;; We might have sent this buffer already. Delete it from the
4342 (setq message-buffer-list (delq (current-buffer) message-buffer-list))
4343 (while (and message-max-buffers
4345 (>= (length message-buffer-list) message-max-buffers))
4346 ;; Kill the oldest buffer -- unless it has been changed.
4347 (let ((buffer (pop message-buffer-list)))
4348 (when (and (buffer-name buffer)
4349 (not (buffer-modified-p buffer)))
4350 (kill-buffer buffer))))
4351 ;; Rename the buffer.
4352 (if message-send-rename-function
4353 (funcall message-send-rename-function)
4354 (when (string-match "\\`\\*\\(unsent \\)?" (buffer-name))
4356 (concat "*sent " (substring (buffer-name) (match-end 0))) t)))
4357 ;; Push the current buffer onto the list.
4358 (when message-max-buffers
4359 (setq message-buffer-list
4360 (nconc message-buffer-list (list (current-buffer))))))
4362 ;;;(defvar mc-modes-alist)
4363 (defun message-setup (headers &optional replybuffer actions)
4364 ;;; (when (and (boundp 'mc-modes-alist)
4365 ;;; (not (assq 'message-mode mc-modes-alist)))
4366 ;;; (push '(message-mode (encrypt . mc-encrypt-message)
4367 ;;; (sign . mc-sign-message))
4368 ;;; mc-modes-alist))
4370 (setq message-send-actions actions))
4371 (setq message-reply-buffer
4372 (or (message-get-parameter 'reply-buffer)
4374 (goto-char (point-min))
4375 ;; Insert all the headers.
4378 (alist message-header-format-alist))
4380 (unless (assq (caar h) message-header-format-alist)
4381 (push (list (caar h)) alist))
4385 (delete-region (point) (progn (forward-line -1) (point)))
4386 (when message-default-headers
4387 (insert message-default-headers)
4388 (or (bolp) (insert ?\n)))
4392 (insert mail-header-separator "\n")
4396 (when (message-news-p)
4397 (when message-default-news-headers
4398 (insert message-default-news-headers)
4399 (or (bolp) (insert ?\n)))
4400 (when message-generate-headers-first
4401 (message-generate-headers
4404 (copy-sequence message-required-news-headers))))))
4405 (when (message-mail-p)
4406 (when message-default-mail-headers
4407 (insert message-default-mail-headers)
4408 (or (bolp) (insert ?\n)))
4409 (when message-generate-headers-first
4410 (message-generate-headers
4413 (copy-sequence message-required-mail-headers))))))
4414 (run-hooks 'message-signature-setup-hook)
4415 (message-insert-signature)
4417 (message-narrow-to-headers)
4418 (if message-alternative-emails
4419 (message-use-alternative-email-as-from))
4420 (run-hooks 'message-header-setup-hook))
4421 (set-buffer-modified-p nil)
4422 (setq buffer-undo-list nil)
4423 (run-hooks 'message-setup-hook)
4424 (message-position-point)
4427 (defun message-set-auto-save-file-name ()
4428 "Associate the message buffer with a file in the drafts directory."
4429 (when message-auto-save-directory
4431 (setq message-draft-article
4432 (nndraft-request-associate-buffer "drafts"))
4433 (setq buffer-file-name (expand-file-name "*message*"
4434 message-auto-save-directory))
4435 (setq buffer-auto-save-file-name (make-auto-save-file-name)))
4436 (clear-visited-file-modtime)
4437 (static-if (boundp 'MULE)
4438 (set-file-coding-system message-draft-coding-system)
4439 (setq buffer-file-coding-system message-draft-coding-system))))
4441 (defun message-disassociate-draft ()
4442 "Disassociate the message buffer from the drafts directory."
4443 (when message-draft-article
4444 (nndraft-request-expire-articles
4445 (list message-draft-article) "drafts" nil t)))
4447 (defun message-insert-headers ()
4448 "Generate the headers for the article."
4452 (message-narrow-to-headers)
4453 (when (message-news-p)
4454 (message-generate-headers
4457 (copy-sequence message-required-news-headers)))))
4458 (when (message-mail-p)
4459 (message-generate-headers
4462 (copy-sequence message-required-mail-headers))))))))
4467 ;;; Commands for interfacing with message
4471 (defun message-mail (&optional to subject
4472 other-headers continue switch-function
4473 yank-action send-actions)
4474 "Start editing a mail message to be sent.
4475 OTHER-HEADERS is an alist of header/value pairs."
4477 (let ((message-this-is-mail t))
4478 (message-pop-to-buffer (message-buffer-name "mail" to))
4481 `((To . ,(or to "")) (Subject . ,(or subject "")))
4482 (when other-headers other-headers)))))
4485 (defun message-news (&optional newsgroups subject)
4486 "Start editing a news article to be sent."
4488 (let ((message-this-is-news t))
4489 (message-pop-to-buffer (message-buffer-name "news" nil newsgroups))
4490 (message-setup `((Newsgroups . ,(or newsgroups ""))
4491 (Subject . ,(or subject ""))))))
4493 (defun message-get-reply-headers (wide &optional to-address)
4494 (let (follow-to mct never-mct from to cc reply-to mrt mft)
4495 ;; Find all relevant headers we need.
4496 (setq from (message-fetch-field "from")
4497 to (message-fetch-field "to")
4498 cc (message-fetch-field "cc")
4499 mct (when message-use-mail-copies-to
4500 (message-fetch-field "mail-copies-to"))
4501 reply-to (message-fetch-field "reply-to")
4502 mrt (when message-use-mail-reply-to
4503 (message-fetch-field "mail-reply-to"))
4504 mft (when (and (not (or to-address mrt reply-to))
4505 message-use-mail-followup-to)
4506 (message-fetch-field "mail-followup-to")))
4508 ;; Handle special values of Mail-Copies-To.
4511 ((and (or (equal (downcase mct) "never")
4512 (equal (downcase mct) "nobody"))
4513 (or (not (eq message-use-mail-copies-to 'ask))
4515 (concat "Obey Mail-Copies-To: never? ") t "\
4516 You should normally obey the Mail-Copies-To: header.
4518 `Mail-Copies-To: never'
4519 directs you not to send your response to the author.")))
4522 ((and (or (equal (downcase mct) "always")
4523 (equal (downcase mct) "poster"))
4524 (or (not (eq message-use-mail-copies-to 'ask))
4526 (concat "Obey Mail-Copies-To: always? ") t "\
4527 You should normally obey the Mail-Copies-To: header.
4529 `Mail-Copies-To: always'
4530 sends a copy of your response to the author.")))
4531 (setq mct (or mrt reply-to from)))
4532 ((and (eq message-use-mail-copies-to 'ask)
4535 (concat "Obey Mail-Copies-To: " mct " ? ") t "\
4536 You should normally obey the Mail-Copies-To: header.
4538 `Mail-Copies-To: " mct "'
4539 sends a copy of your response to " (if (string-match "," mct)
4540 "the specified addresses"
4541 "that address") ".")))
4544 ;; Handle Mail-Followup-To.
4546 (eq message-use-mail-followup-to 'ask)
4547 (not (message-y-or-n-p
4548 (concat "Obey Mail-Followup-To: " mft "? ") t "\
4549 You should normally obey the Mail-Followup-To: header.
4551 `Mail-Followup-To: " mft "'
4552 directs your response to " (if (string-match "," mft)
4553 "the specified addresses"
4554 "that address only") ".
4556 A typical situation where Mail-Followup-To is used is when the author thinks
4557 that further discussion should take place only in "
4558 (if (string-match "," mft)
4559 "the specified mailing lists"
4560 "that mailing list") ".")))
4566 (setq follow-to (list (cons 'To
4567 (or to-address mrt reply-to mft from))))
4568 (when (and wide mct)
4569 (push (cons 'Cc mct) follow-to)))
4572 (message-set-work-buffer)
4574 message-use-followup-to
4575 (or (not (eq message-use-followup-to 'ask))
4576 (message-y-or-n-p "Obey Mail-Followup-To? " t "\
4577 You should normally obey the Mail-Followup-To: header. In this
4578 article, it has the value of
4582 which directs your response to " (if (string-match "," mft)
4583 "the specified addresses"
4584 "that address only") ".
4586 If a message is posted to several mailing lists, Mail-Followup-To is
4587 often used to direct the following discussion to one list only,
4588 because discussions that are spread over several lists tend to be
4589 fragmented and very difficult to follow.
4591 Also, some source/announcement lists are not indented for discussion;
4592 responses here are directed to other addresses.")))
4595 (insert (or mrt reply-to from "")))
4596 (insert (if to (concat (if (bolp) "" ", ") to "") ""))
4597 (insert (if mct (concat (if (bolp) "" ", ") mct) ""))
4598 (insert (if cc (concat (if (bolp) "" ", ") cc) "")))
4599 (goto-char (point-min))
4600 (while (re-search-forward "[ \t]+" nil t)
4601 (replace-match " " t t))
4602 ;; Remove addresses that match `rmail-dont-reply-to-names'.
4603 (let ((rmail-dont-reply-to-names message-dont-reply-to-names))
4604 (insert (prog1 (rmail-dont-reply-to (buffer-string))
4606 (goto-char (point-min))
4607 ;; Perhaps "Mail-Copies-To: never" removed the only address?
4609 (insert (or mrt reply-to from "")))
4613 (cons (mail-strip-quoted-names addr) addr))
4614 (message-tokenize-header (buffer-string))))
4617 (setq ccalist (delq (assoc (car (pop s)) s) ccalist)))))
4618 (setq follow-to (list (cons 'To (cdr (pop ccalist)))))
4620 (let ((ccs (cons 'Cc (mapconcat
4621 (lambda (addr) (cdr addr)) ccalist ", "))))
4622 (when (string-match "^ +" (cdr ccs))
4623 (setcdr ccs (substring (cdr ccs) (match-end 0))))
4624 (push ccs follow-to)))))
4628 (defun message-reply (&optional to-address wide)
4629 "Start editing a reply to the article in the current buffer."
4631 (require 'gnus-sum) ; for gnus-list-identifiers
4632 (let ((cur (current-buffer))
4634 references message-id follow-to
4635 (inhibit-point-motion-hooks t)
4636 (message-this-is-mail t)
4637 gnus-warning in-reply-to)
4639 (message-narrow-to-head)
4640 ;; Allow customizations to have their say.
4642 ;; This is a regular reply.
4643 (if (message-functionp message-reply-to-function)
4644 (setq follow-to (funcall message-reply-to-function)))
4645 ;; This is a followup.
4646 (if (message-functionp message-wide-reply-to-function)
4649 (funcall message-wide-reply-to-function)))))
4650 (setq message-id (message-fetch-field "message-id" t)
4651 references (message-fetch-field "references")
4652 date (message-fetch-field "date")
4653 from (message-fetch-field "from")
4654 subject (or (message-fetch-field "subject") "none"))
4655 (if gnus-list-identifiers
4656 (setq subject (message-strip-list-identifiers subject)))
4657 (setq subject (message-make-followup-subject subject))
4659 (when (and (setq gnus-warning (message-fetch-field "gnus-warning"))
4660 (string-match "<[^>]+>" gnus-warning))
4661 (setq message-id (match-string 0 gnus-warning)))
4664 (setq follow-to (message-get-reply-headers wide to-address)))
4666 ;; Get the references from "In-Reply-To" field if there were
4667 ;; no references and "In-Reply-To" field looks promising.
4669 (when (and (setq in-reply-to (message-fetch-field "in-reply-to"))
4670 (string-match "<[^>]+>" in-reply-to))
4671 (setq references (match-string 0 in-reply-to)))))
4673 (message-pop-to-buffer
4674 (message-buffer-name
4675 (if wide "wide reply" "reply") from
4676 (if wide to-address nil)))
4678 (setq message-reply-headers
4679 (make-full-mail-header-from-decoded-header
4680 0 subject from date message-id references 0 0 ""))
4683 `((Subject . ,subject)
4685 ,@(if (or references message-id)
4686 `((References . ,(concat (or references "") (and references " ")
4687 (or message-id ""))))
4692 (defun message-wide-reply (&optional to-address)
4693 "Make a \"wide\" reply to the message in the current buffer."
4695 (message-reply to-address t))
4698 (defun message-followup (&optional to-newsgroups)
4699 "Follow up to the message in the current buffer.
4700 If TO-NEWSGROUPS, use that as the new Newsgroups line."
4702 (require 'gnus-sum) ; for gnus-list-identifiers
4703 (let ((cur (current-buffer))
4704 from subject date reply-to mrt mct mft
4705 references message-id follow-to
4706 (inhibit-point-motion-hooks t)
4707 (message-this-is-news t)
4708 followup-to distribution newsgroups gnus-warning posted-to)
4710 (message-narrow-to-head)
4711 (when (message-functionp message-followup-to-function)
4713 (funcall message-followup-to-function)))
4714 (setq from (message-fetch-field "from")
4715 date (message-fetch-field "date")
4716 subject (or (message-fetch-field "subject") "none")
4717 references (message-fetch-field "references")
4718 message-id (message-fetch-field "message-id" t)
4719 followup-to (message-fetch-field "followup-to")
4720 newsgroups (message-fetch-field "newsgroups")
4721 posted-to (message-fetch-field "posted-to")
4722 reply-to (message-fetch-field "reply-to")
4723 mrt (when message-use-mail-reply-to
4724 (message-fetch-field "mail-reply-to"))
4725 distribution (message-fetch-field "distribution")
4726 mct (when message-use-mail-copies-to
4727 (message-fetch-field "mail-copies-to"))
4728 mft (when message-use-mail-followup-to
4729 (message-fetch-field "mail-followup-to")))
4730 (when (and (setq gnus-warning (message-fetch-field "gnus-warning"))
4731 (string-match "<[^>]+>" gnus-warning))
4732 (setq message-id (match-string 0 gnus-warning)))
4733 ;; Remove bogus distribution.
4734 (when (and (stringp distribution)
4735 (let ((case-fold-search t))
4736 (string-match "world" distribution)))
4737 (setq distribution nil))
4738 (if gnus-list-identifiers
4739 (setq subject (message-strip-list-identifiers subject)))
4740 (setq subject (message-make-followup-subject subject))
4743 ;; Handle special values of Mail-Copies-To.
4746 ((and (or (equal (downcase mct) "never")
4747 (equal (downcase mct) "nobody"))
4748 (or (not (eq message-use-mail-copies-to 'ask))
4750 (concat "Obey Mail-Copies-To: never? ") t "\
4751 You should normally obey the Mail-Copies-To: header.
4753 `Mail-Copies-To: never'
4754 directs you not to send your response to the author.")))
4756 ((and (or (equal (downcase mct) "always")
4757 (equal (downcase mct) "poster"))
4758 (or (not (eq message-use-mail-copies-to 'ask))
4760 (concat "Obey Mail-Copies-To: always? ") t "\
4761 You should normally obey the Mail-Copies-To: header.
4763 `Mail-Copies-To: always'
4764 sends a copy of your response to the author.")))
4765 (setq mct (or mrt reply-to from)))
4766 ((and (eq message-use-mail-copies-to 'ask)
4769 (concat "Obey Mail-Copies-To: " mct " ? ") t "\
4770 You should normally obey the Mail-Copies-To: header.
4772 `Mail-Copies-To: " mct "'
4773 sends a copy of your response to " (if (string-match "," mct)
4774 "the specified addresses"
4775 "that address") ".")))
4781 (to-newsgroups (setq follow-to (list (cons 'Newsgroups to-newsgroups))))
4782 ;; Handle Followup-To.
4785 ((equal (downcase followup-to) "poster")
4786 (if (or (and followup-to (eq message-use-followup-to 'use))
4787 (message-y-or-n-p "Obey Followup-To: poster? " t "\
4788 You should normally obey the Followup-To: header.
4790 `Followup-To: poster'
4791 sends your response via e-mail instead of news.
4793 A typical situation where `Followup-To: poster' is used is when the author
4794 does not read the newsgroup, so he wouldn't see any replies sent to it."))
4795 (setq message-this-is-news nil
4797 follow-to (list (cons 'To (or mrt reply-to from ""))))
4798 (setq follow-to (list (cons 'Newsgroups newsgroups)))))
4800 (if (or (equal followup-to newsgroups)
4801 (not (and followup-to (eq message-use-followup-to 'ask)))
4803 (concat "Obey Followup-To: " followup-to "? ") t "\
4804 You should normally obey the Followup-To: header.
4806 `Followup-To: " followup-to "'
4807 directs your response to " (if (string-match "," followup-to)
4808 "the specified newsgroups"
4809 "that newsgroup only") ".
4811 If a message is posted to several newsgroups, Followup-To is often
4812 used to direct the following discussion to one newsgroup only,
4813 because discussions that are spread over several newsgroup tend to
4814 be fragmented and very difficult to follow.
4816 Also, some source/announcement newsgroups are not indented for discussion;
4817 responses here are directed to other newsgroups."))
4818 (setq follow-to (list (cons 'Newsgroups followup-to)))
4819 (setq follow-to (list (cons 'Newsgroups newsgroups)))))))
4820 ;; Handle Mail-Followup-To, followup via e-mail.
4822 (or (not (eq message-use-mail-followup-to 'ask))
4824 (concat "Obey Mail-Followup-To: " mft "? ") t "\
4825 You should normally obey the Mail-Followup-To: header.
4827 `Mail-Followup-To: " mft "'
4828 directs your response to " (if (string-match "," mft)
4829 "the specified addresses"
4830 "that address only") " instead of news.
4832 A typical situation where Mail-Followup-To is used is when the author thinks
4833 that further discussion should take place only in "
4834 (if (string-match "," mft)
4835 "the specified mailing lists"
4836 "that mailing list") ".")))
4837 (setq message-this-is-news nil
4839 follow-to (list (cons 'To mft))))
4840 (posted-to (setq follow-to (list (cons 'Newsgroups posted-to))))
4842 (setq follow-to (list (cons 'Newsgroups newsgroups))))))
4844 (message-pop-to-buffer (message-buffer-name "followup" from newsgroups))
4847 `((Subject . ,subject)
4849 ,@(and mct (list (cons 'Cc mct)))
4850 ,@(and distribution (list (cons 'Distribution distribution)))
4851 ,@(if (or references message-id)
4852 `((References . ,(concat (or references "") (and references " ")
4853 (or message-id ""))))))
4856 (setq message-reply-headers
4857 (make-full-mail-header-from-decoded-header
4858 0 subject from date message-id references 0 0 ""))))
4861 (defun message-cancel-news (&optional arg)
4862 "Cancel an article you posted.
4863 If ARG, allow editing of the cancellation message."
4865 (unless (message-news-p)
4866 (error "This is not a news article; canceling is impossible"))
4867 (when (yes-or-no-p "Do you really want to cancel this article? ")
4868 (let (from newsgroups message-id distribution buf sender)
4870 ;; Get header info from original article.
4872 (message-narrow-to-head)
4873 (setq from (message-fetch-field "from")
4874 sender (message-fetch-field "sender")
4875 newsgroups (message-fetch-field "newsgroups")
4876 message-id (message-fetch-field "message-id" t)
4877 distribution (message-fetch-field "distribution")))
4878 ;; Make sure that this article was written by the user.
4879 (unless (or (and sender
4882 (downcase (message-make-sender))))
4884 (downcase (cadr (std11-extract-address-components
4886 (downcase (cadr (std11-extract-address-components
4887 (message-make-from))))))
4888 (error "This article is not yours"))
4889 ;; Make control message.
4892 (setq buf (set-buffer (get-buffer-create " *message cancel*"))))
4894 (insert "Newsgroups: " newsgroups "\n"
4896 "Subject: cmsg cancel " message-id "\n"
4897 "Control: cancel " message-id "\n"
4899 (concat "Distribution: " distribution "\n")
4901 mail-header-separator "\n"
4902 message-cancel-message)
4903 (run-hooks 'message-cancel-hook)
4904 (message "Canceling your article...")
4906 (if (let ((message-syntax-checks
4907 'dont-check-for-anything-just-trust-me)
4908 (message-encoding-buffer (current-buffer))
4909 (message-edit-buffer (current-buffer)))
4910 (message-send-news))
4911 (message "Canceling your article...done"))
4912 (kill-buffer buf))))))
4914 (defun message-supersede-setup-for-mime-edit ()
4915 (set (make-local-variable 'message-setup-hook) nil)
4919 (defun message-supersede ()
4920 "Start composing a message to supersede the current message.
4921 This is done simply by taking the old article and adding a Supersedes
4922 header line with the old Message-ID."
4924 (let ((cur (current-buffer))
4925 (sender (message-fetch-field "sender"))
4926 (from (message-fetch-field "from")))
4927 ;; Check whether the user owns the article that is to be superseded.
4928 (unless (or (and sender
4931 (downcase (message-make-sender))))
4933 (downcase (cadr (std11-extract-address-components from)))
4934 (downcase (cadr (std11-extract-address-components
4935 (message-make-from))))))
4936 (error "This article is not yours"))
4937 ;; Get a normal message buffer.
4938 (message-pop-to-buffer (message-buffer-name "supersede"))
4939 (insert-buffer-substring cur)
4940 (message-narrow-to-head)
4941 ;; Remove unwanted headers.
4942 (when message-ignored-supersedes-headers
4943 (message-remove-header message-ignored-supersedes-headers t))
4944 (goto-char (point-min))
4945 (if (not (re-search-forward "^Message-ID: " nil t))
4946 (error "No Message-ID in this article")
4947 (replace-match "Supersedes: " t t))
4948 (goto-char (point-max))
4949 (insert mail-header-separator)
4951 (when message-supersede-setup-function
4952 (funcall message-supersede-setup-function))
4953 (run-hooks 'message-supersede-setup-hook)
4954 (goto-char (point-min))
4955 (search-forward (concat "\n" mail-header-separator "\n") nil t)))
4958 (defun message-recover ()
4959 "Reread contents of current buffer from its last auto-save file."
4961 (let ((file-name (make-auto-save-file-name)))
4962 (cond ((save-window-excursion
4963 (if (not (eq system-type 'vax-vms))
4964 (with-output-to-temp-buffer "*Directory*"
4965 (with-current-buffer standard-output
4966 (fundamental-mode)) ; for Emacs 20.4+
4967 (buffer-disable-undo standard-output)
4968 (let ((default-directory "/"))
4970 "ls" nil standard-output nil "-l" file-name))))
4971 (yes-or-no-p (format "Recover auto save file %s? " file-name)))
4972 (let ((buffer-read-only nil))
4974 (insert-file-contents file-name nil)))
4975 (t (error "message-recover cancelled")))))
4977 ;;; Washing Subject:
4979 (defun message-wash-subject (subject)
4980 "Remove junk like \"Re:\", \"(fwd)\", etc. that was added to the subject by previous forwarders, replyers, etc."
4982 (insert-string subject)
4983 (goto-char (point-min))
4984 ;; strip Re/Fwd stuff off the beginning
4985 (while (re-search-forward
4986 "\\([Rr][Ee]:\\|[Ff][Ww][Dd]\\(\\[[0-9]*\\]\\)?:\\|[Ff][Ww]:\\)" nil t)
4989 ;; and gnus-style forwards [foo@bar.com] subject
4990 (goto-char (point-min))
4991 (while (re-search-forward "\\[[^ \t]*\\(@\\|\\.\\)[^ \t]*\\]" nil t)
4995 (goto-char (point-max))
4996 (while (re-search-backward "([Ff][Ww][Dd])" nil t)
4999 ;; and finally, any whitespace that was left-over
5000 (goto-char (point-min))
5001 (while (re-search-forward "^[ \t]+" nil t)
5003 (goto-char (point-max))
5004 (while (re-search-backward "[ \t]+$" nil t)
5009 ;;; Forwarding messages.
5011 (defun message-forward-subject-author-subject (subject)
5012 "Generate a subject for a forwarded message.
5013 The form is: [Source] Subject, where if the original message was mail,
5014 Source is the sender, and if the original message was news, Source is
5015 the list of newsgroups is was posted to."
5017 (or (message-fetch-field
5018 (if (message-news-p) "newsgroups" "from"))
5022 (defun message-forward-subject-fwd (subject)
5023 "Generate a subject for a forwarded message.
5024 The form is: Fwd: Subject, where Subject is the original subject of
5026 (concat "Fwd: " subject))
5028 (defun message-make-forward-subject ()
5029 "Return a Subject header suitable for the message in the current buffer."
5032 (message-narrow-to-head)
5033 (let ((funcs message-make-forward-subject-function)
5034 (subject (message-fetch-field "Subject")))
5037 (if message-wash-forwarded-subjects
5038 (message-wash-subject
5039 (nnheader-decode-subject subject))
5040 (nnheader-decode-subject subject))
5042 ;; Make sure funcs is a list.
5045 (setq funcs (list funcs)))
5046 ;; Apply funcs in order, passing subject generated by previous
5047 ;; func to the next one.
5049 (when (message-functionp (car funcs))
5050 (setq subject (funcall (car funcs) subject)))
5051 (setq funcs (cdr funcs)))
5055 (defun message-forward (&optional news)
5056 "Forward the current message via mail.
5057 Optional NEWS will use news to forward instead of mail."
5059 (let ((cur (current-buffer))
5060 (subject (message-make-forward-subject))
5063 (message-news nil subject)
5064 (message-mail nil subject))
5065 ;; Put point where we want it before inserting the forwarded
5067 (if message-forward-before-signature
5069 (goto-char (point-max)))
5070 ;; Make sure we're at the start of the line.
5073 ;; Narrow to the area we are to insert.
5074 (narrow-to-region (point) (point))
5075 ;; Insert the separators and the forwarded buffer.
5076 (insert message-forward-start-separator)
5077 (setq art-beg (point))
5078 (insert-buffer-substring cur)
5079 (goto-char (point-max))
5080 (insert message-forward-end-separator)
5081 (set-text-properties (point-min) (point-max) nil)
5082 ;; Remove all unwanted headers.
5084 (narrow-to-region (point) (if (search-forward "\n\n" nil t)
5087 (goto-char (point-min))
5088 (message-remove-header message-included-forward-headers t nil t)
5090 (message-position-point)))
5093 (defun message-resend (address)
5094 "Resend the current article to ADDRESS."
5096 (list (message-read-from-minibuffer "Resend message to: ")))
5097 (message "Resending message to %s..." address)
5099 (let ((cur (current-buffer))
5101 ;; We first set up a normal mail buffer.
5102 (set-buffer (get-buffer-create " *message resend*"))
5104 ;; avoid to turn-on-mime-edit
5105 (let (message-setup-hook)
5106 (message-setup `((To . ,address)))
5108 ;; Insert our usual headers.
5109 (message-generate-headers '(From Date To))
5110 (message-narrow-to-headers)
5111 ;; Rename them all to "Resent-*".
5112 (while (re-search-forward "^[A-Za-z]" nil t)
5117 (delete-region (point) (point-max))
5119 ;; Insert the message to be resent.
5120 (insert-buffer-substring cur)
5121 (goto-char (point-min))
5122 (search-forward "\n\n")
5125 (narrow-to-region beg (point))
5126 (message-remove-header message-ignored-resent-headers t)
5127 (goto-char (point-max)))
5128 (insert mail-header-separator)
5129 ;; Rename all old ("Also-")Resent headers.
5130 (while (re-search-backward "^\\(Also-\\)*Resent-" beg t)
5133 ;; Quote any "From " lines at the beginning.
5135 (when (looking-at "From ")
5136 (replace-match "X-From-Line: "))
5138 (let ((message-encoding-buffer (current-buffer))
5139 (message-edit-buffer (current-buffer)))
5140 (let (message-required-mail-headers)
5141 (message-send-mail)))
5142 (kill-buffer (current-buffer)))
5143 (message "Resending message to %s...done" address)))
5145 (defun message-bounce-setup-for-mime-edit ()
5146 (set (make-local-variable 'message-setup-hook) nil)
5150 (defun message-bounce ()
5151 "Re-mail the current message.
5152 This only makes sense if the current message is a bounce message that
5153 contains some mail you have written which has been bounced back to
5156 (let ((cur (current-buffer))
5158 (message-pop-to-buffer (message-buffer-name "bounce"))
5159 (insert-buffer-substring cur)
5161 (message-narrow-to-head)
5162 (if (and (message-fetch-field "MIME-Version")
5163 (setq boundary (message-fetch-field "Content-Type")))
5164 (if (string-match "boundary=\"\\([^\"]+\\)\"" boundary)
5165 (setq boundary (concat (match-string 1 boundary) " *\n"
5166 "Content-Type: message/rfc822"))
5167 (setq boundary nil)))
5169 (goto-char (point-min))
5170 (search-forward "\n\n" nil t)
5172 (re-search-forward boundary nil t)
5174 (and (re-search-forward message-unsent-separator nil t)
5176 (re-search-forward "^Return-Path:.*\n" nil t))
5177 ;; We remove everything before the bounced mail.
5180 (if (re-search-forward "^[^ \n\t]+:" nil t)
5184 (message-narrow-to-head)
5185 (message-remove-header message-ignored-bounced-headers t)
5186 (goto-char (point-max))
5187 (insert mail-header-separator))
5188 (when message-bounce-setup-function
5189 (funcall message-bounce-setup-function))
5190 (run-hooks 'message-bounce-setup-hook)
5191 (message-position-point)))
5194 ;;; Interactive entry points for new message buffers.
5198 (defun message-mail-other-window (&optional to subject)
5199 "Like `message-mail' command, but display mail buffer in another window."
5201 (let ((pop-up-windows t)
5202 (special-display-buffer-names nil)
5203 (special-display-regexps nil)
5204 (same-window-buffer-names nil)
5205 (same-window-regexps nil))
5206 (message-pop-to-buffer (message-buffer-name "mail" to)))
5207 (let ((message-this-is-mail t))
5208 (message-setup `((To . ,(or to "")) (Subject . ,(or subject ""))))))
5211 (defun message-mail-other-frame (&optional to subject)
5212 "Like `message-mail' command, but display mail buffer in another frame."
5214 (let ((pop-up-frames t)
5215 (special-display-buffer-names nil)
5216 (special-display-regexps nil)
5217 (same-window-buffer-names nil)
5218 (same-window-regexps nil))
5219 (message-pop-to-buffer (message-buffer-name "mail" to)))
5220 (let ((message-this-is-mail t))
5221 (message-setup `((To . ,(or to "")) (Subject . ,(or subject ""))))))
5224 (defun message-news-other-window (&optional newsgroups subject)
5225 "Start editing a news article to be sent."
5227 (let ((pop-up-windows t)
5228 (special-display-buffer-names nil)
5229 (special-display-regexps nil)
5230 (same-window-buffer-names nil)
5231 (same-window-regexps nil))
5232 (message-pop-to-buffer (message-buffer-name "news" nil newsgroups)))
5233 (let ((message-this-is-news t))
5234 (message-setup `((Newsgroups . ,(or newsgroups ""))
5235 (Subject . ,(or subject ""))))))
5238 (defun message-news-other-frame (&optional newsgroups subject)
5239 "Start editing a news article to be sent."
5241 (let ((pop-up-frames t)
5242 (special-display-buffer-names nil)
5243 (special-display-regexps nil)
5244 (same-window-buffer-names nil)
5245 (same-window-regexps nil))
5246 (message-pop-to-buffer (message-buffer-name "news" nil newsgroups)))
5247 (let ((message-this-is-news t))
5248 (message-setup `((Newsgroups . ,(or newsgroups ""))
5249 (Subject . ,(or subject ""))))))
5253 ;; This code should be moved to underline.el (from which it is stolen).
5256 (defun bold-region (start end)
5257 "Bold all nonblank characters in the region.
5258 Works by overstriking characters.
5259 Called from program, takes two arguments START and END
5260 which specify the range to operate on."
5263 (let ((end1 (make-marker)))
5264 (move-marker end1 (max start end))
5265 (goto-char (min start end))
5266 (while (< (point) end1)
5267 (or (looking-at "[_\^@- ]")
5268 (insert (char-after) "\b"))
5269 (forward-char 1)))))
5272 (defun unbold-region (start end)
5273 "Remove all boldness (overstruck characters) in the region.
5274 Called from program, takes two arguments START and END
5275 which specify the range to operate on."
5278 (let ((end1 (make-marker)))
5279 (move-marker end1 (max start end))
5280 (goto-char (min start end))
5281 (while (re-search-forward "\b" end1 t)
5282 (if (eq (char-after) (char-after (- (point) 2)))
5283 (delete-char -2))))))
5285 (defalias 'message-exchange-point-and-mark 'exchange-point-and-mark)
5287 ;; Support for toolbar
5288 (when (featurep 'xemacs)
5289 (require 'messagexmas))
5291 ;;; Group name completion.
5293 (defvar message-newgroups-header-regexp
5294 "^\\(Newsgroups\\|Followup-To\\|Posted-To\\|Gcc\\):"
5295 "Regexp that match headers that lists groups.")
5297 (defun message-tab ()
5298 "Expand group names in Newsgroups and Followup-To headers.
5299 Do a `tab-to-tab-stop' if not in those headers."
5301 (if (let ((mail-abbrev-mode-regexp message-newgroups-header-regexp))
5302 (mail-abbrev-in-expansion-header-p))
5303 (message-expand-group)
5306 (defvar gnus-active-hashtb)
5307 (defun message-expand-group ()
5308 "Expand the group name under point."
5309 (let* ((b (save-excursion
5314 (skip-chars-forward "^:")
5317 (skip-chars-backward "^, \t\n") (point))))
5318 (completion-ignore-case t)
5319 (string (buffer-substring b (progn (skip-chars-forward "^,\t\n ")
5321 (hashtb (and (boundp 'gnus-active-hashtb) gnus-active-hashtb))
5322 (completions (all-completions string hashtb))
5324 (delete-region b (point))
5326 ((= (length completions) 1)
5327 (if (string= (car completions) string)
5330 (message "Only matching group"))
5331 (insert (car completions))))
5332 ((and (setq comp (try-completion string hashtb))
5333 (not (string= comp string)))
5338 (message "No matching groups")
5339 (save-selected-window
5340 (pop-to-buffer "*Completions*")
5341 (buffer-disable-undo)
5342 (let ((buffer-read-only nil))
5344 (let ((standard-output (current-buffer)))
5345 (display-completion-list (sort completions 'string<)))
5346 (goto-char (point-min))
5347 (delete-region (point) (progn (forward-line 3) (point))))))))))
5351 (defun message-talkative-question (ask question show &rest text)
5352 "Call FUNCTION with argument QUESTION; optionally display TEXT... args.
5353 If SHOW is non-nil, the arguments TEXT... are displayed in a temp buffer.
5354 The following arguments may contain lists of values."
5356 (setq text (message-flatten-list text)))
5357 (save-window-excursion
5359 (with-output-to-temp-buffer " *MESSAGE information message*"
5360 (set-buffer " *MESSAGE information message*")
5361 (fundamental-mode) ; for Emacs 20.4+
5362 (mapcar 'princ text)
5363 (goto-char (point-min))))
5364 (funcall ask question))
5365 (funcall ask question)))
5367 (defun message-flatten-list (list)
5368 "Return a new, flat list that contains all elements of LIST.
5370 \(message-flatten-list '(1 (2 3 (4 5 (6))) 7))
5373 (apply 'append (mapcar 'message-flatten-list list)))
5377 (defun message-generate-new-buffer-clone-locals (name &optional varstr)
5378 "Create and return a buffer with a name based on NAME using generate-new-buffer.
5379 Then clone the local variables and values from the old buffer to the
5380 new one, cloning only the locals having a substring matching the
5382 (let ((oldbuf (current-buffer)))
5384 (set-buffer (generate-new-buffer name))
5385 (message-clone-locals oldbuf varstr)
5388 (defun message-clone-locals (buffer &optional varstr)
5389 "Clone the local variables from BUFFER to the current buffer."
5390 (let ((locals (save-excursion
5392 (buffer-local-variables)))
5394 "^\\(gnus\\|nn\\|message\\|user-\\(mail-address\\|full-name\\)\\)"))
5397 (when (and (consp local)
5399 (string-match regexp (symbol-name (car local)))
5401 (string-match varstr (symbol-name (car local)))))
5403 (set (make-local-variable (car local))
5408 ;;; @ for MIME Edit mode
5411 (defun message-maybe-encode ()
5412 (when message-mime-mode
5413 ;; Inherit the buffer local variable `mime-edit-pgp-processing'.
5414 (let ((pgp-processing (with-current-buffer message-edit-buffer
5415 mime-edit-pgp-processing)))
5416 (setq mime-edit-pgp-processing pgp-processing))
5417 (run-hooks 'mime-edit-translate-hook)
5418 (if (catch 'mime-edit-error
5420 (mime-edit-pgp-enclose-buffer)
5421 (mime-edit-translate-body)
5423 (error "Translation error!")
5426 (run-hooks 'mime-edit-exit-hook)
5429 (defun message-mime-insert-article (&optional full-headers)
5431 (let ((message-cite-function 'mime-edit-inserted-message-filter)
5432 (message-reply-buffer
5433 (message-get-parameter-with-eval 'original-buffer))
5435 (message-yank-original nil)
5437 (narrow-to-region (goto-char start)
5438 (if (search-forward "\n\n" nil t)
5441 (goto-char (point-min))
5442 (let ((message-included-forward-headers
5443 (if full-headers "" message-included-forward-headers)))
5444 (message-remove-header message-included-forward-headers t nil t))
5447 (set-alist 'mime-edit-message-inserter-alist
5448 'message-mode (function message-mime-insert-article))
5450 ;;; Miscellaneous functions
5452 ;; stolen (and renamed) from nnheader.el
5453 (static-if (fboundp 'subst-char-in-string)
5454 (defsubst message-replace-chars-in-string (string from to)
5455 (subst-char-in-string from to string))
5456 (defun message-replace-chars-in-string (string from to)
5457 "Replace characters in STRING from FROM to TO."
5458 (let ((string (substring string 0)) ;Copy string.
5459 (len (length string))
5461 ;; Replace all occurrences of FROM with TO.
5463 (when (= (aref string idx) from)
5464 (aset string idx to))
5465 (setq idx (1+ idx)))
5472 (defvar message-inhibit-body-encoding t)
5474 (defun message-encode-message-body ()
5475 (unless message-inhibit-body-encoding
5476 (let ((mail-parse-charset (or mail-parse-charset
5477 message-default-charset))
5478 (case-fold-search t)
5479 lines content-type-p)
5482 (narrow-to-region (point) (point-max))
5483 (let ((new (mml-generate-mime)))
5485 (delete-region (point-min) (point-max))
5487 (goto-char (point-min))
5488 (if (eq (aref new 0) ?\n)
5490 (search-forward "\n\n")
5491 (setq lines (buffer-substring (point-min) (1- (point))))
5492 (delete-region (point-min) (point))))))
5494 (message-narrow-to-headers-or-head)
5495 (message-remove-header "Mime-Version")
5496 (goto-char (point-max))
5497 (insert "MIME-Version: 1.0\n")
5500 (setq content-type-p
5501 (re-search-backward "^Content-Type:" nil t)))
5503 (message-narrow-to-headers-or-head)
5504 (message-remove-first-header "Content-Type")
5505 (message-remove-first-header "Content-Transfer-Encoding"))
5506 ;; We always make sure that the message has a Content-Type header.
5507 ;; This is because some broken MTAs and MUAs get awfully confused
5508 ;; when confronted with a message with a MIME-Version header and
5509 ;; without a Content-Type header. For instance, Solaris'
5511 (unless content-type-p
5512 (goto-char (point-min))
5513 (re-search-forward "^MIME-Version:")
5515 (insert "Content-Type: text/plain; charset=us-ascii\n")))))
5517 (defun message-read-from-minibuffer (prompt)
5518 "Read from the minibuffer while providing abbrev expansion."
5519 (if (fboundp 'mail-abbrevs-setup)
5520 (let ((mail-abbrev-mode-regexp "")
5521 (minibuffer-setup-hook 'mail-abbrevs-setup))
5522 (read-from-minibuffer prompt))
5523 (let ((minibuffer-setup-hook 'mail-abbrev-minibuffer-setup-hook))
5524 (read-string prompt))))
5526 (defun message-use-alternative-email-as-from ()
5527 (require 'mail-utils)
5528 (let* ((fields '("To" "Cc"))
5531 (mail-strip-quoted-names
5532 (mapconcat 'message-fetch-reply-field fields ","))
5536 (if (string-match message-alternative-emails (car emails))
5537 (setq email (car emails)
5540 (unless (or (not email) (equal email user-mail-address))
5541 (goto-char (point-max))
5542 (insert "From: " email "\n"))))
5544 (defun message-options-get (symbol)
5545 (cdr (assq symbol message-options)))
5547 (defun message-options-set (symbol value)
5548 (let ((the-cons (assq symbol message-options)))
5551 (setcdr the-cons value)
5552 (setq message-options (delq the-cons message-options)))
5554 (push (cons symbol value) message-options))))
5557 (defun message-options-set-recipient ()
5559 (message-narrow-to-headers-or-head)
5560 (message-options-set 'message-sender
5561 (mail-strip-quoted-names
5562 (message-fetch-field "from")))
5563 (message-options-set 'message-recipients
5564 (mail-strip-quoted-names
5565 (message-fetch-field "to")))))
5567 (defun message-save-drafts ()
5568 "Postponing the message."
5570 (message "Saving %s..." buffer-file-name)
5571 (let ((reply-headers message-reply-headers)
5572 (msg (buffer-substring-no-properties (point-min) (point-max))))
5573 (with-temp-file buffer-file-name
5575 (setq message-reply-headers reply-headers)
5576 (message-generate-headers '((optional . In-Reply-To)))
5577 (mime-edit-translate-buffer))
5578 (set-buffer-modified-p nil))
5579 (message "Saving %s...done" buffer-file-name))
5581 (when (featurep 'xemacs)
5582 (require 'messagexmas)
5583 (message-xmas-redefine))
5587 (run-hooks 'message-load-hook)
5590 ;; coding: iso-8859-1
5593 ;;; message.el ends here