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
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)
1138 ;; backward-compatibility alias
1139 (put 'message-header-to-face 'face-alias 'message-header-to)
1141 (defface message-header-cc
1144 (:foreground "green4" :bold t))
1147 (:foreground "MidnightBlue"))
1150 "Face used for displaying Cc headers."
1151 :group 'message-faces)
1152 ;; backward-compatibility alias
1153 (put 'message-header-cc-face 'face-alias 'message-header-cc)
1155 (defface message-header-subject
1158 (:foreground "green3"))
1161 (:foreground "navy blue" :bold t))
1164 "Face used for displaying subject headers."
1165 :group 'message-faces)
1166 ;; backward-compatibility alias
1167 (put 'message-header-subject-face 'face-alias 'message-header-subject)
1169 (defface message-header-newsgroups
1172 (:foreground "yellow" :bold t :italic t))
1175 (:foreground "blue4" :bold t :italic t))
1177 (:bold t :italic t)))
1178 "Face used for displaying newsgroups headers."
1179 :group 'message-faces)
1180 ;; backward-compatibility alias
1181 (put 'message-header-newsgroups-face 'face-alias 'message-header-newsgroups)
1183 (defface message-header-other
1186 (:foreground "#b00000"))
1189 (:foreground "steel blue"))
1191 (:bold t :italic t)))
1192 "Face used for displaying newsgroups headers."
1193 :group 'message-faces)
1194 ;; backward-compatibility alias
1195 (put 'message-header-other-face 'face-alias 'message-header-other)
1197 (defface message-header-name
1200 (:foreground "DarkGreen"))
1203 (:foreground "cornflower blue"))
1206 "Face used for displaying header names."
1207 :group 'message-faces)
1208 ;; backward-compatibility alias
1209 (put 'message-header-name-face 'face-alias 'message-header-name)
1211 (defface message-header-xheader
1214 (:foreground "blue"))
1217 (:foreground "blue"))
1220 "Face used for displaying X-Header headers."
1221 :group 'message-faces)
1222 ;; backward-compatibility alias
1223 (put 'message-header-xheader-face 'face-alias 'message-header-xheader)
1225 (defface message-separator
1228 (:foreground "blue3"))
1231 (:foreground "brown"))
1234 "Face used for displaying the separator."
1235 :group 'message-faces)
1236 ;; backward-compatibility alias
1237 (put 'message-separator-face 'face-alias 'message-separator)
1239 (defface message-cited-text
1242 (:foreground "red"))
1245 (:foreground "red"))
1248 "Face used for displaying cited text names."
1249 :group 'message-faces)
1250 ;; backward-compatibility alias
1251 (put 'message-cited-text-face 'face-alias 'message-cited-text)
1253 (defface message-mml
1256 (:foreground "ForestGreen"))
1259 (:foreground "ForestGreen"))
1262 "Face used for displaying MML."
1263 :group 'message-faces)
1264 ;; backward-compatibility alias
1265 (put 'message-mml-face 'face-alias 'message-mml)
1267 (defun message-font-lock-make-header-matcher (regexp)
1270 (let ((start (point)))
1273 (goto-char (point-min))
1274 (if (re-search-forward
1275 (concat "^" (regexp-quote mail-header-separator) "$")
1277 (setq limit (min limit (match-beginning 0))))
1279 (and (< start limit)
1280 (re-search-forward ,regexp limit t))))))
1281 (if (featurep 'bytecomp)
1285 (defvar message-font-lock-keywords
1286 (let ((content "[ \t]*\\(.+\\(\n[ \t].*\\)*\\)\n?"))
1287 `((,(message-font-lock-make-header-matcher
1288 (concat "^\\([Tt]o:\\)" content))
1289 (1 'message-header-name)
1290 (2 'message-header-to nil t))
1291 (,(message-font-lock-make-header-matcher
1292 (concat "^\\(^[GBF]?[Cc][Cc]:\\|^[Rr]eply-[Tt]o:\\)" content))
1293 (1 'message-header-name)
1294 (2 'message-header-cc nil t))
1295 (,(message-font-lock-make-header-matcher
1296 (concat "^\\([Ss]ubject:\\)" content))
1297 (1 'message-header-name)
1298 (2 'message-header-subject nil t))
1299 (,(message-font-lock-make-header-matcher
1300 (concat "^\\([Nn]ewsgroups:\\|Followup-[Tt]o:\\)" content))
1301 (1 'message-header-name)
1302 (2 'message-header-newsgroups nil t))
1303 (,(message-font-lock-make-header-matcher
1304 (concat "^\\([A-Z][^: \n\t]+:\\)" content))
1305 (1 'message-header-name)
1306 (2 'message-header-other nil t))
1307 (,(message-font-lock-make-header-matcher
1308 (concat "^\\(X-[A-Za-z0-9-]+:\\|In-Reply-To:\\)" content))
1309 (1 'message-header-name)
1310 (2 'message-header-name))
1311 ,@(if (and mail-header-separator
1312 (not (equal mail-header-separator "")))
1313 `((,(concat "^\\(" (regexp-quote mail-header-separator) "\\)$")
1314 1 'message-separator))
1317 (re-search-forward (concat "^\\("
1318 message-cite-prefix-regexp
1321 (0 'message-cited-text))
1322 ("<#/?\\(multipart\\|part\\|external\\|mml\\|secure\\)[^>]*>"
1324 "Additional expressions to highlight in Message mode.")
1327 ;; XEmacs does it like this. For Emacs, we have to set the
1328 ;; `font-lock-defaults' buffer-local variable.
1329 (put 'message-mode 'font-lock-defaults '(message-font-lock-keywords t))
1331 (defvar message-face-alist
1332 '((bold . bold-region)
1333 (underline . underline-region)
1334 (default . (lambda (b e)
1336 (ununderline-region b e))))
1337 "Alist of mail and news faces for facemenu.
1338 The cdr of each entry is a function for applying the face to a region.")
1340 (defcustom message-send-hook nil
1341 "Hook run before sending messages.
1342 This hook is run quite early when sending."
1343 :group 'message-various
1344 :options '(ispell-message)
1345 :link '(custom-manual "(message)Various Message Variables")
1348 (defcustom message-send-mail-hook nil
1349 "Hook run before sending mail messages.
1350 This hook is run very late -- just before the message is sent as
1352 :group 'message-various
1353 :link '(custom-manual "(message)Various Message Variables")
1356 (defcustom message-send-news-hook nil
1357 "Hook run before sending news messages.
1358 This hook is run very late -- just before the message is sent as
1360 :group 'message-various
1361 :link '(custom-manual "(message)Various Message Variables")
1364 (defcustom message-sent-hook nil
1365 "Hook run after sending messages."
1366 :group 'message-various
1369 (defvar message-send-coding-system 'binary
1370 "Coding system to encode outgoing mail.")
1372 (defvar message-draft-coding-system
1373 mm-auto-save-coding-system
1374 "*Coding system to compose mail.
1375 If you'd like to make it possible to share draft files between XEmacs
1376 and Emacs, you may use `iso-2022-7bit' for this value at your own risk.
1377 Note that the coding-system `iso-2022-7bit' isn't suitable to all data.")
1379 (defcustom message-send-mail-partially-limit 1000000
1380 "The limitation of messages sent as message/partial.
1381 The lower bound of message size in characters, beyond which the message
1382 should be sent in several parts. If it is nil, the size is unlimited."
1384 :group 'message-buffers
1385 :link '(custom-manual "(message)Mail Variables")
1386 :type '(choice (const :tag "unlimited" nil)
1389 (defcustom message-alternative-emails nil
1390 "A regexp to match the alternative email addresses.
1391 The first matched address (not primary one) is used in the From field."
1392 :group 'message-headers
1393 :link '(custom-manual "(message)Message Headers")
1394 :type '(choice (const :tag "Always use primary" nil)
1397 (defcustom message-hierarchical-addresses nil
1398 "A list of hierarchical mail address definitions.
1400 Inside each entry, the first address is the \"top\" address, and
1401 subsequent addresses are subaddresses; this is used to indicate that
1402 mail sent to the first address will automatically be delivered to the
1403 subaddresses. So if the first address appears in the recipient list
1404 for a message, the subaddresses will be removed (if present) before
1405 the mail is sent. All addresses in this structure should be
1408 :group 'message-headers
1409 :type '(repeat (repeat string)))
1411 (defcustom message-mail-user-agent nil
1412 "Like `mail-user-agent'.
1413 Except if it is nil, use Gnus native MUA; if it is t, use
1416 :type '(radio (const :tag "Gnus native"
1419 (const :tag "`mail-user-agent'"
1422 (function-item :tag "Default Emacs mail"
1424 sendmail-user-agent)
1425 (function-item :tag "Emacs interface to MH"
1428 (function :tag "Other"))
1432 (defcustom message-wide-reply-confirm-recipients nil
1433 "Whether to confirm a wide reply to multiple email recipients.
1434 If this variable is nil, don't ask whether to reply to all recipients.
1435 If this variable is non-nil, pose the question \"Reply to all
1436 recipients?\" before a wide reply to multiple recipients. If the user
1437 answers yes, reply to all recipients as usual. If the user answers
1438 no, only reply back to the author."
1440 :group 'message-headers
1441 :link '(custom-manual "(message)Wide Reply")
1444 (defcustom message-user-fqdn nil
1445 "*Domain part of Messsage-Ids."
1447 :group 'message-headers
1448 :link '(custom-manual "(message)News Headers")
1449 :type '(radio (const :format "%v " nil)
1450 (string :format "FQDN: %v")))
1452 (defcustom message-use-idna (and (condition-case nil (require 'idna)
1454 (mm-coding-system-p 'utf-8)
1455 (executable-find idna-program)
1457 "Whether to encode non-ASCII in domain names into ASCII according to IDNA."
1459 :group 'message-headers
1460 :link '(custom-manual "(message)IDNA")
1461 :type '(choice (const :tag "Ask" ask)
1462 (const :tag "Never" nil)
1463 (const :tag "Always" t)))
1465 ;;; Internal variables.
1467 (defvar message-sending-message "Sending...")
1468 (defvar message-buffer-list nil)
1469 (defvar message-this-is-news nil)
1470 (defvar message-this-is-mail nil)
1471 (defvar message-draft-article nil)
1472 (defvar message-mime-part nil)
1473 (defvar message-posting-charset nil)
1474 (defvar message-inserted-headers nil)
1476 ;; Byte-compiler warning
1478 (defvar gnus-active-hashtb)
1479 (defvar gnus-read-active-file))
1481 ;;; Regexp matching the delimiter of messages in UNIX mail format
1482 ;;; (UNIX From lines), minus the initial ^. It should be a copy
1483 ;;; of rmail.el's rmail-unix-mail-delimiter.
1484 (defvar message-unix-mail-delimiter
1485 (let ((time-zone-regexp
1486 (concat "\\([A-Z]?[A-Z]?[A-Z][A-Z]\\( DST\\)?"
1487 "\\|[-+]?[0-9][0-9][0-9][0-9]"
1493 ;; Many things can happen to an RFC 822 mailbox before it is put into
1494 ;; a `From' line. The leading phrase can be stripped, e.g.
1495 ;; `Joe <@w.x:joe@y.z>' -> `<@w.x:joe@y.z>'. The <> can be stripped, e.g.
1496 ;; `<@x.y:joe@y.z>' -> `@x.y:joe@y.z'. Everything starting with a CRLF
1497 ;; can be removed, e.g.
1498 ;; From: joe@y.z (Joe K
1500 ;; can yield `From joe@y.z (Joe K Fri Mar 22 08:11:15 1996', and
1503 ;; can yield `From Joe User Fri Mar 22 08:11:15 1996'.
1504 ;; The mailbox can be removed or be replaced by white space, e.g.
1505 ;; From: "Joe User"{space}{tab}
1507 ;; can yield `From {space}{tab} Fri Mar 22 08:11:15 1996',
1508 ;; where {space} and {tab} represent the Ascii space and tab characters.
1509 ;; We want to match the results of any of these manglings.
1510 ;; The following regexp rejects names whose first characters are
1511 ;; obviously bogus, but after that anything goes.
1512 "\\([^\0-\b\n-\r\^?].*\\)?"
1514 ;; The time the message was sent.
1515 "\\([^\0-\r \^?]+\\) +" ; day of the week
1516 "\\([^\0-\r \^?]+\\) +" ; month
1517 "\\([0-3]?[0-9]\\) +" ; day of month
1518 "\\([0-2][0-9]:[0-5][0-9]\\(:[0-6][0-9]\\)?\\) *" ; time of day
1520 ;; Perhaps a time zone, specified by an abbreviation, or by a
1525 " \\([0-9][0-9]+\\) *"
1527 ;; On some systems the time zone can appear after the year, too.
1531 "\\(remote from .*\\)?"
1534 "Regexp matching the delimiter of messages in UNIX mail format.")
1536 (defvar message-unsent-separator
1537 (concat "^ *---+ +Unsent message follows +---+ *$\\|"
1538 "^ *---+ +Returned message +---+ *$\\|"
1539 "^Start of returned message$\\|"
1540 "^ *---+ +Original message +---+ *$\\|"
1541 "^ *--+ +begin message +--+ *$\\|"
1542 "^ *---+ +Original message follows +---+ *$\\|"
1543 "^ *---+ +Undelivered message follows +---+ *$\\|"
1544 "^|? *---+ +Message text follows: +---+ *|?$")
1545 "A regexp that matches the separator before the text of a failed message.")
1547 (defvar message-header-format-alist
1549 (To . message-fill-address)
1550 (Cc . message-fill-address)
1561 (References . message-shorten-references)
1563 "Alist used for formatting headers.")
1565 (defvar message-options nil
1566 "Some saved answers when sending message.")
1568 (defvar message-send-mail-real-function nil
1569 "Internal send mail function.")
1571 (defvar message-bogus-system-names "^localhost\\."
1572 "The regexp of bogus system names.")
1574 (defcustom message-valid-fqdn-regexp
1575 (concat "[a-z0-9][-.a-z0-9]+\\." ;; [hostname.subdomain.]domain.
1577 "\\([a-z][a-z]" ;; two letter country TDLs
1578 "\\|biz\\|com\\|edu\\|gov\\|int\\|mil\\|net\\|org"
1579 "\\|aero\\|coop\\|info\\|name\\|museum"
1580 "\\|arpa\\|pro\\|uucp\\|bitnet\\|bofh" ;; old style?
1582 "Regular expression that matches a valid FQDN."
1583 ;; see also: gnus-button-valid-fqdn-regexp
1585 :group 'message-headers
1589 (autoload 'idna-to-ascii "idna")
1590 (autoload 'message-setup-toolbar "messagexmas")
1591 (autoload 'mh-new-draft-name "mh-comp")
1592 (autoload 'mh-send-letter "mh-comp")
1593 (autoload 'gnus-point-at-eol "gnus-util")
1594 (autoload 'gnus-point-at-bol "gnus-util")
1595 (autoload 'gnus-output-to-rmail "gnus-util")
1596 (autoload 'gnus-output-to-mail "gnus-util")
1597 (autoload 'nndraft-request-associate-buffer "nndraft")
1598 (autoload 'nndraft-request-expire-articles "nndraft")
1599 (autoload 'gnus-open-server "gnus-int")
1600 (autoload 'gnus-request-post "gnus-int")
1601 (autoload 'gnus-alive-p "gnus-util")
1602 (autoload 'gnus-server-string "gnus")
1603 (autoload 'gnus-group-name-charset "gnus-group")
1604 (autoload 'gnus-group-name-decode "gnus-group")
1605 (autoload 'gnus-groups-from-server "gnus")
1606 (autoload 'rmail-output "rmailout")
1607 (autoload 'gnus-delay-article "gnus-delay")
1608 (autoload 'gnus-make-local-hook "gnus-util")
1609 (autoload 'gnus-extract-address-components "gnus-util"))
1614 ;;; Utility functions.
1617 (defmacro message-y-or-n-p (question show &rest text)
1618 "Ask QUESTION, displaying remaining args in a temporary buffer if SHOW."
1619 `(message-talkative-question 'y-or-n-p ,question ,show ,@text))
1621 (defmacro message-delete-line (&optional n)
1622 "Delete the current line (and the next N lines)."
1623 `(delete-region (progn (beginning-of-line) (point))
1624 (progn (forward-line ,(or n 1)) (point))))
1626 (defun message-mark-active-p ()
1627 "Non-nil means the mark and region are currently active in this buffer."
1630 (defun message-unquote-tokens (elems)
1631 "Remove double quotes (\") from strings in list ELEMS."
1632 (mapcar (lambda (item)
1633 (while (string-match "^\\(.*\\)\"\\(.*\\)$" item)
1634 (setq item (concat (match-string 1 item)
1635 (match-string 2 item))))
1639 (defun message-tokenize-header (header &optional separator)
1640 "Split HEADER into a list of header elements.
1641 SEPARATOR is a string of characters to be used as separators. \",\"
1642 is used by default."
1645 (let ((regexp (format "[%s]+" (or separator ",")))
1647 beg quoted elems paren)
1649 (mm-enable-multibyte)
1650 (setq beg (point-min))
1652 (goto-char (point-min))
1657 (cond ((and (> (point) beg)
1659 (and (looking-at regexp)
1662 (push (buffer-substring beg (point)) elems)
1663 (setq beg (match-end 0)))
1664 ((eq (char-after) ?\")
1665 (setq quoted (not quoted)))
1666 ((and (eq (char-after) ?\()
1669 ((and (eq (char-after) ?\))
1672 (nreverse elems)))))
1674 (defun message-mail-file-mbox-p (file)
1675 "Say whether FILE looks like a Unix mbox file."
1676 (when (and (file-exists-p file)
1677 (file-readable-p file)
1678 (file-regular-p file))
1680 (nnheader-insert-file-contents file)
1681 (goto-char (point-min))
1682 (looking-at message-unix-mail-delimiter))))
1684 (defun message-fetch-field (header &optional not-all)
1685 "The same as `mail-fetch-field', only remove all newlines.
1686 The buffer is expected to be narrowed to just the header of the message;
1687 see `message-narrow-to-headers-or-head'."
1688 (let* ((inhibit-point-motion-hooks t)
1689 (case-fold-search t)
1690 (value (mail-fetch-field header nil (not not-all))))
1692 (while (string-match "\n[\t ]+" value)
1693 (setq value (replace-match " " t t value)))
1694 (set-text-properties 0 (length value) nil value)
1697 (defun message-field-value (header &optional not-all)
1698 "The same as `message-fetch-field', only narrow to the headers first."
1701 (message-narrow-to-headers-or-head)
1702 (message-fetch-field header not-all))))
1704 (defun message-narrow-to-field ()
1705 "Narrow the buffer to the header on the current line."
1711 (if (re-search-forward "^[^ \n\t]" nil t)
1716 (goto-char (point-min)))
1718 (defun message-add-header (&rest headers)
1719 "Add the HEADERS to the message header, skipping those already present."
1722 (unless (string-match "^\\([^:]+\\):[ \t]*[^ \t]" (car headers))
1723 (error "Invalid header `%s'" (car headers)))
1724 (setq hclean (match-string 1 (car headers)))
1726 (message-narrow-to-headers)
1727 (unless (re-search-forward (concat "^" (regexp-quote hclean) ":") nil t)
1728 (goto-char (point-max))
1729 (if (string-match "\n$" (car headers))
1730 (insert (car headers))
1731 (insert (car headers) ?\n)))))
1732 (setq headers (cdr headers))))
1734 (defmacro message-with-reply-buffer (&rest forms)
1735 "Evaluate FORMS in the reply buffer, if it exists."
1736 `(when (and message-reply-buffer
1737 (buffer-name message-reply-buffer))
1739 (set-buffer message-reply-buffer)
1742 (put 'message-with-reply-buffer 'lisp-indent-function 0)
1743 (put 'message-with-reply-buffer 'edebug-form-spec '(body))
1745 (defun message-fetch-reply-field (header)
1746 "Fetch field HEADER from the message we're replying to."
1747 (message-with-reply-buffer
1749 (mail-narrow-to-head)
1750 (message-fetch-field header))))
1752 (defun message-strip-list-identifiers (subject)
1753 "Remove list identifiers in `gnus-list-identifiers' from string SUBJECT."
1754 (require 'gnus-sum) ; for gnus-list-identifiers
1755 (let ((regexp (if (stringp gnus-list-identifiers)
1756 gnus-list-identifiers
1757 (mapconcat 'identity gnus-list-identifiers " *\\|"))))
1758 (if (string-match (concat "\\(\\(\\(Re: +\\)?\\(" regexp
1759 " *\\)\\)+\\(Re: +\\)?\\)") subject)
1760 (concat (substring subject 0 (match-beginning 1))
1761 (or (match-string 3 subject)
1762 (match-string 5 subject))
1767 (defun message-strip-subject-re (subject)
1768 "Remove \"Re:\" from subject lines in string SUBJECT."
1769 (if (string-match message-subject-re-regexp subject)
1770 (substring subject (match-end 0))
1773 ;;; Start of functions adopted from `message-utils.el'.
1775 (defun message-strip-subject-trailing-was (subject)
1776 "Remove trailing \"(was: <old subject>)\" from SUBJECT lines.
1777 Leading \"Re: \" is not stripped by this function. Use the function
1778 `message-strip-subject-re' for this."
1779 (let* ((query message-subject-trailing-was-query)
1784 message-subject-trailing-was-ask-regexp
1785 message-subject-trailing-was-regexp)
1788 (setq new (substring subject 0 (match-beginning 0))))
1789 (if (or (not found) (eq query nil))
1792 (if (message-y-or-n-p
1793 "Strip `(was: <old subject>)' in subject? " t
1795 "Strip `(was: <old subject>)' in subject "
1796 "and use the new one instead?\n\n"
1797 "Current subject is: \""
1799 "New subject would be: \""
1801 "See the variable `message-subject-trailing-was-query' "
1802 "to get rid of this query."
1807 ;;; Suggested by Jonas Steverud @ www.dtek.chalmers.se/~d4jonas/
1810 (defun message-change-subject (new-subject)
1811 "Ask for NEW-SUBJECT header, append (was: <Old Subject>)."
1812 ;; <URL:http://www.landfield.com/usefor/drafts/draft-ietf-usefor-useage--1.02.unpaged>
1815 (read-from-minibuffer "New subject: ")))
1816 (cond ((and (not (or (null new-subject) ; new subject not empty
1817 (zerop (string-width new-subject))
1818 (string-match "^[ \t]*$" new-subject))))
1822 (message-narrow-to-headers)
1823 (message-fetch-field "Subject"))))
1824 (cond ((not old-subject)
1825 (error "No current subject"))
1828 (regexp-quote new-subject)
1830 old-subject)) ; yes, it really is a new subject
1831 ;; delete eventual Re: prefix
1833 (message-strip-subject-re old-subject))
1834 (message-goto-subject)
1835 (message-delete-line)
1836 (insert (concat "Subject: "
1839 old-subject ")\n")))))))))
1842 (defun message-mark-inserted-region (beg end)
1843 "Mark some region in the current article with enclosing tags.
1844 See `message-mark-insert-begin' and `message-mark-insert-end'."
1847 ;; add to the end of the region first, otherwise end would be invalid
1849 (insert message-mark-insert-end)
1851 (insert message-mark-insert-begin)))
1854 (defun message-mark-insert-file (file)
1855 "Insert FILE at point, marking it with enclosing tags.
1856 See `message-mark-insert-begin' and `message-mark-insert-end'."
1857 (interactive "fFile to insert: ")
1858 ;; reverse insertion to get correct result.
1860 (insert message-mark-insert-end)
1862 (insert-file-contents file)
1864 (insert message-mark-insert-begin)))
1867 (defun message-add-archive-header ()
1868 "Insert \"X-No-Archive: Yes\" in the header and a note in the body.
1869 The note can be customized using `message-archive-note'. When called with a
1870 prefix argument, ask for a text to insert. If you don't want the note in the
1871 body, set `message-archive-note' to nil."
1873 (if current-prefix-arg
1874 (setq message-archive-note
1875 (read-from-minibuffer "Reason for No-Archive: "
1876 (cons message-archive-note 0))))
1878 (if (message-goto-signature)
1879 (re-search-backward message-signature-separator))
1880 (when message-archive-note
1881 (insert message-archive-note)
1883 (message-add-header message-archive-header)
1884 (message-sort-headers)))
1887 (defun message-cross-post-followup-to-header (target-group)
1888 "Mangles FollowUp-To and Newsgroups header to point to TARGET-GROUP.
1889 With prefix-argument just set Follow-Up, don't cross-post."
1891 (list ; Completion based on Gnus
1892 (completing-read "Followup To: "
1893 (if (boundp 'gnus-newsrc-alist)
1895 nil nil '("poster" . 0)
1896 (if (boundp 'gnus-group-history)
1897 'gnus-group-history))))
1898 (message-remove-header "Follow[Uu]p-[Tt]o" t)
1899 (message-goto-newsgroups)
1901 ;; if we already did a crosspost before, kill old target
1902 (if (and message-cross-post-old-target
1904 (regexp-quote (concat "," message-cross-post-old-target))
1907 ;; unless (followup is to poster or user explicitly asked not
1908 ;; to cross-post, or target-group is already in Newsgroups)
1909 ;; add target-group to Newsgroups line.
1911 ;; def: cross-post, req:no
1912 (and message-cross-post-default (not current-prefix-arg))
1913 ;; def: no-cross-post, req:yes
1914 (and (not message-cross-post-default) current-prefix-arg))
1915 (not (string-match "poster" target-group))
1916 (not (string-match (regexp-quote target-group)
1917 (message-fetch-field "Newsgroups"))))
1919 (insert (concat "," target-group))))
1920 (end-of-line) ; ensure Followup: comes after Newsgroups:
1921 ;; unless new followup would be identical to Newsgroups line
1922 ;; make a new Followup-To line
1923 (if (not (string-match (concat "^[ \t]*"
1926 (message-fetch-field "Newsgroups")))
1927 (insert (concat "\nFollowup-To: " target-group)))
1928 (setq message-cross-post-old-target target-group))
1931 (defun message-cross-post-insert-note (target-group cross-post in-old
1933 "Insert a in message body note about a set Followup or Crosspost.
1934 If there have been previous notes, delete them. TARGET-GROUP specifies the
1935 group to Followup-To. When CROSS-POST is t, insert note about
1936 crossposting. IN-OLD specifies whether TARGET-GROUP is a member of
1937 OLD-GROUPS. OLD-GROUPS lists the old-groups the posting would have
1938 been made to before the user asked for a Crosspost."
1939 ;; start scanning body for previous uses
1940 (message-goto-signature)
1941 (let ((head (re-search-backward
1942 (concat "^" mail-header-separator)
1943 nil t))) ; just search in body
1944 (message-goto-signature)
1945 (while (re-search-backward
1946 (concat "^" (regexp-quote message-cross-post-note) ".*")
1948 (message-delete-line))
1949 (message-goto-signature)
1950 (while (re-search-backward
1951 (concat "^" (regexp-quote message-followup-to-note) ".*")
1953 (message-delete-line))
1955 (if (message-goto-signature)
1956 (re-search-backward message-signature-separator))
1959 (string-match "^[ \t]*poster[ \t]*$" target-group))
1960 (insert (concat message-followup-to-note target-group "\n"))
1961 (insert (concat message-cross-post-note target-group "\n")))))
1964 (defun message-cross-post-followup-to (target-group)
1965 "Crossposts message and set Followup-To to TARGET-GROUP.
1966 With prefix-argument just set Follow-Up, don't cross-post."
1968 (list ; Completion based on Gnus
1969 (completing-read "Followup To: "
1970 (if (boundp 'gnus-newsrc-alist)
1972 nil nil '("poster" . 0)
1973 (if (boundp 'gnus-group-history)
1974 'gnus-group-history))))
1975 (cond ((not (or (null target-group) ; new subject not empty
1976 (zerop (string-width target-group))
1977 (string-match "^[ \t]*$" target-group)))
1979 (let* ((old-groups (message-fetch-field "Newsgroups"))
1980 (in-old (string-match
1981 (regexp-quote target-group)
1982 (or old-groups ""))))
1983 ;; check whether target exactly matches old Newsgroups
1984 (cond ((not old-groups)
1985 (error "No current newsgroup"))
1989 (regexp-quote target-group)
1992 ;; yes, Newsgroups line must change
1993 (message-cross-post-followup-to-header target-group)
1994 ;; insert note whether we do cross-post or followup-to
1995 (funcall message-cross-post-note-function
1997 (if (or (and message-cross-post-default
1998 (not current-prefix-arg))
1999 (and (not message-cross-post-default)
2000 current-prefix-arg)) t)
2001 in-old old-groups))))))))
2003 ;;; Reduce To: to Cc: or Bcc: header
2006 (defun message-reduce-to-to-cc ()
2007 "Replace contents of To: header with contents of Cc: or Bcc: header."
2010 (save-restriction (message-narrow-to-headers)
2011 (message-fetch-field "cc")))
2013 (if (and (not cc-content)
2016 (message-narrow-to-headers)
2017 (message-fetch-field "bcc"))))
2022 (message-delete-line)
2023 (insert (concat "To: " cc-content "\n"))
2025 (message-narrow-to-headers)
2026 (message-remove-header (if bcc
2030 ;;; End of functions adopted from `message-utils.el'.
2032 (defun message-remove-header (header &optional is-regexp first reverse)
2033 "Remove HEADER in the narrowed buffer.
2034 If IS-REGEXP, HEADER is a regular expression.
2035 If FIRST, only remove the first instance of the header.
2036 Return the number of headers removed."
2037 (goto-char (point-min))
2038 (let ((regexp (if is-regexp header (concat "^" (regexp-quote header) ":")))
2040 (case-fold-search t)
2042 (while (and (not (eobp))
2045 (not (looking-at regexp))
2046 (looking-at regexp))
2053 ;; There might be a continuation header, so we have to search
2054 ;; until we find a new non-continuation line.
2057 (if (re-search-forward "^[^ \t]" nil t)
2058 (goto-char (match-beginning 0))
2061 (if (re-search-forward "^[^ \t]" nil t)
2062 (goto-char (match-beginning 0))
2063 (goto-char (point-max)))))
2066 (defun message-remove-first-header (header)
2067 "Remove the first instance of HEADER if there is more than one."
2069 (regexp (concat "^" (regexp-quote header) ":")))
2071 (goto-char (point-min))
2072 (while (re-search-forward regexp nil t)
2075 (message-remove-header header nil t)
2078 (defun message-narrow-to-headers ()
2079 "Narrow the buffer to the head of the message."
2082 (goto-char (point-min))
2083 (if (re-search-forward
2084 (concat "^" (regexp-quote mail-header-separator) "\n") nil t)
2087 (goto-char (point-min)))
2089 (defun message-narrow-to-head-1 ()
2090 "Like `message-narrow-to-head'. Don't widen."
2092 (goto-char (point-min))
2093 (if (search-forward "\n\n" nil 1)
2096 (goto-char (point-min)))
2098 (defun message-narrow-to-head ()
2099 "Narrow the buffer to the head of the message.
2100 Point is left at the beginning of the narrowed-to region."
2102 (message-narrow-to-head-1))
2104 (defun message-narrow-to-headers-or-head ()
2105 "Narrow the buffer to the head of the message."
2108 (goto-char (point-min))
2111 (concat "^" (regexp-quote mail-header-separator) "\n") nil t)
2112 (match-beginning 0))
2113 ((search-forward "\n\n" nil t)
2117 (goto-char (point-min)))
2119 (defun message-news-p ()
2120 "Say whether the current buffer contains a news message."
2121 (and (not message-this-is-mail)
2122 (or message-this-is-news
2125 (message-narrow-to-headers)
2126 (and (message-fetch-field "newsgroups")
2127 (not (message-fetch-field "posted-to"))))))))
2129 (defun message-mail-p ()
2130 "Say whether the current buffer contains a mail message."
2131 (and (not message-this-is-news)
2132 (or message-this-is-mail
2135 (message-narrow-to-headers)
2136 (or (message-fetch-field "to")
2137 (message-fetch-field "cc")
2138 (message-fetch-field "bcc")))))))
2140 (defun message-subscribed-p ()
2141 "Say whether we need to insert a MFT header."
2142 (or message-subscribed-regexps
2143 message-subscribed-addresses
2144 message-subscribed-address-file
2145 message-subscribed-address-functions))
2147 (defun message-next-header ()
2148 "Go to the beginning of the next header."
2150 (or (eobp) (forward-char 1))
2151 (not (if (re-search-forward "^[^ \t]" nil t)
2153 (goto-char (point-max)))))
2155 (defun message-sort-headers-1 ()
2156 "Sort the buffer as headers using `message-rank' text props."
2157 (goto-char (point-min))
2160 nil 'message-next-header
2162 (message-next-header)
2166 (or (get-text-property (point) 'message-rank)
2169 (defun message-sort-headers ()
2170 "Sort the headers of the current message according to `message-header-format-alist'."
2174 (let ((max (1+ (length message-header-format-alist)))
2176 (message-narrow-to-headers)
2177 (while (re-search-forward "^[^ \n]+:" nil t)
2179 (match-beginning 0) (1+ (match-beginning 0))
2181 (if (setq rank (length (memq (assq (intern (buffer-substring
2183 (1- (match-end 0))))
2184 message-header-format-alist)
2185 message-header-format-alist)))
2188 (message-sort-headers-1))))
2199 (defvar message-mode-map nil)
2201 (unless message-mode-map
2202 (setq message-mode-map (make-keymap))
2203 (set-keymap-parent message-mode-map text-mode-map)
2204 (define-key message-mode-map "\C-c?" 'describe-mode)
2206 (define-key message-mode-map "\C-c\C-f\C-t" 'message-goto-to)
2207 (define-key message-mode-map "\C-c\C-f\C-o" 'message-goto-from)
2208 (define-key message-mode-map "\C-c\C-f\C-b" 'message-goto-bcc)
2209 (define-key message-mode-map "\C-c\C-f\C-w" 'message-goto-fcc)
2210 (define-key message-mode-map "\C-c\C-f\C-c" 'message-goto-cc)
2211 (define-key message-mode-map "\C-c\C-f\C-s" 'message-goto-subject)
2212 (define-key message-mode-map "\C-c\C-f\C-r" 'message-goto-reply-to)
2213 (define-key message-mode-map "\C-c\C-f\C-n" 'message-goto-newsgroups)
2214 (define-key message-mode-map "\C-c\C-f\C-d" 'message-goto-distribution)
2215 (define-key message-mode-map "\C-c\C-f\C-f" 'message-goto-followup-to)
2216 (define-key message-mode-map "\C-c\C-f\C-m" 'message-goto-mail-followup-to)
2217 (define-key message-mode-map "\C-c\C-f\C-k" 'message-goto-keywords)
2218 (define-key message-mode-map "\C-c\C-f\C-u" 'message-goto-summary)
2219 (define-key message-mode-map "\C-c\C-f\C-i"
2220 'message-insert-or-toggle-importance)
2221 (define-key message-mode-map "\C-c\C-f\C-a"
2222 'message-generate-unsubscribed-mail-followup-to)
2224 ;; modify headers (and insert notes in body)
2225 (define-key message-mode-map "\C-c\C-fs" 'message-change-subject)
2227 (define-key message-mode-map "\C-c\C-fx" 'message-cross-post-followup-to)
2228 ;; prefix+message-cross-post-followup-to = same w/o cross-post
2229 (define-key message-mode-map "\C-c\C-ft" 'message-reduce-to-to-cc)
2230 (define-key message-mode-map "\C-c\C-fa" 'message-add-archive-header)
2231 ;; mark inserted text
2232 (define-key message-mode-map "\C-c\M-m" 'message-mark-inserted-region)
2233 (define-key message-mode-map "\C-c\M-f" 'message-mark-insert-file)
2235 (define-key message-mode-map "\C-c\C-b" 'message-goto-body)
2236 (define-key message-mode-map "\C-c\C-i" 'message-goto-signature)
2238 (define-key message-mode-map "\C-c\C-t" 'message-insert-to)
2239 (define-key message-mode-map "\C-c\C-fw" 'message-insert-wide-reply)
2240 (define-key message-mode-map "\C-c\C-n" 'message-insert-newsgroups)
2241 (define-key message-mode-map "\C-c\C-l" 'message-to-list-only)
2243 (define-key message-mode-map "\C-c\C-u" 'message-insert-or-toggle-importance)
2244 (define-key message-mode-map "\C-c\M-n"
2245 'message-insert-disposition-notification-to)
2247 (define-key message-mode-map "\C-c\C-y" 'message-yank-original)
2248 (define-key message-mode-map "\C-c\M-\C-y" 'message-yank-buffer)
2249 (define-key message-mode-map "\C-c\C-q" 'message-fill-yanked-message)
2250 (define-key message-mode-map "\C-c\C-w" 'message-insert-signature)
2251 (define-key message-mode-map "\C-c\M-h" 'message-insert-headers)
2252 (define-key message-mode-map "\C-c\C-r" 'message-caesar-buffer-body)
2253 (define-key message-mode-map "\C-c\C-o" 'message-sort-headers)
2254 (define-key message-mode-map "\C-c\M-r" 'message-rename-buffer)
2256 (define-key message-mode-map "\C-c\C-c" 'message-send-and-exit)
2257 (define-key message-mode-map "\C-c\C-s" 'message-send)
2258 (define-key message-mode-map "\C-c\C-k" 'message-kill-buffer)
2259 (define-key message-mode-map "\C-c\C-d" 'message-dont-send)
2260 (define-key message-mode-map "\C-c\n" 'gnus-delay-article)
2262 (define-key message-mode-map "\C-c\C-e" 'message-elide-region)
2263 (define-key message-mode-map "\C-c\C-v" 'message-delete-not-region)
2264 (define-key message-mode-map "\C-c\C-z" 'message-kill-to-signature)
2265 (define-key message-mode-map "\M-\r" 'message-newline-and-reformat)
2266 ;;(define-key message-mode-map "\M-q" 'message-fill-paragraph)
2267 (define-key message-mode-map [remap split-line] 'message-split-line)
2269 (define-key message-mode-map "\C-c\C-a" 'mml-attach-file)
2271 (define-key message-mode-map "\C-a" 'message-beginning-of-line)
2272 (define-key message-mode-map "\t" 'message-tab)
2273 (define-key message-mode-map "\M-;" 'comment-region))
2276 message-mode-menu message-mode-map "Message Menu."
2278 ["Yank Original" message-yank-original message-reply-buffer]
2279 ["Fill Yanked Message" message-fill-yanked-message t]
2280 ["Insert Signature" message-insert-signature t]
2281 ["Caesar (rot13) Message" message-caesar-buffer-body t]
2282 ["Caesar (rot13) Region" message-caesar-region (message-mark-active-p)]
2283 ["Elide Region" message-elide-region
2284 :active (message-mark-active-p)
2285 ,@(if (featurep 'xemacs) nil
2286 '(:help "Replace text in region with an ellipsis"))]
2287 ["Delete Outside Region" message-delete-not-region
2288 :active (message-mark-active-p)
2289 ,@(if (featurep 'xemacs) nil
2290 '(:help "Delete all quoted text outside region"))]
2291 ["Kill To Signature" message-kill-to-signature t]
2292 ["Newline and Reformat" message-newline-and-reformat t]
2293 ["Rename buffer" message-rename-buffer t]
2294 ["Spellcheck" ispell-message
2295 ,@(if (featurep 'xemacs) '(t)
2296 '(:help "Spellcheck this message"))]
2298 ["Insert Region Marked" message-mark-inserted-region
2299 :active (message-mark-active-p)
2300 ,@(if (featurep 'xemacs) nil
2301 '(:help "Mark region with enclosing tags"))]
2302 ["Insert File Marked..." message-mark-insert-file
2303 ,@(if (featurep 'xemacs) '(t)
2304 '(:help "Insert file at point marked with enclosing tags"))]
2306 ["Send Message" message-send-and-exit
2307 ,@(if (featurep 'xemacs) '(t)
2308 '(:help "Send this message"))]
2309 ["Postpone Message" message-dont-send
2310 ,@(if (featurep 'xemacs) '(t)
2311 '(:help "File this draft message and exit"))]
2312 ["Send at Specific Time..." gnus-delay-article
2313 ,@(if (featurep 'xemacs) '(t)
2314 '(:help "Ask, then arrange to send message at that time"))]
2315 ["Kill Message" message-kill-buffer
2316 ,@(if (featurep 'xemacs) '(t)
2317 '(:help "Delete this message without sending"))]))
2320 message-mode-field-menu message-mode-map ""
2322 ["To" message-goto-to t]
2323 ["From" message-goto-from t]
2324 ["Subject" message-goto-subject t]
2325 ["Change subject..." message-change-subject t]
2326 ["Cc" message-goto-cc t]
2327 ["Bcc" message-goto-bcc t]
2328 ["Fcc" message-goto-fcc t]
2329 ["Reply-To" message-goto-reply-to t]
2330 ["Flag As Important" message-insert-importance-high
2331 ,@(if (featurep 'xemacs) '(t)
2332 '(:help "Mark this message as important"))]
2333 ["Flag As Unimportant" message-insert-importance-low
2334 ,@(if (featurep 'xemacs) '(t)
2335 '(:help "Mark this message as unimportant"))]
2337 message-insert-disposition-notification-to
2338 ,@(if (featurep 'xemacs) '(t)
2339 '(:help "Request a receipt notification"))]
2341 ;; (typical) news stuff
2342 ["Summary" message-goto-summary t]
2343 ["Keywords" message-goto-keywords t]
2344 ["Newsgroups" message-goto-newsgroups t]
2345 ["Fetch Newsgroups" message-insert-newsgroups t]
2346 ["Followup-To" message-goto-followup-to t]
2347 ;; ["Followup-To (with note in body)" message-cross-post-followup-to t]
2348 ["Crosspost / Followup-To..." message-cross-post-followup-to t]
2349 ["Distribution" message-goto-distribution t]
2350 ["X-No-Archive:" message-add-archive-header t ]
2352 ;; (typical) mailing-lists stuff
2353 ["Fetch To" message-insert-to
2354 ,@(if (featurep 'xemacs) '(t)
2355 '(:help "Insert a To header that points to the author."))]
2356 ["Fetch To and Cc" message-insert-wide-reply
2357 ,@(if (featurep 'xemacs) '(t)
2359 "Insert To and Cc headers as if you were doing a wide reply."))]
2361 ["Send to list only" message-to-list-only t]
2362 ["Mail-Followup-To" message-goto-mail-followup-to t]
2363 ["Unsubscribed list post" message-generate-unsubscribed-mail-followup-to
2364 ,@(if (featurep 'xemacs) '(t)
2365 '(:help "Insert a reasonable `Mail-Followup-To:' header."))]
2366 ["Reduce To: to Cc:" message-reduce-to-to-cc t]
2368 ["Sort Headers" message-sort-headers t]
2369 ["Encode non-ASCII domain names" message-idna-to-ascii-rhs t]
2370 ["Goto Body" message-goto-body t]
2371 ["Goto Signature" message-goto-signature t]))
2373 (defvar message-tool-bar-map nil)
2376 (defvar facemenu-add-face-function)
2377 (defvar facemenu-remove-face-function))
2379 ;;; Forbidden properties
2381 ;; We use `after-change-functions' to keep special text properties
2382 ;; that interfer with the normal function of message mode out of the
2385 (defcustom message-strip-special-text-properties t
2386 "Strip special properties from the message buffer.
2388 Emacs has a number of special text properties which can break message
2389 composing in various ways. If this option is set, message will strip
2390 these properties from the message composition buffer. However, some
2391 packages requires these properties to be present in order to work.
2392 If you use one of these packages, turn this option off, and hope the
2393 message composition doesn't break too bad."
2395 :group 'message-various
2396 :link '(custom-manual "(message)Various Message Variables")
2399 (defconst message-forbidden-properties
2400 ;; No reason this should be clutter up customize. We make it a
2401 ;; property list (rather than a list of property symbols), to be
2402 ;; directly useful for `remove-text-properties'.
2403 '(field nil read-only nil invisible nil intangible nil
2404 mouse-face nil modification-hooks nil insert-in-front-hooks nil
2405 insert-behind-hooks nil point-entered nil point-left nil)
2406 ;; Other special properties:
2407 ;; category, face, display: probably doesn't do any harm.
2408 ;; fontified: is used by font-lock.
2409 ;; syntax-table, local-map: I dunno.
2410 ;; We need to add XEmacs names to the list.
2411 "Property list of with properties forbidden in message buffers.
2412 The values of the properties are ignored, only the property names are used.")
2414 (defun message-tamago-not-in-use-p (pos)
2415 "Return t when tamago version 4 is not in use at the cursor position.
2416 Tamago version 4 is a popular input method for writing Japanese text.
2417 It uses the properties `intangible', `invisible', `modification-hooks'
2418 and `read-only' when translating ascii or kana text to kanji text.
2419 These properties are essential to work, so we should never strip them."
2420 (not (and (boundp 'egg-modefull-mode)
2421 (symbol-value 'egg-modefull-mode)
2422 (or (memq (get-text-property pos 'intangible)
2423 '(its-part-1 its-part-2))
2424 (get-text-property pos 'egg-end)
2425 (get-text-property pos 'egg-lang)
2426 (get-text-property pos 'egg-start)))))
2428 (defun message-strip-forbidden-properties (begin end &optional old-length)
2429 "Strip forbidden properties between BEGIN and END, ignoring the third arg.
2430 This function is intended to be called from `after-change-functions'.
2431 See also `message-forbidden-properties'."
2432 (when (and message-strip-special-text-properties
2433 (message-tamago-not-in-use-p begin))
2434 (let ((buffer-read-only nil)
2435 (inhibit-read-only t))
2436 (while (not (= begin end))
2437 (when (not (get-text-property begin 'message-hidden))
2438 (remove-text-properties begin (1+ begin)
2439 message-forbidden-properties))
2443 (define-derived-mode message-mode text-mode "Message"
2444 "Major mode for editing mail and news to be sent.
2445 Like Text Mode but with these additional commands:\\<message-mode-map>
2446 C-c C-s `message-send' (send the message) C-c C-c `message-send-and-exit'
2447 C-c C-d Postpone sending the message C-c C-k Kill the message
2448 C-c C-f move to a header field (and create it if there isn't):
2449 C-c C-f C-t move to To C-c C-f C-s move to Subject
2450 C-c C-f C-c move to Cc C-c C-f C-b move to Bcc
2451 C-c C-f C-w move to Fcc C-c C-f C-r move to Reply-To
2452 C-c C-f C-u move to Summary C-c C-f C-n move to Newsgroups
2453 C-c C-f C-k move to Keywords C-c C-f C-d move to Distribution
2454 C-c C-f C-o move to From (\"Originator\")
2455 C-c C-f C-f move to Followup-To
2456 C-c C-f C-m move to Mail-Followup-To
2457 C-c C-f C-i cycle through Importance values
2458 C-c C-f s change subject and append \"(was: <Old Subject>)\"
2459 C-c C-f x crossposting with FollowUp-To header and note in body
2460 C-c C-f t replace To: header with contents of Cc: or Bcc:
2461 C-c C-f a Insert X-No-Archive: header and a note in the body
2462 C-c C-t `message-insert-to' (add a To header to a news followup)
2463 C-c C-l `message-to-list-only' (removes all but list address in to/cc)
2464 C-c C-n `message-insert-newsgroups' (add a Newsgroup header to a news reply)
2465 C-c C-b `message-goto-body' (move to beginning of message text).
2466 C-c C-i `message-goto-signature' (move to the beginning of the signature).
2467 C-c C-w `message-insert-signature' (insert `message-signature-file' file).
2468 C-c C-y `message-yank-original' (insert current message, if any).
2469 C-c C-q `message-fill-yanked-message' (fill what was yanked).
2470 C-c C-e `message-elide-region' (elide the text between point and mark).
2471 C-c C-v `message-delete-not-region' (remove the text outside the region).
2472 C-c C-z `message-kill-to-signature' (kill the text up to the signature).
2473 C-c C-r `message-caesar-buffer-body' (rot13 the message body).
2474 C-c C-a `mml-attach-file' (attach a file as MIME).
2475 C-c C-u `message-insert-or-toggle-importance' (insert or cycle importance).
2476 C-c M-n `message-insert-disposition-notification-to' (request receipt).
2477 C-c M-m `message-mark-inserted-region' (mark region with enclosing tags).
2478 C-c M-f `message-mark-insert-file' (insert file marked with enclosing tags).
2479 M-RET `message-newline-and-reformat' (break the line and reformat)."
2480 (setq local-abbrev-table text-mode-abbrev-table)
2481 (set (make-local-variable 'message-reply-buffer) nil)
2482 (set (make-local-variable 'message-inserted-headers) nil)
2483 (set (make-local-variable 'message-send-actions) nil)
2484 (set (make-local-variable 'message-exit-actions) nil)
2485 (set (make-local-variable 'message-kill-actions) nil)
2486 (set (make-local-variable 'message-postpone-actions) nil)
2487 (set (make-local-variable 'message-draft-article) nil)
2488 (setq buffer-offer-save t)
2489 (set (make-local-variable 'facemenu-add-face-function)
2491 (let ((face-fun (cdr (assq face message-face-alist))))
2493 (funcall face-fun (point) end)
2494 (error "Face %s not configured for %s mode" face mode-name)))
2496 (set (make-local-variable 'facemenu-remove-face-function) t)
2497 (set (make-local-variable 'message-reply-headers) nil)
2498 (make-local-variable 'message-newsreader)
2499 (make-local-variable 'message-mailer)
2500 (make-local-variable 'message-post-method)
2501 (set (make-local-variable 'message-sent-message-via) nil)
2502 (set (make-local-variable 'message-checksum) nil)
2503 (set (make-local-variable 'message-mime-part) 0)
2504 (message-setup-fill-variables)
2505 ;; Allow using comment commands to add/remove quoting.
2506 ;; (set (make-local-variable 'comment-start) message-yank-prefix)
2507 (when message-yank-prefix
2508 (set (make-local-variable 'comment-start) message-yank-prefix)
2509 (set (make-local-variable 'comment-start-skip)
2510 (concat "^" (regexp-quote message-yank-prefix) "[ \t]*")))
2511 (if (featurep 'xemacs)
2512 (message-setup-toolbar)
2513 (set (make-local-variable 'font-lock-defaults)
2514 '(message-font-lock-keywords t))
2515 (if (boundp 'tool-bar-map)
2516 (set (make-local-variable 'tool-bar-map) (message-tool-bar-map))))
2517 (easy-menu-add message-mode-menu message-mode-map)
2518 (easy-menu-add message-mode-field-menu message-mode-map)
2519 (gnus-make-local-hook 'after-change-functions)
2520 ;; Mmmm... Forbidden properties...
2521 (add-hook 'after-change-functions 'message-strip-forbidden-properties
2523 ;; Allow mail alias things.
2524 (when (eq message-mail-alias-type 'abbrev)
2525 (if (fboundp 'mail-abbrevs-setup)
2526 (mail-abbrevs-setup)
2527 (if (fboundp 'mail-aliases-setup) ; warning avoidance
2528 (mail-aliases-setup))))
2529 (unless buffer-file-name
2530 (message-set-auto-save-file-name))
2531 (unless (buffer-base-buffer)
2532 ;; Don't enable multibyte on an indirect buffer. Maybe enabling
2533 ;; multibyte is not necessary at all. -- zsh
2534 (mm-enable-multibyte))
2535 (set (make-local-variable 'indent-tabs-mode) nil) ;No tabs for indentation.
2538 (defun message-setup-fill-variables ()
2539 "Setup message fill variables."
2540 (set (make-local-variable 'fill-paragraph-function)
2541 'message-fill-paragraph)
2542 (make-local-variable 'paragraph-separate)
2543 (make-local-variable 'paragraph-start)
2544 (make-local-variable 'adaptive-fill-regexp)
2545 (unless (boundp 'adaptive-fill-first-line-regexp)
2546 (setq adaptive-fill-first-line-regexp nil))
2547 (make-local-variable 'adaptive-fill-first-line-regexp)
2548 (let ((quote-prefix-regexp
2549 ;; User should change message-cite-prefix-regexp if
2550 ;; message-yank-prefix is set to an abnormal value.
2551 (concat "\\(" message-cite-prefix-regexp "\\)[ \t]*")))
2552 (setq paragraph-start
2554 (regexp-quote mail-header-separator) "$\\|"
2555 "[ \t]*$\\|" ; blank lines
2556 "-- $\\|" ; signature delimiter
2557 "---+$\\|" ; delimiters for forwarded messages
2558 page-delimiter "$\\|" ; spoiler warnings
2559 ".*wrote:$\\|" ; attribution lines
2560 quote-prefix-regexp "$\\|" ; empty lines in quoted text
2562 "<#!*/?\\(multipart\\|part\\|external\\|mml\\|secure\\)"))
2563 (setq paragraph-separate paragraph-start)
2564 (setq adaptive-fill-regexp
2565 (concat quote-prefix-regexp "\\|" adaptive-fill-regexp))
2566 (setq adaptive-fill-first-line-regexp
2567 (concat quote-prefix-regexp "\\|"
2568 adaptive-fill-first-line-regexp)))
2569 (make-local-variable 'auto-fill-inhibit-regexp)
2570 ;;(setq auto-fill-inhibit-regexp "^[A-Z][^: \n\t]+:")
2571 (setq auto-fill-inhibit-regexp nil)
2572 (make-local-variable 'normal-auto-fill-function)
2573 (setq normal-auto-fill-function 'message-do-auto-fill)
2574 ;; KLUDGE: auto fill might already be turned on in `text-mode-hook'.
2575 ;; In that case, ensure that it uses the right function. The real
2576 ;; solution would be not to use `define-derived-mode', and run
2577 ;; `text-mode-hook' ourself at the end of the mode.
2578 ;; -- Per Abrahamsen <abraham@dina.kvl.dk> Date: 2001-10-19.
2579 (when auto-fill-function
2580 (setq auto-fill-function normal-auto-fill-function)))
2585 ;;; Message mode commands
2588 ;;; Movement commands
2590 (defun message-goto-to ()
2591 "Move point to the To header."
2593 (message-position-on-field "To"))
2595 (defun message-goto-from ()
2596 "Move point to the From header."
2598 (message-position-on-field "From"))
2600 (defun message-goto-subject ()
2601 "Move point to the Subject header."
2603 (message-position-on-field "Subject"))
2605 (defun message-goto-cc ()
2606 "Move point to the Cc header."
2608 (message-position-on-field "Cc" "To"))
2610 (defun message-goto-bcc ()
2611 "Move point to the Bcc header."
2613 (message-position-on-field "Bcc" "Cc" "To"))
2615 (defun message-goto-fcc ()
2616 "Move point to the Fcc header."
2618 (message-position-on-field "Fcc" "To" "Newsgroups"))
2620 (defun message-goto-reply-to ()
2621 "Move point to the Reply-To header."
2623 (message-position-on-field "Reply-To" "Subject"))
2625 (defun message-goto-newsgroups ()
2626 "Move point to the Newsgroups header."
2628 (message-position-on-field "Newsgroups"))
2630 (defun message-goto-distribution ()
2631 "Move point to the Distribution header."
2633 (message-position-on-field "Distribution"))
2635 (defun message-goto-followup-to ()
2636 "Move point to the Followup-To header."
2638 (message-position-on-field "Followup-To" "Newsgroups"))
2640 (defun message-goto-mail-followup-to ()
2641 "Move point to the Mail-Followup-To header."
2643 (message-position-on-field "Mail-Followup-To" "To"))
2645 (defun message-goto-keywords ()
2646 "Move point to the Keywords header."
2648 (message-position-on-field "Keywords" "Subject"))
2650 (defun message-goto-summary ()
2651 "Move point to the Summary header."
2653 (message-position-on-field "Summary" "Subject"))
2655 (defun message-goto-body (&optional interactivep)
2656 "Move point to the beginning of the message body."
2657 (interactive (list t))
2658 (when (and interactivep
2659 (looking-at "[ \t]*\n"))
2661 (goto-char (point-min))
2662 (or (search-forward (concat "\n" mail-header-separator "\n") nil t)
2663 (search-forward-regexp "[^:]+:\\([^\n]\\|\n[ \t]\\)+\n\n" nil t)))
2665 (defun message-goto-eoh ()
2666 "Move point to the end of the headers."
2671 (defun message-goto-signature ()
2672 "Move point to the beginning of the message signature.
2673 If there is no signature in the article, go to the end and
2676 (goto-char (point-min))
2677 (if (re-search-forward message-signature-separator nil t)
2679 (goto-char (point-max))
2682 (defun message-generate-unsubscribed-mail-followup-to (&optional include-cc)
2683 "Insert a reasonable MFT header in a post to an unsubscribed list.
2684 When making original posts to a mailing list you are not subscribed to,
2685 you have to type in a MFT header by hand. The contents, usually, are
2686 the addresses of the list and your own address. This function inserts
2687 such a header automatically. It fetches the contents of the To: header
2688 in the current mail buffer, and appends the current `user-mail-address'.
2690 If the optional argument INCLUDE-CC is non-nil, the addresses in the
2691 Cc: header are also put into the MFT."
2696 (message-narrow-to-headers)
2697 (message-remove-header "Mail-Followup-To")
2698 (setq cc (and include-cc (message-fetch-field "Cc")))
2700 (concat (message-fetch-field "To") "," cc)
2701 (message-fetch-field "To"))))
2702 (message-goto-mail-followup-to)
2703 (insert (concat tos ", " user-mail-address))))
2707 (defun message-insert-to (&optional force)
2708 "Insert a To header that points to the author of the article being replied to.
2709 If the original author requested not to be sent mail, don't insert unless the
2710 prefix FORCE is given."
2712 (let* ((mct (message-fetch-reply-field "mail-copies-to"))
2713 (dont (and mct (or (equal (downcase mct) "never")
2714 (equal (downcase mct) "nobody"))))
2715 (to (or (message-fetch-reply-field "mail-reply-to")
2716 (message-fetch-reply-field "reply-to")
2717 (message-fetch-reply-field "from"))))
2721 "Ignoring the user request not to have copies sent via mail"
2722 "Complying with the user request not to have copies sent via mail")))
2723 (when (and force (not to))
2724 (error "No mail address in the article"))
2725 (when (and to (or force (not dont)))
2726 (message-carefully-insert-headers (list (cons 'To to))))))
2728 (defun message-insert-wide-reply ()
2729 "Insert To and Cc headers as if you were doing a wide reply."
2731 (let ((headers (message-with-reply-buffer
2732 (message-get-reply-headers t))))
2733 (message-carefully-insert-headers headers)))
2735 (defcustom message-header-synonyms
2737 "List of lists of header synonyms.
2738 E.g., if this list contains a member list with elements `Cc' and `To',
2739 then `message-carefully-insert-headers' will not insert a `To' header
2740 when the message is already `Cc'ed to the recipient."
2742 :group 'message-headers
2743 :link '(custom-manual "(message)Message Headers")
2744 :type '(repeat sexp))
2746 (defun message-carefully-insert-headers (headers)
2747 "Insert the HEADERS, an alist, into the message buffer.
2748 Does not insert the headers when they are already present there
2749 or in the synonym headers, defined by `message-header-synonyms'."
2750 ;; FIXME: Should compare only the address and not the full name. Comparison
2751 ;; should be done case-folded (and with `string=' rather than
2753 ;; (mail-strip-quoted-names "Foo Bar <foo@bar>, bla@fasel (Bla Fasel)")
2754 (dolist (header headers)
2755 (let* ((header-name (symbol-name (car header)))
2756 (new-header (cdr header))
2757 (synonyms (loop for synonym in message-header-synonyms
2758 when (memq (car header) synonym) return synonym))
2760 (loop for synonym in synonyms
2761 for old-header = (mail-fetch-field (symbol-name synonym))
2762 when (and old-header (string-match new-header old-header))
2765 (message "already have `%s' in `%s'" new-header old-header)
2766 (when (and (message-position-on-field header-name)
2767 (setq old-header (mail-fetch-field header-name))
2768 (not (string-match "\\` *\\'" old-header)))
2770 (insert new-header)))))
2772 (defun message-widen-reply ()
2773 "Widen the reply to include maximum recipients."
2776 (and message-reply-buffer
2777 (buffer-name message-reply-buffer)
2779 (set-buffer message-reply-buffer)
2780 (message-get-reply-headers t)))))
2783 (message-narrow-to-headers)
2784 (dolist (elem follow-to)
2785 (message-remove-header (symbol-name (car elem)))
2786 (goto-char (point-min))
2787 (insert (symbol-name (car elem)) ": "
2788 (cdr elem) "\n"))))))
2790 (defun message-insert-newsgroups ()
2791 "Insert the Newsgroups header from the article being replied to."
2793 (when (and (message-position-on-field "Newsgroups")
2794 (mail-fetch-field "newsgroups")
2795 (not (string-match "\\` *\\'" (mail-fetch-field "newsgroups"))))
2797 (insert (or (message-fetch-reply-field "newsgroups") "")))
2801 ;;; Various commands
2803 (defun message-delete-not-region (beg end)
2804 "Delete everything in the body of the current message outside of the region."
2809 ;; snarf citation prefix, if appropriate
2810 (unless (eq (point) (progn (beginning-of-line) (point)))
2811 (when (looking-at message-cite-prefix-regexp)
2812 (setq citeprefix (match-string 0))))
2814 (delete-region (point) (if (not (message-goto-signature))
2820 (delete-region beg (progn (message-goto-body)
2824 (insert citeprefix))))
2825 (when (message-goto-signature)
2828 (defun message-kill-to-signature ()
2829 "Deletes all text up to the signature."
2831 (let ((point (point)))
2832 (message-goto-signature)
2835 (kill-region point (point))
2839 (defun message-newline-and-reformat (&optional arg not-break)
2840 "Insert four newlines, and then reformat if inside quoted text.
2841 Prefix arg means justify as well."
2842 (interactive (list (if current-prefix-arg 'full)))
2843 (let (quoted point beg end leading-space bolp)
2844 (setq point (point))
2847 (setq bolp (= beg point))
2848 ;; Find first line of the paragraph.
2850 (while (and (not (eobp))
2851 (not (looking-at message-cite-prefix-regexp))
2852 (looking-at paragraph-start))
2855 (when (looking-at message-cite-prefix-regexp)
2856 (setq quoted (match-string 0))
2857 (goto-char (match-end 0))
2858 (looking-at "[ \t]*")
2859 (setq leading-space (match-string 0)))
2863 (< (- point beg) (length quoted)))
2864 ;; break inside the cite prefix.
2870 (while (and (not (eobp))
2871 (not (looking-at paragraph-separate))
2872 (looking-at message-cite-prefix-regexp)
2873 (equal quoted (match-string 0)))
2874 (goto-char (match-end 0))
2875 (looking-at "[ \t]*")
2876 (if (> (length leading-space) (length (match-string 0)))
2877 (setq leading-space (match-string 0)))
2881 (while (and (if (bobp) nil (forward-line -1) t)
2882 (not (looking-at paragraph-start))
2883 (looking-at message-cite-prefix-regexp)
2884 (equal quoted (match-string 0)))
2886 (goto-char (match-end 0))
2887 (looking-at "[ \t]*")
2888 (if (> (length leading-space) (length (match-string 0)))
2889 (setq leading-space (match-string 0)))))
2890 (while (and (not (eobp))
2891 (not (looking-at paragraph-separate))
2892 (not (looking-at message-cite-prefix-regexp)))
2896 (while (and (if (bobp) nil (forward-line -1) t)
2897 (not (looking-at paragraph-start))
2898 (not (looking-at message-cite-prefix-regexp)))
2899 (setq beg (point))))
2902 (narrow-to-region beg end)
2909 (setq point (point))
2910 ;; (newline 2) doesn't mark both newline's as hard, so call
2911 ;; newline twice. -jas
2914 (delete-region (point) (re-search-forward "[ \t]*"))
2915 (when (and quoted (not bolp))
2916 (insert quoted leading-space)))
2919 (let* ((adaptive-fill-regexp
2920 (regexp-quote (concat quoted leading-space)))
2921 (adaptive-fill-first-line-regexp
2922 adaptive-fill-regexp ))
2923 (fill-paragraph arg))
2924 (fill-paragraph arg))
2925 (if point (goto-char point)))))
2927 (defun message-fill-paragraph (&optional arg)
2928 "Like `fill-paragraph'."
2929 (interactive (list (if current-prefix-arg 'full)))
2930 (if (if (boundp 'filladapt-mode) filladapt-mode)
2932 (message-newline-and-reformat arg t)
2935 ;; Is it better to use `mail-header-end'?
2936 (defun message-point-in-header-p ()
2937 "Return t if point is in the header."
2940 (goto-char (point-min))
2941 (not (re-search-forward
2942 (concat "^" (regexp-quote mail-header-separator) "\n")
2945 (defun message-do-auto-fill ()
2946 "Like `do-auto-fill', but don't fill in message header."
2947 (unless (message-point-in-header-p)
2950 (defun message-insert-signature (&optional force)
2951 "Insert a signature. See documentation for variable `message-signature'."
2952 (interactive (list 0))
2955 ((and (null message-signature)
2958 (goto-char (point-max))
2959 (not (re-search-backward message-signature-separator nil t))))
2960 ((and (null message-signature)
2963 ((functionp message-signature)
2964 (funcall message-signature))
2965 ((listp message-signature)
2966 (eval message-signature))
2967 (t message-signature)))
2969 (cond ((stringp signature)
2971 ((and (eq t signature)
2972 message-signature-file
2973 (file-exists-p message-signature-file))
2976 (goto-char (point-max))
2977 ;; Insert the signature.
2980 (when message-signature-insert-empty-line
2983 (if (eq signature t)
2984 (insert-file-contents message-signature-file)
2986 (goto-char (point-max))
2987 (or (bolp) (insert "\n")))))
2989 (defun message-insert-importance-high ()
2990 "Insert header to mark message as important."
2994 (message-narrow-to-headers)
2995 (message-remove-header "Importance"))
2997 (insert "Importance: high\n")))
2999 (defun message-insert-importance-low ()
3000 "Insert header to mark message as unimportant."
3004 (message-narrow-to-headers)
3005 (message-remove-header "Importance"))
3007 (insert "Importance: low\n")))
3009 (defun message-insert-or-toggle-importance ()
3010 "Insert a \"Importance: high\" header, or cycle through the header values.
3011 The three allowed values according to RFC 1327 are `high', `normal'
3015 (let ((valid '("high" "normal" "low"))
3019 (message-narrow-to-headers)
3020 (when (setq cur (message-fetch-field "Importance"))
3021 (message-remove-header "Importance")
3022 (setq new (cond ((string= cur "high")
3024 ((string= cur "low")
3029 (insert (format "Importance: %s\n" new)))))
3031 (defun message-insert-disposition-notification-to ()
3032 "Request a disposition notification (return receipt) to this message.
3033 Note that this should not be used in newsgroups."
3037 (message-narrow-to-headers)
3038 (message-remove-header "Disposition-Notification-To"))
3040 (insert (format "Disposition-Notification-To: %s\n"
3041 (or (message-field-value "Reply-to")
3042 (message-field-value "From")
3043 (message-make-from))))))
3045 (defun message-elide-region (b e)
3046 "Elide the text in the region.
3047 An ellipsis (from `message-elide-ellipsis') will be inserted where the
3051 (insert message-elide-ellipsis))
3053 (defvar message-caesar-translation-table nil)
3055 (defun message-caesar-region (b e &optional n)
3056 "Caesar rotate region B to E by N, default 13, for decrypting netnews."
3059 (min (point) (or (mark t) (point)))
3060 (max (point) (or (mark t) (point)))
3061 (when current-prefix-arg
3062 (prefix-numeric-value current-prefix-arg))))
3064 (setq n (if (numberp n) (mod n 26) 13)) ;canonize N
3065 (unless (or (zerop n) ; no action needed for a rot of 0
3066 (= b e)) ; no region to rotate
3067 ;; We build the table, if necessary.
3068 (when (or (not message-caesar-translation-table)
3069 (/= (aref message-caesar-translation-table ?a) (+ ?a n)))
3070 (setq message-caesar-translation-table
3071 (message-make-caesar-translation-table n)))
3072 (translate-region b e message-caesar-translation-table)))
3074 (defun message-make-caesar-translation-table (n)
3075 "Create a rot table with offset N."
3077 (table (make-string 256 0)))
3078 (while (< (incf i) 256)
3081 (substring table 0 ?A)
3082 (substring table (+ ?A n) (+ ?A n (- 26 n)))
3083 (substring table ?A (+ ?A n))
3084 (substring table (+ ?A 26) ?a)
3085 (substring table (+ ?a n) (+ ?a n (- 26 n)))
3086 (substring table ?a (+ ?a n))
3087 (substring table (+ ?a 26) 255))))
3089 (defun message-caesar-buffer-body (&optional rotnum)
3090 "Caesar rotate all letters in the current buffer by 13 places.
3091 Used to encode/decode possibly offensive messages (commonly in rec.humor).
3092 With prefix arg, specifies the number of places to rotate each letter forward.
3093 Mail and USENET news headers are not rotated."
3094 (interactive (if current-prefix-arg
3095 (list (prefix-numeric-value current-prefix-arg))
3099 (when (message-goto-body)
3100 (narrow-to-region (point) (point-max)))
3101 (message-caesar-region (point-min) (point-max) rotnum))))
3103 (defun message-pipe-buffer-body (program)
3104 "Pipe the message body in the current buffer through PROGRAM."
3107 (when (message-goto-body)
3108 (narrow-to-region (point) (point-max)))
3109 (shell-command-on-region
3110 (point-min) (point-max) program nil t))))
3112 (defun message-rename-buffer (&optional enter-string)
3113 "Rename the *message* buffer to \"*message* RECIPIENT\".
3114 If the function is run with a prefix, it will ask for a new buffer
3115 name, rather than giving an automatic name."
3116 (interactive "Pbuffer name: ")
3119 (goto-char (point-min))
3120 (narrow-to-region (point)
3121 (search-forward mail-header-separator nil 'end))
3123 (if (message-news-p) (message-fetch-field "Newsgroups")
3124 (message-fetch-field "To"))
3127 (if (string-match "," mail-to)
3128 (concat (substring mail-to 0 (match-beginning 0)) ", ...")
3130 (name-default (concat "*message* " mail-trimmed-to))
3131 (name (if enter-string
3132 (read-string "New buffer name: " name-default)
3134 (rename-buffer name t)))))
3136 (defun message-fill-yanked-message (&optional justifyp)
3137 "Fill the paragraphs of a message yanked into this one.
3138 Numeric argument means justify as well."
3141 (goto-char (point-min))
3142 (search-forward (concat "\n" mail-header-separator "\n") nil t)
3143 (let ((fill-prefix message-yank-prefix))
3144 (fill-individual-paragraphs (point) (point-max) justifyp))))
3146 (defun message-indent-citation ()
3147 "Modify text just inserted from a message to be cited.
3148 The inserted text should be the region.
3149 When this function returns, the region is again around the modified text.
3151 Normally, indent each nonblank line `message-indentation-spaces' spaces.
3152 However, if `message-yank-prefix' is non-nil, insert that prefix on each line."
3153 (let ((start (point)))
3154 ;; Remove unwanted headers.
3155 (when message-ignored-cited-headers
3160 (if (search-forward "\n\n" nil t)
3163 (message-remove-header message-ignored-cited-headers t)
3164 (when (= (point-min) (point-max))
3165 (setq all-removed t))
3166 (goto-char (point-max)))
3170 ;; Delete blank lines at the start of the buffer.
3171 (while (and (point-min)
3174 (message-delete-line))
3175 ;; Delete blank lines at the end of the buffer.
3176 (goto-char (point-max))
3179 (while (and (zerop (forward-line -1))
3181 (message-delete-line))
3182 ;; Do the indentation.
3183 (if (null message-yank-prefix)
3184 (indent-rigidly start (mark t) message-indentation-spaces)
3187 (while (< (point) (mark t))
3188 (if (or (looking-at ">") (looking-at "^$"))
3189 (insert message-yank-cited-prefix)
3190 (insert message-yank-prefix))
3194 (defun message-yank-original (&optional arg)
3195 "Insert the message being replied to, if any.
3196 Puts point before the text and mark after.
3197 Normally indents each nonblank line ARG spaces (default 3). However,
3198 if `message-yank-prefix' is non-nil, insert that prefix on each line.
3200 This function uses `message-cite-function' to do the actual citing.
3202 Just \\[universal-argument] as argument means don't indent, insert no
3203 prefix, and don't delete any headers."
3205 (let ((modified (buffer-modified-p)))
3206 (when (and message-reply-buffer
3207 message-cite-function)
3208 (delete-windows-on message-reply-buffer t)
3209 (insert-buffer message-reply-buffer)
3211 (funcall message-cite-function))
3212 (message-exchange-point-and-mark)
3216 (setq message-checksum (message-checksum))))))
3218 (defun message-yank-buffer (buffer)
3219 "Insert BUFFER into the current buffer and quote it."
3220 (interactive "bYank buffer: ")
3221 (let ((message-reply-buffer (get-buffer buffer)))
3222 (save-window-excursion
3223 (message-yank-original))))
3225 (defun message-buffers ()
3226 "Return a list of active message buffers."
3229 (dolist (buffer (buffer-list t))
3231 (when (and (eq major-mode 'message-mode)
3232 (null message-sent-message-via))
3233 (push (buffer-name buffer) buffers))))
3234 (nreverse buffers)))
3236 (defun message-cite-original-without-signature ()
3237 "Cite function in the standard Message manner."
3238 (let* ((start (point))
3241 (when message-indent-citation-function
3242 (if (listp message-indent-citation-function)
3243 message-indent-citation-function
3244 (list message-indent-citation-function))))
3245 ;; This function may be called by `gnus-summary-yank-message' and
3246 ;; may insert a different article from the original. So, we will
3247 ;; modify the value of `message-reply-headers' with that article.
3248 (message-reply-headers
3250 (narrow-to-region start end)
3251 (message-narrow-to-head-1)
3253 (or (message-fetch-field "subject") "none")
3254 (message-fetch-field "from")
3255 (message-fetch-field "date")
3256 (message-fetch-field "message-id" t)
3257 (message-fetch-field "references")
3259 (mml-quote-region start end)
3263 (when (re-search-backward message-signature-separator start t)
3264 ;; Also peel off any blank lines before the signature.
3266 (while (looking-at "^[ \t]*$")
3269 (delete-region (point) end)
3270 (unless (search-backward "\n\n" start t)
3271 ;; Insert a blank line if it is peeled off.
3275 (funcall (pop functions)))
3276 (when message-citation-line-function
3279 (funcall message-citation-line-function))))
3281 (eval-when-compile (defvar mail-citation-hook)) ;Compiler directive
3282 (defun message-cite-original ()
3283 "Cite function in the standard Message manner."
3284 (if (and (boundp 'mail-citation-hook)
3286 (run-hooks 'mail-citation-hook)
3287 (let* ((start (point))
3290 (when message-indent-citation-function
3291 (if (listp message-indent-citation-function)
3292 message-indent-citation-function
3293 (list message-indent-citation-function))))
3294 ;; This function may be called by `gnus-summary-yank-message' and
3295 ;; may insert a different article from the original. So, we will
3296 ;; modify the value of `message-reply-headers' with that article.
3297 (message-reply-headers
3299 (narrow-to-region start end)
3300 (message-narrow-to-head-1)
3302 (or (message-fetch-field "subject") "none")
3303 (message-fetch-field "from")
3304 (message-fetch-field "date")
3305 (message-fetch-field "message-id" t)
3306 (message-fetch-field "references")
3308 (mml-quote-region start end)
3311 (funcall (pop functions)))
3312 (when message-citation-line-function
3315 (funcall message-citation-line-function)))))
3317 (defun message-insert-citation-line ()
3318 "Insert a simple citation line."
3319 (when message-reply-headers
3320 (insert (mail-header-from message-reply-headers) " writes:\n\n")))
3322 (defun message-position-on-field (header &rest afters)
3323 (let ((case-fold-search t))
3326 (goto-char (point-min))
3329 (concat "^" (regexp-quote mail-header-separator) "$"))
3330 (match-beginning 0)))
3331 (goto-char (point-min))
3332 (if (re-search-forward (concat "^" (regexp-quote header) ":") nil t)
3334 (re-search-forward "^[^ \t]" nil 'move)
3336 (skip-chars-backward "\n")
3339 (not (re-search-forward
3340 (concat "^" (regexp-quote (car afters)) ":")
3344 (re-search-forward "^[^ \t]" nil 'move)
3345 (beginning-of-line))
3346 (insert header ": \n")
3350 (defun message-remove-signature ()
3351 "Remove the signature from the text between point and mark.
3352 The text will also be indented the normal way."
3354 (let ((start (point))
3356 (if (not (re-search-forward message-signature-separator (mark t) t))
3357 ;; No signature here, so we just indent the cited text.
3358 (message-indent-citation)
3359 ;; Find the last non-empty line.
3361 (while (looking-at "[ \t]*$")
3364 (setq mark (set-marker (make-marker) (point)))
3366 (message-indent-citation)
3367 ;; Enable undoing the deletion.
3369 (delete-region mark (mark t))
3370 (set-marker mark nil)))))
3375 ;;; Sending messages
3378 (defun message-send-and-exit (&optional arg)
3379 "Send message like `message-send', then, if no errors, exit from mail buffer."
3381 (let ((buf (current-buffer))
3382 (actions message-exit-actions))
3383 (when (and (message-send arg)
3385 (if message-kill-buffer-on-exit
3388 (when (eq buf (current-buffer))
3389 (message-bury buf)))
3390 (message-do-actions actions)
3393 (defun message-dont-send ()
3394 "Don't send the message you have been editing.
3395 Instead, just auto-save the buffer and then bury it."
3397 (set-buffer-modified-p t)
3399 (let ((actions message-postpone-actions))
3400 (message-bury (current-buffer))
3401 (message-do-actions actions)))
3403 (defun message-kill-buffer ()
3404 "Kill the current buffer."
3406 (when (or (not (buffer-modified-p))
3407 (yes-or-no-p "Message modified; kill anyway? "))
3408 (let ((actions message-kill-actions)
3409 (draft-article message-draft-article)
3410 (auto-save-file-name buffer-auto-save-file-name)
3411 (file-name buffer-file-name)
3412 (modified (buffer-modified-p)))
3413 (setq buffer-file-name nil)
3414 (kill-buffer (current-buffer))
3415 (when (and (or (and auto-save-file-name
3416 (file-exists-p auto-save-file-name))
3418 (file-exists-p file-name)))
3419 (yes-or-no-p (format "Remove the backup file%s? "
3420 (if modified " too" ""))))
3422 (delete-file auto-save-file-name))
3423 (let ((message-draft-article draft-article))
3424 (message-disassociate-draft)))
3425 (message-do-actions actions))))
3427 (defun message-bury (buffer)
3428 "Bury this mail BUFFER."
3429 (let ((newbuf (other-buffer buffer)))
3430 (bury-buffer buffer)
3431 (if (and (fboundp 'frame-parameters)
3432 (cdr (assq 'dedicated (frame-parameters)))
3433 (not (null (delq (selected-frame) (visible-frame-list)))))
3434 (delete-frame (selected-frame))
3435 (switch-to-buffer newbuf))))
3437 (defun message-send (&optional arg)
3438 "Send the message in the current buffer.
3439 If `message-interactive' is non-nil, wait for success indication or
3440 error messages, and inform user.
3441 Otherwise any failure is reported in a message back to the user from
3443 The usage of ARG is defined by the instance that called Message.
3444 It should typically alter the sending method in some way or other."
3446 ;; Make it possible to undo the coming changes.
3448 (let ((inhibit-read-only t))
3449 (put-text-property (point-min) (point-max) 'read-only nil))
3450 (message-fix-before-sending)
3451 (run-hooks 'message-send-hook)
3452 (message message-sending-message)
3453 (let ((alist message-send-method-alist)
3455 elem sent dont-barf-on-no-method
3456 (message-options message-options))
3457 (message-options-set-recipient)
3459 (setq elem (pop alist)))
3460 (when (funcall (cadr elem))
3461 (when (and (or (not (memq (car elem)
3462 message-sent-message-via))
3463 (message-fetch-field "supersedes")
3464 (if (or (message-gnksa-enable-p 'multiple-copies)
3465 (not (eq (car elem) 'news)))
3468 "Already sent message via %s; resend? "
3470 (error "Denied posting -- multiple copies")))
3471 (setq success (funcall (caddr elem) arg)))
3475 (let ((fcc (message-fetch-field "Fcc"))
3476 (gcc (message-fetch-field "Gcc")))
3478 (or (eq message-allow-no-recipients 'always)
3479 (and (not (eq message-allow-no-recipients 'never))
3480 (setq dont-barf-on-no-method
3482 (format "No receiver, perform %s anyway? "
3483 (cond ((and fcc gcc) "Fcc and Gcc")
3486 (error "No methods specified to send by"))
3487 (when (or dont-barf-on-no-method
3491 (run-hooks 'message-sent-hook))
3492 (message "Sending...done")
3493 ;; Mark the buffer as unmodified and delete auto-save.
3494 (set-buffer-modified-p nil)
3495 (delete-auto-save-file-if-necessary t)
3496 (message-disassociate-draft)
3497 ;; Delete other mail buffers and stuff.
3498 (message-do-send-housekeeping)
3499 (message-do-actions message-send-actions)
3503 (defun message-send-via-mail (arg)
3504 "Send the current message via mail."
3505 (message-send-mail arg))
3507 (defun message-send-via-news (arg)
3508 "Send the current message via news."
3509 (funcall message-send-news-function arg))
3511 (defmacro message-check (type &rest forms)
3512 "Eval FORMS if TYPE is to be checked."
3513 `(or (message-check-element ,type)
3517 (put 'message-check 'lisp-indent-function 1)
3518 (put 'message-check 'edebug-form-spec '(form body))
3520 (defun message-text-with-property (prop)
3521 "Return a list of all points where the text has PROP."
3523 (point (point-min)))
3525 (while (< point (point-max))
3526 (when (get-text-property point prop)
3527 (push point points))
3531 (defun message-fix-before-sending ()
3532 "Do various things to make the message nice before sending it."
3533 ;; Make sure there's a newline at the end of the message.
3534 (goto-char (point-max))
3537 ;; Make the hidden headers visible.
3538 (let ((points (message-text-with-property 'message-hidden)))
3540 (goto-char (car points))
3541 (dolist (point points)
3542 (add-text-properties point (1+ point)
3543 '(invisible nil intangible nil)))))
3544 ;; Make invisible text visible.
3545 ;; It doesn't seem as if this is useful, since the invisible property
3546 ;; is clobbered by an after-change hook anyhow.
3547 (message-check 'invisible-text
3548 (let ((points (message-text-with-property 'invisible)))
3550 (goto-char (car points))
3551 (dolist (point points)
3552 (put-text-property point (1+ point) 'invisible nil)
3553 (message-overlay-put (message-make-overlay point (1+ point))
3555 (unless (yes-or-no-p
3556 "Invisible text found and made visible; continue sending? ")
3557 (error "Invisible text found and made visible")))))
3558 (message-check 'illegible-text
3561 (skip-chars-forward mm-7bit-chars)
3563 (when (let ((char (char-after)))
3564 (or (< (mm-char-int char) 128)
3565 (and (mm-multibyte-p)
3566 (memq (char-charset char)
3567 '(eight-bit-control eight-bit-graphic
3569 (not (get-text-property
3570 (point) 'untranslated-utf-8)))))
3571 (message-overlay-put (message-make-overlay (point) (1+ (point)))
3575 (skip-chars-forward mm-7bit-chars))
3578 (gnus-multiple-choice
3579 "Non-printable characters found. Continue sending?"
3580 '((?d "Remove non-printable characters and send")
3581 (?r "Replace non-printable characters with dots and send")
3582 (?i "Ignore non-printable characters and send")
3583 (?e "Continue editing"))))
3585 (error "Non-printable characters"))
3587 (skip-chars-forward mm-7bit-chars)
3589 (when (let ((char (char-after)))
3590 (or (< (mm-char-int char) 128)
3591 (and (mm-multibyte-p)
3592 ;; Fixme: Wrong for Emacs 22 and for things
3593 ;; like undecable utf-8. Should at least
3594 ;; use find-coding-systems-region.
3595 (memq (char-charset char)
3596 '(eight-bit-control eight-bit-graphic
3598 (not (get-text-property
3599 (point) 'untranslated-utf-8)))))
3601 (message-kill-all-overlays)
3603 (when (eq choice ?r)
3606 (skip-chars-forward mm-7bit-chars))))))
3608 (defun message-add-action (action &rest types)
3609 "Add ACTION to be performed when doing an exit of type TYPES."
3611 (add-to-list (intern (format "message-%s-actions" (pop types)))
3614 (defun message-delete-action (action &rest types)
3615 "Delete ACTION from lists of actions performed when doing an exit of type TYPES."
3618 (set (setq var (intern (format "message-%s-actions" (pop types))))
3619 (delq action (symbol-value var))))))
3621 (defun message-do-actions (actions)
3622 "Perform all actions in ACTIONS."
3623 ;; Now perform actions on successful sending.
3627 ;; A simple function.
3628 ((functionp (car actions))
3629 (funcall (car actions)))
3630 ;; Something to be evaled.
3632 (eval (car actions)))))
3635 (defun message-send-mail-partially ()
3636 "Send mail as message/partial."
3637 ;; replace the header delimiter with a blank line
3638 (goto-char (point-min))
3640 (concat "^" (regexp-quote mail-header-separator) "\n"))
3641 (replace-match "\n")
3642 (run-hooks 'message-send-mail-hook)
3643 (let ((p (goto-char (point-min)))
3644 (tembuf (message-generate-new-buffer-clone-locals " message temp"))
3645 (curbuf (current-buffer))
3646 (id (message-make-message-id)) (n 1)
3647 plist total header required-mail-headers)
3649 (if (< (point-max) (+ p message-send-mail-partially-limit))
3650 (goto-char (point-max))
3651 (goto-char (+ p message-send-mail-partially-limit))
3653 (if (<= (point) p) (forward-line 1))) ;; In case of bad message.
3656 (setq total (length plist))
3657 (push (point-max) plist)
3658 (setq plist (nreverse plist))
3661 (setq p (pop plist))
3664 (copy-to-buffer tembuf p (car plist))
3666 (goto-char (point-min))
3669 (goto-char (point-min))
3670 (narrow-to-region (point) (point))
3673 (setq header (buffer-substring (point-min) (point)))
3674 (goto-char (point-min))
3675 (narrow-to-region (point) (point))
3677 (message-remove-header "Mime-Version")
3678 (message-remove-header "Content-Type")
3679 (message-remove-header "Content-Transfer-Encoding")
3680 (message-remove-header "Message-ID")
3681 (message-remove-header "Lines")
3682 (goto-char (point-max))
3683 (insert "Mime-Version: 1.0\n")
3684 (setq header (buffer-string)))
3685 (goto-char (point-max))
3686 (insert (format "Content-Type: message/partial; id=\"%s\"; number=%d; total=%d\n\n"
3689 (let ((mail-header-separator ""))
3690 (when (memq 'Message-ID message-required-mail-headers)
3691 (insert "Message-ID: " (message-make-message-id) "\n"))
3692 (when (memq 'Lines message-required-mail-headers)
3693 (insert "Lines: " (message-make-lines) "\n"))
3694 (message-goto-subject)
3696 (insert (format " (%d/%d)" n total))
3698 (mm-with-unibyte-current-buffer
3699 (funcall (or message-send-mail-real-function
3700 message-send-mail-function))))
3702 (setq p (pop plist))
3704 (kill-buffer tembuf))))
3706 (defun message-send-mail (&optional arg)
3707 (require 'mail-utils)
3708 (let* ((tembuf (message-generate-new-buffer-clone-locals " message temp"))
3709 (case-fold-search nil)
3710 (news (message-news-p))
3711 (mailbuf (current-buffer))
3712 (message-this-is-mail t)
3713 (message-posting-charset
3714 (if (fboundp 'gnus-setup-posting-charset)
3715 (gnus-setup-posting-charset nil)
3716 message-posting-charset))
3717 (headers message-required-mail-headers))
3719 (message-narrow-to-headers)
3720 ;; Generate the Mail-Followup-To header if the header is not there...
3721 (if (and (message-subscribed-p)
3722 (not (mail-fetch-field "mail-followup-to")))
3725 (cons "Mail-Followup-To" (message-make-mail-followup-to))
3726 message-required-mail-headers))
3727 ;; otherwise, delete the MFT header if the field is empty
3728 (when (equal "" (mail-fetch-field "mail-followup-to"))
3729 (message-remove-header "^Mail-Followup-To:")))
3730 ;; Insert some headers.
3731 (let ((message-deletable-headers
3732 (if news nil message-deletable-headers)))
3733 (message-generate-headers headers))
3734 ;; Let the user do all of the above.
3735 (run-hooks 'message-header-hook))
3740 ;; Avoid copying text props (except hard newlines).
3741 (insert (with-current-buffer mailbuf
3742 (mml-buffer-substring-no-properties-except-hard-newlines
3743 (point-min) (point-max))))
3744 ;; Remove some headers.
3745 (message-encode-message-body)
3747 (message-narrow-to-headers)
3748 ;; We (re)generate the Lines header.
3749 (when (memq 'Lines message-required-mail-headers)
3750 (message-generate-headers '(Lines)))
3751 ;; Remove some headers.
3752 (message-remove-header message-ignored-mail-headers t)
3753 (let ((mail-parse-charset message-default-charset))
3754 (mail-encode-encoded-word-buffer)))
3755 (goto-char (point-max))
3756 ;; require one newline at the end.
3757 (or (= (preceding-char) ?\n)
3759 (message-cleanup-headers)
3760 ;; FIXME: we're inserting the courtesy copy after encoding.
3761 ;; This is wrong if the courtesy copy string contains
3762 ;; non-ASCII characters. -- jh
3765 (message-narrow-to-headers)
3767 (or (message-fetch-field "cc")
3768 (message-fetch-field "bcc")
3769 (message-fetch-field "to"))
3770 (let ((content-type (message-fetch-field
3775 (string= "text/plain"
3777 (mail-header-parse-content-type
3781 (message-fetch-field
3782 "content-transfer-encoding")))))))
3783 (message-insert-courtesy-copy))
3784 (if (or (not message-send-mail-partially-limit)
3785 (< (buffer-size) message-send-mail-partially-limit)
3786 (not (message-y-or-n-p
3787 "The message size is too large, split? "
3791 (/ (buffer-size) 1000) "KB, is too large.
3793 Some mail gateways (MTA's) bounce large messages. To avoid the
3794 problem, answer `y', and the message will be split into several
3795 smaller pieces, the size of each is about "
3796 (/ message-send-mail-partially-limit 1000)
3800 However, some mail readers (MUA's) can't read split messages, i.e.,
3801 mails in message/partially format. Answer `n', and the message will be
3804 The size limit is controlled by `message-send-mail-partially-limit'.
3805 If you always want Gnus to send messages in one piece, set
3806 `message-send-mail-partially-limit' to nil.
3808 (mm-with-unibyte-current-buffer
3809 (message "Sending via mail...")
3810 (funcall (or message-send-mail-real-function
3811 message-send-mail-function)))
3812 (message-send-mail-partially)))
3813 (kill-buffer tembuf))
3814 (set-buffer mailbuf)
3815 (push 'mail message-sent-message-via)))
3817 (defun message-send-mail-with-sendmail ()
3818 "Send off the prepared buffer with sendmail."
3819 (let ((errbuf (if message-interactive
3820 (message-generate-new-buffer-clone-locals
3823 resend-to-addresses delimline)
3826 (let ((case-fold-search t))
3828 (message-narrow-to-headers)
3829 (setq resend-to-addresses (message-fetch-field "resent-to")))
3830 ;; Change header-delimiter to be what sendmail expects.
3831 (goto-char (point-min))
3833 (concat "^" (regexp-quote mail-header-separator) "\n"))
3834 (replace-match "\n")
3836 (setq delimline (point-marker))
3837 (run-hooks 'message-send-mail-hook)
3838 ;; Insert an extra newline if we need it to work around
3839 ;; Sun's bug that swallows newlines.
3840 (goto-char (1+ delimline))
3841 (when (eval message-mailer-swallows-blank-line)
3843 (when message-interactive
3847 (let* ((default-directory "/")
3848 (coding-system-for-write message-send-coding-system)
3850 'call-process-region
3852 (list (point-min) (point-max)
3853 (if (boundp 'sendmail-program)
3855 "/usr/lib/sendmail")
3856 nil errbuf nil "-oi")
3857 ;; Always specify who from,
3858 ;; since some systems have broken sendmails.
3859 ;; But some systems are more broken with -f, so
3860 ;; we'll let users override this.
3861 (if (null message-sendmail-f-is-evil)
3862 (list "-f" (message-sendmail-envelope-from)))
3863 ;; These mean "report errors by mail"
3864 ;; and "deliver in background".
3865 (if (null message-interactive) '("-oem" "-odb"))
3866 ;; Get the addresses from the message
3867 ;; unless this is a resend.
3868 ;; We must not do that for a resend
3869 ;; because we would find the original addresses.
3870 ;; For a resend, include the specific addresses.
3871 (if resend-to-addresses
3872 (list resend-to-addresses)
3874 (unless (or (null cpr) (and (numberp cpr) (zerop cpr)))
3875 (error "Sending...failed with exit value %d" cpr)))
3876 (when message-interactive
3879 (goto-char (point-min))
3880 (while (re-search-forward "\n\n* *" nil t)
3881 (replace-match "; "))
3882 (if (not (zerop (buffer-size)))
3883 (error "Sending...failed to %s"
3884 (buffer-string))))))
3885 (when (bufferp errbuf)
3886 (kill-buffer errbuf)))))
3888 (defun message-send-mail-with-qmail ()
3889 "Pass the prepared message buffer to qmail-inject.
3890 Refer to the documentation for the variable `message-send-mail-function'
3891 to find out how to use this."
3892 ;; replace the header delimiter with a blank line
3893 (goto-char (point-min))
3895 (concat "^" (regexp-quote mail-header-separator) "\n"))
3896 (replace-match "\n")
3897 (run-hooks 'message-send-mail-hook)
3900 (let ((coding-system-for-write message-send-coding-system))
3902 'call-process-region (point-min) (point-max)
3903 message-qmail-inject-program nil nil nil
3904 ;; qmail-inject's default behaviour is to look for addresses on the
3905 ;; command line; if there're none, it scans the headers.
3906 ;; yes, it does The Right Thing w.r.t. Resent-To and it's kin.
3908 ;; in general, ALL of qmail-inject's defaults are perfect for simply
3909 ;; reading a formatted (i. e., at least a To: or Resent-To header)
3910 ;; message from stdin.
3912 ;; qmail also has the advantage of not having been raped by
3913 ;; various vendors, so we don't have to allow for that, either --
3914 ;; compare this with message-send-mail-with-sendmail and weep
3915 ;; for sendmail's lost innocence.
3917 ;; all this is way cool coz it lets us keep the arguments entirely
3918 ;; free for -inject-arguments -- a big win for the user and for us
3919 ;; since we don't have to play that double-guessing game and the user
3920 ;; gets full control (no gestapo'ish -f's, for instance). --sj
3921 (if (functionp message-qmail-inject-args)
3922 (funcall message-qmail-inject-args)
3923 message-qmail-inject-args)))
3924 ;; qmail-inject doesn't say anything on it's stdout/stderr,
3925 ;; we have to look at the retval instead
3927 (100 (error "qmail-inject reported permanent failure"))
3928 (111 (error "qmail-inject reported transient failure"))
3929 ;; should never happen
3930 (t (error "qmail-inject reported unknown failure"))))
3932 (defun message-send-mail-with-mh ()
3933 "Send the prepared message buffer with mh."
3934 (let ((mh-previous-window-config nil)
3935 (name (mh-new-draft-name)))
3936 (setq buffer-file-name name)
3937 ;; MH wants to generate these headers itself.
3938 (when message-mh-deletable-headers
3939 (let ((headers message-mh-deletable-headers))
3941 (goto-char (point-min))
3942 (and (re-search-forward
3943 (concat "^" (symbol-name (car headers)) ": *") nil t)
3944 (message-delete-line))
3946 (run-hooks 'message-send-mail-hook)
3947 ;; Pass it on to mh.
3950 (defun message-smtpmail-send-it ()
3951 "Send the prepared message buffer with `smtpmail-send-it'.
3952 This only differs from `smtpmail-send-it' that this command evaluates
3953 `message-send-mail-hook' just before sending a message. It is useful
3954 if your ISP requires the POP-before-SMTP authentication. See the Gnus
3955 manual for details."
3956 (run-hooks 'message-send-mail-hook)
3959 (defun message-canlock-generate ()
3960 "Return a string that is non-trivial to guess.
3961 Do not use this for anything important, it is cryptographically weak."
3963 (let (sha1-maximum-internal-length)
3964 (sha1 (concat (message-unique-id)
3965 (format "%x%x%x" (random) (random t) (random))
3966 (prin1-to-string (recent-keys))
3967 (prin1-to-string (garbage-collect))))))
3969 (defun message-canlock-password ()
3970 "The password used by message for cancel locks.
3971 This is the value of `canlock-password', if that option is non-nil.
3972 Otherwise, generate and save a value for `canlock-password' first."
3973 (unless canlock-password
3974 (customize-save-variable 'canlock-password (message-canlock-generate))
3975 (setq canlock-password-for-verify canlock-password))
3978 (defun message-insert-canlock ()
3979 (when message-insert-canlock
3980 (message-canlock-password)
3981 (canlock-insert-header)))
3983 (defun message-send-news (&optional arg)
3984 (let* ((tembuf (message-generate-new-buffer-clone-locals " *message temp*"))
3985 (case-fold-search nil)
3986 (method (if (functionp message-post-method)
3987 (funcall message-post-method arg)
3988 message-post-method))
3989 (newsgroups-field (save-restriction
3990 (message-narrow-to-headers-or-head)
3991 (message-fetch-field "Newsgroups")))
3992 (followup-field (save-restriction
3993 (message-narrow-to-headers-or-head)
3994 (message-fetch-field "Followup-To")))
3995 ;; BUG: We really need to get the charset for each name in the
3996 ;; Newsgroups and Followup-To lines to allow crossposting
3997 ;; between group namess with incompatible character sets.
3998 ;; -- Per Abrahamsen <abraham@dina.kvl.dk> 2001-10-08.
3999 (group-field-charset
4000 (gnus-group-name-charset method newsgroups-field))
4001 (followup-field-charset
4002 (gnus-group-name-charset method (or followup-field "")))
4003 (rfc2047-header-encoding-alist
4004 (append (when group-field-charset
4005 (list (cons "Newsgroups" group-field-charset)))
4006 (when followup-field-charset
4007 (list (cons "Followup-To" followup-field-charset)))
4008 rfc2047-header-encoding-alist))
4009 (messbuf (current-buffer))
4010 (message-syntax-checks
4012 (listp message-syntax-checks))
4013 (cons '(existing-newsgroups . disabled)
4014 message-syntax-checks)
4015 message-syntax-checks))
4016 (message-this-is-news t)
4017 (message-posting-charset
4018 (gnus-setup-posting-charset newsgroups-field))
4020 (if (not (message-check-news-body-syntax))
4023 (message-narrow-to-headers)
4024 ;; Insert some headers.
4025 (message-generate-headers message-required-news-headers)
4026 (message-insert-canlock)
4027 ;; Let the user do all of the above.
4028 (run-hooks 'message-header-hook))
4029 ;; Note: This check will be disabled by the ".*" default value for
4030 ;; gnus-group-name-charset-group-alist. -- Pa 2001-10-07.
4031 (when (and group-field-charset
4032 (listp message-syntax-checks))
4033 (setq message-syntax-checks
4034 (cons '(valid-newsgroups . disabled)
4035 message-syntax-checks)))
4036 (message-cleanup-headers)
4037 (if (not (let ((message-post-method method))
4038 (message-check-news-syntax)))
4043 (buffer-disable-undo)
4045 ;; Avoid copying text props (except hard newlines).
4047 (with-current-buffer messbuf
4048 (mml-buffer-substring-no-properties-except-hard-newlines
4049 (point-min) (point-max))))
4050 (message-encode-message-body)
4051 ;; Remove some headers.
4053 (message-narrow-to-headers)
4054 ;; We (re)generate the Lines header.
4055 (when (memq 'Lines message-required-mail-headers)
4056 (message-generate-headers '(Lines)))
4057 ;; Remove some headers.
4058 (message-remove-header message-ignored-news-headers t)
4059 (let ((mail-parse-charset message-default-charset))
4060 (mail-encode-encoded-word-buffer)))
4061 (goto-char (point-max))
4062 ;; require one newline at the end.
4063 (or (= (preceding-char) ?\n)
4065 (let ((case-fold-search t))
4066 ;; Remove the delimiter.
4067 (goto-char (point-min))
4069 (concat "^" (regexp-quote mail-header-separator) "\n"))
4070 (replace-match "\n")
4072 (run-hooks 'message-send-news-hook)
4073 (gnus-open-server method)
4074 (message "Sending news via %s..." (gnus-server-string method))
4075 (setq result (let ((mail-header-separator ""))
4076 (gnus-request-post method))))
4077 (kill-buffer tembuf))
4078 (set-buffer messbuf)
4080 (push 'news message-sent-message-via)
4081 (message "Couldn't send message via news: %s"
4082 (nnheader-get-report (car method)))
4086 ;;; Header generation & syntax checking.
4089 (defun message-check-element (type)
4090 "Return non-nil if this TYPE is not to be checked."
4091 (if (eq message-syntax-checks 'dont-check-for-anything-just-trust-me)
4093 (let ((able (assq type message-syntax-checks)))
4095 (eq (cdr able) 'disabled)))))
4097 (defun message-check-news-syntax ()
4098 "Check the syntax of the message."
4102 ;; We narrow to the headers and check them first.
4105 (message-narrow-to-headers)
4106 (message-check-news-header-syntax))))))
4108 (defun message-check-news-header-syntax ()
4110 ;; Check Newsgroups header.
4111 (message-check 'newsgroups
4112 (let ((group (message-fetch-field "newsgroups")))
4115 (not (string-match "\\`[ \t]*\\'" group)))
4118 "The newsgroups field is empty or missing. Posting is denied.")))))
4119 ;; Check the Subject header.
4120 (message-check 'subject
4121 (let* ((case-fold-search t)
4122 (subject (message-fetch-field "subject")))
4125 (not (string-match "\\`[ \t]*\\'" subject)))
4128 "The subject field is empty or missing. Posting is denied.")))))
4129 ;; Check for commands in Subject.
4130 (message-check 'subject-cmsg
4131 (if (string-match "^cmsg " (message-fetch-field "subject"))
4133 "The control code \"cmsg\" is in the subject. Really post? ")
4135 ;; Check long header lines.
4136 (message-check 'long-header-lines
4137 (let ((start (point))
4141 (while (and (not found)
4142 (re-search-forward "^\\([^ \t:]+\\): " nil t))
4143 (if (> (- (point) (match-beginning 0)) 998)
4145 length (- (point) (match-beginning 0)))
4146 (setq header (match-string-no-properties 1)))
4147 (setq start (match-beginning 0))
4150 (y-or-n-p (format "Your %s header is too long (%d). Really post? "
4153 ;; Check for multiple identical headers.
4154 (message-check 'multiple-headers
4156 (while (and (not found)
4157 (re-search-forward "^[^ \t:]+: " nil t))
4159 (or (re-search-forward
4164 (match-beginning 0) (- (match-end 0) 2))))
4169 (y-or-n-p (format "Multiple %s headers. Really post? " found))
4171 ;; Check for Version and Sendsys.
4172 (message-check 'sendsys
4173 (if (re-search-forward "^Sendsys:\\|^Version:" nil t)
4175 (format "The article contains a %s command. Really post? "
4176 (buffer-substring (match-beginning 0)
4177 (1- (match-end 0)))))
4179 ;; See whether we can shorten Followup-To.
4180 (message-check 'shorten-followup-to
4181 (let ((newsgroups (message-fetch-field "newsgroups"))
4182 (followup-to (message-fetch-field "followup-to"))
4184 (when (and newsgroups
4185 (string-match "," newsgroups)
4190 (setq to (completing-read
4191 "Followups to (default: no Followup-To header) "
4194 (message-tokenize-header
4196 (goto-char (point-min))
4197 (insert "Followup-To: " to "\n"))
4199 ;; Check "Shoot me".
4200 (message-check 'shoot
4201 (if (re-search-forward
4202 "Message-ID.*.i-did-not-set--mail-host-address--so-tickle-me" nil t)
4203 (y-or-n-p "You appear to have a misconfigured system. Really post? ")
4205 ;; Check for Approved.
4206 (message-check 'approved
4207 (if (re-search-forward "^Approved:" nil t)
4208 (y-or-n-p "The article contains an Approved header. Really post? ")
4210 ;; Check the Message-ID header.
4211 (message-check 'message-id
4212 (let* ((case-fold-search t)
4213 (message-id (message-fetch-field "message-id" t)))
4214 (or (not message-id)
4215 ;; Is there an @ in the ID?
4216 (and (string-match "@" message-id)
4217 ;; Is there a dot in the ID?
4218 (string-match "@[^.]*\\." message-id)
4219 ;; Does the ID end with a dot?
4220 (not (string-match "\\.>" message-id)))
4222 (format "The Message-ID looks strange: \"%s\". Really post? "
4224 ;; Check the Newsgroups & Followup-To headers.
4225 (message-check 'existing-newsgroups
4226 (let* ((case-fold-search t)
4227 (newsgroups (message-fetch-field "newsgroups"))
4228 (followup-to (message-fetch-field "followup-to"))
4229 (groups (message-tokenize-header
4231 (concat newsgroups "," followup-to)
4233 (post-method (if (functionp message-post-method)
4234 (funcall message-post-method)
4235 message-post-method))
4236 ;; KLUDGE to handle nnvirtual groups. Doing this right
4237 ;; would probably involve a new nnoo function.
4238 ;; -- Per Abrahamsen <abraham@dina.kvl.dk>, 2001-10-17.
4239 (method (if (and (consp post-method)
4240 (eq (car post-method) 'nnvirtual)
4241 gnus-message-group-art)
4242 (let ((group (car (nnvirtual-find-group-art
4243 (car gnus-message-group-art)
4244 (cdr gnus-message-group-art)))))
4245 (gnus-find-method-for-group group))
4249 (gnus-group-name-decode
4250 (gnus-group-real-name n)
4251 (gnus-group-name-charset method n)))
4252 (gnus-groups-from-server method)))
4255 (when (and (not (equal (car groups) "poster"))
4256 (not (member (car groups) known-groups))
4257 (not (member (car groups) errors)))
4258 (push (car groups) errors))
4261 ;; Gnus is not running.
4262 ((or (not (and (boundp 'gnus-active-hashtb)
4263 gnus-active-hashtb))
4264 (not (boundp 'gnus-read-active-file)))
4266 ;; We don't have all the group names.
4267 ((and (or (not gnus-read-active-file)
4268 (eq gnus-read-active-file 'some))
4272 "Really use %s possibly unknown group%s: %s? "
4273 (if (= (length errors) 1) "this" "these")
4274 (if (= (length errors) 1) "" "s")
4275 (mapconcat 'identity errors ", "))))
4276 ;; There were no errors.
4279 ;; There are unknown groups.
4283 "Really post to %s unknown group%s: %s? "
4284 (if (= (length errors) 1) "this" "these")
4285 (if (= (length errors) 1) "" "s")
4286 (mapconcat 'identity errors ", ")))))))
4287 ;; Check continuation headers.
4288 (message-check 'continuation-headers
4289 (goto-char (point-min))
4290 (let ((do-posting t))
4291 (while (re-search-forward "^[^ \t\n][^:\n]*$" nil t)
4292 (if (y-or-n-p "Fix continuation lines? ")
4294 (goto-char (match-beginning 0))
4296 (unless (y-or-n-p "Send anyway? ")
4297 (setq do-posting nil))))
4299 ;; Check the Newsgroups & Followup-To headers for syntax errors.
4300 (message-check 'valid-newsgroups
4301 (let ((case-fold-search t)
4302 (headers '("Newsgroups" "Followup-To"))
4304 (while (and headers (not error))
4305 (when (setq header (mail-fetch-field (car headers)))
4309 "\\`\\([-+_&.a-zA-Z0-9]+\\)?\\(,[-+_&.a-zA-Z0-9]+\\)*\\'"
4314 (not (string-match "\\.\\'\\|\\.\\." g)))
4315 (message-tokenize-header header ","))))
4322 (format "The %s header looks odd: \"%s\". Really post? "
4323 (car headers) header)))))
4324 (message-check 'repeated-newsgroups
4325 (let ((case-fold-search t)
4326 (headers '("Newsgroups" "Followup-To"))
4327 header error groups group)
4330 (when (setq header (mail-fetch-field (pop headers)))
4331 (setq groups (message-tokenize-header header ","))
4332 (while (setq group (pop groups))
4333 (when (member group groups)
4339 (format "Group %s is repeated in headers. Really post? " error)))))
4340 ;; Check the From header.
4341 (message-check 'from
4342 (let* ((case-fold-search t)
4343 (from (message-fetch-field "from"))
4347 (message "There is no From line. Posting is denied.")
4349 ((or (not (string-match
4351 (setq ad (nth 1 (mail-extract-address-components
4352 from))))) ;larsi@ifi
4353 (string-match "\\.\\." ad) ;larsi@ifi..uio
4354 (string-match "@\\." ad) ;larsi@.ifi.uio
4355 (string-match "\\.$" ad) ;larsi@ifi.uio.
4356 (not (string-match "^[^@]+@[^@]+$" ad)) ;larsi.ifi.uio
4357 (string-match "(.*).*(.*)" from)) ;(lars) (lars)
4359 "Denied posting -- the From looks strange: \"%s\"." from)
4361 ((let ((addresses (rfc822-addresses from)))
4362 (while (and addresses
4363 (not (eq (string-to-char (car addresses)) ?\()))
4364 (setq addresses (cdr addresses)))
4367 "Denied posting -- bad From address: \"%s\"." from)
4370 ;; Check the Reply-To header.
4371 (message-check 'reply-to
4372 (let* ((case-fold-search t)
4373 (reply-to (message-fetch-field "reply-to"))
4378 ((string-match "," reply-to)
4380 (format "Multiple Reply-To addresses: \"%s\". Really post? "
4382 ((or (not (string-match
4384 (setq ad (nth 1 (mail-extract-address-components
4385 reply-to))))) ;larsi@ifi
4386 (string-match "\\.\\." ad) ;larsi@ifi..uio
4387 (string-match "@\\." ad) ;larsi@.ifi.uio
4388 (string-match "\\.$" ad) ;larsi@ifi.uio.
4389 (not (string-match "^[^@]+@[^@]+$" ad)) ;larsi.ifi.uio
4390 (string-match "(.*).*(.*)" reply-to)) ;(lars) (lars)
4393 "The Reply-To looks strange: \"%s\". Really post? "
4397 (defun message-check-news-body-syntax ()
4399 ;; Check for long lines.
4400 (message-check 'long-lines
4401 (goto-char (point-min))
4403 (concat "^" (regexp-quote mail-header-separator) "$"))
4407 "<#\\(/\\)?\\(multipart\\|part\\|external\\|mml\\)")
4410 (< (- (point) p) 80)))
4411 (zerop (forward-line 1))))
4415 "You have lines longer than 79 characters. Really post? ")))
4416 ;; Check whether the article is empty.
4417 (message-check 'empty
4418 (goto-char (point-min))
4420 (concat "^" (regexp-quote mail-header-separator) "$"))
4423 (goto-char (point-max))
4424 (re-search-backward message-signature-separator nil t)
4426 (or (re-search-backward "[^ \n\t]" b t)
4427 (if (message-gnksa-enable-p 'empty-article)
4428 (y-or-n-p "Empty article. Really post? ")
4429 (message "Denied posting -- Empty article.")
4431 ;; Check for control characters.
4432 (message-check 'control-chars
4433 (if (re-search-forward
4434 (mm-string-as-multibyte "[\000-\007\013\015-\032\034-\037\200-\237]")
4437 "The article contains control characters. Really post? ")
4439 ;; Check excessive size.
4440 (message-check 'size
4441 (if (> (buffer-size) 60000)
4443 (format "The article is %d octets long. Really post? "
4446 ;; Check whether any new text has been added.
4447 (message-check 'new-text
4449 (not message-checksum)
4450 (not (eq (message-checksum) message-checksum))
4451 (if (message-gnksa-enable-p 'quoted-text-only)
4453 "It looks like no new text has been added. Really post? ")
4454 (message "Denied posting -- no new text has been added.")
4456 ;; Check the length of the signature.
4457 (message-check 'signature
4458 (goto-char (point-max))
4459 (if (> (count-lines (point) (point-max)) 5)
4462 "Your .sig is %d lines; it should be max 4. Really post? "
4463 (1- (count-lines (point) (point-max)))))
4465 ;; Ensure that text follows last quoted portion.
4466 (message-check 'quoting-style
4467 (goto-char (point-max))
4468 (let ((no-problem t))
4469 (when (search-backward-regexp "^>[^\n]*\n" nil t)
4470 (setq no-problem (search-forward-regexp "^[ \t]*[^>\n]" nil t)))
4473 (if (message-gnksa-enable-p 'quoted-text-only)
4474 (y-or-n-p "Your text should follow quoted text. Really post? ")
4476 (goto-char (point-min))
4478 (concat "^" (regexp-quote mail-header-separator) "$"))
4479 (if (search-forward-regexp "^[ \t]*[^>\n]" nil t)
4480 (y-or-n-p "Your text should follow quoted text. Really post? ")
4481 (message "Denied posting -- only quoted text.")
4484 (defun message-checksum ()
4485 "Return a \"checksum\" for the current buffer."
4488 (goto-char (point-min))
4490 (concat "^" (regexp-quote mail-header-separator) "$"))
4492 (when (not (looking-at "[ \t\n]"))
4493 (setq sum (logxor (ash sum 1) (if (natnump sum) 0 1)
4498 (defun message-do-fcc ()
4499 "Process Fcc headers in the current buffer."
4500 (let ((case-fold-search t)
4501 (buf (current-buffer))
4503 (mml-externalize-attachments message-fcc-externalize-attachments))
4506 (message-narrow-to-headers)
4507 (setq file (message-fetch-field "fcc" t)))
4509 (set-buffer (get-buffer-create " *message temp*"))
4511 (insert-buffer-substring buf)
4512 (message-encode-message-body)
4514 (message-narrow-to-headers)
4515 (while (setq file (message-fetch-field "fcc" t))
4517 (message-remove-header "fcc" nil t))
4518 (let ((mail-parse-charset message-default-charset)
4519 (rfc2047-header-encoding-alist
4520 (cons '("Newsgroups" . default)
4521 rfc2047-header-encoding-alist)))
4522 (mail-encode-encoded-word-buffer)))
4523 (goto-char (point-min))
4524 (when (re-search-forward
4525 (concat "^" (regexp-quote mail-header-separator) "$")
4527 (replace-match "" t t ))
4528 ;; Process FCC operations.
4530 (setq file (pop list))
4531 (if (string-match "^[ \t]*|[ \t]*\\(.*\\)[ \t]*$" file)
4532 ;; Pipe the article to the program in question.
4533 (call-process-region (point-min) (point-max) shell-file-name
4534 nil nil nil shell-command-switch
4535 (match-string 1 file))
4536 ;; Save the article.
4537 (setq file (expand-file-name file))
4538 (unless (file-exists-p (file-name-directory file))
4539 (make-directory (file-name-directory file) t))
4540 (if (and message-fcc-handler-function
4541 (not (eq message-fcc-handler-function 'rmail-output)))
4542 (funcall message-fcc-handler-function file)
4543 (if (and (file-readable-p file) (mail-file-babyl-p file))
4544 (rmail-output file 1 nil t)
4545 (let ((mail-use-rfc822 t))
4546 (rmail-output file 1 t t))))))
4547 (kill-buffer (current-buffer))))))
4549 (defun message-output (filename)
4550 "Append this article to Unix/babyl mail file FILENAME."
4551 (if (and (file-readable-p filename)
4552 (mail-file-babyl-p filename))
4553 (gnus-output-to-rmail filename t)
4554 (gnus-output-to-mail filename t)))
4556 (defun message-cleanup-headers ()
4557 "Do various automatic cleanups of the headers."
4558 ;; Remove empty lines in the header.
4560 (message-narrow-to-headers)
4561 ;; Remove blank lines.
4562 (while (re-search-forward "^[ \t]*\n" nil t)
4563 (replace-match "" t t))
4565 ;; Correct Newsgroups and Followup-To headers: Change sequence of
4566 ;; spaces to comma and eliminate spaces around commas. Eliminate
4567 ;; embedded line breaks.
4568 (goto-char (point-min))
4569 (while (re-search-forward "^\\(Newsgroups\\|Followup-To\\): +" nil t)
4573 (if (re-search-forward "^[^ \t]" nil t)
4577 (goto-char (point-min))
4578 (while (re-search-forward "\n[ \t]+" nil t)
4579 (replace-match " " t t)) ;No line breaks (too confusing)
4580 (goto-char (point-min))
4581 (while (re-search-forward "[ \t\n]*,[ \t\n]*\\|[ \t]+" nil t)
4582 (replace-match "," t t))
4583 (goto-char (point-min))
4584 ;; Remove trailing commas.
4585 (when (re-search-forward ",+$" nil t)
4586 (replace-match "" t t))))))
4588 (eval-when-compile (require 'parse-time))
4589 (defun message-make-date (&optional now)
4590 "Make a valid data header.
4591 If NOW, use that time instead."
4592 (require 'parse-time)
4593 (let* ((now (or now (current-time)))
4594 (zone (nth 8 (decode-time now)))
4598 (setq zone (- zone)))
4600 ;; The day name of the %a spec is locale-specific. Pfff.
4601 (format "%s, " (capitalize (car (rassoc (nth 6 (decode-time now))
4602 parse-time-weekdays))))
4603 (format-time-string "%d" now)
4604 ;; The month name of the %b spec is locale-specific. Pfff.
4606 (capitalize (car (rassoc (nth 4 (decode-time now))
4607 parse-time-months))))
4608 (format-time-string "%Y %H:%M:%S " now)
4609 ;; We do all of this because XEmacs doesn't have the %z spec.
4610 (format "%s%02d%02d" sign (/ zone 3600) (/ (% zone 3600) 60)))))
4612 (defun message-make-message-id ()
4613 "Make a unique Message-ID."
4614 (concat "<" (message-unique-id)
4615 (let ((psubject (save-excursion (message-fetch-field "subject")))
4617 (save-excursion (message-fetch-field "supersedes"))))
4619 (and message-reply-headers
4620 (mail-header-references message-reply-headers)
4621 (mail-header-subject message-reply-headers)
4624 (message-strip-subject-re
4625 (mail-header-subject message-reply-headers))
4626 (message-strip-subject-re psubject))))
4628 (string-match "_-_@" psupersedes)))
4630 "@" (message-make-fqdn) ">"))
4632 (defvar message-unique-id-char nil)
4634 ;; If you ever change this function, make sure the new version
4635 ;; cannot generate IDs that the old version could.
4636 ;; You might for example insert a "." somewhere (not next to another dot
4637 ;; or string boundary), or modify the "fsf" string.
4638 (defun message-unique-id ()
4639 ;; Don't use microseconds from (current-time), they may be unsupported.
4640 ;; Instead we use this randomly inited counter.
4641 (setq message-unique-id-char
4642 (% (1+ (or message-unique-id-char (logand (random t) (1- (lsh 1 20)))))
4643 ;; (current-time) returns 16-bit ints,
4644 ;; and 2^16*25 just fits into 4 digits i base 36.
4646 (let ((tm (current-time)))
4648 (if (memq system-type '(ms-dos emx vax-vms))
4649 (let ((user (downcase (user-login-name))))
4650 (while (string-match "[^a-z0-9_]" user)
4651 (aset user (match-beginning 0) ?_))
4653 (message-number-base36 (user-uid) -1))
4654 (message-number-base36 (+ (car tm)
4655 (lsh (% message-unique-id-char 25) 16)) 4)
4656 (message-number-base36 (+ (nth 1 tm)
4657 (lsh (/ message-unique-id-char 25) 16)) 4)
4658 ;; Append a given name, because while the generated ID is unique
4659 ;; to this newsreader, other newsreaders might otherwise generate
4660 ;; the same ID via another algorithm.
4663 (defun message-number-base36 (num len)
4668 (concat (message-number-base36 (/ num 36) (1- len))
4669 (char-to-string (aref "zyxwvutsrqponmlkjihgfedcba9876543210"
4672 (defun message-make-organization ()
4673 "Make an Organization header."
4674 (let* ((organization
4675 (when message-user-organization
4676 (if (functionp message-user-organization)
4677 (funcall message-user-organization)
4678 message-user-organization))))
4680 (mm-enable-multibyte)
4681 (cond ((stringp organization)
4682 (insert organization))
4683 ((and (eq t organization)
4684 message-user-organization-file
4685 (file-exists-p message-user-organization-file))
4686 (insert-file-contents message-user-organization-file)))
4687 (goto-char (point-min))
4688 (while (re-search-forward "[\t\n]+" nil t)
4689 (replace-match "" t t))
4690 (unless (zerop (buffer-size))
4693 (defun message-make-lines ()
4694 "Count the number of lines and return numeric string."
4699 (int-to-string (count-lines (point) (point-max))))))
4701 (defun message-make-references ()
4702 "Return the References header for this message."
4703 (when message-reply-headers
4704 (let ((message-id (mail-header-message-id message-reply-headers))
4705 (references (mail-header-references message-reply-headers))
4707 (if (or references message-id)
4708 (concat (or references "") (and references " ")
4712 (defun message-make-in-reply-to ()
4713 "Return the In-Reply-To header for this message."
4714 (when message-reply-headers
4715 (let ((from (mail-header-from message-reply-headers))
4716 (date (mail-header-date message-reply-headers))
4717 (msg-id (mail-header-message-id message-reply-headers)))
4719 (let ((name (mail-extract-address-components from)))
4720 (concat msg-id (if msg-id " (")
4724 (if (or (not date) (string= date ""))
4725 "(unknown date)" date)
4726 "\"" (if msg-id ")")))))))
4728 (defun message-make-distribution ()
4729 "Make a Distribution header."
4730 (let ((orig-distribution (message-fetch-reply-field "distribution")))
4731 (cond ((functionp message-distribution-function)
4732 (funcall message-distribution-function))
4733 (t orig-distribution))))
4735 (defun message-make-expires ()
4736 "Return an Expires header based on `message-expires'."
4737 (let ((current (current-time))
4738 (future (* 1.0 message-expires 60 60 24)))
4739 ;; Add the future to current.
4740 (setcar current (+ (car current) (round (/ future (expt 2 16)))))
4741 (setcar (cdr current) (+ (nth 1 current) (% (round future) (expt 2 16))))
4742 (message-make-date current)))
4744 (defun message-make-path ()
4746 (let ((login-name (user-login-name)))
4747 (cond ((null message-user-path)
4748 (concat (system-name) "!" login-name))
4749 ((stringp message-user-path)
4750 ;; Support GENERICPATH. Suggested by vixie@decwrl.dec.com.
4751 (concat message-user-path "!" login-name))
4754 (defun message-make-from ()
4755 "Make a From header."
4756 (let* ((style message-from-style)
4757 (login (message-make-address))
4759 (or (and (boundp 'user-full-name)
4762 (when (string= fullname "&")
4763 (setq fullname (user-login-name)))
4765 (mm-enable-multibyte)
4768 (equal fullname ""))
4770 ((or (eq style 'angles)
4771 (and (not (eq style 'parens))
4772 ;; Use angles if no quoting is needed, or if parens would
4773 ;; need quoting too.
4774 (or (not (string-match "[^- !#-'*+/-9=?A-Z^-~]" fullname))
4775 (let ((tmp (concat fullname nil)))
4776 (while (string-match "([^()]*)" tmp)
4777 (aset tmp (match-beginning 0) ?-)
4778 (aset tmp (1- (match-end 0)) ?-))
4779 (string-match "[\\()]" tmp)))))
4781 (goto-char (point-min))
4782 ;; Look for a character that cannot appear unquoted
4783 ;; according to RFC 822.
4784 (when (re-search-forward "[^- !#-'*+/-9=?A-Z^-~]" nil 1)
4785 ;; Quote fullname, escaping specials.
4786 (goto-char (point-min))
4788 (while (re-search-forward "[\"\\]" nil 1)
4789 (replace-match "\\\\\\&" t))
4791 (insert " <" login ">"))
4792 (t ; 'parens or default
4794 (let ((fullname-start (point)))
4796 (goto-char fullname-start)
4797 ;; RFC 822 says \ and nonmatching parentheses
4798 ;; must be escaped in comments.
4799 ;; Escape every instance of ()\ ...
4800 (while (re-search-forward "[()\\]" nil 1)
4801 (replace-match "\\\\\\&" t))
4802 ;; ... then undo escaping of matching parentheses,
4803 ;; including matching nested parentheses.
4804 (goto-char fullname-start)
4805 (while (re-search-forward
4806 "\\(\\=\\|[^\\]\\(\\\\\\\\\\)*\\)\\\\(\\(\\([^\\]\\|\\\\\\\\\\)*\\)\\\\)"
4808 (replace-match "\\1(\\3)" t)
4809 (goto-char fullname-start)))
4813 (defun message-make-sender ()
4814 "Return the \"real\" user address.
4815 This function tries to ignore all user modifications, and
4816 give as trustworthy answer as possible."
4817 (concat (user-login-name) "@" (system-name)))
4819 (defun message-make-address ()
4820 "Make the address of the user."
4821 (or (message-user-mail-address)
4822 (concat (user-login-name) "@" (message-make-domain))))
4824 (defun message-user-mail-address ()
4825 "Return the pertinent part of `user-mail-address'."
4826 (when (and user-mail-address
4827 (string-match "@.*\\." user-mail-address))
4828 (if (string-match " " user-mail-address)
4829 (nth 1 (mail-extract-address-components user-mail-address))
4830 user-mail-address)))
4832 (defun message-sendmail-envelope-from ()
4833 "Return the envelope from."
4834 (cond ((eq message-sendmail-envelope-from 'header)
4835 (nth 1 (mail-extract-address-components
4836 (message-fetch-field "from"))))
4837 ((stringp message-sendmail-envelope-from)
4838 message-sendmail-envelope-from)
4840 (message-make-address))))
4842 (defun message-make-fqdn ()
4843 "Return user's fully qualified domain name."
4844 (let* ((system-name (system-name))
4845 (user-mail (message-user-mail-address))
4848 (string-match "@\\(.*\\)\\'" user-mail))
4849 (match-string 1 user-mail)))
4850 (case-fold-search t))
4852 ((and message-user-fqdn
4853 (stringp message-user-fqdn)
4854 (string-match message-valid-fqdn-regexp message-user-fqdn)
4855 (not (string-match message-bogus-system-names message-user-fqdn)))
4857 ;; `message-user-fqdn' seems to be valid
4858 ((and (string-match message-valid-fqdn-regexp system-name)
4859 (not (string-match message-bogus-system-names system-name)))
4860 ;; `system-name' returned the right result.
4862 ;; Try `mail-host-address'.
4863 ((and (boundp 'mail-host-address)
4864 (stringp mail-host-address)
4865 (string-match message-valid-fqdn-regexp mail-host-address)
4866 (not (string-match message-bogus-system-names mail-host-address)))
4868 ;; We try `user-mail-address' as a backup.
4870 (stringp user-domain)
4871 (string-match message-valid-fqdn-regexp user-domain)
4872 (not (string-match message-bogus-system-names user-domain)))
4874 ;; Default to this bogus thing.
4877 ".i-did-not-set--mail-host-address--so-tickle-me")))))
4879 (defun message-make-host-name ()
4880 "Return the name of the host."
4881 (let ((fqdn (message-make-fqdn)))
4882 (string-match "^[^.]+\\." fqdn)
4883 (substring fqdn 0 (1- (match-end 0)))))
4885 (defun message-make-domain ()
4886 "Return the domain name."
4887 (or mail-host-address
4888 (message-make-fqdn)))
4890 (defun message-to-list-only ()
4891 "Send a message to the list only.
4892 Remove all addresses but the list address from To and Cc headers."
4894 (let ((listaddr (message-make-mail-followup-to t)))
4897 (message-remove-header "to")
4898 (message-remove-header "cc")
4899 (message-position-on-field "To" "X-Draft-From")
4900 (insert listaddr)))))
4902 (defun message-make-mail-followup-to (&optional only-show-subscribed)
4903 "Return the Mail-Followup-To header.
4904 If passed the optional argument ONLY-SHOW-SUBSCRIBED only return the
4905 subscribed address (and not the additional To and Cc header contents)."
4906 (let* ((case-fold-search t)
4907 (to (message-fetch-field "To"))
4908 (cc (message-fetch-field "cc"))
4909 (msg-recipients (concat to (and to cc ", ") cc))
4911 (mapcar 'mail-strip-quoted-names
4912 (message-tokenize-header msg-recipients)))
4914 (if message-subscribed-address-file
4915 (let (begin end item re)
4918 (insert-file-contents message-subscribed-address-file)
4920 (setq begin (point))
4923 (if (bolp) (setq end (1- end)))
4924 (setq item (regexp-quote (buffer-substring begin end)))
4925 (if re (setq re (concat re "\\|" item))
4926 (setq re (concat "\\`\\(" item))))
4927 (and re (list (concat re "\\)\\'"))))))))
4928 (mft-regexps (apply 'append message-subscribed-regexps
4929 (mapcar 'regexp-quote
4930 message-subscribed-addresses)
4933 message-subscribed-address-functions))))
4935 (let ((subscribed-lists nil)
4937 (loop for recipient in recipients
4938 when (loop for regexp in mft-regexps
4939 when (string-match regexp recipient) return t)
4942 (if only-show-subscribed
4944 msg-recipients))))))
4946 (defun message-idna-to-ascii-rhs-1 (header)
4947 "Interactively potentially IDNA encode domain names in HEADER."
4948 (let ((field (message-fetch-field header))
4951 (dolist (address (mail-header-parse-addresses field))
4952 (setq address (car address)
4953 rhs (downcase (or (cadr (split-string address "@")) ""))
4954 ace (downcase (idna-to-ascii rhs)))
4955 (when (and (not (equal rhs ace))
4956 (or (not (eq message-use-idna 'ask))
4957 (y-or-n-p (format "Replace %s with %s? " rhs ace))))
4958 (goto-char (point-min))
4959 (while (re-search-forward (concat "^" header ":") nil t)
4960 (message-narrow-to-field)
4961 (while (search-forward (concat "@" rhs) nil t)
4962 (replace-match (concat "@" ace) t t))
4963 (goto-char (point-max))
4966 (defun message-idna-to-ascii-rhs ()
4967 "Possibly IDNA encode non-ASCII domain names in From:, To: and Cc: headers.
4968 See `message-idna-encode'."
4970 (when message-use-idna
4973 (message-narrow-to-head)
4974 (message-idna-to-ascii-rhs-1 "From")
4975 (message-idna-to-ascii-rhs-1 "To")
4976 (message-idna-to-ascii-rhs-1 "Cc")))))
4978 (defun message-generate-headers (headers)
4979 "Prepare article HEADERS.
4980 Headers already prepared in the buffer are not modified."
4981 (setq headers (append headers message-required-headers))
4983 (message-narrow-to-headers)
4984 (let* ((Date (message-make-date))
4985 (Message-ID (message-make-message-id))
4986 (Organization (message-make-organization))
4987 (From (message-make-from))
4988 (Path (message-make-path))
4991 (In-Reply-To (message-make-in-reply-to))
4992 (References (message-make-references))
4994 (Distribution (message-make-distribution))
4995 (Lines (message-make-lines))
4996 (User-Agent message-newsreader)
4997 (Expires (message-make-expires))
4998 (case-fold-search t)
5000 header value elem header-string)
5001 ;; First we remove any old generated headers.
5002 (let ((headers message-deletable-headers))
5003 (unless (buffer-modified-p)
5004 (setq headers (delq 'Message-ID (copy-sequence headers))))
5006 (goto-char (point-min))
5007 (and (re-search-forward
5008 (concat "^" (symbol-name (car headers)) ": *") nil t)
5009 (get-text-property (1+ (match-beginning 0)) 'message-deletable)
5010 (message-delete-line))
5012 ;; Go through all the required headers and see if they are in the
5013 ;; articles already. If they are not, or are empty, they are
5014 ;; inserted automatically - except for Subject, Newsgroups and
5017 (goto-char (point-min))
5018 (setq elem (pop headers))
5020 (if (eq (car elem) 'optional)
5021 (setq header (cdr elem)
5023 (setq header (car elem)))
5025 (setq header-string (if (stringp header)
5027 (symbol-name header)))
5028 (when (or (not (re-search-forward
5030 (regexp-quote (downcase header-string))
5034 ;; The header was found. We insert a space after the
5035 ;; colon, if there is none.
5036 (if (/= (char-after) ? ) (insert " ") (forward-char 1))
5037 ;; Find out whether the header is empty.
5038 (looking-at "[ \t]*\n[^ \t]")))
5039 ;; So we find out what value we should insert.
5043 (eq (car elem) 'optional)
5044 (not (member header-string message-inserted-headers)))
5045 ;; This is an optional header. If the cdr of this
5046 ;; is something that is nil, then we do not insert
5048 (setq header (cdr elem))
5049 (or (and (functionp (cdr elem))
5050 (funcall (cdr elem)))
5051 (and (boundp (cdr elem))
5052 (symbol-value (cdr elem)))))
5054 ;; The element is a cons. Either the cdr is a
5055 ;; string to be inserted verbatim, or it is a
5056 ;; function, and we insert the value returned from
5058 (or (and (stringp (cdr elem))
5060 (and (functionp (cdr elem))
5061 (funcall (cdr elem)))))
5062 ((and (boundp header)
5063 (symbol-value header))
5064 ;; The element is a symbol. We insert the value
5065 ;; of this symbol, if any.
5066 (symbol-value header))
5067 ((not (message-check-element header))
5068 ;; We couldn't generate a value for this header,
5069 ;; so we just ask the user.
5070 (read-from-minibuffer
5071 (format "Empty header for %s; enter value: " header)))))
5072 ;; Finally insert the header.
5074 (not (equal value "")))
5078 ;; This header didn't exist, so we insert it.
5079 (goto-char (point-max))
5081 (cdr (assq header message-header-format-alist))))
5083 (funcall formatter header value)
5084 (insert header-string ": " value))
5085 ;; We check whether the value was ended by a
5086 ;; newline. If now, we insert one.
5090 ;; The value of this header was empty, so we clear
5091 ;; totally and insert the new value.
5092 (delete-region (point) (gnus-point-at-eol))
5093 ;; If the header is optional, and the header was
5094 ;; empty, we con't insert it anyway.
5096 (push header-string message-inserted-headers)
5098 ;; Add the deletable property to the headers that require it.
5099 (and (memq header message-deletable-headers)
5100 (progn (beginning-of-line) (looking-at "[^:]+: "))
5101 (add-text-properties
5102 (point) (match-end 0)
5103 '(message-deletable t face italic) (current-buffer)))))))
5104 ;; Insert new Sender if the From is strange.
5105 (let ((from (message-fetch-field "from"))
5106 (sender (message-fetch-field "sender"))
5107 (secure-sender (message-make-sender)))
5109 (not (message-check-element 'sender))
5112 (cadr (mail-extract-address-components from)))
5113 (downcase secure-sender)))
5118 (cadr (mail-extract-address-components sender)))
5119 (downcase secure-sender)))))
5120 (goto-char (point-min))
5121 ;; Rename any old Sender headers to Original-Sender.
5122 (when (re-search-forward "^\\(Original-\\)*Sender:" nil t)
5124 (insert "Original-")
5125 (beginning-of-line))
5126 (when (or (message-news-p)
5127 (string-match "@.+\\.." secure-sender))
5128 (insert "Sender: " secure-sender "\n"))))
5130 (message-idna-to-ascii-rhs))))
5132 (defun message-insert-courtesy-copy ()
5133 "Insert a courtesy message in mail copies of combined messages."
5137 (message-narrow-to-headers)
5138 (when (setq newsgroups (message-fetch-field "newsgroups"))
5139 (goto-char (point-max))
5140 (insert "Posted-To: " newsgroups "\n")))
5142 (when message-courtesy-message
5144 ((string-match "%s" message-courtesy-message)
5145 (insert (format message-courtesy-message newsgroups)))
5147 (insert message-courtesy-message)))))))
5150 ;;; Setting up a message buffer
5153 (defun message-fill-address (header value)
5155 (narrow-to-region (point) (point))
5156 (insert (capitalize (symbol-name header))
5158 (if (consp value) (car value) value)
5160 (narrow-to-region (point-min) (1- (point-max)))
5162 (goto-char (point-min))
5164 (skip-chars-forward "^,\"" (point-max))
5165 (if (or (eq (char-after) ?,)
5168 (if (and (> (current-column) 78)
5174 (setq last (1+ (point))))
5175 (setq last (1+ (point)))))
5176 (setq quoted (not quoted)))
5179 (goto-char (point-max))
5183 (defun message-split-line ()
5184 "Split current line, moving portion beyond point vertically down.
5185 If the current line has `message-yank-prefix', insert it on the new line."
5188 (split-line message-yank-prefix) ;; Emacs 22.1+ supports arg.
5192 (defun message-fill-header (header value)
5193 (let ((begin (point))
5196 (insert (capitalize (symbol-name header))
5198 (if (consp value) (car value) value)
5201 (narrow-to-region begin (point))
5202 (fill-region-as-paragraph begin (point))
5203 ;; Tapdance around looong Message-IDs.
5205 (when (looking-at "[ \t]*$")
5206 (message-delete-line))
5208 (re-search-forward ":" nil t)
5209 (when (looking-at "\n[ \t]+")
5210 (replace-match " " t t))
5211 (goto-char (point-max)))))
5213 (defun message-shorten-1 (list cut surplus)
5214 "Cut SURPLUS elements out of LIST, beginning with CUTth one."
5215 (setcdr (nthcdr (- cut 2) list)
5216 (nthcdr (+ (- cut 2) surplus 1) list)))
5218 (defun message-shorten-references (header references)
5219 "Trim REFERENCES to be 21 Message-ID long or less, and fold them.
5220 If folding is disallowed, also check that the REFERENCES are less
5221 than 988 characters long, and if they are not, trim them until they are."
5228 (goto-char (point-min))
5229 ;; Cons a list of valid references.
5230 (while (re-search-forward "<[^>]+>" nil t)
5231 (push (match-string 0) refs))
5232 (setq refs (nreverse refs)
5233 count (length refs)))
5235 ;; If the list has more than MAXCOUNT elements, trim it by
5236 ;; removing the CUTth element and the required number of
5237 ;; elements that follow.
5238 (when (> count maxcount)
5239 (let ((surplus (- count maxcount)))
5240 (message-shorten-1 refs cut surplus)
5241 (decf count surplus)))
5243 ;; If folding is disallowed, make sure the total length (including
5244 ;; the spaces between) will be less than MAXSIZE characters.
5246 ;; Only disallow folding for News messages. At this point the headers
5247 ;; have not been generated, thus we use message-this-is-news directly.
5248 (when (and message-this-is-news message-cater-to-broken-inn)
5250 (totalsize (+ (apply #'+ (mapcar #'length refs))
5253 (ptr (nthcdr (1- cut) refs)))
5254 ;; Decide how many elements to cut off...
5255 (while (> totalsize maxsize)
5256 (decf totalsize (1+ (length (car ptr))))
5258 (setq ptr (cdr ptr)))
5261 (message-shorten-1 refs cut surplus))))
5263 ;; Finally, collect the references back into a string and insert
5264 ;; it into the buffer.
5265 (let ((refstring (mapconcat #'identity refs " ")))
5266 (if (and message-this-is-news message-cater-to-broken-inn)
5267 (insert (capitalize (symbol-name header)) ": "
5269 (message-fill-header header refstring)))))
5271 (defun message-position-point ()
5272 "Move point to where the user probably wants to find it."
5273 (message-narrow-to-headers)
5275 ((re-search-forward "^[^:]+:[ \t]*$" nil t)
5276 (search-backward ":" )
5279 (if (eq (char-after) ? )
5283 (goto-char (point-max))
5286 (unless (looking-at "$")
5290 (defcustom message-beginning-of-line t
5291 "Whether \\<message-mode-map>\\[message-beginning-of-line]\
5292 goes to beginning of header values."
5294 :group 'message-buffers
5295 :link '(custom-manual "(message)Movement")
5298 (defun message-beginning-of-line (&optional n)
5299 "Move point to beginning of header value or to beginning of line.
5300 The prefix argument N is passed directly to `beginning-of-line'.
5302 This command is identical to `beginning-of-line' if point is
5303 outside the message header or if the option `message-beginning-of-line'
5306 If point is in the message header and on a (non-continued) header
5307 line, move point to the beginning of the header value or the beginning of line,
5308 whichever is closer. If point is already at beginning of line, move point to
5309 beginning of header value. Therefore, repeated calls will toggle point
5310 between beginning of field and beginning of line."
5312 (let ((zrs 'zmacs-region-stays))
5313 (when (and (interactive-p) (boundp zrs))
5315 (if (and message-beginning-of-line
5316 (message-point-in-header-p))
5317 (let* ((here (point))
5318 (bol (progn (beginning-of-line n) (point)))
5319 (eol (gnus-point-at-eol))
5320 (eoh (re-search-forward ": *" eol t)))
5322 (if (and eoh (or (< eoh here) (= bol here)))
5324 (beginning-of-line n)))
5326 (defun message-buffer-name (type &optional to group)
5327 "Return a new (unique) buffer name based on TYPE and TO."
5329 ;; Generate a new buffer name The Message Way.
5330 ((eq message-generate-new-buffers 'unique)
5331 (generate-new-buffer-name
5335 (or (car (mail-extract-address-components to))
5338 (if (and group (not (string= group ""))) (concat " on " group) "")
5340 ;; Check whether `message-generate-new-buffers' is a function,
5341 ;; and if so, call it.
5342 ((functionp message-generate-new-buffers)
5343 (funcall message-generate-new-buffers type to group))
5344 ((eq message-generate-new-buffers 'unsent)
5345 (generate-new-buffer-name
5346 (concat "*unsent " type
5349 (or (car (mail-extract-address-components to))
5352 (if (and group (not (string= group ""))) (concat " on " group) "")
5354 ;; Use standard name.
5356 (format "*%s message*" type))))
5358 (defun message-pop-to-buffer (name)
5359 "Pop to buffer NAME, and warn if it already exists and is modified."
5360 (let ((buffer (get-buffer name)))
5362 (buffer-name buffer))
5364 (set-buffer (pop-to-buffer buffer))
5365 (when (and (buffer-modified-p)
5367 "Message already being composed; erase? ")))
5368 (error "Message being composed")))
5369 (set-buffer (pop-to-buffer name)))
5373 (defun message-do-send-housekeeping ()
5374 "Kill old message buffers."
5375 ;; We might have sent this buffer already. Delete it from the
5377 (setq message-buffer-list (delq (current-buffer) message-buffer-list))
5378 (while (and message-max-buffers
5380 (>= (length message-buffer-list) message-max-buffers))
5381 ;; Kill the oldest buffer -- unless it has been changed.
5382 (let ((buffer (pop message-buffer-list)))
5383 (when (and (buffer-name buffer)
5384 (not (buffer-modified-p buffer)))
5385 (kill-buffer buffer))))
5386 ;; Rename the buffer.
5387 (if message-send-rename-function
5388 (funcall message-send-rename-function)
5389 ;; Note: mail-abbrevs of XEmacs renames buffer name behind Gnus.
5391 "\\`\\*\\(sent \\|unsent \\)?\\(.+\\)\\*[^\\*]*\\|\\`mail to "
5393 (let ((name (match-string 2 (buffer-name)))
5395 (if (not (or (null name)
5396 (string-equal name "mail")
5397 (string-equal name "posting")))
5398 (setq name (concat "*sent " name "*"))
5399 (message-narrow-to-headers)
5400 (setq to (message-fetch-field "to"))
5401 (setq group (message-fetch-field "newsgroups"))
5405 (to (concat "*sent mail to "
5406 (or (car (mail-extract-address-components to))
5408 ((and group (not (string= group "")))
5409 (concat "*sent posting on " group "*"))
5410 (t "*sent mail*"))))
5411 (unless (string-equal name (buffer-name))
5412 (rename-buffer name t)))))
5413 ;; Push the current buffer onto the list.
5414 (when message-max-buffers
5415 (setq message-buffer-list
5416 (nconc message-buffer-list (list (current-buffer))))))
5418 (defun message-mail-user-agent ()
5420 ((not message-mail-user-agent) nil)
5421 ((eq message-mail-user-agent t) mail-user-agent)
5422 (t message-mail-user-agent))))
5423 (if (memq mua '(message-user-agent gnus-user-agent))
5427 (defun message-setup (headers &optional replybuffer actions switch-function)
5428 (let ((mua (message-mail-user-agent))
5429 subject to field yank-action)
5430 (if (not (and message-this-is-mail mua))
5431 (message-setup-1 headers replybuffer actions)
5433 (setq yank-action (list 'insert-buffer replybuffer)))
5434 (setq headers (copy-sequence headers))
5435 (setq field (assq 'Subject headers))
5437 (setq subject (cdr field))
5438 (setq headers (delq field headers)))
5439 (setq field (assq 'To headers))
5441 (setq to (cdr field))
5442 (setq headers (delq field headers)))
5443 (let ((mail-user-agent mua))
5444 (compose-mail to subject
5445 (mapcar (lambda (item)
5447 (format "%s" (car item))
5450 nil switch-function yank-action actions)))))
5452 (defun message-headers-to-generate (headers included-headers excluded-headers)
5453 "Return a list that includes all headers from HEADERS.
5454 If INCLUDED-HEADERS is a list, just include those headers. If if is
5455 t, include all headers. In any case, headers from EXCLUDED-HEADERS
5459 (dolist (header headers)
5460 (setq header-name (cond
5461 ((and (consp header)
5462 (eq (car header) 'optional))
5463 ;; On the form (optional . Header)
5466 ;; On the form (Header . function)
5471 (when (and (not (memq header-name excluded-headers))
5472 (or (eq included-headers t)
5473 (memq header-name included-headers)))
5474 (push header result)))
5477 (defun message-setup-1 (headers &optional replybuffer actions)
5478 (dolist (action actions)
5480 (add-to-list 'message-send-actions
5481 `(apply ',(car action) ',(cdr action)))))
5482 (setq message-reply-buffer replybuffer)
5483 (goto-char (point-min))
5484 ;; Insert all the headers.
5487 (alist message-header-format-alist))
5489 (unless (assq (caar h) message-header-format-alist)
5490 (push (list (caar h)) alist))
5494 (delete-region (point) (progn (forward-line -1) (point)))
5495 (when message-default-headers
5496 (insert message-default-headers)
5497 (or (bolp) (insert ?\n)))
5501 (insert mail-header-separator "\n")
5505 (when (message-news-p)
5506 (when message-default-news-headers
5507 (insert message-default-news-headers)
5508 (or (bolp) (insert ?\n)))
5509 (when message-generate-headers-first
5510 (message-generate-headers
5511 (message-headers-to-generate
5512 (append message-required-news-headers
5513 message-required-headers)
5514 message-generate-headers-first
5515 '(Lines Subject)))))
5516 (when (message-mail-p)
5517 (when message-default-mail-headers
5518 (insert message-default-mail-headers)
5519 (or (bolp) (insert ?\n)))
5521 (message-narrow-to-headers)
5522 (if message-alternative-emails
5523 (message-use-alternative-email-as-from)))
5524 (when message-generate-headers-first
5525 (message-generate-headers
5526 (message-headers-to-generate
5527 (append message-required-mail-headers
5528 message-required-headers)
5529 message-generate-headers-first
5530 '(Lines Subject)))))
5531 (run-hooks 'message-signature-setup-hook)
5532 (message-insert-signature)
5534 (message-narrow-to-headers)
5535 (run-hooks 'message-header-setup-hook))
5536 (set-buffer-modified-p nil)
5537 (setq buffer-undo-list nil)
5538 (run-hooks 'message-setup-hook)
5539 (message-position-point)
5542 (defun message-set-auto-save-file-name ()
5543 "Associate the message buffer with a file in the drafts directory."
5544 (when message-auto-save-directory
5545 (unless (file-directory-p
5546 (directory-file-name message-auto-save-directory))
5547 (make-directory message-auto-save-directory t))
5549 (setq message-draft-article
5550 (nndraft-request-associate-buffer "drafts"))
5551 (setq buffer-file-name (expand-file-name
5552 (if (memq system-type
5553 '(ms-dos ms-windows windows-nt
5554 cygwin cygwin32 win32 w32
5558 message-auto-save-directory))
5559 (setq buffer-auto-save-file-name (make-auto-save-file-name)))
5560 (clear-visited-file-modtime)
5561 (setq buffer-file-coding-system message-draft-coding-system)))
5563 (defun message-disassociate-draft ()
5564 "Disassociate the message buffer from the drafts directory."
5565 (when message-draft-article
5566 (nndraft-request-expire-articles
5567 (list message-draft-article) "drafts" nil t)))
5569 (defun message-insert-headers ()
5570 "Generate the headers for the article."
5574 (message-narrow-to-headers)
5575 (when (message-news-p)
5576 (message-generate-headers
5579 (copy-sequence message-required-news-headers)))))
5580 (when (message-mail-p)
5581 (message-generate-headers
5584 (copy-sequence message-required-mail-headers))))))))
5589 ;;; Commands for interfacing with message
5593 (defun message-mail (&optional to subject
5594 other-headers continue switch-function
5595 yank-action send-actions)
5596 "Start editing a mail message to be sent.
5597 OTHER-HEADERS is an alist of header/value pairs."
5599 (let ((message-this-is-mail t) replybuffer)
5600 (unless (message-mail-user-agent)
5601 (message-pop-to-buffer (message-buffer-name "mail" to)))
5602 ;; FIXME: message-mail should do something if YANK-ACTION is not
5604 (and (consp yank-action) (eq (car yank-action) 'insert-buffer)
5605 (setq replybuffer (nth 1 yank-action)))
5608 `((To . ,(or to "")) (Subject . ,(or subject "")))
5609 (when other-headers other-headers))
5610 replybuffer send-actions)
5611 ;; FIXME: Should return nil if failure.
5615 (defun message-news (&optional newsgroups subject)
5616 "Start editing a news article to be sent."
5618 (let ((message-this-is-news t))
5619 (message-pop-to-buffer (message-buffer-name "posting" nil newsgroups))
5620 (message-setup `((Newsgroups . ,(or newsgroups ""))
5621 (Subject . ,(or subject ""))))))
5623 (defun message-get-reply-headers (wide &optional to-address address-headers)
5624 (let (follow-to mct never-mct to cc author mft recipients)
5625 ;; Find all relevant headers we need.
5627 (message-narrow-to-headers-or-head)
5628 ;; Gmane renames "To". Look at "Original-To", too, if it is present in
5629 ;; message-header-synonyms.
5630 (setq to (or (message-fetch-field "to")
5631 (and (loop for synonym in message-header-synonyms
5632 when (memq 'Original-To synonym)
5634 (message-fetch-field "original-to")))
5635 cc (message-fetch-field "cc")
5636 mct (message-fetch-field "mail-copies-to")
5637 author (or (message-fetch-field "mail-reply-to")
5638 (message-fetch-field "reply-to")
5639 (message-fetch-field "from")
5641 mft (and message-use-mail-followup-to
5642 (message-fetch-field "mail-followup-to"))))
5644 ;; Handle special values of Mail-Copies-To.
5646 (cond ((or (equal (downcase mct) "never")
5647 (equal (downcase mct) "nobody"))
5650 ((or (equal (downcase mct) "always")
5651 (equal (downcase mct) "poster"))
5652 (setq mct author))))
5655 ;; Build (textual) list of new recipient addresses.
5658 (setq recipients (concat ", " author)))
5660 (dolist (header address-headers)
5661 (let ((value (message-fetch-field header)))
5663 (setq recipients (concat recipients ", " value))))))
5665 (string-match "[^ \t,]" mft)
5666 (or (not (eq message-use-mail-followup-to 'ask))
5667 (message-y-or-n-p "Obey Mail-Followup-To? " t "\
5668 You should normally obey the Mail-Followup-To: header. In this
5669 article, it has the value of
5673 which directs your response to " (if (string-match "," mft)
5674 "the specified addresses"
5675 "that address only") ".
5677 Most commonly, Mail-Followup-To is used by a mailing list poster to
5678 express that responses should be sent to just the list, and not the
5681 If a message is posted to several mailing lists, Mail-Followup-To may
5682 also be used to direct the following discussion to one list only,
5683 because discussions that are spread over several lists tend to be
5684 fragmented and very difficult to follow.
5686 Also, some source/announcement lists are not intended for discussion;
5687 responses here are directed to other addresses.
5689 You may customize the variable `message-use-mail-followup-to', if you
5690 want to get rid of this query permanently.")))
5691 (setq recipients (concat ", " mft)))
5693 (setq recipients (concat ", " to-address))
5694 ;; If the author explicitly asked for a copy, we don't deny it to them.
5695 (if mct (setq recipients (concat recipients ", " mct))))
5697 (setq recipients (if never-mct "" (concat ", " author)))
5698 (if to (setq recipients (concat recipients ", " to)))
5699 (if cc (setq recipients (concat recipients ", " cc)))
5700 (if mct (setq recipients (concat recipients ", " mct)))))
5701 (if (>= (length recipients) 2)
5702 ;; Strip the leading ", ".
5703 (setq recipients (substring recipients 2)))
5704 ;; Squeeze whitespace.
5705 (while (string-match "[ \t][ \t]+" recipients)
5706 (setq recipients (replace-match " " t t recipients)))
5707 ;; Remove addresses that match `rmail-dont-reply-to-names'.
5708 (let ((rmail-dont-reply-to-names message-dont-reply-to-names))
5709 (setq recipients (rmail-dont-reply-to recipients)))
5710 ;; Perhaps "Mail-Copies-To: never" removed the only address?
5711 (if (string-equal recipients "")
5712 (setq recipients author))
5713 ;; Convert string to a list of (("foo@bar" . "Name <Foo@BAR>") ...).
5717 (cons (downcase (mail-strip-quoted-names addr)) addr))
5718 (message-tokenize-header recipients)))
5719 ;; Remove first duplicates. (Why not all duplicates? Is this a bug?)
5720 (let ((s recipients))
5722 (setq recipients (delq (assoc (car (pop s)) s) recipients))))
5724 ;; Remove hierarchical lists that are contained within each other,
5725 ;; if message-hierarchical-addresses is defined.
5726 (when message-hierarchical-addresses
5727 (let ((plain-addrs (mapcar 'car recipients))
5730 (setq subaddrs (assoc (car plain-addrs)
5731 message-hierarchical-addresses)
5732 plain-addrs (cdr plain-addrs))
5734 (setq subaddrs (cdr subaddrs))
5736 (setq recip (assoc (car subaddrs) recipients)
5737 subaddrs (cdr subaddrs))
5739 (setq recipients (delq recip recipients))))))))
5741 ;; Build the header alist. Allow the user to be asked whether
5742 ;; or not to reply to all recipients in a wide reply.
5743 (setq follow-to (list (cons 'To (cdr (pop recipients)))))
5744 (when (and recipients
5745 (or (not message-wide-reply-confirm-recipients)
5746 (y-or-n-p "Reply to all recipients? ")))
5747 (setq recipients (mapconcat
5748 (lambda (addr) (cdr addr)) recipients ", "))
5749 (if (string-match "^ +" recipients)
5750 (setq recipients (substring recipients (match-end 0))))
5751 (push (cons 'Cc recipients) follow-to)))
5755 (defun message-reply (&optional to-address wide)
5756 "Start editing a reply to the article in the current buffer."
5758 (require 'gnus-sum) ; for gnus-list-identifiers
5759 (let ((cur (current-buffer))
5760 from subject date reply-to to cc
5761 references message-id follow-to
5762 (inhibit-point-motion-hooks t)
5763 (message-this-is-mail t)
5766 (message-narrow-to-head-1)
5767 ;; Allow customizations to have their say.
5769 ;; This is a regular reply.
5770 (when (functionp message-reply-to-function)
5772 (setq follow-to (funcall message-reply-to-function))))
5773 ;; This is a followup.
5774 (when (functionp message-wide-reply-to-function)
5777 (funcall message-wide-reply-to-function)))))
5778 (setq message-id (message-fetch-field "message-id" t)
5779 references (message-fetch-field "references")
5780 date (message-fetch-field "date")
5781 from (message-fetch-field "from")
5782 subject (or (message-fetch-field "subject") "none"))
5783 (when gnus-list-identifiers
5784 (setq subject (message-strip-list-identifiers subject)))
5785 (setq subject (concat "Re: " (message-strip-subject-re subject)))
5786 (when message-subject-trailing-was-query
5787 (setq subject (message-strip-subject-trailing-was subject)))
5789 (when (and (setq gnus-warning (message-fetch-field "gnus-warning"))
5790 (string-match "<[^>]+>" gnus-warning))
5791 (setq message-id (match-string 0 gnus-warning)))
5794 (setq follow-to (message-get-reply-headers wide to-address))))
5796 (unless (message-mail-user-agent)
5797 (message-pop-to-buffer
5798 (message-buffer-name
5799 (if wide "wide reply" "reply") from
5800 (if wide to-address nil))))
5802 (setq message-reply-headers
5803 (vector 0 subject from date message-id references 0 0 ""))
5806 `((Subject . ,subject)
5811 (defun message-wide-reply (&optional to-address)
5812 "Make a \"wide\" reply to the message in the current buffer."
5814 (message-reply to-address t))
5817 (defun message-followup (&optional to-newsgroups)
5818 "Follow up to the message in the current buffer.
5819 If TO-NEWSGROUPS, use that as the new Newsgroups line."
5821 (require 'gnus-sum) ; for gnus-list-identifiers
5822 (let ((cur (current-buffer))
5823 from subject date reply-to mrt mct
5824 references message-id follow-to
5825 (inhibit-point-motion-hooks t)
5826 (message-this-is-news t)
5827 followup-to distribution newsgroups gnus-warning posted-to)
5830 (goto-char (point-min))
5831 (if (search-forward "\n\n" nil t)
5834 (when (functionp message-followup-to-function)
5836 (funcall message-followup-to-function)))
5837 (setq from (message-fetch-field "from")
5838 date (message-fetch-field "date")
5839 subject (or (message-fetch-field "subject") "none")
5840 references (message-fetch-field "references")
5841 message-id (message-fetch-field "message-id" t)
5842 followup-to (message-fetch-field "followup-to")
5843 newsgroups (message-fetch-field "newsgroups")
5844 posted-to (message-fetch-field "posted-to")
5845 reply-to (message-fetch-field "reply-to")
5846 mrt (message-fetch-field "mail-reply-to")
5847 distribution (message-fetch-field "distribution")
5848 mct (message-fetch-field "mail-copies-to"))
5849 (when (and (setq gnus-warning (message-fetch-field "gnus-warning"))
5850 (string-match "<[^>]+>" gnus-warning))
5851 (setq message-id (match-string 0 gnus-warning)))
5852 ;; Remove bogus distribution.
5853 (when (and (stringp distribution)
5854 (let ((case-fold-search t))
5855 (string-match "world" distribution)))
5856 (setq distribution nil))
5857 (if gnus-list-identifiers
5858 (setq subject (message-strip-list-identifiers subject)))
5859 (setq subject (concat "Re: " (message-strip-subject-re subject)))
5860 (when message-subject-trailing-was-query
5861 (setq subject (message-strip-subject-trailing-was subject)))
5864 (message-pop-to-buffer (message-buffer-name "followup" from newsgroups))
5866 (setq message-reply-headers
5867 (vector 0 subject from date message-id references 0 0 ""))
5870 `((Subject . ,subject)
5873 (list (cons 'Newsgroups to-newsgroups)))
5874 (follow-to follow-to)
5875 ((and followup-to message-use-followup-to)
5878 ((equal (downcase followup-to) "poster")
5879 (if (or (eq message-use-followup-to 'use)
5880 (message-y-or-n-p "Obey Followup-To: poster? " t "\
5881 You should normally obey the Followup-To: header.
5883 `Followup-To: poster' sends your response via e-mail instead of news.
5885 A typical situation where `Followup-To: poster' is used is when the poster
5886 does not read the newsgroup, so he wouldn't see any replies sent to it.
5888 You may customize the variable `message-use-followup-to', if you
5889 want to get rid of this query permanently."))
5891 (setq message-this-is-news nil)
5892 (cons 'To (or mrt reply-to from "")))
5893 (cons 'Newsgroups newsgroups)))
5895 (if (or (equal followup-to newsgroups)
5896 (not (eq message-use-followup-to 'ask))
5898 (concat "Obey Followup-To: " followup-to "? ") t "\
5899 You should normally obey the Followup-To: header.
5901 `Followup-To: " followup-to "'
5902 directs your response to " (if (string-match "," followup-to)
5903 "the specified newsgroups"
5904 "that newsgroup only") ".
5906 If a message is posted to several newsgroups, Followup-To is often
5907 used to direct the following discussion to one newsgroup only,
5908 because discussions that are spread over several newsgroup tend to
5909 be fragmented and very difficult to follow.
5911 Also, some source/announcement newsgroups are not intended for discussion;
5912 responses here are directed to other newsgroups.
5914 You may customize the variable `message-use-followup-to', if you
5915 want to get rid of this query permanently."))
5916 (cons 'Newsgroups followup-to)
5917 (cons 'Newsgroups newsgroups))))))
5919 `((Newsgroups . ,posted-to)))
5921 `((Newsgroups . ,newsgroups))))
5922 ,@(and distribution (list (cons 'Distribution distribution)))
5924 (not (or (equal (downcase mct) "never")
5925 (equal (downcase mct) "nobody"))))
5926 (list (cons 'Cc (if (or (equal (downcase mct) "always")
5927 (equal (downcase mct) "poster"))
5928 (or mrt reply-to from "")
5933 (defun message-is-yours-p ()
5934 "Non-nil means current article is yours.
5935 If you have added 'cancel-messages to `message-shoot-gnksa-feet', all articles
5936 are yours except those that have Cancel-Lock header not belonging to you.
5937 Instead of shooting GNKSA feet, you should modify `message-alternative-emails'
5938 regexp to match all of yours addresses."
5939 ;; Canlock-logic as suggested by Per Abrahamsen
5940 ;; <abraham@dina.kvl.dk>
5942 ;; IF article has cancel-lock THEN
5943 ;; IF we can verify it THEN
5946 ;; error: cancellock: article is not yours
5948 ;; Use old rules, comparing sender...
5951 (message-narrow-to-head-1)
5952 (if (message-fetch-field "Cancel-Lock")
5953 (if (null (canlock-verify))
5955 (error "Failed to verify Cancel-lock: This article is not yours"))
5958 (message-gnksa-enable-p 'cancel-messages)
5959 (and (setq sender (message-fetch-field "sender"))
5960 (string-equal (downcase sender)
5961 (downcase (message-make-sender))))
5962 ;; Email address in From field equals to our address
5963 (and (setq from (message-fetch-field "from"))
5965 (downcase (cadr (mail-extract-address-components from)))
5966 (downcase (cadr (mail-extract-address-components
5967 (message-make-from))))))
5968 ;; Email address in From field matches
5969 ;; 'message-alternative-emails' regexp
5971 message-alternative-emails
5973 message-alternative-emails
5974 (cadr (mail-extract-address-components from))))))))))
5977 (defun message-cancel-news (&optional arg)
5978 "Cancel an article you posted.
5979 If ARG, allow editing of the cancellation message."
5981 (unless (message-news-p)
5982 (error "This is not a news article; canceling is impossible"))
5983 (let (from newsgroups message-id distribution buf)
5985 ;; Get header info from original article.
5987 (message-narrow-to-head-1)
5988 (setq from (message-fetch-field "from")
5989 newsgroups (message-fetch-field "newsgroups")
5990 message-id (message-fetch-field "message-id" t)
5991 distribution (message-fetch-field "distribution")))
5992 ;; Make sure that this article was written by the user.
5993 (unless (message-is-yours-p)
5994 (error "This article is not yours"))
5995 (when (yes-or-no-p "Do you really want to cancel this article? ")
5996 ;; Make control message.
5999 (setq buf (set-buffer (get-buffer-create " *message cancel*"))))
6001 (insert "Newsgroups: " newsgroups "\n"
6003 "Subject: cmsg cancel " message-id "\n"
6004 "Control: cancel " message-id "\n"
6006 (concat "Distribution: " distribution "\n")
6008 mail-header-separator "\n"
6009 message-cancel-message)
6010 (run-hooks 'message-cancel-hook)
6012 (message "Canceling your article...")
6013 (if (let ((message-syntax-checks
6014 'dont-check-for-anything-just-trust-me))
6015 (funcall message-send-news-function))
6016 (message "Canceling your article...done"))
6017 (kill-buffer buf))))))
6020 (defun message-supersede ()
6021 "Start composing a message to supersede the current message.
6022 This is done simply by taking the old article and adding a Supersedes
6023 header line with the old Message-ID."
6025 (let ((cur (current-buffer)))
6026 ;; Check whether the user owns the article that is to be superseded.
6027 (unless (message-is-yours-p)
6028 (error "This article is not yours"))
6029 ;; Get a normal message buffer.
6030 (message-pop-to-buffer (message-buffer-name "supersede"))
6031 (insert-buffer-substring cur)
6033 (message-narrow-to-head-1)
6034 ;; Remove unwanted headers.
6035 (when message-ignored-supersedes-headers
6036 (message-remove-header message-ignored-supersedes-headers t))
6037 (goto-char (point-min))
6038 (if (not (re-search-forward "^Message-ID: " nil t))
6039 (error "No Message-ID in this article")
6040 (replace-match "Supersedes: " t t))
6041 (goto-char (point-max))
6042 (insert mail-header-separator)
6047 (defun message-recover ()
6048 "Reread contents of current buffer from its last auto-save file."
6050 (let ((file-name (make-auto-save-file-name)))
6051 (cond ((save-window-excursion
6052 (if (not (eq system-type 'vax-vms))
6053 (with-output-to-temp-buffer "*Directory*"
6054 (with-current-buffer standard-output
6055 (fundamental-mode)) ; for Emacs 20.4+
6056 (buffer-disable-undo standard-output)
6057 (let ((default-directory "/"))
6059 "ls" nil standard-output nil "-l" file-name))))
6060 (yes-or-no-p (format "Recover auto save file %s? " file-name)))
6061 (let ((buffer-read-only nil))
6063 (insert-file-contents file-name nil)))
6064 (t (error "message-recover cancelled")))))
6066 ;;; Washing Subject:
6068 (defun message-wash-subject (subject)
6069 "Remove junk like \"Re:\", \"(fwd)\", etc. added to subject string SUBJECT.
6070 Previous forwarders, replyers, etc. may add it."
6073 (goto-char (point-min))
6074 ;; strip Re/Fwd stuff off the beginning
6075 (while (re-search-forward
6076 "\\([Rr][Ee]:\\|[Ff][Ww][Dd]\\(\\[[0-9]*\\]\\)?:\\|[Ff][Ww]:\\)" nil t)
6079 ;; and gnus-style forwards [foo@bar.com] subject
6080 (goto-char (point-min))
6081 (while (re-search-forward "\\[[^ \t]*\\(@\\|\\.\\)[^ \t]*\\]" nil t)
6085 (goto-char (point-max))
6086 (while (re-search-backward "([Ff][Ww][Dd])" nil t)
6089 ;; and finally, any whitespace that was left-over
6090 (goto-char (point-min))
6091 (while (re-search-forward "^[ \t]+" nil t)
6093 (goto-char (point-max))
6094 (while (re-search-backward "[ \t]+$" nil t)
6099 ;;; Forwarding messages.
6101 (defvar message-forward-decoded-p nil
6102 "Non-nil means the original message is decoded.")
6104 (defun message-forward-subject-name-subject (subject)
6105 "Generate a SUBJECT for a forwarded message.
6106 The form is: [Source] Subject, where if the original message was mail,
6107 Source is the name of the sender, and if the original message was
6108 news, Source is the list of newsgroups is was posted to."
6109 (let* ((group (message-fetch-field "newsgroups"))
6110 (from (message-fetch-field "from"))
6113 (gnus-group-decoded-name group)
6114 (or (and from (car (gnus-extract-address-components from)))
6117 (if message-forward-decoded-p
6119 (mail-decode-encoded-word-string prefix))
6122 (defun message-forward-subject-author-subject (subject)
6123 "Generate a SUBJECT for a forwarded message.
6124 The form is: [Source] Subject, where if the original message was mail,
6125 Source is the sender, and if the original message was news, Source is
6126 the list of newsgroups is was posted to."
6127 (let* ((group (message-fetch-field "newsgroups"))
6130 (gnus-group-decoded-name group)
6131 (or (message-fetch-field "from")
6134 (if message-forward-decoded-p
6136 (mail-decode-encoded-word-string prefix))
6139 (defun message-forward-subject-fwd (subject)
6140 "Generate a SUBJECT for a forwarded message.
6141 The form is: Fwd: Subject, where Subject is the original subject of
6143 (if (string-match "^Fwd: " subject)
6145 (concat "Fwd: " subject)))
6147 (defun message-make-forward-subject ()
6148 "Return a Subject header suitable for the message in the current buffer."
6151 (message-narrow-to-head-1)
6152 (let ((funcs message-make-forward-subject-function)
6153 (subject (message-fetch-field "Subject")))
6156 (if message-forward-decoded-p
6158 (mail-decode-encoded-word-string subject))
6160 (if message-wash-forwarded-subjects
6161 (setq subject (message-wash-subject subject)))
6162 ;; Make sure funcs is a list.
6165 (setq funcs (list funcs)))
6166 ;; Apply funcs in order, passing subject generated by previous
6167 ;; func to the next one.
6169 (when (functionp (car funcs))
6170 (setq subject (funcall (car funcs) subject)))
6171 (setq funcs (cdr funcs)))
6175 (defvar gnus-article-decoded-p))
6179 (defun message-forward (&optional news digest)
6180 "Forward the current message via mail.
6181 Optional NEWS will use news to forward instead of mail.
6182 Optional DIGEST will use digest to forward."
6184 (let* ((cur (current-buffer))
6185 (message-forward-decoded-p
6186 (if (local-variable-p 'gnus-article-decoded-p (current-buffer))
6187 gnus-article-decoded-p ;; In an article buffer.
6188 message-forward-decoded-p))
6189 (subject (message-make-forward-subject)))
6191 (message-news nil subject)
6192 (message-mail nil subject))
6193 (message-forward-make-body cur digest)))
6195 (defun message-forward-make-body-plain (forward-buffer)
6197 "\n-------------------- Start of forwarded message --------------------\n")
6198 (let ((b (point)) e)
6201 (mm-disable-multibyte)
6203 (with-current-buffer forward-buffer
6204 (mm-with-unibyte-current-buffer (buffer-string))))
6205 (mm-enable-multibyte)
6207 (goto-char (point-min))
6208 (when (looking-at "From ")
6209 (replace-match "X-From-Line: "))
6213 "\n-------------------- End of forwarded message --------------------\n")
6214 (when message-forward-ignored-headers
6216 (narrow-to-region b e)
6218 (narrow-to-region (point)
6219 (or (search-forward "\n\n" nil t) (point)))
6220 (message-remove-header message-forward-ignored-headers t)))))
6222 (defun message-forward-make-body-mime (forward-buffer)
6223 (insert "\n\n<#part type=message/rfc822 disposition=inline raw=t>\n")
6224 (let ((b (point)) e)
6226 (narrow-to-region (point) (point))
6227 (mml-insert-buffer forward-buffer)
6228 (goto-char (point-min))
6229 (when (looking-at "From ")
6230 (replace-match "X-From-Line: "))
6231 (goto-char (point-max)))
6233 (insert "<#/part>\n")))
6235 (defun message-forward-make-body-mml (forward-buffer)
6236 (insert "\n\n<#mml type=message/rfc822 disposition=inline>\n")
6237 (let ((b (point)) e)
6238 (if (not message-forward-decoded-p)
6241 (mm-disable-multibyte)
6243 (with-current-buffer forward-buffer
6244 (mm-with-unibyte-current-buffer (buffer-string))))
6245 (mm-enable-multibyte)
6247 (goto-char (point-min))
6248 (when (looking-at "From ")
6249 (replace-match "X-From-Line: "))
6252 (narrow-to-region (point) (point))
6253 (mml-insert-buffer forward-buffer)
6254 (goto-char (point-min))
6255 (when (looking-at "From ")
6256 (replace-match "X-From-Line: "))
6257 (goto-char (point-max))))
6259 (insert "<#/mml>\n")
6260 (when (and (not message-forward-decoded-p)
6261 message-forward-ignored-headers)
6263 (narrow-to-region b e)
6265 (narrow-to-region (point)
6266 (or (search-forward "\n\n" nil t) (point)))
6267 (message-remove-header message-forward-ignored-headers t)))))
6269 (defun message-forward-make-body-digest-plain (forward-buffer)
6271 "\n-------------------- Start of forwarded message --------------------\n")
6272 (let ((b (point)) e)
6273 (mml-insert-buffer forward-buffer)
6276 "\n-------------------- End of forwarded message --------------------\n")))
6278 (defun message-forward-make-body-digest-mime (forward-buffer)
6279 (insert "\n<#multipart type=digest>\n")
6280 (let ((b (point)) e)
6281 (insert-buffer-substring forward-buffer)
6283 (insert "<#/multipart>\n")
6285 (narrow-to-region b e)
6287 (narrow-to-region (point)
6288 (or (search-forward "\n\n" nil t) (point)))
6289 (delete-region (point-min) (point-max)))))
6291 (defun message-forward-make-body-digest (forward-buffer)
6292 (if message-forward-as-mime
6293 (message-forward-make-body-digest-mime forward-buffer)
6294 (message-forward-make-body-digest-plain forward-buffer)))
6297 (defun message-forward-make-body (forward-buffer &optional digest)
6298 ;; Put point where we want it before inserting the forwarded
6300 (if message-forward-before-signature
6302 (goto-char (point-max)))
6304 (message-forward-make-body-digest forward-buffer)
6305 (if message-forward-as-mime
6306 (if (and message-forward-show-mml
6307 (not (and (eq message-forward-show-mml 'best)
6308 (with-current-buffer forward-buffer
6309 (goto-char (point-min))
6311 "Content-Type: *multipart/\\(signed\\|encrypted\\)"
6313 (message-forward-make-body-mml forward-buffer)
6314 (message-forward-make-body-mime forward-buffer))
6315 (message-forward-make-body-plain forward-buffer)))
6316 (message-position-point))
6319 (defun message-forward-rmail-make-body (forward-buffer)
6320 (save-window-excursion
6321 (set-buffer forward-buffer)
6322 ;; Rmail doesn't have rmail-msg-restore-non-pruned-header in Emacs
6323 ;; 20. FIXIT, or we drop support for rmail in Emacs 20.
6324 (if (rmail-msg-is-pruned)
6325 (rmail-msg-restore-non-pruned-header)))
6326 (message-forward-make-body forward-buffer))
6328 (eval-when-compile (defvar rmail-enable-mime-composing))
6330 ;; Fixme: Should have defcustom.
6332 (defun message-insinuate-rmail ()
6333 "Let RMAIL use message to forward."
6335 (setq rmail-enable-mime-composing t)
6336 (setq rmail-insert-mime-forwarded-message-function
6337 'message-forward-rmail-make-body))
6340 (defun message-resend (address)
6341 "Resend the current article to ADDRESS."
6343 (list (message-read-from-minibuffer "Resend message to: ")))
6344 (message "Resending message to %s..." address)
6346 (let ((cur (current-buffer))
6348 ;; We first set up a normal mail buffer.
6349 (unless (message-mail-user-agent)
6350 (set-buffer (get-buffer-create " *message resend*"))
6352 (let ((message-this-is-mail t)
6354 (message-setup `((To . ,address))))
6355 ;; Insert our usual headers.
6356 (message-generate-headers '(From Date To Message-ID))
6357 (message-narrow-to-headers)
6358 ;; Remove X-Draft-From header etc.
6359 (message-remove-header message-ignored-mail-headers t)
6360 ;; Rename them all to "Resent-*".
6361 (goto-char (point-min))
6362 (while (re-search-forward "^[A-Za-z]" nil t)
6367 (delete-region (point) (point-max))
6369 ;; Insert the message to be resent.
6370 (insert-buffer-substring cur)
6371 (goto-char (point-min))
6372 (search-forward "\n\n")
6375 (narrow-to-region beg (point))
6376 (message-remove-header message-ignored-resent-headers t)
6377 (goto-char (point-max)))
6378 (insert mail-header-separator)
6379 ;; Rename all old ("Also-")Resent headers.
6380 (while (re-search-backward "^\\(Also-\\)*Resent-" beg t)
6383 ;; Quote any "From " lines at the beginning.
6385 (when (looking-at "From ")
6386 (replace-match "X-From-Line: "))
6388 (let ((message-inhibit-body-encoding t)
6389 message-required-mail-headers
6390 rfc2047-encode-encoded-words)
6391 (message-send-mail))
6392 (kill-buffer (current-buffer)))
6393 (message "Resending message to %s...done" address)))
6396 (defun message-bounce ()
6397 "Re-mail the current message.
6398 This only makes sense if the current message is a bounce message that
6399 contains some mail you have written which has been bounced back to
6402 (let ((handles (mm-dissect-buffer t))
6404 (message-pop-to-buffer (message-buffer-name "bounce"))
6405 (if (stringp (car handles))
6406 ;; This is a MIME bounce.
6407 (mm-insert-part (car (last handles)))
6408 ;; This is a non-MIME bounce, so we try to remove things
6410 (mm-insert-part handles)
6412 (goto-char (point-min))
6413 (re-search-forward "\n\n+" nil t)
6414 (setq boundary (point))
6415 ;; We remove everything before the bounced mail.
6416 (if (or (re-search-forward message-unsent-separator nil t)
6418 (search-forward "\n\n" nil 'move)
6419 (re-search-backward "^Return-Path:.*\n" boundary t)))
6422 (delete-region (point-min)
6423 (if (re-search-forward "^[^ \n\t]+:" nil t)
6426 (goto-char boundary)
6427 (when (re-search-backward "^.?From .*\n" nil t)
6428 (delete-region (match-beginning 0) (match-end 0)))))
6429 (mm-enable-multibyte)
6431 (message-narrow-to-head-1)
6432 (message-remove-header message-ignored-bounced-headers t)
6433 (goto-char (point-max))
6434 (insert mail-header-separator))
6435 (message-position-point)))
6438 ;;; Interactive entry points for new message buffers.
6442 (defun message-mail-other-window (&optional to subject)
6443 "Like `message-mail' command, but display mail buffer in another window."
6445 (unless (message-mail-user-agent)
6446 (let ((pop-up-windows t)
6447 (special-display-buffer-names nil)
6448 (special-display-regexps nil)
6449 (same-window-buffer-names nil)
6450 (same-window-regexps nil))
6451 (message-pop-to-buffer (message-buffer-name "mail" to))))
6452 (let ((message-this-is-mail t))
6453 (message-setup `((To . ,(or to "")) (Subject . ,(or subject "")))
6454 nil nil 'switch-to-buffer-other-window)))
6457 (defun message-mail-other-frame (&optional to subject)
6458 "Like `message-mail' command, but display mail buffer in another frame."
6460 (unless (message-mail-user-agent)
6461 (let ((pop-up-frames t)
6462 (special-display-buffer-names nil)
6463 (special-display-regexps nil)
6464 (same-window-buffer-names nil)
6465 (same-window-regexps nil))
6466 (message-pop-to-buffer (message-buffer-name "mail" to))))
6467 (let ((message-this-is-mail t))
6468 (message-setup `((To . ,(or to "")) (Subject . ,(or subject "")))
6469 nil nil 'switch-to-buffer-other-frame)))
6472 (defun message-news-other-window (&optional newsgroups subject)
6473 "Start editing a news article to be sent."
6475 (let ((pop-up-windows t)
6476 (special-display-buffer-names nil)
6477 (special-display-regexps nil)
6478 (same-window-buffer-names nil)
6479 (same-window-regexps nil))
6480 (message-pop-to-buffer (message-buffer-name "posting" nil newsgroups)))
6481 (let ((message-this-is-news t))
6482 (message-setup `((Newsgroups . ,(or newsgroups ""))
6483 (Subject . ,(or subject ""))))))
6486 (defun message-news-other-frame (&optional newsgroups subject)
6487 "Start editing a news article to be sent."
6489 (let ((pop-up-frames t)
6490 (special-display-buffer-names nil)
6491 (special-display-regexps nil)
6492 (same-window-buffer-names nil)
6493 (same-window-regexps nil))
6494 (message-pop-to-buffer (message-buffer-name "posting" nil newsgroups)))
6495 (let ((message-this-is-news t))
6496 (message-setup `((Newsgroups . ,(or newsgroups ""))
6497 (Subject . ,(or subject ""))))))
6501 ;; This code should be moved to underline.el (from which it is stolen).
6504 (defun bold-region (start end)
6505 "Bold all nonblank characters in the region.
6506 Works by overstriking characters.
6507 Called from program, takes two arguments START and END
6508 which specify the range to operate on."
6511 (let ((end1 (make-marker)))
6512 (move-marker end1 (max start end))
6513 (goto-char (min start end))
6514 (while (< (point) end1)
6515 (or (looking-at "[_\^@- ]")
6516 (insert (char-after) "\b"))
6517 (forward-char 1)))))
6520 (defun unbold-region (start end)
6521 "Remove all boldness (overstruck characters) in the region.
6522 Called from program, takes two arguments START and END
6523 which specify the range to operate on."
6526 (let ((end1 (make-marker)))
6527 (move-marker end1 (max start end))
6528 (goto-char (min start end))
6529 (while (re-search-forward "\b" end1 t)
6530 (if (eq (char-after) (char-after (- (point) 2)))
6531 (delete-char -2))))))
6533 (defun message-exchange-point-and-mark ()
6534 "Exchange point and mark, but don't activate region if it was inactive."
6536 (message-mark-active-p)
6537 (exchange-point-and-mark))
6538 (setq mark-active nil)))
6540 (defalias 'message-make-overlay 'make-overlay)
6541 (defalias 'message-delete-overlay 'delete-overlay)
6542 (defalias 'message-overlay-put 'overlay-put)
6543 (defun message-kill-all-overlays ()
6544 (if (featurep 'xemacs)
6545 (map-extents (lambda (extent ignore) (delete-extent extent)))
6546 (mapcar #'delete-overlay (overlays-in (point-min) (point-max)))))
6548 ;; Support for toolbar
6550 (defvar tool-bar-map)
6551 (defvar tool-bar-mode))
6553 (defun message-tool-bar-local-item-from-menu (command icon in-map &optional from-map &rest props)
6554 ;; We need to make tool bar entries in local keymaps with
6555 ;; `tool-bar-local-item-from-menu' in Emacs > 21.3
6556 (if (fboundp 'tool-bar-local-item-from-menu)
6557 ;; This is for Emacs 21.3
6558 (tool-bar-local-item-from-menu command icon in-map from-map props)
6559 (tool-bar-add-item-from-menu command icon from-map props)))
6561 (defun message-tool-bar-map ()
6562 (or message-tool-bar-map
6563 (setq message-tool-bar-map
6565 (condition-case nil (require 'tool-bar) (error nil))
6566 (fboundp 'tool-bar-add-item-from-menu)
6568 (let ((tool-bar-map (copy-keymap tool-bar-map))
6569 (load-path (mm-image-load-path)))
6570 ;; Zap some items which aren't so relevant and take
6572 (dolist (key '(print-buffer kill-buffer save-buffer
6573 write-file dired open-file))
6574 (define-key tool-bar-map (vector key) nil))
6575 (message-tool-bar-local-item-from-menu
6576 'message-send-and-exit "mail_send" tool-bar-map message-mode-map)
6577 (message-tool-bar-local-item-from-menu
6578 'message-kill-buffer "close" tool-bar-map message-mode-map)
6579 (message-tool-bar-local-item-from-menu
6580 'message-dont-send "cancel" tool-bar-map message-mode-map)
6581 (message-tool-bar-local-item-from-menu
6582 'mml-attach-file "attach" tool-bar-map mml-mode-map)
6583 (message-tool-bar-local-item-from-menu
6584 'ispell-message "spell" tool-bar-map message-mode-map)
6585 (message-tool-bar-local-item-from-menu
6586 'mml-preview "preview"
6587 tool-bar-map mml-mode-map)
6588 (message-tool-bar-local-item-from-menu
6589 'message-insert-importance-high "important"
6590 tool-bar-map message-mode-map)
6591 (message-tool-bar-local-item-from-menu
6592 'message-insert-importance-low "unimportant"
6593 tool-bar-map message-mode-map)
6594 (message-tool-bar-local-item-from-menu
6595 'message-insert-disposition-notification-to "receipt"
6596 tool-bar-map message-mode-map)
6599 ;;; Group name completion.
6601 (defcustom message-newgroups-header-regexp
6602 "^\\(Newsgroups\\|Followup-To\\|Posted-To\\|Gcc\\):"
6603 "Regexp that match headers that lists groups."
6607 (defcustom message-completion-alist
6608 (list (cons message-newgroups-header-regexp 'message-expand-group)
6609 '("^\\(Resent-\\)?\\(To\\|B?Cc\\):" . message-expand-name)
6610 '("^\\(Reply-To\\|From\\|Mail-Followup-To\\|Mail-Copies-To\\):"
6611 . message-expand-name)
6612 '("^\\(Disposition-Notification-To\\|Return-Receipt-To\\):"
6613 . message-expand-name))
6614 "Alist of (RE . FUN). Use FUN for completion on header lines matching RE."
6617 :type '(alist :key-type regexp :value-type function))
6619 (defcustom message-tab-body-function nil
6620 "*Function to execute when `message-tab' (TAB) is executed in the body.
6621 If nil, the function bound in `text-mode-map' or `global-map' is executed."
6624 :link '(custom-manual "(message)Various Commands")
6627 (defun message-tab ()
6628 "Complete names according to `message-completion-alist'.
6629 Execute function specified by `message-tab-body-function' when not in
6632 (let ((alist message-completion-alist))
6634 (let ((mail-abbrev-mode-regexp (caar alist)))
6635 (not (mail-abbrev-in-expansion-header-p))))
6636 (setq alist (cdr alist)))
6637 (funcall (or (cdar alist) message-tab-body-function
6638 (lookup-key text-mode-map "\t")
6639 (lookup-key global-map "\t")
6640 'indent-relative))))
6642 (defun message-expand-group ()
6643 "Expand the group name under point."
6644 (let* ((b (save-excursion
6649 (skip-chars-forward "^:")
6652 (skip-chars-backward "^, \t\n") (point))))
6653 (completion-ignore-case t)
6654 (string (buffer-substring b (progn (skip-chars-forward "^,\t\n ")
6656 (hashtb (and (boundp 'gnus-active-hashtb) gnus-active-hashtb))
6657 (completions (all-completions string hashtb))
6659 (delete-region b (point))
6661 ((= (length completions) 1)
6662 (if (string= (car completions) string)
6665 (message "Only matching group"))
6666 (insert (car completions))))
6667 ((and (setq comp (try-completion string hashtb))
6668 (not (string= comp string)))
6673 (message "No matching groups")
6674 (save-selected-window
6675 (pop-to-buffer "*Completions*")
6676 (buffer-disable-undo)
6677 (let ((buffer-read-only nil))
6679 (let ((standard-output (current-buffer)))
6680 (display-completion-list (sort completions 'string<)))
6681 (goto-char (point-min))
6682 (delete-region (point) (progn (forward-line 3) (point))))))))))
6684 (defun message-expand-name ()
6685 (if (fboundp 'bbdb-complete-name)
6686 (bbdb-complete-name)
6691 (defun message-talkative-question (ask question show &rest text)
6692 "Call FUNCTION with argument QUESTION; optionally display TEXT... args.
6693 If SHOW is non-nil, the arguments TEXT... are displayed in a temp buffer.
6694 The following arguments may contain lists of values."
6696 (setq text (message-flatten-list text)))
6697 (save-window-excursion
6699 (with-output-to-temp-buffer " *MESSAGE information message*"
6700 (set-buffer " *MESSAGE information message*")
6701 (fundamental-mode) ; for Emacs 20.4+
6702 (mapcar 'princ text)
6703 (goto-char (point-min))))
6704 (funcall ask question))
6705 (funcall ask question)))
6707 (defun message-flatten-list (list)
6708 "Return a new, flat list that contains all elements of LIST.
6710 \(message-flatten-list '(1 (2 3 (4 5 (6))) 7))
6713 (apply 'append (mapcar 'message-flatten-list list)))
6717 (defun message-generate-new-buffer-clone-locals (name &optional varstr)
6718 "Create and return a buffer with name based on NAME using `generate-new-buffer'.
6719 Then clone the local variables and values from the old buffer to the
6720 new one, cloning only the locals having a substring matching the
6722 (let ((oldbuf (current-buffer)))
6724 (set-buffer (generate-new-buffer name))
6725 (message-clone-locals oldbuf varstr)
6728 (defun message-clone-locals (buffer &optional varstr)
6729 "Clone the local variables from BUFFER to the current buffer."
6730 (let ((locals (save-excursion
6732 (buffer-local-variables)))
6733 (regexp "^gnus\\|^nn\\|^message\\|^sendmail\\|^smtp\\|^user-mail-address"))
6736 (when (and (consp local)
6738 (string-match regexp (symbol-name (car local)))
6740 (string-match varstr (symbol-name (car local)))))
6742 (set (make-local-variable (car local))
6750 (defvar message-inhibit-body-encoding nil)
6752 (defun message-encode-message-body ()
6753 (unless message-inhibit-body-encoding
6754 (let ((mail-parse-charset (or mail-parse-charset
6755 message-default-charset))
6756 (case-fold-search t)
6757 lines content-type-p)
6760 (narrow-to-region (point) (point-max))
6761 (let ((new (mml-generate-mime)))
6763 (delete-region (point-min) (point-max))
6765 (goto-char (point-min))
6766 (if (eq (aref new 0) ?\n)
6768 (search-forward "\n\n")
6769 (setq lines (buffer-substring (point-min) (1- (point))))
6770 (delete-region (point-min) (point))))))
6772 (message-narrow-to-headers-or-head)
6773 (message-remove-header "Mime-Version")
6774 (goto-char (point-max))
6775 (insert "MIME-Version: 1.0\n")
6778 (setq content-type-p
6780 (re-search-backward "^Content-Type:" nil t))))
6782 (message-narrow-to-headers-or-head)
6783 (message-remove-first-header "Content-Type")
6784 (message-remove-first-header "Content-Transfer-Encoding"))
6785 ;; We always make sure that the message has a Content-Type
6786 ;; header. This is because some broken MTAs and MUAs get
6787 ;; awfully confused when confronted with a message with a
6788 ;; MIME-Version header and without a Content-Type header. For
6789 ;; instance, Solaris' /usr/bin/mail.
6790 (unless content-type-p
6791 (goto-char (point-min))
6792 ;; For unknown reason, MIME-Version doesn't exist.
6793 (when (re-search-forward "^MIME-Version:" nil t)
6795 (insert "Content-Type: text/plain; charset=us-ascii\n"))))))
6797 (defun message-read-from-minibuffer (prompt &optional initial-contents)
6798 "Read from the minibuffer while providing abbrev expansion."
6799 (if (fboundp 'mail-abbrevs-setup)
6800 (let ((mail-abbrev-mode-regexp "")
6801 (minibuffer-setup-hook 'mail-abbrevs-setup)
6802 (minibuffer-local-map message-minibuffer-local-map))
6803 (read-from-minibuffer prompt initial-contents))
6804 (let ((minibuffer-setup-hook 'mail-abbrev-minibuffer-setup-hook)
6805 (minibuffer-local-map message-minibuffer-local-map))
6806 (read-string prompt initial-contents))))
6808 (defun message-use-alternative-email-as-from ()
6809 (require 'mail-utils)
6810 (let* ((fields '("To" "Cc"))
6813 (mail-strip-quoted-names
6814 (mapconcat 'message-fetch-reply-field fields ","))
6818 (if (string-match message-alternative-emails (car emails))
6819 (setq email (car emails)
6822 (unless (or (not email) (equal email user-mail-address))
6823 (goto-char (point-max))
6824 (insert "From: " email "\n"))))
6826 (defun message-options-get (symbol)
6827 (cdr (assq symbol message-options)))
6829 (defun message-options-set (symbol value)
6830 (let ((the-cons (assq symbol message-options)))
6833 (setcdr the-cons value)
6834 (setq message-options (delq the-cons message-options)))
6836 (push (cons symbol value) message-options))))
6839 (defun message-options-set-recipient ()
6841 (message-narrow-to-headers-or-head)
6842 (message-options-set 'message-sender
6843 (mail-strip-quoted-names
6844 (message-fetch-field "from")))
6845 (message-options-set 'message-recipients
6846 (mail-strip-quoted-names
6847 (let ((to (message-fetch-field "to"))
6848 (cc (message-fetch-field "cc"))
6849 (bcc (message-fetch-field "bcc")))
6852 (if (and to cc) ", ")
6854 (if (and (or to cc) bcc) ", ")
6857 (defun message-hide-headers ()
6858 "Hide headers based on the `message-hidden-headers' variable."
6859 (let ((regexps (if (stringp message-hidden-headers)
6860 (list message-hidden-headers)
6861 message-hidden-headers))
6862 (inhibit-point-motion-hooks t)
6863 (after-change-functions nil))
6867 (message-narrow-to-headers)
6868 (goto-char (point-min))
6870 (if (not (message-hide-header-p regexps))
6871 (message-next-header)
6872 (let ((begin (point)))
6873 (message-next-header)
6874 (add-text-properties
6876 '(invisible t message-hidden t))))))))))
6878 (defun message-hide-header-p (regexps)
6881 (when (eq (car regexps) 'not)
6884 (dolist (regexp regexps)
6885 (setq result (or result (looking-at regexp))))
6890 (when (featurep 'xemacs)
6891 (require 'messagexmas)
6892 (message-xmas-redefine))
6896 (run-hooks 'message-load-hook)
6899 ;; coding: iso-8859-1
6902 ;; arch-tag: 94b32cac-4504-4b6c-8181-030ebf380ee0
6903 ;;; message.el ends here