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-show-mml t
410 "*If non-nil, forward messages are shown as mml. Otherwise, forward messages are unchanged."
411 :group 'message-forwarding
414 (defcustom message-forward-before-signature t
415 "*If non-nil, put forwarded message before signature, else after."
416 :group 'message-forwarding
419 (defcustom message-wash-forwarded-subjects nil
420 "*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."
421 :group 'message-forwarding
424 (defcustom message-ignored-resent-headers "^Return-receipt\\|^X-Gnus\\|^Gnus-Warning:"
425 "*All headers that match this regexp will be deleted when resending a message."
426 :group 'message-interface
429 (defcustom message-forward-ignored-headers "Content-Transfer-Encoding"
430 "*All headers that match this regexp will be deleted when forwarding a message."
431 :group 'message-forwarding
432 :type '(choice (const :tag "None" nil)
435 (defcustom message-ignored-cited-headers "."
436 "*Delete these headers from the messages you yank."
437 :group 'message-insertion
440 (defcustom message-cancel-message "I am canceling my own article.\n"
441 "Message to be inserted in the cancel message."
442 :group 'message-interface
445 ;; Useful to set in site-init.el
447 (defcustom message-send-mail-function 'message-send-mail-with-sendmail
448 "Function to call to send the current buffer as mail.
449 The headers should be delimited by a line whose contents match the
450 variable `mail-header-separator'.
452 Valid values include `message-send-mail-with-sendmail' (the default),
453 `message-send-mail-with-mh', `message-send-mail-with-qmail' and
454 `message-send-mail-with-smtp'."
455 :type '(radio (function-item message-send-mail-with-sendmail)
456 (function-item message-send-mail-with-mh)
457 (function-item message-send-mail-with-qmail)
458 (function-item message-send-mail-with-smtp)
459 (function :tag "Other"))
460 :group 'message-sending
461 :group 'message-mail)
463 ;; 1997-09-29 by MORIOKA Tomohiko
464 (defcustom message-send-news-function 'message-send-news-with-gnus
465 "Function to call to send the current buffer as news.
466 The headers should be delimited by a line whose contents match the
467 variable `mail-header-separator'."
468 :group 'message-sending
472 (defcustom message-reply-to-function nil
473 "Function that should return a list of headers.
474 This function should pick out addresses from the To, Cc, and From headers
475 and respond with new To and Cc headers."
476 :group 'message-interface
479 (defcustom message-wide-reply-to-function nil
480 "Function that should return a list of headers.
481 This function should pick out addresses from the To, Cc, and From headers
482 and respond with new To and Cc headers."
483 :group 'message-interface
486 (defcustom message-followup-to-function nil
487 "Function that should return a list of headers.
488 This function should pick out addresses from the To, Cc, and From headers
489 and respond with new To and Cc headers."
490 :group 'message-interface
493 (defcustom message-use-followup-to 'ask
494 "*Specifies what to do with Followup-To header.
495 If nil, always ignore the header. If it is t, use its value, but
496 query before using the \"poster\" value. If it is the symbol `ask',
497 always query the user whether to use the value. If it is the symbol
498 `use', always use the value."
499 :group 'message-interface
500 :type '(choice (const :tag "ignore" nil)
501 (const :tag "maybe" t)
502 (const :tag "always" use)
503 (const :tag "ask" ask)))
505 (defcustom message-use-mail-copies-to 'ask
506 "*Specifies what to do with Mail-Copies-To header.
507 If nil, always ignore the header. If it is t, use its value, but
508 query before using the value other than \"always\" or \"never\".
509 If it is the symbol `ask', always query the user whether to use
510 the value. If it is the symbol `use', always use the value."
511 :group 'message-interface
512 :type '(choice (const :tag "ignore" nil)
513 (const :tag "maybe" t)
514 (const :tag "always" use)
515 (const :tag "ask" ask)))
517 (defcustom message-use-mail-followup-to 'ask
518 "*Specifies what to do with Mail-Followup-To header.
519 If nil, always ignore the header. If it is the symbol `ask', always
520 query the user whether to use the value. If it is t or the symbol
521 `use', always use the value."
522 :group 'message-interface
523 :type '(choice (const :tag "ignore" nil)
524 (const :tag "maybe" t)
525 (const :tag "always" use)
526 (const :tag "ask" ask)))
528 ;;; XXX: 'ask and 'use are not implemented yet.
529 (defcustom message-use-mail-reply-to 'ask
530 "*Specifies what to do with Mail-Reply-To/Reply-To header.
531 If nil, always ignore the header. If it is t or the symbol `use', use
532 its value. If it is the symbol `ask', always query the user whether to
533 use the value. Note that if \"Reply-To\" is marked as \"broken\", its value
535 :group 'message-interface
536 :type '(choice (const :tag "ignore" nil)
537 (const :tag "maybe" t)
538 (const :tag "always" use)
539 (const :tag "ask" ask)))
541 (defcustom message-sendmail-f-is-evil nil
542 "*Non-nil means that \"-f username\" should not be added to the sendmail command line.
543 Doing so would be even more evil than leaving it out."
544 :group 'message-sending
547 ;; qmail-related stuff
548 (defcustom message-qmail-inject-program "/var/qmail/bin/qmail-inject"
549 "Location of the qmail-inject program."
550 :group 'message-sending
553 (defcustom message-qmail-inject-args nil
554 "Arguments passed to qmail-inject programs.
555 This should be a list of strings, one string for each argument.
557 For e.g., if you wish to set the envelope sender address so that bounces
558 go to the right place or to deal with listserv's usage of that address, you
559 might set this variable to '(\"-f\" \"you@some.where\")."
560 :group 'message-sending
561 :type '(repeat string))
563 (defvar message-cater-to-broken-inn t
564 "Non-nil means Gnus should not fold the `References' header.
565 Folding `References' makes ancient versions of INN create incorrect
568 (defvar gnus-post-method)
569 (defvar gnus-select-method)
570 (defcustom message-post-method
571 (cond ((and (boundp 'gnus-post-method)
572 (listp gnus-post-method)
575 ((boundp 'gnus-select-method)
578 "*Method used to post news.
579 Note that when posting from inside Gnus, for instance, this
580 variable isn't used."
582 :group 'message-sending
583 ;; This should be the `gnus-select-method' widget, but that might
584 ;; create a dependence to `gnus.el'.
587 (defcustom message-generate-headers-first nil
588 "*If non-nil, generate all possible headers before composing."
589 :group 'message-headers
592 (defcustom message-setup-hook '(turn-on-mime-edit)
593 "Normal hook, run each time a new outgoing message is initialized.
594 The function `message-setup' runs this hook."
595 :group 'message-various
598 (defcustom message-cancel-hook nil
599 "Hook run when cancelling articles."
600 :group 'message-various
603 (defcustom message-signature-setup-hook nil
604 "Normal hook, run each time a new outgoing message is initialized.
605 It is run after the headers have been inserted and before
606 the signature is inserted."
607 :group 'message-various
610 (defcustom message-bounce-setup-hook nil
611 "Normal hook, run each time a re-sending bounced message is initialized.
612 The function `message-bounce' runs this hook."
613 :group 'message-various
616 (defcustom message-supersede-setup-hook nil
617 "Normal hook, run each time a supersede message is initialized.
618 The function `message-supersede' runs this hook."
619 :group 'message-various
622 (defcustom message-mode-hook nil
623 "Hook run in message mode buffers."
624 :group 'message-various
627 (defcustom message-header-hook '((lambda () (eword-encode-header t)))
628 "Hook run in a message mode buffer narrowed to the headers."
629 :group 'message-various
632 (defcustom message-header-setup-hook nil
633 "Hook called narrowed to the headers when setting up a message buffer."
634 :group 'message-various
638 (defcustom message-citation-line-function 'message-insert-citation-line
639 "*Function called to insert the \"Whomever writes:\" line."
641 :group 'message-insertion)
644 (defcustom message-yank-prefix "> "
645 "*Prefix inserted on the lines of yanked messages."
647 :group 'message-insertion)
649 (defcustom message-yank-add-new-references t
650 "Non-nil means new IDs will be added to \"References\" field when an
651 article is yanked by the command `message-yank-original' interactively.
652 If it is a symbol `message-id-only', only an ID from \"Message-ID\" field
653 is used, otherwise IDs extracted from \"References\", \"In-Reply-To\" and
654 \"Message-ID\" fields are used."
655 :type '(radio (const :tag "Do not add anything" nil)
656 (const :tag "From Message-Id, References and In-Reply-To fields" t)
657 (const :tag "From only Message-Id field." message-id-only))
658 :group 'message-insertion)
660 (defcustom message-list-references-add-position nil
661 "Integer value means position for adding to \"References\" field when
662 an article is yanked by the command `message-yank-original' interactively."
663 :type '(radio (const :tag "Add to last" nil)
664 (integer :tag "Position from last ID"))
665 :group 'message-insertion)
667 (defcustom message-indentation-spaces 3
668 "*Number of spaces to insert at the beginning of each cited line.
669 Used by `message-yank-original' via `message-yank-cite'."
670 :group 'message-insertion
674 (defcustom message-cite-function 'message-cite-original
675 "*Function for citing an original message.
676 Predefined functions include `message-cite-original' and
677 `message-cite-original-without-signature'.
678 Note that `message-cite-original' uses `mail-citation-hook' if that is non-nil."
679 :type '(radio (function-item message-cite-original)
680 (function-item message-cite-original-without-signature)
681 (function-item mu-cite-original)
682 (function-item sc-cite-original)
683 (function :tag "Other"))
684 :group 'message-insertion)
687 (defcustom message-indent-citation-function 'message-indent-citation
688 "*Function for modifying a citation just inserted in the mail buffer.
689 This can also be a list of functions. Each function can find the
690 citation between (point) and (mark t). And each function should leave
691 point and mark around the citation text as modified."
693 :group 'message-insertion)
695 (defvar message-abbrevs-loaded nil)
698 (defcustom message-signature t
699 "*String to be inserted at the end of the message buffer.
700 If t, the `message-signature-file' file will be inserted instead.
701 If a function, the result from the function will be used instead.
702 If a form, the result from the form will be used instead."
704 :group 'message-insertion)
707 (defcustom message-signature-file "~/.signature"
708 "*File containing the text inserted at end of message buffer."
710 :group 'message-insertion)
712 (defcustom message-distribution-function nil
713 "*Function called to return a Distribution header."
715 :group 'message-headers
718 (defcustom message-expires 14
719 "Number of days before your article expires."
721 :group 'message-headers
722 :link '(custom-manual "(message)News Headers")
725 (defcustom message-user-path nil
726 "If nil, use the NNTP server name in the Path header.
727 If stringp, use this; if non-nil, use no host name (user name only)."
729 :group 'message-headers
730 :link '(custom-manual "(message)News Headers")
731 :type '(choice (const :tag "nntp" nil)
733 (sexp :tag "none" :format "%t" t)))
735 (defvar message-reply-buffer nil)
736 (defvar message-reply-headers nil)
737 (defvar message-sent-message-via nil)
738 (defvar message-checksum nil)
739 (defvar message-send-actions nil
740 "A list of actions to be performed upon successful sending of a message.")
741 (defvar message-exit-actions nil
742 "A list of actions to be performed upon exiting after sending a message.")
743 (defvar message-kill-actions nil
744 "A list of actions to be performed before killing a message buffer.")
745 (defvar message-postpone-actions nil
746 "A list of actions to be performed after postponing a message.")
747 (defvar message-original-frame nil)
748 (defvar message-parameter-alist nil)
749 (defvar message-startup-parameter-alist nil)
751 (define-widget 'message-header-lines 'text
752 "All header lines must be LFD terminated."
755 :error "All header lines must be newline terminated")
757 (defcustom message-default-headers ""
758 "*A string containing header lines to be inserted in outgoing messages.
759 It is inserted before you edit the message, so you can edit or delete
761 :group 'message-headers
762 :type 'message-header-lines)
764 (defcustom message-default-mail-headers ""
765 "*A string of header lines to be inserted in outgoing mails."
766 :group 'message-headers
768 :type 'message-header-lines)
770 (defcustom message-default-news-headers ""
771 "*A string of header lines to be inserted in outgoing news articles."
772 :group 'message-headers
774 :type 'message-header-lines)
776 ;; Note: could use /usr/ucb/mail instead of sendmail;
777 ;; options -t, and -v if not interactive.
778 (defcustom message-mailer-swallows-blank-line
779 (if (and (string-match "sparc-sun-sunos\\(\\'\\|[^5]\\)"
780 system-configuration)
781 (file-readable-p "/etc/sendmail.cf")
782 (let ((buffer (get-buffer-create " *temp*")))
786 (insert-file-contents "/etc/sendmail.cf")
787 (goto-char (point-min))
788 (let ((case-fold-search nil))
789 (re-search-forward "^OR\\>" nil t)))
790 (kill-buffer buffer))))
791 ;; According to RFC822, "The field-name must be composed of printable
792 ;; ASCII characters (i. e., characters that have decimal values between
793 ;; 33 and 126, except colon)", i. e., any chars except ctl chars,
795 '(looking-at "[ \t]\\|[][!\"#$%&'()*+,-./0-9;<=>?@A-Z\\\\^_`a-z{|}~]+:"))
796 "*Set this non-nil if the system's mailer runs the header and body together.
797 \(This problem exists on Sunos 4 when sendmail is run in remote mode.)
798 The value should be an expression to test whether the problem will
800 :group 'message-sending
803 ;;; XXX: This symbol is overloaded! See below.
804 (defvar message-user-agent nil
805 "String of the form of PRODUCT/VERSION. Used for User-Agent header field.")
807 ;; Ignore errors in case this is used in Emacs 19.
808 ;; Don't use ignore-errors because this is copied into loaddefs.el.
811 (define-mail-user-agent 'message-user-agent
812 'message-mail 'message-send-and-exit
813 'message-kill-buffer 'message-send-hook))
815 (defvar message-mh-deletable-headers '(Message-ID Date Lines Sender)
816 "If non-nil, delete the deletable headers before feeding to mh.")
818 (defvar message-send-method-alist
819 '((news message-news-p message-send-via-news)
820 (mail message-mail-p message-send-via-mail))
821 "Alist of ways to send outgoing messages.
822 Each element has the form
824 \(TYPE PREDICATE FUNCTION)
826 where TYPE is a symbol that names the method; PREDICATE is a function
827 called without any parameters to determine whether the message is
828 a message of type TYPE; and FUNCTION is a function to be called if
829 PREDICATE returns non-nil. FUNCTION is called with one parameter --
832 (defvar message-mail-alias-type 'abbrev
833 "*What alias expansion type to use in Message buffers.
834 The default is `abbrev', which uses mailabbrev. nil switches
837 (defcustom message-auto-save-directory
838 (nnheader-concat message-directory "drafts/")
839 "*Directory where Message auto-saves buffers if Gnus isn't running.
840 If nil, Message won't auto-save."
841 :group 'message-buffers
844 (defcustom message-buffer-naming-style 'unique
845 "*The way new message buffers are named.
846 Valid valued are `unique' and `unsent'."
847 :group 'message-buffers
848 :type '(choice (const :tag "unique" unique)
849 (const :tag "unsent" unsent)))
851 (defcustom message-default-charset nil
852 "Default charset used in non-MULE XEmacsen."
856 (defcustom message-dont-reply-to-names rmail-dont-reply-to-names
857 "*A regexp specifying names to prune when doing wide replies.
858 A value of nil means exclude your own name only."
860 :type '(choice (const :tag "Yourself" nil)
863 ;;; Internal variables.
864 ;;; Well, not really internal.
866 (defvar message-mode-syntax-table
867 (let ((table (copy-syntax-table text-mode-syntax-table)))
868 (modify-syntax-entry ?% ". " table)
869 (modify-syntax-entry ?> ". " table)
870 (modify-syntax-entry ?< ". " table)
872 "Syntax table used while in Message mode.")
874 (defvar message-mode-abbrev-table text-mode-abbrev-table
875 "Abbrev table used in Message mode buffers.
876 Defaults to `text-mode-abbrev-table'.")
877 (defgroup message-headers nil
879 :link '(custom-manual "(message)Variables")
882 (defface message-header-to-face
885 (:foreground "green2" :bold t))
888 (:foreground "MidnightBlue" :bold t))
890 (:bold t :italic t)))
891 "Face used for displaying From headers."
892 :group 'message-faces)
894 (defface message-header-cc-face
897 (:foreground "green4" :bold t))
900 (:foreground "MidnightBlue"))
903 "Face used for displaying Cc headers."
904 :group 'message-faces)
906 (defface message-header-subject-face
909 (:foreground "green3"))
912 (:foreground "navy blue" :bold t))
915 "Face used for displaying subject headers."
916 :group 'message-faces)
918 (defface message-header-newsgroups-face
921 (:foreground "yellow" :bold t :italic t))
924 (:foreground "blue4" :bold t :italic t))
926 (:bold t :italic t)))
927 "Face used for displaying newsgroups headers."
928 :group 'message-faces)
930 (defface message-header-other-face
933 (:foreground "#b00000"))
936 (:foreground "steel blue"))
938 (:bold t :italic t)))
939 "Face used for displaying newsgroups headers."
940 :group 'message-faces)
942 (defface message-header-name-face
945 (:foreground "DarkGreen"))
948 (:foreground "cornflower blue"))
951 "Face used for displaying header names."
952 :group 'message-faces)
954 (defface message-header-xheader-face
957 (:foreground "blue"))
960 (:foreground "blue"))
963 "Face used for displaying X-Header headers."
964 :group 'message-faces)
966 (defface message-separator-face
969 (:foreground "blue3"))
972 (:foreground "brown"))
975 "Face used for displaying the separator."
976 :group 'message-faces)
978 (defface message-cited-text-face
987 "Face used for displaying cited text names."
988 :group 'message-faces)
990 (defface message-mml-face
993 (:foreground "ForestGreen"))
996 (:foreground "ForestGreen"))
999 "Face used for displaying MML."
1000 :group 'message-faces)
1002 (defvar message-font-lock-fence-open-regexp "[+|]"
1003 "*Regexp that matches fence open string.")
1005 (defvar message-font-lock-fence-close-regexp "|"
1006 "*Regexp that matches fence close string.")
1008 (defvar message-font-lock-fence-open-position nil
1009 "*Cons of SYMBOL of a function or a variable and a number of OFFSET that
1010 indicate the fence open position. If it is non-nil,
1011 `message-font-lock-fence-open-regexp' is not used for searching for the
1012 fence open position. If SYMBOL is a function, it is called with one argument
1013 last cursor position and should return the fence open position as a number
1014 or a marker. If SYMBOL is a variable symbol, the value is examined with
1015 `symbol-value'. OFFSET is added to the position to compensate the value.
1016 For example, the following combinations of variable symbol and offset value
1019 Egg v3: '(egg:*region-start* . -1)
1020 Canna: '(canna:*region-start* . 0)
1023 (defvar message-font-lock-fence-close-position nil
1024 "*Cons of SYMBOL of a function or a variable and a number of OFFSET that
1025 indicate the fence close position. If it is non-nil,
1026 `message-font-lock-fence-close-regexp' is not used for searching for the
1027 fence close position. If SYMBOL is a function, it is called with one argument
1028 last cursor position and should return the fence close position as a number
1029 or a marker. If SYMBOL is a variable symbol, the value is examined with
1030 `symbol-value'. OFFSET is added to the position to compensate the value.
1031 For example, the following combinations of variable symbol and offset value
1034 Egg v3: '(egg:*region-end* . 0)
1035 Canna: '(canna:*region-end* . 0)
1038 (defvar message-font-lock-cited-text-regexp
1039 "^[\t ]*\\([^\000- :>|}\177]*\\)[:>|}].*"
1040 "*Regexp that matches cited text. It should have a grouping for the
1041 citation prefix which is ended at the beginning of citation mark string.")
1043 (defvar message-font-lock-citation-name-max-column 10
1044 "*Maximun number of column for citation name for fontifying.")
1046 (defvar message-font-lock-last-position nil
1047 "Internal buffer local variable to save the last cursor position
1048 before fontifying.")
1050 (eval-after-load "font-lock"
1051 '(defadvice font-lock-after-change-function
1052 (before message-font-lock-save-last-position activate)
1053 "Save last cursor position before fontifying."
1054 (if (eq 'message-mode major-mode)
1055 (setq message-font-lock-last-position (point)))))
1057 (defun message-font-lock-cited-text-matcher (limit)
1058 "Search for a cited text containing `message-font-lock-cited-text-regexp'
1059 forward. Argument LIMIT bounds the search. If a cited text is found, it
1060 returns t and sets match data 1 and 2, otherwise it returns nil. Normally,
1061 match data 2 has zero length, but if the FENCE (for input method) is detected
1062 in matched text, result is divided into match data 1 and 2 across the FENCE.
1063 See also the documentations for the following variables:
1064 `message-font-lock-fence-open-regexp'
1065 `message-font-lock-fence-close-regexp'
1066 `message-font-lock-fence-open-position'
1067 `message-font-lock-fence-close-position'
1070 (when (re-search-forward message-font-lock-cited-text-regexp limit t)
1071 (let* ((start0 (match-beginning 0))
1072 (end0 (match-end 0))
1073 (cite-mark (match-end 1))
1076 (goto-char cite-mark)
1077 (<= (current-column)
1078 message-font-lock-citation-name-max-column)))
1082 message-font-lock-last-position
1083 (>= message-font-lock-last-position start0)
1084 (<= message-font-lock-last-position end0)
1086 (message-font-lock-fence-open-position
1087 (let* ((symbol (car message-font-lock-fence-open-position))
1089 (cond ((functionp symbol)
1090 (funcall symbol message-font-lock-last-position))
1091 ((and (symbolp symbol)
1093 (symbol-value symbol)))))
1094 (when (markerp open)
1095 (setq open (marker-position open)))
1099 (cdr message-font-lock-fence-open-position)))
1100 (>= message-font-lock-last-position open)
1102 (or (not message-font-lock-fence-open-regexp)
1103 (looking-at message-font-lock-fence-open-regexp))
1105 (message-font-lock-fence-open-regexp
1106 (goto-char message-font-lock-last-position)
1107 (when (re-search-backward
1108 message-font-lock-fence-open-regexp start0 t)
1109 (setq end1 (match-beginning 0)))))
1110 (setq should-fontify
1111 (and message-font-lock-fence-open-position
1112 (not (eq cite-mark end1))))
1114 (message-font-lock-fence-close-position
1115 (let* ((symbol (car message-font-lock-fence-close-position))
1117 (cond ((functionp symbol)
1118 (funcall symbol message-font-lock-last-position))
1119 ((and (symbolp symbol)
1121 (symbol-value symbol)))))
1122 (when (markerp close)
1123 (setq close (marker-position close)))
1124 (and (numberp close)
1127 (cdr message-font-lock-fence-close-position)))
1128 (<= message-font-lock-last-position close)
1129 (setq start2 close))))
1130 (message-font-lock-fence-close-regexp
1131 (goto-char message-font-lock-last-position)
1132 (when (looking-at message-font-lock-fence-close-regexp)
1133 (setq start2 (match-end 0)))))
1134 (setq should-fontify
1135 (and (not (and (not message-font-lock-fence-open-position)
1136 (eq cite-mark end1)))
1137 (not (eq cite-mark start2)))))
1139 (when should-fontify
1141 (store-match-data (list start0 end0 start0 end1 start2 end0))
1142 (store-match-data (list start0 end0 start0 end0 end0 end0)))
1144 (setq message-font-lock-last-position nil)))
1146 (defvar message-font-lock-keywords-1
1147 (let ((content "[ \t]*\\(.+\\(\n[ \t].*\\)*\\)"))
1148 `((,(concat "^\\([Tt]o:\\)" content)
1149 (1 'message-header-name-face)
1150 (2 'message-header-to-face nil t))
1151 (,(concat "^\\([GBF]?[Cc][Cc]:\\|[Rr]eply-[Tt]o:\\|"
1152 "[Mm]ail-[Cc]opies-[Tt]o:\\|"
1153 "[Mm]ail-[Rr]eply-[Tt]o:\\|"
1154 "[Mm]ail-[Ff]ollowup-[Tt]o:\\)" content)
1155 (1 'message-header-name-face)
1156 (2 'message-header-cc-face nil t))
1157 (,(concat "^\\([Ss]ubject:\\)" content)
1158 (1 'message-header-name-face)
1159 (2 'message-header-subject-face nil t))
1160 (,(concat "^\\([Nn]ewsgroups:\\|Followup-[Tt]o:\\)" content)
1161 (1 'message-header-name-face)
1162 (2 'message-header-newsgroups-face nil t))
1163 (,(concat "^\\([A-Z][^: \n\t]+:\\)" content)
1164 (1 'message-header-name-face)
1165 (2 'message-header-other-face nil t))
1166 (,(concat "^\\(X-[A-Za-z0-9-]+\\|In-Reply-To\\):" content)
1167 (1 'message-header-name-face)
1168 (2 'message-header-name-face))
1169 ,@(if (and mail-header-separator
1170 (not (equal mail-header-separator "")))
1171 `((,(concat "^\\(" (regexp-quote mail-header-separator) "\\)$")
1172 1 'message-separator-face))
1175 (defvar message-font-lock-keywords-2
1176 (append message-font-lock-keywords-1
1177 '((message-font-lock-cited-text-matcher
1178 (1 'message-cited-text-face)
1179 (2 'message-cited-text-face))
1180 ("<#/?\\(multipart\\|part\\|external\\).*>"
1181 (0 'message-mml-face)))))
1183 (defvar message-font-lock-keywords message-font-lock-keywords-2
1184 "Additional expressions to highlight in Message mode.")
1186 ;; XEmacs does it like this. For Emacs, we have to set the
1187 ;; `font-lock-defaults' buffer-local variable.
1188 (put 'message-mode 'font-lock-defaults
1189 '((message-font-lock-keywords
1190 message-font-lock-keywords-1
1191 message-font-lock-keywords-2)
1193 (font-lock-mark-block-function . mark-paragraph)))
1195 (defvar message-face-alist
1196 '((bold . bold-region)
1197 (underline . underline-region)
1198 (default . (lambda (b e)
1200 (ununderline-region b e))))
1201 "Alist of mail and news faces for facemenu.
1202 The cdr of ech entry is a function for applying the face to a region.")
1204 (defcustom message-send-hook nil
1205 "Hook run before sending messages."
1206 :group 'message-various
1207 :options '(ispell-message)
1210 (defcustom message-send-mail-hook nil
1211 "Hook run before sending mail messages."
1212 :group 'message-various
1215 (defcustom message-send-news-hook nil
1216 "Hook run before sending news messages."
1217 :group 'message-various
1220 (defcustom message-sent-hook nil
1221 "Hook run after sending messages."
1222 :group 'message-various
1225 (defcustom message-use-multi-frames nil
1226 "Make new frame when sending messages."
1227 :group 'message-frames
1230 (defcustom message-delete-frame-on-exit nil
1231 "Delete frame after sending messages."
1232 :group 'message-frames
1233 :type '(choice (const :tag "off" nil)
1234 (const :tag "always" t)
1235 (const :tag "ask" ask)))
1237 (defvar message-draft-coding-system
1239 ((boundp 'MULE) '*junet*)
1240 ((not (fboundp 'find-coding-system)) nil)
1241 ((find-coding-system 'emacs-mule)
1242 (if (memq system-type '(windows-nt ms-dos ms-windows))
1243 'emacs-mule-dos 'emacs-mule))
1244 ((find-coding-system 'escape-quoted) 'escape-quoted)
1245 ((find-coding-system 'no-conversion) 'no-conversion)
1247 "Coding system to compose mail.")
1249 (defcustom message-send-mail-partially-limit 1000000
1250 "The limitation of messages sent as message/partial.
1251 The lower bound of message size in characters, beyond which the message
1252 should be sent in several parts. If it is nil, the size is unlimited."
1253 :group 'message-buffers
1254 :type '(choice (const :tag "unlimited" nil)
1257 ;;; Internal variables.
1259 (defvar message-buffer-list nil)
1260 (defvar message-this-is-news nil)
1261 (defvar message-this-is-mail nil)
1262 (defvar message-draft-article nil)
1263 (defvar message-mime-part nil)
1264 (defvar message-posting-charset nil)
1266 ;; Byte-compiler warning
1267 (defvar gnus-active-hashtb)
1268 (defvar gnus-read-active-file)
1270 ;;; Regexp matching the delimiter of messages in UNIX mail format
1271 ;;; (UNIX From lines), minus the initial ^. It should be a copy
1272 ;;; of rmail.el's rmail-unix-mail-delimiter.
1273 (defvar message-unix-mail-delimiter
1274 (let ((time-zone-regexp
1275 (concat "\\([A-Z]?[A-Z]?[A-Z][A-Z]\\( DST\\)?"
1276 "\\|[-+]?[0-9][0-9][0-9][0-9]"
1282 ;; Many things can happen to an RFC 822 mailbox before it is put into
1283 ;; a `From' line. The leading phrase can be stripped, e.g.
1284 ;; `Joe <@w.x:joe@y.z>' -> `<@w.x:joe@y.z>'. The <> can be stripped, e.g.
1285 ;; `<@x.y:joe@y.z>' -> `@x.y:joe@y.z'. Everything starting with a CRLF
1286 ;; can be removed, e.g.
1287 ;; From: joe@y.z (Joe K
1289 ;; can yield `From joe@y.z (Joe K Fri Mar 22 08:11:15 1996', and
1292 ;; can yield `From Joe User Fri Mar 22 08:11:15 1996'.
1293 ;; The mailbox can be removed or be replaced by white space, e.g.
1294 ;; From: "Joe User"{space}{tab}
1296 ;; can yield `From {space}{tab} Fri Mar 22 08:11:15 1996',
1297 ;; where {space} and {tab} represent the Ascii space and tab characters.
1298 ;; We want to match the results of any of these manglings.
1299 ;; The following regexp rejects names whose first characters are
1300 ;; obviously bogus, but after that anything goes.
1301 "\\([^\0-\b\n-\r\^?].*\\)? "
1303 ;; The time the message was sent.
1304 "\\([^\0-\r \^?]+\\) +" ; day of the week
1305 "\\([^\0-\r \^?]+\\) +" ; month
1306 "\\([0-3]?[0-9]\\) +" ; day of month
1307 "\\([0-2][0-9]:[0-5][0-9]\\(:[0-6][0-9]\\)?\\) *" ; time of day
1309 ;; Perhaps a time zone, specified by an abbreviation, or by a
1314 " \\([0-9][0-9]+\\) *"
1316 ;; On some systems the time zone can appear after the year, too.
1320 "\\(remote from .*\\)?"
1323 "Regexp matching the delimiter of messages in UNIX mail format.")
1325 (defvar message-unsent-separator
1326 (concat "^ *---+ +Unsent message follows +---+ *$\\|"
1327 "^ *---+ +Returned message +---+ *$\\|"
1328 "^Start of returned message$\\|"
1329 "^ *---+ +Original message +---+ *$\\|"
1330 "^ *--+ +begin message +--+ *$\\|"
1331 "^ *---+ +Original message follows +---+ *$\\|"
1332 "^ *---+ +Undelivered message follows +---+ *$\\|"
1333 "^|? *---+ +Message text follows: +---+ *|?$")
1334 "A regexp that matches the separator before the text of a failed message.")
1336 (defvar message-header-format-alist
1338 (To . message-fill-address)
1339 (Cc . message-fill-address)
1350 (References . message-shorten-references)
1352 "Alist used for formatting headers.")
1355 (autoload 'message-setup-toolbar "messagexmas")
1356 (autoload 'mh-new-draft-name "mh-comp")
1357 (autoload 'mh-send-letter "mh-comp")
1358 (autoload 'gnus-point-at-eol "gnus-util")
1359 (autoload 'gnus-point-at-bol "gnus-util")
1360 (autoload 'gnus-output-to-mail "gnus-util")
1361 (autoload 'mail-abbrev-in-expansion-header-p "mailabbrev")
1362 (autoload 'nndraft-request-associate-buffer "nndraft")
1363 (autoload 'nndraft-request-expire-articles "nndraft")
1364 (autoload 'gnus-open-server "gnus-int")
1365 (autoload 'gnus-request-post "gnus-int")
1366 (autoload 'gnus-copy-article-buffer "gnus-msg")
1367 (autoload 'gnus-alive-p "gnus-util")
1368 (autoload 'rmail-output "rmail")
1369 (autoload 'mu-cite-original "mu-cite"))
1374 ;;; Utility functions.
1376 (defun message-eval-parameter (parameter)
1378 (if (symbolp parameter)
1379 (if (functionp parameter)
1385 (defsubst message-get-parameter (key &optional alist)
1387 (setq alist message-parameter-alist))
1388 (cdr (assq key alist)))
1390 (defmacro message-get-parameter-with-eval (key &optional alist)
1391 `(message-eval-parameter (message-get-parameter ,key ,alist)))
1393 (defmacro message-y-or-n-p (question show &rest text)
1394 "Ask QUESTION, displaying the rest of the arguments in a temp. buffer if SHOW"
1395 `(message-talkative-question 'y-or-n-p ,question ,show ,@text))
1397 ;; Delete the current line (and the next N lines.);
1398 (defmacro message-delete-line (&optional n)
1399 `(delete-region (progn (beginning-of-line) (point))
1400 (progn (forward-line ,(or n 1)) (point))))
1402 (defun message-tokenize-header (header &optional separator)
1403 "Split HEADER into a list of header elements.
1404 \",\" is used as the separator."
1407 (let ((regexp (format "[%s]+" (or separator ",")))
1412 (message-set-work-buffer)
1414 (goto-char (point-min))
1419 (cond ((and (> (point) beg)
1421 (and (looking-at regexp)
1424 (push (buffer-substring beg (point)) elems)
1425 (setq beg (match-end 0)))
1426 ((eq (char-after) ?\")
1427 (setq quoted (not quoted)))
1428 ((and (eq (char-after) ?\()
1431 ((and (eq (char-after) ?\))
1434 (nreverse elems)))))
1436 (defun message-mail-file-mbox-p (file)
1437 "Say whether FILE looks like a Unix mbox file."
1438 (when (and (file-exists-p file)
1439 (file-readable-p file)
1440 (file-regular-p file))
1442 (nnheader-insert-file-contents file)
1443 (goto-char (point-min))
1444 (looking-at message-unix-mail-delimiter))))
1446 (defun message-fetch-field (header &optional not-all)
1447 "The same as `mail-fetch-field', only remove all newlines."
1448 (let* ((inhibit-point-motion-hooks t)
1449 (case-fold-search t)
1450 (value (mail-fetch-field header nil (not not-all))))
1452 (while (string-match "\n[\t ]+" value)
1453 (setq value (replace-match " " t t value)))
1454 ;; We remove all text props.
1455 (format "%s" value))))
1457 (defun message-narrow-to-field ()
1458 "Narrow the buffer to the header on the current line."
1464 (if (re-search-forward "^[^ \n\t]" nil t)
1469 (goto-char (point-min)))
1471 (defun message-add-header (&rest headers)
1472 "Add the HEADERS to the message header, skipping those already present."
1475 (unless (string-match "^\\([^:]+\\):[ \t]*[^ \t]" (car headers))
1476 (error "Invalid header `%s'" (car headers)))
1477 (setq hclean (match-string 1 (car headers)))
1479 (message-narrow-to-headers)
1480 (unless (re-search-forward (concat "^" (regexp-quote hclean) ":") nil t)
1481 (insert (car headers) ?\n))))
1482 (setq headers (cdr headers))))
1485 (defun message-fetch-reply-field (header)
1486 "Fetch FIELD from the message we're replying to."
1487 (let ((buffer (message-eval-parameter message-reply-buffer)))
1489 (buffer-name buffer))
1492 (message-fetch-field header)))))
1494 (defun message-set-work-buffer ()
1495 (if (get-buffer " *message work*")
1497 (set-buffer " *message work*")
1499 (set-buffer (get-buffer-create " *message work*"))
1500 (kill-all-local-variables)))
1502 (defun message-functionp (form)
1503 "Return non-nil if FORM is funcallable."
1504 (or (and (symbolp form) (fboundp form))
1505 (and (listp form) (eq (car form) 'lambda))
1506 (byte-code-function-p form)))
1508 (defun message-strip-subject-re (subject)
1509 "Remove \"Re:\" from subject lines."
1510 (if (string-match message-subject-re-regexp subject)
1511 (substring subject (match-end 0))
1514 (defun message-remove-header (header &optional is-regexp first reverse)
1515 "Remove HEADER in the narrowed buffer.
1516 If REGEXP, HEADER is a regular expression.
1517 If FIRST, only remove the first instance of the header.
1518 Return the number of headers removed."
1519 (goto-char (point-min))
1520 (let ((regexp (if is-regexp header (concat "^" (regexp-quote header) ":")))
1522 (case-fold-search t)
1524 (while (and (not (eobp))
1527 (not (looking-at regexp))
1528 (looking-at regexp))
1535 ;; There might be a continuation header, so we have to search
1536 ;; until we find a new non-continuation line.
1539 (if (re-search-forward "^[^ \t]" nil t)
1540 (goto-char (match-beginning 0))
1543 (if (re-search-forward "^[^ \t]" nil t)
1544 (goto-char (match-beginning 0))
1545 (goto-char (point-max)))))
1548 (defun message-remove-first-header (header)
1549 "Remove the first instance of HEADER if there is more than one."
1551 (regexp (concat "^" (regexp-quote header) ":")))
1553 (goto-char (point-min))
1554 (while (re-search-forward regexp nil t)
1557 (message-remove-header header nil t)
1560 (defun message-narrow-to-headers ()
1561 "Narrow the buffer to the head of the message."
1564 (goto-char (point-min))
1565 (if (re-search-forward
1566 (concat "^" (regexp-quote mail-header-separator) "\n") nil t)
1569 (goto-char (point-min)))
1571 (defun message-narrow-to-head ()
1572 "Narrow the buffer to the head of the message.
1573 Point is left at the beginning of the narrowed-to region."
1576 (goto-char (point-min))
1577 (if (search-forward "\n\n" nil 1)
1580 (goto-char (point-min)))
1582 (defun message-narrow-to-headers-or-head ()
1583 "Narrow the buffer to the head of the message."
1586 (goto-char (point-min))
1589 (concat "^" (regexp-quote mail-header-separator) "\n") nil t)
1590 (match-beginning 0))
1591 ((search-forward "\n\n" nil t)
1595 (goto-char (point-min)))
1597 (defun message-news-p ()
1598 "Say whether the current buffer contains a news message."
1599 (and (not message-this-is-mail)
1600 (or message-this-is-news
1603 (message-narrow-to-headers)
1604 (and (message-fetch-field "newsgroups")
1605 (not (message-fetch-field "posted-to"))))))))
1607 (defun message-mail-p ()
1608 "Say whether the current buffer contains a mail message."
1609 (and (not message-this-is-news)
1610 (or message-this-is-mail
1613 (message-narrow-to-headers)
1614 (or (message-fetch-field "to")
1615 (message-fetch-field "cc")
1616 (message-fetch-field "bcc")))))))
1618 (defun message-next-header ()
1619 "Go to the beginning of the next header."
1621 (or (eobp) (forward-char 1))
1622 (not (if (re-search-forward "^[^ \t]" nil t)
1624 (goto-char (point-max)))))
1626 (defun message-sort-headers-1 ()
1627 "Sort the buffer as headers using `message-rank' text props."
1628 (goto-char (point-min))
1631 nil 'message-next-header
1633 (message-next-header)
1637 (or (get-text-property (point) 'message-rank)
1640 (defun message-sort-headers ()
1641 "Sort the headers of the current message according to `message-header-format-alist'."
1645 (let ((max (1+ (length message-header-format-alist)))
1647 (message-narrow-to-headers)
1648 (while (re-search-forward "^[^ \n]+:" nil t)
1650 (match-beginning 0) (1+ (match-beginning 0))
1652 (if (setq rank (length (memq (assq (intern (buffer-substring
1654 (1- (match-end 0))))
1655 message-header-format-alist)
1656 message-header-format-alist)))
1659 (message-sort-headers-1))))
1669 (defvar message-mode-map nil)
1671 (unless message-mode-map
1672 (setq message-mode-map (make-keymap))
1673 (set-keymap-parent message-mode-map text-mode-map)
1674 (define-key message-mode-map "\C-c?" 'describe-mode)
1676 (define-key message-mode-map "\C-c\C-f\C-t" 'message-goto-to)
1677 (define-key message-mode-map "\C-c\C-f\C-b" 'message-goto-bcc)
1678 (define-key message-mode-map "\C-c\C-f\C-w" 'message-goto-fcc)
1679 (define-key message-mode-map "\C-c\C-f\C-c" 'message-goto-cc)
1680 (define-key message-mode-map "\C-c\C-f\C-s" 'message-goto-subject)
1681 ;; (define-key message-mode-map "\C-c\C-f\C-r" 'message-goto-reply-to)
1682 (define-key message-mode-map "\C-c\C-f\C-r" 'message-goto-mail-reply-to)
1683 (define-key message-mode-map "\C-c\C-f\C-m" 'message-goto-mail-followup-to)
1684 (define-key message-mode-map "\C-c\C-f\C-n" 'message-goto-newsgroups)
1685 (define-key message-mode-map "\C-c\C-f\C-d" 'message-goto-distribution)
1686 (define-key message-mode-map "\C-c\C-f\C-f" 'message-goto-followup-to)
1687 (define-key message-mode-map "\C-c\C-f\C-k" 'message-goto-keywords)
1688 (define-key message-mode-map "\C-c\C-f\C-u" 'message-goto-summary)
1689 (define-key message-mode-map "\C-c\C-b" 'message-goto-body)
1690 (define-key message-mode-map "\C-c\C-i" 'message-goto-signature)
1691 (define-key message-mode-map "\C-c\C-fc" 'message-goto-mail-copies-to)
1693 (define-key message-mode-map "\C-c\C-t" 'message-insert-to)
1694 (define-key message-mode-map "\C-c\C-n" 'message-insert-newsgroups)
1696 (define-key message-mode-map "\C-c\C-y" 'message-yank-original)
1697 (define-key message-mode-map "\C-c\M-\C-y" 'message-yank-buffer)
1698 (define-key message-mode-map "\C-c\C-q" 'message-fill-yanked-message)
1699 (define-key message-mode-map "\C-c\C-w" 'message-insert-signature)
1700 (define-key message-mode-map "\C-c\M-h" 'message-insert-headers)
1701 (define-key message-mode-map "\C-c\C-r" 'message-caesar-buffer-body)
1702 (define-key message-mode-map "\C-c\C-o" 'message-sort-headers)
1703 (define-key message-mode-map "\C-c\M-r" 'message-rename-buffer)
1705 (define-key message-mode-map "\C-c\C-c" 'message-send-and-exit)
1706 (define-key message-mode-map "\C-c\C-s" 'message-send)
1707 (define-key message-mode-map "\C-c\C-k" 'message-kill-buffer)
1708 (define-key message-mode-map "\C-c\C-d" 'message-dont-send)
1710 (define-key message-mode-map "\C-c\C-e" 'message-elide-region)
1711 (define-key message-mode-map "\C-c\C-v" 'message-delete-not-region)
1712 (define-key message-mode-map "\C-c\C-z" 'message-kill-to-signature)
1713 (define-key message-mode-map "\M-\r" 'message-newline-and-reformat)
1715 (define-key message-mode-map "\t" 'message-tab)
1717 (define-key message-mode-map "\C-x\C-s" 'message-save-drafts)
1718 (define-key message-mode-map "\C-xk" 'message-mimic-kill-buffer))
1721 message-mode-menu message-mode-map "Message Menu."
1723 ["Sort Headers" message-sort-headers t]
1724 ["Yank Original" message-yank-original t]
1725 ["Fill Yanked Message" message-fill-yanked-message t]
1726 ["Insert Signature" message-insert-signature t]
1727 ["Caesar (rot13) Message" message-caesar-buffer-body t]
1728 ["Caesar (rot13) Region" message-caesar-region (mark t)]
1729 ["Elide Region" message-elide-region (mark t)]
1730 ["Delete Outside Region" message-delete-not-region (mark t)]
1731 ["Kill To Signature" message-kill-to-signature t]
1732 ["Newline and Reformat" message-newline-and-reformat t]
1733 ["Rename buffer" message-rename-buffer t]
1734 ["Spellcheck" ispell-message t]
1735 ["Attach file as MIME" mime-edit-insert-file t]
1737 ["Send Message" message-send-and-exit t]
1738 ["Abort Message" message-dont-send t]
1739 ["Kill Message" message-kill-buffer t]))
1742 message-mode-field-menu message-mode-map ""
1744 ["Fetch To" message-insert-to t]
1745 ["Fetch Newsgroups" message-insert-newsgroups t]
1747 ["To" message-goto-to t]
1748 ["Subject" message-goto-subject t]
1749 ["Cc" message-goto-cc t]
1750 ["Reply-To" message-goto-reply-to t]
1751 ["Mail-Reply-To" message-goto-mail-reply-to t]
1752 ["Mail-Followup-To" message-goto-mail-followup-to t]
1753 ["Mail-Copies-To" message-goto-mail-copies-to t]
1754 ["Summary" message-goto-summary t]
1755 ["Keywords" message-goto-keywords t]
1756 ["Newsgroups" message-goto-newsgroups t]
1757 ["Followup-To" message-goto-followup-to t]
1758 ["Distribution" message-goto-distribution t]
1759 ["Body" message-goto-body t]
1760 ["Signature" message-goto-signature t]))
1762 (defvar facemenu-add-face-function)
1763 (defvar facemenu-remove-face-function)
1766 (defun message-mode ()
1767 "Major mode for editing mail and news to be sent.
1768 Like Text Mode but with these additional commands:
1769 C-c C-s message-send (send the message) C-c C-c message-send-and-exit
1770 C-c C-d Pospone sending the message C-c C-k Kill the message
1771 C-c C-f move to a header field (and create it if there isn't):
1772 C-c C-f C-t move to To C-c C-f C-s move to Subject
1773 C-c C-f C-c move to Cc C-c C-f C-b move to Bcc
1774 C-c C-f C-w move to Fcc C-c C-f C-r move to Reply-To
1775 C-c C-f C-u move to Summary C-c C-f C-n move to Newsgroups
1776 C-c C-f C-k move to Keywords C-c C-f C-d move to Distribution
1777 C-c C-f C-m move to Mail-Followup-To
1778 C-c C-f C-f move to Followup-To
1779 C-c C-t message-insert-to (add a To header to a news followup)
1780 C-c C-n message-insert-newsgroups (add a Newsgroup header to a news reply)
1781 C-c C-b message-goto-body (move to beginning of message text).
1782 C-c C-i message-goto-signature (move to the beginning of the signature).
1783 C-c C-w message-insert-signature (insert `message-signature-file' file).
1784 C-c C-y message-yank-original (insert current message, if any).
1785 C-c C-q message-fill-yanked-message (fill what was yanked).
1786 C-c C-e message-elide-region (elide the text between point and mark).
1787 C-c C-v message-delete-not-region (remove the text outside the region).
1788 C-c C-z message-kill-to-signature (kill the text up to the signature).
1789 C-c C-r message-caesar-buffer-body (rot13 the message body).
1790 M-RET message-newline-and-reformat (break the line and reformat)."
1792 (kill-all-local-variables)
1793 (set (make-local-variable 'message-reply-buffer) nil)
1794 (make-local-variable 'message-send-actions)
1795 (make-local-variable 'message-exit-actions)
1796 (make-local-variable 'message-kill-actions)
1797 (make-local-variable 'message-postpone-actions)
1798 (make-local-variable 'message-draft-article)
1799 (make-local-hook 'kill-buffer-hook)
1800 (set-syntax-table message-mode-syntax-table)
1801 (use-local-map message-mode-map)
1802 (setq local-abbrev-table message-mode-abbrev-table)
1803 (setq major-mode 'message-mode)
1804 (setq mode-name "Message")
1805 (setq buffer-offer-save t)
1806 (make-local-variable 'facemenu-add-face-function)
1807 (make-local-variable 'facemenu-remove-face-function)
1808 (setq facemenu-add-face-function
1810 (let ((face-fun (cdr (assq face message-face-alist))))
1812 (funcall face-fun (point) end)
1813 (error "Face %s not configured for %s mode" face mode-name)))
1815 facemenu-remove-face-function t)
1816 (make-local-variable 'paragraph-separate)
1817 (make-local-variable 'paragraph-start)
1818 ;; `-- ' precedes the signature. `-----' appears at the start of the
1819 ;; lines that delimit forwarded messages.
1820 ;; Lines containing just >= 3 dashes, perhaps after whitespace,
1821 ;; are also sometimes used and should be separators.
1822 (setq paragraph-start
1823 (concat (regexp-quote mail-header-separator)
1824 "$\\|[ \t]*[a-z0-9A-Z]*>+[ \t]*$\\|[ \t]*$\\|"
1827 ;;!!! Uhm... shurely this can't be right?
1828 "[> " (regexp-quote message-yank-prefix) "]+$"))
1829 (setq paragraph-separate paragraph-start)
1830 (make-local-variable 'message-reply-headers)
1831 (setq message-reply-headers nil)
1832 (make-local-variable 'message-user-agent)
1833 (make-local-variable 'message-post-method)
1834 (set (make-local-variable 'message-sent-message-via) nil)
1835 (set (make-local-variable 'message-checksum) nil)
1836 (make-local-variable 'message-parameter-alist)
1837 (setq message-parameter-alist
1838 (copy-sequence message-startup-parameter-alist))
1839 ;;(when (fboundp 'mail-hist-define-keys)
1840 ;; (mail-hist-define-keys))
1841 (when (string-match "XEmacs\\|Lucid" emacs-version)
1842 (message-setup-toolbar))
1843 (easy-menu-add message-mode-menu message-mode-map)
1844 (easy-menu-add message-mode-field-menu message-mode-map)
1845 ;; Allow mail alias things.
1846 (when (eq message-mail-alias-type 'abbrev)
1847 (if (fboundp 'mail-abbrevs-setup)
1848 (mail-abbrevs-setup)
1849 (mail-aliases-setup)))
1850 (message-set-auto-save-file-name)
1851 (unless (string-match "XEmacs" emacs-version)
1852 (set (make-local-variable 'font-lock-defaults)
1853 '((message-font-lock-keywords
1854 message-font-lock-keywords-1
1855 message-font-lock-keywords-2)
1857 (font-lock-mark-block-function . mark-paragraph))))
1858 (set (make-local-variable 'message-font-lock-last-position) nil)
1859 (make-local-variable 'adaptive-fill-regexp)
1860 (setq adaptive-fill-regexp
1861 (concat "[ \t]*[-a-z0-9A-Z]*\\(>[ \t]*\\)+[ \t]*\\|"
1862 adaptive-fill-regexp))
1863 (unless (boundp 'adaptive-fill-first-line-regexp)
1864 (setq adaptive-fill-first-line-regexp nil))
1865 (make-local-variable 'adaptive-fill-first-line-regexp)
1866 (setq adaptive-fill-first-line-regexp
1867 (concat "[ \t]*[-a-z0-9A-Z]*\\(>[ \t]*\\)+[ \t]*\\|"
1868 adaptive-fill-first-line-regexp))
1869 (make-local-variable 'auto-fill-inhibit-regexp)
1870 (setq auto-fill-inhibit-regexp "^[A-Z][^: \n\t]+:")
1871 (make-local-variable 'indent-tabs-mode) ;Turn off tabs for indentation.
1872 (setq indent-tabs-mode nil)
1873 (run-hooks 'text-mode-hook 'message-mode-hook))
1878 ;;; Message mode commands
1881 ;;; Movement commands
1883 (defun message-goto-to ()
1884 "Move point to the To header."
1886 (message-position-on-field "To"))
1888 (defun message-goto-subject ()
1889 "Move point to the Subject header."
1891 (message-position-on-field "Subject"))
1893 (defun message-goto-cc ()
1894 "Move point to the Cc header."
1896 (message-position-on-field "Cc" "To"))
1898 (defun message-goto-bcc ()
1899 "Move point to the Bcc header."
1901 (message-position-on-field "Bcc" "Cc" "To"))
1903 (defun message-goto-fcc ()
1904 "Move point to the Fcc header."
1906 (message-position-on-field "Fcc" "To" "Newsgroups"))
1908 (defun message-goto-reply-to ()
1909 "Move point to the Reply-To header."
1911 (message-position-on-field "Reply-To" "Subject"))
1913 (defun message-goto-mail-reply-to ()
1914 "Move point to the Mail-Reply-To header."
1916 (message-position-on-field "Mail-Reply-To" "Subject"))
1918 (defun message-goto-mail-followup-to ()
1919 "Move point to the Mail-Followup-To header. If the header is newly created
1920 and To field contains only one address, the address is inserted in default."
1922 (unless (message-position-on-field "Mail-Followup-To" "Subject")
1923 (let ((start (point))
1926 (message-narrow-to-headers)
1927 (setq addresses (split-string (mail-strip-quoted-names
1928 (or (std11-fetch-field "to") ""))
1930 (when (eq 1 (length addresses))
1932 (insert (car addresses))
1933 (goto-char start))))))
1935 (defun message-goto-mail-copies-to ()
1936 "Move point to the Mail-Copies-To header. If the header is newly created,
1937 a string \"never\" is inserted in default."
1939 (unless (message-position-on-field "Mail-Copies-To" "Subject")
1943 (defun message-goto-newsgroups ()
1944 "Move point to the Newsgroups header."
1946 (message-position-on-field "Newsgroups"))
1948 (defun message-goto-distribution ()
1949 "Move point to the Distribution header."
1951 (message-position-on-field "Distribution"))
1953 (defun message-goto-followup-to ()
1954 "Move point to the Followup-To header."
1956 (message-position-on-field "Followup-To" "Newsgroups"))
1958 (defun message-goto-keywords ()
1959 "Move point to the Keywords header."
1961 (message-position-on-field "Keywords" "Subject"))
1963 (defun message-goto-summary ()
1964 "Move point to the Summary header."
1966 (message-position-on-field "Summary" "Subject"))
1968 (defun message-goto-body ()
1969 "Move point to the beginning of the message body."
1971 (if (looking-at "[ \t]*\n") (expand-abbrev))
1972 (goto-char (point-min))
1973 (or (search-forward (concat "\n" mail-header-separator "\n") nil t)
1974 (search-forward "\n\n" nil t)))
1976 (defun message-goto-eoh ()
1977 "Move point to the end of the headers."
1982 (defun message-goto-signature ()
1983 "Move point to the beginning of the message signature.
1984 If there is no signature in the article, go to the end and
1987 (goto-char (point-min))
1988 (if (re-search-forward message-signature-separator nil t)
1990 (goto-char (point-max))
1995 (defun message-insert-to (&optional force)
1996 "Insert a To header that points to the author of the article being replied to.
1997 If the original author requested not to be sent mail, the function signals
1999 With the prefix argument FORCE, insert the header anyway."
2001 (let ((co (message-fetch-reply-field "mail-copies-to")))
2002 (when (and (null force)
2004 (or (equal (downcase co) "never")
2005 (equal (downcase co) "nobody")))
2006 (error "The user has requested not to have copies sent via mail")))
2007 (when (and (message-position-on-field "To")
2008 (mail-fetch-field "to")
2009 (not (string-match "\\` *\\'" (mail-fetch-field "to"))))
2011 (insert (or (message-fetch-reply-field "reply-to")
2012 (message-fetch-reply-field "from") "")))
2014 (defun message-widen-reply ()
2015 "Widen the reply to include maximum recipients."
2018 (and message-reply-buffer
2019 (buffer-name message-reply-buffer)
2021 (set-buffer message-reply-buffer)
2022 (message-get-reply-headers t)))))
2025 (message-narrow-to-headers)
2026 (dolist (elem follow-to)
2027 (message-remove-header (symbol-name (car elem)))
2028 (goto-char (point-min))
2029 (insert (symbol-name (car elem)) ": "
2030 (cdr elem) "\n"))))))
2032 (defun message-insert-newsgroups ()
2033 "Insert the Newsgroups header from the article being replied to."
2035 (when (and (message-position-on-field "Newsgroups")
2036 (mail-fetch-field "newsgroups")
2037 (not (string-match "\\` *\\'" (mail-fetch-field "newsgroups"))))
2039 (insert (or (message-fetch-reply-field "newsgroups") "")))
2043 ;;; Various commands
2045 (defun message-delete-not-region (beg end)
2046 "Delete everything in the body of the current message that is outside of the region."
2050 (delete-region (point) (if (not (message-goto-signature))
2056 (delete-region beg (progn (message-goto-body)
2059 (when (message-goto-signature)
2062 (defun message-kill-to-signature ()
2063 "Deletes all text up to the signature."
2065 (let ((point (point)))
2066 (message-goto-signature)
2069 (kill-region point (point))
2073 (defun message-newline-and-reformat ()
2074 "Insert four newlines, and then reformat if inside quoted text."
2076 (let ((prefix "[]>»|:}+ \t]*")
2077 (supercite-thing "[-._a-zA-Z0-9]*[>]+[ \t]*")
2082 (when (looking-at (concat prefix
2084 (setq quoted (match-string 0))))
2086 (setq point (point))
2088 (delete-region (point) (re-search-forward "[ \t]*"))
2091 (fill-paragraph nil)
2095 (defun message-insert-signature (&optional force)
2096 "Insert a signature. See documentation for the `message-signature' variable."
2097 (interactive (list 0))
2100 ((and (null message-signature)
2103 (goto-char (point-max))
2104 (not (re-search-backward message-signature-separator nil t))))
2105 ((and (null message-signature)
2108 ((message-functionp message-signature)
2109 (funcall message-signature))
2110 ((listp message-signature)
2111 (eval message-signature))
2112 (t message-signature)))
2114 (cond ((stringp signature)
2116 ((and (eq t signature)
2117 message-signature-file
2118 (file-exists-p message-signature-file))
2121 (goto-char (point-max))
2122 ;; Insert the signature.
2126 (if (eq signature t)
2127 (insert-file-contents message-signature-file)
2129 (goto-char (point-max))
2130 (or (bolp) (insert "\n")))))
2132 (defun message-elide-region (b e)
2133 "Elide the text between point and mark.
2134 An ellipsis (from `message-elide-ellipsis') will be inserted where the
2138 (insert message-elide-ellipsis))
2140 (defvar message-caesar-translation-table nil)
2142 (defun message-caesar-region (b e &optional n)
2143 "Caesar rotation of region by N, default 13, for decrypting netnews."
2146 (min (point) (or (mark t) (point)))
2147 (max (point) (or (mark t) (point)))
2148 (when current-prefix-arg
2149 (prefix-numeric-value current-prefix-arg))))
2151 (setq n (if (numberp n) (mod n 26) 13)) ;canonize N
2152 (unless (or (zerop n) ; no action needed for a rot of 0
2153 (= b e)) ; no region to rotate
2154 ;; We build the table, if necessary.
2155 (when (or (not message-caesar-translation-table)
2156 (/= (aref message-caesar-translation-table ?a) (+ ?a n)))
2157 (setq message-caesar-translation-table
2158 (message-make-caesar-translation-table n)))
2159 (translate-region b e message-caesar-translation-table)))
2161 (defun message-make-caesar-translation-table (n)
2162 "Create a rot table with offset N."
2164 (table (make-string 256 0)))
2165 (while (< (incf i) 256)
2168 (substring table 0 ?A)
2169 (substring table (+ ?A n) (+ ?A n (- 26 n)))
2170 (substring table ?A (+ ?A n))
2171 (substring table (+ ?A 26) ?a)
2172 (substring table (+ ?a n) (+ ?a n (- 26 n)))
2173 (substring table ?a (+ ?a n))
2174 (substring table (+ ?a 26) 255))))
2176 (defun message-caesar-buffer-body (&optional rotnum)
2177 "Caesar rotates all letters in the current buffer by 13 places.
2178 Used to encode/decode possiblyun offensive messages (commonly in net.jokes).
2179 With prefix arg, specifies the number of places to rotate each letter forward.
2180 Mail and USENET news headers are not rotated."
2181 (interactive (if current-prefix-arg
2182 (list (prefix-numeric-value current-prefix-arg))
2186 (when (message-goto-body)
2187 (narrow-to-region (point) (point-max)))
2188 (message-caesar-region (point-min) (point-max) rotnum))))
2190 (defun message-pipe-buffer-body (program)
2191 "Pipe the message body in the current buffer through PROGRAM."
2194 (when (message-goto-body)
2195 (narrow-to-region (point) (point-max)))
2196 (shell-command-on-region
2197 (point-min) (point-max) program nil t))))
2199 (defun message-rename-buffer (&optional enter-string)
2200 "Rename the *message* buffer to \"*message* RECIPIENT\".
2201 If the function is run with a prefix, it will ask for a new buffer
2202 name, rather than giving an automatic name."
2203 (interactive "Pbuffer name: ")
2206 (goto-char (point-min))
2207 (narrow-to-region (point)
2208 (search-forward mail-header-separator nil 'end))
2210 (if (message-news-p) (message-fetch-field "Newsgroups")
2211 (message-fetch-field "To"))
2214 (if (string-match "," mail-to)
2215 (concat (substring mail-to 0 (match-beginning 0)) ", ...")
2217 (name-default (concat "*message* " mail-trimmed-to))
2218 (name (if enter-string
2219 (read-string "New buffer name: " name-default)
2221 (rename-buffer name t)))))
2223 (defun message-fill-yanked-message (&optional justifyp)
2224 "Fill the paragraphs of a message yanked into this one.
2225 Numeric argument means justify as well."
2228 (goto-char (point-min))
2229 (search-forward (concat "\n" mail-header-separator "\n") nil t)
2230 (let ((fill-prefix message-yank-prefix))
2231 (fill-individual-paragraphs (point) (point-max) justifyp))))
2233 (defun message-indent-citation ()
2234 "Modify text just inserted from a message to be cited.
2235 The inserted text should be the region.
2236 When this function returns, the region is again around the modified text.
2238 Normally, indent each nonblank line `message-indentation-spaces' spaces.
2239 However, if `message-yank-prefix' is non-nil, insert that prefix on each line."
2240 (let ((start (point)))
2241 ;; Remove unwanted headers.
2242 (when message-ignored-cited-headers
2247 (if (search-forward "\n\n" nil t)
2250 (message-remove-header message-ignored-cited-headers t)
2251 (when (= (point-min) (point-max))
2252 (setq all-removed t))
2253 (goto-char (point-max)))
2257 ;; Delete blank lines at the start of the buffer.
2258 (while (and (point-min)
2261 (message-delete-line))
2262 ;; Delete blank lines at the end of the buffer.
2263 (goto-char (point-max))
2266 (while (and (zerop (forward-line -1))
2268 (message-delete-line))
2269 ;; Do the indentation.
2270 (if (null message-yank-prefix)
2271 (indent-rigidly start (mark t) message-indentation-spaces)
2274 (while (< (point) (mark t))
2275 (insert message-yank-prefix)
2279 (defun message-list-references (refs-list &rest refs-strs)
2280 "Add `Message-ID's which appear in REFS-STRS but not in REFS-LIST,
2282 (let (refs ref id saved-id)
2283 (when (and refs-list
2284 (integerp message-list-references-add-position))
2285 (let ((pos message-list-references-add-position))
2286 (while (and refs-list
2288 (push (pop refs-list) saved-id)
2289 (setq pos (1- pos)))))
2291 (when (setq refs (pop refs-strs))
2292 (setq refs (std11-parse-msg-ids (std11-lexical-analyze refs)))
2294 (when (eq (car (setq ref (pop refs))) 'msg-id)
2295 (setq id (concat "<" (mapconcat 'cdr (cdr ref) "") ">"))
2296 (or (member id refs-list)
2297 (member id saved-id)
2298 (push id refs-list))))))
2300 (push (pop saved-id) refs-list))
2303 (defvar gnus-article-copy)
2304 (defun message-yank-original (&optional arg)
2305 "Insert the message being replied to, if any.
2306 Puts point before the text and mark after.
2307 Normally indents each nonblank line ARG spaces (default 3). However,
2308 if `message-yank-prefix' is non-nil, insert that prefix on each line.
2310 This function uses `message-cite-function' to do the actual citing.
2312 Just \\[universal-argument] as argument means don't indent, insert no
2313 prefix, and don't delete any headers.
2315 In addition, if `message-yank-add-new-references' is non-nil and this
2316 command is called interactively, new IDs from the yanked article will
2317 be added to \"References\" field.
2318 \(See also `message-yank-add-new-references'.)"
2320 (let ((modified (buffer-modified-p))
2321 (buffer (message-eval-parameter message-reply-buffer))
2324 message-cite-function)
2325 (delete-windows-on buffer t)
2326 (insert-buffer buffer) ; mark will be set at the end of article.
2330 ;; Add new IDs to References field.
2331 (when (and message-yank-add-new-references (interactive-p))
2334 (message-narrow-to-headers)
2335 (setq refs (message-list-references
2337 (message-fetch-field "References")))
2339 (narrow-to-region start end)
2340 (std11-narrow-to-header)
2341 (when (setq refs (message-list-references
2343 (unless (eq message-yank-add-new-references
2345 (or (message-fetch-field "References")
2346 (message-fetch-field "In-Reply-To")))
2347 (message-fetch-field "Message-ID")))
2349 (message-narrow-to-headers)
2350 (goto-char (point-min))
2351 (let ((case-fold-search t))
2352 (if (re-search-forward "^References:\\([\t ]+.+\n\\)+" nil t)
2354 (goto-char (point-max))))
2356 (list (or (assq 'References message-header-format-alist)
2357 '(References . message-fill-references)))
2358 (list (cons 'References
2359 (mapconcat 'identity (nreverse refs) " "))))
2360 (backward-delete-char 1)))))
2362 (funcall message-cite-function)
2363 (message-exchange-point-and-mark)
2367 (setq message-checksum (message-checksum))))))
2369 (defun message-yank-buffer (buffer)
2370 "Insert BUFFER into the current buffer and quote it."
2371 (interactive "bYank buffer: ")
2372 (let ((message-reply-buffer buffer))
2373 (save-window-excursion
2374 (message-yank-original))))
2376 (defun message-buffers ()
2377 "Return a list of active message buffers."
2380 (dolist (buffer (buffer-list t))
2382 (when (and (eq major-mode 'message-mode)
2383 (null message-sent-message-via))
2384 (push (buffer-name buffer) buffers))))
2385 (nreverse buffers)))
2387 (defun message-cite-original-without-signature ()
2388 "Cite function in the standard Message manner."
2389 (let ((start (point))
2392 (when message-indent-citation-function
2393 (if (listp message-indent-citation-function)
2394 message-indent-citation-function
2395 (list message-indent-citation-function)))))
2399 (when (re-search-backward message-signature-separator start t)
2400 ;; Also peel off any blank lines before the signature.
2402 (while (looking-at "^[ \t]*$")
2405 (delete-region (point) end))
2408 (funcall (pop functions)))
2409 (when message-citation-line-function
2412 (funcall message-citation-line-function))))
2414 (defvar mail-citation-hook) ;Compiler directive
2415 (defun message-cite-original ()
2416 "Cite function in the standard Message manner."
2417 (if (and (boundp 'mail-citation-hook)
2419 (run-hooks 'mail-citation-hook)
2420 (let ((start (point))
2423 (when message-indent-citation-function
2424 (if (listp message-indent-citation-function)
2425 message-indent-citation-function
2426 (list message-indent-citation-function))))
2427 (message-reply-headers (or message-reply-headers
2428 (make-mail-header))))
2429 (mail-header-set-from message-reply-headers
2433 (if (search-forward "\n\n" nil t)
2436 (or (message-fetch-field "from")
2440 (funcall (pop functions)))
2441 (when message-citation-line-function
2444 (funcall message-citation-line-function)))))
2446 (defun message-insert-citation-line ()
2447 "Function that inserts a simple citation line."
2448 (when message-reply-headers
2449 (insert (mail-header-from message-reply-headers) " writes:\n\n")))
2451 (defun message-position-on-field (header &rest afters)
2452 (let ((case-fold-search t))
2455 (goto-char (point-min))
2458 (concat "^" (regexp-quote mail-header-separator) "$"))
2459 (match-beginning 0)))
2460 (goto-char (point-min))
2461 (if (re-search-forward (concat "^" (regexp-quote header) ":") nil t)
2463 (re-search-forward "^[^ \t]" nil 'move)
2465 (skip-chars-backward "\n")
2468 (not (re-search-forward
2469 (concat "^" (regexp-quote (car afters)) ":")
2473 (re-search-forward "^[^ \t]" nil 'move)
2474 (beginning-of-line))
2475 (insert header ": \n")
2479 (defun message-remove-signature ()
2480 "Remove the signature from the text between point and mark.
2481 The text will also be indented the normal way."
2483 (let ((start (point))
2485 (if (not (re-search-forward message-signature-separator (mark t) t))
2486 ;; No signature here, so we just indent the cited text.
2487 (message-indent-citation)
2488 ;; Find the last non-empty line.
2490 (while (looking-at "[ \t]*$")
2493 (setq mark (set-marker (make-marker) (point)))
2495 (message-indent-citation)
2496 ;; Enable undoing the deletion.
2498 (delete-region mark (mark t))
2499 (set-marker mark nil)))))
2504 ;;; Sending messages
2507 ;; Avoid byte-compile warning.
2508 (defvar message-encoding-buffer nil)
2509 (defvar message-edit-buffer nil)
2510 (defvar message-mime-mode nil)
2512 (defun message-send-and-exit (&optional arg)
2513 "Send message like `message-send', then, if no errors, exit from mail buffer."
2515 (let ((buf (current-buffer))
2516 (actions message-exit-actions)
2517 (frame (selected-frame))
2518 (org-frame message-original-frame))
2519 (when (and (message-send arg)
2521 (if message-kill-buffer-on-exit
2524 (when (eq buf (current-buffer))
2525 (message-bury buf)))
2526 (message-do-actions actions)
2527 (message-delete-frame frame org-frame)
2530 (defun message-dont-send ()
2531 "Don't send the message you have been editing."
2533 (message-save-drafts)
2534 (let ((actions message-postpone-actions)
2535 (frame (selected-frame))
2536 (org-frame message-original-frame))
2537 (message-bury (current-buffer))
2538 (message-do-actions actions)
2539 (message-delete-frame frame org-frame)))
2541 (defun message-kill-buffer ()
2542 "Kill the current buffer."
2544 (when (or (not (buffer-modified-p))
2545 (eq t message-kill-buffer-query-function)
2546 (funcall message-kill-buffer-query-function
2547 "The buffer modified; kill anyway? "))
2548 (let ((actions message-kill-actions)
2549 (frame (selected-frame))
2550 (org-frame message-original-frame))
2551 (setq buffer-file-name nil)
2552 (kill-buffer (current-buffer))
2553 (message-do-actions actions)
2554 (message-delete-frame frame org-frame)))
2557 (defun message-mimic-kill-buffer ()
2558 "Kill the current buffer with query."
2560 (unless (eq 'message-mode major-mode)
2561 (error "%s must be invoked from a message buffer." this-command))
2562 (let ((command this-command)
2563 (bufname (read-buffer (format "Kill buffer: (default %s) "
2565 (if (or (not bufname)
2566 (string-equal bufname "")
2567 (string-equal bufname (buffer-name)))
2568 (message-kill-buffer)
2569 (message "%s must be invoked only for the current buffer." command))))
2571 (defun message-delete-frame (frame org-frame)
2572 "Delete frame for editing message."
2573 (when (and (or (static-if (featurep 'xemacs)
2574 (device-on-window-system-p)
2576 (>= emacs-major-version 20))
2577 (or (and (eq message-delete-frame-on-exit t)
2578 (select-frame frame)
2579 (or (eq frame org-frame)
2581 (y-or-n-p "Delete this frame?")
2583 (and (eq message-delete-frame-on-exit 'ask)
2584 (select-frame frame)
2586 (y-or-n-p "Delete this frame?")
2588 (delete-frame frame)))
2590 (defun message-bury (buffer)
2591 "Bury this mail buffer."
2592 (let ((newbuf (other-buffer buffer)))
2593 (bury-buffer buffer)
2594 (if (and (fboundp 'frame-parameters)
2595 (cdr (assq 'dedicated (frame-parameters)))
2596 (not (null (delq (selected-frame) (visible-frame-list)))))
2597 (delete-frame (selected-frame))
2598 (switch-to-buffer newbuf))))
2600 (defun message-send (&optional arg)
2601 "Send the message in the current buffer.
2602 If `message-interactive' is non-nil, wait for success indication or
2603 error messages, and inform user.
2604 Otherwise any failure is reported in a message back to the user from
2606 The usage of ARG is defined by the instance that called Message.
2607 It should typically alter the sending method in some way or other."
2610 (when (or (buffer-modified-p)
2611 (message-check-element 'unchanged)
2612 (y-or-n-p "No changes in the buffer; really send? "))
2613 ;; Make it possible to undo the coming changes.
2615 (let ((inhibit-read-only t))
2616 (put-text-property (point-min) (point-max) 'read-only nil))
2617 (run-hooks 'message-send-hook)
2618 (message "Sending...")
2619 (let ((message-encoding-buffer
2620 (message-generate-new-buffer-clone-locals " message encoding"))
2621 (message-edit-buffer (current-buffer))
2622 (message-mime-mode mime-edit-mode-flag)
2623 (alist message-send-method-alist)
2627 (set-buffer message-encoding-buffer)
2629 (insert-buffer message-edit-buffer)
2630 (funcall message-encode-function)
2631 (message-fix-before-sending)
2633 (setq elem (pop alist)))
2634 (when (or (not (funcall (cadr elem)))
2635 (and (or (not (memq (car elem)
2636 message-sent-message-via))
2639 "Already sent message via %s; resend? "
2641 (setq success (funcall (caddr elem) arg))))
2643 (unless (or sent (not success))
2644 (error "No methods specified to send by"))
2646 (when (and success sent)
2649 (run-hooks 'message-sent-hook))
2650 (message "Sending...done")
2651 ;; Mark the buffer as unmodified and delete autosave.
2652 (set-buffer-modified-p nil)
2653 (delete-auto-save-file-if-necessary t)
2654 (message-disassociate-draft)
2655 ;; Delete other mail buffers and stuff.
2656 (message-do-send-housekeeping)
2657 (message-do-actions message-send-actions)
2660 (kill-buffer message-encoding-buffer)))))
2662 (defun message-send-via-mail (arg)
2663 "Send the current message via mail."
2664 (message-send-mail arg))
2666 (defun message-send-via-news (arg)
2667 "Send the current message via news."
2668 (message-send-news arg))
2670 (defmacro message-check (type &rest forms)
2671 "Eval FORMS if TYPE is to be checked."
2672 `(or (message-check-element ,type)
2676 (put 'message-check 'lisp-indent-function 1)
2677 (put 'message-check 'edebug-form-spec '(form body))
2679 (defun message-fix-before-sending ()
2680 "Do various things to make the message nice before sending it."
2681 ;; Make sure there's a newline at the end of the message.
2682 (goto-char (point-max))
2685 ;; Delete all invisible text.
2686 (message-check 'invisible-text
2687 (when (text-property-any (point-min) (point-max) 'invisible t)
2688 (put-text-property (point-min) (point-max) 'invisible nil)
2689 (unless (yes-or-no-p
2690 "Invisible text found and made visible; continue posting? ")
2691 (error "Invisible text found and made visible")))))
2693 (defun message-add-action (action &rest types)
2694 "Add ACTION to be performed when doing an exit of type TYPES."
2697 (set (setq var (intern (format "message-%s-actions" (pop types))))
2698 (nconc (symbol-value var) (list action))))))
2700 (defun message-do-actions (actions)
2701 "Perform all actions in ACTIONS."
2702 ;; Now perform actions on successful sending.
2706 ;; A simple function.
2707 ((message-functionp (car actions))
2708 (funcall (car actions)))
2709 ;; Something to be evaled.
2711 (eval (car actions)))))
2714 (defsubst message-maybe-split-and-send-mail ()
2715 "Split a message if necessary, and send it via mail.
2716 Returns nil if sending succeeded, returns any string if sending failed.
2717 This sub function is for exclusive use of `message-send-mail'."
2718 (let ((mime-edit-split-ignored-field-regexp
2719 mime-edit-split-ignored-field-regexp)
2720 (case-fold-search t)
2722 (while (string-match "Message-ID" mime-edit-split-ignored-field-regexp)
2723 (setq mime-edit-split-ignored-field-regexp
2724 (concat (substring mime-edit-split-ignored-field-regexp
2725 0 (match-beginning 0))
2726 "Hey_MIME-Edit,_there_is_an_inviolable_Message_ID"
2727 "_so_don't_rape_it!"
2728 (substring mime-edit-split-ignored-field-regexp
2732 (catch 'message-sending-mail-failure
2733 (mime-edit-maybe-split-and-send
2738 (std11-narrow-to-header mail-header-separator)
2739 (goto-char (point-min))
2740 (when (re-search-forward "^Message-ID:" nil t)
2741 (delete-region (match-end 0) (std11-field-end))
2742 (insert " " (message-make-message-id))))
2744 (funcall message-send-mail-function)
2746 (throw 'message-sending-mail-failure err))))))
2750 (funcall message-send-mail-function)
2754 (if (eq 'error (car failure))
2756 (prin1-to-string failure)))))
2758 (defun message-send-mail-partially ()
2759 "Sendmail as message/partial."
2760 (let ((p (goto-char (point-min)))
2761 (tembuf (message-generate-new-buffer-clone-locals " message temp"))
2762 (curbuf (current-buffer))
2763 (id (message-make-message-id)) (n 1)
2764 plist total header required-mail-headers)
2766 (if (< (point-max) (+ p message-send-mail-partially-limit))
2767 (goto-char (point-max))
2768 (goto-char (+ p message-send-mail-partially-limit))
2770 (if (<= (point) p) (forward-line 1))) ;; In case of bad message.
2773 (setq total (length plist))
2774 (push (point-max) plist)
2775 (setq plist (nreverse plist))
2778 (setq p (pop plist))
2781 (copy-to-buffer tembuf p (car plist))
2783 (goto-char (point-min))
2786 (goto-char (point-min))
2787 (narrow-to-region (point) (point))
2790 (setq header (buffer-substring (point-min) (point)))
2791 (goto-char (point-min))
2792 (narrow-to-region (point) (point))
2794 (message-remove-header "Mime-Version")
2795 (message-remove-header "Content-Type")
2796 (message-remove-header "Content-Transfer-Encoding")
2797 (message-remove-header "Message-ID")
2798 (message-remove-header "Lines")
2799 (goto-char (point-max))
2800 (insert "Mime-Version: 1.0\n")
2801 (setq header (buffer-substring (point-min) (point-max))))
2802 (goto-char (point-max))
2803 (insert (format "Content-Type: message/partial; id=\"%s\"; number=%d; total=%d\n"
2805 (let ((mail-header-separator ""))
2806 (when (memq 'Message-ID message-required-mail-headers)
2807 (insert "Message-ID: " (message-make-message-id) "\n"))
2808 (when (memq 'Lines message-required-mail-headers)
2809 (let ((mail-header-separator ""))
2810 (insert "Lines: " (message-make-lines) "\n")))
2811 (message-goto-subject)
2813 (insert (format " (%d/%d)" n total))
2814 (goto-char (point-max))
2817 (funcall message-send-mail-function))
2819 (setq p (pop plist))
2821 (kill-buffer tembuf))))
2823 (defun message-send-mail (&optional arg)
2824 (require 'mail-utils)
2825 (let* ((tembuf (message-generate-new-buffer-clone-locals " message temp"))
2826 (case-fold-search nil)
2827 (news (message-news-p))
2828 (message-this-is-mail t)
2831 (message-narrow-to-headers)
2832 ;; Insert some headers.
2833 (let ((message-deletable-headers
2834 (if news nil message-deletable-headers)))
2835 (message-generate-headers message-required-mail-headers))
2836 ;; Let the user do all of the above.
2837 (run-hooks 'message-header-hook))
2838 (if (not (message-check-mail-syntax))
2846 (insert-buffer message-encoding-buffer)
2847 ;; Remove some headers.
2849 (message-narrow-to-headers)
2850 ;; We Semi-gnus people have no use for it.
2851 ;; ;; We (re)generate the Lines header.
2852 ;; (when (memq 'Lines message-required-mail-headers)
2853 ;; (message-generate-headers '(Lines)))
2854 ;; Remove some headers.
2855 (message-remove-header message-ignored-mail-headers t))
2856 (goto-char (point-max))
2857 ;; require one newline at the end.
2858 (or (= (preceding-char) ?\n)
2861 (or (message-fetch-field "cc")
2862 (message-fetch-field "to")))
2863 (message-insert-courtesy-copy))
2864 (setq failure (message-maybe-split-and-send-mail)))
2865 (kill-buffer tembuf))
2866 (set-buffer message-edit-buffer)
2869 (message "Couldn't send message via mail: %s" failure)
2871 (push 'mail message-sent-message-via)))))
2873 (defun message-send-mail-with-sendmail ()
2874 "Send off the prepared buffer with sendmail."
2875 (let ((errbuf (if message-interactive
2876 (message-generate-new-buffer-clone-locals
2879 resend-to-addresses delimline)
2880 (let ((case-fold-search t))
2882 (message-narrow-to-headers)
2883 (setq resend-to-addresses (message-fetch-field "resent-to")))
2884 ;; Change header-delimiter to be what sendmail expects.
2885 (goto-char (point-min))
2887 (concat "^" (regexp-quote mail-header-separator) "\n"))
2888 (replace-match "\n")
2890 (setq delimline (point-marker))
2891 (run-hooks 'message-send-mail-hook)
2892 ;; Insert an extra newline if we need it to work around
2893 ;; Sun's bug that swallows newlines.
2894 (goto-char (1+ delimline))
2895 (when (eval message-mailer-swallows-blank-line)
2897 (when message-interactive
2901 (let ((default-directory "/"))
2903 (apply 'call-process-region
2904 (append (list (point-min) (point-max)
2905 (if (boundp 'sendmail-program)
2907 "/usr/lib/sendmail")
2908 nil errbuf nil "-oi")
2909 ;; Always specify who from,
2910 ;; since some systems have broken sendmails.
2911 ;; But some systems are more broken with -f, so
2912 ;; we'll let users override this.
2913 (if (null message-sendmail-f-is-evil)
2914 (list "-f" (message-make-address)))
2915 ;; These mean "report errors by mail"
2916 ;; and "deliver in background".
2917 (if (null message-interactive) '("-oem" "-odb"))
2918 ;; Get the addresses from the message
2919 ;; unless this is a resend.
2920 ;; We must not do that for a resend
2921 ;; because we would find the original addresses.
2922 ;; For a resend, include the specific addresses.
2923 (if resend-to-addresses
2924 (list resend-to-addresses)
2926 (when message-interactive
2929 (goto-char (point-min))
2930 (while (re-search-forward "\n\n* *" nil t)
2931 (replace-match "; "))
2932 (if (not (zerop (buffer-size)))
2933 (error "Sending...failed to %s"
2934 (buffer-substring (point-min) (point-max)))))
2935 (when (bufferp errbuf)
2936 (kill-buffer errbuf)))))
2938 (defun message-send-mail-with-qmail ()
2939 "Pass the prepared message buffer to qmail-inject.
2940 Refer to the documentation for the variable `message-send-mail-function'
2941 to find out how to use this."
2942 ;; replace the header delimiter with a blank line
2943 (goto-char (point-min))
2945 (concat "^" (regexp-quote mail-header-separator) "\n"))
2946 (replace-match "\n")
2948 (run-hooks 'message-send-mail-hook)
2953 'call-process-region 1 (point-max) message-qmail-inject-program
2955 ;; qmail-inject's default behaviour is to look for addresses on the
2956 ;; command line; if there're none, it scans the headers.
2957 ;; yes, it does The Right Thing w.r.t. Resent-To and it's kin.
2959 ;; in general, ALL of qmail-inject's defaults are perfect for simply
2960 ;; reading a formatted (i. e., at least a To: or Resent-To header)
2961 ;; message from stdin.
2963 ;; qmail also has the advantage of not having been raped by
2964 ;; various vendors, so we don't have to allow for that, either --
2965 ;; compare this with message-send-mail-with-sendmail and weep
2966 ;; for sendmail's lost innocence.
2968 ;; all this is way cool coz it lets us keep the arguments entirely
2969 ;; free for -inject-arguments -- a big win for the user and for us
2970 ;; since we don't have to play that double-guessing game and the user
2971 ;; gets full control (no gestapo'ish -f's, for instance). --sj
2972 message-qmail-inject-args))
2973 ;; qmail-inject doesn't say anything on it's stdout/stderr,
2974 ;; we have to look at the retval instead
2976 (1 (error "qmail-inject reported permanent failure"))
2977 (111 (error "qmail-inject reported transient failure"))
2978 ;; should never happen
2979 (t (error "qmail-inject reported unknown failure"))))
2981 (defun message-send-mail-with-mh ()
2982 "Send the prepared message buffer with mh."
2983 (let ((mh-previous-window-config nil)
2984 (name (mh-new-draft-name)))
2985 (setq buffer-file-name name)
2986 ;; MH wants to generate these headers itself.
2987 (when message-mh-deletable-headers
2988 (let ((headers message-mh-deletable-headers))
2990 (goto-char (point-min))
2991 (and (re-search-forward
2992 (concat "^" (symbol-name (car headers)) ": *") nil t)
2993 (message-delete-line))
2995 (run-hooks 'message-send-mail-hook)
2996 ;; Pass it on to mh.
2999 (defun message-send-mail-with-smtp ()
3000 "Send off the prepared buffer with SMTP."
3001 (require 'smtp) ; XXX
3002 (let ((case-fold-search t)
3005 (message-narrow-to-headers)
3007 ;; XXX: Should be replaced by better one.
3008 (smtp-deduce-address-list (current-buffer)
3009 (point-min) (point-max)))
3010 ;; Remove BCC lines.
3011 (message-remove-header "bcc"))
3012 ;; replace the header delimiter with a blank line.
3013 (goto-char (point-min))
3015 (concat "^" (regexp-quote mail-header-separator) "\n"))
3016 (replace-match "\n")
3018 (run-hooks 'message-send-mail-hook)
3020 (let ((result (smtp-via-smtp user-mail-address
3023 (unless (eq result t)
3024 (error "Sending failed; " result)))
3025 (error "Sending failed; no recipients"))))
3027 (defsubst message-maybe-split-and-send-news (method)
3028 "Split a message if necessary, and send it via news.
3029 Returns nil if sending succeeded, returns t if sending failed.
3030 This sub function is for exclusive use of `message-send-news'."
3031 (let ((mime-edit-split-ignored-field-regexp
3032 mime-edit-split-ignored-field-regexp)
3033 (case-fold-search t))
3034 (while (string-match "Message-ID" mime-edit-split-ignored-field-regexp)
3035 (setq mime-edit-split-ignored-field-regexp
3036 (concat (substring mime-edit-split-ignored-field-regexp
3037 0 (match-beginning 0))
3038 "Hey_MIME-Edit,_there_is_an_inviolable_Message_ID"
3039 "_so_don't_rape_it!"
3040 (substring mime-edit-split-ignored-field-regexp
3043 (catch 'message-sending-news-failure
3044 (mime-edit-maybe-split-and-send
3049 (std11-narrow-to-header mail-header-separator)
3050 (goto-char (point-min))
3051 (when (re-search-forward "^Message-ID:" nil t)
3052 (delete-region (match-end 0) (std11-field-end))
3053 (insert " " (message-make-message-id))))
3054 (unless (funcall message-send-news-function method)
3055 (throw 'message-sending-news-failure t)))))
3057 (not (funcall message-send-news-function method)))))
3059 (defun message-send-news (&optional arg)
3060 (let* ((tembuf (message-generate-new-buffer-clone-locals " *message temp*"))
3061 (case-fold-search nil)
3062 (method (if (message-functionp message-post-method)
3063 (funcall message-post-method arg)
3064 message-post-method))
3065 (message-syntax-checks
3067 (cons '(existing-newsgroups . disabled)
3068 message-syntax-checks)
3069 message-syntax-checks))
3070 (message-this-is-news t)
3073 (message-narrow-to-headers)
3074 ;; Insert some headers.
3075 (message-generate-headers message-required-news-headers)
3076 ;; Let the user do all of the above.
3077 (run-hooks 'message-header-hook))
3078 (message-cleanup-headers)
3079 (if (not (message-check-news-syntax))
3084 (buffer-disable-undo)
3086 (insert-buffer message-encoding-buffer)
3087 ;; Remove some headers.
3089 (message-narrow-to-headers)
3090 ;; We Semi-gnus people have no use for it.
3091 ;; ;; We (re)generate the Lines header.
3092 ;; (when (memq 'Lines message-required-mail-headers)
3093 ;; (message-generate-headers '(Lines)))
3094 ;; Remove some headers.
3095 (message-remove-header message-ignored-news-headers t))
3096 (goto-char (point-max))
3097 ;; require one newline at the end.
3098 (or (= (preceding-char) ?\n)
3100 (setq result (message-maybe-split-and-send-news method)))
3101 (kill-buffer tembuf))
3102 (set-buffer message-edit-buffer)
3105 (message "Couldn't send message via news: %s"
3106 (nnheader-get-report (car method)))
3108 (push 'news message-sent-message-via)))))
3110 ;; 1997-09-29 by MORIOKA Tomohiko
3111 (defun message-send-news-with-gnus (method)
3112 (let ((case-fold-search t))
3113 ;; Remove the delimiter.
3114 (goto-char (point-min))
3116 (concat "^" (regexp-quote mail-header-separator) "\n"))
3117 (replace-match "\n")
3119 (run-hooks 'message-send-news-hook)
3120 (gnus-open-server method)
3121 (gnus-request-post method)
3125 ;;; Header generation & syntax checking.
3128 (defun message-check-element (type)
3129 "Returns non-nil if this type is not to be checked."
3130 (if (eq message-syntax-checks 'dont-check-for-anything-just-trust-me)
3132 (let ((able (assq type message-syntax-checks)))
3134 (eq (cdr able) 'disabled)))))
3136 (defun message-check-news-syntax ()
3137 "Check the syntax of the message."
3142 ;; We narrow to the headers and check them first.
3145 (message-narrow-to-headers)
3146 (message-check-news-header-syntax)))
3149 (set-buffer message-edit-buffer)
3150 (message-check-news-body-syntax))))))
3152 (defun message-check-news-header-syntax ()
3154 ;; Check Newsgroups header.
3155 (message-check 'newsgroups
3156 (let ((group (message-fetch-field "newsgroups")))
3159 (not (string-match "\\`[ \t]*\\'" group)))
3162 "The newsgroups field is empty or missing. Posting is denied.")))))
3163 ;; Check the Subject header.
3164 (message-check 'subject
3165 (let* ((case-fold-search t)
3166 (subject (message-fetch-field "subject")))
3169 (not (string-match "\\`[ \t]*\\'" subject)))
3172 "The subject field is empty or missing. Posting is denied.")))))
3173 ;; Check for commands in Subject.
3174 (message-check 'subject-cmsg
3175 (if (string-match "^cmsg " (message-fetch-field "subject"))
3177 "The control code \"cmsg\" is in the subject. Really post? ")
3179 ;; Check for multiple identical headers.
3180 (message-check 'multiple-headers
3182 (while (and (not found)
3183 (re-search-forward "^[^ \t:]+: " nil t))
3185 (or (re-search-forward
3190 (match-beginning 0) (- (match-end 0) 2))))
3195 (y-or-n-p (format "Multiple %s headers. Really post? " found))
3197 ;; Check for Version and Sendsys.
3198 (message-check 'sendsys
3199 (if (re-search-forward "^Sendsys:\\|^Version:" nil t)
3201 (format "The article contains a %s command. Really post? "
3202 (buffer-substring (match-beginning 0)
3203 (1- (match-end 0)))))
3205 ;; See whether we can shorten Followup-To.
3206 (message-check 'shorten-followup-to
3207 (let ((newsgroups (message-fetch-field "newsgroups"))
3208 (followup-to (message-fetch-field "followup-to"))
3210 (when (and newsgroups
3211 (string-match "," newsgroups)
3216 (setq to (completing-read
3217 "Followups to: (default all groups) "
3218 (mapcar (lambda (g) (list g))
3220 (message-tokenize-header
3222 (goto-char (point-min))
3223 (insert "Followup-To: " to "\n"))
3225 ;; Check "Shoot me".
3226 (message-check 'shoot
3227 (if (re-search-forward
3228 "Message-ID.*.i-did-not-set--mail-host-address--so-shoot-me" nil t)
3229 (y-or-n-p "You appear to have a misconfigured system. Really post? ")
3231 ;; Check for Approved.
3232 (message-check 'approved
3233 (if (re-search-forward "^Approved:" nil t)
3234 (y-or-n-p "The article contains an Approved header. Really post? ")
3236 ;; Check the Message-ID header.
3237 (message-check 'message-id
3238 (let* ((case-fold-search t)
3239 (message-id (message-fetch-field "message-id" t)))
3240 (or (not message-id)
3241 ;; Is there an @ in the ID?
3242 (and (string-match "@" message-id)
3243 ;; Is there a dot in the ID?
3244 (string-match "@[^.]*\\." message-id)
3245 ;; Does the ID end with a dot?
3246 (not (string-match "\\.>" message-id)))
3248 (format "The Message-ID looks strange: \"%s\". Really post? "
3250 ;; Check the Newsgroups & Followup-To headers.
3251 (message-check 'existing-newsgroups
3252 (let* ((case-fold-search t)
3253 (newsgroups (message-fetch-field "newsgroups"))
3254 (followup-to (message-fetch-field "followup-to"))
3255 (groups (message-tokenize-header
3257 (concat newsgroups "," followup-to)
3259 (hashtb (and (boundp 'gnus-active-hashtb)
3260 gnus-active-hashtb))
3262 (if (or (not hashtb)
3263 (not (boundp 'gnus-read-active-file))
3264 (not gnus-read-active-file)
3265 (eq gnus-read-active-file 'some))
3268 (when (and (not (boundp (intern (car groups) hashtb)))
3269 (not (equal (car groups) "poster")))
3270 (push (car groups) errors))
3276 "Really post to %s unknown group%s: %s "
3277 (if (= (length errors) 1) "this" "these")
3278 (if (= (length errors) 1) "" "s")
3279 (mapconcat 'identity errors ", ")))))))
3280 ;; Check the Newsgroups & Followup-To headers for syntax errors.
3281 (message-check 'valid-newsgroups
3282 (let ((case-fold-search t)
3283 (headers '("Newsgroups" "Followup-To"))
3285 (while (and headers (not error))
3286 (when (setq header (mail-fetch-field (car headers)))
3290 "\\`\\([-+_&.a-zA-Z0-9]+\\)?\\(,[-+_&.a-zA-Z0-9]+\\)*\\'"
3295 (not (string-match "\\.\\'\\|\\.\\." g)))
3296 (message-tokenize-header header ","))))
3303 (format "The %s header looks odd: \"%s\". Really post? "
3304 (car headers) header)))))
3305 (message-check 'repeated-newsgroups
3306 (let ((case-fold-search t)
3307 (headers '("Newsgroups" "Followup-To"))
3308 header error groups group)
3311 (when (setq header (mail-fetch-field (pop headers)))
3312 (setq groups (message-tokenize-header header ","))
3313 (while (setq group (pop groups))
3314 (when (member group groups)
3320 (format "Group %s is repeated in headers. Really post? " error)))))
3321 ;; Check the From header.
3322 (message-check 'from
3323 (let* ((case-fold-search t)
3324 (from (message-fetch-field "from"))
3328 (message "There is no From line. Posting is denied.")
3330 ((or (not (string-match
3332 (setq ad (nth 1 (mail-extract-address-components
3333 from))))) ;larsi@ifi
3334 (string-match "\\.\\." ad) ;larsi@ifi..uio
3335 (string-match "@\\." ad) ;larsi@.ifi.uio
3336 (string-match "\\.$" ad) ;larsi@ifi.uio.
3337 (not (string-match "^[^@]+@[^@]+$" ad)) ;larsi.ifi.uio
3338 (string-match "(.*).*(.*)" from)) ;(lars) (lars)
3340 "Denied posting -- the From looks strange: \"%s\"." from)
3344 (defun message-check-news-body-syntax ()
3346 ;; Check for long lines.
3347 (message-check 'long-lines
3348 (goto-char (point-min))
3350 (concat "^" (regexp-quote mail-header-separator) "$"))
3354 (< (current-column) 80))
3355 (zerop (forward-line 1))))
3359 "You have lines longer than 79 characters. Really post? ")))
3360 ;; Check whether the article is empty.
3361 (message-check 'empty
3362 (goto-char (point-min))
3364 (concat "^" (regexp-quote mail-header-separator) "$"))
3367 (goto-char (point-max))
3368 (re-search-backward message-signature-separator nil t)
3370 (or (re-search-backward "[^ \n\t]" b t)
3371 (y-or-n-p "Empty article. Really post? "))))
3372 ;; Check for control characters.
3373 (message-check 'control-chars
3374 (if (re-search-forward "[\000-\007\013\015-\032\034-\037\200-\237]" nil t)
3376 "The article contains control characters. Really post? ")
3378 ;; Check 8bit characters.
3379 (message-check '8bit
3380 (message-check-8bit))
3381 ;; Check excessive size.
3382 (message-check 'size
3383 (if (> (buffer-size) 60000)
3385 (format "The article is %d octets long. Really post? "
3388 ;; Check whether any new text has been added.
3389 (message-check 'new-text
3391 (not message-checksum)
3392 (not (eq (message-checksum) message-checksum))
3394 "It looks like no new text has been added. Really post? ")))
3395 ;; Check the length of the signature.
3396 (message-check 'signature
3397 (goto-char (point-max))
3398 (if (> (count-lines (point) (point-max)) 5)
3401 "Your .sig is %d lines; it should be max 4. Really post? "
3402 (1- (count-lines (point) (point-max)))))
3405 (defun message-check-mail-syntax ()
3406 "Check the syntax of the message."
3411 ;; We narrow to the headers and check them first.
3414 (message-narrow-to-headers)
3415 (message-check-mail-header-syntax)))
3418 (set-buffer message-edit-buffer)
3419 (message-check-mail-body-syntax))))))
3421 (defun message-check-mail-header-syntax ()
3424 (defun message-check-mail-body-syntax ()
3426 ;; Check 8bit characters.
3427 (message-check '8bit
3428 (message-check-8bit)
3431 (defun message-check-8bit ()
3432 "Check the article contains 8bit characters."
3434 (set-buffer message-encoding-buffer)
3435 (message-narrow-to-headers)
3436 (let* ((case-fold-search t)
3437 (field-value (message-fetch-field "content-transfer-encoding")))
3438 (if (and field-value
3439 (member (downcase field-value) message-8bit-encoding-list))
3442 (set-buffer (get-buffer-create " message syntax"))
3444 (goto-char (point-min))
3445 (set-buffer-multibyte nil)
3446 (insert-buffer message-encoding-buffer)
3447 (goto-char (point-min))
3448 (if (re-search-forward "[^\x00-\x7f]" nil t)
3450 "The article contains 8bit characters. Really post? ")
3453 (defun message-checksum ()
3454 "Return a \"checksum\" for the current buffer."
3457 (goto-char (point-min))
3459 (concat "^" (regexp-quote mail-header-separator) "$"))
3461 (when (not (looking-at "[ \t\n]"))
3462 (setq sum (logxor (ash sum 1) (if (natnump sum) 0 1)
3467 (defun message-do-fcc ()
3468 "Process Fcc headers in the current buffer."
3469 (let ((case-fold-search t)
3470 (coding-system-for-write 'raw-text)
3471 (output-coding-system 'raw-text)
3474 (set-buffer (get-buffer-create " *message temp*"))
3476 (insert-buffer-substring message-encoding-buffer)
3478 (message-narrow-to-headers)
3479 (while (setq file (message-fetch-field "fcc"))
3481 (message-remove-header "fcc" nil t)))
3482 (goto-char (point-min))
3483 (re-search-forward (concat "^" (regexp-quote mail-header-separator) "$"))
3484 (replace-match "" t t)
3485 ;; Process FCC operations.
3487 (setq file (pop list))
3488 (if (string-match "^[ \t]*|[ \t]*\\(.*\\)[ \t]*$" file)
3489 ;; Pipe the article to the program in question.
3490 (call-process-region (point-min) (point-max) shell-file-name
3491 nil nil nil shell-command-switch
3492 (match-string 1 file))
3493 ;; Save the article.
3494 (setq file (expand-file-name file))
3495 (unless (file-exists-p (file-name-directory file))
3496 (make-directory (file-name-directory file) t))
3497 (if (and message-fcc-handler-function
3498 (not (eq message-fcc-handler-function 'rmail-output)))
3499 (funcall message-fcc-handler-function file)
3500 (if (and (file-readable-p file) (mail-file-babyl-p file))
3501 (rmail-output file 1 nil t)
3502 (let ((mail-use-rfc822 t))
3503 (rmail-output file 1 t t))))))
3504 (kill-buffer (current-buffer)))))
3506 (defun message-output (filename)
3507 "Append this article to Unix/babyl mail file.."
3508 (if (and (file-readable-p filename)
3509 (mail-file-babyl-p filename))
3510 (rmail-output-to-rmail-file filename t)
3511 (gnus-output-to-mail filename t)))
3513 (defun message-cleanup-headers ()
3514 "Do various automatic cleanups of the headers."
3515 ;; Remove empty lines in the header.
3517 (message-narrow-to-headers)
3518 ;; Remove blank lines.
3519 (while (re-search-forward "^[ \t]*\n" nil t)
3520 (replace-match "" t t))
3522 ;; Correct Newsgroups and Followup-To headers: Change sequence of
3523 ;; spaces to comma and eliminate spaces around commas. Eliminate
3524 ;; embedded line breaks.
3525 (goto-char (point-min))
3526 (while (re-search-forward "^\\(Newsgroups\\|Followup-To\\): +" nil t)
3530 (if (re-search-forward "^[^ \t]" nil t)
3534 (goto-char (point-min))
3535 (while (re-search-forward "\n[ \t]+" nil t)
3536 (replace-match " " t t)) ;No line breaks (too confusing)
3537 (goto-char (point-min))
3538 (while (re-search-forward "[ \t\n]*,[ \t\n]*\\|[ \t]+" nil t)
3539 (replace-match "," t t))
3540 (goto-char (point-min))
3541 ;; Remove trailing commas.
3542 (when (re-search-forward ",+$" nil t)
3543 (replace-match "" t t))))))
3545 (defun message-make-date (&optional now)
3546 "Make a valid data header.
3547 If NOW, use that time instead."
3548 (let* ((now (or now (current-time)))
3549 (zone (nth 8 (decode-time now)))
3553 (setq zone (- zone)))
3555 (format-time-string "%d" now)
3556 ;; The month name of the %b spec is locale-specific. Pfff.
3558 (capitalize (car (rassoc (nth 4 (decode-time now))
3559 parse-time-months))))
3560 (format-time-string "%Y %H:%M:%S " now)
3561 ;; We do all of this because XEmacs doesn't have the %z spec.
3562 (format "%s%02d%02d" sign (/ zone 3600) (/ (% zone 3600) 60)))))
3564 (defun message-make-followup-subject (subject)
3565 "Make a followup Subject."
3567 ((and (eq message-use-subject-re 'guess)
3568 (string-match message-subject-encoded-re-regexp subject))
3570 (message-use-subject-re
3571 (concat "Re: " (message-strip-subject-re subject)))
3574 (defun message-make-message-id ()
3575 "Make a unique Message-ID."
3576 (concat "<" (message-unique-id)
3577 (let ((psubject (save-excursion (message-fetch-field "subject")))
3579 (save-excursion (message-fetch-field "supersedes"))))
3581 (and message-reply-headers
3582 (mail-header-references message-reply-headers)
3583 (mail-header-subject message-reply-headers)
3585 (mail-header-subject message-reply-headers)
3587 (message-strip-subject-re
3588 (mail-header-subject message-reply-headers))
3589 (message-strip-subject-re psubject))))
3591 (string-match "_-_@" psupersedes)))
3593 "@" (message-make-fqdn) ">"))
3595 (defvar message-unique-id-char nil)
3597 ;; If you ever change this function, make sure the new version
3598 ;; cannot generate IDs that the old version could.
3599 ;; You might for example insert a "." somewhere (not next to another dot
3600 ;; or string boundary), or modify the "fsf" string.
3601 (defun message-unique-id ()
3602 ;; Don't use microseconds from (current-time), they may be unsupported.
3603 ;; Instead we use this randomly inited counter.
3604 (setq message-unique-id-char
3605 (% (1+ (or message-unique-id-char (logand (random t) (1- (lsh 1 20)))))
3606 ;; (current-time) returns 16-bit ints,
3607 ;; and 2^16*25 just fits into 4 digits i base 36.
3609 (let ((tm (current-time)))
3611 (if (memq system-type '(ms-dos emx vax-vms))
3612 (let ((user (downcase (user-login-name))))
3613 (while (string-match "[^a-z0-9_]" user)
3614 (aset user (match-beginning 0) ?_))
3616 (message-number-base36 (user-uid) -1))
3617 (message-number-base36 (+ (car tm)
3618 (lsh (% message-unique-id-char 25) 16)) 4)
3619 (message-number-base36 (+ (nth 1 tm)
3620 (lsh (/ message-unique-id-char 25) 16)) 4)
3621 ;; Append the newsreader name, because while the generated
3622 ;; ID is unique to this newsreader, other newsreaders might
3623 ;; otherwise generate the same ID via another algorithm.
3626 (defun message-number-base36 (num len)
3631 (concat (message-number-base36 (/ num 36) (1- len))
3632 (char-to-string (aref "zyxwvutsrqponmlkjihgfedcba9876543210"
3635 (defun message-make-organization ()
3636 "Make an Organization header."
3637 (let* ((organization
3638 (when message-user-organization
3639 (if (message-functionp message-user-organization)
3640 (funcall message-user-organization)
3641 message-user-organization))))
3643 (message-set-work-buffer)
3644 (cond ((stringp organization)
3645 (insert organization))
3646 ((and (eq t organization)
3647 message-user-organization-file
3648 (file-exists-p message-user-organization-file))
3649 (insert-file-contents message-user-organization-file)))
3650 (goto-char (point-min))
3651 (while (re-search-forward "[\t\n]+" nil t)
3652 (replace-match "" t t))
3653 (unless (zerop (buffer-size))
3656 (defun message-make-lines ()
3657 "Count the number of lines and return numeric string."
3661 (goto-char (point-min))
3663 (concat "^" (regexp-quote mail-header-separator) "$"))
3665 (int-to-string (count-lines (point) (point-max))))))
3667 (defun message-make-in-reply-to ()
3668 "Return the In-Reply-To header for this message."
3669 (when message-reply-headers
3670 (let ((mid (mail-header-message-id message-reply-headers))
3671 (from (mail-header-from message-reply-headers))
3672 (date (mail-header-date message-reply-headers)))
3676 (let ((pair (std11-extract-address-components from)))
3678 (or (car pair) (cadr pair))
3680 (if (or (not date) (string= date ""))
3681 "(unknown date)" date)
3684 (defun message-make-distribution ()
3685 "Make a Distribution header."
3686 (let ((orig-distribution (message-fetch-reply-field "distribution")))
3687 (cond ((message-functionp message-distribution-function)
3688 (funcall message-distribution-function))
3689 (t orig-distribution))))
3691 (defun message-make-expires ()
3692 "Return an Expires header based on `message-expires'."
3693 (let ((current (current-time))
3694 (future (* 1.0 message-expires 60 60 24)))
3695 ;; Add the future to current.
3696 (setcar current (+ (car current) (round (/ future (expt 2 16)))))
3697 (setcar (cdr current) (+ (nth 1 current) (% (round future) (expt 2 16))))
3698 (message-make-date current)))
3700 (defun message-make-path ()
3702 (let ((login-name (user-login-name)))
3703 (cond ((null message-user-path)
3704 (concat (system-name) "!" login-name))
3705 ((stringp message-user-path)
3706 ;; Support GENERICPATH. Suggested by vixie@decwrl.dec.com.
3707 (concat message-user-path "!" login-name))
3710 (defun message-make-from ()
3711 "Make a From header."
3712 (let* ((style message-from-style)
3713 (login (message-make-address))
3715 (or (and (boundp 'user-full-name)
3718 (when (string= fullname "&")
3719 (setq fullname (user-login-name)))
3721 (message-set-work-buffer)
3724 (equal fullname ""))
3726 ((or (eq style 'angles)
3727 (and (not (eq style 'parens))
3728 ;; Use angles if no quoting is needed, or if parens would
3729 ;; need quoting too.
3730 (or (not (string-match "[^- !#-'*+/-9=?A-Z^-~]" fullname))
3731 (let ((tmp (concat fullname nil)))
3732 (while (string-match "([^()]*)" tmp)
3733 (aset tmp (match-beginning 0) ?-)
3734 (aset tmp (1- (match-end 0)) ?-))
3735 (string-match "[\\()]" tmp)))))
3737 (goto-char (point-min))
3738 ;; Look for a character that cannot appear unquoted
3739 ;; according to RFC 822.
3740 (when (re-search-forward "[^- !#-'*+/-9=?A-Z^-~]" nil 1)
3741 ;; Quote fullname, escaping specials.
3742 (goto-char (point-min))
3744 (while (re-search-forward "[\"\\]" nil 1)
3745 (replace-match "\\\\\\&" t))
3747 (insert " <" login ">"))
3748 (t ; 'parens or default
3750 (let ((fullname-start (point)))
3752 (goto-char fullname-start)
3753 ;; RFC 822 says \ and nonmatching parentheses
3754 ;; must be escaped in comments.
3755 ;; Escape every instance of ()\ ...
3756 (while (re-search-forward "[()\\]" nil 1)
3757 (replace-match "\\\\\\&" t))
3758 ;; ... then undo escaping of matching parentheses,
3759 ;; including matching nested parentheses.
3760 (goto-char fullname-start)
3761 (while (re-search-forward
3762 "\\(\\=\\|[^\\]\\(\\\\\\\\\\)*\\)\\\\(\\(\\([^\\]\\|\\\\\\\\\\)*\\)\\\\)"
3764 (replace-match "\\1(\\3)" t)
3765 (goto-char fullname-start)))
3769 (defun message-make-sender ()
3770 "Return the \"real\" user address.
3771 This function tries to ignore all user modifications, and
3772 give as trustworthy answer as possible."
3773 (concat (user-login-name) "@" (system-name)))
3775 (defun message-make-address ()
3776 "Make the address of the user."
3777 (or (message-user-mail-address)
3778 (concat (user-login-name) "@" (message-make-domain))))
3780 (defun message-user-mail-address ()
3781 "Return the pertinent part of `user-mail-address'."
3782 (when user-mail-address
3783 (if (string-match " " user-mail-address)
3784 (nth 1 (std11-extract-address-components user-mail-address))
3785 user-mail-address)))
3787 (defun message-make-fqdn ()
3788 "Return user's fully qualified domain name."
3789 (let ((system-name (system-name))
3790 (user-mail (message-user-mail-address)))
3792 ((string-match "[^.]\\.[^.]" system-name)
3793 ;; `system-name' returned the right result.
3795 ;; Try `mail-host-address'.
3796 ((and (boundp 'mail-host-address)
3797 (stringp mail-host-address)
3798 (string-match "\\." mail-host-address))
3800 ;; We try `user-mail-address' as a backup.
3802 (string-match "\\." user-mail)
3803 (string-match "@\\(.*\\)\\'" user-mail))
3804 (match-string 1 user-mail))
3805 ;; Default to this bogus thing.
3807 (concat system-name ".i-did-not-set--mail-host-address--so-shoot-me")))))
3809 (defun message-make-host-name ()
3810 "Return the name of the host."
3811 (let ((fqdn (message-make-fqdn)))
3812 (string-match "^[^.]+\\." fqdn)
3813 (substring fqdn 0 (1- (match-end 0)))))
3815 (defun message-make-domain ()
3816 "Return the domain name."
3817 (or mail-host-address
3818 (message-make-fqdn)))
3820 ;; Dummy to avoid byte-compile warning.
3821 (defvar mule-version)
3822 (defvar emacs-beta-version)
3823 (defvar xemacs-codename)
3824 (defvar gnus-inviolable-extended-version)
3826 (defun message-make-user-agent ()
3827 "Return user-agent info if the value `message-user-agent' is non-nil. If the
3828 \"User-Agent\" field has already exist, it's value will be added in the return
3830 (when message-user-agent
3832 (goto-char (point-min))
3833 (let ((case-fold-search t)
3834 user-agent start p end)
3835 (if (re-search-forward "^User-Agent:[\t ]*" nil t)
3837 (setq start (match-beginning 0)
3839 end (std11-field-end)
3840 user-agent (buffer-substring-no-properties p end))
3841 (delete-region start (1+ end))
3842 (concat message-user-agent " " user-agent))
3843 message-user-agent)))))
3845 (defun message-generate-headers (headers)
3846 "Prepare article HEADERS.
3847 Headers already prepared in the buffer are not modified."
3849 (message-narrow-to-headers)
3850 (let* ((Date (message-make-date))
3851 (Message-ID (message-make-message-id))
3852 (Organization (message-make-organization))
3853 (From (message-make-from))
3854 (Path (message-make-path))
3857 (In-Reply-To (message-make-in-reply-to))
3859 (Distribution (message-make-distribution))
3860 (Lines (message-make-lines))
3861 (User-Agent (message-make-user-agent))
3862 (Expires (message-make-expires))
3863 (case-fold-search t)
3865 ;; First we remove any old generated headers.
3866 (let ((headers message-deletable-headers))
3867 (unless (buffer-modified-p)
3868 (setq headers (delq 'Message-ID (copy-sequence headers))))
3870 (goto-char (point-min))
3871 (and (re-search-forward
3872 (concat "^" (symbol-name (car headers)) ": *") nil t)
3873 (get-text-property (1+ (match-beginning 0)) 'message-deletable)
3874 (message-delete-line))
3876 ;; Go through all the required headers and see if they are in the
3877 ;; articles already. If they are not, or are empty, they are
3878 ;; inserted automatically - except for Subject, Newsgroups and
3881 (goto-char (point-min))
3882 (setq elem (pop headers))
3884 (if (eq (car elem) 'optional)
3885 (setq header (cdr elem))
3886 (setq header (car elem)))
3888 (when (or (not (re-search-forward
3892 (if (stringp header)
3894 (symbol-name header))))
3898 ;; The header was found. We insert a space after the
3899 ;; colon, if there is none.
3900 (if (/= (char-after) ? ) (insert " ") (forward-char 1))
3901 ;; Find out whether the header is empty...
3902 (looking-at "[ \t]*\n[^ \t]")))
3903 ;; So we find out what value we should insert.
3906 ((and (consp elem) (eq (car elem) 'optional))
3907 ;; This is an optional header. If the cdr of this
3908 ;; is something that is nil, then we do not insert
3910 (setq header (cdr elem))
3911 (or (and (fboundp (cdr elem)) (funcall (cdr elem)))
3912 (and (boundp (cdr elem)) (symbol-value (cdr elem)))))
3914 ;; The element is a cons. Either the cdr is a
3915 ;; string to be inserted verbatim, or it is a
3916 ;; function, and we insert the value returned from
3918 (or (and (stringp (cdr elem)) (cdr elem))
3919 (and (fboundp (cdr elem)) (funcall (cdr elem)))))
3920 ((and (boundp header) (symbol-value header))
3921 ;; The element is a symbol. We insert the value
3922 ;; of this symbol, if any.
3923 (symbol-value header))
3924 ((not (message-check-element header))
3925 ;; We couldn't generate a value for this header,
3926 ;; so we just ask the user.
3927 (read-from-minibuffer
3928 (format "Empty header for %s; enter value: " header)))))
3929 ;; Finally insert the header.
3931 (not (equal value "")))
3935 ;; This header didn't exist, so we insert it.
3936 (goto-char (point-max))
3937 (insert (if (stringp header) header (symbol-name header))
3942 ;; The value of this header was empty, so we clear
3943 ;; totally and insert the new value.
3944 (delete-region (point) (gnus-point-at-eol))
3948 ;; Add the deletable property to the headers that require it.
3949 (and (memq header message-deletable-headers)
3950 (progn (beginning-of-line) (looking-at "[^:]+: "))
3951 (add-text-properties
3952 (point) (match-end 0)
3953 '(message-deletable t face italic) (current-buffer)))))))
3954 ;; Insert new Sender if the From is strange.
3955 (let ((from (message-fetch-field "from"))
3956 (sender (message-fetch-field "sender"))
3957 (secure-sender (message-make-sender)))
3959 (not (message-check-element 'sender))
3962 (cadr (std11-extract-address-components from)))
3963 (downcase secure-sender)))
3968 (cadr (std11-extract-address-components sender)))
3969 (downcase secure-sender)))))
3970 (goto-char (point-min))
3971 ;; Rename any old Sender headers to Original-Sender.
3972 (when (re-search-forward "^\\(Original-\\)*Sender:" nil t)
3974 (insert "Original-")
3975 (beginning-of-line))
3976 (when (or (message-news-p)
3977 (string-match "@.+\\.." secure-sender))
3978 (insert "Sender: " secure-sender "\n")))))))
3980 (defun message-insert-courtesy-copy ()
3981 "Insert a courtesy message in mail copies of combined messages."
3985 (message-narrow-to-headers)
3986 (when (setq newsgroups (message-fetch-field "newsgroups"))
3987 (goto-char (point-max))
3988 (insert "Posted-To: " newsgroups "\n")))
3990 (when message-courtesy-message
3992 ((string-match "%s" message-courtesy-message)
3993 (insert (format message-courtesy-message newsgroups)))
3995 (insert message-courtesy-message)))))))
3998 ;;; Setting up a message buffer
4001 (defun message-fill-address (header value)
4003 (narrow-to-region (point) (point))
4004 (insert (capitalize (symbol-name header))
4006 (if (consp value) (car value) value)
4008 (narrow-to-region (point-min) (1- (point-max)))
4010 (goto-char (point-min))
4012 (skip-chars-forward "^,\"" (point-max))
4013 (if (or (eq (char-after) ?,)
4016 (if (and (> (current-column) 78)
4020 (looking-at "[ \t]*")
4021 (replace-match "\n " t t)))
4022 (setq last (1+ (point))))
4023 (setq quoted (not quoted)))
4026 (goto-char (point-max))
4030 (defun message-fill-references (header value)
4031 (insert (capitalize (symbol-name header))
4033 (std11-fill-msg-id-list-string
4034 (if (consp value) (car value) value))
4037 (defun message-fill-header (header value)
4038 (let ((begin (point))
4041 (insert (capitalize (symbol-name header))
4043 (if (consp value) (car value) value)
4046 (narrow-to-region begin (point))
4047 (fill-region-as-paragraph begin (point))
4048 ;; Tapdance around looong Message-IDs.
4050 (when (looking-at "[ \t]*$")
4051 (message-delete-line))
4053 (re-search-forward ":" nil t)
4054 (when (looking-at "\n[ \t]+")
4055 (replace-match " " t t))
4056 (goto-char (point-max)))))
4058 (defun message-shorten-1 (list cut surplus)
4059 ;; Cut SURPLUS elements out of LIST, beginning with CUTth one.
4060 (setcdr (nthcdr (- cut 2) list)
4061 (nthcdr (+ (- cut 2) surplus 1) list)))
4063 (defun message-shorten-references (header references)
4064 "Trim REFERENCES to be less than 31 Message-ID long, and fold them.
4065 If folding is disallowed, also check that the REFERENCES are less
4066 than 988 characters long, and if they are not, trim them until they are."
4073 (goto-char (point-min))
4074 ;; Cons a list of valid references.
4075 (while (re-search-forward "<[^>]+>" nil t)
4076 (push (match-string 0) refs))
4077 (setq refs (nreverse refs)
4078 count (length refs)))
4080 ;; If the list has more than MAXCOUNT elements, trim it by
4081 ;; removing the CUTth element and the required number of
4082 ;; elements that follow.
4083 (when (> count maxcount)
4084 (let ((surplus (- count maxcount)))
4085 (message-shorten-1 refs cut surplus)
4086 (decf count surplus)))
4088 ;; If folding is disallowed, make sure the total length (including
4089 ;; the spaces between) will be less than MAXSIZE characters.
4091 ;; Only disallow folding for News messages. At this point the headers
4092 ;; have not been generated, thus we use message-this-is-news directly.
4093 (when (and message-this-is-news message-cater-to-broken-inn)
4095 (totalsize (+ (apply #'+ (mapcar #'length refs))
4098 (ptr (nthcdr (1- cut) refs)))
4099 ;; Decide how many elements to cut off...
4100 (while (> totalsize maxsize)
4101 (decf totalsize (1+ (length (car ptr))))
4103 (setq ptr (cdr ptr)))
4106 (message-shorten-1 refs cut surplus))))
4108 ;; Finally, collect the references back into a string and insert
4109 ;; it into the buffer.
4110 (let ((refstring (mapconcat #'identity refs " ")))
4111 (if (and message-this-is-news message-cater-to-broken-inn)
4112 (insert (capitalize (symbol-name header)) ": "
4114 (message-fill-header header refstring)))))
4116 (defun message-position-point ()
4117 "Move point to where the user probably wants to find it."
4118 (message-narrow-to-headers)
4120 ((re-search-forward "^[^:]+:[ \t]*$" nil t)
4121 (search-backward ":" )
4124 (if (eq (char-after) ? )
4128 (goto-char (point-max))
4131 (unless (looking-at "$")
4135 (defun message-buffer-name (type &optional to group)
4136 "Return a new (unique) buffer name based on TYPE and TO."
4138 ;; Generate a new buffer name The Message Way.
4139 ((eq message-generate-new-buffers 'unique)
4140 (generate-new-buffer-name
4144 (or (car (std11-extract-address-components to))
4147 (if (and group (not (string= group ""))) (concat " on " group) "")
4149 ;; Check whether `message-generate-new-buffers' is a function,
4150 ;; and if so, call it.
4151 ((message-functionp message-generate-new-buffers)
4152 (funcall message-generate-new-buffers type to group))
4153 ((eq message-generate-new-buffers 'unsent)
4154 (generate-new-buffer-name
4155 (concat "*unsent " type
4158 (or (car (mail-extract-address-components to))
4161 (if (and group (not (string= group ""))) (concat " on " group) "")
4163 ;; Use standard name.
4165 (format "*%s message*" type))))
4167 (defmacro message-pop-to-buffer-1 (buffer)
4169 (let (special-display-buffer-names
4170 special-display-regexps
4171 same-window-buffer-names
4172 same-window-regexps)
4173 (pop-to-buffer ,buffer))
4174 (pop-to-buffer ,buffer)))
4176 (defun message-pop-to-buffer (name)
4177 "Pop to buffer NAME, and warn if it already exists and is modified."
4178 (let ((buffer (get-buffer name))
4179 (pop-up-frames (and (or (static-if (featurep 'xemacs)
4180 (device-on-window-system-p)
4182 (>= emacs-major-version 20))
4183 message-use-multi-frames)))
4185 (buffer-name buffer))
4187 (message-pop-to-buffer-1 buffer)
4188 (when (and (buffer-modified-p)
4190 "Message already being composed; erase? ")))
4191 (error "Message being composed")))
4192 (message-pop-to-buffer-1 name))
4196 (set (make-local-variable 'message-original-frame) (selected-frame)))))
4198 (defun message-do-send-housekeeping ()
4199 "Kill old message buffers."
4200 ;; We might have sent this buffer already. Delete it from the
4202 (setq message-buffer-list (delq (current-buffer) message-buffer-list))
4203 (while (and message-max-buffers
4205 (>= (length message-buffer-list) message-max-buffers))
4206 ;; Kill the oldest buffer -- unless it has been changed.
4207 (let ((buffer (pop message-buffer-list)))
4208 (when (and (buffer-name buffer)
4209 (not (buffer-modified-p buffer)))
4210 (kill-buffer buffer))))
4211 ;; Rename the buffer.
4212 (if message-send-rename-function
4213 (funcall message-send-rename-function)
4214 (when (string-match "\\`\\*\\(unsent \\)?" (buffer-name))
4216 (concat "*sent " (substring (buffer-name) (match-end 0))) t)))
4217 ;; Push the current buffer onto the list.
4218 (when message-max-buffers
4219 (setq message-buffer-list
4220 (nconc message-buffer-list (list (current-buffer))))))
4222 (defvar mc-modes-alist)
4223 (defun message-setup (headers &optional replybuffer actions)
4224 (when (and (boundp 'mc-modes-alist)
4225 (not (assq 'message-mode mc-modes-alist)))
4226 (push '(message-mode (encrypt . mc-encrypt-message)
4227 (sign . mc-sign-message))
4230 (setq message-send-actions actions))
4231 (setq message-reply-buffer
4232 (or (message-get-parameter 'reply-buffer)
4234 (goto-char (point-min))
4235 ;; Insert all the headers.
4238 (alist message-header-format-alist))
4240 (unless (assq (caar h) message-header-format-alist)
4241 (push (list (caar h)) alist))
4245 (delete-region (point) (progn (forward-line -1) (point)))
4246 (when message-default-headers
4247 (insert message-default-headers)
4248 (or (bolp) (insert ?\n)))
4252 (insert mail-header-separator "\n")
4256 (when (message-news-p)
4257 (when message-default-news-headers
4258 (insert message-default-news-headers)
4259 (or (bolp) (insert ?\n)))
4260 (when message-generate-headers-first
4261 (message-generate-headers
4264 (copy-sequence message-required-news-headers))))))
4265 (when (message-mail-p)
4266 (when message-default-mail-headers
4267 (insert message-default-mail-headers)
4268 (or (bolp) (insert ?\n)))
4269 (when message-generate-headers-first
4270 (message-generate-headers
4273 (copy-sequence message-required-mail-headers))))))
4274 (run-hooks 'message-signature-setup-hook)
4275 (message-insert-signature)
4277 (message-narrow-to-headers)
4278 (run-hooks 'message-header-setup-hook))
4279 (set-buffer-modified-p nil)
4280 (setq buffer-undo-list nil)
4281 (run-hooks 'message-setup-hook)
4282 (message-position-point)
4285 (defun message-set-auto-save-file-name ()
4286 "Associate the message buffer with a file in the drafts directory."
4287 (when message-auto-save-directory
4289 (setq message-draft-article
4290 (nndraft-request-associate-buffer "drafts"))
4291 (setq buffer-file-name (expand-file-name "*message*"
4292 message-auto-save-directory))
4293 (setq buffer-auto-save-file-name (make-auto-save-file-name)))
4294 (clear-visited-file-modtime)
4295 (static-if (boundp 'MULE)
4296 (set-file-coding-system message-draft-coding-system)
4297 (setq buffer-file-coding-system message-draft-coding-system))))
4299 (defun message-disassociate-draft ()
4300 "Disassociate the message buffer from the drafts directory."
4301 (when message-draft-article
4302 (nndraft-request-expire-articles
4303 (list message-draft-article) "drafts" nil t)))
4305 (defun message-insert-headers ()
4306 "Generate the headers for the article."
4310 (message-narrow-to-headers)
4311 (when (message-news-p)
4312 (message-generate-headers
4315 (copy-sequence message-required-news-headers)))))
4316 (when (message-mail-p)
4317 (message-generate-headers
4320 (copy-sequence message-required-mail-headers))))))))
4325 ;;; Commands for interfacing with message
4329 (defun message-mail (&optional to subject
4330 other-headers continue switch-function
4331 yank-action send-actions)
4332 "Start editing a mail message to be sent.
4333 OTHER-HEADERS is an alist of header/value pairs."
4335 (let ((message-this-is-mail t))
4336 (message-pop-to-buffer (message-buffer-name "mail" to))
4339 `((To . ,(or to "")) (Subject . ,(or subject "")))
4340 (when other-headers other-headers)))))
4343 (defun message-news (&optional newsgroups subject)
4344 "Start editing a news article to be sent."
4346 (let ((message-this-is-news t))
4347 (message-pop-to-buffer (message-buffer-name "news" nil newsgroups))
4348 (message-setup `((Newsgroups . ,(or newsgroups ""))
4349 (Subject . ,(or subject ""))))))
4351 (defun message-get-reply-headers (wide &optional to-address)
4352 (let (follow-to mct never-mct from to cc reply-to mft)
4353 ;; Find all relevant headers we need.
4354 (setq from (message-fetch-field "from")
4355 to (message-fetch-field "to")
4356 cc (message-fetch-field "cc")
4357 mct (when message-use-mail-copies-to
4358 (message-fetch-field "mail-copies-to"))
4359 reply-to (when message-use-mail-reply-to
4360 (or (message-fetch-field "mail-reply-to")
4361 (message-fetch-field "reply-to")))
4362 mft (when (and (not to-address)
4364 message-use-mail-followup-to)
4365 (message-fetch-field "mail-followup-to")))
4367 ;; Handle special values of Mail-Copies-To.
4370 ((and (or (equal (downcase mct) "never")
4371 (equal (downcase mct) "nobody"))
4372 (or (not (eq message-use-mail-copies-to 'ask))
4374 (concat "Obey Mail-Copies-To: never? ") t "\
4375 You should normally obey the Mail-Copies-To: header.
4377 `Mail-Copies-To: never'
4378 directs you not to send your response to the author.")))
4381 ((and (or (equal (downcase mct) "always")
4382 (equal (downcase mct) "poster"))
4383 (or (not (eq message-use-mail-copies-to 'ask))
4385 (concat "Obey Mail-Copies-To: always? ") t "\
4386 You should normally obey the Mail-Copies-To: header.
4388 `Mail-Copies-To: always'
4389 sends a copy of your response to the author.")))
4390 (setq mct (or reply-to from)))
4391 ((and (eq message-use-mail-copies-to 'ask)
4394 (concat "Obey Mail-Copies-To: " mct " ? ") t "\
4395 You should normally obey the Mail-Copies-To: header.
4397 `Mail-Copies-To: " mct "'
4398 sends a copy of your response to " (if (string-match "," mct)
4399 "the specified addresses"
4400 "that address") ".")))
4403 ;; Handle Mail-Followup-To.
4405 (eq message-use-mail-followup-to 'ask)
4406 (not (message-y-or-n-p
4407 (concat "Obey Mail-Followup-To: " mft "? ") t "\
4408 You should normally obey the Mail-Followup-To: header.
4410 `Mail-Followup-To: " mft "'
4411 directs your response to " (if (string-match "," mft)
4412 "the specified addresses"
4413 "that address only") ".
4415 A typical situation where Mail-Followup-To is used is when the author thinks
4416 that further discussion should take place only in "
4417 (if (string-match "," mft)
4418 "the specified mailing lists"
4419 "that mailing list") ".")))
4425 (setq follow-to (list (cons 'To (or to-address reply-to mft from))))
4426 (when (and wide mct)
4427 (push (cons 'Cc mct) follow-to)))
4430 (message-set-work-buffer)
4432 (insert (or reply-to from "")))
4433 (insert (if mft (concat (if (bolp) "" ", ") mft "") ""))
4434 (insert (if to (concat (if (bolp) "" ", ") to "") ""))
4435 (insert (if mct (concat (if (bolp) "" ", ") mct) ""))
4436 (insert (if cc (concat (if (bolp) "" ", ") cc) ""))
4437 (goto-char (point-min))
4438 (while (re-search-forward "[ \t]+" nil t)
4439 (replace-match " " t t))
4440 ;; Remove addresses that match `rmail-dont-reply-to-names'.
4441 (let ((rmail-dont-reply-to-names message-dont-reply-to-names))
4442 (insert (prog1 (rmail-dont-reply-to (buffer-string))
4444 (goto-char (point-min))
4445 ;; Perhaps "Mail-Copies-To: never" removed the only address?
4447 (insert (or reply-to from "")))
4451 (cons (mail-strip-quoted-names addr) addr))
4452 (message-tokenize-header (buffer-string))))
4455 (setq ccalist (delq (assoc (car (pop s)) s) ccalist)))))
4456 (setq follow-to (list (cons 'To (cdr (pop ccalist)))))
4458 (let ((ccs (cons 'Cc (mapconcat
4459 (lambda (addr) (cdr addr)) ccalist ", "))))
4460 (when (string-match "^ +" (cdr ccs))
4461 (setcdr ccs (substring (cdr ccs) (match-end 0))))
4462 (push ccs follow-to)))))
4466 (defun message-reply (&optional to-address wide)
4467 "Start editing a reply to the article in the current buffer."
4469 (let ((cur (current-buffer))
4471 references message-id follow-to
4472 (inhibit-point-motion-hooks t)
4473 (message-this-is-mail t)
4474 gnus-warning in-reply-to)
4476 (message-narrow-to-head)
4477 ;; Allow customizations to have their say.
4479 ;; This is a regular reply.
4480 (if (message-functionp message-reply-to-function)
4481 (setq follow-to (funcall message-reply-to-function)))
4482 ;; This is a followup.
4483 (if (message-functionp message-wide-reply-to-function)
4486 (funcall message-wide-reply-to-function)))))
4487 (setq message-id (message-fetch-field "message-id" t)
4488 references (message-fetch-field "references")
4489 date (message-fetch-field "date")
4490 from (message-fetch-field "from")
4491 subject (or (message-fetch-field "subject") "none"))
4492 ;; Remove any (buggy) Re:'s that are present and make a
4494 (when (string-match message-subject-re-regexp subject)
4495 (setq subject (substring subject (match-end 0))))
4496 (setq subject (message-make-followup-subject subject))
4498 (when (and (setq gnus-warning (message-fetch-field "gnus-warning"))
4499 (string-match "<[^>]+>" gnus-warning))
4500 (setq message-id (match-string 0 gnus-warning)))
4503 (setq follow-to (message-get-reply-headers wide to-address)))
4505 ;; Get the references from "In-Reply-To" field if there were
4506 ;; no references and "In-Reply-To" field looks promising.
4508 (when (and (setq in-reply-to (message-fetch-field "in-reply-to"))
4509 (string-match "<[^>]+>" in-reply-to))
4510 (setq references (match-string 0 in-reply-to)))))
4512 (message-pop-to-buffer
4513 (message-buffer-name
4514 (if wide "wide reply" "reply") from
4515 (if wide to-address nil)))
4517 (setq message-reply-headers
4518 (make-full-mail-header-from-decoded-header
4519 0 subject from date message-id references 0 0 ""))
4522 `((Subject . ,subject)
4524 ,@(if (or references message-id)
4525 `((References . ,(concat (or references "") (and references " ")
4526 (or message-id ""))))
4531 (defun message-wide-reply (&optional to-address)
4532 "Make a \"wide\" reply to the message in the current buffer."
4534 (message-reply to-address t))
4537 (defun message-followup (&optional to-newsgroups)
4538 "Follow up to the message in the current buffer.
4539 If TO-NEWSGROUPS, use that as the new Newsgroups line."
4541 (let ((cur (current-buffer))
4542 from subject date mct
4543 references message-id follow-to
4544 (inhibit-point-motion-hooks t)
4545 (message-this-is-news t)
4546 followup-to distribution newsgroups gnus-warning posted-to mft mrt)
4548 (message-narrow-to-head)
4549 (when (message-functionp message-followup-to-function)
4551 (funcall message-followup-to-function)))
4552 (setq from (message-fetch-field "from")
4553 date (message-fetch-field "date" t)
4554 subject (or (message-fetch-field "subject") "none")
4555 references (message-fetch-field "references")
4556 message-id (message-fetch-field "message-id" t)
4557 followup-to (when message-use-followup-to
4558 (message-fetch-field "followup-to"))
4559 distribution (message-fetch-field "distribution")
4560 newsgroups (message-fetch-field "newsgroups")
4561 posted-to (message-fetch-field "posted-to")
4562 mct (when message-use-mail-copies-to
4563 (message-fetch-field "mail-copies-to"))
4564 mft (when message-use-mail-followup-to
4565 (message-fetch-field "mail-followup-to"))
4566 mrt (when message-use-mail-reply-to
4567 (or (message-fetch-field "mail-reply-to")
4568 (message-fetch-field "reply-to")))
4569 gnus-warning (message-fetch-field "gnus-warning"))
4570 (when (and gnus-warning (string-match "<[^>]+>" gnus-warning))
4571 (setq message-id (match-string 0 gnus-warning)))
4572 ;; Remove bogus distribution.
4573 (when (and (stringp distribution)
4574 (let ((case-fold-search t))
4575 (string-match "world" distribution)))
4576 (setq distribution nil))
4577 ;; Remove any (buggy) Re:'s that are present and make a
4579 (setq subject (message-make-followup-subject subject))
4582 ;; Handle special values of Mail-Copies-To.
4585 ((and (or (equal (downcase mct) "never")
4586 (equal (downcase mct) "nobody"))
4587 (or (not (eq message-use-mail-copies-to 'ask))
4589 (concat "Obey Mail-Copies-To: never? ") t "\
4590 You should normally obey the Mail-Copies-To: header.
4592 `Mail-Copies-To: never'
4593 directs you not to send your response to the author.")))
4595 ((and (or (equal (downcase mct) "always")
4596 (equal (downcase mct) "poster"))
4597 (or (not (eq message-use-mail-copies-to 'ask))
4599 (concat "Obey Mail-Copies-To: always? ") t "\
4600 You should normally obey the Mail-Copies-To: header.
4602 `Mail-Copies-To: always'
4603 sends a copy of your response to the author.")))
4604 (setq mct (or mrt from)))
4605 ((and (eq message-use-mail-copies-to 'ask)
4608 (concat "Obey Mail-Copies-To: " mct " ? ") t "\
4609 You should normally obey the Mail-Copies-To: header.
4611 `Mail-Copies-To: " mct "'
4612 sends a copy of your response to " (if (string-match "," mct)
4613 "the specified addresses"
4614 "that address") ".")))
4620 (to-newsgroups (setq follow-to (list (cons 'Newsgroups to-newsgroups))))
4621 ;; Handle Followup-To.
4624 ((equal (downcase followup-to) "poster")
4625 (if (or (eq message-use-followup-to 'use)
4626 (message-y-or-n-p "Obey Followup-To: poster? " t "\
4627 You should normally obey the Followup-To: header.
4629 `Followup-To: poster'
4630 sends your response via e-mail instead of news.
4632 A typical situation where `Followup-To: poster' is used is when the author
4633 does not read the newsgroup, so he wouldn't see any replies sent to it."))
4634 (setq message-this-is-news nil
4636 follow-to (list (cons 'To (or mrt from ""))))
4637 (setq follow-to (list (cons 'Newsgroups newsgroups)))))
4639 (if (or (equal followup-to newsgroups)
4640 (not (eq message-use-followup-to 'ask))
4642 (concat "Obey Followup-To: " followup-to "? ") t "\
4643 You should normally obey the Followup-To: header.
4645 `Followup-To: " followup-to "'
4646 directs your response to " (if (string-match "," followup-to)
4647 "the specified newsgroups"
4648 "that newsgroup only") ".
4650 If a message is posted to several newsgroups, Followup-To is often
4651 used to direct the following discussion to one newsgroup only,
4652 because discussions that are spread over several newsgroup tend to
4653 be fragmented and very difficult to follow.
4655 Also, some source/announcement newsgroups are not indented for discussion;
4656 responses here are directed to other newsgroups."))
4657 (setq follow-to (list (cons 'Newsgroups followup-to)))
4658 (setq follow-to (list (cons 'Newsgroups newsgroups)))))))
4659 ;; Handle Mail-Followup-To, followup via e-mail.
4661 (or (not (eq message-use-mail-followup-to 'ask))
4663 (concat "Obey Mail-Followup-To: " mft "? ") t "\
4664 You should normally obey the Mail-Followup-To: header.
4666 `Mail-Followup-To: " mft "'
4667 directs your response to " (if (string-match "," mft)
4668 "the specified addresses"
4669 "that address only") " instead of news.
4671 A typical situation where Mail-Followup-To is used is when the author thinks
4672 that further discussion should take place only in "
4673 (if (string-match "," mft)
4674 "the specified mailing lists"
4675 "that mailing list") ".")))
4676 (setq message-this-is-news nil
4678 follow-to (list (cons 'To mft))))
4679 (posted-to (setq follow-to (list (cons 'Newsgroups posted-to))))
4681 (setq follow-to (list (cons 'Newsgroups newsgroups))))))
4683 (message-pop-to-buffer (message-buffer-name "followup" from newsgroups))
4685 (setq message-reply-headers
4686 (make-full-mail-header-from-decoded-header
4687 0 subject from date message-id references 0 0 ""))
4690 `((Subject . ,subject)
4692 ,@(and mct (list (cons 'Cc mct)))
4693 ,@(and distribution (list (cons 'Distribution distribution)))
4694 ,@(if (or references message-id)
4695 `((References . ,(concat (or references "") (and references " ")
4696 (or message-id ""))))))
4700 (defun message-cancel-news (&optional arg)
4701 "Cancel an article you posted.
4702 If ARG, allow editing of the cancellation message."
4704 (unless (message-news-p)
4705 (error "This is not a news article; canceling is impossible"))
4706 (when (yes-or-no-p "Do you really want to cancel this article? ")
4707 (let (from newsgroups message-id distribution buf sender)
4709 ;; Get header info from original article.
4711 (message-narrow-to-head)
4712 (setq from (message-fetch-field "from")
4713 sender (message-fetch-field "sender")
4714 newsgroups (message-fetch-field "newsgroups")
4715 message-id (message-fetch-field "message-id" t)
4716 distribution (message-fetch-field "distribution")))
4717 ;; Make sure that this article was written by the user.
4718 (unless (or (and sender
4721 (downcase (message-make-sender))))
4723 (downcase (cadr (std11-extract-address-components
4725 (downcase (cadr (std11-extract-address-components
4726 (message-make-from))))))
4727 (error "This article is not yours"))
4728 ;; Make control message.
4731 (setq buf (set-buffer (get-buffer-create " *message cancel*"))))
4733 (insert "Newsgroups: " newsgroups "\n"
4734 "From: " (message-make-from) "\n"
4735 "Subject: cmsg cancel " message-id "\n"
4736 "Control: cancel " message-id "\n"
4738 (concat "Distribution: " distribution "\n")
4740 mail-header-separator "\n"
4741 message-cancel-message)
4742 (run-hooks 'message-cancel-hook)
4743 (message "Canceling your article...")
4745 (if (let ((message-syntax-checks
4746 'dont-check-for-anything-just-trust-me)
4747 (message-encoding-buffer (current-buffer))
4748 (message-edit-buffer (current-buffer)))
4749 (message-send-news))
4750 (message "Canceling your article...done"))
4751 (kill-buffer buf))))))
4753 (defun message-supersede-setup-for-mime-edit ()
4754 (set (make-local-variable 'message-setup-hook) nil)
4758 (defun message-supersede ()
4759 "Start composing a message to supersede the current message.
4760 This is done simply by taking the old article and adding a Supersedes
4761 header line with the old Message-ID."
4763 (let ((cur (current-buffer))
4764 (sender (message-fetch-field "sender"))
4765 (from (message-fetch-field "from")))
4766 ;; Check whether the user owns the article that is to be superseded.
4767 (unless (or (and sender
4770 (downcase (message-make-sender))))
4772 (downcase (cadr (std11-extract-address-components from)))
4773 (downcase (cadr (std11-extract-address-components
4774 (message-make-from))))))
4775 (error "This article is not yours"))
4776 ;; Get a normal message buffer.
4777 (message-pop-to-buffer (message-buffer-name "supersede"))
4778 (insert-buffer-substring cur)
4779 (message-narrow-to-head)
4780 ;; Remove unwanted headers.
4781 (when message-ignored-supersedes-headers
4782 (message-remove-header message-ignored-supersedes-headers t))
4783 (goto-char (point-min))
4784 (if (not (re-search-forward "^Message-ID: " nil t))
4785 (error "No Message-ID in this article")
4786 (replace-match "Supersedes: " t t))
4787 (goto-char (point-max))
4788 (insert mail-header-separator)
4790 (when message-supersede-setup-function
4791 (funcall message-supersede-setup-function))
4792 (run-hooks 'message-supersede-setup-hook)
4793 (goto-char (point-min))
4794 (search-forward (concat "\n" mail-header-separator "\n") nil t)))
4797 (defun message-recover ()
4798 "Reread contents of current buffer from its last auto-save file."
4800 (let ((file-name (make-auto-save-file-name)))
4801 (cond ((save-window-excursion
4802 (if (not (eq system-type 'vax-vms))
4803 (with-output-to-temp-buffer "*Directory*"
4804 (with-current-buffer standard-output
4805 (fundamental-mode)) ; for Emacs 20.4+
4806 (buffer-disable-undo standard-output)
4807 (let ((default-directory "/"))
4809 "ls" nil standard-output nil "-l" file-name))))
4810 (yes-or-no-p (format "Recover auto save file %s? " file-name)))
4811 (let ((buffer-read-only nil))
4813 (insert-file-contents file-name nil)))
4814 (t (error "message-recover cancelled")))))
4816 ;;; Washing Subject:
4818 (defun message-wash-subject (subject)
4819 "Remove junk like \"Re:\", \"(fwd)\", etc. that was added to the subject by previous forwarders, replyers, etc."
4821 (insert-string subject)
4822 (goto-char (point-min))
4823 ;; strip Re/Fwd stuff off the beginning
4824 (while (re-search-forward
4825 "\\([Rr][Ee]:\\|[Ff][Ww][Dd]\\(\\[[0-9]*\\]\\)?:\\|[Ff][Ww]:\\)" nil t)
4828 ;; and gnus-style forwards [foo@bar.com] subject
4829 (goto-char (point-min))
4830 (while (re-search-forward "\\[[^ \t]*\\(@\\|\\.\\)[^ \t]*\\]" nil t)
4834 (goto-char (point-max))
4835 (while (re-search-backward "([Ff][Ww][Dd])" nil t)
4838 ;; and finally, any whitespace that was left-over
4839 (goto-char (point-min))
4840 (while (re-search-forward "^[ \t]+" nil t)
4842 (goto-char (point-max))
4843 (while (re-search-backward "[ \t]+$" nil t)
4848 ;;; Forwarding messages.
4850 (defun message-forward-subject-author-subject (subject)
4851 "Generate a subject for a forwarded message.
4852 The form is: [Source] Subject, where if the original message was mail,
4853 Source is the sender, and if the original message was news, Source is
4854 the list of newsgroups is was posted to."
4856 (or (message-fetch-field
4857 (if (message-news-p) "newsgroups" "from"))
4861 (defun message-forward-subject-fwd (subject)
4862 "Generate a subject for a forwarded message.
4863 The form is: Fwd: Subject, where Subject is the original subject of
4865 (concat "Fwd: " subject))
4867 (defun message-make-forward-subject ()
4868 "Return a Subject header suitable for the message in the current buffer."
4872 (message-narrow-to-head)
4873 (let ((funcs message-make-forward-subject-function)
4874 (subject (message-fetch-field "Subject")))
4877 (if message-wash-forwarded-subjects
4878 (message-wash-subject
4879 (nnheader-decode-subject subject))
4880 (nnheader-decode-subject subject))
4882 ;; Make sure funcs is a list.
4885 (setq funcs (list funcs)))
4886 ;; Apply funcs in order, passing subject generated by previous
4887 ;; func to the next one.
4889 (when (message-functionp (car funcs))
4890 (setq subject (funcall (car funcs) subject)))
4891 (setq funcs (cdr funcs)))
4895 (defun message-forward (&optional news)
4896 "Forward the current message via mail.
4897 Optional NEWS will use news to forward instead of mail."
4899 (let ((cur (current-buffer))
4900 (subject (message-make-forward-subject))
4903 (message-news nil subject)
4904 (message-mail nil subject))
4905 ;; Put point where we want it before inserting the forwarded
4907 (if message-forward-before-signature
4909 (goto-char (point-max)))
4910 ;; Make sure we're at the start of the line.
4913 ;; Narrow to the area we are to insert.
4914 (narrow-to-region (point) (point))
4915 ;; Insert the separators and the forwarded buffer.
4916 (insert message-forward-start-separator)
4917 (setq art-beg (point))
4918 (insert-buffer-substring cur)
4919 (goto-char (point-max))
4920 (insert message-forward-end-separator)
4921 (set-text-properties (point-min) (point-max) nil)
4922 ;; Remove all unwanted headers.
4924 (narrow-to-region (point) (if (search-forward "\n\n" nil t)
4927 (goto-char (point-min))
4928 (message-remove-header message-included-forward-headers t nil t)
4930 (message-position-point)))
4933 (defun message-resend (address)
4934 "Resend the current article to ADDRESS."
4936 (list (message-read-from-minibuffer "Resend message to: ")))
4937 (message "Resending message to %s..." address)
4939 (let ((cur (current-buffer))
4941 ;; We first set up a normal mail buffer.
4942 (set-buffer (get-buffer-create " *message resend*"))
4944 ;; avoid to turn-on-mime-edit
4945 (let (message-setup-hook)
4946 (message-setup `((To . ,address)))
4948 ;; Insert our usual headers.
4949 (message-generate-headers '(From Date To))
4950 (message-narrow-to-headers)
4951 ;; Rename them all to "Resent-*".
4952 (while (re-search-forward "^[A-Za-z]" nil t)
4957 (delete-region (point) (point-max))
4959 ;; Insert the message to be resent.
4960 (insert-buffer-substring cur)
4961 (goto-char (point-min))
4962 (search-forward "\n\n")
4965 (narrow-to-region beg (point))
4966 (message-remove-header message-ignored-resent-headers t)
4967 (goto-char (point-max)))
4968 (insert mail-header-separator)
4969 ;; Rename all old ("Also-")Resent headers.
4970 (while (re-search-backward "^\\(Also-\\)*Resent-" beg t)
4973 ;; Quote any "From " lines at the beginning.
4975 (when (looking-at "From ")
4976 (replace-match "X-From-Line: "))
4978 (let ((message-encoding-buffer (current-buffer))
4979 (message-edit-buffer (current-buffer)))
4980 (let (message-required-mail-headers)
4981 (message-send-mail)))
4982 (kill-buffer (current-buffer)))
4983 (message "Resending message to %s...done" address)))
4985 (defun message-bounce-setup-for-mime-edit ()
4986 (set (make-local-variable 'message-setup-hook) nil)
4990 (defun message-bounce ()
4991 "Re-mail the current message.
4992 This only makes sense if the current message is a bounce message than
4993 contains some mail you have written which has been bounced back to
4996 (let ((cur (current-buffer))
4998 (message-pop-to-buffer (message-buffer-name "bounce"))
4999 (insert-buffer-substring cur)
5001 (message-narrow-to-head)
5002 (if (and (message-fetch-field "MIME-Version")
5003 (setq boundary (message-fetch-field "Content-Type")))
5004 (if (string-match "boundary=\"\\([^\"]+\\)\"" boundary)
5005 (setq boundary (concat (match-string 1 boundary) " *\n"
5006 "Content-Type: message/rfc822"))
5007 (setq boundary nil)))
5009 (goto-char (point-min))
5010 (search-forward "\n\n" nil t)
5012 (re-search-forward boundary nil t)
5014 (and (re-search-forward message-unsent-separator nil t)
5016 (re-search-forward "^Return-Path:.*\n" nil t))
5017 ;; We remove everything before the bounced mail.
5020 (if (re-search-forward "^[^ \n\t]+:" nil t)
5024 (message-narrow-to-head)
5025 (message-remove-header message-ignored-bounced-headers t)
5026 (goto-char (point-max))
5027 (insert mail-header-separator))
5028 (when message-bounce-setup-function
5029 (funcall message-bounce-setup-function))
5030 (run-hooks 'message-bounce-setup-hook)
5031 (message-position-point)))
5034 ;;; Interactive entry points for new message buffers.
5038 (defun message-mail-other-window (&optional to subject)
5039 "Like `message-mail' command, but display mail buffer in another window."
5041 (let ((pop-up-windows t)
5042 (special-display-buffer-names nil)
5043 (special-display-regexps nil)
5044 (same-window-buffer-names nil)
5045 (same-window-regexps nil))
5046 (message-pop-to-buffer (message-buffer-name "mail" to)))
5047 (let ((message-this-is-mail t))
5048 (message-setup `((To . ,(or to "")) (Subject . ,(or subject ""))))))
5051 (defun message-mail-other-frame (&optional to subject)
5052 "Like `message-mail' command, but display mail buffer in another frame."
5054 (let ((pop-up-frames t)
5055 (special-display-buffer-names nil)
5056 (special-display-regexps nil)
5057 (same-window-buffer-names nil)
5058 (same-window-regexps nil))
5059 (message-pop-to-buffer (message-buffer-name "mail" to)))
5060 (let ((message-this-is-mail t))
5061 (message-setup `((To . ,(or to "")) (Subject . ,(or subject ""))))))
5064 (defun message-news-other-window (&optional newsgroups subject)
5065 "Start editing a news article to be sent."
5067 (let ((pop-up-windows t)
5068 (special-display-buffer-names nil)
5069 (special-display-regexps nil)
5070 (same-window-buffer-names nil)
5071 (same-window-regexps nil))
5072 (message-pop-to-buffer (message-buffer-name "news" nil newsgroups)))
5073 (let ((message-this-is-news t))
5074 (message-setup `((Newsgroups . ,(or newsgroups ""))
5075 (Subject . ,(or subject ""))))))
5078 (defun message-news-other-frame (&optional newsgroups subject)
5079 "Start editing a news article to be sent."
5081 (let ((pop-up-frames t)
5082 (special-display-buffer-names nil)
5083 (special-display-regexps nil)
5084 (same-window-buffer-names nil)
5085 (same-window-regexps nil))
5086 (message-pop-to-buffer (message-buffer-name "news" nil newsgroups)))
5087 (let ((message-this-is-news t))
5088 (message-setup `((Newsgroups . ,(or newsgroups ""))
5089 (Subject . ,(or subject ""))))))
5093 ;; This code should be moved to underline.el (from which it is stolen).
5096 (defun bold-region (start end)
5097 "Bold all nonblank characters in the region.
5098 Works by overstriking characters.
5099 Called from program, takes two arguments START and END
5100 which specify the range to operate on."
5103 (let ((end1 (make-marker)))
5104 (move-marker end1 (max start end))
5105 (goto-char (min start end))
5106 (while (< (point) end1)
5107 (or (looking-at "[_\^@- ]")
5108 (insert (char-after) "\b"))
5109 (forward-char 1)))))
5112 (defun unbold-region (start end)
5113 "Remove all boldness (overstruck characters) in the region.
5114 Called from program, takes two arguments START and END
5115 which specify the range to operate on."
5118 (let ((end1 (make-marker)))
5119 (move-marker end1 (max start end))
5120 (goto-char (min start end))
5121 (while (re-search-forward "\b" end1 t)
5122 (if (eq (char-after) (char-after (- (point) 2)))
5123 (delete-char -2))))))
5125 (defalias 'message-exchange-point-and-mark 'exchange-point-and-mark)
5127 ;; Support for toolbar
5128 (when (string-match "XEmacs\\|Lucid" emacs-version)
5129 (require 'messagexmas))
5131 ;;; Group name completion.
5133 (defvar message-newgroups-header-regexp
5134 "^\\(Newsgroups\\|Followup-To\\|Posted-To\\|Gcc\\):"
5135 "Regexp that match headers that lists groups.")
5137 (defun message-tab ()
5138 "Expand group names in Newsgroups and Followup-To headers.
5139 Do a `tab-to-tab-stop' if not in those headers."
5141 (if (let ((mail-abbrev-mode-regexp message-newgroups-header-regexp))
5142 (mail-abbrev-in-expansion-header-p))
5143 (message-expand-group)
5146 (defvar gnus-active-hashtb)
5147 (defun message-expand-group ()
5148 "Expand the group name under point."
5149 (let* ((b (save-excursion
5154 (skip-chars-forward "^:")
5157 (skip-chars-backward "^, \t\n") (point))))
5158 (completion-ignore-case t)
5159 (string (buffer-substring b (progn (skip-chars-forward "^,\t\n ")
5161 (hashtb (and (boundp 'gnus-active-hashtb) gnus-active-hashtb))
5162 (completions (all-completions string hashtb))
5164 (delete-region b (point))
5166 ((= (length completions) 1)
5167 (if (string= (car completions) string)
5170 (message "Only matching group"))
5171 (insert (car completions))))
5172 ((and (setq comp (try-completion string hashtb))
5173 (not (string= comp string)))
5178 (message "No matching groups")
5179 (save-selected-window
5180 (pop-to-buffer "*Completions*")
5181 (buffer-disable-undo)
5182 (let ((buffer-read-only nil))
5184 (let ((standard-output (current-buffer)))
5185 (display-completion-list (sort completions 'string<)))
5186 (goto-char (point-min))
5187 (delete-region (point) (progn (forward-line 3) (point))))))))))
5191 (defun message-talkative-question (ask question show &rest text)
5192 "Call FUNCTION with argument QUESTION; optionally display TEXT... args.
5193 If SHOW is non-nil, the arguments TEXT... are displayed in a temp buffer.
5194 The following arguments may contain lists of values."
5196 (setq text (message-flatten-list text)))
5197 (save-window-excursion
5199 (with-output-to-temp-buffer " *MESSAGE information message*"
5200 (set-buffer " *MESSAGE information message*")
5201 (fundamental-mode) ; for Emacs 20.4+
5202 (mapcar 'princ text)
5203 (goto-char (point-min))))
5204 (funcall ask question))
5205 (funcall ask question)))
5207 (defun message-flatten-list (list)
5208 "Return a new, flat list that contains all elements of LIST.
5210 \(message-flatten-list '(1 (2 3 (4 5 (6))) 7))
5213 (apply 'append (mapcar 'message-flatten-list list)))
5217 (defun message-generate-new-buffer-clone-locals (name &optional varstr)
5218 "Create and return a buffer with a name based on NAME using generate-new-buffer.
5219 Then clone the local variables and values from the old buffer to the
5220 new one, cloning only the locals having a substring matching the
5222 (let ((oldbuf (current-buffer)))
5224 (set-buffer (generate-new-buffer name))
5225 (message-clone-locals oldbuf varstr)
5228 (defun message-clone-locals (buffer &optional varstr)
5229 "Clone the local variables from BUFFER to the current buffer."
5230 (let ((locals (save-excursion
5232 (buffer-local-variables)))
5234 "^\\(gnus\\|nn\\|message\\|user-\\(mail-address\\|full-name\\)\\)"))
5237 (when (and (consp local)
5239 (string-match regexp (symbol-name (car local)))
5241 (string-match varstr (symbol-name (car local)))))
5243 (set (make-local-variable (car local))
5248 ;;; @ for MIME Edit mode
5251 (defun message-maybe-encode ()
5252 (when message-mime-mode
5253 ;; Inherit the buffer local variable `mime-edit-pgp-processing'.
5254 (let ((pgp-processing (with-current-buffer message-edit-buffer
5255 mime-edit-pgp-processing)))
5256 (setq mime-edit-pgp-processing pgp-processing))
5257 (run-hooks 'mime-edit-translate-hook)
5258 (if (catch 'mime-edit-error
5260 (mime-edit-pgp-enclose-buffer)
5261 (mime-edit-translate-body)
5263 (error "Translation error!")
5266 (run-hooks 'mime-edit-exit-hook)
5269 (defun message-mime-insert-article (&optional full-headers)
5271 (let ((message-cite-function 'mime-edit-inserted-message-filter)
5272 (message-reply-buffer
5273 (message-get-parameter-with-eval 'original-buffer))
5275 (message-yank-original nil)
5277 (narrow-to-region (goto-char start)
5278 (if (search-forward "\n\n" nil t)
5281 (goto-char (point-min))
5282 (let ((message-included-forward-headers
5283 (if full-headers "" message-included-forward-headers)))
5284 (message-remove-header message-included-forward-headers t nil t))
5287 (set-alist 'mime-edit-message-inserter-alist
5288 'message-mode (function message-mime-insert-article))
5290 ;;; Miscellaneous functions
5292 ;; stolen (and renamed) from nnheader.el
5293 (defun message-replace-chars-in-string (string from to)
5294 "Replace characters in STRING from FROM to TO."
5295 (let ((string (substring string 0)) ;Copy string.
5296 (len (length string))
5298 ;; Replace all occurrences of FROM with TO.
5300 (when (= (aref string idx) from)
5301 (aset string idx to))
5302 (setq idx (1+ idx)))
5309 (defvar message-inhibit-body-encoding t)
5311 (defun message-encode-message-body ()
5312 (unless message-inhibit-body-encoding
5313 (let ((mail-parse-charset (or mail-parse-charset
5314 message-default-charset))
5315 (case-fold-search t)
5316 lines content-type-p)
5319 (narrow-to-region (point) (point-max))
5320 (let ((new (mml-generate-mime)))
5322 (delete-region (point-min) (point-max))
5324 (goto-char (point-min))
5325 (if (eq (aref new 0) ?\n)
5327 (search-forward "\n\n")
5328 (setq lines (buffer-substring (point-min) (1- (point))))
5329 (delete-region (point-min) (point))))))
5331 (message-narrow-to-headers-or-head)
5332 (message-remove-header "Mime-Version")
5333 (goto-char (point-max))
5334 (insert "MIME-Version: 1.0\n")
5337 (setq content-type-p
5338 (re-search-backward "^Content-Type:" nil t)))
5340 (message-narrow-to-headers-or-head)
5341 (message-remove-first-header "Content-Type")
5342 (message-remove-first-header "Content-Transfer-Encoding"))
5343 ;; We always make sure that the message has a Content-Type header.
5344 ;; This is because some broken MTAs and MUAs get awfully confused
5345 ;; when confronted with a message with a MIME-Version header and
5346 ;; without a Content-Type header. For instance, Solaris'
5348 (unless content-type-p
5349 (goto-char (point-min))
5350 (re-search-forward "^MIME-Version:")
5352 (insert "Content-Type: text/plain; charset=us-ascii\n")))))
5354 (defun message-read-from-minibuffer (prompt)
5355 "Read from the minibuffer while providing abbrev expansion."
5356 (if (fboundp 'mail-abbrevs-setup)
5357 (let ((mail-abbrev-mode-regexp "")
5358 (minibuffer-setup-hook 'mail-abbrevs-setup))
5359 (read-from-minibuffer prompt)))
5360 (let ((minibuffer-setup-hook 'mail-abbrev-minibuffer-setup-hook))
5361 (read-string prompt)))
5363 (defvar message-save-buffer " *encoding")
5364 (defun message-save-drafts ()
5366 (if (not (get-buffer message-save-buffer))
5367 (get-buffer-create message-save-buffer))
5368 (let ((filename buffer-file-name)
5369 (buffer (current-buffer))
5370 (reply-headers message-reply-headers))
5371 (set-buffer message-save-buffer)
5373 (insert-buffer buffer)
5374 (setq message-reply-headers reply-headers)
5375 (message-generate-headers '((optional . In-Reply-To)))
5376 (mime-edit-translate-buffer)
5377 (write-region (point-min) (point-max) filename)
5379 (set-buffer-modified-p nil)))
5383 (run-hooks 'message-load-hook)
5386 ;; coding: iso-8859-1
5389 ;;; message.el ends here