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 ;; qmail-related stuff
640 (defcustom message-qmail-inject-program "/var/qmail/bin/qmail-inject"
641 "Location of the qmail-inject program."
642 :group 'message-sending
645 (defcustom message-qmail-inject-args nil
646 "Arguments passed to qmail-inject programs.
647 This should be a list of strings, one string for each argument. It
648 may also be a function.
650 For e.g., if you wish to set the envelope sender address so that bounces
651 go to the right place or to deal with listserv's usage of that address, you
652 might set this variable to '(\"-f\" \"you@some.where\")."
653 :group 'message-sending
654 :type '(choice (function)
657 (defvar message-cater-to-broken-inn t
658 "Non-nil means Gnus should not fold the `References' header.
659 Folding `References' makes ancient versions of INN create incorrect
663 (defvar gnus-post-method)
664 (defvar gnus-select-method))
665 (defcustom message-post-method
666 (cond ((and (boundp 'gnus-post-method)
667 (listp gnus-post-method)
670 ((boundp 'gnus-select-method)
673 "*Method used to post news.
674 Note that when posting from inside Gnus, for instance, this
675 variable isn't used."
677 :group 'message-sending
678 ;; This should be the `gnus-select-method' widget, but that might
679 ;; create a dependence to `gnus.el'.
682 (defcustom message-generate-headers-first nil
683 "*If non-nil, generate all required headers before composing.
684 The variables `message-required-news-headers' and
685 `message-required-mail-headers' specify which headers to generate.
686 This can also be a list of headers that should be generated before
689 Note that the variable `message-deletable-headers' specifies headers which
690 are to be deleted and then re-generated before sending, so this variable
691 will not have a visible effect for those headers."
692 :group 'message-headers
693 :type '(choice (const :tag "None" nil)
695 (repeat (sexp :tag "Header"))))
697 (defcustom message-setup-hook nil
698 "Normal hook, run each time a new outgoing message is initialized.
699 The function `message-setup' runs this hook."
700 :group 'message-various
703 (defcustom message-cancel-hook nil
704 "Hook run when cancelling articles."
705 :group 'message-various
708 (defcustom message-signature-setup-hook nil
709 "Normal hook, run each time a new outgoing message is initialized.
710 It is run after the headers have been inserted and before
711 the signature is inserted."
712 :group 'message-various
715 (defcustom message-mode-hook nil
716 "Hook run in message mode buffers."
717 :group 'message-various
720 (defcustom message-header-hook nil
721 "Hook run in a message mode buffer narrowed to the headers."
722 :group 'message-various
725 (defcustom message-header-setup-hook nil
726 "Hook called narrowed to the headers when setting up a message buffer."
727 :group 'message-various
730 (defcustom message-minibuffer-local-map
731 (let ((map (make-sparse-keymap 'message-minibuffer-local-map)))
732 (set-keymap-parent map minibuffer-local-map)
734 "Keymap for `message-read-from-minibuffer'.")
737 (defcustom message-citation-line-function 'message-insert-citation-line
738 "*Function called to insert the \"Whomever writes:\" line.
740 Note that Gnus provides a feature where the reader can click on
741 `writes:' to hide the cited text. If you change this line too much,
742 people who read your message will have to change their Gnus
743 configuration. See the variable `gnus-cite-attribution-suffix'."
745 :group 'message-insertion)
748 (defcustom message-yank-prefix "> "
749 "*Prefix inserted on the lines of yanked messages.
750 Fix `message-cite-prefix-regexp' if it is set to an abnormal value.
751 See also `message-yank-cited-prefix'."
753 :group 'message-insertion)
755 (defcustom message-yank-cited-prefix ">"
756 "*Prefix inserted on cited or empty lines of yanked messages.
757 Fix `message-cite-prefix-regexp' if it is set to an abnormal value.
758 See also `message-yank-prefix'."
760 :group 'message-insertion)
762 (defcustom message-indentation-spaces 3
763 "*Number of spaces to insert at the beginning of each cited line.
764 Used by `message-yank-original' via `message-yank-cite'."
765 :group 'message-insertion
769 (defcustom message-cite-function 'message-cite-original
770 "*Function for citing an original message.
771 Predefined functions include `message-cite-original' and
772 `message-cite-original-without-signature'.
773 Note that `message-cite-original' uses `mail-citation-hook' if that is non-nil."
774 :type '(radio (function-item message-cite-original)
775 (function-item message-cite-original-without-signature)
776 (function-item sc-cite-original)
777 (function :tag "Other"))
778 :group 'message-insertion)
781 (defcustom message-indent-citation-function 'message-indent-citation
782 "*Function for modifying a citation just inserted in the mail buffer.
783 This can also be a list of functions. Each function can find the
784 citation between (point) and (mark t). And each function should leave
785 point and mark around the citation text as modified."
787 :group 'message-insertion)
790 (defcustom message-signature t
791 "*String to be inserted at the end of the message buffer.
792 If t, the `message-signature-file' file will be inserted instead.
793 If a function, the result from the function will be used instead.
794 If a form, the result from the form will be used instead."
796 :group 'message-insertion)
799 (defcustom message-signature-file "~/.signature"
800 "*Name of file containing the text inserted at end of message buffer.
801 Ignored if the named file doesn't exist.
802 If nil, don't insert a signature."
803 :type '(choice file (const :tags "None" nil))
804 :group 'message-insertion)
807 (defcustom message-signature-insert-empty-line t
808 "*If non-nil, insert an empty line before the signature separator."
810 :group 'message-insertion)
812 (defcustom message-distribution-function nil
813 "*Function called to return a Distribution header."
815 :group 'message-headers
816 :type '(choice function (const nil)))
818 (defcustom message-expires 14
819 "Number of days before your article expires."
821 :group 'message-headers
822 :link '(custom-manual "(message)News Headers")
825 (defcustom message-user-path nil
826 "If nil, use the NNTP server name in the Path header.
827 If stringp, use this; if non-nil, use no host name (user name only)."
829 :group 'message-headers
830 :link '(custom-manual "(message)News Headers")
831 :type '(choice (const :tag "nntp" nil)
833 (sexp :tag "none" :format "%t" t)))
835 (defvar message-reply-buffer nil)
836 (defvar message-reply-headers nil
837 "The headers of the current replied article.
838 It is a vector of the following headers:
839 \[number subject from date id references chars lines xref extra].")
840 (defvar message-newsreader nil)
841 (defvar message-mailer nil)
842 (defvar message-sent-message-via nil)
843 (defvar message-checksum nil)
844 (defvar message-send-actions nil
845 "A list of actions to be performed upon successful sending of a message.")
846 (defvar message-exit-actions nil
847 "A list of actions to be performed upon exiting after sending a message.")
848 (defvar message-kill-actions nil
849 "A list of actions to be performed before killing a message buffer.")
850 (defvar message-postpone-actions nil
851 "A list of actions to be performed after postponing a message.")
853 (define-widget 'message-header-lines 'text
854 "All header lines must be LFD terminated."
855 :format "%{%t%}:%n%v"
857 :error "All header lines must be newline terminated")
859 (defcustom message-default-headers ""
860 "*A string containing header lines to be inserted in outgoing messages.
861 It is inserted before you edit the message, so you can edit or delete
863 :group 'message-headers
864 :type 'message-header-lines)
866 (defcustom message-default-mail-headers ""
867 "*A string of header lines to be inserted in outgoing mails."
868 :group 'message-headers
870 :type 'message-header-lines)
872 (defcustom message-default-news-headers ""
873 "*A string of header lines to be inserted in outgoing news articles."
874 :group 'message-headers
876 :type 'message-header-lines)
878 ;; Note: could use /usr/ucb/mail instead of sendmail;
879 ;; options -t, and -v if not interactive.
880 (defcustom message-mailer-swallows-blank-line
881 (if (and (string-match "sparc-sun-sunos\\(\\'\\|[^5]\\)"
882 system-configuration)
883 (file-readable-p "/etc/sendmail.cf")
884 (let ((buffer (get-buffer-create " *temp*")))
888 (insert-file-contents "/etc/sendmail.cf")
889 (goto-char (point-min))
890 (let ((case-fold-search nil))
891 (re-search-forward "^OR\\>" nil t)))
892 (kill-buffer buffer))))
893 ;; According to RFC822, "The field-name must be composed of printable
894 ;; ASCII characters (i. e., characters that have decimal values between
895 ;; 33 and 126, except colon)", i. e., any chars except ctl chars,
897 '(looking-at "[ \t]\\|[][!\"#$%&'()*+,-./0-9;<=>?@A-Z\\\\^_`a-z{|}~]+:"))
898 "*Set this non-nil if the system's mailer runs the header and body together.
899 \(This problem exists on Sunos 4 when sendmail is run in remote mode.)
900 The value should be an expression to test whether the problem will
902 :group 'message-sending
906 (define-mail-user-agent 'message-user-agent
907 'message-mail 'message-send-and-exit
908 'message-kill-buffer 'message-send-hook)
910 (defvar message-mh-deletable-headers '(Message-ID Date Lines Sender)
911 "If non-nil, delete the deletable headers before feeding to mh.")
913 (defvar message-send-method-alist
914 '((news message-news-p message-send-via-news)
915 (mail message-mail-p message-send-via-mail))
916 "Alist of ways to send outgoing messages.
917 Each element has the form
919 \(TYPE PREDICATE FUNCTION)
921 where TYPE is a symbol that names the method; PREDICATE is a function
922 called without any parameters to determine whether the message is
923 a message of type TYPE; and FUNCTION is a function to be called if
924 PREDICATE returns non-nil. FUNCTION is called with one parameter --
927 (defcustom message-mail-alias-type 'abbrev
928 "*What alias expansion type to use in Message buffers.
929 The default is `abbrev', which uses mailabbrev. nil switches
932 :link '(custom-manual "(message)Mail Aliases")
933 :type '(choice (const :tag "Use Mailabbrev" abbrev)
934 (const :tag "No expansion" nil)))
936 (defcustom message-auto-save-directory
937 (file-name-as-directory (nnheader-concat message-directory "drafts"))
938 "*Directory where Message auto-saves buffers if Gnus isn't running.
939 If nil, Message won't auto-save."
940 :group 'message-buffers
941 :type '(choice directory (const :tag "Don't auto-save" nil)))
943 (defcustom message-default-charset
944 (and (not (mm-multibyte-p)) 'iso-8859-1)
945 "Default charset used in non-MULE Emacsen.
946 If nil, you might be asked to input the charset."
951 (defcustom message-dont-reply-to-names
952 (and (boundp 'rmail-dont-reply-to-names) rmail-dont-reply-to-names)
953 "*A regexp specifying addresses to prune when doing wide replies.
954 A value of nil means exclude your own user name only."
957 :type '(choice (const :tag "Yourself" nil)
960 (defvar message-shoot-gnksa-feet nil
961 "*A list of GNKSA feet you are allowed to shoot.
962 Gnus gives you all the opportunity you could possibly want for
963 shooting yourself in the foot. Also, Gnus allows you to shoot the
964 feet of Good Net-Keeping Seal of Approval. The following are foot
966 `empty-article' Allow you to post an empty article;
967 `quoted-text-only' Allow you to post quoted text only;
968 `multiple-copies' Allow you to post multiple copies;
969 `cancel-messages' Allow you to cancel or supersede messages from
970 your other email addresses.")
972 (defsubst message-gnksa-enable-p (feature)
973 (or (not (listp message-shoot-gnksa-feet))
974 (memq feature message-shoot-gnksa-feet)))
976 ;;; Internal variables.
977 ;;; Well, not really internal.
979 (defvar message-mode-syntax-table
980 (let ((table (copy-syntax-table text-mode-syntax-table)))
981 (modify-syntax-entry ?% ". " table)
982 (modify-syntax-entry ?> ". " table)
983 (modify-syntax-entry ?< ". " table)
985 "Syntax table used while in Message mode.")
987 (defface message-header-to-face
990 (:foreground "green2" :bold t))
993 (:foreground "MidnightBlue" :bold t))
995 (:bold t :italic t)))
996 "Face used for displaying From headers."
997 :group 'message-faces)
999 (defface message-header-cc-face
1002 (:foreground "green4" :bold t))
1005 (:foreground "MidnightBlue"))
1008 "Face used for displaying Cc headers."
1009 :group 'message-faces)
1011 (defface message-header-subject-face
1014 (:foreground "green3"))
1017 (:foreground "navy blue" :bold t))
1020 "Face used for displaying subject headers."
1021 :group 'message-faces)
1023 (defface message-header-newsgroups-face
1026 (:foreground "yellow" :bold t :italic t))
1029 (:foreground "blue4" :bold t :italic t))
1031 (:bold t :italic t)))
1032 "Face used for displaying newsgroups headers."
1033 :group 'message-faces)
1035 (defface message-header-other-face
1038 (:foreground "#b00000"))
1041 (:foreground "steel blue"))
1043 (:bold t :italic t)))
1044 "Face used for displaying newsgroups headers."
1045 :group 'message-faces)
1047 (defface message-header-name-face
1050 (:foreground "DarkGreen"))
1053 (:foreground "cornflower blue"))
1056 "Face used for displaying header names."
1057 :group 'message-faces)
1059 (defface message-header-xheader-face
1062 (:foreground "blue"))
1065 (:foreground "blue"))
1068 "Face used for displaying X-Header headers."
1069 :group 'message-faces)
1071 (defface message-separator-face
1074 (:foreground "blue3"))
1077 (:foreground "brown"))
1080 "Face used for displaying the separator."
1081 :group 'message-faces)
1083 (defface message-cited-text-face
1086 (:foreground "red"))
1089 (:foreground "red"))
1092 "Face used for displaying cited text names."
1093 :group 'message-faces)
1095 (defface message-mml-face
1098 (:foreground "ForestGreen"))
1101 (:foreground "ForestGreen"))
1104 "Face used for displaying MML."
1105 :group 'message-faces)
1107 (defun message-font-lock-make-header-matcher (regexp)
1110 (let ((start (point)))
1113 (goto-char (point-min))
1114 (if (re-search-forward
1115 (concat "^" (regexp-quote mail-header-separator) "$")
1117 (setq limit (min limit (match-beginning 0))))
1119 (and (< start limit)
1120 (re-search-forward ,regexp limit t))))))
1121 (if (featurep 'bytecomp)
1125 (defvar message-font-lock-keywords
1126 (let ((content "[ \t]*\\(.+\\(\n[ \t].*\\)*\\)\n?"))
1127 `((,(message-font-lock-make-header-matcher
1128 (concat "^\\([Tt]o:\\)" content))
1129 (1 'message-header-name-face)
1130 (2 'message-header-to-face nil t))
1131 (,(message-font-lock-make-header-matcher
1132 (concat "^\\(^[GBF]?[Cc][Cc]:\\|^[Rr]eply-[Tt]o:\\)" content))
1133 (1 'message-header-name-face)
1134 (2 'message-header-cc-face nil t))
1135 (,(message-font-lock-make-header-matcher
1136 (concat "^\\([Ss]ubject:\\)" content))
1137 (1 'message-header-name-face)
1138 (2 'message-header-subject-face nil t))
1139 (,(message-font-lock-make-header-matcher
1140 (concat "^\\([Nn]ewsgroups:\\|Followup-[Tt]o:\\)" content))
1141 (1 'message-header-name-face)
1142 (2 'message-header-newsgroups-face nil t))
1143 (,(message-font-lock-make-header-matcher
1144 (concat "^\\([A-Z][^: \n\t]+:\\)" content))
1145 (1 'message-header-name-face)
1146 (2 'message-header-other-face nil t))
1147 (,(message-font-lock-make-header-matcher
1148 (concat "^\\(X-[A-Za-z0-9-]+:\\|In-Reply-To:\\)" content))
1149 (1 'message-header-name-face)
1150 (2 'message-header-name-face))
1151 ,@(if (and mail-header-separator
1152 (not (equal mail-header-separator "")))
1153 `((,(concat "^\\(" (regexp-quote mail-header-separator) "\\)$")
1154 1 'message-separator-face))
1157 (re-search-forward (concat "^\\("
1158 message-cite-prefix-regexp
1161 (0 'message-cited-text-face))
1162 ("<#/?\\(multipart\\|part\\|external\\|mml\\|secure\\)[^>]*>"
1163 (0 'message-mml-face))))
1164 "Additional expressions to highlight in Message mode.")
1167 ;; XEmacs does it like this. For Emacs, we have to set the
1168 ;; `font-lock-defaults' buffer-local variable.
1169 (put 'message-mode 'font-lock-defaults '(message-font-lock-keywords t))
1171 (defvar message-face-alist
1172 '((bold . bold-region)
1173 (underline . underline-region)
1174 (default . (lambda (b e)
1176 (ununderline-region b e))))
1177 "Alist of mail and news faces for facemenu.
1178 The cdr of each entry is a function for applying the face to a region.")
1180 (defcustom message-send-hook nil
1181 "Hook run before sending messages.
1182 This hook is run quite early when sending."
1183 :group 'message-various
1184 :options '(ispell-message)
1187 (defcustom message-send-mail-hook nil
1188 "Hook run before sending mail messages.
1189 This hook is run very late -- just before the message is sent as
1191 :group 'message-various
1194 (defcustom message-send-news-hook nil
1195 "Hook run before sending news messages.
1196 This hook is run very late -- just before the message is sent as
1198 :group 'message-various
1201 (defcustom message-sent-hook nil
1202 "Hook run after sending messages."
1203 :group 'message-various
1206 (defvar message-send-coding-system 'binary
1207 "Coding system to encode outgoing mail.")
1209 (defvar message-draft-coding-system
1210 mm-auto-save-coding-system
1211 "*Coding system to compose mail.
1212 If you'd like to make it possible to share draft files between XEmacs
1213 and Emacs, you may use `iso-2022-7bit' for this value at your own risk.
1214 Note that the coding-system `iso-2022-7bit' isn't suitable to all data.")
1216 (defcustom message-send-mail-partially-limit 1000000
1217 "The limitation of messages sent as message/partial.
1218 The lower bound of message size in characters, beyond which the message
1219 should be sent in several parts. If it is nil, the size is unlimited."
1221 :group 'message-buffers
1222 :type '(choice (const :tag "unlimited" nil)
1225 (defcustom message-alternative-emails nil
1226 "A regexp to match the alternative email addresses.
1227 The first matched address (not primary one) is used in the From field."
1228 :group 'message-headers
1229 :type '(choice (const :tag "Always use primary" nil)
1232 (defcustom message-hierarchical-addresses nil
1233 "A list of hierarchical mail address definitions.
1235 Inside each entry, the first address is the \"top\" address, and
1236 subsequent addresses are subaddresses; this is used to indicate that
1237 mail sent to the first address will automatically be delivered to the
1238 subaddresses. So if the first address appears in the recipient list
1239 for a message, the subaddresses will be removed (if present) before
1240 the mail is sent. All addresses in this structure should be
1242 :group 'message-headers
1243 :type '(repeat (repeat string)))
1245 (defcustom message-mail-user-agent nil
1246 "Like `mail-user-agent'.
1247 Except if it is nil, use Gnus native MUA; if it is t, use
1249 :type '(radio (const :tag "Gnus native"
1252 (const :tag "`mail-user-agent'"
1255 (function-item :tag "Default Emacs mail"
1257 sendmail-user-agent)
1258 (function-item :tag "Emacs interface to MH"
1261 (function :tag "Other"))
1265 (defcustom message-wide-reply-confirm-recipients nil
1266 "Whether to confirm a wide reply to multiple email recipients.
1267 If this variable is nil, don't ask whether to reply to all recipients.
1268 If this variable is non-nil, pose the question \"Reply to all
1269 recipients?\" before a wide reply to multiple recipients. If the user
1270 answers yes, reply to all recipients as usual. If the user answers
1271 no, only reply back to the author."
1273 :group 'message-headers
1276 ;;; Internal variables.
1278 (defvar message-sending-message "Sending...")
1279 (defvar message-buffer-list nil)
1280 (defvar message-this-is-news nil)
1281 (defvar message-this-is-mail nil)
1282 (defvar message-draft-article nil)
1283 (defvar message-mime-part nil)
1284 (defvar message-posting-charset nil)
1286 ;; Byte-compiler warning
1288 (defvar gnus-active-hashtb)
1289 (defvar gnus-read-active-file))
1291 ;;; Regexp matching the delimiter of messages in UNIX mail format
1292 ;;; (UNIX From lines), minus the initial ^. It should be a copy
1293 ;;; of rmail.el's rmail-unix-mail-delimiter.
1294 (defvar message-unix-mail-delimiter
1295 (let ((time-zone-regexp
1296 (concat "\\([A-Z]?[A-Z]?[A-Z][A-Z]\\( DST\\)?"
1297 "\\|[-+]?[0-9][0-9][0-9][0-9]"
1303 ;; Many things can happen to an RFC 822 mailbox before it is put into
1304 ;; a `From' line. The leading phrase can be stripped, e.g.
1305 ;; `Joe <@w.x:joe@y.z>' -> `<@w.x:joe@y.z>'. The <> can be stripped, e.g.
1306 ;; `<@x.y:joe@y.z>' -> `@x.y:joe@y.z'. Everything starting with a CRLF
1307 ;; can be removed, e.g.
1308 ;; From: joe@y.z (Joe K
1310 ;; can yield `From joe@y.z (Joe K Fri Mar 22 08:11:15 1996', and
1313 ;; can yield `From Joe User Fri Mar 22 08:11:15 1996'.
1314 ;; The mailbox can be removed or be replaced by white space, e.g.
1315 ;; From: "Joe User"{space}{tab}
1317 ;; can yield `From {space}{tab} Fri Mar 22 08:11:15 1996',
1318 ;; where {space} and {tab} represent the Ascii space and tab characters.
1319 ;; We want to match the results of any of these manglings.
1320 ;; The following regexp rejects names whose first characters are
1321 ;; obviously bogus, but after that anything goes.
1322 "\\([^\0-\b\n-\r\^?].*\\)?"
1324 ;; The time the message was sent.
1325 "\\([^\0-\r \^?]+\\) +" ; day of the week
1326 "\\([^\0-\r \^?]+\\) +" ; month
1327 "\\([0-3]?[0-9]\\) +" ; day of month
1328 "\\([0-2][0-9]:[0-5][0-9]\\(:[0-6][0-9]\\)?\\) *" ; time of day
1330 ;; Perhaps a time zone, specified by an abbreviation, or by a
1335 " \\([0-9][0-9]+\\) *"
1337 ;; On some systems the time zone can appear after the year, too.
1341 "\\(remote from .*\\)?"
1344 "Regexp matching the delimiter of messages in UNIX mail format.")
1346 (defvar message-unsent-separator
1347 (concat "^ *---+ +Unsent message follows +---+ *$\\|"
1348 "^ *---+ +Returned message +---+ *$\\|"
1349 "^Start of returned message$\\|"
1350 "^ *---+ +Original message +---+ *$\\|"
1351 "^ *--+ +begin message +--+ *$\\|"
1352 "^ *---+ +Original message follows +---+ *$\\|"
1353 "^ *---+ +Undelivered message follows +---+ *$\\|"
1354 "^|? *---+ +Message text follows: +---+ *|?$")
1355 "A regexp that matches the separator before the text of a failed message.")
1357 (defvar message-header-format-alist
1359 (To . message-fill-address)
1360 (Cc . message-fill-address)
1371 (References . message-shorten-references)
1373 "Alist used for formatting headers.")
1375 (defvar message-options nil
1376 "Some saved answers when sending message.")
1378 (defvar message-send-mail-real-function nil
1379 "Internal send mail function.")
1381 (defvar message-bogus-system-names "^localhost\\."
1382 "The regexp of bogus system names.")
1385 (autoload 'message-setup-toolbar "messagexmas")
1386 (autoload 'mh-new-draft-name "mh-comp")
1387 (autoload 'mh-send-letter "mh-comp")
1388 (autoload 'gnus-point-at-eol "gnus-util")
1389 (autoload 'gnus-point-at-bol "gnus-util")
1390 (autoload 'gnus-output-to-rmail "gnus-util")
1391 (autoload 'gnus-output-to-mail "gnus-util")
1392 (autoload 'nndraft-request-associate-buffer "nndraft")
1393 (autoload 'nndraft-request-expire-articles "nndraft")
1394 (autoload 'gnus-open-server "gnus-int")
1395 (autoload 'gnus-request-post "gnus-int")
1396 (autoload 'gnus-alive-p "gnus-util")
1397 (autoload 'gnus-server-string "gnus")
1398 (autoload 'gnus-group-name-charset "gnus-group")
1399 (autoload 'gnus-group-name-decode "gnus-group")
1400 (autoload 'gnus-groups-from-server "gnus")
1401 (autoload 'rmail-output "rmailout")
1402 (autoload 'gnus-delay-article "gnus-delay"))
1407 ;;; Utility functions.
1410 (defmacro message-y-or-n-p (question show &rest text)
1411 "Ask QUESTION, displaying remaining args in a temporary buffer if SHOW."
1412 `(message-talkative-question 'y-or-n-p ,question ,show ,@text))
1414 (defmacro message-delete-line (&optional n)
1415 "Delete the current line (and the next N lines)."
1416 `(delete-region (progn (beginning-of-line) (point))
1417 (progn (forward-line ,(or n 1)) (point))))
1419 (defun message-mark-active-p ()
1420 "Non-nil means the mark and region are currently active in this buffer."
1423 (defun message-unquote-tokens (elems)
1424 "Remove double quotes (\") from strings in list ELEMS."
1425 (mapcar (lambda (item)
1426 (while (string-match "^\\(.*\\)\"\\(.*\\)$" item)
1427 (setq item (concat (match-string 1 item)
1428 (match-string 2 item))))
1432 (defun message-tokenize-header (header &optional separator)
1433 "Split HEADER into a list of header elements.
1434 SEPARATOR is a string of characters to be used as separators. \",\"
1435 is used by default."
1438 (let ((regexp (format "[%s]+" (or separator ",")))
1443 (message-set-work-buffer)
1445 (goto-char (point-min))
1450 (cond ((and (> (point) beg)
1452 (and (looking-at regexp)
1455 (push (buffer-substring beg (point)) elems)
1456 (setq beg (match-end 0)))
1457 ((eq (char-after) ?\")
1458 (setq quoted (not quoted)))
1459 ((and (eq (char-after) ?\()
1462 ((and (eq (char-after) ?\))
1465 (nreverse elems)))))
1467 (defun message-mail-file-mbox-p (file)
1468 "Say whether FILE looks like a Unix mbox file."
1469 (when (and (file-exists-p file)
1470 (file-readable-p file)
1471 (file-regular-p file))
1473 (nnheader-insert-file-contents file)
1474 (goto-char (point-min))
1475 (looking-at message-unix-mail-delimiter))))
1477 (defun message-fetch-field (header &optional not-all)
1478 "The same as `mail-fetch-field', only remove all newlines."
1479 (let* ((inhibit-point-motion-hooks t)
1480 (case-fold-search t)
1481 (value (mail-fetch-field header nil (not not-all))))
1483 (while (string-match "\n[\t ]+" value)
1484 (setq value (replace-match " " t t value)))
1485 (set-text-properties 0 (length value) nil value)
1488 (defun message-narrow-to-field ()
1489 "Narrow the buffer to the header on the current line."
1495 (if (re-search-forward "^[^ \n\t]" nil t)
1500 (goto-char (point-min)))
1502 (defun message-add-header (&rest headers)
1503 "Add the HEADERS to the message header, skipping those already present."
1506 (unless (string-match "^\\([^:]+\\):[ \t]*[^ \t]" (car headers))
1507 (error "Invalid header `%s'" (car headers)))
1508 (setq hclean (match-string 1 (car headers)))
1510 (message-narrow-to-headers)
1511 (unless (re-search-forward (concat "^" (regexp-quote hclean) ":") nil t)
1512 (goto-char (point-max))
1513 (if (string-match "\n$" (car headers))
1514 (insert (car headers))
1515 (insert (car headers) ?\n)))))
1516 (setq headers (cdr headers))))
1518 (defmacro message-with-reply-buffer (&rest forms)
1519 "Evaluate FORMS in the reply buffer, if it exists."
1520 `(when (and message-reply-buffer
1521 (buffer-name message-reply-buffer))
1523 (set-buffer message-reply-buffer)
1526 (put 'message-with-reply-buffer 'lisp-indent-function 0)
1527 (put 'message-with-reply-buffer 'edebug-form-spec '(body))
1529 (defun message-fetch-reply-field (header)
1530 "Fetch field HEADER from the message we're replying to."
1531 (message-with-reply-buffer
1533 (mail-narrow-to-head)
1534 (message-fetch-field header))))
1536 (defun message-set-work-buffer ()
1537 (if (get-buffer " *message work*")
1539 (set-buffer " *message work*")
1541 (set-buffer (get-buffer-create " *message work*"))
1542 (kill-all-local-variables)
1543 (mm-enable-multibyte)))
1545 (defun message-functionp (form)
1546 "Return non-nil if FORM is funcallable."
1547 (or (and (symbolp form) (fboundp form))
1548 (and (listp form) (eq (car form) 'lambda))
1549 (byte-code-function-p form)))
1551 (defun message-strip-list-identifiers (subject)
1552 "Remove list identifiers in `gnus-list-identifiers' from string SUBJECT."
1553 (require 'gnus-sum) ; for gnus-list-identifiers
1554 (let ((regexp (if (stringp gnus-list-identifiers)
1555 gnus-list-identifiers
1556 (mapconcat 'identity gnus-list-identifiers " *\\|"))))
1557 (if (string-match (concat "\\(\\(\\(Re: +\\)?\\(" regexp
1558 " *\\)\\)+\\(Re: +\\)?\\)") subject)
1559 (concat (substring subject 0 (match-beginning 1))
1560 (or (match-string 3 subject)
1561 (match-string 5 subject))
1566 (defun message-strip-subject-re (subject)
1567 "Remove \"Re:\" from subject lines in string SUBJECT."
1568 (if (string-match message-subject-re-regexp subject)
1569 (substring subject (match-end 0))
1572 ;;; Start of functions adopted from `message-utils.el'.
1574 (defun message-strip-subject-trailing-was (subject)
1575 "Remove trailing \"(Was: <old subject>)\" from SUBJECT lines.
1576 Leading \"Re: \" is not stripped by this function. Use the function
1577 `message-strip-subject-re' for this."
1578 (let* ((query message-subject-trailing-was-query)
1583 message-subject-trailing-was-ask-regexp
1584 message-subject-trailing-was-regexp)
1587 (setq new (substring subject 0 (match-beginning 0))))
1588 (if (or (not found) (eq query nil))
1591 (if (message-y-or-n-p
1592 "Strip `(was: <old subject>)' in subject? " t
1594 "Strip `(was: <old subject>)' in subject "
1595 "and use the new one instead?\n\n"
1596 "Current subject is: \""
1598 "New subject would be: \""
1600 "See the variable `message-subject-trailing-was-query' "
1601 "to get rid of this query."
1606 ;;; Suggested by Jonas Steverud @ www.dtek.chalmers.se/~d4jonas/
1609 (defun message-change-subject (new-subject)
1610 "Ask for NEW-SUBJECT header, append (was: <Old Subject>)."
1613 (read-from-minibuffer "New subject: ")))
1614 (cond ((and (not (or (null new-subject) ; new subject not empty
1615 (zerop (string-width new-subject))
1616 (string-match "^[ \t]*$" new-subject))))
1618 (let ((old-subject (message-fetch-field "Subject")))
1619 (cond ((not old-subject)
1620 (error "No current subject"))
1623 (regexp-quote new-subject)
1625 old-subject)) ; yes, it really is a new subject
1626 ;; delete eventual Re: prefix
1628 (message-strip-subject-re old-subject))
1629 (message-goto-subject)
1630 (message-delete-line)
1631 (insert (concat "Subject: "
1634 old-subject ")\n")))))))))
1637 (defun message-mark-inserted-region (beg end)
1638 "Mark some region in the current article with enclosing tags.
1639 See `message-mark-insert-begin' and `message-mark-insert-end'."
1642 ; add to the end of the region first, otherwise end would be invalid
1644 (insert message-mark-insert-end)
1646 (insert message-mark-insert-begin)))
1649 (defun message-mark-insert-file (file)
1650 "Insert FILE at point, marking it with enclosing tags.
1651 See `message-mark-insert-begin' and `message-mark-insert-end'."
1652 (interactive "fFile to insert: ")
1653 ;; reverse insertion to get correct result.
1655 (insert message-mark-insert-end)
1657 (insert-file-contents file)
1659 (insert message-mark-insert-begin)))
1662 (defun message-add-archive-header ()
1663 "Insert \"X-No-Archive: Yes\" in the header and a note in the body.
1664 The note can be customized using `message-archive-note'. When called with a
1665 prefix argument, ask for a text to insert. If you don't want the note in the
1666 body, set `message-archive-note' to nil."
1668 (if current-prefix-arg
1669 (setq message-archive-note
1670 (read-from-minibuffer "Reason for No-Archive: "
1671 (cons message-archive-note 0))))
1673 (if (message-goto-signature)
1674 (re-search-backward message-signature-separator))
1675 (when message-archive-note
1676 (insert message-archive-note)
1678 (message-add-header message-archive-header)
1679 (message-sort-headers)))
1682 (defun message-cross-post-followup-to-header (target-group)
1683 "Mangles FollowUp-To and Newsgroups header to point to TARGET-GROUP.
1684 With prefix-argument just set Follow-Up, don't cross-post."
1686 (list ; Completion based on Gnus
1687 (completing-read "Followup To: "
1688 (if (boundp 'gnus-newsrc-alist)
1690 nil nil '("poster" . 0)
1691 (if (boundp 'gnus-group-history)
1692 'gnus-group-history))))
1693 (message-remove-header "Follow[Uu]p-[Tt]o" t)
1694 (message-goto-newsgroups)
1696 ;; if we already did a crosspost before, kill old target
1697 (if (and message-cross-post-old-target
1699 (regexp-quote (concat "," message-cross-post-old-target))
1702 ;; unless (followup is to poster or user explicitly asked not
1703 ;; to cross-post, or target-group is already in Newsgroups)
1704 ;; add target-group to Newsgroups line.
1706 ;; def: cross-post, req:no
1707 (and message-cross-post-default (not current-prefix-arg))
1708 ;; def: no-cross-post, req:yes
1709 (and (not message-cross-post-default) current-prefix-arg))
1710 (not (string-match "poster" target-group))
1711 (not (string-match (regexp-quote target-group)
1712 (message-fetch-field "Newsgroups"))))
1714 (insert (concat "," target-group))))
1715 (end-of-line) ; ensure Followup: comes after Newsgroups:
1716 ;; unless new followup would be identical to Newsgroups line
1717 ;; make a new Followup-To line
1718 (if (not (string-match (concat "^[ \t]*"
1721 (message-fetch-field "Newsgroups")))
1722 (insert (concat "\nFollowup-To: " target-group)))
1723 (setq message-cross-post-old-target target-group))
1726 (defun message-cross-post-insert-note (target-group cross-post in-old
1728 "Insert a in message body note about a set Followup or Crosspost.
1729 If there have been previous notes, delete them. TARGET-GROUP specifies the
1730 group to Followup-To. When CROSS-POST is t, insert note about
1731 crossposting. IN-OLD specifies whether TARGET-GROUP is a member of
1732 OLD-GROUPS. OLD-GROUPS lists the old-groups the posting would have
1733 been made to before the user asked for a Crosspost."
1734 ;; start scanning body for previous uses
1735 (message-goto-signature)
1736 (let ((head (re-search-backward
1737 (concat "^" mail-header-separator)
1738 nil t))) ; just search in body
1739 (message-goto-signature)
1740 (while (re-search-backward
1741 (concat "^" (regexp-quote message-cross-post-note) ".*")
1743 (message-delete-line))
1744 (message-goto-signature)
1745 (while (re-search-backward
1746 (concat "^" (regexp-quote message-followup-to-note) ".*")
1748 (message-delete-line))
1750 (if (message-goto-signature)
1751 (re-search-backward message-signature-separator))
1754 (string-match "^[ \t]*poster[ \t]*$" target-group))
1755 (insert (concat message-followup-to-note target-group "\n"))
1756 (insert (concat message-cross-post-note target-group "\n")))))
1759 (defun message-cross-post-followup-to (target-group)
1760 "Crossposts message and set Followup-To to TARGET-GROUP.
1761 With prefix-argument just set Follow-Up, don't cross-post."
1763 (list ; Completion based on Gnus
1764 (completing-read "Followup To: "
1765 (if (boundp 'gnus-newsrc-alist)
1767 nil nil '("poster" . 0)
1768 (if (boundp 'gnus-group-history)
1769 'gnus-group-history))))
1770 (cond ((not (or (null target-group) ; new subject not empty
1771 (zerop (string-width target-group))
1772 (string-match "^[ \t]*$" target-group)))
1774 (let* ((old-groups (message-fetch-field "Newsgroups"))
1775 (in-old (string-match
1776 (regexp-quote target-group)
1777 (or old-groups ""))))
1778 ;; check whether target exactly matches old Newsgroups
1779 (cond ((not old-groups)
1780 (error "No current newsgroup"))
1784 (regexp-quote target-group)
1787 ;; yes, Newsgroups line must change
1788 (message-cross-post-followup-to-header target-group)
1789 ;; insert note whether we do cross-post or followup-to
1790 (funcall message-cross-post-note-function
1792 (if (or (and message-cross-post-default
1793 (not current-prefix-arg))
1794 (and (not message-cross-post-default)
1795 current-prefix-arg)) t)
1796 in-old old-groups))))))))
1798 ;;; Reduce To: to Cc: or Bcc: header
1801 (defun message-reduce-to-to-cc ()
1802 "Replace contents of To: header with contents of Cc: or Bcc: header."
1804 (let ((cc-content (message-fetch-field "cc"))
1806 (if (and (not cc-content)
1807 (setq cc-content (message-fetch-field "bcc")))
1812 (message-delete-line)
1813 (insert (concat "To: " cc-content "\n"))
1814 (message-remove-header (if bcc
1818 ;;; End of functions adopted from `message-utils.el'.
1820 (defun message-remove-header (header &optional is-regexp first reverse)
1821 "Remove HEADER in the narrowed buffer.
1822 If IS-REGEXP, HEADER is a regular expression.
1823 If FIRST, only remove the first instance of the header.
1824 Return the number of headers removed."
1825 (goto-char (point-min))
1826 (let ((regexp (if is-regexp header (concat "^" (regexp-quote header) ":")))
1828 (case-fold-search t)
1830 (while (and (not (eobp))
1833 (not (looking-at regexp))
1834 (looking-at regexp))
1841 ;; There might be a continuation header, so we have to search
1842 ;; until we find a new non-continuation line.
1845 (if (re-search-forward "^[^ \t]" nil t)
1846 (goto-char (match-beginning 0))
1849 (if (re-search-forward "^[^ \t]" nil t)
1850 (goto-char (match-beginning 0))
1851 (goto-char (point-max)))))
1854 (defun message-remove-first-header (header)
1855 "Remove the first instance of HEADER if there is more than one."
1857 (regexp (concat "^" (regexp-quote header) ":")))
1859 (goto-char (point-min))
1860 (while (re-search-forward regexp nil t)
1863 (message-remove-header header nil t)
1866 (defun message-narrow-to-headers ()
1867 "Narrow the buffer to the head of the message."
1870 (goto-char (point-min))
1871 (if (re-search-forward
1872 (concat "^" (regexp-quote mail-header-separator) "\n") nil t)
1875 (goto-char (point-min)))
1877 (defun message-narrow-to-head-1 ()
1878 "Like `message-narrow-to-head'. Don't widen."
1880 (goto-char (point-min))
1881 (if (search-forward "\n\n" nil 1)
1884 (goto-char (point-min)))
1886 (defun message-narrow-to-head ()
1887 "Narrow the buffer to the head of the message.
1888 Point is left at the beginning of the narrowed-to region."
1890 (message-narrow-to-head-1))
1892 (defun message-narrow-to-headers-or-head ()
1893 "Narrow the buffer to the head of the message."
1896 (goto-char (point-min))
1899 (concat "^" (regexp-quote mail-header-separator) "\n") nil t)
1900 (match-beginning 0))
1901 ((search-forward "\n\n" nil t)
1905 (goto-char (point-min)))
1907 (defun message-news-p ()
1908 "Say whether the current buffer contains a news message."
1909 (and (not message-this-is-mail)
1910 (or message-this-is-news
1913 (message-narrow-to-headers)
1914 (and (message-fetch-field "newsgroups")
1915 (not (message-fetch-field "posted-to"))))))))
1917 (defun message-mail-p ()
1918 "Say whether the current buffer contains a mail message."
1919 (and (not message-this-is-news)
1920 (or message-this-is-mail
1923 (message-narrow-to-headers)
1924 (or (message-fetch-field "to")
1925 (message-fetch-field "cc")
1926 (message-fetch-field "bcc")))))))
1928 (defun message-subscribed-p ()
1929 "Say whether we need to insert a MFT header."
1930 (or message-subscribed-regexps
1931 message-subscribed-addresses
1932 message-subscribed-address-file
1933 message-subscribed-address-functions))
1935 (defun message-next-header ()
1936 "Go to the beginning of the next header."
1938 (or (eobp) (forward-char 1))
1939 (not (if (re-search-forward "^[^ \t]" nil t)
1941 (goto-char (point-max)))))
1943 (defun message-sort-headers-1 ()
1944 "Sort the buffer as headers using `message-rank' text props."
1945 (goto-char (point-min))
1948 nil 'message-next-header
1950 (message-next-header)
1954 (or (get-text-property (point) 'message-rank)
1957 (defun message-sort-headers ()
1958 "Sort the headers of the current message according to `message-header-format-alist'."
1962 (let ((max (1+ (length message-header-format-alist)))
1964 (message-narrow-to-headers)
1965 (while (re-search-forward "^[^ \n]+:" nil t)
1967 (match-beginning 0) (1+ (match-beginning 0))
1969 (if (setq rank (length (memq (assq (intern (buffer-substring
1971 (1- (match-end 0))))
1972 message-header-format-alist)
1973 message-header-format-alist)))
1976 (message-sort-headers-1))))
1987 (defvar message-mode-map nil)
1989 (unless message-mode-map
1990 (setq message-mode-map (make-keymap))
1991 (set-keymap-parent message-mode-map text-mode-map)
1992 (define-key message-mode-map "\C-c?" 'describe-mode)
1994 (define-key message-mode-map "\C-c\C-f\C-t" 'message-goto-to)
1995 (define-key message-mode-map "\C-c\C-f\C-o" 'message-goto-from)
1996 (define-key message-mode-map "\C-c\C-f\C-b" 'message-goto-bcc)
1997 (define-key message-mode-map "\C-c\C-f\C-w" 'message-goto-fcc)
1998 (define-key message-mode-map "\C-c\C-f\C-c" 'message-goto-cc)
1999 (define-key message-mode-map "\C-c\C-f\C-s" 'message-goto-subject)
2000 (define-key message-mode-map "\C-c\C-f\C-r" 'message-goto-reply-to)
2001 (define-key message-mode-map "\C-c\C-f\C-n" 'message-goto-newsgroups)
2002 (define-key message-mode-map "\C-c\C-f\C-d" 'message-goto-distribution)
2003 (define-key message-mode-map "\C-c\C-f\C-f" 'message-goto-followup-to)
2004 (define-key message-mode-map "\C-c\C-f\C-m" 'message-goto-mail-followup-to)
2005 (define-key message-mode-map "\C-c\C-f\C-k" 'message-goto-keywords)
2006 (define-key message-mode-map "\C-c\C-f\C-u" 'message-goto-summary)
2007 (define-key message-mode-map "\C-c\C-f\C-i"
2008 'message-insert-or-toggle-importance)
2009 (define-key message-mode-map "\C-c\C-f\C-a"
2010 'message-generate-unsubscribed-mail-followup-to)
2012 ;; modify headers (and insert notes in body)
2013 (define-key message-mode-map "\C-c\C-fs" 'message-change-subject)
2015 (define-key message-mode-map "\C-c\C-fx" 'message-cross-post-followup-to)
2016 ;; prefix+message-cross-post-followup-to = same w/o cross-post
2017 (define-key message-mode-map "\C-c\C-ft" 'message-reduce-to-to-cc)
2018 (define-key message-mode-map "\C-c\C-fa" 'message-add-archive-header)
2019 ;; mark inserted text
2020 (define-key message-mode-map "\C-c\M-m" 'message-mark-inserted-region)
2021 (define-key message-mode-map "\C-c\M-f" 'message-mark-insert-file)
2023 (define-key message-mode-map "\C-c\C-b" 'message-goto-body)
2024 (define-key message-mode-map "\C-c\C-i" 'message-goto-signature)
2026 (define-key message-mode-map "\C-c\C-t" 'message-insert-to)
2027 (define-key message-mode-map "\C-c\C-fw" 'message-insert-wide-reply)
2028 (define-key message-mode-map "\C-c\C-n" 'message-insert-newsgroups)
2029 (define-key message-mode-map "\C-c\C-l" 'message-to-list-only)
2031 (define-key message-mode-map "\C-c\C-u" 'message-insert-or-toggle-importance)
2032 (define-key message-mode-map "\C-c\M-n"
2033 'message-insert-disposition-notification-to)
2035 (define-key message-mode-map "\C-c\C-y" 'message-yank-original)
2036 (define-key message-mode-map "\C-c\M-\C-y" 'message-yank-buffer)
2037 (define-key message-mode-map "\C-c\C-q" 'message-fill-yanked-message)
2038 (define-key message-mode-map "\C-c\C-w" 'message-insert-signature)
2039 (define-key message-mode-map "\C-c\M-h" 'message-insert-headers)
2040 (define-key message-mode-map "\C-c\C-r" 'message-caesar-buffer-body)
2041 (define-key message-mode-map "\C-c\C-o" 'message-sort-headers)
2042 (define-key message-mode-map "\C-c\M-r" 'message-rename-buffer)
2044 (define-key message-mode-map "\C-c\C-c" 'message-send-and-exit)
2045 (define-key message-mode-map "\C-c\C-s" 'message-send)
2046 (define-key message-mode-map "\C-c\C-k" 'message-kill-buffer)
2047 (define-key message-mode-map "\C-c\C-d" 'message-dont-send)
2048 (define-key message-mode-map "\C-c\n" 'gnus-delay-article)
2050 (define-key message-mode-map "\C-c\C-e" 'message-elide-region)
2051 (define-key message-mode-map "\C-c\C-v" 'message-delete-not-region)
2052 (define-key message-mode-map "\C-c\C-z" 'message-kill-to-signature)
2053 (define-key message-mode-map "\M-\r" 'message-newline-and-reformat)
2054 ;;(define-key message-mode-map "\M-q" 'message-fill-paragraph)
2056 (define-key message-mode-map "\C-c\C-a" 'mml-attach-file)
2058 (define-key message-mode-map "\C-a" 'message-beginning-of-line)
2059 (define-key message-mode-map "\t" 'message-tab)
2060 (define-key message-mode-map "\M-;" 'comment-region))
2063 message-mode-menu message-mode-map "Message Menu."
2065 ["Yank Original" message-yank-original message-reply-buffer]
2066 ["Fill Yanked Message" message-fill-yanked-message t]
2067 ["Insert Signature" message-insert-signature t]
2068 ["Caesar (rot13) Message" message-caesar-buffer-body t]
2069 ["Caesar (rot13) Region" message-caesar-region (message-mark-active-p)]
2070 ["Elide Region" message-elide-region
2071 :active (message-mark-active-p)
2072 ,@(if (featurep 'xemacs) nil
2073 '(:help "Replace text in region with an ellipsis"))]
2074 ["Delete Outside Region" message-delete-not-region
2075 :active (message-mark-active-p)
2076 ,@(if (featurep 'xemacs) nil
2077 '(:help "Delete all quoted text outside region"))]
2078 ["Kill To Signature" message-kill-to-signature t]
2079 ["Newline and Reformat" message-newline-and-reformat t]
2080 ["Rename buffer" message-rename-buffer t]
2081 ["Spellcheck" ispell-message
2082 ,@(if (featurep 'xemacs) '(t)
2083 '(:help "Spellcheck this message"))]
2085 ["Insert Region Marked" message-mark-inserted-region
2086 :active (message-mark-active-p)
2087 ,@(if (featurep 'xemacs) nil
2088 '(:help "Mark region with enclosing tags"))]
2089 ["Insert File Marked..." message-mark-insert-file
2090 ,@(if (featurep 'xemacs) '(t)
2091 '(:help "Insert file at point marked with enclosing tags"))]
2093 ["Send Message" message-send-and-exit
2094 ,@(if (featurep 'xemacs) '(t)
2095 '(:help "Send this message"))]
2096 ["Postpone Message" message-dont-send
2097 ,@(if (featurep 'xemacs) '(t)
2098 '(:help "File this draft message and exit"))]
2099 ["Send at Specific Time..." gnus-delay-article
2100 ,@(if (featurep 'xemacs) '(t)
2101 '(:help "Ask, then arrange to send message at that time"))]
2102 ["Kill Message" message-kill-buffer
2103 ,@(if (featurep 'xemacs) '(t)
2104 '(:help "Delete this message without sending"))]))
2107 message-mode-field-menu message-mode-map ""
2109 ["Fetch To" message-insert-to t]
2110 ["Fetch Newsgroups" message-insert-newsgroups t]
2112 ["To" message-goto-to t]
2113 ["From" message-goto-from t]
2114 ["Subject" message-goto-subject t]
2115 ["Change subject..." message-change-subject t]
2116 ["Cc" message-goto-cc t]
2117 ["Bcc" message-goto-bcc t]
2118 ["Fcc" message-goto-fcc t]
2119 ["Reply-To" message-goto-reply-to t]
2120 ["Flag As Important" message-insert-importance-high
2121 ,@(if (featurep 'xemacs) '(t)
2122 '(:help "Mark this message as important"))]
2123 ["Flag As Unimportant" message-insert-importance-low
2124 ,@(if (featurep 'xemacs) '(t)
2125 '(:help "Mark this message as unimportant"))]
2127 message-insert-disposition-notification-to
2128 ,@(if (featurep 'xemacs) '(t)
2129 '(:help "Request a receipt notification"))]
2131 ;; (typical) news stuff
2132 ["Summary" message-goto-summary t]
2133 ["Keywords" message-goto-keywords t]
2134 ["Newsgroups" message-goto-newsgroups t]
2135 ["Followup-To" message-goto-followup-to t]
2136 ;; ["Followup-To (with note in body)" message-cross-post-followup-to t]
2137 ["Crosspost / Followup-To..." message-cross-post-followup-to t]
2138 ["Distribution" message-goto-distribution t]
2139 ["X-No-Archive:" message-add-archive-header t ]
2141 ;; (typical) mailing-lists stuff
2142 ["Send to list only" message-to-list-only t]
2143 ["Mail-Followup-To" message-goto-mail-followup-to t]
2144 ["Reduce To: to Cc:" message-reduce-to-to-cc t]
2146 ["Sort Headers" message-sort-headers t]
2147 ["Goto Body" message-goto-body t]
2148 ["Goto Signature" message-goto-signature t]))
2150 (defvar message-tool-bar-map nil)
2153 (defvar facemenu-add-face-function)
2154 (defvar facemenu-remove-face-function))
2156 ;;; Forbidden properties
2158 ;; We use `after-change-functions' to keep special text properties
2159 ;; that interfer with the normal function of message mode out of the
2162 (defcustom message-strip-special-text-properties t
2163 "Strip special properties from the message buffer.
2165 Emacs has a number of special text properties which can break message
2166 composing in various ways. If this option is set, message will strip
2167 these properties from the message composition buffer. However, some
2168 packages requires these properties to be present in order to work.
2169 If you use one of these packages, turn this option off, and hope the
2170 message composition doesn't break too bad."
2171 :group 'message-various
2174 (defconst message-forbidden-properties
2175 ;; No reason this should be clutter up customize. We make it a
2176 ;; property list (rather than a list of property symbols), to be
2177 ;; directly useful for `remove-text-properties'.
2178 '(field nil read-only nil intangible nil invisible nil
2179 mouse-face nil modification-hooks nil insert-in-front-hooks nil
2180 insert-behind-hooks nil point-entered nil point-left nil)
2181 ;; Other special properties:
2182 ;; category, face, display: probably doesn't do any harm.
2183 ;; fontified: is used by font-lock.
2184 ;; syntax-table, local-map: I dunno.
2185 ;; We need to add XEmacs names to the list.
2186 "Property list of with properties.forbidden in message buffers.
2187 The values of the properties are ignored, only the property names are used.")
2189 (defun message-tamago-not-in-use-p (pos)
2190 "Return t when tamago version 4 is not in use at the cursor position.
2191 Tamago version 4 is a popular input method for writing Japanese text.
2192 It uses the properties `intangible', `invisible', `modification-hooks'
2193 and `read-only' when translating ascii or kana text to kanji text.
2194 These properties are essential to work, so we should never strip them."
2195 (not (and (boundp 'egg-modefull-mode)
2196 (symbol-value 'egg-modefull-mode)
2197 (or (memq (get-text-property pos 'intangible)
2198 '(its-part-1 its-part-2))
2199 (get-text-property pos 'egg-end)
2200 (get-text-property pos 'egg-lang)
2201 (get-text-property pos 'egg-start)))))
2203 (defun message-strip-forbidden-properties (begin end &optional old-length)
2204 "Strip forbidden properties between BEGIN and END, ignoring the third arg.
2205 This function is intended to be called from `after-change-functions'.
2206 See also `message-forbidden-properties'."
2207 (when (and message-strip-special-text-properties
2208 (message-tamago-not-in-use-p begin))
2209 (remove-text-properties begin end message-forbidden-properties)))
2212 (define-derived-mode message-mode text-mode "Message"
2213 "Major mode for editing mail and news to be sent.
2214 Like Text Mode but with these additional commands:\\<message-mode-map>
2215 C-c C-s `message-send' (send the message) C-c C-c `message-send-and-exit'
2216 C-c C-d Postpone sending the message C-c C-k Kill the message
2217 C-c C-f move to a header field (and create it if there isn't):
2218 C-c C-f C-t move to To C-c C-f C-s move to Subject
2219 C-c C-f C-c move to Cc C-c C-f C-b move to Bcc
2220 C-c C-f C-w move to Fcc C-c C-f C-r move to Reply-To
2221 C-c C-f C-u move to Summary C-c C-f C-n move to Newsgroups
2222 C-c C-f C-k move to Keywords C-c C-f C-d move to Distribution
2223 C-c C-f C-o move to From (\"Originator\")
2224 C-c C-f C-f move to Followup-To
2225 C-c C-f C-m move to Mail-Followup-To
2226 C-c C-f C-i cycle through Importance values
2227 C-c C-f s change subject and append \"(was: <Old Subject>)\"
2228 C-c C-f x crossposting with FollowUp-To header and note in body
2229 C-c C-f t replace To: header with contents of Cc: or Bcc:
2230 C-c C-f a Insert X-No-Archive: header and a note in the body
2231 C-c C-t `message-insert-to' (add a To header to a news followup)
2232 C-c C-l `message-to-list-only' (removes all but list address in to/cc)
2233 C-c C-n `message-insert-newsgroups' (add a Newsgroup header to a news reply)
2234 C-c C-b `message-goto-body' (move to beginning of message text).
2235 C-c C-i `message-goto-signature' (move to the beginning of the signature).
2236 C-c C-w `message-insert-signature' (insert `message-signature-file' file).
2237 C-c C-y `message-yank-original' (insert current message, if any).
2238 C-c C-q `message-fill-yanked-message' (fill what was yanked).
2239 C-c C-e `message-elide-region' (elide the text between point and mark).
2240 C-c C-v `message-delete-not-region' (remove the text outside the region).
2241 C-c C-z `message-kill-to-signature' (kill the text up to the signature).
2242 C-c C-r `message-caesar-buffer-body' (rot13 the message body).
2243 C-c C-a `mml-attach-file' (attach a file as MIME).
2244 C-c C-u `message-insert-or-toggle-importance' (insert or cycle importance).
2245 C-c M-n `message-insert-disposition-notification-to' (request receipt).
2246 C-c M-m `message-mark-inserted-region' (mark region with enclosing tags).
2247 C-c M-f `message-mark-insert-file' (insert file marked with enclosing tags).
2248 M-RET `message-newline-and-reformat' (break the line and reformat)."
2249 (setq local-abbrev-table text-mode-abbrev-table)
2250 (set (make-local-variable 'message-reply-buffer) nil)
2251 (make-local-variable 'message-send-actions)
2252 (make-local-variable 'message-exit-actions)
2253 (make-local-variable 'message-kill-actions)
2254 (make-local-variable 'message-postpone-actions)
2255 (make-local-variable 'message-draft-article)
2256 (setq buffer-offer-save t)
2257 (set (make-local-variable 'facemenu-add-face-function)
2259 (let ((face-fun (cdr (assq face message-face-alist))))
2261 (funcall face-fun (point) end)
2262 (error "Face %s not configured for %s mode" face mode-name)))
2264 (set (make-local-variable 'facemenu-remove-face-function) t)
2265 (set (make-local-variable 'message-reply-headers) nil)
2266 (make-local-variable 'message-newsreader)
2267 (make-local-variable 'message-mailer)
2268 (make-local-variable 'message-post-method)
2269 (set (make-local-variable 'message-sent-message-via) nil)
2270 (set (make-local-variable 'message-checksum) nil)
2271 (set (make-local-variable 'message-mime-part) 0)
2272 (message-setup-fill-variables)
2273 (set (make-local-variable 'paragraph-separate)
2274 (concat paragraph-separate
2275 "\\|<#!*/?\\(multipart\\|part\\|external\\|mml\\|secure\\)"))
2276 ;; Allow using comment commands to add/remove quoting.
2277 (set (make-local-variable 'comment-start) message-yank-prefix)
2278 (if (featurep 'xemacs)
2279 (message-setup-toolbar)
2280 (set (make-local-variable 'font-lock-defaults)
2281 '(message-font-lock-keywords t))
2282 (if (boundp 'tool-bar-map)
2283 (set (make-local-variable 'tool-bar-map) (message-tool-bar-map))))
2284 (easy-menu-add message-mode-menu message-mode-map)
2285 (easy-menu-add message-mode-field-menu message-mode-map)
2286 ;; make-local-hook is harmless though obsolete in Emacs 21.
2287 ;; Emacs 20 and XEmacs need make-local-hook.
2288 (make-local-hook 'after-change-functions)
2289 ;; Mmmm... Forbidden properties...
2290 (add-hook 'after-change-functions 'message-strip-forbidden-properties
2292 ;; Allow mail alias things.
2293 (when (eq message-mail-alias-type 'abbrev)
2294 (if (fboundp 'mail-abbrevs-setup)
2295 (mail-abbrevs-setup)
2296 (mail-aliases-setup)))
2297 (unless buffer-file-name
2298 (message-set-auto-save-file-name))
2299 (unless (buffer-base-buffer)
2300 ;; Don't enable multibyte on an indirect buffer. Maybe enabling
2301 ;; multibyte is not necessary at all. -- zsh
2302 (mm-enable-multibyte))
2303 (set (make-local-variable 'indent-tabs-mode) nil) ;No tabs for indentation.
2306 (defun message-setup-fill-variables ()
2307 "Setup message fill variables."
2308 (set (make-local-variable 'fill-paragraph-function)
2309 'message-fill-paragraph)
2310 (make-local-variable 'paragraph-separate)
2311 (make-local-variable 'paragraph-start)
2312 (make-local-variable 'adaptive-fill-regexp)
2313 (unless (boundp 'adaptive-fill-first-line-regexp)
2314 (setq adaptive-fill-first-line-regexp nil))
2315 (make-local-variable 'adaptive-fill-first-line-regexp)
2316 (let ((quote-prefix-regexp
2317 ;; User should change message-cite-prefix-regexp if
2318 ;; message-yank-prefix is set to an abnormal value.
2319 (concat "\\(" message-cite-prefix-regexp "\\)[ \t]*")))
2320 (setq paragraph-start
2322 (regexp-quote mail-header-separator) "$\\|"
2323 "[ \t]*$\\|" ; blank lines
2324 "-- $\\|" ; signature delimiter
2325 "---+$\\|" ; delimiters for forwarded messages
2326 page-delimiter "$\\|" ; spoiler warnings
2327 ".*wrote:$\\|" ; attribution lines
2328 quote-prefix-regexp "$")) ; empty lines in quoted text
2329 (setq paragraph-separate paragraph-start)
2330 (setq adaptive-fill-regexp
2331 (concat quote-prefix-regexp "\\|" adaptive-fill-regexp))
2332 (setq adaptive-fill-first-line-regexp
2333 (concat quote-prefix-regexp "\\|"
2334 adaptive-fill-first-line-regexp)))
2335 (make-local-variable 'auto-fill-inhibit-regexp)
2336 ;;(setq auto-fill-inhibit-regexp "^[A-Z][^: \n\t]+:")
2337 (setq auto-fill-inhibit-regexp nil)
2338 (make-local-variable 'normal-auto-fill-function)
2339 (setq normal-auto-fill-function 'message-do-auto-fill)
2340 ;; KLUDGE: auto fill might already be turned on in `text-mode-hook'.
2341 ;; In that case, ensure that it uses the right function. The real
2342 ;; solution would be not to use `define-derived-mode', and run
2343 ;; `text-mode-hook' ourself at the end of the mode.
2344 ;; -- Per Abrahamsen <abraham@dina.kvl.dk> Date: 2001-10-19.
2345 (when auto-fill-function
2346 (setq auto-fill-function normal-auto-fill-function)))
2351 ;;; Message mode commands
2354 ;;; Movement commands
2356 (defun message-goto-to ()
2357 "Move point to the To header."
2359 (message-position-on-field "To"))
2361 (defun message-goto-from ()
2362 "Move point to the From header."
2364 (message-position-on-field "From"))
2366 (defun message-goto-subject ()
2367 "Move point to the Subject header."
2369 (message-position-on-field "Subject"))
2371 (defun message-goto-cc ()
2372 "Move point to the Cc header."
2374 (message-position-on-field "Cc" "To"))
2376 (defun message-goto-bcc ()
2377 "Move point to the Bcc header."
2379 (message-position-on-field "Bcc" "Cc" "To"))
2381 (defun message-goto-fcc ()
2382 "Move point to the Fcc header."
2384 (message-position-on-field "Fcc" "To" "Newsgroups"))
2386 (defun message-goto-reply-to ()
2387 "Move point to the Reply-To header."
2389 (message-position-on-field "Reply-To" "Subject"))
2391 (defun message-goto-newsgroups ()
2392 "Move point to the Newsgroups header."
2394 (message-position-on-field "Newsgroups"))
2396 (defun message-goto-distribution ()
2397 "Move point to the Distribution header."
2399 (message-position-on-field "Distribution"))
2401 (defun message-goto-followup-to ()
2402 "Move point to the Followup-To header."
2404 (message-position-on-field "Followup-To" "Newsgroups"))
2406 (defun message-goto-mail-followup-to ()
2407 "Move point to the Mail-Followup-To header."
2409 (message-position-on-field "Mail-Followup-To" "From"))
2411 (defun message-goto-keywords ()
2412 "Move point to the Keywords header."
2414 (message-position-on-field "Keywords" "Subject"))
2416 (defun message-goto-summary ()
2417 "Move point to the Summary header."
2419 (message-position-on-field "Summary" "Subject"))
2421 (defun message-goto-body (&optional interactivep)
2422 "Move point to the beginning of the message body."
2423 (interactive (list t))
2424 (when (and interactivep
2425 (looking-at "[ \t]*\n"))
2427 (goto-char (point-min))
2428 (or (search-forward (concat "\n" mail-header-separator "\n") nil t)
2429 (search-forward-regexp "[^:]+:\\([^\n]\\|\n[ \t]\\)+\n\n" nil t)))
2431 (defun message-goto-eoh ()
2432 "Move point to the end of the headers."
2437 (defun message-goto-signature ()
2438 "Move point to the beginning of the message signature.
2439 If there is no signature in the article, go to the end and
2442 (goto-char (point-min))
2443 (if (re-search-forward message-signature-separator nil t)
2445 (goto-char (point-max))
2448 (defun message-generate-unsubscribed-mail-followup-to (&optional include-cc)
2449 "Insert a reasonable MFT header in a post to an unsubscribed list.
2450 When making original posts to a mailing list you are not subscribed to,
2451 you have to type in a MFT header by hand. The contents, usually, are
2452 the addresses of the list and your own address. This function inserts
2453 such a header automatically. It fetches the contents of the To: header
2454 in the current mail buffer, and appends the current `user-mail-address'.
2456 If the optional argument INCLUDE-CC is non-nil, the addresses in the
2457 Cc: header are also put into the MFT."
2460 (message-remove-header "Mail-Followup-To")
2461 (let* ((cc (and include-cc (message-fetch-field "Cc")))
2463 (concat (message-fetch-field "To") "," cc)
2464 (message-fetch-field "To"))))
2465 (message-goto-mail-followup-to)
2466 (insert (concat tos ", " user-mail-address))))
2470 (defun message-insert-to (&optional force)
2471 "Insert a To header that points to the author of the article being replied to.
2472 If the original author requested not to be sent mail, the function signals
2474 With the prefix argument FORCE, insert the header anyway."
2476 (let ((co (message-fetch-reply-field "mail-copies-to")))
2477 (when (and (null force)
2479 (or (equal (downcase co) "never")
2480 (equal (downcase co) "nobody")))
2481 (error "The user has requested not to have copies sent via mail")))
2482 (message-carefully-insert-headers
2484 (or (message-fetch-reply-field "mail-reply-to")
2485 (message-fetch-reply-field "reply-to")
2486 (message-fetch-reply-field "from")
2489 (defun message-insert-wide-reply ()
2490 "Insert To and Cc headers as if you were doing a wide reply."
2492 (let ((headers (message-with-reply-buffer
2493 (message-get-reply-headers t))))
2494 (message-carefully-insert-headers headers)))
2496 (defun message-carefully-insert-headers (headers)
2497 (dolist (header headers)
2498 (let ((header-name (symbol-name (car header))))
2499 (when (and (message-position-on-field header-name)
2500 (mail-fetch-field header-name)
2501 (not (string-match "\\` *\\'"
2502 (mail-fetch-field header-name))))
2504 (insert (cdr header)))))
2506 (defun message-widen-reply ()
2507 "Widen the reply to include maximum recipients."
2510 (and message-reply-buffer
2511 (buffer-name message-reply-buffer)
2513 (set-buffer message-reply-buffer)
2514 (message-get-reply-headers t)))))
2517 (message-narrow-to-headers)
2518 (dolist (elem follow-to)
2519 (message-remove-header (symbol-name (car elem)))
2520 (goto-char (point-min))
2521 (insert (symbol-name (car elem)) ": "
2522 (cdr elem) "\n"))))))
2524 (defun message-insert-newsgroups ()
2525 "Insert the Newsgroups header from the article being replied to."
2527 (when (and (message-position-on-field "Newsgroups")
2528 (mail-fetch-field "newsgroups")
2529 (not (string-match "\\` *\\'" (mail-fetch-field "newsgroups"))))
2531 (insert (or (message-fetch-reply-field "newsgroups") "")))
2535 ;;; Various commands
2537 (defun message-delete-not-region (beg end)
2538 "Delete everything in the body of the current message outside of the region."
2543 ;; snarf citation prefix, if appropriate
2544 (unless (eq (point) (progn (beginning-of-line) (point)))
2545 (when (looking-at message-cite-prefix-regexp)
2546 (setq citeprefix (match-string 0))))
2548 (delete-region (point) (if (not (message-goto-signature))
2554 (delete-region beg (progn (message-goto-body)
2558 (insert citeprefix))))
2559 (when (message-goto-signature)
2562 (defun message-kill-to-signature ()
2563 "Deletes all text up to the signature."
2565 (let ((point (point)))
2566 (message-goto-signature)
2569 (kill-region point (point))
2573 (defun message-newline-and-reformat (&optional arg not-break)
2574 "Insert four newlines, and then reformat if inside quoted text.
2575 Prefix arg means justify as well."
2576 (interactive (list (if current-prefix-arg 'full)))
2577 (let (quoted point beg end leading-space bolp)
2578 (setq point (point))
2581 (setq bolp (= beg point))
2582 ;; Find first line of the paragraph.
2584 (while (and (not (eobp))
2585 (not (looking-at message-cite-prefix-regexp))
2586 (looking-at paragraph-start))
2589 (when (looking-at message-cite-prefix-regexp)
2590 (setq quoted (match-string 0))
2591 (goto-char (match-end 0))
2592 (looking-at "[ \t]*")
2593 (setq leading-space (match-string 0)))
2597 (< (- point beg) (length quoted)))
2598 ;; break inside the cite prefix.
2604 (while (and (not (eobp))
2605 (not (looking-at paragraph-separate))
2606 (looking-at message-cite-prefix-regexp)
2607 (equal quoted (match-string 0)))
2608 (goto-char (match-end 0))
2609 (looking-at "[ \t]*")
2610 (if (> (length leading-space) (length (match-string 0)))
2611 (setq leading-space (match-string 0)))
2615 (while (and (if (bobp) nil (forward-line -1) t)
2616 (not (looking-at paragraph-start))
2617 (looking-at message-cite-prefix-regexp)
2618 (equal quoted (match-string 0)))
2620 (goto-char (match-end 0))
2621 (looking-at "[ \t]*")
2622 (if (> (length leading-space) (length (match-string 0)))
2623 (setq leading-space (match-string 0)))))
2624 (while (and (not (eobp))
2625 (not (looking-at paragraph-separate))
2626 (not (looking-at message-cite-prefix-regexp)))
2630 (while (and (if (bobp) nil (forward-line -1) t)
2631 (not (looking-at paragraph-start))
2632 (not (looking-at message-cite-prefix-regexp)))
2633 (setq beg (point))))
2636 (narrow-to-region beg end)
2643 (setq point (point))
2644 ;; (newline 2) doesn't mark both newline's as hard, so call
2645 ;; newline twice. -jas
2648 (delete-region (point) (re-search-forward "[ \t]*"))
2649 (when (and quoted (not bolp))
2650 (insert quoted leading-space)))
2652 (let* ((adaptive-fill-regexp
2653 (regexp-quote (concat quoted leading-space)))
2654 (adaptive-fill-first-line-regexp
2655 adaptive-fill-regexp ))
2656 (fill-paragraph arg))
2657 (fill-paragraph arg))
2658 (if point (goto-char point)))))
2660 (defun message-fill-paragraph (&optional arg)
2661 "Like `fill-paragraph'."
2662 (interactive (list (if current-prefix-arg 'full)))
2663 (if (and (boundp 'filladapt-mode) filladapt-mode)
2665 (message-newline-and-reformat arg t)
2668 ;; Is it better to use `mail-header-end'?
2669 (defun message-point-in-header-p ()
2670 "Return t if point is in the header."
2673 (goto-char (point-min))
2674 (not (re-search-forward
2675 (concat "^" (regexp-quote mail-header-separator) "\n")
2678 (defun message-do-auto-fill ()
2679 "Like `do-auto-fill', but don't fill in message header."
2680 (unless (message-point-in-header-p)
2683 (defun message-insert-signature (&optional force)
2684 "Insert a signature. See documentation for variable `message-signature'."
2685 (interactive (list 0))
2688 ((and (null message-signature)
2691 (goto-char (point-max))
2692 (not (re-search-backward message-signature-separator nil t))))
2693 ((and (null message-signature)
2696 ((message-functionp message-signature)
2697 (funcall message-signature))
2698 ((listp message-signature)
2699 (eval message-signature))
2700 (t message-signature)))
2702 (cond ((stringp signature)
2704 ((and (eq t signature)
2705 message-signature-file
2706 (file-exists-p message-signature-file))
2709 (goto-char (point-max))
2710 ;; Insert the signature.
2713 (when message-signature-insert-empty-line
2716 (if (eq signature t)
2717 (insert-file-contents message-signature-file)
2719 (goto-char (point-max))
2720 (or (bolp) (insert "\n")))))
2722 (defun message-insert-importance-high ()
2723 "Insert header to mark message as important."
2726 (message-remove-header "Importance")
2728 (insert "Importance: high\n")))
2730 (defun message-insert-importance-low ()
2731 "Insert header to mark message as unimportant."
2734 (message-remove-header "Importance")
2736 (insert "Importance: low\n")))
2738 (defun message-insert-or-toggle-importance ()
2739 "Insert a \"Importance: high\" header, or cycle through the header values.
2740 The three allowed values according to RFC 1327 are `high', `normal'
2744 (let ((valid '("high" "normal" "low"))
2747 (when (setq cur (message-fetch-field "Importance"))
2748 (message-remove-header "Importance")
2749 (setq new (cond ((string= cur "high")
2751 ((string= cur "low")
2756 (insert (format "Importance: %s\n" new)))))
2758 (defun message-insert-disposition-notification-to ()
2759 "Request a disposition notification (return receipt) to this message.
2760 Note that this should not be used in newsgroups."
2763 (message-remove-header "Disposition-Notification-To")
2765 (insert (format "Disposition-Notification-To: %s\n"
2766 (or (message-fetch-field "From") (message-make-from))))))
2768 (defun message-elide-region (b e)
2769 "Elide the text in the region.
2770 An ellipsis (from `message-elide-ellipsis') will be inserted where the
2774 (insert message-elide-ellipsis))
2776 (defvar message-caesar-translation-table nil)
2778 (defun message-caesar-region (b e &optional n)
2779 "Caesar rotate region B to E by N, default 13, for decrypting netnews."
2782 (min (point) (or (mark t) (point)))
2783 (max (point) (or (mark t) (point)))
2784 (when current-prefix-arg
2785 (prefix-numeric-value current-prefix-arg))))
2787 (setq n (if (numberp n) (mod n 26) 13)) ;canonize N
2788 (unless (or (zerop n) ; no action needed for a rot of 0
2789 (= b e)) ; no region to rotate
2790 ;; We build the table, if necessary.
2791 (when (or (not message-caesar-translation-table)
2792 (/= (aref message-caesar-translation-table ?a) (+ ?a n)))
2793 (setq message-caesar-translation-table
2794 (message-make-caesar-translation-table n)))
2795 (translate-region b e message-caesar-translation-table)))
2797 (defun message-make-caesar-translation-table (n)
2798 "Create a rot table with offset N."
2800 (table (make-string 256 0)))
2801 (while (< (incf i) 256)
2804 (substring table 0 ?A)
2805 (substring table (+ ?A n) (+ ?A n (- 26 n)))
2806 (substring table ?A (+ ?A n))
2807 (substring table (+ ?A 26) ?a)
2808 (substring table (+ ?a n) (+ ?a n (- 26 n)))
2809 (substring table ?a (+ ?a n))
2810 (substring table (+ ?a 26) 255))))
2812 (defun message-caesar-buffer-body (&optional rotnum)
2813 "Caesar rotate all letters in the current buffer by 13 places.
2814 Used to encode/decode possibly offensive messages (commonly in rec.humor).
2815 With prefix arg, specifies the number of places to rotate each letter forward.
2816 Mail and USENET news headers are not rotated."
2817 (interactive (if current-prefix-arg
2818 (list (prefix-numeric-value current-prefix-arg))
2822 (when (message-goto-body)
2823 (narrow-to-region (point) (point-max)))
2824 (message-caesar-region (point-min) (point-max) rotnum))))
2826 (defun message-pipe-buffer-body (program)
2827 "Pipe the message body in the current buffer through PROGRAM."
2830 (when (message-goto-body)
2831 (narrow-to-region (point) (point-max)))
2832 (shell-command-on-region
2833 (point-min) (point-max) program nil t))))
2835 (defun message-rename-buffer (&optional enter-string)
2836 "Rename the *message* buffer to \"*message* RECIPIENT\".
2837 If the function is run with a prefix, it will ask for a new buffer
2838 name, rather than giving an automatic name."
2839 (interactive "Pbuffer name: ")
2842 (goto-char (point-min))
2843 (narrow-to-region (point)
2844 (search-forward mail-header-separator nil 'end))
2846 (if (message-news-p) (message-fetch-field "Newsgroups")
2847 (message-fetch-field "To"))
2850 (if (string-match "," mail-to)
2851 (concat (substring mail-to 0 (match-beginning 0)) ", ...")
2853 (name-default (concat "*message* " mail-trimmed-to))
2854 (name (if enter-string
2855 (read-string "New buffer name: " name-default)
2857 (rename-buffer name t)))))
2859 (defun message-fill-yanked-message (&optional justifyp)
2860 "Fill the paragraphs of a message yanked into this one.
2861 Numeric argument means justify as well."
2864 (goto-char (point-min))
2865 (search-forward (concat "\n" mail-header-separator "\n") nil t)
2866 (let ((fill-prefix message-yank-prefix))
2867 (fill-individual-paragraphs (point) (point-max) justifyp))))
2869 (defun message-indent-citation ()
2870 "Modify text just inserted from a message to be cited.
2871 The inserted text should be the region.
2872 When this function returns, the region is again around the modified text.
2874 Normally, indent each nonblank line `message-indentation-spaces' spaces.
2875 However, if `message-yank-prefix' is non-nil, insert that prefix on each line."
2876 (let ((start (point)))
2877 ;; Remove unwanted headers.
2878 (when message-ignored-cited-headers
2883 (if (search-forward "\n\n" nil t)
2886 (message-remove-header message-ignored-cited-headers t)
2887 (when (= (point-min) (point-max))
2888 (setq all-removed t))
2889 (goto-char (point-max)))
2893 ;; Delete blank lines at the start of the buffer.
2894 (while (and (point-min)
2897 (message-delete-line))
2898 ;; Delete blank lines at the end of the buffer.
2899 (goto-char (point-max))
2902 (while (and (zerop (forward-line -1))
2904 (message-delete-line))
2905 ;; Do the indentation.
2906 (if (null message-yank-prefix)
2907 (indent-rigidly start (mark t) message-indentation-spaces)
2910 (while (< (point) (mark t))
2911 (if (or (looking-at ">") (looking-at "^$"))
2912 (insert message-yank-cited-prefix)
2913 (insert message-yank-prefix))
2917 (defun message-yank-original (&optional arg)
2918 "Insert the message being replied to, if any.
2919 Puts point before the text and mark after.
2920 Normally indents each nonblank line ARG spaces (default 3). However,
2921 if `message-yank-prefix' is non-nil, insert that prefix on each line.
2923 This function uses `message-cite-function' to do the actual citing.
2925 Just \\[universal-argument] as argument means don't indent, insert no
2926 prefix, and don't delete any headers."
2928 (let ((modified (buffer-modified-p)))
2929 (when (and message-reply-buffer
2930 message-cite-function)
2931 (delete-windows-on message-reply-buffer t)
2932 (insert-buffer message-reply-buffer)
2934 (funcall message-cite-function))
2935 (message-exchange-point-and-mark)
2939 (setq message-checksum (message-checksum))))))
2941 (defun message-yank-buffer (buffer)
2942 "Insert BUFFER into the current buffer and quote it."
2943 (interactive "bYank buffer: ")
2944 (let ((message-reply-buffer buffer))
2945 (save-window-excursion
2946 (message-yank-original))))
2948 (defun message-buffers ()
2949 "Return a list of active message buffers."
2952 (dolist (buffer (buffer-list t))
2954 (when (and (eq major-mode 'message-mode)
2955 (null message-sent-message-via))
2956 (push (buffer-name buffer) buffers))))
2957 (nreverse buffers)))
2959 (defun message-cite-original-without-signature ()
2960 "Cite function in the standard Message manner."
2961 (let ((start (point))
2964 (when message-indent-citation-function
2965 (if (listp message-indent-citation-function)
2966 message-indent-citation-function
2967 (list message-indent-citation-function)))))
2968 (mml-quote-region start end)
2972 (when (re-search-backward message-signature-separator start t)
2973 ;; Also peel off any blank lines before the signature.
2975 (while (looking-at "^[ \t]*$")
2978 (delete-region (point) end)
2979 (unless (search-backward "\n\n" start t)
2980 ;; Insert a blank line if it is peeled off.
2984 (funcall (pop functions)))
2985 (when message-citation-line-function
2988 (funcall message-citation-line-function))))
2990 (eval-when-compile (defvar mail-citation-hook)) ;Compiler directive
2991 (defun message-cite-original ()
2992 "Cite function in the standard Message manner."
2993 (if (and (boundp 'mail-citation-hook)
2995 (run-hooks 'mail-citation-hook)
2996 (let ((start (point))
2999 (when message-indent-citation-function
3000 (if (listp message-indent-citation-function)
3001 message-indent-citation-function
3002 (list message-indent-citation-function)))))
3003 (mml-quote-region start end)
3006 (funcall (pop functions)))
3007 (when message-citation-line-function
3010 (funcall message-citation-line-function)))))
3012 (defun message-insert-citation-line ()
3013 "Insert a simple citation line."
3014 (when message-reply-headers
3015 (insert (mail-header-from message-reply-headers) " writes:\n\n")))
3017 (defun message-position-on-field (header &rest afters)
3018 (let ((case-fold-search t))
3021 (goto-char (point-min))
3024 (concat "^" (regexp-quote mail-header-separator) "$"))
3025 (match-beginning 0)))
3026 (goto-char (point-min))
3027 (if (re-search-forward (concat "^" (regexp-quote header) ":") nil t)
3029 (re-search-forward "^[^ \t]" nil 'move)
3031 (skip-chars-backward "\n")
3034 (not (re-search-forward
3035 (concat "^" (regexp-quote (car afters)) ":")
3039 (re-search-forward "^[^ \t]" nil 'move)
3040 (beginning-of-line))
3041 (insert header ": \n")
3045 (defun message-remove-signature ()
3046 "Remove the signature from the text between point and mark.
3047 The text will also be indented the normal way."
3049 (let ((start (point))
3051 (if (not (re-search-forward message-signature-separator (mark t) t))
3052 ;; No signature here, so we just indent the cited text.
3053 (message-indent-citation)
3054 ;; Find the last non-empty line.
3056 (while (looking-at "[ \t]*$")
3059 (setq mark (set-marker (make-marker) (point)))
3061 (message-indent-citation)
3062 ;; Enable undoing the deletion.
3064 (delete-region mark (mark t))
3065 (set-marker mark nil)))))
3070 ;;; Sending messages
3073 (defun message-send-and-exit (&optional arg)
3074 "Send message like `message-send', then, if no errors, exit from mail buffer."
3076 (let ((buf (current-buffer))
3077 (actions message-exit-actions))
3078 (when (and (message-send arg)
3080 (if message-kill-buffer-on-exit
3083 (when (eq buf (current-buffer))
3084 (message-bury buf)))
3085 (message-do-actions actions)
3088 (defun message-dont-send ()
3089 "Don't send the message you have been editing.
3090 Instead, just auto-save the buffer and then bury it."
3092 (set-buffer-modified-p t)
3094 (let ((actions message-postpone-actions))
3095 (message-bury (current-buffer))
3096 (message-do-actions actions)))
3098 (defun message-kill-buffer ()
3099 "Kill the current buffer."
3101 (when (or (not (buffer-modified-p))
3102 (yes-or-no-p "Message modified; kill anyway? "))
3103 (let ((actions message-kill-actions)
3104 (draft-article message-draft-article)
3105 (auto-save-file-name buffer-auto-save-file-name)
3106 (file-name buffer-file-name)
3107 (modified (buffer-modified-p)))
3108 (setq buffer-file-name nil)
3109 (kill-buffer (current-buffer))
3110 (when (and (or (and auto-save-file-name
3111 (file-exists-p auto-save-file-name))
3113 (file-exists-p file-name)))
3114 (yes-or-no-p (format "Remove the backup file%s? "
3115 (if modified " too" ""))))
3117 (delete-file auto-save-file-name))
3118 (let ((message-draft-article draft-article))
3119 (message-disassociate-draft)))
3120 (message-do-actions actions))))
3122 (defun message-bury (buffer)
3123 "Bury this mail BUFFER."
3124 (let ((newbuf (other-buffer buffer)))
3125 (bury-buffer buffer)
3126 (if (and (fboundp 'frame-parameters)
3127 (cdr (assq 'dedicated (frame-parameters)))
3128 (not (null (delq (selected-frame) (visible-frame-list)))))
3129 (delete-frame (selected-frame))
3130 (switch-to-buffer newbuf))))
3132 (defun message-send (&optional arg)
3133 "Send the message in the current buffer.
3134 If `message-interactive' is non-nil, wait for success indication or
3135 error messages, and inform user.
3136 Otherwise any failure is reported in a message back to the user from
3138 The usage of ARG is defined by the instance that called Message.
3139 It should typically alter the sending method in some way or other."
3141 ;; Make it possible to undo the coming changes.
3143 (let ((inhibit-read-only t))
3144 (put-text-property (point-min) (point-max) 'read-only nil))
3145 (message-fix-before-sending)
3146 (run-hooks 'message-send-hook)
3147 (message message-sending-message)
3148 (let ((alist message-send-method-alist)
3150 elem sent dont-barf-on-no-method
3151 (message-options message-options))
3152 (message-options-set-recipient)
3154 (setq elem (pop alist)))
3155 (when (funcall (cadr elem))
3156 (when (and (or (not (memq (car elem)
3157 message-sent-message-via))
3158 (not (message-fetch-field "supersedes"))
3159 (if (or (message-gnksa-enable-p 'multiple-copies)
3160 (not (eq (car elem) 'news)))
3163 "Already sent message via %s; resend? "
3165 (error "Denied posting -- multiple copies")))
3166 (setq success (funcall (caddr elem) arg)))
3170 (let ((fcc (message-fetch-field "Fcc"))
3171 (gcc (message-fetch-field "Gcc")))
3173 (or (eq message-allow-no-recipients 'always)
3174 (and (not (eq message-allow-no-recipients 'never))
3175 (setq dont-barf-on-no-method
3177 (format "No receiver, perform %s anyway? "
3178 (cond ((and fcc gcc) "Fcc and Gcc")
3181 (error "No methods specified to send by"))
3182 (when (or dont-barf-on-no-method
3186 (run-hooks 'message-sent-hook))
3187 (message "Sending...done")
3188 ;; Mark the buffer as unmodified and delete auto-save.
3189 (set-buffer-modified-p nil)
3190 (delete-auto-save-file-if-necessary t)
3191 (message-disassociate-draft)
3192 ;; Delete other mail buffers and stuff.
3193 (message-do-send-housekeeping)
3194 (message-do-actions message-send-actions)
3198 (defun message-send-via-mail (arg)
3199 "Send the current message via mail."
3200 (message-send-mail arg))
3202 (defun message-send-via-news (arg)
3203 "Send the current message via news."
3204 (funcall message-send-news-function arg))
3206 (defmacro message-check (type &rest forms)
3207 "Eval FORMS if TYPE is to be checked."
3208 `(or (message-check-element ,type)
3212 (put 'message-check 'lisp-indent-function 1)
3213 (put 'message-check 'edebug-form-spec '(form body))
3215 (defun message-text-with-property (prop)
3216 "Return a list of all points where the text has PROP."
3218 (point (point-min)))
3220 (while (< point (point-max))
3221 (when (get-text-property point prop)
3222 (push point points))
3226 (defun message-fix-before-sending ()
3227 "Do various things to make the message nice before sending it."
3228 ;; Make sure there's a newline at the end of the message.
3229 (goto-char (point-max))
3232 ;; Delete all invisible text.
3233 (message-check 'invisible-text
3234 (let ((points (message-text-with-property 'invisible)))
3236 (goto-char (car points))
3237 (dolist (point points)
3238 (add-text-properties point (1+ point)
3239 '(invisible nil face highlight
3240 font-lock-face highlight)))
3241 (unless (yes-or-no-p
3242 "Invisible text found and made visible; continue posting? ")
3243 (error "Invisible text found and made visible")))))
3244 (message-check 'illegible-text
3247 (skip-chars-forward mm-7bit-chars)
3249 (when (let ((char (char-after)))
3250 (or (< (mm-char-int char) 128)
3251 (and (mm-multibyte-p)
3252 (memq (char-charset char)
3253 '(eight-bit-control eight-bit-graphic
3255 (add-text-properties (point) (1+ (point))
3256 '(font-lock-face highlight face highlight))
3259 (skip-chars-forward mm-7bit-chars))
3262 (gnus-multiple-choice
3263 "Illegible text found. Continue posting?"
3264 '((?d "Remove and continue posting")
3265 (?r "Replace with dots and continue posting")
3266 (?i "Ignore and continue posting")
3267 (?e "Continue editing"))))
3269 (error "Illegible text found"))
3271 (skip-chars-forward mm-7bit-chars)
3273 (when (let ((char (char-after)))
3274 (or (< (mm-char-int char) 128)
3275 (and (mm-multibyte-p)
3276 (memq (char-charset char)
3277 '(eight-bit-control eight-bit-graphic
3280 (remove-text-properties (point) (1+ (point))
3281 '(font-lock-face highlight face highlight))
3283 (when (eq choice ?r)
3286 (skip-chars-forward mm-7bit-chars))))))
3288 (defun message-add-action (action &rest types)
3289 "Add ACTION to be performed when doing an exit of type TYPES."
3291 (add-to-list (intern (format "message-%s-actions" (pop types)))
3294 (defun message-delete-action (action &rest types)
3295 "Delete ACTION from lists of actions performed when doing an exit of type TYPES."
3298 (set (setq var (intern (format "message-%s-actions" (pop types))))
3299 (delq action (symbol-value var))))))
3301 (defun message-do-actions (actions)
3302 "Perform all actions in ACTIONS."
3303 ;; Now perform actions on successful sending.
3307 ;; A simple function.
3308 ((message-functionp (car actions))
3309 (funcall (car actions)))
3310 ;; Something to be evaled.
3312 (eval (car actions)))))
3315 (defun message-send-mail-partially ()
3316 "Send mail as message/partial."
3317 ;; replace the header delimiter with a blank line
3318 (goto-char (point-min))
3320 (concat "^" (regexp-quote mail-header-separator) "\n"))
3321 (replace-match "\n")
3322 (run-hooks 'message-send-mail-hook)
3323 (let ((p (goto-char (point-min)))
3324 (tembuf (message-generate-new-buffer-clone-locals " message temp"))
3325 (curbuf (current-buffer))
3326 (id (message-make-message-id)) (n 1)
3327 plist total header required-mail-headers)
3329 (if (< (point-max) (+ p message-send-mail-partially-limit))
3330 (goto-char (point-max))
3331 (goto-char (+ p message-send-mail-partially-limit))
3333 (if (<= (point) p) (forward-line 1))) ;; In case of bad message.
3336 (setq total (length plist))
3337 (push (point-max) plist)
3338 (setq plist (nreverse plist))
3341 (setq p (pop plist))
3344 (copy-to-buffer tembuf p (car plist))
3346 (goto-char (point-min))
3349 (goto-char (point-min))
3350 (narrow-to-region (point) (point))
3353 (setq header (buffer-substring (point-min) (point)))
3354 (goto-char (point-min))
3355 (narrow-to-region (point) (point))
3357 (message-remove-header "Mime-Version")
3358 (message-remove-header "Content-Type")
3359 (message-remove-header "Content-Transfer-Encoding")
3360 (message-remove-header "Message-ID")
3361 (message-remove-header "Lines")
3362 (goto-char (point-max))
3363 (insert "Mime-Version: 1.0\n")
3364 (setq header (buffer-substring (point-min) (point-max))))
3365 (goto-char (point-max))
3366 (insert (format "Content-Type: message/partial; id=\"%s\"; number=%d; total=%d\n\n"
3369 (let ((mail-header-separator ""))
3370 (when (memq 'Message-ID message-required-mail-headers)
3371 (insert "Message-ID: " (message-make-message-id) "\n"))
3372 (when (memq 'Lines message-required-mail-headers)
3373 (insert "Lines: " (message-make-lines) "\n"))
3374 (message-goto-subject)
3376 (insert (format " (%d/%d)" n total))
3378 (mm-with-unibyte-current-buffer
3379 (funcall (or message-send-mail-real-function
3380 message-send-mail-function))))
3382 (setq p (pop plist))
3384 (kill-buffer tembuf))))
3386 (defun message-send-mail (&optional arg)
3387 (require 'mail-utils)
3388 (let* ((tembuf (message-generate-new-buffer-clone-locals " message temp"))
3389 (case-fold-search nil)
3390 (news (message-news-p))
3391 (mailbuf (current-buffer))
3392 (message-this-is-mail t)
3393 (message-posting-charset
3394 (if (fboundp 'gnus-setup-posting-charset)
3395 (gnus-setup-posting-charset nil)
3396 message-posting-charset))
3397 (headers message-required-mail-headers))
3399 (message-narrow-to-headers)
3400 ;; Generate the Mail-Followup-To header if the header is not there...
3401 (if (and (message-subscribed-p)
3402 (not (mail-fetch-field "mail-followup-to")))
3405 (cons "Mail-Followup-To" (message-make-mail-followup-to))
3406 message-required-mail-headers))
3407 ;; otherwise, delete the MFT header if the field is empty
3408 (when (equal "" (mail-fetch-field "mail-followup-to"))
3409 (message-remove-header "^Mail-Followup-To:")))
3410 ;; Insert some headers.
3411 (let ((message-deletable-headers
3412 (if news nil message-deletable-headers)))
3413 (message-generate-headers headers))
3414 ;; Let the user do all of the above.
3415 (run-hooks 'message-header-hook))
3420 ;; Avoid copying text props (except hard newlines).
3421 (insert (with-current-buffer mailbuf
3422 (mml-buffer-substring-no-properties-except-hard-newlines
3423 (point-min) (point-max))))
3424 ;; Remove some headers.
3425 (message-encode-message-body)
3427 (message-narrow-to-headers)
3428 ;; We (re)generate the Lines header.
3429 (when (memq 'Lines message-required-mail-headers)
3430 (message-generate-headers '(Lines)))
3431 ;; Remove some headers.
3432 (message-remove-header message-ignored-mail-headers t)
3433 (let ((mail-parse-charset message-default-charset))
3434 (mail-encode-encoded-word-buffer)))
3435 (goto-char (point-max))
3436 ;; require one newline at the end.
3437 (or (= (preceding-char) ?\n)
3439 (message-cleanup-headers)
3442 (message-narrow-to-headers)
3444 (or (message-fetch-field "cc")
3445 (message-fetch-field "to"))
3446 (let ((content-type (message-fetch-field "content-type")))
3449 (string= "text/plain"
3451 (mail-header-parse-content-type
3453 (message-insert-courtesy-copy))
3454 (if (or (not message-send-mail-partially-limit)
3455 (< (point-max) message-send-mail-partially-limit)
3456 (not (message-y-or-n-p
3457 "The message size is too large, split? "
3461 (/ (point-max) 1000) "KB, is too large.
3463 Some mail gateways (MTA's) bounce large messages. To avoid the
3464 problem, answer `y', and the message will be split into several
3465 smaller pieces, the size of each is about "
3466 (/ message-send-mail-partially-limit 1000)
3470 However, some mail readers (MUA's) can't read split messages, i.e.,
3471 mails in message/partially format. Answer `n', and the message will be
3474 The size limit is controlled by `message-send-mail-partially-limit'.
3475 If you always want Gnus to send messages in one piece, set
3476 `message-send-mail-partially-limit' to nil.
3478 (mm-with-unibyte-current-buffer
3479 (message "Sending via mail...")
3480 (funcall (or message-send-mail-real-function
3481 message-send-mail-function)))
3482 (message-send-mail-partially)))
3483 (kill-buffer tembuf))
3484 (set-buffer mailbuf)
3485 (push 'mail message-sent-message-via)))
3487 (defun message-send-mail-with-sendmail ()
3488 "Send off the prepared buffer with sendmail."
3489 (let ((errbuf (if message-interactive
3490 (message-generate-new-buffer-clone-locals
3493 resend-to-addresses delimline)
3496 (let ((case-fold-search t))
3498 (message-narrow-to-headers)
3499 (setq resend-to-addresses (message-fetch-field "resent-to")))
3500 ;; Change header-delimiter to be what sendmail expects.
3501 (goto-char (point-min))
3503 (concat "^" (regexp-quote mail-header-separator) "\n"))
3504 (replace-match "\n")
3506 (setq delimline (point-marker))
3507 (run-hooks 'message-send-mail-hook)
3508 ;; Insert an extra newline if we need it to work around
3509 ;; Sun's bug that swallows newlines.
3510 (goto-char (1+ delimline))
3511 (when (eval message-mailer-swallows-blank-line)
3513 (when message-interactive
3517 (let* ((default-directory "/")
3518 (coding-system-for-write message-send-coding-system)
3520 'call-process-region
3522 (list (point-min) (point-max)
3523 (if (boundp 'sendmail-program)
3525 "/usr/lib/sendmail")
3526 nil errbuf nil "-oi")
3527 ;; Always specify who from,
3528 ;; since some systems have broken sendmails.
3529 ;; But some systems are more broken with -f, so
3530 ;; we'll let users override this.
3531 (if (null message-sendmail-f-is-evil)
3532 (list "-f" (message-make-address)))
3533 ;; These mean "report errors by mail"
3534 ;; and "deliver in background".
3535 (if (null message-interactive) '("-oem" "-odb"))
3536 ;; Get the addresses from the message
3537 ;; unless this is a resend.
3538 ;; We must not do that for a resend
3539 ;; because we would find the original addresses.
3540 ;; For a resend, include the specific addresses.
3541 (if resend-to-addresses
3542 (list resend-to-addresses)
3544 (unless (or (null cpr) (zerop cpr))
3545 (error "Sending...failed with exit value %d" cpr)))
3546 (when message-interactive
3549 (goto-char (point-min))
3550 (while (re-search-forward "\n\n* *" nil t)
3551 (replace-match "; "))
3552 (if (not (zerop (buffer-size)))
3553 (error "Sending...failed to %s"
3554 (buffer-substring (point-min) (point-max)))))))
3555 (when (bufferp errbuf)
3556 (kill-buffer errbuf)))))
3558 (defun message-send-mail-with-qmail ()
3559 "Pass the prepared message buffer to qmail-inject.
3560 Refer to the documentation for the variable `message-send-mail-function'
3561 to find out how to use this."
3562 ;; replace the header delimiter with a blank line
3563 (goto-char (point-min))
3565 (concat "^" (regexp-quote mail-header-separator) "\n"))
3566 (replace-match "\n")
3567 (run-hooks 'message-send-mail-hook)
3570 (let ((coding-system-for-write message-send-coding-system))
3572 'call-process-region 1 (point-max) message-qmail-inject-program
3574 ;; qmail-inject's default behaviour is to look for addresses on the
3575 ;; command line; if there're none, it scans the headers.
3576 ;; yes, it does The Right Thing w.r.t. Resent-To and it's kin.
3578 ;; in general, ALL of qmail-inject's defaults are perfect for simply
3579 ;; reading a formatted (i. e., at least a To: or Resent-To header)
3580 ;; message from stdin.
3582 ;; qmail also has the advantage of not having been raped by
3583 ;; various vendors, so we don't have to allow for that, either --
3584 ;; compare this with message-send-mail-with-sendmail and weep
3585 ;; for sendmail's lost innocence.
3587 ;; all this is way cool coz it lets us keep the arguments entirely
3588 ;; free for -inject-arguments -- a big win for the user and for us
3589 ;; since we don't have to play that double-guessing game and the user
3590 ;; gets full control (no gestapo'ish -f's, for instance). --sj
3591 (if (message-functionp message-qmail-inject-args)
3592 (funcall message-qmail-inject-args)
3593 message-qmail-inject-args)))
3594 ;; qmail-inject doesn't say anything on it's stdout/stderr,
3595 ;; we have to look at the retval instead
3597 (100 (error "qmail-inject reported permanent failure"))
3598 (111 (error "qmail-inject reported transient failure"))
3599 ;; should never happen
3600 (t (error "qmail-inject reported unknown failure"))))
3602 (defun message-send-mail-with-mh ()
3603 "Send the prepared message buffer with mh."
3604 (let ((mh-previous-window-config nil)
3605 (name (mh-new-draft-name)))
3606 (setq buffer-file-name name)
3607 ;; MH wants to generate these headers itself.
3608 (when message-mh-deletable-headers
3609 (let ((headers message-mh-deletable-headers))
3611 (goto-char (point-min))
3612 (and (re-search-forward
3613 (concat "^" (symbol-name (car headers)) ": *") nil t)
3614 (message-delete-line))
3616 (run-hooks 'message-send-mail-hook)
3617 ;; Pass it on to mh.
3620 (defun message-smtpmail-send-it ()
3621 "Send the prepared message buffer with `smtpmail-send-it'.
3622 This only differs from `smtpmail-send-it' that this command evaluates
3623 `message-send-mail-hook' just before sending a message. It is useful
3624 if your ISP requires the POP-before-SMTP authentication. See the
3625 documentation for the function `mail-source-touch-pop'."
3626 (run-hooks 'message-send-mail-hook)
3629 (defun message-canlock-generate ()
3630 "Return a string that is non-trival to guess.
3631 Do not use this for anything important, it is cryptographically weak."
3632 (let (sha1-maximum-internal-length)
3633 (sha1 (concat (message-unique-id)
3634 (format "%x%x%x" (random) (random t) (random))
3635 (prin1-to-string (recent-keys))
3636 (prin1-to-string (garbage-collect))))))
3638 (defun message-canlock-password ()
3639 "The password used by message for cancel locks.
3640 This is the value of `canlock-password', if that option is non-nil.
3641 Otherwise, generate and save a value for `canlock-password' first."
3642 (unless canlock-password
3643 (customize-save-variable 'canlock-password (message-canlock-generate))
3644 (setq canlock-password-for-verify canlock-password))
3647 (defun message-insert-canlock ()
3648 (when message-insert-canlock
3649 (message-canlock-password)
3650 (canlock-insert-header)))
3652 (defun message-send-news (&optional arg)
3653 (let* ((tembuf (message-generate-new-buffer-clone-locals " *message temp*"))
3654 (case-fold-search nil)
3655 (method (if (message-functionp message-post-method)
3656 (funcall message-post-method arg)
3657 message-post-method))
3658 (newsgroups-field (save-restriction
3659 (message-narrow-to-headers-or-head)
3660 (message-fetch-field "Newsgroups")))
3661 (followup-field (save-restriction
3662 (message-narrow-to-headers-or-head)
3663 (message-fetch-field "Followup-To")))
3664 ;; BUG: We really need to get the charset for each name in the
3665 ;; Newsgroups and Followup-To lines to allow crossposting
3666 ;; between group namess with incompatible character sets.
3667 ;; -- Per Abrahamsen <abraham@dina.kvl.dk> 2001-10-08.
3668 (group-field-charset
3669 (gnus-group-name-charset method newsgroups-field))
3670 (followup-field-charset
3671 (gnus-group-name-charset method (or followup-field "")))
3672 (rfc2047-header-encoding-alist
3673 (append (when group-field-charset
3674 (list (cons "Newsgroups" group-field-charset)))
3675 (when followup-field-charset
3676 (list (cons "Followup-To" followup-field-charset)))
3677 rfc2047-header-encoding-alist))
3678 (messbuf (current-buffer))
3679 (message-syntax-checks
3681 (listp message-syntax-checks))
3682 (cons '(existing-newsgroups . disabled)
3683 message-syntax-checks)
3684 message-syntax-checks))
3685 (message-this-is-news t)
3686 (message-posting-charset
3687 (gnus-setup-posting-charset newsgroups-field))
3689 (if (not (message-check-news-body-syntax))
3692 (message-narrow-to-headers)
3693 ;; Insert some headers.
3694 (message-generate-headers message-required-news-headers)
3695 (message-insert-canlock)
3696 ;; Let the user do all of the above.
3697 (run-hooks 'message-header-hook))
3698 ;; Note: This check will be disabled by the ".*" default value for
3699 ;; gnus-group-name-charset-group-alist. -- Pa 2001-10-07.
3700 (when (and group-field-charset
3701 (listp message-syntax-checks))
3702 (setq message-syntax-checks
3703 (cons '(valid-newsgroups . disabled)
3704 message-syntax-checks)))
3705 (message-cleanup-headers)
3706 (if (not (let ((message-post-method method))
3707 (message-check-news-syntax)))
3712 (buffer-disable-undo)
3714 ;; Avoid copying text props (except hard newlines).
3716 (with-current-buffer messbuf
3717 (mml-buffer-substring-no-properties-except-hard-newlines
3718 (point-min) (point-max))))
3719 (message-encode-message-body)
3720 ;; Remove some headers.
3722 (message-narrow-to-headers)
3723 ;; We (re)generate the Lines header.
3724 (when (memq 'Lines message-required-mail-headers)
3725 (message-generate-headers '(Lines)))
3726 ;; Remove some headers.
3727 (message-remove-header message-ignored-news-headers t)
3728 (let ((mail-parse-charset message-default-charset))
3729 (mail-encode-encoded-word-buffer)))
3730 (goto-char (point-max))
3731 ;; require one newline at the end.
3732 (or (= (preceding-char) ?\n)
3734 (let ((case-fold-search t))
3735 ;; Remove the delimiter.
3736 (goto-char (point-min))
3738 (concat "^" (regexp-quote mail-header-separator) "\n"))
3739 (replace-match "\n")
3741 (run-hooks 'message-send-news-hook)
3742 (gnus-open-server method)
3743 (message "Sending news via %s..." (gnus-server-string method))
3744 (setq result (let ((mail-header-separator ""))
3745 (gnus-request-post method))))
3746 (kill-buffer tembuf))
3747 (set-buffer messbuf)
3749 (push 'news message-sent-message-via)
3750 (message "Couldn't send message via news: %s"
3751 (nnheader-get-report (car method)))
3755 ;;; Header generation & syntax checking.
3758 (defun message-check-element (type)
3759 "Return non-nil if this TYPE is not to be checked."
3760 (if (eq message-syntax-checks 'dont-check-for-anything-just-trust-me)
3762 (let ((able (assq type message-syntax-checks)))
3764 (eq (cdr able) 'disabled)))))
3766 (defun message-check-news-syntax ()
3767 "Check the syntax of the message."
3771 ;; We narrow to the headers and check them first.
3774 (message-narrow-to-headers)
3775 (message-check-news-header-syntax))))))
3777 (defun message-check-news-header-syntax ()
3779 ;; Check Newsgroups header.
3780 (message-check 'newsgroups
3781 (let ((group (message-fetch-field "newsgroups")))
3784 (not (string-match "\\`[ \t]*\\'" group)))
3787 "The newsgroups field is empty or missing. Posting is denied.")))))
3788 ;; Check the Subject header.
3789 (message-check 'subject
3790 (let* ((case-fold-search t)
3791 (subject (message-fetch-field "subject")))
3794 (not (string-match "\\`[ \t]*\\'" subject)))
3797 "The subject field is empty or missing. Posting is denied.")))))
3798 ;; Check for commands in Subject.
3799 (message-check 'subject-cmsg
3800 (if (string-match "^cmsg " (message-fetch-field "subject"))
3802 "The control code \"cmsg\" is in the subject. Really post? ")
3804 ;; Check long header lines.
3805 (message-check 'long-header-lines
3806 (let ((start (point))
3810 (while (and (not found)
3811 (re-search-forward "^\\([^ \t:]+\\): " nil t))
3812 (if (> (- (point) (match-beginning 0)) 998)
3814 length (- (point) (match-beginning 0)))
3815 (setq header (match-string-no-properties 1)))
3816 (setq start (match-beginning 0))
3819 (y-or-n-p (format "Your %s header is too long (%d). Really post? "
3822 ;; Check for multiple identical headers.
3823 (message-check 'multiple-headers
3825 (while (and (not found)
3826 (re-search-forward "^[^ \t:]+: " nil t))
3828 (or (re-search-forward
3833 (match-beginning 0) (- (match-end 0) 2))))
3838 (y-or-n-p (format "Multiple %s headers. Really post? " found))
3840 ;; Check for Version and Sendsys.
3841 (message-check 'sendsys
3842 (if (re-search-forward "^Sendsys:\\|^Version:" nil t)
3844 (format "The article contains a %s command. Really post? "
3845 (buffer-substring (match-beginning 0)
3846 (1- (match-end 0)))))
3848 ;; See whether we can shorten Followup-To.
3849 (message-check 'shorten-followup-to
3850 (let ((newsgroups (message-fetch-field "newsgroups"))
3851 (followup-to (message-fetch-field "followup-to"))
3853 (when (and newsgroups
3854 (string-match "," newsgroups)
3859 (setq to (completing-read
3860 "Followups to (default: no Followup-To header) "
3861 (mapcar (lambda (g) (list g))
3863 (message-tokenize-header
3865 (goto-char (point-min))
3866 (insert "Followup-To: " to "\n"))
3868 ;; Check "Shoot me".
3869 (message-check 'shoot
3870 (if (re-search-forward
3871 "Message-ID.*.i-did-not-set--mail-host-address--so-shoot-me" nil t)
3872 (y-or-n-p "You appear to have a misconfigured system. Really post? ")
3874 ;; Check for Approved.
3875 (message-check 'approved
3876 (if (re-search-forward "^Approved:" nil t)
3877 (y-or-n-p "The article contains an Approved header. Really post? ")
3879 ;; Check the Message-ID header.
3880 (message-check 'message-id
3881 (let* ((case-fold-search t)
3882 (message-id (message-fetch-field "message-id" t)))
3883 (or (not message-id)
3884 ;; Is there an @ in the ID?
3885 (and (string-match "@" message-id)
3886 ;; Is there a dot in the ID?
3887 (string-match "@[^.]*\\." message-id)
3888 ;; Does the ID end with a dot?
3889 (not (string-match "\\.>" message-id)))
3891 (format "The Message-ID looks strange: \"%s\". Really post? "
3893 ;; Check the Newsgroups & Followup-To headers.
3894 (message-check 'existing-newsgroups
3895 (let* ((case-fold-search t)
3896 (newsgroups (message-fetch-field "newsgroups"))
3897 (followup-to (message-fetch-field "followup-to"))
3898 (groups (message-tokenize-header
3900 (concat newsgroups "," followup-to)
3902 (post-method (if (message-functionp message-post-method)
3903 (funcall message-post-method)
3904 message-post-method))
3905 ;; KLUDGE to handle nnvirtual groups. Doing this right
3906 ;; would probably involve a new nnoo function.
3907 ;; -- Per Abrahamsen <abraham@dina.kvl.dk>, 2001-10-17.
3908 (method (if (and (consp post-method)
3909 (eq (car post-method) 'nnvirtual)
3910 gnus-message-group-art)
3911 (let ((group (car (nnvirtual-find-group-art
3912 (car gnus-message-group-art)
3913 (cdr gnus-message-group-art)))))
3914 (gnus-find-method-for-group group))
3918 (gnus-group-name-decode
3919 (gnus-group-real-name n)
3920 (gnus-group-name-charset method n)))
3921 (gnus-groups-from-server method)))
3924 (unless (or (equal (car groups) "poster")
3925 (member (car groups) known-groups))
3926 (push (car groups) errors))
3929 ;; Gnus is not running.
3930 ((or (not (and (boundp 'gnus-active-hashtb)
3931 gnus-active-hashtb))
3932 (not (boundp 'gnus-read-active-file)))
3934 ;; We don't have all the group names.
3935 ((and (or (not gnus-read-active-file)
3936 (eq gnus-read-active-file 'some))
3940 "Really post to %s possibly unknown group%s: %s? "
3941 (if (= (length errors) 1) "this" "these")
3942 (if (= (length errors) 1) "" "s")
3943 (mapconcat 'identity errors ", "))))
3944 ;; There were no errors.
3947 ;; There are unknown groups.
3951 "Really post to %s unknown group%s: %s? "
3952 (if (= (length errors) 1) "this" "these")
3953 (if (= (length errors) 1) "" "s")
3954 (mapconcat 'identity errors ", ")))))))
3955 ;; Check continuation headers.
3956 (message-check 'continuation-headers
3957 (goto-char (point-min))
3958 (let ((do-posting t))
3959 (while (re-search-forward "^[^ \t\n][^:\n]*$" nil t)
3960 (if (y-or-n-p "Fix continuation lines? ")
3962 (goto-char (match-beginning 0))
3964 (unless (y-or-n-p "Send anyway? ")
3965 (setq do-posting nil))))
3967 ;; Check the Newsgroups & Followup-To headers for syntax errors.
3968 (message-check 'valid-newsgroups
3969 (let ((case-fold-search t)
3970 (headers '("Newsgroups" "Followup-To"))
3972 (while (and headers (not error))
3973 (when (setq header (mail-fetch-field (car headers)))
3977 "\\`\\([-+_&.a-zA-Z0-9]+\\)?\\(,[-+_&.a-zA-Z0-9]+\\)*\\'"
3982 (not (string-match "\\.\\'\\|\\.\\." g)))
3983 (message-tokenize-header header ","))))
3990 (format "The %s header looks odd: \"%s\". Really post? "
3991 (car headers) header)))))
3992 (message-check 'repeated-newsgroups
3993 (let ((case-fold-search t)
3994 (headers '("Newsgroups" "Followup-To"))
3995 header error groups group)
3998 (when (setq header (mail-fetch-field (pop headers)))
3999 (setq groups (message-tokenize-header header ","))
4000 (while (setq group (pop groups))
4001 (when (member group groups)
4007 (format "Group %s is repeated in headers. Really post? " error)))))
4008 ;; Check the From header.
4009 (message-check 'from
4010 (let* ((case-fold-search t)
4011 (from (message-fetch-field "from"))
4015 (message "There is no From line. Posting is denied.")
4017 ((or (not (string-match
4019 (setq ad (nth 1 (mail-extract-address-components
4020 from))))) ;larsi@ifi
4021 (string-match "\\.\\." ad) ;larsi@ifi..uio
4022 (string-match "@\\." ad) ;larsi@.ifi.uio
4023 (string-match "\\.$" ad) ;larsi@ifi.uio.
4024 (not (string-match "^[^@]+@[^@]+$" ad)) ;larsi.ifi.uio
4025 (string-match "(.*).*(.*)" from)) ;(lars) (lars)
4027 "Denied posting -- the From looks strange: \"%s\"." from)
4029 ((let ((addresses (rfc822-addresses from)))
4030 (while (and addresses
4031 (not (eq (string-to-char (car addresses)) ?\()))
4032 (setq addresses (cdr addresses)))
4035 "Denied posting -- bad From address: \"%s\"." from)
4038 ;; Check the Reply-To header.
4039 (message-check 'reply-to
4040 (let* ((case-fold-search t)
4041 (reply-to (message-fetch-field "reply-to"))
4046 ((string-match "," reply-to)
4048 (format "Multiple Reply-To addresses: \"%s\". Really post? "
4050 ((or (not (string-match
4052 (setq ad (nth 1 (mail-extract-address-components
4053 reply-to))))) ;larsi@ifi
4054 (string-match "\\.\\." ad) ;larsi@ifi..uio
4055 (string-match "@\\." ad) ;larsi@.ifi.uio
4056 (string-match "\\.$" ad) ;larsi@ifi.uio.
4057 (not (string-match "^[^@]+@[^@]+$" ad)) ;larsi.ifi.uio
4058 (string-match "(.*).*(.*)" reply-to)) ;(lars) (lars)
4061 "The Reply-To looks strange: \"%s\". Really post? "
4065 (defun message-check-news-body-syntax ()
4067 ;; Check for long lines.
4068 (message-check 'long-lines
4069 (goto-char (point-min))
4071 (concat "^" (regexp-quote mail-header-separator) "$"))
4075 "<#\\(/\\)?\\(multipart\\|part\\|external\\|mml\\)")
4078 (< (- (point) p) 80)))
4079 (zerop (forward-line 1))))
4083 "You have lines longer than 79 characters. Really post? ")))
4084 ;; Check whether the article is empty.
4085 (message-check 'empty
4086 (goto-char (point-min))
4088 (concat "^" (regexp-quote mail-header-separator) "$"))
4091 (goto-char (point-max))
4092 (re-search-backward message-signature-separator nil t)
4094 (or (re-search-backward "[^ \n\t]" b t)
4095 (if (message-gnksa-enable-p 'empty-article)
4096 (y-or-n-p "Empty article. Really post? ")
4097 (message "Denied posting -- Empty article.")
4099 ;; Check for control characters.
4100 (message-check 'control-chars
4101 (if (re-search-forward "[\000-\007\013\015-\032\034-\037\200-\237]" nil t)
4103 "The article contains control characters. Really post? ")
4105 ;; Check excessive size.
4106 (message-check 'size
4107 (if (> (buffer-size) 60000)
4109 (format "The article is %d octets long. Really post? "
4112 ;; Check whether any new text has been added.
4113 (message-check 'new-text
4115 (not message-checksum)
4116 (not (eq (message-checksum) message-checksum))
4117 (if (message-gnksa-enable-p 'quoted-text-only)
4119 "It looks like no new text has been added. Really post? ")
4120 (message "Denied posting -- no new text has been added.")
4122 ;; Check the length of the signature.
4123 (message-check 'signature
4124 (goto-char (point-max))
4125 (if (> (count-lines (point) (point-max)) 5)
4128 "Your .sig is %d lines; it should be max 4. Really post? "
4129 (1- (count-lines (point) (point-max)))))
4131 ;; Ensure that text follows last quoted portion.
4132 (message-check 'quoting-style
4133 (goto-char (point-max))
4134 (let ((no-problem t))
4135 (when (search-backward-regexp "^>[^\n]*\n" nil t)
4136 (setq no-problem (search-forward-regexp "^[ \t]*[^>\n]" nil t)))
4139 (if (message-gnksa-enable-p 'quoted-text-only)
4140 (y-or-n-p "Your text should follow quoted text. Really post? ")
4142 (goto-char (point-min))
4144 (concat "^" (regexp-quote mail-header-separator) "$"))
4145 (if (search-forward-regexp "^[ \t]*[^>\n]" nil t)
4146 (y-or-n-p "Your text should follow quoted text. Really post? ")
4147 (message "Denied posting -- only quoted text.")
4150 (defun message-checksum ()
4151 "Return a \"checksum\" for the current buffer."
4154 (goto-char (point-min))
4156 (concat "^" (regexp-quote mail-header-separator) "$"))
4158 (when (not (looking-at "[ \t\n]"))
4159 (setq sum (logxor (ash sum 1) (if (natnump sum) 0 1)
4164 (defun message-do-fcc ()
4165 "Process Fcc headers in the current buffer."
4166 (let ((case-fold-search t)
4167 (buf (current-buffer))
4169 (mml-externalize-attachments message-fcc-externalize-attachments))
4172 (message-narrow-to-headers)
4173 (setq file (message-fetch-field "fcc" t)))
4175 (set-buffer (get-buffer-create " *message temp*"))
4177 (insert-buffer-substring buf)
4178 (message-encode-message-body)
4180 (message-narrow-to-headers)
4181 (while (setq file (message-fetch-field "fcc" t))
4183 (message-remove-header "fcc" nil t))
4184 (let ((mail-parse-charset message-default-charset)
4185 (rfc2047-header-encoding-alist
4186 (cons '("Newsgroups" . default)
4187 rfc2047-header-encoding-alist)))
4188 (mail-encode-encoded-word-buffer)))
4189 (goto-char (point-min))
4190 (when (re-search-forward
4191 (concat "^" (regexp-quote mail-header-separator) "$")
4193 (replace-match "" t t ))
4194 ;; Process FCC operations.
4196 (setq file (pop list))
4197 (if (string-match "^[ \t]*|[ \t]*\\(.*\\)[ \t]*$" file)
4198 ;; Pipe the article to the program in question.
4199 (call-process-region (point-min) (point-max) shell-file-name
4200 nil nil nil shell-command-switch
4201 (match-string 1 file))
4202 ;; Save the article.
4203 (setq file (expand-file-name file))
4204 (unless (file-exists-p (file-name-directory file))
4205 (make-directory (file-name-directory file) t))
4206 (if (and message-fcc-handler-function
4207 (not (eq message-fcc-handler-function 'rmail-output)))
4208 (funcall message-fcc-handler-function file)
4209 (if (and (file-readable-p file) (mail-file-babyl-p file))
4210 (rmail-output file 1 nil t)
4211 (let ((mail-use-rfc822 t))
4212 (rmail-output file 1 t t))))))
4213 (kill-buffer (current-buffer))))))
4215 (defun message-output (filename)
4216 "Append this article to Unix/babyl mail file FILENAME."
4217 (if (and (file-readable-p filename)
4218 (mail-file-babyl-p filename))
4219 (gnus-output-to-rmail filename t)
4220 (gnus-output-to-mail filename t)))
4222 (defun message-cleanup-headers ()
4223 "Do various automatic cleanups of the headers."
4224 ;; Remove empty lines in the header.
4226 (message-narrow-to-headers)
4227 ;; Remove blank lines.
4228 (while (re-search-forward "^[ \t]*\n" nil t)
4229 (replace-match "" t t))
4231 ;; Correct Newsgroups and Followup-To headers: Change sequence of
4232 ;; spaces to comma and eliminate spaces around commas. Eliminate
4233 ;; embedded line breaks.
4234 (goto-char (point-min))
4235 (while (re-search-forward "^\\(Newsgroups\\|Followup-To\\): +" nil t)
4239 (if (re-search-forward "^[^ \t]" nil t)
4243 (goto-char (point-min))
4244 (while (re-search-forward "\n[ \t]+" nil t)
4245 (replace-match " " t t)) ;No line breaks (too confusing)
4246 (goto-char (point-min))
4247 (while (re-search-forward "[ \t\n]*,[ \t\n]*\\|[ \t]+" nil t)
4248 (replace-match "," t t))
4249 (goto-char (point-min))
4250 ;; Remove trailing commas.
4251 (when (re-search-forward ",+$" nil t)
4252 (replace-match "" t t))))))
4254 (defun message-make-date (&optional now)
4255 "Make a valid data header.
4256 If NOW, use that time instead."
4257 (let* ((now (or now (current-time)))
4258 (zone (nth 8 (decode-time now)))
4262 (setq zone (- zone)))
4264 ;; The day name of the %a spec is locale-specific. Pfff.
4265 (format "%s, " (capitalize (car (rassoc (nth 6 (decode-time now))
4266 parse-time-weekdays))))
4267 (format-time-string "%d" now)
4268 ;; The month name of the %b spec is locale-specific. Pfff.
4270 (capitalize (car (rassoc (nth 4 (decode-time now))
4271 parse-time-months))))
4272 (format-time-string "%Y %H:%M:%S " now)
4273 ;; We do all of this because XEmacs doesn't have the %z spec.
4274 (format "%s%02d%02d" sign (/ zone 3600) (/ (% zone 3600) 60)))))
4276 (defun message-make-message-id ()
4277 "Make a unique Message-ID."
4278 (concat "<" (message-unique-id)
4279 (let ((psubject (save-excursion (message-fetch-field "subject")))
4281 (save-excursion (message-fetch-field "supersedes"))))
4283 (and message-reply-headers
4284 (mail-header-references message-reply-headers)
4285 (mail-header-subject message-reply-headers)
4288 (message-strip-subject-re
4289 (mail-header-subject message-reply-headers))
4290 (message-strip-subject-re psubject))))
4292 (string-match "_-_@" psupersedes)))
4294 "@" (message-make-fqdn) ">"))
4296 (defvar message-unique-id-char nil)
4298 ;; If you ever change this function, make sure the new version
4299 ;; cannot generate IDs that the old version could.
4300 ;; You might for example insert a "." somewhere (not next to another dot
4301 ;; or string boundary), or modify the "fsf" string.
4302 (defun message-unique-id ()
4303 ;; Don't use microseconds from (current-time), they may be unsupported.
4304 ;; Instead we use this randomly inited counter.
4305 (setq message-unique-id-char
4306 (% (1+ (or message-unique-id-char (logand (random t) (1- (lsh 1 20)))))
4307 ;; (current-time) returns 16-bit ints,
4308 ;; and 2^16*25 just fits into 4 digits i base 36.
4310 (let ((tm (current-time)))
4312 (if (memq system-type '(ms-dos emx vax-vms))
4313 (let ((user (downcase (user-login-name))))
4314 (while (string-match "[^a-z0-9_]" user)
4315 (aset user (match-beginning 0) ?_))
4317 (message-number-base36 (user-uid) -1))
4318 (message-number-base36 (+ (car tm)
4319 (lsh (% message-unique-id-char 25) 16)) 4)
4320 (message-number-base36 (+ (nth 1 tm)
4321 (lsh (/ message-unique-id-char 25) 16)) 4)
4322 ;; Append the newsreader name, because while the generated
4323 ;; ID is unique to this newsreader, other newsreaders might
4324 ;; otherwise generate the same ID via another algorithm.
4327 (defun message-number-base36 (num len)
4332 (concat (message-number-base36 (/ num 36) (1- len))
4333 (char-to-string (aref "zyxwvutsrqponmlkjihgfedcba9876543210"
4336 (defun message-make-organization ()
4337 "Make an Organization header."
4338 (let* ((organization
4339 (when message-user-organization
4340 (if (message-functionp message-user-organization)
4341 (funcall message-user-organization)
4342 message-user-organization))))
4344 (message-set-work-buffer)
4345 (cond ((stringp organization)
4346 (insert organization))
4347 ((and (eq t organization)
4348 message-user-organization-file
4349 (file-exists-p message-user-organization-file))
4350 (insert-file-contents message-user-organization-file)))
4351 (goto-char (point-min))
4352 (while (re-search-forward "[\t\n]+" nil t)
4353 (replace-match "" t t))
4354 (unless (zerop (buffer-size))
4357 (defun message-make-lines ()
4358 "Count the number of lines and return numeric string."
4363 (int-to-string (count-lines (point) (point-max))))))
4365 (defun message-make-references ()
4366 "Return the References header for this message."
4367 (when message-reply-headers
4368 (let ((message-id (mail-header-message-id message-reply-headers))
4369 (references (mail-header-references message-reply-headers))
4371 (if (or references message-id)
4372 (concat (or references "") (and references " ")
4376 (defun message-make-in-reply-to ()
4377 "Return the In-Reply-To header for this message."
4378 (when message-reply-headers
4379 (let ((from (mail-header-from message-reply-headers))
4380 (date (mail-header-date message-reply-headers))
4381 (msg-id (mail-header-message-id message-reply-headers)))
4384 (string-match " *at \\| *@ \\| *(\\| *<" from)))
4385 (concat msg-id (if msg-id " (")
4387 (not (zerop stop-pos)))
4388 (substring from 0 stop-pos) from)
4390 (if (or (not date) (string= date ""))
4391 "(unknown date)" date)
4392 "\"" (if msg-id ")")))))))
4394 (defun message-make-distribution ()
4395 "Make a Distribution header."
4396 (let ((orig-distribution (message-fetch-reply-field "distribution")))
4397 (cond ((message-functionp message-distribution-function)
4398 (funcall message-distribution-function))
4399 (t orig-distribution))))
4401 (defun message-make-expires ()
4402 "Return an Expires header based on `message-expires'."
4403 (let ((current (current-time))
4404 (future (* 1.0 message-expires 60 60 24)))
4405 ;; Add the future to current.
4406 (setcar current (+ (car current) (round (/ future (expt 2 16)))))
4407 (setcar (cdr current) (+ (nth 1 current) (% (round future) (expt 2 16))))
4408 (message-make-date current)))
4410 (defun message-make-path ()
4412 (let ((login-name (user-login-name)))
4413 (cond ((null message-user-path)
4414 (concat (system-name) "!" login-name))
4415 ((stringp message-user-path)
4416 ;; Support GENERICPATH. Suggested by vixie@decwrl.dec.com.
4417 (concat message-user-path "!" login-name))
4420 (defun message-make-from ()
4421 "Make a From header."
4422 (let* ((style message-from-style)
4423 (login (message-make-address))
4425 (or (and (boundp 'user-full-name)
4428 (when (string= fullname "&")
4429 (setq fullname (user-login-name)))
4431 (message-set-work-buffer)
4434 (equal fullname ""))
4436 ((or (eq style 'angles)
4437 (and (not (eq style 'parens))
4438 ;; Use angles if no quoting is needed, or if parens would
4439 ;; need quoting too.
4440 (or (not (string-match "[^- !#-'*+/-9=?A-Z^-~]" fullname))
4441 (let ((tmp (concat fullname nil)))
4442 (while (string-match "([^()]*)" tmp)
4443 (aset tmp (match-beginning 0) ?-)
4444 (aset tmp (1- (match-end 0)) ?-))
4445 (string-match "[\\()]" tmp)))))
4447 (insert " <" login ">"))
4448 (t ; 'parens or default
4450 (let ((fullname-start (point)))
4452 (goto-char fullname-start)
4453 ;; RFC 822 says \ and nonmatching parentheses
4454 ;; must be escaped in comments.
4455 ;; Escape every instance of ()\ ...
4456 (while (re-search-forward "[()\\]" nil 1)
4457 (replace-match "\\\\\\&" t))
4458 ;; ... then undo escaping of matching parentheses,
4459 ;; including matching nested parentheses.
4460 (goto-char fullname-start)
4461 (while (re-search-forward
4462 "\\(\\=\\|[^\\]\\(\\\\\\\\\\)*\\)\\\\(\\(\\([^\\]\\|\\\\\\\\\\)*\\)\\\\)"
4464 (replace-match "\\1(\\3)" t)
4465 (goto-char fullname-start)))
4469 (defun message-make-sender ()
4470 "Return the \"real\" user address.
4471 This function tries to ignore all user modifications, and
4472 give as trustworthy answer as possible."
4473 (concat (user-login-name) "@" (system-name)))
4475 (defun message-make-address ()
4476 "Make the address of the user."
4477 (or (message-user-mail-address)
4478 (concat (user-login-name) "@" (message-make-domain))))
4480 (defun message-user-mail-address ()
4481 "Return the pertinent part of `user-mail-address'."
4482 (when user-mail-address
4483 (if (string-match " " user-mail-address)
4484 (nth 1 (mail-extract-address-components user-mail-address))
4485 user-mail-address)))
4487 (defun message-make-fqdn ()
4488 "Return user's fully qualified domain name."
4489 (let ((system-name (system-name))
4490 (user-mail (message-user-mail-address)))
4492 ((and (string-match "[^.]\\.[^.]" system-name)
4493 (not (string-match message-bogus-system-names system-name)))
4494 ;; `system-name' returned the right result.
4496 ;; Try `mail-host-address'.
4497 ((and (boundp 'mail-host-address)
4498 (stringp mail-host-address)
4499 (string-match "\\." mail-host-address))
4501 ;; We try `user-mail-address' as a backup.
4503 (string-match "\\." user-mail)
4504 (string-match "@\\(.*\\)\\'" user-mail))
4505 (match-string 1 user-mail))
4506 ;; Default to this bogus thing.
4508 (concat system-name ".i-did-not-set--mail-host-address--so-tickle-me")))))
4510 (defun message-make-host-name ()
4511 "Return the name of the host."
4512 (let ((fqdn (message-make-fqdn)))
4513 (string-match "^[^.]+\\." fqdn)
4514 (substring fqdn 0 (1- (match-end 0)))))
4516 (defun message-make-domain ()
4517 "Return the domain name."
4518 (or mail-host-address
4519 (message-make-fqdn)))
4521 (defun message-to-list-only ()
4522 "Send a message to the list only.
4523 Remove all addresses but the list address from To and Cc headers."
4525 (let ((listaddr (message-make-mail-followup-to t)))
4528 (message-remove-header "to")
4529 (message-remove-header "cc")
4530 (message-position-on-field "To" "X-Draft-From")
4531 (insert listaddr)))))
4533 (defun message-make-mail-followup-to (&optional only-show-subscribed)
4534 "Return the Mail-Followup-To header.
4535 If passed the optional argument ONLY-SHOW-SUBSCRIBED only return the
4536 subscribed address (and not the additional To and Cc header contents)."
4537 (let* ((case-fold-search t)
4538 (to (message-fetch-field "To"))
4539 (cc (message-fetch-field "cc"))
4540 (msg-recipients (concat to (and to cc ", ") cc))
4542 (mapcar 'mail-strip-quoted-names
4543 (message-tokenize-header msg-recipients)))
4545 (if message-subscribed-address-file
4546 (let (begin end item re)
4549 (insert-file-contents message-subscribed-address-file)
4551 (setq begin (point))
4554 (if (bolp) (setq end (1- end)))
4555 (setq item (regexp-quote (buffer-substring begin end)))
4556 (if re (setq re (concat re "\\|" item))
4557 (setq re (concat "\\`\\(" item))))
4558 (and re (list (concat re "\\)\\'"))))))))
4559 (mft-regexps (apply 'append message-subscribed-regexps
4560 (mapcar 'regexp-quote
4561 message-subscribed-addresses)
4564 message-subscribed-address-functions))))
4566 (let ((subscribed-lists nil)
4568 (loop for recipient in recipients
4569 when (loop for regexp in mft-regexps
4570 when (string-match regexp recipient) return t)
4573 (if only-show-subscribed
4575 msg-recipients))))))
4577 (defun message-generate-headers (headers)
4578 "Prepare article HEADERS.
4579 Headers already prepared in the buffer are not modified."
4580 (setq headers (append headers message-required-headers))
4582 (message-narrow-to-headers)
4583 (let* ((Date (message-make-date))
4584 (Message-ID (message-make-message-id))
4585 (Organization (message-make-organization))
4586 (From (message-make-from))
4587 (Path (message-make-path))
4590 (In-Reply-To (message-make-in-reply-to))
4591 (References (message-make-references))
4593 (Distribution (message-make-distribution))
4594 (Lines (message-make-lines))
4595 (User-Agent message-newsreader)
4596 (Expires (message-make-expires))
4597 (case-fold-search t)
4600 ;; First we remove any old generated headers.
4601 (let ((headers message-deletable-headers))
4602 (unless (buffer-modified-p)
4603 (setq headers (delq 'Message-ID (copy-sequence headers))))
4605 (goto-char (point-min))
4606 (and (re-search-forward
4607 (concat "^" (symbol-name (car headers)) ": *") nil t)
4608 (get-text-property (1+ (match-beginning 0)) 'message-deletable)
4609 (message-delete-line))
4611 ;; Go through all the required headers and see if they are in the
4612 ;; articles already. If they are not, or are empty, they are
4613 ;; inserted automatically - except for Subject, Newsgroups and
4616 (goto-char (point-min))
4617 (setq elem (pop headers))
4619 (if (eq (car elem) 'optional)
4620 (setq header (cdr elem)
4622 (setq header (car elem)))
4624 (when (or (not (re-search-forward
4628 (if (stringp header)
4630 (symbol-name header))))
4634 ;; The header was found. We insert a space after the
4635 ;; colon, if there is none.
4636 (if (/= (char-after) ? ) (insert " ") (forward-char 1))
4637 ;; Find out whether the header is empty.
4638 (looking-at "[ \t]*\n[^ \t]")))
4639 ;; So we find out what value we should insert.
4643 (eq (car elem) 'optional))
4644 ;; This is an optional header. If the cdr of this
4645 ;; is something that is nil, then we do not insert
4647 (setq header (cdr elem))
4648 (or (and (message-functionp (cdr elem))
4649 (funcall (cdr elem)))
4650 (and (boundp (cdr elem))
4651 (symbol-value (cdr elem)))))
4653 ;; The element is a cons. Either the cdr is a
4654 ;; string to be inserted verbatim, or it is a
4655 ;; function, and we insert the value returned from
4657 (or (and (stringp (cdr elem))
4659 (and (message-functionp (cdr elem))
4660 (funcall (cdr elem)))))
4661 ((and (boundp header)
4662 (symbol-value header))
4663 ;; The element is a symbol. We insert the value
4664 ;; of this symbol, if any.
4665 (symbol-value header))
4666 ((not (message-check-element header))
4667 ;; We couldn't generate a value for this header,
4668 ;; so we just ask the user.
4669 (read-from-minibuffer
4670 (format "Empty header for %s; enter value: " header)))))
4671 ;; Finally insert the header.
4673 (not (equal value "")))
4677 ;; This header didn't exist, so we insert it.
4678 (goto-char (point-max))
4680 (cdr (assq header message-header-format-alist))))
4682 (funcall formatter header value)
4683 (insert (if (stringp header)
4684 header (symbol-name header))
4686 ;; We check whether the value was ended by a
4687 ;; newline. If now, we insert one.
4691 ;; The value of this header was empty, so we clear
4692 ;; totally and insert the new value.
4693 (delete-region (point) (gnus-point-at-eol))
4694 ;; If the header is optional, and the header was
4695 ;; empty, we con't insert it anyway.
4698 ;; Add the deletable property to the headers that require it.
4699 (and (memq header message-deletable-headers)
4700 (progn (beginning-of-line) (looking-at "[^:]+: "))
4701 (add-text-properties
4702 (point) (match-end 0)
4703 '(message-deletable t face italic) (current-buffer)))))))
4704 ;; Insert new Sender if the From is strange.
4705 (let ((from (message-fetch-field "from"))
4706 (sender (message-fetch-field "sender"))
4707 (secure-sender (message-make-sender)))
4709 (not (message-check-element 'sender))
4712 (cadr (mail-extract-address-components from)))
4713 (downcase secure-sender)))
4718 (cadr (mail-extract-address-components sender)))
4719 (downcase secure-sender)))))
4720 (goto-char (point-min))
4721 ;; Rename any old Sender headers to Original-Sender.
4722 (when (re-search-forward "^\\(Original-\\)*Sender:" nil t)
4724 (insert "Original-")
4725 (beginning-of-line))
4726 (when (or (message-news-p)
4727 (string-match "@.+\\.." secure-sender))
4728 (insert "Sender: " secure-sender "\n")))))))
4730 (defun message-insert-courtesy-copy ()
4731 "Insert a courtesy message in mail copies of combined messages."
4735 (message-narrow-to-headers)
4736 (when (setq newsgroups (message-fetch-field "newsgroups"))
4737 (goto-char (point-max))
4738 (insert "Posted-To: " newsgroups "\n")))
4740 (when message-courtesy-message
4742 ((string-match "%s" message-courtesy-message)
4743 (insert (format message-courtesy-message newsgroups)))
4745 (insert message-courtesy-message)))))))
4748 ;;; Setting up a message buffer
4751 (defun message-fill-address (header value)
4753 (narrow-to-region (point) (point))
4754 (insert (capitalize (symbol-name header))
4756 (if (consp value) (car value) value)
4758 (narrow-to-region (point-min) (1- (point-max)))
4760 (goto-char (point-min))
4762 (skip-chars-forward "^,\"" (point-max))
4763 (if (or (eq (char-after) ?,)
4766 (if (and (> (current-column) 78)
4772 (setq last (1+ (point))))
4773 (setq last (1+ (point)))))
4774 (setq quoted (not quoted)))
4777 (goto-char (point-max))
4781 (defun message-fill-header (header value)
4782 (let ((begin (point))
4785 (insert (capitalize (symbol-name header))
4787 (if (consp value) (car value) value)
4790 (narrow-to-region begin (point))
4791 (fill-region-as-paragraph begin (point))
4792 ;; Tapdance around looong Message-IDs.
4794 (when (looking-at "[ \t]*$")
4795 (message-delete-line))
4797 (re-search-forward ":" nil t)
4798 (when (looking-at "\n[ \t]+")
4799 (replace-match " " t t))
4800 (goto-char (point-max)))))
4802 (defun message-shorten-1 (list cut surplus)
4803 "Cut SURPLUS elements out of LIST, beginning with CUTth one."
4804 (setcdr (nthcdr (- cut 2) list)
4805 (nthcdr (+ (- cut 2) surplus 1) list)))
4807 (defun message-shorten-references (header references)
4808 "Trim REFERENCES to be 21 Message-ID long or less, and fold them.
4809 If folding is disallowed, also check that the REFERENCES are less
4810 than 988 characters long, and if they are not, trim them until they are."
4817 (goto-char (point-min))
4818 ;; Cons a list of valid references.
4819 (while (re-search-forward "<[^>]+>" nil t)
4820 (push (match-string 0) refs))
4821 (setq refs (nreverse refs)
4822 count (length refs)))
4824 ;; If the list has more than MAXCOUNT elements, trim it by
4825 ;; removing the CUTth element and the required number of
4826 ;; elements that follow.
4827 (when (> count maxcount)
4828 (let ((surplus (- count maxcount)))
4829 (message-shorten-1 refs cut surplus)
4830 (decf count surplus)))
4832 ;; If folding is disallowed, make sure the total length (including
4833 ;; the spaces between) will be less than MAXSIZE characters.
4835 ;; Only disallow folding for News messages. At this point the headers
4836 ;; have not been generated, thus we use message-this-is-news directly.
4837 (when (and message-this-is-news message-cater-to-broken-inn)
4839 (totalsize (+ (apply #'+ (mapcar #'length refs))
4842 (ptr (nthcdr (1- cut) refs)))
4843 ;; Decide how many elements to cut off...
4844 (while (> totalsize maxsize)
4845 (decf totalsize (1+ (length (car ptr))))
4847 (setq ptr (cdr ptr)))
4850 (message-shorten-1 refs cut surplus))))
4852 ;; Finally, collect the references back into a string and insert
4853 ;; it into the buffer.
4854 (let ((refstring (mapconcat #'identity refs " ")))
4855 (if (and message-this-is-news message-cater-to-broken-inn)
4856 (insert (capitalize (symbol-name header)) ": "
4858 (message-fill-header header refstring)))))
4860 (defun message-position-point ()
4861 "Move point to where the user probably wants to find it."
4862 (message-narrow-to-headers)
4864 ((re-search-forward "^[^:]+:[ \t]*$" nil t)
4865 (search-backward ":" )
4868 (if (eq (char-after) ? )
4872 (goto-char (point-max))
4875 (unless (looking-at "$")
4879 (defcustom message-beginning-of-line t
4880 "Whether C-a goes to beginning of header values."
4881 :group 'message-buffers
4884 (defun message-beginning-of-line (&optional n)
4885 "Move point to beginning of header value or to beginning of line."
4887 (let ((zrs 'zmacs-region-stays))
4888 (when (and (interactive-p) (boundp zrs))
4890 (if (and message-beginning-of-line
4891 (message-point-in-header-p))
4892 (let* ((here (point))
4893 (bol (progn (beginning-of-line n) (point)))
4894 (eol (gnus-point-at-eol))
4895 (eoh (re-search-forward ": *" eol t)))
4896 (if (or (not eoh) (equal here eoh))
4899 (beginning-of-line n)))
4901 (defun message-buffer-name (type &optional to group)
4902 "Return a new (unique) buffer name based on TYPE and TO."
4904 ;; Generate a new buffer name The Message Way.
4905 ((eq message-generate-new-buffers 'unique)
4906 (generate-new-buffer-name
4910 (or (car (mail-extract-address-components to))
4913 (if (and group (not (string= group ""))) (concat " on " group) "")
4915 ;; Check whether `message-generate-new-buffers' is a function,
4916 ;; and if so, call it.
4917 ((message-functionp message-generate-new-buffers)
4918 (funcall message-generate-new-buffers type to group))
4919 ((eq message-generate-new-buffers 'unsent)
4920 (generate-new-buffer-name
4921 (concat "*unsent " type
4924 (or (car (mail-extract-address-components to))
4927 (if (and group (not (string= group ""))) (concat " on " group) "")
4929 ;; Use standard name.
4931 (format "*%s message*" type))))
4933 (defun message-pop-to-buffer (name)
4934 "Pop to buffer NAME, and warn if it already exists and is modified."
4935 (let ((buffer (get-buffer name)))
4937 (buffer-name buffer))
4939 (set-buffer (pop-to-buffer buffer))
4940 (when (and (buffer-modified-p)
4942 "Message already being composed; erase? ")))
4943 (error "Message being composed")))
4944 (set-buffer (pop-to-buffer name)))
4948 (defun message-do-send-housekeeping ()
4949 "Kill old message buffers."
4950 ;; We might have sent this buffer already. Delete it from the
4952 (setq message-buffer-list (delq (current-buffer) message-buffer-list))
4953 (while (and message-max-buffers
4955 (>= (length message-buffer-list) message-max-buffers))
4956 ;; Kill the oldest buffer -- unless it has been changed.
4957 (let ((buffer (pop message-buffer-list)))
4958 (when (and (buffer-name buffer)
4959 (not (buffer-modified-p buffer)))
4960 (kill-buffer buffer))))
4961 ;; Rename the buffer.
4962 (if message-send-rename-function
4963 (funcall message-send-rename-function)
4964 ;; Note: mail-abbrevs of XEmacs renames buffer name behind Gnus.
4966 "\\`\\*\\(sent \\|unsent \\)?\\(.+\\)\\*[^\\*]*\\|\\`mail to "
4968 (let ((name (match-string 2 (buffer-name)))
4970 (if (not (or (null name)
4971 (string-equal name "mail")
4972 (string-equal name "posting")))
4973 (setq name (concat "*sent " name "*"))
4974 (message-narrow-to-headers)
4975 (setq to (message-fetch-field "to"))
4976 (setq group (message-fetch-field "newsgroups"))
4980 (to (concat "*sent mail to "
4981 (or (car (mail-extract-address-components to))
4983 ((and group (not (string= group "")))
4984 (concat "*sent posting on " group "*"))
4985 (t "*sent mail*"))))
4986 (unless (string-equal name (buffer-name))
4987 (rename-buffer name t)))))
4988 ;; Push the current buffer onto the list.
4989 (when message-max-buffers
4990 (setq message-buffer-list
4991 (nconc message-buffer-list (list (current-buffer))))))
4993 (defun message-mail-user-agent ()
4995 ((not message-mail-user-agent) nil)
4996 ((eq message-mail-user-agent t) mail-user-agent)
4997 (t message-mail-user-agent))))
4998 (if (memq mua '(message-user-agent gnus-user-agent))
5002 (defun message-setup (headers &optional replybuffer actions switch-function)
5003 (let ((mua (message-mail-user-agent))
5004 subject to field yank-action)
5005 (if (not (and message-this-is-mail mua))
5006 (message-setup-1 headers replybuffer actions)
5008 (setq yank-action (list 'insert-buffer replybuffer)))
5009 (setq headers (copy-sequence headers))
5010 (setq field (assq 'Subject headers))
5012 (setq subject (cdr field))
5013 (setq headers (delq field headers)))
5014 (setq field (assq 'To headers))
5016 (setq to (cdr field))
5017 (setq headers (delq field headers)))
5018 (let ((mail-user-agent mua))
5019 (compose-mail to subject
5020 (mapcar (lambda (item)
5022 (format "%s" (car item))
5025 nil switch-function yank-action actions)))))
5027 (defun message-headers-to-generate (headers included-headers excluded-headers)
5028 "Return a list that includes all headers from HEADERS.
5029 If INCLUDED-HEADERS is a list, just include those headers. If if is
5030 t, include all headers. In any case, headers from EXCLUDED-HEADERS
5034 (dolist (header headers)
5035 (setq header-name (cond
5036 ((and (consp header)
5037 (eq (car header) 'optional))
5038 ;; On the form (optional . Header)
5041 ;; On the form (Header . function)
5046 (when (and (not (memq header-name excluded-headers))
5047 (or (eq included-headers t)
5048 (memq header-name included-headers)))
5049 (push header result)))
5052 (defun message-setup-1 (headers &optional replybuffer actions)
5053 (dolist (action actions)
5055 (add-to-list 'message-send-actions
5056 `(apply ',(car action) ',(cdr action)))))
5057 (setq message-reply-buffer replybuffer)
5058 (goto-char (point-min))
5059 ;; Insert all the headers.
5062 (alist message-header-format-alist))
5064 (unless (assq (caar h) message-header-format-alist)
5065 (push (list (caar h)) alist))
5069 (delete-region (point) (progn (forward-line -1) (point)))
5070 (when message-default-headers
5071 (insert message-default-headers)
5072 (or (bolp) (insert ?\n)))
5076 (insert mail-header-separator "\n")
5080 (when (message-news-p)
5081 (when message-default-news-headers
5082 (insert message-default-news-headers)
5083 (or (bolp) (insert ?\n)))
5084 (when message-generate-headers-first
5085 (message-generate-headers
5086 (message-headers-to-generate
5087 (append message-required-news-headers
5088 message-required-headers)
5089 message-generate-headers-first
5090 '(Lines Subject)))))
5091 (when (message-mail-p)
5092 (when message-default-mail-headers
5093 (insert message-default-mail-headers)
5094 (or (bolp) (insert ?\n)))
5095 (when message-generate-headers-first
5096 (message-generate-headers
5097 (message-headers-to-generate
5098 (append message-required-mail-headers
5099 message-required-headers)
5100 message-generate-headers-first
5101 '(Lines Subject)))))
5102 (run-hooks 'message-signature-setup-hook)
5103 (message-insert-signature)
5105 (message-narrow-to-headers)
5106 (if message-alternative-emails
5107 (message-use-alternative-email-as-from))
5108 (run-hooks 'message-header-setup-hook))
5109 (set-buffer-modified-p nil)
5110 (setq buffer-undo-list nil)
5111 (run-hooks 'message-setup-hook)
5112 (message-position-point)
5115 (defun message-set-auto-save-file-name ()
5116 "Associate the message buffer with a file in the drafts directory."
5117 (when message-auto-save-directory
5118 (unless (file-directory-p
5119 (directory-file-name message-auto-save-directory))
5120 (make-directory message-auto-save-directory t))
5122 (setq message-draft-article
5123 (nndraft-request-associate-buffer "drafts"))
5124 (setq buffer-file-name (expand-file-name
5125 (if (memq system-type
5126 '(ms-dos ms-windows windows-nt
5127 cygwin cygwin32 win32 w32
5131 message-auto-save-directory))
5132 (setq buffer-auto-save-file-name (make-auto-save-file-name)))
5133 (clear-visited-file-modtime)
5134 (setq buffer-file-coding-system message-draft-coding-system)))
5136 (defun message-disassociate-draft ()
5137 "Disassociate the message buffer from the drafts directory."
5138 (when message-draft-article
5139 (nndraft-request-expire-articles
5140 (list message-draft-article) "drafts" nil t)))
5142 (defun message-insert-headers ()
5143 "Generate the headers for the article."
5147 (message-narrow-to-headers)
5148 (when (message-news-p)
5149 (message-generate-headers
5152 (copy-sequence message-required-news-headers)))))
5153 (when (message-mail-p)
5154 (message-generate-headers
5157 (copy-sequence message-required-mail-headers))))))))
5162 ;;; Commands for interfacing with message
5166 (defun message-mail (&optional to subject
5167 other-headers continue switch-function
5168 yank-action send-actions)
5169 "Start editing a mail message to be sent.
5170 OTHER-HEADERS is an alist of header/value pairs."
5172 (let ((message-this-is-mail t) replybuffer)
5173 (unless (message-mail-user-agent)
5174 (message-pop-to-buffer (message-buffer-name "mail" to)))
5175 ;; FIXME: message-mail should do something if YANK-ACTION is not
5177 (and (consp yank-action) (eq (car yank-action) 'insert-buffer)
5178 (setq replybuffer (nth 1 yank-action)))
5181 `((To . ,(or to "")) (Subject . ,(or subject "")))
5182 (when other-headers other-headers))
5183 replybuffer send-actions)
5184 ;; FIXME: Should return nil if failure.
5188 (defun message-news (&optional newsgroups subject)
5189 "Start editing a news article to be sent."
5191 (let ((message-this-is-news t))
5192 (message-pop-to-buffer (message-buffer-name "posting" nil newsgroups))
5193 (message-setup `((Newsgroups . ,(or newsgroups ""))
5194 (Subject . ,(or subject ""))))))
5196 (defun message-get-reply-headers (wide &optional to-address address-headers)
5197 (let (follow-to mct never-mct to cc author mft recipients)
5198 ;; Find all relevant headers we need.
5199 (setq to (message-fetch-field "to")
5200 cc (message-fetch-field "cc")
5201 mct (message-fetch-field "mail-copies-to")
5202 author (or (message-fetch-field "mail-reply-to")
5203 (message-fetch-field "reply-to")
5204 (message-fetch-field "from")
5206 mft (and message-use-mail-followup-to
5207 (message-fetch-field "mail-followup-to")))
5209 ;; Handle special values of Mail-Copies-To.
5211 (cond ((or (equal (downcase mct) "never")
5212 (equal (downcase mct) "nobody"))
5215 ((or (equal (downcase mct) "always")
5216 (equal (downcase mct) "poster"))
5217 (setq mct author))))
5220 ;; Build (textual) list of new recipient addresses.
5223 (setq recipients (concat ", " author)))
5225 (dolist (header address-headers)
5226 (let ((value (message-fetch-field header)))
5228 (setq recipients (concat recipients ", " value))))))
5230 (string-match "[^ \t,]" mft)
5231 (or (not (eq message-use-mail-followup-to 'ask))
5232 (message-y-or-n-p "Obey Mail-Followup-To? " t "\
5233 You should normally obey the Mail-Followup-To: header. In this
5234 article, it has the value of
5238 which directs your response to " (if (string-match "," mft)
5239 "the specified addresses"
5240 "that address only") ".
5242 Most commonly, Mail-Followup-To is used by a mailing list poster to
5243 express that responses should be sent to just the list, and not the
5246 If a message is posted to several mailing lists, Mail-Followup-To may
5247 also be used to direct the following discussion to one list only,
5248 because discussions that are spread over several lists tend to be
5249 fragmented and very difficult to follow.
5251 Also, some source/announcement lists are not intended for discussion;
5252 responses here are directed to other addresses.")))
5253 (setq recipients (concat ", " mft)))
5255 (setq recipients (concat ", " to-address))
5256 ;; If the author explicitly asked for a copy, we don't deny it to them.
5257 (if mct (setq recipients (concat recipients ", " mct))))
5259 (setq recipients (if never-mct "" (concat ", " author)))
5260 (if to (setq recipients (concat recipients ", " to)))
5261 (if cc (setq recipients (concat recipients ", " cc)))
5262 (if mct (setq recipients (concat recipients ", " mct)))))
5263 (if (>= (length recipients) 2)
5264 ;; Strip the leading ", ".
5265 (setq recipients (substring recipients 2)))
5266 ;; Squeeze whitespace.
5267 (while (string-match "[ \t][ \t]+" recipients)
5268 (setq recipients (replace-match " " t t recipients)))
5269 ;; Remove addresses that match `rmail-dont-reply-to-names'.
5270 (let ((rmail-dont-reply-to-names message-dont-reply-to-names))
5271 (setq recipients (rmail-dont-reply-to recipients)))
5272 ;; Perhaps "Mail-Copies-To: never" removed the only address?
5273 (if (string-equal recipients "")
5274 (setq recipients author))
5275 ;; Convert string to a list of (("foo@bar" . "Name <Foo@BAR>") ...).
5279 (cons (downcase (mail-strip-quoted-names addr)) addr))
5280 (message-tokenize-header recipients)))
5281 ;; Remove first duplicates. (Why not all duplicates? Is this a bug?)
5282 (let ((s recipients))
5284 (setq recipients (delq (assoc (car (pop s)) s) recipients))))
5286 ;; Remove hierarchical lists that are contained within each other,
5287 ;; if message-hierarchical-addresses is defined.
5288 (when message-hierarchical-addresses
5289 (let ((plain-addrs (mapcar 'car recipients))
5292 (setq subaddrs (assoc (car plain-addrs)
5293 message-hierarchical-addresses)
5294 plain-addrs (cdr plain-addrs))
5296 (setq subaddrs (cdr subaddrs))
5298 (setq recip (assoc (car subaddrs) recipients)
5299 subaddrs (cdr subaddrs))
5301 (setq recipients (delq recip recipients))))))))
5303 ;; Build the header alist. Allow the user to be asked whether
5304 ;; or not to reply to all recipients in a wide reply.
5305 (setq follow-to (list (cons 'To (cdr (pop recipients)))))
5306 (when (and recipients
5307 (or (not message-wide-reply-confirm-recipients)
5308 (y-or-n-p "Reply to all recipients? ")))
5309 (setq recipients (mapconcat
5310 (lambda (addr) (cdr addr)) recipients ", "))
5311 (if (string-match "^ +" recipients)
5312 (setq recipients (substring recipients (match-end 0))))
5313 (push (cons 'Cc recipients) follow-to)))
5317 (defun message-reply (&optional to-address wide)
5318 "Start editing a reply to the article in the current buffer."
5320 (require 'gnus-sum) ; for gnus-list-identifiers
5321 (let ((cur (current-buffer))
5322 from subject date reply-to to cc
5323 references message-id follow-to
5324 (inhibit-point-motion-hooks t)
5325 (message-this-is-mail t)
5328 (message-narrow-to-head-1)
5329 ;; Allow customizations to have their say.
5331 ;; This is a regular reply.
5332 (when (message-functionp message-reply-to-function)
5334 (setq follow-to (funcall message-reply-to-function))))
5335 ;; This is a followup.
5336 (when (message-functionp message-wide-reply-to-function)
5339 (funcall message-wide-reply-to-function)))))
5340 (setq message-id (message-fetch-field "message-id" t)
5341 references (message-fetch-field "references")
5342 date (message-fetch-field "date")
5343 from (message-fetch-field "from")
5344 subject (or (message-fetch-field "subject") "none"))
5345 (when gnus-list-identifiers
5346 (setq subject (message-strip-list-identifiers subject)))
5347 (setq subject (concat "Re: " (message-strip-subject-re subject)))
5348 (when message-subject-trailing-was-query
5349 (setq subject (message-strip-subject-trailing-was subject)))
5351 (when (and (setq gnus-warning (message-fetch-field "gnus-warning"))
5352 (string-match "<[^>]+>" gnus-warning))
5353 (setq message-id (match-string 0 gnus-warning)))
5356 (setq follow-to (message-get-reply-headers wide to-address))))
5358 (unless (message-mail-user-agent)
5359 (message-pop-to-buffer
5360 (message-buffer-name
5361 (if wide "wide reply" "reply") from
5362 (if wide to-address nil))))
5364 (setq message-reply-headers
5365 (vector 0 subject from date message-id references 0 0 ""))
5368 `((Subject . ,subject)
5373 (defun message-wide-reply (&optional to-address)
5374 "Make a \"wide\" reply to the message in the current buffer."
5376 (message-reply to-address t))
5379 (defun message-followup (&optional to-newsgroups)
5380 "Follow up to the message in the current buffer.
5381 If TO-NEWSGROUPS, use that as the new Newsgroups line."
5383 (require 'gnus-sum) ; for gnus-list-identifiers
5384 (let ((cur (current-buffer))
5385 from subject date reply-to mrt mct
5386 references message-id follow-to
5387 (inhibit-point-motion-hooks t)
5388 (message-this-is-news t)
5389 followup-to distribution newsgroups gnus-warning posted-to)
5392 (goto-char (point-min))
5393 (if (search-forward "\n\n" nil t)
5396 (when (message-functionp message-followup-to-function)
5398 (funcall message-followup-to-function)))
5399 (setq from (message-fetch-field "from")
5400 date (message-fetch-field "date")
5401 subject (or (message-fetch-field "subject") "none")
5402 references (message-fetch-field "references")
5403 message-id (message-fetch-field "message-id" t)
5404 followup-to (message-fetch-field "followup-to")
5405 newsgroups (message-fetch-field "newsgroups")
5406 posted-to (message-fetch-field "posted-to")
5407 reply-to (message-fetch-field "reply-to")
5408 mrt (message-fetch-field "mail-reply-to")
5409 distribution (message-fetch-field "distribution")
5410 mct (message-fetch-field "mail-copies-to"))
5411 (when (and (setq gnus-warning (message-fetch-field "gnus-warning"))
5412 (string-match "<[^>]+>" gnus-warning))
5413 (setq message-id (match-string 0 gnus-warning)))
5414 ;; Remove bogus distribution.
5415 (when (and (stringp distribution)
5416 (let ((case-fold-search t))
5417 (string-match "world" distribution)))
5418 (setq distribution nil))
5419 (if gnus-list-identifiers
5420 (setq subject (message-strip-list-identifiers subject)))
5421 (setq subject (concat "Re: " (message-strip-subject-re subject)))
5422 (when message-subject-trailing-was-query
5423 (setq subject (message-strip-subject-trailing-was subject)))
5426 (message-pop-to-buffer (message-buffer-name "followup" from newsgroups))
5428 (setq message-reply-headers
5429 (vector 0 subject from date message-id references 0 0 ""))
5432 `((Subject . ,subject)
5435 (list (cons 'Newsgroups to-newsgroups)))
5436 (follow-to follow-to)
5437 ((and followup-to message-use-followup-to)
5440 ((equal (downcase followup-to) "poster")
5441 (if (or (eq message-use-followup-to 'use)
5442 (message-y-or-n-p "Obey Followup-To: poster? " t "\
5443 You should normally obey the Followup-To: header.
5445 `Followup-To: poster' sends your response via e-mail instead of news.
5447 A typical situation where `Followup-To: poster' is used is when the poster
5448 does not read the newsgroup, so he wouldn't see any replies sent to it."))
5450 (setq message-this-is-news nil)
5451 (cons 'To (or mrt reply-to from "")))
5452 (cons 'Newsgroups newsgroups)))
5454 (if (or (equal followup-to newsgroups)
5455 (not (eq message-use-followup-to 'ask))
5457 (concat "Obey Followup-To: " followup-to "? ") t "\
5458 You should normally obey the Followup-To: header.
5460 `Followup-To: " followup-to "'
5461 directs your response to " (if (string-match "," followup-to)
5462 "the specified newsgroups"
5463 "that newsgroup only") ".
5465 If a message is posted to several newsgroups, Followup-To is often
5466 used to direct the following discussion to one newsgroup only,
5467 because discussions that are spread over several newsgroup tend to
5468 be fragmented and very difficult to follow.
5470 Also, some source/announcement newsgroups are not intended for discussion;
5471 responses here are directed to other newsgroups."))
5472 (cons 'Newsgroups followup-to)
5473 (cons 'Newsgroups newsgroups))))))
5475 `((Newsgroups . ,posted-to)))
5477 `((Newsgroups . ,newsgroups))))
5478 ,@(and distribution (list (cons 'Distribution distribution)))
5480 (not (or (equal (downcase mct) "never")
5481 (equal (downcase mct) "nobody"))))
5482 (list (cons 'Cc (if (or (equal (downcase mct) "always")
5483 (equal (downcase mct) "poster"))
5484 (or mrt reply-to from "")
5491 (defun message-cancel-news (&optional arg)
5492 "Cancel an article you posted.
5493 If ARG, allow editing of the cancellation message."
5495 (unless (message-news-p)
5496 (error "This is not a news article; canceling is impossible"))
5497 (let (from newsgroups message-id distribution buf sender)
5499 ;; Get header info from original article.
5501 (message-narrow-to-head-1)
5502 (setq from (message-fetch-field "from")
5503 sender (message-fetch-field "sender")
5504 newsgroups (message-fetch-field "newsgroups")
5505 message-id (message-fetch-field "message-id" t)
5506 distribution (message-fetch-field "distribution")))
5507 ;; Make sure that this article was written by the user.
5509 ;; Canlock-logic as suggested by Per Abrahamsen
5510 ;; <abraham@dina.kvl.dk>
5512 ;; IF article has cancel-lock THEN
5513 ;; IF we can verify it THEN
5516 ;; error: cancellock: article is not yours
5518 ;; Use old rules, comparing sender...
5519 (if (message-fetch-field "Cancel-Lock")
5520 (if (null (canlock-verify))
5522 (error "Failed to verify Cancel-lock: This article is not yours"))
5524 (message-gnksa-enable-p 'cancel-messages)
5528 (downcase (message-make-sender))))
5530 (downcase (cadr (mail-extract-address-components from)))
5531 (downcase (cadr (mail-extract-address-components
5532 (message-make-from))))))
5533 (error "This article is not yours"))
5534 (when (yes-or-no-p "Do you really want to cancel this article? ")
5535 ;; Make control message.
5538 (setq buf (set-buffer (get-buffer-create " *message cancel*"))))
5540 (insert "Newsgroups: " newsgroups "\n"
5542 "Subject: cmsg cancel " message-id "\n"
5543 "Control: cancel " message-id "\n"
5545 (concat "Distribution: " distribution "\n")
5547 mail-header-separator "\n"
5548 message-cancel-message)
5549 (run-hooks 'message-cancel-hook)
5551 (message "Canceling your article...")
5552 (if (let ((message-syntax-checks
5553 'dont-check-for-anything-just-trust-me))
5554 (funcall message-send-news-function))
5555 (message "Canceling your article...done"))
5556 (kill-buffer buf))))))
5559 (defun message-supersede ()
5560 "Start composing a message to supersede the current message.
5561 This is done simply by taking the old article and adding a Supersedes
5562 header line with the old Message-ID."
5564 (let ((cur (current-buffer))
5565 (sender (message-fetch-field "sender"))
5566 (from (message-fetch-field "from")))
5567 ;; Check whether the user owns the article that is to be superseded.
5569 ;; Canlock-logic as suggested by Per Abrahamsen
5570 ;; <abraham@dina.kvl.dk>
5572 ;; IF article has cancel-lock THEN
5573 ;; IF we can verify it THEN
5576 ;; error: cancellock: article is not yours
5578 ;; Use old rules, comparing sender...
5579 (if (message-fetch-field "Cancel-Lock")
5580 (if (null (canlock-verify))
5582 (error "Failed to verify Cancel-lock: This article is not yours"))
5584 (message-gnksa-enable-p 'cancel-messages)
5588 (downcase (message-make-sender))))
5590 (downcase (cadr (mail-extract-address-components from)))
5591 (downcase (cadr (mail-extract-address-components
5592 (message-make-from))))))
5593 (error "This article is not yours"))
5594 ;; Get a normal message buffer.
5595 (message-pop-to-buffer (message-buffer-name "supersede"))
5596 (insert-buffer-substring cur)
5598 (message-narrow-to-head-1)
5599 ;; Remove unwanted headers.
5600 (when message-ignored-supersedes-headers
5601 (message-remove-header message-ignored-supersedes-headers t))
5602 (goto-char (point-min))
5603 (if (not (re-search-forward "^Message-ID: " nil t))
5604 (error "No Message-ID in this article")
5605 (replace-match "Supersedes: " t t))
5606 (goto-char (point-max))
5607 (insert mail-header-separator)
5612 (defun message-recover ()
5613 "Reread contents of current buffer from its last auto-save file."
5615 (let ((file-name (make-auto-save-file-name)))
5616 (cond ((save-window-excursion
5617 (if (not (eq system-type 'vax-vms))
5618 (with-output-to-temp-buffer "*Directory*"
5619 (with-current-buffer standard-output
5620 (fundamental-mode)) ; for Emacs 20.4+
5621 (buffer-disable-undo standard-output)
5622 (let ((default-directory "/"))
5624 "ls" nil standard-output nil "-l" file-name))))
5625 (yes-or-no-p (format "Recover auto save file %s? " file-name)))
5626 (let ((buffer-read-only nil))
5628 (insert-file-contents file-name nil)))
5629 (t (error "message-recover cancelled")))))
5631 ;;; Washing Subject:
5633 (defun message-wash-subject (subject)
5634 "Remove junk like \"Re:\", \"(fwd)\", etc. added to subject string SUBJECT.
5635 Previous forwarders, replyers, etc. may add it."
5638 (goto-char (point-min))
5639 ;; strip Re/Fwd stuff off the beginning
5640 (while (re-search-forward
5641 "\\([Rr][Ee]:\\|[Ff][Ww][Dd]\\(\\[[0-9]*\\]\\)?:\\|[Ff][Ww]:\\)" nil t)
5644 ;; and gnus-style forwards [foo@bar.com] subject
5645 (goto-char (point-min))
5646 (while (re-search-forward "\\[[^ \t]*\\(@\\|\\.\\)[^ \t]*\\]" nil t)
5650 (goto-char (point-max))
5651 (while (re-search-backward "([Ff][Ww][Dd])" nil t)
5654 ;; and finally, any whitespace that was left-over
5655 (goto-char (point-min))
5656 (while (re-search-forward "^[ \t]+" nil t)
5658 (goto-char (point-max))
5659 (while (re-search-backward "[ \t]+$" nil t)
5664 ;;; Forwarding messages.
5666 (defvar message-forward-decoded-p nil
5667 "Non-nil means the original message is decoded.")
5669 (defun message-forward-subject-author-subject (subject)
5670 "Generate a SUBJECT for a forwarded message.
5671 The form is: [Source] Subject, where if the original message was mail,
5672 Source is the sender, and if the original message was news, Source is
5673 the list of newsgroups is was posted to."
5676 (or (message-fetch-field "newsgroups")
5677 (message-fetch-field "from")
5679 (if message-forward-decoded-p
5681 (mail-decode-encoded-word-string prefix)))
5684 (defun message-forward-subject-fwd (subject)
5685 "Generate a SUBJECT for a forwarded message.
5686 The form is: Fwd: Subject, where Subject is the original subject of
5688 (concat "Fwd: " subject))
5690 (defun message-make-forward-subject ()
5691 "Return a Subject header suitable for the message in the current buffer."
5694 (message-narrow-to-head-1)
5695 (let ((funcs message-make-forward-subject-function)
5696 (subject (message-fetch-field "Subject")))
5699 (if message-forward-decoded-p
5701 (mail-decode-encoded-word-string subject))
5703 (if message-wash-forwarded-subjects
5704 (setq subject (message-wash-subject subject)))
5705 ;; Make sure funcs is a list.
5708 (setq funcs (list funcs)))
5709 ;; Apply funcs in order, passing subject generated by previous
5710 ;; func to the next one.
5712 (when (message-functionp (car funcs))
5713 (setq subject (funcall (car funcs) subject)))
5714 (setq funcs (cdr funcs)))
5718 (defvar gnus-article-decoded-p))
5722 (defun message-forward (&optional news digest)
5723 "Forward the current message via mail.
5724 Optional NEWS will use news to forward instead of mail.
5725 Optional DIGEST will use digest to forward."
5727 (let* ((cur (current-buffer))
5728 (message-forward-decoded-p
5729 (if (local-variable-p 'gnus-article-decoded-p (current-buffer))
5730 gnus-article-decoded-p ;; In an article buffer.
5731 message-forward-decoded-p))
5732 (subject (message-make-forward-subject)))
5734 (message-news nil subject)
5735 (message-mail nil subject))
5736 (message-forward-make-body cur digest)))
5739 (defun message-forward-make-body (forward-buffer &optional digest)
5740 ;; Put point where we want it before inserting the forwarded
5742 (if message-forward-before-signature
5744 (goto-char (point-max)))
5745 (if message-forward-as-mime
5747 (insert "\n<#multipart type=digest>\n")
5748 (if message-forward-show-mml
5749 (insert "\n\n<#mml type=message/rfc822 disposition=inline>\n")
5750 (insert "\n\n<#part type=message/rfc822 disposition=inline raw=t>\n")))
5751 (insert "\n-------------------- Start of forwarded message --------------------\n"))
5752 (let ((b (point)) e)
5754 (if message-forward-as-mime
5755 (insert-buffer-substring forward-buffer)
5756 (mml-insert-buffer forward-buffer))
5757 (if (and message-forward-show-mml
5758 (not message-forward-decoded-p))
5761 (mm-disable-multibyte-mule4)
5763 (with-current-buffer forward-buffer
5764 (mm-with-unibyte-current-buffer-mule4 (buffer-string))))
5765 (mm-enable-multibyte-mule4)
5767 (goto-char (point-min))
5768 (when (looking-at "From ")
5769 (replace-match "X-From-Line: "))
5772 (narrow-to-region (point) (point))
5773 (mml-insert-buffer forward-buffer)
5774 (goto-char (point-min))
5775 (when (looking-at "From ")
5776 (replace-match "X-From-Line: "))
5777 (goto-char (point-max)))))
5779 (if message-forward-as-mime
5781 (insert "<#/multipart>\n")
5782 (if message-forward-show-mml
5783 (insert "<#/mml>\n")
5784 (insert "<#/part>\n")))
5785 (insert "\n-------------------- End of forwarded message --------------------\n"))
5786 (if (and digest message-forward-as-mime)
5788 (narrow-to-region b e)
5790 (narrow-to-region (point)
5791 (or (search-forward "\n\n" nil t) (point)))
5792 (delete-region (point-min) (point-max)))
5793 (when (and (not current-prefix-arg)
5794 message-forward-ignored-headers
5795 ;; don't remove CTE, X-Gnus etc when doing "raw" forward:
5796 message-forward-show-mml)
5798 (narrow-to-region b e)
5800 (narrow-to-region (point)
5801 (or (search-forward "\n\n" nil t) (point)))
5802 (message-remove-header message-forward-ignored-headers t)))))
5803 (message-position-point))
5806 (defun message-forward-rmail-make-body (forward-buffer)
5807 (save-window-excursion
5808 (set-buffer forward-buffer)
5809 ;; Rmail doesn't have rmail-msg-restore-non-pruned-header in Emacs
5810 ;; 20. FIXIT, or we drop support for rmail in Emacs 20.
5811 (if (rmail-msg-is-pruned)
5812 (rmail-msg-restore-non-pruned-header)))
5813 (message-forward-make-body forward-buffer))
5816 (defun message-insinuate-rmail ()
5817 "Let RMAIL uses message to forward."
5819 (setq rmail-enable-mime-composing t)
5820 (setq rmail-insert-mime-forwarded-message-function
5821 'message-forward-rmail-make-body))
5824 (defun message-resend (address)
5825 "Resend the current article to ADDRESS."
5827 (list (message-read-from-minibuffer "Resend message to: ")))
5828 (message "Resending message to %s..." address)
5830 (let ((cur (current-buffer))
5832 ;; We first set up a normal mail buffer.
5833 (unless (message-mail-user-agent)
5834 (set-buffer (get-buffer-create " *message resend*"))
5836 (let ((message-this-is-mail t)
5838 (message-setup `((To . ,address))))
5839 ;; Insert our usual headers.
5840 (message-generate-headers '(From Date To))
5841 (message-narrow-to-headers)
5842 ;; Remove X-Draft-From header etc.
5843 (message-remove-header message-ignored-mail-headers t)
5844 ;; Rename them all to "Resent-*".
5845 (goto-char (point-min))
5846 (while (re-search-forward "^[A-Za-z]" nil t)
5851 (delete-region (point) (point-max))
5853 ;; Insert the message to be resent.
5854 (insert-buffer-substring cur)
5855 (goto-char (point-min))
5856 (search-forward "\n\n")
5859 (narrow-to-region beg (point))
5860 (message-remove-header message-ignored-resent-headers t)
5861 (goto-char (point-max)))
5862 (insert mail-header-separator)
5863 ;; Rename all old ("Also-")Resent headers.
5864 (while (re-search-backward "^\\(Also-\\)*Resent-" beg t)
5867 ;; Quote any "From " lines at the beginning.
5869 (when (looking-at "From ")
5870 (replace-match "X-From-Line: "))
5872 (let ((message-inhibit-body-encoding t)
5873 message-required-mail-headers)
5874 (message-send-mail))
5875 (kill-buffer (current-buffer)))
5876 (message "Resending message to %s...done" address)))
5879 (defun message-bounce ()
5880 "Re-mail the current message.
5881 This only makes sense if the current message is a bounce message that
5882 contains some mail you have written which has been bounced back to
5885 (let ((handles (mm-dissect-buffer t))
5887 (message-pop-to-buffer (message-buffer-name "bounce"))
5888 (if (stringp (car handles))
5889 ;; This is a MIME bounce.
5890 (mm-insert-part (car (last handles)))
5891 ;; This is a non-MIME bounce, so we try to remove things
5893 (mm-insert-part handles)
5895 (goto-char (point-min))
5896 (search-forward "\n\n" nil t)
5897 (if (or (and (re-search-forward message-unsent-separator nil t)
5899 (re-search-forward "^Return-Path:.*\n" nil t))
5900 ;; We remove everything before the bounced mail.
5903 (if (re-search-forward "^[^ \n\t]+:" nil t)
5906 (when (re-search-backward "^.?From .*\n" nil t)
5907 (delete-region (match-beginning 0) (match-end 0)))))
5908 (mm-enable-multibyte)
5911 (message-narrow-to-head-1)
5912 (message-remove-header message-ignored-bounced-headers t)
5913 (goto-char (point-max))
5914 (insert mail-header-separator))
5915 (message-position-point)))
5918 ;;; Interactive entry points for new message buffers.
5922 (defun message-mail-other-window (&optional to subject)
5923 "Like `message-mail' command, but display mail buffer in another window."
5925 (unless (message-mail-user-agent)
5926 (let ((pop-up-windows t)
5927 (special-display-buffer-names nil)
5928 (special-display-regexps nil)
5929 (same-window-buffer-names nil)
5930 (same-window-regexps nil))
5931 (message-pop-to-buffer (message-buffer-name "mail" to))))
5932 (let ((message-this-is-mail t))
5933 (message-setup `((To . ,(or to "")) (Subject . ,(or subject "")))
5934 nil nil 'switch-to-buffer-other-window)))
5937 (defun message-mail-other-frame (&optional to subject)
5938 "Like `message-mail' command, but display mail buffer in another frame."
5940 (unless (message-mail-user-agent)
5941 (let ((pop-up-frames t)
5942 (special-display-buffer-names nil)
5943 (special-display-regexps nil)
5944 (same-window-buffer-names nil)
5945 (same-window-regexps nil))
5946 (message-pop-to-buffer (message-buffer-name "mail" to))))
5947 (let ((message-this-is-mail t))
5948 (message-setup `((To . ,(or to "")) (Subject . ,(or subject "")))
5949 nil nil 'switch-to-buffer-other-frame)))
5952 (defun message-news-other-window (&optional newsgroups subject)
5953 "Start editing a news article to be sent."
5955 (let ((pop-up-windows t)
5956 (special-display-buffer-names nil)
5957 (special-display-regexps nil)
5958 (same-window-buffer-names nil)
5959 (same-window-regexps nil))
5960 (message-pop-to-buffer (message-buffer-name "posting" nil newsgroups)))
5961 (let ((message-this-is-news t))
5962 (message-setup `((Newsgroups . ,(or newsgroups ""))
5963 (Subject . ,(or subject ""))))))
5966 (defun message-news-other-frame (&optional newsgroups subject)
5967 "Start editing a news article to be sent."
5969 (let ((pop-up-frames t)
5970 (special-display-buffer-names nil)
5971 (special-display-regexps nil)
5972 (same-window-buffer-names nil)
5973 (same-window-regexps nil))
5974 (message-pop-to-buffer (message-buffer-name "posting" nil newsgroups)))
5975 (let ((message-this-is-news t))
5976 (message-setup `((Newsgroups . ,(or newsgroups ""))
5977 (Subject . ,(or subject ""))))))
5981 ;; This code should be moved to underline.el (from which it is stolen).
5984 (defun bold-region (start end)
5985 "Bold all nonblank characters in the region.
5986 Works by overstriking characters.
5987 Called from program, takes two arguments START and END
5988 which specify the range to operate on."
5991 (let ((end1 (make-marker)))
5992 (move-marker end1 (max start end))
5993 (goto-char (min start end))
5994 (while (< (point) end1)
5995 (or (looking-at "[_\^@- ]")
5996 (insert (char-after) "\b"))
5997 (forward-char 1)))))
6000 (defun unbold-region (start end)
6001 "Remove all boldness (overstruck characters) in the region.
6002 Called from program, takes two arguments START and END
6003 which specify the range to operate on."
6006 (let ((end1 (make-marker)))
6007 (move-marker end1 (max start end))
6008 (goto-char (min start end))
6009 (while (re-search-forward "\b" end1 t)
6010 (if (eq (char-after) (char-after (- (point) 2)))
6011 (delete-char -2))))))
6013 (defalias 'message-exchange-point-and-mark 'exchange-point-and-mark)
6015 ;; Support for toolbar
6017 (defvar tool-bar-map)
6018 (defvar tool-bar-mode))
6020 (defun message-tool-bar-local-item-from-menu (command icon in-map &optional from-map &rest props)
6021 ;; We need to make tool bar entries in local keymaps with
6022 ;; `tool-bar-local-item-from-menu' in Emacs > 21.3
6023 (if (fboundp 'tool-bar-local-item-from-menu)
6024 ;; This is for Emacs 21.3
6025 (tool-bar-local-item-from-menu command icon in-map from-map props)
6026 (tool-bar-add-item-from-menu command icon from-map props)))
6028 (defun message-tool-bar-map ()
6029 (or message-tool-bar-map
6030 (setq message-tool-bar-map
6032 (condition-case nil (require 'tool-bar) (error nil))
6033 (fboundp 'tool-bar-add-item-from-menu)
6035 (let ((tool-bar-map (copy-keymap tool-bar-map))
6036 (load-path (mm-image-load-path)))
6037 ;; Zap some items which aren't so relevant and take
6039 (dolist (key '(print-buffer kill-buffer save-buffer
6040 write-file dired open-file))
6041 (define-key tool-bar-map (vector key) nil))
6042 (message-tool-bar-local-item-from-menu
6043 'message-send-and-exit "mail_send" tool-bar-map message-mode-map)
6044 (message-tool-bar-local-item-from-menu
6045 'message-kill-buffer "close" tool-bar-map message-mode-map)
6046 (message-tool-bar-local-item-from-menu
6047 'message-dont-send "cancel" tool-bar-map message-mode-map)
6048 (message-tool-bar-local-item-from-menu
6049 'mml-attach-file "attach" tool-bar-map mml-mode-map)
6050 (message-tool-bar-local-item-from-menu
6051 'ispell-message "spell" tool-bar-map message-mode-map)
6052 (message-tool-bar-local-item-from-menu
6053 'mml-preview "preview"
6054 tool-bar-map mml-mode-map)
6055 (message-tool-bar-local-item-from-menu
6056 'message-insert-importance-high "important"
6057 tool-bar-map message-mode-map)
6058 (message-tool-bar-local-item-from-menu
6059 'message-insert-importance-low "unimportant"
6060 tool-bar-map message-mode-map)
6061 (message-tool-bar-local-item-from-menu
6062 'message-insert-disposition-notification-to "receipt"
6063 tool-bar-map message-mode-map)
6066 ;;; Group name completion.
6068 (defcustom message-newgroups-header-regexp
6069 "^\\(Newsgroups\\|Followup-To\\|Posted-To\\|Gcc\\):"
6070 "Regexp that match headers that lists groups."
6074 (defcustom message-completion-alist
6075 (list (cons message-newgroups-header-regexp 'message-expand-group)
6076 '("^\\(Resent-\\)?\\(To\\|B?Cc\\):" . message-expand-name)
6077 '("^\\(Reply-To\\|From\\|Mail-Followup-To\\|Mail-Copies-To\\):"
6078 . message-expand-name)
6079 '("^\\(Disposition-Notification-To\\|Return-Receipt-To\\):"
6080 . message-expand-name))
6081 "Alist of (RE . FUN). Use FUN for completion on header lines matching RE."
6083 :type '(alist :key-type regexp :value-type function))
6085 (defcustom message-tab-body-function nil
6086 "*Function to execute when `message-tab' (TAB) is executed in the body.
6087 If nil, the function bound in `text-mode-map' or `global-map' is executed."
6091 (defun message-tab ()
6092 "Complete names according to `message-completion-alist'.
6093 Execute function specified by `message-tab-body-function' when not in
6096 (let ((alist message-completion-alist))
6098 (let ((mail-abbrev-mode-regexp (caar alist)))
6099 (not (mail-abbrev-in-expansion-header-p))))
6100 (setq alist (cdr alist)))
6101 (funcall (or (cdar alist) message-tab-body-function
6102 (lookup-key text-mode-map "\t")
6103 (lookup-key global-map "\t")
6104 'indent-relative))))
6106 (defun message-expand-group ()
6107 "Expand the group name under point."
6108 (let* ((b (save-excursion
6113 (skip-chars-forward "^:")
6116 (skip-chars-backward "^, \t\n") (point))))
6117 (completion-ignore-case t)
6118 (string (buffer-substring b (progn (skip-chars-forward "^,\t\n ")
6120 (hashtb (and (boundp 'gnus-active-hashtb) gnus-active-hashtb))
6121 (completions (all-completions string hashtb))
6123 (delete-region b (point))
6125 ((= (length completions) 1)
6126 (if (string= (car completions) string)
6129 (message "Only matching group"))
6130 (insert (car completions))))
6131 ((and (setq comp (try-completion string hashtb))
6132 (not (string= comp string)))
6137 (message "No matching groups")
6138 (save-selected-window
6139 (pop-to-buffer "*Completions*")
6140 (buffer-disable-undo)
6141 (let ((buffer-read-only nil))
6143 (let ((standard-output (current-buffer)))
6144 (display-completion-list (sort completions 'string<)))
6145 (goto-char (point-min))
6146 (delete-region (point) (progn (forward-line 3) (point))))))))))
6148 (defun message-expand-name ()
6149 (if (fboundp 'bbdb-complete-name)
6150 (bbdb-complete-name)
6155 (defun message-talkative-question (ask question show &rest text)
6156 "Call FUNCTION with argument QUESTION; optionally display TEXT... args.
6157 If SHOW is non-nil, the arguments TEXT... are displayed in a temp buffer.
6158 The following arguments may contain lists of values."
6160 (setq text (message-flatten-list text)))
6161 (save-window-excursion
6163 (with-output-to-temp-buffer " *MESSAGE information message*"
6164 (set-buffer " *MESSAGE information message*")
6165 (fundamental-mode) ; for Emacs 20.4+
6166 (mapcar 'princ text)
6167 (goto-char (point-min))))
6168 (funcall ask question))
6169 (funcall ask question)))
6171 (defun message-flatten-list (list)
6172 "Return a new, flat list that contains all elements of LIST.
6174 \(message-flatten-list '(1 (2 3 (4 5 (6))) 7))
6177 (apply 'append (mapcar 'message-flatten-list list)))
6181 (defun message-generate-new-buffer-clone-locals (name &optional varstr)
6182 "Create and return a buffer with name based on NAME using `generate-new-buffer.'
6183 Then clone the local variables and values from the old buffer to the
6184 new one, cloning only the locals having a substring matching the
6186 (let ((oldbuf (current-buffer)))
6188 (set-buffer (generate-new-buffer name))
6189 (message-clone-locals oldbuf varstr)
6192 (defun message-clone-locals (buffer &optional varstr)
6193 "Clone the local variables from BUFFER to the current buffer."
6194 (let ((locals (save-excursion
6196 (buffer-local-variables)))
6197 (regexp "^gnus\\|^nn\\|^message\\|^user-mail-address"))
6200 (when (and (consp local)
6202 (string-match regexp (symbol-name (car local)))
6204 (string-match varstr (symbol-name (car local)))))
6206 (set (make-local-variable (car local))
6210 ;;; Miscellaneous functions
6212 (defsubst message-replace-chars-in-string (string from to)
6213 (mm-subst-char-in-string from to string))
6219 (defvar message-inhibit-body-encoding nil)
6221 (defun message-encode-message-body ()
6222 (unless message-inhibit-body-encoding
6223 (let ((mail-parse-charset (or mail-parse-charset
6224 message-default-charset))
6225 (case-fold-search t)
6226 lines content-type-p)
6229 (narrow-to-region (point) (point-max))
6230 (let ((new (mml-generate-mime)))
6232 (delete-region (point-min) (point-max))
6234 (goto-char (point-min))
6235 (if (eq (aref new 0) ?\n)
6237 (search-forward "\n\n")
6238 (setq lines (buffer-substring (point-min) (1- (point))))
6239 (delete-region (point-min) (point))))))
6241 (message-narrow-to-headers-or-head)
6242 (message-remove-header "Mime-Version")
6243 (goto-char (point-max))
6244 (insert "MIME-Version: 1.0\n")
6247 (setq content-type-p
6249 (re-search-backward "^Content-Type:" nil t))))
6251 (message-narrow-to-headers-or-head)
6252 (message-remove-first-header "Content-Type")
6253 (message-remove-first-header "Content-Transfer-Encoding"))
6254 ;; We always make sure that the message has a Content-Type
6255 ;; header. This is because some broken MTAs and MUAs get
6256 ;; awfully confused when confronted with a message with a
6257 ;; MIME-Version header and without a Content-Type header. For
6258 ;; instance, Solaris' /usr/bin/mail.
6259 (unless content-type-p
6260 (goto-char (point-min))
6261 ;; For unknown reason, MIME-Version doesn't exist.
6262 (when (re-search-forward "^MIME-Version:" nil t)
6264 (insert "Content-Type: text/plain; charset=us-ascii\n"))))))
6266 (defun message-read-from-minibuffer (prompt &optional initial-contents)
6267 "Read from the minibuffer while providing abbrev expansion."
6268 (if (fboundp 'mail-abbrevs-setup)
6269 (let ((mail-abbrev-mode-regexp "")
6270 (minibuffer-setup-hook 'mail-abbrevs-setup)
6271 (minibuffer-local-map message-minibuffer-local-map))
6272 (read-from-minibuffer prompt initial-contents))
6273 (let ((minibuffer-setup-hook 'mail-abbrev-minibuffer-setup-hook)
6274 (minibuffer-local-map message-minibuffer-local-map))
6275 (read-string prompt initial-contents))))
6277 (defun message-use-alternative-email-as-from ()
6278 (require 'mail-utils)
6279 (let* ((fields '("To" "Cc"))
6282 (mail-strip-quoted-names
6283 (mapconcat 'message-fetch-reply-field fields ","))
6287 (if (string-match message-alternative-emails (car emails))
6288 (setq email (car emails)
6291 (unless (or (not email) (equal email user-mail-address))
6292 (goto-char (point-max))
6293 (insert "From: " email "\n"))))
6295 (defun message-options-get (symbol)
6296 (cdr (assq symbol message-options)))
6298 (defun message-options-set (symbol value)
6299 (let ((the-cons (assq symbol message-options)))
6302 (setcdr the-cons value)
6303 (setq message-options (delq the-cons message-options)))
6305 (push (cons symbol value) message-options))))
6308 (defun message-options-set-recipient ()
6310 (message-narrow-to-headers-or-head)
6311 (message-options-set 'message-sender
6312 (mail-strip-quoted-names
6313 (message-fetch-field "from")))
6314 (message-options-set 'message-recipients
6315 (mail-strip-quoted-names
6316 (let ((to (message-fetch-field "to"))
6317 (cc (message-fetch-field "cc"))
6318 (bcc (message-fetch-field "bcc")))
6321 (if (and to cc) ", ")
6323 (if (and (or to cc) bcc) ", ")
6326 (when (featurep 'xemacs)
6327 (require 'messagexmas)
6328 (message-xmas-redefine))
6332 (run-hooks 'message-load-hook)
6335 ;; coding: iso-8859-1
6338 ;;; message.el ends here