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
39 ;; This is apparently necessary even though things are autoloaded:
40 (if (featurep 'xemacs)
41 (require 'mail-abbrevs))
46 (defgroup message '((user-mail-address custom-variable)
47 (user-full-name custom-variable))
48 "Mail and news message composing."
49 :link '(custom-manual "(message)Top")
53 (put 'user-mail-address 'custom-type 'string)
54 (put 'user-full-name 'custom-type 'string)
56 (defgroup message-various nil
57 "Various Message Variables"
58 :link '(custom-manual "(message)Various Message Variables")
61 (defgroup message-buffers nil
63 :link '(custom-manual "(message)Message Buffers")
66 (defgroup message-sending nil
68 :link '(custom-manual "(message)Sending Variables")
71 (defgroup message-interface nil
73 :link '(custom-manual "(message)Interface")
76 (defgroup message-forwarding nil
78 :link '(custom-manual "(message)Forwarding")
79 :group 'message-interface)
81 (defgroup message-insertion nil
83 :link '(custom-manual "(message)Insertion")
86 (defgroup message-headers nil
88 :link '(custom-manual "(message)Message Headers")
91 (defgroup message-news nil
92 "Composing News Messages"
95 (defgroup message-mail nil
96 "Composing Mail Messages"
99 (defgroup message-faces nil
100 "Faces used for message composing."
104 (defcustom message-directory "~/Mail/"
105 "*Directory from which all other mail file variables are derived."
106 :group 'message-various
109 (defcustom message-max-buffers 10
110 "*How many buffers to keep before starting to kill them off."
111 :group 'message-buffers
114 (defcustom message-send-rename-function nil
115 "Function called to rename the buffer after sending it."
116 :group 'message-buffers
117 :type '(choice function (const nil)))
119 (defcustom message-fcc-handler-function 'message-output
120 "*A function called to save outgoing articles.
121 This function will be called with the name of the file to store the
122 article in. The default function is `message-output' which saves in Unix
124 :type '(radio (function-item message-output)
125 (function :tag "Other"))
126 :group 'message-sending)
128 (defcustom message-courtesy-message
129 "The following message is a courtesy copy of an article\nthat has been posted to %s as well.\n\n"
130 "*This is inserted at the start of a mailed copy of a posted message.
131 If the string contains the format spec \"%s\", the Newsgroups
132 the article has been posted to will be inserted there.
133 If this variable is nil, no such courtesy message will be added."
134 :group 'message-sending
137 (defcustom message-ignored-bounced-headers "^\\(Received\\|Return-Path\\):"
138 "*Regexp that matches headers to be removed in resent bounced mail."
139 :group 'message-interface
143 (defcustom message-from-style 'default
144 "*Specifies how \"From\" headers look.
146 If nil, they contain just the return address like:
148 If `parens', they look like:
149 king@grassland.com (Elvis Parsley)
150 If `angles', they look like:
151 Elvis Parsley <king@grassland.com>
153 Otherwise, most addresses look like `angles', but they look like
154 `parens' if `angles' would need quoting and `parens' would not."
155 :type '(choice (const :tag "simple" nil)
159 :group 'message-headers)
161 (defcustom message-syntax-checks nil
162 ;; Guess this one shouldn't be easy to customize...
163 "*Controls what syntax checks should not be performed on outgoing posts.
164 To disable checking of long signatures, for instance, add
165 `(signature . disabled)' to this list.
167 Don't touch this variable unless you really know what you're doing.
169 Checks include `subject-cmsg', `multiple-headers', `sendsys',
170 `message-id', `from', `long-lines', `control-chars', `size',
171 `new-text', `quoting-style', `redirected-followup', `signature',
172 `approved', `sender', `empty', `empty-headers', `message-id', `from',
173 `subject', `shorten-followup-to', `existing-newsgroups',
174 `buffer-file-name', `unchanged', `newsgroups', `reply-to'."
176 :type '(repeat sexp)) ; Fixme: improve this
178 (defcustom message-required-news-headers
179 '(From Newsgroups Subject Date Message-ID
180 (optional . Organization) Lines
181 (optional . User-Agent))
182 "*Headers to be generated or prompted for when posting an article.
183 RFC977 and RFC1036 require From, Date, Newsgroups, Subject,
184 Message-ID. Organization, Lines, In-Reply-To, Expires, and
185 User-Agent are optional. If don't you want message to insert some
186 header, remove it from this list."
188 :group 'message-headers
189 :type '(repeat sexp))
191 (defcustom message-required-mail-headers
192 '(From Subject Date (optional . In-Reply-To) Message-ID Lines
193 (optional . User-Agent))
194 "*Headers to be generated or prompted for when mailing a message.
195 It is recommended that From, Date, To, Subject and Message-ID be
196 included. Organization, Lines and User-Agent are optional."
198 :group 'message-headers
199 :type '(repeat sexp))
201 (defcustom message-deletable-headers '(Message-ID Date Lines)
202 "Headers to be deleted if they already exist and were generated by message previously."
203 :group 'message-headers
206 (defcustom message-ignored-news-headers
207 "^NNTP-Posting-Host:\\|^Xref:\\|^[BGF]cc:\\|^Resent-Fcc:\\|^X-Draft-From:"
208 "*Regexp of headers to be removed unconditionally before posting."
210 :group 'message-headers
213 (defcustom message-ignored-mail-headers
214 "^[GF]cc:\\|^Resent-Fcc:\\|^Xref:\\|^X-Draft-From:"
215 "*Regexp of headers to be removed unconditionally before mailing."
217 :group 'message-headers
220 (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:\\|^Cancel-Lock:\\|^Cancel-Key:"
221 "*Header lines matching this regexp will be deleted before posting.
222 It's best to delete old Path and Date headers before posting to avoid
224 :group 'message-interface
227 (defcustom message-subject-re-regexp "^[ \t]*\\([Rr][Ee]:[ \t]*\\)*[ \t]*"
228 "*Regexp matching \"Re: \" in the subject line."
229 :group 'message-various
233 (defcustom message-signature-separator "^-- *$"
234 "Regexp matching the signature separator."
236 :group 'message-various)
238 (defcustom message-elide-ellipsis "\n[...]\n\n"
239 "*The string which is inserted for elided text."
241 :group 'message-various)
243 (defcustom message-interactive nil
244 "Non-nil means when sending a message wait for and display errors.
245 nil means let mailer mail back a message to report errors."
246 :group 'message-sending
250 (defcustom message-generate-new-buffers 'unique
251 "*Non-nil means create a new message buffer whenever `message-setup' is called.
252 If this is a function, call that function with three parameters: The type,
253 the to address and the group name. (Any of these may be nil.) The function
254 should return the new buffer name."
255 :group 'message-buffers
256 :type '(choice (const :tag "off" nil)
257 (const :tag "unique" unique)
258 (const :tag "unsent" unsent)
261 (defcustom message-kill-buffer-on-exit nil
262 "*Non-nil means that the message buffer will be killed after sending a message."
263 :group 'message-buffers
267 (defvar gnus-local-organization))
268 (defcustom message-user-organization
269 (or (and (boundp 'gnus-local-organization)
270 (stringp gnus-local-organization)
271 gnus-local-organization)
272 (getenv "ORGANIZATION")
274 "*String to be used as an Organization header.
275 If t, use `message-user-organization-file'."
276 :group 'message-headers
277 :type '(choice string
278 (const :tag "consult file" t)))
281 (defcustom message-user-organization-file "/usr/lib/news/organization"
282 "*Local news organization file."
284 :group 'message-headers)
286 (defcustom message-make-forward-subject-function
287 'message-forward-subject-author-subject
288 "*List of functions called to generate subject headers for forwarded messages.
289 The subject generated by the previous function is passed into each
292 The provided functions are:
294 * `message-forward-subject-author-subject' (Source of article (author or
295 newsgroup)), in brackets followed by the subject
296 * `message-forward-subject-fwd' (Subject of article with 'Fwd:' prepended
298 :group 'message-forwarding
299 :type '(radio (function-item message-forward-subject-author-subject)
300 (function-item message-forward-subject-fwd)
301 (repeat :tag "List of functions" function)))
303 (defcustom message-forward-as-mime t
304 "*If non-nil, forward messages as an inline/rfc822 MIME section. Otherwise, directly inline the old message in the forwarded message."
306 :group 'message-forwarding
309 (defcustom message-forward-show-mml t
310 "*If non-nil, forward messages are shown as mml. Otherwise, forward messages are unchanged."
312 :group 'message-forwarding
315 (defcustom message-forward-before-signature t
316 "*If non-nil, put forwarded message before signature, else after."
317 :group 'message-forwarding
320 (defcustom message-wash-forwarded-subjects nil
321 "*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."
322 :group 'message-forwarding
325 (defcustom message-ignored-resent-headers "^Return-receipt\\|^X-Gnus\\|^Gnus-Warning:"
326 "*All headers that match this regexp will be deleted when resending a message."
327 :group 'message-interface
330 (defcustom message-forward-ignored-headers "^Content-Transfer-Encoding:\\|^X-Gnus"
331 "*All headers that match this regexp will be deleted when forwarding a message."
333 :group 'message-forwarding
334 :type '(choice (const :tag "None" nil)
337 (defcustom message-ignored-cited-headers "."
338 "*Delete these headers from the messages you yank."
339 :group 'message-insertion
342 (defcustom message-cite-prefix-regexp
343 (if (string-match "[[:digit:]]" "1") ;; support POSIX?
344 "\\([ \t]*[-_.[:word:]]+>+\\|[ \t]*[]>»|:}+]\\)+"
345 ;; ?-, ?_ or ?. MUST NOT be in syntax entry w.
346 "\\([ \t]*\\(\\w\\|[-_.]\\)+>+\\|[ \t]*[]>»|:}+]\\)+")
347 "*Regexp matching the longest possible citation prefix on a line."
348 :group 'message-insertion
351 (defcustom message-cancel-message "I am canceling my own article.\n"
352 "Message to be inserted in the cancel message."
353 :group 'message-interface
356 ;; Useful to set in site-init.el
358 (defcustom message-send-mail-function 'message-send-mail-with-sendmail
359 "Function to call to send the current buffer as mail.
360 The headers should be delimited by a line whose contents match the
361 variable `mail-header-separator'.
363 Valid values include `message-send-mail-with-sendmail' (the default),
364 `message-send-mail-with-mh', `message-send-mail-with-qmail',
365 `smtpmail-send-it' and `feedmail-send-it'.
367 See also `send-mail-function'."
368 :type '(radio (function-item message-send-mail-with-sendmail)
369 (function-item message-send-mail-with-mh)
370 (function-item message-send-mail-with-qmail)
371 (function-item smtpmail-send-it)
372 (function-item feedmail-send-it)
373 (function :tag "Other"))
374 :group 'message-sending
375 :group 'message-mail)
377 (defcustom message-send-news-function 'message-send-news
378 "Function to call to send the current buffer as news.
379 The headers should be delimited by a line whose contents match the
380 variable `mail-header-separator'."
381 :group 'message-sending
385 (defcustom message-reply-to-function nil
386 "If non-nil, function that should return a list of headers.
387 This function should pick out addresses from the To, Cc, and From headers
388 and respond with new To and Cc headers."
389 :group 'message-interface
390 :type '(choice function (const nil)))
392 (defcustom message-wide-reply-to-function nil
393 "If non-nil, function that should return a list of headers.
394 This function should pick out addresses from the To, Cc, and From headers
395 and respond with new To and Cc headers."
396 :group 'message-interface
397 :type '(choice function (const nil)))
399 (defcustom message-followup-to-function nil
400 "If non-nil, function that should return a list of headers.
401 This function should pick out addresses from the To, Cc, and From headers
402 and respond with new To and Cc headers."
403 :group 'message-interface
404 :type '(choice function (const nil)))
406 (defcustom message-use-followup-to 'ask
407 "*Specifies what to do with Followup-To header.
408 If nil, always ignore the header. If it is t, use its value, but
409 query before using the \"poster\" value. If it is the symbol `ask',
410 always query the user whether to use the value. If it is the symbol
411 `use', always use the value."
412 :group 'message-interface
413 :type '(choice (const :tag "ignore" nil)
414 (const :tag "use & query" t)
418 (defcustom message-use-mail-followup-to 'use
419 "*Specifies what to do with Mail-Followup-To header.
420 If nil, always ignore the header. If it is the symbol `ask', always
421 query the user whether to use the value. If it is the symbol `use',
422 always use the value."
423 :group 'message-interface
424 :type '(choice (const :tag "ignore" nil)
428 (defcustom message-subscribed-address-functions nil
429 "*Specifies functions for determining list subscription.
430 If nil, do not attempt to determine list subscribtion with functions.
431 If non-nil, this variable contains a list of functions which return
432 regular expressions to match lists. These functions can be used in
433 conjunction with `message-subscribed-regexps' and
434 `message-subscribed-addresses'."
435 :group 'message-interface
436 :type '(repeat sexp))
438 (defcustom message-subscribed-addresses nil
439 "*Specifies a list of addresses the user is subscribed to.
440 If nil, do not use any predefined list subscriptions. This list of
441 addresses can be used in conjuction with
442 `message-subscribed-address-functions' and `message-subscribed-regexps'."
443 :group 'message-interface
444 :type '(repeat string))
446 (defcustom message-subscribed-regexps nil
447 "*Specifies a list of addresses the user is subscribed to.
448 If nil, do not use any predefined list subscriptions. This list of
449 regular expressions can be used in conjuction with
450 `message-subscribed-address-functions' and `message-subscribed-addresses'."
451 :group 'message-interface
452 :type '(repeat regexp))
454 (defcustom message-sendmail-f-is-evil nil
455 "*Non-nil means don't add \"-f username\" to the sendmail command line.
456 Doing so would be even more evil than leaving it out."
457 :group 'message-sending
460 ;; qmail-related stuff
461 (defcustom message-qmail-inject-program "/var/qmail/bin/qmail-inject"
462 "Location of the qmail-inject program."
463 :group 'message-sending
466 (defcustom message-qmail-inject-args nil
467 "Arguments passed to qmail-inject programs.
468 This should be a list of strings, one string for each argument.
470 For e.g., if you wish to set the envelope sender address so that bounces
471 go to the right place or to deal with listserv's usage of that address, you
472 might set this variable to '(\"-f\" \"you@some.where\")."
473 :group 'message-sending
474 :type '(repeat string))
476 (defvar message-cater-to-broken-inn t
477 "Non-nil means Gnus should not fold the `References' header.
478 Folding `References' makes ancient versions of INN create incorrect
482 (defvar gnus-post-method)
483 (defvar gnus-select-method))
484 (defcustom message-post-method
485 (cond ((and (boundp 'gnus-post-method)
486 (listp gnus-post-method)
489 ((boundp 'gnus-select-method)
492 "*Method used to post news.
493 Note that when posting from inside Gnus, for instance, this
494 variable isn't used."
496 :group 'message-sending
497 ;; This should be the `gnus-select-method' widget, but that might
498 ;; create a dependence to `gnus.el'.
501 (defcustom message-generate-headers-first nil
502 "*If non-nil, generate all required headers before composing.
503 The variables `message-required-news-headers' and
504 `message-required-mail-headers' specify which headers to generate.
506 Note that the variable `message-deletable-headers' specifies headers which
507 are to be deleted and then re-generated before sending, so this variable
508 will not have a visible effect for those headers."
509 :group 'message-headers
512 (defcustom message-setup-hook nil
513 "Normal hook, run each time a new outgoing message is initialized.
514 The function `message-setup' runs this hook."
515 :group 'message-various
518 (defcustom message-cancel-hook nil
519 "Hook run when cancelling articles."
520 :group 'message-various
523 (defcustom message-signature-setup-hook nil
524 "Normal hook, run each time a new outgoing message is initialized.
525 It is run after the headers have been inserted and before
526 the signature is inserted."
527 :group 'message-various
530 (defcustom message-mode-hook nil
531 "Hook run in message mode buffers."
532 :group 'message-various
535 (defcustom message-header-hook nil
536 "Hook run in a message mode buffer narrowed to the headers."
537 :group 'message-various
540 (defcustom message-header-setup-hook nil
541 "Hook called narrowed to the headers when setting up a message buffer."
542 :group 'message-various
545 (defcustom message-minibuffer-local-map
546 (let ((map (make-sparse-keymap 'message-minibuffer-local-map)))
547 (set-keymap-parent map minibuffer-local-map)
549 "Keymap for `message-read-from-minibuffer'.")
552 (defcustom message-citation-line-function 'message-insert-citation-line
553 "*Function called to insert the \"Whomever writes:\" line.
555 Note that Gnus provides a feature where the reader can click on
556 `writes:' to hide the cited text. If you change this line too much,
557 people who read your message will have to change their Gnus
558 configuration. See the variable `gnus-cite-attribution-suffix'."
560 :group 'message-insertion)
563 (defcustom message-yank-prefix "> "
564 "*Prefix inserted on the lines of yanked messages.
565 Fix `message-cite-prefix-regexp' if it is set to an abnormal value.
566 See also `message-yank-cited-prefix'."
568 :group 'message-insertion)
570 (defcustom message-yank-cited-prefix ">"
571 "*Prefix inserted on cited or empty lines of yanked messages.
572 Fix `message-cite-prefix-regexp' if it is set to an abnormal value.
573 See also `message-yank-prefix'."
575 :group 'message-insertion)
577 (defcustom message-indentation-spaces 3
578 "*Number of spaces to insert at the beginning of each cited line.
579 Used by `message-yank-original' via `message-yank-cite'."
580 :group 'message-insertion
584 (defcustom message-cite-function 'message-cite-original
585 "*Function for citing an original message.
586 Predefined functions include `message-cite-original' and
587 `message-cite-original-without-signature'.
588 Note that `message-cite-original' uses `mail-citation-hook' if that is non-nil."
589 :type '(radio (function-item message-cite-original)
590 (function-item message-cite-original-without-signature)
591 (function-item sc-cite-original)
592 (function :tag "Other"))
593 :group 'message-insertion)
596 (defcustom message-indent-citation-function 'message-indent-citation
597 "*Function for modifying a citation just inserted in the mail buffer.
598 This can also be a list of functions. Each function can find the
599 citation between (point) and (mark t). And each function should leave
600 point and mark around the citation text as modified."
602 :group 'message-insertion)
604 (defvar message-abbrevs-loaded nil)
607 (defcustom message-signature t
608 "*String to be inserted at the end of the message buffer.
609 If t, the `message-signature-file' file will be inserted instead.
610 If a function, the result from the function will be used instead.
611 If a form, the result from the form will be used instead."
613 :group 'message-insertion)
616 (defcustom message-signature-file "~/.signature"
617 "*Name of file containing the text inserted at end of message buffer.
618 Ignored if the named file doesn't exist.
619 If nil, don't insert a signature."
620 :type '(choice file (const :tags "None" nil))
621 :group 'message-insertion)
623 (defcustom message-distribution-function nil
624 "*Function called to return a Distribution header."
626 :group 'message-headers
627 :type '(choice function (const nil)))
629 (defcustom message-expires 14
630 "Number of days before your article expires."
632 :group 'message-headers
633 :link '(custom-manual "(message)News Headers")
636 (defcustom message-user-path nil
637 "If nil, use the NNTP server name in the Path header.
638 If stringp, use this; if non-nil, use no host name (user name only)."
640 :group 'message-headers
641 :link '(custom-manual "(message)News Headers")
642 :type '(choice (const :tag "nntp" nil)
644 (sexp :tag "none" :format "%t" t)))
646 (defvar message-reply-buffer nil)
647 (defvar message-reply-headers nil)
648 (defvar message-newsreader nil)
649 (defvar message-mailer nil)
650 (defvar message-sent-message-via nil)
651 (defvar message-checksum nil)
652 (defvar message-send-actions nil
653 "A list of actions to be performed upon successful sending of a message.")
654 (defvar message-exit-actions nil
655 "A list of actions to be performed upon exiting after sending a message.")
656 (defvar message-kill-actions nil
657 "A list of actions to be performed before killing a message buffer.")
658 (defvar message-postpone-actions nil
659 "A list of actions to be performed after postponing a message.")
661 (define-widget 'message-header-lines 'text
662 "All header lines must be LFD terminated."
663 :format "%{%t%}:%n%v"
665 :error "All header lines must be newline terminated")
667 (defcustom message-default-headers ""
668 "*A string containing header lines to be inserted in outgoing messages.
669 It is inserted before you edit the message, so you can edit or delete
671 :group 'message-headers
672 :type 'message-header-lines)
674 (defcustom message-default-mail-headers ""
675 "*A string of header lines to be inserted in outgoing mails."
676 :group 'message-headers
678 :type 'message-header-lines)
680 (defcustom message-default-news-headers ""
681 "*A string of header lines to be inserted in outgoing news articles."
682 :group 'message-headers
684 :type 'message-header-lines)
686 ;; Note: could use /usr/ucb/mail instead of sendmail;
687 ;; options -t, and -v if not interactive.
688 (defcustom message-mailer-swallows-blank-line
689 (if (and (string-match "sparc-sun-sunos\\(\\'\\|[^5]\\)"
690 system-configuration)
691 (file-readable-p "/etc/sendmail.cf")
692 (let ((buffer (get-buffer-create " *temp*")))
696 (insert-file-contents "/etc/sendmail.cf")
697 (goto-char (point-min))
698 (let ((case-fold-search nil))
699 (re-search-forward "^OR\\>" nil t)))
700 (kill-buffer buffer))))
701 ;; According to RFC822, "The field-name must be composed of printable
702 ;; ASCII characters (i. e., characters that have decimal values between
703 ;; 33 and 126, except colon)", i. e., any chars except ctl chars,
705 '(looking-at "[ \t]\\|[][!\"#$%&'()*+,-./0-9;<=>?@A-Z\\\\^_`a-z{|}~]+:"))
706 "*Set this non-nil if the system's mailer runs the header and body together.
707 \(This problem exists on Sunos 4 when sendmail is run in remote mode.)
708 The value should be an expression to test whether the problem will
710 :group 'message-sending
714 (define-mail-user-agent 'message-user-agent
715 'message-mail 'message-send-and-exit
716 'message-kill-buffer 'message-send-hook)
718 (defvar message-mh-deletable-headers '(Message-ID Date Lines Sender)
719 "If non-nil, delete the deletable headers before feeding to mh.")
721 (defvar message-send-method-alist
722 '((news message-news-p message-send-via-news)
723 (mail message-mail-p message-send-via-mail))
724 "Alist of ways to send outgoing messages.
725 Each element has the form
727 \(TYPE PREDICATE FUNCTION)
729 where TYPE is a symbol that names the method; PREDICATE is a function
730 called without any parameters to determine whether the message is
731 a message of type TYPE; and FUNCTION is a function to be called if
732 PREDICATE returns non-nil. FUNCTION is called with one parameter --
735 (defcustom message-mail-alias-type 'abbrev
736 "*What alias expansion type to use in Message buffers.
737 The default is `abbrev', which uses mailabbrev. nil switches
740 :link '(custom-manual "(message)Mail Aliases")
741 :type '(choice (const :tag "Use Mailabbrev" abbrev)
742 (const :tag "No expansion" nil)))
744 (defcustom message-auto-save-directory
745 (file-name-as-directory (nnheader-concat message-directory "drafts"))
746 "*Directory where Message auto-saves buffers if Gnus isn't running.
747 If nil, Message won't auto-save."
748 :group 'message-buffers
749 :type '(choice directory (const :tag "Don't auto-save" nil)))
751 (defcustom message-buffer-naming-style 'unique
752 "*The way new message buffers are named.
753 Valid valued are `unique' and `unsent'."
755 :group 'message-buffers
756 :type '(choice (const :tag "unique" unique)
757 (const :tag "unsent" unsent)))
759 (defcustom message-default-charset
760 (and (not (mm-multibyte-p)) 'iso-8859-1)
761 "Default charset used in non-MULE Emacsen.
762 If nil, you might be asked to input the charset."
767 (defcustom message-dont-reply-to-names
768 (and (boundp 'rmail-dont-reply-to-names) rmail-dont-reply-to-names)
769 "*A regexp specifying addresses to prune when doing wide replies.
770 A value of nil means exclude your own user name only."
773 :type '(choice (const :tag "Yourself" nil)
776 (defvar message-shoot-gnksa-feet nil
777 "*A list of GNKSA feet you are allowed to shoot.
778 Gnus gives you all the opportunity you could possibly want for
779 shooting yourself in the foot. Also, Gnus allows you to shoot the
780 feet of Good Net-Keeping Seal of Approval. The following are foot
782 `empty-article' Allow you to post an empty article;
783 `quoted-text-only' Allow you to post quoted text only;
784 `multiple-copies' Allow you to post multiple copies.")
785 ;; `cancel-messages' Allow you to cancel or supersede others' messages.
787 (defsubst message-gnksa-enable-p (feature)
788 (or (not (listp message-shoot-gnksa-feet))
789 (memq feature message-shoot-gnksa-feet)))
791 ;;; Internal variables.
792 ;;; Well, not really internal.
794 (defvar message-mode-syntax-table
795 (let ((table (copy-syntax-table text-mode-syntax-table)))
796 (modify-syntax-entry ?% ". " table)
797 (modify-syntax-entry ?> ". " table)
798 (modify-syntax-entry ?< ". " table)
800 "Syntax table used while in Message mode.")
802 (defface message-header-to-face
805 (:foreground "green2" :bold t))
808 (:foreground "MidnightBlue" :bold t))
810 (:bold t :italic t)))
811 "Face used for displaying From headers."
812 :group 'message-faces)
814 (defface message-header-cc-face
817 (:foreground "green4" :bold t))
820 (:foreground "MidnightBlue"))
823 "Face used for displaying Cc headers."
824 :group 'message-faces)
826 (defface message-header-subject-face
829 (:foreground "green3"))
832 (:foreground "navy blue" :bold t))
835 "Face used for displaying subject headers."
836 :group 'message-faces)
838 (defface message-header-newsgroups-face
841 (:foreground "yellow" :bold t :italic t))
844 (:foreground "blue4" :bold t :italic t))
846 (:bold t :italic t)))
847 "Face used for displaying newsgroups headers."
848 :group 'message-faces)
850 (defface message-header-other-face
853 (:foreground "#b00000"))
856 (:foreground "steel blue"))
858 (:bold t :italic t)))
859 "Face used for displaying newsgroups headers."
860 :group 'message-faces)
862 (defface message-header-name-face
865 (:foreground "DarkGreen"))
868 (:foreground "cornflower blue"))
871 "Face used for displaying header names."
872 :group 'message-faces)
874 (defface message-header-xheader-face
877 (:foreground "blue"))
880 (:foreground "blue"))
883 "Face used for displaying X-Header headers."
884 :group 'message-faces)
886 (defface message-separator-face
889 (:foreground "blue3"))
892 (:foreground "brown"))
895 "Face used for displaying the separator."
896 :group 'message-faces)
898 (defface message-cited-text-face
907 "Face used for displaying cited text names."
908 :group 'message-faces)
910 (defface message-mml-face
913 (:foreground "ForestGreen"))
916 (:foreground "ForestGreen"))
919 "Face used for displaying MML."
920 :group 'message-faces)
922 (defvar message-font-lock-keywords
923 (let ((content "[ \t]*\\(.+\\(\n[ \t].*\\)*\\)\n?"))
924 `((,(concat "^\\([Tt]o:\\)" content)
925 (1 'message-header-name-face)
926 (2 'message-header-to-face nil t))
927 (,(concat "^\\(^[GBF]?[Cc][Cc]:\\|^[Rr]eply-[Tt]o:\\)" content)
928 (1 'message-header-name-face)
929 (2 'message-header-cc-face nil t))
930 (,(concat "^\\([Ss]ubject:\\)" content)
931 (1 'message-header-name-face)
932 (2 'message-header-subject-face nil t))
933 (,(concat "^\\([Nn]ewsgroups:\\|Followup-[Tt]o:\\)" content)
934 (1 'message-header-name-face)
935 (2 'message-header-newsgroups-face nil t))
936 (,(concat "^\\([A-Z][^: \n\t]+:\\)" content)
937 (1 'message-header-name-face)
938 (2 'message-header-other-face nil t))
939 (,(concat "^\\(X-[A-Za-z0-9-]+\\|In-Reply-To\\):" content)
940 (1 'message-header-name-face)
941 (2 'message-header-name-face))
942 ,@(if (and mail-header-separator
943 (not (equal mail-header-separator "")))
944 `((,(concat "^\\(" (regexp-quote mail-header-separator) "\\)$")
945 1 'message-separator-face))
947 (,(concat "^\\(" message-cite-prefix-regexp "\\).*")
948 (0 'message-cited-text-face))
949 ("<#/?\\(multipart\\|part\\|external\\|mml\\).*>"
950 (0 'message-mml-face))))
951 "Additional expressions to highlight in Message mode.")
953 ;; XEmacs does it like this. For Emacs, we have to set the
954 ;; `font-lock-defaults' buffer-local variable.
955 (put 'message-mode 'font-lock-defaults '(message-font-lock-keywords t))
957 (defvar message-face-alist
958 '((bold . bold-region)
959 (underline . underline-region)
960 (default . (lambda (b e)
962 (ununderline-region b e))))
963 "Alist of mail and news faces for facemenu.
964 The cdr of ech entry is a function for applying the face to a region.")
966 (defcustom message-send-hook nil
967 "Hook run before sending messages."
968 :group 'message-various
969 :options '(ispell-message)
972 (defcustom message-send-mail-hook nil
973 "Hook run before sending mail messages."
974 :group 'message-various
977 (defcustom message-send-news-hook nil
978 "Hook run before sending news messages."
979 :group 'message-various
982 (defcustom message-sent-hook nil
983 "Hook run after sending messages."
984 :group 'message-various
987 (defvar message-send-coding-system 'binary
988 "Coding system to encode outgoing mail.")
990 (defvar message-draft-coding-system
991 mm-auto-save-coding-system
992 "Coding system to compose mail.")
994 (defcustom message-send-mail-partially-limit 1000000
995 "The limitation of messages sent as message/partial.
996 The lower bound of message size in characters, beyond which the message
997 should be sent in several parts. If it is nil, the size is unlimited."
999 :group 'message-buffers
1000 :type '(choice (const :tag "unlimited" nil)
1003 (defcustom message-alternative-emails nil
1004 "A regexp to match the alternative email addresses.
1005 The first matched address (not primary one) is used in the From field."
1006 :group 'message-headers
1007 :type '(choice (const :tag "Always use primary" nil)
1010 (defcustom message-mail-user-agent nil
1011 "Like `mail-user-agent'.
1012 Except if it is nil, use Gnus native MUA; if it is t, use
1014 :type '(radio (const :tag "Gnus native"
1017 (const :tag "`mail-user-agent'"
1020 (function-item :tag "Default Emacs mail"
1022 sendmail-user-agent)
1023 (function-item :tag "Emacs interface to MH"
1026 (function :tag "Other"))
1030 (defcustom message-wide-reply-confirm-recipients nil
1031 "Whether to confirm a wide reply to multiple email recipients.
1032 If this variable is nil, don't ask whether to reply to all recipients.
1033 If this variable is non-nil, pose the question \"Reply to all
1034 recipients?\" before a wide reply to multiple recipients. If the user
1035 answers yes, reply to all recipients as usual. If the user answers
1036 no, only reply back to the author."
1037 :group 'message-headers
1040 (defcustom message-insert-canlock t
1041 "Whether to insert a Cancel-Lock header in news postings."
1042 :group 'message-headers
1045 ;;; Internal variables.
1047 (defvar message-sending-message "Sending...")
1048 (defvar message-buffer-list nil)
1049 (defvar message-this-is-news nil)
1050 (defvar message-this-is-mail nil)
1051 (defvar message-draft-article nil)
1052 (defvar message-mime-part nil)
1053 (defvar message-posting-charset nil)
1055 ;; Byte-compiler warning
1057 (defvar gnus-active-hashtb)
1058 (defvar gnus-read-active-file))
1060 ;;; Regexp matching the delimiter of messages in UNIX mail format
1061 ;;; (UNIX From lines), minus the initial ^. It should be a copy
1062 ;;; of rmail.el's rmail-unix-mail-delimiter.
1063 (defvar message-unix-mail-delimiter
1064 (let ((time-zone-regexp
1065 (concat "\\([A-Z]?[A-Z]?[A-Z][A-Z]\\( DST\\)?"
1066 "\\|[-+]?[0-9][0-9][0-9][0-9]"
1072 ;; Many things can happen to an RFC 822 mailbox before it is put into
1073 ;; a `From' line. The leading phrase can be stripped, e.g.
1074 ;; `Joe <@w.x:joe@y.z>' -> `<@w.x:joe@y.z>'. The <> can be stripped, e.g.
1075 ;; `<@x.y:joe@y.z>' -> `@x.y:joe@y.z'. Everything starting with a CRLF
1076 ;; can be removed, e.g.
1077 ;; From: joe@y.z (Joe K
1079 ;; can yield `From joe@y.z (Joe K Fri Mar 22 08:11:15 1996', and
1082 ;; can yield `From Joe User Fri Mar 22 08:11:15 1996'.
1083 ;; The mailbox can be removed or be replaced by white space, e.g.
1084 ;; From: "Joe User"{space}{tab}
1086 ;; can yield `From {space}{tab} Fri Mar 22 08:11:15 1996',
1087 ;; where {space} and {tab} represent the Ascii space and tab characters.
1088 ;; We want to match the results of any of these manglings.
1089 ;; The following regexp rejects names whose first characters are
1090 ;; obviously bogus, but after that anything goes.
1091 "\\([^\0-\b\n-\r\^?].*\\)? "
1093 ;; The time the message was sent.
1094 "\\([^\0-\r \^?]+\\) +" ; day of the week
1095 "\\([^\0-\r \^?]+\\) +" ; month
1096 "\\([0-3]?[0-9]\\) +" ; day of month
1097 "\\([0-2][0-9]:[0-5][0-9]\\(:[0-6][0-9]\\)?\\) *" ; time of day
1099 ;; Perhaps a time zone, specified by an abbreviation, or by a
1104 " \\([0-9][0-9]+\\) *"
1106 ;; On some systems the time zone can appear after the year, too.
1110 "\\(remote from .*\\)?"
1113 "Regexp matching the delimiter of messages in UNIX mail format.")
1115 (defvar message-unsent-separator
1116 (concat "^ *---+ +Unsent message follows +---+ *$\\|"
1117 "^ *---+ +Returned message +---+ *$\\|"
1118 "^Start of returned message$\\|"
1119 "^ *---+ +Original message +---+ *$\\|"
1120 "^ *--+ +begin message +--+ *$\\|"
1121 "^ *---+ +Original message follows +---+ *$\\|"
1122 "^ *---+ +Undelivered message follows +---+ *$\\|"
1123 "^|? *---+ +Message text follows: +---+ *|?$")
1124 "A regexp that matches the separator before the text of a failed message.")
1126 (defvar message-header-format-alist
1128 (To . message-fill-address)
1129 (Cc . message-fill-address)
1140 (References . message-shorten-references)
1142 "Alist used for formatting headers.")
1144 (defvar message-options nil
1145 "Some saved answers when sending message.")
1147 (defvar message-send-mail-real-function nil
1148 "Internal send mail function.")
1150 (defvar message-bogus-system-names "^localhost\\."
1151 "The regexp of bogus system names.")
1154 (autoload 'message-setup-toolbar "messagexmas")
1155 (autoload 'mh-new-draft-name "mh-comp")
1156 (autoload 'mh-send-letter "mh-comp")
1157 (autoload 'gnus-point-at-eol "gnus-util")
1158 (autoload 'gnus-point-at-bol "gnus-util")
1159 (autoload 'gnus-output-to-rmail "gnus-util")
1160 (autoload 'gnus-output-to-mail "gnus-util")
1161 (autoload 'mail-abbrev-in-expansion-header-p "mailabbrev")
1162 (autoload 'nndraft-request-associate-buffer "nndraft")
1163 (autoload 'nndraft-request-expire-articles "nndraft")
1164 (autoload 'gnus-open-server "gnus-int")
1165 (autoload 'gnus-request-post "gnus-int")
1166 (autoload 'gnus-alive-p "gnus-util")
1167 (autoload 'gnus-server-string "gnus")
1168 (autoload 'gnus-group-name-charset "gnus-group")
1169 (autoload 'gnus-group-name-decode "gnus-group")
1170 (autoload 'gnus-groups-from-server "gnus")
1171 (autoload 'rmail-output "rmailout"))
1176 ;;; Utility functions.
1179 (defmacro message-y-or-n-p (question show &rest text)
1180 "Ask QUESTION, displaying remaining args in a temporary buffer if SHOW."
1181 `(message-talkative-question 'y-or-n-p ,question ,show ,@text))
1183 (defmacro message-delete-line (&optional n)
1184 "Delete the current line (and the next N lines)."
1185 `(delete-region (progn (beginning-of-line) (point))
1186 (progn (forward-line ,(or n 1)) (point))))
1188 (defun message-unquote-tokens (elems)
1189 "Remove double quotes (\") from strings in list ELEMS."
1190 (mapcar (lambda (item)
1191 (while (string-match "^\\(.*\\)\"\\(.*\\)$" item)
1192 (setq item (concat (match-string 1 item)
1193 (match-string 2 item))))
1197 (defun message-tokenize-header (header &optional separator)
1198 "Split HEADER into a list of header elements.
1199 SEPARATOR is a string of characters to be used as separators. \",\"
1200 is used by default."
1203 (let ((regexp (format "[%s]+" (or separator ",")))
1208 (message-set-work-buffer)
1210 (goto-char (point-min))
1215 (cond ((and (> (point) beg)
1217 (and (looking-at regexp)
1220 (push (buffer-substring beg (point)) elems)
1221 (setq beg (match-end 0)))
1222 ((eq (char-after) ?\")
1223 (setq quoted (not quoted)))
1224 ((and (eq (char-after) ?\()
1227 ((and (eq (char-after) ?\))
1230 (nreverse elems)))))
1232 (defun message-mail-file-mbox-p (file)
1233 "Say whether FILE looks like a Unix mbox file."
1234 (when (and (file-exists-p file)
1235 (file-readable-p file)
1236 (file-regular-p file))
1238 (nnheader-insert-file-contents file)
1239 (goto-char (point-min))
1240 (looking-at message-unix-mail-delimiter))))
1242 (defun message-fetch-field (header &optional not-all)
1243 "The same as `mail-fetch-field', only remove all newlines."
1244 (let* ((inhibit-point-motion-hooks t)
1245 (case-fold-search t)
1246 (value (mail-fetch-field header nil (not not-all))))
1248 (while (string-match "\n[\t ]+" value)
1249 (setq value (replace-match " " t t value)))
1250 (set-text-properties 0 (length value) nil value)
1253 (defun message-narrow-to-field ()
1254 "Narrow the buffer to the header on the current line."
1260 (if (re-search-forward "^[^ \n\t]" nil t)
1265 (goto-char (point-min)))
1267 (defun message-add-header (&rest headers)
1268 "Add the HEADERS to the message header, skipping those already present."
1271 (unless (string-match "^\\([^:]+\\):[ \t]*[^ \t]" (car headers))
1272 (error "Invalid header `%s'" (car headers)))
1273 (setq hclean (match-string 1 (car headers)))
1275 (message-narrow-to-headers)
1276 (unless (re-search-forward (concat "^" (regexp-quote hclean) ":") nil t)
1277 (goto-char (point-max))
1278 (if (string-match "\n$" (car headers))
1279 (insert (car headers))
1280 (insert (car headers) ?\n)))))
1281 (setq headers (cdr headers))))
1284 (defun message-fetch-reply-field (header)
1285 "Fetch field HEADER from the message we're replying to."
1286 (when (and message-reply-buffer
1287 (buffer-name message-reply-buffer))
1289 (set-buffer message-reply-buffer)
1290 (message-fetch-field header))))
1292 (defun message-set-work-buffer ()
1293 (if (get-buffer " *message work*")
1295 (set-buffer " *message work*")
1297 (set-buffer (get-buffer-create " *message work*"))
1298 (kill-all-local-variables)
1299 (mm-enable-multibyte)))
1301 (defun message-functionp (form)
1302 "Return non-nil if FORM is funcallable."
1303 (or (and (symbolp form) (fboundp form))
1304 (and (listp form) (eq (car form) 'lambda))
1305 (byte-code-function-p form)))
1307 (defun message-strip-list-identifiers (subject)
1308 "Remove list identifiers in `gnus-list-identifiers' from string SUBJECT."
1309 (require 'gnus-sum) ; for gnus-list-identifiers
1310 (let ((regexp (if (stringp gnus-list-identifiers)
1311 gnus-list-identifiers
1312 (mapconcat 'identity gnus-list-identifiers " *\\|"))))
1313 (if (string-match (concat "\\(\\(\\(Re: +\\)?\\(" regexp
1314 " *\\)\\)+\\(Re: +\\)?\\)") subject)
1315 (concat (substring subject 0 (match-beginning 1))
1316 (or (match-string 3 subject)
1317 (match-string 5 subject))
1322 (defun message-strip-subject-re (subject)
1323 "Remove \"Re:\" from subject lines in string SUBJECT."
1324 (if (string-match message-subject-re-regexp subject)
1325 (substring subject (match-end 0))
1328 (defun message-remove-header (header &optional is-regexp first reverse)
1329 "Remove HEADER in the narrowed buffer.
1330 If IS-REGEXP, HEADER is a regular expression.
1331 If FIRST, only remove the first instance of the header.
1332 Return the number of headers removed."
1333 (goto-char (point-min))
1334 (let ((regexp (if is-regexp header (concat "^" (regexp-quote header) ":")))
1336 (case-fold-search t)
1338 (while (and (not (eobp))
1341 (not (looking-at regexp))
1342 (looking-at regexp))
1349 ;; There might be a continuation header, so we have to search
1350 ;; until we find a new non-continuation line.
1353 (if (re-search-forward "^[^ \t]" nil t)
1354 (goto-char (match-beginning 0))
1357 (if (re-search-forward "^[^ \t]" nil t)
1358 (goto-char (match-beginning 0))
1359 (goto-char (point-max)))))
1362 (defun message-remove-first-header (header)
1363 "Remove the first instance of HEADER if there is more than one."
1365 (regexp (concat "^" (regexp-quote header) ":")))
1367 (goto-char (point-min))
1368 (while (re-search-forward regexp nil t)
1371 (message-remove-header header nil t)
1374 (defun message-narrow-to-headers ()
1375 "Narrow the buffer to the head of the message."
1378 (goto-char (point-min))
1379 (if (re-search-forward
1380 (concat "^" (regexp-quote mail-header-separator) "\n") nil t)
1383 (goto-char (point-min)))
1385 (defun message-narrow-to-head-1 ()
1386 "Like `message-narrow-to-head'. Don't widen."
1388 (goto-char (point-min))
1389 (if (search-forward "\n\n" nil 1)
1392 (goto-char (point-min)))
1394 (defun message-narrow-to-head ()
1395 "Narrow the buffer to the head of the message.
1396 Point is left at the beginning of the narrowed-to region."
1398 (message-narrow-to-head-1))
1400 (defun message-narrow-to-headers-or-head ()
1401 "Narrow the buffer to the head of the message."
1404 (goto-char (point-min))
1407 (concat "^" (regexp-quote mail-header-separator) "\n") nil t)
1408 (match-beginning 0))
1409 ((search-forward "\n\n" nil t)
1413 (goto-char (point-min)))
1415 (defun message-news-p ()
1416 "Say whether the current buffer contains a news message."
1417 (and (not message-this-is-mail)
1418 (or message-this-is-news
1421 (message-narrow-to-headers)
1422 (and (message-fetch-field "newsgroups")
1423 (not (message-fetch-field "posted-to"))))))))
1425 (defun message-mail-p ()
1426 "Say whether the current buffer contains a mail message."
1427 (and (not message-this-is-news)
1428 (or message-this-is-mail
1431 (message-narrow-to-headers)
1432 (or (message-fetch-field "to")
1433 (message-fetch-field "cc")
1434 (message-fetch-field "bcc")))))))
1436 (defun message-next-header ()
1437 "Go to the beginning of the next header."
1439 (or (eobp) (forward-char 1))
1440 (not (if (re-search-forward "^[^ \t]" nil t)
1442 (goto-char (point-max)))))
1444 (defun message-sort-headers-1 ()
1445 "Sort the buffer as headers using `message-rank' text props."
1446 (goto-char (point-min))
1449 nil 'message-next-header
1451 (message-next-header)
1455 (or (get-text-property (point) 'message-rank)
1458 (defun message-sort-headers ()
1459 "Sort the headers of the current message according to `message-header-format-alist'."
1463 (let ((max (1+ (length message-header-format-alist)))
1465 (message-narrow-to-headers)
1466 (while (re-search-forward "^[^ \n]+:" nil t)
1468 (match-beginning 0) (1+ (match-beginning 0))
1470 (if (setq rank (length (memq (assq (intern (buffer-substring
1472 (1- (match-end 0))))
1473 message-header-format-alist)
1474 message-header-format-alist)))
1477 (message-sort-headers-1))))
1487 (defvar message-mode-map nil)
1489 (unless message-mode-map
1490 (setq message-mode-map (make-keymap))
1491 (set-keymap-parent message-mode-map text-mode-map)
1492 (define-key message-mode-map "\C-c?" 'describe-mode)
1494 (define-key message-mode-map "\C-c\C-f\C-t" 'message-goto-to)
1495 (define-key message-mode-map "\C-c\C-f\C-b" 'message-goto-bcc)
1496 (define-key message-mode-map "\C-c\C-f\C-w" 'message-goto-fcc)
1497 (define-key message-mode-map "\C-c\C-f\C-c" 'message-goto-cc)
1498 (define-key message-mode-map "\C-c\C-f\C-s" 'message-goto-subject)
1499 (define-key message-mode-map "\C-c\C-f\C-r" 'message-goto-reply-to)
1500 (define-key message-mode-map "\C-c\C-f\C-n" 'message-goto-newsgroups)
1501 (define-key message-mode-map "\C-c\C-f\C-d" 'message-goto-distribution)
1502 (define-key message-mode-map "\C-c\C-f\C-f" 'message-goto-followup-to)
1503 (define-key message-mode-map "\C-c\C-f\C-m" 'message-goto-mail-followup-to)
1504 (define-key message-mode-map "\C-c\C-f\C-k" 'message-goto-keywords)
1505 (define-key message-mode-map "\C-c\C-f\C-u" 'message-goto-summary)
1506 (define-key message-mode-map "\C-c\C-b" 'message-goto-body)
1507 (define-key message-mode-map "\C-c\C-i" 'message-goto-signature)
1509 (define-key message-mode-map "\C-c\C-t" 'message-insert-to)
1510 (define-key message-mode-map "\C-c\C-n" 'message-insert-newsgroups)
1512 (define-key message-mode-map "\C-c\C-y" 'message-yank-original)
1513 (define-key message-mode-map "\C-c\M-\C-y" 'message-yank-buffer)
1514 (define-key message-mode-map "\C-c\C-q" 'message-fill-yanked-message)
1515 (define-key message-mode-map "\C-c\C-w" 'message-insert-signature)
1516 (define-key message-mode-map "\C-c\M-h" 'message-insert-headers)
1517 (define-key message-mode-map "\C-c\C-r" 'message-caesar-buffer-body)
1518 (define-key message-mode-map "\C-c\C-o" 'message-sort-headers)
1519 (define-key message-mode-map "\C-c\M-r" 'message-rename-buffer)
1521 (define-key message-mode-map "\C-c\C-c" 'message-send-and-exit)
1522 (define-key message-mode-map "\C-c\C-s" 'message-send)
1523 (define-key message-mode-map "\C-c\C-k" 'message-kill-buffer)
1524 (define-key message-mode-map "\C-c\C-d" 'message-dont-send)
1525 (define-key message-mode-map "\C-c\n" 'gnus-delay-article)
1527 (define-key message-mode-map "\C-c\C-e" 'message-elide-region)
1528 (define-key message-mode-map "\C-c\C-v" 'message-delete-not-region)
1529 (define-key message-mode-map "\C-c\C-z" 'message-kill-to-signature)
1530 (define-key message-mode-map "\M-\r" 'message-newline-and-reformat)
1531 ;;(define-key message-mode-map "\M-q" 'message-fill-paragraph)
1533 (define-key message-mode-map "\C-c\C-a" 'mml-attach-file)
1535 (define-key message-mode-map "\t" 'message-tab)
1536 (define-key message-mode-map "\M-;" 'comment-region))
1539 message-mode-menu message-mode-map "Message Menu."
1541 ["Sort Headers" message-sort-headers t]
1542 ["Yank Original" message-yank-original t]
1543 ["Fill Yanked Message" message-fill-yanked-message t]
1544 ["Insert Signature" message-insert-signature t]
1545 ["Caesar (rot13) Message" message-caesar-buffer-body t]
1546 ["Caesar (rot13) Region" message-caesar-region (mark t)]
1547 ["Elide Region" message-elide-region (mark t)]
1548 ["Delete Outside Region" message-delete-not-region (mark t)]
1549 ["Kill To Signature" message-kill-to-signature t]
1550 ["Newline and Reformat" message-newline-and-reformat t]
1551 ["Rename buffer" message-rename-buffer t]
1552 ["Spellcheck" ispell-message
1553 ,@(if (featurep 'xemacs) '(t)
1554 '(:help "Spellcheck this message"))]
1556 ["Send Message" message-send-and-exit
1557 ,@(if (featurep 'xemacs) '(t)
1558 '(:help "Send this message"))]
1559 ["Postpone Message" message-dont-send
1560 ,@(if (featurep 'xemacs) '(t)
1561 '(:help "File this draft message and exit"))]
1562 ["Send at Specific Time" gnus-delay-article
1563 ,@(if (featurep 'xemacs) '(t)
1564 '(:help "Ask, then arrange to send message at that time"))]
1565 ["Kill Message" message-kill-buffer
1566 ,@(if (featurep 'xemacs) '(t)
1567 '(:help "Delete this message without sending"))]))
1570 message-mode-field-menu message-mode-map ""
1572 ["Fetch To" message-insert-to t]
1573 ["Fetch Newsgroups" message-insert-newsgroups t]
1575 ["To" message-goto-to t]
1576 ["Subject" message-goto-subject t]
1577 ["Cc" message-goto-cc t]
1578 ["Reply-To" message-goto-reply-to t]
1579 ["Summary" message-goto-summary t]
1580 ["Keywords" message-goto-keywords t]
1581 ["Newsgroups" message-goto-newsgroups t]
1582 ["Followup-To" message-goto-followup-to t]
1583 ["Mail-Followup-To" message-goto-mail-followup-to t]
1584 ["Distribution" message-goto-distribution t]
1585 ["Body" message-goto-body t]
1586 ["Signature" message-goto-signature t]))
1588 (defvar message-tool-bar-map nil)
1591 (defvar facemenu-add-face-function)
1592 (defvar facemenu-remove-face-function))
1594 ;;; Forbidden properties
1596 ;; We use `after-change-functions' to keep special text properties
1597 ;; that interfer with the normal function of message mode out of the
1600 (defconst message-forbidden-properties
1601 ;; No reason this should be clutter up customize. We make it a
1602 ;; property list (rather than a list of property symbols), to be
1603 ;; directly useful for `remove-text-properties'.
1604 '(field nil read-only nil intangible nil invisible nil
1605 mouse-face nil modification-hooks nil insert-in-front-hooks nil
1606 insert-behind-hooks nil point-entered nil point-left nil)
1607 ;; Other special properties:
1608 ;; category, face, display: probably doesn't do any harm.
1609 ;; fontified: is used by font-lock.
1610 ;; syntax-table, local-map: I dunno.
1611 ;; We need to add XEmacs names to the list.
1612 "Property list of with properties.forbidden in message buffers.
1613 The values of the properties are ignored, only the property names are used.")
1615 (defun message-strip-forbidden-properties (begin end &optional old-length)
1616 "Strip forbidden properties between BEGIN and END, ignoring the third arg.
1617 This function is intended to be called from `after-change-functions'.
1618 See also `message-forbidden-properties'."
1619 (remove-text-properties begin end message-forbidden-properties))
1622 (define-derived-mode message-mode text-mode "Message"
1623 "Major mode for editing mail and news to be sent.
1624 Like Text Mode but with these additional commands:\\<message-mode-map>
1625 C-c C-s `message-send' (send the message) C-c C-c `message-send-and-exit'
1626 C-c C-d Postpone sending the message C-c C-k Kill the message
1627 C-c C-f move to a header field (and create it if there isn't):
1628 C-c C-f C-t move to To C-c C-f C-s move to Subject
1629 C-c C-f C-c move to Cc C-c C-f C-b move to Bcc
1630 C-c C-f C-w move to Fcc C-c C-f C-r move to Reply-To
1631 C-c C-f C-u move to Summary C-c C-f C-n move to Newsgroups
1632 C-c C-f C-k move to Keywords C-c C-f C-d move to Distribution
1633 C-c C-f C-f move to Followup-To
1634 C-c C-f C-m move to Mail-Followup-To
1635 C-c C-t `message-insert-to' (add a To header to a news followup)
1636 C-c C-n `message-insert-newsgroups' (add a Newsgroup header to a news reply)
1637 C-c C-b `message-goto-body' (move to beginning of message text).
1638 C-c C-i `message-goto-signature' (move to the beginning of the signature).
1639 C-c C-w `message-insert-signature' (insert `message-signature-file' file).
1640 C-c C-y `message-yank-original' (insert current message, if any).
1641 C-c C-q `message-fill-yanked-message' (fill what was yanked).
1642 C-c C-e `message-elide-region' (elide the text between point and mark).
1643 C-c C-v `message-delete-not-region' (remove the text outside the region).
1644 C-c C-z `message-kill-to-signature' (kill the text up to the signature).
1645 C-c C-r `message-caesar-buffer-body' (rot13 the message body).
1646 C-c C-a `mml-attach-file' (attach a file as MIME).
1647 M-RET `message-newline-and-reformat' (break the line and reformat)."
1648 (set (make-local-variable 'message-reply-buffer) nil)
1649 (make-local-variable 'message-send-actions)
1650 (make-local-variable 'message-exit-actions)
1651 (make-local-variable 'message-kill-actions)
1652 (make-local-variable 'message-postpone-actions)
1653 (make-local-variable 'message-draft-article)
1654 (setq buffer-offer-save t)
1655 (set (make-local-variable 'facemenu-add-face-function)
1657 (let ((face-fun (cdr (assq face message-face-alist))))
1659 (funcall face-fun (point) end)
1660 (error "Face %s not configured for %s mode" face mode-name)))
1662 (set (make-local-variable 'facemenu-remove-face-function) t)
1663 (set (make-local-variable 'message-reply-headers) nil)
1664 (make-local-variable 'message-newsreader)
1665 (make-local-variable 'message-mailer)
1666 (make-local-variable 'message-post-method)
1667 (set (make-local-variable 'message-sent-message-via) nil)
1668 (set (make-local-variable 'message-checksum) nil)
1669 (set (make-local-variable 'message-mime-part) 0)
1670 (message-setup-fill-variables)
1671 ;; Allow using comment commands to add/remove quoting.
1672 (set (make-local-variable 'comment-start) message-yank-prefix)
1673 (if (featurep 'xemacs)
1674 (message-setup-toolbar)
1675 (set (make-local-variable 'font-lock-defaults)
1676 '(message-font-lock-keywords t))
1677 (if (boundp 'tool-bar-map)
1678 (set (make-local-variable 'tool-bar-map) (message-tool-bar-map))))
1679 (easy-menu-add message-mode-menu message-mode-map)
1680 (easy-menu-add message-mode-field-menu message-mode-map)
1681 ;; Mmmm... Forbidden properties...
1682 (add-hook 'after-change-functions 'message-strip-forbidden-properties nil t)
1683 ;; Allow mail alias things.
1684 (when (eq message-mail-alias-type 'abbrev)
1685 (if (fboundp 'mail-abbrevs-setup)
1686 (mail-abbrevs-setup)
1687 (mail-aliases-setup)))
1688 (message-set-auto-save-file-name)
1689 (mm-enable-multibyte)
1690 (set (make-local-variable 'indent-tabs-mode) nil) ;No tabs for indentation.
1693 (defun message-setup-fill-variables ()
1694 "Setup message fill variables."
1695 (set (make-local-variable 'fill-paragraph-function)
1696 'message-fill-paragraph)
1697 (make-local-variable 'paragraph-separate)
1698 (make-local-variable 'paragraph-start)
1699 (make-local-variable 'adaptive-fill-regexp)
1700 (unless (boundp 'adaptive-fill-first-line-regexp)
1701 (setq adaptive-fill-first-line-regexp nil))
1702 (make-local-variable 'adaptive-fill-first-line-regexp)
1703 (let ((quote-prefix-regexp
1704 ;; User should change message-cite-prefix-regexp if
1705 ;; message-yank-prefix is set to an abnormal value.
1706 (concat "\\(" message-cite-prefix-regexp "\\)[ \t]*")))
1707 (setq paragraph-start
1709 (regexp-quote mail-header-separator) "$\\|"
1710 "[ \t]*$\\|" ; blank lines
1711 "-- $\\|" ; signature delimiter
1712 "---+$\\|" ; delimiters for forwarded messages
1713 page-delimiter "$\\|" ; spoiler warnings
1714 ".*wrote:$\\|" ; attribution lines
1715 quote-prefix-regexp "$")) ; empty lines in quoted text
1716 (setq paragraph-separate paragraph-start)
1717 (setq adaptive-fill-regexp
1718 (concat quote-prefix-regexp "\\|" adaptive-fill-regexp))
1719 (setq adaptive-fill-first-line-regexp
1720 (concat quote-prefix-regexp "\\|"
1721 adaptive-fill-first-line-regexp)))
1722 (make-local-variable 'auto-fill-inhibit-regexp)
1723 ;;(setq auto-fill-inhibit-regexp "^[A-Z][^: \n\t]+:")
1724 (setq auto-fill-inhibit-regexp nil)
1725 (make-local-variable 'normal-auto-fill-function)
1726 (setq normal-auto-fill-function 'message-do-auto-fill)
1727 ;; KLUDGE: auto fill might already be turned on in `text-mode-hook'.
1728 ;; In that case, ensure that it uses the right function. The real
1729 ;; solution would be not to use `define-derived-mode', and run
1730 ;; `text-mode-hook' ourself at the end of the mode.
1731 ;; -- Per Abrahamsen <abraham@dina.kvl.dk> Date: 2001-10-19.
1732 (when auto-fill-function
1733 (setq auto-fill-function normal-auto-fill-function)))
1738 ;;; Message mode commands
1741 ;;; Movement commands
1743 (defun message-goto-to ()
1744 "Move point to the To header."
1746 (message-position-on-field "To"))
1748 (defun message-goto-subject ()
1749 "Move point to the Subject header."
1751 (message-position-on-field "Subject"))
1753 (defun message-goto-cc ()
1754 "Move point to the Cc header."
1756 (message-position-on-field "Cc" "To"))
1758 (defun message-goto-bcc ()
1759 "Move point to the Bcc header."
1761 (message-position-on-field "Bcc" "Cc" "To"))
1763 (defun message-goto-fcc ()
1764 "Move point to the Fcc header."
1766 (message-position-on-field "Fcc" "To" "Newsgroups"))
1768 (defun message-goto-reply-to ()
1769 "Move point to the Reply-To header."
1771 (message-position-on-field "Reply-To" "Subject"))
1773 (defun message-goto-newsgroups ()
1774 "Move point to the Newsgroups header."
1776 (message-position-on-field "Newsgroups"))
1778 (defun message-goto-distribution ()
1779 "Move point to the Distribution header."
1781 (message-position-on-field "Distribution"))
1783 (defun message-goto-followup-to ()
1784 "Move point to the Followup-To header."
1786 (message-position-on-field "Followup-To" "Newsgroups"))
1788 (defun message-goto-mail-followup-to ()
1789 "Move point to the Mail-Followup-To header."
1791 (message-position-on-field "Mail-Followup-To" "From"))
1793 (defun message-goto-keywords ()
1794 "Move point to the Keywords header."
1796 (message-position-on-field "Keywords" "Subject"))
1798 (defun message-goto-summary ()
1799 "Move point to the Summary header."
1801 (message-position-on-field "Summary" "Subject"))
1803 (defun message-goto-body (&optional interactivep)
1804 "Move point to the beginning of the message body."
1805 (interactive (list t))
1806 (when (and interactivep
1807 (looking-at "[ \t]*\n"))
1809 (goto-char (point-min))
1810 (or (search-forward (concat "\n" mail-header-separator "\n") nil t)
1811 (search-forward-regexp "[^:]+:\\([^\n]\\|\n[ \t]\\)+\n\n" nil t)))
1813 (defun message-goto-eoh ()
1814 "Move point to the end of the headers."
1819 (defun message-goto-signature ()
1820 "Move point to the beginning of the message signature.
1821 If there is no signature in the article, go to the end and
1824 (goto-char (point-min))
1825 (if (re-search-forward message-signature-separator nil t)
1827 (goto-char (point-max))
1832 (defun message-insert-to (&optional force)
1833 "Insert a To header that points to the author of the article being replied to.
1834 If the original author requested not to be sent mail, the function signals
1836 With the prefix argument FORCE, insert the header anyway."
1838 (let ((co (message-fetch-reply-field "mail-copies-to")))
1839 (when (and (null force)
1841 (or (equal (downcase co) "never")
1842 (equal (downcase co) "nobody")))
1843 (error "The user has requested not to have copies sent via mail")))
1844 (when (and (message-position-on-field "To")
1845 (mail-fetch-field "to")
1846 (not (string-match "\\` *\\'" (mail-fetch-field "to"))))
1848 (insert (or (message-fetch-reply-field "mail-reply-to")
1849 (message-fetch-reply-field "reply-to")
1850 (message-fetch-reply-field "from") "")))
1852 (defun message-widen-reply ()
1853 "Widen the reply to include maximum recipients."
1856 (and message-reply-buffer
1857 (buffer-name message-reply-buffer)
1859 (set-buffer message-reply-buffer)
1860 (message-get-reply-headers t)))))
1863 (message-narrow-to-headers)
1864 (dolist (elem follow-to)
1865 (message-remove-header (symbol-name (car elem)))
1866 (goto-char (point-min))
1867 (insert (symbol-name (car elem)) ": "
1868 (cdr elem) "\n"))))))
1870 (defun message-insert-newsgroups ()
1871 "Insert the Newsgroups header from the article being replied to."
1873 (when (and (message-position-on-field "Newsgroups")
1874 (mail-fetch-field "newsgroups")
1875 (not (string-match "\\` *\\'" (mail-fetch-field "newsgroups"))))
1877 (insert (or (message-fetch-reply-field "newsgroups") "")))
1881 ;;; Various commands
1883 (defun message-delete-not-region (beg end)
1884 "Delete everything in the body of the current message outside of the region."
1889 ;; snarf citation prefix, if appropriate
1890 (unless (eq (point) (progn (beginning-of-line) (point)))
1891 (when (looking-at message-cite-prefix-regexp)
1892 (setq citeprefix (match-string 0))))
1894 (delete-region (point) (if (not (message-goto-signature))
1900 (delete-region beg (progn (message-goto-body)
1904 (insert citeprefix))))
1905 (when (message-goto-signature)
1908 (defun message-kill-to-signature ()
1909 "Deletes all text up to the signature."
1911 (let ((point (point)))
1912 (message-goto-signature)
1915 (kill-region point (point))
1919 (defun message-newline-and-reformat (&optional arg not-break)
1920 "Insert four newlines, and then reformat if inside quoted text.
1921 Prefix arg means justify as well."
1922 (interactive (list (if current-prefix-arg 'full)))
1923 (let (quoted point beg end leading-space bolp)
1924 (setq point (point))
1927 (setq bolp (= beg point))
1928 ;; Find first line of the paragraph.
1930 (while (and (not (eobp))
1931 (not (looking-at message-cite-prefix-regexp))
1932 (looking-at paragraph-start))
1935 (when (looking-at message-cite-prefix-regexp)
1936 (setq quoted (match-string 0))
1937 (goto-char (match-end 0))
1938 (looking-at "[ \t]*")
1939 (setq leading-space (match-string 0)))
1943 (< (- point beg) (length quoted)))
1944 ;; break inside the cite prefix.
1950 (while (and (not (eobp))
1951 (not (looking-at paragraph-separate))
1952 (looking-at message-cite-prefix-regexp)
1953 (equal quoted (match-string 0)))
1954 (goto-char (match-end 0))
1955 (looking-at "[ \t]*")
1956 (if (> (length leading-space) (length (match-string 0)))
1957 (setq leading-space (match-string 0)))
1961 (while (and (if (bobp) nil (forward-line -1) t)
1962 (not (looking-at paragraph-start))
1963 (looking-at message-cite-prefix-regexp)
1964 (equal quoted (match-string 0)))
1966 (goto-char (match-end 0))
1967 (looking-at "[ \t]*")
1968 (if (> (length leading-space) (length (match-string 0)))
1969 (setq leading-space (match-string 0)))))
1970 (while (and (not (eobp))
1971 (not (looking-at paragraph-separate))
1972 (not (looking-at message-cite-prefix-regexp)))
1976 (while (and (if (bobp) nil (forward-line -1) t)
1977 (not (looking-at paragraph-start))
1978 (not (looking-at message-cite-prefix-regexp)))
1979 (setq beg (point))))
1982 (narrow-to-region beg end)
1988 (setq point (point))
1990 (delete-region (point) (re-search-forward "[ \t]*"))
1991 (when (and quoted (not bolp))
1992 (insert quoted leading-space)))
1994 (let* ((adaptive-fill-regexp
1995 (regexp-quote (concat quoted leading-space)))
1996 (adaptive-fill-first-line-regexp
1997 adaptive-fill-regexp ))
1998 (fill-paragraph arg))
1999 (fill-paragraph arg))
2000 (if point (goto-char point)))))
2002 (defun message-fill-paragraph (&optional arg)
2003 "Like `fill-paragraph'."
2004 (interactive (list (if current-prefix-arg 'full)))
2005 (if (and (boundp 'filladapt-mode) filladapt-mode)
2007 (message-newline-and-reformat arg t)
2010 (defun message-do-auto-fill ()
2011 "Like `do-auto-fill', but don't fill in message header."
2012 (when (> (point) (save-excursion
2013 (goto-char (point-min))
2014 (if (re-search-forward
2015 (concat "^" (regexp-quote mail-header-separator)
2021 (defun message-insert-signature (&optional force)
2022 "Insert a signature. See documentation for variable `message-signature'."
2023 (interactive (list 0))
2026 ((and (null message-signature)
2029 (goto-char (point-max))
2030 (not (re-search-backward message-signature-separator nil t))))
2031 ((and (null message-signature)
2034 ((message-functionp message-signature)
2035 (funcall message-signature))
2036 ((listp message-signature)
2037 (eval message-signature))
2038 (t message-signature)))
2040 (cond ((stringp signature)
2042 ((and (eq t signature)
2043 message-signature-file
2044 (file-exists-p message-signature-file))
2047 (goto-char (point-max))
2048 ;; Insert the signature.
2052 (if (eq signature t)
2053 (insert-file-contents message-signature-file)
2055 (goto-char (point-max))
2056 (or (bolp) (insert "\n")))))
2058 (defun message-elide-region (b e)
2059 "Elide the text in the region.
2060 An ellipsis (from `message-elide-ellipsis') will be inserted where the
2064 (insert message-elide-ellipsis))
2066 (defvar message-caesar-translation-table nil)
2068 (defun message-caesar-region (b e &optional n)
2069 "Caesar rotate region B to E by N, default 13, for decrypting netnews."
2072 (min (point) (or (mark t) (point)))
2073 (max (point) (or (mark t) (point)))
2074 (when current-prefix-arg
2075 (prefix-numeric-value current-prefix-arg))))
2077 (setq n (if (numberp n) (mod n 26) 13)) ;canonize N
2078 (unless (or (zerop n) ; no action needed for a rot of 0
2079 (= b e)) ; no region to rotate
2080 ;; We build the table, if necessary.
2081 (when (or (not message-caesar-translation-table)
2082 (/= (aref message-caesar-translation-table ?a) (+ ?a n)))
2083 (setq message-caesar-translation-table
2084 (message-make-caesar-translation-table n)))
2085 (translate-region b e message-caesar-translation-table)))
2087 (defun message-make-caesar-translation-table (n)
2088 "Create a rot table with offset N."
2090 (table (make-string 256 0)))
2091 (while (< (incf i) 256)
2094 (substring table 0 ?A)
2095 (substring table (+ ?A n) (+ ?A n (- 26 n)))
2096 (substring table ?A (+ ?A n))
2097 (substring table (+ ?A 26) ?a)
2098 (substring table (+ ?a n) (+ ?a n (- 26 n)))
2099 (substring table ?a (+ ?a n))
2100 (substring table (+ ?a 26) 255))))
2102 (defun message-caesar-buffer-body (&optional rotnum)
2103 "Caesar rotate all letters in the current buffer by 13 places.
2104 Used to encode/decode possibly offensive messages (commonly in rec.humor).
2105 With prefix arg, specifies the number of places to rotate each letter forward.
2106 Mail and USENET news headers are not rotated."
2107 (interactive (if current-prefix-arg
2108 (list (prefix-numeric-value current-prefix-arg))
2112 (when (message-goto-body)
2113 (narrow-to-region (point) (point-max)))
2114 (message-caesar-region (point-min) (point-max) rotnum))))
2116 (defun message-pipe-buffer-body (program)
2117 "Pipe the message body in the current buffer through PROGRAM."
2120 (when (message-goto-body)
2121 (narrow-to-region (point) (point-max)))
2122 (shell-command-on-region
2123 (point-min) (point-max) program nil t))))
2125 (defun message-rename-buffer (&optional enter-string)
2126 "Rename the *message* buffer to \"*message* RECIPIENT\".
2127 If the function is run with a prefix, it will ask for a new buffer
2128 name, rather than giving an automatic name."
2129 (interactive "Pbuffer name: ")
2132 (goto-char (point-min))
2133 (narrow-to-region (point)
2134 (search-forward mail-header-separator nil 'end))
2136 (if (message-news-p) (message-fetch-field "Newsgroups")
2137 (message-fetch-field "To"))
2140 (if (string-match "," mail-to)
2141 (concat (substring mail-to 0 (match-beginning 0)) ", ...")
2143 (name-default (concat "*message* " mail-trimmed-to))
2144 (name (if enter-string
2145 (read-string "New buffer name: " name-default)
2147 (rename-buffer name t)))))
2149 (defun message-fill-yanked-message (&optional justifyp)
2150 "Fill the paragraphs of a message yanked into this one.
2151 Numeric argument means justify as well."
2154 (goto-char (point-min))
2155 (search-forward (concat "\n" mail-header-separator "\n") nil t)
2156 (let ((fill-prefix message-yank-prefix))
2157 (fill-individual-paragraphs (point) (point-max) justifyp))))
2159 (defun message-indent-citation ()
2160 "Modify text just inserted from a message to be cited.
2161 The inserted text should be the region.
2162 When this function returns, the region is again around the modified text.
2164 Normally, indent each nonblank line `message-indentation-spaces' spaces.
2165 However, if `message-yank-prefix' is non-nil, insert that prefix on each line."
2166 (let ((start (point)))
2167 ;; Remove unwanted headers.
2168 (when message-ignored-cited-headers
2173 (if (search-forward "\n\n" nil t)
2176 (message-remove-header message-ignored-cited-headers t)
2177 (when (= (point-min) (point-max))
2178 (setq all-removed t))
2179 (goto-char (point-max)))
2183 ;; Delete blank lines at the start of the buffer.
2184 (while (and (point-min)
2187 (message-delete-line))
2188 ;; Delete blank lines at the end of the buffer.
2189 (goto-char (point-max))
2192 (while (and (zerop (forward-line -1))
2194 (message-delete-line))
2195 ;; Do the indentation.
2196 (if (null message-yank-prefix)
2197 (indent-rigidly start (mark t) message-indentation-spaces)
2200 (while (< (point) (mark t))
2201 (if (or (looking-at ">") (looking-at "^$"))
2202 (insert message-yank-cited-prefix)
2203 (insert message-yank-prefix))
2207 (defun message-yank-original (&optional arg)
2208 "Insert the message being replied to, if any.
2209 Puts point before the text and mark after.
2210 Normally indents each nonblank line ARG spaces (default 3). However,
2211 if `message-yank-prefix' is non-nil, insert that prefix on each line.
2213 This function uses `message-cite-function' to do the actual citing.
2215 Just \\[universal-argument] as argument means don't indent, insert no
2216 prefix, and don't delete any headers."
2218 (let ((modified (buffer-modified-p)))
2219 (when (and message-reply-buffer
2220 message-cite-function)
2221 (delete-windows-on message-reply-buffer t)
2222 (insert-buffer message-reply-buffer)
2224 (funcall message-cite-function))
2225 (message-exchange-point-and-mark)
2229 (setq message-checksum (message-checksum))))))
2231 (defun message-yank-buffer (buffer)
2232 "Insert BUFFER into the current buffer and quote it."
2233 (interactive "bYank buffer: ")
2234 (let ((message-reply-buffer buffer))
2235 (save-window-excursion
2236 (message-yank-original))))
2238 (defun message-buffers ()
2239 "Return a list of active message buffers."
2242 (dolist (buffer (buffer-list t))
2244 (when (and (eq major-mode 'message-mode)
2245 (null message-sent-message-via))
2246 (push (buffer-name buffer) buffers))))
2247 (nreverse buffers)))
2249 (defun message-cite-original-without-signature ()
2250 "Cite function in the standard Message manner."
2251 (let ((start (point))
2254 (when message-indent-citation-function
2255 (if (listp message-indent-citation-function)
2256 message-indent-citation-function
2257 (list message-indent-citation-function)))))
2258 (mml-quote-region start end)
2262 (when (re-search-backward message-signature-separator start t)
2263 ;; Also peel off any blank lines before the signature.
2265 (while (looking-at "^[ \t]*$")
2268 (delete-region (point) end)
2269 (unless (search-backward "\n\n" start t)
2270 ;; Insert a blank line if it is peeled off.
2274 (funcall (pop functions)))
2275 (when message-citation-line-function
2278 (funcall message-citation-line-function))))
2280 (eval-when-compile (defvar mail-citation-hook)) ;Compiler directive
2281 (defun message-cite-original ()
2282 "Cite function in the standard Message manner."
2283 (if (and (boundp 'mail-citation-hook)
2285 (run-hooks 'mail-citation-hook)
2286 (let ((start (point))
2289 (when message-indent-citation-function
2290 (if (listp message-indent-citation-function)
2291 message-indent-citation-function
2292 (list message-indent-citation-function)))))
2293 (mml-quote-region start end)
2296 (funcall (pop functions)))
2297 (when message-citation-line-function
2300 (funcall message-citation-line-function)))))
2302 (defun message-insert-citation-line ()
2303 "Insert a simple citation line."
2304 (when message-reply-headers
2305 (insert (mail-header-from message-reply-headers) " writes:\n\n")))
2307 (defun message-position-on-field (header &rest afters)
2308 (let ((case-fold-search t))
2311 (goto-char (point-min))
2314 (concat "^" (regexp-quote mail-header-separator) "$"))
2315 (match-beginning 0)))
2316 (goto-char (point-min))
2317 (if (re-search-forward (concat "^" (regexp-quote header) ":") nil t)
2319 (re-search-forward "^[^ \t]" nil 'move)
2321 (skip-chars-backward "\n")
2324 (not (re-search-forward
2325 (concat "^" (regexp-quote (car afters)) ":")
2329 (re-search-forward "^[^ \t]" nil 'move)
2330 (beginning-of-line))
2331 (insert header ": \n")
2335 (defun message-remove-signature ()
2336 "Remove the signature from the text between point and mark.
2337 The text will also be indented the normal way."
2339 (let ((start (point))
2341 (if (not (re-search-forward message-signature-separator (mark t) t))
2342 ;; No signature here, so we just indent the cited text.
2343 (message-indent-citation)
2344 ;; Find the last non-empty line.
2346 (while (looking-at "[ \t]*$")
2349 (setq mark (set-marker (make-marker) (point)))
2351 (message-indent-citation)
2352 ;; Enable undoing the deletion.
2354 (delete-region mark (mark t))
2355 (set-marker mark nil)))))
2360 ;;; Sending messages
2363 (defun message-send-and-exit (&optional arg)
2364 "Send message like `message-send', then, if no errors, exit from mail buffer."
2366 (let ((buf (current-buffer))
2367 (actions message-exit-actions))
2368 (when (and (message-send arg)
2370 (if message-kill-buffer-on-exit
2373 (when (eq buf (current-buffer))
2374 (message-bury buf)))
2375 (message-do-actions actions)
2378 (defun message-dont-send ()
2379 "Don't send the message you have been editing."
2381 (set-buffer-modified-p t)
2383 (let ((actions message-postpone-actions))
2384 (message-bury (current-buffer))
2385 (message-do-actions actions)))
2387 (defun message-kill-buffer ()
2388 "Kill the current buffer."
2390 (when (or (not (buffer-modified-p))
2391 (yes-or-no-p "Message modified; kill anyway? "))
2392 (let ((actions message-kill-actions)
2393 (draft-article message-draft-article)
2394 (auto-save-file-name buffer-auto-save-file-name)
2395 (file-name buffer-file-name)
2396 (modified (buffer-modified-p)))
2397 (setq buffer-file-name nil)
2398 (kill-buffer (current-buffer))
2399 (when (and (or (and auto-save-file-name
2400 (file-exists-p auto-save-file-name))
2402 (file-exists-p file-name)))
2403 (yes-or-no-p (format "Remove the backup file%s? "
2404 (if modified " too" ""))))
2406 (delete-file auto-save-file-name))
2407 (let ((message-draft-article draft-article))
2408 (message-disassociate-draft)))
2409 (message-do-actions actions))))
2411 (defun message-bury (buffer)
2412 "Bury this mail BUFFER."
2413 (let ((newbuf (other-buffer buffer)))
2414 (bury-buffer buffer)
2415 (if (and (fboundp 'frame-parameters)
2416 (cdr (assq 'dedicated (frame-parameters)))
2417 (not (null (delq (selected-frame) (visible-frame-list)))))
2418 (delete-frame (selected-frame))
2419 (switch-to-buffer newbuf))))
2421 (defun message-send (&optional arg)
2422 "Send the message in the current buffer.
2423 If `message-interactive' is non-nil, wait for success indication or
2424 error messages, and inform user.
2425 Otherwise any failure is reported in a message back to the user from
2427 The usage of ARG is defined by the instance that called Message.
2428 It should typically alter the sending method in some way or other."
2430 ;; Make it possible to undo the coming changes.
2432 (let ((inhibit-read-only t))
2433 (put-text-property (point-min) (point-max) 'read-only nil))
2434 (message-fix-before-sending)
2435 (run-hooks 'message-send-hook)
2436 (message message-sending-message)
2437 (let ((alist message-send-method-alist)
2440 (message-options message-options))
2441 (message-options-set-recipient)
2443 (setq elem (pop alist)))
2444 (when (funcall (cadr elem))
2445 (when (and (or (not (memq (car elem)
2446 message-sent-message-via))
2447 (if (or (message-gnksa-enable-p 'multiple-copies)
2448 (not (eq (car elem) 'news)))
2451 "Already sent message via %s; resend? "
2453 (error "Denied posting -- multiple copies")))
2454 (setq success (funcall (caddr elem) arg)))
2456 (unless (or sent (not success))
2457 (error "No methods specified to send by"))
2458 (when (and success sent)
2461 (run-hooks 'message-sent-hook))
2462 (message "Sending...done")
2463 ;; Mark the buffer as unmodified and delete auto-save.
2464 (set-buffer-modified-p nil)
2465 (delete-auto-save-file-if-necessary t)
2466 (message-disassociate-draft)
2467 ;; Delete other mail buffers and stuff.
2468 (message-do-send-housekeeping)
2469 (message-do-actions message-send-actions)
2473 (defun message-send-via-mail (arg)
2474 "Send the current message via mail."
2475 (message-send-mail arg))
2477 (defun message-send-via-news (arg)
2478 "Send the current message via news."
2479 (funcall message-send-news-function arg))
2481 (defmacro message-check (type &rest forms)
2482 "Eval FORMS if TYPE is to be checked."
2483 `(or (message-check-element ,type)
2487 (put 'message-check 'lisp-indent-function 1)
2488 (put 'message-check 'edebug-form-spec '(form body))
2490 (defun message-fix-before-sending ()
2491 "Do various things to make the message nice before sending it."
2492 ;; Make sure there's a newline at the end of the message.
2493 (goto-char (point-max))
2496 ;; Delete all invisible text.
2497 (message-check 'invisible-text
2498 (when (text-property-any (point-min) (point-max) 'invisible t)
2499 (put-text-property (point-min) (point-max) 'invisible nil)
2500 (unless (yes-or-no-p
2501 "Invisible text found and made visible; continue posting? ")
2502 (error "Invisible text found and made visible")))))
2504 (defun message-add-action (action &rest types)
2505 "Add ACTION to be performed when doing an exit of type TYPES."
2508 (set (setq var (intern (format "message-%s-actions" (pop types))))
2509 (nconc (symbol-value var) (list action))))))
2511 (defun message-do-actions (actions)
2512 "Perform all actions in ACTIONS."
2513 ;; Now perform actions on successful sending.
2517 ;; A simple function.
2518 ((message-functionp (car actions))
2519 (funcall (car actions)))
2520 ;; Something to be evaled.
2522 (eval (car actions)))))
2525 (defun message-send-mail-partially ()
2526 "Send mail as message/partial."
2527 ;; replace the header delimiter with a blank line
2528 (goto-char (point-min))
2530 (concat "^" (regexp-quote mail-header-separator) "\n"))
2531 (replace-match "\n")
2532 (run-hooks 'message-send-mail-hook)
2533 (let ((p (goto-char (point-min)))
2534 (tembuf (message-generate-new-buffer-clone-locals " message temp"))
2535 (curbuf (current-buffer))
2536 (id (message-make-message-id)) (n 1)
2537 plist total header required-mail-headers)
2539 (if (< (point-max) (+ p message-send-mail-partially-limit))
2540 (goto-char (point-max))
2541 (goto-char (+ p message-send-mail-partially-limit))
2543 (if (<= (point) p) (forward-line 1))) ;; In case of bad message.
2546 (setq total (length plist))
2547 (push (point-max) plist)
2548 (setq plist (nreverse plist))
2551 (setq p (pop plist))
2554 (copy-to-buffer tembuf p (car plist))
2556 (goto-char (point-min))
2559 (goto-char (point-min))
2560 (narrow-to-region (point) (point))
2563 (setq header (buffer-substring (point-min) (point)))
2564 (goto-char (point-min))
2565 (narrow-to-region (point) (point))
2567 (message-remove-header "Mime-Version")
2568 (message-remove-header "Content-Type")
2569 (message-remove-header "Content-Transfer-Encoding")
2570 (message-remove-header "Message-ID")
2571 (message-remove-header "Lines")
2572 (goto-char (point-max))
2573 (insert "Mime-Version: 1.0\n")
2574 (setq header (buffer-substring (point-min) (point-max))))
2575 (goto-char (point-max))
2576 (insert (format "Content-Type: message/partial; id=\"%s\"; number=%d; total=%d\n\n"
2579 (let ((mail-header-separator ""))
2580 (when (memq 'Message-ID message-required-mail-headers)
2581 (insert "Message-ID: " (message-make-message-id) "\n"))
2582 (when (memq 'Lines message-required-mail-headers)
2583 (insert "Lines: " (message-make-lines) "\n"))
2584 (message-goto-subject)
2586 (insert (format " (%d/%d)" n total))
2588 (mm-with-unibyte-current-buffer
2589 (funcall (or message-send-mail-real-function
2590 message-send-mail-function))))
2592 (setq p (pop plist))
2594 (kill-buffer tembuf))))
2596 (defun message-send-mail (&optional arg)
2597 (require 'mail-utils)
2598 (let* ((tembuf (message-generate-new-buffer-clone-locals " message temp"))
2599 (case-fold-search nil)
2600 (news (message-news-p))
2601 (mailbuf (current-buffer))
2602 (message-this-is-mail t)
2603 (message-posting-charset
2604 (if (fboundp 'gnus-setup-posting-charset)
2605 (gnus-setup-posting-charset nil)
2606 message-posting-charset))
2607 (headers message-required-mail-headers))
2609 (message-narrow-to-headers)
2610 ;; Generate the Mail-Followup-To header if the header is not there...
2611 (if (and (or message-subscribed-regexps
2612 message-subscribed-addresses
2613 message-subscribed-address-functions)
2614 (not (mail-fetch-field "mail-followup-to")))
2617 (cons "Mail-Followup-To" (message-make-mft))
2618 message-required-mail-headers))
2619 ;; otherwise, delete the MFT header if the field is empty
2620 (when (equal "" (mail-fetch-field "mail-followup-to"))
2621 (message-remove-header "^Mail-Followup-To:")))
2622 ;; Insert some headers.
2623 (let ((message-deletable-headers
2624 (if news nil message-deletable-headers)))
2625 (message-generate-headers headers))
2626 ;; Let the user do all of the above.
2627 (run-hooks 'message-header-hook))
2632 ;; Avoid copying text props.
2633 (insert (with-current-buffer mailbuf
2634 (buffer-substring-no-properties (point-min) (point-max))))
2635 ;; Remove some headers.
2636 (message-encode-message-body)
2638 (message-narrow-to-headers)
2639 ;; We (re)generate the Lines header.
2640 (when (memq 'Lines message-required-mail-headers)
2641 (message-generate-headers '(Lines)))
2642 ;; Remove some headers.
2643 (message-remove-header message-ignored-mail-headers t)
2644 (let ((mail-parse-charset message-default-charset))
2645 (mail-encode-encoded-word-buffer)))
2646 (goto-char (point-max))
2647 ;; require one newline at the end.
2648 (or (= (preceding-char) ?\n)
2652 (message-narrow-to-headers)
2654 (or (message-fetch-field "cc")
2655 (message-fetch-field "to"))
2656 (let ((content-type (message-fetch-field "content-type")))
2659 (string= "text/plain"
2661 (mail-header-parse-content-type
2663 (message-insert-courtesy-copy))
2664 (if (or (not message-send-mail-partially-limit)
2665 (< (point-max) message-send-mail-partially-limit)
2666 (not (y-or-n-p "Message exceeds message-send-mail-partially-limit, send in parts? ")))
2667 (mm-with-unibyte-current-buffer
2668 (message "Sending via mail...")
2669 (funcall (or message-send-mail-real-function
2670 message-send-mail-function)))
2671 (message-send-mail-partially)))
2672 (kill-buffer tembuf))
2673 (set-buffer mailbuf)
2674 (push 'mail message-sent-message-via)))
2676 (defun message-send-mail-with-sendmail ()
2677 "Send off the prepared buffer with sendmail."
2678 (let ((errbuf (if message-interactive
2679 (message-generate-new-buffer-clone-locals
2682 resend-to-addresses delimline)
2683 (let ((case-fold-search t))
2685 (message-narrow-to-headers)
2686 (setq resend-to-addresses (message-fetch-field "resent-to")))
2687 ;; Change header-delimiter to be what sendmail expects.
2688 (goto-char (point-min))
2690 (concat "^" (regexp-quote mail-header-separator) "\n"))
2691 (replace-match "\n")
2693 (setq delimline (point-marker))
2694 (run-hooks 'message-send-mail-hook)
2695 ;; Insert an extra newline if we need it to work around
2696 ;; Sun's bug that swallows newlines.
2697 (goto-char (1+ delimline))
2698 (when (eval message-mailer-swallows-blank-line)
2700 (when message-interactive
2704 (let ((default-directory "/")
2705 (coding-system-for-write message-send-coding-system))
2706 (apply 'call-process-region
2707 (append (list (point-min) (point-max)
2708 (if (boundp 'sendmail-program)
2710 "/usr/lib/sendmail")
2711 nil errbuf nil "-oi")
2712 ;; Always specify who from,
2713 ;; since some systems have broken sendmails.
2714 ;; But some systems are more broken with -f, so
2715 ;; we'll let users override this.
2716 (if (null message-sendmail-f-is-evil)
2717 (list "-f" (message-make-address)))
2718 ;; These mean "report errors by mail"
2719 ;; and "deliver in background".
2720 (if (null message-interactive) '("-oem" "-odb"))
2721 ;; Get the addresses from the message
2722 ;; unless this is a resend.
2723 ;; We must not do that for a resend
2724 ;; because we would find the original addresses.
2725 ;; For a resend, include the specific addresses.
2726 (if resend-to-addresses
2727 (list resend-to-addresses)
2729 (when message-interactive
2732 (goto-char (point-min))
2733 (while (re-search-forward "\n\n* *" nil t)
2734 (replace-match "; "))
2735 (if (not (zerop (buffer-size)))
2736 (error "Sending...failed to %s"
2737 (buffer-substring (point-min) (point-max)))))
2738 (when (bufferp errbuf)
2739 (kill-buffer errbuf)))))
2741 (defun message-send-mail-with-qmail ()
2742 "Pass the prepared message buffer to qmail-inject.
2743 Refer to the documentation for the variable `message-send-mail-function'
2744 to find out how to use this."
2745 ;; replace the header delimiter with a blank line
2746 (goto-char (point-min))
2748 (concat "^" (regexp-quote mail-header-separator) "\n"))
2749 (replace-match "\n")
2750 (run-hooks 'message-send-mail-hook)
2753 (let ((coding-system-for-write message-send-coding-system))
2755 'call-process-region 1 (point-max) message-qmail-inject-program
2757 ;; qmail-inject's default behaviour is to look for addresses on the
2758 ;; command line; if there're none, it scans the headers.
2759 ;; yes, it does The Right Thing w.r.t. Resent-To and it's kin.
2761 ;; in general, ALL of qmail-inject's defaults are perfect for simply
2762 ;; reading a formatted (i. e., at least a To: or Resent-To header)
2763 ;; message from stdin.
2765 ;; qmail also has the advantage of not having been raped by
2766 ;; various vendors, so we don't have to allow for that, either --
2767 ;; compare this with message-send-mail-with-sendmail and weep
2768 ;; for sendmail's lost innocence.
2770 ;; all this is way cool coz it lets us keep the arguments entirely
2771 ;; free for -inject-arguments -- a big win for the user and for us
2772 ;; since we don't have to play that double-guessing game and the user
2773 ;; gets full control (no gestapo'ish -f's, for instance). --sj
2774 message-qmail-inject-args))
2775 ;; qmail-inject doesn't say anything on it's stdout/stderr,
2776 ;; we have to look at the retval instead
2778 (100 (error "qmail-inject reported permanent failure"))
2779 (111 (error "qmail-inject reported transient failure"))
2780 ;; should never happen
2781 (t (error "qmail-inject reported unknown failure"))))
2783 (defun message-send-mail-with-mh ()
2784 "Send the prepared message buffer with mh."
2785 (let ((mh-previous-window-config nil)
2786 (name (mh-new-draft-name)))
2787 (setq buffer-file-name name)
2788 ;; MH wants to generate these headers itself.
2789 (when message-mh-deletable-headers
2790 (let ((headers message-mh-deletable-headers))
2792 (goto-char (point-min))
2793 (and (re-search-forward
2794 (concat "^" (symbol-name (car headers)) ": *") nil t)
2795 (message-delete-line))
2797 (run-hooks 'message-send-mail-hook)
2798 ;; Pass it on to mh.
2801 (defun message-canlock-generate ()
2802 "Return a string that is non-trival to guess.
2803 Do not use this for anything important, it is cryptographically weak."
2804 (md5 (concat (message-unique-id)
2805 (format "%x%x%x" (random) (random t) (random))
2806 (prin1-to-string (recent-keys))
2807 (prin1-to-string (garbage-collect)))))
2809 (defun message-canlock-password ()
2810 "The password used by message for cancel locks.
2811 This is the value of `canlock-password', if that option is non-nil.
2812 Otherwise, generate and save a value for `canlock-password' first."
2813 (unless canlock-password
2814 (customize-save-variable 'canlock-password (message-canlock-generate)))
2817 (defun message-insert-canlock ()
2818 (when message-insert-canlock
2819 (message-canlock-password)
2820 (canlock-insert-header)))
2822 (defun message-send-news (&optional arg)
2823 (let* ((tembuf (message-generate-new-buffer-clone-locals " *message temp*"))
2824 (case-fold-search nil)
2825 (method (if (message-functionp message-post-method)
2826 (funcall message-post-method arg)
2827 message-post-method))
2828 (newsgroups-field (save-restriction
2829 (message-narrow-to-headers-or-head)
2830 (message-fetch-field "Newsgroups")))
2831 (followup-field (save-restriction
2832 (message-narrow-to-headers-or-head)
2833 (message-fetch-field "Followup-To")))
2834 ;; BUG: We really need to get the charset for each name in the
2835 ;; Newsgroups and Followup-To lines to allow crossposting
2836 ;; between group namess with incompatible character sets.
2837 ;; -- Per Abrahamsen <abraham@dina.kvl.dk> 2001-10-08.
2838 (group-field-charset
2839 (gnus-group-name-charset method newsgroups-field))
2840 (followup-field-charset
2841 (gnus-group-name-charset method (or followup-field "")))
2842 (rfc2047-header-encoding-alist
2843 (append (when group-field-charset
2844 (list (cons "Newsgroups" group-field-charset)))
2845 (when followup-field-charset
2846 (list (cons "Followup-To" followup-field-charset)))
2847 rfc2047-header-encoding-alist))
2848 (messbuf (current-buffer))
2849 (message-syntax-checks
2851 (listp message-syntax-checks))
2852 (cons '(existing-newsgroups . disabled)
2853 message-syntax-checks)
2854 message-syntax-checks))
2855 (message-this-is-news t)
2856 (message-posting-charset
2857 (gnus-setup-posting-charset newsgroups-field))
2859 (if (not (message-check-news-body-syntax))
2862 (message-narrow-to-headers)
2863 ;; Insert some headers.
2864 (message-generate-headers message-required-news-headers)
2865 (message-insert-canlock)
2866 ;; Let the user do all of the above.
2867 (run-hooks 'message-header-hook))
2868 ;; Note: This check will be disabled by the ".*" default value for
2869 ;; gnus-group-name-charset-group-alist. -- Pa 2001-10-07.
2870 (when (and group-field-charset
2871 (listp message-syntax-checks))
2872 (setq message-syntax-checks
2873 (cons '(valid-newsgroups . disabled)
2874 message-syntax-checks)))
2875 (message-cleanup-headers)
2876 (if (not (let ((message-post-method method))
2877 (message-check-news-syntax)))
2882 (buffer-disable-undo)
2884 ;; Avoid copying text props.
2885 (insert (with-current-buffer messbuf
2886 (buffer-substring-no-properties
2887 (point-min) (point-max))))
2888 (message-encode-message-body)
2889 ;; Remove some headers.
2891 (message-narrow-to-headers)
2892 ;; We (re)generate the Lines header.
2893 (when (memq 'Lines message-required-mail-headers)
2894 (message-generate-headers '(Lines)))
2895 ;; Remove some headers.
2896 (message-remove-header message-ignored-news-headers t)
2897 (let ((mail-parse-charset message-default-charset))
2898 (mail-encode-encoded-word-buffer)))
2899 (goto-char (point-max))
2900 ;; require one newline at the end.
2901 (or (= (preceding-char) ?\n)
2903 (let ((case-fold-search t))
2904 ;; Remove the delimiter.
2905 (goto-char (point-min))
2907 (concat "^" (regexp-quote mail-header-separator) "\n"))
2908 (replace-match "\n")
2910 (run-hooks 'message-send-news-hook)
2911 (gnus-open-server method)
2912 (message "Sending news with %s..." (gnus-server-string method))
2913 (setq result (let ((mail-header-separator ""))
2914 (gnus-request-post method))))
2915 (kill-buffer tembuf))
2916 (set-buffer messbuf)
2918 (push 'news message-sent-message-via)
2919 (message "Couldn't send message via news: %s"
2920 (nnheader-get-report (car method)))
2924 ;;; Header generation & syntax checking.
2927 (defun message-check-element (type)
2928 "Return non-nil if this TYPE is not to be checked."
2929 (if (eq message-syntax-checks 'dont-check-for-anything-just-trust-me)
2931 (let ((able (assq type message-syntax-checks)))
2933 (eq (cdr able) 'disabled)))))
2935 (defun message-check-news-syntax ()
2936 "Check the syntax of the message."
2940 ;; We narrow to the headers and check them first.
2943 (message-narrow-to-headers)
2944 (message-check-news-header-syntax))))))
2946 (defun message-check-news-header-syntax ()
2948 ;; Check Newsgroups header.
2949 (message-check 'newsgroups
2950 (let ((group (message-fetch-field "newsgroups")))
2953 (not (string-match "\\`[ \t]*\\'" group)))
2956 "The newsgroups field is empty or missing. Posting is denied.")))))
2957 ;; Check the Subject header.
2958 (message-check 'subject
2959 (let* ((case-fold-search t)
2960 (subject (message-fetch-field "subject")))
2963 (not (string-match "\\`[ \t]*\\'" subject)))
2966 "The subject field is empty or missing. Posting is denied.")))))
2967 ;; Check for commands in Subject.
2968 (message-check 'subject-cmsg
2969 (if (string-match "^cmsg " (message-fetch-field "subject"))
2971 "The control code \"cmsg\" is in the subject. Really post? ")
2973 ;; Check for multiple identical headers.
2974 (message-check 'multiple-headers
2976 (while (and (not found)
2977 (re-search-forward "^[^ \t:]+: " nil t))
2979 (or (re-search-forward
2984 (match-beginning 0) (- (match-end 0) 2))))
2989 (y-or-n-p (format "Multiple %s headers. Really post? " found))
2991 ;; Check for Version and Sendsys.
2992 (message-check 'sendsys
2993 (if (re-search-forward "^Sendsys:\\|^Version:" nil t)
2995 (format "The article contains a %s command. Really post? "
2996 (buffer-substring (match-beginning 0)
2997 (1- (match-end 0)))))
2999 ;; See whether we can shorten Followup-To.
3000 (message-check 'shorten-followup-to
3001 (let ((newsgroups (message-fetch-field "newsgroups"))
3002 (followup-to (message-fetch-field "followup-to"))
3004 (when (and newsgroups
3005 (string-match "," newsgroups)
3010 (setq to (completing-read
3011 "Followups to: (default all groups) "
3012 (mapcar (lambda (g) (list g))
3014 (message-tokenize-header
3016 (goto-char (point-min))
3017 (insert "Followup-To: " to "\n"))
3019 ;; Check "Shoot me".
3020 (message-check 'shoot
3021 (if (re-search-forward
3022 "Message-ID.*.i-did-not-set--mail-host-address--so-shoot-me" nil t)
3023 (y-or-n-p "You appear to have a misconfigured system. Really post? ")
3025 ;; Check for Approved.
3026 (message-check 'approved
3027 (if (re-search-forward "^Approved:" nil t)
3028 (y-or-n-p "The article contains an Approved header. Really post? ")
3030 ;; Check the Message-ID header.
3031 (message-check 'message-id
3032 (let* ((case-fold-search t)
3033 (message-id (message-fetch-field "message-id" t)))
3034 (or (not message-id)
3035 ;; Is there an @ in the ID?
3036 (and (string-match "@" message-id)
3037 ;; Is there a dot in the ID?
3038 (string-match "@[^.]*\\." message-id)
3039 ;; Does the ID end with a dot?
3040 (not (string-match "\\.>" message-id)))
3042 (format "The Message-ID looks strange: \"%s\". Really post? "
3044 ;; Check the Newsgroups & Followup-To headers.
3045 (message-check 'existing-newsgroups
3046 (let* ((case-fold-search t)
3047 (newsgroups (message-fetch-field "newsgroups"))
3048 (followup-to (message-fetch-field "followup-to"))
3049 (groups (message-tokenize-header
3051 (concat newsgroups "," followup-to)
3053 (post-method (if (message-functionp message-post-method)
3054 (funcall message-post-method)
3055 message-post-method))
3056 ;; KLUDGE to handle nnvirtual groups. Doing this right
3057 ;; would probably involve a new nnoo function.
3058 ;; -- Per Abrahamsen <abraham@dina.kvl.dk>, 2001-10-17.
3059 (method (if (and (consp post-method)
3060 (eq (car post-method) 'nnvirtual)
3061 gnus-message-group-art)
3062 (let ((group (car (nnvirtual-find-group-art
3063 (car gnus-message-group-art)
3064 (cdr gnus-message-group-art)))))
3065 (gnus-find-method-for-group group))
3069 (gnus-group-name-decode
3070 (gnus-group-real-name n)
3071 (gnus-group-name-charset method n)))
3072 (gnus-groups-from-server method)))
3075 (unless (or (equal (car groups) "poster")
3076 (member (car groups) known-groups))
3077 (push (car groups) errors))
3080 ;; Gnus is not running.
3081 ((or (not (and (boundp 'gnus-active-hashtb)
3082 gnus-active-hashtb))
3083 (not (boundp 'gnus-read-active-file)))
3085 ;; We don't have all the group names.
3086 ((and (or (not gnus-read-active-file)
3087 (eq gnus-read-active-file 'some))
3091 "Really post to %s possibly unknown group%s: %s? "
3092 (if (= (length errors) 1) "this" "these")
3093 (if (= (length errors) 1) "" "s")
3094 (mapconcat 'identity errors ", "))))
3095 ;; There were no errors.
3098 ;; There are unknown groups.
3102 "Really post to %s unknown group%s: %s? "
3103 (if (= (length errors) 1) "this" "these")
3104 (if (= (length errors) 1) "" "s")
3105 (mapconcat 'identity errors ", ")))))))
3106 ;; Check the Newsgroups & Followup-To headers for syntax errors.
3107 (message-check 'valid-newsgroups
3108 (let ((case-fold-search t)
3109 (headers '("Newsgroups" "Followup-To"))
3111 (while (and headers (not error))
3112 (when (setq header (mail-fetch-field (car headers)))
3116 "\\`\\([-+_&.a-zA-Z0-9]+\\)?\\(,[-+_&.a-zA-Z0-9]+\\)*\\'"
3121 (not (string-match "\\.\\'\\|\\.\\." g)))
3122 (message-tokenize-header header ","))))
3129 (format "The %s header looks odd: \"%s\". Really post? "
3130 (car headers) header)))))
3131 (message-check 'repeated-newsgroups
3132 (let ((case-fold-search t)
3133 (headers '("Newsgroups" "Followup-To"))
3134 header error groups group)
3137 (when (setq header (mail-fetch-field (pop headers)))
3138 (setq groups (message-tokenize-header header ","))
3139 (while (setq group (pop groups))
3140 (when (member group groups)
3146 (format "Group %s is repeated in headers. Really post? " error)))))
3147 ;; Check the From header.
3148 (message-check 'from
3149 (let* ((case-fold-search t)
3150 (from (message-fetch-field "from"))
3154 (message "There is no From line. Posting is denied.")
3156 ((or (not (string-match
3158 (setq ad (nth 1 (mail-extract-address-components
3159 from))))) ;larsi@ifi
3160 (string-match "\\.\\." ad) ;larsi@ifi..uio
3161 (string-match "@\\." ad) ;larsi@.ifi.uio
3162 (string-match "\\.$" ad) ;larsi@ifi.uio.
3163 (not (string-match "^[^@]+@[^@]+$" ad)) ;larsi.ifi.uio
3164 (string-match "(.*).*(.*)" from)) ;(lars) (lars)
3166 "Denied posting -- the From looks strange: \"%s\"." from)
3168 ((let ((addresses (rfc822-addresses from)))
3169 (while (and addresses
3170 (not (eq (string-to-char (car addresses)) ?\()))
3171 (setq addresses (cdr addresses)))
3174 "Denied posting -- bad From address: \"%s\"." from)
3177 ;; Check the Reply-To header.
3178 (message-check 'reply-to
3179 (let* ((case-fold-search t)
3180 (reply-to (message-fetch-field "reply-to"))
3185 ((string-match "," reply-to)
3187 (format "Multiple Reply-To addresses: \"%s\". Really post? "
3189 ((or (not (string-match
3191 (setq ad (nth 1 (mail-extract-address-components
3192 reply-to))))) ;larsi@ifi
3193 (string-match "\\.\\." ad) ;larsi@ifi..uio
3194 (string-match "@\\." ad) ;larsi@.ifi.uio
3195 (string-match "\\.$" ad) ;larsi@ifi.uio.
3196 (not (string-match "^[^@]+@[^@]+$" ad)) ;larsi.ifi.uio
3197 (string-match "(.*).*(.*)" reply-to)) ;(lars) (lars)
3200 "The Reply-To looks strange: \"%s\". Really post? "
3204 (defun message-check-news-body-syntax ()
3206 ;; Check for long lines.
3207 (message-check 'long-lines
3208 (goto-char (point-min))
3210 (concat "^" (regexp-quote mail-header-separator) "$"))
3214 "<#\\(/\\)?\\(multipart\\|part\\|external\\|mml\\)")
3217 (< (- (point) p) 80)))
3218 (zerop (forward-line 1))))
3222 "You have lines longer than 79 characters. Really post? ")))
3223 ;; Check whether the article is empty.
3224 (message-check 'empty
3225 (goto-char (point-min))
3227 (concat "^" (regexp-quote mail-header-separator) "$"))
3230 (goto-char (point-max))
3231 (re-search-backward message-signature-separator nil t)
3233 (or (re-search-backward "[^ \n\t]" b t)
3234 (if (message-gnksa-enable-p 'empty-article)
3235 (y-or-n-p "Empty article. Really post? ")
3236 (message "Denied posting -- Empty article.")
3238 ;; Check for control characters.
3239 (message-check 'control-chars
3240 (if (re-search-forward "[\000-\007\013\015-\032\034-\037\200-\237]" nil t)
3242 "The article contains control characters. Really post? ")
3244 ;; Check excessive size.
3245 (message-check 'size
3246 (if (> (buffer-size) 60000)
3248 (format "The article is %d octets long. Really post? "
3251 ;; Check whether any new text has been added.
3252 (message-check 'new-text
3254 (not message-checksum)
3255 (not (eq (message-checksum) message-checksum))
3256 (if (message-gnksa-enable-p 'quoted-text-only)
3258 "It looks like no new text has been added. Really post? ")
3259 (message "Denied posting -- no new text has been added.")
3261 ;; Check the length of the signature.
3262 (message-check 'signature
3263 (goto-char (point-max))
3264 (if (> (count-lines (point) (point-max)) 5)
3267 "Your .sig is %d lines; it should be max 4. Really post? "
3268 (1- (count-lines (point) (point-max)))))
3270 ;; Ensure that text follows last quoted portion.
3271 (message-check 'quoting-style
3272 (goto-char (point-max))
3273 (let ((no-problem t))
3274 (when (search-backward-regexp "^>[^\n]*\n" nil t)
3275 (setq no-problem (search-forward-regexp "^[ \t]*[^>\n]" nil t)))
3278 (if (message-gnksa-enable-p 'quoted-text-only)
3279 (y-or-n-p "Your text should follow quoted text. Really post? ")
3281 (goto-char (point-min))
3283 (concat "^" (regexp-quote mail-header-separator) "$"))
3284 (if (search-forward-regexp "^[ \t]*[^>\n]" nil t)
3285 (y-or-n-p "Your text should follow quoted text. Really post? ")
3286 (message "Denied posting -- only quoted text.")
3289 (defun message-checksum ()
3290 "Return a \"checksum\" for the current buffer."
3293 (goto-char (point-min))
3295 (concat "^" (regexp-quote mail-header-separator) "$"))
3297 (when (not (looking-at "[ \t\n]"))
3298 (setq sum (logxor (ash sum 1) (if (natnump sum) 0 1)
3303 (defun message-do-fcc ()
3304 "Process Fcc headers in the current buffer."
3305 (let ((case-fold-search t)
3306 (buf (current-buffer))
3310 (message-narrow-to-headers)
3311 (setq file (message-fetch-field "fcc" t)))
3313 (set-buffer (get-buffer-create " *message temp*"))
3315 (insert-buffer-substring buf)
3316 (message-encode-message-body)
3318 (message-narrow-to-headers)
3319 (while (setq file (message-fetch-field "fcc" t))
3321 (message-remove-header "fcc" nil t))
3322 (let ((mail-parse-charset message-default-charset)
3323 (rfc2047-header-encoding-alist
3324 (cons '("Newsgroups" . default)
3325 rfc2047-header-encoding-alist)))
3326 (mail-encode-encoded-word-buffer)))
3327 (goto-char (point-min))
3328 (when (re-search-forward
3329 (concat "^" (regexp-quote mail-header-separator) "$")
3331 (replace-match "" t t ))
3332 ;; Process FCC operations.
3334 (setq file (pop list))
3335 (if (string-match "^[ \t]*|[ \t]*\\(.*\\)[ \t]*$" file)
3336 ;; Pipe the article to the program in question.
3337 (call-process-region (point-min) (point-max) shell-file-name
3338 nil nil nil shell-command-switch
3339 (match-string 1 file))
3340 ;; Save the article.
3341 (setq file (expand-file-name file))
3342 (unless (file-exists-p (file-name-directory file))
3343 (make-directory (file-name-directory file) t))
3344 (if (and message-fcc-handler-function
3345 (not (eq message-fcc-handler-function 'rmail-output)))
3346 (funcall message-fcc-handler-function file)
3347 (if (and (file-readable-p file) (mail-file-babyl-p file))
3348 (rmail-output file 1 nil t)
3349 (let ((mail-use-rfc822 t))
3350 (rmail-output file 1 t t))))))
3351 (kill-buffer (current-buffer))))))
3353 (defun message-output (filename)
3354 "Append this article to Unix/babyl mail file FILENAME."
3355 (if (and (file-readable-p filename)
3356 (mail-file-babyl-p filename))
3357 (gnus-output-to-rmail filename t)
3358 (gnus-output-to-mail filename t)))
3360 (defun message-cleanup-headers ()
3361 "Do various automatic cleanups of the headers."
3362 ;; Remove empty lines in the header.
3364 (message-narrow-to-headers)
3365 ;; Remove blank lines.
3366 (while (re-search-forward "^[ \t]*\n" nil t)
3367 (replace-match "" t t))
3369 ;; Correct Newsgroups and Followup-To headers: Change sequence of
3370 ;; spaces to comma and eliminate spaces around commas. Eliminate
3371 ;; embedded line breaks.
3372 (goto-char (point-min))
3373 (while (re-search-forward "^\\(Newsgroups\\|Followup-To\\): +" nil t)
3377 (if (re-search-forward "^[^ \t]" nil t)
3381 (goto-char (point-min))
3382 (while (re-search-forward "\n[ \t]+" nil t)
3383 (replace-match " " t t)) ;No line breaks (too confusing)
3384 (goto-char (point-min))
3385 (while (re-search-forward "[ \t\n]*,[ \t\n]*\\|[ \t]+" nil t)
3386 (replace-match "," t t))
3387 (goto-char (point-min))
3388 ;; Remove trailing commas.
3389 (when (re-search-forward ",+$" nil t)
3390 (replace-match "" t t))))))
3392 (defun message-make-date (&optional now)
3393 "Make a valid data header.
3394 If NOW, use that time instead."
3395 (let* ((now (or now (current-time)))
3396 (zone (nth 8 (decode-time now)))
3400 (setq zone (- zone)))
3402 ;; The day name of the %a spec is locale-specific. Pfff.
3403 (format "%s, " (capitalize (car (rassoc (nth 6 (decode-time now))
3404 parse-time-weekdays))))
3405 (format-time-string "%d" now)
3406 ;; The month name of the %b spec is locale-specific. Pfff.
3408 (capitalize (car (rassoc (nth 4 (decode-time now))
3409 parse-time-months))))
3410 (format-time-string "%Y %H:%M:%S " now)
3411 ;; We do all of this because XEmacs doesn't have the %z spec.
3412 (format "%s%02d%02d" sign (/ zone 3600) (/ (% zone 3600) 60)))))
3414 (defun message-make-message-id ()
3415 "Make a unique Message-ID."
3416 (concat "<" (message-unique-id)
3417 (let ((psubject (save-excursion (message-fetch-field "subject")))
3419 (save-excursion (message-fetch-field "supersedes"))))
3421 (and message-reply-headers
3422 (mail-header-references message-reply-headers)
3423 (mail-header-subject message-reply-headers)
3426 (message-strip-subject-re
3427 (mail-header-subject message-reply-headers))
3428 (message-strip-subject-re psubject))))
3430 (string-match "_-_@" psupersedes)))
3432 "@" (message-make-fqdn) ">"))
3434 (defvar message-unique-id-char nil)
3436 ;; If you ever change this function, make sure the new version
3437 ;; cannot generate IDs that the old version could.
3438 ;; You might for example insert a "." somewhere (not next to another dot
3439 ;; or string boundary), or modify the "fsf" string.
3440 (defun message-unique-id ()
3441 ;; Don't use microseconds from (current-time), they may be unsupported.
3442 ;; Instead we use this randomly inited counter.
3443 (setq message-unique-id-char
3444 (% (1+ (or message-unique-id-char (logand (random t) (1- (lsh 1 20)))))
3445 ;; (current-time) returns 16-bit ints,
3446 ;; and 2^16*25 just fits into 4 digits i base 36.
3448 (let ((tm (current-time)))
3450 (if (memq system-type '(ms-dos emx vax-vms))
3451 (let ((user (downcase (user-login-name))))
3452 (while (string-match "[^a-z0-9_]" user)
3453 (aset user (match-beginning 0) ?_))
3455 (message-number-base36 (user-uid) -1))
3456 (message-number-base36 (+ (car tm)
3457 (lsh (% message-unique-id-char 25) 16)) 4)
3458 (message-number-base36 (+ (nth 1 tm)
3459 (lsh (/ message-unique-id-char 25) 16)) 4)
3460 ;; Append the newsreader name, because while the generated
3461 ;; ID is unique to this newsreader, other newsreaders might
3462 ;; otherwise generate the same ID via another algorithm.
3465 (defun message-number-base36 (num len)
3470 (concat (message-number-base36 (/ num 36) (1- len))
3471 (char-to-string (aref "zyxwvutsrqponmlkjihgfedcba9876543210"
3474 (defun message-make-organization ()
3475 "Make an Organization header."
3476 (let* ((organization
3477 (when message-user-organization
3478 (if (message-functionp message-user-organization)
3479 (funcall message-user-organization)
3480 message-user-organization))))
3482 (message-set-work-buffer)
3483 (cond ((stringp organization)
3484 (insert organization))
3485 ((and (eq t organization)
3486 message-user-organization-file
3487 (file-exists-p message-user-organization-file))
3488 (insert-file-contents message-user-organization-file)))
3489 (goto-char (point-min))
3490 (while (re-search-forward "[\t\n]+" nil t)
3491 (replace-match "" t t))
3492 (unless (zerop (buffer-size))
3495 (defun message-make-lines ()
3496 "Count the number of lines and return numeric string."
3501 (int-to-string (count-lines (point) (point-max))))))
3503 (defun message-make-in-reply-to ()
3504 "Return the In-Reply-To header for this message."
3505 (when message-reply-headers
3506 (let ((from (mail-header-from message-reply-headers))
3507 (date (mail-header-date message-reply-headers))
3508 (msg-id (mail-header-message-id message-reply-headers)))
3511 (string-match " *at \\| *@ \\| *(\\| *<" from)))
3512 (concat msg-id (if msg-id " (")
3514 (not (zerop stop-pos)))
3515 (substring from 0 stop-pos) from)
3517 (if (or (not date) (string= date ""))
3518 "(unknown date)" date)
3519 "\"" (if msg-id ")")))))))
3521 (defun message-make-distribution ()
3522 "Make a Distribution header."
3523 (let ((orig-distribution (message-fetch-reply-field "distribution")))
3524 (cond ((message-functionp message-distribution-function)
3525 (funcall message-distribution-function))
3526 (t orig-distribution))))
3528 (defun message-make-expires ()
3529 "Return an Expires header based on `message-expires'."
3530 (let ((current (current-time))
3531 (future (* 1.0 message-expires 60 60 24)))
3532 ;; Add the future to current.
3533 (setcar current (+ (car current) (round (/ future (expt 2 16)))))
3534 (setcar (cdr current) (+ (nth 1 current) (% (round future) (expt 2 16))))
3535 (message-make-date current)))
3537 (defun message-make-path ()
3539 (let ((login-name (user-login-name)))
3540 (cond ((null message-user-path)
3541 (concat (system-name) "!" login-name))
3542 ((stringp message-user-path)
3543 ;; Support GENERICPATH. Suggested by vixie@decwrl.dec.com.
3544 (concat message-user-path "!" login-name))
3547 (defun message-make-from ()
3548 "Make a From header."
3549 (let* ((style message-from-style)
3550 (login (message-make-address))
3552 (or (and (boundp 'user-full-name)
3555 (when (string= fullname "&")
3556 (setq fullname (user-login-name)))
3558 (message-set-work-buffer)
3561 (equal fullname ""))
3563 ((or (eq style 'angles)
3564 (and (not (eq style 'parens))
3565 ;; Use angles if no quoting is needed, or if parens would
3566 ;; need quoting too.
3567 (or (not (string-match "[^- !#-'*+/-9=?A-Z^-~]" fullname))
3568 (let ((tmp (concat fullname nil)))
3569 (while (string-match "([^()]*)" tmp)
3570 (aset tmp (match-beginning 0) ?-)
3571 (aset tmp (1- (match-end 0)) ?-))
3572 (string-match "[\\()]" tmp)))))
3574 (goto-char (point-min))
3575 ;; Look for a character that cannot appear unquoted
3576 ;; according to RFC 822.
3577 (when (re-search-forward "[^- !#-'*+/-9=?A-Z^-~]" nil 1)
3578 ;; Quote fullname, escaping specials.
3579 (goto-char (point-min))
3581 (while (re-search-forward "[\"\\]" nil 1)
3582 (replace-match "\\\\\\&" t))
3584 (insert " <" login ">"))
3585 (t ; 'parens or default
3587 (let ((fullname-start (point)))
3589 (goto-char fullname-start)
3590 ;; RFC 822 says \ and nonmatching parentheses
3591 ;; must be escaped in comments.
3592 ;; Escape every instance of ()\ ...
3593 (while (re-search-forward "[()\\]" nil 1)
3594 (replace-match "\\\\\\&" t))
3595 ;; ... then undo escaping of matching parentheses,
3596 ;; including matching nested parentheses.
3597 (goto-char fullname-start)
3598 (while (re-search-forward
3599 "\\(\\=\\|[^\\]\\(\\\\\\\\\\)*\\)\\\\(\\(\\([^\\]\\|\\\\\\\\\\)*\\)\\\\)"
3601 (replace-match "\\1(\\3)" t)
3602 (goto-char fullname-start)))
3606 (defun message-make-sender ()
3607 "Return the \"real\" user address.
3608 This function tries to ignore all user modifications, and
3609 give as trustworthy answer as possible."
3610 (concat (user-login-name) "@" (system-name)))
3612 (defun message-make-address ()
3613 "Make the address of the user."
3614 (or (message-user-mail-address)
3615 (concat (user-login-name) "@" (message-make-domain))))
3617 (defun message-user-mail-address ()
3618 "Return the pertinent part of `user-mail-address'."
3619 (when user-mail-address
3620 (if (string-match " " user-mail-address)
3621 (nth 1 (mail-extract-address-components user-mail-address))
3622 user-mail-address)))
3624 (defun message-make-fqdn ()
3625 "Return user's fully qualified domain name."
3626 (let ((system-name (system-name))
3627 (user-mail (message-user-mail-address)))
3629 ((and (string-match "[^.]\\.[^.]" system-name)
3630 (not (string-match message-bogus-system-names system-name)))
3631 ;; `system-name' returned the right result.
3633 ;; Try `mail-host-address'.
3634 ((and (boundp 'mail-host-address)
3635 (stringp mail-host-address)
3636 (string-match "\\." mail-host-address))
3638 ;; We try `user-mail-address' as a backup.
3640 (string-match "\\." user-mail)
3641 (string-match "@\\(.*\\)\\'" user-mail))
3642 (match-string 1 user-mail))
3643 ;; Default to this bogus thing.
3645 (concat system-name ".i-did-not-set--mail-host-address--so-shoot-me")))))
3647 (defun message-make-host-name ()
3648 "Return the name of the host."
3649 (let ((fqdn (message-make-fqdn)))
3650 (string-match "^[^.]+\\." fqdn)
3651 (substring fqdn 0 (1- (match-end 0)))))
3653 (defun message-make-domain ()
3654 "Return the domain name."
3655 (or mail-host-address
3656 (message-make-fqdn)))
3658 (defun message-make-mft ()
3659 "Return the Mail-Followup-To header."
3660 (let* ((msg-recipients (message-options-get 'message-recipients))
3662 (mapcar 'mail-strip-quoted-names
3663 (message-tokenize-header msg-recipients)))
3664 (mft-regexps (apply 'append message-subscribed-regexps
3665 (mapcar 'regexp-quote
3666 message-subscribed-addresses)
3668 message-subscribed-address-functions))))
3670 (when (eval (apply 'append '(or)
3672 (function (lambda (regexp)
3674 (function (lambda (recipient)
3675 `(string-match ,regexp
3681 (defun message-generate-headers (headers)
3682 "Prepare article HEADERS.
3683 Headers already prepared in the buffer are not modified."
3685 (message-narrow-to-headers)
3686 (let* ((Date (message-make-date))
3687 (Message-ID (message-make-message-id))
3688 (Organization (message-make-organization))
3689 (From (message-make-from))
3690 (Path (message-make-path))
3693 (In-Reply-To (message-make-in-reply-to))
3695 (Distribution (message-make-distribution))
3696 (Lines (message-make-lines))
3697 (User-Agent message-newsreader)
3698 (Expires (message-make-expires))
3699 (case-fold-search t)
3701 ;; First we remove any old generated headers.
3702 (let ((headers message-deletable-headers))
3703 (unless (buffer-modified-p)
3704 (setq headers (delq 'Message-ID (copy-sequence headers))))
3706 (goto-char (point-min))
3707 (and (re-search-forward
3708 (concat "^" (symbol-name (car headers)) ": *") nil t)
3709 (get-text-property (1+ (match-beginning 0)) 'message-deletable)
3710 (message-delete-line))
3712 ;; Go through all the required headers and see if they are in the
3713 ;; articles already. If they are not, or are empty, they are
3714 ;; inserted automatically - except for Subject, Newsgroups and
3717 (goto-char (point-min))
3718 (setq elem (pop headers))
3720 (if (eq (car elem) 'optional)
3721 (setq header (cdr elem))
3722 (setq header (car elem)))
3724 (when (or (not (re-search-forward
3728 (if (stringp header)
3730 (symbol-name header))))
3734 ;; The header was found. We insert a space after the
3735 ;; colon, if there is none.
3736 (if (/= (char-after) ? ) (insert " ") (forward-char 1))
3737 ;; Find out whether the header is empty...
3738 (looking-at "[ \t]*\n[^ \t]")))
3739 ;; So we find out what value we should insert.
3742 ((and (consp elem) (eq (car elem) 'optional))
3743 ;; This is an optional header. If the cdr of this
3744 ;; is something that is nil, then we do not insert
3746 (setq header (cdr elem))
3747 (or (and (fboundp (cdr elem)) (funcall (cdr elem)))
3748 (and (boundp (cdr elem)) (symbol-value (cdr elem)))))
3750 ;; The element is a cons. Either the cdr is a
3751 ;; string to be inserted verbatim, or it is a
3752 ;; function, and we insert the value returned from
3754 (or (and (stringp (cdr elem)) (cdr elem))
3755 (and (fboundp (cdr elem)) (funcall (cdr elem)))))
3756 ((and (boundp header) (symbol-value header))
3757 ;; The element is a symbol. We insert the value
3758 ;; of this symbol, if any.
3759 (symbol-value header))
3760 ((not (message-check-element header))
3761 ;; We couldn't generate a value for this header,
3762 ;; so we just ask the user.
3763 (read-from-minibuffer
3764 (format "Empty header for %s; enter value: " header)))))
3765 ;; Finally insert the header.
3767 (not (equal value "")))
3771 ;; This header didn't exist, so we insert it.
3772 (goto-char (point-max))
3773 (insert (if (stringp header) header (symbol-name header))
3776 ;; The value of this header was empty, so we clear
3777 ;; totally and insert the new value.
3778 (delete-region (point) (gnus-point-at-eol))
3780 ;; Add the deletable property to the headers that require it.
3781 (and (memq header message-deletable-headers)
3782 (progn (beginning-of-line) (looking-at "[^:]+: "))
3783 (add-text-properties
3784 (point) (match-end 0)
3785 '(message-deletable t face italic) (current-buffer)))))))
3786 ;; Insert new Sender if the From is strange.
3787 (let ((from (message-fetch-field "from"))
3788 (sender (message-fetch-field "sender"))
3789 (secure-sender (message-make-sender)))
3791 (not (message-check-element 'sender))
3794 (cadr (mail-extract-address-components from)))
3795 (downcase secure-sender)))
3800 (cadr (mail-extract-address-components sender)))
3801 (downcase secure-sender)))))
3802 (goto-char (point-min))
3803 ;; Rename any old Sender headers to Original-Sender.
3804 (when (re-search-forward "^\\(Original-\\)*Sender:" nil t)
3806 (insert "Original-")
3807 (beginning-of-line))
3808 (when (or (message-news-p)
3809 (string-match "@.+\\.." secure-sender))
3810 (insert "Sender: " secure-sender "\n")))))))
3812 (defun message-insert-courtesy-copy ()
3813 "Insert a courtesy message in mail copies of combined messages."
3817 (message-narrow-to-headers)
3818 (when (setq newsgroups (message-fetch-field "newsgroups"))
3819 (goto-char (point-max))
3820 (insert "Posted-To: " newsgroups "\n")))
3822 (when message-courtesy-message
3824 ((string-match "%s" message-courtesy-message)
3825 (insert (format message-courtesy-message newsgroups)))
3827 (insert message-courtesy-message)))))))
3830 ;;; Setting up a message buffer
3833 (defun message-fill-address (header value)
3835 (narrow-to-region (point) (point))
3836 (insert (capitalize (symbol-name header))
3838 (if (consp value) (car value) value)
3840 (narrow-to-region (point-min) (1- (point-max)))
3842 (goto-char (point-min))
3844 (skip-chars-forward "^,\"" (point-max))
3845 (if (or (eq (char-after) ?,)
3848 (if (and (> (current-column) 78)
3854 (setq last (1+ (point))))
3855 (setq last (1+ (point)))))
3856 (setq quoted (not quoted)))
3859 (goto-char (point-max))
3863 (defun message-fill-header (header value)
3864 (let ((begin (point))
3867 (insert (capitalize (symbol-name header))
3869 (if (consp value) (car value) value)
3872 (narrow-to-region begin (point))
3873 (fill-region-as-paragraph begin (point))
3874 ;; Tapdance around looong Message-IDs.
3876 (when (looking-at "[ \t]*$")
3877 (message-delete-line))
3879 (re-search-forward ":" nil t)
3880 (when (looking-at "\n[ \t]+")
3881 (replace-match " " t t))
3882 (goto-char (point-max)))))
3884 (defun message-shorten-1 (list cut surplus)
3885 "Cut SURPLUS elements out of LIST, beginning with CUTth one."
3886 (setcdr (nthcdr (- cut 2) list)
3887 (nthcdr (+ (- cut 2) surplus 1) list)))
3889 (defun message-shorten-references (header references)
3890 "Trim REFERENCES to be 21 Message-ID long or less, and fold them.
3891 If folding is disallowed, also check that the REFERENCES are less
3892 than 988 characters long, and if they are not, trim them until they are."
3899 (goto-char (point-min))
3900 ;; Cons a list of valid references.
3901 (while (re-search-forward "<[^>]+>" nil t)
3902 (push (match-string 0) refs))
3903 (setq refs (nreverse refs)
3904 count (length refs)))
3906 ;; If the list has more than MAXCOUNT elements, trim it by
3907 ;; removing the CUTth element and the required number of
3908 ;; elements that follow.
3909 (when (> count maxcount)
3910 (let ((surplus (- count maxcount)))
3911 (message-shorten-1 refs cut surplus)
3912 (decf count surplus)))
3914 ;; If folding is disallowed, make sure the total length (including
3915 ;; the spaces between) will be less than MAXSIZE characters.
3917 ;; Only disallow folding for News messages. At this point the headers
3918 ;; have not been generated, thus we use message-this-is-news directly.
3919 (when (and message-this-is-news message-cater-to-broken-inn)
3921 (totalsize (+ (apply #'+ (mapcar #'length refs))
3924 (ptr (nthcdr (1- cut) refs)))
3925 ;; Decide how many elements to cut off...
3926 (while (> totalsize maxsize)
3927 (decf totalsize (1+ (length (car ptr))))
3929 (setq ptr (cdr ptr)))
3932 (message-shorten-1 refs cut surplus))))
3934 ;; Finally, collect the references back into a string and insert
3935 ;; it into the buffer.
3936 (let ((refstring (mapconcat #'identity refs " ")))
3937 (if (and message-this-is-news message-cater-to-broken-inn)
3938 (insert (capitalize (symbol-name header)) ": "
3940 (message-fill-header header refstring)))))
3942 (defun message-position-point ()
3943 "Move point to where the user probably wants to find it."
3944 (message-narrow-to-headers)
3946 ((re-search-forward "^[^:]+:[ \t]*$" nil t)
3947 (search-backward ":" )
3950 (if (eq (char-after) ? )
3954 (goto-char (point-max))
3957 (unless (looking-at "$")
3961 (defun message-buffer-name (type &optional to group)
3962 "Return a new (unique) buffer name based on TYPE and TO."
3964 ;; Generate a new buffer name The Message Way.
3965 ((eq message-generate-new-buffers 'unique)
3966 (generate-new-buffer-name
3970 (or (car (mail-extract-address-components to))
3973 (if (and group (not (string= group ""))) (concat " on " group) "")
3975 ;; Check whether `message-generate-new-buffers' is a function,
3976 ;; and if so, call it.
3977 ((message-functionp message-generate-new-buffers)
3978 (funcall message-generate-new-buffers type to group))
3979 ((eq message-generate-new-buffers 'unsent)
3980 (generate-new-buffer-name
3981 (concat "*unsent " type
3984 (or (car (mail-extract-address-components to))
3987 (if (and group (not (string= group ""))) (concat " on " group) "")
3989 ;; Use standard name.
3991 (format "*%s message*" type))))
3993 (defun message-pop-to-buffer (name)
3994 "Pop to buffer NAME, and warn if it already exists and is modified."
3995 (let ((buffer (get-buffer name)))
3997 (buffer-name buffer))
3999 (set-buffer (pop-to-buffer buffer))
4000 (when (and (buffer-modified-p)
4002 "Message already being composed; erase? ")))
4003 (error "Message being composed")))
4004 (set-buffer (pop-to-buffer name)))
4008 (defun message-do-send-housekeeping ()
4009 "Kill old message buffers."
4010 ;; We might have sent this buffer already. Delete it from the
4012 (setq message-buffer-list (delq (current-buffer) message-buffer-list))
4013 (while (and message-max-buffers
4015 (>= (length message-buffer-list) message-max-buffers))
4016 ;; Kill the oldest buffer -- unless it has been changed.
4017 (let ((buffer (pop message-buffer-list)))
4018 (when (and (buffer-name buffer)
4019 (not (buffer-modified-p buffer)))
4020 (kill-buffer buffer))))
4021 ;; Rename the buffer.
4022 (if message-send-rename-function
4023 (funcall message-send-rename-function)
4024 ;; Note: mail-abbrevs of XEmacs renames buffer name behind Gnus.
4026 "\\`\\*\\(sent \\|unsent \\)?\\(.+\\)\\*[^\\*]*\\|\\`mail to "
4028 (let ((name (match-string 2 (buffer-name)))
4030 (if (not (or (null name)
4031 (string-equal name "mail")
4032 (string-equal name "news")))
4033 (setq name (concat "*sent " name "*"))
4034 (message-narrow-to-headers)
4035 (setq to (message-fetch-field "to"))
4036 (setq group (message-fetch-field "newsgroups"))
4040 (to (concat "*sent mail to "
4041 (or (car (mail-extract-address-components to))
4043 ((and group (not (string= group "")))
4044 (concat "*sent news on " group "*"))
4045 (t "*sent mail*"))))
4046 (unless (string-equal name (buffer-name))
4047 (rename-buffer name t)))))
4048 ;; Push the current buffer onto the list.
4049 (when message-max-buffers
4050 (setq message-buffer-list
4051 (nconc message-buffer-list (list (current-buffer))))))
4053 (defun message-mail-user-agent ()
4055 ((not message-mail-user-agent) nil)
4056 ((eq message-mail-user-agent t) mail-user-agent)
4057 (t message-mail-user-agent))))
4058 (if (memq mua '(message-user-agent gnus-user-agent))
4062 (defun message-setup (headers &optional replybuffer actions switch-function)
4063 (let ((mua (message-mail-user-agent))
4064 subject to field yank-action)
4065 (if (not (and message-this-is-mail mua))
4066 (message-setup-1 headers replybuffer actions)
4068 (setq yank-action (list 'insert-buffer replybuffer)))
4069 (setq headers (copy-sequence headers))
4070 (setq field (assq 'Subject headers))
4072 (setq subject (cdr field))
4073 (setq headers (delq field headers)))
4074 (setq field (assq 'To headers))
4076 (setq to (cdr field))
4077 (setq headers (delq field headers)))
4078 (let ((mail-user-agent mua))
4079 (compose-mail to subject
4080 (mapcar (lambda (item)
4082 (format "%s" (car item))
4085 nil switch-function yank-action actions)))))
4087 ;;;(defvar mc-modes-alist)
4088 (defun message-setup-1 (headers &optional replybuffer actions)
4089 ;;; (when (and (boundp 'mc-modes-alist)
4090 ;;; (not (assq 'message-mode mc-modes-alist)))
4091 ;;; (push '(message-mode (encrypt . mc-encrypt-message)
4092 ;;; (sign . mc-sign-message))
4093 ;;; mc-modes-alist))
4094 (dolist (action actions)
4096 (add-to-list 'message-send-actions
4097 `(apply ',(car action) ',(cdr action)))))
4098 (setq message-reply-buffer replybuffer)
4099 (goto-char (point-min))
4100 ;; Insert all the headers.
4103 (alist message-header-format-alist))
4105 (unless (assq (caar h) message-header-format-alist)
4106 (push (list (caar h)) alist))
4110 (delete-region (point) (progn (forward-line -1) (point)))
4111 (when message-default-headers
4112 (insert message-default-headers)
4113 (or (bolp) (insert ?\n)))
4117 (insert mail-header-separator "\n")
4121 (when (message-news-p)
4122 (when message-default-news-headers
4123 (insert message-default-news-headers)
4124 (or (bolp) (insert ?\n)))
4125 (when message-generate-headers-first
4126 (message-generate-headers
4129 (copy-sequence message-required-news-headers))))))
4130 (when (message-mail-p)
4131 (when message-default-mail-headers
4132 (insert message-default-mail-headers)
4133 (or (bolp) (insert ?\n)))
4134 (when message-generate-headers-first
4135 (message-generate-headers
4138 (copy-sequence message-required-mail-headers))))))
4139 (run-hooks 'message-signature-setup-hook)
4140 (message-insert-signature)
4142 (message-narrow-to-headers)
4143 (if message-alternative-emails
4144 (message-use-alternative-email-as-from))
4145 (run-hooks 'message-header-setup-hook))
4146 (set-buffer-modified-p nil)
4147 (setq buffer-undo-list nil)
4148 (run-hooks 'message-setup-hook)
4149 (message-position-point)
4152 (defun message-set-auto-save-file-name ()
4153 "Associate the message buffer with a file in the drafts directory."
4154 (when message-auto-save-directory
4155 (unless (file-directory-p
4156 (directory-file-name message-auto-save-directory))
4157 (gnus-make-directory message-auto-save-directory))
4159 (setq message-draft-article
4160 (nndraft-request-associate-buffer "drafts"))
4161 (setq buffer-file-name (expand-file-name
4162 (if (memq system-type
4163 '(ms-dos ms-windows windows-nt
4168 message-auto-save-directory))
4169 (setq buffer-auto-save-file-name (make-auto-save-file-name)))
4170 (clear-visited-file-modtime)
4171 (setq buffer-file-coding-system message-draft-coding-system)))
4173 (defun message-disassociate-draft ()
4174 "Disassociate the message buffer from the drafts directory."
4175 (when message-draft-article
4176 (nndraft-request-expire-articles
4177 (list message-draft-article) "drafts" nil t)))
4179 (defun message-insert-headers ()
4180 "Generate the headers for the article."
4184 (message-narrow-to-headers)
4185 (when (message-news-p)
4186 (message-generate-headers
4189 (copy-sequence message-required-news-headers)))))
4190 (when (message-mail-p)
4191 (message-generate-headers
4194 (copy-sequence message-required-mail-headers))))))))
4199 ;;; Commands for interfacing with message
4203 (defun message-mail (&optional to subject
4204 other-headers continue switch-function
4205 yank-action send-actions)
4206 "Start editing a mail message to be sent.
4207 OTHER-HEADERS is an alist of header/value pairs."
4209 (let ((message-this-is-mail t) replybuffer)
4210 (unless (message-mail-user-agent)
4211 (message-pop-to-buffer (message-buffer-name "mail" to)))
4212 ;; FIXME: message-mail should do something if YANK-ACTION is not
4214 (and (consp yank-action) (eq (car yank-action) 'insert-buffer)
4215 (setq replybuffer (nth 1 yank-action)))
4218 `((To . ,(or to "")) (Subject . ,(or subject "")))
4219 (when other-headers other-headers))
4220 replybuffer send-actions)
4221 ;; FIXME: Should return nil if failure.
4225 (defun message-news (&optional newsgroups subject)
4226 "Start editing a news article to be sent."
4228 (let ((message-this-is-news t))
4229 (message-pop-to-buffer (message-buffer-name "news" nil newsgroups))
4230 (message-setup `((Newsgroups . ,(or newsgroups ""))
4231 (Subject . ,(or subject ""))))))
4233 (defun message-get-reply-headers (wide &optional to-address)
4234 (let (follow-to mct never-mct to cc author mft recipients)
4235 ;; Find all relevant headers we need.
4236 (setq to (message-fetch-field "to")
4237 cc (message-fetch-field "cc")
4238 mct (message-fetch-field "mail-copies-to")
4239 author (or (message-fetch-field "mail-reply-to")
4240 (message-fetch-field "reply-to")
4241 (message-fetch-field "from")
4243 mft (and message-use-mail-followup-to
4244 (message-fetch-field "mail-followup-to")))
4246 ;; Handle special values of Mail-Copies-To.
4248 (cond ((or (equal (downcase mct) "never")
4249 (equal (downcase mct) "nobody"))
4252 ((or (equal (downcase mct) "always")
4253 (equal (downcase mct) "poster"))
4254 (setq mct author))))
4257 ;; Build (textual) list of new recipient addresses.
4260 (setq recipients (concat ", " author)))
4262 (string-match "[^ \t,]" mft)
4263 (or (not (eq message-use-mail-followup-to 'ask))
4264 (message-y-or-n-p "Obey Mail-Followup-To? " t "\
4265 You should normally obey the Mail-Followup-To: header. In this
4266 article, it has the value of
4270 which directs your response to " (if (string-match "," mft)
4271 "the specified addresses"
4272 "that address only") ".
4274 Most commonly, Mail-Followup-To is used by a mailing list poster to
4275 express that responses should be sent to just the list, and not the
4278 If a message is posted to several mailing lists, Mail-Followup-To may
4279 also be used to direct the following discussion to one list only,
4280 because discussions that are spread over several lists tend to be
4281 fragmented and very difficult to follow.
4283 Also, some source/announcement lists are not intended for discussion;
4284 responses here are directed to other addresses.")))
4285 (setq recipients (concat ", " mft)))
4287 (setq recipients (concat ", " to-address))
4288 ;; If the author explicitly asked for a copy, we don't deny it to them.
4289 (if mct (setq recipients (concat recipients ", " mct))))
4291 (setq recipients (if never-mct "" (concat ", " author)))
4292 (if to (setq recipients (concat recipients ", " to)))
4293 (if cc (setq recipients (concat recipients ", " cc)))
4294 (if mct (setq recipients (concat recipients ", " mct)))))
4295 (if (>= (length recipients) 2)
4296 ;; Strip the leading ", ".
4297 (setq recipients (substring recipients 2)))
4298 ;; Squeeze whitespace.
4299 (while (string-match "[ \t][ \t]+" recipients)
4300 (setq recipients (replace-match " " t t recipients)))
4301 ;; Remove addresses that match `rmail-dont-reply-to-names'.
4302 (let ((rmail-dont-reply-to-names message-dont-reply-to-names))
4303 (setq recipients (rmail-dont-reply-to recipients)))
4304 ;; Perhaps "Mail-Copies-To: never" removed the only address?
4305 (if (string-equal recipients "")
4306 (setq recipients author))
4307 ;; Convert string to a list of (("foo@bar" . "Name <foo@bar>") ...).
4311 (cons (mail-strip-quoted-names addr) addr))
4312 (message-tokenize-header recipients)))
4313 ;; Remove first duplicates. (Why not all duplicates? Is this a bug?)
4314 (let ((s recipients))
4316 (setq recipients (delq (assoc (car (pop s)) s) recipients))))
4317 ;; Build the header alist. Allow the user to be asked whether
4318 ;; or not to reply to all recipients in a wide reply.
4319 (setq follow-to (list (cons 'To (cdr (pop recipients)))))
4320 (when (and recipients
4321 (or (not message-wide-reply-confirm-recipients)
4322 (y-or-n-p "Reply to all recipients? ")))
4323 (setq recipients (mapconcat
4324 (lambda (addr) (cdr addr)) recipients ", "))
4325 (if (string-match "^ +" recipients)
4326 (setq recipients (substring recipients (match-end 0))))
4327 (push (cons 'Cc recipients) follow-to)))
4331 (defun message-reply (&optional to-address wide)
4332 "Start editing a reply to the article in the current buffer."
4334 (require 'gnus-sum) ; for gnus-list-identifiers
4335 (let ((cur (current-buffer))
4336 from subject date reply-to to cc
4337 references message-id follow-to
4338 (inhibit-point-motion-hooks t)
4339 (message-this-is-mail t)
4342 (message-narrow-to-head-1)
4343 ;; Allow customizations to have their say.
4345 ;; This is a regular reply.
4346 (when (message-functionp message-reply-to-function)
4348 (setq follow-to (funcall message-reply-to-function))))
4349 ;; This is a followup.
4350 (when (message-functionp message-wide-reply-to-function)
4353 (funcall message-wide-reply-to-function)))))
4354 (setq message-id (message-fetch-field "message-id" t)
4355 references (message-fetch-field "references")
4356 date (message-fetch-field "date")
4357 from (message-fetch-field "from")
4358 subject (or (message-fetch-field "subject") "none"))
4359 (when gnus-list-identifiers
4360 (setq subject (message-strip-list-identifiers subject)))
4361 (setq subject (concat "Re: " (message-strip-subject-re subject)))
4363 (when (and (setq gnus-warning (message-fetch-field "gnus-warning"))
4364 (string-match "<[^>]+>" gnus-warning))
4365 (setq message-id (match-string 0 gnus-warning)))
4368 (setq follow-to (message-get-reply-headers wide to-address))))
4370 (unless (message-mail-user-agent)
4371 (message-pop-to-buffer
4372 (message-buffer-name
4373 (if wide "wide reply" "reply") from
4374 (if wide to-address nil))))
4376 (setq message-reply-headers
4377 (vector 0 subject from date message-id references 0 0 ""))
4380 `((Subject . ,subject)
4382 ,@(if (or references message-id)
4383 `((References . ,(concat (or references "") (and references " ")
4384 (or message-id ""))))
4389 (defun message-wide-reply (&optional to-address)
4390 "Make a \"wide\" reply to the message in the current buffer."
4392 (message-reply to-address t))
4395 (defun message-followup (&optional to-newsgroups)
4396 "Follow up to the message in the current buffer.
4397 If TO-NEWSGROUPS, use that as the new Newsgroups line."
4399 (require 'gnus-sum) ; for gnus-list-identifiers
4400 (let ((cur (current-buffer))
4401 from subject date reply-to mrt mct
4402 references message-id follow-to
4403 (inhibit-point-motion-hooks t)
4404 (message-this-is-news t)
4405 followup-to distribution newsgroups gnus-warning posted-to)
4408 (goto-char (point-min))
4409 (if (search-forward "\n\n" nil t)
4412 (when (message-functionp message-followup-to-function)
4414 (funcall message-followup-to-function)))
4415 (setq from (message-fetch-field "from")
4416 date (message-fetch-field "date")
4417 subject (or (message-fetch-field "subject") "none")
4418 references (message-fetch-field "references")
4419 message-id (message-fetch-field "message-id" t)
4420 followup-to (message-fetch-field "followup-to")
4421 newsgroups (message-fetch-field "newsgroups")
4422 posted-to (message-fetch-field "posted-to")
4423 reply-to (message-fetch-field "reply-to")
4424 mrt (message-fetch-field "mail-reply-to")
4425 distribution (message-fetch-field "distribution")
4426 mct (message-fetch-field "mail-copies-to"))
4427 (when (and (setq gnus-warning (message-fetch-field "gnus-warning"))
4428 (string-match "<[^>]+>" gnus-warning))
4429 (setq message-id (match-string 0 gnus-warning)))
4430 ;; Remove bogus distribution.
4431 (when (and (stringp distribution)
4432 (let ((case-fold-search t))
4433 (string-match "world" distribution)))
4434 (setq distribution nil))
4435 (if gnus-list-identifiers
4436 (setq subject (message-strip-list-identifiers subject)))
4437 (setq subject (concat "Re: " (message-strip-subject-re subject)))
4440 (message-pop-to-buffer (message-buffer-name "followup" from newsgroups))
4443 `((Subject . ,subject)
4446 (list (cons 'Newsgroups to-newsgroups)))
4447 (follow-to follow-to)
4448 ((and followup-to message-use-followup-to)
4451 ((equal (downcase followup-to) "poster")
4452 (if (or (eq message-use-followup-to 'use)
4453 (message-y-or-n-p "Obey Followup-To: poster? " t "\
4454 You should normally obey the Followup-To: header.
4456 `Followup-To: poster' sends your response via e-mail instead of news.
4458 A typical situation where `Followup-To: poster' is used is when the poster
4459 does not read the newsgroup, so he wouldn't see any replies sent to it."))
4461 (setq message-this-is-news nil)
4462 (cons 'To (or mrt reply-to from "")))
4463 (cons 'Newsgroups newsgroups)))
4465 (if (or (equal followup-to newsgroups)
4466 (not (eq message-use-followup-to 'ask))
4468 (concat "Obey Followup-To: " followup-to "? ") t "\
4469 You should normally obey the Followup-To: header.
4471 `Followup-To: " followup-to "'
4472 directs your response to " (if (string-match "," followup-to)
4473 "the specified newsgroups"
4474 "that newsgroup only") ".
4476 If a message is posted to several newsgroups, Followup-To is often
4477 used to direct the following discussion to one newsgroup only,
4478 because discussions that are spread over several newsgroup tend to
4479 be fragmented and very difficult to follow.
4481 Also, some source/announcement newsgroups are not intended for discussion;
4482 responses here are directed to other newsgroups."))
4483 (cons 'Newsgroups followup-to)
4484 (cons 'Newsgroups newsgroups))))))
4486 `((Newsgroups . ,posted-to)))
4488 `((Newsgroups . ,newsgroups))))
4489 ,@(and distribution (list (cons 'Distribution distribution)))
4490 ,@(if (or references message-id)
4491 `((References . ,(concat (or references "") (and references " ")
4492 (or message-id "")))))
4494 (not (or (equal (downcase mct) "never")
4495 (equal (downcase mct) "nobody"))))
4496 (list (cons 'Cc (if (or (equal (downcase mct) "always")
4497 (equal (downcase mct) "poster"))
4498 (or mrt reply-to from "")
4503 (setq message-reply-headers
4504 (vector 0 subject from date message-id references 0 0 ""))))
4508 (defun message-cancel-news (&optional arg)
4509 "Cancel an article you posted.
4510 If ARG, allow editing of the cancellation message."
4512 (unless (message-news-p)
4513 (error "This is not a news article; canceling is impossible"))
4514 (let (from newsgroups message-id distribution buf sender)
4516 ;; Get header info from original article.
4518 (message-narrow-to-head-1)
4519 (setq from (message-fetch-field "from")
4520 sender (message-fetch-field "sender")
4521 newsgroups (message-fetch-field "newsgroups")
4522 message-id (message-fetch-field "message-id" t)
4523 distribution (message-fetch-field "distribution")))
4524 ;; Make sure that this article was written by the user.
4526 ;; Canlock-logic as suggested by Per Abrahamsen
4527 ;; <abraham@dina.kvl.dk>
4529 ;; IF article has cancel-lock THEN
4530 ;; IF we can verify it THEN
4533 ;; error: cancellock: article is not yours
4535 ;; Use old rules, comparing sender...
4536 (if (message-fetch-field "Cancel-Lock")
4537 (if (null (canlock-verify))
4539 (error "Failed to verify Cancel-lock: This article is not yours"))
4541 (message-gnksa-enable-p 'cancel-messages)
4545 (downcase (message-make-sender))))
4547 (downcase (cadr (mail-extract-address-components from)))
4548 (downcase (cadr (mail-extract-address-components
4549 (message-make-from))))))
4550 (error "This article is not yours"))
4551 (when (yes-or-no-p "Do you really want to cancel this article? ")
4552 ;; Make control message.
4555 (setq buf (set-buffer (get-buffer-create " *message cancel*"))))
4557 (insert "Newsgroups: " newsgroups "\n"
4559 "Subject: cmsg cancel " message-id "\n"
4560 "Control: cancel " message-id "\n"
4562 (concat "Distribution: " distribution "\n")
4564 mail-header-separator "\n"
4565 message-cancel-message)
4566 (run-hooks 'message-cancel-hook)
4568 (message "Canceling your article...")
4569 (if (let ((message-syntax-checks
4570 'dont-check-for-anything-just-trust-me))
4571 (funcall message-send-news-function))
4572 (message "Canceling your article...done"))
4573 (kill-buffer buf))))))
4576 (defun message-supersede ()
4577 "Start composing a message to supersede the current message.
4578 This is done simply by taking the old article and adding a Supersedes
4579 header line with the old Message-ID."
4581 (let ((cur (current-buffer))
4582 (sender (message-fetch-field "sender"))
4583 (from (message-fetch-field "from")))
4584 ;; Check whether the user owns the article that is to be superseded.
4586 ;; Canlock-logic as suggested by Per Abrahamsen
4587 ;; <abraham@dina.kvl.dk>
4589 ;; IF article has cancel-lock THEN
4590 ;; IF we can verify it THEN
4593 ;; error: cancellock: article is not yours
4595 ;; Use old rules, comparing sender...
4596 (if (message-fetch-field "Cancel-Lock")
4597 (if (null (canlock-verify))
4599 (error "Failed to verify Cancel-lock: This article is not yours"))
4601 (message-gnksa-enable-p 'cancel-messages)
4605 (downcase (message-make-sender))))
4607 (downcase (cadr (mail-extract-address-components from)))
4608 (downcase (cadr (mail-extract-address-components
4609 (message-make-from))))))
4610 (error "This article is not yours"))
4611 ;; Get a normal message buffer.
4612 (message-pop-to-buffer (message-buffer-name "supersede"))
4613 (insert-buffer-substring cur)
4615 (message-narrow-to-head-1)
4616 ;; Remove unwanted headers.
4617 (when message-ignored-supersedes-headers
4618 (message-remove-header message-ignored-supersedes-headers t))
4619 (goto-char (point-min))
4620 (if (not (re-search-forward "^Message-ID: " nil t))
4621 (error "No Message-ID in this article")
4622 (replace-match "Supersedes: " t t))
4623 (goto-char (point-max))
4624 (insert mail-header-separator)
4629 (defun message-recover ()
4630 "Reread contents of current buffer from its last auto-save file."
4632 (let ((file-name (make-auto-save-file-name)))
4633 (cond ((save-window-excursion
4634 (if (not (eq system-type 'vax-vms))
4635 (with-output-to-temp-buffer "*Directory*"
4636 (with-current-buffer standard-output
4637 (fundamental-mode)) ; for Emacs 20.4+
4638 (buffer-disable-undo standard-output)
4639 (let ((default-directory "/"))
4641 "ls" nil standard-output nil "-l" file-name))))
4642 (yes-or-no-p (format "Recover auto save file %s? " file-name)))
4643 (let ((buffer-read-only nil))
4645 (insert-file-contents file-name nil)))
4646 (t (error "message-recover cancelled")))))
4648 ;;; Washing Subject:
4650 (defun message-wash-subject (subject)
4651 "Remove junk like \"Re:\", \"(fwd)\", etc. added to subject string SUBJECT.
4652 Previous forwarders, replyers, etc. may add it."
4654 (insert-string subject)
4655 (goto-char (point-min))
4656 ;; strip Re/Fwd stuff off the beginning
4657 (while (re-search-forward
4658 "\\([Rr][Ee]:\\|[Ff][Ww][Dd]\\(\\[[0-9]*\\]\\)?:\\|[Ff][Ww]:\\)" nil t)
4661 ;; and gnus-style forwards [foo@bar.com] subject
4662 (goto-char (point-min))
4663 (while (re-search-forward "\\[[^ \t]*\\(@\\|\\.\\)[^ \t]*\\]" nil t)
4667 (goto-char (point-max))
4668 (while (re-search-backward "([Ff][Ww][Dd])" nil t)
4671 ;; and finally, any whitespace that was left-over
4672 (goto-char (point-min))
4673 (while (re-search-forward "^[ \t]+" nil t)
4675 (goto-char (point-max))
4676 (while (re-search-backward "[ \t]+$" nil t)
4681 ;;; Forwarding messages.
4683 (defvar message-forward-decoded-p nil
4684 "Non-nil means the original message is decoded.")
4686 (defun message-forward-subject-author-subject (subject)
4687 "Generate a SUBJECT for a forwarded message.
4688 The form is: [Source] Subject, where if the original message was mail,
4689 Source is the sender, and if the original message was news, Source is
4690 the list of newsgroups is was posted to."
4693 (or (message-fetch-field "newsgroups")
4694 (message-fetch-field "from")
4696 (if message-forward-decoded-p
4698 (mail-decode-encoded-word-string prefix)))
4701 (defun message-forward-subject-fwd (subject)
4702 "Generate a SUBJECT for a forwarded message.
4703 The form is: Fwd: Subject, where Subject is the original subject of
4705 (concat "Fwd: " subject))
4707 (defun message-make-forward-subject ()
4708 "Return a Subject header suitable for the message in the current buffer."
4711 (message-narrow-to-head-1)
4712 (let ((funcs message-make-forward-subject-function)
4713 (subject (message-fetch-field "Subject")))
4716 (if message-forward-decoded-p
4718 (mail-decode-encoded-word-string subject))
4720 (if message-wash-forwarded-subjects
4721 (setq subject (message-wash-subject subject)))
4722 ;; Make sure funcs is a list.
4725 (setq funcs (list funcs)))
4726 ;; Apply funcs in order, passing subject generated by previous
4727 ;; func to the next one.
4729 (when (message-functionp (car funcs))
4730 (setq subject (funcall (car funcs) subject)))
4731 (setq funcs (cdr funcs)))
4735 (defvar gnus-article-decoded-p))
4739 (defun message-forward (&optional news digest)
4740 "Forward the current message via mail.
4741 Optional NEWS will use news to forward instead of mail.
4742 Optional DIGEST will use digest to forward."
4744 (let* ((cur (current-buffer))
4745 (message-forward-decoded-p
4746 (if (local-variable-p 'gnus-article-decoded-p (current-buffer))
4747 gnus-article-decoded-p ;; In an article buffer.
4748 message-forward-decoded-p))
4749 (subject (message-make-forward-subject)))
4751 (message-news nil subject)
4752 (message-mail nil subject))
4753 (message-forward-make-body cur digest)))
4756 (defun message-forward-make-body (forward-buffer &optional digest)
4757 ;; Put point where we want it before inserting the forwarded
4759 (if message-forward-before-signature
4761 (goto-char (point-max)))
4762 (if message-forward-as-mime
4764 (insert "\n<#multipart type=digest>\n")
4765 (if message-forward-show-mml
4766 (insert "\n\n<#mml type=message/rfc822 disposition=inline>\n")
4767 (insert "\n\n<#part type=message/rfc822 disposition=inline raw=t>\n")))
4768 (insert "\n-------------------- Start of forwarded message --------------------\n"))
4769 (let ((b (point)) e)
4771 (if message-forward-as-mime
4772 (insert-buffer-substring forward-buffer)
4773 (mml-insert-buffer forward-buffer))
4774 (if (and message-forward-show-mml
4775 (not message-forward-decoded-p))
4778 (mm-disable-multibyte-mule4) ;; Must copy buffer in unibyte mode
4780 (with-current-buffer forward-buffer
4781 (mm-string-as-unibyte (buffer-string))))
4782 (mm-enable-multibyte-mule4)
4784 (goto-char (point-min))
4785 (when (looking-at "From ")
4786 (replace-match "X-From-Line: "))
4789 (narrow-to-region (point) (point))
4790 (mml-insert-buffer forward-buffer)
4791 (goto-char (point-min))
4792 (when (looking-at "From ")
4793 (replace-match "X-From-Line: "))
4794 (goto-char (point-max)))))
4796 (if message-forward-as-mime
4798 (insert "<#/multipart>\n")
4799 (if message-forward-show-mml
4800 (insert "<#/mml>\n")
4801 (insert "<#/part>\n")))
4802 (insert "\n-------------------- End of forwarded message --------------------\n"))
4803 (if (and digest message-forward-as-mime)
4805 (narrow-to-region b e)
4807 (narrow-to-region (point)
4808 (or (search-forward "\n\n" nil t) (point)))
4809 (delete-region (point-min) (point-max)))
4810 (when (and (not current-prefix-arg)
4811 message-forward-ignored-headers)
4813 (narrow-to-region b e)
4815 (narrow-to-region (point)
4816 (or (search-forward "\n\n" nil t) (point)))
4817 (message-remove-header message-forward-ignored-headers t)))))
4818 (message-position-point))
4821 (defun message-forward-rmail-make-body (forward-buffer)
4822 (save-window-excursion
4823 (set-buffer forward-buffer)
4824 (let (rmail-enable-mime)
4825 (rmail-toggle-header 0)))
4826 (message-forward-make-body forward-buffer))
4829 (defun message-insinuate-rmail ()
4830 "Let RMAIL uses message to forward."
4832 (setq rmail-enable-mime-composing t)
4833 (setq rmail-insert-mime-forwarded-message-function
4834 'message-forward-rmail-make-body))
4837 (defun message-resend (address)
4838 "Resend the current article to ADDRESS."
4840 (list (message-read-from-minibuffer "Resend message to: ")))
4841 (message "Resending message to %s..." address)
4843 (let ((cur (current-buffer))
4845 ;; We first set up a normal mail buffer.
4846 (unless (message-mail-user-agent)
4847 (set-buffer (get-buffer-create " *message resend*"))
4849 (let ((message-this-is-mail t))
4850 (message-setup `((To . ,address))))
4851 ;; Insert our usual headers.
4852 (message-generate-headers '(From Date To))
4853 (message-narrow-to-headers)
4854 ;; Rename them all to "Resent-*".
4855 (while (re-search-forward "^[A-Za-z]" nil t)
4860 (delete-region (point) (point-max))
4862 ;; Insert the message to be resent.
4863 (insert-buffer-substring cur)
4864 (goto-char (point-min))
4865 (search-forward "\n\n")
4868 (narrow-to-region beg (point))
4869 (message-remove-header message-ignored-resent-headers t)
4870 (goto-char (point-max)))
4871 (insert mail-header-separator)
4872 ;; Rename all old ("Also-")Resent headers.
4873 (while (re-search-backward "^\\(Also-\\)*Resent-" beg t)
4876 ;; Quote any "From " lines at the beginning.
4878 (when (looking-at "From ")
4879 (replace-match "X-From-Line: "))
4881 (let ((message-inhibit-body-encoding t)
4882 message-required-mail-headers)
4883 (message-send-mail))
4884 (kill-buffer (current-buffer)))
4885 (message "Resending message to %s...done" address)))
4888 (defun message-bounce ()
4889 "Re-mail the current message.
4890 This only makes sense if the current message is a bounce message that
4891 contains some mail you have written which has been bounced back to
4894 (let ((handles (mm-dissect-buffer t))
4896 (message-pop-to-buffer (message-buffer-name "bounce"))
4897 (if (stringp (car handles))
4898 ;; This is a MIME bounce.
4899 (mm-insert-part (car (last handles)))
4900 ;; This is a non-MIME bounce, so we try to remove things
4902 (mm-insert-part handles)
4904 (goto-char (point-min))
4905 (search-forward "\n\n" nil t)
4906 (if (or (and (re-search-forward message-unsent-separator nil t)
4908 (re-search-forward "^Return-Path:.*\n" nil t))
4909 ;; We remove everything before the bounced mail.
4912 (if (re-search-forward "^[^ \n\t]+:" nil t)
4915 (when (re-search-backward "^.?From .*\n" nil t)
4916 (delete-region (match-beginning 0) (match-end 0)))))
4917 (mm-enable-multibyte)
4920 (message-narrow-to-head-1)
4921 (message-remove-header message-ignored-bounced-headers t)
4922 (goto-char (point-max))
4923 (insert mail-header-separator))
4924 (message-position-point)))
4927 ;;; Interactive entry points for new message buffers.
4931 (defun message-mail-other-window (&optional to subject)
4932 "Like `message-mail' command, but display mail buffer in another window."
4934 (unless (message-mail-user-agent)
4935 (let ((pop-up-windows t)
4936 (special-display-buffer-names nil)
4937 (special-display-regexps nil)
4938 (same-window-buffer-names nil)
4939 (same-window-regexps nil))
4940 (message-pop-to-buffer (message-buffer-name "mail" to))))
4941 (let ((message-this-is-mail t))
4942 (message-setup `((To . ,(or to "")) (Subject . ,(or subject "")))
4943 nil nil 'switch-to-buffer-other-window)))
4946 (defun message-mail-other-frame (&optional to subject)
4947 "Like `message-mail' command, but display mail buffer in another frame."
4949 (unless (message-mail-user-agent)
4950 (let ((pop-up-frames t)
4951 (special-display-buffer-names nil)
4952 (special-display-regexps nil)
4953 (same-window-buffer-names nil)
4954 (same-window-regexps nil))
4955 (message-pop-to-buffer (message-buffer-name "mail" to))))
4956 (let ((message-this-is-mail t))
4957 (message-setup `((To . ,(or to "")) (Subject . ,(or subject "")))
4958 nil nil 'switch-to-buffer-other-frame)))
4961 (defun message-news-other-window (&optional newsgroups subject)
4962 "Start editing a news article to be sent."
4964 (let ((pop-up-windows t)
4965 (special-display-buffer-names nil)
4966 (special-display-regexps nil)
4967 (same-window-buffer-names nil)
4968 (same-window-regexps nil))
4969 (message-pop-to-buffer (message-buffer-name "news" nil newsgroups)))
4970 (let ((message-this-is-news t))
4971 (message-setup `((Newsgroups . ,(or newsgroups ""))
4972 (Subject . ,(or subject ""))))))
4975 (defun message-news-other-frame (&optional newsgroups subject)
4976 "Start editing a news article to be sent."
4978 (let ((pop-up-frames t)
4979 (special-display-buffer-names nil)
4980 (special-display-regexps nil)
4981 (same-window-buffer-names nil)
4982 (same-window-regexps nil))
4983 (message-pop-to-buffer (message-buffer-name "news" nil newsgroups)))
4984 (let ((message-this-is-news t))
4985 (message-setup `((Newsgroups . ,(or newsgroups ""))
4986 (Subject . ,(or subject ""))))))
4990 ;; This code should be moved to underline.el (from which it is stolen).
4993 (defun bold-region (start end)
4994 "Bold all nonblank characters in the region.
4995 Works by overstriking characters.
4996 Called from program, takes two arguments START and END
4997 which specify the range to operate on."
5000 (let ((end1 (make-marker)))
5001 (move-marker end1 (max start end))
5002 (goto-char (min start end))
5003 (while (< (point) end1)
5004 (or (looking-at "[_\^@- ]")
5005 (insert (char-after) "\b"))
5006 (forward-char 1)))))
5009 (defun unbold-region (start end)
5010 "Remove all boldness (overstruck characters) in the region.
5011 Called from program, takes two arguments START and END
5012 which specify the range to operate on."
5015 (let ((end1 (make-marker)))
5016 (move-marker end1 (max start end))
5017 (goto-char (min start end))
5018 (while (re-search-forward "\b" end1 t)
5019 (if (eq (char-after) (char-after (- (point) 2)))
5020 (delete-char -2))))))
5022 (defalias 'message-exchange-point-and-mark 'exchange-point-and-mark)
5024 ;; Support for toolbar
5026 (defvar tool-bar-map)
5027 (defvar tool-bar-mode))
5029 (defun message-tool-bar-map ()
5030 (or message-tool-bar-map
5031 (setq message-tool-bar-map
5032 (and (fboundp 'tool-bar-add-item-from-menu)
5034 (let ((tool-bar-map (copy-keymap tool-bar-map))
5035 (load-path (mm-image-load-path)))
5036 ;; Zap some items which aren't so relevant and take
5038 (dolist (key '(print-buffer kill-buffer save-buffer
5039 write-file dired open-file))
5040 (define-key tool-bar-map (vector key) nil))
5041 (tool-bar-add-item-from-menu
5042 'message-send-and-exit "mail_send" message-mode-map)
5043 (tool-bar-add-item-from-menu
5044 'message-kill-buffer "close" message-mode-map)
5045 (tool-bar-add-item-from-menu
5046 'message-dont-send "cancel" message-mode-map)
5047 (tool-bar-add-item-from-menu
5048 'mml-attach-file "attach" message-mode-map)
5049 (tool-bar-add-item-from-menu
5050 'ispell-message "spell" message-mode-map)
5053 ;;; Group name completion.
5055 (defvar message-newgroups-header-regexp
5056 "^\\(Newsgroups\\|Followup-To\\|Posted-To\\|Gcc\\):"
5057 "Regexp that match headers that lists groups.")
5059 (defvar message-completion-alist
5060 (list (cons message-newgroups-header-regexp 'message-expand-group)
5061 '("^\\(Resent-\\)?\\(To\\|B?Cc\\):" . message-expand-name))
5062 "Alist of (RE . FUN). Use FUN for completion on header lines matching RE.")
5064 (defvar message-tab-body-function 'indent-relative
5065 "*Function to execute when `message-tab' (TAB) is executed in the body.")
5067 (defun message-tab ()
5068 "Complete names according to `message-completion-alist'.
5069 Do an `indent-relative' if not in those headers."
5071 (let ((alist message-completion-alist))
5073 (let ((mail-abbrev-mode-regexp (caar alist)))
5074 (not (mail-abbrev-in-expansion-header-p))))
5075 (setq alist (cdr alist)))
5076 (funcall (or (cdar alist) message-tab-body-function))))
5078 (defun message-expand-group ()
5079 "Expand the group name under point."
5080 (let* ((b (save-excursion
5085 (skip-chars-forward "^:")
5088 (skip-chars-backward "^, \t\n") (point))))
5089 (completion-ignore-case t)
5090 (string (buffer-substring b (progn (skip-chars-forward "^,\t\n ")
5092 (hashtb (and (boundp 'gnus-active-hashtb) gnus-active-hashtb))
5093 (completions (all-completions string hashtb))
5095 (delete-region b (point))
5097 ((= (length completions) 1)
5098 (if (string= (car completions) string)
5101 (message "Only matching group"))
5102 (insert (car completions))))
5103 ((and (setq comp (try-completion string hashtb))
5104 (not (string= comp string)))
5109 (message "No matching groups")
5110 (save-selected-window
5111 (pop-to-buffer "*Completions*")
5112 (buffer-disable-undo)
5113 (let ((buffer-read-only nil))
5115 (let ((standard-output (current-buffer)))
5116 (display-completion-list (sort completions 'string<)))
5117 (goto-char (point-min))
5118 (delete-region (point) (progn (forward-line 3) (point))))))))))
5120 (defun message-expand-name ()
5121 (if (fboundp 'bbdb-complete-name)
5122 (bbdb-complete-name)
5127 (defun message-talkative-question (ask question show &rest text)
5128 "Call FUNCTION with argument QUESTION; optionally display TEXT... args.
5129 If SHOW is non-nil, the arguments TEXT... are displayed in a temp buffer.
5130 The following arguments may contain lists of values."
5132 (setq text (message-flatten-list text)))
5133 (save-window-excursion
5135 (with-output-to-temp-buffer " *MESSAGE information message*"
5136 (set-buffer " *MESSAGE information message*")
5137 (fundamental-mode) ; for Emacs 20.4+
5138 (mapcar 'princ text)
5139 (goto-char (point-min))))
5140 (funcall ask question))
5141 (funcall ask question)))
5143 (defun message-flatten-list (list)
5144 "Return a new, flat list that contains all elements of LIST.
5146 \(message-flatten-list '(1 (2 3 (4 5 (6))) 7))
5149 (apply 'append (mapcar 'message-flatten-list list)))
5153 (defun message-generate-new-buffer-clone-locals (name &optional varstr)
5154 "Create and return a buffer with name based on NAME using `generate-new-buffer.'
5155 Then clone the local variables and values from the old buffer to the
5156 new one, cloning only the locals having a substring matching the
5158 (let ((oldbuf (current-buffer)))
5160 (set-buffer (generate-new-buffer name))
5161 (message-clone-locals oldbuf varstr)
5164 (defun message-clone-locals (buffer &optional varstr)
5165 "Clone the local variables from BUFFER to the current buffer."
5166 (let ((locals (save-excursion
5168 (buffer-local-variables)))
5169 (regexp "^gnus\\|^nn\\|^message\\|^user-mail-address"))
5172 (when (and (consp local)
5174 (string-match regexp (symbol-name (car local)))
5176 (string-match varstr (symbol-name (car local)))))
5178 (set (make-local-variable (car local))
5182 ;;; Miscellaneous functions
5184 (defsubst message-replace-chars-in-string (string from to)
5185 (mm-subst-char-in-string from to string))
5191 (defvar message-inhibit-body-encoding nil)
5193 (defun message-encode-message-body ()
5194 (unless message-inhibit-body-encoding
5195 (let ((mail-parse-charset (or mail-parse-charset
5196 message-default-charset))
5197 (case-fold-search t)
5198 lines content-type-p)
5201 (narrow-to-region (point) (point-max))
5202 (let ((new (mml-generate-mime)))
5204 (delete-region (point-min) (point-max))
5206 (goto-char (point-min))
5207 (if (eq (aref new 0) ?\n)
5209 (search-forward "\n\n")
5210 (setq lines (buffer-substring (point-min) (1- (point))))
5211 (delete-region (point-min) (point))))))
5213 (message-narrow-to-headers-or-head)
5214 (message-remove-header "Mime-Version")
5215 (goto-char (point-max))
5216 (insert "MIME-Version: 1.0\n")
5219 (setq content-type-p
5221 (re-search-backward "^Content-Type:" nil t))))
5223 (message-narrow-to-headers-or-head)
5224 (message-remove-first-header "Content-Type")
5225 (message-remove-first-header "Content-Transfer-Encoding"))
5226 ;; We always make sure that the message has a Content-Type header.
5227 ;; This is because some broken MTAs and MUAs get awfully confused
5228 ;; when confronted with a message with a MIME-Version header and
5229 ;; without a Content-Type header. For instance, Solaris'
5231 (unless content-type-p
5232 (goto-char (point-min))
5233 ;; For unknown reason, MIME-Version doesn't exist.
5234 (when (re-search-forward "^MIME-Version:" nil t)
5236 (insert "Content-Type: text/plain; charset=us-ascii\n"))))))
5238 (defun message-read-from-minibuffer (prompt)
5239 "Read from the minibuffer while providing abbrev expansion."
5240 (if (fboundp 'mail-abbrevs-setup)
5241 (let ((mail-abbrev-mode-regexp "")
5242 (minibuffer-setup-hook 'mail-abbrevs-setup)
5243 (minibuffer-local-map message-minibuffer-local-map))
5244 (read-from-minibuffer prompt))
5245 (let ((minibuffer-setup-hook 'mail-abbrev-minibuffer-setup-hook)
5246 (minibuffer-local-map message-minibuffer-local-map))
5247 (read-string prompt))))
5249 (defun message-use-alternative-email-as-from ()
5250 (require 'mail-utils)
5251 (let* ((fields '("To" "Cc"))
5254 (mail-strip-quoted-names
5255 (mapconcat 'message-fetch-reply-field fields ","))
5259 (if (string-match message-alternative-emails (car emails))
5260 (setq email (car emails)
5263 (unless (or (not email) (equal email user-mail-address))
5264 (goto-char (point-max))
5265 (insert "From: " email "\n"))))
5267 (defun message-options-get (symbol)
5268 (cdr (assq symbol message-options)))
5270 (defun message-options-set (symbol value)
5271 (let ((the-cons (assq symbol message-options)))
5274 (setcdr the-cons value)
5275 (setq message-options (delq the-cons message-options)))
5277 (push (cons symbol value) message-options))))
5280 (defun message-options-set-recipient ()
5282 (message-narrow-to-headers-or-head)
5283 (message-options-set 'message-sender
5284 (mail-strip-quoted-names
5285 (message-fetch-field "from")))
5286 (message-options-set 'message-recipients
5287 (mail-strip-quoted-names
5288 (let ((to (message-fetch-field "to"))
5289 (cc (message-fetch-field "cc"))
5290 (bcc (message-fetch-field "bcc")))
5293 (if (and to cc) ", ")
5295 (if (and (or to cc) bcc) ", ")
5298 (when (featurep 'xemacs)
5299 (require 'messagexmas)
5300 (message-xmas-redefine))
5304 (run-hooks 'message-load-hook)
5307 ;; coding: iso-8859-1
5310 ;;; message.el ends here