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
42 ;; This is apparently necessary even though things are autoloaded.
43 ;; Because we dynamically bind mail-abbrev-mode-regexp, we'd better
44 ;; require mailabbrev here.
45 (if (featurep 'xemacs)
46 (require 'mail-abbrevs)
47 (require 'mailabbrev))
52 (autoload 'gnus-find-method-for-group "gnus")
53 (autoload 'nnvirtual-find-group-art "nnvirtual")
54 (autoload 'gnus-group-decoded-name "gnus-group"))
56 (defgroup message '((user-mail-address custom-variable)
57 (user-full-name custom-variable))
58 "Mail and news message composing."
59 :link '(custom-manual "(message)Top")
63 (put 'user-mail-address 'custom-type 'string)
64 (put 'user-full-name 'custom-type 'string)
66 (defgroup message-various nil
67 "Various Message Variables."
68 :link '(custom-manual "(message)Various Message Variables")
71 (defgroup message-buffers nil
73 :link '(custom-manual "(message)Message Buffers")
76 (defgroup message-sending nil
78 :link '(custom-manual "(message)Sending Variables")
81 (defgroup message-interface nil
83 :link '(custom-manual "(message)Interface")
86 (defgroup message-forwarding nil
88 :link '(custom-manual "(message)Forwarding")
89 :group 'message-interface)
91 (defgroup message-insertion nil
93 :link '(custom-manual "(message)Insertion")
96 (defgroup message-headers nil
98 :link '(custom-manual "(message)Message Headers")
101 (defgroup message-news nil
102 "Composing News Messages."
105 (defgroup message-mail nil
106 "Composing Mail Messages."
109 (defgroup message-faces nil
110 "Faces used for message composing."
114 (defcustom message-directory "~/Mail/"
115 "*Directory from which all other mail file variables are derived."
116 :group 'message-various
119 (defcustom message-max-buffers 10
120 "*How many buffers to keep before starting to kill them off."
121 :group 'message-buffers
124 (defcustom message-send-rename-function nil
125 "Function called to rename the buffer after sending it."
126 :group 'message-buffers
127 :type '(choice function (const nil)))
129 (defcustom message-fcc-handler-function 'message-output
130 "*A function called to save outgoing articles.
131 This function will be called with the name of the file to store the
132 article in. The default function is `message-output' which saves in Unix
134 :type '(radio (function-item message-output)
135 (function :tag "Other"))
136 :group 'message-sending)
138 (defcustom message-fcc-externalize-attachments nil
139 "If non-nil, attachments are included as external parts in Fcc copies."
142 :group 'message-sending)
144 (defcustom message-courtesy-message
145 "The following message is a courtesy copy of an article\nthat has been posted to %s as well.\n\n"
146 "*This is inserted at the start of a mailed copy of a posted message.
147 If the string contains the format spec \"%s\", the Newsgroups
148 the article has been posted to will be inserted there.
149 If this variable is nil, no such courtesy message will be added."
150 :group 'message-sending
151 :type '(radio string (const nil)))
153 (defcustom message-ignored-bounced-headers
154 "^\\(Received\\|Return-Path\\|Delivered-To\\):"
155 "*Regexp that matches headers to be removed in resent bounced mail."
156 :group 'message-interface
160 (defcustom message-from-style 'default
161 "*Specifies how \"From\" headers look.
163 If nil, they contain just the return address like:
165 If `parens', they look like:
166 king@grassland.com (Elvis Parsley)
167 If `angles', they look like:
168 Elvis Parsley <king@grassland.com>
170 Otherwise, most addresses look like `angles', but they look like
171 `parens' if `angles' would need quoting and `parens' would not."
172 :type '(choice (const :tag "simple" nil)
176 :group 'message-headers)
178 (defcustom message-insert-canlock t
179 "Whether to insert a Cancel-Lock header in news postings."
181 :group 'message-headers
184 (defcustom message-syntax-checks
185 (if message-insert-canlock '((sender . disabled)) nil)
186 ;; Guess this one shouldn't be easy to customize...
187 "*Controls what syntax checks should not be performed on outgoing posts.
188 To disable checking of long signatures, for instance, add
189 `(signature . disabled)' to this list.
191 Don't touch this variable unless you really know what you're doing.
193 Checks include `subject-cmsg', `multiple-headers', `sendsys',
194 `message-id', `from', `long-lines', `control-chars', `size',
195 `new-text', `quoting-style', `redirected-followup', `signature',
196 `approved', `sender', `empty', `empty-headers', `message-id', `from',
197 `subject', `shorten-followup-to', `existing-newsgroups',
198 `buffer-file-name', `unchanged', `newsgroups', `reply-to',
199 `continuation-headers', `long-header-lines', `invisible-text' and
202 :type '(repeat sexp)) ; Fixme: improve this
204 (defcustom message-required-headers '((optional . References)
206 "*Headers to be generated or prompted for when sending a message.
207 Also see `message-required-news-headers' and
208 `message-required-mail-headers'."
211 :group 'message-headers
212 :link '(custom-manual "(message)Message Headers")
213 :type '(repeat sexp))
215 (defcustom message-draft-headers '(References From)
216 "*Headers to be generated when saving a draft message."
219 :group 'message-headers
220 :link '(custom-manual "(message)Message Headers")
221 :type '(repeat sexp))
223 (defcustom message-required-news-headers
224 '(From Newsgroups Subject Date Message-ID
225 (optional . Organization)
226 (optional . User-Agent))
227 "*Headers to be generated or prompted for when posting an article.
228 RFC977 and RFC1036 require From, Date, Newsgroups, Subject,
229 Message-ID. Organization, Lines, In-Reply-To, Expires, and
230 User-Agent are optional. If don't you want message to insert some
231 header, remove it from this list."
233 :group 'message-headers
234 :link '(custom-manual "(message)Message Headers")
235 :type '(repeat sexp))
237 (defcustom message-required-mail-headers
238 '(From Subject Date (optional . In-Reply-To) Message-ID
239 (optional . User-Agent))
240 "*Headers to be generated or prompted for when mailing a message.
241 It is recommended that From, Date, To, Subject and Message-ID be
242 included. Organization and User-Agent are optional."
244 :group 'message-headers
245 :link '(custom-manual "(message)Message Headers")
246 :type '(repeat sexp))
248 (defcustom message-deletable-headers '(Message-ID Date Lines)
249 "Headers to be deleted if they already exist and were generated by message previously."
250 :group 'message-headers
251 :link '(custom-manual "(message)Message Headers")
254 (defcustom message-ignored-news-headers
255 "^NNTP-Posting-Host:\\|^Xref:\\|^[BGF]cc:\\|^Resent-Fcc:\\|^X-Draft-From:\\|^X-Gnus-Agent-Meta-Information:"
256 "*Regexp of headers to be removed unconditionally before posting."
258 :group 'message-headers
259 :link '(custom-manual "(message)Message Headers")
260 :type '(repeat :value-to-internal (lambda (widget value)
261 (custom-split-regexp-maybe value))
262 :match (lambda (widget value)
264 (widget-editable-list-match widget value)))
267 (defcustom message-ignored-mail-headers
268 "^[GF]cc:\\|^Resent-Fcc:\\|^Xref:\\|^X-Draft-From:\\|^X-Gnus-Agent-Meta-Information:"
269 "*Regexp of headers to be removed unconditionally before mailing."
271 :group 'message-headers
272 :link '(custom-manual "(message)Mail Headers")
275 (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:"
276 "*Header lines matching this regexp will be deleted before posting.
277 It's best to delete old Path and Date headers before posting to avoid
279 :group 'message-interface
280 :link '(custom-manual "(message)Superseding")
281 :type '(repeat :value-to-internal (lambda (widget value)
282 (custom-split-regexp-maybe value))
283 :match (lambda (widget value)
285 (widget-editable-list-match widget value)))
288 (defcustom message-subject-re-regexp
289 "^[ \t]*\\([Rr][Ee]\\(\\[[0-9]*\\]\\)*:[ \t]*\\)*[ \t]*"
290 "*Regexp matching \"Re: \" in the subject line."
291 :group 'message-various
292 :link '(custom-manual "(message)Message Headers")
295 ;;; Start of variables adopted from `message-utils.el'.
297 (defcustom message-subject-trailing-was-query 'ask
298 "*What to do with trailing \"(was: <old subject>)\" in subject lines.
299 If nil, leave the subject unchanged. If it is the symbol `ask', query
300 the user what do do. In this case, the subject is matched against
301 `message-subject-trailing-was-ask-regexp'. If
302 `message-subject-trailing-was-query' is t, always strip the trailing
303 old subject. In this case, `message-subject-trailing-was-regexp' is
306 :type '(choice (const :tag "never" nil)
307 (const :tag "always strip" t)
309 :link '(custom-manual "(message)Message Headers")
310 :group 'message-various)
312 (defcustom message-subject-trailing-was-ask-regexp
313 "[ \t]*\\([[(]+[Ww][Aa][Ss][ \t]*.*[\])]+\\)"
314 "*Regexp matching \"(was: <old subject>)\" in the subject line.
316 The function `message-strip-subject-trailing-was' uses this regexp if
317 `message-subject-trailing-was-query' is set to the symbol `ask'. If
318 the variable is t instead of `ask', use
319 `message-subject-trailing-was-regexp' instead.
321 It is okay to create some false positives here, as the user is asked."
323 :group 'message-various
324 :link '(custom-manual "(message)Message Headers")
327 (defcustom message-subject-trailing-was-regexp
328 "[ \t]*\\((*[Ww][Aa][Ss]:[ \t]*.*)\\)"
329 "*Regexp matching \"(was: <old subject>)\" in the subject line.
331 If `message-subject-trailing-was-query' is set to t, the subject is
332 matched against `message-subject-trailing-was-regexp' in
333 `message-strip-subject-trailing-was'. You should use a regexp creating very
334 few false positives here."
336 :group 'message-various
337 :link '(custom-manual "(message)Message Headers")
340 ;;; marking inserted text
342 (defcustom message-mark-insert-begin
343 "--8<---------------cut here---------------start------------->8---\n"
344 "How to mark the beginning of some inserted text."
347 :link '(custom-manual "(message)Insertion Variables")
348 :group 'message-various)
350 (defcustom message-mark-insert-end
351 "--8<---------------cut here---------------end--------------->8---\n"
352 "How to mark the end of some inserted text."
355 :link '(custom-manual "(message)Insertion Variables")
356 :group 'message-various)
358 (defcustom message-archive-header "X-No-Archive: Yes\n"
359 "Header to insert when you don't want your article to be archived.
360 Archives \(such as groups.google.com\) respect this header."
363 :link '(custom-manual "(message)Header Commands")
364 :group 'message-various)
366 (defcustom message-archive-note
367 "X-No-Archive: Yes - save http://groups.google.com/"
368 "Note to insert why you wouldn't want this posting archived.
369 If nil, don't insert any text in the body."
371 :type '(radio string (const nil))
372 :link '(custom-manual "(message)Header Commands")
373 :group 'message-various)
375 ;;; Crossposts and Followups
376 ;; inspired by JoH-followup-to by Jochem Huhman <joh at gmx.de>
377 ;; new suggestions by R. Weikusat <rw at another.de>
379 (defvar message-cross-post-old-target nil
380 "Old target for cross-posts or follow-ups.")
381 (make-variable-buffer-local 'message-cross-post-old-target)
383 (defcustom message-cross-post-default t
384 "When non-nil `message-cross-post-followup-to' will perform a crosspost.
385 If nil, `message-cross-post-followup-to' will only do a followup. Note that
386 you can explicitly override this setting by calling
387 `message-cross-post-followup-to' with a prefix."
390 :group 'message-various)
392 (defcustom message-cross-post-note "Crosspost & Followup-To: "
393 "Note to insert before signature to notify of cross-post and follow-up."
396 :group 'message-various)
398 (defcustom message-followup-to-note "Followup-To: "
399 "Note to insert before signature to notify of follow-up only."
402 :group 'message-various)
404 (defcustom message-cross-post-note-function 'message-cross-post-insert-note
405 "Function to use to insert note about Crosspost or Followup-To.
406 The function will be called with four arguments. The function should not only
407 insert a note, but also ensure old notes are deleted. See the documentation
408 for `message-cross-post-insert-note'."
411 :group 'message-various)
413 ;;; End of variables adopted from `message-utils.el'.
416 (defcustom message-signature-separator "^-- *$"
417 "Regexp matching the signature separator."
419 :link '(custom-manual "(message)Various Message Variables")
420 :group 'message-various)
422 (defcustom message-elide-ellipsis "\n[...]\n\n"
423 "*The string which is inserted for elided text."
425 :link '(custom-manual "(message)Various Commands")
426 :group 'message-various)
428 (defcustom message-interactive t
429 "Non-nil means when sending a message wait for and display errors.
430 nil means let mailer mail back a message to report errors."
431 :group 'message-sending
433 :link '(custom-manual "(message)Sending Variables")
436 (defcustom message-generate-new-buffers 'unique
437 "*Non-nil means create a new message buffer whenever `message-setup' is called.
438 If this is a function, call that function with three parameters: The type,
439 the to address and the group name. (Any of these may be nil.) The function
440 should return the new buffer name."
441 :group 'message-buffers
442 :link '(custom-manual "(message)Message Buffers")
443 :type '(choice (const :tag "off" nil)
444 (const :tag "unique" unique)
445 (const :tag "unsent" unsent)
448 (defcustom message-kill-buffer-on-exit nil
449 "*Non-nil means that the message buffer will be killed after sending a message."
450 :group 'message-buffers
451 :link '(custom-manual "(message)Message Buffers")
455 (defvar gnus-local-organization))
456 (defcustom message-user-organization
457 (or (and (boundp 'gnus-local-organization)
458 (stringp gnus-local-organization)
459 gnus-local-organization)
460 (getenv "ORGANIZATION")
462 "*String to be used as an Organization header.
463 If t, use `message-user-organization-file'."
464 :group 'message-headers
465 :type '(choice string
466 (const :tag "consult file" t)))
469 (defcustom message-user-organization-file "/usr/lib/news/organization"
470 "*Local news organization file."
472 :link '(custom-manual "(message)News Headers")
473 :group 'message-headers)
475 (defcustom message-make-forward-subject-function
476 #'message-forward-subject-name-subject
477 "*List of functions called to generate subject headers for forwarded messages.
478 The subject generated by the previous function is passed into each
481 The provided functions are:
483 * `message-forward-subject-author-subject' Source of article (author or
484 newsgroup), in brackets followed by the subject
485 * `message-forward-subject-name-subject' Source of article (name of author
486 or newsgroup), in brackets followed by the subject
487 * `message-forward-subject-fwd' Subject of article with 'Fwd:' prepended
489 :group 'message-forwarding
490 :link '(custom-manual "(message)Forwarding")
491 :type '(radio (function-item message-forward-subject-author-subject)
492 (function-item message-forward-subject-fwd)
493 (function-item message-forward-subject-name-subject)
494 (repeat :tag "List of functions" function)))
496 (defcustom message-forward-as-mime t
497 "*Non-nil means forward messages as an inline/rfc822 MIME section.
498 Otherwise, directly inline the old message in the forwarded message."
500 :group 'message-forwarding
501 :link '(custom-manual "(message)Forwarding")
504 (defcustom message-forward-show-mml 'best
505 "*Non-nil means show forwarded messages as MML (decoded from MIME).
506 Otherwise, forwarded messages are unchanged.
507 Can also be the symbol `best' to indicate that MML should be
508 used, except when it is a bad idea to use MML. One example where
509 it is a bad idea is when forwarding a signed or encrypted
510 message, because converting MIME to MML would invalidate the
513 :group 'message-forwarding
514 :type '(choice (const :tag "use MML" t)
515 (const :tag "don't use MML " nil)
516 (const :tag "use MML when appropriate" best)))
518 (defcustom message-forward-before-signature t
519 "*Non-nil means put forwarded message before signature, else after."
520 :group 'message-forwarding
523 (defcustom message-wash-forwarded-subjects nil
524 "*Non-nil means try to remove as much cruft as possible from the subject.
525 Done before generating the new subject of a forward."
526 :group 'message-forwarding
527 :link '(custom-manual "(message)Forwarding")
530 (defcustom message-ignored-resent-headers "^Return-receipt\\|^X-Gnus\\|^Gnus-Warning:\\|^>?From "
531 "*All headers that match this regexp will be deleted when resending a message."
532 :group 'message-interface
533 :link '(custom-manual "(message)Resending")
534 :type '(repeat :value-to-internal (lambda (widget value)
535 (custom-split-regexp-maybe value))
536 :match (lambda (widget value)
538 (widget-editable-list-match widget value)))
541 (defcustom message-forward-ignored-headers "^Content-Transfer-Encoding:\\|^X-Gnus"
542 "*All headers that match this regexp will be deleted when forwarding a message."
544 :group 'message-forwarding
545 :type '(repeat :value-to-internal (lambda (widget value)
546 (custom-split-regexp-maybe value))
547 :match (lambda (widget value)
549 (widget-editable-list-match widget value)))
552 (defcustom message-ignored-cited-headers "."
553 "*Delete these headers from the messages you yank."
554 :group 'message-insertion
555 :link '(custom-manual "(message)Insertion Variables")
558 (defcustom message-cite-prefix-regexp
559 (if (string-match "[[:digit:]]" "1") ;; support POSIX?
560 "\\([ \t]*[-_.[:word:]]+>+\\|[ \t]*[]>|}+]\\)+"
561 ;; ?-, ?_ or ?. MUST NOT be in syntax entry w.
562 (let ((old-table (syntax-table))
563 non-word-constituents)
564 (set-syntax-table text-mode-syntax-table)
565 (setq non-word-constituents
567 (if (string-match "\\w" "-") "" "-")
568 (if (string-match "\\w" "_") "" "_")
569 (if (string-match "\\w" ".") "" ".")))
570 (set-syntax-table old-table)
571 (if (equal non-word-constituents "")
572 "\\([ \t]*\\(\\w\\)+>+\\|[ \t]*[]>|}+]\\)+"
573 (concat "\\([ \t]*\\(\\w\\|["
574 non-word-constituents
575 "]\\)+>+\\|[ \t]*[]>|}+]\\)+"))))
576 "*Regexp matching the longest possible citation prefix on a line."
578 :group 'message-insertion
579 :link '(custom-manual "(message)Insertion Variables")
582 (defcustom message-cancel-message "I am canceling my own article.\n"
583 "Message to be inserted in the cancel message."
584 :group 'message-interface
585 :link '(custom-manual "(message)Canceling News")
588 ;; Useful to set in site-init.el
590 (defcustom message-send-mail-function 'message-send-mail-with-sendmail
591 "Function to call to send the current buffer as mail.
592 The headers should be delimited by a line whose contents match the
593 variable `mail-header-separator'.
595 Valid values include `message-send-mail-with-sendmail' (the default),
596 `message-send-mail-with-mh', `message-send-mail-with-qmail',
597 `message-smtpmail-send-it', `smtpmail-send-it' and `feedmail-send-it'.
599 See also `send-mail-function'."
600 :type '(radio (function-item message-send-mail-with-sendmail)
601 (function-item message-send-mail-with-mh)
602 (function-item message-send-mail-with-qmail)
603 (function-item message-smtpmail-send-it)
604 (function-item smtpmail-send-it)
605 (function-item feedmail-send-it)
606 (function :tag "Other"))
607 :group 'message-sending
608 :link '(custom-manual "(message)Mail Variables")
609 :group 'message-mail)
611 (defcustom message-send-news-function 'message-send-news
612 "Function to call to send the current buffer as news.
613 The headers should be delimited by a line whose contents match the
614 variable `mail-header-separator'."
615 :group 'message-sending
617 :link '(custom-manual "(message)News Variables")
620 (defcustom message-reply-to-function nil
621 "If non-nil, function that should return a list of headers.
622 This function should pick out addresses from the To, Cc, and From headers
623 and respond with new To and Cc headers."
624 :group 'message-interface
625 :link '(custom-manual "(message)Reply")
626 :type '(choice function (const nil)))
628 (defcustom message-wide-reply-to-function nil
629 "If non-nil, function that should return a list of headers.
630 This function should pick out addresses from the To, Cc, and From headers
631 and respond with new To and Cc headers."
632 :group 'message-interface
633 :link '(custom-manual "(message)Wide Reply")
634 :type '(choice function (const nil)))
636 (defcustom message-followup-to-function nil
637 "If non-nil, function that should return a list of headers.
638 This function should pick out addresses from the To, Cc, and From headers
639 and respond with new To and Cc headers."
640 :group 'message-interface
641 :link '(custom-manual "(message)Followup")
642 :type '(choice function (const nil)))
644 (defcustom message-use-followup-to 'ask
645 "*Specifies what to do with Followup-To header.
646 If nil, always ignore the header. If it is t, use its value, but
647 query before using the \"poster\" value. If it is the symbol `ask',
648 always query the user whether to use the value. If it is the symbol
649 `use', always use the value."
650 :group 'message-interface
651 :link '(custom-manual "(message)Followup")
652 :type '(choice (const :tag "ignore" nil)
653 (const :tag "use & query" t)
657 (defcustom message-use-mail-followup-to 'use
658 "*Specifies what to do with Mail-Followup-To header.
659 If nil, always ignore the header. If it is the symbol `ask', always
660 query the user whether to use the value. If it is the symbol `use',
661 always use the value."
663 :group 'message-interface
664 :link '(custom-manual "(message)Mailing Lists")
665 :type '(choice (const :tag "ignore" nil)
669 (defcustom message-subscribed-address-functions nil
670 "*Specifies functions for determining list subscription.
671 If nil, do not attempt to determine list subscription with functions.
672 If non-nil, this variable contains a list of functions which return
673 regular expressions to match lists. These functions can be used in
674 conjunction with `message-subscribed-regexps' and
675 `message-subscribed-addresses'."
677 :group 'message-interface
678 :link '(custom-manual "(message)Mailing Lists")
679 :type '(repeat sexp))
681 (defcustom message-subscribed-address-file nil
682 "*A file containing addresses the user is subscribed to.
683 If nil, do not look at any files to determine list subscriptions. If
684 non-nil, each line of this file should be a mailing list address."
686 :group 'message-interface
687 :link '(custom-manual "(message)Mailing Lists")
688 :type '(radio file (const nil)))
690 (defcustom message-subscribed-addresses nil
691 "*Specifies a list of addresses the user is subscribed to.
692 If nil, do not use any predefined list subscriptions. This list of
693 addresses can be used in conjunction with
694 `message-subscribed-address-functions' and `message-subscribed-regexps'."
696 :group 'message-interface
697 :link '(custom-manual "(message)Mailing Lists")
698 :type '(repeat string))
700 (defcustom message-subscribed-regexps nil
701 "*Specifies a list of addresses the user is subscribed to.
702 If nil, do not use any predefined list subscriptions. This list of
703 regular expressions can be used in conjunction with
704 `message-subscribed-address-functions' and `message-subscribed-addresses'."
706 :group 'message-interface
707 :link '(custom-manual "(message)Mailing Lists")
708 :type '(repeat regexp))
710 (defcustom message-allow-no-recipients 'ask
711 "Specifies what to do when there are no recipients other than Gcc/Fcc.
712 If it is the symbol `always', the posting is allowed. If it is the
713 symbol `never', the posting is not allowed. If it is the symbol
714 `ask', you are prompted."
716 :group 'message-interface
717 :link '(custom-manual "(message)Message Headers")
718 :type '(choice (const always)
722 (defcustom message-sendmail-f-is-evil nil
723 "*Non-nil means don't add \"-f username\" to the sendmail command line.
724 Doing so would be even more evil than leaving it out."
725 :group 'message-sending
726 :link '(custom-manual "(message)Mail Variables")
729 (defcustom message-sendmail-envelope-from nil
730 "*Envelope-from when sending mail with sendmail.
731 If this is nil, use `user-mail-address'. If it is the symbol
732 `header', use the From: header of the message."
734 :type '(choice (string :tag "From name")
735 (const :tag "Use From: header from message" header)
736 (const :tag "Use `user-mail-address'" nil))
737 :link '(custom-manual "(message)Mail Variables")
738 :group 'message-sending)
740 ;; qmail-related stuff
741 (defcustom message-qmail-inject-program "/var/qmail/bin/qmail-inject"
742 "Location of the qmail-inject program."
743 :group 'message-sending
744 :link '(custom-manual "(message)Mail Variables")
747 (defcustom message-qmail-inject-args nil
748 "Arguments passed to qmail-inject programs.
749 This should be a list of strings, one string for each argument. It
750 may also be a function.
752 For e.g., if you wish to set the envelope sender address so that bounces
753 go to the right place or to deal with listserv's usage of that address, you
754 might set this variable to '(\"-f\" \"you@some.where\")."
755 :group 'message-sending
756 :link '(custom-manual "(message)Mail Variables")
757 :type '(choice (function)
760 (defvar message-cater-to-broken-inn t
761 "Non-nil means Gnus should not fold the `References' header.
762 Folding `References' makes ancient versions of INN create incorrect
766 (defvar gnus-post-method)
767 (defvar gnus-select-method))
768 (defcustom message-post-method
769 (cond ((and (boundp 'gnus-post-method)
770 (listp gnus-post-method)
773 ((boundp 'gnus-select-method)
776 "*Method used to post news.
777 Note that when posting from inside Gnus, for instance, this
778 variable isn't used."
780 :group 'message-sending
781 ;; This should be the `gnus-select-method' widget, but that might
782 ;; create a dependence to `gnus.el'.
785 ;; FIXME: This should be a temporary workaround until someone implements a
786 ;; proper solution. If a crash happens while replying, the auto-save file
787 ;; will *not* have a `References:' header if `message-generate-headers-first'
788 ;; is nil. See: http://article.gmane.org/gmane.emacs.gnus.general/51138
789 (defcustom message-generate-headers-first '(references)
790 "Which headers should be generated before starting to compose a message.
791 If t, generate all required headers. This can also be a list of headers to
792 generate. The variables `message-required-news-headers' and
793 `message-required-mail-headers' specify which headers to generate.
795 Note that the variable `message-deletable-headers' specifies headers which
796 are to be deleted and then re-generated before sending, so this variable
797 will not have a visible effect for those headers."
798 :group 'message-headers
799 :link '(custom-manual "(message)Message Headers")
800 :type '(choice (const :tag "None" nil)
801 (const :tag "References" '(references))
803 (repeat (sexp :tag "Header"))))
805 (defcustom message-setup-hook nil
806 "Normal hook, run each time a new outgoing message is initialized.
807 The function `message-setup' runs this hook."
808 :group 'message-various
809 :link '(custom-manual "(message)Various Message Variables")
812 (defcustom message-cancel-hook nil
813 "Hook run when cancelling articles."
814 :group 'message-various
815 :link '(custom-manual "(message)Various Message Variables")
818 (defcustom message-signature-setup-hook nil
819 "Normal hook, run each time a new outgoing message is initialized.
820 It is run after the headers have been inserted and before
821 the signature is inserted."
822 :group 'message-various
823 :link '(custom-manual "(message)Various Message Variables")
826 (defcustom message-mode-hook nil
827 "Hook run in message mode buffers."
828 :group 'message-various
831 (defcustom message-header-hook nil
832 "Hook run in a message mode buffer narrowed to the headers."
833 :group 'message-various
836 (defcustom message-header-setup-hook nil
837 "Hook called narrowed to the headers when setting up a message buffer."
838 :group 'message-various
839 :link '(custom-manual "(message)Various Message Variables")
842 (defcustom message-minibuffer-local-map
843 (let ((map (make-sparse-keymap 'message-minibuffer-local-map)))
844 (set-keymap-parent map minibuffer-local-map)
846 "Keymap for `message-read-from-minibuffer'."
848 :group 'message-various)
851 (defcustom message-citation-line-function 'message-insert-citation-line
852 "*Function called to insert the \"Whomever writes:\" line.
854 Note that Gnus provides a feature where the reader can click on
855 `writes:' to hide the cited text. If you change this line too much,
856 people who read your message will have to change their Gnus
857 configuration. See the variable `gnus-cite-attribution-suffix'."
859 :link '(custom-manual "(message)Insertion Variables")
860 :group 'message-insertion)
863 (defcustom message-yank-prefix "> "
864 "*Prefix inserted on the lines of yanked messages.
865 Fix `message-cite-prefix-regexp' if it is set to an abnormal value.
866 See also `message-yank-cited-prefix'."
868 :link '(custom-manual "(message)Insertion Variables")
869 :group 'message-insertion)
871 (defcustom message-yank-cited-prefix ">"
872 "*Prefix inserted on cited or empty lines of yanked messages.
873 Fix `message-cite-prefix-regexp' if it is set to an abnormal value.
874 See also `message-yank-prefix'."
877 :link '(custom-manual "(message)Insertion Variables")
878 :group 'message-insertion)
880 (defcustom message-indentation-spaces 3
881 "*Number of spaces to insert at the beginning of each cited line.
882 Used by `message-yank-original' via `message-yank-cite'."
883 :group 'message-insertion
884 :link '(custom-manual "(message)Insertion Variables")
888 (defcustom message-cite-function 'message-cite-original
889 "*Function for citing an original message.
890 Predefined functions include `message-cite-original' and
891 `message-cite-original-without-signature'.
892 Note that `message-cite-original' uses `mail-citation-hook' if that is non-nil."
893 :type '(radio (function-item message-cite-original)
894 (function-item message-cite-original-without-signature)
895 (function-item sc-cite-original)
896 (function :tag "Other"))
897 :link '(custom-manual "(message)Insertion Variables")
898 :group 'message-insertion)
901 (defcustom message-indent-citation-function 'message-indent-citation
902 "*Function for modifying a citation just inserted in the mail buffer.
903 This can also be a list of functions. Each function can find the
904 citation between (point) and (mark t). And each function should leave
905 point and mark around the citation text as modified."
907 :link '(custom-manual "(message)Insertion Variables")
908 :group 'message-insertion)
911 (defcustom message-signature t
912 "*String to be inserted at the end of the message buffer.
913 If t, the `message-signature-file' file will be inserted instead.
914 If a function, the result from the function will be used instead.
915 If a form, the result from the form will be used instead."
917 :link '(custom-manual "(message)Insertion Variables")
918 :group 'message-insertion)
921 (defcustom message-signature-file "~/.signature"
922 "*Name of file containing the text inserted at end of message buffer.
923 Ignored if the named file doesn't exist.
924 If nil, don't insert a signature."
925 :type '(choice file (const :tags "None" nil))
926 :link '(custom-manual "(message)Insertion Variables")
927 :group 'message-insertion)
930 (defcustom message-signature-insert-empty-line t
931 "*If non-nil, insert an empty line before the signature separator."
934 :link '(custom-manual "(message)Insertion Variables")
935 :group 'message-insertion)
937 (defcustom message-distribution-function nil
938 "*Function called to return a Distribution header."
940 :group 'message-headers
941 :link '(custom-manual "(message)News Headers")
942 :type '(choice function (const nil)))
944 (defcustom message-expires 14
945 "Number of days before your article expires."
947 :group 'message-headers
948 :link '(custom-manual "(message)News Headers")
951 (defcustom message-user-path nil
952 "If nil, use the NNTP server name in the Path header.
953 If stringp, use this; if non-nil, use no host name (user name only)."
955 :group 'message-headers
956 :link '(custom-manual "(message)News Headers")
957 :type '(choice (const :tag "nntp" nil)
959 (sexp :tag "none" :format "%t" t)))
961 (defvar message-reply-buffer nil)
962 (defvar message-reply-headers nil
963 "The headers of the current replied article.
964 It is a vector of the following headers:
965 \[number subject from date id references chars lines xref extra].")
966 (defvar message-newsreader nil)
967 (defvar message-mailer nil)
968 (defvar message-sent-message-via nil)
969 (defvar message-checksum nil)
970 (defvar message-send-actions nil
971 "A list of actions to be performed upon successful sending of a message.")
972 (defvar message-exit-actions nil
973 "A list of actions to be performed upon exiting after sending a message.")
974 (defvar message-kill-actions nil
975 "A list of actions to be performed before killing a message buffer.")
976 (defvar message-postpone-actions nil
977 "A list of actions to be performed after postponing a message.")
979 (define-widget 'message-header-lines 'text
980 "All header lines must be LFD terminated."
981 :format "%{%t%}:%n%v"
983 :error "All header lines must be newline terminated")
985 (defcustom message-default-headers ""
986 "*A string containing header lines to be inserted in outgoing messages.
987 It is inserted before you edit the message, so you can edit or delete
989 :group 'message-headers
990 :link '(custom-manual "(message)Message Headers")
991 :type 'message-header-lines)
993 (defcustom message-default-mail-headers ""
994 "*A string of header lines to be inserted in outgoing mails."
995 :group 'message-headers
997 :link '(custom-manual "(message)Mail Headers")
998 :type 'message-header-lines)
1000 (defcustom message-default-news-headers ""
1001 "*A string of header lines to be inserted in outgoing news articles."
1002 :group 'message-headers
1003 :group 'message-news
1004 :link '(custom-manual "(message)News Headers")
1005 :type 'message-header-lines)
1007 ;; Note: could use /usr/ucb/mail instead of sendmail;
1008 ;; options -t, and -v if not interactive.
1009 (defcustom message-mailer-swallows-blank-line
1010 (if (and (string-match "sparc-sun-sunos\\(\\'\\|[^5]\\)"
1011 system-configuration)
1012 (file-readable-p "/etc/sendmail.cf")
1013 (let ((buffer (get-buffer-create " *temp*")))
1017 (insert-file-contents "/etc/sendmail.cf")
1018 (goto-char (point-min))
1019 (let ((case-fold-search nil))
1020 (re-search-forward "^OR\\>" nil t)))
1021 (kill-buffer buffer))))
1022 ;; According to RFC822, "The field-name must be composed of printable
1023 ;; ASCII characters (i. e., characters that have decimal values between
1024 ;; 33 and 126, except colon)", i. e., any chars except ctl chars,
1026 '(looking-at "[ \t]\\|[][!\"#$%&'()*+,-./0-9;<=>?@A-Z\\\\^_`a-z{|}~]+:"))
1027 "*Set this non-nil if the system's mailer runs the header and body together.
1028 \(This problem exists on Sunos 4 when sendmail is run in remote mode.)
1029 The value should be an expression to test whether the problem will
1031 :group 'message-sending
1032 :link '(custom-manual "(message)Mail Variables")
1036 (define-mail-user-agent 'message-user-agent
1037 'message-mail 'message-send-and-exit
1038 'message-kill-buffer 'message-send-hook)
1040 (defvar message-mh-deletable-headers '(Message-ID Date Lines Sender)
1041 "If non-nil, delete the deletable headers before feeding to mh.")
1043 (defvar message-send-method-alist
1044 '((news message-news-p message-send-via-news)
1045 (mail message-mail-p message-send-via-mail))
1046 "Alist of ways to send outgoing messages.
1047 Each element has the form
1049 \(TYPE PREDICATE FUNCTION)
1051 where TYPE is a symbol that names the method; PREDICATE is a function
1052 called without any parameters to determine whether the message is
1053 a message of type TYPE; and FUNCTION is a function to be called if
1054 PREDICATE returns non-nil. FUNCTION is called with one parameter --
1057 (defcustom message-mail-alias-type 'abbrev
1058 "*What alias expansion type to use in Message buffers.
1059 The default is `abbrev', which uses mailabbrev. nil switches
1062 :link '(custom-manual "(message)Mail Aliases")
1063 :type '(choice (const :tag "Use Mailabbrev" abbrev)
1064 (const :tag "No expansion" nil)))
1066 (defcustom message-auto-save-directory
1067 (file-name-as-directory (nnheader-concat message-directory "drafts"))
1068 "*Directory where Message auto-saves buffers if Gnus isn't running.
1069 If nil, Message won't auto-save."
1070 :group 'message-buffers
1071 :link '(custom-manual "(message)Various Message Variables")
1072 :type '(choice directory (const :tag "Don't auto-save" nil)))
1074 (defcustom message-default-charset
1075 (and (not (mm-multibyte-p)) 'iso-8859-1)
1076 "Default charset used in non-MULE Emacsen.
1077 If nil, you might be asked to input the charset."
1080 :link '(custom-manual "(message)Various Message Variables")
1083 (defcustom message-dont-reply-to-names
1084 (and (boundp 'rmail-dont-reply-to-names) rmail-dont-reply-to-names)
1085 "*A regexp specifying addresses to prune when doing wide replies.
1086 A value of nil means exclude your own user name only."
1089 :link '(custom-manual "(message)Wide Reply")
1090 :type '(choice (const :tag "Yourself" nil)
1093 (defvar message-shoot-gnksa-feet nil
1094 "*A list of GNKSA feet you are allowed to shoot.
1095 Gnus gives you all the opportunity you could possibly want for
1096 shooting yourself in the foot. Also, Gnus allows you to shoot the
1097 feet of Good Net-Keeping Seal of Approval. The following are foot
1099 `empty-article' Allow you to post an empty article;
1100 `quoted-text-only' Allow you to post quoted text only;
1101 `multiple-copies' Allow you to post multiple copies;
1102 `cancel-messages' Allow you to cancel or supersede messages from
1103 your other email addresses.")
1105 (defsubst message-gnksa-enable-p (feature)
1106 (or (not (listp message-shoot-gnksa-feet))
1107 (memq feature message-shoot-gnksa-feet)))
1109 (defcustom message-hidden-headers nil
1110 "Regexp of headers to be hidden when composing new messages.
1111 This can also be a list of regexps to match headers. Or a list
1112 starting with `not' and followed by regexps."
1115 :link '(custom-manual "(message)Message Headers")
1116 :type '(repeat regexp))
1118 ;;; Internal variables.
1119 ;;; Well, not really internal.
1121 (defvar message-mode-syntax-table
1122 (let ((table (copy-syntax-table text-mode-syntax-table)))
1123 (modify-syntax-entry ?% ". " table)
1124 (modify-syntax-entry ?> ". " table)
1125 (modify-syntax-entry ?< ". " table)
1127 "Syntax table used while in Message mode.")
1129 (defface message-header-to
1132 (:foreground "green2" :bold t))
1135 (:foreground "MidnightBlue" :bold t))
1137 (:bold t :italic t)))
1138 "Face used for displaying From headers."
1139 :group 'message-faces)
1140 ;; backward-compatibility alias
1141 (put 'message-header-to-face 'face-alias 'message-header-to)
1143 (defface message-header-cc
1146 (:foreground "green4" :bold t))
1149 (:foreground "MidnightBlue"))
1152 "Face used for displaying Cc headers."
1153 :group 'message-faces)
1154 ;; backward-compatibility alias
1155 (put 'message-header-cc-face 'face-alias 'message-header-cc)
1157 (defface message-header-subject
1160 (:foreground "green3"))
1163 (:foreground "navy blue" :bold t))
1166 "Face used for displaying subject headers."
1167 :group 'message-faces)
1168 ;; backward-compatibility alias
1169 (put 'message-header-subject-face 'face-alias 'message-header-subject)
1171 (defface message-header-newsgroups
1174 (:foreground "yellow" :bold t :italic t))
1177 (:foreground "blue4" :bold t :italic t))
1179 (:bold t :italic t)))
1180 "Face used for displaying newsgroups headers."
1181 :group 'message-faces)
1182 ;; backward-compatibility alias
1183 (put 'message-header-newsgroups-face 'face-alias 'message-header-newsgroups)
1185 (defface message-header-other
1188 (:foreground "#b00000"))
1191 (:foreground "steel blue"))
1193 (:bold t :italic t)))
1194 "Face used for displaying newsgroups headers."
1195 :group 'message-faces)
1196 ;; backward-compatibility alias
1197 (put 'message-header-other-face 'face-alias 'message-header-other)
1199 (defface message-header-name
1202 (:foreground "DarkGreen"))
1205 (:foreground "cornflower blue"))
1208 "Face used for displaying header names."
1209 :group 'message-faces)
1210 ;; backward-compatibility alias
1211 (put 'message-header-name-face 'face-alias 'message-header-name)
1213 (defface message-header-xheader
1216 (:foreground "blue"))
1219 (:foreground "blue"))
1222 "Face used for displaying X-Header headers."
1223 :group 'message-faces)
1224 ;; backward-compatibility alias
1225 (put 'message-header-xheader-face 'face-alias 'message-header-xheader)
1227 (defface message-separator
1230 (:foreground "blue3"))
1233 (:foreground "brown"))
1236 "Face used for displaying the separator."
1237 :group 'message-faces)
1238 ;; backward-compatibility alias
1239 (put 'message-separator-face 'face-alias 'message-separator)
1241 (defface message-cited-text
1244 (:foreground "red"))
1247 (:foreground "red"))
1250 "Face used for displaying cited text names."
1251 :group 'message-faces)
1252 ;; backward-compatibility alias
1253 (put 'message-cited-text-face 'face-alias 'message-cited-text)
1255 (defface message-mml
1258 (:foreground "ForestGreen"))
1261 (:foreground "ForestGreen"))
1264 "Face used for displaying MML."
1265 :group 'message-faces)
1266 ;; backward-compatibility alias
1267 (put 'message-mml-face 'face-alias 'message-mml)
1269 (defun message-font-lock-make-header-matcher (regexp)
1272 (let ((start (point)))
1275 (goto-char (point-min))
1276 (if (re-search-forward
1277 (concat "^" (regexp-quote mail-header-separator) "$")
1279 (setq limit (min limit (match-beginning 0))))
1281 (and (< start limit)
1282 (re-search-forward ,regexp limit t))))))
1283 (if (featurep 'bytecomp)
1287 (defvar message-font-lock-keywords
1288 (let ((content "[ \t]*\\(.+\\(\n[ \t].*\\)*\\)\n?"))
1289 `((,(message-font-lock-make-header-matcher
1290 (concat "^\\([Tt]o:\\)" content))
1291 (1 'message-header-name)
1292 (2 'message-header-to nil t))
1293 (,(message-font-lock-make-header-matcher
1294 (concat "^\\(^[GBF]?[Cc][Cc]:\\|^[Rr]eply-[Tt]o:\\)" content))
1295 (1 'message-header-name)
1296 (2 'message-header-cc nil t))
1297 (,(message-font-lock-make-header-matcher
1298 (concat "^\\([Ss]ubject:\\)" content))
1299 (1 'message-header-name)
1300 (2 'message-header-subject nil t))
1301 (,(message-font-lock-make-header-matcher
1302 (concat "^\\([Nn]ewsgroups:\\|Followup-[Tt]o:\\)" content))
1303 (1 'message-header-name)
1304 (2 'message-header-newsgroups nil t))
1305 (,(message-font-lock-make-header-matcher
1306 (concat "^\\([A-Z][^: \n\t]+:\\)" content))
1307 (1 'message-header-name)
1308 (2 'message-header-other nil t))
1309 (,(message-font-lock-make-header-matcher
1310 (concat "^\\(X-[A-Za-z0-9-]+:\\|In-Reply-To:\\)" content))
1311 (1 'message-header-name)
1312 (2 'message-header-name))
1313 ,@(if (and mail-header-separator
1314 (not (equal mail-header-separator "")))
1315 `((,(concat "^\\(" (regexp-quote mail-header-separator) "\\)$")
1316 1 'message-separator))
1319 (re-search-forward (concat "^\\("
1320 message-cite-prefix-regexp
1323 (0 'message-cited-text))
1324 ("<#/?\\(multipart\\|part\\|external\\|mml\\|secure\\)[^>]*>"
1326 "Additional expressions to highlight in Message mode.")
1329 ;; XEmacs does it like this. For Emacs, we have to set the
1330 ;; `font-lock-defaults' buffer-local variable.
1331 (put 'message-mode 'font-lock-defaults '(message-font-lock-keywords t))
1333 (defvar message-face-alist
1334 '((bold . bold-region)
1335 (underline . underline-region)
1336 (default . (lambda (b e)
1338 (ununderline-region b e))))
1339 "Alist of mail and news faces for facemenu.
1340 The cdr of each entry is a function for applying the face to a region.")
1342 (defcustom message-send-hook nil
1343 "Hook run before sending messages.
1344 This hook is run quite early when sending."
1345 :group 'message-various
1346 :options '(ispell-message)
1347 :link '(custom-manual "(message)Various Message Variables")
1350 (defcustom message-send-mail-hook nil
1351 "Hook run before sending mail messages.
1352 This hook is run very late -- just before the message is sent as
1354 :group 'message-various
1355 :link '(custom-manual "(message)Various Message Variables")
1358 (defcustom message-send-news-hook nil
1359 "Hook run before sending news messages.
1360 This hook is run very late -- just before the message is sent as
1362 :group 'message-various
1363 :link '(custom-manual "(message)Various Message Variables")
1366 (defcustom message-sent-hook nil
1367 "Hook run after sending messages."
1368 :group 'message-various
1371 (defvar message-send-coding-system 'binary
1372 "Coding system to encode outgoing mail.")
1374 (defvar message-draft-coding-system
1375 mm-auto-save-coding-system
1376 "*Coding system to compose mail.
1377 If you'd like to make it possible to share draft files between XEmacs
1378 and Emacs, you may use `iso-2022-7bit' for this value at your own risk.
1379 Note that the coding-system `iso-2022-7bit' isn't suitable to all data.")
1381 (defcustom message-send-mail-partially-limit 1000000
1382 "The limitation of messages sent as message/partial.
1383 The lower bound of message size in characters, beyond which the message
1384 should be sent in several parts. If it is nil, the size is unlimited."
1386 :group 'message-buffers
1387 :link '(custom-manual "(message)Mail Variables")
1388 :type '(choice (const :tag "unlimited" nil)
1391 (defcustom message-alternative-emails nil
1392 "*Regexp matching alternative email addresses.
1393 The first address in the To, Cc or From headers of the original
1394 article matching this variable is used as the From field of
1397 This variable has precedence over posting styles and anything that runs
1398 off `message-setup-hook'."
1399 :group 'message-headers
1400 :link '(custom-manual "(message)Message Headers")
1401 :type '(choice (const :tag "Always use primary" nil)
1404 (defcustom message-hierarchical-addresses nil
1405 "A list of hierarchical mail address definitions.
1407 Inside each entry, the first address is the \"top\" address, and
1408 subsequent addresses are subaddresses; this is used to indicate that
1409 mail sent to the first address will automatically be delivered to the
1410 subaddresses. So if the first address appears in the recipient list
1411 for a message, the subaddresses will be removed (if present) before
1412 the mail is sent. All addresses in this structure should be
1415 :group 'message-headers
1416 :type '(repeat (repeat string)))
1418 (defcustom message-mail-user-agent nil
1419 "Like `mail-user-agent'.
1420 Except if it is nil, use Gnus native MUA; if it is t, use
1423 :type '(radio (const :tag "Gnus native"
1426 (const :tag "`mail-user-agent'"
1429 (function-item :tag "Default Emacs mail"
1431 sendmail-user-agent)
1432 (function-item :tag "Emacs interface to MH"
1435 (function :tag "Other"))
1439 (defcustom message-wide-reply-confirm-recipients nil
1440 "Whether to confirm a wide reply to multiple email recipients.
1441 If this variable is nil, don't ask whether to reply to all recipients.
1442 If this variable is non-nil, pose the question \"Reply to all
1443 recipients?\" before a wide reply to multiple recipients. If the user
1444 answers yes, reply to all recipients as usual. If the user answers
1445 no, only reply back to the author."
1447 :group 'message-headers
1448 :link '(custom-manual "(message)Wide Reply")
1451 (defcustom message-user-fqdn nil
1452 "*Domain part of Message-Ids."
1454 :group 'message-headers
1455 :link '(custom-manual "(message)News Headers")
1456 :type '(radio (const :format "%v " nil)
1457 (string :format "FQDN: %v")))
1459 (defcustom message-use-idna (and (condition-case nil (require 'idna)
1461 (mm-coding-system-p 'utf-8)
1462 (executable-find idna-program)
1463 (string= (idna-to-ascii "räksmörgås")
1464 "xn--rksmrgs-5wao1o")
1466 "Whether to encode non-ASCII in domain names into ASCII according to IDNA.
1467 GNU Libidn, and in particular the elisp package \"idna.el\" and
1468 the external program \"idn\", must be installed for this
1469 functionality to work."
1471 :group 'message-headers
1472 :link '(custom-manual "(message)IDNA")
1473 :type '(choice (const :tag "Ask" ask)
1474 (const :tag "Never" nil)
1475 (const :tag "Always" t)))
1477 ;;; Internal variables.
1479 (defvar message-sending-message "Sending...")
1480 (defvar message-buffer-list nil)
1481 (defvar message-this-is-news nil)
1482 (defvar message-this-is-mail nil)
1483 (defvar message-draft-article nil)
1484 (defvar message-mime-part nil)
1485 (defvar message-posting-charset nil)
1486 (defvar message-inserted-headers nil)
1488 ;; Byte-compiler warning
1490 (defvar gnus-active-hashtb)
1491 (defvar gnus-read-active-file))
1493 ;;; Regexp matching the delimiter of messages in UNIX mail format
1494 ;;; (UNIX From lines), minus the initial ^. It should be a copy
1495 ;;; of rmail.el's rmail-unix-mail-delimiter.
1496 (defvar message-unix-mail-delimiter
1497 (let ((time-zone-regexp
1498 (concat "\\([A-Z]?[A-Z]?[A-Z][A-Z]\\( DST\\)?"
1499 "\\|[-+]?[0-9][0-9][0-9][0-9]"
1505 ;; Many things can happen to an RFC 822 mailbox before it is put into
1506 ;; a `From' line. The leading phrase can be stripped, e.g.
1507 ;; `Joe <@w.x:joe@y.z>' -> `<@w.x:joe@y.z>'. The <> can be stripped, e.g.
1508 ;; `<@x.y:joe@y.z>' -> `@x.y:joe@y.z'. Everything starting with a CRLF
1509 ;; can be removed, e.g.
1510 ;; From: joe@y.z (Joe K
1512 ;; can yield `From joe@y.z (Joe K Fri Mar 22 08:11:15 1996', and
1515 ;; can yield `From Joe User Fri Mar 22 08:11:15 1996'.
1516 ;; The mailbox can be removed or be replaced by white space, e.g.
1517 ;; From: "Joe User"{space}{tab}
1519 ;; can yield `From {space}{tab} Fri Mar 22 08:11:15 1996',
1520 ;; where {space} and {tab} represent the Ascii space and tab characters.
1521 ;; We want to match the results of any of these manglings.
1522 ;; The following regexp rejects names whose first characters are
1523 ;; obviously bogus, but after that anything goes.
1524 "\\([^\0-\b\n-\r\^?].*\\)?"
1526 ;; The time the message was sent.
1527 "\\([^\0-\r \^?]+\\) +" ; day of the week
1528 "\\([^\0-\r \^?]+\\) +" ; month
1529 "\\([0-3]?[0-9]\\) +" ; day of month
1530 "\\([0-2][0-9]:[0-5][0-9]\\(:[0-6][0-9]\\)?\\) *" ; time of day
1532 ;; Perhaps a time zone, specified by an abbreviation, or by a
1537 " \\([0-9][0-9]+\\) *"
1539 ;; On some systems the time zone can appear after the year, too.
1543 "\\(remote from .*\\)?"
1546 "Regexp matching the delimiter of messages in UNIX mail format.")
1548 (defvar message-unsent-separator
1549 (concat "^ *---+ +Unsent message follows +---+ *$\\|"
1550 "^ *---+ +Returned message +---+ *$\\|"
1551 "^Start of returned message$\\|"
1552 "^ *---+ +Original message +---+ *$\\|"
1553 "^ *--+ +begin message +--+ *$\\|"
1554 "^ *---+ +Original message follows +---+ *$\\|"
1555 "^ *---+ +Undelivered message follows +---+ *$\\|"
1556 "^|? *---+ +Message text follows: +---+ *|?$")
1557 "A regexp that matches the separator before the text of a failed message.")
1559 (defvar message-header-format-alist
1561 (To . message-fill-address)
1562 (Cc . message-fill-address)
1573 (References . message-shorten-references)
1575 "Alist used for formatting headers.")
1577 (defvar message-options nil
1578 "Some saved answers when sending message.")
1580 (defvar message-send-mail-real-function nil
1581 "Internal send mail function.")
1583 (defvar message-bogus-system-names "^localhost\\."
1584 "The regexp of bogus system names.")
1586 (defcustom message-valid-fqdn-regexp
1587 (concat "[a-z0-9][-.a-z0-9]+\\." ;; [hostname.subdomain.]domain.
1589 "\\([a-z][a-z]" ;; two letter country TDLs
1590 "\\|biz\\|com\\|edu\\|gov\\|int\\|mil\\|net\\|org"
1591 "\\|aero\\|coop\\|info\\|name\\|museum"
1592 "\\|arpa\\|pro\\|uucp\\|bitnet\\|bofh" ;; old style?
1594 "Regular expression that matches a valid FQDN."
1595 ;; see also: gnus-button-valid-fqdn-regexp
1597 :group 'message-headers
1601 (autoload 'idna-to-ascii "idna")
1602 (autoload 'message-setup-toolbar "messagexmas")
1603 (autoload 'mh-new-draft-name "mh-comp")
1604 (autoload 'mh-send-letter "mh-comp")
1605 (autoload 'gnus-point-at-eol "gnus-util")
1606 (autoload 'gnus-point-at-bol "gnus-util")
1607 (autoload 'gnus-output-to-rmail "gnus-util")
1608 (autoload 'gnus-output-to-mail "gnus-util")
1609 (autoload 'nndraft-request-associate-buffer "nndraft")
1610 (autoload 'nndraft-request-expire-articles "nndraft")
1611 (autoload 'gnus-open-server "gnus-int")
1612 (autoload 'gnus-request-post "gnus-int")
1613 (autoload 'gnus-alive-p "gnus-util")
1614 (autoload 'gnus-server-string "gnus")
1615 (autoload 'gnus-group-name-charset "gnus-group")
1616 (autoload 'gnus-group-name-decode "gnus-group")
1617 (autoload 'gnus-groups-from-server "gnus")
1618 (autoload 'rmail-output "rmailout")
1619 (autoload 'gnus-delay-article "gnus-delay")
1620 (autoload 'gnus-make-local-hook "gnus-util")
1621 (autoload 'gnus-extract-address-components "gnus-util"))
1626 ;;; Utility functions.
1629 (defmacro message-y-or-n-p (question show &rest text)
1630 "Ask QUESTION, displaying remaining args in a temporary buffer if SHOW."
1631 `(message-talkative-question 'y-or-n-p ,question ,show ,@text))
1633 (defmacro message-delete-line (&optional n)
1634 "Delete the current line (and the next N lines)."
1635 `(delete-region (progn (beginning-of-line) (point))
1636 (progn (forward-line ,(or n 1)) (point))))
1638 (defun message-mark-active-p ()
1639 "Non-nil means the mark and region are currently active in this buffer."
1642 (defun message-unquote-tokens (elems)
1643 "Remove double quotes (\") from strings in list ELEMS."
1644 (mapcar (lambda (item)
1645 (while (string-match "^\\(.*\\)\"\\(.*\\)$" item)
1646 (setq item (concat (match-string 1 item)
1647 (match-string 2 item))))
1651 (defun message-tokenize-header (header &optional separator)
1652 "Split HEADER into a list of header elements.
1653 SEPARATOR is a string of characters to be used as separators. \",\"
1654 is used by default."
1657 (let ((regexp (format "[%s]+" (or separator ",")))
1659 beg quoted elems paren)
1661 (mm-enable-multibyte)
1662 (setq beg (point-min))
1664 (goto-char (point-min))
1669 (cond ((and (> (point) beg)
1671 (and (looking-at regexp)
1674 (push (buffer-substring beg (point)) elems)
1675 (setq beg (match-end 0)))
1676 ((eq (char-after) ?\")
1677 (setq quoted (not quoted)))
1678 ((and (eq (char-after) ?\()
1681 ((and (eq (char-after) ?\))
1684 (nreverse elems)))))
1686 (defun message-mail-file-mbox-p (file)
1687 "Say whether FILE looks like a Unix mbox file."
1688 (when (and (file-exists-p file)
1689 (file-readable-p file)
1690 (file-regular-p file))
1692 (nnheader-insert-file-contents file)
1693 (goto-char (point-min))
1694 (looking-at message-unix-mail-delimiter))))
1696 (defun message-fetch-field (header &optional not-all)
1697 "The same as `mail-fetch-field', only remove all newlines.
1698 The buffer is expected to be narrowed to just the header of the message;
1699 see `message-narrow-to-headers-or-head'."
1700 (let* ((inhibit-point-motion-hooks t)
1701 (case-fold-search t)
1702 (value (mail-fetch-field header nil (not not-all))))
1704 (while (string-match "\n[\t ]+" value)
1705 (setq value (replace-match " " t t value)))
1706 (set-text-properties 0 (length value) nil value)
1709 (defun message-field-value (header &optional not-all)
1710 "The same as `message-fetch-field', only narrow to the headers first."
1713 (message-narrow-to-headers-or-head)
1714 (message-fetch-field header not-all))))
1716 (defun message-narrow-to-field ()
1717 "Narrow the buffer to the header on the current line."
1723 (if (re-search-forward "^[^ \n\t]" nil t)
1728 (goto-char (point-min)))
1730 (defun message-add-header (&rest headers)
1731 "Add the HEADERS to the message header, skipping those already present."
1734 (unless (string-match "^\\([^:]+\\):[ \t]*[^ \t]" (car headers))
1735 (error "Invalid header `%s'" (car headers)))
1736 (setq hclean (match-string 1 (car headers)))
1738 (message-narrow-to-headers)
1739 (unless (re-search-forward (concat "^" (regexp-quote hclean) ":") nil t)
1740 (goto-char (point-max))
1741 (if (string-match "\n$" (car headers))
1742 (insert (car headers))
1743 (insert (car headers) ?\n)))))
1744 (setq headers (cdr headers))))
1746 (defmacro message-with-reply-buffer (&rest forms)
1747 "Evaluate FORMS in the reply buffer, if it exists."
1748 `(when (and message-reply-buffer
1749 (buffer-name message-reply-buffer))
1751 (set-buffer message-reply-buffer)
1754 (put 'message-with-reply-buffer 'lisp-indent-function 0)
1755 (put 'message-with-reply-buffer 'edebug-form-spec '(body))
1757 (defun message-fetch-reply-field (header)
1758 "Fetch field HEADER from the message we're replying to."
1759 (message-with-reply-buffer
1761 (mail-narrow-to-head)
1762 (message-fetch-field header))))
1764 (defun message-strip-list-identifiers (subject)
1765 "Remove list identifiers in `gnus-list-identifiers' from string SUBJECT."
1766 (require 'gnus-sum) ; for gnus-list-identifiers
1767 (let ((regexp (if (stringp gnus-list-identifiers)
1768 gnus-list-identifiers
1769 (mapconcat 'identity gnus-list-identifiers " *\\|"))))
1770 (if (string-match (concat "\\(\\(\\(Re: +\\)?\\(" regexp
1771 " *\\)\\)+\\(Re: +\\)?\\)") subject)
1772 (concat (substring subject 0 (match-beginning 1))
1773 (or (match-string 3 subject)
1774 (match-string 5 subject))
1779 (defun message-strip-subject-re (subject)
1780 "Remove \"Re:\" from subject lines in string SUBJECT."
1781 (if (string-match message-subject-re-regexp subject)
1782 (substring subject (match-end 0))
1785 ;;; Start of functions adopted from `message-utils.el'.
1787 (defun message-strip-subject-trailing-was (subject)
1788 "Remove trailing \"(was: <old subject>)\" from SUBJECT lines.
1789 Leading \"Re: \" is not stripped by this function. Use the function
1790 `message-strip-subject-re' for this."
1791 (let* ((query message-subject-trailing-was-query)
1796 message-subject-trailing-was-ask-regexp
1797 message-subject-trailing-was-regexp)
1800 (setq new (substring subject 0 (match-beginning 0))))
1801 (if (or (not found) (eq query nil))
1804 (if (message-y-or-n-p
1805 "Strip `(was: <old subject>)' in subject? " t
1807 "Strip `(was: <old subject>)' in subject "
1808 "and use the new one instead?\n\n"
1809 "Current subject is: \""
1811 "New subject would be: \""
1813 "See the variable `message-subject-trailing-was-query' "
1814 "to get rid of this query."
1819 ;;; Suggested by Jonas Steverud @ www.dtek.chalmers.se/~d4jonas/
1821 (defun message-change-subject (new-subject)
1822 "Ask for NEW-SUBJECT header, append (was: <Old Subject>)."
1823 ;; <URL:http://www.landfield.com/usefor/drafts/draft-ietf-usefor-useage--1.02.unpaged>
1826 (read-from-minibuffer "New subject: ")))
1827 (cond ((and (not (or (null new-subject) ; new subject not empty
1828 (zerop (string-width new-subject))
1829 (string-match "^[ \t]*$" new-subject))))
1833 (message-narrow-to-headers)
1834 (message-fetch-field "Subject"))))
1835 (cond ((not old-subject)
1836 (error "No current subject"))
1839 (regexp-quote new-subject)
1841 old-subject)) ; yes, it really is a new subject
1842 ;; delete eventual Re: prefix
1844 (message-strip-subject-re old-subject))
1845 (message-goto-subject)
1846 (message-delete-line)
1847 (insert (concat "Subject: "
1850 old-subject ")\n")))))))))
1852 (defun message-mark-inserted-region (beg end)
1853 "Mark some region in the current article with enclosing tags.
1854 See `message-mark-insert-begin' and `message-mark-insert-end'."
1857 ;; add to the end of the region first, otherwise end would be invalid
1859 (insert message-mark-insert-end)
1861 (insert message-mark-insert-begin)))
1863 (defun message-mark-insert-file (file)
1864 "Insert FILE at point, marking it with enclosing tags.
1865 See `message-mark-insert-begin' and `message-mark-insert-end'."
1866 (interactive "fFile to insert: ")
1867 ;; reverse insertion to get correct result.
1869 (insert message-mark-insert-end)
1871 (insert-file-contents file)
1873 (insert message-mark-insert-begin)))
1875 (defun message-add-archive-header ()
1876 "Insert \"X-No-Archive: Yes\" in the header and a note in the body.
1877 The note can be customized using `message-archive-note'. When called with a
1878 prefix argument, ask for a text to insert. If you don't want the note in the
1879 body, set `message-archive-note' to nil."
1881 (if current-prefix-arg
1882 (setq message-archive-note
1883 (read-from-minibuffer "Reason for No-Archive: "
1884 (cons message-archive-note 0))))
1886 (if (message-goto-signature)
1887 (re-search-backward message-signature-separator))
1888 (when message-archive-note
1889 (insert message-archive-note)
1891 (message-add-header message-archive-header)
1892 (message-sort-headers)))
1894 (defun message-cross-post-followup-to-header (target-group)
1895 "Mangles FollowUp-To and Newsgroups header to point to TARGET-GROUP.
1896 With prefix-argument just set Follow-Up, don't cross-post."
1898 (list ; Completion based on Gnus
1899 (completing-read "Followup To: "
1900 (if (boundp 'gnus-newsrc-alist)
1902 nil nil '("poster" . 0)
1903 (if (boundp 'gnus-group-history)
1904 'gnus-group-history))))
1905 (message-remove-header "Follow[Uu]p-[Tt]o" t)
1906 (message-goto-newsgroups)
1908 ;; if we already did a crosspost before, kill old target
1909 (if (and message-cross-post-old-target
1911 (regexp-quote (concat "," message-cross-post-old-target))
1914 ;; unless (followup is to poster or user explicitly asked not
1915 ;; to cross-post, or target-group is already in Newsgroups)
1916 ;; add target-group to Newsgroups line.
1918 ;; def: cross-post, req:no
1919 (and message-cross-post-default (not current-prefix-arg))
1920 ;; def: no-cross-post, req:yes
1921 (and (not message-cross-post-default) current-prefix-arg))
1922 (not (string-match "poster" target-group))
1923 (not (string-match (regexp-quote target-group)
1924 (message-fetch-field "Newsgroups"))))
1926 (insert (concat "," target-group))))
1927 (end-of-line) ; ensure Followup: comes after Newsgroups:
1928 ;; unless new followup would be identical to Newsgroups line
1929 ;; make a new Followup-To line
1930 (if (not (string-match (concat "^[ \t]*"
1933 (message-fetch-field "Newsgroups")))
1934 (insert (concat "\nFollowup-To: " target-group)))
1935 (setq message-cross-post-old-target target-group))
1937 (defun message-cross-post-insert-note (target-group cross-post in-old
1939 "Insert a in message body note about a set Followup or Crosspost.
1940 If there have been previous notes, delete them. TARGET-GROUP specifies the
1941 group to Followup-To. When CROSS-POST is t, insert note about
1942 crossposting. IN-OLD specifies whether TARGET-GROUP is a member of
1943 OLD-GROUPS. OLD-GROUPS lists the old-groups the posting would have
1944 been made to before the user asked for a Crosspost."
1945 ;; start scanning body for previous uses
1946 (message-goto-signature)
1947 (let ((head (re-search-backward
1948 (concat "^" mail-header-separator)
1949 nil t))) ; just search in body
1950 (message-goto-signature)
1951 (while (re-search-backward
1952 (concat "^" (regexp-quote message-cross-post-note) ".*")
1954 (message-delete-line))
1955 (message-goto-signature)
1956 (while (re-search-backward
1957 (concat "^" (regexp-quote message-followup-to-note) ".*")
1959 (message-delete-line))
1961 (if (message-goto-signature)
1962 (re-search-backward message-signature-separator))
1965 (string-match "^[ \t]*poster[ \t]*$" target-group))
1966 (insert (concat message-followup-to-note target-group "\n"))
1967 (insert (concat message-cross-post-note target-group "\n")))))
1969 (defun message-cross-post-followup-to (target-group)
1970 "Crossposts message and set Followup-To to TARGET-GROUP.
1971 With prefix-argument just set Follow-Up, don't cross-post."
1973 (list ; Completion based on Gnus
1974 (completing-read "Followup To: "
1975 (if (boundp 'gnus-newsrc-alist)
1977 nil nil '("poster" . 0)
1978 (if (boundp 'gnus-group-history)
1979 'gnus-group-history))))
1980 (cond ((not (or (null target-group) ; new subject not empty
1981 (zerop (string-width target-group))
1982 (string-match "^[ \t]*$" target-group)))
1984 (let* ((old-groups (message-fetch-field "Newsgroups"))
1985 (in-old (string-match
1986 (regexp-quote target-group)
1987 (or old-groups ""))))
1988 ;; check whether target exactly matches old Newsgroups
1989 (cond ((not old-groups)
1990 (error "No current newsgroup"))
1994 (regexp-quote target-group)
1997 ;; yes, Newsgroups line must change
1998 (message-cross-post-followup-to-header target-group)
1999 ;; insert note whether we do cross-post or followup-to
2000 (funcall message-cross-post-note-function
2002 (if (or (and message-cross-post-default
2003 (not current-prefix-arg))
2004 (and (not message-cross-post-default)
2005 current-prefix-arg)) t)
2006 in-old old-groups))))))))
2008 ;;; Reduce To: to Cc: or Bcc: header
2010 (defun message-reduce-to-to-cc ()
2011 "Replace contents of To: header with contents of Cc: or Bcc: header."
2014 (save-restriction (message-narrow-to-headers)
2015 (message-fetch-field "cc")))
2017 (if (and (not cc-content)
2020 (message-narrow-to-headers)
2021 (message-fetch-field "bcc"))))
2026 (message-delete-line)
2027 (insert (concat "To: " cc-content "\n"))
2029 (message-narrow-to-headers)
2030 (message-remove-header (if bcc
2034 ;;; End of functions adopted from `message-utils.el'.
2036 (defun message-remove-header (header &optional is-regexp first reverse)
2037 "Remove HEADER in the narrowed buffer.
2038 If IS-REGEXP, HEADER is a regular expression.
2039 If FIRST, only remove the first instance of the header.
2040 Return the number of headers removed."
2041 (goto-char (point-min))
2042 (let ((regexp (if is-regexp header (concat "^" (regexp-quote header) ":")))
2044 (case-fold-search t)
2046 (while (and (not (eobp))
2049 (not (looking-at regexp))
2050 (looking-at regexp))
2057 ;; There might be a continuation header, so we have to search
2058 ;; until we find a new non-continuation line.
2061 (if (re-search-forward "^[^ \t]" nil t)
2062 (goto-char (match-beginning 0))
2065 (if (re-search-forward "^[^ \t]" nil t)
2066 (goto-char (match-beginning 0))
2067 (goto-char (point-max)))))
2070 (defun message-remove-first-header (header)
2071 "Remove the first instance of HEADER if there is more than one."
2073 (regexp (concat "^" (regexp-quote header) ":")))
2075 (goto-char (point-min))
2076 (while (re-search-forward regexp nil t)
2079 (message-remove-header header nil t)
2082 (defun message-narrow-to-headers ()
2083 "Narrow the buffer to the head of the message."
2086 (goto-char (point-min))
2087 (if (re-search-forward
2088 (concat "^" (regexp-quote mail-header-separator) "\n") nil t)
2091 (goto-char (point-min)))
2093 (defun message-narrow-to-head-1 ()
2094 "Like `message-narrow-to-head'. Don't widen."
2096 (goto-char (point-min))
2097 (if (search-forward "\n\n" nil 1)
2100 (goto-char (point-min)))
2102 (defun message-narrow-to-head ()
2103 "Narrow the buffer to the head of the message.
2104 Point is left at the beginning of the narrowed-to region."
2106 (message-narrow-to-head-1))
2108 (defun message-narrow-to-headers-or-head ()
2109 "Narrow the buffer to the head of the message."
2112 (goto-char (point-min))
2115 (concat "^" (regexp-quote mail-header-separator) "\n") nil t)
2116 (match-beginning 0))
2117 ((search-forward "\n\n" nil t)
2121 (goto-char (point-min)))
2123 (defun message-news-p ()
2124 "Say whether the current buffer contains a news message."
2125 (and (not message-this-is-mail)
2126 (or message-this-is-news
2129 (message-narrow-to-headers)
2130 (and (message-fetch-field "newsgroups")
2131 (not (message-fetch-field "posted-to"))))))))
2133 (defun message-mail-p ()
2134 "Say whether the current buffer contains a mail message."
2135 (and (not message-this-is-news)
2136 (or message-this-is-mail
2139 (message-narrow-to-headers)
2140 (or (message-fetch-field "to")
2141 (message-fetch-field "cc")
2142 (message-fetch-field "bcc")))))))
2144 (defun message-subscribed-p ()
2145 "Say whether we need to insert a MFT header."
2146 (or message-subscribed-regexps
2147 message-subscribed-addresses
2148 message-subscribed-address-file
2149 message-subscribed-address-functions))
2151 (defun message-next-header ()
2152 "Go to the beginning of the next header."
2154 (or (eobp) (forward-char 1))
2155 (not (if (re-search-forward "^[^ \t]" nil t)
2157 (goto-char (point-max)))))
2159 (defun message-sort-headers-1 ()
2160 "Sort the buffer as headers using `message-rank' text props."
2161 (goto-char (point-min))
2164 nil 'message-next-header
2166 (message-next-header)
2170 (or (get-text-property (point) 'message-rank)
2173 (defun message-sort-headers ()
2174 "Sort the headers of the current message according to `message-header-format-alist'."
2178 (let ((max (1+ (length message-header-format-alist)))
2180 (message-narrow-to-headers)
2181 (while (re-search-forward "^[^ \n]+:" nil t)
2183 (match-beginning 0) (1+ (match-beginning 0))
2185 (if (setq rank (length (memq (assq (intern (buffer-substring
2187 (1- (match-end 0))))
2188 message-header-format-alist)
2189 message-header-format-alist)))
2192 (message-sort-headers-1))))
2194 (defun message-info (&optional arg)
2195 "Display the Message manual.
2197 Prefixed with one \\[universal-argument], display the Emacs MIME manual.
2198 Prefixed with two \\[universal-argument]'s, display the PGG manual."
2200 (cond ((eq arg 16) (Info-goto-node "(pgg)Top"))
2201 ((eq arg 4) (Info-goto-node "(emacs-mime)Top"))
2202 (t (Info-goto-node "(message)Top"))))
2212 (defvar message-mode-map nil)
2214 (unless message-mode-map
2215 (setq message-mode-map (make-keymap))
2216 (set-keymap-parent message-mode-map text-mode-map)
2217 (define-key message-mode-map "\C-c?" 'describe-mode)
2219 (define-key message-mode-map "\C-c\C-f\C-t" 'message-goto-to)
2220 (define-key message-mode-map "\C-c\C-f\C-o" 'message-goto-from)
2221 (define-key message-mode-map "\C-c\C-f\C-b" 'message-goto-bcc)
2222 (define-key message-mode-map "\C-c\C-f\C-w" 'message-goto-fcc)
2223 (define-key message-mode-map "\C-c\C-f\C-c" 'message-goto-cc)
2224 (define-key message-mode-map "\C-c\C-f\C-s" 'message-goto-subject)
2225 (define-key message-mode-map "\C-c\C-f\C-r" 'message-goto-reply-to)
2226 (define-key message-mode-map "\C-c\C-f\C-n" 'message-goto-newsgroups)
2227 (define-key message-mode-map "\C-c\C-f\C-d" 'message-goto-distribution)
2228 (define-key message-mode-map "\C-c\C-f\C-f" 'message-goto-followup-to)
2229 (define-key message-mode-map "\C-c\C-f\C-m" 'message-goto-mail-followup-to)
2230 (define-key message-mode-map "\C-c\C-f\C-k" 'message-goto-keywords)
2231 (define-key message-mode-map "\C-c\C-f\C-u" 'message-goto-summary)
2232 (define-key message-mode-map "\C-c\C-f\C-i"
2233 'message-insert-or-toggle-importance)
2234 (define-key message-mode-map "\C-c\C-f\C-a"
2235 'message-generate-unsubscribed-mail-followup-to)
2237 ;; modify headers (and insert notes in body)
2238 (define-key message-mode-map "\C-c\C-fs" 'message-change-subject)
2240 (define-key message-mode-map "\C-c\C-fx" 'message-cross-post-followup-to)
2241 ;; prefix+message-cross-post-followup-to = same w/o cross-post
2242 (define-key message-mode-map "\C-c\C-ft" 'message-reduce-to-to-cc)
2243 (define-key message-mode-map "\C-c\C-fa" 'message-add-archive-header)
2244 ;; mark inserted text
2245 (define-key message-mode-map "\C-c\M-m" 'message-mark-inserted-region)
2246 (define-key message-mode-map "\C-c\M-f" 'message-mark-insert-file)
2248 (define-key message-mode-map "\C-c\C-b" 'message-goto-body)
2249 (define-key message-mode-map "\C-c\C-i" 'message-goto-signature)
2251 (define-key message-mode-map "\C-c\C-t" 'message-insert-to)
2252 (define-key message-mode-map "\C-c\C-fw" 'message-insert-wide-reply)
2253 (define-key message-mode-map "\C-c\C-n" 'message-insert-newsgroups)
2254 (define-key message-mode-map "\C-c\C-l" 'message-to-list-only)
2256 (define-key message-mode-map "\C-c\C-u" 'message-insert-or-toggle-importance)
2257 (define-key message-mode-map "\C-c\M-n"
2258 'message-insert-disposition-notification-to)
2260 (define-key message-mode-map "\C-c\C-y" 'message-yank-original)
2261 (define-key message-mode-map "\C-c\M-\C-y" 'message-yank-buffer)
2262 (define-key message-mode-map "\C-c\C-q" 'message-fill-yanked-message)
2263 (define-key message-mode-map "\C-c\C-w" 'message-insert-signature)
2264 (define-key message-mode-map "\C-c\M-h" 'message-insert-headers)
2265 (define-key message-mode-map "\C-c\C-r" 'message-caesar-buffer-body)
2266 (define-key message-mode-map "\C-c\C-o" 'message-sort-headers)
2267 (define-key message-mode-map "\C-c\M-r" 'message-rename-buffer)
2269 (define-key message-mode-map "\C-c\C-c" 'message-send-and-exit)
2270 (define-key message-mode-map "\C-c\C-s" 'message-send)
2271 (define-key message-mode-map "\C-c\C-k" 'message-kill-buffer)
2272 (define-key message-mode-map "\C-c\C-d" 'message-dont-send)
2273 (define-key message-mode-map "\C-c\n" 'gnus-delay-article)
2275 (define-key message-mode-map "\C-c\C-e" 'message-elide-region)
2276 (define-key message-mode-map "\C-c\C-v" 'message-delete-not-region)
2277 (define-key message-mode-map "\C-c\C-z" 'message-kill-to-signature)
2278 (define-key message-mode-map "\M-\r" 'message-newline-and-reformat)
2279 ;;(define-key message-mode-map "\M-q" 'message-fill-paragraph)
2280 (define-key message-mode-map [remap split-line] 'message-split-line)
2282 (define-key message-mode-map "\C-c\C-a" 'mml-attach-file)
2284 (define-key message-mode-map "\C-a" 'message-beginning-of-line)
2285 (define-key message-mode-map "\t" 'message-tab)
2286 (define-key message-mode-map "\M-;" 'comment-region))
2289 message-mode-menu message-mode-map "Message Menu."
2291 ["Yank Original" message-yank-original message-reply-buffer]
2292 ["Fill Yanked Message" message-fill-yanked-message t]
2293 ["Insert Signature" message-insert-signature t]
2294 ["Caesar (rot13) Message" message-caesar-buffer-body t]
2295 ["Caesar (rot13) Region" message-caesar-region (message-mark-active-p)]
2296 ["Elide Region" message-elide-region
2297 :active (message-mark-active-p)
2298 ,@(if (featurep 'xemacs) nil
2299 '(:help "Replace text in region with an ellipsis"))]
2300 ["Delete Outside Region" message-delete-not-region
2301 :active (message-mark-active-p)
2302 ,@(if (featurep 'xemacs) nil
2303 '(:help "Delete all quoted text outside region"))]
2304 ["Kill To Signature" message-kill-to-signature t]
2305 ["Newline and Reformat" message-newline-and-reformat t]
2306 ["Rename buffer" message-rename-buffer t]
2307 ["Spellcheck" ispell-message
2308 ,@(if (featurep 'xemacs) '(t)
2309 '(:help "Spellcheck this message"))]
2311 ["Insert Region Marked" message-mark-inserted-region
2312 :active (message-mark-active-p)
2313 ,@(if (featurep 'xemacs) nil
2314 '(:help "Mark region with enclosing tags"))]
2315 ["Insert File Marked..." message-mark-insert-file
2316 ,@(if (featurep 'xemacs) '(t)
2317 '(:help "Insert file at point marked with enclosing tags"))]
2319 ["Send Message" message-send-and-exit
2320 ,@(if (featurep 'xemacs) '(t)
2321 '(:help "Send this message"))]
2322 ["Postpone Message" message-dont-send
2323 ,@(if (featurep 'xemacs) '(t)
2324 '(:help "File this draft message and exit"))]
2325 ["Send at Specific Time..." gnus-delay-article
2326 ,@(if (featurep 'xemacs) '(t)
2327 '(:help "Ask, then arrange to send message at that time"))]
2328 ["Kill Message" message-kill-buffer
2329 ,@(if (featurep 'xemacs) '(t)
2330 '(:help "Delete this message without sending"))]
2332 ["Message manual" message-info
2333 ,@(if (featurep 'xemacs) '(t)
2334 '(:help "Display the Message manual"))]))
2337 message-mode-field-menu message-mode-map ""
2339 ["To" message-goto-to t]
2340 ["From" message-goto-from t]
2341 ["Subject" message-goto-subject t]
2342 ["Change subject..." message-change-subject t]
2343 ["Cc" message-goto-cc t]
2344 ["Bcc" message-goto-bcc t]
2345 ["Fcc" message-goto-fcc t]
2346 ["Reply-To" message-goto-reply-to t]
2347 ["Flag As Important" message-insert-importance-high
2348 ,@(if (featurep 'xemacs) '(t)
2349 '(:help "Mark this message as important"))]
2350 ["Flag As Unimportant" message-insert-importance-low
2351 ,@(if (featurep 'xemacs) '(t)
2352 '(:help "Mark this message as unimportant"))]
2354 message-insert-disposition-notification-to
2355 ,@(if (featurep 'xemacs) '(t)
2356 '(:help "Request a receipt notification"))]
2358 ;; (typical) news stuff
2359 ["Summary" message-goto-summary t]
2360 ["Keywords" message-goto-keywords t]
2361 ["Newsgroups" message-goto-newsgroups t]
2362 ["Fetch Newsgroups" message-insert-newsgroups t]
2363 ["Followup-To" message-goto-followup-to t]
2364 ;; ["Followup-To (with note in body)" message-cross-post-followup-to t]
2365 ["Crosspost / Followup-To..." message-cross-post-followup-to t]
2366 ["Distribution" message-goto-distribution t]
2367 ["X-No-Archive:" message-add-archive-header t ]
2369 ;; (typical) mailing-lists stuff
2370 ["Fetch To" message-insert-to
2371 ,@(if (featurep 'xemacs) '(t)
2372 '(:help "Insert a To header that points to the author."))]
2373 ["Fetch To and Cc" message-insert-wide-reply
2374 ,@(if (featurep 'xemacs) '(t)
2376 "Insert To and Cc headers as if you were doing a wide reply."))]
2378 ["Send to list only" message-to-list-only t]
2379 ["Mail-Followup-To" message-goto-mail-followup-to t]
2380 ["Unsubscribed list post" message-generate-unsubscribed-mail-followup-to
2381 ,@(if (featurep 'xemacs) '(t)
2382 '(:help "Insert a reasonable `Mail-Followup-To:' header."))]
2383 ["Reduce To: to Cc:" message-reduce-to-to-cc t]
2385 ["Sort Headers" message-sort-headers t]
2386 ["Encode non-ASCII domain names" message-idna-to-ascii-rhs t]
2387 ["Goto Body" message-goto-body t]
2388 ["Goto Signature" message-goto-signature t]))
2390 (defvar message-tool-bar-map nil)
2393 (defvar facemenu-add-face-function)
2394 (defvar facemenu-remove-face-function))
2396 ;;; Forbidden properties
2398 ;; We use `after-change-functions' to keep special text properties
2399 ;; that interfer with the normal function of message mode out of the
2402 (defcustom message-strip-special-text-properties t
2403 "Strip special properties from the message buffer.
2405 Emacs has a number of special text properties which can break message
2406 composing in various ways. If this option is set, message will strip
2407 these properties from the message composition buffer. However, some
2408 packages requires these properties to be present in order to work.
2409 If you use one of these packages, turn this option off, and hope the
2410 message composition doesn't break too bad."
2412 :group 'message-various
2413 :link '(custom-manual "(message)Various Message Variables")
2416 (defconst message-forbidden-properties
2417 ;; No reason this should be clutter up customize. We make it a
2418 ;; property list (rather than a list of property symbols), to be
2419 ;; directly useful for `remove-text-properties'.
2420 '(field nil read-only nil invisible nil intangible nil
2421 mouse-face nil modification-hooks nil insert-in-front-hooks nil
2422 insert-behind-hooks nil point-entered nil point-left nil)
2423 ;; Other special properties:
2424 ;; category, face, display: probably doesn't do any harm.
2425 ;; fontified: is used by font-lock.
2426 ;; syntax-table, local-map: I dunno.
2427 ;; We need to add XEmacs names to the list.
2428 "Property list of with properties forbidden in message buffers.
2429 The values of the properties are ignored, only the property names are used.")
2431 (defun message-tamago-not-in-use-p (pos)
2432 "Return t when tamago version 4 is not in use at the cursor position.
2433 Tamago version 4 is a popular input method for writing Japanese text.
2434 It uses the properties `intangible', `invisible', `modification-hooks'
2435 and `read-only' when translating ascii or kana text to kanji text.
2436 These properties are essential to work, so we should never strip them."
2437 (not (and (boundp 'egg-modefull-mode)
2438 (symbol-value 'egg-modefull-mode)
2439 (or (memq (get-text-property pos 'intangible)
2440 '(its-part-1 its-part-2))
2441 (get-text-property pos 'egg-end)
2442 (get-text-property pos 'egg-lang)
2443 (get-text-property pos 'egg-start)))))
2445 (defun message-strip-forbidden-properties (begin end &optional old-length)
2446 "Strip forbidden properties between BEGIN and END, ignoring the third arg.
2447 This function is intended to be called from `after-change-functions'.
2448 See also `message-forbidden-properties'."
2449 (when (and message-strip-special-text-properties
2450 (message-tamago-not-in-use-p begin))
2451 (let ((buffer-read-only nil)
2452 (inhibit-read-only t))
2453 (while (not (= begin end))
2454 (when (not (get-text-property begin 'message-hidden))
2455 (remove-text-properties begin (1+ begin)
2456 message-forbidden-properties))
2460 (define-derived-mode message-mode text-mode "Message"
2461 "Major mode for editing mail and news to be sent.
2462 Like Text Mode but with these additional commands:\\<message-mode-map>
2463 C-c C-s `message-send' (send the message) C-c C-c `message-send-and-exit'
2464 C-c C-d Postpone sending the message C-c C-k Kill the message
2465 C-c C-f move to a header field (and create it if there isn't):
2466 C-c C-f C-t move to To C-c C-f C-s move to Subject
2467 C-c C-f C-c move to Cc C-c C-f C-b move to Bcc
2468 C-c C-f C-w move to Fcc C-c C-f C-r move to Reply-To
2469 C-c C-f C-u move to Summary C-c C-f C-n move to Newsgroups
2470 C-c C-f C-k move to Keywords C-c C-f C-d move to Distribution
2471 C-c C-f C-o move to From (\"Originator\")
2472 C-c C-f C-f move to Followup-To
2473 C-c C-f C-m move to Mail-Followup-To
2474 C-c C-f C-i cycle through Importance values
2475 C-c C-f s change subject and append \"(was: <Old Subject>)\"
2476 C-c C-f x crossposting with FollowUp-To header and note in body
2477 C-c C-f t replace To: header with contents of Cc: or Bcc:
2478 C-c C-f a Insert X-No-Archive: header and a note in the body
2479 C-c C-t `message-insert-to' (add a To header to a news followup)
2480 C-c C-l `message-to-list-only' (removes all but list address in to/cc)
2481 C-c C-n `message-insert-newsgroups' (add a Newsgroup header to a news reply)
2482 C-c C-b `message-goto-body' (move to beginning of message text).
2483 C-c C-i `message-goto-signature' (move to the beginning of the signature).
2484 C-c C-w `message-insert-signature' (insert `message-signature-file' file).
2485 C-c C-y `message-yank-original' (insert current message, if any).
2486 C-c C-q `message-fill-yanked-message' (fill what was yanked).
2487 C-c C-e `message-elide-region' (elide the text between point and mark).
2488 C-c C-v `message-delete-not-region' (remove the text outside the region).
2489 C-c C-z `message-kill-to-signature' (kill the text up to the signature).
2490 C-c C-r `message-caesar-buffer-body' (rot13 the message body).
2491 C-c C-a `mml-attach-file' (attach a file as MIME).
2492 C-c C-u `message-insert-or-toggle-importance' (insert or cycle importance).
2493 C-c M-n `message-insert-disposition-notification-to' (request receipt).
2494 C-c M-m `message-mark-inserted-region' (mark region with enclosing tags).
2495 C-c M-f `message-mark-insert-file' (insert file marked with enclosing tags).
2496 M-RET `message-newline-and-reformat' (break the line and reformat)."
2497 (setq local-abbrev-table text-mode-abbrev-table)
2498 (set (make-local-variable 'message-reply-buffer) nil)
2499 (set (make-local-variable 'message-inserted-headers) nil)
2500 (set (make-local-variable 'message-send-actions) nil)
2501 (set (make-local-variable 'message-exit-actions) nil)
2502 (set (make-local-variable 'message-kill-actions) nil)
2503 (set (make-local-variable 'message-postpone-actions) nil)
2504 (set (make-local-variable 'message-draft-article) nil)
2505 (setq buffer-offer-save t)
2506 (set (make-local-variable 'facemenu-add-face-function)
2508 (let ((face-fun (cdr (assq face message-face-alist))))
2510 (funcall face-fun (point) end)
2511 (error "Face %s not configured for %s mode" face mode-name)))
2513 (set (make-local-variable 'facemenu-remove-face-function) t)
2514 (set (make-local-variable 'message-reply-headers) nil)
2515 (make-local-variable 'message-newsreader)
2516 (make-local-variable 'message-mailer)
2517 (make-local-variable 'message-post-method)
2518 (set (make-local-variable 'message-sent-message-via) nil)
2519 (set (make-local-variable 'message-checksum) nil)
2520 (set (make-local-variable 'message-mime-part) 0)
2521 (message-setup-fill-variables)
2522 ;; Allow using comment commands to add/remove quoting.
2523 ;; (set (make-local-variable 'comment-start) message-yank-prefix)
2524 (when message-yank-prefix
2525 (set (make-local-variable 'comment-start) message-yank-prefix)
2526 (set (make-local-variable 'comment-start-skip)
2527 (concat "^" (regexp-quote message-yank-prefix) "[ \t]*")))
2528 (if (featurep 'xemacs)
2529 (message-setup-toolbar)
2530 (set (make-local-variable 'font-lock-defaults)
2531 '(message-font-lock-keywords t))
2532 (if (boundp 'tool-bar-map)
2533 (set (make-local-variable 'tool-bar-map) (message-make-tool-bar))))
2534 (easy-menu-add message-mode-menu message-mode-map)
2535 (easy-menu-add message-mode-field-menu message-mode-map)
2536 (gnus-make-local-hook 'after-change-functions)
2537 ;; Mmmm... Forbidden properties...
2538 (add-hook 'after-change-functions 'message-strip-forbidden-properties
2540 ;; Allow mail alias things.
2541 (when (eq message-mail-alias-type 'abbrev)
2542 (if (fboundp 'mail-abbrevs-setup)
2543 (mail-abbrevs-setup)
2544 (if (fboundp 'mail-aliases-setup) ; warning avoidance
2545 (mail-aliases-setup))))
2546 (unless buffer-file-name
2547 (message-set-auto-save-file-name))
2548 (unless (buffer-base-buffer)
2549 ;; Don't enable multibyte on an indirect buffer. Maybe enabling
2550 ;; multibyte is not necessary at all. -- zsh
2551 (mm-enable-multibyte))
2552 (set (make-local-variable 'indent-tabs-mode) nil) ;No tabs for indentation.
2555 (defun message-setup-fill-variables ()
2556 "Setup message fill variables."
2557 (set (make-local-variable 'fill-paragraph-function)
2558 'message-fill-paragraph)
2559 (make-local-variable 'paragraph-separate)
2560 (make-local-variable 'paragraph-start)
2561 (make-local-variable 'adaptive-fill-regexp)
2562 (unless (boundp 'adaptive-fill-first-line-regexp)
2563 (setq adaptive-fill-first-line-regexp nil))
2564 (make-local-variable 'adaptive-fill-first-line-regexp)
2565 (let ((quote-prefix-regexp
2566 ;; User should change message-cite-prefix-regexp if
2567 ;; message-yank-prefix is set to an abnormal value.
2568 (concat "\\(" message-cite-prefix-regexp "\\)[ \t]*")))
2569 (setq paragraph-start
2571 (regexp-quote mail-header-separator) "$\\|"
2572 "[ \t]*$\\|" ; blank lines
2573 "-- $\\|" ; signature delimiter
2574 "---+$\\|" ; delimiters for forwarded messages
2575 page-delimiter "$\\|" ; spoiler warnings
2576 ".*wrote:$\\|" ; attribution lines
2577 quote-prefix-regexp "$\\|" ; empty lines in quoted text
2579 "<#!*/?\\(multipart\\|part\\|external\\|mml\\|secure\\)"))
2580 (setq paragraph-separate paragraph-start)
2581 (setq adaptive-fill-regexp
2582 (concat quote-prefix-regexp "\\|" adaptive-fill-regexp))
2583 (setq adaptive-fill-first-line-regexp
2584 (concat quote-prefix-regexp "\\|"
2585 adaptive-fill-first-line-regexp)))
2586 (make-local-variable 'auto-fill-inhibit-regexp)
2587 ;;(setq auto-fill-inhibit-regexp "^[A-Z][^: \n\t]+:")
2588 (setq auto-fill-inhibit-regexp nil)
2589 (make-local-variable 'normal-auto-fill-function)
2590 (setq normal-auto-fill-function 'message-do-auto-fill)
2591 ;; KLUDGE: auto fill might already be turned on in `text-mode-hook'.
2592 ;; In that case, ensure that it uses the right function. The real
2593 ;; solution would be not to use `define-derived-mode', and run
2594 ;; `text-mode-hook' ourself at the end of the mode.
2595 ;; -- Per Abrahamsen <abraham@dina.kvl.dk> Date: 2001-10-19.
2596 (when auto-fill-function
2597 (setq auto-fill-function normal-auto-fill-function)))
2602 ;;; Message mode commands
2605 ;;; Movement commands
2607 (defun message-goto-to ()
2608 "Move point to the To header."
2610 (message-position-on-field "To"))
2612 (defun message-goto-from ()
2613 "Move point to the From header."
2615 (message-position-on-field "From"))
2617 (defun message-goto-subject ()
2618 "Move point to the Subject header."
2620 (message-position-on-field "Subject"))
2622 (defun message-goto-cc ()
2623 "Move point to the Cc header."
2625 (message-position-on-field "Cc" "To"))
2627 (defun message-goto-bcc ()
2628 "Move point to the Bcc header."
2630 (message-position-on-field "Bcc" "Cc" "To"))
2632 (defun message-goto-fcc ()
2633 "Move point to the Fcc header."
2635 (message-position-on-field "Fcc" "To" "Newsgroups"))
2637 (defun message-goto-reply-to ()
2638 "Move point to the Reply-To header."
2640 (message-position-on-field "Reply-To" "Subject"))
2642 (defun message-goto-newsgroups ()
2643 "Move point to the Newsgroups header."
2645 (message-position-on-field "Newsgroups"))
2647 (defun message-goto-distribution ()
2648 "Move point to the Distribution header."
2650 (message-position-on-field "Distribution"))
2652 (defun message-goto-followup-to ()
2653 "Move point to the Followup-To header."
2655 (message-position-on-field "Followup-To" "Newsgroups"))
2657 (defun message-goto-mail-followup-to ()
2658 "Move point to the Mail-Followup-To header."
2660 (message-position-on-field "Mail-Followup-To" "To"))
2662 (defun message-goto-keywords ()
2663 "Move point to the Keywords header."
2665 (message-position-on-field "Keywords" "Subject"))
2667 (defun message-goto-summary ()
2668 "Move point to the Summary header."
2670 (message-position-on-field "Summary" "Subject"))
2672 (defun message-goto-body (&optional interactivep)
2673 "Move point to the beginning of the message body."
2674 (interactive (list t))
2675 (when (and interactivep
2676 (looking-at "[ \t]*\n"))
2678 (goto-char (point-min))
2679 (or (search-forward (concat "\n" mail-header-separator "\n") nil t)
2680 (search-forward-regexp "[^:]+:\\([^\n]\\|\n[ \t]\\)+\n\n" nil t)))
2682 (defun message-goto-eoh ()
2683 "Move point to the end of the headers."
2688 (defun message-goto-signature ()
2689 "Move point to the beginning of the message signature.
2690 If there is no signature in the article, go to the end and
2693 (goto-char (point-min))
2694 (if (re-search-forward message-signature-separator nil t)
2696 (goto-char (point-max))
2699 (defun message-generate-unsubscribed-mail-followup-to (&optional include-cc)
2700 "Insert a reasonable MFT header in a post to an unsubscribed list.
2701 When making original posts to a mailing list you are not subscribed to,
2702 you have to type in a MFT header by hand. The contents, usually, are
2703 the addresses of the list and your own address. This function inserts
2704 such a header automatically. It fetches the contents of the To: header
2705 in the current mail buffer, and appends the current `user-mail-address'.
2707 If the optional argument INCLUDE-CC is non-nil, the addresses in the
2708 Cc: header are also put into the MFT."
2713 (message-narrow-to-headers)
2714 (message-remove-header "Mail-Followup-To")
2715 (setq cc (and include-cc (message-fetch-field "Cc")))
2717 (concat (message-fetch-field "To") "," cc)
2718 (message-fetch-field "To"))))
2719 (message-goto-mail-followup-to)
2720 (insert (concat tos ", " user-mail-address))))
2724 (defun message-insert-to (&optional force)
2725 "Insert a To header that points to the author of the article being replied to.
2726 If the original author requested not to be sent mail, don't insert unless the
2727 prefix FORCE is given."
2729 (let* ((mct (message-fetch-reply-field "mail-copies-to"))
2730 (dont (and mct (or (equal (downcase mct) "never")
2731 (equal (downcase mct) "nobody"))))
2732 (to (or (message-fetch-reply-field "mail-reply-to")
2733 (message-fetch-reply-field "reply-to")
2734 (message-fetch-reply-field "from"))))
2738 "Ignoring the user request not to have copies sent via mail"
2739 "Complying with the user request not to have copies sent via mail")))
2740 (when (and force (not to))
2741 (error "No mail address in the article"))
2742 (when (and to (or force (not dont)))
2743 (message-carefully-insert-headers (list (cons 'To to))))))
2745 (defun message-insert-wide-reply ()
2746 "Insert To and Cc headers as if you were doing a wide reply."
2748 (let ((headers (message-with-reply-buffer
2749 (message-get-reply-headers t))))
2750 (message-carefully-insert-headers headers)))
2752 (defcustom message-header-synonyms
2755 "List of lists of header synonyms.
2756 E.g., if this list contains a member list with elements `Cc' and `To',
2757 then `message-carefully-insert-headers' will not insert a `To' header
2758 when the message is already `Cc'ed to the recipient."
2760 :group 'message-headers
2761 :link '(custom-manual "(message)Message Headers")
2762 :type '(repeat sexp))
2764 (defun message-carefully-insert-headers (headers)
2765 "Insert the HEADERS, an alist, into the message buffer.
2766 Does not insert the headers when they are already present there
2767 or in the synonym headers, defined by `message-header-synonyms'."
2768 ;; FIXME: Should compare only the address and not the full name. Comparison
2769 ;; should be done case-folded (and with `string=' rather than
2771 ;; (mail-strip-quoted-names "Foo Bar <foo@bar>, bla@fasel (Bla Fasel)")
2772 (dolist (header headers)
2773 (let* ((header-name (symbol-name (car header)))
2774 (new-header (cdr header))
2775 (synonyms (loop for synonym in message-header-synonyms
2776 when (memq (car header) synonym) return synonym))
2778 (loop for synonym in synonyms
2779 for old-header = (mail-fetch-field (symbol-name synonym))
2780 when (and old-header (string-match new-header old-header))
2783 (message "already have `%s' in `%s'" new-header old-header)
2784 (when (and (message-position-on-field header-name)
2785 (setq old-header (mail-fetch-field header-name))
2786 (not (string-match "\\` *\\'" old-header)))
2788 (insert new-header)))))
2790 (defun message-widen-reply ()
2791 "Widen the reply to include maximum recipients."
2794 (and message-reply-buffer
2795 (buffer-name message-reply-buffer)
2797 (set-buffer message-reply-buffer)
2798 (message-get-reply-headers t)))))
2801 (message-narrow-to-headers)
2802 (dolist (elem follow-to)
2803 (message-remove-header (symbol-name (car elem)))
2804 (goto-char (point-min))
2805 (insert (symbol-name (car elem)) ": "
2806 (cdr elem) "\n"))))))
2808 (defun message-insert-newsgroups ()
2809 "Insert the Newsgroups header from the article being replied to."
2811 (when (and (message-position-on-field "Newsgroups")
2812 (mail-fetch-field "newsgroups")
2813 (not (string-match "\\` *\\'" (mail-fetch-field "newsgroups"))))
2815 (insert (or (message-fetch-reply-field "newsgroups") "")))
2819 ;;; Various commands
2821 (defun message-delete-not-region (beg end)
2822 "Delete everything in the body of the current message outside of the region."
2827 ;; snarf citation prefix, if appropriate
2828 (unless (eq (point) (progn (beginning-of-line) (point)))
2829 (when (looking-at message-cite-prefix-regexp)
2830 (setq citeprefix (match-string 0))))
2832 (delete-region (point) (if (not (message-goto-signature))
2838 (delete-region beg (progn (message-goto-body)
2842 (insert citeprefix))))
2843 (when (message-goto-signature)
2846 (defun message-kill-to-signature ()
2847 "Deletes all text up to the signature."
2849 (let ((point (point)))
2850 (message-goto-signature)
2853 (kill-region point (point))
2857 (defun message-newline-and-reformat (&optional arg not-break)
2858 "Insert four newlines, and then reformat if inside quoted text.
2859 Prefix arg means justify as well."
2860 (interactive (list (if current-prefix-arg 'full)))
2861 (let (quoted point beg end leading-space bolp)
2862 (setq point (point))
2865 (setq bolp (= beg point))
2866 ;; Find first line of the paragraph.
2868 (while (and (not (eobp))
2869 (not (looking-at message-cite-prefix-regexp))
2870 (looking-at paragraph-start))
2873 (when (looking-at message-cite-prefix-regexp)
2874 (setq quoted (match-string 0))
2875 (goto-char (match-end 0))
2876 (looking-at "[ \t]*")
2877 (setq leading-space (match-string 0)))
2881 (< (- point beg) (length quoted)))
2882 ;; break inside the cite prefix.
2888 (while (and (not (eobp))
2889 (not (looking-at paragraph-separate))
2890 (looking-at message-cite-prefix-regexp)
2891 (equal quoted (match-string 0)))
2892 (goto-char (match-end 0))
2893 (looking-at "[ \t]*")
2894 (if (> (length leading-space) (length (match-string 0)))
2895 (setq leading-space (match-string 0)))
2899 (while (and (if (bobp) nil (forward-line -1) t)
2900 (not (looking-at paragraph-start))
2901 (looking-at message-cite-prefix-regexp)
2902 (equal quoted (match-string 0)))
2904 (goto-char (match-end 0))
2905 (looking-at "[ \t]*")
2906 (if (> (length leading-space) (length (match-string 0)))
2907 (setq leading-space (match-string 0)))))
2908 (while (and (not (eobp))
2909 (not (looking-at paragraph-separate))
2910 (not (looking-at message-cite-prefix-regexp)))
2914 (while (and (if (bobp) nil (forward-line -1) t)
2915 (not (looking-at paragraph-start))
2916 (not (looking-at message-cite-prefix-regexp)))
2917 (setq beg (point))))
2920 (narrow-to-region beg end)
2927 (setq point (point))
2928 ;; (newline 2) doesn't mark both newline's as hard, so call
2929 ;; newline twice. -jas
2932 (delete-region (point) (re-search-forward "[ \t]*"))
2933 (when (and quoted (not bolp))
2934 (insert quoted leading-space)))
2937 (let* ((adaptive-fill-regexp
2938 (regexp-quote (concat quoted leading-space)))
2939 (adaptive-fill-first-line-regexp
2940 adaptive-fill-regexp ))
2941 (fill-paragraph arg))
2942 (fill-paragraph arg))
2943 (if point (goto-char point)))))
2945 (defun message-fill-paragraph (&optional arg)
2946 "Like `fill-paragraph'."
2947 (interactive (list (if current-prefix-arg 'full)))
2948 (if (if (boundp 'filladapt-mode) filladapt-mode)
2950 (message-newline-and-reformat arg t)
2953 ;; Is it better to use `mail-header-end'?
2954 (defun message-point-in-header-p ()
2955 "Return t if point is in the header."
2958 (goto-char (point-min))
2959 (not (re-search-forward
2960 (concat "^" (regexp-quote mail-header-separator) "\n")
2963 (defun message-do-auto-fill ()
2964 "Like `do-auto-fill', but don't fill in message header."
2965 (unless (message-point-in-header-p)
2968 (defun message-insert-signature (&optional force)
2969 "Insert a signature. See documentation for variable `message-signature'."
2970 (interactive (list 0))
2973 ((and (null message-signature)
2976 (goto-char (point-max))
2977 (not (re-search-backward message-signature-separator nil t))))
2978 ((and (null message-signature)
2981 ((functionp message-signature)
2982 (funcall message-signature))
2983 ((listp message-signature)
2984 (eval message-signature))
2985 (t message-signature)))
2987 (cond ((stringp signature)
2989 ((and (eq t signature)
2990 message-signature-file
2991 (file-exists-p message-signature-file))
2994 (goto-char (point-max))
2995 ;; Insert the signature.
2998 (when message-signature-insert-empty-line
3001 (if (eq signature t)
3002 (insert-file-contents message-signature-file)
3004 (goto-char (point-max))
3005 (or (bolp) (insert "\n")))))
3007 (defun message-insert-importance-high ()
3008 "Insert header to mark message as important."
3012 (message-narrow-to-headers)
3013 (message-remove-header "Importance"))
3015 (insert "Importance: high\n")))
3017 (defun message-insert-importance-low ()
3018 "Insert header to mark message as unimportant."
3022 (message-narrow-to-headers)
3023 (message-remove-header "Importance"))
3025 (insert "Importance: low\n")))
3027 (defun message-insert-or-toggle-importance ()
3028 "Insert a \"Importance: high\" header, or cycle through the header values.
3029 The three allowed values according to RFC 1327 are `high', `normal'
3033 (let ((valid '("high" "normal" "low"))
3037 (message-narrow-to-headers)
3038 (when (setq cur (message-fetch-field "Importance"))
3039 (message-remove-header "Importance")
3040 (setq new (cond ((string= cur "high")
3042 ((string= cur "low")
3047 (insert (format "Importance: %s\n" new)))))
3049 (defun message-insert-disposition-notification-to ()
3050 "Request a disposition notification (return receipt) to this message.
3051 Note that this should not be used in newsgroups."
3055 (message-narrow-to-headers)
3056 (message-remove-header "Disposition-Notification-To"))
3058 (insert (format "Disposition-Notification-To: %s\n"
3059 (or (message-field-value "Reply-to")
3060 (message-field-value "From")
3061 (message-make-from))))))
3063 (defun message-elide-region (b e)
3064 "Elide the text in the region.
3065 An ellipsis (from `message-elide-ellipsis') will be inserted where the
3069 (insert message-elide-ellipsis))
3071 (defvar message-caesar-translation-table nil)
3073 (defun message-caesar-region (b e &optional n)
3074 "Caesar rotate region B to E by N, default 13, for decrypting netnews."
3077 (min (point) (or (mark t) (point)))
3078 (max (point) (or (mark t) (point)))
3079 (when current-prefix-arg
3080 (prefix-numeric-value current-prefix-arg))))
3082 (setq n (if (numberp n) (mod n 26) 13)) ;canonize N
3083 (unless (or (zerop n) ; no action needed for a rot of 0
3084 (= b e)) ; no region to rotate
3085 ;; We build the table, if necessary.
3086 (when (or (not message-caesar-translation-table)
3087 (/= (aref message-caesar-translation-table ?a) (+ ?a n)))
3088 (setq message-caesar-translation-table
3089 (message-make-caesar-translation-table n)))
3090 (translate-region b e message-caesar-translation-table)))
3092 (defun message-make-caesar-translation-table (n)
3093 "Create a rot table with offset N."
3095 (table (make-string 256 0)))
3096 (while (< (incf i) 256)
3099 (substring table 0 ?A)
3100 (substring table (+ ?A n) (+ ?A n (- 26 n)))
3101 (substring table ?A (+ ?A n))
3102 (substring table (+ ?A 26) ?a)
3103 (substring table (+ ?a n) (+ ?a n (- 26 n)))
3104 (substring table ?a (+ ?a n))
3105 (substring table (+ ?a 26) 255))))
3107 (defun message-caesar-buffer-body (&optional rotnum)
3108 "Caesar rotate all letters in the current buffer by 13 places.
3109 Used to encode/decode possibly offensive messages (commonly in rec.humor).
3110 With prefix arg, specifies the number of places to rotate each letter forward.
3111 Mail and USENET news headers are not rotated."
3112 (interactive (if current-prefix-arg
3113 (list (prefix-numeric-value current-prefix-arg))
3117 (when (message-goto-body)
3118 (narrow-to-region (point) (point-max)))
3119 (message-caesar-region (point-min) (point-max) rotnum))))
3121 (defun message-pipe-buffer-body (program)
3122 "Pipe the message body in the current buffer through PROGRAM."
3125 (when (message-goto-body)
3126 (narrow-to-region (point) (point-max)))
3127 (shell-command-on-region
3128 (point-min) (point-max) program nil t))))
3130 (defun message-rename-buffer (&optional enter-string)
3131 "Rename the *message* buffer to \"*message* RECIPIENT\".
3132 If the function is run with a prefix, it will ask for a new buffer
3133 name, rather than giving an automatic name."
3134 (interactive "Pbuffer name: ")
3137 (goto-char (point-min))
3138 (narrow-to-region (point)
3139 (search-forward mail-header-separator nil 'end))
3141 (if (message-news-p) (message-fetch-field "Newsgroups")
3142 (message-fetch-field "To"))
3145 (if (string-match "," mail-to)
3146 (concat (substring mail-to 0 (match-beginning 0)) ", ...")
3148 (name-default (concat "*message* " mail-trimmed-to))
3149 (name (if enter-string
3150 (read-string "New buffer name: " name-default)
3152 (rename-buffer name t)))))
3154 (defun message-fill-yanked-message (&optional justifyp)
3155 "Fill the paragraphs of a message yanked into this one.
3156 Numeric argument means justify as well."
3159 (goto-char (point-min))
3160 (search-forward (concat "\n" mail-header-separator "\n") nil t)
3161 (let ((fill-prefix message-yank-prefix))
3162 (fill-individual-paragraphs (point) (point-max) justifyp))))
3164 (defun message-indent-citation ()
3165 "Modify text just inserted from a message to be cited.
3166 The inserted text should be the region.
3167 When this function returns, the region is again around the modified text.
3169 Normally, indent each nonblank line `message-indentation-spaces' spaces.
3170 However, if `message-yank-prefix' is non-nil, insert that prefix on each line."
3171 (let ((start (point)))
3172 ;; Remove unwanted headers.
3173 (when message-ignored-cited-headers
3178 (if (search-forward "\n\n" nil t)
3181 (message-remove-header message-ignored-cited-headers t)
3182 (when (= (point-min) (point-max))
3183 (setq all-removed t))
3184 (goto-char (point-max)))
3188 ;; Delete blank lines at the start of the buffer.
3189 (while (and (point-min)
3192 (message-delete-line))
3193 ;; Delete blank lines at the end of the buffer.
3194 (goto-char (point-max))
3197 (while (and (zerop (forward-line -1))
3199 (message-delete-line))
3200 ;; Do the indentation.
3201 (if (null message-yank-prefix)
3202 (indent-rigidly start (mark t) message-indentation-spaces)
3205 (while (< (point) (mark t))
3206 (if (or (looking-at ">") (looking-at "^$"))
3207 (insert message-yank-cited-prefix)
3208 (insert message-yank-prefix))
3212 (defun message-yank-original (&optional arg)
3213 "Insert the message being replied to, if any.
3214 Puts point before the text and mark after.
3215 Normally indents each nonblank line ARG spaces (default 3). However,
3216 if `message-yank-prefix' is non-nil, insert that prefix on each line.
3218 This function uses `message-cite-function' to do the actual citing.
3220 Just \\[universal-argument] as argument means don't indent, insert no
3221 prefix, and don't delete any headers."
3223 (let ((modified (buffer-modified-p)))
3224 (when (and message-reply-buffer
3225 message-cite-function)
3226 (delete-windows-on message-reply-buffer t)
3227 (push-mark (save-excursion
3228 (insert-buffer-substring message-reply-buffer)
3231 (funcall message-cite-function))
3232 (message-exchange-point-and-mark)
3236 (setq message-checksum (message-checksum))))))
3238 (defun message-yank-buffer (buffer)
3239 "Insert BUFFER into the current buffer and quote it."
3240 (interactive "bYank buffer: ")
3241 (let ((message-reply-buffer (get-buffer buffer)))
3242 (save-window-excursion
3243 (message-yank-original))))
3245 (defun message-buffers ()
3246 "Return a list of active message buffers."
3249 (dolist (buffer (buffer-list t))
3251 (when (and (eq major-mode 'message-mode)
3252 (null message-sent-message-via))
3253 (push (buffer-name buffer) buffers))))
3254 (nreverse buffers)))
3256 (defun message-cite-original-without-signature ()
3257 "Cite function in the standard Message manner."
3258 (let* ((start (point))
3261 (when message-indent-citation-function
3262 (if (listp message-indent-citation-function)
3263 message-indent-citation-function
3264 (list message-indent-citation-function))))
3265 ;; This function may be called by `gnus-summary-yank-message' and
3266 ;; may insert a different article from the original. So, we will
3267 ;; modify the value of `message-reply-headers' with that article.
3268 (message-reply-headers
3270 (narrow-to-region start end)
3271 (message-narrow-to-head-1)
3273 (or (message-fetch-field "subject") "none")
3274 (message-fetch-field "from")
3275 (message-fetch-field "date")
3276 (message-fetch-field "message-id" t)
3277 (message-fetch-field "references")
3279 (mml-quote-region start end)
3283 (when (re-search-backward message-signature-separator start t)
3284 ;; Also peel off any blank lines before the signature.
3286 (while (looking-at "^[ \t]*$")
3289 (delete-region (point) end)
3290 (unless (search-backward "\n\n" start t)
3291 ;; Insert a blank line if it is peeled off.
3295 (funcall (pop functions)))
3296 (when message-citation-line-function
3299 (funcall message-citation-line-function))))
3301 (eval-when-compile (defvar mail-citation-hook)) ;Compiler directive
3302 (defun message-cite-original ()
3303 "Cite function in the standard Message manner."
3304 (if (and (boundp 'mail-citation-hook)
3306 (run-hooks 'mail-citation-hook)
3307 (let* ((start (point))
3310 (when message-indent-citation-function
3311 (if (listp message-indent-citation-function)
3312 message-indent-citation-function
3313 (list message-indent-citation-function))))
3314 ;; This function may be called by `gnus-summary-yank-message' and
3315 ;; may insert a different article from the original. So, we will
3316 ;; modify the value of `message-reply-headers' with that article.
3317 (message-reply-headers
3319 (narrow-to-region start end)
3320 (message-narrow-to-head-1)
3322 (or (message-fetch-field "subject") "none")
3323 (message-fetch-field "from")
3324 (message-fetch-field "date")
3325 (message-fetch-field "message-id" t)
3326 (message-fetch-field "references")
3328 (mml-quote-region start end)
3331 (funcall (pop functions)))
3332 (when message-citation-line-function
3335 (funcall message-citation-line-function)))))
3337 (defun message-insert-citation-line ()
3338 "Insert a simple citation line."
3339 (when message-reply-headers
3340 (insert (mail-header-from message-reply-headers) " writes:")
3344 (defun message-position-on-field (header &rest afters)
3345 (let ((case-fold-search t))
3348 (goto-char (point-min))
3351 (concat "^" (regexp-quote mail-header-separator) "$"))
3352 (match-beginning 0)))
3353 (goto-char (point-min))
3354 (if (re-search-forward (concat "^" (regexp-quote header) ":") nil t)
3356 (re-search-forward "^[^ \t]" nil 'move)
3358 (skip-chars-backward "\n")
3361 (not (re-search-forward
3362 (concat "^" (regexp-quote (car afters)) ":")
3366 (re-search-forward "^[^ \t]" nil 'move)
3367 (beginning-of-line))
3368 (insert header ": \n")
3372 (defun message-remove-signature ()
3373 "Remove the signature from the text between point and mark.
3374 The text will also be indented the normal way."
3376 (let ((start (point))
3378 (if (not (re-search-forward message-signature-separator (mark t) t))
3379 ;; No signature here, so we just indent the cited text.
3380 (message-indent-citation)
3381 ;; Find the last non-empty line.
3383 (while (looking-at "[ \t]*$")
3386 (setq mark (set-marker (make-marker) (point)))
3388 (message-indent-citation)
3389 ;; Enable undoing the deletion.
3391 (delete-region mark (mark t))
3392 (set-marker mark nil)))))
3397 ;;; Sending messages
3400 (defun message-send-and-exit (&optional arg)
3401 "Send message like `message-send', then, if no errors, exit from mail buffer."
3403 (let ((buf (current-buffer))
3404 (actions message-exit-actions))
3405 (when (and (message-send arg)
3407 (if message-kill-buffer-on-exit
3410 (when (eq buf (current-buffer))
3411 (message-bury buf)))
3412 (message-do-actions actions)
3415 (defun message-dont-send ()
3416 "Don't send the message you have been editing.
3417 Instead, just auto-save the buffer and then bury it."
3419 (set-buffer-modified-p t)
3421 (let ((actions message-postpone-actions))
3422 (message-bury (current-buffer))
3423 (message-do-actions actions)))
3425 (defun message-kill-buffer ()
3426 "Kill the current buffer."
3428 (when (or (not (buffer-modified-p))
3429 (yes-or-no-p "Message modified; kill anyway? "))
3430 (let ((actions message-kill-actions)
3431 (draft-article message-draft-article)
3432 (auto-save-file-name buffer-auto-save-file-name)
3433 (file-name buffer-file-name)
3434 (modified (buffer-modified-p)))
3435 (setq buffer-file-name nil)
3436 (kill-buffer (current-buffer))
3437 (when (and (or (and auto-save-file-name
3438 (file-exists-p auto-save-file-name))
3440 (file-exists-p file-name)))
3442 ;; If the message buffer has lived in a dedicated window,
3443 ;; `kill-buffer' has killed the frame. Thus the
3444 ;; `yes-or-no-p' may show up in a lowered frame. Make sure
3445 ;; that the user can see the question by raising the
3448 (yes-or-no-p (format "Remove the backup file%s? "
3449 (if modified " too" "")))))
3451 (delete-file auto-save-file-name))
3452 (let ((message-draft-article draft-article))
3453 (message-disassociate-draft)))
3454 (message-do-actions actions))))
3456 (defun message-bury (buffer)
3457 "Bury this mail BUFFER."
3458 (let ((newbuf (other-buffer buffer)))
3459 (bury-buffer buffer)
3460 (if (and (window-dedicated-p (selected-window))
3461 (not (null (delq (selected-frame) (visible-frame-list)))))
3462 (delete-frame (selected-frame))
3463 (switch-to-buffer newbuf))))
3465 (defun message-send (&optional arg)
3466 "Send the message in the current buffer.
3467 If `message-interactive' is non-nil, wait for success indication or
3468 error messages, and inform user.
3469 Otherwise any failure is reported in a message back to the user from
3471 The usage of ARG is defined by the instance that called Message.
3472 It should typically alter the sending method in some way or other."
3474 ;; Make it possible to undo the coming changes.
3476 (let ((inhibit-read-only t))
3477 (put-text-property (point-min) (point-max) 'read-only nil))
3478 (message-fix-before-sending)
3479 (run-hooks 'message-send-hook)
3480 (message message-sending-message)
3481 (let ((alist message-send-method-alist)
3483 elem sent dont-barf-on-no-method
3484 (message-options message-options))
3485 (message-options-set-recipient)
3487 (setq elem (pop alist)))
3488 (when (funcall (cadr elem))
3489 (when (and (or (not (memq (car elem)
3490 message-sent-message-via))
3491 (message-fetch-field "supersedes")
3492 (if (or (message-gnksa-enable-p 'multiple-copies)
3493 (not (eq (car elem) 'news)))
3496 "Already sent message via %s; resend? "
3498 (error "Denied posting -- multiple copies")))
3499 (setq success (funcall (caddr elem) arg)))
3503 (let ((fcc (message-fetch-field "Fcc"))
3504 (gcc (message-fetch-field "Gcc")))
3506 (or (eq message-allow-no-recipients 'always)
3507 (and (not (eq message-allow-no-recipients 'never))
3508 (setq dont-barf-on-no-method
3510 (format "No receiver, perform %s anyway? "
3511 (cond ((and fcc gcc) "Fcc and Gcc")
3514 (error "No methods specified to send by"))
3515 (when (or dont-barf-on-no-method
3519 (run-hooks 'message-sent-hook))
3520 (message "Sending...done")
3521 ;; Mark the buffer as unmodified and delete auto-save.
3522 (set-buffer-modified-p nil)
3523 (delete-auto-save-file-if-necessary t)
3524 (message-disassociate-draft)
3525 ;; Delete other mail buffers and stuff.
3526 (message-do-send-housekeeping)
3527 (message-do-actions message-send-actions)
3531 (defun message-send-via-mail (arg)
3532 "Send the current message via mail."
3533 (message-send-mail arg))
3535 (defun message-send-via-news (arg)
3536 "Send the current message via news."
3537 (funcall message-send-news-function arg))
3539 (defmacro message-check (type &rest forms)
3540 "Eval FORMS if TYPE is to be checked."
3541 `(or (message-check-element ,type)
3545 (put 'message-check 'lisp-indent-function 1)
3546 (put 'message-check 'edebug-form-spec '(form body))
3548 (defun message-text-with-property (prop)
3549 "Return a list of all points where the text has PROP."
3551 (point (point-min)))
3553 (while (< point (point-max))
3554 (when (get-text-property point prop)
3555 (push point points))
3559 (defun message-fix-before-sending ()
3560 "Do various things to make the message nice before sending it."
3561 ;; Make sure there's a newline at the end of the message.
3562 (goto-char (point-max))
3565 ;; Make the hidden headers visible.
3566 (let ((points (message-text-with-property 'message-hidden)))
3568 (goto-char (car points))
3569 (dolist (point points)
3570 (add-text-properties point (1+ point)
3571 '(invisible nil intangible nil)))))
3572 ;; Make invisible text visible.
3573 ;; It doesn't seem as if this is useful, since the invisible property
3574 ;; is clobbered by an after-change hook anyhow.
3575 (message-check 'invisible-text
3576 (let ((points (message-text-with-property 'invisible)))
3578 (goto-char (car points))
3579 (dolist (point points)
3580 (put-text-property point (1+ point) 'invisible nil)
3581 (message-overlay-put (message-make-overlay point (1+ point))
3583 (unless (yes-or-no-p
3584 "Invisible text found and made visible; continue sending? ")
3585 (error "Invisible text found and made visible")))))
3586 (message-check 'illegible-text
3589 (skip-chars-forward mm-7bit-chars)
3591 (when (let ((char (char-after)))
3592 (or (< (mm-char-int char) 128)
3593 (and (mm-multibyte-p)
3594 (memq (char-charset char)
3595 '(eight-bit-control eight-bit-graphic
3597 (not (get-text-property
3598 (point) 'untranslated-utf-8)))))
3599 (message-overlay-put (message-make-overlay (point) (1+ (point)))
3603 (skip-chars-forward mm-7bit-chars))
3606 (gnus-multiple-choice
3607 "Non-printable characters found. Continue sending?"
3608 '((?d "Remove non-printable characters and send")
3609 (?r "Replace non-printable characters with dots and send")
3610 (?i "Ignore non-printable characters and send")
3611 (?e "Continue editing"))))
3613 (error "Non-printable characters"))
3615 (skip-chars-forward mm-7bit-chars)
3617 (when (let ((char (char-after)))
3618 (or (< (mm-char-int char) 128)
3619 (and (mm-multibyte-p)
3620 ;; FIXME: Wrong for Emacs 23 (unicode) and for
3621 ;; things like undecable utf-8. Should at least
3622 ;; use find-coding-systems-region.
3623 (memq (char-charset char)
3624 '(eight-bit-control eight-bit-graphic
3626 (not (get-text-property
3627 (point) 'untranslated-utf-8)))))
3629 (message-kill-all-overlays)
3631 (when (eq choice ?r)
3634 (skip-chars-forward mm-7bit-chars))))))
3636 (defun message-add-action (action &rest types)
3637 "Add ACTION to be performed when doing an exit of type TYPES."
3639 (add-to-list (intern (format "message-%s-actions" (pop types)))
3642 (defun message-delete-action (action &rest types)
3643 "Delete ACTION from lists of actions performed when doing an exit of type TYPES."
3646 (set (setq var (intern (format "message-%s-actions" (pop types))))
3647 (delq action (symbol-value var))))))
3649 (defun message-do-actions (actions)
3650 "Perform all actions in ACTIONS."
3651 ;; Now perform actions on successful sending.
3655 ;; A simple function.
3656 ((functionp (car actions))
3657 (funcall (car actions)))
3658 ;; Something to be evaled.
3660 (eval (car actions)))))
3663 (defun message-send-mail-partially ()
3664 "Send mail as message/partial."
3665 ;; replace the header delimiter with a blank line
3666 (goto-char (point-min))
3668 (concat "^" (regexp-quote mail-header-separator) "\n"))
3669 (replace-match "\n")
3670 (run-hooks 'message-send-mail-hook)
3671 (let ((p (goto-char (point-min)))
3672 (tembuf (message-generate-new-buffer-clone-locals " message temp"))
3673 (curbuf (current-buffer))
3674 (id (message-make-message-id)) (n 1)
3675 plist total header required-mail-headers)
3677 (if (< (point-max) (+ p message-send-mail-partially-limit))
3678 (goto-char (point-max))
3679 (goto-char (+ p message-send-mail-partially-limit))
3681 (if (<= (point) p) (forward-line 1))) ;; In case of bad message.
3684 (setq total (length plist))
3685 (push (point-max) plist)
3686 (setq plist (nreverse plist))
3689 (setq p (pop plist))
3692 (copy-to-buffer tembuf p (car plist))
3694 (goto-char (point-min))
3697 (goto-char (point-min))
3698 (narrow-to-region (point) (point))
3701 (setq header (buffer-substring (point-min) (point)))
3702 (goto-char (point-min))
3703 (narrow-to-region (point) (point))
3705 (message-remove-header "Mime-Version")
3706 (message-remove-header "Content-Type")
3707 (message-remove-header "Content-Transfer-Encoding")
3708 (message-remove-header "Message-ID")
3709 (message-remove-header "Lines")
3710 (goto-char (point-max))
3711 (insert "Mime-Version: 1.0\n")
3712 (setq header (buffer-string)))
3713 (goto-char (point-max))
3714 (insert (format "Content-Type: message/partial; id=\"%s\"; number=%d; total=%d\n\n"
3717 (let ((mail-header-separator ""))
3718 (when (memq 'Message-ID message-required-mail-headers)
3719 (insert "Message-ID: " (message-make-message-id) "\n"))
3720 (when (memq 'Lines message-required-mail-headers)
3721 (insert "Lines: " (message-make-lines) "\n"))
3722 (message-goto-subject)
3724 (insert (format " (%d/%d)" n total))
3726 (mm-with-unibyte-current-buffer
3727 (funcall (or message-send-mail-real-function
3728 message-send-mail-function))))
3730 (setq p (pop plist))
3732 (kill-buffer tembuf))))
3734 (defun message-send-mail (&optional arg)
3735 (require 'mail-utils)
3736 (let* ((tembuf (message-generate-new-buffer-clone-locals " message temp"))
3737 (case-fold-search nil)
3738 (news (message-news-p))
3739 (mailbuf (current-buffer))
3740 (message-this-is-mail t)
3741 (message-posting-charset
3742 (if (fboundp 'gnus-setup-posting-charset)
3743 (gnus-setup-posting-charset nil)
3744 message-posting-charset))
3745 (headers message-required-mail-headers))
3747 (message-narrow-to-headers)
3748 ;; Generate the Mail-Followup-To header if the header is not there...
3749 (if (and (message-subscribed-p)
3750 (not (mail-fetch-field "mail-followup-to")))
3753 (cons "Mail-Followup-To" (message-make-mail-followup-to))
3754 message-required-mail-headers))
3755 ;; otherwise, delete the MFT header if the field is empty
3756 (when (equal "" (mail-fetch-field "mail-followup-to"))
3757 (message-remove-header "^Mail-Followup-To:")))
3758 ;; Insert some headers.
3759 (let ((message-deletable-headers
3760 (if news nil message-deletable-headers)))
3761 (message-generate-headers headers))
3762 ;; Let the user do all of the above.
3763 (run-hooks 'message-header-hook))
3768 ;; Avoid copying text props (except hard newlines).
3769 (insert (with-current-buffer mailbuf
3770 (mml-buffer-substring-no-properties-except-hard-newlines
3771 (point-min) (point-max))))
3772 ;; Remove some headers.
3773 (message-encode-message-body)
3775 (message-narrow-to-headers)
3776 ;; We (re)generate the Lines header.
3777 (when (memq 'Lines message-required-mail-headers)
3778 (message-generate-headers '(Lines)))
3779 ;; Remove some headers.
3780 (message-remove-header message-ignored-mail-headers t)
3781 (let ((mail-parse-charset message-default-charset))
3782 (mail-encode-encoded-word-buffer)))
3783 (goto-char (point-max))
3784 ;; require one newline at the end.
3785 (or (= (preceding-char) ?\n)
3787 (message-cleanup-headers)
3788 ;; FIXME: we're inserting the courtesy copy after encoding.
3789 ;; This is wrong if the courtesy copy string contains
3790 ;; non-ASCII characters. -- jh
3793 (message-narrow-to-headers)
3795 (or (message-fetch-field "cc")
3796 (message-fetch-field "bcc")
3797 (message-fetch-field "to"))
3798 (let ((content-type (message-fetch-field
3803 (string= "text/plain"
3805 (mail-header-parse-content-type
3809 (message-fetch-field
3810 "content-transfer-encoding")))))))
3811 (message-insert-courtesy-copy))
3812 (if (or (not message-send-mail-partially-limit)
3813 (< (buffer-size) message-send-mail-partially-limit)
3814 (not (message-y-or-n-p
3815 "The message size is too large, split? "
3819 (/ (buffer-size) 1000) "KB, is too large.
3821 Some mail gateways (MTA's) bounce large messages. To avoid the
3822 problem, answer `y', and the message will be split into several
3823 smaller pieces, the size of each is about "
3824 (/ message-send-mail-partially-limit 1000)
3828 However, some mail readers (MUA's) can't read split messages, i.e.,
3829 mails in message/partially format. Answer `n', and the message will be
3832 The size limit is controlled by `message-send-mail-partially-limit'.
3833 If you always want Gnus to send messages in one piece, set
3834 `message-send-mail-partially-limit' to nil.
3836 (mm-with-unibyte-current-buffer
3837 (message "Sending via mail...")
3838 (funcall (or message-send-mail-real-function
3839 message-send-mail-function)))
3840 (message-send-mail-partially)))
3841 (kill-buffer tembuf))
3842 (set-buffer mailbuf)
3843 (push 'mail message-sent-message-via)))
3845 (defun message-send-mail-with-sendmail ()
3846 "Send off the prepared buffer with sendmail."
3847 (let ((errbuf (if message-interactive
3848 (message-generate-new-buffer-clone-locals
3851 resend-to-addresses delimline)
3854 (let ((case-fold-search t))
3856 (message-narrow-to-headers)
3857 (setq resend-to-addresses (message-fetch-field "resent-to")))
3858 ;; Change header-delimiter to be what sendmail expects.
3859 (goto-char (point-min))
3861 (concat "^" (regexp-quote mail-header-separator) "\n"))
3862 (replace-match "\n")
3864 (setq delimline (point-marker))
3865 (run-hooks 'message-send-mail-hook)
3866 ;; Insert an extra newline if we need it to work around
3867 ;; Sun's bug that swallows newlines.
3868 (goto-char (1+ delimline))
3869 (when (eval message-mailer-swallows-blank-line)
3871 (when message-interactive
3875 (let* ((default-directory "/")
3876 (coding-system-for-write message-send-coding-system)
3878 'call-process-region
3880 (list (point-min) (point-max)
3881 (if (boundp 'sendmail-program)
3883 "/usr/lib/sendmail")
3884 nil errbuf nil "-oi")
3885 ;; Always specify who from,
3886 ;; since some systems have broken sendmails.
3887 ;; But some systems are more broken with -f, so
3888 ;; we'll let users override this.
3889 (if (null message-sendmail-f-is-evil)
3890 (list "-f" (message-sendmail-envelope-from)))
3891 ;; These mean "report errors by mail"
3892 ;; and "deliver in background".
3893 (if (null message-interactive) '("-oem" "-odb"))
3894 ;; Get the addresses from the message
3895 ;; unless this is a resend.
3896 ;; We must not do that for a resend
3897 ;; because we would find the original addresses.
3898 ;; For a resend, include the specific addresses.
3899 (if resend-to-addresses
3900 (list resend-to-addresses)
3902 (unless (or (null cpr) (and (numberp cpr) (zerop cpr)))
3903 (error "Sending...failed with exit value %d" cpr)))
3904 (when message-interactive
3907 (goto-char (point-min))
3908 (while (re-search-forward "\n\n* *" nil t)
3909 (replace-match "; "))
3910 (if (not (zerop (buffer-size)))
3911 (error "Sending...failed to %s"
3912 (buffer-string))))))
3913 (when (bufferp errbuf)
3914 (kill-buffer errbuf)))))
3916 (defun message-send-mail-with-qmail ()
3917 "Pass the prepared message buffer to qmail-inject.
3918 Refer to the documentation for the variable `message-send-mail-function'
3919 to find out how to use this."
3920 ;; replace the header delimiter with a blank line
3921 (goto-char (point-min))
3923 (concat "^" (regexp-quote mail-header-separator) "\n"))
3924 (replace-match "\n")
3925 (run-hooks 'message-send-mail-hook)
3928 (let ((coding-system-for-write message-send-coding-system))
3930 'call-process-region (point-min) (point-max)
3931 message-qmail-inject-program nil nil nil
3932 ;; qmail-inject's default behaviour is to look for addresses on the
3933 ;; command line; if there're none, it scans the headers.
3934 ;; yes, it does The Right Thing w.r.t. Resent-To and it's kin.
3936 ;; in general, ALL of qmail-inject's defaults are perfect for simply
3937 ;; reading a formatted (i. e., at least a To: or Resent-To header)
3938 ;; message from stdin.
3940 ;; qmail also has the advantage of not having been raped by
3941 ;; various vendors, so we don't have to allow for that, either --
3942 ;; compare this with message-send-mail-with-sendmail and weep
3943 ;; for sendmail's lost innocence.
3945 ;; all this is way cool coz it lets us keep the arguments entirely
3946 ;; free for -inject-arguments -- a big win for the user and for us
3947 ;; since we don't have to play that double-guessing game and the user
3948 ;; gets full control (no gestapo'ish -f's, for instance). --sj
3949 (if (functionp message-qmail-inject-args)
3950 (funcall message-qmail-inject-args)
3951 message-qmail-inject-args)))
3952 ;; qmail-inject doesn't say anything on it's stdout/stderr,
3953 ;; we have to look at the retval instead
3955 (100 (error "qmail-inject reported permanent failure"))
3956 (111 (error "qmail-inject reported transient failure"))
3957 ;; should never happen
3958 (t (error "qmail-inject reported unknown failure"))))
3960 (defun message-send-mail-with-mh ()
3961 "Send the prepared message buffer with mh."
3962 (let ((mh-previous-window-config nil)
3963 (name (mh-new-draft-name)))
3964 (setq buffer-file-name name)
3965 ;; MH wants to generate these headers itself.
3966 (when message-mh-deletable-headers
3967 (let ((headers message-mh-deletable-headers))
3969 (goto-char (point-min))
3970 (and (re-search-forward
3971 (concat "^" (symbol-name (car headers)) ": *") nil t)
3972 (message-delete-line))
3974 (run-hooks 'message-send-mail-hook)
3975 ;; Pass it on to mh.
3978 (defun message-smtpmail-send-it ()
3979 "Send the prepared message buffer with `smtpmail-send-it'.
3980 This only differs from `smtpmail-send-it' that this command evaluates
3981 `message-send-mail-hook' just before sending a message. It is useful
3982 if your ISP requires the POP-before-SMTP authentication. See the Gnus
3983 manual for details."
3984 (run-hooks 'message-send-mail-hook)
3987 (defun message-canlock-generate ()
3988 "Return a string that is non-trivial to guess.
3989 Do not use this for anything important, it is cryptographically weak."
3991 (let (sha1-maximum-internal-length)
3992 (sha1 (concat (message-unique-id)
3993 (format "%x%x%x" (random) (random t) (random))
3994 (prin1-to-string (recent-keys))
3995 (prin1-to-string (garbage-collect))))))
3997 (defun message-canlock-password ()
3998 "The password used by message for cancel locks.
3999 This is the value of `canlock-password', if that option is non-nil.
4000 Otherwise, generate and save a value for `canlock-password' first."
4001 (unless canlock-password
4002 (customize-save-variable 'canlock-password (message-canlock-generate))
4003 (setq canlock-password-for-verify canlock-password))
4006 (defun message-insert-canlock ()
4007 (when message-insert-canlock
4008 (message-canlock-password)
4009 (canlock-insert-header)))
4011 (defun message-send-news (&optional arg)
4012 (let* ((tembuf (message-generate-new-buffer-clone-locals " *message temp*"))
4013 (case-fold-search nil)
4014 (method (if (functionp message-post-method)
4015 (funcall message-post-method arg)
4016 message-post-method))
4017 (newsgroups-field (save-restriction
4018 (message-narrow-to-headers-or-head)
4019 (message-fetch-field "Newsgroups")))
4020 (followup-field (save-restriction
4021 (message-narrow-to-headers-or-head)
4022 (message-fetch-field "Followup-To")))
4023 ;; BUG: We really need to get the charset for each name in the
4024 ;; Newsgroups and Followup-To lines to allow crossposting
4025 ;; between group namess with incompatible character sets.
4026 ;; -- Per Abrahamsen <abraham@dina.kvl.dk> 2001-10-08.
4027 (group-field-charset
4028 (gnus-group-name-charset method newsgroups-field))
4029 (followup-field-charset
4030 (gnus-group-name-charset method (or followup-field "")))
4031 (rfc2047-header-encoding-alist
4032 (append (when group-field-charset
4033 (list (cons "Newsgroups" group-field-charset)))
4034 (when followup-field-charset
4035 (list (cons "Followup-To" followup-field-charset)))
4036 rfc2047-header-encoding-alist))
4037 (messbuf (current-buffer))
4038 (message-syntax-checks
4040 (listp message-syntax-checks))
4041 (cons '(existing-newsgroups . disabled)
4042 message-syntax-checks)
4043 message-syntax-checks))
4044 (message-this-is-news t)
4045 (message-posting-charset
4046 (gnus-setup-posting-charset newsgroups-field))
4048 (if (not (message-check-news-body-syntax))
4051 (message-narrow-to-headers)
4052 ;; Insert some headers.
4053 (message-generate-headers message-required-news-headers)
4054 (message-insert-canlock)
4055 ;; Let the user do all of the above.
4056 (run-hooks 'message-header-hook))
4057 ;; Note: This check will be disabled by the ".*" default value for
4058 ;; gnus-group-name-charset-group-alist. -- Pa 2001-10-07.
4059 (when (and group-field-charset
4060 (listp message-syntax-checks))
4061 (setq message-syntax-checks
4062 (cons '(valid-newsgroups . disabled)
4063 message-syntax-checks)))
4064 (message-cleanup-headers)
4065 (if (not (let ((message-post-method method))
4066 (message-check-news-syntax)))
4071 (buffer-disable-undo)
4073 ;; Avoid copying text props (except hard newlines).
4075 (with-current-buffer messbuf
4076 (mml-buffer-substring-no-properties-except-hard-newlines
4077 (point-min) (point-max))))
4078 (message-encode-message-body)
4079 ;; Remove some headers.
4081 (message-narrow-to-headers)
4082 ;; We (re)generate the Lines header.
4083 (when (memq 'Lines message-required-mail-headers)
4084 (message-generate-headers '(Lines)))
4085 ;; Remove some headers.
4086 (message-remove-header message-ignored-news-headers t)
4087 (let ((mail-parse-charset message-default-charset))
4088 (mail-encode-encoded-word-buffer)))
4089 (goto-char (point-max))
4090 ;; require one newline at the end.
4091 (or (= (preceding-char) ?\n)
4093 (let ((case-fold-search t))
4094 ;; Remove the delimiter.
4095 (goto-char (point-min))
4097 (concat "^" (regexp-quote mail-header-separator) "\n"))
4098 (replace-match "\n")
4100 (run-hooks 'message-send-news-hook)
4101 (gnus-open-server method)
4102 (message "Sending news via %s..." (gnus-server-string method))
4103 (setq result (let ((mail-header-separator ""))
4104 (gnus-request-post method))))
4105 (kill-buffer tembuf))
4106 (set-buffer messbuf)
4108 (push 'news message-sent-message-via)
4109 (message "Couldn't send message via news: %s"
4110 (nnheader-get-report (car method)))
4114 ;;; Header generation & syntax checking.
4117 (defun message-check-element (type)
4118 "Return non-nil if this TYPE is not to be checked."
4119 (if (eq message-syntax-checks 'dont-check-for-anything-just-trust-me)
4121 (let ((able (assq type message-syntax-checks)))
4123 (eq (cdr able) 'disabled)))))
4125 (defun message-check-news-syntax ()
4126 "Check the syntax of the message."
4130 ;; We narrow to the headers and check them first.
4133 (message-narrow-to-headers)
4134 (message-check-news-header-syntax))))))
4136 (defun message-check-news-header-syntax ()
4138 ;; Check Newsgroups header.
4139 (message-check 'newsgroups
4140 (let ((group (message-fetch-field "newsgroups")))
4143 (not (string-match "\\`[ \t]*\\'" group)))
4146 "The newsgroups field is empty or missing. Posting is denied.")))))
4147 ;; Check the Subject header.
4148 (message-check 'subject
4149 (let* ((case-fold-search t)
4150 (subject (message-fetch-field "subject")))
4153 (not (string-match "\\`[ \t]*\\'" subject)))
4156 "The subject field is empty or missing. Posting is denied.")))))
4157 ;; Check for commands in Subject.
4158 (message-check 'subject-cmsg
4159 (if (string-match "^cmsg " (message-fetch-field "subject"))
4161 "The control code \"cmsg\" is in the subject. Really post? ")
4163 ;; Check long header lines.
4164 (message-check 'long-header-lines
4165 (let ((start (point))
4169 (while (and (not found)
4170 (re-search-forward "^\\([^ \t:]+\\): " nil t))
4171 (if (> (- (point) (match-beginning 0)) 998)
4173 length (- (point) (match-beginning 0)))
4174 (setq header (match-string-no-properties 1)))
4175 (setq start (match-beginning 0))
4178 (y-or-n-p (format "Your %s header is too long (%d). Really post? "
4181 ;; Check for multiple identical headers.
4182 (message-check 'multiple-headers
4184 (while (and (not found)
4185 (re-search-forward "^[^ \t:]+: " nil t))
4187 (or (re-search-forward
4192 (match-beginning 0) (- (match-end 0) 2))))
4197 (y-or-n-p (format "Multiple %s headers. Really post? " found))
4199 ;; Check for Version and Sendsys.
4200 (message-check 'sendsys
4201 (if (re-search-forward "^Sendsys:\\|^Version:" nil t)
4203 (format "The article contains a %s command. Really post? "
4204 (buffer-substring (match-beginning 0)
4205 (1- (match-end 0)))))
4207 ;; See whether we can shorten Followup-To.
4208 (message-check 'shorten-followup-to
4209 (let ((newsgroups (message-fetch-field "newsgroups"))
4210 (followup-to (message-fetch-field "followup-to"))
4212 (when (and newsgroups
4213 (string-match "," newsgroups)
4218 (setq to (completing-read
4219 "Followups to (default no Followup-To header): "
4222 (message-tokenize-header
4224 (goto-char (point-min))
4225 (insert "Followup-To: " to "\n"))
4227 ;; Check "Shoot me".
4228 (message-check 'shoot
4229 (if (re-search-forward
4230 "Message-ID.*.i-did-not-set--mail-host-address--so-tickle-me" nil t)
4231 (y-or-n-p "You appear to have a misconfigured system. Really post? ")
4233 ;; Check for Approved.
4234 (message-check 'approved
4235 (if (re-search-forward "^Approved:" nil t)
4236 (y-or-n-p "The article contains an Approved header. Really post? ")
4238 ;; Check the Message-ID header.
4239 (message-check 'message-id
4240 (let* ((case-fold-search t)
4241 (message-id (message-fetch-field "message-id" t)))
4242 (or (not message-id)
4243 ;; Is there an @ in the ID?
4244 (and (string-match "@" message-id)
4245 ;; Is there a dot in the ID?
4246 (string-match "@[^.]*\\." message-id)
4247 ;; Does the ID end with a dot?
4248 (not (string-match "\\.>" message-id)))
4250 (format "The Message-ID looks strange: \"%s\". Really post? "
4252 ;; Check the Newsgroups & Followup-To headers.
4253 (message-check 'existing-newsgroups
4254 (let* ((case-fold-search t)
4255 (newsgroups (message-fetch-field "newsgroups"))
4256 (followup-to (message-fetch-field "followup-to"))
4257 (groups (message-tokenize-header
4259 (concat newsgroups "," followup-to)
4261 (post-method (if (functionp message-post-method)
4262 (funcall message-post-method)
4263 message-post-method))
4264 ;; KLUDGE to handle nnvirtual groups. Doing this right
4265 ;; would probably involve a new nnoo function.
4266 ;; -- Per Abrahamsen <abraham@dina.kvl.dk>, 2001-10-17.
4267 (method (if (and (consp post-method)
4268 (eq (car post-method) 'nnvirtual)
4269 gnus-message-group-art)
4270 (let ((group (car (nnvirtual-find-group-art
4271 (car gnus-message-group-art)
4272 (cdr gnus-message-group-art)))))
4273 (gnus-find-method-for-group group))
4277 (gnus-group-name-decode
4278 (gnus-group-real-name n)
4279 (gnus-group-name-charset method n)))
4280 (gnus-groups-from-server method)))
4283 (when (and (not (equal (car groups) "poster"))
4284 (not (member (car groups) known-groups))
4285 (not (member (car groups) errors)))
4286 (push (car groups) errors))
4289 ;; Gnus is not running.
4290 ((or (not (and (boundp 'gnus-active-hashtb)
4291 gnus-active-hashtb))
4292 (not (boundp 'gnus-read-active-file)))
4294 ;; We don't have all the group names.
4295 ((and (or (not gnus-read-active-file)
4296 (eq gnus-read-active-file 'some))
4300 "Really use %s possibly unknown group%s: %s? "
4301 (if (= (length errors) 1) "this" "these")
4302 (if (= (length errors) 1) "" "s")
4303 (mapconcat 'identity errors ", "))))
4304 ;; There were no errors.
4307 ;; There are unknown groups.
4311 "Really post to %s unknown group%s: %s? "
4312 (if (= (length errors) 1) "this" "these")
4313 (if (= (length errors) 1) "" "s")
4314 (mapconcat 'identity errors ", ")))))))
4315 ;; Check continuation headers.
4316 (message-check 'continuation-headers
4317 (goto-char (point-min))
4318 (let ((do-posting t))
4319 (while (re-search-forward "^[^ \t\n][^:\n]*$" nil t)
4320 (if (y-or-n-p "Fix continuation lines? ")
4322 (goto-char (match-beginning 0))
4324 (unless (y-or-n-p "Send anyway? ")
4325 (setq do-posting nil))))
4327 ;; Check the Newsgroups & Followup-To headers for syntax errors.
4328 (message-check 'valid-newsgroups
4329 (let ((case-fold-search t)
4330 (headers '("Newsgroups" "Followup-To"))
4332 (while (and headers (not error))
4333 (when (setq header (mail-fetch-field (car headers)))
4337 "\\`\\([-+_&.a-zA-Z0-9]+\\)?\\(,[-+_&.a-zA-Z0-9]+\\)*\\'"
4342 (not (string-match "\\.\\'\\|\\.\\." g)))
4343 (message-tokenize-header header ","))))
4350 (format "The %s header looks odd: \"%s\". Really post? "
4351 (car headers) header)))))
4352 (message-check 'repeated-newsgroups
4353 (let ((case-fold-search t)
4354 (headers '("Newsgroups" "Followup-To"))
4355 header error groups group)
4358 (when (setq header (mail-fetch-field (pop headers)))
4359 (setq groups (message-tokenize-header header ","))
4360 (while (setq group (pop groups))
4361 (when (member group groups)
4367 (format "Group %s is repeated in headers. Really post? " error)))))
4368 ;; Check the From header.
4369 (message-check 'from
4370 (let* ((case-fold-search t)
4371 (from (message-fetch-field "from"))
4375 (message "There is no From line. Posting is denied.")
4377 ((or (not (string-match
4379 (setq ad (nth 1 (mail-extract-address-components
4380 from))))) ;larsi@ifi
4381 (string-match "\\.\\." ad) ;larsi@ifi..uio
4382 (string-match "@\\." ad) ;larsi@.ifi.uio
4383 (string-match "\\.$" ad) ;larsi@ifi.uio.
4384 (not (string-match "^[^@]+@[^@]+$" ad)) ;larsi.ifi.uio
4385 (string-match "(.*).*(.*)" from)) ;(lars) (lars)
4387 "Denied posting -- the From looks strange: \"%s\"." from)
4389 ((let ((addresses (rfc822-addresses from)))
4390 (while (and addresses
4391 (not (eq (string-to-char (car addresses)) ?\()))
4392 (setq addresses (cdr addresses)))
4395 "Denied posting -- bad From address: \"%s\"." from)
4398 ;; Check the Reply-To header.
4399 (message-check 'reply-to
4400 (let* ((case-fold-search t)
4401 (reply-to (message-fetch-field "reply-to"))
4406 ((string-match "," reply-to)
4408 (format "Multiple Reply-To addresses: \"%s\". Really post? "
4410 ((or (not (string-match
4412 (setq ad (nth 1 (mail-extract-address-components
4413 reply-to))))) ;larsi@ifi
4414 (string-match "\\.\\." ad) ;larsi@ifi..uio
4415 (string-match "@\\." ad) ;larsi@.ifi.uio
4416 (string-match "\\.$" ad) ;larsi@ifi.uio.
4417 (not (string-match "^[^@]+@[^@]+$" ad)) ;larsi.ifi.uio
4418 (string-match "(.*).*(.*)" reply-to)) ;(lars) (lars)
4421 "The Reply-To looks strange: \"%s\". Really post? "
4425 (defun message-check-news-body-syntax ()
4427 ;; Check for long lines.
4428 (message-check 'long-lines
4429 (goto-char (point-min))
4431 (concat "^" (regexp-quote mail-header-separator) "$"))
4435 "<#\\(/\\)?\\(multipart\\|part\\|external\\|mml\\)")
4438 (< (- (point) p) 80)))
4439 (zerop (forward-line 1))))
4443 "You have lines longer than 79 characters. Really post? ")))
4444 ;; Check whether the article is empty.
4445 (message-check 'empty
4446 (goto-char (point-min))
4448 (concat "^" (regexp-quote mail-header-separator) "$"))
4451 (goto-char (point-max))
4452 (re-search-backward message-signature-separator nil t)
4454 (or (re-search-backward "[^ \n\t]" b t)
4455 (if (message-gnksa-enable-p 'empty-article)
4456 (y-or-n-p "Empty article. Really post? ")
4457 (message "Denied posting -- Empty article.")
4459 ;; Check for control characters.
4460 (message-check 'control-chars
4461 (if (re-search-forward
4462 (mm-string-as-multibyte "[\000-\007\013\015-\032\034-\037\200-\237]")
4465 "The article contains control characters. Really post? ")
4467 ;; Check excessive size.
4468 (message-check 'size
4469 (if (> (buffer-size) 60000)
4471 (format "The article is %d octets long. Really post? "
4474 ;; Check whether any new text has been added.
4475 (message-check 'new-text
4477 (not message-checksum)
4478 (not (eq (message-checksum) message-checksum))
4479 (if (message-gnksa-enable-p 'quoted-text-only)
4481 "It looks like no new text has been added. Really post? ")
4482 (message "Denied posting -- no new text has been added.")
4484 ;; Check the length of the signature.
4485 (message-check 'signature
4486 (goto-char (point-max))
4487 (if (> (count-lines (point) (point-max)) 5)
4490 "Your .sig is %d lines; it should be max 4. Really post? "
4491 (1- (count-lines (point) (point-max)))))
4493 ;; Ensure that text follows last quoted portion.
4494 (message-check 'quoting-style
4495 (goto-char (point-max))
4496 (let ((no-problem t))
4497 (when (search-backward-regexp "^>[^\n]*\n" nil t)
4498 (setq no-problem (search-forward-regexp "^[ \t]*[^>\n]" nil t)))
4501 (if (message-gnksa-enable-p 'quoted-text-only)
4502 (y-or-n-p "Your text should follow quoted text. Really post? ")
4504 (goto-char (point-min))
4506 (concat "^" (regexp-quote mail-header-separator) "$"))
4507 (if (search-forward-regexp "^[ \t]*[^>\n]" nil t)
4508 (y-or-n-p "Your text should follow quoted text. Really post? ")
4509 (message "Denied posting -- only quoted text.")
4512 (defun message-checksum ()
4513 "Return a \"checksum\" for the current buffer."
4516 (goto-char (point-min))
4518 (concat "^" (regexp-quote mail-header-separator) "$"))
4520 (when (not (looking-at "[ \t\n]"))
4521 (setq sum (logxor (ash sum 1) (if (natnump sum) 0 1)
4526 (defun message-do-fcc ()
4527 "Process Fcc headers in the current buffer."
4528 (let ((case-fold-search t)
4529 (buf (current-buffer))
4531 (mml-externalize-attachments message-fcc-externalize-attachments))
4534 (message-narrow-to-headers)
4535 (setq file (message-fetch-field "fcc" t)))
4537 (set-buffer (get-buffer-create " *message temp*"))
4539 (insert-buffer-substring buf)
4540 (message-encode-message-body)
4542 (message-narrow-to-headers)
4543 (while (setq file (message-fetch-field "fcc" t))
4545 (message-remove-header "fcc" nil t))
4546 (let ((mail-parse-charset message-default-charset)
4547 (rfc2047-header-encoding-alist
4548 (cons '("Newsgroups" . default)
4549 rfc2047-header-encoding-alist)))
4550 (mail-encode-encoded-word-buffer)))
4551 (goto-char (point-min))
4552 (when (re-search-forward
4553 (concat "^" (regexp-quote mail-header-separator) "$")
4555 (replace-match "" t t ))
4556 ;; Process FCC operations.
4558 (setq file (pop list))
4559 (if (string-match "^[ \t]*|[ \t]*\\(.*\\)[ \t]*$" file)
4560 ;; Pipe the article to the program in question.
4561 (call-process-region (point-min) (point-max) shell-file-name
4562 nil nil nil shell-command-switch
4563 (match-string 1 file))
4564 ;; Save the article.
4565 (setq file (expand-file-name file))
4566 (unless (file-exists-p (file-name-directory file))
4567 (make-directory (file-name-directory file) t))
4568 (if (and message-fcc-handler-function
4569 (not (eq message-fcc-handler-function 'rmail-output)))
4570 (funcall message-fcc-handler-function file)
4571 (if (and (file-readable-p file) (mail-file-babyl-p file))
4572 (rmail-output file 1 nil t)
4573 (let ((mail-use-rfc822 t))
4574 (rmail-output file 1 t t))))))
4575 (kill-buffer (current-buffer))))))
4577 (defun message-output (filename)
4578 "Append this article to Unix/babyl mail file FILENAME."
4579 (if (and (file-readable-p filename)
4580 (mail-file-babyl-p filename))
4581 (gnus-output-to-rmail filename t)
4582 (gnus-output-to-mail filename t)))
4584 (defun message-cleanup-headers ()
4585 "Do various automatic cleanups of the headers."
4586 ;; Remove empty lines in the header.
4588 (message-narrow-to-headers)
4589 ;; Remove blank lines.
4590 (while (re-search-forward "^[ \t]*\n" nil t)
4591 (replace-match "" t t))
4593 ;; Correct Newsgroups and Followup-To headers: Change sequence of
4594 ;; spaces to comma and eliminate spaces around commas. Eliminate
4595 ;; embedded line breaks.
4596 (goto-char (point-min))
4597 (while (re-search-forward "^\\(Newsgroups\\|Followup-To\\): +" nil t)
4601 (if (re-search-forward "^[^ \t]" nil t)
4605 (goto-char (point-min))
4606 (while (re-search-forward "\n[ \t]+" nil t)
4607 (replace-match " " t t)) ;No line breaks (too confusing)
4608 (goto-char (point-min))
4609 (while (re-search-forward "[ \t\n]*,[ \t\n]*\\|[ \t]+" nil t)
4610 (replace-match "," t t))
4611 (goto-char (point-min))
4612 ;; Remove trailing commas.
4613 (when (re-search-forward ",+$" nil t)
4614 (replace-match "" t t))))))
4616 (eval-when-compile (require 'parse-time))
4617 (defun message-make-date (&optional now)
4618 "Make a valid data header.
4619 If NOW, use that time instead."
4620 (require 'parse-time)
4621 (let* ((now (or now (current-time)))
4622 (zone (nth 8 (decode-time now)))
4626 (setq zone (- zone)))
4628 ;; The day name of the %a spec is locale-specific. Pfff.
4629 (format "%s, " (capitalize (car (rassoc (nth 6 (decode-time now))
4630 parse-time-weekdays))))
4631 (format-time-string "%d" now)
4632 ;; The month name of the %b spec is locale-specific. Pfff.
4634 (capitalize (car (rassoc (nth 4 (decode-time now))
4635 parse-time-months))))
4636 (format-time-string "%Y %H:%M:%S " now)
4637 ;; We do all of this because XEmacs doesn't have the %z spec.
4638 (format "%s%02d%02d" sign (/ zone 3600) (/ (% zone 3600) 60)))))
4640 (defun message-make-message-id ()
4641 "Make a unique Message-ID."
4642 (concat "<" (message-unique-id)
4643 (let ((psubject (save-excursion (message-fetch-field "subject")))
4645 (save-excursion (message-fetch-field "supersedes"))))
4647 (and message-reply-headers
4648 (mail-header-references message-reply-headers)
4649 (mail-header-subject message-reply-headers)
4652 (message-strip-subject-re
4653 (mail-header-subject message-reply-headers))
4654 (message-strip-subject-re psubject))))
4656 (string-match "_-_@" psupersedes)))
4658 "@" (message-make-fqdn) ">"))
4660 (defvar message-unique-id-char nil)
4662 ;; If you ever change this function, make sure the new version
4663 ;; cannot generate IDs that the old version could.
4664 ;; You might for example insert a "." somewhere (not next to another dot
4665 ;; or string boundary), or modify the "fsf" string.
4666 (defun message-unique-id ()
4667 ;; Don't use microseconds from (current-time), they may be unsupported.
4668 ;; Instead we use this randomly inited counter.
4669 (setq message-unique-id-char
4670 (% (1+ (or message-unique-id-char (logand (random t) (1- (lsh 1 20)))))
4671 ;; (current-time) returns 16-bit ints,
4672 ;; and 2^16*25 just fits into 4 digits i base 36.
4674 (let ((tm (current-time)))
4676 (if (or (memq system-type '(ms-dos emx vax-vms))
4677 ;; message-number-base36 doesn't handle bigints.
4678 (floatp (user-uid)))
4679 (let ((user (downcase (user-login-name))))
4680 (while (string-match "[^a-z0-9_]" user)
4681 (aset user (match-beginning 0) ?_))
4683 (message-number-base36 (user-uid) -1))
4684 (message-number-base36 (+ (car tm)
4685 (lsh (% message-unique-id-char 25) 16)) 4)
4686 (message-number-base36 (+ (nth 1 tm)
4687 (lsh (/ message-unique-id-char 25) 16)) 4)
4688 ;; Append a given name, because while the generated ID is unique
4689 ;; to this newsreader, other newsreaders might otherwise generate
4690 ;; the same ID via another algorithm.
4693 (defun message-number-base36 (num len)
4698 (concat (message-number-base36 (/ num 36) (1- len))
4699 (char-to-string (aref "zyxwvutsrqponmlkjihgfedcba9876543210"
4702 (defun message-make-organization ()
4703 "Make an Organization header."
4704 (let* ((organization
4705 (when message-user-organization
4706 (if (functionp message-user-organization)
4707 (funcall message-user-organization)
4708 message-user-organization))))
4710 (mm-enable-multibyte)
4711 (cond ((stringp organization)
4712 (insert organization))
4713 ((and (eq t organization)
4714 message-user-organization-file
4715 (file-exists-p message-user-organization-file))
4716 (insert-file-contents message-user-organization-file)))
4717 (goto-char (point-min))
4718 (while (re-search-forward "[\t\n]+" nil t)
4719 (replace-match "" t t))
4720 (unless (zerop (buffer-size))
4723 (defun message-make-lines ()
4724 "Count the number of lines and return numeric string."
4729 (int-to-string (count-lines (point) (point-max))))))
4731 (defun message-make-references ()
4732 "Return the References header for this message."
4733 (when message-reply-headers
4734 (let ((message-id (mail-header-message-id message-reply-headers))
4735 (references (mail-header-references message-reply-headers))
4737 (if (or references message-id)
4738 (concat (or references "") (and references " ")
4742 (defun message-make-in-reply-to ()
4743 "Return the In-Reply-To header for this message."
4744 (when message-reply-headers
4745 (let ((from (mail-header-from message-reply-headers))
4746 (date (mail-header-date message-reply-headers))
4747 (msg-id (mail-header-message-id message-reply-headers)))
4749 (let ((name (mail-extract-address-components from)))
4750 (concat msg-id (if msg-id " (")
4754 (if (or (not date) (string= date ""))
4755 "(unknown date)" date)
4756 "\"" (if msg-id ")")))))))
4758 (defun message-make-distribution ()
4759 "Make a Distribution header."
4760 (let ((orig-distribution (message-fetch-reply-field "distribution")))
4761 (cond ((functionp message-distribution-function)
4762 (funcall message-distribution-function))
4763 (t orig-distribution))))
4765 (defun message-make-expires ()
4766 "Return an Expires header based on `message-expires'."
4767 (let ((current (current-time))
4768 (future (* 1.0 message-expires 60 60 24)))
4769 ;; Add the future to current.
4770 (setcar current (+ (car current) (round (/ future (expt 2 16)))))
4771 (setcar (cdr current) (+ (nth 1 current) (% (round future) (expt 2 16))))
4772 (message-make-date current)))
4774 (defun message-make-path ()
4776 (let ((login-name (user-login-name)))
4777 (cond ((null message-user-path)
4778 (concat (system-name) "!" login-name))
4779 ((stringp message-user-path)
4780 ;; Support GENERICPATH. Suggested by vixie@decwrl.dec.com.
4781 (concat message-user-path "!" login-name))
4784 (defun message-make-from ()
4785 "Make a From header."
4786 (let* ((style message-from-style)
4787 (login (message-make-address))
4789 (or (and (boundp 'user-full-name)
4792 (when (string= fullname "&")
4793 (setq fullname (user-login-name)))
4795 (mm-enable-multibyte)
4798 (equal fullname ""))
4800 ((or (eq style 'angles)
4801 (and (not (eq style 'parens))
4802 ;; Use angles if no quoting is needed, or if parens would
4803 ;; need quoting too.
4804 (or (not (string-match "[^- !#-'*+/-9=?A-Z^-~]" fullname))
4805 (let ((tmp (concat fullname nil)))
4806 (while (string-match "([^()]*)" tmp)
4807 (aset tmp (match-beginning 0) ?-)
4808 (aset tmp (1- (match-end 0)) ?-))
4809 (string-match "[\\()]" tmp)))))
4811 (goto-char (point-min))
4812 ;; Look for a character that cannot appear unquoted
4813 ;; according to RFC 822.
4814 (when (re-search-forward "[^- !#-'*+/-9=?A-Z^-~]" nil 1)
4815 ;; Quote fullname, escaping specials.
4816 (goto-char (point-min))
4818 (while (re-search-forward "[\"\\]" nil 1)
4819 (replace-match "\\\\\\&" t))
4821 (insert " <" login ">"))
4822 (t ; 'parens or default
4824 (let ((fullname-start (point)))
4826 (goto-char fullname-start)
4827 ;; RFC 822 says \ and nonmatching parentheses
4828 ;; must be escaped in comments.
4829 ;; Escape every instance of ()\ ...
4830 (while (re-search-forward "[()\\]" nil 1)
4831 (replace-match "\\\\\\&" t))
4832 ;; ... then undo escaping of matching parentheses,
4833 ;; including matching nested parentheses.
4834 (goto-char fullname-start)
4835 (while (re-search-forward
4836 "\\(\\=\\|[^\\]\\(\\\\\\\\\\)*\\)\\\\(\\(\\([^\\]\\|\\\\\\\\\\)*\\)\\\\)"
4838 (replace-match "\\1(\\3)" t)
4839 (goto-char fullname-start)))
4843 (defun message-make-sender ()
4844 "Return the \"real\" user address.
4845 This function tries to ignore all user modifications, and
4846 give as trustworthy answer as possible."
4847 (concat (user-login-name) "@" (system-name)))
4849 (defun message-make-address ()
4850 "Make the address of the user."
4851 (or (message-user-mail-address)
4852 (concat (user-login-name) "@" (message-make-domain))))
4854 (defun message-user-mail-address ()
4855 "Return the pertinent part of `user-mail-address'."
4856 (when (and user-mail-address
4857 (string-match "@.*\\." user-mail-address))
4858 (if (string-match " " user-mail-address)
4859 (nth 1 (mail-extract-address-components user-mail-address))
4860 user-mail-address)))
4862 (defun message-sendmail-envelope-from ()
4863 "Return the envelope from."
4864 (cond ((eq message-sendmail-envelope-from 'header)
4865 (nth 1 (mail-extract-address-components
4866 (message-fetch-field "from"))))
4867 ((stringp message-sendmail-envelope-from)
4868 message-sendmail-envelope-from)
4870 (message-make-address))))
4872 (defun message-make-fqdn ()
4873 "Return user's fully qualified domain name."
4874 (let* ((system-name (system-name))
4875 (user-mail (message-user-mail-address))
4878 (string-match "@\\(.*\\)\\'" user-mail))
4879 (match-string 1 user-mail)))
4880 (case-fold-search t))
4882 ((and message-user-fqdn
4883 (stringp message-user-fqdn)
4884 (string-match message-valid-fqdn-regexp message-user-fqdn)
4885 (not (string-match message-bogus-system-names message-user-fqdn)))
4887 ;; `message-user-fqdn' seems to be valid
4888 ((and (string-match message-valid-fqdn-regexp system-name)
4889 (not (string-match message-bogus-system-names system-name)))
4890 ;; `system-name' returned the right result.
4892 ;; Try `mail-host-address'.
4893 ((and (boundp 'mail-host-address)
4894 (stringp mail-host-address)
4895 (string-match message-valid-fqdn-regexp mail-host-address)
4896 (not (string-match message-bogus-system-names mail-host-address)))
4898 ;; We try `user-mail-address' as a backup.
4900 (stringp user-domain)
4901 (string-match message-valid-fqdn-regexp user-domain)
4902 (not (string-match message-bogus-system-names user-domain)))
4904 ;; Default to this bogus thing.
4907 ".i-did-not-set--mail-host-address--so-tickle-me")))))
4909 (defun message-make-host-name ()
4910 "Return the name of the host."
4911 (let ((fqdn (message-make-fqdn)))
4912 (string-match "^[^.]+\\." fqdn)
4913 (substring fqdn 0 (1- (match-end 0)))))
4915 (defun message-make-domain ()
4916 "Return the domain name."
4917 (or mail-host-address
4918 (message-make-fqdn)))
4920 (defun message-to-list-only ()
4921 "Send a message to the list only.
4922 Remove all addresses but the list address from To and Cc headers."
4924 (let ((listaddr (message-make-mail-followup-to t)))
4927 (message-remove-header "to")
4928 (message-remove-header "cc")
4929 (message-position-on-field "To" "X-Draft-From")
4930 (insert listaddr)))))
4932 (defun message-make-mail-followup-to (&optional only-show-subscribed)
4933 "Return the Mail-Followup-To header.
4934 If passed the optional argument ONLY-SHOW-SUBSCRIBED only return the
4935 subscribed address (and not the additional To and Cc header contents)."
4936 (let* ((case-fold-search t)
4937 (to (message-fetch-field "To"))
4938 (cc (message-fetch-field "cc"))
4939 (msg-recipients (concat to (and to cc ", ") cc))
4941 (mapcar 'mail-strip-quoted-names
4942 (message-tokenize-header msg-recipients)))
4944 (if message-subscribed-address-file
4945 (let (begin end item re)
4948 (insert-file-contents message-subscribed-address-file)
4950 (setq begin (point))
4953 (if (bolp) (setq end (1- end)))
4954 (setq item (regexp-quote (buffer-substring begin end)))
4955 (if re (setq re (concat re "\\|" item))
4956 (setq re (concat "\\`\\(" item))))
4957 (and re (list (concat re "\\)\\'"))))))))
4958 (mft-regexps (apply 'append message-subscribed-regexps
4959 (mapcar 'regexp-quote
4960 message-subscribed-addresses)
4963 message-subscribed-address-functions))))
4965 (let ((subscribed-lists nil)
4967 (loop for recipient in recipients
4968 when (loop for regexp in mft-regexps
4969 when (string-match regexp recipient) return t)
4972 (if only-show-subscribed
4974 msg-recipients))))))
4976 (defun message-idna-to-ascii-rhs-1 (header)
4977 "Interactively potentially IDNA encode domain names in HEADER."
4978 (let ((field (message-fetch-field header))
4982 (mm-delete-duplicates
4983 (mapcar (lambda (rhs) (or (cadr (split-string rhs "@")) ""))
4986 'car (mail-header-parse-addresses field))))))
4987 (setq ace (downcase (idna-to-ascii rhs)))
4988 (when (and (not (equal rhs ace))
4989 (or (not (eq message-use-idna 'ask))
4990 (y-or-n-p (format "Replace %s with %s in %s:? "
4992 (goto-char (point-min))
4993 (while (re-search-forward (concat "^" header ":") nil t)
4994 (message-narrow-to-field)
4995 (while (search-forward (concat "@" rhs) nil t)
4996 (replace-match (concat "@" ace) t t))
4997 (goto-char (point-max))
5000 (defun message-idna-to-ascii-rhs ()
5001 "Possibly IDNA encode non-ASCII domain names in From:, To: and Cc: headers.
5002 See `message-idna-encode'."
5004 (when message-use-idna
5007 (message-narrow-to-head)
5008 (message-idna-to-ascii-rhs-1 "From")
5009 (message-idna-to-ascii-rhs-1 "To")
5010 (message-idna-to-ascii-rhs-1 "Reply-To")
5011 (message-idna-to-ascii-rhs-1 "Mail-Reply-To")
5012 (message-idna-to-ascii-rhs-1 "Mail-Followup-To")
5013 (message-idna-to-ascii-rhs-1 "Cc")))))
5015 (defun message-generate-headers (headers)
5016 "Prepare article HEADERS.
5017 Headers already prepared in the buffer are not modified."
5018 (setq headers (append headers message-required-headers))
5020 (message-narrow-to-headers)
5021 (let* ((Date (message-make-date))
5022 (Message-ID (message-make-message-id))
5023 (Organization (message-make-organization))
5024 (From (message-make-from))
5025 (Path (message-make-path))
5028 (In-Reply-To (message-make-in-reply-to))
5029 (References (message-make-references))
5031 (Distribution (message-make-distribution))
5032 (Lines (message-make-lines))
5033 (User-Agent message-newsreader)
5034 (Expires (message-make-expires))
5035 (case-fold-search t)
5037 header value elem header-string)
5038 ;; First we remove any old generated headers.
5039 (let ((headers message-deletable-headers))
5040 (unless (buffer-modified-p)
5041 (setq headers (delq 'Message-ID (copy-sequence headers))))
5043 (goto-char (point-min))
5044 (and (re-search-forward
5045 (concat "^" (symbol-name (car headers)) ": *") nil t)
5046 (get-text-property (1+ (match-beginning 0)) 'message-deletable)
5047 (message-delete-line))
5049 ;; Go through all the required headers and see if they are in the
5050 ;; articles already. If they are not, or are empty, they are
5051 ;; inserted automatically - except for Subject, Newsgroups and
5054 (goto-char (point-min))
5055 (setq elem (pop headers))
5057 (if (eq (car elem) 'optional)
5058 (setq header (cdr elem)
5060 (setq header (car elem)))
5062 (setq header-string (if (stringp header)
5064 (symbol-name header)))
5065 (when (or (not (re-search-forward
5067 (regexp-quote (downcase header-string))
5071 ;; The header was found. We insert a space after the
5072 ;; colon, if there is none.
5073 (if (/= (char-after) ? ) (insert " ") (forward-char 1))
5074 ;; Find out whether the header is empty.
5075 (looking-at "[ \t]*\n[^ \t]")))
5076 ;; So we find out what value we should insert.
5080 (eq (car elem) 'optional)
5081 (not (member header-string message-inserted-headers)))
5082 ;; This is an optional header. If the cdr of this
5083 ;; is something that is nil, then we do not insert
5085 (setq header (cdr elem))
5086 (or (and (functionp (cdr elem))
5087 (funcall (cdr elem)))
5088 (and (boundp (cdr elem))
5089 (symbol-value (cdr elem)))))
5091 ;; The element is a cons. Either the cdr is a
5092 ;; string to be inserted verbatim, or it is a
5093 ;; function, and we insert the value returned from
5095 (or (and (stringp (cdr elem))
5097 (and (functionp (cdr elem))
5098 (funcall (cdr elem)))))
5099 ((and (boundp header)
5100 (symbol-value header))
5101 ;; The element is a symbol. We insert the value
5102 ;; of this symbol, if any.
5103 (symbol-value header))
5104 ((not (message-check-element
5105 (intern (downcase (symbol-name header)))))
5106 ;; We couldn't generate a value for this header,
5107 ;; so we just ask the user.
5108 (read-from-minibuffer
5109 (format "Empty header for %s; enter value: " header)))))
5110 ;; Finally insert the header.
5112 (not (equal value "")))
5116 ;; This header didn't exist, so we insert it.
5117 (goto-char (point-max))
5119 (cdr (assq header message-header-format-alist))))
5121 (funcall formatter header value)
5122 (insert header-string ": " value))
5123 ;; We check whether the value was ended by a
5124 ;; newline. If now, we insert one.
5128 ;; The value of this header was empty, so we clear
5129 ;; totally and insert the new value.
5130 (delete-region (point) (gnus-point-at-eol))
5131 ;; If the header is optional, and the header was
5132 ;; empty, we con't insert it anyway.
5134 (push header-string message-inserted-headers)
5136 ;; Add the deletable property to the headers that require it.
5137 (and (memq header message-deletable-headers)
5138 (progn (beginning-of-line) (looking-at "[^:]+: "))
5139 (add-text-properties
5140 (point) (match-end 0)
5141 '(message-deletable t face italic) (current-buffer)))))))
5142 ;; Insert new Sender if the From is strange.
5143 (let ((from (message-fetch-field "from"))
5144 (sender (message-fetch-field "sender"))
5145 (secure-sender (message-make-sender)))
5147 (not (message-check-element 'sender))
5150 (cadr (mail-extract-address-components from)))
5151 (downcase secure-sender)))
5156 (cadr (mail-extract-address-components sender)))
5157 (downcase secure-sender)))))
5158 (goto-char (point-min))
5159 ;; Rename any old Sender headers to Original-Sender.
5160 (when (re-search-forward "^\\(Original-\\)*Sender:" nil t)
5162 (insert "Original-")
5163 (beginning-of-line))
5164 (when (or (message-news-p)
5165 (string-match "@.+\\.." secure-sender))
5166 (insert "Sender: " secure-sender "\n"))))
5168 (message-idna-to-ascii-rhs))))
5170 (defun message-insert-courtesy-copy ()
5171 "Insert a courtesy message in mail copies of combined messages."
5175 (message-narrow-to-headers)
5176 (when (setq newsgroups (message-fetch-field "newsgroups"))
5177 (goto-char (point-max))
5178 (insert "Posted-To: " newsgroups "\n")))
5180 (when message-courtesy-message
5182 ((string-match "%s" message-courtesy-message)
5183 (insert (format message-courtesy-message newsgroups)))
5185 (insert message-courtesy-message)))))))
5188 ;;; Setting up a message buffer
5191 (defun message-fill-address (header value)
5193 (narrow-to-region (point) (point))
5194 (insert (capitalize (symbol-name header))
5196 (if (consp value) (car value) value)
5198 (narrow-to-region (point-min) (1- (point-max)))
5200 (goto-char (point-min))
5202 (skip-chars-forward "^,\"" (point-max))
5203 (if (or (eq (char-after) ?,)
5206 (if (and (> (current-column) 78)
5212 (setq last (1+ (point))))
5213 (setq last (1+ (point)))))
5214 (setq quoted (not quoted)))
5217 (goto-char (point-max))
5221 (defun message-split-line ()
5222 "Split current line, moving portion beyond point vertically down.
5223 If the current line has `message-yank-prefix', insert it on the new line."
5226 (split-line message-yank-prefix) ;; Emacs 22.1+ supports arg.
5230 (defun message-fill-header (header value)
5231 (let ((begin (point))
5234 (insert (capitalize (symbol-name header))
5236 (if (consp value) (car value) value)
5239 (narrow-to-region begin (point))
5240 (fill-region-as-paragraph begin (point))
5241 ;; Tapdance around looong Message-IDs.
5243 (when (looking-at "[ \t]*$")
5244 (message-delete-line))
5246 (re-search-forward ":" nil t)
5247 (when (looking-at "\n[ \t]+")
5248 (replace-match " " t t))
5249 (goto-char (point-max)))))
5251 (defun message-shorten-1 (list cut surplus)
5252 "Cut SURPLUS elements out of LIST, beginning with CUTth one."
5253 (setcdr (nthcdr (- cut 2) list)
5254 (nthcdr (+ (- cut 2) surplus 1) list)))
5256 (defun message-shorten-references (header references)
5257 "Trim REFERENCES to be 21 Message-ID long or less, and fold them.
5258 If folding is disallowed, also check that the REFERENCES are less
5259 than 988 characters long, and if they are not, trim them until they are."
5266 (goto-char (point-min))
5267 ;; Cons a list of valid references.
5268 (while (re-search-forward "<[^>]+>" nil t)
5269 (push (match-string 0) refs))
5270 (setq refs (nreverse refs)
5271 count (length refs)))
5273 ;; If the list has more than MAXCOUNT elements, trim it by
5274 ;; removing the CUTth element and the required number of
5275 ;; elements that follow.
5276 (when (> count maxcount)
5277 (let ((surplus (- count maxcount)))
5278 (message-shorten-1 refs cut surplus)
5279 (decf count surplus)))
5281 ;; If folding is disallowed, make sure the total length (including
5282 ;; the spaces between) will be less than MAXSIZE characters.
5284 ;; Only disallow folding for News messages. At this point the headers
5285 ;; have not been generated, thus we use message-this-is-news directly.
5286 (when (and message-this-is-news message-cater-to-broken-inn)
5288 (totalsize (+ (apply #'+ (mapcar #'length refs))
5291 (ptr (nthcdr (1- cut) refs)))
5292 ;; Decide how many elements to cut off...
5293 (while (> totalsize maxsize)
5294 (decf totalsize (1+ (length (car ptr))))
5296 (setq ptr (cdr ptr)))
5299 (message-shorten-1 refs cut surplus))))
5301 ;; Finally, collect the references back into a string and insert
5302 ;; it into the buffer.
5303 (let ((refstring (mapconcat #'identity refs " ")))
5304 (if (and message-this-is-news message-cater-to-broken-inn)
5305 (insert (capitalize (symbol-name header)) ": "
5307 (message-fill-header header refstring)))))
5309 (defun message-position-point ()
5310 "Move point to where the user probably wants to find it."
5311 (message-narrow-to-headers)
5313 ((re-search-forward "^[^:]+:[ \t]*$" nil t)
5314 (search-backward ":" )
5317 (if (eq (char-after) ? )
5321 (goto-char (point-max))
5324 (unless (looking-at "$")
5328 (defcustom message-beginning-of-line t
5329 "Whether \\<message-mode-map>\\[message-beginning-of-line]\
5330 goes to beginning of header values."
5332 :group 'message-buffers
5333 :link '(custom-manual "(message)Movement")
5336 (defun message-beginning-of-line (&optional n)
5337 "Move point to beginning of header value or to beginning of line.
5338 The prefix argument N is passed directly to `beginning-of-line'.
5340 This command is identical to `beginning-of-line' if point is
5341 outside the message header or if the option `message-beginning-of-line'
5344 If point is in the message header and on a (non-continued) header
5345 line, move point to the beginning of the header value or the beginning of line,
5346 whichever is closer. If point is already at beginning of line, move point to
5347 beginning of header value. Therefore, repeated calls will toggle point
5348 between beginning of field and beginning of line."
5350 (let ((zrs 'zmacs-region-stays))
5351 (when (and (interactive-p) (boundp zrs))
5353 (if (and message-beginning-of-line
5354 (message-point-in-header-p))
5355 (let* ((here (point))
5356 (bol (progn (beginning-of-line n) (point)))
5357 (eol (gnus-point-at-eol))
5358 (eoh (re-search-forward ": *" eol t)))
5360 (if (and eoh (or (< eoh here) (= bol here)))
5362 (beginning-of-line n)))
5364 (defun message-buffer-name (type &optional to group)
5365 "Return a new (unique) buffer name based on TYPE and TO."
5367 ;; Generate a new buffer name The Message Way.
5368 ((eq message-generate-new-buffers 'unique)
5369 (generate-new-buffer-name
5373 (or (car (mail-extract-address-components to))
5376 (if (and group (not (string= group ""))) (concat " on " group) "")
5378 ;; Check whether `message-generate-new-buffers' is a function,
5379 ;; and if so, call it.
5380 ((functionp message-generate-new-buffers)
5381 (funcall message-generate-new-buffers type to group))
5382 ((eq message-generate-new-buffers 'unsent)
5383 (generate-new-buffer-name
5384 (concat "*unsent " type
5387 (or (car (mail-extract-address-components to))
5390 (if (and group (not (string= group ""))) (concat " on " group) "")
5392 ;; Use standard name.
5394 (format "*%s message*" type))))
5396 (defun message-pop-to-buffer (name)
5397 "Pop to buffer NAME, and warn if it already exists and is modified."
5398 (let ((buffer (get-buffer name)))
5400 (buffer-name buffer))
5402 (set-buffer (pop-to-buffer buffer))
5403 (when (and (buffer-modified-p)
5405 "Message already being composed; erase? ")))
5406 (error "Message being composed")))
5407 (set-buffer (pop-to-buffer name)))
5411 (defun message-do-send-housekeeping ()
5412 "Kill old message buffers."
5413 ;; We might have sent this buffer already. Delete it from the
5415 (setq message-buffer-list (delq (current-buffer) message-buffer-list))
5416 (while (and message-max-buffers
5418 (>= (length message-buffer-list) message-max-buffers))
5419 ;; Kill the oldest buffer -- unless it has been changed.
5420 (let ((buffer (pop message-buffer-list)))
5421 (when (and (buffer-name buffer)
5422 (not (buffer-modified-p buffer)))
5423 (kill-buffer buffer))))
5424 ;; Rename the buffer.
5425 (if message-send-rename-function
5426 (funcall message-send-rename-function)
5427 ;; Note: mail-abbrevs of XEmacs renames buffer name behind Gnus.
5429 "\\`\\*\\(sent \\|unsent \\)?\\(.+\\)\\*[^\\*]*\\|\\`mail to "
5431 (let ((name (match-string 2 (buffer-name)))
5433 (if (not (or (null name)
5434 (string-equal name "mail")
5435 (string-equal name "posting")))
5436 (setq name (concat "*sent " name "*"))
5437 (message-narrow-to-headers)
5438 (setq to (message-fetch-field "to"))
5439 (setq group (message-fetch-field "newsgroups"))
5443 (to (concat "*sent mail to "
5444 (or (car (mail-extract-address-components to))
5446 ((and group (not (string= group "")))
5447 (concat "*sent posting on " group "*"))
5448 (t "*sent mail*"))))
5449 (unless (string-equal name (buffer-name))
5450 (rename-buffer name t)))))
5451 ;; Push the current buffer onto the list.
5452 (when message-max-buffers
5453 (setq message-buffer-list
5454 (nconc message-buffer-list (list (current-buffer))))))
5456 (defun message-mail-user-agent ()
5458 ((not message-mail-user-agent) nil)
5459 ((eq message-mail-user-agent t) mail-user-agent)
5460 (t message-mail-user-agent))))
5461 (if (memq mua '(message-user-agent gnus-user-agent))
5465 (defun message-setup (headers &optional replybuffer actions switch-function)
5466 (let ((mua (message-mail-user-agent))
5467 subject to field yank-action)
5468 (if (not (and message-this-is-mail mua))
5469 (message-setup-1 headers replybuffer actions)
5471 (setq yank-action (list 'insert-buffer replybuffer)))
5472 (setq headers (copy-sequence headers))
5473 (setq field (assq 'Subject headers))
5475 (setq subject (cdr field))
5476 (setq headers (delq field headers)))
5477 (setq field (assq 'To headers))
5479 (setq to (cdr field))
5480 (setq headers (delq field headers)))
5481 (let ((mail-user-agent mua))
5482 (compose-mail to subject
5483 (mapcar (lambda (item)
5485 (format "%s" (car item))
5488 nil switch-function yank-action actions)))))
5490 (defun message-headers-to-generate (headers included-headers excluded-headers)
5491 "Return a list that includes all headers from HEADERS.
5492 If INCLUDED-HEADERS is a list, just include those headers. If if is
5493 t, include all headers. In any case, headers from EXCLUDED-HEADERS
5497 (dolist (header headers)
5498 (setq header-name (cond
5499 ((and (consp header)
5500 (eq (car header) 'optional))
5501 ;; On the form (optional . Header)
5504 ;; On the form (Header . function)
5509 (when (and (not (memq header-name excluded-headers))
5510 (or (eq included-headers t)
5511 (memq header-name included-headers)))
5512 (push header result)))
5515 (defun message-setup-1 (headers &optional replybuffer actions)
5516 (dolist (action actions)
5518 (add-to-list 'message-send-actions
5519 `(apply ',(car action) ',(cdr action)))))
5520 (setq message-reply-buffer replybuffer)
5521 (goto-char (point-min))
5522 ;; Insert all the headers.
5525 (alist message-header-format-alist))
5527 (unless (assq (caar h) message-header-format-alist)
5528 (push (list (caar h)) alist))
5532 (delete-region (point) (progn (forward-line -1) (point)))
5533 (when message-default-headers
5534 (insert message-default-headers)
5535 (or (bolp) (insert ?\n)))
5539 (insert mail-header-separator "\n")
5543 (when (message-news-p)
5544 (when message-default-news-headers
5545 (insert message-default-news-headers)
5546 (or (bolp) (insert ?\n)))
5547 (when message-generate-headers-first
5548 (message-generate-headers
5549 (message-headers-to-generate
5550 (append message-required-news-headers
5551 message-required-headers)
5552 message-generate-headers-first
5553 '(Lines Subject)))))
5554 (when (message-mail-p)
5555 (when message-default-mail-headers
5556 (insert message-default-mail-headers)
5557 (or (bolp) (insert ?\n)))
5558 (when message-generate-headers-first
5559 (message-generate-headers
5560 (message-headers-to-generate
5561 (append message-required-mail-headers
5562 message-required-headers)
5563 message-generate-headers-first
5564 '(Lines Subject)))))
5565 (run-hooks 'message-signature-setup-hook)
5566 (message-insert-signature)
5568 (message-narrow-to-headers)
5569 (run-hooks 'message-header-setup-hook))
5570 (set-buffer-modified-p nil)
5571 (setq buffer-undo-list nil)
5572 (run-hooks 'message-setup-hook)
5573 ;; Do this last to give it precedence over posting styles, etc.
5574 (when (message-mail-p)
5576 (message-narrow-to-headers)
5577 (if message-alternative-emails
5578 (message-use-alternative-email-as-from))))
5579 (message-position-point)
5582 (defun message-set-auto-save-file-name ()
5583 "Associate the message buffer with a file in the drafts directory."
5584 (when message-auto-save-directory
5585 (unless (file-directory-p
5586 (directory-file-name message-auto-save-directory))
5587 (make-directory message-auto-save-directory t))
5589 (setq message-draft-article
5590 (nndraft-request-associate-buffer "drafts"))
5591 (setq buffer-file-name (expand-file-name
5592 (if (memq system-type
5593 '(ms-dos ms-windows windows-nt
5594 cygwin cygwin32 win32 w32
5598 message-auto-save-directory))
5599 (setq buffer-auto-save-file-name (make-auto-save-file-name)))
5600 (clear-visited-file-modtime)
5601 (setq buffer-file-coding-system message-draft-coding-system)))
5603 (defun message-disassociate-draft ()
5604 "Disassociate the message buffer from the drafts directory."
5605 (when message-draft-article
5606 (nndraft-request-expire-articles
5607 (list message-draft-article) "drafts" nil t)))
5609 (defun message-insert-headers ()
5610 "Generate the headers for the article."
5614 (message-narrow-to-headers)
5615 (when (message-news-p)
5616 (message-generate-headers
5619 (copy-sequence message-required-news-headers)))))
5620 (when (message-mail-p)
5621 (message-generate-headers
5624 (copy-sequence message-required-mail-headers))))))))
5629 ;;; Commands for interfacing with message
5633 (defun message-mail (&optional to subject
5634 other-headers continue switch-function
5635 yank-action send-actions)
5636 "Start editing a mail message to be sent.
5637 OTHER-HEADERS is an alist of header/value pairs."
5639 (let ((message-this-is-mail t) replybuffer)
5640 (unless (message-mail-user-agent)
5641 (message-pop-to-buffer (message-buffer-name "mail" to)))
5642 ;; FIXME: message-mail should do something if YANK-ACTION is not
5644 (and (consp yank-action) (eq (car yank-action) 'insert-buffer)
5645 (setq replybuffer (nth 1 yank-action)))
5648 `((To . ,(or to "")) (Subject . ,(or subject "")))
5649 (when other-headers other-headers))
5650 replybuffer send-actions)
5651 ;; FIXME: Should return nil if failure.
5655 (defun message-news (&optional newsgroups subject)
5656 "Start editing a news article to be sent."
5658 (let ((message-this-is-news t))
5659 (message-pop-to-buffer (message-buffer-name "posting" nil newsgroups))
5660 (message-setup `((Newsgroups . ,(or newsgroups ""))
5661 (Subject . ,(or subject ""))))))
5663 (defun message-get-reply-headers (wide &optional to-address address-headers)
5664 (let (follow-to mct never-mct to cc author mft recipients)
5665 ;; Find all relevant headers we need.
5667 (message-narrow-to-headers-or-head)
5668 ;; Gmane renames "To". Look at "Original-To", too, if it is present in
5669 ;; message-header-synonyms.
5670 (setq to (or (message-fetch-field "to")
5671 (and (loop for synonym in message-header-synonyms
5672 when (memq 'Original-To synonym)
5674 (message-fetch-field "original-to")))
5675 cc (message-fetch-field "cc")
5676 mct (message-fetch-field "mail-copies-to")
5677 author (or (message-fetch-field "mail-reply-to")
5678 (message-fetch-field "reply-to")
5679 (message-fetch-field "from")
5681 mft (and message-use-mail-followup-to
5682 (message-fetch-field "mail-followup-to"))))
5684 ;; Handle special values of Mail-Copies-To.
5686 (cond ((or (equal (downcase mct) "never")
5687 (equal (downcase mct) "nobody"))
5690 ((or (equal (downcase mct) "always")
5691 (equal (downcase mct) "poster"))
5692 (setq mct author))))
5695 ;; Build (textual) list of new recipient addresses.
5698 (setq recipients (concat ", " author)))
5700 (dolist (header address-headers)
5701 (let ((value (message-fetch-field header)))
5703 (setq recipients (concat recipients ", " value))))))
5705 (string-match "[^ \t,]" mft)
5706 (or (not (eq message-use-mail-followup-to 'ask))
5707 (message-y-or-n-p "Obey Mail-Followup-To? " t "\
5708 You should normally obey the Mail-Followup-To: header. In this
5709 article, it has the value of
5713 which directs your response to " (if (string-match "," mft)
5714 "the specified addresses"
5715 "that address only") ".
5717 Most commonly, Mail-Followup-To is used by a mailing list poster to
5718 express that responses should be sent to just the list, and not the
5721 If a message is posted to several mailing lists, Mail-Followup-To may
5722 also be used to direct the following discussion to one list only,
5723 because discussions that are spread over several lists tend to be
5724 fragmented and very difficult to follow.
5726 Also, some source/announcement lists are not intended for discussion;
5727 responses here are directed to other addresses.
5729 You may customize the variable `message-use-mail-followup-to', if you
5730 want to get rid of this query permanently.")))
5731 (setq recipients (concat ", " mft)))
5733 (setq recipients (concat ", " to-address))
5734 ;; If the author explicitly asked for a copy, we don't deny it to them.
5735 (if mct (setq recipients (concat recipients ", " mct))))
5737 (setq recipients (if never-mct "" (concat ", " author)))
5738 (if to (setq recipients (concat recipients ", " to)))
5739 (if cc (setq recipients (concat recipients ", " cc)))
5740 (if mct (setq recipients (concat recipients ", " mct)))))
5741 (if (>= (length recipients) 2)
5742 ;; Strip the leading ", ".
5743 (setq recipients (substring recipients 2)))
5744 ;; Squeeze whitespace.
5745 (while (string-match "[ \t][ \t]+" recipients)
5746 (setq recipients (replace-match " " t t recipients)))
5747 ;; Remove addresses that match `rmail-dont-reply-to-names'.
5748 (let ((rmail-dont-reply-to-names message-dont-reply-to-names))
5749 (setq recipients (rmail-dont-reply-to recipients)))
5750 ;; Perhaps "Mail-Copies-To: never" removed the only address?
5751 (if (string-equal recipients "")
5752 (setq recipients author))
5753 ;; Convert string to a list of (("foo@bar" . "Name <Foo@BAR>") ...).
5757 (cons (downcase (mail-strip-quoted-names addr)) addr))
5758 (message-tokenize-header recipients)))
5759 ;; Remove first duplicates. (Why not all duplicates? Is this a bug?)
5760 (let ((s recipients))
5762 (setq recipients (delq (assoc (car (pop s)) s) recipients))))
5764 ;; Remove hierarchical lists that are contained within each other,
5765 ;; if message-hierarchical-addresses is defined.
5766 (when message-hierarchical-addresses
5767 (let ((plain-addrs (mapcar 'car recipients))
5770 (setq subaddrs (assoc (car plain-addrs)
5771 message-hierarchical-addresses)
5772 plain-addrs (cdr plain-addrs))
5774 (setq subaddrs (cdr subaddrs))
5776 (setq recip (assoc (car subaddrs) recipients)
5777 subaddrs (cdr subaddrs))
5779 (setq recipients (delq recip recipients))))))))
5781 ;; Build the header alist. Allow the user to be asked whether
5782 ;; or not to reply to all recipients in a wide reply.
5783 (setq follow-to (list (cons 'To (cdr (pop recipients)))))
5784 (when (and recipients
5785 (or (not message-wide-reply-confirm-recipients)
5786 (y-or-n-p "Reply to all recipients? ")))
5787 (setq recipients (mapconcat
5788 (lambda (addr) (cdr addr)) recipients ", "))
5789 (if (string-match "^ +" recipients)
5790 (setq recipients (substring recipients (match-end 0))))
5791 (push (cons 'Cc recipients) follow-to)))
5795 (defun message-reply (&optional to-address wide)
5796 "Start editing a reply to the article in the current buffer."
5798 (require 'gnus-sum) ; for gnus-list-identifiers
5799 (let ((cur (current-buffer))
5800 from subject date reply-to to cc
5801 references message-id follow-to
5802 (inhibit-point-motion-hooks t)
5803 (message-this-is-mail t)
5806 (message-narrow-to-head-1)
5807 ;; Allow customizations to have their say.
5809 ;; This is a regular reply.
5810 (when (functionp message-reply-to-function)
5812 (setq follow-to (funcall message-reply-to-function))))
5813 ;; This is a followup.
5814 (when (functionp message-wide-reply-to-function)
5817 (funcall message-wide-reply-to-function)))))
5818 (setq message-id (message-fetch-field "message-id" t)
5819 references (message-fetch-field "references")
5820 date (message-fetch-field "date")
5821 from (message-fetch-field "from")
5822 subject (or (message-fetch-field "subject") "none"))
5823 (when gnus-list-identifiers
5824 (setq subject (message-strip-list-identifiers subject)))
5825 (setq subject (concat "Re: " (message-strip-subject-re subject)))
5826 (when message-subject-trailing-was-query
5827 (setq subject (message-strip-subject-trailing-was subject)))
5829 (when (and (setq gnus-warning (message-fetch-field "gnus-warning"))
5830 (string-match "<[^>]+>" gnus-warning))
5831 (setq message-id (match-string 0 gnus-warning)))
5834 (setq follow-to (message-get-reply-headers wide to-address))))
5836 (unless (message-mail-user-agent)
5837 (message-pop-to-buffer
5838 (message-buffer-name
5839 (if wide "wide reply" "reply") from
5840 (if wide to-address nil))))
5842 (setq message-reply-headers
5843 (vector 0 subject from date message-id references 0 0 ""))
5846 `((Subject . ,subject)
5851 (defun message-wide-reply (&optional to-address)
5852 "Make a \"wide\" reply to the message in the current buffer."
5854 (message-reply to-address t))
5857 (defun message-followup (&optional to-newsgroups)
5858 "Follow up to the message in the current buffer.
5859 If TO-NEWSGROUPS, use that as the new Newsgroups line."
5861 (require 'gnus-sum) ; for gnus-list-identifiers
5862 (let ((cur (current-buffer))
5863 from subject date reply-to mrt mct
5864 references message-id follow-to
5865 (inhibit-point-motion-hooks t)
5866 (message-this-is-news t)
5867 followup-to distribution newsgroups gnus-warning posted-to)
5870 (goto-char (point-min))
5871 (if (search-forward "\n\n" nil t)
5874 (when (functionp message-followup-to-function)
5876 (funcall message-followup-to-function)))
5877 (setq from (message-fetch-field "from")
5878 date (message-fetch-field "date")
5879 subject (or (message-fetch-field "subject") "none")
5880 references (message-fetch-field "references")
5881 message-id (message-fetch-field "message-id" t)
5882 followup-to (message-fetch-field "followup-to")
5883 newsgroups (message-fetch-field "newsgroups")
5884 posted-to (message-fetch-field "posted-to")
5885 reply-to (message-fetch-field "reply-to")
5886 mrt (message-fetch-field "mail-reply-to")
5887 distribution (message-fetch-field "distribution")
5888 mct (message-fetch-field "mail-copies-to"))
5889 (when (and (setq gnus-warning (message-fetch-field "gnus-warning"))
5890 (string-match "<[^>]+>" gnus-warning))
5891 (setq message-id (match-string 0 gnus-warning)))
5892 ;; Remove bogus distribution.
5893 (when (and (stringp distribution)
5894 (let ((case-fold-search t))
5895 (string-match "world" distribution)))
5896 (setq distribution nil))
5897 (if gnus-list-identifiers
5898 (setq subject (message-strip-list-identifiers subject)))
5899 (setq subject (concat "Re: " (message-strip-subject-re subject)))
5900 (when message-subject-trailing-was-query
5901 (setq subject (message-strip-subject-trailing-was subject)))
5904 (message-pop-to-buffer (message-buffer-name "followup" from newsgroups))
5906 (setq message-reply-headers
5907 (vector 0 subject from date message-id references 0 0 ""))
5910 `((Subject . ,subject)
5913 (list (cons 'Newsgroups to-newsgroups)))
5914 (follow-to follow-to)
5915 ((and followup-to message-use-followup-to)
5918 ((equal (downcase followup-to) "poster")
5919 (if (or (eq message-use-followup-to 'use)
5920 (message-y-or-n-p "Obey Followup-To: poster? " t "\
5921 You should normally obey the Followup-To: header.
5923 `Followup-To: poster' sends your response via e-mail instead of news.
5925 A typical situation where `Followup-To: poster' is used is when the poster
5926 does not read the newsgroup, so he wouldn't see any replies sent to it.
5928 You may customize the variable `message-use-followup-to', if you
5929 want to get rid of this query permanently."))
5931 (setq message-this-is-news nil)
5932 (cons 'To (or mrt reply-to from "")))
5933 (cons 'Newsgroups newsgroups)))
5935 (if (or (equal followup-to newsgroups)
5936 (not (eq message-use-followup-to 'ask))
5938 (concat "Obey Followup-To: " followup-to "? ") t "\
5939 You should normally obey the Followup-To: header.
5941 `Followup-To: " followup-to "'
5942 directs your response to " (if (string-match "," followup-to)
5943 "the specified newsgroups"
5944 "that newsgroup only") ".
5946 If a message is posted to several newsgroups, Followup-To is often
5947 used to direct the following discussion to one newsgroup only,
5948 because discussions that are spread over several newsgroup tend to
5949 be fragmented and very difficult to follow.
5951 Also, some source/announcement newsgroups are not intended for discussion;
5952 responses here are directed to other newsgroups.
5954 You may customize the variable `message-use-followup-to', if you
5955 want to get rid of this query permanently."))
5956 (cons 'Newsgroups followup-to)
5957 (cons 'Newsgroups newsgroups))))))
5959 `((Newsgroups . ,posted-to)))
5961 `((Newsgroups . ,newsgroups))))
5962 ,@(and distribution (list (cons 'Distribution distribution)))
5964 (not (or (equal (downcase mct) "never")
5965 (equal (downcase mct) "nobody"))))
5966 (list (cons 'Cc (if (or (equal (downcase mct) "always")
5967 (equal (downcase mct) "poster"))
5968 (or mrt reply-to from "")
5973 (defun message-is-yours-p ()
5974 "Non-nil means current article is yours.
5975 If you have added 'cancel-messages to `message-shoot-gnksa-feet', all articles
5976 are yours except those that have Cancel-Lock header not belonging to you.
5977 Instead of shooting GNKSA feet, you should modify `message-alternative-emails'
5978 regexp to match all of yours addresses."
5979 ;; Canlock-logic as suggested by Per Abrahamsen
5980 ;; <abraham@dina.kvl.dk>
5982 ;; IF article has cancel-lock THEN
5983 ;; IF we can verify it THEN
5986 ;; error: cancellock: article is not yours
5988 ;; Use old rules, comparing sender...
5991 (message-narrow-to-head-1)
5992 (if (message-fetch-field "Cancel-Lock")
5993 (if (null (canlock-verify))
5995 (error "Failed to verify Cancel-lock: This article is not yours"))
5998 (message-gnksa-enable-p 'cancel-messages)
5999 (and (setq sender (message-fetch-field "sender"))
6000 (string-equal (downcase sender)
6001 (downcase (message-make-sender))))
6002 ;; Email address in From field equals to our address
6003 (and (setq from (message-fetch-field "from"))
6005 (downcase (cadr (mail-extract-address-components from)))
6006 (downcase (cadr (mail-extract-address-components
6007 (message-make-from))))))
6008 ;; Email address in From field matches
6009 ;; 'message-alternative-emails' regexp
6011 message-alternative-emails
6013 message-alternative-emails
6014 (cadr (mail-extract-address-components from))))))))))
6017 (defun message-cancel-news (&optional arg)
6018 "Cancel an article you posted.
6019 If ARG, allow editing of the cancellation message."
6021 (unless (message-news-p)
6022 (error "This is not a news article; canceling is impossible"))
6023 (let (from newsgroups message-id distribution buf)
6025 ;; Get header info from original article.
6027 (message-narrow-to-head-1)
6028 (setq from (message-fetch-field "from")
6029 newsgroups (message-fetch-field "newsgroups")
6030 message-id (message-fetch-field "message-id" t)
6031 distribution (message-fetch-field "distribution")))
6032 ;; Make sure that this article was written by the user.
6033 (unless (message-is-yours-p)
6034 (error "This article is not yours"))
6035 (when (yes-or-no-p "Do you really want to cancel this article? ")
6036 ;; Make control message.
6039 (setq buf (set-buffer (get-buffer-create " *message cancel*"))))
6041 (insert "Newsgroups: " newsgroups "\n"
6043 "Subject: cmsg cancel " message-id "\n"
6044 "Control: cancel " message-id "\n"
6046 (concat "Distribution: " distribution "\n")
6048 mail-header-separator "\n"
6049 message-cancel-message)
6050 (run-hooks 'message-cancel-hook)
6052 (message "Canceling your article...")
6053 (if (let ((message-syntax-checks
6054 'dont-check-for-anything-just-trust-me))
6055 (funcall message-send-news-function))
6056 (message "Canceling your article...done"))
6057 (kill-buffer buf))))))
6060 (defun message-supersede ()
6061 "Start composing a message to supersede the current message.
6062 This is done simply by taking the old article and adding a Supersedes
6063 header line with the old Message-ID."
6065 (let ((cur (current-buffer)))
6066 ;; Check whether the user owns the article that is to be superseded.
6067 (unless (message-is-yours-p)
6068 (error "This article is not yours"))
6069 ;; Get a normal message buffer.
6070 (message-pop-to-buffer (message-buffer-name "supersede"))
6071 (insert-buffer-substring cur)
6073 (message-narrow-to-head-1)
6074 ;; Remove unwanted headers.
6075 (when message-ignored-supersedes-headers
6076 (message-remove-header message-ignored-supersedes-headers t))
6077 (goto-char (point-min))
6078 (if (not (re-search-forward "^Message-ID: " nil t))
6079 (error "No Message-ID in this article")
6080 (replace-match "Supersedes: " t t))
6081 (goto-char (point-max))
6082 (insert mail-header-separator)
6087 (defun message-recover ()
6088 "Reread contents of current buffer from its last auto-save file."
6090 (let ((file-name (make-auto-save-file-name)))
6091 (cond ((save-window-excursion
6092 (if (not (eq system-type 'vax-vms))
6093 (with-output-to-temp-buffer "*Directory*"
6094 (with-current-buffer standard-output
6095 (fundamental-mode)) ; for Emacs 20.4+
6096 (buffer-disable-undo standard-output)
6097 (let ((default-directory "/"))
6099 "ls" nil standard-output nil "-l" file-name))))
6100 (yes-or-no-p (format "Recover auto save file %s? " file-name)))
6101 (let ((buffer-read-only nil))
6103 (insert-file-contents file-name nil)))
6104 (t (error "message-recover cancelled")))))
6106 ;;; Washing Subject:
6108 (defun message-wash-subject (subject)
6109 "Remove junk like \"Re:\", \"(fwd)\", etc. added to subject string SUBJECT.
6110 Previous forwarders, replyers, etc. may add it."
6113 (goto-char (point-min))
6114 ;; strip Re/Fwd stuff off the beginning
6115 (while (re-search-forward
6116 "\\([Rr][Ee]:\\|[Ff][Ww][Dd]\\(\\[[0-9]*\\]\\)?:\\|[Ff][Ww]:\\)" nil t)
6119 ;; and gnus-style forwards [foo@bar.com] subject
6120 (goto-char (point-min))
6121 (while (re-search-forward "\\[[^ \t]*\\(@\\|\\.\\)[^ \t]*\\]" nil t)
6125 (goto-char (point-max))
6126 (while (re-search-backward "([Ff][Ww][Dd])" nil t)
6129 ;; and finally, any whitespace that was left-over
6130 (goto-char (point-min))
6131 (while (re-search-forward "^[ \t]+" nil t)
6133 (goto-char (point-max))
6134 (while (re-search-backward "[ \t]+$" nil t)
6139 ;;; Forwarding messages.
6141 (defvar message-forward-decoded-p nil
6142 "Non-nil means the original message is decoded.")
6144 (defun message-forward-subject-name-subject (subject)
6145 "Generate a SUBJECT for a forwarded message.
6146 The form is: [Source] Subject, where if the original message was mail,
6147 Source is the name of the sender, and if the original message was
6148 news, Source is the list of newsgroups is was posted to."
6149 (let* ((group (message-fetch-field "newsgroups"))
6150 (from (message-fetch-field "from"))
6153 (gnus-group-decoded-name group)
6154 (or (and from (car (gnus-extract-address-components from)))
6157 (if message-forward-decoded-p
6159 (mail-decode-encoded-word-string prefix))
6162 (defun message-forward-subject-author-subject (subject)
6163 "Generate a SUBJECT for a forwarded message.
6164 The form is: [Source] Subject, where if the original message was mail,
6165 Source is the sender, and if the original message was news, Source is
6166 the list of newsgroups is was posted to."
6167 (let* ((group (message-fetch-field "newsgroups"))
6170 (gnus-group-decoded-name group)
6171 (or (message-fetch-field "from")
6174 (if message-forward-decoded-p
6176 (mail-decode-encoded-word-string prefix))
6179 (defun message-forward-subject-fwd (subject)
6180 "Generate a SUBJECT for a forwarded message.
6181 The form is: Fwd: Subject, where Subject is the original subject of
6183 (if (string-match "^Fwd: " subject)
6185 (concat "Fwd: " subject)))
6187 (defun message-make-forward-subject ()
6188 "Return a Subject header suitable for the message in the current buffer."
6191 (message-narrow-to-head-1)
6192 (let ((funcs message-make-forward-subject-function)
6193 (subject (message-fetch-field "Subject")))
6196 (if message-forward-decoded-p
6198 (mail-decode-encoded-word-string subject))
6200 (if message-wash-forwarded-subjects
6201 (setq subject (message-wash-subject subject)))
6202 ;; Make sure funcs is a list.
6205 (setq funcs (list funcs)))
6206 ;; Apply funcs in order, passing subject generated by previous
6207 ;; func to the next one.
6209 (when (functionp (car funcs))
6210 (setq subject (funcall (car funcs) subject)))
6211 (setq funcs (cdr funcs)))
6215 (defvar gnus-article-decoded-p))
6219 (defun message-forward (&optional news digest)
6220 "Forward the current message via mail.
6221 Optional NEWS will use news to forward instead of mail.
6222 Optional DIGEST will use digest to forward."
6224 (let* ((cur (current-buffer))
6225 (message-forward-decoded-p
6226 (if (local-variable-p 'gnus-article-decoded-p (current-buffer))
6227 gnus-article-decoded-p ;; In an article buffer.
6228 message-forward-decoded-p))
6229 (subject (message-make-forward-subject)))
6231 (message-news nil subject)
6232 (message-mail nil subject))
6233 (message-forward-make-body cur digest)))
6235 (defun message-forward-make-body-plain (forward-buffer)
6237 "\n-------------------- Start of forwarded message --------------------\n")
6238 (let ((b (point)) e)
6241 (mm-disable-multibyte)
6243 (with-current-buffer forward-buffer
6244 (mm-with-unibyte-current-buffer (buffer-string))))
6245 (mm-enable-multibyte)
6247 (goto-char (point-min))
6248 (when (looking-at "From ")
6249 (replace-match "X-From-Line: "))
6253 "\n-------------------- End of forwarded message --------------------\n")
6254 (when message-forward-ignored-headers
6256 (narrow-to-region b e)
6258 (narrow-to-region (point)
6259 (or (search-forward "\n\n" nil t) (point)))
6260 (message-remove-header message-forward-ignored-headers t)))))
6262 (defun message-forward-make-body-mime (forward-buffer)
6263 (insert "\n\n<#part type=message/rfc822 disposition=inline raw=t>\n")
6264 (let ((b (point)) e)
6266 (narrow-to-region (point) (point))
6267 (mml-insert-buffer forward-buffer)
6268 (goto-char (point-min))
6269 (when (looking-at "From ")
6270 (replace-match "X-From-Line: "))
6271 (goto-char (point-max)))
6273 (insert "<#/part>\n")))
6275 (defun message-forward-make-body-mml (forward-buffer)
6276 (insert "\n\n<#mml type=message/rfc822 disposition=inline>\n")
6277 (let ((b (point)) e)
6278 (if (not message-forward-decoded-p)
6281 (mm-disable-multibyte)
6283 (with-current-buffer forward-buffer
6284 (mm-with-unibyte-current-buffer (buffer-string))))
6285 (mm-enable-multibyte)
6287 (goto-char (point-min))
6288 (when (looking-at "From ")
6289 (replace-match "X-From-Line: "))
6292 (narrow-to-region (point) (point))
6293 (mml-insert-buffer forward-buffer)
6294 (goto-char (point-min))
6295 (when (looking-at "From ")
6296 (replace-match "X-From-Line: "))
6297 (goto-char (point-max))))
6299 (insert "<#/mml>\n")
6300 (when (and (not message-forward-decoded-p)
6301 message-forward-ignored-headers)
6303 (narrow-to-region b e)
6305 (narrow-to-region (point)
6306 (or (search-forward "\n\n" nil t) (point)))
6307 (message-remove-header message-forward-ignored-headers t)))))
6309 (defun message-forward-make-body-digest-plain (forward-buffer)
6311 "\n-------------------- Start of forwarded message --------------------\n")
6312 (let ((b (point)) e)
6313 (mml-insert-buffer forward-buffer)
6316 "\n-------------------- End of forwarded message --------------------\n")))
6318 (defun message-forward-make-body-digest-mime (forward-buffer)
6319 (insert "\n<#multipart type=digest>\n")
6320 (let ((b (point)) e)
6321 (insert-buffer-substring forward-buffer)
6323 (insert "<#/multipart>\n")
6325 (narrow-to-region b e)
6327 (narrow-to-region (point)
6328 (or (search-forward "\n\n" nil t) (point)))
6329 (delete-region (point-min) (point-max)))))
6331 (defun message-forward-make-body-digest (forward-buffer)
6332 (if message-forward-as-mime
6333 (message-forward-make-body-digest-mime forward-buffer)
6334 (message-forward-make-body-digest-plain forward-buffer)))
6337 (defun message-forward-make-body (forward-buffer &optional digest)
6338 ;; Put point where we want it before inserting the forwarded
6340 (if message-forward-before-signature
6342 (goto-char (point-max)))
6344 (message-forward-make-body-digest forward-buffer)
6345 (if message-forward-as-mime
6346 (if (and message-forward-show-mml
6347 (not (and (eq message-forward-show-mml 'best)
6348 (with-current-buffer forward-buffer
6349 (goto-char (point-min))
6351 "Content-Type: *multipart/\\(signed\\|encrypted\\)"
6353 (message-forward-make-body-mml forward-buffer)
6354 (message-forward-make-body-mime forward-buffer))
6355 (message-forward-make-body-plain forward-buffer)))
6356 (message-position-point))
6359 (defun message-forward-rmail-make-body (forward-buffer)
6360 (save-window-excursion
6361 (set-buffer forward-buffer)
6362 ;; Rmail doesn't have rmail-msg-restore-non-pruned-header in Emacs
6363 ;; 20. FIXIT, or we drop support for rmail in Emacs 20.
6364 (if (rmail-msg-is-pruned)
6365 (rmail-msg-restore-non-pruned-header)))
6366 (message-forward-make-body forward-buffer))
6368 (eval-when-compile (defvar rmail-enable-mime-composing))
6370 ;; Fixme: Should have defcustom.
6372 (defun message-insinuate-rmail ()
6373 "Let RMAIL use message to forward."
6375 (setq rmail-enable-mime-composing t)
6376 (setq rmail-insert-mime-forwarded-message-function
6377 'message-forward-rmail-make-body))
6380 (defun message-resend (address)
6381 "Resend the current article to ADDRESS."
6383 (list (message-read-from-minibuffer "Resend message to: ")))
6384 (message "Resending message to %s..." address)
6386 (let ((cur (current-buffer))
6388 ;; We first set up a normal mail buffer.
6389 (unless (message-mail-user-agent)
6390 (set-buffer (get-buffer-create " *message resend*"))
6392 (let ((message-this-is-mail t)
6394 (message-setup `((To . ,address))))
6395 ;; Insert our usual headers.
6396 (message-generate-headers '(From Date To Message-ID))
6397 (message-narrow-to-headers)
6398 ;; Remove X-Draft-From header etc.
6399 (message-remove-header message-ignored-mail-headers t)
6400 ;; Rename them all to "Resent-*".
6401 (goto-char (point-min))
6402 (while (re-search-forward "^[A-Za-z]" nil t)
6407 (delete-region (point) (point-max))
6409 ;; Insert the message to be resent.
6410 (insert-buffer-substring cur)
6411 (goto-char (point-min))
6412 (search-forward "\n\n")
6415 (narrow-to-region beg (point))
6416 (message-remove-header message-ignored-resent-headers t)
6417 (goto-char (point-max)))
6418 (insert mail-header-separator)
6419 ;; Rename all old ("Also-")Resent headers.
6420 (while (re-search-backward "^\\(Also-\\)*Resent-" beg t)
6423 ;; Quote any "From " lines at the beginning.
6425 (when (looking-at "From ")
6426 (replace-match "X-From-Line: "))
6428 (let ((message-inhibit-body-encoding t)
6429 message-required-mail-headers
6430 rfc2047-encode-encoded-words)
6431 (message-send-mail))
6432 (kill-buffer (current-buffer)))
6433 (message "Resending message to %s...done" address)))
6436 (defun message-bounce ()
6437 "Re-mail the current message.
6438 This only makes sense if the current message is a bounce message that
6439 contains some mail you have written which has been bounced back to
6442 (let ((handles (mm-dissect-buffer t))
6444 (message-pop-to-buffer (message-buffer-name "bounce"))
6445 (if (stringp (car handles))
6446 ;; This is a MIME bounce.
6447 (mm-insert-part (car (last handles)))
6448 ;; This is a non-MIME bounce, so we try to remove things
6450 (mm-insert-part handles)
6452 (goto-char (point-min))
6453 (re-search-forward "\n\n+" nil t)
6454 (setq boundary (point))
6455 ;; We remove everything before the bounced mail.
6456 (if (or (re-search-forward message-unsent-separator nil t)
6458 (search-forward "\n\n" nil 'move)
6459 (re-search-backward "^Return-Path:.*\n" boundary t)))
6462 (delete-region (point-min)
6463 (if (re-search-forward "^[^ \n\t]+:" nil t)
6466 (goto-char boundary)
6467 (when (re-search-backward "^.?From .*\n" nil t)
6468 (delete-region (match-beginning 0) (match-end 0)))))
6469 (mm-enable-multibyte)
6471 (message-narrow-to-head-1)
6472 (message-remove-header message-ignored-bounced-headers t)
6473 (goto-char (point-max))
6474 (insert mail-header-separator))
6475 (message-position-point)))
6478 ;;; Interactive entry points for new message buffers.
6482 (defun message-mail-other-window (&optional to subject)
6483 "Like `message-mail' command, but display mail buffer in another window."
6485 (unless (message-mail-user-agent)
6486 (let ((pop-up-windows t)
6487 (special-display-buffer-names nil)
6488 (special-display-regexps nil)
6489 (same-window-buffer-names nil)
6490 (same-window-regexps nil))
6491 (message-pop-to-buffer (message-buffer-name "mail" to))))
6492 (let ((message-this-is-mail t))
6493 (message-setup `((To . ,(or to "")) (Subject . ,(or subject "")))
6494 nil nil 'switch-to-buffer-other-window)))
6497 (defun message-mail-other-frame (&optional to subject)
6498 "Like `message-mail' command, but display mail buffer in another frame."
6500 (unless (message-mail-user-agent)
6501 (let ((pop-up-frames t)
6502 (special-display-buffer-names nil)
6503 (special-display-regexps nil)
6504 (same-window-buffer-names nil)
6505 (same-window-regexps nil))
6506 (message-pop-to-buffer (message-buffer-name "mail" to))))
6507 (let ((message-this-is-mail t))
6508 (message-setup `((To . ,(or to "")) (Subject . ,(or subject "")))
6509 nil nil 'switch-to-buffer-other-frame)))
6512 (defun message-news-other-window (&optional newsgroups subject)
6513 "Start editing a news article to be sent."
6515 (let ((pop-up-windows t)
6516 (special-display-buffer-names nil)
6517 (special-display-regexps nil)
6518 (same-window-buffer-names nil)
6519 (same-window-regexps nil))
6520 (message-pop-to-buffer (message-buffer-name "posting" nil newsgroups)))
6521 (let ((message-this-is-news t))
6522 (message-setup `((Newsgroups . ,(or newsgroups ""))
6523 (Subject . ,(or subject ""))))))
6526 (defun message-news-other-frame (&optional newsgroups subject)
6527 "Start editing a news article to be sent."
6529 (let ((pop-up-frames t)
6530 (special-display-buffer-names nil)
6531 (special-display-regexps nil)
6532 (same-window-buffer-names nil)
6533 (same-window-regexps nil))
6534 (message-pop-to-buffer (message-buffer-name "posting" nil newsgroups)))
6535 (let ((message-this-is-news t))
6536 (message-setup `((Newsgroups . ,(or newsgroups ""))
6537 (Subject . ,(or subject ""))))))
6541 ;; This code should be moved to underline.el (from which it is stolen).
6544 (defun bold-region (start end)
6545 "Bold all nonblank characters in the region.
6546 Works by overstriking characters.
6547 Called from program, takes two arguments START and END
6548 which specify the range to operate on."
6551 (let ((end1 (make-marker)))
6552 (move-marker end1 (max start end))
6553 (goto-char (min start end))
6554 (while (< (point) end1)
6555 (or (looking-at "[_\^@- ]")
6556 (insert (char-after) "\b"))
6557 (forward-char 1)))))
6560 (defun unbold-region (start end)
6561 "Remove all boldness (overstruck characters) in the region.
6562 Called from program, takes two arguments START and END
6563 which specify the range to operate on."
6566 (let ((end1 (make-marker)))
6567 (move-marker end1 (max start end))
6568 (goto-char (min start end))
6569 (while (re-search-forward "\b" end1 t)
6570 (if (eq (char-after) (char-after (- (point) 2)))
6571 (delete-char -2))))))
6573 (defun message-exchange-point-and-mark ()
6574 "Exchange point and mark, but don't activate region if it was inactive."
6576 (message-mark-active-p)
6577 (exchange-point-and-mark))
6578 (setq mark-active nil)))
6580 (defalias 'message-make-overlay 'make-overlay)
6581 (defalias 'message-delete-overlay 'delete-overlay)
6582 (defalias 'message-overlay-put 'overlay-put)
6583 (defun message-kill-all-overlays ()
6584 (if (featurep 'xemacs)
6585 (map-extents (lambda (extent ignore) (delete-extent extent)))
6586 (mapcar #'delete-overlay (overlays-in (point-min) (point-max)))))
6588 ;; Support for toolbar
6590 (defvar tool-bar-mode))
6592 ;; Note: The :set function in the `message-tool-bar*' variables will only
6593 ;; affect _new_ message buffers. We might add a function that walks thru all
6594 ;; message-mode buffers and force the update.
6595 (defun message-tool-bar-update (&optional symbol value)
6596 "Update message mode toolbar.
6597 Setter function for custom variables."
6598 (setq-default message-tool-bar-map nil)
6600 ;; When used as ":set" function:
6601 (set-default symbol value)))
6603 (defcustom message-tool-bar (if (eq gmm-tool-bar-style 'gnome)
6604 'message-tool-bar-gnome
6605 'message-tool-bar-retro)
6606 "Specifies the message mode tool bar.
6608 It can be either a list or a symbol refering to a list. See
6609 `gmm-tool-bar-from-list' for the format of the list. The
6610 default key map is `message-mode-map'.
6612 Pre-defined symbols include `message-tool-bar-gnome' and
6613 `message-tool-bar-retro'."
6614 :type '(repeat gmm-tool-bar-list-item)
6615 :type '(choice (const :tag "GNOME style" message-tool-bar-gnome)
6616 (const :tag "Retro look" message-tool-bar-retro)
6617 (repeat :tag "User defined list" gmm-tool-bar-item)
6619 :version "22.1" ;; Gnus 5.10.9
6620 :initialize 'custom-initialize-default
6621 :set 'message-tool-bar-update
6624 (defcustom message-tool-bar-gnome
6625 '((ispell-message "spell" nil
6626 :visible (or (not (boundp 'flyspell-mode))
6627 (not flyspell-mode)))
6628 (flyspell-buffer "spell" t
6629 :visible (and (boundp 'flyspell-mode)
6631 :help "Flyspell whole buffer")
6632 (gmm-ignore "separator")
6633 (message-send-and-exit "mail/send")
6634 (message-dont-send "mail/save-draft")
6635 (message-kill-buffer "close") ;; stock_cancel
6636 (mml-attach-file "attach" mml-mode-map)
6637 (mml-preview "mail/preview" mml-mode-map)
6638 ;; (mml-secure-message-sign-encrypt "lock" mml-mode-map :visible nil)
6639 (message-insert-importance-high "important" nil :visible nil)
6640 (message-insert-importance-low "unimportant" nil :visible nil)
6641 (message-insert-disposition-notification-to "receipt" nil :visible nil)
6642 (gmm-customize-mode "preferences" t :help "Edit mode preferences")
6643 (message-info "help" t :help "Message manual"))
6644 "List of items for the message tool bar (GNOME style).
6646 See `gmm-tool-bar-from-list' for details on the format of the list."
6647 :type '(repeat gmm-tool-bar-item)
6648 :version "22.1" ;; Gnus 5.10.9
6649 :initialize 'custom-initialize-default
6650 :set 'message-tool-bar-update
6653 (defcustom message-tool-bar-retro
6654 '(;; Old Emacs 21 icon for consistency.
6655 (message-send-and-exit "gnus/mail_send")
6656 (message-kill-buffer "close")
6657 (message-dont-send "cancel")
6658 (mml-attach-file "attach" mml-mode-map)
6659 (ispell-message "spell")
6660 (mml-preview "preview" mml-mode-map)
6661 (message-insert-importance-high "gnus/important")
6662 (message-insert-importance-low "gnus/unimportant")
6663 (message-insert-disposition-notification-to "gnus/receipt"))
6664 "List of items for the message tool bar (retro style).
6666 See `gmm-tool-bar-from-list' for details on the format of the list."
6667 :type '(repeat gmm-tool-bar-item)
6668 :version "22.1" ;; Gnus 5.10.9
6669 :initialize 'custom-initialize-default
6670 :set 'message-tool-bar-update
6673 (defcustom message-tool-bar-zap-list
6674 '(new-file open-file dired kill-buffer write-file
6675 print-buffer customize help)
6676 "List of icon items from the global tool bar.
6677 These items are not displayed on the message mode tool bar.
6679 See `gmm-tool-bar-from-list' for the format of the list."
6680 :type 'gmm-tool-bar-zap-list
6681 :version "22.1" ;; Gnus 5.10.9
6682 :initialize 'custom-initialize-default
6683 :set 'message-tool-bar-update
6686 (defvar image-load-path)
6688 (defun message-make-tool-bar (&optional force)
6689 "Make a message mode tool bar from `message-tool-bar-list'.
6690 When FORCE, rebuild the tool bar."
6691 (when (and (not (featurep 'xemacs))
6692 (boundp 'tool-bar-mode)
6694 (or (not message-tool-bar-map) force))
6695 (setq message-tool-bar-map
6697 (gmm-image-load-path-for-library "message"
6698 "mail/save-draft.xpm"
6700 (image-load-path (cons (car load-path)
6701 (when (boundp 'image-load-path)
6703 (gmm-tool-bar-from-list message-tool-bar
6704 message-tool-bar-zap-list
6705 'message-mode-map))))
6706 message-tool-bar-map)
6708 ;;; Group name completion.
6710 (defcustom message-newgroups-header-regexp
6711 "^\\(Newsgroups\\|Followup-To\\|Posted-To\\|Gcc\\):"
6712 "Regexp that match headers that lists groups."
6716 (defcustom message-completion-alist
6717 (list (cons message-newgroups-header-regexp 'message-expand-group)
6718 '("^\\(Resent-\\)?\\(To\\|B?Cc\\):" . message-expand-name)
6719 '("^\\(Reply-To\\|From\\|Mail-Followup-To\\|Mail-Copies-To\\):"
6720 . message-expand-name)
6721 '("^\\(Disposition-Notification-To\\|Return-Receipt-To\\):"
6722 . message-expand-name))
6723 "Alist of (RE . FUN). Use FUN for completion on header lines matching RE."
6726 :type '(alist :key-type regexp :value-type function))
6728 (defcustom message-tab-body-function nil
6729 "*Function to execute when `message-tab' (TAB) is executed in the body.
6730 If nil, the function bound in `text-mode-map' or `global-map' is executed."
6733 :link '(custom-manual "(message)Various Commands")
6734 :type '(choice (const nil)
6737 (defun message-tab ()
6738 "Complete names according to `message-completion-alist'.
6739 Execute function specified by `message-tab-body-function' when not in
6742 (let ((alist message-completion-alist))
6744 (let ((mail-abbrev-mode-regexp (caar alist)))
6745 (not (mail-abbrev-in-expansion-header-p))))
6746 (setq alist (cdr alist)))
6747 (funcall (or (cdar alist) message-tab-body-function
6748 (lookup-key text-mode-map "\t")
6749 (lookup-key global-map "\t")
6750 'indent-relative))))
6755 (let ((standard-output (current-buffer)))
6756 (eval '(display-completion-list nil "")))
6757 (defalias 'message-display-completion-list 'display-completion-list))
6758 (error ;; Don't use `wrong-number-of-arguments' here because of XEmacs.
6759 (defun message-display-completion-list (completions &optional ignore)
6760 "Display the list of completions, COMPLETIONS, using `standard-output'."
6761 (display-completion-list completions)))))
6763 (defun message-expand-group ()
6764 "Expand the group name under point."
6765 (let* ((b (save-excursion
6770 (skip-chars-forward "^:")
6773 (skip-chars-backward "^, \t\n") (point))))
6774 (completion-ignore-case t)
6775 (string (buffer-substring b (progn (skip-chars-forward "^,\t\n ")
6777 (hashtb (and (boundp 'gnus-active-hashtb) gnus-active-hashtb))
6778 (completions (all-completions string hashtb))
6780 (delete-region b (point))
6782 ((= (length completions) 1)
6783 (if (string= (car completions) string)
6786 (message "Only matching group"))
6787 (insert (car completions))))
6788 ((and (setq comp (try-completion string hashtb))
6789 (not (string= comp string)))
6794 (message "No matching groups")
6795 (save-selected-window
6796 (pop-to-buffer "*Completions*")
6797 (buffer-disable-undo)
6798 (let ((buffer-read-only nil))
6800 (let ((standard-output (current-buffer)))
6801 (message-display-completion-list (sort completions 'string<)
6803 (setq buffer-read-only nil)
6804 (goto-char (point-min))
6805 (delete-region (point) (progn (forward-line 3) (point))))))))))
6807 (defun message-expand-name ()
6808 (if (fboundp 'bbdb-complete-name)
6809 (bbdb-complete-name)
6814 (defun message-talkative-question (ask question show &rest text)
6815 "Call FUNCTION with argument QUESTION; optionally display TEXT... args.
6816 If SHOW is non-nil, the arguments TEXT... are displayed in a temp buffer.
6817 The following arguments may contain lists of values."
6819 (setq text (message-flatten-list text)))
6820 (save-window-excursion
6822 (with-output-to-temp-buffer " *MESSAGE information message*"
6823 (set-buffer " *MESSAGE information message*")
6824 (fundamental-mode) ; for Emacs 20.4+
6825 (mapcar 'princ text)
6826 (goto-char (point-min))))
6827 (funcall ask question))
6828 (funcall ask question)))
6830 (defun message-flatten-list (list)
6831 "Return a new, flat list that contains all elements of LIST.
6833 \(message-flatten-list '(1 (2 3 (4 5 (6))) 7))
6836 (apply 'append (mapcar 'message-flatten-list list)))
6840 (defun message-generate-new-buffer-clone-locals (name &optional varstr)
6841 "Create and return a buffer with name based on NAME using `generate-new-buffer'.
6842 Then clone the local variables and values from the old buffer to the
6843 new one, cloning only the locals having a substring matching the
6845 (let ((oldbuf (current-buffer)))
6847 (set-buffer (generate-new-buffer name))
6848 (message-clone-locals oldbuf varstr)
6851 (defun message-clone-locals (buffer &optional varstr)
6852 "Clone the local variables from BUFFER to the current buffer."
6853 (let ((locals (save-excursion
6855 (buffer-local-variables)))
6856 (regexp "^gnus\\|^nn\\|^message\\|^sendmail\\|^smtp\\|^user-mail-address"))
6859 (when (and (consp local)
6861 (string-match regexp (symbol-name (car local)))
6863 (string-match varstr (symbol-name (car local)))))
6865 (set (make-local-variable (car local))
6873 (defvar message-inhibit-body-encoding nil)
6875 (defun message-encode-message-body ()
6876 (unless message-inhibit-body-encoding
6877 (let ((mail-parse-charset (or mail-parse-charset
6878 message-default-charset))
6879 (case-fold-search t)
6880 lines content-type-p)
6883 (narrow-to-region (point) (point-max))
6884 (let ((new (mml-generate-mime)))
6886 (delete-region (point-min) (point-max))
6888 (goto-char (point-min))
6889 (if (eq (aref new 0) ?\n)
6891 (search-forward "\n\n")
6892 (setq lines (buffer-substring (point-min) (1- (point))))
6893 (delete-region (point-min) (point))))))
6895 (message-narrow-to-headers-or-head)
6896 (message-remove-header "Mime-Version")
6897 (goto-char (point-max))
6898 (insert "MIME-Version: 1.0\n")
6901 (setq content-type-p
6903 (re-search-backward "^Content-Type:" nil t))))
6905 (message-narrow-to-headers-or-head)
6906 (message-remove-first-header "Content-Type")
6907 (message-remove-first-header "Content-Transfer-Encoding"))
6908 ;; We always make sure that the message has a Content-Type
6909 ;; header. This is because some broken MTAs and MUAs get
6910 ;; awfully confused when confronted with a message with a
6911 ;; MIME-Version header and without a Content-Type header. For
6912 ;; instance, Solaris' /usr/bin/mail.
6913 (unless content-type-p
6914 (goto-char (point-min))
6915 ;; For unknown reason, MIME-Version doesn't exist.
6916 (when (re-search-forward "^MIME-Version:" nil t)
6918 (insert "Content-Type: text/plain; charset=us-ascii\n"))))))
6920 (defun message-read-from-minibuffer (prompt &optional initial-contents)
6921 "Read from the minibuffer while providing abbrev expansion."
6922 (if (fboundp 'mail-abbrevs-setup)
6923 (let ((mail-abbrev-mode-regexp "")
6924 (minibuffer-setup-hook 'mail-abbrevs-setup)
6925 (minibuffer-local-map message-minibuffer-local-map))
6926 (read-from-minibuffer prompt initial-contents))
6927 (let ((minibuffer-setup-hook 'mail-abbrev-minibuffer-setup-hook)
6928 (minibuffer-local-map message-minibuffer-local-map))
6929 (read-string prompt initial-contents))))
6931 (defun message-use-alternative-email-as-from ()
6932 "Set From field of the outgoing message to the first matching
6933 address in `message-alternative-emails', looking at To, Cc and
6934 From headers in the original article."
6935 (require 'mail-utils)
6936 (let* ((fields '("To" "Cc"))
6939 (mail-strip-quoted-names
6940 (mapconcat 'message-fetch-reply-field fields ","))
6944 (if (string-match message-alternative-emails (car emails))
6945 (setq email (car emails)
6948 (unless (or (not email) (equal email user-mail-address))
6949 (message-remove-header "From")
6950 (goto-char (point-max))
6951 (insert "From: " email "\n"))))
6953 (defun message-options-get (symbol)
6954 (cdr (assq symbol message-options)))
6956 (defun message-options-set (symbol value)
6957 (let ((the-cons (assq symbol message-options)))
6960 (setcdr the-cons value)
6961 (setq message-options (delq the-cons message-options)))
6963 (push (cons symbol value) message-options))))
6966 (defun message-options-set-recipient ()
6968 (message-narrow-to-headers-or-head)
6969 (message-options-set 'message-sender
6970 (mail-strip-quoted-names
6971 (message-fetch-field "from")))
6972 (message-options-set 'message-recipients
6973 (mail-strip-quoted-names
6974 (let ((to (message-fetch-field "to"))
6975 (cc (message-fetch-field "cc"))
6976 (bcc (message-fetch-field "bcc")))
6979 (if (and to cc) ", ")
6981 (if (and (or to cc) bcc) ", ")
6984 (defun message-hide-headers ()
6985 "Hide headers based on the `message-hidden-headers' variable."
6986 (let ((regexps (if (stringp message-hidden-headers)
6987 (list message-hidden-headers)
6988 message-hidden-headers))
6989 (inhibit-point-motion-hooks t)
6990 (after-change-functions nil))
6994 (message-narrow-to-headers)
6995 (goto-char (point-min))
6997 (if (not (message-hide-header-p regexps))
6998 (message-next-header)
6999 (let ((begin (point)))
7000 (message-next-header)
7001 (add-text-properties
7003 '(invisible t message-hidden t))))))))))
7005 (defun message-hide-header-p (regexps)
7008 (when (eq (car regexps) 'not)
7011 (dolist (regexp regexps)
7012 (setq result (or result (looking-at regexp))))
7017 (when (featurep 'xemacs)
7018 (require 'messagexmas)
7019 (message-xmas-redefine))
7023 (run-hooks 'message-load-hook)
7026 ;; coding: iso-8859-1
7029 ;; arch-tag: 94b32cac-4504-4b6c-8181-030ebf380ee0
7030 ;;; message.el ends here