1 ;;; message.el --- composing mail and news messages
2 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005
3 ;; Free Software Foundation, Inc.
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
6 ;; Keywords: mail, news
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
27 ;; This mode provides mail-sending facilities from within Emacs. It
28 ;; consists mainly of large chunks of code from the sendmail.el,
29 ;; gnus-msg.el and rnewspost.el files.
35 (defvar gnus-message-group-art)
36 (defvar gnus-list-identifiers)) ; gnus-sum is required where necessary
40 ;; This is apparently necessary even though things are autoloaded.
41 ;; Because we dynamically bind mail-abbrev-mode-regexp, we'd better
42 ;; require mailabbrev here.
43 (if (featurep 'xemacs)
44 (require 'mail-abbrevs)
45 (require 'mailabbrev))
50 (autoload 'gnus-find-method-for-group "gnus")
51 (autoload 'nnvirtual-find-group-art "nnvirtual")
52 (autoload 'gnus-group-decoded-name "gnus-group"))
54 (defgroup message '((user-mail-address custom-variable)
55 (user-full-name custom-variable))
56 "Mail and news message composing."
57 :link '(custom-manual "(message)Top")
61 (put 'user-mail-address 'custom-type 'string)
62 (put 'user-full-name 'custom-type 'string)
64 (defgroup message-various nil
65 "Various Message Variables"
66 :link '(custom-manual "(message)Various Message Variables")
69 (defgroup message-buffers nil
71 :link '(custom-manual "(message)Message Buffers")
74 (defgroup message-sending nil
76 :link '(custom-manual "(message)Sending Variables")
79 (defgroup message-interface nil
81 :link '(custom-manual "(message)Interface")
84 (defgroup message-forwarding nil
86 :link '(custom-manual "(message)Forwarding")
87 :group 'message-interface)
89 (defgroup message-insertion nil
91 :link '(custom-manual "(message)Insertion")
94 (defgroup message-headers nil
96 :link '(custom-manual "(message)Message Headers")
99 (defgroup message-news nil
100 "Composing News Messages"
103 (defgroup message-mail nil
104 "Composing Mail Messages"
107 (defgroup message-faces nil
108 "Faces used for message composing."
112 (defcustom message-directory "~/Mail/"
113 "*Directory from which all other mail file variables are derived."
114 :group 'message-various
117 (defcustom message-max-buffers 10
118 "*How many buffers to keep before starting to kill them off."
119 :group 'message-buffers
122 (defcustom message-send-rename-function nil
123 "Function called to rename the buffer after sending it."
124 :group 'message-buffers
125 :type '(choice function (const nil)))
127 (defcustom message-fcc-handler-function 'message-output
128 "*A function called to save outgoing articles.
129 This function will be called with the name of the file to store the
130 article in. The default function is `message-output' which saves in Unix
132 :type '(radio (function-item message-output)
133 (function :tag "Other"))
134 :group 'message-sending)
136 (defcustom message-fcc-externalize-attachments nil
137 "If non-nil, attachments are included as external parts in Fcc copies."
140 :group 'message-sending)
142 (defcustom message-courtesy-message
143 "The following message is a courtesy copy of an article\nthat has been posted to %s as well.\n\n"
144 "*This is inserted at the start of a mailed copy of a posted message.
145 If the string contains the format spec \"%s\", the Newsgroups
146 the article has been posted to will be inserted there.
147 If this variable is nil, no such courtesy message will be added."
148 :group 'message-sending
149 :type '(radio string (const nil)))
151 (defcustom message-ignored-bounced-headers
152 "^\\(Received\\|Return-Path\\|Delivered-To\\):"
153 "*Regexp that matches headers to be removed in resent bounced mail."
154 :group 'message-interface
158 (defcustom message-from-style 'default
159 "*Specifies how \"From\" headers look.
161 If nil, they contain just the return address like:
163 If `parens', they look like:
164 king@grassland.com (Elvis Parsley)
165 If `angles', they look like:
166 Elvis Parsley <king@grassland.com>
168 Otherwise, most addresses look like `angles', but they look like
169 `parens' if `angles' would need quoting and `parens' would not."
170 :type '(choice (const :tag "simple" nil)
174 :group 'message-headers)
176 (defcustom message-insert-canlock t
177 "Whether to insert a Cancel-Lock header in news postings."
179 :group 'message-headers
182 (defcustom message-syntax-checks
183 (if message-insert-canlock '((sender . disabled)) nil)
184 ;; Guess this one shouldn't be easy to customize...
185 "*Controls what syntax checks should not be performed on outgoing posts.
186 To disable checking of long signatures, for instance, add
187 `(signature . disabled)' to this list.
189 Don't touch this variable unless you really know what you're doing.
191 Checks include `subject-cmsg', `multiple-headers', `sendsys',
192 `message-id', `from', `long-lines', `control-chars', `size',
193 `new-text', `quoting-style', `redirected-followup', `signature',
194 `approved', `sender', `empty', `empty-headers', `message-id', `from',
195 `subject', `shorten-followup-to', `existing-newsgroups',
196 `buffer-file-name', `unchanged', `newsgroups', `reply-to',
197 `continuation-headers', `long-header-lines', `invisible-text' and
200 :type '(repeat sexp)) ; Fixme: improve this
202 (defcustom message-required-headers '((optional . References)
204 "*Headers to be generated or prompted for when sending a message.
205 Also see `message-required-news-headers' and
206 `message-required-mail-headers'."
209 :group 'message-headers
210 :link '(custom-manual "(message)Message Headers")
211 :type '(repeat sexp))
213 (defcustom message-draft-headers '(References From)
214 "*Headers to be generated when saving a draft message."
217 :group 'message-headers
218 :link '(custom-manual "(message)Message Headers")
219 :type '(repeat sexp))
221 (defcustom message-required-news-headers
222 '(From Newsgroups Subject Date Message-ID
223 (optional . Organization)
224 (optional . User-Agent))
225 "*Headers to be generated or prompted for when posting an article.
226 RFC977 and RFC1036 require From, Date, Newsgroups, Subject,
227 Message-ID. Organization, Lines, In-Reply-To, Expires, and
228 User-Agent are optional. If don't you want message to insert some
229 header, remove it from this list."
231 :group 'message-headers
232 :link '(custom-manual "(message)Message Headers")
233 :type '(repeat sexp))
235 (defcustom message-required-mail-headers
236 '(From Subject Date (optional . In-Reply-To) Message-ID
237 (optional . User-Agent))
238 "*Headers to be generated or prompted for when mailing a message.
239 It is recommended that From, Date, To, Subject and Message-ID be
240 included. Organization and User-Agent are optional."
242 :group 'message-headers
243 :link '(custom-manual "(message)Message Headers")
244 :type '(repeat sexp))
246 (defcustom message-deletable-headers '(Message-ID Date Lines)
247 "Headers to be deleted if they already exist and were generated by message previously."
248 :group 'message-headers
249 :link '(custom-manual "(message)Message Headers")
252 (defcustom message-ignored-news-headers
253 "^NNTP-Posting-Host:\\|^Xref:\\|^[BGF]cc:\\|^Resent-Fcc:\\|^X-Draft-From:\\|^X-Gnus-Agent-Meta-Information:"
254 "*Regexp of headers to be removed unconditionally before posting."
256 :group 'message-headers
257 :link '(custom-manual "(message)Message Headers")
258 :type '(repeat :value-to-internal (lambda (widget value)
259 (custom-split-regexp-maybe value))
260 :match (lambda (widget value)
262 (widget-editable-list-match widget value)))
265 (defcustom message-ignored-mail-headers
266 "^[GF]cc:\\|^Resent-Fcc:\\|^Xref:\\|^X-Draft-From:\\|^X-Gnus-Agent-Meta-Information:"
267 "*Regexp of headers to be removed unconditionally before mailing."
269 :group 'message-headers
270 :link '(custom-manual "(message)Mail Headers")
273 (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:"
274 "*Header lines matching this regexp will be deleted before posting.
275 It's best to delete old Path and Date headers before posting to avoid
277 :group 'message-interface
278 :link '(custom-manual "(message)Superseding")
279 :type '(repeat :value-to-internal (lambda (widget value)
280 (custom-split-regexp-maybe value))
281 :match (lambda (widget value)
283 (widget-editable-list-match widget value)))
286 (defcustom message-subject-re-regexp
287 "^[ \t]*\\([Rr][Ee]\\(\\[[0-9]*\\]\\)*:[ \t]*\\)*[ \t]*"
288 "*Regexp matching \"Re: \" in the subject line."
289 :group 'message-various
290 :link '(custom-manual "(message)Message Headers")
293 ;;; Start of variables adopted from `message-utils.el'.
295 (defcustom message-subject-trailing-was-query 'ask
296 "*What to do with trailing \"(was: <old subject>)\" in subject lines.
297 If nil, leave the subject unchanged. If it is the symbol `ask', query
298 the user what do do. In this case, the subject is matched against
299 `message-subject-trailing-was-ask-regexp'. If
300 `message-subject-trailing-was-query' is t, always strip the trailing
301 old subject. In this case, `message-subject-trailing-was-regexp' is
304 :type '(choice (const :tag "never" nil)
305 (const :tag "always strip" t)
307 :link '(custom-manual "(message)Message Headers")
308 :group 'message-various)
310 (defcustom message-subject-trailing-was-ask-regexp
311 "[ \t]*\\([[(]+[Ww][Aa][Ss][ \t]*.*[\])]+\\)"
312 "*Regexp matching \"(was: <old subject>)\" in the subject line.
314 The function `message-strip-subject-trailing-was' uses this regexp if
315 `message-subject-trailing-was-query' is set to the symbol `ask'. If
316 the variable is t instead of `ask', use
317 `message-subject-trailing-was-regexp' instead.
319 It is okay to create some false positives here, as the user is asked."
321 :group 'message-various
322 :link '(custom-manual "(message)Message Headers")
325 (defcustom message-subject-trailing-was-regexp
326 "[ \t]*\\((*[Ww][Aa][Ss]:[ \t]*.*)\\)"
327 "*Regexp matching \"(was: <old subject>)\" in the subject line.
329 If `message-subject-trailing-was-query' is set to t, the subject is
330 matched against `message-subject-trailing-was-regexp' in
331 `message-strip-subject-trailing-was'. You should use a regexp creating very
332 few false positives here."
334 :group 'message-various
335 :link '(custom-manual "(message)Message Headers")
338 ;;; marking inserted text
340 (defcustom message-mark-insert-begin
341 "--8<---------------cut here---------------start------------->8---\n"
342 "How to mark the beginning of some inserted text."
345 :link '(custom-manual "(message)Insertion Variables")
346 :group 'message-various)
348 (defcustom message-mark-insert-end
349 "--8<---------------cut here---------------end--------------->8---\n"
350 "How to mark the end of some inserted text."
353 :link '(custom-manual "(message)Insertion Variables")
354 :group 'message-various)
356 (defcustom message-archive-header "X-No-Archive: Yes\n"
357 "Header to insert when you don't want your article to be archived.
358 Archives \(such as groups.google.com\) respect this header."
361 :link '(custom-manual "(message)Header Commands")
362 :group 'message-various)
364 (defcustom message-archive-note
365 "X-No-Archive: Yes - save http://groups.google.com/"
366 "Note to insert why you wouldn't want this posting archived.
367 If nil, don't insert any text in the body."
369 :type '(radio string (const nil))
370 :link '(custom-manual "(message)Header Commands")
371 :group 'message-various)
373 ;;; Crossposts and Followups
374 ;; inspired by JoH-followup-to by Jochem Huhman <joh at gmx.de>
375 ;; new suggestions by R. Weikusat <rw at another.de>
377 (defvar message-cross-post-old-target nil
378 "Old target for cross-posts or follow-ups.")
379 (make-variable-buffer-local 'message-cross-post-old-target)
381 (defcustom message-cross-post-default t
382 "When non-nil `message-cross-post-followup-to' will perform a crosspost.
383 If nil, `message-cross-post-followup-to' will only do a followup. Note that
384 you can explicitly override this setting by calling
385 `message-cross-post-followup-to' with a prefix."
388 :group 'message-various)
390 (defcustom message-cross-post-note "Crosspost & Followup-To: "
391 "Note to insert before signature to notify of cross-post and follow-up."
394 :group 'message-various)
396 (defcustom message-followup-to-note "Followup-To: "
397 "Note to insert before signature to notify of follow-up only."
400 :group 'message-various)
402 (defcustom message-cross-post-note-function 'message-cross-post-insert-note
403 "Function to use to insert note about Crosspost or Followup-To.
404 The function will be called with four arguments. The function should not only
405 insert a note, but also ensure old notes are deleted. See the documentation
406 for `message-cross-post-insert-note'."
409 :group 'message-various)
411 ;;; End of variables adopted from `message-utils.el'.
414 (defcustom message-signature-separator "^-- *$"
415 "Regexp matching the signature separator."
417 :link '(custom-manual "(message)Various Message Variables")
418 :group 'message-various)
420 (defcustom message-elide-ellipsis "\n[...]\n\n"
421 "*The string which is inserted for elided text."
423 :link '(custom-manual "(message)Various Commands")
424 :group 'message-various)
426 (defcustom message-interactive t
427 "Non-nil means when sending a message wait for and display errors.
428 nil means let mailer mail back a message to report errors."
429 :group 'message-sending
431 :link '(custom-manual "(message)Sending Variables")
434 (defcustom message-generate-new-buffers 'unique
435 "*Non-nil means create a new message buffer whenever `message-setup' is called.
436 If this is a function, call that function with three parameters: The type,
437 the to address and the group name. (Any of these may be nil.) The function
438 should return the new buffer name."
439 :group 'message-buffers
440 :link '(custom-manual "(message)Message Buffers")
441 :type '(choice (const :tag "off" nil)
442 (const :tag "unique" unique)
443 (const :tag "unsent" unsent)
446 (defcustom message-kill-buffer-on-exit nil
447 "*Non-nil means that the message buffer will be killed after sending a message."
448 :group 'message-buffers
449 :link '(custom-manual "(message)Message Buffers")
453 (defvar gnus-local-organization))
454 (defcustom message-user-organization
455 (or (and (boundp 'gnus-local-organization)
456 (stringp gnus-local-organization)
457 gnus-local-organization)
458 (getenv "ORGANIZATION")
460 "*String to be used as an Organization header.
461 If t, use `message-user-organization-file'."
462 :group 'message-headers
463 :type '(choice string
464 (const :tag "consult file" t)))
467 (defcustom message-user-organization-file "/usr/lib/news/organization"
468 "*Local news organization file."
470 :link '(custom-manual "(message)News Headers")
471 :group 'message-headers)
473 (defcustom message-make-forward-subject-function
474 #'message-forward-subject-name-subject
475 "*List of functions called to generate subject headers for forwarded messages.
476 The subject generated by the previous function is passed into each
479 The provided functions are:
481 * `message-forward-subject-author-subject' Source of article (author or
482 newsgroup), in brackets followed by the subject
483 * `message-forward-subject-name-subject' Source of article (name of author
484 or newsgroup), in brackets followed by the subject
485 * `message-forward-subject-fwd' Subject of article with 'Fwd:' prepended
487 :group 'message-forwarding
488 :link '(custom-manual "(message)Forwarding")
489 :type '(radio (function-item message-forward-subject-author-subject)
490 (function-item message-forward-subject-fwd)
491 (function-item message-forward-subject-name-subject)
492 (repeat :tag "List of functions" function)))
494 (defcustom message-forward-as-mime t
495 "*Non-nil means forward messages as an inline/rfc822 MIME section.
496 Otherwise, directly inline the old message in the forwarded message."
498 :group 'message-forwarding
499 :link '(custom-manual "(message)Forwarding")
502 (defcustom message-forward-show-mml 'best
503 "*Non-nil means show forwarded messages as MML (decoded from MIME).
504 Otherwise, forwarded messages are unchanged.
505 Can also be the symbol `best' to indicate that MML should be
506 used, except when it is a bad idea to use MML. One example where
507 it is a bad idea is when forwarding a signed or encrypted
508 message, because converting MIME to MML would invalidate the
511 :group 'message-forwarding
512 :type '(choice (const :tag "use MML" t)
513 (const :tag "don't use MML " nil)
514 (const :tag "use MML when appropriate" best)))
516 (defcustom message-forward-before-signature t
517 "*Non-nil means put forwarded message before signature, else after."
518 :group 'message-forwarding
521 (defcustom message-wash-forwarded-subjects nil
522 "*Non-nil means try to remove as much cruft as possible from the subject.
523 Done before generating the new subject of a forward."
524 :group 'message-forwarding
525 :link '(custom-manual "(message)Forwarding")
528 (defcustom message-ignored-resent-headers "^Return-receipt\\|^X-Gnus\\|^Gnus-Warning:\\|^>?From "
529 "*All headers that match this regexp will be deleted when resending a message."
530 :group 'message-interface
531 :link '(custom-manual "(message)Resending")
532 :type '(repeat :value-to-internal (lambda (widget value)
533 (custom-split-regexp-maybe value))
534 :match (lambda (widget value)
536 (widget-editable-list-match widget value)))
539 (defcustom message-forward-ignored-headers "^Content-Transfer-Encoding:\\|^X-Gnus"
540 "*All headers that match this regexp will be deleted when forwarding a message."
542 :group 'message-forwarding
543 :type '(repeat :value-to-internal (lambda (widget value)
544 (custom-split-regexp-maybe value))
545 :match (lambda (widget value)
547 (widget-editable-list-match widget value)))
550 (defcustom message-ignored-cited-headers "."
551 "*Delete these headers from the messages you yank."
552 :group 'message-insertion
553 :link '(custom-manual "(message)Insertion Variables")
556 (defcustom message-cite-prefix-regexp
557 (if (string-match "[[:digit:]]" "1") ;; support POSIX?
558 "\\([ \t]*[-_.[:word:]]+>+\\|[ \t]*[]>|}+]\\)+"
559 ;; ?-, ?_ or ?. MUST NOT be in syntax entry w.
560 (let ((old-table (syntax-table))
561 non-word-constituents)
562 (set-syntax-table text-mode-syntax-table)
563 (setq non-word-constituents
565 (if (string-match "\\w" "-") "" "-")
566 (if (string-match "\\w" "_") "" "_")
567 (if (string-match "\\w" ".") "" ".")))
568 (set-syntax-table old-table)
569 (if (equal non-word-constituents "")
570 "\\([ \t]*\\(\\w\\)+>+\\|[ \t]*[]>|}+]\\)+"
571 (concat "\\([ \t]*\\(\\w\\|["
572 non-word-constituents
573 "]\\)+>+\\|[ \t]*[]>|}+]\\)+"))))
574 "*Regexp matching the longest possible citation prefix on a line."
576 :group 'message-insertion
577 :link '(custom-manual "(message)Insertion Variables")
580 (defcustom message-cancel-message "I am canceling my own article.\n"
581 "Message to be inserted in the cancel message."
582 :group 'message-interface
583 :link '(custom-manual "(message)Canceling News")
586 ;; Useful to set in site-init.el
588 (defcustom message-send-mail-function 'message-send-mail-with-sendmail
589 "Function to call to send the current buffer as mail.
590 The headers should be delimited by a line whose contents match the
591 variable `mail-header-separator'.
593 Valid values include `message-send-mail-with-sendmail' (the default),
594 `message-send-mail-with-mh', `message-send-mail-with-qmail',
595 `message-smtpmail-send-it', `smtpmail-send-it' and `feedmail-send-it'.
597 See also `send-mail-function'."
598 :type '(radio (function-item message-send-mail-with-sendmail)
599 (function-item message-send-mail-with-mh)
600 (function-item message-send-mail-with-qmail)
601 (function-item message-smtpmail-send-it)
602 (function-item smtpmail-send-it)
603 (function-item feedmail-send-it)
604 (function :tag "Other"))
605 :group 'message-sending
606 :link '(custom-manual "(message)Mail Variables")
607 :group 'message-mail)
609 (defcustom message-send-news-function 'message-send-news
610 "Function to call to send the current buffer as news.
611 The headers should be delimited by a line whose contents match the
612 variable `mail-header-separator'."
613 :group 'message-sending
615 :link '(custom-manual "(message)News Variables")
618 (defcustom message-reply-to-function nil
619 "If non-nil, function that should return a list of headers.
620 This function should pick out addresses from the To, Cc, and From headers
621 and respond with new To and Cc headers."
622 :group 'message-interface
623 :link '(custom-manual "(message)Reply")
624 :type '(choice function (const nil)))
626 (defcustom message-wide-reply-to-function nil
627 "If non-nil, function that should return a list of headers.
628 This function should pick out addresses from the To, Cc, and From headers
629 and respond with new To and Cc headers."
630 :group 'message-interface
631 :link '(custom-manual "(message)Wide Reply")
632 :type '(choice function (const nil)))
634 (defcustom message-followup-to-function nil
635 "If non-nil, function that should return a list of headers.
636 This function should pick out addresses from the To, Cc, and From headers
637 and respond with new To and Cc headers."
638 :group 'message-interface
639 :link '(custom-manual "(message)Followup")
640 :type '(choice function (const nil)))
642 (defcustom message-use-followup-to 'ask
643 "*Specifies what to do with Followup-To header.
644 If nil, always ignore the header. If it is t, use its value, but
645 query before using the \"poster\" value. If it is the symbol `ask',
646 always query the user whether to use the value. If it is the symbol
647 `use', always use the value."
648 :group 'message-interface
649 :link '(custom-manual "(message)Followup")
650 :type '(choice (const :tag "ignore" nil)
651 (const :tag "use & query" t)
655 (defcustom message-use-mail-followup-to 'use
656 "*Specifies what to do with Mail-Followup-To header.
657 If nil, always ignore the header. If it is the symbol `ask', always
658 query the user whether to use the value. If it is the symbol `use',
659 always use the value."
661 :group 'message-interface
662 :link '(custom-manual "(message)Mailing Lists")
663 :type '(choice (const :tag "ignore" nil)
667 (defcustom message-subscribed-address-functions nil
668 "*Specifies functions for determining list subscription.
669 If nil, do not attempt to determine list subscription with functions.
670 If non-nil, this variable contains a list of functions which return
671 regular expressions to match lists. These functions can be used in
672 conjunction with `message-subscribed-regexps' and
673 `message-subscribed-addresses'."
675 :group 'message-interface
676 :link '(custom-manual "(message)Mailing Lists")
677 :type '(repeat sexp))
679 (defcustom message-subscribed-address-file nil
680 "*A file containing addresses the user is subscribed to.
681 If nil, do not look at any files to determine list subscriptions. If
682 non-nil, each line of this file should be a mailing list address."
684 :group 'message-interface
685 :link '(custom-manual "(message)Mailing Lists")
686 :type '(radio file (const nil)))
688 (defcustom message-subscribed-addresses nil
689 "*Specifies a list of addresses the user is subscribed to.
690 If nil, do not use any predefined list subscriptions. This list of
691 addresses can be used in conjunction with
692 `message-subscribed-address-functions' and `message-subscribed-regexps'."
694 :group 'message-interface
695 :link '(custom-manual "(message)Mailing Lists")
696 :type '(repeat string))
698 (defcustom message-subscribed-regexps nil
699 "*Specifies a list of addresses the user is subscribed to.
700 If nil, do not use any predefined list subscriptions. This list of
701 regular expressions can be used in conjunction with
702 `message-subscribed-address-functions' and `message-subscribed-addresses'."
704 :group 'message-interface
705 :link '(custom-manual "(message)Mailing Lists")
706 :type '(repeat regexp))
708 (defcustom message-allow-no-recipients 'ask
709 "Specifies what to do when there are no recipients other than Gcc/Fcc.
710 If it is the symbol `always', the posting is allowed. If it is the
711 symbol `never', the posting is not allowed. If it is the symbol
712 `ask', you are prompted."
714 :group 'message-interface
715 :link '(custom-manual "(message)Message Headers")
716 :type '(choice (const always)
720 (defcustom message-sendmail-f-is-evil nil
721 "*Non-nil means don't add \"-f username\" to the sendmail command line.
722 Doing so would be even more evil than leaving it out."
723 :group 'message-sending
724 :link '(custom-manual "(message)Mail Variables")
727 (defcustom message-sendmail-envelope-from nil
728 "*Envelope-from when sending mail with sendmail.
729 If this is nil, use `user-mail-address'. If it is the symbol
730 `header', use the From: header of the message."
732 :type '(choice (string :tag "From name")
733 (const :tag "Use From: header from message" header)
734 (const :tag "Use `user-mail-address'" nil))
735 :link '(custom-manual "(message)Mail Variables")
736 :group 'message-sending)
738 ;; qmail-related stuff
739 (defcustom message-qmail-inject-program "/var/qmail/bin/qmail-inject"
740 "Location of the qmail-inject program."
741 :group 'message-sending
742 :link '(custom-manual "(message)Mail Variables")
745 (defcustom message-qmail-inject-args nil
746 "Arguments passed to qmail-inject programs.
747 This should be a list of strings, one string for each argument. It
748 may also be a function.
750 For e.g., if you wish to set the envelope sender address so that bounces
751 go to the right place or to deal with listserv's usage of that address, you
752 might set this variable to '(\"-f\" \"you@some.where\")."
753 :group 'message-sending
754 :link '(custom-manual "(message)Mail Variables")
755 :type '(choice (function)
758 (defvar message-cater-to-broken-inn t
759 "Non-nil means Gnus should not fold the `References' header.
760 Folding `References' makes ancient versions of INN create incorrect
764 (defvar gnus-post-method)
765 (defvar gnus-select-method))
766 (defcustom message-post-method
767 (cond ((and (boundp 'gnus-post-method)
768 (listp gnus-post-method)
771 ((boundp 'gnus-select-method)
774 "*Method used to post news.
775 Note that when posting from inside Gnus, for instance, this
776 variable isn't used."
778 :group 'message-sending
779 ;; This should be the `gnus-select-method' widget, but that might
780 ;; create a dependence to `gnus.el'.
783 ;; FIXME: This should be a temporary workaround until someone implements a
784 ;; proper solution. If a crash happens while replying, the auto-save file
785 ;; will *not* have a `References:' header if `message-generate-headers-first'
786 ;; is nil. See: http://article.gmane.org/gmane.emacs.gnus.general/51138
787 (defcustom message-generate-headers-first '(references)
788 "Which headers should be generated before starting to compose a message.
789 If t, generate all required headers. This can also be a list of headers to
790 generate. The variables `message-required-news-headers' and
791 `message-required-mail-headers' specify which headers to generate.
793 Note that the variable `message-deletable-headers' specifies headers which
794 are to be deleted and then re-generated before sending, so this variable
795 will not have a visible effect for those headers."
796 :group 'message-headers
797 :link '(custom-manual "(message)Message Headers")
798 :type '(choice (const :tag "None" nil)
799 (const :tag "References" '(references))
801 (repeat (sexp :tag "Header"))))
803 (defcustom message-setup-hook nil
804 "Normal hook, run each time a new outgoing message is initialized.
805 The function `message-setup' runs this hook."
806 :group 'message-various
807 :link '(custom-manual "(message)Various Message Variables")
810 (defcustom message-cancel-hook nil
811 "Hook run when cancelling articles."
812 :group 'message-various
813 :link '(custom-manual "(message)Various Message Variables")
816 (defcustom message-signature-setup-hook nil
817 "Normal hook, run each time a new outgoing message is initialized.
818 It is run after the headers have been inserted and before
819 the signature is inserted."
820 :group 'message-various
821 :link '(custom-manual "(message)Various Message Variables")
824 (defcustom message-mode-hook nil
825 "Hook run in message mode buffers."
826 :group 'message-various
829 (defcustom message-header-hook nil
830 "Hook run in a message mode buffer narrowed to the headers."
831 :group 'message-various
834 (defcustom message-header-setup-hook nil
835 "Hook called narrowed to the headers when setting up a message buffer."
836 :group 'message-various
837 :link '(custom-manual "(message)Various Message Variables")
840 (defcustom message-minibuffer-local-map
841 (let ((map (make-sparse-keymap 'message-minibuffer-local-map)))
842 (set-keymap-parent map minibuffer-local-map)
844 "Keymap for `message-read-from-minibuffer'."
846 :group 'message-various)
849 (defcustom message-citation-line-function 'message-insert-citation-line
850 "*Function called to insert the \"Whomever writes:\" line.
852 Note that Gnus provides a feature where the reader can click on
853 `writes:' to hide the cited text. If you change this line too much,
854 people who read your message will have to change their Gnus
855 configuration. See the variable `gnus-cite-attribution-suffix'."
857 :link '(custom-manual "(message)Insertion Variables")
858 :group 'message-insertion)
861 (defcustom message-yank-prefix "> "
862 "*Prefix inserted on the lines of yanked messages.
863 Fix `message-cite-prefix-regexp' if it is set to an abnormal value.
864 See also `message-yank-cited-prefix'."
866 :link '(custom-manual "(message)Insertion Variables")
867 :group 'message-insertion)
869 (defcustom message-yank-cited-prefix ">"
870 "*Prefix inserted on cited or empty lines of yanked messages.
871 Fix `message-cite-prefix-regexp' if it is set to an abnormal value.
872 See also `message-yank-prefix'."
875 :link '(custom-manual "(message)Insertion Variables")
876 :group 'message-insertion)
878 (defcustom message-indentation-spaces 3
879 "*Number of spaces to insert at the beginning of each cited line.
880 Used by `message-yank-original' via `message-yank-cite'."
881 :group 'message-insertion
882 :link '(custom-manual "(message)Insertion Variables")
886 (defcustom message-cite-function 'message-cite-original
887 "*Function for citing an original message.
888 Predefined functions include `message-cite-original' and
889 `message-cite-original-without-signature'.
890 Note that `message-cite-original' uses `mail-citation-hook' if that is non-nil."
891 :type '(radio (function-item message-cite-original)
892 (function-item message-cite-original-without-signature)
893 (function-item sc-cite-original)
894 (function :tag "Other"))
895 :link '(custom-manual "(message)Insertion Variables")
896 :group 'message-insertion)
899 (defcustom message-indent-citation-function 'message-indent-citation
900 "*Function for modifying a citation just inserted in the mail buffer.
901 This can also be a list of functions. Each function can find the
902 citation between (point) and (mark t). And each function should leave
903 point and mark around the citation text as modified."
905 :link '(custom-manual "(message)Insertion Variables")
906 :group 'message-insertion)
909 (defcustom message-signature t
910 "*String to be inserted at the end of the message buffer.
911 If t, the `message-signature-file' file will be inserted instead.
912 If a function, the result from the function will be used instead.
913 If a form, the result from the form will be used instead."
915 :link '(custom-manual "(message)Insertion Variables")
916 :group 'message-insertion)
919 (defcustom message-signature-file "~/.signature"
920 "*Name of file containing the text inserted at end of message buffer.
921 Ignored if the named file doesn't exist.
922 If nil, don't insert a signature."
923 :type '(choice file (const :tags "None" nil))
924 :link '(custom-manual "(message)Insertion Variables")
925 :group 'message-insertion)
928 (defcustom message-signature-insert-empty-line t
929 "*If non-nil, insert an empty line before the signature separator."
932 :link '(custom-manual "(message)Insertion Variables")
933 :group 'message-insertion)
935 (defcustom message-distribution-function nil
936 "*Function called to return a Distribution header."
938 :group 'message-headers
939 :link '(custom-manual "(message)News Headers")
940 :type '(choice function (const nil)))
942 (defcustom message-expires 14
943 "Number of days before your article expires."
945 :group 'message-headers
946 :link '(custom-manual "(message)News Headers")
949 (defcustom message-user-path nil
950 "If nil, use the NNTP server name in the Path header.
951 If stringp, use this; if non-nil, use no host name (user name only)."
953 :group 'message-headers
954 :link '(custom-manual "(message)News Headers")
955 :type '(choice (const :tag "nntp" nil)
957 (sexp :tag "none" :format "%t" t)))
959 (defvar message-reply-buffer nil)
960 (defvar message-reply-headers nil
961 "The headers of the current replied article.
962 It is a vector of the following headers:
963 \[number subject from date id references chars lines xref extra].")
964 (defvar message-newsreader nil)
965 (defvar message-mailer nil)
966 (defvar message-sent-message-via nil)
967 (defvar message-checksum nil)
968 (defvar message-send-actions nil
969 "A list of actions to be performed upon successful sending of a message.")
970 (defvar message-exit-actions nil
971 "A list of actions to be performed upon exiting after sending a message.")
972 (defvar message-kill-actions nil
973 "A list of actions to be performed before killing a message buffer.")
974 (defvar message-postpone-actions nil
975 "A list of actions to be performed after postponing a message.")
977 (define-widget 'message-header-lines 'text
978 "All header lines must be LFD terminated."
979 :format "%{%t%}:%n%v"
981 :error "All header lines must be newline terminated")
983 (defcustom message-default-headers ""
984 "*A string containing header lines to be inserted in outgoing messages.
985 It is inserted before you edit the message, so you can edit or delete
987 :group 'message-headers
988 :link '(custom-manual "(message)Message Headers")
989 :type 'message-header-lines)
991 (defcustom message-default-mail-headers ""
992 "*A string of header lines to be inserted in outgoing mails."
993 :group 'message-headers
995 :link '(custom-manual "(message)Mail Headers")
996 :type 'message-header-lines)
998 (defcustom message-default-news-headers ""
999 "*A string of header lines to be inserted in outgoing news articles."
1000 :group 'message-headers
1001 :group 'message-news
1002 :link '(custom-manual "(message)News Headers")
1003 :type 'message-header-lines)
1005 ;; Note: could use /usr/ucb/mail instead of sendmail;
1006 ;; options -t, and -v if not interactive.
1007 (defcustom message-mailer-swallows-blank-line
1008 (if (and (string-match "sparc-sun-sunos\\(\\'\\|[^5]\\)"
1009 system-configuration)
1010 (file-readable-p "/etc/sendmail.cf")
1011 (let ((buffer (get-buffer-create " *temp*")))
1015 (insert-file-contents "/etc/sendmail.cf")
1016 (goto-char (point-min))
1017 (let ((case-fold-search nil))
1018 (re-search-forward "^OR\\>" nil t)))
1019 (kill-buffer buffer))))
1020 ;; According to RFC822, "The field-name must be composed of printable
1021 ;; ASCII characters (i. e., characters that have decimal values between
1022 ;; 33 and 126, except colon)", i. e., any chars except ctl chars,
1024 '(looking-at "[ \t]\\|[][!\"#$%&'()*+,-./0-9;<=>?@A-Z\\\\^_`a-z{|}~]+:"))
1025 "*Set this non-nil if the system's mailer runs the header and body together.
1026 \(This problem exists on Sunos 4 when sendmail is run in remote mode.)
1027 The value should be an expression to test whether the problem will
1029 :group 'message-sending
1030 :link '(custom-manual "(message)Mail Variables")
1034 (define-mail-user-agent 'message-user-agent
1035 'message-mail 'message-send-and-exit
1036 'message-kill-buffer 'message-send-hook)
1038 (defvar message-mh-deletable-headers '(Message-ID Date Lines Sender)
1039 "If non-nil, delete the deletable headers before feeding to mh.")
1041 (defvar message-send-method-alist
1042 '((news message-news-p message-send-via-news)
1043 (mail message-mail-p message-send-via-mail))
1044 "Alist of ways to send outgoing messages.
1045 Each element has the form
1047 \(TYPE PREDICATE FUNCTION)
1049 where TYPE is a symbol that names the method; PREDICATE is a function
1050 called without any parameters to determine whether the message is
1051 a message of type TYPE; and FUNCTION is a function to be called if
1052 PREDICATE returns non-nil. FUNCTION is called with one parameter --
1055 (defcustom message-mail-alias-type 'abbrev
1056 "*What alias expansion type to use in Message buffers.
1057 The default is `abbrev', which uses mailabbrev. nil switches
1060 :link '(custom-manual "(message)Mail Aliases")
1061 :type '(choice (const :tag "Use Mailabbrev" abbrev)
1062 (const :tag "No expansion" nil)))
1064 (defcustom message-auto-save-directory
1065 (file-name-as-directory (nnheader-concat message-directory "drafts"))
1066 "*Directory where Message auto-saves buffers if Gnus isn't running.
1067 If nil, Message won't auto-save."
1068 :group 'message-buffers
1069 :link '(custom-manual "(message)Various Message Variables")
1070 :type '(choice directory (const :tag "Don't auto-save" nil)))
1072 (defcustom message-default-charset
1073 (and (not (mm-multibyte-p)) 'iso-8859-1)
1074 "Default charset used in non-MULE Emacsen.
1075 If nil, you might be asked to input the charset."
1078 :link '(custom-manual "(message)Various Message Variables")
1081 (defcustom message-dont-reply-to-names
1082 (and (boundp 'rmail-dont-reply-to-names) rmail-dont-reply-to-names)
1083 "*A regexp specifying addresses to prune when doing wide replies.
1084 A value of nil means exclude your own user name only."
1087 :link '(custom-manual "(message)Wide Reply")
1088 :type '(choice (const :tag "Yourself" nil)
1091 (defvar message-shoot-gnksa-feet nil
1092 "*A list of GNKSA feet you are allowed to shoot.
1093 Gnus gives you all the opportunity you could possibly want for
1094 shooting yourself in the foot. Also, Gnus allows you to shoot the
1095 feet of Good Net-Keeping Seal of Approval. The following are foot
1097 `empty-article' Allow you to post an empty article;
1098 `quoted-text-only' Allow you to post quoted text only;
1099 `multiple-copies' Allow you to post multiple copies;
1100 `cancel-messages' Allow you to cancel or supersede messages from
1101 your other email addresses.")
1103 (defsubst message-gnksa-enable-p (feature)
1104 (or (not (listp message-shoot-gnksa-feet))
1105 (memq feature message-shoot-gnksa-feet)))
1107 (defcustom message-hidden-headers nil
1108 "Regexp of headers to be hidden when composing new messages.
1109 This can also be a list of regexps to match headers. Or a list
1110 starting with `not' and followed by regexps."
1113 :link '(custom-manual "(message)Message Headers")
1114 :type '(repeat regexp))
1116 ;;; Internal variables.
1117 ;;; Well, not really internal.
1119 (defvar message-mode-syntax-table
1120 (let ((table (copy-syntax-table text-mode-syntax-table)))
1121 (modify-syntax-entry ?% ". " table)
1122 (modify-syntax-entry ?> ". " table)
1123 (modify-syntax-entry ?< ". " table)
1125 "Syntax table used while in Message mode.")
1127 (defface message-header-to-face
1130 (:foreground "green2" :bold t))
1133 (:foreground "MidnightBlue" :bold t))
1135 (:bold t :italic t)))
1136 "Face used for displaying From headers."
1137 :group 'message-faces)
1139 (defface message-header-cc-face
1142 (:foreground "green4" :bold t))
1145 (:foreground "MidnightBlue"))
1148 "Face used for displaying Cc headers."
1149 :group 'message-faces)
1151 (defface message-header-subject-face
1154 (:foreground "green3"))
1157 (:foreground "navy blue" :bold t))
1160 "Face used for displaying subject headers."
1161 :group 'message-faces)
1163 (defface message-header-newsgroups-face
1166 (:foreground "yellow" :bold t :italic t))
1169 (:foreground "blue4" :bold t :italic t))
1171 (:bold t :italic t)))
1172 "Face used for displaying newsgroups headers."
1173 :group 'message-faces)
1175 (defface message-header-other-face
1178 (:foreground "#b00000"))
1181 (:foreground "steel blue"))
1183 (:bold t :italic t)))
1184 "Face used for displaying newsgroups headers."
1185 :group 'message-faces)
1187 (defface message-header-name-face
1190 (:foreground "DarkGreen"))
1193 (:foreground "cornflower blue"))
1196 "Face used for displaying header names."
1197 :group 'message-faces)
1199 (defface message-header-xheader-face
1202 (:foreground "blue"))
1205 (:foreground "blue"))
1208 "Face used for displaying X-Header headers."
1209 :group 'message-faces)
1211 (defface message-separator-face
1214 (:foreground "blue3"))
1217 (:foreground "brown"))
1220 "Face used for displaying the separator."
1221 :group 'message-faces)
1223 (defface message-cited-text-face
1226 (:foreground "red"))
1229 (:foreground "red"))
1232 "Face used for displaying cited text names."
1233 :group 'message-faces)
1235 (defface message-mml-face
1238 (:foreground "ForestGreen"))
1241 (:foreground "ForestGreen"))
1244 "Face used for displaying MML."
1245 :group 'message-faces)
1247 (defun message-font-lock-make-header-matcher (regexp)
1250 (let ((start (point)))
1253 (goto-char (point-min))
1254 (if (re-search-forward
1255 (concat "^" (regexp-quote mail-header-separator) "$")
1257 (setq limit (min limit (match-beginning 0))))
1259 (and (< start limit)
1260 (re-search-forward ,regexp limit t))))))
1261 (if (featurep 'bytecomp)
1265 (defvar message-font-lock-keywords
1266 (let ((content "[ \t]*\\(.+\\(\n[ \t].*\\)*\\)\n?"))
1267 `((,(message-font-lock-make-header-matcher
1268 (concat "^\\([Tt]o:\\)" content))
1269 (1 'message-header-name-face)
1270 (2 'message-header-to-face nil t))
1271 (,(message-font-lock-make-header-matcher
1272 (concat "^\\(^[GBF]?[Cc][Cc]:\\|^[Rr]eply-[Tt]o:\\)" content))
1273 (1 'message-header-name-face)
1274 (2 'message-header-cc-face nil t))
1275 (,(message-font-lock-make-header-matcher
1276 (concat "^\\([Ss]ubject:\\)" content))
1277 (1 'message-header-name-face)
1278 (2 'message-header-subject-face nil t))
1279 (,(message-font-lock-make-header-matcher
1280 (concat "^\\([Nn]ewsgroups:\\|Followup-[Tt]o:\\)" content))
1281 (1 'message-header-name-face)
1282 (2 'message-header-newsgroups-face nil t))
1283 (,(message-font-lock-make-header-matcher
1284 (concat "^\\([A-Z][^: \n\t]+:\\)" content))
1285 (1 'message-header-name-face)
1286 (2 'message-header-other-face nil t))
1287 (,(message-font-lock-make-header-matcher
1288 (concat "^\\(X-[A-Za-z0-9-]+:\\|In-Reply-To:\\)" content))
1289 (1 'message-header-name-face)
1290 (2 'message-header-name-face))
1291 ,@(if (and mail-header-separator
1292 (not (equal mail-header-separator "")))
1293 `((,(concat "^\\(" (regexp-quote mail-header-separator) "\\)$")
1294 1 'message-separator-face))
1297 (re-search-forward (concat "^\\("
1298 message-cite-prefix-regexp
1301 (0 'message-cited-text-face))
1302 ("<#/?\\(multipart\\|part\\|external\\|mml\\|secure\\)[^>]*>"
1303 (0 'message-mml-face))))
1304 "Additional expressions to highlight in Message mode.")
1307 ;; XEmacs does it like this. For Emacs, we have to set the
1308 ;; `font-lock-defaults' buffer-local variable.
1309 (put 'message-mode 'font-lock-defaults '(message-font-lock-keywords t))
1311 (defvar message-face-alist
1312 '((bold . bold-region)
1313 (underline . underline-region)
1314 (default . (lambda (b e)
1316 (ununderline-region b e))))
1317 "Alist of mail and news faces for facemenu.
1318 The cdr of each entry is a function for applying the face to a region.")
1320 (defcustom message-send-hook nil
1321 "Hook run before sending messages.
1322 This hook is run quite early when sending."
1323 :group 'message-various
1324 :options '(ispell-message)
1325 :link '(custom-manual "(message)Various Message Variables")
1328 (defcustom message-send-mail-hook nil
1329 "Hook run before sending mail messages.
1330 This hook is run very late -- just before the message is sent as
1332 :group 'message-various
1333 :link '(custom-manual "(message)Various Message Variables")
1336 (defcustom message-send-news-hook nil
1337 "Hook run before sending news messages.
1338 This hook is run very late -- just before the message is sent as
1340 :group 'message-various
1341 :link '(custom-manual "(message)Various Message Variables")
1344 (defcustom message-sent-hook nil
1345 "Hook run after sending messages."
1346 :group 'message-various
1349 (defvar message-send-coding-system 'binary
1350 "Coding system to encode outgoing mail.")
1352 (defvar message-draft-coding-system
1353 mm-auto-save-coding-system
1354 "*Coding system to compose mail.
1355 If you'd like to make it possible to share draft files between XEmacs
1356 and Emacs, you may use `iso-2022-7bit' for this value at your own risk.
1357 Note that the coding-system `iso-2022-7bit' isn't suitable to all data.")
1359 (defcustom message-send-mail-partially-limit 1000000
1360 "The limitation of messages sent as message/partial.
1361 The lower bound of message size in characters, beyond which the message
1362 should be sent in several parts. If it is nil, the size is unlimited."
1364 :group 'message-buffers
1365 :link '(custom-manual "(message)Mail Variables")
1366 :type '(choice (const :tag "unlimited" nil)
1369 (defcustom message-alternative-emails nil
1370 "A regexp to match the alternative email addresses.
1371 The first matched address (not primary one) is used in the From field."
1372 :group 'message-headers
1373 :link '(custom-manual "(message)Message Headers")
1374 :type '(choice (const :tag "Always use primary" nil)
1377 (defcustom message-hierarchical-addresses nil
1378 "A list of hierarchical mail address definitions.
1380 Inside each entry, the first address is the \"top\" address, and
1381 subsequent addresses are subaddresses; this is used to indicate that
1382 mail sent to the first address will automatically be delivered to the
1383 subaddresses. So if the first address appears in the recipient list
1384 for a message, the subaddresses will be removed (if present) before
1385 the mail is sent. All addresses in this structure should be
1388 :group 'message-headers
1389 :type '(repeat (repeat string)))
1391 (defcustom message-mail-user-agent nil
1392 "Like `mail-user-agent'.
1393 Except if it is nil, use Gnus native MUA; if it is t, use
1396 :type '(radio (const :tag "Gnus native"
1399 (const :tag "`mail-user-agent'"
1402 (function-item :tag "Default Emacs mail"
1404 sendmail-user-agent)
1405 (function-item :tag "Emacs interface to MH"
1408 (function :tag "Other"))
1412 (defcustom message-wide-reply-confirm-recipients nil
1413 "Whether to confirm a wide reply to multiple email recipients.
1414 If this variable is nil, don't ask whether to reply to all recipients.
1415 If this variable is non-nil, pose the question \"Reply to all
1416 recipients?\" before a wide reply to multiple recipients. If the user
1417 answers yes, reply to all recipients as usual. If the user answers
1418 no, only reply back to the author."
1420 :group 'message-headers
1421 :link '(custom-manual "(message)Wide Reply")
1424 (defcustom message-user-fqdn nil
1425 "*Domain part of Messsage-Ids."
1427 :group 'message-headers
1428 :link '(custom-manual "(message)News Headers")
1429 :type '(radio (const :format "%v " nil)
1430 (string :format "FQDN: %v")))
1432 (defcustom message-use-idna (and (condition-case nil (require 'idna)
1434 (mm-coding-system-p 'utf-8)
1435 (executable-find idna-program)
1437 "Whether to encode non-ASCII in domain names into ASCII according to IDNA."
1439 :group 'message-headers
1440 :link '(custom-manual "(message)IDNA")
1441 :type '(choice (const :tag "Ask" ask)
1442 (const :tag "Never" nil)
1443 (const :tag "Always" t)))
1445 ;;; Internal variables.
1447 (defvar message-sending-message "Sending...")
1448 (defvar message-buffer-list nil)
1449 (defvar message-this-is-news nil)
1450 (defvar message-this-is-mail nil)
1451 (defvar message-draft-article nil)
1452 (defvar message-mime-part nil)
1453 (defvar message-posting-charset nil)
1454 (defvar message-inserted-headers nil)
1456 ;; Byte-compiler warning
1458 (defvar gnus-active-hashtb)
1459 (defvar gnus-read-active-file))
1461 ;;; Regexp matching the delimiter of messages in UNIX mail format
1462 ;;; (UNIX From lines), minus the initial ^. It should be a copy
1463 ;;; of rmail.el's rmail-unix-mail-delimiter.
1464 (defvar message-unix-mail-delimiter
1465 (let ((time-zone-regexp
1466 (concat "\\([A-Z]?[A-Z]?[A-Z][A-Z]\\( DST\\)?"
1467 "\\|[-+]?[0-9][0-9][0-9][0-9]"
1473 ;; Many things can happen to an RFC 822 mailbox before it is put into
1474 ;; a `From' line. The leading phrase can be stripped, e.g.
1475 ;; `Joe <@w.x:joe@y.z>' -> `<@w.x:joe@y.z>'. The <> can be stripped, e.g.
1476 ;; `<@x.y:joe@y.z>' -> `@x.y:joe@y.z'. Everything starting with a CRLF
1477 ;; can be removed, e.g.
1478 ;; From: joe@y.z (Joe K
1480 ;; can yield `From joe@y.z (Joe K Fri Mar 22 08:11:15 1996', and
1483 ;; can yield `From Joe User Fri Mar 22 08:11:15 1996'.
1484 ;; The mailbox can be removed or be replaced by white space, e.g.
1485 ;; From: "Joe User"{space}{tab}
1487 ;; can yield `From {space}{tab} Fri Mar 22 08:11:15 1996',
1488 ;; where {space} and {tab} represent the Ascii space and tab characters.
1489 ;; We want to match the results of any of these manglings.
1490 ;; The following regexp rejects names whose first characters are
1491 ;; obviously bogus, but after that anything goes.
1492 "\\([^\0-\b\n-\r\^?].*\\)?"
1494 ;; The time the message was sent.
1495 "\\([^\0-\r \^?]+\\) +" ; day of the week
1496 "\\([^\0-\r \^?]+\\) +" ; month
1497 "\\([0-3]?[0-9]\\) +" ; day of month
1498 "\\([0-2][0-9]:[0-5][0-9]\\(:[0-6][0-9]\\)?\\) *" ; time of day
1500 ;; Perhaps a time zone, specified by an abbreviation, or by a
1505 " \\([0-9][0-9]+\\) *"
1507 ;; On some systems the time zone can appear after the year, too.
1511 "\\(remote from .*\\)?"
1514 "Regexp matching the delimiter of messages in UNIX mail format.")
1516 (defvar message-unsent-separator
1517 (concat "^ *---+ +Unsent message follows +---+ *$\\|"
1518 "^ *---+ +Returned message +---+ *$\\|"
1519 "^Start of returned message$\\|"
1520 "^ *---+ +Original message +---+ *$\\|"
1521 "^ *--+ +begin message +--+ *$\\|"
1522 "^ *---+ +Original message follows +---+ *$\\|"
1523 "^ *---+ +Undelivered message follows +---+ *$\\|"
1524 "^|? *---+ +Message text follows: +---+ *|?$")
1525 "A regexp that matches the separator before the text of a failed message.")
1527 (defvar message-header-format-alist
1529 (To . message-fill-address)
1530 (Cc . message-fill-address)
1541 (References . message-shorten-references)
1543 "Alist used for formatting headers.")
1545 (defvar message-options nil
1546 "Some saved answers when sending message.")
1548 (defvar message-send-mail-real-function nil
1549 "Internal send mail function.")
1551 (defvar message-bogus-system-names "^localhost\\."
1552 "The regexp of bogus system names.")
1554 (defcustom message-valid-fqdn-regexp
1555 (concat "[a-z0-9][-.a-z0-9]+\\." ;; [hostname.subdomain.]domain.
1557 "\\([a-z][a-z]" ;; two letter country TDLs
1558 "\\|biz\\|com\\|edu\\|gov\\|int\\|mil\\|net\\|org"
1559 "\\|aero\\|coop\\|info\\|name\\|museum"
1560 "\\|arpa\\|pro\\|uucp\\|bitnet\\|bofh" ;; old style?
1562 "Regular expression that matches a valid FQDN."
1563 ;; see also: gnus-button-valid-fqdn-regexp
1565 :group 'message-headers
1569 (autoload 'idna-to-ascii "idna")
1570 (autoload 'message-setup-toolbar "messagexmas")
1571 (autoload 'mh-new-draft-name "mh-comp")
1572 (autoload 'mh-send-letter "mh-comp")
1573 (autoload 'gnus-point-at-eol "gnus-util")
1574 (autoload 'gnus-point-at-bol "gnus-util")
1575 (autoload 'gnus-output-to-rmail "gnus-util")
1576 (autoload 'gnus-output-to-mail "gnus-util")
1577 (autoload 'nndraft-request-associate-buffer "nndraft")
1578 (autoload 'nndraft-request-expire-articles "nndraft")
1579 (autoload 'gnus-open-server "gnus-int")
1580 (autoload 'gnus-request-post "gnus-int")
1581 (autoload 'gnus-alive-p "gnus-util")
1582 (autoload 'gnus-server-string "gnus")
1583 (autoload 'gnus-group-name-charset "gnus-group")
1584 (autoload 'gnus-group-name-decode "gnus-group")
1585 (autoload 'gnus-groups-from-server "gnus")
1586 (autoload 'rmail-output "rmailout")
1587 (autoload 'gnus-delay-article "gnus-delay")
1588 (autoload 'gnus-make-local-hook "gnus-util")
1589 (autoload 'gnus-extract-address-components "gnus-util"))
1594 ;;; Utility functions.
1597 (defmacro message-y-or-n-p (question show &rest text)
1598 "Ask QUESTION, displaying remaining args in a temporary buffer if SHOW."
1599 `(message-talkative-question 'y-or-n-p ,question ,show ,@text))
1601 (defmacro message-delete-line (&optional n)
1602 "Delete the current line (and the next N lines)."
1603 `(delete-region (progn (beginning-of-line) (point))
1604 (progn (forward-line ,(or n 1)) (point))))
1606 (defun message-mark-active-p ()
1607 "Non-nil means the mark and region are currently active in this buffer."
1610 (defun message-unquote-tokens (elems)
1611 "Remove double quotes (\") from strings in list ELEMS."
1612 (mapcar (lambda (item)
1613 (while (string-match "^\\(.*\\)\"\\(.*\\)$" item)
1614 (setq item (concat (match-string 1 item)
1615 (match-string 2 item))))
1619 (defun message-tokenize-header (header &optional separator)
1620 "Split HEADER into a list of header elements.
1621 SEPARATOR is a string of characters to be used as separators. \",\"
1622 is used by default."
1625 (let ((regexp (format "[%s]+" (or separator ",")))
1627 beg quoted elems paren)
1629 (mm-enable-multibyte)
1630 (setq beg (point-min))
1632 (goto-char (point-min))
1637 (cond ((and (> (point) beg)
1639 (and (looking-at regexp)
1642 (push (buffer-substring beg (point)) elems)
1643 (setq beg (match-end 0)))
1644 ((eq (char-after) ?\")
1645 (setq quoted (not quoted)))
1646 ((and (eq (char-after) ?\()
1649 ((and (eq (char-after) ?\))
1652 (nreverse elems)))))
1654 (defun message-mail-file-mbox-p (file)
1655 "Say whether FILE looks like a Unix mbox file."
1656 (when (and (file-exists-p file)
1657 (file-readable-p file)
1658 (file-regular-p file))
1660 (nnheader-insert-file-contents file)
1661 (goto-char (point-min))
1662 (looking-at message-unix-mail-delimiter))))
1664 (defun message-fetch-field (header &optional not-all)
1665 "The same as `mail-fetch-field', only remove all newlines.
1666 The buffer is expected to be narrowed to just the header of the message;
1667 see `message-narrow-to-headers-or-head'."
1668 (let* ((inhibit-point-motion-hooks t)
1669 (case-fold-search t)
1670 (value (mail-fetch-field header nil (not not-all))))
1672 (while (string-match "\n[\t ]+" value)
1673 (setq value (replace-match " " t t value)))
1674 (set-text-properties 0 (length value) nil value)
1677 (defun message-field-value (header &optional not-all)
1678 "The same as `message-fetch-field', only narrow to the headers first."
1681 (message-narrow-to-headers-or-head)
1682 (message-fetch-field header not-all))))
1684 (defun message-narrow-to-field ()
1685 "Narrow the buffer to the header on the current line."
1691 (if (re-search-forward "^[^ \n\t]" nil t)
1696 (goto-char (point-min)))
1698 (defun message-add-header (&rest headers)
1699 "Add the HEADERS to the message header, skipping those already present."
1702 (unless (string-match "^\\([^:]+\\):[ \t]*[^ \t]" (car headers))
1703 (error "Invalid header `%s'" (car headers)))
1704 (setq hclean (match-string 1 (car headers)))
1706 (message-narrow-to-headers)
1707 (unless (re-search-forward (concat "^" (regexp-quote hclean) ":") nil t)
1708 (goto-char (point-max))
1709 (if (string-match "\n$" (car headers))
1710 (insert (car headers))
1711 (insert (car headers) ?\n)))))
1712 (setq headers (cdr headers))))
1714 (defmacro message-with-reply-buffer (&rest forms)
1715 "Evaluate FORMS in the reply buffer, if it exists."
1716 `(when (and message-reply-buffer
1717 (buffer-name message-reply-buffer))
1719 (set-buffer message-reply-buffer)
1722 (put 'message-with-reply-buffer 'lisp-indent-function 0)
1723 (put 'message-with-reply-buffer 'edebug-form-spec '(body))
1725 (defun message-fetch-reply-field (header)
1726 "Fetch field HEADER from the message we're replying to."
1727 (message-with-reply-buffer
1729 (mail-narrow-to-head)
1730 (message-fetch-field header))))
1732 (defun message-strip-list-identifiers (subject)
1733 "Remove list identifiers in `gnus-list-identifiers' from string SUBJECT."
1734 (require 'gnus-sum) ; for gnus-list-identifiers
1735 (let ((regexp (if (stringp gnus-list-identifiers)
1736 gnus-list-identifiers
1737 (mapconcat 'identity gnus-list-identifiers " *\\|"))))
1738 (if (string-match (concat "\\(\\(\\(Re: +\\)?\\(" regexp
1739 " *\\)\\)+\\(Re: +\\)?\\)") subject)
1740 (concat (substring subject 0 (match-beginning 1))
1741 (or (match-string 3 subject)
1742 (match-string 5 subject))
1747 (defun message-strip-subject-re (subject)
1748 "Remove \"Re:\" from subject lines in string SUBJECT."
1749 (if (string-match message-subject-re-regexp subject)
1750 (substring subject (match-end 0))
1753 ;;; Start of functions adopted from `message-utils.el'.
1755 (defun message-strip-subject-trailing-was (subject)
1756 "Remove trailing \"(was: <old subject>)\" from SUBJECT lines.
1757 Leading \"Re: \" is not stripped by this function. Use the function
1758 `message-strip-subject-re' for this."
1759 (let* ((query message-subject-trailing-was-query)
1764 message-subject-trailing-was-ask-regexp
1765 message-subject-trailing-was-regexp)
1768 (setq new (substring subject 0 (match-beginning 0))))
1769 (if (or (not found) (eq query nil))
1772 (if (message-y-or-n-p
1773 "Strip `(was: <old subject>)' in subject? " t
1775 "Strip `(was: <old subject>)' in subject "
1776 "and use the new one instead?\n\n"
1777 "Current subject is: \""
1779 "New subject would be: \""
1781 "See the variable `message-subject-trailing-was-query' "
1782 "to get rid of this query."
1787 ;;; Suggested by Jonas Steverud @ www.dtek.chalmers.se/~d4jonas/
1790 (defun message-change-subject (new-subject)
1791 "Ask for NEW-SUBJECT header, append (was: <Old Subject>)."
1792 ;; <URL:http://www.landfield.com/usefor/drafts/draft-ietf-usefor-useage--1.02.unpaged>
1795 (read-from-minibuffer "New subject: ")))
1796 (cond ((and (not (or (null new-subject) ; new subject not empty
1797 (zerop (string-width new-subject))
1798 (string-match "^[ \t]*$" new-subject))))
1802 (message-narrow-to-headers)
1803 (message-fetch-field "Subject"))))
1804 (cond ((not old-subject)
1805 (error "No current subject"))
1808 (regexp-quote new-subject)
1810 old-subject)) ; yes, it really is a new subject
1811 ;; delete eventual Re: prefix
1813 (message-strip-subject-re old-subject))
1814 (message-goto-subject)
1815 (message-delete-line)
1816 (insert (concat "Subject: "
1819 old-subject ")\n")))))))))
1822 (defun message-mark-inserted-region (beg end)
1823 "Mark some region in the current article with enclosing tags.
1824 See `message-mark-insert-begin' and `message-mark-insert-end'."
1827 ;; add to the end of the region first, otherwise end would be invalid
1829 (insert message-mark-insert-end)
1831 (insert message-mark-insert-begin)))
1834 (defun message-mark-insert-file (file)
1835 "Insert FILE at point, marking it with enclosing tags.
1836 See `message-mark-insert-begin' and `message-mark-insert-end'."
1837 (interactive "fFile to insert: ")
1838 ;; reverse insertion to get correct result.
1840 (insert message-mark-insert-end)
1842 (insert-file-contents file)
1844 (insert message-mark-insert-begin)))
1847 (defun message-add-archive-header ()
1848 "Insert \"X-No-Archive: Yes\" in the header and a note in the body.
1849 The note can be customized using `message-archive-note'. When called with a
1850 prefix argument, ask for a text to insert. If you don't want the note in the
1851 body, set `message-archive-note' to nil."
1853 (if current-prefix-arg
1854 (setq message-archive-note
1855 (read-from-minibuffer "Reason for No-Archive: "
1856 (cons message-archive-note 0))))
1858 (if (message-goto-signature)
1859 (re-search-backward message-signature-separator))
1860 (when message-archive-note
1861 (insert message-archive-note)
1863 (message-add-header message-archive-header)
1864 (message-sort-headers)))
1867 (defun message-cross-post-followup-to-header (target-group)
1868 "Mangles FollowUp-To and Newsgroups header to point to TARGET-GROUP.
1869 With prefix-argument just set Follow-Up, don't cross-post."
1871 (list ; Completion based on Gnus
1872 (completing-read "Followup To: "
1873 (if (boundp 'gnus-newsrc-alist)
1875 nil nil '("poster" . 0)
1876 (if (boundp 'gnus-group-history)
1877 'gnus-group-history))))
1878 (message-remove-header "Follow[Uu]p-[Tt]o" t)
1879 (message-goto-newsgroups)
1881 ;; if we already did a crosspost before, kill old target
1882 (if (and message-cross-post-old-target
1884 (regexp-quote (concat "," message-cross-post-old-target))
1887 ;; unless (followup is to poster or user explicitly asked not
1888 ;; to cross-post, or target-group is already in Newsgroups)
1889 ;; add target-group to Newsgroups line.
1891 ;; def: cross-post, req:no
1892 (and message-cross-post-default (not current-prefix-arg))
1893 ;; def: no-cross-post, req:yes
1894 (and (not message-cross-post-default) current-prefix-arg))
1895 (not (string-match "poster" target-group))
1896 (not (string-match (regexp-quote target-group)
1897 (message-fetch-field "Newsgroups"))))
1899 (insert (concat "," target-group))))
1900 (end-of-line) ; ensure Followup: comes after Newsgroups:
1901 ;; unless new followup would be identical to Newsgroups line
1902 ;; make a new Followup-To line
1903 (if (not (string-match (concat "^[ \t]*"
1906 (message-fetch-field "Newsgroups")))
1907 (insert (concat "\nFollowup-To: " target-group)))
1908 (setq message-cross-post-old-target target-group))
1911 (defun message-cross-post-insert-note (target-group cross-post in-old
1913 "Insert a in message body note about a set Followup or Crosspost.
1914 If there have been previous notes, delete them. TARGET-GROUP specifies the
1915 group to Followup-To. When CROSS-POST is t, insert note about
1916 crossposting. IN-OLD specifies whether TARGET-GROUP is a member of
1917 OLD-GROUPS. OLD-GROUPS lists the old-groups the posting would have
1918 been made to before the user asked for a Crosspost."
1919 ;; start scanning body for previous uses
1920 (message-goto-signature)
1921 (let ((head (re-search-backward
1922 (concat "^" mail-header-separator)
1923 nil t))) ; just search in body
1924 (message-goto-signature)
1925 (while (re-search-backward
1926 (concat "^" (regexp-quote message-cross-post-note) ".*")
1928 (message-delete-line))
1929 (message-goto-signature)
1930 (while (re-search-backward
1931 (concat "^" (regexp-quote message-followup-to-note) ".*")
1933 (message-delete-line))
1935 (if (message-goto-signature)
1936 (re-search-backward message-signature-separator))
1939 (string-match "^[ \t]*poster[ \t]*$" target-group))
1940 (insert (concat message-followup-to-note target-group "\n"))
1941 (insert (concat message-cross-post-note target-group "\n")))))
1944 (defun message-cross-post-followup-to (target-group)
1945 "Crossposts message and set Followup-To to TARGET-GROUP.
1946 With prefix-argument just set Follow-Up, don't cross-post."
1948 (list ; Completion based on Gnus
1949 (completing-read "Followup To: "
1950 (if (boundp 'gnus-newsrc-alist)
1952 nil nil '("poster" . 0)
1953 (if (boundp 'gnus-group-history)
1954 'gnus-group-history))))
1955 (cond ((not (or (null target-group) ; new subject not empty
1956 (zerop (string-width target-group))
1957 (string-match "^[ \t]*$" target-group)))
1959 (let* ((old-groups (message-fetch-field "Newsgroups"))
1960 (in-old (string-match
1961 (regexp-quote target-group)
1962 (or old-groups ""))))
1963 ;; check whether target exactly matches old Newsgroups
1964 (cond ((not old-groups)
1965 (error "No current newsgroup"))
1969 (regexp-quote target-group)
1972 ;; yes, Newsgroups line must change
1973 (message-cross-post-followup-to-header target-group)
1974 ;; insert note whether we do cross-post or followup-to
1975 (funcall message-cross-post-note-function
1977 (if (or (and message-cross-post-default
1978 (not current-prefix-arg))
1979 (and (not message-cross-post-default)
1980 current-prefix-arg)) t)
1981 in-old old-groups))))))))
1983 ;;; Reduce To: to Cc: or Bcc: header
1986 (defun message-reduce-to-to-cc ()
1987 "Replace contents of To: header with contents of Cc: or Bcc: header."
1990 (save-restriction (message-narrow-to-headers)
1991 (message-fetch-field "cc")))
1993 (if (and (not cc-content)
1996 (message-narrow-to-headers)
1997 (message-fetch-field "bcc"))))
2002 (message-delete-line)
2003 (insert (concat "To: " cc-content "\n"))
2005 (message-narrow-to-headers)
2006 (message-remove-header (if bcc
2010 ;;; End of functions adopted from `message-utils.el'.
2012 (defun message-remove-header (header &optional is-regexp first reverse)
2013 "Remove HEADER in the narrowed buffer.
2014 If IS-REGEXP, HEADER is a regular expression.
2015 If FIRST, only remove the first instance of the header.
2016 Return the number of headers removed."
2017 (goto-char (point-min))
2018 (let ((regexp (if is-regexp header (concat "^" (regexp-quote header) ":")))
2020 (case-fold-search t)
2022 (while (and (not (eobp))
2025 (not (looking-at regexp))
2026 (looking-at regexp))
2033 ;; There might be a continuation header, so we have to search
2034 ;; until we find a new non-continuation line.
2037 (if (re-search-forward "^[^ \t]" nil t)
2038 (goto-char (match-beginning 0))
2041 (if (re-search-forward "^[^ \t]" nil t)
2042 (goto-char (match-beginning 0))
2043 (goto-char (point-max)))))
2046 (defun message-remove-first-header (header)
2047 "Remove the first instance of HEADER if there is more than one."
2049 (regexp (concat "^" (regexp-quote header) ":")))
2051 (goto-char (point-min))
2052 (while (re-search-forward regexp nil t)
2055 (message-remove-header header nil t)
2058 (defun message-narrow-to-headers ()
2059 "Narrow the buffer to the head of the message."
2062 (goto-char (point-min))
2063 (if (re-search-forward
2064 (concat "^" (regexp-quote mail-header-separator) "\n") nil t)
2067 (goto-char (point-min)))
2069 (defun message-narrow-to-head-1 ()
2070 "Like `message-narrow-to-head'. Don't widen."
2072 (goto-char (point-min))
2073 (if (search-forward "\n\n" nil 1)
2076 (goto-char (point-min)))
2078 (defun message-narrow-to-head ()
2079 "Narrow the buffer to the head of the message.
2080 Point is left at the beginning of the narrowed-to region."
2082 (message-narrow-to-head-1))
2084 (defun message-narrow-to-headers-or-head ()
2085 "Narrow the buffer to the head of the message."
2088 (goto-char (point-min))
2091 (concat "^" (regexp-quote mail-header-separator) "\n") nil t)
2092 (match-beginning 0))
2093 ((search-forward "\n\n" nil t)
2097 (goto-char (point-min)))
2099 (defun message-news-p ()
2100 "Say whether the current buffer contains a news message."
2101 (and (not message-this-is-mail)
2102 (or message-this-is-news
2105 (message-narrow-to-headers)
2106 (and (message-fetch-field "newsgroups")
2107 (not (message-fetch-field "posted-to"))))))))
2109 (defun message-mail-p ()
2110 "Say whether the current buffer contains a mail message."
2111 (and (not message-this-is-news)
2112 (or message-this-is-mail
2115 (message-narrow-to-headers)
2116 (or (message-fetch-field "to")
2117 (message-fetch-field "cc")
2118 (message-fetch-field "bcc")))))))
2120 (defun message-subscribed-p ()
2121 "Say whether we need to insert a MFT header."
2122 (or message-subscribed-regexps
2123 message-subscribed-addresses
2124 message-subscribed-address-file
2125 message-subscribed-address-functions))
2127 (defun message-next-header ()
2128 "Go to the beginning of the next header."
2130 (or (eobp) (forward-char 1))
2131 (not (if (re-search-forward "^[^ \t]" nil t)
2133 (goto-char (point-max)))))
2135 (defun message-sort-headers-1 ()
2136 "Sort the buffer as headers using `message-rank' text props."
2137 (goto-char (point-min))
2140 nil 'message-next-header
2142 (message-next-header)
2146 (or (get-text-property (point) 'message-rank)
2149 (defun message-sort-headers ()
2150 "Sort the headers of the current message according to `message-header-format-alist'."
2154 (let ((max (1+ (length message-header-format-alist)))
2156 (message-narrow-to-headers)
2157 (while (re-search-forward "^[^ \n]+:" nil t)
2159 (match-beginning 0) (1+ (match-beginning 0))
2161 (if (setq rank (length (memq (assq (intern (buffer-substring
2163 (1- (match-end 0))))
2164 message-header-format-alist)
2165 message-header-format-alist)))
2168 (message-sort-headers-1))))
2179 (defvar message-mode-map nil)
2181 (unless message-mode-map
2182 (setq message-mode-map (make-keymap))
2183 (set-keymap-parent message-mode-map text-mode-map)
2184 (define-key message-mode-map "\C-c?" 'describe-mode)
2186 (define-key message-mode-map "\C-c\C-f\C-t" 'message-goto-to)
2187 (define-key message-mode-map "\C-c\C-f\C-o" 'message-goto-from)
2188 (define-key message-mode-map "\C-c\C-f\C-b" 'message-goto-bcc)
2189 (define-key message-mode-map "\C-c\C-f\C-w" 'message-goto-fcc)
2190 (define-key message-mode-map "\C-c\C-f\C-c" 'message-goto-cc)
2191 (define-key message-mode-map "\C-c\C-f\C-s" 'message-goto-subject)
2192 (define-key message-mode-map "\C-c\C-f\C-r" 'message-goto-reply-to)
2193 (define-key message-mode-map "\C-c\C-f\C-n" 'message-goto-newsgroups)
2194 (define-key message-mode-map "\C-c\C-f\C-d" 'message-goto-distribution)
2195 (define-key message-mode-map "\C-c\C-f\C-f" 'message-goto-followup-to)
2196 (define-key message-mode-map "\C-c\C-f\C-m" 'message-goto-mail-followup-to)
2197 (define-key message-mode-map "\C-c\C-f\C-k" 'message-goto-keywords)
2198 (define-key message-mode-map "\C-c\C-f\C-u" 'message-goto-summary)
2199 (define-key message-mode-map "\C-c\C-f\C-i"
2200 'message-insert-or-toggle-importance)
2201 (define-key message-mode-map "\C-c\C-f\C-a"
2202 'message-generate-unsubscribed-mail-followup-to)
2204 ;; modify headers (and insert notes in body)
2205 (define-key message-mode-map "\C-c\C-fs" 'message-change-subject)
2207 (define-key message-mode-map "\C-c\C-fx" 'message-cross-post-followup-to)
2208 ;; prefix+message-cross-post-followup-to = same w/o cross-post
2209 (define-key message-mode-map "\C-c\C-ft" 'message-reduce-to-to-cc)
2210 (define-key message-mode-map "\C-c\C-fa" 'message-add-archive-header)
2211 ;; mark inserted text
2212 (define-key message-mode-map "\C-c\M-m" 'message-mark-inserted-region)
2213 (define-key message-mode-map "\C-c\M-f" 'message-mark-insert-file)
2215 (define-key message-mode-map "\C-c\C-b" 'message-goto-body)
2216 (define-key message-mode-map "\C-c\C-i" 'message-goto-signature)
2218 (define-key message-mode-map "\C-c\C-t" 'message-insert-to)
2219 (define-key message-mode-map "\C-c\C-fw" 'message-insert-wide-reply)
2220 (define-key message-mode-map "\C-c\C-n" 'message-insert-newsgroups)
2221 (define-key message-mode-map "\C-c\C-l" 'message-to-list-only)
2223 (define-key message-mode-map "\C-c\C-u" 'message-insert-or-toggle-importance)
2224 (define-key message-mode-map "\C-c\M-n"
2225 'message-insert-disposition-notification-to)
2227 (define-key message-mode-map "\C-c\C-y" 'message-yank-original)
2228 (define-key message-mode-map "\C-c\M-\C-y" 'message-yank-buffer)
2229 (define-key message-mode-map "\C-c\C-q" 'message-fill-yanked-message)
2230 (define-key message-mode-map "\C-c\C-w" 'message-insert-signature)
2231 (define-key message-mode-map "\C-c\M-h" 'message-insert-headers)
2232 (define-key message-mode-map "\C-c\C-r" 'message-caesar-buffer-body)
2233 (define-key message-mode-map "\C-c\C-o" 'message-sort-headers)
2234 (define-key message-mode-map "\C-c\M-r" 'message-rename-buffer)
2236 (define-key message-mode-map "\C-c\C-c" 'message-send-and-exit)
2237 (define-key message-mode-map "\C-c\C-s" 'message-send)
2238 (define-key message-mode-map "\C-c\C-k" 'message-kill-buffer)
2239 (define-key message-mode-map "\C-c\C-d" 'message-dont-send)
2240 (define-key message-mode-map "\C-c\n" 'gnus-delay-article)
2242 (define-key message-mode-map "\C-c\C-e" 'message-elide-region)
2243 (define-key message-mode-map "\C-c\C-v" 'message-delete-not-region)
2244 (define-key message-mode-map "\C-c\C-z" 'message-kill-to-signature)
2245 (define-key message-mode-map "\M-\r" 'message-newline-and-reformat)
2246 ;;(define-key message-mode-map "\M-q" 'message-fill-paragraph)
2247 (define-key message-mode-map [remap split-line] 'message-split-line)
2249 (define-key message-mode-map "\C-c\C-a" 'mml-attach-file)
2251 (define-key message-mode-map "\C-a" 'message-beginning-of-line)
2252 (define-key message-mode-map "\t" 'message-tab)
2253 (define-key message-mode-map "\M-;" 'comment-region))
2256 message-mode-menu message-mode-map "Message Menu."
2258 ["Yank Original" message-yank-original message-reply-buffer]
2259 ["Fill Yanked Message" message-fill-yanked-message t]
2260 ["Insert Signature" message-insert-signature t]
2261 ["Caesar (rot13) Message" message-caesar-buffer-body t]
2262 ["Caesar (rot13) Region" message-caesar-region (message-mark-active-p)]
2263 ["Elide Region" message-elide-region
2264 :active (message-mark-active-p)
2265 ,@(if (featurep 'xemacs) nil
2266 '(:help "Replace text in region with an ellipsis"))]
2267 ["Delete Outside Region" message-delete-not-region
2268 :active (message-mark-active-p)
2269 ,@(if (featurep 'xemacs) nil
2270 '(:help "Delete all quoted text outside region"))]
2271 ["Kill To Signature" message-kill-to-signature t]
2272 ["Newline and Reformat" message-newline-and-reformat t]
2273 ["Rename buffer" message-rename-buffer t]
2274 ["Spellcheck" ispell-message
2275 ,@(if (featurep 'xemacs) '(t)
2276 '(:help "Spellcheck this message"))]
2278 ["Insert Region Marked" message-mark-inserted-region
2279 :active (message-mark-active-p)
2280 ,@(if (featurep 'xemacs) nil
2281 '(:help "Mark region with enclosing tags"))]
2282 ["Insert File Marked..." message-mark-insert-file
2283 ,@(if (featurep 'xemacs) '(t)
2284 '(:help "Insert file at point marked with enclosing tags"))]
2286 ["Send Message" message-send-and-exit
2287 ,@(if (featurep 'xemacs) '(t)
2288 '(:help "Send this message"))]
2289 ["Postpone Message" message-dont-send
2290 ,@(if (featurep 'xemacs) '(t)
2291 '(:help "File this draft message and exit"))]
2292 ["Send at Specific Time..." gnus-delay-article
2293 ,@(if (featurep 'xemacs) '(t)
2294 '(:help "Ask, then arrange to send message at that time"))]
2295 ["Kill Message" message-kill-buffer
2296 ,@(if (featurep 'xemacs) '(t)
2297 '(:help "Delete this message without sending"))]))
2300 message-mode-field-menu message-mode-map ""
2302 ["To" message-goto-to t]
2303 ["From" message-goto-from t]
2304 ["Subject" message-goto-subject t]
2305 ["Change subject..." message-change-subject t]
2306 ["Cc" message-goto-cc t]
2307 ["Bcc" message-goto-bcc t]
2308 ["Fcc" message-goto-fcc t]
2309 ["Reply-To" message-goto-reply-to t]
2310 ["Flag As Important" message-insert-importance-high
2311 ,@(if (featurep 'xemacs) '(t)
2312 '(:help "Mark this message as important"))]
2313 ["Flag As Unimportant" message-insert-importance-low
2314 ,@(if (featurep 'xemacs) '(t)
2315 '(:help "Mark this message as unimportant"))]
2317 message-insert-disposition-notification-to
2318 ,@(if (featurep 'xemacs) '(t)
2319 '(:help "Request a receipt notification"))]
2321 ;; (typical) news stuff
2322 ["Summary" message-goto-summary t]
2323 ["Keywords" message-goto-keywords t]
2324 ["Newsgroups" message-goto-newsgroups t]
2325 ["Fetch Newsgroups" message-insert-newsgroups t]
2326 ["Followup-To" message-goto-followup-to t]
2327 ;; ["Followup-To (with note in body)" message-cross-post-followup-to t]
2328 ["Crosspost / Followup-To..." message-cross-post-followup-to t]
2329 ["Distribution" message-goto-distribution t]
2330 ["X-No-Archive:" message-add-archive-header t ]
2332 ;; (typical) mailing-lists stuff
2333 ["Fetch To" message-insert-to
2334 ,@(if (featurep 'xemacs) '(t)
2335 '(:help "Insert a To header that points to the author."))]
2336 ["Fetch To and Cc" message-insert-wide-reply
2337 ,@(if (featurep 'xemacs) '(t)
2339 "Insert To and Cc headers as if you were doing a wide reply."))]
2341 ["Send to list only" message-to-list-only t]
2342 ["Mail-Followup-To" message-goto-mail-followup-to t]
2343 ["Unsubscribed list post" message-generate-unsubscribed-mail-followup-to
2344 ,@(if (featurep 'xemacs) '(t)
2345 '(:help "Insert a reasonable `Mail-Followup-To:' header."))]
2346 ["Reduce To: to Cc:" message-reduce-to-to-cc t]
2348 ["Sort Headers" message-sort-headers t]
2349 ["Encode non-ASCII domain names" message-idna-to-ascii-rhs t]
2350 ["Goto Body" message-goto-body t]
2351 ["Goto Signature" message-goto-signature t]))
2353 (defvar message-tool-bar-map nil)
2356 (defvar facemenu-add-face-function)
2357 (defvar facemenu-remove-face-function))
2359 ;;; Forbidden properties
2361 ;; We use `after-change-functions' to keep special text properties
2362 ;; that interfer with the normal function of message mode out of the
2365 (defcustom message-strip-special-text-properties t
2366 "Strip special properties from the message buffer.
2368 Emacs has a number of special text properties which can break message
2369 composing in various ways. If this option is set, message will strip
2370 these properties from the message composition buffer. However, some
2371 packages requires these properties to be present in order to work.
2372 If you use one of these packages, turn this option off, and hope the
2373 message composition doesn't break too bad."
2375 :group 'message-various
2376 :link '(custom-manual "(message)Various Message Variables")
2379 (defconst message-forbidden-properties
2380 ;; No reason this should be clutter up customize. We make it a
2381 ;; property list (rather than a list of property symbols), to be
2382 ;; directly useful for `remove-text-properties'.
2383 '(field nil read-only nil invisible nil intangible nil
2384 mouse-face nil modification-hooks nil insert-in-front-hooks nil
2385 insert-behind-hooks nil point-entered nil point-left nil)
2386 ;; Other special properties:
2387 ;; category, face, display: probably doesn't do any harm.
2388 ;; fontified: is used by font-lock.
2389 ;; syntax-table, local-map: I dunno.
2390 ;; We need to add XEmacs names to the list.
2391 "Property list of with properties forbidden in message buffers.
2392 The values of the properties are ignored, only the property names are used.")
2394 (defun message-tamago-not-in-use-p (pos)
2395 "Return t when tamago version 4 is not in use at the cursor position.
2396 Tamago version 4 is a popular input method for writing Japanese text.
2397 It uses the properties `intangible', `invisible', `modification-hooks'
2398 and `read-only' when translating ascii or kana text to kanji text.
2399 These properties are essential to work, so we should never strip them."
2400 (not (and (boundp 'egg-modefull-mode)
2401 (symbol-value 'egg-modefull-mode)
2402 (or (memq (get-text-property pos 'intangible)
2403 '(its-part-1 its-part-2))
2404 (get-text-property pos 'egg-end)
2405 (get-text-property pos 'egg-lang)
2406 (get-text-property pos 'egg-start)))))
2408 (defun message-strip-forbidden-properties (begin end &optional old-length)
2409 "Strip forbidden properties between BEGIN and END, ignoring the third arg.
2410 This function is intended to be called from `after-change-functions'.
2411 See also `message-forbidden-properties'."
2412 (when (and message-strip-special-text-properties
2413 (message-tamago-not-in-use-p begin))
2414 (let ((buffer-read-only nil)
2415 (inhibit-read-only t))
2416 (while (not (= begin end))
2417 (when (not (get-text-property begin 'message-hidden))
2418 (remove-text-properties begin (1+ begin)
2419 message-forbidden-properties))
2423 (define-derived-mode message-mode text-mode "Message"
2424 "Major mode for editing mail and news to be sent.
2425 Like Text Mode but with these additional commands:\\<message-mode-map>
2426 C-c C-s `message-send' (send the message) C-c C-c `message-send-and-exit'
2427 C-c C-d Postpone sending the message C-c C-k Kill the message
2428 C-c C-f move to a header field (and create it if there isn't):
2429 C-c C-f C-t move to To C-c C-f C-s move to Subject
2430 C-c C-f C-c move to Cc C-c C-f C-b move to Bcc
2431 C-c C-f C-w move to Fcc C-c C-f C-r move to Reply-To
2432 C-c C-f C-u move to Summary C-c C-f C-n move to Newsgroups
2433 C-c C-f C-k move to Keywords C-c C-f C-d move to Distribution
2434 C-c C-f C-o move to From (\"Originator\")
2435 C-c C-f C-f move to Followup-To
2436 C-c C-f C-m move to Mail-Followup-To
2437 C-c C-f C-i cycle through Importance values
2438 C-c C-f s change subject and append \"(was: <Old Subject>)\"
2439 C-c C-f x crossposting with FollowUp-To header and note in body
2440 C-c C-f t replace To: header with contents of Cc: or Bcc:
2441 C-c C-f a Insert X-No-Archive: header and a note in the body
2442 C-c C-t `message-insert-to' (add a To header to a news followup)
2443 C-c C-l `message-to-list-only' (removes all but list address in to/cc)
2444 C-c C-n `message-insert-newsgroups' (add a Newsgroup header to a news reply)
2445 C-c C-b `message-goto-body' (move to beginning of message text).
2446 C-c C-i `message-goto-signature' (move to the beginning of the signature).
2447 C-c C-w `message-insert-signature' (insert `message-signature-file' file).
2448 C-c C-y `message-yank-original' (insert current message, if any).
2449 C-c C-q `message-fill-yanked-message' (fill what was yanked).
2450 C-c C-e `message-elide-region' (elide the text between point and mark).
2451 C-c C-v `message-delete-not-region' (remove the text outside the region).
2452 C-c C-z `message-kill-to-signature' (kill the text up to the signature).
2453 C-c C-r `message-caesar-buffer-body' (rot13 the message body).
2454 C-c C-a `mml-attach-file' (attach a file as MIME).
2455 C-c C-u `message-insert-or-toggle-importance' (insert or cycle importance).
2456 C-c M-n `message-insert-disposition-notification-to' (request receipt).
2457 C-c M-m `message-mark-inserted-region' (mark region with enclosing tags).
2458 C-c M-f `message-mark-insert-file' (insert file marked with enclosing tags).
2459 M-RET `message-newline-and-reformat' (break the line and reformat)."
2460 (setq local-abbrev-table text-mode-abbrev-table)
2461 (set (make-local-variable 'message-reply-buffer) nil)
2462 (set (make-local-variable 'message-inserted-headers) nil)
2463 (set (make-local-variable 'message-send-actions) nil)
2464 (set (make-local-variable 'message-exit-actions) nil)
2465 (set (make-local-variable 'message-kill-actions) nil)
2466 (set (make-local-variable 'message-postpone-actions) nil)
2467 (set (make-local-variable 'message-draft-article) nil)
2468 (setq buffer-offer-save t)
2469 (set (make-local-variable 'facemenu-add-face-function)
2471 (let ((face-fun (cdr (assq face message-face-alist))))
2473 (funcall face-fun (point) end)
2474 (error "Face %s not configured for %s mode" face mode-name)))
2476 (set (make-local-variable 'facemenu-remove-face-function) t)
2477 (set (make-local-variable 'message-reply-headers) nil)
2478 (make-local-variable 'message-newsreader)
2479 (make-local-variable 'message-mailer)
2480 (make-local-variable 'message-post-method)
2481 (set (make-local-variable 'message-sent-message-via) nil)
2482 (set (make-local-variable 'message-checksum) nil)
2483 (set (make-local-variable 'message-mime-part) 0)
2484 (message-setup-fill-variables)
2485 ;; Allow using comment commands to add/remove quoting.
2486 ;; (set (make-local-variable 'comment-start) message-yank-prefix)
2487 (when message-yank-prefix
2488 (set (make-local-variable 'comment-start) message-yank-prefix)
2489 (set (make-local-variable 'comment-start-skip)
2490 (concat "^" (regexp-quote message-yank-prefix) "[ \t]*")))
2491 (if (featurep 'xemacs)
2492 (message-setup-toolbar)
2493 (set (make-local-variable 'font-lock-defaults)
2494 '(message-font-lock-keywords t))
2495 (if (boundp 'tool-bar-map)
2496 (set (make-local-variable 'tool-bar-map) (message-tool-bar-map))))
2497 (easy-menu-add message-mode-menu message-mode-map)
2498 (easy-menu-add message-mode-field-menu message-mode-map)
2499 (gnus-make-local-hook 'after-change-functions)
2500 ;; Mmmm... Forbidden properties...
2501 (add-hook 'after-change-functions 'message-strip-forbidden-properties
2503 ;; Allow mail alias things.
2504 (when (eq message-mail-alias-type 'abbrev)
2505 (if (fboundp 'mail-abbrevs-setup)
2506 (mail-abbrevs-setup)
2507 (if (fboundp 'mail-aliases-setup) ; warning avoidance
2508 (mail-aliases-setup))))
2509 (unless buffer-file-name
2510 (message-set-auto-save-file-name))
2511 (unless (buffer-base-buffer)
2512 ;; Don't enable multibyte on an indirect buffer. Maybe enabling
2513 ;; multibyte is not necessary at all. -- zsh
2514 (mm-enable-multibyte))
2515 (set (make-local-variable 'indent-tabs-mode) nil) ;No tabs for indentation.
2518 (defun message-setup-fill-variables ()
2519 "Setup message fill variables."
2520 (set (make-local-variable 'fill-paragraph-function)
2521 'message-fill-paragraph)
2522 (make-local-variable 'paragraph-separate)
2523 (make-local-variable 'paragraph-start)
2524 (make-local-variable 'adaptive-fill-regexp)
2525 (unless (boundp 'adaptive-fill-first-line-regexp)
2526 (setq adaptive-fill-first-line-regexp nil))
2527 (make-local-variable 'adaptive-fill-first-line-regexp)
2528 (let ((quote-prefix-regexp
2529 ;; User should change message-cite-prefix-regexp if
2530 ;; message-yank-prefix is set to an abnormal value.
2531 (concat "\\(" message-cite-prefix-regexp "\\)[ \t]*")))
2532 (setq paragraph-start
2534 (regexp-quote mail-header-separator) "$\\|"
2535 "[ \t]*$\\|" ; blank lines
2536 "-- $\\|" ; signature delimiter
2537 "---+$\\|" ; delimiters for forwarded messages
2538 page-delimiter "$\\|" ; spoiler warnings
2539 ".*wrote:$\\|" ; attribution lines
2540 quote-prefix-regexp "$\\|" ; empty lines in quoted text
2542 "<#!*/?\\(multipart\\|part\\|external\\|mml\\|secure\\)"))
2543 (setq paragraph-separate paragraph-start)
2544 (setq adaptive-fill-regexp
2545 (concat quote-prefix-regexp "\\|" adaptive-fill-regexp))
2546 (setq adaptive-fill-first-line-regexp
2547 (concat quote-prefix-regexp "\\|"
2548 adaptive-fill-first-line-regexp)))
2549 (make-local-variable 'auto-fill-inhibit-regexp)
2550 ;;(setq auto-fill-inhibit-regexp "^[A-Z][^: \n\t]+:")
2551 (setq auto-fill-inhibit-regexp nil)
2552 (make-local-variable 'normal-auto-fill-function)
2553 (setq normal-auto-fill-function 'message-do-auto-fill)
2554 ;; KLUDGE: auto fill might already be turned on in `text-mode-hook'.
2555 ;; In that case, ensure that it uses the right function. The real
2556 ;; solution would be not to use `define-derived-mode', and run
2557 ;; `text-mode-hook' ourself at the end of the mode.
2558 ;; -- Per Abrahamsen <abraham@dina.kvl.dk> Date: 2001-10-19.
2559 (when auto-fill-function
2560 (setq auto-fill-function normal-auto-fill-function)))
2565 ;;; Message mode commands
2568 ;;; Movement commands
2570 (defun message-goto-to ()
2571 "Move point to the To header."
2573 (message-position-on-field "To"))
2575 (defun message-goto-from ()
2576 "Move point to the From header."
2578 (message-position-on-field "From"))
2580 (defun message-goto-subject ()
2581 "Move point to the Subject header."
2583 (message-position-on-field "Subject"))
2585 (defun message-goto-cc ()
2586 "Move point to the Cc header."
2588 (message-position-on-field "Cc" "To"))
2590 (defun message-goto-bcc ()
2591 "Move point to the Bcc header."
2593 (message-position-on-field "Bcc" "Cc" "To"))
2595 (defun message-goto-fcc ()
2596 "Move point to the Fcc header."
2598 (message-position-on-field "Fcc" "To" "Newsgroups"))
2600 (defun message-goto-reply-to ()
2601 "Move point to the Reply-To header."
2603 (message-position-on-field "Reply-To" "Subject"))
2605 (defun message-goto-newsgroups ()
2606 "Move point to the Newsgroups header."
2608 (message-position-on-field "Newsgroups"))
2610 (defun message-goto-distribution ()
2611 "Move point to the Distribution header."
2613 (message-position-on-field "Distribution"))
2615 (defun message-goto-followup-to ()
2616 "Move point to the Followup-To header."
2618 (message-position-on-field "Followup-To" "Newsgroups"))
2620 (defun message-goto-mail-followup-to ()
2621 "Move point to the Mail-Followup-To header."
2623 (message-position-on-field "Mail-Followup-To" "To"))
2625 (defun message-goto-keywords ()
2626 "Move point to the Keywords header."
2628 (message-position-on-field "Keywords" "Subject"))
2630 (defun message-goto-summary ()
2631 "Move point to the Summary header."
2633 (message-position-on-field "Summary" "Subject"))
2635 (defun message-goto-body (&optional interactivep)
2636 "Move point to the beginning of the message body."
2637 (interactive (list t))
2638 (when (and interactivep
2639 (looking-at "[ \t]*\n"))
2641 (goto-char (point-min))
2642 (or (search-forward (concat "\n" mail-header-separator "\n") nil t)
2643 (search-forward-regexp "[^:]+:\\([^\n]\\|\n[ \t]\\)+\n\n" nil t)))
2645 (defun message-goto-eoh ()
2646 "Move point to the end of the headers."
2651 (defun message-goto-signature ()
2652 "Move point to the beginning of the message signature.
2653 If there is no signature in the article, go to the end and
2656 (goto-char (point-min))
2657 (if (re-search-forward message-signature-separator nil t)
2659 (goto-char (point-max))
2662 (defun message-generate-unsubscribed-mail-followup-to (&optional include-cc)
2663 "Insert a reasonable MFT header in a post to an unsubscribed list.
2664 When making original posts to a mailing list you are not subscribed to,
2665 you have to type in a MFT header by hand. The contents, usually, are
2666 the addresses of the list and your own address. This function inserts
2667 such a header automatically. It fetches the contents of the To: header
2668 in the current mail buffer, and appends the current `user-mail-address'.
2670 If the optional argument INCLUDE-CC is non-nil, the addresses in the
2671 Cc: header are also put into the MFT."
2676 (message-narrow-to-headers)
2677 (message-remove-header "Mail-Followup-To")
2678 (setq cc (and include-cc (message-fetch-field "Cc")))
2680 (concat (message-fetch-field "To") "," cc)
2681 (message-fetch-field "To"))))
2682 (message-goto-mail-followup-to)
2683 (insert (concat tos ", " user-mail-address))))
2687 (defun message-insert-to (&optional force)
2688 "Insert a To header that points to the author of the article being replied to.
2689 If the original author requested not to be sent mail, don't insert unless the
2690 prefix FORCE is given."
2692 (let* ((mct (message-fetch-reply-field "mail-copies-to"))
2693 (dont (and mct (or (equal (downcase mct) "never")
2694 (equal (downcase mct) "nobody"))))
2695 (to (or (message-fetch-reply-field "mail-reply-to")
2696 (message-fetch-reply-field "reply-to")
2697 (message-fetch-reply-field "from"))))
2701 "Ignoring the user request not to have copies sent via mail"
2702 "Complying with the user request not to have copies sent via mail")))
2703 (when (and force (not to))
2704 (error "No mail address in the article"))
2705 (when (and to (or force (not dont)))
2706 (message-carefully-insert-headers (list (cons 'To to))))))
2708 (defun message-insert-wide-reply ()
2709 "Insert To and Cc headers as if you were doing a wide reply."
2711 (let ((headers (message-with-reply-buffer
2712 (message-get-reply-headers t))))
2713 (message-carefully-insert-headers headers)))
2715 (defcustom message-header-synonyms
2717 "List of lists of header synonyms.
2718 E.g., if this list contains a member list with elements `Cc' and `To',
2719 then `message-carefully-insert-headers' will not insert a `To' header
2720 when the message is already `Cc'ed to the recipient."
2722 :group 'message-headers
2723 :link '(custom-manual "(message)Message Headers")
2724 :type '(repeat sexp))
2726 (defun message-carefully-insert-headers (headers)
2727 "Insert the HEADERS, an alist, into the message buffer.
2728 Does not insert the headers when they are already present there
2729 or in the synonym headers, defined by `message-header-synonyms'."
2730 ;; FIXME: Should compare only the address and not the full name. Comparison
2731 ;; should be done case-folded (and with `string=' rather than
2733 ;; (mail-strip-quoted-names "Foo Bar <foo@bar>, bla@fasel (Bla Fasel)")
2734 (dolist (header headers)
2735 (let* ((header-name (symbol-name (car header)))
2736 (new-header (cdr header))
2737 (synonyms (loop for synonym in message-header-synonyms
2738 when (memq (car header) synonym) return synonym))
2740 (loop for synonym in synonyms
2741 for old-header = (mail-fetch-field (symbol-name synonym))
2742 when (and old-header (string-match new-header old-header))
2745 (message "already have `%s' in `%s'" new-header old-header)
2746 (when (and (message-position-on-field header-name)
2747 (setq old-header (mail-fetch-field header-name))
2748 (not (string-match "\\` *\\'" old-header)))
2750 (insert new-header)))))
2752 (defun message-widen-reply ()
2753 "Widen the reply to include maximum recipients."
2756 (and message-reply-buffer
2757 (buffer-name message-reply-buffer)
2759 (set-buffer message-reply-buffer)
2760 (message-get-reply-headers t)))))
2763 (message-narrow-to-headers)
2764 (dolist (elem follow-to)
2765 (message-remove-header (symbol-name (car elem)))
2766 (goto-char (point-min))
2767 (insert (symbol-name (car elem)) ": "
2768 (cdr elem) "\n"))))))
2770 (defun message-insert-newsgroups ()
2771 "Insert the Newsgroups header from the article being replied to."
2773 (when (and (message-position-on-field "Newsgroups")
2774 (mail-fetch-field "newsgroups")
2775 (not (string-match "\\` *\\'" (mail-fetch-field "newsgroups"))))
2777 (insert (or (message-fetch-reply-field "newsgroups") "")))
2781 ;;; Various commands
2783 (defun message-delete-not-region (beg end)
2784 "Delete everything in the body of the current message outside of the region."
2789 ;; snarf citation prefix, if appropriate
2790 (unless (eq (point) (progn (beginning-of-line) (point)))
2791 (when (looking-at message-cite-prefix-regexp)
2792 (setq citeprefix (match-string 0))))
2794 (delete-region (point) (if (not (message-goto-signature))
2800 (delete-region beg (progn (message-goto-body)
2804 (insert citeprefix))))
2805 (when (message-goto-signature)
2808 (defun message-kill-to-signature ()
2809 "Deletes all text up to the signature."
2811 (let ((point (point)))
2812 (message-goto-signature)
2815 (kill-region point (point))
2819 (defun message-newline-and-reformat (&optional arg not-break)
2820 "Insert four newlines, and then reformat if inside quoted text.
2821 Prefix arg means justify as well."
2822 (interactive (list (if current-prefix-arg 'full)))
2823 (let (quoted point beg end leading-space bolp)
2824 (setq point (point))
2827 (setq bolp (= beg point))
2828 ;; Find first line of the paragraph.
2830 (while (and (not (eobp))
2831 (not (looking-at message-cite-prefix-regexp))
2832 (looking-at paragraph-start))
2835 (when (looking-at message-cite-prefix-regexp)
2836 (setq quoted (match-string 0))
2837 (goto-char (match-end 0))
2838 (looking-at "[ \t]*")
2839 (setq leading-space (match-string 0)))
2843 (< (- point beg) (length quoted)))
2844 ;; break inside the cite prefix.
2850 (while (and (not (eobp))
2851 (not (looking-at paragraph-separate))
2852 (looking-at message-cite-prefix-regexp)
2853 (equal quoted (match-string 0)))
2854 (goto-char (match-end 0))
2855 (looking-at "[ \t]*")
2856 (if (> (length leading-space) (length (match-string 0)))
2857 (setq leading-space (match-string 0)))
2861 (while (and (if (bobp) nil (forward-line -1) t)
2862 (not (looking-at paragraph-start))
2863 (looking-at message-cite-prefix-regexp)
2864 (equal quoted (match-string 0)))
2866 (goto-char (match-end 0))
2867 (looking-at "[ \t]*")
2868 (if (> (length leading-space) (length (match-string 0)))
2869 (setq leading-space (match-string 0)))))
2870 (while (and (not (eobp))
2871 (not (looking-at paragraph-separate))
2872 (not (looking-at message-cite-prefix-regexp)))
2876 (while (and (if (bobp) nil (forward-line -1) t)
2877 (not (looking-at paragraph-start))
2878 (not (looking-at message-cite-prefix-regexp)))
2879 (setq beg (point))))
2882 (narrow-to-region beg end)
2889 (setq point (point))
2890 ;; (newline 2) doesn't mark both newline's as hard, so call
2891 ;; newline twice. -jas
2894 (delete-region (point) (re-search-forward "[ \t]*"))
2895 (when (and quoted (not bolp))
2896 (insert quoted leading-space)))
2899 (let* ((adaptive-fill-regexp
2900 (regexp-quote (concat quoted leading-space)))
2901 (adaptive-fill-first-line-regexp
2902 adaptive-fill-regexp ))
2903 (fill-paragraph arg))
2904 (fill-paragraph arg))
2905 (if point (goto-char point)))))
2907 (defun message-fill-paragraph (&optional arg)
2908 "Like `fill-paragraph'."
2909 (interactive (list (if current-prefix-arg 'full)))
2910 (if (if (boundp 'filladapt-mode) filladapt-mode)
2912 (message-newline-and-reformat arg t)
2915 ;; Is it better to use `mail-header-end'?
2916 (defun message-point-in-header-p ()
2917 "Return t if point is in the header."
2920 (goto-char (point-min))
2921 (not (re-search-forward
2922 (concat "^" (regexp-quote mail-header-separator) "\n")
2925 (defun message-do-auto-fill ()
2926 "Like `do-auto-fill', but don't fill in message header."
2927 (unless (message-point-in-header-p)
2930 (defun message-insert-signature (&optional force)
2931 "Insert a signature. See documentation for variable `message-signature'."
2932 (interactive (list 0))
2935 ((and (null message-signature)
2938 (goto-char (point-max))
2939 (not (re-search-backward message-signature-separator nil t))))
2940 ((and (null message-signature)
2943 ((functionp message-signature)
2944 (funcall message-signature))
2945 ((listp message-signature)
2946 (eval message-signature))
2947 (t message-signature)))
2949 (cond ((stringp signature)
2951 ((and (eq t signature)
2952 message-signature-file
2953 (file-exists-p message-signature-file))
2956 (goto-char (point-max))
2957 ;; Insert the signature.
2960 (when message-signature-insert-empty-line
2963 (if (eq signature t)
2964 (insert-file-contents message-signature-file)
2966 (goto-char (point-max))
2967 (or (bolp) (insert "\n")))))
2969 (defun message-insert-importance-high ()
2970 "Insert header to mark message as important."
2974 (message-narrow-to-headers)
2975 (message-remove-header "Importance"))
2977 (insert "Importance: high\n")))
2979 (defun message-insert-importance-low ()
2980 "Insert header to mark message as unimportant."
2984 (message-narrow-to-headers)
2985 (message-remove-header "Importance"))
2987 (insert "Importance: low\n")))
2989 (defun message-insert-or-toggle-importance ()
2990 "Insert a \"Importance: high\" header, or cycle through the header values.
2991 The three allowed values according to RFC 1327 are `high', `normal'
2995 (let ((valid '("high" "normal" "low"))
2999 (message-narrow-to-headers)
3000 (when (setq cur (message-fetch-field "Importance"))
3001 (message-remove-header "Importance")
3002 (setq new (cond ((string= cur "high")
3004 ((string= cur "low")
3009 (insert (format "Importance: %s\n" new)))))
3011 (defun message-insert-disposition-notification-to ()
3012 "Request a disposition notification (return receipt) to this message.
3013 Note that this should not be used in newsgroups."
3017 (message-narrow-to-headers)
3018 (message-remove-header "Disposition-Notification-To"))
3020 (insert (format "Disposition-Notification-To: %s\n"
3021 (or (message-field-value "Reply-to")
3022 (message-field-value "From")
3023 (message-make-from))))))
3025 (defun message-elide-region (b e)
3026 "Elide the text in the region.
3027 An ellipsis (from `message-elide-ellipsis') will be inserted where the
3031 (insert message-elide-ellipsis))
3033 (defvar message-caesar-translation-table nil)
3035 (defun message-caesar-region (b e &optional n)
3036 "Caesar rotate region B to E by N, default 13, for decrypting netnews."
3039 (min (point) (or (mark t) (point)))
3040 (max (point) (or (mark t) (point)))
3041 (when current-prefix-arg
3042 (prefix-numeric-value current-prefix-arg))))
3044 (setq n (if (numberp n) (mod n 26) 13)) ;canonize N
3045 (unless (or (zerop n) ; no action needed for a rot of 0
3046 (= b e)) ; no region to rotate
3047 ;; We build the table, if necessary.
3048 (when (or (not message-caesar-translation-table)
3049 (/= (aref message-caesar-translation-table ?a) (+ ?a n)))
3050 (setq message-caesar-translation-table
3051 (message-make-caesar-translation-table n)))
3052 (translate-region b e message-caesar-translation-table)))
3054 (defun message-make-caesar-translation-table (n)
3055 "Create a rot table with offset N."
3057 (table (make-string 256 0)))
3058 (while (< (incf i) 256)
3061 (substring table 0 ?A)
3062 (substring table (+ ?A n) (+ ?A n (- 26 n)))
3063 (substring table ?A (+ ?A n))
3064 (substring table (+ ?A 26) ?a)
3065 (substring table (+ ?a n) (+ ?a n (- 26 n)))
3066 (substring table ?a (+ ?a n))
3067 (substring table (+ ?a 26) 255))))
3069 (defun message-caesar-buffer-body (&optional rotnum)
3070 "Caesar rotate all letters in the current buffer by 13 places.
3071 Used to encode/decode possibly offensive messages (commonly in rec.humor).
3072 With prefix arg, specifies the number of places to rotate each letter forward.
3073 Mail and USENET news headers are not rotated."
3074 (interactive (if current-prefix-arg
3075 (list (prefix-numeric-value current-prefix-arg))
3079 (when (message-goto-body)
3080 (narrow-to-region (point) (point-max)))
3081 (message-caesar-region (point-min) (point-max) rotnum))))
3083 (defun message-pipe-buffer-body (program)
3084 "Pipe the message body in the current buffer through PROGRAM."
3087 (when (message-goto-body)
3088 (narrow-to-region (point) (point-max)))
3089 (shell-command-on-region
3090 (point-min) (point-max) program nil t))))
3092 (defun message-rename-buffer (&optional enter-string)
3093 "Rename the *message* buffer to \"*message* RECIPIENT\".
3094 If the function is run with a prefix, it will ask for a new buffer
3095 name, rather than giving an automatic name."
3096 (interactive "Pbuffer name: ")
3099 (goto-char (point-min))
3100 (narrow-to-region (point)
3101 (search-forward mail-header-separator nil 'end))
3103 (if (message-news-p) (message-fetch-field "Newsgroups")
3104 (message-fetch-field "To"))
3107 (if (string-match "," mail-to)
3108 (concat (substring mail-to 0 (match-beginning 0)) ", ...")
3110 (name-default (concat "*message* " mail-trimmed-to))
3111 (name (if enter-string
3112 (read-string "New buffer name: " name-default)
3114 (rename-buffer name t)))))
3116 (defun message-fill-yanked-message (&optional justifyp)
3117 "Fill the paragraphs of a message yanked into this one.
3118 Numeric argument means justify as well."
3121 (goto-char (point-min))
3122 (search-forward (concat "\n" mail-header-separator "\n") nil t)
3123 (let ((fill-prefix message-yank-prefix))
3124 (fill-individual-paragraphs (point) (point-max) justifyp))))
3126 (defun message-indent-citation ()
3127 "Modify text just inserted from a message to be cited.
3128 The inserted text should be the region.
3129 When this function returns, the region is again around the modified text.
3131 Normally, indent each nonblank line `message-indentation-spaces' spaces.
3132 However, if `message-yank-prefix' is non-nil, insert that prefix on each line."
3133 (let ((start (point)))
3134 ;; Remove unwanted headers.
3135 (when message-ignored-cited-headers
3140 (if (search-forward "\n\n" nil t)
3143 (message-remove-header message-ignored-cited-headers t)
3144 (when (= (point-min) (point-max))
3145 (setq all-removed t))
3146 (goto-char (point-max)))
3150 ;; Delete blank lines at the start of the buffer.
3151 (while (and (point-min)
3154 (message-delete-line))
3155 ;; Delete blank lines at the end of the buffer.
3156 (goto-char (point-max))
3159 (while (and (zerop (forward-line -1))
3161 (message-delete-line))
3162 ;; Do the indentation.
3163 (if (null message-yank-prefix)
3164 (indent-rigidly start (mark t) message-indentation-spaces)
3167 (while (< (point) (mark t))
3168 (if (or (looking-at ">") (looking-at "^$"))
3169 (insert message-yank-cited-prefix)
3170 (insert message-yank-prefix))
3174 (defun message-yank-original (&optional arg)
3175 "Insert the message being replied to, if any.
3176 Puts point before the text and mark after.
3177 Normally indents each nonblank line ARG spaces (default 3). However,
3178 if `message-yank-prefix' is non-nil, insert that prefix on each line.
3180 This function uses `message-cite-function' to do the actual citing.
3182 Just \\[universal-argument] as argument means don't indent, insert no
3183 prefix, and don't delete any headers."
3185 (let ((modified (buffer-modified-p)))
3186 (when (and message-reply-buffer
3187 message-cite-function)
3188 (delete-windows-on message-reply-buffer t)
3189 (insert-buffer message-reply-buffer)
3191 (funcall message-cite-function))
3192 (message-exchange-point-and-mark)
3196 (setq message-checksum (message-checksum))))))
3198 (defun message-yank-buffer (buffer)
3199 "Insert BUFFER into the current buffer and quote it."
3200 (interactive "bYank buffer: ")
3201 (let ((message-reply-buffer (get-buffer buffer)))
3202 (save-window-excursion
3203 (message-yank-original))))
3205 (defun message-buffers ()
3206 "Return a list of active message buffers."
3209 (dolist (buffer (buffer-list t))
3211 (when (and (eq major-mode 'message-mode)
3212 (null message-sent-message-via))
3213 (push (buffer-name buffer) buffers))))
3214 (nreverse buffers)))
3216 (defun message-cite-original-without-signature ()
3217 "Cite function in the standard Message manner."
3218 (let* ((start (point))
3221 (when message-indent-citation-function
3222 (if (listp message-indent-citation-function)
3223 message-indent-citation-function
3224 (list message-indent-citation-function))))
3225 ;; This function may be called by `gnus-summary-yank-message' and
3226 ;; may insert a different article from the original. So, we will
3227 ;; modify the value of `message-reply-headers' with that article.
3228 (message-reply-headers
3230 (narrow-to-region start end)
3231 (message-narrow-to-head-1)
3233 (or (message-fetch-field "subject") "none")
3234 (message-fetch-field "from")
3235 (message-fetch-field "date")
3236 (message-fetch-field "message-id" t)
3237 (message-fetch-field "references")
3239 (mml-quote-region start end)
3243 (when (re-search-backward message-signature-separator start t)
3244 ;; Also peel off any blank lines before the signature.
3246 (while (looking-at "^[ \t]*$")
3249 (delete-region (point) end)
3250 (unless (search-backward "\n\n" start t)
3251 ;; Insert a blank line if it is peeled off.
3255 (funcall (pop functions)))
3256 (when message-citation-line-function
3259 (funcall message-citation-line-function))))
3261 (eval-when-compile (defvar mail-citation-hook)) ;Compiler directive
3262 (defun message-cite-original ()
3263 "Cite function in the standard Message manner."
3264 (if (and (boundp 'mail-citation-hook)
3266 (run-hooks 'mail-citation-hook)
3267 (let* ((start (point))
3270 (when message-indent-citation-function
3271 (if (listp message-indent-citation-function)
3272 message-indent-citation-function
3273 (list message-indent-citation-function))))
3274 ;; This function may be called by `gnus-summary-yank-message' and
3275 ;; may insert a different article from the original. So, we will
3276 ;; modify the value of `message-reply-headers' with that article.
3277 (message-reply-headers
3279 (narrow-to-region start end)
3280 (message-narrow-to-head-1)
3282 (or (message-fetch-field "subject") "none")
3283 (message-fetch-field "from")
3284 (message-fetch-field "date")
3285 (message-fetch-field "message-id" t)
3286 (message-fetch-field "references")
3288 (mml-quote-region start end)
3291 (funcall (pop functions)))
3292 (when message-citation-line-function
3295 (funcall message-citation-line-function)))))
3297 (defun message-insert-citation-line ()
3298 "Insert a simple citation line."
3299 (when message-reply-headers
3300 (insert (mail-header-from message-reply-headers) " writes:\n\n")))
3302 (defun message-position-on-field (header &rest afters)
3303 (let ((case-fold-search t))
3306 (goto-char (point-min))
3309 (concat "^" (regexp-quote mail-header-separator) "$"))
3310 (match-beginning 0)))
3311 (goto-char (point-min))
3312 (if (re-search-forward (concat "^" (regexp-quote header) ":") nil t)
3314 (re-search-forward "^[^ \t]" nil 'move)
3316 (skip-chars-backward "\n")
3319 (not (re-search-forward
3320 (concat "^" (regexp-quote (car afters)) ":")
3324 (re-search-forward "^[^ \t]" nil 'move)
3325 (beginning-of-line))
3326 (insert header ": \n")
3330 (defun message-remove-signature ()
3331 "Remove the signature from the text between point and mark.
3332 The text will also be indented the normal way."
3334 (let ((start (point))
3336 (if (not (re-search-forward message-signature-separator (mark t) t))
3337 ;; No signature here, so we just indent the cited text.
3338 (message-indent-citation)
3339 ;; Find the last non-empty line.
3341 (while (looking-at "[ \t]*$")
3344 (setq mark (set-marker (make-marker) (point)))
3346 (message-indent-citation)
3347 ;; Enable undoing the deletion.
3349 (delete-region mark (mark t))
3350 (set-marker mark nil)))))
3355 ;;; Sending messages
3358 (defun message-send-and-exit (&optional arg)
3359 "Send message like `message-send', then, if no errors, exit from mail buffer."
3361 (let ((buf (current-buffer))
3362 (actions message-exit-actions))
3363 (when (and (message-send arg)
3365 (if message-kill-buffer-on-exit
3368 (when (eq buf (current-buffer))
3369 (message-bury buf)))
3370 (message-do-actions actions)
3373 (defun message-dont-send ()
3374 "Don't send the message you have been editing.
3375 Instead, just auto-save the buffer and then bury it."
3377 (set-buffer-modified-p t)
3379 (let ((actions message-postpone-actions))
3380 (message-bury (current-buffer))
3381 (message-do-actions actions)))
3383 (defun message-kill-buffer ()
3384 "Kill the current buffer."
3386 (when (or (not (buffer-modified-p))
3387 (yes-or-no-p "Message modified; kill anyway? "))
3388 (let ((actions message-kill-actions)
3389 (draft-article message-draft-article)
3390 (auto-save-file-name buffer-auto-save-file-name)
3391 (file-name buffer-file-name)
3392 (modified (buffer-modified-p)))
3393 (setq buffer-file-name nil)
3394 (kill-buffer (current-buffer))
3395 (when (and (or (and auto-save-file-name
3396 (file-exists-p auto-save-file-name))
3398 (file-exists-p file-name)))
3399 (yes-or-no-p (format "Remove the backup file%s? "
3400 (if modified " too" ""))))
3402 (delete-file auto-save-file-name))
3403 (let ((message-draft-article draft-article))
3404 (message-disassociate-draft)))
3405 (message-do-actions actions))))
3407 (defun message-bury (buffer)
3408 "Bury this mail BUFFER."
3409 (let ((newbuf (other-buffer buffer)))
3410 (bury-buffer buffer)
3411 (if (and (fboundp 'frame-parameters)
3412 (cdr (assq 'dedicated (frame-parameters)))
3413 (not (null (delq (selected-frame) (visible-frame-list)))))
3414 (delete-frame (selected-frame))
3415 (switch-to-buffer newbuf))))
3417 (defun message-send (&optional arg)
3418 "Send the message in the current buffer.
3419 If `message-interactive' is non-nil, wait for success indication or
3420 error messages, and inform user.
3421 Otherwise any failure is reported in a message back to the user from
3423 The usage of ARG is defined by the instance that called Message.
3424 It should typically alter the sending method in some way or other."
3426 ;; Make it possible to undo the coming changes.
3428 (let ((inhibit-read-only t))
3429 (put-text-property (point-min) (point-max) 'read-only nil))
3430 (message-fix-before-sending)
3431 (run-hooks 'message-send-hook)
3432 (message message-sending-message)
3433 (let ((alist message-send-method-alist)
3435 elem sent dont-barf-on-no-method
3436 (message-options message-options))
3437 (message-options-set-recipient)
3439 (setq elem (pop alist)))
3440 (when (funcall (cadr elem))
3441 (when (and (or (not (memq (car elem)
3442 message-sent-message-via))
3443 (message-fetch-field "supersedes")
3444 (if (or (message-gnksa-enable-p 'multiple-copies)
3445 (not (eq (car elem) 'news)))
3448 "Already sent message via %s; resend? "
3450 (error "Denied posting -- multiple copies")))
3451 (setq success (funcall (caddr elem) arg)))
3455 (let ((fcc (message-fetch-field "Fcc"))
3456 (gcc (message-fetch-field "Gcc")))
3458 (or (eq message-allow-no-recipients 'always)
3459 (and (not (eq message-allow-no-recipients 'never))
3460 (setq dont-barf-on-no-method
3462 (format "No receiver, perform %s anyway? "
3463 (cond ((and fcc gcc) "Fcc and Gcc")
3466 (error "No methods specified to send by"))
3467 (when (or dont-barf-on-no-method
3471 (run-hooks 'message-sent-hook))
3472 (message "Sending...done")
3473 ;; Mark the buffer as unmodified and delete auto-save.
3474 (set-buffer-modified-p nil)
3475 (delete-auto-save-file-if-necessary t)
3476 (message-disassociate-draft)
3477 ;; Delete other mail buffers and stuff.
3478 (message-do-send-housekeeping)
3479 (message-do-actions message-send-actions)
3483 (defun message-send-via-mail (arg)
3484 "Send the current message via mail."
3485 (message-send-mail arg))
3487 (defun message-send-via-news (arg)
3488 "Send the current message via news."
3489 (funcall message-send-news-function arg))
3491 (defmacro message-check (type &rest forms)
3492 "Eval FORMS if TYPE is to be checked."
3493 `(or (message-check-element ,type)
3497 (put 'message-check 'lisp-indent-function 1)
3498 (put 'message-check 'edebug-form-spec '(form body))
3500 (defun message-text-with-property (prop)
3501 "Return a list of all points where the text has PROP."
3503 (point (point-min)))
3505 (while (< point (point-max))
3506 (when (get-text-property point prop)
3507 (push point points))
3511 (defun message-fix-before-sending ()
3512 "Do various things to make the message nice before sending it."
3513 ;; Make sure there's a newline at the end of the message.
3514 (goto-char (point-max))
3517 ;; Make the hidden headers visible.
3518 (let ((points (message-text-with-property 'message-hidden)))
3520 (goto-char (car points))
3521 (dolist (point points)
3522 (add-text-properties point (1+ point)
3523 '(invisible nil intangible nil)))))
3524 ;; Make invisible text visible.
3525 ;; It doesn't seem as if this is useful, since the invisible property
3526 ;; is clobbered by an after-change hook anyhow.
3527 (message-check 'invisible-text
3528 (let ((points (message-text-with-property 'invisible)))
3530 (goto-char (car points))
3531 (dolist (point points)
3532 (put-text-property point (1+ point) 'invisible nil)
3533 (message-overlay-put (message-make-overlay point (1+ point))
3535 (unless (yes-or-no-p
3536 "Invisible text found and made visible; continue sending? ")
3537 (error "Invisible text found and made visible")))))
3538 (message-check 'illegible-text
3541 (skip-chars-forward mm-7bit-chars)
3543 (when (let ((char (char-after)))
3544 (or (< (mm-char-int char) 128)
3545 (and (mm-multibyte-p)
3546 (memq (char-charset char)
3547 '(eight-bit-control eight-bit-graphic
3549 (not (get-text-property
3550 (point) 'untranslated-utf-8)))))
3551 (message-overlay-put (message-make-overlay (point) (1+ (point)))
3555 (skip-chars-forward mm-7bit-chars))
3558 (gnus-multiple-choice
3559 "Non-printable characters found. Continue sending?"
3560 '((?d "Remove non-printable characters and send")
3561 (?r "Replace non-printable characters with dots and send")
3562 (?i "Ignore non-printable characters and send")
3563 (?e "Continue editing"))))
3565 (error "Non-printable characters"))
3567 (skip-chars-forward mm-7bit-chars)
3569 (when (let ((char (char-after)))
3570 (or (< (mm-char-int char) 128)
3571 (and (mm-multibyte-p)
3572 ;; Fixme: Wrong for Emacs 22 and for things
3573 ;; like undecable utf-8. Should at least
3574 ;; use find-coding-systems-region.
3575 (memq (char-charset char)
3576 '(eight-bit-control eight-bit-graphic
3578 (not (get-text-property
3579 (point) 'untranslated-utf-8)))))
3581 (message-kill-all-overlays)
3583 (when (eq choice ?r)
3586 (skip-chars-forward mm-7bit-chars))))))
3588 (defun message-add-action (action &rest types)
3589 "Add ACTION to be performed when doing an exit of type TYPES."
3591 (add-to-list (intern (format "message-%s-actions" (pop types)))
3594 (defun message-delete-action (action &rest types)
3595 "Delete ACTION from lists of actions performed when doing an exit of type TYPES."
3598 (set (setq var (intern (format "message-%s-actions" (pop types))))
3599 (delq action (symbol-value var))))))
3601 (defun message-do-actions (actions)
3602 "Perform all actions in ACTIONS."
3603 ;; Now perform actions on successful sending.
3607 ;; A simple function.
3608 ((functionp (car actions))
3609 (funcall (car actions)))
3610 ;; Something to be evaled.
3612 (eval (car actions)))))
3615 (defun message-send-mail-partially ()
3616 "Send mail as message/partial."
3617 ;; replace the header delimiter with a blank line
3618 (goto-char (point-min))
3620 (concat "^" (regexp-quote mail-header-separator) "\n"))
3621 (replace-match "\n")
3622 (run-hooks 'message-send-mail-hook)
3623 (let ((p (goto-char (point-min)))
3624 (tembuf (message-generate-new-buffer-clone-locals " message temp"))
3625 (curbuf (current-buffer))
3626 (id (message-make-message-id)) (n 1)
3627 plist total header required-mail-headers)
3629 (if (< (point-max) (+ p message-send-mail-partially-limit))
3630 (goto-char (point-max))
3631 (goto-char (+ p message-send-mail-partially-limit))
3633 (if (<= (point) p) (forward-line 1))) ;; In case of bad message.
3636 (setq total (length plist))
3637 (push (point-max) plist)
3638 (setq plist (nreverse plist))
3641 (setq p (pop plist))
3644 (copy-to-buffer tembuf p (car plist))
3646 (goto-char (point-min))
3649 (goto-char (point-min))
3650 (narrow-to-region (point) (point))
3653 (setq header (buffer-substring (point-min) (point)))
3654 (goto-char (point-min))
3655 (narrow-to-region (point) (point))
3657 (message-remove-header "Mime-Version")
3658 (message-remove-header "Content-Type")
3659 (message-remove-header "Content-Transfer-Encoding")
3660 (message-remove-header "Message-ID")
3661 (message-remove-header "Lines")
3662 (goto-char (point-max))
3663 (insert "Mime-Version: 1.0\n")
3664 (setq header (buffer-string)))
3665 (goto-char (point-max))
3666 (insert (format "Content-Type: message/partial; id=\"%s\"; number=%d; total=%d\n\n"
3669 (let ((mail-header-separator ""))
3670 (when (memq 'Message-ID message-required-mail-headers)
3671 (insert "Message-ID: " (message-make-message-id) "\n"))
3672 (when (memq 'Lines message-required-mail-headers)
3673 (insert "Lines: " (message-make-lines) "\n"))
3674 (message-goto-subject)
3676 (insert (format " (%d/%d)" n total))
3678 (mm-with-unibyte-current-buffer
3679 (funcall (or message-send-mail-real-function
3680 message-send-mail-function))))
3682 (setq p (pop plist))
3684 (kill-buffer tembuf))))
3686 (defun message-send-mail (&optional arg)
3687 (require 'mail-utils)
3688 (let* ((tembuf (message-generate-new-buffer-clone-locals " message temp"))
3689 (case-fold-search nil)
3690 (news (message-news-p))
3691 (mailbuf (current-buffer))
3692 (message-this-is-mail t)
3693 (message-posting-charset
3694 (if (fboundp 'gnus-setup-posting-charset)
3695 (gnus-setup-posting-charset nil)
3696 message-posting-charset))
3697 (headers message-required-mail-headers))
3699 (message-narrow-to-headers)
3700 ;; Generate the Mail-Followup-To header if the header is not there...
3701 (if (and (message-subscribed-p)
3702 (not (mail-fetch-field "mail-followup-to")))
3705 (cons "Mail-Followup-To" (message-make-mail-followup-to))
3706 message-required-mail-headers))
3707 ;; otherwise, delete the MFT header if the field is empty
3708 (when (equal "" (mail-fetch-field "mail-followup-to"))
3709 (message-remove-header "^Mail-Followup-To:")))
3710 ;; Insert some headers.
3711 (let ((message-deletable-headers
3712 (if news nil message-deletable-headers)))
3713 (message-generate-headers headers))
3714 ;; Let the user do all of the above.
3715 (run-hooks 'message-header-hook))
3720 ;; Avoid copying text props (except hard newlines).
3721 (insert (with-current-buffer mailbuf
3722 (mml-buffer-substring-no-properties-except-hard-newlines
3723 (point-min) (point-max))))
3724 ;; Remove some headers.
3725 (message-encode-message-body)
3727 (message-narrow-to-headers)
3728 ;; We (re)generate the Lines header.
3729 (when (memq 'Lines message-required-mail-headers)
3730 (message-generate-headers '(Lines)))
3731 ;; Remove some headers.
3732 (message-remove-header message-ignored-mail-headers t)
3733 (let ((mail-parse-charset message-default-charset))
3734 (mail-encode-encoded-word-buffer)))
3735 (goto-char (point-max))
3736 ;; require one newline at the end.
3737 (or (= (preceding-char) ?\n)
3739 (message-cleanup-headers)
3740 ;; FIXME: we're inserting the courtesy copy after encoding.
3741 ;; This is wrong if the courtesy copy string contains
3742 ;; non-ASCII characters. -- jh
3745 (message-narrow-to-headers)
3747 (or (message-fetch-field "cc")
3748 (message-fetch-field "bcc")
3749 (message-fetch-field "to"))
3750 (let ((content-type (message-fetch-field
3755 (string= "text/plain"
3757 (mail-header-parse-content-type
3761 (message-fetch-field
3762 "content-transfer-encoding")))))))
3763 (message-insert-courtesy-copy))
3764 (if (or (not message-send-mail-partially-limit)
3765 (< (buffer-size) message-send-mail-partially-limit)
3766 (not (message-y-or-n-p
3767 "The message size is too large, split? "
3771 (/ (buffer-size) 1000) "KB, is too large.
3773 Some mail gateways (MTA's) bounce large messages. To avoid the
3774 problem, answer `y', and the message will be split into several
3775 smaller pieces, the size of each is about "
3776 (/ message-send-mail-partially-limit 1000)
3780 However, some mail readers (MUA's) can't read split messages, i.e.,
3781 mails in message/partially format. Answer `n', and the message will be
3784 The size limit is controlled by `message-send-mail-partially-limit'.
3785 If you always want Gnus to send messages in one piece, set
3786 `message-send-mail-partially-limit' to nil.
3788 (mm-with-unibyte-current-buffer
3789 (message "Sending via mail...")
3790 (funcall (or message-send-mail-real-function
3791 message-send-mail-function)))
3792 (message-send-mail-partially)))
3793 (kill-buffer tembuf))
3794 (set-buffer mailbuf)
3795 (push 'mail message-sent-message-via)))
3797 (defun message-send-mail-with-sendmail ()
3798 "Send off the prepared buffer with sendmail."
3799 (let ((errbuf (if message-interactive
3800 (message-generate-new-buffer-clone-locals
3803 resend-to-addresses delimline)
3806 (let ((case-fold-search t))
3808 (message-narrow-to-headers)
3809 (setq resend-to-addresses (message-fetch-field "resent-to")))
3810 ;; Change header-delimiter to be what sendmail expects.
3811 (goto-char (point-min))
3813 (concat "^" (regexp-quote mail-header-separator) "\n"))
3814 (replace-match "\n")
3816 (setq delimline (point-marker))
3817 (run-hooks 'message-send-mail-hook)
3818 ;; Insert an extra newline if we need it to work around
3819 ;; Sun's bug that swallows newlines.
3820 (goto-char (1+ delimline))
3821 (when (eval message-mailer-swallows-blank-line)
3823 (when message-interactive
3827 (let* ((default-directory "/")
3828 (coding-system-for-write message-send-coding-system)
3830 'call-process-region
3832 (list (point-min) (point-max)
3833 (if (boundp 'sendmail-program)
3835 "/usr/lib/sendmail")
3836 nil errbuf nil "-oi")
3837 ;; Always specify who from,
3838 ;; since some systems have broken sendmails.
3839 ;; But some systems are more broken with -f, so
3840 ;; we'll let users override this.
3841 (if (null message-sendmail-f-is-evil)
3842 (list "-f" (message-sendmail-envelope-from)))
3843 ;; These mean "report errors by mail"
3844 ;; and "deliver in background".
3845 (if (null message-interactive) '("-oem" "-odb"))
3846 ;; Get the addresses from the message
3847 ;; unless this is a resend.
3848 ;; We must not do that for a resend
3849 ;; because we would find the original addresses.
3850 ;; For a resend, include the specific addresses.
3851 (if resend-to-addresses
3852 (list resend-to-addresses)
3854 (unless (or (null cpr) (and (numberp cpr) (zerop cpr)))
3855 (error "Sending...failed with exit value %d" cpr)))
3856 (when message-interactive
3859 (goto-char (point-min))
3860 (while (re-search-forward "\n\n* *" nil t)
3861 (replace-match "; "))
3862 (if (not (zerop (buffer-size)))
3863 (error "Sending...failed to %s"
3864 (buffer-string))))))
3865 (when (bufferp errbuf)
3866 (kill-buffer errbuf)))))
3868 (defun message-send-mail-with-qmail ()
3869 "Pass the prepared message buffer to qmail-inject.
3870 Refer to the documentation for the variable `message-send-mail-function'
3871 to find out how to use this."
3872 ;; replace the header delimiter with a blank line
3873 (goto-char (point-min))
3875 (concat "^" (regexp-quote mail-header-separator) "\n"))
3876 (replace-match "\n")
3877 (run-hooks 'message-send-mail-hook)
3880 (let ((coding-system-for-write message-send-coding-system))
3882 'call-process-region (point-min) (point-max)
3883 message-qmail-inject-program nil nil nil
3884 ;; qmail-inject's default behaviour is to look for addresses on the
3885 ;; command line; if there're none, it scans the headers.
3886 ;; yes, it does The Right Thing w.r.t. Resent-To and it's kin.
3888 ;; in general, ALL of qmail-inject's defaults are perfect for simply
3889 ;; reading a formatted (i. e., at least a To: or Resent-To header)
3890 ;; message from stdin.
3892 ;; qmail also has the advantage of not having been raped by
3893 ;; various vendors, so we don't have to allow for that, either --
3894 ;; compare this with message-send-mail-with-sendmail and weep
3895 ;; for sendmail's lost innocence.
3897 ;; all this is way cool coz it lets us keep the arguments entirely
3898 ;; free for -inject-arguments -- a big win for the user and for us
3899 ;; since we don't have to play that double-guessing game and the user
3900 ;; gets full control (no gestapo'ish -f's, for instance). --sj
3901 (if (functionp message-qmail-inject-args)
3902 (funcall message-qmail-inject-args)
3903 message-qmail-inject-args)))
3904 ;; qmail-inject doesn't say anything on it's stdout/stderr,
3905 ;; we have to look at the retval instead
3907 (100 (error "qmail-inject reported permanent failure"))
3908 (111 (error "qmail-inject reported transient failure"))
3909 ;; should never happen
3910 (t (error "qmail-inject reported unknown failure"))))
3912 (defun message-send-mail-with-mh ()
3913 "Send the prepared message buffer with mh."
3914 (let ((mh-previous-window-config nil)
3915 (name (mh-new-draft-name)))
3916 (setq buffer-file-name name)
3917 ;; MH wants to generate these headers itself.
3918 (when message-mh-deletable-headers
3919 (let ((headers message-mh-deletable-headers))
3921 (goto-char (point-min))
3922 (and (re-search-forward
3923 (concat "^" (symbol-name (car headers)) ": *") nil t)
3924 (message-delete-line))
3926 (run-hooks 'message-send-mail-hook)
3927 ;; Pass it on to mh.
3930 (defun message-smtpmail-send-it ()
3931 "Send the prepared message buffer with `smtpmail-send-it'.
3932 This only differs from `smtpmail-send-it' that this command evaluates
3933 `message-send-mail-hook' just before sending a message. It is useful
3934 if your ISP requires the POP-before-SMTP authentication. See the Gnus
3935 manual for details."
3936 (run-hooks 'message-send-mail-hook)
3939 (defun message-canlock-generate ()
3940 "Return a string that is non-trivial to guess.
3941 Do not use this for anything important, it is cryptographically weak."
3943 (let (sha1-maximum-internal-length)
3944 (sha1 (concat (message-unique-id)
3945 (format "%x%x%x" (random) (random t) (random))
3946 (prin1-to-string (recent-keys))
3947 (prin1-to-string (garbage-collect))))))
3949 (defun message-canlock-password ()
3950 "The password used by message for cancel locks.
3951 This is the value of `canlock-password', if that option is non-nil.
3952 Otherwise, generate and save a value for `canlock-password' first."
3953 (unless canlock-password
3954 (customize-save-variable 'canlock-password (message-canlock-generate))
3955 (setq canlock-password-for-verify canlock-password))
3958 (defun message-insert-canlock ()
3959 (when message-insert-canlock
3960 (message-canlock-password)
3961 (canlock-insert-header)))
3963 (defun message-send-news (&optional arg)
3964 (let* ((tembuf (message-generate-new-buffer-clone-locals " *message temp*"))
3965 (case-fold-search nil)
3966 (method (if (functionp message-post-method)
3967 (funcall message-post-method arg)
3968 message-post-method))
3969 (newsgroups-field (save-restriction
3970 (message-narrow-to-headers-or-head)
3971 (message-fetch-field "Newsgroups")))
3972 (followup-field (save-restriction
3973 (message-narrow-to-headers-or-head)
3974 (message-fetch-field "Followup-To")))
3975 ;; BUG: We really need to get the charset for each name in the
3976 ;; Newsgroups and Followup-To lines to allow crossposting
3977 ;; between group namess with incompatible character sets.
3978 ;; -- Per Abrahamsen <abraham@dina.kvl.dk> 2001-10-08.
3979 (group-field-charset
3980 (gnus-group-name-charset method newsgroups-field))
3981 (followup-field-charset
3982 (gnus-group-name-charset method (or followup-field "")))
3983 (rfc2047-header-encoding-alist
3984 (append (when group-field-charset
3985 (list (cons "Newsgroups" group-field-charset)))
3986 (when followup-field-charset
3987 (list (cons "Followup-To" followup-field-charset)))
3988 rfc2047-header-encoding-alist))
3989 (messbuf (current-buffer))
3990 (message-syntax-checks
3992 (listp message-syntax-checks))
3993 (cons '(existing-newsgroups . disabled)
3994 message-syntax-checks)
3995 message-syntax-checks))
3996 (message-this-is-news t)
3997 (message-posting-charset
3998 (gnus-setup-posting-charset newsgroups-field))
4000 (if (not (message-check-news-body-syntax))
4003 (message-narrow-to-headers)
4004 ;; Insert some headers.
4005 (message-generate-headers message-required-news-headers)
4006 (message-insert-canlock)
4007 ;; Let the user do all of the above.
4008 (run-hooks 'message-header-hook))
4009 ;; Note: This check will be disabled by the ".*" default value for
4010 ;; gnus-group-name-charset-group-alist. -- Pa 2001-10-07.
4011 (when (and group-field-charset
4012 (listp message-syntax-checks))
4013 (setq message-syntax-checks
4014 (cons '(valid-newsgroups . disabled)
4015 message-syntax-checks)))
4016 (message-cleanup-headers)
4017 (if (not (let ((message-post-method method))
4018 (message-check-news-syntax)))
4023 (buffer-disable-undo)
4025 ;; Avoid copying text props (except hard newlines).
4027 (with-current-buffer messbuf
4028 (mml-buffer-substring-no-properties-except-hard-newlines
4029 (point-min) (point-max))))
4030 (message-encode-message-body)
4031 ;; Remove some headers.
4033 (message-narrow-to-headers)
4034 ;; We (re)generate the Lines header.
4035 (when (memq 'Lines message-required-mail-headers)
4036 (message-generate-headers '(Lines)))
4037 ;; Remove some headers.
4038 (message-remove-header message-ignored-news-headers t)
4039 (let ((mail-parse-charset message-default-charset))
4040 (mail-encode-encoded-word-buffer)))
4041 (goto-char (point-max))
4042 ;; require one newline at the end.
4043 (or (= (preceding-char) ?\n)
4045 (let ((case-fold-search t))
4046 ;; Remove the delimiter.
4047 (goto-char (point-min))
4049 (concat "^" (regexp-quote mail-header-separator) "\n"))
4050 (replace-match "\n")
4052 (run-hooks 'message-send-news-hook)
4053 (gnus-open-server method)
4054 (message "Sending news via %s..." (gnus-server-string method))
4055 (setq result (let ((mail-header-separator ""))
4056 (gnus-request-post method))))
4057 (kill-buffer tembuf))
4058 (set-buffer messbuf)
4060 (push 'news message-sent-message-via)
4061 (message "Couldn't send message via news: %s"
4062 (nnheader-get-report (car method)))
4066 ;;; Header generation & syntax checking.
4069 (defun message-check-element (type)
4070 "Return non-nil if this TYPE is not to be checked."
4071 (if (eq message-syntax-checks 'dont-check-for-anything-just-trust-me)
4073 (let ((able (assq type message-syntax-checks)))
4075 (eq (cdr able) 'disabled)))))
4077 (defun message-check-news-syntax ()
4078 "Check the syntax of the message."
4082 ;; We narrow to the headers and check them first.
4085 (message-narrow-to-headers)
4086 (message-check-news-header-syntax))))))
4088 (defun message-check-news-header-syntax ()
4090 ;; Check Newsgroups header.
4091 (message-check 'newsgroups
4092 (let ((group (message-fetch-field "newsgroups")))
4095 (not (string-match "\\`[ \t]*\\'" group)))
4098 "The newsgroups field is empty or missing. Posting is denied.")))))
4099 ;; Check the Subject header.
4100 (message-check 'subject
4101 (let* ((case-fold-search t)
4102 (subject (message-fetch-field "subject")))
4105 (not (string-match "\\`[ \t]*\\'" subject)))
4108 "The subject field is empty or missing. Posting is denied.")))))
4109 ;; Check for commands in Subject.
4110 (message-check 'subject-cmsg
4111 (if (string-match "^cmsg " (message-fetch-field "subject"))
4113 "The control code \"cmsg\" is in the subject. Really post? ")
4115 ;; Check long header lines.
4116 (message-check 'long-header-lines
4117 (let ((start (point))
4121 (while (and (not found)
4122 (re-search-forward "^\\([^ \t:]+\\): " nil t))
4123 (if (> (- (point) (match-beginning 0)) 998)
4125 length (- (point) (match-beginning 0)))
4126 (setq header (match-string-no-properties 1)))
4127 (setq start (match-beginning 0))
4130 (y-or-n-p (format "Your %s header is too long (%d). Really post? "
4133 ;; Check for multiple identical headers.
4134 (message-check 'multiple-headers
4136 (while (and (not found)
4137 (re-search-forward "^[^ \t:]+: " nil t))
4139 (or (re-search-forward
4144 (match-beginning 0) (- (match-end 0) 2))))
4149 (y-or-n-p (format "Multiple %s headers. Really post? " found))
4151 ;; Check for Version and Sendsys.
4152 (message-check 'sendsys
4153 (if (re-search-forward "^Sendsys:\\|^Version:" nil t)
4155 (format "The article contains a %s command. Really post? "
4156 (buffer-substring (match-beginning 0)
4157 (1- (match-end 0)))))
4159 ;; See whether we can shorten Followup-To.
4160 (message-check 'shorten-followup-to
4161 (let ((newsgroups (message-fetch-field "newsgroups"))
4162 (followup-to (message-fetch-field "followup-to"))
4164 (when (and newsgroups
4165 (string-match "," newsgroups)
4170 (setq to (completing-read
4171 "Followups to (default: no Followup-To header) "
4174 (message-tokenize-header
4176 (goto-char (point-min))
4177 (insert "Followup-To: " to "\n"))
4179 ;; Check "Shoot me".
4180 (message-check 'shoot
4181 (if (re-search-forward
4182 "Message-ID.*.i-did-not-set--mail-host-address--so-tickle-me" nil t)
4183 (y-or-n-p "You appear to have a misconfigured system. Really post? ")
4185 ;; Check for Approved.
4186 (message-check 'approved
4187 (if (re-search-forward "^Approved:" nil t)
4188 (y-or-n-p "The article contains an Approved header. Really post? ")
4190 ;; Check the Message-ID header.
4191 (message-check 'message-id
4192 (let* ((case-fold-search t)
4193 (message-id (message-fetch-field "message-id" t)))
4194 (or (not message-id)
4195 ;; Is there an @ in the ID?
4196 (and (string-match "@" message-id)
4197 ;; Is there a dot in the ID?
4198 (string-match "@[^.]*\\." message-id)
4199 ;; Does the ID end with a dot?
4200 (not (string-match "\\.>" message-id)))
4202 (format "The Message-ID looks strange: \"%s\". Really post? "
4204 ;; Check the Newsgroups & Followup-To headers.
4205 (message-check 'existing-newsgroups
4206 (let* ((case-fold-search t)
4207 (newsgroups (message-fetch-field "newsgroups"))
4208 (followup-to (message-fetch-field "followup-to"))
4209 (groups (message-tokenize-header
4211 (concat newsgroups "," followup-to)
4213 (post-method (if (functionp message-post-method)
4214 (funcall message-post-method)
4215 message-post-method))
4216 ;; KLUDGE to handle nnvirtual groups. Doing this right
4217 ;; would probably involve a new nnoo function.
4218 ;; -- Per Abrahamsen <abraham@dina.kvl.dk>, 2001-10-17.
4219 (method (if (and (consp post-method)
4220 (eq (car post-method) 'nnvirtual)
4221 gnus-message-group-art)
4222 (let ((group (car (nnvirtual-find-group-art
4223 (car gnus-message-group-art)
4224 (cdr gnus-message-group-art)))))
4225 (gnus-find-method-for-group group))
4229 (gnus-group-name-decode
4230 (gnus-group-real-name n)
4231 (gnus-group-name-charset method n)))
4232 (gnus-groups-from-server method)))
4235 (when (and (not (equal (car groups) "poster"))
4236 (not (member (car groups) known-groups))
4237 (not (member (car groups) errors)))
4238 (push (car groups) errors))
4241 ;; Gnus is not running.
4242 ((or (not (and (boundp 'gnus-active-hashtb)
4243 gnus-active-hashtb))
4244 (not (boundp 'gnus-read-active-file)))
4246 ;; We don't have all the group names.
4247 ((and (or (not gnus-read-active-file)
4248 (eq gnus-read-active-file 'some))
4252 "Really use %s possibly unknown group%s: %s? "
4253 (if (= (length errors) 1) "this" "these")
4254 (if (= (length errors) 1) "" "s")
4255 (mapconcat 'identity errors ", "))))
4256 ;; There were no errors.
4259 ;; There are unknown groups.
4263 "Really post to %s unknown group%s: %s? "
4264 (if (= (length errors) 1) "this" "these")
4265 (if (= (length errors) 1) "" "s")
4266 (mapconcat 'identity errors ", ")))))))
4267 ;; Check continuation headers.
4268 (message-check 'continuation-headers
4269 (goto-char (point-min))
4270 (let ((do-posting t))
4271 (while (re-search-forward "^[^ \t\n][^:\n]*$" nil t)
4272 (if (y-or-n-p "Fix continuation lines? ")
4274 (goto-char (match-beginning 0))
4276 (unless (y-or-n-p "Send anyway? ")
4277 (setq do-posting nil))))
4279 ;; Check the Newsgroups & Followup-To headers for syntax errors.
4280 (message-check 'valid-newsgroups
4281 (let ((case-fold-search t)
4282 (headers '("Newsgroups" "Followup-To"))
4284 (while (and headers (not error))
4285 (when (setq header (mail-fetch-field (car headers)))
4289 "\\`\\([-+_&.a-zA-Z0-9]+\\)?\\(,[-+_&.a-zA-Z0-9]+\\)*\\'"
4294 (not (string-match "\\.\\'\\|\\.\\." g)))
4295 (message-tokenize-header header ","))))
4302 (format "The %s header looks odd: \"%s\". Really post? "
4303 (car headers) header)))))
4304 (message-check 'repeated-newsgroups
4305 (let ((case-fold-search t)
4306 (headers '("Newsgroups" "Followup-To"))
4307 header error groups group)
4310 (when (setq header (mail-fetch-field (pop headers)))
4311 (setq groups (message-tokenize-header header ","))
4312 (while (setq group (pop groups))
4313 (when (member group groups)
4319 (format "Group %s is repeated in headers. Really post? " error)))))
4320 ;; Check the From header.
4321 (message-check 'from
4322 (let* ((case-fold-search t)
4323 (from (message-fetch-field "from"))
4327 (message "There is no From line. Posting is denied.")
4329 ((or (not (string-match
4331 (setq ad (nth 1 (mail-extract-address-components
4332 from))))) ;larsi@ifi
4333 (string-match "\\.\\." ad) ;larsi@ifi..uio
4334 (string-match "@\\." ad) ;larsi@.ifi.uio
4335 (string-match "\\.$" ad) ;larsi@ifi.uio.
4336 (not (string-match "^[^@]+@[^@]+$" ad)) ;larsi.ifi.uio
4337 (string-match "(.*).*(.*)" from)) ;(lars) (lars)
4339 "Denied posting -- the From looks strange: \"%s\"." from)
4341 ((let ((addresses (rfc822-addresses from)))
4342 (while (and addresses
4343 (not (eq (string-to-char (car addresses)) ?\()))
4344 (setq addresses (cdr addresses)))
4347 "Denied posting -- bad From address: \"%s\"." from)
4350 ;; Check the Reply-To header.
4351 (message-check 'reply-to
4352 (let* ((case-fold-search t)
4353 (reply-to (message-fetch-field "reply-to"))
4358 ((string-match "," reply-to)
4360 (format "Multiple Reply-To addresses: \"%s\". Really post? "
4362 ((or (not (string-match
4364 (setq ad (nth 1 (mail-extract-address-components
4365 reply-to))))) ;larsi@ifi
4366 (string-match "\\.\\." ad) ;larsi@ifi..uio
4367 (string-match "@\\." ad) ;larsi@.ifi.uio
4368 (string-match "\\.$" ad) ;larsi@ifi.uio.
4369 (not (string-match "^[^@]+@[^@]+$" ad)) ;larsi.ifi.uio
4370 (string-match "(.*).*(.*)" reply-to)) ;(lars) (lars)
4373 "The Reply-To looks strange: \"%s\". Really post? "
4377 (defun message-check-news-body-syntax ()
4379 ;; Check for long lines.
4380 (message-check 'long-lines
4381 (goto-char (point-min))
4383 (concat "^" (regexp-quote mail-header-separator) "$"))
4387 "<#\\(/\\)?\\(multipart\\|part\\|external\\|mml\\)")
4390 (< (- (point) p) 80)))
4391 (zerop (forward-line 1))))
4395 "You have lines longer than 79 characters. Really post? ")))
4396 ;; Check whether the article is empty.
4397 (message-check 'empty
4398 (goto-char (point-min))
4400 (concat "^" (regexp-quote mail-header-separator) "$"))
4403 (goto-char (point-max))
4404 (re-search-backward message-signature-separator nil t)
4406 (or (re-search-backward "[^ \n\t]" b t)
4407 (if (message-gnksa-enable-p 'empty-article)
4408 (y-or-n-p "Empty article. Really post? ")
4409 (message "Denied posting -- Empty article.")
4411 ;; Check for control characters.
4412 (message-check 'control-chars
4413 (if (re-search-forward
4414 (mm-string-as-multibyte "[\000-\007\013\015-\032\034-\037\200-\237]")
4417 "The article contains control characters. Really post? ")
4419 ;; Check excessive size.
4420 (message-check 'size
4421 (if (> (buffer-size) 60000)
4423 (format "The article is %d octets long. Really post? "
4426 ;; Check whether any new text has been added.
4427 (message-check 'new-text
4429 (not message-checksum)
4430 (not (eq (message-checksum) message-checksum))
4431 (if (message-gnksa-enable-p 'quoted-text-only)
4433 "It looks like no new text has been added. Really post? ")
4434 (message "Denied posting -- no new text has been added.")
4436 ;; Check the length of the signature.
4437 (message-check 'signature
4438 (goto-char (point-max))
4439 (if (> (count-lines (point) (point-max)) 5)
4442 "Your .sig is %d lines; it should be max 4. Really post? "
4443 (1- (count-lines (point) (point-max)))))
4445 ;; Ensure that text follows last quoted portion.
4446 (message-check 'quoting-style
4447 (goto-char (point-max))
4448 (let ((no-problem t))
4449 (when (search-backward-regexp "^>[^\n]*\n" nil t)
4450 (setq no-problem (search-forward-regexp "^[ \t]*[^>\n]" nil t)))
4453 (if (message-gnksa-enable-p 'quoted-text-only)
4454 (y-or-n-p "Your text should follow quoted text. Really post? ")
4456 (goto-char (point-min))
4458 (concat "^" (regexp-quote mail-header-separator) "$"))
4459 (if (search-forward-regexp "^[ \t]*[^>\n]" nil t)
4460 (y-or-n-p "Your text should follow quoted text. Really post? ")
4461 (message "Denied posting -- only quoted text.")
4464 (defun message-checksum ()
4465 "Return a \"checksum\" for the current buffer."
4468 (goto-char (point-min))
4470 (concat "^" (regexp-quote mail-header-separator) "$"))
4472 (when (not (looking-at "[ \t\n]"))
4473 (setq sum (logxor (ash sum 1) (if (natnump sum) 0 1)
4478 (defun message-do-fcc ()
4479 "Process Fcc headers in the current buffer."
4480 (let ((case-fold-search t)
4481 (buf (current-buffer))
4483 (mml-externalize-attachments message-fcc-externalize-attachments))
4486 (message-narrow-to-headers)
4487 (setq file (message-fetch-field "fcc" t)))
4489 (set-buffer (get-buffer-create " *message temp*"))
4491 (insert-buffer-substring buf)
4492 (message-encode-message-body)
4494 (message-narrow-to-headers)
4495 (while (setq file (message-fetch-field "fcc" t))
4497 (message-remove-header "fcc" nil t))
4498 (let ((mail-parse-charset message-default-charset)
4499 (rfc2047-header-encoding-alist
4500 (cons '("Newsgroups" . default)
4501 rfc2047-header-encoding-alist)))
4502 (mail-encode-encoded-word-buffer)))
4503 (goto-char (point-min))
4504 (when (re-search-forward
4505 (concat "^" (regexp-quote mail-header-separator) "$")
4507 (replace-match "" t t ))
4508 ;; Process FCC operations.
4510 (setq file (pop list))
4511 (if (string-match "^[ \t]*|[ \t]*\\(.*\\)[ \t]*$" file)
4512 ;; Pipe the article to the program in question.
4513 (call-process-region (point-min) (point-max) shell-file-name
4514 nil nil nil shell-command-switch
4515 (match-string 1 file))
4516 ;; Save the article.
4517 (setq file (expand-file-name file))
4518 (unless (file-exists-p (file-name-directory file))
4519 (make-directory (file-name-directory file) t))
4520 (if (and message-fcc-handler-function
4521 (not (eq message-fcc-handler-function 'rmail-output)))
4522 (funcall message-fcc-handler-function file)
4523 (if (and (file-readable-p file) (mail-file-babyl-p file))
4524 (rmail-output file 1 nil t)
4525 (let ((mail-use-rfc822 t))
4526 (rmail-output file 1 t t))))))
4527 (kill-buffer (current-buffer))))))
4529 (defun message-output (filename)
4530 "Append this article to Unix/babyl mail file FILENAME."
4531 (if (and (file-readable-p filename)
4532 (mail-file-babyl-p filename))
4533 (gnus-output-to-rmail filename t)
4534 (gnus-output-to-mail filename t)))
4536 (defun message-cleanup-headers ()
4537 "Do various automatic cleanups of the headers."
4538 ;; Remove empty lines in the header.
4540 (message-narrow-to-headers)
4541 ;; Remove blank lines.
4542 (while (re-search-forward "^[ \t]*\n" nil t)
4543 (replace-match "" t t))
4545 ;; Correct Newsgroups and Followup-To headers: Change sequence of
4546 ;; spaces to comma and eliminate spaces around commas. Eliminate
4547 ;; embedded line breaks.
4548 (goto-char (point-min))
4549 (while (re-search-forward "^\\(Newsgroups\\|Followup-To\\): +" nil t)
4553 (if (re-search-forward "^[^ \t]" nil t)
4557 (goto-char (point-min))
4558 (while (re-search-forward "\n[ \t]+" nil t)
4559 (replace-match " " t t)) ;No line breaks (too confusing)
4560 (goto-char (point-min))
4561 (while (re-search-forward "[ \t\n]*,[ \t\n]*\\|[ \t]+" nil t)
4562 (replace-match "," t t))
4563 (goto-char (point-min))
4564 ;; Remove trailing commas.
4565 (when (re-search-forward ",+$" nil t)
4566 (replace-match "" t t))))))
4568 (eval-when-compile (require 'parse-time))
4569 (defun message-make-date (&optional now)
4570 "Make a valid data header.
4571 If NOW, use that time instead."
4572 (require 'parse-time)
4573 (let* ((now (or now (current-time)))
4574 (zone (nth 8 (decode-time now)))
4578 (setq zone (- zone)))
4580 ;; The day name of the %a spec is locale-specific. Pfff.
4581 (format "%s, " (capitalize (car (rassoc (nth 6 (decode-time now))
4582 parse-time-weekdays))))
4583 (format-time-string "%d" now)
4584 ;; The month name of the %b spec is locale-specific. Pfff.
4586 (capitalize (car (rassoc (nth 4 (decode-time now))
4587 parse-time-months))))
4588 (format-time-string "%Y %H:%M:%S " now)
4589 ;; We do all of this because XEmacs doesn't have the %z spec.
4590 (format "%s%02d%02d" sign (/ zone 3600) (/ (% zone 3600) 60)))))
4592 (defun message-make-message-id ()
4593 "Make a unique Message-ID."
4594 (concat "<" (message-unique-id)
4595 (let ((psubject (save-excursion (message-fetch-field "subject")))
4597 (save-excursion (message-fetch-field "supersedes"))))
4599 (and message-reply-headers
4600 (mail-header-references message-reply-headers)
4601 (mail-header-subject message-reply-headers)
4604 (message-strip-subject-re
4605 (mail-header-subject message-reply-headers))
4606 (message-strip-subject-re psubject))))
4608 (string-match "_-_@" psupersedes)))
4610 "@" (message-make-fqdn) ">"))
4612 (defvar message-unique-id-char nil)
4614 ;; If you ever change this function, make sure the new version
4615 ;; cannot generate IDs that the old version could.
4616 ;; You might for example insert a "." somewhere (not next to another dot
4617 ;; or string boundary), or modify the "fsf" string.
4618 (defun message-unique-id ()
4619 ;; Don't use microseconds from (current-time), they may be unsupported.
4620 ;; Instead we use this randomly inited counter.
4621 (setq message-unique-id-char
4622 (% (1+ (or message-unique-id-char (logand (random t) (1- (lsh 1 20)))))
4623 ;; (current-time) returns 16-bit ints,
4624 ;; and 2^16*25 just fits into 4 digits i base 36.
4626 (let ((tm (current-time)))
4628 (if (memq system-type '(ms-dos emx vax-vms))
4629 (let ((user (downcase (user-login-name))))
4630 (while (string-match "[^a-z0-9_]" user)
4631 (aset user (match-beginning 0) ?_))
4633 (message-number-base36 (user-uid) -1))
4634 (message-number-base36 (+ (car tm)
4635 (lsh (% message-unique-id-char 25) 16)) 4)
4636 (message-number-base36 (+ (nth 1 tm)
4637 (lsh (/ message-unique-id-char 25) 16)) 4)
4638 ;; Append a given name, because while the generated ID is unique
4639 ;; to this newsreader, other newsreaders might otherwise generate
4640 ;; the same ID via another algorithm.
4643 (defun message-number-base36 (num len)
4648 (concat (message-number-base36 (/ num 36) (1- len))
4649 (char-to-string (aref "zyxwvutsrqponmlkjihgfedcba9876543210"
4652 (defun message-make-organization ()
4653 "Make an Organization header."
4654 (let* ((organization
4655 (when message-user-organization
4656 (if (functionp message-user-organization)
4657 (funcall message-user-organization)
4658 message-user-organization))))
4660 (mm-enable-multibyte)
4661 (cond ((stringp organization)
4662 (insert organization))
4663 ((and (eq t organization)
4664 message-user-organization-file
4665 (file-exists-p message-user-organization-file))
4666 (insert-file-contents message-user-organization-file)))
4667 (goto-char (point-min))
4668 (while (re-search-forward "[\t\n]+" nil t)
4669 (replace-match "" t t))
4670 (unless (zerop (buffer-size))
4673 (defun message-make-lines ()
4674 "Count the number of lines and return numeric string."
4679 (int-to-string (count-lines (point) (point-max))))))
4681 (defun message-make-references ()
4682 "Return the References header for this message."
4683 (when message-reply-headers
4684 (let ((message-id (mail-header-message-id message-reply-headers))
4685 (references (mail-header-references message-reply-headers))
4687 (if (or references message-id)
4688 (concat (or references "") (and references " ")
4692 (defun message-make-in-reply-to ()
4693 "Return the In-Reply-To header for this message."
4694 (when message-reply-headers
4695 (let ((from (mail-header-from message-reply-headers))
4696 (date (mail-header-date message-reply-headers))
4697 (msg-id (mail-header-message-id message-reply-headers)))
4699 (let ((name (mail-extract-address-components from)))
4700 (concat msg-id (if msg-id " (")
4704 (if (or (not date) (string= date ""))
4705 "(unknown date)" date)
4706 "\"" (if msg-id ")")))))))
4708 (defun message-make-distribution ()
4709 "Make a Distribution header."
4710 (let ((orig-distribution (message-fetch-reply-field "distribution")))
4711 (cond ((functionp message-distribution-function)
4712 (funcall message-distribution-function))
4713 (t orig-distribution))))
4715 (defun message-make-expires ()
4716 "Return an Expires header based on `message-expires'."
4717 (let ((current (current-time))
4718 (future (* 1.0 message-expires 60 60 24)))
4719 ;; Add the future to current.
4720 (setcar current (+ (car current) (round (/ future (expt 2 16)))))
4721 (setcar (cdr current) (+ (nth 1 current) (% (round future) (expt 2 16))))
4722 (message-make-date current)))
4724 (defun message-make-path ()
4726 (let ((login-name (user-login-name)))
4727 (cond ((null message-user-path)
4728 (concat (system-name) "!" login-name))
4729 ((stringp message-user-path)
4730 ;; Support GENERICPATH. Suggested by vixie@decwrl.dec.com.
4731 (concat message-user-path "!" login-name))
4734 (defun message-make-from ()
4735 "Make a From header."
4736 (let* ((style message-from-style)
4737 (login (message-make-address))
4739 (or (and (boundp 'user-full-name)
4742 (when (string= fullname "&")
4743 (setq fullname (user-login-name)))
4745 (mm-enable-multibyte)
4748 (equal fullname ""))
4750 ((or (eq style 'angles)
4751 (and (not (eq style 'parens))
4752 ;; Use angles if no quoting is needed, or if parens would
4753 ;; need quoting too.
4754 (or (not (string-match "[^- !#-'*+/-9=?A-Z^-~]" fullname))
4755 (let ((tmp (concat fullname nil)))
4756 (while (string-match "([^()]*)" tmp)
4757 (aset tmp (match-beginning 0) ?-)
4758 (aset tmp (1- (match-end 0)) ?-))
4759 (string-match "[\\()]" tmp)))))
4761 (goto-char (point-min))
4762 ;; Look for a character that cannot appear unquoted
4763 ;; according to RFC 822.
4764 (when (re-search-forward "[^- !#-'*+/-9=?A-Z^-~]" nil 1)
4765 ;; Quote fullname, escaping specials.
4766 (goto-char (point-min))
4768 (while (re-search-forward "[\"\\]" nil 1)
4769 (replace-match "\\\\\\&" t))
4771 (insert " <" login ">"))
4772 (t ; 'parens or default
4774 (let ((fullname-start (point)))
4776 (goto-char fullname-start)
4777 ;; RFC 822 says \ and nonmatching parentheses
4778 ;; must be escaped in comments.
4779 ;; Escape every instance of ()\ ...
4780 (while (re-search-forward "[()\\]" nil 1)
4781 (replace-match "\\\\\\&" t))
4782 ;; ... then undo escaping of matching parentheses,
4783 ;; including matching nested parentheses.
4784 (goto-char fullname-start)
4785 (while (re-search-forward
4786 "\\(\\=\\|[^\\]\\(\\\\\\\\\\)*\\)\\\\(\\(\\([^\\]\\|\\\\\\\\\\)*\\)\\\\)"
4788 (replace-match "\\1(\\3)" t)
4789 (goto-char fullname-start)))
4793 (defun message-make-sender ()
4794 "Return the \"real\" user address.
4795 This function tries to ignore all user modifications, and
4796 give as trustworthy answer as possible."
4797 (concat (user-login-name) "@" (system-name)))
4799 (defun message-make-address ()
4800 "Make the address of the user."
4801 (or (message-user-mail-address)
4802 (concat (user-login-name) "@" (message-make-domain))))
4804 (defun message-user-mail-address ()
4805 "Return the pertinent part of `user-mail-address'."
4806 (when (and user-mail-address
4807 (string-match "@.*\\." user-mail-address))
4808 (if (string-match " " user-mail-address)
4809 (nth 1 (mail-extract-address-components user-mail-address))
4810 user-mail-address)))
4812 (defun message-sendmail-envelope-from ()
4813 "Return the envelope from."
4814 (cond ((eq message-sendmail-envelope-from 'header)
4815 (nth 1 (mail-extract-address-components
4816 (message-fetch-field "from"))))
4817 ((stringp message-sendmail-envelope-from)
4818 message-sendmail-envelope-from)
4820 (message-make-address))))
4822 (defun message-make-fqdn ()
4823 "Return user's fully qualified domain name."
4824 (let* ((system-name (system-name))
4825 (user-mail (message-user-mail-address))
4828 (string-match "@\\(.*\\)\\'" user-mail))
4829 (match-string 1 user-mail)))
4830 (case-fold-search t))
4832 ((and message-user-fqdn
4833 (stringp message-user-fqdn)
4834 (string-match message-valid-fqdn-regexp message-user-fqdn)
4835 (not (string-match message-bogus-system-names message-user-fqdn)))
4837 ;; `message-user-fqdn' seems to be valid
4838 ((and (string-match message-valid-fqdn-regexp system-name)
4839 (not (string-match message-bogus-system-names system-name)))
4840 ;; `system-name' returned the right result.
4842 ;; Try `mail-host-address'.
4843 ((and (boundp 'mail-host-address)
4844 (stringp mail-host-address)
4845 (string-match message-valid-fqdn-regexp mail-host-address)
4846 (not (string-match message-bogus-system-names mail-host-address)))
4848 ;; We try `user-mail-address' as a backup.
4850 (stringp user-domain)
4851 (string-match message-valid-fqdn-regexp user-domain)
4852 (not (string-match message-bogus-system-names user-domain)))
4854 ;; Default to this bogus thing.
4857 ".i-did-not-set--mail-host-address--so-tickle-me")))))
4859 (defun message-make-host-name ()
4860 "Return the name of the host."
4861 (let ((fqdn (message-make-fqdn)))
4862 (string-match "^[^.]+\\." fqdn)
4863 (substring fqdn 0 (1- (match-end 0)))))
4865 (defun message-make-domain ()
4866 "Return the domain name."
4867 (or mail-host-address
4868 (message-make-fqdn)))
4870 (defun message-to-list-only ()
4871 "Send a message to the list only.
4872 Remove all addresses but the list address from To and Cc headers."
4874 (let ((listaddr (message-make-mail-followup-to t)))
4877 (message-remove-header "to")
4878 (message-remove-header "cc")
4879 (message-position-on-field "To" "X-Draft-From")
4880 (insert listaddr)))))
4882 (defun message-make-mail-followup-to (&optional only-show-subscribed)
4883 "Return the Mail-Followup-To header.
4884 If passed the optional argument ONLY-SHOW-SUBSCRIBED only return the
4885 subscribed address (and not the additional To and Cc header contents)."
4886 (let* ((case-fold-search t)
4887 (to (message-fetch-field "To"))
4888 (cc (message-fetch-field "cc"))
4889 (msg-recipients (concat to (and to cc ", ") cc))
4891 (mapcar 'mail-strip-quoted-names
4892 (message-tokenize-header msg-recipients)))
4894 (if message-subscribed-address-file
4895 (let (begin end item re)
4898 (insert-file-contents message-subscribed-address-file)
4900 (setq begin (point))
4903 (if (bolp) (setq end (1- end)))
4904 (setq item (regexp-quote (buffer-substring begin end)))
4905 (if re (setq re (concat re "\\|" item))
4906 (setq re (concat "\\`\\(" item))))
4907 (and re (list (concat re "\\)\\'"))))))))
4908 (mft-regexps (apply 'append message-subscribed-regexps
4909 (mapcar 'regexp-quote
4910 message-subscribed-addresses)
4913 message-subscribed-address-functions))))
4915 (let ((subscribed-lists nil)
4917 (loop for recipient in recipients
4918 when (loop for regexp in mft-regexps
4919 when (string-match regexp recipient) return t)
4922 (if only-show-subscribed
4924 msg-recipients))))))
4926 (defun message-idna-to-ascii-rhs-1 (header)
4927 "Interactively potentially IDNA encode domain names in HEADER."
4928 (let ((field (message-fetch-field header))
4931 (dolist (address (mail-header-parse-addresses field))
4932 (setq address (car address)
4933 rhs (downcase (or (cadr (split-string address "@")) ""))
4934 ace (downcase (idna-to-ascii rhs)))
4935 (when (and (not (equal rhs ace))
4936 (or (not (eq message-use-idna 'ask))
4937 (y-or-n-p (format "Replace %s with %s? " rhs ace))))
4938 (goto-char (point-min))
4939 (while (re-search-forward (concat "^" header ":") nil t)
4940 (message-narrow-to-field)
4941 (while (search-forward (concat "@" rhs) nil t)
4942 (replace-match (concat "@" ace) t t))
4943 (goto-char (point-max))
4946 (defun message-idna-to-ascii-rhs ()
4947 "Possibly IDNA encode non-ASCII domain names in From:, To: and Cc: headers.
4948 See `message-idna-encode'."
4950 (when message-use-idna
4953 (message-narrow-to-head)
4954 (message-idna-to-ascii-rhs-1 "From")
4955 (message-idna-to-ascii-rhs-1 "To")
4956 (message-idna-to-ascii-rhs-1 "Cc")))))
4958 (defun message-generate-headers (headers)
4959 "Prepare article HEADERS.
4960 Headers already prepared in the buffer are not modified."
4961 (setq headers (append headers message-required-headers))
4963 (message-narrow-to-headers)
4964 (let* ((Date (message-make-date))
4965 (Message-ID (message-make-message-id))
4966 (Organization (message-make-organization))
4967 (From (message-make-from))
4968 (Path (message-make-path))
4971 (In-Reply-To (message-make-in-reply-to))
4972 (References (message-make-references))
4974 (Distribution (message-make-distribution))
4975 (Lines (message-make-lines))
4976 (User-Agent message-newsreader)
4977 (Expires (message-make-expires))
4978 (case-fold-search t)
4980 header value elem header-string)
4981 ;; First we remove any old generated headers.
4982 (let ((headers message-deletable-headers))
4983 (unless (buffer-modified-p)
4984 (setq headers (delq 'Message-ID (copy-sequence headers))))
4986 (goto-char (point-min))
4987 (and (re-search-forward
4988 (concat "^" (symbol-name (car headers)) ": *") nil t)
4989 (get-text-property (1+ (match-beginning 0)) 'message-deletable)
4990 (message-delete-line))
4992 ;; Go through all the required headers and see if they are in the
4993 ;; articles already. If they are not, or are empty, they are
4994 ;; inserted automatically - except for Subject, Newsgroups and
4997 (goto-char (point-min))
4998 (setq elem (pop headers))
5000 (if (eq (car elem) 'optional)
5001 (setq header (cdr elem)
5003 (setq header (car elem)))
5005 (setq header-string (if (stringp header)
5007 (symbol-name header)))
5008 (when (or (not (re-search-forward
5010 (regexp-quote (downcase header-string))
5014 ;; The header was found. We insert a space after the
5015 ;; colon, if there is none.
5016 (if (/= (char-after) ? ) (insert " ") (forward-char 1))
5017 ;; Find out whether the header is empty.
5018 (looking-at "[ \t]*\n[^ \t]")))
5019 ;; So we find out what value we should insert.
5023 (eq (car elem) 'optional)
5024 (not (member header-string message-inserted-headers)))
5025 ;; This is an optional header. If the cdr of this
5026 ;; is something that is nil, then we do not insert
5028 (setq header (cdr elem))
5029 (or (and (functionp (cdr elem))
5030 (funcall (cdr elem)))
5031 (and (boundp (cdr elem))
5032 (symbol-value (cdr elem)))))
5034 ;; The element is a cons. Either the cdr is a
5035 ;; string to be inserted verbatim, or it is a
5036 ;; function, and we insert the value returned from
5038 (or (and (stringp (cdr elem))
5040 (and (functionp (cdr elem))
5041 (funcall (cdr elem)))))
5042 ((and (boundp header)
5043 (symbol-value header))
5044 ;; The element is a symbol. We insert the value
5045 ;; of this symbol, if any.
5046 (symbol-value header))
5047 ((not (message-check-element header))
5048 ;; We couldn't generate a value for this header,
5049 ;; so we just ask the user.
5050 (read-from-minibuffer
5051 (format "Empty header for %s; enter value: " header)))))
5052 ;; Finally insert the header.
5054 (not (equal value "")))
5058 ;; This header didn't exist, so we insert it.
5059 (goto-char (point-max))
5061 (cdr (assq header message-header-format-alist))))
5063 (funcall formatter header value)
5064 (insert header-string ": " value))
5065 ;; We check whether the value was ended by a
5066 ;; newline. If now, we insert one.
5070 ;; The value of this header was empty, so we clear
5071 ;; totally and insert the new value.
5072 (delete-region (point) (gnus-point-at-eol))
5073 ;; If the header is optional, and the header was
5074 ;; empty, we con't insert it anyway.
5076 (push header-string message-inserted-headers)
5078 ;; Add the deletable property to the headers that require it.
5079 (and (memq header message-deletable-headers)
5080 (progn (beginning-of-line) (looking-at "[^:]+: "))
5081 (add-text-properties
5082 (point) (match-end 0)
5083 '(message-deletable t face italic) (current-buffer)))))))
5084 ;; Insert new Sender if the From is strange.
5085 (let ((from (message-fetch-field "from"))
5086 (sender (message-fetch-field "sender"))
5087 (secure-sender (message-make-sender)))
5089 (not (message-check-element 'sender))
5092 (cadr (mail-extract-address-components from)))
5093 (downcase secure-sender)))
5098 (cadr (mail-extract-address-components sender)))
5099 (downcase secure-sender)))))
5100 (goto-char (point-min))
5101 ;; Rename any old Sender headers to Original-Sender.
5102 (when (re-search-forward "^\\(Original-\\)*Sender:" nil t)
5104 (insert "Original-")
5105 (beginning-of-line))
5106 (when (or (message-news-p)
5107 (string-match "@.+\\.." secure-sender))
5108 (insert "Sender: " secure-sender "\n"))))
5110 (message-idna-to-ascii-rhs))))
5112 (defun message-insert-courtesy-copy ()
5113 "Insert a courtesy message in mail copies of combined messages."
5117 (message-narrow-to-headers)
5118 (when (setq newsgroups (message-fetch-field "newsgroups"))
5119 (goto-char (point-max))
5120 (insert "Posted-To: " newsgroups "\n")))
5122 (when message-courtesy-message
5124 ((string-match "%s" message-courtesy-message)
5125 (insert (format message-courtesy-message newsgroups)))
5127 (insert message-courtesy-message)))))))
5130 ;;; Setting up a message buffer
5133 (defun message-fill-address (header value)
5135 (narrow-to-region (point) (point))
5136 (insert (capitalize (symbol-name header))
5138 (if (consp value) (car value) value)
5140 (narrow-to-region (point-min) (1- (point-max)))
5142 (goto-char (point-min))
5144 (skip-chars-forward "^,\"" (point-max))
5145 (if (or (eq (char-after) ?,)
5148 (if (and (> (current-column) 78)
5154 (setq last (1+ (point))))
5155 (setq last (1+ (point)))))
5156 (setq quoted (not quoted)))
5159 (goto-char (point-max))
5163 (defun message-split-line ()
5164 "Split current line, moving portion beyond point vertically down.
5165 If the current line has `message-yank-prefix', insert it on the new line."
5168 (split-line message-yank-prefix) ;; Emacs 22.1+ supports arg.
5172 (defun message-fill-header (header value)
5173 (let ((begin (point))
5176 (insert (capitalize (symbol-name header))
5178 (if (consp value) (car value) value)
5181 (narrow-to-region begin (point))
5182 (fill-region-as-paragraph begin (point))
5183 ;; Tapdance around looong Message-IDs.
5185 (when (looking-at "[ \t]*$")
5186 (message-delete-line))
5188 (re-search-forward ":" nil t)
5189 (when (looking-at "\n[ \t]+")
5190 (replace-match " " t t))
5191 (goto-char (point-max)))))
5193 (defun message-shorten-1 (list cut surplus)
5194 "Cut SURPLUS elements out of LIST, beginning with CUTth one."
5195 (setcdr (nthcdr (- cut 2) list)
5196 (nthcdr (+ (- cut 2) surplus 1) list)))
5198 (defun message-shorten-references (header references)
5199 "Trim REFERENCES to be 21 Message-ID long or less, and fold them.
5200 If folding is disallowed, also check that the REFERENCES are less
5201 than 988 characters long, and if they are not, trim them until they are."
5208 (goto-char (point-min))
5209 ;; Cons a list of valid references.
5210 (while (re-search-forward "<[^>]+>" nil t)
5211 (push (match-string 0) refs))
5212 (setq refs (nreverse refs)
5213 count (length refs)))
5215 ;; If the list has more than MAXCOUNT elements, trim it by
5216 ;; removing the CUTth element and the required number of
5217 ;; elements that follow.
5218 (when (> count maxcount)
5219 (let ((surplus (- count maxcount)))
5220 (message-shorten-1 refs cut surplus)
5221 (decf count surplus)))
5223 ;; If folding is disallowed, make sure the total length (including
5224 ;; the spaces between) will be less than MAXSIZE characters.
5226 ;; Only disallow folding for News messages. At this point the headers
5227 ;; have not been generated, thus we use message-this-is-news directly.
5228 (when (and message-this-is-news message-cater-to-broken-inn)
5230 (totalsize (+ (apply #'+ (mapcar #'length refs))
5233 (ptr (nthcdr (1- cut) refs)))
5234 ;; Decide how many elements to cut off...
5235 (while (> totalsize maxsize)
5236 (decf totalsize (1+ (length (car ptr))))
5238 (setq ptr (cdr ptr)))
5241 (message-shorten-1 refs cut surplus))))
5243 ;; Finally, collect the references back into a string and insert
5244 ;; it into the buffer.
5245 (let ((refstring (mapconcat #'identity refs " ")))
5246 (if (and message-this-is-news message-cater-to-broken-inn)
5247 (insert (capitalize (symbol-name header)) ": "
5249 (message-fill-header header refstring)))))
5251 (defun message-position-point ()
5252 "Move point to where the user probably wants to find it."
5253 (message-narrow-to-headers)
5255 ((re-search-forward "^[^:]+:[ \t]*$" nil t)
5256 (search-backward ":" )
5259 (if (eq (char-after) ? )
5263 (goto-char (point-max))
5266 (unless (looking-at "$")
5270 (defcustom message-beginning-of-line t
5271 "Whether \\<message-mode-map>\\[message-beginning-of-line]\
5272 goes to beginning of header values."
5274 :group 'message-buffers
5275 :link '(custom-manual "(message)Movement")
5278 (defun message-beginning-of-line (&optional n)
5279 "Move point to beginning of header value or to beginning of line.
5280 The prefix argument N is passed directly to `beginning-of-line'.
5282 This command is identical to `beginning-of-line' if point is
5283 outside the message header or if the option `message-beginning-of-line'
5286 If point is in the message header and on a (non-continued) header
5287 line, move point to the beginning of the header value or the beginning of line,
5288 whichever is closer. If point is already at beginning of line, move point to
5289 beginning of header value. Therefore, repeated calls will toggle point
5290 between beginning of field and beginning of line."
5292 (let ((zrs 'zmacs-region-stays))
5293 (when (and (interactive-p) (boundp zrs))
5295 (if (and message-beginning-of-line
5296 (message-point-in-header-p))
5297 (let* ((here (point))
5298 (bol (progn (beginning-of-line n) (point)))
5299 (eol (gnus-point-at-eol))
5300 (eoh (re-search-forward ": *" eol t)))
5302 (if (and eoh (or (< eoh here) (= bol here)))
5304 (beginning-of-line n)))
5306 (defun message-buffer-name (type &optional to group)
5307 "Return a new (unique) buffer name based on TYPE and TO."
5309 ;; Generate a new buffer name The Message Way.
5310 ((eq message-generate-new-buffers 'unique)
5311 (generate-new-buffer-name
5315 (or (car (mail-extract-address-components to))
5318 (if (and group (not (string= group ""))) (concat " on " group) "")
5320 ;; Check whether `message-generate-new-buffers' is a function,
5321 ;; and if so, call it.
5322 ((functionp message-generate-new-buffers)
5323 (funcall message-generate-new-buffers type to group))
5324 ((eq message-generate-new-buffers 'unsent)
5325 (generate-new-buffer-name
5326 (concat "*unsent " type
5329 (or (car (mail-extract-address-components to))
5332 (if (and group (not (string= group ""))) (concat " on " group) "")
5334 ;; Use standard name.
5336 (format "*%s message*" type))))
5338 (defun message-pop-to-buffer (name)
5339 "Pop to buffer NAME, and warn if it already exists and is modified."
5340 (let ((buffer (get-buffer name)))
5342 (buffer-name buffer))
5344 (set-buffer (pop-to-buffer buffer))
5345 (when (and (buffer-modified-p)
5347 "Message already being composed; erase? ")))
5348 (error "Message being composed")))
5349 (set-buffer (pop-to-buffer name)))
5353 (defun message-do-send-housekeeping ()
5354 "Kill old message buffers."
5355 ;; We might have sent this buffer already. Delete it from the
5357 (setq message-buffer-list (delq (current-buffer) message-buffer-list))
5358 (while (and message-max-buffers
5360 (>= (length message-buffer-list) message-max-buffers))
5361 ;; Kill the oldest buffer -- unless it has been changed.
5362 (let ((buffer (pop message-buffer-list)))
5363 (when (and (buffer-name buffer)
5364 (not (buffer-modified-p buffer)))
5365 (kill-buffer buffer))))
5366 ;; Rename the buffer.
5367 (if message-send-rename-function
5368 (funcall message-send-rename-function)
5369 ;; Note: mail-abbrevs of XEmacs renames buffer name behind Gnus.
5371 "\\`\\*\\(sent \\|unsent \\)?\\(.+\\)\\*[^\\*]*\\|\\`mail to "
5373 (let ((name (match-string 2 (buffer-name)))
5375 (if (not (or (null name)
5376 (string-equal name "mail")
5377 (string-equal name "posting")))
5378 (setq name (concat "*sent " name "*"))
5379 (message-narrow-to-headers)
5380 (setq to (message-fetch-field "to"))
5381 (setq group (message-fetch-field "newsgroups"))
5385 (to (concat "*sent mail to "
5386 (or (car (mail-extract-address-components to))
5388 ((and group (not (string= group "")))
5389 (concat "*sent posting on " group "*"))
5390 (t "*sent mail*"))))
5391 (unless (string-equal name (buffer-name))
5392 (rename-buffer name t)))))
5393 ;; Push the current buffer onto the list.
5394 (when message-max-buffers
5395 (setq message-buffer-list
5396 (nconc message-buffer-list (list (current-buffer))))))
5398 (defun message-mail-user-agent ()
5400 ((not message-mail-user-agent) nil)
5401 ((eq message-mail-user-agent t) mail-user-agent)
5402 (t message-mail-user-agent))))
5403 (if (memq mua '(message-user-agent gnus-user-agent))
5407 (defun message-setup (headers &optional replybuffer actions switch-function)
5408 (let ((mua (message-mail-user-agent))
5409 subject to field yank-action)
5410 (if (not (and message-this-is-mail mua))
5411 (message-setup-1 headers replybuffer actions)
5413 (setq yank-action (list 'insert-buffer replybuffer)))
5414 (setq headers (copy-sequence headers))
5415 (setq field (assq 'Subject headers))
5417 (setq subject (cdr field))
5418 (setq headers (delq field headers)))
5419 (setq field (assq 'To headers))
5421 (setq to (cdr field))
5422 (setq headers (delq field headers)))
5423 (let ((mail-user-agent mua))
5424 (compose-mail to subject
5425 (mapcar (lambda (item)
5427 (format "%s" (car item))
5430 nil switch-function yank-action actions)))))
5432 (defun message-headers-to-generate (headers included-headers excluded-headers)
5433 "Return a list that includes all headers from HEADERS.
5434 If INCLUDED-HEADERS is a list, just include those headers. If if is
5435 t, include all headers. In any case, headers from EXCLUDED-HEADERS
5439 (dolist (header headers)
5440 (setq header-name (cond
5441 ((and (consp header)
5442 (eq (car header) 'optional))
5443 ;; On the form (optional . Header)
5446 ;; On the form (Header . function)
5451 (when (and (not (memq header-name excluded-headers))
5452 (or (eq included-headers t)
5453 (memq header-name included-headers)))
5454 (push header result)))
5457 (defun message-setup-1 (headers &optional replybuffer actions)
5458 (dolist (action actions)
5460 (add-to-list 'message-send-actions
5461 `(apply ',(car action) ',(cdr action)))))
5462 (setq message-reply-buffer replybuffer)
5463 (goto-char (point-min))
5464 ;; Insert all the headers.
5467 (alist message-header-format-alist))
5469 (unless (assq (caar h) message-header-format-alist)
5470 (push (list (caar h)) alist))
5474 (delete-region (point) (progn (forward-line -1) (point)))
5475 (when message-default-headers
5476 (insert message-default-headers)
5477 (or (bolp) (insert ?\n)))
5481 (insert mail-header-separator "\n")
5485 (when (message-news-p)
5486 (when message-default-news-headers
5487 (insert message-default-news-headers)
5488 (or (bolp) (insert ?\n)))
5489 (when message-generate-headers-first
5490 (message-generate-headers
5491 (message-headers-to-generate
5492 (append message-required-news-headers
5493 message-required-headers)
5494 message-generate-headers-first
5495 '(Lines Subject)))))
5496 (when (message-mail-p)
5497 (when message-default-mail-headers
5498 (insert message-default-mail-headers)
5499 (or (bolp) (insert ?\n)))
5501 (message-narrow-to-headers)
5502 (if message-alternative-emails
5503 (message-use-alternative-email-as-from)))
5504 (when message-generate-headers-first
5505 (message-generate-headers
5506 (message-headers-to-generate
5507 (append message-required-mail-headers
5508 message-required-headers)
5509 message-generate-headers-first
5510 '(Lines Subject)))))
5511 (run-hooks 'message-signature-setup-hook)
5512 (message-insert-signature)
5514 (message-narrow-to-headers)
5515 (run-hooks 'message-header-setup-hook))
5516 (set-buffer-modified-p nil)
5517 (setq buffer-undo-list nil)
5518 (run-hooks 'message-setup-hook)
5519 (message-position-point)
5522 (defun message-set-auto-save-file-name ()
5523 "Associate the message buffer with a file in the drafts directory."
5524 (when message-auto-save-directory
5525 (unless (file-directory-p
5526 (directory-file-name message-auto-save-directory))
5527 (make-directory message-auto-save-directory t))
5529 (setq message-draft-article
5530 (nndraft-request-associate-buffer "drafts"))
5531 (setq buffer-file-name (expand-file-name
5532 (if (memq system-type
5533 '(ms-dos ms-windows windows-nt
5534 cygwin cygwin32 win32 w32
5538 message-auto-save-directory))
5539 (setq buffer-auto-save-file-name (make-auto-save-file-name)))
5540 (clear-visited-file-modtime)
5541 (setq buffer-file-coding-system message-draft-coding-system)))
5543 (defun message-disassociate-draft ()
5544 "Disassociate the message buffer from the drafts directory."
5545 (when message-draft-article
5546 (nndraft-request-expire-articles
5547 (list message-draft-article) "drafts" nil t)))
5549 (defun message-insert-headers ()
5550 "Generate the headers for the article."
5554 (message-narrow-to-headers)
5555 (when (message-news-p)
5556 (message-generate-headers
5559 (copy-sequence message-required-news-headers)))))
5560 (when (message-mail-p)
5561 (message-generate-headers
5564 (copy-sequence message-required-mail-headers))))))))
5569 ;;; Commands for interfacing with message
5573 (defun message-mail (&optional to subject
5574 other-headers continue switch-function
5575 yank-action send-actions)
5576 "Start editing a mail message to be sent.
5577 OTHER-HEADERS is an alist of header/value pairs."
5579 (let ((message-this-is-mail t) replybuffer)
5580 (unless (message-mail-user-agent)
5581 (message-pop-to-buffer (message-buffer-name "mail" to)))
5582 ;; FIXME: message-mail should do something if YANK-ACTION is not
5584 (and (consp yank-action) (eq (car yank-action) 'insert-buffer)
5585 (setq replybuffer (nth 1 yank-action)))
5588 `((To . ,(or to "")) (Subject . ,(or subject "")))
5589 (when other-headers other-headers))
5590 replybuffer send-actions)
5591 ;; FIXME: Should return nil if failure.
5595 (defun message-news (&optional newsgroups subject)
5596 "Start editing a news article to be sent."
5598 (let ((message-this-is-news t))
5599 (message-pop-to-buffer (message-buffer-name "posting" nil newsgroups))
5600 (message-setup `((Newsgroups . ,(or newsgroups ""))
5601 (Subject . ,(or subject ""))))))
5603 (defun message-get-reply-headers (wide &optional to-address address-headers)
5604 (let (follow-to mct never-mct to cc author mft recipients)
5605 ;; Find all relevant headers we need.
5607 (message-narrow-to-headers-or-head)
5608 ;; Gmane renames "To". Look at "Original-To", too, if it is present in
5609 ;; message-header-synonyms.
5610 (setq to (or (message-fetch-field "to")
5611 (and (loop for synonym in message-header-synonyms
5612 when (memq 'Original-To synonym)
5614 (message-fetch-field "original-to")))
5615 cc (message-fetch-field "cc")
5616 mct (message-fetch-field "mail-copies-to")
5617 author (or (message-fetch-field "mail-reply-to")
5618 (message-fetch-field "reply-to")
5619 (message-fetch-field "from")
5621 mft (and message-use-mail-followup-to
5622 (message-fetch-field "mail-followup-to"))))
5624 ;; Handle special values of Mail-Copies-To.
5626 (cond ((or (equal (downcase mct) "never")
5627 (equal (downcase mct) "nobody"))
5630 ((or (equal (downcase mct) "always")
5631 (equal (downcase mct) "poster"))
5632 (setq mct author))))
5635 ;; Build (textual) list of new recipient addresses.
5638 (setq recipients (concat ", " author)))
5640 (dolist (header address-headers)
5641 (let ((value (message-fetch-field header)))
5643 (setq recipients (concat recipients ", " value))))))
5645 (string-match "[^ \t,]" mft)
5646 (or (not (eq message-use-mail-followup-to 'ask))
5647 (message-y-or-n-p "Obey Mail-Followup-To? " t "\
5648 You should normally obey the Mail-Followup-To: header. In this
5649 article, it has the value of
5653 which directs your response to " (if (string-match "," mft)
5654 "the specified addresses"
5655 "that address only") ".
5657 Most commonly, Mail-Followup-To is used by a mailing list poster to
5658 express that responses should be sent to just the list, and not the
5661 If a message is posted to several mailing lists, Mail-Followup-To may
5662 also be used to direct the following discussion to one list only,
5663 because discussions that are spread over several lists tend to be
5664 fragmented and very difficult to follow.
5666 Also, some source/announcement lists are not intended for discussion;
5667 responses here are directed to other addresses.
5669 You may customize the variable `message-use-mail-followup-to', if you
5670 want to get rid of this query permanently.")))
5671 (setq recipients (concat ", " mft)))
5673 (setq recipients (concat ", " to-address))
5674 ;; If the author explicitly asked for a copy, we don't deny it to them.
5675 (if mct (setq recipients (concat recipients ", " mct))))
5677 (setq recipients (if never-mct "" (concat ", " author)))
5678 (if to (setq recipients (concat recipients ", " to)))
5679 (if cc (setq recipients (concat recipients ", " cc)))
5680 (if mct (setq recipients (concat recipients ", " mct)))))
5681 (if (>= (length recipients) 2)
5682 ;; Strip the leading ", ".
5683 (setq recipients (substring recipients 2)))
5684 ;; Squeeze whitespace.
5685 (while (string-match "[ \t][ \t]+" recipients)
5686 (setq recipients (replace-match " " t t recipients)))
5687 ;; Remove addresses that match `rmail-dont-reply-to-names'.
5688 (let ((rmail-dont-reply-to-names message-dont-reply-to-names))
5689 (setq recipients (rmail-dont-reply-to recipients)))
5690 ;; Perhaps "Mail-Copies-To: never" removed the only address?
5691 (if (string-equal recipients "")
5692 (setq recipients author))
5693 ;; Convert string to a list of (("foo@bar" . "Name <Foo@BAR>") ...).
5697 (cons (downcase (mail-strip-quoted-names addr)) addr))
5698 (message-tokenize-header recipients)))
5699 ;; Remove first duplicates. (Why not all duplicates? Is this a bug?)
5700 (let ((s recipients))
5702 (setq recipients (delq (assoc (car (pop s)) s) recipients))))
5704 ;; Remove hierarchical lists that are contained within each other,
5705 ;; if message-hierarchical-addresses is defined.
5706 (when message-hierarchical-addresses
5707 (let ((plain-addrs (mapcar 'car recipients))
5710 (setq subaddrs (assoc (car plain-addrs)
5711 message-hierarchical-addresses)
5712 plain-addrs (cdr plain-addrs))
5714 (setq subaddrs (cdr subaddrs))
5716 (setq recip (assoc (car subaddrs) recipients)
5717 subaddrs (cdr subaddrs))
5719 (setq recipients (delq recip recipients))))))))
5721 ;; Build the header alist. Allow the user to be asked whether
5722 ;; or not to reply to all recipients in a wide reply.
5723 (setq follow-to (list (cons 'To (cdr (pop recipients)))))
5724 (when (and recipients
5725 (or (not message-wide-reply-confirm-recipients)
5726 (y-or-n-p "Reply to all recipients? ")))
5727 (setq recipients (mapconcat
5728 (lambda (addr) (cdr addr)) recipients ", "))
5729 (if (string-match "^ +" recipients)
5730 (setq recipients (substring recipients (match-end 0))))
5731 (push (cons 'Cc recipients) follow-to)))
5735 (defun message-reply (&optional to-address wide)
5736 "Start editing a reply to the article in the current buffer."
5738 (require 'gnus-sum) ; for gnus-list-identifiers
5739 (let ((cur (current-buffer))
5740 from subject date reply-to to cc
5741 references message-id follow-to
5742 (inhibit-point-motion-hooks t)
5743 (message-this-is-mail t)
5746 (message-narrow-to-head-1)
5747 ;; Allow customizations to have their say.
5749 ;; This is a regular reply.
5750 (when (functionp message-reply-to-function)
5752 (setq follow-to (funcall message-reply-to-function))))
5753 ;; This is a followup.
5754 (when (functionp message-wide-reply-to-function)
5757 (funcall message-wide-reply-to-function)))))
5758 (setq message-id (message-fetch-field "message-id" t)
5759 references (message-fetch-field "references")
5760 date (message-fetch-field "date")
5761 from (message-fetch-field "from")
5762 subject (or (message-fetch-field "subject") "none"))
5763 (when gnus-list-identifiers
5764 (setq subject (message-strip-list-identifiers subject)))
5765 (setq subject (concat "Re: " (message-strip-subject-re subject)))
5766 (when message-subject-trailing-was-query
5767 (setq subject (message-strip-subject-trailing-was subject)))
5769 (when (and (setq gnus-warning (message-fetch-field "gnus-warning"))
5770 (string-match "<[^>]+>" gnus-warning))
5771 (setq message-id (match-string 0 gnus-warning)))
5774 (setq follow-to (message-get-reply-headers wide to-address))))
5776 (unless (message-mail-user-agent)
5777 (message-pop-to-buffer
5778 (message-buffer-name
5779 (if wide "wide reply" "reply") from
5780 (if wide to-address nil))))
5782 (setq message-reply-headers
5783 (vector 0 subject from date message-id references 0 0 ""))
5786 `((Subject . ,subject)
5791 (defun message-wide-reply (&optional to-address)
5792 "Make a \"wide\" reply to the message in the current buffer."
5794 (message-reply to-address t))
5797 (defun message-followup (&optional to-newsgroups)
5798 "Follow up to the message in the current buffer.
5799 If TO-NEWSGROUPS, use that as the new Newsgroups line."
5801 (require 'gnus-sum) ; for gnus-list-identifiers
5802 (let ((cur (current-buffer))
5803 from subject date reply-to mrt mct
5804 references message-id follow-to
5805 (inhibit-point-motion-hooks t)
5806 (message-this-is-news t)
5807 followup-to distribution newsgroups gnus-warning posted-to)
5810 (goto-char (point-min))
5811 (if (search-forward "\n\n" nil t)
5814 (when (functionp message-followup-to-function)
5816 (funcall message-followup-to-function)))
5817 (setq from (message-fetch-field "from")
5818 date (message-fetch-field "date")
5819 subject (or (message-fetch-field "subject") "none")
5820 references (message-fetch-field "references")
5821 message-id (message-fetch-field "message-id" t)
5822 followup-to (message-fetch-field "followup-to")
5823 newsgroups (message-fetch-field "newsgroups")
5824 posted-to (message-fetch-field "posted-to")
5825 reply-to (message-fetch-field "reply-to")
5826 mrt (message-fetch-field "mail-reply-to")
5827 distribution (message-fetch-field "distribution")
5828 mct (message-fetch-field "mail-copies-to"))
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)))
5832 ;; Remove bogus distribution.
5833 (when (and (stringp distribution)
5834 (let ((case-fold-search t))
5835 (string-match "world" distribution)))
5836 (setq distribution nil))
5837 (if gnus-list-identifiers
5838 (setq subject (message-strip-list-identifiers subject)))
5839 (setq subject (concat "Re: " (message-strip-subject-re subject)))
5840 (when message-subject-trailing-was-query
5841 (setq subject (message-strip-subject-trailing-was subject)))
5844 (message-pop-to-buffer (message-buffer-name "followup" from newsgroups))
5846 (setq message-reply-headers
5847 (vector 0 subject from date message-id references 0 0 ""))
5850 `((Subject . ,subject)
5853 (list (cons 'Newsgroups to-newsgroups)))
5854 (follow-to follow-to)
5855 ((and followup-to message-use-followup-to)
5858 ((equal (downcase followup-to) "poster")
5859 (if (or (eq message-use-followup-to 'use)
5860 (message-y-or-n-p "Obey Followup-To: poster? " t "\
5861 You should normally obey the Followup-To: header.
5863 `Followup-To: poster' sends your response via e-mail instead of news.
5865 A typical situation where `Followup-To: poster' is used is when the poster
5866 does not read the newsgroup, so he wouldn't see any replies sent to it.
5868 You may customize the variable `message-use-followup-to', if you
5869 want to get rid of this query permanently."))
5871 (setq message-this-is-news nil)
5872 (cons 'To (or mrt reply-to from "")))
5873 (cons 'Newsgroups newsgroups)))
5875 (if (or (equal followup-to newsgroups)
5876 (not (eq message-use-followup-to 'ask))
5878 (concat "Obey Followup-To: " followup-to "? ") t "\
5879 You should normally obey the Followup-To: header.
5881 `Followup-To: " followup-to "'
5882 directs your response to " (if (string-match "," followup-to)
5883 "the specified newsgroups"
5884 "that newsgroup only") ".
5886 If a message is posted to several newsgroups, Followup-To is often
5887 used to direct the following discussion to one newsgroup only,
5888 because discussions that are spread over several newsgroup tend to
5889 be fragmented and very difficult to follow.
5891 Also, some source/announcement newsgroups are not intended for discussion;
5892 responses here are directed to other newsgroups.
5894 You may customize the variable `message-use-followup-to', if you
5895 want to get rid of this query permanently."))
5896 (cons 'Newsgroups followup-to)
5897 (cons 'Newsgroups newsgroups))))))
5899 `((Newsgroups . ,posted-to)))
5901 `((Newsgroups . ,newsgroups))))
5902 ,@(and distribution (list (cons 'Distribution distribution)))
5904 (not (or (equal (downcase mct) "never")
5905 (equal (downcase mct) "nobody"))))
5906 (list (cons 'Cc (if (or (equal (downcase mct) "always")
5907 (equal (downcase mct) "poster"))
5908 (or mrt reply-to from "")
5913 (defun message-is-yours-p ()
5914 "Non-nil means current article is yours.
5915 If you have added 'cancel-messages to 'message-shoot-gnksa-feet', all articles
5916 are yours except those that have Cancel-Lock header not belonging to you.
5917 Instead of shooting GNKSA feet, you should modify 'message-alternative-emails'
5918 regexp to match all of yours addresses."
5919 ;; Canlock-logic as suggested by Per Abrahamsen
5920 ;; <abraham@dina.kvl.dk>
5922 ;; IF article has cancel-lock THEN
5923 ;; IF we can verify it THEN
5926 ;; error: cancellock: article is not yours
5928 ;; Use old rules, comparing sender...
5931 (message-narrow-to-head-1)
5932 (if (message-fetch-field "Cancel-Lock")
5933 (if (null (canlock-verify))
5935 (error "Failed to verify Cancel-lock: This article is not yours"))
5938 (message-gnksa-enable-p 'cancel-messages)
5939 (and (setq sender (message-fetch-field "sender"))
5940 (string-equal (downcase sender)
5941 (downcase (message-make-sender))))
5942 ;; Email address in From field equals to our address
5943 (and (setq from (message-fetch-field "from"))
5945 (downcase (cadr (mail-extract-address-components from)))
5946 (downcase (cadr (mail-extract-address-components
5947 (message-make-from))))))
5948 ;; Email address in From field matches
5949 ;; 'message-alternative-emails' regexp
5951 message-alternative-emails
5953 message-alternative-emails
5954 (cadr (mail-extract-address-components from))))))))))
5957 (defun message-cancel-news (&optional arg)
5958 "Cancel an article you posted.
5959 If ARG, allow editing of the cancellation message."
5961 (unless (message-news-p)
5962 (error "This is not a news article; canceling is impossible"))
5963 (let (from newsgroups message-id distribution buf)
5965 ;; Get header info from original article.
5967 (message-narrow-to-head-1)
5968 (setq from (message-fetch-field "from")
5969 newsgroups (message-fetch-field "newsgroups")
5970 message-id (message-fetch-field "message-id" t)
5971 distribution (message-fetch-field "distribution")))
5972 ;; Make sure that this article was written by the user.
5973 (unless (message-is-yours-p)
5974 (error "This article is not yours"))
5975 (when (yes-or-no-p "Do you really want to cancel this article? ")
5976 ;; Make control message.
5979 (setq buf (set-buffer (get-buffer-create " *message cancel*"))))
5981 (insert "Newsgroups: " newsgroups "\n"
5983 "Subject: cmsg cancel " message-id "\n"
5984 "Control: cancel " message-id "\n"
5986 (concat "Distribution: " distribution "\n")
5988 mail-header-separator "\n"
5989 message-cancel-message)
5990 (run-hooks 'message-cancel-hook)
5992 (message "Canceling your article...")
5993 (if (let ((message-syntax-checks
5994 'dont-check-for-anything-just-trust-me))
5995 (funcall message-send-news-function))
5996 (message "Canceling your article...done"))
5997 (kill-buffer buf))))))
6000 (defun message-supersede ()
6001 "Start composing a message to supersede the current message.
6002 This is done simply by taking the old article and adding a Supersedes
6003 header line with the old Message-ID."
6005 (let ((cur (current-buffer)))
6006 ;; Check whether the user owns the article that is to be superseded.
6007 (unless (message-is-yours-p)
6008 (error "This article is not yours"))
6009 ;; Get a normal message buffer.
6010 (message-pop-to-buffer (message-buffer-name "supersede"))
6011 (insert-buffer-substring cur)
6013 (message-narrow-to-head-1)
6014 ;; Remove unwanted headers.
6015 (when message-ignored-supersedes-headers
6016 (message-remove-header message-ignored-supersedes-headers t))
6017 (goto-char (point-min))
6018 (if (not (re-search-forward "^Message-ID: " nil t))
6019 (error "No Message-ID in this article")
6020 (replace-match "Supersedes: " t t))
6021 (goto-char (point-max))
6022 (insert mail-header-separator)
6027 (defun message-recover ()
6028 "Reread contents of current buffer from its last auto-save file."
6030 (let ((file-name (make-auto-save-file-name)))
6031 (cond ((save-window-excursion
6032 (if (not (eq system-type 'vax-vms))
6033 (with-output-to-temp-buffer "*Directory*"
6034 (with-current-buffer standard-output
6035 (fundamental-mode)) ; for Emacs 20.4+
6036 (buffer-disable-undo standard-output)
6037 (let ((default-directory "/"))
6039 "ls" nil standard-output nil "-l" file-name))))
6040 (yes-or-no-p (format "Recover auto save file %s? " file-name)))
6041 (let ((buffer-read-only nil))
6043 (insert-file-contents file-name nil)))
6044 (t (error "message-recover cancelled")))))
6046 ;;; Washing Subject:
6048 (defun message-wash-subject (subject)
6049 "Remove junk like \"Re:\", \"(fwd)\", etc. added to subject string SUBJECT.
6050 Previous forwarders, replyers, etc. may add it."
6053 (goto-char (point-min))
6054 ;; strip Re/Fwd stuff off the beginning
6055 (while (re-search-forward
6056 "\\([Rr][Ee]:\\|[Ff][Ww][Dd]\\(\\[[0-9]*\\]\\)?:\\|[Ff][Ww]:\\)" nil t)
6059 ;; and gnus-style forwards [foo@bar.com] subject
6060 (goto-char (point-min))
6061 (while (re-search-forward "\\[[^ \t]*\\(@\\|\\.\\)[^ \t]*\\]" nil t)
6065 (goto-char (point-max))
6066 (while (re-search-backward "([Ff][Ww][Dd])" nil t)
6069 ;; and finally, any whitespace that was left-over
6070 (goto-char (point-min))
6071 (while (re-search-forward "^[ \t]+" nil t)
6073 (goto-char (point-max))
6074 (while (re-search-backward "[ \t]+$" nil t)
6079 ;;; Forwarding messages.
6081 (defvar message-forward-decoded-p nil
6082 "Non-nil means the original message is decoded.")
6084 (defun message-forward-subject-name-subject (subject)
6085 "Generate a SUBJECT for a forwarded message.
6086 The form is: [Source] Subject, where if the original message was mail,
6087 Source is the name of the sender, and if the original message was
6088 news, Source is the list of newsgroups is was posted to."
6089 (let* ((group (message-fetch-field "newsgroups"))
6090 (from (message-fetch-field "from"))
6093 (gnus-group-decoded-name group)
6094 (or (and from (car (gnus-extract-address-components from)))
6097 (if message-forward-decoded-p
6099 (mail-decode-encoded-word-string prefix))
6102 (defun message-forward-subject-author-subject (subject)
6103 "Generate a SUBJECT for a forwarded message.
6104 The form is: [Source] Subject, where if the original message was mail,
6105 Source is the sender, and if the original message was news, Source is
6106 the list of newsgroups is was posted to."
6107 (let* ((group (message-fetch-field "newsgroups"))
6110 (gnus-group-decoded-name group)
6111 (or (message-fetch-field "from")
6114 (if message-forward-decoded-p
6116 (mail-decode-encoded-word-string prefix))
6119 (defun message-forward-subject-fwd (subject)
6120 "Generate a SUBJECT for a forwarded message.
6121 The form is: Fwd: Subject, where Subject is the original subject of
6123 (if (string-match "^Fwd: " subject)
6125 (concat "Fwd: " subject)))
6127 (defun message-make-forward-subject ()
6128 "Return a Subject header suitable for the message in the current buffer."
6131 (message-narrow-to-head-1)
6132 (let ((funcs message-make-forward-subject-function)
6133 (subject (message-fetch-field "Subject")))
6136 (if message-forward-decoded-p
6138 (mail-decode-encoded-word-string subject))
6140 (if message-wash-forwarded-subjects
6141 (setq subject (message-wash-subject subject)))
6142 ;; Make sure funcs is a list.
6145 (setq funcs (list funcs)))
6146 ;; Apply funcs in order, passing subject generated by previous
6147 ;; func to the next one.
6149 (when (functionp (car funcs))
6150 (setq subject (funcall (car funcs) subject)))
6151 (setq funcs (cdr funcs)))
6155 (defvar gnus-article-decoded-p))
6159 (defun message-forward (&optional news digest)
6160 "Forward the current message via mail.
6161 Optional NEWS will use news to forward instead of mail.
6162 Optional DIGEST will use digest to forward."
6164 (let* ((cur (current-buffer))
6165 (message-forward-decoded-p
6166 (if (local-variable-p 'gnus-article-decoded-p (current-buffer))
6167 gnus-article-decoded-p ;; In an article buffer.
6168 message-forward-decoded-p))
6169 (subject (message-make-forward-subject)))
6171 (message-news nil subject)
6172 (message-mail nil subject))
6173 (message-forward-make-body cur digest)))
6175 (defun message-forward-make-body-plain (forward-buffer)
6177 "\n-------------------- Start of forwarded message --------------------\n")
6178 (let ((b (point)) e)
6181 (mm-disable-multibyte)
6183 (with-current-buffer forward-buffer
6184 (mm-with-unibyte-current-buffer (buffer-string))))
6185 (mm-enable-multibyte)
6187 (goto-char (point-min))
6188 (when (looking-at "From ")
6189 (replace-match "X-From-Line: "))
6193 "\n-------------------- End of forwarded message --------------------\n")
6194 (when message-forward-ignored-headers
6196 (narrow-to-region b e)
6198 (narrow-to-region (point)
6199 (or (search-forward "\n\n" nil t) (point)))
6200 (message-remove-header message-forward-ignored-headers t)))))
6202 (defun message-forward-make-body-mime (forward-buffer)
6203 (insert "\n\n<#part type=message/rfc822 disposition=inline raw=t>\n")
6204 (let ((b (point)) e)
6206 (narrow-to-region (point) (point))
6207 (mml-insert-buffer forward-buffer)
6208 (goto-char (point-min))
6209 (when (looking-at "From ")
6210 (replace-match "X-From-Line: "))
6211 (goto-char (point-max)))
6213 (insert "<#/part>\n")))
6215 (defun message-forward-make-body-mml (forward-buffer)
6216 (insert "\n\n<#mml type=message/rfc822 disposition=inline>\n")
6217 (let ((b (point)) e)
6218 (if (not message-forward-decoded-p)
6221 (mm-disable-multibyte)
6223 (with-current-buffer forward-buffer
6224 (mm-with-unibyte-current-buffer (buffer-string))))
6225 (mm-enable-multibyte)
6227 (goto-char (point-min))
6228 (when (looking-at "From ")
6229 (replace-match "X-From-Line: "))
6232 (narrow-to-region (point) (point))
6233 (mml-insert-buffer forward-buffer)
6234 (goto-char (point-min))
6235 (when (looking-at "From ")
6236 (replace-match "X-From-Line: "))
6237 (goto-char (point-max))))
6239 (insert "<#/mml>\n")
6240 (when (and (not message-forward-decoded-p)
6241 message-forward-ignored-headers)
6243 (narrow-to-region b e)
6245 (narrow-to-region (point)
6246 (or (search-forward "\n\n" nil t) (point)))
6247 (message-remove-header message-forward-ignored-headers t)))))
6249 (defun message-forward-make-body-digest-plain (forward-buffer)
6251 "\n-------------------- Start of forwarded message --------------------\n")
6252 (let ((b (point)) e)
6253 (mml-insert-buffer forward-buffer)
6256 "\n-------------------- End of forwarded message --------------------\n")))
6258 (defun message-forward-make-body-digest-mime (forward-buffer)
6259 (insert "\n<#multipart type=digest>\n")
6260 (let ((b (point)) e)
6261 (insert-buffer-substring forward-buffer)
6263 (insert "<#/multipart>\n")
6265 (narrow-to-region b e)
6267 (narrow-to-region (point)
6268 (or (search-forward "\n\n" nil t) (point)))
6269 (delete-region (point-min) (point-max)))))
6271 (defun message-forward-make-body-digest (forward-buffer)
6272 (if message-forward-as-mime
6273 (message-forward-make-body-digest-mime forward-buffer)
6274 (message-forward-make-body-digest-plain forward-buffer)))
6277 (defun message-forward-make-body (forward-buffer &optional digest)
6278 ;; Put point where we want it before inserting the forwarded
6280 (if message-forward-before-signature
6282 (goto-char (point-max)))
6284 (message-forward-make-body-digest forward-buffer)
6285 (if message-forward-as-mime
6286 (if (and message-forward-show-mml
6287 (not (and (eq message-forward-show-mml 'best)
6288 (with-current-buffer forward-buffer
6289 (goto-char (point-min))
6291 "Content-Type: *multipart/\\(signed\\|encrypted\\)"
6293 (message-forward-make-body-mml forward-buffer)
6294 (message-forward-make-body-mime forward-buffer))
6295 (message-forward-make-body-plain forward-buffer)))
6296 (message-position-point))
6299 (defun message-forward-rmail-make-body (forward-buffer)
6300 (save-window-excursion
6301 (set-buffer forward-buffer)
6302 ;; Rmail doesn't have rmail-msg-restore-non-pruned-header in Emacs
6303 ;; 20. FIXIT, or we drop support for rmail in Emacs 20.
6304 (if (rmail-msg-is-pruned)
6305 (rmail-msg-restore-non-pruned-header)))
6306 (message-forward-make-body forward-buffer))
6308 (eval-when-compile (defvar rmail-enable-mime-composing))
6310 ;; Fixme: Should have defcustom.
6312 (defun message-insinuate-rmail ()
6313 "Let RMAIL use message to forward."
6315 (setq rmail-enable-mime-composing t)
6316 (setq rmail-insert-mime-forwarded-message-function
6317 'message-forward-rmail-make-body))
6320 (defun message-resend (address)
6321 "Resend the current article to ADDRESS."
6323 (list (message-read-from-minibuffer "Resend message to: ")))
6324 (message "Resending message to %s..." address)
6326 (let ((cur (current-buffer))
6328 ;; We first set up a normal mail buffer.
6329 (unless (message-mail-user-agent)
6330 (set-buffer (get-buffer-create " *message resend*"))
6332 (let ((message-this-is-mail t)
6334 (message-setup `((To . ,address))))
6335 ;; Insert our usual headers.
6336 (message-generate-headers '(From Date To Message-ID))
6337 (message-narrow-to-headers)
6338 ;; Remove X-Draft-From header etc.
6339 (message-remove-header message-ignored-mail-headers t)
6340 ;; Rename them all to "Resent-*".
6341 (goto-char (point-min))
6342 (while (re-search-forward "^[A-Za-z]" nil t)
6347 (delete-region (point) (point-max))
6349 ;; Insert the message to be resent.
6350 (insert-buffer-substring cur)
6351 (goto-char (point-min))
6352 (search-forward "\n\n")
6355 (narrow-to-region beg (point))
6356 (message-remove-header message-ignored-resent-headers t)
6357 (goto-char (point-max)))
6358 (insert mail-header-separator)
6359 ;; Rename all old ("Also-")Resent headers.
6360 (while (re-search-backward "^\\(Also-\\)*Resent-" beg t)
6363 ;; Quote any "From " lines at the beginning.
6365 (when (looking-at "From ")
6366 (replace-match "X-From-Line: "))
6368 (let ((message-inhibit-body-encoding t)
6369 message-required-mail-headers
6370 rfc2047-encode-encoded-words)
6371 (message-send-mail))
6372 (kill-buffer (current-buffer)))
6373 (message "Resending message to %s...done" address)))
6376 (defun message-bounce ()
6377 "Re-mail the current message.
6378 This only makes sense if the current message is a bounce message that
6379 contains some mail you have written which has been bounced back to
6382 (let ((handles (mm-dissect-buffer t))
6384 (message-pop-to-buffer (message-buffer-name "bounce"))
6385 (if (stringp (car handles))
6386 ;; This is a MIME bounce.
6387 (mm-insert-part (car (last handles)))
6388 ;; This is a non-MIME bounce, so we try to remove things
6390 (mm-insert-part handles)
6392 (goto-char (point-min))
6393 (re-search-forward "\n\n+" nil t)
6394 (setq boundary (point))
6395 ;; We remove everything before the bounced mail.
6396 (if (or (re-search-forward message-unsent-separator nil t)
6398 (search-forward "\n\n" nil 'move)
6399 (re-search-backward "^Return-Path:.*\n" boundary t)))
6402 (delete-region (point-min)
6403 (if (re-search-forward "^[^ \n\t]+:" nil t)
6406 (goto-char boundary)
6407 (when (re-search-backward "^.?From .*\n" nil t)
6408 (delete-region (match-beginning 0) (match-end 0)))))
6409 (mm-enable-multibyte)
6411 (message-narrow-to-head-1)
6412 (message-remove-header message-ignored-bounced-headers t)
6413 (goto-char (point-max))
6414 (insert mail-header-separator))
6415 (message-position-point)))
6418 ;;; Interactive entry points for new message buffers.
6422 (defun message-mail-other-window (&optional to subject)
6423 "Like `message-mail' command, but display mail buffer in another window."
6425 (unless (message-mail-user-agent)
6426 (let ((pop-up-windows t)
6427 (special-display-buffer-names nil)
6428 (special-display-regexps nil)
6429 (same-window-buffer-names nil)
6430 (same-window-regexps nil))
6431 (message-pop-to-buffer (message-buffer-name "mail" to))))
6432 (let ((message-this-is-mail t))
6433 (message-setup `((To . ,(or to "")) (Subject . ,(or subject "")))
6434 nil nil 'switch-to-buffer-other-window)))
6437 (defun message-mail-other-frame (&optional to subject)
6438 "Like `message-mail' command, but display mail buffer in another frame."
6440 (unless (message-mail-user-agent)
6441 (let ((pop-up-frames t)
6442 (special-display-buffer-names nil)
6443 (special-display-regexps nil)
6444 (same-window-buffer-names nil)
6445 (same-window-regexps nil))
6446 (message-pop-to-buffer (message-buffer-name "mail" to))))
6447 (let ((message-this-is-mail t))
6448 (message-setup `((To . ,(or to "")) (Subject . ,(or subject "")))
6449 nil nil 'switch-to-buffer-other-frame)))
6452 (defun message-news-other-window (&optional newsgroups subject)
6453 "Start editing a news article to be sent."
6455 (let ((pop-up-windows t)
6456 (special-display-buffer-names nil)
6457 (special-display-regexps nil)
6458 (same-window-buffer-names nil)
6459 (same-window-regexps nil))
6460 (message-pop-to-buffer (message-buffer-name "posting" nil newsgroups)))
6461 (let ((message-this-is-news t))
6462 (message-setup `((Newsgroups . ,(or newsgroups ""))
6463 (Subject . ,(or subject ""))))))
6466 (defun message-news-other-frame (&optional newsgroups subject)
6467 "Start editing a news article to be sent."
6469 (let ((pop-up-frames t)
6470 (special-display-buffer-names nil)
6471 (special-display-regexps nil)
6472 (same-window-buffer-names nil)
6473 (same-window-regexps nil))
6474 (message-pop-to-buffer (message-buffer-name "posting" nil newsgroups)))
6475 (let ((message-this-is-news t))
6476 (message-setup `((Newsgroups . ,(or newsgroups ""))
6477 (Subject . ,(or subject ""))))))
6481 ;; This code should be moved to underline.el (from which it is stolen).
6484 (defun bold-region (start end)
6485 "Bold all nonblank characters in the region.
6486 Works by overstriking characters.
6487 Called from program, takes two arguments START and END
6488 which specify the range to operate on."
6491 (let ((end1 (make-marker)))
6492 (move-marker end1 (max start end))
6493 (goto-char (min start end))
6494 (while (< (point) end1)
6495 (or (looking-at "[_\^@- ]")
6496 (insert (char-after) "\b"))
6497 (forward-char 1)))))
6500 (defun unbold-region (start end)
6501 "Remove all boldness (overstruck characters) in the region.
6502 Called from program, takes two arguments START and END
6503 which specify the range to operate on."
6506 (let ((end1 (make-marker)))
6507 (move-marker end1 (max start end))
6508 (goto-char (min start end))
6509 (while (re-search-forward "\b" end1 t)
6510 (if (eq (char-after) (char-after (- (point) 2)))
6511 (delete-char -2))))))
6513 (defun message-exchange-point-and-mark ()
6514 "Exchange point and mark, but don't activate region if it was inactive."
6516 (message-mark-active-p)
6517 (exchange-point-and-mark))
6518 (setq mark-active nil)))
6520 (defalias 'message-make-overlay 'make-overlay)
6521 (defalias 'message-delete-overlay 'delete-overlay)
6522 (defalias 'message-overlay-put 'overlay-put)
6523 (defun message-kill-all-overlays ()
6524 (if (featurep 'xemacs)
6525 (map-extents (lambda (extent ignore) (delete-extent extent)))
6526 (mapcar #'delete-overlay (overlays-in (point-min) (point-max)))))
6528 ;; Support for toolbar
6530 (defvar tool-bar-map)
6531 (defvar tool-bar-mode))
6533 (defun message-tool-bar-local-item-from-menu (command icon in-map &optional from-map &rest props)
6534 ;; We need to make tool bar entries in local keymaps with
6535 ;; `tool-bar-local-item-from-menu' in Emacs > 21.3
6536 (if (fboundp 'tool-bar-local-item-from-menu)
6537 ;; This is for Emacs 21.3
6538 (tool-bar-local-item-from-menu command icon in-map from-map props)
6539 (tool-bar-add-item-from-menu command icon from-map props)))
6541 (defun message-tool-bar-map ()
6542 (or message-tool-bar-map
6543 (setq message-tool-bar-map
6545 (condition-case nil (require 'tool-bar) (error nil))
6546 (fboundp 'tool-bar-add-item-from-menu)
6548 (let ((tool-bar-map (copy-keymap tool-bar-map))
6549 (load-path (mm-image-load-path)))
6550 ;; Zap some items which aren't so relevant and take
6552 (dolist (key '(print-buffer kill-buffer save-buffer
6553 write-file dired open-file))
6554 (define-key tool-bar-map (vector key) nil))
6555 (message-tool-bar-local-item-from-menu
6556 'message-send-and-exit "mail_send" tool-bar-map message-mode-map)
6557 (message-tool-bar-local-item-from-menu
6558 'message-kill-buffer "close" tool-bar-map message-mode-map)
6559 (message-tool-bar-local-item-from-menu
6560 'message-dont-send "cancel" tool-bar-map message-mode-map)
6561 (message-tool-bar-local-item-from-menu
6562 'mml-attach-file "attach" tool-bar-map mml-mode-map)
6563 (message-tool-bar-local-item-from-menu
6564 'ispell-message "spell" tool-bar-map message-mode-map)
6565 (message-tool-bar-local-item-from-menu
6566 'mml-preview "preview"
6567 tool-bar-map mml-mode-map)
6568 (message-tool-bar-local-item-from-menu
6569 'message-insert-importance-high "important"
6570 tool-bar-map message-mode-map)
6571 (message-tool-bar-local-item-from-menu
6572 'message-insert-importance-low "unimportant"
6573 tool-bar-map message-mode-map)
6574 (message-tool-bar-local-item-from-menu
6575 'message-insert-disposition-notification-to "receipt"
6576 tool-bar-map message-mode-map)
6579 ;;; Group name completion.
6581 (defcustom message-newgroups-header-regexp
6582 "^\\(Newsgroups\\|Followup-To\\|Posted-To\\|Gcc\\):"
6583 "Regexp that match headers that lists groups."
6587 (defcustom message-completion-alist
6588 (list (cons message-newgroups-header-regexp 'message-expand-group)
6589 '("^\\(Resent-\\)?\\(To\\|B?Cc\\):" . message-expand-name)
6590 '("^\\(Reply-To\\|From\\|Mail-Followup-To\\|Mail-Copies-To\\):"
6591 . message-expand-name)
6592 '("^\\(Disposition-Notification-To\\|Return-Receipt-To\\):"
6593 . message-expand-name))
6594 "Alist of (RE . FUN). Use FUN for completion on header lines matching RE."
6597 :type '(alist :key-type regexp :value-type function))
6599 (defcustom message-tab-body-function nil
6600 "*Function to execute when `message-tab' (TAB) is executed in the body.
6601 If nil, the function bound in `text-mode-map' or `global-map' is executed."
6604 :link '(custom-manual "(message)Various Commands")
6607 (defun message-tab ()
6608 "Complete names according to `message-completion-alist'.
6609 Execute function specified by `message-tab-body-function' when not in
6612 (let ((alist message-completion-alist))
6614 (let ((mail-abbrev-mode-regexp (caar alist)))
6615 (not (mail-abbrev-in-expansion-header-p))))
6616 (setq alist (cdr alist)))
6617 (funcall (or (cdar alist) message-tab-body-function
6618 (lookup-key text-mode-map "\t")
6619 (lookup-key global-map "\t")
6620 'indent-relative))))
6622 (defun message-expand-group ()
6623 "Expand the group name under point."
6624 (let* ((b (save-excursion
6629 (skip-chars-forward "^:")
6632 (skip-chars-backward "^, \t\n") (point))))
6633 (completion-ignore-case t)
6634 (string (buffer-substring b (progn (skip-chars-forward "^,\t\n ")
6636 (hashtb (and (boundp 'gnus-active-hashtb) gnus-active-hashtb))
6637 (completions (all-completions string hashtb))
6639 (delete-region b (point))
6641 ((= (length completions) 1)
6642 (if (string= (car completions) string)
6645 (message "Only matching group"))
6646 (insert (car completions))))
6647 ((and (setq comp (try-completion string hashtb))
6648 (not (string= comp string)))
6653 (message "No matching groups")
6654 (save-selected-window
6655 (pop-to-buffer "*Completions*")
6656 (buffer-disable-undo)
6657 (let ((buffer-read-only nil))
6659 (let ((standard-output (current-buffer)))
6660 (display-completion-list (sort completions 'string<)))
6661 (goto-char (point-min))
6662 (delete-region (point) (progn (forward-line 3) (point))))))))))
6664 (defun message-expand-name ()
6665 (if (fboundp 'bbdb-complete-name)
6666 (bbdb-complete-name)
6671 (defun message-talkative-question (ask question show &rest text)
6672 "Call FUNCTION with argument QUESTION; optionally display TEXT... args.
6673 If SHOW is non-nil, the arguments TEXT... are displayed in a temp buffer.
6674 The following arguments may contain lists of values."
6676 (setq text (message-flatten-list text)))
6677 (save-window-excursion
6679 (with-output-to-temp-buffer " *MESSAGE information message*"
6680 (set-buffer " *MESSAGE information message*")
6681 (fundamental-mode) ; for Emacs 20.4+
6682 (mapcar 'princ text)
6683 (goto-char (point-min))))
6684 (funcall ask question))
6685 (funcall ask question)))
6687 (defun message-flatten-list (list)
6688 "Return a new, flat list that contains all elements of LIST.
6690 \(message-flatten-list '(1 (2 3 (4 5 (6))) 7))
6693 (apply 'append (mapcar 'message-flatten-list list)))
6697 (defun message-generate-new-buffer-clone-locals (name &optional varstr)
6698 "Create and return a buffer with name based on NAME using `generate-new-buffer'.
6699 Then clone the local variables and values from the old buffer to the
6700 new one, cloning only the locals having a substring matching the
6702 (let ((oldbuf (current-buffer)))
6704 (set-buffer (generate-new-buffer name))
6705 (message-clone-locals oldbuf varstr)
6708 (defun message-clone-locals (buffer &optional varstr)
6709 "Clone the local variables from BUFFER to the current buffer."
6710 (let ((locals (save-excursion
6712 (buffer-local-variables)))
6713 (regexp "^gnus\\|^nn\\|^message\\|^sendmail\\|^smtp\\|^user-mail-address"))
6716 (when (and (consp local)
6718 (string-match regexp (symbol-name (car local)))
6720 (string-match varstr (symbol-name (car local)))))
6722 (set (make-local-variable (car local))
6730 (defvar message-inhibit-body-encoding nil)
6732 (defun message-encode-message-body ()
6733 (unless message-inhibit-body-encoding
6734 (let ((mail-parse-charset (or mail-parse-charset
6735 message-default-charset))
6736 (case-fold-search t)
6737 lines content-type-p)
6740 (narrow-to-region (point) (point-max))
6741 (let ((new (mml-generate-mime)))
6743 (delete-region (point-min) (point-max))
6745 (goto-char (point-min))
6746 (if (eq (aref new 0) ?\n)
6748 (search-forward "\n\n")
6749 (setq lines (buffer-substring (point-min) (1- (point))))
6750 (delete-region (point-min) (point))))))
6752 (message-narrow-to-headers-or-head)
6753 (message-remove-header "Mime-Version")
6754 (goto-char (point-max))
6755 (insert "MIME-Version: 1.0\n")
6758 (setq content-type-p
6760 (re-search-backward "^Content-Type:" nil t))))
6762 (message-narrow-to-headers-or-head)
6763 (message-remove-first-header "Content-Type")
6764 (message-remove-first-header "Content-Transfer-Encoding"))
6765 ;; We always make sure that the message has a Content-Type
6766 ;; header. This is because some broken MTAs and MUAs get
6767 ;; awfully confused when confronted with a message with a
6768 ;; MIME-Version header and without a Content-Type header. For
6769 ;; instance, Solaris' /usr/bin/mail.
6770 (unless content-type-p
6771 (goto-char (point-min))
6772 ;; For unknown reason, MIME-Version doesn't exist.
6773 (when (re-search-forward "^MIME-Version:" nil t)
6775 (insert "Content-Type: text/plain; charset=us-ascii\n"))))))
6777 (defun message-read-from-minibuffer (prompt &optional initial-contents)
6778 "Read from the minibuffer while providing abbrev expansion."
6779 (if (fboundp 'mail-abbrevs-setup)
6780 (let ((mail-abbrev-mode-regexp "")
6781 (minibuffer-setup-hook 'mail-abbrevs-setup)
6782 (minibuffer-local-map message-minibuffer-local-map))
6783 (read-from-minibuffer prompt initial-contents))
6784 (let ((minibuffer-setup-hook 'mail-abbrev-minibuffer-setup-hook)
6785 (minibuffer-local-map message-minibuffer-local-map))
6786 (read-string prompt initial-contents))))
6788 (defun message-use-alternative-email-as-from ()
6789 (require 'mail-utils)
6790 (let* ((fields '("To" "Cc"))
6793 (mail-strip-quoted-names
6794 (mapconcat 'message-fetch-reply-field fields ","))
6798 (if (string-match message-alternative-emails (car emails))
6799 (setq email (car emails)
6802 (unless (or (not email) (equal email user-mail-address))
6803 (goto-char (point-max))
6804 (insert "From: " email "\n"))))
6806 (defun message-options-get (symbol)
6807 (cdr (assq symbol message-options)))
6809 (defun message-options-set (symbol value)
6810 (let ((the-cons (assq symbol message-options)))
6813 (setcdr the-cons value)
6814 (setq message-options (delq the-cons message-options)))
6816 (push (cons symbol value) message-options))))
6819 (defun message-options-set-recipient ()
6821 (message-narrow-to-headers-or-head)
6822 (message-options-set 'message-sender
6823 (mail-strip-quoted-names
6824 (message-fetch-field "from")))
6825 (message-options-set 'message-recipients
6826 (mail-strip-quoted-names
6827 (let ((to (message-fetch-field "to"))
6828 (cc (message-fetch-field "cc"))
6829 (bcc (message-fetch-field "bcc")))
6832 (if (and to cc) ", ")
6834 (if (and (or to cc) bcc) ", ")
6837 (defun message-hide-headers ()
6838 "Hide headers based on the `message-hidden-headers' variable."
6839 (let ((regexps (if (stringp message-hidden-headers)
6840 (list message-hidden-headers)
6841 message-hidden-headers))
6842 (inhibit-point-motion-hooks t)
6843 (after-change-functions nil))
6847 (message-narrow-to-headers)
6848 (goto-char (point-min))
6850 (if (not (message-hide-header-p regexps))
6851 (message-next-header)
6852 (let ((begin (point)))
6853 (message-next-header)
6854 (add-text-properties
6856 '(invisible t message-hidden t))))))))))
6858 (defun message-hide-header-p (regexps)
6861 (when (eq (car regexps) 'not)
6864 (dolist (regexp regexps)
6865 (setq result (or result (looking-at regexp))))
6870 (when (featurep 'xemacs)
6871 (require 'messagexmas)
6872 (message-xmas-redefine))
6876 (run-hooks 'message-load-hook)
6879 ;; coding: iso-8859-1
6882 ;; arch-tag: 94b32cac-4504-4b6c-8181-030ebf380ee0
6883 ;;; message.el ends here