1 ;;; message.el --- composing mail and news messages
2 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000
3 ;; Free Software Foundation, Inc.
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
6 ;; MORIOKA Tomohiko <morioka@jaist.ac.jp>
7 ;; Shuhei KOBAYASHI <shuhei-k@jaist.ac.jp>
8 ;; Keiichi Suzuki <kei-suzu@mail.wbs.ne.jp>
9 ;; Tatsuya Ichikawa <t-ichi@po.shiojiri.ne.jp>
10 ;; Katsumi Yamaoka <yamaoka@jpl.org>
11 ;; Kiyokazu SUTO <suto@merry.xmath.ous.ac.jp>
12 ;; Keywords: mail, news, MIME
14 ;; This file is part of GNU Emacs.
16 ;; GNU Emacs is free software; you can redistribute it and/or modify
17 ;; it under the terms of the GNU General Public License as published by
18 ;; the Free Software Foundation; either version 2, or (at your option)
21 ;; GNU Emacs is distributed in the hope that it will be useful,
22 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
23 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 ;; GNU General Public License for more details.
26 ;; You should have received a copy of the GNU General Public License
27 ;; along with GNU Emacs; see the file COPYING. If not, write to the
28 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
29 ;; Boston, MA 02111-1307, USA.
33 ;; This mode provides mail-sending facilities from within Emacs. It
34 ;; consists mainly of large chunks of code from the sendmail.el,
35 ;; gnus-msg.el and rnewspost.el files.
39 (eval-when-compile (require 'cl))
40 (eval-when-compile (require 'smtp))
45 (if (string-match "XEmacs\\|Lucid" emacs-version)
46 (require 'mail-abbrevs)
47 (require 'mailabbrev))
49 (eval-when-compile (require 'static))
51 ;; Avoid byte-compile warnings.
59 (defgroup message '((user-mail-address custom-variable)
60 (user-full-name custom-variable))
61 "Mail and news message composing."
62 :link '(custom-manual "(message)Top")
66 (put 'user-mail-address 'custom-type 'string)
67 (put 'user-full-name 'custom-type 'string)
69 (defgroup message-various nil
70 "Various Message Variables"
71 :link '(custom-manual "(message)Various Message Variables")
74 (defgroup message-buffers nil
76 :link '(custom-manual "(message)Message Buffers")
79 (defgroup message-sending nil
81 :link '(custom-manual "(message)Sending Variables")
84 (defgroup message-interface nil
86 :link '(custom-manual "(message)Interface")
89 (defgroup message-forwarding nil
91 :link '(custom-manual "(message)Forwarding")
92 :group 'message-interface)
94 (defgroup message-insertion nil
96 :link '(custom-manual "(message)Insertion")
99 (defgroup message-headers nil
101 :link '(custom-manual "(message)Message Headers")
104 (defgroup message-news nil
105 "Composing News Messages"
108 (defgroup message-mail nil
109 "Composing Mail Messages"
112 (defgroup message-faces nil
113 "Faces used for message composing."
117 (defgroup message-frames nil
121 (defcustom message-directory "~/Mail/"
122 "*Directory from which all other mail file variables are derived."
123 :group 'message-various
126 (defcustom message-max-buffers 10
127 "*How many buffers to keep before starting to kill them off."
128 :group 'message-buffers
131 (defcustom message-send-rename-function nil
132 "Function called to rename the buffer after sending it."
133 :group 'message-buffers
136 (defcustom message-fcc-handler-function 'message-output
137 "*A function called to save outgoing articles.
138 This function will be called with the name of the file to store the
139 article in. The default function is `message-output' which saves in Unix
141 :type '(radio (function-item message-output)
142 (function :tag "Other"))
143 :group 'message-sending)
145 (defcustom message-encode-function 'message-maybe-encode
146 "*A function called to encode messages."
147 :group 'message-sending
150 (defcustom message-8bit-encoding-list '(8bit binary)
151 "*8bit encoding type in Content-Transfer-Encoding field."
152 :group 'message-sending
153 :type '(repeat (symbol :tag "Type")))
155 (defcustom message-courtesy-message
156 "The following message is a courtesy copy of an article\nthat has been posted to %s as well.\n\n"
157 "*This is inserted at the start of a mailed copy of a posted message.
158 If the string contains the format spec \"%s\", the Newsgroups
159 the article has been posted to will be inserted there.
160 If this variable is nil, no such courtesy message will be added."
161 :group 'message-sending
164 (defcustom message-ignored-bounced-headers "^\\(Received\\|Return-Path\\):"
165 "*Regexp that matches headers to be removed in resent bounced mail."
166 :group 'message-interface
169 (defcustom message-bounce-setup-function 'message-bounce-setup-for-mime-edit
170 "Function to setup a re-sending bounced message."
171 :group 'message-sending
175 (defcustom message-from-style 'default
176 "*Specifies how \"From\" headers look.
178 If `nil', they contain just the return address like:
180 If `parens', they look like:
181 king@grassland.com (Elvis Parsley)
182 If `angles', they look like:
183 Elvis Parsley <king@grassland.com>
185 Otherwise, most addresses look like `angles', but they look like
186 `parens' if `angles' would need quoting and `parens' would not."
187 :type '(choice (const :tag "simple" nil)
191 :group 'message-headers)
193 (defcustom message-syntax-checks nil
194 ;; Guess this one shouldn't be easy to customize...
195 "*Controls what syntax checks should not be performed on outgoing posts.
196 To disable checking of long signatures, for instance, add
197 `(signature . disabled)' to this list.
199 Don't touch this variable unless you really know what you're doing.
201 Checks include subject-cmsg multiple-headers sendsys message-id from
202 long-lines control-chars size new-text redirected-followup signature
203 approved sender empty empty-headers message-id from subject
204 shorten-followup-to existing-newsgroups buffer-file-name unchanged
206 :group 'message-news)
208 (defcustom message-required-news-headers
209 '(From Newsgroups Subject Date Message-ID
210 (optional . Organization) Lines
211 (optional . User-Agent))
212 "*Headers to be generated or prompted for when posting an article.
213 RFC977 and RFC1036 require From, Date, Newsgroups, Subject,
214 Message-ID. Organization, Lines, In-Reply-To, Expires, and
215 User-Agent are optional. If don't you want message to insert some
216 header, remove it from this list."
218 :group 'message-headers
219 :type '(repeat sexp))
221 (defcustom message-required-mail-headers
222 '(From Subject Date (optional . In-Reply-To) Message-ID Lines
223 (optional . User-Agent))
224 "*Headers to be generated or prompted for when mailing a message.
225 RFC822 required that From, Date, To, Subject and Message-ID be
226 included. Organization, Lines and User-Agent are optional."
228 :group 'message-headers
229 :type '(repeat sexp))
231 (defcustom message-deletable-headers '(Message-ID Date Lines)
232 "Headers to be deleted if they already exist and were generated by message previously."
233 :group 'message-headers
236 (defcustom message-ignored-news-headers
237 "^NNTP-Posting-Host:\\|^Xref:\\|^[BGF]cc:\\|^Resent-Fcc:"
238 "*Regexp of headers to be removed unconditionally before posting."
240 :group 'message-headers
243 (defcustom message-ignored-mail-headers "^[GF]cc:\\|^Resent-Fcc:\\|^Xref:"
244 "*Regexp of headers to be removed unconditionally before mailing."
246 :group 'message-headers
249 (defcustom message-ignored-supersedes-headers "^Path:\\|^Date\\|^NNTP-Posting-Host:\\|^Xref:\\|^Lines:\\|^Received:\\|^X-From-Line:\\|^X-Trace:\\|^X-Complaints-To:\\|Return-Path:\\|^Supersedes:"
250 "*Header lines matching this regexp will be deleted before posting.
251 It's best to delete old Path and Date headers before posting to avoid
253 :group 'message-interface
256 (defcustom message-supersede-setup-function
257 'message-supersede-setup-for-mime-edit
258 "Function to setup a supersede message."
259 :group 'message-sending
262 (defcustom message-subject-re-regexp "^[ \t]*\\([Rr][Ee]:[ \t]*\\)*[ \t]*"
263 "*Regexp matching \"Re: \" in the subject line."
264 :group 'message-various
267 ;;; Some sender agents encode the whole subject including leading "Re: ".
268 ;;; And if followup agent does not decode it for some reason (e.g. unknown
269 ;;; charset) and just add a new "Re: " in front of the encoded-word, the
270 ;;; result will contain multiple "Re: "'s.
271 (defcustom message-subject-encoded-re-regexp
275 "[-!#$%&'*+0-9A-Z^_`a-z{|}~]+" ; charset
278 "[Bb]" (regexp-quote "?") ; B encoding
279 "\\(\\(CQk\\|CSA\\|IAk\\|ICA\\)[Jg]\\)*" ; \([ \t][ \t][ \t]\)*
281 "[Uc][km]U6" ; [Rr][Ee]:
283 "\\(C[VX]\\|I[FH]\\)J[Fl]O[g-v]" ; [ \t][Rr][Ee]:
285 "\\(CQl\\|CSB\\|IAl\\|ICB\\)[Sy][RZ]T[o-r]" ; [ \t][ \t][Rr][Ee]:
288 "[Qb]" (regexp-quote "?") ; Q encoding
289 "\\(_\\|=09\\|=20\\)*"
290 "\\([Rr]\\|=[57]2\\)\\([Ee]\\|=[46]5\\)\\(:\\|=3[Aa]\\)"
293 "*Regexp matching \"Re: \" in the subject line.
294 Unlike `message-subject-re-regexp', this regexp matches \"Re: \" within
296 :group 'message-various
299 (defcustom message-use-subject-re t
300 "*If t, remove any (buggy) \"Re: \"'s from the subject of the precursor
301 and add a new \"Re: \". If it is nil, use the subject \"as-is\". If it
302 is the symbol `guess', try to detect \"Re: \" within an encoded-word."
303 :group 'message-various
304 :type '(choice (const :tag "off" nil)
309 (defcustom message-signature-separator "^-- *$"
310 "Regexp matching the signature separator."
312 :group 'message-various)
314 (defcustom message-elide-ellipsis "\n[...]\n\n"
315 "*The string which is inserted for elided text."
317 :group 'message-various)
319 (defcustom message-interactive nil
320 "Non-nil means when sending a message wait for and display errors.
321 nil means let mailer mail back a message to report errors."
322 :group 'message-sending
326 (defcustom message-generate-new-buffers 'unique
327 "*Non-nil means that a new message buffer will be created whenever `message-setup' is called.
328 If this is a function, call that function with three parameters: The type,
329 the to address and the group name. (Any of these may be nil.) The function
330 should return the new buffer name."
331 :group 'message-buffers
332 :type '(choice (const :tag "off" nil)
333 (const :tag "unique" unique)
334 (const :tag "unsent" unsent)
337 (defcustom message-kill-buffer-on-exit nil
338 "*Non-nil means that the message buffer will be killed after sending a message."
339 :group 'message-buffers
342 (defcustom message-kill-buffer-query-function 'yes-or-no-p
343 "*A function called to query the user whether to kill buffer anyway or not.
344 If it is t, the buffer will be killed peremptorily."
345 :type '(radio (function-item yes-or-no-p)
346 (function-item y-or-n-p)
347 (function-item nnheader-Y-or-n-p)
348 (function :tag "Other" t))
349 :group 'message-buffers)
351 (defvar gnus-local-organization)
352 (defcustom message-user-organization
353 (or (and (boundp 'gnus-local-organization)
354 (stringp gnus-local-organization)
355 gnus-local-organization)
356 (getenv "ORGANIZATION")
358 "*String to be used as an Organization header.
359 If t, use `message-user-organization-file'."
360 :group 'message-headers
361 :type '(choice string
362 (const :tag "consult file" t)))
365 (defcustom message-user-organization-file "/usr/lib/news/organization"
366 "*Local news organization file."
368 :group 'message-headers)
370 (defcustom message-forward-start-separator
371 (concat (mime-make-tag "message" "rfc822") "\n")
372 "*Delimiter inserted before forwarded messages."
373 :group 'message-forwarding
376 (defcustom message-forward-end-separator
377 (concat (mime-make-tag "text" "plain") "\n")
378 "*Delimiter inserted after forwarded messages."
379 :group 'message-forwarding
382 (defcustom message-included-forward-headers
383 "^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:"
384 "*Regexp matching headers to be included in forwarded messages."
385 :group 'message-forwarding
388 (defcustom message-make-forward-subject-function
389 'message-forward-subject-author-subject
390 "*A list of functions that are called to generate a subject header for forwarded messages.
391 The subject generated by the previous function is passed into each
394 The provided functions are:
396 * message-forward-subject-author-subject (Source of article (author or
397 newsgroup)), in brackets followed by the subject
398 * message-forward-subject-fwd (Subject of article with 'Fwd:' prepended
400 :group 'message-forwarding
401 :type '(radio (function-item message-forward-subject-author-subject)
402 (function-item message-forward-subject-fwd)))
404 (defcustom message-forward-as-mime t
405 "*If non-nil, forward messages as an inline/rfc822 MIME section. Otherwise, directly inline the old message in the forwarded message."
406 :group 'message-forwarding
409 (defcustom message-forward-before-signature t
410 "*If non-nil, put forwarded message before signature, else after."
411 :group 'message-forwarding
414 (defcustom message-wash-forwarded-subjects nil
415 "*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."
416 :group 'message-forwarding
419 (defcustom message-ignored-resent-headers "^Return-receipt\\|^X-Gnus\\|^Gnus-Warning:"
420 "*All headers that match this regexp will be deleted when resending a message."
421 :group 'message-interface
424 (defcustom message-forward-ignored-headers "Content-Transfer-Encoding"
425 "*All headers that match this regexp will be deleted when forwarding a message."
426 :group 'message-forwarding
427 :type '(choice (const :tag "None" nil)
430 (defcustom message-ignored-cited-headers "."
431 "*Delete these headers from the messages you yank."
432 :group 'message-insertion
435 (defcustom message-cancel-message "I am canceling my own article.\n"
436 "Message to be inserted in the cancel message."
437 :group 'message-interface
440 ;; Useful to set in site-init.el
442 (defcustom message-send-mail-function 'message-send-mail-with-sendmail
443 "Function to call to send the current buffer as mail.
444 The headers should be delimited by a line whose contents match the
445 variable `mail-header-separator'.
447 Valid values include `message-send-mail-with-sendmail' (the default),
448 `message-send-mail-with-mh', `message-send-mail-with-qmail' and
449 `message-send-mail-with-smtp'."
450 :type '(radio (function-item message-send-mail-with-sendmail)
451 (function-item message-send-mail-with-mh)
452 (function-item message-send-mail-with-qmail)
453 (function-item message-send-mail-with-smtp)
454 (function :tag "Other"))
455 :group 'message-sending
456 :group 'message-mail)
458 ;; 1997-09-29 by MORIOKA Tomohiko
459 (defcustom message-send-news-function 'message-send-news-with-gnus
460 "Function to call to send the current buffer as news.
461 The headers should be delimited by a line whose contents match the
462 variable `mail-header-separator'."
463 :group 'message-sending
467 (defcustom message-reply-to-function nil
468 "Function that should return a list of headers.
469 This function should pick out addresses from the To, Cc, and From headers
470 and respond with new To and Cc headers."
471 :group 'message-interface
474 (defcustom message-wide-reply-to-function nil
475 "Function that should return a list of headers.
476 This function should pick out addresses from the To, Cc, and From headers
477 and respond with new To and Cc headers."
478 :group 'message-interface
481 (defcustom message-followup-to-function nil
482 "Function that should return a list of headers.
483 This function should pick out addresses from the To, Cc, and From headers
484 and respond with new To and Cc headers."
485 :group 'message-interface
488 (defcustom message-use-followup-to 'ask
489 "*Specifies what to do with Followup-To header.
490 If nil, always ignore the header. If it is t, use its value, but
491 query before using the \"poster\" value. If it is the symbol `ask',
492 always query the user whether to use the value. If it is the symbol
493 `use', always use the value."
494 :group 'message-interface
495 :type '(choice (const :tag "ignore" nil)
496 (const :tag "maybe" t)
497 (const :tag "always" use)
498 (const :tag "ask" ask)))
500 (defcustom message-use-mail-copies-to 'ask
501 "*Specifies what to do with Mail-Copies-To header.
502 If nil, always ignore the header. If it is t, use its value, but
503 query before using the value other than \"always\" or \"never\".
504 If it is the symbol `ask', always query the user whether to use
505 the value. If it is the symbol `use', always use the value."
506 :group 'message-interface
507 :type '(choice (const :tag "ignore" nil)
508 (const :tag "maybe" t)
509 (const :tag "always" use)
510 (const :tag "ask" ask)))
512 (defcustom message-use-mail-followup-to 'ask
513 "*Specifies what to do with Mail-Followup-To header.
514 If nil, always ignore the header. If it is the symbol `ask', always
515 query the user whether to use the value. If it is t or the symbol
516 `use', always use the value."
517 :group 'message-interface
518 :type '(choice (const :tag "ignore" nil)
519 (const :tag "maybe" t)
520 (const :tag "always" use)
521 (const :tag "ask" ask)))
523 ;;; XXX: 'ask and 'use are not implemented yet.
524 (defcustom message-use-mail-reply-to 'ask
525 "*Specifies what to do with Mail-Reply-To/Reply-To header.
526 If nil, always ignore the header. If it is t or the symbol `use', use
527 its value. If it is the symbol `ask', always query the user whether to
528 use the value. Note that if \"Reply-To\" is marked as \"broken\", its value
530 :group 'message-interface
531 :type '(choice (const :tag "ignore" nil)
532 (const :tag "maybe" t)
533 (const :tag "always" use)
534 (const :tag "ask" ask)))
536 (defcustom message-sendmail-f-is-evil nil
537 "*Non-nil means that \"-f username\" should not be added to the sendmail command line.
538 Doing so would be even more evil than leaving it out."
539 :group 'message-sending
542 ;; qmail-related stuff
543 (defcustom message-qmail-inject-program "/var/qmail/bin/qmail-inject"
544 "Location of the qmail-inject program."
545 :group 'message-sending
548 (defcustom message-qmail-inject-args nil
549 "Arguments passed to qmail-inject programs.
550 This should be a list of strings, one string for each argument.
552 For e.g., if you wish to set the envelope sender address so that bounces
553 go to the right place or to deal with listserv's usage of that address, you
554 might set this variable to '(\"-f\" \"you@some.where\")."
555 :group 'message-sending
556 :type '(repeat string))
558 (defvar message-cater-to-broken-inn t
559 "Non-nil means Gnus should not fold the `References' header.
560 Folding `References' makes ancient versions of INN create incorrect
563 (defvar gnus-post-method)
564 (defvar gnus-select-method)
565 (defcustom message-post-method
566 (cond ((and (boundp 'gnus-post-method)
567 (listp gnus-post-method)
570 ((boundp 'gnus-select-method)
573 "*Method used to post news.
574 Note that when posting from inside Gnus, for instance, this
575 variable isn't used."
577 :group 'message-sending
578 ;; This should be the `gnus-select-method' widget, but that might
579 ;; create a dependence to `gnus.el'.
582 (defcustom message-generate-headers-first nil
583 "*If non-nil, generate all possible headers before composing."
584 :group 'message-headers
587 (defcustom message-setup-hook '(turn-on-mime-edit)
588 "Normal hook, run each time a new outgoing message is initialized.
589 The function `message-setup' runs this hook."
590 :group 'message-various
593 (defcustom message-cancel-hook nil
594 "Hook run when cancelling articles."
595 :group 'message-various
598 (defcustom message-signature-setup-hook nil
599 "Normal hook, run each time a new outgoing message is initialized.
600 It is run after the headers have been inserted and before
601 the signature is inserted."
602 :group 'message-various
605 (defcustom message-bounce-setup-hook nil
606 "Normal hook, run each time a re-sending bounced message is initialized.
607 The function `message-bounce' runs this hook."
608 :group 'message-various
611 (defcustom message-supersede-setup-hook nil
612 "Normal hook, run each time a supersede message is initialized.
613 The function `message-supersede' runs this hook."
614 :group 'message-various
617 (defcustom message-mode-hook nil
618 "Hook run in message mode buffers."
619 :group 'message-various
622 (defcustom message-header-hook '((lambda () (eword-encode-header t)))
623 "Hook run in a message mode buffer narrowed to the headers."
624 :group 'message-various
627 (defcustom message-header-setup-hook nil
628 "Hook called narrowed to the headers when setting up a message buffer."
629 :group 'message-various
633 (defcustom message-citation-line-function 'message-insert-citation-line
634 "*Function called to insert the \"Whomever writes:\" line."
636 :group 'message-insertion)
639 (defcustom message-yank-prefix "> "
640 "*Prefix inserted on the lines of yanked messages."
642 :group 'message-insertion)
644 (defcustom message-yank-add-new-references t
645 "Non-nil means new IDs will be added to \"References\" field when an
646 article is yanked by the command `message-yank-original' interactively.
647 If it is a symbol `message-id-only', only an ID from \"Message-ID\" field
648 is used, otherwise IDs extracted from \"References\", \"In-Reply-To\" and
649 \"Message-ID\" fields are used."
650 :type '(radio (const :tag "Do not add anything" nil)
651 (const :tag "From Message-Id, References and In-Reply-To fields" t)
652 (const :tag "From only Message-Id field." message-id-only))
653 :group 'message-insertion)
655 (defcustom message-list-references-add-position nil
656 "Integer value means position for adding to \"References\" field when
657 an article is yanked by the command `message-yank-original' interactively."
658 :type '(radio (const :tag "Add to last" nil)
659 (integer :tag "Position from last ID"))
660 :group 'message-insertion)
662 (defcustom message-indentation-spaces 3
663 "*Number of spaces to insert at the beginning of each cited line.
664 Used by `message-yank-original' via `message-yank-cite'."
665 :group 'message-insertion
669 (defcustom message-cite-function 'message-cite-original
670 "*Function for citing an original message.
671 Predefined functions include `message-cite-original' and
672 `message-cite-original-without-signature'.
673 Note that `message-cite-original' uses `mail-citation-hook' if that is non-nil."
674 :type '(radio (function-item message-cite-original)
675 (function-item message-cite-original-without-signature)
676 (function-item mu-cite-original)
677 (function-item sc-cite-original)
678 (function :tag "Other"))
679 :group 'message-insertion)
682 (defcustom message-indent-citation-function 'message-indent-citation
683 "*Function for modifying a citation just inserted in the mail buffer.
684 This can also be a list of functions. Each function can find the
685 citation between (point) and (mark t). And each function should leave
686 point and mark around the citation text as modified."
688 :group 'message-insertion)
690 (defvar message-abbrevs-loaded nil)
693 (defcustom message-signature t
694 "*String to be inserted at the end of the message buffer.
695 If t, the `message-signature-file' file will be inserted instead.
696 If a function, the result from the function will be used instead.
697 If a form, the result from the form will be used instead."
699 :group 'message-insertion)
702 (defcustom message-signature-file "~/.signature"
703 "*File containing the text inserted at end of message buffer."
705 :group 'message-insertion)
707 (defcustom message-distribution-function nil
708 "*Function called to return a Distribution header."
710 :group 'message-headers
713 (defcustom message-expires 14
714 "Number of days before your article expires."
716 :group 'message-headers
717 :link '(custom-manual "(message)News Headers")
720 (defcustom message-user-path nil
721 "If nil, use the NNTP server name in the Path header.
722 If stringp, use this; if non-nil, use no host name (user name only)."
724 :group 'message-headers
725 :link '(custom-manual "(message)News Headers")
726 :type '(choice (const :tag "nntp" nil)
728 (sexp :tag "none" :format "%t" t)))
730 (defvar message-reply-buffer nil)
731 (defvar message-reply-headers nil)
732 (defvar message-sent-message-via nil)
733 (defvar message-checksum nil)
734 (defvar message-send-actions nil
735 "A list of actions to be performed upon successful sending of a message.")
736 (defvar message-exit-actions nil
737 "A list of actions to be performed upon exiting after sending a message.")
738 (defvar message-kill-actions nil
739 "A list of actions to be performed before killing a message buffer.")
740 (defvar message-postpone-actions nil
741 "A list of actions to be performed after postponing a message.")
742 (defvar message-original-frame nil)
743 (defvar message-parameter-alist nil)
744 (defvar message-startup-parameter-alist nil)
746 (define-widget 'message-header-lines 'text
747 "All header lines must be LFD terminated."
750 :error "All header lines must be newline terminated")
752 (defcustom message-default-headers ""
753 "*A string containing header lines to be inserted in outgoing messages.
754 It is inserted before you edit the message, so you can edit or delete
756 :group 'message-headers
757 :type 'message-header-lines)
759 (defcustom message-default-mail-headers ""
760 "*A string of header lines to be inserted in outgoing mails."
761 :group 'message-headers
763 :type 'message-header-lines)
765 (defcustom message-default-news-headers ""
766 "*A string of header lines to be inserted in outgoing news articles."
767 :group 'message-headers
769 :type 'message-header-lines)
771 ;; Note: could use /usr/ucb/mail instead of sendmail;
772 ;; options -t, and -v if not interactive.
773 (defcustom message-mailer-swallows-blank-line
774 (if (and (string-match "sparc-sun-sunos\\(\\'\\|[^5]\\)"
775 system-configuration)
776 (file-readable-p "/etc/sendmail.cf")
777 (let ((buffer (get-buffer-create " *temp*")))
781 (insert-file-contents "/etc/sendmail.cf")
782 (goto-char (point-min))
783 (let ((case-fold-search nil))
784 (re-search-forward "^OR\\>" nil t)))
785 (kill-buffer buffer))))
786 ;; According to RFC822, "The field-name must be composed of printable
787 ;; ASCII characters (i. e., characters that have decimal values between
788 ;; 33 and 126, except colon)", i. e., any chars except ctl chars,
790 '(looking-at "[ \t]\\|[][!\"#$%&'()*+,-./0-9;<=>?@A-Z\\\\^_`a-z{|}~]+:"))
791 "*Set this non-nil if the system's mailer runs the header and body together.
792 \(This problem exists on Sunos 4 when sendmail is run in remote mode.)
793 The value should be an expression to test whether the problem will
795 :group 'message-sending
798 ;;; XXX: This symbol is overloaded! See below.
799 (defvar message-user-agent nil
800 "String of the form of PRODUCT/VERSION. Used for User-Agent header field.")
802 ;; Ignore errors in case this is used in Emacs 19.
803 ;; Don't use ignore-errors because this is copied into loaddefs.el.
806 (define-mail-user-agent 'message-user-agent
807 'message-mail 'message-send-and-exit
808 'message-kill-buffer 'message-send-hook))
810 (defvar message-mh-deletable-headers '(Message-ID Date Lines Sender)
811 "If non-nil, delete the deletable headers before feeding to mh.")
813 (defvar message-send-method-alist
814 '((news message-news-p message-send-via-news)
815 (mail message-mail-p message-send-via-mail))
816 "Alist of ways to send outgoing messages.
817 Each element has the form
819 \(TYPE PREDICATE FUNCTION)
821 where TYPE is a symbol that names the method; PREDICATE is a function
822 called without any parameters to determine whether the message is
823 a message of type TYPE; and FUNCTION is a function to be called if
824 PREDICATE returns non-nil. FUNCTION is called with one parameter --
827 (defvar message-mail-alias-type 'abbrev
828 "*What alias expansion type to use in Message buffers.
829 The default is `abbrev', which uses mailabbrev. nil switches
832 (defcustom message-auto-save-directory
833 (nnheader-concat message-directory "drafts/")
834 "*Directory where Message auto-saves buffers if Gnus isn't running.
835 If nil, Message won't auto-save."
836 :group 'message-buffers
839 (defcustom message-buffer-naming-style 'unique
840 "*The way new message buffers are named.
841 Valid valued are `unique' and `unsent'."
842 :group 'message-buffers
843 :type '(choice (const :tag "unique" unique)
844 (const :tag "unsent" unsent)))
846 (defcustom message-default-charset nil
847 "Default charset used in non-MULE XEmacsen."
851 (defcustom message-dont-reply-to-names rmail-dont-reply-to-names
852 "*A regexp specifying names to prune when doing wide replies.
853 A value of nil means exclude your own name only."
855 :type '(choice (const :tag "Yourself" nil)
858 ;;; Internal variables.
859 ;;; Well, not really internal.
861 (defvar message-mode-syntax-table
862 (let ((table (copy-syntax-table text-mode-syntax-table)))
863 (modify-syntax-entry ?% ". " table)
864 (modify-syntax-entry ?> ". " table)
865 (modify-syntax-entry ?< ". " table)
867 "Syntax table used while in Message mode.")
869 (defvar message-mode-abbrev-table text-mode-abbrev-table
870 "Abbrev table used in Message mode buffers.
871 Defaults to `text-mode-abbrev-table'.")
872 (defgroup message-headers nil
874 :link '(custom-manual "(message)Variables")
877 (defface message-header-to-face
880 (:foreground "green2" :bold t))
883 (:foreground "MidnightBlue" :bold t))
885 (:bold t :italic t)))
886 "Face used for displaying From headers."
887 :group 'message-faces)
889 (defface message-header-cc-face
892 (:foreground "green4" :bold t))
895 (:foreground "MidnightBlue"))
898 "Face used for displaying Cc headers."
899 :group 'message-faces)
901 (defface message-header-subject-face
904 (:foreground "green3"))
907 (:foreground "navy blue" :bold t))
910 "Face used for displaying subject headers."
911 :group 'message-faces)
913 (defface message-header-newsgroups-face
916 (:foreground "yellow" :bold t :italic t))
919 (:foreground "blue4" :bold t :italic t))
921 (:bold t :italic t)))
922 "Face used for displaying newsgroups headers."
923 :group 'message-faces)
925 (defface message-header-other-face
928 (:foreground "#b00000"))
931 (:foreground "steel blue"))
933 (:bold t :italic t)))
934 "Face used for displaying newsgroups headers."
935 :group 'message-faces)
937 (defface message-header-name-face
940 (:foreground "DarkGreen"))
943 (:foreground "cornflower blue"))
946 "Face used for displaying header names."
947 :group 'message-faces)
949 (defface message-header-xheader-face
952 (:foreground "blue"))
955 (:foreground "blue"))
958 "Face used for displaying X-Header headers."
959 :group 'message-faces)
961 (defface message-separator-face
964 (:foreground "blue3"))
967 (:foreground "brown"))
970 "Face used for displaying the separator."
971 :group 'message-faces)
973 (defface message-cited-text-face
982 "Face used for displaying cited text names."
983 :group 'message-faces)
985 (defface message-mml-face
988 (:foreground "ForestGreen"))
991 (:foreground "ForestGreen"))
994 "Face used for displaying MML."
995 :group 'message-faces)
997 (defvar message-font-lock-fence-open-regexp "[+|]"
998 "*Regexp that matches fence open string.")
1000 (defvar message-font-lock-fence-close-regexp "|"
1001 "*Regexp that matches fence close string.")
1003 (defvar message-font-lock-fence-open-position nil
1004 "*Cons of SYMBOL of a function or a variable and a number of OFFSET that
1005 indicate the fence open position. If it is non-nil,
1006 `message-font-lock-fence-open-regexp' is not used for searching for the
1007 fence open position. If SYMBOL is a function, it is called with one argument
1008 last cursor position and should return the fence open position as a number
1009 or a marker. If SYMBOL is a variable symbol, the value is examined with
1010 `symbol-value'. OFFSET is added to the position to compensate the value.
1011 For example, the following combinations of variable symbol and offset value
1014 Egg v3: '(egg:*region-start* . -1)
1015 Canna: '(canna:*region-start* . 0)
1018 (defvar message-font-lock-fence-close-position nil
1019 "*Cons of SYMBOL of a function or a variable and a number of OFFSET that
1020 indicate the fence close position. If it is non-nil,
1021 `message-font-lock-fence-close-regexp' is not used for searching for the
1022 fence close position. If SYMBOL is a function, it is called with one argument
1023 last cursor position and should return the fence close position as a number
1024 or a marker. If SYMBOL is a variable symbol, the value is examined with
1025 `symbol-value'. OFFSET is added to the position to compensate the value.
1026 For example, the following combinations of variable symbol and offset value
1029 Egg v3: '(egg:*region-end* . 0)
1030 Canna: '(canna:*region-end* . 0)
1033 (defvar message-font-lock-cited-text-regexp
1034 "^[\t ]*\\([^\000- :>|}\177]*\\)[:>|}].*"
1035 "*Regexp that matches cited text. It should have a grouping for the
1036 citation prefix which is ended at the beginning of citation mark string.")
1038 (defvar message-font-lock-citation-name-max-column 10
1039 "*Maximun number of column for citation name for fontifying.")
1041 (defvar message-font-lock-last-position nil
1042 "Internal buffer local variable to save the last cursor position
1043 before fontifying.")
1045 (eval-after-load "font-lock"
1046 '(defadvice font-lock-after-change-function
1047 (before message-font-lock-save-last-position activate)
1048 "Save last cursor position before fontifying."
1049 (if (eq 'message-mode major-mode)
1050 (setq message-font-lock-last-position (point)))))
1052 (defun message-font-lock-cited-text-matcher (limit)
1053 "Search for a cited text containing `message-font-lock-cited-text-regexp'
1054 forward. Argument LIMIT bounds the search. If a cited text is found, it
1055 returns t and sets match data 1 and 2, otherwise it returns nil. Normally,
1056 match data 2 has zero length, but if the FENCE (for input method) is detected
1057 in matched text, result is divided into match data 1 and 2 across the FENCE.
1058 See also the documentations for the following variables:
1059 `message-font-lock-fence-open-regexp'
1060 `message-font-lock-fence-close-regexp'
1061 `message-font-lock-fence-open-position'
1062 `message-font-lock-fence-close-position'
1065 (when (re-search-forward message-font-lock-cited-text-regexp limit t)
1066 (let* ((start0 (match-beginning 0))
1067 (end0 (match-end 0))
1068 (cite-mark (match-end 1))
1071 (goto-char cite-mark)
1072 (<= (current-column)
1073 message-font-lock-citation-name-max-column)))
1077 message-font-lock-last-position
1078 (>= message-font-lock-last-position start0)
1079 (<= message-font-lock-last-position end0)
1081 (message-font-lock-fence-open-position
1082 (let* ((symbol (car message-font-lock-fence-open-position))
1084 (cond ((functionp symbol)
1085 (funcall symbol message-font-lock-last-position))
1086 ((and (symbolp symbol)
1088 (symbol-value symbol)))))
1089 (when (markerp open)
1090 (setq open (marker-position open)))
1094 (cdr message-font-lock-fence-open-position)))
1095 (>= message-font-lock-last-position open)
1097 (or (not message-font-lock-fence-open-regexp)
1098 (looking-at message-font-lock-fence-open-regexp))
1100 (message-font-lock-fence-open-regexp
1101 (goto-char message-font-lock-last-position)
1102 (when (re-search-backward
1103 message-font-lock-fence-open-regexp start0 t)
1104 (setq end1 (match-beginning 0)))))
1105 (setq should-fontify
1106 (and message-font-lock-fence-open-position
1107 (not (eq cite-mark end1))))
1109 (message-font-lock-fence-close-position
1110 (let* ((symbol (car message-font-lock-fence-close-position))
1112 (cond ((functionp symbol)
1113 (funcall symbol message-font-lock-last-position))
1114 ((and (symbolp symbol)
1116 (symbol-value symbol)))))
1117 (when (markerp close)
1118 (setq close (marker-position close)))
1119 (and (numberp close)
1122 (cdr message-font-lock-fence-close-position)))
1123 (<= message-font-lock-last-position close)
1124 (setq start2 close))))
1125 (message-font-lock-fence-close-regexp
1126 (goto-char message-font-lock-last-position)
1127 (when (looking-at message-font-lock-fence-close-regexp)
1128 (setq start2 (match-end 0)))))
1129 (setq should-fontify
1130 (and (not (and (not message-font-lock-fence-open-position)
1131 (eq cite-mark end1)))
1132 (not (eq cite-mark start2)))))
1134 (when should-fontify
1136 (store-match-data (list start0 end0 start0 end1 start2 end0))
1137 (store-match-data (list start0 end0 start0 end0 end0 end0)))
1139 (setq message-font-lock-last-position nil)))
1141 (defvar message-font-lock-keywords-1
1142 (let ((content "[ \t]*\\(.+\\(\n[ \t].*\\)*\\)"))
1143 `((,(concat "^\\([Tt]o:\\)" content)
1144 (1 'message-header-name-face)
1145 (2 'message-header-to-face nil t))
1146 (,(concat "^\\([GBF]?[Cc][Cc]:\\|[Rr]eply-[Tt]o:\\|"
1147 "[Mm]ail-[Cc]opies-[Tt]o:\\|"
1148 "[Mm]ail-[Rr]eply-[Tt]o:\\|"
1149 "[Mm]ail-[Ff]ollowup-[Tt]o:\\)" content)
1150 (1 'message-header-name-face)
1151 (2 'message-header-cc-face nil t))
1152 (,(concat "^\\([Ss]ubject:\\)" content)
1153 (1 'message-header-name-face)
1154 (2 'message-header-subject-face nil t))
1155 (,(concat "^\\([Nn]ewsgroups:\\|Followup-[Tt]o:\\)" content)
1156 (1 'message-header-name-face)
1157 (2 'message-header-newsgroups-face nil t))
1158 (,(concat "^\\([A-Z][^: \n\t]+:\\)" content)
1159 (1 'message-header-name-face)
1160 (2 'message-header-other-face nil t))
1161 (,(concat "^\\(X-[A-Za-z0-9-]+\\|In-Reply-To\\):" content)
1162 (1 'message-header-name-face)
1163 (2 'message-header-name-face))
1164 ,@(if (and mail-header-separator
1165 (not (equal mail-header-separator "")))
1166 `((,(concat "^\\(" (regexp-quote mail-header-separator) "\\)$")
1167 1 'message-separator-face))
1170 (defvar message-font-lock-keywords-2
1171 (append message-font-lock-keywords-1
1172 '((message-font-lock-cited-text-matcher
1173 (1 'message-cited-text-face)
1174 (2 'message-cited-text-face))
1175 ("<#/?\\(multipart\\|part\\|external\\).*>"
1176 (0 'message-mml-face)))))
1178 (defvar message-font-lock-keywords message-font-lock-keywords-2
1179 "Additional expressions to highlight in Message mode.")
1181 ;; XEmacs does it like this. For Emacs, we have to set the
1182 ;; `font-lock-defaults' buffer-local variable.
1183 (put 'message-mode 'font-lock-defaults
1184 '((message-font-lock-keywords
1185 message-font-lock-keywords-1
1186 message-font-lock-keywords-2)
1188 (font-lock-mark-block-function . mark-paragraph)))
1190 (defvar message-face-alist
1191 '((bold . bold-region)
1192 (underline . underline-region)
1193 (default . (lambda (b e)
1195 (ununderline-region b e))))
1196 "Alist of mail and news faces for facemenu.
1197 The cdr of ech entry is a function for applying the face to a region.")
1199 (defcustom message-send-hook nil
1200 "Hook run before sending messages."
1201 :group 'message-various
1202 :options '(ispell-message)
1205 (defcustom message-send-mail-hook nil
1206 "Hook run before sending mail messages."
1207 :group 'message-various
1210 (defcustom message-send-news-hook nil
1211 "Hook run before sending news messages."
1212 :group 'message-various
1215 (defcustom message-sent-hook nil
1216 "Hook run after sending messages."
1217 :group 'message-various
1220 (defcustom message-use-multi-frames nil
1221 "Make new frame when sending messages."
1222 :group 'message-frames
1225 (defcustom message-delete-frame-on-exit nil
1226 "Delete frame after sending messages."
1227 :group 'message-frames
1228 :type '(choice (const :tag "off" nil)
1229 (const :tag "always" t)
1230 (const :tag "ask" ask)))
1232 (defvar message-draft-coding-system
1234 ((boundp 'MULE) '*junet*)
1235 ((not (fboundp 'find-coding-system)) nil)
1236 ((find-coding-system 'emacs-mule)
1237 (if (memq system-type '(windows-nt ms-dos ms-windows))
1238 'emacs-mule-dos 'emacs-mule))
1239 ((find-coding-system 'escape-quoted) 'escape-quoted)
1240 ((find-coding-system 'no-conversion) 'no-conversion)
1242 "Coding system to compose mail.")
1244 ;;; Internal variables.
1246 (defvar message-buffer-list nil)
1247 (defvar message-this-is-news nil)
1248 (defvar message-this-is-mail nil)
1249 (defvar message-draft-article nil)
1250 (defvar message-mime-part nil)
1251 (defvar message-posting-charset nil)
1253 ;; Byte-compiler warning
1254 (defvar gnus-active-hashtb)
1255 (defvar gnus-read-active-file)
1257 ;;; Regexp matching the delimiter of messages in UNIX mail format
1258 ;;; (UNIX From lines), minus the initial ^. It should be a copy
1259 ;;; of rmail.el's rmail-unix-mail-delimiter.
1260 (defvar message-unix-mail-delimiter
1261 (let ((time-zone-regexp
1262 (concat "\\([A-Z]?[A-Z]?[A-Z][A-Z]\\( DST\\)?"
1263 "\\|[-+]?[0-9][0-9][0-9][0-9]"
1269 ;; Many things can happen to an RFC 822 mailbox before it is put into
1270 ;; a `From' line. The leading phrase can be stripped, e.g.
1271 ;; `Joe <@w.x:joe@y.z>' -> `<@w.x:joe@y.z>'. The <> can be stripped, e.g.
1272 ;; `<@x.y:joe@y.z>' -> `@x.y:joe@y.z'. Everything starting with a CRLF
1273 ;; can be removed, e.g.
1274 ;; From: joe@y.z (Joe K
1276 ;; can yield `From joe@y.z (Joe K Fri Mar 22 08:11:15 1996', and
1279 ;; can yield `From Joe User Fri Mar 22 08:11:15 1996'.
1280 ;; The mailbox can be removed or be replaced by white space, e.g.
1281 ;; From: "Joe User"{space}{tab}
1283 ;; can yield `From {space}{tab} Fri Mar 22 08:11:15 1996',
1284 ;; where {space} and {tab} represent the Ascii space and tab characters.
1285 ;; We want to match the results of any of these manglings.
1286 ;; The following regexp rejects names whose first characters are
1287 ;; obviously bogus, but after that anything goes.
1288 "\\([^\0-\b\n-\r\^?].*\\)? "
1290 ;; The time the message was sent.
1291 "\\([^\0-\r \^?]+\\) +" ; day of the week
1292 "\\([^\0-\r \^?]+\\) +" ; month
1293 "\\([0-3]?[0-9]\\) +" ; day of month
1294 "\\([0-2][0-9]:[0-5][0-9]\\(:[0-6][0-9]\\)?\\) *" ; time of day
1296 ;; Perhaps a time zone, specified by an abbreviation, or by a
1301 " \\([0-9][0-9]+\\) *"
1303 ;; On some systems the time zone can appear after the year, too.
1307 "\\(remote from .*\\)?"
1310 "Regexp matching the delimiter of messages in UNIX mail format.")
1312 (defvar message-unsent-separator
1313 (concat "^ *---+ +Unsent message follows +---+ *$\\|"
1314 "^ *---+ +Returned message +---+ *$\\|"
1315 "^Start of returned message$\\|"
1316 "^ *---+ +Original message +---+ *$\\|"
1317 "^ *--+ +begin message +--+ *$\\|"
1318 "^ *---+ +Original message follows +---+ *$\\|"
1319 "^ *---+ +Undelivered message follows +---+ *$\\|"
1320 "^|? *---+ +Message text follows: +---+ *|?$")
1321 "A regexp that matches the separator before the text of a failed message.")
1323 (defvar message-header-format-alist
1325 (To . message-fill-address)
1326 (Cc . message-fill-address)
1337 (References . message-shorten-references)
1339 "Alist used for formatting headers.")
1342 (autoload 'message-setup-toolbar "messagexmas")
1343 (autoload 'mh-new-draft-name "mh-comp")
1344 (autoload 'mh-send-letter "mh-comp")
1345 (autoload 'gnus-point-at-eol "gnus-util")
1346 (autoload 'gnus-point-at-bol "gnus-util")
1347 (autoload 'gnus-output-to-mail "gnus-util")
1348 (autoload 'mail-abbrev-in-expansion-header-p "mailabbrev")
1349 (autoload 'nndraft-request-associate-buffer "nndraft")
1350 (autoload 'nndraft-request-expire-articles "nndraft")
1351 (autoload 'gnus-open-server "gnus-int")
1352 (autoload 'gnus-request-post "gnus-int")
1353 (autoload 'gnus-copy-article-buffer "gnus-msg")
1354 (autoload 'gnus-alive-p "gnus-util")
1355 (autoload 'rmail-output "rmail")
1356 (autoload 'mu-cite-original "mu-cite"))
1361 ;;; Utility functions.
1363 (defun message-eval-parameter (parameter)
1365 (if (symbolp parameter)
1366 (if (functionp parameter)
1372 (defsubst message-get-parameter (key &optional alist)
1374 (setq alist message-parameter-alist))
1375 (cdr (assq key alist)))
1377 (defmacro message-get-parameter-with-eval (key &optional alist)
1378 `(message-eval-parameter (message-get-parameter ,key ,alist)))
1380 (defmacro message-y-or-n-p (question show &rest text)
1381 "Ask QUESTION, displaying the rest of the arguments in a temp. buffer if SHOW"
1382 `(message-talkative-question 'y-or-n-p ,question ,show ,@text))
1384 ;; Delete the current line (and the next N lines.);
1385 (defmacro message-delete-line (&optional n)
1386 `(delete-region (progn (beginning-of-line) (point))
1387 (progn (forward-line ,(or n 1)) (point))))
1389 (defun message-tokenize-header (header &optional separator)
1390 "Split HEADER into a list of header elements.
1391 \",\" is used as the separator."
1394 (let ((regexp (format "[%s]+" (or separator ",")))
1399 (message-set-work-buffer)
1401 (goto-char (point-min))
1406 (cond ((and (> (point) beg)
1408 (and (looking-at regexp)
1411 (push (buffer-substring beg (point)) elems)
1412 (setq beg (match-end 0)))
1413 ((eq (char-after) ?\")
1414 (setq quoted (not quoted)))
1415 ((and (eq (char-after) ?\()
1418 ((and (eq (char-after) ?\))
1421 (nreverse elems)))))
1423 (defun message-mail-file-mbox-p (file)
1424 "Say whether FILE looks like a Unix mbox file."
1425 (when (and (file-exists-p file)
1426 (file-readable-p file)
1427 (file-regular-p file))
1429 (nnheader-insert-file-contents file)
1430 (goto-char (point-min))
1431 (looking-at message-unix-mail-delimiter))))
1433 (defun message-fetch-field (header &optional not-all)
1434 "The same as `mail-fetch-field', only remove all newlines."
1435 (let* ((inhibit-point-motion-hooks t)
1436 (case-fold-search t)
1437 (value (mail-fetch-field header nil (not not-all))))
1439 (while (string-match "\n[\t ]+" value)
1440 (setq value (replace-match " " t t value)))
1441 ;; We remove all text props.
1442 (format "%s" value))))
1444 (defun message-narrow-to-field ()
1445 "Narrow the buffer to the header on the current line."
1451 (if (re-search-forward "^[^ \n\t]" nil t)
1456 (goto-char (point-min)))
1458 (defun message-add-header (&rest headers)
1459 "Add the HEADERS to the message header, skipping those already present."
1462 (unless (string-match "^\\([^:]+\\):[ \t]*[^ \t]" (car headers))
1463 (error "Invalid header `%s'" (car headers)))
1464 (setq hclean (match-string 1 (car headers)))
1466 (message-narrow-to-headers)
1467 (unless (re-search-forward (concat "^" (regexp-quote hclean) ":") nil t)
1468 (insert (car headers) ?\n))))
1469 (setq headers (cdr headers))))
1472 (defun message-fetch-reply-field (header)
1473 "Fetch FIELD from the message we're replying to."
1474 (let ((buffer (message-eval-parameter message-reply-buffer)))
1476 (buffer-name buffer))
1479 (message-fetch-field header)))))
1481 (defun message-set-work-buffer ()
1482 (if (get-buffer " *message work*")
1484 (set-buffer " *message work*")
1486 (set-buffer (get-buffer-create " *message work*"))
1487 (kill-all-local-variables)))
1489 (defun message-functionp (form)
1490 "Return non-nil if FORM is funcallable."
1491 (or (and (symbolp form) (fboundp form))
1492 (and (listp form) (eq (car form) 'lambda))
1493 (byte-code-function-p form)))
1495 (defun message-strip-subject-re (subject)
1496 "Remove \"Re:\" from subject lines."
1497 (if (string-match message-subject-re-regexp subject)
1498 (substring subject (match-end 0))
1501 (defun message-remove-header (header &optional is-regexp first reverse)
1502 "Remove HEADER in the narrowed buffer.
1503 If REGEXP, HEADER is a regular expression.
1504 If FIRST, only remove the first instance of the header.
1505 Return the number of headers removed."
1506 (goto-char (point-min))
1507 (let ((regexp (if is-regexp header (concat "^" (regexp-quote header) ":")))
1509 (case-fold-search t)
1511 (while (and (not (eobp))
1514 (not (looking-at regexp))
1515 (looking-at regexp))
1522 ;; There might be a continuation header, so we have to search
1523 ;; until we find a new non-continuation line.
1526 (if (re-search-forward "^[^ \t]" nil t)
1527 (goto-char (match-beginning 0))
1530 (if (re-search-forward "^[^ \t]" nil t)
1531 (goto-char (match-beginning 0))
1532 (goto-char (point-max)))))
1535 (defun message-remove-first-header (header)
1536 "Remove the first instance of HEADER if there is more than one."
1538 (regexp (concat "^" (regexp-quote header) ":")))
1540 (goto-char (point-min))
1541 (while (re-search-forward regexp nil t)
1544 (message-remove-header header nil t)
1547 (defun message-narrow-to-headers ()
1548 "Narrow the buffer to the head of the message."
1551 (goto-char (point-min))
1552 (if (re-search-forward
1553 (concat "^" (regexp-quote mail-header-separator) "\n") nil t)
1556 (goto-char (point-min)))
1558 (defun message-narrow-to-head ()
1559 "Narrow the buffer to the head of the message.
1560 Point is left at the beginning of the narrowed-to region."
1563 (goto-char (point-min))
1564 (if (search-forward "\n\n" nil 1)
1567 (goto-char (point-min)))
1569 (defun message-narrow-to-headers-or-head ()
1570 "Narrow the buffer to the head of the message."
1573 (goto-char (point-min))
1576 (concat "^" (regexp-quote mail-header-separator) "\n") nil t)
1577 (match-beginning 0))
1578 ((search-forward "\n\n" nil t)
1582 (goto-char (point-min)))
1584 (defun message-news-p ()
1585 "Say whether the current buffer contains a news message."
1586 (and (not message-this-is-mail)
1587 (or message-this-is-news
1590 (message-narrow-to-headers)
1591 (and (message-fetch-field "newsgroups")
1592 (not (message-fetch-field "posted-to"))))))))
1594 (defun message-mail-p ()
1595 "Say whether the current buffer contains a mail message."
1596 (and (not message-this-is-news)
1597 (or message-this-is-mail
1600 (message-narrow-to-headers)
1601 (or (message-fetch-field "to")
1602 (message-fetch-field "cc")
1603 (message-fetch-field "bcc")))))))
1605 (defun message-next-header ()
1606 "Go to the beginning of the next header."
1608 (or (eobp) (forward-char 1))
1609 (not (if (re-search-forward "^[^ \t]" nil t)
1611 (goto-char (point-max)))))
1613 (defun message-sort-headers-1 ()
1614 "Sort the buffer as headers using `message-rank' text props."
1615 (goto-char (point-min))
1618 nil 'message-next-header
1620 (message-next-header)
1624 (or (get-text-property (point) 'message-rank)
1627 (defun message-sort-headers ()
1628 "Sort the headers of the current message according to `message-header-format-alist'."
1632 (let ((max (1+ (length message-header-format-alist)))
1634 (message-narrow-to-headers)
1635 (while (re-search-forward "^[^ \n]+:" nil t)
1637 (match-beginning 0) (1+ (match-beginning 0))
1639 (if (setq rank (length (memq (assq (intern (buffer-substring
1641 (1- (match-end 0))))
1642 message-header-format-alist)
1643 message-header-format-alist)))
1646 (message-sort-headers-1))))
1656 (defvar message-mode-map nil)
1658 (unless message-mode-map
1659 (setq message-mode-map (make-keymap))
1660 (set-keymap-parent message-mode-map text-mode-map)
1661 (define-key message-mode-map "\C-c?" 'describe-mode)
1663 (define-key message-mode-map "\C-c\C-f\C-t" 'message-goto-to)
1664 (define-key message-mode-map "\C-c\C-f\C-b" 'message-goto-bcc)
1665 (define-key message-mode-map "\C-c\C-f\C-w" 'message-goto-fcc)
1666 (define-key message-mode-map "\C-c\C-f\C-c" 'message-goto-cc)
1667 (define-key message-mode-map "\C-c\C-f\C-s" 'message-goto-subject)
1668 ;; (define-key message-mode-map "\C-c\C-f\C-r" 'message-goto-reply-to)
1669 (define-key message-mode-map "\C-c\C-f\C-r" 'message-goto-mail-reply-to)
1670 (define-key message-mode-map "\C-c\C-f\C-m" 'message-goto-mail-followup-to)
1671 (define-key message-mode-map "\C-c\C-f\C-n" 'message-goto-newsgroups)
1672 (define-key message-mode-map "\C-c\C-f\C-d" 'message-goto-distribution)
1673 (define-key message-mode-map "\C-c\C-f\C-f" 'message-goto-followup-to)
1674 (define-key message-mode-map "\C-c\C-f\C-k" 'message-goto-keywords)
1675 (define-key message-mode-map "\C-c\C-f\C-u" 'message-goto-summary)
1676 (define-key message-mode-map "\C-c\C-b" 'message-goto-body)
1677 (define-key message-mode-map "\C-c\C-i" 'message-goto-signature)
1678 (define-key message-mode-map "\C-c\C-fc" 'message-goto-mail-copies-to)
1680 (define-key message-mode-map "\C-c\C-t" 'message-insert-to)
1681 (define-key message-mode-map "\C-c\C-n" 'message-insert-newsgroups)
1683 (define-key message-mode-map "\C-c\C-y" 'message-yank-original)
1684 (define-key message-mode-map "\C-c\M-\C-y" 'message-yank-buffer)
1685 (define-key message-mode-map "\C-c\C-q" 'message-fill-yanked-message)
1686 (define-key message-mode-map "\C-c\C-w" 'message-insert-signature)
1687 (define-key message-mode-map "\C-c\M-h" 'message-insert-headers)
1688 (define-key message-mode-map "\C-c\C-r" 'message-caesar-buffer-body)
1689 (define-key message-mode-map "\C-c\C-o" 'message-sort-headers)
1690 (define-key message-mode-map "\C-c\M-r" 'message-rename-buffer)
1692 (define-key message-mode-map "\C-c\C-c" 'message-send-and-exit)
1693 (define-key message-mode-map "\C-c\C-s" 'message-send)
1694 (define-key message-mode-map "\C-c\C-k" 'message-kill-buffer)
1695 (define-key message-mode-map "\C-c\C-d" 'message-dont-send)
1697 (define-key message-mode-map "\C-c\C-e" 'message-elide-region)
1698 (define-key message-mode-map "\C-c\C-v" 'message-delete-not-region)
1699 (define-key message-mode-map "\C-c\C-z" 'message-kill-to-signature)
1700 (define-key message-mode-map "\M-\r" 'message-newline-and-reformat)
1702 (define-key message-mode-map "\t" 'message-tab)
1704 (define-key message-mode-map "\C-x\C-s" 'message-save-drafts)
1705 (define-key message-mode-map "\C-xk" 'message-mimic-kill-buffer))
1708 message-mode-menu message-mode-map "Message Menu."
1710 ["Sort Headers" message-sort-headers t]
1711 ["Yank Original" message-yank-original t]
1712 ["Fill Yanked Message" message-fill-yanked-message t]
1713 ["Insert Signature" message-insert-signature t]
1714 ["Caesar (rot13) Message" message-caesar-buffer-body t]
1715 ["Caesar (rot13) Region" message-caesar-region (mark t)]
1716 ["Elide Region" message-elide-region (mark t)]
1717 ["Delete Outside Region" message-delete-not-region (mark t)]
1718 ["Kill To Signature" message-kill-to-signature t]
1719 ["Newline and Reformat" message-newline-and-reformat t]
1720 ["Rename buffer" message-rename-buffer t]
1721 ["Spellcheck" ispell-message t]
1722 ["Attach file as MIME" mime-edit-insert-file t]
1724 ["Send Message" message-send-and-exit t]
1725 ["Abort Message" message-dont-send t]
1726 ["Kill Message" message-kill-buffer t]))
1729 message-mode-field-menu message-mode-map ""
1731 ["Fetch To" message-insert-to t]
1732 ["Fetch Newsgroups" message-insert-newsgroups t]
1734 ["To" message-goto-to t]
1735 ["Subject" message-goto-subject t]
1736 ["Cc" message-goto-cc t]
1737 ["Reply-To" message-goto-reply-to t]
1738 ["Mail-Reply-To" message-goto-mail-reply-to t]
1739 ["Mail-Followup-To" message-goto-mail-followup-to t]
1740 ["Mail-Copies-To" message-goto-mail-copies-to t]
1741 ["Summary" message-goto-summary t]
1742 ["Keywords" message-goto-keywords t]
1743 ["Newsgroups" message-goto-newsgroups t]
1744 ["Followup-To" message-goto-followup-to t]
1745 ["Distribution" message-goto-distribution t]
1746 ["Body" message-goto-body t]
1747 ["Signature" message-goto-signature t]))
1749 (defvar facemenu-add-face-function)
1750 (defvar facemenu-remove-face-function)
1753 (defun message-mode ()
1754 "Major mode for editing mail and news to be sent.
1755 Like Text Mode but with these additional commands:
1756 C-c C-s message-send (send the message) C-c C-c message-send-and-exit
1757 C-c C-d Pospone sending the message C-c C-k Kill the message
1758 C-c C-f move to a header field (and create it if there isn't):
1759 C-c C-f C-t move to To C-c C-f C-s move to Subject
1760 C-c C-f C-c move to Cc C-c C-f C-b move to Bcc
1761 C-c C-f C-w move to Fcc C-c C-f C-r move to Reply-To
1762 C-c C-f C-u move to Summary C-c C-f C-n move to Newsgroups
1763 C-c C-f C-k move to Keywords C-c C-f C-d move to Distribution
1764 C-c C-f C-m move to Mail-Followup-To
1765 C-c C-f C-f move to Followup-To
1766 C-c C-t message-insert-to (add a To header to a news followup)
1767 C-c C-n message-insert-newsgroups (add a Newsgroup header to a news reply)
1768 C-c C-b message-goto-body (move to beginning of message text).
1769 C-c C-i message-goto-signature (move to the beginning of the signature).
1770 C-c C-w message-insert-signature (insert `message-signature-file' file).
1771 C-c C-y message-yank-original (insert current message, if any).
1772 C-c C-q message-fill-yanked-message (fill what was yanked).
1773 C-c C-e message-elide-region (elide the text between point and mark).
1774 C-c C-v message-delete-not-region (remove the text outside the region).
1775 C-c C-z message-kill-to-signature (kill the text up to the signature).
1776 C-c C-r message-caesar-buffer-body (rot13 the message body).
1777 M-RET message-newline-and-reformat (break the line and reformat)."
1779 (kill-all-local-variables)
1780 (set (make-local-variable 'message-reply-buffer) nil)
1781 (make-local-variable 'message-send-actions)
1782 (make-local-variable 'message-exit-actions)
1783 (make-local-variable 'message-kill-actions)
1784 (make-local-variable 'message-postpone-actions)
1785 (make-local-variable 'message-draft-article)
1786 (make-local-hook 'kill-buffer-hook)
1787 (set-syntax-table message-mode-syntax-table)
1788 (use-local-map message-mode-map)
1789 (setq local-abbrev-table message-mode-abbrev-table)
1790 (setq major-mode 'message-mode)
1791 (setq mode-name "Message")
1792 (setq buffer-offer-save t)
1793 (make-local-variable 'facemenu-add-face-function)
1794 (make-local-variable 'facemenu-remove-face-function)
1795 (setq facemenu-add-face-function
1797 (let ((face-fun (cdr (assq face message-face-alist))))
1799 (funcall face-fun (point) end)
1800 (error "Face %s not configured for %s mode" face mode-name)))
1802 facemenu-remove-face-function t)
1803 (make-local-variable 'paragraph-separate)
1804 (make-local-variable 'paragraph-start)
1805 ;; `-- ' precedes the signature. `-----' appears at the start of the
1806 ;; lines that delimit forwarded messages.
1807 ;; Lines containing just >= 3 dashes, perhaps after whitespace,
1808 ;; are also sometimes used and should be separators.
1809 (setq paragraph-start
1810 (concat (regexp-quote mail-header-separator)
1811 "$\\|[ \t]*[a-z0-9A-Z]*>+[ \t]*$\\|[ \t]*$\\|"
1814 ;;!!! Uhm... shurely this can't be right?
1815 "[> " (regexp-quote message-yank-prefix) "]+$"))
1816 (setq paragraph-separate paragraph-start)
1817 (make-local-variable 'message-reply-headers)
1818 (setq message-reply-headers nil)
1819 (make-local-variable 'message-user-agent)
1820 (make-local-variable 'message-post-method)
1821 (set (make-local-variable 'message-sent-message-via) nil)
1822 (set (make-local-variable 'message-checksum) nil)
1823 (make-local-variable 'message-parameter-alist)
1824 (setq message-parameter-alist
1825 (copy-sequence message-startup-parameter-alist))
1826 ;;(when (fboundp 'mail-hist-define-keys)
1827 ;; (mail-hist-define-keys))
1828 (when (string-match "XEmacs\\|Lucid" emacs-version)
1829 (message-setup-toolbar))
1830 (easy-menu-add message-mode-menu message-mode-map)
1831 (easy-menu-add message-mode-field-menu message-mode-map)
1832 ;; Allow mail alias things.
1833 (when (eq message-mail-alias-type 'abbrev)
1834 (if (fboundp 'mail-abbrevs-setup)
1835 (mail-abbrevs-setup)
1836 (mail-aliases-setup)))
1837 (message-set-auto-save-file-name)
1838 (unless (string-match "XEmacs" emacs-version)
1839 (set (make-local-variable 'font-lock-defaults)
1840 '((message-font-lock-keywords
1841 message-font-lock-keywords-1
1842 message-font-lock-keywords-2)
1844 (font-lock-mark-block-function . mark-paragraph))))
1845 (set (make-local-variable 'message-font-lock-last-position) nil)
1846 (make-local-variable 'adaptive-fill-regexp)
1847 (setq adaptive-fill-regexp
1848 (concat "[ \t]*[-a-z0-9A-Z]*\\(>[ \t]*\\)+[ \t]*\\|"
1849 adaptive-fill-regexp))
1850 (unless (boundp 'adaptive-fill-first-line-regexp)
1851 (setq adaptive-fill-first-line-regexp nil))
1852 (make-local-variable 'adaptive-fill-first-line-regexp)
1853 (setq adaptive-fill-first-line-regexp
1854 (concat "[ \t]*[-a-z0-9A-Z]*\\(>[ \t]*\\)+[ \t]*\\|"
1855 adaptive-fill-first-line-regexp))
1856 (make-local-variable 'auto-fill-inhibit-regexp)
1857 (setq auto-fill-inhibit-regexp "^[A-Z][^: \n\t]+:")
1858 (make-local-variable 'indent-tabs-mode) ;Turn off tabs for indentation.
1859 (setq indent-tabs-mode nil)
1860 (run-hooks 'text-mode-hook 'message-mode-hook))
1865 ;;; Message mode commands
1868 ;;; Movement commands
1870 (defun message-goto-to ()
1871 "Move point to the To header."
1873 (message-position-on-field "To"))
1875 (defun message-goto-subject ()
1876 "Move point to the Subject header."
1878 (message-position-on-field "Subject"))
1880 (defun message-goto-cc ()
1881 "Move point to the Cc header."
1883 (message-position-on-field "Cc" "To"))
1885 (defun message-goto-bcc ()
1886 "Move point to the Bcc header."
1888 (message-position-on-field "Bcc" "Cc" "To"))
1890 (defun message-goto-fcc ()
1891 "Move point to the Fcc header."
1893 (message-position-on-field "Fcc" "To" "Newsgroups"))
1895 (defun message-goto-reply-to ()
1896 "Move point to the Reply-To header."
1898 (message-position-on-field "Reply-To" "Subject"))
1900 (defun message-goto-mail-reply-to ()
1901 "Move point to the Mail-Reply-To header."
1903 (message-position-on-field "Mail-Reply-To" "Subject"))
1905 (defun message-goto-mail-followup-to ()
1906 "Move point to the Mail-Followup-To header. If the header is newly created
1907 and To field contains only one address, the address is inserted in default."
1909 (unless (message-position-on-field "Mail-Followup-To" "Subject")
1910 (let ((start (point))
1913 (message-narrow-to-headers)
1914 (setq addresses (split-string (mail-strip-quoted-names
1915 (or (std11-fetch-field "to") ""))
1917 (when (eq 1 (length addresses))
1919 (insert (car addresses))
1920 (goto-char start))))))
1922 (defun message-goto-mail-copies-to ()
1923 "Move point to the Mail-Copies-To header. If the header is newly created,
1924 a string \"never\" is inserted in default."
1926 (unless (message-position-on-field "Mail-Copies-To" "Subject")
1930 (defun message-goto-newsgroups ()
1931 "Move point to the Newsgroups header."
1933 (message-position-on-field "Newsgroups"))
1935 (defun message-goto-distribution ()
1936 "Move point to the Distribution header."
1938 (message-position-on-field "Distribution"))
1940 (defun message-goto-followup-to ()
1941 "Move point to the Followup-To header."
1943 (message-position-on-field "Followup-To" "Newsgroups"))
1945 (defun message-goto-keywords ()
1946 "Move point to the Keywords header."
1948 (message-position-on-field "Keywords" "Subject"))
1950 (defun message-goto-summary ()
1951 "Move point to the Summary header."
1953 (message-position-on-field "Summary" "Subject"))
1955 (defun message-goto-body ()
1956 "Move point to the beginning of the message body."
1958 (if (looking-at "[ \t]*\n") (expand-abbrev))
1959 (goto-char (point-min))
1960 (or (search-forward (concat "\n" mail-header-separator "\n") nil t)
1961 (search-forward "\n\n" nil t)))
1963 (defun message-goto-eoh ()
1964 "Move point to the end of the headers."
1969 (defun message-goto-signature ()
1970 "Move point to the beginning of the message signature.
1971 If there is no signature in the article, go to the end and
1974 (goto-char (point-min))
1975 (if (re-search-forward message-signature-separator nil t)
1977 (goto-char (point-max))
1982 (defun message-insert-to (&optional force)
1983 "Insert a To header that points to the author of the article being replied to.
1984 If the original author requested not to be sent mail, the function signals
1986 With the prefix argument FORCE, insert the header anyway."
1988 (let ((co (message-fetch-reply-field "mail-copies-to")))
1989 (when (and (null force)
1991 (or (equal (downcase co) "never")
1992 (equal (downcase co) "nobody")))
1993 (error "The user has requested not to have copies sent via mail")))
1994 (when (and (message-position-on-field "To")
1995 (mail-fetch-field "to")
1996 (not (string-match "\\` *\\'" (mail-fetch-field "to"))))
1998 (insert (or (message-fetch-reply-field "reply-to")
1999 (message-fetch-reply-field "from") "")))
2001 (defun message-widen-reply ()
2002 "Widen the reply to include maximum recipients."
2005 (and message-reply-buffer
2006 (buffer-name message-reply-buffer)
2008 (set-buffer message-reply-buffer)
2009 (message-get-reply-headers t)))))
2012 (message-narrow-to-headers)
2013 (dolist (elem follow-to)
2014 (message-remove-header (symbol-name (car elem)))
2015 (goto-char (point-min))
2016 (insert (symbol-name (car elem)) ": "
2017 (cdr elem) "\n"))))))
2019 (defun message-insert-newsgroups ()
2020 "Insert the Newsgroups header from the article being replied to."
2022 (when (and (message-position-on-field "Newsgroups")
2023 (mail-fetch-field "newsgroups")
2024 (not (string-match "\\` *\\'" (mail-fetch-field "newsgroups"))))
2026 (insert (or (message-fetch-reply-field "newsgroups") "")))
2030 ;;; Various commands
2032 (defun message-delete-not-region (beg end)
2033 "Delete everything in the body of the current message that is outside of the region."
2037 (delete-region (point) (if (not (message-goto-signature))
2043 (delete-region beg (progn (message-goto-body)
2046 (when (message-goto-signature)
2049 (defun message-kill-to-signature ()
2050 "Deletes all text up to the signature."
2052 (let ((point (point)))
2053 (message-goto-signature)
2056 (kill-region point (point))
2060 (defun message-newline-and-reformat ()
2061 "Insert four newlines, and then reformat if inside quoted text."
2063 (let ((prefix "[]>»|:}+ \t]*")
2064 (supercite-thing "[-._a-zA-Z0-9]*[>]+[ \t]*")
2069 (when (looking-at (concat prefix
2071 (setq quoted (match-string 0))))
2073 (setq point (point))
2075 (delete-region (point) (re-search-forward "[ \t]*"))
2078 (fill-paragraph nil)
2082 (defun message-insert-signature (&optional force)
2083 "Insert a signature. See documentation for the `message-signature' variable."
2084 (interactive (list 0))
2087 ((and (null message-signature)
2090 (goto-char (point-max))
2091 (not (re-search-backward message-signature-separator nil t))))
2092 ((and (null message-signature)
2095 ((message-functionp message-signature)
2096 (funcall message-signature))
2097 ((listp message-signature)
2098 (eval message-signature))
2099 (t message-signature)))
2101 (cond ((stringp signature)
2103 ((and (eq t signature)
2104 message-signature-file
2105 (file-exists-p message-signature-file))
2108 (goto-char (point-max))
2109 ;; Insert the signature.
2113 (if (eq signature t)
2114 (insert-file-contents message-signature-file)
2116 (goto-char (point-max))
2117 (or (bolp) (insert "\n")))))
2119 (defun message-elide-region (b e)
2120 "Elide the text between point and mark.
2121 An ellipsis (from `message-elide-ellipsis') will be inserted where the
2125 (insert message-elide-ellipsis))
2127 (defvar message-caesar-translation-table nil)
2129 (defun message-caesar-region (b e &optional n)
2130 "Caesar rotation of region by N, default 13, for decrypting netnews."
2133 (min (point) (or (mark t) (point)))
2134 (max (point) (or (mark t) (point)))
2135 (when current-prefix-arg
2136 (prefix-numeric-value current-prefix-arg))))
2138 (setq n (if (numberp n) (mod n 26) 13)) ;canonize N
2139 (unless (or (zerop n) ; no action needed for a rot of 0
2140 (= b e)) ; no region to rotate
2141 ;; We build the table, if necessary.
2142 (when (or (not message-caesar-translation-table)
2143 (/= (aref message-caesar-translation-table ?a) (+ ?a n)))
2144 (setq message-caesar-translation-table
2145 (message-make-caesar-translation-table n)))
2146 (translate-region b e message-caesar-translation-table)))
2148 (defun message-make-caesar-translation-table (n)
2149 "Create a rot table with offset N."
2151 (table (make-string 256 0)))
2152 (while (< (incf i) 256)
2155 (substring table 0 ?A)
2156 (substring table (+ ?A n) (+ ?A n (- 26 n)))
2157 (substring table ?A (+ ?A n))
2158 (substring table (+ ?A 26) ?a)
2159 (substring table (+ ?a n) (+ ?a n (- 26 n)))
2160 (substring table ?a (+ ?a n))
2161 (substring table (+ ?a 26) 255))))
2163 (defun message-caesar-buffer-body (&optional rotnum)
2164 "Caesar rotates all letters in the current buffer by 13 places.
2165 Used to encode/decode possiblyun offensive messages (commonly in net.jokes).
2166 With prefix arg, specifies the number of places to rotate each letter forward.
2167 Mail and USENET news headers are not rotated."
2168 (interactive (if current-prefix-arg
2169 (list (prefix-numeric-value current-prefix-arg))
2173 (when (message-goto-body)
2174 (narrow-to-region (point) (point-max)))
2175 (message-caesar-region (point-min) (point-max) rotnum))))
2177 (defun message-pipe-buffer-body (program)
2178 "Pipe the message body in the current buffer through PROGRAM."
2181 (when (message-goto-body)
2182 (narrow-to-region (point) (point-max)))
2183 (shell-command-on-region
2184 (point-min) (point-max) program nil t))))
2186 (defun message-rename-buffer (&optional enter-string)
2187 "Rename the *message* buffer to \"*message* RECIPIENT\".
2188 If the function is run with a prefix, it will ask for a new buffer
2189 name, rather than giving an automatic name."
2190 (interactive "Pbuffer name: ")
2193 (goto-char (point-min))
2194 (narrow-to-region (point)
2195 (search-forward mail-header-separator nil 'end))
2197 (if (message-news-p) (message-fetch-field "Newsgroups")
2198 (message-fetch-field "To"))
2201 (if (string-match "," mail-to)
2202 (concat (substring mail-to 0 (match-beginning 0)) ", ...")
2204 (name-default (concat "*message* " mail-trimmed-to))
2205 (name (if enter-string
2206 (read-string "New buffer name: " name-default)
2208 (rename-buffer name t)))))
2210 (defun message-fill-yanked-message (&optional justifyp)
2211 "Fill the paragraphs of a message yanked into this one.
2212 Numeric argument means justify as well."
2215 (goto-char (point-min))
2216 (search-forward (concat "\n" mail-header-separator "\n") nil t)
2217 (let ((fill-prefix message-yank-prefix))
2218 (fill-individual-paragraphs (point) (point-max) justifyp))))
2220 (defun message-indent-citation ()
2221 "Modify text just inserted from a message to be cited.
2222 The inserted text should be the region.
2223 When this function returns, the region is again around the modified text.
2225 Normally, indent each nonblank line `message-indentation-spaces' spaces.
2226 However, if `message-yank-prefix' is non-nil, insert that prefix on each line."
2227 (let ((start (point)))
2228 ;; Remove unwanted headers.
2229 (when message-ignored-cited-headers
2234 (if (search-forward "\n\n" nil t)
2237 (message-remove-header message-ignored-cited-headers t)
2238 (when (= (point-min) (point-max))
2239 (setq all-removed t))
2240 (goto-char (point-max)))
2244 ;; Delete blank lines at the start of the buffer.
2245 (while (and (point-min)
2248 (message-delete-line))
2249 ;; Delete blank lines at the end of the buffer.
2250 (goto-char (point-max))
2253 (while (and (zerop (forward-line -1))
2255 (message-delete-line))
2256 ;; Do the indentation.
2257 (if (null message-yank-prefix)
2258 (indent-rigidly start (mark t) message-indentation-spaces)
2261 (while (< (point) (mark t))
2262 (insert message-yank-prefix)
2266 (defun message-list-references (refs-list &rest refs-strs)
2267 "Add `Message-ID's which appear in REFS-STRS but not in REFS-LIST,
2269 (let (refs ref id saved-id)
2270 (when (and refs-list
2271 (integerp message-list-references-add-position))
2272 (let ((pos message-list-references-add-position))
2273 (while (and refs-list
2275 (setq saved-id (cons (car refs-list) saved-id)
2276 refs-list (cdr refs-list)
2279 (setq refs (car refs-strs)
2280 refs-strs (cdr refs-strs))
2282 (setq refs (std11-parse-msg-ids (std11-lexical-analyze refs)))
2284 (setq ref (car refs)
2286 (when (eq (car ref) 'msg-id)
2287 (setq id (concat "<"
2289 (function (lambda (p) (cdr p)))
2292 (or (member id refs-list)
2293 (push id refs-list))))))
2295 (setq refs-list (cons (car saved-id) refs-list)
2296 saved-id (cdr saved-id)))
2299 (defvar gnus-article-copy)
2300 (defun message-yank-original (&optional arg)
2301 "Insert the message being replied to, if any.
2302 Puts point before the text and mark after.
2303 Normally indents each nonblank line ARG spaces (default 3). However,
2304 if `message-yank-prefix' is non-nil, insert that prefix on each line.
2306 This function uses `message-cite-function' to do the actual citing.
2308 Just \\[universal-argument] as argument means don't indent, insert no
2309 prefix, and don't delete any headers.
2311 In addition, if `message-yank-add-new-references' is non-nil and this
2312 command is called interactively, new IDs from the yanked article will
2313 be added to \"References\" field.
2314 \(See also `message-yank-add-new-references'.)"
2316 (let ((modified (buffer-modified-p))
2317 (buffer (message-eval-parameter message-reply-buffer))
2320 message-cite-function)
2321 (delete-windows-on buffer t)
2322 (insert-buffer buffer) ; mark will be set at the end of article.
2326 ;; Add new IDs to References field.
2327 (when (and message-yank-add-new-references (interactive-p))
2330 (message-narrow-to-headers)
2331 (setq refs (message-list-references
2333 (message-fetch-field "References")))
2335 (narrow-to-region start end)
2336 (std11-narrow-to-header)
2337 (when (setq refs (message-list-references
2339 (unless (eq message-yank-add-new-references
2341 (or (message-fetch-field "References")
2342 (message-fetch-field "In-Reply-To")))
2343 (message-fetch-field "Message-ID")))
2345 (message-narrow-to-headers)
2346 (goto-char (point-min))
2347 (let ((case-fold-search t))
2348 (if (re-search-forward "^References:\\([\t ]+.+\n\\)+" nil t)
2350 (goto-char (point-max))))
2352 (list (or (assq 'References message-header-format-alist)
2353 '(References . message-fill-references)))
2354 (list (cons 'References
2355 (mapconcat 'identity (nreverse refs) " "))))
2356 (backward-delete-char 1)))))
2358 (funcall message-cite-function)
2359 (message-exchange-point-and-mark)
2363 (setq message-checksum (message-checksum))))))
2365 (defun message-yank-buffer (buffer)
2366 "Insert BUFFER into the current buffer and quote it."
2367 (interactive "bYank buffer: ")
2368 (let ((message-reply-buffer buffer))
2369 (save-window-excursion
2370 (message-yank-original))))
2372 (defun message-buffers ()
2373 "Return a list of active message buffers."
2376 (dolist (buffer (buffer-list t))
2378 (when (and (eq major-mode 'message-mode)
2379 (null message-sent-message-via))
2380 (push (buffer-name buffer) buffers))))
2381 (nreverse buffers)))
2383 (defun message-cite-original-without-signature ()
2384 "Cite function in the standard Message manner."
2385 (let ((start (point))
2388 (when message-indent-citation-function
2389 (if (listp message-indent-citation-function)
2390 message-indent-citation-function
2391 (list message-indent-citation-function)))))
2395 (when (re-search-backward message-signature-separator start t)
2396 ;; Also peel off any blank lines before the signature.
2398 (while (looking-at "^[ \t]*$")
2401 (delete-region (point) end))
2404 (funcall (pop functions)))
2405 (when message-citation-line-function
2408 (funcall message-citation-line-function))))
2410 (defvar mail-citation-hook) ;Compiler directive
2411 (defun message-cite-original ()
2412 "Cite function in the standard Message manner."
2413 (if (and (boundp 'mail-citation-hook)
2415 (run-hooks 'mail-citation-hook)
2416 (let ((start (point))
2419 (when message-indent-citation-function
2420 (if (listp message-indent-citation-function)
2421 message-indent-citation-function
2422 (list message-indent-citation-function))))
2423 (message-reply-headers (or message-reply-headers
2424 (make-mail-header))))
2425 (mail-header-set-from message-reply-headers
2429 (if (search-forward "\n\n" nil t)
2432 (or (message-fetch-field "from")
2436 (funcall (pop functions)))
2437 (when message-citation-line-function
2440 (funcall message-citation-line-function)))))
2442 (defun message-insert-citation-line ()
2443 "Function that inserts a simple citation line."
2444 (when message-reply-headers
2445 (insert (mail-header-from message-reply-headers) " writes:\n\n")))
2447 (defun message-position-on-field (header &rest afters)
2448 (let ((case-fold-search t))
2451 (goto-char (point-min))
2454 (concat "^" (regexp-quote mail-header-separator) "$"))
2455 (match-beginning 0)))
2456 (goto-char (point-min))
2457 (if (re-search-forward (concat "^" (regexp-quote header) ":") nil t)
2459 (re-search-forward "^[^ \t]" nil 'move)
2461 (skip-chars-backward "\n")
2464 (not (re-search-forward
2465 (concat "^" (regexp-quote (car afters)) ":")
2469 (re-search-forward "^[^ \t]" nil 'move)
2470 (beginning-of-line))
2471 (insert header ": \n")
2475 (defun message-remove-signature ()
2476 "Remove the signature from the text between point and mark.
2477 The text will also be indented the normal way."
2479 (let ((start (point))
2481 (if (not (re-search-forward message-signature-separator (mark t) t))
2482 ;; No signature here, so we just indent the cited text.
2483 (message-indent-citation)
2484 ;; Find the last non-empty line.
2486 (while (looking-at "[ \t]*$")
2489 (setq mark (set-marker (make-marker) (point)))
2491 (message-indent-citation)
2492 ;; Enable undoing the deletion.
2494 (delete-region mark (mark t))
2495 (set-marker mark nil)))))
2500 ;;; Sending messages
2503 ;; Avoid byte-compile warning.
2504 (defvar message-encoding-buffer nil)
2505 (defvar message-edit-buffer nil)
2506 (defvar message-mime-mode nil)
2508 (defun message-send-and-exit (&optional arg)
2509 "Send message like `message-send', then, if no errors, exit from mail buffer."
2511 (let ((buf (current-buffer))
2512 (actions message-exit-actions)
2513 (frame (selected-frame))
2514 (org-frame message-original-frame))
2515 (when (and (message-send arg)
2517 (if message-kill-buffer-on-exit
2520 (when (eq buf (current-buffer))
2521 (message-bury buf)))
2522 (message-do-actions actions)
2523 (message-delete-frame frame org-frame)
2526 (defun message-dont-send ()
2527 "Don't send the message you have been editing."
2529 (message-save-drafts)
2530 (let ((actions message-postpone-actions)
2531 (frame (selected-frame))
2532 (org-frame message-original-frame))
2533 (message-bury (current-buffer))
2534 (message-do-actions actions)
2535 (message-delete-frame frame org-frame)))
2537 (defun message-kill-buffer ()
2538 "Kill the current buffer."
2540 (when (or (not (buffer-modified-p))
2541 (eq t message-kill-buffer-query-function)
2542 (funcall message-kill-buffer-query-function
2543 "The buffer modified; kill anyway? "))
2544 (let ((actions message-kill-actions)
2545 (frame (selected-frame))
2546 (org-frame message-original-frame))
2547 (setq buffer-file-name nil)
2548 (kill-buffer (current-buffer))
2549 (message-do-actions actions)
2550 (message-delete-frame frame org-frame)))
2553 (defun message-mimic-kill-buffer ()
2554 "Kill the current buffer with query."
2556 (unless (eq 'message-mode major-mode)
2557 (error "%s must be invoked from a message buffer." this-command))
2558 (let ((command this-command)
2559 (bufname (read-buffer (format "Kill buffer: (default %s) "
2561 (if (or (not bufname)
2562 (string-equal bufname "")
2563 (string-equal bufname (buffer-name)))
2564 (message-kill-buffer)
2565 (message "%s must be invoked only for the current buffer." command))))
2567 (defun message-delete-frame (frame org-frame)
2568 "Delete frame for editing message."
2569 (when (and (or (static-if (featurep 'xemacs)
2570 (device-on-window-system-p)
2572 (>= emacs-major-version 20))
2573 (or (and (eq message-delete-frame-on-exit t)
2574 (select-frame frame)
2575 (or (eq frame org-frame)
2577 (y-or-n-p "Delete this frame?")
2579 (and (eq message-delete-frame-on-exit 'ask)
2580 (select-frame frame)
2582 (y-or-n-p "Delete this frame?")
2584 (delete-frame frame)))
2586 (defun message-bury (buffer)
2587 "Bury this mail buffer."
2588 (let ((newbuf (other-buffer buffer)))
2589 (bury-buffer buffer)
2590 (if (and (fboundp 'frame-parameters)
2591 (cdr (assq 'dedicated (frame-parameters)))
2592 (not (null (delq (selected-frame) (visible-frame-list)))))
2593 (delete-frame (selected-frame))
2594 (switch-to-buffer newbuf))))
2596 (defun message-send (&optional arg)
2597 "Send the message in the current buffer.
2598 If `message-interactive' is non-nil, wait for success indication or
2599 error messages, and inform user.
2600 Otherwise any failure is reported in a message back to the user from
2602 The usage of ARG is defined by the instance that called Message.
2603 It should typically alter the sending method in some way or other."
2606 (when (or (buffer-modified-p)
2607 (message-check-element 'unchanged)
2608 (y-or-n-p "No changes in the buffer; really send? "))
2609 ;; Make it possible to undo the coming changes.
2611 (let ((inhibit-read-only t))
2612 (put-text-property (point-min) (point-max) 'read-only nil))
2613 (run-hooks 'message-send-hook)
2614 (message "Sending...")
2615 (let ((message-encoding-buffer
2616 (message-generate-new-buffer-clone-locals " message encoding"))
2617 (message-edit-buffer (current-buffer))
2618 (message-mime-mode mime-edit-mode-flag)
2619 (alist message-send-method-alist)
2623 (set-buffer message-encoding-buffer)
2625 (insert-buffer message-edit-buffer)
2626 (funcall message-encode-function)
2627 (message-fix-before-sending)
2629 (setq elem (pop alist)))
2630 (when (or (not (funcall (cadr elem)))
2631 (and (or (not (memq (car elem)
2632 message-sent-message-via))
2635 "Already sent message via %s; resend? "
2637 (setq success (funcall (caddr elem) arg))))
2639 (unless (or sent (not success))
2640 (error "No methods specified to send by"))
2642 (when (and success sent)
2645 (run-hooks 'message-sent-hook))
2646 (message "Sending...done")
2647 ;; Mark the buffer as unmodified and delete autosave.
2648 (set-buffer-modified-p nil)
2649 (delete-auto-save-file-if-necessary t)
2650 (message-disassociate-draft)
2651 ;; Delete other mail buffers and stuff.
2652 (message-do-send-housekeeping)
2653 (message-do-actions message-send-actions)
2656 (kill-buffer message-encoding-buffer)))))
2658 (defun message-send-via-mail (arg)
2659 "Send the current message via mail."
2660 (message-send-mail arg))
2662 (defun message-send-via-news (arg)
2663 "Send the current message via news."
2664 (message-send-news arg))
2666 (defmacro message-check (type &rest forms)
2667 "Eval FORMS if TYPE is to be checked."
2668 `(or (message-check-element ,type)
2672 (put 'message-check 'lisp-indent-function 1)
2673 (put 'message-check 'edebug-form-spec '(form body))
2675 (defun message-fix-before-sending ()
2676 "Do various things to make the message nice before sending it."
2677 ;; Make sure there's a newline at the end of the message.
2678 (goto-char (point-max))
2681 ;; Delete all invisible text.
2682 (message-check 'invisible-text
2683 (when (text-property-any (point-min) (point-max) 'invisible t)
2684 (put-text-property (point-min) (point-max) 'invisible nil)
2685 (unless (yes-or-no-p
2686 "Invisible text found and made visible; continue posting? ")
2687 (error "Invisible text found and made visible")))))
2689 (defun message-add-action (action &rest types)
2690 "Add ACTION to be performed when doing an exit of type TYPES."
2693 (set (setq var (intern (format "message-%s-actions" (pop types))))
2694 (nconc (symbol-value var) (list action))))))
2696 (defun message-do-actions (actions)
2697 "Perform all actions in ACTIONS."
2698 ;; Now perform actions on successful sending.
2702 ;; A simple function.
2703 ((message-functionp (car actions))
2704 (funcall (car actions)))
2705 ;; Something to be evaled.
2707 (eval (car actions)))))
2710 (defsubst message-maybe-split-and-send-mail ()
2711 "Split a message if necessary, and send it via mail.
2712 Returns nil if sending succeeded, returns any string if sending failed.
2713 This sub function is for exclusive use of `message-send-mail'."
2714 (let ((mime-edit-split-ignored-field-regexp
2715 mime-edit-split-ignored-field-regexp)
2716 (case-fold-search t)
2718 (while (string-match "Message-ID" mime-edit-split-ignored-field-regexp)
2719 (setq mime-edit-split-ignored-field-regexp
2720 (concat (substring mime-edit-split-ignored-field-regexp
2721 0 (match-beginning 0))
2722 "Hey_MIME-Edit,_there_is_an_inviolable_Message_ID"
2723 "_so_don't_rape_it!"
2724 (substring mime-edit-split-ignored-field-regexp
2728 (catch 'message-sending-mail-failure
2729 (mime-edit-maybe-split-and-send
2734 (std11-narrow-to-header mail-header-separator)
2735 (goto-char (point-min))
2736 (when (re-search-forward "^Message-ID:" nil t)
2737 (delete-region (match-end 0) (std11-field-end))
2738 (insert " " (message-make-message-id))))
2740 (funcall message-send-mail-function)
2742 (throw 'message-sending-mail-failure err))))))
2746 (funcall message-send-mail-function)
2750 (if (eq 'error (car failure))
2752 (prin1-to-string failure)))))
2754 (defun message-send-mail (&optional arg)
2755 (require 'mail-utils)
2756 (let* ((tembuf (message-generate-new-buffer-clone-locals " message temp"))
2757 (case-fold-search nil)
2758 (news (message-news-p))
2759 (message-this-is-mail t)
2762 (message-narrow-to-headers)
2763 ;; Insert some headers.
2764 (let ((message-deletable-headers
2765 (if news nil message-deletable-headers)))
2766 (message-generate-headers message-required-mail-headers))
2767 ;; Let the user do all of the above.
2768 (run-hooks 'message-header-hook))
2769 (if (not (message-check-mail-syntax))
2777 (insert-buffer message-encoding-buffer)
2778 ;; Remove some headers.
2780 (message-narrow-to-headers)
2781 ;; We Semi-gnus people have no use for it.
2782 ;; ;; We (re)generate the Lines header.
2783 ;; (when (memq 'Lines message-required-mail-headers)
2784 ;; (message-generate-headers '(Lines)))
2785 ;; Remove some headers.
2786 (message-remove-header message-ignored-mail-headers t))
2787 (goto-char (point-max))
2788 ;; require one newline at the end.
2789 (or (= (preceding-char) ?\n)
2792 (or (message-fetch-field "cc")
2793 (message-fetch-field "to")))
2794 (message-insert-courtesy-copy))
2795 (setq failure (message-maybe-split-and-send-mail)))
2796 (kill-buffer tembuf))
2797 (set-buffer message-edit-buffer)
2800 (message "Couldn't send message via mail: %s" failure)
2802 (push 'mail message-sent-message-via)))))
2804 (defun message-send-mail-with-sendmail ()
2805 "Send off the prepared buffer with sendmail."
2806 (let ((errbuf (if message-interactive
2807 (message-generate-new-buffer-clone-locals
2810 resend-to-addresses delimline)
2811 (let ((case-fold-search t))
2813 (message-narrow-to-headers)
2814 (setq resend-to-addresses (message-fetch-field "resent-to")))
2815 ;; Change header-delimiter to be what sendmail expects.
2816 (goto-char (point-min))
2818 (concat "^" (regexp-quote mail-header-separator) "\n"))
2819 (replace-match "\n")
2821 (setq delimline (point-marker))
2822 (run-hooks 'message-send-mail-hook)
2823 ;; Insert an extra newline if we need it to work around
2824 ;; Sun's bug that swallows newlines.
2825 (goto-char (1+ delimline))
2826 (when (eval message-mailer-swallows-blank-line)
2828 (when message-interactive
2832 (let ((default-directory "/"))
2834 (apply 'call-process-region
2835 (append (list (point-min) (point-max)
2836 (if (boundp 'sendmail-program)
2838 "/usr/lib/sendmail")
2839 nil errbuf nil "-oi")
2840 ;; Always specify who from,
2841 ;; since some systems have broken sendmails.
2842 ;; But some systems are more broken with -f, so
2843 ;; we'll let users override this.
2844 (if (null message-sendmail-f-is-evil)
2845 (list "-f" (message-make-address)))
2846 ;; These mean "report errors by mail"
2847 ;; and "deliver in background".
2848 (if (null message-interactive) '("-oem" "-odb"))
2849 ;; Get the addresses from the message
2850 ;; unless this is a resend.
2851 ;; We must not do that for a resend
2852 ;; because we would find the original addresses.
2853 ;; For a resend, include the specific addresses.
2854 (if resend-to-addresses
2855 (list resend-to-addresses)
2857 (when message-interactive
2860 (goto-char (point-min))
2861 (while (re-search-forward "\n\n* *" nil t)
2862 (replace-match "; "))
2863 (if (not (zerop (buffer-size)))
2864 (error "Sending...failed to %s"
2865 (buffer-substring (point-min) (point-max)))))
2866 (when (bufferp errbuf)
2867 (kill-buffer errbuf)))))
2869 (defun message-send-mail-with-qmail ()
2870 "Pass the prepared message buffer to qmail-inject.
2871 Refer to the documentation for the variable `message-send-mail-function'
2872 to find out how to use this."
2873 ;; replace the header delimiter with a blank line
2874 (goto-char (point-min))
2876 (concat "^" (regexp-quote mail-header-separator) "\n"))
2877 (replace-match "\n")
2879 (run-hooks 'message-send-mail-hook)
2884 'call-process-region 1 (point-max) message-qmail-inject-program
2886 ;; qmail-inject's default behaviour is to look for addresses on the
2887 ;; command line; if there're none, it scans the headers.
2888 ;; yes, it does The Right Thing w.r.t. Resent-To and it's kin.
2890 ;; in general, ALL of qmail-inject's defaults are perfect for simply
2891 ;; reading a formatted (i. e., at least a To: or Resent-To header)
2892 ;; message from stdin.
2894 ;; qmail also has the advantage of not having been raped by
2895 ;; various vendors, so we don't have to allow for that, either --
2896 ;; compare this with message-send-mail-with-sendmail and weep
2897 ;; for sendmail's lost innocence.
2899 ;; all this is way cool coz it lets us keep the arguments entirely
2900 ;; free for -inject-arguments -- a big win for the user and for us
2901 ;; since we don't have to play that double-guessing game and the user
2902 ;; gets full control (no gestapo'ish -f's, for instance). --sj
2903 message-qmail-inject-args))
2904 ;; qmail-inject doesn't say anything on it's stdout/stderr,
2905 ;; we have to look at the retval instead
2907 (1 (error "qmail-inject reported permanent failure"))
2908 (111 (error "qmail-inject reported transient failure"))
2909 ;; should never happen
2910 (t (error "qmail-inject reported unknown failure"))))
2912 (defun message-send-mail-with-mh ()
2913 "Send the prepared message buffer with mh."
2914 (let ((mh-previous-window-config nil)
2915 (name (mh-new-draft-name)))
2916 (setq buffer-file-name name)
2917 ;; MH wants to generate these headers itself.
2918 (when message-mh-deletable-headers
2919 (let ((headers message-mh-deletable-headers))
2921 (goto-char (point-min))
2922 (and (re-search-forward
2923 (concat "^" (symbol-name (car headers)) ": *") nil t)
2924 (message-delete-line))
2926 (run-hooks 'message-send-mail-hook)
2927 ;; Pass it on to mh.
2930 (defun message-send-mail-with-smtp ()
2931 "Send off the prepared buffer with SMTP."
2932 (require 'smtp) ; XXX
2933 (let ((case-fold-search t)
2936 (message-narrow-to-headers)
2938 ;; XXX: Should be replaced by better one.
2939 (smtp-deduce-address-list (current-buffer)
2940 (point-min) (point-max)))
2941 ;; Remove BCC lines.
2942 (message-remove-header "bcc"))
2943 ;; replace the header delimiter with a blank line.
2944 (goto-char (point-min))
2946 (concat "^" (regexp-quote mail-header-separator) "\n"))
2947 (replace-match "\n")
2949 (run-hooks 'message-send-mail-hook)
2951 (let ((result (smtp-via-smtp user-mail-address
2954 (unless (eq result t)
2955 (error "Sending failed; " result)))
2956 (error "Sending failed; no recipients"))))
2958 (defsubst message-maybe-split-and-send-news (method)
2959 "Split a message if necessary, and send it via news.
2960 Returns nil if sending succeeded, returns t if sending failed.
2961 This sub function is for exclusive use of `message-send-news'."
2962 (let ((mime-edit-split-ignored-field-regexp
2963 mime-edit-split-ignored-field-regexp)
2964 (case-fold-search t))
2965 (while (string-match "Message-ID" mime-edit-split-ignored-field-regexp)
2966 (setq mime-edit-split-ignored-field-regexp
2967 (concat (substring mime-edit-split-ignored-field-regexp
2968 0 (match-beginning 0))
2969 "Hey_MIME-Edit,_there_is_an_inviolable_Message_ID"
2970 "_so_don't_rape_it!"
2971 (substring mime-edit-split-ignored-field-regexp
2974 (catch 'message-sending-news-failure
2975 (mime-edit-maybe-split-and-send
2980 (std11-narrow-to-header mail-header-separator)
2981 (goto-char (point-min))
2982 (when (re-search-forward "^Message-ID:" nil t)
2983 (delete-region (match-end 0) (std11-field-end))
2984 (insert " " (message-make-message-id))))
2985 (unless (funcall message-send-news-function method)
2986 (throw 'message-sending-news-failure t)))))
2988 (not (funcall message-send-news-function method)))))
2990 (defun message-send-news (&optional arg)
2991 (let* ((tembuf (message-generate-new-buffer-clone-locals " *message temp*"))
2992 (case-fold-search nil)
2993 (method (if (message-functionp message-post-method)
2994 (funcall message-post-method arg)
2995 message-post-method))
2996 (message-syntax-checks
2998 (cons '(existing-newsgroups . disabled)
2999 message-syntax-checks)
3000 message-syntax-checks))
3001 (message-this-is-news t)
3004 (message-narrow-to-headers)
3005 ;; Insert some headers.
3006 (message-generate-headers message-required-news-headers)
3007 ;; Let the user do all of the above.
3008 (run-hooks 'message-header-hook))
3009 (message-cleanup-headers)
3010 (if (not (message-check-news-syntax))
3015 (buffer-disable-undo)
3017 (insert-buffer message-encoding-buffer)
3018 ;; Remove some headers.
3020 (message-narrow-to-headers)
3021 ;; We Semi-gnus people have no use for it.
3022 ;; ;; We (re)generate the Lines header.
3023 ;; (when (memq 'Lines message-required-mail-headers)
3024 ;; (message-generate-headers '(Lines)))
3025 ;; Remove some headers.
3026 (message-remove-header message-ignored-news-headers t))
3027 (goto-char (point-max))
3028 ;; require one newline at the end.
3029 (or (= (preceding-char) ?\n)
3031 (setq result (message-maybe-split-and-send-news method)))
3032 (kill-buffer tembuf))
3033 (set-buffer message-edit-buffer)
3036 (message "Couldn't send message via news: %s"
3037 (nnheader-get-report (car method)))
3039 (push 'news message-sent-message-via)))))
3041 ;; 1997-09-29 by MORIOKA Tomohiko
3042 (defun message-send-news-with-gnus (method)
3043 (let ((case-fold-search t))
3044 ;; Remove the delimiter.
3045 (goto-char (point-min))
3047 (concat "^" (regexp-quote mail-header-separator) "\n"))
3048 (replace-match "\n")
3050 (run-hooks 'message-send-news-hook)
3051 (gnus-open-server method)
3052 (gnus-request-post method)
3056 ;;; Header generation & syntax checking.
3059 (defun message-check-element (type)
3060 "Returns non-nil if this type is not to be checked."
3061 (if (eq message-syntax-checks 'dont-check-for-anything-just-trust-me)
3063 (let ((able (assq type message-syntax-checks)))
3065 (eq (cdr able) 'disabled)))))
3067 (defun message-check-news-syntax ()
3068 "Check the syntax of the message."
3073 ;; We narrow to the headers and check them first.
3076 (message-narrow-to-headers)
3077 (message-check-news-header-syntax)))
3080 (set-buffer message-edit-buffer)
3081 (message-check-news-body-syntax))))))
3083 (defun message-check-news-header-syntax ()
3085 ;; Check Newsgroups header.
3086 (message-check 'newsgroups
3087 (let ((group (message-fetch-field "newsgroups")))
3090 (not (string-match "\\`[ \t]*\\'" group)))
3093 "The newsgroups field is empty or missing. Posting is denied.")))))
3094 ;; Check the Subject header.
3095 (message-check 'subject
3096 (let* ((case-fold-search t)
3097 (subject (message-fetch-field "subject")))
3100 (not (string-match "\\`[ \t]*\\'" subject)))
3103 "The subject field is empty or missing. Posting is denied.")))))
3104 ;; Check for commands in Subject.
3105 (message-check 'subject-cmsg
3106 (if (string-match "^cmsg " (message-fetch-field "subject"))
3108 "The control code \"cmsg\" is in the subject. Really post? ")
3110 ;; Check for multiple identical headers.
3111 (message-check 'multiple-headers
3113 (while (and (not found)
3114 (re-search-forward "^[^ \t:]+: " nil t))
3116 (or (re-search-forward
3121 (match-beginning 0) (- (match-end 0) 2))))
3126 (y-or-n-p (format "Multiple %s headers. Really post? " found))
3128 ;; Check for Version and Sendsys.
3129 (message-check 'sendsys
3130 (if (re-search-forward "^Sendsys:\\|^Version:" nil t)
3132 (format "The article contains a %s command. Really post? "
3133 (buffer-substring (match-beginning 0)
3134 (1- (match-end 0)))))
3136 ;; See whether we can shorten Followup-To.
3137 (message-check 'shorten-followup-to
3138 (let ((newsgroups (message-fetch-field "newsgroups"))
3139 (followup-to (message-fetch-field "followup-to"))
3141 (when (and newsgroups
3142 (string-match "," newsgroups)
3147 (setq to (completing-read
3148 "Followups to: (default all groups) "
3149 (mapcar (lambda (g) (list g))
3151 (message-tokenize-header
3153 (goto-char (point-min))
3154 (insert "Followup-To: " to "\n"))
3156 ;; Check "Shoot me".
3157 (message-check 'shoot
3158 (if (re-search-forward
3159 "Message-ID.*.i-did-not-set--mail-host-address--so-shoot-me" nil t)
3160 (y-or-n-p "You appear to have a misconfigured system. Really post? ")
3162 ;; Check for Approved.
3163 (message-check 'approved
3164 (if (re-search-forward "^Approved:" nil t)
3165 (y-or-n-p "The article contains an Approved header. Really post? ")
3167 ;; Check the Message-ID header.
3168 (message-check 'message-id
3169 (let* ((case-fold-search t)
3170 (message-id (message-fetch-field "message-id" t)))
3171 (or (not message-id)
3172 ;; Is there an @ in the ID?
3173 (and (string-match "@" message-id)
3174 ;; Is there a dot in the ID?
3175 (string-match "@[^.]*\\." message-id)
3176 ;; Does the ID end with a dot?
3177 (not (string-match "\\.>" message-id)))
3179 (format "The Message-ID looks strange: \"%s\". Really post? "
3181 ;; Check the Newsgroups & Followup-To headers.
3182 (message-check 'existing-newsgroups
3183 (let* ((case-fold-search t)
3184 (newsgroups (message-fetch-field "newsgroups"))
3185 (followup-to (message-fetch-field "followup-to"))
3186 (groups (message-tokenize-header
3188 (concat newsgroups "," followup-to)
3190 (hashtb (and (boundp 'gnus-active-hashtb)
3191 gnus-active-hashtb))
3193 (if (or (not hashtb)
3194 (not (boundp 'gnus-read-active-file))
3195 (not gnus-read-active-file)
3196 (eq gnus-read-active-file 'some))
3199 (when (and (not (boundp (intern (car groups) hashtb)))
3200 (not (equal (car groups) "poster")))
3201 (push (car groups) errors))
3207 "Really post to %s unknown group%s: %s "
3208 (if (= (length errors) 1) "this" "these")
3209 (if (= (length errors) 1) "" "s")
3210 (mapconcat 'identity errors ", ")))))))
3211 ;; Check the Newsgroups & Followup-To headers for syntax errors.
3212 (message-check 'valid-newsgroups
3213 (let ((case-fold-search t)
3214 (headers '("Newsgroups" "Followup-To"))
3216 (while (and headers (not error))
3217 (when (setq header (mail-fetch-field (car headers)))
3221 "\\`\\([-+_&.a-zA-Z0-9]+\\)?\\(,[-+_&.a-zA-Z0-9]+\\)*\\'"
3226 (not (string-match "\\.\\'\\|\\.\\." g)))
3227 (message-tokenize-header header ","))))
3234 (format "The %s header looks odd: \"%s\". Really post? "
3235 (car headers) header)))))
3236 (message-check 'repeated-newsgroups
3237 (let ((case-fold-search t)
3238 (headers '("Newsgroups" "Followup-To"))
3239 header error groups group)
3242 (when (setq header (mail-fetch-field (pop headers)))
3243 (setq groups (message-tokenize-header header ","))
3244 (while (setq group (pop groups))
3245 (when (member group groups)
3251 (format "Group %s is repeated in headers. Really post? " error)))))
3252 ;; Check the From header.
3253 (message-check 'from
3254 (let* ((case-fold-search t)
3255 (from (message-fetch-field "from"))
3259 (message "There is no From line. Posting is denied.")
3261 ((or (not (string-match
3263 (setq ad (nth 1 (mail-extract-address-components
3264 from))))) ;larsi@ifi
3265 (string-match "\\.\\." ad) ;larsi@ifi..uio
3266 (string-match "@\\." ad) ;larsi@.ifi.uio
3267 (string-match "\\.$" ad) ;larsi@ifi.uio.
3268 (not (string-match "^[^@]+@[^@]+$" ad)) ;larsi.ifi.uio
3269 (string-match "(.*).*(.*)" from)) ;(lars) (lars)
3271 "Denied posting -- the From looks strange: \"%s\"." from)
3275 (defun message-check-news-body-syntax ()
3277 ;; Check for long lines.
3278 (message-check 'long-lines
3279 (goto-char (point-min))
3281 (concat "^" (regexp-quote mail-header-separator) "$"))
3285 (< (current-column) 80))
3286 (zerop (forward-line 1))))
3290 "You have lines longer than 79 characters. Really post? ")))
3291 ;; Check whether the article is empty.
3292 (message-check 'empty
3293 (goto-char (point-min))
3295 (concat "^" (regexp-quote mail-header-separator) "$"))
3298 (goto-char (point-max))
3299 (re-search-backward message-signature-separator nil t)
3301 (or (re-search-backward "[^ \n\t]" b t)
3302 (y-or-n-p "Empty article. Really post? "))))
3303 ;; Check for control characters.
3304 (message-check 'control-chars
3305 (if (re-search-forward "[\000-\007\013\015-\032\034-\037\200-\237]" nil t)
3307 "The article contains control characters. Really post? ")
3309 ;; Check 8bit characters.
3310 (message-check '8bit
3311 (message-check-8bit))
3312 ;; Check excessive size.
3313 (message-check 'size
3314 (if (> (buffer-size) 60000)
3316 (format "The article is %d octets long. Really post? "
3319 ;; Check whether any new text has been added.
3320 (message-check 'new-text
3322 (not message-checksum)
3323 (not (eq (message-checksum) message-checksum))
3325 "It looks like no new text has been added. Really post? ")))
3326 ;; Check the length of the signature.
3327 (message-check 'signature
3328 (goto-char (point-max))
3329 (if (> (count-lines (point) (point-max)) 5)
3332 "Your .sig is %d lines; it should be max 4. Really post? "
3333 (1- (count-lines (point) (point-max)))))
3336 (defun message-check-mail-syntax ()
3337 "Check the syntax of the message."
3342 ;; We narrow to the headers and check them first.
3345 (message-narrow-to-headers)
3346 (message-check-mail-header-syntax)))
3349 (set-buffer message-edit-buffer)
3350 (message-check-mail-body-syntax))))))
3352 (defun message-check-mail-header-syntax ()
3355 (defun message-check-mail-body-syntax ()
3357 ;; Check 8bit characters.
3358 (message-check '8bit
3359 (message-check-8bit)
3362 (defun message-check-8bit ()
3363 "Check the article contains 8bit characters."
3365 (set-buffer message-encoding-buffer)
3366 (message-narrow-to-headers)
3367 (let* ((case-fold-search t)
3368 (field-value (message-fetch-field "content-transfer-encoding")))
3369 (if (and field-value
3370 (member (downcase field-value) message-8bit-encoding-list))
3373 (set-buffer (get-buffer-create " message syntax"))
3375 (goto-char (point-min))
3376 (set-buffer-multibyte nil)
3377 (insert-buffer message-encoding-buffer)
3378 (goto-char (point-min))
3379 (if (re-search-forward "[^\x00-\x7f]" nil t)
3381 "The article contains 8bit characters. Really post? ")
3384 (defun message-checksum ()
3385 "Return a \"checksum\" for the current buffer."
3388 (goto-char (point-min))
3390 (concat "^" (regexp-quote mail-header-separator) "$"))
3392 (when (not (looking-at "[ \t\n]"))
3393 (setq sum (logxor (ash sum 1) (if (natnump sum) 0 1)
3398 (defun message-do-fcc ()
3399 "Process Fcc headers in the current buffer."
3400 (let ((case-fold-search t)
3401 (coding-system-for-write 'raw-text)
3402 (output-coding-system 'raw-text)
3405 (set-buffer (get-buffer-create " *message temp*"))
3407 (insert-buffer-substring message-encoding-buffer)
3409 (message-narrow-to-headers)
3410 (while (setq file (message-fetch-field "fcc"))
3412 (message-remove-header "fcc" nil t)))
3413 (goto-char (point-min))
3414 (re-search-forward (concat "^" (regexp-quote mail-header-separator) "$"))
3415 (replace-match "" t t)
3416 ;; Process FCC operations.
3418 (setq file (pop list))
3419 (if (string-match "^[ \t]*|[ \t]*\\(.*\\)[ \t]*$" file)
3420 ;; Pipe the article to the program in question.
3421 (call-process-region (point-min) (point-max) shell-file-name
3422 nil nil nil shell-command-switch
3423 (match-string 1 file))
3424 ;; Save the article.
3425 (setq file (expand-file-name file))
3426 (unless (file-exists-p (file-name-directory file))
3427 (make-directory (file-name-directory file) t))
3428 (if (and message-fcc-handler-function
3429 (not (eq message-fcc-handler-function 'rmail-output)))
3430 (funcall message-fcc-handler-function file)
3431 (if (and (file-readable-p file) (mail-file-babyl-p file))
3432 (rmail-output file 1 nil t)
3433 (let ((mail-use-rfc822 t))
3434 (rmail-output file 1 t t))))))
3435 (kill-buffer (current-buffer)))))
3437 (defun message-output (filename)
3438 "Append this article to Unix/babyl mail file.."
3439 (if (and (file-readable-p filename)
3440 (mail-file-babyl-p filename))
3441 (rmail-output-to-rmail-file filename t)
3442 (gnus-output-to-mail filename t)))
3444 (defun message-cleanup-headers ()
3445 "Do various automatic cleanups of the headers."
3446 ;; Remove empty lines in the header.
3448 (message-narrow-to-headers)
3449 ;; Remove blank lines.
3450 (while (re-search-forward "^[ \t]*\n" nil t)
3451 (replace-match "" t t))
3453 ;; Correct Newsgroups and Followup-To headers: Change sequence of
3454 ;; spaces to comma and eliminate spaces around commas. Eliminate
3455 ;; embedded line breaks.
3456 (goto-char (point-min))
3457 (while (re-search-forward "^\\(Newsgroups\\|Followup-To\\): +" nil t)
3461 (if (re-search-forward "^[^ \t]" nil t)
3465 (goto-char (point-min))
3466 (while (re-search-forward "\n[ \t]+" nil t)
3467 (replace-match " " t t)) ;No line breaks (too confusing)
3468 (goto-char (point-min))
3469 (while (re-search-forward "[ \t\n]*,[ \t\n]*\\|[ \t]+" nil t)
3470 (replace-match "," t t))
3471 (goto-char (point-min))
3472 ;; Remove trailing commas.
3473 (when (re-search-forward ",+$" nil t)
3474 (replace-match "" t t))))))
3476 (defun message-make-date (&optional now)
3477 "Make a valid data header.
3478 If NOW, use that time instead."
3479 (let* ((now (or now (current-time)))
3480 (zone (nth 8 (decode-time now)))
3484 (setq zone (- zone)))
3486 (format-time-string "%d" now)
3487 ;; The month name of the %b spec is locale-specific. Pfff.
3489 (capitalize (car (rassoc (nth 4 (decode-time now))
3490 parse-time-months))))
3491 (format-time-string "%Y %H:%M:%S " now)
3492 ;; We do all of this because XEmacs doesn't have the %z spec.
3493 (format "%s%02d%02d" sign (/ zone 3600) (/ (% zone 3600) 60)))))
3495 (defun message-make-followup-subject (subject)
3496 "Make a followup Subject."
3498 ((and (eq message-use-subject-re 'guess)
3499 (string-match message-subject-encoded-re-regexp subject))
3501 (message-use-subject-re
3502 (concat "Re: " (message-strip-subject-re subject)))
3505 (defun message-make-message-id ()
3506 "Make a unique Message-ID."
3507 (concat "<" (message-unique-id)
3508 (let ((psubject (save-excursion (message-fetch-field "subject")))
3510 (save-excursion (message-fetch-field "supersedes"))))
3512 (and message-reply-headers
3513 (mail-header-references message-reply-headers)
3514 (mail-header-subject message-reply-headers)
3516 (mail-header-subject message-reply-headers)
3518 (message-strip-subject-re
3519 (mail-header-subject message-reply-headers))
3520 (message-strip-subject-re psubject))))
3522 (string-match "_-_@" psupersedes)))
3524 "@" (message-make-fqdn) ">"))
3526 (defvar message-unique-id-char nil)
3528 ;; If you ever change this function, make sure the new version
3529 ;; cannot generate IDs that the old version could.
3530 ;; You might for example insert a "." somewhere (not next to another dot
3531 ;; or string boundary), or modify the "fsf" string.
3532 (defun message-unique-id ()
3533 ;; Don't use microseconds from (current-time), they may be unsupported.
3534 ;; Instead we use this randomly inited counter.
3535 (setq message-unique-id-char
3536 (% (1+ (or message-unique-id-char (logand (random t) (1- (lsh 1 20)))))
3537 ;; (current-time) returns 16-bit ints,
3538 ;; and 2^16*25 just fits into 4 digits i base 36.
3540 (let ((tm (current-time)))
3542 (if (memq system-type '(ms-dos emx vax-vms))
3543 (let ((user (downcase (user-login-name))))
3544 (while (string-match "[^a-z0-9_]" user)
3545 (aset user (match-beginning 0) ?_))
3547 (message-number-base36 (user-uid) -1))
3548 (message-number-base36 (+ (car tm)
3549 (lsh (% message-unique-id-char 25) 16)) 4)
3550 (message-number-base36 (+ (nth 1 tm)
3551 (lsh (/ message-unique-id-char 25) 16)) 4)
3552 ;; Append the newsreader name, because while the generated
3553 ;; ID is unique to this newsreader, other newsreaders might
3554 ;; otherwise generate the same ID via another algorithm.
3557 (defun message-number-base36 (num len)
3562 (concat (message-number-base36 (/ num 36) (1- len))
3563 (char-to-string (aref "zyxwvutsrqponmlkjihgfedcba9876543210"
3566 (defun message-make-organization ()
3567 "Make an Organization header."
3568 (let* ((organization
3569 (when message-user-organization
3570 (if (message-functionp message-user-organization)
3571 (funcall message-user-organization)
3572 message-user-organization))))
3574 (message-set-work-buffer)
3575 (cond ((stringp organization)
3576 (insert organization))
3577 ((and (eq t organization)
3578 message-user-organization-file
3579 (file-exists-p message-user-organization-file))
3580 (insert-file-contents message-user-organization-file)))
3581 (goto-char (point-min))
3582 (while (re-search-forward "[\t\n]+" nil t)
3583 (replace-match "" t t))
3584 (unless (zerop (buffer-size))
3587 (defun message-make-lines ()
3588 "Count the number of lines and return numeric string."
3592 (goto-char (point-min))
3594 (concat "^" (regexp-quote mail-header-separator) "$"))
3596 (int-to-string (count-lines (point) (point-max))))))
3598 (defun message-make-in-reply-to ()
3599 "Return the In-Reply-To header for this message."
3600 (when message-reply-headers
3601 (let ((mid (mail-header-message-id message-reply-headers))
3602 (from (mail-header-from message-reply-headers))
3603 (date (mail-header-date message-reply-headers)))
3607 (let ((pair (std11-extract-address-components from)))
3609 (or (car pair) (cadr pair))
3611 (if (or (not date) (string= date ""))
3612 "(unknown date)" date)
3615 (defun message-make-distribution ()
3616 "Make a Distribution header."
3617 (let ((orig-distribution (message-fetch-reply-field "distribution")))
3618 (cond ((message-functionp message-distribution-function)
3619 (funcall message-distribution-function))
3620 (t orig-distribution))))
3622 (defun message-make-expires ()
3623 "Return an Expires header based on `message-expires'."
3624 (let ((current (current-time))
3625 (future (* 1.0 message-expires 60 60 24)))
3626 ;; Add the future to current.
3627 (setcar current (+ (car current) (round (/ future (expt 2 16)))))
3628 (setcar (cdr current) (+ (nth 1 current) (% (round future) (expt 2 16))))
3629 (message-make-date current)))
3631 (defun message-make-path ()
3633 (let ((login-name (user-login-name)))
3634 (cond ((null message-user-path)
3635 (concat (system-name) "!" login-name))
3636 ((stringp message-user-path)
3637 ;; Support GENERICPATH. Suggested by vixie@decwrl.dec.com.
3638 (concat message-user-path "!" login-name))
3641 (defun message-make-from ()
3642 "Make a From header."
3643 (let* ((style message-from-style)
3644 (login (message-make-address))
3646 (or (and (boundp 'user-full-name)
3649 (when (string= fullname "&")
3650 (setq fullname (user-login-name)))
3652 (message-set-work-buffer)
3655 (equal fullname ""))
3657 ((or (eq style 'angles)
3658 (and (not (eq style 'parens))
3659 ;; Use angles if no quoting is needed, or if parens would
3660 ;; need quoting too.
3661 (or (not (string-match "[^- !#-'*+/-9=?A-Z^-~]" fullname))
3662 (let ((tmp (concat fullname nil)))
3663 (while (string-match "([^()]*)" tmp)
3664 (aset tmp (match-beginning 0) ?-)
3665 (aset tmp (1- (match-end 0)) ?-))
3666 (string-match "[\\()]" tmp)))))
3668 (goto-char (point-min))
3669 ;; Look for a character that cannot appear unquoted
3670 ;; according to RFC 822.
3671 (when (re-search-forward "[^- !#-'*+/-9=?A-Z^-~]" nil 1)
3672 ;; Quote fullname, escaping specials.
3673 (goto-char (point-min))
3675 (while (re-search-forward "[\"\\]" nil 1)
3676 (replace-match "\\\\\\&" t))
3678 (insert " <" login ">"))
3679 (t ; 'parens or default
3681 (let ((fullname-start (point)))
3683 (goto-char fullname-start)
3684 ;; RFC 822 says \ and nonmatching parentheses
3685 ;; must be escaped in comments.
3686 ;; Escape every instance of ()\ ...
3687 (while (re-search-forward "[()\\]" nil 1)
3688 (replace-match "\\\\\\&" t))
3689 ;; ... then undo escaping of matching parentheses,
3690 ;; including matching nested parentheses.
3691 (goto-char fullname-start)
3692 (while (re-search-forward
3693 "\\(\\=\\|[^\\]\\(\\\\\\\\\\)*\\)\\\\(\\(\\([^\\]\\|\\\\\\\\\\)*\\)\\\\)"
3695 (replace-match "\\1(\\3)" t)
3696 (goto-char fullname-start)))
3700 (defun message-make-sender ()
3701 "Return the \"real\" user address.
3702 This function tries to ignore all user modifications, and
3703 give as trustworthy answer as possible."
3704 (concat (user-login-name) "@" (system-name)))
3706 (defun message-make-address ()
3707 "Make the address of the user."
3708 (or (message-user-mail-address)
3709 (concat (user-login-name) "@" (message-make-domain))))
3711 (defun message-user-mail-address ()
3712 "Return the pertinent part of `user-mail-address'."
3713 (when user-mail-address
3714 (if (string-match " " user-mail-address)
3715 (nth 1 (std11-extract-address-components user-mail-address))
3716 user-mail-address)))
3718 (defun message-make-fqdn ()
3719 "Return user's fully qualified domain name."
3720 (let ((system-name (system-name))
3721 (user-mail (message-user-mail-address)))
3723 ((string-match "[^.]\\.[^.]" system-name)
3724 ;; `system-name' returned the right result.
3726 ;; Try `mail-host-address'.
3727 ((and (boundp 'mail-host-address)
3728 (stringp mail-host-address)
3729 (string-match "\\." mail-host-address))
3731 ;; We try `user-mail-address' as a backup.
3733 (string-match "\\." user-mail)
3734 (string-match "@\\(.*\\)\\'" user-mail))
3735 (match-string 1 user-mail))
3736 ;; Default to this bogus thing.
3738 (concat system-name ".i-did-not-set--mail-host-address--so-shoot-me")))))
3740 (defun message-make-host-name ()
3741 "Return the name of the host."
3742 (let ((fqdn (message-make-fqdn)))
3743 (string-match "^[^.]+\\." fqdn)
3744 (substring fqdn 0 (1- (match-end 0)))))
3746 (defun message-make-domain ()
3747 "Return the domain name."
3748 (or mail-host-address
3749 (message-make-fqdn)))
3751 ;; Dummy to avoid byte-compile warning.
3752 (defvar mule-version)
3753 (defvar emacs-beta-version)
3754 (defvar xemacs-codename)
3755 (defvar gnus-inviolable-extended-version)
3757 (defun message-make-user-agent ()
3758 "Return user-agent info if the value `message-user-agent' is non-nil. If the
3759 \"User-Agent\" field has already exist, it's value will be added in the return
3761 (when message-user-agent
3763 (goto-char (point-min))
3764 (let ((case-fold-search t)
3765 user-agent start p end)
3766 (if (re-search-forward "^User-Agent:[\t ]*" nil t)
3768 (setq start (match-beginning 0)
3770 end (std11-field-end)
3771 user-agent (buffer-substring-no-properties p end))
3772 (delete-region start (1+ end))
3773 (concat message-user-agent " " user-agent))
3774 message-user-agent)))))
3776 (defun message-generate-headers (headers)
3777 "Prepare article HEADERS.
3778 Headers already prepared in the buffer are not modified."
3780 (message-narrow-to-headers)
3781 (let* ((Date (message-make-date))
3782 (Message-ID (message-make-message-id))
3783 (Organization (message-make-organization))
3784 (From (message-make-from))
3785 (Path (message-make-path))
3788 (In-Reply-To (message-make-in-reply-to))
3790 (Distribution (message-make-distribution))
3791 (Lines (message-make-lines))
3792 (User-Agent (message-make-user-agent))
3793 (Expires (message-make-expires))
3794 (case-fold-search t)
3796 ;; First we remove any old generated headers.
3797 (let ((headers message-deletable-headers))
3798 (unless (buffer-modified-p)
3799 (setq headers (delq 'Message-ID (copy-sequence headers))))
3801 (goto-char (point-min))
3802 (and (re-search-forward
3803 (concat "^" (symbol-name (car headers)) ": *") nil t)
3804 (get-text-property (1+ (match-beginning 0)) 'message-deletable)
3805 (message-delete-line))
3807 ;; Go through all the required headers and see if they are in the
3808 ;; articles already. If they are not, or are empty, they are
3809 ;; inserted automatically - except for Subject, Newsgroups and
3812 (goto-char (point-min))
3813 (setq elem (pop headers))
3815 (if (eq (car elem) 'optional)
3816 (setq header (cdr elem))
3817 (setq header (car elem)))
3819 (when (or (not (re-search-forward
3823 (if (stringp header)
3825 (symbol-name header))))
3829 ;; The header was found. We insert a space after the
3830 ;; colon, if there is none.
3831 (if (/= (char-after) ? ) (insert " ") (forward-char 1))
3832 ;; Find out whether the header is empty...
3833 (looking-at "[ \t]*\n[^ \t]")))
3834 ;; So we find out what value we should insert.
3837 ((and (consp elem) (eq (car elem) 'optional))
3838 ;; This is an optional header. If the cdr of this
3839 ;; is something that is nil, then we do not insert
3841 (setq header (cdr elem))
3842 (or (and (fboundp (cdr elem)) (funcall (cdr elem)))
3843 (and (boundp (cdr elem)) (symbol-value (cdr elem)))))
3845 ;; The element is a cons. Either the cdr is a
3846 ;; string to be inserted verbatim, or it is a
3847 ;; function, and we insert the value returned from
3849 (or (and (stringp (cdr elem)) (cdr elem))
3850 (and (fboundp (cdr elem)) (funcall (cdr elem)))))
3851 ((and (boundp header) (symbol-value header))
3852 ;; The element is a symbol. We insert the value
3853 ;; of this symbol, if any.
3854 (symbol-value header))
3855 ((not (message-check-element header))
3856 ;; We couldn't generate a value for this header,
3857 ;; so we just ask the user.
3858 (read-from-minibuffer
3859 (format "Empty header for %s; enter value: " header)))))
3860 ;; Finally insert the header.
3862 (not (equal value "")))
3866 ;; This header didn't exist, so we insert it.
3867 (goto-char (point-max))
3868 (insert (if (stringp header) header (symbol-name header))
3873 ;; The value of this header was empty, so we clear
3874 ;; totally and insert the new value.
3875 (delete-region (point) (gnus-point-at-eol))
3879 ;; Add the deletable property to the headers that require it.
3880 (and (memq header message-deletable-headers)
3881 (progn (beginning-of-line) (looking-at "[^:]+: "))
3882 (add-text-properties
3883 (point) (match-end 0)
3884 '(message-deletable t face italic) (current-buffer)))))))
3885 ;; Insert new Sender if the From is strange.
3886 (let ((from (message-fetch-field "from"))
3887 (sender (message-fetch-field "sender"))
3888 (secure-sender (message-make-sender)))
3890 (not (message-check-element 'sender))
3893 (cadr (std11-extract-address-components from)))
3894 (downcase secure-sender)))
3899 (cadr (std11-extract-address-components sender)))
3900 (downcase secure-sender)))))
3901 (goto-char (point-min))
3902 ;; Rename any old Sender headers to Original-Sender.
3903 (when (re-search-forward "^\\(Original-\\)*Sender:" nil t)
3905 (insert "Original-")
3906 (beginning-of-line))
3907 (when (or (message-news-p)
3908 (string-match "@.+\\.." secure-sender))
3909 (insert "Sender: " secure-sender "\n")))))))
3911 (defun message-insert-courtesy-copy ()
3912 "Insert a courtesy message in mail copies of combined messages."
3916 (message-narrow-to-headers)
3917 (when (setq newsgroups (message-fetch-field "newsgroups"))
3918 (goto-char (point-max))
3919 (insert "Posted-To: " newsgroups "\n")))
3921 (when message-courtesy-message
3923 ((string-match "%s" message-courtesy-message)
3924 (insert (format message-courtesy-message newsgroups)))
3926 (insert message-courtesy-message)))))))
3929 ;;; Setting up a message buffer
3932 (defun message-fill-address (header value)
3934 (narrow-to-region (point) (point))
3935 (insert (capitalize (symbol-name header))
3937 (if (consp value) (car value) value)
3939 (narrow-to-region (point-min) (1- (point-max)))
3941 (goto-char (point-min))
3943 (skip-chars-forward "^,\"" (point-max))
3944 (if (or (eq (char-after) ?,)
3947 (if (and (> (current-column) 78)
3951 (looking-at "[ \t]*")
3952 (replace-match "\n " t t)))
3953 (setq last (1+ (point))))
3954 (setq quoted (not quoted)))
3957 (goto-char (point-max))
3961 (defun message-fill-references (header value)
3962 (insert (capitalize (symbol-name header))
3964 (std11-fill-msg-id-list-string
3965 (if (consp value) (car value) value))
3968 (defun message-fill-header (header value)
3969 (let ((begin (point))
3972 (insert (capitalize (symbol-name header))
3974 (if (consp value) (car value) value)
3977 (narrow-to-region begin (point))
3978 (fill-region-as-paragraph begin (point))
3979 ;; Tapdance around looong Message-IDs.
3981 (when (looking-at "[ \t]*$")
3982 (message-delete-line))
3984 (re-search-forward ":" nil t)
3985 (when (looking-at "\n[ \t]+")
3986 (replace-match " " t t))
3987 (goto-char (point-max)))))
3989 (defun message-shorten-1 (list cut surplus)
3990 ;; Cut SURPLUS elements out of LIST, beginning with CUTth one.
3991 (setcdr (nthcdr (- cut 2) list)
3992 (nthcdr (+ (- cut 2) surplus 1) list)))
3994 (defun message-shorten-references (header references)
3995 "Trim REFERENCES to be less than 31 Message-ID long, and fold them.
3996 If folding is disallowed, also check that the REFERENCES are less
3997 than 988 characters long, and if they are not, trim them until they are."
4004 (goto-char (point-min))
4005 ;; Cons a list of valid references.
4006 (while (re-search-forward "<[^>]+>" nil t)
4007 (push (match-string 0) refs))
4008 (setq refs (nreverse refs)
4009 count (length refs)))
4011 ;; If the list has more than MAXCOUNT elements, trim it by
4012 ;; removing the CUTth element and the required number of
4013 ;; elements that follow.
4014 (when (> count maxcount)
4015 (let ((surplus (- count maxcount)))
4016 (message-shorten-1 refs cut surplus)
4017 (decf count surplus)))
4019 ;; If folding is disallowed, make sure the total length (including
4020 ;; the spaces between) will be less than MAXSIZE characters.
4022 ;; Only disallow folding for News messages. At this point the headers
4023 ;; have not been generated, thus we use message-this-is-news directly.
4024 (when (and message-this-is-news message-cater-to-broken-inn)
4026 (totalsize (+ (apply #'+ (mapcar #'length refs))
4029 (ptr (nthcdr (1- cut) refs)))
4030 ;; Decide how many elements to cut off...
4031 (while (> totalsize maxsize)
4032 (decf totalsize (1+ (length (car ptr))))
4034 (setq ptr (cdr ptr)))
4037 (message-shorten-1 refs cut surplus))))
4039 ;; Finally, collect the references back into a string and insert
4040 ;; it into the buffer.
4041 (let ((refstring (mapconcat #'identity refs " ")))
4042 (if (and message-this-is-news message-cater-to-broken-inn)
4043 (insert (capitalize (symbol-name header)) ": "
4045 (message-fill-header header refstring)))))
4047 (defun message-position-point ()
4048 "Move point to where the user probably wants to find it."
4049 (message-narrow-to-headers)
4051 ((re-search-forward "^[^:]+:[ \t]*$" nil t)
4052 (search-backward ":" )
4055 (if (eq (char-after) ? )
4059 (goto-char (point-max))
4062 (unless (looking-at "$")
4066 (defun message-buffer-name (type &optional to group)
4067 "Return a new (unique) buffer name based on TYPE and TO."
4069 ;; Generate a new buffer name The Message Way.
4070 ((eq message-generate-new-buffers 'unique)
4071 (generate-new-buffer-name
4075 (or (car (std11-extract-address-components to))
4078 (if (and group (not (string= group ""))) (concat " on " group) "")
4080 ;; Check whether `message-generate-new-buffers' is a function,
4081 ;; and if so, call it.
4082 ((message-functionp message-generate-new-buffers)
4083 (funcall message-generate-new-buffers type to group))
4084 ((eq message-generate-new-buffers 'unsent)
4085 (generate-new-buffer-name
4086 (concat "*unsent " type
4089 (or (car (mail-extract-address-components to))
4092 (if (and group (not (string= group ""))) (concat " on " group) "")
4094 ;; Use standard name.
4096 (format "*%s message*" type))))
4098 (defmacro message-pop-to-buffer-1 (buffer)
4100 (let (special-display-buffer-names
4101 special-display-regexps
4102 same-window-buffer-names
4103 same-window-regexps)
4104 (pop-to-buffer ,buffer))
4105 (pop-to-buffer ,buffer)))
4107 (defun message-pop-to-buffer (name)
4108 "Pop to buffer NAME, and warn if it already exists and is modified."
4109 (let ((buffer (get-buffer name))
4110 (pop-up-frames (and (or (static-if (featurep 'xemacs)
4111 (device-on-window-system-p)
4113 (>= emacs-major-version 20))
4114 message-use-multi-frames)))
4116 (buffer-name buffer))
4118 (message-pop-to-buffer-1 buffer)
4119 (when (and (buffer-modified-p)
4121 "Message already being composed; erase? ")))
4122 (error "Message being composed")))
4123 (message-pop-to-buffer-1 name))
4127 (set (make-local-variable 'message-original-frame) (selected-frame)))))
4129 (defun message-do-send-housekeeping ()
4130 "Kill old message buffers."
4131 ;; We might have sent this buffer already. Delete it from the
4133 (setq message-buffer-list (delq (current-buffer) message-buffer-list))
4134 (while (and message-max-buffers
4136 (>= (length message-buffer-list) message-max-buffers))
4137 ;; Kill the oldest buffer -- unless it has been changed.
4138 (let ((buffer (pop message-buffer-list)))
4139 (when (and (buffer-name buffer)
4140 (not (buffer-modified-p buffer)))
4141 (kill-buffer buffer))))
4142 ;; Rename the buffer.
4143 (if message-send-rename-function
4144 (funcall message-send-rename-function)
4145 (when (string-match "\\`\\*\\(unsent \\)?" (buffer-name))
4147 (concat "*sent " (substring (buffer-name) (match-end 0))) t)))
4148 ;; Push the current buffer onto the list.
4149 (when message-max-buffers
4150 (setq message-buffer-list
4151 (nconc message-buffer-list (list (current-buffer))))))
4153 (defvar mc-modes-alist)
4154 (defun message-setup (headers &optional replybuffer actions)
4155 (when (and (boundp 'mc-modes-alist)
4156 (not (assq 'message-mode mc-modes-alist)))
4157 (push '(message-mode (encrypt . mc-encrypt-message)
4158 (sign . mc-sign-message))
4161 (setq message-send-actions actions))
4162 (setq message-reply-buffer
4163 (or (message-get-parameter 'reply-buffer)
4165 (goto-char (point-min))
4166 ;; Insert all the headers.
4169 (alist message-header-format-alist))
4171 (unless (assq (caar h) message-header-format-alist)
4172 (push (list (caar h)) alist))
4176 (delete-region (point) (progn (forward-line -1) (point)))
4177 (when message-default-headers
4178 (insert message-default-headers)
4179 (or (bolp) (insert ?\n)))
4183 (insert mail-header-separator "\n")
4187 (when (message-news-p)
4188 (when message-default-news-headers
4189 (insert message-default-news-headers)
4190 (or (bolp) (insert ?\n)))
4191 (when message-generate-headers-first
4192 (message-generate-headers
4195 (copy-sequence message-required-news-headers))))))
4196 (when (message-mail-p)
4197 (when message-default-mail-headers
4198 (insert message-default-mail-headers)
4199 (or (bolp) (insert ?\n)))
4200 (when message-generate-headers-first
4201 (message-generate-headers
4204 (copy-sequence message-required-mail-headers))))))
4205 (run-hooks 'message-signature-setup-hook)
4206 (message-insert-signature)
4208 (message-narrow-to-headers)
4209 (run-hooks 'message-header-setup-hook))
4210 (set-buffer-modified-p nil)
4211 (setq buffer-undo-list nil)
4212 (run-hooks 'message-setup-hook)
4213 (message-position-point)
4216 (defun message-set-auto-save-file-name ()
4217 "Associate the message buffer with a file in the drafts directory."
4218 (when message-auto-save-directory
4220 (setq message-draft-article
4221 (nndraft-request-associate-buffer "drafts"))
4222 (setq buffer-file-name (expand-file-name "*message*"
4223 message-auto-save-directory))
4224 (setq buffer-auto-save-file-name (make-auto-save-file-name)))
4225 (clear-visited-file-modtime)
4226 (static-if (boundp 'MULE)
4227 (set-file-coding-system message-draft-coding-system)
4228 (setq buffer-file-coding-system message-draft-coding-system))))
4230 (defun message-disassociate-draft ()
4231 "Disassociate the message buffer from the drafts directory."
4232 (when message-draft-article
4233 (nndraft-request-expire-articles
4234 (list message-draft-article) "drafts" nil t)))
4236 (defun message-insert-headers ()
4237 "Generate the headers for the article."
4241 (message-narrow-to-headers)
4242 (when (message-news-p)
4243 (message-generate-headers
4246 (copy-sequence message-required-news-headers)))))
4247 (when (message-mail-p)
4248 (message-generate-headers
4251 (copy-sequence message-required-mail-headers))))))))
4256 ;;; Commands for interfacing with message
4260 (defun message-mail (&optional to subject
4261 other-headers continue switch-function
4262 yank-action send-actions)
4263 "Start editing a mail message to be sent.
4264 OTHER-HEADERS is an alist of header/value pairs."
4266 (let ((message-this-is-mail t))
4267 (message-pop-to-buffer (message-buffer-name "mail" to))
4270 `((To . ,(or to "")) (Subject . ,(or subject "")))
4271 (when other-headers other-headers)))))
4274 (defun message-news (&optional newsgroups subject)
4275 "Start editing a news article to be sent."
4277 (let ((message-this-is-news t))
4278 (message-pop-to-buffer (message-buffer-name "news" nil newsgroups))
4279 (message-setup `((Newsgroups . ,(or newsgroups ""))
4280 (Subject . ,(or subject ""))))))
4282 (defun message-get-reply-headers (wide &optional to-address)
4283 (let (follow-to mct never-mct from to cc reply-to mft)
4284 ;; Find all relevant headers we need.
4285 (setq from (message-fetch-field "from")
4286 to (message-fetch-field "to")
4287 cc (message-fetch-field "cc")
4288 mct (when message-use-mail-copies-to
4289 (message-fetch-field "mail-copies-to"))
4290 reply-to (when message-use-mail-reply-to
4291 (or (message-fetch-field "mail-reply-to")
4292 (message-fetch-field "reply-to")))
4293 mft (when (and (not to-address)
4295 message-use-mail-followup-to)
4296 (message-fetch-field "mail-followup-to")))
4298 ;; Handle special values of Mail-Copies-To.
4301 ((and (or (equal (downcase mct) "never")
4302 (equal (downcase mct) "nobody"))
4303 (or (not (eq message-use-mail-copies-to 'ask))
4305 (concat "Obey Mail-Copies-To: never? ") t "\
4306 You should normally obey the Mail-Copies-To: header.
4308 `Mail-Copies-To: never'
4309 directs you not to send your response to the author.")))
4312 ((and (or (equal (downcase mct) "always")
4313 (equal (downcase mct) "poster"))
4314 (or (not (eq message-use-mail-copies-to 'ask))
4316 (concat "Obey Mail-Copies-To: always? ") t "\
4317 You should normally obey the Mail-Copies-To: header.
4319 `Mail-Copies-To: always'
4320 sends a copy of your response to the author.")))
4321 (setq mct (or reply-to from)))
4322 ((and (eq message-use-mail-copies-to 'ask)
4325 (concat "Obey Mail-Copies-To: " mct " ? ") t "\
4326 You should normally obey the Mail-Copies-To: header.
4328 `Mail-Copies-To: " mct "'
4329 sends a copy of your response to " (if (string-match "," mct)
4330 "the specified addresses"
4331 "that address") ".")))
4334 ;; Handle Mail-Followup-To.
4336 (eq message-use-mail-followup-to 'ask)
4337 (not (message-y-or-n-p
4338 (concat "Obey Mail-Followup-To: " mft "? ") t "\
4339 You should normally obey the Mail-Followup-To: header.
4341 `Mail-Followup-To: " mft "'
4342 directs your response to " (if (string-match "," mft)
4343 "the specified addresses"
4344 "that address only") ".
4346 A typical situation where Mail-Followup-To is used is when the author thinks
4347 that further discussion should take place only in "
4348 (if (string-match "," mft)
4349 "the specified mailing lists"
4350 "that mailing list") ".")))
4356 (setq follow-to (list (cons 'To (or to-address reply-to mft from))))
4357 (when (and wide mct)
4358 (push (cons 'Cc mct) follow-to)))
4361 (message-set-work-buffer)
4363 (insert (or reply-to from "")))
4364 (insert (if mft (concat (if (bolp) "" ", ") mft "") ""))
4365 (insert (if to (concat (if (bolp) "" ", ") to "") ""))
4366 (insert (if mct (concat (if (bolp) "" ", ") mct) ""))
4367 (insert (if cc (concat (if (bolp) "" ", ") cc) ""))
4368 (goto-char (point-min))
4369 (while (re-search-forward "[ \t]+" nil t)
4370 (replace-match " " t t))
4371 ;; Remove addresses that match `rmail-dont-reply-to-names'.
4372 (let ((rmail-dont-reply-to-names message-dont-reply-to-names))
4373 (insert (prog1 (rmail-dont-reply-to (buffer-string))
4375 (goto-char (point-min))
4376 ;; Perhaps "Mail-Copies-To: never" removed the only address?
4378 (insert (or reply-to from "")))
4382 (cons (mail-strip-quoted-names addr) addr))
4383 (message-tokenize-header (buffer-string))))
4386 (setq ccalist (delq (assoc (car (pop s)) s) ccalist)))))
4387 (setq follow-to (list (cons 'To (cdr (pop ccalist)))))
4389 (let ((ccs (cons 'Cc (mapconcat
4390 (lambda (addr) (cdr addr)) ccalist ", "))))
4391 (when (string-match "^ +" (cdr ccs))
4392 (setcdr ccs (substring (cdr ccs) (match-end 0))))
4393 (push ccs follow-to)))))
4397 (defun message-reply (&optional to-address wide)
4398 "Start editing a reply to the article in the current buffer."
4400 (let ((cur (current-buffer))
4402 references message-id follow-to
4403 (inhibit-point-motion-hooks t)
4404 (message-this-is-mail t)
4405 gnus-warning in-reply-to)
4407 (message-narrow-to-head)
4408 ;; Allow customizations to have their say.
4410 ;; This is a regular reply.
4411 (if (message-functionp message-reply-to-function)
4412 (setq follow-to (funcall message-reply-to-function)))
4413 ;; This is a followup.
4414 (if (message-functionp message-wide-reply-to-function)
4417 (funcall message-wide-reply-to-function)))))
4418 (setq message-id (message-fetch-field "message-id" t)
4419 references (message-fetch-field "references")
4420 date (message-fetch-field "date")
4421 from (message-fetch-field "from")
4422 subject (or (message-fetch-field "subject") "none"))
4423 ;; Remove any (buggy) Re:'s that are present and make a
4425 (when (string-match message-subject-re-regexp subject)
4426 (setq subject (substring subject (match-end 0))))
4427 (setq subject (message-make-followup-subject subject))
4429 (when (and (setq gnus-warning (message-fetch-field "gnus-warning"))
4430 (string-match "<[^>]+>" gnus-warning))
4431 (setq message-id (match-string 0 gnus-warning)))
4434 (setq follow-to (message-get-reply-headers wide to-address)))
4436 ;; Get the references from "In-Reply-To" field if there were
4437 ;; no references and "In-Reply-To" field looks promising.
4439 (when (and (setq in-reply-to (message-fetch-field "in-reply-to"))
4440 (string-match "<[^>]+>" in-reply-to))
4441 (setq references (match-string 0 in-reply-to)))))
4443 (message-pop-to-buffer
4444 (message-buffer-name
4445 (if wide "wide reply" "reply") from
4446 (if wide to-address nil)))
4448 (setq message-reply-headers
4449 (make-full-mail-header-from-decoded-header
4450 0 subject from date message-id references 0 0 ""))
4453 `((Subject . ,subject)
4455 ,@(if (or references message-id)
4456 `((References . ,(concat (or references "") (and references " ")
4457 (or message-id ""))))
4462 (defun message-wide-reply (&optional to-address)
4463 "Make a \"wide\" reply to the message in the current buffer."
4465 (message-reply to-address t))
4468 (defun message-followup (&optional to-newsgroups)
4469 "Follow up to the message in the current buffer.
4470 If TO-NEWSGROUPS, use that as the new Newsgroups line."
4472 (let ((cur (current-buffer))
4473 from subject date mct
4474 references message-id follow-to
4475 (inhibit-point-motion-hooks t)
4476 (message-this-is-news t)
4477 followup-to distribution newsgroups gnus-warning posted-to mft mrt)
4479 (message-narrow-to-head)
4480 (when (message-functionp message-followup-to-function)
4482 (funcall message-followup-to-function)))
4483 (setq from (message-fetch-field "from")
4484 date (message-fetch-field "date" t)
4485 subject (or (message-fetch-field "subject") "none")
4486 references (message-fetch-field "references")
4487 message-id (message-fetch-field "message-id" t)
4488 followup-to (when message-use-followup-to
4489 (message-fetch-field "followup-to"))
4490 distribution (message-fetch-field "distribution")
4491 newsgroups (message-fetch-field "newsgroups")
4492 posted-to (message-fetch-field "posted-to")
4493 mct (when message-use-mail-copies-to
4494 (message-fetch-field "mail-copies-to"))
4495 mft (when message-use-mail-followup-to
4496 (message-fetch-field "mail-followup-to"))
4497 mrt (when message-use-mail-reply-to
4498 (or (message-fetch-field "mail-reply-to")
4499 (message-fetch-field "reply-to")))
4500 gnus-warning (message-fetch-field "gnus-warning"))
4501 (when (and gnus-warning (string-match "<[^>]+>" gnus-warning))
4502 (setq message-id (match-string 0 gnus-warning)))
4503 ;; Remove bogus distribution.
4504 (when (and (stringp distribution)
4505 (let ((case-fold-search t))
4506 (string-match "world" distribution)))
4507 (setq distribution nil))
4508 ;; Remove any (buggy) Re:'s that are present and make a
4510 (setq subject (message-make-followup-subject subject))
4513 ;; Handle special values of Mail-Copies-To.
4516 ((and (or (equal (downcase mct) "never")
4517 (equal (downcase mct) "nobody"))
4518 (or (not (eq message-use-mail-copies-to 'ask))
4520 (concat "Obey Mail-Copies-To: never? ") t "\
4521 You should normally obey the Mail-Copies-To: header.
4523 `Mail-Copies-To: never'
4524 directs you not to send your response to the author.")))
4526 ((and (or (equal (downcase mct) "always")
4527 (equal (downcase mct) "poster"))
4528 (or (not (eq message-use-mail-copies-to 'ask))
4530 (concat "Obey Mail-Copies-To: always? ") t "\
4531 You should normally obey the Mail-Copies-To: header.
4533 `Mail-Copies-To: always'
4534 sends a copy of your response to the author.")))
4535 (setq mct (or mrt from)))
4536 ((and (eq message-use-mail-copies-to 'ask)
4539 (concat "Obey Mail-Copies-To: " mct " ? ") t "\
4540 You should normally obey the Mail-Copies-To: header.
4542 `Mail-Copies-To: " mct "'
4543 sends a copy of your response to " (if (string-match "," mct)
4544 "the specified addresses"
4545 "that address") ".")))
4551 (to-newsgroups (setq follow-to (list (cons 'Newsgroups to-newsgroups))))
4552 ;; Handle Followup-To.
4555 ((equal (downcase followup-to) "poster")
4556 (if (or (eq message-use-followup-to 'use)
4557 (message-y-or-n-p "Obey Followup-To: poster? " t "\
4558 You should normally obey the Followup-To: header.
4560 `Followup-To: poster'
4561 sends your response via e-mail instead of news.
4563 A typical situation where `Followup-To: poster' is used is when the author
4564 does not read the newsgroup, so he wouldn't see any replies sent to it."))
4565 (setq message-this-is-news nil
4567 follow-to (list (cons 'To (or mrt from ""))))
4568 (setq follow-to (list (cons 'Newsgroups newsgroups)))))
4570 (if (or (equal followup-to newsgroups)
4571 (not (eq message-use-followup-to 'ask))
4573 (concat "Obey Followup-To: " followup-to "? ") t "\
4574 You should normally obey the Followup-To: header.
4576 `Followup-To: " followup-to "'
4577 directs your response to " (if (string-match "," followup-to)
4578 "the specified newsgroups"
4579 "that newsgroup only") ".
4581 If a message is posted to several newsgroups, Followup-To is often
4582 used to direct the following discussion to one newsgroup only,
4583 because discussions that are spread over several newsgroup tend to
4584 be fragmented and very difficult to follow.
4586 Also, some source/announcement newsgroups are not indented for discussion;
4587 responses here are directed to other newsgroups."))
4588 (setq follow-to (list (cons 'Newsgroups followup-to)))
4589 (setq follow-to (list (cons 'Newsgroups newsgroups)))))))
4590 ;; Handle Mail-Followup-To, followup via e-mail.
4592 (or (not (eq message-use-mail-followup-to 'ask))
4594 (concat "Obey Mail-Followup-To: " mft "? ") t "\
4595 You should normally obey the Mail-Followup-To: header.
4597 `Mail-Followup-To: " mft "'
4598 directs your response to " (if (string-match "," mft)
4599 "the specified addresses"
4600 "that address only") " instead of news.
4602 A typical situation where Mail-Followup-To is used is when the author thinks
4603 that further discussion should take place only in "
4604 (if (string-match "," mft)
4605 "the specified mailing lists"
4606 "that mailing list") ".")))
4607 (setq message-this-is-news nil
4609 follow-to (list (cons 'To mft))))
4610 (posted-to (setq follow-to (list (cons 'Newsgroups posted-to))))
4612 (setq follow-to (list (cons 'Newsgroups newsgroups))))))
4614 (message-pop-to-buffer (message-buffer-name "followup" from newsgroups))
4616 (setq message-reply-headers
4617 (make-full-mail-header-from-decoded-header
4618 0 subject from date message-id references 0 0 ""))
4621 `((Subject . ,subject)
4623 ,@(and mct (list (cons 'Cc mct)))
4624 ,@(and distribution (list (cons 'Distribution distribution)))
4625 ,@(if (or references message-id)
4626 `((References . ,(concat (or references "") (and references " ")
4627 (or message-id ""))))))
4631 (defun message-cancel-news (&optional arg)
4632 "Cancel an article you posted.
4633 If ARG, allow editing of the cancellation message."
4635 (unless (message-news-p)
4636 (error "This is not a news article; canceling is impossible"))
4637 (when (yes-or-no-p "Do you really want to cancel this article? ")
4638 (let (from newsgroups message-id distribution buf sender)
4640 ;; Get header info from original article.
4642 (message-narrow-to-head)
4643 (setq from (message-fetch-field "from")
4644 sender (message-fetch-field "sender")
4645 newsgroups (message-fetch-field "newsgroups")
4646 message-id (message-fetch-field "message-id" t)
4647 distribution (message-fetch-field "distribution")))
4648 ;; Make sure that this article was written by the user.
4649 (unless (or (and sender
4652 (downcase (message-make-sender))))
4654 (downcase (cadr (std11-extract-address-components
4656 (downcase (cadr (std11-extract-address-components
4657 (message-make-from))))))
4658 (error "This article is not yours"))
4659 ;; Make control message.
4662 (setq buf (set-buffer (get-buffer-create " *message cancel*"))))
4664 (insert "Newsgroups: " newsgroups "\n"
4665 "From: " (message-make-from) "\n"
4666 "Subject: cmsg cancel " message-id "\n"
4667 "Control: cancel " message-id "\n"
4669 (concat "Distribution: " distribution "\n")
4671 mail-header-separator "\n"
4672 message-cancel-message)
4673 (run-hooks 'message-cancel-hook)
4674 (message "Canceling your article...")
4676 (if (let ((message-syntax-checks
4677 'dont-check-for-anything-just-trust-me)
4678 (message-encoding-buffer (current-buffer))
4679 (message-edit-buffer (current-buffer)))
4680 (message-send-news))
4681 (message "Canceling your article...done"))
4682 (kill-buffer buf))))))
4684 (defun message-supersede-setup-for-mime-edit ()
4685 (set (make-local-variable 'message-setup-hook) nil)
4689 (defun message-supersede ()
4690 "Start composing a message to supersede the current message.
4691 This is done simply by taking the old article and adding a Supersedes
4692 header line with the old Message-ID."
4694 (let ((cur (current-buffer))
4695 (sender (message-fetch-field "sender"))
4696 (from (message-fetch-field "from")))
4697 ;; Check whether the user owns the article that is to be superseded.
4698 (unless (or (and sender
4701 (downcase (message-make-sender))))
4703 (downcase (cadr (std11-extract-address-components from)))
4704 (downcase (cadr (std11-extract-address-components
4705 (message-make-from))))))
4706 (error "This article is not yours"))
4707 ;; Get a normal message buffer.
4708 (message-pop-to-buffer (message-buffer-name "supersede"))
4709 (insert-buffer-substring cur)
4710 (message-narrow-to-head)
4711 ;; Remove unwanted headers.
4712 (when message-ignored-supersedes-headers
4713 (message-remove-header message-ignored-supersedes-headers t))
4714 (goto-char (point-min))
4715 (if (not (re-search-forward "^Message-ID: " nil t))
4716 (error "No Message-ID in this article")
4717 (replace-match "Supersedes: " t t))
4718 (goto-char (point-max))
4719 (insert mail-header-separator)
4721 (when message-supersede-setup-function
4722 (funcall message-supersede-setup-function))
4723 (run-hooks 'message-supersede-setup-hook)
4724 (goto-char (point-min))
4725 (search-forward (concat "\n" mail-header-separator "\n") nil t)))
4728 (defun message-recover ()
4729 "Reread contents of current buffer from its last auto-save file."
4731 (let ((file-name (make-auto-save-file-name)))
4732 (cond ((save-window-excursion
4733 (if (not (eq system-type 'vax-vms))
4734 (with-output-to-temp-buffer "*Directory*"
4735 (with-current-buffer standard-output
4736 (fundamental-mode)) ; for Emacs 20.4+
4737 (buffer-disable-undo standard-output)
4738 (let ((default-directory "/"))
4740 "ls" nil standard-output nil "-l" file-name))))
4741 (yes-or-no-p (format "Recover auto save file %s? " file-name)))
4742 (let ((buffer-read-only nil))
4744 (insert-file-contents file-name nil)))
4745 (t (error "message-recover cancelled")))))
4747 ;;; Washing Subject:
4749 (defun message-wash-subject (subject)
4750 "Remove junk like \"Re:\", \"(fwd)\", etc. that was added to the subject by previous forwarders, replyers, etc."
4752 (insert-string subject)
4753 (goto-char (point-min))
4754 ;; strip Re/Fwd stuff off the beginning
4755 (while (re-search-forward
4756 "\\([Rr][Ee]:\\|[Ff][Ww][Dd]\\(\\[[0-9]*\\]\\)?:\\|[Ff][Ww]:\\)" nil t)
4759 ;; and gnus-style forwards [foo@bar.com] subject
4760 (goto-char (point-min))
4761 (while (re-search-forward "\\[[^ \t]*\\(@\\|\\.\\)[^ \t]*\\]" nil t)
4765 (goto-char (point-max))
4766 (while (re-search-backward "([Ff][Ww][Dd])" nil t)
4769 ;; and finally, any whitespace that was left-over
4770 (goto-char (point-min))
4771 (while (re-search-forward "^[ \t]+" nil t)
4773 (goto-char (point-max))
4774 (while (re-search-backward "[ \t]+$" nil t)
4779 ;;; Forwarding messages.
4781 (defun message-forward-subject-author-subject (subject)
4782 "Generate a subject for a forwarded message.
4783 The form is: [Source] Subject, where if the original message was mail,
4784 Source is the sender, and if the original message was news, Source is
4785 the list of newsgroups is was posted to."
4787 (or (message-fetch-field
4788 (if (message-news-p) "newsgroups" "from"))
4792 (defun message-forward-subject-fwd (subject)
4793 "Generate a subject for a forwarded message.
4794 The form is: Fwd: Subject, where Subject is the original subject of
4796 (concat "Fwd: " subject))
4798 (defun message-make-forward-subject ()
4799 "Return a Subject header suitable for the message in the current buffer."
4803 (message-narrow-to-head)
4804 (let ((funcs message-make-forward-subject-function)
4805 (subject (message-fetch-field "Subject")))
4808 (if message-wash-forwarded-subjects
4809 (message-wash-subject
4810 (nnheader-decode-subject subject))
4811 (nnheader-decode-subject subject))
4813 ;; Make sure funcs is a list.
4816 (setq funcs (list funcs)))
4817 ;; Apply funcs in order, passing subject generated by previous
4818 ;; func to the next one.
4820 (when (message-functionp (car funcs))
4821 (setq subject (funcall (car funcs) subject)))
4822 (setq funcs (cdr funcs)))
4826 (defun message-forward (&optional news)
4827 "Forward the current message via mail.
4828 Optional NEWS will use news to forward instead of mail."
4830 (let ((cur (current-buffer))
4831 (subject (message-make-forward-subject))
4834 (message-news nil subject)
4835 (message-mail nil subject))
4836 ;; Put point where we want it before inserting the forwarded
4838 (if message-forward-before-signature
4840 (goto-char (point-max)))
4841 ;; Make sure we're at the start of the line.
4844 ;; Narrow to the area we are to insert.
4845 (narrow-to-region (point) (point))
4846 ;; Insert the separators and the forwarded buffer.
4847 (insert message-forward-start-separator)
4848 (setq art-beg (point))
4849 (insert-buffer-substring cur)
4850 (goto-char (point-max))
4851 (insert message-forward-end-separator)
4852 (set-text-properties (point-min) (point-max) nil)
4853 ;; Remove all unwanted headers.
4855 (narrow-to-region (point) (if (search-forward "\n\n" nil t)
4858 (goto-char (point-min))
4859 (message-remove-header message-included-forward-headers t nil t)
4861 (message-position-point)))
4864 (defun message-resend (address)
4865 "Resend the current article to ADDRESS."
4867 (list (message-read-from-minibuffer "Resend message to: ")))
4868 (message "Resending message to %s..." address)
4870 (let ((cur (current-buffer))
4872 ;; We first set up a normal mail buffer.
4873 (set-buffer (get-buffer-create " *message resend*"))
4875 ;; avoid to turn-on-mime-edit
4876 (let (message-setup-hook)
4877 (message-setup `((To . ,address)))
4879 ;; Insert our usual headers.
4880 (message-generate-headers '(From Date To))
4881 (message-narrow-to-headers)
4882 ;; Rename them all to "Resent-*".
4883 (while (re-search-forward "^[A-Za-z]" nil t)
4888 (delete-region (point) (point-max))
4890 ;; Insert the message to be resent.
4891 (insert-buffer-substring cur)
4892 (goto-char (point-min))
4893 (search-forward "\n\n")
4896 (narrow-to-region beg (point))
4897 (message-remove-header message-ignored-resent-headers t)
4898 (goto-char (point-max)))
4899 (insert mail-header-separator)
4900 ;; Rename all old ("Also-")Resent headers.
4901 (while (re-search-backward "^\\(Also-\\)*Resent-" beg t)
4904 ;; Quote any "From " lines at the beginning.
4906 (when (looking-at "From ")
4907 (replace-match "X-From-Line: "))
4909 (let ((message-encoding-buffer (current-buffer))
4910 (message-edit-buffer (current-buffer)))
4911 (let (message-required-mail-headers)
4912 (message-send-mail)))
4913 (kill-buffer (current-buffer)))
4914 (message "Resending message to %s...done" address)))
4916 (defun message-bounce-setup-for-mime-edit ()
4917 (set (make-local-variable 'message-setup-hook) nil)
4921 (defun message-bounce ()
4922 "Re-mail the current message.
4923 This only makes sense if the current message is a bounce message than
4924 contains some mail you have written which has been bounced back to
4927 (let ((cur (current-buffer))
4929 (message-pop-to-buffer (message-buffer-name "bounce"))
4930 (insert-buffer-substring cur)
4932 (message-narrow-to-head)
4933 (if (and (message-fetch-field "MIME-Version")
4934 (setq boundary (message-fetch-field "Content-Type")))
4935 (if (string-match "boundary=\"\\([^\"]+\\)\"" boundary)
4936 (setq boundary (concat (match-string 1 boundary) " *\n"
4937 "Content-Type: message/rfc822"))
4938 (setq boundary nil)))
4940 (goto-char (point-min))
4941 (search-forward "\n\n" nil t)
4943 (re-search-forward boundary nil t)
4945 (and (re-search-forward message-unsent-separator nil t)
4947 (re-search-forward "^Return-Path:.*\n" nil t))
4948 ;; We remove everything before the bounced mail.
4951 (if (re-search-forward "^[^ \n\t]+:" nil t)
4955 (message-narrow-to-head)
4956 (message-remove-header message-ignored-bounced-headers t)
4957 (goto-char (point-max))
4958 (insert mail-header-separator))
4959 (when message-bounce-setup-function
4960 (funcall message-bounce-setup-function))
4961 (run-hooks 'message-bounce-setup-hook)
4962 (message-position-point)))
4965 ;;; Interactive entry points for new message buffers.
4969 (defun message-mail-other-window (&optional to subject)
4970 "Like `message-mail' command, but display mail buffer in another window."
4972 (let ((pop-up-windows t)
4973 (special-display-buffer-names nil)
4974 (special-display-regexps nil)
4975 (same-window-buffer-names nil)
4976 (same-window-regexps nil))
4977 (message-pop-to-buffer (message-buffer-name "mail" to)))
4978 (let ((message-this-is-mail t))
4979 (message-setup `((To . ,(or to "")) (Subject . ,(or subject ""))))))
4982 (defun message-mail-other-frame (&optional to subject)
4983 "Like `message-mail' command, but display mail buffer in another frame."
4985 (let ((pop-up-frames t)
4986 (special-display-buffer-names nil)
4987 (special-display-regexps nil)
4988 (same-window-buffer-names nil)
4989 (same-window-regexps nil))
4990 (message-pop-to-buffer (message-buffer-name "mail" to)))
4991 (let ((message-this-is-mail t))
4992 (message-setup `((To . ,(or to "")) (Subject . ,(or subject ""))))))
4995 (defun message-news-other-window (&optional newsgroups subject)
4996 "Start editing a news article to be sent."
4998 (let ((pop-up-windows t)
4999 (special-display-buffer-names nil)
5000 (special-display-regexps nil)
5001 (same-window-buffer-names nil)
5002 (same-window-regexps nil))
5003 (message-pop-to-buffer (message-buffer-name "news" nil newsgroups)))
5004 (let ((message-this-is-news t))
5005 (message-setup `((Newsgroups . ,(or newsgroups ""))
5006 (Subject . ,(or subject ""))))))
5009 (defun message-news-other-frame (&optional newsgroups subject)
5010 "Start editing a news article to be sent."
5012 (let ((pop-up-frames t)
5013 (special-display-buffer-names nil)
5014 (special-display-regexps nil)
5015 (same-window-buffer-names nil)
5016 (same-window-regexps nil))
5017 (message-pop-to-buffer (message-buffer-name "news" nil newsgroups)))
5018 (let ((message-this-is-news t))
5019 (message-setup `((Newsgroups . ,(or newsgroups ""))
5020 (Subject . ,(or subject ""))))))
5024 ;; This code should be moved to underline.el (from which it is stolen).
5027 (defun bold-region (start end)
5028 "Bold all nonblank characters in the region.
5029 Works by overstriking characters.
5030 Called from program, takes two arguments START and END
5031 which specify the range to operate on."
5034 (let ((end1 (make-marker)))
5035 (move-marker end1 (max start end))
5036 (goto-char (min start end))
5037 (while (< (point) end1)
5038 (or (looking-at "[_\^@- ]")
5039 (insert (char-after) "\b"))
5040 (forward-char 1)))))
5043 (defun unbold-region (start end)
5044 "Remove all boldness (overstruck characters) in the region.
5045 Called from program, takes two arguments START and END
5046 which specify the range to operate on."
5049 (let ((end1 (make-marker)))
5050 (move-marker end1 (max start end))
5051 (goto-char (min start end))
5052 (while (re-search-forward "\b" end1 t)
5053 (if (eq (char-after) (char-after (- (point) 2)))
5054 (delete-char -2))))))
5056 (defalias 'message-exchange-point-and-mark 'exchange-point-and-mark)
5058 ;; Support for toolbar
5059 (when (string-match "XEmacs\\|Lucid" emacs-version)
5060 (require 'messagexmas))
5062 ;;; Group name completion.
5064 (defvar message-newgroups-header-regexp
5065 "^\\(Newsgroups\\|Followup-To\\|Posted-To\\|Gcc\\):"
5066 "Regexp that match headers that lists groups.")
5068 (defun message-tab ()
5069 "Expand group names in Newsgroups and Followup-To headers.
5070 Do a `tab-to-tab-stop' if not in those headers."
5072 (if (let ((mail-abbrev-mode-regexp message-newgroups-header-regexp))
5073 (mail-abbrev-in-expansion-header-p))
5074 (message-expand-group)
5077 (defvar gnus-active-hashtb)
5078 (defun message-expand-group ()
5079 "Expand the group name under point."
5080 (let* ((b (save-excursion
5085 (skip-chars-forward "^:")
5088 (skip-chars-backward "^, \t\n") (point))))
5089 (completion-ignore-case t)
5090 (string (buffer-substring b (progn (skip-chars-forward "^,\t\n ")
5092 (hashtb (and (boundp 'gnus-active-hashtb) gnus-active-hashtb))
5093 (completions (all-completions string hashtb))
5095 (delete-region b (point))
5097 ((= (length completions) 1)
5098 (if (string= (car completions) string)
5101 (message "Only matching group"))
5102 (insert (car completions))))
5103 ((and (setq comp (try-completion string hashtb))
5104 (not (string= comp string)))
5109 (message "No matching groups")
5110 (save-selected-window
5111 (pop-to-buffer "*Completions*")
5112 (buffer-disable-undo)
5113 (let ((buffer-read-only nil))
5115 (let ((standard-output (current-buffer)))
5116 (display-completion-list (sort completions 'string<)))
5117 (goto-char (point-min))
5118 (delete-region (point) (progn (forward-line 3) (point))))))))))
5122 (defun message-talkative-question (ask question show &rest text)
5123 "Call FUNCTION with argument QUESTION; optionally display TEXT... args.
5124 If SHOW is non-nil, the arguments TEXT... are displayed in a temp buffer.
5125 The following arguments may contain lists of values."
5127 (setq text (message-flatten-list text)))
5128 (save-window-excursion
5130 (with-output-to-temp-buffer " *MESSAGE information message*"
5131 (set-buffer " *MESSAGE information message*")
5132 (fundamental-mode) ; for Emacs 20.4+
5133 (mapcar 'princ text)
5134 (goto-char (point-min))))
5135 (funcall ask question))
5136 (funcall ask question)))
5138 (defun message-flatten-list (list)
5139 "Return a new, flat list that contains all elements of LIST.
5141 \(message-flatten-list '(1 (2 3 (4 5 (6))) 7))
5144 (apply 'append (mapcar 'message-flatten-list list)))
5148 (defun message-generate-new-buffer-clone-locals (name &optional varstr)
5149 "Create and return a buffer with a name based on NAME using generate-new-buffer.
5150 Then clone the local variables and values from the old buffer to the
5151 new one, cloning only the locals having a substring matching the
5153 (let ((oldbuf (current-buffer)))
5155 (set-buffer (generate-new-buffer name))
5156 (message-clone-locals oldbuf varstr)
5159 (defun message-clone-locals (buffer &optional varstr)
5160 "Clone the local variables from BUFFER to the current buffer."
5161 (let ((locals (save-excursion
5163 (buffer-local-variables)))
5165 "^\\(gnus\\|nn\\|message\\|user-\\(mail-address\\|full-name\\)\\)"))
5168 (when (and (consp local)
5170 (string-match regexp (symbol-name (car local)))
5172 (string-match varstr (symbol-name (car local)))))
5174 (set (make-local-variable (car local))
5179 ;;; @ for MIME Edit mode
5182 (defun message-maybe-encode ()
5183 (when message-mime-mode
5184 ;; Inherit the buffer local variable `mime-edit-pgp-processing'.
5185 (let ((pgp-processing (with-current-buffer message-edit-buffer
5186 mime-edit-pgp-processing)))
5187 (setq mime-edit-pgp-processing pgp-processing))
5188 (run-hooks 'mime-edit-translate-hook)
5189 (if (catch 'mime-edit-error
5191 (mime-edit-pgp-enclose-buffer)
5192 (mime-edit-translate-body)
5194 (error "Translation error!")
5197 (run-hooks 'mime-edit-exit-hook)
5200 (defun message-mime-insert-article (&optional full-headers)
5202 (let ((message-cite-function 'mime-edit-inserted-message-filter)
5203 (message-reply-buffer
5204 (message-get-parameter-with-eval 'original-buffer))
5206 (message-yank-original nil)
5208 (narrow-to-region (goto-char start)
5209 (if (search-forward "\n\n" nil t)
5212 (goto-char (point-min))
5213 (let ((message-included-forward-headers
5214 (if full-headers "" message-included-forward-headers)))
5215 (message-remove-header message-included-forward-headers t nil t))
5218 (set-alist 'mime-edit-message-inserter-alist
5219 'message-mode (function message-mime-insert-article))
5221 ;;; Miscellaneous functions
5223 ;; stolen (and renamed) from nnheader.el
5224 (defun message-replace-chars-in-string (string from to)
5225 "Replace characters in STRING from FROM to TO."
5226 (let ((string (substring string 0)) ;Copy string.
5227 (len (length string))
5229 ;; Replace all occurrences of FROM with TO.
5231 (when (= (aref string idx) from)
5232 (aset string idx to))
5233 (setq idx (1+ idx)))
5240 (defvar message-inhibit-body-encoding t)
5242 (defun message-encode-message-body ()
5243 (unless message-inhibit-body-encoding
5244 (let ((mail-parse-charset (or mail-parse-charset
5245 message-default-charset))
5246 (case-fold-search t)
5247 lines content-type-p)
5250 (narrow-to-region (point) (point-max))
5251 (let ((new (mml-generate-mime)))
5253 (delete-region (point-min) (point-max))
5255 (goto-char (point-min))
5256 (if (eq (aref new 0) ?\n)
5258 (search-forward "\n\n")
5259 (setq lines (buffer-substring (point-min) (1- (point))))
5260 (delete-region (point-min) (point))))))
5262 (message-narrow-to-headers-or-head)
5263 (message-remove-header "Mime-Version")
5264 (goto-char (point-max))
5265 (insert "MIME-Version: 1.0\n")
5268 (setq content-type-p
5269 (re-search-backward "^Content-Type:" nil t)))
5271 (message-narrow-to-headers-or-head)
5272 (message-remove-first-header "Content-Type")
5273 (message-remove-first-header "Content-Transfer-Encoding"))
5274 ;; We always make sure that the message has a Content-Type header.
5275 ;; This is because some broken MTAs and MUAs get awfully confused
5276 ;; when confronted with a message with a MIME-Version header and
5277 ;; without a Content-Type header. For instance, Solaris'
5279 (unless content-type-p
5280 (goto-char (point-min))
5281 (re-search-forward "^MIME-Version:")
5283 (insert "Content-Type: text/plain; charset=us-ascii\n")))))
5285 (defun message-read-from-minibuffer (prompt)
5286 "Read from the minibuffer while providing abbrev expansion."
5287 (if (fboundp 'mail-abbrevs-setup)
5288 (let ((mail-abbrev-mode-regexp "")
5289 (minibuffer-setup-hook 'mail-abbrevs-setup))
5290 (read-from-minibuffer prompt)))
5291 (let ((minibuffer-setup-hook 'mail-abbrev-minibuffer-setup-hook))
5292 (read-string prompt)))
5294 (defvar message-save-buffer " *encoding")
5295 (defun message-save-drafts ()
5297 (if (not (get-buffer message-save-buffer))
5298 (get-buffer-create message-save-buffer))
5299 (let ((filename buffer-file-name)
5300 (buffer (current-buffer))
5301 (reply-headers message-reply-headers))
5302 (set-buffer message-save-buffer)
5304 (insert-buffer buffer)
5305 (setq message-reply-headers reply-headers)
5306 (message-generate-headers '((optional . In-Reply-To)))
5307 (mime-edit-translate-buffer)
5308 (write-region (point-min) (point-max) filename)
5310 (set-buffer-modified-p nil)))
5314 (run-hooks 'message-load-hook)
5317 ;; coding: iso-8859-1
5320 ;;; message.el ends here