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-list-identifiers)) ; gnus-sum is required where necessary
39 ;; This is apparently necessary even though things are autoloaded.
40 ;; Because we dynamically bind mail-abbrev-mode-regexp, we'd better
41 ;; require mailabbrev here.
42 (if (featurep 'xemacs)
43 (require 'mail-abbrevs)
44 (require 'mailabbrev))
49 (autoload 'sha1 "sha1-el"))
51 (defgroup message '((user-mail-address custom-variable)
52 (user-full-name custom-variable))
53 "Mail and news message composing."
54 :link '(custom-manual "(message)Top")
58 (put 'user-mail-address 'custom-type 'string)
59 (put 'user-full-name 'custom-type 'string)
61 (defgroup message-various nil
62 "Various Message Variables"
63 :link '(custom-manual "(message)Various Message Variables")
66 (defgroup message-buffers nil
68 :link '(custom-manual "(message)Message Buffers")
71 (defgroup message-sending nil
73 :link '(custom-manual "(message)Sending Variables")
76 (defgroup message-interface nil
78 :link '(custom-manual "(message)Interface")
81 (defgroup message-forwarding nil
83 :link '(custom-manual "(message)Forwarding")
84 :group 'message-interface)
86 (defgroup message-insertion nil
88 :link '(custom-manual "(message)Insertion")
91 (defgroup message-headers nil
93 :link '(custom-manual "(message)Message Headers")
96 (defgroup message-news nil
97 "Composing News Messages"
100 (defgroup message-mail nil
101 "Composing Mail Messages"
104 (defgroup message-faces nil
105 "Faces used for message composing."
109 (defcustom message-directory "~/Mail/"
110 "*Directory from which all other mail file variables are derived."
111 :group 'message-various
114 (defcustom message-max-buffers 10
115 "*How many buffers to keep before starting to kill them off."
116 :group 'message-buffers
119 (defcustom message-send-rename-function nil
120 "Function called to rename the buffer after sending it."
121 :group 'message-buffers
122 :type '(choice function (const nil)))
124 (defcustom message-fcc-handler-function 'message-output
125 "*A function called to save outgoing articles.
126 This function will be called with the name of the file to store the
127 article in. The default function is `message-output' which saves in Unix
129 :type '(radio (function-item message-output)
130 (function :tag "Other"))
131 :group 'message-sending)
133 (defcustom message-fcc-externalize-attachments nil
134 "If non-nil, attachments are included as external parts in Fcc copies."
136 :group 'message-sending)
138 (defcustom message-courtesy-message
139 "The following message is a courtesy copy of an article\nthat has been posted to %s as well.\n\n"
140 "*This is inserted at the start of a mailed copy of a posted message.
141 If the string contains the format spec \"%s\", the Newsgroups
142 the article has been posted to will be inserted there.
143 If this variable is nil, no such courtesy message will be added."
144 :group 'message-sending
147 (defcustom message-ignored-bounced-headers "^\\(Received\\|Return-Path\\):"
148 "*Regexp that matches headers to be removed in resent bounced mail."
149 :group 'message-interface
153 (defcustom message-from-style 'default
154 "*Specifies how \"From\" headers look.
156 If nil, they contain just the return address like:
158 If `parens', they look like:
159 king@grassland.com (Elvis Parsley)
160 If `angles', they look like:
161 Elvis Parsley <king@grassland.com>
163 Otherwise, most addresses look like `angles', but they look like
164 `parens' if `angles' would need quoting and `parens' would not."
165 :type '(choice (const :tag "simple" nil)
169 :group 'message-headers)
171 (defcustom message-insert-canlock t
172 "Whether to insert a Cancel-Lock header in news postings."
174 :group 'message-headers
177 (defcustom message-syntax-checks
178 (if message-insert-canlock '((sender . disabled)) nil)
179 ;; Guess this one shouldn't be easy to customize...
180 "*Controls what syntax checks should not be performed on outgoing posts.
181 To disable checking of long signatures, for instance, add
182 `(signature . disabled)' to this list.
184 Don't touch this variable unless you really know what you're doing.
186 Checks include `subject-cmsg', `multiple-headers', `sendsys',
187 `message-id', `from', `long-lines', `control-chars', `size',
188 `new-text', `quoting-style', `redirected-followup', `signature',
189 `approved', `sender', `empty', `empty-headers', `message-id', `from',
190 `subject', `shorten-followup-to', `existing-newsgroups',
191 `buffer-file-name', `unchanged', `newsgroups', `reply-to',
192 'continuation-headers', and `long-header-lines'."
194 :type '(repeat sexp)) ; Fixme: improve this
196 (defcustom message-required-headers '((optional . References) From)
197 "*Headers to be generated or prompted for when sending a message.
198 Also see `message-required-news-headers' and
199 `message-required-mail-headers'."
201 :group 'message-headers
202 :type '(repeat sexp))
204 (defcustom message-draft-headers '(References From)
205 "*Headers to be generated when saving a draft message."
207 :group 'message-headers
208 :type '(repeat sexp))
210 (defcustom message-required-news-headers
211 '(From Newsgroups Subject Date Message-ID
212 (optional . Organization)
213 (optional . User-Agent))
214 "*Headers to be generated or prompted for when posting an article.
215 RFC977 and RFC1036 require From, Date, Newsgroups, Subject,
216 Message-ID. Organization, Lines, In-Reply-To, Expires, and
217 User-Agent are optional. If don't you want message to insert some
218 header, remove it from this list."
220 :group 'message-headers
221 :type '(repeat sexp))
223 (defcustom message-required-mail-headers
224 '(From Subject Date (optional . In-Reply-To) Message-ID
225 (optional . User-Agent))
226 "*Headers to be generated or prompted for when mailing a message.
227 It is recommended that From, Date, To, Subject and Message-ID be
228 included. Organization and User-Agent are optional."
230 :group 'message-headers
231 :type '(repeat sexp))
233 (defcustom message-deletable-headers '(Message-ID Date Lines)
234 "Headers to be deleted if they already exist and were generated by message previously."
235 :group 'message-headers
238 (defcustom message-ignored-news-headers
239 "^NNTP-Posting-Host:\\|^Xref:\\|^[BGF]cc:\\|^Resent-Fcc:\\|^X-Draft-From:\\|^X-Gnus-Agent-Meta-Information:"
240 "*Regexp of headers to be removed unconditionally before posting."
242 :group 'message-headers
245 (defcustom message-ignored-mail-headers
246 "^[GF]cc:\\|^Resent-Fcc:\\|^Xref:\\|^X-Draft-From:\\|^X-Gnus-Agent-Meta-Information:"
247 "*Regexp of headers to be removed unconditionally before mailing."
249 :group 'message-headers
252 (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:"
253 "*Header lines matching this regexp will be deleted before posting.
254 It's best to delete old Path and Date headers before posting to avoid
256 :group 'message-interface
259 (defcustom message-subject-re-regexp
260 "^[ \t]*\\([Rr][Ee]\\(\\[[0-9]*\\]\\)*:[ \t]*\\)*[ \t]*"
261 "*Regexp matching \"Re: \" in the subject line."
262 :group 'message-various
265 ;;; Start of variables adopted from `message-utils.el'.
267 (defcustom message-subject-trailing-was-query 'ask
268 ;; should it default to nil or ask?
269 "*What to do with trailing \"(was: <old subject>)\" in subject lines.
270 If nil, leave the subject unchanged. If it is the symbol `ask', query
271 the user what do do. In this case, the subject is matched against
272 `message-subject-trailing-was-ask-regexp'. If
273 `message-subject-trailing-was-query' is t, always strip the trailing
274 old subject. In this case, `message-subject-trailing-was-regexp' is
276 :type '(choice (const :tag "never" nil)
277 (const :tag "always strip" t)
279 :group 'message-various)
281 (defcustom message-subject-trailing-was-ask-regexp
282 "[ \t]*\\([[(]+[Ww][Aa][Ss][ \t]*.*[\])]+\\)"
283 "*Regexp matching \"(was: <old subject>)\" in the subject line.
285 The function `message-strip-subject-trailing-was' uses this regexp if
286 `message-subject-trailing-was-query' is set to the symbol `ask'. If
287 the variable is t instead of `ask', use
288 `message-subject-trailing-was-regexp' instead.
290 It is okay to create some false positives here, as the user is asked."
291 :group 'message-various
294 (defcustom message-subject-trailing-was-regexp
295 "[ \t]*\\((*[Ww][Aa][Ss]:[ \t]*.*)\\)"
296 "*Regexp matching \"(was: <old subject>)\" in the subject line.
298 If `message-subject-trailing-was-query' is set to t, the subject is
299 matched against `message-subject-trailing-was-regexp' in
300 `message-strip-subject-trailing-was'. You should use a regexp creating very
301 few false positives here."
302 :group 'message-various
305 ;;; marking inserted text
308 (defcustom message-mark-insert-begin
309 "--8<---------------cut here---------------start------------->8---\n"
310 "How to mark the beginning of some inserted text."
312 :group 'message-various)
315 (defcustom message-mark-insert-end
316 "--8<---------------cut here---------------end--------------->8---\n"
317 "How to mark the end of some inserted text."
319 :group 'message-various)
322 (defcustom message-archive-header
323 "X-No-Archive: Yes\n"
324 "Header to insert when you don't want your article to be archived.
325 Archives \(such as groups.googgle.com\) respect this header."
327 :group 'message-various)
330 (defcustom message-archive-note
331 "X-No-Archive: Yes - save http://groups.google.com/"
332 "Note to insert why you wouldn't want this posting archived.
333 If nil, don't insert any text in the body."
335 :group 'message-various)
337 ;;; Crossposts and Followups
338 ;; inspired by JoH-followup-to by Jochem Huhman <joh at gmx.de>
339 ;; new suggestions by R. Weikusat <rw at another.de>
341 (defvar message-cross-post-old-target nil
342 "Old target for cross-posts or follow-ups.")
343 (make-variable-buffer-local 'message-cross-post-old-target)
346 (defcustom message-cross-post-default t
347 "When non-nil `message-cross-post-followup-to' will perform a crosspost.
348 If nil, `message-cross-post-followup-to' will only do a followup. Note that
349 you can explicitly override this setting by calling
350 `message-cross-post-followup-to' with a prefix."
352 :group 'message-various)
355 (defcustom message-cross-post-note
356 "Crosspost & Followup-To: "
357 "Note to insert before signature to notify of cross-post and follow-up."
359 :group 'message-various)
362 (defcustom message-followup-to-note
364 "Note to insert before signature to notify of follow-up only."
366 :group 'message-various)
369 (defcustom message-cross-post-note-function
370 'message-cross-post-insert-note
371 "Function to use to insert note about Crosspost or Followup-To.
372 The function will be called with four arguments. The function should not only
373 insert a note, but also ensure old notes are deleted. See the documentation
374 for `message-cross-post-insert-note'."
376 :group 'message-various)
378 ;;; End of variables adopted from `message-utils.el'.
381 (defcustom message-signature-separator "^-- *$"
382 "Regexp matching the signature separator."
384 :group 'message-various)
386 (defcustom message-elide-ellipsis "\n[...]\n\n"
387 "*The string which is inserted for elided text."
389 :group 'message-various)
391 (defcustom message-interactive t
392 "Non-nil means when sending a message wait for and display errors.
393 nil means let mailer mail back a message to report errors."
394 :group 'message-sending
398 (defcustom message-generate-new-buffers 'unique
399 "*Non-nil means create a new message buffer whenever `message-setup' is called.
400 If this is a function, call that function with three parameters: The type,
401 the to address and the group name. (Any of these may be nil.) The function
402 should return the new buffer name."
403 :group 'message-buffers
404 :type '(choice (const :tag "off" nil)
405 (const :tag "unique" unique)
406 (const :tag "unsent" unsent)
409 (defcustom message-kill-buffer-on-exit nil
410 "*Non-nil means that the message buffer will be killed after sending a message."
411 :group 'message-buffers
415 (defvar gnus-local-organization))
416 (defcustom message-user-organization
417 (or (and (boundp 'gnus-local-organization)
418 (stringp gnus-local-organization)
419 gnus-local-organization)
420 (getenv "ORGANIZATION")
422 "*String to be used as an Organization header.
423 If t, use `message-user-organization-file'."
424 :group 'message-headers
425 :type '(choice string
426 (const :tag "consult file" t)))
429 (defcustom message-user-organization-file "/usr/lib/news/organization"
430 "*Local news organization file."
432 :group 'message-headers)
434 (defcustom message-make-forward-subject-function
435 'message-forward-subject-author-subject
436 "*List of functions called to generate subject headers for forwarded messages.
437 The subject generated by the previous function is passed into each
440 The provided functions are:
442 * `message-forward-subject-author-subject' (Source of article (author or
443 newsgroup)), in brackets followed by the subject
444 * `message-forward-subject-fwd' (Subject of article with 'Fwd:' prepended
446 :group 'message-forwarding
447 :type '(radio (function-item message-forward-subject-author-subject)
448 (function-item message-forward-subject-fwd)
449 (repeat :tag "List of functions" function)))
451 (defcustom message-forward-as-mime t
452 "*If non-nil, forward messages as an inline/rfc822 MIME section. Otherwise, directly inline the old message in the forwarded message."
454 :group 'message-forwarding
457 (defcustom message-forward-show-mml t
458 "*If non-nil, forward messages are shown as mml. Otherwise, forward messages are unchanged."
460 :group 'message-forwarding
463 (defcustom message-forward-before-signature t
464 "*If non-nil, put forwarded message before signature, else after."
465 :group 'message-forwarding
468 (defcustom message-wash-forwarded-subjects nil
469 "*If non-nil, try to remove as much old cruft as possible from the subject of messages before generating the new subject of a forward."
470 :group 'message-forwarding
473 (defcustom message-ignored-resent-headers "^Return-receipt\\|^X-Gnus\\|^Gnus-Warning:\\|^>?From "
474 "*All headers that match this regexp will be deleted when resending a message."
475 :group 'message-interface
478 (defcustom message-forward-ignored-headers "^Content-Transfer-Encoding:\\|^X-Gnus"
479 "*All headers that match this regexp will be deleted when forwarding a message."
481 :group 'message-forwarding
482 :type '(choice (const :tag "None" nil)
485 (defcustom message-ignored-cited-headers "."
486 "*Delete these headers from the messages you yank."
487 :group 'message-insertion
490 (defcustom message-cite-prefix-regexp
491 (if (string-match "[[:digit:]]" "1") ;; support POSIX?
492 "\\([ \t]*[-_.[:word:]]+>+\\|[ \t]*[]>|}+]\\)+"
493 ;; ?-, ?_ or ?. MUST NOT be in syntax entry w.
494 (let ((old-table (syntax-table))
495 non-word-constituents)
496 (set-syntax-table text-mode-syntax-table)
497 (setq non-word-constituents
499 (if (string-match "\\w" "-") "" "-")
500 (if (string-match "\\w" "_") "" "_")
501 (if (string-match "\\w" ".") "" ".")))
502 (set-syntax-table old-table)
503 (if (equal non-word-constituents "")
504 "\\([ \t]*\\(\\w\\)+>+\\|[ \t]*[]>|}+]\\)+"
505 (concat "\\([ \t]*\\(\\w\\|["
506 non-word-constituents
507 "]\\)+>+\\|[ \t]*[]>|}+]\\)+"))))
508 "*Regexp matching the longest possible citation prefix on a line."
509 :group 'message-insertion
512 (defcustom message-cancel-message "I am canceling my own article.\n"
513 "Message to be inserted in the cancel message."
514 :group 'message-interface
517 ;; Useful to set in site-init.el
519 (defcustom message-send-mail-function 'message-send-mail-with-sendmail
520 "Function to call to send the current buffer as mail.
521 The headers should be delimited by a line whose contents match the
522 variable `mail-header-separator'.
524 Valid values include `message-send-mail-with-sendmail' (the default),
525 `message-send-mail-with-mh', `message-send-mail-with-qmail',
526 `message-smtpmail-send-it', `smtpmail-send-it' and `feedmail-send-it'.
528 See also `send-mail-function'."
529 :type '(radio (function-item message-send-mail-with-sendmail)
530 (function-item message-send-mail-with-mh)
531 (function-item message-send-mail-with-qmail)
532 (function-item message-smtpmail-send-it)
533 (function-item smtpmail-send-it)
534 (function-item feedmail-send-it)
535 (function :tag "Other"))
536 :group 'message-sending
537 :group 'message-mail)
539 (defcustom message-send-news-function 'message-send-news
540 "Function to call to send the current buffer as news.
541 The headers should be delimited by a line whose contents match the
542 variable `mail-header-separator'."
543 :group 'message-sending
547 (defcustom message-reply-to-function nil
548 "If non-nil, function that should return a list of headers.
549 This function should pick out addresses from the To, Cc, and From headers
550 and respond with new To and Cc headers."
551 :group 'message-interface
552 :type '(choice function (const nil)))
554 (defcustom message-wide-reply-to-function nil
555 "If non-nil, function that should return a list of headers.
556 This function should pick out addresses from the To, Cc, and From headers
557 and respond with new To and Cc headers."
558 :group 'message-interface
559 :type '(choice function (const nil)))
561 (defcustom message-followup-to-function nil
562 "If non-nil, function that should return a list of headers.
563 This function should pick out addresses from the To, Cc, and From headers
564 and respond with new To and Cc headers."
565 :group 'message-interface
566 :type '(choice function (const nil)))
568 (defcustom message-use-followup-to 'ask
569 "*Specifies what to do with Followup-To header.
570 If nil, always ignore the header. If it is t, use its value, but
571 query before using the \"poster\" value. If it is the symbol `ask',
572 always query the user whether to use the value. If it is the symbol
573 `use', always use the value."
574 :group 'message-interface
575 :type '(choice (const :tag "ignore" nil)
576 (const :tag "use & query" t)
580 (defcustom message-use-mail-followup-to 'use
581 "*Specifies what to do with Mail-Followup-To header.
582 If nil, always ignore the header. If it is the symbol `ask', always
583 query the user whether to use the value. If it is the symbol `use',
584 always use the value."
585 :group 'message-interface
586 :type '(choice (const :tag "ignore" nil)
590 (defcustom message-subscribed-address-functions nil
591 "*Specifies functions for determining list subscription.
592 If nil, do not attempt to determine list subscribtion with functions.
593 If non-nil, this variable contains a list of functions which return
594 regular expressions to match lists. These functions can be used in
595 conjunction with `message-subscribed-regexps' and
596 `message-subscribed-addresses'."
597 :group 'message-interface
598 :type '(repeat sexp))
600 (defcustom message-subscribed-address-file nil
601 "*A file containing addresses the user is subscribed to.
602 If nil, do not look at any files to determine list subscriptions. If
603 non-nil, each line of this file should be a mailing list address."
604 :group 'message-interface
607 (defcustom message-subscribed-addresses nil
608 "*Specifies a list of addresses the user is subscribed to.
609 If nil, do not use any predefined list subscriptions. This list of
610 addresses can be used in conjuction with
611 `message-subscribed-address-functions' and `message-subscribed-regexps'."
612 :group 'message-interface
613 :type '(repeat string))
615 (defcustom message-subscribed-regexps nil
616 "*Specifies a list of addresses the user is subscribed to.
617 If nil, do not use any predefined list subscriptions. This list of
618 regular expressions can be used in conjuction with
619 `message-subscribed-address-functions' and `message-subscribed-addresses'."
620 :group 'message-interface
621 :type '(repeat regexp))
623 (defcustom message-allow-no-recipients 'ask
624 "Specifies what to do when there are no recipients other than Gcc/Fcc.
625 If it is the symbol `always', the posting is allowed. If it is the
626 symbol `never', the posting is not allowed. If it is the symbol
627 `ask', you are prompted."
628 :group 'message-interface
629 :type '(choice (const always)
633 (defcustom message-sendmail-f-is-evil nil
634 "*Non-nil means don't add \"-f username\" to the sendmail command line.
635 Doing so would be even more evil than leaving it out."
636 :group 'message-sending
639 (defcustom message-sendmail-envelope-from nil
640 "*Envelope-from when sending mail with sendmail.
641 If this is nil, use `user-mail-address'. If it is the symbol
642 `header', use the From: header of the message."
643 :type '(choice (string :tag "From name")
644 (const :tag "Use From: header from message" header)
645 (const :tag "Use `user-mail-address'" nil))
646 :group 'message-sending)
648 ;; qmail-related stuff
649 (defcustom message-qmail-inject-program "/var/qmail/bin/qmail-inject"
650 "Location of the qmail-inject program."
651 :group 'message-sending
654 (defcustom message-qmail-inject-args nil
655 "Arguments passed to qmail-inject programs.
656 This should be a list of strings, one string for each argument. It
657 may also be a function.
659 For e.g., if you wish to set the envelope sender address so that bounces
660 go to the right place or to deal with listserv's usage of that address, you
661 might set this variable to '(\"-f\" \"you@some.where\")."
662 :group 'message-sending
663 :type '(choice (function)
666 (defvar message-cater-to-broken-inn t
667 "Non-nil means Gnus should not fold the `References' header.
668 Folding `References' makes ancient versions of INN create incorrect
672 (defvar gnus-post-method)
673 (defvar gnus-select-method))
674 (defcustom message-post-method
675 (cond ((and (boundp 'gnus-post-method)
676 (listp gnus-post-method)
679 ((boundp 'gnus-select-method)
682 "*Method used to post news.
683 Note that when posting from inside Gnus, for instance, this
684 variable isn't used."
686 :group 'message-sending
687 ;; This should be the `gnus-select-method' widget, but that might
688 ;; create a dependence to `gnus.el'.
691 (defcustom message-generate-headers-first nil
692 "*If non-nil, generate all required headers before composing.
693 The variables `message-required-news-headers' and
694 `message-required-mail-headers' specify which headers to generate.
695 This can also be a list of headers that should be generated before
698 Note that the variable `message-deletable-headers' specifies headers which
699 are to be deleted and then re-generated before sending, so this variable
700 will not have a visible effect for those headers."
701 :group 'message-headers
702 :type '(choice (const :tag "None" nil)
704 (repeat (sexp :tag "Header"))))
706 (defcustom message-setup-hook nil
707 "Normal hook, run each time a new outgoing message is initialized.
708 The function `message-setup' runs this hook."
709 :group 'message-various
712 (defcustom message-cancel-hook nil
713 "Hook run when cancelling articles."
714 :group 'message-various
717 (defcustom message-signature-setup-hook nil
718 "Normal hook, run each time a new outgoing message is initialized.
719 It is run after the headers have been inserted and before
720 the signature is inserted."
721 :group 'message-various
724 (defcustom message-mode-hook nil
725 "Hook run in message mode buffers."
726 :group 'message-various
729 (defcustom message-header-hook nil
730 "Hook run in a message mode buffer narrowed to the headers."
731 :group 'message-various
734 (defcustom message-header-setup-hook nil
735 "Hook called narrowed to the headers when setting up a message buffer."
736 :group 'message-various
739 (defcustom message-minibuffer-local-map
740 (let ((map (make-sparse-keymap 'message-minibuffer-local-map)))
741 (set-keymap-parent map minibuffer-local-map)
743 "Keymap for `message-read-from-minibuffer'.")
746 (defcustom message-citation-line-function 'message-insert-citation-line
747 "*Function called to insert the \"Whomever writes:\" line.
749 Note that Gnus provides a feature where the reader can click on
750 `writes:' to hide the cited text. If you change this line too much,
751 people who read your message will have to change their Gnus
752 configuration. See the variable `gnus-cite-attribution-suffix'."
754 :group 'message-insertion)
757 (defcustom message-yank-prefix "> "
758 "*Prefix inserted on the lines of yanked messages.
759 Fix `message-cite-prefix-regexp' if it is set to an abnormal value.
760 See also `message-yank-cited-prefix'."
762 :group 'message-insertion)
764 (defcustom message-yank-cited-prefix ">"
765 "*Prefix inserted on cited or empty lines of yanked messages.
766 Fix `message-cite-prefix-regexp' if it is set to an abnormal value.
767 See also `message-yank-prefix'."
769 :group 'message-insertion)
771 (defcustom message-indentation-spaces 3
772 "*Number of spaces to insert at the beginning of each cited line.
773 Used by `message-yank-original' via `message-yank-cite'."
774 :group 'message-insertion
778 (defcustom message-cite-function 'message-cite-original
779 "*Function for citing an original message.
780 Predefined functions include `message-cite-original' and
781 `message-cite-original-without-signature'.
782 Note that `message-cite-original' uses `mail-citation-hook' if that is non-nil."
783 :type '(radio (function-item message-cite-original)
784 (function-item message-cite-original-without-signature)
785 (function-item sc-cite-original)
786 (function :tag "Other"))
787 :group 'message-insertion)
790 (defcustom message-indent-citation-function 'message-indent-citation
791 "*Function for modifying a citation just inserted in the mail buffer.
792 This can also be a list of functions. Each function can find the
793 citation between (point) and (mark t). And each function should leave
794 point and mark around the citation text as modified."
796 :group 'message-insertion)
799 (defcustom message-signature t
800 "*String to be inserted at the end of the message buffer.
801 If t, the `message-signature-file' file will be inserted instead.
802 If a function, the result from the function will be used instead.
803 If a form, the result from the form will be used instead."
805 :group 'message-insertion)
808 (defcustom message-signature-file "~/.signature"
809 "*Name of file containing the text inserted at end of message buffer.
810 Ignored if the named file doesn't exist.
811 If nil, don't insert a signature."
812 :type '(choice file (const :tags "None" nil))
813 :group 'message-insertion)
816 (defcustom message-signature-insert-empty-line t
817 "*If non-nil, insert an empty line before the signature separator."
819 :group 'message-insertion)
821 (defcustom message-distribution-function nil
822 "*Function called to return a Distribution header."
824 :group 'message-headers
825 :type '(choice function (const nil)))
827 (defcustom message-expires 14
828 "Number of days before your article expires."
830 :group 'message-headers
831 :link '(custom-manual "(message)News Headers")
834 (defcustom message-user-path nil
835 "If nil, use the NNTP server name in the Path header.
836 If stringp, use this; if non-nil, use no host name (user name only)."
838 :group 'message-headers
839 :link '(custom-manual "(message)News Headers")
840 :type '(choice (const :tag "nntp" nil)
842 (sexp :tag "none" :format "%t" t)))
844 (defvar message-reply-buffer nil)
845 (defvar message-reply-headers nil
846 "The headers of the current replied article.
847 It is a vector of the following headers:
848 \[number subject from date id references chars lines xref extra].")
849 (defvar message-newsreader nil)
850 (defvar message-mailer nil)
851 (defvar message-sent-message-via nil)
852 (defvar message-checksum nil)
853 (defvar message-send-actions nil
854 "A list of actions to be performed upon successful sending of a message.")
855 (defvar message-exit-actions nil
856 "A list of actions to be performed upon exiting after sending a message.")
857 (defvar message-kill-actions nil
858 "A list of actions to be performed before killing a message buffer.")
859 (defvar message-postpone-actions nil
860 "A list of actions to be performed after postponing a message.")
862 (define-widget 'message-header-lines 'text
863 "All header lines must be LFD terminated."
864 :format "%{%t%}:%n%v"
866 :error "All header lines must be newline terminated")
868 (defcustom message-default-headers ""
869 "*A string containing header lines to be inserted in outgoing messages.
870 It is inserted before you edit the message, so you can edit or delete
872 :group 'message-headers
873 :type 'message-header-lines)
875 (defcustom message-default-mail-headers ""
876 "*A string of header lines to be inserted in outgoing mails."
877 :group 'message-headers
879 :type 'message-header-lines)
881 (defcustom message-default-news-headers ""
882 "*A string of header lines to be inserted in outgoing news articles."
883 :group 'message-headers
885 :type 'message-header-lines)
887 ;; Note: could use /usr/ucb/mail instead of sendmail;
888 ;; options -t, and -v if not interactive.
889 (defcustom message-mailer-swallows-blank-line
890 (if (and (string-match "sparc-sun-sunos\\(\\'\\|[^5]\\)"
891 system-configuration)
892 (file-readable-p "/etc/sendmail.cf")
893 (let ((buffer (get-buffer-create " *temp*")))
897 (insert-file-contents "/etc/sendmail.cf")
898 (goto-char (point-min))
899 (let ((case-fold-search nil))
900 (re-search-forward "^OR\\>" nil t)))
901 (kill-buffer buffer))))
902 ;; According to RFC822, "The field-name must be composed of printable
903 ;; ASCII characters (i. e., characters that have decimal values between
904 ;; 33 and 126, except colon)", i. e., any chars except ctl chars,
906 '(looking-at "[ \t]\\|[][!\"#$%&'()*+,-./0-9;<=>?@A-Z\\\\^_`a-z{|}~]+:"))
907 "*Set this non-nil if the system's mailer runs the header and body together.
908 \(This problem exists on Sunos 4 when sendmail is run in remote mode.)
909 The value should be an expression to test whether the problem will
911 :group 'message-sending
915 (define-mail-user-agent 'message-user-agent
916 'message-mail 'message-send-and-exit
917 'message-kill-buffer 'message-send-hook)
919 (defvar message-mh-deletable-headers '(Message-ID Date Lines Sender)
920 "If non-nil, delete the deletable headers before feeding to mh.")
922 (defvar message-send-method-alist
923 '((news message-news-p message-send-via-news)
924 (mail message-mail-p message-send-via-mail))
925 "Alist of ways to send outgoing messages.
926 Each element has the form
928 \(TYPE PREDICATE FUNCTION)
930 where TYPE is a symbol that names the method; PREDICATE is a function
931 called without any parameters to determine whether the message is
932 a message of type TYPE; and FUNCTION is a function to be called if
933 PREDICATE returns non-nil. FUNCTION is called with one parameter --
936 (defcustom message-mail-alias-type 'abbrev
937 "*What alias expansion type to use in Message buffers.
938 The default is `abbrev', which uses mailabbrev. nil switches
941 :link '(custom-manual "(message)Mail Aliases")
942 :type '(choice (const :tag "Use Mailabbrev" abbrev)
943 (const :tag "No expansion" nil)))
945 (defcustom message-auto-save-directory
946 (file-name-as-directory (nnheader-concat message-directory "drafts"))
947 "*Directory where Message auto-saves buffers if Gnus isn't running.
948 If nil, Message won't auto-save."
949 :group 'message-buffers
950 :type '(choice directory (const :tag "Don't auto-save" nil)))
952 (defcustom message-default-charset
953 (and (not (mm-multibyte-p)) 'iso-8859-1)
954 "Default charset used in non-MULE Emacsen.
955 If nil, you might be asked to input the charset."
960 (defcustom message-dont-reply-to-names
961 (and (boundp 'rmail-dont-reply-to-names) rmail-dont-reply-to-names)
962 "*A regexp specifying addresses to prune when doing wide replies.
963 A value of nil means exclude your own user name only."
966 :type '(choice (const :tag "Yourself" nil)
969 (defvar message-shoot-gnksa-feet nil
970 "*A list of GNKSA feet you are allowed to shoot.
971 Gnus gives you all the opportunity you could possibly want for
972 shooting yourself in the foot. Also, Gnus allows you to shoot the
973 feet of Good Net-Keeping Seal of Approval. The following are foot
975 `empty-article' Allow you to post an empty article;
976 `quoted-text-only' Allow you to post quoted text only;
977 `multiple-copies' Allow you to post multiple copies;
978 `cancel-messages' Allow you to cancel or supersede messages from
979 your other email addresses.")
981 (defsubst message-gnksa-enable-p (feature)
982 (or (not (listp message-shoot-gnksa-feet))
983 (memq feature message-shoot-gnksa-feet)))
985 ;;; Internal variables.
986 ;;; Well, not really internal.
988 (defvar message-mode-syntax-table
989 (let ((table (copy-syntax-table text-mode-syntax-table)))
990 (modify-syntax-entry ?% ". " table)
991 (modify-syntax-entry ?> ". " table)
992 (modify-syntax-entry ?< ". " table)
994 "Syntax table used while in Message mode.")
996 (defface message-header-to-face
999 (:foreground "green2" :bold t))
1002 (:foreground "MidnightBlue" :bold t))
1004 (:bold t :italic t)))
1005 "Face used for displaying From headers."
1006 :group 'message-faces)
1008 (defface message-header-cc-face
1011 (:foreground "green4" :bold t))
1014 (:foreground "MidnightBlue"))
1017 "Face used for displaying Cc headers."
1018 :group 'message-faces)
1020 (defface message-header-subject-face
1023 (:foreground "green3"))
1026 (:foreground "navy blue" :bold t))
1029 "Face used for displaying subject headers."
1030 :group 'message-faces)
1032 (defface message-header-newsgroups-face
1035 (:foreground "yellow" :bold t :italic t))
1038 (:foreground "blue4" :bold t :italic t))
1040 (:bold t :italic t)))
1041 "Face used for displaying newsgroups headers."
1042 :group 'message-faces)
1044 (defface message-header-other-face
1047 (:foreground "#b00000"))
1050 (:foreground "steel blue"))
1052 (:bold t :italic t)))
1053 "Face used for displaying newsgroups headers."
1054 :group 'message-faces)
1056 (defface message-header-name-face
1059 (:foreground "DarkGreen"))
1062 (:foreground "cornflower blue"))
1065 "Face used for displaying header names."
1066 :group 'message-faces)
1068 (defface message-header-xheader-face
1071 (:foreground "blue"))
1074 (:foreground "blue"))
1077 "Face used for displaying X-Header headers."
1078 :group 'message-faces)
1080 (defface message-separator-face
1083 (:foreground "blue3"))
1086 (:foreground "brown"))
1089 "Face used for displaying the separator."
1090 :group 'message-faces)
1092 (defface message-cited-text-face
1095 (:foreground "red"))
1098 (:foreground "red"))
1101 "Face used for displaying cited text names."
1102 :group 'message-faces)
1104 (defface message-mml-face
1107 (:foreground "ForestGreen"))
1110 (:foreground "ForestGreen"))
1113 "Face used for displaying MML."
1114 :group 'message-faces)
1116 (defun message-font-lock-make-header-matcher (regexp)
1119 (let ((start (point)))
1122 (goto-char (point-min))
1123 (if (re-search-forward
1124 (concat "^" (regexp-quote mail-header-separator) "$")
1126 (setq limit (min limit (match-beginning 0))))
1128 (and (< start limit)
1129 (re-search-forward ,regexp limit t))))))
1130 (if (featurep 'bytecomp)
1134 (defvar message-font-lock-keywords
1135 (let ((content "[ \t]*\\(.+\\(\n[ \t].*\\)*\\)\n?"))
1136 `((,(message-font-lock-make-header-matcher
1137 (concat "^\\([Tt]o:\\)" content))
1138 (1 'message-header-name-face)
1139 (2 'message-header-to-face nil t))
1140 (,(message-font-lock-make-header-matcher
1141 (concat "^\\(^[GBF]?[Cc][Cc]:\\|^[Rr]eply-[Tt]o:\\)" content))
1142 (1 'message-header-name-face)
1143 (2 'message-header-cc-face nil t))
1144 (,(message-font-lock-make-header-matcher
1145 (concat "^\\([Ss]ubject:\\)" content))
1146 (1 'message-header-name-face)
1147 (2 'message-header-subject-face nil t))
1148 (,(message-font-lock-make-header-matcher
1149 (concat "^\\([Nn]ewsgroups:\\|Followup-[Tt]o:\\)" content))
1150 (1 'message-header-name-face)
1151 (2 'message-header-newsgroups-face nil t))
1152 (,(message-font-lock-make-header-matcher
1153 (concat "^\\([A-Z][^: \n\t]+:\\)" content))
1154 (1 'message-header-name-face)
1155 (2 'message-header-other-face nil t))
1156 (,(message-font-lock-make-header-matcher
1157 (concat "^\\(X-[A-Za-z0-9-]+:\\|In-Reply-To:\\)" content))
1158 (1 'message-header-name-face)
1159 (2 'message-header-name-face))
1160 ,@(if (and mail-header-separator
1161 (not (equal mail-header-separator "")))
1162 `((,(concat "^\\(" (regexp-quote mail-header-separator) "\\)$")
1163 1 'message-separator-face))
1166 (re-search-forward (concat "^\\("
1167 message-cite-prefix-regexp
1170 (0 'message-cited-text-face))
1171 ("<#/?\\(multipart\\|part\\|external\\|mml\\|secure\\)[^>]*>"
1172 (0 'message-mml-face))))
1173 "Additional expressions to highlight in Message mode.")
1176 ;; XEmacs does it like this. For Emacs, we have to set the
1177 ;; `font-lock-defaults' buffer-local variable.
1178 (put 'message-mode 'font-lock-defaults '(message-font-lock-keywords t))
1180 (defvar message-face-alist
1181 '((bold . bold-region)
1182 (underline . underline-region)
1183 (default . (lambda (b e)
1185 (ununderline-region b e))))
1186 "Alist of mail and news faces for facemenu.
1187 The cdr of each entry is a function for applying the face to a region.")
1189 (defcustom message-send-hook nil
1190 "Hook run before sending messages.
1191 This hook is run quite early when sending."
1192 :group 'message-various
1193 :options '(ispell-message)
1196 (defcustom message-send-mail-hook nil
1197 "Hook run before sending mail messages.
1198 This hook is run very late -- just before the message is sent as
1200 :group 'message-various
1203 (defcustom message-send-news-hook nil
1204 "Hook run before sending news messages.
1205 This hook is run very late -- just before the message is sent as
1207 :group 'message-various
1210 (defcustom message-sent-hook nil
1211 "Hook run after sending messages."
1212 :group 'message-various
1215 (defvar message-send-coding-system 'binary
1216 "Coding system to encode outgoing mail.")
1218 (defvar message-draft-coding-system
1219 mm-auto-save-coding-system
1220 "*Coding system to compose mail.
1221 If you'd like to make it possible to share draft files between XEmacs
1222 and Emacs, you may use `iso-2022-7bit' for this value at your own risk.
1223 Note that the coding-system `iso-2022-7bit' isn't suitable to all data.")
1225 (defcustom message-send-mail-partially-limit 1000000
1226 "The limitation of messages sent as message/partial.
1227 The lower bound of message size in characters, beyond which the message
1228 should be sent in several parts. If it is nil, the size is unlimited."
1230 :group 'message-buffers
1231 :type '(choice (const :tag "unlimited" nil)
1234 (defcustom message-alternative-emails nil
1235 "A regexp to match the alternative email addresses.
1236 The first matched address (not primary one) is used in the From field."
1237 :group 'message-headers
1238 :type '(choice (const :tag "Always use primary" nil)
1241 (defcustom message-hierarchical-addresses nil
1242 "A list of hierarchical mail address definitions.
1244 Inside each entry, the first address is the \"top\" address, and
1245 subsequent addresses are subaddresses; this is used to indicate that
1246 mail sent to the first address will automatically be delivered to the
1247 subaddresses. So if the first address appears in the recipient list
1248 for a message, the subaddresses will be removed (if present) before
1249 the mail is sent. All addresses in this structure should be
1251 :group 'message-headers
1252 :type '(repeat (repeat string)))
1254 (defcustom message-mail-user-agent nil
1255 "Like `mail-user-agent'.
1256 Except if it is nil, use Gnus native MUA; if it is t, use
1258 :type '(radio (const :tag "Gnus native"
1261 (const :tag "`mail-user-agent'"
1264 (function-item :tag "Default Emacs mail"
1266 sendmail-user-agent)
1267 (function-item :tag "Emacs interface to MH"
1270 (function :tag "Other"))
1274 (defcustom message-wide-reply-confirm-recipients nil
1275 "Whether to confirm a wide reply to multiple email recipients.
1276 If this variable is nil, don't ask whether to reply to all recipients.
1277 If this variable is non-nil, pose the question \"Reply to all
1278 recipients?\" before a wide reply to multiple recipients. If the user
1279 answers yes, reply to all recipients as usual. If the user answers
1280 no, only reply back to the author."
1282 :group 'message-headers
1285 (defcustom message-user-fqdn nil
1286 "*Domain part of Messsage-Ids."
1287 :group 'message-headers
1288 :link '(custom-manual "(message)News Headers")
1291 (defcustom message-use-idna (and (condition-case nil (require 'idna)
1293 (fboundp 'coding-system-p)
1294 (coding-system-p 'utf-8)
1296 "Whether to encode non-ASCII in domain names into ASCII according to IDNA."
1297 :group 'message-headers
1298 :type '(choice (const :tag "Ask" ask)
1299 (const :tag "Never" nil)
1300 (const :tag "Always" t)))
1302 ;;; Internal variables.
1304 (defvar message-sending-message "Sending...")
1305 (defvar message-buffer-list nil)
1306 (defvar message-this-is-news nil)
1307 (defvar message-this-is-mail nil)
1308 (defvar message-draft-article nil)
1309 (defvar message-mime-part nil)
1310 (defvar message-posting-charset nil)
1312 ;; Byte-compiler warning
1314 (defvar gnus-active-hashtb)
1315 (defvar gnus-read-active-file))
1317 ;;; Regexp matching the delimiter of messages in UNIX mail format
1318 ;;; (UNIX From lines), minus the initial ^. It should be a copy
1319 ;;; of rmail.el's rmail-unix-mail-delimiter.
1320 (defvar message-unix-mail-delimiter
1321 (let ((time-zone-regexp
1322 (concat "\\([A-Z]?[A-Z]?[A-Z][A-Z]\\( DST\\)?"
1323 "\\|[-+]?[0-9][0-9][0-9][0-9]"
1329 ;; Many things can happen to an RFC 822 mailbox before it is put into
1330 ;; a `From' line. The leading phrase can be stripped, e.g.
1331 ;; `Joe <@w.x:joe@y.z>' -> `<@w.x:joe@y.z>'. The <> can be stripped, e.g.
1332 ;; `<@x.y:joe@y.z>' -> `@x.y:joe@y.z'. Everything starting with a CRLF
1333 ;; can be removed, e.g.
1334 ;; From: joe@y.z (Joe K
1336 ;; can yield `From joe@y.z (Joe K Fri Mar 22 08:11:15 1996', and
1339 ;; can yield `From Joe User Fri Mar 22 08:11:15 1996'.
1340 ;; The mailbox can be removed or be replaced by white space, e.g.
1341 ;; From: "Joe User"{space}{tab}
1343 ;; can yield `From {space}{tab} Fri Mar 22 08:11:15 1996',
1344 ;; where {space} and {tab} represent the Ascii space and tab characters.
1345 ;; We want to match the results of any of these manglings.
1346 ;; The following regexp rejects names whose first characters are
1347 ;; obviously bogus, but after that anything goes.
1348 "\\([^\0-\b\n-\r\^?].*\\)?"
1350 ;; The time the message was sent.
1351 "\\([^\0-\r \^?]+\\) +" ; day of the week
1352 "\\([^\0-\r \^?]+\\) +" ; month
1353 "\\([0-3]?[0-9]\\) +" ; day of month
1354 "\\([0-2][0-9]:[0-5][0-9]\\(:[0-6][0-9]\\)?\\) *" ; time of day
1356 ;; Perhaps a time zone, specified by an abbreviation, or by a
1361 " \\([0-9][0-9]+\\) *"
1363 ;; On some systems the time zone can appear after the year, too.
1367 "\\(remote from .*\\)?"
1370 "Regexp matching the delimiter of messages in UNIX mail format.")
1372 (defvar message-unsent-separator
1373 (concat "^ *---+ +Unsent message follows +---+ *$\\|"
1374 "^ *---+ +Returned message +---+ *$\\|"
1375 "^Start of returned message$\\|"
1376 "^ *---+ +Original message +---+ *$\\|"
1377 "^ *--+ +begin message +--+ *$\\|"
1378 "^ *---+ +Original message follows +---+ *$\\|"
1379 "^ *---+ +Undelivered message follows +---+ *$\\|"
1380 "^|? *---+ +Message text follows: +---+ *|?$")
1381 "A regexp that matches the separator before the text of a failed message.")
1383 (defvar message-header-format-alist
1385 (To . message-fill-address)
1386 (Cc . message-fill-address)
1397 (References . message-shorten-references)
1399 "Alist used for formatting headers.")
1401 (defvar message-options nil
1402 "Some saved answers when sending message.")
1404 (defvar message-send-mail-real-function nil
1405 "Internal send mail function.")
1407 (defvar message-bogus-system-names "^localhost\\."
1408 "The regexp of bogus system names.")
1410 (defcustom message-valid-fqdn-regexp
1411 (concat "[a-z0-9][-.a-z0-9]+\\." ;; [hostname.subdomain.]domain.
1413 "\\([a-z][a-z]" ;; two letter country TDLs
1414 "\\|biz\\|com\\|edu\\|gov\\|int\\|mil\\|net\\|org"
1415 "\\|aero\\|coop\\|info\\|name\\|museum"
1416 "\\|arpa\\|pro\\|uucp\\|bitnet\\|bofh" ;; old style?
1418 "Regular expression that matches a valid FQDN."
1419 ;; see also: gnus-button-valid-fqdn-regexp
1420 :group 'message-headers
1424 (autoload 'message-setup-toolbar "messagexmas")
1425 (autoload 'mh-new-draft-name "mh-comp")
1426 (autoload 'mh-send-letter "mh-comp")
1427 (autoload 'gnus-point-at-eol "gnus-util")
1428 (autoload 'gnus-point-at-bol "gnus-util")
1429 (autoload 'gnus-output-to-rmail "gnus-util")
1430 (autoload 'gnus-output-to-mail "gnus-util")
1431 (autoload 'nndraft-request-associate-buffer "nndraft")
1432 (autoload 'nndraft-request-expire-articles "nndraft")
1433 (autoload 'gnus-open-server "gnus-int")
1434 (autoload 'gnus-request-post "gnus-int")
1435 (autoload 'gnus-alive-p "gnus-util")
1436 (autoload 'gnus-server-string "gnus")
1437 (autoload 'gnus-group-name-charset "gnus-group")
1438 (autoload 'gnus-group-name-decode "gnus-group")
1439 (autoload 'gnus-groups-from-server "gnus")
1440 (autoload 'rmail-output "rmailout")
1441 (autoload 'gnus-delay-article "gnus-delay"))
1446 ;;; Utility functions.
1449 (defmacro message-y-or-n-p (question show &rest text)
1450 "Ask QUESTION, displaying remaining args in a temporary buffer if SHOW."
1451 `(message-talkative-question 'y-or-n-p ,question ,show ,@text))
1453 (defmacro message-delete-line (&optional n)
1454 "Delete the current line (and the next N lines)."
1455 `(delete-region (progn (beginning-of-line) (point))
1456 (progn (forward-line ,(or n 1)) (point))))
1458 (defun message-mark-active-p ()
1459 "Non-nil means the mark and region are currently active in this buffer."
1462 (defun message-unquote-tokens (elems)
1463 "Remove double quotes (\") from strings in list ELEMS."
1464 (mapcar (lambda (item)
1465 (while (string-match "^\\(.*\\)\"\\(.*\\)$" item)
1466 (setq item (concat (match-string 1 item)
1467 (match-string 2 item))))
1471 (defun message-tokenize-header (header &optional separator)
1472 "Split HEADER into a list of header elements.
1473 SEPARATOR is a string of characters to be used as separators. \",\"
1474 is used by default."
1477 (let ((regexp (format "[%s]+" (or separator ",")))
1482 (message-set-work-buffer)
1484 (goto-char (point-min))
1489 (cond ((and (> (point) beg)
1491 (and (looking-at regexp)
1494 (push (buffer-substring beg (point)) elems)
1495 (setq beg (match-end 0)))
1496 ((eq (char-after) ?\")
1497 (setq quoted (not quoted)))
1498 ((and (eq (char-after) ?\()
1501 ((and (eq (char-after) ?\))
1504 (nreverse elems)))))
1506 (defun message-mail-file-mbox-p (file)
1507 "Say whether FILE looks like a Unix mbox file."
1508 (when (and (file-exists-p file)
1509 (file-readable-p file)
1510 (file-regular-p file))
1512 (nnheader-insert-file-contents file)
1513 (goto-char (point-min))
1514 (looking-at message-unix-mail-delimiter))))
1516 (defun message-fetch-field (header &optional not-all)
1517 "The same as `mail-fetch-field', only remove all newlines."
1518 (let* ((inhibit-point-motion-hooks t)
1519 (case-fold-search t)
1520 (value (mail-fetch-field header nil (not not-all))))
1522 (while (string-match "\n[\t ]+" value)
1523 (setq value (replace-match " " t t value)))
1524 (set-text-properties 0 (length value) nil value)
1527 (defun message-narrow-to-field ()
1528 "Narrow the buffer to the header on the current line."
1534 (if (re-search-forward "^[^ \n\t]" nil t)
1539 (goto-char (point-min)))
1541 (defun message-add-header (&rest headers)
1542 "Add the HEADERS to the message header, skipping those already present."
1545 (unless (string-match "^\\([^:]+\\):[ \t]*[^ \t]" (car headers))
1546 (error "Invalid header `%s'" (car headers)))
1547 (setq hclean (match-string 1 (car headers)))
1549 (message-narrow-to-headers)
1550 (unless (re-search-forward (concat "^" (regexp-quote hclean) ":") nil t)
1551 (goto-char (point-max))
1552 (if (string-match "\n$" (car headers))
1553 (insert (car headers))
1554 (insert (car headers) ?\n)))))
1555 (setq headers (cdr headers))))
1557 (defmacro message-with-reply-buffer (&rest forms)
1558 "Evaluate FORMS in the reply buffer, if it exists."
1559 `(when (and message-reply-buffer
1560 (buffer-name message-reply-buffer))
1562 (set-buffer message-reply-buffer)
1565 (put 'message-with-reply-buffer 'lisp-indent-function 0)
1566 (put 'message-with-reply-buffer 'edebug-form-spec '(body))
1568 (defun message-fetch-reply-field (header)
1569 "Fetch field HEADER from the message we're replying to."
1570 (message-with-reply-buffer
1572 (mail-narrow-to-head)
1573 (message-fetch-field header))))
1575 (defun message-set-work-buffer ()
1576 (if (get-buffer " *message work*")
1578 (set-buffer " *message work*")
1580 (set-buffer (get-buffer-create " *message work*"))
1581 (kill-all-local-variables)
1582 (mm-enable-multibyte)))
1584 (defun message-functionp (form)
1585 "Return non-nil if FORM is funcallable."
1586 (or (and (symbolp form) (fboundp form))
1587 (and (listp form) (eq (car form) 'lambda))
1588 (byte-code-function-p form)))
1590 (defun message-strip-list-identifiers (subject)
1591 "Remove list identifiers in `gnus-list-identifiers' from string SUBJECT."
1592 (require 'gnus-sum) ; for gnus-list-identifiers
1593 (let ((regexp (if (stringp gnus-list-identifiers)
1594 gnus-list-identifiers
1595 (mapconcat 'identity gnus-list-identifiers " *\\|"))))
1596 (if (string-match (concat "\\(\\(\\(Re: +\\)?\\(" regexp
1597 " *\\)\\)+\\(Re: +\\)?\\)") subject)
1598 (concat (substring subject 0 (match-beginning 1))
1599 (or (match-string 3 subject)
1600 (match-string 5 subject))
1605 (defun message-strip-subject-re (subject)
1606 "Remove \"Re:\" from subject lines in string SUBJECT."
1607 (if (string-match message-subject-re-regexp subject)
1608 (substring subject (match-end 0))
1611 ;;; Start of functions adopted from `message-utils.el'.
1613 (defun message-strip-subject-trailing-was (subject)
1614 "Remove trailing \"(Was: <old subject>)\" from SUBJECT lines.
1615 Leading \"Re: \" is not stripped by this function. Use the function
1616 `message-strip-subject-re' for this."
1617 (let* ((query message-subject-trailing-was-query)
1622 message-subject-trailing-was-ask-regexp
1623 message-subject-trailing-was-regexp)
1626 (setq new (substring subject 0 (match-beginning 0))))
1627 (if (or (not found) (eq query nil))
1630 (if (message-y-or-n-p
1631 "Strip `(was: <old subject>)' in subject? " t
1633 "Strip `(was: <old subject>)' in subject "
1634 "and use the new one instead?\n\n"
1635 "Current subject is: \""
1637 "New subject would be: \""
1639 "See the variable `message-subject-trailing-was-query' "
1640 "to get rid of this query."
1645 ;;; Suggested by Jonas Steverud @ www.dtek.chalmers.se/~d4jonas/
1648 (defun message-change-subject (new-subject)
1649 "Ask for NEW-SUBJECT header, append (was: <Old Subject>)."
1652 (read-from-minibuffer "New subject: ")))
1653 (cond ((and (not (or (null new-subject) ; new subject not empty
1654 (zerop (string-width new-subject))
1655 (string-match "^[ \t]*$" new-subject))))
1657 (let ((old-subject (message-fetch-field "Subject")))
1658 (cond ((not old-subject)
1659 (error "No current subject"))
1662 (regexp-quote new-subject)
1664 old-subject)) ; yes, it really is a new subject
1665 ;; delete eventual Re: prefix
1667 (message-strip-subject-re old-subject))
1668 (message-goto-subject)
1669 (message-delete-line)
1670 (insert (concat "Subject: "
1673 old-subject ")\n")))))))))
1676 (defun message-mark-inserted-region (beg end)
1677 "Mark some region in the current article with enclosing tags.
1678 See `message-mark-insert-begin' and `message-mark-insert-end'."
1681 ; add to the end of the region first, otherwise end would be invalid
1683 (insert message-mark-insert-end)
1685 (insert message-mark-insert-begin)))
1688 (defun message-mark-insert-file (file)
1689 "Insert FILE at point, marking it with enclosing tags.
1690 See `message-mark-insert-begin' and `message-mark-insert-end'."
1691 (interactive "fFile to insert: ")
1692 ;; reverse insertion to get correct result.
1694 (insert message-mark-insert-end)
1696 (insert-file-contents file)
1698 (insert message-mark-insert-begin)))
1701 (defun message-add-archive-header ()
1702 "Insert \"X-No-Archive: Yes\" in the header and a note in the body.
1703 The note can be customized using `message-archive-note'. When called with a
1704 prefix argument, ask for a text to insert. If you don't want the note in the
1705 body, set `message-archive-note' to nil."
1707 (if current-prefix-arg
1708 (setq message-archive-note
1709 (read-from-minibuffer "Reason for No-Archive: "
1710 (cons message-archive-note 0))))
1712 (if (message-goto-signature)
1713 (re-search-backward message-signature-separator))
1714 (when message-archive-note
1715 (insert message-archive-note)
1717 (message-add-header message-archive-header)
1718 (message-sort-headers)))
1721 (defun message-cross-post-followup-to-header (target-group)
1722 "Mangles FollowUp-To and Newsgroups header to point to TARGET-GROUP.
1723 With prefix-argument just set Follow-Up, don't cross-post."
1725 (list ; Completion based on Gnus
1726 (completing-read "Followup To: "
1727 (if (boundp 'gnus-newsrc-alist)
1729 nil nil '("poster" . 0)
1730 (if (boundp 'gnus-group-history)
1731 'gnus-group-history))))
1732 (message-remove-header "Follow[Uu]p-[Tt]o" t)
1733 (message-goto-newsgroups)
1735 ;; if we already did a crosspost before, kill old target
1736 (if (and message-cross-post-old-target
1738 (regexp-quote (concat "," message-cross-post-old-target))
1741 ;; unless (followup is to poster or user explicitly asked not
1742 ;; to cross-post, or target-group is already in Newsgroups)
1743 ;; add target-group to Newsgroups line.
1745 ;; def: cross-post, req:no
1746 (and message-cross-post-default (not current-prefix-arg))
1747 ;; def: no-cross-post, req:yes
1748 (and (not message-cross-post-default) current-prefix-arg))
1749 (not (string-match "poster" target-group))
1750 (not (string-match (regexp-quote target-group)
1751 (message-fetch-field "Newsgroups"))))
1753 (insert (concat "," target-group))))
1754 (end-of-line) ; ensure Followup: comes after Newsgroups:
1755 ;; unless new followup would be identical to Newsgroups line
1756 ;; make a new Followup-To line
1757 (if (not (string-match (concat "^[ \t]*"
1760 (message-fetch-field "Newsgroups")))
1761 (insert (concat "\nFollowup-To: " target-group)))
1762 (setq message-cross-post-old-target target-group))
1765 (defun message-cross-post-insert-note (target-group cross-post in-old
1767 "Insert a in message body note about a set Followup or Crosspost.
1768 If there have been previous notes, delete them. TARGET-GROUP specifies the
1769 group to Followup-To. When CROSS-POST is t, insert note about
1770 crossposting. IN-OLD specifies whether TARGET-GROUP is a member of
1771 OLD-GROUPS. OLD-GROUPS lists the old-groups the posting would have
1772 been made to before the user asked for a Crosspost."
1773 ;; start scanning body for previous uses
1774 (message-goto-signature)
1775 (let ((head (re-search-backward
1776 (concat "^" mail-header-separator)
1777 nil t))) ; just search in body
1778 (message-goto-signature)
1779 (while (re-search-backward
1780 (concat "^" (regexp-quote message-cross-post-note) ".*")
1782 (message-delete-line))
1783 (message-goto-signature)
1784 (while (re-search-backward
1785 (concat "^" (regexp-quote message-followup-to-note) ".*")
1787 (message-delete-line))
1789 (if (message-goto-signature)
1790 (re-search-backward message-signature-separator))
1793 (string-match "^[ \t]*poster[ \t]*$" target-group))
1794 (insert (concat message-followup-to-note target-group "\n"))
1795 (insert (concat message-cross-post-note target-group "\n")))))
1798 (defun message-cross-post-followup-to (target-group)
1799 "Crossposts message and set Followup-To to TARGET-GROUP.
1800 With prefix-argument just set Follow-Up, don't cross-post."
1802 (list ; Completion based on Gnus
1803 (completing-read "Followup To: "
1804 (if (boundp 'gnus-newsrc-alist)
1806 nil nil '("poster" . 0)
1807 (if (boundp 'gnus-group-history)
1808 'gnus-group-history))))
1809 (cond ((not (or (null target-group) ; new subject not empty
1810 (zerop (string-width target-group))
1811 (string-match "^[ \t]*$" target-group)))
1813 (let* ((old-groups (message-fetch-field "Newsgroups"))
1814 (in-old (string-match
1815 (regexp-quote target-group)
1816 (or old-groups ""))))
1817 ;; check whether target exactly matches old Newsgroups
1818 (cond ((not old-groups)
1819 (error "No current newsgroup"))
1823 (regexp-quote target-group)
1826 ;; yes, Newsgroups line must change
1827 (message-cross-post-followup-to-header target-group)
1828 ;; insert note whether we do cross-post or followup-to
1829 (funcall message-cross-post-note-function
1831 (if (or (and message-cross-post-default
1832 (not current-prefix-arg))
1833 (and (not message-cross-post-default)
1834 current-prefix-arg)) t)
1835 in-old old-groups))))))))
1837 ;;; Reduce To: to Cc: or Bcc: header
1840 (defun message-reduce-to-to-cc ()
1841 "Replace contents of To: header with contents of Cc: or Bcc: header."
1843 (let ((cc-content (message-fetch-field "cc"))
1845 (if (and (not cc-content)
1846 (setq cc-content (message-fetch-field "bcc")))
1851 (message-delete-line)
1852 (insert (concat "To: " cc-content "\n"))
1853 (message-remove-header (if bcc
1857 ;;; End of functions adopted from `message-utils.el'.
1859 (defun message-remove-header (header &optional is-regexp first reverse)
1860 "Remove HEADER in the narrowed buffer.
1861 If IS-REGEXP, HEADER is a regular expression.
1862 If FIRST, only remove the first instance of the header.
1863 Return the number of headers removed."
1864 (goto-char (point-min))
1865 (let ((regexp (if is-regexp header (concat "^" (regexp-quote header) ":")))
1867 (case-fold-search t)
1869 (while (and (not (eobp))
1872 (not (looking-at regexp))
1873 (looking-at regexp))
1880 ;; There might be a continuation header, so we have to search
1881 ;; until we find a new non-continuation line.
1884 (if (re-search-forward "^[^ \t]" nil t)
1885 (goto-char (match-beginning 0))
1888 (if (re-search-forward "^[^ \t]" nil t)
1889 (goto-char (match-beginning 0))
1890 (goto-char (point-max)))))
1893 (defun message-remove-first-header (header)
1894 "Remove the first instance of HEADER if there is more than one."
1896 (regexp (concat "^" (regexp-quote header) ":")))
1898 (goto-char (point-min))
1899 (while (re-search-forward regexp nil t)
1902 (message-remove-header header nil t)
1905 (defun message-narrow-to-headers ()
1906 "Narrow the buffer to the head of the message."
1909 (goto-char (point-min))
1910 (if (re-search-forward
1911 (concat "^" (regexp-quote mail-header-separator) "\n") nil t)
1914 (goto-char (point-min)))
1916 (defun message-narrow-to-head-1 ()
1917 "Like `message-narrow-to-head'. Don't widen."
1919 (goto-char (point-min))
1920 (if (search-forward "\n\n" nil 1)
1923 (goto-char (point-min)))
1925 (defun message-narrow-to-head ()
1926 "Narrow the buffer to the head of the message.
1927 Point is left at the beginning of the narrowed-to region."
1929 (message-narrow-to-head-1))
1931 (defun message-narrow-to-headers-or-head ()
1932 "Narrow the buffer to the head of the message."
1935 (goto-char (point-min))
1938 (concat "^" (regexp-quote mail-header-separator) "\n") nil t)
1939 (match-beginning 0))
1940 ((search-forward "\n\n" nil t)
1944 (goto-char (point-min)))
1946 (defun message-news-p ()
1947 "Say whether the current buffer contains a news message."
1948 (and (not message-this-is-mail)
1949 (or message-this-is-news
1952 (message-narrow-to-headers)
1953 (and (message-fetch-field "newsgroups")
1954 (not (message-fetch-field "posted-to"))))))))
1956 (defun message-mail-p ()
1957 "Say whether the current buffer contains a mail message."
1958 (and (not message-this-is-news)
1959 (or message-this-is-mail
1962 (message-narrow-to-headers)
1963 (or (message-fetch-field "to")
1964 (message-fetch-field "cc")
1965 (message-fetch-field "bcc")))))))
1967 (defun message-subscribed-p ()
1968 "Say whether we need to insert a MFT header."
1969 (or message-subscribed-regexps
1970 message-subscribed-addresses
1971 message-subscribed-address-file
1972 message-subscribed-address-functions))
1974 (defun message-next-header ()
1975 "Go to the beginning of the next header."
1977 (or (eobp) (forward-char 1))
1978 (not (if (re-search-forward "^[^ \t]" nil t)
1980 (goto-char (point-max)))))
1982 (defun message-sort-headers-1 ()
1983 "Sort the buffer as headers using `message-rank' text props."
1984 (goto-char (point-min))
1987 nil 'message-next-header
1989 (message-next-header)
1993 (or (get-text-property (point) 'message-rank)
1996 (defun message-sort-headers ()
1997 "Sort the headers of the current message according to `message-header-format-alist'."
2001 (let ((max (1+ (length message-header-format-alist)))
2003 (message-narrow-to-headers)
2004 (while (re-search-forward "^[^ \n]+:" nil t)
2006 (match-beginning 0) (1+ (match-beginning 0))
2008 (if (setq rank (length (memq (assq (intern (buffer-substring
2010 (1- (match-end 0))))
2011 message-header-format-alist)
2012 message-header-format-alist)))
2015 (message-sort-headers-1))))
2026 (defvar message-mode-map nil)
2028 (unless message-mode-map
2029 (setq message-mode-map (make-keymap))
2030 (set-keymap-parent message-mode-map text-mode-map)
2031 (define-key message-mode-map "\C-c?" 'describe-mode)
2033 (define-key message-mode-map "\C-c\C-f\C-t" 'message-goto-to)
2034 (define-key message-mode-map "\C-c\C-f\C-o" 'message-goto-from)
2035 (define-key message-mode-map "\C-c\C-f\C-b" 'message-goto-bcc)
2036 (define-key message-mode-map "\C-c\C-f\C-w" 'message-goto-fcc)
2037 (define-key message-mode-map "\C-c\C-f\C-c" 'message-goto-cc)
2038 (define-key message-mode-map "\C-c\C-f\C-s" 'message-goto-subject)
2039 (define-key message-mode-map "\C-c\C-f\C-r" 'message-goto-reply-to)
2040 (define-key message-mode-map "\C-c\C-f\C-n" 'message-goto-newsgroups)
2041 (define-key message-mode-map "\C-c\C-f\C-d" 'message-goto-distribution)
2042 (define-key message-mode-map "\C-c\C-f\C-f" 'message-goto-followup-to)
2043 (define-key message-mode-map "\C-c\C-f\C-m" 'message-goto-mail-followup-to)
2044 (define-key message-mode-map "\C-c\C-f\C-k" 'message-goto-keywords)
2045 (define-key message-mode-map "\C-c\C-f\C-u" 'message-goto-summary)
2046 (define-key message-mode-map "\C-c\C-f\C-i"
2047 'message-insert-or-toggle-importance)
2048 (define-key message-mode-map "\C-c\C-f\C-a"
2049 'message-generate-unsubscribed-mail-followup-to)
2051 ;; modify headers (and insert notes in body)
2052 (define-key message-mode-map "\C-c\C-fs" 'message-change-subject)
2054 (define-key message-mode-map "\C-c\C-fx" 'message-cross-post-followup-to)
2055 ;; prefix+message-cross-post-followup-to = same w/o cross-post
2056 (define-key message-mode-map "\C-c\C-ft" 'message-reduce-to-to-cc)
2057 (define-key message-mode-map "\C-c\C-fa" 'message-add-archive-header)
2058 ;; mark inserted text
2059 (define-key message-mode-map "\C-c\M-m" 'message-mark-inserted-region)
2060 (define-key message-mode-map "\C-c\M-f" 'message-mark-insert-file)
2062 (define-key message-mode-map "\C-c\C-b" 'message-goto-body)
2063 (define-key message-mode-map "\C-c\C-i" 'message-goto-signature)
2065 (define-key message-mode-map "\C-c\C-t" 'message-insert-to)
2066 (define-key message-mode-map "\C-c\C-fw" 'message-insert-wide-reply)
2067 (define-key message-mode-map "\C-c\C-n" 'message-insert-newsgroups)
2068 (define-key message-mode-map "\C-c\C-l" 'message-to-list-only)
2070 (define-key message-mode-map "\C-c\C-u" 'message-insert-or-toggle-importance)
2071 (define-key message-mode-map "\C-c\M-n"
2072 'message-insert-disposition-notification-to)
2074 (define-key message-mode-map "\C-c\C-y" 'message-yank-original)
2075 (define-key message-mode-map "\C-c\M-\C-y" 'message-yank-buffer)
2076 (define-key message-mode-map "\C-c\C-q" 'message-fill-yanked-message)
2077 (define-key message-mode-map "\C-c\C-w" 'message-insert-signature)
2078 (define-key message-mode-map "\C-c\M-h" 'message-insert-headers)
2079 (define-key message-mode-map "\C-c\C-r" 'message-caesar-buffer-body)
2080 (define-key message-mode-map "\C-c\C-o" 'message-sort-headers)
2081 (define-key message-mode-map "\C-c\M-r" 'message-rename-buffer)
2083 (define-key message-mode-map "\C-c\C-c" 'message-send-and-exit)
2084 (define-key message-mode-map "\C-c\C-s" 'message-send)
2085 (define-key message-mode-map "\C-c\C-k" 'message-kill-buffer)
2086 (define-key message-mode-map "\C-c\C-d" 'message-dont-send)
2087 (define-key message-mode-map "\C-c\n" 'gnus-delay-article)
2089 (define-key message-mode-map "\C-c\C-e" 'message-elide-region)
2090 (define-key message-mode-map "\C-c\C-v" 'message-delete-not-region)
2091 (define-key message-mode-map "\C-c\C-z" 'message-kill-to-signature)
2092 (define-key message-mode-map "\M-\r" 'message-newline-and-reformat)
2093 ;;(define-key message-mode-map "\M-q" 'message-fill-paragraph)
2095 (define-key message-mode-map "\C-c\C-a" 'mml-attach-file)
2097 (define-key message-mode-map "\C-a" 'message-beginning-of-line)
2098 (define-key message-mode-map "\t" 'message-tab)
2099 (define-key message-mode-map "\M-;" 'comment-region))
2102 message-mode-menu message-mode-map "Message Menu."
2104 ["Yank Original" message-yank-original message-reply-buffer]
2105 ["Fill Yanked Message" message-fill-yanked-message t]
2106 ["Insert Signature" message-insert-signature t]
2107 ["Caesar (rot13) Message" message-caesar-buffer-body t]
2108 ["Caesar (rot13) Region" message-caesar-region (message-mark-active-p)]
2109 ["Elide Region" message-elide-region
2110 :active (message-mark-active-p)
2111 ,@(if (featurep 'xemacs) nil
2112 '(:help "Replace text in region with an ellipsis"))]
2113 ["Delete Outside Region" message-delete-not-region
2114 :active (message-mark-active-p)
2115 ,@(if (featurep 'xemacs) nil
2116 '(:help "Delete all quoted text outside region"))]
2117 ["Kill To Signature" message-kill-to-signature t]
2118 ["Newline and Reformat" message-newline-and-reformat t]
2119 ["Rename buffer" message-rename-buffer t]
2120 ["Spellcheck" ispell-message
2121 ,@(if (featurep 'xemacs) '(t)
2122 '(:help "Spellcheck this message"))]
2124 ["Insert Region Marked" message-mark-inserted-region
2125 :active (message-mark-active-p)
2126 ,@(if (featurep 'xemacs) nil
2127 '(:help "Mark region with enclosing tags"))]
2128 ["Insert File Marked..." message-mark-insert-file
2129 ,@(if (featurep 'xemacs) '(t)
2130 '(:help "Insert file at point marked with enclosing tags"))]
2132 ["Send Message" message-send-and-exit
2133 ,@(if (featurep 'xemacs) '(t)
2134 '(:help "Send this message"))]
2135 ["Postpone Message" message-dont-send
2136 ,@(if (featurep 'xemacs) '(t)
2137 '(:help "File this draft message and exit"))]
2138 ["Send at Specific Time..." gnus-delay-article
2139 ,@(if (featurep 'xemacs) '(t)
2140 '(:help "Ask, then arrange to send message at that time"))]
2141 ["Kill Message" message-kill-buffer
2142 ,@(if (featurep 'xemacs) '(t)
2143 '(:help "Delete this message without sending"))]))
2146 message-mode-field-menu message-mode-map ""
2148 ["Fetch To" message-insert-to t]
2149 ["Fetch Newsgroups" message-insert-newsgroups t]
2151 ["To" message-goto-to t]
2152 ["From" message-goto-from t]
2153 ["Subject" message-goto-subject t]
2154 ["Change subject..." message-change-subject t]
2155 ["Cc" message-goto-cc t]
2156 ["Bcc" message-goto-bcc t]
2157 ["Fcc" message-goto-fcc t]
2158 ["Reply-To" message-goto-reply-to t]
2159 ["Flag As Important" message-insert-importance-high
2160 ,@(if (featurep 'xemacs) '(t)
2161 '(:help "Mark this message as important"))]
2162 ["Flag As Unimportant" message-insert-importance-low
2163 ,@(if (featurep 'xemacs) '(t)
2164 '(:help "Mark this message as unimportant"))]
2166 message-insert-disposition-notification-to
2167 ,@(if (featurep 'xemacs) '(t)
2168 '(:help "Request a receipt notification"))]
2170 ;; (typical) news stuff
2171 ["Summary" message-goto-summary t]
2172 ["Keywords" message-goto-keywords t]
2173 ["Newsgroups" message-goto-newsgroups t]
2174 ["Followup-To" message-goto-followup-to t]
2175 ;; ["Followup-To (with note in body)" message-cross-post-followup-to t]
2176 ["Crosspost / Followup-To..." message-cross-post-followup-to t]
2177 ["Distribution" message-goto-distribution t]
2178 ["X-No-Archive:" message-add-archive-header t ]
2180 ;; (typical) mailing-lists stuff
2181 ["Send to list only" message-to-list-only t]
2182 ["Mail-Followup-To" message-goto-mail-followup-to t]
2183 ["Reduce To: to Cc:" message-reduce-to-to-cc t]
2185 ["Sort Headers" message-sort-headers t]
2186 ["Encode non-ASCII domain names" message-idna-to-ascii-rhs t]
2187 ["Goto Body" message-goto-body t]
2188 ["Goto Signature" message-goto-signature t]))
2190 (defvar message-tool-bar-map nil)
2193 (defvar facemenu-add-face-function)
2194 (defvar facemenu-remove-face-function))
2196 ;;; Forbidden properties
2198 ;; We use `after-change-functions' to keep special text properties
2199 ;; that interfer with the normal function of message mode out of the
2202 (defcustom message-strip-special-text-properties t
2203 "Strip special properties from the message buffer.
2205 Emacs has a number of special text properties which can break message
2206 composing in various ways. If this option is set, message will strip
2207 these properties from the message composition buffer. However, some
2208 packages requires these properties to be present in order to work.
2209 If you use one of these packages, turn this option off, and hope the
2210 message composition doesn't break too bad."
2211 :group 'message-various
2214 (defconst message-forbidden-properties
2215 ;; No reason this should be clutter up customize. We make it a
2216 ;; property list (rather than a list of property symbols), to be
2217 ;; directly useful for `remove-text-properties'.
2218 '(field nil read-only nil intangible nil invisible nil
2219 mouse-face nil modification-hooks nil insert-in-front-hooks nil
2220 insert-behind-hooks nil point-entered nil point-left nil)
2221 ;; Other special properties:
2222 ;; category, face, display: probably doesn't do any harm.
2223 ;; fontified: is used by font-lock.
2224 ;; syntax-table, local-map: I dunno.
2225 ;; We need to add XEmacs names to the list.
2226 "Property list of with properties.forbidden in message buffers.
2227 The values of the properties are ignored, only the property names are used.")
2229 (defun message-tamago-not-in-use-p (pos)
2230 "Return t when tamago version 4 is not in use at the cursor position.
2231 Tamago version 4 is a popular input method for writing Japanese text.
2232 It uses the properties `intangible', `invisible', `modification-hooks'
2233 and `read-only' when translating ascii or kana text to kanji text.
2234 These properties are essential to work, so we should never strip them."
2235 (not (and (boundp 'egg-modefull-mode)
2236 (symbol-value 'egg-modefull-mode)
2237 (or (memq (get-text-property pos 'intangible)
2238 '(its-part-1 its-part-2))
2239 (get-text-property pos 'egg-end)
2240 (get-text-property pos 'egg-lang)
2241 (get-text-property pos 'egg-start)))))
2243 (defun message-strip-forbidden-properties (begin end &optional old-length)
2244 "Strip forbidden properties between BEGIN and END, ignoring the third arg.
2245 This function is intended to be called from `after-change-functions'.
2246 See also `message-forbidden-properties'."
2247 (when (and message-strip-special-text-properties
2248 (message-tamago-not-in-use-p begin))
2249 (remove-text-properties begin end message-forbidden-properties)))
2252 (define-derived-mode message-mode text-mode "Message"
2253 "Major mode for editing mail and news to be sent.
2254 Like Text Mode but with these additional commands:\\<message-mode-map>
2255 C-c C-s `message-send' (send the message) C-c C-c `message-send-and-exit'
2256 C-c C-d Postpone sending the message C-c C-k Kill the message
2257 C-c C-f move to a header field (and create it if there isn't):
2258 C-c C-f C-t move to To C-c C-f C-s move to Subject
2259 C-c C-f C-c move to Cc C-c C-f C-b move to Bcc
2260 C-c C-f C-w move to Fcc C-c C-f C-r move to Reply-To
2261 C-c C-f C-u move to Summary C-c C-f C-n move to Newsgroups
2262 C-c C-f C-k move to Keywords C-c C-f C-d move to Distribution
2263 C-c C-f C-o move to From (\"Originator\")
2264 C-c C-f C-f move to Followup-To
2265 C-c C-f C-m move to Mail-Followup-To
2266 C-c C-f C-i cycle through Importance values
2267 C-c C-f s change subject and append \"(was: <Old Subject>)\"
2268 C-c C-f x crossposting with FollowUp-To header and note in body
2269 C-c C-f t replace To: header with contents of Cc: or Bcc:
2270 C-c C-f a Insert X-No-Archive: header and a note in the body
2271 C-c C-t `message-insert-to' (add a To header to a news followup)
2272 C-c C-l `message-to-list-only' (removes all but list address in to/cc)
2273 C-c C-n `message-insert-newsgroups' (add a Newsgroup header to a news reply)
2274 C-c C-b `message-goto-body' (move to beginning of message text).
2275 C-c C-i `message-goto-signature' (move to the beginning of the signature).
2276 C-c C-w `message-insert-signature' (insert `message-signature-file' file).
2277 C-c C-y `message-yank-original' (insert current message, if any).
2278 C-c C-q `message-fill-yanked-message' (fill what was yanked).
2279 C-c C-e `message-elide-region' (elide the text between point and mark).
2280 C-c C-v `message-delete-not-region' (remove the text outside the region).
2281 C-c C-z `message-kill-to-signature' (kill the text up to the signature).
2282 C-c C-r `message-caesar-buffer-body' (rot13 the message body).
2283 C-c C-a `mml-attach-file' (attach a file as MIME).
2284 C-c C-u `message-insert-or-toggle-importance' (insert or cycle importance).
2285 C-c M-n `message-insert-disposition-notification-to' (request receipt).
2286 C-c M-m `message-mark-inserted-region' (mark region with enclosing tags).
2287 C-c M-f `message-mark-insert-file' (insert file marked with enclosing tags).
2288 M-RET `message-newline-and-reformat' (break the line and reformat)."
2289 (setq local-abbrev-table text-mode-abbrev-table)
2290 (set (make-local-variable 'message-reply-buffer) nil)
2291 (make-local-variable 'message-send-actions)
2292 (make-local-variable 'message-exit-actions)
2293 (make-local-variable 'message-kill-actions)
2294 (make-local-variable 'message-postpone-actions)
2295 (make-local-variable 'message-draft-article)
2296 (setq buffer-offer-save t)
2297 (set (make-local-variable 'facemenu-add-face-function)
2299 (let ((face-fun (cdr (assq face message-face-alist))))
2301 (funcall face-fun (point) end)
2302 (error "Face %s not configured for %s mode" face mode-name)))
2304 (set (make-local-variable 'facemenu-remove-face-function) t)
2305 (set (make-local-variable 'message-reply-headers) nil)
2306 (make-local-variable 'message-newsreader)
2307 (make-local-variable 'message-mailer)
2308 (make-local-variable 'message-post-method)
2309 (set (make-local-variable 'message-sent-message-via) nil)
2310 (set (make-local-variable 'message-checksum) nil)
2311 (set (make-local-variable 'message-mime-part) 0)
2312 (message-setup-fill-variables)
2314 (make-local-variable 'paragraph-separate)
2315 (format "\\(%s\\)\\|\\(%s\\)"
2317 "<#!*/?\\(multipart\\|part\\|external\\|mml\\|secure\\)"))
2318 ;; Allow using comment commands to add/remove quoting.
2319 (set (make-local-variable 'comment-start) message-yank-prefix)
2320 (if (featurep 'xemacs)
2321 (message-setup-toolbar)
2322 (set (make-local-variable 'font-lock-defaults)
2323 '(message-font-lock-keywords t))
2324 (if (boundp 'tool-bar-map)
2325 (set (make-local-variable 'tool-bar-map) (message-tool-bar-map))))
2326 (easy-menu-add message-mode-menu message-mode-map)
2327 (easy-menu-add message-mode-field-menu message-mode-map)
2328 ;; make-local-hook is harmless though obsolete in Emacs 21.
2329 ;; Emacs 20 and XEmacs need make-local-hook.
2330 (make-local-hook 'after-change-functions)
2331 ;; Mmmm... Forbidden properties...
2332 (add-hook 'after-change-functions 'message-strip-forbidden-properties
2334 ;; Allow mail alias things.
2335 (when (eq message-mail-alias-type 'abbrev)
2336 (if (fboundp 'mail-abbrevs-setup)
2337 (mail-abbrevs-setup)
2338 (mail-aliases-setup)))
2339 (unless buffer-file-name
2340 (message-set-auto-save-file-name))
2341 (unless (buffer-base-buffer)
2342 ;; Don't enable multibyte on an indirect buffer. Maybe enabling
2343 ;; multibyte is not necessary at all. -- zsh
2344 (mm-enable-multibyte))
2345 (set (make-local-variable 'indent-tabs-mode) nil) ;No tabs for indentation.
2348 (defun message-setup-fill-variables ()
2349 "Setup message fill variables."
2350 (set (make-local-variable 'fill-paragraph-function)
2351 'message-fill-paragraph)
2352 (make-local-variable 'paragraph-separate)
2353 (make-local-variable 'paragraph-start)
2354 (make-local-variable 'adaptive-fill-regexp)
2355 (unless (boundp 'adaptive-fill-first-line-regexp)
2356 (setq adaptive-fill-first-line-regexp nil))
2357 (make-local-variable 'adaptive-fill-first-line-regexp)
2358 (let ((quote-prefix-regexp
2359 ;; User should change message-cite-prefix-regexp if
2360 ;; message-yank-prefix is set to an abnormal value.
2361 (concat "\\(" message-cite-prefix-regexp "\\)[ \t]*")))
2362 (setq paragraph-start
2364 (regexp-quote mail-header-separator) "$\\|"
2365 "[ \t]*$\\|" ; blank lines
2366 "-- $\\|" ; signature delimiter
2367 "---+$\\|" ; delimiters for forwarded messages
2368 page-delimiter "$\\|" ; spoiler warnings
2369 ".*wrote:$\\|" ; attribution lines
2370 quote-prefix-regexp "$")) ; empty lines in quoted text
2371 (setq paragraph-separate paragraph-start)
2372 (setq adaptive-fill-regexp
2373 (concat quote-prefix-regexp "\\|" adaptive-fill-regexp))
2374 (setq adaptive-fill-first-line-regexp
2375 (concat quote-prefix-regexp "\\|"
2376 adaptive-fill-first-line-regexp)))
2377 (make-local-variable 'auto-fill-inhibit-regexp)
2378 ;;(setq auto-fill-inhibit-regexp "^[A-Z][^: \n\t]+:")
2379 (setq auto-fill-inhibit-regexp nil)
2380 (make-local-variable 'normal-auto-fill-function)
2381 (setq normal-auto-fill-function 'message-do-auto-fill)
2382 ;; KLUDGE: auto fill might already be turned on in `text-mode-hook'.
2383 ;; In that case, ensure that it uses the right function. The real
2384 ;; solution would be not to use `define-derived-mode', and run
2385 ;; `text-mode-hook' ourself at the end of the mode.
2386 ;; -- Per Abrahamsen <abraham@dina.kvl.dk> Date: 2001-10-19.
2387 (when auto-fill-function
2388 (setq auto-fill-function normal-auto-fill-function)))
2393 ;;; Message mode commands
2396 ;;; Movement commands
2398 (defun message-goto-to ()
2399 "Move point to the To header."
2401 (message-position-on-field "To"))
2403 (defun message-goto-from ()
2404 "Move point to the From header."
2406 (message-position-on-field "From"))
2408 (defun message-goto-subject ()
2409 "Move point to the Subject header."
2411 (message-position-on-field "Subject"))
2413 (defun message-goto-cc ()
2414 "Move point to the Cc header."
2416 (message-position-on-field "Cc" "To"))
2418 (defun message-goto-bcc ()
2419 "Move point to the Bcc header."
2421 (message-position-on-field "Bcc" "Cc" "To"))
2423 (defun message-goto-fcc ()
2424 "Move point to the Fcc header."
2426 (message-position-on-field "Fcc" "To" "Newsgroups"))
2428 (defun message-goto-reply-to ()
2429 "Move point to the Reply-To header."
2431 (message-position-on-field "Reply-To" "Subject"))
2433 (defun message-goto-newsgroups ()
2434 "Move point to the Newsgroups header."
2436 (message-position-on-field "Newsgroups"))
2438 (defun message-goto-distribution ()
2439 "Move point to the Distribution header."
2441 (message-position-on-field "Distribution"))
2443 (defun message-goto-followup-to ()
2444 "Move point to the Followup-To header."
2446 (message-position-on-field "Followup-To" "Newsgroups"))
2448 (defun message-goto-mail-followup-to ()
2449 "Move point to the Mail-Followup-To header."
2451 (message-position-on-field "Mail-Followup-To" "From"))
2453 (defun message-goto-keywords ()
2454 "Move point to the Keywords header."
2456 (message-position-on-field "Keywords" "Subject"))
2458 (defun message-goto-summary ()
2459 "Move point to the Summary header."
2461 (message-position-on-field "Summary" "Subject"))
2463 (defun message-goto-body (&optional interactivep)
2464 "Move point to the beginning of the message body."
2465 (interactive (list t))
2466 (when (and interactivep
2467 (looking-at "[ \t]*\n"))
2469 (goto-char (point-min))
2470 (or (search-forward (concat "\n" mail-header-separator "\n") nil t)
2471 (search-forward-regexp "[^:]+:\\([^\n]\\|\n[ \t]\\)+\n\n" nil t)))
2473 (defun message-goto-eoh ()
2474 "Move point to the end of the headers."
2479 (defun message-goto-signature ()
2480 "Move point to the beginning of the message signature.
2481 If there is no signature in the article, go to the end and
2484 (goto-char (point-min))
2485 (if (re-search-forward message-signature-separator nil t)
2487 (goto-char (point-max))
2490 (defun message-generate-unsubscribed-mail-followup-to (&optional include-cc)
2491 "Insert a reasonable MFT header in a post to an unsubscribed list.
2492 When making original posts to a mailing list you are not subscribed to,
2493 you have to type in a MFT header by hand. The contents, usually, are
2494 the addresses of the list and your own address. This function inserts
2495 such a header automatically. It fetches the contents of the To: header
2496 in the current mail buffer, and appends the current `user-mail-address'.
2498 If the optional argument INCLUDE-CC is non-nil, the addresses in the
2499 Cc: header are also put into the MFT."
2502 (message-remove-header "Mail-Followup-To")
2503 (let* ((cc (and include-cc (message-fetch-field "Cc")))
2505 (concat (message-fetch-field "To") "," cc)
2506 (message-fetch-field "To"))))
2507 (message-goto-mail-followup-to)
2508 (insert (concat tos ", " user-mail-address))))
2512 (defun message-insert-to (&optional force)
2513 "Insert a To header that points to the author of the article being replied to.
2514 If the original author requested not to be sent mail, the function signals
2516 With the prefix argument FORCE, insert the header anyway."
2518 (let ((co (message-fetch-reply-field "mail-copies-to")))
2519 (when (and (null force)
2521 (or (equal (downcase co) "never")
2522 (equal (downcase co) "nobody")))
2523 (error "The user has requested not to have copies sent via mail")))
2524 (message-carefully-insert-headers
2526 (or (message-fetch-reply-field "mail-reply-to")
2527 (message-fetch-reply-field "reply-to")
2528 (message-fetch-reply-field "from")
2531 (defun message-insert-wide-reply ()
2532 "Insert To and Cc headers as if you were doing a wide reply."
2534 (let ((headers (message-with-reply-buffer
2535 (message-get-reply-headers t))))
2536 (message-carefully-insert-headers headers)))
2538 (defun message-carefully-insert-headers (headers)
2539 (dolist (header headers)
2540 (let ((header-name (symbol-name (car header))))
2541 (when (and (message-position-on-field header-name)
2542 (mail-fetch-field header-name)
2543 (not (string-match "\\` *\\'"
2544 (mail-fetch-field header-name))))
2546 (insert (cdr header)))))
2548 (defun message-widen-reply ()
2549 "Widen the reply to include maximum recipients."
2552 (and message-reply-buffer
2553 (buffer-name message-reply-buffer)
2555 (set-buffer message-reply-buffer)
2556 (message-get-reply-headers t)))))
2559 (message-narrow-to-headers)
2560 (dolist (elem follow-to)
2561 (message-remove-header (symbol-name (car elem)))
2562 (goto-char (point-min))
2563 (insert (symbol-name (car elem)) ": "
2564 (cdr elem) "\n"))))))
2566 (defun message-insert-newsgroups ()
2567 "Insert the Newsgroups header from the article being replied to."
2569 (when (and (message-position-on-field "Newsgroups")
2570 (mail-fetch-field "newsgroups")
2571 (not (string-match "\\` *\\'" (mail-fetch-field "newsgroups"))))
2573 (insert (or (message-fetch-reply-field "newsgroups") "")))
2577 ;;; Various commands
2579 (defun message-delete-not-region (beg end)
2580 "Delete everything in the body of the current message outside of the region."
2585 ;; snarf citation prefix, if appropriate
2586 (unless (eq (point) (progn (beginning-of-line) (point)))
2587 (when (looking-at message-cite-prefix-regexp)
2588 (setq citeprefix (match-string 0))))
2590 (delete-region (point) (if (not (message-goto-signature))
2596 (delete-region beg (progn (message-goto-body)
2600 (insert citeprefix))))
2601 (when (message-goto-signature)
2604 (defun message-kill-to-signature ()
2605 "Deletes all text up to the signature."
2607 (let ((point (point)))
2608 (message-goto-signature)
2611 (kill-region point (point))
2615 (defun message-newline-and-reformat (&optional arg not-break)
2616 "Insert four newlines, and then reformat if inside quoted text.
2617 Prefix arg means justify as well."
2618 (interactive (list (if current-prefix-arg 'full)))
2619 (let (quoted point beg end leading-space bolp)
2620 (setq point (point))
2623 (setq bolp (= beg point))
2624 ;; Find first line of the paragraph.
2626 (while (and (not (eobp))
2627 (not (looking-at message-cite-prefix-regexp))
2628 (looking-at paragraph-start))
2631 (when (looking-at message-cite-prefix-regexp)
2632 (setq quoted (match-string 0))
2633 (goto-char (match-end 0))
2634 (looking-at "[ \t]*")
2635 (setq leading-space (match-string 0)))
2639 (< (- point beg) (length quoted)))
2640 ;; break inside the cite prefix.
2646 (while (and (not (eobp))
2647 (not (looking-at paragraph-separate))
2648 (looking-at message-cite-prefix-regexp)
2649 (equal quoted (match-string 0)))
2650 (goto-char (match-end 0))
2651 (looking-at "[ \t]*")
2652 (if (> (length leading-space) (length (match-string 0)))
2653 (setq leading-space (match-string 0)))
2657 (while (and (if (bobp) nil (forward-line -1) t)
2658 (not (looking-at paragraph-start))
2659 (looking-at message-cite-prefix-regexp)
2660 (equal quoted (match-string 0)))
2662 (goto-char (match-end 0))
2663 (looking-at "[ \t]*")
2664 (if (> (length leading-space) (length (match-string 0)))
2665 (setq leading-space (match-string 0)))))
2666 (while (and (not (eobp))
2667 (not (looking-at paragraph-separate))
2668 (not (looking-at message-cite-prefix-regexp)))
2672 (while (and (if (bobp) nil (forward-line -1) t)
2673 (not (looking-at paragraph-start))
2674 (not (looking-at message-cite-prefix-regexp)))
2675 (setq beg (point))))
2678 (narrow-to-region beg end)
2685 (setq point (point))
2686 ;; (newline 2) doesn't mark both newline's as hard, so call
2687 ;; newline twice. -jas
2690 (delete-region (point) (re-search-forward "[ \t]*"))
2691 (when (and quoted (not bolp))
2692 (insert quoted leading-space)))
2694 (let* ((adaptive-fill-regexp
2695 (regexp-quote (concat quoted leading-space)))
2696 (adaptive-fill-first-line-regexp
2697 adaptive-fill-regexp ))
2698 (fill-paragraph arg))
2699 (fill-paragraph arg))
2700 (if point (goto-char point)))))
2702 (defun message-fill-paragraph (&optional arg)
2703 "Like `fill-paragraph'."
2704 (interactive (list (if current-prefix-arg 'full)))
2705 (if (and (boundp 'filladapt-mode) filladapt-mode)
2707 (message-newline-and-reformat arg t)
2710 ;; Is it better to use `mail-header-end'?
2711 (defun message-point-in-header-p ()
2712 "Return t if point is in the header."
2715 (goto-char (point-min))
2716 (not (re-search-forward
2717 (concat "^" (regexp-quote mail-header-separator) "\n")
2720 (defun message-do-auto-fill ()
2721 "Like `do-auto-fill', but don't fill in message header."
2722 (unless (message-point-in-header-p)
2725 (defun message-insert-signature (&optional force)
2726 "Insert a signature. See documentation for variable `message-signature'."
2727 (interactive (list 0))
2730 ((and (null message-signature)
2733 (goto-char (point-max))
2734 (not (re-search-backward message-signature-separator nil t))))
2735 ((and (null message-signature)
2738 ((message-functionp message-signature)
2739 (funcall message-signature))
2740 ((listp message-signature)
2741 (eval message-signature))
2742 (t message-signature)))
2744 (cond ((stringp signature)
2746 ((and (eq t signature)
2747 message-signature-file
2748 (file-exists-p message-signature-file))
2751 (goto-char (point-max))
2752 ;; Insert the signature.
2755 (when message-signature-insert-empty-line
2758 (if (eq signature t)
2759 (insert-file-contents message-signature-file)
2761 (goto-char (point-max))
2762 (or (bolp) (insert "\n")))))
2764 (defun message-insert-importance-high ()
2765 "Insert header to mark message as important."
2768 (message-remove-header "Importance")
2770 (insert "Importance: high\n")))
2772 (defun message-insert-importance-low ()
2773 "Insert header to mark message as unimportant."
2776 (message-remove-header "Importance")
2778 (insert "Importance: low\n")))
2780 (defun message-insert-or-toggle-importance ()
2781 "Insert a \"Importance: high\" header, or cycle through the header values.
2782 The three allowed values according to RFC 1327 are `high', `normal'
2786 (let ((valid '("high" "normal" "low"))
2789 (when (setq cur (message-fetch-field "Importance"))
2790 (message-remove-header "Importance")
2791 (setq new (cond ((string= cur "high")
2793 ((string= cur "low")
2798 (insert (format "Importance: %s\n" new)))))
2800 (defun message-insert-disposition-notification-to ()
2801 "Request a disposition notification (return receipt) to this message.
2802 Note that this should not be used in newsgroups."
2805 (message-remove-header "Disposition-Notification-To")
2807 (insert (format "Disposition-Notification-To: %s\n"
2808 (or (message-fetch-field "From") (message-make-from))))))
2810 (defun message-elide-region (b e)
2811 "Elide the text in the region.
2812 An ellipsis (from `message-elide-ellipsis') will be inserted where the
2816 (insert message-elide-ellipsis))
2818 (defvar message-caesar-translation-table nil)
2820 (defun message-caesar-region (b e &optional n)
2821 "Caesar rotate region B to E by N, default 13, for decrypting netnews."
2824 (min (point) (or (mark t) (point)))
2825 (max (point) (or (mark t) (point)))
2826 (when current-prefix-arg
2827 (prefix-numeric-value current-prefix-arg))))
2829 (setq n (if (numberp n) (mod n 26) 13)) ;canonize N
2830 (unless (or (zerop n) ; no action needed for a rot of 0
2831 (= b e)) ; no region to rotate
2832 ;; We build the table, if necessary.
2833 (when (or (not message-caesar-translation-table)
2834 (/= (aref message-caesar-translation-table ?a) (+ ?a n)))
2835 (setq message-caesar-translation-table
2836 (message-make-caesar-translation-table n)))
2837 (translate-region b e message-caesar-translation-table)))
2839 (defun message-make-caesar-translation-table (n)
2840 "Create a rot table with offset N."
2842 (table (make-string 256 0)))
2843 (while (< (incf i) 256)
2846 (substring table 0 ?A)
2847 (substring table (+ ?A n) (+ ?A n (- 26 n)))
2848 (substring table ?A (+ ?A n))
2849 (substring table (+ ?A 26) ?a)
2850 (substring table (+ ?a n) (+ ?a n (- 26 n)))
2851 (substring table ?a (+ ?a n))
2852 (substring table (+ ?a 26) 255))))
2854 (defun message-caesar-buffer-body (&optional rotnum)
2855 "Caesar rotate all letters in the current buffer by 13 places.
2856 Used to encode/decode possibly offensive messages (commonly in rec.humor).
2857 With prefix arg, specifies the number of places to rotate each letter forward.
2858 Mail and USENET news headers are not rotated."
2859 (interactive (if current-prefix-arg
2860 (list (prefix-numeric-value current-prefix-arg))
2864 (when (message-goto-body)
2865 (narrow-to-region (point) (point-max)))
2866 (message-caesar-region (point-min) (point-max) rotnum))))
2868 (defun message-pipe-buffer-body (program)
2869 "Pipe the message body in the current buffer through PROGRAM."
2872 (when (message-goto-body)
2873 (narrow-to-region (point) (point-max)))
2874 (shell-command-on-region
2875 (point-min) (point-max) program nil t))))
2877 (defun message-rename-buffer (&optional enter-string)
2878 "Rename the *message* buffer to \"*message* RECIPIENT\".
2879 If the function is run with a prefix, it will ask for a new buffer
2880 name, rather than giving an automatic name."
2881 (interactive "Pbuffer name: ")
2884 (goto-char (point-min))
2885 (narrow-to-region (point)
2886 (search-forward mail-header-separator nil 'end))
2888 (if (message-news-p) (message-fetch-field "Newsgroups")
2889 (message-fetch-field "To"))
2892 (if (string-match "," mail-to)
2893 (concat (substring mail-to 0 (match-beginning 0)) ", ...")
2895 (name-default (concat "*message* " mail-trimmed-to))
2896 (name (if enter-string
2897 (read-string "New buffer name: " name-default)
2899 (rename-buffer name t)))))
2901 (defun message-fill-yanked-message (&optional justifyp)
2902 "Fill the paragraphs of a message yanked into this one.
2903 Numeric argument means justify as well."
2906 (goto-char (point-min))
2907 (search-forward (concat "\n" mail-header-separator "\n") nil t)
2908 (let ((fill-prefix message-yank-prefix))
2909 (fill-individual-paragraphs (point) (point-max) justifyp))))
2911 (defun message-indent-citation ()
2912 "Modify text just inserted from a message to be cited.
2913 The inserted text should be the region.
2914 When this function returns, the region is again around the modified text.
2916 Normally, indent each nonblank line `message-indentation-spaces' spaces.
2917 However, if `message-yank-prefix' is non-nil, insert that prefix on each line."
2918 (let ((start (point)))
2919 ;; Remove unwanted headers.
2920 (when message-ignored-cited-headers
2925 (if (search-forward "\n\n" nil t)
2928 (message-remove-header message-ignored-cited-headers t)
2929 (when (= (point-min) (point-max))
2930 (setq all-removed t))
2931 (goto-char (point-max)))
2935 ;; Delete blank lines at the start of the buffer.
2936 (while (and (point-min)
2939 (message-delete-line))
2940 ;; Delete blank lines at the end of the buffer.
2941 (goto-char (point-max))
2944 (while (and (zerop (forward-line -1))
2946 (message-delete-line))
2947 ;; Do the indentation.
2948 (if (null message-yank-prefix)
2949 (indent-rigidly start (mark t) message-indentation-spaces)
2952 (while (< (point) (mark t))
2953 (if (or (looking-at ">") (looking-at "^$"))
2954 (insert message-yank-cited-prefix)
2955 (insert message-yank-prefix))
2959 (defun message-yank-original (&optional arg)
2960 "Insert the message being replied to, if any.
2961 Puts point before the text and mark after.
2962 Normally indents each nonblank line ARG spaces (default 3). However,
2963 if `message-yank-prefix' is non-nil, insert that prefix on each line.
2965 This function uses `message-cite-function' to do the actual citing.
2967 Just \\[universal-argument] as argument means don't indent, insert no
2968 prefix, and don't delete any headers."
2970 (let ((modified (buffer-modified-p)))
2971 (when (and message-reply-buffer
2972 message-cite-function)
2973 (delete-windows-on message-reply-buffer t)
2974 (insert-buffer message-reply-buffer)
2976 (funcall message-cite-function))
2977 (message-exchange-point-and-mark)
2981 (setq message-checksum (message-checksum))))))
2983 (defun message-yank-buffer (buffer)
2984 "Insert BUFFER into the current buffer and quote it."
2985 (interactive "bYank buffer: ")
2986 (let ((message-reply-buffer buffer))
2987 (save-window-excursion
2988 (message-yank-original))))
2990 (defun message-buffers ()
2991 "Return a list of active message buffers."
2994 (dolist (buffer (buffer-list t))
2996 (when (and (eq major-mode 'message-mode)
2997 (null message-sent-message-via))
2998 (push (buffer-name buffer) buffers))))
2999 (nreverse buffers)))
3001 (defun message-cite-original-without-signature ()
3002 "Cite function in the standard Message manner."
3003 (let ((start (point))
3006 (when message-indent-citation-function
3007 (if (listp message-indent-citation-function)
3008 message-indent-citation-function
3009 (list message-indent-citation-function)))))
3010 (mml-quote-region start end)
3014 (when (re-search-backward message-signature-separator start t)
3015 ;; Also peel off any blank lines before the signature.
3017 (while (looking-at "^[ \t]*$")
3020 (delete-region (point) end)
3021 (unless (search-backward "\n\n" start t)
3022 ;; Insert a blank line if it is peeled off.
3026 (funcall (pop functions)))
3027 (when message-citation-line-function
3030 (funcall message-citation-line-function))))
3032 (eval-when-compile (defvar mail-citation-hook)) ;Compiler directive
3033 (defun message-cite-original ()
3034 "Cite function in the standard Message manner."
3035 (if (and (boundp 'mail-citation-hook)
3037 (run-hooks 'mail-citation-hook)
3038 (let ((start (point))
3041 (when message-indent-citation-function
3042 (if (listp message-indent-citation-function)
3043 message-indent-citation-function
3044 (list message-indent-citation-function)))))
3045 (mml-quote-region start end)
3048 (funcall (pop functions)))
3049 (when message-citation-line-function
3052 (funcall message-citation-line-function)))))
3054 (defun message-insert-citation-line ()
3055 "Insert a simple citation line."
3056 (when message-reply-headers
3057 (insert (mail-header-from message-reply-headers) " writes:\n\n")))
3059 (defun message-position-on-field (header &rest afters)
3060 (let ((case-fold-search t))
3063 (goto-char (point-min))
3066 (concat "^" (regexp-quote mail-header-separator) "$"))
3067 (match-beginning 0)))
3068 (goto-char (point-min))
3069 (if (re-search-forward (concat "^" (regexp-quote header) ":") nil t)
3071 (re-search-forward "^[^ \t]" nil 'move)
3073 (skip-chars-backward "\n")
3076 (not (re-search-forward
3077 (concat "^" (regexp-quote (car afters)) ":")
3081 (re-search-forward "^[^ \t]" nil 'move)
3082 (beginning-of-line))
3083 (insert header ": \n")
3087 (defun message-remove-signature ()
3088 "Remove the signature from the text between point and mark.
3089 The text will also be indented the normal way."
3091 (let ((start (point))
3093 (if (not (re-search-forward message-signature-separator (mark t) t))
3094 ;; No signature here, so we just indent the cited text.
3095 (message-indent-citation)
3096 ;; Find the last non-empty line.
3098 (while (looking-at "[ \t]*$")
3101 (setq mark (set-marker (make-marker) (point)))
3103 (message-indent-citation)
3104 ;; Enable undoing the deletion.
3106 (delete-region mark (mark t))
3107 (set-marker mark nil)))))
3112 ;;; Sending messages
3115 (defun message-send-and-exit (&optional arg)
3116 "Send message like `message-send', then, if no errors, exit from mail buffer."
3118 (let ((buf (current-buffer))
3119 (actions message-exit-actions))
3120 (when (and (message-send arg)
3122 (if message-kill-buffer-on-exit
3125 (when (eq buf (current-buffer))
3126 (message-bury buf)))
3127 (message-do-actions actions)
3130 (defun message-dont-send ()
3131 "Don't send the message you have been editing.
3132 Instead, just auto-save the buffer and then bury it."
3134 (set-buffer-modified-p t)
3136 (let ((actions message-postpone-actions))
3137 (message-bury (current-buffer))
3138 (message-do-actions actions)))
3140 (defun message-kill-buffer ()
3141 "Kill the current buffer."
3143 (when (or (not (buffer-modified-p))
3144 (yes-or-no-p "Message modified; kill anyway? "))
3145 (let ((actions message-kill-actions)
3146 (draft-article message-draft-article)
3147 (auto-save-file-name buffer-auto-save-file-name)
3148 (file-name buffer-file-name)
3149 (modified (buffer-modified-p)))
3150 (setq buffer-file-name nil)
3151 (kill-buffer (current-buffer))
3152 (when (and (or (and auto-save-file-name
3153 (file-exists-p auto-save-file-name))
3155 (file-exists-p file-name)))
3156 (yes-or-no-p (format "Remove the backup file%s? "
3157 (if modified " too" ""))))
3159 (delete-file auto-save-file-name))
3160 (let ((message-draft-article draft-article))
3161 (message-disassociate-draft)))
3162 (message-do-actions actions))))
3164 (defun message-bury (buffer)
3165 "Bury this mail BUFFER."
3166 (let ((newbuf (other-buffer buffer)))
3167 (bury-buffer buffer)
3168 (if (and (fboundp 'frame-parameters)
3169 (cdr (assq 'dedicated (frame-parameters)))
3170 (not (null (delq (selected-frame) (visible-frame-list)))))
3171 (delete-frame (selected-frame))
3172 (switch-to-buffer newbuf))))
3174 (defun message-send (&optional arg)
3175 "Send the message in the current buffer.
3176 If `message-interactive' is non-nil, wait for success indication or
3177 error messages, and inform user.
3178 Otherwise any failure is reported in a message back to the user from
3180 The usage of ARG is defined by the instance that called Message.
3181 It should typically alter the sending method in some way or other."
3183 ;; Make it possible to undo the coming changes.
3185 (let ((inhibit-read-only t))
3186 (put-text-property (point-min) (point-max) 'read-only nil))
3187 (message-fix-before-sending)
3188 (run-hooks 'message-send-hook)
3189 (message message-sending-message)
3190 (let ((alist message-send-method-alist)
3192 elem sent dont-barf-on-no-method
3193 (message-options message-options))
3194 (message-options-set-recipient)
3196 (setq elem (pop alist)))
3197 (when (funcall (cadr elem))
3198 (when (and (or (not (memq (car elem)
3199 message-sent-message-via))
3200 (not (message-fetch-field "supersedes"))
3201 (if (or (message-gnksa-enable-p 'multiple-copies)
3202 (not (eq (car elem) 'news)))
3205 "Already sent message via %s; resend? "
3207 (error "Denied posting -- multiple copies")))
3208 (setq success (funcall (caddr elem) arg)))
3212 (let ((fcc (message-fetch-field "Fcc"))
3213 (gcc (message-fetch-field "Gcc")))
3215 (or (eq message-allow-no-recipients 'always)
3216 (and (not (eq message-allow-no-recipients 'never))
3217 (setq dont-barf-on-no-method
3219 (format "No receiver, perform %s anyway? "
3220 (cond ((and fcc gcc) "Fcc and Gcc")
3223 (error "No methods specified to send by"))
3224 (when (or dont-barf-on-no-method
3228 (run-hooks 'message-sent-hook))
3229 (message "Sending...done")
3230 ;; Mark the buffer as unmodified and delete auto-save.
3231 (set-buffer-modified-p nil)
3232 (delete-auto-save-file-if-necessary t)
3233 (message-disassociate-draft)
3234 ;; Delete other mail buffers and stuff.
3235 (message-do-send-housekeeping)
3236 (message-do-actions message-send-actions)
3240 (defun message-send-via-mail (arg)
3241 "Send the current message via mail."
3242 (message-send-mail arg))
3244 (defun message-send-via-news (arg)
3245 "Send the current message via news."
3246 (funcall message-send-news-function arg))
3248 (defmacro message-check (type &rest forms)
3249 "Eval FORMS if TYPE is to be checked."
3250 `(or (message-check-element ,type)
3254 (put 'message-check 'lisp-indent-function 1)
3255 (put 'message-check 'edebug-form-spec '(form body))
3257 (defun message-text-with-property (prop)
3258 "Return a list of all points where the text has PROP."
3260 (point (point-min)))
3262 (while (< point (point-max))
3263 (when (get-text-property point prop)
3264 (push point points))
3268 (defun message-fix-before-sending ()
3269 "Do various things to make the message nice before sending it."
3270 ;; Make sure there's a newline at the end of the message.
3271 (goto-char (point-max))
3274 ;; Delete all invisible text.
3275 (message-check 'invisible-text
3276 (let ((points (message-text-with-property 'invisible)))
3278 (goto-char (car points))
3279 (dolist (point points)
3280 (add-text-properties point (1+ point)
3281 '(invisible nil face highlight
3282 font-lock-face highlight)))
3283 (unless (yes-or-no-p
3284 "Invisible text found and made visible; continue posting? ")
3285 (error "Invisible text found and made visible")))))
3286 (message-check 'illegible-text
3289 (skip-chars-forward mm-7bit-chars)
3291 (when (let ((char (char-after)))
3292 (or (< (mm-char-int char) 128)
3293 (and (mm-multibyte-p)
3294 (memq (char-charset char)
3295 '(eight-bit-control eight-bit-graphic
3297 (add-text-properties (point) (1+ (point))
3298 '(font-lock-face highlight face highlight))
3301 (skip-chars-forward mm-7bit-chars))
3304 (gnus-multiple-choice
3305 "Illegible text found. Continue posting?"
3306 '((?d "Remove and continue posting")
3307 (?r "Replace with dots and continue posting")
3308 (?i "Ignore and continue posting")
3309 (?e "Continue editing"))))
3311 (error "Illegible text found"))
3313 (skip-chars-forward mm-7bit-chars)
3315 (when (let ((char (char-after)))
3316 (or (< (mm-char-int char) 128)
3317 (and (mm-multibyte-p)
3318 (memq (char-charset char)
3319 '(eight-bit-control eight-bit-graphic
3322 (remove-text-properties (point) (1+ (point))
3323 '(font-lock-face highlight face highlight))
3325 (when (eq choice ?r)
3328 (skip-chars-forward mm-7bit-chars))))))
3330 (defun message-add-action (action &rest types)
3331 "Add ACTION to be performed when doing an exit of type TYPES."
3333 (add-to-list (intern (format "message-%s-actions" (pop types)))
3336 (defun message-delete-action (action &rest types)
3337 "Delete ACTION from lists of actions performed when doing an exit of type TYPES."
3340 (set (setq var (intern (format "message-%s-actions" (pop types))))
3341 (delq action (symbol-value var))))))
3343 (defun message-do-actions (actions)
3344 "Perform all actions in ACTIONS."
3345 ;; Now perform actions on successful sending.
3349 ;; A simple function.
3350 ((message-functionp (car actions))
3351 (funcall (car actions)))
3352 ;; Something to be evaled.
3354 (eval (car actions)))))
3357 (defun message-send-mail-partially ()
3358 "Send mail as message/partial."
3359 ;; replace the header delimiter with a blank line
3360 (goto-char (point-min))
3362 (concat "^" (regexp-quote mail-header-separator) "\n"))
3363 (replace-match "\n")
3364 (run-hooks 'message-send-mail-hook)
3365 (let ((p (goto-char (point-min)))
3366 (tembuf (message-generate-new-buffer-clone-locals " message temp"))
3367 (curbuf (current-buffer))
3368 (id (message-make-message-id)) (n 1)
3369 plist total header required-mail-headers)
3371 (if (< (point-max) (+ p message-send-mail-partially-limit))
3372 (goto-char (point-max))
3373 (goto-char (+ p message-send-mail-partially-limit))
3375 (if (<= (point) p) (forward-line 1))) ;; In case of bad message.
3378 (setq total (length plist))
3379 (push (point-max) plist)
3380 (setq plist (nreverse plist))
3383 (setq p (pop plist))
3386 (copy-to-buffer tembuf p (car plist))
3388 (goto-char (point-min))
3391 (goto-char (point-min))
3392 (narrow-to-region (point) (point))
3395 (setq header (buffer-substring (point-min) (point)))
3396 (goto-char (point-min))
3397 (narrow-to-region (point) (point))
3399 (message-remove-header "Mime-Version")
3400 (message-remove-header "Content-Type")
3401 (message-remove-header "Content-Transfer-Encoding")
3402 (message-remove-header "Message-ID")
3403 (message-remove-header "Lines")
3404 (goto-char (point-max))
3405 (insert "Mime-Version: 1.0\n")
3406 (setq header (buffer-string)))
3407 (goto-char (point-max))
3408 (insert (format "Content-Type: message/partial; id=\"%s\"; number=%d; total=%d\n\n"
3411 (let ((mail-header-separator ""))
3412 (when (memq 'Message-ID message-required-mail-headers)
3413 (insert "Message-ID: " (message-make-message-id) "\n"))
3414 (when (memq 'Lines message-required-mail-headers)
3415 (insert "Lines: " (message-make-lines) "\n"))
3416 (message-goto-subject)
3418 (insert (format " (%d/%d)" n total))
3420 (mm-with-unibyte-current-buffer
3421 (funcall (or message-send-mail-real-function
3422 message-send-mail-function))))
3424 (setq p (pop plist))
3426 (kill-buffer tembuf))))
3428 (defun message-send-mail (&optional arg)
3429 (require 'mail-utils)
3430 (let* ((tembuf (message-generate-new-buffer-clone-locals " message temp"))
3431 (case-fold-search nil)
3432 (news (message-news-p))
3433 (mailbuf (current-buffer))
3434 (message-this-is-mail t)
3435 (message-posting-charset
3436 (if (fboundp 'gnus-setup-posting-charset)
3437 (gnus-setup-posting-charset nil)
3438 message-posting-charset))
3439 (headers message-required-mail-headers))
3441 (message-narrow-to-headers)
3442 ;; Generate the Mail-Followup-To header if the header is not there...
3443 (if (and (message-subscribed-p)
3444 (not (mail-fetch-field "mail-followup-to")))
3447 (cons "Mail-Followup-To" (message-make-mail-followup-to))
3448 message-required-mail-headers))
3449 ;; otherwise, delete the MFT header if the field is empty
3450 (when (equal "" (mail-fetch-field "mail-followup-to"))
3451 (message-remove-header "^Mail-Followup-To:")))
3452 ;; Insert some headers.
3453 (let ((message-deletable-headers
3454 (if news nil message-deletable-headers)))
3455 (message-generate-headers headers))
3456 ;; Let the user do all of the above.
3457 (run-hooks 'message-header-hook))
3462 ;; Avoid copying text props (except hard newlines).
3463 (insert (with-current-buffer mailbuf
3464 (mml-buffer-substring-no-properties-except-hard-newlines
3465 (point-min) (point-max))))
3466 ;; Remove some headers.
3467 (message-encode-message-body)
3469 (message-narrow-to-headers)
3470 ;; We (re)generate the Lines header.
3471 (when (memq 'Lines message-required-mail-headers)
3472 (message-generate-headers '(Lines)))
3473 ;; Remove some headers.
3474 (message-remove-header message-ignored-mail-headers t)
3475 (let ((mail-parse-charset message-default-charset))
3476 (mail-encode-encoded-word-buffer)))
3477 (goto-char (point-max))
3478 ;; require one newline at the end.
3479 (or (= (preceding-char) ?\n)
3481 (message-cleanup-headers)
3484 (message-narrow-to-headers)
3486 (or (message-fetch-field "cc")
3487 (message-fetch-field "bcc")
3488 (message-fetch-field "to"))
3489 (let ((content-type (message-fetch-field "content-type")))
3492 (string= "text/plain"
3494 (mail-header-parse-content-type
3496 (message-insert-courtesy-copy))
3497 (if (or (not message-send-mail-partially-limit)
3498 (< (point-max) message-send-mail-partially-limit)
3499 (not (message-y-or-n-p
3500 "The message size is too large, split? "
3504 (/ (point-max) 1000) "KB, is too large.
3506 Some mail gateways (MTA's) bounce large messages. To avoid the
3507 problem, answer `y', and the message will be split into several
3508 smaller pieces, the size of each is about "
3509 (/ message-send-mail-partially-limit 1000)
3513 However, some mail readers (MUA's) can't read split messages, i.e.,
3514 mails in message/partially format. Answer `n', and the message will be
3517 The size limit is controlled by `message-send-mail-partially-limit'.
3518 If you always want Gnus to send messages in one piece, set
3519 `message-send-mail-partially-limit' to nil.
3521 (mm-with-unibyte-current-buffer
3522 (message "Sending via mail...")
3523 (funcall (or message-send-mail-real-function
3524 message-send-mail-function)))
3525 (message-send-mail-partially)))
3526 (kill-buffer tembuf))
3527 (set-buffer mailbuf)
3528 (push 'mail message-sent-message-via)))
3530 (defun message-send-mail-with-sendmail ()
3531 "Send off the prepared buffer with sendmail."
3532 (let ((errbuf (if message-interactive
3533 (message-generate-new-buffer-clone-locals
3536 resend-to-addresses delimline)
3539 (let ((case-fold-search t))
3541 (message-narrow-to-headers)
3542 (setq resend-to-addresses (message-fetch-field "resent-to")))
3543 ;; Change header-delimiter to be what sendmail expects.
3544 (goto-char (point-min))
3546 (concat "^" (regexp-quote mail-header-separator) "\n"))
3547 (replace-match "\n")
3549 (setq delimline (point-marker))
3550 (run-hooks 'message-send-mail-hook)
3551 ;; Insert an extra newline if we need it to work around
3552 ;; Sun's bug that swallows newlines.
3553 (goto-char (1+ delimline))
3554 (when (eval message-mailer-swallows-blank-line)
3556 (when message-interactive
3560 (let* ((default-directory "/")
3561 (coding-system-for-write message-send-coding-system)
3563 'call-process-region
3565 (list (point-min) (point-max)
3566 (if (boundp 'sendmail-program)
3568 "/usr/lib/sendmail")
3569 nil errbuf nil "-oi")
3570 ;; Always specify who from,
3571 ;; since some systems have broken sendmails.
3572 ;; But some systems are more broken with -f, so
3573 ;; we'll let users override this.
3574 (if (null message-sendmail-f-is-evil)
3575 (list "-f" (message-sendmail-envelope-from)))
3576 ;; These mean "report errors by mail"
3577 ;; and "deliver in background".
3578 (if (null message-interactive) '("-oem" "-odb"))
3579 ;; Get the addresses from the message
3580 ;; unless this is a resend.
3581 ;; We must not do that for a resend
3582 ;; because we would find the original addresses.
3583 ;; For a resend, include the specific addresses.
3584 (if resend-to-addresses
3585 (list resend-to-addresses)
3587 (unless (or (null cpr) (zerop cpr))
3588 (error "Sending...failed with exit value %d" cpr)))
3589 (when message-interactive
3592 (goto-char (point-min))
3593 (while (re-search-forward "\n\n* *" nil t)
3594 (replace-match "; "))
3595 (if (not (zerop (buffer-size)))
3596 (error "Sending...failed to %s"
3597 (buffer-string))))))
3598 (when (bufferp errbuf)
3599 (kill-buffer errbuf)))))
3601 (defun message-send-mail-with-qmail ()
3602 "Pass the prepared message buffer to qmail-inject.
3603 Refer to the documentation for the variable `message-send-mail-function'
3604 to find out how to use this."
3605 ;; replace the header delimiter with a blank line
3606 (goto-char (point-min))
3608 (concat "^" (regexp-quote mail-header-separator) "\n"))
3609 (replace-match "\n")
3610 (run-hooks 'message-send-mail-hook)
3613 (let ((coding-system-for-write message-send-coding-system))
3615 'call-process-region 1 (point-max) message-qmail-inject-program
3617 ;; qmail-inject's default behaviour is to look for addresses on the
3618 ;; command line; if there're none, it scans the headers.
3619 ;; yes, it does The Right Thing w.r.t. Resent-To and it's kin.
3621 ;; in general, ALL of qmail-inject's defaults are perfect for simply
3622 ;; reading a formatted (i. e., at least a To: or Resent-To header)
3623 ;; message from stdin.
3625 ;; qmail also has the advantage of not having been raped by
3626 ;; various vendors, so we don't have to allow for that, either --
3627 ;; compare this with message-send-mail-with-sendmail and weep
3628 ;; for sendmail's lost innocence.
3630 ;; all this is way cool coz it lets us keep the arguments entirely
3631 ;; free for -inject-arguments -- a big win for the user and for us
3632 ;; since we don't have to play that double-guessing game and the user
3633 ;; gets full control (no gestapo'ish -f's, for instance). --sj
3634 (if (message-functionp message-qmail-inject-args)
3635 (funcall message-qmail-inject-args)
3636 message-qmail-inject-args)))
3637 ;; qmail-inject doesn't say anything on it's stdout/stderr,
3638 ;; we have to look at the retval instead
3640 (100 (error "qmail-inject reported permanent failure"))
3641 (111 (error "qmail-inject reported transient failure"))
3642 ;; should never happen
3643 (t (error "qmail-inject reported unknown failure"))))
3645 (defun message-send-mail-with-mh ()
3646 "Send the prepared message buffer with mh."
3647 (let ((mh-previous-window-config nil)
3648 (name (mh-new-draft-name)))
3649 (setq buffer-file-name name)
3650 ;; MH wants to generate these headers itself.
3651 (when message-mh-deletable-headers
3652 (let ((headers message-mh-deletable-headers))
3654 (goto-char (point-min))
3655 (and (re-search-forward
3656 (concat "^" (symbol-name (car headers)) ": *") nil t)
3657 (message-delete-line))
3659 (run-hooks 'message-send-mail-hook)
3660 ;; Pass it on to mh.
3663 (defun message-smtpmail-send-it ()
3664 "Send the prepared message buffer with `smtpmail-send-it'.
3665 This only differs from `smtpmail-send-it' that this command evaluates
3666 `message-send-mail-hook' just before sending a message. It is useful
3667 if your ISP requires the POP-before-SMTP authentication. See the
3668 documentation for the function `mail-source-touch-pop'."
3669 (run-hooks 'message-send-mail-hook)
3672 (defun message-canlock-generate ()
3673 "Return a string that is non-trival to guess.
3674 Do not use this for anything important, it is cryptographically weak."
3675 (let (sha1-maximum-internal-length)
3676 (sha1 (concat (message-unique-id)
3677 (format "%x%x%x" (random) (random t) (random))
3678 (prin1-to-string (recent-keys))
3679 (prin1-to-string (garbage-collect))))))
3681 (defun message-canlock-password ()
3682 "The password used by message for cancel locks.
3683 This is the value of `canlock-password', if that option is non-nil.
3684 Otherwise, generate and save a value for `canlock-password' first."
3685 (unless canlock-password
3686 (customize-save-variable 'canlock-password (message-canlock-generate))
3687 (setq canlock-password-for-verify canlock-password))
3690 (defun message-insert-canlock ()
3691 (when message-insert-canlock
3692 (message-canlock-password)
3693 (canlock-insert-header)))
3695 (defun message-send-news (&optional arg)
3696 (let* ((tembuf (message-generate-new-buffer-clone-locals " *message temp*"))
3697 (case-fold-search nil)
3698 (method (if (message-functionp message-post-method)
3699 (funcall message-post-method arg)
3700 message-post-method))
3701 (newsgroups-field (save-restriction
3702 (message-narrow-to-headers-or-head)
3703 (message-fetch-field "Newsgroups")))
3704 (followup-field (save-restriction
3705 (message-narrow-to-headers-or-head)
3706 (message-fetch-field "Followup-To")))
3707 ;; BUG: We really need to get the charset for each name in the
3708 ;; Newsgroups and Followup-To lines to allow crossposting
3709 ;; between group namess with incompatible character sets.
3710 ;; -- Per Abrahamsen <abraham@dina.kvl.dk> 2001-10-08.
3711 (group-field-charset
3712 (gnus-group-name-charset method newsgroups-field))
3713 (followup-field-charset
3714 (gnus-group-name-charset method (or followup-field "")))
3715 (rfc2047-header-encoding-alist
3716 (append (when group-field-charset
3717 (list (cons "Newsgroups" group-field-charset)))
3718 (when followup-field-charset
3719 (list (cons "Followup-To" followup-field-charset)))
3720 rfc2047-header-encoding-alist))
3721 (messbuf (current-buffer))
3722 (message-syntax-checks
3724 (listp message-syntax-checks))
3725 (cons '(existing-newsgroups . disabled)
3726 message-syntax-checks)
3727 message-syntax-checks))
3728 (message-this-is-news t)
3729 (message-posting-charset
3730 (gnus-setup-posting-charset newsgroups-field))
3732 (if (not (message-check-news-body-syntax))
3735 (message-narrow-to-headers)
3736 ;; Insert some headers.
3737 (message-generate-headers message-required-news-headers)
3738 (message-insert-canlock)
3739 ;; Let the user do all of the above.
3740 (run-hooks 'message-header-hook))
3741 ;; Note: This check will be disabled by the ".*" default value for
3742 ;; gnus-group-name-charset-group-alist. -- Pa 2001-10-07.
3743 (when (and group-field-charset
3744 (listp message-syntax-checks))
3745 (setq message-syntax-checks
3746 (cons '(valid-newsgroups . disabled)
3747 message-syntax-checks)))
3748 (message-cleanup-headers)
3749 (if (not (let ((message-post-method method))
3750 (message-check-news-syntax)))
3755 (buffer-disable-undo)
3757 ;; Avoid copying text props (except hard newlines).
3759 (with-current-buffer messbuf
3760 (mml-buffer-substring-no-properties-except-hard-newlines
3761 (point-min) (point-max))))
3762 (message-encode-message-body)
3763 ;; Remove some headers.
3765 (message-narrow-to-headers)
3766 ;; We (re)generate the Lines header.
3767 (when (memq 'Lines message-required-mail-headers)
3768 (message-generate-headers '(Lines)))
3769 ;; Remove some headers.
3770 (message-remove-header message-ignored-news-headers t)
3771 (let ((mail-parse-charset message-default-charset))
3772 (mail-encode-encoded-word-buffer)))
3773 (goto-char (point-max))
3774 ;; require one newline at the end.
3775 (or (= (preceding-char) ?\n)
3777 (let ((case-fold-search t))
3778 ;; Remove the delimiter.
3779 (goto-char (point-min))
3781 (concat "^" (regexp-quote mail-header-separator) "\n"))
3782 (replace-match "\n")
3784 (run-hooks 'message-send-news-hook)
3785 (gnus-open-server method)
3786 (message "Sending news via %s..." (gnus-server-string method))
3787 (setq result (let ((mail-header-separator ""))
3788 (gnus-request-post method))))
3789 (kill-buffer tembuf))
3790 (set-buffer messbuf)
3792 (push 'news message-sent-message-via)
3793 (message "Couldn't send message via news: %s"
3794 (nnheader-get-report (car method)))
3798 ;;; Header generation & syntax checking.
3801 (defun message-check-element (type)
3802 "Return non-nil if this TYPE is not to be checked."
3803 (if (eq message-syntax-checks 'dont-check-for-anything-just-trust-me)
3805 (let ((able (assq type message-syntax-checks)))
3807 (eq (cdr able) 'disabled)))))
3809 (defun message-check-news-syntax ()
3810 "Check the syntax of the message."
3814 ;; We narrow to the headers and check them first.
3817 (message-narrow-to-headers)
3818 (message-check-news-header-syntax))))))
3820 (defun message-check-news-header-syntax ()
3822 ;; Check Newsgroups header.
3823 (message-check 'newsgroups
3824 (let ((group (message-fetch-field "newsgroups")))
3827 (not (string-match "\\`[ \t]*\\'" group)))
3830 "The newsgroups field is empty or missing. Posting is denied.")))))
3831 ;; Check the Subject header.
3832 (message-check 'subject
3833 (let* ((case-fold-search t)
3834 (subject (message-fetch-field "subject")))
3837 (not (string-match "\\`[ \t]*\\'" subject)))
3840 "The subject field is empty or missing. Posting is denied.")))))
3841 ;; Check for commands in Subject.
3842 (message-check 'subject-cmsg
3843 (if (string-match "^cmsg " (message-fetch-field "subject"))
3845 "The control code \"cmsg\" is in the subject. Really post? ")
3847 ;; Check long header lines.
3848 (message-check 'long-header-lines
3849 (let ((start (point))
3853 (while (and (not found)
3854 (re-search-forward "^\\([^ \t:]+\\): " nil t))
3855 (if (> (- (point) (match-beginning 0)) 998)
3857 length (- (point) (match-beginning 0)))
3858 (setq header (match-string-no-properties 1)))
3859 (setq start (match-beginning 0))
3862 (y-or-n-p (format "Your %s header is too long (%d). Really post? "
3865 ;; Check for multiple identical headers.
3866 (message-check 'multiple-headers
3868 (while (and (not found)
3869 (re-search-forward "^[^ \t:]+: " nil t))
3871 (or (re-search-forward
3876 (match-beginning 0) (- (match-end 0) 2))))
3881 (y-or-n-p (format "Multiple %s headers. Really post? " found))
3883 ;; Check for Version and Sendsys.
3884 (message-check 'sendsys
3885 (if (re-search-forward "^Sendsys:\\|^Version:" nil t)
3887 (format "The article contains a %s command. Really post? "
3888 (buffer-substring (match-beginning 0)
3889 (1- (match-end 0)))))
3891 ;; See whether we can shorten Followup-To.
3892 (message-check 'shorten-followup-to
3893 (let ((newsgroups (message-fetch-field "newsgroups"))
3894 (followup-to (message-fetch-field "followup-to"))
3896 (when (and newsgroups
3897 (string-match "," newsgroups)
3902 (setq to (completing-read
3903 "Followups to (default: no Followup-To header) "
3904 (mapcar (lambda (g) (list g))
3906 (message-tokenize-header
3908 (goto-char (point-min))
3909 (insert "Followup-To: " to "\n"))
3911 ;; Check "Shoot me".
3912 (message-check 'shoot
3913 (if (re-search-forward
3914 "Message-ID.*.i-did-not-set--mail-host-address--so-tickle-me" nil t)
3915 (y-or-n-p "You appear to have a misconfigured system. Really post? ")
3917 ;; Check for Approved.
3918 (message-check 'approved
3919 (if (re-search-forward "^Approved:" nil t)
3920 (y-or-n-p "The article contains an Approved header. Really post? ")
3922 ;; Check the Message-ID header.
3923 (message-check 'message-id
3924 (let* ((case-fold-search t)
3925 (message-id (message-fetch-field "message-id" t)))
3926 (or (not message-id)
3927 ;; Is there an @ in the ID?
3928 (and (string-match "@" message-id)
3929 ;; Is there a dot in the ID?
3930 (string-match "@[^.]*\\." message-id)
3931 ;; Does the ID end with a dot?
3932 (not (string-match "\\.>" message-id)))
3934 (format "The Message-ID looks strange: \"%s\". Really post? "
3936 ;; Check the Newsgroups & Followup-To headers.
3937 (message-check 'existing-newsgroups
3938 (let* ((case-fold-search t)
3939 (newsgroups (message-fetch-field "newsgroups"))
3940 (followup-to (message-fetch-field "followup-to"))
3941 (groups (message-tokenize-header
3943 (concat newsgroups "," followup-to)
3945 (post-method (if (message-functionp message-post-method)
3946 (funcall message-post-method)
3947 message-post-method))
3948 ;; KLUDGE to handle nnvirtual groups. Doing this right
3949 ;; would probably involve a new nnoo function.
3950 ;; -- Per Abrahamsen <abraham@dina.kvl.dk>, 2001-10-17.
3951 (method (if (and (consp post-method)
3952 (eq (car post-method) 'nnvirtual)
3953 gnus-message-group-art)
3954 (let ((group (car (nnvirtual-find-group-art
3955 (car gnus-message-group-art)
3956 (cdr gnus-message-group-art)))))
3957 (gnus-find-method-for-group group))
3961 (gnus-group-name-decode
3962 (gnus-group-real-name n)
3963 (gnus-group-name-charset method n)))
3964 (gnus-groups-from-server method)))
3967 (when (and (not (equal (car groups) "poster"))
3968 (not (member (car groups) known-groups))
3969 (not (member (car groups) errors)))
3970 (push (car groups) errors))
3973 ;; Gnus is not running.
3974 ((or (not (and (boundp 'gnus-active-hashtb)
3975 gnus-active-hashtb))
3976 (not (boundp 'gnus-read-active-file)))
3978 ;; We don't have all the group names.
3979 ((and (or (not gnus-read-active-file)
3980 (eq gnus-read-active-file 'some))
3984 "Really post to %s possibly unknown group%s: %s? "
3985 (if (= (length errors) 1) "this" "these")
3986 (if (= (length errors) 1) "" "s")
3987 (mapconcat 'identity errors ", "))))
3988 ;; There were no errors.
3991 ;; There are unknown groups.
3995 "Really post to %s unknown group%s: %s? "
3996 (if (= (length errors) 1) "this" "these")
3997 (if (= (length errors) 1) "" "s")
3998 (mapconcat 'identity errors ", ")))))))
3999 ;; Check continuation headers.
4000 (message-check 'continuation-headers
4001 (goto-char (point-min))
4002 (let ((do-posting t))
4003 (while (re-search-forward "^[^ \t\n][^:\n]*$" nil t)
4004 (if (y-or-n-p "Fix continuation lines? ")
4006 (goto-char (match-beginning 0))
4008 (unless (y-or-n-p "Send anyway? ")
4009 (setq do-posting nil))))
4011 ;; Check the Newsgroups & Followup-To headers for syntax errors.
4012 (message-check 'valid-newsgroups
4013 (let ((case-fold-search t)
4014 (headers '("Newsgroups" "Followup-To"))
4016 (while (and headers (not error))
4017 (when (setq header (mail-fetch-field (car headers)))
4021 "\\`\\([-+_&.a-zA-Z0-9]+\\)?\\(,[-+_&.a-zA-Z0-9]+\\)*\\'"
4026 (not (string-match "\\.\\'\\|\\.\\." g)))
4027 (message-tokenize-header header ","))))
4034 (format "The %s header looks odd: \"%s\". Really post? "
4035 (car headers) header)))))
4036 (message-check 'repeated-newsgroups
4037 (let ((case-fold-search t)
4038 (headers '("Newsgroups" "Followup-To"))
4039 header error groups group)
4042 (when (setq header (mail-fetch-field (pop headers)))
4043 (setq groups (message-tokenize-header header ","))
4044 (while (setq group (pop groups))
4045 (when (member group groups)
4051 (format "Group %s is repeated in headers. Really post? " error)))))
4052 ;; Check the From header.
4053 (message-check 'from
4054 (let* ((case-fold-search t)
4055 (from (message-fetch-field "from"))
4059 (message "There is no From line. Posting is denied.")
4061 ((or (not (string-match
4063 (setq ad (nth 1 (mail-extract-address-components
4064 from))))) ;larsi@ifi
4065 (string-match "\\.\\." ad) ;larsi@ifi..uio
4066 (string-match "@\\." ad) ;larsi@.ifi.uio
4067 (string-match "\\.$" ad) ;larsi@ifi.uio.
4068 (not (string-match "^[^@]+@[^@]+$" ad)) ;larsi.ifi.uio
4069 (string-match "(.*).*(.*)" from)) ;(lars) (lars)
4071 "Denied posting -- the From looks strange: \"%s\"." from)
4073 ((let ((addresses (rfc822-addresses from)))
4074 (while (and addresses
4075 (not (eq (string-to-char (car addresses)) ?\()))
4076 (setq addresses (cdr addresses)))
4079 "Denied posting -- bad From address: \"%s\"." from)
4082 ;; Check the Reply-To header.
4083 (message-check 'reply-to
4084 (let* ((case-fold-search t)
4085 (reply-to (message-fetch-field "reply-to"))
4090 ((string-match "," reply-to)
4092 (format "Multiple Reply-To addresses: \"%s\". Really post? "
4094 ((or (not (string-match
4096 (setq ad (nth 1 (mail-extract-address-components
4097 reply-to))))) ;larsi@ifi
4098 (string-match "\\.\\." ad) ;larsi@ifi..uio
4099 (string-match "@\\." ad) ;larsi@.ifi.uio
4100 (string-match "\\.$" ad) ;larsi@ifi.uio.
4101 (not (string-match "^[^@]+@[^@]+$" ad)) ;larsi.ifi.uio
4102 (string-match "(.*).*(.*)" reply-to)) ;(lars) (lars)
4105 "The Reply-To looks strange: \"%s\". Really post? "
4109 (defun message-check-news-body-syntax ()
4111 ;; Check for long lines.
4112 (message-check 'long-lines
4113 (goto-char (point-min))
4115 (concat "^" (regexp-quote mail-header-separator) "$"))
4119 "<#\\(/\\)?\\(multipart\\|part\\|external\\|mml\\)")
4122 (< (- (point) p) 80)))
4123 (zerop (forward-line 1))))
4127 "You have lines longer than 79 characters. Really post? ")))
4128 ;; Check whether the article is empty.
4129 (message-check 'empty
4130 (goto-char (point-min))
4132 (concat "^" (regexp-quote mail-header-separator) "$"))
4135 (goto-char (point-max))
4136 (re-search-backward message-signature-separator nil t)
4138 (or (re-search-backward "[^ \n\t]" b t)
4139 (if (message-gnksa-enable-p 'empty-article)
4140 (y-or-n-p "Empty article. Really post? ")
4141 (message "Denied posting -- Empty article.")
4143 ;; Check for control characters.
4144 (message-check 'control-chars
4145 (if (re-search-forward "[\000-\007\013\015-\032\034-\037\200-\237]" nil t)
4147 "The article contains control characters. Really post? ")
4149 ;; Check excessive size.
4150 (message-check 'size
4151 (if (> (buffer-size) 60000)
4153 (format "The article is %d octets long. Really post? "
4156 ;; Check whether any new text has been added.
4157 (message-check 'new-text
4159 (not message-checksum)
4160 (not (eq (message-checksum) message-checksum))
4161 (if (message-gnksa-enable-p 'quoted-text-only)
4163 "It looks like no new text has been added. Really post? ")
4164 (message "Denied posting -- no new text has been added.")
4166 ;; Check the length of the signature.
4167 (message-check 'signature
4168 (goto-char (point-max))
4169 (if (> (count-lines (point) (point-max)) 5)
4172 "Your .sig is %d lines; it should be max 4. Really post? "
4173 (1- (count-lines (point) (point-max)))))
4175 ;; Ensure that text follows last quoted portion.
4176 (message-check 'quoting-style
4177 (goto-char (point-max))
4178 (let ((no-problem t))
4179 (when (search-backward-regexp "^>[^\n]*\n" nil t)
4180 (setq no-problem (search-forward-regexp "^[ \t]*[^>\n]" nil t)))
4183 (if (message-gnksa-enable-p 'quoted-text-only)
4184 (y-or-n-p "Your text should follow quoted text. Really post? ")
4186 (goto-char (point-min))
4188 (concat "^" (regexp-quote mail-header-separator) "$"))
4189 (if (search-forward-regexp "^[ \t]*[^>\n]" nil t)
4190 (y-or-n-p "Your text should follow quoted text. Really post? ")
4191 (message "Denied posting -- only quoted text.")
4194 (defun message-checksum ()
4195 "Return a \"checksum\" for the current buffer."
4198 (goto-char (point-min))
4200 (concat "^" (regexp-quote mail-header-separator) "$"))
4202 (when (not (looking-at "[ \t\n]"))
4203 (setq sum (logxor (ash sum 1) (if (natnump sum) 0 1)
4208 (defun message-do-fcc ()
4209 "Process Fcc headers in the current buffer."
4210 (let ((case-fold-search t)
4211 (buf (current-buffer))
4213 (mml-externalize-attachments message-fcc-externalize-attachments))
4216 (message-narrow-to-headers)
4217 (setq file (message-fetch-field "fcc" t)))
4219 (set-buffer (get-buffer-create " *message temp*"))
4221 (insert-buffer-substring buf)
4222 (message-encode-message-body)
4224 (message-narrow-to-headers)
4225 (while (setq file (message-fetch-field "fcc" t))
4227 (message-remove-header "fcc" nil t))
4228 (let ((mail-parse-charset message-default-charset)
4229 (rfc2047-header-encoding-alist
4230 (cons '("Newsgroups" . default)
4231 rfc2047-header-encoding-alist)))
4232 (mail-encode-encoded-word-buffer)))
4233 (goto-char (point-min))
4234 (when (re-search-forward
4235 (concat "^" (regexp-quote mail-header-separator) "$")
4237 (replace-match "" t t ))
4238 ;; Process FCC operations.
4240 (setq file (pop list))
4241 (if (string-match "^[ \t]*|[ \t]*\\(.*\\)[ \t]*$" file)
4242 ;; Pipe the article to the program in question.
4243 (call-process-region (point-min) (point-max) shell-file-name
4244 nil nil nil shell-command-switch
4245 (match-string 1 file))
4246 ;; Save the article.
4247 (setq file (expand-file-name file))
4248 (unless (file-exists-p (file-name-directory file))
4249 (make-directory (file-name-directory file) t))
4250 (if (and message-fcc-handler-function
4251 (not (eq message-fcc-handler-function 'rmail-output)))
4252 (funcall message-fcc-handler-function file)
4253 (if (and (file-readable-p file) (mail-file-babyl-p file))
4254 (rmail-output file 1 nil t)
4255 (let ((mail-use-rfc822 t))
4256 (rmail-output file 1 t t))))))
4257 (kill-buffer (current-buffer))))))
4259 (defun message-output (filename)
4260 "Append this article to Unix/babyl mail file FILENAME."
4261 (if (and (file-readable-p filename)
4262 (mail-file-babyl-p filename))
4263 (gnus-output-to-rmail filename t)
4264 (gnus-output-to-mail filename t)))
4266 (defun message-cleanup-headers ()
4267 "Do various automatic cleanups of the headers."
4268 ;; Remove empty lines in the header.
4270 (message-narrow-to-headers)
4271 ;; Remove blank lines.
4272 (while (re-search-forward "^[ \t]*\n" nil t)
4273 (replace-match "" t t))
4275 ;; Correct Newsgroups and Followup-To headers: Change sequence of
4276 ;; spaces to comma and eliminate spaces around commas. Eliminate
4277 ;; embedded line breaks.
4278 (goto-char (point-min))
4279 (while (re-search-forward "^\\(Newsgroups\\|Followup-To\\): +" nil t)
4283 (if (re-search-forward "^[^ \t]" nil t)
4287 (goto-char (point-min))
4288 (while (re-search-forward "\n[ \t]+" nil t)
4289 (replace-match " " t t)) ;No line breaks (too confusing)
4290 (goto-char (point-min))
4291 (while (re-search-forward "[ \t\n]*,[ \t\n]*\\|[ \t]+" nil t)
4292 (replace-match "," t t))
4293 (goto-char (point-min))
4294 ;; Remove trailing commas.
4295 (when (re-search-forward ",+$" nil t)
4296 (replace-match "" t t))))))
4298 (defun message-make-date (&optional now)
4299 "Make a valid data header.
4300 If NOW, use that time instead."
4301 (let* ((now (or now (current-time)))
4302 (zone (nth 8 (decode-time now)))
4306 (setq zone (- zone)))
4308 ;; The day name of the %a spec is locale-specific. Pfff.
4309 (format "%s, " (capitalize (car (rassoc (nth 6 (decode-time now))
4310 parse-time-weekdays))))
4311 (format-time-string "%d" now)
4312 ;; The month name of the %b spec is locale-specific. Pfff.
4314 (capitalize (car (rassoc (nth 4 (decode-time now))
4315 parse-time-months))))
4316 (format-time-string "%Y %H:%M:%S " now)
4317 ;; We do all of this because XEmacs doesn't have the %z spec.
4318 (format "%s%02d%02d" sign (/ zone 3600) (/ (% zone 3600) 60)))))
4320 (defun message-make-message-id ()
4321 "Make a unique Message-ID."
4322 (concat "<" (message-unique-id)
4323 (let ((psubject (save-excursion (message-fetch-field "subject")))
4325 (save-excursion (message-fetch-field "supersedes"))))
4327 (and message-reply-headers
4328 (mail-header-references message-reply-headers)
4329 (mail-header-subject message-reply-headers)
4332 (message-strip-subject-re
4333 (mail-header-subject message-reply-headers))
4334 (message-strip-subject-re psubject))))
4336 (string-match "_-_@" psupersedes)))
4338 "@" (message-make-fqdn) ">"))
4340 (defvar message-unique-id-char nil)
4342 ;; If you ever change this function, make sure the new version
4343 ;; cannot generate IDs that the old version could.
4344 ;; You might for example insert a "." somewhere (not next to another dot
4345 ;; or string boundary), or modify the "fsf" string.
4346 (defun message-unique-id ()
4347 ;; Don't use microseconds from (current-time), they may be unsupported.
4348 ;; Instead we use this randomly inited counter.
4349 (setq message-unique-id-char
4350 (% (1+ (or message-unique-id-char (logand (random t) (1- (lsh 1 20)))))
4351 ;; (current-time) returns 16-bit ints,
4352 ;; and 2^16*25 just fits into 4 digits i base 36.
4354 (let ((tm (current-time)))
4356 (if (memq system-type '(ms-dos emx vax-vms))
4357 (let ((user (downcase (user-login-name))))
4358 (while (string-match "[^a-z0-9_]" user)
4359 (aset user (match-beginning 0) ?_))
4361 (message-number-base36 (user-uid) -1))
4362 (message-number-base36 (+ (car tm)
4363 (lsh (% message-unique-id-char 25) 16)) 4)
4364 (message-number-base36 (+ (nth 1 tm)
4365 (lsh (/ message-unique-id-char 25) 16)) 4)
4366 ;; Append the newsreader name, because while the generated
4367 ;; ID is unique to this newsreader, other newsreaders might
4368 ;; otherwise generate the same ID via another algorithm.
4371 (defun message-number-base36 (num len)
4376 (concat (message-number-base36 (/ num 36) (1- len))
4377 (char-to-string (aref "zyxwvutsrqponmlkjihgfedcba9876543210"
4380 (defun message-make-organization ()
4381 "Make an Organization header."
4382 (let* ((organization
4383 (when message-user-organization
4384 (if (message-functionp message-user-organization)
4385 (funcall message-user-organization)
4386 message-user-organization))))
4388 (message-set-work-buffer)
4389 (cond ((stringp organization)
4390 (insert organization))
4391 ((and (eq t organization)
4392 message-user-organization-file
4393 (file-exists-p message-user-organization-file))
4394 (insert-file-contents message-user-organization-file)))
4395 (goto-char (point-min))
4396 (while (re-search-forward "[\t\n]+" nil t)
4397 (replace-match "" t t))
4398 (unless (zerop (buffer-size))
4401 (defun message-make-lines ()
4402 "Count the number of lines and return numeric string."
4407 (int-to-string (count-lines (point) (point-max))))))
4409 (defun message-make-references ()
4410 "Return the References header for this message."
4411 (when message-reply-headers
4412 (let ((message-id (mail-header-message-id message-reply-headers))
4413 (references (mail-header-references message-reply-headers))
4415 (if (or references message-id)
4416 (concat (or references "") (and references " ")
4420 (defun message-make-in-reply-to ()
4421 "Return the In-Reply-To header for this message."
4422 (when message-reply-headers
4423 (let ((from (mail-header-from message-reply-headers))
4424 (date (mail-header-date message-reply-headers))
4425 (msg-id (mail-header-message-id message-reply-headers)))
4428 (string-match " *at \\| *@ \\| *(\\| *<" from)))
4429 (concat msg-id (if msg-id " (")
4431 (not (zerop stop-pos)))
4432 (substring from 0 stop-pos) from)
4434 (if (or (not date) (string= date ""))
4435 "(unknown date)" date)
4436 "\"" (if msg-id ")")))))))
4438 (defun message-make-distribution ()
4439 "Make a Distribution header."
4440 (let ((orig-distribution (message-fetch-reply-field "distribution")))
4441 (cond ((message-functionp message-distribution-function)
4442 (funcall message-distribution-function))
4443 (t orig-distribution))))
4445 (defun message-make-expires ()
4446 "Return an Expires header based on `message-expires'."
4447 (let ((current (current-time))
4448 (future (* 1.0 message-expires 60 60 24)))
4449 ;; Add the future to current.
4450 (setcar current (+ (car current) (round (/ future (expt 2 16)))))
4451 (setcar (cdr current) (+ (nth 1 current) (% (round future) (expt 2 16))))
4452 (message-make-date current)))
4454 (defun message-make-path ()
4456 (let ((login-name (user-login-name)))
4457 (cond ((null message-user-path)
4458 (concat (system-name) "!" login-name))
4459 ((stringp message-user-path)
4460 ;; Support GENERICPATH. Suggested by vixie@decwrl.dec.com.
4461 (concat message-user-path "!" login-name))
4464 (defun message-make-from ()
4465 "Make a From header."
4466 (let* ((style message-from-style)
4467 (login (message-make-address))
4469 (or (and (boundp 'user-full-name)
4472 (when (string= fullname "&")
4473 (setq fullname (user-login-name)))
4475 (message-set-work-buffer)
4478 (equal fullname ""))
4480 ((or (eq style 'angles)
4481 (and (not (eq style 'parens))
4482 ;; Use angles if no quoting is needed, or if parens would
4483 ;; need quoting too.
4484 (or (not (string-match "[^- !#-'*+/-9=?A-Z^-~]" fullname))
4485 (let ((tmp (concat fullname nil)))
4486 (while (string-match "([^()]*)" tmp)
4487 (aset tmp (match-beginning 0) ?-)
4488 (aset tmp (1- (match-end 0)) ?-))
4489 (string-match "[\\()]" tmp)))))
4491 (insert " <" login ">"))
4492 (t ; 'parens or default
4494 (let ((fullname-start (point)))
4496 (goto-char fullname-start)
4497 ;; RFC 822 says \ and nonmatching parentheses
4498 ;; must be escaped in comments.
4499 ;; Escape every instance of ()\ ...
4500 (while (re-search-forward "[()\\]" nil 1)
4501 (replace-match "\\\\\\&" t))
4502 ;; ... then undo escaping of matching parentheses,
4503 ;; including matching nested parentheses.
4504 (goto-char fullname-start)
4505 (while (re-search-forward
4506 "\\(\\=\\|[^\\]\\(\\\\\\\\\\)*\\)\\\\(\\(\\([^\\]\\|\\\\\\\\\\)*\\)\\\\)"
4508 (replace-match "\\1(\\3)" t)
4509 (goto-char fullname-start)))
4513 (defun message-make-sender ()
4514 "Return the \"real\" user address.
4515 This function tries to ignore all user modifications, and
4516 give as trustworthy answer as possible."
4517 (concat (user-login-name) "@" (system-name)))
4519 (defun message-make-address ()
4520 "Make the address of the user."
4521 (or (message-user-mail-address)
4522 (concat (user-login-name) "@" (message-make-domain))))
4524 (defun message-user-mail-address ()
4525 "Return the pertinent part of `user-mail-address'."
4526 (when (and user-mail-address
4527 (string-match "@.*\\." user-mail-address))
4528 (if (string-match " " user-mail-address)
4529 (nth 1 (mail-extract-address-components user-mail-address))
4530 user-mail-address)))
4532 (defun message-sendmail-envelope-from ()
4533 "Return the envelope from."
4534 (cond ((eq message-sendmail-envelope-from 'header)
4535 (nth 1 (mail-extract-address-components
4536 (message-fetch-field "from"))))
4537 ((stringp message-sendmail-envelope-from)
4538 message-sendmail-envelope-from)
4540 (message-make-address))))
4542 (defun message-make-fqdn ()
4543 "Return user's fully qualified domain name."
4544 (let* ((system-name (system-name))
4545 (user-mail (message-user-mail-address))
4548 (string-match "@\\(.*\\)\\'" user-mail))
4549 (match-string 1 user-mail))))
4551 ((and message-user-fqdn
4552 (stringp message-user-fqdn)
4553 (string-match message-valid-fqdn-regexp message-user-fqdn)
4554 (not (string-match message-bogus-system-names message-user-fqdn)))
4556 ;; `message-user-fqdn' seems to be valid
4557 ((and (string-match message-valid-fqdn-regexp system-name)
4558 (not (string-match message-bogus-system-names system-name)))
4559 ;; `system-name' returned the right result.
4561 ;; Try `mail-host-address'.
4562 ((and (boundp 'mail-host-address)
4563 (stringp mail-host-address)
4564 (string-match message-valid-fqdn-regexp mail-host-address)
4565 (not (string-match message-bogus-system-names mail-host-address)))
4567 ;; We try `user-mail-address' as a backup.
4569 (stringp user-domain)
4570 (string-match message-valid-fqdn-regexp user-domain)
4571 (not (string-match message-bogus-system-names user-domain)))
4573 ;; Default to this bogus thing.
4575 (concat system-name ".i-did-not-set--mail-host-address--so-tickle-me")))))
4577 (defun message-make-host-name ()
4578 "Return the name of the host."
4579 (let ((fqdn (message-make-fqdn)))
4580 (string-match "^[^.]+\\." fqdn)
4581 (substring fqdn 0 (1- (match-end 0)))))
4583 (defun message-make-domain ()
4584 "Return the domain name."
4585 (or mail-host-address
4586 (message-make-fqdn)))
4588 (defun message-to-list-only ()
4589 "Send a message to the list only.
4590 Remove all addresses but the list address from To and Cc headers."
4592 (let ((listaddr (message-make-mail-followup-to t)))
4595 (message-remove-header "to")
4596 (message-remove-header "cc")
4597 (message-position-on-field "To" "X-Draft-From")
4598 (insert listaddr)))))
4600 (defun message-make-mail-followup-to (&optional only-show-subscribed)
4601 "Return the Mail-Followup-To header.
4602 If passed the optional argument ONLY-SHOW-SUBSCRIBED only return the
4603 subscribed address (and not the additional To and Cc header contents)."
4604 (let* ((case-fold-search t)
4605 (to (message-fetch-field "To"))
4606 (cc (message-fetch-field "cc"))
4607 (msg-recipients (concat to (and to cc ", ") cc))
4609 (mapcar 'mail-strip-quoted-names
4610 (message-tokenize-header msg-recipients)))
4612 (if message-subscribed-address-file
4613 (let (begin end item re)
4616 (insert-file-contents message-subscribed-address-file)
4618 (setq begin (point))
4621 (if (bolp) (setq end (1- end)))
4622 (setq item (regexp-quote (buffer-substring begin end)))
4623 (if re (setq re (concat re "\\|" item))
4624 (setq re (concat "\\`\\(" item))))
4625 (and re (list (concat re "\\)\\'"))))))))
4626 (mft-regexps (apply 'append message-subscribed-regexps
4627 (mapcar 'regexp-quote
4628 message-subscribed-addresses)
4631 message-subscribed-address-functions))))
4633 (let ((subscribed-lists nil)
4635 (loop for recipient in recipients
4636 when (loop for regexp in mft-regexps
4637 when (string-match regexp recipient) return t)
4640 (if only-show-subscribed
4642 msg-recipients))))))
4644 (defun message-idna-inside-rhs-p ()
4645 "Return t iff point is inside a RHS (heuristically).
4646 Only works properly if header contains mailbox-list or address-list.
4647 I.e., calling it on a Subject: header is useless."
4648 (if (re-search-backward
4649 "[\\\n\r\t ]" (save-excursion (search-backward "@" nil t)) t)
4650 ;; whitespace between @ and point
4652 (let ((dquote 1) (paren 1))
4653 (while (save-excursion (re-search-backward "[^\\]\"" nil t dquote))
4655 (while (save-excursion (re-search-backward "[^\\]\(" nil t paren))
4657 (and (= (% dquote 2) 1) (= (% paren 2) 1)))))
4659 (autoload 'idna-to-ascii "idna")
4661 (defun message-idna-to-ascii-rhs-1 (header)
4662 "Interactively potentially IDNA encode domain names in HEADER."
4663 (let (rhs ace start end startpos endpos ovl)
4664 (goto-char (point-min))
4665 (setq start (re-search-forward (concat "^" header) nil t)
4666 end (or (save-excursion (re-search-forward "^[ \t]" nil t))
4668 (when (and start end)
4669 (while (re-search-forward "@\\([^ \t\r\n>]+\\)" end t)
4670 (setq rhs (match-string-no-properties 1)
4671 startpos (match-beginning 1)
4672 endpos (match-end 1))
4673 (when (save-match-data
4674 (and (message-idna-inside-rhs-p)
4675 (setq ace (idna-to-ascii rhs))
4676 (not (string= rhs ace))
4677 (if (eq message-use-idna 'ask)
4680 (setq ovl (message-make-overlay startpos
4682 (message-overlay-put ovl 'face 'highlight)
4684 (format "Replace with `%s'? " ace)))
4686 (message-delete-overlay ovl))
4688 (replace-match (concat "@" ace)))))))
4690 (defun message-idna-to-ascii-rhs ()
4691 "Possibly IDNA encode non-ASCII domain names in From:, To: and Cc: headers.
4692 See `message-idna-encode'."
4694 (when message-use-idna
4697 (message-narrow-to-head)
4698 (message-idna-to-ascii-rhs-1 "From")
4699 (message-idna-to-ascii-rhs-1 "To")
4700 (message-idna-to-ascii-rhs-1 "Cc")))))
4702 (defun message-generate-headers (headers)
4703 "Prepare article HEADERS.
4704 Headers already prepared in the buffer are not modified."
4705 (setq headers (append headers message-required-headers))
4707 (message-narrow-to-headers)
4708 (let* ((Date (message-make-date))
4709 (Message-ID (message-make-message-id))
4710 (Organization (message-make-organization))
4711 (From (message-make-from))
4712 (Path (message-make-path))
4715 (In-Reply-To (message-make-in-reply-to))
4716 (References (message-make-references))
4718 (Distribution (message-make-distribution))
4719 (Lines (message-make-lines))
4720 (User-Agent message-newsreader)
4721 (Expires (message-make-expires))
4722 (case-fold-search t)
4725 ;; First we remove any old generated headers.
4726 (let ((headers message-deletable-headers))
4727 (unless (buffer-modified-p)
4728 (setq headers (delq 'Message-ID (copy-sequence headers))))
4730 (goto-char (point-min))
4731 (and (re-search-forward
4732 (concat "^" (symbol-name (car headers)) ": *") nil t)
4733 (get-text-property (1+ (match-beginning 0)) 'message-deletable)
4734 (message-delete-line))
4736 ;; Go through all the required headers and see if they are in the
4737 ;; articles already. If they are not, or are empty, they are
4738 ;; inserted automatically - except for Subject, Newsgroups and
4741 (goto-char (point-min))
4742 (setq elem (pop headers))
4744 (if (eq (car elem) 'optional)
4745 (setq header (cdr elem)
4747 (setq header (car elem)))
4749 (when (or (not (re-search-forward
4753 (if (stringp header)
4755 (symbol-name header))))
4759 ;; The header was found. We insert a space after the
4760 ;; colon, if there is none.
4761 (if (/= (char-after) ? ) (insert " ") (forward-char 1))
4762 ;; Find out whether the header is empty.
4763 (looking-at "[ \t]*\n[^ \t]")))
4764 ;; So we find out what value we should insert.
4768 (eq (car elem) 'optional))
4769 ;; This is an optional header. If the cdr of this
4770 ;; is something that is nil, then we do not insert
4772 (setq header (cdr elem))
4773 (or (and (message-functionp (cdr elem))
4774 (funcall (cdr elem)))
4775 (and (boundp (cdr elem))
4776 (symbol-value (cdr elem)))))
4778 ;; The element is a cons. Either the cdr is a
4779 ;; string to be inserted verbatim, or it is a
4780 ;; function, and we insert the value returned from
4782 (or (and (stringp (cdr elem))
4784 (and (message-functionp (cdr elem))
4785 (funcall (cdr elem)))))
4786 ((and (boundp header)
4787 (symbol-value header))
4788 ;; The element is a symbol. We insert the value
4789 ;; of this symbol, if any.
4790 (symbol-value header))
4791 ((not (message-check-element header))
4792 ;; We couldn't generate a value for this header,
4793 ;; so we just ask the user.
4794 (read-from-minibuffer
4795 (format "Empty header for %s; enter value: " header)))))
4796 ;; Finally insert the header.
4798 (not (equal value "")))
4802 ;; This header didn't exist, so we insert it.
4803 (goto-char (point-max))
4805 (cdr (assq header message-header-format-alist))))
4807 (funcall formatter header value)
4808 (insert (if (stringp header)
4809 header (symbol-name header))
4811 ;; We check whether the value was ended by a
4812 ;; newline. If now, we insert one.
4816 ;; The value of this header was empty, so we clear
4817 ;; totally and insert the new value.
4818 (delete-region (point) (gnus-point-at-eol))
4819 ;; If the header is optional, and the header was
4820 ;; empty, we con't insert it anyway.
4823 ;; Add the deletable property to the headers that require it.
4824 (and (memq header message-deletable-headers)
4825 (progn (beginning-of-line) (looking-at "[^:]+: "))
4826 (add-text-properties
4827 (point) (match-end 0)
4828 '(message-deletable t face italic) (current-buffer)))))))
4829 ;; Insert new Sender if the From is strange.
4830 (let ((from (message-fetch-field "from"))
4831 (sender (message-fetch-field "sender"))
4832 (secure-sender (message-make-sender)))
4834 (not (message-check-element 'sender))
4837 (cadr (mail-extract-address-components from)))
4838 (downcase secure-sender)))
4843 (cadr (mail-extract-address-components sender)))
4844 (downcase secure-sender)))))
4845 (goto-char (point-min))
4846 ;; Rename any old Sender headers to Original-Sender.
4847 (when (re-search-forward "^\\(Original-\\)*Sender:" nil t)
4849 (insert "Original-")
4850 (beginning-of-line))
4851 (when (or (message-news-p)
4852 (string-match "@.+\\.." secure-sender))
4853 (insert "Sender: " secure-sender "\n"))))
4855 (message-idna-to-ascii-rhs))))
4857 (defun message-insert-courtesy-copy ()
4858 "Insert a courtesy message in mail copies of combined messages."
4862 (message-narrow-to-headers)
4863 (when (setq newsgroups (message-fetch-field "newsgroups"))
4864 (goto-char (point-max))
4865 (insert "Posted-To: " newsgroups "\n")))
4867 (when message-courtesy-message
4869 ((string-match "%s" message-courtesy-message)
4870 (insert (format message-courtesy-message newsgroups)))
4872 (insert message-courtesy-message)))))))
4875 ;;; Setting up a message buffer
4878 (defun message-fill-address (header value)
4880 (narrow-to-region (point) (point))
4881 (insert (capitalize (symbol-name header))
4883 (if (consp value) (car value) value)
4885 (narrow-to-region (point-min) (1- (point-max)))
4887 (goto-char (point-min))
4889 (skip-chars-forward "^,\"" (point-max))
4890 (if (or (eq (char-after) ?,)
4893 (if (and (> (current-column) 78)
4899 (setq last (1+ (point))))
4900 (setq last (1+ (point)))))
4901 (setq quoted (not quoted)))
4904 (goto-char (point-max))
4908 (defun message-fill-header (header value)
4909 (let ((begin (point))
4912 (insert (capitalize (symbol-name header))
4914 (if (consp value) (car value) value)
4917 (narrow-to-region begin (point))
4918 (fill-region-as-paragraph begin (point))
4919 ;; Tapdance around looong Message-IDs.
4921 (when (looking-at "[ \t]*$")
4922 (message-delete-line))
4924 (re-search-forward ":" nil t)
4925 (when (looking-at "\n[ \t]+")
4926 (replace-match " " t t))
4927 (goto-char (point-max)))))
4929 (defun message-shorten-1 (list cut surplus)
4930 "Cut SURPLUS elements out of LIST, beginning with CUTth one."
4931 (setcdr (nthcdr (- cut 2) list)
4932 (nthcdr (+ (- cut 2) surplus 1) list)))
4934 (defun message-shorten-references (header references)
4935 "Trim REFERENCES to be 21 Message-ID long or less, and fold them.
4936 If folding is disallowed, also check that the REFERENCES are less
4937 than 988 characters long, and if they are not, trim them until they are."
4944 (goto-char (point-min))
4945 ;; Cons a list of valid references.
4946 (while (re-search-forward "<[^>]+>" nil t)
4947 (push (match-string 0) refs))
4948 (setq refs (nreverse refs)
4949 count (length refs)))
4951 ;; If the list has more than MAXCOUNT elements, trim it by
4952 ;; removing the CUTth element and the required number of
4953 ;; elements that follow.
4954 (when (> count maxcount)
4955 (let ((surplus (- count maxcount)))
4956 (message-shorten-1 refs cut surplus)
4957 (decf count surplus)))
4959 ;; If folding is disallowed, make sure the total length (including
4960 ;; the spaces between) will be less than MAXSIZE characters.
4962 ;; Only disallow folding for News messages. At this point the headers
4963 ;; have not been generated, thus we use message-this-is-news directly.
4964 (when (and message-this-is-news message-cater-to-broken-inn)
4966 (totalsize (+ (apply #'+ (mapcar #'length refs))
4969 (ptr (nthcdr (1- cut) refs)))
4970 ;; Decide how many elements to cut off...
4971 (while (> totalsize maxsize)
4972 (decf totalsize (1+ (length (car ptr))))
4974 (setq ptr (cdr ptr)))
4977 (message-shorten-1 refs cut surplus))))
4979 ;; Finally, collect the references back into a string and insert
4980 ;; it into the buffer.
4981 (let ((refstring (mapconcat #'identity refs " ")))
4982 (if (and message-this-is-news message-cater-to-broken-inn)
4983 (insert (capitalize (symbol-name header)) ": "
4985 (message-fill-header header refstring)))))
4987 (defun message-position-point ()
4988 "Move point to where the user probably wants to find it."
4989 (message-narrow-to-headers)
4991 ((re-search-forward "^[^:]+:[ \t]*$" nil t)
4992 (search-backward ":" )
4995 (if (eq (char-after) ? )
4999 (goto-char (point-max))
5002 (unless (looking-at "$")
5006 (defcustom message-beginning-of-line t
5007 "Whether C-a goes to beginning of header values."
5008 :group 'message-buffers
5011 (defun message-beginning-of-line (&optional n)
5012 "Move point to beginning of header value or to beginning of line."
5014 (let ((zrs 'zmacs-region-stays))
5015 (when (and (interactive-p) (boundp zrs))
5017 (if (and message-beginning-of-line
5018 (message-point-in-header-p))
5019 (let* ((here (point))
5020 (bol (progn (beginning-of-line n) (point)))
5021 (eol (gnus-point-at-eol))
5022 (eoh (re-search-forward ": *" eol t)))
5023 (if (or (not eoh) (equal here eoh))
5026 (beginning-of-line n)))
5028 (defun message-buffer-name (type &optional to group)
5029 "Return a new (unique) buffer name based on TYPE and TO."
5031 ;; Generate a new buffer name The Message Way.
5032 ((eq message-generate-new-buffers 'unique)
5033 (generate-new-buffer-name
5037 (or (car (mail-extract-address-components to))
5040 (if (and group (not (string= group ""))) (concat " on " group) "")
5042 ;; Check whether `message-generate-new-buffers' is a function,
5043 ;; and if so, call it.
5044 ((message-functionp message-generate-new-buffers)
5045 (funcall message-generate-new-buffers type to group))
5046 ((eq message-generate-new-buffers 'unsent)
5047 (generate-new-buffer-name
5048 (concat "*unsent " type
5051 (or (car (mail-extract-address-components to))
5054 (if (and group (not (string= group ""))) (concat " on " group) "")
5056 ;; Use standard name.
5058 (format "*%s message*" type))))
5060 (defun message-pop-to-buffer (name)
5061 "Pop to buffer NAME, and warn if it already exists and is modified."
5062 (let ((buffer (get-buffer name)))
5064 (buffer-name buffer))
5066 (set-buffer (pop-to-buffer buffer))
5067 (when (and (buffer-modified-p)
5069 "Message already being composed; erase? ")))
5070 (error "Message being composed")))
5071 (set-buffer (pop-to-buffer name)))
5075 (defun message-do-send-housekeeping ()
5076 "Kill old message buffers."
5077 ;; We might have sent this buffer already. Delete it from the
5079 (setq message-buffer-list (delq (current-buffer) message-buffer-list))
5080 (while (and message-max-buffers
5082 (>= (length message-buffer-list) message-max-buffers))
5083 ;; Kill the oldest buffer -- unless it has been changed.
5084 (let ((buffer (pop message-buffer-list)))
5085 (when (and (buffer-name buffer)
5086 (not (buffer-modified-p buffer)))
5087 (kill-buffer buffer))))
5088 ;; Rename the buffer.
5089 (if message-send-rename-function
5090 (funcall message-send-rename-function)
5091 ;; Note: mail-abbrevs of XEmacs renames buffer name behind Gnus.
5093 "\\`\\*\\(sent \\|unsent \\)?\\(.+\\)\\*[^\\*]*\\|\\`mail to "
5095 (let ((name (match-string 2 (buffer-name)))
5097 (if (not (or (null name)
5098 (string-equal name "mail")
5099 (string-equal name "posting")))
5100 (setq name (concat "*sent " name "*"))
5101 (message-narrow-to-headers)
5102 (setq to (message-fetch-field "to"))
5103 (setq group (message-fetch-field "newsgroups"))
5107 (to (concat "*sent mail to "
5108 (or (car (mail-extract-address-components to))
5110 ((and group (not (string= group "")))
5111 (concat "*sent posting on " group "*"))
5112 (t "*sent mail*"))))
5113 (unless (string-equal name (buffer-name))
5114 (rename-buffer name t)))))
5115 ;; Push the current buffer onto the list.
5116 (when message-max-buffers
5117 (setq message-buffer-list
5118 (nconc message-buffer-list (list (current-buffer))))))
5120 (defun message-mail-user-agent ()
5122 ((not message-mail-user-agent) nil)
5123 ((eq message-mail-user-agent t) mail-user-agent)
5124 (t message-mail-user-agent))))
5125 (if (memq mua '(message-user-agent gnus-user-agent))
5129 (defun message-setup (headers &optional replybuffer actions switch-function)
5130 (let ((mua (message-mail-user-agent))
5131 subject to field yank-action)
5132 (if (not (and message-this-is-mail mua))
5133 (message-setup-1 headers replybuffer actions)
5135 (setq yank-action (list 'insert-buffer replybuffer)))
5136 (setq headers (copy-sequence headers))
5137 (setq field (assq 'Subject headers))
5139 (setq subject (cdr field))
5140 (setq headers (delq field headers)))
5141 (setq field (assq 'To headers))
5143 (setq to (cdr field))
5144 (setq headers (delq field headers)))
5145 (let ((mail-user-agent mua))
5146 (compose-mail to subject
5147 (mapcar (lambda (item)
5149 (format "%s" (car item))
5152 nil switch-function yank-action actions)))))
5154 (defun message-headers-to-generate (headers included-headers excluded-headers)
5155 "Return a list that includes all headers from HEADERS.
5156 If INCLUDED-HEADERS is a list, just include those headers. If if is
5157 t, include all headers. In any case, headers from EXCLUDED-HEADERS
5161 (dolist (header headers)
5162 (setq header-name (cond
5163 ((and (consp header)
5164 (eq (car header) 'optional))
5165 ;; On the form (optional . Header)
5168 ;; On the form (Header . function)
5173 (when (and (not (memq header-name excluded-headers))
5174 (or (eq included-headers t)
5175 (memq header-name included-headers)))
5176 (push header result)))
5179 (defun message-setup-1 (headers &optional replybuffer actions)
5180 (dolist (action actions)
5182 (add-to-list 'message-send-actions
5183 `(apply ',(car action) ',(cdr action)))))
5184 (setq message-reply-buffer replybuffer)
5185 (goto-char (point-min))
5186 ;; Insert all the headers.
5189 (alist message-header-format-alist))
5191 (unless (assq (caar h) message-header-format-alist)
5192 (push (list (caar h)) alist))
5196 (delete-region (point) (progn (forward-line -1) (point)))
5197 (when message-default-headers
5198 (insert message-default-headers)
5199 (or (bolp) (insert ?\n)))
5203 (insert mail-header-separator "\n")
5207 (when (message-news-p)
5208 (when message-default-news-headers
5209 (insert message-default-news-headers)
5210 (or (bolp) (insert ?\n)))
5211 (when message-generate-headers-first
5212 (message-generate-headers
5213 (message-headers-to-generate
5214 (append message-required-news-headers
5215 message-required-headers)
5216 message-generate-headers-first
5217 '(Lines Subject)))))
5218 (when (message-mail-p)
5219 (when message-default-mail-headers
5220 (insert message-default-mail-headers)
5221 (or (bolp) (insert ?\n)))
5222 (when message-generate-headers-first
5223 (message-generate-headers
5224 (message-headers-to-generate
5225 (append message-required-mail-headers
5226 message-required-headers)
5227 message-generate-headers-first
5228 '(Lines Subject)))))
5229 (run-hooks 'message-signature-setup-hook)
5230 (message-insert-signature)
5232 (message-narrow-to-headers)
5233 (if message-alternative-emails
5234 (message-use-alternative-email-as-from))
5235 (run-hooks 'message-header-setup-hook))
5236 (set-buffer-modified-p nil)
5237 (setq buffer-undo-list nil)
5238 (run-hooks 'message-setup-hook)
5239 (message-position-point)
5242 (defun message-set-auto-save-file-name ()
5243 "Associate the message buffer with a file in the drafts directory."
5244 (when message-auto-save-directory
5245 (unless (file-directory-p
5246 (directory-file-name message-auto-save-directory))
5247 (make-directory message-auto-save-directory t))
5249 (setq message-draft-article
5250 (nndraft-request-associate-buffer "drafts"))
5251 (setq buffer-file-name (expand-file-name
5252 (if (memq system-type
5253 '(ms-dos ms-windows windows-nt
5254 cygwin cygwin32 win32 w32
5258 message-auto-save-directory))
5259 (setq buffer-auto-save-file-name (make-auto-save-file-name)))
5260 (clear-visited-file-modtime)
5261 (setq buffer-file-coding-system message-draft-coding-system)))
5263 (defun message-disassociate-draft ()
5264 "Disassociate the message buffer from the drafts directory."
5265 (when message-draft-article
5266 (nndraft-request-expire-articles
5267 (list message-draft-article) "drafts" nil t)))
5269 (defun message-insert-headers ()
5270 "Generate the headers for the article."
5274 (message-narrow-to-headers)
5275 (when (message-news-p)
5276 (message-generate-headers
5279 (copy-sequence message-required-news-headers)))))
5280 (when (message-mail-p)
5281 (message-generate-headers
5284 (copy-sequence message-required-mail-headers))))))))
5289 ;;; Commands for interfacing with message
5293 (defun message-mail (&optional to subject
5294 other-headers continue switch-function
5295 yank-action send-actions)
5296 "Start editing a mail message to be sent.
5297 OTHER-HEADERS is an alist of header/value pairs."
5299 (let ((message-this-is-mail t) replybuffer)
5300 (unless (message-mail-user-agent)
5301 (message-pop-to-buffer (message-buffer-name "mail" to)))
5302 ;; FIXME: message-mail should do something if YANK-ACTION is not
5304 (and (consp yank-action) (eq (car yank-action) 'insert-buffer)
5305 (setq replybuffer (nth 1 yank-action)))
5308 `((To . ,(or to "")) (Subject . ,(or subject "")))
5309 (when other-headers other-headers))
5310 replybuffer send-actions)
5311 ;; FIXME: Should return nil if failure.
5315 (defun message-news (&optional newsgroups subject)
5316 "Start editing a news article to be sent."
5318 (let ((message-this-is-news t))
5319 (message-pop-to-buffer (message-buffer-name "posting" nil newsgroups))
5320 (message-setup `((Newsgroups . ,(or newsgroups ""))
5321 (Subject . ,(or subject ""))))))
5323 (defun message-get-reply-headers (wide &optional to-address address-headers)
5324 (let (follow-to mct never-mct to cc author mft recipients)
5325 ;; Find all relevant headers we need.
5326 (setq to (message-fetch-field "to")
5327 cc (message-fetch-field "cc")
5328 mct (message-fetch-field "mail-copies-to")
5329 author (or (message-fetch-field "mail-reply-to")
5330 (message-fetch-field "reply-to")
5331 (message-fetch-field "from")
5333 mft (and message-use-mail-followup-to
5334 (message-fetch-field "mail-followup-to")))
5336 ;; Handle special values of Mail-Copies-To.
5338 (cond ((or (equal (downcase mct) "never")
5339 (equal (downcase mct) "nobody"))
5342 ((or (equal (downcase mct) "always")
5343 (equal (downcase mct) "poster"))
5344 (setq mct author))))
5347 ;; Build (textual) list of new recipient addresses.
5350 (setq recipients (concat ", " author)))
5352 (dolist (header address-headers)
5353 (let ((value (message-fetch-field header)))
5355 (setq recipients (concat recipients ", " value))))))
5357 (string-match "[^ \t,]" mft)
5358 (or (not (eq message-use-mail-followup-to 'ask))
5359 (message-y-or-n-p "Obey Mail-Followup-To? " t "\
5360 You should normally obey the Mail-Followup-To: header. In this
5361 article, it has the value of
5365 which directs your response to " (if (string-match "," mft)
5366 "the specified addresses"
5367 "that address only") ".
5369 Most commonly, Mail-Followup-To is used by a mailing list poster to
5370 express that responses should be sent to just the list, and not the
5373 If a message is posted to several mailing lists, Mail-Followup-To may
5374 also be used to direct the following discussion to one list only,
5375 because discussions that are spread over several lists tend to be
5376 fragmented and very difficult to follow.
5378 Also, some source/announcement lists are not intended for discussion;
5379 responses here are directed to other addresses.")))
5380 (setq recipients (concat ", " mft)))
5382 (setq recipients (concat ", " to-address))
5383 ;; If the author explicitly asked for a copy, we don't deny it to them.
5384 (if mct (setq recipients (concat recipients ", " mct))))
5386 (setq recipients (if never-mct "" (concat ", " author)))
5387 (if to (setq recipients (concat recipients ", " to)))
5388 (if cc (setq recipients (concat recipients ", " cc)))
5389 (if mct (setq recipients (concat recipients ", " mct)))))
5390 (if (>= (length recipients) 2)
5391 ;; Strip the leading ", ".
5392 (setq recipients (substring recipients 2)))
5393 ;; Squeeze whitespace.
5394 (while (string-match "[ \t][ \t]+" recipients)
5395 (setq recipients (replace-match " " t t recipients)))
5396 ;; Remove addresses that match `rmail-dont-reply-to-names'.
5397 (let ((rmail-dont-reply-to-names message-dont-reply-to-names))
5398 (setq recipients (rmail-dont-reply-to recipients)))
5399 ;; Perhaps "Mail-Copies-To: never" removed the only address?
5400 (if (string-equal recipients "")
5401 (setq recipients author))
5402 ;; Convert string to a list of (("foo@bar" . "Name <Foo@BAR>") ...).
5406 (cons (downcase (mail-strip-quoted-names addr)) addr))
5407 (message-tokenize-header recipients)))
5408 ;; Remove first duplicates. (Why not all duplicates? Is this a bug?)
5409 (let ((s recipients))
5411 (setq recipients (delq (assoc (car (pop s)) s) recipients))))
5413 ;; Remove hierarchical lists that are contained within each other,
5414 ;; if message-hierarchical-addresses is defined.
5415 (when message-hierarchical-addresses
5416 (let ((plain-addrs (mapcar 'car recipients))
5419 (setq subaddrs (assoc (car plain-addrs)
5420 message-hierarchical-addresses)
5421 plain-addrs (cdr plain-addrs))
5423 (setq subaddrs (cdr subaddrs))
5425 (setq recip (assoc (car subaddrs) recipients)
5426 subaddrs (cdr subaddrs))
5428 (setq recipients (delq recip recipients))))))))
5430 ;; Build the header alist. Allow the user to be asked whether
5431 ;; or not to reply to all recipients in a wide reply.
5432 (setq follow-to (list (cons 'To (cdr (pop recipients)))))
5433 (when (and recipients
5434 (or (not message-wide-reply-confirm-recipients)
5435 (y-or-n-p "Reply to all recipients? ")))
5436 (setq recipients (mapconcat
5437 (lambda (addr) (cdr addr)) recipients ", "))
5438 (if (string-match "^ +" recipients)
5439 (setq recipients (substring recipients (match-end 0))))
5440 (push (cons 'Cc recipients) follow-to)))
5444 (defun message-reply (&optional to-address wide)
5445 "Start editing a reply to the article in the current buffer."
5447 (require 'gnus-sum) ; for gnus-list-identifiers
5448 (let ((cur (current-buffer))
5449 from subject date reply-to to cc
5450 references message-id follow-to
5451 (inhibit-point-motion-hooks t)
5452 (message-this-is-mail t)
5455 (message-narrow-to-head-1)
5456 ;; Allow customizations to have their say.
5458 ;; This is a regular reply.
5459 (when (message-functionp message-reply-to-function)
5461 (setq follow-to (funcall message-reply-to-function))))
5462 ;; This is a followup.
5463 (when (message-functionp message-wide-reply-to-function)
5466 (funcall message-wide-reply-to-function)))))
5467 (setq message-id (message-fetch-field "message-id" t)
5468 references (message-fetch-field "references")
5469 date (message-fetch-field "date")
5470 from (message-fetch-field "from")
5471 subject (or (message-fetch-field "subject") "none"))
5472 (when gnus-list-identifiers
5473 (setq subject (message-strip-list-identifiers subject)))
5474 (setq subject (concat "Re: " (message-strip-subject-re subject)))
5475 (when message-subject-trailing-was-query
5476 (setq subject (message-strip-subject-trailing-was subject)))
5478 (when (and (setq gnus-warning (message-fetch-field "gnus-warning"))
5479 (string-match "<[^>]+>" gnus-warning))
5480 (setq message-id (match-string 0 gnus-warning)))
5483 (setq follow-to (message-get-reply-headers wide to-address))))
5485 (unless (message-mail-user-agent)
5486 (message-pop-to-buffer
5487 (message-buffer-name
5488 (if wide "wide reply" "reply") from
5489 (if wide to-address nil))))
5491 (setq message-reply-headers
5492 (vector 0 subject from date message-id references 0 0 ""))
5495 `((Subject . ,subject)
5500 (defun message-wide-reply (&optional to-address)
5501 "Make a \"wide\" reply to the message in the current buffer."
5503 (message-reply to-address t))
5506 (defun message-followup (&optional to-newsgroups)
5507 "Follow up to the message in the current buffer.
5508 If TO-NEWSGROUPS, use that as the new Newsgroups line."
5510 (require 'gnus-sum) ; for gnus-list-identifiers
5511 (let ((cur (current-buffer))
5512 from subject date reply-to mrt mct
5513 references message-id follow-to
5514 (inhibit-point-motion-hooks t)
5515 (message-this-is-news t)
5516 followup-to distribution newsgroups gnus-warning posted-to)
5519 (goto-char (point-min))
5520 (if (search-forward "\n\n" nil t)
5523 (when (message-functionp message-followup-to-function)
5525 (funcall message-followup-to-function)))
5526 (setq from (message-fetch-field "from")
5527 date (message-fetch-field "date")
5528 subject (or (message-fetch-field "subject") "none")
5529 references (message-fetch-field "references")
5530 message-id (message-fetch-field "message-id" t)
5531 followup-to (message-fetch-field "followup-to")
5532 newsgroups (message-fetch-field "newsgroups")
5533 posted-to (message-fetch-field "posted-to")
5534 reply-to (message-fetch-field "reply-to")
5535 mrt (message-fetch-field "mail-reply-to")
5536 distribution (message-fetch-field "distribution")
5537 mct (message-fetch-field "mail-copies-to"))
5538 (when (and (setq gnus-warning (message-fetch-field "gnus-warning"))
5539 (string-match "<[^>]+>" gnus-warning))
5540 (setq message-id (match-string 0 gnus-warning)))
5541 ;; Remove bogus distribution.
5542 (when (and (stringp distribution)
5543 (let ((case-fold-search t))
5544 (string-match "world" distribution)))
5545 (setq distribution nil))
5546 (if gnus-list-identifiers
5547 (setq subject (message-strip-list-identifiers subject)))
5548 (setq subject (concat "Re: " (message-strip-subject-re subject)))
5549 (when message-subject-trailing-was-query
5550 (setq subject (message-strip-subject-trailing-was subject)))
5553 (message-pop-to-buffer (message-buffer-name "followup" from newsgroups))
5555 (setq message-reply-headers
5556 (vector 0 subject from date message-id references 0 0 ""))
5559 `((Subject . ,subject)
5562 (list (cons 'Newsgroups to-newsgroups)))
5563 (follow-to follow-to)
5564 ((and followup-to message-use-followup-to)
5567 ((equal (downcase followup-to) "poster")
5568 (if (or (eq message-use-followup-to 'use)
5569 (message-y-or-n-p "Obey Followup-To: poster? " t "\
5570 You should normally obey the Followup-To: header.
5572 `Followup-To: poster' sends your response via e-mail instead of news.
5574 A typical situation where `Followup-To: poster' is used is when the poster
5575 does not read the newsgroup, so he wouldn't see any replies sent to it."))
5577 (setq message-this-is-news nil)
5578 (cons 'To (or mrt reply-to from "")))
5579 (cons 'Newsgroups newsgroups)))
5581 (if (or (equal followup-to newsgroups)
5582 (not (eq message-use-followup-to 'ask))
5584 (concat "Obey Followup-To: " followup-to "? ") t "\
5585 You should normally obey the Followup-To: header.
5587 `Followup-To: " followup-to "'
5588 directs your response to " (if (string-match "," followup-to)
5589 "the specified newsgroups"
5590 "that newsgroup only") ".
5592 If a message is posted to several newsgroups, Followup-To is often
5593 used to direct the following discussion to one newsgroup only,
5594 because discussions that are spread over several newsgroup tend to
5595 be fragmented and very difficult to follow.
5597 Also, some source/announcement newsgroups are not intended for discussion;
5598 responses here are directed to other newsgroups."))
5599 (cons 'Newsgroups followup-to)
5600 (cons 'Newsgroups newsgroups))))))
5602 `((Newsgroups . ,posted-to)))
5604 `((Newsgroups . ,newsgroups))))
5605 ,@(and distribution (list (cons 'Distribution distribution)))
5607 (not (or (equal (downcase mct) "never")
5608 (equal (downcase mct) "nobody"))))
5609 (list (cons 'Cc (if (or (equal (downcase mct) "always")
5610 (equal (downcase mct) "poster"))
5611 (or mrt reply-to from "")
5618 (defun message-cancel-news (&optional arg)
5619 "Cancel an article you posted.
5620 If ARG, allow editing of the cancellation message."
5622 (unless (message-news-p)
5623 (error "This is not a news article; canceling is impossible"))
5624 (let (from newsgroups message-id distribution buf sender)
5626 ;; Get header info from original article.
5628 (message-narrow-to-head-1)
5629 (setq from (message-fetch-field "from")
5630 sender (message-fetch-field "sender")
5631 newsgroups (message-fetch-field "newsgroups")
5632 message-id (message-fetch-field "message-id" t)
5633 distribution (message-fetch-field "distribution")))
5634 ;; Make sure that this article was written by the user.
5636 ;; Canlock-logic as suggested by Per Abrahamsen
5637 ;; <abraham@dina.kvl.dk>
5639 ;; IF article has cancel-lock THEN
5640 ;; IF we can verify it THEN
5643 ;; error: cancellock: article is not yours
5645 ;; Use old rules, comparing sender...
5646 (if (message-fetch-field "Cancel-Lock")
5647 (if (null (canlock-verify))
5649 (error "Failed to verify Cancel-lock: This article is not yours"))
5651 (message-gnksa-enable-p 'cancel-messages)
5655 (downcase (message-make-sender))))
5657 (downcase (cadr (mail-extract-address-components from)))
5658 (downcase (cadr (mail-extract-address-components
5659 (message-make-from))))))
5660 (error "This article is not yours"))
5661 (when (yes-or-no-p "Do you really want to cancel this article? ")
5662 ;; Make control message.
5665 (setq buf (set-buffer (get-buffer-create " *message cancel*"))))
5667 (insert "Newsgroups: " newsgroups "\n"
5669 "Subject: cmsg cancel " message-id "\n"
5670 "Control: cancel " message-id "\n"
5672 (concat "Distribution: " distribution "\n")
5674 mail-header-separator "\n"
5675 message-cancel-message)
5676 (run-hooks 'message-cancel-hook)
5678 (message "Canceling your article...")
5679 (if (let ((message-syntax-checks
5680 'dont-check-for-anything-just-trust-me))
5681 (funcall message-send-news-function))
5682 (message "Canceling your article...done"))
5683 (kill-buffer buf))))))
5686 (defun message-supersede ()
5687 "Start composing a message to supersede the current message.
5688 This is done simply by taking the old article and adding a Supersedes
5689 header line with the old Message-ID."
5691 (let ((cur (current-buffer))
5692 (sender (message-fetch-field "sender"))
5693 (from (message-fetch-field "from")))
5694 ;; Check whether the user owns the article that is to be superseded.
5696 ;; Canlock-logic as suggested by Per Abrahamsen
5697 ;; <abraham@dina.kvl.dk>
5699 ;; IF article has cancel-lock THEN
5700 ;; IF we can verify it THEN
5703 ;; error: cancellock: article is not yours
5705 ;; Use old rules, comparing sender...
5706 (if (message-fetch-field "Cancel-Lock")
5707 (if (null (canlock-verify))
5709 (error "Failed to verify Cancel-lock: This article is not yours"))
5711 (message-gnksa-enable-p 'cancel-messages)
5715 (downcase (message-make-sender))))
5717 (downcase (cadr (mail-extract-address-components from)))
5718 (downcase (cadr (mail-extract-address-components
5719 (message-make-from))))))
5720 (error "This article is not yours"))
5721 ;; Get a normal message buffer.
5722 (message-pop-to-buffer (message-buffer-name "supersede"))
5723 (insert-buffer-substring cur)
5725 (message-narrow-to-head-1)
5726 ;; Remove unwanted headers.
5727 (when message-ignored-supersedes-headers
5728 (message-remove-header message-ignored-supersedes-headers t))
5729 (goto-char (point-min))
5730 (if (not (re-search-forward "^Message-ID: " nil t))
5731 (error "No Message-ID in this article")
5732 (replace-match "Supersedes: " t t))
5733 (goto-char (point-max))
5734 (insert mail-header-separator)
5739 (defun message-recover ()
5740 "Reread contents of current buffer from its last auto-save file."
5742 (let ((file-name (make-auto-save-file-name)))
5743 (cond ((save-window-excursion
5744 (if (not (eq system-type 'vax-vms))
5745 (with-output-to-temp-buffer "*Directory*"
5746 (with-current-buffer standard-output
5747 (fundamental-mode)) ; for Emacs 20.4+
5748 (buffer-disable-undo standard-output)
5749 (let ((default-directory "/"))
5751 "ls" nil standard-output nil "-l" file-name))))
5752 (yes-or-no-p (format "Recover auto save file %s? " file-name)))
5753 (let ((buffer-read-only nil))
5755 (insert-file-contents file-name nil)))
5756 (t (error "message-recover cancelled")))))
5758 ;;; Washing Subject:
5760 (defun message-wash-subject (subject)
5761 "Remove junk like \"Re:\", \"(fwd)\", etc. added to subject string SUBJECT.
5762 Previous forwarders, replyers, etc. may add it."
5765 (goto-char (point-min))
5766 ;; strip Re/Fwd stuff off the beginning
5767 (while (re-search-forward
5768 "\\([Rr][Ee]:\\|[Ff][Ww][Dd]\\(\\[[0-9]*\\]\\)?:\\|[Ff][Ww]:\\)" nil t)
5771 ;; and gnus-style forwards [foo@bar.com] subject
5772 (goto-char (point-min))
5773 (while (re-search-forward "\\[[^ \t]*\\(@\\|\\.\\)[^ \t]*\\]" nil t)
5777 (goto-char (point-max))
5778 (while (re-search-backward "([Ff][Ww][Dd])" nil t)
5781 ;; and finally, any whitespace that was left-over
5782 (goto-char (point-min))
5783 (while (re-search-forward "^[ \t]+" nil t)
5785 (goto-char (point-max))
5786 (while (re-search-backward "[ \t]+$" nil t)
5791 ;;; Forwarding messages.
5793 (defvar message-forward-decoded-p nil
5794 "Non-nil means the original message is decoded.")
5796 (defun message-forward-subject-author-subject (subject)
5797 "Generate a SUBJECT for a forwarded message.
5798 The form is: [Source] Subject, where if the original message was mail,
5799 Source is the sender, and if the original message was news, Source is
5800 the list of newsgroups is was posted to."
5803 (or (message-fetch-field "newsgroups")
5804 (message-fetch-field "from")
5806 (if message-forward-decoded-p
5808 (mail-decode-encoded-word-string prefix)))
5811 (defun message-forward-subject-fwd (subject)
5812 "Generate a SUBJECT for a forwarded message.
5813 The form is: Fwd: Subject, where Subject is the original subject of
5815 (concat "Fwd: " subject))
5817 (defun message-make-forward-subject ()
5818 "Return a Subject header suitable for the message in the current buffer."
5821 (message-narrow-to-head-1)
5822 (let ((funcs message-make-forward-subject-function)
5823 (subject (message-fetch-field "Subject")))
5826 (if message-forward-decoded-p
5828 (mail-decode-encoded-word-string subject))
5830 (if message-wash-forwarded-subjects
5831 (setq subject (message-wash-subject subject)))
5832 ;; Make sure funcs is a list.
5835 (setq funcs (list funcs)))
5836 ;; Apply funcs in order, passing subject generated by previous
5837 ;; func to the next one.
5839 (when (message-functionp (car funcs))
5840 (setq subject (funcall (car funcs) subject)))
5841 (setq funcs (cdr funcs)))
5845 (defvar gnus-article-decoded-p))
5849 (defun message-forward (&optional news digest)
5850 "Forward the current message via mail.
5851 Optional NEWS will use news to forward instead of mail.
5852 Optional DIGEST will use digest to forward."
5854 (let* ((cur (current-buffer))
5855 (message-forward-decoded-p
5856 (if (local-variable-p 'gnus-article-decoded-p (current-buffer))
5857 gnus-article-decoded-p ;; In an article buffer.
5858 message-forward-decoded-p))
5859 (subject (message-make-forward-subject)))
5861 (message-news nil subject)
5862 (message-mail nil subject))
5863 (message-forward-make-body cur digest)))
5866 (defun message-forward-make-body (forward-buffer &optional digest)
5867 ;; Put point where we want it before inserting the forwarded
5869 (if message-forward-before-signature
5871 (goto-char (point-max)))
5872 (if message-forward-as-mime
5874 (insert "\n<#multipart type=digest>\n")
5875 (if message-forward-show-mml
5876 (insert "\n\n<#mml type=message/rfc822 disposition=inline>\n")
5877 (insert "\n\n<#part type=message/rfc822 disposition=inline raw=t>\n")))
5878 (insert "\n-------------------- Start of forwarded message --------------------\n"))
5879 (let ((b (point)) e)
5881 (if message-forward-as-mime
5882 (insert-buffer-substring forward-buffer)
5883 (mml-insert-buffer forward-buffer))
5884 (if (and message-forward-show-mml
5885 (not message-forward-decoded-p))
5888 (mm-disable-multibyte-mule4)
5890 (with-current-buffer forward-buffer
5891 (mm-with-unibyte-current-buffer-mule4 (buffer-string))))
5892 (mm-enable-multibyte-mule4)
5894 (goto-char (point-min))
5895 (when (looking-at "From ")
5896 (replace-match "X-From-Line: "))
5899 (narrow-to-region (point) (point))
5900 (mml-insert-buffer forward-buffer)
5901 (goto-char (point-min))
5902 (when (looking-at "From ")
5903 (replace-match "X-From-Line: "))
5904 (goto-char (point-max)))))
5906 (if message-forward-as-mime
5908 (insert "<#/multipart>\n")
5909 (if message-forward-show-mml
5910 (insert "<#/mml>\n")
5911 (insert "<#/part>\n")))
5912 (insert "\n-------------------- End of forwarded message --------------------\n"))
5913 (if (and digest message-forward-as-mime)
5915 (narrow-to-region b e)
5917 (narrow-to-region (point)
5918 (or (search-forward "\n\n" nil t) (point)))
5919 (delete-region (point-min) (point-max)))
5920 (when (and (not current-prefix-arg)
5921 message-forward-ignored-headers
5922 ;; don't remove CTE, X-Gnus etc when doing "raw" forward:
5923 message-forward-show-mml)
5925 (narrow-to-region b e)
5927 (narrow-to-region (point)
5928 (or (search-forward "\n\n" nil t) (point)))
5929 (message-remove-header message-forward-ignored-headers t)))))
5930 (message-position-point))
5933 (defun message-forward-rmail-make-body (forward-buffer)
5934 (save-window-excursion
5935 (set-buffer forward-buffer)
5936 ;; Rmail doesn't have rmail-msg-restore-non-pruned-header in Emacs
5937 ;; 20. FIXIT, or we drop support for rmail in Emacs 20.
5938 (if (rmail-msg-is-pruned)
5939 (rmail-msg-restore-non-pruned-header)))
5940 (message-forward-make-body forward-buffer))
5943 (defun message-insinuate-rmail ()
5944 "Let RMAIL uses message to forward."
5946 (setq rmail-enable-mime-composing t)
5947 (setq rmail-insert-mime-forwarded-message-function
5948 'message-forward-rmail-make-body))
5951 (defun message-resend (address)
5952 "Resend the current article to ADDRESS."
5954 (list (message-read-from-minibuffer "Resend message to: ")))
5955 (message "Resending message to %s..." address)
5957 (let ((cur (current-buffer))
5959 ;; We first set up a normal mail buffer.
5960 (unless (message-mail-user-agent)
5961 (set-buffer (get-buffer-create " *message resend*"))
5963 (let ((message-this-is-mail t)
5965 (message-setup `((To . ,address))))
5966 ;; Insert our usual headers.
5967 (message-generate-headers '(From Date To))
5968 (message-narrow-to-headers)
5969 ;; Remove X-Draft-From header etc.
5970 (message-remove-header message-ignored-mail-headers t)
5971 ;; Rename them all to "Resent-*".
5972 (goto-char (point-min))
5973 (while (re-search-forward "^[A-Za-z]" nil t)
5978 (delete-region (point) (point-max))
5980 ;; Insert the message to be resent.
5981 (insert-buffer-substring cur)
5982 (goto-char (point-min))
5983 (search-forward "\n\n")
5986 (narrow-to-region beg (point))
5987 (message-remove-header message-ignored-resent-headers t)
5988 (goto-char (point-max)))
5989 (insert mail-header-separator)
5990 ;; Rename all old ("Also-")Resent headers.
5991 (while (re-search-backward "^\\(Also-\\)*Resent-" beg t)
5994 ;; Quote any "From " lines at the beginning.
5996 (when (looking-at "From ")
5997 (replace-match "X-From-Line: "))
5999 (let ((message-inhibit-body-encoding t)
6000 message-required-mail-headers)
6001 (message-send-mail))
6002 (kill-buffer (current-buffer)))
6003 (message "Resending message to %s...done" address)))
6006 (defun message-bounce ()
6007 "Re-mail the current message.
6008 This only makes sense if the current message is a bounce message that
6009 contains some mail you have written which has been bounced back to
6012 (let ((handles (mm-dissect-buffer t))
6014 (message-pop-to-buffer (message-buffer-name "bounce"))
6015 (if (stringp (car handles))
6016 ;; This is a MIME bounce.
6017 (mm-insert-part (car (last handles)))
6018 ;; This is a non-MIME bounce, so we try to remove things
6020 (mm-insert-part handles)
6022 (goto-char (point-min))
6023 (search-forward "\n\n" nil t)
6024 (if (or (and (re-search-forward message-unsent-separator nil t)
6026 (re-search-forward "^Return-Path:.*\n" nil t))
6027 ;; We remove everything before the bounced mail.
6030 (if (re-search-forward "^[^ \n\t]+:" nil t)
6033 (when (re-search-backward "^.?From .*\n" nil t)
6034 (delete-region (match-beginning 0) (match-end 0)))))
6035 (mm-enable-multibyte)
6038 (message-narrow-to-head-1)
6039 (message-remove-header message-ignored-bounced-headers t)
6040 (goto-char (point-max))
6041 (insert mail-header-separator))
6042 (message-position-point)))
6045 ;;; Interactive entry points for new message buffers.
6049 (defun message-mail-other-window (&optional to subject)
6050 "Like `message-mail' command, but display mail buffer in another window."
6052 (unless (message-mail-user-agent)
6053 (let ((pop-up-windows t)
6054 (special-display-buffer-names nil)
6055 (special-display-regexps nil)
6056 (same-window-buffer-names nil)
6057 (same-window-regexps nil))
6058 (message-pop-to-buffer (message-buffer-name "mail" to))))
6059 (let ((message-this-is-mail t))
6060 (message-setup `((To . ,(or to "")) (Subject . ,(or subject "")))
6061 nil nil 'switch-to-buffer-other-window)))
6064 (defun message-mail-other-frame (&optional to subject)
6065 "Like `message-mail' command, but display mail buffer in another frame."
6067 (unless (message-mail-user-agent)
6068 (let ((pop-up-frames t)
6069 (special-display-buffer-names nil)
6070 (special-display-regexps nil)
6071 (same-window-buffer-names nil)
6072 (same-window-regexps nil))
6073 (message-pop-to-buffer (message-buffer-name "mail" to))))
6074 (let ((message-this-is-mail t))
6075 (message-setup `((To . ,(or to "")) (Subject . ,(or subject "")))
6076 nil nil 'switch-to-buffer-other-frame)))
6079 (defun message-news-other-window (&optional newsgroups subject)
6080 "Start editing a news article to be sent."
6082 (let ((pop-up-windows t)
6083 (special-display-buffer-names nil)
6084 (special-display-regexps nil)
6085 (same-window-buffer-names nil)
6086 (same-window-regexps nil))
6087 (message-pop-to-buffer (message-buffer-name "posting" nil newsgroups)))
6088 (let ((message-this-is-news t))
6089 (message-setup `((Newsgroups . ,(or newsgroups ""))
6090 (Subject . ,(or subject ""))))))
6093 (defun message-news-other-frame (&optional newsgroups subject)
6094 "Start editing a news article to be sent."
6096 (let ((pop-up-frames t)
6097 (special-display-buffer-names nil)
6098 (special-display-regexps nil)
6099 (same-window-buffer-names nil)
6100 (same-window-regexps nil))
6101 (message-pop-to-buffer (message-buffer-name "posting" nil newsgroups)))
6102 (let ((message-this-is-news t))
6103 (message-setup `((Newsgroups . ,(or newsgroups ""))
6104 (Subject . ,(or subject ""))))))
6108 ;; This code should be moved to underline.el (from which it is stolen).
6111 (defun bold-region (start end)
6112 "Bold all nonblank characters in the region.
6113 Works by overstriking characters.
6114 Called from program, takes two arguments START and END
6115 which specify the range to operate on."
6118 (let ((end1 (make-marker)))
6119 (move-marker end1 (max start end))
6120 (goto-char (min start end))
6121 (while (< (point) end1)
6122 (or (looking-at "[_\^@- ]")
6123 (insert (char-after) "\b"))
6124 (forward-char 1)))))
6127 (defun unbold-region (start end)
6128 "Remove all boldness (overstruck characters) in the region.
6129 Called from program, takes two arguments START and END
6130 which specify the range to operate on."
6133 (let ((end1 (make-marker)))
6134 (move-marker end1 (max start end))
6135 (goto-char (min start end))
6136 (while (re-search-forward "\b" end1 t)
6137 (if (eq (char-after) (char-after (- (point) 2)))
6138 (delete-char -2))))))
6140 (defalias 'message-exchange-point-and-mark 'exchange-point-and-mark)
6141 (defalias 'message-make-overlay 'make-overlay)
6142 (defalias 'message-delete-overlay 'delete-overlay)
6143 (defalias 'message-overlay-put 'overlay-put)
6145 ;; Support for toolbar
6147 (defvar tool-bar-map)
6148 (defvar tool-bar-mode))
6150 (defun message-tool-bar-local-item-from-menu (command icon in-map &optional from-map &rest props)
6151 ;; We need to make tool bar entries in local keymaps with
6152 ;; `tool-bar-local-item-from-menu' in Emacs > 21.3
6153 (if (fboundp 'tool-bar-local-item-from-menu)
6154 ;; This is for Emacs 21.3
6155 (tool-bar-local-item-from-menu command icon in-map from-map props)
6156 (tool-bar-add-item-from-menu command icon from-map props)))
6158 (defun message-tool-bar-map ()
6159 (or message-tool-bar-map
6160 (setq message-tool-bar-map
6162 (condition-case nil (require 'tool-bar) (error nil))
6163 (fboundp 'tool-bar-add-item-from-menu)
6165 (let ((tool-bar-map (copy-keymap tool-bar-map))
6166 (load-path (mm-image-load-path)))
6167 ;; Zap some items which aren't so relevant and take
6169 (dolist (key '(print-buffer kill-buffer save-buffer
6170 write-file dired open-file))
6171 (define-key tool-bar-map (vector key) nil))
6172 (message-tool-bar-local-item-from-menu
6173 'message-send-and-exit "mail_send" tool-bar-map message-mode-map)
6174 (message-tool-bar-local-item-from-menu
6175 'message-kill-buffer "close" tool-bar-map message-mode-map)
6176 (message-tool-bar-local-item-from-menu
6177 'message-dont-send "cancel" tool-bar-map message-mode-map)
6178 (message-tool-bar-local-item-from-menu
6179 'mml-attach-file "attach" tool-bar-map mml-mode-map)
6180 (message-tool-bar-local-item-from-menu
6181 'ispell-message "spell" tool-bar-map message-mode-map)
6182 (message-tool-bar-local-item-from-menu
6183 'mml-preview "preview"
6184 tool-bar-map mml-mode-map)
6185 (message-tool-bar-local-item-from-menu
6186 'message-insert-importance-high "important"
6187 tool-bar-map message-mode-map)
6188 (message-tool-bar-local-item-from-menu
6189 'message-insert-importance-low "unimportant"
6190 tool-bar-map message-mode-map)
6191 (message-tool-bar-local-item-from-menu
6192 'message-insert-disposition-notification-to "receipt"
6193 tool-bar-map message-mode-map)
6196 ;;; Group name completion.
6198 (defcustom message-newgroups-header-regexp
6199 "^\\(Newsgroups\\|Followup-To\\|Posted-To\\|Gcc\\):"
6200 "Regexp that match headers that lists groups."
6204 (defcustom message-completion-alist
6205 (list (cons message-newgroups-header-regexp 'message-expand-group)
6206 '("^\\(Resent-\\)?\\(To\\|B?Cc\\):" . message-expand-name)
6207 '("^\\(Reply-To\\|From\\|Mail-Followup-To\\|Mail-Copies-To\\):"
6208 . message-expand-name)
6209 '("^\\(Disposition-Notification-To\\|Return-Receipt-To\\):"
6210 . message-expand-name))
6211 "Alist of (RE . FUN). Use FUN for completion on header lines matching RE."
6213 :type '(alist :key-type regexp :value-type function))
6215 (defcustom message-tab-body-function nil
6216 "*Function to execute when `message-tab' (TAB) is executed in the body.
6217 If nil, the function bound in `text-mode-map' or `global-map' is executed."
6221 (defun message-tab ()
6222 "Complete names according to `message-completion-alist'.
6223 Execute function specified by `message-tab-body-function' when not in
6226 (let ((alist message-completion-alist))
6228 (let ((mail-abbrev-mode-regexp (caar alist)))
6229 (not (mail-abbrev-in-expansion-header-p))))
6230 (setq alist (cdr alist)))
6231 (funcall (or (cdar alist) message-tab-body-function
6232 (lookup-key text-mode-map "\t")
6233 (lookup-key global-map "\t")
6234 'indent-relative))))
6236 (defun message-expand-group ()
6237 "Expand the group name under point."
6238 (let* ((b (save-excursion
6243 (skip-chars-forward "^:")
6246 (skip-chars-backward "^, \t\n") (point))))
6247 (completion-ignore-case t)
6248 (string (buffer-substring b (progn (skip-chars-forward "^,\t\n ")
6250 (hashtb (and (boundp 'gnus-active-hashtb) gnus-active-hashtb))
6251 (completions (all-completions string hashtb))
6253 (delete-region b (point))
6255 ((= (length completions) 1)
6256 (if (string= (car completions) string)
6259 (message "Only matching group"))
6260 (insert (car completions))))
6261 ((and (setq comp (try-completion string hashtb))
6262 (not (string= comp string)))
6267 (message "No matching groups")
6268 (save-selected-window
6269 (pop-to-buffer "*Completions*")
6270 (buffer-disable-undo)
6271 (let ((buffer-read-only nil))
6273 (let ((standard-output (current-buffer)))
6274 (display-completion-list (sort completions 'string<)))
6275 (goto-char (point-min))
6276 (delete-region (point) (progn (forward-line 3) (point))))))))))
6278 (defun message-expand-name ()
6279 (if (fboundp 'bbdb-complete-name)
6280 (bbdb-complete-name)
6285 (defun message-talkative-question (ask question show &rest text)
6286 "Call FUNCTION with argument QUESTION; optionally display TEXT... args.
6287 If SHOW is non-nil, the arguments TEXT... are displayed in a temp buffer.
6288 The following arguments may contain lists of values."
6290 (setq text (message-flatten-list text)))
6291 (save-window-excursion
6293 (with-output-to-temp-buffer " *MESSAGE information message*"
6294 (set-buffer " *MESSAGE information message*")
6295 (fundamental-mode) ; for Emacs 20.4+
6296 (mapcar 'princ text)
6297 (goto-char (point-min))))
6298 (funcall ask question))
6299 (funcall ask question)))
6301 (defun message-flatten-list (list)
6302 "Return a new, flat list that contains all elements of LIST.
6304 \(message-flatten-list '(1 (2 3 (4 5 (6))) 7))
6307 (apply 'append (mapcar 'message-flatten-list list)))
6311 (defun message-generate-new-buffer-clone-locals (name &optional varstr)
6312 "Create and return a buffer with name based on NAME using `generate-new-buffer.'
6313 Then clone the local variables and values from the old buffer to the
6314 new one, cloning only the locals having a substring matching the
6316 (let ((oldbuf (current-buffer)))
6318 (set-buffer (generate-new-buffer name))
6319 (message-clone-locals oldbuf varstr)
6322 (defun message-clone-locals (buffer &optional varstr)
6323 "Clone the local variables from BUFFER to the current buffer."
6324 (let ((locals (save-excursion
6326 (buffer-local-variables)))
6327 (regexp "^gnus\\|^nn\\|^message\\|^user-mail-address"))
6330 (when (and (consp local)
6332 (string-match regexp (symbol-name (car local)))
6334 (string-match varstr (symbol-name (car local)))))
6336 (set (make-local-variable (car local))
6340 ;;; Miscellaneous functions
6342 (defsubst message-replace-chars-in-string (string from to)
6343 (mm-subst-char-in-string from to string))
6349 (defvar message-inhibit-body-encoding nil)
6351 (defun message-encode-message-body ()
6352 (unless message-inhibit-body-encoding
6353 (let ((mail-parse-charset (or mail-parse-charset
6354 message-default-charset))
6355 (case-fold-search t)
6356 lines content-type-p)
6359 (narrow-to-region (point) (point-max))
6360 (let ((new (mml-generate-mime)))
6362 (delete-region (point-min) (point-max))
6364 (goto-char (point-min))
6365 (if (eq (aref new 0) ?\n)
6367 (search-forward "\n\n")
6368 (setq lines (buffer-substring (point-min) (1- (point))))
6369 (delete-region (point-min) (point))))))
6371 (message-narrow-to-headers-or-head)
6372 (message-remove-header "Mime-Version")
6373 (goto-char (point-max))
6374 (insert "MIME-Version: 1.0\n")
6377 (setq content-type-p
6379 (re-search-backward "^Content-Type:" nil t))))
6381 (message-narrow-to-headers-or-head)
6382 (message-remove-first-header "Content-Type")
6383 (message-remove-first-header "Content-Transfer-Encoding"))
6384 ;; We always make sure that the message has a Content-Type
6385 ;; header. This is because some broken MTAs and MUAs get
6386 ;; awfully confused when confronted with a message with a
6387 ;; MIME-Version header and without a Content-Type header. For
6388 ;; instance, Solaris' /usr/bin/mail.
6389 (unless content-type-p
6390 (goto-char (point-min))
6391 ;; For unknown reason, MIME-Version doesn't exist.
6392 (when (re-search-forward "^MIME-Version:" nil t)
6394 (insert "Content-Type: text/plain; charset=us-ascii\n"))))))
6396 (defun message-read-from-minibuffer (prompt &optional initial-contents)
6397 "Read from the minibuffer while providing abbrev expansion."
6398 (if (fboundp 'mail-abbrevs-setup)
6399 (let ((mail-abbrev-mode-regexp "")
6400 (minibuffer-setup-hook 'mail-abbrevs-setup)
6401 (minibuffer-local-map message-minibuffer-local-map))
6402 (read-from-minibuffer prompt initial-contents))
6403 (let ((minibuffer-setup-hook 'mail-abbrev-minibuffer-setup-hook)
6404 (minibuffer-local-map message-minibuffer-local-map))
6405 (read-string prompt initial-contents))))
6407 (defun message-use-alternative-email-as-from ()
6408 (require 'mail-utils)
6409 (let* ((fields '("To" "Cc"))
6412 (mail-strip-quoted-names
6413 (mapconcat 'message-fetch-reply-field fields ","))
6417 (if (string-match message-alternative-emails (car emails))
6418 (setq email (car emails)
6421 (unless (or (not email) (equal email user-mail-address))
6422 (goto-char (point-max))
6423 (insert "From: " email "\n"))))
6425 (defun message-options-get (symbol)
6426 (cdr (assq symbol message-options)))
6428 (defun message-options-set (symbol value)
6429 (let ((the-cons (assq symbol message-options)))
6432 (setcdr the-cons value)
6433 (setq message-options (delq the-cons message-options)))
6435 (push (cons symbol value) message-options))))
6438 (defun message-options-set-recipient ()
6440 (message-narrow-to-headers-or-head)
6441 (message-options-set 'message-sender
6442 (mail-strip-quoted-names
6443 (message-fetch-field "from")))
6444 (message-options-set 'message-recipients
6445 (mail-strip-quoted-names
6446 (let ((to (message-fetch-field "to"))
6447 (cc (message-fetch-field "cc"))
6448 (bcc (message-fetch-field "bcc")))
6451 (if (and to cc) ", ")
6453 (if (and (or to cc) bcc) ", ")
6456 (when (featurep 'xemacs)
6457 (require 'messagexmas)
6458 (message-xmas-redefine))
6462 (run-hooks 'message-load-hook)
6465 ;; coding: iso-8859-1
6468 ;;; message.el ends here