1 ;;; message.el --- composing mail and news messages -*- coding: iso-latin-1 -*-
2 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001
3 ;; Free Software Foundation, Inc.
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
6 ;; Keywords: mail, news
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
27 ;; This mode provides mail-sending facilities from within Emacs. It
28 ;; consists mainly of large chunks of code from the sendmail.el,
29 ;; gnus-msg.el and rnewspost.el files.
35 (defvar gnus-list-identifiers)) ; gnus-sum is required where necessary
38 ;; This is apparently necessary even though things are autoloaded:
39 (if (featurep 'xemacs)
40 (require 'mail-abbrevs))
44 (defgroup message '((user-mail-address custom-variable)
45 (user-full-name custom-variable))
46 "Mail and news message composing."
47 :link '(custom-manual "(message)Top")
51 (put 'user-mail-address 'custom-type 'string)
52 (put 'user-full-name 'custom-type 'string)
54 (defgroup message-various nil
55 "Various Message Variables"
56 :link '(custom-manual "(message)Various Message Variables")
59 (defgroup message-buffers nil
61 :link '(custom-manual "(message)Message Buffers")
64 (defgroup message-sending nil
66 :link '(custom-manual "(message)Sending Variables")
69 (defgroup message-interface nil
71 :link '(custom-manual "(message)Interface")
74 (defgroup message-forwarding nil
76 :link '(custom-manual "(message)Forwarding")
77 :group 'message-interface)
79 (defgroup message-insertion nil
81 :link '(custom-manual "(message)Insertion")
84 (defgroup message-headers nil
86 :link '(custom-manual "(message)Message Headers")
89 (defgroup message-news nil
90 "Composing News Messages"
93 (defgroup message-mail nil
94 "Composing Mail Messages"
97 (defgroup message-faces nil
98 "Faces used for message composing."
102 (defcustom message-directory "~/Mail/"
103 "*Directory from which all other mail file variables are derived."
104 :group 'message-various
107 (defcustom message-max-buffers 10
108 "*How many buffers to keep before starting to kill them off."
109 :group 'message-buffers
112 (defcustom message-send-rename-function nil
113 "Function called to rename the buffer after sending it."
114 :group 'message-buffers
115 :type '(choice function (const nil)))
117 (defcustom message-fcc-handler-function 'message-output
118 "*A function called to save outgoing articles.
119 This function will be called with the name of the file to store the
120 article in. The default function is `message-output' which saves in Unix
122 :type '(radio (function-item message-output)
123 (function :tag "Other"))
124 :group 'message-sending)
126 (defcustom message-courtesy-message
127 "The following message is a courtesy copy of an article\nthat has been posted to %s as well.\n\n"
128 "*This is inserted at the start of a mailed copy of a posted message.
129 If the string contains the format spec \"%s\", the Newsgroups
130 the article has been posted to will be inserted there.
131 If this variable is nil, no such courtesy message will be added."
132 :group 'message-sending
135 (defcustom message-ignored-bounced-headers "^\\(Received\\|Return-Path\\):"
136 "*Regexp that matches headers to be removed in resent bounced mail."
137 :group 'message-interface
141 (defcustom message-from-style 'default
142 "*Specifies how \"From\" headers look.
144 If nil, they contain just the return address like:
146 If `parens', they look like:
147 king@grassland.com (Elvis Parsley)
148 If `angles', they look like:
149 Elvis Parsley <king@grassland.com>
151 Otherwise, most addresses look like `angles', but they look like
152 `parens' if `angles' would need quoting and `parens' would not."
153 :type '(choice (const :tag "simple" nil)
157 :group 'message-headers)
159 (defcustom message-syntax-checks nil
160 ;; Guess this one shouldn't be easy to customize...
161 "*Controls what syntax checks should not be performed on outgoing posts.
162 To disable checking of long signatures, for instance, add
163 `(signature . disabled)' to this list.
165 Don't touch this variable unless you really know what you're doing.
167 Checks include `subject-cmsg', `multiple-headers', `sendsys',
168 `message-id', `from', `long-lines', `control-chars', `size',
169 `new-text', `quoting-style', `redirected-followup', `signature',
170 `approved', `sender', `empty', `empty-headers', `message-id', `from',
171 `subject', `shorten-followup-to', `existing-newsgroups',
172 `buffer-file-name', `unchanged', `newsgroups'."
174 :type '(repeat sexp)) ; Fixme: improve this
176 (defcustom message-required-news-headers
177 '(From Newsgroups Subject Date Message-ID
178 (optional . Organization) Lines
179 (optional . User-Agent))
180 "*Headers to be generated or prompted for when posting an article.
181 RFC977 and RFC1036 require From, Date, Newsgroups, Subject,
182 Message-ID. Organization, Lines, In-Reply-To, Expires, and
183 User-Agent are optional. If don't you want message to insert some
184 header, remove it from this list."
186 :group 'message-headers
187 :type '(repeat sexp))
189 (defcustom message-required-mail-headers
190 '(From Subject Date (optional . In-Reply-To) Message-ID Lines
191 (optional . User-Agent))
192 "*Headers to be generated or prompted for when mailing a message.
193 RFC822 required that From, Date, To, Subject and Message-ID be
194 included. Organization, Lines and User-Agent are optional."
196 :group 'message-headers
197 :type '(repeat sexp))
199 (defcustom message-deletable-headers '(Message-ID Date Lines)
200 "Headers to be deleted if they already exist and were generated by message previously."
201 :group 'message-headers
204 (defcustom message-ignored-news-headers
205 "^NNTP-Posting-Host:\\|^Xref:\\|^[BGF]cc:\\|^Resent-Fcc:\\|^X-Draft-From:"
206 "*Regexp of headers to be removed unconditionally before posting."
208 :group 'message-headers
211 (defcustom message-ignored-mail-headers
212 "^[GF]cc:\\|^Resent-Fcc:\\|^Xref:\\|^X-Draft-From:"
213 "*Regexp of headers to be removed unconditionally before mailing."
215 :group 'message-headers
218 (defcustom message-ignored-supersedes-headers "^Path:\\|^Date\\|^NNTP-Posting-Host:\\|^Xref:\\|^Lines:\\|^Received:\\|^X-From-Line:\\|^X-Trace:\\|^X-Complaints-To:\\|Return-Path:\\|^Supersedes:\\|^NNTP-Posting-Date:\\|^X-Trace:\\|^X-Complaints-To:"
219 "*Header lines matching this regexp will be deleted before posting.
220 It's best to delete old Path and Date headers before posting to avoid
222 :group 'message-interface
225 (defcustom message-subject-re-regexp "^[ \t]*\\([Rr][Ee]:[ \t]*\\)*[ \t]*"
226 "*Regexp matching \"Re: \" in the subject line."
227 :group 'message-various
231 (defcustom message-signature-separator "^-- *$"
232 "Regexp matching the signature separator."
234 :group 'message-various)
236 (defcustom message-elide-ellipsis "\n[...]\n\n"
237 "*The string which is inserted for elided text."
239 :group 'message-various)
241 (defcustom message-interactive nil
242 "Non-nil means when sending a message wait for and display errors.
243 nil means let mailer mail back a message to report errors."
244 :group 'message-sending
248 (defcustom message-generate-new-buffers 'unique
249 "*Non-nil means create a new message buffer whenever `message-setup' is called.
250 If this is a function, call that function with three parameters: The type,
251 the to address and the group name. (Any of these may be nil.) The function
252 should return the new buffer name."
253 :group 'message-buffers
254 :type '(choice (const :tag "off" nil)
255 (const :tag "unique" unique)
256 (const :tag "unsent" unsent)
259 (defcustom message-kill-buffer-on-exit nil
260 "*Non-nil means that the message buffer will be killed after sending a message."
261 :group 'message-buffers
265 (defvar gnus-local-organization))
266 (defcustom message-user-organization
267 (or (and (boundp 'gnus-local-organization)
268 (stringp gnus-local-organization)
269 gnus-local-organization)
270 (getenv "ORGANIZATION")
272 "*String to be used as an Organization header.
273 If t, use `message-user-organization-file'."
274 :group 'message-headers
275 :type '(choice string
276 (const :tag "consult file" t)))
279 (defcustom message-user-organization-file "/usr/lib/news/organization"
280 "*Local news organization file."
282 :group 'message-headers)
284 (defcustom message-make-forward-subject-function
285 'message-forward-subject-author-subject
286 "*List of functions called to generate subject headers for forwarded messages.
287 The subject generated by the previous function is passed into each
290 The provided functions are:
292 * `message-forward-subject-author-subject' (Source of article (author or
293 newsgroup)), in brackets followed by the subject
294 * `message-forward-subject-fwd' (Subject of article with 'Fwd:' prepended
296 :group 'message-forwarding
297 :type '(radio (function-item message-forward-subject-author-subject)
298 (function-item message-forward-subject-fwd)
299 (repeat :tag "List of functions" function)))
301 (defcustom message-forward-as-mime t
302 "*If non-nil, forward messages as an inline/rfc822 MIME section. Otherwise, directly inline the old message in the forwarded message."
304 :group 'message-forwarding
307 (defcustom message-forward-show-mml t
308 "*If non-nil, forward messages are shown as mml. Otherwise, forward messages are unchanged."
310 :group 'message-forwarding
313 (defcustom message-forward-before-signature t
314 "*If non-nil, put forwarded message before signature, else after."
315 :group 'message-forwarding
318 (defcustom message-wash-forwarded-subjects nil
319 "*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."
320 :group 'message-forwarding
323 (defcustom message-ignored-resent-headers "^Return-receipt\\|^X-Gnus\\|^Gnus-Warning:"
324 "*All headers that match this regexp will be deleted when resending a message."
325 :group 'message-interface
328 (defcustom message-forward-ignored-headers "^Content-Transfer-Encoding:\\|^X-Gnus"
329 "*All headers that match this regexp will be deleted when forwarding a message."
331 :group 'message-forwarding
332 :type '(choice (const :tag "None" nil)
335 (defcustom message-ignored-cited-headers "."
336 "*Delete these headers from the messages you yank."
337 :group 'message-insertion
340 (defcustom message-cite-prefix-regexp
341 (if (string-match "[[:digit:]]" "1") ;; support POSIX?
342 "\\([ \t]*[-_.[:word:]]+>+\\|[ \t]*[]>»|:}+]\\)+"
343 ;; ?-, ?_ or ?. MUST NOT be in syntax entry w.
344 "\\([ \t]*\\(\\w\\|[-_.]\\)+>+\\|[ \t]*[]>»|:}+]\\)+")
345 "*Regexp matching the longest possible citation prefix on a line."
346 :group 'message-insertion
349 (defcustom message-cancel-message "I am canceling my own article.\n"
350 "Message to be inserted in the cancel message."
351 :group 'message-interface
354 ;; Useful to set in site-init.el
356 (defcustom message-send-mail-function 'message-send-mail-with-sendmail
357 "Function to call to send the current buffer as mail.
358 The headers should be delimited by a line whose contents match the
359 variable `mail-header-separator'.
361 Valid values include `message-send-mail-with-sendmail' (the default),
362 `message-send-mail-with-mh', `message-send-mail-with-qmail',
363 `smtpmail-send-it' and `feedmail-send-it'.
365 See also `send-mail-function'."
366 :type '(radio (function-item message-send-mail-with-sendmail)
367 (function-item message-send-mail-with-mh)
368 (function-item message-send-mail-with-qmail)
369 (function-item smtpmail-send-it)
370 (function-item feedmail-send-it)
371 (function :tag "Other"))
372 :group 'message-sending
373 :group 'message-mail)
375 (defcustom message-send-news-function 'message-send-news
376 "Function to call to send the current buffer as news.
377 The headers should be delimited by a line whose contents match the
378 variable `mail-header-separator'."
379 :group 'message-sending
383 (defcustom message-reply-to-function nil
384 "If non-nil, function that should return a list of headers.
385 This function should pick out addresses from the To, Cc, and From headers
386 and respond with new To and Cc headers."
387 :group 'message-interface
388 :type '(choice function (const nil)))
390 (defcustom message-wide-reply-to-function nil
391 "If non-nil, function that should return a list of headers.
392 This function should pick out addresses from the To, Cc, and From headers
393 and respond with new To and Cc headers."
394 :group 'message-interface
395 :type '(choice function (const nil)))
397 (defcustom message-followup-to-function nil
398 "If non-nil, function that should return a list of headers.
399 This function should pick out addresses from the To, Cc, and From headers
400 and respond with new To and Cc headers."
401 :group 'message-interface
402 :type '(choice function (const nil)))
404 (defcustom message-use-followup-to t
405 "*Specifies what to do with Followup-To header.
406 If nil, always ignore the header. If it is t, use its value, but
407 query before using the \"poster\" value. If it is the symbol `ask',
408 always query the user whether to use the value. If it is the symbol
409 `use', always use the value."
410 :group 'message-interface
411 :type '(choice (const :tag "ignore" nil)
412 (const :tag "use & query" t)
416 (defcustom message-sendmail-f-is-evil nil
417 "*Non-nil means don't add \"-f username\" to the sendmail command line.
418 Doing so would be even more evil than leaving it out."
419 :group 'message-sending
422 ;; qmail-related stuff
423 (defcustom message-qmail-inject-program "/var/qmail/bin/qmail-inject"
424 "Location of the qmail-inject program."
425 :group 'message-sending
428 (defcustom message-qmail-inject-args nil
429 "Arguments passed to qmail-inject programs.
430 This should be a list of strings, one string for each argument.
432 For e.g., if you wish to set the envelope sender address so that bounces
433 go to the right place or to deal with listserv's usage of that address, you
434 might set this variable to '(\"-f\" \"you@some.where\")."
435 :group 'message-sending
436 :type '(repeat string))
438 (defvar message-cater-to-broken-inn t
439 "Non-nil means Gnus should not fold the `References' header.
440 Folding `References' makes ancient versions of INN create incorrect
444 (defvar gnus-post-method)
445 (defvar gnus-select-method))
446 (defcustom message-post-method
447 (cond ((and (boundp 'gnus-post-method)
448 (listp gnus-post-method)
451 ((boundp 'gnus-select-method)
454 "*Method used to post news.
455 Note that when posting from inside Gnus, for instance, this
456 variable isn't used."
458 :group 'message-sending
459 ;; This should be the `gnus-select-method' widget, but that might
460 ;; create a dependence to `gnus.el'.
463 (defcustom message-generate-headers-first nil
464 "*If non-nil, generate all required headers before composing.
465 The variables `message-required-news-headers' and
466 `message-required-mail-headers' specify which headers to generate.
468 Note that the variable `message-deletable-headers' specifies headers which
469 are to be deleted and then re-generated before sending, so this variable
470 will not have a visible effect for those headers."
471 :group 'message-headers
474 (defcustom message-setup-hook nil
475 "Normal hook, run each time a new outgoing message is initialized.
476 The function `message-setup' runs this hook."
477 :group 'message-various
480 (defcustom message-cancel-hook nil
481 "Hook run when cancelling articles."
482 :group 'message-various
485 (defcustom message-signature-setup-hook nil
486 "Normal hook, run each time a new outgoing message is initialized.
487 It is run after the headers have been inserted and before
488 the signature is inserted."
489 :group 'message-various
492 (defcustom message-mode-hook nil
493 "Hook run in message mode buffers."
494 :group 'message-various
497 (defcustom message-header-hook nil
498 "Hook run in a message mode buffer narrowed to the headers."
499 :group 'message-various
502 (defcustom message-header-setup-hook nil
503 "Hook called narrowed to the headers when setting up a message buffer."
504 :group 'message-various
507 (defcustom message-minibuffer-local-map
508 (let ((map (make-sparse-keymap 'message-minibuffer-local-map)))
509 (set-keymap-parent map minibuffer-local-map)
511 "Keymap for `message-read-from-minibuffer'.")
514 (defcustom message-citation-line-function 'message-insert-citation-line
515 "*Function called to insert the \"Whomever writes:\" line."
517 :group 'message-insertion)
520 (defcustom message-yank-prefix "> "
521 "*Prefix inserted on the lines of yanked messages.
522 Fix `message-cite-prefix-regexp' if it is set to an abnormal value."
524 :group 'message-insertion)
526 (defcustom message-yank-cited-prefix ">"
527 "*Prefix inserted on cited lines of yanked messages.
528 Fix `message-cite-prefix-regexp' if it is set to an abnormal value."
530 :group 'message-insertion)
532 (defcustom message-indentation-spaces 3
533 "*Number of spaces to insert at the beginning of each cited line.
534 Used by `message-yank-original' via `message-yank-cite'."
535 :group 'message-insertion
539 (defcustom message-cite-function 'message-cite-original
540 "*Function for citing an original message.
541 Predefined functions include `message-cite-original' and
542 `message-cite-original-without-signature'.
543 Note that `message-cite-original' uses `mail-citation-hook' if that is non-nil."
544 :type '(radio (function-item message-cite-original)
545 (function-item message-cite-original-without-signature)
546 (function-item sc-cite-original)
547 (function :tag "Other"))
548 :group 'message-insertion)
551 (defcustom message-indent-citation-function 'message-indent-citation
552 "*Function for modifying a citation just inserted in the mail buffer.
553 This can also be a list of functions. Each function can find the
554 citation between (point) and (mark t). And each function should leave
555 point and mark around the citation text as modified."
557 :group 'message-insertion)
559 (defvar message-abbrevs-loaded nil)
562 (defcustom message-signature t
563 "*String to be inserted at the end of the message buffer.
564 If t, the `message-signature-file' file will be inserted instead.
565 If a function, the result from the function will be used instead.
566 If a form, the result from the form will be used instead."
568 :group 'message-insertion)
571 (defcustom message-signature-file "~/.signature"
572 "*Name of file containing the text inserted at end of message buffer.
573 Ignored if the named file doesn't exist.
574 If nil, don't insert a signature."
575 :type '(choice file (const :tags "None" nil))
576 :group 'message-insertion)
578 (defcustom message-distribution-function nil
579 "*Function called to return a Distribution header."
581 :group 'message-headers
582 :type '(choice function (const nil)))
584 (defcustom message-expires 14
585 "Number of days before your article expires."
587 :group 'message-headers
588 :link '(custom-manual "(message)News Headers")
591 (defcustom message-user-path nil
592 "If nil, use the NNTP server name in the Path header.
593 If stringp, use this; if non-nil, use no host name (user name only)."
595 :group 'message-headers
596 :link '(custom-manual "(message)News Headers")
597 :type '(choice (const :tag "nntp" nil)
599 (sexp :tag "none" :format "%t" t)))
601 (defvar message-reply-buffer nil)
602 (defvar message-reply-headers nil)
603 (defvar message-newsreader nil)
604 (defvar message-mailer nil)
605 (defvar message-sent-message-via nil)
606 (defvar message-checksum nil)
607 (defvar message-send-actions nil
608 "A list of actions to be performed upon successful sending of a message.")
609 (defvar message-exit-actions nil
610 "A list of actions to be performed upon exiting after sending a message.")
611 (defvar message-kill-actions nil
612 "A list of actions to be performed before killing a message buffer.")
613 (defvar message-postpone-actions nil
614 "A list of actions to be performed after postponing a message.")
616 (define-widget 'message-header-lines 'text
617 "All header lines must be LFD terminated."
618 :format "%{%t%}:%n%v"
620 :error "All header lines must be newline terminated")
622 (defcustom message-default-headers ""
623 "*A string containing header lines to be inserted in outgoing messages.
624 It is inserted before you edit the message, so you can edit or delete
626 :group 'message-headers
627 :type 'message-header-lines)
629 (defcustom message-default-mail-headers ""
630 "*A string of header lines to be inserted in outgoing mails."
631 :group 'message-headers
633 :type 'message-header-lines)
635 (defcustom message-default-news-headers ""
636 "*A string of header lines to be inserted in outgoing news articles."
637 :group 'message-headers
639 :type 'message-header-lines)
641 ;; Note: could use /usr/ucb/mail instead of sendmail;
642 ;; options -t, and -v if not interactive.
643 (defcustom message-mailer-swallows-blank-line
644 (if (and (string-match "sparc-sun-sunos\\(\\'\\|[^5]\\)"
645 system-configuration)
646 (file-readable-p "/etc/sendmail.cf")
647 (let ((buffer (get-buffer-create " *temp*")))
651 (insert-file-contents "/etc/sendmail.cf")
652 (goto-char (point-min))
653 (let ((case-fold-search nil))
654 (re-search-forward "^OR\\>" nil t)))
655 (kill-buffer buffer))))
656 ;; According to RFC822, "The field-name must be composed of printable
657 ;; ASCII characters (i. e., characters that have decimal values between
658 ;; 33 and 126, except colon)", i. e., any chars except ctl chars,
660 '(looking-at "[ \t]\\|[][!\"#$%&'()*+,-./0-9;<=>?@A-Z\\\\^_`a-z{|}~]+:"))
661 "*Set this non-nil if the system's mailer runs the header and body together.
662 \(This problem exists on Sunos 4 when sendmail is run in remote mode.)
663 The value should be an expression to test whether the problem will
665 :group 'message-sending
669 (define-mail-user-agent 'message-user-agent
670 'message-mail 'message-send-and-exit
671 'message-kill-buffer 'message-send-hook)
673 (defvar message-mh-deletable-headers '(Message-ID Date Lines Sender)
674 "If non-nil, delete the deletable headers before feeding to mh.")
676 (defvar message-send-method-alist
677 '((news message-news-p message-send-via-news)
678 (mail message-mail-p message-send-via-mail))
679 "Alist of ways to send outgoing messages.
680 Each element has the form
682 \(TYPE PREDICATE FUNCTION)
684 where TYPE is a symbol that names the method; PREDICATE is a function
685 called without any parameters to determine whether the message is
686 a message of type TYPE; and FUNCTION is a function to be called if
687 PREDICATE returns non-nil. FUNCTION is called with one parameter --
690 (defcustom message-mail-alias-type 'abbrev
691 "*What alias expansion type to use in Message buffers.
692 The default is `abbrev', which uses mailabbrev. nil switches
695 :link '(custom-manual "(message)Mail Aliases")
696 :type '(choice (const :tag "Use Mailabbrev" abbrev)
697 (const :tag "No expansion" nil)))
699 (defcustom message-auto-save-directory
700 (file-name-as-directory (nnheader-concat message-directory "drafts"))
701 "*Directory where Message auto-saves buffers if Gnus isn't running.
702 If nil, Message won't auto-save."
703 :group 'message-buffers
704 :type '(choice directory (const :tag "Don't auto-save" nil)))
706 (defcustom message-buffer-naming-style 'unique
707 "*The way new message buffers are named.
708 Valid valued are `unique' and `unsent'."
710 :group 'message-buffers
711 :type '(choice (const :tag "unique" unique)
712 (const :tag "unsent" unsent)))
714 (defcustom message-default-charset
715 (and (not (mm-multibyte-p)) 'iso-8859-1)
716 "Default charset used in non-MULE Emacsen.
717 If nil, you might be asked to input the charset."
722 (defcustom message-dont-reply-to-names
723 (and (boundp 'rmail-dont-reply-to-names) rmail-dont-reply-to-names)
724 "*A regexp specifying addresses to prune when doing wide replies.
725 A value of nil means exclude your own user name only."
728 :type '(choice (const :tag "Yourself" nil)
731 (defvar message-shoot-gnksa-feet nil
732 "*A list of GNKSA feet you are allowed to shoot.
733 Gnus gives you all the opportunity you could possibly want for
734 shooting yourself in the foot. Also, Gnus allows you to shoot the
735 feet of Good Net-Keeping Seal of Approval. The following are foot
737 `empty-article' Allow you to post an empty article;
738 `quoted-text-only' Allow you to post quoted text only;
739 `multiple-copies' Allow you to post multiple copies.")
740 ;; `cancel-messages' Allow you to cancel or supersede others' messages.
742 (defsubst message-gnksa-enable-p (feature)
743 (or (not (listp message-shoot-gnksa-feet))
744 (memq feature message-shoot-gnksa-feet)))
746 ;;; Internal variables.
747 ;;; Well, not really internal.
749 (defvar message-mode-syntax-table
750 (let ((table (copy-syntax-table text-mode-syntax-table)))
751 (modify-syntax-entry ?% ". " table)
752 (modify-syntax-entry ?> ". " table)
753 (modify-syntax-entry ?< ". " table)
755 "Syntax table used while in Message mode.")
757 (defvar message-mode-abbrev-table text-mode-abbrev-table
758 "Abbrev table used in Message mode buffers.
759 Defaults to `text-mode-abbrev-table'.")
761 (defface message-header-to-face
764 (:foreground "green2" :bold t))
767 (:foreground "MidnightBlue" :bold t))
769 (:bold t :italic t)))
770 "Face used for displaying From headers."
771 :group 'message-faces)
773 (defface message-header-cc-face
776 (:foreground "green4" :bold t))
779 (:foreground "MidnightBlue"))
782 "Face used for displaying Cc headers."
783 :group 'message-faces)
785 (defface message-header-subject-face
788 (:foreground "green3"))
791 (:foreground "navy blue" :bold t))
794 "Face used for displaying subject headers."
795 :group 'message-faces)
797 (defface message-header-newsgroups-face
800 (:foreground "yellow" :bold t :italic t))
803 (:foreground "blue4" :bold t :italic t))
805 (:bold t :italic t)))
806 "Face used for displaying newsgroups headers."
807 :group 'message-faces)
809 (defface message-header-other-face
812 (:foreground "#b00000"))
815 (:foreground "steel blue"))
817 (:bold t :italic t)))
818 "Face used for displaying newsgroups headers."
819 :group 'message-faces)
821 (defface message-header-name-face
824 (:foreground "DarkGreen"))
827 (:foreground "cornflower blue"))
830 "Face used for displaying header names."
831 :group 'message-faces)
833 (defface message-header-xheader-face
836 (:foreground "blue"))
839 (:foreground "blue"))
842 "Face used for displaying X-Header headers."
843 :group 'message-faces)
845 (defface message-separator-face
848 (:foreground "blue3"))
851 (:foreground "brown"))
854 "Face used for displaying the separator."
855 :group 'message-faces)
857 (defface message-cited-text-face
866 "Face used for displaying cited text names."
867 :group 'message-faces)
869 (defface message-mml-face
872 (:foreground "ForestGreen"))
875 (:foreground "ForestGreen"))
878 "Face used for displaying MML."
879 :group 'message-faces)
881 (defvar message-font-lock-keywords
882 (let ((content "[ \t]*\\(.+\\(\n[ \t].*\\)*\\)\n?"))
883 `((,(concat "^\\([Tt]o:\\)" content)
884 (1 'message-header-name-face)
885 (2 'message-header-to-face nil t))
886 (,(concat "^\\(^[GBF]?[Cc][Cc]:\\|^[Rr]eply-[Tt]o:\\)" content)
887 (1 'message-header-name-face)
888 (2 'message-header-cc-face nil t))
889 (,(concat "^\\([Ss]ubject:\\)" content)
890 (1 'message-header-name-face)
891 (2 'message-header-subject-face nil t))
892 (,(concat "^\\([Nn]ewsgroups:\\|Followup-[Tt]o:\\)" content)
893 (1 'message-header-name-face)
894 (2 'message-header-newsgroups-face nil t))
895 (,(concat "^\\([A-Z][^: \n\t]+:\\)" content)
896 (1 'message-header-name-face)
897 (2 'message-header-other-face nil t))
898 (,(concat "^\\(X-[A-Za-z0-9-]+\\|In-Reply-To\\):" content)
899 (1 'message-header-name-face)
900 (2 'message-header-name-face))
901 ,@(if (and mail-header-separator
902 (not (equal mail-header-separator "")))
903 `((,(concat "^\\(" (regexp-quote mail-header-separator) "\\)$")
904 1 'message-separator-face))
906 (,(concat "^\\(" message-cite-prefix-regexp "\\).*")
907 (0 'message-cited-text-face))
908 ("<#/?\\(multipart\\|part\\|external\\|mml\\).*>"
909 (0 'message-mml-face))))
910 "Additional expressions to highlight in Message mode.")
912 ;; XEmacs does it like this. For Emacs, we have to set the
913 ;; `font-lock-defaults' buffer-local variable.
914 (put 'message-mode 'font-lock-defaults '(message-font-lock-keywords t))
916 (defvar message-face-alist
917 '((bold . bold-region)
918 (underline . underline-region)
919 (default . (lambda (b e)
921 (ununderline-region b e))))
922 "Alist of mail and news faces for facemenu.
923 The cdr of ech entry is a function for applying the face to a region.")
925 (defcustom message-send-hook nil
926 "Hook run before sending messages."
927 :group 'message-various
928 :options '(ispell-message)
931 (defcustom message-send-mail-hook nil
932 "Hook run before sending mail messages."
933 :group 'message-various
936 (defcustom message-send-news-hook nil
937 "Hook run before sending news messages."
938 :group 'message-various
941 (defcustom message-sent-hook nil
942 "Hook run after sending messages."
943 :group 'message-various
946 (defvar message-send-coding-system 'binary
947 "Coding system to encode outgoing mail.")
949 (defvar message-draft-coding-system
950 mm-auto-save-coding-system
951 "Coding system to compose mail.")
953 (defcustom message-send-mail-partially-limit 1000000
954 "The limitation of messages sent as message/partial.
955 The lower bound of message size in characters, beyond which the message
956 should be sent in several parts. If it is nil, the size is unlimited."
958 :group 'message-buffers
959 :type '(choice (const :tag "unlimited" nil)
962 (defcustom message-alternative-emails nil
963 "A regexp to match the alternative email addresses.
964 The first matched address (not primary one) is used in the From field."
965 :group 'message-headers
966 :type '(choice (const :tag "Always use primary" nil)
969 (defcustom message-mail-user-agent nil
970 "Like `mail-user-agent'.
971 Except if it is nil, use Gnus native MUA; if it is t, use
973 :type '(radio (const :tag "Gnus native"
976 (const :tag "`mail-user-agent'"
979 (function-item :tag "Default Emacs mail"
982 (function-item :tag "Emacs interface to MH"
985 (function :tag "Other"))
989 (defcustom message-wide-reply-confirm-recipients nil
990 "Whether to confirm a wide reply to multiple email recipients.
991 If this variable is nil, don't ask whether to reply to all recipients.
992 If this variable is non-nil, pose the question \"Reply to all
993 recipients?\" before a wide reply to multiple recipients. If the user
994 answers yes, reply to all recipients as usual. If the user answers
995 no, only reply back to the author."
996 :group 'message-headers
999 ;;; Internal variables.
1001 (defvar message-sending-message "Sending...")
1002 (defvar message-buffer-list nil)
1003 (defvar message-this-is-news nil)
1004 (defvar message-this-is-mail nil)
1005 (defvar message-draft-article nil)
1006 (defvar message-mime-part nil)
1007 (defvar message-posting-charset nil)
1009 ;; Byte-compiler warning
1011 (defvar gnus-active-hashtb)
1012 (defvar gnus-read-active-file))
1014 ;;; Regexp matching the delimiter of messages in UNIX mail format
1015 ;;; (UNIX From lines), minus the initial ^. It should be a copy
1016 ;;; of rmail.el's rmail-unix-mail-delimiter.
1017 (defvar message-unix-mail-delimiter
1018 (let ((time-zone-regexp
1019 (concat "\\([A-Z]?[A-Z]?[A-Z][A-Z]\\( DST\\)?"
1020 "\\|[-+]?[0-9][0-9][0-9][0-9]"
1026 ;; Many things can happen to an RFC 822 mailbox before it is put into
1027 ;; a `From' line. The leading phrase can be stripped, e.g.
1028 ;; `Joe <@w.x:joe@y.z>' -> `<@w.x:joe@y.z>'. The <> can be stripped, e.g.
1029 ;; `<@x.y:joe@y.z>' -> `@x.y:joe@y.z'. Everything starting with a CRLF
1030 ;; can be removed, e.g.
1031 ;; From: joe@y.z (Joe K
1033 ;; can yield `From joe@y.z (Joe K Fri Mar 22 08:11:15 1996', and
1036 ;; can yield `From Joe User Fri Mar 22 08:11:15 1996'.
1037 ;; The mailbox can be removed or be replaced by white space, e.g.
1038 ;; From: "Joe User"{space}{tab}
1040 ;; can yield `From {space}{tab} Fri Mar 22 08:11:15 1996',
1041 ;; where {space} and {tab} represent the Ascii space and tab characters.
1042 ;; We want to match the results of any of these manglings.
1043 ;; The following regexp rejects names whose first characters are
1044 ;; obviously bogus, but after that anything goes.
1045 "\\([^\0-\b\n-\r\^?].*\\)? "
1047 ;; The time the message was sent.
1048 "\\([^\0-\r \^?]+\\) +" ; day of the week
1049 "\\([^\0-\r \^?]+\\) +" ; month
1050 "\\([0-3]?[0-9]\\) +" ; day of month
1051 "\\([0-2][0-9]:[0-5][0-9]\\(:[0-6][0-9]\\)?\\) *" ; time of day
1053 ;; Perhaps a time zone, specified by an abbreviation, or by a
1058 " \\([0-9][0-9]+\\) *"
1060 ;; On some systems the time zone can appear after the year, too.
1064 "\\(remote from .*\\)?"
1067 "Regexp matching the delimiter of messages in UNIX mail format.")
1069 (defvar message-unsent-separator
1070 (concat "^ *---+ +Unsent message follows +---+ *$\\|"
1071 "^ *---+ +Returned message +---+ *$\\|"
1072 "^Start of returned message$\\|"
1073 "^ *---+ +Original message +---+ *$\\|"
1074 "^ *--+ +begin message +--+ *$\\|"
1075 "^ *---+ +Original message follows +---+ *$\\|"
1076 "^ *---+ +Undelivered message follows +---+ *$\\|"
1077 "^|? *---+ +Message text follows: +---+ *|?$")
1078 "A regexp that matches the separator before the text of a failed message.")
1080 (defvar message-header-format-alist
1082 (To . message-fill-address)
1083 (Cc . message-fill-address)
1094 (References . message-shorten-references)
1096 "Alist used for formatting headers.")
1098 (defvar message-options nil
1099 "Some saved answers when sending message.")
1102 (autoload 'message-setup-toolbar "messagexmas")
1103 (autoload 'mh-new-draft-name "mh-comp")
1104 (autoload 'mh-send-letter "mh-comp")
1105 (autoload 'gnus-point-at-eol "gnus-util")
1106 (autoload 'gnus-point-at-bol "gnus-util")
1107 (autoload 'gnus-output-to-rmail "gnus-util")
1108 (autoload 'gnus-output-to-mail "gnus-util")
1109 (autoload 'mail-abbrev-in-expansion-header-p "mailabbrev")
1110 (autoload 'nndraft-request-associate-buffer "nndraft")
1111 (autoload 'nndraft-request-expire-articles "nndraft")
1112 (autoload 'gnus-open-server "gnus-int")
1113 (autoload 'gnus-request-post "gnus-int")
1114 (autoload 'gnus-alive-p "gnus-util")
1115 (autoload 'gnus-server-string "gnus")
1116 (autoload 'gnus-group-name-charset "gnus-group")
1117 (autoload 'rmail-output "rmailout"))
1122 ;;; Utility functions.
1125 (defmacro message-y-or-n-p (question show &rest text)
1126 "Ask QUESTION, displaying remaining args in a temporary buffer if SHOW."
1127 `(message-talkative-question 'y-or-n-p ,question ,show ,@text))
1129 (defmacro message-delete-line (&optional n)
1130 "Delete the current line (and the next N lines)."
1131 `(delete-region (progn (beginning-of-line) (point))
1132 (progn (forward-line ,(or n 1)) (point))))
1134 (defun message-unquote-tokens (elems)
1135 "Remove double quotes (\") from strings in list ELEMS."
1136 (mapcar (lambda (item)
1137 (while (string-match "^\\(.*\\)\"\\(.*\\)$" item)
1138 (setq item (concat (match-string 1 item)
1139 (match-string 2 item))))
1143 (defun message-tokenize-header (header &optional separator)
1144 "Split HEADER into a list of header elements.
1145 SEPARATOR is a string of characters to be used as separators. \",\"
1146 is used by default."
1149 (let ((regexp (format "[%s]+" (or separator ",")))
1154 (message-set-work-buffer)
1156 (goto-char (point-min))
1161 (cond ((and (> (point) beg)
1163 (and (looking-at regexp)
1166 (push (buffer-substring beg (point)) elems)
1167 (setq beg (match-end 0)))
1168 ((eq (char-after) ?\")
1169 (setq quoted (not quoted)))
1170 ((and (eq (char-after) ?\()
1173 ((and (eq (char-after) ?\))
1176 (nreverse elems)))))
1178 (defun message-mail-file-mbox-p (file)
1179 "Say whether FILE looks like a Unix mbox file."
1180 (when (and (file-exists-p file)
1181 (file-readable-p file)
1182 (file-regular-p file))
1184 (nnheader-insert-file-contents file)
1185 (goto-char (point-min))
1186 (looking-at message-unix-mail-delimiter))))
1188 (defun message-fetch-field (header &optional not-all)
1189 "The same as `mail-fetch-field', only remove all newlines."
1190 (let* ((inhibit-point-motion-hooks t)
1191 (case-fold-search t)
1192 (value (mail-fetch-field header nil (not not-all))))
1194 (while (string-match "\n[\t ]+" value)
1195 (setq value (replace-match " " t t value)))
1196 (set-text-properties 0 (length value) nil value)
1199 (defun message-narrow-to-field ()
1200 "Narrow the buffer to the header on the current line."
1206 (if (re-search-forward "^[^ \n\t]" nil t)
1211 (goto-char (point-min)))
1213 (defun message-add-header (&rest headers)
1214 "Add the HEADERS to the message header, skipping those already present."
1217 (unless (string-match "^\\([^:]+\\):[ \t]*[^ \t]" (car headers))
1218 (error "Invalid header `%s'" (car headers)))
1219 (setq hclean (match-string 1 (car headers)))
1221 (message-narrow-to-headers)
1222 (unless (re-search-forward (concat "^" (regexp-quote hclean) ":") nil t)
1223 (goto-char (point-max))
1224 (if (string-match "\n$" (car headers))
1225 (insert (car headers))
1226 (insert (car headers) ?\n)))))
1227 (setq headers (cdr headers))))
1230 (defun message-fetch-reply-field (header)
1231 "Fetch field HEADER from the message we're replying to."
1232 (when (and message-reply-buffer
1233 (buffer-name message-reply-buffer))
1235 (set-buffer message-reply-buffer)
1236 (message-fetch-field header))))
1238 (defun message-set-work-buffer ()
1239 (if (get-buffer " *message work*")
1241 (set-buffer " *message work*")
1243 (set-buffer (get-buffer-create " *message work*"))
1244 (kill-all-local-variables)
1245 (mm-enable-multibyte)))
1247 (defun message-functionp (form)
1248 "Return non-nil if FORM is funcallable."
1249 (or (and (symbolp form) (fboundp form))
1250 (and (listp form) (eq (car form) 'lambda))
1251 (byte-code-function-p form)))
1253 (defun message-strip-list-identifiers (subject)
1254 "Remove list identifiers in `gnus-list-identifiers' from string SUBJECT."
1255 (require 'gnus-sum) ; for gnus-list-identifiers
1256 (let ((regexp (if (stringp gnus-list-identifiers)
1257 gnus-list-identifiers
1258 (mapconcat 'identity gnus-list-identifiers " *\\|"))))
1259 (if (string-match (concat "\\(\\(\\(Re: +\\)?\\(" regexp
1260 " *\\)\\)+\\(Re: +\\)?\\)") subject)
1261 (concat (substring subject 0 (match-beginning 1))
1262 (or (match-string 3 subject)
1263 (match-string 5 subject))
1268 (defun message-strip-subject-re (subject)
1269 "Remove \"Re:\" from subject lines in string SUBJECT."
1270 (if (string-match message-subject-re-regexp subject)
1271 (substring subject (match-end 0))
1274 (defun message-remove-header (header &optional is-regexp first reverse)
1275 "Remove HEADER in the narrowed buffer.
1276 If IS-REGEXP, HEADER is a regular expression.
1277 If FIRST, only remove the first instance of the header.
1278 Return the number of headers removed."
1279 (goto-char (point-min))
1280 (let ((regexp (if is-regexp header (concat "^" (regexp-quote header) ":")))
1282 (case-fold-search t)
1284 (while (and (not (eobp))
1287 (not (looking-at regexp))
1288 (looking-at regexp))
1295 ;; There might be a continuation header, so we have to search
1296 ;; until we find a new non-continuation line.
1299 (if (re-search-forward "^[^ \t]" nil t)
1300 (goto-char (match-beginning 0))
1303 (if (re-search-forward "^[^ \t]" nil t)
1304 (goto-char (match-beginning 0))
1305 (goto-char (point-max)))))
1308 (defun message-remove-first-header (header)
1309 "Remove the first instance of HEADER if there is more than one."
1311 (regexp (concat "^" (regexp-quote header) ":")))
1313 (goto-char (point-min))
1314 (while (re-search-forward regexp nil t)
1317 (message-remove-header header nil t)
1320 (defun message-narrow-to-headers ()
1321 "Narrow the buffer to the head of the message."
1324 (goto-char (point-min))
1325 (if (re-search-forward
1326 (concat "^" (regexp-quote mail-header-separator) "\n") nil t)
1329 (goto-char (point-min)))
1331 (defun message-narrow-to-head-1 ()
1332 "Like `message-narrow-to-head'. Don't widen."
1334 (goto-char (point-min))
1335 (if (search-forward "\n\n" nil 1)
1338 (goto-char (point-min)))
1340 (defun message-narrow-to-head ()
1341 "Narrow the buffer to the head of the message.
1342 Point is left at the beginning of the narrowed-to region."
1344 (message-narrow-to-head-1))
1346 (defun message-narrow-to-headers-or-head ()
1347 "Narrow the buffer to the head of the message."
1350 (goto-char (point-min))
1353 (concat "^" (regexp-quote mail-header-separator) "\n") nil t)
1354 (match-beginning 0))
1355 ((search-forward "\n\n" nil t)
1359 (goto-char (point-min)))
1361 (defun message-news-p ()
1362 "Say whether the current buffer contains a news message."
1363 (and (not message-this-is-mail)
1364 (or message-this-is-news
1367 (message-narrow-to-headers)
1368 (and (message-fetch-field "newsgroups")
1369 (not (message-fetch-field "posted-to"))))))))
1371 (defun message-mail-p ()
1372 "Say whether the current buffer contains a mail message."
1373 (and (not message-this-is-news)
1374 (or message-this-is-mail
1377 (message-narrow-to-headers)
1378 (or (message-fetch-field "to")
1379 (message-fetch-field "cc")
1380 (message-fetch-field "bcc")))))))
1382 (defun message-next-header ()
1383 "Go to the beginning of the next header."
1385 (or (eobp) (forward-char 1))
1386 (not (if (re-search-forward "^[^ \t]" nil t)
1388 (goto-char (point-max)))))
1390 (defun message-sort-headers-1 ()
1391 "Sort the buffer as headers using `message-rank' text props."
1392 (goto-char (point-min))
1395 nil 'message-next-header
1397 (message-next-header)
1401 (or (get-text-property (point) 'message-rank)
1404 (defun message-sort-headers ()
1405 "Sort the headers of the current message according to `message-header-format-alist'."
1409 (let ((max (1+ (length message-header-format-alist)))
1411 (message-narrow-to-headers)
1412 (while (re-search-forward "^[^ \n]+:" nil t)
1414 (match-beginning 0) (1+ (match-beginning 0))
1416 (if (setq rank (length (memq (assq (intern (buffer-substring
1418 (1- (match-end 0))))
1419 message-header-format-alist)
1420 message-header-format-alist)))
1423 (message-sort-headers-1))))
1433 (defvar message-mode-map nil)
1435 (unless message-mode-map
1436 (setq message-mode-map (make-keymap))
1437 (set-keymap-parent message-mode-map text-mode-map)
1438 (define-key message-mode-map "\C-c?" 'describe-mode)
1440 (define-key message-mode-map "\C-c\C-f\C-t" 'message-goto-to)
1441 (define-key message-mode-map "\C-c\C-f\C-b" 'message-goto-bcc)
1442 (define-key message-mode-map "\C-c\C-f\C-w" 'message-goto-fcc)
1443 (define-key message-mode-map "\C-c\C-f\C-c" 'message-goto-cc)
1444 (define-key message-mode-map "\C-c\C-f\C-s" 'message-goto-subject)
1445 (define-key message-mode-map "\C-c\C-f\C-r" 'message-goto-reply-to)
1446 (define-key message-mode-map "\C-c\C-f\C-n" 'message-goto-newsgroups)
1447 (define-key message-mode-map "\C-c\C-f\C-d" 'message-goto-distribution)
1448 (define-key message-mode-map "\C-c\C-f\C-f" 'message-goto-followup-to)
1449 (define-key message-mode-map "\C-c\C-f\C-k" 'message-goto-keywords)
1450 (define-key message-mode-map "\C-c\C-f\C-u" 'message-goto-summary)
1451 (define-key message-mode-map "\C-c\C-b" 'message-goto-body)
1452 (define-key message-mode-map "\C-c\C-i" 'message-goto-signature)
1454 (define-key message-mode-map "\C-c\C-t" 'message-insert-to)
1455 (define-key message-mode-map "\C-c\C-n" 'message-insert-newsgroups)
1457 (define-key message-mode-map "\C-c\C-y" 'message-yank-original)
1458 (define-key message-mode-map "\C-c\M-\C-y" 'message-yank-buffer)
1459 (define-key message-mode-map "\C-c\C-q" 'message-fill-yanked-message)
1460 (define-key message-mode-map "\C-c\C-w" 'message-insert-signature)
1461 (define-key message-mode-map "\C-c\M-h" 'message-insert-headers)
1462 (define-key message-mode-map "\C-c\C-r" 'message-caesar-buffer-body)
1463 (define-key message-mode-map "\C-c\C-o" 'message-sort-headers)
1464 (define-key message-mode-map "\C-c\M-r" 'message-rename-buffer)
1466 (define-key message-mode-map "\C-c\C-c" 'message-send-and-exit)
1467 (define-key message-mode-map "\C-c\C-s" 'message-send)
1468 (define-key message-mode-map "\C-c\C-k" 'message-kill-buffer)
1469 (define-key message-mode-map "\C-c\C-d" 'message-dont-send)
1471 (define-key message-mode-map "\C-c\C-e" 'message-elide-region)
1472 (define-key message-mode-map "\C-c\C-v" 'message-delete-not-region)
1473 (define-key message-mode-map "\C-c\C-z" 'message-kill-to-signature)
1474 (define-key message-mode-map "\M-\r" 'message-newline-and-reformat)
1475 ;;(define-key message-mode-map "\M-q" 'message-fill-paragraph)
1477 (define-key message-mode-map "\C-c\C-a" 'mml-attach-file)
1479 (define-key message-mode-map "\t" 'message-tab)
1480 (define-key message-mode-map "\M-;" 'comment-region))
1483 message-mode-menu message-mode-map "Message Menu."
1485 ["Sort Headers" message-sort-headers t]
1486 ["Yank Original" message-yank-original t]
1487 ["Fill Yanked Message" message-fill-yanked-message t]
1488 ["Insert Signature" message-insert-signature t]
1489 ["Caesar (rot13) Message" message-caesar-buffer-body t]
1490 ["Caesar (rot13) Region" message-caesar-region (mark t)]
1491 ["Elide Region" message-elide-region (mark t)]
1492 ["Delete Outside Region" message-delete-not-region (mark t)]
1493 ["Kill To Signature" message-kill-to-signature t]
1494 ["Newline and Reformat" message-newline-and-reformat t]
1495 ["Rename buffer" message-rename-buffer t]
1496 ["Spellcheck" ispell-message
1497 ,@(if (featurep 'xemacs) '(t)
1498 '(:help "Spellcheck this message"))]
1499 ["Attach file as MIME" mml-attach-file
1500 ,@(if (featurep 'xemacs) '(t)
1501 '(:help "Attach a file at point"))]
1503 ["Send Message" message-send-and-exit
1504 ,@(if (featurep 'xemacs) '(t)
1505 '(:help "Send this message"))]
1506 ["Abort Message" message-dont-send
1507 ,@(if (featurep 'xemacs) '(t)
1508 '(:help "File this draft message and exit"))]
1509 ["Kill Message" message-kill-buffer
1510 ,@(if (featurep 'xemacs) '(t)
1511 '(:help "Delete this message without sending"))]))
1514 message-mode-field-menu message-mode-map ""
1516 ["Fetch To" message-insert-to t]
1517 ["Fetch Newsgroups" message-insert-newsgroups t]
1519 ["To" message-goto-to t]
1520 ["Subject" message-goto-subject t]
1521 ["Cc" message-goto-cc t]
1522 ["Reply-To" message-goto-reply-to t]
1523 ["Summary" message-goto-summary t]
1524 ["Keywords" message-goto-keywords t]
1525 ["Newsgroups" message-goto-newsgroups t]
1526 ["Followup-To" message-goto-followup-to t]
1527 ["Distribution" message-goto-distribution t]
1528 ["Body" message-goto-body t]
1529 ["Signature" message-goto-signature t]))
1531 (defvar message-tool-bar-map nil)
1534 (defvar facemenu-add-face-function)
1535 (defvar facemenu-remove-face-function))
1538 (defun message-mode ()
1539 "Major mode for editing mail and news to be sent.
1540 Like Text Mode but with these additional commands:\\<message-mode-map>
1541 C-c C-s `message-send' (send the message) C-c C-c `message-send-and-exit'
1542 C-c C-d Postpone sending the message C-c C-k Kill the message
1543 C-c C-f move to a header field (and create it if there isn't):
1544 C-c C-f C-t move to To C-c C-f C-s move to Subject
1545 C-c C-f C-c move to Cc C-c C-f C-b move to Bcc
1546 C-c C-f C-w move to Fcc C-c C-f C-r move to Reply-To
1547 C-c C-f C-u move to Summary C-c C-f C-n move to Newsgroups
1548 C-c C-f C-k move to Keywords C-c C-f C-d move to Distribution
1549 C-c C-f C-f move to Followup-To
1550 C-c C-t `message-insert-to' (add a To header to a news followup)
1551 C-c C-n `message-insert-newsgroups' (add a Newsgroup header to a news reply)
1552 C-c C-b `message-goto-body' (move to beginning of message text).
1553 C-c C-i `message-goto-signature' (move to the beginning of the signature).
1554 C-c C-w `message-insert-signature' (insert `message-signature-file' file).
1555 C-c C-y `message-yank-original' (insert current message, if any).
1556 C-c C-q `message-fill-yanked-message' (fill what was yanked).
1557 C-c C-e `message-elide-region' (elide the text between point and mark).
1558 C-c C-v `message-delete-not-region' (remove the text outside the region).
1559 C-c C-z `message-kill-to-signature' (kill the text up to the signature).
1560 C-c C-r `message-caesar-buffer-body' (rot13 the message body).
1561 C-c C-a `mml-attach-file' (attach a file as MIME).
1562 M-RET `message-newline-and-reformat' (break the line and reformat)."
1564 (if (local-variable-p 'mml-buffer-list (current-buffer))
1565 (mml-destroy-buffers))
1566 (kill-all-local-variables)
1567 (set (make-local-variable 'message-reply-buffer) nil)
1568 (make-local-variable 'message-send-actions)
1569 (make-local-variable 'message-exit-actions)
1570 (make-local-variable 'message-kill-actions)
1571 (make-local-variable 'message-postpone-actions)
1572 (make-local-variable 'message-draft-article)
1573 (make-local-hook 'kill-buffer-hook)
1574 (set-syntax-table message-mode-syntax-table)
1575 (use-local-map message-mode-map)
1576 (setq local-abbrev-table message-mode-abbrev-table)
1577 (setq major-mode 'message-mode)
1578 (setq mode-name "Message")
1579 (setq buffer-offer-save t)
1580 (make-local-variable 'facemenu-add-face-function)
1581 (make-local-variable 'facemenu-remove-face-function)
1582 (setq facemenu-add-face-function
1584 (let ((face-fun (cdr (assq face message-face-alist))))
1586 (funcall face-fun (point) end)
1587 (error "Face %s not configured for %s mode" face mode-name)))
1589 facemenu-remove-face-function t)
1590 (make-local-variable 'message-reply-headers)
1591 (setq message-reply-headers nil)
1592 (make-local-variable 'message-newsreader)
1593 (make-local-variable 'message-mailer)
1594 (make-local-variable 'message-post-method)
1595 (set (make-local-variable 'message-sent-message-via) nil)
1596 (set (make-local-variable 'message-checksum) nil)
1597 (set (make-local-variable 'message-mime-part) 0)
1598 (message-setup-fill-variables)
1599 ;; Allow using comment commands to add/remove quoting.
1600 (set (make-local-variable 'comment-start) message-yank-prefix)
1601 (if (featurep 'xemacs)
1602 (message-setup-toolbar)
1603 (set (make-local-variable 'font-lock-defaults)
1604 '(message-font-lock-keywords t))
1605 (if (boundp 'tool-bar-map)
1606 (set (make-local-variable 'tool-bar-map) (message-tool-bar-map))))
1607 (easy-menu-add message-mode-menu message-mode-map)
1608 (easy-menu-add message-mode-field-menu message-mode-map)
1609 ;; Allow mail alias things.
1610 (when (eq message-mail-alias-type 'abbrev)
1611 (if (fboundp 'mail-abbrevs-setup)
1612 (mail-abbrevs-setup)
1613 (mail-aliases-setup)))
1614 (message-set-auto-save-file-name)
1615 (mm-enable-multibyte)
1616 (make-local-variable 'indent-tabs-mode) ;Turn off tabs for indentation.
1617 (setq indent-tabs-mode nil)
1619 (run-hooks 'text-mode-hook 'message-mode-hook))
1621 (defun message-setup-fill-variables ()
1622 "Setup message fill variables."
1623 (set (make-local-variable 'fill-paragraph-function)
1624 'message-fill-paragraph)
1625 (make-local-variable 'paragraph-separate)
1626 (make-local-variable 'paragraph-start)
1627 (make-local-variable 'adaptive-fill-regexp)
1628 (unless (boundp 'adaptive-fill-first-line-regexp)
1629 (setq adaptive-fill-first-line-regexp nil))
1630 (make-local-variable 'adaptive-fill-first-line-regexp)
1631 (make-local-variable 'auto-fill-inhibit-regexp)
1632 (let ((quote-prefix-regexp
1633 ;; User should change message-cite-prefix-regexp if
1634 ;; message-yank-prefix is set to an abnormal value.
1635 (concat "\\(" message-cite-prefix-regexp "\\)[ \t]*")))
1636 (setq paragraph-start
1638 (regexp-quote mail-header-separator) "$\\|"
1639 "[ \t]*$\\|" ; blank lines
1640 "-- $\\|" ; signature delimiter
1641 "---+$\\|" ; delimiters for forwarded messages
1642 page-delimiter "$\\|" ; spoiler warnings
1643 ".*wrote:$\\|" ; attribution lines
1644 quote-prefix-regexp "$")) ; empty lines in quoted text
1645 (setq paragraph-separate paragraph-start)
1646 (setq adaptive-fill-regexp
1647 (concat quote-prefix-regexp "\\|" adaptive-fill-regexp))
1648 (setq adaptive-fill-first-line-regexp
1649 (concat quote-prefix-regexp "\\|"
1650 adaptive-fill-first-line-regexp))
1651 (setq auto-fill-inhibit-regexp "^[A-Z][^: \n\t]+:")))
1656 ;;; Message mode commands
1659 ;;; Movement commands
1661 (defun message-goto-to ()
1662 "Move point to the To header."
1664 (message-position-on-field "To"))
1666 (defun message-goto-subject ()
1667 "Move point to the Subject header."
1669 (message-position-on-field "Subject"))
1671 (defun message-goto-cc ()
1672 "Move point to the Cc header."
1674 (message-position-on-field "Cc" "To"))
1676 (defun message-goto-bcc ()
1677 "Move point to the Bcc header."
1679 (message-position-on-field "Bcc" "Cc" "To"))
1681 (defun message-goto-fcc ()
1682 "Move point to the Fcc header."
1684 (message-position-on-field "Fcc" "To" "Newsgroups"))
1686 (defun message-goto-reply-to ()
1687 "Move point to the Reply-To header."
1689 (message-position-on-field "Reply-To" "Subject"))
1691 (defun message-goto-newsgroups ()
1692 "Move point to the Newsgroups header."
1694 (message-position-on-field "Newsgroups"))
1696 (defun message-goto-distribution ()
1697 "Move point to the Distribution header."
1699 (message-position-on-field "Distribution"))
1701 (defun message-goto-followup-to ()
1702 "Move point to the Followup-To header."
1704 (message-position-on-field "Followup-To" "Newsgroups"))
1706 (defun message-goto-keywords ()
1707 "Move point to the Keywords header."
1709 (message-position-on-field "Keywords" "Subject"))
1711 (defun message-goto-summary ()
1712 "Move point to the Summary header."
1714 (message-position-on-field "Summary" "Subject"))
1716 (defun message-goto-body (&optional interactivep)
1717 "Move point to the beginning of the message body."
1718 (interactive (list t))
1719 (when (and interactivep
1720 (looking-at "[ \t]*\n"))
1722 (goto-char (point-min))
1723 (or (search-forward (concat "\n" mail-header-separator "\n") nil t)
1724 (search-forward "\n\n" nil t)))
1726 (defun message-goto-eoh ()
1727 "Move point to the end of the headers."
1732 (defun message-goto-signature ()
1733 "Move point to the beginning of the message signature.
1734 If there is no signature in the article, go to the end and
1737 (goto-char (point-min))
1738 (if (re-search-forward message-signature-separator nil t)
1740 (goto-char (point-max))
1745 (defun message-insert-to (&optional force)
1746 "Insert a To header that points to the author of the article being replied to.
1747 If the original author requested not to be sent mail, the function signals
1749 With the prefix argument FORCE, insert the header anyway."
1751 (let ((co (message-fetch-reply-field "mail-copies-to")))
1752 (when (and (null force)
1754 (or (equal (downcase co) "never")
1755 (equal (downcase co) "nobody")))
1756 (error "The user has requested not to have copies sent via mail")))
1757 (when (and (message-position-on-field "To")
1758 (mail-fetch-field "to")
1759 (not (string-match "\\` *\\'" (mail-fetch-field "to"))))
1761 (insert (or (message-fetch-reply-field "mail-reply-to")
1762 (message-fetch-reply-field "reply-to")
1763 (message-fetch-reply-field "from") "")))
1765 (defun message-widen-reply ()
1766 "Widen the reply to include maximum recipients."
1769 (and message-reply-buffer
1770 (buffer-name message-reply-buffer)
1772 (set-buffer message-reply-buffer)
1773 (message-get-reply-headers t)))))
1776 (message-narrow-to-headers)
1777 (dolist (elem follow-to)
1778 (message-remove-header (symbol-name (car elem)))
1779 (goto-char (point-min))
1780 (insert (symbol-name (car elem)) ": "
1781 (cdr elem) "\n"))))))
1783 (defun message-insert-newsgroups ()
1784 "Insert the Newsgroups header from the article being replied to."
1786 (when (and (message-position-on-field "Newsgroups")
1787 (mail-fetch-field "newsgroups")
1788 (not (string-match "\\` *\\'" (mail-fetch-field "newsgroups"))))
1790 (insert (or (message-fetch-reply-field "newsgroups") "")))
1794 ;;; Various commands
1796 (defun message-delete-not-region (beg end)
1797 "Delete everything in the body of the current message outside of the region."
1801 (delete-region (point) (if (not (message-goto-signature))
1807 (delete-region beg (progn (message-goto-body)
1810 (when (message-goto-signature)
1813 (defun message-kill-to-signature ()
1814 "Deletes all text up to the signature."
1816 (let ((point (point)))
1817 (message-goto-signature)
1820 (kill-region point (point))
1824 (defun message-newline-and-reformat (&optional arg not-break)
1825 "Insert four newlines, and then reformat if inside quoted text.
1826 Prefix arg means justify as well."
1827 (interactive (list (if current-prefix-arg 'full)))
1828 (let (quoted point beg end leading-space bolp)
1829 (setq point (point))
1832 (setq bolp (= beg point))
1833 ;; Find first line of the paragraph.
1835 (while (and (not (eobp))
1836 (not (looking-at message-cite-prefix-regexp))
1837 (looking-at paragraph-start))
1840 (when (looking-at message-cite-prefix-regexp)
1841 (setq quoted (match-string 0))
1842 (goto-char (match-end 0))
1843 (looking-at "[ \t]*")
1844 (setq leading-space (match-string 0)))
1848 (< (- point beg) (length quoted)))
1849 ;; break inside the cite prefix.
1855 (while (and (not (eobp))
1856 (not (looking-at paragraph-separate))
1857 (looking-at message-cite-prefix-regexp)
1858 (equal quoted (match-string 0)))
1859 (goto-char (match-end 0))
1860 (looking-at "[ \t]*")
1861 (if (> (length leading-space) (length (match-string 0)))
1862 (setq leading-space (match-string 0)))
1866 (while (and (if (bobp) nil (forward-line -1) t)
1867 (not (looking-at paragraph-start))
1868 (looking-at message-cite-prefix-regexp)
1869 (equal quoted (match-string 0)))
1871 (goto-char (match-end 0))
1872 (looking-at "[ \t]*")
1873 (if (> (length leading-space) (length (match-string 0)))
1874 (setq leading-space (match-string 0)))))
1875 (while (and (not (eobp))
1876 (not (looking-at paragraph-separate))
1877 (not (looking-at message-cite-prefix-regexp)))
1881 (while (and (if (bobp) nil (forward-line -1) t)
1882 (not (looking-at paragraph-start))
1883 (not (looking-at message-cite-prefix-regexp)))
1884 (setq beg (point))))
1887 (narrow-to-region beg end)
1893 (setq point (point))
1895 (delete-region (point) (re-search-forward "[ \t]*"))
1896 (when (and quoted (not bolp))
1897 (insert quoted leading-space)))
1899 (let* ((adaptive-fill-regexp
1900 (regexp-quote (concat quoted leading-space)))
1901 (adaptive-fill-first-line-regexp
1902 adaptive-fill-regexp ))
1903 (fill-paragraph arg))
1904 (fill-paragraph arg))
1905 (if point (goto-char point)))))
1907 (defun message-fill-paragraph (&optional arg)
1908 "Like `fill-paragraph'."
1909 (interactive (list (if current-prefix-arg 'full)))
1910 (message-newline-and-reformat arg t)
1913 (defun message-insert-signature (&optional force)
1914 "Insert a signature. See documentation for variable `message-signature'."
1915 (interactive (list 0))
1918 ((and (null message-signature)
1921 (goto-char (point-max))
1922 (not (re-search-backward message-signature-separator nil t))))
1923 ((and (null message-signature)
1926 ((message-functionp message-signature)
1927 (funcall message-signature))
1928 ((listp message-signature)
1929 (eval message-signature))
1930 (t message-signature)))
1932 (cond ((stringp signature)
1934 ((and (eq t signature)
1935 message-signature-file
1936 (file-exists-p message-signature-file))
1939 (goto-char (point-max))
1940 ;; Insert the signature.
1944 (if (eq signature t)
1945 (insert-file-contents message-signature-file)
1947 (goto-char (point-max))
1948 (or (bolp) (insert "\n")))))
1950 (defun message-elide-region (b e)
1951 "Elide the text in the region.
1952 An ellipsis (from `message-elide-ellipsis') will be inserted where the
1956 (insert message-elide-ellipsis))
1958 (defvar message-caesar-translation-table nil)
1960 (defun message-caesar-region (b e &optional n)
1961 "Caesar rotate region B to E by N, default 13, for decrypting netnews."
1964 (min (point) (or (mark t) (point)))
1965 (max (point) (or (mark t) (point)))
1966 (when current-prefix-arg
1967 (prefix-numeric-value current-prefix-arg))))
1969 (setq n (if (numberp n) (mod n 26) 13)) ;canonize N
1970 (unless (or (zerop n) ; no action needed for a rot of 0
1971 (= b e)) ; no region to rotate
1972 ;; We build the table, if necessary.
1973 (when (or (not message-caesar-translation-table)
1974 (/= (aref message-caesar-translation-table ?a) (+ ?a n)))
1975 (setq message-caesar-translation-table
1976 (message-make-caesar-translation-table n)))
1977 (translate-region b e message-caesar-translation-table)))
1979 (defun message-make-caesar-translation-table (n)
1980 "Create a rot table with offset N."
1982 (table (make-string 256 0)))
1983 (while (< (incf i) 256)
1986 (substring table 0 ?A)
1987 (substring table (+ ?A n) (+ ?A n (- 26 n)))
1988 (substring table ?A (+ ?A n))
1989 (substring table (+ ?A 26) ?a)
1990 (substring table (+ ?a n) (+ ?a n (- 26 n)))
1991 (substring table ?a (+ ?a n))
1992 (substring table (+ ?a 26) 255))))
1994 (defun message-caesar-buffer-body (&optional rotnum)
1995 "Caesar rotate all letters in the current buffer by 13 places.
1996 Used to encode/decode possibly offensive messages (commonly in rec.humor).
1997 With prefix arg, specifies the number of places to rotate each letter forward.
1998 Mail and USENET news headers are not rotated."
1999 (interactive (if current-prefix-arg
2000 (list (prefix-numeric-value current-prefix-arg))
2004 (when (message-goto-body)
2005 (narrow-to-region (point) (point-max)))
2006 (message-caesar-region (point-min) (point-max) rotnum))))
2008 (defun message-pipe-buffer-body (program)
2009 "Pipe the message body in the current buffer through PROGRAM."
2012 (when (message-goto-body)
2013 (narrow-to-region (point) (point-max)))
2014 (shell-command-on-region
2015 (point-min) (point-max) program nil t))))
2017 (defun message-rename-buffer (&optional enter-string)
2018 "Rename the *message* buffer to \"*message* RECIPIENT\".
2019 If the function is run with a prefix, it will ask for a new buffer
2020 name, rather than giving an automatic name."
2021 (interactive "Pbuffer name: ")
2024 (goto-char (point-min))
2025 (narrow-to-region (point)
2026 (search-forward mail-header-separator nil 'end))
2028 (if (message-news-p) (message-fetch-field "Newsgroups")
2029 (message-fetch-field "To"))
2032 (if (string-match "," mail-to)
2033 (concat (substring mail-to 0 (match-beginning 0)) ", ...")
2035 (name-default (concat "*message* " mail-trimmed-to))
2036 (name (if enter-string
2037 (read-string "New buffer name: " name-default)
2039 (rename-buffer name t)))))
2041 (defun message-fill-yanked-message (&optional justifyp)
2042 "Fill the paragraphs of a message yanked into this one.
2043 Numeric argument means justify as well."
2046 (goto-char (point-min))
2047 (search-forward (concat "\n" mail-header-separator "\n") nil t)
2048 (let ((fill-prefix message-yank-prefix))
2049 (fill-individual-paragraphs (point) (point-max) justifyp))))
2051 (defun message-indent-citation ()
2052 "Modify text just inserted from a message to be cited.
2053 The inserted text should be the region.
2054 When this function returns, the region is again around the modified text.
2056 Normally, indent each nonblank line `message-indentation-spaces' spaces.
2057 However, if `message-yank-prefix' is non-nil, insert that prefix on each line."
2058 (let ((start (point)))
2059 ;; Remove unwanted headers.
2060 (when message-ignored-cited-headers
2065 (if (search-forward "\n\n" nil t)
2068 (message-remove-header message-ignored-cited-headers t)
2069 (when (= (point-min) (point-max))
2070 (setq all-removed t))
2071 (goto-char (point-max)))
2075 ;; Delete blank lines at the start of the buffer.
2076 (while (and (point-min)
2079 (message-delete-line))
2080 ;; Delete blank lines at the end of the buffer.
2081 (goto-char (point-max))
2084 (while (and (zerop (forward-line -1))
2086 (message-delete-line))
2087 ;; Do the indentation.
2088 (if (null message-yank-prefix)
2089 (indent-rigidly start (mark t) message-indentation-spaces)
2092 (while (< (point) (mark t))
2093 (if (looking-at message-cite-prefix-regexp)
2094 (insert message-yank-cited-prefix)
2095 (insert message-yank-prefix))
2099 (defun message-yank-original (&optional arg)
2100 "Insert the message being replied to, if any.
2101 Puts point before the text and mark after.
2102 Normally indents each nonblank line ARG spaces (default 3). However,
2103 if `message-yank-prefix' is non-nil, insert that prefix on each line.
2105 This function uses `message-cite-function' to do the actual citing.
2107 Just \\[universal-argument] as argument means don't indent, insert no
2108 prefix, and don't delete any headers."
2110 (let ((modified (buffer-modified-p)))
2111 (when (and message-reply-buffer
2112 message-cite-function)
2113 (delete-windows-on message-reply-buffer t)
2114 (insert-buffer message-reply-buffer)
2116 (funcall message-cite-function))
2117 (message-exchange-point-and-mark)
2121 (setq message-checksum (message-checksum))))))
2123 (defun message-yank-buffer (buffer)
2124 "Insert BUFFER into the current buffer and quote it."
2125 (interactive "bYank buffer: ")
2126 (let ((message-reply-buffer buffer))
2127 (save-window-excursion
2128 (message-yank-original))))
2130 (defun message-buffers ()
2131 "Return a list of active message buffers."
2134 (dolist (buffer (buffer-list t))
2136 (when (and (eq major-mode 'message-mode)
2137 (null message-sent-message-via))
2138 (push (buffer-name buffer) buffers))))
2139 (nreverse buffers)))
2141 (defun message-cite-original-without-signature ()
2142 "Cite function in the standard Message manner."
2143 (let ((start (point))
2146 (when message-indent-citation-function
2147 (if (listp message-indent-citation-function)
2148 message-indent-citation-function
2149 (list message-indent-citation-function)))))
2150 (mml-quote-region start end)
2154 (when (re-search-backward message-signature-separator start t)
2155 ;; Also peel off any blank lines before the signature.
2157 (while (looking-at "^[ \t]*$")
2160 (delete-region (point) end)
2161 (unless (search-backward "\n\n" start t)
2162 ;; Insert a blank line if it is peeled off.
2166 (funcall (pop functions)))
2167 (when message-citation-line-function
2170 (funcall message-citation-line-function))))
2172 (eval-when-compile (defvar mail-citation-hook)) ;Compiler directive
2173 (defun message-cite-original ()
2174 "Cite function in the standard Message manner."
2175 (if (and (boundp 'mail-citation-hook)
2177 (run-hooks 'mail-citation-hook)
2178 (let ((start (point))
2181 (when message-indent-citation-function
2182 (if (listp message-indent-citation-function)
2183 message-indent-citation-function
2184 (list message-indent-citation-function)))))
2185 (mml-quote-region start end)
2188 (funcall (pop functions)))
2189 (when message-citation-line-function
2192 (funcall message-citation-line-function)))))
2194 (defun message-insert-citation-line ()
2195 "Insert a simple citation line."
2196 (when message-reply-headers
2197 (insert (mail-header-from message-reply-headers) " writes:\n\n")))
2199 (defun message-position-on-field (header &rest afters)
2200 (let ((case-fold-search t))
2203 (goto-char (point-min))
2206 (concat "^" (regexp-quote mail-header-separator) "$"))
2207 (match-beginning 0)))
2208 (goto-char (point-min))
2209 (if (re-search-forward (concat "^" (regexp-quote header) ":") nil t)
2211 (re-search-forward "^[^ \t]" nil 'move)
2213 (skip-chars-backward "\n")
2216 (not (re-search-forward
2217 (concat "^" (regexp-quote (car afters)) ":")
2221 (re-search-forward "^[^ \t]" nil 'move)
2222 (beginning-of-line))
2223 (insert header ": \n")
2227 (defun message-remove-signature ()
2228 "Remove the signature from the text between point and mark.
2229 The text will also be indented the normal way."
2231 (let ((start (point))
2233 (if (not (re-search-forward message-signature-separator (mark t) t))
2234 ;; No signature here, so we just indent the cited text.
2235 (message-indent-citation)
2236 ;; Find the last non-empty line.
2238 (while (looking-at "[ \t]*$")
2241 (setq mark (set-marker (make-marker) (point)))
2243 (message-indent-citation)
2244 ;; Enable undoing the deletion.
2246 (delete-region mark (mark t))
2247 (set-marker mark nil)))))
2252 ;;; Sending messages
2255 (defun message-send-and-exit (&optional arg)
2256 "Send message like `message-send', then, if no errors, exit from mail buffer."
2258 (let ((buf (current-buffer))
2259 (actions message-exit-actions))
2260 (when (and (message-send arg)
2262 (if message-kill-buffer-on-exit
2265 (when (eq buf (current-buffer))
2266 (message-bury buf)))
2267 (message-do-actions actions)
2270 (defun message-dont-send ()
2271 "Don't send the message you have been editing."
2273 (set-buffer-modified-p t)
2275 (let ((actions message-postpone-actions))
2276 (message-bury (current-buffer))
2277 (message-do-actions actions)))
2279 (defun message-kill-buffer ()
2280 "Kill the current buffer."
2282 (when (or (not (buffer-modified-p))
2283 (yes-or-no-p "Message modified; kill anyway? "))
2284 (let ((actions message-kill-actions))
2285 (setq buffer-file-name nil)
2286 (kill-buffer (current-buffer))
2287 (message-do-actions actions))))
2289 (defun message-bury (buffer)
2290 "Bury this mail BUFFER."
2291 (let ((newbuf (other-buffer buffer)))
2292 (bury-buffer buffer)
2293 (if (and (fboundp 'frame-parameters)
2294 (cdr (assq 'dedicated (frame-parameters)))
2295 (not (null (delq (selected-frame) (visible-frame-list)))))
2296 (delete-frame (selected-frame))
2297 (switch-to-buffer newbuf))))
2299 (defun message-send (&optional arg)
2300 "Send the message in the current buffer.
2301 If `message-interactive' is non-nil, wait for success indication or
2302 error messages, and inform user.
2303 Otherwise any failure is reported in a message back to the user from
2305 The usage of ARG is defined by the instance that called Message.
2306 It should typically alter the sending method in some way or other."
2308 ;; Make it possible to undo the coming changes.
2310 (let ((inhibit-read-only t))
2311 (put-text-property (point-min) (point-max) 'read-only nil))
2312 (message-fix-before-sending)
2313 (run-hooks 'message-send-hook)
2314 (message message-sending-message)
2315 (let ((alist message-send-method-alist)
2318 (message-options message-options))
2319 (message-options-set-recipient)
2321 (setq elem (pop alist)))
2322 (when (funcall (cadr elem))
2323 (when (and (or (not (memq (car elem)
2324 message-sent-message-via))
2325 (if (or (message-gnksa-enable-p 'multiple-copies)
2326 (not (eq (car elem) 'news)))
2329 "Already sent message via %s; resend? "
2331 (error "Denied posting -- multiple copies.")))
2332 (setq success (funcall (caddr elem) arg)))
2334 (unless (or sent (not success))
2335 (error "No methods specified to send by"))
2336 (when (and success sent)
2339 (run-hooks 'message-sent-hook))
2340 (message "Sending...done")
2341 ;; Mark the buffer as unmodified and delete auto-save.
2342 (set-buffer-modified-p nil)
2343 (delete-auto-save-file-if-necessary t)
2344 (message-disassociate-draft)
2345 ;; Delete other mail buffers and stuff.
2346 (message-do-send-housekeeping)
2347 (message-do-actions message-send-actions)
2351 (defun message-send-via-mail (arg)
2352 "Send the current message via mail."
2353 (message-send-mail arg))
2355 (defun message-send-via-news (arg)
2356 "Send the current message via news."
2357 (funcall message-send-news-function arg))
2359 (defmacro message-check (type &rest forms)
2360 "Eval FORMS if TYPE is to be checked."
2361 `(or (message-check-element ,type)
2365 (put 'message-check 'lisp-indent-function 1)
2366 (put 'message-check 'edebug-form-spec '(form body))
2368 (defun message-fix-before-sending ()
2369 "Do various things to make the message nice before sending it."
2370 ;; Make sure there's a newline at the end of the message.
2371 (goto-char (point-max))
2374 ;; Delete all invisible text.
2375 (message-check 'invisible-text
2376 (when (text-property-any (point-min) (point-max) 'invisible t)
2377 (put-text-property (point-min) (point-max) 'invisible nil)
2378 (unless (yes-or-no-p
2379 "Invisible text found and made visible; continue posting? ")
2380 (error "Invisible text found and made visible")))))
2382 (defun message-add-action (action &rest types)
2383 "Add ACTION to be performed when doing an exit of type TYPES."
2386 (set (setq var (intern (format "message-%s-actions" (pop types))))
2387 (nconc (symbol-value var) (list action))))))
2389 (defun message-do-actions (actions)
2390 "Perform all actions in ACTIONS."
2391 ;; Now perform actions on successful sending.
2395 ;; A simple function.
2396 ((message-functionp (car actions))
2397 (funcall (car actions)))
2398 ;; Something to be evaled.
2400 (eval (car actions)))))
2403 (defun message-send-mail-partially ()
2404 "Send mail as message/partial."
2405 ;; replace the header delimiter with a blank line
2406 (goto-char (point-min))
2408 (concat "^" (regexp-quote mail-header-separator) "\n"))
2409 (replace-match "\n")
2410 (run-hooks 'message-send-mail-hook)
2411 (let ((p (goto-char (point-min)))
2412 (tembuf (message-generate-new-buffer-clone-locals " message temp"))
2413 (curbuf (current-buffer))
2414 (id (message-make-message-id)) (n 1)
2415 plist total header required-mail-headers)
2417 (if (< (point-max) (+ p message-send-mail-partially-limit))
2418 (goto-char (point-max))
2419 (goto-char (+ p message-send-mail-partially-limit))
2421 (if (<= (point) p) (forward-line 1))) ;; In case of bad message.
2424 (setq total (length plist))
2425 (push (point-max) plist)
2426 (setq plist (nreverse plist))
2429 (setq p (pop plist))
2432 (copy-to-buffer tembuf p (car plist))
2434 (goto-char (point-min))
2437 (goto-char (point-min))
2438 (narrow-to-region (point) (point))
2441 (setq header (buffer-substring (point-min) (point)))
2442 (goto-char (point-min))
2443 (narrow-to-region (point) (point))
2445 (message-remove-header "Mime-Version")
2446 (message-remove-header "Content-Type")
2447 (message-remove-header "Content-Transfer-Encoding")
2448 (message-remove-header "Message-ID")
2449 (message-remove-header "Lines")
2450 (goto-char (point-max))
2451 (insert "Mime-Version: 1.0\n")
2452 (setq header (buffer-substring (point-min) (point-max))))
2453 (goto-char (point-max))
2454 (insert (format "Content-Type: message/partial; id=\"%s\"; number=%d; total=%d\n"
2456 (let ((mail-header-separator ""))
2457 (when (memq 'Message-ID message-required-mail-headers)
2458 (insert "Message-ID: " (message-make-message-id) "\n"))
2459 (when (memq 'Lines message-required-mail-headers)
2460 (let ((mail-header-separator ""))
2461 (insert "Lines: " (message-make-lines) "\n")))
2462 (message-goto-subject)
2464 (insert (format " (%d/%d)" n total))
2465 (goto-char (point-max))
2468 (mm-with-unibyte-current-buffer
2469 (funcall message-send-mail-function)))
2471 (setq p (pop plist))
2473 (kill-buffer tembuf))))
2475 (defun message-send-mail (&optional arg)
2476 (require 'mail-utils)
2477 (let* ((tembuf (message-generate-new-buffer-clone-locals " message temp"))
2478 (case-fold-search nil)
2479 (news (message-news-p))
2480 (mailbuf (current-buffer))
2481 (message-this-is-mail t)
2482 (message-posting-charset
2483 (if (fboundp 'gnus-setup-posting-charset)
2484 (gnus-setup-posting-charset nil)
2485 message-posting-charset)))
2487 (message-narrow-to-headers)
2488 ;; Insert some headers.
2489 (let ((message-deletable-headers
2490 (if news nil message-deletable-headers)))
2491 (message-generate-headers message-required-mail-headers))
2492 ;; Let the user do all of the above.
2493 (run-hooks 'message-header-hook))
2498 ;; Avoid copying text props.
2499 (insert (with-current-buffer mailbuf
2500 (buffer-substring-no-properties (point-min) (point-max))))
2501 ;; Remove some headers.
2502 (message-encode-message-body)
2504 (message-narrow-to-headers)
2505 ;; We (re)generate the Lines header.
2506 (when (memq 'Lines message-required-mail-headers)
2507 (message-generate-headers '(Lines)))
2508 ;; Remove some headers.
2509 (message-remove-header message-ignored-mail-headers t)
2510 (let ((mail-parse-charset message-default-charset))
2511 (mail-encode-encoded-word-buffer)))
2512 (goto-char (point-max))
2513 ;; require one newline at the end.
2514 (or (= (preceding-char) ?\n)
2518 (message-narrow-to-headers)
2520 (or (message-fetch-field "cc")
2521 (message-fetch-field "to"))
2522 (let ((content-type (message-fetch-field "content-type")))
2525 (string= "text/plain"
2527 (mail-header-parse-content-type
2529 (message-insert-courtesy-copy))
2530 (if (or (not message-send-mail-partially-limit)
2531 (< (point-max) message-send-mail-partially-limit)
2532 (not (y-or-n-p "Message exceeds message-send-mail-partially-limit, send in parts? ")))
2533 (mm-with-unibyte-current-buffer
2534 (message "Sending via mail...")
2535 (funcall message-send-mail-function))
2536 (message-send-mail-partially)))
2537 (kill-buffer tembuf))
2538 (set-buffer mailbuf)
2539 (push 'mail message-sent-message-via)))
2541 (defun message-send-mail-with-sendmail ()
2542 "Send off the prepared buffer with sendmail."
2543 (let ((errbuf (if message-interactive
2544 (message-generate-new-buffer-clone-locals
2547 resend-to-addresses delimline)
2548 (let ((case-fold-search t))
2550 (message-narrow-to-headers)
2551 (setq resend-to-addresses (message-fetch-field "resent-to")))
2552 ;; Change header-delimiter to be what sendmail expects.
2553 (goto-char (point-min))
2555 (concat "^" (regexp-quote mail-header-separator) "\n"))
2556 (replace-match "\n")
2558 (setq delimline (point-marker))
2559 (run-hooks 'message-send-mail-hook)
2560 ;; Insert an extra newline if we need it to work around
2561 ;; Sun's bug that swallows newlines.
2562 (goto-char (1+ delimline))
2563 (when (eval message-mailer-swallows-blank-line)
2565 (when message-interactive
2569 (let ((default-directory "/")
2570 (coding-system-for-write message-send-coding-system))
2571 (apply 'call-process-region
2572 (append (list (point-min) (point-max)
2573 (if (boundp 'sendmail-program)
2575 "/usr/lib/sendmail")
2576 nil errbuf nil "-oi")
2577 ;; Always specify who from,
2578 ;; since some systems have broken sendmails.
2579 ;; But some systems are more broken with -f, so
2580 ;; we'll let users override this.
2581 (if (null message-sendmail-f-is-evil)
2582 (list "-f" (message-make-address)))
2583 ;; These mean "report errors by mail"
2584 ;; and "deliver in background".
2585 (if (null message-interactive) '("-oem" "-odb"))
2586 ;; Get the addresses from the message
2587 ;; unless this is a resend.
2588 ;; We must not do that for a resend
2589 ;; because we would find the original addresses.
2590 ;; For a resend, include the specific addresses.
2591 (if resend-to-addresses
2592 (list resend-to-addresses)
2594 (when message-interactive
2597 (goto-char (point-min))
2598 (while (re-search-forward "\n\n* *" nil t)
2599 (replace-match "; "))
2600 (if (not (zerop (buffer-size)))
2601 (error "Sending...failed to %s"
2602 (buffer-substring (point-min) (point-max)))))
2603 (when (bufferp errbuf)
2604 (kill-buffer errbuf)))))
2606 (defun message-send-mail-with-qmail ()
2607 "Pass the prepared message buffer to qmail-inject.
2608 Refer to the documentation for the variable `message-send-mail-function'
2609 to find out how to use this."
2610 ;; replace the header delimiter with a blank line
2611 (goto-char (point-min))
2613 (concat "^" (regexp-quote mail-header-separator) "\n"))
2614 (replace-match "\n")
2615 (run-hooks 'message-send-mail-hook)
2618 (let ((coding-system-for-write message-send-coding-system))
2620 'call-process-region 1 (point-max) message-qmail-inject-program
2622 ;; qmail-inject's default behaviour is to look for addresses on the
2623 ;; command line; if there're none, it scans the headers.
2624 ;; yes, it does The Right Thing w.r.t. Resent-To and it's kin.
2626 ;; in general, ALL of qmail-inject's defaults are perfect for simply
2627 ;; reading a formatted (i. e., at least a To: or Resent-To header)
2628 ;; message from stdin.
2630 ;; qmail also has the advantage of not having been raped by
2631 ;; various vendors, so we don't have to allow for that, either --
2632 ;; compare this with message-send-mail-with-sendmail and weep
2633 ;; for sendmail's lost innocence.
2635 ;; all this is way cool coz it lets us keep the arguments entirely
2636 ;; free for -inject-arguments -- a big win for the user and for us
2637 ;; since we don't have to play that double-guessing game and the user
2638 ;; gets full control (no gestapo'ish -f's, for instance). --sj
2639 message-qmail-inject-args))
2640 ;; qmail-inject doesn't say anything on it's stdout/stderr,
2641 ;; we have to look at the retval instead
2643 (1 (error "qmail-inject reported permanent failure"))
2644 (111 (error "qmail-inject reported transient failure"))
2645 ;; should never happen
2646 (t (error "qmail-inject reported unknown failure"))))
2648 (defun message-send-mail-with-mh ()
2649 "Send the prepared message buffer with mh."
2650 (let ((mh-previous-window-config nil)
2651 (name (mh-new-draft-name)))
2652 (setq buffer-file-name name)
2653 ;; MH wants to generate these headers itself.
2654 (when message-mh-deletable-headers
2655 (let ((headers message-mh-deletable-headers))
2657 (goto-char (point-min))
2658 (and (re-search-forward
2659 (concat "^" (symbol-name (car headers)) ": *") nil t)
2660 (message-delete-line))
2662 (run-hooks 'message-send-mail-hook)
2663 ;; Pass it on to mh.
2666 (defun message-send-news (&optional arg)
2667 (let* ((tembuf (message-generate-new-buffer-clone-locals " *message temp*"))
2668 (case-fold-search nil)
2669 (method (if (message-functionp message-post-method)
2670 (funcall message-post-method arg)
2671 message-post-method))
2672 (group-name-charset (gnus-group-name-charset method ""))
2673 (rfc2047-header-encoding-alist
2674 (if group-name-charset
2675 (cons (cons "Newsgroups" group-name-charset)
2676 rfc2047-header-encoding-alist)
2677 rfc2047-header-encoding-alist))
2678 (messbuf (current-buffer))
2679 (message-syntax-checks
2681 (cons '(existing-newsgroups . disabled)
2682 message-syntax-checks)
2683 message-syntax-checks))
2684 (message-this-is-news t)
2685 (message-posting-charset (gnus-setup-posting-charset
2687 (message-narrow-to-headers-or-head)
2688 (message-fetch-field "Newsgroups"))))
2690 (if (not (message-check-news-body-syntax))
2693 (message-narrow-to-headers)
2694 ;; Insert some headers.
2695 (message-generate-headers message-required-news-headers)
2696 ;; Let the user do all of the above.
2697 (run-hooks 'message-header-hook))
2698 (when group-name-charset
2699 (setq message-syntax-checks
2700 (cons '(valid-newsgroups . disabled)
2701 message-syntax-checks)))
2702 (message-cleanup-headers)
2703 (if (not (message-check-news-syntax))
2708 (buffer-disable-undo)
2710 ;; Avoid copying text props.
2711 (insert (with-current-buffer messbuf
2712 (buffer-substring-no-properties
2713 (point-min) (point-max))))
2714 (message-encode-message-body)
2715 ;; Remove some headers.
2717 (message-narrow-to-headers)
2718 ;; We (re)generate the Lines header.
2719 (when (memq 'Lines message-required-mail-headers)
2720 (message-generate-headers '(Lines)))
2721 ;; Remove some headers.
2722 (message-remove-header message-ignored-news-headers t)
2723 (let ((mail-parse-charset message-default-charset))
2724 (mail-encode-encoded-word-buffer)))
2725 (goto-char (point-max))
2726 ;; require one newline at the end.
2727 (or (= (preceding-char) ?\n)
2729 (let ((case-fold-search t))
2730 ;; Remove the delimiter.
2731 (goto-char (point-min))
2733 (concat "^" (regexp-quote mail-header-separator) "\n"))
2734 (replace-match "\n")
2736 (run-hooks 'message-send-news-hook)
2737 (gnus-open-server method)
2738 (message "Sending news with %s..." (gnus-server-string method))
2739 (setq result (let ((mail-header-separator ""))
2740 (gnus-request-post method))))
2741 (kill-buffer tembuf))
2742 (set-buffer messbuf)
2744 (push 'news message-sent-message-via)
2745 (message "Couldn't send message via news: %s"
2746 (nnheader-get-report (car method)))
2750 ;;; Header generation & syntax checking.
2753 (defun message-check-element (type)
2754 "Return non-nil if this TYPE is not to be checked."
2755 (if (eq message-syntax-checks 'dont-check-for-anything-just-trust-me)
2757 (let ((able (assq type message-syntax-checks)))
2759 (eq (cdr able) 'disabled)))))
2761 (defun message-check-news-syntax ()
2762 "Check the syntax of the message."
2766 ;; We narrow to the headers and check them first.
2769 (message-narrow-to-headers)
2770 (message-check-news-header-syntax))))))
2772 (defun message-check-news-header-syntax ()
2774 ;; Check Newsgroups header.
2775 (message-check 'newsgroups
2776 (let ((group (message-fetch-field "newsgroups")))
2779 (not (string-match "\\`[ \t]*\\'" group)))
2782 "The newsgroups field is empty or missing. Posting is denied.")))))
2783 ;; Check the Subject header.
2784 (message-check 'subject
2785 (let* ((case-fold-search t)
2786 (subject (message-fetch-field "subject")))
2789 (not (string-match "\\`[ \t]*\\'" subject)))
2792 "The subject field is empty or missing. Posting is denied.")))))
2793 ;; Check for commands in Subject.
2794 (message-check 'subject-cmsg
2795 (if (string-match "^cmsg " (message-fetch-field "subject"))
2797 "The control code \"cmsg\" is in the subject. Really post? ")
2799 ;; Check for multiple identical headers.
2800 (message-check 'multiple-headers
2802 (while (and (not found)
2803 (re-search-forward "^[^ \t:]+: " nil t))
2805 (or (re-search-forward
2810 (match-beginning 0) (- (match-end 0) 2))))
2815 (y-or-n-p (format "Multiple %s headers. Really post? " found))
2817 ;; Check for Version and Sendsys.
2818 (message-check 'sendsys
2819 (if (re-search-forward "^Sendsys:\\|^Version:" nil t)
2821 (format "The article contains a %s command. Really post? "
2822 (buffer-substring (match-beginning 0)
2823 (1- (match-end 0)))))
2825 ;; See whether we can shorten Followup-To.
2826 (message-check 'shorten-followup-to
2827 (let ((newsgroups (message-fetch-field "newsgroups"))
2828 (followup-to (message-fetch-field "followup-to"))
2830 (when (and newsgroups
2831 (string-match "," newsgroups)
2836 (setq to (completing-read
2837 "Followups to: (default all groups) "
2838 (mapcar (lambda (g) (list g))
2840 (message-tokenize-header
2842 (goto-char (point-min))
2843 (insert "Followup-To: " to "\n"))
2845 ;; Check "Shoot me".
2846 (message-check 'shoot
2847 (if (re-search-forward
2848 "Message-ID.*.i-did-not-set--mail-host-address--so-shoot-me" nil t)
2849 (y-or-n-p "You appear to have a misconfigured system. Really post? ")
2851 ;; Check for Approved.
2852 (message-check 'approved
2853 (if (re-search-forward "^Approved:" nil t)
2854 (y-or-n-p "The article contains an Approved header. Really post? ")
2856 ;; Check the Message-ID header.
2857 (message-check 'message-id
2858 (let* ((case-fold-search t)
2859 (message-id (message-fetch-field "message-id" t)))
2860 (or (not message-id)
2861 ;; Is there an @ in the ID?
2862 (and (string-match "@" message-id)
2863 ;; Is there a dot in the ID?
2864 (string-match "@[^.]*\\." message-id)
2865 ;; Does the ID end with a dot?
2866 (not (string-match "\\.>" message-id)))
2868 (format "The Message-ID looks strange: \"%s\". Really post? "
2870 ;; Check the Newsgroups & Followup-To headers.
2871 (message-check 'existing-newsgroups
2872 (let* ((case-fold-search t)
2873 (newsgroups (message-fetch-field "newsgroups"))
2874 (followup-to (message-fetch-field "followup-to"))
2875 (groups (message-tokenize-header
2877 (concat newsgroups "," followup-to)
2879 (hashtb (and (boundp 'gnus-active-hashtb)
2880 gnus-active-hashtb))
2883 (when (and (not (boundp (intern (car groups) hashtb)))
2884 (not (equal (car groups) "poster")))
2885 (push (car groups) errors))
2888 ;; Gnus is not running.
2890 (not (boundp 'gnus-read-active-file)))
2892 ;; We don't have all the group names.
2893 ((and (or (not gnus-read-active-file)
2894 (eq gnus-read-active-file 'some))
2898 "Really post to %s possibly unknown group%s: %s? "
2899 (if (= (length errors) 1) "this" "these")
2900 (if (= (length errors) 1) "" "s")
2901 (mapconcat 'identity errors ", "))))
2902 ;; There were no errors.
2905 ;; There are unknown groups.
2909 "Really post to %s unknown group%s: %s? "
2910 (if (= (length errors) 1) "this" "these")
2911 (if (= (length errors) 1) "" "s")
2912 (mapconcat 'identity errors ", ")))))))
2913 ;; Check the Newsgroups & Followup-To headers for syntax errors.
2914 (message-check 'valid-newsgroups
2915 (let ((case-fold-search t)
2916 (headers '("Newsgroups" "Followup-To"))
2918 (while (and headers (not error))
2919 (when (setq header (mail-fetch-field (car headers)))
2923 "\\`\\([-+_&.a-zA-Z0-9]+\\)?\\(,[-+_&.a-zA-Z0-9]+\\)*\\'"
2928 (not (string-match "\\.\\'\\|\\.\\." g)))
2929 (message-tokenize-header header ","))))
2936 (format "The %s header looks odd: \"%s\". Really post? "
2937 (car headers) header)))))
2938 (message-check 'repeated-newsgroups
2939 (let ((case-fold-search t)
2940 (headers '("Newsgroups" "Followup-To"))
2941 header error groups group)
2944 (when (setq header (mail-fetch-field (pop headers)))
2945 (setq groups (message-tokenize-header header ","))
2946 (while (setq group (pop groups))
2947 (when (member group groups)
2953 (format "Group %s is repeated in headers. Really post? " error)))))
2954 ;; Check the From header.
2955 (message-check 'from
2956 (let* ((case-fold-search t)
2957 (from (message-fetch-field "from"))
2961 (message "There is no From line. Posting is denied.")
2963 ((or (not (string-match
2965 (setq ad (nth 1 (mail-extract-address-components
2966 from))))) ;larsi@ifi
2967 (string-match "\\.\\." ad) ;larsi@ifi..uio
2968 (string-match "@\\." ad) ;larsi@.ifi.uio
2969 (string-match "\\.$" ad) ;larsi@ifi.uio.
2970 (not (string-match "^[^@]+@[^@]+$" ad)) ;larsi.ifi.uio
2971 (string-match "(.*).*(.*)" from)) ;(lars) (lars)
2973 "Denied posting -- the From looks strange: \"%s\"." from)
2977 (defun message-check-news-body-syntax ()
2979 ;; Check for long lines.
2980 (message-check 'long-lines
2981 (goto-char (point-min))
2983 (concat "^" (regexp-quote mail-header-separator) "$"))
2987 "<#\\(/\\)?\\(multipart\\|part\\|external\\|mml\\)")
2990 (< (- (point) p) 80)))
2991 (zerop (forward-line 1))))
2995 "You have lines longer than 79 characters. Really post? ")))
2996 ;; Check whether the article is empty.
2997 (message-check 'empty
2998 (goto-char (point-min))
3000 (concat "^" (regexp-quote mail-header-separator) "$"))
3003 (goto-char (point-max))
3004 (re-search-backward message-signature-separator nil t)
3006 (or (re-search-backward "[^ \n\t]" b t)
3007 (if (message-gnksa-enable-p 'empty-article)
3008 (y-or-n-p "Empty article. Really post? ")
3009 (message "Denied posting -- Empty article.")
3011 ;; Check for control characters.
3012 (message-check 'control-chars
3013 (if (re-search-forward "[\000-\007\013\015-\032\034-\037\200-\237]" nil t)
3015 "The article contains control characters. Really post? ")
3017 ;; Check excessive size.
3018 (message-check 'size
3019 (if (> (buffer-size) 60000)
3021 (format "The article is %d octets long. Really post? "
3024 ;; Check whether any new text has been added.
3025 (message-check 'new-text
3027 (not message-checksum)
3028 (not (eq (message-checksum) message-checksum))
3029 (if (message-gnksa-enable-p 'quoted-text-only)
3031 "It looks like no new text has been added. Really post? ")
3032 (message "Denied posting -- no new text has been added.")
3034 ;; Check the length of the signature.
3035 (message-check 'signature
3036 (goto-char (point-max))
3037 (if (> (count-lines (point) (point-max)) 5)
3040 "Your .sig is %d lines; it should be max 4. Really post? "
3041 (1- (count-lines (point) (point-max)))))
3043 ;; Ensure that text follows last quoted portion.
3044 (message-check 'quoting-style
3045 (goto-char (point-max))
3046 (let ((no-problem t))
3047 (when (search-backward-regexp "^>[^\n]*\n" nil t)
3048 (setq no-problem (search-forward-regexp "^[ \t]*[^>\n]" nil t)))
3051 (if (message-gnksa-enable-p 'quoted-text-only)
3052 (y-or-n-p "Your text should follow quoted text. Really post? ")
3054 (goto-char (point-min))
3056 (concat "^" (regexp-quote mail-header-separator) "$"))
3057 (if (search-forward-regexp "^[ \t]*[^>\n]" nil t)
3058 (y-or-n-p "Your text should follow quoted text. Really post? ")
3059 (message "Denied posting -- only quoted text.")
3062 (defun message-checksum ()
3063 "Return a \"checksum\" for the current buffer."
3066 (goto-char (point-min))
3068 (concat "^" (regexp-quote mail-header-separator) "$"))
3070 (when (not (looking-at "[ \t\n]"))
3071 (setq sum (logxor (ash sum 1) (if (natnump sum) 0 1)
3076 (defun message-do-fcc ()
3077 "Process Fcc headers in the current buffer."
3078 (let ((case-fold-search t)
3079 (buf (current-buffer))
3082 (set-buffer (get-buffer-create " *message temp*"))
3084 (insert-buffer-substring buf)
3086 (message-narrow-to-headers)
3087 (while (setq file (message-fetch-field "fcc"))
3089 (message-remove-header "fcc" nil t)))
3090 (message-encode-message-body)
3092 (message-narrow-to-headers)
3093 (let ((mail-parse-charset message-default-charset)
3094 (rfc2047-header-encoding-alist
3095 (cons '("Newsgroups" . default)
3096 rfc2047-header-encoding-alist)))
3097 (mail-encode-encoded-word-buffer)))
3098 (goto-char (point-min))
3099 (when (re-search-forward
3100 (concat "^" (regexp-quote mail-header-separator) "$")
3102 (replace-match "" t t ))
3103 ;; Process FCC operations.
3105 (setq file (pop list))
3106 (if (string-match "^[ \t]*|[ \t]*\\(.*\\)[ \t]*$" file)
3107 ;; Pipe the article to the program in question.
3108 (call-process-region (point-min) (point-max) shell-file-name
3109 nil nil nil shell-command-switch
3110 (match-string 1 file))
3111 ;; Save the article.
3112 (setq file (expand-file-name file))
3113 (unless (file-exists-p (file-name-directory file))
3114 (make-directory (file-name-directory file) t))
3115 (if (and message-fcc-handler-function
3116 (not (eq message-fcc-handler-function 'rmail-output)))
3117 (funcall message-fcc-handler-function file)
3118 (if (and (file-readable-p file) (mail-file-babyl-p file))
3119 (rmail-output file 1 nil t)
3120 (let ((mail-use-rfc822 t))
3121 (rmail-output file 1 t t))))))
3122 (kill-buffer (current-buffer)))))
3124 (defun message-output (filename)
3125 "Append this article to Unix/babyl mail file FILENAME."
3126 (if (and (file-readable-p filename)
3127 (mail-file-babyl-p filename))
3128 (gnus-output-to-rmail filename t)
3129 (gnus-output-to-mail filename t)))
3131 (defun message-cleanup-headers ()
3132 "Do various automatic cleanups of the headers."
3133 ;; Remove empty lines in the header.
3135 (message-narrow-to-headers)
3136 ;; Remove blank lines.
3137 (while (re-search-forward "^[ \t]*\n" nil t)
3138 (replace-match "" t t))
3140 ;; Correct Newsgroups and Followup-To headers: Change sequence of
3141 ;; spaces to comma and eliminate spaces around commas. Eliminate
3142 ;; embedded line breaks.
3143 (goto-char (point-min))
3144 (while (re-search-forward "^\\(Newsgroups\\|Followup-To\\): +" nil t)
3148 (if (re-search-forward "^[^ \t]" nil t)
3152 (goto-char (point-min))
3153 (while (re-search-forward "\n[ \t]+" nil t)
3154 (replace-match " " t t)) ;No line breaks (too confusing)
3155 (goto-char (point-min))
3156 (while (re-search-forward "[ \t\n]*,[ \t\n]*\\|[ \t]+" nil t)
3157 (replace-match "," t t))
3158 (goto-char (point-min))
3159 ;; Remove trailing commas.
3160 (when (re-search-forward ",+$" nil t)
3161 (replace-match "" t t))))))
3163 (defun message-make-date (&optional now)
3164 "Make a valid data header.
3165 If NOW, use that time instead."
3166 (let* ((now (or now (current-time)))
3167 (zone (nth 8 (decode-time now)))
3171 (setq zone (- zone)))
3173 (format-time-string "%d" now)
3174 ;; The month name of the %b spec is locale-specific. Pfff.
3176 (capitalize (car (rassoc (nth 4 (decode-time now))
3177 parse-time-months))))
3178 (format-time-string "%Y %H:%M:%S " now)
3179 ;; We do all of this because XEmacs doesn't have the %z spec.
3180 (format "%s%02d%02d" sign (/ zone 3600) (/ (% zone 3600) 60)))))
3182 (defun message-make-message-id ()
3183 "Make a unique Message-ID."
3184 (concat "<" (message-unique-id)
3185 (let ((psubject (save-excursion (message-fetch-field "subject")))
3187 (save-excursion (message-fetch-field "supersedes"))))
3189 (and message-reply-headers
3190 (mail-header-references message-reply-headers)
3191 (mail-header-subject message-reply-headers)
3194 (message-strip-subject-re
3195 (mail-header-subject message-reply-headers))
3196 (message-strip-subject-re psubject))))
3198 (string-match "_-_@" psupersedes)))
3200 "@" (message-make-fqdn) ">"))
3202 (defvar message-unique-id-char nil)
3204 ;; If you ever change this function, make sure the new version
3205 ;; cannot generate IDs that the old version could.
3206 ;; You might for example insert a "." somewhere (not next to another dot
3207 ;; or string boundary), or modify the "fsf" string.
3208 (defun message-unique-id ()
3209 ;; Don't use microseconds from (current-time), they may be unsupported.
3210 ;; Instead we use this randomly inited counter.
3211 (setq message-unique-id-char
3212 (% (1+ (or message-unique-id-char (logand (random t) (1- (lsh 1 20)))))
3213 ;; (current-time) returns 16-bit ints,
3214 ;; and 2^16*25 just fits into 4 digits i base 36.
3216 (let ((tm (current-time)))
3218 (if (memq system-type '(ms-dos emx vax-vms))
3219 (let ((user (downcase (user-login-name))))
3220 (while (string-match "[^a-z0-9_]" user)
3221 (aset user (match-beginning 0) ?_))
3223 (message-number-base36 (user-uid) -1))
3224 (message-number-base36 (+ (car tm)
3225 (lsh (% message-unique-id-char 25) 16)) 4)
3226 (message-number-base36 (+ (nth 1 tm)
3227 (lsh (/ message-unique-id-char 25) 16)) 4)
3228 ;; Append the newsreader name, because while the generated
3229 ;; ID is unique to this newsreader, other newsreaders might
3230 ;; otherwise generate the same ID via another algorithm.
3233 (defun message-number-base36 (num len)
3238 (concat (message-number-base36 (/ num 36) (1- len))
3239 (char-to-string (aref "zyxwvutsrqponmlkjihgfedcba9876543210"
3242 (defun message-make-organization ()
3243 "Make an Organization header."
3244 (let* ((organization
3245 (when message-user-organization
3246 (if (message-functionp message-user-organization)
3247 (funcall message-user-organization)
3248 message-user-organization))))
3250 (message-set-work-buffer)
3251 (cond ((stringp organization)
3252 (insert organization))
3253 ((and (eq t organization)
3254 message-user-organization-file
3255 (file-exists-p message-user-organization-file))
3256 (insert-file-contents message-user-organization-file)))
3257 (goto-char (point-min))
3258 (while (re-search-forward "[\t\n]+" nil t)
3259 (replace-match "" t t))
3260 (unless (zerop (buffer-size))
3263 (defun message-make-lines ()
3264 "Count the number of lines and return numeric string."
3269 (int-to-string (count-lines (point) (point-max))))))
3271 (defun message-make-in-reply-to ()
3272 "Return the In-Reply-To header for this message."
3273 (when message-reply-headers
3274 (let ((from (mail-header-from message-reply-headers))
3275 (date (mail-header-date message-reply-headers))
3276 (msg-id (mail-header-message-id message-reply-headers)))
3279 (string-match " *at \\| *@ \\| *(\\| *<" from)))
3280 (concat msg-id (if msg-id " (")
3282 (not (zerop stop-pos)))
3283 (substring from 0 stop-pos) from)
3285 (if (or (not date) (string= date ""))
3286 "(unknown date)" date)
3287 "\"" (if msg-id ")")))))))
3289 (defun message-make-distribution ()
3290 "Make a Distribution header."
3291 (let ((orig-distribution (message-fetch-reply-field "distribution")))
3292 (cond ((message-functionp message-distribution-function)
3293 (funcall message-distribution-function))
3294 (t orig-distribution))))
3296 (defun message-make-expires ()
3297 "Return an Expires header based on `message-expires'."
3298 (let ((current (current-time))
3299 (future (* 1.0 message-expires 60 60 24)))
3300 ;; Add the future to current.
3301 (setcar current (+ (car current) (round (/ future (expt 2 16)))))
3302 (setcar (cdr current) (+ (nth 1 current) (% (round future) (expt 2 16))))
3303 (message-make-date current)))
3305 (defun message-make-path ()
3307 (let ((login-name (user-login-name)))
3308 (cond ((null message-user-path)
3309 (concat (system-name) "!" login-name))
3310 ((stringp message-user-path)
3311 ;; Support GENERICPATH. Suggested by vixie@decwrl.dec.com.
3312 (concat message-user-path "!" login-name))
3315 (defun message-make-from ()
3316 "Make a From header."
3317 (let* ((style message-from-style)
3318 (login (message-make-address))
3320 (or (and (boundp 'user-full-name)
3323 (when (string= fullname "&")
3324 (setq fullname (user-login-name)))
3326 (message-set-work-buffer)
3329 (equal fullname ""))
3331 ((or (eq style 'angles)
3332 (and (not (eq style 'parens))
3333 ;; Use angles if no quoting is needed, or if parens would
3334 ;; need quoting too.
3335 (or (not (string-match "[^- !#-'*+/-9=?A-Z^-~]" fullname))
3336 (let ((tmp (concat fullname nil)))
3337 (while (string-match "([^()]*)" tmp)
3338 (aset tmp (match-beginning 0) ?-)
3339 (aset tmp (1- (match-end 0)) ?-))
3340 (string-match "[\\()]" tmp)))))
3342 (goto-char (point-min))
3343 ;; Look for a character that cannot appear unquoted
3344 ;; according to RFC 822.
3345 (when (re-search-forward "[^- !#-'*+/-9=?A-Z^-~]" nil 1)
3346 ;; Quote fullname, escaping specials.
3347 (goto-char (point-min))
3349 (while (re-search-forward "[\"\\]" nil 1)
3350 (replace-match "\\\\\\&" t))
3352 (insert " <" login ">"))
3353 (t ; 'parens or default
3355 (let ((fullname-start (point)))
3357 (goto-char fullname-start)
3358 ;; RFC 822 says \ and nonmatching parentheses
3359 ;; must be escaped in comments.
3360 ;; Escape every instance of ()\ ...
3361 (while (re-search-forward "[()\\]" nil 1)
3362 (replace-match "\\\\\\&" t))
3363 ;; ... then undo escaping of matching parentheses,
3364 ;; including matching nested parentheses.
3365 (goto-char fullname-start)
3366 (while (re-search-forward
3367 "\\(\\=\\|[^\\]\\(\\\\\\\\\\)*\\)\\\\(\\(\\([^\\]\\|\\\\\\\\\\)*\\)\\\\)"
3369 (replace-match "\\1(\\3)" t)
3370 (goto-char fullname-start)))
3374 (defun message-make-sender ()
3375 "Return the \"real\" user address.
3376 This function tries to ignore all user modifications, and
3377 give as trustworthy answer as possible."
3378 (concat (user-login-name) "@" (system-name)))
3380 (defun message-make-address ()
3381 "Make the address of the user."
3382 (or (message-user-mail-address)
3383 (concat (user-login-name) "@" (message-make-domain))))
3385 (defun message-user-mail-address ()
3386 "Return the pertinent part of `user-mail-address'."
3387 (when user-mail-address
3388 (if (string-match " " user-mail-address)
3389 (nth 1 (mail-extract-address-components user-mail-address))
3390 user-mail-address)))
3392 (defun message-make-fqdn ()
3393 "Return user's fully qualified domain name."
3394 (let ((system-name (system-name))
3395 (user-mail (message-user-mail-address)))
3397 ((string-match "[^.]\\.[^.]" system-name)
3398 ;; `system-name' returned the right result.
3400 ;; Try `mail-host-address'.
3401 ((and (boundp 'mail-host-address)
3402 (stringp mail-host-address)
3403 (string-match "\\." mail-host-address))
3405 ;; We try `user-mail-address' as a backup.
3407 (string-match "\\." user-mail)
3408 (string-match "@\\(.*\\)\\'" user-mail))
3409 (match-string 1 user-mail))
3410 ;; Default to this bogus thing.
3412 (concat system-name ".i-did-not-set--mail-host-address--so-shoot-me")))))
3414 (defun message-make-host-name ()
3415 "Return the name of the host."
3416 (let ((fqdn (message-make-fqdn)))
3417 (string-match "^[^.]+\\." fqdn)
3418 (substring fqdn 0 (1- (match-end 0)))))
3420 (defun message-make-domain ()
3421 "Return the domain name."
3422 (or mail-host-address
3423 (message-make-fqdn)))
3425 (defun message-generate-headers (headers)
3426 "Prepare article HEADERS.
3427 Headers already prepared in the buffer are not modified."
3429 (message-narrow-to-headers)
3430 (let* ((Date (message-make-date))
3431 (Message-ID (message-make-message-id))
3432 (Organization (message-make-organization))
3433 (From (message-make-from))
3434 (Path (message-make-path))
3437 (In-Reply-To (message-make-in-reply-to))
3439 (Distribution (message-make-distribution))
3440 (Lines (message-make-lines))
3441 (User-Agent message-newsreader)
3442 (Expires (message-make-expires))
3443 (case-fold-search t)
3445 ;; First we remove any old generated headers.
3446 (let ((headers message-deletable-headers))
3447 (unless (buffer-modified-p)
3448 (setq headers (delq 'Message-ID (copy-sequence headers))))
3450 (goto-char (point-min))
3451 (and (re-search-forward
3452 (concat "^" (symbol-name (car headers)) ": *") nil t)
3453 (get-text-property (1+ (match-beginning 0)) 'message-deletable)
3454 (message-delete-line))
3456 ;; Go through all the required headers and see if they are in the
3457 ;; articles already. If they are not, or are empty, they are
3458 ;; inserted automatically - except for Subject, Newsgroups and
3461 (goto-char (point-min))
3462 (setq elem (pop headers))
3464 (if (eq (car elem) 'optional)
3465 (setq header (cdr elem))
3466 (setq header (car elem)))
3468 (when (or (not (re-search-forward
3472 (if (stringp header)
3474 (symbol-name header))))
3478 ;; The header was found. We insert a space after the
3479 ;; colon, if there is none.
3480 (if (/= (char-after) ? ) (insert " ") (forward-char 1))
3481 ;; Find out whether the header is empty...
3482 (looking-at "[ \t]*\n[^ \t]")))
3483 ;; So we find out what value we should insert.
3486 ((and (consp elem) (eq (car elem) 'optional))
3487 ;; This is an optional header. If the cdr of this
3488 ;; is something that is nil, then we do not insert
3490 (setq header (cdr elem))
3491 (or (and (fboundp (cdr elem)) (funcall (cdr elem)))
3492 (and (boundp (cdr elem)) (symbol-value (cdr elem)))))
3494 ;; The element is a cons. Either the cdr is a
3495 ;; string to be inserted verbatim, or it is a
3496 ;; function, and we insert the value returned from
3498 (or (and (stringp (cdr elem)) (cdr elem))
3499 (and (fboundp (cdr elem)) (funcall (cdr elem)))))
3500 ((and (boundp header) (symbol-value header))
3501 ;; The element is a symbol. We insert the value
3502 ;; of this symbol, if any.
3503 (symbol-value header))
3504 ((not (message-check-element header))
3505 ;; We couldn't generate a value for this header,
3506 ;; so we just ask the user.
3507 (read-from-minibuffer
3508 (format "Empty header for %s; enter value: " header)))))
3509 ;; Finally insert the header.
3511 (not (equal value "")))
3515 ;; This header didn't exist, so we insert it.
3516 (goto-char (point-max))
3517 (insert (if (stringp header) header (symbol-name header))
3520 ;; The value of this header was empty, so we clear
3521 ;; totally and insert the new value.
3522 (delete-region (point) (gnus-point-at-eol))
3524 ;; Add the deletable property to the headers that require it.
3525 (and (memq header message-deletable-headers)
3526 (progn (beginning-of-line) (looking-at "[^:]+: "))
3527 (add-text-properties
3528 (point) (match-end 0)
3529 '(message-deletable t face italic) (current-buffer)))))))
3530 ;; Insert new Sender if the From is strange.
3531 (let ((from (message-fetch-field "from"))
3532 (sender (message-fetch-field "sender"))
3533 (secure-sender (message-make-sender)))
3535 (not (message-check-element 'sender))
3538 (cadr (mail-extract-address-components from)))
3539 (downcase secure-sender)))
3544 (cadr (mail-extract-address-components sender)))
3545 (downcase secure-sender)))))
3546 (goto-char (point-min))
3547 ;; Rename any old Sender headers to Original-Sender.
3548 (when (re-search-forward "^\\(Original-\\)*Sender:" nil t)
3550 (insert "Original-")
3551 (beginning-of-line))
3552 (when (or (message-news-p)
3553 (string-match "@.+\\.." secure-sender))
3554 (insert "Sender: " secure-sender "\n")))))))
3556 (defun message-insert-courtesy-copy ()
3557 "Insert a courtesy message in mail copies of combined messages."
3561 (message-narrow-to-headers)
3562 (when (setq newsgroups (message-fetch-field "newsgroups"))
3563 (goto-char (point-max))
3564 (insert "Posted-To: " newsgroups "\n")))
3566 (when message-courtesy-message
3568 ((string-match "%s" message-courtesy-message)
3569 (insert (format message-courtesy-message newsgroups)))
3571 (insert message-courtesy-message)))))))
3574 ;;; Setting up a message buffer
3577 (defun message-fill-address (header value)
3579 (narrow-to-region (point) (point))
3580 (insert (capitalize (symbol-name header))
3582 (if (consp value) (car value) value)
3584 (narrow-to-region (point-min) (1- (point-max)))
3586 (goto-char (point-min))
3588 (skip-chars-forward "^,\"" (point-max))
3589 (if (or (eq (char-after) ?,)
3592 (if (and (> (current-column) 78)
3598 (setq last (1+ (point))))
3599 (setq last (1+ (point)))))
3600 (setq quoted (not quoted)))
3603 (goto-char (point-max))
3607 (defun message-fill-header (header value)
3608 (let ((begin (point))
3611 (insert (capitalize (symbol-name header))
3613 (if (consp value) (car value) value)
3616 (narrow-to-region begin (point))
3617 (fill-region-as-paragraph begin (point))
3618 ;; Tapdance around looong Message-IDs.
3620 (when (looking-at "[ \t]*$")
3621 (message-delete-line))
3623 (re-search-forward ":" nil t)
3624 (when (looking-at "\n[ \t]+")
3625 (replace-match " " t t))
3626 (goto-char (point-max)))))
3628 (defun message-shorten-1 (list cut surplus)
3629 "Cut SURPLUS elements out of LIST, beginning with CUTth one."
3630 (setcdr (nthcdr (- cut 2) list)
3631 (nthcdr (+ (- cut 2) surplus 1) list)))
3633 (defun message-shorten-references (header references)
3634 "Trim REFERENCES to be less than 31 Message-ID long, and fold them.
3635 If folding is disallowed, also check that the REFERENCES are less
3636 than 988 characters long, and if they are not, trim them until they are."
3643 (goto-char (point-min))
3644 ;; Cons a list of valid references.
3645 (while (re-search-forward "<[^>]+>" nil t)
3646 (push (match-string 0) refs))
3647 (setq refs (nreverse refs)
3648 count (length refs)))
3650 ;; If the list has more than MAXCOUNT elements, trim it by
3651 ;; removing the CUTth element and the required number of
3652 ;; elements that follow.
3653 (when (> count maxcount)
3654 (let ((surplus (- count maxcount)))
3655 (message-shorten-1 refs cut surplus)
3656 (decf count surplus)))
3658 ;; If folding is disallowed, make sure the total length (including
3659 ;; the spaces between) will be less than MAXSIZE characters.
3661 ;; Only disallow folding for News messages. At this point the headers
3662 ;; have not been generated, thus we use message-this-is-news directly.
3663 (when (and message-this-is-news message-cater-to-broken-inn)
3665 (totalsize (+ (apply #'+ (mapcar #'length refs))
3668 (ptr (nthcdr (1- cut) refs)))
3669 ;; Decide how many elements to cut off...
3670 (while (> totalsize maxsize)
3671 (decf totalsize (1+ (length (car ptr))))
3673 (setq ptr (cdr ptr)))
3676 (message-shorten-1 refs cut surplus))))
3678 ;; Finally, collect the references back into a string and insert
3679 ;; it into the buffer.
3680 (let ((refstring (mapconcat #'identity refs " ")))
3681 (if (and message-this-is-news message-cater-to-broken-inn)
3682 (insert (capitalize (symbol-name header)) ": "
3684 (message-fill-header header refstring)))))
3686 (defun message-position-point ()
3687 "Move point to where the user probably wants to find it."
3688 (message-narrow-to-headers)
3690 ((re-search-forward "^[^:]+:[ \t]*$" nil t)
3691 (search-backward ":" )
3694 (if (eq (char-after) ? )
3698 (goto-char (point-max))
3701 (unless (looking-at "$")
3705 (defun message-buffer-name (type &optional to group)
3706 "Return a new (unique) buffer name based on TYPE and TO."
3708 ;; Generate a new buffer name The Message Way.
3709 ((eq message-generate-new-buffers 'unique)
3710 (generate-new-buffer-name
3714 (or (car (mail-extract-address-components to))
3717 (if (and group (not (string= group ""))) (concat " on " group) "")
3719 ;; Check whether `message-generate-new-buffers' is a function,
3720 ;; and if so, call it.
3721 ((message-functionp message-generate-new-buffers)
3722 (funcall message-generate-new-buffers type to group))
3723 ((eq message-generate-new-buffers 'unsent)
3724 (generate-new-buffer-name
3725 (concat "*unsent " type
3728 (or (car (mail-extract-address-components to))
3731 (if (and group (not (string= group ""))) (concat " on " group) "")
3733 ;; Use standard name.
3735 (format "*%s message*" type))))
3737 (defun message-pop-to-buffer (name)
3738 "Pop to buffer NAME, and warn if it already exists and is modified."
3739 (let ((buffer (get-buffer name)))
3741 (buffer-name buffer))
3743 (set-buffer (pop-to-buffer buffer))
3744 (when (and (buffer-modified-p)
3746 "Message already being composed; erase? ")))
3747 (error "Message being composed")))
3748 (set-buffer (pop-to-buffer name)))
3752 (defun message-do-send-housekeeping ()
3753 "Kill old message buffers."
3754 ;; We might have sent this buffer already. Delete it from the
3756 (setq message-buffer-list (delq (current-buffer) message-buffer-list))
3757 (while (and message-max-buffers
3759 (>= (length message-buffer-list) message-max-buffers))
3760 ;; Kill the oldest buffer -- unless it has been changed.
3761 (let ((buffer (pop message-buffer-list)))
3762 (when (and (buffer-name buffer)
3763 (not (buffer-modified-p buffer)))
3764 (kill-buffer buffer))))
3765 ;; Rename the buffer.
3766 (if message-send-rename-function
3767 (funcall message-send-rename-function)
3768 ;; Note: mail-abbrevs of XEmacs renames buffer name behind Gnus.
3770 "\\`\\*\\(sent \\|unsent \\)?\\(.+\\)\\*[^\\*]*\\|\\`mail to "
3772 (let ((name (match-string 2 (buffer-name)))
3774 (if (not (or (null name)
3775 (string-equal name "mail")
3776 (string-equal name "news")))
3777 (setq name (concat "*sent " name "*"))
3778 (setq to (message-fetch-field "to"))
3779 (setq group (message-fetch-field "newsgroups"))
3782 (to (concat "*sent mail to "
3783 (or (car (mail-extract-address-components to))
3785 ((and group (not (string= group "")))
3786 (concat "*sent news on " group "*"))
3787 (t "*sent mail*"))))
3788 (unless (string-equal name (buffer-name))
3789 (rename-buffer name t)))))
3790 ;; Push the current buffer onto the list.
3791 (when message-max-buffers
3792 (setq message-buffer-list
3793 (nconc message-buffer-list (list (current-buffer))))))
3795 (defun message-mail-user-agent ()
3797 ((not message-mail-user-agent) nil)
3798 ((eq message-mail-user-agent t) mail-user-agent)
3799 (t message-mail-user-agent))))
3800 (if (memq mua '(message-user-agent gnus-user-agent))
3804 (defun message-setup (headers &optional replybuffer actions switch-function)
3805 (let ((mua (message-mail-user-agent))
3806 subject to field yank-action)
3807 (if (not (and message-this-is-mail mua))
3808 (message-setup-1 headers replybuffer actions)
3810 (setq yank-action (list 'insert-buffer replybuffer)))
3811 (setq headers (copy-sequence headers))
3812 (setq field (assq 'Subject headers))
3814 (setq subject (cdr field))
3815 (setq headers (delq field headers)))
3816 (setq field (assq 'To headers))
3818 (setq to (cdr field))
3819 (setq headers (delq field headers)))
3820 (let ((mail-user-agent mua))
3821 (compose-mail to subject
3822 (mapcar (lambda (item)
3824 (format "%s" (car item))
3827 nil switch-function yank-action actions)))))
3829 ;;;(defvar mc-modes-alist)
3830 (defun message-setup-1 (headers &optional replybuffer actions)
3831 ;;; (when (and (boundp 'mc-modes-alist)
3832 ;;; (not (assq 'message-mode mc-modes-alist)))
3833 ;;; (push '(message-mode (encrypt . mc-encrypt-message)
3834 ;;; (sign . mc-sign-message))
3835 ;;; mc-modes-alist))
3837 (setq message-send-actions actions))
3838 (setq message-reply-buffer replybuffer)
3839 (goto-char (point-min))
3840 ;; Insert all the headers.
3843 (alist message-header-format-alist))
3845 (unless (assq (caar h) message-header-format-alist)
3846 (push (list (caar h)) alist))
3850 (delete-region (point) (progn (forward-line -1) (point)))
3851 (when message-default-headers
3852 (insert message-default-headers)
3853 (or (bolp) (insert ?\n)))
3857 (insert mail-header-separator "\n")
3861 (when (message-news-p)
3862 (when message-default-news-headers
3863 (insert message-default-news-headers)
3864 (or (bolp) (insert ?\n)))
3865 (when message-generate-headers-first
3866 (message-generate-headers
3869 (copy-sequence message-required-news-headers))))))
3870 (when (message-mail-p)
3871 (when message-default-mail-headers
3872 (insert message-default-mail-headers)
3873 (or (bolp) (insert ?\n)))
3874 (when message-generate-headers-first
3875 (message-generate-headers
3878 (copy-sequence message-required-mail-headers))))))
3879 (run-hooks 'message-signature-setup-hook)
3880 (message-insert-signature)
3882 (message-narrow-to-headers)
3883 (if message-alternative-emails
3884 (message-use-alternative-email-as-from))
3885 (run-hooks 'message-header-setup-hook))
3886 (set-buffer-modified-p nil)
3887 (setq buffer-undo-list nil)
3888 (run-hooks 'message-setup-hook)
3889 (message-position-point)
3892 (defun message-set-auto-save-file-name ()
3893 "Associate the message buffer with a file in the drafts directory."
3894 (when message-auto-save-directory
3895 (unless (file-directory-p
3896 (directory-file-name message-auto-save-directory))
3897 (gnus-make-directory message-auto-save-directory))
3899 (setq message-draft-article
3900 (nndraft-request-associate-buffer "drafts"))
3901 (setq buffer-file-name (expand-file-name
3902 (if (eq system-type 'windows-nt)
3905 message-auto-save-directory))
3906 (setq buffer-auto-save-file-name (make-auto-save-file-name)))
3907 (clear-visited-file-modtime)
3908 (setq buffer-file-coding-system message-draft-coding-system)))
3910 (defun message-disassociate-draft ()
3911 "Disassociate the message buffer from the drafts directory."
3912 (when message-draft-article
3913 (nndraft-request-expire-articles
3914 (list message-draft-article) "drafts" nil t)))
3916 (defun message-insert-headers ()
3917 "Generate the headers for the article."
3921 (message-narrow-to-headers)
3922 (when (message-news-p)
3923 (message-generate-headers
3926 (copy-sequence message-required-news-headers)))))
3927 (when (message-mail-p)
3928 (message-generate-headers
3931 (copy-sequence message-required-mail-headers))))))))
3936 ;;; Commands for interfacing with message
3940 (defun message-mail (&optional to subject
3941 other-headers continue switch-function
3942 yank-action send-actions)
3943 "Start editing a mail message to be sent.
3944 OTHER-HEADERS is an alist of header/value pairs."
3946 (let ((message-this-is-mail t) replybuffer)
3947 (unless (message-mail-user-agent)
3948 (message-pop-to-buffer (message-buffer-name "mail" to)))
3949 ;; FIXME: message-mail should do something if YANK-ACTION is not
3951 (and (consp yank-action) (eq (car yank-action) 'insert-buffer)
3952 (setq replybuffer (nth 1 yank-action)))
3955 `((To . ,(or to "")) (Subject . ,(or subject "")))
3956 (when other-headers other-headers))
3957 replybuffer send-actions)
3958 ;; FIXME: Should return nil if failure.
3962 (defun message-news (&optional newsgroups subject)
3963 "Start editing a news article to be sent."
3965 (let ((message-this-is-news t))
3966 (message-pop-to-buffer (message-buffer-name "news" nil newsgroups))
3967 (message-setup `((Newsgroups . ,(or newsgroups ""))
3968 (Subject . ,(or subject ""))))))
3970 (defun message-get-reply-headers (wide &optional to-address)
3971 (let (follow-to mct never-mct from to cc reply-to mrt mft ccalist)
3972 ;; Find all relevant headers we need.
3973 (setq from (message-fetch-field "from")
3974 to (message-fetch-field "to")
3975 cc (message-fetch-field "cc")
3976 mct (message-fetch-field "mail-copies-to")
3977 reply-to (message-fetch-field "reply-to")
3978 mrt (message-fetch-field "mail-reply-to")
3979 mft (and message-use-followup-to
3980 (message-fetch-field "mail-followup-to")))
3982 ;; Handle special values of Mail-Copies-To.
3984 (cond ((or (equal (downcase mct) "never")
3985 (equal (downcase mct) "nobody"))
3988 ((or (equal (downcase mct) "always")
3989 (equal (downcase mct) "poster"))
3990 (setq mct (or mrt reply-to from)))))
3996 (setq follow-to (list (cons 'To (or to-address mrt reply-to from))))
3997 (when (and (and wide mct)
3998 (not (member (cons 'To mct) follow-to)))
3999 (push (cons 'Cc mct) follow-to)))
4002 (message-set-work-buffer)
4004 message-use-followup-to
4006 (or (not (eq message-use-followup-to 'ask))
4008 (concat "Obey Mail-Followup-To? ") t "\
4009 You should normally obey the Mail-Followup-To: header. In this
4010 article, it has the value of
4014 which directs your response to " (if (string-match "," mft)
4015 "the specified addresses"
4016 "that address only") ".
4018 If a message is posted to several mailing lists, Mail-Followup-To is
4019 often used to direct the following discussion to one list only,
4020 because discussions that are spread over several lists tend to be
4021 fragmented and very difficult to follow.
4023 Also, some source/announcement lists are not intended for discussion;
4024 responses here are directed to other addresses.")))
4027 (insert (or mrt reply-to from "")))
4028 (insert (if to (concat (if (bolp) "" ", ") to "") ""))
4029 (insert (if mct (concat (if (bolp) "" ", ") mct) ""))
4030 (insert (if cc (concat (if (bolp) "" ", ") cc) "")))
4031 (goto-char (point-min))
4032 (while (re-search-forward "[ \t]+" nil t)
4033 (replace-match " " t t))
4034 ;; Remove addresses that match `rmail-dont-reply-to-names'.
4035 (let ((rmail-dont-reply-to-names message-dont-reply-to-names))
4036 (insert (prog1 (rmail-dont-reply-to (buffer-string))
4038 (goto-char (point-min))
4039 ;; Perhaps "Mail-Copies-To: never" removed the only address?
4041 (insert (or mrt reply-to from "")))
4045 (cons (mail-strip-quoted-names addr) addr))
4046 (message-tokenize-header (buffer-string))))
4049 (setq ccalist (delq (assoc (car (pop s)) s) ccalist)))))
4050 (setq follow-to (list (cons 'To (cdr (pop ccalist)))))
4052 (let ((ccs (cons 'Cc (mapconcat
4053 (lambda (addr) (cdr addr)) ccalist ", "))))
4054 (when (string-match "^ +" (cdr ccs))
4055 (setcdr ccs (substring (cdr ccs) (match-end 0))))
4056 (push ccs follow-to)))
4057 ;; Allow the user to be asked whether or not to reply to all
4058 ;; recipients in a wide reply.
4059 (if (and ccalist wide message-wide-reply-confirm-recipients
4060 (not (y-or-n-p "Reply to all recipients?")))
4061 (setq follow-to (delq (assoc 'Cc follow-to) follow-to)))))
4066 (defun message-reply (&optional to-address wide)
4067 "Start editing a reply to the article in the current buffer."
4069 (require 'gnus-sum) ; for gnus-list-identifiers
4070 (let ((cur (current-buffer))
4071 from subject date reply-to to cc
4072 references message-id follow-to
4073 (inhibit-point-motion-hooks t)
4074 (message-this-is-mail t)
4077 (message-narrow-to-head-1)
4078 ;; Allow customizations to have their say.
4080 ;; This is a regular reply.
4081 (when (message-functionp message-reply-to-function)
4083 (setq follow-to (funcall message-reply-to-function))))
4084 ;; This is a followup.
4085 (when (message-functionp message-wide-reply-to-function)
4088 (funcall message-wide-reply-to-function)))))
4089 (setq message-id (message-fetch-field "message-id" t)
4090 references (message-fetch-field "references")
4091 date (message-fetch-field "date")
4092 from (message-fetch-field "from")
4093 subject (or (message-fetch-field "subject") "none"))
4094 (when gnus-list-identifiers
4095 (setq subject (message-strip-list-identifiers subject)))
4096 (setq subject (concat "Re: " (message-strip-subject-re subject)))
4098 (when (and (setq gnus-warning (message-fetch-field "gnus-warning"))
4099 (string-match "<[^>]+>" gnus-warning))
4100 (setq message-id (match-string 0 gnus-warning)))
4103 (setq follow-to (message-get-reply-headers wide to-address))))
4105 (unless (message-mail-user-agent)
4106 (message-pop-to-buffer
4107 (message-buffer-name
4108 (if wide "wide reply" "reply") from
4109 (if wide to-address nil))))
4111 (setq message-reply-headers
4112 (vector 0 subject from date message-id references 0 0 ""))
4115 `((Subject . ,subject)
4117 ,@(if (or references message-id)
4118 `((References . ,(concat (or references "") (and references " ")
4119 (or message-id ""))))
4124 (defun message-wide-reply (&optional to-address)
4125 "Make a \"wide\" reply to the message in the current buffer."
4127 (message-reply to-address t))
4130 (defun message-followup (&optional to-newsgroups)
4131 "Follow up to the message in the current buffer.
4132 If TO-NEWSGROUPS, use that as the new Newsgroups line."
4134 (require 'gnus-sum) ; for gnus-list-identifiers
4135 (let ((cur (current-buffer))
4136 from subject date reply-to mrt mct
4137 references message-id follow-to
4138 (inhibit-point-motion-hooks t)
4139 (message-this-is-news t)
4140 followup-to distribution newsgroups gnus-warning posted-to)
4143 (goto-char (point-min))
4144 (if (search-forward "\n\n" nil t)
4147 (when (message-functionp message-followup-to-function)
4149 (funcall message-followup-to-function)))
4150 (setq from (message-fetch-field "from")
4151 date (message-fetch-field "date")
4152 subject (or (message-fetch-field "subject") "none")
4153 references (message-fetch-field "references")
4154 message-id (message-fetch-field "message-id" t)
4155 followup-to (message-fetch-field "followup-to")
4156 newsgroups (message-fetch-field "newsgroups")
4157 posted-to (message-fetch-field "posted-to")
4158 reply-to (message-fetch-field "reply-to")
4159 mrt (message-fetch-field "mail-reply-to")
4160 distribution (message-fetch-field "distribution")
4161 mct (message-fetch-field "mail-copies-to"))
4162 (when (and (setq gnus-warning (message-fetch-field "gnus-warning"))
4163 (string-match "<[^>]+>" gnus-warning))
4164 (setq message-id (match-string 0 gnus-warning)))
4165 ;; Remove bogus distribution.
4166 (when (and (stringp distribution)
4167 (let ((case-fold-search t))
4168 (string-match "world" distribution)))
4169 (setq distribution nil))
4170 (if gnus-list-identifiers
4171 (setq subject (message-strip-list-identifiers subject)))
4172 (setq subject (concat "Re: " (message-strip-subject-re subject)))
4175 (message-pop-to-buffer (message-buffer-name "followup" from newsgroups))
4178 `((Subject . ,subject)
4181 (list (cons 'Newsgroups to-newsgroups)))
4182 (follow-to follow-to)
4183 ((and followup-to message-use-followup-to)
4186 ((equal (downcase followup-to) "poster")
4187 (if (or (eq message-use-followup-to 'use)
4188 (message-y-or-n-p "Obey Followup-To: poster? " t "\
4189 You should normally obey the Followup-To: header.
4191 `Followup-To: poster' sends your response via e-mail instead of news.
4193 A typical situation where `Followup-To: poster' is used is when the poster
4194 does not read the newsgroup, so he wouldn't see any replies sent to it."))
4196 (setq message-this-is-news nil)
4197 (cons 'To (or mrt reply-to from "")))
4198 (cons 'Newsgroups newsgroups)))
4200 (if (or (equal followup-to newsgroups)
4201 (not (eq message-use-followup-to 'ask))
4203 (concat "Obey Followup-To: " followup-to "? ") t "\
4204 You should normally obey the Followup-To: header.
4206 `Followup-To: " followup-to "'
4207 directs your response to " (if (string-match "," followup-to)
4208 "the specified newsgroups"
4209 "that newsgroup only") ".
4211 If a message is posted to several newsgroups, Followup-To is often
4212 used to direct the following discussion to one newsgroup only,
4213 because discussions that are spread over several newsgroup tend to
4214 be fragmented and very difficult to follow.
4216 Also, some source/announcement newsgroups are not intended for discussion;
4217 responses here are directed to other newsgroups."))
4218 (cons 'Newsgroups followup-to)
4219 (cons 'Newsgroups newsgroups))))))
4221 `((Newsgroups . ,posted-to)))
4223 `((Newsgroups . ,newsgroups))))
4224 ,@(and distribution (list (cons 'Distribution distribution)))
4225 ,@(if (or references message-id)
4226 `((References . ,(concat (or references "") (and references " ")
4227 (or message-id "")))))
4229 (not (or (equal (downcase mct) "never")
4230 (equal (downcase mct) "nobody"))))
4231 (list (cons 'Cc (if (or (equal (downcase mct) "always")
4232 (equal (downcase mct) "poster"))
4233 (or mrt reply-to from "")
4238 (setq message-reply-headers
4239 (vector 0 subject from date message-id references 0 0 ""))))
4243 (defun message-cancel-news (&optional arg)
4244 "Cancel an article you posted.
4245 If ARG, allow editing of the cancellation message."
4247 (unless (message-news-p)
4248 (error "This is not a news article; canceling is impossible"))
4249 (let (from newsgroups message-id distribution buf sender)
4251 ;; Get header info from original article.
4253 (message-narrow-to-head-1)
4254 (setq from (message-fetch-field "from")
4255 sender (message-fetch-field "sender")
4256 newsgroups (message-fetch-field "newsgroups")
4257 message-id (message-fetch-field "message-id" t)
4258 distribution (message-fetch-field "distribution")))
4259 ;; Make sure that this article was written by the user.
4260 (unless (or (message-gnksa-enable-p 'cancel-messages)
4264 (downcase (message-make-sender))))
4266 (downcase (cadr (mail-extract-address-components from)))
4267 (downcase (cadr (mail-extract-address-components
4268 (message-make-from))))))
4269 (error "This article is not yours"))
4270 (when (yes-or-no-p "Do you really want to cancel this article? ")
4271 ;; Make control message.
4274 (setq buf (set-buffer (get-buffer-create " *message cancel*"))))
4276 (insert "Newsgroups: " newsgroups "\n"
4278 "Subject: cmsg cancel " message-id "\n"
4279 "Control: cancel " message-id "\n"
4281 (concat "Distribution: " distribution "\n")
4283 mail-header-separator "\n"
4284 message-cancel-message)
4285 (run-hooks 'message-cancel-hook)
4287 (message "Canceling your article...")
4288 (if (let ((message-syntax-checks
4289 'dont-check-for-anything-just-trust-me))
4290 (funcall message-send-news-function))
4291 (message "Canceling your article...done"))
4292 (kill-buffer buf))))))
4295 (defun message-supersede ()
4296 "Start composing a message to supersede the current message.
4297 This is done simply by taking the old article and adding a Supersedes
4298 header line with the old Message-ID."
4300 (let ((cur (current-buffer))
4301 (sender (message-fetch-field "sender"))
4302 (from (message-fetch-field "from")))
4303 ;; Check whether the user owns the article that is to be superseded.
4304 (unless (or (message-gnksa-enable-p 'cancel-messages)
4308 (downcase (message-make-sender))))
4310 (downcase (cadr (mail-extract-address-components from)))
4311 (downcase (cadr (mail-extract-address-components
4312 (message-make-from))))))
4313 (error "This article is not yours"))
4314 ;; Get a normal message buffer.
4315 (message-pop-to-buffer (message-buffer-name "supersede"))
4316 (insert-buffer-substring cur)
4318 (message-narrow-to-head-1)
4319 ;; Remove unwanted headers.
4320 (when message-ignored-supersedes-headers
4321 (message-remove-header message-ignored-supersedes-headers t))
4322 (goto-char (point-min))
4323 (if (not (re-search-forward "^Message-ID: " nil t))
4324 (error "No Message-ID in this article")
4325 (replace-match "Supersedes: " t t))
4326 (goto-char (point-max))
4327 (insert mail-header-separator)
4332 (defun message-recover ()
4333 "Reread contents of current buffer from its last auto-save file."
4335 (let ((file-name (make-auto-save-file-name)))
4336 (cond ((save-window-excursion
4337 (if (not (eq system-type 'vax-vms))
4338 (with-output-to-temp-buffer "*Directory*"
4339 (with-current-buffer standard-output
4340 (fundamental-mode)) ; for Emacs 20.4+
4341 (buffer-disable-undo standard-output)
4342 (let ((default-directory "/"))
4344 "ls" nil standard-output nil "-l" file-name))))
4345 (yes-or-no-p (format "Recover auto save file %s? " file-name)))
4346 (let ((buffer-read-only nil))
4348 (insert-file-contents file-name nil)))
4349 (t (error "message-recover cancelled")))))
4351 ;;; Washing Subject:
4353 (defun message-wash-subject (subject)
4354 "Remove junk like \"Re:\", \"(fwd)\", etc. added to subject string SUBJECT.
4355 Previous forwarders, replyers, etc. may add it."
4357 (insert-string subject)
4358 (goto-char (point-min))
4359 ;; strip Re/Fwd stuff off the beginning
4360 (while (re-search-forward
4361 "\\([Rr][Ee]:\\|[Ff][Ww][Dd]\\(\\[[0-9]*\\]\\)?:\\|[Ff][Ww]:\\)" nil t)
4364 ;; and gnus-style forwards [foo@bar.com] subject
4365 (goto-char (point-min))
4366 (while (re-search-forward "\\[[^ \t]*\\(@\\|\\.\\)[^ \t]*\\]" nil t)
4370 (goto-char (point-max))
4371 (while (re-search-backward "([Ff][Ww][Dd])" nil t)
4374 ;; and finally, any whitespace that was left-over
4375 (goto-char (point-min))
4376 (while (re-search-forward "^[ \t]+" nil t)
4378 (goto-char (point-max))
4379 (while (re-search-backward "[ \t]+$" nil t)
4384 ;;; Forwarding messages.
4386 (defvar message-forward-decoded-p nil
4387 "Non-nil means the original message is decoded.")
4389 (defun message-forward-subject-author-subject (subject)
4390 "Generate a SUBJECT for a forwarded message.
4391 The form is: [Source] Subject, where if the original message was mail,
4392 Source is the sender, and if the original message was news, Source is
4393 the list of newsgroups is was posted to."
4396 (or (message-fetch-field
4397 (if (message-news-p) "newsgroups" "from"))
4399 (if message-forward-decoded-p
4401 (mail-decode-encoded-word-string prefix)))
4404 (defun message-forward-subject-fwd (subject)
4405 "Generate a SUBJECT for a forwarded message.
4406 The form is: Fwd: Subject, where Subject is the original subject of
4408 (concat "Fwd: " subject))
4410 (defun message-make-forward-subject ()
4411 "Return a Subject header suitable for the message in the current buffer."
4414 (message-narrow-to-head-1)
4415 (let ((funcs message-make-forward-subject-function)
4416 (subject (message-fetch-field "Subject")))
4419 (if message-forward-decoded-p
4421 (mail-decode-encoded-word-string subject))
4423 (if message-wash-forwarded-subjects
4424 (setq subject (message-wash-subject subject)))
4425 ;; Make sure funcs is a list.
4428 (setq funcs (list funcs)))
4429 ;; Apply funcs in order, passing subject generated by previous
4430 ;; func to the next one.
4432 (when (message-functionp (car funcs))
4433 (setq subject (funcall (car funcs) subject)))
4434 (setq funcs (cdr funcs)))
4438 (defvar gnus-article-decoded-p))
4441 (defun message-forward (&optional news digest)
4442 "Forward the current message via mail.
4443 Optional NEWS will use news to forward instead of mail.
4444 Optional DIGEST will use digest to forward."
4446 (let* ((cur (current-buffer))
4447 (message-forward-decoded-p
4448 (if (local-variable-p 'gnus-article-decoded-p (current-buffer))
4449 gnus-article-decoded-p ;; In an article buffer.
4450 message-forward-decoded-p))
4451 (subject (message-make-forward-subject))
4454 (message-news nil subject)
4455 (message-mail nil subject))
4456 ;; Put point where we want it before inserting the forwarded
4458 (if message-forward-before-signature
4460 (goto-char (point-max)))
4461 (if message-forward-as-mime
4463 (insert "\n<#multipart type=digest>\n")
4464 (if message-forward-show-mml
4465 (insert "\n\n<#mml type=message/rfc822 disposition=inline>\n")
4466 (insert "\n\n<#part type=message/rfc822 disposition=inline raw=t>\n")))
4467 (insert "\n-------------------- Start of forwarded message --------------------\n"))
4468 (let ((b (point)) e)
4470 (if message-forward-as-mime
4471 (insert-buffer-substring cur)
4472 (mml-insert-buffer cur))
4473 (if (and message-forward-show-mml
4474 (not message-forward-decoded-p))
4477 (mm-disable-multibyte-mule4) ;; Must copy buffer in unibyte mode
4479 (with-current-buffer cur
4480 (mm-string-as-unibyte (buffer-string))))
4481 (mm-enable-multibyte-mule4)
4483 (goto-char (point-min))
4484 (when (looking-at "From ")
4485 (replace-match "X-From-Line: "))
4488 (narrow-to-region (point) (point))
4489 (mml-insert-buffer cur)
4490 (goto-char (point-min))
4491 (when (looking-at "From ")
4492 (replace-match "X-From-Line: "))
4493 (goto-char (point-max)))))
4495 (if message-forward-as-mime
4497 (insert "<#/multipart>\n")
4498 (if message-forward-show-mml
4499 (insert "<#/mml>\n")
4500 (insert "<#/part>\n")))
4501 (insert "\n-------------------- End of forwarded message --------------------\n"))
4502 (if (and digest message-forward-as-mime)
4504 (narrow-to-region b e)
4506 (narrow-to-region (point)
4507 (or (search-forward "\n\n" nil t) (point)))
4508 (delete-region (point-min) (point-max)))
4509 (when (and (not current-prefix-arg)
4510 message-forward-ignored-headers)
4512 (narrow-to-region b e)
4514 (narrow-to-region (point)
4515 (or (search-forward "\n\n" nil t) (point)))
4516 (message-remove-header message-forward-ignored-headers t)))))
4517 (message-position-point)))
4520 (defun message-resend (address)
4521 "Resend the current article to ADDRESS."
4523 (list (message-read-from-minibuffer "Resend message to: ")))
4524 (message "Resending message to %s..." address)
4526 (let ((cur (current-buffer))
4528 ;; We first set up a normal mail buffer.
4529 (unless (message-mail-user-agent)
4530 (set-buffer (get-buffer-create " *message resend*"))
4532 (let ((message-this-is-mail t))
4533 (message-setup `((To . ,address))))
4534 ;; Insert our usual headers.
4535 (message-generate-headers '(From Date To))
4536 (message-narrow-to-headers)
4537 ;; Rename them all to "Resent-*".
4538 (while (re-search-forward "^[A-Za-z]" nil t)
4543 (delete-region (point) (point-max))
4545 ;; Insert the message to be resent.
4546 (insert-buffer-substring cur)
4547 (goto-char (point-min))
4548 (search-forward "\n\n")
4551 (narrow-to-region beg (point))
4552 (message-remove-header message-ignored-resent-headers t)
4553 (goto-char (point-max)))
4554 (insert mail-header-separator)
4555 ;; Rename all old ("Also-")Resent headers.
4556 (while (re-search-backward "^\\(Also-\\)*Resent-" beg t)
4559 ;; Quote any "From " lines at the beginning.
4561 (when (looking-at "From ")
4562 (replace-match "X-From-Line: "))
4564 (let ((message-inhibit-body-encoding t)
4565 message-required-mail-headers)
4566 (message-send-mail))
4567 (kill-buffer (current-buffer)))
4568 (message "Resending message to %s...done" address)))
4571 (defun message-bounce ()
4572 "Re-mail the current message.
4573 This only makes sense if the current message is a bounce message that
4574 contains some mail you have written which has been bounced back to
4577 (let ((handles (mm-dissect-buffer t))
4579 (message-pop-to-buffer (message-buffer-name "bounce"))
4580 (if (stringp (car handles))
4581 ;; This is a MIME bounce.
4582 (mm-insert-part (car (last handles)))
4583 ;; This is a non-MIME bounce, so we try to remove things
4585 (mm-insert-part handles)
4587 (goto-char (point-min))
4588 (search-forward "\n\n" nil t)
4589 (or (and (re-search-forward message-unsent-separator nil t)
4591 (re-search-forward "^Return-Path:.*\n" nil t))
4592 ;; We remove everything before the bounced mail.
4595 (if (re-search-forward "^[^ \n\t]+:" nil t)
4598 (mm-enable-multibyte)
4601 (message-narrow-to-head-1)
4602 (message-remove-header message-ignored-bounced-headers t)
4603 (goto-char (point-max))
4604 (insert mail-header-separator))
4605 (message-position-point)))
4608 ;;; Interactive entry points for new message buffers.
4612 (defun message-mail-other-window (&optional to subject)
4613 "Like `message-mail' command, but display mail buffer in another window."
4615 (unless (message-mail-user-agent)
4616 (let ((pop-up-windows t)
4617 (special-display-buffer-names nil)
4618 (special-display-regexps nil)
4619 (same-window-buffer-names nil)
4620 (same-window-regexps nil))
4621 (message-pop-to-buffer (message-buffer-name "mail" to))))
4622 (let ((message-this-is-mail t))
4623 (message-setup `((To . ,(or to "")) (Subject . ,(or subject "")))
4624 nil nil 'switch-to-buffer-other-window)))
4627 (defun message-mail-other-frame (&optional to subject)
4628 "Like `message-mail' command, but display mail buffer in another frame."
4630 (unless (message-mail-user-agent)
4631 (let ((pop-up-frames t)
4632 (special-display-buffer-names nil)
4633 (special-display-regexps nil)
4634 (same-window-buffer-names nil)
4635 (same-window-regexps nil))
4636 (message-pop-to-buffer (message-buffer-name "mail" to))))
4637 (let ((message-this-is-mail t))
4638 (message-setup `((To . ,(or to "")) (Subject . ,(or subject "")))
4639 nil nil 'switch-to-buffer-other-frame)))
4642 (defun message-news-other-window (&optional newsgroups subject)
4643 "Start editing a news article to be sent."
4645 (let ((pop-up-windows t)
4646 (special-display-buffer-names nil)
4647 (special-display-regexps nil)
4648 (same-window-buffer-names nil)
4649 (same-window-regexps nil))
4650 (message-pop-to-buffer (message-buffer-name "news" nil newsgroups)))
4651 (let ((message-this-is-news t))
4652 (message-setup `((Newsgroups . ,(or newsgroups ""))
4653 (Subject . ,(or subject ""))))))
4656 (defun message-news-other-frame (&optional newsgroups subject)
4657 "Start editing a news article to be sent."
4659 (let ((pop-up-frames t)
4660 (special-display-buffer-names nil)
4661 (special-display-regexps nil)
4662 (same-window-buffer-names nil)
4663 (same-window-regexps nil))
4664 (message-pop-to-buffer (message-buffer-name "news" nil newsgroups)))
4665 (let ((message-this-is-news t))
4666 (message-setup `((Newsgroups . ,(or newsgroups ""))
4667 (Subject . ,(or subject ""))))))
4671 ;; This code should be moved to underline.el (from which it is stolen).
4674 (defun bold-region (start end)
4675 "Bold all nonblank characters in the region.
4676 Works by overstriking characters.
4677 Called from program, takes two arguments START and END
4678 which specify the range to operate on."
4681 (let ((end1 (make-marker)))
4682 (move-marker end1 (max start end))
4683 (goto-char (min start end))
4684 (while (< (point) end1)
4685 (or (looking-at "[_\^@- ]")
4686 (insert (char-after) "\b"))
4687 (forward-char 1)))))
4690 (defun unbold-region (start end)
4691 "Remove all boldness (overstruck characters) in the region.
4692 Called from program, takes two arguments START and END
4693 which specify the range to operate on."
4696 (let ((end1 (make-marker)))
4697 (move-marker end1 (max start end))
4698 (goto-char (min start end))
4699 (while (re-search-forward "\b" end1 t)
4700 (if (eq (char-after) (char-after (- (point) 2)))
4701 (delete-char -2))))))
4703 (defalias 'message-exchange-point-and-mark 'exchange-point-and-mark)
4705 ;; Support for toolbar
4707 (defvar tool-bar-map)
4708 (defvar tool-bar-mode))
4710 (defun message-tool-bar-map ()
4711 (or message-tool-bar-map
4712 (setq message-tool-bar-map
4713 (and (fboundp 'tool-bar-add-item-from-menu)
4715 (let ((tool-bar-map (copy-keymap tool-bar-map))
4716 (load-path (mm-image-load-path)))
4717 ;; Zap some items which aren't so relevant and take
4719 (dolist (key '(print-buffer kill-buffer save-buffer
4720 write-file dired open-file))
4721 (define-key tool-bar-map (vector key) nil))
4722 (tool-bar-add-item-from-menu
4723 'message-send-and-exit "mail_send" message-mode-map)
4724 (tool-bar-add-item-from-menu
4725 'message-kill-buffer "close" message-mode-map)
4726 (tool-bar-add-item-from-menu
4727 'message-dont-send "cancel" message-mode-map)
4728 (tool-bar-add-item-from-menu
4729 'mml-attach-file "attach" message-mode-map)
4730 (tool-bar-add-item-from-menu
4731 'ispell-message "spell" message-mode-map)
4734 ;;; Group name completion.
4736 (defvar message-newgroups-header-regexp
4737 "^\\(Newsgroups\\|Followup-To\\|Posted-To\\|Gcc\\):"
4738 "Regexp that match headers that lists groups.")
4740 (defun message-tab ()
4741 "Expand group names in Newsgroups and Followup-To headers.
4742 Do a `tab-to-tab-stop' if not in those headers."
4744 (if (let ((mail-abbrev-mode-regexp message-newgroups-header-regexp))
4745 (mail-abbrev-in-expansion-header-p))
4746 (message-expand-group)
4749 (defun message-expand-group ()
4750 "Expand the group name under point."
4751 (let* ((b (save-excursion
4756 (skip-chars-forward "^:")
4759 (skip-chars-backward "^, \t\n") (point))))
4760 (completion-ignore-case t)
4761 (string (buffer-substring b (progn (skip-chars-forward "^,\t\n ")
4763 (hashtb (and (boundp 'gnus-active-hashtb) gnus-active-hashtb))
4764 (completions (all-completions string hashtb))
4766 (delete-region b (point))
4768 ((= (length completions) 1)
4769 (if (string= (car completions) string)
4772 (message "Only matching group"))
4773 (insert (car completions))))
4774 ((and (setq comp (try-completion string hashtb))
4775 (not (string= comp string)))
4780 (message "No matching groups")
4781 (save-selected-window
4782 (pop-to-buffer "*Completions*")
4783 (buffer-disable-undo)
4784 (let ((buffer-read-only nil))
4786 (let ((standard-output (current-buffer)))
4787 (display-completion-list (sort completions 'string<)))
4788 (goto-char (point-min))
4789 (delete-region (point) (progn (forward-line 3) (point))))))))))
4793 (defun message-talkative-question (ask question show &rest text)
4794 "Call FUNCTION with argument QUESTION; optionally display TEXT... args.
4795 If SHOW is non-nil, the arguments TEXT... are displayed in a temp buffer.
4796 The following arguments may contain lists of values."
4798 (setq text (message-flatten-list text)))
4799 (save-window-excursion
4801 (with-output-to-temp-buffer " *MESSAGE information message*"
4802 (set-buffer " *MESSAGE information message*")
4803 (fundamental-mode) ; for Emacs 20.4+
4804 (mapcar 'princ text)
4805 (goto-char (point-min))))
4806 (funcall ask question))
4807 (funcall ask question)))
4809 (defun message-flatten-list (list)
4810 "Return a new, flat list that contains all elements of LIST.
4812 \(message-flatten-list '(1 (2 3 (4 5 (6))) 7))
4815 (apply 'append (mapcar 'message-flatten-list list)))
4819 (defun message-generate-new-buffer-clone-locals (name &optional varstr)
4820 "Create and return a buffer with name based on NAME using `generate-new-buffer.'
4821 Then clone the local variables and values from the old buffer to the
4822 new one, cloning only the locals having a substring matching the
4824 (let ((oldbuf (current-buffer)))
4826 (set-buffer (generate-new-buffer name))
4827 (message-clone-locals oldbuf varstr)
4830 (defun message-clone-locals (buffer &optional varstr)
4831 "Clone the local variables from BUFFER to the current buffer."
4832 (let ((locals (save-excursion
4834 (buffer-local-variables)))
4835 (regexp "^gnus\\|^nn\\|^message\\|^user-mail-address"))
4838 (when (and (consp local)
4840 (string-match regexp (symbol-name (car local)))
4842 (string-match varstr (symbol-name (car local)))))
4844 (set (make-local-variable (car local))
4848 ;;; Miscellaneous functions
4850 (defsubst message-replace-chars-in-string (string from to)
4851 (mm-subst-char-in-string from to string))
4857 (defvar message-inhibit-body-encoding nil)
4859 (defun message-encode-message-body ()
4860 (unless message-inhibit-body-encoding
4861 (let ((mail-parse-charset (or mail-parse-charset
4862 message-default-charset))
4863 (case-fold-search t)
4864 lines content-type-p)
4867 (narrow-to-region (point) (point-max))
4868 (let ((new (mml-generate-mime)))
4870 (delete-region (point-min) (point-max))
4872 (goto-char (point-min))
4873 (if (eq (aref new 0) ?\n)
4875 (search-forward "\n\n")
4876 (setq lines (buffer-substring (point-min) (1- (point))))
4877 (delete-region (point-min) (point))))))
4879 (message-narrow-to-headers-or-head)
4880 (message-remove-header "Mime-Version")
4881 (goto-char (point-max))
4882 (insert "MIME-Version: 1.0\n")
4885 (setq content-type-p
4887 (re-search-backward "^Content-Type:" nil t))))
4889 (message-narrow-to-headers-or-head)
4890 (message-remove-first-header "Content-Type")
4891 (message-remove-first-header "Content-Transfer-Encoding"))
4892 ;; We always make sure that the message has a Content-Type header.
4893 ;; This is because some broken MTAs and MUAs get awfully confused
4894 ;; when confronted with a message with a MIME-Version header and
4895 ;; without a Content-Type header. For instance, Solaris'
4897 (unless content-type-p
4898 (goto-char (point-min))
4899 (re-search-forward "^MIME-Version:")
4901 (insert "Content-Type: text/plain; charset=us-ascii\n")))))
4903 (defun message-read-from-minibuffer (prompt)
4904 "Read from the minibuffer while providing abbrev expansion."
4905 (if (fboundp 'mail-abbrevs-setup)
4906 (let ((mail-abbrev-mode-regexp "")
4907 (minibuffer-setup-hook 'mail-abbrevs-setup)
4908 (minibuffer-local-map message-minibuffer-local-map))
4909 (read-from-minibuffer prompt))
4910 (let ((minibuffer-setup-hook 'mail-abbrev-minibuffer-setup-hook)
4911 (minibuffer-local-map message-minibuffer-local-map))
4912 (read-string prompt))))
4914 (defun message-use-alternative-email-as-from ()
4915 (require 'mail-utils)
4916 (let* ((fields '("To" "Cc"))
4919 (mail-strip-quoted-names
4920 (mapconcat 'message-fetch-reply-field fields ","))
4924 (if (string-match message-alternative-emails (car emails))
4925 (setq email (car emails)
4928 (unless (or (not email) (equal email user-mail-address))
4929 (goto-char (point-max))
4930 (insert "From: " email "\n"))))
4932 (defun message-options-get (symbol)
4933 (cdr (assq symbol message-options)))
4935 (defun message-options-set (symbol value)
4936 (let ((the-cons (assq symbol message-options)))
4939 (setcdr the-cons value)
4940 (setq message-options (delq the-cons message-options)))
4942 (push (cons symbol value) message-options))))
4945 (defun message-options-set-recipient ()
4947 (message-narrow-to-headers-or-head)
4948 (message-options-set 'message-sender
4949 (mail-strip-quoted-names
4950 (message-fetch-field "from")))
4951 (message-options-set 'message-recipients
4952 (mail-strip-quoted-names
4953 (let ((to (message-fetch-field "to"))
4954 (cc (message-fetch-field "cc"))
4955 (bcc (message-fetch-field "bcc")))
4958 (if (and to cc) ", ")
4960 (if (and (or to cc) bcc) ", ")
4963 (when (featurep 'xemacs)
4964 (require 'messagexmas)
4965 (message-xmas-redefine))
4969 (run-hooks 'message-load-hook)
4972 ;; coding: iso-8859-1
4975 ;;; message.el ends here