1 ;;; message.el --- composing mail and news messages
3 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
4 ;; 2005, 2006 Free Software Foundation, Inc.
6 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
7 ;; Keywords: mail, news
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
23 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
24 ;; Boston, MA 02110-1301, USA.
28 ;; This mode provides mail-sending facilities from within Emacs. It
29 ;; consists mainly of large chunks of code from the sendmail.el,
30 ;; gnus-msg.el and rnewspost.el files.
36 (defvar gnus-message-group-art)
37 (defvar gnus-list-identifiers)) ; gnus-sum is required where necessary
43 ;; This is apparently necessary even though things are autoloaded.
44 ;; Because we dynamically bind mail-abbrev-mode-regexp, we'd better
45 ;; require mailabbrev here.
46 (if (featurep 'xemacs)
47 (require 'mail-abbrevs)
48 (require 'mailabbrev))
54 (defgroup message '((user-mail-address custom-variable)
55 (user-full-name custom-variable))
56 "Mail and news message composing."
57 :link '(custom-manual "(message)Top")
61 (put 'user-mail-address 'custom-type 'string)
62 (put 'user-full-name 'custom-type 'string)
64 (defgroup message-various nil
65 "Various Message Variables."
66 :link '(custom-manual "(message)Various Message Variables")
69 (defgroup message-buffers nil
71 :link '(custom-manual "(message)Message Buffers")
74 (defgroup message-sending nil
76 :link '(custom-manual "(message)Sending Variables")
79 (defgroup message-interface nil
81 :link '(custom-manual "(message)Interface")
84 (defgroup message-forwarding nil
86 :link '(custom-manual "(message)Forwarding")
87 :group 'message-interface)
89 (defgroup message-insertion nil
91 :link '(custom-manual "(message)Insertion")
94 (defgroup message-headers nil
96 :link '(custom-manual "(message)Message Headers")
99 (defgroup message-news nil
100 "Composing News Messages."
103 (defgroup message-mail nil
104 "Composing Mail Messages."
107 (defgroup message-faces nil
108 "Faces used for message composing."
112 (defcustom message-directory "~/Mail/"
113 "*Directory from which all other mail file variables are derived."
114 :group 'message-various
117 (defcustom message-max-buffers 10
118 "*How many buffers to keep before starting to kill them off."
119 :group 'message-buffers
122 (defcustom message-send-rename-function nil
123 "Function called to rename the buffer after sending it."
124 :group 'message-buffers
125 :type '(choice function (const nil)))
127 (defcustom message-fcc-handler-function 'message-output
128 "*A function called to save outgoing articles.
129 This function will be called with the name of the file to store the
130 article in. The default function is `message-output' which saves in Unix
132 :type '(radio (function-item message-output)
133 (function :tag "Other"))
134 :group 'message-sending)
136 (defcustom message-fcc-externalize-attachments nil
137 "If non-nil, attachments are included as external parts in Fcc copies."
140 :group 'message-sending)
142 (defcustom message-courtesy-message
143 "The following message is a courtesy copy of an article\nthat has been posted to %s as well.\n\n"
144 "*This is inserted at the start of a mailed copy of a posted message.
145 If the string contains the format spec \"%s\", the Newsgroups
146 the article has been posted to will be inserted there.
147 If this variable is nil, no such courtesy message will be added."
148 :group 'message-sending
149 :type '(radio string (const nil)))
151 (defcustom message-ignored-bounced-headers
152 "^\\(Received\\|Return-Path\\|Delivered-To\\):"
153 "*Regexp that matches headers to be removed in resent bounced mail."
154 :group 'message-interface
157 (defcustom message-from-style 'default
158 "*Specifies how \"From\" headers look.
160 If nil, they contain just the return address like:
162 If `parens', they look like:
163 king@grassland.com (Elvis Parsley)
164 If `angles', they look like:
165 Elvis Parsley <king@grassland.com>
167 Otherwise, most addresses look like `angles', but they look like
168 `parens' if `angles' would need quoting and `parens' would not."
169 :type '(choice (const :tag "simple" nil)
173 :group 'message-headers)
175 (defcustom message-insert-canlock t
176 "Whether to insert a Cancel-Lock header in news postings."
178 :group 'message-headers
181 (defcustom message-syntax-checks
182 (if message-insert-canlock '((sender . disabled)) nil)
183 ;; Guess this one shouldn't be easy to customize...
184 "*Controls what syntax checks should not be performed on outgoing posts.
185 To disable checking of long signatures, for instance, add
186 `(signature . disabled)' to this list.
188 Don't touch this variable unless you really know what you're doing.
190 Checks include `approved', `continuation-headers', `control-chars',
191 `empty', `existing-newsgroups', `from', `illegible-text',
192 `invisible-text', `long-header-lines', `long-lines', `message-id',
193 `multiple-headers', `new-text', `newsgroups', `quoting-style',
194 `repeated-newsgroups', `reply-to', `sender', `sendsys', `shoot',
195 `shorten-followup-to', `signature', `size', `subject', `subject-cmsg'
196 and `valid-newsgroups'."
198 :type '(repeat sexp)) ; Fixme: improve this
200 (defcustom message-required-headers '((optional . References)
202 "*Headers to be generated or prompted for when sending a message.
203 Also see `message-required-news-headers' and
204 `message-required-mail-headers'."
207 :group 'message-headers
208 :link '(custom-manual "(message)Message Headers")
209 :type '(repeat sexp))
211 (defcustom message-draft-headers '(References From Date)
212 "*Headers to be generated when saving a draft message."
215 :group 'message-headers
216 :link '(custom-manual "(message)Message Headers")
217 :type '(repeat sexp))
219 (defcustom message-required-news-headers
220 '(From Newsgroups Subject Date Message-ID
221 (optional . Organization)
222 (optional . User-Agent))
223 "*Headers to be generated or prompted for when posting an article.
224 RFC977 and RFC1036 require From, Date, Newsgroups, Subject,
225 Message-ID. Organization, Lines, In-Reply-To, Expires, and
226 User-Agent are optional. If don't you want message to insert some
227 header, remove it from this list."
229 :group 'message-headers
230 :link '(custom-manual "(message)Message Headers")
231 :type '(repeat sexp))
233 (defcustom message-required-mail-headers
234 '(From Subject Date (optional . In-Reply-To) Message-ID
235 (optional . User-Agent))
236 "*Headers to be generated or prompted for when mailing a message.
237 It is recommended that From, Date, To, Subject and Message-ID be
238 included. Organization and User-Agent are optional."
240 :group 'message-headers
241 :link '(custom-manual "(message)Message Headers")
242 :type '(repeat sexp))
244 (defcustom message-deletable-headers '(Message-ID Date Lines)
245 "Headers to be deleted if they already exist and were generated by message previously."
246 :group 'message-headers
247 :link '(custom-manual "(message)Message Headers")
250 (defcustom message-ignored-news-headers
251 "^NNTP-Posting-Host:\\|^Xref:\\|^[BGF]cc:\\|^Resent-Fcc:\\|^X-Draft-From:\\|^X-Gnus-Agent-Meta-Information:"
252 "*Regexp of headers to be removed unconditionally before posting."
254 :group 'message-headers
255 :link '(custom-manual "(message)Message Headers")
256 :type '(repeat :value-to-internal (lambda (widget value)
257 (custom-split-regexp-maybe value))
258 :match (lambda (widget value)
260 (widget-editable-list-match widget value)))
263 (defcustom message-ignored-mail-headers
264 "^[GF]cc:\\|^Resent-Fcc:\\|^Xref:\\|^X-Draft-From:\\|^X-Gnus-Agent-Meta-Information:"
265 "*Regexp of headers to be removed unconditionally before mailing."
267 :group 'message-headers
268 :link '(custom-manual "(message)Mail Headers")
271 (defcustom message-ignored-supersedes-headers "^Path:\\|^Date\\|^NNTP-Posting-Host:\\|^Xref:\\|^Lines:\\|^Received:\\|^X-From-Line:\\|^X-Trace:\\|^X-Complaints-To:\\|Return-Path:\\|^Supersedes:\\|^NNTP-Posting-Date:\\|^X-Trace:\\|^X-Complaints-To:\\|^Cancel-Lock:\\|^Cancel-Key:\\|^X-Hashcash:\\|^X-Payment:\\|^Approved:"
272 "*Header lines matching this regexp will be deleted before posting.
273 It's best to delete old Path and Date headers before posting to avoid
275 :group 'message-interface
276 :link '(custom-manual "(message)Superseding")
277 :type '(repeat :value-to-internal (lambda (widget value)
278 (custom-split-regexp-maybe value))
279 :match (lambda (widget value)
281 (widget-editable-list-match widget value)))
284 (defcustom message-subject-re-regexp
285 "^[ \t]*\\([Rr][Ee]\\(\\[[0-9]*\\]\\)*:[ \t]*\\)*[ \t]*"
286 "*Regexp matching \"Re: \" in the subject line."
287 :group 'message-various
288 :link '(custom-manual "(message)Message Headers")
291 ;;; Start of variables adopted from `message-utils.el'.
293 (defcustom message-subject-trailing-was-query 'ask
294 "*What to do with trailing \"(was: <old subject>)\" in subject lines.
295 If nil, leave the subject unchanged. If it is the symbol `ask', query
296 the user what do do. In this case, the subject is matched against
297 `message-subject-trailing-was-ask-regexp'. If
298 `message-subject-trailing-was-query' is t, always strip the trailing
299 old subject. In this case, `message-subject-trailing-was-regexp' is
302 :type '(choice (const :tag "never" nil)
303 (const :tag "always strip" t)
305 :link '(custom-manual "(message)Message Headers")
306 :group 'message-various)
308 (defcustom message-subject-trailing-was-ask-regexp
309 "[ \t]*\\([[(]+[Ww][Aa][Ss][ \t]*.*[\])]+\\)"
310 "*Regexp matching \"(was: <old subject>)\" in the subject line.
312 The function `message-strip-subject-trailing-was' uses this regexp if
313 `message-subject-trailing-was-query' is set to the symbol `ask'. If
314 the variable is t instead of `ask', use
315 `message-subject-trailing-was-regexp' instead.
317 It is okay to create some false positives here, as the user is asked."
319 :group 'message-various
320 :link '(custom-manual "(message)Message Headers")
323 (defcustom message-subject-trailing-was-regexp
324 "[ \t]*\\((*[Ww][Aa][Ss]:[ \t]*.*)\\)"
325 "*Regexp matching \"(was: <old subject>)\" in the subject line.
327 If `message-subject-trailing-was-query' is set to t, the subject is
328 matched against `message-subject-trailing-was-regexp' in
329 `message-strip-subject-trailing-was'. You should use a regexp creating very
330 few false positives here."
332 :group 'message-various
333 :link '(custom-manual "(message)Message Headers")
336 ;;; marking inserted text
338 (defcustom message-mark-insert-begin
339 "--8<---------------cut here---------------start------------->8---\n"
340 "How to mark the beginning of some inserted text."
343 :link '(custom-manual "(message)Insertion Variables")
344 :group 'message-various)
346 (defcustom message-mark-insert-end
347 "--8<---------------cut here---------------end--------------->8---\n"
348 "How to mark the end of some inserted text."
351 :link '(custom-manual "(message)Insertion Variables")
352 :group 'message-various)
354 (defcustom message-archive-header "X-No-Archive: Yes\n"
355 "Header to insert when you don't want your article to be archived.
356 Archives \(such as groups.google.com\) respect this header."
359 :link '(custom-manual "(message)Header Commands")
360 :group 'message-various)
362 (defcustom message-archive-note
363 "X-No-Archive: Yes - save http://groups.google.com/"
364 "Note to insert why you wouldn't want this posting archived.
365 If nil, don't insert any text in the body."
367 :type '(radio string (const nil))
368 :link '(custom-manual "(message)Header Commands")
369 :group 'message-various)
371 ;;; Crossposts and Followups
372 ;; inspired by JoH-followup-to by Jochem Huhman <joh at gmx.de>
373 ;; new suggestions by R. Weikusat <rw at another.de>
375 (defvar message-cross-post-old-target nil
376 "Old target for cross-posts or follow-ups.")
377 (make-variable-buffer-local 'message-cross-post-old-target)
379 (defcustom message-cross-post-default t
380 "When non-nil `message-cross-post-followup-to' will perform a crosspost.
381 If nil, `message-cross-post-followup-to' will only do a followup. Note that
382 you can explicitly override this setting by calling
383 `message-cross-post-followup-to' with a prefix."
386 :group 'message-various)
388 (defcustom message-cross-post-note "Crosspost & Followup-To: "
389 "Note to insert before signature to notify of cross-post and follow-up."
392 :group 'message-various)
394 (defcustom message-followup-to-note "Followup-To: "
395 "Note to insert before signature to notify of follow-up only."
398 :group 'message-various)
400 (defcustom message-cross-post-note-function 'message-cross-post-insert-note
401 "Function to use to insert note about Crosspost or Followup-To.
402 The function will be called with four arguments. The function should not only
403 insert a note, but also ensure old notes are deleted. See the documentation
404 for `message-cross-post-insert-note'."
407 :group 'message-various)
409 ;;; End of variables adopted from `message-utils.el'.
411 (defcustom message-signature-separator "^-- *$"
412 "Regexp matching the signature separator."
414 :link '(custom-manual "(message)Various Message Variables")
415 :group 'message-various)
417 (defcustom message-elide-ellipsis "\n[...]\n\n"
418 "*The string which is inserted for elided text."
420 :link '(custom-manual "(message)Various Commands")
421 :group 'message-various)
423 (defcustom message-interactive t
424 "Non-nil means when sending a message wait for and display errors.
425 nil means let mailer mail back a message to report errors."
426 :group 'message-sending
428 :link '(custom-manual "(message)Sending Variables")
431 (defcustom message-generate-new-buffers 'unique
432 "*Non-nil means create a new message buffer whenever `message-setup' is called.
433 If this is a function, call that function with three parameters: The type,
434 the to address and the group name. (Any of these may be nil.) The function
435 should return the new buffer name."
436 :group 'message-buffers
437 :link '(custom-manual "(message)Message Buffers")
438 :type '(choice (const :tag "off" nil)
439 (const :tag "unique" unique)
440 (const :tag "unsent" unsent)
443 (defcustom message-kill-buffer-on-exit nil
444 "*Non-nil means that the message buffer will be killed after sending a message."
445 :group 'message-buffers
446 :link '(custom-manual "(message)Message Buffers")
449 (defcustom message-kill-buffer-query t
450 "*Non-nil means that killing a modified message buffer has to be confirmed.
451 This is used by `message-kill-buffer'."
452 :version "23.0" ;; No Gnus
453 :group 'message-buffers
457 (defvar gnus-local-organization))
458 (defcustom message-user-organization
459 (or (and (boundp 'gnus-local-organization)
460 (stringp gnus-local-organization)
461 gnus-local-organization)
462 (getenv "ORGANIZATION")
464 "*String to be used as an Organization header.
465 If t, use `message-user-organization-file'."
466 :group 'message-headers
467 :type '(choice string
468 (const :tag "consult file" t)))
470 (defcustom message-user-organization-file
472 (dolist (f (list "/etc/organization"
473 "/etc/news/organization"
474 "/usr/lib/news/organization"))
475 (when (file-readable-p f)
478 "*Local news organization file."
480 :link '(custom-manual "(message)News Headers")
481 :group 'message-headers)
483 (defcustom message-make-forward-subject-function
484 #'message-forward-subject-name-subject
485 "*List of functions called to generate subject headers for forwarded messages.
486 The subject generated by the previous function is passed into each
489 The provided functions are:
491 * `message-forward-subject-author-subject' Source of article (author or
492 newsgroup), in brackets followed by the subject
493 * `message-forward-subject-name-subject' Source of article (name of author
494 or newsgroup), in brackets followed by the subject
495 * `message-forward-subject-fwd' Subject of article with 'Fwd:' prepended
497 :group 'message-forwarding
498 :link '(custom-manual "(message)Forwarding")
499 :type '(radio (function-item message-forward-subject-author-subject)
500 (function-item message-forward-subject-fwd)
501 (function-item message-forward-subject-name-subject)
502 (repeat :tag "List of functions" function)))
504 (defcustom message-forward-as-mime t
505 "*Non-nil means forward messages as an inline/rfc822 MIME section.
506 Otherwise, directly inline the old message in the forwarded message."
508 :group 'message-forwarding
509 :link '(custom-manual "(message)Forwarding")
512 (defcustom message-forward-show-mml 'best
513 "*Non-nil means show forwarded messages as MML (decoded from MIME).
514 Otherwise, forwarded messages are unchanged.
515 Can also be the symbol `best' to indicate that MML should be
516 used, except when it is a bad idea to use MML. One example where
517 it is a bad idea is when forwarding a signed or encrypted
518 message, because converting MIME to MML would invalidate the
521 :group 'message-forwarding
522 :type '(choice (const :tag "use MML" t)
523 (const :tag "don't use MML " nil)
524 (const :tag "use MML when appropriate" best)))
526 (defcustom message-forward-before-signature t
527 "*Non-nil means put forwarded message before signature, else after."
528 :group 'message-forwarding
531 (defcustom message-wash-forwarded-subjects nil
532 "*Non-nil means try to remove as much cruft as possible from the subject.
533 Done before generating the new subject of a forward."
534 :group 'message-forwarding
535 :link '(custom-manual "(message)Forwarding")
538 (defcustom message-ignored-resent-headers "^Return-receipt\\|^X-Gnus\\|^Gnus-Warning:\\|^>?From "
539 "*All headers that match this regexp will be deleted when resending a message."
540 :group 'message-interface
541 :link '(custom-manual "(message)Resending")
542 :type '(repeat :value-to-internal (lambda (widget value)
543 (custom-split-regexp-maybe value))
544 :match (lambda (widget value)
546 (widget-editable-list-match widget value)))
549 (defcustom message-forward-ignored-headers "^Content-Transfer-Encoding:\\|^X-Gnus"
550 "*All headers that match this regexp will be deleted when forwarding a message."
552 :group 'message-forwarding
553 :type '(repeat :value-to-internal (lambda (widget value)
554 (custom-split-regexp-maybe value))
555 :match (lambda (widget value)
557 (widget-editable-list-match widget value)))
560 (defcustom message-ignored-cited-headers "."
561 "*Delete these headers from the messages you yank."
562 :group 'message-insertion
563 :link '(custom-manual "(message)Insertion Variables")
566 (defcustom message-cite-prefix-regexp
567 (if (string-match "[[:digit:]]" "1") ;; support POSIX?
568 "\\([ \t]*[-_.[:word:]]+>+\\|[ \t]*[]>|}+]\\)+"
569 ;; ?-, ?_ or ?. MUST NOT be in syntax entry w.
570 (let (non-word-constituents)
571 (with-syntax-table text-mode-syntax-table
572 (setq non-word-constituents
574 (if (string-match "\\w" "-") "" "-")
575 (if (string-match "\\w" "_") "" "_")
576 (if (string-match "\\w" ".") "" "."))))
577 (if (equal non-word-constituents "")
578 "\\([ \t]*\\(\\w\\)+>+\\|[ \t]*[]>|}+]\\)+"
579 (concat "\\([ \t]*\\(\\w\\|["
580 non-word-constituents
581 "]\\)+>+\\|[ \t]*[]>|}+]\\)+"))))
582 "*Regexp matching the longest possible citation prefix on a line."
584 :group 'message-insertion
585 :link '(custom-manual "(message)Insertion Variables")
588 (defcustom message-cancel-message "I am canceling my own article.\n"
589 "Message to be inserted in the cancel message."
590 :group 'message-interface
591 :link '(custom-manual "(message)Canceling News")
594 ;; Useful to set in site-init.el
595 (defcustom message-send-mail-function
596 (let ((program (if (boundp 'sendmail-program)
601 (string-match "/" program) ;; Skip path
602 (file-executable-p program))
603 'message-send-mail-with-sendmail)
605 (executable-find program))
606 'message-send-mail-with-sendmail)
609 "Function to call to send the current buffer as mail.
610 The headers should be delimited by a line whose contents match the
611 variable `mail-header-separator'.
613 Valid values include `message-send-mail-with-sendmail' (the default),
614 `message-send-mail-with-mh', `message-send-mail-with-qmail',
615 `message-smtpmail-send-it', `smtpmail-send-it' and `feedmail-send-it'.
617 See also `send-mail-function'."
618 :type '(radio (function-item message-send-mail-with-sendmail)
619 (function-item message-send-mail-with-mh)
620 (function-item message-send-mail-with-qmail)
621 (function-item message-smtpmail-send-it)
622 (function-item smtpmail-send-it)
623 (function-item feedmail-send-it)
624 (function :tag "Other"))
625 :group 'message-sending
626 :link '(custom-manual "(message)Mail Variables")
627 :group 'message-mail)
629 (defcustom message-send-news-function 'message-send-news
630 "Function to call to send the current buffer as news.
631 The headers should be delimited by a line whose contents match the
632 variable `mail-header-separator'."
633 :group 'message-sending
635 :link '(custom-manual "(message)News Variables")
638 (defcustom message-reply-to-function nil
639 "If non-nil, function that should return a list of headers.
640 This function should pick out addresses from the To, Cc, and From headers
641 and respond with new To and Cc headers."
642 :group 'message-interface
643 :link '(custom-manual "(message)Reply")
644 :type '(choice function (const nil)))
646 (defcustom message-wide-reply-to-function nil
647 "If non-nil, function that should return a list of headers.
648 This function should pick out addresses from the To, Cc, and From headers
649 and respond with new To and Cc headers."
650 :group 'message-interface
651 :link '(custom-manual "(message)Wide Reply")
652 :type '(choice function (const nil)))
654 (defcustom message-followup-to-function nil
655 "If non-nil, function that should return a list of headers.
656 This function should pick out addresses from the To, Cc, and From headers
657 and respond with new To and Cc headers."
658 :group 'message-interface
659 :link '(custom-manual "(message)Followup")
660 :type '(choice function (const nil)))
662 (defcustom message-extra-wide-headers nil
663 "If non-nil, a list of additional address headers.
664 These are used when composing a wide reply."
665 :group 'message-sending
666 :type '(repeat string))
668 (defcustom message-use-followup-to 'ask
669 "*Specifies what to do with Followup-To header.
670 If nil, always ignore the header. If it is t, use its value, but
671 query before using the \"poster\" value. If it is the symbol `ask',
672 always query the user whether to use the value. If it is the symbol
673 `use', always use the value."
674 :group 'message-interface
675 :link '(custom-manual "(message)Followup")
676 :type '(choice (const :tag "ignore" nil)
677 (const :tag "use & query" t)
681 (defcustom message-use-mail-followup-to 'use
682 "*Specifies what to do with Mail-Followup-To header.
683 If nil, always ignore the header. If it is the symbol `ask', always
684 query the user whether to use the value. If it is the symbol `use',
685 always use the value."
687 :group 'message-interface
688 :link '(custom-manual "(message)Mailing Lists")
689 :type '(choice (const :tag "ignore" nil)
693 (defcustom message-subscribed-address-functions nil
694 "*Specifies functions for determining list subscription.
695 If nil, do not attempt to determine list subscription with functions.
696 If non-nil, this variable contains a list of functions which return
697 regular expressions to match lists. These functions can be used in
698 conjunction with `message-subscribed-regexps' and
699 `message-subscribed-addresses'."
701 :group 'message-interface
702 :link '(custom-manual "(message)Mailing Lists")
703 :type '(repeat sexp))
705 (defcustom message-subscribed-address-file nil
706 "*A file containing addresses the user is subscribed to.
707 If nil, do not look at any files to determine list subscriptions. If
708 non-nil, each line of this file should be a mailing list address."
710 :group 'message-interface
711 :link '(custom-manual "(message)Mailing Lists")
712 :type '(radio file (const nil)))
714 (defcustom message-subscribed-addresses nil
715 "*Specifies a list of addresses the user is subscribed to.
716 If nil, do not use any predefined list subscriptions. This list of
717 addresses can be used in conjunction with
718 `message-subscribed-address-functions' and `message-subscribed-regexps'."
720 :group 'message-interface
721 :link '(custom-manual "(message)Mailing Lists")
722 :type '(repeat string))
724 (defcustom message-subscribed-regexps nil
725 "*Specifies a list of addresses the user is subscribed to.
726 If nil, do not use any predefined list subscriptions. This list of
727 regular expressions can be used in conjunction with
728 `message-subscribed-address-functions' and `message-subscribed-addresses'."
730 :group 'message-interface
731 :link '(custom-manual "(message)Mailing Lists")
732 :type '(repeat regexp))
734 (defcustom message-allow-no-recipients 'ask
735 "Specifies what to do when there are no recipients other than Gcc/Fcc.
736 If it is the symbol `always', the posting is allowed. If it is the
737 symbol `never', the posting is not allowed. If it is the symbol
738 `ask', you are prompted."
740 :group 'message-interface
741 :link '(custom-manual "(message)Message Headers")
742 :type '(choice (const always)
746 (defcustom message-sendmail-f-is-evil nil
747 "*Non-nil means don't add \"-f username\" to the sendmail command line.
748 Doing so would be even more evil than leaving it out."
749 :group 'message-sending
750 :link '(custom-manual "(message)Mail Variables")
753 (defcustom message-sendmail-envelope-from nil
754 "*Envelope-from when sending mail with sendmail.
755 If this is nil, use `user-mail-address'. If it is the symbol
756 `header', use the From: header of the message."
758 :type '(choice (string :tag "From name")
759 (const :tag "Use From: header from message" header)
760 (const :tag "Use `user-mail-address'" nil))
761 :link '(custom-manual "(message)Mail Variables")
762 :group 'message-sending)
764 ;; qmail-related stuff
765 (defcustom message-qmail-inject-program "/var/qmail/bin/qmail-inject"
766 "Location of the qmail-inject program."
767 :group 'message-sending
768 :link '(custom-manual "(message)Mail Variables")
771 (defcustom message-qmail-inject-args nil
772 "Arguments passed to qmail-inject programs.
773 This should be a list of strings, one string for each argument. It
774 may also be a function.
776 For e.g., if you wish to set the envelope sender address so that bounces
777 go to the right place or to deal with listserv's usage of that address, you
778 might set this variable to '(\"-f\" \"you@some.where\")."
779 :group 'message-sending
780 :link '(custom-manual "(message)Mail Variables")
781 :type '(choice (function)
785 (defvar gnus-post-method)
786 (defvar gnus-select-method))
787 (defcustom message-post-method
788 (cond ((and (boundp 'gnus-post-method)
789 (listp gnus-post-method)
792 ((boundp 'gnus-select-method)
795 "*Method used to post news.
796 Note that when posting from inside Gnus, for instance, this
797 variable isn't used."
799 :group 'message-sending
800 ;; This should be the `gnus-select-method' widget, but that might
801 ;; create a dependence to `gnus.el'.
804 ;; FIXME: This should be a temporary workaround until someone implements a
805 ;; proper solution. If a crash happens while replying, the auto-save file
806 ;; will *not* have a `References:' header if `message-generate-headers-first'
807 ;; is nil. See: http://article.gmane.org/gmane.emacs.gnus.general/51138
808 (defcustom message-generate-headers-first '(references)
809 "Which headers should be generated before starting to compose a message.
810 If t, generate all required headers. This can also be a list of headers to
811 generate. The variables `message-required-news-headers' and
812 `message-required-mail-headers' specify which headers to generate.
814 Note that the variable `message-deletable-headers' specifies headers which
815 are to be deleted and then re-generated before sending, so this variable
816 will not have a visible effect for those headers."
817 :group 'message-headers
818 :link '(custom-manual "(message)Message Headers")
819 :type '(choice (const :tag "None" nil)
820 (const :tag "References" '(references))
822 (repeat (sexp :tag "Header"))))
824 (defcustom message-setup-hook nil
825 "Normal hook, run each time a new outgoing message is initialized.
826 The function `message-setup' runs this hook."
827 :group 'message-various
828 :link '(custom-manual "(message)Various Message Variables")
831 (defcustom message-cancel-hook nil
832 "Hook run when cancelling articles."
833 :group 'message-various
834 :link '(custom-manual "(message)Various Message Variables")
837 (defcustom message-signature-setup-hook nil
838 "Normal hook, run each time a new outgoing message is initialized.
839 It is run after the headers have been inserted and before
840 the signature is inserted."
841 :group 'message-various
842 :link '(custom-manual "(message)Various Message Variables")
845 (defcustom message-mode-hook nil
846 "Hook run in message mode buffers."
847 :group 'message-various
850 (defcustom message-header-hook nil
851 "Hook run in a message mode buffer narrowed to the headers."
852 :group 'message-various
855 (defcustom message-header-setup-hook nil
856 "Hook called narrowed to the headers when setting up a message buffer."
857 :group 'message-various
858 :link '(custom-manual "(message)Various Message Variables")
861 (defcustom message-minibuffer-local-map
862 (let ((map (make-sparse-keymap 'message-minibuffer-local-map)))
863 (set-keymap-parent map minibuffer-local-map)
865 "Keymap for `message-read-from-minibuffer'."
867 :group 'message-various)
869 (defcustom message-citation-line-function 'message-insert-citation-line
870 "*Function called to insert the \"Whomever writes:\" line.
872 Predefined functions include `message-insert-citation-line' and
873 `message-insert-formated-citation-line' (see the variable
874 `message-citation-line-format').
876 Note that Gnus provides a feature where the reader can click on
877 `writes:' to hide the cited text. If you change this line too much,
878 people who read your message will have to change their Gnus
879 configuration. See the variable `gnus-cite-attribution-suffix'."
881 (function-item :tag "plain" message-insert-citation-line)
882 (function-item :tag "formatted" message-insert-formated-citation-line)
883 (function :tag "Other"))
884 :link '(custom-manual "(message)Insertion Variables")
885 :group 'message-insertion)
887 (defcustom message-citation-line-format "On %a, %b %d %Y, %N wrote:"
888 "Format of the \"Whomever writes:\" line.
890 The string is formatted using `format-spec'. The following
891 constructs are replaced:
893 %f The full From, e.g. \"John Doe <john.doe@example.invalid>\".
894 %n The mail address, e.g. \"john.doe@example.invalid\".
895 %N The real name if present, e.g.: \"John Doe\", else fall
896 back to the mail address.
897 %F The first name if present, e.g.: \"John\".
898 %L The last name if present, e.g.: \"Doe\".
900 All other format specifiers are passed to `format-time-string'
901 which is called using the date from the article your replying to.
902 Extracting the first (%F) and last name (%L) is done
903 heuristically, so you should always check it yourself.
905 Please also read the note in the documentation of
906 `message-citation-line-function'."
907 :type '(choice (const :tag "Plain" "%f writes:")
908 (const :tag "Include date" "On %a, %b %d %Y, %n wrote:")
910 :link '(custom-manual "(message)Insertion Variables")
911 :version "23.0" ;; No Gnus
912 :group 'message-insertion)
914 (defcustom message-yank-prefix "> "
915 "*Prefix inserted on the lines of yanked messages.
916 Fix `message-cite-prefix-regexp' if it is set to an abnormal value.
917 See also `message-yank-cited-prefix' and `message-yank-empty-prefix'."
919 :link '(custom-manual "(message)Insertion Variables")
920 :group 'message-insertion)
922 (defcustom message-yank-cited-prefix ">"
923 "*Prefix inserted on cited lines of yanked messages.
924 Fix `message-cite-prefix-regexp' if it is set to an abnormal value.
925 See also `message-yank-prefix' and `message-yank-empty-prefix'."
928 :link '(custom-manual "(message)Insertion Variables")
929 :group 'message-insertion)
931 (defcustom message-yank-empty-prefix ">"
932 "*Prefix inserted on empty lines of yanked messages.
933 See also `message-yank-prefix' and `message-yank-cited-prefix'."
936 :link '(custom-manual "(message)Insertion Variables")
937 :group 'message-insertion)
939 (defcustom message-indentation-spaces 3
940 "*Number of spaces to insert at the beginning of each cited line.
941 Used by `message-yank-original' via `message-yank-cite'."
942 :group 'message-insertion
943 :link '(custom-manual "(message)Insertion Variables")
946 (defcustom message-cite-function 'message-cite-original
947 "*Function for citing an original message.
948 Predefined functions include `message-cite-original' and
949 `message-cite-original-without-signature'.
950 Note that these functions use `mail-citation-hook' if that is non-nil."
951 :type '(radio (function-item message-cite-original)
952 (function-item message-cite-original-without-signature)
953 (function-item sc-cite-original)
954 (function :tag "Other"))
955 :link '(custom-manual "(message)Insertion Variables")
956 :group 'message-insertion)
958 (defcustom message-indent-citation-function 'message-indent-citation
959 "*Function for modifying a citation just inserted in the mail buffer.
960 This can also be a list of functions. Each function can find the
961 citation between (point) and (mark t). And each function should leave
962 point and mark around the citation text as modified."
964 :link '(custom-manual "(message)Insertion Variables")
965 :group 'message-insertion)
967 (defcustom message-signature t
968 "*String to be inserted at the end of the message buffer.
969 If t, the `message-signature-file' file will be inserted instead.
970 If a function, the result from the function will be used instead.
971 If a form, the result from the form will be used instead."
973 :link '(custom-manual "(message)Insertion Variables")
974 :group 'message-insertion)
976 (defcustom message-signature-file "~/.signature"
977 "*Name of file containing the text inserted at end of message buffer.
978 Ignored if the named file doesn't exist.
979 If nil, don't insert a signature."
980 :type '(choice file (const :tags "None" nil))
981 :link '(custom-manual "(message)Insertion Variables")
982 :group 'message-insertion)
984 (defcustom message-signature-insert-empty-line t
985 "*If non-nil, insert an empty line before the signature separator."
988 :link '(custom-manual "(message)Insertion Variables")
989 :group 'message-insertion)
991 (defcustom message-distribution-function nil
992 "*Function called to return a Distribution header."
994 :group 'message-headers
995 :link '(custom-manual "(message)News Headers")
996 :type '(choice function (const nil)))
998 (defcustom message-expires 14
999 "Number of days before your article expires."
1000 :group 'message-news
1001 :group 'message-headers
1002 :link '(custom-manual "(message)News Headers")
1005 (defcustom message-user-path nil
1006 "If nil, use the NNTP server name in the Path header.
1007 If stringp, use this; if non-nil, use no host name (user name only)."
1008 :group 'message-news
1009 :group 'message-headers
1010 :link '(custom-manual "(message)News Headers")
1011 :type '(choice (const :tag "nntp" nil)
1012 (string :tag "name")
1013 (sexp :tag "none" :format "%t" t)))
1015 (defvar message-reply-buffer nil)
1016 (defvar message-reply-headers nil
1017 "The headers of the current replied article.
1018 It is a vector of the following headers:
1019 \[number subject from date id references chars lines xref extra].")
1020 (defvar message-newsreader nil)
1021 (defvar message-mailer nil)
1022 (defvar message-sent-message-via nil)
1023 (defvar message-checksum nil)
1024 (defvar message-send-actions nil
1025 "A list of actions to be performed upon successful sending of a message.")
1026 (defvar message-exit-actions nil
1027 "A list of actions to be performed upon exiting after sending a message.")
1028 (defvar message-kill-actions nil
1029 "A list of actions to be performed before killing a message buffer.")
1030 (defvar message-postpone-actions nil
1031 "A list of actions to be performed after postponing a message.")
1033 (define-widget 'message-header-lines 'text
1034 "All header lines must be LFD terminated."
1035 :format "%{%t%}:%n%v"
1036 :valid-regexp "^\\'"
1037 :error "All header lines must be newline terminated")
1039 (defcustom message-default-headers ""
1040 "*A string containing header lines to be inserted in outgoing messages.
1041 It is inserted before you edit the message, so you can edit or delete
1043 :group 'message-headers
1044 :link '(custom-manual "(message)Message Headers")
1045 :type 'message-header-lines)
1047 (defcustom message-default-mail-headers ""
1048 "*A string of header lines to be inserted in outgoing mails."
1049 :group 'message-headers
1050 :group 'message-mail
1051 :link '(custom-manual "(message)Mail Headers")
1052 :type 'message-header-lines)
1054 (defcustom message-default-news-headers ""
1055 "*A string of header lines to be inserted in outgoing news articles."
1056 :group 'message-headers
1057 :group 'message-news
1058 :link '(custom-manual "(message)News Headers")
1059 :type 'message-header-lines)
1061 ;; Note: could use /usr/ucb/mail instead of sendmail;
1062 ;; options -t, and -v if not interactive.
1063 (defcustom message-mailer-swallows-blank-line
1064 (if (and (string-match "sparc-sun-sunos\\(\\'\\|[^5]\\)"
1065 system-configuration)
1066 (file-readable-p "/etc/sendmail.cf")
1067 (let ((buffer (get-buffer-create " *temp*")))
1071 (insert-file-contents "/etc/sendmail.cf")
1072 (goto-char (point-min))
1073 (let ((case-fold-search nil))
1074 (re-search-forward "^OR\\>" nil t)))
1075 (kill-buffer buffer))))
1076 ;; According to RFC822, "The field-name must be composed of printable
1077 ;; ASCII characters (i. e., characters that have decimal values between
1078 ;; 33 and 126, except colon)", i. e., any chars except ctl chars,
1080 '(looking-at "[ \t]\\|[][!\"#$%&'()*+,-./0-9;<=>?@A-Z\\\\^_`a-z{|}~]+:"))
1081 "*Set this non-nil if the system's mailer runs the header and body together.
1082 \(This problem exists on Sunos 4 when sendmail is run in remote mode.)
1083 The value should be an expression to test whether the problem will
1085 :group 'message-sending
1086 :link '(custom-manual "(message)Mail Variables")
1090 (define-mail-user-agent 'message-user-agent
1091 'message-mail 'message-send-and-exit
1092 'message-kill-buffer 'message-send-hook)
1094 (defvar message-mh-deletable-headers '(Message-ID Date Lines Sender)
1095 "If non-nil, delete the deletable headers before feeding to mh.")
1097 (defvar message-send-method-alist
1098 '((news message-news-p message-send-via-news)
1099 (mail message-mail-p message-send-via-mail))
1100 "Alist of ways to send outgoing messages.
1101 Each element has the form
1103 \(TYPE PREDICATE FUNCTION)
1105 where TYPE is a symbol that names the method; PREDICATE is a function
1106 called without any parameters to determine whether the message is
1107 a message of type TYPE; and FUNCTION is a function to be called if
1108 PREDICATE returns non-nil. FUNCTION is called with one parameter --
1111 (defcustom message-mail-alias-type 'abbrev
1112 "*What alias expansion type to use in Message buffers.
1113 The default is `abbrev', which uses mailabbrev. `ecomplete' uses
1114 an electric completion mode. nil switches mail aliases off.
1115 This can also be a list of values."
1117 :link '(custom-manual "(message)Mail Aliases")
1118 :type '(choice (const :tag "Use Mailabbrev" abbrev)
1119 (const :tag "Use ecomplete" ecomplete)
1120 (const :tag "No expansion" nil)))
1122 (defcustom message-self-insert-commands '(self-insert-command)
1123 "List of `self-insert-command's used to trigger ecomplete.
1124 When one of those commands is invoked to enter a character in To or Cc
1125 header, ecomplete will suggest the candidates of recipients (see also
1126 `message-mail-alias-type'). If you use some tool to enter non-ASCII
1127 text and it replaces `self-insert-command' with the other command, e.g.
1128 `egg-self-insert-command', you may want to add it to this list."
1129 :group 'message-various
1130 :type '(repeat function))
1132 (defcustom message-auto-save-directory
1133 (file-name-as-directory (nnheader-concat message-directory "drafts"))
1134 "*Directory where Message auto-saves buffers if Gnus isn't running.
1135 If nil, Message won't auto-save."
1136 :group 'message-buffers
1137 :link '(custom-manual "(message)Various Message Variables")
1138 :type '(choice directory (const :tag "Don't auto-save" nil)))
1140 (defcustom message-default-charset
1141 (and (not (mm-multibyte-p)) 'iso-8859-1)
1142 "Default charset used in non-MULE Emacsen.
1143 If nil, you might be asked to input the charset."
1146 :link '(custom-manual "(message)Various Message Variables")
1149 (defcustom message-dont-reply-to-names
1150 (and (boundp 'rmail-dont-reply-to-names) rmail-dont-reply-to-names)
1151 "*Addresses to prune when doing wide replies.
1152 This can be a regexp or a list of regexps. Also, a value of nil means
1153 exclude your own user name only."
1156 :link '(custom-manual "(message)Wide Reply")
1157 :type '(choice (const :tag "Yourself" nil)
1159 (repeat :tag "Regexp List" regexp)))
1161 ;; #### FIXME: this might become a generally usefull function at some point
1163 (defsubst message-dont-reply-to-names ()
1164 "Potentially convert a list of regexps into a single one."
1165 (cond ((null message-dont-reply-to-names)
1167 ((stringp message-dont-reply-to-names)
1168 message-dont-reply-to-names)
1169 ((listp message-dont-reply-to-names)
1170 (mapconcat (lambda (elt) (concat "\\(" elt "\\)"))
1171 message-dont-reply-to-names
1174 (defvar message-shoot-gnksa-feet nil
1175 "*A list of GNKSA feet you are allowed to shoot.
1176 Gnus gives you all the opportunity you could possibly want for
1177 shooting yourself in the foot. Also, Gnus allows you to shoot the
1178 feet of Good Net-Keeping Seal of Approval. The following are foot
1180 `empty-article' Allow you to post an empty article;
1181 `quoted-text-only' Allow you to post quoted text only;
1182 `multiple-copies' Allow you to post multiple copies;
1183 `cancel-messages' Allow you to cancel or supersede messages from
1184 your other email addresses.")
1186 (defsubst message-gnksa-enable-p (feature)
1187 (or (not (listp message-shoot-gnksa-feet))
1188 (memq feature message-shoot-gnksa-feet)))
1190 (defcustom message-hidden-headers '("^References:" "^Face:" "^X-Face:"
1192 "Regexp of headers to be hidden when composing new messages.
1193 This can also be a list of regexps to match headers. Or a list
1194 starting with `not' and followed by regexps."
1197 :link '(custom-manual "(message)Message Headers")
1199 :format "%{%t%}: %[Value Type%] %v"
1200 (regexp :menu-tag "regexp" :format "regexp\n%t: %v")
1201 (repeat :menu-tag "(regexp ...)" :format "(regexp ...)\n%v%i"
1202 (regexp :format "%t: %v"))
1203 (cons :menu-tag "(not regexp ...)" :format "(not regexp ...)\n%v"
1205 (repeat :format "%v%i"
1206 (regexp :format "%t: %v")))))
1208 (defcustom message-cite-articles-with-x-no-archive t
1209 "If non-nil, cite text from articles that has X-No-Archive set."
1213 ;;; Internal variables.
1214 ;;; Well, not really internal.
1216 (defvar message-mode-syntax-table
1217 (let ((table (copy-syntax-table text-mode-syntax-table)))
1218 (modify-syntax-entry ?% ". " table)
1219 (modify-syntax-entry ?> ". " table)
1220 (modify-syntax-entry ?< ". " table)
1222 "Syntax table used while in Message mode.")
1224 (defface message-header-to
1227 (:foreground "green2" :bold t))
1230 (:foreground "MidnightBlue" :bold t))
1232 (:bold t :italic t)))
1233 "Face used for displaying From headers."
1234 :group 'message-faces)
1235 ;; backward-compatibility alias
1236 (put 'message-header-to-face 'face-alias 'message-header-to)
1238 (defface message-header-cc
1241 (:foreground "green4" :bold t))
1244 (:foreground "MidnightBlue"))
1247 "Face used for displaying Cc headers."
1248 :group 'message-faces)
1249 ;; backward-compatibility alias
1250 (put 'message-header-cc-face 'face-alias 'message-header-cc)
1252 (defface message-header-subject
1255 (:foreground "green3"))
1258 (:foreground "navy blue" :bold t))
1261 "Face used for displaying subject headers."
1262 :group 'message-faces)
1263 ;; backward-compatibility alias
1264 (put 'message-header-subject-face 'face-alias 'message-header-subject)
1266 (defface message-header-newsgroups
1269 (:foreground "yellow" :bold t :italic t))
1272 (:foreground "blue4" :bold t :italic t))
1274 (:bold t :italic t)))
1275 "Face used for displaying newsgroups headers."
1276 :group 'message-faces)
1277 ;; backward-compatibility alias
1278 (put 'message-header-newsgroups-face 'face-alias 'message-header-newsgroups)
1280 (defface message-header-other
1283 (:foreground "#b00000"))
1286 (:foreground "steel blue"))
1288 (:bold t :italic t)))
1289 "Face used for displaying newsgroups headers."
1290 :group 'message-faces)
1291 ;; backward-compatibility alias
1292 (put 'message-header-other-face 'face-alias 'message-header-other)
1294 (defface message-header-name
1297 (:foreground "DarkGreen"))
1300 (:foreground "cornflower blue"))
1303 "Face used for displaying header names."
1304 :group 'message-faces)
1305 ;; backward-compatibility alias
1306 (put 'message-header-name-face 'face-alias 'message-header-name)
1308 (defface message-header-xheader
1311 (:foreground "blue"))
1314 (:foreground "blue"))
1317 "Face used for displaying X-Header headers."
1318 :group 'message-faces)
1319 ;; backward-compatibility alias
1320 (put 'message-header-xheader-face 'face-alias 'message-header-xheader)
1322 (defface message-separator
1325 (:foreground "blue3"))
1328 (:foreground "brown"))
1331 "Face used for displaying the separator."
1332 :group 'message-faces)
1333 ;; backward-compatibility alias
1334 (put 'message-separator-face 'face-alias 'message-separator)
1336 (defface message-cited-text
1339 (:foreground "red"))
1342 (:foreground "red"))
1345 "Face used for displaying cited text names."
1346 :group 'message-faces)
1347 ;; backward-compatibility alias
1348 (put 'message-cited-text-face 'face-alias 'message-cited-text)
1350 (defface message-mml
1353 (:foreground "ForestGreen"))
1356 (:foreground "ForestGreen"))
1359 "Face used for displaying MML."
1360 :group 'message-faces)
1361 ;; backward-compatibility alias
1362 (put 'message-mml-face 'face-alias 'message-mml)
1364 (defun message-font-lock-make-header-matcher (regexp)
1367 (let ((start (point)))
1370 (goto-char (point-min))
1371 (if (re-search-forward
1372 (concat "^" (regexp-quote mail-header-separator) "$")
1374 (setq limit (min limit (match-beginning 0))))
1376 (and (< start limit)
1377 (re-search-forward ,regexp limit t))))))
1378 (if (featurep 'bytecomp)
1382 (defvar message-font-lock-keywords
1383 (let ((content "[ \t]*\\(.+\\(\n[ \t].*\\)*\\)\n?"))
1384 `((,(message-font-lock-make-header-matcher
1385 (concat "^\\([Tt]o:\\)" content))
1386 (1 'message-header-name)
1387 (2 'message-header-to nil t))
1388 (,(message-font-lock-make-header-matcher
1389 (concat "^\\(^[GBF]?[Cc][Cc]:\\|^[Rr]eply-[Tt]o:\\)" content))
1390 (1 'message-header-name)
1391 (2 'message-header-cc nil t))
1392 (,(message-font-lock-make-header-matcher
1393 (concat "^\\([Ss]ubject:\\)" content))
1394 (1 'message-header-name)
1395 (2 'message-header-subject nil t))
1396 (,(message-font-lock-make-header-matcher
1397 (concat "^\\([Nn]ewsgroups:\\|Followup-[Tt]o:\\)" content))
1398 (1 'message-header-name)
1399 (2 'message-header-newsgroups nil t))
1400 (,(message-font-lock-make-header-matcher
1401 (concat "^\\([A-Z][^: \n\t]+:\\)" content))
1402 (1 'message-header-name)
1403 (2 'message-header-other nil t))
1404 (,(message-font-lock-make-header-matcher
1405 (concat "^\\(X-[A-Za-z0-9-]+:\\|In-Reply-To:\\)" content))
1406 (1 'message-header-name)
1407 (2 'message-header-name))
1408 ,@(if (and mail-header-separator
1409 (not (equal mail-header-separator "")))
1410 `((,(concat "^\\(" (regexp-quote mail-header-separator) "\\)$")
1411 1 'message-separator))
1414 (re-search-forward (concat "^\\("
1415 message-cite-prefix-regexp
1418 (0 'message-cited-text))
1419 ("<#/?\\(multipart\\|part\\|external\\|mml\\|secure\\)[^>]*>"
1421 "Additional expressions to highlight in Message mode.")
1424 ;; XEmacs does it like this. For Emacs, we have to set the
1425 ;; `font-lock-defaults' buffer-local variable.
1426 (put 'message-mode 'font-lock-defaults '(message-font-lock-keywords t))
1428 (defvar message-face-alist
1429 '((bold . message-bold-region)
1430 (underline . underline-region)
1431 (default . (lambda (b e)
1432 (message-unbold-region b e)
1433 (ununderline-region b e))))
1434 "Alist of mail and news faces for facemenu.
1435 The cdr of each entry is a function for applying the face to a region.")
1437 (defcustom message-send-hook nil
1438 "Hook run before sending messages.
1439 This hook is run quite early when sending."
1440 :group 'message-various
1441 :options '(ispell-message)
1442 :link '(custom-manual "(message)Various Message Variables")
1445 (defcustom message-send-mail-hook nil
1446 "Hook run before sending mail messages.
1447 This hook is run very late -- just before the message is sent as
1449 :group 'message-various
1450 :link '(custom-manual "(message)Various Message Variables")
1453 (defcustom message-send-news-hook nil
1454 "Hook run before sending news messages.
1455 This hook is run very late -- just before the message is sent as
1457 :group 'message-various
1458 :link '(custom-manual "(message)Various Message Variables")
1461 (defcustom message-sent-hook nil
1462 "Hook run after sending messages."
1463 :group 'message-various
1466 (defvar message-send-coding-system 'binary
1467 "Coding system to encode outgoing mail.")
1469 (defvar message-draft-coding-system
1470 mm-auto-save-coding-system
1471 "*Coding system to compose mail.
1472 If you'd like to make it possible to share draft files between XEmacs
1473 and Emacs, you may use `iso-2022-7bit' for this value at your own risk.
1474 Note that the coding-system `iso-2022-7bit' isn't suitable to all data.")
1476 (defcustom message-send-mail-partially-limit 1000000
1477 "The limitation of messages sent as message/partial.
1478 The lower bound of message size in characters, beyond which the message
1479 should be sent in several parts. If it is nil, the size is unlimited."
1481 :group 'message-buffers
1482 :link '(custom-manual "(message)Mail Variables")
1483 :type '(choice (const :tag "unlimited" nil)
1486 (defcustom message-alternative-emails nil
1487 "*Regexp matching alternative email addresses.
1488 The first address in the To, Cc or From headers of the original
1489 article matching this variable is used as the From field of
1492 This variable has precedence over posting styles and anything that runs
1493 off `message-setup-hook'."
1494 :group 'message-headers
1495 :link '(custom-manual "(message)Message Headers")
1496 :type '(choice (const :tag "Always use primary" nil)
1499 (defcustom message-hierarchical-addresses nil
1500 "A list of hierarchical mail address definitions.
1502 Inside each entry, the first address is the \"top\" address, and
1503 subsequent addresses are subaddresses; this is used to indicate that
1504 mail sent to the first address will automatically be delivered to the
1505 subaddresses. So if the first address appears in the recipient list
1506 for a message, the subaddresses will be removed (if present) before
1507 the mail is sent. All addresses in this structure should be
1510 :group 'message-headers
1511 :type '(repeat (repeat string)))
1513 (defcustom message-mail-user-agent nil
1514 "Like `mail-user-agent'.
1515 Except if it is nil, use Gnus native MUA; if it is t, use
1518 :type '(radio (const :tag "Gnus native"
1521 (const :tag "`mail-user-agent'"
1524 (function-item :tag "Default Emacs mail"
1526 sendmail-user-agent)
1527 (function-item :tag "Emacs interface to MH"
1530 (function :tag "Other"))
1534 (defcustom message-wide-reply-confirm-recipients nil
1535 "Whether to confirm a wide reply to multiple email recipients.
1536 If this variable is nil, don't ask whether to reply to all recipients.
1537 If this variable is non-nil, pose the question \"Reply to all
1538 recipients?\" before a wide reply to multiple recipients. If the user
1539 answers yes, reply to all recipients as usual. If the user answers
1540 no, only reply back to the author."
1542 :group 'message-headers
1543 :link '(custom-manual "(message)Wide Reply")
1546 (defcustom message-user-fqdn nil
1547 "*Domain part of Message-Ids."
1549 :group 'message-headers
1550 :link '(custom-manual "(message)News Headers")
1551 :type '(radio (const :format "%v " nil)
1552 (string :format "FQDN: %v")))
1554 (defcustom message-use-idna (and (condition-case nil (require 'idna)
1556 (mm-coding-system-p 'utf-8)
1557 (executable-find idna-program)
1558 (string= (idna-to-ascii "räksmörgås")
1559 "xn--rksmrgs-5wao1o")
1561 "Whether to encode non-ASCII in domain names into ASCII according to IDNA.
1562 GNU Libidn, and in particular the elisp package \"idna.el\" and
1563 the external program \"idn\", must be installed for this
1564 functionality to work."
1566 :group 'message-headers
1567 :link '(custom-manual "(message)IDNA")
1568 :type '(choice (const :tag "Ask" ask)
1569 (const :tag "Never" nil)
1570 (const :tag "Always" t)))
1572 (defcustom message-generate-hashcash (if (executable-find "hashcash") t)
1573 "*Whether to generate X-Hashcash: headers.
1574 You must have the \"hashcash\" binary installed, see `hashcash-path'."
1575 :group 'message-headers
1576 :link '(custom-manual "(message)Mail Headers")
1579 ;;; Internal variables.
1581 (defvar message-sending-message "Sending...")
1582 (defvar message-buffer-list nil)
1583 (defvar message-this-is-news nil)
1584 (defvar message-this-is-mail nil)
1585 (defvar message-draft-article nil)
1586 (defvar message-mime-part nil)
1587 (defvar message-posting-charset nil)
1588 (defvar message-inserted-headers nil)
1590 ;; Byte-compiler warning
1592 (defvar gnus-active-hashtb)
1593 (defvar gnus-read-active-file))
1595 ;;; Regexp matching the delimiter of messages in UNIX mail format
1596 ;;; (UNIX From lines), minus the initial ^. It should be a copy
1597 ;;; of rmail.el's rmail-unix-mail-delimiter.
1598 (defvar message-unix-mail-delimiter
1599 (let ((time-zone-regexp
1600 (concat "\\([A-Z]?[A-Z]?[A-Z][A-Z]\\( DST\\)?"
1601 "\\|[-+]?[0-9][0-9][0-9][0-9]"
1607 ;; Many things can happen to an RFC 822 mailbox before it is put into
1608 ;; a `From' line. The leading phrase can be stripped, e.g.
1609 ;; `Joe <@w.x:joe@y.z>' -> `<@w.x:joe@y.z>'. The <> can be stripped, e.g.
1610 ;; `<@x.y:joe@y.z>' -> `@x.y:joe@y.z'. Everything starting with a CRLF
1611 ;; can be removed, e.g.
1612 ;; From: joe@y.z (Joe K
1614 ;; can yield `From joe@y.z (Joe K Fri Mar 22 08:11:15 1996', and
1617 ;; can yield `From Joe User Fri Mar 22 08:11:15 1996'.
1618 ;; The mailbox can be removed or be replaced by white space, e.g.
1619 ;; From: "Joe User"{space}{tab}
1621 ;; can yield `From {space}{tab} Fri Mar 22 08:11:15 1996',
1622 ;; where {space} and {tab} represent the Ascii space and tab characters.
1623 ;; We want to match the results of any of these manglings.
1624 ;; The following regexp rejects names whose first characters are
1625 ;; obviously bogus, but after that anything goes.
1626 "\\([^\0-\b\n-\r\^?].*\\)?"
1628 ;; The time the message was sent.
1629 "\\([^\0-\r \^?]+\\) +" ; day of the week
1630 "\\([^\0-\r \^?]+\\) +" ; month
1631 "\\([0-3]?[0-9]\\) +" ; day of month
1632 "\\([0-2][0-9]:[0-5][0-9]\\(:[0-6][0-9]\\)?\\) *" ; time of day
1634 ;; Perhaps a time zone, specified by an abbreviation, or by a
1639 " \\([0-9][0-9]+\\) *"
1641 ;; On some systems the time zone can appear after the year, too.
1645 "\\(remote from .*\\)?"
1648 "Regexp matching the delimiter of messages in UNIX mail format.")
1650 (defvar message-unsent-separator
1651 (concat "^ *---+ +Unsent message follows +---+ *$\\|"
1652 "^ *---+ +Returned message +---+ *$\\|"
1653 "^Start of returned message$\\|"
1654 "^ *---+ +Original message +---+ *$\\|"
1655 "^ *--+ +begin message +--+ *$\\|"
1656 "^ *---+ +Original message follows +---+ *$\\|"
1657 "^ *---+ +Undelivered message follows +---+ *$\\|"
1658 "^|? *---+ +Message text follows: +---+ *|?$")
1659 "A regexp that matches the separator before the text of a failed message.")
1661 (defvar message-field-fillers
1662 '((To message-fill-field-address)
1663 (Cc message-fill-field-address)
1664 (From message-fill-field-address))
1665 "Alist of header names/filler functions.")
1667 (defvar message-header-format-alist
1682 (References . message-shorten-references)
1684 "Alist used for formatting headers.")
1686 (defvar message-options nil
1687 "Some saved answers when sending message.")
1689 (defvar message-send-mail-real-function nil
1690 "Internal send mail function.")
1692 (defvar message-bogus-system-names "^localhost\\."
1693 "The regexp of bogus system names.")
1695 (defcustom message-valid-fqdn-regexp
1696 (concat "[a-z0-9][-.a-z0-9]+\\." ;; [hostname.subdomain.]domain.
1698 "\\([a-z][a-z]\\|" ;; two letter country TDLs
1699 "aero\\|arpa\\|bitnet\\|biz\\|bofh\\|"
1700 "cat\\|com\\|coop\\|edu\\|gov\\|"
1701 "info\\|int\\|jobs\\|"
1702 "mil\\|mobi\\|museum\\|name\\|net\\|"
1703 "org\\|pro\\|travel\\|uucp\\)")
1704 ;; http://en.wikipedia.org/wiki/List_of_Internet_top-level_domains
1705 ;; http://en.wikipedia.org/wiki/GTLD
1706 ;; `in the process of being approved': .asia .post .tel .sex
1707 ;; "dead" nato bitnet uucp
1708 "Regular expression that matches a valid FQDN."
1709 ;; see also: gnus-button-valid-fqdn-regexp
1711 :group 'message-headers
1715 (autoload 'gnus-alive-p "gnus-util")
1716 (autoload 'gnus-delay-article "gnus-delay")
1717 (autoload 'gnus-extract-address-components "gnus-util")
1718 (autoload 'gnus-find-method-for-group "gnus")
1719 (autoload 'gnus-group-decoded-name "gnus-group")
1720 (autoload 'gnus-group-name-charset "gnus-group")
1721 (autoload 'gnus-group-name-decode "gnus-group")
1722 (autoload 'gnus-groups-from-server "gnus")
1723 (autoload 'gnus-make-local-hook "gnus-util")
1724 (autoload 'gnus-open-server "gnus-int")
1725 (autoload 'gnus-output-to-mail "gnus-util")
1726 (autoload 'gnus-output-to-rmail "gnus-util")
1727 (autoload 'gnus-request-post "gnus-int")
1728 (autoload 'gnus-server-string "gnus")
1729 (autoload 'idna-to-ascii "idna")
1730 (autoload 'message-setup-toolbar "messagexmas")
1731 (autoload 'mh-new-draft-name "mh-comp")
1732 (autoload 'mh-send-letter "mh-comp")
1733 (autoload 'nndraft-request-associate-buffer "nndraft")
1734 (autoload 'nndraft-request-expire-articles "nndraft")
1735 (autoload 'nnvirtual-find-group-art "nnvirtual")
1736 (autoload 'rmail-dont-reply-to "mail-utils")
1737 (autoload 'rmail-msg-is-pruned "rmail")
1738 (autoload 'rmail-msg-restore-non-pruned-header "rmail")
1739 (autoload 'rmail-output "rmailout"))
1744 ;;; Utility functions.
1747 (defmacro message-y-or-n-p (question show &rest text)
1748 "Ask QUESTION, displaying remaining args in a temporary buffer if SHOW."
1749 `(message-talkative-question 'y-or-n-p ,question ,show ,@text))
1751 (defmacro message-delete-line (&optional n)
1752 "Delete the current line (and the next N lines)."
1753 `(delete-region (progn (beginning-of-line) (point))
1754 (progn (forward-line ,(or n 1)) (point))))
1756 (defun message-mark-active-p ()
1757 "Non-nil means the mark and region are currently active in this buffer."
1760 (defun message-unquote-tokens (elems)
1761 "Remove double quotes (\") from strings in list ELEMS."
1762 (mapcar (lambda (item)
1763 (while (string-match "^\\(.*\\)\"\\(.*\\)$" item)
1764 (setq item (concat (match-string 1 item)
1765 (match-string 2 item))))
1769 (defun message-tokenize-header (header &optional separator)
1770 "Split HEADER into a list of header elements.
1771 SEPARATOR is a string of characters to be used as separators. \",\"
1772 is used by default."
1775 (let ((regexp (format "[%s]+" (or separator ",")))
1777 beg quoted elems paren)
1779 (mm-enable-multibyte)
1780 (setq beg (point-min))
1782 (goto-char (point-min))
1787 (cond ((and (> (point) beg)
1789 (and (looking-at regexp)
1792 (push (buffer-substring beg (point)) elems)
1793 (setq beg (match-end 0)))
1794 ((eq (char-after) ?\")
1795 (setq quoted (not quoted)))
1796 ((and (eq (char-after) ?\()
1799 ((and (eq (char-after) ?\))
1802 (nreverse elems)))))
1804 (defun message-mail-file-mbox-p (file)
1805 "Say whether FILE looks like a Unix mbox file."
1806 (when (and (file-exists-p file)
1807 (file-readable-p file)
1808 (file-regular-p file))
1810 (nnheader-insert-file-contents file)
1811 (goto-char (point-min))
1812 (looking-at message-unix-mail-delimiter))))
1814 (defun message-fetch-field (header &optional not-all)
1815 "The same as `mail-fetch-field', only remove all newlines.
1816 The buffer is expected to be narrowed to just the header of the message;
1817 see `message-narrow-to-headers-or-head'."
1818 (let* ((inhibit-point-motion-hooks t)
1819 (value (mail-fetch-field header nil (not not-all))))
1821 (while (string-match "\n[\t ]+" value)
1822 (setq value (replace-match " " t t value)))
1825 (defun message-field-value (header &optional not-all)
1826 "The same as `message-fetch-field', only narrow to the headers first."
1829 (message-narrow-to-headers-or-head)
1830 (message-fetch-field header not-all))))
1832 (defun message-narrow-to-field ()
1833 "Narrow the buffer to the header on the current line."
1835 (while (looking-at "[ \t]")
1841 (if (re-search-forward "^[^ \n\t]" nil t)
1844 (goto-char (point-min)))
1846 (defun message-add-header (&rest headers)
1847 "Add the HEADERS to the message header, skipping those already present."
1850 (unless (string-match "^\\([^:]+\\):[ \t]*[^ \t]" (car headers))
1851 (error "Invalid header `%s'" (car headers)))
1852 (setq hclean (match-string 1 (car headers)))
1854 (message-narrow-to-headers)
1855 (unless (re-search-forward (concat "^" (regexp-quote hclean) ":") nil t)
1856 (goto-char (point-max))
1857 (if (string-match "\n$" (car headers))
1858 (insert (car headers))
1859 (insert (car headers) ?\n)))))
1860 (setq headers (cdr headers))))
1862 (defmacro message-with-reply-buffer (&rest forms)
1863 "Evaluate FORMS in the reply buffer, if it exists."
1864 `(when (and message-reply-buffer
1865 (buffer-name message-reply-buffer))
1867 (set-buffer message-reply-buffer)
1870 (put 'message-with-reply-buffer 'lisp-indent-function 0)
1871 (put 'message-with-reply-buffer 'edebug-form-spec '(body))
1873 (defun message-fetch-reply-field (header)
1874 "Fetch field HEADER from the message we're replying to."
1875 (message-with-reply-buffer
1877 (mail-narrow-to-head)
1878 (message-fetch-field header))))
1880 (defun message-strip-list-identifiers (subject)
1881 "Remove list identifiers in `gnus-list-identifiers' from string SUBJECT."
1882 (require 'gnus-sum) ; for gnus-list-identifiers
1883 (let ((regexp (if (stringp gnus-list-identifiers)
1884 gnus-list-identifiers
1885 (mapconcat 'identity gnus-list-identifiers " *\\|"))))
1886 (if (string-match (concat "\\(\\(\\(Re: +\\)?\\(" regexp
1887 " *\\)\\)+\\(Re: +\\)?\\)") subject)
1888 (concat (substring subject 0 (match-beginning 1))
1889 (or (match-string 3 subject)
1890 (match-string 5 subject))
1895 (defun message-strip-subject-re (subject)
1896 "Remove \"Re:\" from subject lines in string SUBJECT."
1897 (if (string-match message-subject-re-regexp subject)
1898 (substring subject (match-end 0))
1901 (defcustom message-replacement-char "."
1902 "Replacement character used instead of unprintable or not decodable chars."
1903 :group 'message-various
1904 :version "22.1" ;; Gnus 5.10.9
1905 :type '(choice string
1909 ;; FIXME: We also should call `message-strip-subject-encoded-words'
1910 ;; when forwarding. Probably in `message-make-forward-subject' and
1911 ;; `message-forward-make-body'.
1913 (defun message-strip-subject-encoded-words (subject)
1914 "Fix non-decodable words in SUBJECT."
1915 ;; Cf. `gnus-simplify-subject-fully'.
1916 (let* ((case-fold-search t)
1917 (replacement-chars (format "[%s%s%s]"
1918 message-replacement-char
1919 message-replacement-char
1920 message-replacement-char))
1921 (enc-word-re "=\\?\\([^?]+\\)\\?\\([QB]\\)\\?\\([^?]+\\)\\(\\?=\\)")
1926 (goto-char (point-min))
1927 (when (re-search-forward enc-word-re nil t)
1928 (setq cs-string (match-string 1)))))
1929 cs-coding q-or-b word-beg word-end)
1930 (if (or (not have-marker) ;; No encoded word found...
1931 ;; ... or double encoding was correct:
1932 (and (stringp cs-string)
1933 (setq cs-string (downcase cs-string))
1934 (mm-coding-system-p (intern cs-string))
1938 Decoded Subject \"%s\"
1939 contains a valid encoded word. Decode again? "
1941 (setq cs-coding (intern cs-string))))))
1945 (goto-char (point-min))
1946 (while (re-search-forward enc-word-re nil t)
1947 (setq cs-string (downcase (match-string 1))
1948 q-or-b (match-string 2)
1949 word-beg (match-beginning 0)
1950 word-end (match-end 0))
1952 (if (mm-coding-system-p (intern cs-string))
1953 (setq cs-coding (intern cs-string))
1955 ;; No double encoded subject? => bogus charset.
1958 (mm-read-coding-system
1960 Decoded Subject \"%s\"
1961 contains an encoded word. The charset `%s' is unknown or invalid.
1962 Hit RET to replace non-decodable characters with \"%s\" or enter replacement
1964 subject cs-string message-replacement-char)))
1966 (replace-match (concat "=?" (symbol-name cs-coding)
1969 (goto-char word-beg)
1970 (re-search-forward "=\\?\\([^?]+\\)\\?\\([QB]\\)\\?" word-end t)
1973 (if (string-match "\\`Q\\'" q-or-b)
1976 (message "Replacing non-decodable characters with \"%s\"."
1977 message-replacement-char)
1978 (while (re-search-forward "\\(=[A-F0-9][A-F0-9]\\)+"
1980 (replace-match message-replacement-char)))
1982 (message "Replacing non-decodable characters with \"%s\"."
1984 (re-search-forward "[^?]+" word-end t)
1985 (replace-match replacement-chars))
1986 (re-search-forward "\\?=")
1987 (replace-match "")))))
1988 (rfc2047-decode-region (point-min) (point-max))
1991 ;;; Start of functions adopted from `message-utils.el'.
1993 (defun message-strip-subject-trailing-was (subject)
1994 "Remove trailing \"(was: <old subject>)\" from SUBJECT lines.
1995 Leading \"Re: \" is not stripped by this function. Use the function
1996 `message-strip-subject-re' for this."
1997 (let* ((query message-subject-trailing-was-query)
2002 message-subject-trailing-was-ask-regexp
2003 message-subject-trailing-was-regexp)
2006 (setq new (substring subject 0 (match-beginning 0))))
2007 (if (or (not found) (eq query nil))
2010 (if (message-y-or-n-p
2011 "Strip `(was: <old subject>)' in subject? " t
2013 "Strip `(was: <old subject>)' in subject "
2014 "and use the new one instead?\n\n"
2015 "Current subject is: \""
2017 "New subject would be: \""
2019 "See the variable `message-subject-trailing-was-query' "
2020 "to get rid of this query."
2025 ;;; Suggested by Jonas Steverud @ www.dtek.chalmers.se/~d4jonas/
2027 (defun message-change-subject (new-subject)
2028 "Ask for NEW-SUBJECT header, append (was: <Old Subject>)."
2029 ;; <URL:http://www.landfield.com/usefor/drafts/draft-ietf-usefor-useage--1.02.unpaged>
2032 (read-from-minibuffer "New subject: ")))
2033 (cond ((and (not (or (null new-subject) ; new subject not empty
2034 (zerop (string-width new-subject))
2035 (string-match "^[ \t]*$" new-subject))))
2039 (message-narrow-to-headers)
2040 (message-fetch-field "Subject"))))
2041 (cond ((not old-subject)
2042 (error "No current subject"))
2045 (regexp-quote new-subject)
2047 old-subject)) ; yes, it really is a new subject
2048 ;; delete eventual Re: prefix
2050 (message-strip-subject-re old-subject))
2051 (message-goto-subject)
2052 (message-delete-line)
2053 (insert (concat "Subject: "
2056 old-subject ")\n")))))))))
2058 (defun message-mark-inserted-region (beg end &optional verbatim)
2059 "Mark some region in the current article with enclosing tags.
2060 See `message-mark-insert-begin' and `message-mark-insert-end'.
2061 If VERBATIM, use slrn style verbatim marks (\"#v+\" and \"#v-\")."
2062 (interactive "r\nP")
2064 ;; add to the end of the region first, otherwise end would be invalid
2066 (insert (if verbatim "#v-\n" message-mark-insert-end))
2068 (insert (if verbatim "#v+\n" message-mark-insert-begin))))
2070 (defun message-mark-insert-file (file &optional verbatim)
2071 "Insert FILE at point, marking it with enclosing tags.
2072 See `message-mark-insert-begin' and `message-mark-insert-end'.
2073 If VERBATIM, use slrn style verbatim marks (\"#v+\" and \"#v-\")."
2074 (interactive "fFile to insert: \nP")
2075 ;; reverse insertion to get correct result.
2077 (insert (if verbatim "#v-\n" message-mark-insert-end))
2079 (insert-file-contents file)
2081 (insert (if verbatim "#v+\n" message-mark-insert-begin))))
2083 (defun message-add-archive-header ()
2084 "Insert \"X-No-Archive: Yes\" in the header and a note in the body.
2085 The note can be customized using `message-archive-note'. When called with a
2086 prefix argument, ask for a text to insert. If you don't want the note in the
2087 body, set `message-archive-note' to nil."
2089 (if current-prefix-arg
2090 (setq message-archive-note
2091 (read-from-minibuffer "Reason for No-Archive: "
2092 (cons message-archive-note 0))))
2094 (if (message-goto-signature)
2095 (re-search-backward message-signature-separator))
2096 (when message-archive-note
2097 (insert message-archive-note)
2099 (message-add-header message-archive-header)
2100 (message-sort-headers)))
2102 (defun message-cross-post-followup-to-header (target-group)
2103 "Mangles FollowUp-To and Newsgroups header to point to TARGET-GROUP.
2104 With prefix-argument just set Follow-Up, don't cross-post."
2106 (list ; Completion based on Gnus
2107 (completing-read "Followup To: "
2108 (if (boundp 'gnus-newsrc-alist)
2110 nil nil '("poster" . 0)
2111 (if (boundp 'gnus-group-history)
2112 'gnus-group-history))))
2113 (message-remove-header "Follow[Uu]p-[Tt]o" t)
2114 (message-goto-newsgroups)
2116 ;; if we already did a crosspost before, kill old target
2117 (if (and message-cross-post-old-target
2119 (regexp-quote (concat "," message-cross-post-old-target))
2122 ;; unless (followup is to poster or user explicitly asked not
2123 ;; to cross-post, or target-group is already in Newsgroups)
2124 ;; add target-group to Newsgroups line.
2126 ;; def: cross-post, req:no
2127 (and message-cross-post-default (not current-prefix-arg))
2128 ;; def: no-cross-post, req:yes
2129 (and (not message-cross-post-default) current-prefix-arg))
2130 (not (string-match "poster" target-group))
2131 (not (string-match (regexp-quote target-group)
2132 (message-fetch-field "Newsgroups"))))
2134 (insert (concat "," target-group))))
2135 (end-of-line) ; ensure Followup: comes after Newsgroups:
2136 ;; unless new followup would be identical to Newsgroups line
2137 ;; make a new Followup-To line
2138 (if (not (string-match (concat "^[ \t]*"
2141 (message-fetch-field "Newsgroups")))
2142 (insert (concat "\nFollowup-To: " target-group)))
2143 (setq message-cross-post-old-target target-group))
2145 (defun message-cross-post-insert-note (target-group cross-post in-old
2147 "Insert a in message body note about a set Followup or Crosspost.
2148 If there have been previous notes, delete them. TARGET-GROUP specifies the
2149 group to Followup-To. When CROSS-POST is t, insert note about
2150 crossposting. IN-OLD specifies whether TARGET-GROUP is a member of
2151 OLD-GROUPS. OLD-GROUPS lists the old-groups the posting would have
2152 been made to before the user asked for a Crosspost."
2153 ;; start scanning body for previous uses
2154 (message-goto-signature)
2155 (let ((head (re-search-backward
2156 (concat "^" mail-header-separator)
2157 nil t))) ; just search in body
2158 (message-goto-signature)
2159 (while (re-search-backward
2160 (concat "^" (regexp-quote message-cross-post-note) ".*")
2162 (message-delete-line))
2163 (message-goto-signature)
2164 (while (re-search-backward
2165 (concat "^" (regexp-quote message-followup-to-note) ".*")
2167 (message-delete-line))
2169 (if (message-goto-signature)
2170 (re-search-backward message-signature-separator))
2173 (string-match "^[ \t]*poster[ \t]*$" target-group))
2174 (insert (concat message-followup-to-note target-group "\n"))
2175 (insert (concat message-cross-post-note target-group "\n")))))
2177 (defun message-cross-post-followup-to (target-group)
2178 "Crossposts message and set Followup-To to TARGET-GROUP.
2179 With prefix-argument just set Follow-Up, don't cross-post."
2181 (list ; Completion based on Gnus
2182 (completing-read "Followup To: "
2183 (if (boundp 'gnus-newsrc-alist)
2185 nil nil '("poster" . 0)
2186 (if (boundp 'gnus-group-history)
2187 'gnus-group-history))))
2188 (cond ((not (or (null target-group) ; new subject not empty
2189 (zerop (string-width target-group))
2190 (string-match "^[ \t]*$" target-group)))
2192 (let* ((old-groups (message-fetch-field "Newsgroups"))
2193 (in-old (string-match
2194 (regexp-quote target-group)
2195 (or old-groups ""))))
2196 ;; check whether target exactly matches old Newsgroups
2197 (cond ((not old-groups)
2198 (error "No current newsgroup"))
2202 (regexp-quote target-group)
2205 ;; yes, Newsgroups line must change
2206 (message-cross-post-followup-to-header target-group)
2207 ;; insert note whether we do cross-post or followup-to
2208 (funcall message-cross-post-note-function
2210 (if (or (and message-cross-post-default
2211 (not current-prefix-arg))
2212 (and (not message-cross-post-default)
2213 current-prefix-arg)) t)
2214 in-old old-groups))))))))
2216 ;;; Reduce To: to Cc: or Bcc: header
2218 (defun message-reduce-to-to-cc ()
2219 "Replace contents of To: header with contents of Cc: or Bcc: header."
2222 (save-restriction (message-narrow-to-headers)
2223 (message-fetch-field "cc")))
2225 (if (and (not cc-content)
2228 (message-narrow-to-headers)
2229 (message-fetch-field "bcc"))))
2234 (message-delete-line)
2235 (insert (concat "To: " cc-content "\n"))
2237 (message-narrow-to-headers)
2238 (message-remove-header (if bcc
2242 ;;; End of functions adopted from `message-utils.el'.
2244 (defun message-remove-header (header &optional is-regexp first reverse)
2245 "Remove HEADER in the narrowed buffer.
2246 If IS-REGEXP, HEADER is a regular expression.
2247 If FIRST, only remove the first instance of the header.
2248 Return the number of headers removed."
2249 (goto-char (point-min))
2250 (let ((regexp (if is-regexp header (concat "^" (regexp-quote header) ":")))
2252 (case-fold-search t)
2254 (while (and (not (eobp))
2257 (not (looking-at regexp))
2258 (looking-at regexp))
2265 ;; There might be a continuation header, so we have to search
2266 ;; until we find a new non-continuation line.
2269 (if (re-search-forward "^[^ \t]" nil t)
2270 (goto-char (match-beginning 0))
2273 (if (re-search-forward "^[^ \t]" nil t)
2274 (goto-char (match-beginning 0))
2275 (goto-char (point-max)))))
2278 (defun message-remove-first-header (header)
2279 "Remove the first instance of HEADER if there is more than one."
2281 (regexp (concat "^" (regexp-quote header) ":")))
2283 (goto-char (point-min))
2284 (while (re-search-forward regexp nil t)
2287 (message-remove-header header nil t)
2290 (defun message-narrow-to-headers ()
2291 "Narrow the buffer to the head of the message."
2294 (goto-char (point-min))
2295 (if (re-search-forward
2296 (concat "^" (regexp-quote mail-header-separator) "\n") nil t)
2299 (goto-char (point-min)))
2301 (defun message-narrow-to-head-1 ()
2302 "Like `message-narrow-to-head'. Don't widen."
2304 (goto-char (point-min))
2305 (if (search-forward "\n\n" nil 1)
2308 (goto-char (point-min)))
2310 (defun message-narrow-to-head ()
2311 "Narrow the buffer to the head of the message.
2312 Point is left at the beginning of the narrowed-to region."
2314 (message-narrow-to-head-1))
2316 (defun message-narrow-to-headers-or-head ()
2317 "Narrow the buffer to the head of the message."
2320 (goto-char (point-min))
2323 (concat "^" (regexp-quote mail-header-separator) "\n") nil t)
2324 (match-beginning 0))
2325 ((search-forward "\n\n" nil t)
2329 (goto-char (point-min)))
2331 (defun message-news-p ()
2332 "Say whether the current buffer contains a news message."
2333 (and (not message-this-is-mail)
2334 (or message-this-is-news
2337 (message-narrow-to-headers)
2338 (and (message-fetch-field "newsgroups")
2339 (not (message-fetch-field "posted-to"))))))))
2341 (defun message-mail-p ()
2342 "Say whether the current buffer contains a mail message."
2343 (and (not message-this-is-news)
2344 (or message-this-is-mail
2347 (message-narrow-to-headers)
2348 (or (message-fetch-field "to")
2349 (message-fetch-field "cc")
2350 (message-fetch-field "bcc")))))))
2352 (defun message-subscribed-p ()
2353 "Say whether we need to insert a MFT header."
2354 (or message-subscribed-regexps
2355 message-subscribed-addresses
2356 message-subscribed-address-file
2357 message-subscribed-address-functions))
2359 (defun message-next-header ()
2360 "Go to the beginning of the next header."
2362 (or (eobp) (forward-char 1))
2363 (not (if (re-search-forward "^[^ \t]" nil t)
2365 (goto-char (point-max)))))
2367 (defun message-sort-headers-1 ()
2368 "Sort the buffer as headers using `message-rank' text props."
2369 (goto-char (point-min))
2372 nil 'message-next-header
2374 (message-next-header)
2378 (or (get-text-property (point) 'message-rank)
2381 (defun message-sort-headers ()
2382 "Sort the headers of the current message according to `message-header-format-alist'."
2386 (let ((max (1+ (length message-header-format-alist)))
2388 (message-narrow-to-headers)
2389 (while (re-search-forward "^[^ \n]+:" nil t)
2391 (match-beginning 0) (1+ (match-beginning 0))
2393 (if (setq rank (length (memq (assq (intern (buffer-substring
2395 (1- (match-end 0))))
2396 message-header-format-alist)
2397 message-header-format-alist)))
2400 (message-sort-headers-1))))
2402 (defun message-kill-address ()
2403 "Kill the address under point."
2405 (let ((start (point)))
2406 (message-skip-to-next-address)
2407 (kill-region start (point))))
2410 (defun message-info (&optional arg)
2411 "Display the Message manual.
2413 Prefixed with one \\[universal-argument], display the Emacs MIME manual.
2414 Prefixed with two \\[universal-argument]'s, display the PGG manual."
2416 (cond ((eq arg 16) (Info-goto-node "(pgg)Top"))
2417 ((eq arg 4) (Info-goto-node "(emacs-mime)Top"))
2418 (t (Info-goto-node "(message)Top"))))
2428 (defvar message-mode-map nil)
2430 (unless message-mode-map
2431 (setq message-mode-map (make-keymap))
2432 (set-keymap-parent message-mode-map text-mode-map)
2433 (define-key message-mode-map "\C-c?" 'describe-mode)
2435 (define-key message-mode-map "\C-c\C-f\C-t" 'message-goto-to)
2436 (define-key message-mode-map "\C-c\C-f\C-o" 'message-goto-from)
2437 (define-key message-mode-map "\C-c\C-f\C-b" 'message-goto-bcc)
2438 (define-key message-mode-map "\C-c\C-f\C-w" 'message-goto-fcc)
2439 (define-key message-mode-map "\C-c\C-f\C-c" 'message-goto-cc)
2440 (define-key message-mode-map "\C-c\C-f\C-s" 'message-goto-subject)
2441 (define-key message-mode-map "\C-c\C-f\C-r" 'message-goto-reply-to)
2442 (define-key message-mode-map "\C-c\C-f\C-n" 'message-goto-newsgroups)
2443 (define-key message-mode-map "\C-c\C-f\C-d" 'message-goto-distribution)
2444 (define-key message-mode-map "\C-c\C-f\C-f" 'message-goto-followup-to)
2445 (define-key message-mode-map "\C-c\C-f\C-m" 'message-goto-mail-followup-to)
2446 (define-key message-mode-map "\C-c\C-f\C-k" 'message-goto-keywords)
2447 (define-key message-mode-map "\C-c\C-f\C-u" 'message-goto-summary)
2448 (define-key message-mode-map "\C-c\C-f\C-i"
2449 'message-insert-or-toggle-importance)
2450 (define-key message-mode-map "\C-c\C-f\C-a"
2451 'message-generate-unsubscribed-mail-followup-to)
2453 ;; modify headers (and insert notes in body)
2454 (define-key message-mode-map "\C-c\C-fs" 'message-change-subject)
2456 (define-key message-mode-map "\C-c\C-fx" 'message-cross-post-followup-to)
2457 ;; prefix+message-cross-post-followup-to = same w/o cross-post
2458 (define-key message-mode-map "\C-c\C-ft" 'message-reduce-to-to-cc)
2459 (define-key message-mode-map "\C-c\C-fa" 'message-add-archive-header)
2460 ;; mark inserted text
2461 (define-key message-mode-map "\C-c\M-m" 'message-mark-inserted-region)
2462 (define-key message-mode-map "\C-c\M-f" 'message-mark-insert-file)
2464 (define-key message-mode-map "\C-c\C-b" 'message-goto-body)
2465 (define-key message-mode-map "\C-c\C-i" 'message-goto-signature)
2467 (define-key message-mode-map "\C-c\C-t" 'message-insert-to)
2468 (define-key message-mode-map "\C-c\C-fw" 'message-insert-wide-reply)
2469 (define-key message-mode-map "\C-c\C-n" 'message-insert-newsgroups)
2470 (define-key message-mode-map "\C-c\C-l" 'message-to-list-only)
2471 (define-key message-mode-map "\C-c\C-f\C-e" 'message-insert-expires)
2473 (define-key message-mode-map "\C-c\C-u" 'message-insert-or-toggle-importance)
2474 (define-key message-mode-map "\C-c\M-n"
2475 'message-insert-disposition-notification-to)
2477 (define-key message-mode-map "\C-c\C-y" 'message-yank-original)
2478 (define-key message-mode-map "\C-c\M-\C-y" 'message-yank-buffer)
2479 (define-key message-mode-map "\C-c\C-q" 'message-fill-yanked-message)
2480 (define-key message-mode-map "\C-c\C-w" 'message-insert-signature)
2481 (define-key message-mode-map "\C-c\M-h" 'message-insert-headers)
2482 (define-key message-mode-map "\C-c\C-r" 'message-caesar-buffer-body)
2483 (define-key message-mode-map "\C-c\C-o" 'message-sort-headers)
2484 (define-key message-mode-map "\C-c\M-r" 'message-rename-buffer)
2486 (define-key message-mode-map "\C-c\C-c" 'message-send-and-exit)
2487 (define-key message-mode-map "\C-c\C-s" 'message-send)
2488 (define-key message-mode-map "\C-c\C-k" 'message-kill-buffer)
2489 (define-key message-mode-map "\C-c\C-d" 'message-dont-send)
2490 (define-key message-mode-map "\C-c\n" 'gnus-delay-article)
2492 (define-key message-mode-map "\C-c\M-k" 'message-kill-address)
2493 (define-key message-mode-map "\C-c\C-e" 'message-elide-region)
2494 (define-key message-mode-map "\C-c\C-v" 'message-delete-not-region)
2495 (define-key message-mode-map "\C-c\C-z" 'message-kill-to-signature)
2496 (define-key message-mode-map "\M-\r" 'message-newline-and-reformat)
2497 (define-key message-mode-map [remap split-line] 'message-split-line)
2499 (define-key message-mode-map "\C-c\C-a" 'mml-attach-file)
2501 (define-key message-mode-map "\C-a" 'message-beginning-of-line)
2502 (define-key message-mode-map "\t" 'message-tab)
2503 (define-key message-mode-map "\M-;" 'comment-region)
2505 (define-key message-mode-map "\M-n" 'message-display-abbrev))
2508 message-mode-menu message-mode-map "Message Menu."
2510 ["Yank Original" message-yank-original message-reply-buffer]
2511 ["Fill Yanked Message" message-fill-yanked-message t]
2512 ["Insert Signature" message-insert-signature t]
2513 ["Caesar (rot13) Message" message-caesar-buffer-body t]
2514 ["Caesar (rot13) Region" message-caesar-region (message-mark-active-p)]
2515 ["Elide Region" message-elide-region
2516 :active (message-mark-active-p)
2517 ,@(if (featurep 'xemacs) nil
2518 '(:help "Replace text in region with an ellipsis"))]
2519 ["Delete Outside Region" message-delete-not-region
2520 :active (message-mark-active-p)
2521 ,@(if (featurep 'xemacs) nil
2522 '(:help "Delete all quoted text outside region"))]
2523 ["Kill To Signature" message-kill-to-signature t]
2524 ["Newline and Reformat" message-newline-and-reformat t]
2525 ["Rename buffer" message-rename-buffer t]
2526 ["Spellcheck" ispell-message
2527 ,@(if (featurep 'xemacs) '(t)
2528 '(:help "Spellcheck this message"))]
2530 ["Insert Region Marked" message-mark-inserted-region
2531 :active (message-mark-active-p)
2532 ,@(if (featurep 'xemacs) nil
2533 '(:help "Mark region with enclosing tags"))]
2534 ["Insert File Marked..." message-mark-insert-file
2535 ,@(if (featurep 'xemacs) '(t)
2536 '(:help "Insert file at point marked with enclosing tags"))]
2538 ["Send Message" message-send-and-exit
2539 ,@(if (featurep 'xemacs) '(t)
2540 '(:help "Send this message"))]
2541 ["Postpone Message" message-dont-send
2542 ,@(if (featurep 'xemacs) '(t)
2543 '(:help "File this draft message and exit"))]
2544 ["Send at Specific Time..." gnus-delay-article
2545 ,@(if (featurep 'xemacs) '(t)
2546 '(:help "Ask, then arrange to send message at that time"))]
2547 ["Kill Message" message-kill-buffer
2548 ,@(if (featurep 'xemacs) '(t)
2549 '(:help "Delete this message without sending"))]
2551 ["Message manual" message-info
2552 ,@(if (featurep 'xemacs) '(t)
2553 '(:help "Display the Message manual"))]))
2556 message-mode-field-menu message-mode-map ""
2558 ["To" message-goto-to t]
2559 ["From" message-goto-from t]
2560 ["Subject" message-goto-subject t]
2561 ["Change subject..." message-change-subject t]
2562 ["Cc" message-goto-cc t]
2563 ["Bcc" message-goto-bcc t]
2564 ["Fcc" message-goto-fcc t]
2565 ["Reply-To" message-goto-reply-to t]
2566 ["Flag As Important" message-insert-importance-high
2567 ,@(if (featurep 'xemacs) '(t)
2568 '(:help "Mark this message as important"))]
2569 ["Flag As Unimportant" message-insert-importance-low
2570 ,@(if (featurep 'xemacs) '(t)
2571 '(:help "Mark this message as unimportant"))]
2573 message-insert-disposition-notification-to
2574 ,@(if (featurep 'xemacs) '(t)
2575 '(:help "Request a receipt notification"))]
2577 ;; (typical) news stuff
2578 ["Summary" message-goto-summary t]
2579 ["Keywords" message-goto-keywords t]
2580 ["Newsgroups" message-goto-newsgroups t]
2581 ["Fetch Newsgroups" message-insert-newsgroups t]
2582 ["Followup-To" message-goto-followup-to t]
2583 ;; ["Followup-To (with note in body)" message-cross-post-followup-to t]
2584 ["Crosspost / Followup-To..." message-cross-post-followup-to t]
2585 ["Distribution" message-goto-distribution t]
2586 ["Expires" message-insert-expires t ]
2587 ["X-No-Archive" message-add-archive-header t ]
2589 ;; (typical) mailing-lists stuff
2590 ["Fetch To" message-insert-to
2591 ,@(if (featurep 'xemacs) '(t)
2592 '(:help "Insert a To header that points to the author."))]
2593 ["Fetch To and Cc" message-insert-wide-reply
2594 ,@(if (featurep 'xemacs) '(t)
2596 "Insert To and Cc headers as if you were doing a wide reply."))]
2598 ["Send to list only" message-to-list-only t]
2599 ["Mail-Followup-To" message-goto-mail-followup-to t]
2600 ["Unsubscribed list post" message-generate-unsubscribed-mail-followup-to
2601 ,@(if (featurep 'xemacs) '(t)
2602 '(:help "Insert a reasonable `Mail-Followup-To:' header."))]
2603 ["Reduce To: to Cc:" message-reduce-to-to-cc t]
2605 ["Sort Headers" message-sort-headers t]
2606 ["Encode non-ASCII domain names" message-idna-to-ascii-rhs t]
2607 ;; We hide `message-hidden-headers' by narrowing the buffer.
2608 ["Show Hidden Headers" widen t]
2609 ["Goto Body" message-goto-body t]
2610 ["Goto Signature" message-goto-signature t]))
2612 (defvar message-tool-bar-map nil)
2615 (defvar facemenu-add-face-function)
2616 (defvar facemenu-remove-face-function))
2618 ;;; Forbidden properties
2620 ;; We use `after-change-functions' to keep special text properties
2621 ;; that interfer with the normal function of message mode out of the
2624 (defcustom message-strip-special-text-properties t
2625 "Strip special properties from the message buffer.
2627 Emacs has a number of special text properties which can break message
2628 composing in various ways. If this option is set, message will strip
2629 these properties from the message composition buffer. However, some
2630 packages requires these properties to be present in order to work.
2631 If you use one of these packages, turn this option off, and hope the
2632 message composition doesn't break too bad."
2634 :group 'message-various
2635 :link '(custom-manual "(message)Various Message Variables")
2638 (defconst message-forbidden-properties
2639 ;; No reason this should be clutter up customize. We make it a
2640 ;; property list (rather than a list of property symbols), to be
2641 ;; directly useful for `remove-text-properties'.
2642 '(field nil read-only nil invisible nil intangible nil
2643 mouse-face nil modification-hooks nil insert-in-front-hooks nil
2644 insert-behind-hooks nil point-entered nil point-left nil)
2645 ;; Other special properties:
2646 ;; category, face, display: probably doesn't do any harm.
2647 ;; fontified: is used by font-lock.
2648 ;; syntax-table, local-map: I dunno.
2649 ;; We need to add XEmacs names to the list.
2650 "Property list of with properties forbidden in message buffers.
2651 The values of the properties are ignored, only the property names are used.")
2653 (defun message-tamago-not-in-use-p (pos)
2654 "Return t when tamago version 4 is not in use at the cursor position.
2655 Tamago version 4 is a popular input method for writing Japanese text.
2656 It uses the properties `intangible', `invisible', `modification-hooks'
2657 and `read-only' when translating ascii or kana text to kanji text.
2658 These properties are essential to work, so we should never strip them."
2659 (not (and (boundp 'egg-modefull-mode)
2660 (symbol-value 'egg-modefull-mode)
2661 (or (memq (get-text-property pos 'intangible)
2662 '(its-part-1 its-part-2))
2663 (get-text-property pos 'egg-end)
2664 (get-text-property pos 'egg-lang)
2665 (get-text-property pos 'egg-start)))))
2667 (defsubst message-mail-alias-type-p (type)
2668 (if (atom message-mail-alias-type)
2669 (eq message-mail-alias-type type)
2670 (memq type message-mail-alias-type)))
2672 (defun message-strip-forbidden-properties (begin end &optional old-length)
2673 "Strip forbidden properties between BEGIN and END, ignoring the third arg.
2674 This function is intended to be called from `after-change-functions'.
2675 See also `message-forbidden-properties'."
2676 (when (and (message-mail-alias-type-p 'ecomplete)
2677 (memq this-command message-self-insert-commands))
2678 (message-display-abbrev))
2679 (when (and message-strip-special-text-properties
2680 (message-tamago-not-in-use-p begin))
2681 (let ((buffer-read-only nil)
2682 (inhibit-read-only t))
2683 (remove-text-properties begin end message-forbidden-properties))))
2686 (define-derived-mode message-mode text-mode "Message"
2687 "Major mode for editing mail and news to be sent.
2688 Like Text Mode but with these additional commands:\\<message-mode-map>
2689 C-c C-s `message-send' (send the message) C-c C-c `message-send-and-exit'
2690 C-c C-d Postpone sending the message C-c C-k Kill the message
2691 C-c C-f move to a header field (and create it if there isn't):
2692 C-c C-f C-t move to To C-c C-f C-s move to Subject
2693 C-c C-f C-c move to Cc C-c C-f C-b move to Bcc
2694 C-c C-f C-w move to Fcc C-c C-f C-r move to Reply-To
2695 C-c C-f C-u move to Summary C-c C-f C-n move to Newsgroups
2696 C-c C-f C-k move to Keywords C-c C-f C-d move to Distribution
2697 C-c C-f C-o move to From (\"Originator\")
2698 C-c C-f C-f move to Followup-To
2699 C-c C-f C-m move to Mail-Followup-To
2700 C-c C-f C-e move to Expires
2701 C-c C-f C-i cycle through Importance values
2702 C-c C-f s change subject and append \"(was: <Old Subject>)\"
2703 C-c C-f x crossposting with FollowUp-To header and note in body
2704 C-c C-f t replace To: header with contents of Cc: or Bcc:
2705 C-c C-f a Insert X-No-Archive: header and a note in the body
2706 C-c C-t `message-insert-to' (add a To header to a news followup)
2707 C-c C-l `message-to-list-only' (removes all but list address in to/cc)
2708 C-c C-n `message-insert-newsgroups' (add a Newsgroup header to a news reply)
2709 C-c C-b `message-goto-body' (move to beginning of message text).
2710 C-c C-i `message-goto-signature' (move to the beginning of the signature).
2711 C-c C-w `message-insert-signature' (insert `message-signature-file' file).
2712 C-c C-y `message-yank-original' (insert current message, if any).
2713 C-c C-q `message-fill-yanked-message' (fill what was yanked).
2714 C-c C-e `message-elide-region' (elide the text between point and mark).
2715 C-c C-v `message-delete-not-region' (remove the text outside the region).
2716 C-c C-z `message-kill-to-signature' (kill the text up to the signature).
2717 C-c C-r `message-caesar-buffer-body' (rot13 the message body).
2718 C-c C-a `mml-attach-file' (attach a file as MIME).
2719 C-c C-u `message-insert-or-toggle-importance' (insert or cycle importance).
2720 C-c M-n `message-insert-disposition-notification-to' (request receipt).
2721 C-c M-m `message-mark-inserted-region' (mark region with enclosing tags).
2722 C-c M-f `message-mark-insert-file' (insert file marked with enclosing tags).
2723 M-RET `message-newline-and-reformat' (break the line and reformat)."
2724 (setq local-abbrev-table text-mode-abbrev-table)
2725 (set (make-local-variable 'message-reply-buffer) nil)
2726 (set (make-local-variable 'message-inserted-headers) nil)
2727 (set (make-local-variable 'message-send-actions) nil)
2728 (set (make-local-variable 'message-exit-actions) nil)
2729 (set (make-local-variable 'message-kill-actions) nil)
2730 (set (make-local-variable 'message-postpone-actions) nil)
2731 (set (make-local-variable 'message-draft-article) nil)
2732 (setq buffer-offer-save t)
2733 (set (make-local-variable 'facemenu-add-face-function)
2735 (let ((face-fun (cdr (assq face message-face-alist))))
2737 (funcall face-fun (point) end)
2738 (error "Face %s not configured for %s mode" face mode-name)))
2740 (set (make-local-variable 'facemenu-remove-face-function) t)
2741 (set (make-local-variable 'message-reply-headers) nil)
2742 (make-local-variable 'message-newsreader)
2743 (make-local-variable 'message-mailer)
2744 (make-local-variable 'message-post-method)
2745 (set (make-local-variable 'message-sent-message-via) nil)
2746 (set (make-local-variable 'message-checksum) nil)
2747 (set (make-local-variable 'message-mime-part) 0)
2748 (message-setup-fill-variables)
2749 ;; Allow using comment commands to add/remove quoting.
2750 ;; (set (make-local-variable 'comment-start) message-yank-prefix)
2751 (when message-yank-prefix
2752 (set (make-local-variable 'comment-start) message-yank-prefix)
2753 (set (make-local-variable 'comment-start-skip)
2754 (concat "^" (regexp-quote message-yank-prefix) "[ \t]*")))
2755 (if (featurep 'xemacs)
2756 (message-setup-toolbar)
2757 (set (make-local-variable 'font-lock-defaults)
2758 '(message-font-lock-keywords t))
2759 (if (boundp 'tool-bar-map)
2760 (set (make-local-variable 'tool-bar-map) (message-make-tool-bar))))
2761 (easy-menu-add message-mode-menu message-mode-map)
2762 (easy-menu-add message-mode-field-menu message-mode-map)
2763 (gnus-make-local-hook 'after-change-functions)
2764 ;; Mmmm... Forbidden properties...
2765 (add-hook 'after-change-functions 'message-strip-forbidden-properties
2767 ;; Allow mail alias things.
2769 ((message-mail-alias-type-p 'abbrev)
2770 (if (fboundp 'mail-abbrevs-setup)
2771 (mail-abbrevs-setup)
2772 (if (fboundp 'mail-aliases-setup) ; warning avoidance
2773 (mail-aliases-setup))))
2774 ((message-mail-alias-type-p 'ecomplete)
2776 (unless buffer-file-name
2777 (message-set-auto-save-file-name))
2778 (unless (buffer-base-buffer)
2779 ;; Don't enable multibyte on an indirect buffer. Maybe enabling
2780 ;; multibyte is not necessary at all. -- zsh
2781 (mm-enable-multibyte))
2782 (set (make-local-variable 'indent-tabs-mode) nil) ;No tabs for indentation.
2785 (defun message-setup-fill-variables ()
2786 "Setup message fill variables."
2787 (set (make-local-variable 'fill-paragraph-function)
2788 'message-fill-paragraph)
2789 (make-local-variable 'paragraph-separate)
2790 (make-local-variable 'paragraph-start)
2791 (make-local-variable 'adaptive-fill-regexp)
2792 (unless (boundp 'adaptive-fill-first-line-regexp)
2793 (setq adaptive-fill-first-line-regexp nil))
2794 (make-local-variable 'adaptive-fill-first-line-regexp)
2795 (let ((quote-prefix-regexp
2796 ;; User should change message-cite-prefix-regexp if
2797 ;; message-yank-prefix is set to an abnormal value.
2798 (concat "\\(" message-cite-prefix-regexp "\\)[ \t]*")))
2799 (setq paragraph-start
2801 (regexp-quote mail-header-separator) "$\\|"
2802 "[ \t]*$\\|" ; blank lines
2803 "-- $\\|" ; signature delimiter
2804 "---+$\\|" ; delimiters for forwarded messages
2805 page-delimiter "$\\|" ; spoiler warnings
2806 ".*wrote:$\\|" ; attribution lines
2807 quote-prefix-regexp "$\\|" ; empty lines in quoted text
2809 "<#!*/?\\(multipart\\|part\\|external\\|mml\\|secure\\)"))
2810 (setq paragraph-separate paragraph-start)
2811 (setq adaptive-fill-regexp
2812 (concat quote-prefix-regexp "\\|" adaptive-fill-regexp))
2813 (setq adaptive-fill-first-line-regexp
2814 (concat quote-prefix-regexp "\\|"
2815 adaptive-fill-first-line-regexp)))
2816 (make-local-variable 'auto-fill-inhibit-regexp)
2817 ;;(setq auto-fill-inhibit-regexp "^[A-Z][^: \n\t]+:")
2818 (setq auto-fill-inhibit-regexp nil)
2819 (make-local-variable 'normal-auto-fill-function)
2820 (setq normal-auto-fill-function 'message-do-auto-fill)
2821 ;; KLUDGE: auto fill might already be turned on in `text-mode-hook'.
2822 ;; In that case, ensure that it uses the right function. The real
2823 ;; solution would be not to use `define-derived-mode', and run
2824 ;; `text-mode-hook' ourself at the end of the mode.
2825 ;; -- Per Abrahamsen <abraham@dina.kvl.dk> Date: 2001-10-19.
2826 (when auto-fill-function
2827 (setq auto-fill-function normal-auto-fill-function)))
2832 ;;; Message mode commands
2835 ;;; Movement commands
2837 (defun message-goto-to ()
2838 "Move point to the To header."
2840 (message-position-on-field "To"))
2842 (defun message-goto-from ()
2843 "Move point to the From header."
2845 (message-position-on-field "From"))
2847 (defun message-goto-subject ()
2848 "Move point to the Subject header."
2850 (message-position-on-field "Subject"))
2852 (defun message-goto-cc ()
2853 "Move point to the Cc header."
2855 (message-position-on-field "Cc" "To"))
2857 (defun message-goto-bcc ()
2858 "Move point to the Bcc header."
2860 (message-position-on-field "Bcc" "Cc" "To"))
2862 (defun message-goto-fcc ()
2863 "Move point to the Fcc header."
2865 (message-position-on-field "Fcc" "To" "Newsgroups"))
2867 (defun message-goto-reply-to ()
2868 "Move point to the Reply-To header."
2870 (message-position-on-field "Reply-To" "Subject"))
2872 (defun message-goto-newsgroups ()
2873 "Move point to the Newsgroups header."
2875 (message-position-on-field "Newsgroups"))
2877 (defun message-goto-distribution ()
2878 "Move point to the Distribution header."
2880 (message-position-on-field "Distribution"))
2882 (defun message-goto-followup-to ()
2883 "Move point to the Followup-To header."
2885 (message-position-on-field "Followup-To" "Newsgroups"))
2887 (defun message-goto-mail-followup-to ()
2888 "Move point to the Mail-Followup-To header."
2890 (message-position-on-field "Mail-Followup-To" "To"))
2892 (defun message-goto-keywords ()
2893 "Move point to the Keywords header."
2895 (message-position-on-field "Keywords" "Subject"))
2897 (defun message-goto-summary ()
2898 "Move point to the Summary header."
2900 (message-position-on-field "Summary" "Subject"))
2902 (defun message-goto-body (&optional interactivep)
2903 "Move point to the beginning of the message body."
2904 (interactive (list t))
2905 (when (and interactivep
2906 (looking-at "[ \t]*\n"))
2908 (goto-char (point-min))
2909 (or (search-forward (concat "\n" mail-header-separator "\n") nil t)
2910 (search-forward-regexp "[^:]+:\\([^\n]\\|\n[ \t]\\)+\n\n" nil t)))
2912 (defun message-in-body-p ()
2913 "Return t if point is in the message body."
2914 (let ((body (save-excursion (message-goto-body) (point))))
2917 (defun message-goto-eoh ()
2918 "Move point to the end of the headers."
2923 (defun message-goto-signature ()
2924 "Move point to the beginning of the message signature.
2925 If there is no signature in the article, go to the end and
2928 (goto-char (point-min))
2929 (if (re-search-forward message-signature-separator nil t)
2931 (goto-char (point-max))
2934 (defun message-generate-unsubscribed-mail-followup-to (&optional include-cc)
2935 "Insert a reasonable MFT header in a post to an unsubscribed list.
2936 When making original posts to a mailing list you are not subscribed to,
2937 you have to type in a MFT header by hand. The contents, usually, are
2938 the addresses of the list and your own address. This function inserts
2939 such a header automatically. It fetches the contents of the To: header
2940 in the current mail buffer, and appends the current `user-mail-address'.
2942 If the optional argument INCLUDE-CC is non-nil, the addresses in the
2943 Cc: header are also put into the MFT."
2948 (message-narrow-to-headers)
2949 (message-remove-header "Mail-Followup-To")
2950 (setq cc (and include-cc (message-fetch-field "Cc")))
2952 (concat (message-fetch-field "To") "," cc)
2953 (message-fetch-field "To"))))
2954 (message-goto-mail-followup-to)
2955 (insert (concat tos ", " user-mail-address))))
2959 (defun message-insert-to (&optional force)
2960 "Insert a To header that points to the author of the article being replied to.
2961 If the original author requested not to be sent mail, don't insert unless the
2962 prefix FORCE is given."
2964 (let* ((mct (message-fetch-reply-field "mail-copies-to"))
2965 (dont (and mct (or (equal (downcase mct) "never")
2966 (equal (downcase mct) "nobody"))))
2967 (to (or (message-fetch-reply-field "mail-reply-to")
2968 (message-fetch-reply-field "reply-to")
2969 (message-fetch-reply-field "from"))))
2973 "Ignoring the user request not to have copies sent via mail"
2974 "Complying with the user request not to have copies sent via mail")))
2975 (when (and force (not to))
2976 (error "No mail address in the article"))
2977 (when (and to (or force (not dont)))
2978 (message-carefully-insert-headers (list (cons 'To to))))))
2980 (defun message-insert-wide-reply ()
2981 "Insert To and Cc headers as if you were doing a wide reply."
2983 (let ((headers (message-with-reply-buffer
2984 (message-get-reply-headers t))))
2985 (message-carefully-insert-headers headers)))
2987 (defcustom message-header-synonyms
2990 "List of lists of header synonyms.
2991 E.g., if this list contains a member list with elements `Cc' and `To',
2992 then `message-carefully-insert-headers' will not insert a `To' header
2993 when the message is already `Cc'ed to the recipient."
2995 :group 'message-headers
2996 :link '(custom-manual "(message)Message Headers")
2997 :type '(repeat sexp))
2999 (defun message-carefully-insert-headers (headers)
3000 "Insert the HEADERS, an alist, into the message buffer.
3001 Does not insert the headers when they are already present there
3002 or in the synonym headers, defined by `message-header-synonyms'."
3003 ;; FIXME: Should compare only the address and not the full name. Comparison
3004 ;; should be done case-folded (and with `string=' rather than
3006 ;; (mail-strip-quoted-names "Foo Bar <foo@bar>, bla@fasel (Bla Fasel)")
3007 (dolist (header headers)
3008 (let* ((header-name (symbol-name (car header)))
3009 (new-header (cdr header))
3010 (synonyms (loop for synonym in message-header-synonyms
3011 when (memq (car header) synonym) return synonym))
3013 (loop for synonym in synonyms
3014 for old-header = (mail-fetch-field (symbol-name synonym))
3015 when (and old-header (string-match new-header old-header))
3018 (message "already have `%s' in `%s'" new-header old-header)
3019 (when (and (message-position-on-field header-name)
3020 (setq old-header (mail-fetch-field header-name))
3021 (not (string-match "\\` *\\'" old-header)))
3023 (insert new-header)))))
3025 (defun message-widen-reply ()
3026 "Widen the reply to include maximum recipients."
3029 (and message-reply-buffer
3030 (buffer-name message-reply-buffer)
3032 (set-buffer message-reply-buffer)
3033 (message-get-reply-headers t)))))
3036 (message-narrow-to-headers)
3037 (dolist (elem follow-to)
3038 (message-remove-header (symbol-name (car elem)))
3039 (goto-char (point-min))
3040 (insert (symbol-name (car elem)) ": "
3041 (cdr elem) "\n"))))))
3043 (defun message-insert-newsgroups ()
3044 "Insert the Newsgroups header from the article being replied to."
3046 (when (and (message-position-on-field "Newsgroups")
3047 (mail-fetch-field "newsgroups")
3048 (not (string-match "\\` *\\'" (mail-fetch-field "newsgroups"))))
3050 (insert (or (message-fetch-reply-field "newsgroups") "")))
3054 ;;; Various commands
3056 (defun message-delete-not-region (beg end)
3057 "Delete everything in the body of the current message outside of the region."
3062 ;; snarf citation prefix, if appropriate
3063 (unless (eq (point) (progn (beginning-of-line) (point)))
3064 (when (looking-at message-cite-prefix-regexp)
3065 (setq citeprefix (match-string 0))))
3067 (delete-region (point) (if (not (message-goto-signature))
3073 (delete-region beg (progn (message-goto-body)
3077 (insert citeprefix))))
3078 (when (message-goto-signature)
3081 (defun message-kill-to-signature (&optional arg)
3082 "Kill all text up to the signature.
3083 If a numberic argument or prefix arg is given, leave that number
3084 of lines before the signature intact."
3088 (let ((point (point)))
3089 (narrow-to-region point (point-max))
3090 (message-goto-signature)
3092 (if (and arg (numberp arg))
3093 (forward-line (- -1 arg))
3095 (unless (= point (point))
3096 (kill-region point (point))
3100 (defun message-newline-and-reformat (&optional arg not-break)
3101 "Insert four newlines, and then reformat if inside quoted text.
3102 Prefix arg means justify as well."
3103 (interactive (list (if current-prefix-arg 'full)))
3104 (let (quoted point beg end leading-space bolp fill-paragraph-function)
3105 (setq point (point))
3108 (setq bolp (= beg point))
3109 ;; Find first line of the paragraph.
3111 (while (and (not (eobp))
3112 (not (looking-at message-cite-prefix-regexp))
3113 (looking-at paragraph-start))
3116 (when (looking-at message-cite-prefix-regexp)
3117 (setq quoted (match-string 0))
3118 (goto-char (match-end 0))
3119 (looking-at "[ \t]*")
3120 (setq leading-space (match-string 0)))
3124 (< (- point beg) (length quoted)))
3125 ;; break inside the cite prefix.
3131 (while (and (not (eobp))
3132 (not (looking-at paragraph-separate))
3133 (looking-at message-cite-prefix-regexp)
3134 (equal quoted (match-string 0)))
3135 (goto-char (match-end 0))
3136 (looking-at "[ \t]*")
3137 (if (> (length leading-space) (length (match-string 0)))
3138 (setq leading-space (match-string 0)))
3142 (while (and (if (bobp) nil (forward-line -1) t)
3143 (not (looking-at paragraph-start))
3144 (looking-at message-cite-prefix-regexp)
3145 (equal quoted (match-string 0)))
3147 (goto-char (match-end 0))
3148 (looking-at "[ \t]*")
3149 (if (> (length leading-space) (length (match-string 0)))
3150 (setq leading-space (match-string 0)))))
3151 (while (and (not (eobp))
3152 (not (looking-at paragraph-separate))
3153 (not (looking-at message-cite-prefix-regexp)))
3157 (while (and (if (bobp) nil (forward-line -1) t)
3158 (not (looking-at paragraph-start))
3159 (not (looking-at message-cite-prefix-regexp)))
3160 (setq beg (point))))
3163 (narrow-to-region beg end)
3170 (setq point (point))
3171 ;; (newline 2) doesn't mark both newline's as hard, so call
3172 ;; newline twice. -jas
3175 (delete-region (point) (re-search-forward "[ \t]*"))
3176 (when (and quoted (not bolp))
3177 (insert quoted leading-space)))
3180 (let* ((adaptive-fill-regexp
3181 (regexp-quote (concat quoted leading-space)))
3182 (adaptive-fill-first-line-regexp
3183 adaptive-fill-regexp ))
3184 (fill-paragraph arg))
3185 (fill-paragraph arg))
3186 (if point (goto-char point)))))
3188 (defun message-fill-paragraph (&optional arg)
3189 "Message specific function to fill a paragraph.
3190 This function is used as the value of `fill-paragraph-function' in
3191 Message buffers and is not meant to be called directly."
3192 (interactive (list (if current-prefix-arg 'full)))
3193 (if (if (boundp 'filladapt-mode) filladapt-mode)
3195 (if (message-point-in-header-p)
3196 (message-fill-field)
3197 (message-newline-and-reformat arg t))
3200 (defun message-point-in-header-p ()
3201 "Return t if point is in the header."
3203 (not (re-search-backward
3204 (concat "^" (regexp-quote mail-header-separator) "\n") nil t))))
3206 (defun message-do-auto-fill ()
3207 "Like `do-auto-fill', but don't fill in message header."
3208 (unless (message-point-in-header-p)
3211 (defun message-insert-signature (&optional force)
3212 "Insert a signature. See documentation for variable `message-signature'."
3213 (interactive (list 0))
3216 ((and (null message-signature)
3219 (goto-char (point-max))
3220 (not (re-search-backward message-signature-separator nil t))))
3221 ((and (null message-signature)
3224 ((functionp message-signature)
3225 (funcall message-signature))
3226 ((listp message-signature)
3227 (eval message-signature))
3228 (t message-signature)))
3230 (cond ((stringp signature)
3232 ((and (eq t signature)
3233 message-signature-file
3234 (file-exists-p message-signature-file))
3237 (goto-char (point-max))
3238 ;; Insert the signature.
3241 (when message-signature-insert-empty-line
3244 (if (eq signature t)
3245 (insert-file-contents message-signature-file)
3247 (goto-char (point-max))
3248 (or (bolp) (insert "\n")))))
3250 (defun message-insert-importance-high ()
3251 "Insert header to mark message as important."
3255 (message-narrow-to-headers)
3256 (message-remove-header "Importance"))
3258 (insert "Importance: high\n")))
3260 (defun message-insert-importance-low ()
3261 "Insert header to mark message as unimportant."
3265 (message-narrow-to-headers)
3266 (message-remove-header "Importance"))
3268 (insert "Importance: low\n")))
3270 (defun message-insert-or-toggle-importance ()
3271 "Insert a \"Importance: high\" header, or cycle through the header values.
3272 The three allowed values according to RFC 1327 are `high', `normal'
3276 (let ((valid '("high" "normal" "low"))
3280 (message-narrow-to-headers)
3281 (when (setq cur (message-fetch-field "Importance"))
3282 (message-remove-header "Importance")
3283 (setq new (cond ((string= cur "high")
3285 ((string= cur "low")
3290 (insert (format "Importance: %s\n" new)))))
3292 (defun message-insert-disposition-notification-to ()
3293 "Request a disposition notification (return receipt) to this message.
3294 Note that this should not be used in newsgroups."
3298 (message-narrow-to-headers)
3299 (message-remove-header "Disposition-Notification-To"))
3301 (insert (format "Disposition-Notification-To: %s\n"
3302 (or (message-field-value "Reply-to")
3303 (message-field-value "From")
3304 (message-make-from))))))
3306 (defun message-elide-region (b e)
3307 "Elide the text in the region.
3308 An ellipsis (from `message-elide-ellipsis') will be inserted where the
3312 (insert message-elide-ellipsis))
3314 (defvar message-caesar-translation-table nil)
3316 (defun message-caesar-region (b e &optional n)
3317 "Caesar rotate region B to E by N, default 13, for decrypting netnews."
3320 (min (point) (or (mark t) (point)))
3321 (max (point) (or (mark t) (point)))
3322 (when current-prefix-arg
3323 (prefix-numeric-value current-prefix-arg))))
3325 (setq n (if (numberp n) (mod n 26) 13)) ;canonize N
3326 (unless (or (zerop n) ; no action needed for a rot of 0
3327 (= b e)) ; no region to rotate
3328 ;; We build the table, if necessary.
3329 (when (or (not message-caesar-translation-table)
3330 (/= (aref message-caesar-translation-table ?a) (+ ?a n)))
3331 (setq message-caesar-translation-table
3332 (message-make-caesar-translation-table n)))
3333 (translate-region b e message-caesar-translation-table)))
3335 (defun message-make-caesar-translation-table (n)
3336 "Create a rot table with offset N."
3338 (table (make-string 256 0)))
3339 (while (< (incf i) 256)
3342 (substring table 0 ?A)
3343 (substring table (+ ?A n) (+ ?A n (- 26 n)))
3344 (substring table ?A (+ ?A n))
3345 (substring table (+ ?A 26) ?a)
3346 (substring table (+ ?a n) (+ ?a n (- 26 n)))
3347 (substring table ?a (+ ?a n))
3348 (substring table (+ ?a 26) 255))))
3350 (defun message-caesar-buffer-body (&optional rotnum wide)
3351 "Caesar rotate all letters in the current buffer by 13 places.
3352 Used to encode/decode possibly offensive messages (commonly in rec.humor).
3353 With prefix arg, specifies the number of places to rotate each letter forward.
3354 Mail and USENET news headers are not rotated unless WIDE is non-nil."
3355 (interactive (if current-prefix-arg
3356 (list (prefix-numeric-value current-prefix-arg))
3360 (when (and (not wide) (message-goto-body))
3361 (narrow-to-region (point) (point-max)))
3362 (message-caesar-region (point-min) (point-max) rotnum))))
3364 (defun message-pipe-buffer-body (program)
3365 "Pipe the message body in the current buffer through PROGRAM."
3368 (when (message-goto-body)
3369 (narrow-to-region (point) (point-max)))
3370 (shell-command-on-region
3371 (point-min) (point-max) program nil t))))
3373 (defun message-rename-buffer (&optional enter-string)
3374 "Rename the *message* buffer to \"*message* RECIPIENT\".
3375 If the function is run with a prefix, it will ask for a new buffer
3376 name, rather than giving an automatic name."
3377 (interactive "Pbuffer name: ")
3380 (goto-char (point-min))
3381 (narrow-to-region (point)
3382 (search-forward mail-header-separator nil 'end))
3384 (if (message-news-p) (message-fetch-field "Newsgroups")
3385 (message-fetch-field "To"))
3388 (if (string-match "," mail-to)
3389 (concat (substring mail-to 0 (match-beginning 0)) ", ...")
3391 (name-default (concat "*message* " mail-trimmed-to))
3392 (name (if enter-string
3393 (read-string "New buffer name: " name-default)
3395 (rename-buffer name t)))))
3397 (defun message-fill-yanked-message (&optional justifyp)
3398 "Fill the paragraphs of a message yanked into this one.
3399 Numeric argument means justify as well."
3402 (goto-char (point-min))
3403 (search-forward (concat "\n" mail-header-separator "\n") nil t)
3404 (let ((fill-prefix message-yank-prefix))
3405 (fill-individual-paragraphs (point) (point-max) justifyp))))
3407 (defun message-indent-citation (&optional start end yank-only)
3408 "Modify text just inserted from a message to be cited.
3409 The inserted text should be the region.
3410 When this function returns, the region is again around the modified text.
3412 Normally, indent each nonblank line `message-indentation-spaces' spaces.
3413 However, if `message-yank-prefix' is non-nil, insert that prefix on each line."
3414 (unless start (setq start (point)))
3416 ;; Remove unwanted headers.
3417 (when message-ignored-cited-headers
3422 (if (search-forward "\n\n" nil t)
3425 (message-remove-header message-ignored-cited-headers t)
3426 (when (= (point-min) (point-max))
3427 (setq all-removed t))
3428 (goto-char (point-max)))
3432 ;; Delete blank lines at the start of the buffer.
3433 (while (and (point-min)
3436 (message-delete-line))
3437 ;; Delete blank lines at the end of the buffer.
3438 (goto-char (point-max))
3441 (while (and (zerop (forward-line -1))
3443 (message-delete-line)))
3444 ;; Do the indentation.
3445 (if (null message-yank-prefix)
3446 (indent-rigidly start (or end (mark t)) message-indentation-spaces)
3449 (while (< (point) (or end (mark t)))
3450 (cond ((looking-at ">")
3451 (insert message-yank-cited-prefix))
3453 (insert message-yank-empty-prefix))
3455 (insert message-yank-prefix)))
3459 (defvar message-cite-reply-above nil
3460 "If non-nil, start own text above the quote.
3462 Note: Top posting is bad netiquette. Don't use it unless you
3463 really must. You probably want to set variable only for specific
3464 groups, e.g. using `gnus-posting-styles':
3466 (eval (set (make-local-variable 'message-cite-reply-above) t))
3468 This variable has no effect in news postings.")
3470 (defun message-yank-original (&optional arg)
3471 "Insert the message being replied to, if any.
3472 Puts point before the text and mark after.
3473 Normally indents each nonblank line ARG spaces (default 3). However,
3474 if `message-yank-prefix' is non-nil, insert that prefix on each line.
3476 This function uses `message-cite-function' to do the actual citing.
3478 Just \\[universal-argument] as argument means don't indent, insert no
3479 prefix, and don't delete any headers."
3481 (let ((modified (buffer-modified-p))
3483 (when (and message-reply-buffer
3484 message-cite-function)
3485 (when message-cite-reply-above
3486 (if (and (not (message-news-p))
3487 (or (eq message-cite-reply-above 'is-evil)
3489 Top posting is bad netiquette. Please don't top post unless you really must.
3490 Really top post? ")))
3493 (buffer-substring (message-goto-body)
3495 (delete-region (message-goto-body) (point-max)))
3496 (set (make-local-variable 'message-cite-reply-above) nil)))
3497 (delete-windows-on message-reply-buffer t)
3498 (push-mark (save-excursion
3499 (insert-buffer-substring message-reply-buffer)
3502 (funcall message-cite-function))
3503 (if message-cite-reply-above
3509 (message-exchange-point-and-mark))
3510 (message-exchange-point-and-mark))
3514 (setq message-checksum (message-checksum))))))
3516 (defun message-yank-buffer (buffer)
3517 "Insert BUFFER into the current buffer and quote it."
3518 (interactive "bYank buffer: ")
3519 (let ((message-reply-buffer (get-buffer buffer)))
3520 (save-window-excursion
3521 (message-yank-original))))
3523 (defun message-buffers ()
3524 "Return a list of active message buffers."
3527 (dolist (buffer (buffer-list t))
3529 (when (and (eq major-mode 'message-mode)
3530 (null message-sent-message-via))
3531 (push (buffer-name buffer) buffers))))
3532 (nreverse buffers)))
3534 (eval-when-compile (defvar mail-citation-hook)) ; Compiler directive
3536 (defun message-cite-original-1 (strip-signature)
3537 "Cite an original message.
3538 If STRIP-SIGNATURE is non-nil, strips off the signature from the
3541 This function uses `mail-citation-hook' if that is non-nil."
3542 (if (and (boundp 'mail-citation-hook)
3544 (run-hooks 'mail-citation-hook)
3545 (let* ((start (point))
3549 (when message-indent-citation-function
3550 (if (listp message-indent-citation-function)
3551 message-indent-citation-function
3552 (list message-indent-citation-function))))
3553 ;; This function may be called by `gnus-summary-yank-message' and
3554 ;; may insert a different article from the original. So, we will
3555 ;; modify the value of `message-reply-headers' with that article.
3556 (message-reply-headers
3558 (narrow-to-region start end)
3559 (message-narrow-to-head-1)
3560 (setq x-no-archive (message-fetch-field "x-no-archive"))
3562 (or (message-fetch-field "subject") "none")
3563 (or (message-fetch-field "from") "nobody")
3564 (message-fetch-field "date")
3565 (message-fetch-field "message-id" t)
3566 (message-fetch-field "references")
3568 (mml-quote-region start end)
3569 (when strip-signature
3573 (when (re-search-backward message-signature-separator start t)
3574 ;; Also peel off any blank lines before the signature.
3576 (while (looking-at "^[ \t]*$")
3579 (delete-region (point) end)
3580 (unless (search-backward "\n\n" start t)
3581 ;; Insert a blank line if it is peeled off.
3584 (mapc 'funcall functions)
3585 (when message-citation-line-function
3588 (funcall message-citation-line-function))
3589 (when (and x-no-archive
3590 (not message-cite-articles-with-x-no-archive)
3591 (string-match "yes" x-no-archive))
3593 (delete-region (point) (mark t))
3594 (insert "> [Quoted text removed due to X-No-Archive]\n")
3596 (forward-line -1)))))
3598 (defun message-cite-original ()
3599 "Cite function in the standard Message manner."
3600 (message-cite-original-1 nil))
3602 (defun message-insert-formated-citation-line (&optional from date)
3603 "Function that inserts a formated citation line.
3605 See `message-citation-line-format'."
3606 ;; The optional args are for testing/debugging. They will disappear later.
3608 ;; (with-temp-buffer
3609 ;; (message-insert-formated-citation-line
3610 ;; "John Doe <john.doe@example.invalid>"
3613 (when (or message-reply-headers (and from date))
3615 (setq from (mail-header-from message-reply-headers)))
3616 (let* ((data (condition-case ()
3617 (funcall (if (boundp gnus-extract-address-components)
3618 gnus-extract-address-components
3619 'mail-extract-address-components)
3625 (net (car (cdr data)))
3626 (name-or-net (or (car data)
3627 (car (cdr data)) from))
3631 ;; We need Gnus functionality if the user wants date or time from
3632 ;; the original article:
3633 (when (string-match "%[^fnNFL]" message-citation-line-format)
3634 (autoload 'gnus-date-get-time "gnus-util")
3635 (gnus-date-get-time (mail-header-date message-reply-headers)))))
3638 (when (stringp name)
3639 ;; Guess first name and last name:
3640 (cond ((string-match
3641 "\\`\\(\\w\\|[-.]\\)+ \\(\\w\\|[-.]\\)+\\'" name)
3642 (setq fname (nth 0 (split-string name "[ \t]+"))
3643 lname (nth 1 (split-string name "[ \t]+"))))
3645 "\\`\\(\\w\\|[-.]\\)+, \\(\\w\\|[-.]\\)+\\'" name)
3646 (setq fname (nth 1 (split-string name "[ \t,]+"))
3647 lname (nth 0 (split-string name "[ \t,]+"))))
3649 "\\`\\(\\w\\|[-.]\\)+\\'" name)
3652 ;; The following letters are not used in `format-time-string':
3653 (push ?E lst) (push "<E>" lst)
3654 (push ?F lst) (push fname lst)
3655 ;; We might want to use "" instead of "<X>" later.
3656 (push ?J lst) (push "<J>" lst)
3657 (push ?K lst) (push "<K>" lst)
3658 (push ?L lst) (push lname lst)
3659 (push ?N lst) (push name-or-net lst)
3660 (push ?O lst) (push "<O>" lst)
3661 (push ?P lst) (push "<P>" lst)
3662 (push ?Q lst) (push "<Q>" lst)
3663 (push ?f lst) (push from lst)
3664 (push ?i lst) (push "<i>" lst)
3665 (push ?n lst) (push net lst)
3666 (push ?o lst) (push "<o>" lst)
3667 (push ?q lst) (push "<q>" lst)
3668 (push ?t lst) (push "<t>" lst)
3669 (push ?v lst) (push "<v>" lst)
3670 ;; Delegate the rest to `format-time-string':
3672 (when (and (not (memq i lst))
3677 (push (condition-case nil
3678 (progn (format-time-string (format "%%%c" i)
3684 (spec (apply 'format-spec-make flist)))
3685 (insert (format-spec message-citation-line-format spec)))
3689 (defun message-cite-original-without-signature ()
3690 "Cite function in the standard Message manner.
3691 This function strips off the signature from the original message."
3692 (message-cite-original-1 t))
3694 (defun message-insert-citation-line ()
3695 "Insert a simple citation line."
3696 (when message-reply-headers
3697 (insert (mail-header-from message-reply-headers) " writes:")
3701 (defun message-position-on-field (header &rest afters)
3702 (let ((case-fold-search t))
3705 (goto-char (point-min))
3708 (concat "^" (regexp-quote mail-header-separator) "$"))
3709 (match-beginning 0)))
3710 (goto-char (point-min))
3711 (if (re-search-forward (concat "^" (regexp-quote header) ":") nil t)
3713 (re-search-forward "^[^ \t]" nil 'move)
3715 (skip-chars-backward "\n")
3718 (not (re-search-forward
3719 (concat "^" (regexp-quote (car afters)) ":")
3723 (re-search-forward "^[^ \t]" nil 'move)
3724 (beginning-of-line))
3725 (insert header ": \n")
3729 (defun message-remove-signature ()
3730 "Remove the signature from the text between point and mark.
3731 The text will also be indented the normal way."
3733 (let ((start (point))
3735 (if (not (re-search-forward message-signature-separator (mark t) t))
3736 ;; No signature here, so we just indent the cited text.
3737 (message-indent-citation)
3738 ;; Find the last non-empty line.
3740 (while (looking-at "[ \t]*$")
3743 (setq mark (set-marker (make-marker) (point)))
3745 (message-indent-citation)
3746 ;; Enable undoing the deletion.
3748 (delete-region mark (mark t))
3749 (set-marker mark nil)))))
3754 ;;; Sending messages
3757 (defun message-send-and-exit (&optional arg)
3758 "Send message like `message-send', then, if no errors, exit from mail buffer."
3760 (let ((buf (current-buffer))
3761 (actions message-exit-actions))
3762 (when (and (message-send arg)
3764 (if message-kill-buffer-on-exit
3767 (when (eq buf (current-buffer))
3768 (message-bury buf)))
3769 (message-do-actions actions)
3772 (defun message-dont-send ()
3773 "Don't send the message you have been editing.
3774 Instead, just auto-save the buffer and then bury it."
3776 (set-buffer-modified-p t)
3778 (let ((actions message-postpone-actions))
3779 (message-bury (current-buffer))
3780 (message-do-actions actions)))
3782 (defun message-kill-buffer ()
3783 "Kill the current buffer."
3785 (when (or (not (buffer-modified-p))
3786 (not message-kill-buffer-query)
3787 (yes-or-no-p "Message modified; kill anyway? "))
3788 (let ((actions message-kill-actions)
3789 (draft-article message-draft-article)
3790 (auto-save-file-name buffer-auto-save-file-name)
3791 (file-name buffer-file-name)
3792 (modified (buffer-modified-p)))
3793 (setq buffer-file-name nil)
3794 (kill-buffer (current-buffer))
3795 (when (and (or (and auto-save-file-name
3796 (file-exists-p auto-save-file-name))
3798 (file-exists-p file-name)))
3800 ;; If the message buffer has lived in a dedicated window,
3801 ;; `kill-buffer' has killed the frame. Thus the
3802 ;; `yes-or-no-p' may show up in a lowered frame. Make sure
3803 ;; that the user can see the question by raising the
3806 (yes-or-no-p (format "Remove the backup file%s? "
3807 (if modified " too" "")))))
3809 (delete-file auto-save-file-name))
3810 (let ((message-draft-article draft-article))
3811 (message-disassociate-draft)))
3812 (message-do-actions actions))))
3814 (defun message-bury (buffer)
3815 "Bury this mail BUFFER."
3816 (let ((newbuf (other-buffer buffer)))
3817 (bury-buffer buffer)
3818 (if (and (window-dedicated-p (selected-window))
3819 (not (null (delq (selected-frame) (visible-frame-list)))))
3820 (delete-frame (selected-frame))
3821 (switch-to-buffer newbuf))))
3823 (defun message-send (&optional arg)
3824 "Send the message in the current buffer.
3825 If `message-interactive' is non-nil, wait for success indication or
3826 error messages, and inform user.
3827 Otherwise any failure is reported in a message back to the user from
3829 The usage of ARG is defined by the instance that called Message.
3830 It should typically alter the sending method in some way or other."
3832 ;; Make it possible to undo the coming changes.
3834 (let ((inhibit-read-only t))
3835 (put-text-property (point-min) (point-max) 'read-only nil))
3836 (message-fix-before-sending)
3837 (run-hooks 'message-send-hook)
3838 (message message-sending-message)
3839 (let ((alist message-send-method-alist)
3841 elem sent dont-barf-on-no-method
3842 (message-options message-options))
3843 (message-options-set-recipient)
3845 (setq elem (pop alist)))
3846 (when (funcall (cadr elem))
3847 (when (and (or (not (memq (car elem)
3848 message-sent-message-via))
3849 (message-fetch-field "supersedes")
3850 (if (or (message-gnksa-enable-p 'multiple-copies)
3851 (not (eq (car elem) 'news)))
3854 "Already sent message via %s; resend? "
3856 (error "Denied posting -- multiple copies")))
3857 (setq success (funcall (caddr elem) arg)))
3861 (let ((fcc (message-fetch-field "Fcc"))
3862 (gcc (message-fetch-field "Gcc")))
3864 (or (eq message-allow-no-recipients 'always)
3865 (and (not (eq message-allow-no-recipients 'never))
3866 (setq dont-barf-on-no-method
3868 (format "No receiver, perform %s anyway? "
3869 (cond ((and fcc gcc) "Fcc and Gcc")
3872 (error "No methods specified to send by"))
3873 (when (or dont-barf-on-no-method
3877 (run-hooks 'message-sent-hook))
3878 (message "Sending...done")
3879 ;; Do ecomplete address snarfing.
3880 (when (message-mail-alias-type-p 'ecomplete)
3881 (message-put-addresses-in-ecomplete))
3882 ;; Mark the buffer as unmodified and delete auto-save.
3883 (set-buffer-modified-p nil)
3884 (delete-auto-save-file-if-necessary t)
3885 (message-disassociate-draft)
3886 ;; Delete other mail buffers and stuff.
3887 (message-do-send-housekeeping)
3888 (message-do-actions message-send-actions)
3892 (defun message-send-via-mail (arg)
3893 "Send the current message via mail."
3894 (message-send-mail arg))
3896 (defun message-send-via-news (arg)
3897 "Send the current message via news."
3898 (funcall message-send-news-function arg))
3900 (defmacro message-check (type &rest forms)
3901 "Eval FORMS if TYPE is to be checked."
3902 `(or (message-check-element ,type)
3906 (put 'message-check 'lisp-indent-function 1)
3907 (put 'message-check 'edebug-form-spec '(form body))
3909 (defun message-text-with-property (prop &optional start end reverse)
3910 "Return a list of start and end positions where the text has PROP.
3911 START and END bound the search, they default to `point-min' and
3912 `point-max' respectively. If REVERSE is non-nil, find text which does
3915 (setq start (point-min)))
3917 (setq end (point-max)))
3921 (setq start (text-property-any start end prop nil)))
3922 (setq next (next-single-property-change start prop nil end))
3923 (push (cons start (or next end)) regions)
3926 (or (get-text-property start prop)
3927 (and (setq start (next-single-property-change
3928 start prop nil end))
3929 (get-text-property start prop))))
3930 (setq next (text-property-any start end prop nil))
3931 (push (cons start (or next end)) regions)
3933 (nreverse regions)))
3935 (defun message-fix-before-sending ()
3936 "Do various things to make the message nice before sending it."
3937 ;; Make sure there's a newline at the end of the message.
3938 (goto-char (point-max))
3941 ;; Make the hidden headers visible.
3943 ;; Sort headers before sending the message.
3944 (message-sort-headers)
3945 ;; Make invisible text visible.
3946 ;; It doesn't seem as if this is useful, since the invisible property
3947 ;; is clobbered by an after-change hook anyhow.
3948 (message-check 'invisible-text
3949 (let ((regions (message-text-with-property 'invisible))
3953 (setq from (caar regions)
3955 regions (cdr regions))
3956 (put-text-property from to 'invisible nil)
3957 (message-overlay-put (message-make-overlay from to)
3959 (unless (yes-or-no-p
3960 "Invisible text found and made visible; continue sending? ")
3961 (error "Invisible text found and made visible")))))
3962 (message-check 'illegible-text
3965 (skip-chars-forward mm-7bit-chars)
3967 (when (let ((char (char-after)))
3968 (or (< (mm-char-int char) 128)
3969 (and (mm-multibyte-p)
3970 (memq (char-charset char)
3971 '(eight-bit-control eight-bit-graphic
3973 (not (get-text-property
3974 (point) 'untranslated-utf-8)))))
3975 (message-overlay-put (message-make-overlay (point) (1+ (point)))
3979 (skip-chars-forward mm-7bit-chars))
3982 (gnus-multiple-choice
3983 "Non-printable characters found. Continue sending?"
3984 `((?d "Remove non-printable characters and send")
3986 "Replace non-printable characters with \"%s\" and send"
3987 message-replacement-char))
3988 (?i "Ignore non-printable characters and send")
3989 (?e "Continue editing"))))
3991 (error "Non-printable characters"))
3993 (skip-chars-forward mm-7bit-chars)
3995 (when (let ((char (char-after)))
3996 (or (< (mm-char-int char) 128)
3997 (and (mm-multibyte-p)
3998 ;; FIXME: Wrong for Emacs 23 (unicode) and for
3999 ;; things like undecable utf-8. Should at least
4000 ;; use find-coding-systems-region.
4001 (memq (char-charset char)
4002 '(eight-bit-control eight-bit-graphic
4004 (not (get-text-property
4005 (point) 'untranslated-utf-8)))))
4007 (message-kill-all-overlays)
4009 (when (eq choice ?r)
4010 (insert message-replacement-char))))
4012 (skip-chars-forward mm-7bit-chars))))))
4014 (defun message-add-action (action &rest types)
4015 "Add ACTION to be performed when doing an exit of type TYPES."
4017 (add-to-list (intern (format "message-%s-actions" (pop types)))
4020 (defun message-delete-action (action &rest types)
4021 "Delete ACTION from lists of actions performed when doing an exit of type TYPES."
4024 (set (setq var (intern (format "message-%s-actions" (pop types))))
4025 (delq action (symbol-value var))))))
4027 (defun message-do-actions (actions)
4028 "Perform all actions in ACTIONS."
4029 ;; Now perform actions on successful sending.
4030 (dolist (action actions)
4033 ;; A simple function.
4036 ;; Something to be evaled.
4040 (defun message-send-mail-partially ()
4041 "Send mail as message/partial."
4042 ;; replace the header delimiter with a blank line
4043 (goto-char (point-min))
4045 (concat "^" (regexp-quote mail-header-separator) "\n"))
4046 (replace-match "\n")
4047 (run-hooks 'message-send-mail-hook)
4048 (let ((p (goto-char (point-min)))
4049 (tembuf (message-generate-new-buffer-clone-locals " message temp"))
4050 (curbuf (current-buffer))
4051 (id (message-make-message-id)) (n 1)
4052 plist total header required-mail-headers)
4054 (if (< (point-max) (+ p message-send-mail-partially-limit))
4055 (goto-char (point-max))
4056 (goto-char (+ p message-send-mail-partially-limit))
4058 (if (<= (point) p) (forward-line 1))) ;; In case of bad message.
4061 (setq total (length plist))
4062 (push (point-max) plist)
4063 (setq plist (nreverse plist))
4066 (setq p (pop plist))
4069 (copy-to-buffer tembuf p (car plist))
4071 (goto-char (point-min))
4074 (goto-char (point-min))
4075 (narrow-to-region (point) (point))
4078 (setq header (buffer-substring (point-min) (point)))
4079 (goto-char (point-min))
4080 (narrow-to-region (point) (point))
4082 (message-remove-header "Mime-Version")
4083 (message-remove-header "Content-Type")
4084 (message-remove-header "Content-Transfer-Encoding")
4085 (message-remove-header "Message-ID")
4086 (message-remove-header "Lines")
4087 (goto-char (point-max))
4088 (insert "Mime-Version: 1.0\n")
4089 (setq header (buffer-string)))
4090 (goto-char (point-max))
4091 (insert (format "Content-Type: message/partial; id=\"%s\"; number=%d; total=%d\n\n"
4094 (let ((mail-header-separator ""))
4095 (when (memq 'Message-ID message-required-mail-headers)
4096 (insert "Message-ID: " (message-make-message-id) "\n"))
4097 (when (memq 'Lines message-required-mail-headers)
4098 (insert "Lines: " (message-make-lines) "\n"))
4099 (message-goto-subject)
4101 (insert (format " (%d/%d)" n total))
4103 (mm-with-unibyte-current-buffer
4104 (funcall (or message-send-mail-real-function
4105 message-send-mail-function))))
4107 (setq p (pop plist))
4109 (kill-buffer tembuf))))
4111 (defun message-send-mail (&optional arg)
4112 (require 'mail-utils)
4113 (let* ((tembuf (message-generate-new-buffer-clone-locals " message temp"))
4114 (case-fold-search nil)
4115 (news (message-news-p))
4116 (mailbuf (current-buffer))
4117 (message-this-is-mail t)
4118 (message-posting-charset
4119 (if (fboundp 'gnus-setup-posting-charset)
4120 (gnus-setup-posting-charset nil)
4121 message-posting-charset))
4122 (headers message-required-mail-headers))
4123 (when message-generate-hashcash
4124 (message "Generating hashcash...")
4125 ;; Wait for calculations already started to finish...
4126 (hashcash-wait-async)
4127 ;; ...and do calculations not already done. mail-add-payment
4128 ;; will leave existing X-Hashcash headers alone.
4130 (message "Generating hashcash...done"))
4132 (message-narrow-to-headers)
4133 ;; Generate the Mail-Followup-To header if the header is not there...
4134 (if (and (message-subscribed-p)
4135 (not (mail-fetch-field "mail-followup-to")))
4138 (cons "Mail-Followup-To" (message-make-mail-followup-to))
4139 message-required-mail-headers))
4140 ;; otherwise, delete the MFT header if the field is empty
4141 (when (equal "" (mail-fetch-field "mail-followup-to"))
4142 (message-remove-header "^Mail-Followup-To:")))
4143 ;; Insert some headers.
4144 (let ((message-deletable-headers
4145 (if news nil message-deletable-headers)))
4146 (message-generate-headers headers))
4147 ;; Check continuation headers.
4148 (message-check 'continuation-headers
4149 (goto-char (point-min))
4150 (while (re-search-forward "^[^ \t\n][^ \t\n:]*[ \t\n]" nil t)
4151 (goto-char (match-beginning 0))
4152 (if (y-or-n-p "Fix continuation lines? ")
4155 (unless (y-or-n-p "Send anyway? ")
4156 (error "Failed to send the message")))))
4157 ;; Let the user do all of the above.
4158 (run-hooks 'message-header-hook))
4163 ;; Avoid copying text props (except hard newlines).
4164 (insert (with-current-buffer mailbuf
4165 (mml-buffer-substring-no-properties-except-hard-newlines
4166 (point-min) (point-max))))
4167 ;; Remove some headers.
4168 (message-encode-message-body)
4170 (message-narrow-to-headers)
4171 ;; We (re)generate the Lines header.
4172 (when (memq 'Lines message-required-mail-headers)
4173 (message-generate-headers '(Lines)))
4174 ;; Remove some headers.
4175 (message-remove-header message-ignored-mail-headers t)
4176 (let ((mail-parse-charset message-default-charset))
4177 (mail-encode-encoded-word-buffer)))
4178 (goto-char (point-max))
4179 ;; require one newline at the end.
4180 (or (= (preceding-char) ?\n)
4182 (message-cleanup-headers)
4183 ;; FIXME: we're inserting the courtesy copy after encoding.
4184 ;; This is wrong if the courtesy copy string contains
4185 ;; non-ASCII characters. -- jh
4188 (message-narrow-to-headers)
4190 (or (message-fetch-field "cc")
4191 (message-fetch-field "bcc")
4192 (message-fetch-field "to"))
4193 (let ((content-type (message-fetch-field
4198 (string= "text/plain"
4200 (mail-header-parse-content-type
4204 (message-fetch-field
4205 "content-transfer-encoding")))))))
4206 (message-insert-courtesy-copy))
4207 (if (or (not message-send-mail-partially-limit)
4208 (< (buffer-size) message-send-mail-partially-limit)
4209 (not (message-y-or-n-p
4210 "The message size is too large, split? "
4214 (/ (buffer-size) 1000) "KB, is too large.
4216 Some mail gateways (MTA's) bounce large messages. To avoid the
4217 problem, answer `y', and the message will be split into several
4218 smaller pieces, the size of each is about "
4219 (/ message-send-mail-partially-limit 1000)
4223 However, some mail readers (MUA's) can't read split messages, i.e.,
4224 mails in message/partially format. Answer `n', and the message will be
4227 The size limit is controlled by `message-send-mail-partially-limit'.
4228 If you always want Gnus to send messages in one piece, set
4229 `message-send-mail-partially-limit' to nil.
4231 (mm-with-unibyte-current-buffer
4232 (message "Sending via mail...")
4233 (funcall (or message-send-mail-real-function
4234 message-send-mail-function)))
4235 (message-send-mail-partially)))
4236 (kill-buffer tembuf))
4237 (set-buffer mailbuf)
4238 (push 'mail message-sent-message-via)))
4240 (defun message-send-mail-with-sendmail ()
4241 "Send off the prepared buffer with sendmail."
4242 (let ((errbuf (if message-interactive
4243 (message-generate-new-buffer-clone-locals
4246 resend-to-addresses delimline)
4249 (let ((case-fold-search t))
4251 (message-narrow-to-headers)
4252 (setq resend-to-addresses (message-fetch-field "resent-to")))
4253 ;; Change header-delimiter to be what sendmail expects.
4254 (goto-char (point-min))
4256 (concat "^" (regexp-quote mail-header-separator) "\n"))
4257 (replace-match "\n")
4259 (setq delimline (point-marker))
4260 (run-hooks 'message-send-mail-hook)
4261 ;; Insert an extra newline if we need it to work around
4262 ;; Sun's bug that swallows newlines.
4263 (goto-char (1+ delimline))
4264 (when (eval message-mailer-swallows-blank-line)
4266 (when message-interactive
4267 (with-current-buffer errbuf
4269 (let* ((default-directory "/")
4270 (coding-system-for-write message-send-coding-system)
4272 'call-process-region
4274 (list (point-min) (point-max)
4275 (cond ((boundp 'sendmail-program)
4277 ((file-exists-p "/usr/sbin/sendmail")
4278 "/usr/sbin/sendmail")
4279 ((file-exists-p "/usr/lib/sendmail")
4280 "/usr/lib/sendmail")
4281 ((file-exists-p "/usr/ucblib/sendmail")
4282 "/usr/ucblib/sendmail")
4284 nil errbuf nil "-oi")
4285 ;; Always specify who from,
4286 ;; since some systems have broken sendmails.
4287 ;; But some systems are more broken with -f, so
4288 ;; we'll let users override this.
4289 (if (null message-sendmail-f-is-evil)
4290 (list "-f" (message-sendmail-envelope-from)))
4291 ;; These mean "report errors by mail"
4292 ;; and "deliver in background".
4293 (if (null message-interactive) '("-oem" "-odb"))
4294 ;; Get the addresses from the message
4295 ;; unless this is a resend.
4296 ;; We must not do that for a resend
4297 ;; because we would find the original addresses.
4298 ;; For a resend, include the specific addresses.
4299 (if resend-to-addresses
4300 (list resend-to-addresses)
4302 (unless (or (null cpr) (and (numberp cpr) (zerop cpr)))
4303 (error "Sending...failed with exit value %d" cpr)))
4304 (when message-interactive
4307 (goto-char (point-min))
4308 (while (re-search-forward "\n+ *" nil t)
4309 (replace-match "; "))
4310 (if (not (zerop (buffer-size)))
4311 (error "Sending...failed to %s"
4312 (buffer-string))))))
4313 (when (bufferp errbuf)
4314 (kill-buffer errbuf)))))
4316 (defun message-send-mail-with-qmail ()
4317 "Pass the prepared message buffer to qmail-inject.
4318 Refer to the documentation for the variable `message-send-mail-function'
4319 to find out how to use this."
4320 ;; replace the header delimiter with a blank line
4321 (goto-char (point-min))
4323 (concat "^" (regexp-quote mail-header-separator) "\n"))
4324 (replace-match "\n")
4325 (run-hooks 'message-send-mail-hook)
4328 (let ((coding-system-for-write message-send-coding-system))
4330 'call-process-region (point-min) (point-max)
4331 message-qmail-inject-program nil nil nil
4332 ;; qmail-inject's default behaviour is to look for addresses on the
4333 ;; command line; if there're none, it scans the headers.
4334 ;; yes, it does The Right Thing w.r.t. Resent-To and it's kin.
4336 ;; in general, ALL of qmail-inject's defaults are perfect for simply
4337 ;; reading a formatted (i. e., at least a To: or Resent-To header)
4338 ;; message from stdin.
4340 ;; qmail also has the advantage of not having been raped by
4341 ;; various vendors, so we don't have to allow for that, either --
4342 ;; compare this with message-send-mail-with-sendmail and weep
4343 ;; for sendmail's lost innocence.
4345 ;; all this is way cool coz it lets us keep the arguments entirely
4346 ;; free for -inject-arguments -- a big win for the user and for us
4347 ;; since we don't have to play that double-guessing game and the user
4348 ;; gets full control (no gestapo'ish -f's, for instance). --sj
4349 (if (functionp message-qmail-inject-args)
4350 (funcall message-qmail-inject-args)
4351 message-qmail-inject-args)))
4352 ;; qmail-inject doesn't say anything on it's stdout/stderr,
4353 ;; we have to look at the retval instead
4355 (100 (error "qmail-inject reported permanent failure"))
4356 (111 (error "qmail-inject reported transient failure"))
4357 ;; should never happen
4358 (t (error "qmail-inject reported unknown failure"))))
4360 (defun message-send-mail-with-mh ()
4361 "Send the prepared message buffer with mh."
4362 (let ((mh-previous-window-config nil)
4363 (name (mh-new-draft-name)))
4364 (setq buffer-file-name name)
4365 ;; MH wants to generate these headers itself.
4366 (when message-mh-deletable-headers
4367 (let ((headers message-mh-deletable-headers))
4369 (goto-char (point-min))
4370 (and (re-search-forward
4371 (concat "^" (symbol-name (car headers)) ": *") nil t)
4372 (message-delete-line))
4374 (run-hooks 'message-send-mail-hook)
4375 ;; Pass it on to mh.
4378 (defun message-smtpmail-send-it ()
4379 "Send the prepared message buffer with `smtpmail-send-it'.
4380 This only differs from `smtpmail-send-it' that this command evaluates
4381 `message-send-mail-hook' just before sending a message. It is useful
4382 if your ISP requires the POP-before-SMTP authentication. See the Gnus
4383 manual for details."
4384 (run-hooks 'message-send-mail-hook)
4387 (defun message-canlock-generate ()
4388 "Return a string that is non-trivial to guess.
4389 Do not use this for anything important, it is cryptographically weak."
4391 (let (sha1-maximum-internal-length)
4392 (sha1 (concat (message-unique-id)
4393 (format "%x%x%x" (random) (random t) (random))
4394 (prin1-to-string (recent-keys))
4395 (prin1-to-string (garbage-collect))))))
4397 (defun message-canlock-password ()
4398 "The password used by message for cancel locks.
4399 This is the value of `canlock-password', if that option is non-nil.
4400 Otherwise, generate and save a value for `canlock-password' first."
4401 (unless canlock-password
4402 (customize-save-variable 'canlock-password (message-canlock-generate))
4403 (setq canlock-password-for-verify canlock-password))
4406 (defun message-insert-canlock ()
4407 (when message-insert-canlock
4408 (message-canlock-password)
4409 (canlock-insert-header)))
4411 (defun message-send-news (&optional arg)
4412 (let* ((tembuf (message-generate-new-buffer-clone-locals " *message temp*"))
4413 (case-fold-search nil)
4414 (method (if (functionp message-post-method)
4415 (funcall message-post-method arg)
4416 message-post-method))
4417 (newsgroups-field (save-restriction
4418 (message-narrow-to-headers-or-head)
4419 (message-fetch-field "Newsgroups")))
4420 (followup-field (save-restriction
4421 (message-narrow-to-headers-or-head)
4422 (message-fetch-field "Followup-To")))
4423 ;; BUG: We really need to get the charset for each name in the
4424 ;; Newsgroups and Followup-To lines to allow crossposting
4425 ;; between group namess with incompatible character sets.
4426 ;; -- Per Abrahamsen <abraham@dina.kvl.dk> 2001-10-08.
4427 (group-field-charset
4428 (gnus-group-name-charset method newsgroups-field))
4429 (followup-field-charset
4430 (gnus-group-name-charset method (or followup-field "")))
4431 (rfc2047-header-encoding-alist
4432 (append (when group-field-charset
4433 (list (cons "Newsgroups" group-field-charset)))
4434 (when followup-field-charset
4435 (list (cons "Followup-To" followup-field-charset)))
4436 rfc2047-header-encoding-alist))
4437 (messbuf (current-buffer))
4438 (message-syntax-checks
4440 (listp message-syntax-checks))
4441 (cons '(existing-newsgroups . disabled)
4442 message-syntax-checks)
4443 message-syntax-checks))
4444 (message-this-is-news t)
4445 (message-posting-charset
4446 (gnus-setup-posting-charset newsgroups-field))
4448 (if (not (message-check-news-body-syntax))
4451 (message-narrow-to-headers)
4452 ;; Insert some headers.
4453 (message-generate-headers message-required-news-headers)
4454 (message-insert-canlock)
4455 ;; Let the user do all of the above.
4456 (run-hooks 'message-header-hook))
4457 ;; Note: This check will be disabled by the ".*" default value for
4458 ;; gnus-group-name-charset-group-alist. -- Pa 2001-10-07.
4459 (when (and group-field-charset
4460 (listp message-syntax-checks))
4461 (setq message-syntax-checks
4462 (cons '(valid-newsgroups . disabled)
4463 message-syntax-checks)))
4464 (message-cleanup-headers)
4465 (if (not (let ((message-post-method method))
4466 (message-check-news-syntax)))
4471 (buffer-disable-undo)
4473 ;; Avoid copying text props (except hard newlines).
4475 (with-current-buffer messbuf
4476 (mml-buffer-substring-no-properties-except-hard-newlines
4477 (point-min) (point-max))))
4478 (message-encode-message-body)
4479 ;; Remove some headers.
4481 (message-narrow-to-headers)
4482 ;; We (re)generate the Lines header.
4483 (when (memq 'Lines message-required-mail-headers)
4484 (message-generate-headers '(Lines)))
4485 ;; Remove some headers.
4486 (message-remove-header message-ignored-news-headers t)
4487 (let ((mail-parse-charset message-default-charset))
4488 (mail-encode-encoded-word-buffer)))
4489 (goto-char (point-max))
4490 ;; require one newline at the end.
4491 (or (= (preceding-char) ?\n)
4493 (let ((case-fold-search t))
4494 ;; Remove the delimiter.
4495 (goto-char (point-min))
4497 (concat "^" (regexp-quote mail-header-separator) "\n"))
4498 (replace-match "\n")
4500 (run-hooks 'message-send-news-hook)
4501 (gnus-open-server method)
4502 (message "Sending news via %s..." (gnus-server-string method))
4503 (setq result (let ((mail-header-separator ""))
4504 (gnus-request-post method))))
4505 (kill-buffer tembuf))
4506 (set-buffer messbuf)
4508 (push 'news message-sent-message-via)
4509 (message "Couldn't send message via news: %s"
4510 (nnheader-get-report (car method)))
4514 ;;; Header generation & syntax checking.
4517 (defun message-check-element (type)
4518 "Return non-nil if this TYPE is not to be checked."
4519 (if (eq message-syntax-checks 'dont-check-for-anything-just-trust-me)
4521 (let ((able (assq type message-syntax-checks)))
4523 (eq (cdr able) 'disabled)))))
4525 (defun message-check-news-syntax ()
4526 "Check the syntax of the message."
4530 ;; We narrow to the headers and check them first.
4533 (message-narrow-to-headers)
4534 (message-check-news-header-syntax))))))
4536 (defun message-check-news-header-syntax ()
4538 ;; Check Newsgroups header.
4539 (message-check 'newsgroups
4540 (let ((group (message-fetch-field "newsgroups")))
4543 (not (string-match "\\`[ \t]*\\'" group)))
4546 "The newsgroups field is empty or missing. Posting is denied.")))))
4547 ;; Check the Subject header.
4548 (message-check 'subject
4549 (let* ((case-fold-search t)
4550 (subject (message-fetch-field "subject")))
4553 (not (string-match "\\`[ \t]*\\'" subject)))
4556 "The subject field is empty or missing. Posting is denied.")))))
4557 ;; Check for commands in Subject.
4558 (message-check 'subject-cmsg
4559 (if (string-match "^cmsg " (message-fetch-field "subject"))
4561 "The control code \"cmsg\" is in the subject. Really post? ")
4563 ;; Check long header lines.
4564 (message-check 'long-header-lines
4565 (let ((start (point))
4569 (while (and (not found)
4570 (re-search-forward "^\\([^ \t:]+\\): " nil t))
4571 (if (> (- (point) (match-beginning 0)) 998)
4573 length (- (point) (match-beginning 0)))
4574 (setq header (match-string-no-properties 1)))
4575 (setq start (match-beginning 0))
4578 (y-or-n-p (format "Your %s header is too long (%d). Really post? "
4581 ;; Check for multiple identical headers.
4582 (message-check 'multiple-headers
4584 (while (and (not found)
4585 (re-search-forward "^[^ \t:]+: " nil t))
4587 (or (re-search-forward
4592 (match-beginning 0) (- (match-end 0) 2))))
4597 (y-or-n-p (format "Multiple %s headers. Really post? " found))
4599 ;; Check for Version and Sendsys.
4600 (message-check 'sendsys
4601 (if (re-search-forward "^Sendsys:\\|^Version:" nil t)
4603 (format "The article contains a %s command. Really post? "
4604 (buffer-substring (match-beginning 0)
4605 (1- (match-end 0)))))
4607 ;; See whether we can shorten Followup-To.
4608 (message-check 'shorten-followup-to
4609 (let ((newsgroups (message-fetch-field "newsgroups"))
4610 (followup-to (message-fetch-field "followup-to"))
4612 (when (and newsgroups
4613 (string-match "," newsgroups)
4618 (setq to (completing-read
4619 "Followups to (default no Followup-To header): "
4622 (message-tokenize-header
4624 (goto-char (point-min))
4625 (insert "Followup-To: " to "\n"))
4627 ;; Check "Shoot me".
4628 (message-check 'shoot
4629 (if (re-search-forward
4630 "Message-ID.*.i-did-not-set--mail-host-address--so-tickle-me" nil t)
4631 (y-or-n-p "You appear to have a misconfigured system. Really post? ")
4633 ;; Check for Approved.
4634 (message-check 'approved
4635 (if (re-search-forward "^Approved:" nil t)
4636 (y-or-n-p "The article contains an Approved header. Really post? ")
4638 ;; Check the Message-ID header.
4639 (message-check 'message-id
4640 (let* ((case-fold-search t)
4641 (message-id (message-fetch-field "message-id" t)))
4642 (or (not message-id)
4643 ;; Is there an @ in the ID?
4644 (and (string-match "@" message-id)
4645 ;; Is there a dot in the ID?
4646 (string-match "@[^.]*\\." message-id)
4647 ;; Does the ID end with a dot?
4648 (not (string-match "\\.>" message-id)))
4650 (format "The Message-ID looks strange: \"%s\". Really post? "
4652 ;; Check the Newsgroups & Followup-To headers.
4653 (message-check 'existing-newsgroups
4654 (let* ((case-fold-search t)
4655 (newsgroups (message-fetch-field "newsgroups"))
4656 (followup-to (message-fetch-field "followup-to"))
4657 (groups (message-tokenize-header
4659 (concat newsgroups "," followup-to)
4661 (post-method (if (functionp message-post-method)
4662 (funcall message-post-method)
4663 message-post-method))
4664 ;; KLUDGE to handle nnvirtual groups. Doing this right
4665 ;; would probably involve a new nnoo function.
4666 ;; -- Per Abrahamsen <abraham@dina.kvl.dk>, 2001-10-17.
4667 (method (if (and (consp post-method)
4668 (eq (car post-method) 'nnvirtual)
4669 gnus-message-group-art)
4670 (let ((group (car (nnvirtual-find-group-art
4671 (car gnus-message-group-art)
4672 (cdr gnus-message-group-art)))))
4673 (gnus-find-method-for-group group))
4677 (gnus-group-name-decode
4678 (gnus-group-real-name n)
4679 (gnus-group-name-charset method n)))
4680 (gnus-groups-from-server method)))
4683 (when (and (not (equal (car groups) "poster"))
4684 (not (member (car groups) known-groups))
4685 (not (member (car groups) errors)))
4686 (push (car groups) errors))
4689 ;; Gnus is not running.
4690 ((or (not (and (boundp 'gnus-active-hashtb)
4691 gnus-active-hashtb))
4692 (not (boundp 'gnus-read-active-file)))
4694 ;; We don't have all the group names.
4695 ((and (or (not gnus-read-active-file)
4696 (eq gnus-read-active-file 'some))
4700 "Really use %s possibly unknown group%s: %s? "
4701 (if (= (length errors) 1) "this" "these")
4702 (if (= (length errors) 1) "" "s")
4703 (mapconcat 'identity errors ", "))))
4704 ;; There were no errors.
4707 ;; There are unknown groups.
4711 "Really post to %s unknown group%s: %s? "
4712 (if (= (length errors) 1) "this" "these")
4713 (if (= (length errors) 1) "" "s")
4714 (mapconcat 'identity errors ", ")))))))
4715 ;; Check continuation headers.
4716 (message-check 'continuation-headers
4717 (goto-char (point-min))
4718 (let ((do-posting t))
4719 (while (re-search-forward "^[^ \t\n][^ \t\n:]*[ \t\n]" nil t)
4720 (goto-char (match-beginning 0))
4721 (if (y-or-n-p "Fix continuation lines? ")
4724 (unless (y-or-n-p "Send anyway? ")
4725 (setq do-posting nil))))
4727 ;; Check the Newsgroups & Followup-To headers for syntax errors.
4728 (message-check 'valid-newsgroups
4729 (let ((case-fold-search t)
4730 (headers '("Newsgroups" "Followup-To"))
4732 (while (and headers (not error))
4733 (when (setq header (mail-fetch-field (car headers)))
4737 "\\`\\([-+_&.a-zA-Z0-9]+\\)?\\(,[-+_&.a-zA-Z0-9]+\\)*\\'"
4742 (not (string-match "\\.\\'\\|\\.\\." g)))
4743 (message-tokenize-header header ","))))
4750 (format "The %s header looks odd: \"%s\". Really post? "
4751 (car headers) header)))))
4752 (message-check 'repeated-newsgroups
4753 (let ((case-fold-search t)
4754 (headers '("Newsgroups" "Followup-To"))
4755 header error groups group)
4758 (when (setq header (mail-fetch-field (pop headers)))
4759 (setq groups (message-tokenize-header header ","))
4760 (while (setq group (pop groups))
4761 (when (member group groups)
4767 (format "Group %s is repeated in headers. Really post? " error)))))
4768 ;; Check the From header.
4769 (message-check 'from
4770 (let* ((case-fold-search t)
4771 (from (message-fetch-field "from"))
4775 (message "There is no From line. Posting is denied.")
4777 ((or (not (string-match
4779 (setq ad (nth 1 (mail-extract-address-components
4780 from))))) ;larsi@ifi
4781 (string-match "\\.\\." ad) ;larsi@ifi..uio
4782 (string-match "@\\." ad) ;larsi@.ifi.uio
4783 (string-match "\\.$" ad) ;larsi@ifi.uio.
4784 (not (string-match "^[^@]+@[^@]+$" ad)) ;larsi.ifi.uio
4785 (string-match "(.*).*(.*)" from)) ;(lars) (lars)
4787 "Denied posting -- the From looks strange: \"%s\"." from)
4789 ((let ((addresses (rfc822-addresses from)))
4790 (while (and addresses
4791 (not (eq (string-to-char (car addresses)) ?\()))
4792 (setq addresses (cdr addresses)))
4795 "Denied posting -- bad From address: \"%s\"." from)
4798 ;; Check the Reply-To header.
4799 (message-check 'reply-to
4800 (let* ((case-fold-search t)
4801 (reply-to (message-fetch-field "reply-to"))
4806 ((string-match "," reply-to)
4808 (format "Multiple Reply-To addresses: \"%s\". Really post? "
4810 ((or (not (string-match
4812 (setq ad (nth 1 (mail-extract-address-components
4813 reply-to))))) ;larsi@ifi
4814 (string-match "\\.\\." ad) ;larsi@ifi..uio
4815 (string-match "@\\." ad) ;larsi@.ifi.uio
4816 (string-match "\\.$" ad) ;larsi@ifi.uio.
4817 (not (string-match "^[^@]+@[^@]+$" ad)) ;larsi.ifi.uio
4818 (string-match "(.*).*(.*)" reply-to)) ;(lars) (lars)
4821 "The Reply-To looks strange: \"%s\". Really post? "
4825 (defun message-check-news-body-syntax ()
4827 ;; Check for long lines.
4828 (message-check 'long-lines
4829 (goto-char (point-min))
4831 (concat "^" (regexp-quote mail-header-separator) "$"))
4835 "<#\\(/\\)?\\(multipart\\|part\\|external\\|mml\\)")
4838 (< (- (point) p) 80)))
4839 (zerop (forward-line 1))))
4843 "You have lines longer than 79 characters. Really post? ")))
4844 ;; Check whether the article is empty.
4845 (message-check 'empty
4846 (goto-char (point-min))
4848 (concat "^" (regexp-quote mail-header-separator) "$"))
4851 (goto-char (point-max))
4852 (re-search-backward message-signature-separator nil t)
4854 (or (re-search-backward "[^ \n\t]" b t)
4855 (if (message-gnksa-enable-p 'empty-article)
4856 (y-or-n-p "Empty article. Really post? ")
4857 (message "Denied posting -- Empty article.")
4859 ;; Check for control characters.
4860 (message-check 'control-chars
4861 (if (re-search-forward
4862 (mm-string-as-multibyte "[\000-\007\013\015-\032\034-\037\200-\237]")
4865 "The article contains control characters. Really post? ")
4867 ;; Check excessive size.
4868 (message-check 'size
4869 (if (> (buffer-size) 60000)
4871 (format "The article is %d octets long. Really post? "
4874 ;; Check whether any new text has been added.
4875 (message-check 'new-text
4877 (not message-checksum)
4878 (not (eq (message-checksum) message-checksum))
4879 (if (message-gnksa-enable-p 'quoted-text-only)
4881 "It looks like no new text has been added. Really post? ")
4882 (message "Denied posting -- no new text has been added.")
4884 ;; Check the length of the signature.
4885 (message-check 'signature
4886 (goto-char (point-max))
4887 (if (> (count-lines (point) (point-max)) 5)
4890 "Your .sig is %d lines; it should be max 4. Really post? "
4891 (1- (count-lines (point) (point-max)))))
4893 ;; Ensure that text follows last quoted portion.
4894 (message-check 'quoting-style
4895 (goto-char (point-max))
4896 (let ((no-problem t))
4897 (when (search-backward-regexp "^>[^\n]*\n" nil t)
4898 (setq no-problem (search-forward-regexp "^[ \t]*[^>\n]" nil t)))
4901 (if (message-gnksa-enable-p 'quoted-text-only)
4902 (y-or-n-p "Your text should follow quoted text. Really post? ")
4904 (goto-char (point-min))
4906 (concat "^" (regexp-quote mail-header-separator) "$"))
4907 (if (search-forward-regexp "^[ \t]*[^>\n]" nil t)
4908 (y-or-n-p "Your text should follow quoted text. Really post? ")
4909 (message "Denied posting -- only quoted text.")
4912 (defun message-checksum ()
4913 "Return a \"checksum\" for the current buffer."
4916 (goto-char (point-min))
4918 (concat "^" (regexp-quote mail-header-separator) "$"))
4920 (when (not (looking-at "[ \t\n]"))
4921 (setq sum (logxor (ash sum 1) (if (natnump sum) 0 1)
4926 (defun message-do-fcc ()
4927 "Process Fcc headers in the current buffer."
4928 (let ((case-fold-search t)
4929 (buf (current-buffer))
4931 (mml-externalize-attachments message-fcc-externalize-attachments))
4934 (message-narrow-to-headers)
4935 (setq file (message-fetch-field "fcc" t)))
4937 (set-buffer (get-buffer-create " *message temp*"))
4939 (insert-buffer-substring buf)
4940 (message-encode-message-body)
4942 (message-narrow-to-headers)
4943 (while (setq file (message-fetch-field "fcc" t))
4945 (message-remove-header "fcc" nil t))
4946 (let ((mail-parse-charset message-default-charset)
4947 (rfc2047-header-encoding-alist
4948 (cons '("Newsgroups" . default)
4949 rfc2047-header-encoding-alist)))
4950 (mail-encode-encoded-word-buffer)))
4951 (goto-char (point-min))
4952 (when (re-search-forward
4953 (concat "^" (regexp-quote mail-header-separator) "$")
4955 (replace-match "" t t ))
4956 ;; Process FCC operations.
4958 (setq file (pop list))
4959 (if (string-match "^[ \t]*|[ \t]*\\(.*\\)[ \t]*$" file)
4960 ;; Pipe the article to the program in question.
4961 (call-process-region (point-min) (point-max) shell-file-name
4962 nil nil nil shell-command-switch
4963 (match-string 1 file))
4964 ;; Save the article.
4965 (setq file (expand-file-name file))
4966 (unless (file-exists-p (file-name-directory file))
4967 (make-directory (file-name-directory file) t))
4968 (if (and message-fcc-handler-function
4969 (not (eq message-fcc-handler-function 'rmail-output)))
4970 (funcall message-fcc-handler-function file)
4971 (if (and (file-readable-p file) (mail-file-babyl-p file))
4972 (rmail-output file 1 nil t)
4973 (let ((mail-use-rfc822 t))
4974 (rmail-output file 1 t t))))))
4975 (kill-buffer (current-buffer))))))
4977 (defun message-output (filename)
4978 "Append this article to Unix/babyl mail file FILENAME."
4979 (if (and (file-readable-p filename)
4980 (mail-file-babyl-p filename))
4981 (gnus-output-to-rmail filename t)
4982 (gnus-output-to-mail filename t)))
4984 (defun message-cleanup-headers ()
4985 "Do various automatic cleanups of the headers."
4986 ;; Remove empty lines in the header.
4988 (message-narrow-to-headers)
4989 ;; Remove blank lines.
4990 (while (re-search-forward "^[ \t]*\n" nil t)
4991 (replace-match "" t t))
4993 ;; Correct Newsgroups and Followup-To headers: Change sequence of
4994 ;; spaces to comma and eliminate spaces around commas. Eliminate
4995 ;; embedded line breaks.
4996 (goto-char (point-min))
4997 (while (re-search-forward "^\\(Newsgroups\\|Followup-To\\): +" nil t)
5001 (if (re-search-forward "^[^ \t]" nil t)
5005 (goto-char (point-min))
5006 (while (re-search-forward "\n[ \t]+" nil t)
5007 (replace-match " " t t)) ;No line breaks (too confusing)
5008 (goto-char (point-min))
5009 (while (re-search-forward "[ \t\n]*,[ \t\n]*\\|[ \t]+" nil t)
5010 (replace-match "," t t))
5011 (goto-char (point-min))
5012 ;; Remove trailing commas.
5013 (when (re-search-forward ",+$" nil t)
5014 (replace-match "" t t))))))
5016 (defun message-make-date (&optional now)
5017 "Make a valid data header.
5018 If NOW, use that time instead."
5019 (let ((system-time-locale "C"))
5020 (format-time-string "%a, %d %b %Y %T %z" now)))
5022 (defun message-insert-expires (days)
5023 "Insert the Expires header. Expiry in DAYS days."
5024 (interactive "NExpire article in how many days? ")
5026 (message-position-on-field "Expires" "X-Draft-From")
5027 (insert (message-make-expires-date days))))
5029 (defun message-make-expires-date (days)
5030 "Make date string for the Expires header. Expiry in DAYS days.
5032 In posting styles use `(\"Expires\" (make-expires-date 30))'."
5033 (let* ((cur (decode-time (current-time)))
5034 (nday (+ days (nth 3 cur))))
5035 (setf (nth 3 cur) nday)
5036 (message-make-date (apply 'encode-time cur))))
5038 (defun message-make-message-id ()
5039 "Make a unique Message-ID."
5040 (concat "<" (message-unique-id)
5041 (let ((psubject (save-excursion (message-fetch-field "subject")))
5043 (save-excursion (message-fetch-field "supersedes"))))
5045 (and message-reply-headers
5046 (mail-header-references message-reply-headers)
5047 (mail-header-subject message-reply-headers)
5050 (message-strip-subject-re
5051 (mail-header-subject message-reply-headers))
5052 (message-strip-subject-re psubject))))
5054 (string-match "_-_@" psupersedes)))
5056 "@" (message-make-fqdn) ">"))
5058 (defvar message-unique-id-char nil)
5060 ;; If you ever change this function, make sure the new version
5061 ;; cannot generate IDs that the old version could.
5062 ;; You might for example insert a "." somewhere (not next to another dot
5063 ;; or string boundary), or modify the "fsf" string.
5064 (defun message-unique-id ()
5065 ;; Don't use microseconds from (current-time), they may be unsupported.
5066 ;; Instead we use this randomly inited counter.
5067 (setq message-unique-id-char
5068 (% (1+ (or message-unique-id-char (logand (random t) (1- (lsh 1 20)))))
5069 ;; (current-time) returns 16-bit ints,
5070 ;; and 2^16*25 just fits into 4 digits i base 36.
5072 (let ((tm (current-time)))
5074 (if (or (memq system-type '(ms-dos emx vax-vms))
5075 ;; message-number-base36 doesn't handle bigints.
5076 (floatp (user-uid)))
5077 (let ((user (downcase (user-login-name))))
5078 (while (string-match "[^a-z0-9_]" user)
5079 (aset user (match-beginning 0) ?_))
5081 (message-number-base36 (user-uid) -1))
5082 (message-number-base36 (+ (car tm)
5083 (lsh (% message-unique-id-char 25) 16)) 4)
5084 (message-number-base36 (+ (nth 1 tm)
5085 (lsh (/ message-unique-id-char 25) 16)) 4)
5086 ;; Append a given name, because while the generated ID is unique
5087 ;; to this newsreader, other newsreaders might otherwise generate
5088 ;; the same ID via another algorithm.
5091 (defun message-number-base36 (num len)
5096 (concat (message-number-base36 (/ num 36) (1- len))
5097 (char-to-string (aref "zyxwvutsrqponmlkjihgfedcba9876543210"
5100 (defun message-make-organization ()
5101 "Make an Organization header."
5102 (let* ((organization
5103 (when message-user-organization
5104 (if (functionp message-user-organization)
5105 (funcall message-user-organization)
5106 message-user-organization))))
5108 (mm-enable-multibyte)
5109 (cond ((stringp organization)
5110 (insert organization))
5111 ((and (eq t organization)
5112 message-user-organization-file
5113 (file-exists-p message-user-organization-file))
5114 (insert-file-contents message-user-organization-file)))
5115 (goto-char (point-min))
5116 (while (re-search-forward "[\t\n]+" nil t)
5117 (replace-match "" t t))
5118 (unless (zerop (buffer-size))
5121 (defun message-make-lines ()
5122 "Count the number of lines and return numeric string."
5127 (int-to-string (count-lines (point) (point-max))))))
5129 (defun message-make-references ()
5130 "Return the References header for this message."
5131 (when message-reply-headers
5132 (let ((message-id (mail-header-message-id message-reply-headers))
5133 (references (mail-header-references message-reply-headers))
5135 (if (or references message-id)
5136 (concat (or references "") (and references " ")
5140 (defun message-make-in-reply-to ()
5141 "Return the In-Reply-To header for this message."
5142 (when message-reply-headers
5143 (let ((from (mail-header-from message-reply-headers))
5144 (date (mail-header-date message-reply-headers))
5145 (msg-id (mail-header-message-id message-reply-headers)))
5147 (let ((name (mail-extract-address-components from)))
5148 (concat msg-id (if msg-id " (")
5152 (if (or (not date) (string= date ""))
5153 "(unknown date)" date)
5154 "\"" (if msg-id ")")))))))
5156 (defun message-make-distribution ()
5157 "Make a Distribution header."
5158 (let ((orig-distribution (message-fetch-reply-field "distribution")))
5159 (cond ((functionp message-distribution-function)
5160 (funcall message-distribution-function))
5161 (t orig-distribution))))
5163 (defun message-make-expires ()
5164 "Return an Expires header based on `message-expires'."
5165 (let ((current (current-time))
5166 (future (* 1.0 message-expires 60 60 24)))
5167 ;; Add the future to current.
5168 (setcar current (+ (car current) (round (/ future (expt 2 16)))))
5169 (setcar (cdr current) (+ (nth 1 current) (% (round future) (expt 2 16))))
5170 (message-make-date current)))
5172 (defun message-make-path ()
5174 (let ((login-name (user-login-name)))
5175 (cond ((null message-user-path)
5176 (concat (system-name) "!" login-name))
5177 ((stringp message-user-path)
5178 ;; Support GENERICPATH. Suggested by vixie@decwrl.dec.com.
5179 (concat message-user-path "!" login-name))
5182 (defun message-make-from ()
5183 "Make a From header."
5184 (let* ((style message-from-style)
5185 (login (message-make-address))
5187 (or (and (boundp 'user-full-name)
5190 (when (string= fullname "&")
5191 (setq fullname (user-login-name)))
5193 (mm-enable-multibyte)
5196 (equal fullname ""))
5198 ((or (eq style 'angles)
5199 (and (not (eq style 'parens))
5200 ;; Use angles if no quoting is needed, or if parens would
5201 ;; need quoting too.
5202 (or (not (string-match "[^- !#-'*+/-9=?A-Z^-~]" fullname))
5203 (let ((tmp (concat fullname nil)))
5204 (while (string-match "([^()]*)" tmp)
5205 (aset tmp (match-beginning 0) ?-)
5206 (aset tmp (1- (match-end 0)) ?-))
5207 (string-match "[\\()]" tmp)))))
5209 (goto-char (point-min))
5210 ;; Look for a character that cannot appear unquoted
5211 ;; according to RFC 822.
5212 (when (re-search-forward "[^- !#-'*+/-9=?A-Z^-~]" nil 1)
5213 ;; Quote fullname, escaping specials.
5214 (goto-char (point-min))
5216 (while (re-search-forward "[\"\\]" nil 1)
5217 (replace-match "\\\\\\&" t))
5219 (insert " <" login ">"))
5220 (t ; 'parens or default
5222 (let ((fullname-start (point)))
5224 (goto-char fullname-start)
5225 ;; RFC 822 says \ and nonmatching parentheses
5226 ;; must be escaped in comments.
5227 ;; Escape every instance of ()\ ...
5228 (while (re-search-forward "[()\\]" nil 1)
5229 (replace-match "\\\\\\&" t))
5230 ;; ... then undo escaping of matching parentheses,
5231 ;; including matching nested parentheses.
5232 (goto-char fullname-start)
5233 (while (re-search-forward
5234 "\\(\\=\\|[^\\]\\(\\\\\\\\\\)*\\)\\\\(\\(\\([^\\]\\|\\\\\\\\\\)*\\)\\\\)"
5236 (replace-match "\\1(\\3)" t)
5237 (goto-char fullname-start)))
5241 (defun message-make-sender ()
5242 "Return the \"real\" user address.
5243 This function tries to ignore all user modifications, and
5244 give as trustworthy answer as possible."
5245 (concat (user-login-name) "@" (system-name)))
5247 (defun message-make-address ()
5248 "Make the address of the user."
5249 (or (message-user-mail-address)
5250 (concat (user-login-name) "@" (message-make-domain))))
5252 (defun message-user-mail-address ()
5253 "Return the pertinent part of `user-mail-address'."
5254 (when (and user-mail-address
5255 (string-match "@.*\\." user-mail-address))
5256 (if (string-match " " user-mail-address)
5257 (nth 1 (mail-extract-address-components user-mail-address))
5258 user-mail-address)))
5260 (defun message-sendmail-envelope-from ()
5261 "Return the envelope from."
5262 (cond ((eq message-sendmail-envelope-from 'header)
5263 (nth 1 (mail-extract-address-components
5264 (message-fetch-field "from"))))
5265 ((stringp message-sendmail-envelope-from)
5266 message-sendmail-envelope-from)
5268 (message-make-address))))
5270 (defun message-make-fqdn ()
5271 "Return user's fully qualified domain name."
5272 (let* ((system-name (system-name))
5273 (user-mail (message-user-mail-address))
5276 (string-match "@\\(.*\\)\\'" user-mail))
5277 (match-string 1 user-mail)))
5278 (case-fold-search t))
5280 ((and message-user-fqdn
5281 (stringp message-user-fqdn)
5282 (string-match message-valid-fqdn-regexp message-user-fqdn)
5283 (not (string-match message-bogus-system-names message-user-fqdn)))
5285 ;; `message-user-fqdn' seems to be valid
5286 ((and (string-match message-valid-fqdn-regexp system-name)
5287 (not (string-match message-bogus-system-names system-name)))
5288 ;; `system-name' returned the right result.
5290 ;; Try `mail-host-address'.
5291 ((and (boundp 'mail-host-address)
5292 (stringp mail-host-address)
5293 (string-match message-valid-fqdn-regexp mail-host-address)
5294 (not (string-match message-bogus-system-names mail-host-address)))
5296 ;; We try `user-mail-address' as a backup.
5298 (stringp user-domain)
5299 (string-match message-valid-fqdn-regexp user-domain)
5300 (not (string-match message-bogus-system-names user-domain)))
5302 ;; Default to this bogus thing.
5305 ".i-did-not-set--mail-host-address--so-tickle-me")))))
5307 (defun message-make-host-name ()
5308 "Return the name of the host."
5309 (let ((fqdn (message-make-fqdn)))
5310 (string-match "^[^.]+\\." fqdn)
5311 (substring fqdn 0 (1- (match-end 0)))))
5313 (defun message-make-domain ()
5314 "Return the domain name."
5315 (or mail-host-address
5316 (message-make-fqdn)))
5318 (defun message-to-list-only ()
5319 "Send a message to the list only.
5320 Remove all addresses but the list address from To and Cc headers."
5322 (let ((listaddr (message-make-mail-followup-to t)))
5325 (message-remove-header "to")
5326 (message-remove-header "cc")
5327 (message-position-on-field "To" "X-Draft-From")
5328 (insert listaddr)))))
5330 (defun message-make-mail-followup-to (&optional only-show-subscribed)
5331 "Return the Mail-Followup-To header.
5332 If passed the optional argument ONLY-SHOW-SUBSCRIBED only return the
5333 subscribed address (and not the additional To and Cc header contents)."
5334 (let* ((case-fold-search t)
5335 (to (message-fetch-field "To"))
5336 (cc (message-fetch-field "cc"))
5337 (msg-recipients (concat to (and to cc ", ") cc))
5339 (mapcar 'mail-strip-quoted-names
5340 (message-tokenize-header msg-recipients)))
5342 (if message-subscribed-address-file
5343 (let (begin end item re)
5346 (insert-file-contents message-subscribed-address-file)
5348 (setq begin (point))
5351 (if (bolp) (setq end (1- end)))
5352 (setq item (regexp-quote (buffer-substring begin end)))
5353 (if re (setq re (concat re "\\|" item))
5354 (setq re (concat "\\`\\(" item))))
5355 (and re (list (concat re "\\)\\'"))))))))
5356 (mft-regexps (apply 'append message-subscribed-regexps
5357 (mapcar 'regexp-quote
5358 message-subscribed-addresses)
5361 message-subscribed-address-functions))))
5363 (let ((subscribed-lists nil)
5365 (loop for recipient in recipients
5366 when (loop for regexp in mft-regexps
5367 when (string-match regexp recipient) return t)
5370 (if only-show-subscribed
5372 msg-recipients))))))
5374 (defun message-idna-to-ascii-rhs-1 (header)
5375 "Interactively potentially IDNA encode domain names in HEADER."
5376 (let ((field (message-fetch-field header))
5380 (mm-delete-duplicates
5381 (mapcar (lambda (rhs) (or (cadr (split-string rhs "@")) ""))
5384 'car (mail-header-parse-addresses field))))))
5385 (setq ace (downcase (idna-to-ascii rhs)))
5386 (when (and (not (equal rhs ace))
5387 (or (not (eq message-use-idna 'ask))
5388 (y-or-n-p (format "Replace %s with %s in %s:? "
5390 (goto-char (point-min))
5391 (while (re-search-forward (concat "^" header ":") nil t)
5392 (message-narrow-to-field)
5393 (while (search-forward (concat "@" rhs) nil t)
5394 (replace-match (concat "@" ace) t t))
5395 (goto-char (point-max))
5398 (defun message-idna-to-ascii-rhs ()
5399 "Possibly IDNA encode non-ASCII domain names in From:, To: and Cc: headers.
5400 See `message-idna-encode'."
5402 (when message-use-idna
5405 (message-narrow-to-head)
5406 (message-idna-to-ascii-rhs-1 "From")
5407 (message-idna-to-ascii-rhs-1 "To")
5408 (message-idna-to-ascii-rhs-1 "Reply-To")
5409 (message-idna-to-ascii-rhs-1 "Mail-Reply-To")
5410 (message-idna-to-ascii-rhs-1 "Mail-Followup-To")
5411 (message-idna-to-ascii-rhs-1 "Cc")))))
5413 (defun message-generate-headers (headers)
5414 "Prepare article HEADERS.
5415 Headers already prepared in the buffer are not modified."
5416 (setq headers (append headers message-required-headers))
5418 (message-narrow-to-headers)
5419 (let* ((Date (message-make-date))
5420 (Message-ID (message-make-message-id))
5421 (Organization (message-make-organization))
5422 (From (message-make-from))
5423 (Path (message-make-path))
5426 (In-Reply-To (message-make-in-reply-to))
5427 (References (message-make-references))
5429 (Distribution (message-make-distribution))
5430 (Lines (message-make-lines))
5431 (User-Agent message-newsreader)
5432 (Expires (message-make-expires))
5433 (case-fold-search t)
5435 header value elem header-string)
5436 ;; First we remove any old generated headers.
5437 (let ((headers message-deletable-headers))
5438 (unless (buffer-modified-p)
5439 (setq headers (delq 'Message-ID (copy-sequence headers))))
5441 (goto-char (point-min))
5442 (and (re-search-forward
5443 (concat "^" (symbol-name (car headers)) ": *") nil t)
5444 (get-text-property (1+ (match-beginning 0)) 'message-deletable)
5445 (message-delete-line))
5447 ;; Go through all the required headers and see if they are in the
5448 ;; articles already. If they are not, or are empty, they are
5449 ;; inserted automatically - except for Subject, Newsgroups and
5452 (goto-char (point-min))
5453 (setq elem (pop headers))
5455 (if (eq (car elem) 'optional)
5456 (setq header (cdr elem)
5458 (setq header (car elem)))
5460 (setq header-string (if (stringp header)
5462 (symbol-name header)))
5463 (when (or (not (re-search-forward
5465 (regexp-quote (downcase header-string))
5469 ;; The header was found. We insert a space after the
5470 ;; colon, if there is none.
5471 (if (/= (char-after) ? ) (insert " ") (forward-char 1))
5472 ;; Find out whether the header is empty.
5473 (looking-at "[ \t]*\n[^ \t]")))
5474 ;; So we find out what value we should insert.
5478 (eq (car elem) 'optional)
5479 (not (member header-string message-inserted-headers)))
5480 ;; This is an optional header. If the cdr of this
5481 ;; is something that is nil, then we do not insert
5483 (setq header (cdr elem))
5484 (or (and (functionp (cdr elem))
5485 (funcall (cdr elem)))
5486 (and (boundp (cdr elem))
5487 (symbol-value (cdr elem)))))
5489 ;; The element is a cons. Either the cdr is a
5490 ;; string to be inserted verbatim, or it is a
5491 ;; function, and we insert the value returned from
5493 (or (and (stringp (cdr elem))
5495 (and (functionp (cdr elem))
5496 (funcall (cdr elem)))))
5497 ((and (boundp header)
5498 (symbol-value header))
5499 ;; The element is a symbol. We insert the value
5500 ;; of this symbol, if any.
5501 (symbol-value header))
5502 ((not (message-check-element
5503 (intern (downcase (symbol-name header)))))
5504 ;; We couldn't generate a value for this header,
5505 ;; so we just ask the user.
5506 (read-from-minibuffer
5507 (format "Empty header for %s; enter value: " header)))))
5508 ;; Finally insert the header.
5510 (not (equal value "")))
5514 ;; This header didn't exist, so we insert it.
5515 (goto-char (point-max))
5517 (cdr (assq header message-header-format-alist))))
5519 (funcall formatter header value)
5520 (insert header-string ": " value))
5521 (goto-char (message-fill-field))
5522 ;; We check whether the value was ended by a
5523 ;; newline. If not, we insert one.
5527 ;; The value of this header was empty, so we clear
5528 ;; totally and insert the new value.
5529 (delete-region (point) (point-at-eol))
5530 ;; If the header is optional, and the header was
5531 ;; empty, we can't insert it anyway.
5533 (push header-string message-inserted-headers)
5535 (message-fill-field)))
5536 ;; Add the deletable property to the headers that require it.
5537 (and (memq header message-deletable-headers)
5538 (progn (beginning-of-line) (looking-at "[^:]+: "))
5539 (add-text-properties
5540 (point) (match-end 0)
5541 '(message-deletable t face italic) (current-buffer)))))))
5542 ;; Insert new Sender if the From is strange.
5543 (let ((from (message-fetch-field "from"))
5544 (sender (message-fetch-field "sender"))
5545 (secure-sender (message-make-sender)))
5547 (not (message-check-element 'sender))
5550 (cadr (mail-extract-address-components from)))
5551 (downcase secure-sender)))
5556 (cadr (mail-extract-address-components sender)))
5557 (downcase secure-sender)))))
5558 (goto-char (point-min))
5559 ;; Rename any old Sender headers to Original-Sender.
5560 (when (re-search-forward "^\\(Original-\\)*Sender:" nil t)
5562 (insert "Original-")
5563 (beginning-of-line))
5564 (when (or (message-news-p)
5565 (string-match "@.+\\.." secure-sender))
5566 (insert "Sender: " secure-sender "\n"))))
5568 (message-idna-to-ascii-rhs))))
5570 (defun message-insert-courtesy-copy ()
5571 "Insert a courtesy message in mail copies of combined messages."
5575 (message-narrow-to-headers)
5576 (when (setq newsgroups (message-fetch-field "newsgroups"))
5577 (goto-char (point-max))
5578 (insert "Posted-To: " newsgroups "\n")))
5580 (when message-courtesy-message
5582 ((string-match "%s" message-courtesy-message)
5583 (insert (format message-courtesy-message newsgroups)))
5585 (insert message-courtesy-message)))))))
5588 ;;; Setting up a message buffer
5591 (defun message-skip-to-next-address ()
5592 (let ((end (save-excursion
5593 (message-next-header)
5596 (when (looking-at ",")
5598 (while (and (not (= (point) end))
5599 (or (not (eq char ?,))
5601 (skip-chars-forward "^,\"" (point-max))
5602 (when (eq (setq char (following-char)) ?\")
5603 (setq quoted (not quoted)))
5604 (unless (= (point) end)
5606 (skip-chars-forward " \t\n")))
5608 (defun message-fill-address (header value)
5609 (insert (capitalize (symbol-name header))
5611 (if (consp value) (car value) value)
5613 (message-fill-field-address))
5615 (defun message-split-line ()
5616 "Split current line, moving portion beyond point vertically down.
5617 If the current line has `message-yank-prefix', insert it on the new line."
5620 (split-line message-yank-prefix) ;; Emacs 22.1+ supports arg.
5624 (defun message-insert-header (header value)
5625 (insert (capitalize (symbol-name header))
5627 (if (consp value) (car value) value)))
5629 (defun message-field-name ()
5631 (goto-char (point-min))
5632 (when (looking-at "\\([^:]+\\):")
5633 (intern (capitalize (match-string 1))))))
5635 (defun message-fill-field ()
5638 (message-narrow-to-field)
5639 (let ((field-name (message-field-name)))
5640 (funcall (or (cadr (assq field-name message-field-fillers))
5641 'message-fill-field-general)))
5644 (defun message-fill-field-address ()
5646 (message-skip-to-next-address)
5648 (if (and (> (current-column) 78)
5654 (setq last (1+ (point))))
5655 (setq last (1+ (point)))))))
5657 (defun message-fill-field-general ()
5658 (let ((begin (point))
5661 (while (and (search-forward "\n" nil t)
5663 (replace-match " " t t))
5664 (fill-region-as-paragraph begin (point-max))
5665 ;; Tapdance around looong Message-IDs.
5667 (when (looking-at "[ \t]*$")
5668 (message-delete-line))
5670 (search-forward ":" nil t)
5671 (when (looking-at "\n[ \t]+")
5672 (replace-match " " t t))
5673 (goto-char (point-max))))
5675 (defun message-shorten-1 (list cut surplus)
5676 "Cut SURPLUS elements out of LIST, beginning with CUTth one."
5677 (setcdr (nthcdr (- cut 2) list)
5678 (nthcdr (+ (- cut 2) surplus 1) list)))
5680 (defun message-shorten-references (header references)
5681 "Trim REFERENCES to be 21 Message-ID long or less, and fold them.
5682 When sending via news, also check that the REFERENCES are less
5683 than 988 characters long, and if they are not, trim them until
5691 (goto-char (point-min))
5692 ;; Cons a list of valid references.
5693 (while (re-search-forward "<[^>]+>" nil t)
5694 (push (match-string 0) refs))
5695 (setq refs (nreverse refs)
5696 count (length refs)))
5698 ;; If the list has more than MAXCOUNT elements, trim it by
5699 ;; removing the CUTth element and the required number of
5700 ;; elements that follow.
5701 (when (> count maxcount)
5702 (let ((surplus (- count maxcount)))
5703 (message-shorten-1 refs cut surplus)
5704 (decf count surplus)))
5706 ;; When sending via news, make sure the total folded length will
5707 ;; be less than 998 characters. This is to cater to broken INN
5708 ;; 2.3 which counts the total number of characters in a header
5709 ;; rather than the physical line length of each line, as it should.
5711 ;; This hack should be removed when it's believed than INN 2.3 is
5712 ;; no longer widely used.
5714 ;; At this point the headers have not been generated, thus we use
5715 ;; message-this-is-news directly.
5716 (when message-this-is-news
5719 (message-insert-header
5720 header (mapconcat #'identity refs " "))
5722 (message-shorten-1 refs cut 1)))
5723 ;; Finally, collect the references back into a string and insert
5724 ;; it into the buffer.
5725 (message-insert-header header (mapconcat #'identity refs " "))))
5727 (defun message-position-point ()
5728 "Move point to where the user probably wants to find it."
5729 (message-narrow-to-headers)
5731 ((re-search-forward "^[^:]+:[ \t]*$" nil t)
5732 (search-backward ":" )
5735 (if (eq (char-after) ? )
5739 (goto-char (point-max))
5742 (unless (looking-at "$")
5746 (defcustom message-beginning-of-line t
5747 "Whether \\<message-mode-map>\\[message-beginning-of-line]\
5748 goes to beginning of header values."
5750 :group 'message-buffers
5751 :link '(custom-manual "(message)Movement")
5754 (defun message-beginning-of-line (&optional n)
5755 "Move point to beginning of header value or to beginning of line.
5756 The prefix argument N is passed directly to `beginning-of-line'.
5758 This command is identical to `beginning-of-line' if point is
5759 outside the message header or if the option `message-beginning-of-line'
5762 If point is in the message header and on a (non-continued) header
5763 line, move point to the beginning of the header value or the beginning of line,
5764 whichever is closer. If point is already at beginning of line, move point to
5765 beginning of header value. Therefore, repeated calls will toggle point
5766 between beginning of field and beginning of line."
5768 (let ((zrs 'zmacs-region-stays))
5769 (when (and (interactive-p) (boundp zrs))
5771 (if (and message-beginning-of-line
5772 (message-point-in-header-p))
5773 (let* ((here (point))
5774 (bol (progn (beginning-of-line n) (point)))
5775 (eol (point-at-eol))
5776 (eoh (re-search-forward ": *" eol t)))
5778 (if (and eoh (or (< eoh here) (= bol here)))
5780 (beginning-of-line n)))
5782 (defun message-buffer-name (type &optional to group)
5783 "Return a new (unique) buffer name based on TYPE and TO."
5785 ;; Generate a new buffer name The Message Way.
5786 ((eq message-generate-new-buffers 'unique)
5787 (generate-new-buffer-name
5791 (or (car (mail-extract-address-components to))
5794 (if (and group (not (string= group ""))) (concat " on " group) "")
5796 ;; Check whether `message-generate-new-buffers' is a function,
5797 ;; and if so, call it.
5798 ((functionp message-generate-new-buffers)
5799 (funcall message-generate-new-buffers type to group))
5800 ((eq message-generate-new-buffers 'unsent)
5801 (generate-new-buffer-name
5802 (concat "*unsent " type
5805 (or (car (mail-extract-address-components to))
5808 (if (and group (not (string= group ""))) (concat " on " group) "")
5810 ;; Use standard name.
5812 (format "*%s message*" type))))
5814 (defun message-pop-to-buffer (name)
5815 "Pop to buffer NAME, and warn if it already exists and is modified."
5816 (let ((buffer (get-buffer name)))
5818 (buffer-name buffer))
5820 (set-buffer (pop-to-buffer buffer))
5821 (when (and (buffer-modified-p)
5823 "Message already being composed; erase? ")))
5824 (error "Message being composed")))
5825 (set-buffer (pop-to-buffer name)))
5829 (defun message-do-send-housekeeping ()
5830 "Kill old message buffers."
5831 ;; We might have sent this buffer already. Delete it from the
5833 (setq message-buffer-list (delq (current-buffer) message-buffer-list))
5834 (while (and message-max-buffers
5836 (>= (length message-buffer-list) message-max-buffers))
5837 ;; Kill the oldest buffer -- unless it has been changed.
5838 (let ((buffer (pop message-buffer-list)))
5839 (when (and (buffer-name buffer)
5840 (not (buffer-modified-p buffer)))
5841 (kill-buffer buffer))))
5842 ;; Rename the buffer.
5843 (if message-send-rename-function
5844 (funcall message-send-rename-function)
5845 ;; Note: mail-abbrevs of XEmacs renames buffer name behind Gnus.
5847 "\\`\\*\\(sent \\|unsent \\)?\\(.+\\)\\*[^\\*]*\\|\\`mail to "
5849 (let ((name (match-string 2 (buffer-name)))
5851 (if (not (or (null name)
5852 (string-equal name "mail")
5853 (string-equal name "posting")))
5854 (setq name (concat "*sent " name "*"))
5855 (message-narrow-to-headers)
5856 (setq to (message-fetch-field "to"))
5857 (setq group (message-fetch-field "newsgroups"))
5861 (to (concat "*sent mail to "
5862 (or (car (mail-extract-address-components to))
5864 ((and group (not (string= group "")))
5865 (concat "*sent posting on " group "*"))
5866 (t "*sent mail*"))))
5867 (unless (string-equal name (buffer-name))
5868 (rename-buffer name t)))))
5869 ;; Push the current buffer onto the list.
5870 (when message-max-buffers
5871 (setq message-buffer-list
5872 (nconc message-buffer-list (list (current-buffer))))))
5874 (defun message-mail-user-agent ()
5876 ((not message-mail-user-agent) nil)
5877 ((eq message-mail-user-agent t) mail-user-agent)
5878 (t message-mail-user-agent))))
5879 (if (memq mua '(message-user-agent gnus-user-agent))
5883 (defun message-setup (headers &optional replybuffer actions switch-function)
5884 (let ((mua (message-mail-user-agent))
5885 subject to field yank-action)
5886 (if (not (and message-this-is-mail mua))
5887 (message-setup-1 headers replybuffer actions)
5889 (setq yank-action (list 'insert-buffer replybuffer)))
5890 (setq headers (copy-sequence headers))
5891 (setq field (assq 'Subject headers))
5893 (setq subject (cdr field))
5894 (setq headers (delq field headers)))
5895 (setq field (assq 'To headers))
5897 (setq to (cdr field))
5898 (setq headers (delq field headers)))
5899 (let ((mail-user-agent mua))
5900 (compose-mail to subject
5901 (mapcar (lambda (item)
5903 (format "%s" (car item))
5906 nil switch-function yank-action actions)))))
5908 (defun message-headers-to-generate (headers included-headers excluded-headers)
5909 "Return a list that includes all headers from HEADERS.
5910 If INCLUDED-HEADERS is a list, just include those headers. If it is
5911 t, include all headers. In any case, headers from EXCLUDED-HEADERS
5915 (dolist (header headers)
5916 (setq header-name (cond
5917 ((and (consp header)
5918 (eq (car header) 'optional))
5919 ;; On the form (optional . Header)
5922 ;; On the form (Header . function)
5927 (when (and (not (memq header-name excluded-headers))
5928 (or (eq included-headers t)
5929 (memq header-name included-headers)))
5930 (push header result)))
5933 (defun message-setup-1 (headers &optional replybuffer actions)
5934 (dolist (action actions)
5936 (add-to-list 'message-send-actions
5937 `(apply ',(car action) ',(cdr action)))))
5938 (setq message-reply-buffer replybuffer)
5939 (goto-char (point-min))
5940 ;; Insert all the headers.
5943 (alist message-header-format-alist))
5945 (unless (assq (caar h) message-header-format-alist)
5946 (push (list (caar h)) alist))
5950 (delete-region (point) (progn (forward-line -1) (point)))
5951 (when message-default-headers
5952 (insert message-default-headers)
5953 (or (bolp) (insert ?\n)))
5954 (insert mail-header-separator "\n")
5956 (when (message-news-p)
5957 (when message-default-news-headers
5958 (insert message-default-news-headers)
5959 (or (bolp) (insert ?\n)))
5960 (when message-generate-headers-first
5961 (message-generate-headers
5962 (message-headers-to-generate
5963 (append message-required-news-headers
5964 message-required-headers)
5965 message-generate-headers-first
5966 '(Lines Subject)))))
5967 (when (message-mail-p)
5968 (when message-default-mail-headers
5969 (insert message-default-mail-headers)
5970 (or (bolp) (insert ?\n)))
5971 (when message-generate-headers-first
5972 (message-generate-headers
5973 (message-headers-to-generate
5974 (append message-required-mail-headers
5975 message-required-headers)
5976 message-generate-headers-first
5977 '(Lines Subject)))))
5978 (run-hooks 'message-signature-setup-hook)
5979 (message-insert-signature)
5981 (message-narrow-to-headers)
5982 (run-hooks 'message-header-setup-hook))
5983 (set-buffer-modified-p nil)
5984 (setq buffer-undo-list nil)
5985 (when message-generate-hashcash
5986 ;; Generate hashcash headers for recipients already known
5987 (mail-add-payment-async))
5988 (run-hooks 'message-setup-hook)
5989 ;; Do this last to give it precedence over posting styles, etc.
5990 (when (message-mail-p)
5992 (message-narrow-to-headers)
5993 (if message-alternative-emails
5994 (message-use-alternative-email-as-from))))
5995 (message-position-point)
5998 (defun message-set-auto-save-file-name ()
5999 "Associate the message buffer with a file in the drafts directory."
6000 (when message-auto-save-directory
6001 (unless (file-directory-p
6002 (directory-file-name message-auto-save-directory))
6003 (make-directory message-auto-save-directory t))
6005 (setq message-draft-article
6006 (nndraft-request-associate-buffer "drafts"))
6007 (setq buffer-file-name (expand-file-name
6008 (if (memq system-type
6009 '(ms-dos ms-windows windows-nt
6010 cygwin cygwin32 win32 w32
6014 message-auto-save-directory))
6015 (setq buffer-auto-save-file-name (make-auto-save-file-name)))
6016 (clear-visited-file-modtime)
6017 (setq buffer-file-coding-system message-draft-coding-system)))
6019 (defun message-disassociate-draft ()
6020 "Disassociate the message buffer from the drafts directory."
6021 (when message-draft-article
6022 (nndraft-request-expire-articles
6023 (list message-draft-article) "drafts" nil t)))
6025 (defun message-insert-headers ()
6026 "Generate the headers for the article."
6030 (message-narrow-to-headers)
6031 (when (message-news-p)
6032 (message-generate-headers
6035 (copy-sequence message-required-news-headers)))))
6036 (when (message-mail-p)
6037 (message-generate-headers
6040 (copy-sequence message-required-mail-headers))))))))
6045 ;;; Commands for interfacing with message
6049 (defun message-mail (&optional to subject
6050 other-headers continue switch-function
6051 yank-action send-actions)
6052 "Start editing a mail message to be sent.
6053 OTHER-HEADERS is an alist of header/value pairs."
6055 (let ((message-this-is-mail t) replybuffer)
6056 (unless (message-mail-user-agent)
6057 (message-pop-to-buffer (message-buffer-name "mail" to)))
6058 ;; FIXME: message-mail should do something if YANK-ACTION is not
6060 (and (consp yank-action) (eq (car yank-action) 'insert-buffer)
6061 (setq replybuffer (nth 1 yank-action)))
6064 `((To . ,(or to "")) (Subject . ,(or subject "")))
6065 (when other-headers other-headers))
6066 replybuffer send-actions)
6067 ;; FIXME: Should return nil if failure.
6071 (defun message-news (&optional newsgroups subject)
6072 "Start editing a news article to be sent."
6074 (let ((message-this-is-news t))
6075 (message-pop-to-buffer (message-buffer-name "posting" nil newsgroups))
6076 (message-setup `((Newsgroups . ,(or newsgroups ""))
6077 (Subject . ,(or subject ""))))))
6079 (defun message-get-reply-headers (wide &optional to-address address-headers)
6080 (let (follow-to mct never-mct to cc author mft recipients extra)
6081 ;; Find all relevant headers we need.
6083 (message-narrow-to-headers-or-head)
6084 ;; Gmane renames "To". Look at "Original-To", too, if it is present in
6085 ;; message-header-synonyms.
6086 (setq to (or (message-fetch-field "to")
6087 (and (loop for synonym in message-header-synonyms
6088 when (memq 'Original-To synonym)
6090 (message-fetch-field "original-to")))
6091 cc (message-fetch-field "cc")
6092 extra (when message-extra-wide-headers
6093 (mapconcat 'identity
6094 (mapcar 'message-fetch-field
6095 message-extra-wide-headers)
6097 mct (message-fetch-field "mail-copies-to")
6098 author (or (message-fetch-field "mail-reply-to")
6099 (message-fetch-field "reply-to")
6100 (message-fetch-field "from")
6102 mft (and message-use-mail-followup-to
6103 (message-fetch-field "mail-followup-to"))))
6105 ;; Handle special values of Mail-Copies-To.
6107 (cond ((or (equal (downcase mct) "never")
6108 (equal (downcase mct) "nobody"))
6111 ((or (equal (downcase mct) "always")
6112 (equal (downcase mct) "poster"))
6113 (setq mct author))))
6116 ;; Build (textual) list of new recipient addresses.
6119 (setq recipients (concat ", " author)))
6121 (dolist (header address-headers)
6122 (let ((value (message-fetch-field header)))
6124 (setq recipients (concat recipients ", " value))))))
6126 (string-match "[^ \t,]" mft)
6127 (or (not (eq message-use-mail-followup-to 'ask))
6128 (message-y-or-n-p "Obey Mail-Followup-To? " t "\
6129 You should normally obey the Mail-Followup-To: header. In this
6130 article, it has the value of
6134 which directs your response to " (if (string-match "," mft)
6135 "the specified addresses"
6136 "that address only") ".
6138 Most commonly, Mail-Followup-To is used by a mailing list poster to
6139 express that responses should be sent to just the list, and not the
6142 If a message is posted to several mailing lists, Mail-Followup-To may
6143 also be used to direct the following discussion to one list only,
6144 because discussions that are spread over several lists tend to be
6145 fragmented and very difficult to follow.
6147 Also, some source/announcement lists are not intended for discussion;
6148 responses here are directed to other addresses.
6150 You may customize the variable `message-use-mail-followup-to', if you
6151 want to get rid of this query permanently.")))
6152 (setq recipients (concat ", " mft)))
6154 (setq recipients (concat ", " to-address))
6155 ;; If the author explicitly asked for a copy, we don't deny it to them.
6156 (if mct (setq recipients (concat recipients ", " mct))))
6158 (setq recipients (if never-mct "" (concat ", " author)))
6159 (if to (setq recipients (concat recipients ", " to)))
6160 (if cc (setq recipients (concat recipients ", " cc)))
6161 (if extra (setq recipients (concat recipients ", " extra)))
6162 (if mct (setq recipients (concat recipients ", " mct)))))
6163 (if (>= (length recipients) 2)
6164 ;; Strip the leading ", ".
6165 (setq recipients (substring recipients 2)))
6166 ;; Squeeze whitespace.
6167 (while (string-match "[ \t][ \t]+" recipients)
6168 (setq recipients (replace-match " " t t recipients)))
6169 ;; Remove addresses that match `rmail-dont-reply-to-names'.
6170 (let ((rmail-dont-reply-to-names (message-dont-reply-to-names)))
6171 (setq recipients (rmail-dont-reply-to recipients)))
6172 ;; Perhaps "Mail-Copies-To: never" removed the only address?
6173 (if (string-equal recipients "")
6174 (setq recipients author))
6175 ;; Convert string to a list of (("foo@bar" . "Name <Foo@BAR>") ...).
6179 (cons (downcase (mail-strip-quoted-names addr)) addr))
6180 (message-tokenize-header recipients)))
6181 ;; Remove first duplicates. (Why not all duplicates? Is this a bug?)
6182 (let ((s recipients))
6184 (setq recipients (delq (assoc (car (pop s)) s) recipients))))
6186 ;; Remove hierarchical lists that are contained within each other,
6187 ;; if message-hierarchical-addresses is defined.
6188 (when message-hierarchical-addresses
6189 (let ((plain-addrs (mapcar 'car recipients))
6192 (setq subaddrs (assoc (car plain-addrs)
6193 message-hierarchical-addresses)
6194 plain-addrs (cdr plain-addrs))
6196 (setq subaddrs (cdr subaddrs))
6198 (setq recip (assoc (car subaddrs) recipients)
6199 subaddrs (cdr subaddrs))
6201 (setq recipients (delq recip recipients))))))))
6203 ;; Build the header alist. Allow the user to be asked whether
6204 ;; or not to reply to all recipients in a wide reply.
6205 (setq follow-to (list (cons 'To (cdr (pop recipients)))))
6206 (when (and recipients
6207 (or (not message-wide-reply-confirm-recipients)
6208 (y-or-n-p "Reply to all recipients? ")))
6209 (setq recipients (mapconcat
6210 (lambda (addr) (cdr addr)) recipients ", "))
6211 (if (string-match "^ +" recipients)
6212 (setq recipients (substring recipients (match-end 0))))
6213 (push (cons 'Cc recipients) follow-to)))
6216 (defcustom message-simplify-subject-functions
6217 '(message-strip-list-identifiers
6218 message-strip-subject-re
6219 message-strip-subject-trailing-was
6220 message-strip-subject-encoded-words)
6221 "List of functions taking a string argument that simplify subjects.
6222 The functions are applied when replying to a message.
6224 Useful functions to put in this list include:
6225 `message-strip-list-identifiers', `message-strip-subject-re',
6226 `message-strip-subject-trailing-was', and
6227 `message-strip-subject-encoded-words'."
6228 :version "22.1" ;; Gnus 5.10.9
6229 :group 'message-various
6230 :type '(repeat function))
6232 (defun message-simplify-subject (subject &optional functions)
6233 "Return simplified SUBJECT."
6236 (setq functions message-simplify-subject-functions))
6237 (when (and (memq 'message-strip-list-identifiers functions)
6238 gnus-list-identifiers)
6239 (setq subject (message-strip-list-identifiers subject)))
6240 (when (memq 'message-strip-subject-re functions)
6241 (setq subject (concat "Re: " (message-strip-subject-re subject))))
6242 (when (and (memq 'message-strip-subject-trailing-was functions)
6243 message-subject-trailing-was-query)
6244 (setq subject (message-strip-subject-trailing-was subject)))
6245 (when (memq 'message-strip-subject-encoded-words functions)
6246 (setq subject (message-strip-subject-encoded-words subject)))
6250 (defun message-reply (&optional to-address wide)
6251 "Start editing a reply to the article in the current buffer."
6253 (require 'gnus-sum) ; for gnus-list-identifiers
6254 (let ((cur (current-buffer))
6255 from subject date reply-to to cc
6256 references message-id follow-to
6257 (inhibit-point-motion-hooks t)
6258 (message-this-is-mail t)
6261 (message-narrow-to-head-1)
6262 ;; Allow customizations to have their say.
6264 ;; This is a regular reply.
6265 (when (functionp message-reply-to-function)
6267 (setq follow-to (funcall message-reply-to-function))))
6268 ;; This is a followup.
6269 (when (functionp message-wide-reply-to-function)
6272 (funcall message-wide-reply-to-function)))))
6273 (setq message-id (message-fetch-field "message-id" t)
6274 references (message-fetch-field "references")
6275 date (message-fetch-field "date")
6276 from (or (message-fetch-field "from") "nobody")
6277 subject (or (message-fetch-field "subject") "none"))
6279 ;; Strip list identifiers, "Re: ", and "was:"
6280 (setq subject (message-simplify-subject subject))
6282 (when (and (setq gnus-warning (message-fetch-field "gnus-warning"))
6283 (string-match "<[^>]+>" gnus-warning))
6284 (setq message-id (match-string 0 gnus-warning)))
6287 (setq follow-to (message-get-reply-headers wide to-address))))
6289 (unless (message-mail-user-agent)
6290 (message-pop-to-buffer
6291 (message-buffer-name
6292 (if wide "wide reply" "reply") from
6293 (if wide to-address nil))))
6295 (setq message-reply-headers
6296 (vector 0 subject from date message-id references 0 0 ""))
6299 `((Subject . ,subject)
6304 (defun message-wide-reply (&optional to-address)
6305 "Make a \"wide\" reply to the message in the current buffer."
6307 (message-reply to-address t))
6310 (defun message-followup (&optional to-newsgroups)
6311 "Follow up to the message in the current buffer.
6312 If TO-NEWSGROUPS, use that as the new Newsgroups line."
6314 (require 'gnus-sum) ; for gnus-list-identifiers
6315 (let ((cur (current-buffer))
6316 from subject date reply-to mrt mct
6317 references message-id follow-to
6318 (inhibit-point-motion-hooks t)
6319 (message-this-is-news t)
6320 followup-to distribution newsgroups gnus-warning posted-to)
6323 (goto-char (point-min))
6324 (if (search-forward "\n\n" nil t)
6327 (when (functionp message-followup-to-function)
6329 (funcall message-followup-to-function)))
6330 (setq from (message-fetch-field "from")
6331 date (message-fetch-field "date")
6332 subject (or (message-fetch-field "subject") "none")
6333 references (message-fetch-field "references")
6334 message-id (message-fetch-field "message-id" t)
6335 followup-to (message-fetch-field "followup-to")
6336 newsgroups (message-fetch-field "newsgroups")
6337 posted-to (message-fetch-field "posted-to")
6338 reply-to (message-fetch-field "reply-to")
6339 mrt (message-fetch-field "mail-reply-to")
6340 distribution (message-fetch-field "distribution")
6341 mct (message-fetch-field "mail-copies-to"))
6342 (when (and (setq gnus-warning (message-fetch-field "gnus-warning"))
6343 (string-match "<[^>]+>" gnus-warning))
6344 (setq message-id (match-string 0 gnus-warning)))
6345 ;; Remove bogus distribution.
6346 (when (and (stringp distribution)
6347 (let ((case-fold-search t))
6348 (string-match "world" distribution)))
6349 (setq distribution nil))
6350 ;; Strip list identifiers, "Re: ", and "was:"
6351 (setq subject (message-simplify-subject subject))
6354 (message-pop-to-buffer (message-buffer-name "followup" from newsgroups))
6356 (setq message-reply-headers
6357 (vector 0 subject from date message-id references 0 0 ""))
6360 `((Subject . ,subject)
6363 (list (cons 'Newsgroups to-newsgroups)))
6364 (follow-to follow-to)
6365 ((and followup-to message-use-followup-to)
6368 ((equal (downcase followup-to) "poster")
6369 (if (or (eq message-use-followup-to 'use)
6370 (message-y-or-n-p "Obey Followup-To: poster? " t "\
6371 You should normally obey the Followup-To: header.
6373 `Followup-To: poster' sends your response via e-mail instead of news.
6375 A typical situation where `Followup-To: poster' is used is when the poster
6376 does not read the newsgroup, so he wouldn't see any replies sent to it.
6378 You may customize the variable `message-use-followup-to', if you
6379 want to get rid of this query permanently."))
6381 (setq message-this-is-news nil)
6382 (cons 'To (or mrt reply-to from "")))
6383 (cons 'Newsgroups newsgroups)))
6385 (if (or (equal followup-to newsgroups)
6386 (not (eq message-use-followup-to 'ask))
6388 (concat "Obey Followup-To: " followup-to "? ") t "\
6389 You should normally obey the Followup-To: header.
6391 `Followup-To: " followup-to "'
6392 directs your response to " (if (string-match "," followup-to)
6393 "the specified newsgroups"
6394 "that newsgroup only") ".
6396 If a message is posted to several newsgroups, Followup-To is often
6397 used to direct the following discussion to one newsgroup only,
6398 because discussions that are spread over several newsgroup tend to
6399 be fragmented and very difficult to follow.
6401 Also, some source/announcement newsgroups are not intended for discussion;
6402 responses here are directed to other newsgroups.
6404 You may customize the variable `message-use-followup-to', if you
6405 want to get rid of this query permanently."))
6406 (cons 'Newsgroups followup-to)
6407 (cons 'Newsgroups newsgroups))))))
6409 `((Newsgroups . ,posted-to)))
6411 `((Newsgroups . ,newsgroups))))
6412 ,@(and distribution (list (cons 'Distribution distribution)))
6414 (not (or (equal (downcase mct) "never")
6415 (equal (downcase mct) "nobody"))))
6416 (list (cons 'Cc (if (or (equal (downcase mct) "always")
6417 (equal (downcase mct) "poster"))
6418 (or mrt reply-to from "")
6423 (defun message-is-yours-p ()
6424 "Non-nil means current article is yours.
6425 If you have added 'cancel-messages to `message-shoot-gnksa-feet', all articles
6426 are yours except those that have Cancel-Lock header not belonging to you.
6427 Instead of shooting GNKSA feet, you should modify `message-alternative-emails'
6428 regexp to match all of yours addresses."
6429 ;; Canlock-logic as suggested by Per Abrahamsen
6430 ;; <abraham@dina.kvl.dk>
6432 ;; IF article has cancel-lock THEN
6433 ;; IF we can verify it THEN
6436 ;; error: cancellock: article is not yours
6438 ;; Use old rules, comparing sender...
6441 (message-narrow-to-head-1)
6442 (if (message-fetch-field "Cancel-Lock")
6443 (if (null (canlock-verify))
6445 (error "Failed to verify Cancel-lock: This article is not yours"))
6448 (message-gnksa-enable-p 'cancel-messages)
6449 (and (setq sender (message-fetch-field "sender"))
6450 (string-equal (downcase sender)
6451 (downcase (message-make-sender))))
6452 ;; Email address in From field equals to our address
6453 (and (setq from (message-fetch-field "from"))
6455 (downcase (car (mail-header-parse-address from)))
6456 (downcase (car (mail-header-parse-address
6457 (message-make-from))))))
6458 ;; Email address in From field matches
6459 ;; 'message-alternative-emails' regexp
6461 message-alternative-emails
6463 message-alternative-emails
6464 (car (mail-header-parse-address from))))))))))
6467 (defun message-cancel-news (&optional arg)
6468 "Cancel an article you posted.
6469 If ARG, allow editing of the cancellation message."
6471 (unless (message-news-p)
6472 (error "This is not a news article; canceling is impossible"))
6473 (let (from newsgroups message-id distribution buf)
6475 ;; Get header info from original article.
6477 (message-narrow-to-head-1)
6478 (setq from (message-fetch-field "from")
6479 newsgroups (message-fetch-field "newsgroups")
6480 message-id (message-fetch-field "message-id" t)
6481 distribution (message-fetch-field "distribution")))
6482 ;; Make sure that this article was written by the user.
6483 (unless (message-is-yours-p)
6484 (error "This article is not yours"))
6485 (when (yes-or-no-p "Do you really want to cancel this article? ")
6486 ;; Make control message.
6489 (setq buf (set-buffer (get-buffer-create " *message cancel*"))))
6491 (insert "Newsgroups: " newsgroups "\n"
6493 "Subject: cmsg cancel " message-id "\n"
6494 "Control: cancel " message-id "\n"
6496 (concat "Distribution: " distribution "\n")
6498 mail-header-separator "\n"
6499 message-cancel-message)
6500 (run-hooks 'message-cancel-hook)
6502 (message "Canceling your article...")
6503 (if (let ((message-syntax-checks
6504 'dont-check-for-anything-just-trust-me))
6505 (funcall message-send-news-function))
6506 (message "Canceling your article...done"))
6507 (kill-buffer buf))))))
6510 (defun message-supersede ()
6511 "Start composing a message to supersede the current message.
6512 This is done simply by taking the old article and adding a Supersedes
6513 header line with the old Message-ID."
6515 (let ((cur (current-buffer)))
6516 ;; Check whether the user owns the article that is to be superseded.
6517 (unless (message-is-yours-p)
6518 (error "This article is not yours"))
6519 ;; Get a normal message buffer.
6520 (message-pop-to-buffer (message-buffer-name "supersede"))
6521 (insert-buffer-substring cur)
6523 (message-narrow-to-head-1)
6524 ;; Remove unwanted headers.
6525 (when message-ignored-supersedes-headers
6526 (message-remove-header message-ignored-supersedes-headers t))
6527 (goto-char (point-min))
6528 (if (not (re-search-forward "^Message-ID: " nil t))
6529 (error "No Message-ID in this article")
6530 (replace-match "Supersedes: " t t))
6531 (goto-char (point-max))
6532 (insert mail-header-separator)
6537 (defun message-recover ()
6538 "Reread contents of current buffer from its last auto-save file."
6540 (let ((file-name (make-auto-save-file-name)))
6541 (cond ((save-window-excursion
6542 (if (not (eq system-type 'vax-vms))
6543 (with-output-to-temp-buffer "*Directory*"
6544 (with-current-buffer standard-output
6545 (fundamental-mode)) ; for Emacs 20.4+
6546 (buffer-disable-undo standard-output)
6547 (let ((default-directory "/"))
6549 "ls" nil standard-output nil "-l" file-name))))
6550 (yes-or-no-p (format "Recover auto save file %s? " file-name)))
6551 (let ((buffer-read-only nil))
6553 (insert-file-contents file-name nil)))
6554 (t (error "message-recover cancelled")))))
6556 ;;; Washing Subject:
6558 (defun message-wash-subject (subject)
6559 "Remove junk like \"Re:\", \"(fwd)\", etc. added to subject string SUBJECT.
6560 Previous forwarders, replyers, etc. may add it."
6563 (goto-char (point-min))
6564 ;; strip Re/Fwd stuff off the beginning
6565 (while (re-search-forward
6566 "\\([Rr][Ee]:\\|[Ff][Ww][Dd]\\(\\[[0-9]*\\]\\)?:\\|[Ff][Ww]:\\)" nil t)
6569 ;; and gnus-style forwards [foo@bar.com] subject
6570 (goto-char (point-min))
6571 (while (re-search-forward "\\[[^ \t]*\\(@\\|\\.\\)[^ \t]*\\]" nil t)
6575 (goto-char (point-max))
6576 (while (re-search-backward "([Ff][Ww][Dd])" nil t)
6579 ;; and finally, any whitespace that was left-over
6580 (goto-char (point-min))
6581 (while (re-search-forward "^[ \t]+" nil t)
6583 (goto-char (point-max))
6584 (while (re-search-backward "[ \t]+$" nil t)
6589 ;;; Forwarding messages.
6591 (defvar message-forward-decoded-p nil
6592 "Non-nil means the original message is decoded.")
6594 (defun message-forward-subject-name-subject (subject)
6595 "Generate a SUBJECT for a forwarded message.
6596 The form is: [Source] Subject, where if the original message was mail,
6597 Source is the name of the sender, and if the original message was
6598 news, Source is the list of newsgroups is was posted to."
6599 (let* ((group (message-fetch-field "newsgroups"))
6600 (from (message-fetch-field "from"))
6603 (gnus-group-decoded-name group)
6605 (car (gnus-extract-address-components from))
6606 (cadr (gnus-extract-address-components from))))
6609 (if message-forward-decoded-p
6611 (mail-decode-encoded-word-string prefix))
6614 (defun message-forward-subject-author-subject (subject)
6615 "Generate a SUBJECT for a forwarded message.
6616 The form is: [Source] Subject, where if the original message was mail,
6617 Source is the sender, and if the original message was news, Source is
6618 the list of newsgroups is was posted to."
6619 (let* ((group (message-fetch-field "newsgroups"))
6622 (gnus-group-decoded-name group)
6623 (or (message-fetch-field "from")
6626 (if message-forward-decoded-p
6628 (mail-decode-encoded-word-string prefix))
6631 (defun message-forward-subject-fwd (subject)
6632 "Generate a SUBJECT for a forwarded message.
6633 The form is: Fwd: Subject, where Subject is the original subject of
6635 (if (string-match "^Fwd: " subject)
6637 (concat "Fwd: " subject)))
6639 (defun message-make-forward-subject ()
6640 "Return a Subject header suitable for the message in the current buffer."
6643 (message-narrow-to-head-1)
6644 (let ((funcs message-make-forward-subject-function)
6645 (subject (message-fetch-field "Subject")))
6648 (if message-forward-decoded-p
6650 (mail-decode-encoded-word-string subject))
6652 (when message-wash-forwarded-subjects
6653 (setq subject (message-wash-subject subject)))
6654 ;; Make sure funcs is a list.
6657 (setq funcs (list funcs)))
6658 ;; Apply funcs in order, passing subject generated by previous
6659 ;; func to the next one.
6660 (dolist (func funcs)
6661 (when (functionp func)
6662 (setq subject (funcall func subject))))
6666 (defvar gnus-article-decoded-p))
6670 (defun message-forward (&optional news digest)
6671 "Forward the current message via mail.
6672 Optional NEWS will use news to forward instead of mail.
6673 Optional DIGEST will use digest to forward."
6675 (let* ((cur (current-buffer))
6676 (message-forward-decoded-p
6677 (if (local-variable-p 'gnus-article-decoded-p (current-buffer))
6678 gnus-article-decoded-p ;; In an article buffer.
6679 message-forward-decoded-p))
6680 (subject (message-make-forward-subject)))
6682 (message-news nil subject)
6683 (message-mail nil subject))
6684 (message-forward-make-body cur digest)))
6686 (defun message-forward-make-body-plain (forward-buffer)
6688 "\n-------------------- Start of forwarded message --------------------\n")
6689 (let ((b (point)) e)
6692 (mm-disable-multibyte)
6694 (with-current-buffer forward-buffer
6695 (mm-with-unibyte-current-buffer (buffer-string))))
6696 (mm-enable-multibyte)
6698 (goto-char (point-min))
6699 (when (looking-at "From ")
6700 (replace-match "X-From-Line: "))
6704 "\n-------------------- End of forwarded message --------------------\n")
6705 (message-remove-ignored-headers b e)))
6707 (defun message-remove-ignored-headers (b e)
6708 (when message-forward-ignored-headers
6710 (narrow-to-region b e)
6712 (narrow-to-region (point)
6713 (or (search-forward "\n\n" nil t) (point)))
6714 (let ((ignored (if (stringp message-forward-ignored-headers)
6715 (list message-forward-ignored-headers)
6716 message-forward-ignored-headers)))
6717 (dolist (elem ignored)
6718 (message-remove-header elem t))))))
6720 (defun message-forward-make-body-mime (forward-buffer)
6721 (insert "\n\n<#part type=message/rfc822 disposition=inline raw=t>\n")
6722 (let ((b (point)) e)
6724 (narrow-to-region (point) (point))
6725 (mml-insert-buffer forward-buffer)
6726 (goto-char (point-min))
6727 (when (looking-at "From ")
6728 (replace-match "X-From-Line: "))
6729 (goto-char (point-max)))
6731 (insert "<#/part>\n")))
6733 (defun message-forward-make-body-mml (forward-buffer)
6734 (insert "\n\n<#mml type=message/rfc822 disposition=inline>\n")
6735 (let ((b (point)) e)
6736 (if (not message-forward-decoded-p)
6739 (mm-disable-multibyte)
6741 (with-current-buffer forward-buffer
6742 (mm-with-unibyte-current-buffer (buffer-string))))
6743 (mm-enable-multibyte)
6745 (goto-char (point-min))
6746 (when (looking-at "From ")
6747 (replace-match "X-From-Line: "))
6750 (narrow-to-region (point) (point))
6751 (mml-insert-buffer forward-buffer)
6752 (goto-char (point-min))
6753 (when (looking-at "From ")
6754 (replace-match "X-From-Line: "))
6755 (goto-char (point-max))))
6757 (insert "<#/mml>\n")
6758 (when (and (not message-forward-decoded-p)
6759 message-forward-ignored-headers)
6760 (message-remove-ignored-headers b e))))
6762 (defun message-forward-make-body-digest-plain (forward-buffer)
6764 "\n-------------------- Start of forwarded message --------------------\n")
6765 (let ((b (point)) e)
6766 (mml-insert-buffer forward-buffer)
6769 "\n-------------------- End of forwarded message --------------------\n")))
6771 (defun message-forward-make-body-digest-mime (forward-buffer)
6772 (insert "\n<#multipart type=digest>\n")
6773 (let ((b (point)) e)
6774 (insert-buffer-substring forward-buffer)
6776 (insert "<#/multipart>\n")
6778 (narrow-to-region b e)
6780 (narrow-to-region (point)
6781 (or (search-forward "\n\n" nil t) (point)))
6782 (delete-region (point-min) (point-max)))))
6784 (defun message-forward-make-body-digest (forward-buffer)
6785 (if message-forward-as-mime
6786 (message-forward-make-body-digest-mime forward-buffer)
6787 (message-forward-make-body-digest-plain forward-buffer)))
6790 (defun message-forward-make-body (forward-buffer &optional digest)
6791 ;; Put point where we want it before inserting the forwarded
6793 (if message-forward-before-signature
6795 (goto-char (point-max)))
6797 (message-forward-make-body-digest forward-buffer)
6798 (if message-forward-as-mime
6799 (if (and message-forward-show-mml
6800 (not (and (eq message-forward-show-mml 'best)
6801 (with-current-buffer forward-buffer
6802 (goto-char (point-min))
6804 "Content-Type: *multipart/\\(signed\\|encrypted\\)"
6806 (message-forward-make-body-mml forward-buffer)
6807 (message-forward-make-body-mime forward-buffer))
6808 (message-forward-make-body-plain forward-buffer)))
6809 (message-position-point))
6812 (defun message-forward-rmail-make-body (forward-buffer)
6813 (save-window-excursion
6814 (set-buffer forward-buffer)
6815 (if (rmail-msg-is-pruned)
6816 (rmail-msg-restore-non-pruned-header)))
6817 (message-forward-make-body forward-buffer))
6819 (eval-when-compile (defvar rmail-enable-mime-composing))
6821 ;; Fixme: Should have defcustom.
6823 (defun message-insinuate-rmail ()
6824 "Let RMAIL use message to forward."
6826 (setq rmail-enable-mime-composing t)
6827 (setq rmail-insert-mime-forwarded-message-function
6828 'message-forward-rmail-make-body))
6831 (defun message-resend (address)
6832 "Resend the current article to ADDRESS."
6834 (list (message-read-from-minibuffer "Resend message to: ")))
6835 (message "Resending message to %s..." address)
6837 (let ((cur (current-buffer))
6839 ;; We first set up a normal mail buffer.
6840 (unless (message-mail-user-agent)
6841 (set-buffer (get-buffer-create " *message resend*"))
6843 (let ((message-this-is-mail t)
6844 message-generate-hashcash
6846 (message-setup `((To . ,address))))
6847 ;; Insert our usual headers.
6848 (message-generate-headers '(From Date To Message-ID))
6849 (message-narrow-to-headers)
6850 ;; Remove X-Draft-From header etc.
6851 (message-remove-header message-ignored-mail-headers t)
6852 ;; Rename them all to "Resent-*".
6853 (goto-char (point-min))
6854 (while (re-search-forward "^[A-Za-z]" nil t)
6859 (delete-region (point) (point-max))
6861 ;; Insert the message to be resent.
6862 (insert-buffer-substring cur)
6863 (goto-char (point-min))
6864 (search-forward "\n\n")
6867 (narrow-to-region beg (point))
6868 (message-remove-header message-ignored-resent-headers t)
6869 (goto-char (point-max)))
6870 (insert mail-header-separator)
6871 ;; Rename all old ("Also-")Resent headers.
6872 (while (re-search-backward "^\\(Also-\\)*Resent-" beg t)
6875 ;; Quote any "From " lines at the beginning.
6877 (when (looking-at "From ")
6878 (replace-match "X-From-Line: "))
6880 (let ((message-inhibit-body-encoding t)
6881 message-required-mail-headers
6882 message-generate-hashcash
6883 rfc2047-encode-encoded-words)
6884 (message-send-mail))
6885 (kill-buffer (current-buffer)))
6886 (message "Resending message to %s...done" address)))
6889 (defun message-bounce ()
6890 "Re-mail the current message.
6891 This only makes sense if the current message is a bounce message that
6892 contains some mail you have written which has been bounced back to
6895 (let ((handles (mm-dissect-buffer t))
6897 (message-pop-to-buffer (message-buffer-name "bounce"))
6898 (if (stringp (car handles))
6899 ;; This is a MIME bounce.
6900 (mm-insert-part (car (last handles)))
6901 ;; This is a non-MIME bounce, so we try to remove things
6903 (mm-insert-part handles)
6905 (goto-char (point-min))
6906 (re-search-forward "\n\n+" nil t)
6907 (setq boundary (point))
6908 ;; We remove everything before the bounced mail.
6909 (if (or (re-search-forward message-unsent-separator nil t)
6911 (search-forward "\n\n" nil 'move)
6912 (re-search-backward "^Return-Path:.*\n" boundary t)))
6915 (delete-region (point-min)
6916 (if (re-search-forward "^[^ \n\t]+:" nil t)
6919 (goto-char boundary)
6920 (when (re-search-backward "^.?From .*\n" nil t)
6921 (delete-region (match-beginning 0) (match-end 0)))))
6922 (mm-enable-multibyte)
6924 (message-narrow-to-head-1)
6925 (message-remove-header message-ignored-bounced-headers t)
6926 (goto-char (point-max))
6927 (insert mail-header-separator))
6928 (message-position-point)))
6931 ;;; Interactive entry points for new message buffers.
6935 (defun message-mail-other-window (&optional to subject)
6936 "Like `message-mail' command, but display mail buffer in another window."
6938 (unless (message-mail-user-agent)
6939 (let ((pop-up-windows t)
6940 (special-display-buffer-names nil)
6941 (special-display-regexps nil)
6942 (same-window-buffer-names nil)
6943 (same-window-regexps nil))
6944 (message-pop-to-buffer (message-buffer-name "mail" to))))
6945 (let ((message-this-is-mail t))
6946 (message-setup `((To . ,(or to "")) (Subject . ,(or subject "")))
6947 nil nil 'switch-to-buffer-other-window)))
6950 (defun message-mail-other-frame (&optional to subject)
6951 "Like `message-mail' command, but display mail buffer in another frame."
6953 (unless (message-mail-user-agent)
6954 (let ((pop-up-frames t)
6955 (special-display-buffer-names nil)
6956 (special-display-regexps nil)
6957 (same-window-buffer-names nil)
6958 (same-window-regexps nil))
6959 (message-pop-to-buffer (message-buffer-name "mail" to))))
6960 (let ((message-this-is-mail t))
6961 (message-setup `((To . ,(or to "")) (Subject . ,(or subject "")))
6962 nil nil 'switch-to-buffer-other-frame)))
6965 (defun message-news-other-window (&optional newsgroups subject)
6966 "Start editing a news article to be sent."
6968 (let ((pop-up-windows t)
6969 (special-display-buffer-names nil)
6970 (special-display-regexps nil)
6971 (same-window-buffer-names nil)
6972 (same-window-regexps nil))
6973 (message-pop-to-buffer (message-buffer-name "posting" nil newsgroups)))
6974 (let ((message-this-is-news t))
6975 (message-setup `((Newsgroups . ,(or newsgroups ""))
6976 (Subject . ,(or subject ""))))))
6979 (defun message-news-other-frame (&optional newsgroups subject)
6980 "Start editing a news article to be sent."
6982 (let ((pop-up-frames t)
6983 (special-display-buffer-names nil)
6984 (special-display-regexps nil)
6985 (same-window-buffer-names nil)
6986 (same-window-regexps nil))
6987 (message-pop-to-buffer (message-buffer-name "posting" nil newsgroups)))
6988 (let ((message-this-is-news t))
6989 (message-setup `((Newsgroups . ,(or newsgroups ""))
6990 (Subject . ,(or subject ""))))))
6994 ;; This code should be moved to underline.el (from which it is stolen).
6997 (defun message-bold-region (start end)
6998 "Bold all nonblank characters in the region.
6999 Works by overstriking characters.
7000 Called from program, takes two arguments START and END
7001 which specify the range to operate on."
7004 (let ((end1 (make-marker)))
7005 (move-marker end1 (max start end))
7006 (goto-char (min start end))
7007 (while (< (point) end1)
7008 (or (looking-at "[_\^@- ]")
7009 (insert (char-after) "\b"))
7010 (forward-char 1)))))
7013 (defun message-unbold-region (start end)
7014 "Remove all boldness (overstruck characters) in the region.
7015 Called from program, takes two arguments START and END
7016 which specify the range to operate on."
7019 (let ((end1 (make-marker)))
7020 (move-marker end1 (max start end))
7021 (goto-char (min start end))
7022 (while (search-forward "\b" end1 t)
7023 (if (eq (char-after) (char-after (- (point) 2)))
7024 (delete-char -2))))))
7026 (defun message-exchange-point-and-mark ()
7027 "Exchange point and mark, but don't activate region if it was inactive."
7029 (message-mark-active-p)
7030 (exchange-point-and-mark))
7031 (setq mark-active nil)))
7033 (defalias 'message-make-overlay 'make-overlay)
7034 (defalias 'message-delete-overlay 'delete-overlay)
7035 (defalias 'message-overlay-put 'overlay-put)
7036 (defun message-kill-all-overlays ()
7037 (if (featurep 'xemacs)
7038 (map-extents (lambda (extent ignore) (delete-extent extent)))
7039 (mapcar #'delete-overlay (overlays-in (point-min) (point-max)))))
7041 ;; Support for toolbar
7043 (defvar tool-bar-mode))
7045 ;; Note: The :set function in the `message-tool-bar*' variables will only
7046 ;; affect _new_ message buffers. We might add a function that walks thru all
7047 ;; message-mode buffers and force the update.
7048 (defun message-tool-bar-update (&optional symbol value)
7049 "Update message mode toolbar.
7050 Setter function for custom variables."
7051 (setq-default message-tool-bar-map nil)
7053 ;; When used as ":set" function:
7054 (set-default symbol value)))
7056 (defcustom message-tool-bar (if (eq gmm-tool-bar-style 'gnome)
7057 'message-tool-bar-gnome
7058 'message-tool-bar-retro)
7059 "Specifies the message mode tool bar.
7061 It can be either a list or a symbol refering to a list. See
7062 `gmm-tool-bar-from-list' for the format of the list. The
7063 default key map is `message-mode-map'.
7065 Pre-defined symbols include `message-tool-bar-gnome' and
7066 `message-tool-bar-retro'."
7067 :type '(repeat gmm-tool-bar-list-item)
7068 :type '(choice (const :tag "GNOME style" message-tool-bar-gnome)
7069 (const :tag "Retro look" message-tool-bar-retro)
7070 (repeat :tag "User defined list" gmm-tool-bar-item)
7072 :version "23.0" ;; No Gnus
7073 :initialize 'custom-initialize-default
7074 :set 'message-tool-bar-update
7077 (defcustom message-tool-bar-gnome
7078 '((ispell-message "spell" nil
7079 :visible (or (not (boundp 'flyspell-mode))
7080 (not flyspell-mode)))
7081 (flyspell-buffer "spell" t
7082 :visible (and (boundp 'flyspell-mode)
7084 :help "Flyspell whole buffer")
7085 (gmm-ignore "separator")
7086 (message-send-and-exit "mail/send")
7087 (message-dont-send "mail/save-draft")
7088 (message-kill-buffer "close") ;; stock_cancel
7089 (mml-attach-file "attach" mml-mode-map)
7090 (mml-preview "mail/preview" mml-mode-map)
7091 (mml-secure-message-sign-encrypt "lock" mml-mode-map :visible nil)
7092 (message-insert-importance-high "important" nil :visible nil)
7093 (message-insert-importance-low "unimportant" nil :visible nil)
7094 (message-insert-disposition-notification-to "receipt" nil :visible nil)
7095 (gmm-customize-mode "preferences" t :help "Edit mode preferences")
7096 (message-info "help" t :help "Message manual"))
7097 "List of items for the message tool bar (GNOME style).
7099 See `gmm-tool-bar-from-list' for details on the format of the list."
7100 :type '(repeat gmm-tool-bar-item)
7101 :version "23.0" ;; No Gnus
7102 :initialize 'custom-initialize-default
7103 :set 'message-tool-bar-update
7106 (defcustom message-tool-bar-retro
7107 '(;; Old Emacs 21 icon for consistency.
7108 (message-send-and-exit "gnus/mail_send")
7109 (message-kill-buffer "close")
7110 (message-dont-send "cancel")
7111 (mml-attach-file "attach" mml-mode-map)
7112 (ispell-message "spell")
7113 (mml-preview "preview" mml-mode-map)
7114 (message-insert-importance-high "gnus/important")
7115 (message-insert-importance-low "gnus/unimportant")
7116 (message-insert-disposition-notification-to "gnus/receipt"))
7117 "List of items for the message tool bar (retro style).
7119 See `gmm-tool-bar-from-list' for details on the format of the list."
7120 :type '(repeat gmm-tool-bar-item)
7121 :version "23.0" ;; No Gnus
7122 :initialize 'custom-initialize-default
7123 :set 'message-tool-bar-update
7126 (defcustom message-tool-bar-zap-list
7127 '(new-file open-file dired kill-buffer write-file
7128 print-buffer customize help)
7129 "List of icon items from the global tool bar.
7130 These items are not displayed on the message mode tool bar.
7132 See `gmm-tool-bar-from-list' for the format of the list."
7133 :type 'gmm-tool-bar-zap-list
7134 :version "23.0" ;; No Gnus
7135 :initialize 'custom-initialize-default
7136 :set 'message-tool-bar-update
7139 (defvar image-load-path)
7141 (defun message-make-tool-bar (&optional force)
7142 "Make a message mode tool bar from `message-tool-bar-list'.
7143 When FORCE, rebuild the tool bar."
7144 (when (and (not (featurep 'xemacs))
7145 (boundp 'tool-bar-mode)
7147 (or (not message-tool-bar-map) force))
7148 (setq message-tool-bar-map
7150 (gmm-image-load-path-for-library "message"
7151 "mail/save-draft.xpm"
7153 (image-load-path (cons (car load-path)
7154 (when (boundp 'image-load-path)
7156 (gmm-tool-bar-from-list message-tool-bar
7157 message-tool-bar-zap-list
7158 'message-mode-map))))
7159 message-tool-bar-map)
7161 ;;; Group name completion.
7163 (defcustom message-newgroups-header-regexp
7164 "^\\(Newsgroups\\|Followup-To\\|Posted-To\\|Gcc\\):"
7165 "Regexp that match headers that lists groups."
7169 (defcustom message-completion-alist
7170 (list (cons message-newgroups-header-regexp 'message-expand-group)
7171 '("^\\(Resent-\\)?\\(To\\|B?Cc\\):" . message-expand-name)
7172 '("^\\(Reply-To\\|From\\|Mail-Followup-To\\|Mail-Copies-To\\):"
7173 . message-expand-name)
7174 '("^\\(Disposition-Notification-To\\|Return-Receipt-To\\):"
7175 . message-expand-name))
7176 "Alist of (RE . FUN). Use FUN for completion on header lines matching RE."
7179 :type '(alist :key-type regexp :value-type function))
7181 (defcustom message-expand-name-databases
7183 "List of databases to try for name completion (`message-expand-name').
7184 Each element is a symbol and can be `bbdb' or `eudc'."
7186 :type '(set (const bbdb) (const eudc)))
7188 (defcustom message-tab-body-function nil
7189 "*Function to execute when `message-tab' (TAB) is executed in the body.
7190 If nil, the function bound in `text-mode-map' or `global-map' is executed."
7193 :link '(custom-manual "(message)Various Commands")
7194 :type '(choice (const nil)
7197 (defun message-tab ()
7198 "Complete names according to `message-completion-alist'.
7199 Execute function specified by `message-tab-body-function' when not in
7202 (let ((alist message-completion-alist))
7204 (let ((mail-abbrev-mode-regexp (caar alist)))
7205 (not (mail-abbrev-in-expansion-header-p))))
7206 (setq alist (cdr alist)))
7207 (funcall (or (cdar alist) message-tab-body-function
7208 (lookup-key text-mode-map "\t")
7209 (lookup-key global-map "\t")
7210 'indent-relative))))
7215 (let ((standard-output (current-buffer)))
7216 (eval '(display-completion-list nil "")))
7217 (defalias 'message-display-completion-list 'display-completion-list))
7218 (error ;; Don't use `wrong-number-of-arguments' here because of XEmacs.
7219 (defun message-display-completion-list (completions &optional ignore)
7220 "Display the list of completions, COMPLETIONS, using `standard-output'."
7221 (display-completion-list completions)))))
7223 (defun message-expand-group ()
7224 "Expand the group name under point."
7225 (let* ((b (save-excursion
7230 (skip-chars-forward "^:")
7233 (skip-chars-backward "^, \t\n") (point))))
7234 (completion-ignore-case t)
7235 (string (buffer-substring b (progn (skip-chars-forward "^,\t\n ")
7237 (hashtb (and (boundp 'gnus-active-hashtb) gnus-active-hashtb))
7238 (completions (all-completions string hashtb))
7240 (delete-region b (point))
7242 ((= (length completions) 1)
7243 (if (string= (car completions) string)
7246 (message "Only matching group"))
7247 (insert (car completions))))
7248 ((and (setq comp (try-completion string hashtb))
7249 (not (string= comp string)))
7254 (message "No matching groups")
7255 (save-selected-window
7256 (pop-to-buffer "*Completions*")
7257 (buffer-disable-undo)
7258 (let ((buffer-read-only nil))
7260 (let ((standard-output (current-buffer)))
7261 (message-display-completion-list (sort completions 'string<)
7263 (setq buffer-read-only nil)
7264 (goto-char (point-min))
7265 (delete-region (point) (progn (forward-line 3) (point))))))))))
7267 (defun message-expand-name ()
7268 (cond ((and (memq 'eudc message-expand-name-databases)
7269 (boundp 'eudc-protocol)
7271 (eudc-expand-inline))
7272 ((and (memq 'bbdb message-expand-name-databases)
7273 (fboundp 'bbdb-complete-name))
7274 (bbdb-complete-name))
7280 (defun message-talkative-question (ask question show &rest text)
7281 "Call FUNCTION with argument QUESTION; optionally display TEXT... args.
7282 If SHOW is non-nil, the arguments TEXT... are displayed in a temp buffer.
7283 The following arguments may contain lists of values."
7285 (setq text (message-flatten-list text)))
7286 (save-window-excursion
7288 (with-output-to-temp-buffer " *MESSAGE information message*"
7289 (set-buffer " *MESSAGE information message*")
7290 (fundamental-mode) ; for Emacs 20.4+
7291 (mapcar 'princ text)
7292 (goto-char (point-min))))
7293 (funcall ask question))
7294 (funcall ask question)))
7296 (defun message-flatten-list (list)
7297 "Return a new, flat list that contains all elements of LIST.
7299 \(message-flatten-list '(1 (2 3 (4 5 (6))) 7))
7302 (apply 'append (mapcar 'message-flatten-list list)))
7306 (defun message-generate-new-buffer-clone-locals (name &optional varstr)
7307 "Create and return a buffer with name based on NAME using `generate-new-buffer'.
7308 Then clone the local variables and values from the old buffer to the
7309 new one, cloning only the locals having a substring matching the
7311 (let ((oldbuf (current-buffer)))
7313 (set-buffer (generate-new-buffer name))
7314 (message-clone-locals oldbuf varstr)
7317 (defun message-clone-locals (buffer &optional varstr)
7318 "Clone the local variables from BUFFER to the current buffer."
7319 (let ((locals (save-excursion
7321 (buffer-local-variables)))
7322 (regexp "^gnus\\|^nn\\|^message\\|^sendmail\\|^smtp\\|^user-mail-address"))
7325 (when (and (consp local)
7327 (string-match regexp (symbol-name (car local)))
7329 (string-match varstr (symbol-name (car local)))))
7331 (set (make-local-variable (car local))
7339 (defvar message-inhibit-body-encoding nil)
7341 (defun message-encode-message-body ()
7342 (unless message-inhibit-body-encoding
7343 (let ((mail-parse-charset (or mail-parse-charset
7344 message-default-charset))
7345 (case-fold-search t)
7346 lines content-type-p)
7349 (narrow-to-region (point) (point-max))
7350 (let ((new (mml-generate-mime)))
7352 (delete-region (point-min) (point-max))
7354 (goto-char (point-min))
7355 (if (eq (aref new 0) ?\n)
7357 (search-forward "\n\n")
7358 (setq lines (buffer-substring (point-min) (1- (point))))
7359 (delete-region (point-min) (point))))))
7361 (message-narrow-to-headers-or-head)
7362 (message-remove-header "Mime-Version")
7363 (goto-char (point-max))
7364 (insert "MIME-Version: 1.0\n")
7367 (setq content-type-p
7369 (re-search-backward "^Content-Type:" nil t))))
7371 (message-narrow-to-headers-or-head)
7372 (message-remove-first-header "Content-Type")
7373 (message-remove-first-header "Content-Transfer-Encoding"))
7374 ;; We always make sure that the message has a Content-Type
7375 ;; header. This is because some broken MTAs and MUAs get
7376 ;; awfully confused when confronted with a message with a
7377 ;; MIME-Version header and without a Content-Type header. For
7378 ;; instance, Solaris' /usr/bin/mail.
7379 (unless content-type-p
7380 (goto-char (point-min))
7381 ;; For unknown reason, MIME-Version doesn't exist.
7382 (when (re-search-forward "^MIME-Version:" nil t)
7384 (insert "Content-Type: text/plain; charset=us-ascii\n"))))))
7386 (defun message-read-from-minibuffer (prompt &optional initial-contents)
7387 "Read from the minibuffer while providing abbrev expansion."
7388 (if (fboundp 'mail-abbrevs-setup)
7389 (let ((mail-abbrev-mode-regexp "")
7390 (minibuffer-setup-hook 'mail-abbrevs-setup)
7391 (minibuffer-local-map message-minibuffer-local-map))
7392 (read-from-minibuffer prompt initial-contents))
7393 (let ((minibuffer-setup-hook 'mail-abbrev-minibuffer-setup-hook)
7394 (minibuffer-local-map message-minibuffer-local-map))
7395 (read-string prompt initial-contents))))
7397 (defun message-use-alternative-email-as-from ()
7398 "Set From field of the outgoing message to the first matching
7399 address in `message-alternative-emails', looking at To, Cc and
7400 From headers in the original article."
7401 (require 'mail-utils)
7402 (let* ((fields '("To" "Cc" "From"))
7405 (mail-strip-quoted-names
7406 (mapconcat 'message-fetch-reply-field fields ","))
7410 (if (string-match message-alternative-emails (car emails))
7411 (setq email (car emails)
7414 (unless (or (not email) (equal email user-mail-address))
7415 (message-remove-header "From")
7416 (goto-char (point-max))
7417 (insert "From: " (let ((user-mail-address email)) (message-make-from))
7420 (defun message-options-get (symbol)
7421 (cdr (assq symbol message-options)))
7423 (defun message-options-set (symbol value)
7424 (let ((the-cons (assq symbol message-options)))
7427 (setcdr the-cons value)
7428 (setq message-options (delq the-cons message-options)))
7430 (push (cons symbol value) message-options))))
7433 (defun message-options-set-recipient ()
7435 (message-narrow-to-headers-or-head)
7436 (message-options-set 'message-sender
7437 (mail-strip-quoted-names
7438 (message-fetch-field "from")))
7439 (message-options-set 'message-recipients
7440 (mail-strip-quoted-names
7441 (let ((to (message-fetch-field "to"))
7442 (cc (message-fetch-field "cc"))
7443 (bcc (message-fetch-field "bcc")))
7446 (if (and to cc) ", ")
7448 (if (and (or to cc) bcc) ", ")
7451 (defun message-hide-headers ()
7452 "Hide headers based on the `message-hidden-headers' variable."
7453 (let ((regexps (if (stringp message-hidden-headers)
7454 (list message-hidden-headers)
7455 message-hidden-headers))
7456 (inhibit-point-motion-hooks t)
7457 (after-change-functions nil)
7462 (message-narrow-to-headers)
7463 (goto-char (point-min))
7465 (if (not (message-hide-header-p regexps))
7466 (message-next-header)
7467 (let ((begin (point))
7469 (message-next-header)
7470 (setq header (buffer-substring begin (point))
7471 header-len (- (point) begin))
7472 (delete-region begin (point))
7473 (goto-char (1+ end-of-headers))
7475 (setq end-of-headers
7476 (+ end-of-headers header-len))))))))
7477 (narrow-to-region (1+ end-of-headers) (point-max))))
7479 (defun message-hide-header-p (regexps)
7482 (when (eq (car regexps) 'not)
7485 (dolist (regexp regexps)
7486 (setq result (or result (looking-at regexp))))
7491 (defun message-put-addresses-in-ecomplete ()
7492 (dolist (header '("to" "cc" "from" "reply-to"))
7493 (let ((value (message-fetch-field header)))
7494 (dolist (string (mail-header-parse-addresses value 'raw))
7496 (gnus-replace-in-string
7497 (gnus-replace-in-string string "^ +\\| +$" "") "\n" ""))
7498 (ecomplete-add-item 'mail (car (mail-header-parse-address string))
7502 (defun message-display-abbrev (&optional choose)
7503 "Display the next possible abbrev for the text before point."
7504 (interactive (list t))
7505 (when (and (member (char-after (point-at-bol)) '(?C ?T ? ))
7506 (message-point-in-header-p)
7509 (message-narrow-to-field)
7510 (goto-char (point-min))
7511 (looking-at "To\\|Cc"))))
7512 (let* ((end (point))
7513 (start (save-excursion
7514 (and (re-search-backward "[\n\t ]" nil t)
7516 (word (when start (buffer-substring start end)))
7517 (match (when (and word
7518 (not (zerop (length word))))
7519 (ecomplete-display-matches 'mail word choose))))
7520 (when (and choose match)
7521 (delete-region start end)
7524 (when (featurep 'xemacs)
7525 (require 'messagexmas)
7526 (message-xmas-redefine))
7530 (run-hooks 'message-load-hook)
7533 ;; coding: iso-8859-1
7536 ;; arch-tag: 94b32cac-4504-4b6c-8181-030ebf380ee0
7537 ;;; message.el ends here