1 ;;; message.el --- composing mail and news messages
3 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
4 ;; 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
6 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
7 ;; Keywords: mail, news
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software: you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation, either version 3 of the License, or
14 ;; (at your option) any later version.
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
26 ;; This mode provides mail-sending facilities from within Emacs. It
27 ;; consists mainly of large chunks of code from the sendmail.el,
28 ;; gnus-msg.el and rnewspost.el files.
32 ;; For Emacs <22.2 and XEmacs.
34 (unless (fboundp 'declare-function
) (defmacro declare-function
(&rest r
))))
41 ;; Only for the trivial macros mail-header-from, mail-header-date
42 ;; mail-header-references, mail-header-subject, mail-header-id
43 (eval-when-compile (require 'nnheader
))
44 ;; This is apparently necessary even though things are autoloaded.
45 ;; Because we dynamically bind mail-abbrev-mode-regexp, we'd better
46 ;; require mailabbrev here.
47 (if (featurep 'xemacs
)
48 (require 'mail-abbrevs
)
49 (require 'mailabbrev
))
54 (autoload 'mailclient-send-it
"mailclient") ;; Emacs 22 or contrib/
56 (defvar gnus-message-group-art
)
57 (defvar gnus-list-identifiers
) ; gnus-sum is required where necessary
58 (defvar rmail-enable-mime-composing
)
60 (defgroup message
'((user-mail-address custom-variable
)
61 (user-full-name custom-variable
))
62 "Mail and news message composing."
63 :link
'(custom-manual "(message)Top")
67 (put 'user-mail-address
'custom-type
'string
)
68 (put 'user-full-name
'custom-type
'string
)
70 (defgroup message-various nil
71 "Various Message Variables."
72 :link
'(custom-manual "(message)Various Message Variables")
75 (defgroup message-buffers nil
77 :link
'(custom-manual "(message)Message Buffers")
80 (defgroup message-sending nil
82 :link
'(custom-manual "(message)Sending Variables")
85 (defgroup message-interface nil
87 :link
'(custom-manual "(message)Interface")
90 (defgroup message-forwarding nil
92 :link
'(custom-manual "(message)Forwarding")
93 :group
'message-interface
)
95 (defgroup message-insertion nil
97 :link
'(custom-manual "(message)Insertion")
100 (defgroup message-headers nil
102 :link
'(custom-manual "(message)Message Headers")
105 (defgroup message-news nil
106 "Composing News Messages."
109 (defgroup message-mail nil
110 "Composing Mail Messages."
113 (defgroup message-faces nil
114 "Faces used for message composing."
118 (defcustom message-directory
"~/Mail/"
119 "*Directory from which all other mail file variables are derived."
120 :group
'message-various
123 (defcustom message-max-buffers
10
124 "*How many buffers to keep before starting to kill them off."
125 :group
'message-buffers
128 (defcustom message-send-rename-function nil
129 "Function called to rename the buffer after sending it."
130 :group
'message-buffers
131 :type
'(choice function
(const nil
)))
133 (defcustom message-fcc-handler-function
'message-output
134 "*A function called to save outgoing articles.
135 This function will be called with the name of the file to store the
136 article in. The default function is `message-output' which saves in Unix
138 :type
'(radio (function-item message-output
)
139 (function :tag
"Other"))
140 :group
'message-sending
)
142 (defcustom message-fcc-externalize-attachments nil
143 "If non-nil, attachments are included as external parts in Fcc copies."
146 :group
'message-sending
)
148 (defcustom message-courtesy-message
149 "The following message is a courtesy copy of an article\nthat has been posted to %s as well.\n\n"
150 "*This is inserted at the start of a mailed copy of a posted message.
151 If the string contains the format spec \"%s\", the Newsgroups
152 the article has been posted to will be inserted there.
153 If this variable is nil, no such courtesy message will be added."
154 :group
'message-sending
155 :type
'(radio string
(const nil
)))
157 (defcustom message-ignored-bounced-headers
158 "^\\(Received\\|Return-Path\\|Delivered-To\\):"
159 "*Regexp that matches headers to be removed in resent bounced mail."
160 :group
'message-interface
163 (defcustom message-from-style mail-from-style
164 "Specifies how \"From\" headers look.
166 If nil, they contain just the return address like:
168 If `parens', they look like:
169 king@grassland.com (Elvis Parsley)
170 If `angles', they look like:
171 Elvis Parsley <king@grassland.com>
173 Otherwise, most addresses look like `angles', but they look like
174 `parens' if `angles' would need quoting and `parens' would not."
176 :type
'(choice (const :tag
"simple" nil
)
180 :group
'message-headers
)
182 (defcustom message-insert-canlock t
183 "Whether to insert a Cancel-Lock header in news postings."
185 :group
'message-headers
188 (defcustom message-syntax-checks
189 (if message-insert-canlock
'((sender . disabled
)) nil
)
190 ;; Guess this one shouldn't be easy to customize...
191 "*Controls what syntax checks should not be performed on outgoing posts.
192 To disable checking of long signatures, for instance, add
193 `(signature . disabled)' to this list.
195 Don't touch this variable unless you really know what you're doing.
197 Checks include `approved', `bogus-recipient', `continuation-headers',
198 `control-chars', `empty', `existing-newsgroups', `from', `illegible-text',
199 `invisible-text', `long-header-lines', `long-lines', `message-id',
200 `multiple-headers', `new-text', `newsgroups', `quoting-style',
201 `repeated-newsgroups', `reply-to', `sender', `sendsys', `shoot',
202 `shorten-followup-to', `signature', `size', `subject', `subject-cmsg'
203 and `valid-newsgroups'."
205 :type
'(repeat sexp
)) ; Fixme: improve this
207 (defcustom message-required-headers
'((optional . References
)
209 "*Headers to be generated or prompted for when sending a message.
210 Also see `message-required-news-headers' and
211 `message-required-mail-headers'."
214 :group
'message-headers
215 :link
'(custom-manual "(message)Message Headers")
216 :type
'(repeat sexp
))
218 (defcustom message-draft-headers
'(References From Date
)
219 "*Headers to be generated when saving a draft message."
222 :group
'message-headers
223 :link
'(custom-manual "(message)Message Headers")
224 :type
'(repeat sexp
))
226 (defcustom message-required-news-headers
227 '(From Newsgroups Subject Date Message-ID
228 (optional . Organization
)
229 (optional . User-Agent
))
230 "*Headers to be generated or prompted for when posting an article.
231 RFC977 and RFC1036 require From, Date, Newsgroups, Subject,
232 Message-ID. Organization, Lines, In-Reply-To, Expires, and
233 User-Agent are optional. If you don't want message to insert some
234 header, remove it from this list."
236 :group
'message-headers
237 :link
'(custom-manual "(message)Message Headers")
238 :type
'(repeat sexp
))
240 (defcustom message-required-mail-headers
241 '(From Subject Date
(optional . In-Reply-To
) Message-ID
242 (optional . User-Agent
))
243 "*Headers to be generated or prompted for when mailing a message.
244 It is recommended that From, Date, To, Subject and Message-ID be
245 included. Organization and User-Agent are optional."
247 :group
'message-headers
248 :link
'(custom-manual "(message)Message Headers")
249 :type
'(repeat sexp
))
251 (defcustom message-prune-recipient-rules nil
252 "Rules for how to prune the list of recipients when doing wide replies.
253 This is a list of regexps and regexp matches."
256 :group
'message-headers
257 :link
'(custom-manual "(message)Wide Reply")
258 :type
'(repeat regexp
))
260 (defcustom message-deletable-headers
'(Message-ID Date Lines
)
261 "Headers to be deleted if they already exist and were generated by message previously."
262 :group
'message-headers
263 :link
'(custom-manual "(message)Message Headers")
266 (defcustom message-ignored-news-headers
267 "^NNTP-Posting-Host:\\|^Xref:\\|^[BGF]cc:\\|^Resent-Fcc:\\|^X-Draft-From:\\|^X-Gnus-Agent-Meta-Information:"
268 "*Regexp of headers to be removed unconditionally before posting."
270 :group
'message-headers
271 :link
'(custom-manual "(message)Message Headers")
272 :type
'(repeat :value-to-internal
(lambda (widget value
)
273 (custom-split-regexp-maybe value
))
274 :match
(lambda (widget value
)
276 (widget-editable-list-match widget value
)))
279 (defcustom message-ignored-mail-headers
280 "^\\([GF]cc\\|Resent-Fcc\\|Xref\\|X-Draft-From\\|X-Gnus-Agent-Meta-Information\\):"
281 "*Regexp of headers to be removed unconditionally before mailing."
283 :group
'message-headers
284 :link
'(custom-manual "(message)Mail Headers")
287 (defcustom message-ignored-supersedes-headers
"^Path:\\|^Date\\|^NNTP-Posting-Host:\\|^Xref:\\|^Lines:\\|^Received:\\|^X-From-Line:\\|^X-Trace:\\|^X-ID:\\|^X-Complaints-To:\\|Return-Path:\\|^Supersedes:\\|^NNTP-Posting-Date:\\|^X-Trace:\\|^X-Complaints-To:\\|^Cancel-Lock:\\|^Cancel-Key:\\|^X-Hashcash:\\|^X-Payment:\\|^Approved:\\|^Injection-Date:\\|^Injection-Info:"
288 "*Header lines matching this regexp will be deleted before posting.
289 It's best to delete old Path and Date headers before posting to avoid
291 :group
'message-interface
292 :link
'(custom-manual "(message)Superseding")
293 :type
'(repeat :value-to-internal
(lambda (widget value
)
294 (custom-split-regexp-maybe value
))
295 :match
(lambda (widget value
)
297 (widget-editable-list-match widget value
)))
300 (defcustom message-subject-re-regexp
301 "^[ \t]*\\([Rr][Ee]\\(\\[[0-9]*\\]\\)*:[ \t]*\\)*[ \t]*"
302 "*Regexp matching \"Re: \" in the subject line."
303 :group
'message-various
304 :link
'(custom-manual "(message)Message Headers")
307 ;;; Start of variables adopted from `message-utils.el'.
309 (defcustom message-subject-trailing-was-query t
310 "*What to do with trailing \"(was: <old subject>)\" in subject lines.
311 If nil, leave the subject unchanged. If it is the symbol `ask', query
312 the user what do do. In this case, the subject is matched against
313 `message-subject-trailing-was-ask-regexp'. If
314 `message-subject-trailing-was-query' is t, always strip the trailing
315 old subject. In this case, `message-subject-trailing-was-regexp' is
318 :type
'(choice (const :tag
"never" nil
)
319 (const :tag
"always strip" t
)
321 :link
'(custom-manual "(message)Message Headers")
322 :group
'message-various
)
324 (defcustom message-subject-trailing-was-ask-regexp
325 "[ \t]*\\([[(]+[Ww][Aa][Ss]:?[ \t]*.*[])]+\\)"
326 "*Regexp matching \"(was: <old subject>)\" in the subject line.
328 The function `message-strip-subject-trailing-was' uses this regexp if
329 `message-subject-trailing-was-query' is set to the symbol `ask'. If
330 the variable is t instead of `ask', use
331 `message-subject-trailing-was-regexp' instead.
333 It is okay to create some false positives here, as the user is asked."
335 :group
'message-various
336 :link
'(custom-manual "(message)Message Headers")
339 (defcustom message-subject-trailing-was-regexp
340 "[ \t]*\\((*[Ww][Aa][Ss]:[ \t]*.*)\\)"
341 "*Regexp matching \"(was: <old subject>)\" in the subject line.
343 If `message-subject-trailing-was-query' is set to t, the subject is
344 matched against `message-subject-trailing-was-regexp' in
345 `message-strip-subject-trailing-was'. You should use a regexp creating very
346 few false positives here."
348 :group
'message-various
349 :link
'(custom-manual "(message)Message Headers")
352 ;;; marking inserted text
354 (defcustom message-mark-insert-begin
355 "--8<---------------cut here---------------start------------->8---\n"
356 "How to mark the beginning of some inserted text."
359 :link
'(custom-manual "(message)Insertion Variables")
360 :group
'message-various
)
362 (defcustom message-mark-insert-end
363 "--8<---------------cut here---------------end--------------->8---\n"
364 "How to mark the end of some inserted text."
367 :link
'(custom-manual "(message)Insertion Variables")
368 :group
'message-various
)
370 (defcustom message-archive-header
"X-No-Archive: Yes\n"
371 "Header to insert when you don't want your article to be archived.
372 Archives \(such as groups.google.com\) respect this header."
375 :link
'(custom-manual "(message)Header Commands")
376 :group
'message-various
)
378 (defcustom message-archive-note
379 "X-No-Archive: Yes - save http://groups.google.com/"
380 "Note to insert why you wouldn't want this posting archived.
381 If nil, don't insert any text in the body."
383 :type
'(radio string
(const nil
))
384 :link
'(custom-manual "(message)Header Commands")
385 :group
'message-various
)
387 ;;; Crossposts and Followups
388 ;; inspired by JoH-followup-to by Jochem Huhman <joh at gmx.de>
389 ;; new suggestions by R. Weikusat <rw at another.de>
391 (defvar message-cross-post-old-target nil
392 "Old target for cross-posts or follow-ups.")
393 (make-variable-buffer-local 'message-cross-post-old-target
)
395 (defcustom message-cross-post-default t
396 "When non-nil `message-cross-post-followup-to' will perform a crosspost.
397 If nil, `message-cross-post-followup-to' will only do a followup. Note that
398 you can explicitly override this setting by calling
399 `message-cross-post-followup-to' with a prefix."
402 :group
'message-various
)
404 (defcustom message-cross-post-note
"Crosspost & Followup-To: "
405 "Note to insert before signature to notify of cross-post and follow-up."
408 :group
'message-various
)
410 (defcustom message-followup-to-note
"Followup-To: "
411 "Note to insert before signature to notify of follow-up only."
414 :group
'message-various
)
416 (defcustom message-cross-post-note-function
'message-cross-post-insert-note
417 "Function to use to insert note about Crosspost or Followup-To.
418 The function will be called with four arguments. The function should not only
419 insert a note, but also ensure old notes are deleted. See the documentation
420 for `message-cross-post-insert-note'."
423 :group
'message-various
)
425 ;;; End of variables adopted from `message-utils.el'.
427 (defcustom message-signature-separator
"^-- $"
428 "Regexp matching the signature separator.
429 This variable is used to strip off the signature from quoted text
430 when `message-cite-function' is
431 `message-cite-original-without-signature'. Most useful values
432 are \"^-- $\" (strict) and \"^-- *$\" (loose; allow missing
434 :type
'(choice (const :tag
"strict" "^-- $")
435 (const :tag
"loose" "^-- *$")
437 :version
"22.3" ;; Gnus 5.10.12 (changed default)
438 :link
'(custom-manual "(message)Various Message Variables")
439 :group
'message-various
)
441 (defcustom message-elide-ellipsis
"\n[...]\n\n"
442 "*The string which is inserted for elided text."
444 :link
'(custom-manual "(message)Various Commands")
445 :group
'message-various
)
447 (defcustom message-interactive mail-interactive
448 "Non-nil means when sending a message wait for and display errors.
449 A value of nil means let mailer mail back a message to report errors."
451 :group
'message-sending
453 :link
'(custom-manual "(message)Sending Variables")
456 (defcustom message-confirm-send nil
457 "When non-nil, ask for confirmation when sending a message."
458 :group
'message-sending
460 :version
"23.1" ;; No Gnus
461 :link
'(custom-manual "(message)Sending Variables")
464 (defcustom message-generate-new-buffers
'unsent
465 "*Say whether to create a new message buffer to compose a message.
466 Valid values include:
469 Generate the buffer name in the Message way (e.g., *mail*, *news*,
470 *mail to whom*, *news on group*, etc.) and continue editing in the
471 existing buffer of that name. If there is no such buffer, it will
475 Create the new buffer with the name generated in the Message way.
478 Similar to `unique' but the buffer name begins with \"*unsent \".
481 Similar to nil but the buffer name is simpler like *mail message*.
484 If this is a function, call that function with three parameters:
485 The type, the To address and the group name (any of these may be nil).
486 The function should return the new buffer name."
488 :group
'message-buffers
489 :link
'(custom-manual "(message)Message Buffers")
490 :type
'(choice (const nil
)
491 (sexp :tag
"unique" :format
"unique\n" :value unique
492 :match
(lambda (widget value
) (memq value
'(unique t
))))
495 (function :format
"\n %{%t%}: %v")))
497 (defcustom message-kill-buffer-on-exit nil
498 "*Non-nil means that the message buffer will be killed after sending a message."
499 :group
'message-buffers
500 :link
'(custom-manual "(message)Message Buffers")
503 (defcustom message-kill-buffer-query t
504 "*Non-nil means that killing a modified message buffer has to be confirmed.
505 This is used by `message-kill-buffer'."
506 :version
"23.1" ;; No Gnus
507 :group
'message-buffers
510 (defcustom message-user-organization
511 (or (getenv "ORGANIZATION") t
)
512 "String to be used as an Organization header.
513 If t, use `message-user-organization-file'."
514 :group
'message-headers
515 :type
'(choice string
516 (const :tag
"consult file" t
)))
518 (defcustom message-user-organization-file
520 (dolist (f (list "/etc/organization"
521 "/etc/news/organization"
522 "/usr/lib/news/organization"))
523 (when (file-readable-p f
)
526 "*Local news organization file."
528 :link
'(custom-manual "(message)News Headers")
529 :group
'message-headers
)
531 (defcustom message-make-forward-subject-function
532 #'message-forward-subject-name-subject
533 "*List of functions called to generate subject headers for forwarded messages.
534 The subject generated by the previous function is passed into each
537 The provided functions are:
539 * `message-forward-subject-author-subject' Source of article (author or
540 newsgroup), in brackets followed by the subject
541 * `message-forward-subject-name-subject' Source of article (name of author
542 or newsgroup), in brackets followed by the subject
543 * `message-forward-subject-fwd' Subject of article with 'Fwd:' prepended
545 :group
'message-forwarding
546 :link
'(custom-manual "(message)Forwarding")
547 :type
'(radio (function-item message-forward-subject-author-subject
)
548 (function-item message-forward-subject-fwd
)
549 (function-item message-forward-subject-name-subject
)
550 (repeat :tag
"List of functions" function
)))
552 (defcustom message-forward-as-mime t
553 "*Non-nil means forward messages as an inline/rfc822 MIME section.
554 Otherwise, directly inline the old message in the forwarded message."
556 :group
'message-forwarding
557 :link
'(custom-manual "(message)Forwarding")
560 (defcustom message-forward-show-mml
'best
561 "*Non-nil means show forwarded messages as MML (decoded from MIME).
562 Otherwise, forwarded messages are unchanged.
563 Can also be the symbol `best' to indicate that MML should be
564 used, except when it is a bad idea to use MML. One example where
565 it is a bad idea is when forwarding a signed or encrypted
566 message, because converting MIME to MML would invalidate the
569 :group
'message-forwarding
570 :type
'(choice (const :tag
"use MML" t
)
571 (const :tag
"don't use MML " nil
)
572 (const :tag
"use MML when appropriate" best
)))
574 (defcustom message-forward-before-signature t
575 "*Non-nil means put forwarded message before signature, else after."
576 :group
'message-forwarding
579 (defcustom message-wash-forwarded-subjects nil
580 "*Non-nil means try to remove as much cruft as possible from the subject.
581 Done before generating the new subject of a forward."
582 :group
'message-forwarding
583 :link
'(custom-manual "(message)Forwarding")
586 (defcustom message-ignored-resent-headers
587 ;; `Delivered-To' needs to be removed because some mailers use it to
588 ;; detect loops, so if you resend a message to an address that ultimately
589 ;; comes back to you (e.g. a mailing-list to which you subscribe, in which
590 ;; case you may be removed from the list on the grounds that mail to you
591 ;; bounced with a "mailing loop" error).
592 "^Return-receipt\\|^X-Gnus\\|^Gnus-Warning:\\|^>?From \\|^Delivered-To:"
593 "*All headers that match this regexp will be deleted when resending a message."
594 :group
'message-interface
595 :link
'(custom-manual "(message)Resending")
596 :type
'(repeat :value-to-internal
(lambda (widget value
)
597 (custom-split-regexp-maybe value
))
598 :match
(lambda (widget value
)
600 (widget-editable-list-match widget value
)))
603 (defcustom message-forward-ignored-headers
"^Content-Transfer-Encoding:\\|^X-Gnus"
604 "*All headers that match this regexp will be deleted when forwarding a message."
606 :group
'message-forwarding
607 :type
'(repeat :value-to-internal
(lambda (widget value
)
608 (custom-split-regexp-maybe value
))
609 :match
(lambda (widget value
)
611 (widget-editable-list-match widget value
)))
614 (defcustom message-ignored-cited-headers
"."
615 "*Delete these headers from the messages you yank."
616 :group
'message-insertion
617 :link
'(custom-manual "(message)Insertion Variables")
620 (defcustom message-cite-prefix-regexp mail-citation-prefix-regexp
621 "*Regexp matching the longest possible citation prefix on a line."
623 :group
'message-insertion
624 :link
'(custom-manual "(message)Insertion Variables")
626 :set
(lambda (symbol value
)
628 (custom-set-default symbol value
)
629 (if (boundp 'gnus-message-cite-prefix-regexp
)
630 (setq gnus-message-cite-prefix-regexp
631 (concat "^\\(?:" value
"\\)"))))))
633 (defcustom message-cancel-message
"I am canceling my own article.\n"
634 "Message to be inserted in the cancel message."
635 :group
'message-interface
636 :link
'(custom-manual "(message)Canceling News")
639 (defun message-send-mail-function ()
640 "Return suitable value for the variable `message-send-mail-function'."
641 (cond ((and (require 'sendmail
)
642 (boundp 'sendmail-program
)
644 (executable-find sendmail-program
))
645 'message-send-mail-with-sendmail
)
646 ((and (locate-library "smtpmail")
647 (boundp 'smtpmail-default-smtp-server
)
648 smtpmail-default-smtp-server
)
649 'message-smtpmail-send-it
)
650 ((locate-library "mailclient")
651 'message-send-mail-with-mailclient
)
653 (error "Don't know how to send mail. Please customize `message-send-mail-function'"))))
655 ;; Useful to set in site-init.el
656 (defcustom message-send-mail-function
657 (cond ((eq send-mail-function
'smtpmail-send-it
) 'message-smtpmail-send-it
)
658 ((eq send-mail-function
'feedmail-send-it
) 'feedmail-send-it
)
659 ((eq send-mail-function
'mailclient-send-it
)
660 'message-send-mail-with-mailclient
)
661 (t (message-send-mail-function)))
662 "Function to call to send the current buffer as mail.
663 The headers should be delimited by a line whose contents match the
664 variable `mail-header-separator'.
666 Valid values include `message-send-mail-with-sendmail'
667 `message-send-mail-with-mh', `message-send-mail-with-qmail',
668 `message-smtpmail-send-it', `smtpmail-send-it',
669 `feedmail-send-it' and `message-send-mail-with-mailclient'. The
670 default is system dependent and determined by the function
671 `message-send-mail-function'.
673 See also `send-mail-function'."
674 :type
'(radio (function-item message-send-mail-with-sendmail
)
675 (function-item message-send-mail-with-mh
)
676 (function-item message-send-mail-with-qmail
)
677 (function-item message-smtpmail-send-it
)
678 (function-item smtpmail-send-it
)
679 (function-item feedmail-send-it
)
680 (function-item message-send-mail-with-mailclient
681 :tag
"Use Mailclient package")
682 (function :tag
"Other"))
683 :group
'message-sending
685 :initialize
'custom-initialize-default
686 :link
'(custom-manual "(message)Mail Variables")
687 :group
'message-mail
)
689 (defcustom message-send-news-function
'message-send-news
690 "Function to call to send the current buffer as news.
691 The headers should be delimited by a line whose contents match the
692 variable `mail-header-separator'."
693 :group
'message-sending
695 :link
'(custom-manual "(message)News Variables")
698 (defcustom message-reply-to-function nil
699 "If non-nil, function that should return a list of headers.
700 This function should pick out addresses from the To, Cc, and From headers
701 and respond with new To and Cc headers."
702 :group
'message-interface
703 :link
'(custom-manual "(message)Reply")
704 :type
'(choice function
(const nil
)))
706 (defcustom message-wide-reply-to-function nil
707 "If non-nil, function that should return a list of headers.
708 This function should pick out addresses from the To, Cc, and From headers
709 and respond with new To and Cc headers."
710 :group
'message-interface
711 :link
'(custom-manual "(message)Wide Reply")
712 :type
'(choice function
(const nil
)))
714 (defcustom message-followup-to-function nil
715 "If non-nil, function that should return a list of headers.
716 This function should pick out addresses from the To, Cc, and From headers
717 and respond with new To and Cc headers."
718 :group
'message-interface
719 :link
'(custom-manual "(message)Followup")
720 :type
'(choice function
(const nil
)))
722 (defcustom message-extra-wide-headers nil
723 "If non-nil, a list of additional address headers.
724 These are used when composing a wide reply."
725 :group
'message-sending
726 :type
'(repeat string
))
728 (defcustom message-use-followup-to
'ask
729 "*Specifies what to do with Followup-To header.
730 If nil, always ignore the header. If it is t, use its value, but
731 query before using the \"poster\" value. If it is the symbol `ask',
732 always query the user whether to use the value. If it is the symbol
733 `use', always use the value."
734 :group
'message-interface
735 :link
'(custom-manual "(message)Followup")
736 :type
'(choice (const :tag
"ignore" nil
)
737 (const :tag
"use & query" t
)
741 (defcustom message-use-mail-followup-to
'use
742 "*Specifies what to do with Mail-Followup-To header.
743 If nil, always ignore the header. If it is the symbol `ask', always
744 query the user whether to use the value. If it is the symbol `use',
745 always use the value."
747 :group
'message-interface
748 :link
'(custom-manual "(message)Mailing Lists")
749 :type
'(choice (const :tag
"ignore" nil
)
753 (defcustom message-subscribed-address-functions nil
754 "*Specifies functions for determining list subscription.
755 If nil, do not attempt to determine list subscription with functions.
756 If non-nil, this variable contains a list of functions which return
757 regular expressions to match lists. These functions can be used in
758 conjunction with `message-subscribed-regexps' and
759 `message-subscribed-addresses'."
761 :group
'message-interface
762 :link
'(custom-manual "(message)Mailing Lists")
763 :type
'(repeat sexp
))
765 (defcustom message-subscribed-address-file nil
766 "*A file containing addresses the user is subscribed to.
767 If nil, do not look at any files to determine list subscriptions. If
768 non-nil, each line of this file should be a mailing list address."
770 :group
'message-interface
771 :link
'(custom-manual "(message)Mailing Lists")
772 :type
'(radio file
(const nil
)))
774 (defcustom message-subscribed-addresses nil
775 "*Specifies a list of addresses the user is subscribed to.
776 If nil, do not use any predefined list subscriptions. This list of
777 addresses can be used in conjunction with
778 `message-subscribed-address-functions' and `message-subscribed-regexps'."
780 :group
'message-interface
781 :link
'(custom-manual "(message)Mailing Lists")
782 :type
'(repeat string
))
784 (defcustom message-subscribed-regexps nil
785 "*Specifies a list of addresses the user is subscribed to.
786 If nil, do not use any predefined list subscriptions. This list of
787 regular expressions can be used in conjunction with
788 `message-subscribed-address-functions' and `message-subscribed-addresses'."
790 :group
'message-interface
791 :link
'(custom-manual "(message)Mailing Lists")
792 :type
'(repeat regexp
))
794 (defcustom message-allow-no-recipients
'ask
795 "Specifies what to do when there are no recipients other than Gcc/Fcc.
796 If it is the symbol `always', the posting is allowed. If it is the
797 symbol `never', the posting is not allowed. If it is the symbol
798 `ask', you are prompted."
800 :group
'message-interface
801 :link
'(custom-manual "(message)Message Headers")
802 :type
'(choice (const always
)
806 (defcustom message-sendmail-f-is-evil nil
807 "*Non-nil means don't add \"-f username\" to the sendmail command line.
808 Doing so would be even more evil than leaving it out."
809 :group
'message-sending
810 :link
'(custom-manual "(message)Mail Variables")
813 (defcustom message-sendmail-envelope-from
814 ;; `mail-envelope-from' is unavailable unless sendmail.el is loaded.
815 (if (boundp 'mail-envelope-from
) mail-envelope-from
)
816 "*Envelope-from when sending mail with sendmail.
817 If this is nil, use `user-mail-address'. If it is the symbol
818 `header', use the From: header of the message."
820 :type
'(choice (string :tag
"From name")
821 (const :tag
"Use From: header from message" header
)
822 (const :tag
"Use `user-mail-address'" nil
))
823 :link
'(custom-manual "(message)Mail Variables")
824 :group
'message-sending
)
826 (defcustom message-sendmail-extra-arguments nil
827 "Additional arguments to `sendmail-program'."
828 ;; E.g. '("-a" "account") for msmtp
829 :version
"23.1" ;; No Gnus
830 :type
'(repeat string
)
831 ;; :link '(custom-manual "(message)Mail Variables")
832 :group
'message-sending
)
834 ;; qmail-related stuff
835 (defcustom message-qmail-inject-program
"/var/qmail/bin/qmail-inject"
836 "Location of the qmail-inject program."
837 :group
'message-sending
838 :link
'(custom-manual "(message)Mail Variables")
841 (defcustom message-qmail-inject-args nil
842 "Arguments passed to qmail-inject programs.
843 This should be a list of strings, one string for each argument.
844 It may also be a function.
846 For e.g., if you wish to set the envelope sender address so that bounces
847 go to the right place or to deal with listserv's usage of that address, you
848 might set this variable to '(\"-f\" \"you@some.where\")."
849 :group
'message-sending
850 :link
'(custom-manual "(message)Mail Variables")
851 :type
'(choice (function)
854 (defvar gnus-post-method
)
855 (defvar gnus-select-method
)
856 (defcustom message-post-method
857 (cond ((and (boundp 'gnus-post-method
)
858 (listp gnus-post-method
)
861 ((boundp 'gnus-select-method
)
864 "*Method used to post news.
865 Note that when posting from inside Gnus, for instance, this
866 variable isn't used."
868 :group
'message-sending
869 ;; This should be the `gnus-select-method' widget, but that might
870 ;; create a dependence to `gnus.el'.
873 ;; FIXME: This should be a temporary workaround until someone implements a
874 ;; proper solution. If a crash happens while replying, the auto-save file
875 ;; will *not* have a `References:' header if `message-generate-headers-first'
876 ;; is nil. See: http://article.gmane.org/gmane.emacs.gnus.general/51138
877 (defcustom message-generate-headers-first
'(references)
878 "Which headers should be generated before starting to compose a message.
879 If t, generate all required headers. This can also be a list of headers to
880 generate. The variables `message-required-news-headers' and
881 `message-required-mail-headers' specify which headers to generate.
883 Note that the variable `message-deletable-headers' specifies headers which
884 are to be deleted and then re-generated before sending, so this variable
885 will not have a visible effect for those headers."
886 :group
'message-headers
887 :link
'(custom-manual "(message)Message Headers")
888 :type
'(choice (const :tag
"None" nil
)
889 (const :tag
"References" '(references))
891 (repeat (sexp :tag
"Header"))))
893 (defcustom message-fill-column
72
894 "Column beyond which automatic line-wrapping should happen.
895 Local value for message buffers. If non-nil, also turn on
896 auto-fill in message buffers."
897 :group
'message-various
898 ;; :link '(custom-manual "(message)Message Headers")
899 :type
'(choice (const :tag
"Don't turn on auto fill" nil
)
902 (defcustom message-setup-hook nil
903 "Normal hook, run each time a new outgoing message is initialized.
904 The function `message-setup' runs this hook."
905 :group
'message-various
906 :link
'(custom-manual "(message)Various Message Variables")
909 (defcustom message-cancel-hook nil
910 "Hook run when cancelling articles."
911 :group
'message-various
912 :link
'(custom-manual "(message)Various Message Variables")
915 (defcustom message-signature-setup-hook nil
916 "Normal hook, run each time a new outgoing message is initialized.
917 It is run after the headers have been inserted and before
918 the signature is inserted."
919 :group
'message-various
920 :link
'(custom-manual "(message)Various Message Variables")
923 (defcustom message-mode-hook nil
924 "Hook run in message mode buffers."
925 :group
'message-various
928 (defcustom message-header-hook nil
929 "Hook run in a message mode buffer narrowed to the headers."
930 :group
'message-various
933 (defcustom message-header-setup-hook nil
934 "Hook called narrowed to the headers when setting up a message buffer."
935 :group
'message-various
936 :link
'(custom-manual "(message)Various Message Variables")
939 (defcustom message-minibuffer-local-map
940 (let ((map (make-sparse-keymap 'message-minibuffer-local-map
)))
941 (set-keymap-parent map minibuffer-local-map
)
943 "Keymap for `message-read-from-minibuffer'."
945 :group
'message-various
)
947 (defcustom message-citation-line-function
'message-insert-citation-line
948 "*Function called to insert the \"Whomever writes:\" line.
950 Predefined functions include `message-insert-citation-line' and
951 `message-insert-formatted-citation-line' (see the variable
952 `message-citation-line-format').
954 Note that Gnus provides a feature where the reader can click on
955 `writes:' to hide the cited text. If you change this line too much,
956 people who read your message will have to change their Gnus
957 configuration. See the variable `gnus-cite-attribution-suffix'."
959 (function-item :tag
"plain" message-insert-citation-line
)
960 (function-item :tag
"formatted" message-insert-formatted-citation-line
)
961 (function :tag
"Other"))
962 :link
'(custom-manual "(message)Insertion Variables")
963 :group
'message-insertion
)
965 (defcustom message-citation-line-format
"On %a, %b %d %Y, %N wrote:\n"
966 "Format of the \"Whomever writes:\" line.
968 The string is formatted using `format-spec'. The following
969 constructs are replaced:
971 %f The full From, e.g. \"John Doe <john.doe@example.invalid>\".
972 %n The mail address, e.g. \"john.doe@example.invalid\".
973 %N The real name if present, e.g.: \"John Doe\", else fall
974 back to the mail address.
975 %F The first name if present, e.g.: \"John\".
976 %L The last name if present, e.g.: \"Doe\".
978 All other format specifiers are passed to `format-time-string'
979 which is called using the date from the article your replying to.
980 Extracting the first (%F) and last name (%L) is done
981 heuristically, so you should always check it yourself.
983 Please also read the note in the documentation of
984 `message-citation-line-function'."
985 :type
'(choice (const :tag
"Plain" "%f writes:")
986 (const :tag
"Include date" "On %a, %b %d %Y, %n wrote:")
988 :link
'(custom-manual "(message)Insertion Variables")
989 :version
"23.1" ;; No Gnus
990 :group
'message-insertion
)
992 (defcustom message-yank-prefix mail-yank-prefix
993 "*Prefix inserted on the lines of yanked messages.
994 Fix `message-cite-prefix-regexp' if it is set to an abnormal value.
995 See also `message-yank-cited-prefix' and `message-yank-empty-prefix'."
998 :link
'(custom-manual "(message)Insertion Variables")
999 :group
'message-insertion
)
1001 (defcustom message-yank-cited-prefix
">"
1002 "*Prefix inserted on cited lines of yanked messages.
1003 Fix `message-cite-prefix-regexp' if it is set to an abnormal value.
1004 See also `message-yank-prefix' and `message-yank-empty-prefix'."
1007 :link
'(custom-manual "(message)Insertion Variables")
1008 :group
'message-insertion
)
1010 (defcustom message-yank-empty-prefix
">"
1011 "*Prefix inserted on empty lines of yanked messages.
1012 See also `message-yank-prefix' and `message-yank-cited-prefix'."
1015 :link
'(custom-manual "(message)Insertion Variables")
1016 :group
'message-insertion
)
1018 (defcustom message-indentation-spaces mail-indentation-spaces
1019 "*Number of spaces to insert at the beginning of each cited line.
1020 Used by `message-yank-original' via `message-yank-cite'."
1022 :group
'message-insertion
1023 :link
'(custom-manual "(message)Insertion Variables")
1026 (defcustom message-cite-function
'message-cite-original-without-signature
1027 "*Function for citing an original message.
1028 Predefined functions include `message-cite-original' and
1029 `message-cite-original-without-signature'.
1030 Note that these functions use `mail-citation-hook' if that is non-nil."
1031 :type
'(radio (function-item message-cite-original
)
1032 (function-item message-cite-original-without-signature
)
1033 (function-item sc-cite-original
)
1034 (function :tag
"Other"))
1035 :link
'(custom-manual "(message)Insertion Variables")
1036 :version
"22.3" ;; Gnus 5.10.12 (changed default)
1037 :group
'message-insertion
)
1039 (defcustom message-indent-citation-function
'message-indent-citation
1040 "*Function for modifying a citation just inserted in the mail buffer.
1041 This can also be a list of functions. Each function can find the
1042 citation between (point) and (mark t). And each function should leave
1043 point and mark around the citation text as modified."
1045 :link
'(custom-manual "(message)Insertion Variables")
1046 :group
'message-insertion
)
1048 (defcustom message-signature mail-signature
1049 "*String to be inserted at the end of the message buffer.
1050 If t, the `message-signature-file' file will be inserted instead.
1051 If a function, the result from the function will be used instead.
1052 If a form, the result from the form will be used instead."
1055 :link
'(custom-manual "(message)Insertion Variables")
1056 :group
'message-insertion
)
1058 (defcustom message-signature-file mail-signature-file
1059 "*Name of file containing the text inserted at end of message buffer.
1060 Ignored if the named file doesn't exist.
1061 If nil, don't insert a signature.
1062 If a path is specified, the value of `message-signature-directory' is ignored,
1065 :type
'(choice file
(const :tags
"None" nil
))
1066 :link
'(custom-manual "(message)Insertion Variables")
1067 :group
'message-insertion
)
1069 (defcustom message-signature-directory nil
1070 "*Name of directory containing signature files.
1071 Comes in handy if you have many such files, handled via posting styles for
1073 If nil, `message-signature-file' is expected to specify the directory if
1075 :type
'(choice string
(const :tags
"None" nil
))
1076 :link
'(custom-manual "(message)Insertion Variables")
1077 :group
'message-insertion
)
1079 (defcustom message-signature-insert-empty-line t
1080 "*If non-nil, insert an empty line before the signature separator."
1083 :link
'(custom-manual "(message)Insertion Variables")
1084 :group
'message-insertion
)
1086 (defcustom message-distribution-function nil
1087 "*Function called to return a Distribution header."
1088 :group
'message-news
1089 :group
'message-headers
1090 :link
'(custom-manual "(message)News Headers")
1091 :type
'(choice function
(const nil
)))
1093 (defcustom message-expires
14
1094 "Number of days before your article expires."
1095 :group
'message-news
1096 :group
'message-headers
1097 :link
'(custom-manual "(message)News Headers")
1100 (defcustom message-user-path nil
1101 "If nil, use the NNTP server name in the Path header.
1102 If stringp, use this; if non-nil, use no host name (user name only)."
1103 :group
'message-news
1104 :group
'message-headers
1105 :link
'(custom-manual "(message)News Headers")
1106 :type
'(choice (const :tag
"nntp" nil
)
1107 (string :tag
"name")
1108 (sexp :tag
"none" :format
"%t" t
)))
1110 ;; This can be the name of a buffer, or a cons cell (FUNCTION . ARGS)
1111 ;; for yanking the original buffer.
1112 (defvar message-reply-buffer nil
)
1113 (defvar message-reply-headers nil
1114 "The headers of the current replied article.
1115 It is a vector of the following headers:
1116 \[number subject from date id references chars lines xref extra].")
1117 (defvar message-newsreader nil
)
1118 (defvar message-mailer nil
)
1119 (defvar message-sent-message-via nil
)
1120 (defvar message-checksum nil
)
1121 (defvar message-send-actions nil
1122 "A list of actions to be performed upon successful sending of a message.")
1123 (defvar message-exit-actions nil
1124 "A list of actions to be performed upon exiting after sending a message.")
1125 (defvar message-kill-actions nil
1126 "A list of actions to be performed before killing a message buffer.")
1127 (defvar message-postpone-actions nil
1128 "A list of actions to be performed after postponing a message.")
1130 (define-widget 'message-header-lines
'text
1131 "All header lines must be LFD terminated."
1132 :format
"%{%t%}:%n%v"
1133 :valid-regexp
"^\\'"
1134 :error
"All header lines must be newline terminated")
1136 (defcustom message-default-headers
""
1137 "Header lines to be inserted in outgoing messages.
1138 This can be set to a string containing or a function returning
1139 header lines to be inserted before you edit the message, so you
1140 can edit or delete these lines. If set to a function, it is
1141 called and its result is inserted."
1143 :group
'message-headers
1144 :link
'(custom-manual "(message)Message Headers")
1146 (message-header-lines :tag
"String")
1147 (function :tag
"Function")))
1149 (defcustom message-default-mail-headers
1150 ;; Ease the transition from mail-mode to message-mode. See bugs#4431, 5555.
1151 (concat (if (and (boundp 'mail-default-reply-to
)
1152 (stringp mail-default-reply-to
))
1153 (format "Reply-to: %s\n" mail-default-reply-to
))
1154 (if (and (boundp 'mail-self-blind
)
1156 (format "BCC: %s\n" user-mail-address
))
1157 (if (and (boundp 'mail-archive-file-name
)
1158 (stringp mail-archive-file-name
))
1159 (format "FCC: %s\n" mail-archive-file-name
))
1160 ;; Use the value of `mail-default-headers' if available.
1161 ;; Note: as for XEmacs 21.4 and 21.5, it is unavailable
1162 ;; unless sendmail.el is loaded.
1163 (if (boundp 'mail-default-headers
)
1164 mail-default-headers
))
1165 "*A string of header lines to be inserted in outgoing mails."
1167 :group
'message-headers
1168 :group
'message-mail
1169 :link
'(custom-manual "(message)Mail Headers")
1170 :type
'message-header-lines
)
1172 (defcustom message-default-news-headers
""
1173 "*A string of header lines to be inserted in outgoing news articles."
1174 :group
'message-headers
1175 :group
'message-news
1176 :link
'(custom-manual "(message)News Headers")
1177 :type
'message-header-lines
)
1179 ;; Note: could use /usr/ucb/mail instead of sendmail;
1180 ;; options -t, and -v if not interactive.
1181 (defcustom message-mailer-swallows-blank-line
1182 (if (and (string-match "sparc-sun-sunos\\(\\'\\|[^5]\\)"
1183 system-configuration
)
1184 (file-readable-p "/etc/sendmail.cf")
1185 (let ((buffer (get-buffer-create " *temp*")))
1187 (with-current-buffer buffer
1188 (insert-file-contents "/etc/sendmail.cf")
1189 (goto-char (point-min))
1190 (let ((case-fold-search nil
))
1191 (re-search-forward "^OR\\>" nil t
)))
1192 (kill-buffer buffer
))))
1193 ;; According to RFC822, "The field-name must be composed of printable
1194 ;; ASCII characters (i. e., characters that have decimal values between
1195 ;; 33 and 126, except colon)", i. e., any chars except ctl chars,
1197 '(looking-at "[ \t]\\|[][!\"#$%&'()*+,-./0-9;<=>?@A-Z\\\\^_`a-z{|}~]+:"))
1198 "*Set this non-nil if the system's mailer runs the header and body together.
1199 \(This problem exists on Sunos 4 when sendmail is run in remote mode.)
1200 The value should be an expression to test whether the problem will
1202 :group
'message-sending
1203 :link
'(custom-manual "(message)Mail Variables")
1207 (define-mail-user-agent 'message-user-agent
1208 'message-mail
'message-send-and-exit
1209 'message-kill-buffer
'message-send-hook
)
1211 (defvar message-mh-deletable-headers
'(Message-ID Date Lines Sender
)
1212 "If non-nil, delete the deletable headers before feeding to mh.")
1214 (defvar message-send-method-alist
1215 '((news message-news-p message-send-via-news
)
1216 (mail message-mail-p message-send-via-mail
))
1217 "Alist of ways to send outgoing messages.
1218 Each element has the form
1220 \(TYPE PREDICATE FUNCTION)
1222 where TYPE is a symbol that names the method; PREDICATE is a function
1223 called without any parameters to determine whether the message is
1224 a message of type TYPE; and FUNCTION is a function to be called if
1225 PREDICATE returns non-nil. FUNCTION is called with one parameter --
1228 (defcustom message-mail-alias-type
'abbrev
1229 "*What alias expansion type to use in Message buffers.
1230 The default is `abbrev', which uses mailabbrev. `ecomplete' uses
1231 an electric completion mode. nil switches mail aliases off.
1232 This can also be a list of values."
1234 :link
'(custom-manual "(message)Mail Aliases")
1235 :type
'(choice (const :tag
"Use Mailabbrev" abbrev
)
1236 (const :tag
"Use ecomplete" ecomplete
)
1237 (const :tag
"No expansion" nil
)))
1239 (defcustom message-self-insert-commands
'(self-insert-command)
1240 "List of `self-insert-command's used to trigger ecomplete.
1241 When one of those commands is invoked to enter a character in To or Cc
1242 header, ecomplete will suggest the candidates of recipients (see also
1243 `message-mail-alias-type'). If you use some tool to enter non-ASCII
1244 text and it replaces `self-insert-command' with the other command, e.g.
1245 `egg-self-insert-command', you may want to add it to this list."
1246 :group
'message-various
1247 :type
'(repeat function
))
1249 (defcustom message-auto-save-directory
1250 (file-name-as-directory (expand-file-name "drafts" message-directory
))
1251 "*Directory where Message auto-saves buffers if Gnus isn't running.
1252 If nil, Message won't auto-save."
1253 :group
'message-buffers
1254 :link
'(custom-manual "(message)Various Message Variables")
1255 :type
'(choice directory
(const :tag
"Don't auto-save" nil
)))
1257 (defcustom message-default-charset
1258 (and (not (mm-multibyte-p)) 'iso-8859-1
)
1259 "Default charset used in non-MULE Emacsen.
1260 If nil, you might be asked to input the charset."
1263 :link
'(custom-manual "(message)Various Message Variables")
1266 (defcustom message-dont-reply-to-names
1267 (and (boundp 'rmail-dont-reply-to-names
) rmail-dont-reply-to-names
)
1268 "*Addresses to prune when doing wide replies.
1269 This can be a regexp or a list of regexps. Also, a value of nil means
1270 exclude your own user name only."
1273 :link
'(custom-manual "(message)Wide Reply")
1274 :type
'(choice (const :tag
"Yourself" nil
)
1276 (repeat :tag
"Regexp List" regexp
)))
1278 (defsubst message-dont-reply-to-names
()
1279 (gmm-regexp-concat message-dont-reply-to-names
))
1281 (defvar message-shoot-gnksa-feet nil
1282 "*A list of GNKSA feet you are allowed to shoot.
1283 Gnus gives you all the opportunity you could possibly want for
1284 shooting yourself in the foot. Also, Gnus allows you to shoot the
1285 feet of Good Net-Keeping Seal of Approval. The following are foot
1287 `empty-article' Allow you to post an empty article;
1288 `quoted-text-only' Allow you to post quoted text only;
1289 `multiple-copies' Allow you to post multiple copies;
1290 `cancel-messages' Allow you to cancel or supersede messages from
1291 your other email addresses.")
1293 (defsubst message-gnksa-enable-p
(feature)
1294 (or (not (listp message-shoot-gnksa-feet
))
1295 (memq feature message-shoot-gnksa-feet
)))
1297 (defcustom message-hidden-headers
'("^References:" "^Face:" "^X-Face:"
1299 "Regexp of headers to be hidden when composing new messages.
1300 This can also be a list of regexps to match headers. Or a list
1301 starting with `not' and followed by regexps."
1304 :link
'(custom-manual "(message)Message Headers")
1306 :format
"%{%t%}: %[Value Type%] %v"
1307 (regexp :menu-tag
"regexp" :format
"regexp\n%t: %v")
1308 (repeat :menu-tag
"(regexp ...)" :format
"(regexp ...)\n%v%i"
1309 (regexp :format
"%t: %v"))
1310 (cons :menu-tag
"(not regexp ...)" :format
"(not regexp ...)\n%v"
1312 (repeat :format
"%v%i"
1313 (regexp :format
"%t: %v")))))
1315 (defcustom message-cite-articles-with-x-no-archive t
1316 "If non-nil, cite text from articles that has X-No-Archive set."
1320 ;;; Internal variables.
1321 ;;; Well, not really internal.
1323 (defvar message-mode-syntax-table
1324 (let ((table (copy-syntax-table text-mode-syntax-table
)))
1325 (modify-syntax-entry ?%
". " table
)
1326 (modify-syntax-entry ?
> ". " table
)
1327 (modify-syntax-entry ?
< ". " table
)
1329 "Syntax table used while in Message mode.")
1331 (defface message-header-to
1334 (:foreground
"DarkOliveGreen1" :bold t
))
1337 (:foreground
"MidnightBlue" :bold t
))
1339 (:bold t
:italic t
)))
1340 "Face used for displaying From headers."
1341 :group
'message-faces
)
1342 ;; backward-compatibility alias
1343 (put 'message-header-to-face
'face-alias
'message-header-to
)
1344 (put 'message-header-to-face
'obsolete-face
"22.1")
1346 (defface message-header-cc
1349 (:foreground
"chartreuse1" :bold t
))
1352 (:foreground
"MidnightBlue"))
1355 "Face used for displaying Cc headers."
1356 :group
'message-faces
)
1357 ;; backward-compatibility alias
1358 (put 'message-header-cc-face
'face-alias
'message-header-cc
)
1359 (put 'message-header-cc-face
'obsolete-face
"22.1")
1361 (defface message-header-subject
1364 (:foreground
"OliveDrab1"))
1367 (:foreground
"navy blue" :bold t
))
1370 "Face used for displaying subject headers."
1371 :group
'message-faces
)
1372 ;; backward-compatibility alias
1373 (put 'message-header-subject-face
'face-alias
'message-header-subject
)
1374 (put 'message-header-subject-face
'obsolete-face
"22.1")
1376 (defface message-header-newsgroups
1379 (:foreground
"yellow" :bold t
:italic t
))
1382 (:foreground
"blue4" :bold t
:italic t
))
1384 (:bold t
:italic t
)))
1385 "Face used for displaying newsgroups headers."
1386 :group
'message-faces
)
1387 ;; backward-compatibility alias
1388 (put 'message-header-newsgroups-face
'face-alias
'message-header-newsgroups
)
1389 (put 'message-header-newsgroups-face
'obsolete-face
"22.1")
1391 (defface message-header-other
1394 (:foreground
"VioletRed1"))
1397 (:foreground
"steel blue"))
1399 (:bold t
:italic t
)))
1400 "Face used for displaying newsgroups headers."
1401 :group
'message-faces
)
1402 ;; backward-compatibility alias
1403 (put 'message-header-other-face
'face-alias
'message-header-other
)
1404 (put 'message-header-other-face
'obsolete-face
"22.1")
1406 (defface message-header-name
1409 (:foreground
"green"))
1412 (:foreground
"cornflower blue"))
1415 "Face used for displaying header names."
1416 :group
'message-faces
)
1417 ;; backward-compatibility alias
1418 (put 'message-header-name-face
'face-alias
'message-header-name
)
1419 (put 'message-header-name-face
'obsolete-face
"22.1")
1421 (defface message-header-xheader
1424 (:foreground
"DeepSkyBlue1"))
1427 (:foreground
"blue"))
1430 "Face used for displaying X-Header headers."
1431 :group
'message-faces
)
1432 ;; backward-compatibility alias
1433 (put 'message-header-xheader-face
'face-alias
'message-header-xheader
)
1434 (put 'message-header-xheader-face
'obsolete-face
"22.1")
1436 (defface message-separator
1439 (:foreground
"LightSkyBlue1"))
1442 (:foreground
"brown"))
1445 "Face used for displaying the separator."
1446 :group
'message-faces
)
1447 ;; backward-compatibility alias
1448 (put 'message-separator-face
'face-alias
'message-separator
)
1449 (put 'message-separator-face
'obsolete-face
"22.1")
1451 (defface message-cited-text
1454 (:foreground
"LightPink1"))
1457 (:foreground
"red"))
1460 "Face used for displaying cited text names."
1461 :group
'message-faces
)
1462 ;; backward-compatibility alias
1463 (put 'message-cited-text-face
'face-alias
'message-cited-text
)
1464 (put 'message-cited-text-face
'obsolete-face
"22.1")
1466 (defface message-mml
1469 (:foreground
"MediumSpringGreen"))
1472 (:foreground
"ForestGreen"))
1475 "Face used for displaying MML."
1476 :group
'message-faces
)
1477 ;; backward-compatibility alias
1478 (put 'message-mml-face
'face-alias
'message-mml
)
1479 (put 'message-mml-face
'obsolete-face
"22.1")
1481 (defun message-font-lock-make-header-matcher (regexp)
1484 (let ((start (point)))
1487 (goto-char (point-min))
1488 (if (re-search-forward
1489 (concat "^" (regexp-quote mail-header-separator
) "$")
1491 (setq limit
(min limit
(match-beginning 0))))
1493 (and (< start limit
)
1494 (re-search-forward ,regexp limit t
))))))
1495 (if (featurep 'bytecomp
)
1499 (defvar message-font-lock-keywords
1500 (let ((content "[ \t]*\\(.+\\(\n[ \t].*\\)*\\)\n?"))
1501 `((,(message-font-lock-make-header-matcher
1502 (concat "^\\([Tt]o:\\)" content
))
1503 (1 'message-header-name
)
1504 (2 'message-header-to nil t
))
1505 (,(message-font-lock-make-header-matcher
1506 (concat "^\\(^[GBF]?[Cc][Cc]:\\|^[Rr]eply-[Tt]o:\\)" content
))
1507 (1 'message-header-name
)
1508 (2 'message-header-cc nil t
))
1509 (,(message-font-lock-make-header-matcher
1510 (concat "^\\([Ss]ubject:\\)" content
))
1511 (1 'message-header-name
)
1512 (2 'message-header-subject nil t
))
1513 (,(message-font-lock-make-header-matcher
1514 (concat "^\\([Nn]ewsgroups:\\|Followup-[Tt]o:\\)" content
))
1515 (1 'message-header-name
)
1516 (2 'message-header-newsgroups nil t
))
1517 (,(message-font-lock-make-header-matcher
1518 (concat "^\\(X-[A-Za-z0-9-]+:\\|In-Reply-To:\\)" content
))
1519 (1 'message-header-name
)
1520 (2 'message-header-xheader
))
1521 (,(message-font-lock-make-header-matcher
1522 (concat "^\\([A-Z][^: \n\t]+:\\)" content
))
1523 (1 'message-header-name
)
1524 (2 'message-header-other nil t
))
1525 ,@(if (and mail-header-separator
1526 (not (equal mail-header-separator
"")))
1527 `((,(concat "^\\(" (regexp-quote mail-header-separator
) "\\)$")
1528 1 'message-separator
))
1531 (re-search-forward (concat "^\\("
1532 message-cite-prefix-regexp
1535 (0 'message-cited-text
))
1536 ("<#/?\\(multipart\\|part\\|external\\|mml\\|secure\\)[^>]*>"
1538 "Additional expressions to highlight in Message mode.")
1541 ;; XEmacs does it like this. For Emacs, we have to set the
1542 ;; `font-lock-defaults' buffer-local variable.
1543 (put 'message-mode
'font-lock-defaults
'(message-font-lock-keywords t
))
1545 (defvar message-face-alist
1546 '((bold . message-bold-region
)
1547 (underline . underline-region
)
1548 (default .
(lambda (b e
)
1549 (message-unbold-region b e
)
1550 (ununderline-region b e
))))
1551 "Alist of mail and news faces for facemenu.
1552 The cdr of each entry is a function for applying the face to a region.")
1554 (defcustom message-send-hook nil
1555 "Hook run before sending messages.
1556 This hook is run quite early when sending."
1557 :group
'message-various
1558 :options
'(ispell-message)
1559 :link
'(custom-manual "(message)Various Message Variables")
1562 (defcustom message-send-mail-hook nil
1563 "Hook run before sending mail messages.
1564 This hook is run very late -- just before the message is sent as
1566 :group
'message-various
1567 :link
'(custom-manual "(message)Various Message Variables")
1570 (defcustom message-send-news-hook nil
1571 "Hook run before sending news messages.
1572 This hook is run very late -- just before the message is sent as
1574 :group
'message-various
1575 :link
'(custom-manual "(message)Various Message Variables")
1578 (defcustom message-sent-hook nil
1579 "Hook run after sending messages."
1580 :group
'message-various
1583 (defvar message-send-coding-system
'binary
1584 "Coding system to encode outgoing mail.")
1586 (defvar message-draft-coding-system
1587 mm-auto-save-coding-system
1588 "*Coding system to compose mail.
1589 If you'd like to make it possible to share draft files between XEmacs
1590 and Emacs, you may use `iso-2022-7bit' for this value at your own risk.
1591 Note that the coding-system `iso-2022-7bit' isn't suitable to all data.")
1593 (defcustom message-send-mail-partially-limit nil
1594 "The limitation of messages sent as message/partial.
1595 The lower bound of message size in characters, beyond which the message
1596 should be sent in several parts. If it is nil, the size is unlimited."
1598 :group
'message-buffers
1599 :link
'(custom-manual "(message)Mail Variables")
1600 :type
'(choice (const :tag
"unlimited" nil
)
1603 (defcustom message-alternative-emails nil
1604 "*Regexp matching alternative email addresses.
1605 The first address in the To, Cc or From headers of the original
1606 article matching this variable is used as the From field of
1609 This variable has precedence over posting styles and anything that runs
1610 off `message-setup-hook'."
1611 :group
'message-headers
1612 :link
'(custom-manual "(message)Message Headers")
1613 :type
'(choice (const :tag
"Always use primary" nil
)
1616 (defcustom message-hierarchical-addresses nil
1617 "A list of hierarchical mail address definitions.
1619 Inside each entry, the first address is the \"top\" address, and
1620 subsequent addresses are subaddresses; this is used to indicate that
1621 mail sent to the first address will automatically be delivered to the
1622 subaddresses. So if the first address appears in the recipient list
1623 for a message, the subaddresses will be removed (if present) before
1624 the mail is sent. All addresses in this structure should be
1627 :group
'message-headers
1628 :type
'(repeat (repeat string
)))
1630 (defcustom message-mail-user-agent nil
1631 "Like `mail-user-agent'.
1632 Except if it is nil, use Gnus native MUA; if it is t, use
1635 :type
'(radio (const :tag
"Gnus native"
1638 (const :tag
"`mail-user-agent'"
1641 (function-item :tag
"Default Emacs mail"
1643 sendmail-user-agent
)
1644 (function-item :tag
"Emacs interface to MH"
1647 (function :tag
"Other"))
1651 (defcustom message-wide-reply-confirm-recipients nil
1652 "Whether to confirm a wide reply to multiple email recipients.
1653 If this variable is nil, don't ask whether to reply to all recipients.
1654 If this variable is non-nil, pose the question \"Reply to all
1655 recipients?\" before a wide reply to multiple recipients. If the user
1656 answers yes, reply to all recipients as usual. If the user answers
1657 no, only reply back to the author."
1659 :group
'message-headers
1660 :link
'(custom-manual "(message)Wide Reply")
1663 (defcustom message-user-fqdn nil
1664 "*Domain part of Message-Ids."
1666 :group
'message-headers
1667 :link
'(custom-manual "(message)News Headers")
1668 :type
'(radio (const :format
"%v " nil
)
1669 (string :format
"FQDN: %v")))
1671 (defcustom message-use-idna
(and (condition-case nil
(require 'idna
)
1673 (mm-coding-system-p 'utf-8
)
1674 (executable-find idna-program
)
1675 (string= (idna-to-ascii "räksmörgås")
1676 "xn--rksmrgs-5wao1o")
1678 "Whether to encode non-ASCII in domain names into ASCII according to IDNA.
1679 GNU Libidn, and in particular the elisp package \"idna.el\" and
1680 the external program \"idn\", must be installed for this
1681 functionality to work."
1683 :group
'message-headers
1684 :link
'(custom-manual "(message)IDNA")
1685 :type
'(choice (const :tag
"Ask" ask
)
1686 (const :tag
"Never" nil
)
1687 (const :tag
"Always" t
)))
1689 (defcustom message-generate-hashcash
(if (executable-find "hashcash") 'opportunistic
)
1690 "*Whether to generate X-Hashcash: headers.
1691 If t, always generate hashcash headers. If `opportunistic',
1692 only generate hashcash headers if it can be done without the user
1693 waiting (i.e., only asynchronously).
1695 You must have the \"hashcash\" binary installed, see `hashcash-path'."
1697 :group
'message-headers
1698 :link
'(custom-manual "(message)Mail Headers")
1699 :type
'(choice (const :tag
"Always" t
)
1700 (const :tag
"Never" nil
)
1701 (const :tag
"Opportunistic" opportunistic
)))
1703 ;;; Internal variables.
1705 (defvar message-sending-message
"Sending...")
1706 (defvar message-buffer-list nil
)
1707 (defvar message-this-is-news nil
)
1708 (defvar message-this-is-mail nil
)
1709 (defvar message-draft-article nil
)
1710 (defvar message-mime-part nil
)
1711 (defvar message-posting-charset nil
)
1712 (defvar message-inserted-headers nil
)
1713 (defvar message-inhibit-ecomplete nil
)
1715 ;; Byte-compiler warning
1716 (defvar gnus-active-hashtb
)
1717 (defvar gnus-read-active-file
)
1719 ;;; Regexp matching the delimiter of messages in UNIX mail format
1720 ;;; (UNIX From lines), minus the initial ^. It should be a copy
1721 ;;; of rmail.el's rmail-unix-mail-delimiter.
1722 (defvar message-unix-mail-delimiter
1723 (let ((time-zone-regexp
1724 (concat "\\([A-Z]?[A-Z]?[A-Z][A-Z]\\( DST\\)?"
1725 "\\|[-+]?[0-9][0-9][0-9][0-9]"
1731 ;; Many things can happen to an RFC 822 mailbox before it is put into
1732 ;; a `From' line. The leading phrase can be stripped, e.g.
1733 ;; `Joe <@w.x:joe@y.z>' -> `<@w.x:joe@y.z>'. The <> can be stripped, e.g.
1734 ;; `<@x.y:joe@y.z>' -> `@x.y:joe@y.z'. Everything starting with a CRLF
1735 ;; can be removed, e.g.
1736 ;; From: joe@y.z (Joe K
1738 ;; can yield `From joe@y.z (Joe K Fri Mar 22 08:11:15 1996', and
1741 ;; can yield `From Joe User Fri Mar 22 08:11:15 1996'.
1742 ;; The mailbox can be removed or be replaced by white space, e.g.
1743 ;; From: "Joe User"{space}{tab}
1745 ;; can yield `From {space}{tab} Fri Mar 22 08:11:15 1996',
1746 ;; where {space} and {tab} represent the Ascii space and tab characters.
1747 ;; We want to match the results of any of these manglings.
1748 ;; The following regexp rejects names whose first characters are
1749 ;; obviously bogus, but after that anything goes.
1750 "\\([^\0-\b\n-\r\^?].*\\)?"
1752 ;; The time the message was sent.
1753 "\\([^\0-\r \^?]+\\) +" ; day of the week
1754 "\\([^\0-\r \^?]+\\) +" ; month
1755 "\\([0-3]?[0-9]\\) +" ; day of month
1756 "\\([0-2][0-9]:[0-5][0-9]\\(:[0-6][0-9]\\)?\\) *" ; time of day
1758 ;; Perhaps a time zone, specified by an abbreviation, or by a
1763 " \\([0-9][0-9]+\\) *"
1765 ;; On some systems the time zone can appear after the year, too.
1769 "\\(remote from .*\\)?"
1772 "Regexp matching the delimiter of messages in UNIX mail format.")
1774 (defvar message-unsent-separator
1775 (concat "^ *---+ +Unsent message follows +---+ *$\\|"
1776 "^ *---+ +Returned message +---+ *$\\|"
1777 "^Start of returned message$\\|"
1778 "^ *---+ +Original message +---+ *$\\|"
1779 "^ *--+ +begin message +--+ *$\\|"
1780 "^ *---+ +Original message follows +---+ *$\\|"
1781 "^ *---+ +Undelivered message follows +---+ *$\\|"
1782 "^------ This is a copy of the message, including all the headers. ------ *$\\|"
1783 "^|? *---+ +Message text follows: +---+ *|?$")
1784 "A regexp that matches the separator before the text of a failed message.")
1786 (defvar message-field-fillers
1787 '((To message-fill-field-address
)
1788 (Cc message-fill-field-address
)
1789 (From message-fill-field-address
))
1790 "Alist of header names/filler functions.")
1792 (defvar message-header-format-alist
1807 (References . message-shorten-references
)
1809 "Alist used for formatting headers.")
1811 (defvar message-options nil
1812 "Some saved answers when sending message.")
1814 (defvar message-send-mail-real-function nil
1815 "Internal send mail function.")
1817 (defvar message-bogus-system-names
"^localhost\\.\\|\\.local$"
1818 "The regexp of bogus system names.")
1820 (defcustom message-valid-fqdn-regexp
1821 (concat "[a-z0-9][-.a-z0-9]+\\." ;; [hostname.subdomain.]domain.
1823 "\\([a-z][a-z]\\|" ;; two letter country TDLs
1824 "aero\\|arpa\\|bitnet\\|biz\\|bofh\\|"
1825 "cat\\|com\\|coop\\|edu\\|gov\\|"
1826 "info\\|int\\|jobs\\|"
1827 "mil\\|mobi\\|museum\\|name\\|net\\|"
1828 "org\\|pro\\|travel\\|uucp\\)")
1829 ;; http://en.wikipedia.org/wiki/List_of_Internet_top-level_domains
1830 ;; http://en.wikipedia.org/wiki/GTLD
1831 ;; `in the process of being approved': .asia .post .tel .sex
1832 ;; "dead" nato bitnet uucp
1833 "Regular expression that matches a valid FQDN."
1834 ;; see also: gnus-button-valid-fqdn-regexp
1836 :group
'message-headers
1839 (autoload 'gnus-alive-p
"gnus-util")
1840 (autoload 'gnus-delay-article
"gnus-delay")
1841 (autoload 'gnus-extract-address-components
"gnus-util")
1842 (autoload 'gnus-find-method-for-group
"gnus")
1843 (autoload 'gnus-group-decoded-name
"gnus-group")
1844 (autoload 'gnus-group-name-charset
"gnus-group")
1845 (autoload 'gnus-group-name-decode
"gnus-group")
1846 (autoload 'gnus-groups-from-server
"gnus")
1847 (autoload 'gnus-make-local-hook
"gnus-util")
1848 (autoload 'gnus-open-server
"gnus-int")
1849 (autoload 'gnus-output-to-mail
"gnus-util")
1850 (autoload 'gnus-output-to-rmail
"gnus-util")
1851 (autoload 'gnus-request-post
"gnus-int")
1852 (autoload 'gnus-select-frame-set-input-focus
"gnus-util")
1853 (autoload 'gnus-server-string
"gnus")
1854 (autoload 'idna-to-ascii
"idna")
1855 (autoload 'message-setup-toolbar
"messagexmas")
1856 (autoload 'mh-new-draft-name
"mh-comp")
1857 (autoload 'mh-send-letter
"mh-comp")
1858 (autoload 'nndraft-request-associate-buffer
"nndraft")
1859 (autoload 'nndraft-request-expire-articles
"nndraft")
1860 (autoload 'nnvirtual-find-group-art
"nnvirtual")
1861 (autoload 'rmail-dont-reply-to
"mail-utils")
1862 (autoload 'rmail-msg-is-pruned
"rmail")
1863 (autoload 'rmail-output
"rmailout")
1868 ;;; Utility functions.
1871 (defmacro message-y-or-n-p
(question show
&rest text
)
1872 "Ask QUESTION, displaying remaining args in a temporary buffer if SHOW."
1873 `(message-talkative-question 'y-or-n-p
,question
,show
,@text
))
1875 (defmacro message-delete-line
(&optional n
)
1876 "Delete the current line (and the next N lines)."
1877 `(delete-region (progn (beginning-of-line) (point))
1878 (progn (forward-line ,(or n
1)) (point))))
1880 (defun message-mark-active-p ()
1881 "Non-nil means the mark and region are currently active in this buffer."
1884 (defun message-unquote-tokens (elems)
1885 "Remove double quotes (\") from strings in list ELEMS."
1886 (mapcar (lambda (item)
1887 (while (string-match "^\\(.*\\)\"\\(.*\\)$" item
)
1888 (setq item
(concat (match-string 1 item
)
1889 (match-string 2 item
))))
1893 (defun message-tokenize-header (header &optional separator
)
1894 "Split HEADER into a list of header elements.
1895 SEPARATOR is a string of characters to be used as separators. \",\"
1896 is used by default."
1899 (let ((regexp (format "[%s]+" (or separator
",")))
1901 beg quoted elems paren
)
1903 (mm-enable-multibyte)
1904 (setq beg
(point-min))
1906 (goto-char (point-min))
1911 (cond ((and (> (point) beg
)
1913 (and (looking-at regexp
)
1916 (push (buffer-substring beg
(point)) elems
)
1917 (setq beg
(match-end 0)))
1918 ((eq (char-after) ?
\")
1919 (setq quoted
(not quoted
)))
1920 ((and (eq (char-after) ?\
()
1923 ((and (eq (char-after) ?\
))
1926 (nreverse elems
)))))
1928 (autoload 'nnheader-insert-file-contents
"nnheader")
1930 (defun message-mail-file-mbox-p (file)
1931 "Say whether FILE looks like a Unix mbox file."
1932 (when (and (file-exists-p file
)
1933 (file-readable-p file
)
1934 (file-regular-p file
))
1936 (nnheader-insert-file-contents file
)
1937 (goto-char (point-min))
1938 (looking-at message-unix-mail-delimiter
))))
1940 (defun message-fetch-field (header &optional not-all
)
1941 "The same as `mail-fetch-field', only remove all newlines.
1942 The buffer is expected to be narrowed to just the header of the message;
1943 see `message-narrow-to-headers-or-head'."
1944 (let* ((inhibit-point-motion-hooks t
)
1945 (value (mail-fetch-field header nil
(not not-all
))))
1947 (while (string-match "\n[\t ]+" value
)
1948 (setq value
(replace-match " " t t value
)))
1951 (defun message-field-value (header &optional not-all
)
1952 "The same as `message-fetch-field', only narrow to the headers first."
1955 (message-narrow-to-headers-or-head)
1956 (message-fetch-field header not-all
))))
1958 (defun message-narrow-to-field ()
1959 "Narrow the buffer to the header on the current line."
1961 (while (looking-at "[ \t]")
1967 (if (re-search-forward "^[^ \n\t]" nil t
)
1970 (goto-char (point-min)))
1972 (defun message-add-header (&rest headers
)
1973 "Add the HEADERS to the message header, skipping those already present."
1976 (unless (string-match "^\\([^:]+\\):[ \t]*[^ \t]" (car headers
))
1977 (error "Invalid header `%s'" (car headers
)))
1978 (setq hclean
(match-string 1 (car headers
)))
1980 (message-narrow-to-headers)
1981 (unless (re-search-forward (concat "^" (regexp-quote hclean
) ":") nil t
)
1982 (goto-char (point-max))
1983 (if (string-match "\n$" (car headers
))
1984 (insert (car headers
))
1985 (insert (car headers
) ?
\n)))))
1986 (setq headers
(cdr headers
))))
1988 (defmacro message-with-reply-buffer
(&rest forms
)
1989 "Evaluate FORMS in the reply buffer, if it exists."
1990 `(when (and (bufferp message-reply-buffer
)
1991 (buffer-name message-reply-buffer
))
1992 (with-current-buffer message-reply-buffer
1995 (put 'message-with-reply-buffer
'lisp-indent-function
0)
1996 (put 'message-with-reply-buffer
'edebug-form-spec
'(body))
1998 (defun message-fetch-reply-field (header)
1999 "Fetch field HEADER from the message we're replying to."
2000 (message-with-reply-buffer
2002 (mail-narrow-to-head)
2003 (message-fetch-field header
))))
2005 (defun message-strip-list-identifiers (subject)
2006 "Remove list identifiers in `gnus-list-identifiers' from string SUBJECT."
2007 (require 'gnus-sum
) ; for gnus-list-identifiers
2008 (let ((regexp (if (stringp gnus-list-identifiers
)
2009 gnus-list-identifiers
2010 (mapconcat 'identity gnus-list-identifiers
" *\\|"))))
2011 (if (string-match (concat "\\(\\(\\(Re: +\\)?\\(" regexp
2012 " *\\)\\)+\\(Re: +\\)?\\)") subject
)
2013 (concat (substring subject
0 (match-beginning 1))
2014 (or (match-string 3 subject
)
2015 (match-string 5 subject
))
2020 (defun message-strip-subject-re (subject)
2021 "Remove \"Re:\" from subject lines in string SUBJECT."
2022 (if (string-match message-subject-re-regexp subject
)
2023 (substring subject
(match-end 0))
2026 (defcustom message-replacement-char
"."
2027 "Replacement character used instead of unprintable or not decodable chars."
2028 :group
'message-various
2029 :version
"22.1" ;; Gnus 5.10.9
2030 :type
'(choice string
2034 ;; FIXME: We also should call `message-strip-subject-encoded-words'
2035 ;; when forwarding. Probably in `message-make-forward-subject' and
2036 ;; `message-forward-make-body'.
2038 (defun message-strip-subject-encoded-words (subject)
2039 "Fix non-decodable words in SUBJECT."
2040 ;; Cf. `gnus-simplify-subject-fully'.
2041 (let* ((case-fold-search t
)
2042 (replacement-chars (format "[%s%s%s]"
2043 message-replacement-char
2044 message-replacement-char
2045 message-replacement-char
))
2046 (enc-word-re "=\\?\\([^?]+\\)\\?\\([QB]\\)\\?\\([^?]+\\)\\(\\?=\\)")
2051 (goto-char (point-min))
2052 (when (re-search-forward enc-word-re nil t
)
2053 (setq cs-string
(match-string 1)))))
2054 cs-coding q-or-b word-beg word-end
)
2055 (if (or (not have-marker
) ;; No encoded word found...
2056 ;; ... or double encoding was correct:
2057 (and (stringp cs-string
)
2058 (setq cs-string
(downcase cs-string
))
2059 (mm-coding-system-p (intern cs-string
))
2063 Decoded Subject \"%s\"
2064 contains a valid encoded word. Decode again? "
2066 (setq cs-coding
(intern cs-string
))))))
2070 (goto-char (point-min))
2071 (while (re-search-forward enc-word-re nil t
)
2072 (setq cs-string
(downcase (match-string 1))
2073 q-or-b
(match-string 2)
2074 word-beg
(match-beginning 0)
2075 word-end
(match-end 0))
2077 (if (mm-coding-system-p (intern cs-string
))
2078 (setq cs-coding
(intern cs-string
))
2080 ;; No double encoded subject? => bogus charset.
2083 (mm-read-coding-system
2085 Decoded Subject \"%s\"
2086 contains an encoded word. The charset `%s' is unknown or invalid.
2087 Hit RET to replace non-decodable characters with \"%s\" or enter replacement
2089 subject cs-string message-replacement-char
)))
2091 (replace-match (concat "=?" (symbol-name cs-coding
)
2094 (goto-char word-beg
)
2095 (re-search-forward "=\\?\\([^?]+\\)\\?\\([QB]\\)\\?" word-end t
)
2098 (if (string-match "\\`Q\\'" q-or-b
)
2101 (message "Replacing non-decodable characters with \"%s\"."
2102 message-replacement-char
)
2103 (while (re-search-forward "\\(=[A-F0-9][A-F0-9]\\)+"
2105 (replace-match message-replacement-char
)))
2107 (message "Replacing non-decodable characters with \"%s\"."
2109 (re-search-forward "[^?]+" word-end t
)
2110 (replace-match replacement-chars
))
2111 (re-search-forward "\\?=")
2112 (replace-match "")))))
2113 (rfc2047-decode-region (point-min) (point-max))
2116 ;;; Start of functions adopted from `message-utils.el'.
2118 (defun message-strip-subject-trailing-was (subject)
2119 "Remove trailing \"(was: <old subject>)\" from SUBJECT lines.
2120 Leading \"Re: \" is not stripped by this function. Use the function
2121 `message-strip-subject-re' for this."
2122 (let* ((query message-subject-trailing-was-query
)
2127 message-subject-trailing-was-ask-regexp
2128 message-subject-trailing-was-regexp
)
2131 (setq new
(substring subject
0 (match-beginning 0))))
2132 (if (or (not found
) (eq query nil
))
2135 (if (message-y-or-n-p
2136 "Strip `(was: <old subject>)' in subject? " t
2138 "Strip `(was: <old subject>)' in subject "
2139 "and use the new one instead?\n\n"
2140 "Current subject is: \""
2142 "New subject would be: \""
2144 "See the variable `message-subject-trailing-was-query' "
2145 "to get rid of this query."
2150 ;;; Suggested by Jonas Steverud @ www.dtek.chalmers.se/~d4jonas/
2152 (defun message-change-subject (new-subject)
2153 "Ask for NEW-SUBJECT header, append (was: <Old Subject>)."
2156 (read-from-minibuffer "New subject: ")))
2157 (cond ((and (not (or (null new-subject
) ; new subject not empty
2158 (zerop (string-width new-subject
))
2159 (string-match "^[ \t]*$" new-subject
))))
2163 (message-narrow-to-headers)
2164 (message-fetch-field "Subject"))))
2165 (cond ((not old-subject
)
2166 (error "No current subject"))
2169 (regexp-quote new-subject
)
2171 old-subject
)) ; yes, it really is a new subject
2172 ;; delete eventual Re: prefix
2174 (message-strip-subject-re old-subject
))
2175 (message-goto-subject)
2176 (message-delete-line)
2177 (insert (concat "Subject: "
2180 old-subject
")\n")))))))))
2182 (defun message-mark-inserted-region (beg end
&optional verbatim
)
2183 "Mark some region in the current article with enclosing tags.
2184 See `message-mark-insert-begin' and `message-mark-insert-end'.
2185 If VERBATIM, use slrn style verbatim marks (\"#v+\" and \"#v-\")."
2186 (interactive "r\nP")
2188 ;; add to the end of the region first, otherwise end would be invalid
2190 (insert (if verbatim
"#v-\n" message-mark-insert-end
))
2192 (insert (if verbatim
"#v+\n" message-mark-insert-begin
))))
2194 (defun message-mark-insert-file (file &optional verbatim
)
2195 "Insert FILE at point, marking it with enclosing tags.
2196 See `message-mark-insert-begin' and `message-mark-insert-end'.
2197 If VERBATIM, use slrn style verbatim marks (\"#v+\" and \"#v-\")."
2198 (interactive "fFile to insert: \nP")
2199 ;; reverse insertion to get correct result.
2201 (insert (if verbatim
"#v-\n" message-mark-insert-end
))
2203 (insert-file-contents file
)
2205 (insert (if verbatim
"#v+\n" message-mark-insert-begin
))))
2207 (defun message-add-archive-header ()
2208 "Insert \"X-No-Archive: Yes\" in the header and a note in the body.
2209 The note can be customized using `message-archive-note'. When called with a
2210 prefix argument, ask for a text to insert. If you don't want the note in the
2211 body, set `message-archive-note' to nil."
2213 (if current-prefix-arg
2214 (setq message-archive-note
2215 (read-from-minibuffer "Reason for No-Archive: "
2216 (cons message-archive-note
0))))
2218 (if (message-goto-signature)
2219 (re-search-backward message-signature-separator
))
2220 (when message-archive-note
2221 (insert message-archive-note
)
2223 (message-add-header message-archive-header
)
2224 (message-sort-headers)))
2226 (defun message-cross-post-followup-to-header (target-group)
2227 "Mangles FollowUp-To and Newsgroups header to point to TARGET-GROUP.
2228 With prefix-argument just set Follow-Up, don't cross-post."
2230 (list ; Completion based on Gnus
2231 (completing-read "Followup To: "
2232 (if (boundp 'gnus-newsrc-alist
)
2234 nil nil
'("poster" .
0)
2235 (if (boundp 'gnus-group-history
)
2236 'gnus-group-history
))))
2237 (message-remove-header "Follow[Uu]p-[Tt]o" t
)
2238 (message-goto-newsgroups)
2240 ;; if we already did a crosspost before, kill old target
2241 (if (and message-cross-post-old-target
2243 (regexp-quote (concat "," message-cross-post-old-target
))
2246 ;; unless (followup is to poster or user explicitly asked not
2247 ;; to cross-post, or target-group is already in Newsgroups)
2248 ;; add target-group to Newsgroups line.
2250 ;; def: cross-post, req:no
2251 (and message-cross-post-default
(not current-prefix-arg
))
2252 ;; def: no-cross-post, req:yes
2253 (and (not message-cross-post-default
) current-prefix-arg
))
2254 (not (string-match "poster" target-group
))
2255 (not (string-match (regexp-quote target-group
)
2256 (message-fetch-field "Newsgroups"))))
2258 (insert (concat "," target-group
))))
2259 (end-of-line) ; ensure Followup: comes after Newsgroups:
2260 ;; unless new followup would be identical to Newsgroups line
2261 ;; make a new Followup-To line
2262 (if (not (string-match (concat "^[ \t]*"
2265 (message-fetch-field "Newsgroups")))
2266 (insert (concat "\nFollowup-To: " target-group
)))
2267 (setq message-cross-post-old-target target-group
))
2269 (defun message-cross-post-insert-note (target-group cross-post in-old
2271 "Insert a in message body note about a set Followup or Crosspost.
2272 If there have been previous notes, delete them. TARGET-GROUP specifies the
2273 group to Followup-To. When CROSS-POST is t, insert note about
2274 crossposting. IN-OLD specifies whether TARGET-GROUP is a member of
2275 OLD-GROUPS. OLD-GROUPS lists the old-groups the posting would have
2276 been made to before the user asked for a Crosspost."
2277 ;; start scanning body for previous uses
2278 (message-goto-signature)
2279 (let ((head (re-search-backward
2280 (concat "^" mail-header-separator
)
2281 nil t
))) ; just search in body
2282 (message-goto-signature)
2283 (while (re-search-backward
2284 (concat "^" (regexp-quote message-cross-post-note
) ".*")
2286 (message-delete-line))
2287 (message-goto-signature)
2288 (while (re-search-backward
2289 (concat "^" (regexp-quote message-followup-to-note
) ".*")
2291 (message-delete-line))
2293 (if (message-goto-signature)
2294 (re-search-backward message-signature-separator
))
2297 (string-match "^[ \t]*poster[ \t]*$" target-group
))
2298 (insert (concat message-followup-to-note target-group
"\n"))
2299 (insert (concat message-cross-post-note target-group
"\n")))))
2301 (defun message-cross-post-followup-to (target-group)
2302 "Crossposts message and set Followup-To to TARGET-GROUP.
2303 With prefix-argument just set Follow-Up, don't cross-post."
2305 (list ; Completion based on Gnus
2306 (completing-read "Followup To: "
2307 (if (boundp 'gnus-newsrc-alist
)
2309 nil nil
'("poster" .
0)
2310 (if (boundp 'gnus-group-history
)
2311 'gnus-group-history
))))
2312 (cond ((not (or (null target-group
) ; new subject not empty
2313 (zerop (string-width target-group
))
2314 (string-match "^[ \t]*$" target-group
)))
2316 (let* ((old-groups (message-fetch-field "Newsgroups"))
2317 (in-old (string-match
2318 (regexp-quote target-group
)
2319 (or old-groups
""))))
2320 ;; check whether target exactly matches old Newsgroups
2321 (cond ((not old-groups
)
2322 (error "No current newsgroup"))
2326 (regexp-quote target-group
)
2329 ;; yes, Newsgroups line must change
2330 (message-cross-post-followup-to-header target-group
)
2331 ;; insert note whether we do cross-post or followup-to
2332 (funcall message-cross-post-note-function
2334 (if (or (and message-cross-post-default
2335 (not current-prefix-arg
))
2336 (and (not message-cross-post-default
)
2337 current-prefix-arg
)) t
)
2338 in-old old-groups
))))))))
2340 ;;; Reduce To: to Cc: or Bcc: header
2342 (defun message-reduce-to-to-cc ()
2343 "Replace contents of To: header with contents of Cc: or Bcc: header."
2346 (save-restriction (message-narrow-to-headers)
2347 (message-fetch-field "cc")))
2349 (if (and (not cc-content
)
2352 (message-narrow-to-headers)
2353 (message-fetch-field "bcc"))))
2358 (message-delete-line)
2359 (insert (concat "To: " cc-content
"\n"))
2361 (message-narrow-to-headers)
2362 (message-remove-header (if bcc
2366 ;;; End of functions adopted from `message-utils.el'.
2368 (defun message-remove-header (header &optional is-regexp first reverse
)
2369 "Remove HEADER in the narrowed buffer.
2370 If IS-REGEXP, HEADER is a regular expression.
2371 If FIRST, only remove the first instance of the header.
2372 Return the number of headers removed."
2373 (goto-char (point-min))
2374 (let ((regexp (if is-regexp header
(concat "^" (regexp-quote header
) ":")))
2376 (case-fold-search t
)
2378 (while (and (not (eobp))
2381 (not (looking-at regexp
))
2382 (looking-at regexp
))
2389 ;; There might be a continuation header, so we have to search
2390 ;; until we find a new non-continuation line.
2393 (if (re-search-forward "^[^ \t]" nil t
)
2394 (goto-char (match-beginning 0))
2397 (if (re-search-forward "^[^ \t]" nil t
)
2398 (goto-char (match-beginning 0))
2399 (goto-char (point-max)))))
2402 (defun message-remove-first-header (header)
2403 "Remove the first instance of HEADER if there is more than one."
2405 (regexp (concat "^" (regexp-quote header
) ":")))
2407 (goto-char (point-min))
2408 (while (re-search-forward regexp nil t
)
2411 (message-remove-header header nil t
)
2414 (defun message-narrow-to-headers ()
2415 "Narrow the buffer to the head of the message."
2418 (goto-char (point-min))
2419 (if (re-search-forward
2420 (concat "^" (regexp-quote mail-header-separator
) "\n") nil t
)
2423 (goto-char (point-min)))
2425 (defun message-narrow-to-head-1 ()
2426 "Like `message-narrow-to-head'. Don't widen."
2428 (goto-char (point-min))
2429 (if (search-forward "\n\n" nil
1)
2432 (goto-char (point-min)))
2434 ;; FIXME: clarify diffference: message-narrow-to-head,
2435 ;; message-narrow-to-headers-or-head, message-narrow-to-headers
2436 (defun message-narrow-to-head ()
2437 "Narrow the buffer to the head of the message.
2438 Point is left at the beginning of the narrowed-to region."
2440 (message-narrow-to-head-1))
2442 (defun message-narrow-to-headers-or-head ()
2443 "Narrow the buffer to the head of the message."
2446 (goto-char (point-min))
2447 (if (re-search-forward (concat "\\(\n\\)\n\\|^\\("
2448 (regexp-quote mail-header-separator
)
2451 (or (match-end 1) (match-beginning 2))
2453 (goto-char (point-min)))
2455 (defun message-news-p ()
2456 "Say whether the current buffer contains a news message."
2457 (and (not message-this-is-mail
)
2458 (or message-this-is-news
2461 (message-narrow-to-headers)
2462 (and (message-fetch-field "newsgroups")
2463 (not (message-fetch-field "posted-to"))))))))
2465 (defun message-mail-p ()
2466 "Say whether the current buffer contains a mail message."
2467 (and (not message-this-is-news
)
2468 (or message-this-is-mail
2471 (message-narrow-to-headers)
2472 (or (message-fetch-field "to")
2473 (message-fetch-field "cc")
2474 (message-fetch-field "bcc")))))))
2476 (defun message-subscribed-p ()
2477 "Say whether we need to insert a MFT header."
2478 (or message-subscribed-regexps
2479 message-subscribed-addresses
2480 message-subscribed-address-file
2481 message-subscribed-address-functions
))
2483 (defun message-next-header ()
2484 "Go to the beginning of the next header."
2486 (or (eobp) (forward-char 1))
2487 (not (if (re-search-forward "^[^ \t]" nil t
)
2489 (goto-char (point-max)))))
2491 (defun message-sort-headers-1 ()
2492 "Sort the buffer as headers using `message-rank' text props."
2493 (goto-char (point-min))
2496 nil
'message-next-header
2498 (message-next-header)
2502 (or (get-text-property (point) 'message-rank
)
2505 (defun message-sort-headers ()
2506 "Sort the headers of the current message according to `message-header-format-alist'."
2510 (let ((max (1+ (length message-header-format-alist
)))
2512 (message-narrow-to-headers)
2513 (while (re-search-forward "^[^ \n]+:" nil t
)
2515 (match-beginning 0) (1+ (match-beginning 0))
2517 (if (setq rank
(length (memq (assq (intern (buffer-substring
2519 (1- (match-end 0))))
2520 message-header-format-alist
)
2521 message-header-format-alist
)))
2524 (message-sort-headers-1))))
2526 (defun message-kill-address ()
2527 "Kill the address under point."
2529 (let ((start (point)))
2530 (message-skip-to-next-address)
2531 (kill-region start
(point))))
2534 (autoload 'Info-goto-node
"info")
2535 (defvar mml2015-use
)
2537 (defun message-info (&optional arg
)
2538 "Display the Message manual.
2540 Prefixed with one \\[universal-argument], display the Emacs MIME
2541 manual. With two \\[universal-argument]'s, display the EasyPG or
2542 PGG manual, depending on the value of `mml2015-use'."
2544 ;; Don't use `info' because support for `(filename)nodename' is not
2545 ;; available in XEmacs < 21.5.12.
2546 (Info-goto-node (format "(%s)Top"
2550 ((eq arg
4) 'emacs-mime
)
2551 ;; `booleanp' only available in Emacs 22+
2552 ((and (not (memq arg
'(nil t
)))
2566 (defvar message-mode-map nil
)
2568 (unless message-mode-map
2569 (setq message-mode-map
(make-keymap))
2570 (set-keymap-parent message-mode-map text-mode-map
)
2571 (define-key message-mode-map
"\C-c?" 'describe-mode
)
2573 (define-key message-mode-map
"\C-c\C-f\C-t" 'message-goto-to
)
2574 (define-key message-mode-map
"\C-c\C-f\C-o" 'message-goto-from
)
2575 (define-key message-mode-map
"\C-c\C-f\C-b" 'message-goto-bcc
)
2576 (define-key message-mode-map
"\C-c\C-f\C-w" 'message-goto-fcc
)
2577 (define-key message-mode-map
"\C-c\C-f\C-c" 'message-goto-cc
)
2578 (define-key message-mode-map
"\C-c\C-f\C-s" 'message-goto-subject
)
2579 (define-key message-mode-map
"\C-c\C-f\C-r" 'message-goto-reply-to
)
2580 (define-key message-mode-map
"\C-c\C-f\C-n" 'message-goto-newsgroups
)
2581 (define-key message-mode-map
"\C-c\C-f\C-d" 'message-goto-distribution
)
2582 (define-key message-mode-map
"\C-c\C-f\C-f" 'message-goto-followup-to
)
2583 (define-key message-mode-map
"\C-c\C-f\C-m" 'message-goto-mail-followup-to
)
2584 (define-key message-mode-map
"\C-c\C-f\C-k" 'message-goto-keywords
)
2585 (define-key message-mode-map
"\C-c\C-f\C-u" 'message-goto-summary
)
2586 (define-key message-mode-map
"\C-c\C-f\C-i"
2587 'message-insert-or-toggle-importance
)
2588 (define-key message-mode-map
"\C-c\C-f\C-a"
2589 'message-generate-unsubscribed-mail-followup-to
)
2591 ;; modify headers (and insert notes in body)
2592 (define-key message-mode-map
"\C-c\C-fs" 'message-change-subject
)
2594 (define-key message-mode-map
"\C-c\C-fx" 'message-cross-post-followup-to
)
2595 ;; prefix+message-cross-post-followup-to = same w/o cross-post
2596 (define-key message-mode-map
"\C-c\C-ft" 'message-reduce-to-to-cc
)
2597 (define-key message-mode-map
"\C-c\C-fa" 'message-add-archive-header
)
2598 ;; mark inserted text
2599 (define-key message-mode-map
"\C-c\M-m" 'message-mark-inserted-region
)
2600 (define-key message-mode-map
"\C-c\M-f" 'message-mark-insert-file
)
2602 (define-key message-mode-map
"\C-c\C-b" 'message-goto-body
)
2603 (define-key message-mode-map
"\C-c\C-i" 'message-goto-signature
)
2605 (define-key message-mode-map
"\C-c\C-t" 'message-insert-to
)
2606 (define-key message-mode-map
"\C-c\C-fw" 'message-insert-wide-reply
)
2607 (define-key message-mode-map
"\C-c\C-n" 'message-insert-newsgroups
)
2608 (define-key message-mode-map
"\C-c\C-l" 'message-to-list-only
)
2609 (define-key message-mode-map
"\C-c\C-f\C-e" 'message-insert-expires
)
2611 (define-key message-mode-map
"\C-c\C-u" 'message-insert-or-toggle-importance
)
2612 (define-key message-mode-map
"\C-c\M-n"
2613 'message-insert-disposition-notification-to
)
2615 (define-key message-mode-map
"\C-c\C-y" 'message-yank-original
)
2616 (define-key message-mode-map
"\C-c\M-\C-y" 'message-yank-buffer
)
2617 (define-key message-mode-map
"\C-c\C-q" 'message-fill-yanked-message
)
2618 (define-key message-mode-map
"\C-c\C-w" 'message-insert-signature
)
2619 (define-key message-mode-map
"\C-c\M-h" 'message-insert-headers
)
2620 (define-key message-mode-map
"\C-c\C-r" 'message-caesar-buffer-body
)
2621 (define-key message-mode-map
"\C-c\C-o" 'message-sort-headers
)
2622 (define-key message-mode-map
"\C-c\M-r" 'message-rename-buffer
)
2624 (define-key message-mode-map
"\C-c\C-c" 'message-send-and-exit
)
2625 (define-key message-mode-map
"\C-c\C-s" 'message-send
)
2626 (define-key message-mode-map
"\C-c\C-k" 'message-kill-buffer
)
2627 (define-key message-mode-map
"\C-c\C-d" 'message-dont-send
)
2628 (define-key message-mode-map
"\C-c\n" 'gnus-delay-article
)
2630 (define-key message-mode-map
"\C-c\M-k" 'message-kill-address
)
2631 (define-key message-mode-map
"\C-c\C-e" 'message-elide-region
)
2632 (define-key message-mode-map
"\C-c\C-v" 'message-delete-not-region
)
2633 (define-key message-mode-map
"\C-c\C-z" 'message-kill-to-signature
)
2634 (define-key message-mode-map
"\M-\r" 'message-newline-and-reformat
)
2635 (define-key message-mode-map
[remap split-line
] 'message-split-line
)
2637 (define-key message-mode-map
"\C-c\C-a" 'mml-attach-file
)
2639 (define-key message-mode-map
"\C-a" 'message-beginning-of-line
)
2640 (define-key message-mode-map
"\t" 'message-tab
)
2642 (define-key message-mode-map
"\M-n" 'message-display-abbrev
))
2645 message-mode-menu message-mode-map
"Message Menu."
2647 ["Yank Original" message-yank-original message-reply-buffer
]
2648 ["Fill Yanked Message" message-fill-yanked-message t
]
2649 ["Insert Signature" message-insert-signature t
]
2650 ["Caesar (rot13) Message" message-caesar-buffer-body t
]
2651 ["Caesar (rot13) Region" message-caesar-region
(message-mark-active-p)]
2652 ["Elide Region" message-elide-region
2653 :active
(message-mark-active-p)
2654 ,@(if (featurep 'xemacs
) nil
2655 '(:help
"Replace text in region with an ellipsis"))]
2656 ["Delete Outside Region" message-delete-not-region
2657 :active
(message-mark-active-p)
2658 ,@(if (featurep 'xemacs
) nil
2659 '(:help
"Delete all quoted text outside region"))]
2660 ["Kill To Signature" message-kill-to-signature t
]
2661 ["Newline and Reformat" message-newline-and-reformat t
]
2662 ["Rename buffer" message-rename-buffer t
]
2663 ["Spellcheck" ispell-message
2664 ,@(if (featurep 'xemacs
) '(t)
2665 '(:help
"Spellcheck this message"))]
2667 ["Insert Region Marked" message-mark-inserted-region
2668 :active
(message-mark-active-p)
2669 ,@(if (featurep 'xemacs
) nil
2670 '(:help
"Mark region with enclosing tags"))]
2671 ["Insert File Marked..." message-mark-insert-file
2672 ,@(if (featurep 'xemacs
) '(t)
2673 '(:help
"Insert file at point marked with enclosing tags"))]
2675 ["Send Message" message-send-and-exit
2676 ,@(if (featurep 'xemacs
) '(t)
2677 '(:help
"Send this message"))]
2678 ["Postpone Message" message-dont-send
2679 ,@(if (featurep 'xemacs
) '(t)
2680 '(:help
"File this draft message and exit"))]
2681 ["Send at Specific Time..." gnus-delay-article
2682 ,@(if (featurep 'xemacs
) '(t)
2683 '(:help
"Ask, then arrange to send message at that time"))]
2684 ["Kill Message" message-kill-buffer
2685 ,@(if (featurep 'xemacs
) '(t)
2686 '(:help
"Delete this message without sending"))]
2688 ["Message manual" message-info
2689 ,@(if (featurep 'xemacs
) '(t)
2690 '(:help
"Display the Message manual"))]))
2693 message-mode-field-menu message-mode-map
""
2695 ["To" message-goto-to t
]
2696 ["From" message-goto-from t
]
2697 ["Subject" message-goto-subject t
]
2698 ["Change subject..." message-change-subject t
]
2699 ["Cc" message-goto-cc t
]
2700 ["Bcc" message-goto-bcc t
]
2701 ["Fcc" message-goto-fcc t
]
2702 ["Reply-To" message-goto-reply-to t
]
2703 ["Flag As Important" message-insert-importance-high
2704 ,@(if (featurep 'xemacs
) '(t)
2705 '(:help
"Mark this message as important"))]
2706 ["Flag As Unimportant" message-insert-importance-low
2707 ,@(if (featurep 'xemacs
) '(t)
2708 '(:help
"Mark this message as unimportant"))]
2710 message-insert-disposition-notification-to
2711 ,@(if (featurep 'xemacs
) '(t)
2712 '(:help
"Request a receipt notification"))]
2714 ;; (typical) news stuff
2715 ["Summary" message-goto-summary t
]
2716 ["Keywords" message-goto-keywords t
]
2717 ["Newsgroups" message-goto-newsgroups t
]
2718 ["Fetch Newsgroups" message-insert-newsgroups t
]
2719 ["Followup-To" message-goto-followup-to t
]
2720 ;; ["Followup-To (with note in body)" message-cross-post-followup-to t]
2721 ["Crosspost / Followup-To..." message-cross-post-followup-to t
]
2722 ["Distribution" message-goto-distribution t
]
2723 ["Expires" message-insert-expires t
]
2724 ["X-No-Archive" message-add-archive-header t
]
2726 ;; (typical) mailing-lists stuff
2727 ["Fetch To" message-insert-to
2728 ,@(if (featurep 'xemacs
) '(t)
2729 '(:help
"Insert a To header that points to the author."))]
2730 ["Fetch To and Cc" message-insert-wide-reply
2731 ,@(if (featurep 'xemacs
) '(t)
2733 "Insert To and Cc headers as if you were doing a wide reply."))]
2735 ["Send to list only" message-to-list-only t
]
2736 ["Mail-Followup-To" message-goto-mail-followup-to t
]
2737 ["Unsubscribed list post" message-generate-unsubscribed-mail-followup-to
2738 ,@(if (featurep 'xemacs
) '(t)
2739 '(:help
"Insert a reasonable `Mail-Followup-To:' header."))]
2740 ["Reduce To: to Cc:" message-reduce-to-to-cc t
]
2742 ["Sort Headers" message-sort-headers t
]
2743 ["Encode non-ASCII domain names" message-idna-to-ascii-rhs t
]
2744 ;; We hide `message-hidden-headers' by narrowing the buffer.
2745 ["Show Hidden Headers" widen t
]
2746 ["Goto Body" message-goto-body t
]
2747 ["Goto Signature" message-goto-signature t
]))
2749 (defvar message-tool-bar-map nil
)
2751 (defvar facemenu-add-face-function
)
2752 (defvar facemenu-remove-face-function
)
2754 ;;; Forbidden properties
2756 ;; We use `after-change-functions' to keep special text properties
2757 ;; that interfere with the normal function of message mode out of the
2760 (defcustom message-strip-special-text-properties t
2761 "Strip special properties from the message buffer.
2763 Emacs has a number of special text properties which can break message
2764 composing in various ways. If this option is set, message will strip
2765 these properties from the message composition buffer. However, some
2766 packages requires these properties to be present in order to work.
2767 If you use one of these packages, turn this option off, and hope the
2768 message composition doesn't break too bad."
2770 :group
'message-various
2771 :link
'(custom-manual "(message)Various Message Variables")
2774 (defconst message-forbidden-properties
2775 ;; No reason this should be clutter up customize. We make it a
2776 ;; property list (rather than a list of property symbols), to be
2777 ;; directly useful for `remove-text-properties'.
2778 '(field nil read-only nil invisible nil intangible nil
2779 mouse-face nil modification-hooks nil insert-in-front-hooks nil
2780 insert-behind-hooks nil point-entered nil point-left nil
)
2781 ;; Other special properties:
2782 ;; category, face, display: probably doesn't do any harm.
2783 ;; fontified: is used by font-lock.
2784 ;; syntax-table, local-map: I dunno.
2785 ;; We need to add XEmacs names to the list.
2786 "Property list of with properties forbidden in message buffers.
2787 The values of the properties are ignored, only the property names are used.")
2789 (defun message-tamago-not-in-use-p (pos)
2790 "Return t when tamago version 4 is not in use at the cursor position.
2791 Tamago version 4 is a popular input method for writing Japanese text.
2792 It uses the properties `intangible', `invisible', `modification-hooks'
2793 and `read-only' when translating ascii or kana text to kanji text.
2794 These properties are essential to work, so we should never strip them."
2795 (not (and (boundp 'egg-modefull-mode
)
2796 (symbol-value 'egg-modefull-mode
)
2797 (or (memq (get-text-property pos
'intangible
)
2798 '(its-part-1 its-part-2
))
2799 (get-text-property pos
'egg-end
)
2800 (get-text-property pos
'egg-lang
)
2801 (get-text-property pos
'egg-start
)))))
2803 (defsubst message-mail-alias-type-p
(type)
2804 (if (atom message-mail-alias-type
)
2805 (eq message-mail-alias-type type
)
2806 (memq type message-mail-alias-type
)))
2808 (defun message-strip-forbidden-properties (begin end
&optional old-length
)
2809 "Strip forbidden properties between BEGIN and END, ignoring the third arg.
2810 This function is intended to be called from `after-change-functions'.
2811 See also `message-forbidden-properties'."
2812 (when (and (message-mail-alias-type-p 'ecomplete
)
2813 (memq this-command message-self-insert-commands
))
2814 (message-display-abbrev))
2815 (when (and message-strip-special-text-properties
2816 (message-tamago-not-in-use-p begin
))
2817 (let ((buffer-read-only nil
)
2818 (inhibit-read-only t
))
2819 (remove-text-properties begin end message-forbidden-properties
))))
2821 (autoload 'ecomplete-setup
"ecomplete") ;; for Emacs <23.
2824 (define-derived-mode message-mode text-mode
"Message"
2825 "Major mode for editing mail and news to be sent.
2826 Like Text Mode but with these additional commands:\\<message-mode-map>
2827 C-c C-s `message-send' (send the message) C-c C-c `message-send-and-exit'
2828 C-c C-d Postpone sending the message C-c C-k Kill the message
2829 C-c C-f move to a header field (and create it if there isn't):
2830 C-c C-f C-t move to To C-c C-f C-s move to Subject
2831 C-c C-f C-c move to Cc C-c C-f C-b move to Bcc
2832 C-c C-f C-w move to Fcc C-c C-f C-r move to Reply-To
2833 C-c C-f C-u move to Summary C-c C-f C-n move to Newsgroups
2834 C-c C-f C-k move to Keywords C-c C-f C-d move to Distribution
2835 C-c C-f C-o move to From (\"Originator\")
2836 C-c C-f C-f move to Followup-To
2837 C-c C-f C-m move to Mail-Followup-To
2838 C-c C-f C-e move to Expires
2839 C-c C-f C-i cycle through Importance values
2840 C-c C-f s change subject and append \"(was: <Old Subject>)\"
2841 C-c C-f x crossposting with FollowUp-To header and note in body
2842 C-c C-f t replace To: header with contents of Cc: or Bcc:
2843 C-c C-f a Insert X-No-Archive: header and a note in the body
2844 C-c C-t `message-insert-to' (add a To header to a news followup)
2845 C-c C-l `message-to-list-only' (removes all but list address in to/cc)
2846 C-c C-n `message-insert-newsgroups' (add a Newsgroup header to a news reply)
2847 C-c C-b `message-goto-body' (move to beginning of message text).
2848 C-c C-i `message-goto-signature' (move to the beginning of the signature).
2849 C-c C-w `message-insert-signature' (insert `message-signature-file' file).
2850 C-c C-y `message-yank-original' (insert current message, if any).
2851 C-c C-q `message-fill-yanked-message' (fill what was yanked).
2852 C-c C-e `message-elide-region' (elide the text between point and mark).
2853 C-c C-v `message-delete-not-region' (remove the text outside the region).
2854 C-c C-z `message-kill-to-signature' (kill the text up to the signature).
2855 C-c C-r `message-caesar-buffer-body' (rot13 the message body).
2856 C-c C-a `mml-attach-file' (attach a file as MIME).
2857 C-c C-u `message-insert-or-toggle-importance' (insert or cycle importance).
2858 C-c M-n `message-insert-disposition-notification-to' (request receipt).
2859 C-c M-m `message-mark-inserted-region' (mark region with enclosing tags).
2860 C-c M-f `message-mark-insert-file' (insert file marked with enclosing tags).
2861 M-RET `message-newline-and-reformat' (break the line and reformat)."
2862 (setq local-abbrev-table text-mode-abbrev-table
)
2863 (set (make-local-variable 'message-reply-buffer
) nil
)
2864 (set (make-local-variable 'message-inserted-headers
) nil
)
2865 (set (make-local-variable 'message-send-actions
) nil
)
2866 (set (make-local-variable 'message-exit-actions
) nil
)
2867 (set (make-local-variable 'message-kill-actions
) nil
)
2868 (set (make-local-variable 'message-postpone-actions
) nil
)
2869 (set (make-local-variable 'message-draft-article
) nil
)
2870 (setq buffer-offer-save t
)
2871 (set (make-local-variable 'facemenu-add-face-function
)
2873 (let ((face-fun (cdr (assq face message-face-alist
))))
2875 (funcall face-fun
(point) end
)
2876 (error "Face %s not configured for %s mode" face mode-name
)))
2878 (set (make-local-variable 'facemenu-remove-face-function
) t
)
2879 (set (make-local-variable 'message-reply-headers
) nil
)
2880 (make-local-variable 'message-newsreader
)
2881 (make-local-variable 'message-mailer
)
2882 (make-local-variable 'message-post-method
)
2883 (set (make-local-variable 'message-sent-message-via
) nil
)
2884 (set (make-local-variable 'message-checksum
) nil
)
2885 (set (make-local-variable 'message-mime-part
) 0)
2886 (message-setup-fill-variables)
2887 (when message-fill-column
2888 (setq fill-column message-fill-column
)
2889 (turn-on-auto-fill))
2890 ;; Allow using comment commands to add/remove quoting.
2891 ;; (set (make-local-variable 'comment-start) message-yank-prefix)
2892 (when message-yank-prefix
2893 (set (make-local-variable 'comment-start
) message-yank-prefix
)
2894 (set (make-local-variable 'comment-start-skip
)
2895 (concat "^" (regexp-quote message-yank-prefix
) "[ \t]*")))
2896 (if (featurep 'xemacs
)
2897 (message-setup-toolbar)
2898 (set (make-local-variable 'font-lock-defaults
)
2899 '(message-font-lock-keywords t
))
2900 (if (boundp 'tool-bar-map
)
2901 (set (make-local-variable 'tool-bar-map
) (message-make-tool-bar))))
2902 (easy-menu-add message-mode-menu message-mode-map
)
2903 (easy-menu-add message-mode-field-menu message-mode-map
)
2904 (gnus-make-local-hook 'after-change-functions
)
2905 ;; Mmmm... Forbidden properties...
2906 (add-hook 'after-change-functions
'message-strip-forbidden-properties
2908 ;; Allow mail alias things.
2910 ((message-mail-alias-type-p 'abbrev
)
2911 (if (fboundp 'mail-abbrevs-setup
)
2912 (mail-abbrevs-setup)
2913 (if (fboundp 'mail-aliases-setup
) ; warning avoidance
2914 (mail-aliases-setup))))
2915 ((message-mail-alias-type-p 'ecomplete
)
2917 (add-hook 'completion-at-point-functions
'message-completion-function nil t
)
2918 (unless buffer-file-name
2919 (message-set-auto-save-file-name))
2920 (unless (buffer-base-buffer)
2921 ;; Don't enable multibyte on an indirect buffer. Maybe enabling
2922 ;; multibyte is not necessary at all. -- zsh
2923 (mm-enable-multibyte))
2924 (set (make-local-variable 'indent-tabs-mode
) nil
) ;No tabs for indentation.
2927 (defun message-setup-fill-variables ()
2928 "Setup message fill variables."
2929 (set (make-local-variable 'fill-paragraph-function
)
2930 'message-fill-paragraph
)
2931 (make-local-variable 'paragraph-separate
)
2932 (make-local-variable 'paragraph-start
)
2933 (make-local-variable 'adaptive-fill-regexp
)
2934 (unless (boundp 'adaptive-fill-first-line-regexp
)
2935 (setq adaptive-fill-first-line-regexp nil
))
2936 (make-local-variable 'adaptive-fill-first-line-regexp
)
2937 (let ((quote-prefix-regexp
2938 ;; User should change message-cite-prefix-regexp if
2939 ;; message-yank-prefix is set to an abnormal value.
2940 (concat "\\(" message-cite-prefix-regexp
"\\)[ \t]*")))
2941 (setq paragraph-start
2943 (regexp-quote mail-header-separator
) "$\\|"
2944 "[ \t]*$\\|" ; blank lines
2945 "-- $\\|" ; signature delimiter
2946 "---+$\\|" ; delimiters for forwarded messages
2947 page-delimiter
"$\\|" ; spoiler warnings
2948 ".*wrote:$\\|" ; attribution lines
2949 quote-prefix-regexp
"$\\|" ; empty lines in quoted text
2951 "<#!*/?\\(multipart\\|part\\|external\\|mml\\|secure\\)"))
2952 (setq paragraph-separate paragraph-start
)
2953 (setq adaptive-fill-regexp
2954 (concat quote-prefix-regexp
"\\|" adaptive-fill-regexp
))
2955 (setq adaptive-fill-first-line-regexp
2956 (concat quote-prefix-regexp
"\\|"
2957 adaptive-fill-first-line-regexp
)))
2958 (make-local-variable 'auto-fill-inhibit-regexp
)
2959 ;;(setq auto-fill-inhibit-regexp "^[A-Z][^: \n\t]+:")
2960 (setq auto-fill-inhibit-regexp nil
)
2961 (make-local-variable 'normal-auto-fill-function
)
2962 (setq normal-auto-fill-function
'message-do-auto-fill
)
2963 ;; KLUDGE: auto fill might already be turned on in `text-mode-hook'.
2964 ;; In that case, ensure that it uses the right function. The real
2965 ;; solution would be not to use `define-derived-mode', and run
2966 ;; `text-mode-hook' ourself at the end of the mode.
2967 ;; -- Per Abrahamsen <abraham@dina.kvl.dk> Date: 2001-10-19.
2968 ;; This kludge is unneeded in Emacs>=21 since define-derived-mode is
2969 ;; now careful to run parent hooks after the body. --Stef
2970 (when auto-fill-function
2971 (setq auto-fill-function normal-auto-fill-function
)))
2976 ;;; Message mode commands
2979 ;;; Movement commands
2981 (defun message-goto-to ()
2982 "Move point to the To header."
2984 (message-position-on-field "To"))
2986 (defun message-goto-from ()
2987 "Move point to the From header."
2989 (message-position-on-field "From"))
2991 (defun message-goto-subject ()
2992 "Move point to the Subject header."
2994 (message-position-on-field "Subject"))
2996 (defun message-goto-cc ()
2997 "Move point to the Cc header."
2999 (message-position-on-field "Cc" "To"))
3001 (defun message-goto-bcc ()
3002 "Move point to the Bcc header."
3004 (message-position-on-field "Bcc" "Cc" "To"))
3006 (defun message-goto-fcc ()
3007 "Move point to the Fcc header."
3009 (message-position-on-field "Fcc" "To" "Newsgroups"))
3011 (defun message-goto-reply-to ()
3012 "Move point to the Reply-To header."
3014 (message-position-on-field "Reply-To" "Subject"))
3016 (defun message-goto-newsgroups ()
3017 "Move point to the Newsgroups header."
3019 (message-position-on-field "Newsgroups"))
3021 (defun message-goto-distribution ()
3022 "Move point to the Distribution header."
3024 (message-position-on-field "Distribution"))
3026 (defun message-goto-followup-to ()
3027 "Move point to the Followup-To header."
3029 (message-position-on-field "Followup-To" "Newsgroups"))
3031 (defun message-goto-mail-followup-to ()
3032 "Move point to the Mail-Followup-To header."
3034 (message-position-on-field "Mail-Followup-To" "To"))
3036 (defun message-goto-keywords ()
3037 "Move point to the Keywords header."
3039 (message-position-on-field "Keywords" "Subject"))
3041 (defun message-goto-summary ()
3042 "Move point to the Summary header."
3044 (message-position-on-field "Summary" "Subject"))
3047 (defmacro message-called-interactively-p
(kind)
3050 (eval '(called-interactively-p 'any
))
3052 `(called-interactively-p ,kind
))
3054 (wrong-number-of-arguments '(called-interactively-p))
3056 (void-function '(interactive-p)))))
3058 (defun message-goto-body ()
3059 "Move point to the beginning of the message body."
3061 (when (and (message-called-interactively-p 'any
)
3062 (looking-at "[ \t]*\n"))
3064 (goto-char (point-min))
3065 (or (search-forward (concat "\n" mail-header-separator
"\n") nil t
)
3066 (search-forward-regexp "[^:]+:\\([^\n]\\|\n[ \t]\\)+\n\n" nil t
)))
3068 (defun message-in-body-p ()
3069 "Return t if point is in the message body."
3070 (let ((body (save-excursion (message-goto-body))))
3073 (defun message-goto-eoh ()
3074 "Move point to the end of the headers."
3079 (defun message-goto-signature ()
3080 "Move point to the beginning of the message signature.
3081 If there is no signature in the article, go to the end and
3084 (goto-char (point-min))
3085 (if (re-search-forward message-signature-separator nil t
)
3087 (goto-char (point-max))
3090 (defun message-generate-unsubscribed-mail-followup-to (&optional include-cc
)
3091 "Insert a reasonable MFT header in a post to an unsubscribed list.
3092 When making original posts to a mailing list you are not subscribed to,
3093 you have to type in a MFT header by hand. The contents, usually, are
3094 the addresses of the list and your own address. This function inserts
3095 such a header automatically. It fetches the contents of the To: header
3096 in the current mail buffer, and appends the current `user-mail-address'.
3098 If the optional argument INCLUDE-CC is non-nil, the addresses in the
3099 Cc: header are also put into the MFT."
3104 (message-narrow-to-headers)
3105 (message-remove-header "Mail-Followup-To")
3106 (setq cc
(and include-cc
(message-fetch-field "Cc")))
3108 (concat (message-fetch-field "To") "," cc
)
3109 (message-fetch-field "To"))))
3110 (message-goto-mail-followup-to)
3111 (insert (concat tos
", " user-mail-address
))))
3115 (defun message-insert-to (&optional force
)
3116 "Insert a To header that points to the author of the article being replied to.
3117 If the original author requested not to be sent mail, don't insert unless the
3118 prefix FORCE is given."
3120 (let* ((mct (message-fetch-reply-field "mail-copies-to"))
3121 (dont (and mct
(or (equal (downcase mct
) "never")
3122 (equal (downcase mct
) "nobody"))))
3123 (to (or (message-fetch-reply-field "mail-reply-to")
3124 (message-fetch-reply-field "reply-to")
3125 (message-fetch-reply-field "from"))))
3129 "Ignoring the user request not to have copies sent via mail"
3130 "Complying with the user request not to have copies sent via mail")))
3131 (when (and force
(not to
))
3132 (error "No mail address in the article"))
3133 (when (and to
(or force
(not dont
)))
3134 (message-carefully-insert-headers (list (cons 'To to
))))))
3136 (defun message-insert-wide-reply ()
3137 "Insert To and Cc headers as if you were doing a wide reply."
3139 (let ((headers (message-with-reply-buffer
3140 (message-get-reply-headers t
))))
3141 (message-carefully-insert-headers headers
)))
3143 (defcustom message-header-synonyms
3146 "List of lists of header synonyms.
3147 E.g., if this list contains a member list with elements `Cc' and `To',
3148 then `message-carefully-insert-headers' will not insert a `To' header
3149 when the message is already `Cc'ed to the recipient."
3151 :group
'message-headers
3152 :link
'(custom-manual "(message)Message Headers")
3153 :type
'(repeat sexp
))
3155 (defun message-carefully-insert-headers (headers)
3156 "Insert the HEADERS, an alist, into the message buffer.
3157 Does not insert the headers when they are already present there
3158 or in the synonym headers, defined by `message-header-synonyms'."
3159 ;; FIXME: Should compare only the address and not the full name. Comparison
3160 ;; should be done case-folded (and with `string=' rather than
3162 ;; (mail-strip-quoted-names "Foo Bar <foo@bar>, bla@fasel (Bla Fasel)")
3163 (dolist (header headers
)
3164 (let* ((header-name (symbol-name (car header
)))
3165 (new-header (cdr header
))
3166 (synonyms (loop for synonym in message-header-synonyms
3167 when
(memq (car header
) synonym
) return synonym
))
3169 (loop for synonym in synonyms
3170 for old-header
= (mail-fetch-field (symbol-name synonym
))
3171 when
(and old-header
(string-match new-header old-header
))
3174 (message "already have `%s' in `%s'" new-header old-header
)
3175 (when (and (message-position-on-field header-name
)
3176 (setq old-header
(mail-fetch-field header-name
))
3177 (not (string-match "\\` *\\'" old-header
)))
3179 (insert new-header
)))))
3181 (defun message-widen-reply ()
3182 "Widen the reply to include maximum recipients."
3185 (and (bufferp message-reply-buffer
)
3186 (buffer-name message-reply-buffer
)
3187 (with-current-buffer message-reply-buffer
3188 (message-get-reply-headers t
)))))
3191 (message-narrow-to-headers)
3192 (dolist (elem follow-to
)
3193 (message-remove-header (symbol-name (car elem
)))
3194 (goto-char (point-min))
3195 (insert (symbol-name (car elem
)) ": "
3196 (cdr elem
) "\n"))))))
3198 (defun message-insert-newsgroups ()
3199 "Insert the Newsgroups header from the article being replied to."
3201 (when (and (message-position-on-field "Newsgroups")
3202 (mail-fetch-field "newsgroups")
3203 (not (string-match "\\` *\\'" (mail-fetch-field "newsgroups"))))
3205 (insert (or (message-fetch-reply-field "newsgroups") "")))
3209 ;;; Various commands
3211 (defun message-delete-not-region (beg end
)
3212 "Delete everything in the body of the current message outside of the region."
3217 ;; snarf citation prefix, if appropriate
3218 (unless (eq (point) (progn (beginning-of-line) (point)))
3219 (when (looking-at message-cite-prefix-regexp
)
3220 (setq citeprefix
(match-string 0))))
3222 (delete-region (point) (if (not (message-goto-signature))
3228 (delete-region beg
(progn (message-goto-body)
3232 (insert citeprefix
))))
3233 (when (message-goto-signature)
3236 (defun message-kill-to-signature (&optional arg
)
3237 "Kill all text up to the signature.
3238 If a numeric argument or prefix arg is given, leave that number
3239 of lines before the signature intact."
3243 (let ((point (point)))
3244 (narrow-to-region point
(point-max))
3245 (message-goto-signature)
3247 (if (and arg
(numberp arg
))
3248 (forward-line (- -
1 arg
))
3250 (unless (= point
(point))
3251 (kill-region point
(point))
3255 (defun message-newline-and-reformat (&optional arg not-break
)
3256 "Insert four newlines, and then reformat if inside quoted text.
3257 Prefix arg means justify as well."
3258 (interactive (list (if current-prefix-arg
'full
)))
3259 (let (quoted point beg end leading-space bolp fill-paragraph-function
)
3260 (setq point
(point))
3263 (setq bolp
(= beg point
))
3264 ;; Find first line of the paragraph.
3266 (while (and (not (eobp))
3267 (not (looking-at message-cite-prefix-regexp
))
3268 (looking-at paragraph-start
))
3271 (when (looking-at message-cite-prefix-regexp
)
3272 (setq quoted
(match-string 0))
3273 (goto-char (match-end 0))
3274 (looking-at "[ \t]*")
3275 (setq leading-space
(match-string 0)))
3279 (< (- point beg
) (length quoted
)))
3280 ;; break inside the cite prefix.
3286 (while (and (not (eobp))
3287 (not (looking-at paragraph-separate
))
3288 (looking-at message-cite-prefix-regexp
)
3289 (equal quoted
(match-string 0)))
3290 (goto-char (match-end 0))
3291 (looking-at "[ \t]*")
3292 (if (> (length leading-space
) (length (match-string 0)))
3293 (setq leading-space
(match-string 0)))
3297 (while (and (if (bobp) nil
(forward-line -
1) t
)
3298 (not (looking-at paragraph-start
))
3299 (looking-at message-cite-prefix-regexp
)
3300 (equal quoted
(match-string 0)))
3302 (goto-char (match-end 0))
3303 (looking-at "[ \t]*")
3304 (if (> (length leading-space
) (length (match-string 0)))
3305 (setq leading-space
(match-string 0)))))
3306 (while (and (not (eobp))
3307 (not (looking-at paragraph-separate
))
3308 (not (looking-at message-cite-prefix-regexp
)))
3312 (while (and (if (bobp) nil
(forward-line -
1) t
)
3313 (not (looking-at paragraph-start
))
3314 (not (looking-at message-cite-prefix-regexp
)))
3315 (setq beg
(point))))
3318 (narrow-to-region beg end
)
3325 (setq point
(point))
3326 ;; (newline 2) doesn't mark both newline's as hard, so call
3327 ;; newline twice. -jas
3330 (delete-region (point) (re-search-forward "[ \t]*"))
3331 (when (and quoted
(not bolp
))
3332 (insert quoted leading-space
)))
3335 (let* ((adaptive-fill-regexp
3336 (regexp-quote (concat quoted leading-space
)))
3337 (adaptive-fill-first-line-regexp
3338 adaptive-fill-regexp
))
3339 (fill-paragraph arg
))
3340 (fill-paragraph arg
))
3341 (if point
(goto-char point
)))))
3343 (defun message-fill-paragraph (&optional arg
)
3344 "Message specific function to fill a paragraph.
3345 This function is used as the value of `fill-paragraph-function' in
3346 Message buffers and is not meant to be called directly."
3347 (interactive (list (if current-prefix-arg
'full
)))
3348 (if (if (boundp 'filladapt-mode
) filladapt-mode
)
3350 (if (message-point-in-header-p)
3351 (message-fill-field)
3352 (message-newline-and-reformat arg t
))
3355 (defun message-point-in-header-p ()
3356 "Return t if point is in the header."
3358 (not (re-search-backward
3359 (concat "^" (regexp-quote mail-header-separator
) "\n") nil t
))))
3361 (defun message-do-auto-fill ()
3362 "Like `do-auto-fill', but don't fill in message header."
3363 (unless (message-point-in-header-p)
3366 (defun message-insert-signature (&optional force
)
3367 "Insert a signature. See documentation for variable `message-signature'."
3368 (interactive (list 0))
3371 ((and (null message-signature
)
3374 (goto-char (point-max))
3375 (not (re-search-backward message-signature-separator nil t
))))
3376 ((and (null message-signature
)
3379 ((functionp message-signature
)
3380 (funcall message-signature
))
3381 ((listp message-signature
)
3382 (eval message-signature
))
3383 (t message-signature
)))
3386 (cond ((stringp signature
)
3388 ((and (eq t signature
) message-signature-file
)
3389 (setq signature-file
3390 (if (and message-signature-directory
3391 ;; don't actually use the signature directory
3392 ;; if message-signature-file contains a path.
3393 (not (file-name-directory
3394 message-signature-file
)))
3395 (expand-file-name message-signature-file
3396 message-signature-directory
)
3397 message-signature-file
))
3398 (file-exists-p signature-file
))))
3400 (goto-char (point-max))
3401 ;; Insert the signature.
3404 (when message-signature-insert-empty-line
3407 (if (eq signature t
)
3408 (insert-file-contents signature-file
)
3410 (goto-char (point-max))
3411 (or (bolp) (insert "\n")))))
3413 (defun message-insert-importance-high ()
3414 "Insert header to mark message as important."
3418 (message-narrow-to-headers)
3419 (message-remove-header "Importance"))
3421 (insert "Importance: high\n")))
3423 (defun message-insert-importance-low ()
3424 "Insert header to mark message as unimportant."
3428 (message-narrow-to-headers)
3429 (message-remove-header "Importance"))
3431 (insert "Importance: low\n")))
3433 (defun message-insert-or-toggle-importance ()
3434 "Insert a \"Importance: high\" header, or cycle through the header values.
3435 The three allowed values according to RFC 1327 are `high', `normal'
3442 (message-narrow-to-headers)
3443 (when (setq cur
(message-fetch-field "Importance"))
3444 (message-remove-header "Importance")
3445 (setq new
(cond ((string= cur
"high")
3447 ((string= cur
"low")
3452 (insert (format "Importance: %s\n" new
)))))
3454 (defun message-insert-disposition-notification-to ()
3455 "Request a disposition notification (return receipt) to this message.
3456 Note that this should not be used in newsgroups."
3460 (message-narrow-to-headers)
3461 (message-remove-header "Disposition-Notification-To"))
3463 (insert (format "Disposition-Notification-To: %s\n"
3464 (or (message-field-value "Reply-to")
3465 (message-field-value "From")
3466 (message-make-from))))))
3468 (defun message-elide-region (b e
)
3469 "Elide the text in the region.
3470 An ellipsis (from `message-elide-ellipsis') will be inserted where the
3474 (insert message-elide-ellipsis
))
3476 (defvar message-caesar-translation-table nil
)
3478 (defun message-caesar-region (b e
&optional n
)
3479 "Caesar rotate region B to E by N, default 13, for decrypting netnews."
3482 (min (point) (or (mark t
) (point)))
3483 (max (point) (or (mark t
) (point)))
3484 (when current-prefix-arg
3485 (prefix-numeric-value current-prefix-arg
))))
3487 (setq n
(if (numberp n
) (mod n
26) 13)) ;canonize N
3488 (unless (or (zerop n
) ; no action needed for a rot of 0
3489 (= b e
)) ; no region to rotate
3490 ;; We build the table, if necessary.
3491 (when (or (not message-caesar-translation-table
)
3492 (/= (aref message-caesar-translation-table ?a
) (+ ?a n
)))
3493 (setq message-caesar-translation-table
3494 (message-make-caesar-translation-table n
)))
3495 (translate-region b e message-caesar-translation-table
)))
3497 (defun message-make-caesar-translation-table (n)
3498 "Create a rot table with offset N."
3500 (table (make-string 256 0)))
3501 (while (< (incf i
) 256)
3504 (substring table
0 ?A
)
3505 (substring table
(+ ?A n
) (+ ?A n
(- 26 n
)))
3506 (substring table ?A
(+ ?A n
))
3507 (substring table
(+ ?A
26) ?a
)
3508 (substring table
(+ ?a n
) (+ ?a n
(- 26 n
)))
3509 (substring table ?a
(+ ?a n
))
3510 (substring table
(+ ?a
26) 255))))
3512 (defun message-caesar-buffer-body (&optional rotnum wide
)
3513 "Caesar rotate all letters in the current buffer by 13 places.
3514 Used to encode/decode possibly offensive messages (commonly in rec.humor).
3515 With prefix arg, specifies the number of places to rotate each letter forward.
3516 Mail and USENET news headers are not rotated unless WIDE is non-nil."
3517 (interactive (if current-prefix-arg
3518 (list (prefix-numeric-value current-prefix-arg
))
3522 (when (and (not wide
) (message-goto-body))
3523 (narrow-to-region (point) (point-max)))
3524 (message-caesar-region (point-min) (point-max) rotnum
))))
3526 (defun message-pipe-buffer-body (program)
3527 "Pipe the message body in the current buffer through PROGRAM."
3530 (when (message-goto-body)
3531 (narrow-to-region (point) (point-max)))
3532 (shell-command-on-region
3533 (point-min) (point-max) program nil t
))))
3535 (defun message-rename-buffer (&optional enter-string
)
3536 "Rename the *message* buffer to \"*message* RECIPIENT\".
3537 If the function is run with a prefix, it will ask for a new buffer
3538 name, rather than giving an automatic name."
3539 (interactive "Pbuffer name: ")
3542 (goto-char (point-min))
3543 (narrow-to-region (point)
3544 (search-forward mail-header-separator nil
'end
))
3546 (if (message-news-p) (message-fetch-field "Newsgroups")
3547 (message-fetch-field "To"))
3550 (if (string-match "," mail-to
)
3551 (concat (substring mail-to
0 (match-beginning 0)) ", ...")
3553 (name-default (concat "*message* " mail-trimmed-to
))
3554 (name (if enter-string
3555 (read-string "New buffer name: " name-default
)
3557 (rename-buffer name t
)))))
3559 (defun message-fill-yanked-message (&optional justifyp
)
3560 "Fill the paragraphs of a message yanked into this one.
3561 Numeric argument means justify as well."
3564 (goto-char (point-min))
3565 (search-forward (concat "\n" mail-header-separator
"\n") nil t
)
3566 (let ((fill-prefix message-yank-prefix
))
3567 (fill-individual-paragraphs (point) (point-max) justifyp
))))
3569 (defun message-indent-citation (&optional start end yank-only
)
3570 "Modify text just inserted from a message to be cited.
3571 The inserted text should be the region.
3572 When this function returns, the region is again around the modified text.
3574 Normally, indent each nonblank line `message-indentation-spaces' spaces.
3575 However, if `message-yank-prefix' is non-nil, insert that prefix on each line."
3576 (unless start
(setq start
(point)))
3578 ;; Remove unwanted headers.
3579 (when message-ignored-cited-headers
3584 (if (search-forward "\n\n" nil t
)
3587 (message-remove-header message-ignored-cited-headers t
)
3588 (when (= (point-min) (point-max))
3589 (setq all-removed t
))
3590 (goto-char (point-max)))
3594 ;; Delete blank lines at the start of the buffer.
3595 (while (and (point-min)
3598 (message-delete-line))
3599 ;; Delete blank lines at the end of the buffer.
3600 (goto-char (point-max))
3603 (while (and (zerop (forward-line -
1))
3605 (message-delete-line)))
3606 ;; Do the indentation.
3607 (if (null message-yank-prefix
)
3608 (indent-rigidly start
(or end
(mark t
)) message-indentation-spaces
)
3611 (while (< (point) (or end
(mark t
)))
3612 (cond ((looking-at ">")
3613 (insert message-yank-cited-prefix
))
3615 (insert message-yank-empty-prefix
))
3617 (insert message-yank-prefix
)))
3621 (defun message-remove-blank-cited-lines (&optional remove
)
3622 "Remove cited lines containing only blanks.
3623 If REMOVE is non-nil, remove newlines, too.
3625 To use this automatically, you may add this function to
3626 `gnus-message-setup-hook'."
3631 (when (boundp 'message-yank-cited-prefix
)
3632 (concat message-yank-cited-prefix
"\\|"))
3636 (gnus-message 8 "removing `%s'" citexp
)
3639 (while (re-search-forward citexp nil t
)
3640 (replace-match (if remove
"" "\n"))))))
3642 (defvar message-cite-reply-above nil
3643 "If non-nil, start own text above the quote.
3645 Note: Top posting is bad netiquette. Don't use it unless you
3646 really must. You probably want to set variable only for specific
3647 groups, e.g. using `gnus-posting-styles':
3649 (eval (set (make-local-variable 'message-cite-reply-above) t))
3651 This variable has no effect in news postings.")
3653 (defun message-yank-original (&optional arg
)
3654 "Insert the message being replied to, if any.
3655 Puts point before the text and mark after.
3656 Normally indents each nonblank line ARG spaces (default 3). However,
3657 if `message-yank-prefix' is non-nil, insert that prefix on each line.
3659 This function uses `message-cite-function' to do the actual citing.
3661 Just \\[universal-argument] as argument means don't indent, insert no
3662 prefix, and don't delete any headers."
3664 (let ((modified (buffer-modified-p))
3666 (when (and message-reply-buffer
3667 message-cite-function
)
3668 (when message-cite-reply-above
3669 (if (and (not (message-news-p))
3670 (or (eq message-cite-reply-above
'is-evil
)
3672 Top posting is bad netiquette. Please don't top post unless you really must.
3673 Really top post? ")))
3676 (buffer-substring (message-goto-body)
3678 (delete-region (message-goto-body) (point-max)))
3679 (set (make-local-variable 'message-cite-reply-above
) nil
)))
3680 (if (bufferp message-reply-buffer
)
3681 (delete-windows-on message-reply-buffer t
))
3682 (push-mark (save-excursion
3684 ((bufferp message-reply-buffer
)
3685 (insert-buffer-substring message-reply-buffer
))
3686 ((and (consp message-reply-buffer
)
3687 (functionp (car message-reply-buffer
)))
3688 (apply (car message-reply-buffer
)
3689 (cdr message-reply-buffer
))))
3694 (funcall message-cite-function
)
3695 (unless (eq (char-before (mark t
)) ?
\n)
3697 (goto-char (mark t
))
3698 (insert-before-markers ?
\n)
3700 (when message-cite-reply-above
3703 (insert (if (bolp) "\n" "\n\n"))
3704 (message-goto-body))
3705 ;; Add a `message-setup-very-last-hook' here?
3706 ;; Add `gnus-article-highlight-citation' here?
3708 (setq message-checksum
(message-checksum))))))
3710 (defun message-yank-buffer (buffer)
3711 "Insert BUFFER into the current buffer and quote it."
3712 (interactive "bYank buffer: ")
3713 (let ((message-reply-buffer (get-buffer buffer
)))
3714 (save-window-excursion
3715 (message-yank-original))))
3717 (defun message-buffers ()
3718 "Return a list of active message buffers."
3720 (save-current-buffer
3721 (dolist (buffer (buffer-list t
))
3723 (when (and (eq major-mode
'message-mode
)
3724 (null message-sent-message-via
))
3725 (push (buffer-name buffer
) buffers
))))
3726 (nreverse buffers
)))
3728 (defun message-cite-original-1 (strip-signature)
3729 "Cite an original message.
3730 If STRIP-SIGNATURE is non-nil, strips off the signature from the
3733 This function uses `mail-citation-hook' if that is non-nil."
3734 (if (and (boundp 'mail-citation-hook
)
3736 (run-hooks 'mail-citation-hook
)
3737 (let* ((start (point))
3741 (when message-indent-citation-function
3742 (if (listp message-indent-citation-function
)
3743 message-indent-citation-function
3744 (list message-indent-citation-function
))))
3745 ;; This function may be called by `gnus-summary-yank-message' and
3746 ;; may insert a different article from the original. So, we will
3747 ;; modify the value of `message-reply-headers' with that article.
3748 (message-reply-headers
3750 (narrow-to-region start end
)
3751 (message-narrow-to-head-1)
3752 (setq x-no-archive
(message-fetch-field "x-no-archive"))
3754 (or (message-fetch-field "subject") "none")
3755 (or (message-fetch-field "from") "nobody")
3756 (message-fetch-field "date")
3757 (message-fetch-field "message-id" t
)
3758 (message-fetch-field "references")
3760 (mml-quote-region start end
)
3761 (when strip-signature
3765 (when (re-search-backward message-signature-separator start t
)
3766 ;; Also peel off any blank lines before the signature.
3768 (while (looking-at "^[ \t]*$")
3771 (delete-region (point) end
)
3772 (unless (search-backward "\n\n" start t
)
3773 ;; Insert a blank line if it is peeled off.
3776 (mapc 'funcall functions
)
3777 (when message-citation-line-function
3780 (funcall message-citation-line-function
))
3781 (when (and x-no-archive
3782 (not message-cite-articles-with-x-no-archive
)
3783 (string-match "yes" x-no-archive
))
3785 (delete-region (point) (mark t
))
3786 (insert "> [Quoted text removed due to X-No-Archive]\n")
3788 (forward-line -
1)))))
3790 (defun message-cite-original ()
3791 "Cite function in the standard Message manner."
3792 (message-cite-original-1 nil
))
3794 (defvar gnus-extract-address-components
)
3796 (autoload 'format-spec
"format-spec")
3798 (defun message-insert-formatted-citation-line (&optional from date
)
3799 "Function that inserts a formatted citation line.
3801 See `message-citation-line-format'."
3802 ;; The optional args are for testing/debugging. They will disappear later.
3804 ;; (with-temp-buffer
3805 ;; (message-insert-formatted-citation-line
3806 ;; "John Doe <john.doe@example.invalid>"
3809 (when (or message-reply-headers
(and from date
))
3811 (setq from
(mail-header-from message-reply-headers
)))
3812 (let* ((data (condition-case ()
3813 (funcall (if (boundp gnus-extract-address-components
)
3814 gnus-extract-address-components
3815 'mail-extract-address-components
)
3821 (net (car (cdr data
)))
3822 (name-or-net (or (car data
)
3823 (car (cdr data
)) from
))
3827 ;; We need Gnus functionality if the user wants date or time from
3828 ;; the original article:
3829 (when (string-match "%[^fnNFL]" message-citation-line-format
)
3830 (autoload 'gnus-date-get-time
"gnus-util")
3831 (gnus-date-get-time (mail-header-date message-reply-headers
)))))
3834 (when (stringp name
)
3835 ;; Guess first name and last name:
3836 (cond ((string-match
3837 "\\`\\(\\w\\|[-.]\\)+ \\(\\w\\|[-.]\\)+\\'" name
)
3838 (setq fname
(nth 0 (split-string name
"[ \t]+"))
3839 lname
(nth 1 (split-string name
"[ \t]+"))))
3841 "\\`\\(\\w\\|[-.]\\)+, \\(\\w\\|[-.]\\)+\\'" name
)
3842 (setq fname
(nth 1 (split-string name
"[ \t,]+"))
3843 lname
(nth 0 (split-string name
"[ \t,]+"))))
3845 "\\`\\(\\w\\|[-.]\\)+\\'" name
)
3848 ;; The following letters are not used in `format-time-string':
3849 (push ?E lst
) (push "<E>" lst
)
3850 (push ?F lst
) (push fname lst
)
3851 ;; We might want to use "" instead of "<X>" later.
3852 (push ?J lst
) (push "<J>" lst
)
3853 (push ?K lst
) (push "<K>" lst
)
3854 (push ?L lst
) (push lname lst
)
3855 (push ?N lst
) (push name-or-net lst
)
3856 (push ?O lst
) (push "<O>" lst
)
3857 (push ?P lst
) (push "<P>" lst
)
3858 (push ?Q lst
) (push "<Q>" lst
)
3859 (push ?f lst
) (push from lst
)
3860 (push ?i lst
) (push "<i>" lst
)
3861 (push ?n lst
) (push net lst
)
3862 (push ?o lst
) (push "<o>" lst
)
3863 (push ?q lst
) (push "<q>" lst
)
3864 (push ?t lst
) (push "<t>" lst
)
3865 (push ?v lst
) (push "<v>" lst
)
3866 ;; Delegate the rest to `format-time-string':
3868 (when (and (not (memq i lst
))
3873 (push (condition-case nil
3874 (format-time-string (format "%%%c" i
) replydate
)
3875 (error (format ">%c<" i
)))
3879 (spec (apply 'format-spec-make flist
)))
3880 (insert (format-spec message-citation-line-format spec
)))
3883 (defun message-cite-original-without-signature ()
3884 "Cite function in the standard Message manner.
3885 This function strips off the signature from the original message."
3886 (message-cite-original-1 t
))
3888 (defun message-insert-citation-line ()
3889 "Insert a simple citation line."
3890 (when message-reply-headers
3891 (insert (mail-header-from message-reply-headers
) " writes:")
3895 (defun message-position-on-field (header &rest afters
)
3896 (let ((case-fold-search t
))
3899 (goto-char (point-min))
3902 (concat "^" (regexp-quote mail-header-separator
) "$"))
3903 (match-beginning 0)))
3904 (goto-char (point-min))
3905 (if (re-search-forward (concat "^" (regexp-quote header
) ":") nil t
)
3907 (re-search-forward "^[^ \t]" nil
'move
)
3909 (skip-chars-backward "\n")
3912 (not (re-search-forward
3913 (concat "^" (regexp-quote (car afters
)) ":")
3917 (re-search-forward "^[^ \t]" nil
'move
)
3918 (beginning-of-line))
3919 (insert header
": \n")
3923 (defun message-remove-signature ()
3924 "Remove the signature from the text between point and mark.
3925 The text will also be indented the normal way."
3927 (let ((start (point))
3929 (if (not (re-search-forward message-signature-separator
(mark t
) t
))
3930 ;; No signature here, so we just indent the cited text.
3931 (message-indent-citation)
3932 ;; Find the last non-empty line.
3934 (while (looking-at "[ \t]*$")
3937 (setq mark
(set-marker (make-marker) (point)))
3939 (message-indent-citation)
3940 ;; Enable undoing the deletion.
3942 (delete-region mark
(mark t
))
3943 (set-marker mark nil
)))))
3948 ;;; Sending messages
3951 (defun message-send-and-exit (&optional arg
)
3952 "Send message like `message-send', then, if no errors, exit from mail buffer."
3954 (let ((buf (current-buffer))
3955 (actions message-exit-actions
))
3956 (when (and (message-send arg
)
3958 (if message-kill-buffer-on-exit
3961 (when (eq buf
(current-buffer))
3962 (message-bury buf
)))
3963 (message-do-actions actions
)
3966 (defun message-dont-send ()
3967 "Don't send the message you have been editing.
3968 Instead, just auto-save the buffer and then bury it."
3970 (set-buffer-modified-p t
)
3972 (let ((actions message-postpone-actions
))
3973 (message-bury (current-buffer))
3974 (message-do-actions actions
)))
3976 (defun message-kill-buffer ()
3977 "Kill the current buffer."
3979 (when (or (not (buffer-modified-p))
3980 (not message-kill-buffer-query
)
3981 (yes-or-no-p "Message modified; kill anyway? "))
3982 (let ((actions message-kill-actions
)
3983 (draft-article message-draft-article
)
3984 (auto-save-file-name buffer-auto-save-file-name
)
3985 (file-name buffer-file-name
)
3986 (modified (buffer-modified-p)))
3987 (setq buffer-file-name nil
)
3988 (kill-buffer (current-buffer))
3989 (when (and (or (and auto-save-file-name
3990 (file-exists-p auto-save-file-name
))
3992 (file-exists-p file-name
)))
3994 ;; If the message buffer has lived in a dedicated window,
3995 ;; `kill-buffer' has killed the frame. Thus the
3996 ;; `yes-or-no-p' may show up in a lowered frame. Make sure
3997 ;; that the user can see the question by raising the
4000 (yes-or-no-p (format "Remove the backup file%s? "
4001 (if modified
" too" "")))))
4003 (delete-file auto-save-file-name
))
4004 (let ((message-draft-article draft-article
))
4005 (message-disassociate-draft)))
4006 (message-do-actions actions
))))
4008 (defun message-bury (buffer)
4009 "Bury this mail BUFFER."
4010 (let ((newbuf (other-buffer buffer
)))
4011 (bury-buffer buffer
)
4012 (if (and (window-dedicated-p (selected-window))
4013 (not (null (delq (selected-frame) (visible-frame-list)))))
4014 (delete-frame (selected-frame))
4015 (switch-to-buffer newbuf
))))
4017 (defun message-send (&optional arg
)
4018 "Send the message in the current buffer.
4019 If `message-interactive' is non-nil, wait for success indication or
4020 error messages, and inform user.
4021 Otherwise any failure is reported in a message back to the user from
4023 The usage of ARG is defined by the instance that called Message.
4024 It should typically alter the sending method in some way or other."
4026 ;; Make it possible to undo the coming changes.
4028 (let ((inhibit-read-only t
))
4029 (put-text-property (point-min) (point-max) 'read-only nil
))
4030 (message-fix-before-sending)
4031 (run-hooks 'message-send-hook
)
4032 (when message-confirm-send
4033 (or (y-or-n-p "Send message? ")
4035 (message message-sending-message
)
4036 (let ((alist message-send-method-alist
)
4038 elem sent dont-barf-on-no-method
4039 (message-options message-options
))
4040 (message-options-set-recipient)
4042 (setq elem
(pop alist
)))
4043 (when (funcall (cadr elem
))
4044 (when (and (or (not (memq (car elem
)
4045 message-sent-message-via
))
4046 (message-fetch-field "supersedes")
4047 (if (or (message-gnksa-enable-p 'multiple-copies
)
4048 (not (eq (car elem
) 'news
)))
4051 "Already sent message via %s; resend? "
4053 (error "Denied posting -- multiple copies")))
4054 (setq success
(funcall (caddr elem
) arg
)))
4058 (let ((fcc (message-fetch-field "Fcc"))
4059 (gcc (message-fetch-field "Gcc")))
4061 (or (eq message-allow-no-recipients
'always
)
4062 (and (not (eq message-allow-no-recipients
'never
))
4063 (setq dont-barf-on-no-method
4065 (format "No receiver, perform %s anyway? "
4066 (cond ((and fcc gcc
) "Fcc and Gcc")
4069 (error "No methods specified to send by"))
4070 (when (or dont-barf-on-no-method
4074 (run-hooks 'message-sent-hook
))
4075 (message "Sending...done")
4076 ;; Do ecomplete address snarfing.
4077 (when (and (message-mail-alias-type-p 'ecomplete
)
4078 (not message-inhibit-ecomplete
))
4079 (message-put-addresses-in-ecomplete))
4080 ;; Mark the buffer as unmodified and delete auto-save.
4081 (set-buffer-modified-p nil
)
4082 (delete-auto-save-file-if-necessary t
)
4083 (message-disassociate-draft)
4084 ;; Delete other mail buffers and stuff.
4085 (message-do-send-housekeeping)
4086 (message-do-actions message-send-actions
)
4090 (defun message-send-via-mail (arg)
4091 "Send the current message via mail."
4092 (message-send-mail arg
))
4094 (defun message-send-via-news (arg)
4095 "Send the current message via news."
4096 (funcall message-send-news-function arg
))
4098 (defmacro message-check
(type &rest forms
)
4099 "Eval FORMS if TYPE is to be checked."
4100 `(or (message-check-element ,type
)
4104 (put 'message-check
'lisp-indent-function
1)
4105 (put 'message-check
'edebug-form-spec
'(form body
))
4107 (defun message-text-with-property (prop &optional start end reverse
)
4108 "Return a list of start and end positions where the text has PROP.
4109 START and END bound the search, they default to `point-min' and
4110 `point-max' respectively. If REVERSE is non-nil, find text which does
4113 (setq start
(point-min)))
4115 (setq end
(point-max)))
4119 (setq start
(text-property-any start end prop nil
)))
4120 (setq next
(next-single-property-change start prop nil end
))
4121 (push (cons start
(or next end
)) regions
)
4124 (or (get-text-property start prop
)
4125 (and (setq start
(next-single-property-change
4126 start prop nil end
))
4127 (get-text-property start prop
))))
4128 (setq next
(text-property-any start end prop nil
))
4129 (push (cons start
(or next end
)) regions
)
4131 (nreverse regions
)))
4133 (defcustom message-bogus-addresses
4134 ;; '("noreply" "nospam" "invalid")
4135 '("noreply" "nospam" "invalid" "@@" "[^[:ascii:]].*@" "[ \t]")
4136 "List of regexps of potentially bogus mail addresses.
4137 See `message-check-recipients' how to setup checking.
4139 This list should make it possible to catch typos or warn about
4140 spam-trap addresses. It doesn't aim to verify strict RFC
4142 :version
"23.1" ;; No Gnus
4143 :group
'message-headers
4145 (const :tag
"None" nil
)
4151 (const :tag
"duplicate @" "@@")
4152 (const :tag
"non-ascii local part" "[^[:ascii:]].*@")
4153 ;; Already caught by `message-valid-fqdn-regexp'
4154 ;; (const :tag "`_' in domain part" "@.*_")
4155 (const :tag
"whitespace" "[ \t]"))
4160 (defun message-fix-before-sending ()
4161 "Do various things to make the message nice before sending it."
4162 ;; Make sure there's a newline at the end of the message.
4163 (goto-char (point-max))
4166 ;; Make the hidden headers visible.
4168 ;; Sort headers before sending the message.
4169 (message-sort-headers)
4170 ;; Make invisible text visible.
4171 ;; It doesn't seem as if this is useful, since the invisible property
4172 ;; is clobbered by an after-change hook anyhow.
4173 (message-check 'invisible-text
4174 (let ((regions (message-text-with-property 'invisible
))
4178 (setq from
(caar regions
)
4180 regions
(cdr regions
))
4181 (put-text-property from to
'invisible nil
)
4182 (message-overlay-put (message-make-overlay from to
)
4184 (unless (yes-or-no-p
4185 "Invisible text found and made visible; continue sending? ")
4186 (error "Invisible text found and made visible")))))
4187 (message-check 'illegible-text
4188 (let (char found choice
)
4191 (skip-chars-forward mm-7bit-chars
)
4192 (when (get-text-property (point) 'no-illegible-text
)
4193 ;; There is a signed or encrypted raw message part
4194 ;; that is considered to be safe.
4195 (goto-char (or (next-single-property-change
4196 (point) 'no-illegible-text
)
4198 (setq char
(char-after)))
4199 (when (or (< (mm-char-int char
) 128)
4200 (and (mm-multibyte-p)
4201 (memq (char-charset char
)
4202 '(eight-bit-control eight-bit-graphic
4203 ;; Emacs 23, Bug#1770:
4206 (not (get-text-property
4207 (point) 'untranslated-utf-8
))))
4208 (message-overlay-put (message-make-overlay (point) (1+ (point)))
4214 (gnus-multiple-choice
4215 "Non-printable characters found. Continue sending?"
4216 `((?d
"Remove non-printable characters and send")
4218 "Replace non-printable characters with \"%s\" and send"
4219 message-replacement-char
))
4220 (?s
"Send as is without removing anything")
4221 (?e
"Continue editing"))))
4223 (error "Non-printable characters"))
4225 (skip-chars-forward mm-7bit-chars
)
4227 (when (let ((char (char-after)))
4228 (or (< (mm-char-int char
) 128)
4229 (and (mm-multibyte-p)
4230 ;; FIXME: Wrong for Emacs 23 (unicode) and for
4231 ;; things like undecodable utf-8 (in Emacs 21?).
4232 ;; Should at least use find-coding-systems-region.
4234 (memq (char-charset char
)
4235 '(eight-bit-control eight-bit-graphic
4236 ;; Emacs 23, Bug#1770:
4239 (not (get-text-property
4240 (point) 'untranslated-utf-8
)))))
4242 (message-kill-all-overlays)
4244 (when (eq choice ?r
)
4245 (insert message-replacement-char
))))
4247 (skip-chars-forward mm-7bit-chars
)))))
4248 (message-check 'bogus-recipient
4249 ;; Warn before sending a mail to an invalid address.
4250 (message-check-recipients)))
4252 (defun message-bogus-recipient-p (recipients)
4253 "Check if a mail address in RECIPIENTS looks bogus.
4255 RECIPIENTS is a mail header. Return a list of potentially bogus
4256 addresses. If none is found, return nil.
4258 An address might be bogus if the domain part is not fully
4259 qualified, see `message-valid-fqdn-regexp', or if there's a
4260 matching entry in `message-bogus-addresses'."
4261 ;; FIXME: How about "foo@subdomain", when the MTA adds ".domain.tld"?
4263 (mapc (lambda (address)
4264 (setq address
(or (cadr address
) ""))
4266 (or (string= "" address
)
4269 (not (string-match "@" address
))
4272 message-valid-fqdn-regexp
"\\)\\'") address
)))
4273 (and message-bogus-addresses
4275 (if (listp message-bogus-addresses
)
4276 (mapconcat 'identity
4277 message-bogus-addresses
4279 message-bogus-addresses
)))
4280 (string-match re address
))))
4281 (push address found
)))
4283 (mail-extract-address-components recipients t
))
4286 (defun message-check-recipients ()
4287 "Warn before composing or sending a mail to an invalid address.
4289 This function could be useful in `message-setup-hook'."
4292 (message-narrow-to-headers)
4293 (dolist (hdr '("To" "Cc" "Bcc"))
4294 (let ((addr (message-fetch-field hdr
)))
4295 (when (stringp addr
)
4296 (dolist (bog (message-bogus-recipient-p addr
))
4300 "Address `%s' might be bogus. Continue? " bog
)))
4301 (error "Bogus address"))))))))
4303 (custom-add-option 'message-setup-hook
'message-check-recipients
)
4305 (defun message-add-action (action &rest types
)
4306 "Add ACTION to be performed when doing an exit of type TYPES."
4308 (add-to-list (intern (format "message-%s-actions" (pop types
)))
4311 (defun message-delete-action (action &rest types
)
4312 "Delete ACTION from lists of actions performed when doing an exit of type TYPES."
4315 (set (setq var
(intern (format "message-%s-actions" (pop types
))))
4316 (delq action
(symbol-value var
))))))
4318 (defun message-do-actions (actions)
4319 "Perform all actions in ACTIONS."
4320 ;; Now perform actions on successful sending.
4321 (dolist (action actions
)
4324 ;; A simple function.
4327 ;; Something to be evaled.
4331 (defun message-send-mail-partially ()
4332 "Send mail as message/partial."
4333 ;; replace the header delimiter with a blank line
4334 (goto-char (point-min))
4336 (concat "^" (regexp-quote mail-header-separator
) "\n"))
4337 (replace-match "\n")
4338 (run-hooks 'message-send-mail-hook
)
4339 (let ((p (goto-char (point-min)))
4340 (tembuf (message-generate-new-buffer-clone-locals " message temp"))
4341 (curbuf (current-buffer))
4342 (id (message-make-message-id)) (n 1)
4343 plist total header required-mail-headers
)
4345 (if (< (point-max) (+ p message-send-mail-partially-limit
))
4346 (goto-char (point-max))
4347 (goto-char (+ p message-send-mail-partially-limit
))
4349 (if (<= (point) p
) (forward-line 1))) ;; In case of bad message.
4352 (setq total
(length plist
))
4353 (push (point-max) plist
)
4354 (setq plist
(nreverse plist
))
4357 (setq p
(pop plist
))
4360 (copy-to-buffer tembuf p
(car plist
))
4362 (goto-char (point-min))
4365 (goto-char (point-min))
4366 (narrow-to-region (point) (point))
4369 (setq header
(buffer-substring (point-min) (point)))
4370 (goto-char (point-min))
4371 (narrow-to-region (point) (point))
4373 (message-remove-header "Mime-Version")
4374 (message-remove-header "Content-Type")
4375 (message-remove-header "Content-Transfer-Encoding")
4376 (message-remove-header "Message-ID")
4377 (message-remove-header "Lines")
4378 (goto-char (point-max))
4379 (insert "Mime-Version: 1.0\n")
4380 (setq header
(buffer-string)))
4381 (goto-char (point-max))
4382 (insert (format "Content-Type: message/partial; id=\"%s\"; number=%d; total=%d\n\n"
4385 (let ((mail-header-separator ""))
4386 (when (memq 'Message-ID message-required-mail-headers
)
4387 (insert "Message-ID: " (message-make-message-id) "\n"))
4388 (when (memq 'Lines message-required-mail-headers
)
4389 (insert "Lines: " (message-make-lines) "\n"))
4390 (message-goto-subject)
4392 (insert (format " (%d/%d)" n total
))
4394 (funcall (or message-send-mail-real-function
4395 message-send-mail-function
)))
4397 (setq p
(pop plist
))
4399 (kill-buffer tembuf
))))
4401 (declare-function hashcash-wait-async
"hashcash" (&optional buffer
))
4403 (defun message-send-mail (&optional arg
)
4404 (require 'mail-utils
)
4405 (let* ((tembuf (message-generate-new-buffer-clone-locals " message temp"))
4406 (case-fold-search nil
)
4407 (news (message-news-p))
4408 (mailbuf (current-buffer))
4409 (message-this-is-mail t
)
4410 ;; gnus-setup-posting-charset is autoloaded in mml.el (FIXME
4411 ;; maybe it should not be), which this file requires. Hence
4412 ;; the fboundp test is always true. Loading it from gnus-msg
4413 ;; loads many Gnus files (Bug#5642). If
4414 ;; gnus-group-posting-charset-alist hasn't been customized,
4415 ;; this is just going to return nil anyway. FIXME it would
4416 ;; be good to improve this further, because even if g-g-p-c-a
4417 ;; has been customized, that is likely to just be for news.
4418 ;; Eg either move the definition from gnus-msg, or separate out
4419 ;; the mail and news parts.
4420 (message-posting-charset
4421 (if (and (fboundp 'gnus-setup-posting-charset
)
4422 (boundp 'gnus-group-posting-charset-alist
))
4423 (gnus-setup-posting-charset nil
)
4424 message-posting-charset
))
4425 (headers message-required-mail-headers
))
4426 (when (and message-generate-hashcash
4427 (not (eq message-generate-hashcash
'opportunistic
)))
4428 (message "Generating hashcash...")
4430 ;; Wait for calculations already started to finish...
4431 (hashcash-wait-async)
4432 ;; ...and do calculations not already done. mail-add-payment
4433 ;; will leave existing X-Hashcash headers alone.
4435 (message "Generating hashcash...done"))
4437 (message-narrow-to-headers)
4438 ;; Generate the Mail-Followup-To header if the header is not there...
4439 (if (and (message-subscribed-p)
4440 (not (mail-fetch-field "mail-followup-to")))
4443 (cons "Mail-Followup-To" (message-make-mail-followup-to))
4444 message-required-mail-headers
))
4445 ;; otherwise, delete the MFT header if the field is empty
4446 (when (equal "" (mail-fetch-field "mail-followup-to"))
4447 (message-remove-header "^Mail-Followup-To:")))
4448 ;; Insert some headers.
4449 (let ((message-deletable-headers
4450 (if news nil message-deletable-headers
)))
4451 (message-generate-headers headers
))
4452 ;; Check continuation headers.
4453 (message-check 'continuation-headers
4454 (goto-char (point-min))
4455 (while (re-search-forward "^[^ \t\n][^ \t\n:]*[ \t\n]" nil t
)
4456 (goto-char (match-beginning 0))
4457 (if (y-or-n-p "Fix continuation lines? ")
4460 (unless (y-or-n-p "Send anyway? ")
4461 (error "Failed to send the message")))))
4462 ;; Let the user do all of the above.
4463 (run-hooks 'message-header-hook
))
4465 (with-current-buffer tembuf
4467 ;; Avoid copying text props (except hard newlines).
4468 (insert (with-current-buffer mailbuf
4469 (mml-buffer-substring-no-properties-except-hard-newlines
4470 (point-min) (point-max))))
4471 ;; Remove some headers.
4472 (message-encode-message-body)
4474 (message-narrow-to-headers)
4475 ;; We (re)generate the Lines header.
4476 (when (memq 'Lines message-required-mail-headers
)
4477 (message-generate-headers '(Lines)))
4478 ;; Remove some headers.
4479 (message-remove-header message-ignored-mail-headers t
)
4480 (let ((mail-parse-charset message-default-charset
))
4481 (mail-encode-encoded-word-buffer)))
4482 (goto-char (point-max))
4483 ;; require one newline at the end.
4484 (or (= (preceding-char) ?
\n)
4486 (message-cleanup-headers)
4487 ;; FIXME: we're inserting the courtesy copy after encoding.
4488 ;; This is wrong if the courtesy copy string contains
4489 ;; non-ASCII characters. -- jh
4492 (message-narrow-to-headers)
4494 (not (message-fetch-field "List-Post"))
4495 (not (message-fetch-field "List-ID"))
4496 (or (message-fetch-field "cc")
4497 (message-fetch-field "bcc")
4498 (message-fetch-field "to"))
4499 (let ((content-type (message-fetch-field
4504 (string= "text/plain"
4506 (mail-header-parse-content-type
4510 (message-fetch-field
4511 "content-transfer-encoding")))))))
4512 (message-insert-courtesy-copy
4513 (with-current-buffer mailbuf
4514 message-courtesy-message
)))
4515 ;; Let's make sure we encoded all the body.
4516 (assert (save-excursion
4517 (goto-char (point-min))
4518 (not (re-search-forward "[^\000-\377]" nil t
))))
4519 (mm-disable-multibyte)
4520 (if (or (not message-send-mail-partially-limit
)
4521 (< (buffer-size) message-send-mail-partially-limit
)
4522 (not (message-y-or-n-p
4523 "The message size is too large, split? "
4527 (/ (buffer-size) 1000) "KB, is too large.
4529 Some mail gateways (MTA's) bounce large messages. To avoid the
4530 problem, answer `y', and the message will be split into several
4531 smaller pieces, the size of each is about "
4532 (/ message-send-mail-partially-limit
1000)
4536 However, some mail readers (MUA's) can't read split messages, i.e.,
4537 mails in message/partially format. Answer `n', and the message will be
4540 The size limit is controlled by `message-send-mail-partially-limit'.
4541 If you always want Gnus to send messages in one piece, set
4542 `message-send-mail-partially-limit' to nil.
4545 (message "Sending via mail...")
4546 (funcall (or message-send-mail-real-function
4547 message-send-mail-function
)))
4548 (message-send-mail-partially)))
4549 (kill-buffer tembuf
))
4550 (set-buffer mailbuf
)
4551 (push 'mail message-sent-message-via
)))
4553 (defun message-send-mail-with-sendmail ()
4554 "Send off the prepared buffer with sendmail."
4556 (let ((errbuf (if message-interactive
4557 (message-generate-new-buffer-clone-locals
4560 resend-to-addresses delimline
)
4563 (let ((case-fold-search t
))
4565 (message-narrow-to-headers)
4566 (setq resend-to-addresses
(message-fetch-field "resent-to")))
4567 ;; Change header-delimiter to be what sendmail expects.
4568 (goto-char (point-min))
4570 (concat "^" (regexp-quote mail-header-separator
) "\n"))
4571 (replace-match "\n")
4573 (setq delimline
(point-marker))
4574 (run-hooks 'message-send-mail-hook
)
4575 ;; Insert an extra newline if we need it to work around
4576 ;; Sun's bug that swallows newlines.
4577 (goto-char (1+ delimline
))
4578 (when (eval message-mailer-swallows-blank-line
)
4580 (when message-interactive
4581 (with-current-buffer errbuf
4583 (let* ((default-directory "/")
4584 (coding-system-for-write message-send-coding-system
)
4586 'call-process-region
4588 (list (point-min) (point-max)
4589 (cond ((boundp 'sendmail-program
)
4591 ((file-exists-p "/usr/sbin/sendmail")
4592 "/usr/sbin/sendmail")
4593 ((file-exists-p "/usr/lib/sendmail")
4594 "/usr/lib/sendmail")
4595 ((file-exists-p "/usr/ucblib/sendmail")
4596 "/usr/ucblib/sendmail")
4598 nil errbuf nil
"-oi")
4599 message-sendmail-extra-arguments
4600 ;; Always specify who from,
4601 ;; since some systems have broken sendmails.
4602 ;; But some systems are more broken with -f, so
4603 ;; we'll let users override this.
4604 (and (null message-sendmail-f-is-evil
)
4605 (list "-f" (message-sendmail-envelope-from)))
4606 ;; These mean "report errors by mail"
4607 ;; and "deliver in background".
4608 (if (null message-interactive
) '("-oem" "-odb"))
4609 ;; Get the addresses from the message
4610 ;; unless this is a resend.
4611 ;; We must not do that for a resend
4612 ;; because we would find the original addresses.
4613 ;; For a resend, include the specific addresses.
4614 (if resend-to-addresses
4615 (list resend-to-addresses
)
4617 (unless (or (null cpr
) (and (numberp cpr
) (zerop cpr
)))
4618 (if errbuf
(pop-to-buffer errbuf
))
4619 (error "Sending...failed with exit value %d" cpr
)))
4620 (when message-interactive
4621 (with-current-buffer errbuf
4622 (goto-char (point-min))
4623 (while (re-search-forward "\n+ *" nil t
)
4624 (replace-match "; "))
4625 (if (not (zerop (buffer-size)))
4626 (error "Sending...failed to %s"
4627 (buffer-string))))))
4628 (when (bufferp errbuf
)
4629 (kill-buffer errbuf
)))))
4631 (defun message-send-mail-with-qmail ()
4632 "Pass the prepared message buffer to qmail-inject.
4633 Refer to the documentation for the variable `message-send-mail-function'
4634 to find out how to use this."
4635 ;; replace the header delimiter with a blank line
4636 (goto-char (point-min))
4638 (concat "^" (regexp-quote mail-header-separator
) "\n"))
4639 (replace-match "\n")
4640 (run-hooks 'message-send-mail-hook
)
4643 (let ((coding-system-for-write message-send-coding-system
))
4645 'call-process-region
(point-min) (point-max)
4646 message-qmail-inject-program nil nil nil
4647 ;; qmail-inject's default behavior is to look for addresses on the
4648 ;; command line; if there're none, it scans the headers.
4649 ;; yes, it does The Right Thing w.r.t. Resent-To and it's kin.
4651 ;; in general, ALL of qmail-inject's defaults are perfect for simply
4652 ;; reading a formatted (i. e., at least a To: or Resent-To header)
4653 ;; message from stdin.
4655 ;; qmail also has the advantage of not having been raped by
4656 ;; various vendors, so we don't have to allow for that, either --
4657 ;; compare this with message-send-mail-with-sendmail and weep
4658 ;; for sendmail's lost innocence.
4660 ;; all this is way cool coz it lets us keep the arguments entirely
4661 ;; free for -inject-arguments -- a big win for the user and for us
4662 ;; since we don't have to play that double-guessing game and the user
4663 ;; gets full control (no gestapo'ish -f's, for instance). --sj
4664 (if (functionp message-qmail-inject-args
)
4665 (funcall message-qmail-inject-args
)
4666 message-qmail-inject-args
)))
4667 ;; qmail-inject doesn't say anything on it's stdout/stderr,
4668 ;; we have to look at the retval instead
4670 (100 (error "qmail-inject reported permanent failure"))
4671 (111 (error "qmail-inject reported transient failure"))
4672 ;; should never happen
4673 (t (error "qmail-inject reported unknown failure"))))
4675 (defun message-send-mail-with-mh ()
4676 "Send the prepared message buffer with mh."
4677 (let ((mh-previous-window-config nil
)
4678 (name (mh-new-draft-name)))
4679 (setq buffer-file-name name
)
4680 ;; MH wants to generate these headers itself.
4681 (when message-mh-deletable-headers
4682 (let ((headers message-mh-deletable-headers
))
4684 (goto-char (point-min))
4685 (and (re-search-forward
4686 (concat "^" (symbol-name (car headers
)) ": *") nil t
)
4687 (message-delete-line))
4689 (run-hooks 'message-send-mail-hook
)
4690 ;; Pass it on to mh.
4693 (defun message-smtpmail-send-it ()
4694 "Send the prepared message buffer with `smtpmail-send-it'.
4695 The only difference from `smtpmail-send-it' is that this command
4696 evaluates `message-send-mail-hook' just before sending a message.
4697 It is useful if your ISP requires the POP-before-SMTP
4698 authentication. See the Gnus manual for details."
4699 (run-hooks 'message-send-mail-hook
)
4702 (defun message-send-mail-with-mailclient ()
4703 "Send the prepared message buffer with `mailclient-send-it'.
4704 The only difference from `mailclient-send-it' is that this
4705 command evaluates `message-send-mail-hook' just before sending a message."
4706 (run-hooks 'message-send-mail-hook
)
4707 (mailclient-send-it))
4709 (defun message-canlock-generate ()
4710 "Return a string that is non-trivial to guess.
4711 Do not use this for anything important, it is cryptographically weak."
4713 (let (sha1-maximum-internal-length)
4714 (sha1 (concat (message-unique-id)
4715 (format "%x%x%x" (random) (random t
) (random))
4716 (prin1-to-string (recent-keys))
4717 (prin1-to-string (garbage-collect))))))
4719 (defvar canlock-password
)
4720 (defvar canlock-password-for-verify
)
4722 (defun message-canlock-password ()
4723 "The password used by message for cancel locks.
4724 This is the value of `canlock-password', if that option is non-nil.
4725 Otherwise, generate and save a value for `canlock-password' first."
4727 (unless canlock-password
4728 (customize-save-variable 'canlock-password
(message-canlock-generate))
4729 (setq canlock-password-for-verify canlock-password
))
4732 (defun message-insert-canlock ()
4733 (when message-insert-canlock
4734 (message-canlock-password)
4735 (canlock-insert-header)))
4737 (autoload 'nnheader-get-report
"nnheader")
4739 (declare-function gnus-setup-posting-charset
"gnus-msg" (group))
4741 (defun message-send-news (&optional arg
)
4743 (let* ((tembuf (message-generate-new-buffer-clone-locals " *message temp*"))
4744 (case-fold-search nil
)
4745 (method (if (functionp message-post-method
)
4746 (funcall message-post-method arg
)
4747 message-post-method
))
4748 (newsgroups-field (save-restriction
4749 (message-narrow-to-headers-or-head)
4750 (message-fetch-field "Newsgroups")))
4751 (followup-field (save-restriction
4752 (message-narrow-to-headers-or-head)
4753 (message-fetch-field "Followup-To")))
4754 ;; BUG: We really need to get the charset for each name in the
4755 ;; Newsgroups and Followup-To lines to allow crossposting
4756 ;; between group namess with incompatible character sets.
4757 ;; -- Per Abrahamsen <abraham@dina.kvl.dk> 2001-10-08.
4758 (group-field-charset
4759 (gnus-group-name-charset method newsgroups-field
))
4760 (followup-field-charset
4761 (gnus-group-name-charset method
(or followup-field
"")))
4762 (rfc2047-header-encoding-alist
4763 (append (when group-field-charset
4764 (list (cons "Newsgroups" group-field-charset
)))
4765 (when followup-field-charset
4766 (list (cons "Followup-To" followup-field-charset
)))
4767 rfc2047-header-encoding-alist
))
4768 (messbuf (current-buffer))
4769 (message-syntax-checks
4771 (listp message-syntax-checks
))
4772 (cons '(existing-newsgroups . disabled
)
4773 message-syntax-checks
)
4774 message-syntax-checks
))
4775 (message-this-is-news t
)
4776 (message-posting-charset
4777 (gnus-setup-posting-charset newsgroups-field
))
4779 (if (not (message-check-news-body-syntax))
4782 (message-narrow-to-headers)
4783 ;; Insert some headers.
4784 (message-generate-headers message-required-news-headers
)
4785 (message-insert-canlock)
4786 ;; Let the user do all of the above.
4787 (run-hooks 'message-header-hook
))
4788 ;; Note: This check will be disabled by the ".*" default value for
4789 ;; gnus-group-name-charset-group-alist. -- Pa 2001-10-07.
4790 (when (and group-field-charset
4791 (listp message-syntax-checks
))
4792 (setq message-syntax-checks
4793 (cons '(valid-newsgroups . disabled
)
4794 message-syntax-checks
)))
4795 (message-cleanup-headers)
4796 (if (not (let ((message-post-method method
))
4797 (message-check-news-syntax)))
4800 (with-current-buffer tembuf
4801 (buffer-disable-undo)
4803 ;; Avoid copying text props (except hard newlines).
4805 (with-current-buffer messbuf
4806 (mml-buffer-substring-no-properties-except-hard-newlines
4807 (point-min) (point-max))))
4808 (message-encode-message-body)
4809 ;; Remove some headers.
4811 (message-narrow-to-headers)
4812 ;; We (re)generate the Lines header.
4813 (when (memq 'Lines message-required-mail-headers
)
4814 (message-generate-headers '(Lines)))
4815 ;; Remove some headers.
4816 (message-remove-header message-ignored-news-headers t
)
4817 (let ((mail-parse-charset message-default-charset
))
4818 (mail-encode-encoded-word-buffer)))
4819 (goto-char (point-max))
4820 ;; require one newline at the end.
4821 (or (= (preceding-char) ?
\n)
4823 (let ((case-fold-search t
))
4824 ;; Remove the delimiter.
4825 (goto-char (point-min))
4827 (concat "^" (regexp-quote mail-header-separator
) "\n"))
4828 (replace-match "\n")
4830 (run-hooks 'message-send-news-hook
)
4831 (gnus-open-server method
)
4832 (message "Sending news via %s..." (gnus-server-string method
))
4833 (setq result
(let ((mail-header-separator ""))
4834 (gnus-request-post method
))))
4835 (kill-buffer tembuf
))
4836 (set-buffer messbuf
)
4838 (push 'news message-sent-message-via
)
4839 (message "Couldn't send message via news: %s"
4840 (nnheader-get-report (car method
)))
4844 ;;; Header generation & syntax checking.
4847 (defun message-check-element (type)
4848 "Return non-nil if this TYPE is not to be checked."
4849 (if (eq message-syntax-checks
'dont-check-for-anything-just-trust-me
)
4851 (let ((able (assq type message-syntax-checks
)))
4853 (eq (cdr able
) 'disabled
)))))
4855 (defun message-check-news-syntax ()
4856 "Check the syntax of the message."
4860 ;; We narrow to the headers and check them first.
4863 (message-narrow-to-headers)
4864 (message-check-news-header-syntax))))))
4866 (defun message-check-news-header-syntax ()
4868 ;; Check Newsgroups header.
4869 (message-check 'newsgroups
4870 (let ((group (message-fetch-field "newsgroups")))
4873 (not (string-match "\\`[ \t]*\\'" group
)))
4876 "The newsgroups field is empty or missing. Posting is denied.")))))
4877 ;; Check the Subject header.
4878 (message-check 'subject
4879 (let* ((case-fold-search t
)
4880 (subject (message-fetch-field "subject")))
4883 (not (string-match "\\`[ \t]*\\'" subject
)))
4886 "The subject field is empty or missing. Posting is denied.")))))
4887 ;; Check for commands in Subject.
4888 (message-check 'subject-cmsg
4889 (if (string-match "^cmsg " (message-fetch-field "subject"))
4891 "The control code \"cmsg\" is in the subject. Really post? ")
4893 ;; Check long header lines.
4894 (message-check 'long-header-lines
4895 (let ((start (point))
4899 (while (and (not found
)
4900 (re-search-forward "^\\([^ \t:]+\\): " nil t
))
4901 (if (> (- (point) (match-beginning 0)) 998)
4903 length
(- (point) (match-beginning 0)))
4904 (setq header
(match-string-no-properties 1)))
4905 (setq start
(match-beginning 0))
4908 (y-or-n-p (format "Your %s header is too long (%d). Really post? "
4911 ;; Check for multiple identical headers.
4912 (message-check 'multiple-headers
4914 (while (and (not found
)
4915 (re-search-forward "^[^ \t:]+: " nil t
))
4917 (or (re-search-forward
4922 (match-beginning 0) (- (match-end 0) 2))))
4927 (y-or-n-p (format "Multiple %s headers. Really post? " found
))
4929 ;; Check for Version and Sendsys.
4930 (message-check 'sendsys
4931 (if (re-search-forward "^Sendsys:\\|^Version:" nil t
)
4933 (format "The article contains a %s command. Really post? "
4934 (buffer-substring (match-beginning 0)
4935 (1- (match-end 0)))))
4937 ;; See whether we can shorten Followup-To.
4938 (message-check 'shorten-followup-to
4939 (let ((newsgroups (message-fetch-field "newsgroups"))
4940 (followup-to (message-fetch-field "followup-to"))
4942 (when (and newsgroups
4943 (string-match "," newsgroups
)
4948 (setq to
(completing-read
4949 "Followups to (default no Followup-To header): "
4952 (message-tokenize-header
4954 (goto-char (point-min))
4955 (insert "Followup-To: " to
"\n"))
4957 ;; Check "Shoot me".
4958 (message-check 'shoot
4959 (if (re-search-forward
4960 "Message-ID.*.i-did-not-set--mail-host-address--so-tickle-me" nil t
)
4961 (y-or-n-p "You appear to have a misconfigured system. Really post? ")
4963 ;; Check for Approved.
4964 (message-check 'approved
4965 (if (re-search-forward "^Approved:" nil t
)
4966 (y-or-n-p "The article contains an Approved header. Really post? ")
4968 ;; Check the Message-ID header.
4969 (message-check 'message-id
4970 (let* ((case-fold-search t
)
4971 (message-id (message-fetch-field "message-id" t
)))
4972 (or (not message-id
)
4973 ;; Is there an @ in the ID?
4974 (and (string-match "@" message-id
)
4975 ;; Is there a dot in the ID?
4976 (string-match "@[^.]*\\." message-id
)
4977 ;; Does the ID end with a dot?
4978 (not (string-match "\\.>" message-id
)))
4980 (format "The Message-ID looks strange: \"%s\". Really post? "
4982 ;; Check the Newsgroups & Followup-To headers.
4983 (message-check 'existing-newsgroups
4984 (let* ((case-fold-search t
)
4985 (newsgroups (message-fetch-field "newsgroups"))
4986 (followup-to (message-fetch-field "followup-to"))
4987 (groups (message-tokenize-header
4989 (concat newsgroups
"," followup-to
)
4991 (post-method (if (functionp message-post-method
)
4992 (funcall message-post-method
)
4993 message-post-method
))
4994 ;; KLUDGE to handle nnvirtual groups. Doing this right
4995 ;; would probably involve a new nnoo function.
4996 ;; -- Per Abrahamsen <abraham@dina.kvl.dk>, 2001-10-17.
4997 (method (if (and (consp post-method
)
4998 (eq (car post-method
) 'nnvirtual
)
4999 gnus-message-group-art
)
5000 (let ((group (car (nnvirtual-find-group-art
5001 (car gnus-message-group-art
)
5002 (cdr gnus-message-group-art
)))))
5003 (gnus-find-method-for-group group
))
5007 (gnus-group-name-decode
5008 (gnus-group-real-name n
)
5009 (gnus-group-name-charset method n
)))
5010 (gnus-groups-from-server method
)))
5013 (when (and (not (equal (car groups
) "poster"))
5014 (not (member (car groups
) known-groups
))
5015 (not (member (car groups
) errors
)))
5016 (push (car groups
) errors
))
5019 ;; Gnus is not running.
5020 ((or (not (and (boundp 'gnus-active-hashtb
)
5021 gnus-active-hashtb
))
5022 (not (boundp 'gnus-read-active-file
)))
5024 ;; We don't have all the group names.
5025 ((and (or (not gnus-read-active-file
)
5026 (eq gnus-read-active-file
'some
))
5030 "Really use %s possibly unknown group%s: %s? "
5031 (if (= (length errors
) 1) "this" "these")
5032 (if (= (length errors
) 1) "" "s")
5033 (mapconcat 'identity errors
", "))))
5034 ;; There were no errors.
5037 ;; There are unknown groups.
5041 "Really post to %s unknown group%s: %s? "
5042 (if (= (length errors
) 1) "this" "these")
5043 (if (= (length errors
) 1) "" "s")
5044 (mapconcat 'identity errors
", ")))))))
5045 ;; Check continuation headers.
5046 (message-check 'continuation-headers
5047 (goto-char (point-min))
5048 (let ((do-posting t
))
5049 (while (re-search-forward "^[^ \t\n][^ \t\n:]*[ \t\n]" nil t
)
5050 (goto-char (match-beginning 0))
5051 (if (y-or-n-p "Fix continuation lines? ")
5054 (unless (y-or-n-p "Send anyway? ")
5055 (setq do-posting nil
))))
5057 ;; Check the Newsgroups & Followup-To headers for syntax errors.
5058 (message-check 'valid-newsgroups
5059 (let ((case-fold-search t
)
5060 (headers '("Newsgroups" "Followup-To"))
5062 (while (and headers
(not error
))
5063 (when (setq header
(mail-fetch-field (car headers
)))
5067 "\\`\\([-+_&.a-zA-Z0-9]+\\)?\\(,[-+_&.a-zA-Z0-9]+\\)*\\'"
5072 (not (string-match "\\.\\'\\|\\.\\." g
)))
5073 (message-tokenize-header header
","))))
5080 (format "The %s header looks odd: \"%s\". Really post? "
5081 (car headers
) header
)))))
5082 (message-check 'repeated-newsgroups
5083 (let ((case-fold-search t
)
5084 (headers '("Newsgroups" "Followup-To"))
5085 header error groups group
)
5088 (when (setq header
(mail-fetch-field (pop headers
)))
5089 (setq groups
(message-tokenize-header header
","))
5090 (while (setq group
(pop groups
))
5091 (when (member group groups
)
5097 (format "Group %s is repeated in headers. Really post? " error
)))))
5098 ;; Check the From header.
5099 (message-check 'from
5100 (let* ((case-fold-search t
)
5101 (from (message-fetch-field "from"))
5105 (message "There is no From line. Posting is denied.")
5107 ((or (not (string-match
5109 (setq ad
(nth 1 (mail-extract-address-components
5110 from
))))) ;larsi@ifi
5111 (string-match "\\.\\." ad
) ;larsi@ifi..uio
5112 (string-match "@\\." ad
) ;larsi@.ifi.uio
5113 (string-match "\\.$" ad
) ;larsi@ifi.uio.
5114 (not (string-match "^[^@]+@[^@]+$" ad
)) ;larsi.ifi.uio
5115 (string-match "(.*).*(.*)" from
)) ;(lars) (lars)
5117 "Denied posting -- the From looks strange: \"%s\"." from
)
5119 ((let ((addresses (rfc822-addresses from
)))
5120 ;; `rfc822-addresses' returns a string if parsing fails.
5121 (while (and (consp addresses
)
5122 (not (eq (string-to-char (car addresses
)) ?\
()))
5123 (setq addresses
(cdr addresses
)))
5126 "Denied posting -- bad From address: \"%s\"." from
)
5129 ;; Check the Reply-To header.
5130 (message-check 'reply-to
5131 (let* ((case-fold-search t
)
5132 (reply-to (message-fetch-field "reply-to"))
5137 ((string-match "," reply-to
)
5139 (format "Multiple Reply-To addresses: \"%s\". Really post? "
5141 ((or (not (string-match
5143 (setq ad
(nth 1 (mail-extract-address-components
5144 reply-to
))))) ;larsi@ifi
5145 (string-match "\\.\\." ad
) ;larsi@ifi..uio
5146 (string-match "@\\." ad
) ;larsi@.ifi.uio
5147 (string-match "\\.$" ad
) ;larsi@ifi.uio.
5148 (not (string-match "^[^@]+@[^@]+$" ad
)) ;larsi.ifi.uio
5149 (string-match "(.*).*(.*)" reply-to
)) ;(lars) (lars)
5152 "The Reply-To looks strange: \"%s\". Really post? "
5156 (defun message-check-news-body-syntax ()
5158 ;; Check for long lines.
5159 (message-check 'long-lines
5160 (goto-char (point-min))
5162 (concat "^" (regexp-quote mail-header-separator
) "$"))
5166 "<#\\(/\\)?\\(multipart\\|part\\|external\\|mml\\)")
5169 (< (- (point) p
) 80)))
5170 (zerop (forward-line 1))))
5174 "You have lines longer than 79 characters. Really post? ")))
5175 ;; Check whether the article is empty.
5176 (message-check 'empty
5177 (goto-char (point-min))
5179 (concat "^" (regexp-quote mail-header-separator
) "$"))
5182 (goto-char (point-max))
5183 (re-search-backward message-signature-separator nil t
)
5185 (or (re-search-backward "[^ \n\t]" b t
)
5186 (if (message-gnksa-enable-p 'empty-article
)
5187 (y-or-n-p "Empty article. Really post? ")
5188 (message "Denied posting -- Empty article.")
5190 ;; Check for control characters.
5191 (message-check 'control-chars
5192 (if (re-search-forward
5193 (mm-string-to-multibyte "[\000-\007\013\015-\032\034-\037\200-\237]")
5196 "The article contains control characters. Really post? ")
5198 ;; Check excessive size.
5199 (message-check 'size
5200 (if (> (buffer-size) 60000)
5202 (format "The article is %d octets long. Really post? "
5205 ;; Check whether any new text has been added.
5206 (message-check 'new-text
5208 (not message-checksum
)
5209 (not (eq (message-checksum) message-checksum
))
5210 (if (message-gnksa-enable-p 'quoted-text-only
)
5212 "It looks like no new text has been added. Really post? ")
5213 (message "Denied posting -- no new text has been added.")
5215 ;; Check the length of the signature.
5216 (message-check 'signature
5217 (let (sig-start sig-end
)
5218 (goto-char (point-max))
5219 (if (not (re-search-backward message-signature-separator nil t
))
5221 (setq sig-start
(1+ (point-at-eol)))
5223 (if (re-search-forward
5224 "<#/?\\(multipart\\|part\\|external\\|mml\\)" nil t
)
5225 (- (point-at-bol) 1)
5227 (if (>= (count-lines sig-start sig-end
) 5)
5228 (if (message-gnksa-enable-p 'signature
)
5230 (format "Signature is excessively long (%d lines). Really post? "
5231 (count-lines sig-start sig-end
)))
5232 (message "Denied posting -- Excessive signature.")
5235 ;; Ensure that text follows last quoted portion.
5236 (message-check 'quoting-style
5237 (goto-char (point-max))
5238 (let ((no-problem t
))
5239 (when (search-backward-regexp "^>[^\n]*\n" nil t
)
5240 (setq no-problem
(search-forward-regexp "^[ \t]*[^>\n]" nil t
)))
5243 (if (message-gnksa-enable-p 'quoted-text-only
)
5244 (y-or-n-p "Your text should follow quoted text. Really post? ")
5246 (goto-char (point-min))
5248 (concat "^" (regexp-quote mail-header-separator
) "$"))
5249 (if (search-forward-regexp "^[ \t]*[^>\n]" nil t
)
5250 (y-or-n-p "Your text should follow quoted text. Really post? ")
5251 (message "Denied posting -- only quoted text.")
5254 (defun message-checksum ()
5255 "Return a \"checksum\" for the current buffer."
5258 (goto-char (point-min))
5260 (concat "^" (regexp-quote mail-header-separator
) "$"))
5262 (when (not (looking-at "[ \t\n]"))
5263 (setq sum
(logxor (ash sum
1) (if (natnump sum
) 0 1)
5268 (defun message-do-fcc ()
5269 "Process Fcc headers in the current buffer."
5270 (let ((case-fold-search t
)
5271 (buf (current-buffer))
5273 (mml-externalize-attachments message-fcc-externalize-attachments
))
5276 (message-narrow-to-headers)
5277 (setq file
(message-fetch-field "fcc" t
)))
5279 (set-buffer (get-buffer-create " *message temp*"))
5281 (insert-buffer-substring buf
)
5282 (message-encode-message-body)
5284 (message-narrow-to-headers)
5285 (while (setq file
(message-fetch-field "fcc" t
))
5287 (message-remove-header "fcc" nil t
))
5288 (let ((mail-parse-charset message-default-charset
)
5289 (rfc2047-header-encoding-alist
5290 (cons '("Newsgroups" . default
)
5291 rfc2047-header-encoding-alist
)))
5292 (mail-encode-encoded-word-buffer)))
5293 (goto-char (point-min))
5294 (when (re-search-forward
5295 (concat "^" (regexp-quote mail-header-separator
) "$")
5297 (replace-match "" t t
))
5298 ;; Process FCC operations.
5300 (setq file
(pop list
))
5301 (if (string-match "^[ \t]*|[ \t]*\\(.*\\)[ \t]*$" file
)
5302 ;; Pipe the article to the program in question.
5303 (call-process-region (point-min) (point-max) shell-file-name
5304 nil nil nil shell-command-switch
5305 (match-string 1 file
))
5306 ;; Save the article.
5307 (setq file
(expand-file-name file
))
5308 (unless (file-exists-p (file-name-directory file
))
5309 (make-directory (file-name-directory file
) t
))
5310 (if (and message-fcc-handler-function
5311 (not (eq message-fcc-handler-function
'rmail-output
)))
5312 (funcall message-fcc-handler-function file
)
5313 ;; FIXME this option, rmail-output (also used if
5314 ;; message-fcc-handler-function is nil) is not
5315 ;; documented anywhere AFAICS. It should work in Emacs
5316 ;; 23; I suspect it does not work in Emacs 22.
5317 ;; FIXME I don't see the need for the two different cases here.
5318 ;; mail-use-rfc822 makes no difference (in Emacs 23),and
5319 ;; the third argument just controls \"Wrote file\" message.
5320 (if (and (file-readable-p file
) (mail-file-babyl-p file
))
5321 (rmail-output file
1 nil t
)
5322 (let ((mail-use-rfc822 t
))
5323 (rmail-output file
1 t t
))))))
5324 (kill-buffer (current-buffer))))))
5326 (defun message-output (filename)
5327 "Append this article to Unix/babyl mail file FILENAME."
5328 (if (or (and (file-readable-p filename
)
5329 (mail-file-babyl-p filename
))
5330 ;; gnus-output-to-mail does the wrong thing with live, mbox
5331 ;; Rmail buffers in Emacs 23.
5332 ;; http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=597255
5333 (let ((buff (find-buffer-visiting filename
)))
5334 (and buff
(with-current-buffer buff
5335 (eq major-mode
'rmail-mode
)))))
5336 (gnus-output-to-rmail filename t
)
5337 (gnus-output-to-mail filename t
)))
5339 (defun message-cleanup-headers ()
5340 "Do various automatic cleanups of the headers."
5341 ;; Remove empty lines in the header.
5343 (message-narrow-to-headers)
5344 ;; Remove blank lines.
5345 (while (re-search-forward "^[ \t]*\n" nil t
)
5346 (replace-match "" t t
))
5348 ;; Correct Newsgroups and Followup-To headers: Change sequence of
5349 ;; spaces to comma and eliminate spaces around commas. Eliminate
5350 ;; embedded line breaks.
5351 (goto-char (point-min))
5352 (while (re-search-forward "^\\(Newsgroups\\|Followup-To\\): +" nil t
)
5356 (if (re-search-forward "^[^ \t]" nil t
)
5360 (goto-char (point-min))
5361 (while (re-search-forward "\n[ \t]+" nil t
)
5362 (replace-match " " t t
)) ;No line breaks (too confusing)
5363 (goto-char (point-min))
5364 (while (re-search-forward "[ \t\n]*,[ \t\n]*\\|[ \t]+" nil t
)
5365 (replace-match "," t t
))
5366 (goto-char (point-min))
5367 ;; Remove trailing commas.
5368 (when (re-search-forward ",+$" nil t
)
5369 (replace-match "" t t
))))))
5371 (defun message-make-date (&optional now
)
5372 "Make a valid data header.
5373 If NOW, use that time instead."
5374 (let ((system-time-locale "C"))
5375 (format-time-string "%a, %d %b %Y %T %z" now
)))
5377 (defun message-insert-expires (days)
5378 "Insert the Expires header. Expiry in DAYS days."
5379 (interactive "NExpire article in how many days? ")
5381 (message-position-on-field "Expires" "X-Draft-From")
5382 (insert (message-make-expires-date days
))))
5384 (defun message-make-expires-date (days)
5385 "Make date string for the Expires header. Expiry in DAYS days.
5387 In posting styles use `(\"Expires\" (make-expires-date 30))'."
5388 (let* ((cur (decode-time (current-time)))
5389 (nday (+ days
(nth 3 cur
))))
5390 (setf (nth 3 cur
) nday
)
5391 (message-make-date (apply 'encode-time cur
))))
5393 (defun message-make-message-id ()
5394 "Make a unique Message-ID."
5395 (concat "<" (message-unique-id)
5396 (let ((psubject (save-excursion (message-fetch-field "subject")))
5398 (save-excursion (message-fetch-field "supersedes"))))
5400 (and message-reply-headers
5401 (mail-header-references message-reply-headers
)
5402 (mail-header-subject message-reply-headers
)
5405 (message-strip-subject-re
5406 (mail-header-subject message-reply-headers
))
5407 (message-strip-subject-re psubject
))))
5409 (string-match "_-_@" psupersedes
)))
5411 "@" (message-make-fqdn) ">"))
5413 (defvar message-unique-id-char nil
)
5415 ;; If you ever change this function, make sure the new version
5416 ;; cannot generate IDs that the old version could.
5417 ;; You might for example insert a "." somewhere (not next to another dot
5418 ;; or string boundary), or modify the "fsf" string.
5419 (defun message-unique-id ()
5420 ;; Don't use microseconds from (current-time), they may be unsupported.
5421 ;; Instead we use this randomly inited counter.
5422 (setq message-unique-id-char
5423 (%
(1+ (or message-unique-id-char
(logand (random t
) (1- (lsh 1 20)))))
5424 ;; (current-time) returns 16-bit ints,
5425 ;; and 2^16*25 just fits into 4 digits i base 36.
5427 (let ((tm (current-time)))
5429 (if (or (eq system-type
'ms-dos
)
5430 ;; message-number-base36 doesn't handle bigints.
5431 (floatp (user-uid)))
5432 (let ((user (downcase (user-login-name))))
5433 (while (string-match "[^a-z0-9_]" user
)
5434 (aset user
(match-beginning 0) ?_
))
5436 (message-number-base36 (user-uid) -
1))
5437 (message-number-base36 (+ (car tm
)
5438 (lsh (% message-unique-id-char
25) 16)) 4)
5439 (message-number-base36 (+ (nth 1 tm
)
5440 (lsh (/ message-unique-id-char
25) 16)) 4)
5441 ;; Append a given name, because while the generated ID is unique
5442 ;; to this newsreader, other newsreaders might otherwise generate
5443 ;; the same ID via another algorithm.
5446 (defun message-number-base36 (num len
)
5451 (concat (message-number-base36 (/ num
36) (1- len
))
5452 (char-to-string (aref "zyxwvutsrqponmlkjihgfedcba9876543210"
5455 (defun message-make-organization ()
5456 "Make an Organization header."
5457 (let* ((organization
5458 (when message-user-organization
5459 (if (functionp message-user-organization
)
5460 (funcall message-user-organization
)
5461 message-user-organization
))))
5463 (mm-enable-multibyte)
5464 (cond ((stringp organization
)
5465 (insert organization
))
5466 ((and (eq t organization
)
5467 message-user-organization-file
5468 (file-exists-p message-user-organization-file
))
5469 (insert-file-contents message-user-organization-file
)))
5470 (goto-char (point-min))
5471 (while (re-search-forward "[\t\n]+" nil t
)
5472 (replace-match "" t t
))
5473 (unless (zerop (buffer-size))
5476 (defun message-make-lines ()
5477 "Count the number of lines and return numeric string."
5482 (int-to-string (count-lines (point) (point-max))))))
5484 (defun message-make-references ()
5485 "Return the References header for this message."
5486 (when message-reply-headers
5487 (let ((message-id (mail-header-id message-reply-headers
))
5488 (references (mail-header-references message-reply-headers
)))
5489 (if (or references message-id
)
5490 (concat (or references
"") (and references
" ")
5494 (defun message-make-in-reply-to ()
5495 "Return the In-Reply-To header for this message."
5496 (when message-reply-headers
5497 (let ((from (mail-header-from message-reply-headers
))
5498 (date (mail-header-date message-reply-headers
))
5499 (msg-id (mail-header-id message-reply-headers
)))
5501 (let ((name (mail-extract-address-components from
)))
5503 msg-id
(if msg-id
" (")
5505 (if (string-match "[^\000-\177]" (car name
))
5506 ;; Quote a string containing non-ASCII characters.
5507 ;; It will make the RFC2047 encoder cause an error
5508 ;; if there are special characters.
5509 (mm-with-multibyte-buffer
5511 (goto-char (point-min))
5512 (while (search-forward "\"" nil t
)
5515 (zerop (%
(skip-chars-backward "\\\\") 2))
5516 (goto-char (match-beginning 0)))
5519 ;; Those quotes will be removed by the RFC2047 encoder.
5520 (concat "\"" (buffer-string) "\""))
5524 (if (or (not date
) (string= date
""))
5525 "(unknown date)" date
)
5526 "\"" (if msg-id
")")))))))
5528 (defun message-make-distribution ()
5529 "Make a Distribution header."
5530 (let ((orig-distribution (message-fetch-reply-field "distribution")))
5531 (cond ((functionp message-distribution-function
)
5532 (funcall message-distribution-function
))
5533 (t orig-distribution
))))
5535 (defun message-make-expires ()
5536 "Return an Expires header based on `message-expires'."
5537 (let ((current (current-time))
5538 (future (* 1.0 message-expires
60 60 24)))
5539 ;; Add the future to current.
5540 (setcar current
(+ (car current
) (round (/ future
(expt 2 16)))))
5541 (setcar (cdr current
) (+ (nth 1 current
) (%
(round future
) (expt 2 16))))
5542 (message-make-date current
)))
5544 (defun message-make-path ()
5546 (let ((login-name (user-login-name)))
5547 (cond ((null message-user-path
)
5548 (concat (system-name) "!" login-name
))
5549 ((stringp message-user-path
)
5550 ;; Support GENERICPATH. Suggested by vixie@decwrl.dec.com.
5551 (concat message-user-path
"!" login-name
))
5554 (defun message-make-from (&optional name address
)
5555 "Make a From header."
5556 (let* ((style message-from-style
)
5557 (login (or address
(message-make-address)))
5559 (and (boundp 'user-full-name
)
5562 (when (string= fullname
"&")
5563 (setq fullname
(user-login-name)))
5565 (mm-enable-multibyte)
5568 (equal fullname
""))
5570 ((or (eq style
'angles
)
5571 (and (not (eq style
'parens
))
5572 ;; Use angles if no quoting is needed, or if parens would
5573 ;; need quoting too.
5574 (or (not (string-match "[^- !#-'*+/-9=?A-Z^-~]" fullname
))
5575 (let ((tmp (concat fullname nil
)))
5576 (while (string-match "([^()]*)" tmp
)
5577 (aset tmp
(match-beginning 0) ?-
)
5578 (aset tmp
(1- (match-end 0)) ?-
))
5579 (string-match "[\\()]" tmp
)))))
5581 (goto-char (point-min))
5582 ;; Look for a character that cannot appear unquoted
5583 ;; according to RFC 822.
5584 (when (re-search-forward "[^- !#-'*+/-9=?A-Z^-~]" nil
1)
5585 ;; Quote fullname, escaping specials.
5586 (goto-char (point-min))
5588 (while (re-search-forward "[\"\\]" nil
1)
5589 (replace-match "\\\\\\&" t
))
5591 (insert " <" login
">"))
5592 (t ; 'parens or default
5594 (let ((fullname-start (point)))
5596 (goto-char fullname-start
)
5597 ;; RFC 822 says \ and nonmatching parentheses
5598 ;; must be escaped in comments.
5599 ;; Escape every instance of ()\ ...
5600 (while (re-search-forward "[()\\]" nil
1)
5601 (replace-match "\\\\\\&" t
))
5602 ;; ... then undo escaping of matching parentheses,
5603 ;; including matching nested parentheses.
5604 (goto-char fullname-start
)
5605 (while (re-search-forward
5606 "\\(\\=\\|[^\\]\\(\\\\\\\\\\)*\\)\\\\(\\(\\([^\\]\\|\\\\\\\\\\)*\\)\\\\)"
5608 (replace-match "\\1(\\3)" t
)
5609 (goto-char fullname-start
)))
5613 (defun message-make-sender ()
5614 "Return the \"real\" user address.
5615 This function tries to ignore all user modifications, and
5616 give as trustworthy answer as possible."
5617 (concat (user-login-name) "@" (system-name)))
5619 (defun message-make-address ()
5620 "Make the address of the user."
5621 (or (message-user-mail-address)
5622 (concat (user-login-name) "@" (message-make-domain))))
5624 (defun message-user-mail-address ()
5625 "Return the pertinent part of `user-mail-address'."
5626 (when (and user-mail-address
5627 (string-match "@.*\\." user-mail-address
))
5628 (if (string-match " " user-mail-address
)
5629 (nth 1 (mail-extract-address-components user-mail-address
))
5630 user-mail-address
)))
5632 (defun message-sendmail-envelope-from ()
5633 "Return the envelope from."
5634 (cond ((eq message-sendmail-envelope-from
'header
)
5635 (nth 1 (mail-extract-address-components
5636 (message-fetch-field "from"))))
5637 ((stringp message-sendmail-envelope-from
)
5638 message-sendmail-envelope-from
)
5640 (message-make-address))))
5642 (defun message-make-fqdn ()
5643 "Return user's fully qualified domain name."
5644 (let* ((system-name (system-name))
5645 (user-mail (message-user-mail-address))
5648 (string-match "@\\(.*\\)\\'" user-mail
))
5649 (match-string 1 user-mail
)))
5650 (case-fold-search t
))
5652 ((and message-user-fqdn
5653 (stringp message-user-fqdn
)
5654 (string-match message-valid-fqdn-regexp message-user-fqdn
)
5655 (not (string-match message-bogus-system-names message-user-fqdn
)))
5656 ;; `message-user-fqdn' seems to be valid
5658 ((and (string-match message-valid-fqdn-regexp system-name
)
5659 (not (string-match message-bogus-system-names system-name
)))
5660 ;; `system-name' returned the right result.
5662 ;; Try `mail-host-address'.
5663 ((and (boundp 'mail-host-address
)
5664 (stringp mail-host-address
)
5665 (string-match message-valid-fqdn-regexp mail-host-address
)
5666 (not (string-match message-bogus-system-names mail-host-address
)))
5668 ;; We try `user-mail-address' as a backup.
5670 (stringp user-domain
)
5671 (string-match message-valid-fqdn-regexp user-domain
)
5672 (not (string-match message-bogus-system-names user-domain
)))
5674 ;; Default to this bogus thing.
5677 ".i-did-not-set--mail-host-address--so-tickle-me")))))
5679 (defun message-make-host-name ()
5680 "Return the name of the host."
5681 (let ((fqdn (message-make-fqdn)))
5682 (string-match "^[^.]+\\." fqdn
)
5683 (substring fqdn
0 (1- (match-end 0)))))
5685 (defun message-make-domain ()
5686 "Return the domain name."
5687 (or mail-host-address
5688 (message-make-fqdn)))
5690 (defun message-to-list-only ()
5691 "Send a message to the list only.
5692 Remove all addresses but the list address from To and Cc headers."
5694 (let ((listaddr (message-make-mail-followup-to t
)))
5697 (message-remove-header "to")
5698 (message-remove-header "cc")
5699 (message-position-on-field "To" "X-Draft-From")
5700 (insert listaddr
)))))
5702 (defun message-make-mail-followup-to (&optional only-show-subscribed
)
5703 "Return the Mail-Followup-To header.
5704 If passed the optional argument ONLY-SHOW-SUBSCRIBED only return the
5705 subscribed address (and not the additional To and Cc header contents)."
5706 (let* ((case-fold-search t
)
5707 (to (message-fetch-field "To"))
5708 (cc (message-fetch-field "cc"))
5709 (msg-recipients (concat to
(and to cc
", ") cc
))
5711 (mapcar 'mail-strip-quoted-names
5712 (message-tokenize-header msg-recipients
)))
5714 (if message-subscribed-address-file
5715 (let (begin end item re
)
5718 (insert-file-contents message-subscribed-address-file
)
5720 (setq begin
(point))
5723 (if (bolp) (setq end
(1- end
)))
5724 (setq item
(regexp-quote (buffer-substring begin end
)))
5725 (if re
(setq re
(concat re
"\\|" item
))
5726 (setq re
(concat "\\`\\(" item
))))
5727 (and re
(list (concat re
"\\)\\'"))))))))
5728 (mft-regexps (apply 'append message-subscribed-regexps
5729 (mapcar 'regexp-quote
5730 message-subscribed-addresses
)
5733 message-subscribed-address-functions
))))
5736 (loop for recipient in recipients
5737 when
(loop for regexp in mft-regexps
5738 when
(string-match regexp recipient
) return t
)
5741 (if only-show-subscribed
5743 msg-recipients
))))))
5745 (defun message-idna-to-ascii-rhs-1 (header)
5746 "Interactively potentially IDNA encode domain names in HEADER."
5747 (let ((field (message-fetch-field header
))
5751 (mm-delete-duplicates
5752 (mapcar (lambda (rhs) (or (cadr (split-string rhs
"@")) ""))
5758 (mail-extract-address-components field t
))))))
5759 ;; Note that `rhs' will be "" if the address does not have
5760 ;; the domain part, i.e., if it is a local user's address.
5761 (setq ace
(if (string-match "\\`[[:ascii:]]*\\'" rhs
)
5763 (downcase (idna-to-ascii rhs
))))
5764 (when (and (not (equal rhs ace
))
5765 (or (not (eq message-use-idna
'ask
))
5766 (y-or-n-p (format "Replace %s with %s in %s:? "
5768 (goto-char (point-min))
5769 (while (re-search-forward (concat "^" header
":") nil t
)
5770 (message-narrow-to-field)
5771 (while (search-forward (concat "@" rhs
) nil t
)
5772 (replace-match (concat "@" ace
) t t
))
5773 (goto-char (point-max))
5776 (defun message-idna-to-ascii-rhs ()
5777 "Possibly IDNA encode non-ASCII domain names in From:, To: and Cc: headers.
5778 See `message-idna-encode'."
5780 (when message-use-idna
5783 ;; `message-narrow-to-head' that recognizes only the first empty
5784 ;; line as the message header separator used to be used here.
5785 ;; However, since there is the "--text follows this line--" line
5786 ;; normally, it failed in narrowing to the headers and potentially
5787 ;; caused the IDNA encoding on lines that look like headers in
5788 ;; the message body.
5789 (message-narrow-to-headers-or-head)
5790 (message-idna-to-ascii-rhs-1 "From")
5791 (message-idna-to-ascii-rhs-1 "To")
5792 (message-idna-to-ascii-rhs-1 "Reply-To")
5793 (message-idna-to-ascii-rhs-1 "Mail-Reply-To")
5794 (message-idna-to-ascii-rhs-1 "Mail-Followup-To")
5795 (message-idna-to-ascii-rhs-1 "Cc")))))
5797 (defun message-generate-headers (headers)
5798 "Prepare article HEADERS.
5799 Headers already prepared in the buffer are not modified."
5800 (setq headers
(append headers message-required-headers
))
5802 (message-narrow-to-headers)
5803 (let* ((Date (message-make-date))
5804 (Message-ID (message-make-message-id))
5805 (Organization (message-make-organization))
5806 (From (message-make-from))
5807 (Path (message-make-path))
5810 (In-Reply-To (message-make-in-reply-to))
5811 (References (message-make-references))
5813 (Distribution (message-make-distribution))
5814 (Lines (message-make-lines))
5815 (User-Agent message-newsreader
)
5816 (Expires (message-make-expires))
5817 (case-fold-search t
)
5819 header value elem header-string
)
5820 ;; First we remove any old generated headers.
5821 (let ((headers message-deletable-headers
))
5822 (unless (buffer-modified-p)
5823 (setq headers
(delq 'Message-ID
(copy-sequence headers
))))
5825 (goto-char (point-min))
5826 (and (re-search-forward
5827 (concat "^" (symbol-name (car headers
)) ": *") nil t
)
5828 (get-text-property (1+ (match-beginning 0)) 'message-deletable
)
5829 (message-delete-line))
5831 ;; Go through all the required headers and see if they are in the
5832 ;; articles already. If they are not, or are empty, they are
5833 ;; inserted automatically - except for Subject, Newsgroups and
5836 (goto-char (point-min))
5837 (setq elem
(pop headers
))
5839 (if (eq (car elem
) 'optional
)
5840 (setq header
(cdr elem
)
5842 (setq header
(car elem
)))
5844 (setq header-string
(if (stringp header
)
5846 (symbol-name header
)))
5847 (when (or (not (re-search-forward
5849 (regexp-quote (downcase header-string
))
5853 ;; The header was found. We insert a space after the
5854 ;; colon, if there is none.
5855 (if (/= (char-after) ?
) (insert " ") (forward-char 1))
5856 ;; Find out whether the header is empty.
5857 (looking-at "[ \t]*\n[^ \t]")))
5858 ;; So we find out what value we should insert.
5862 (eq (car elem
) 'optional
)
5863 (not (member header-string message-inserted-headers
)))
5864 ;; This is an optional header. If the cdr of this
5865 ;; is something that is nil, then we do not insert
5867 (setq header
(cdr elem
))
5868 (or (and (functionp (cdr elem
))
5869 (funcall (cdr elem
)))
5870 (and (boundp (cdr elem
))
5871 (symbol-value (cdr elem
)))))
5873 ;; The element is a cons. Either the cdr is a
5874 ;; string to be inserted verbatim, or it is a
5875 ;; function, and we insert the value returned from
5877 (or (and (stringp (cdr elem
))
5879 (and (functionp (cdr elem
))
5880 (funcall (cdr elem
)))))
5881 ((and (boundp header
)
5882 (symbol-value header
))
5883 ;; The element is a symbol. We insert the value
5884 ;; of this symbol, if any.
5885 (symbol-value header
))
5886 ((not (message-check-element
5887 (intern (downcase (symbol-name header
)))))
5888 ;; We couldn't generate a value for this header,
5889 ;; so we just ask the user.
5890 (read-from-minibuffer
5891 (format "Empty header for %s; enter value: " header
)))))
5892 ;; Finally insert the header.
5894 (not (equal value
"")))
5898 ;; This header didn't exist, so we insert it.
5899 (goto-char (point-max))
5901 (cdr (assq header message-header-format-alist
))))
5903 (funcall formatter header value
)
5904 (insert header-string
": " value
))
5905 (push header-string message-inserted-headers
)
5906 (goto-char (message-fill-field))
5907 ;; We check whether the value was ended by a
5908 ;; newline. If not, we insert one.
5912 ;; The value of this header was empty, so we clear
5913 ;; totally and insert the new value.
5914 (delete-region (point) (point-at-eol))
5915 ;; If the header is optional, and the header was
5916 ;; empty, we can't insert it anyway.
5918 (push header-string message-inserted-headers
)
5920 (message-fill-field)))
5921 ;; Add the deletable property to the headers that require it.
5922 (and (memq header message-deletable-headers
)
5923 (progn (beginning-of-line) (looking-at "[^:]+: "))
5924 (add-text-properties
5925 (point) (match-end 0)
5926 '(message-deletable t face italic
) (current-buffer)))))))
5927 ;; Insert new Sender if the From is strange.
5928 (let ((from (message-fetch-field "from"))
5929 (sender (message-fetch-field "sender"))
5930 (secure-sender (message-make-sender)))
5932 (not (message-check-element 'sender
))
5935 (cadr (mail-extract-address-components from
)))
5936 (downcase secure-sender
)))
5941 (cadr (mail-extract-address-components sender
)))
5942 (downcase secure-sender
)))))
5943 (goto-char (point-min))
5944 ;; Rename any old Sender headers to Original-Sender.
5945 (when (re-search-forward "^\\(Original-\\)*Sender:" nil t
)
5947 (insert "Original-")
5948 (beginning-of-line))
5949 (when (or (message-news-p)
5950 (string-match "@.+\\.." secure-sender
))
5951 (insert "Sender: " secure-sender
"\n"))))
5953 (message-idna-to-ascii-rhs))))
5955 (defun message-insert-courtesy-copy (message)
5956 "Insert a courtesy message in mail copies of combined messages."
5960 (message-narrow-to-headers)
5961 (when (setq newsgroups
(message-fetch-field "newsgroups"))
5962 (goto-char (point-max))
5963 (insert "Posted-To: " newsgroups
"\n")))
5967 ((string-match "%s" message
)
5968 (insert (format message newsgroups
)))
5970 (insert message
)))))))
5973 ;;; Setting up a message buffer
5976 (defun message-skip-to-next-address ()
5977 (let ((end (save-excursion
5978 (message-next-header)
5981 (when (looking-at ",")
5983 (while (and (not (= (point) end
))
5984 (or (not (eq char ?
,))
5986 (skip-chars-forward "^,\"" (point-max))
5987 (when (eq (setq char
(following-char)) ?
\")
5988 (setq quoted
(not quoted
)))
5989 (unless (= (point) end
)
5991 (skip-chars-forward " \t\n")))
5993 (defun message-fill-address (header value
)
5994 (insert (capitalize (symbol-name header
))
5996 (if (consp value
) (car value
) value
)
5998 (message-fill-field-address))
6000 (defun message-split-line ()
6001 "Split current line, moving portion beyond point vertically down.
6002 If the current line has `message-yank-prefix', insert it on the new line."
6005 (split-line message-yank-prefix
) ;; Emacs 22.1+ supports arg.
6009 (defun message-insert-header (header value
)
6010 (insert (capitalize (symbol-name header
))
6012 (if (consp value
) (car value
) value
)))
6014 (defun message-field-name ()
6016 (goto-char (point-min))
6017 (when (looking-at "\\([^:]+\\):")
6018 (intern (capitalize (match-string 1))))))
6020 (defun message-fill-field ()
6023 (message-narrow-to-field)
6024 (let ((field-name (message-field-name)))
6025 (funcall (or (cadr (assq field-name message-field-fillers
))
6026 'message-fill-field-general
)))
6029 (defun message-fill-field-address ()
6031 (message-skip-to-next-address)
6033 (if (and (> (current-column) 78)
6039 (setq last
(1+ (point))))
6040 (setq last
(1+ (point)))))))
6042 (defun message-fill-field-general ()
6043 (let ((begin (point))
6046 (while (and (search-forward "\n" nil t
)
6048 (replace-match " " t t
))
6049 (fill-region-as-paragraph begin
(point-max))
6050 ;; Tapdance around looong Message-IDs.
6052 (when (looking-at "[ \t]*$")
6053 (message-delete-line))
6055 (search-forward ":" nil t
)
6056 (when (looking-at "\n[ \t]+")
6057 (replace-match " " t t
))
6058 (goto-char (point-max))))
6060 (defun message-shorten-1 (list cut surplus
)
6061 "Cut SURPLUS elements out of LIST, beginning with CUTth one."
6062 (setcdr (nthcdr (- cut
2) list
)
6063 (nthcdr (+ (- cut
2) surplus
1) list
)))
6065 (defun message-shorten-references (header references
)
6066 "Trim REFERENCES to be 21 Message-ID long or less, and fold them.
6067 When sending via news, also check that the REFERENCES are less
6068 than 988 characters long, and if they are not, trim them until
6070 ;; 21 is the number suggested by USEAGE.
6077 (goto-char (point-min))
6078 ;; Cons a list of valid references. GNKSA says we must not include MIDs
6079 ;; with whitespace or missing brackets (7.a "Does not propagate broken
6080 ;; Message-IDs in original References").
6081 (while (re-search-forward "<[^ <]+@[^ <]+>" nil t
)
6082 (push (match-string 0) refs
))
6083 (setq refs
(nreverse refs
)
6084 count
(length refs
)))
6086 ;; If the list has more than MAXCOUNT elements, trim it by
6087 ;; removing the CUTth element and the required number of
6088 ;; elements that follow.
6089 (when (> count maxcount
)
6090 (let ((surplus (- count maxcount
)))
6091 (message-shorten-1 refs cut surplus
)
6092 (decf count surplus
)))
6094 ;; When sending via news, make sure the total folded length will
6095 ;; be less than 998 characters. This is to cater to broken INN
6096 ;; 2.3 which counts the total number of characters in a header
6097 ;; rather than the physical line length of each line, as it should.
6099 ;; This hack should be removed when it's believed than INN 2.3 is
6100 ;; no longer widely used.
6102 ;; At this point the headers have not been generated, thus we use
6103 ;; message-this-is-news directly.
6104 (when message-this-is-news
6107 (message-insert-header
6108 header
(mapconcat #'identity refs
" "))
6110 (message-shorten-1 refs cut
1)))
6111 ;; Finally, collect the references back into a string and insert
6112 ;; it into the buffer.
6113 (message-insert-header header
(mapconcat #'identity refs
" "))))
6115 (defun message-position-point ()
6116 "Move point to where the user probably wants to find it."
6117 (message-narrow-to-headers)
6119 ((re-search-forward "^[^:]+:[ \t]*$" nil t
)
6120 (search-backward ":" )
6123 (if (eq (char-after) ?
)
6127 (goto-char (point-max))
6130 (unless (looking-at "$")
6134 (defcustom message-beginning-of-line t
6135 "Whether \\<message-mode-map>\\[message-beginning-of-line]\
6136 goes to beginning of header values."
6138 :group
'message-buffers
6139 :link
'(custom-manual "(message)Movement")
6142 (defun message-beginning-of-line (&optional n
)
6143 "Move point to beginning of header value or to beginning of line.
6144 The prefix argument N is passed directly to `beginning-of-line'.
6146 This command is identical to `beginning-of-line' if point is
6147 outside the message header or if the option `message-beginning-of-line'
6150 If point is in the message header and on a (non-continued) header
6151 line, move point to the beginning of the header value or the beginning of line,
6152 whichever is closer. If point is already at beginning of line, move point to
6153 beginning of header value. Therefore, repeated calls will toggle point
6154 between beginning of field and beginning of line."
6156 (let ((zrs 'zmacs-region-stays
))
6157 (when (and (featurep 'xemacs
) (interactive-p) (boundp zrs
))
6159 (if (and message-beginning-of-line
6160 (message-point-in-header-p))
6161 (let* ((here (point))
6162 (bol (progn (beginning-of-line n
) (point)))
6163 (eol (point-at-eol))
6164 (eoh (re-search-forward ": *" eol t
)))
6166 (if (and eoh
(or (< eoh here
) (= bol here
)))
6168 (beginning-of-line n
)))
6170 (defun message-buffer-name (type &optional to group
)
6171 "Return a new (unique) buffer name based on TYPE and TO."
6173 ;; Generate a new buffer name The Message Way.
6174 ((memq message-generate-new-buffers
'(unique t
))
6175 (generate-new-buffer-name
6179 (or (car (mail-extract-address-components to
))
6182 (if (and group
(not (string= group
""))) (concat " on " group
) "")
6184 ;; Check whether `message-generate-new-buffers' is a function,
6185 ;; and if so, call it.
6186 ((functionp message-generate-new-buffers
)
6187 (funcall message-generate-new-buffers type to group
))
6188 ((eq message-generate-new-buffers
'unsent
)
6189 (generate-new-buffer-name
6190 (concat "*unsent " type
6193 (or (car (mail-extract-address-components to
))
6196 (if (and group
(not (string= group
""))) (concat " on " group
) "")
6198 ;; Search for the existing message buffer with the specified name.
6200 (let* ((new (if (eq message-generate-new-buffers
'standard
)
6201 (generate-new-buffer-name (concat "*" type
" message*"))
6202 (let ((message-generate-new-buffers 'unique
))
6203 (message-buffer-name type to group
))))
6204 (regexp (concat "\\`"
6206 (if (string-match "<[0-9]+>\\'" new
)
6207 (substring new
0 (match-beginning 0))
6209 "\\(?:<\\([0-9]+\\)>\\)?\\'"))
6210 (case-fold-search nil
))
6217 (when (and (string-match regexp
(setq b
(buffer-name b
)))
6218 (eq (with-current-buffer b major-mode
)
6220 (cons (string-to-number (or (match-string 1 b
) "1"))
6223 'car-less-than-car
)))
6226 (defun message-pop-to-buffer (name &optional switch-function
)
6227 "Pop to buffer NAME, and warn if it already exists and is modified."
6228 (let ((buffer (get-buffer name
)))
6230 (buffer-name buffer
))
6231 (let ((window (get-buffer-window buffer
0)))
6233 ;; Raise the frame already displaying the message buffer.
6235 (gnus-select-frame-set-input-focus (window-frame window
))
6236 (select-window window
))
6237 (funcall (or switch-function
'pop-to-buffer
) buffer
)
6238 (set-buffer buffer
))
6239 (when (and (buffer-modified-p)
6242 "Message already being composed; erase? ")
6244 (error "Message being composed")))
6245 (funcall (or switch-function
'pop-to-buffer
) name
)
6250 (defun message-do-send-housekeeping ()
6251 "Kill old message buffers."
6252 ;; We might have sent this buffer already. Delete it from the
6254 (setq message-buffer-list
(delq (current-buffer) message-buffer-list
))
6255 (while (and message-max-buffers
6257 (>= (length message-buffer-list
) message-max-buffers
))
6258 ;; Kill the oldest buffer -- unless it has been changed.
6259 (let ((buffer (pop message-buffer-list
)))
6260 (when (and (buffer-name buffer
)
6261 (not (buffer-modified-p buffer
)))
6262 (kill-buffer buffer
))))
6263 ;; Rename the buffer.
6264 (if message-send-rename-function
6265 (funcall message-send-rename-function
)
6266 ;; Note: mail-abbrevs of XEmacs renames buffer name behind Gnus.
6268 "\\`\\*\\(sent \\|unsent \\)?\\(.+\\)\\*[^\\*]*\\|\\`mail to "
6270 (let ((name (match-string 2 (buffer-name)))
6272 (if (not (or (null name
)
6273 (string-equal name
"mail")
6274 (string-equal name
"posting")))
6275 (setq name
(concat "*sent " name
"*"))
6276 (message-narrow-to-headers)
6277 (setq to
(message-fetch-field "to"))
6278 (setq group
(message-fetch-field "newsgroups"))
6282 (to (concat "*sent mail to "
6283 (or (car (mail-extract-address-components to
))
6285 ((and group
(not (string= group
"")))
6286 (concat "*sent posting on " group
"*"))
6287 (t "*sent mail*"))))
6288 (unless (string-equal name
(buffer-name))
6289 (rename-buffer name t
)))))
6290 ;; Push the current buffer onto the list.
6291 (when message-max-buffers
6292 (setq message-buffer-list
6293 (nconc message-buffer-list
(list (current-buffer))))))
6295 (defun message-mail-user-agent ()
6297 ((not message-mail-user-agent
) nil
)
6298 ((eq message-mail-user-agent t
) mail-user-agent
)
6299 (t message-mail-user-agent
))))
6300 (if (memq mua
'(message-user-agent gnus-user-agent
))
6304 ;; YANK-ACTION, if non-nil, can be a buffer or a yank action of the
6305 ;; form (FUNCTION . ARGS).
6306 (defun message-setup (headers &optional yank-action actions
6307 continue switch-function
)
6308 (let ((mua (message-mail-user-agent))
6310 (if (not (and message-this-is-mail mua
))
6311 (message-setup-1 headers yank-action actions
)
6312 (setq headers
(copy-sequence headers
))
6313 (setq field
(assq 'Subject headers
))
6315 (setq subject
(cdr field
))
6316 (setq headers
(delq field headers
)))
6317 (setq field
(assq 'To headers
))
6319 (setq to
(cdr field
))
6320 (setq headers
(delq field headers
)))
6321 (let ((mail-user-agent mua
))
6322 (compose-mail to subject
6323 (mapcar (lambda (item)
6325 (format "%s" (car item
))
6328 continue switch-function
6329 (if (bufferp yank-action
)
6330 (list 'insert-buffer yank-action
)
6334 (defun message-headers-to-generate (headers included-headers excluded-headers
)
6335 "Return a list that includes all headers from HEADERS.
6336 If INCLUDED-HEADERS is a list, just include those headers. If it is
6337 t, include all headers. In any case, headers from EXCLUDED-HEADERS
6341 (dolist (header headers
)
6342 (setq header-name
(cond
6343 ((and (consp header
)
6344 (eq (car header
) 'optional
))
6345 ;; On the form (optional . Header)
6348 ;; On the form (Header . function)
6353 (when (and (not (memq header-name excluded-headers
))
6354 (or (eq included-headers t
)
6355 (memq header-name included-headers
)))
6356 (push header result
)))
6359 (defun message-setup-1 (headers &optional yank-action actions
)
6360 (dolist (action actions
)
6362 (add-to-list 'message-send-actions
6363 `(apply ',(car action
) ',(cdr action
)))))
6364 (setq message-reply-buffer
6365 (if (and (consp yank-action
)
6366 (eq (car yank-action
) 'insert-buffer
))
6369 (goto-char (point-min))
6370 ;; Insert all the headers.
6373 (alist message-header-format-alist
))
6375 (unless (assq (caar h
) message-header-format-alist
)
6376 (push (list (caar h
)) alist
))
6380 (delete-region (point) (progn (forward-line -
1) (point)))
6381 (when message-default-headers
6383 (if (functionp message-default-headers
)
6384 (funcall message-default-headers
)
6385 message-default-headers
))
6386 (or (bolp) (insert ?
\n)))
6387 (insert mail-header-separator
"\n")
6389 (when (message-news-p)
6390 (when message-default-news-headers
6391 (insert message-default-news-headers
)
6392 (or (bolp) (insert ?
\n)))
6393 (when message-generate-headers-first
6394 (message-generate-headers
6395 (message-headers-to-generate
6396 (append message-required-news-headers
6397 message-required-headers
)
6398 message-generate-headers-first
6399 '(Lines Subject
)))))
6400 (when (message-mail-p)
6401 (when message-default-mail-headers
6402 (insert message-default-mail-headers
)
6403 (or (bolp) (insert ?
\n)))
6404 (when message-generate-headers-first
6405 (message-generate-headers
6406 (message-headers-to-generate
6407 (append message-required-mail-headers
6408 message-required-headers
)
6409 message-generate-headers-first
6410 '(Lines Subject
)))))
6411 (run-hooks 'message-signature-setup-hook
)
6412 (message-insert-signature)
6414 (message-narrow-to-headers)
6415 (run-hooks 'message-header-setup-hook
))
6416 (setq buffer-undo-list nil
)
6417 (when message-generate-hashcash
6418 ;; Generate hashcash headers for recipients already known
6419 (mail-add-payment-async))
6420 ;; Gnus posting styles are applied via buffer-local `message-setup-hook'
6422 (run-hooks 'message-setup-hook
)
6423 ;; Do this last to give it precedence over posting styles, etc.
6424 (when (message-mail-p)
6426 (message-narrow-to-headers)
6427 (if message-alternative-emails
6428 (message-use-alternative-email-as-from))))
6429 (message-position-point)
6430 ;; Allow correct handling of `message-checksum' in `message-yank-original':
6431 (set-buffer-modified-p nil
)
6434 (defun message-set-auto-save-file-name ()
6435 "Associate the message buffer with a file in the drafts directory."
6436 (when message-auto-save-directory
6437 (unless (file-directory-p
6438 (directory-file-name message-auto-save-directory
))
6439 (make-directory message-auto-save-directory t
))
6441 (setq message-draft-article
6442 (nndraft-request-associate-buffer "drafts"))
6444 ;; If Gnus were alive, draft messages would be saved in the drafts folder.
6445 ;; But Gnus is not alive, so arrange to save the draft message in a
6446 ;; regular file in message-auto-save-directory. Append a unique
6447 ;; time-based suffix to the filename to allow multiple drafts to be saved
6448 ;; simultaneously without overwriting each other (which mimics the
6449 ;; functionality of the Gnus drafts folder).
6450 (setq buffer-file-name
(expand-file-name
6452 (if (memq system-type
6453 '(ms-dos windows-nt cygwin
))
6456 (format-time-string "-%Y%m%d-%H%M%S"))
6457 message-auto-save-directory
))
6458 (setq buffer-auto-save-file-name
(make-auto-save-file-name)))
6459 (clear-visited-file-modtime)
6460 (setq buffer-file-coding-system message-draft-coding-system
)))
6462 (defun message-disassociate-draft ()
6463 "Disassociate the message buffer from the drafts directory."
6464 (when message-draft-article
6465 (nndraft-request-expire-articles
6466 (list message-draft-article
) "drafts" nil t
)))
6468 (defun message-insert-headers ()
6469 "Generate the headers for the article."
6473 (message-narrow-to-headers)
6474 (when (message-news-p)
6475 (message-generate-headers
6478 (copy-sequence message-required-news-headers
)))))
6479 (when (message-mail-p)
6480 (message-generate-headers
6483 (copy-sequence message-required-mail-headers
))))))))
6488 ;;; Commands for interfacing with message
6492 (defun message-mail (&optional to subject
6493 other-headers continue switch-function
6494 yank-action send-actions
)
6495 "Start editing a mail message to be sent.
6496 OTHER-HEADERS is an alist of header/value pairs. CONTINUE says whether
6497 to continue editing a message already being composed. SWITCH-FUNCTION
6498 is a function used to switch to and display the mail buffer."
6500 (let ((message-this-is-mail t
))
6501 (unless (message-mail-user-agent)
6502 (message-pop-to-buffer
6503 ;; Search for the existing message buffer if `continue' is non-nil.
6504 (let ((message-generate-new-buffers
6505 (when (or (not continue
)
6506 (eq message-generate-new-buffers
'standard
)
6507 (functionp message-generate-new-buffers
))
6508 message-generate-new-buffers
)))
6509 (message-buffer-name "mail" to
))
6513 `((To .
,(or to
"")) (Subject .
,(or subject
"")))
6514 (when other-headers other-headers
))
6515 yank-action send-actions continue switch-function
)
6516 ;; FIXME: Should return nil if failure.
6520 (defun message-news (&optional newsgroups subject
)
6521 "Start editing a news article to be sent."
6523 (let ((message-this-is-news t
))
6524 (message-pop-to-buffer (message-buffer-name "posting" nil newsgroups
))
6525 (message-setup `((Newsgroups .
,(or newsgroups
""))
6526 (Subject .
,(or subject
""))))))
6528 (defun message-alter-recipients-discard-bogus-full-name (addrcell)
6529 "Discard mail address in full names.
6530 When the full name in reply headers contains the mail
6531 address (e.g. \"foo@bar <foo@bar>\"), discard full name.
6532 ADDRCELL is a cons cell where the car is the mail address and the
6533 cdr is the complete address (full name and mail address)."
6534 (if (string-match (concat (regexp-quote (car addrcell
)) ".*"
6535 (regexp-quote (car addrcell
)))
6537 (cons (car addrcell
) (car addrcell
))
6540 (defcustom message-alter-recipients-function nil
6541 "Function called to allow alteration of reply header structures.
6542 It is called in `message-get-reply-headers' for each recipient.
6543 The function is called with one parameter, a cons cell ..."
6544 :type
'(choice (const :tag
"None" nil
)
6545 (const :tag
"Discard bogus full name"
6546 message-alter-recipients-discard-bogus-full-name
)
6548 :version
"23.1" ;; No Gnus
6549 :group
'message-headers
)
6551 (defun message-get-reply-headers (wide &optional to-address address-headers
)
6552 (let (follow-to mct never-mct to cc author mft recipients extra
)
6553 ;; Find all relevant headers we need.
6555 (message-narrow-to-headers-or-head)
6556 ;; Gmane renames "To". Look at "Original-To", too, if it is present in
6557 ;; message-header-synonyms.
6558 (setq to
(or (message-fetch-field "to")
6559 (and (loop for synonym in message-header-synonyms
6560 when
(memq 'Original-To synonym
)
6562 (message-fetch-field "original-to")))
6563 cc
(message-fetch-field "cc")
6564 extra
(when message-extra-wide-headers
6565 (mapconcat 'identity
6566 (mapcar 'message-fetch-field
6567 message-extra-wide-headers
)
6569 mct
(message-fetch-field "mail-copies-to")
6570 author
(or (message-fetch-field "mail-reply-to")
6571 (message-fetch-field "reply-to")
6572 (message-fetch-field "from")
6574 mft
(and message-use-mail-followup-to
6575 (message-fetch-field "mail-followup-to"))))
6577 ;; Handle special values of Mail-Copies-To.
6579 (cond ((or (equal (downcase mct
) "never")
6580 (equal (downcase mct
) "nobody"))
6583 ((or (equal (downcase mct
) "always")
6584 (equal (downcase mct
) "poster"))
6585 (setq mct author
))))
6588 ;; Build (textual) list of new recipient addresses.
6591 (setq recipients
(concat ", " to-address
))
6592 ;; If the author explicitly asked for a copy, we don't deny it to them.
6593 (if mct
(setq recipients
(concat recipients
", " mct
))))
6595 (setq recipients
(concat ", " author
)))
6597 (dolist (header address-headers
)
6598 (let ((value (message-fetch-field header
)))
6600 (setq recipients
(concat recipients
", " value
))))))
6602 (string-match "[^ \t,]" mft
)
6603 (or (not (eq message-use-mail-followup-to
'ask
))
6604 (message-y-or-n-p "Obey Mail-Followup-To? " t
"\
6605 You should normally obey the Mail-Followup-To: header. In this
6606 article, it has the value of
6610 which directs your response to " (if (string-match "," mft
)
6611 "the specified addresses"
6612 "that address only") ".
6614 Most commonly, Mail-Followup-To is used by a mailing list poster to
6615 express that responses should be sent to just the list, and not the
6618 If a message is posted to several mailing lists, Mail-Followup-To may
6619 also be used to direct the following discussion to one list only,
6620 because discussions that are spread over several lists tend to be
6621 fragmented and very difficult to follow.
6623 Also, some source/announcement lists are not intended for discussion;
6624 responses here are directed to other addresses.
6626 You may customize the variable `message-use-mail-followup-to', if you
6627 want to get rid of this query permanently.")))
6628 (setq recipients
(concat ", " mft
)))
6630 (setq recipients
(if never-mct
"" (concat ", " author
)))
6631 (if to
(setq recipients
(concat recipients
", " to
)))
6632 (if cc
(setq recipients
(concat recipients
", " cc
)))
6633 (if extra
(setq recipients
(concat recipients
", " extra
)))
6634 (if mct
(setq recipients
(concat recipients
", " mct
)))))
6635 (if (>= (length recipients
) 2)
6636 ;; Strip the leading ", ".
6637 (setq recipients
(substring recipients
2)))
6638 ;; Squeeze whitespace.
6639 (while (string-match "[ \t][ \t]+" recipients
)
6640 (setq recipients
(replace-match " " t t recipients
)))
6641 ;; Remove addresses that match `rmail-dont-reply-to-names'.
6642 (let ((rmail-dont-reply-to-names (message-dont-reply-to-names)))
6643 (setq recipients
(rmail-dont-reply-to recipients
)))
6644 ;; Perhaps "Mail-Copies-To: never" removed the only address?
6645 (if (string-equal recipients
"")
6646 (setq recipients author
))
6647 ;; Convert string to a list of (("foo@bar" . "Name <Foo@BAR>") ...).
6651 (if message-alter-recipients-function
6652 (funcall message-alter-recipients-function
6653 (cons (downcase (mail-strip-quoted-names addr
))
6655 (cons (downcase (mail-strip-quoted-names addr
)) addr
)))
6656 (message-tokenize-header recipients
)))
6657 ;; Remove first duplicates. (Why not all duplicates? Is this a bug?)
6658 (let ((s recipients
))
6660 (setq recipients
(delq (assoc (car (pop s
)) s
) recipients
))))
6662 ;; Remove hierarchical lists that are contained within each other,
6663 ;; if message-hierarchical-addresses is defined.
6664 (when message-hierarchical-addresses
6665 (let ((plain-addrs (mapcar 'car recipients
))
6668 (setq subaddrs
(assoc (car plain-addrs
)
6669 message-hierarchical-addresses
)
6670 plain-addrs
(cdr plain-addrs
))
6672 (setq subaddrs
(cdr subaddrs
))
6674 (setq recip
(assoc (car subaddrs
) recipients
)
6675 subaddrs
(cdr subaddrs
))
6677 (setq recipients
(delq recip recipients
))))))))
6679 (setq recipients
(message-prune-recipients recipients
))
6681 ;; Build the header alist. Allow the user to be asked whether
6682 ;; or not to reply to all recipients in a wide reply.
6683 (setq follow-to
(list (cons 'To
(cdr (pop recipients
)))))
6684 (when (and recipients
6685 (or (not message-wide-reply-confirm-recipients
)
6686 (y-or-n-p "Reply to all recipients? ")))
6687 (setq recipients
(mapconcat
6688 (lambda (addr) (cdr addr
)) recipients
", "))
6689 (if (string-match "^ +" recipients
)
6690 (setq recipients
(substring recipients
(match-end 0))))
6691 (push (cons 'Cc recipients
) follow-to
)))
6694 (defun message-prune-recipients (recipients)
6695 (dolist (rule message-prune-recipient-rules
)
6696 (let ((match (car rule
))
6699 (dolist (recipient recipients
)
6700 (setq address
(car recipient
))
6701 (when (string-match match address
)
6702 (setq dup-match
(replace-match (cadr rule
) nil nil address
))
6703 (dolist (recipient recipients
)
6704 ;; Don't delete the address that triggered this.
6705 (when (and (not (eq address
(car recipient
)))
6706 (string-match dup-match
(car recipient
)))
6707 (setq recipients
(delq recipient recipients
))))))))
6710 (defcustom message-simplify-subject-functions
6711 '(message-strip-list-identifiers
6712 message-strip-subject-re
6713 message-strip-subject-trailing-was
6714 message-strip-subject-encoded-words
)
6715 "List of functions taking a string argument that simplify subjects.
6716 The functions are applied when replying to a message.
6718 Useful functions to put in this list include:
6719 `message-strip-list-identifiers', `message-strip-subject-re',
6720 `message-strip-subject-trailing-was', and
6721 `message-strip-subject-encoded-words'."
6722 :version
"22.1" ;; Gnus 5.10.9
6723 :group
'message-various
6724 :type
'(repeat function
))
6726 (defun message-simplify-subject (subject &optional functions
)
6727 "Return simplified SUBJECT."
6730 (setq functions message-simplify-subject-functions
))
6731 (when (and (memq 'message-strip-list-identifiers functions
)
6732 gnus-list-identifiers
)
6733 (setq subject
(message-strip-list-identifiers subject
)))
6734 (when (memq 'message-strip-subject-re functions
)
6735 (setq subject
(concat "Re: " (message-strip-subject-re subject
))))
6736 (when (and (memq 'message-strip-subject-trailing-was functions
)
6737 message-subject-trailing-was-query
)
6738 (setq subject
(message-strip-subject-trailing-was subject
)))
6739 (when (memq 'message-strip-subject-encoded-words functions
)
6740 (setq subject
(message-strip-subject-encoded-words subject
)))
6744 (defun message-reply (&optional to-address wide
)
6745 "Start editing a reply to the article in the current buffer."
6747 (require 'gnus-sum
) ; for gnus-list-identifiers
6748 (let ((cur (current-buffer))
6749 from subject date reply-to to cc
6750 references message-id follow-to
6751 (inhibit-point-motion-hooks t
)
6752 (message-this-is-mail t
)
6755 (message-narrow-to-head-1)
6756 ;; Allow customizations to have their say.
6758 ;; This is a regular reply.
6759 (when (functionp message-reply-to-function
)
6761 (setq follow-to
(funcall message-reply-to-function
))))
6762 ;; This is a followup.
6763 (when (functionp message-wide-reply-to-function
)
6766 (funcall message-wide-reply-to-function
)))))
6767 (setq message-id
(message-fetch-field "message-id" t
)
6768 references
(message-fetch-field "references")
6769 date
(message-fetch-field "date")
6770 from
(or (message-fetch-field "from") "nobody")
6771 subject
(or (message-fetch-field "subject") "none"))
6773 ;; Strip list identifiers, "Re: ", and "was:"
6774 (setq subject
(message-simplify-subject subject
))
6776 (when (and (setq gnus-warning
(message-fetch-field "gnus-warning"))
6777 (string-match "<[^>]+>" gnus-warning
))
6778 (setq message-id
(match-string 0 gnus-warning
)))
6781 (setq follow-to
(message-get-reply-headers wide to-address
))))
6783 (unless (message-mail-user-agent)
6784 (message-pop-to-buffer
6785 (message-buffer-name
6786 (if wide
"wide reply" "reply") from
6787 (if wide to-address nil
))))
6789 (setq message-reply-headers
6790 (vector 0 subject from date message-id references
0 0 ""))
6793 `((Subject .
,subject
)
6798 (defun message-wide-reply (&optional to-address
)
6799 "Make a \"wide\" reply to the message in the current buffer."
6801 (message-reply to-address t
))
6804 (defun message-followup (&optional to-newsgroups
)
6805 "Follow up to the message in the current buffer.
6806 If TO-NEWSGROUPS, use that as the new Newsgroups line."
6808 (require 'gnus-sum
) ; for gnus-list-identifiers
6809 (let ((cur (current-buffer))
6810 from subject date reply-to mrt mct
6811 references message-id follow-to
6812 (inhibit-point-motion-hooks t
)
6813 (message-this-is-news t
)
6814 followup-to distribution newsgroups gnus-warning posted-to
)
6817 (goto-char (point-min))
6818 (if (search-forward "\n\n" nil t
)
6821 (when (functionp message-followup-to-function
)
6823 (funcall message-followup-to-function
)))
6824 (setq from
(message-fetch-field "from")
6825 date
(message-fetch-field "date")
6826 subject
(or (message-fetch-field "subject") "none")
6827 references
(message-fetch-field "references")
6828 message-id
(message-fetch-field "message-id" t
)
6829 followup-to
(message-fetch-field "followup-to")
6830 newsgroups
(message-fetch-field "newsgroups")
6831 posted-to
(message-fetch-field "posted-to")
6832 reply-to
(message-fetch-field "reply-to")
6833 mrt
(message-fetch-field "mail-reply-to")
6834 distribution
(message-fetch-field "distribution")
6835 mct
(message-fetch-field "mail-copies-to"))
6836 (when (and (setq gnus-warning
(message-fetch-field "gnus-warning"))
6837 (string-match "<[^>]+>" gnus-warning
))
6838 (setq message-id
(match-string 0 gnus-warning
)))
6839 ;; Remove bogus distribution.
6840 (when (and (stringp distribution
)
6841 (let ((case-fold-search t
))
6842 (string-match "world" distribution
)))
6843 (setq distribution nil
))
6844 ;; Strip list identifiers, "Re: ", and "was:"
6845 (setq subject
(message-simplify-subject subject
))
6848 (message-pop-to-buffer (message-buffer-name "followup" from newsgroups
))
6850 (setq message-reply-headers
6851 (vector 0 subject from date message-id references
0 0 ""))
6854 `((Subject .
,subject
)
6857 (list (cons 'Newsgroups to-newsgroups
)))
6858 (follow-to follow-to
)
6859 ((and followup-to message-use-followup-to
)
6862 ((equal (downcase followup-to
) "poster")
6863 (if (or (eq message-use-followup-to
'use
)
6864 (message-y-or-n-p "Obey Followup-To: poster? " t
"\
6865 You should normally obey the Followup-To: header.
6867 `Followup-To: poster' sends your response via e-mail instead of news.
6869 A typical situation where `Followup-To: poster' is used is when the poster
6870 does not read the newsgroup, so he wouldn't see any replies sent to it.
6872 You may customize the variable `message-use-followup-to', if you
6873 want to get rid of this query permanently."))
6875 (setq message-this-is-news nil
)
6876 (cons 'To
(or mrt reply-to from
"")))
6877 (cons 'Newsgroups newsgroups
)))
6879 (if (or (equal followup-to newsgroups
)
6880 (not (eq message-use-followup-to
'ask
))
6882 (concat "Obey Followup-To: " followup-to
"? ") t
"\
6883 You should normally obey the Followup-To: header.
6885 `Followup-To: " followup-to
"'
6886 directs your response to " (if (string-match "," followup-to
)
6887 "the specified newsgroups"
6888 "that newsgroup only") ".
6890 If a message is posted to several newsgroups, Followup-To is often
6891 used to direct the following discussion to one newsgroup only,
6892 because discussions that are spread over several newsgroup tend to
6893 be fragmented and very difficult to follow.
6895 Also, some source/announcement newsgroups are not intended for discussion;
6896 responses here are directed to other newsgroups.
6898 You may customize the variable `message-use-followup-to', if you
6899 want to get rid of this query permanently."))
6900 (cons 'Newsgroups followup-to
)
6901 (cons 'Newsgroups newsgroups
))))))
6903 `((Newsgroups .
,posted-to
)))
6905 `((Newsgroups .
,newsgroups
))))
6906 ,@(and distribution
(list (cons 'Distribution distribution
)))
6908 (not (or (equal (downcase mct
) "never")
6909 (equal (downcase mct
) "nobody"))))
6910 (list (cons 'Cc
(if (or (equal (downcase mct
) "always")
6911 (equal (downcase mct
) "poster"))
6912 (or mrt reply-to from
"")
6917 (defun message-is-yours-p ()
6918 "Non-nil means current article is yours.
6919 If you have added 'cancel-messages to `message-shoot-gnksa-feet', all articles
6920 are yours except those that have Cancel-Lock header not belonging to you.
6921 Instead of shooting GNKSA feet, you should modify `message-alternative-emails'
6922 regexp to match all of yours addresses."
6923 ;; Canlock-logic as suggested by Per Abrahamsen
6924 ;; <abraham@dina.kvl.dk>
6926 ;; IF article has cancel-lock THEN
6927 ;; IF we can verify it THEN
6930 ;; error: cancellock: article is not yours
6932 ;; Use old rules, comparing sender...
6935 (message-narrow-to-head-1)
6936 (if (message-fetch-field "Cancel-Lock")
6937 (if (null (canlock-verify))
6939 (error "Failed to verify Cancel-lock: This article is not yours"))
6942 (message-gnksa-enable-p 'cancel-messages
)
6943 (and (setq sender
(message-fetch-field "sender"))
6944 (string-equal (downcase sender
)
6945 (downcase (message-make-sender))))
6946 ;; Email address in From field equals to our address
6947 (and (setq from
(message-fetch-field "from"))
6949 (downcase (car (mail-header-parse-address from
)))
6950 (downcase (car (mail-header-parse-address
6951 (message-make-from))))))
6952 ;; Email address in From field matches
6953 ;; 'message-alternative-emails' regexp
6955 message-alternative-emails
6957 message-alternative-emails
6958 (car (mail-header-parse-address from
))))))))))
6961 (defun message-cancel-news (&optional arg
)
6962 "Cancel an article you posted.
6963 If ARG, allow editing of the cancellation message."
6965 (unless (message-news-p)
6966 (error "This is not a news article; canceling is impossible"))
6967 (let (from newsgroups message-id distribution buf
)
6969 ;; Get header info from original article.
6971 (message-narrow-to-head-1)
6972 (setq from
(message-fetch-field "from")
6973 newsgroups
(message-fetch-field "newsgroups")
6974 message-id
(message-fetch-field "message-id" t
)
6975 distribution
(message-fetch-field "distribution")))
6976 ;; Make sure that this article was written by the user.
6977 (unless (message-is-yours-p)
6978 (error "This article is not yours"))
6979 (when (yes-or-no-p "Do you really want to cancel this article? ")
6980 ;; Make control message.
6983 (setq buf
(set-buffer (get-buffer-create " *message cancel*"))))
6985 (insert "Newsgroups: " newsgroups
"\n"
6987 "Subject: cmsg cancel " message-id
"\n"
6988 "Control: cancel " message-id
"\n"
6990 (concat "Distribution: " distribution
"\n")
6992 mail-header-separator
"\n"
6993 message-cancel-message
)
6994 (run-hooks 'message-cancel-hook
)
6996 (message "Canceling your article...")
6997 (if (let ((message-syntax-checks
6998 'dont-check-for-anything-just-trust-me
))
6999 (funcall message-send-news-function
))
7000 (message "Canceling your article...done"))
7001 (kill-buffer buf
))))))
7004 (defun message-supersede ()
7005 "Start composing a message to supersede the current message.
7006 This is done simply by taking the old article and adding a Supersedes
7007 header line with the old Message-ID."
7009 (let ((cur (current-buffer)))
7010 ;; Check whether the user owns the article that is to be superseded.
7011 (unless (message-is-yours-p)
7012 (error "This article is not yours"))
7013 ;; Get a normal message buffer.
7014 (message-pop-to-buffer (message-buffer-name "supersede"))
7015 (insert-buffer-substring cur
)
7017 (message-narrow-to-head-1)
7018 ;; Remove unwanted headers.
7019 (when message-ignored-supersedes-headers
7020 (message-remove-header message-ignored-supersedes-headers t
))
7021 (goto-char (point-min))
7022 (if (not (re-search-forward "^Message-ID: " nil t
))
7023 (error "No Message-ID in this article")
7024 (replace-match "Supersedes: " t t
))
7025 (goto-char (point-max))
7026 (insert mail-header-separator
)
7031 (defun message-recover ()
7032 "Reread contents of current buffer from its last auto-save file."
7034 (let ((file-name (make-auto-save-file-name)))
7035 (cond ((save-window-excursion
7036 (with-output-to-temp-buffer "*Directory*"
7037 (with-current-buffer standard-output
7038 (fundamental-mode)) ; for Emacs 20.4+
7039 (buffer-disable-undo standard-output
)
7040 (let ((default-directory "/"))
7042 "ls" nil standard-output nil
"-l" file-name
)))
7043 (yes-or-no-p (format "Recover auto save file %s? " file-name
)))
7044 (let ((buffer-read-only nil
))
7046 (insert-file-contents file-name nil
)))
7047 (t (error "message-recover cancelled")))))
7049 ;;; Washing Subject:
7051 (defun message-wash-subject (subject)
7052 "Remove junk like \"Re:\", \"(fwd)\", etc. added to subject string SUBJECT.
7053 Previous forwarders, replyers, etc. may add it."
7056 (goto-char (point-min))
7057 ;; strip Re/Fwd stuff off the beginning
7058 (while (re-search-forward
7059 "\\([Rr][Ee]:\\|[Ff][Ww][Dd]\\(\\[[0-9]*\\]\\)?:\\|[Ff][Ww]:\\)" nil t
)
7062 ;; and gnus-style forwards [foo@bar.com] subject
7063 (goto-char (point-min))
7064 (while (re-search-forward "\\[[^ \t]*\\(@\\|\\.\\)[^ \t]*\\]" nil t
)
7068 (goto-char (point-max))
7069 (while (re-search-backward "([Ff][Ww][Dd])" nil t
)
7072 ;; and finally, any whitespace that was left-over
7073 (goto-char (point-min))
7074 (while (re-search-forward "^[ \t]+" nil t
)
7076 (goto-char (point-max))
7077 (while (re-search-backward "[ \t]+$" nil t
)
7082 ;;; Forwarding messages.
7084 (defvar message-forward-decoded-p nil
7085 "Non-nil means the original message is decoded.")
7087 (defun message-forward-subject-name-subject (subject)
7088 "Generate a SUBJECT for a forwarded message.
7089 The form is: [Source] Subject, where if the original message was mail,
7090 Source is the name of the sender, and if the original message was
7091 news, Source is the list of newsgroups is was posted to."
7092 (let* ((group (message-fetch-field "newsgroups"))
7093 (from (message-fetch-field "from"))
7096 (gnus-group-decoded-name group
)
7098 (car (gnus-extract-address-components from
))
7099 (cadr (gnus-extract-address-components from
))))
7102 (if message-forward-decoded-p
7104 (mail-decode-encoded-word-string prefix
))
7107 (defun message-forward-subject-author-subject (subject)
7108 "Generate a SUBJECT for a forwarded message.
7109 The form is: [Source] Subject, where if the original message was mail,
7110 Source is the sender, and if the original message was news, Source is
7111 the list of newsgroups is was posted to."
7112 (let* ((group (message-fetch-field "newsgroups"))
7115 (gnus-group-decoded-name group
)
7116 (or (message-fetch-field "from")
7119 (if message-forward-decoded-p
7121 (mail-decode-encoded-word-string prefix
))
7124 (defun message-forward-subject-fwd (subject)
7125 "Generate a SUBJECT for a forwarded message.
7126 The form is: Fwd: Subject, where Subject is the original subject of
7128 (if (string-match "^Fwd: " subject
)
7130 (concat "Fwd: " subject
)))
7132 (defun message-make-forward-subject ()
7133 "Return a Subject header suitable for the message in the current buffer."
7136 (message-narrow-to-head-1)
7137 (let ((funcs message-make-forward-subject-function
)
7138 (subject (message-fetch-field "Subject")))
7141 (if message-forward-decoded-p
7143 (mail-decode-encoded-word-string subject
))
7145 (when message-wash-forwarded-subjects
7146 (setq subject
(message-wash-subject subject
)))
7147 ;; Make sure funcs is a list.
7150 (setq funcs
(list funcs
)))
7151 ;; Apply funcs in order, passing subject generated by previous
7152 ;; func to the next one.
7153 (dolist (func funcs
)
7154 (when (functionp func
)
7155 (setq subject
(funcall func subject
))))
7158 (defvar gnus-article-decoded-p
)
7162 (defun message-forward (&optional news digest
)
7163 "Forward the current message via mail.
7164 Optional NEWS will use news to forward instead of mail.
7165 Optional DIGEST will use digest to forward."
7167 (let* ((cur (current-buffer))
7168 (message-forward-decoded-p
7169 (if (local-variable-p 'gnus-article-decoded-p
(current-buffer))
7170 gnus-article-decoded-p
;; In an article buffer.
7171 message-forward-decoded-p
))
7172 (subject (message-make-forward-subject)))
7174 (message-news nil subject
)
7175 (message-mail nil subject
))
7176 (message-forward-make-body cur digest
)))
7178 (defun message-forward-make-body-plain (forward-buffer)
7180 "\n-------------------- Start of forwarded message --------------------\n")
7182 (contents (with-current-buffer forward-buffer
(buffer-string)))
7184 (unless (featurep 'xemacs
)
7185 (unless (mm-multibyte-string-p contents
)
7186 (error "Attempt to insert unibyte string from the buffer \"%s\"\
7187 to the multibyte buffer \"%s\""
7188 (if (bufferp forward-buffer
)
7189 (buffer-name forward-buffer
)
7192 (insert (mm-with-multibyte-buffer
7195 (goto-char (point-min))
7196 (when (looking-at "From ")
7197 (replace-match "X-From-Line: "))
7199 (unless (bolp) (insert "\n"))
7202 "-------------------- End of forwarded message --------------------\n")
7203 (message-remove-ignored-headers b e
)))
7205 (defun message-remove-ignored-headers (b e
)
7206 (when message-forward-ignored-headers
7208 (narrow-to-region b e
)
7210 (narrow-to-region (point)
7211 (or (search-forward "\n\n" nil t
) (point)))
7212 (let ((ignored (if (stringp message-forward-ignored-headers
)
7213 (list message-forward-ignored-headers
)
7214 message-forward-ignored-headers
)))
7215 (dolist (elem ignored
)
7216 (message-remove-header elem t
))))))
7218 (defun message-forward-make-body-mime (forward-buffer)
7220 (insert "\n\n<#part type=message/rfc822 disposition=inline raw=t>\n")
7222 (narrow-to-region (point) (point))
7223 (mml-insert-buffer forward-buffer
)
7224 (goto-char (point-min))
7225 (when (looking-at "From ")
7226 (replace-match "X-From-Line: "))
7227 (goto-char (point-max)))
7228 (insert "<#/part>\n")
7229 ;; Consider there is no illegible text.
7230 (add-text-properties
7232 `(no-illegible-text t rear-nonsticky t start-open t
))))
7234 (defun message-forward-make-body-mml (forward-buffer)
7235 (insert "\n\n<#mml type=message/rfc822 disposition=inline>\n")
7236 (let ((b (point)) e
)
7237 (if (not message-forward-decoded-p
)
7238 (let ((contents (with-current-buffer forward-buffer
(buffer-string))))
7239 (unless (featurep 'xemacs
)
7240 (unless (mm-multibyte-string-p contents
)
7241 (error "Attempt to insert unibyte string from the buffer \"%s\"\
7242 to the multibyte buffer \"%s\""
7243 (if (bufferp forward-buffer
)
7244 (buffer-name forward-buffer
)
7247 (insert (mm-with-multibyte-buffer
7250 (goto-char (point-min))
7251 (when (looking-at "From ")
7252 (replace-match "X-From-Line: "))
7255 (narrow-to-region (point) (point))
7256 (mml-insert-buffer forward-buffer
)
7257 (goto-char (point-min))
7258 (when (looking-at "From ")
7259 (replace-match "X-From-Line: "))
7260 (goto-char (point-max))))
7262 (insert "<#/mml>\n")
7263 (when (and (not message-forward-decoded-p
)
7264 message-forward-ignored-headers
)
7265 (message-remove-ignored-headers b e
))))
7267 (defun message-forward-make-body-digest-plain (forward-buffer)
7269 "\n-------------------- Start of forwarded message --------------------\n")
7270 (let ((b (point)) e
)
7271 (mml-insert-buffer forward-buffer
)
7274 "\n-------------------- End of forwarded message --------------------\n")))
7276 (defun message-forward-make-body-digest-mime (forward-buffer)
7277 (insert "\n<#multipart type=digest>\n")
7278 (let ((b (point)) e
)
7279 (insert-buffer-substring forward-buffer
)
7281 (insert "<#/multipart>\n")
7283 (narrow-to-region b e
)
7285 (narrow-to-region (point)
7286 (or (search-forward "\n\n" nil t
) (point)))
7287 (delete-region (point-min) (point-max)))))
7289 (defun message-forward-make-body-digest (forward-buffer)
7290 (if message-forward-as-mime
7291 (message-forward-make-body-digest-mime forward-buffer
)
7292 (message-forward-make-body-digest-plain forward-buffer
)))
7294 (autoload 'mm-uu-dissect-text-parts
"mm-uu")
7295 (autoload 'mm-uu-dissect
"mm-uu")
7297 (defun message-signed-or-encrypted-p (&optional dont-emulate-mime handles
)
7298 "Say whether the current buffer contains signed or encrypted message.
7299 If DONT-EMULATE-MIME is nil, this function does the MIME emulation on
7300 messages that don't conform to PGP/MIME described in RFC2015. HANDLES
7301 is for the internal use."
7303 (let ((mm-decrypt-option 'never
)
7304 (mm-verify-option 'never
))
7305 (if (setq handles
(mm-dissect-buffer nil t
))
7306 (unless dont-emulate-mime
7307 (mm-uu-dissect-text-parts handles
))
7308 (unless dont-emulate-mime
7309 (setq handles
(mm-uu-dissect))))))
7310 ;; Check text/plain message in which there is a signed or encrypted
7311 ;; body that has been encoded by B or Q.
7312 (unless (or handles dont-emulate-mime
)
7313 (let ((cur (current-buffer))
7314 (mm-decrypt-option 'never
)
7315 (mm-verify-option 'never
))
7317 (insert-buffer-substring cur
)
7318 (when (setq handles
(mm-dissect-buffer t t
))
7320 (bufferp (car handles
))
7321 (mm-destroy-parts handles
))
7322 (equal (mm-handle-media-type handles
) "text/plain"))
7324 (mm-decode-content-transfer-encoding
7325 (mm-handle-encoding handles
))
7326 (setq handles
(mm-uu-dissect)))
7327 (setq handles nil
))))))
7331 (dolist (handle (if (stringp (car handles
))
7332 (if (member (car handles
)
7333 '("multipart/signed"
7334 "multipart/encrypted"))
7338 (if (stringp (car handle
))
7339 (when (message-signed-or-encrypted-p dont-emulate-mime handle
)
7341 (when (and (bufferp (car handle
))
7342 (equal (mm-handle-media-type handle
)
7344 (with-current-buffer (mm-handle-buffer handle
)
7345 (when (message-signed-or-encrypted-p dont-emulate-mime
)
7346 (throw 'found t
)))))))
7347 (mm-destroy-parts handles
))))
7350 (defun message-forward-make-body (forward-buffer &optional digest
)
7351 ;; Put point where we want it before inserting the forwarded
7353 (if message-forward-before-signature
7355 (goto-char (point-max)))
7357 (message-forward-make-body-digest forward-buffer
)
7358 (if message-forward-as-mime
7359 (if (and message-forward-show-mml
7360 (not (and (eq message-forward-show-mml
'best
)
7361 ;; Use the raw form in the body if it contains
7362 ;; signed or encrypted message so as not to be
7363 ;; destroyed by re-encoding.
7364 (with-current-buffer forward-buffer
7366 (message-signed-or-encrypted-p)
7368 (message-forward-make-body-mml forward-buffer
)
7369 (message-forward-make-body-mime forward-buffer
))
7370 (message-forward-make-body-plain forward-buffer
)))
7371 (message-position-point))
7373 (declare-function rmail-toggle-header
"rmail" (&optional arg
))
7376 (defun message-forward-rmail-make-body (forward-buffer)
7377 (save-window-excursion
7378 (set-buffer forward-buffer
)
7379 (if (rmail-msg-is-pruned)
7380 (if (fboundp 'rmail-msg-restore-non-pruned-header
)
7381 (rmail-msg-restore-non-pruned-header) ; Emacs 22
7382 (rmail-toggle-header 0)))) ; Emacs 23
7383 (message-forward-make-body forward-buffer
))
7385 ;; Fixme: Should have defcustom.
7387 (defun message-insinuate-rmail ()
7388 "Let RMAIL use message to forward."
7390 (setq rmail-enable-mime-composing t
)
7391 (setq rmail-insert-mime-forwarded-message-function
7392 'message-forward-rmail-make-body
))
7395 (defun message-resend (address)
7396 "Resend the current article to ADDRESS."
7398 (list (message-read-from-minibuffer "Resend message to: ")))
7399 (message "Resending message to %s..." address
)
7401 (let ((cur (current-buffer))
7403 ;; We first set up a normal mail buffer.
7404 (unless (message-mail-user-agent)
7405 (set-buffer (get-buffer-create " *message resend*"))
7407 (let ((message-this-is-mail t
)
7408 message-generate-hashcash
7410 (message-setup `((To .
,address
))))
7411 ;; Insert our usual headers.
7412 (message-generate-headers '(From Date To Message-ID
))
7413 (message-narrow-to-headers)
7414 ;; Remove X-Draft-From header etc.
7415 (message-remove-header message-ignored-mail-headers t
)
7416 ;; Rename them all to "Resent-*".
7417 (goto-char (point-min))
7418 (while (re-search-forward "^[A-Za-z]" nil t
)
7423 (delete-region (point) (point-max))
7425 ;; Insert the message to be resent.
7426 (insert-buffer-substring cur
)
7427 (goto-char (point-min))
7428 (search-forward "\n\n")
7431 (narrow-to-region beg
(point))
7432 (message-remove-header message-ignored-resent-headers t
)
7433 (goto-char (point-max)))
7434 (insert mail-header-separator
)
7435 ;; Rename all old ("Also-")Resent headers.
7436 (while (re-search-backward "^\\(Also-\\)*Resent-" beg t
)
7439 ;; Quote any "From " lines at the beginning.
7441 (when (looking-at "From ")
7442 (replace-match "X-From-Line: "))
7444 (let ((message-inhibit-body-encoding
7445 ;; Don't do any further encoding if it looks like the
7446 ;; message has already been encoded.
7447 (let ((case-fold-search t
))
7448 (re-search-forward "^mime-version:" nil t
)))
7449 (message-inhibit-ecomplete t
)
7450 message-required-mail-headers
7451 message-generate-hashcash
7452 rfc2047-encode-encoded-words
)
7453 (message-send-mail))
7454 (kill-buffer (current-buffer)))
7455 (message "Resending message to %s...done" address
)))
7458 (defun message-bounce ()
7459 "Re-mail the current message.
7460 This only makes sense if the current message is a bounce message that
7461 contains some mail you have written which has been bounced back to
7464 (let ((handles (mm-dissect-buffer t
))
7466 (message-pop-to-buffer (message-buffer-name "bounce"))
7467 (if (stringp (car handles
))
7468 ;; This is a MIME bounce.
7469 (mm-insert-part (car (last handles
)))
7470 ;; This is a non-MIME bounce, so we try to remove things
7472 (mm-insert-part handles
)
7474 (goto-char (point-min))
7475 (re-search-forward "\n\n+" nil t
)
7476 (setq boundary
(point))
7477 ;; We remove everything before the bounced mail.
7478 (if (or (re-search-forward message-unsent-separator nil t
)
7480 (search-forward "\n\n" nil
'move
)
7481 (re-search-backward "^Return-Path:.*\n" boundary t
)))
7484 (delete-region (point-min)
7485 (if (re-search-forward "^[^ \n\t]+:" nil t
)
7488 (goto-char boundary
)
7489 (when (re-search-backward "^.?From .*\n" nil t
)
7490 (delete-region (match-beginning 0) (match-end 0)))))
7493 (message-narrow-to-head-1)
7494 (message-remove-header message-ignored-bounced-headers t
)
7495 (goto-char (point-max))
7496 (insert mail-header-separator
))
7497 (message-position-point)))
7500 ;;; Interactive entry points for new message buffers.
7504 (defun message-mail-other-window (&optional to subject
)
7505 "Like `message-mail' command, but display mail buffer in another window."
7507 (unless (message-mail-user-agent)
7508 (let ((pop-up-windows t
)
7509 (special-display-buffer-names nil
)
7510 (special-display-regexps nil
)
7511 (same-window-buffer-names nil
)
7512 (same-window-regexps nil
))
7513 (message-pop-to-buffer (message-buffer-name "mail" to
))))
7514 (let ((message-this-is-mail t
))
7515 (message-setup `((To .
,(or to
"")) (Subject .
,(or subject
"")))
7516 nil nil nil
'switch-to-buffer-other-window
)))
7519 (defun message-mail-other-frame (&optional to subject
)
7520 "Like `message-mail' command, but display mail buffer in another frame."
7522 (unless (message-mail-user-agent)
7523 (let ((pop-up-frames t
)
7524 (special-display-buffer-names nil
)
7525 (special-display-regexps nil
)
7526 (same-window-buffer-names nil
)
7527 (same-window-regexps nil
))
7528 (message-pop-to-buffer (message-buffer-name "mail" to
))))
7529 (let ((message-this-is-mail t
))
7530 (message-setup `((To .
,(or to
"")) (Subject .
,(or subject
"")))
7531 nil nil nil
'switch-to-buffer-other-frame
)))
7534 (defun message-news-other-window (&optional newsgroups subject
)
7535 "Start editing a news article to be sent."
7537 (let ((pop-up-windows t
)
7538 (special-display-buffer-names nil
)
7539 (special-display-regexps nil
)
7540 (same-window-buffer-names nil
)
7541 (same-window-regexps nil
))
7542 (message-pop-to-buffer (message-buffer-name "posting" nil newsgroups
)))
7543 (let ((message-this-is-news t
))
7544 (message-setup `((Newsgroups .
,(or newsgroups
""))
7545 (Subject .
,(or subject
""))))))
7548 (defun message-news-other-frame (&optional newsgroups subject
)
7549 "Start editing a news article to be sent."
7551 (let ((pop-up-frames t
)
7552 (special-display-buffer-names nil
)
7553 (special-display-regexps nil
)
7554 (same-window-buffer-names nil
)
7555 (same-window-regexps nil
))
7556 (message-pop-to-buffer (message-buffer-name "posting" nil newsgroups
)))
7557 (let ((message-this-is-news t
))
7558 (message-setup `((Newsgroups .
,(or newsgroups
""))
7559 (Subject .
,(or subject
""))))))
7563 ;; This code should be moved to underline.el (from which it is stolen).
7566 (defun message-bold-region (start end
)
7567 "Bold all nonblank characters in the region.
7568 Works by overstriking characters.
7569 Called from program, takes two arguments START and END
7570 which specify the range to operate on."
7573 (let ((end1 (make-marker)))
7574 (move-marker end1
(max start end
))
7575 (goto-char (min start end
))
7576 (while (< (point) end1
)
7577 (or (looking-at "[_\^@- ]")
7578 (insert (char-after) "\b"))
7579 (forward-char 1)))))
7582 (defun message-unbold-region (start end
)
7583 "Remove all boldness (overstruck characters) in the region.
7584 Called from program, takes two arguments START and END
7585 which specify the range to operate on."
7588 (let ((end1 (make-marker)))
7589 (move-marker end1
(max start end
))
7590 (goto-char (min start end
))
7591 (while (search-forward "\b" end1 t
)
7592 (if (eq (char-after) (char-after (- (point) 2)))
7593 (delete-char -
2))))))
7595 (defun message-exchange-point-and-mark ()
7596 "Exchange point and mark, but don't activate region if it was inactive."
7597 (goto-char (prog1 (mark t
)
7598 (set-marker (mark-marker) (point)))))
7600 (defalias 'message-make-overlay
'make-overlay
)
7601 (defalias 'message-delete-overlay
'delete-overlay
)
7602 (defalias 'message-overlay-put
'overlay-put
)
7603 (defun message-kill-all-overlays ()
7604 (if (featurep 'xemacs
)
7605 (map-extents (lambda (extent ignore
) (delete-extent extent
)))
7606 (mapcar #'delete-overlay
(overlays-in (point-min) (point-max)))))
7608 ;; Support for toolbar
7609 (defvar tool-bar-mode
)
7611 ;; Note: The :set function in the `message-tool-bar*' variables will only
7612 ;; affect _new_ message buffers. We might add a function that walks thru all
7613 ;; message-mode buffers and force the update.
7614 (defun message-tool-bar-update (&optional symbol value
)
7615 "Update message mode toolbar.
7616 Setter function for custom variables."
7617 (setq-default message-tool-bar-map nil
)
7619 ;; When used as ":set" function:
7620 (set-default symbol value
)))
7622 (defcustom message-tool-bar
(if (eq gmm-tool-bar-style
'gnome
)
7623 'message-tool-bar-gnome
7624 'message-tool-bar-retro
)
7625 "Specifies the message mode tool bar.
7627 It can be either a list or a symbol refering to a list. See
7628 `gmm-tool-bar-from-list' for the format of the list. The
7629 default key map is `message-mode-map'.
7631 Pre-defined symbols include `message-tool-bar-gnome' and
7632 `message-tool-bar-retro'."
7633 :type
'(repeat gmm-tool-bar-list-item
)
7634 :type
'(choice (const :tag
"GNOME style" message-tool-bar-gnome
)
7635 (const :tag
"Retro look" message-tool-bar-retro
)
7636 (repeat :tag
"User defined list" gmm-tool-bar-item
)
7638 :version
"23.1" ;; No Gnus
7639 :initialize
'custom-initialize-default
7640 :set
'message-tool-bar-update
7643 (defcustom message-tool-bar-gnome
7644 '((ispell-message "spell" nil
7645 :visible
(or (not (boundp 'flyspell-mode
))
7646 (not flyspell-mode
)))
7647 (flyspell-buffer "spell" t
7648 :visible
(and (boundp 'flyspell-mode
)
7650 :help
"Flyspell whole buffer")
7651 (gmm-ignore "separator")
7652 (message-send-and-exit "mail/send")
7653 (message-dont-send "mail/save-draft")
7654 (message-kill-buffer "close") ;; stock_cancel
7655 (mml-attach-file "attach" mml-mode-map
)
7656 (mml-preview "mail/preview" mml-mode-map
)
7657 (mml-secure-message-sign-encrypt "lock" mml-mode-map
:visible nil
)
7658 (message-insert-importance-high "important" nil
:visible nil
)
7659 (message-insert-importance-low "unimportant" nil
:visible nil
)
7660 (message-insert-disposition-notification-to "receipt" nil
:visible nil
)
7661 (gmm-customize-mode "preferences" t
:help
"Edit mode preferences")
7662 (message-info "help" t
:help
"Message manual"))
7663 "List of items for the message tool bar (GNOME style).
7665 See `gmm-tool-bar-from-list' for details on the format of the list."
7666 :type
'(repeat gmm-tool-bar-item
)
7667 :version
"23.1" ;; No Gnus
7668 :initialize
'custom-initialize-default
7669 :set
'message-tool-bar-update
7672 (defcustom message-tool-bar-retro
7673 '(;; Old Emacs 21 icon for consistency.
7674 (message-send-and-exit "gnus/mail-send")
7675 (message-kill-buffer "close")
7676 (message-dont-send "cancel")
7677 (mml-attach-file "attach" mml-mode-map
)
7678 (ispell-message "spell")
7679 (mml-preview "preview" mml-mode-map
)
7680 (message-insert-importance-high "gnus/important")
7681 (message-insert-importance-low "gnus/unimportant")
7682 (message-insert-disposition-notification-to "gnus/receipt"))
7683 "List of items for the message tool bar (retro style).
7685 See `gmm-tool-bar-from-list' for details on the format of the list."
7686 :type
'(repeat gmm-tool-bar-item
)
7687 :version
"23.1" ;; No Gnus
7688 :initialize
'custom-initialize-default
7689 :set
'message-tool-bar-update
7692 (defcustom message-tool-bar-zap-list
7693 '(new-file open-file dired kill-buffer write-file
7694 print-buffer customize help
)
7695 "List of icon items from the global tool bar.
7696 These items are not displayed on the message mode tool bar.
7698 See `gmm-tool-bar-from-list' for the format of the list."
7699 :type
'gmm-tool-bar-zap-list
7700 :version
"23.1" ;; No Gnus
7701 :initialize
'custom-initialize-default
7702 :set
'message-tool-bar-update
7705 (defvar image-load-path
)
7707 (defun message-make-tool-bar (&optional force
)
7708 "Make a message mode tool bar from `message-tool-bar-list'.
7709 When FORCE, rebuild the tool bar."
7710 (when (and (not (featurep 'xemacs
))
7711 (boundp 'tool-bar-mode
)
7713 (or (not message-tool-bar-map
) force
))
7714 (setq message-tool-bar-map
7716 (gmm-image-load-path-for-library "message"
7717 "mail/save-draft.xpm"
7719 (image-load-path (cons (car load-path
)
7720 (when (boundp 'image-load-path
)
7722 (gmm-tool-bar-from-list message-tool-bar
7723 message-tool-bar-zap-list
7724 'message-mode-map
))))
7725 message-tool-bar-map
)
7727 ;;; Group name completion.
7729 (defcustom message-newgroups-header-regexp
7730 "^\\(Newsgroups\\|Followup-To\\|Posted-To\\|Gcc\\):"
7731 "Regexp that match headers that lists groups."
7735 (defcustom message-completion-alist
7736 (list (cons message-newgroups-header-regexp
'message-expand-group
)
7737 '("^\\(Resent-\\)?\\(To\\|B?Cc\\):" . message-expand-name
)
7738 '("^\\(Reply-To\\|From\\|Mail-Followup-To\\|Mail-Copies-To\\):"
7739 . message-expand-name
)
7740 '("^\\(Disposition-Notification-To\\|Return-Receipt-To\\):"
7741 . message-expand-name
))
7742 "Alist of (RE . FUN). Use FUN for completion on header lines matching RE."
7745 :type
'(alist :key-type regexp
:value-type function
))
7747 (defcustom message-expand-name-databases
7749 "List of databases to try for name completion (`message-expand-name').
7750 Each element is a symbol and can be `bbdb' or `eudc'."
7752 :type
'(set (const bbdb
) (const eudc
)))
7754 (defcustom message-tab-body-function nil
7755 "*Function to execute when `message-tab' (TAB) is executed in the body.
7756 If nil, the function bound in `text-mode-map' or `global-map' is executed."
7759 :link
'(custom-manual "(message)Various Commands")
7760 :type
'(choice (const nil
)
7763 (declare-function mail-abbrev-in-expansion-header-p
"mailabbrev" ())
7765 (defun message-tab ()
7766 "Complete names according to `message-completion-alist'.
7767 Execute function specified by `message-tab-body-function' when not in
7771 ((if (and (boundp 'completion-fail-discreetly
)
7772 (fboundp 'completion-at-point
))
7773 (let ((completion-fail-discreetly t
)) (completion-at-point))
7774 (funcall (or (message-completion-function) #'ignore
)))
7775 ;; Completion was performed; nothing else to do.
7777 (message-tab-body-function (funcall message-tab-body-function
))
7778 (t (funcall (or (lookup-key text-mode-map
"\t")
7779 (lookup-key global-map
"\t")
7780 'indent-relative
)))))
7782 (defun message-completion-function ()
7783 (let ((alist message-completion-alist
))
7785 (let ((mail-abbrev-mode-regexp (caar alist
)))
7786 (not (mail-abbrev-in-expansion-header-p))))
7787 (setq alist
(cdr alist
)))
7793 (let ((standard-output (current-buffer)))
7794 (eval '(display-completion-list nil
"")))
7795 (defalias 'message-display-completion-list
'display-completion-list
))
7796 (error ;; Don't use `wrong-number-of-arguments' here because of XEmacs.
7797 (defun message-display-completion-list (completions &optional ignore
)
7798 "Display the list of completions, COMPLETIONS, using `standard-output'."
7799 (display-completion-list completions
)))))
7801 (defun message-expand-group ()
7802 "Expand the group name under point."
7803 (let* ((b (save-excursion
7808 (skip-chars-forward "^:")
7811 (skip-chars-backward "^, \t\n") (point))))
7812 (completion-ignore-case t
)
7813 (e (progn (skip-chars-forward "^,\t\n ") (point)))
7814 (hashtb (and (boundp 'gnus-active-hashtb
) gnus-active-hashtb
)))
7815 (message-completion-in-region e b hashtb
)))
7817 (defalias 'message-completion-in-region
7818 (if (fboundp 'completion-in-region
)
7819 'completion-in-region
7820 (lambda (e b hashtb
)
7821 (let* ((string (buffer-substring b e
))
7822 (completions (all-completions string hashtb
))
7824 (delete-region b
(point))
7826 ((= (length completions
) 1)
7827 (if (string= (car completions
) string
)
7830 (message "Only matching group"))
7831 (insert (car completions
))))
7832 ((and (setq comp
(try-completion string hashtb
))
7833 (not (string= comp string
)))
7838 (message "No matching groups")
7839 (save-selected-window
7840 (pop-to-buffer "*Completions*")
7841 (buffer-disable-undo)
7842 (let ((buffer-read-only nil
))
7844 (let ((standard-output (current-buffer)))
7845 (message-display-completion-list (sort completions
'string
<)
7847 (setq buffer-read-only nil
)
7848 (goto-char (point-min))
7849 (delete-region (point)
7850 (progn (forward-line 3) (point))))))))))))
7852 (defun message-expand-name ()
7853 (cond ((and (memq 'eudc message-expand-name-databases
)
7854 (boundp 'eudc-protocol
)
7856 (eudc-expand-inline))
7857 ((and (memq 'bbdb message-expand-name-databases
)
7858 (fboundp 'bbdb-complete-name
))
7859 (bbdb-complete-name))
7865 (defun message-talkative-question (ask question show
&rest text
)
7866 "Call FUNCTION with argument QUESTION; optionally display TEXT... args.
7867 If SHOW is non-nil, the arguments TEXT... are displayed in a temp buffer.
7868 The following arguments may contain lists of values."
7870 (setq text
(message-flatten-list text
)))
7871 (save-window-excursion
7872 (with-output-to-temp-buffer " *MESSAGE information message*"
7873 (with-current-buffer " *MESSAGE information message*"
7874 (fundamental-mode) ; for Emacs 20.4+
7876 (goto-char (point-min))))
7877 (funcall ask question
))
7878 (funcall ask question
)))
7880 (defun message-flatten-list (list)
7881 "Return a new, flat list that contains all elements of LIST.
7883 \(message-flatten-list '(1 (2 3 (4 5 (6))) 7))
7886 (apply 'append
(mapcar 'message-flatten-list list
)))
7890 (defun message-generate-new-buffer-clone-locals (name &optional varstr
)
7891 "Create and return a buffer with name based on NAME using `generate-new-buffer'.
7892 Then clone the local variables and values from the old buffer to the
7893 new one, cloning only the locals having a substring matching the
7895 (let ((oldbuf (current-buffer)))
7896 (with-current-buffer (generate-new-buffer name
)
7897 (message-clone-locals oldbuf varstr
)
7900 (defun message-clone-locals (buffer &optional varstr
)
7901 "Clone the local variables from BUFFER to the current buffer."
7902 (let ((locals (with-current-buffer buffer
(buffer-local-variables)))
7903 (regexp "^gnus\\|^nn\\|^message\\|^sendmail\\|^smtp\\|^user-mail-address"))
7906 (when (and (consp local
)
7908 (string-match regexp
(symbol-name (car local
)))
7910 (string-match varstr
(symbol-name (car local
)))))
7912 (set (make-local-variable (car local
))
7920 (defvar message-inhibit-body-encoding nil
)
7922 (defun message-encode-message-body ()
7923 (unless message-inhibit-body-encoding
7924 (let ((mail-parse-charset (or mail-parse-charset
7925 message-default-charset
))
7926 (case-fold-search t
)
7927 lines content-type-p
)
7930 (narrow-to-region (point) (point-max))
7931 (let ((new (mml-generate-mime)))
7933 (delete-region (point-min) (point-max))
7935 (goto-char (point-min))
7936 (if (eq (aref new
0) ?
\n)
7938 (search-forward "\n\n")
7939 (setq lines
(buffer-substring (point-min) (1- (point))))
7940 (delete-region (point-min) (point))))))
7942 (message-narrow-to-headers-or-head)
7943 (message-remove-header "Mime-Version")
7944 (goto-char (point-max))
7945 (insert "MIME-Version: 1.0\n")
7948 (setq content-type-p
7950 (re-search-backward "^Content-Type:" nil t
))))
7952 (message-narrow-to-headers-or-head)
7953 (message-remove-first-header "Content-Type")
7954 (message-remove-first-header "Content-Transfer-Encoding"))
7955 ;; We always make sure that the message has a Content-Type
7956 ;; header. This is because some broken MTAs and MUAs get
7957 ;; awfully confused when confronted with a message with a
7958 ;; MIME-Version header and without a Content-Type header. For
7959 ;; instance, Solaris' /usr/bin/mail.
7960 (unless content-type-p
7961 (goto-char (point-min))
7962 ;; For unknown reason, MIME-Version doesn't exist.
7963 (when (re-search-forward "^MIME-Version:" nil t
)
7965 (insert "Content-Type: text/plain; charset=us-ascii\n"))))))
7967 (defun message-read-from-minibuffer (prompt &optional initial-contents
)
7968 "Read from the minibuffer while providing abbrev expansion."
7969 (if (fboundp 'mail-abbrevs-setup
)
7970 (let ((mail-abbrev-mode-regexp "")
7971 (minibuffer-setup-hook 'mail-abbrevs-setup
)
7972 (minibuffer-local-map message-minibuffer-local-map
))
7973 (read-from-minibuffer prompt initial-contents
))
7974 (let ((minibuffer-setup-hook 'mail-abbrev-minibuffer-setup-hook
)
7975 (minibuffer-local-map message-minibuffer-local-map
))
7976 (read-string prompt initial-contents
))))
7978 (defun message-use-alternative-email-as-from ()
7979 "Set From field of the outgoing message to the first matching
7980 address in `message-alternative-emails', looking at To, Cc and
7981 From headers in the original article."
7982 (require 'mail-utils
)
7983 (let* ((fields '("To" "Cc" "From"))
7986 (mail-strip-quoted-names
7987 (mapconcat 'message-fetch-reply-field fields
","))
7991 (if (string-match message-alternative-emails
(car emails
))
7992 (setq email
(car emails
)
7995 (unless (or (not email
) (equal email user-mail-address
))
7996 (message-remove-header "From")
7997 (goto-char (point-max))
7998 (insert "From: " (let ((user-mail-address email
)) (message-make-from))
8001 (defun message-options-get (symbol)
8002 (cdr (assq symbol message-options
)))
8004 (defun message-options-set (symbol value
)
8005 (let ((the-cons (assq symbol message-options
)))
8008 (setcdr the-cons value
)
8009 (setq message-options
(delq the-cons message-options
)))
8011 (push (cons symbol value
) message-options
))))
8014 (defun message-options-set-recipient ()
8016 (message-narrow-to-headers-or-head)
8017 (message-options-set 'message-sender
8018 (mail-strip-quoted-names
8019 (message-fetch-field "from")))
8020 (message-options-set 'message-recipients
8021 (mail-strip-quoted-names
8022 (let ((to (message-fetch-field "to"))
8023 (cc (message-fetch-field "cc"))
8024 (bcc (message-fetch-field "bcc")))
8027 (if (and to cc
) ", ")
8029 (if (and (or to cc
) bcc
) ", ")
8032 (defun message-hide-headers ()
8033 "Hide headers based on the `message-hidden-headers' variable."
8034 (let ((regexps (if (stringp message-hidden-headers
)
8035 (list message-hidden-headers
)
8036 message-hidden-headers
))
8037 (inhibit-point-motion-hooks t
)
8038 (after-change-functions nil
)
8039 (end-of-headers (point-min)))
8043 (message-narrow-to-headers)
8044 (goto-char (point-min))
8046 (if (not (message-hide-header-p regexps
))
8047 (message-next-header)
8048 (let ((begin (point))
8050 (message-next-header)
8051 (setq header
(buffer-substring begin
(point))
8052 header-len
(- (point) begin
))
8053 (delete-region begin
(point))
8054 (goto-char end-of-headers
)
8056 (setq end-of-headers
8057 (+ end-of-headers header-len
))))))))
8058 (narrow-to-region end-of-headers
(point-max))))
8060 (defun message-hide-header-p (regexps)
8063 (when (eq (car regexps
) 'not
)
8066 (dolist (regexp regexps
)
8067 (setq result
(or result
(looking-at regexp
))))
8072 (declare-function ecomplete-add-item
"ecomplete" (type key text
))
8073 (declare-function ecomplete-save
"ecomplete" ())
8075 (defun message-put-addresses-in-ecomplete ()
8076 (require 'ecomplete
)
8077 (dolist (header '("to" "cc" "from" "reply-to"))
8078 (let ((value (message-field-value header
)))
8079 (dolist (string (mail-header-parse-addresses value
'raw
))
8081 (gnus-replace-in-string
8082 (gnus-replace-in-string string
"^ +\\| +$" "") "\n" ""))
8083 (ecomplete-add-item 'mail
(car (mail-header-parse-address string
))
8087 (autoload 'ecomplete-display-matches
"ecomplete")
8089 (defun message-display-abbrev (&optional choose
)
8090 "Display the next possible abbrev for the text before point."
8091 (interactive (list t
))
8092 (when (and (memq (char-after (point-at-bol)) '(?C ?T ?
\t ?
))
8093 (message-point-in-header-p)
8096 (while (and (memq (char-after) '(?
\t ?
))
8097 (zerop (forward-line -
1))))
8098 (looking-at "To:\\|Cc:")))
8099 (let* ((end (point))
8100 (start (save-excursion
8101 (and (re-search-backward "[\n\t ]" nil t
)
8103 (word (when start
(buffer-substring start end
)))
8104 (match (when (and word
8105 (not (zerop (length word
))))
8106 (ecomplete-display-matches 'mail word choose
))))
8107 (when (and choose match
)
8108 (delete-region start end
)
8111 ;; To send pre-formatted letters like the example below, you can use
8112 ;; `message-send-form-letter':
8113 ;; --8<---------------cut here---------------start------------->8---
8114 ;; To: alice@invalid.invalid
8115 ;; Subject: Verification of your contact information
8116 ;; From: Contact verification <admin@foo.invalid>
8117 ;; --text follows this line--
8119 ;; please verify that your contact information is still valid:
8120 ;; Alice A, A avenue 11, 1111 A town, Austria
8121 ;; ----------next form letter message follows this line----------
8122 ;; To: bob@invalid.invalid
8123 ;; Subject: Verification of your contact information
8124 ;; From: Contact verification <admin@foo.invalid>
8125 ;; --text follows this line--
8127 ;; please verify that your contact information is still valid:
8128 ;; Bob, B street 22, 22222 Be town, Belgium
8129 ;; ----------next form letter message follows this line----------
8130 ;; To: charlie@invalid.invalid
8131 ;; Subject: Verification of your contact information
8132 ;; From: Contact verification <admin@foo.invalid>
8133 ;; --text follows this line--
8135 ;; please verify that your contact information is still valid:
8136 ;; Charlie Chaplin, C plaza 33, 33333 C town, Chile
8137 ;; --8<---------------cut here---------------end--------------->8---
8139 ;; FIXME: What is the most common term (circular letter, form letter, serial
8140 ;; letter, standard letter) for such kind of letter? See also
8141 ;; <http://en.wikipedia.org/wiki/Form_letter>
8143 ;; FIXME: Maybe extent message-mode's font-lock support to recognize
8144 ;; `message-form-letter-separator', i.e. highlight each message like a single
8147 (defcustom message-form-letter-separator
8148 "\n----------next form letter message follows this line----------\n"
8149 "Separator for `message-send-form-letter'."
8150 ;; :group 'message-form-letter
8151 :group
'message-various
8152 :version
"23.1" ;; No Gnus
8155 (defcustom message-send-form-letter-delay
1
8156 "Delay in seconds when sending a message with `message-send-form-letter'.
8157 Only used when `message-send-form-letter' is called with non-nil
8159 ;; :group 'message-form-letter
8160 :group
'message-various
8161 :version
"23.1" ;; No Gnus
8164 (defun message-send-form-letter (&optional force
)
8165 "Sent all form letter messages from current buffer.
8166 Unless FORCE, prompt before sending.
8168 The messages are separated by `message-form-letter-separator'.
8169 Header and body are separated by `mail-header-separator'."
8171 (let ((sent 0) (skipped 0)
8175 (goto-char (point-min))
8178 end
(if (search-forward message-form-letter-separator nil t
)
8179 (- (point) (length message-form-letter-separator
) -
1)
8183 (buffer-substring-no-properties start end
))
8184 (setq buff
(generate-new-buffer "*mail - form letter*"))
8185 (with-current-buffer buff
8188 (setq to
(message-fetch-field "To"))
8189 (switch-to-buffer buff
)
8191 (sit-for message-send-form-letter-delay
))
8193 (y-or-n-p (format "Send message to `%s'? " to
)))
8195 (setq sent
(1+ sent
))
8196 (message-send-and-exit))
8197 (message (format "Message to `%s' skipped." to
))
8198 (setq skipped
(1+ skipped
)))
8199 (when (buffer-live-p buff
)
8200 (kill-buffer buff
))))
8201 (message "%s message(s) sent, %s skipped." sent skipped
)))
8203 (defun message-replace-header (header new-value
&optional after force
)
8204 "Remove HEADER and insert the NEW-VALUE.
8205 If AFTER, insert after this header. If FORCE, insert new field
8206 even if NEW-VALUE is empty."
8207 ;; Similar to `nnheader-replace-header' but for message buffers.
8210 (message-narrow-to-headers)
8211 (message-remove-header header
))
8212 (when (or force
(> (length new-value
) 0))
8214 (message-position-on-field header after
)
8215 (message-position-on-field header
))
8216 (insert new-value
))))
8218 (defcustom message-recipients-without-full-name
8219 (list "ding@gnus.org"
8221 "emacs-devel@gnu.org"
8222 "emacs-pretest-bug@gnu.org"
8223 "bug-gnu-emacs@gnu.org")
8224 "Mail addresses that have no full name.
8225 Used in `message-simplify-recipients'."
8226 ;; Maybe the addresses could be extracted from
8227 ;; `gnus-parameter-to-list-alist'?
8228 :type
'(choice (const :tag
"None" nil
)
8230 :version
"23.1" ;; No Gnus
8231 :group
'message-headers
)
8233 (defun message-simplify-recipients ()
8235 (dolist (hdr '("Cc" "To"))
8236 (message-replace-header
8240 (if (and message-recipients-without-full-name
8242 (regexp-opt message-recipients-without-full-name
)
8246 (message-make-from (car addrcomp
) (cadr addrcomp
))
8248 (when (message-fetch-field hdr
)
8249 (mail-extract-address-components
8250 (message-fetch-field hdr
) t
))
8253 (when (featurep 'xemacs
)
8254 (require 'messagexmas
)
8255 (message-xmas-redefine))
8259 (run-hooks 'message-load-hook
)
8262 ;; coding: iso-8859-1
8265 ;;; message.el ends here