1 ;;; message.el --- composing mail and news messages
2 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
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-message-group-art)
36 (defvar gnus-list-identifiers)) ; gnus-sum is required where necessary
40 ;; This is apparently necessary even though things are autoloaded.
41 ;; Because we dynamically bind mail-abbrev-mode-regexp, we'd better
42 ;; require mailabbrev here.
43 (if (featurep 'xemacs)
44 (require 'mail-abbrevs)
45 (require 'mailabbrev))
50 (autoload 'sha1 "sha1-el")
51 (autoload 'gnus-find-method-for-group "gnus")
52 (autoload 'nnvirtual-find-group-art "nnvirtual")
53 (autoload 'gnus-group-decoded-name "gnus-group"))
55 (defgroup message '((user-mail-address custom-variable)
56 (user-full-name custom-variable))
57 "Mail and news message composing."
58 :link '(custom-manual "(message)Top")
62 (put 'user-mail-address 'custom-type 'string)
63 (put 'user-full-name 'custom-type 'string)
65 (defgroup message-various nil
66 "Various Message Variables"
67 :link '(custom-manual "(message)Various Message Variables")
70 (defgroup message-buffers nil
72 :link '(custom-manual "(message)Message Buffers")
75 (defgroup message-sending nil
77 :link '(custom-manual "(message)Sending Variables")
80 (defgroup message-interface nil
82 :link '(custom-manual "(message)Interface")
85 (defgroup message-forwarding nil
87 :link '(custom-manual "(message)Forwarding")
88 :group 'message-interface)
90 (defgroup message-insertion nil
92 :link '(custom-manual "(message)Insertion")
95 (defgroup message-headers nil
97 :link '(custom-manual "(message)Message Headers")
100 (defgroup message-news nil
101 "Composing News Messages"
104 (defgroup message-mail nil
105 "Composing Mail Messages"
108 (defgroup message-faces nil
109 "Faces used for message composing."
113 (defcustom message-directory "~/Mail/"
114 "*Directory from which all other mail file variables are derived."
115 :group 'message-various
118 (defcustom message-max-buffers 10
119 "*How many buffers to keep before starting to kill them off."
120 :group 'message-buffers
123 (defcustom message-send-rename-function nil
124 "Function called to rename the buffer after sending it."
125 :group 'message-buffers
126 :type '(choice function (const nil)))
128 (defcustom message-fcc-handler-function 'message-output
129 "*A function called to save outgoing articles.
130 This function will be called with the name of the file to store the
131 article in. The default function is `message-output' which saves in Unix
133 :type '(radio (function-item message-output)
134 (function :tag "Other"))
135 :group 'message-sending)
137 (defcustom message-fcc-externalize-attachments nil
138 "If non-nil, attachments are included as external parts in Fcc copies."
140 :group 'message-sending)
142 (defcustom message-courtesy-message
143 "The following message is a courtesy copy of an article\nthat has been posted to %s as well.\n\n"
144 "*This is inserted at the start of a mailed copy of a posted message.
145 If the string contains the format spec \"%s\", the Newsgroups
146 the article has been posted to will be inserted there.
147 If this variable is nil, no such courtesy message will be added."
148 :group 'message-sending
149 :type '(radio (string :format "%t: %v\n" :size 0) (const nil)))
151 (defcustom message-ignored-bounced-headers
152 "^\\(Received\\|Return-Path\\|Delivered-To\\):"
153 "*Regexp that matches headers to be removed in resent bounced mail."
154 :group 'message-interface
158 (defcustom message-from-style 'default
159 "*Specifies how \"From\" headers look.
161 If nil, they contain just the return address like:
163 If `parens', they look like:
164 king@grassland.com (Elvis Parsley)
165 If `angles', they look like:
166 Elvis Parsley <king@grassland.com>
168 Otherwise, most addresses look like `angles', but they look like
169 `parens' if `angles' would need quoting and `parens' would not."
170 :type '(choice (const :tag "simple" nil)
174 :group 'message-headers)
176 (defcustom message-insert-canlock t
177 "Whether to insert a Cancel-Lock header in news postings."
179 :group 'message-headers
182 (defcustom message-syntax-checks
183 (if message-insert-canlock '((sender . disabled)) nil)
184 ;; Guess this one shouldn't be easy to customize...
185 "*Controls what syntax checks should not be performed on outgoing posts.
186 To disable checking of long signatures, for instance, add
187 `(signature . disabled)' to this list.
189 Don't touch this variable unless you really know what you're doing.
191 Checks include `subject-cmsg', `multiple-headers', `sendsys',
192 `message-id', `from', `long-lines', `control-chars', `size',
193 `new-text', `quoting-style', `redirected-followup', `signature',
194 `approved', `sender', `empty', `empty-headers', `message-id', `from',
195 `subject', `shorten-followup-to', `existing-newsgroups',
196 `buffer-file-name', `unchanged', `newsgroups', `reply-to',
197 `continuation-headers', `long-header-lines', `invisible-text' and
200 :type '(repeat sexp)) ; Fixme: improve this
202 (defcustom message-required-headers '((optional . References)
204 "*Headers to be generated or prompted for when sending a message.
205 Also see `message-required-news-headers' and
206 `message-required-mail-headers'."
208 :group 'message-headers
209 :type '(repeat sexp))
211 (defcustom message-draft-headers '(References From)
212 "*Headers to be generated when saving a draft message."
214 :group 'message-headers
215 :type '(repeat sexp))
217 (defcustom message-required-news-headers
218 '(From Newsgroups Subject Date Message-ID
219 (optional . Organization)
220 (optional . User-Agent))
221 "*Headers to be generated or prompted for when posting an article.
222 RFC977 and RFC1036 require From, Date, Newsgroups, Subject,
223 Message-ID. Organization, Lines, In-Reply-To, Expires, and
224 User-Agent are optional. If don't you want message to insert some
225 header, remove it from this list."
227 :group 'message-headers
228 :type '(repeat sexp))
230 (defcustom message-required-mail-headers
231 '(From Subject Date (optional . In-Reply-To) Message-ID
232 (optional . User-Agent))
233 "*Headers to be generated or prompted for when mailing a message.
234 It is recommended that From, Date, To, Subject and Message-ID be
235 included. Organization and User-Agent are optional."
237 :group 'message-headers
238 :type '(repeat sexp))
240 (defcustom message-deletable-headers '(Message-ID Date Lines)
241 "Headers to be deleted if they already exist and were generated by message previously."
242 :group 'message-headers
245 (defcustom message-ignored-news-headers
246 "^NNTP-Posting-Host:\\|^Xref:\\|^[BGF]cc:\\|^Resent-Fcc:\\|^X-Draft-From:\\|^X-Gnus-Agent-Meta-Information:"
247 "*Regexp of headers to be removed unconditionally before posting."
249 :group 'message-headers
252 (defcustom message-ignored-mail-headers
253 "^[GF]cc:\\|^Resent-Fcc:\\|^Xref:\\|^X-Draft-From:\\|^X-Gnus-Agent-Meta-Information:"
254 "*Regexp of headers to be removed unconditionally before mailing."
256 :group 'message-headers
259 (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:\\|^X-Hashcash:\\|^X-Payment:"
260 "*Header lines matching this regexp will be deleted before posting.
261 It's best to delete old Path and Date headers before posting to avoid
263 :group 'message-interface
266 (defcustom message-subject-re-regexp
267 "^[ \t]*\\([Rr][Ee]\\(\\[[0-9]*\\]\\)*:[ \t]*\\)*[ \t]*"
268 "*Regexp matching \"Re: \" in the subject line."
269 :group 'message-various
272 ;;; Start of variables adopted from `message-utils.el'.
274 (defcustom message-subject-trailing-was-query 'ask
275 ;; should it default to nil or ask?
276 "*What to do with trailing \"(was: <old subject>)\" in subject lines.
277 If nil, leave the subject unchanged. If it is the symbol `ask', query
278 the user what do do. In this case, the subject is matched against
279 `message-subject-trailing-was-ask-regexp'. If
280 `message-subject-trailing-was-query' is t, always strip the trailing
281 old subject. In this case, `message-subject-trailing-was-regexp' is
283 :type '(choice (const :tag "never" nil)
284 (const :tag "always strip" t)
286 :group 'message-various)
288 (defcustom message-subject-trailing-was-ask-regexp
289 "[ \t]*\\([[(]+[Ww][Aa][Ss][ \t]*.*[\])]+\\)"
290 "*Regexp matching \"(was: <old subject>)\" in the subject line.
292 The function `message-strip-subject-trailing-was' uses this regexp if
293 `message-subject-trailing-was-query' is set to the symbol `ask'. If
294 the variable is t instead of `ask', use
295 `message-subject-trailing-was-regexp' instead.
297 It is okay to create some false positives here, as the user is asked."
298 :group 'message-various
301 (defcustom message-subject-trailing-was-regexp
302 "[ \t]*\\((*[Ww][Aa][Ss]:[ \t]*.*)\\)"
303 "*Regexp matching \"(was: <old subject>)\" in the subject line.
305 If `message-subject-trailing-was-query' is set to t, the subject is
306 matched against `message-subject-trailing-was-regexp' in
307 `message-strip-subject-trailing-was'. You should use a regexp creating very
308 few false positives here."
309 :group 'message-various
312 ;; Fixme: Why are all these things autoloaded?
314 ;;; marking inserted text
317 (defcustom message-mark-insert-begin
318 "--8<---------------cut here---------------start------------->8---\n"
319 "How to mark the beginning of some inserted text."
321 :group 'message-various)
324 (defcustom message-mark-insert-end
325 "--8<---------------cut here---------------end--------------->8---\n"
326 "How to mark the end of some inserted text."
328 :group 'message-various)
331 (defcustom message-archive-header
332 "X-No-Archive: Yes\n"
333 "Header to insert when you don't want your article to be archived.
334 Archives \(such as groups.google.com\) respect this header."
336 :group 'message-various)
339 (defcustom message-archive-note
340 "X-No-Archive: Yes - save http://groups.google.com/"
341 "Note to insert why you wouldn't want this posting archived.
342 If nil, don't insert any text in the body."
343 :type '(radio (string :format "%t: %v\n" :size 0)
345 :group 'message-various)
347 ;;; Crossposts and Followups
348 ;; inspired by JoH-followup-to by Jochem Huhman <joh at gmx.de>
349 ;; new suggestions by R. Weikusat <rw at another.de>
351 (defvar message-cross-post-old-target nil
352 "Old target for cross-posts or follow-ups.")
353 (make-variable-buffer-local 'message-cross-post-old-target)
356 (defcustom message-cross-post-default t
357 "When non-nil `message-cross-post-followup-to' will perform a crosspost.
358 If nil, `message-cross-post-followup-to' will only do a followup. Note that
359 you can explicitly override this setting by calling
360 `message-cross-post-followup-to' with a prefix."
362 :group 'message-various)
365 (defcustom message-cross-post-note
366 "Crosspost & Followup-To: "
367 "Note to insert before signature to notify of cross-post and follow-up."
369 :group 'message-various)
372 (defcustom message-followup-to-note
374 "Note to insert before signature to notify of follow-up only."
376 :group 'message-various)
379 (defcustom message-cross-post-note-function
380 'message-cross-post-insert-note
381 "Function to use to insert note about Crosspost or Followup-To.
382 The function will be called with four arguments. The function should not only
383 insert a note, but also ensure old notes are deleted. See the documentation
384 for `message-cross-post-insert-note'."
386 :group 'message-various)
388 ;;; End of variables adopted from `message-utils.el'.
391 (defcustom message-signature-separator "^-- *$"
392 "Regexp matching the signature separator."
394 :group 'message-various)
396 (defcustom message-elide-ellipsis "\n[...]\n\n"
397 "*The string which is inserted for elided text."
399 :group 'message-various)
401 (defcustom message-interactive t
402 "Non-nil means when sending a message wait for and display errors.
403 nil means let mailer mail back a message to report errors."
404 :group 'message-sending
408 (defcustom message-generate-new-buffers 'unique
409 "*Non-nil means create a new message buffer whenever `message-setup' is called.
410 If this is a function, call that function with three parameters: The type,
411 the to address and the group name. (Any of these may be nil.) The function
412 should return the new buffer name."
413 :group 'message-buffers
414 :type '(choice (const :tag "off" nil)
415 (const :tag "unique" unique)
416 (const :tag "unsent" unsent)
419 (defcustom message-kill-buffer-on-exit nil
420 "*Non-nil means that the message buffer will be killed after sending a message."
421 :group 'message-buffers
425 (defvar gnus-local-organization))
426 (defcustom message-user-organization
427 (or (and (boundp 'gnus-local-organization)
428 (stringp gnus-local-organization)
429 gnus-local-organization)
430 (getenv "ORGANIZATION")
432 "*String to be used as an Organization header.
433 If t, use `message-user-organization-file'."
434 :group 'message-headers
435 :type '(choice string
436 (const :tag "consult file" t)))
439 (defcustom message-user-organization-file "/usr/lib/news/organization"
440 "*Local news organization file."
442 :group 'message-headers)
444 (defcustom message-make-forward-subject-function
445 #'message-forward-subject-name-subject
446 "*List of functions called to generate subject headers for forwarded messages.
447 The subject generated by the previous function is passed into each
450 The provided functions are:
452 * `message-forward-subject-author-subject' Source of article (author or
453 newsgroup), in brackets followed by the subject
454 * `message-forward-subject-name-subject' Source of article (name of author
455 or newsgroup), in brackets followed by the subject
456 * `message-forward-subject-fwd' Subject of article with 'Fwd:' prepended
458 :group 'message-forwarding
459 :type '(radio (function-item message-forward-subject-author-subject)
460 (function-item message-forward-subject-fwd)
461 (function-item message-forward-subject-name-subject)
462 (repeat :tag "List of functions" function)))
464 (defcustom message-forward-as-mime t
465 "*Non-nil means forward messages as an inline/rfc822 MIME section.
466 Otherwise, directly inline the old message in the forwarded message."
468 :group 'message-forwarding
471 (defcustom message-forward-show-mml 'best
472 "*Non-nil means show forwarded messages as MML (decoded from MIME).
473 Otherwise, forwarded messages are unchanged.
474 Can also be the symbol `best' to indicate that MML should be
475 used, except when it is a bad idea to use MML. One example where
476 it is a bad idea is when forwarding a signed or encrypted
477 message, because converting MIME to MML would invalidate the
480 :group 'message-forwarding
481 :type '(choice (const :tag "use MML" t)
482 (const :tag "don't use MML " nil)
483 (const :tag "use MML when appropriate" best)))
485 (defcustom message-forward-before-signature t
486 "*Non-nil means put forwarded message before signature, else after."
487 :group 'message-forwarding
490 (defcustom message-wash-forwarded-subjects nil
491 "*Non-nil means try to remove as much cruft as possible from the subject.
492 Done before generating the new subject of a forward."
493 :group 'message-forwarding
496 (defcustom message-ignored-resent-headers "^Return-receipt\\|^X-Gnus\\|^Gnus-Warning:\\|^>?From "
497 "*All headers that match this regexp will be deleted when resending a message."
498 :group 'message-interface
501 (defcustom message-forward-ignored-headers "^Content-Transfer-Encoding:\\|^X-Gnus"
502 "*All headers that match this regexp will be deleted when forwarding a message."
504 :group 'message-forwarding
505 :type '(choice (const :tag "None" nil)
508 (defcustom message-ignored-cited-headers "."
509 "*Delete these headers from the messages you yank."
510 :group 'message-insertion
513 (defcustom message-cite-prefix-regexp
514 (if (string-match "[[:digit:]]" "1") ;; support POSIX?
515 "\\([ \t]*[-_.[:word:]]+>+\\|[ \t]*[]>|}+]\\)+"
516 ;; ?-, ?_ or ?. MUST NOT be in syntax entry w.
517 (let ((old-table (syntax-table))
518 non-word-constituents)
519 (set-syntax-table text-mode-syntax-table)
520 (setq non-word-constituents
522 (if (string-match "\\w" "-") "" "-")
523 (if (string-match "\\w" "_") "" "_")
524 (if (string-match "\\w" ".") "" ".")))
525 (set-syntax-table old-table)
526 (if (equal non-word-constituents "")
527 "\\([ \t]*\\(\\w\\)+>+\\|[ \t]*[]>|}+]\\)+"
528 (concat "\\([ \t]*\\(\\w\\|["
529 non-word-constituents
530 "]\\)+>+\\|[ \t]*[]>|}+]\\)+"))))
531 "*Regexp matching the longest possible citation prefix on a line."
532 :group 'message-insertion
535 (defcustom message-cancel-message "I am canceling my own article.\n"
536 "Message to be inserted in the cancel message."
537 :group 'message-interface
540 ;; Useful to set in site-init.el
542 (defcustom message-send-mail-function 'message-send-mail-with-sendmail
543 "Function to call to send the current buffer as mail.
544 The headers should be delimited by a line whose contents match the
545 variable `mail-header-separator'.
547 Valid values include `message-send-mail-with-sendmail' (the default),
548 `message-send-mail-with-mh', `message-send-mail-with-qmail',
549 `message-smtpmail-send-it', `smtpmail-send-it' and `feedmail-send-it'.
551 See also `send-mail-function'."
552 :type '(radio (function-item message-send-mail-with-sendmail)
553 (function-item message-send-mail-with-mh)
554 (function-item message-send-mail-with-qmail)
555 (function-item message-smtpmail-send-it)
556 (function-item smtpmail-send-it)
557 (function-item feedmail-send-it)
558 (function :tag "Other"))
559 :group 'message-sending
560 :group 'message-mail)
562 (defcustom message-send-news-function 'message-send-news
563 "Function to call to send the current buffer as news.
564 The headers should be delimited by a line whose contents match the
565 variable `mail-header-separator'."
566 :group 'message-sending
570 (defcustom message-reply-to-function nil
571 "If non-nil, function that should return a list of headers.
572 This function should pick out addresses from the To, Cc, and From headers
573 and respond with new To and Cc headers."
574 :group 'message-interface
575 :type '(choice function (const nil)))
577 (defcustom message-wide-reply-to-function nil
578 "If non-nil, function that should return a list of headers.
579 This function should pick out addresses from the To, Cc, and From headers
580 and respond with new To and Cc headers."
581 :group 'message-interface
582 :type '(choice function (const nil)))
584 (defcustom message-followup-to-function nil
585 "If non-nil, function that should return a list of headers.
586 This function should pick out addresses from the To, Cc, and From headers
587 and respond with new To and Cc headers."
588 :group 'message-interface
589 :type '(choice function (const nil)))
591 (defcustom message-use-followup-to 'ask
592 "*Specifies what to do with Followup-To header.
593 If nil, always ignore the header. If it is t, use its value, but
594 query before using the \"poster\" value. If it is the symbol `ask',
595 always query the user whether to use the value. If it is the symbol
596 `use', always use the value."
597 :group 'message-interface
598 :type '(choice (const :tag "ignore" nil)
599 (const :tag "use & query" t)
603 (defcustom message-use-mail-followup-to 'use
604 "*Specifies what to do with Mail-Followup-To header.
605 If nil, always ignore the header. If it is the symbol `ask', always
606 query the user whether to use the value. If it is the symbol `use',
607 always use the value."
608 :group 'message-interface
609 :type '(choice (const :tag "ignore" nil)
613 (defcustom message-subscribed-address-functions nil
614 "*Specifies functions for determining list subscription.
615 If nil, do not attempt to determine list subscription with functions.
616 If non-nil, this variable contains a list of functions which return
617 regular expressions to match lists. These functions can be used in
618 conjunction with `message-subscribed-regexps' and
619 `message-subscribed-addresses'."
620 :group 'message-interface
621 :type '(repeat sexp))
623 (defcustom message-subscribed-address-file nil
624 "*A file containing addresses the user is subscribed to.
625 If nil, do not look at any files to determine list subscriptions. If
626 non-nil, each line of this file should be a mailing list address."
627 :group 'message-interface
628 :type '(radio (file :format "%t: %v\n" :size 0)
631 (defcustom message-subscribed-addresses nil
632 "*Specifies a list of addresses the user is subscribed to.
633 If nil, do not use any predefined list subscriptions. This list of
634 addresses can be used in conjunction with
635 `message-subscribed-address-functions' and `message-subscribed-regexps'."
636 :group 'message-interface
637 :type '(repeat string))
639 (defcustom message-subscribed-regexps nil
640 "*Specifies a list of addresses the user is subscribed to.
641 If nil, do not use any predefined list subscriptions. This list of
642 regular expressions can be used in conjunction with
643 `message-subscribed-address-functions' and `message-subscribed-addresses'."
644 :group 'message-interface
645 :type '(repeat regexp))
647 (defcustom message-allow-no-recipients 'ask
648 "Specifies what to do when there are no recipients other than Gcc/Fcc.
649 If it is the symbol `always', the posting is allowed. If it is the
650 symbol `never', the posting is not allowed. If it is the symbol
651 `ask', you are prompted."
652 :group 'message-interface
653 :type '(choice (const always)
657 (defcustom message-sendmail-f-is-evil nil
658 "*Non-nil means don't add \"-f username\" to the sendmail command line.
659 Doing so would be even more evil than leaving it out."
660 :group 'message-sending
663 (defcustom message-sendmail-envelope-from nil
664 "*Envelope-from when sending mail with sendmail.
665 If this is nil, use `user-mail-address'. If it is the symbol
666 `header', use the From: header of the message."
667 :type '(choice (string :tag "From name")
668 (const :tag "Use From: header from message" header)
669 (const :tag "Use `user-mail-address'" nil))
670 :group 'message-sending)
672 ;; qmail-related stuff
673 (defcustom message-qmail-inject-program "/var/qmail/bin/qmail-inject"
674 "Location of the qmail-inject program."
675 :group 'message-sending
678 (defcustom message-qmail-inject-args nil
679 "Arguments passed to qmail-inject programs.
680 This should be a list of strings, one string for each argument. It
681 may also be a function.
683 For e.g., if you wish to set the envelope sender address so that bounces
684 go to the right place or to deal with listserv's usage of that address, you
685 might set this variable to '(\"-f\" \"you@some.where\")."
686 :group 'message-sending
687 :type '(choice (function)
690 (defvar message-cater-to-broken-inn t
691 "Non-nil means Gnus should not fold the `References' header.
692 Folding `References' makes ancient versions of INN create incorrect
696 (defvar gnus-post-method)
697 (defvar gnus-select-method))
698 (defcustom message-post-method
699 (cond ((and (boundp 'gnus-post-method)
700 (listp gnus-post-method)
703 ((boundp 'gnus-select-method)
706 "*Method used to post news.
707 Note that when posting from inside Gnus, for instance, this
708 variable isn't used."
710 :group 'message-sending
711 ;; This should be the `gnus-select-method' widget, but that might
712 ;; create a dependence to `gnus.el'.
715 ;; FIXME: This should be a temporary workaround until someone implements a
716 ;; proper solution. If a crash happens while replying, the auto-save file
717 ;; will *not* have a `References:' header if `message-generate-headers-first'
718 ;; is nil. See: http://article.gmane.org/gmane.emacs.gnus.general/51138
719 (defcustom message-generate-headers-first '(references)
720 "*If non-nil, generate all required headers before composing.
721 The variables `message-required-news-headers' and
722 `message-required-mail-headers' specify which headers to generate.
723 This can also be a list of headers that should be generated before
726 Note that the variable `message-deletable-headers' specifies headers which
727 are to be deleted and then re-generated before sending, so this variable
728 will not have a visible effect for those headers."
729 :group 'message-headers
730 :type '(choice (const :tag "None" nil)
731 (const :tag "References" '(references))
733 (repeat (sexp :tag "Header"))))
735 (defcustom message-setup-hook nil
736 "Normal hook, run each time a new outgoing message is initialized.
737 The function `message-setup' runs this hook."
738 :group 'message-various
741 (defcustom message-cancel-hook nil
742 "Hook run when cancelling articles."
743 :group 'message-various
746 (defcustom message-signature-setup-hook nil
747 "Normal hook, run each time a new outgoing message is initialized.
748 It is run after the headers have been inserted and before
749 the signature is inserted."
750 :group 'message-various
753 (defcustom message-mode-hook nil
754 "Hook run in message mode buffers."
755 :group 'message-various
758 (defcustom message-header-hook nil
759 "Hook run in a message mode buffer narrowed to the headers."
760 :group 'message-various
763 (defcustom message-header-setup-hook nil
764 "Hook called narrowed to the headers when setting up a message buffer."
765 :group 'message-various
768 (defcustom message-minibuffer-local-map
769 (let ((map (make-sparse-keymap 'message-minibuffer-local-map)))
770 (set-keymap-parent map minibuffer-local-map)
772 "Keymap for `message-read-from-minibuffer'.")
775 (defcustom message-citation-line-function 'message-insert-citation-line
776 "*Function called to insert the \"Whomever writes:\" line.
778 Note that Gnus provides a feature where the reader can click on
779 `writes:' to hide the cited text. If you change this line too much,
780 people who read your message will have to change their Gnus
781 configuration. See the variable `gnus-cite-attribution-suffix'."
783 :group 'message-insertion)
786 (defcustom message-yank-prefix "> "
787 "*Prefix inserted on the lines of yanked messages.
788 Fix `message-cite-prefix-regexp' if it is set to an abnormal value.
789 See also `message-yank-cited-prefix'."
791 :group 'message-insertion)
793 (defcustom message-yank-cited-prefix ">"
794 "*Prefix inserted on cited or empty lines of yanked messages.
795 Fix `message-cite-prefix-regexp' if it is set to an abnormal value.
796 See also `message-yank-prefix'."
798 :group 'message-insertion)
800 (defcustom message-indentation-spaces 3
801 "*Number of spaces to insert at the beginning of each cited line.
802 Used by `message-yank-original' via `message-yank-cite'."
803 :group 'message-insertion
807 (defcustom message-cite-function 'message-cite-original
808 "*Function for citing an original message.
809 Predefined functions include `message-cite-original' and
810 `message-cite-original-without-signature'.
811 Note that `message-cite-original' uses `mail-citation-hook' if that is non-nil."
812 :type '(radio (function-item message-cite-original)
813 (function-item message-cite-original-without-signature)
814 (function-item sc-cite-original)
815 (function :tag "Other"))
816 :group 'message-insertion)
819 (defcustom message-indent-citation-function 'message-indent-citation
820 "*Function for modifying a citation just inserted in the mail buffer.
821 This can also be a list of functions. Each function can find the
822 citation between (point) and (mark t). And each function should leave
823 point and mark around the citation text as modified."
825 :group 'message-insertion)
828 (defcustom message-signature t
829 "*String to be inserted at the end of the message buffer.
830 If t, the `message-signature-file' file will be inserted instead.
831 If a function, the result from the function will be used instead.
832 If a form, the result from the form will be used instead."
834 :group 'message-insertion)
837 (defcustom message-signature-file "~/.signature"
838 "*Name of file containing the text inserted at end of message buffer.
839 Ignored if the named file doesn't exist.
840 If nil, don't insert a signature."
841 :type '(choice file (const :tags "None" nil))
842 :group 'message-insertion)
845 (defcustom message-signature-insert-empty-line t
846 "*If non-nil, insert an empty line before the signature separator."
848 :group 'message-insertion)
850 (defcustom message-distribution-function nil
851 "*Function called to return a Distribution header."
853 :group 'message-headers
854 :type '(choice function (const nil)))
856 (defcustom message-expires 14
857 "Number of days before your article expires."
859 :group 'message-headers
860 :link '(custom-manual "(message)News Headers")
863 (defcustom message-user-path nil
864 "If nil, use the NNTP server name in the Path header.
865 If stringp, use this; if non-nil, use no host name (user name only)."
867 :group 'message-headers
868 :link '(custom-manual "(message)News Headers")
869 :type '(choice (const :tag "nntp" nil)
871 (sexp :tag "none" :format "%t" t)))
873 (defvar message-reply-buffer nil)
874 (defvar message-reply-headers nil
875 "The headers of the current replied article.
876 It is a vector of the following headers:
877 \[number subject from date id references chars lines xref extra].")
878 (defvar message-newsreader nil)
879 (defvar message-mailer nil)
880 (defvar message-sent-message-via nil)
881 (defvar message-checksum nil)
882 (defvar message-send-actions nil
883 "A list of actions to be performed upon successful sending of a message.")
884 (defvar message-exit-actions nil
885 "A list of actions to be performed upon exiting after sending a message.")
886 (defvar message-kill-actions nil
887 "A list of actions to be performed before killing a message buffer.")
888 (defvar message-postpone-actions nil
889 "A list of actions to be performed after postponing a message.")
891 (define-widget 'message-header-lines 'text
892 "All header lines must be LFD terminated."
893 :format "%{%t%}:%n%v"
895 :error "All header lines must be newline terminated")
897 (defcustom message-default-headers ""
898 "*A string containing header lines to be inserted in outgoing messages.
899 It is inserted before you edit the message, so you can edit or delete
901 :group 'message-headers
902 :type 'message-header-lines)
904 (defcustom message-default-mail-headers ""
905 "*A string of header lines to be inserted in outgoing mails."
906 :group 'message-headers
908 :type 'message-header-lines)
910 (defcustom message-default-news-headers ""
911 "*A string of header lines to be inserted in outgoing news articles."
912 :group 'message-headers
914 :type 'message-header-lines)
916 ;; Note: could use /usr/ucb/mail instead of sendmail;
917 ;; options -t, and -v if not interactive.
918 (defcustom message-mailer-swallows-blank-line
919 (if (and (string-match "sparc-sun-sunos\\(\\'\\|[^5]\\)"
920 system-configuration)
921 (file-readable-p "/etc/sendmail.cf")
922 (let ((buffer (get-buffer-create " *temp*")))
926 (insert-file-contents "/etc/sendmail.cf")
927 (goto-char (point-min))
928 (let ((case-fold-search nil))
929 (re-search-forward "^OR\\>" nil t)))
930 (kill-buffer buffer))))
931 ;; According to RFC822, "The field-name must be composed of printable
932 ;; ASCII characters (i. e., characters that have decimal values between
933 ;; 33 and 126, except colon)", i. e., any chars except ctl chars,
935 '(looking-at "[ \t]\\|[][!\"#$%&'()*+,-./0-9;<=>?@A-Z\\\\^_`a-z{|}~]+:"))
936 "*Set this non-nil if the system's mailer runs the header and body together.
937 \(This problem exists on Sunos 4 when sendmail is run in remote mode.)
938 The value should be an expression to test whether the problem will
940 :group 'message-sending
944 (define-mail-user-agent 'message-user-agent
945 'message-mail 'message-send-and-exit
946 'message-kill-buffer 'message-send-hook)
948 (defvar message-mh-deletable-headers '(Message-ID Date Lines Sender)
949 "If non-nil, delete the deletable headers before feeding to mh.")
951 (defvar message-send-method-alist
952 '((news message-news-p message-send-via-news)
953 (mail message-mail-p message-send-via-mail))
954 "Alist of ways to send outgoing messages.
955 Each element has the form
957 \(TYPE PREDICATE FUNCTION)
959 where TYPE is a symbol that names the method; PREDICATE is a function
960 called without any parameters to determine whether the message is
961 a message of type TYPE; and FUNCTION is a function to be called if
962 PREDICATE returns non-nil. FUNCTION is called with one parameter --
965 (defcustom message-mail-alias-type 'abbrev
966 "*What alias expansion type to use in Message buffers.
967 The default is `abbrev', which uses mailabbrev. nil switches
970 :link '(custom-manual "(message)Mail Aliases")
971 :type '(choice (const :tag "Use Mailabbrev" abbrev)
972 (const :tag "No expansion" nil)))
974 (defcustom message-auto-save-directory
975 (file-name-as-directory (nnheader-concat message-directory "drafts"))
976 "*Directory where Message auto-saves buffers if Gnus isn't running.
977 If nil, Message won't auto-save."
978 :group 'message-buffers
979 :type '(choice directory (const :tag "Don't auto-save" nil)))
981 (defcustom message-default-charset
982 (and (not (mm-multibyte-p)) 'iso-8859-1)
983 "Default charset used in non-MULE Emacsen.
984 If nil, you might be asked to input the charset."
989 (defcustom message-dont-reply-to-names
990 (and (boundp 'rmail-dont-reply-to-names) rmail-dont-reply-to-names)
991 "*A regexp specifying addresses to prune when doing wide replies.
992 A value of nil means exclude your own user name only."
995 :type '(choice (const :tag "Yourself" nil)
998 (defvar message-shoot-gnksa-feet nil
999 "*A list of GNKSA feet you are allowed to shoot.
1000 Gnus gives you all the opportunity you could possibly want for
1001 shooting yourself in the foot. Also, Gnus allows you to shoot the
1002 feet of Good Net-Keeping Seal of Approval. The following are foot
1004 `empty-article' Allow you to post an empty article;
1005 `quoted-text-only' Allow you to post quoted text only;
1006 `multiple-copies' Allow you to post multiple copies;
1007 `cancel-messages' Allow you to cancel or supersede messages from
1008 your other email addresses.")
1010 (defsubst message-gnksa-enable-p (feature)
1011 (or (not (listp message-shoot-gnksa-feet))
1012 (memq feature message-shoot-gnksa-feet)))
1014 (defcustom message-hidden-headers nil
1015 "Regexp of headers to be hidden when composing new messages.
1016 This can also be a list of regexps to match headers. Or a list
1017 starting with `not' and followed by regexps."
1019 :type '(repeat regexp))
1021 ;;; Internal variables.
1022 ;;; Well, not really internal.
1024 (defvar message-mode-syntax-table
1025 (let ((table (copy-syntax-table text-mode-syntax-table)))
1026 (modify-syntax-entry ?% ". " table)
1027 (modify-syntax-entry ?> ". " table)
1028 (modify-syntax-entry ?< ". " table)
1030 "Syntax table used while in Message mode.")
1032 (defface message-header-to-face
1035 (:foreground "green2" :bold t))
1038 (:foreground "MidnightBlue" :bold t))
1040 (:bold t :italic t)))
1041 "Face used for displaying From headers."
1042 :group 'message-faces)
1044 (defface message-header-cc-face
1047 (:foreground "green4" :bold t))
1050 (:foreground "MidnightBlue"))
1053 "Face used for displaying Cc headers."
1054 :group 'message-faces)
1056 (defface message-header-subject-face
1059 (:foreground "green3"))
1062 (:foreground "navy blue" :bold t))
1065 "Face used for displaying subject headers."
1066 :group 'message-faces)
1068 (defface message-header-newsgroups-face
1071 (:foreground "yellow" :bold t :italic t))
1074 (:foreground "blue4" :bold t :italic t))
1076 (:bold t :italic t)))
1077 "Face used for displaying newsgroups headers."
1078 :group 'message-faces)
1080 (defface message-header-other-face
1083 (:foreground "#b00000"))
1086 (:foreground "steel blue"))
1088 (:bold t :italic t)))
1089 "Face used for displaying newsgroups headers."
1090 :group 'message-faces)
1092 (defface message-header-name-face
1095 (:foreground "DarkGreen"))
1098 (:foreground "cornflower blue"))
1101 "Face used for displaying header names."
1102 :group 'message-faces)
1104 (defface message-header-xheader-face
1107 (:foreground "blue"))
1110 (:foreground "blue"))
1113 "Face used for displaying X-Header headers."
1114 :group 'message-faces)
1116 (defface message-separator-face
1119 (:foreground "blue3"))
1122 (:foreground "brown"))
1125 "Face used for displaying the separator."
1126 :group 'message-faces)
1128 (defface message-cited-text-face
1131 (:foreground "red"))
1134 (:foreground "red"))
1137 "Face used for displaying cited text names."
1138 :group 'message-faces)
1140 (defface message-mml-face
1143 (:foreground "ForestGreen"))
1146 (:foreground "ForestGreen"))
1149 "Face used for displaying MML."
1150 :group 'message-faces)
1152 (defun message-font-lock-make-header-matcher (regexp)
1155 (let ((start (point)))
1158 (goto-char (point-min))
1159 (if (re-search-forward
1160 (concat "^" (regexp-quote mail-header-separator) "$")
1162 (setq limit (min limit (match-beginning 0))))
1164 (and (< start limit)
1165 (re-search-forward ,regexp limit t))))))
1166 (if (featurep 'bytecomp)
1170 (defvar message-font-lock-keywords
1171 (let ((content "[ \t]*\\(.+\\(\n[ \t].*\\)*\\)\n?"))
1172 `((,(message-font-lock-make-header-matcher
1173 (concat "^\\([Tt]o:\\)" content))
1174 (1 'message-header-name-face)
1175 (2 'message-header-to-face nil t))
1176 (,(message-font-lock-make-header-matcher
1177 (concat "^\\(^[GBF]?[Cc][Cc]:\\|^[Rr]eply-[Tt]o:\\)" content))
1178 (1 'message-header-name-face)
1179 (2 'message-header-cc-face nil t))
1180 (,(message-font-lock-make-header-matcher
1181 (concat "^\\([Ss]ubject:\\)" content))
1182 (1 'message-header-name-face)
1183 (2 'message-header-subject-face nil t))
1184 (,(message-font-lock-make-header-matcher
1185 (concat "^\\([Nn]ewsgroups:\\|Followup-[Tt]o:\\)" content))
1186 (1 'message-header-name-face)
1187 (2 'message-header-newsgroups-face nil t))
1188 (,(message-font-lock-make-header-matcher
1189 (concat "^\\([A-Z][^: \n\t]+:\\)" content))
1190 (1 'message-header-name-face)
1191 (2 'message-header-other-face nil t))
1192 (,(message-font-lock-make-header-matcher
1193 (concat "^\\(X-[A-Za-z0-9-]+:\\|In-Reply-To:\\)" content))
1194 (1 'message-header-name-face)
1195 (2 'message-header-name-face))
1196 ,@(if (and mail-header-separator
1197 (not (equal mail-header-separator "")))
1198 `((,(concat "^\\(" (regexp-quote mail-header-separator) "\\)$")
1199 1 'message-separator-face))
1202 (re-search-forward (concat "^\\("
1203 message-cite-prefix-regexp
1206 (0 'message-cited-text-face))
1207 ("<#/?\\(multipart\\|part\\|external\\|mml\\|secure\\)[^>]*>"
1208 (0 'message-mml-face))))
1209 "Additional expressions to highlight in Message mode.")
1212 ;; XEmacs does it like this. For Emacs, we have to set the
1213 ;; `font-lock-defaults' buffer-local variable.
1214 (put 'message-mode 'font-lock-defaults '(message-font-lock-keywords t))
1216 (defvar message-face-alist
1217 '((bold . bold-region)
1218 (underline . underline-region)
1219 (default . (lambda (b e)
1221 (ununderline-region b e))))
1222 "Alist of mail and news faces for facemenu.
1223 The cdr of each entry is a function for applying the face to a region.")
1225 (defcustom message-send-hook nil
1226 "Hook run before sending messages.
1227 This hook is run quite early when sending."
1228 :group 'message-various
1229 :options '(ispell-message)
1232 (defcustom message-send-mail-hook nil
1233 "Hook run before sending mail messages.
1234 This hook is run very late -- just before the message is sent as
1236 :group 'message-various
1239 (defcustom message-send-news-hook nil
1240 "Hook run before sending news messages.
1241 This hook is run very late -- just before the message is sent as
1243 :group 'message-various
1246 (defcustom message-sent-hook nil
1247 "Hook run after sending messages."
1248 :group 'message-various
1251 (defvar message-send-coding-system 'binary
1252 "Coding system to encode outgoing mail.")
1254 (defvar message-draft-coding-system
1255 mm-auto-save-coding-system
1256 "*Coding system to compose mail.
1257 If you'd like to make it possible to share draft files between XEmacs
1258 and Emacs, you may use `iso-2022-7bit' for this value at your own risk.
1259 Note that the coding-system `iso-2022-7bit' isn't suitable to all data.")
1261 (defcustom message-send-mail-partially-limit 1000000
1262 "The limitation of messages sent as message/partial.
1263 The lower bound of message size in characters, beyond which the message
1264 should be sent in several parts. If it is nil, the size is unlimited."
1266 :group 'message-buffers
1267 :type '(choice (const :tag "unlimited" nil)
1270 (defcustom message-alternative-emails nil
1271 "A regexp to match the alternative email addresses.
1272 The first matched address (not primary one) is used in the From field."
1273 :group 'message-headers
1274 :type '(choice (const :tag "Always use primary" nil)
1277 (defcustom message-hierarchical-addresses nil
1278 "A list of hierarchical mail address definitions.
1280 Inside each entry, the first address is the \"top\" address, and
1281 subsequent addresses are subaddresses; this is used to indicate that
1282 mail sent to the first address will automatically be delivered to the
1283 subaddresses. So if the first address appears in the recipient list
1284 for a message, the subaddresses will be removed (if present) before
1285 the mail is sent. All addresses in this structure should be
1287 :group 'message-headers
1288 :type '(repeat (repeat string)))
1290 (defcustom message-mail-user-agent nil
1291 "Like `mail-user-agent'.
1292 Except if it is nil, use Gnus native MUA; if it is t, use
1294 :type '(radio (const :tag "Gnus native"
1297 (const :tag "`mail-user-agent'"
1300 (function-item :tag "Default Emacs mail"
1302 sendmail-user-agent)
1303 (function-item :tag "Emacs interface to MH"
1306 (function :tag "Other"))
1310 (defcustom message-wide-reply-confirm-recipients nil
1311 "Whether to confirm a wide reply to multiple email recipients.
1312 If this variable is nil, don't ask whether to reply to all recipients.
1313 If this variable is non-nil, pose the question \"Reply to all
1314 recipients?\" before a wide reply to multiple recipients. If the user
1315 answers yes, reply to all recipients as usual. If the user answers
1316 no, only reply back to the author."
1318 :group 'message-headers
1321 (defcustom message-user-fqdn nil
1322 "*Domain part of Messsage-Ids."
1323 :group 'message-headers
1324 :link '(custom-manual "(message)News Headers")
1325 :type '(radio (const :format "%v " nil)
1326 (string :format "FQDN: %v\n" :size 0)))
1328 (defcustom message-use-idna (and (condition-case nil (require 'idna)
1330 (mm-coding-system-p 'utf-8)
1331 (executable-find idna-program)
1333 "Whether to encode non-ASCII in domain names into ASCII according to IDNA."
1334 :group 'message-headers
1335 :type '(choice (const :tag "Ask" ask)
1336 (const :tag "Never" nil)
1337 (const :tag "Always" t)))
1339 ;;; Internal variables.
1341 (defvar message-sending-message "Sending...")
1342 (defvar message-buffer-list nil)
1343 (defvar message-this-is-news nil)
1344 (defvar message-this-is-mail nil)
1345 (defvar message-draft-article nil)
1346 (defvar message-mime-part nil)
1347 (defvar message-posting-charset nil)
1348 (defvar message-inserted-headers nil)
1350 ;; Byte-compiler warning
1352 (defvar gnus-active-hashtb)
1353 (defvar gnus-read-active-file))
1355 ;;; Regexp matching the delimiter of messages in UNIX mail format
1356 ;;; (UNIX From lines), minus the initial ^. It should be a copy
1357 ;;; of rmail.el's rmail-unix-mail-delimiter.
1358 (defvar message-unix-mail-delimiter
1359 (let ((time-zone-regexp
1360 (concat "\\([A-Z]?[A-Z]?[A-Z][A-Z]\\( DST\\)?"
1361 "\\|[-+]?[0-9][0-9][0-9][0-9]"
1367 ;; Many things can happen to an RFC 822 mailbox before it is put into
1368 ;; a `From' line. The leading phrase can be stripped, e.g.
1369 ;; `Joe <@w.x:joe@y.z>' -> `<@w.x:joe@y.z>'. The <> can be stripped, e.g.
1370 ;; `<@x.y:joe@y.z>' -> `@x.y:joe@y.z'. Everything starting with a CRLF
1371 ;; can be removed, e.g.
1372 ;; From: joe@y.z (Joe K
1374 ;; can yield `From joe@y.z (Joe K Fri Mar 22 08:11:15 1996', and
1377 ;; can yield `From Joe User Fri Mar 22 08:11:15 1996'.
1378 ;; The mailbox can be removed or be replaced by white space, e.g.
1379 ;; From: "Joe User"{space}{tab}
1381 ;; can yield `From {space}{tab} Fri Mar 22 08:11:15 1996',
1382 ;; where {space} and {tab} represent the Ascii space and tab characters.
1383 ;; We want to match the results of any of these manglings.
1384 ;; The following regexp rejects names whose first characters are
1385 ;; obviously bogus, but after that anything goes.
1386 "\\([^\0-\b\n-\r\^?].*\\)?"
1388 ;; The time the message was sent.
1389 "\\([^\0-\r \^?]+\\) +" ; day of the week
1390 "\\([^\0-\r \^?]+\\) +" ; month
1391 "\\([0-3]?[0-9]\\) +" ; day of month
1392 "\\([0-2][0-9]:[0-5][0-9]\\(:[0-6][0-9]\\)?\\) *" ; time of day
1394 ;; Perhaps a time zone, specified by an abbreviation, or by a
1399 " \\([0-9][0-9]+\\) *"
1401 ;; On some systems the time zone can appear after the year, too.
1405 "\\(remote from .*\\)?"
1408 "Regexp matching the delimiter of messages in UNIX mail format.")
1410 (defvar message-unsent-separator
1411 (concat "^ *---+ +Unsent message follows +---+ *$\\|"
1412 "^ *---+ +Returned message +---+ *$\\|"
1413 "^Start of returned message$\\|"
1414 "^ *---+ +Original message +---+ *$\\|"
1415 "^ *--+ +begin message +--+ *$\\|"
1416 "^ *---+ +Original message follows +---+ *$\\|"
1417 "^ *---+ +Undelivered message follows +---+ *$\\|"
1418 "^|? *---+ +Message text follows: +---+ *|?$")
1419 "A regexp that matches the separator before the text of a failed message.")
1421 (defvar message-header-format-alist
1423 (To . message-fill-address)
1424 (Cc . message-fill-address)
1435 (References . message-shorten-references)
1437 "Alist used for formatting headers.")
1439 (defvar message-options nil
1440 "Some saved answers when sending message.")
1442 (defvar message-send-mail-real-function nil
1443 "Internal send mail function.")
1445 (defvar message-bogus-system-names "^localhost\\."
1446 "The regexp of bogus system names.")
1448 (defcustom message-valid-fqdn-regexp
1449 (concat "[a-z0-9][-.a-z0-9]+\\." ;; [hostname.subdomain.]domain.
1451 "\\([a-z][a-z]" ;; two letter country TDLs
1452 "\\|biz\\|com\\|edu\\|gov\\|int\\|mil\\|net\\|org"
1453 "\\|aero\\|coop\\|info\\|name\\|museum"
1454 "\\|arpa\\|pro\\|uucp\\|bitnet\\|bofh" ;; old style?
1456 "Regular expression that matches a valid FQDN."
1457 ;; see also: gnus-button-valid-fqdn-regexp
1458 :group 'message-headers
1462 (autoload 'message-setup-toolbar "messagexmas")
1463 (autoload 'mh-new-draft-name "mh-comp")
1464 (autoload 'mh-send-letter "mh-comp")
1465 (autoload 'gnus-point-at-eol "gnus-util")
1466 (autoload 'gnus-point-at-bol "gnus-util")
1467 (autoload 'gnus-output-to-rmail "gnus-util")
1468 (autoload 'gnus-output-to-mail "gnus-util")
1469 (autoload 'nndraft-request-associate-buffer "nndraft")
1470 (autoload 'nndraft-request-expire-articles "nndraft")
1471 (autoload 'gnus-open-server "gnus-int")
1472 (autoload 'gnus-request-post "gnus-int")
1473 (autoload 'gnus-alive-p "gnus-util")
1474 (autoload 'gnus-server-string "gnus")
1475 (autoload 'gnus-group-name-charset "gnus-group")
1476 (autoload 'gnus-group-name-decode "gnus-group")
1477 (autoload 'gnus-groups-from-server "gnus")
1478 (autoload 'rmail-output "rmailout")
1479 (autoload 'gnus-delay-article "gnus-delay")
1480 (autoload 'gnus-make-local-hook "gnus-util"))
1485 ;;; Utility functions.
1488 (defmacro message-y-or-n-p (question show &rest text)
1489 "Ask QUESTION, displaying remaining args in a temporary buffer if SHOW."
1490 `(message-talkative-question 'y-or-n-p ,question ,show ,@text))
1492 (defmacro message-delete-line (&optional n)
1493 "Delete the current line (and the next N lines)."
1494 `(delete-region (progn (beginning-of-line) (point))
1495 (progn (forward-line ,(or n 1)) (point))))
1497 (defun message-mark-active-p ()
1498 "Non-nil means the mark and region are currently active in this buffer."
1501 (defun message-unquote-tokens (elems)
1502 "Remove double quotes (\") from strings in list ELEMS."
1503 (mapcar (lambda (item)
1504 (while (string-match "^\\(.*\\)\"\\(.*\\)$" item)
1505 (setq item (concat (match-string 1 item)
1506 (match-string 2 item))))
1510 (defun message-tokenize-header (header &optional separator)
1511 "Split HEADER into a list of header elements.
1512 SEPARATOR is a string of characters to be used as separators. \",\"
1513 is used by default."
1516 (let ((regexp (format "[%s]+" (or separator ",")))
1521 (mm-enable-multibyte)
1523 (goto-char (point-min))
1528 (cond ((and (> (point) beg)
1530 (and (looking-at regexp)
1533 (push (buffer-substring beg (point)) elems)
1534 (setq beg (match-end 0)))
1535 ((eq (char-after) ?\")
1536 (setq quoted (not quoted)))
1537 ((and (eq (char-after) ?\()
1540 ((and (eq (char-after) ?\))
1543 (nreverse elems)))))
1545 (defun message-mail-file-mbox-p (file)
1546 "Say whether FILE looks like a Unix mbox file."
1547 (when (and (file-exists-p file)
1548 (file-readable-p file)
1549 (file-regular-p file))
1551 (nnheader-insert-file-contents file)
1552 (goto-char (point-min))
1553 (looking-at message-unix-mail-delimiter))))
1555 (defun message-fetch-field (header &optional not-all)
1556 "The same as `mail-fetch-field', only remove all newlines.
1557 The buffer is expected to be narrowed to just the header of the message;
1558 see `message-narrow-to-headers-or-head'."
1559 (let* ((inhibit-point-motion-hooks t)
1560 (case-fold-search t)
1561 (value (mail-fetch-field header nil (not not-all))))
1563 (while (string-match "\n[\t ]+" value)
1564 (setq value (replace-match " " t t value)))
1565 (set-text-properties 0 (length value) nil value)
1568 (defun message-field-value (header &optional not-all)
1569 "The same as `message-fetch-field', only narrow to the headers first."
1572 (message-narrow-to-headers-or-head)
1573 (message-fetch-field header not-all))))
1575 (defun message-narrow-to-field ()
1576 "Narrow the buffer to the header on the current line."
1582 (if (re-search-forward "^[^ \n\t]" nil t)
1587 (goto-char (point-min)))
1589 (defun message-add-header (&rest headers)
1590 "Add the HEADERS to the message header, skipping those already present."
1593 (unless (string-match "^\\([^:]+\\):[ \t]*[^ \t]" (car headers))
1594 (error "Invalid header `%s'" (car headers)))
1595 (setq hclean (match-string 1 (car headers)))
1597 (message-narrow-to-headers)
1598 (unless (re-search-forward (concat "^" (regexp-quote hclean) ":") nil t)
1599 (goto-char (point-max))
1600 (if (string-match "\n$" (car headers))
1601 (insert (car headers))
1602 (insert (car headers) ?\n)))))
1603 (setq headers (cdr headers))))
1605 (defmacro message-with-reply-buffer (&rest forms)
1606 "Evaluate FORMS in the reply buffer, if it exists."
1607 `(when (and message-reply-buffer
1608 (buffer-name message-reply-buffer))
1610 (set-buffer message-reply-buffer)
1613 (put 'message-with-reply-buffer 'lisp-indent-function 0)
1614 (put 'message-with-reply-buffer 'edebug-form-spec '(body))
1616 (defun message-fetch-reply-field (header)
1617 "Fetch field HEADER from the message we're replying to."
1618 (message-with-reply-buffer
1620 (mail-narrow-to-head)
1621 (message-fetch-field header))))
1623 (defun message-strip-list-identifiers (subject)
1624 "Remove list identifiers in `gnus-list-identifiers' from string SUBJECT."
1625 (require 'gnus-sum) ; for gnus-list-identifiers
1626 (let ((regexp (if (stringp gnus-list-identifiers)
1627 gnus-list-identifiers
1628 (mapconcat 'identity gnus-list-identifiers " *\\|"))))
1629 (if (string-match (concat "\\(\\(\\(Re: +\\)?\\(" regexp
1630 " *\\)\\)+\\(Re: +\\)?\\)") subject)
1631 (concat (substring subject 0 (match-beginning 1))
1632 (or (match-string 3 subject)
1633 (match-string 5 subject))
1638 (defun message-strip-subject-re (subject)
1639 "Remove \"Re:\" from subject lines in string SUBJECT."
1640 (if (string-match message-subject-re-regexp subject)
1641 (substring subject (match-end 0))
1644 ;;; Start of functions adopted from `message-utils.el'.
1646 (defun message-strip-subject-trailing-was (subject)
1647 "Remove trailing \"(Was: <old subject>)\" from SUBJECT lines.
1648 Leading \"Re: \" is not stripped by this function. Use the function
1649 `message-strip-subject-re' for this."
1650 (let* ((query message-subject-trailing-was-query)
1655 message-subject-trailing-was-ask-regexp
1656 message-subject-trailing-was-regexp)
1659 (setq new (substring subject 0 (match-beginning 0))))
1660 (if (or (not found) (eq query nil))
1663 (if (message-y-or-n-p
1664 "Strip `(was: <old subject>)' in subject? " t
1666 "Strip `(was: <old subject>)' in subject "
1667 "and use the new one instead?\n\n"
1668 "Current subject is: \""
1670 "New subject would be: \""
1672 "See the variable `message-subject-trailing-was-query' "
1673 "to get rid of this query."
1678 ;;; Suggested by Jonas Steverud @ www.dtek.chalmers.se/~d4jonas/
1681 (defun message-change-subject (new-subject)
1682 "Ask for NEW-SUBJECT header, append (was: <Old Subject>)."
1683 ;; <URL:http://www.karlsruhe.org/rfc/son1036.txt>
1684 ;; <URL:http://www.karlsruhe.org/rfc/draft-ietf-usefor-article-09.txt>
1685 ;; But not mentioned in...
1686 ;; <URL:http://www.karlsruhe.org/rfc/draft-ietf-usefor-article-11.txt>
1689 (read-from-minibuffer "New subject: ")))
1690 (cond ((and (not (or (null new-subject) ; new subject not empty
1691 (zerop (string-width new-subject))
1692 (string-match "^[ \t]*$" new-subject))))
1696 (message-narrow-to-headers)
1697 (message-fetch-field "Subject"))))
1698 (cond ((not old-subject)
1699 (error "No current subject"))
1702 (regexp-quote new-subject)
1704 old-subject)) ; yes, it really is a new subject
1705 ;; delete eventual Re: prefix
1707 (message-strip-subject-re old-subject))
1708 (message-goto-subject)
1709 (message-delete-line)
1710 (insert (concat "Subject: "
1713 old-subject ")\n")))))))))
1716 (defun message-mark-inserted-region (beg end)
1717 "Mark some region in the current article with enclosing tags.
1718 See `message-mark-insert-begin' and `message-mark-insert-end'."
1721 ;; add to the end of the region first, otherwise end would be invalid
1723 (insert message-mark-insert-end)
1725 (insert message-mark-insert-begin)))
1728 (defun message-mark-insert-file (file)
1729 "Insert FILE at point, marking it with enclosing tags.
1730 See `message-mark-insert-begin' and `message-mark-insert-end'."
1731 (interactive "fFile to insert: ")
1732 ;; reverse insertion to get correct result.
1734 (insert message-mark-insert-end)
1736 (insert-file-contents file)
1738 (insert message-mark-insert-begin)))
1741 (defun message-add-archive-header ()
1742 "Insert \"X-No-Archive: Yes\" in the header and a note in the body.
1743 The note can be customized using `message-archive-note'. When called with a
1744 prefix argument, ask for a text to insert. If you don't want the note in the
1745 body, set `message-archive-note' to nil."
1747 (if current-prefix-arg
1748 (setq message-archive-note
1749 (read-from-minibuffer "Reason for No-Archive: "
1750 (cons message-archive-note 0))))
1752 (if (message-goto-signature)
1753 (re-search-backward message-signature-separator))
1754 (when message-archive-note
1755 (insert message-archive-note)
1757 (message-add-header message-archive-header)
1758 (message-sort-headers)))
1761 (defun message-cross-post-followup-to-header (target-group)
1762 "Mangles FollowUp-To and Newsgroups header to point to TARGET-GROUP.
1763 With prefix-argument just set Follow-Up, don't cross-post."
1765 (list ; Completion based on Gnus
1766 (completing-read "Followup To: "
1767 (if (boundp 'gnus-newsrc-alist)
1769 nil nil '("poster" . 0)
1770 (if (boundp 'gnus-group-history)
1771 'gnus-group-history))))
1772 (message-remove-header "Follow[Uu]p-[Tt]o" t)
1773 (message-goto-newsgroups)
1775 ;; if we already did a crosspost before, kill old target
1776 (if (and message-cross-post-old-target
1778 (regexp-quote (concat "," message-cross-post-old-target))
1781 ;; unless (followup is to poster or user explicitly asked not
1782 ;; to cross-post, or target-group is already in Newsgroups)
1783 ;; add target-group to Newsgroups line.
1785 ;; def: cross-post, req:no
1786 (and message-cross-post-default (not current-prefix-arg))
1787 ;; def: no-cross-post, req:yes
1788 (and (not message-cross-post-default) current-prefix-arg))
1789 (not (string-match "poster" target-group))
1790 (not (string-match (regexp-quote target-group)
1791 (message-fetch-field "Newsgroups"))))
1793 (insert (concat "," target-group))))
1794 (end-of-line) ; ensure Followup: comes after Newsgroups:
1795 ;; unless new followup would be identical to Newsgroups line
1796 ;; make a new Followup-To line
1797 (if (not (string-match (concat "^[ \t]*"
1800 (message-fetch-field "Newsgroups")))
1801 (insert (concat "\nFollowup-To: " target-group)))
1802 (setq message-cross-post-old-target target-group))
1805 (defun message-cross-post-insert-note (target-group cross-post in-old
1807 "Insert a in message body note about a set Followup or Crosspost.
1808 If there have been previous notes, delete them. TARGET-GROUP specifies the
1809 group to Followup-To. When CROSS-POST is t, insert note about
1810 crossposting. IN-OLD specifies whether TARGET-GROUP is a member of
1811 OLD-GROUPS. OLD-GROUPS lists the old-groups the posting would have
1812 been made to before the user asked for a Crosspost."
1813 ;; start scanning body for previous uses
1814 (message-goto-signature)
1815 (let ((head (re-search-backward
1816 (concat "^" mail-header-separator)
1817 nil t))) ; just search in body
1818 (message-goto-signature)
1819 (while (re-search-backward
1820 (concat "^" (regexp-quote message-cross-post-note) ".*")
1822 (message-delete-line))
1823 (message-goto-signature)
1824 (while (re-search-backward
1825 (concat "^" (regexp-quote message-followup-to-note) ".*")
1827 (message-delete-line))
1829 (if (message-goto-signature)
1830 (re-search-backward message-signature-separator))
1833 (string-match "^[ \t]*poster[ \t]*$" target-group))
1834 (insert (concat message-followup-to-note target-group "\n"))
1835 (insert (concat message-cross-post-note target-group "\n")))))
1838 (defun message-cross-post-followup-to (target-group)
1839 "Crossposts message and set Followup-To to TARGET-GROUP.
1840 With prefix-argument just set Follow-Up, don't cross-post."
1842 (list ; Completion based on Gnus
1843 (completing-read "Followup To: "
1844 (if (boundp 'gnus-newsrc-alist)
1846 nil nil '("poster" . 0)
1847 (if (boundp 'gnus-group-history)
1848 'gnus-group-history))))
1849 (cond ((not (or (null target-group) ; new subject not empty
1850 (zerop (string-width target-group))
1851 (string-match "^[ \t]*$" target-group)))
1853 (let* ((old-groups (message-fetch-field "Newsgroups"))
1854 (in-old (string-match
1855 (regexp-quote target-group)
1856 (or old-groups ""))))
1857 ;; check whether target exactly matches old Newsgroups
1858 (cond ((not old-groups)
1859 (error "No current newsgroup"))
1863 (regexp-quote target-group)
1866 ;; yes, Newsgroups line must change
1867 (message-cross-post-followup-to-header target-group)
1868 ;; insert note whether we do cross-post or followup-to
1869 (funcall message-cross-post-note-function
1871 (if (or (and message-cross-post-default
1872 (not current-prefix-arg))
1873 (and (not message-cross-post-default)
1874 current-prefix-arg)) t)
1875 in-old old-groups))))))))
1877 ;;; Reduce To: to Cc: or Bcc: header
1880 (defun message-reduce-to-to-cc ()
1881 "Replace contents of To: header with contents of Cc: or Bcc: header."
1884 (save-restriction (message-narrow-to-headers)
1885 (message-fetch-field "cc")))
1887 (if (and (not cc-content)
1890 (message-narrow-to-headers)
1891 (message-fetch-field "bcc"))))
1896 (message-delete-line)
1897 (insert (concat "To: " cc-content "\n"))
1899 (message-narrow-to-headers)
1900 (message-remove-header (if bcc
1904 ;;; End of functions adopted from `message-utils.el'.
1906 (defun message-remove-header (header &optional is-regexp first reverse)
1907 "Remove HEADER in the narrowed buffer.
1908 If IS-REGEXP, HEADER is a regular expression.
1909 If FIRST, only remove the first instance of the header.
1910 Return the number of headers removed."
1911 (goto-char (point-min))
1912 (let ((regexp (if is-regexp header (concat "^" (regexp-quote header) ":")))
1914 (case-fold-search t)
1916 (while (and (not (eobp))
1919 (not (looking-at regexp))
1920 (looking-at regexp))
1927 ;; There might be a continuation header, so we have to search
1928 ;; until we find a new non-continuation line.
1931 (if (re-search-forward "^[^ \t]" nil t)
1932 (goto-char (match-beginning 0))
1935 (if (re-search-forward "^[^ \t]" nil t)
1936 (goto-char (match-beginning 0))
1937 (goto-char (point-max)))))
1940 (defun message-remove-first-header (header)
1941 "Remove the first instance of HEADER if there is more than one."
1943 (regexp (concat "^" (regexp-quote header) ":")))
1945 (goto-char (point-min))
1946 (while (re-search-forward regexp nil t)
1949 (message-remove-header header nil t)
1952 (defun message-narrow-to-headers ()
1953 "Narrow the buffer to the head of the message."
1956 (goto-char (point-min))
1957 (if (re-search-forward
1958 (concat "^" (regexp-quote mail-header-separator) "\n") nil t)
1961 (goto-char (point-min)))
1963 (defun message-narrow-to-head-1 ()
1964 "Like `message-narrow-to-head'. Don't widen."
1966 (goto-char (point-min))
1967 (if (search-forward "\n\n" nil 1)
1970 (goto-char (point-min)))
1972 (defun message-narrow-to-head ()
1973 "Narrow the buffer to the head of the message.
1974 Point is left at the beginning of the narrowed-to region."
1976 (message-narrow-to-head-1))
1978 (defun message-narrow-to-headers-or-head ()
1979 "Narrow the buffer to the head of the message."
1982 (goto-char (point-min))
1985 (concat "^" (regexp-quote mail-header-separator) "\n") nil t)
1986 (match-beginning 0))
1987 ((search-forward "\n\n" nil t)
1991 (goto-char (point-min)))
1993 (defun message-news-p ()
1994 "Say whether the current buffer contains a news message."
1995 (and (not message-this-is-mail)
1996 (or message-this-is-news
1999 (message-narrow-to-headers)
2000 (and (message-fetch-field "newsgroups")
2001 (not (message-fetch-field "posted-to"))))))))
2003 (defun message-mail-p ()
2004 "Say whether the current buffer contains a mail message."
2005 (and (not message-this-is-news)
2006 (or message-this-is-mail
2009 (message-narrow-to-headers)
2010 (or (message-fetch-field "to")
2011 (message-fetch-field "cc")
2012 (message-fetch-field "bcc")))))))
2014 (defun message-subscribed-p ()
2015 "Say whether we need to insert a MFT header."
2016 (or message-subscribed-regexps
2017 message-subscribed-addresses
2018 message-subscribed-address-file
2019 message-subscribed-address-functions))
2021 (defun message-next-header ()
2022 "Go to the beginning of the next header."
2024 (or (eobp) (forward-char 1))
2025 (not (if (re-search-forward "^[^ \t]" nil t)
2027 (goto-char (point-max)))))
2029 (defun message-sort-headers-1 ()
2030 "Sort the buffer as headers using `message-rank' text props."
2031 (goto-char (point-min))
2034 nil 'message-next-header
2036 (message-next-header)
2040 (or (get-text-property (point) 'message-rank)
2043 (defun message-sort-headers ()
2044 "Sort the headers of the current message according to `message-header-format-alist'."
2048 (let ((max (1+ (length message-header-format-alist)))
2050 (message-narrow-to-headers)
2051 (while (re-search-forward "^[^ \n]+:" nil t)
2053 (match-beginning 0) (1+ (match-beginning 0))
2055 (if (setq rank (length (memq (assq (intern (buffer-substring
2057 (1- (match-end 0))))
2058 message-header-format-alist)
2059 message-header-format-alist)))
2062 (message-sort-headers-1))))
2073 (defvar message-mode-map nil)
2075 (unless message-mode-map
2076 (setq message-mode-map (make-keymap))
2077 (set-keymap-parent message-mode-map text-mode-map)
2078 (define-key message-mode-map "\C-c?" 'describe-mode)
2080 (define-key message-mode-map "\C-c\C-f\C-t" 'message-goto-to)
2081 (define-key message-mode-map "\C-c\C-f\C-o" 'message-goto-from)
2082 (define-key message-mode-map "\C-c\C-f\C-b" 'message-goto-bcc)
2083 (define-key message-mode-map "\C-c\C-f\C-w" 'message-goto-fcc)
2084 (define-key message-mode-map "\C-c\C-f\C-c" 'message-goto-cc)
2085 (define-key message-mode-map "\C-c\C-f\C-s" 'message-goto-subject)
2086 (define-key message-mode-map "\C-c\C-f\C-r" 'message-goto-reply-to)
2087 (define-key message-mode-map "\C-c\C-f\C-n" 'message-goto-newsgroups)
2088 (define-key message-mode-map "\C-c\C-f\C-d" 'message-goto-distribution)
2089 (define-key message-mode-map "\C-c\C-f\C-f" 'message-goto-followup-to)
2090 (define-key message-mode-map "\C-c\C-f\C-m" 'message-goto-mail-followup-to)
2091 (define-key message-mode-map "\C-c\C-f\C-k" 'message-goto-keywords)
2092 (define-key message-mode-map "\C-c\C-f\C-u" 'message-goto-summary)
2093 (define-key message-mode-map "\C-c\C-f\C-i"
2094 'message-insert-or-toggle-importance)
2095 (define-key message-mode-map "\C-c\C-f\C-a"
2096 'message-generate-unsubscribed-mail-followup-to)
2098 ;; modify headers (and insert notes in body)
2099 (define-key message-mode-map "\C-c\C-fs" 'message-change-subject)
2101 (define-key message-mode-map "\C-c\C-fx" 'message-cross-post-followup-to)
2102 ;; prefix+message-cross-post-followup-to = same w/o cross-post
2103 (define-key message-mode-map "\C-c\C-ft" 'message-reduce-to-to-cc)
2104 (define-key message-mode-map "\C-c\C-fa" 'message-add-archive-header)
2105 ;; mark inserted text
2106 (define-key message-mode-map "\C-c\M-m" 'message-mark-inserted-region)
2107 (define-key message-mode-map "\C-c\M-f" 'message-mark-insert-file)
2109 (define-key message-mode-map "\C-c\C-b" 'message-goto-body)
2110 (define-key message-mode-map "\C-c\C-i" 'message-goto-signature)
2112 (define-key message-mode-map "\C-c\C-t" 'message-insert-to)
2113 (define-key message-mode-map "\C-c\C-fw" 'message-insert-wide-reply)
2114 (define-key message-mode-map "\C-c\C-n" 'message-insert-newsgroups)
2115 (define-key message-mode-map "\C-c\C-l" 'message-to-list-only)
2117 (define-key message-mode-map "\C-c\C-u" 'message-insert-or-toggle-importance)
2118 (define-key message-mode-map "\C-c\M-n"
2119 'message-insert-disposition-notification-to)
2121 (define-key message-mode-map "\C-c\C-y" 'message-yank-original)
2122 (define-key message-mode-map "\C-c\M-\C-y" 'message-yank-buffer)
2123 (define-key message-mode-map "\C-c\C-q" 'message-fill-yanked-message)
2124 (define-key message-mode-map "\C-c\C-w" 'message-insert-signature)
2125 (define-key message-mode-map "\C-c\M-h" 'message-insert-headers)
2126 (define-key message-mode-map "\C-c\C-r" 'message-caesar-buffer-body)
2127 (define-key message-mode-map "\C-c\C-o" 'message-sort-headers)
2128 (define-key message-mode-map "\C-c\M-r" 'message-rename-buffer)
2130 (define-key message-mode-map "\C-c\C-c" 'message-send-and-exit)
2131 (define-key message-mode-map "\C-c\C-s" 'message-send)
2132 (define-key message-mode-map "\C-c\C-k" 'message-kill-buffer)
2133 (define-key message-mode-map "\C-c\C-d" 'message-dont-send)
2134 (define-key message-mode-map "\C-c\n" 'gnus-delay-article)
2136 (define-key message-mode-map "\C-c\C-e" 'message-elide-region)
2137 (define-key message-mode-map "\C-c\C-v" 'message-delete-not-region)
2138 (define-key message-mode-map "\C-c\C-z" 'message-kill-to-signature)
2139 (define-key message-mode-map "\M-\r" 'message-newline-and-reformat)
2140 ;;(define-key message-mode-map "\M-q" 'message-fill-paragraph)
2141 (define-key message-mode-map [remap split-line] 'message-split-line)
2143 (define-key message-mode-map "\C-c\C-a" 'mml-attach-file)
2145 (define-key message-mode-map "\C-a" 'message-beginning-of-line)
2146 (define-key message-mode-map "\t" 'message-tab)
2147 (define-key message-mode-map "\M-;" 'comment-region))
2150 message-mode-menu message-mode-map "Message Menu."
2152 ["Yank Original" message-yank-original message-reply-buffer]
2153 ["Fill Yanked Message" message-fill-yanked-message t]
2154 ["Insert Signature" message-insert-signature t]
2155 ["Caesar (rot13) Message" message-caesar-buffer-body t]
2156 ["Caesar (rot13) Region" message-caesar-region (message-mark-active-p)]
2157 ["Elide Region" message-elide-region
2158 :active (message-mark-active-p)
2159 ,@(if (featurep 'xemacs) nil
2160 '(:help "Replace text in region with an ellipsis"))]
2161 ["Delete Outside Region" message-delete-not-region
2162 :active (message-mark-active-p)
2163 ,@(if (featurep 'xemacs) nil
2164 '(:help "Delete all quoted text outside region"))]
2165 ["Kill To Signature" message-kill-to-signature t]
2166 ["Newline and Reformat" message-newline-and-reformat t]
2167 ["Rename buffer" message-rename-buffer t]
2168 ["Spellcheck" ispell-message
2169 ,@(if (featurep 'xemacs) '(t)
2170 '(:help "Spellcheck this message"))]
2172 ["Insert Region Marked" message-mark-inserted-region
2173 :active (message-mark-active-p)
2174 ,@(if (featurep 'xemacs) nil
2175 '(:help "Mark region with enclosing tags"))]
2176 ["Insert File Marked..." message-mark-insert-file
2177 ,@(if (featurep 'xemacs) '(t)
2178 '(:help "Insert file at point marked with enclosing tags"))]
2180 ["Send Message" message-send-and-exit
2181 ,@(if (featurep 'xemacs) '(t)
2182 '(:help "Send this message"))]
2183 ["Postpone Message" message-dont-send
2184 ,@(if (featurep 'xemacs) '(t)
2185 '(:help "File this draft message and exit"))]
2186 ["Send at Specific Time..." gnus-delay-article
2187 ,@(if (featurep 'xemacs) '(t)
2188 '(:help "Ask, then arrange to send message at that time"))]
2189 ["Kill Message" message-kill-buffer
2190 ,@(if (featurep 'xemacs) '(t)
2191 '(:help "Delete this message without sending"))]))
2194 message-mode-field-menu message-mode-map ""
2196 ["Fetch To" message-insert-to t]
2197 ["Fetch Newsgroups" message-insert-newsgroups t]
2199 ["To" message-goto-to t]
2200 ["From" message-goto-from t]
2201 ["Subject" message-goto-subject t]
2202 ["Change subject..." message-change-subject t]
2203 ["Cc" message-goto-cc t]
2204 ["Bcc" message-goto-bcc t]
2205 ["Fcc" message-goto-fcc t]
2206 ["Reply-To" message-goto-reply-to t]
2207 ["Flag As Important" message-insert-importance-high
2208 ,@(if (featurep 'xemacs) '(t)
2209 '(:help "Mark this message as important"))]
2210 ["Flag As Unimportant" message-insert-importance-low
2211 ,@(if (featurep 'xemacs) '(t)
2212 '(:help "Mark this message as unimportant"))]
2214 message-insert-disposition-notification-to
2215 ,@(if (featurep 'xemacs) '(t)
2216 '(:help "Request a receipt notification"))]
2218 ;; (typical) news stuff
2219 ["Summary" message-goto-summary t]
2220 ["Keywords" message-goto-keywords t]
2221 ["Newsgroups" message-goto-newsgroups t]
2222 ["Followup-To" message-goto-followup-to t]
2223 ;; ["Followup-To (with note in body)" message-cross-post-followup-to t]
2224 ["Crosspost / Followup-To..." message-cross-post-followup-to t]
2225 ["Distribution" message-goto-distribution t]
2226 ["X-No-Archive:" message-add-archive-header t ]
2228 ;; (typical) mailing-lists stuff
2229 ["Send to list only" message-to-list-only t]
2230 ["Mail-Followup-To" message-goto-mail-followup-to t]
2231 ["Unsubscribed list post" message-generate-unsubscribed-mail-followup-to
2232 ,@(if (featurep 'xemacs) '(t)
2233 '(:help "Insert a reasonable `Mail-Followup-To:' header."))]
2234 ["Reduce To: to Cc:" message-reduce-to-to-cc t]
2236 ["Sort Headers" message-sort-headers t]
2237 ["Encode non-ASCII domain names" message-idna-to-ascii-rhs t]
2238 ["Goto Body" message-goto-body t]
2239 ["Goto Signature" message-goto-signature t]))
2241 (defvar message-tool-bar-map nil)
2244 (defvar facemenu-add-face-function)
2245 (defvar facemenu-remove-face-function))
2247 ;;; Forbidden properties
2249 ;; We use `after-change-functions' to keep special text properties
2250 ;; that interfer with the normal function of message mode out of the
2253 (defcustom message-strip-special-text-properties t
2254 "Strip special properties from the message buffer.
2256 Emacs has a number of special text properties which can break message
2257 composing in various ways. If this option is set, message will strip
2258 these properties from the message composition buffer. However, some
2259 packages requires these properties to be present in order to work.
2260 If you use one of these packages, turn this option off, and hope the
2261 message composition doesn't break too bad."
2262 :group 'message-various
2265 (defconst message-forbidden-properties
2266 ;; No reason this should be clutter up customize. We make it a
2267 ;; property list (rather than a list of property symbols), to be
2268 ;; directly useful for `remove-text-properties'.
2269 '(field nil read-only nil invisible nil intangible nil
2270 mouse-face nil modification-hooks nil insert-in-front-hooks nil
2271 insert-behind-hooks nil point-entered nil point-left nil)
2272 ;; Other special properties:
2273 ;; category, face, display: probably doesn't do any harm.
2274 ;; fontified: is used by font-lock.
2275 ;; syntax-table, local-map: I dunno.
2276 ;; We need to add XEmacs names to the list.
2277 "Property list of with properties.forbidden in message buffers.
2278 The values of the properties are ignored, only the property names are used.")
2280 (defun message-tamago-not-in-use-p (pos)
2281 "Return t when tamago version 4 is not in use at the cursor position.
2282 Tamago version 4 is a popular input method for writing Japanese text.
2283 It uses the properties `intangible', `invisible', `modification-hooks'
2284 and `read-only' when translating ascii or kana text to kanji text.
2285 These properties are essential to work, so we should never strip them."
2286 (not (and (boundp 'egg-modefull-mode)
2287 (symbol-value 'egg-modefull-mode)
2288 (or (memq (get-text-property pos 'intangible)
2289 '(its-part-1 its-part-2))
2290 (get-text-property pos 'egg-end)
2291 (get-text-property pos 'egg-lang)
2292 (get-text-property pos 'egg-start)))))
2294 (defun message-strip-forbidden-properties (begin end &optional old-length)
2295 "Strip forbidden properties between BEGIN and END, ignoring the third arg.
2296 This function is intended to be called from `after-change-functions'.
2297 See also `message-forbidden-properties'."
2298 (when (and message-strip-special-text-properties
2299 (message-tamago-not-in-use-p begin))
2300 (while (not (= begin end))
2301 (when (not (get-text-property begin 'message-hidden))
2302 (remove-text-properties begin (1+ begin)
2303 message-forbidden-properties))
2307 (define-derived-mode message-mode text-mode "Message"
2308 "Major mode for editing mail and news to be sent.
2309 Like Text Mode but with these additional commands:\\<message-mode-map>
2310 C-c C-s `message-send' (send the message) C-c C-c `message-send-and-exit'
2311 C-c C-d Postpone sending the message C-c C-k Kill the message
2312 C-c C-f move to a header field (and create it if there isn't):
2313 C-c C-f C-t move to To C-c C-f C-s move to Subject
2314 C-c C-f C-c move to Cc C-c C-f C-b move to Bcc
2315 C-c C-f C-w move to Fcc C-c C-f C-r move to Reply-To
2316 C-c C-f C-u move to Summary C-c C-f C-n move to Newsgroups
2317 C-c C-f C-k move to Keywords C-c C-f C-d move to Distribution
2318 C-c C-f C-o move to From (\"Originator\")
2319 C-c C-f C-f move to Followup-To
2320 C-c C-f C-m move to Mail-Followup-To
2321 C-c C-f C-i cycle through Importance values
2322 C-c C-f s change subject and append \"(was: <Old Subject>)\"
2323 C-c C-f x crossposting with FollowUp-To header and note in body
2324 C-c C-f t replace To: header with contents of Cc: or Bcc:
2325 C-c C-f a Insert X-No-Archive: header and a note in the body
2326 C-c C-t `message-insert-to' (add a To header to a news followup)
2327 C-c C-l `message-to-list-only' (removes all but list address in to/cc)
2328 C-c C-n `message-insert-newsgroups' (add a Newsgroup header to a news reply)
2329 C-c C-b `message-goto-body' (move to beginning of message text).
2330 C-c C-i `message-goto-signature' (move to the beginning of the signature).
2331 C-c C-w `message-insert-signature' (insert `message-signature-file' file).
2332 C-c C-y `message-yank-original' (insert current message, if any).
2333 C-c C-q `message-fill-yanked-message' (fill what was yanked).
2334 C-c C-e `message-elide-region' (elide the text between point and mark).
2335 C-c C-v `message-delete-not-region' (remove the text outside the region).
2336 C-c C-z `message-kill-to-signature' (kill the text up to the signature).
2337 C-c C-r `message-caesar-buffer-body' (rot13 the message body).
2338 C-c C-a `mml-attach-file' (attach a file as MIME).
2339 C-c C-u `message-insert-or-toggle-importance' (insert or cycle importance).
2340 C-c M-n `message-insert-disposition-notification-to' (request receipt).
2341 C-c M-m `message-mark-inserted-region' (mark region with enclosing tags).
2342 C-c M-f `message-mark-insert-file' (insert file marked with enclosing tags).
2343 M-RET `message-newline-and-reformat' (break the line and reformat)."
2344 (setq local-abbrev-table text-mode-abbrev-table)
2345 (set (make-local-variable 'message-reply-buffer) nil)
2346 (set (make-local-variable 'message-inserted-headers) nil)
2347 (set (make-local-variable 'message-send-actions) nil)
2348 (set (make-local-variable 'message-exit-actions) nil)
2349 (set (make-local-variable 'message-kill-actions) nil)
2350 (set (make-local-variable 'message-postpone-actions) nil)
2351 (set (make-local-variable 'message-draft-article) nil)
2352 (setq buffer-offer-save t)
2353 (set (make-local-variable 'facemenu-add-face-function)
2355 (let ((face-fun (cdr (assq face message-face-alist))))
2357 (funcall face-fun (point) end)
2358 (error "Face %s not configured for %s mode" face mode-name)))
2360 (set (make-local-variable 'facemenu-remove-face-function) t)
2361 (set (make-local-variable 'message-reply-headers) nil)
2362 (make-local-variable 'message-newsreader)
2363 (make-local-variable 'message-mailer)
2364 (make-local-variable 'message-post-method)
2365 (set (make-local-variable 'message-sent-message-via) nil)
2366 (set (make-local-variable 'message-checksum) nil)
2367 (set (make-local-variable 'message-mime-part) 0)
2368 (message-setup-fill-variables)
2370 (make-local-variable 'paragraph-separate)
2371 (format "\\(%s\\)\\|\\(%s\\)"
2373 "<#!*/?\\(multipart\\|part\\|external\\|mml\\|secure\\)"))
2374 ;; Allow using comment commands to add/remove quoting.
2375 (set (make-local-variable 'comment-start) message-yank-prefix)
2376 (if (featurep 'xemacs)
2377 (message-setup-toolbar)
2378 (set (make-local-variable 'font-lock-defaults)
2379 '(message-font-lock-keywords t))
2380 (if (boundp 'tool-bar-map)
2381 (set (make-local-variable 'tool-bar-map) (message-tool-bar-map))))
2382 (easy-menu-add message-mode-menu message-mode-map)
2383 (easy-menu-add message-mode-field-menu message-mode-map)
2384 (gnus-make-local-hook 'after-change-functions)
2385 ;; Mmmm... Forbidden properties...
2386 (add-hook 'after-change-functions 'message-strip-forbidden-properties
2388 ;; Allow mail alias things.
2389 (when (eq message-mail-alias-type 'abbrev)
2390 (if (fboundp 'mail-abbrevs-setup)
2391 (mail-abbrevs-setup)
2392 (if (fboundp 'mail-aliases-setup) ; warning avoidance
2393 (mail-aliases-setup))))
2394 (unless buffer-file-name
2395 (message-set-auto-save-file-name))
2396 (unless (buffer-base-buffer)
2397 ;; Don't enable multibyte on an indirect buffer. Maybe enabling
2398 ;; multibyte is not necessary at all. -- zsh
2399 (mm-enable-multibyte))
2400 (set (make-local-variable 'indent-tabs-mode) nil) ;No tabs for indentation.
2403 (defun message-setup-fill-variables ()
2404 "Setup message fill variables."
2405 (set (make-local-variable 'fill-paragraph-function)
2406 'message-fill-paragraph)
2407 (make-local-variable 'paragraph-separate)
2408 (make-local-variable 'paragraph-start)
2409 (make-local-variable 'adaptive-fill-regexp)
2410 (unless (boundp 'adaptive-fill-first-line-regexp)
2411 (setq adaptive-fill-first-line-regexp nil))
2412 (make-local-variable 'adaptive-fill-first-line-regexp)
2413 (let ((quote-prefix-regexp
2414 ;; User should change message-cite-prefix-regexp if
2415 ;; message-yank-prefix is set to an abnormal value.
2416 (concat "\\(" message-cite-prefix-regexp "\\)[ \t]*")))
2417 (setq paragraph-start
2419 (regexp-quote mail-header-separator) "$\\|"
2420 "[ \t]*$\\|" ; blank lines
2421 "-- $\\|" ; signature delimiter
2422 "---+$\\|" ; delimiters for forwarded messages
2423 page-delimiter "$\\|" ; spoiler warnings
2424 ".*wrote:$\\|" ; attribution lines
2425 quote-prefix-regexp "$")) ; empty lines in quoted text
2426 (setq paragraph-separate paragraph-start)
2427 (setq adaptive-fill-regexp
2428 (concat quote-prefix-regexp "\\|" adaptive-fill-regexp))
2429 (setq adaptive-fill-first-line-regexp
2430 (concat quote-prefix-regexp "\\|"
2431 adaptive-fill-first-line-regexp)))
2432 (make-local-variable 'auto-fill-inhibit-regexp)
2433 ;;(setq auto-fill-inhibit-regexp "^[A-Z][^: \n\t]+:")
2434 (setq auto-fill-inhibit-regexp nil)
2435 (make-local-variable 'normal-auto-fill-function)
2436 (setq normal-auto-fill-function 'message-do-auto-fill)
2437 ;; KLUDGE: auto fill might already be turned on in `text-mode-hook'.
2438 ;; In that case, ensure that it uses the right function. The real
2439 ;; solution would be not to use `define-derived-mode', and run
2440 ;; `text-mode-hook' ourself at the end of the mode.
2441 ;; -- Per Abrahamsen <abraham@dina.kvl.dk> Date: 2001-10-19.
2442 (when auto-fill-function
2443 (setq auto-fill-function normal-auto-fill-function)))
2448 ;;; Message mode commands
2451 ;;; Movement commands
2453 (defun message-goto-to ()
2454 "Move point to the To header."
2456 (message-position-on-field "To"))
2458 (defun message-goto-from ()
2459 "Move point to the From header."
2461 (message-position-on-field "From"))
2463 (defun message-goto-subject ()
2464 "Move point to the Subject header."
2466 (message-position-on-field "Subject"))
2468 (defun message-goto-cc ()
2469 "Move point to the Cc header."
2471 (message-position-on-field "Cc" "To"))
2473 (defun message-goto-bcc ()
2474 "Move point to the Bcc header."
2476 (message-position-on-field "Bcc" "Cc" "To"))
2478 (defun message-goto-fcc ()
2479 "Move point to the Fcc header."
2481 (message-position-on-field "Fcc" "To" "Newsgroups"))
2483 (defun message-goto-reply-to ()
2484 "Move point to the Reply-To header."
2486 (message-position-on-field "Reply-To" "Subject"))
2488 (defun message-goto-newsgroups ()
2489 "Move point to the Newsgroups header."
2491 (message-position-on-field "Newsgroups"))
2493 (defun message-goto-distribution ()
2494 "Move point to the Distribution header."
2496 (message-position-on-field "Distribution"))
2498 (defun message-goto-followup-to ()
2499 "Move point to the Followup-To header."
2501 (message-position-on-field "Followup-To" "Newsgroups"))
2503 (defun message-goto-mail-followup-to ()
2504 "Move point to the Mail-Followup-To header."
2506 (message-position-on-field "Mail-Followup-To" "From"))
2508 (defun message-goto-keywords ()
2509 "Move point to the Keywords header."
2511 (message-position-on-field "Keywords" "Subject"))
2513 (defun message-goto-summary ()
2514 "Move point to the Summary header."
2516 (message-position-on-field "Summary" "Subject"))
2518 (defun message-goto-body (&optional interactivep)
2519 "Move point to the beginning of the message body."
2520 (interactive (list t))
2521 (when (and interactivep
2522 (looking-at "[ \t]*\n"))
2524 (goto-char (point-min))
2525 (or (search-forward (concat "\n" mail-header-separator "\n") nil t)
2526 (search-forward-regexp "[^:]+:\\([^\n]\\|\n[ \t]\\)+\n\n" nil t)))
2528 (defun message-goto-eoh ()
2529 "Move point to the end of the headers."
2534 (defun message-goto-signature ()
2535 "Move point to the beginning of the message signature.
2536 If there is no signature in the article, go to the end and
2539 (goto-char (point-min))
2540 (if (re-search-forward message-signature-separator nil t)
2542 (goto-char (point-max))
2545 (defun message-generate-unsubscribed-mail-followup-to (&optional include-cc)
2546 "Insert a reasonable MFT header in a post to an unsubscribed list.
2547 When making original posts to a mailing list you are not subscribed to,
2548 you have to type in a MFT header by hand. The contents, usually, are
2549 the addresses of the list and your own address. This function inserts
2550 such a header automatically. It fetches the contents of the To: header
2551 in the current mail buffer, and appends the current `user-mail-address'.
2553 If the optional argument INCLUDE-CC is non-nil, the addresses in the
2554 Cc: header are also put into the MFT."
2559 (message-narrow-to-headers)
2560 (message-remove-header "Mail-Followup-To")
2561 (setq cc (and include-cc (message-fetch-field "Cc")))
2563 (concat (message-fetch-field "To") "," cc)
2564 (message-fetch-field "To"))))
2565 (message-goto-mail-followup-to)
2566 (insert (concat tos ", " user-mail-address))))
2570 (defun message-insert-to (&optional force)
2571 "Insert a To header that points to the author of the article being replied to.
2572 If the original author requested not to be sent mail, the function signals
2574 With the prefix argument FORCE, insert the header anyway."
2576 (let ((co (message-fetch-reply-field "mail-copies-to")))
2577 (when (and (null force)
2579 (or (equal (downcase co) "never")
2580 (equal (downcase co) "nobody")))
2581 (error "The user has requested not to have copies sent via mail")))
2582 (message-carefully-insert-headers
2584 (or (message-fetch-reply-field "mail-reply-to")
2585 (message-fetch-reply-field "reply-to")
2586 (message-fetch-reply-field "from")
2589 (defun message-insert-wide-reply ()
2590 "Insert To and Cc headers as if you were doing a wide reply."
2592 (let ((headers (message-with-reply-buffer
2593 (message-get-reply-headers t))))
2594 (message-carefully-insert-headers headers)))
2596 (defun message-carefully-insert-headers (headers)
2597 (dolist (header headers)
2598 (let ((header-name (symbol-name (car header))))
2599 (when (and (message-position-on-field header-name)
2600 (mail-fetch-field header-name)
2601 (not (string-match "\\` *\\'"
2602 (mail-fetch-field header-name))))
2604 (insert (cdr header)))))
2606 (defun message-widen-reply ()
2607 "Widen the reply to include maximum recipients."
2610 (and message-reply-buffer
2611 (buffer-name message-reply-buffer)
2613 (set-buffer message-reply-buffer)
2614 (message-get-reply-headers t)))))
2617 (message-narrow-to-headers)
2618 (dolist (elem follow-to)
2619 (message-remove-header (symbol-name (car elem)))
2620 (goto-char (point-min))
2621 (insert (symbol-name (car elem)) ": "
2622 (cdr elem) "\n"))))))
2624 (defun message-insert-newsgroups ()
2625 "Insert the Newsgroups header from the article being replied to."
2627 (when (and (message-position-on-field "Newsgroups")
2628 (mail-fetch-field "newsgroups")
2629 (not (string-match "\\` *\\'" (mail-fetch-field "newsgroups"))))
2631 (insert (or (message-fetch-reply-field "newsgroups") "")))
2635 ;;; Various commands
2637 (defun message-delete-not-region (beg end)
2638 "Delete everything in the body of the current message outside of the region."
2643 ;; snarf citation prefix, if appropriate
2644 (unless (eq (point) (progn (beginning-of-line) (point)))
2645 (when (looking-at message-cite-prefix-regexp)
2646 (setq citeprefix (match-string 0))))
2648 (delete-region (point) (if (not (message-goto-signature))
2654 (delete-region beg (progn (message-goto-body)
2658 (insert citeprefix))))
2659 (when (message-goto-signature)
2662 (defun message-kill-to-signature ()
2663 "Deletes all text up to the signature."
2665 (let ((point (point)))
2666 (message-goto-signature)
2669 (kill-region point (point))
2673 (defun message-newline-and-reformat (&optional arg not-break)
2674 "Insert four newlines, and then reformat if inside quoted text.
2675 Prefix arg means justify as well."
2676 (interactive (list (if current-prefix-arg 'full)))
2677 (let (quoted point beg end leading-space bolp)
2678 (setq point (point))
2681 (setq bolp (= beg point))
2682 ;; Find first line of the paragraph.
2684 (while (and (not (eobp))
2685 (not (looking-at message-cite-prefix-regexp))
2686 (looking-at paragraph-start))
2689 (when (looking-at message-cite-prefix-regexp)
2690 (setq quoted (match-string 0))
2691 (goto-char (match-end 0))
2692 (looking-at "[ \t]*")
2693 (setq leading-space (match-string 0)))
2697 (< (- point beg) (length quoted)))
2698 ;; break inside the cite prefix.
2704 (while (and (not (eobp))
2705 (not (looking-at paragraph-separate))
2706 (looking-at message-cite-prefix-regexp)
2707 (equal quoted (match-string 0)))
2708 (goto-char (match-end 0))
2709 (looking-at "[ \t]*")
2710 (if (> (length leading-space) (length (match-string 0)))
2711 (setq leading-space (match-string 0)))
2715 (while (and (if (bobp) nil (forward-line -1) t)
2716 (not (looking-at paragraph-start))
2717 (looking-at message-cite-prefix-regexp)
2718 (equal quoted (match-string 0)))
2720 (goto-char (match-end 0))
2721 (looking-at "[ \t]*")
2722 (if (> (length leading-space) (length (match-string 0)))
2723 (setq leading-space (match-string 0)))))
2724 (while (and (not (eobp))
2725 (not (looking-at paragraph-separate))
2726 (not (looking-at message-cite-prefix-regexp)))
2730 (while (and (if (bobp) nil (forward-line -1) t)
2731 (not (looking-at paragraph-start))
2732 (not (looking-at message-cite-prefix-regexp)))
2733 (setq beg (point))))
2736 (narrow-to-region beg end)
2743 (setq point (point))
2744 ;; (newline 2) doesn't mark both newline's as hard, so call
2745 ;; newline twice. -jas
2748 (delete-region (point) (re-search-forward "[ \t]*"))
2749 (when (and quoted (not bolp))
2750 (insert quoted leading-space)))
2753 (let* ((adaptive-fill-regexp
2754 (regexp-quote (concat quoted leading-space)))
2755 (adaptive-fill-first-line-regexp
2756 adaptive-fill-regexp ))
2757 (fill-paragraph arg))
2758 (fill-paragraph arg))
2759 (if point (goto-char point)))))
2761 (defun message-fill-paragraph (&optional arg)
2762 "Like `fill-paragraph'."
2763 (interactive (list (if current-prefix-arg 'full)))
2764 (if (if (boundp 'filladapt-mode) filladapt-mode)
2766 (message-newline-and-reformat arg t)
2769 ;; Is it better to use `mail-header-end'?
2770 (defun message-point-in-header-p ()
2771 "Return t if point is in the header."
2774 (goto-char (point-min))
2775 (not (re-search-forward
2776 (concat "^" (regexp-quote mail-header-separator) "\n")
2779 (defun message-do-auto-fill ()
2780 "Like `do-auto-fill', but don't fill in message header."
2781 (unless (message-point-in-header-p)
2784 (defun message-insert-signature (&optional force)
2785 "Insert a signature. See documentation for variable `message-signature'."
2786 (interactive (list 0))
2789 ((and (null message-signature)
2792 (goto-char (point-max))
2793 (not (re-search-backward message-signature-separator nil t))))
2794 ((and (null message-signature)
2797 ((functionp message-signature)
2798 (funcall message-signature))
2799 ((listp message-signature)
2800 (eval message-signature))
2801 (t message-signature)))
2803 (cond ((stringp signature)
2805 ((and (eq t signature)
2806 message-signature-file
2807 (file-exists-p message-signature-file))
2810 (goto-char (point-max))
2811 ;; Insert the signature.
2814 (when message-signature-insert-empty-line
2817 (if (eq signature t)
2818 (insert-file-contents message-signature-file)
2820 (goto-char (point-max))
2821 (or (bolp) (insert "\n")))))
2823 (defun message-insert-importance-high ()
2824 "Insert header to mark message as important."
2828 (message-narrow-to-headers)
2829 (message-remove-header "Importance"))
2831 (insert "Importance: high\n")))
2833 (defun message-insert-importance-low ()
2834 "Insert header to mark message as unimportant."
2838 (message-narrow-to-headers)
2839 (message-remove-header "Importance"))
2841 (insert "Importance: low\n")))
2843 (defun message-insert-or-toggle-importance ()
2844 "Insert a \"Importance: high\" header, or cycle through the header values.
2845 The three allowed values according to RFC 1327 are `high', `normal'
2849 (let ((valid '("high" "normal" "low"))
2853 (message-narrow-to-headers)
2854 (when (setq cur (message-fetch-field "Importance"))
2855 (message-remove-header "Importance")
2856 (setq new (cond ((string= cur "high")
2858 ((string= cur "low")
2863 (insert (format "Importance: %s\n" new)))))
2865 (defun message-insert-disposition-notification-to ()
2866 "Request a disposition notification (return receipt) to this message.
2867 Note that this should not be used in newsgroups."
2871 (message-narrow-to-headers)
2872 (message-remove-header "Disposition-Notification-To"))
2874 (insert (format "Disposition-Notification-To: %s\n"
2875 (or (message-field-value "Reply-to")
2876 (message-field-value "From")
2877 (message-make-from))))))
2879 (defun message-elide-region (b e)
2880 "Elide the text in the region.
2881 An ellipsis (from `message-elide-ellipsis') will be inserted where the
2885 (insert message-elide-ellipsis))
2887 (defvar message-caesar-translation-table nil)
2889 (defun message-caesar-region (b e &optional n)
2890 "Caesar rotate region B to E by N, default 13, for decrypting netnews."
2893 (min (point) (or (mark t) (point)))
2894 (max (point) (or (mark t) (point)))
2895 (when current-prefix-arg
2896 (prefix-numeric-value current-prefix-arg))))
2898 (setq n (if (numberp n) (mod n 26) 13)) ;canonize N
2899 (unless (or (zerop n) ; no action needed for a rot of 0
2900 (= b e)) ; no region to rotate
2901 ;; We build the table, if necessary.
2902 (when (or (not message-caesar-translation-table)
2903 (/= (aref message-caesar-translation-table ?a) (+ ?a n)))
2904 (setq message-caesar-translation-table
2905 (message-make-caesar-translation-table n)))
2906 (translate-region b e message-caesar-translation-table)))
2908 (defun message-make-caesar-translation-table (n)
2909 "Create a rot table with offset N."
2911 (table (make-string 256 0)))
2912 (while (< (incf i) 256)
2915 (substring table 0 ?A)
2916 (substring table (+ ?A n) (+ ?A n (- 26 n)))
2917 (substring table ?A (+ ?A n))
2918 (substring table (+ ?A 26) ?a)
2919 (substring table (+ ?a n) (+ ?a n (- 26 n)))
2920 (substring table ?a (+ ?a n))
2921 (substring table (+ ?a 26) 255))))
2923 (defun message-caesar-buffer-body (&optional rotnum)
2924 "Caesar rotate all letters in the current buffer by 13 places.
2925 Used to encode/decode possibly offensive messages (commonly in rec.humor).
2926 With prefix arg, specifies the number of places to rotate each letter forward.
2927 Mail and USENET news headers are not rotated."
2928 (interactive (if current-prefix-arg
2929 (list (prefix-numeric-value current-prefix-arg))
2933 (when (message-goto-body)
2934 (narrow-to-region (point) (point-max)))
2935 (message-caesar-region (point-min) (point-max) rotnum))))
2937 (defun message-pipe-buffer-body (program)
2938 "Pipe the message body in the current buffer through PROGRAM."
2941 (when (message-goto-body)
2942 (narrow-to-region (point) (point-max)))
2943 (shell-command-on-region
2944 (point-min) (point-max) program nil t))))
2946 (defun message-rename-buffer (&optional enter-string)
2947 "Rename the *message* buffer to \"*message* RECIPIENT\".
2948 If the function is run with a prefix, it will ask for a new buffer
2949 name, rather than giving an automatic name."
2950 (interactive "Pbuffer name: ")
2953 (goto-char (point-min))
2954 (narrow-to-region (point)
2955 (search-forward mail-header-separator nil 'end))
2957 (if (message-news-p) (message-fetch-field "Newsgroups")
2958 (message-fetch-field "To"))
2961 (if (string-match "," mail-to)
2962 (concat (substring mail-to 0 (match-beginning 0)) ", ...")
2964 (name-default (concat "*message* " mail-trimmed-to))
2965 (name (if enter-string
2966 (read-string "New buffer name: " name-default)
2968 (rename-buffer name t)))))
2970 (defun message-fill-yanked-message (&optional justifyp)
2971 "Fill the paragraphs of a message yanked into this one.
2972 Numeric argument means justify as well."
2975 (goto-char (point-min))
2976 (search-forward (concat "\n" mail-header-separator "\n") nil t)
2977 (let ((fill-prefix message-yank-prefix))
2978 (fill-individual-paragraphs (point) (point-max) justifyp))))
2980 (defun message-indent-citation ()
2981 "Modify text just inserted from a message to be cited.
2982 The inserted text should be the region.
2983 When this function returns, the region is again around the modified text.
2985 Normally, indent each nonblank line `message-indentation-spaces' spaces.
2986 However, if `message-yank-prefix' is non-nil, insert that prefix on each line."
2987 (let ((start (point)))
2988 ;; Remove unwanted headers.
2989 (when message-ignored-cited-headers
2994 (if (search-forward "\n\n" nil t)
2997 (message-remove-header message-ignored-cited-headers t)
2998 (when (= (point-min) (point-max))
2999 (setq all-removed t))
3000 (goto-char (point-max)))
3004 ;; Delete blank lines at the start of the buffer.
3005 (while (and (point-min)
3008 (message-delete-line))
3009 ;; Delete blank lines at the end of the buffer.
3010 (goto-char (point-max))
3013 (while (and (zerop (forward-line -1))
3015 (message-delete-line))
3016 ;; Do the indentation.
3017 (if (null message-yank-prefix)
3018 (indent-rigidly start (mark t) message-indentation-spaces)
3021 (while (< (point) (mark t))
3022 (if (or (looking-at ">") (looking-at "^$"))
3023 (insert message-yank-cited-prefix)
3024 (insert message-yank-prefix))
3028 (defun message-yank-original (&optional arg)
3029 "Insert the message being replied to, if any.
3030 Puts point before the text and mark after.
3031 Normally indents each nonblank line ARG spaces (default 3). However,
3032 if `message-yank-prefix' is non-nil, insert that prefix on each line.
3034 This function uses `message-cite-function' to do the actual citing.
3036 Just \\[universal-argument] as argument means don't indent, insert no
3037 prefix, and don't delete any headers."
3039 (let ((modified (buffer-modified-p)))
3040 (when (and message-reply-buffer
3041 message-cite-function)
3042 (delete-windows-on message-reply-buffer t)
3043 (insert-buffer message-reply-buffer)
3045 (funcall message-cite-function))
3046 (message-exchange-point-and-mark)
3050 (setq message-checksum (message-checksum))))))
3052 (defun message-yank-buffer (buffer)
3053 "Insert BUFFER into the current buffer and quote it."
3054 (interactive "bYank buffer: ")
3055 (let ((message-reply-buffer buffer))
3056 (save-window-excursion
3057 (message-yank-original))))
3059 (defun message-buffers ()
3060 "Return a list of active message buffers."
3063 (dolist (buffer (buffer-list t))
3065 (when (and (eq major-mode 'message-mode)
3066 (null message-sent-message-via))
3067 (push (buffer-name buffer) buffers))))
3068 (nreverse buffers)))
3070 (defun message-cite-original-without-signature ()
3071 "Cite function in the standard Message manner."
3072 (let ((start (point))
3075 (when message-indent-citation-function
3076 (if (listp message-indent-citation-function)
3077 message-indent-citation-function
3078 (list message-indent-citation-function)))))
3079 (mml-quote-region start end)
3083 (when (re-search-backward message-signature-separator start t)
3084 ;; Also peel off any blank lines before the signature.
3086 (while (looking-at "^[ \t]*$")
3089 (delete-region (point) end)
3090 (unless (search-backward "\n\n" start t)
3091 ;; Insert a blank line if it is peeled off.
3095 (funcall (pop functions)))
3096 (when message-citation-line-function
3099 (funcall message-citation-line-function))))
3101 (eval-when-compile (defvar mail-citation-hook)) ;Compiler directive
3102 (defun message-cite-original ()
3103 "Cite function in the standard Message manner."
3104 (if (and (boundp 'mail-citation-hook)
3106 (run-hooks 'mail-citation-hook)
3107 (let ((start (point))
3110 (when message-indent-citation-function
3111 (if (listp message-indent-citation-function)
3112 message-indent-citation-function
3113 (list message-indent-citation-function)))))
3114 (mml-quote-region start end)
3117 (funcall (pop functions)))
3118 (when message-citation-line-function
3121 (funcall message-citation-line-function)))))
3123 (defun message-insert-citation-line ()
3124 "Insert a simple citation line."
3125 (when message-reply-headers
3126 (insert (mail-header-from message-reply-headers) " writes:\n\n")))
3128 (defun message-position-on-field (header &rest afters)
3129 (let ((case-fold-search t))
3132 (goto-char (point-min))
3135 (concat "^" (regexp-quote mail-header-separator) "$"))
3136 (match-beginning 0)))
3137 (goto-char (point-min))
3138 (if (re-search-forward (concat "^" (regexp-quote header) ":") nil t)
3140 (re-search-forward "^[^ \t]" nil 'move)
3142 (skip-chars-backward "\n")
3145 (not (re-search-forward
3146 (concat "^" (regexp-quote (car afters)) ":")
3150 (re-search-forward "^[^ \t]" nil 'move)
3151 (beginning-of-line))
3152 (insert header ": \n")
3156 (defun message-remove-signature ()
3157 "Remove the signature from the text between point and mark.
3158 The text will also be indented the normal way."
3160 (let ((start (point))
3162 (if (not (re-search-forward message-signature-separator (mark t) t))
3163 ;; No signature here, so we just indent the cited text.
3164 (message-indent-citation)
3165 ;; Find the last non-empty line.
3167 (while (looking-at "[ \t]*$")
3170 (setq mark (set-marker (make-marker) (point)))
3172 (message-indent-citation)
3173 ;; Enable undoing the deletion.
3175 (delete-region mark (mark t))
3176 (set-marker mark nil)))))
3181 ;;; Sending messages
3184 (defun message-send-and-exit (&optional arg)
3185 "Send message like `message-send', then, if no errors, exit from mail buffer."
3187 (let ((buf (current-buffer))
3188 (actions message-exit-actions))
3189 (when (and (message-send arg)
3191 (if message-kill-buffer-on-exit
3194 (when (eq buf (current-buffer))
3195 (message-bury buf)))
3196 (message-do-actions actions)
3199 (defun message-dont-send ()
3200 "Don't send the message you have been editing.
3201 Instead, just auto-save the buffer and then bury it."
3203 (set-buffer-modified-p t)
3205 (let ((actions message-postpone-actions))
3206 (message-bury (current-buffer))
3207 (message-do-actions actions)))
3209 (defun message-kill-buffer ()
3210 "Kill the current buffer."
3212 (when (or (not (buffer-modified-p))
3213 (yes-or-no-p "Message modified; kill anyway? "))
3214 (let ((actions message-kill-actions)
3215 (draft-article message-draft-article)
3216 (auto-save-file-name buffer-auto-save-file-name)
3217 (file-name buffer-file-name)
3218 (modified (buffer-modified-p)))
3219 (setq buffer-file-name nil)
3220 (kill-buffer (current-buffer))
3221 (when (and (or (and auto-save-file-name
3222 (file-exists-p auto-save-file-name))
3224 (file-exists-p file-name)))
3225 (yes-or-no-p (format "Remove the backup file%s? "
3226 (if modified " too" ""))))
3228 (delete-file auto-save-file-name))
3229 (let ((message-draft-article draft-article))
3230 (message-disassociate-draft)))
3231 (message-do-actions actions))))
3233 (defun message-bury (buffer)
3234 "Bury this mail BUFFER."
3235 (let ((newbuf (other-buffer buffer)))
3236 (bury-buffer buffer)
3237 (if (and (fboundp 'frame-parameters)
3238 (cdr (assq 'dedicated (frame-parameters)))
3239 (not (null (delq (selected-frame) (visible-frame-list)))))
3240 (delete-frame (selected-frame))
3241 (switch-to-buffer newbuf))))
3243 (defun message-send (&optional arg)
3244 "Send the message in the current buffer.
3245 If `message-interactive' is non-nil, wait for success indication or
3246 error messages, and inform user.
3247 Otherwise any failure is reported in a message back to the user from
3249 The usage of ARG is defined by the instance that called Message.
3250 It should typically alter the sending method in some way or other."
3252 ;; Make it possible to undo the coming changes.
3254 (let ((inhibit-read-only t))
3255 (put-text-property (point-min) (point-max) 'read-only nil))
3256 (message-fix-before-sending)
3257 (run-hooks 'message-send-hook)
3258 (message message-sending-message)
3259 (let ((alist message-send-method-alist)
3261 elem sent dont-barf-on-no-method
3262 (message-options message-options))
3263 (message-options-set-recipient)
3265 (setq elem (pop alist)))
3266 (when (funcall (cadr elem))
3267 (when (and (or (not (memq (car elem)
3268 message-sent-message-via))
3269 (message-fetch-field "supersedes")
3270 (if (or (message-gnksa-enable-p 'multiple-copies)
3271 (not (eq (car elem) 'news)))
3274 "Already sent message via %s; resend? "
3276 (error "Denied posting -- multiple copies")))
3277 (setq success (funcall (caddr elem) arg)))
3281 (let ((fcc (message-fetch-field "Fcc"))
3282 (gcc (message-fetch-field "Gcc")))
3284 (or (eq message-allow-no-recipients 'always)
3285 (and (not (eq message-allow-no-recipients 'never))
3286 (setq dont-barf-on-no-method
3288 (format "No receiver, perform %s anyway? "
3289 (cond ((and fcc gcc) "Fcc and Gcc")
3292 (error "No methods specified to send by"))
3293 (when (or dont-barf-on-no-method
3297 (run-hooks 'message-sent-hook))
3298 (message "Sending...done")
3299 ;; Mark the buffer as unmodified and delete auto-save.
3300 (set-buffer-modified-p nil)
3301 (delete-auto-save-file-if-necessary t)
3302 (message-disassociate-draft)
3303 ;; Delete other mail buffers and stuff.
3304 (message-do-send-housekeeping)
3305 (message-do-actions message-send-actions)
3309 (defun message-send-via-mail (arg)
3310 "Send the current message via mail."
3311 (message-send-mail arg))
3313 (defun message-send-via-news (arg)
3314 "Send the current message via news."
3315 (funcall message-send-news-function arg))
3317 (defmacro message-check (type &rest forms)
3318 "Eval FORMS if TYPE is to be checked."
3319 `(or (message-check-element ,type)
3323 (put 'message-check 'lisp-indent-function 1)
3324 (put 'message-check 'edebug-form-spec '(form body))
3326 (defun message-text-with-property (prop)
3327 "Return a list of all points where the text has PROP."
3329 (point (point-min)))
3331 (while (< point (point-max))
3332 (when (get-text-property point prop)
3333 (push point points))
3337 (defun message-fix-before-sending ()
3338 "Do various things to make the message nice before sending it."
3339 ;; Make sure there's a newline at the end of the message.
3340 (goto-char (point-max))
3343 ;; Make the hidden headers visible.
3344 (let ((points (message-text-with-property 'message-hidden)))
3346 (goto-char (car points))
3347 (dolist (point points)
3348 (add-text-properties point (1+ point)
3349 '(invisible nil intangible nil)))))
3350 ;; Make invisible text visible.
3351 ;; It doesn't seem as if this is useful, since the invisible property
3352 ;; is clobbered by an after-change hook anyhow.
3353 (message-check 'invisible-text
3354 (let ((points (message-text-with-property 'invisible)))
3356 (goto-char (car points))
3357 (dolist (point points)
3358 (put-text-property point (1+ point) 'invisible nil)
3359 (message-overlay-put (message-make-overlay point (1+ point))
3361 (unless (yes-or-no-p
3362 "Invisible text found and made visible; continue sending? ")
3363 (error "Invisible text found and made visible")))))
3364 (message-check 'illegible-text
3367 (skip-chars-forward mm-7bit-chars)
3369 (when (let ((char (char-after)))
3370 (or (< (mm-char-int char) 128)
3371 (and (mm-multibyte-p)
3372 (> (length (mm-find-mime-charset-region
3373 (point) (point-max)))
3375 (message-overlay-put (message-make-overlay (point) (1+ (point)))
3379 (skip-chars-forward mm-7bit-chars))
3382 (gnus-multiple-choice
3383 "Non-printable characters found. Continue sending?"
3384 '((?d "Remove non-printable characters and send")
3385 (?r "Replace non-printable characters with dots and send")
3386 (?i "Ignore non-printable characters and send")
3387 (?e "Continue editing"))))
3389 (error "Non-printable characters"))
3391 (skip-chars-forward mm-7bit-chars)
3393 (when (let ((char (char-after)))
3394 (or (< (mm-char-int char) 128)
3395 (and (mm-multibyte-p)
3396 ;; Fixme: Wrong for Emacs 22 and for things
3397 ;; like undecable utf-8. Should at least
3398 ;; use find-coding-systems-region.
3399 (memq (char-charset char)
3400 '(eight-bit-control eight-bit-graphic
3403 (message-kill-all-overlays)
3405 (when (eq choice ?r)
3408 (skip-chars-forward mm-7bit-chars))))))
3410 (defun message-add-action (action &rest types)
3411 "Add ACTION to be performed when doing an exit of type TYPES."
3413 (add-to-list (intern (format "message-%s-actions" (pop types)))
3416 (defun message-delete-action (action &rest types)
3417 "Delete ACTION from lists of actions performed when doing an exit of type TYPES."
3420 (set (setq var (intern (format "message-%s-actions" (pop types))))
3421 (delq action (symbol-value var))))))
3423 (defun message-do-actions (actions)
3424 "Perform all actions in ACTIONS."
3425 ;; Now perform actions on successful sending.
3429 ;; A simple function.
3430 ((functionp (car actions))
3431 (funcall (car actions)))
3432 ;; Something to be evaled.
3434 (eval (car actions)))))
3437 (defun message-send-mail-partially ()
3438 "Send mail as message/partial."
3439 ;; replace the header delimiter with a blank line
3440 (goto-char (point-min))
3442 (concat "^" (regexp-quote mail-header-separator) "\n"))
3443 (replace-match "\n")
3444 (run-hooks 'message-send-mail-hook)
3445 (let ((p (goto-char (point-min)))
3446 (tembuf (message-generate-new-buffer-clone-locals " message temp"))
3447 (curbuf (current-buffer))
3448 (id (message-make-message-id)) (n 1)
3449 plist total header required-mail-headers)
3451 (if (< (point-max) (+ p message-send-mail-partially-limit))
3452 (goto-char (point-max))
3453 (goto-char (+ p message-send-mail-partially-limit))
3455 (if (<= (point) p) (forward-line 1))) ;; In case of bad message.
3458 (setq total (length plist))
3459 (push (point-max) plist)
3460 (setq plist (nreverse plist))
3463 (setq p (pop plist))
3466 (copy-to-buffer tembuf p (car plist))
3468 (goto-char (point-min))
3471 (goto-char (point-min))
3472 (narrow-to-region (point) (point))
3475 (setq header (buffer-substring (point-min) (point)))
3476 (goto-char (point-min))
3477 (narrow-to-region (point) (point))
3479 (message-remove-header "Mime-Version")
3480 (message-remove-header "Content-Type")
3481 (message-remove-header "Content-Transfer-Encoding")
3482 (message-remove-header "Message-ID")
3483 (message-remove-header "Lines")
3484 (goto-char (point-max))
3485 (insert "Mime-Version: 1.0\n")
3486 (setq header (buffer-string)))
3487 (goto-char (point-max))
3488 (insert (format "Content-Type: message/partial; id=\"%s\"; number=%d; total=%d\n\n"
3491 (let ((mail-header-separator ""))
3492 (when (memq 'Message-ID message-required-mail-headers)
3493 (insert "Message-ID: " (message-make-message-id) "\n"))
3494 (when (memq 'Lines message-required-mail-headers)
3495 (insert "Lines: " (message-make-lines) "\n"))
3496 (message-goto-subject)
3498 (insert (format " (%d/%d)" n total))
3500 (mm-with-unibyte-current-buffer
3501 (funcall (or message-send-mail-real-function
3502 message-send-mail-function))))
3504 (setq p (pop plist))
3506 (kill-buffer tembuf))))
3508 (defun message-send-mail (&optional arg)
3509 (require 'mail-utils)
3510 (let* ((tembuf (message-generate-new-buffer-clone-locals " message temp"))
3511 (case-fold-search nil)
3512 (news (message-news-p))
3513 (mailbuf (current-buffer))
3514 (message-this-is-mail t)
3515 (message-posting-charset
3516 (if (fboundp 'gnus-setup-posting-charset)
3517 (gnus-setup-posting-charset nil)
3518 message-posting-charset))
3519 (headers message-required-mail-headers))
3521 (message-narrow-to-headers)
3522 ;; Generate the Mail-Followup-To header if the header is not there...
3523 (if (and (message-subscribed-p)
3524 (not (mail-fetch-field "mail-followup-to")))
3527 (cons "Mail-Followup-To" (message-make-mail-followup-to))
3528 message-required-mail-headers))
3529 ;; otherwise, delete the MFT header if the field is empty
3530 (when (equal "" (mail-fetch-field "mail-followup-to"))
3531 (message-remove-header "^Mail-Followup-To:")))
3532 ;; Insert some headers.
3533 (let ((message-deletable-headers
3534 (if news nil message-deletable-headers)))
3535 (message-generate-headers headers))
3536 ;; Let the user do all of the above.
3537 (run-hooks 'message-header-hook))
3542 ;; Avoid copying text props (except hard newlines).
3543 (insert (with-current-buffer mailbuf
3544 (mml-buffer-substring-no-properties-except-hard-newlines
3545 (point-min) (point-max))))
3546 ;; Remove some headers.
3547 (message-encode-message-body)
3549 (message-narrow-to-headers)
3550 ;; We (re)generate the Lines header.
3551 (when (memq 'Lines message-required-mail-headers)
3552 (message-generate-headers '(Lines)))
3553 ;; Remove some headers.
3554 (message-remove-header message-ignored-mail-headers t)
3555 (let ((mail-parse-charset message-default-charset))
3556 (mail-encode-encoded-word-buffer)))
3557 (goto-char (point-max))
3558 ;; require one newline at the end.
3559 (or (= (preceding-char) ?\n)
3561 (message-cleanup-headers)
3562 ;; FIXME: we're inserting the courtesy copy after encoding.
3563 ;; This is wrong if the courtesy copy string contains
3564 ;; non-ASCII characters. -- jh
3567 (message-narrow-to-headers)
3569 (or (message-fetch-field "cc")
3570 (message-fetch-field "bcc")
3571 (message-fetch-field "to"))
3572 (let ((content-type (message-fetch-field
3577 (string= "text/plain"
3579 (mail-header-parse-content-type
3583 (message-fetch-field
3584 "content-transfer-encoding")))))))
3585 (message-insert-courtesy-copy))
3586 (if (or (not message-send-mail-partially-limit)
3587 (< (point-max) message-send-mail-partially-limit)
3588 (not (message-y-or-n-p
3589 "The message size is too large, split? "
3593 (/ (point-max) 1000) "KB, is too large.
3595 Some mail gateways (MTA's) bounce large messages. To avoid the
3596 problem, answer `y', and the message will be split into several
3597 smaller pieces, the size of each is about "
3598 (/ message-send-mail-partially-limit 1000)
3602 However, some mail readers (MUA's) can't read split messages, i.e.,
3603 mails in message/partially format. Answer `n', and the message will be
3606 The size limit is controlled by `message-send-mail-partially-limit'.
3607 If you always want Gnus to send messages in one piece, set
3608 `message-send-mail-partially-limit' to nil.
3610 (mm-with-unibyte-current-buffer
3611 (message "Sending via mail...")
3612 (funcall (or message-send-mail-real-function
3613 message-send-mail-function)))
3614 (message-send-mail-partially)))
3615 (kill-buffer tembuf))
3616 (set-buffer mailbuf)
3617 (push 'mail message-sent-message-via)))
3619 (defun message-send-mail-with-sendmail ()
3620 "Send off the prepared buffer with sendmail."
3621 (let ((errbuf (if message-interactive
3622 (message-generate-new-buffer-clone-locals
3625 resend-to-addresses delimline)
3628 (let ((case-fold-search t))
3630 (message-narrow-to-headers)
3631 (setq resend-to-addresses (message-fetch-field "resent-to")))
3632 ;; Change header-delimiter to be what sendmail expects.
3633 (goto-char (point-min))
3635 (concat "^" (regexp-quote mail-header-separator) "\n"))
3636 (replace-match "\n")
3638 (setq delimline (point-marker))
3639 (run-hooks 'message-send-mail-hook)
3640 ;; Insert an extra newline if we need it to work around
3641 ;; Sun's bug that swallows newlines.
3642 (goto-char (1+ delimline))
3643 (when (eval message-mailer-swallows-blank-line)
3645 (when message-interactive
3649 (let* ((default-directory "/")
3650 (coding-system-for-write message-send-coding-system)
3652 'call-process-region
3654 (list (point-min) (point-max)
3655 (if (boundp 'sendmail-program)
3657 "/usr/lib/sendmail")
3658 nil errbuf nil "-oi")
3659 ;; Always specify who from,
3660 ;; since some systems have broken sendmails.
3661 ;; But some systems are more broken with -f, so
3662 ;; we'll let users override this.
3663 (if (null message-sendmail-f-is-evil)
3664 (list "-f" (message-sendmail-envelope-from)))
3665 ;; These mean "report errors by mail"
3666 ;; and "deliver in background".
3667 (if (null message-interactive) '("-oem" "-odb"))
3668 ;; Get the addresses from the message
3669 ;; unless this is a resend.
3670 ;; We must not do that for a resend
3671 ;; because we would find the original addresses.
3672 ;; For a resend, include the specific addresses.
3673 (if resend-to-addresses
3674 (list resend-to-addresses)
3676 (unless (or (null cpr) (and (numberp cpr) (zerop cpr)))
3677 (error "Sending...failed with exit value %d" cpr)))
3678 (when message-interactive
3681 (goto-char (point-min))
3682 (while (re-search-forward "\n\n* *" nil t)
3683 (replace-match "; "))
3684 (if (not (zerop (buffer-size)))
3685 (error "Sending...failed to %s"
3686 (buffer-string))))))
3687 (when (bufferp errbuf)
3688 (kill-buffer errbuf)))))
3690 (defun message-send-mail-with-qmail ()
3691 "Pass the prepared message buffer to qmail-inject.
3692 Refer to the documentation for the variable `message-send-mail-function'
3693 to find out how to use this."
3694 ;; replace the header delimiter with a blank line
3695 (goto-char (point-min))
3697 (concat "^" (regexp-quote mail-header-separator) "\n"))
3698 (replace-match "\n")
3699 (run-hooks 'message-send-mail-hook)
3702 (let ((coding-system-for-write message-send-coding-system))
3704 'call-process-region 1 (point-max) message-qmail-inject-program
3706 ;; qmail-inject's default behaviour is to look for addresses on the
3707 ;; command line; if there're none, it scans the headers.
3708 ;; yes, it does The Right Thing w.r.t. Resent-To and it's kin.
3710 ;; in general, ALL of qmail-inject's defaults are perfect for simply
3711 ;; reading a formatted (i. e., at least a To: or Resent-To header)
3712 ;; message from stdin.
3714 ;; qmail also has the advantage of not having been raped by
3715 ;; various vendors, so we don't have to allow for that, either --
3716 ;; compare this with message-send-mail-with-sendmail and weep
3717 ;; for sendmail's lost innocence.
3719 ;; all this is way cool coz it lets us keep the arguments entirely
3720 ;; free for -inject-arguments -- a big win for the user and for us
3721 ;; since we don't have to play that double-guessing game and the user
3722 ;; gets full control (no gestapo'ish -f's, for instance). --sj
3723 (if (functionp message-qmail-inject-args)
3724 (funcall message-qmail-inject-args)
3725 message-qmail-inject-args)))
3726 ;; qmail-inject doesn't say anything on it's stdout/stderr,
3727 ;; we have to look at the retval instead
3729 (100 (error "qmail-inject reported permanent failure"))
3730 (111 (error "qmail-inject reported transient failure"))
3731 ;; should never happen
3732 (t (error "qmail-inject reported unknown failure"))))
3734 (defun message-send-mail-with-mh ()
3735 "Send the prepared message buffer with mh."
3736 (let ((mh-previous-window-config nil)
3737 (name (mh-new-draft-name)))
3738 (setq buffer-file-name name)
3739 ;; MH wants to generate these headers itself.
3740 (when message-mh-deletable-headers
3741 (let ((headers message-mh-deletable-headers))
3743 (goto-char (point-min))
3744 (and (re-search-forward
3745 (concat "^" (symbol-name (car headers)) ": *") nil t)
3746 (message-delete-line))
3748 (run-hooks 'message-send-mail-hook)
3749 ;; Pass it on to mh.
3752 (defun message-smtpmail-send-it ()
3753 "Send the prepared message buffer with `smtpmail-send-it'.
3754 This only differs from `smtpmail-send-it' that this command evaluates
3755 `message-send-mail-hook' just before sending a message. It is useful
3756 if your ISP requires the POP-before-SMTP authentication. See the
3757 documentation for the function `mail-source-touch-pop'."
3758 (run-hooks 'message-send-mail-hook)
3761 (defun message-canlock-generate ()
3762 "Return a string that is non-trivial to guess.
3763 Do not use this for anything important, it is cryptographically weak."
3764 (let (sha1-maximum-internal-length)
3765 (sha1 (concat (message-unique-id)
3766 (format "%x%x%x" (random) (random t) (random))
3767 (prin1-to-string (recent-keys))
3768 (prin1-to-string (garbage-collect))))))
3770 (defun message-canlock-password ()
3771 "The password used by message for cancel locks.
3772 This is the value of `canlock-password', if that option is non-nil.
3773 Otherwise, generate and save a value for `canlock-password' first."
3774 (unless canlock-password
3775 (customize-save-variable 'canlock-password (message-canlock-generate))
3776 (setq canlock-password-for-verify canlock-password))
3779 (defun message-insert-canlock ()
3780 (when message-insert-canlock
3781 (message-canlock-password)
3782 (canlock-insert-header)))
3784 (defun message-send-news (&optional arg)
3785 (let* ((tembuf (message-generate-new-buffer-clone-locals " *message temp*"))
3786 (case-fold-search nil)
3787 (method (if (functionp message-post-method)
3788 (funcall message-post-method arg)
3789 message-post-method))
3790 (newsgroups-field (save-restriction
3791 (message-narrow-to-headers-or-head)
3792 (message-fetch-field "Newsgroups")))
3793 (followup-field (save-restriction
3794 (message-narrow-to-headers-or-head)
3795 (message-fetch-field "Followup-To")))
3796 ;; BUG: We really need to get the charset for each name in the
3797 ;; Newsgroups and Followup-To lines to allow crossposting
3798 ;; between group namess with incompatible character sets.
3799 ;; -- Per Abrahamsen <abraham@dina.kvl.dk> 2001-10-08.
3800 (group-field-charset
3801 (gnus-group-name-charset method newsgroups-field))
3802 (followup-field-charset
3803 (gnus-group-name-charset method (or followup-field "")))
3804 (rfc2047-header-encoding-alist
3805 (append (when group-field-charset
3806 (list (cons "Newsgroups" group-field-charset)))
3807 (when followup-field-charset
3808 (list (cons "Followup-To" followup-field-charset)))
3809 rfc2047-header-encoding-alist))
3810 (messbuf (current-buffer))
3811 (message-syntax-checks
3813 (listp message-syntax-checks))
3814 (cons '(existing-newsgroups . disabled)
3815 message-syntax-checks)
3816 message-syntax-checks))
3817 (message-this-is-news t)
3818 (message-posting-charset
3819 (gnus-setup-posting-charset newsgroups-field))
3821 (if (not (message-check-news-body-syntax))
3824 (message-narrow-to-headers)
3825 ;; Insert some headers.
3826 (message-generate-headers message-required-news-headers)
3827 (message-insert-canlock)
3828 ;; Let the user do all of the above.
3829 (run-hooks 'message-header-hook))
3830 ;; Note: This check will be disabled by the ".*" default value for
3831 ;; gnus-group-name-charset-group-alist. -- Pa 2001-10-07.
3832 (when (and group-field-charset
3833 (listp message-syntax-checks))
3834 (setq message-syntax-checks
3835 (cons '(valid-newsgroups . disabled)
3836 message-syntax-checks)))
3837 (message-cleanup-headers)
3838 (if (not (let ((message-post-method method))
3839 (message-check-news-syntax)))
3844 (buffer-disable-undo)
3846 ;; Avoid copying text props (except hard newlines).
3848 (with-current-buffer messbuf
3849 (mml-buffer-substring-no-properties-except-hard-newlines
3850 (point-min) (point-max))))
3851 (message-encode-message-body)
3852 ;; Remove some headers.
3854 (message-narrow-to-headers)
3855 ;; We (re)generate the Lines header.
3856 (when (memq 'Lines message-required-mail-headers)
3857 (message-generate-headers '(Lines)))
3858 ;; Remove some headers.
3859 (message-remove-header message-ignored-news-headers t)
3860 (let ((mail-parse-charset message-default-charset))
3861 (mail-encode-encoded-word-buffer)))
3862 (goto-char (point-max))
3863 ;; require one newline at the end.
3864 (or (= (preceding-char) ?\n)
3866 (let ((case-fold-search t))
3867 ;; Remove the delimiter.
3868 (goto-char (point-min))
3870 (concat "^" (regexp-quote mail-header-separator) "\n"))
3871 (replace-match "\n")
3873 (run-hooks 'message-send-news-hook)
3874 (gnus-open-server method)
3875 (message "Sending news via %s..." (gnus-server-string method))
3876 (setq result (let ((mail-header-separator ""))
3877 (gnus-request-post method))))
3878 (kill-buffer tembuf))
3879 (set-buffer messbuf)
3881 (push 'news message-sent-message-via)
3882 (message "Couldn't send message via news: %s"
3883 (nnheader-get-report (car method)))
3887 ;;; Header generation & syntax checking.
3890 (defun message-check-element (type)
3891 "Return non-nil if this TYPE is not to be checked."
3892 (if (eq message-syntax-checks 'dont-check-for-anything-just-trust-me)
3894 (let ((able (assq type message-syntax-checks)))
3896 (eq (cdr able) 'disabled)))))
3898 (defun message-check-news-syntax ()
3899 "Check the syntax of the message."
3903 ;; We narrow to the headers and check them first.
3906 (message-narrow-to-headers)
3907 (message-check-news-header-syntax))))))
3909 (defun message-check-news-header-syntax ()
3911 ;; Check Newsgroups header.
3912 (message-check 'newsgroups
3913 (let ((group (message-fetch-field "newsgroups")))
3916 (not (string-match "\\`[ \t]*\\'" group)))
3919 "The newsgroups field is empty or missing. Posting is denied.")))))
3920 ;; Check the Subject header.
3921 (message-check 'subject
3922 (let* ((case-fold-search t)
3923 (subject (message-fetch-field "subject")))
3926 (not (string-match "\\`[ \t]*\\'" subject)))
3929 "The subject field is empty or missing. Posting is denied.")))))
3930 ;; Check for commands in Subject.
3931 (message-check 'subject-cmsg
3932 (if (string-match "^cmsg " (message-fetch-field "subject"))
3934 "The control code \"cmsg\" is in the subject. Really post? ")
3936 ;; Check long header lines.
3937 (message-check 'long-header-lines
3938 (let ((start (point))
3942 (while (and (not found)
3943 (re-search-forward "^\\([^ \t:]+\\): " nil t))
3944 (if (> (- (point) (match-beginning 0)) 998)
3946 length (- (point) (match-beginning 0)))
3947 (setq header (match-string-no-properties 1)))
3948 (setq start (match-beginning 0))
3951 (y-or-n-p (format "Your %s header is too long (%d). Really post? "
3954 ;; Check for multiple identical headers.
3955 (message-check 'multiple-headers
3957 (while (and (not found)
3958 (re-search-forward "^[^ \t:]+: " nil t))
3960 (or (re-search-forward
3965 (match-beginning 0) (- (match-end 0) 2))))
3970 (y-or-n-p (format "Multiple %s headers. Really post? " found))
3972 ;; Check for Version and Sendsys.
3973 (message-check 'sendsys
3974 (if (re-search-forward "^Sendsys:\\|^Version:" nil t)
3976 (format "The article contains a %s command. Really post? "
3977 (buffer-substring (match-beginning 0)
3978 (1- (match-end 0)))))
3980 ;; See whether we can shorten Followup-To.
3981 (message-check 'shorten-followup-to
3982 (let ((newsgroups (message-fetch-field "newsgroups"))
3983 (followup-to (message-fetch-field "followup-to"))
3985 (when (and newsgroups
3986 (string-match "," newsgroups)
3991 (setq to (completing-read
3992 "Followups to (default: no Followup-To header) "
3995 (message-tokenize-header
3997 (goto-char (point-min))
3998 (insert "Followup-To: " to "\n"))
4000 ;; Check "Shoot me".
4001 (message-check 'shoot
4002 (if (re-search-forward
4003 "Message-ID.*.i-did-not-set--mail-host-address--so-tickle-me" nil t)
4004 (y-or-n-p "You appear to have a misconfigured system. Really post? ")
4006 ;; Check for Approved.
4007 (message-check 'approved
4008 (if (re-search-forward "^Approved:" nil t)
4009 (y-or-n-p "The article contains an Approved header. Really post? ")
4011 ;; Check the Message-ID header.
4012 (message-check 'message-id
4013 (let* ((case-fold-search t)
4014 (message-id (message-fetch-field "message-id" t)))
4015 (or (not message-id)
4016 ;; Is there an @ in the ID?
4017 (and (string-match "@" message-id)
4018 ;; Is there a dot in the ID?
4019 (string-match "@[^.]*\\." message-id)
4020 ;; Does the ID end with a dot?
4021 (not (string-match "\\.>" message-id)))
4023 (format "The Message-ID looks strange: \"%s\". Really post? "
4025 ;; Check the Newsgroups & Followup-To headers.
4026 (message-check 'existing-newsgroups
4027 (let* ((case-fold-search t)
4028 (newsgroups (message-fetch-field "newsgroups"))
4029 (followup-to (message-fetch-field "followup-to"))
4030 (groups (message-tokenize-header
4032 (concat newsgroups "," followup-to)
4034 (post-method (if (functionp message-post-method)
4035 (funcall message-post-method)
4036 message-post-method))
4037 ;; KLUDGE to handle nnvirtual groups. Doing this right
4038 ;; would probably involve a new nnoo function.
4039 ;; -- Per Abrahamsen <abraham@dina.kvl.dk>, 2001-10-17.
4040 (method (if (and (consp post-method)
4041 (eq (car post-method) 'nnvirtual)
4042 gnus-message-group-art)
4043 (let ((group (car (nnvirtual-find-group-art
4044 (car gnus-message-group-art)
4045 (cdr gnus-message-group-art)))))
4046 (gnus-find-method-for-group group))
4050 (gnus-group-name-decode
4051 (gnus-group-real-name n)
4052 (gnus-group-name-charset method n)))
4053 (gnus-groups-from-server method)))
4056 (when (and (not (equal (car groups) "poster"))
4057 (not (member (car groups) known-groups))
4058 (not (member (car groups) errors)))
4059 (push (car groups) errors))
4062 ;; Gnus is not running.
4063 ((or (not (and (boundp 'gnus-active-hashtb)
4064 gnus-active-hashtb))
4065 (not (boundp 'gnus-read-active-file)))
4067 ;; We don't have all the group names.
4068 ((and (or (not gnus-read-active-file)
4069 (eq gnus-read-active-file 'some))
4073 "Really use %s possibly unknown group%s: %s? "
4074 (if (= (length errors) 1) "this" "these")
4075 (if (= (length errors) 1) "" "s")
4076 (mapconcat 'identity errors ", "))))
4077 ;; There were no errors.
4080 ;; There are unknown groups.
4084 "Really post to %s unknown group%s: %s? "
4085 (if (= (length errors) 1) "this" "these")
4086 (if (= (length errors) 1) "" "s")
4087 (mapconcat 'identity errors ", ")))))))
4088 ;; Check continuation headers.
4089 (message-check 'continuation-headers
4090 (goto-char (point-min))
4091 (let ((do-posting t))
4092 (while (re-search-forward "^[^ \t\n][^:\n]*$" nil t)
4093 (if (y-or-n-p "Fix continuation lines? ")
4095 (goto-char (match-beginning 0))
4097 (unless (y-or-n-p "Send anyway? ")
4098 (setq do-posting nil))))
4100 ;; Check the Newsgroups & Followup-To headers for syntax errors.
4101 (message-check 'valid-newsgroups
4102 (let ((case-fold-search t)
4103 (headers '("Newsgroups" "Followup-To"))
4105 (while (and headers (not error))
4106 (when (setq header (mail-fetch-field (car headers)))
4110 "\\`\\([-+_&.a-zA-Z0-9]+\\)?\\(,[-+_&.a-zA-Z0-9]+\\)*\\'"
4115 (not (string-match "\\.\\'\\|\\.\\." g)))
4116 (message-tokenize-header header ","))))
4123 (format "The %s header looks odd: \"%s\". Really post? "
4124 (car headers) header)))))
4125 (message-check 'repeated-newsgroups
4126 (let ((case-fold-search t)
4127 (headers '("Newsgroups" "Followup-To"))
4128 header error groups group)
4131 (when (setq header (mail-fetch-field (pop headers)))
4132 (setq groups (message-tokenize-header header ","))
4133 (while (setq group (pop groups))
4134 (when (member group groups)
4140 (format "Group %s is repeated in headers. Really post? " error)))))
4141 ;; Check the From header.
4142 (message-check 'from
4143 (let* ((case-fold-search t)
4144 (from (message-fetch-field "from"))
4148 (message "There is no From line. Posting is denied.")
4150 ((or (not (string-match
4152 (setq ad (nth 1 (mail-extract-address-components
4153 from))))) ;larsi@ifi
4154 (string-match "\\.\\." ad) ;larsi@ifi..uio
4155 (string-match "@\\." ad) ;larsi@.ifi.uio
4156 (string-match "\\.$" ad) ;larsi@ifi.uio.
4157 (not (string-match "^[^@]+@[^@]+$" ad)) ;larsi.ifi.uio
4158 (string-match "(.*).*(.*)" from)) ;(lars) (lars)
4160 "Denied posting -- the From looks strange: \"%s\"." from)
4162 ((let ((addresses (rfc822-addresses from)))
4163 (while (and addresses
4164 (not (eq (string-to-char (car addresses)) ?\()))
4165 (setq addresses (cdr addresses)))
4168 "Denied posting -- bad From address: \"%s\"." from)
4171 ;; Check the Reply-To header.
4172 (message-check 'reply-to
4173 (let* ((case-fold-search t)
4174 (reply-to (message-fetch-field "reply-to"))
4179 ((string-match "," reply-to)
4181 (format "Multiple Reply-To addresses: \"%s\". Really post? "
4183 ((or (not (string-match
4185 (setq ad (nth 1 (mail-extract-address-components
4186 reply-to))))) ;larsi@ifi
4187 (string-match "\\.\\." ad) ;larsi@ifi..uio
4188 (string-match "@\\." ad) ;larsi@.ifi.uio
4189 (string-match "\\.$" ad) ;larsi@ifi.uio.
4190 (not (string-match "^[^@]+@[^@]+$" ad)) ;larsi.ifi.uio
4191 (string-match "(.*).*(.*)" reply-to)) ;(lars) (lars)
4194 "The Reply-To looks strange: \"%s\". Really post? "
4198 (defun message-check-news-body-syntax ()
4200 ;; Check for long lines.
4201 (message-check 'long-lines
4202 (goto-char (point-min))
4204 (concat "^" (regexp-quote mail-header-separator) "$"))
4208 "<#\\(/\\)?\\(multipart\\|part\\|external\\|mml\\)")
4211 (< (- (point) p) 80)))
4212 (zerop (forward-line 1))))
4216 "You have lines longer than 79 characters. Really post? ")))
4217 ;; Check whether the article is empty.
4218 (message-check 'empty
4219 (goto-char (point-min))
4221 (concat "^" (regexp-quote mail-header-separator) "$"))
4224 (goto-char (point-max))
4225 (re-search-backward message-signature-separator nil t)
4227 (or (re-search-backward "[^ \n\t]" b t)
4228 (if (message-gnksa-enable-p 'empty-article)
4229 (y-or-n-p "Empty article. Really post? ")
4230 (message "Denied posting -- Empty article.")
4232 ;; Check for control characters.
4233 (message-check 'control-chars
4234 (if (re-search-forward "[\000-\007\013\015-\032\034-\037\200-\237]" nil t)
4236 "The article contains control characters. Really post? ")
4238 ;; Check excessive size.
4239 (message-check 'size
4240 (if (> (buffer-size) 60000)
4242 (format "The article is %d octets long. Really post? "
4245 ;; Check whether any new text has been added.
4246 (message-check 'new-text
4248 (not message-checksum)
4249 (not (eq (message-checksum) message-checksum))
4250 (if (message-gnksa-enable-p 'quoted-text-only)
4252 "It looks like no new text has been added. Really post? ")
4253 (message "Denied posting -- no new text has been added.")
4255 ;; Check the length of the signature.
4256 (message-check 'signature
4257 (goto-char (point-max))
4258 (if (> (count-lines (point) (point-max)) 5)
4261 "Your .sig is %d lines; it should be max 4. Really post? "
4262 (1- (count-lines (point) (point-max)))))
4264 ;; Ensure that text follows last quoted portion.
4265 (message-check 'quoting-style
4266 (goto-char (point-max))
4267 (let ((no-problem t))
4268 (when (search-backward-regexp "^>[^\n]*\n" nil t)
4269 (setq no-problem (search-forward-regexp "^[ \t]*[^>\n]" nil t)))
4272 (if (message-gnksa-enable-p 'quoted-text-only)
4273 (y-or-n-p "Your text should follow quoted text. Really post? ")
4275 (goto-char (point-min))
4277 (concat "^" (regexp-quote mail-header-separator) "$"))
4278 (if (search-forward-regexp "^[ \t]*[^>\n]" nil t)
4279 (y-or-n-p "Your text should follow quoted text. Really post? ")
4280 (message "Denied posting -- only quoted text.")
4283 (defun message-checksum ()
4284 "Return a \"checksum\" for the current buffer."
4287 (goto-char (point-min))
4289 (concat "^" (regexp-quote mail-header-separator) "$"))
4291 (when (not (looking-at "[ \t\n]"))
4292 (setq sum (logxor (ash sum 1) (if (natnump sum) 0 1)
4297 (defun message-do-fcc ()
4298 "Process Fcc headers in the current buffer."
4299 (let ((case-fold-search t)
4300 (buf (current-buffer))
4302 (mml-externalize-attachments message-fcc-externalize-attachments))
4305 (message-narrow-to-headers)
4306 (setq file (message-fetch-field "fcc" t)))
4308 (set-buffer (get-buffer-create " *message temp*"))
4310 (insert-buffer-substring buf)
4311 (message-encode-message-body)
4313 (message-narrow-to-headers)
4314 (while (setq file (message-fetch-field "fcc" t))
4316 (message-remove-header "fcc" nil t))
4317 (let ((mail-parse-charset message-default-charset)
4318 (rfc2047-header-encoding-alist
4319 (cons '("Newsgroups" . default)
4320 rfc2047-header-encoding-alist)))
4321 (mail-encode-encoded-word-buffer)))
4322 (goto-char (point-min))
4323 (when (re-search-forward
4324 (concat "^" (regexp-quote mail-header-separator) "$")
4326 (replace-match "" t t ))
4327 ;; Process FCC operations.
4329 (setq file (pop list))
4330 (if (string-match "^[ \t]*|[ \t]*\\(.*\\)[ \t]*$" file)
4331 ;; Pipe the article to the program in question.
4332 (call-process-region (point-min) (point-max) shell-file-name
4333 nil nil nil shell-command-switch
4334 (match-string 1 file))
4335 ;; Save the article.
4336 (setq file (expand-file-name file))
4337 (unless (file-exists-p (file-name-directory file))
4338 (make-directory (file-name-directory file) t))
4339 (if (and message-fcc-handler-function
4340 (not (eq message-fcc-handler-function 'rmail-output)))
4341 (funcall message-fcc-handler-function file)
4342 (if (and (file-readable-p file) (mail-file-babyl-p file))
4343 (rmail-output file 1 nil t)
4344 (let ((mail-use-rfc822 t))
4345 (rmail-output file 1 t t))))))
4346 (kill-buffer (current-buffer))))))
4348 (defun message-output (filename)
4349 "Append this article to Unix/babyl mail file FILENAME."
4350 (if (and (file-readable-p filename)
4351 (mail-file-babyl-p filename))
4352 (gnus-output-to-rmail filename t)
4353 (gnus-output-to-mail filename t)))
4355 (defun message-cleanup-headers ()
4356 "Do various automatic cleanups of the headers."
4357 ;; Remove empty lines in the header.
4359 (message-narrow-to-headers)
4360 ;; Remove blank lines.
4361 (while (re-search-forward "^[ \t]*\n" nil t)
4362 (replace-match "" t t))
4364 ;; Correct Newsgroups and Followup-To headers: Change sequence of
4365 ;; spaces to comma and eliminate spaces around commas. Eliminate
4366 ;; embedded line breaks.
4367 (goto-char (point-min))
4368 (while (re-search-forward "^\\(Newsgroups\\|Followup-To\\): +" nil t)
4372 (if (re-search-forward "^[^ \t]" nil t)
4376 (goto-char (point-min))
4377 (while (re-search-forward "\n[ \t]+" nil t)
4378 (replace-match " " t t)) ;No line breaks (too confusing)
4379 (goto-char (point-min))
4380 (while (re-search-forward "[ \t\n]*,[ \t\n]*\\|[ \t]+" nil t)
4381 (replace-match "," t t))
4382 (goto-char (point-min))
4383 ;; Remove trailing commas.
4384 (when (re-search-forward ",+$" nil t)
4385 (replace-match "" t t))))))
4387 (defun message-make-date (&optional now)
4388 "Make a valid data header.
4389 If NOW, use that time instead."
4390 (let* ((now (or now (current-time)))
4391 (zone (nth 8 (decode-time now)))
4395 (setq zone (- zone)))
4397 ;; The day name of the %a spec is locale-specific. Pfff.
4398 (format "%s, " (capitalize (car (rassoc (nth 6 (decode-time now))
4399 parse-time-weekdays))))
4400 (format-time-string "%d" now)
4401 ;; The month name of the %b spec is locale-specific. Pfff.
4403 (capitalize (car (rassoc (nth 4 (decode-time now))
4404 parse-time-months))))
4405 (format-time-string "%Y %H:%M:%S " now)
4406 ;; We do all of this because XEmacs doesn't have the %z spec.
4407 (format "%s%02d%02d" sign (/ zone 3600) (/ (% zone 3600) 60)))))
4409 (defun message-make-message-id ()
4410 "Make a unique Message-ID."
4411 (concat "<" (message-unique-id)
4412 (let ((psubject (save-excursion (message-fetch-field "subject")))
4414 (save-excursion (message-fetch-field "supersedes"))))
4416 (and message-reply-headers
4417 (mail-header-references message-reply-headers)
4418 (mail-header-subject message-reply-headers)
4421 (message-strip-subject-re
4422 (mail-header-subject message-reply-headers))
4423 (message-strip-subject-re psubject))))
4425 (string-match "_-_@" psupersedes)))
4427 "@" (message-make-fqdn) ">"))
4429 (defvar message-unique-id-char nil)
4431 ;; If you ever change this function, make sure the new version
4432 ;; cannot generate IDs that the old version could.
4433 ;; You might for example insert a "." somewhere (not next to another dot
4434 ;; or string boundary), or modify the "fsf" string.
4435 (defun message-unique-id ()
4436 ;; Don't use microseconds from (current-time), they may be unsupported.
4437 ;; Instead we use this randomly inited counter.
4438 (setq message-unique-id-char
4439 (% (1+ (or message-unique-id-char (logand (random t) (1- (lsh 1 20)))))
4440 ;; (current-time) returns 16-bit ints,
4441 ;; and 2^16*25 just fits into 4 digits i base 36.
4443 (let ((tm (current-time)))
4445 (if (memq system-type '(ms-dos emx vax-vms))
4446 (let ((user (downcase (user-login-name))))
4447 (while (string-match "[^a-z0-9_]" user)
4448 (aset user (match-beginning 0) ?_))
4450 (message-number-base36 (user-uid) -1))
4451 (message-number-base36 (+ (car tm)
4452 (lsh (% message-unique-id-char 25) 16)) 4)
4453 (message-number-base36 (+ (nth 1 tm)
4454 (lsh (/ message-unique-id-char 25) 16)) 4)
4455 ;; Append a given name, because while the generated ID is unique
4456 ;; to this newsreader, other newsreaders might otherwise generate
4457 ;; the same ID via another algorithm.
4460 (defun message-number-base36 (num len)
4465 (concat (message-number-base36 (/ num 36) (1- len))
4466 (char-to-string (aref "zyxwvutsrqponmlkjihgfedcba9876543210"
4469 (defun message-make-organization ()
4470 "Make an Organization header."
4471 (let* ((organization
4472 (when message-user-organization
4473 (if (functionp message-user-organization)
4474 (funcall message-user-organization)
4475 message-user-organization))))
4477 (mm-enable-multibyte)
4478 (cond ((stringp organization)
4479 (insert organization))
4480 ((and (eq t organization)
4481 message-user-organization-file
4482 (file-exists-p message-user-organization-file))
4483 (insert-file-contents message-user-organization-file)))
4484 (goto-char (point-min))
4485 (while (re-search-forward "[\t\n]+" nil t)
4486 (replace-match "" t t))
4487 (unless (zerop (buffer-size))
4490 (defun message-make-lines ()
4491 "Count the number of lines and return numeric string."
4496 (int-to-string (count-lines (point) (point-max))))))
4498 (defun message-make-references ()
4499 "Return the References header for this message."
4500 (when message-reply-headers
4501 (let ((message-id (mail-header-message-id message-reply-headers))
4502 (references (mail-header-references message-reply-headers))
4504 (if (or references message-id)
4505 (concat (or references "") (and references " ")
4509 (defun message-make-in-reply-to ()
4510 "Return the In-Reply-To header for this message."
4511 (when message-reply-headers
4512 (let ((from (mail-header-from message-reply-headers))
4513 (date (mail-header-date message-reply-headers))
4514 (msg-id (mail-header-message-id message-reply-headers)))
4516 (let ((name (mail-extract-address-components from)))
4517 (concat msg-id (if msg-id " (")
4521 (if (or (not date) (string= date ""))
4522 "(unknown date)" date)
4523 "\"" (if msg-id ")")))))))
4525 (defun message-make-distribution ()
4526 "Make a Distribution header."
4527 (let ((orig-distribution (message-fetch-reply-field "distribution")))
4528 (cond ((functionp message-distribution-function)
4529 (funcall message-distribution-function))
4530 (t orig-distribution))))
4532 (defun message-make-expires ()
4533 "Return an Expires header based on `message-expires'."
4534 (let ((current (current-time))
4535 (future (* 1.0 message-expires 60 60 24)))
4536 ;; Add the future to current.
4537 (setcar current (+ (car current) (round (/ future (expt 2 16)))))
4538 (setcar (cdr current) (+ (nth 1 current) (% (round future) (expt 2 16))))
4539 (message-make-date current)))
4541 (defun message-make-path ()
4543 (let ((login-name (user-login-name)))
4544 (cond ((null message-user-path)
4545 (concat (system-name) "!" login-name))
4546 ((stringp message-user-path)
4547 ;; Support GENERICPATH. Suggested by vixie@decwrl.dec.com.
4548 (concat message-user-path "!" login-name))
4551 (defun message-make-from ()
4552 "Make a From header."
4553 (let* ((style message-from-style)
4554 (login (message-make-address))
4556 (or (and (boundp 'user-full-name)
4559 (when (string= fullname "&")
4560 (setq fullname (user-login-name)))
4562 (mm-enable-multibyte)
4565 (equal fullname ""))
4567 ((or (eq style 'angles)
4568 (and (not (eq style 'parens))
4569 ;; Use angles if no quoting is needed, or if parens would
4570 ;; need quoting too.
4571 (or (not (string-match "[^- !#-'*+/-9=?A-Z^-~]" fullname))
4572 (let ((tmp (concat fullname nil)))
4573 (while (string-match "([^()]*)" tmp)
4574 (aset tmp (match-beginning 0) ?-)
4575 (aset tmp (1- (match-end 0)) ?-))
4576 (string-match "[\\()]" tmp)))))
4578 (goto-char (point-min))
4579 ;; Look for a character that cannot appear unquoted
4580 ;; according to RFC 822.
4581 (when (re-search-forward "[^- !#-'*+/-9=?A-Z^-~]" nil 1)
4582 ;; Quote fullname, escaping specials.
4583 (goto-char (point-min))
4585 (while (re-search-forward "[\"\\]" nil 1)
4586 (replace-match "\\\\\\&" t))
4588 (insert " <" login ">"))
4589 (t ; 'parens or default
4591 (let ((fullname-start (point)))
4593 (goto-char fullname-start)
4594 ;; RFC 822 says \ and nonmatching parentheses
4595 ;; must be escaped in comments.
4596 ;; Escape every instance of ()\ ...
4597 (while (re-search-forward "[()\\]" nil 1)
4598 (replace-match "\\\\\\&" t))
4599 ;; ... then undo escaping of matching parentheses,
4600 ;; including matching nested parentheses.
4601 (goto-char fullname-start)
4602 (while (re-search-forward
4603 "\\(\\=\\|[^\\]\\(\\\\\\\\\\)*\\)\\\\(\\(\\([^\\]\\|\\\\\\\\\\)*\\)\\\\)"
4605 (replace-match "\\1(\\3)" t)
4606 (goto-char fullname-start)))
4610 (defun message-make-sender ()
4611 "Return the \"real\" user address.
4612 This function tries to ignore all user modifications, and
4613 give as trustworthy answer as possible."
4614 (concat (user-login-name) "@" (system-name)))
4616 (defun message-make-address ()
4617 "Make the address of the user."
4618 (or (message-user-mail-address)
4619 (concat (user-login-name) "@" (message-make-domain))))
4621 (defun message-user-mail-address ()
4622 "Return the pertinent part of `user-mail-address'."
4623 (when (and user-mail-address
4624 (string-match "@.*\\." user-mail-address))
4625 (if (string-match " " user-mail-address)
4626 (nth 1 (mail-extract-address-components user-mail-address))
4627 user-mail-address)))
4629 (defun message-sendmail-envelope-from ()
4630 "Return the envelope from."
4631 (cond ((eq message-sendmail-envelope-from 'header)
4632 (nth 1 (mail-extract-address-components
4633 (message-fetch-field "from"))))
4634 ((stringp message-sendmail-envelope-from)
4635 message-sendmail-envelope-from)
4637 (message-make-address))))
4639 (defun message-make-fqdn ()
4640 "Return user's fully qualified domain name."
4641 (let* ((system-name (system-name))
4642 (user-mail (message-user-mail-address))
4645 (string-match "@\\(.*\\)\\'" user-mail))
4646 (match-string 1 user-mail)))
4647 (case-fold-search t))
4649 ((and message-user-fqdn
4650 (stringp message-user-fqdn)
4651 (string-match message-valid-fqdn-regexp message-user-fqdn)
4652 (not (string-match message-bogus-system-names message-user-fqdn)))
4654 ;; `message-user-fqdn' seems to be valid
4655 ((and (string-match message-valid-fqdn-regexp system-name)
4656 (not (string-match message-bogus-system-names system-name)))
4657 ;; `system-name' returned the right result.
4659 ;; Try `mail-host-address'.
4660 ((and (boundp 'mail-host-address)
4661 (stringp mail-host-address)
4662 (string-match message-valid-fqdn-regexp mail-host-address)
4663 (not (string-match message-bogus-system-names mail-host-address)))
4665 ;; We try `user-mail-address' as a backup.
4667 (stringp user-domain)
4668 (string-match message-valid-fqdn-regexp user-domain)
4669 (not (string-match message-bogus-system-names user-domain)))
4671 ;; Default to this bogus thing.
4674 ".i-did-not-set--mail-host-address--so-tickle-me")))))
4676 (defun message-make-host-name ()
4677 "Return the name of the host."
4678 (let ((fqdn (message-make-fqdn)))
4679 (string-match "^[^.]+\\." fqdn)
4680 (substring fqdn 0 (1- (match-end 0)))))
4682 (defun message-make-domain ()
4683 "Return the domain name."
4684 (or mail-host-address
4685 (message-make-fqdn)))
4687 (defun message-to-list-only ()
4688 "Send a message to the list only.
4689 Remove all addresses but the list address from To and Cc headers."
4691 (let ((listaddr (message-make-mail-followup-to t)))
4694 (message-remove-header "to")
4695 (message-remove-header "cc")
4696 (message-position-on-field "To" "X-Draft-From")
4697 (insert listaddr)))))
4699 (defun message-make-mail-followup-to (&optional only-show-subscribed)
4700 "Return the Mail-Followup-To header.
4701 If passed the optional argument ONLY-SHOW-SUBSCRIBED only return the
4702 subscribed address (and not the additional To and Cc header contents)."
4703 (let* ((case-fold-search t)
4704 (to (message-fetch-field "To"))
4705 (cc (message-fetch-field "cc"))
4706 (msg-recipients (concat to (and to cc ", ") cc))
4708 (mapcar 'mail-strip-quoted-names
4709 (message-tokenize-header msg-recipients)))
4711 (if message-subscribed-address-file
4712 (let (begin end item re)
4715 (insert-file-contents message-subscribed-address-file)
4717 (setq begin (point))
4720 (if (bolp) (setq end (1- end)))
4721 (setq item (regexp-quote (buffer-substring begin end)))
4722 (if re (setq re (concat re "\\|" item))
4723 (setq re (concat "\\`\\(" item))))
4724 (and re (list (concat re "\\)\\'"))))))))
4725 (mft-regexps (apply 'append message-subscribed-regexps
4726 (mapcar 'regexp-quote
4727 message-subscribed-addresses)
4730 message-subscribed-address-functions))))
4732 (let ((subscribed-lists nil)
4734 (loop for recipient in recipients
4735 when (loop for regexp in mft-regexps
4736 when (string-match regexp recipient) return t)
4739 (if only-show-subscribed
4741 msg-recipients))))))
4743 (defun message-idna-inside-rhs-p ()
4744 "Return t iff point is inside a RHS (heuristically).
4745 Only works properly if header contains mailbox-list or address-list.
4746 I.e., calling it on a Subject: header is useless."
4748 (narrow-to-region (save-excursion (or (re-search-backward "^[^ \t]" nil t)
4750 (save-excursion (or (re-search-forward "^[^ \t]" nil t)
4752 (if (re-search-backward "[\\\n\r\t ]"
4753 (save-excursion (search-backward "@" nil t)) t)
4754 ;; whitespace between @ and point
4756 (let ((dquote 1) (paren 1))
4757 (while (save-excursion (re-search-backward "[^\\]\"" nil t dquote))
4759 (while (save-excursion (re-search-backward "[^\\]\(" nil t paren))
4761 (and (= (% dquote 2) 1) (= (% paren 2) 1))))))
4763 (autoload 'idna-to-ascii "idna")
4765 (defun message-idna-to-ascii-rhs-1 (header)
4766 "Interactively potentially IDNA encode domain names in HEADER."
4767 (let (rhs ace start startpos endpos ovl)
4768 (goto-char (point-min))
4769 (while (re-search-forward (concat "^" header) nil t)
4770 (while (re-search-forward "@\\([^ \t\r\n>,]+\\)"
4772 (re-search-forward "^[^ \t]" nil t))
4775 (setq rhs (match-string-no-properties 1)
4776 startpos (match-beginning 1)
4777 endpos (match-end 1))
4778 (when (save-match-data
4779 (and (message-idna-inside-rhs-p)
4780 (setq ace (idna-to-ascii rhs))
4781 (not (string= rhs ace))
4782 (if (eq message-use-idna 'ask)
4785 (setq ovl (message-make-overlay startpos
4787 (message-overlay-put ovl 'face 'highlight)
4789 (format "Replace with `%s'? " ace)))
4791 (message-delete-overlay ovl))
4793 (replace-match (concat "@" ace)))))))
4795 (defun message-idna-to-ascii-rhs ()
4796 "Possibly IDNA encode non-ASCII domain names in From:, To: and Cc: headers.
4797 See `message-idna-encode'."
4799 (when message-use-idna
4802 (message-narrow-to-head)
4803 (message-idna-to-ascii-rhs-1 "From")
4804 (message-idna-to-ascii-rhs-1 "To")
4805 (message-idna-to-ascii-rhs-1 "Cc")))))
4807 (defun message-generate-headers (headers)
4808 "Prepare article HEADERS.
4809 Headers already prepared in the buffer are not modified."
4810 (setq headers (append headers message-required-headers))
4812 (message-narrow-to-headers)
4813 (let* ((Date (message-make-date))
4814 (Message-ID (message-make-message-id))
4815 (Organization (message-make-organization))
4816 (From (message-make-from))
4817 (Path (message-make-path))
4820 (In-Reply-To (message-make-in-reply-to))
4821 (References (message-make-references))
4823 (Distribution (message-make-distribution))
4824 (Lines (message-make-lines))
4825 (User-Agent message-newsreader)
4826 (Expires (message-make-expires))
4827 (case-fold-search t)
4829 header value elem header-string)
4830 ;; First we remove any old generated headers.
4831 (let ((headers message-deletable-headers))
4832 (unless (buffer-modified-p)
4833 (setq headers (delq 'Message-ID (copy-sequence headers))))
4835 (goto-char (point-min))
4836 (and (re-search-forward
4837 (concat "^" (symbol-name (car headers)) ": *") nil t)
4838 (get-text-property (1+ (match-beginning 0)) 'message-deletable)
4839 (message-delete-line))
4841 ;; Go through all the required headers and see if they are in the
4842 ;; articles already. If they are not, or are empty, they are
4843 ;; inserted automatically - except for Subject, Newsgroups and
4846 (goto-char (point-min))
4847 (setq elem (pop headers))
4849 (if (eq (car elem) 'optional)
4850 (setq header (cdr elem)
4852 (setq header (car elem)))
4854 (setq header-string (if (stringp header)
4856 (symbol-name header)))
4857 (when (or (not (re-search-forward
4859 (regexp-quote (downcase header-string))
4863 ;; The header was found. We insert a space after the
4864 ;; colon, if there is none.
4865 (if (/= (char-after) ? ) (insert " ") (forward-char 1))
4866 ;; Find out whether the header is empty.
4867 (looking-at "[ \t]*\n[^ \t]")))
4868 ;; So we find out what value we should insert.
4872 (eq (car elem) 'optional)
4873 (not (member header-string message-inserted-headers)))
4874 ;; This is an optional header. If the cdr of this
4875 ;; is something that is nil, then we do not insert
4877 (setq header (cdr elem))
4878 (or (and (functionp (cdr elem))
4879 (funcall (cdr elem)))
4880 (and (boundp (cdr elem))
4881 (symbol-value (cdr elem)))))
4883 ;; The element is a cons. Either the cdr is a
4884 ;; string to be inserted verbatim, or it is a
4885 ;; function, and we insert the value returned from
4887 (or (and (stringp (cdr elem))
4889 (and (functionp (cdr elem))
4890 (funcall (cdr elem)))))
4891 ((and (boundp header)
4892 (symbol-value header))
4893 ;; The element is a symbol. We insert the value
4894 ;; of this symbol, if any.
4895 (symbol-value header))
4896 ((not (message-check-element header))
4897 ;; We couldn't generate a value for this header,
4898 ;; so we just ask the user.
4899 (read-from-minibuffer
4900 (format "Empty header for %s; enter value: " header)))))
4901 ;; Finally insert the header.
4903 (not (equal value "")))
4907 ;; This header didn't exist, so we insert it.
4908 (goto-char (point-max))
4910 (cdr (assq header message-header-format-alist))))
4912 (funcall formatter header value)
4913 (insert header-string ": " value))
4914 ;; We check whether the value was ended by a
4915 ;; newline. If now, we insert one.
4919 ;; The value of this header was empty, so we clear
4920 ;; totally and insert the new value.
4921 (delete-region (point) (gnus-point-at-eol))
4922 ;; If the header is optional, and the header was
4923 ;; empty, we con't insert it anyway.
4925 (push header-string message-inserted-headers)
4927 ;; Add the deletable property to the headers that require it.
4928 (and (memq header message-deletable-headers)
4929 (progn (beginning-of-line) (looking-at "[^:]+: "))
4930 (add-text-properties
4931 (point) (match-end 0)
4932 '(message-deletable t face italic) (current-buffer)))))))
4933 ;; Insert new Sender if the From is strange.
4934 (let ((from (message-fetch-field "from"))
4935 (sender (message-fetch-field "sender"))
4936 (secure-sender (message-make-sender)))
4938 (not (message-check-element 'sender))
4941 (cadr (mail-extract-address-components from)))
4942 (downcase secure-sender)))
4947 (cadr (mail-extract-address-components sender)))
4948 (downcase secure-sender)))))
4949 (goto-char (point-min))
4950 ;; Rename any old Sender headers to Original-Sender.
4951 (when (re-search-forward "^\\(Original-\\)*Sender:" nil t)
4953 (insert "Original-")
4954 (beginning-of-line))
4955 (when (or (message-news-p)
4956 (string-match "@.+\\.." secure-sender))
4957 (insert "Sender: " secure-sender "\n"))))
4959 (message-idna-to-ascii-rhs))))
4961 (defun message-insert-courtesy-copy ()
4962 "Insert a courtesy message in mail copies of combined messages."
4966 (message-narrow-to-headers)
4967 (when (setq newsgroups (message-fetch-field "newsgroups"))
4968 (goto-char (point-max))
4969 (insert "Posted-To: " newsgroups "\n")))
4971 (when message-courtesy-message
4973 ((string-match "%s" message-courtesy-message)
4974 (insert (format message-courtesy-message newsgroups)))
4976 (insert message-courtesy-message)))))))
4979 ;;; Setting up a message buffer
4982 (defun message-fill-address (header value)
4984 (narrow-to-region (point) (point))
4985 (insert (capitalize (symbol-name header))
4987 (if (consp value) (car value) value)
4989 (narrow-to-region (point-min) (1- (point-max)))
4991 (goto-char (point-min))
4993 (skip-chars-forward "^,\"" (point-max))
4994 (if (or (eq (char-after) ?,)
4997 (if (and (> (current-column) 78)
5003 (setq last (1+ (point))))
5004 (setq last (1+ (point)))))
5005 (setq quoted (not quoted)))
5008 (goto-char (point-max))
5012 (defun message-split-line ()
5013 "Split current line, moving portion beyond point vertically down.
5014 If the current line has `message-yank-prefix', insert it on the new line."
5017 (split-line message-yank-prefix) ;; Emacs 21.3.50+ supports arg.
5022 (defun message-fill-header (header value)
5023 (let ((begin (point))
5026 (insert (capitalize (symbol-name header))
5028 (if (consp value) (car value) value)
5031 (narrow-to-region begin (point))
5032 (fill-region-as-paragraph begin (point))
5033 ;; Tapdance around looong Message-IDs.
5035 (when (looking-at "[ \t]*$")
5036 (message-delete-line))
5038 (re-search-forward ":" nil t)
5039 (when (looking-at "\n[ \t]+")
5040 (replace-match " " t t))
5041 (goto-char (point-max)))))
5043 (defun message-shorten-1 (list cut surplus)
5044 "Cut SURPLUS elements out of LIST, beginning with CUTth one."
5045 (setcdr (nthcdr (- cut 2) list)
5046 (nthcdr (+ (- cut 2) surplus 1) list)))
5048 (defun message-shorten-references (header references)
5049 "Trim REFERENCES to be 21 Message-ID long or less, and fold them.
5050 If folding is disallowed, also check that the REFERENCES are less
5051 than 988 characters long, and if they are not, trim them until they are."
5058 (goto-char (point-min))
5059 ;; Cons a list of valid references.
5060 (while (re-search-forward "<[^>]+>" nil t)
5061 (push (match-string 0) refs))
5062 (setq refs (nreverse refs)
5063 count (length refs)))
5065 ;; If the list has more than MAXCOUNT elements, trim it by
5066 ;; removing the CUTth element and the required number of
5067 ;; elements that follow.
5068 (when (> count maxcount)
5069 (let ((surplus (- count maxcount)))
5070 (message-shorten-1 refs cut surplus)
5071 (decf count surplus)))
5073 ;; If folding is disallowed, make sure the total length (including
5074 ;; the spaces between) will be less than MAXSIZE characters.
5076 ;; Only disallow folding for News messages. At this point the headers
5077 ;; have not been generated, thus we use message-this-is-news directly.
5078 (when (and message-this-is-news message-cater-to-broken-inn)
5080 (totalsize (+ (apply #'+ (mapcar #'length refs))
5083 (ptr (nthcdr (1- cut) refs)))
5084 ;; Decide how many elements to cut off...
5085 (while (> totalsize maxsize)
5086 (decf totalsize (1+ (length (car ptr))))
5088 (setq ptr (cdr ptr)))
5091 (message-shorten-1 refs cut surplus))))
5093 ;; Finally, collect the references back into a string and insert
5094 ;; it into the buffer.
5095 (let ((refstring (mapconcat #'identity refs " ")))
5096 (if (and message-this-is-news message-cater-to-broken-inn)
5097 (insert (capitalize (symbol-name header)) ": "
5099 (message-fill-header header refstring)))))
5101 (defun message-position-point ()
5102 "Move point to where the user probably wants to find it."
5103 (message-narrow-to-headers)
5105 ((re-search-forward "^[^:]+:[ \t]*$" nil t)
5106 (search-backward ":" )
5109 (if (eq (char-after) ? )
5113 (goto-char (point-max))
5116 (unless (looking-at "$")
5120 (defcustom message-beginning-of-line t
5121 "Whether \\<message-mode-map>\\[message-beginning-of-line]\
5122 goes to beginning of header values."
5123 :group 'message-buffers
5126 (defun message-beginning-of-line (&optional n)
5127 "Move point to beginning of header value or to beginning of line.
5128 The prefix argument N is passed directly to `beginning-of-line'.
5130 This command is identical to `beginning-of-line' if point is
5131 outside the message header or if the option `message-beginning-of-line'
5134 If point is in the message header and on a (non-continued) header
5135 line, move point to the beginning of the header value. If point
5136 is already there, move point to beginning of line. Therefore,
5137 repeated calls will toggle point between beginning of field and
5140 (let ((zrs 'zmacs-region-stays))
5141 (when (and (interactive-p) (boundp zrs))
5143 (if (and message-beginning-of-line
5144 (message-point-in-header-p))
5145 (let* ((here (point))
5146 (bol (progn (beginning-of-line n) (point)))
5147 (eol (gnus-point-at-eol))
5148 (eoh (re-search-forward ": *" eol t)))
5149 (if (or (not eoh) (equal here eoh))
5152 (beginning-of-line n)))
5154 (defun message-buffer-name (type &optional to group)
5155 "Return a new (unique) buffer name based on TYPE and TO."
5157 ;; Generate a new buffer name The Message Way.
5158 ((eq message-generate-new-buffers 'unique)
5159 (generate-new-buffer-name
5163 (or (car (mail-extract-address-components to))
5166 (if (and group (not (string= group ""))) (concat " on " group) "")
5168 ;; Check whether `message-generate-new-buffers' is a function,
5169 ;; and if so, call it.
5170 ((functionp message-generate-new-buffers)
5171 (funcall message-generate-new-buffers type to group))
5172 ((eq message-generate-new-buffers 'unsent)
5173 (generate-new-buffer-name
5174 (concat "*unsent " type
5177 (or (car (mail-extract-address-components to))
5180 (if (and group (not (string= group ""))) (concat " on " group) "")
5182 ;; Use standard name.
5184 (format "*%s message*" type))))
5186 (defun message-pop-to-buffer (name)
5187 "Pop to buffer NAME, and warn if it already exists and is modified."
5188 (let ((buffer (get-buffer name)))
5190 (buffer-name buffer))
5192 (set-buffer (pop-to-buffer buffer))
5193 (when (and (buffer-modified-p)
5195 "Message already being composed; erase? ")))
5196 (error "Message being composed")))
5197 (set-buffer (pop-to-buffer name)))
5201 (defun message-do-send-housekeeping ()
5202 "Kill old message buffers."
5203 ;; We might have sent this buffer already. Delete it from the
5205 (setq message-buffer-list (delq (current-buffer) message-buffer-list))
5206 (while (and message-max-buffers
5208 (>= (length message-buffer-list) message-max-buffers))
5209 ;; Kill the oldest buffer -- unless it has been changed.
5210 (let ((buffer (pop message-buffer-list)))
5211 (when (and (buffer-name buffer)
5212 (not (buffer-modified-p buffer)))
5213 (kill-buffer buffer))))
5214 ;; Rename the buffer.
5215 (if message-send-rename-function
5216 (funcall message-send-rename-function)
5217 ;; Note: mail-abbrevs of XEmacs renames buffer name behind Gnus.
5219 "\\`\\*\\(sent \\|unsent \\)?\\(.+\\)\\*[^\\*]*\\|\\`mail to "
5221 (let ((name (match-string 2 (buffer-name)))
5223 (if (not (or (null name)
5224 (string-equal name "mail")
5225 (string-equal name "posting")))
5226 (setq name (concat "*sent " name "*"))
5227 (message-narrow-to-headers)
5228 (setq to (message-fetch-field "to"))
5229 (setq group (message-fetch-field "newsgroups"))
5233 (to (concat "*sent mail to "
5234 (or (car (mail-extract-address-components to))
5236 ((and group (not (string= group "")))
5237 (concat "*sent posting on " group "*"))
5238 (t "*sent mail*"))))
5239 (unless (string-equal name (buffer-name))
5240 (rename-buffer name t)))))
5241 ;; Push the current buffer onto the list.
5242 (when message-max-buffers
5243 (setq message-buffer-list
5244 (nconc message-buffer-list (list (current-buffer))))))
5246 (defun message-mail-user-agent ()
5248 ((not message-mail-user-agent) nil)
5249 ((eq message-mail-user-agent t) mail-user-agent)
5250 (t message-mail-user-agent))))
5251 (if (memq mua '(message-user-agent gnus-user-agent))
5255 (defun message-setup (headers &optional replybuffer actions switch-function)
5256 (let ((mua (message-mail-user-agent))
5257 subject to field yank-action)
5258 (if (not (and message-this-is-mail mua))
5259 (message-setup-1 headers replybuffer actions)
5261 (setq yank-action (list 'insert-buffer replybuffer)))
5262 (setq headers (copy-sequence headers))
5263 (setq field (assq 'Subject headers))
5265 (setq subject (cdr field))
5266 (setq headers (delq field headers)))
5267 (setq field (assq 'To headers))
5269 (setq to (cdr field))
5270 (setq headers (delq field headers)))
5271 (let ((mail-user-agent mua))
5272 (compose-mail to subject
5273 (mapcar (lambda (item)
5275 (format "%s" (car item))
5278 nil switch-function yank-action actions)))))
5280 (defun message-headers-to-generate (headers included-headers excluded-headers)
5281 "Return a list that includes all headers from HEADERS.
5282 If INCLUDED-HEADERS is a list, just include those headers. If if is
5283 t, include all headers. In any case, headers from EXCLUDED-HEADERS
5287 (dolist (header headers)
5288 (setq header-name (cond
5289 ((and (consp header)
5290 (eq (car header) 'optional))
5291 ;; On the form (optional . Header)
5294 ;; On the form (Header . function)
5299 (when (and (not (memq header-name excluded-headers))
5300 (or (eq included-headers t)
5301 (memq header-name included-headers)))
5302 (push header result)))
5305 (defun message-setup-1 (headers &optional replybuffer actions)
5306 (dolist (action actions)
5308 (add-to-list 'message-send-actions
5309 `(apply ',(car action) ',(cdr action)))))
5310 (setq message-reply-buffer replybuffer)
5311 (goto-char (point-min))
5312 ;; Insert all the headers.
5315 (alist message-header-format-alist))
5317 (unless (assq (caar h) message-header-format-alist)
5318 (push (list (caar h)) alist))
5322 (delete-region (point) (progn (forward-line -1) (point)))
5323 (when message-default-headers
5324 (insert message-default-headers)
5325 (or (bolp) (insert ?\n)))
5329 (insert mail-header-separator "\n")
5333 (when (message-news-p)
5334 (when message-default-news-headers
5335 (insert message-default-news-headers)
5336 (or (bolp) (insert ?\n)))
5337 (when message-generate-headers-first
5338 (message-generate-headers
5339 (message-headers-to-generate
5340 (append message-required-news-headers
5341 message-required-headers)
5342 message-generate-headers-first
5343 '(Lines Subject)))))
5344 (when (message-mail-p)
5345 (when message-default-mail-headers
5346 (insert message-default-mail-headers)
5347 (or (bolp) (insert ?\n)))
5349 (message-narrow-to-headers)
5350 (if message-alternative-emails
5351 (message-use-alternative-email-as-from)))
5352 (when message-generate-headers-first
5353 (message-generate-headers
5354 (message-headers-to-generate
5355 (append message-required-mail-headers
5356 message-required-headers)
5357 message-generate-headers-first
5358 '(Lines Subject)))))
5359 (run-hooks 'message-signature-setup-hook)
5360 (message-insert-signature)
5362 (message-narrow-to-headers)
5363 (run-hooks 'message-header-setup-hook))
5364 (set-buffer-modified-p nil)
5365 (setq buffer-undo-list nil)
5366 (run-hooks 'message-setup-hook)
5367 (message-position-point)
5370 (defun message-set-auto-save-file-name ()
5371 "Associate the message buffer with a file in the drafts directory."
5372 (when message-auto-save-directory
5373 (unless (file-directory-p
5374 (directory-file-name message-auto-save-directory))
5375 (make-directory message-auto-save-directory t))
5377 (setq message-draft-article
5378 (nndraft-request-associate-buffer "drafts"))
5379 (setq buffer-file-name (expand-file-name
5380 (if (memq system-type
5381 '(ms-dos ms-windows windows-nt
5382 cygwin cygwin32 win32 w32
5386 message-auto-save-directory))
5387 (setq buffer-auto-save-file-name (make-auto-save-file-name)))
5388 (clear-visited-file-modtime)
5389 (setq buffer-file-coding-system message-draft-coding-system)))
5391 (defun message-disassociate-draft ()
5392 "Disassociate the message buffer from the drafts directory."
5393 (when message-draft-article
5394 (nndraft-request-expire-articles
5395 (list message-draft-article) "drafts" nil t)))
5397 (defun message-insert-headers ()
5398 "Generate the headers for the article."
5402 (message-narrow-to-headers)
5403 (when (message-news-p)
5404 (message-generate-headers
5407 (copy-sequence message-required-news-headers)))))
5408 (when (message-mail-p)
5409 (message-generate-headers
5412 (copy-sequence message-required-mail-headers))))))))
5417 ;;; Commands for interfacing with message
5421 (defun message-mail (&optional to subject
5422 other-headers continue switch-function
5423 yank-action send-actions)
5424 "Start editing a mail message to be sent.
5425 OTHER-HEADERS is an alist of header/value pairs."
5427 (let ((message-this-is-mail t) replybuffer)
5428 (unless (message-mail-user-agent)
5429 (message-pop-to-buffer (message-buffer-name "mail" to)))
5430 ;; FIXME: message-mail should do something if YANK-ACTION is not
5432 (and (consp yank-action) (eq (car yank-action) 'insert-buffer)
5433 (setq replybuffer (nth 1 yank-action)))
5436 `((To . ,(or to "")) (Subject . ,(or subject "")))
5437 (when other-headers other-headers))
5438 replybuffer send-actions)
5439 ;; FIXME: Should return nil if failure.
5443 (defun message-news (&optional newsgroups subject)
5444 "Start editing a news article to be sent."
5446 (let ((message-this-is-news t))
5447 (message-pop-to-buffer (message-buffer-name "posting" nil newsgroups))
5448 (message-setup `((Newsgroups . ,(or newsgroups ""))
5449 (Subject . ,(or subject ""))))))
5451 (defun message-get-reply-headers (wide &optional to-address address-headers)
5452 (let (follow-to mct never-mct to cc author mft recipients)
5453 ;; Find all relevant headers we need.
5454 (setq to (message-fetch-field "to")
5455 cc (message-fetch-field "cc")
5456 mct (message-fetch-field "mail-copies-to")
5457 author (or (message-fetch-field "mail-reply-to")
5458 (message-fetch-field "reply-to")
5459 (message-fetch-field "from")
5461 mft (and message-use-mail-followup-to
5462 (message-fetch-field "mail-followup-to")))
5464 ;; Handle special values of Mail-Copies-To.
5466 (cond ((or (equal (downcase mct) "never")
5467 (equal (downcase mct) "nobody"))
5470 ((or (equal (downcase mct) "always")
5471 (equal (downcase mct) "poster"))
5472 (setq mct author))))
5475 ;; Build (textual) list of new recipient addresses.
5478 (setq recipients (concat ", " author)))
5480 (dolist (header address-headers)
5481 (let ((value (message-fetch-field header)))
5483 (setq recipients (concat recipients ", " value))))))
5485 (string-match "[^ \t,]" mft)
5486 (or (not (eq message-use-mail-followup-to 'ask))
5487 (message-y-or-n-p "Obey Mail-Followup-To? " t "\
5488 You should normally obey the Mail-Followup-To: header. In this
5489 article, it has the value of
5493 which directs your response to " (if (string-match "," mft)
5494 "the specified addresses"
5495 "that address only") ".
5497 Most commonly, Mail-Followup-To is used by a mailing list poster to
5498 express that responses should be sent to just the list, and not the
5501 If a message is posted to several mailing lists, Mail-Followup-To may
5502 also be used to direct the following discussion to one list only,
5503 because discussions that are spread over several lists tend to be
5504 fragmented and very difficult to follow.
5506 Also, some source/announcement lists are not intended for discussion;
5507 responses here are directed to other addresses.")))
5508 (setq recipients (concat ", " mft)))
5510 (setq recipients (concat ", " to-address))
5511 ;; If the author explicitly asked for a copy, we don't deny it to them.
5512 (if mct (setq recipients (concat recipients ", " mct))))
5514 (setq recipients (if never-mct "" (concat ", " author)))
5515 (if to (setq recipients (concat recipients ", " to)))
5516 (if cc (setq recipients (concat recipients ", " cc)))
5517 (if mct (setq recipients (concat recipients ", " mct)))))
5518 (if (>= (length recipients) 2)
5519 ;; Strip the leading ", ".
5520 (setq recipients (substring recipients 2)))
5521 ;; Squeeze whitespace.
5522 (while (string-match "[ \t][ \t]+" recipients)
5523 (setq recipients (replace-match " " t t recipients)))
5524 ;; Remove addresses that match `rmail-dont-reply-to-names'.
5525 (let ((rmail-dont-reply-to-names message-dont-reply-to-names))
5526 (setq recipients (rmail-dont-reply-to recipients)))
5527 ;; Perhaps "Mail-Copies-To: never" removed the only address?
5528 (if (string-equal recipients "")
5529 (setq recipients author))
5530 ;; Convert string to a list of (("foo@bar" . "Name <Foo@BAR>") ...).
5534 (cons (downcase (mail-strip-quoted-names addr)) addr))
5535 (message-tokenize-header recipients)))
5536 ;; Remove first duplicates. (Why not all duplicates? Is this a bug?)
5537 (let ((s recipients))
5539 (setq recipients (delq (assoc (car (pop s)) s) recipients))))
5541 ;; Remove hierarchical lists that are contained within each other,
5542 ;; if message-hierarchical-addresses is defined.
5543 (when message-hierarchical-addresses
5544 (let ((plain-addrs (mapcar 'car recipients))
5547 (setq subaddrs (assoc (car plain-addrs)
5548 message-hierarchical-addresses)
5549 plain-addrs (cdr plain-addrs))
5551 (setq subaddrs (cdr subaddrs))
5553 (setq recip (assoc (car subaddrs) recipients)
5554 subaddrs (cdr subaddrs))
5556 (setq recipients (delq recip recipients))))))))
5558 ;; Build the header alist. Allow the user to be asked whether
5559 ;; or not to reply to all recipients in a wide reply.
5560 (setq follow-to (list (cons 'To (cdr (pop recipients)))))
5561 (when (and recipients
5562 (or (not message-wide-reply-confirm-recipients)
5563 (y-or-n-p "Reply to all recipients? ")))
5564 (setq recipients (mapconcat
5565 (lambda (addr) (cdr addr)) recipients ", "))
5566 (if (string-match "^ +" recipients)
5567 (setq recipients (substring recipients (match-end 0))))
5568 (push (cons 'Cc recipients) follow-to)))
5572 (defun message-reply (&optional to-address wide)
5573 "Start editing a reply to the article in the current buffer."
5575 (require 'gnus-sum) ; for gnus-list-identifiers
5576 (let ((cur (current-buffer))
5577 from subject date reply-to to cc
5578 references message-id follow-to
5579 (inhibit-point-motion-hooks t)
5580 (message-this-is-mail t)
5583 (message-narrow-to-head-1)
5584 ;; Allow customizations to have their say.
5586 ;; This is a regular reply.
5587 (when (functionp message-reply-to-function)
5589 (setq follow-to (funcall message-reply-to-function))))
5590 ;; This is a followup.
5591 (when (functionp message-wide-reply-to-function)
5594 (funcall message-wide-reply-to-function)))))
5595 (setq message-id (message-fetch-field "message-id" t)
5596 references (message-fetch-field "references")
5597 date (message-fetch-field "date")
5598 from (message-fetch-field "from")
5599 subject (or (message-fetch-field "subject") "none"))
5600 (when gnus-list-identifiers
5601 (setq subject (message-strip-list-identifiers subject)))
5602 (setq subject (concat "Re: " (message-strip-subject-re subject)))
5603 (when message-subject-trailing-was-query
5604 (setq subject (message-strip-subject-trailing-was subject)))
5606 (when (and (setq gnus-warning (message-fetch-field "gnus-warning"))
5607 (string-match "<[^>]+>" gnus-warning))
5608 (setq message-id (match-string 0 gnus-warning)))
5611 (setq follow-to (message-get-reply-headers wide to-address))))
5613 (unless (message-mail-user-agent)
5614 (message-pop-to-buffer
5615 (message-buffer-name
5616 (if wide "wide reply" "reply") from
5617 (if wide to-address nil))))
5619 (setq message-reply-headers
5620 (vector 0 subject from date message-id references 0 0 ""))
5623 `((Subject . ,subject)
5628 (defun message-wide-reply (&optional to-address)
5629 "Make a \"wide\" reply to the message in the current buffer."
5631 (message-reply to-address t))
5634 (defun message-followup (&optional to-newsgroups)
5635 "Follow up to the message in the current buffer.
5636 If TO-NEWSGROUPS, use that as the new Newsgroups line."
5638 (require 'gnus-sum) ; for gnus-list-identifiers
5639 (let ((cur (current-buffer))
5640 from subject date reply-to mrt mct
5641 references message-id follow-to
5642 (inhibit-point-motion-hooks t)
5643 (message-this-is-news t)
5644 followup-to distribution newsgroups gnus-warning posted-to)
5647 (goto-char (point-min))
5648 (if (search-forward "\n\n" nil t)
5651 (when (functionp message-followup-to-function)
5653 (funcall message-followup-to-function)))
5654 (setq from (message-fetch-field "from")
5655 date (message-fetch-field "date")
5656 subject (or (message-fetch-field "subject") "none")
5657 references (message-fetch-field "references")
5658 message-id (message-fetch-field "message-id" t)
5659 followup-to (message-fetch-field "followup-to")
5660 newsgroups (message-fetch-field "newsgroups")
5661 posted-to (message-fetch-field "posted-to")
5662 reply-to (message-fetch-field "reply-to")
5663 mrt (message-fetch-field "mail-reply-to")
5664 distribution (message-fetch-field "distribution")
5665 mct (message-fetch-field "mail-copies-to"))
5666 (when (and (setq gnus-warning (message-fetch-field "gnus-warning"))
5667 (string-match "<[^>]+>" gnus-warning))
5668 (setq message-id (match-string 0 gnus-warning)))
5669 ;; Remove bogus distribution.
5670 (when (and (stringp distribution)
5671 (let ((case-fold-search t))
5672 (string-match "world" distribution)))
5673 (setq distribution nil))
5674 (if gnus-list-identifiers
5675 (setq subject (message-strip-list-identifiers subject)))
5676 (setq subject (concat "Re: " (message-strip-subject-re subject)))
5677 (when message-subject-trailing-was-query
5678 (setq subject (message-strip-subject-trailing-was subject)))
5681 (message-pop-to-buffer (message-buffer-name "followup" from newsgroups))
5683 (setq message-reply-headers
5684 (vector 0 subject from date message-id references 0 0 ""))
5687 `((Subject . ,subject)
5690 (list (cons 'Newsgroups to-newsgroups)))
5691 (follow-to follow-to)
5692 ((and followup-to message-use-followup-to)
5695 ((equal (downcase followup-to) "poster")
5696 (if (or (eq message-use-followup-to 'use)
5697 (message-y-or-n-p "Obey Followup-To: poster? " t "\
5698 You should normally obey the Followup-To: header.
5700 `Followup-To: poster' sends your response via e-mail instead of news.
5702 A typical situation where `Followup-To: poster' is used is when the poster
5703 does not read the newsgroup, so he wouldn't see any replies sent to it."))
5705 (setq message-this-is-news nil)
5706 (cons 'To (or mrt reply-to from "")))
5707 (cons 'Newsgroups newsgroups)))
5709 (if (or (equal followup-to newsgroups)
5710 (not (eq message-use-followup-to 'ask))
5712 (concat "Obey Followup-To: " followup-to "? ") t "\
5713 You should normally obey the Followup-To: header.
5715 `Followup-To: " followup-to "'
5716 directs your response to " (if (string-match "," followup-to)
5717 "the specified newsgroups"
5718 "that newsgroup only") ".
5720 If a message is posted to several newsgroups, Followup-To is often
5721 used to direct the following discussion to one newsgroup only,
5722 because discussions that are spread over several newsgroup tend to
5723 be fragmented and very difficult to follow.
5725 Also, some source/announcement newsgroups are not intended for discussion;
5726 responses here are directed to other newsgroups."))
5727 (cons 'Newsgroups followup-to)
5728 (cons 'Newsgroups newsgroups))))))
5730 `((Newsgroups . ,posted-to)))
5732 `((Newsgroups . ,newsgroups))))
5733 ,@(and distribution (list (cons 'Distribution distribution)))
5735 (not (or (equal (downcase mct) "never")
5736 (equal (downcase mct) "nobody"))))
5737 (list (cons 'Cc (if (or (equal (downcase mct) "always")
5738 (equal (downcase mct) "poster"))
5739 (or mrt reply-to from "")
5744 (defun message-is-yours-p ()
5745 "Non-nil means current article is yours.
5746 If you have added 'cancel-messages to 'message-shoot-gnksa-feet', all articles
5747 are yours except those that have Cancel-Lock header not belonging to you.
5748 Instead of shooting GNKSA feet, you should modify 'message-alternative-emails'
5749 regexp to match all of yours addresses."
5750 ;; Canlock-logic as suggested by Per Abrahamsen
5751 ;; <abraham@dina.kvl.dk>
5753 ;; IF article has cancel-lock THEN
5754 ;; IF we can verify it THEN
5757 ;; error: cancellock: article is not yours
5759 ;; Use old rules, comparing sender...
5762 (message-narrow-to-head-1)
5763 (if (message-fetch-field "Cancel-Lock")
5764 (if (null (canlock-verify))
5766 (error "Failed to verify Cancel-lock: This article is not yours"))
5769 (message-gnksa-enable-p 'cancel-messages)
5770 (and (setq sender (message-fetch-field "sender"))
5771 (string-equal (downcase sender)
5772 (downcase (message-make-sender))))
5773 ;; Email address in From field equals to our address
5774 (and (setq from (message-fetch-field "from"))
5776 (downcase (cadr (mail-extract-address-components from)))
5777 (downcase (cadr (mail-extract-address-components
5778 (message-make-from))))))
5779 ;; Email address in From field matches
5780 ;; 'message-alternative-emails' regexp
5782 message-alternative-emails
5784 message-alternative-emails
5785 (cadr (mail-extract-address-components from))))))))))
5788 (defun message-cancel-news (&optional arg)
5789 "Cancel an article you posted.
5790 If ARG, allow editing of the cancellation message."
5792 (unless (message-news-p)
5793 (error "This is not a news article; canceling is impossible"))
5794 (let (from newsgroups message-id distribution buf)
5796 ;; Get header info from original article.
5798 (message-narrow-to-head-1)
5799 (setq from (message-fetch-field "from")
5800 newsgroups (message-fetch-field "newsgroups")
5801 message-id (message-fetch-field "message-id" t)
5802 distribution (message-fetch-field "distribution")))
5803 ;; Make sure that this article was written by the user.
5804 (unless (message-is-yours-p)
5805 (error "This article is not yours"))
5806 (when (yes-or-no-p "Do you really want to cancel this article? ")
5807 ;; Make control message.
5810 (setq buf (set-buffer (get-buffer-create " *message cancel*"))))
5812 (insert "Newsgroups: " newsgroups "\n"
5814 "Subject: cmsg cancel " message-id "\n"
5815 "Control: cancel " message-id "\n"
5817 (concat "Distribution: " distribution "\n")
5819 mail-header-separator "\n"
5820 message-cancel-message)
5821 (run-hooks 'message-cancel-hook)
5823 (message "Canceling your article...")
5824 (if (let ((message-syntax-checks
5825 'dont-check-for-anything-just-trust-me))
5826 (funcall message-send-news-function))
5827 (message "Canceling your article...done"))
5828 (kill-buffer buf))))))
5831 (defun message-supersede ()
5832 "Start composing a message to supersede the current message.
5833 This is done simply by taking the old article and adding a Supersedes
5834 header line with the old Message-ID."
5836 (let ((cur (current-buffer)))
5837 ;; Check whether the user owns the article that is to be superseded.
5838 (unless (message-is-yours-p)
5839 (error "This article is not yours"))
5840 ;; Get a normal message buffer.
5841 (message-pop-to-buffer (message-buffer-name "supersede"))
5842 (insert-buffer-substring cur)
5844 (message-narrow-to-head-1)
5845 ;; Remove unwanted headers.
5846 (when message-ignored-supersedes-headers
5847 (message-remove-header message-ignored-supersedes-headers t))
5848 (goto-char (point-min))
5849 (if (not (re-search-forward "^Message-ID: " nil t))
5850 (error "No Message-ID in this article")
5851 (replace-match "Supersedes: " t t))
5852 (goto-char (point-max))
5853 (insert mail-header-separator)
5858 (defun message-recover ()
5859 "Reread contents of current buffer from its last auto-save file."
5861 (let ((file-name (make-auto-save-file-name)))
5862 (cond ((save-window-excursion
5863 (if (not (eq system-type 'vax-vms))
5864 (with-output-to-temp-buffer "*Directory*"
5865 (with-current-buffer standard-output
5866 (fundamental-mode)) ; for Emacs 20.4+
5867 (buffer-disable-undo standard-output)
5868 (let ((default-directory "/"))
5870 "ls" nil standard-output nil "-l" file-name))))
5871 (yes-or-no-p (format "Recover auto save file %s? " file-name)))
5872 (let ((buffer-read-only nil))
5874 (insert-file-contents file-name nil)))
5875 (t (error "message-recover cancelled")))))
5877 ;;; Washing Subject:
5879 (defun message-wash-subject (subject)
5880 "Remove junk like \"Re:\", \"(fwd)\", etc. added to subject string SUBJECT.
5881 Previous forwarders, replyers, etc. may add it."
5884 (goto-char (point-min))
5885 ;; strip Re/Fwd stuff off the beginning
5886 (while (re-search-forward
5887 "\\([Rr][Ee]:\\|[Ff][Ww][Dd]\\(\\[[0-9]*\\]\\)?:\\|[Ff][Ww]:\\)" nil t)
5890 ;; and gnus-style forwards [foo@bar.com] subject
5891 (goto-char (point-min))
5892 (while (re-search-forward "\\[[^ \t]*\\(@\\|\\.\\)[^ \t]*\\]" nil t)
5896 (goto-char (point-max))
5897 (while (re-search-backward "([Ff][Ww][Dd])" nil t)
5900 ;; and finally, any whitespace that was left-over
5901 (goto-char (point-min))
5902 (while (re-search-forward "^[ \t]+" nil t)
5904 (goto-char (point-max))
5905 (while (re-search-backward "[ \t]+$" nil t)
5910 ;;; Forwarding messages.
5912 (defvar message-forward-decoded-p nil
5913 "Non-nil means the original message is decoded.")
5915 (defun message-forward-subject-name-subject (subject)
5916 "Generate a SUBJECT for a forwarded message.
5917 The form is: [Source] Subject, where if the original message was mail,
5918 Source is the name of the sender, and if the original message was
5919 news, Source is the list of newsgroups is was posted to."
5920 (let* ((group (message-fetch-field "newsgroups"))
5921 (from (message-fetch-field "from"))
5924 (gnus-group-decoded-name group)
5925 (or (and from (cdr (mail-header-parse-address from)))
5928 (if message-forward-decoded-p
5930 (mail-decode-encoded-word-string prefix))
5933 (defun message-forward-subject-author-subject (subject)
5934 "Generate a SUBJECT for a forwarded message.
5935 The form is: [Source] Subject, where if the original message was mail,
5936 Source is the sender, and if the original message was news, Source is
5937 the list of newsgroups is was posted to."
5938 (let* ((group (message-fetch-field "newsgroups"))
5941 (gnus-group-decoded-name group)
5942 (or (message-fetch-field "from")
5945 (if message-forward-decoded-p
5947 (mail-decode-encoded-word-string prefix))
5950 (defun message-forward-subject-fwd (subject)
5951 "Generate a SUBJECT for a forwarded message.
5952 The form is: Fwd: Subject, where Subject is the original subject of
5954 (if (string-match "^Fwd: " subject)
5956 (concat "Fwd: " subject)))
5958 (defun message-make-forward-subject ()
5959 "Return a Subject header suitable for the message in the current buffer."
5962 (message-narrow-to-head-1)
5963 (let ((funcs message-make-forward-subject-function)
5964 (subject (message-fetch-field "Subject")))
5967 (if message-forward-decoded-p
5969 (mail-decode-encoded-word-string subject))
5971 (if message-wash-forwarded-subjects
5972 (setq subject (message-wash-subject subject)))
5973 ;; Make sure funcs is a list.
5976 (setq funcs (list funcs)))
5977 ;; Apply funcs in order, passing subject generated by previous
5978 ;; func to the next one.
5980 (when (functionp (car funcs))
5981 (setq subject (funcall (car funcs) subject)))
5982 (setq funcs (cdr funcs)))
5986 (defvar gnus-article-decoded-p))
5990 (defun message-forward (&optional news digest)
5991 "Forward the current message via mail.
5992 Optional NEWS will use news to forward instead of mail.
5993 Optional DIGEST will use digest to forward."
5995 (let* ((cur (current-buffer))
5996 (message-forward-decoded-p
5997 (if (local-variable-p 'gnus-article-decoded-p (current-buffer))
5998 gnus-article-decoded-p ;; In an article buffer.
5999 message-forward-decoded-p))
6000 (subject (message-make-forward-subject)))
6002 (message-news nil subject)
6003 (message-mail nil subject))
6004 (message-forward-make-body cur digest)))
6006 (defun message-forward-make-body-plain (forward-buffer)
6008 "\n-------------------- Start of forwarded message --------------------\n")
6009 (let ((b (point)) e)
6012 (mm-disable-multibyte)
6014 (with-current-buffer forward-buffer
6015 (mm-with-unibyte-current-buffer (buffer-string))))
6016 (mm-enable-multibyte)
6018 (goto-char (point-min))
6019 (when (looking-at "From ")
6020 (replace-match "X-From-Line: "))
6024 "\n-------------------- End of forwarded message --------------------\n")
6025 (when (and (not current-prefix-arg)
6026 message-forward-ignored-headers)
6028 (narrow-to-region b e)
6030 (narrow-to-region (point)
6031 (or (search-forward "\n\n" nil t) (point)))
6032 (message-remove-header message-forward-ignored-headers t)))))
6034 (defun message-forward-make-body-mime (forward-buffer)
6035 (insert "\n\n<#part type=message/rfc822 disposition=inline raw=t>\n")
6036 (let ((b (point)) e)
6038 (narrow-to-region (point) (point))
6039 (mml-insert-buffer forward-buffer)
6040 (goto-char (point-min))
6041 (when (looking-at "From ")
6042 (replace-match "X-From-Line: "))
6043 (goto-char (point-max)))
6045 (insert "<#/part>\n")))
6047 (defun message-forward-make-body-mml (forward-buffer)
6048 (insert "\n\n<#mml type=message/rfc822 disposition=inline>\n")
6049 (let ((b (point)) e)
6050 (if (not message-forward-decoded-p)
6053 (mm-disable-multibyte)
6055 (with-current-buffer forward-buffer
6056 (mm-with-unibyte-current-buffer (buffer-string))))
6057 (mm-enable-multibyte)
6059 (goto-char (point-min))
6060 (when (looking-at "From ")
6061 (replace-match "X-From-Line: "))
6064 (narrow-to-region (point) (point))
6065 (mml-insert-buffer forward-buffer)
6066 (goto-char (point-min))
6067 (when (looking-at "From ")
6068 (replace-match "X-From-Line: "))
6069 (goto-char (point-max))))
6071 (insert "<#/mml>\n")
6072 (when (and (not current-prefix-arg)
6073 message-forward-ignored-headers)
6075 (narrow-to-region b e)
6077 (narrow-to-region (point)
6078 (or (search-forward "\n\n" nil t) (point)))
6079 (message-remove-header message-forward-ignored-headers t)))))
6081 (defun message-forward-make-body-digest-plain (forward-buffer)
6083 "\n-------------------- Start of forwarded message --------------------\n")
6084 (let ((b (point)) e)
6085 (mml-insert-buffer forward-buffer)
6088 "\n-------------------- End of forwarded message --------------------\n")))
6090 (defun message-forward-make-body-digest-mime (forward-buffer)
6091 (insert "\n<#multipart type=digest>\n")
6092 (let ((b (point)) e)
6093 (insert-buffer-substring forward-buffer)
6095 (insert "<#/multipart>\n")
6097 (narrow-to-region b e)
6099 (narrow-to-region (point)
6100 (or (search-forward "\n\n" nil t) (point)))
6101 (delete-region (point-min) (point-max)))))
6103 (defun message-forward-make-body-digest (forward-buffer)
6104 (if message-forward-as-mime
6105 (message-forward-make-body-digest-mime forward-buffer)
6106 (message-forward-make-body-digest-plain forward-buffer)))
6109 (defun message-forward-make-body (forward-buffer &optional digest)
6110 ;; Put point where we want it before inserting the forwarded
6112 (if message-forward-before-signature
6114 (goto-char (point-max)))
6116 (message-forward-make-body-digest forward-buffer)
6117 (if message-forward-as-mime
6118 (if (and message-forward-show-mml
6119 (not (and (eq message-forward-show-mml 'best)
6120 (with-current-buffer forward-buffer
6121 (goto-char (point-min))
6123 "Content-Type: *multipart/\\(signed\\|encrypted\\)"
6125 (message-forward-make-body-mml forward-buffer)
6126 (message-forward-make-body-mime forward-buffer))
6127 (message-forward-make-body-plain forward-buffer)))
6128 (message-position-point))
6131 (defun message-forward-rmail-make-body (forward-buffer)
6132 (save-window-excursion
6133 (set-buffer forward-buffer)
6134 ;; Rmail doesn't have rmail-msg-restore-non-pruned-header in Emacs
6135 ;; 20. FIXIT, or we drop support for rmail in Emacs 20.
6136 (if (rmail-msg-is-pruned)
6137 (rmail-msg-restore-non-pruned-header)))
6138 (message-forward-make-body forward-buffer))
6140 (eval-when-compile (defvar rmail-enable-mime-composing))
6142 ;; Fixme: Should have defcustom.
6144 (defun message-insinuate-rmail ()
6145 "Let RMAIL use message to forward."
6147 (setq rmail-enable-mime-composing t)
6148 (setq rmail-insert-mime-forwarded-message-function
6149 'message-forward-rmail-make-body))
6152 (defun message-resend (address)
6153 "Resend the current article to ADDRESS."
6155 (list (message-read-from-minibuffer "Resend message to: ")))
6156 (message "Resending message to %s..." address)
6158 (let ((cur (current-buffer))
6160 ;; We first set up a normal mail buffer.
6161 (unless (message-mail-user-agent)
6162 (set-buffer (get-buffer-create " *message resend*"))
6164 (let ((message-this-is-mail t)
6166 (message-setup `((To . ,address))))
6167 ;; Insert our usual headers.
6168 (message-generate-headers '(From Date To Message-ID))
6169 (message-narrow-to-headers)
6170 ;; Remove X-Draft-From header etc.
6171 (message-remove-header message-ignored-mail-headers t)
6172 ;; Rename them all to "Resent-*".
6173 (goto-char (point-min))
6174 (while (re-search-forward "^[A-Za-z]" nil t)
6179 (delete-region (point) (point-max))
6181 ;; Insert the message to be resent.
6182 (insert-buffer-substring cur)
6183 (goto-char (point-min))
6184 (search-forward "\n\n")
6187 (narrow-to-region beg (point))
6188 (message-remove-header message-ignored-resent-headers t)
6189 (goto-char (point-max)))
6190 (insert mail-header-separator)
6191 ;; Rename all old ("Also-")Resent headers.
6192 (while (re-search-backward "^\\(Also-\\)*Resent-" beg t)
6195 ;; Quote any "From " lines at the beginning.
6197 (when (looking-at "From ")
6198 (replace-match "X-From-Line: "))
6200 (let ((message-inhibit-body-encoding t)
6201 message-required-mail-headers)
6202 (message-send-mail))
6203 (kill-buffer (current-buffer)))
6204 (message "Resending message to %s...done" address)))
6207 (defun message-bounce ()
6208 "Re-mail the current message.
6209 This only makes sense if the current message is a bounce message that
6210 contains some mail you have written which has been bounced back to
6213 (let ((handles (mm-dissect-buffer t))
6215 (message-pop-to-buffer (message-buffer-name "bounce"))
6216 (if (stringp (car handles))
6217 ;; This is a MIME bounce.
6218 (mm-insert-part (car (last handles)))
6219 ;; This is a non-MIME bounce, so we try to remove things
6221 (mm-insert-part handles)
6223 (goto-char (point-min))
6224 (re-search-forward "\n\n+" nil t)
6225 (setq boundary (point))
6226 ;; We remove everything before the bounced mail.
6227 (if (or (re-search-forward message-unsent-separator nil t)
6229 (search-forward "\n\n" nil 'move)
6230 (re-search-backward "^Return-Path:.*\n" boundary t)))
6233 (delete-region (point-min)
6234 (if (re-search-forward "^[^ \n\t]+:" nil t)
6237 (goto-char boundary)
6238 (when (re-search-backward "^.?From .*\n" nil t)
6239 (delete-region (match-beginning 0) (match-end 0)))))
6240 (mm-enable-multibyte)
6242 (message-narrow-to-head-1)
6243 (message-remove-header message-ignored-bounced-headers t)
6244 (goto-char (point-max))
6245 (insert mail-header-separator))
6246 (message-position-point)))
6249 ;;; Interactive entry points for new message buffers.
6253 (defun message-mail-other-window (&optional to subject)
6254 "Like `message-mail' command, but display mail buffer in another window."
6256 (unless (message-mail-user-agent)
6257 (let ((pop-up-windows t)
6258 (special-display-buffer-names nil)
6259 (special-display-regexps nil)
6260 (same-window-buffer-names nil)
6261 (same-window-regexps nil))
6262 (message-pop-to-buffer (message-buffer-name "mail" to))))
6263 (let ((message-this-is-mail t))
6264 (message-setup `((To . ,(or to "")) (Subject . ,(or subject "")))
6265 nil nil 'switch-to-buffer-other-window)))
6268 (defun message-mail-other-frame (&optional to subject)
6269 "Like `message-mail' command, but display mail buffer in another frame."
6271 (unless (message-mail-user-agent)
6272 (let ((pop-up-frames t)
6273 (special-display-buffer-names nil)
6274 (special-display-regexps nil)
6275 (same-window-buffer-names nil)
6276 (same-window-regexps nil))
6277 (message-pop-to-buffer (message-buffer-name "mail" to))))
6278 (let ((message-this-is-mail t))
6279 (message-setup `((To . ,(or to "")) (Subject . ,(or subject "")))
6280 nil nil 'switch-to-buffer-other-frame)))
6283 (defun message-news-other-window (&optional newsgroups subject)
6284 "Start editing a news article to be sent."
6286 (let ((pop-up-windows t)
6287 (special-display-buffer-names nil)
6288 (special-display-regexps nil)
6289 (same-window-buffer-names nil)
6290 (same-window-regexps nil))
6291 (message-pop-to-buffer (message-buffer-name "posting" nil newsgroups)))
6292 (let ((message-this-is-news t))
6293 (message-setup `((Newsgroups . ,(or newsgroups ""))
6294 (Subject . ,(or subject ""))))))
6297 (defun message-news-other-frame (&optional newsgroups subject)
6298 "Start editing a news article to be sent."
6300 (let ((pop-up-frames t)
6301 (special-display-buffer-names nil)
6302 (special-display-regexps nil)
6303 (same-window-buffer-names nil)
6304 (same-window-regexps nil))
6305 (message-pop-to-buffer (message-buffer-name "posting" nil newsgroups)))
6306 (let ((message-this-is-news t))
6307 (message-setup `((Newsgroups . ,(or newsgroups ""))
6308 (Subject . ,(or subject ""))))))
6312 ;; This code should be moved to underline.el (from which it is stolen).
6315 (defun bold-region (start end)
6316 "Bold all nonblank characters in the region.
6317 Works by overstriking characters.
6318 Called from program, takes two arguments START and END
6319 which specify the range to operate on."
6322 (let ((end1 (make-marker)))
6323 (move-marker end1 (max start end))
6324 (goto-char (min start end))
6325 (while (< (point) end1)
6326 (or (looking-at "[_\^@- ]")
6327 (insert (char-after) "\b"))
6328 (forward-char 1)))))
6331 (defun unbold-region (start end)
6332 "Remove all boldness (overstruck characters) in the region.
6333 Called from program, takes two arguments START and END
6334 which specify the range to operate on."
6337 (let ((end1 (make-marker)))
6338 (move-marker end1 (max start end))
6339 (goto-char (min start end))
6340 (while (re-search-forward "\b" end1 t)
6341 (if (eq (char-after) (char-after (- (point) 2)))
6342 (delete-char -2))))))
6344 (defalias 'message-exchange-point-and-mark 'exchange-point-and-mark)
6345 (defalias 'message-make-overlay 'make-overlay)
6346 (defalias 'message-delete-overlay 'delete-overlay)
6347 (defalias 'message-overlay-put 'overlay-put)
6348 (defun message-kill-all-overlays ()
6349 (if (featurep 'xemacs)
6350 (map-extents (lambda (extent ignore) (delete-extent extent)))
6351 (mapcar #'delete-overlay (overlays-in (point-min) (point-max)))))
6353 ;; Support for toolbar
6355 (defvar tool-bar-map)
6356 (defvar tool-bar-mode))
6358 (defun message-tool-bar-local-item-from-menu (command icon in-map &optional from-map &rest props)
6359 ;; We need to make tool bar entries in local keymaps with
6360 ;; `tool-bar-local-item-from-menu' in Emacs > 21.3
6361 (if (fboundp 'tool-bar-local-item-from-menu)
6362 ;; This is for Emacs 21.3
6363 (tool-bar-local-item-from-menu command icon in-map from-map props)
6364 (tool-bar-add-item-from-menu command icon from-map props)))
6366 (defun message-tool-bar-map ()
6367 (or message-tool-bar-map
6368 (setq message-tool-bar-map
6370 (condition-case nil (require 'tool-bar) (error nil))
6371 (fboundp 'tool-bar-add-item-from-menu)
6373 (let ((tool-bar-map (copy-keymap tool-bar-map))
6374 (load-path (mm-image-load-path)))
6375 ;; Zap some items which aren't so relevant and take
6377 (dolist (key '(print-buffer kill-buffer save-buffer
6378 write-file dired open-file))
6379 (define-key tool-bar-map (vector key) nil))
6380 (message-tool-bar-local-item-from-menu
6381 'message-send-and-exit "mail_send" tool-bar-map message-mode-map)
6382 (message-tool-bar-local-item-from-menu
6383 'message-kill-buffer "close" tool-bar-map message-mode-map)
6384 (message-tool-bar-local-item-from-menu
6385 'message-dont-send "cancel" tool-bar-map message-mode-map)
6386 (message-tool-bar-local-item-from-menu
6387 'mml-attach-file "attach" tool-bar-map mml-mode-map)
6388 (message-tool-bar-local-item-from-menu
6389 'ispell-message "spell" tool-bar-map message-mode-map)
6390 (message-tool-bar-local-item-from-menu
6391 'mml-preview "preview"
6392 tool-bar-map mml-mode-map)
6393 (message-tool-bar-local-item-from-menu
6394 'message-insert-importance-high "important"
6395 tool-bar-map message-mode-map)
6396 (message-tool-bar-local-item-from-menu
6397 'message-insert-importance-low "unimportant"
6398 tool-bar-map message-mode-map)
6399 (message-tool-bar-local-item-from-menu
6400 'message-insert-disposition-notification-to "receipt"
6401 tool-bar-map message-mode-map)
6404 ;;; Group name completion.
6406 (defcustom message-newgroups-header-regexp
6407 "^\\(Newsgroups\\|Followup-To\\|Posted-To\\|Gcc\\):"
6408 "Regexp that match headers that lists groups."
6412 (defcustom message-completion-alist
6413 (list (cons message-newgroups-header-regexp 'message-expand-group)
6414 '("^\\(Resent-\\)?\\(To\\|B?Cc\\):" . message-expand-name)
6415 '("^\\(Reply-To\\|From\\|Mail-Followup-To\\|Mail-Copies-To\\):"
6416 . message-expand-name)
6417 '("^\\(Disposition-Notification-To\\|Return-Receipt-To\\):"
6418 . message-expand-name))
6419 "Alist of (RE . FUN). Use FUN for completion on header lines matching RE."
6421 :type '(alist :key-type regexp :value-type function))
6423 (defcustom message-tab-body-function nil
6424 "*Function to execute when `message-tab' (TAB) is executed in the body.
6425 If nil, the function bound in `text-mode-map' or `global-map' is executed."
6429 (defun message-tab ()
6430 "Complete names according to `message-completion-alist'.
6431 Execute function specified by `message-tab-body-function' when not in
6434 (let ((alist message-completion-alist))
6436 (let ((mail-abbrev-mode-regexp (caar alist)))
6437 (not (mail-abbrev-in-expansion-header-p))))
6438 (setq alist (cdr alist)))
6439 (funcall (or (cdar alist) message-tab-body-function
6440 (lookup-key text-mode-map "\t")
6441 (lookup-key global-map "\t")
6442 'indent-relative))))
6444 (defun message-expand-group ()
6445 "Expand the group name under point."
6446 (let* ((b (save-excursion
6451 (skip-chars-forward "^:")
6454 (skip-chars-backward "^, \t\n") (point))))
6455 (completion-ignore-case t)
6456 (string (buffer-substring b (progn (skip-chars-forward "^,\t\n ")
6458 (hashtb (and (boundp 'gnus-active-hashtb) gnus-active-hashtb))
6459 (completions (all-completions string hashtb))
6461 (delete-region b (point))
6463 ((= (length completions) 1)
6464 (if (string= (car completions) string)
6467 (message "Only matching group"))
6468 (insert (car completions))))
6469 ((and (setq comp (try-completion string hashtb))
6470 (not (string= comp string)))
6475 (message "No matching groups")
6476 (save-selected-window
6477 (pop-to-buffer "*Completions*")
6478 (buffer-disable-undo)
6479 (let ((buffer-read-only nil))
6481 (let ((standard-output (current-buffer)))
6482 (display-completion-list (sort completions 'string<)))
6483 (goto-char (point-min))
6484 (delete-region (point) (progn (forward-line 3) (point))))))))))
6486 (defun message-expand-name ()
6487 (if (fboundp 'bbdb-complete-name)
6488 (bbdb-complete-name)
6493 (defun message-talkative-question (ask question show &rest text)
6494 "Call FUNCTION with argument QUESTION; optionally display TEXT... args.
6495 If SHOW is non-nil, the arguments TEXT... are displayed in a temp buffer.
6496 The following arguments may contain lists of values."
6498 (setq text (message-flatten-list text)))
6499 (save-window-excursion
6501 (with-output-to-temp-buffer " *MESSAGE information message*"
6502 (set-buffer " *MESSAGE information message*")
6503 (fundamental-mode) ; for Emacs 20.4+
6504 (mapcar 'princ text)
6505 (goto-char (point-min))))
6506 (funcall ask question))
6507 (funcall ask question)))
6509 (defun message-flatten-list (list)
6510 "Return a new, flat list that contains all elements of LIST.
6512 \(message-flatten-list '(1 (2 3 (4 5 (6))) 7))
6515 (apply 'append (mapcar 'message-flatten-list list)))
6519 (defun message-generate-new-buffer-clone-locals (name &optional varstr)
6520 "Create and return a buffer with name based on NAME using `generate-new-buffer'.
6521 Then clone the local variables and values from the old buffer to the
6522 new one, cloning only the locals having a substring matching the
6524 (let ((oldbuf (current-buffer)))
6526 (set-buffer (generate-new-buffer name))
6527 (message-clone-locals oldbuf varstr)
6530 (defun message-clone-locals (buffer &optional varstr)
6531 "Clone the local variables from BUFFER to the current buffer."
6532 (let ((locals (save-excursion
6534 (buffer-local-variables)))
6535 (regexp "^gnus\\|^nn\\|^message\\|^user-mail-address"))
6538 (when (and (consp local)
6540 (string-match regexp (symbol-name (car local)))
6542 (string-match varstr (symbol-name (car local)))))
6544 (set (make-local-variable (car local))
6552 (defvar message-inhibit-body-encoding nil)
6554 (defun message-encode-message-body ()
6555 (unless message-inhibit-body-encoding
6556 (let ((mail-parse-charset (or mail-parse-charset
6557 message-default-charset))
6558 (case-fold-search t)
6559 lines content-type-p)
6562 (narrow-to-region (point) (point-max))
6563 (let ((new (mml-generate-mime)))
6565 (delete-region (point-min) (point-max))
6567 (goto-char (point-min))
6568 (if (eq (aref new 0) ?\n)
6570 (search-forward "\n\n")
6571 (setq lines (buffer-substring (point-min) (1- (point))))
6572 (delete-region (point-min) (point))))))
6574 (message-narrow-to-headers-or-head)
6575 (message-remove-header "Mime-Version")
6576 (goto-char (point-max))
6577 (insert "MIME-Version: 1.0\n")
6580 (setq content-type-p
6582 (re-search-backward "^Content-Type:" nil t))))
6584 (message-narrow-to-headers-or-head)
6585 (message-remove-first-header "Content-Type")
6586 (message-remove-first-header "Content-Transfer-Encoding"))
6587 ;; We always make sure that the message has a Content-Type
6588 ;; header. This is because some broken MTAs and MUAs get
6589 ;; awfully confused when confronted with a message with a
6590 ;; MIME-Version header and without a Content-Type header. For
6591 ;; instance, Solaris' /usr/bin/mail.
6592 (unless content-type-p
6593 (goto-char (point-min))
6594 ;; For unknown reason, MIME-Version doesn't exist.
6595 (when (re-search-forward "^MIME-Version:" nil t)
6597 (insert "Content-Type: text/plain; charset=us-ascii\n"))))))
6599 (defun message-read-from-minibuffer (prompt &optional initial-contents)
6600 "Read from the minibuffer while providing abbrev expansion."
6601 (if (fboundp 'mail-abbrevs-setup)
6602 (let ((mail-abbrev-mode-regexp "")
6603 (minibuffer-setup-hook 'mail-abbrevs-setup)
6604 (minibuffer-local-map message-minibuffer-local-map))
6605 (read-from-minibuffer prompt initial-contents))
6606 (let ((minibuffer-setup-hook 'mail-abbrev-minibuffer-setup-hook)
6607 (minibuffer-local-map message-minibuffer-local-map))
6608 (read-string prompt initial-contents))))
6610 (defun message-use-alternative-email-as-from ()
6611 (require 'mail-utils)
6612 (let* ((fields '("To" "Cc"))
6615 (mail-strip-quoted-names
6616 (mapconcat 'message-fetch-reply-field fields ","))
6620 (if (string-match message-alternative-emails (car emails))
6621 (setq email (car emails)
6624 (unless (or (not email) (equal email user-mail-address))
6625 (goto-char (point-max))
6626 (insert "From: " email "\n"))))
6628 (defun message-options-get (symbol)
6629 (cdr (assq symbol message-options)))
6631 (defun message-options-set (symbol value)
6632 (let ((the-cons (assq symbol message-options)))
6635 (setcdr the-cons value)
6636 (setq message-options (delq the-cons message-options)))
6638 (push (cons symbol value) message-options))))
6641 (defun message-options-set-recipient ()
6643 (message-narrow-to-headers-or-head)
6644 (message-options-set 'message-sender
6645 (mail-strip-quoted-names
6646 (message-fetch-field "from")))
6647 (message-options-set 'message-recipients
6648 (mail-strip-quoted-names
6649 (let ((to (message-fetch-field "to"))
6650 (cc (message-fetch-field "cc"))
6651 (bcc (message-fetch-field "bcc")))
6654 (if (and to cc) ", ")
6656 (if (and (or to cc) bcc) ", ")
6659 (defun message-hide-headers ()
6660 "Hide headers based on the `message-hidden-headers' variable."
6661 (let ((regexps (if (stringp message-hidden-headers)
6662 (list message-hidden-headers)
6663 message-hidden-headers))
6664 (inhibit-point-motion-hooks t)
6665 (after-change-functions nil))
6669 (message-narrow-to-headers)
6670 (goto-char (point-min))
6672 (if (not (message-hide-header-p regexps))
6673 (message-next-header)
6674 (let ((begin (point)))
6675 (message-next-header)
6676 (add-text-properties
6678 '(invisible t message-hidden t))))))))))
6680 (defun message-hide-header-p (regexps)
6683 (when (eq (car regexps) 'not)
6686 (dolist (regexp regexps)
6687 (setq result (or result (looking-at regexp))))
6692 (when (featurep 'xemacs)
6693 (require 'messagexmas)
6694 (message-xmas-redefine))
6698 (run-hooks 'message-load-hook)
6701 ;; coding: iso-8859-1
6704 ;;; message.el ends here