1 ;;; message.el --- composing mail and news messages
2 ;; Copyright (C) 1996,97,98 Free Software Foundation, Inc.
4 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
5 ;; MORIOKA Tomohiko <morioka@jaist.ac.jp>
6 ;; Shuhei KOBAYASHI <shuhei-k@jaist.ac.jp>
7 ;; Keiichi Suzuki <kei-suzu@mail.wbs.ne.jp>
8 ;; Tatsuya Ichikawa <t-ichi@po.shiojiri.ne.jp>
9 ;; Katsumi Yamaoka <yamaoka@jpl.org>
10 ;; Keywords: mail, news, MIME
12 ;; This file is part of GNU Emacs.
14 ;; GNU Emacs is free software; you can redistribute it and/or modify
15 ;; it under the terms of the GNU General Public License as published by
16 ;; the Free Software Foundation; either version 2, or (at your option)
19 ;; GNU Emacs is distributed in the hope that it will be useful,
20 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
21 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 ;; GNU General Public License for more details.
24 ;; You should have received a copy of the GNU General Public License
25 ;; along with GNU Emacs; see the file COPYING. If not, write to the
26 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
27 ;; Boston, MA 02111-1307, USA.
31 ;; This mode provides mail-sending facilities from within Emacs. It
32 ;; consists mainly of large chunks of code from the sendmail.el,
33 ;; gnus-msg.el and rnewspost.el files.
46 (if (string-match "XEmacs\\|Lucid" emacs-version)
47 (require 'mail-abbrevs)
48 (require 'mailabbrev))
51 ;; Avoid byte-compile warnings.
58 (defgroup message '((user-mail-address custom-variable)
59 (user-full-name custom-variable))
60 "Mail and news message composing."
61 :link '(custom-manual "(message)Top")
65 (put 'user-mail-address 'custom-type 'string)
66 (put 'user-full-name 'custom-type 'string)
68 (defgroup message-various nil
69 "Various Message Variables"
70 :link '(custom-manual "(message)Various Message Variables")
73 (defgroup message-buffers nil
75 :link '(custom-manual "(message)Message Buffers")
78 (defgroup message-sending nil
80 :link '(custom-manual "(message)Sending Variables")
83 (defgroup message-interface nil
85 :link '(custom-manual "(message)Interface")
88 (defgroup message-forwarding nil
90 :link '(custom-manual "(message)Forwarding")
91 :group 'message-interface)
93 (defgroup message-insertion nil
95 :link '(custom-manual "(message)Insertion")
98 (defgroup message-headers nil
100 :link '(custom-manual "(message)Message Headers")
103 (defgroup message-news nil
104 "Composing News Messages"
107 (defgroup message-mail nil
108 "Composing Mail Messages"
111 (defgroup message-faces nil
112 "Faces used for message composing."
116 (defgroup message-frames nil
120 (defcustom message-directory "~/Mail/"
121 "*Directory from which all other mail file variables are derived."
122 :group 'message-various
125 (defcustom message-max-buffers 10
126 "*How many buffers to keep before starting to kill them off."
127 :group 'message-buffers
130 (defcustom message-send-rename-function nil
131 "Function called to rename the buffer after sending it."
132 :group 'message-buffers
135 (defcustom message-fcc-handler-function 'message-output
136 "*A function called to save outgoing articles.
137 This function will be called with the name of the file to store the
138 article in. The default function is `message-output' which saves in Unix
140 :type '(radio (function-item message-output)
141 (function :tag "Other"))
142 :group 'message-sending)
144 (defcustom message-encode-function 'message-maybe-encode
145 "*A function called to encode messages."
146 :group 'message-sending
149 (defcustom message-8bit-encoding-list '(8bit binary)
150 "*8bit encoding type in Content-Transfer-Encoding field."
151 :group 'message-sending
152 :type '(repeat (symbol :tag "Type")))
154 (defcustom message-courtesy-message
155 "The following message is a courtesy copy of an article\nthat has been posted to %s as well.\n\n"
156 "*This is inserted at the start of a mailed copy of a posted message.
157 If the string contains the format spec \"%s\", the Newsgroups
158 the article has been posted to will be inserted there.
159 If this variable is nil, no such courtesy message will be added."
160 :group 'message-sending
163 (defcustom message-ignored-bounced-headers "^\\(Received\\|Return-Path\\):"
164 "*Regexp that matches headers to be removed in resent bounced mail."
165 :group 'message-interface
168 (defcustom message-bounce-setup-function 'message-bounce-setup-for-mime-edit
169 "Function to setup a re-sending bounced message."
170 :group 'message-sending
174 (defcustom message-from-style 'default
175 "*Specifies how \"From\" headers look.
177 If `nil', they contain just the return address like:
179 If `parens', they look like:
180 king@grassland.com (Elvis Parsley)
181 If `angles', they look like:
182 Elvis Parsley <king@grassland.com>
184 Otherwise, most addresses look like `angles', but they look like
185 `parens' if `angles' would need quoting and `parens' would not."
186 :type '(choice (const :tag "simple" nil)
190 :group 'message-headers)
192 (defcustom message-syntax-checks nil
193 ; Guess this one shouldn't be easy to customize...
194 "*Controls what syntax checks should not be performed on outgoing posts.
195 To disable checking of long signatures, for instance, add
196 `(signature . disabled)' to this list.
198 Don't touch this variable unless you really know what you're doing.
200 Checks include subject-cmsg multiple-headers sendsys message-id from
201 long-lines control-chars size new-text redirected-followup signature
202 approved sender empty empty-headers message-id from subject
203 shorten-followup-to existing-newsgroups buffer-file-name unchanged."
204 :group 'message-news)
206 (defcustom message-required-news-headers
207 '(From Newsgroups Subject Date Message-ID
208 (optional . Organization) Lines
209 (optional . User-Agent))
210 "*Headers to be generated or prompted for when posting an article.
211 RFC977 and RFC1036 require From, Date, Newsgroups, Subject,
212 Message-ID. Organization, Lines, In-Reply-To, Expires, and
213 User-Agent are optional. If don't you want message to insert some
214 header, remove it from this list."
216 :group 'message-headers
217 :type '(repeat sexp))
219 (defcustom message-required-mail-headers
220 '(From Subject Date (optional . In-Reply-To) Message-ID Lines
221 (optional . User-Agent))
222 "*Headers to be generated or prompted for when mailing a message.
223 RFC822 required that From, Date, To, Subject and Message-ID be
224 included. Organization, Lines and User-Agent are optional."
226 :group 'message-headers
227 :type '(repeat sexp))
229 (defcustom message-deletable-headers '(Message-ID Date Lines)
230 "Headers to be deleted if they already exist and were generated by message previously."
231 :group 'message-headers
234 (defcustom message-ignored-news-headers
235 "^NNTP-Posting-Host:\\|^Xref:\\|^[BGF]cc:\\|^Resent-Fcc:"
236 "*Regexp of headers to be removed unconditionally before posting."
238 :group 'message-headers
241 (defcustom message-ignored-mail-headers "^[GF]cc:\\|^Resent-Fcc:\\|^Xref:"
242 "*Regexp of headers to be removed unconditionally before mailing."
244 :group 'message-headers
247 (defcustom message-ignored-supersedes-headers "^Path:\\|^Date\\|^NNTP-Posting-Host:\\|^Xref:\\|^Lines:\\|^Received:\\|^X-From-Line:\\|^X-Trace:\\|^X-Complaints-To:\\|Return-Path:\\|^Supersedes:"
248 "*Header lines matching this regexp will be deleted before posting.
249 It's best to delete old Path and Date headers before posting to avoid
251 :group 'message-interface
254 (defcustom message-subject-re-regexp "^[ \t]*\\([Rr][Ee]:[ \t]*\\)*[ \t]*"
255 "*Regexp matching \"Re: \" in the subject line."
256 :group 'message-various
259 ;;; Some sender agents encode the whole subject including leading "Re: ".
260 ;;; And if followup agent does not decode it for some reason (e.g. unknown
261 ;;; charset) and just add a new "Re: " in front of the encoded-word, the
262 ;;; result will contain multiple "Re: "'s.
263 (defcustom message-subject-encoded-re-regexp
267 "[-!#$%&'*+0-9A-Z^_`a-z{|}~]+" ; charset
270 "[Bb]" (regexp-quote "?") ; B encoding
271 "\\(\\(CQk\\|CSA\\|IAk\\|ICA\\)[Jg]\\)*" ; \([ \t][ \t][ \t]\)*
273 "[Uc][km]U6" ; [Rr][Ee]:
275 "\\(C[VX]\\|I[FH]\\)J[Fl]O[g-v]" ; [ \t][Rr][Ee]:
277 "\\(CQl\\|CSB\\|IAl\\|ICB\\)[Sy][RZ]T[o-r]" ; [ \t][ \t][Rr][Ee]:
280 "[Qb]" (regexp-quote "?") ; Q encoding
281 "\\(_\\|=09\\|=20\\)*"
282 "\\([Rr]\\|=[57]2\\)\\([Ee]\\|=[46]5\\)\\(:\\|=3[Aa]\\)"
285 "*Regexp matching \"Re: \" in the subject line.
286 Unlike `message-subject-re-regexp', this regexp matches \"Re: \" within
288 :group 'message-various
291 (defcustom message-use-subject-re t
292 "*If t, remove any (buggy) \"Re: \"'s from the subject of the precursor
293 and add a new \"Re: \". If it is nil, use the subject \"as-is\". If it
294 is the symbol `guess', try to detect \"Re: \" within an encoded-word."
295 :group 'message-various
296 :type '(choice (const :tag "off" nil)
301 (defcustom message-signature-separator "^-- *$"
302 "Regexp matching the signature separator."
304 :group 'message-various)
306 (defcustom message-elide-elipsis "\n[...]\n\n"
307 "*The string which is inserted for elided text."
309 :group 'message-various)
311 (defcustom message-interactive nil
312 "Non-nil means when sending a message wait for and display errors.
313 nil means let mailer mail back a message to report errors."
314 :group 'message-sending
318 (defcustom message-generate-new-buffers 'unique
319 "*Non-nil means that a new message buffer will be created whenever `message-setup' is called.
320 If this is a function, call that function with three parameters: The type,
321 the to address and the group name. (Any of these may be nil.) The function
322 should return the new buffer name."
323 :group 'message-buffers
324 :type '(choice (const :tag "off" nil)
325 (const :tag "unique" unique)
326 (const :tag "unsuniqueent" unsent)
329 (defcustom message-kill-buffer-on-exit nil
330 "*Non-nil means that the message buffer will be killed after sending a message."
331 :group 'message-buffers
334 (defcustom message-kill-buffer-query-function 'yes-or-no-p
335 "*A function called to query the user whether to kill buffer anyway or not.
336 If it is t, the buffer will be killed peremptorily."
337 :type '(radio (function-item yes-or-no-p)
338 (function-item y-or-n-p)
339 (function-item nnheader-Y-or-n-p)
340 (function :tag "Other" t))
341 :group 'message-buffers)
343 (defvar gnus-local-organization)
344 (defcustom message-user-organization
345 (or (and (boundp 'gnus-local-organization)
346 (stringp gnus-local-organization)
347 gnus-local-organization)
348 (getenv "ORGANIZATION")
350 "*String to be used as an Organization header.
351 If t, use `message-user-organization-file'."
352 :group 'message-headers
353 :type '(choice string
354 (const :tag "consult file" t)))
357 (defcustom message-user-organization-file "/usr/lib/news/organization"
358 "*Local news organization file."
360 :group 'message-headers)
362 (defcustom message-forward-start-separator
363 (concat (mime-make-tag "message" "rfc822") "\n")
364 "*Delimiter inserted before forwarded messages."
365 :group 'message-forwarding
368 (defcustom message-forward-end-separator
369 (concat (mime-make-tag "text" "plain") "\n")
370 "*Delimiter inserted after forwarded messages."
371 :group 'message-forwarding
374 (defcustom message-signature-before-forwarded-message t
375 "*If non-nil, put the signature before any included forwarded message."
376 :group 'message-forwarding
379 (defcustom message-included-forward-headers
380 "^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:"
381 "*Regexp matching headers to be included in forwarded messages."
382 :group 'message-forwarding
385 (defcustom message-make-forward-subject-function
386 'message-forward-subject-author-subject
387 "*A list of functions that are called to generate a subject header for forwarded messages.
388 The subject generated by the previous function is passed into each
391 The provided functions are:
393 * message-forward-subject-author-subject (Source of article (author or
394 newsgroup)), in brackets followed by the subject
395 * message-forward-subject-fwd (Subject of article with 'Fwd:' prepended
397 :group 'message-forwarding
398 :type '(radio (function-item message-forward-subject-author-subject)
399 (function-item message-forward-subject-fwd)))
401 (defcustom message-wash-forwarded-subjects nil
402 "*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."
403 :group 'message-forwarding
406 (defcustom message-ignored-resent-headers "^Return-Receipt"
407 "*All headers that match this regexp will be deleted when resending a message."
408 :group 'message-interface
411 (defcustom message-ignored-cited-headers "."
412 "*Delete these headers from the messages you yank."
413 :group 'message-insertion
416 (defcustom message-cancel-message "I am canceling my own article."
417 "Message to be inserted in the cancel message."
418 :group 'message-interface
421 ;; Useful to set in site-init.el
423 (defcustom message-send-mail-function 'message-send-mail-with-sendmail
424 "Function to call to send the current buffer as mail.
425 The headers should be delimited by a line whose contents match the
426 variable `mail-header-separator'.
428 Legal values include `message-send-mail-with-sendmail' (the default),
429 `message-send-mail-with-mh', `message-send-mail-with-qmail' and
430 `message-send-mail-with-smtp'."
431 :type '(radio (function-item message-send-mail-with-sendmail)
432 (function-item message-send-mail-with-mh)
433 (function-item message-send-mail-with-qmail)
434 (function-item message-send-mail-with-smtp)
435 (function :tag "Other"))
436 :group 'message-sending
437 :group 'message-mail)
439 ;; 1997-09-29 by MORIOKA Tomohiko
440 (defcustom message-send-news-function 'message-send-news-with-gnus
441 "Function to call to send the current buffer as news.
442 The headers should be delimited by a line whose contents match the
443 variable `mail-header-separator'."
444 :group 'message-sending
448 (defcustom message-reply-to-function nil
449 "Function that should return a list of headers.
450 This function should pick out addresses from the To, Cc, and From headers
451 and respond with new To and Cc headers."
452 :group 'message-interface
455 (defcustom message-wide-reply-to-function nil
456 "Function that should return a list of headers.
457 This function should pick out addresses from the To, Cc, and From headers
458 and respond with new To and Cc headers."
459 :group 'message-interface
462 (defcustom message-followup-to-function nil
463 "Function that should return a list of headers.
464 This function should pick out addresses from the To, Cc, and From headers
465 and respond with new To and Cc headers."
466 :group 'message-interface
469 (defcustom message-use-followup-to 'ask
470 "*Specifies what to do with Followup-To header.
471 If nil, always ignore the header. If it is t, use its value, but
472 query before using the \"poster\" value. If it is the symbol `ask',
473 always query the user whether to use the value. If it is the symbol
474 `use', always use the value."
475 :group 'message-interface
476 :type '(choice (const :tag "ignore" nil)
477 (const :tag "maybe" t)
478 (const :tag "always" use)
479 (const :tag "ask" ask)))
481 (defcustom message-use-mail-copies-to 'ask
482 "*Specifies what to do with Mail-Copies-To header.
483 If nil, always ignore the header. If it is t, use its value, but
484 query before using the value other than \"always\" or \"never\".
485 If it is the symbol `ask', always query the user whether to use
486 the value. If it is the symbol `use', always use the value."
487 :group 'message-interface
488 :type '(choice (const :tag "ignore" nil)
489 (const :tag "maybe" t)
490 (const :tag "always" use)
491 (const :tag "ask" ask)))
493 (defcustom message-use-mail-followup-to 'ask
494 "*Specifies what to do with Mail-Followup-To header.
495 If nil, always ignore the header. If it is the symbol `ask', always
496 query the user whether to use the value. If it is t or the symbol
497 `use', always use the value."
498 :group 'message-interface
499 :type '(choice (const :tag "ignore" nil)
500 (const :tag "maybe" t)
501 (const :tag "always" use)
502 (const :tag "ask" ask)))
504 ;;; XXX: 'ask and 'use are not implemented yet.
505 (defcustom message-use-mail-reply-to 'ask
506 "*Specifies what to do with Mail-Reply-To/Reply-To header.
507 If nil, always ignore the header. If it is t or the symbol `use', use
508 its value. If it is the symbol `ask', always query the user whether to
509 use the value. Note that if \"Reply-To\" is marked as \"broken\", its 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 ;; stuff relating to broken sendmail in MMDF
518 (defcustom message-sendmail-f-is-evil nil
519 "*Non-nil means that \"-f username\" should not be added to the sendmail
520 command line, because it is even more evil than leaving it out."
521 :group 'message-sending
524 ;; qmail-related stuff
525 (defcustom message-qmail-inject-program "/var/qmail/bin/qmail-inject"
526 "Location of the qmail-inject program."
527 :group 'message-sending
530 (defcustom message-qmail-inject-args nil
531 "Arguments passed to qmail-inject programs.
532 This should be a list of strings, one string for each argument.
534 For e.g., if you wish to set the envelope sender address so that bounces
535 go to the right place or to deal with listserv's usage of that address, you
536 might set this variable to '(\"-f\" \"you@some.where\")."
537 :group 'message-sending
538 :type '(repeat string))
540 (defvar gnus-post-method)
541 (defvar gnus-select-method)
542 (defcustom message-post-method
543 (cond ((and (boundp 'gnus-post-method)
544 (listp gnus-post-method)
547 ((boundp 'gnus-select-method)
550 "*Method used to post news.
551 Note that when posting from inside Gnus, for instance, this
552 variable isn't used."
554 :group 'message-sending
555 ;; This should be the `gnus-select-method' widget, but that might
556 ;; create a dependence to `gnus.el'.
559 (defcustom message-generate-headers-first nil
560 "*If non-nil, generate all possible headers before composing."
561 :group 'message-headers
564 (defcustom message-setup-hook '(turn-on-mime-edit)
565 "Normal hook, run each time a new outgoing message is initialized.
566 The function `message-setup' runs this hook."
567 :group 'message-various
570 (defcustom message-signature-setup-hook nil
571 "Normal hook, run each time a new outgoing message is initialized.
572 It is run after the headers have been inserted and before
573 the signature is inserted."
574 :group 'message-various
577 (defcustom message-bounce-setup-hook nil
578 "Normal hook, run each time a a re-sending bounced message is initialized.
579 The function `message-bounce' runs this hook."
580 :group 'message-various
583 (defcustom message-mode-hook nil
584 "Hook run in message mode buffers."
585 :group 'message-various
588 (defcustom message-header-hook '(eword-encode-header)
589 "Hook run in a message mode buffer narrowed to the headers."
590 :group 'message-various
593 (defcustom message-header-setup-hook nil
594 "Hook called narrowed to the headers when setting up a message buffer."
595 :group 'message-various
599 (defcustom message-citation-line-function 'message-insert-citation-line
600 "*Function called to insert the \"Whomever writes:\" line."
602 :group 'message-insertion)
605 (defcustom message-yank-prefix "> "
606 "*Prefix inserted on the lines of yanked messages.
607 nil means use indentation."
609 :group 'message-insertion)
611 (defcustom message-indentation-spaces 3
612 "*Number of spaces to insert at the beginning of each cited line.
613 Used by `message-yank-original' via `message-yank-cite'."
614 :group 'message-insertion
618 (defcustom message-cite-function 'message-cite-original
619 "*Function for citing an original message.
620 Predefined functions include `message-cite-original' and
621 `message-cite-original-without-signature'.
622 Note that `message-cite-original' uses `mail-citation-hook' if that is non-nil."
623 :type '(radio (function-item message-cite-original)
624 (function-item sc-cite-original)
625 (function :tag "Other"))
626 :group 'message-insertion)
629 (defcustom message-indent-citation-function 'message-indent-citation
630 "*Function for modifying a citation just inserted in the mail buffer.
631 This can also be a list of functions. Each function can find the
632 citation between (point) and (mark t). And each function should leave
633 point and mark around the citation text as modified."
635 :group 'message-insertion)
637 (defvar message-abbrevs-loaded nil)
640 (defcustom message-signature t
641 "*String to be inserted at the end of the message buffer.
642 If t, the `message-signature-file' file will be inserted instead.
643 If a function, the result from the function will be used instead.
644 If a form, the result from the form will be used instead."
646 :group 'message-insertion)
649 (defcustom message-signature-file "~/.signature"
650 "*File containing the text inserted at end of message buffer."
652 :group 'message-insertion)
654 (defcustom message-distribution-function nil
655 "*Function called to return a Distribution header."
657 :group 'message-headers
660 (defcustom message-expires 14
661 "Number of days before your article expires."
663 :group 'message-headers
664 :link '(custom-manual "(message)News Headers")
667 (defcustom message-user-path nil
668 "If nil, use the NNTP server name in the Path header.
669 If stringp, use this; if non-nil, use no host name (user name only)."
671 :group 'message-headers
672 :link '(custom-manual "(message)News Headers")
673 :type '(choice (const :tag "nntp" nil)
675 (sexp :tag "none" :format "%t" t)))
677 (defvar message-reply-buffer nil)
678 (defvar message-reply-headers nil)
679 (defvar message-sent-message-via nil)
680 (defvar message-checksum nil)
681 (defvar message-send-actions nil
682 "A list of actions to be performed upon successful sending of a message.")
683 (defvar message-exit-actions nil
684 "A list of actions to be performed upon exiting after sending a message.")
685 (defvar message-kill-actions nil
686 "A list of actions to be performed before killing a message buffer.")
687 (defvar message-postpone-actions nil
688 "A list of actions to be performed after postponing a message.")
689 (defvar message-original-frame nil)
690 (defvar message-parameter-alist nil)
691 (defvar message-startup-parameter-alist nil)
693 (define-widget 'message-header-lines 'text
694 "All header lines must be LFD terminated."
697 :error "All header lines must be newline terminated")
699 (defcustom message-default-headers ""
700 "*A string containing header lines to be inserted in outgoing messages.
701 It is inserted before you edit the message, so you can edit or delete
703 :group 'message-headers
704 :type 'message-header-lines)
706 (defcustom message-default-mail-headers ""
707 "*A string of header lines to be inserted in outgoing mails."
708 :group 'message-headers
710 :type 'message-header-lines)
712 (defcustom message-default-news-headers ""
713 "*A string of header lines to be inserted in outgoing news
715 :group 'message-headers
717 :type 'message-header-lines)
719 ;; Note: could use /usr/ucb/mail instead of sendmail;
720 ;; options -t, and -v if not interactive.
721 (defcustom message-mailer-swallows-blank-line
722 (if (and (string-match "sparc-sun-sunos\\(\\'\\|[^5]\\)"
723 system-configuration)
724 (file-readable-p "/etc/sendmail.cf")
725 (let ((buffer (get-buffer-create " *temp*")))
729 (insert-file-contents "/etc/sendmail.cf")
730 (goto-char (point-min))
731 (let ((case-fold-search nil))
732 (re-search-forward "^OR\\>" nil t)))
733 (kill-buffer buffer))))
734 ;; According to RFC822, "The field-name must be composed of printable
735 ;; ASCII characters (i. e., characters that have decimal values between
736 ;; 33 and 126, except colon)", i. e., any chars except ctl chars,
738 '(looking-at "[ \t]\\|[][!\"#$%&'()*+,-./0-9;<=>?@A-Z\\\\^_`a-z{|}~]+:"))
739 "*Set this non-nil if the system's mailer runs the header and body together.
740 \(This problem exists on Sunos 4 when sendmail is run in remote mode.)
741 The value should be an expression to test whether the problem will
743 :group 'message-sending
746 ;;; XXX: This symbol is overloaded! See below.
747 (defvar message-user-agent nil
748 "String of the form of PRODUCT/VERSION. Used for User-Agent header field.")
750 ;; Ignore errors in case this is used in Emacs 19.
751 ;; Don't use ignore-errors because this is copied into loaddefs.el.
754 (define-mail-user-agent 'message-user-agent
755 'message-mail 'message-send-and-exit
756 'message-kill-buffer 'message-send-hook)
759 (defvar message-mh-deletable-headers '(Message-ID Date Lines Sender)
760 "If non-nil, delete the deletable headers before feeding to mh.")
762 (defvar message-send-method-alist
763 '((news message-news-p message-send-via-news)
764 (mail message-mail-p message-send-via-mail))
765 "Alist of ways to send outgoing messages.
766 Each element has the form
768 \(TYPE PREDICATE FUNCTION)
770 where TYPE is a symbol that names the method; PREDICATE is a function
771 called without any parameters to determine whether the message is
772 a message of type TYPE; and FUNCTION is a function to be called if
773 PREDICATE returns non-nil. FUNCTION is called with one parameter --
776 (defvar message-mail-alias-type 'abbrev
777 "*What alias expansion type to use in Message buffers.
778 The default is `abbrev', which uses mailabbrev. nil switches
781 (defcustom message-auto-save-directory
782 (nnheader-concat message-directory "drafts/")
783 "*Directory where Message auto-saves buffers if Gnus isn't running.
784 If nil, Message won't auto-save."
785 :group 'message-buffers
788 (defcustom message-buffer-naming-style 'unique
789 "*The way new message buffers are named.
790 Valid valued are `unique' and `unsent'."
791 :group 'message-buffers
792 :type '(choice (const :tag "unique" unique)
793 (const :tag "unsent" unsent)))
795 ;;; Internal variables.
796 ;;; Well, not really internal.
798 (defvar message-mode-syntax-table
799 (let ((table (copy-syntax-table text-mode-syntax-table)))
800 (modify-syntax-entry ?% ". " table)
802 "Syntax table used while in Message mode.")
804 (defvar message-mode-abbrev-table text-mode-abbrev-table
805 "Abbrev table used in Message mode buffers.
806 Defaults to `text-mode-abbrev-table'.")
807 (defgroup message-headers nil
809 :link '(custom-manual "(message)Variables")
812 (defface message-header-to-face
815 (:foreground "green2" :bold t))
818 (:foreground "MidnightBlue" :bold t))
820 (:bold t :italic t)))
821 "Face used for displaying From headers."
822 :group 'message-faces)
824 (defface message-header-cc-face
827 (:foreground "green4" :bold t))
830 (:foreground "MidnightBlue"))
833 "Face used for displaying Cc headers."
834 :group 'message-faces)
836 (defface message-header-subject-face
839 (:foreground "green3"))
842 (:foreground "navy blue" :bold t))
845 "Face used for displaying subject headers."
846 :group 'message-faces)
848 (defface message-header-newsgroups-face
851 (:foreground "yellow" :bold t :italic t))
854 (:foreground "blue4" :bold t :italic t))
856 (:bold t :italic t)))
857 "Face used for displaying newsgroups headers."
858 :group 'message-faces)
860 (defface message-header-other-face
863 (:foreground "#b00000"))
866 (:foreground "steel blue"))
868 (:bold t :italic t)))
869 "Face used for displaying newsgroups headers."
870 :group 'message-faces)
872 (defface message-header-name-face
875 (:foreground "DarkGreen"))
878 (:foreground "cornflower blue"))
881 "Face used for displaying header names."
882 :group 'message-faces)
884 (defface message-header-xheader-face
887 (:foreground "blue"))
890 (:foreground "blue"))
893 "Face used for displaying X-Header headers."
894 :group 'message-faces)
896 (defface message-separator-face
899 (:foreground "blue3"))
902 (:foreground "brown"))
905 "Face used for displaying the separator."
906 :group 'message-faces)
908 (defface message-cited-text-face
917 "Face used for displaying cited text names."
918 :group 'message-faces)
920 (defvar message-font-lock-keywords
921 (let* ((cite-prefix "A-Za-z")
922 (cite-suffix (concat cite-prefix "0-9_.@-"))
923 (content "[ \t]*\\(.+\\(\n[ \t].*\\)*\\)"))
924 `((,(concat "^\\([Tt]o:\\)" content)
925 (1 'message-header-name-face)
926 (2 'message-header-to-face nil t))
927 (,(concat "^\\([GBF]?[Cc][Cc]:\\|[Rr]eply-[Tt]o:\\|"
928 "[Mm]ail-[Cc]opies-[Tt]o:\\|"
929 "[Mm]ail-[Rr]eply-[Tt]o:\\|"
930 "[Mm]ail-[Ff]ollowup-[Tt]o:\\)" content)
931 (1 'message-header-name-face)
932 (2 'message-header-cc-face nil t))
933 (,(concat "^\\([Ss]ubject:\\)" content)
934 (1 'message-header-name-face)
935 (2 'message-header-subject-face nil t))
936 (,(concat "^\\([Nn]ewsgroups:\\|Followup-[Tt]o:\\)" content)
937 (1 'message-header-name-face)
938 (2 'message-header-newsgroups-face nil t))
939 (,(concat "^\\([A-Z][^: \n\t]+:\\)" content)
940 (1 'message-header-name-face)
941 (2 'message-header-other-face nil t))
942 (,(concat "^\\(X-[A-Za-z0-9-]+\\|In-Reply-To\\):" content)
943 (1 'message-header-name-face)
944 (2 'message-header-name-face))
945 ,@(if (and mail-header-separator
946 (not (equal mail-header-separator "")))
947 `((,(concat "^\\(" (regexp-quote mail-header-separator) "\\)$")
948 1 'message-separator-face))
951 "\\([" cite-prefix "]+[" cite-suffix "]*\\)?"
953 (0 'message-cited-text-face))))
954 "Additional expressions to highlight in Message mode.")
956 ;; XEmacs does it like this. For Emacs, we have to set the
957 ;; `font-lock-defaults' buffer-local variable.
958 (put 'message-mode 'font-lock-defaults '(message-font-lock-keywords t))
960 (defvar message-face-alist
961 '((bold . bold-region)
962 (underline . underline-region)
963 (default . (lambda (b e)
965 (ununderline-region b e))))
966 "Alist of mail and news faces for facemenu.
967 The cdr of ech entry is a function for applying the face to a region.")
969 (defcustom message-send-hook nil
970 "Hook run before sending messages."
971 :group 'message-various
972 :options '(ispell-message)
975 (defcustom message-send-mail-hook nil
976 "Hook run before sending mail messages."
977 :group 'message-various
980 (defcustom message-send-news-hook nil
981 "Hook run before sending news messages."
982 :group 'message-various
985 (defcustom message-sent-hook nil
986 "Hook run after sending messages."
987 :group 'message-various
990 (defcustom message-use-multi-frames nil
991 "Make new frame when sending messages."
992 :group 'message-frames
995 (defcustom message-delete-frame-on-exit nil
996 "Delete frame after sending messages."
997 :group 'message-frames
998 :type '(choice (const :tag "off" nil)
999 (const :tag "always" t)
1000 (const :tag "ask" ask)))
1002 (defvar message-send-coding-system 'binary
1003 "Coding system to encode outgoing mail.")
1005 ;;; Internal variables.
1007 (defvar message-default-charset nil)
1008 (defvar message-buffer-list nil)
1009 (defvar message-this-is-news nil)
1010 (defvar message-this-is-mail nil)
1011 (defvar message-draft-article nil)
1013 ;; Byte-compiler warning
1014 (defvar gnus-active-hashtb)
1015 (defvar gnus-read-active-file)
1017 ;;; Regexp matching the delimiter of messages in UNIX mail format
1018 ;;; (UNIX From lines), minus the initial ^. It should be a copy
1019 ;;; of rmail.el's rmail-unix-mail-delimiter.
1020 (defvar message-unix-mail-delimiter
1021 (let ((time-zone-regexp
1022 (concat "\\([A-Z]?[A-Z]?[A-Z][A-Z]\\( DST\\)?"
1023 "\\|[-+]?[0-9][0-9][0-9][0-9]"
1029 ;; Many things can happen to an RFC 822 mailbox before it is put into
1030 ;; a `From' line. The leading phrase can be stripped, e.g.
1031 ;; `Joe <@w.x:joe@y.z>' -> `<@w.x:joe@y.z>'. The <> can be stripped, e.g.
1032 ;; `<@x.y:joe@y.z>' -> `@x.y:joe@y.z'. Everything starting with a CRLF
1033 ;; can be removed, e.g.
1034 ;; From: joe@y.z (Joe K
1036 ;; can yield `From joe@y.z (Joe K Fri Mar 22 08:11:15 1996', and
1039 ;; can yield `From Joe User Fri Mar 22 08:11:15 1996'.
1040 ;; The mailbox can be removed or be replaced by white space, e.g.
1041 ;; From: "Joe User"{space}{tab}
1043 ;; can yield `From {space}{tab} Fri Mar 22 08:11:15 1996',
1044 ;; where {space} and {tab} represent the Ascii space and tab characters.
1045 ;; We want to match the results of any of these manglings.
1046 ;; The following regexp rejects names whose first characters are
1047 ;; obviously bogus, but after that anything goes.
1048 "\\([^\0-\b\n-\r\^?].*\\)? "
1050 ;; The time the message was sent.
1051 "\\([^\0-\r \^?]+\\) +" ; day of the week
1052 "\\([^\0-\r \^?]+\\) +" ; month
1053 "\\([0-3]?[0-9]\\) +" ; day of month
1054 "\\([0-2][0-9]:[0-5][0-9]\\(:[0-6][0-9]\\)?\\) *" ; time of day
1056 ;; Perhaps a time zone, specified by an abbreviation, or by a
1061 " \\([0-9][0-9]+\\) *"
1063 ;; On some systems the time zone can appear after the year, too.
1067 "\\(remote from .*\\)?"
1070 "Regexp matching the delimiter of messages in UNIX mail format.")
1072 (defvar message-unsent-separator
1073 (concat "^ *---+ +Unsent message follows +---+ *$\\|"
1074 "^ *---+ +Returned message +---+ *$\\|"
1075 "^Start of returned message$\\|"
1076 "^ *---+ +Original message +---+ *$\\|"
1077 "^ *--+ +begin message +--+ *$\\|"
1078 "^ *---+ +Original message follows +---+ *$\\|"
1079 "^|? *---+ +Message text follows: +---+ *|?$")
1080 "A regexp that matches the separator before the text of a failed message.")
1082 (defvar message-header-format-alist
1084 (To . message-fill-address)
1085 (Cc . message-fill-address)
1096 (References . message-fill-header)
1098 "Alist used for formatting headers.")
1101 (autoload 'message-setup-toolbar "messagexmas")
1102 (autoload 'mh-new-draft-name "mh-comp")
1103 (autoload 'mh-send-letter "mh-comp")
1104 (autoload 'gnus-point-at-eol "gnus-util")
1105 (autoload 'gnus-point-at-bol "gnus-util")
1106 (autoload 'gnus-output-to-mail "gnus-util")
1107 (autoload 'mail-abbrev-in-expansion-header-p "mailabbrev")
1108 (autoload 'nndraft-request-associate-buffer "nndraft")
1109 (autoload 'nndraft-request-expire-articles "nndraft")
1110 (autoload 'gnus-open-server "gnus-int")
1111 (autoload 'gnus-request-post "gnus-int")
1112 (autoload 'gnus-copy-article-buffer "gnus-msg")
1113 (autoload 'gnus-alive-p "gnus-util")
1114 (autoload 'rmail-output "rmail"))
1119 ;;; Utility functions.
1122 (defmacro message-y-or-n-p (question show &rest text)
1123 "Ask QUESTION, displaying the rest of the arguments in a temp. buffer if SHOW"
1124 `(message-talkative-question 'y-or-n-p ,question ,show ,@text))
1126 ;; Delete the current line (and the next N lines.);
1127 (defmacro message-delete-line (&optional n)
1128 `(delete-region (progn (beginning-of-line) (point))
1129 (progn (forward-line ,(or n 1)) (point))))
1131 (defun message-tokenize-header (header &optional separator)
1132 "Split HEADER into a list of header elements.
1133 \",\" is used as the separator."
1136 (let ((regexp (format "[%s]+" (or separator ",")))
1141 (message-set-work-buffer)
1143 (goto-char (point-min))
1148 (cond ((and (> (point) beg)
1150 (and (looking-at regexp)
1153 (push (buffer-substring beg (point)) elems)
1154 (setq beg (match-end 0)))
1155 ((eq (char-after) ?\")
1156 (setq quoted (not quoted)))
1157 ((and (eq (char-after) ?\()
1160 ((and (eq (char-after) ?\))
1163 (nreverse elems)))))
1165 (defun message-mail-file-mbox-p (file)
1166 "Say whether FILE looks like a Unix mbox file."
1167 (when (and (file-exists-p file)
1168 (file-readable-p file)
1169 (file-regular-p file))
1171 (nnheader-insert-file-contents file)
1172 (goto-char (point-min))
1173 (looking-at message-unix-mail-delimiter))))
1175 (defun message-fetch-field (header &optional not-all)
1176 "The same as `mail-fetch-field', only remove all newlines."
1177 (let* ((inhibit-point-motion-hooks t)
1178 (value (mail-fetch-field header nil (not not-all))))
1180 (while (string-match "\n[\t ]+" value)
1181 (setq value (replace-match " " t t value)))
1184 (defun message-narrow-to-field ()
1185 "Narrow the buffer to the header on the current line."
1191 (if (re-search-forward "^[^ \n\t]" nil t)
1196 (goto-char (point-min)))
1198 (defun message-add-header (&rest headers)
1199 "Add the HEADERS to the message header, skipping those already present."
1202 (unless (string-match "^\\([^:]+\\):[ \t]*[^ \t]" (car headers))
1203 (error "Invalid header `%s'" (car headers)))
1204 (setq hclean (match-string 1 (car headers)))
1206 (message-narrow-to-headers)
1207 (unless (re-search-forward (concat "^" (regexp-quote hclean) ":") nil t)
1208 (insert (car headers) ?\n))))
1209 (setq headers (cdr headers))))
1211 (defun message-fetch-reply-field (header)
1212 "Fetch FIELD from the message we're replying to."
1213 (let ((buffer (message-get-reply-buffer)))
1215 (buffer-name buffer))
1218 (message-fetch-field header)))))
1220 (defun message-set-work-buffer ()
1221 (if (get-buffer " *message work*")
1223 (set-buffer " *message work*")
1225 (set-buffer (get-buffer-create " *message work*"))
1226 (kill-all-local-variables)))
1228 (defun message-functionp (form)
1229 "Return non-nil if FORM is funcallable."
1230 (or (and (symbolp form) (fboundp form))
1231 (and (listp form) (eq (car form) 'lambda))
1232 (byte-code-function-p form)))
1234 (defun message-strip-subject-re (subject)
1235 "Remove \"Re:\" from subject lines."
1236 (if (string-match message-subject-re-regexp subject)
1237 (substring subject (match-end 0))
1240 (defun message-remove-header (header &optional is-regexp first reverse)
1241 "Remove HEADER in the narrowed buffer.
1242 If REGEXP, HEADER is a regular expression.
1243 If FIRST, only remove the first instance of the header.
1244 Return the number of headers removed."
1245 (goto-char (point-min))
1246 (let ((regexp (if is-regexp header (concat "^" (regexp-quote header) ":")))
1248 (case-fold-search t)
1250 (while (and (not (eobp))
1253 (not (looking-at regexp))
1254 (looking-at regexp))
1261 ;; There might be a continuation header, so we have to search
1262 ;; until we find a new non-continuation line.
1265 (if (re-search-forward "^[^ \t]" nil t)
1266 (goto-char (match-beginning 0))
1269 (if (re-search-forward "^[^ \t]" nil t)
1270 (goto-char (match-beginning 0))
1274 (defun message-narrow-to-headers ()
1275 "Narrow the buffer to the head of the message."
1278 (goto-char (point-min))
1279 (if (re-search-forward
1280 (concat "^" (regexp-quote mail-header-separator) "\n") nil t)
1283 (goto-char (point-min)))
1285 (defun message-narrow-to-head ()
1286 "Narrow the buffer to the head of the message.
1287 Point is left at the beginning of the narrowed-to region."
1290 (goto-char (point-min))
1291 (if (search-forward "\n\n" nil 1)
1294 (goto-char (point-min)))
1296 (defun message-narrow-to-headers-or-head ()
1297 "Narrow the buffer to the head of the message."
1300 (goto-char (point-min))
1303 (concat "^" (regexp-quote mail-header-separator) "\n") nil t)
1304 (match-beginning 0))
1305 ((search-forward "\n\n" nil t)
1309 (goto-char (point-min)))
1311 (defun message-news-p ()
1312 "Say whether the current buffer contains a news message."
1313 (and (not message-this-is-mail)
1314 (or message-this-is-news
1317 (message-narrow-to-headers)
1318 (and (message-fetch-field "newsgroups")
1319 (not (message-fetch-field "posted-to"))))))))
1321 (defun message-mail-p ()
1322 "Say whether the current buffer contains a mail message."
1323 (and (not message-this-is-news)
1324 (or message-this-is-mail
1327 (message-narrow-to-headers)
1328 (or (message-fetch-field "to")
1329 (message-fetch-field "cc")
1330 (message-fetch-field "bcc")))))))
1332 (defun message-next-header ()
1333 "Go to the beginning of the next header."
1335 (or (eobp) (forward-char 1))
1336 (not (if (re-search-forward "^[^ \t]" nil t)
1338 (goto-char (point-max)))))
1340 (defun message-sort-headers-1 ()
1341 "Sort the buffer as headers using `message-rank' text props."
1342 (goto-char (point-min))
1344 nil 'message-next-header
1346 (message-next-header)
1350 (or (get-text-property (point) 'message-rank)
1353 (defun message-sort-headers ()
1354 "Sort the headers of the current message according to `message-header-format-alist'."
1358 (let ((max (1+ (length message-header-format-alist)))
1360 (message-narrow-to-headers)
1361 (while (re-search-forward "^[^ \n]+:" nil t)
1363 (match-beginning 0) (1+ (match-beginning 0))
1365 (if (setq rank (length (memq (assq (intern (buffer-substring
1367 (1- (match-end 0))))
1368 message-header-format-alist)
1369 message-header-format-alist)))
1372 (message-sort-headers-1))))
1374 (defun message-eval-parameter (parameter)
1376 (if (symbolp parameter)
1377 (if (functionp parameter)
1383 (defun message-get-reply-buffer ()
1384 (message-eval-parameter message-reply-buffer))
1386 (defun message-get-original-reply-buffer ()
1387 (message-eval-parameter
1388 (cdr (assq 'original-buffer message-parameter-alist))))
1398 (defvar message-mode-map nil)
1400 (unless message-mode-map
1401 (setq message-mode-map (make-keymap))
1402 (set-keymap-parent message-mode-map text-mode-map)
1403 (define-key message-mode-map "\C-c?" 'describe-mode)
1405 (define-key message-mode-map "\C-c\C-f\C-t" 'message-goto-to)
1406 (define-key message-mode-map "\C-c\C-f\C-b" 'message-goto-bcc)
1407 (define-key message-mode-map "\C-c\C-f\C-w" 'message-goto-fcc)
1408 (define-key message-mode-map "\C-c\C-f\C-c" 'message-goto-cc)
1409 (define-key message-mode-map "\C-c\C-f\C-s" 'message-goto-subject)
1410 ;; (define-key message-mode-map "\C-c\C-f\C-r" 'message-goto-reply-to)
1411 (define-key message-mode-map "\C-c\C-f\C-r" 'message-goto-mail-reply-to)
1412 (define-key message-mode-map "\C-c\C-f\C-m" 'message-goto-mail-followup-to)
1413 (define-key message-mode-map "\C-c\C-f\C-n" 'message-goto-newsgroups)
1414 (define-key message-mode-map "\C-c\C-f\C-d" 'message-goto-distribution)
1415 (define-key message-mode-map "\C-c\C-f\C-f" 'message-goto-followup-to)
1416 (define-key message-mode-map "\C-c\C-f\C-k" 'message-goto-keywords)
1417 (define-key message-mode-map "\C-c\C-f\C-u" 'message-goto-summary)
1418 (define-key message-mode-map "\C-c\C-b" 'message-goto-body)
1419 (define-key message-mode-map "\C-c\C-i" 'message-goto-signature)
1421 (define-key message-mode-map "\C-c\C-t" 'message-insert-to)
1422 (define-key message-mode-map "\C-c\C-n" 'message-insert-newsgroups)
1424 (define-key message-mode-map "\C-c\C-y" 'message-yank-original)
1425 (define-key message-mode-map "\C-c\C-q" 'message-fill-yanked-message)
1426 (define-key message-mode-map "\C-c\C-w" 'message-insert-signature)
1427 (define-key message-mode-map "\C-c\C-r" 'message-caesar-buffer-body)
1428 (define-key message-mode-map "\C-c\C-o" 'message-sort-headers)
1429 (define-key message-mode-map "\C-c\M-r" 'message-rename-buffer)
1431 (define-key message-mode-map "\C-c\C-c" 'message-send-and-exit)
1432 (define-key message-mode-map "\C-c\C-s" 'message-send)
1433 (define-key message-mode-map "\C-c\C-k" 'message-kill-buffer)
1434 (define-key message-mode-map "\C-c\C-d" 'message-dont-send)
1436 (define-key message-mode-map "\C-c\C-e" 'message-elide-region)
1437 (define-key message-mode-map "\C-c\C-v" 'message-delete-not-region)
1438 (define-key message-mode-map "\C-c\C-z" 'message-kill-to-signature)
1439 (define-key message-mode-map "\M-\r" 'message-newline-and-reformat)
1441 (define-key message-mode-map "\t" 'message-tab)
1443 (define-key message-mode-map "\C-x\C-s" 'message-save-drafts)
1444 (define-key message-mode-map "\C-xk" 'message-kill-buffer))
1447 message-mode-menu message-mode-map "Message Menu."
1449 ["Sort Headers" message-sort-headers t]
1450 ["Yank Original" message-yank-original t]
1451 ["Fill Yanked Message" message-fill-yanked-message t]
1452 ["Insert Signature" message-insert-signature t]
1453 ["Caesar (rot13) Message" message-caesar-buffer-body t]
1454 ["Caesar (rot13) Region" message-caesar-region (mark t)]
1455 ["Elide Region" message-elide-region (mark t)]
1456 ["Delete Outside Region" message-delete-not-region (mark t)]
1457 ["Kill To Signature" message-kill-to-signature t]
1458 ["Newline and Reformat" message-newline-and-reformat t]
1459 ["Rename buffer" message-rename-buffer t]
1460 ["Spellcheck" ispell-message t]
1462 ["Send Message" message-send-and-exit t]
1463 ["Abort Message" message-dont-send t]
1464 ["Kill Message" message-kill-buffer t]))
1467 message-mode-field-menu message-mode-map ""
1469 ["Fetch To" message-insert-to t]
1470 ["Fetch Newsgroups" message-insert-newsgroups t]
1472 ["To" message-goto-to t]
1473 ["Subject" message-goto-subject t]
1474 ["Cc" message-goto-cc t]
1475 ["Reply-To" message-goto-reply-to t]
1476 ["Mail-Reply-To" message-goto-mail-reply-to t]
1477 ["Mail-Followup-To" message-goto-mail-followup-to t]
1478 ["Mail-Copies-To" message-goto-mail-copies-to t]
1479 ["Summary" message-goto-summary t]
1480 ["Keywords" message-goto-keywords t]
1481 ["Newsgroups" message-goto-newsgroups t]
1482 ["Followup-To" message-goto-followup-to t]
1483 ["Distribution" message-goto-distribution t]
1484 ["Body" message-goto-body t]
1485 ["Signature" message-goto-signature t]))
1487 (defvar facemenu-add-face-function)
1488 (defvar facemenu-remove-face-function)
1491 (defun message-mode ()
1492 "Major mode for editing mail and news to be sent.
1493 Like Text Mode but with these additional commands:
1494 C-c C-s message-send (send the message) C-c C-c message-send-and-exit
1495 C-c C-f move to a header field (and create it if there isn't):
1496 C-c C-f C-t move to To C-c C-f C-s move to Subject
1497 C-c C-f C-c move to Cc C-c C-f C-b move to Bcc
1498 C-c C-f C-w move to Fcc C-c C-f C-r move to Reply-To
1499 C-c C-f C-u move to Summary C-c C-f C-n move to Newsgroups
1500 C-c C-f C-k move to Keywords C-c C-f C-d move to Distribution
1501 C-c C-f C-m move to Mail-Followup-To
1502 C-c C-f C-f move to Followup-To
1503 C-c C-t message-insert-to (add a To header to a news followup)
1504 C-c C-n message-insert-newsgroups (add a Newsgroup header to a news reply)
1505 C-c C-b message-goto-body (move to beginning of message text).
1506 C-c C-i message-goto-signature (move to the beginning of the signature).
1507 C-c C-w message-insert-signature (insert `message-signature-file' file).
1508 C-c C-y message-yank-original (insert current message, if any).
1509 C-c C-q message-fill-yanked-message (fill what was yanked).
1510 C-c C-e message-elide-region (elide the text between point and mark).
1511 C-c C-v message-delete-not-region (remove the text outside the region).
1512 C-c C-z message-kill-to-signature (kill the text up to the signature).
1513 C-c C-r message-caesar-buffer-body (rot13 the message body)."
1515 (kill-all-local-variables)
1516 (make-local-variable 'message-reply-buffer)
1517 (setq message-reply-buffer nil)
1518 (make-local-variable 'message-send-actions)
1519 (make-local-variable 'message-exit-actions)
1520 (make-local-variable 'message-kill-actions)
1521 (make-local-variable 'message-postpone-actions)
1522 (make-local-variable 'message-draft-article)
1523 (make-local-hook 'kill-buffer-hook)
1524 (set-syntax-table message-mode-syntax-table)
1525 (use-local-map message-mode-map)
1526 (setq local-abbrev-table message-mode-abbrev-table)
1527 (setq major-mode 'message-mode)
1528 (setq mode-name "Message")
1529 (setq buffer-offer-save t)
1530 (make-local-variable 'facemenu-add-face-function)
1531 (make-local-variable 'facemenu-remove-face-function)
1532 (setq facemenu-add-face-function
1534 (let ((face-fun (cdr (assq face message-face-alist))))
1536 (funcall face-fun (point) end)
1537 (error "Face %s not configured for %s mode" face mode-name)))
1539 facemenu-remove-face-function t)
1540 (make-local-variable 'paragraph-separate)
1541 (make-local-variable 'paragraph-start)
1542 ;; `-- ' precedes the signature. `-----' appears at the start of the
1543 ;; lines that delimit forwarded messages.
1544 ;; Lines containing just >= 3 dashes, perhaps after whitespace,
1545 ;; are also sometimes used and should be separators.
1546 (setq paragraph-start
1547 (concat (regexp-quote mail-header-separator)
1548 "$\\|[ \t]*[a-z0-9A-Z]*>+[ \t]*$\\|[ \t]*$\\|"
1551 ;;!!! Uhm... shurely this can't be right?
1552 "[> " (regexp-quote message-yank-prefix) "]+$"))
1553 (setq paragraph-separate paragraph-start)
1554 (make-local-variable 'message-reply-headers)
1555 (setq message-reply-headers nil)
1556 (make-local-variable 'message-user-agent)
1557 (make-local-variable 'message-post-method)
1558 (make-local-variable 'message-sent-message-via)
1559 (setq message-sent-message-via nil)
1560 (make-local-variable 'message-checksum)
1561 (setq message-checksum nil)
1562 (make-local-variable 'message-parameter-alist)
1563 (setq message-parameter-alist
1564 (copy-sequence message-startup-parameter-alist))
1565 ;;(when (fboundp 'mail-hist-define-keys)
1566 ;; (mail-hist-define-keys))
1567 (when (string-match "XEmacs\\|Lucid" emacs-version)
1568 (message-setup-toolbar))
1569 (easy-menu-add message-mode-menu message-mode-map)
1570 (easy-menu-add message-mode-field-menu message-mode-map)
1571 ;; Allow mail alias things.
1572 (when (eq message-mail-alias-type 'abbrev)
1573 (if (fboundp 'mail-abbrevs-setup)
1574 (mail-abbrevs-setup)
1575 (mail-aliases-setup)))
1576 (message-set-auto-save-file-name)
1577 (unless (string-match "XEmacs" emacs-version)
1578 (set (make-local-variable 'font-lock-defaults)
1579 '(message-font-lock-keywords t)))
1580 (make-local-variable 'adaptive-fill-regexp)
1581 (setq adaptive-fill-regexp
1582 (concat "[ \t]*[-a-z0-9A-Z]*>+[ \t]*\\|" adaptive-fill-regexp))
1583 (unless (boundp 'adaptive-fill-first-line-regexp)
1584 (setq adaptive-fill-first-line-regexp nil))
1585 (make-local-variable 'adaptive-fill-first-line-regexp)
1586 (setq adaptive-fill-first-line-regexp
1587 (concat "[ \t]*[-a-z0-9A-Z]*>+[ \t]*\\|"
1588 adaptive-fill-first-line-regexp))
1589 (run-hooks 'text-mode-hook 'message-mode-hook))
1594 ;;; Message mode commands
1597 ;;; Movement commands
1599 (defun message-goto-to ()
1600 "Move point to the To header."
1602 (message-position-on-field "To"))
1604 (defun message-goto-subject ()
1605 "Move point to the Subject header."
1607 (message-position-on-field "Subject"))
1609 (defun message-goto-cc ()
1610 "Move point to the Cc header."
1612 (message-position-on-field "Cc" "To"))
1614 (defun message-goto-bcc ()
1615 "Move point to the Bcc header."
1617 (message-position-on-field "Bcc" "Cc" "To"))
1619 (defun message-goto-fcc ()
1620 "Move point to the Fcc header."
1622 (message-position-on-field "Fcc" "To" "Newsgroups"))
1624 (defun message-goto-reply-to ()
1625 "Move point to the Reply-To header."
1627 (message-position-on-field "Reply-To" "Subject"))
1629 (defun message-goto-mail-reply-to ()
1630 "Move point to the Mail-Reply-To header."
1632 (message-position-on-field "Mail-Reply-To" "Subject"))
1634 (defun message-goto-mail-followup-to ()
1635 "Move point to the Mail-Followup-To header."
1637 (message-position-on-field "Mail-Followup-To" "Subject"))
1639 (defun message-goto-mail-copies-to ()
1640 "Move point to the Mail-Copies-To header."
1642 (message-position-on-field "Mail-Copies-To" "Subject"))
1644 (defun message-goto-newsgroups ()
1645 "Move point to the Newsgroups header."
1647 (message-position-on-field "Newsgroups"))
1649 (defun message-goto-distribution ()
1650 "Move point to the Distribution header."
1652 (message-position-on-field "Distribution"))
1654 (defun message-goto-followup-to ()
1655 "Move point to the Followup-To header."
1657 (message-position-on-field "Followup-To" "Newsgroups"))
1659 (defun message-goto-keywords ()
1660 "Move point to the Keywords header."
1662 (message-position-on-field "Keywords" "Subject"))
1664 (defun message-goto-summary ()
1665 "Move point to the Summary header."
1667 (message-position-on-field "Summary" "Subject"))
1669 (defun message-goto-body ()
1670 "Move point to the beginning of the message body."
1672 (if (looking-at "[ \t]*\n") (expand-abbrev))
1673 (goto-char (point-min))
1674 (search-forward (concat "\n" mail-header-separator "\n") nil t))
1676 (defun message-goto-eoh ()
1677 "Move point to the end of the headers."
1682 (defun message-goto-signature ()
1683 "Move point to the beginning of the message signature.
1684 If there is no signature in the article, go to the end and
1687 (goto-char (point-min))
1688 (if (re-search-forward message-signature-separator nil t)
1690 (goto-char (point-max))
1695 (defun message-insert-to (&optional force)
1696 "Insert a To header that points to the author of the article being replied to.
1697 If the original author requested not to be sent mail, the function signals
1699 With the prefix argument FORCE, insert the header anyway."
1701 (let ((co (message-fetch-reply-field "mail-copies-to")))
1702 (when (and (null force)
1704 (or (equal (downcase co) "never")
1705 (equal (downcase co) "nobody")))
1706 (error "The user has requested not to have copies sent via mail")))
1707 (when (and (message-position-on-field "To")
1708 (mail-fetch-field "to")
1709 (not (string-match "\\` *\\'" (mail-fetch-field "to"))))
1711 (insert (or (message-fetch-reply-field "reply-to")
1712 (message-fetch-reply-field "from") "")))
1714 (defun message-insert-newsgroups ()
1715 "Insert the Newsgroups header from the article being replied to."
1717 (when (and (message-position-on-field "Newsgroups")
1718 (mail-fetch-field "newsgroups")
1719 (not (string-match "\\` *\\'" (mail-fetch-field "newsgroups"))))
1721 (insert (or (message-fetch-reply-field "newsgroups") "")))
1725 ;;; Various commands
1727 (defun message-delete-not-region (beg end)
1728 "Delete everything in the body of the current message that is outside of the region."
1732 (delete-region (point) (if (not (message-goto-signature))
1738 (delete-region beg (progn (message-goto-body)
1741 (when (message-goto-signature)
1744 (defun message-kill-to-signature ()
1745 "Deletes all text up to the signature."
1747 (let ((point (point)))
1748 (message-goto-signature)
1751 (kill-region point (point))
1755 (defun message-newline-and-reformat ()
1756 "Insert four newlines, and then reformat if inside quoted text."
1758 (let ((point (point))
1762 (setq quoted (looking-at (regexp-quote message-yank-prefix))))
1765 (insert message-yank-prefix))
1766 (fill-paragraph nil)
1770 (defun message-insert-signature (&optional force)
1771 "Insert a signature. See documentation for the `message-signature' variable."
1772 (interactive (list 0))
1775 ((and (null message-signature)
1778 (goto-char (point-max))
1779 (not (re-search-backward
1780 message-signature-separator nil t))))
1781 ((and (null message-signature)
1784 ((message-functionp message-signature)
1785 (funcall message-signature))
1786 ((listp message-signature)
1787 (eval message-signature))
1788 (t message-signature)))
1790 (cond ((stringp signature)
1792 ((and (eq t signature)
1793 message-signature-file
1794 (file-exists-p message-signature-file))
1797 (goto-char (point-max))
1798 ;; Insert the signature.
1802 (if (eq signature t)
1803 (insert-file-contents message-signature-file)
1805 (goto-char (point-max))
1806 (or (bolp) (insert "\n")))))
1808 (defun message-elide-region (b e)
1809 "Elide the text between point and mark.
1810 An ellipsis (from `message-elide-elipsis') will be inserted where the
1816 (insert message-elide-elipsis))
1818 (defvar message-caesar-translation-table nil)
1820 (defun message-caesar-region (b e &optional n)
1821 "Caesar rotation of region by N, default 13, for decrypting netnews."
1824 (min (point) (or (mark t) (point)))
1825 (max (point) (or (mark t) (point)))
1826 (when current-prefix-arg
1827 (prefix-numeric-value current-prefix-arg))))
1829 (setq n (if (numberp n) (mod n 26) 13)) ;canonize N
1830 (unless (or (zerop n) ; no action needed for a rot of 0
1831 (= b e)) ; no region to rotate
1832 ;; We build the table, if necessary.
1833 (when (or (not message-caesar-translation-table)
1834 (/= (aref message-caesar-translation-table ?a) (+ ?a n)))
1835 (setq message-caesar-translation-table
1836 (message-make-caesar-translation-table n)))
1837 ;; Then we translate the region. Do it this way to retain
1840 (when (< (char-after b) 255)
1841 (subst-char-in-region
1842 b (1+ b) (char-after b)
1843 (aref message-caesar-translation-table (char-after b))))
1846 (defun message-make-caesar-translation-table (n)
1847 "Create a rot table with offset N."
1849 (table (make-string 256 0)))
1850 (while (< (incf i) 256)
1853 (substring table 0 ?A)
1854 (substring table (+ ?A n) (+ ?A n (- 26 n)))
1855 (substring table ?A (+ ?A n))
1856 (substring table (+ ?A 26) ?a)
1857 (substring table (+ ?a n) (+ ?a n (- 26 n)))
1858 (substring table ?a (+ ?a n))
1859 (substring table (+ ?a 26) 255))))
1861 (defun message-caesar-buffer-body (&optional rotnum)
1862 "Caesar rotates all letters in the current buffer by 13 places.
1863 Used to encode/decode possiblyun offensive messages (commonly in net.jokes).
1864 With prefix arg, specifies the number of places to rotate each letter forward.
1865 Mail and USENET news headers are not rotated."
1866 (interactive (if current-prefix-arg
1867 (list (prefix-numeric-value current-prefix-arg))
1871 (when (message-goto-body)
1872 (narrow-to-region (point) (point-max)))
1873 (message-caesar-region (point-min) (point-max) rotnum))))
1875 (defun message-pipe-buffer-body (program)
1876 "Pipe the message body in the current buffer through PROGRAM."
1879 (when (message-goto-body)
1880 (narrow-to-region (point) (point-max)))
1881 (let ((body (buffer-substring (point-min) (point-max))))
1882 (unless (equal 0 (call-process-region
1883 (point-min) (point-max) program t t))
1885 (message "%s failed." program))))))
1887 (defun message-rename-buffer (&optional enter-string)
1888 "Rename the *message* buffer to \"*message* RECIPIENT\".
1889 If the function is run with a prefix, it will ask for a new buffer
1890 name, rather than giving an automatic name."
1891 (interactive "Pbuffer name: ")
1894 (goto-char (point-min))
1895 (narrow-to-region (point)
1896 (search-forward mail-header-separator nil 'end))
1898 (if (message-news-p) (message-fetch-field "Newsgroups")
1899 (message-fetch-field "To"))
1902 (if (string-match "," mail-to)
1903 (concat (substring mail-to 0 (match-beginning 0)) ", ...")
1905 (name-default (concat "*message* " mail-trimmed-to))
1906 (name (if enter-string
1907 (read-string "New buffer name: " name-default)
1909 (rename-buffer name t)))))
1911 (defun message-fill-yanked-message (&optional justifyp)
1912 "Fill the paragraphs of a message yanked into this one.
1913 Numeric argument means justify as well."
1916 (goto-char (point-min))
1917 (search-forward (concat "\n" mail-header-separator "\n") nil t)
1918 (let ((fill-prefix message-yank-prefix))
1919 (fill-individual-paragraphs (point) (point-max) justifyp t))))
1921 (defun message-indent-citation ()
1922 "Modify text just inserted from a message to be cited.
1923 The inserted text should be the region.
1924 When this function returns, the region is again around the modified text.
1926 Normally, indent each nonblank line `message-indentation-spaces' spaces.
1927 However, if `message-yank-prefix' is non-nil, insert that prefix on each line."
1928 (let ((start (point)))
1929 ;; Remove unwanted headers.
1930 (when message-ignored-cited-headers
1935 (if (search-forward "\n\n" nil t)
1938 (message-remove-header message-ignored-cited-headers t)
1939 (when (= (point-min) (point-max))
1940 (setq all-removed t))
1941 (goto-char (point-max)))
1945 ;; Delete blank lines at the start of the buffer.
1946 (while (and (point-min)
1949 (message-delete-line))
1950 ;; Delete blank lines at the end of the buffer.
1951 (goto-char (point-max))
1954 (while (and (zerop (forward-line -1))
1956 (message-delete-line))
1957 ;; Do the indentation.
1958 (if (null message-yank-prefix)
1959 (indent-rigidly start (mark t) message-indentation-spaces)
1962 (while (< (point) (mark t))
1963 (insert message-yank-prefix)
1967 (defvar gnus-article-copy)
1968 (defun message-yank-original (&optional arg)
1969 "Insert the message being replied to, if any.
1970 Puts point before the text and mark after.
1971 Normally indents each nonblank line ARG spaces (default 3). However,
1972 if `message-yank-prefix' is non-nil, insert that prefix on each line.
1974 This function uses `message-cite-function' to do the actual citing.
1976 Just \\[universal-argument] as argument means don't indent, insert no
1977 prefix, and don't delete any headers."
1979 (let ((modified (buffer-modified-p))
1980 (buffer (message-get-reply-buffer)))
1982 message-cite-function)
1983 (delete-windows-on buffer t)
1984 (insert-buffer buffer)
1985 (funcall message-cite-function)
1986 (message-exchange-point-and-mark)
1990 (setq message-checksum (message-checksum))))))
1992 (defun message-cite-original-without-signature ()
1993 "Cite function in the standard Message manner."
1994 (let ((start (point))
1997 (when message-indent-citation-function
1998 (if (listp message-indent-citation-function)
1999 message-indent-citation-function
2000 (list message-indent-citation-function)))))
2002 (when (re-search-backward "^-- $" start t)
2003 ;; Also peel off any blank lines before the signature.
2005 (while (looking-at "^[ \t]*$")
2008 (delete-region (point) end))
2011 (funcall (pop functions)))
2012 (when message-citation-line-function
2015 (funcall message-citation-line-function))))
2017 (defvar mail-citation-hook) ;Compiler directive
2018 (defun message-cite-original ()
2019 "Cite function in the standard Message manner."
2020 (if (and (boundp 'mail-citation-hook)
2022 (run-hooks 'mail-citation-hook)
2023 (let ((start (point))
2025 (when message-indent-citation-function
2026 (if (listp message-indent-citation-function)
2027 message-indent-citation-function
2028 (list message-indent-citation-function)))))
2031 (funcall (pop functions)))
2032 (when message-citation-line-function
2035 (funcall message-citation-line-function)))))
2037 (defun message-insert-citation-line ()
2038 "Function that inserts a simple citation line."
2039 (when message-reply-headers
2040 (insert (mail-header-from message-reply-headers) " writes:\n\n")))
2042 (defun message-position-on-field (header &rest afters)
2043 (let ((case-fold-search t))
2046 (goto-char (point-min))
2049 (concat "^" (regexp-quote mail-header-separator) "$"))
2050 (match-beginning 0)))
2051 (goto-char (point-min))
2052 (if (re-search-forward (concat "^" (regexp-quote header) ":") nil t)
2054 (re-search-forward "^[^ \t]" nil 'move)
2056 (skip-chars-backward "\n")
2059 (not (re-search-forward
2060 (concat "^" (regexp-quote (car afters)) ":")
2064 (re-search-forward "^[^ \t]" nil 'move)
2065 (beginning-of-line))
2066 (insert header ": \n")
2070 (defun message-remove-signature ()
2071 "Remove the signature from the text between point and mark.
2072 The text will also be indented the normal way."
2074 (let ((start (point))
2076 (if (not (re-search-forward message-signature-separator (mark t) t))
2077 ;; No signature here, so we just indent the cited text.
2078 (message-indent-citation)
2079 ;; Find the last non-empty line.
2081 (while (looking-at "[ \t]*$")
2084 (setq mark (set-marker (make-marker) (point)))
2086 (message-indent-citation)
2087 ;; Enable undoing the deletion.
2089 (delete-region mark (mark t))
2090 (set-marker mark nil)))))
2095 ;;; Sending messages
2098 ;; Avoid byte-compile warning.
2099 (defvar message-encoding-buffer nil)
2100 (defvar message-edit-buffer nil)
2101 (defvar message-mime-mode nil)
2103 (defun message-send-and-exit (&optional arg)
2104 "Send message like `message-send', then, if no errors, exit from mail buffer."
2106 (let ((buf (current-buffer))
2107 (actions message-exit-actions)
2108 (frame (selected-frame))
2109 (org-frame message-original-frame))
2110 (when (and (message-send arg)
2112 (if message-kill-buffer-on-exit
2115 (when (eq buf (current-buffer))
2116 (message-bury buf)))
2117 (message-do-actions actions)
2118 (message-delete-frame frame org-frame)
2121 (defun message-dont-send ()
2122 "Don't send the message you have been editing."
2124 (set-buffer-modified-p t)
2126 (let ((actions message-postpone-actions))
2127 (message-bury (current-buffer))
2128 (message-do-actions actions)))
2130 (defun message-kill-buffer ()
2131 "Kill the current buffer."
2133 (when (or (not (buffer-modified-p))
2134 (eq t message-kill-buffer-query-function)
2135 (funcall message-kill-buffer-query-function
2136 "The buffer modified; kill anyway? "))
2137 (let ((actions message-kill-actions)
2138 (frame (selected-frame))
2139 (org-frame message-original-frame))
2140 (setq buffer-file-name nil)
2141 (kill-buffer (current-buffer))
2142 (message-do-actions actions)
2143 (message-delete-frame frame org-frame)))
2146 (defun message-delete-frame (frame org-frame)
2147 "Delete frame for editing message."
2148 (when (and (or (and (featurep 'xemacs)
2149 (not (eq 'tty (device-type))))
2151 (>= emacs-major-version 20))
2152 (or (and (eq message-delete-frame-on-exit t)
2153 (select-frame frame)
2154 (or (eq frame org-frame)
2156 (y-or-n-p "Delete this frame?")
2158 (and (eq message-delete-frame-on-exit 'ask)
2159 (select-frame frame)
2161 (y-or-n-p "Delete this frame?")
2163 (delete-frame frame)))
2165 (defun message-bury (buffer)
2166 "Bury this mail buffer."
2167 (let ((newbuf (other-buffer buffer)))
2168 (bury-buffer buffer)
2169 (if (and (fboundp 'frame-parameters)
2170 (cdr (assq 'dedicated (frame-parameters)))
2171 (not (null (delq (selected-frame) (visible-frame-list)))))
2172 (delete-frame (selected-frame))
2173 (switch-to-buffer newbuf))))
2175 (defun message-send (&optional arg)
2176 "Send the message in the current buffer.
2177 If `message-interactive' is non-nil, wait for success indication
2178 or error messages, and inform user.
2179 Otherwise any failure is reported in a message back to
2180 the user from the mailer."
2183 (when (or (buffer-modified-p)
2184 (message-check-element 'unchanged)
2185 (y-or-n-p "No changes in the buffer; really send? "))
2186 ;; Make it possible to undo the coming changes.
2188 (let ((inhibit-read-only t))
2189 (put-text-property (point-min) (point-max) 'read-only nil))
2190 (run-hooks 'message-send-hook)
2191 (message "Sending...")
2192 (let ((message-encoding-buffer
2193 (message-generate-new-buffer-clone-locals " message encoding"))
2194 (message-edit-buffer (current-buffer))
2195 (message-mime-mode mime-edit-mode-flag)
2196 (alist message-send-method-alist)
2200 (set-buffer message-encoding-buffer)
2202 (insert-buffer message-edit-buffer)
2203 (funcall message-encode-function)
2204 (message-fix-before-sending)
2206 (setq elem (pop alist)))
2207 (when (and (or (not (funcall (cadr elem)))
2208 (and (or (not (memq (car elem)
2209 message-sent-message-via))
2212 "Already sent message via %s; resend? "
2214 (setq success (funcall (caddr elem) arg)))))
2216 (when (and success sent)
2218 ;;(when (fboundp 'mail-hist-put-headers-into-history)
2219 ;; (mail-hist-put-headers-into-history))
2220 (run-hooks 'message-sent-hook)
2221 (message "Sending...done")
2222 ;; Mark the buffer as unmodified and delete autosave.
2223 (set-buffer-modified-p nil)
2224 (delete-auto-save-file-if-necessary t)
2225 (message-disassociate-draft)
2226 ;; Delete other mail buffers and stuff.
2227 (message-do-send-housekeeping)
2228 (message-do-actions message-send-actions)
2232 (defun message-send-via-mail (arg)
2233 "Send the current message via mail."
2234 (message-send-mail arg))
2236 (defun message-send-via-news (arg)
2237 "Send the current message via news."
2238 (message-send-news arg))
2240 (defmacro message-check (type &rest forms)
2241 "Eval FORMS if TYPE is to be checked."
2242 `(or (message-check-element ,type)
2246 (put 'message-check 'lisp-indent-function 1)
2247 (put 'message-check 'edebug-form-spec '(form body))
2249 (defun message-fix-before-sending ()
2250 "Do various things to make the message nice before sending it."
2251 ;; Make sure there's a newline at the end of the message.
2252 (goto-char (point-max))
2255 ;; Delete all invisible text.
2256 (message-check 'invisible-text
2257 (when (text-property-any (point-min) (point-max) 'invisible t)
2258 (put-text-property (point-min) (point-max) 'invisible nil)
2259 (unless (yes-or-no-p "Invisible text found and made visible; continue posting? ")
2260 (error "Invisible text found and made visible")))))
2262 (defun message-add-action (action &rest types)
2263 "Add ACTION to be performed when doing an exit of type TYPES."
2266 (set (setq var (intern (format "message-%s-actions" (pop types))))
2267 (nconc (symbol-value var) (list action))))))
2269 (defun message-do-actions (actions)
2270 "Perform all actions in ACTIONS."
2271 ;; Now perform actions on successful sending.
2275 ;; A simple function.
2276 ((message-functionp (car actions))
2277 (funcall (car actions)))
2278 ;; Something to be evaled.
2280 (eval (car actions)))))
2283 (defsubst message-maybe-split-and-send-mail ()
2284 "Split a message if necessary, and send it via mail.
2285 Returns nil if sending succeeded, returns any string if sending failed.
2286 This sub function is for exclusive use of `message-send-mail'."
2287 (let ((mime-edit-split-ignored-field-regexp
2288 mime-edit-split-ignored-field-regexp)
2289 (case-fold-search t)
2291 (while (string-match "Message-ID" mime-edit-split-ignored-field-regexp)
2292 (setq mime-edit-split-ignored-field-regexp
2293 (concat (substring mime-edit-split-ignored-field-regexp
2294 0 (match-beginning 0))
2295 "Hey_MIME-Edit,_there_is_an_inviolable_Message_ID"
2296 "_so_don't_rape_it!"
2297 (substring mime-edit-split-ignored-field-regexp
2301 (catch 'message-sending-mail-failure
2302 (mime-edit-maybe-split-and-send
2307 (std11-narrow-to-header mail-header-separator)
2308 (goto-char (point-min))
2309 (when (re-search-forward "^Message-ID:" nil t)
2310 (delete-region (match-end 0) (std11-field-end))
2311 (insert " " (message-make-message-id))))
2313 (funcall message-send-mail-function)
2315 (throw 'message-sending-mail-failure err))))))
2319 (funcall message-send-mail-function)
2323 (if (eq 'error (car failure))
2325 (prin1-to-string failure)))))
2327 (defun message-send-mail (&optional arg)
2328 (require 'mail-utils)
2329 (let ((tembuf (message-generate-new-buffer-clone-locals " message temp"))
2330 (case-fold-search nil)
2331 (news (message-news-p))
2334 (message-narrow-to-headers)
2335 ;; Insert some headers.
2336 (let ((message-deletable-headers
2337 (if news nil message-deletable-headers)))
2338 (message-generate-headers message-required-mail-headers))
2339 ;; Let the user do all of the above.
2340 (run-hooks 'message-header-hook))
2341 (if (not (message-check-mail-syntax))
2349 (insert-buffer message-encoding-buffer)
2350 ;; Remove some headers.
2352 (message-narrow-to-headers)
2353 ;; Remove some headers.
2354 (message-remove-header message-ignored-mail-headers t))
2355 (goto-char (point-max))
2356 ;; require one newline at the end.
2357 (or (= (preceding-char) ?\n)
2360 (or (message-fetch-field "cc")
2361 (message-fetch-field "to")))
2362 (message-insert-courtesy-copy))
2363 (setq failure (message-maybe-split-and-send-mail)))
2364 (kill-buffer tembuf))
2365 (set-buffer message-edit-buffer)
2368 (message "Couldn't send message via mail: %s" failure)
2370 (push 'mail message-sent-message-via)))))
2372 (defun message-send-mail-with-sendmail ()
2373 "Send off the prepared buffer with sendmail."
2374 (let ((errbuf (if message-interactive
2375 (generate-new-buffer " sendmail errors")
2377 resend-to-addresses delimline)
2378 (let ((case-fold-search t))
2380 (message-narrow-to-headers)
2381 (setq resend-to-addresses (message-fetch-field "resent-to")))
2382 ;; Change header-delimiter to be what sendmail expects.
2383 (goto-char (point-min))
2385 (concat "^" (regexp-quote mail-header-separator) "\n"))
2386 (replace-match "\n")
2388 (setq delimline (point-marker))
2389 (run-hooks 'message-send-mail-hook)
2390 ;; Insert an extra newline if we need it to work around
2391 ;; Sun's bug that swallows newlines.
2392 (goto-char (1+ delimline))
2393 (when (eval message-mailer-swallows-blank-line)
2395 (when message-interactive
2399 (let ((default-directory "/")
2400 (coding-system-for-write message-send-coding-system))
2401 (apply 'call-process-region
2402 (append (list (point-min) (point-max)
2403 (if (boundp 'sendmail-program)
2405 "/usr/lib/sendmail")
2406 nil errbuf nil "-oi")
2407 ;; Always specify who from,
2408 ;; since some systems have broken sendmails.
2409 ;; But some systems are more broken with -f, so
2410 ;; we'll let users override this.
2411 (if (null message-sendmail-f-is-evil)
2412 (list "-f" (user-login-name)))
2413 ;; These mean "report errors by mail"
2414 ;; and "deliver in background".
2415 (if (null message-interactive) '("-oem" "-odb"))
2416 ;; Get the addresses from the message
2417 ;; unless this is a resend.
2418 ;; We must not do that for a resend
2419 ;; because we would find the original addresses.
2420 ;; For a resend, include the specific addresses.
2421 (if resend-to-addresses
2422 (list resend-to-addresses)
2424 (when message-interactive
2427 (goto-char (point-min))
2428 (while (re-search-forward "\n\n* *" nil t)
2429 (replace-match "; "))
2430 (if (not (zerop (buffer-size)))
2431 (error "Sending...failed to %s"
2432 (buffer-substring (point-min) (point-max)))))
2433 (when (bufferp errbuf)
2434 (kill-buffer errbuf)))))
2436 (defun message-send-mail-with-qmail ()
2437 "Pass the prepared message buffer to qmail-inject.
2438 Refer to the documentation for the variable `message-send-mail-function'
2439 to find out how to use this."
2440 ;; replace the header delimiter with a blank line
2441 (goto-char (point-min))
2443 (concat "^" (regexp-quote mail-header-separator) "\n"))
2444 (replace-match "\n")
2446 (run-hooks 'message-send-mail-hook)
2449 (let ((coding-system-for-write message-send-coding-system))
2451 'call-process-region 1 (point-max) message-qmail-inject-program
2453 ;; qmail-inject's default behaviour is to look for addresses on the
2454 ;; command line; if there're none, it scans the headers.
2455 ;; yes, it does The Right Thing w.r.t. Resent-To and it's kin.
2457 ;; in general, ALL of qmail-inject's defaults are perfect for simply
2458 ;; reading a formatted (i. e., at least a To: or Resent-To header)
2459 ;; message from stdin.
2461 ;; qmail also has the advantage of not having been raped by
2462 ;; various vendors, so we don't have to allow for that, either --
2463 ;; compare this with message-send-mail-with-sendmail and weep
2464 ;; for sendmail's lost innocence.
2466 ;; all this is way cool coz it lets us keep the arguments entirely
2467 ;; free for -inject-arguments -- a big win for the user and for us
2468 ;; since we don't have to play that double-guessing game and the user
2469 ;; gets full control (no gestapo'ish -f's, for instance). --sj
2470 message-qmail-inject-args))
2471 ;; qmail-inject doesn't say anything on it's stdout/stderr,
2472 ;; we have to look at the retval instead
2474 (1 (error "qmail-inject reported permanent failure"))
2475 (111 (error "qmail-inject reported transient failure"))
2476 ;; should never happen
2477 (t (error "qmail-inject reported unknown failure"))))
2479 (defun message-send-mail-with-mh ()
2480 "Send the prepared message buffer with mh."
2481 (let ((mh-previous-window-config nil)
2482 (name (mh-new-draft-name)))
2483 (setq buffer-file-name name)
2484 ;; MH wants to generate these headers itself.
2485 (when message-mh-deletable-headers
2486 (let ((headers message-mh-deletable-headers))
2488 (goto-char (point-min))
2489 (and (re-search-forward
2490 (concat "^" (symbol-name (car headers)) ": *") nil t)
2491 (message-delete-line))
2493 (run-hooks 'message-send-mail-hook)
2494 ;; Pass it on to mh.
2497 (defun message-send-mail-with-smtp ()
2498 "Send off the prepared buffer with SMTP."
2499 (require 'smtp) ; XXX
2500 (let ((case-fold-search t)
2503 (message-narrow-to-headers)
2505 ;; XXX: Should be replaced by better one.
2506 (smtp-deduce-address-list (current-buffer)
2507 (point-min) (point-max)))
2508 ;; Remove BCC lines.
2509 (message-remove-header "bcc"))
2510 ;; replace the header delimiter with a blank line.
2511 (goto-char (point-min))
2513 (concat "^" (regexp-quote mail-header-separator) "\n"))
2514 (replace-match "\n")
2516 (run-hooks 'message-send-mail-hook)
2518 (let ((result (smtp-via-smtp user-mail-address
2521 (unless (eq result t)
2522 (error "Sending failed; " result)))
2523 (error "Sending failed; no recipients"))))
2525 (defsubst message-maybe-split-and-send-news ()
2526 "Split a message if necessary, and send it via news.
2527 Returns nil if sending succeeded, returns t if sending failed.
2528 This sub function is for exclusive use of `message-send-news'."
2529 (let ((mime-edit-split-ignored-field-regexp
2530 mime-edit-split-ignored-field-regexp)
2531 (case-fold-search t))
2532 (while (string-match "Message-ID" mime-edit-split-ignored-field-regexp)
2533 (setq mime-edit-split-ignored-field-regexp
2534 (concat (substring mime-edit-split-ignored-field-regexp
2535 0 (match-beginning 0))
2536 "Hey_MIME-Edit,_there_is_an_inviolable_Message_ID"
2537 "_so_don't_rape_it!"
2538 (substring mime-edit-split-ignored-field-regexp
2541 (catch 'message-sending-news-failure
2542 (mime-edit-maybe-split-and-send
2547 (std11-narrow-to-header mail-header-separator)
2548 (goto-char (point-min))
2549 (when (re-search-forward "^Message-ID:" nil t)
2550 (delete-region (match-end 0) (std11-field-end))
2551 (insert " " (message-make-message-id))))
2552 (unless (funcall message-send-news-function method)
2553 (throw 'message-sending-news-failure t)))))
2555 (not (funcall message-send-news-function method)))))
2557 (defun message-send-news (&optional arg)
2558 (let ((tembuf (message-generate-new-buffer-clone-locals " *message temp*"))
2559 (case-fold-search nil)
2560 (method (if (message-functionp message-post-method)
2561 (funcall message-post-method arg)
2562 message-post-method))
2563 (message-syntax-checks
2565 (cons '(existing-newsgroups . disabled)
2566 message-syntax-checks)
2567 message-syntax-checks))
2570 (message-narrow-to-headers)
2571 ;; Insert some headers.
2572 (message-generate-headers message-required-news-headers)
2573 ;; Let the user do all of the above.
2574 (run-hooks 'message-header-hook))
2575 (message-cleanup-headers)
2576 (if (not (message-check-news-syntax))
2581 (buffer-disable-undo)
2583 (insert-buffer message-encoding-buffer)
2584 ;; Remove some headers.
2586 (message-narrow-to-headers)
2587 ;; Remove some headers.
2588 (message-remove-header message-ignored-news-headers t))
2589 (goto-char (point-max))
2590 ;; require one newline at the end.
2591 (or (= (preceding-char) ?\n)
2593 (setq result (message-maybe-split-and-send-news)))
2594 (kill-buffer tembuf))
2595 (set-buffer message-edit-buffer)
2598 (message "Couldn't send message via news: %s"
2599 (nnheader-get-report (car method)))
2601 (push 'news message-sent-message-via)))))
2603 ;; 1997-09-29 by MORIOKA Tomohiko
2604 (defun message-send-news-with-gnus (method)
2605 (let ((case-fold-search t))
2606 ;; Remove the delimiter.
2607 (goto-char (point-min))
2609 (concat "^" (regexp-quote mail-header-separator) "\n"))
2610 (replace-match "\n")
2612 (run-hooks 'message-send-news-hook)
2613 ;;(require (car method))
2614 ;;(funcall (intern (format "%s-open-server" (car method)))
2615 ;;(cadr method) (cddr method))
2617 ;; (funcall (intern (format "%s-request-post" (car method)))
2619 (gnus-open-server method)
2620 (gnus-request-post method)
2624 ;;; Header generation & syntax checking.
2627 (defun message-check-element (type)
2628 "Returns non-nil if this type is not to be checked."
2629 (if (eq message-syntax-checks 'dont-check-for-anything-just-trust-me)
2631 (let ((able (assq type message-syntax-checks)))
2633 (eq (cdr able) 'disabled)))))
2635 (defun message-check-news-syntax ()
2636 "Check the syntax of the message."
2641 ;; We narrow to the headers and check them first.
2644 (message-narrow-to-headers)
2645 (message-check-news-header-syntax)))
2648 (set-buffer message-edit-buffer)
2649 (message-check-news-body-syntax))))))
2651 (defun message-check-news-header-syntax ()
2653 ;; Check the Subject header.
2654 (message-check 'subject
2655 (let* ((case-fold-search t)
2656 (subject (message-fetch-field "subject")))
2659 (not (string-match "\\`[ \t]*\\'" subject)))
2662 "The subject field is empty or missing. Posting is denied.")))))
2663 ;; Check for commands in Subject.
2664 (message-check 'subject-cmsg
2665 (if (string-match "^cmsg " (message-fetch-field "subject"))
2667 "The control code \"cmsg\" is in the subject. Really post? ")
2669 ;; Check for multiple identical headers.
2670 (message-check 'multiple-headers
2672 (while (and (not found)
2673 (re-search-forward "^[^ \t:]+: " nil t))
2675 (or (re-search-forward
2680 (match-beginning 0) (- (match-end 0) 2))))
2685 (y-or-n-p (format "Multiple %s headers. Really post? " found))
2687 ;; Check for Version and Sendsys.
2688 (message-check 'sendsys
2689 (if (re-search-forward "^Sendsys:\\|^Version:" nil t)
2691 (format "The article contains a %s command. Really post? "
2692 (buffer-substring (match-beginning 0)
2693 (1- (match-end 0)))))
2695 ;; See whether we can shorten Followup-To.
2696 (message-check 'shorten-followup-to
2697 (let ((newsgroups (message-fetch-field "newsgroups"))
2698 (followup-to (message-fetch-field "followup-to"))
2700 (when (and newsgroups
2701 (string-match "," newsgroups)
2706 (setq to (completing-read
2707 "Followups to: (default all groups) "
2708 (mapcar (lambda (g) (list g))
2710 (message-tokenize-header
2712 (goto-char (point-min))
2713 (insert "Followup-To: " to "\n"))
2715 ;; Check "Shoot me".
2716 (message-check 'shoot
2717 (if (re-search-forward
2718 "Message-ID.*.i-did-not-set--mail-host-address--so-shoot-me" nil t)
2719 (y-or-n-p "You appear to have a misconfigured system. Really post? ")
2721 ;; Check for Approved.
2722 (message-check 'approved
2723 (if (re-search-forward "^Approved:" nil t)
2724 (y-or-n-p "The article contains an Approved header. Really post? ")
2726 ;; Check the Message-ID header.
2727 (message-check 'message-id
2728 (let* ((case-fold-search t)
2729 (message-id (message-fetch-field "message-id" t)))
2730 (or (not message-id)
2731 ;; Is there an @ in the ID?
2732 (and (string-match "@" message-id)
2733 ;; Is there a dot in the ID?
2734 (string-match "@[^.]*\\." message-id)
2735 ;; Does the ID end with a dot?
2736 (not (string-match "\\.>" message-id)))
2738 (format "The Message-ID looks strange: \"%s\". Really post? "
2740 ;; Check the Newsgroups & Followup-To headers.
2741 (message-check 'existing-newsgroups
2742 (let* ((case-fold-search t)
2743 (newsgroups (message-fetch-field "newsgroups"))
2744 (followup-to (message-fetch-field "followup-to"))
2745 (groups (message-tokenize-header
2747 (concat newsgroups "," followup-to)
2749 (hashtb (and (boundp 'gnus-active-hashtb)
2750 gnus-active-hashtb))
2752 (if (or (not hashtb)
2753 (not (boundp 'gnus-read-active-file))
2754 (not gnus-read-active-file)
2755 (eq gnus-read-active-file 'some))
2758 (when (and (not (boundp (intern (car groups) hashtb)))
2759 (not (equal (car groups) "poster")))
2760 (push (car groups) errors))
2766 "Really post to %s unknown group%s: %s "
2767 (if (= (length errors) 1) "this" "these")
2768 (if (= (length errors) 1) "" "s")
2769 (mapconcat 'identity errors ", ")))))))
2770 ;; Check the Newsgroups & Followup-To headers for syntax errors.
2771 (message-check 'valid-newsgroups
2772 (let ((case-fold-search t)
2773 (headers '("Newsgroups" "Followup-To"))
2775 (while (and headers (not error))
2776 (when (setq header (mail-fetch-field (car headers)))
2780 "\\`\\([-+_&.a-zA-Z0-9]+\\)?\\(,[-+_&.a-zA-Z0-9]+\\)*\\'"
2785 (not (string-match "\\.\\'\\|\\.\\." g)))
2786 (message-tokenize-header header ","))))
2793 (format "The %s header looks odd: \"%s\". Really post? "
2794 (car headers) header)))))
2795 (message-check 'repeated-newsgroups
2796 (let ((case-fold-search t)
2797 (headers '("Newsgroups" "Followup-To"))
2798 header error groups group)
2801 (when (setq header (mail-fetch-field (pop headers)))
2802 (setq groups (message-tokenize-header header ","))
2803 (while (setq group (pop groups))
2804 (when (member group groups)
2810 (format "Group %s is repeated in headers. Really post? " error)))))
2811 ;; Check the From header.
2812 (message-check 'from
2813 (let* ((case-fold-search t)
2814 (from (message-fetch-field "from"))
2815 (ad (nth 1 (std11-extract-address-components from))))
2818 (message "There is no From line. Posting is denied.")
2820 ((or (not (string-match "@[^\\.]*\\." ad)) ;larsi@ifi
2821 (string-match "\\.\\." ad) ;larsi@ifi..uio
2822 (string-match "@\\." ad) ;larsi@.ifi.uio
2823 (string-match "\\.$" ad) ;larsi@ifi.uio.
2824 (not (string-match "^[^@]+@[^@]+$" ad)) ;larsi.ifi.uio
2825 (string-match "(.*).*(.*)" from)) ;(lars) (lars)
2827 "Denied posting -- the From looks strange: \"%s\"." from)
2831 (defun message-check-news-body-syntax ()
2833 ;; Check for long lines.
2834 (message-check 'long-lines
2835 (goto-char (point-min))
2837 (concat "^" (regexp-quote mail-header-separator) "$"))
2841 (< (current-column) 80))
2842 (zerop (forward-line 1))))
2846 "You have lines longer than 79 characters. Really post? ")))
2847 ;; Check whether the article is empty.
2848 (message-check 'empty
2849 (goto-char (point-min))
2851 (concat "^" (regexp-quote mail-header-separator) "$"))
2854 (goto-char (point-max))
2855 (re-search-backward message-signature-separator nil t)
2857 (or (re-search-backward "[^ \n\t]" b t)
2858 (y-or-n-p "Empty article. Really post? "))))
2859 ;; Check for control characters.
2860 (message-check 'control-chars
2861 (if (re-search-forward "[\000-\007\013\015-\032\034-\037\200-\237]" nil t)
2863 "The article contains control characters. Really post? ")
2865 ;; Check 8bit characters.
2866 (message-check '8bit
2867 (message-check-8bit))
2868 ;; Check excessive size.
2869 (message-check 'size
2870 (if (> (buffer-size) 60000)
2872 (format "The article is %d octets long. Really post? "
2875 ;; Check whether any new text has been added.
2876 (message-check 'new-text
2878 (not message-checksum)
2879 (not (eq (message-checksum) message-checksum))
2881 "It looks like no new text has been added. Really post? ")))
2882 ;; Check the length of the signature.
2883 (message-check 'signature
2884 (goto-char (point-max))
2885 (if (or (not (re-search-backward message-signature-separator nil t))
2886 (search-forward message-forward-end-separator nil t))
2888 (if (> (count-lines (point) (point-max)) 5)
2891 "Your .sig is %d lines; it should be max 4. Really post? "
2892 (1- (count-lines (point) (point-max)))))
2895 (defun message-check-mail-syntax ()
2896 "Check the syntax of the message."
2901 ;; We narrow to the headers and check them first.
2904 (message-narrow-to-headers)
2905 (message-check-mail-header-syntax)))
2908 (set-buffer message-edit-buffer)
2909 (message-check-mail-body-syntax))))))
2911 (defun message-check-mail-header-syntax ()
2914 (defun message-check-mail-body-syntax ()
2916 ;; Check 8bit characters.
2917 (message-check '8bit
2918 (message-check-8bit)
2921 (defun message-check-8bit ()
2922 "Check the article contains 8bit characters."
2924 (set-buffer message-encoding-buffer)
2925 (message-narrow-to-headers)
2926 (let* ((case-fold-search t)
2927 (field-value (message-fetch-field "content-transfer-encoding")))
2928 (if (and field-value
2929 (member (downcase field-value) message-8bit-encoding-list))
2932 (set-buffer (get-buffer-create " message syntax"))
2934 (goto-char (point-min))
2935 (set-buffer-multibyte nil)
2936 (insert-buffer message-encoding-buffer)
2937 (goto-char (point-min))
2938 (if (re-search-forward "[^\x00-\x7f]" nil t)
2940 "The article contains 8bit characters. Really post? ")
2943 (defun message-checksum ()
2944 "Return a \"checksum\" for the current buffer."
2947 (goto-char (point-min))
2949 (concat "^" (regexp-quote mail-header-separator) "$"))
2951 (when (not (looking-at "[ \t\n]"))
2952 (setq sum (logxor (ash sum 1) (if (natnump sum) 0 1)
2957 (defun message-do-fcc ()
2958 "Process Fcc headers in the current buffer."
2959 (let ((case-fold-search t)
2960 (coding-system-for-write 'raw-text)
2963 (set-buffer (get-buffer-create " *message temp*"))
2965 (insert-buffer-substring message-encoding-buffer)
2967 (message-narrow-to-headers)
2968 (while (setq file (message-fetch-field "fcc"))
2970 (message-remove-header "fcc" nil t)))
2971 (goto-char (point-min))
2972 (re-search-forward (concat "^" (regexp-quote mail-header-separator) "$"))
2973 (replace-match "" t t)
2974 ;; Process FCC operations.
2976 (setq file (pop list))
2977 (if (string-match "^[ \t]*|[ \t]*\\(.*\\)[ \t]*$" file)
2978 ;; Pipe the article to the program in question.
2979 (call-process-region (point-min) (point-max) shell-file-name
2980 nil nil nil shell-command-switch
2981 (match-string 1 file))
2982 ;; Save the article.
2983 (setq file (expand-file-name file))
2984 (unless (file-exists-p (file-name-directory file))
2985 (make-directory (file-name-directory file) t))
2986 (if (and message-fcc-handler-function
2987 (not (eq message-fcc-handler-function 'rmail-output)))
2988 (funcall message-fcc-handler-function file)
2989 (if (and (file-readable-p file) (mail-file-babyl-p file))
2990 (rmail-output file 1 nil t)
2991 (let ((mail-use-rfc822 t))
2992 (rmail-output file 1 t t))))))
2993 (kill-buffer (current-buffer)))))
2995 (defun message-output (filename)
2996 "Append this article to Unix/babyl mail file.."
2997 (if (and (file-readable-p filename)
2998 (mail-file-babyl-p filename))
2999 (rmail-output-to-rmail-file filename t)
3000 (gnus-output-to-mail filename t)))
3002 (defun message-cleanup-headers ()
3003 "Do various automatic cleanups of the headers."
3004 ;; Remove empty lines in the header.
3006 (message-narrow-to-headers)
3007 ;; Remove blank lines.
3008 (while (re-search-forward "^[ \t]*\n" nil t)
3009 (replace-match "" t t))
3011 ;; Correct Newsgroups and Followup-To headers: Change sequence of
3012 ;; spaces to comma and eliminate spaces around commas. Eliminate
3013 ;; embedded line breaks.
3014 (goto-char (point-min))
3015 (while (re-search-forward "^\\(Newsgroups\\|Followup-To\\): +" nil t)
3019 (if (re-search-forward "^[^ \t]" nil t)
3023 (goto-char (point-min))
3024 (while (re-search-forward "\n[ \t]+" nil t)
3025 (replace-match " " t t)) ;No line breaks (too confusing)
3026 (goto-char (point-min))
3027 (while (re-search-forward "[ \t\n]*,[ \t\n]*\\|[ \t]+" nil t)
3028 (replace-match "," t t))
3029 (goto-char (point-min))
3030 ;; Remove trailing commas.
3031 (when (re-search-forward ",+$" nil t)
3032 (replace-match "" t t))))))
3034 (defun message-make-date (&optional now)
3035 "Make a valid data header.
3036 If NOW, use that time instead."
3037 (let* ((now (or now (current-time)))
3038 (zone (nth 8 (decode-time now)))
3042 (setq zone (- zone)))
3044 (format-time-string "%d" now)
3045 ;; The month name of the %b spec is locale-specific. Pfff.
3047 (capitalize (car (rassoc (nth 4 (decode-time now))
3048 parse-time-months))))
3049 (format-time-string "%Y %H:%M:%S " now)
3050 ;; We do all of this because XEmacs doesn't have the %z spec.
3051 (format "%s%02d%02d" sign (/ zone 3600) (% zone 3600)))))
3053 (defun message-make-followup-subject (subject)
3054 "Make a followup Subject."
3056 ((and (eq message-use-subject-re 'guess)
3057 (string-match message-subject-encoded-re-regexp subject))
3059 (message-use-subject-re
3060 (concat "Re: " (message-strip-subject-re subject)))
3063 (defun message-make-message-id ()
3064 "Make a unique Message-ID."
3065 (concat "<" (message-unique-id)
3066 (let ((psubject (save-excursion (message-fetch-field "subject")))
3068 (save-excursion (message-fetch-field "supersedes"))))
3070 (and message-reply-headers
3071 (mail-header-references message-reply-headers)
3072 (mail-header-subject message-reply-headers)
3074 (mail-header-subject message-reply-headers)
3076 (message-strip-subject-re
3077 (mail-header-subject message-reply-headers))
3078 (message-strip-subject-re psubject))))
3080 (string-match "_-_@" psupersedes)))
3082 "@" (message-make-fqdn) ">"))
3084 (defvar message-unique-id-char nil)
3086 ;; If you ever change this function, make sure the new version
3087 ;; cannot generate IDs that the old version could.
3088 ;; You might for example insert a "." somewhere (not next to another dot
3089 ;; or string boundary), or modify the "fsf" string.
3090 (defun message-unique-id ()
3091 ;; Don't use microseconds from (current-time), they may be unsupported.
3092 ;; Instead we use this randomly inited counter.
3093 (setq message-unique-id-char
3094 (% (1+ (or message-unique-id-char (logand (random t) (1- (lsh 1 20)))))
3095 ;; (current-time) returns 16-bit ints,
3096 ;; and 2^16*25 just fits into 4 digits i base 36.
3098 (let ((tm (current-time)))
3100 (if (memq system-type '(ms-dos emx vax-vms))
3101 (let ((user (downcase (user-login-name))))
3102 (while (string-match "[^a-z0-9_]" user)
3103 (aset user (match-beginning 0) ?_))
3105 (message-number-base36 (user-uid) -1))
3106 (message-number-base36 (+ (car tm)
3107 (lsh (% message-unique-id-char 25) 16)) 4)
3108 (message-number-base36 (+ (nth 1 tm)
3109 (lsh (/ message-unique-id-char 25) 16)) 4)
3110 ;; Append the newsreader name, because while the generated
3111 ;; ID is unique to this newsreader, other newsreaders might
3112 ;; otherwise generate the same ID via another algorithm.
3115 (defun message-number-base36 (num len)
3120 (concat (message-number-base36 (/ num 36) (1- len))
3121 (char-to-string (aref "zyxwvutsrqponmlkjihgfedcba9876543210"
3124 (defun message-make-organization ()
3125 "Make an Organization header."
3126 (let* ((organization
3127 (when message-user-organization
3128 (if (message-functionp message-user-organization)
3129 (funcall message-user-organization)
3130 message-user-organization))))
3132 (message-set-work-buffer)
3133 (cond ((stringp organization)
3134 (insert organization))
3135 ((and (eq t organization)
3136 message-user-organization-file
3137 (file-exists-p message-user-organization-file))
3138 (insert-file-contents message-user-organization-file)))
3139 (goto-char (point-min))
3140 (while (re-search-forward "[\t\n]+" nil t)
3141 (replace-match "" t t))
3142 (unless (zerop (buffer-size))
3145 (defun message-make-lines ()
3146 "Count the number of lines and return numeric string."
3150 (goto-char (point-min))
3152 (concat "^" (regexp-quote mail-header-separator) "$"))
3154 (int-to-string (count-lines (point) (point-max))))))
3156 (defun message-make-in-reply-to ()
3157 "Return the In-Reply-To header for this message."
3158 (when message-reply-headers
3159 (let ((mid (mail-header-message-id message-reply-headers))
3160 (from (mail-header-from message-reply-headers))
3161 (date (mail-header-date message-reply-headers)))
3165 (let ((pair (std11-extract-address-components from)))
3167 (or (car pair) (cadr pair))
3169 (if (or (not date) (string= date ""))
3170 "(unknown date)" date)
3173 (defun message-make-distribution ()
3174 "Make a Distribution header."
3175 (let ((orig-distribution (message-fetch-reply-field "distribution")))
3176 (cond ((message-functionp message-distribution-function)
3177 (funcall message-distribution-function))
3178 (t orig-distribution))))
3180 (defun message-make-expires ()
3181 "Return an Expires header based on `message-expires'."
3182 (let ((current (current-time))
3183 (future (* 1.0 message-expires 60 60 24)))
3184 ;; Add the future to current.
3185 (setcar current (+ (car current) (round (/ future (expt 2 16)))))
3186 (setcar (cdr current) (+ (nth 1 current) (% (round future) (expt 2 16))))
3187 (message-make-date current)))
3189 (defun message-make-path ()
3191 (let ((login-name (user-login-name)))
3192 (cond ((null message-user-path)
3193 (concat (system-name) "!" login-name))
3194 ((stringp message-user-path)
3195 ;; Support GENERICPATH. Suggested by vixie@decwrl.dec.com.
3196 (concat message-user-path "!" login-name))
3199 (defun message-make-from ()
3200 "Make a From header."
3201 (let* ((style message-from-style)
3202 (login (message-make-address))
3204 (or (and (boundp 'user-full-name)
3207 (when (string= fullname "&")
3208 (setq fullname (user-login-name)))
3210 (message-set-work-buffer)
3213 (equal fullname ""))
3215 ((or (eq style 'angles)
3216 (and (not (eq style 'parens))
3217 ;; Use angles if no quoting is needed, or if parens would
3218 ;; need quoting too.
3219 (or (not (string-match "[^- !#-'*+/-9=?A-Z^-~]" fullname))
3220 (let ((tmp (concat fullname nil)))
3221 (while (string-match "([^()]*)" tmp)
3222 (aset tmp (match-beginning 0) ?-)
3223 (aset tmp (1- (match-end 0)) ?-))
3224 (string-match "[\\()]" tmp)))))
3226 (goto-char (point-min))
3227 ;; Look for a character that cannot appear unquoted
3228 ;; according to RFC 822.
3229 (when (re-search-forward "[^- !#-'*+/-9=?A-Z^-~]" nil 1)
3230 ;; Quote fullname, escaping specials.
3231 (goto-char (point-min))
3233 (while (re-search-forward "[\"\\]" nil 1)
3234 (replace-match "\\\\\\&" t))
3236 (insert " <" login ">"))
3237 (t ; 'parens or default
3239 (let ((fullname-start (point)))
3241 (goto-char fullname-start)
3242 ;; RFC 822 says \ and nonmatching parentheses
3243 ;; must be escaped in comments.
3244 ;; Escape every instance of ()\ ...
3245 (while (re-search-forward "[()\\]" nil 1)
3246 (replace-match "\\\\\\&" t))
3247 ;; ... then undo escaping of matching parentheses,
3248 ;; including matching nested parentheses.
3249 (goto-char fullname-start)
3250 (while (re-search-forward
3251 "\\(\\=\\|[^\\]\\(\\\\\\\\\\)*\\)\\\\(\\(\\([^\\]\\|\\\\\\\\\\)*\\)\\\\)"
3253 (replace-match "\\1(\\3)" t)
3254 (goto-char fullname-start)))
3258 (defun message-make-sender ()
3259 "Return the \"real\" user address.
3260 This function tries to ignore all user modifications, and
3261 give as trustworthy answer as possible."
3262 (concat (user-login-name) "@" (system-name)))
3264 (defun message-make-address ()
3265 "Make the address of the user."
3266 (or (message-user-mail-address)
3267 (concat (user-login-name) "@" (message-make-domain))))
3269 (defun message-user-mail-address ()
3270 "Return the pertinent part of `user-mail-address'."
3271 (when user-mail-address
3272 (if (string-match " " user-mail-address)
3273 (nth 1 (std11-extract-address-components user-mail-address))
3274 user-mail-address)))
3276 (defun message-make-fqdn ()
3277 "Return user's fully qualified domain name."
3278 (let ((system-name (system-name))
3279 (user-mail (message-user-mail-address)))
3281 ((string-match "[^.]\\.[^.]" system-name)
3282 ;; `system-name' returned the right result.
3284 ;; Try `mail-host-address'.
3285 ((and (boundp 'mail-host-address)
3286 (stringp mail-host-address)
3287 (string-match "\\." mail-host-address))
3289 ;; We try `user-mail-address' as a backup.
3291 (string-match "\\." user-mail)
3292 (string-match "@\\(.*\\)\\'" user-mail))
3293 (match-string 1 user-mail))
3294 ;; Default to this bogus thing.
3296 (concat system-name ".i-did-not-set--mail-host-address--so-shoot-me")))))
3298 (defun message-make-host-name ()
3299 "Return the name of the host."
3300 (let ((fqdn (message-make-fqdn)))
3301 (string-match "^[^.]+\\." fqdn)
3302 (substring fqdn 0 (1- (match-end 0)))))
3304 (defun message-make-domain ()
3305 "Return the domain name."
3306 (or mail-host-address
3307 (message-make-fqdn)))
3309 ;; Dummy to avoid byte-compile warning.
3310 (defvar mule-version)
3311 (defvar emacs-beta-version)
3312 (defvar xemacs-codename)
3313 (defvar gnus-inviolable-extended-version)
3315 (defun message-make-user-agent ()
3316 "Return user-agent info if the value `message-user-agent' is non-nil. If the
3317 \"User-Agent\" field has already exist, it's value will be added in the return
3319 (when message-user-agent
3321 (goto-char (point-min))
3322 (let ((case-fold-search t)
3323 user-agent start p end)
3324 (if (re-search-forward "^User-Agent:[\t ]*" nil t)
3326 (setq start (match-beginning 0)
3328 end (std11-field-end)
3329 user-agent (buffer-substring-no-properties p end))
3330 (delete-region start (1+ end))
3331 (concat message-user-agent " " user-agent))
3332 message-user-agent)))))
3334 (defun message-generate-headers (headers)
3335 "Prepare article HEADERS.
3336 Headers already prepared in the buffer are not modified."
3338 (message-narrow-to-headers)
3339 (let* ((Date (message-make-date))
3340 (Message-ID (message-make-message-id))
3341 (Organization (message-make-organization))
3342 (From (message-make-from))
3343 (Path (message-make-path))
3346 (In-Reply-To (message-make-in-reply-to))
3348 (Distribution (message-make-distribution))
3349 (Lines (message-make-lines))
3350 (User-Agent (message-make-user-agent))
3351 (Expires (message-make-expires))
3352 (case-fold-search t)
3354 ;; First we remove any old generated headers.
3355 (let ((headers message-deletable-headers))
3356 (unless (buffer-modified-p)
3357 (setq headers (delq 'Message-ID (copy-sequence headers))))
3359 (goto-char (point-min))
3360 (and (re-search-forward
3361 (concat "^" (symbol-name (car headers)) ": *") nil t)
3362 (get-text-property (1+ (match-beginning 0)) 'message-deletable)
3363 (message-delete-line))
3365 ;; Go through all the required headers and see if they are in the
3366 ;; articles already. If they are not, or are empty, they are
3367 ;; inserted automatically - except for Subject, Newsgroups and
3370 (goto-char (point-min))
3371 (setq elem (pop headers))
3373 (if (eq (car elem) 'optional)
3374 (setq header (cdr elem))
3375 (setq header (car elem)))
3377 (when (or (not (re-search-forward
3381 (if (stringp header)
3383 (symbol-name header))))
3387 ;; The header was found. We insert a space after the
3388 ;; colon, if there is none.
3389 (if (/= (char-after) ? ) (insert " ") (forward-char 1))
3390 ;; Find out whether the header is empty...
3391 (looking-at "[ \t]*$")))
3392 ;; So we find out what value we should insert.
3395 ((and (consp elem) (eq (car elem) 'optional))
3396 ;; This is an optional header. If the cdr of this
3397 ;; is something that is nil, then we do not insert
3399 (setq header (cdr elem))
3400 (or (and (fboundp (cdr elem)) (funcall (cdr elem)))
3401 (and (boundp (cdr elem)) (symbol-value (cdr elem)))))
3403 ;; The element is a cons. Either the cdr is a
3404 ;; string to be inserted verbatim, or it is a
3405 ;; function, and we insert the value returned from
3407 (or (and (stringp (cdr elem)) (cdr elem))
3408 (and (fboundp (cdr elem)) (funcall (cdr elem)))))
3409 ((and (boundp header) (symbol-value header))
3410 ;; The element is a symbol. We insert the value
3411 ;; of this symbol, if any.
3412 (symbol-value header))
3414 ;; We couldn't generate a value for this header,
3415 ;; so we just ask the user.
3416 (read-from-minibuffer
3417 (format "Empty header for %s; enter value: " header)))))
3418 ;; Finally insert the header.
3420 (not (equal value "")))
3424 ;; This header didn't exist, so we insert it.
3425 (goto-char (point-max))
3426 (insert (if (stringp header) header (symbol-name header))
3429 ;; The value of this header was empty, so we clear
3430 ;; totally and insert the new value.
3431 (delete-region (point) (gnus-point-at-eol))
3433 ;; Add the deletable property to the headers that require it.
3434 (and (memq header message-deletable-headers)
3435 (progn (beginning-of-line) (looking-at "[^:]+: "))
3436 (add-text-properties
3437 (point) (match-end 0)
3438 '(message-deletable t face italic) (current-buffer)))))))
3439 ;; Insert new Sender if the From is strange.
3440 (let ((from (message-fetch-field "from"))
3441 (sender (message-fetch-field "sender"))
3442 (secure-sender (message-make-sender)))
3444 (not (message-check-element 'sender))
3447 (cadr (std11-extract-address-components from)))
3448 (downcase secure-sender)))
3453 (cadr (std11-extract-address-components sender)))
3454 (downcase secure-sender)))))
3455 (goto-char (point-min))
3456 ;; Rename any old Sender headers to Original-Sender.
3457 (when (re-search-forward "^\\(Original-\\)*Sender:" nil t)
3459 (insert "Original-")
3460 (beginning-of-line))
3461 (when (or (message-news-p)
3462 (string-match "@.+\\.." secure-sender))
3463 (insert "Sender: " secure-sender "\n")))))))
3465 (defun message-insert-courtesy-copy ()
3466 "Insert a courtesy message in mail copies of combined messages."
3470 (message-narrow-to-headers)
3471 (when (setq newsgroups (message-fetch-field "newsgroups"))
3472 (goto-char (point-max))
3473 (insert "Posted-To: " newsgroups "\n")))
3475 (when message-courtesy-message
3477 ((string-match "%s" message-courtesy-message)
3478 (insert (format message-courtesy-message newsgroups)))
3480 (insert message-courtesy-message)))))))
3483 ;;; Setting up a message buffer
3486 (defun message-fill-address (header value)
3488 (narrow-to-region (point) (point))
3489 (insert (capitalize (symbol-name header))
3491 (if (consp value) (car value) value)
3493 (narrow-to-region (point-min) (1- (point-max)))
3495 (goto-char (point-min))
3497 (skip-chars-forward "^,\"" (point-max))
3498 (if (or (eq (char-after) ?,)
3501 (if (and (> (current-column) 78)
3505 (looking-at "[ \t]*")
3506 (replace-match "\n " t t)))
3507 (setq last (1+ (point))))
3508 (setq quoted (not quoted)))
3511 (goto-char (point-max))
3515 (defun message-fill-references (header value)
3516 (insert (capitalize (symbol-name header))
3518 (std11-fill-msg-id-list-string
3519 (if (consp value) (car value) value))
3522 (defun message-fill-header (header value)
3523 (let ((begin (point))
3526 (insert (capitalize (symbol-name header))
3528 (if (consp value) (car value) value)
3531 (narrow-to-region begin (point))
3532 (fill-region-as-paragraph begin (point))
3533 ;; Tapdance around looong Message-IDs.
3535 (when (looking-at "[ \t]*$")
3536 (message-delete-line))
3538 (re-search-forward ":" nil t)
3539 (when (looking-at "\n[ \t]+")
3540 (replace-match " " t t))
3541 (goto-char (point-max)))))
3543 (defun message-shorten-references (header references)
3544 "Limit REFERENCES to be shorter than 988 characters."
3550 (goto-char (point-min))
3551 (while (re-search-forward "<[^>]+>" nil t)
3552 (push (match-string 0) refs))
3553 (setq refs (nreverse refs))
3554 (while (> (length (mapconcat 'identity refs " ")) max)
3555 (when (< (length refs) (1+ cut))
3557 (setcdr (nthcdr cut refs) (cddr (nthcdr cut refs)))))
3558 (insert (capitalize (symbol-name header)) ": "
3559 (mapconcat 'identity refs " ") "\n")))
3561 (defun message-position-point ()
3562 "Move point to where the user probably wants to find it."
3563 (message-narrow-to-headers)
3565 ((re-search-forward "^[^:]+:[ \t]*$" nil t)
3566 (search-backward ":" )
3569 (if (eq (char-after) ? )
3573 (goto-char (point-max))
3576 (unless (looking-at "$")
3580 (defun message-buffer-name (type &optional to group)
3581 "Return a new (unique) buffer name based on TYPE and TO."
3583 ;; Check whether `message-generate-new-buffers' is a function,
3584 ;; and if so, call it.
3585 ((message-functionp message-generate-new-buffers)
3586 (funcall message-generate-new-buffers type to group))
3587 ;; Generate a new buffer name The Message Way.
3588 ((eq message-generate-new-buffers 'unique)
3589 (generate-new-buffer-name
3593 (or (car (std11-extract-address-components to))
3596 (if (and group (not (string= group ""))) (concat " on " group) "")
3598 ((eq message-generate-new-buffers 'unsent)
3599 (generate-new-buffer-name
3600 (concat "*unsent " type
3603 (or (car (mail-extract-address-components to))
3606 (if (and group (not (string= group ""))) (concat " on " group) "")
3608 ;; Use standard name.
3610 (format "*%s message*" type))))
3612 (defun message-pop-to-buffer (name)
3613 "Pop to buffer NAME, and warn if it already exists and is modified."
3614 (let ((pop-up-frames pop-up-frames)
3615 (special-display-buffer-names special-display-buffer-names)
3616 (special-display-regexps special-display-regexps)
3617 (same-window-buffer-names same-window-buffer-names)
3618 (same-window-regexps same-window-regexps)
3619 (buffer (get-buffer name))
3620 (cur (current-buffer)))
3621 (if (or (and (featurep 'xemacs)
3622 (not (eq 'tty (device-type))))
3624 (>= emacs-major-version 20))
3625 (when message-use-multi-frames
3626 (setq pop-up-frames t
3627 special-display-buffer-names nil
3628 special-display-regexps nil
3629 same-window-buffer-names nil
3630 same-window-regexps nil))
3631 (setq pop-up-frames nil))
3633 (buffer-name buffer))
3635 (set-buffer (pop-to-buffer buffer))
3636 (when (and (buffer-modified-p)
3638 "Message already being composed; erase? ")))
3639 (error "Message being composed")))
3640 (set-buffer (pop-to-buffer name)))
3644 (make-local-variable 'message-original-frame)
3645 (setq message-original-frame (selected-frame)))))
3647 (defun message-do-send-housekeeping ()
3648 "Kill old message buffers."
3649 ;; We might have sent this buffer already. Delete it from the
3651 (setq message-buffer-list (delq (current-buffer) message-buffer-list))
3652 (while (and message-max-buffers
3654 (>= (length message-buffer-list) message-max-buffers))
3655 ;; Kill the oldest buffer -- unless it has been changed.
3656 (let ((buffer (pop message-buffer-list)))
3657 (when (and (buffer-name buffer)
3658 (not (buffer-modified-p buffer)))
3659 (kill-buffer buffer))))
3660 ;; Rename the buffer.
3661 (if message-send-rename-function
3662 (funcall message-send-rename-function)
3663 (when (string-match "\\`\\*\\(unsent \\)?" (buffer-name))
3665 (concat "*sent " (substring (buffer-name) (match-end 0))) t)))
3666 ;; Push the current buffer onto the list.
3667 (when message-max-buffers
3668 (setq message-buffer-list
3669 (nconc message-buffer-list (list (current-buffer))))))
3671 (defvar mc-modes-alist)
3672 (defun message-setup (headers &optional replybuffer actions)
3673 (when (and (boundp 'mc-modes-alist)
3674 (not (assq 'message-mode mc-modes-alist)))
3675 (push '(message-mode (encrypt . mc-encrypt-message)
3676 (sign . mc-sign-message))
3679 (setq message-send-actions actions))
3680 (setq message-reply-buffer
3681 (or (cdr (assq 'reply-buffer message-parameter-alist))
3683 (goto-char (point-min))
3684 ;; Insert all the headers.
3687 (alist message-header-format-alist))
3689 (unless (assq (caar h) message-header-format-alist)
3690 (push (list (caar h)) alist))
3694 (delete-region (point) (progn (forward-line -1) (point)))
3695 (when message-default-headers
3696 (insert message-default-headers)
3697 (or (bolp) (insert ?\n)))
3701 (insert mail-header-separator "\n")
3705 (when (message-news-p)
3706 (when message-default-news-headers
3707 (insert message-default-news-headers)
3708 (or (bolp) (insert ?\n)))
3709 (when message-generate-headers-first
3710 (message-generate-headers
3713 (copy-sequence message-required-news-headers))))))
3714 (when (message-mail-p)
3715 (when message-default-mail-headers
3716 (insert message-default-mail-headers)
3717 (or (bolp) (insert ?\n)))
3718 (when message-generate-headers-first
3719 (message-generate-headers
3722 (copy-sequence message-required-mail-headers))))))
3723 (run-hooks 'message-signature-setup-hook)
3724 (message-insert-signature)
3726 (message-narrow-to-headers)
3727 (run-hooks 'message-header-setup-hook))
3728 (set-buffer-modified-p nil)
3729 (setq buffer-undo-list nil)
3730 (run-hooks 'message-setup-hook)
3731 (message-position-point)
3734 (defun message-set-auto-save-file-name ()
3735 "Associate the message buffer with a file in the drafts directory."
3736 (when message-auto-save-directory
3738 (setq message-draft-article
3739 (nndraft-request-associate-buffer "drafts"))
3740 (setq buffer-file-name (expand-file-name "*message*"
3741 message-auto-save-directory))
3742 (setq buffer-auto-save-file-name (make-auto-save-file-name)))
3743 (clear-visited-file-modtime)))
3745 (defun message-disassociate-draft ()
3746 "Disassociate the message buffer from the drafts directory."
3747 (when message-draft-article
3748 (nndraft-request-expire-articles
3749 (list message-draft-article) "drafts" nil t)))
3754 ;;; Commands for interfacing with message
3758 (defun message-mail (&optional to subject
3759 other-headers continue switch-function
3760 yank-action send-actions)
3761 "Start editing a mail message to be sent.
3762 OTHER-HEADERS is an alist of header/value pairs."
3764 (let ((message-this-is-mail t))
3765 (message-pop-to-buffer (message-buffer-name "mail" to))
3768 `((To . ,(or to "")) (Subject . ,(or subject "")))
3769 (when other-headers other-headers)))))
3772 (defun message-news (&optional newsgroups subject)
3773 "Start editing a news article to be sent."
3775 (let ((message-this-is-news t))
3776 (message-pop-to-buffer (message-buffer-name "news" nil newsgroups))
3777 (message-setup `((Newsgroups . ,(or newsgroups ""))
3778 (Subject . ,(or subject ""))))))
3781 (defun message-reply (&optional to-address wide)
3782 "Start editing a reply to the article in the current buffer."
3784 (let ((cur (current-buffer))
3785 from subject date to cc
3786 references message-id follow-to
3787 (inhibit-point-motion-hooks t)
3788 mct never-mct mft mrt gnus-warning)
3790 (message-narrow-to-head)
3791 ;; Allow customizations to have their say.
3793 ;; This is a regular reply.
3794 (if (message-functionp message-reply-to-function)
3795 (setq follow-to (funcall message-reply-to-function)))
3796 ;; This is a followup.
3797 (if (message-functionp message-wide-reply-to-function)
3800 (funcall message-wide-reply-to-function)))))
3801 ;; Find all relevant headers we need.
3802 (setq from (message-fetch-field "from")
3803 date (message-fetch-field "date" t)
3804 subject (or (message-fetch-field "subject") "none")
3805 references (message-fetch-field "references")
3806 message-id (message-fetch-field "message-id" t)
3807 to (message-fetch-field "to")
3808 cc (message-fetch-field "cc")
3809 mct (when (and wide message-use-mail-copies-to)
3810 (message-fetch-field "mail-copies-to"))
3811 mft (when (and wide message-use-mail-followup-to)
3812 (message-fetch-field "mail-followup-to"))
3813 mrt (when message-use-mail-reply-to
3814 (or (message-fetch-field "mail-reply-to")
3815 (message-fetch-field "reply-to")))
3816 gnus-warning (message-fetch-field "gnus-warning"))
3817 (when (and gnus-warning (string-match "<[^>]+>" gnus-warning))
3818 (setq message-id (match-string 0 gnus-warning)))
3819 ;; Remove any (buggy) Re:'s that are present and make a
3821 (setq subject (message-make-followup-subject subject))
3824 ;; Handle special values of Mail-Copies-To.
3827 ((and (or (equal (downcase mct) "never")
3828 (equal (downcase mct) "nobody"))
3829 (or (not (eq message-use-mail-copies-to 'ask))
3831 (concat "Obey Mail-Copies-To: never? ") t "\
3832 You should normally obey the Mail-Copies-To: header.
3834 `Mail-Copies-To: never'
3835 directs you not to send your response to the author.")))
3838 ((and (or (equal (downcase mct) "always")
3839 (equal (downcase mct) "poster"))
3840 (or (not (eq message-use-mail-copies-to 'ask))
3842 (concat "Obey Mail-Copies-To: always? ") t "\
3843 You should normally obey the Mail-Copies-To: header.
3845 `Mail-Copies-To: always'
3846 sends a copy of your response to the author.")))
3847 (setq mct (or mrt from)))
3848 ((and (eq message-use-mail-copies-to 'ask)
3851 (concat "Obey Mail-Copies-To: " mct " ? ") t "\
3852 You should normally obey the Mail-Copies-To: header.
3854 `Mail-Copies-To: " mct "'
3855 sends a copy of your response to " (if (string-match "," mct)
3856 "the specified addresses"
3857 "that address") ".")))
3863 (to-address (setq follow-to (list (cons 'To to-address))))
3864 ((not wide) (setq follow-to (list (cons 'To (or mrt from)))))
3865 ;; Handle Mail-Followup-To.
3867 (or (not (eq message-use-mail-followup-to 'ask))
3869 (concat "Obey Mail-Followup-To: " mft "? ") t "\
3870 You should normally obey the Mail-Followup-To: header.
3872 `Mail-Followup-To: " mft "'
3873 directs your response to " (if (string-match "," mft)
3874 "the specified addresses"
3875 "that address only") ".
3877 A typical situation where Mail-Followup-To is used is when the author thinks
3878 that further discussion should take place only in "
3879 (if (string-match "," mft)
3880 "the specified mailing lists"
3881 "that mailing list") ".")))
3882 (setq follow-to (list (cons 'To mft)))
3884 (push (cons 'Cc mct) follow-to)))
3888 (message-set-work-buffer)
3890 (insert (or mrt from "")))
3891 (insert (if to (concat (if (bolp) "" ", ") to "") ""))
3892 (insert (if mct (concat (if (bolp) "" ", ") mct) ""))
3893 (insert (if cc (concat (if (bolp) "" ", ") cc) ""))
3894 (goto-char (point-min))
3895 (while (re-search-forward "[ \t]+" nil t)
3896 (replace-match " " t t))
3897 ;; Remove addresses that match `rmail-dont-reply-to-names'.
3898 (insert (prog1 (rmail-dont-reply-to (buffer-string))
3900 (goto-char (point-min))
3901 ;; Perhaps Mail-Copies-To: never removed the only address?
3903 (insert (or mrt from "")))
3907 (cons (mail-strip-quoted-names addr) addr))
3908 (message-tokenize-header (buffer-string))))
3911 (setq ccalist (delq (assoc (car (pop s)) s) ccalist)))))
3912 (setq follow-to (list (cons 'To (cdr (pop ccalist)))))
3914 (let ((ccs (cons 'Cc (mapconcat
3915 (lambda (addr) (cdr addr)) ccalist ", "))))
3916 (when (string-match "^ +" (cdr ccs))
3917 (setcdr ccs (substring (cdr ccs) (match-end 0))))
3918 (push ccs follow-to)))))))
3920 (message-pop-to-buffer (message-buffer-name
3921 (if wide "wide reply" "reply") from
3922 (if wide to-address nil)))
3924 (setq message-reply-headers
3925 (make-full-mail-header-from-decoded-header
3926 0 subject from date message-id references 0 0 ""))
3929 `((Subject . ,subject)
3931 ,@(if (or references message-id)
3932 `((References . ,(concat (or references "") (and references " ")
3933 (or message-id ""))))))
3937 (defun message-wide-reply (&optional to-address)
3938 "Make a \"wide\" reply to the message in the current buffer."
3940 (message-reply to-address t))
3943 (defun message-followup (&optional to-newsgroups)
3944 "Follow up to the message in the current buffer.
3945 If TO-NEWSGROUPS, use that as the new Newsgroups line."
3947 (let ((cur (current-buffer))
3948 from subject date mct
3949 references message-id follow-to
3950 (inhibit-point-motion-hooks t)
3951 (message-this-is-news t)
3952 followup-to distribution newsgroups gnus-warning posted-to mft mrt)
3954 (message-narrow-to-head)
3955 (when (message-functionp message-followup-to-function)
3957 (funcall message-followup-to-function)))
3958 (setq from (message-fetch-field "from")
3959 date (message-fetch-field "date" t)
3960 subject (or (message-fetch-field "subject") "none")
3961 references (message-fetch-field "references")
3962 message-id (message-fetch-field "message-id" t)
3963 followup-to (when message-use-followup-to
3964 (message-fetch-field "followup-to"))
3965 distribution (message-fetch-field "distribution")
3966 newsgroups (message-fetch-field "newsgroups")
3967 posted-to (message-fetch-field "posted-to")
3968 mct (when message-use-mail-copies-to
3969 (message-fetch-field "mail-copies-to"))
3970 mft (when message-use-mail-followup-to
3971 (message-fetch-field "mail-followup-to"))
3972 mrt (when message-use-mail-reply-to
3973 (or (message-fetch-field "mail-reply-to")
3974 (message-fetch-field "reply-to")))
3975 gnus-warning (message-fetch-field "gnus-warning"))
3976 (when (and gnus-warning (string-match "<[^>]+>" gnus-warning))
3977 (setq message-id (match-string 0 gnus-warning)))
3978 ;; Remove bogus distribution.
3979 (when (and (stringp distribution)
3980 (let ((case-fold-search t))
3981 (string-match "world" distribution)))
3982 (setq distribution nil))
3983 ;; Remove any (buggy) Re:'s that are present and make a
3985 (setq subject (message-make-followup-subject subject))
3988 ;; Handle special values of Mail-Copies-To.
3991 ((and (or (equal (downcase mct) "never")
3992 (equal (downcase mct) "nobody"))
3993 (or (not (eq message-use-mail-copies-to 'ask))
3995 (concat "Obey Mail-Copies-To: never? ") t "\
3996 You should normally obey the Mail-Copies-To: header.
3998 `Mail-Copies-To: never'
3999 directs you not to send your response to the author.")))
4001 ((and (or (equal (downcase mct) "always")
4002 (equal (downcase mct) "poster"))
4003 (or (not (eq message-use-mail-copies-to 'ask))
4005 (concat "Obey Mail-Copies-To: always? ") t "\
4006 You should normally obey the Mail-Copies-To: header.
4008 `Mail-Copies-To: always'
4009 sends a copy of your response to the author.")))
4010 (setq mct (or mrt from)))
4011 ((and (eq message-use-mail-copies-to 'ask)
4014 (concat "Obey Mail-Copies-To: " mct " ? ") t "\
4015 You should normally obey the Mail-Copies-To: header.
4017 `Mail-Copies-To: " mct "'
4018 sends a copy of your response to " (if (string-match "," mct)
4019 "the specified addresses"
4020 "that address") ".")))
4026 (to-newsgroups (setq follow-to (list (cons 'Newsgroups to-newsgroups))))
4027 ;; Handle Followup-To.
4030 ((equal (downcase followup-to) "poster")
4031 (if (or (eq message-use-followup-to 'use)
4032 (message-y-or-n-p "Obey Followup-To: poster? " t "\
4033 You should normally obey the Followup-To: header.
4035 `Followup-To: poster'
4036 sends your response via e-mail instead of news.
4038 A typical situation where `Followup-To: poster' is used is when the author
4039 does not read the newsgroup, so he wouldn't see any replies sent to it."))
4040 (setq message-this-is-news nil
4042 follow-to (list (cons 'To (or mrt from ""))))
4043 (setq follow-to (list (cons 'Newsgroups newsgroups)))))
4045 (if (or (equal followup-to newsgroups)
4046 (not (eq message-use-followup-to 'ask))
4048 (concat "Obey Followup-To: " followup-to "? ") t "\
4049 You should normally obey the Followup-To: header.
4051 `Followup-To: " followup-to "'
4052 directs your response to " (if (string-match "," followup-to)
4053 "the specified newsgroups"
4054 "that newsgroup only") ".
4056 If a message is posted to several newsgroups, Followup-To is often
4057 used to direct the following discussion to one newsgroup only,
4058 because discussions that are spread over several newsgroup tend to
4059 be fragmented and very difficult to follow.
4061 Also, some source/announcement newsgroups are not indented for discussion;
4062 responses here are directed to other newsgroups."))
4063 (setq follow-to (list (cons 'Newsgroups followup-to)))
4064 (setq follow-to (list (cons 'Newsgroups newsgroups)))))))
4065 ;; Handle Mail-Followup-To, followup via e-mail.
4067 (or (not (eq message-use-mail-followup-to 'ask))
4069 (concat "Obey Mail-Followup-To: " mft "? ") t "\
4070 You should normally obey the Mail-Followup-To: header.
4072 `Mail-Followup-To: " mft "'
4073 directs your response to " (if (string-match "," mft)
4074 "the specified addresses"
4075 "that address only") " instead of news.
4077 A typical situation where Mail-Followup-To is used is when the author thinks
4078 that further discussion should take place only in "
4079 (if (string-match "," mft)
4080 "the specified mailing lists"
4081 "that mailing list") ".")))
4082 (setq message-this-is-news nil
4084 follow-to (list (cons 'To mft))))
4085 (posted-to (setq follow-to (list (cons 'Newsgroups posted-to))))
4087 (setq follow-to (list (cons 'Newsgroups newsgroups))))))
4089 (message-pop-to-buffer (message-buffer-name "followup" from newsgroups))
4091 (setq message-reply-headers
4092 (make-full-mail-header-from-decoded-header
4093 0 subject from date message-id references 0 0 ""))
4096 `((Subject . ,subject)
4098 ,@(and mct (list (cons 'Cc mct)))
4099 ,@(and distribution (list (cons 'Distribution distribution)))
4100 ,@(if (or references message-id)
4101 `((References . ,(concat (or references "") (and references " ")
4102 (or message-id ""))))))
4106 (defun message-cancel-news ()
4107 "Cancel an article you posted."
4109 (unless (message-news-p)
4110 (error "This is not a news article; canceling is impossible"))
4111 (when (yes-or-no-p "Do you really want to cancel this article? ")
4112 (let (from newsgroups message-id distribution buf sender)
4114 ;; Get header info. from original article.
4116 (message-narrow-to-head)
4117 (setq from (message-fetch-field "from")
4118 sender (message-fetch-field "sender")
4119 newsgroups (message-fetch-field "newsgroups")
4120 message-id (message-fetch-field "message-id" t)
4121 distribution (message-fetch-field "distribution")))
4122 ;; Make sure that this article was written by the user.
4123 (unless (or (and sender
4126 (downcase (message-make-sender))))
4128 (downcase (cadr (std11-extract-address-components
4130 (downcase (cadr (std11-extract-address-components
4131 (message-make-from))))))
4132 (error "This article is not yours"))
4133 ;; Make control message.
4134 (setq buf (set-buffer (get-buffer-create " *message cancel*")))
4136 (insert "Newsgroups: " newsgroups "\n"
4137 "From: " (message-make-from) "\n"
4138 "Subject: cmsg cancel " message-id "\n"
4139 "Control: cancel " message-id "\n"
4141 (concat "Distribution: " distribution "\n")
4143 mail-header-separator "\n"
4144 message-cancel-message)
4145 (message "Canceling your article...")
4146 (if (let ((message-syntax-checks
4147 'dont-check-for-anything-just-trust-me)
4148 (message-encoding-buffer (current-buffer))
4149 (message-edit-buffer (current-buffer)))
4150 (message-send-news))
4151 (message "Canceling your article...done"))
4152 (kill-buffer buf)))))
4155 (defun message-supersede ()
4156 "Start composing a message to supersede the current message.
4157 This is done simply by taking the old article and adding a Supersedes
4158 header line with the old Message-ID."
4160 (let ((cur (current-buffer))
4161 (sender (message-fetch-field "sender"))
4162 (from (message-fetch-field "from")))
4163 ;; Check whether the user owns the article that is to be superseded.
4164 (unless (or (and sender
4167 (downcase (message-make-sender))))
4169 (downcase (cadr (std11-extract-address-components from)))
4170 (downcase (cadr (std11-extract-address-components
4171 (message-make-from))))))
4172 (error "This article is not yours"))
4173 ;; Get a normal message buffer.
4174 (message-pop-to-buffer (message-buffer-name "supersede"))
4175 (insert-buffer-substring cur)
4176 (message-narrow-to-head)
4177 ;; Remove unwanted headers.
4178 (when message-ignored-supersedes-headers
4179 (message-remove-header message-ignored-supersedes-headers t))
4180 (goto-char (point-min))
4181 (if (not (re-search-forward "^Message-ID: " nil t))
4182 (error "No Message-ID in this article")
4183 (replace-match "Supersedes: " t t))
4184 (goto-char (point-max))
4185 (insert mail-header-separator)
4190 (defun message-recover ()
4191 "Reread contents of current buffer from its last auto-save file."
4193 (let ((file-name (make-auto-save-file-name)))
4194 (cond ((save-window-excursion
4195 (if (not (eq system-type 'vax-vms))
4196 (with-output-to-temp-buffer "*Directory*"
4197 (buffer-disable-undo standard-output)
4198 (let ((default-directory "/"))
4200 "ls" nil standard-output nil "-l" file-name))))
4201 (yes-or-no-p (format "Recover auto save file %s? " file-name)))
4202 (let ((buffer-read-only nil))
4204 (insert-file-contents file-name nil)))
4205 (t (error "message-recover cancelled")))))
4207 ;;; Washing Subject:
4209 (defun message-wash-subject (subject)
4210 "Remove junk like \"Re:\", \"(fwd)\", etc. that was added to the subject by previous forwarders, replyers, etc."
4212 (insert-string subject)
4213 (goto-char (point-min))
4214 ;; strip Re/Fwd stuff off the beginning
4215 (while (re-search-forward
4216 "\\([Rr][Ee]:\\|[Ff][Ww][Dd]\\(\\[[0-9]*\\]\\)?:\\|[Ff][Ww]:\\)" nil t)
4219 ;; and gnus-style forwards [foo@bar.com] subject
4220 (goto-char (point-min))
4221 (while (re-search-forward "\\[[^ \t]*\\(@\\|\\.\\)[^ \t]*\\]" nil t)
4225 (goto-char (point-max))
4226 (while (re-search-backward "([Ff][Ww][Dd])" nil t)
4229 ;; and finally, any whitespace that was left-over
4230 (goto-char (point-min))
4231 (while (re-search-forward "^[ \t]+" nil t)
4233 (goto-char (point-max))
4234 (while (re-search-backward "[ \t]+$" nil t)
4239 ;;; Forwarding messages.
4241 (defun message-forward-subject-author-subject (subject)
4242 "Generate a subject for a forwarded message.
4243 The form is: [Source] Subject, where if the original message was mail,
4244 Source is the sender, and if the original message was news, Source is
4245 the list of newsgroups is was posted to."
4247 (or (message-fetch-field
4248 (if (message-news-p) "newsgroups" "from"))
4252 (defun message-forward-subject-fwd (subject)
4253 "Generate a subject for a forwarded message.
4254 The form is: Fwd: Subject, where Subject is the original subject of
4256 (concat "Fwd: " subject))
4258 (defun message-make-forward-subject ()
4259 "Return a Subject header suitable for the message in the current buffer."
4263 (message-narrow-to-head)
4264 (let ((funcs message-make-forward-subject-function)
4265 (subject (if message-wash-forwarded-subjects
4266 (message-wash-subject
4267 (or (eword-decode-unstructured-field-body
4268 (message-fetch-field "Subject")) ""))
4269 (or (eword-decode-unstructured-field-body
4270 (message-fetch-field "Subject")) ""))))
4271 ;; Make sure funcs is a list.
4274 (setq funcs (list funcs)))
4275 ;; Apply funcs in order, passing subject generated by previous
4276 ;; func to the next one.
4278 (when (message-functionp (car funcs))
4279 (setq subject (funcall (car funcs) subject)))
4280 (setq funcs (cdr funcs)))
4284 (defun message-forward (&optional news)
4285 "Forward the current message via mail.
4286 Optional NEWS will use news to forward instead of mail."
4288 (let ((cur (current-buffer))
4289 (subject (message-make-forward-subject))
4291 (if news (message-news nil subject) (message-mail nil subject))
4292 ;; Put point where we want it before inserting the forwarded
4294 (if message-signature-before-forwarded-message
4295 (goto-char (point-max))
4296 (message-goto-body))
4297 ;; Make sure we're at the start of the line.
4300 ;; Narrow to the area we are to insert.
4301 (narrow-to-region (point) (point))
4302 ;; Insert the separators and the forwarded buffer.
4303 (insert message-forward-start-separator)
4304 (setq art-beg (point))
4305 (insert-buffer-substring cur)
4306 (goto-char (point-max))
4307 (insert message-forward-end-separator)
4308 (set-text-properties (point-min) (point-max) nil)
4309 ;; Remove all unwanted headers.
4311 (narrow-to-region (point) (if (search-forward "\n\n" nil t)
4314 (goto-char (point-min))
4315 (message-remove-header message-included-forward-headers t nil t)
4317 (message-position-point)))
4320 (defun message-resend (address)
4321 "Resend the current article to ADDRESS."
4322 (interactive "sResend message to: ")
4323 (message "Resending message to %s..." address)
4325 (let ((cur (current-buffer))
4327 ;; We first set up a normal mail buffer.
4328 (set-buffer (get-buffer-create " *message resend*"))
4330 ;; avoid to turn-on-mime-edit
4331 (let (message-setup-hook)
4332 (message-setup `((To . ,address)))
4334 ;; Insert our usual headers.
4335 (message-generate-headers '(From Date To))
4336 (message-narrow-to-headers)
4337 ;; Rename them all to "Resent-*".
4338 (while (re-search-forward "^[A-Za-z]" nil t)
4343 (delete-region (point) (point-max))
4345 ;; Insert the message to be resent.
4346 (insert-buffer-substring cur)
4347 (goto-char (point-min))
4348 (search-forward "\n\n")
4351 (narrow-to-region beg (point))
4352 (message-remove-header message-ignored-resent-headers t)
4353 (goto-char (point-max)))
4354 (insert mail-header-separator)
4355 ;; Rename all old ("Also-")Resent headers.
4356 (while (re-search-backward "^\\(Also-\\)*Resent-" beg t)
4359 ;; Quote any "From " lines at the beginning.
4361 (when (looking-at "From ")
4362 (replace-match "X-From-Line: "))
4364 (let ((message-encoding-buffer (current-buffer))
4365 (message-edit-buffer (current-buffer)))
4366 (message-send-mail))
4367 (kill-buffer (current-buffer)))
4368 (message "Resending message to %s...done" address)))
4370 (defun message-bounce-setup-for-mime-edit ()
4371 (goto-char (point-min))
4372 (when (search-forward (concat "\n" mail-header-separator "\n") nil t)
4373 (replace-match "\n\n"))
4374 (set (make-local-variable 'message-setup-hook) nil)
4378 (defun message-bounce ()
4379 "Re-mail the current message.
4380 This only makes sense if the current message is a bounce message than
4381 contains some mail you have written which has been bounced back to
4384 (let ((cur (current-buffer))
4386 (message-pop-to-buffer (message-buffer-name "bounce"))
4387 (insert-buffer-substring cur)
4389 (message-narrow-to-head)
4390 (if (and (message-fetch-field "MIME-Version")
4391 (setq boundary (message-fetch-field "Content-Type")))
4392 (if (string-match "boundary=\"\\([^\"]+\\)\"" boundary)
4393 (setq boundary (concat (match-string 1 boundary) " *\n"
4394 "Content-Type: message/rfc822"))
4395 (setq boundary nil)))
4397 (goto-char (point-min))
4398 (search-forward "\n\n" nil t)
4400 (re-search-forward boundary nil t)
4402 (and (re-search-forward message-unsent-separator nil t)
4404 (re-search-forward "^Return-Path:.*\n" nil t))
4405 ;; We remove everything before the bounced mail.
4408 (if (re-search-forward "^[^ \n\t]+:" nil t)
4412 (message-narrow-to-head)
4413 (message-remove-header message-ignored-bounced-headers t)
4414 (goto-char (point-max))
4415 (insert mail-header-separator))
4416 (when message-bounce-setup-function
4417 (funcall message-bounce-setup-function))
4418 (run-hooks 'message-bounce-setup-hook)
4419 (message-position-point)))
4422 ;;; Interactive entry points for new message buffers.
4426 (defun message-mail-other-window (&optional to subject)
4427 "Like `message-mail' command, but display mail buffer in another window."
4429 (let ((pop-up-windows t)
4430 (special-display-buffer-names nil)
4431 (special-display-regexps nil)
4432 (same-window-buffer-names nil)
4433 (same-window-regexps nil))
4434 (message-pop-to-buffer (message-buffer-name "mail" to)))
4435 (let ((message-this-is-mail t))
4436 (message-setup `((To . ,(or to "")) (Subject . ,(or subject ""))))))
4439 (defun message-mail-other-frame (&optional to subject)
4440 "Like `message-mail' command, but display mail buffer in another frame."
4442 (let ((pop-up-frames t)
4443 (special-display-buffer-names nil)
4444 (special-display-regexps nil)
4445 (same-window-buffer-names nil)
4446 (same-window-regexps nil))
4447 (message-pop-to-buffer (message-buffer-name "mail" to)))
4448 (let ((message-this-is-mail t))
4449 (message-setup `((To . ,(or to "")) (Subject . ,(or subject ""))))))
4452 (defun message-news-other-window (&optional newsgroups subject)
4453 "Start editing a news article to be sent."
4455 (let ((pop-up-windows t)
4456 (special-display-buffer-names nil)
4457 (special-display-regexps nil)
4458 (same-window-buffer-names nil)
4459 (same-window-regexps nil))
4460 (message-pop-to-buffer (message-buffer-name "news" nil newsgroups)))
4461 (let ((message-this-is-news t))
4462 (message-setup `((Newsgroups . ,(or newsgroups ""))
4463 (Subject . ,(or subject ""))))))
4466 (defun message-news-other-frame (&optional newsgroups subject)
4467 "Start editing a news article to be sent."
4469 (let ((pop-up-frames t)
4470 (special-display-buffer-names nil)
4471 (special-display-regexps nil)
4472 (same-window-buffer-names nil)
4473 (same-window-regexps nil))
4474 (message-pop-to-buffer (message-buffer-name "news" nil newsgroups)))
4475 (let ((message-this-is-news t))
4476 (message-setup `((Newsgroups . ,(or newsgroups ""))
4477 (Subject . ,(or subject ""))))))
4481 ;; This code should be moved to underline.el (from which it is stolen).
4484 (defun bold-region (start end)
4485 "Bold all nonblank characters in the region.
4486 Works by overstriking characters.
4487 Called from program, takes two arguments START and END
4488 which specify the range to operate on."
4491 (let ((end1 (make-marker)))
4492 (move-marker end1 (max start end))
4493 (goto-char (min start end))
4494 (while (< (point) end1)
4495 (or (looking-at "[_\^@- ]")
4496 (insert (char-after) "\b"))
4497 (forward-char 1)))))
4500 (defun unbold-region (start end)
4501 "Remove all boldness (overstruck characters) in the region.
4502 Called from program, takes two arguments START and END
4503 which specify the range to operate on."
4506 (let ((end1 (make-marker)))
4507 (move-marker end1 (max start end))
4508 (goto-char (min start end))
4509 (while (re-search-forward "\b" end1 t)
4510 (if (eq (char-after) (char-after (- (point) 2)))
4511 (delete-char -2))))))
4513 (defalias 'message-exchange-point-and-mark 'exchange-point-and-mark)
4515 ;; Support for toolbar
4516 (when (string-match "XEmacs\\|Lucid" emacs-version)
4517 (require 'messagexmas))
4519 ;;; Group name completion.
4521 (defvar message-newgroups-header-regexp
4522 "^\\(Newsgroups\\|Followup-To\\|Posted-To\\|Gcc\\):"
4523 "Regexp that match headers that lists groups.")
4525 (defun message-tab ()
4526 "Expand group names in Newsgroups and Followup-To headers.
4527 Do a `tab-to-tab-stop' if not in those headers."
4529 (if (let ((mail-abbrev-mode-regexp message-newgroups-header-regexp))
4530 (mail-abbrev-in-expansion-header-p))
4531 (message-expand-group)
4534 (defvar gnus-active-hashtb)
4535 (defun message-expand-group ()
4536 "Expand the group name under point."
4537 (let* ((b (save-excursion
4542 (skip-chars-forward "^:")
4545 (skip-chars-backward "^, \t\n") (point))))
4546 (completion-ignore-case t)
4547 (string (buffer-substring b (progn (skip-chars-forward "^,\t\n ")
4549 (hashtb (and (boundp 'gnus-active-hashtb) gnus-active-hashtb))
4550 (completions (all-completions string hashtb))
4552 (delete-region b (point))
4554 ((= (length completions) 1)
4555 (if (string= (car completions) string)
4558 (message "Only matching group"))
4559 (insert (car completions))))
4560 ((and (setq comp (try-completion string hashtb))
4561 (not (string= comp string)))
4566 (message "No matching groups")
4567 (save-selected-window
4568 (pop-to-buffer "*Completions*")
4569 (buffer-disable-undo)
4570 (let ((buffer-read-only nil))
4572 (let ((standard-output (current-buffer)))
4573 (display-completion-list (sort completions 'string<)))
4574 (goto-char (point-min))
4575 (delete-region (point) (progn (forward-line 3) (point))))))))))
4579 (defun message-talkative-question (ask question show &rest text)
4580 "Call FUNCTION with argument QUESTION; optionally display TEXT... args.
4581 If SHOW is non-nil, the arguments TEXT... are displayed in a temp buffer.
4582 The following arguments may contain lists of values."
4584 (setq text (message-flatten-list text)))
4585 (save-window-excursion
4587 (with-output-to-temp-buffer " *MESSAGE information message*"
4588 (set-buffer " *MESSAGE information message*")
4589 (mapcar 'princ text)
4590 (goto-char (point-min))))
4591 (funcall ask question))
4592 (funcall ask question)))
4594 (defun message-flatten-list (list)
4595 "Return a new, flat list that contains all elements of LIST.
4597 \(message-flatten-list '(1 (2 3 (4 5 (6))) 7))
4600 (apply 'append (mapcar 'message-flatten-list list)))
4604 (defun message-generate-new-buffer-clone-locals (name &optional varstr)
4605 "Create and return a buffer with a name based on NAME using generate-new-buffer.
4606 Then clone the local variables and values from the old buffer to the
4607 new one, cloning only the locals having a substring matching the
4609 (let ((oldbuf (current-buffer)))
4611 (set-buffer (generate-new-buffer name))
4612 (message-clone-locals oldbuf)
4615 (defun message-clone-locals (buffer)
4616 "Clone the local variables from BUFFER to the current buffer."
4617 (let ((locals (save-excursion
4619 (buffer-local-variables)))
4620 (regexp "^gnus\\|^nn\\|^message"))
4623 (when (and (consp local)
4625 (string-match regexp (symbol-name (car local))))
4627 (set (make-local-variable (car local))
4632 ;;; @ for MIME Edit mode
4635 (defun message-maybe-encode ()
4636 (when message-mime-mode
4637 (run-hooks 'mime-edit-translate-hook)
4638 (if (catch 'mime-edit-error
4640 (mime-edit-translate-body)
4642 (error "Translation error!")
4645 (run-hooks 'mime-edit-exit-hook)
4648 (defun message-mime-insert-article (&optional full-headers)
4650 (let ((message-cite-function 'mime-edit-inserted-message-filter)
4651 (message-reply-buffer (message-get-original-reply-buffer))
4653 (message-yank-original nil)
4655 (narrow-to-region (goto-char start)
4656 (if (search-forward "\n\n" nil t)
4659 (goto-char (point-min))
4660 (let ((message-included-forward-headers
4661 (if full-headers "" message-included-forward-headers)))
4662 (message-remove-header message-included-forward-headers t nil t))
4665 (set-alist 'mime-edit-message-inserter-alist
4666 'message-mode (function message-mime-insert-article))
4668 ;;; Miscellaneous functions
4670 ;; stolen (and renamed) from nnheader.el
4671 (defun message-replace-chars-in-string (string from to)
4672 "Replace characters in STRING from FROM to TO."
4673 (let ((string (substring string 0)) ;Copy string.
4674 (len (length string))
4676 ;; Replace all occurrences of FROM with TO.
4678 (when (= (aref string idx) from)
4679 (aset string idx to))
4680 (setq idx (1+ idx)))
4687 (defun message-encode-message-body ()
4688 "Examine the message body, encode it, and add the requisite headers."
4689 (when (featurep 'mule)
4693 (message-narrow-to-headers-or-head)
4694 (unless (setq old-headers (message-fetch-field "mime-version"))
4695 (message-remove-header
4696 "^Content-Transfer-Encoding:\\|^Content-Type:\\|^Mime-Version:" t))
4697 (goto-char (point-max))
4699 (narrow-to-region (point) (point-max))
4700 (let* ((charset (mm-encode-body))
4701 (encoding (mm-body-encoding)))
4702 (when (consp charset)
4703 (error "Can't encode messages with multiple charsets (yet)"))
4705 (message-narrow-to-headers-or-head)
4706 (goto-char (point-max))
4707 (setq charset (or charset
4708 (mm-mule-charset-to-mime-charset 'ascii)))
4709 ;; We don't insert MIME headers if they only say the default.
4710 (when (and (not old-headers)
4711 (not (and (eq charset 'us-ascii)
4712 (eq encoding '7bit))))
4713 (mm-insert-rfc822-headers charset encoding))
4714 (mm-encode-body)))))))
4716 (defvar message-save-buffer " *encoding")
4717 (defun message-save-drafts ()
4719 (if (not (get-buffer message-save-buffer))
4720 (get-buffer-create message-save-buffer))
4721 (let ((filename buffer-file-name)
4722 (buffer (current-buffer)))
4723 (set-buffer message-save-buffer)
4725 (insert-buffer buffer)
4726 (mime-edit-translate-buffer)
4727 (write-region (point-min) (point-max) filename)
4729 (set-buffer-modified-p nil)))
4731 (run-hooks 'message-load-hook)
4735 ;;; message.el ends here