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 (defvar gnus-local-organization
)
511 (defcustom message-user-organization
512 (or (and (boundp 'gnus-local-organization
)
513 (stringp gnus-local-organization
)
514 gnus-local-organization
)
515 (getenv "ORGANIZATION")
517 "*String to be used as an Organization header.
518 If t, use `message-user-organization-file'."
519 :group
'message-headers
520 :type
'(choice string
521 (const :tag
"consult file" t
)))
523 (defcustom message-user-organization-file
525 (dolist (f (list "/etc/organization"
526 "/etc/news/organization"
527 "/usr/lib/news/organization"))
528 (when (file-readable-p f
)
531 "*Local news organization file."
533 :link
'(custom-manual "(message)News Headers")
534 :group
'message-headers
)
536 (defcustom message-make-forward-subject-function
537 #'message-forward-subject-name-subject
538 "*List of functions called to generate subject headers for forwarded messages.
539 The subject generated by the previous function is passed into each
542 The provided functions are:
544 * `message-forward-subject-author-subject' Source of article (author or
545 newsgroup), in brackets followed by the subject
546 * `message-forward-subject-name-subject' Source of article (name of author
547 or newsgroup), in brackets followed by the subject
548 * `message-forward-subject-fwd' Subject of article with 'Fwd:' prepended
550 :group
'message-forwarding
551 :link
'(custom-manual "(message)Forwarding")
552 :type
'(radio (function-item message-forward-subject-author-subject
)
553 (function-item message-forward-subject-fwd
)
554 (function-item message-forward-subject-name-subject
)
555 (repeat :tag
"List of functions" function
)))
557 (defcustom message-forward-as-mime t
558 "*Non-nil means forward messages as an inline/rfc822 MIME section.
559 Otherwise, directly inline the old message in the forwarded message."
561 :group
'message-forwarding
562 :link
'(custom-manual "(message)Forwarding")
565 (defcustom message-forward-show-mml
'best
566 "*Non-nil means show forwarded messages as MML (decoded from MIME).
567 Otherwise, forwarded messages are unchanged.
568 Can also be the symbol `best' to indicate that MML should be
569 used, except when it is a bad idea to use MML. One example where
570 it is a bad idea is when forwarding a signed or encrypted
571 message, because converting MIME to MML would invalidate the
574 :group
'message-forwarding
575 :type
'(choice (const :tag
"use MML" t
)
576 (const :tag
"don't use MML " nil
)
577 (const :tag
"use MML when appropriate" best
)))
579 (defcustom message-forward-before-signature t
580 "*Non-nil means put forwarded message before signature, else after."
581 :group
'message-forwarding
584 (defcustom message-wash-forwarded-subjects nil
585 "*Non-nil means try to remove as much cruft as possible from the subject.
586 Done before generating the new subject of a forward."
587 :group
'message-forwarding
588 :link
'(custom-manual "(message)Forwarding")
591 (defcustom message-ignored-resent-headers
592 ;; `Delivered-To' needs to be removed because some mailers use it to
593 ;; detect loops, so if you resend a message to an address that ultimately
594 ;; comes back to you (e.g. a mailing-list to which you subscribe, in which
595 ;; case you may be removed from the list on the grounds that mail to you
596 ;; bounced with a "mailing loop" error).
597 "^Return-receipt\\|^X-Gnus\\|^Gnus-Warning:\\|^>?From \\|^Delivered-To:"
598 "*All headers that match this regexp will be deleted when resending a message."
599 :group
'message-interface
600 :link
'(custom-manual "(message)Resending")
601 :type
'(repeat :value-to-internal
(lambda (widget value
)
602 (custom-split-regexp-maybe value
))
603 :match
(lambda (widget value
)
605 (widget-editable-list-match widget value
)))
608 (defcustom message-forward-ignored-headers
"^Content-Transfer-Encoding:\\|^X-Gnus"
609 "*All headers that match this regexp will be deleted when forwarding a message."
611 :group
'message-forwarding
612 :type
'(repeat :value-to-internal
(lambda (widget value
)
613 (custom-split-regexp-maybe value
))
614 :match
(lambda (widget value
)
616 (widget-editable-list-match widget value
)))
619 (defcustom message-ignored-cited-headers
"."
620 "*Delete these headers from the messages you yank."
621 :group
'message-insertion
622 :link
'(custom-manual "(message)Insertion Variables")
625 (defcustom message-cite-prefix-regexp mail-citation-prefix-regexp
626 "*Regexp matching the longest possible citation prefix on a line."
628 :group
'message-insertion
629 :link
'(custom-manual "(message)Insertion Variables")
631 :set
(lambda (symbol value
)
633 (custom-set-default symbol value
)
634 (if (boundp 'gnus-message-cite-prefix-regexp
)
635 (setq gnus-message-cite-prefix-regexp
636 (concat "^\\(?:" value
"\\)"))))))
638 (defcustom message-cancel-message
"I am canceling my own article.\n"
639 "Message to be inserted in the cancel message."
640 :group
'message-interface
641 :link
'(custom-manual "(message)Canceling News")
644 (defun message-send-mail-function ()
645 "Return suitable value for the variable `message-send-mail-function'."
646 (cond ((and (require 'sendmail
)
647 (boundp 'sendmail-program
)
649 (executable-find sendmail-program
))
650 'message-send-mail-with-sendmail
)
651 ((and (locate-library "smtpmail")
652 (boundp 'smtpmail-default-smtp-server
)
653 smtpmail-default-smtp-server
)
654 'message-smtpmail-send-it
)
655 ((locate-library "mailclient")
656 'message-send-mail-with-mailclient
)
658 (error "Don't know how to send mail. Please customize `message-send-mail-function'"))))
660 ;; Useful to set in site-init.el
661 (defcustom message-send-mail-function
662 (cond ((eq send-mail-function
'smtpmail-send-it
) 'message-smtpmail-send-it
)
663 ((eq send-mail-function
'feedmail-send-it
) 'feedmail-send-it
)
664 ((eq send-mail-function
'mailclient-send-it
)
665 'message-send-mail-with-mailclient
)
666 (t (message-send-mail-function)))
667 "Function to call to send the current buffer as mail.
668 The headers should be delimited by a line whose contents match the
669 variable `mail-header-separator'.
671 Valid values include `message-send-mail-with-sendmail'
672 `message-send-mail-with-mh', `message-send-mail-with-qmail',
673 `message-smtpmail-send-it', `smtpmail-send-it',
674 `feedmail-send-it' and `message-send-mail-with-mailclient'. The
675 default is system dependent and determined by the function
676 `message-send-mail-function'.
678 See also `send-mail-function'."
679 :type
'(radio (function-item message-send-mail-with-sendmail
)
680 (function-item message-send-mail-with-mh
)
681 (function-item message-send-mail-with-qmail
)
682 (function-item message-smtpmail-send-it
)
683 (function-item smtpmail-send-it
)
684 (function-item feedmail-send-it
)
685 (function-item message-send-mail-with-mailclient
686 :tag
"Use Mailclient package")
687 (function :tag
"Other"))
688 :group
'message-sending
690 :initialize
'custom-initialize-default
691 :link
'(custom-manual "(message)Mail Variables")
692 :group
'message-mail
)
694 (defcustom message-send-news-function
'message-send-news
695 "Function to call to send the current buffer as news.
696 The headers should be delimited by a line whose contents match the
697 variable `mail-header-separator'."
698 :group
'message-sending
700 :link
'(custom-manual "(message)News Variables")
703 (defcustom message-reply-to-function nil
704 "If non-nil, function that should return a list of headers.
705 This function should pick out addresses from the To, Cc, and From headers
706 and respond with new To and Cc headers."
707 :group
'message-interface
708 :link
'(custom-manual "(message)Reply")
709 :type
'(choice function
(const nil
)))
711 (defcustom message-wide-reply-to-function nil
712 "If non-nil, function that should return a list of headers.
713 This function should pick out addresses from the To, Cc, and From headers
714 and respond with new To and Cc headers."
715 :group
'message-interface
716 :link
'(custom-manual "(message)Wide Reply")
717 :type
'(choice function
(const nil
)))
719 (defcustom message-followup-to-function nil
720 "If non-nil, function that should return a list of headers.
721 This function should pick out addresses from the To, Cc, and From headers
722 and respond with new To and Cc headers."
723 :group
'message-interface
724 :link
'(custom-manual "(message)Followup")
725 :type
'(choice function
(const nil
)))
727 (defcustom message-extra-wide-headers nil
728 "If non-nil, a list of additional address headers.
729 These are used when composing a wide reply."
730 :group
'message-sending
731 :type
'(repeat string
))
733 (defcustom message-use-followup-to
'ask
734 "*Specifies what to do with Followup-To header.
735 If nil, always ignore the header. If it is t, use its value, but
736 query before using the \"poster\" value. If it is the symbol `ask',
737 always query the user whether to use the value. If it is the symbol
738 `use', always use the value."
739 :group
'message-interface
740 :link
'(custom-manual "(message)Followup")
741 :type
'(choice (const :tag
"ignore" nil
)
742 (const :tag
"use & query" t
)
746 (defcustom message-use-mail-followup-to
'use
747 "*Specifies what to do with Mail-Followup-To header.
748 If nil, always ignore the header. If it is the symbol `ask', always
749 query the user whether to use the value. If it is the symbol `use',
750 always use the value."
752 :group
'message-interface
753 :link
'(custom-manual "(message)Mailing Lists")
754 :type
'(choice (const :tag
"ignore" nil
)
758 (defcustom message-subscribed-address-functions nil
759 "*Specifies functions for determining list subscription.
760 If nil, do not attempt to determine list subscription with functions.
761 If non-nil, this variable contains a list of functions which return
762 regular expressions to match lists. These functions can be used in
763 conjunction with `message-subscribed-regexps' and
764 `message-subscribed-addresses'."
766 :group
'message-interface
767 :link
'(custom-manual "(message)Mailing Lists")
768 :type
'(repeat sexp
))
770 (defcustom message-subscribed-address-file nil
771 "*A file containing addresses the user is subscribed to.
772 If nil, do not look at any files to determine list subscriptions. If
773 non-nil, each line of this file should be a mailing list address."
775 :group
'message-interface
776 :link
'(custom-manual "(message)Mailing Lists")
777 :type
'(radio file
(const nil
)))
779 (defcustom message-subscribed-addresses nil
780 "*Specifies a list of addresses the user is subscribed to.
781 If nil, do not use any predefined list subscriptions. This list of
782 addresses can be used in conjunction with
783 `message-subscribed-address-functions' and `message-subscribed-regexps'."
785 :group
'message-interface
786 :link
'(custom-manual "(message)Mailing Lists")
787 :type
'(repeat string
))
789 (defcustom message-subscribed-regexps nil
790 "*Specifies a list of addresses the user is subscribed to.
791 If nil, do not use any predefined list subscriptions. This list of
792 regular expressions can be used in conjunction with
793 `message-subscribed-address-functions' and `message-subscribed-addresses'."
795 :group
'message-interface
796 :link
'(custom-manual "(message)Mailing Lists")
797 :type
'(repeat regexp
))
799 (defcustom message-allow-no-recipients
'ask
800 "Specifies what to do when there are no recipients other than Gcc/Fcc.
801 If it is the symbol `always', the posting is allowed. If it is the
802 symbol `never', the posting is not allowed. If it is the symbol
803 `ask', you are prompted."
805 :group
'message-interface
806 :link
'(custom-manual "(message)Message Headers")
807 :type
'(choice (const always
)
811 (defcustom message-sendmail-f-is-evil nil
812 "*Non-nil means don't add \"-f username\" to the sendmail command line.
813 Doing so would be even more evil than leaving it out."
814 :group
'message-sending
815 :link
'(custom-manual "(message)Mail Variables")
818 (defcustom message-sendmail-envelope-from
819 ;; `mail-envelope-from' is unavailable unless sendmail.el is loaded.
820 (if (boundp 'mail-envelope-from
) mail-envelope-from
)
821 "*Envelope-from when sending mail with sendmail.
822 If this is nil, use `user-mail-address'. If it is the symbol
823 `header', use the From: header of the message."
825 :type
'(choice (string :tag
"From name")
826 (const :tag
"Use From: header from message" header
)
827 (const :tag
"Use `user-mail-address'" nil
))
828 :link
'(custom-manual "(message)Mail Variables")
829 :group
'message-sending
)
831 (defcustom message-sendmail-extra-arguments nil
832 "Additional arguments to `sendmail-program'."
833 ;; E.g. '("-a" "account") for msmtp
834 :version
"23.1" ;; No Gnus
835 :type
'(repeat string
)
836 ;; :link '(custom-manual "(message)Mail Variables")
837 :group
'message-sending
)
839 ;; qmail-related stuff
840 (defcustom message-qmail-inject-program
"/var/qmail/bin/qmail-inject"
841 "Location of the qmail-inject program."
842 :group
'message-sending
843 :link
'(custom-manual "(message)Mail Variables")
846 (defcustom message-qmail-inject-args nil
847 "Arguments passed to qmail-inject programs.
848 This should be a list of strings, one string for each argument.
849 It may also be a function.
851 For e.g., if you wish to set the envelope sender address so that bounces
852 go to the right place or to deal with listserv's usage of that address, you
853 might set this variable to '(\"-f\" \"you@some.where\")."
854 :group
'message-sending
855 :link
'(custom-manual "(message)Mail Variables")
856 :type
'(choice (function)
859 (defvar gnus-post-method
)
860 (defvar gnus-select-method
)
861 (defcustom message-post-method
862 (cond ((and (boundp 'gnus-post-method
)
863 (listp gnus-post-method
)
866 ((boundp 'gnus-select-method
)
869 "*Method used to post news.
870 Note that when posting from inside Gnus, for instance, this
871 variable isn't used."
873 :group
'message-sending
874 ;; This should be the `gnus-select-method' widget, but that might
875 ;; create a dependence to `gnus.el'.
878 ;; FIXME: This should be a temporary workaround until someone implements a
879 ;; proper solution. If a crash happens while replying, the auto-save file
880 ;; will *not* have a `References:' header if `message-generate-headers-first'
881 ;; is nil. See: http://article.gmane.org/gmane.emacs.gnus.general/51138
882 (defcustom message-generate-headers-first
'(references)
883 "Which headers should be generated before starting to compose a message.
884 If t, generate all required headers. This can also be a list of headers to
885 generate. The variables `message-required-news-headers' and
886 `message-required-mail-headers' specify which headers to generate.
888 Note that the variable `message-deletable-headers' specifies headers which
889 are to be deleted and then re-generated before sending, so this variable
890 will not have a visible effect for those headers."
891 :group
'message-headers
892 :link
'(custom-manual "(message)Message Headers")
893 :type
'(choice (const :tag
"None" nil
)
894 (const :tag
"References" '(references))
896 (repeat (sexp :tag
"Header"))))
898 (defcustom message-fill-column
72
899 "Column beyond which automatic line-wrapping should happen.
900 Local value for message buffers. If non-nil, also turn on
901 auto-fill in message buffers."
902 :group
'message-various
903 ;; :link '(custom-manual "(message)Message Headers")
904 :type
'(choice (const :tag
"Don't turn on auto fill" nil
)
907 (defcustom message-setup-hook nil
908 "Normal hook, run each time a new outgoing message is initialized.
909 The function `message-setup' runs this hook."
910 :group
'message-various
911 :link
'(custom-manual "(message)Various Message Variables")
914 (defcustom message-cancel-hook nil
915 "Hook run when cancelling articles."
916 :group
'message-various
917 :link
'(custom-manual "(message)Various Message Variables")
920 (defcustom message-signature-setup-hook nil
921 "Normal hook, run each time a new outgoing message is initialized.
922 It is run after the headers have been inserted and before
923 the signature is inserted."
924 :group
'message-various
925 :link
'(custom-manual "(message)Various Message Variables")
928 (defcustom message-mode-hook nil
929 "Hook run in message mode buffers."
930 :group
'message-various
933 (defcustom message-header-hook nil
934 "Hook run in a message mode buffer narrowed to the headers."
935 :group
'message-various
938 (defcustom message-header-setup-hook nil
939 "Hook called narrowed to the headers when setting up a message buffer."
940 :group
'message-various
941 :link
'(custom-manual "(message)Various Message Variables")
944 (defcustom message-minibuffer-local-map
945 (let ((map (make-sparse-keymap 'message-minibuffer-local-map
)))
946 (set-keymap-parent map minibuffer-local-map
)
948 "Keymap for `message-read-from-minibuffer'."
950 :group
'message-various
)
952 (defcustom message-citation-line-function
'message-insert-citation-line
953 "*Function called to insert the \"Whomever writes:\" line.
955 Predefined functions include `message-insert-citation-line' and
956 `message-insert-formatted-citation-line' (see the variable
957 `message-citation-line-format').
959 Note that Gnus provides a feature where the reader can click on
960 `writes:' to hide the cited text. If you change this line too much,
961 people who read your message will have to change their Gnus
962 configuration. See the variable `gnus-cite-attribution-suffix'."
964 (function-item :tag
"plain" message-insert-citation-line
)
965 (function-item :tag
"formatted" message-insert-formatted-citation-line
)
966 (function :tag
"Other"))
967 :link
'(custom-manual "(message)Insertion Variables")
968 :group
'message-insertion
)
970 (defcustom message-citation-line-format
"On %a, %b %d %Y, %N wrote:\n"
971 "Format of the \"Whomever writes:\" line.
973 The string is formatted using `format-spec'. The following
974 constructs are replaced:
976 %f The full From, e.g. \"John Doe <john.doe@example.invalid>\".
977 %n The mail address, e.g. \"john.doe@example.invalid\".
978 %N The real name if present, e.g.: \"John Doe\", else fall
979 back to the mail address.
980 %F The first name if present, e.g.: \"John\".
981 %L The last name if present, e.g.: \"Doe\".
983 All other format specifiers are passed to `format-time-string'
984 which is called using the date from the article your replying to.
985 Extracting the first (%F) and last name (%L) is done
986 heuristically, so you should always check it yourself.
988 Please also read the note in the documentation of
989 `message-citation-line-function'."
990 :type
'(choice (const :tag
"Plain" "%f writes:")
991 (const :tag
"Include date" "On %a, %b %d %Y, %n wrote:")
993 :link
'(custom-manual "(message)Insertion Variables")
994 :version
"23.1" ;; No Gnus
995 :group
'message-insertion
)
997 (defcustom message-yank-prefix mail-yank-prefix
998 "*Prefix inserted on the lines of yanked messages.
999 Fix `message-cite-prefix-regexp' if it is set to an abnormal value.
1000 See also `message-yank-cited-prefix' and `message-yank-empty-prefix'."
1003 :link
'(custom-manual "(message)Insertion Variables")
1004 :group
'message-insertion
)
1006 (defcustom message-yank-cited-prefix
">"
1007 "*Prefix inserted on cited lines of yanked messages.
1008 Fix `message-cite-prefix-regexp' if it is set to an abnormal value.
1009 See also `message-yank-prefix' and `message-yank-empty-prefix'."
1012 :link
'(custom-manual "(message)Insertion Variables")
1013 :group
'message-insertion
)
1015 (defcustom message-yank-empty-prefix
">"
1016 "*Prefix inserted on empty lines of yanked messages.
1017 See also `message-yank-prefix' and `message-yank-cited-prefix'."
1020 :link
'(custom-manual "(message)Insertion Variables")
1021 :group
'message-insertion
)
1023 (defcustom message-indentation-spaces mail-indentation-spaces
1024 "*Number of spaces to insert at the beginning of each cited line.
1025 Used by `message-yank-original' via `message-yank-cite'."
1027 :group
'message-insertion
1028 :link
'(custom-manual "(message)Insertion Variables")
1031 (defcustom message-cite-function
'message-cite-original-without-signature
1032 "*Function for citing an original message.
1033 Predefined functions include `message-cite-original' and
1034 `message-cite-original-without-signature'.
1035 Note that these functions use `mail-citation-hook' if that is non-nil."
1036 :type
'(radio (function-item message-cite-original
)
1037 (function-item message-cite-original-without-signature
)
1038 (function-item sc-cite-original
)
1039 (function :tag
"Other"))
1040 :link
'(custom-manual "(message)Insertion Variables")
1041 :version
"22.3" ;; Gnus 5.10.12 (changed default)
1042 :group
'message-insertion
)
1044 (defcustom message-indent-citation-function
'message-indent-citation
1045 "*Function for modifying a citation just inserted in the mail buffer.
1046 This can also be a list of functions. Each function can find the
1047 citation between (point) and (mark t). And each function should leave
1048 point and mark around the citation text as modified."
1050 :link
'(custom-manual "(message)Insertion Variables")
1051 :group
'message-insertion
)
1053 (defcustom message-signature mail-signature
1054 "*String to be inserted at the end of the message buffer.
1055 If t, the `message-signature-file' file will be inserted instead.
1056 If a function, the result from the function will be used instead.
1057 If a form, the result from the form will be used instead."
1060 :link
'(custom-manual "(message)Insertion Variables")
1061 :group
'message-insertion
)
1063 (defcustom message-signature-file mail-signature-file
1064 "*Name of file containing the text inserted at end of message buffer.
1065 Ignored if the named file doesn't exist.
1066 If nil, don't insert a signature.
1067 If a path is specified, the value of `message-signature-directory' is ignored,
1070 :type
'(choice file
(const :tags
"None" nil
))
1071 :link
'(custom-manual "(message)Insertion Variables")
1072 :group
'message-insertion
)
1074 (defcustom message-signature-directory nil
1075 "*Name of directory containing signature files.
1076 Comes in handy if you have many such files, handled via posting styles for
1078 If nil, `message-signature-file' is expected to specify the directory if
1080 :type
'(choice string
(const :tags
"None" nil
))
1081 :link
'(custom-manual "(message)Insertion Variables")
1082 :group
'message-insertion
)
1084 (defcustom message-signature-insert-empty-line t
1085 "*If non-nil, insert an empty line before the signature separator."
1088 :link
'(custom-manual "(message)Insertion Variables")
1089 :group
'message-insertion
)
1091 (defcustom message-distribution-function nil
1092 "*Function called to return a Distribution header."
1093 :group
'message-news
1094 :group
'message-headers
1095 :link
'(custom-manual "(message)News Headers")
1096 :type
'(choice function
(const nil
)))
1098 (defcustom message-expires
14
1099 "Number of days before your article expires."
1100 :group
'message-news
1101 :group
'message-headers
1102 :link
'(custom-manual "(message)News Headers")
1105 (defcustom message-user-path nil
1106 "If nil, use the NNTP server name in the Path header.
1107 If stringp, use this; if non-nil, use no host name (user name only)."
1108 :group
'message-news
1109 :group
'message-headers
1110 :link
'(custom-manual "(message)News Headers")
1111 :type
'(choice (const :tag
"nntp" nil
)
1112 (string :tag
"name")
1113 (sexp :tag
"none" :format
"%t" t
)))
1115 ;; This can be the name of a buffer, or a cons cell (FUNCTION . ARGS)
1116 ;; for yanking the original buffer.
1117 (defvar message-reply-buffer nil
)
1118 (defvar message-reply-headers nil
1119 "The headers of the current replied article.
1120 It is a vector of the following headers:
1121 \[number subject from date id references chars lines xref extra].")
1122 (defvar message-newsreader nil
)
1123 (defvar message-mailer nil
)
1124 (defvar message-sent-message-via nil
)
1125 (defvar message-checksum nil
)
1126 (defvar message-send-actions nil
1127 "A list of actions to be performed upon successful sending of a message.")
1128 (defvar message-exit-actions nil
1129 "A list of actions to be performed upon exiting after sending a message.")
1130 (defvar message-kill-actions nil
1131 "A list of actions to be performed before killing a message buffer.")
1132 (defvar message-postpone-actions nil
1133 "A list of actions to be performed after postponing a message.")
1135 (define-widget 'message-header-lines
'text
1136 "All header lines must be LFD terminated."
1137 :format
"%{%t%}:%n%v"
1138 :valid-regexp
"^\\'"
1139 :error
"All header lines must be newline terminated")
1141 (defcustom message-default-headers
""
1142 "Header lines to be inserted in outgoing messages.
1143 This can be set to a string containing or a function returning
1144 header lines to be inserted before you edit the message, so you
1145 can edit or delete these lines. If set to a function, it is
1146 called and its result is inserted."
1148 :group
'message-headers
1149 :link
'(custom-manual "(message)Message Headers")
1151 (message-header-lines :tag
"String")
1152 (function :tag
"Function")))
1154 (defcustom message-default-mail-headers
1155 ;; Ease the transition from mail-mode to message-mode. See bugs#4431, 5555.
1156 (concat (if (and (boundp 'mail-default-reply-to
)
1157 (stringp mail-default-reply-to
))
1158 (format "Reply-to: %s\n" mail-default-reply-to
))
1159 (if (and (boundp 'mail-self-blind
)
1161 (format "BCC: %s\n" user-mail-address
))
1162 (if (and (boundp 'mail-archive-file-name
)
1163 (stringp mail-archive-file-name
))
1164 (format "FCC: %s\n" mail-archive-file-name
))
1165 ;; Use the value of `mail-default-headers' if available.
1166 ;; Note: as for XEmacs 21.4 and 21.5, it is unavailable
1167 ;; unless sendmail.el is loaded.
1168 (if (boundp 'mail-default-headers
)
1169 mail-default-headers
))
1170 "*A string of header lines to be inserted in outgoing mails."
1172 :group
'message-headers
1173 :group
'message-mail
1174 :link
'(custom-manual "(message)Mail Headers")
1175 :type
'message-header-lines
)
1177 (defcustom message-default-news-headers
""
1178 "*A string of header lines to be inserted in outgoing news articles."
1179 :group
'message-headers
1180 :group
'message-news
1181 :link
'(custom-manual "(message)News Headers")
1182 :type
'message-header-lines
)
1184 ;; Note: could use /usr/ucb/mail instead of sendmail;
1185 ;; options -t, and -v if not interactive.
1186 (defcustom message-mailer-swallows-blank-line
1187 (if (and (string-match "sparc-sun-sunos\\(\\'\\|[^5]\\)"
1188 system-configuration
)
1189 (file-readable-p "/etc/sendmail.cf")
1190 (let ((buffer (get-buffer-create " *temp*")))
1192 (with-current-buffer buffer
1193 (insert-file-contents "/etc/sendmail.cf")
1194 (goto-char (point-min))
1195 (let ((case-fold-search nil
))
1196 (re-search-forward "^OR\\>" nil t
)))
1197 (kill-buffer buffer
))))
1198 ;; According to RFC822, "The field-name must be composed of printable
1199 ;; ASCII characters (i. e., characters that have decimal values between
1200 ;; 33 and 126, except colon)", i. e., any chars except ctl chars,
1202 '(looking-at "[ \t]\\|[][!\"#$%&'()*+,-./0-9;<=>?@A-Z\\\\^_`a-z{|}~]+:"))
1203 "*Set this non-nil if the system's mailer runs the header and body together.
1204 \(This problem exists on Sunos 4 when sendmail is run in remote mode.)
1205 The value should be an expression to test whether the problem will
1207 :group
'message-sending
1208 :link
'(custom-manual "(message)Mail Variables")
1212 (define-mail-user-agent 'message-user-agent
1213 'message-mail
'message-send-and-exit
1214 'message-kill-buffer
'message-send-hook
)
1216 (defvar message-mh-deletable-headers
'(Message-ID Date Lines Sender
)
1217 "If non-nil, delete the deletable headers before feeding to mh.")
1219 (defvar message-send-method-alist
1220 '((news message-news-p message-send-via-news
)
1221 (mail message-mail-p message-send-via-mail
))
1222 "Alist of ways to send outgoing messages.
1223 Each element has the form
1225 \(TYPE PREDICATE FUNCTION)
1227 where TYPE is a symbol that names the method; PREDICATE is a function
1228 called without any parameters to determine whether the message is
1229 a message of type TYPE; and FUNCTION is a function to be called if
1230 PREDICATE returns non-nil. FUNCTION is called with one parameter --
1233 (defcustom message-mail-alias-type
'abbrev
1234 "*What alias expansion type to use in Message buffers.
1235 The default is `abbrev', which uses mailabbrev. `ecomplete' uses
1236 an electric completion mode. nil switches mail aliases off.
1237 This can also be a list of values."
1239 :link
'(custom-manual "(message)Mail Aliases")
1240 :type
'(choice (const :tag
"Use Mailabbrev" abbrev
)
1241 (const :tag
"Use ecomplete" ecomplete
)
1242 (const :tag
"No expansion" nil
)))
1244 (defcustom message-self-insert-commands
'(self-insert-command)
1245 "List of `self-insert-command's used to trigger ecomplete.
1246 When one of those commands is invoked to enter a character in To or Cc
1247 header, ecomplete will suggest the candidates of recipients (see also
1248 `message-mail-alias-type'). If you use some tool to enter non-ASCII
1249 text and it replaces `self-insert-command' with the other command, e.g.
1250 `egg-self-insert-command', you may want to add it to this list."
1251 :group
'message-various
1252 :type
'(repeat function
))
1254 (defcustom message-auto-save-directory
1255 (file-name-as-directory (expand-file-name "drafts" message-directory
))
1256 "*Directory where Message auto-saves buffers if Gnus isn't running.
1257 If nil, Message won't auto-save."
1258 :group
'message-buffers
1259 :link
'(custom-manual "(message)Various Message Variables")
1260 :type
'(choice directory
(const :tag
"Don't auto-save" nil
)))
1262 (defcustom message-default-charset
1263 (and (not (mm-multibyte-p)) 'iso-8859-1
)
1264 "Default charset used in non-MULE Emacsen.
1265 If nil, you might be asked to input the charset."
1268 :link
'(custom-manual "(message)Various Message Variables")
1271 (defcustom message-dont-reply-to-names
1272 (and (boundp 'rmail-dont-reply-to-names
) rmail-dont-reply-to-names
)
1273 "*Addresses to prune when doing wide replies.
1274 This can be a regexp or a list of regexps. Also, a value of nil means
1275 exclude your own user name only."
1278 :link
'(custom-manual "(message)Wide Reply")
1279 :type
'(choice (const :tag
"Yourself" nil
)
1281 (repeat :tag
"Regexp List" regexp
)))
1283 (defsubst message-dont-reply-to-names
()
1284 (gmm-regexp-concat message-dont-reply-to-names
))
1286 (defvar message-shoot-gnksa-feet nil
1287 "*A list of GNKSA feet you are allowed to shoot.
1288 Gnus gives you all the opportunity you could possibly want for
1289 shooting yourself in the foot. Also, Gnus allows you to shoot the
1290 feet of Good Net-Keeping Seal of Approval. The following are foot
1292 `empty-article' Allow you to post an empty article;
1293 `quoted-text-only' Allow you to post quoted text only;
1294 `multiple-copies' Allow you to post multiple copies;
1295 `cancel-messages' Allow you to cancel or supersede messages from
1296 your other email addresses.")
1298 (defsubst message-gnksa-enable-p
(feature)
1299 (or (not (listp message-shoot-gnksa-feet
))
1300 (memq feature message-shoot-gnksa-feet
)))
1302 (defcustom message-hidden-headers
'("^References:" "^Face:" "^X-Face:"
1304 "Regexp of headers to be hidden when composing new messages.
1305 This can also be a list of regexps to match headers. Or a list
1306 starting with `not' and followed by regexps."
1309 :link
'(custom-manual "(message)Message Headers")
1311 :format
"%{%t%}: %[Value Type%] %v"
1312 (regexp :menu-tag
"regexp" :format
"regexp\n%t: %v")
1313 (repeat :menu-tag
"(regexp ...)" :format
"(regexp ...)\n%v%i"
1314 (regexp :format
"%t: %v"))
1315 (cons :menu-tag
"(not regexp ...)" :format
"(not regexp ...)\n%v"
1317 (repeat :format
"%v%i"
1318 (regexp :format
"%t: %v")))))
1320 (defcustom message-cite-articles-with-x-no-archive t
1321 "If non-nil, cite text from articles that has X-No-Archive set."
1325 ;;; Internal variables.
1326 ;;; Well, not really internal.
1328 (defvar message-mode-syntax-table
1329 (let ((table (copy-syntax-table text-mode-syntax-table
)))
1330 (modify-syntax-entry ?%
". " table
)
1331 (modify-syntax-entry ?
> ". " table
)
1332 (modify-syntax-entry ?
< ". " table
)
1334 "Syntax table used while in Message mode.")
1336 (defface message-header-to
1339 (:foreground
"DarkOliveGreen1" :bold t
))
1342 (:foreground
"MidnightBlue" :bold t
))
1344 (:bold t
:italic t
)))
1345 "Face used for displaying From headers."
1346 :group
'message-faces
)
1347 ;; backward-compatibility alias
1348 (put 'message-header-to-face
'face-alias
'message-header-to
)
1349 (put 'message-header-to-face
'obsolete-face
"22.1")
1351 (defface message-header-cc
1354 (:foreground
"chartreuse1" :bold t
))
1357 (:foreground
"MidnightBlue"))
1360 "Face used for displaying Cc headers."
1361 :group
'message-faces
)
1362 ;; backward-compatibility alias
1363 (put 'message-header-cc-face
'face-alias
'message-header-cc
)
1364 (put 'message-header-cc-face
'obsolete-face
"22.1")
1366 (defface message-header-subject
1369 (:foreground
"OliveDrab1"))
1372 (:foreground
"navy blue" :bold t
))
1375 "Face used for displaying subject headers."
1376 :group
'message-faces
)
1377 ;; backward-compatibility alias
1378 (put 'message-header-subject-face
'face-alias
'message-header-subject
)
1379 (put 'message-header-subject-face
'obsolete-face
"22.1")
1381 (defface message-header-newsgroups
1384 (:foreground
"yellow" :bold t
:italic t
))
1387 (:foreground
"blue4" :bold t
:italic t
))
1389 (:bold t
:italic t
)))
1390 "Face used for displaying newsgroups headers."
1391 :group
'message-faces
)
1392 ;; backward-compatibility alias
1393 (put 'message-header-newsgroups-face
'face-alias
'message-header-newsgroups
)
1394 (put 'message-header-newsgroups-face
'obsolete-face
"22.1")
1396 (defface message-header-other
1399 (:foreground
"VioletRed1"))
1402 (:foreground
"steel blue"))
1404 (:bold t
:italic t
)))
1405 "Face used for displaying newsgroups headers."
1406 :group
'message-faces
)
1407 ;; backward-compatibility alias
1408 (put 'message-header-other-face
'face-alias
'message-header-other
)
1409 (put 'message-header-other-face
'obsolete-face
"22.1")
1411 (defface message-header-name
1414 (:foreground
"green"))
1417 (:foreground
"cornflower blue"))
1420 "Face used for displaying header names."
1421 :group
'message-faces
)
1422 ;; backward-compatibility alias
1423 (put 'message-header-name-face
'face-alias
'message-header-name
)
1424 (put 'message-header-name-face
'obsolete-face
"22.1")
1426 (defface message-header-xheader
1429 (:foreground
"DeepSkyBlue1"))
1432 (:foreground
"blue"))
1435 "Face used for displaying X-Header headers."
1436 :group
'message-faces
)
1437 ;; backward-compatibility alias
1438 (put 'message-header-xheader-face
'face-alias
'message-header-xheader
)
1439 (put 'message-header-xheader-face
'obsolete-face
"22.1")
1441 (defface message-separator
1444 (:foreground
"LightSkyBlue1"))
1447 (:foreground
"brown"))
1450 "Face used for displaying the separator."
1451 :group
'message-faces
)
1452 ;; backward-compatibility alias
1453 (put 'message-separator-face
'face-alias
'message-separator
)
1454 (put 'message-separator-face
'obsolete-face
"22.1")
1456 (defface message-cited-text
1459 (:foreground
"LightPink1"))
1462 (:foreground
"red"))
1465 "Face used for displaying cited text names."
1466 :group
'message-faces
)
1467 ;; backward-compatibility alias
1468 (put 'message-cited-text-face
'face-alias
'message-cited-text
)
1469 (put 'message-cited-text-face
'obsolete-face
"22.1")
1471 (defface message-mml
1474 (:foreground
"MediumSpringGreen"))
1477 (:foreground
"ForestGreen"))
1480 "Face used for displaying MML."
1481 :group
'message-faces
)
1482 ;; backward-compatibility alias
1483 (put 'message-mml-face
'face-alias
'message-mml
)
1484 (put 'message-mml-face
'obsolete-face
"22.1")
1486 (defun message-font-lock-make-header-matcher (regexp)
1489 (let ((start (point)))
1492 (goto-char (point-min))
1493 (if (re-search-forward
1494 (concat "^" (regexp-quote mail-header-separator
) "$")
1496 (setq limit
(min limit
(match-beginning 0))))
1498 (and (< start limit
)
1499 (re-search-forward ,regexp limit t
))))))
1500 (if (featurep 'bytecomp
)
1504 (defvar message-font-lock-keywords
1505 (let ((content "[ \t]*\\(.+\\(\n[ \t].*\\)*\\)\n?"))
1506 `((,(message-font-lock-make-header-matcher
1507 (concat "^\\([Tt]o:\\)" content
))
1508 (1 'message-header-name
)
1509 (2 'message-header-to nil t
))
1510 (,(message-font-lock-make-header-matcher
1511 (concat "^\\(^[GBF]?[Cc][Cc]:\\|^[Rr]eply-[Tt]o:\\)" content
))
1512 (1 'message-header-name
)
1513 (2 'message-header-cc nil t
))
1514 (,(message-font-lock-make-header-matcher
1515 (concat "^\\([Ss]ubject:\\)" content
))
1516 (1 'message-header-name
)
1517 (2 'message-header-subject nil t
))
1518 (,(message-font-lock-make-header-matcher
1519 (concat "^\\([Nn]ewsgroups:\\|Followup-[Tt]o:\\)" content
))
1520 (1 'message-header-name
)
1521 (2 'message-header-newsgroups nil t
))
1522 (,(message-font-lock-make-header-matcher
1523 (concat "^\\(X-[A-Za-z0-9-]+:\\|In-Reply-To:\\)" content
))
1524 (1 'message-header-name
)
1525 (2 'message-header-xheader
))
1526 (,(message-font-lock-make-header-matcher
1527 (concat "^\\([A-Z][^: \n\t]+:\\)" content
))
1528 (1 'message-header-name
)
1529 (2 'message-header-other nil t
))
1530 ,@(if (and mail-header-separator
1531 (not (equal mail-header-separator
"")))
1532 `((,(concat "^\\(" (regexp-quote mail-header-separator
) "\\)$")
1533 1 'message-separator
))
1536 (re-search-forward (concat "^\\("
1537 message-cite-prefix-regexp
1540 (0 'message-cited-text
))
1541 ("<#/?\\(multipart\\|part\\|external\\|mml\\|secure\\)[^>]*>"
1543 "Additional expressions to highlight in Message mode.")
1546 ;; XEmacs does it like this. For Emacs, we have to set the
1547 ;; `font-lock-defaults' buffer-local variable.
1548 (put 'message-mode
'font-lock-defaults
'(message-font-lock-keywords t
))
1550 (defvar message-face-alist
1551 '((bold . message-bold-region
)
1552 (underline . underline-region
)
1553 (default .
(lambda (b e
)
1554 (message-unbold-region b e
)
1555 (ununderline-region b e
))))
1556 "Alist of mail and news faces for facemenu.
1557 The cdr of each entry is a function for applying the face to a region.")
1559 (defcustom message-send-hook nil
1560 "Hook run before sending messages.
1561 This hook is run quite early when sending."
1562 :group
'message-various
1563 :options
'(ispell-message)
1564 :link
'(custom-manual "(message)Various Message Variables")
1567 (defcustom message-send-mail-hook nil
1568 "Hook run before sending mail messages.
1569 This hook is run very late -- just before the message is sent as
1571 :group
'message-various
1572 :link
'(custom-manual "(message)Various Message Variables")
1575 (defcustom message-send-news-hook nil
1576 "Hook run before sending news messages.
1577 This hook is run very late -- just before the message is sent as
1579 :group
'message-various
1580 :link
'(custom-manual "(message)Various Message Variables")
1583 (defcustom message-sent-hook nil
1584 "Hook run after sending messages."
1585 :group
'message-various
1588 (defvar message-send-coding-system
'binary
1589 "Coding system to encode outgoing mail.")
1591 (defvar message-draft-coding-system
1592 mm-auto-save-coding-system
1593 "*Coding system to compose mail.
1594 If you'd like to make it possible to share draft files between XEmacs
1595 and Emacs, you may use `iso-2022-7bit' for this value at your own risk.
1596 Note that the coding-system `iso-2022-7bit' isn't suitable to all data.")
1598 (defcustom message-send-mail-partially-limit nil
1599 "The limitation of messages sent as message/partial.
1600 The lower bound of message size in characters, beyond which the message
1601 should be sent in several parts. If it is nil, the size is unlimited."
1603 :group
'message-buffers
1604 :link
'(custom-manual "(message)Mail Variables")
1605 :type
'(choice (const :tag
"unlimited" nil
)
1608 (defcustom message-alternative-emails nil
1609 "*Regexp matching alternative email addresses.
1610 The first address in the To, Cc or From headers of the original
1611 article matching this variable is used as the From field of
1614 This variable has precedence over posting styles and anything that runs
1615 off `message-setup-hook'."
1616 :group
'message-headers
1617 :link
'(custom-manual "(message)Message Headers")
1618 :type
'(choice (const :tag
"Always use primary" nil
)
1621 (defcustom message-hierarchical-addresses nil
1622 "A list of hierarchical mail address definitions.
1624 Inside each entry, the first address is the \"top\" address, and
1625 subsequent addresses are subaddresses; this is used to indicate that
1626 mail sent to the first address will automatically be delivered to the
1627 subaddresses. So if the first address appears in the recipient list
1628 for a message, the subaddresses will be removed (if present) before
1629 the mail is sent. All addresses in this structure should be
1632 :group
'message-headers
1633 :type
'(repeat (repeat string
)))
1635 (defcustom message-mail-user-agent nil
1636 "Like `mail-user-agent'.
1637 Except if it is nil, use Gnus native MUA; if it is t, use
1640 :type
'(radio (const :tag
"Gnus native"
1643 (const :tag
"`mail-user-agent'"
1646 (function-item :tag
"Default Emacs mail"
1648 sendmail-user-agent
)
1649 (function-item :tag
"Emacs interface to MH"
1652 (function :tag
"Other"))
1656 (defcustom message-wide-reply-confirm-recipients nil
1657 "Whether to confirm a wide reply to multiple email recipients.
1658 If this variable is nil, don't ask whether to reply to all recipients.
1659 If this variable is non-nil, pose the question \"Reply to all
1660 recipients?\" before a wide reply to multiple recipients. If the user
1661 answers yes, reply to all recipients as usual. If the user answers
1662 no, only reply back to the author."
1664 :group
'message-headers
1665 :link
'(custom-manual "(message)Wide Reply")
1668 (defcustom message-user-fqdn nil
1669 "*Domain part of Message-Ids."
1671 :group
'message-headers
1672 :link
'(custom-manual "(message)News Headers")
1673 :type
'(radio (const :format
"%v " nil
)
1674 (string :format
"FQDN: %v")))
1676 (defcustom message-use-idna
(and (condition-case nil
(require 'idna
)
1678 (mm-coding-system-p 'utf-8
)
1679 (executable-find idna-program
)
1680 (string= (idna-to-ascii "räksmörgås")
1681 "xn--rksmrgs-5wao1o")
1683 "Whether to encode non-ASCII in domain names into ASCII according to IDNA.
1684 GNU Libidn, and in particular the elisp package \"idna.el\" and
1685 the external program \"idn\", must be installed for this
1686 functionality to work."
1688 :group
'message-headers
1689 :link
'(custom-manual "(message)IDNA")
1690 :type
'(choice (const :tag
"Ask" ask
)
1691 (const :tag
"Never" nil
)
1692 (const :tag
"Always" t
)))
1694 (defcustom message-generate-hashcash
(if (executable-find "hashcash") 'opportunistic
)
1695 "*Whether to generate X-Hashcash: headers.
1696 If t, always generate hashcash headers. If `opportunistic',
1697 only generate hashcash headers if it can be done without the user
1698 waiting (i.e., only asynchronously).
1700 You must have the \"hashcash\" binary installed, see `hashcash-path'."
1702 :group
'message-headers
1703 :link
'(custom-manual "(message)Mail Headers")
1704 :type
'(choice (const :tag
"Always" t
)
1705 (const :tag
"Never" nil
)
1706 (const :tag
"Opportunistic" opportunistic
)))
1708 ;;; Internal variables.
1710 (defvar message-sending-message
"Sending...")
1711 (defvar message-buffer-list nil
)
1712 (defvar message-this-is-news nil
)
1713 (defvar message-this-is-mail nil
)
1714 (defvar message-draft-article nil
)
1715 (defvar message-mime-part nil
)
1716 (defvar message-posting-charset nil
)
1717 (defvar message-inserted-headers nil
)
1718 (defvar message-inhibit-ecomplete nil
)
1720 ;; Byte-compiler warning
1721 (defvar gnus-active-hashtb
)
1722 (defvar gnus-read-active-file
)
1724 ;;; Regexp matching the delimiter of messages in UNIX mail format
1725 ;;; (UNIX From lines), minus the initial ^. It should be a copy
1726 ;;; of rmail.el's rmail-unix-mail-delimiter.
1727 (defvar message-unix-mail-delimiter
1728 (let ((time-zone-regexp
1729 (concat "\\([A-Z]?[A-Z]?[A-Z][A-Z]\\( DST\\)?"
1730 "\\|[-+]?[0-9][0-9][0-9][0-9]"
1736 ;; Many things can happen to an RFC 822 mailbox before it is put into
1737 ;; a `From' line. The leading phrase can be stripped, e.g.
1738 ;; `Joe <@w.x:joe@y.z>' -> `<@w.x:joe@y.z>'. The <> can be stripped, e.g.
1739 ;; `<@x.y:joe@y.z>' -> `@x.y:joe@y.z'. Everything starting with a CRLF
1740 ;; can be removed, e.g.
1741 ;; From: joe@y.z (Joe K
1743 ;; can yield `From joe@y.z (Joe K Fri Mar 22 08:11:15 1996', and
1746 ;; can yield `From Joe User Fri Mar 22 08:11:15 1996'.
1747 ;; The mailbox can be removed or be replaced by white space, e.g.
1748 ;; From: "Joe User"{space}{tab}
1750 ;; can yield `From {space}{tab} Fri Mar 22 08:11:15 1996',
1751 ;; where {space} and {tab} represent the Ascii space and tab characters.
1752 ;; We want to match the results of any of these manglings.
1753 ;; The following regexp rejects names whose first characters are
1754 ;; obviously bogus, but after that anything goes.
1755 "\\([^\0-\b\n-\r\^?].*\\)?"
1757 ;; The time the message was sent.
1758 "\\([^\0-\r \^?]+\\) +" ; day of the week
1759 "\\([^\0-\r \^?]+\\) +" ; month
1760 "\\([0-3]?[0-9]\\) +" ; day of month
1761 "\\([0-2][0-9]:[0-5][0-9]\\(:[0-6][0-9]\\)?\\) *" ; time of day
1763 ;; Perhaps a time zone, specified by an abbreviation, or by a
1768 " \\([0-9][0-9]+\\) *"
1770 ;; On some systems the time zone can appear after the year, too.
1774 "\\(remote from .*\\)?"
1777 "Regexp matching the delimiter of messages in UNIX mail format.")
1779 (defvar message-unsent-separator
1780 (concat "^ *---+ +Unsent message follows +---+ *$\\|"
1781 "^ *---+ +Returned message +---+ *$\\|"
1782 "^Start of returned message$\\|"
1783 "^ *---+ +Original message +---+ *$\\|"
1784 "^ *--+ +begin message +--+ *$\\|"
1785 "^ *---+ +Original message follows +---+ *$\\|"
1786 "^ *---+ +Undelivered message follows +---+ *$\\|"
1787 "^------ This is a copy of the message, including all the headers. ------ *$\\|"
1788 "^|? *---+ +Message text follows: +---+ *|?$")
1789 "A regexp that matches the separator before the text of a failed message.")
1791 (defvar message-field-fillers
1792 '((To message-fill-field-address
)
1793 (Cc message-fill-field-address
)
1794 (From message-fill-field-address
))
1795 "Alist of header names/filler functions.")
1797 (defvar message-header-format-alist
1812 (References . message-shorten-references
)
1814 "Alist used for formatting headers.")
1816 (defvar message-options nil
1817 "Some saved answers when sending message.")
1819 (defvar message-send-mail-real-function nil
1820 "Internal send mail function.")
1822 (defvar message-bogus-system-names
"^localhost\\.\\|\\.local$"
1823 "The regexp of bogus system names.")
1825 (defcustom message-valid-fqdn-regexp
1826 (concat "[a-z0-9][-.a-z0-9]+\\." ;; [hostname.subdomain.]domain.
1828 "\\([a-z][a-z]\\|" ;; two letter country TDLs
1829 "aero\\|arpa\\|bitnet\\|biz\\|bofh\\|"
1830 "cat\\|com\\|coop\\|edu\\|gov\\|"
1831 "info\\|int\\|jobs\\|"
1832 "mil\\|mobi\\|museum\\|name\\|net\\|"
1833 "org\\|pro\\|travel\\|uucp\\)")
1834 ;; http://en.wikipedia.org/wiki/List_of_Internet_top-level_domains
1835 ;; http://en.wikipedia.org/wiki/GTLD
1836 ;; `in the process of being approved': .asia .post .tel .sex
1837 ;; "dead" nato bitnet uucp
1838 "Regular expression that matches a valid FQDN."
1839 ;; see also: gnus-button-valid-fqdn-regexp
1841 :group
'message-headers
1844 (autoload 'gnus-alive-p
"gnus-util")
1845 (autoload 'gnus-delay-article
"gnus-delay")
1846 (autoload 'gnus-extract-address-components
"gnus-util")
1847 (autoload 'gnus-find-method-for-group
"gnus")
1848 (autoload 'gnus-group-decoded-name
"gnus-group")
1849 (autoload 'gnus-group-name-charset
"gnus-group")
1850 (autoload 'gnus-group-name-decode
"gnus-group")
1851 (autoload 'gnus-groups-from-server
"gnus")
1852 (autoload 'gnus-make-local-hook
"gnus-util")
1853 (autoload 'gnus-open-server
"gnus-int")
1854 (autoload 'gnus-output-to-mail
"gnus-util")
1855 (autoload 'gnus-output-to-rmail
"gnus-util")
1856 (autoload 'gnus-request-post
"gnus-int")
1857 (autoload 'gnus-select-frame-set-input-focus
"gnus-util")
1858 (autoload 'gnus-server-string
"gnus")
1859 (autoload 'idna-to-ascii
"idna")
1860 (autoload 'message-setup-toolbar
"messagexmas")
1861 (autoload 'mh-new-draft-name
"mh-comp")
1862 (autoload 'mh-send-letter
"mh-comp")
1863 (autoload 'nndraft-request-associate-buffer
"nndraft")
1864 (autoload 'nndraft-request-expire-articles
"nndraft")
1865 (autoload 'nnvirtual-find-group-art
"nnvirtual")
1866 (autoload 'rmail-dont-reply-to
"mail-utils")
1867 (autoload 'rmail-msg-is-pruned
"rmail")
1868 (autoload 'rmail-output
"rmailout")
1873 ;;; Utility functions.
1876 (defmacro message-y-or-n-p
(question show
&rest text
)
1877 "Ask QUESTION, displaying remaining args in a temporary buffer if SHOW."
1878 `(message-talkative-question 'y-or-n-p
,question
,show
,@text
))
1880 (defmacro message-delete-line
(&optional n
)
1881 "Delete the current line (and the next N lines)."
1882 `(delete-region (progn (beginning-of-line) (point))
1883 (progn (forward-line ,(or n
1)) (point))))
1885 (defun message-mark-active-p ()
1886 "Non-nil means the mark and region are currently active in this buffer."
1889 (defun message-unquote-tokens (elems)
1890 "Remove double quotes (\") from strings in list ELEMS."
1891 (mapcar (lambda (item)
1892 (while (string-match "^\\(.*\\)\"\\(.*\\)$" item
)
1893 (setq item
(concat (match-string 1 item
)
1894 (match-string 2 item
))))
1898 (defun message-tokenize-header (header &optional separator
)
1899 "Split HEADER into a list of header elements.
1900 SEPARATOR is a string of characters to be used as separators. \",\"
1901 is used by default."
1904 (let ((regexp (format "[%s]+" (or separator
",")))
1906 beg quoted elems paren
)
1908 (mm-enable-multibyte)
1909 (setq beg
(point-min))
1911 (goto-char (point-min))
1916 (cond ((and (> (point) beg
)
1918 (and (looking-at regexp
)
1921 (push (buffer-substring beg
(point)) elems
)
1922 (setq beg
(match-end 0)))
1923 ((eq (char-after) ?
\")
1924 (setq quoted
(not quoted
)))
1925 ((and (eq (char-after) ?\
()
1928 ((and (eq (char-after) ?\
))
1931 (nreverse elems
)))))
1933 (autoload 'nnheader-insert-file-contents
"nnheader")
1935 (defun message-mail-file-mbox-p (file)
1936 "Say whether FILE looks like a Unix mbox file."
1937 (when (and (file-exists-p file
)
1938 (file-readable-p file
)
1939 (file-regular-p file
))
1941 (nnheader-insert-file-contents file
)
1942 (goto-char (point-min))
1943 (looking-at message-unix-mail-delimiter
))))
1945 (defun message-fetch-field (header &optional not-all
)
1946 "The same as `mail-fetch-field', only remove all newlines.
1947 The buffer is expected to be narrowed to just the header of the message;
1948 see `message-narrow-to-headers-or-head'."
1949 (let* ((inhibit-point-motion-hooks t
)
1950 (value (mail-fetch-field header nil
(not not-all
))))
1952 (while (string-match "\n[\t ]+" value
)
1953 (setq value
(replace-match " " t t value
)))
1956 (defun message-field-value (header &optional not-all
)
1957 "The same as `message-fetch-field', only narrow to the headers first."
1960 (message-narrow-to-headers-or-head)
1961 (message-fetch-field header not-all
))))
1963 (defun message-narrow-to-field ()
1964 "Narrow the buffer to the header on the current line."
1966 (while (looking-at "[ \t]")
1972 (if (re-search-forward "^[^ \n\t]" nil t
)
1975 (goto-char (point-min)))
1977 (defun message-add-header (&rest headers
)
1978 "Add the HEADERS to the message header, skipping those already present."
1981 (unless (string-match "^\\([^:]+\\):[ \t]*[^ \t]" (car headers
))
1982 (error "Invalid header `%s'" (car headers
)))
1983 (setq hclean
(match-string 1 (car headers
)))
1985 (message-narrow-to-headers)
1986 (unless (re-search-forward (concat "^" (regexp-quote hclean
) ":") nil t
)
1987 (goto-char (point-max))
1988 (if (string-match "\n$" (car headers
))
1989 (insert (car headers
))
1990 (insert (car headers
) ?
\n)))))
1991 (setq headers
(cdr headers
))))
1993 (defmacro message-with-reply-buffer
(&rest forms
)
1994 "Evaluate FORMS in the reply buffer, if it exists."
1995 `(when (and (bufferp message-reply-buffer
)
1996 (buffer-name message-reply-buffer
))
1997 (with-current-buffer message-reply-buffer
2000 (put 'message-with-reply-buffer
'lisp-indent-function
0)
2001 (put 'message-with-reply-buffer
'edebug-form-spec
'(body))
2003 (defun message-fetch-reply-field (header)
2004 "Fetch field HEADER from the message we're replying to."
2005 (message-with-reply-buffer
2007 (mail-narrow-to-head)
2008 (message-fetch-field header
))))
2010 (defun message-strip-list-identifiers (subject)
2011 "Remove list identifiers in `gnus-list-identifiers' from string SUBJECT."
2012 (require 'gnus-sum
) ; for gnus-list-identifiers
2013 (let ((regexp (if (stringp gnus-list-identifiers
)
2014 gnus-list-identifiers
2015 (mapconcat 'identity gnus-list-identifiers
" *\\|"))))
2016 (if (string-match (concat "\\(\\(\\(Re: +\\)?\\(" regexp
2017 " *\\)\\)+\\(Re: +\\)?\\)") subject
)
2018 (concat (substring subject
0 (match-beginning 1))
2019 (or (match-string 3 subject
)
2020 (match-string 5 subject
))
2025 (defun message-strip-subject-re (subject)
2026 "Remove \"Re:\" from subject lines in string SUBJECT."
2027 (if (string-match message-subject-re-regexp subject
)
2028 (substring subject
(match-end 0))
2031 (defcustom message-replacement-char
"."
2032 "Replacement character used instead of unprintable or not decodable chars."
2033 :group
'message-various
2034 :version
"22.1" ;; Gnus 5.10.9
2035 :type
'(choice string
2039 ;; FIXME: We also should call `message-strip-subject-encoded-words'
2040 ;; when forwarding. Probably in `message-make-forward-subject' and
2041 ;; `message-forward-make-body'.
2043 (defun message-strip-subject-encoded-words (subject)
2044 "Fix non-decodable words in SUBJECT."
2045 ;; Cf. `gnus-simplify-subject-fully'.
2046 (let* ((case-fold-search t
)
2047 (replacement-chars (format "[%s%s%s]"
2048 message-replacement-char
2049 message-replacement-char
2050 message-replacement-char
))
2051 (enc-word-re "=\\?\\([^?]+\\)\\?\\([QB]\\)\\?\\([^?]+\\)\\(\\?=\\)")
2056 (goto-char (point-min))
2057 (when (re-search-forward enc-word-re nil t
)
2058 (setq cs-string
(match-string 1)))))
2059 cs-coding q-or-b word-beg word-end
)
2060 (if (or (not have-marker
) ;; No encoded word found...
2061 ;; ... or double encoding was correct:
2062 (and (stringp cs-string
)
2063 (setq cs-string
(downcase cs-string
))
2064 (mm-coding-system-p (intern cs-string
))
2068 Decoded Subject \"%s\"
2069 contains a valid encoded word. Decode again? "
2071 (setq cs-coding
(intern cs-string
))))))
2075 (goto-char (point-min))
2076 (while (re-search-forward enc-word-re nil t
)
2077 (setq cs-string
(downcase (match-string 1))
2078 q-or-b
(match-string 2)
2079 word-beg
(match-beginning 0)
2080 word-end
(match-end 0))
2082 (if (mm-coding-system-p (intern cs-string
))
2083 (setq cs-coding
(intern cs-string
))
2085 ;; No double encoded subject? => bogus charset.
2088 (mm-read-coding-system
2090 Decoded Subject \"%s\"
2091 contains an encoded word. The charset `%s' is unknown or invalid.
2092 Hit RET to replace non-decodable characters with \"%s\" or enter replacement
2094 subject cs-string message-replacement-char
)))
2096 (replace-match (concat "=?" (symbol-name cs-coding
)
2099 (goto-char word-beg
)
2100 (re-search-forward "=\\?\\([^?]+\\)\\?\\([QB]\\)\\?" word-end t
)
2103 (if (string-match "\\`Q\\'" q-or-b
)
2106 (message "Replacing non-decodable characters with \"%s\"."
2107 message-replacement-char
)
2108 (while (re-search-forward "\\(=[A-F0-9][A-F0-9]\\)+"
2110 (replace-match message-replacement-char
)))
2112 (message "Replacing non-decodable characters with \"%s\"."
2114 (re-search-forward "[^?]+" word-end t
)
2115 (replace-match replacement-chars
))
2116 (re-search-forward "\\?=")
2117 (replace-match "")))))
2118 (rfc2047-decode-region (point-min) (point-max))
2121 ;;; Start of functions adopted from `message-utils.el'.
2123 (defun message-strip-subject-trailing-was (subject)
2124 "Remove trailing \"(was: <old subject>)\" from SUBJECT lines.
2125 Leading \"Re: \" is not stripped by this function. Use the function
2126 `message-strip-subject-re' for this."
2127 (let* ((query message-subject-trailing-was-query
)
2132 message-subject-trailing-was-ask-regexp
2133 message-subject-trailing-was-regexp
)
2136 (setq new
(substring subject
0 (match-beginning 0))))
2137 (if (or (not found
) (eq query nil
))
2140 (if (message-y-or-n-p
2141 "Strip `(was: <old subject>)' in subject? " t
2143 "Strip `(was: <old subject>)' in subject "
2144 "and use the new one instead?\n\n"
2145 "Current subject is: \""
2147 "New subject would be: \""
2149 "See the variable `message-subject-trailing-was-query' "
2150 "to get rid of this query."
2155 ;;; Suggested by Jonas Steverud @ www.dtek.chalmers.se/~d4jonas/
2157 (defun message-change-subject (new-subject)
2158 "Ask for NEW-SUBJECT header, append (was: <Old Subject>)."
2161 (read-from-minibuffer "New subject: ")))
2162 (cond ((and (not (or (null new-subject
) ; new subject not empty
2163 (zerop (string-width new-subject
))
2164 (string-match "^[ \t]*$" new-subject
))))
2168 (message-narrow-to-headers)
2169 (message-fetch-field "Subject"))))
2170 (cond ((not old-subject
)
2171 (error "No current subject"))
2174 (regexp-quote new-subject
)
2176 old-subject
)) ; yes, it really is a new subject
2177 ;; delete eventual Re: prefix
2179 (message-strip-subject-re old-subject
))
2180 (message-goto-subject)
2181 (message-delete-line)
2182 (insert (concat "Subject: "
2185 old-subject
")\n")))))))))
2187 (defun message-mark-inserted-region (beg end
&optional verbatim
)
2188 "Mark some region in the current article with enclosing tags.
2189 See `message-mark-insert-begin' and `message-mark-insert-end'.
2190 If VERBATIM, use slrn style verbatim marks (\"#v+\" and \"#v-\")."
2191 (interactive "r\nP")
2193 ;; add to the end of the region first, otherwise end would be invalid
2195 (insert (if verbatim
"#v-\n" message-mark-insert-end
))
2197 (insert (if verbatim
"#v+\n" message-mark-insert-begin
))))
2199 (defun message-mark-insert-file (file &optional verbatim
)
2200 "Insert FILE at point, marking it with enclosing tags.
2201 See `message-mark-insert-begin' and `message-mark-insert-end'.
2202 If VERBATIM, use slrn style verbatim marks (\"#v+\" and \"#v-\")."
2203 (interactive "fFile to insert: \nP")
2204 ;; reverse insertion to get correct result.
2206 (insert (if verbatim
"#v-\n" message-mark-insert-end
))
2208 (insert-file-contents file
)
2210 (insert (if verbatim
"#v+\n" message-mark-insert-begin
))))
2212 (defun message-add-archive-header ()
2213 "Insert \"X-No-Archive: Yes\" in the header and a note in the body.
2214 The note can be customized using `message-archive-note'. When called with a
2215 prefix argument, ask for a text to insert. If you don't want the note in the
2216 body, set `message-archive-note' to nil."
2218 (if current-prefix-arg
2219 (setq message-archive-note
2220 (read-from-minibuffer "Reason for No-Archive: "
2221 (cons message-archive-note
0))))
2223 (if (message-goto-signature)
2224 (re-search-backward message-signature-separator
))
2225 (when message-archive-note
2226 (insert message-archive-note
)
2228 (message-add-header message-archive-header
)
2229 (message-sort-headers)))
2231 (defun message-cross-post-followup-to-header (target-group)
2232 "Mangles FollowUp-To and Newsgroups header to point to TARGET-GROUP.
2233 With prefix-argument just set Follow-Up, don't cross-post."
2235 (list ; Completion based on Gnus
2236 (completing-read "Followup To: "
2237 (if (boundp 'gnus-newsrc-alist
)
2239 nil nil
'("poster" .
0)
2240 (if (boundp 'gnus-group-history
)
2241 'gnus-group-history
))))
2242 (message-remove-header "Follow[Uu]p-[Tt]o" t
)
2243 (message-goto-newsgroups)
2245 ;; if we already did a crosspost before, kill old target
2246 (if (and message-cross-post-old-target
2248 (regexp-quote (concat "," message-cross-post-old-target
))
2251 ;; unless (followup is to poster or user explicitly asked not
2252 ;; to cross-post, or target-group is already in Newsgroups)
2253 ;; add target-group to Newsgroups line.
2255 ;; def: cross-post, req:no
2256 (and message-cross-post-default
(not current-prefix-arg
))
2257 ;; def: no-cross-post, req:yes
2258 (and (not message-cross-post-default
) current-prefix-arg
))
2259 (not (string-match "poster" target-group
))
2260 (not (string-match (regexp-quote target-group
)
2261 (message-fetch-field "Newsgroups"))))
2263 (insert (concat "," target-group
))))
2264 (end-of-line) ; ensure Followup: comes after Newsgroups:
2265 ;; unless new followup would be identical to Newsgroups line
2266 ;; make a new Followup-To line
2267 (if (not (string-match (concat "^[ \t]*"
2270 (message-fetch-field "Newsgroups")))
2271 (insert (concat "\nFollowup-To: " target-group
)))
2272 (setq message-cross-post-old-target target-group
))
2274 (defun message-cross-post-insert-note (target-group cross-post in-old
2276 "Insert a in message body note about a set Followup or Crosspost.
2277 If there have been previous notes, delete them. TARGET-GROUP specifies the
2278 group to Followup-To. When CROSS-POST is t, insert note about
2279 crossposting. IN-OLD specifies whether TARGET-GROUP is a member of
2280 OLD-GROUPS. OLD-GROUPS lists the old-groups the posting would have
2281 been made to before the user asked for a Crosspost."
2282 ;; start scanning body for previous uses
2283 (message-goto-signature)
2284 (let ((head (re-search-backward
2285 (concat "^" mail-header-separator
)
2286 nil t
))) ; just search in body
2287 (message-goto-signature)
2288 (while (re-search-backward
2289 (concat "^" (regexp-quote message-cross-post-note
) ".*")
2291 (message-delete-line))
2292 (message-goto-signature)
2293 (while (re-search-backward
2294 (concat "^" (regexp-quote message-followup-to-note
) ".*")
2296 (message-delete-line))
2298 (if (message-goto-signature)
2299 (re-search-backward message-signature-separator
))
2302 (string-match "^[ \t]*poster[ \t]*$" target-group
))
2303 (insert (concat message-followup-to-note target-group
"\n"))
2304 (insert (concat message-cross-post-note target-group
"\n")))))
2306 (defun message-cross-post-followup-to (target-group)
2307 "Crossposts message and set Followup-To to TARGET-GROUP.
2308 With prefix-argument just set Follow-Up, don't cross-post."
2310 (list ; Completion based on Gnus
2311 (completing-read "Followup To: "
2312 (if (boundp 'gnus-newsrc-alist
)
2314 nil nil
'("poster" .
0)
2315 (if (boundp 'gnus-group-history
)
2316 'gnus-group-history
))))
2317 (cond ((not (or (null target-group
) ; new subject not empty
2318 (zerop (string-width target-group
))
2319 (string-match "^[ \t]*$" target-group
)))
2321 (let* ((old-groups (message-fetch-field "Newsgroups"))
2322 (in-old (string-match
2323 (regexp-quote target-group
)
2324 (or old-groups
""))))
2325 ;; check whether target exactly matches old Newsgroups
2326 (cond ((not old-groups
)
2327 (error "No current newsgroup"))
2331 (regexp-quote target-group
)
2334 ;; yes, Newsgroups line must change
2335 (message-cross-post-followup-to-header target-group
)
2336 ;; insert note whether we do cross-post or followup-to
2337 (funcall message-cross-post-note-function
2339 (if (or (and message-cross-post-default
2340 (not current-prefix-arg
))
2341 (and (not message-cross-post-default
)
2342 current-prefix-arg
)) t
)
2343 in-old old-groups
))))))))
2345 ;;; Reduce To: to Cc: or Bcc: header
2347 (defun message-reduce-to-to-cc ()
2348 "Replace contents of To: header with contents of Cc: or Bcc: header."
2351 (save-restriction (message-narrow-to-headers)
2352 (message-fetch-field "cc")))
2354 (if (and (not cc-content
)
2357 (message-narrow-to-headers)
2358 (message-fetch-field "bcc"))))
2363 (message-delete-line)
2364 (insert (concat "To: " cc-content
"\n"))
2366 (message-narrow-to-headers)
2367 (message-remove-header (if bcc
2371 ;;; End of functions adopted from `message-utils.el'.
2373 (defun message-remove-header (header &optional is-regexp first reverse
)
2374 "Remove HEADER in the narrowed buffer.
2375 If IS-REGEXP, HEADER is a regular expression.
2376 If FIRST, only remove the first instance of the header.
2377 Return the number of headers removed."
2378 (goto-char (point-min))
2379 (let ((regexp (if is-regexp header
(concat "^" (regexp-quote header
) ":")))
2381 (case-fold-search t
)
2383 (while (and (not (eobp))
2386 (not (looking-at regexp
))
2387 (looking-at regexp
))
2394 ;; There might be a continuation header, so we have to search
2395 ;; until we find a new non-continuation line.
2398 (if (re-search-forward "^[^ \t]" nil t
)
2399 (goto-char (match-beginning 0))
2402 (if (re-search-forward "^[^ \t]" nil t
)
2403 (goto-char (match-beginning 0))
2404 (goto-char (point-max)))))
2407 (defun message-remove-first-header (header)
2408 "Remove the first instance of HEADER if there is more than one."
2410 (regexp (concat "^" (regexp-quote header
) ":")))
2412 (goto-char (point-min))
2413 (while (re-search-forward regexp nil t
)
2416 (message-remove-header header nil t
)
2419 (defun message-narrow-to-headers ()
2420 "Narrow the buffer to the head of the message."
2423 (goto-char (point-min))
2424 (if (re-search-forward
2425 (concat "^" (regexp-quote mail-header-separator
) "\n") nil t
)
2428 (goto-char (point-min)))
2430 (defun message-narrow-to-head-1 ()
2431 "Like `message-narrow-to-head'. Don't widen."
2433 (goto-char (point-min))
2434 (if (search-forward "\n\n" nil
1)
2437 (goto-char (point-min)))
2439 ;; FIXME: clarify diffference: message-narrow-to-head,
2440 ;; message-narrow-to-headers-or-head, message-narrow-to-headers
2441 (defun message-narrow-to-head ()
2442 "Narrow the buffer to the head of the message.
2443 Point is left at the beginning of the narrowed-to region."
2445 (message-narrow-to-head-1))
2447 (defun message-narrow-to-headers-or-head ()
2448 "Narrow the buffer to the head of the message."
2451 (goto-char (point-min))
2452 (if (re-search-forward (concat "\\(\n\\)\n\\|^\\("
2453 (regexp-quote mail-header-separator
)
2456 (or (match-end 1) (match-beginning 2))
2458 (goto-char (point-min)))
2460 (defun message-news-p ()
2461 "Say whether the current buffer contains a news message."
2462 (and (not message-this-is-mail
)
2463 (or message-this-is-news
2466 (message-narrow-to-headers)
2467 (and (message-fetch-field "newsgroups")
2468 (not (message-fetch-field "posted-to"))))))))
2470 (defun message-mail-p ()
2471 "Say whether the current buffer contains a mail message."
2472 (and (not message-this-is-news
)
2473 (or message-this-is-mail
2476 (message-narrow-to-headers)
2477 (or (message-fetch-field "to")
2478 (message-fetch-field "cc")
2479 (message-fetch-field "bcc")))))))
2481 (defun message-subscribed-p ()
2482 "Say whether we need to insert a MFT header."
2483 (or message-subscribed-regexps
2484 message-subscribed-addresses
2485 message-subscribed-address-file
2486 message-subscribed-address-functions
))
2488 (defun message-next-header ()
2489 "Go to the beginning of the next header."
2491 (or (eobp) (forward-char 1))
2492 (not (if (re-search-forward "^[^ \t]" nil t
)
2494 (goto-char (point-max)))))
2496 (defun message-sort-headers-1 ()
2497 "Sort the buffer as headers using `message-rank' text props."
2498 (goto-char (point-min))
2501 nil
'message-next-header
2503 (message-next-header)
2507 (or (get-text-property (point) 'message-rank
)
2510 (defun message-sort-headers ()
2511 "Sort the headers of the current message according to `message-header-format-alist'."
2515 (let ((max (1+ (length message-header-format-alist
)))
2517 (message-narrow-to-headers)
2518 (while (re-search-forward "^[^ \n]+:" nil t
)
2520 (match-beginning 0) (1+ (match-beginning 0))
2522 (if (setq rank
(length (memq (assq (intern (buffer-substring
2524 (1- (match-end 0))))
2525 message-header-format-alist
)
2526 message-header-format-alist
)))
2529 (message-sort-headers-1))))
2531 (defun message-kill-address ()
2532 "Kill the address under point."
2534 (let ((start (point)))
2535 (message-skip-to-next-address)
2536 (kill-region start
(point))))
2539 (autoload 'Info-goto-node
"info")
2540 (defvar mml2015-use
)
2542 (defun message-info (&optional arg
)
2543 "Display the Message manual.
2545 Prefixed with one \\[universal-argument], display the Emacs MIME
2546 manual. With two \\[universal-argument]'s, display the EasyPG or
2547 PGG manual, depending on the value of `mml2015-use'."
2549 ;; Don't use `info' because support for `(filename)nodename' is not
2550 ;; available in XEmacs < 21.5.12.
2551 (Info-goto-node (format "(%s)Top"
2555 ((eq arg
4) 'emacs-mime
)
2556 ;; `booleanp' only available in Emacs 22+
2557 ((and (not (memq arg
'(nil t
)))
2571 (defvar message-mode-map nil
)
2573 (unless message-mode-map
2574 (setq message-mode-map
(make-keymap))
2575 (set-keymap-parent message-mode-map text-mode-map
)
2576 (define-key message-mode-map
"\C-c?" 'describe-mode
)
2578 (define-key message-mode-map
"\C-c\C-f\C-t" 'message-goto-to
)
2579 (define-key message-mode-map
"\C-c\C-f\C-o" 'message-goto-from
)
2580 (define-key message-mode-map
"\C-c\C-f\C-b" 'message-goto-bcc
)
2581 (define-key message-mode-map
"\C-c\C-f\C-w" 'message-goto-fcc
)
2582 (define-key message-mode-map
"\C-c\C-f\C-c" 'message-goto-cc
)
2583 (define-key message-mode-map
"\C-c\C-f\C-s" 'message-goto-subject
)
2584 (define-key message-mode-map
"\C-c\C-f\C-r" 'message-goto-reply-to
)
2585 (define-key message-mode-map
"\C-c\C-f\C-n" 'message-goto-newsgroups
)
2586 (define-key message-mode-map
"\C-c\C-f\C-d" 'message-goto-distribution
)
2587 (define-key message-mode-map
"\C-c\C-f\C-f" 'message-goto-followup-to
)
2588 (define-key message-mode-map
"\C-c\C-f\C-m" 'message-goto-mail-followup-to
)
2589 (define-key message-mode-map
"\C-c\C-f\C-k" 'message-goto-keywords
)
2590 (define-key message-mode-map
"\C-c\C-f\C-u" 'message-goto-summary
)
2591 (define-key message-mode-map
"\C-c\C-f\C-i"
2592 'message-insert-or-toggle-importance
)
2593 (define-key message-mode-map
"\C-c\C-f\C-a"
2594 'message-generate-unsubscribed-mail-followup-to
)
2596 ;; modify headers (and insert notes in body)
2597 (define-key message-mode-map
"\C-c\C-fs" 'message-change-subject
)
2599 (define-key message-mode-map
"\C-c\C-fx" 'message-cross-post-followup-to
)
2600 ;; prefix+message-cross-post-followup-to = same w/o cross-post
2601 (define-key message-mode-map
"\C-c\C-ft" 'message-reduce-to-to-cc
)
2602 (define-key message-mode-map
"\C-c\C-fa" 'message-add-archive-header
)
2603 ;; mark inserted text
2604 (define-key message-mode-map
"\C-c\M-m" 'message-mark-inserted-region
)
2605 (define-key message-mode-map
"\C-c\M-f" 'message-mark-insert-file
)
2607 (define-key message-mode-map
"\C-c\C-b" 'message-goto-body
)
2608 (define-key message-mode-map
"\C-c\C-i" 'message-goto-signature
)
2610 (define-key message-mode-map
"\C-c\C-t" 'message-insert-to
)
2611 (define-key message-mode-map
"\C-c\C-fw" 'message-insert-wide-reply
)
2612 (define-key message-mode-map
"\C-c\C-n" 'message-insert-newsgroups
)
2613 (define-key message-mode-map
"\C-c\C-l" 'message-to-list-only
)
2614 (define-key message-mode-map
"\C-c\C-f\C-e" 'message-insert-expires
)
2616 (define-key message-mode-map
"\C-c\C-u" 'message-insert-or-toggle-importance
)
2617 (define-key message-mode-map
"\C-c\M-n"
2618 'message-insert-disposition-notification-to
)
2620 (define-key message-mode-map
"\C-c\C-y" 'message-yank-original
)
2621 (define-key message-mode-map
"\C-c\M-\C-y" 'message-yank-buffer
)
2622 (define-key message-mode-map
"\C-c\C-q" 'message-fill-yanked-message
)
2623 (define-key message-mode-map
"\C-c\C-w" 'message-insert-signature
)
2624 (define-key message-mode-map
"\C-c\M-h" 'message-insert-headers
)
2625 (define-key message-mode-map
"\C-c\C-r" 'message-caesar-buffer-body
)
2626 (define-key message-mode-map
"\C-c\C-o" 'message-sort-headers
)
2627 (define-key message-mode-map
"\C-c\M-r" 'message-rename-buffer
)
2629 (define-key message-mode-map
"\C-c\C-c" 'message-send-and-exit
)
2630 (define-key message-mode-map
"\C-c\C-s" 'message-send
)
2631 (define-key message-mode-map
"\C-c\C-k" 'message-kill-buffer
)
2632 (define-key message-mode-map
"\C-c\C-d" 'message-dont-send
)
2633 (define-key message-mode-map
"\C-c\n" 'gnus-delay-article
)
2635 (define-key message-mode-map
"\C-c\M-k" 'message-kill-address
)
2636 (define-key message-mode-map
"\C-c\C-e" 'message-elide-region
)
2637 (define-key message-mode-map
"\C-c\C-v" 'message-delete-not-region
)
2638 (define-key message-mode-map
"\C-c\C-z" 'message-kill-to-signature
)
2639 (define-key message-mode-map
"\M-\r" 'message-newline-and-reformat
)
2640 (define-key message-mode-map
[remap split-line
] 'message-split-line
)
2642 (define-key message-mode-map
"\C-c\C-a" 'mml-attach-file
)
2644 (define-key message-mode-map
"\C-a" 'message-beginning-of-line
)
2645 (define-key message-mode-map
"\t" 'message-tab
)
2647 (define-key message-mode-map
"\M-n" 'message-display-abbrev
))
2650 message-mode-menu message-mode-map
"Message Menu."
2652 ["Yank Original" message-yank-original message-reply-buffer
]
2653 ["Fill Yanked Message" message-fill-yanked-message t
]
2654 ["Insert Signature" message-insert-signature t
]
2655 ["Caesar (rot13) Message" message-caesar-buffer-body t
]
2656 ["Caesar (rot13) Region" message-caesar-region
(message-mark-active-p)]
2657 ["Elide Region" message-elide-region
2658 :active
(message-mark-active-p)
2659 ,@(if (featurep 'xemacs
) nil
2660 '(:help
"Replace text in region with an ellipsis"))]
2661 ["Delete Outside Region" message-delete-not-region
2662 :active
(message-mark-active-p)
2663 ,@(if (featurep 'xemacs
) nil
2664 '(:help
"Delete all quoted text outside region"))]
2665 ["Kill To Signature" message-kill-to-signature t
]
2666 ["Newline and Reformat" message-newline-and-reformat t
]
2667 ["Rename buffer" message-rename-buffer t
]
2668 ["Spellcheck" ispell-message
2669 ,@(if (featurep 'xemacs
) '(t)
2670 '(:help
"Spellcheck this message"))]
2672 ["Insert Region Marked" message-mark-inserted-region
2673 :active
(message-mark-active-p)
2674 ,@(if (featurep 'xemacs
) nil
2675 '(:help
"Mark region with enclosing tags"))]
2676 ["Insert File Marked..." message-mark-insert-file
2677 ,@(if (featurep 'xemacs
) '(t)
2678 '(:help
"Insert file at point marked with enclosing tags"))]
2680 ["Send Message" message-send-and-exit
2681 ,@(if (featurep 'xemacs
) '(t)
2682 '(:help
"Send this message"))]
2683 ["Postpone Message" message-dont-send
2684 ,@(if (featurep 'xemacs
) '(t)
2685 '(:help
"File this draft message and exit"))]
2686 ["Send at Specific Time..." gnus-delay-article
2687 ,@(if (featurep 'xemacs
) '(t)
2688 '(:help
"Ask, then arrange to send message at that time"))]
2689 ["Kill Message" message-kill-buffer
2690 ,@(if (featurep 'xemacs
) '(t)
2691 '(:help
"Delete this message without sending"))]
2693 ["Message manual" message-info
2694 ,@(if (featurep 'xemacs
) '(t)
2695 '(:help
"Display the Message manual"))]))
2698 message-mode-field-menu message-mode-map
""
2700 ["To" message-goto-to t
]
2701 ["From" message-goto-from t
]
2702 ["Subject" message-goto-subject t
]
2703 ["Change subject..." message-change-subject t
]
2704 ["Cc" message-goto-cc t
]
2705 ["Bcc" message-goto-bcc t
]
2706 ["Fcc" message-goto-fcc t
]
2707 ["Reply-To" message-goto-reply-to t
]
2708 ["Flag As Important" message-insert-importance-high
2709 ,@(if (featurep 'xemacs
) '(t)
2710 '(:help
"Mark this message as important"))]
2711 ["Flag As Unimportant" message-insert-importance-low
2712 ,@(if (featurep 'xemacs
) '(t)
2713 '(:help
"Mark this message as unimportant"))]
2715 message-insert-disposition-notification-to
2716 ,@(if (featurep 'xemacs
) '(t)
2717 '(:help
"Request a receipt notification"))]
2719 ;; (typical) news stuff
2720 ["Summary" message-goto-summary t
]
2721 ["Keywords" message-goto-keywords t
]
2722 ["Newsgroups" message-goto-newsgroups t
]
2723 ["Fetch Newsgroups" message-insert-newsgroups t
]
2724 ["Followup-To" message-goto-followup-to t
]
2725 ;; ["Followup-To (with note in body)" message-cross-post-followup-to t]
2726 ["Crosspost / Followup-To..." message-cross-post-followup-to t
]
2727 ["Distribution" message-goto-distribution t
]
2728 ["Expires" message-insert-expires t
]
2729 ["X-No-Archive" message-add-archive-header t
]
2731 ;; (typical) mailing-lists stuff
2732 ["Fetch To" message-insert-to
2733 ,@(if (featurep 'xemacs
) '(t)
2734 '(:help
"Insert a To header that points to the author."))]
2735 ["Fetch To and Cc" message-insert-wide-reply
2736 ,@(if (featurep 'xemacs
) '(t)
2738 "Insert To and Cc headers as if you were doing a wide reply."))]
2740 ["Send to list only" message-to-list-only t
]
2741 ["Mail-Followup-To" message-goto-mail-followup-to t
]
2742 ["Unsubscribed list post" message-generate-unsubscribed-mail-followup-to
2743 ,@(if (featurep 'xemacs
) '(t)
2744 '(:help
"Insert a reasonable `Mail-Followup-To:' header."))]
2745 ["Reduce To: to Cc:" message-reduce-to-to-cc t
]
2747 ["Sort Headers" message-sort-headers t
]
2748 ["Encode non-ASCII domain names" message-idna-to-ascii-rhs t
]
2749 ;; We hide `message-hidden-headers' by narrowing the buffer.
2750 ["Show Hidden Headers" widen t
]
2751 ["Goto Body" message-goto-body t
]
2752 ["Goto Signature" message-goto-signature t
]))
2754 (defvar message-tool-bar-map nil
)
2756 (defvar facemenu-add-face-function
)
2757 (defvar facemenu-remove-face-function
)
2759 ;;; Forbidden properties
2761 ;; We use `after-change-functions' to keep special text properties
2762 ;; that interfere with the normal function of message mode out of the
2765 (defcustom message-strip-special-text-properties t
2766 "Strip special properties from the message buffer.
2768 Emacs has a number of special text properties which can break message
2769 composing in various ways. If this option is set, message will strip
2770 these properties from the message composition buffer. However, some
2771 packages requires these properties to be present in order to work.
2772 If you use one of these packages, turn this option off, and hope the
2773 message composition doesn't break too bad."
2775 :group
'message-various
2776 :link
'(custom-manual "(message)Various Message Variables")
2779 (defconst message-forbidden-properties
2780 ;; No reason this should be clutter up customize. We make it a
2781 ;; property list (rather than a list of property symbols), to be
2782 ;; directly useful for `remove-text-properties'.
2783 '(field nil read-only nil invisible nil intangible nil
2784 mouse-face nil modification-hooks nil insert-in-front-hooks nil
2785 insert-behind-hooks nil point-entered nil point-left nil
)
2786 ;; Other special properties:
2787 ;; category, face, display: probably doesn't do any harm.
2788 ;; fontified: is used by font-lock.
2789 ;; syntax-table, local-map: I dunno.
2790 ;; We need to add XEmacs names to the list.
2791 "Property list of with properties forbidden in message buffers.
2792 The values of the properties are ignored, only the property names are used.")
2794 (defun message-tamago-not-in-use-p (pos)
2795 "Return t when tamago version 4 is not in use at the cursor position.
2796 Tamago version 4 is a popular input method for writing Japanese text.
2797 It uses the properties `intangible', `invisible', `modification-hooks'
2798 and `read-only' when translating ascii or kana text to kanji text.
2799 These properties are essential to work, so we should never strip them."
2800 (not (and (boundp 'egg-modefull-mode
)
2801 (symbol-value 'egg-modefull-mode
)
2802 (or (memq (get-text-property pos
'intangible
)
2803 '(its-part-1 its-part-2
))
2804 (get-text-property pos
'egg-end
)
2805 (get-text-property pos
'egg-lang
)
2806 (get-text-property pos
'egg-start
)))))
2808 (defsubst message-mail-alias-type-p
(type)
2809 (if (atom message-mail-alias-type
)
2810 (eq message-mail-alias-type type
)
2811 (memq type message-mail-alias-type
)))
2813 (defun message-strip-forbidden-properties (begin end
&optional old-length
)
2814 "Strip forbidden properties between BEGIN and END, ignoring the third arg.
2815 This function is intended to be called from `after-change-functions'.
2816 See also `message-forbidden-properties'."
2817 (when (and (message-mail-alias-type-p 'ecomplete
)
2818 (memq this-command message-self-insert-commands
))
2819 (message-display-abbrev))
2820 (when (and message-strip-special-text-properties
2821 (message-tamago-not-in-use-p begin
))
2822 (let ((buffer-read-only nil
)
2823 (inhibit-read-only t
))
2824 (remove-text-properties begin end message-forbidden-properties
))))
2826 (autoload 'ecomplete-setup
"ecomplete") ;; for Emacs <23.
2829 (define-derived-mode message-mode text-mode
"Message"
2830 "Major mode for editing mail and news to be sent.
2831 Like Text Mode but with these additional commands:\\<message-mode-map>
2832 C-c C-s `message-send' (send the message) C-c C-c `message-send-and-exit'
2833 C-c C-d Postpone sending the message C-c C-k Kill the message
2834 C-c C-f move to a header field (and create it if there isn't):
2835 C-c C-f C-t move to To C-c C-f C-s move to Subject
2836 C-c C-f C-c move to Cc C-c C-f C-b move to Bcc
2837 C-c C-f C-w move to Fcc C-c C-f C-r move to Reply-To
2838 C-c C-f C-u move to Summary C-c C-f C-n move to Newsgroups
2839 C-c C-f C-k move to Keywords C-c C-f C-d move to Distribution
2840 C-c C-f C-o move to From (\"Originator\")
2841 C-c C-f C-f move to Followup-To
2842 C-c C-f C-m move to Mail-Followup-To
2843 C-c C-f C-e move to Expires
2844 C-c C-f C-i cycle through Importance values
2845 C-c C-f s change subject and append \"(was: <Old Subject>)\"
2846 C-c C-f x crossposting with FollowUp-To header and note in body
2847 C-c C-f t replace To: header with contents of Cc: or Bcc:
2848 C-c C-f a Insert X-No-Archive: header and a note in the body
2849 C-c C-t `message-insert-to' (add a To header to a news followup)
2850 C-c C-l `message-to-list-only' (removes all but list address in to/cc)
2851 C-c C-n `message-insert-newsgroups' (add a Newsgroup header to a news reply)
2852 C-c C-b `message-goto-body' (move to beginning of message text).
2853 C-c C-i `message-goto-signature' (move to the beginning of the signature).
2854 C-c C-w `message-insert-signature' (insert `message-signature-file' file).
2855 C-c C-y `message-yank-original' (insert current message, if any).
2856 C-c C-q `message-fill-yanked-message' (fill what was yanked).
2857 C-c C-e `message-elide-region' (elide the text between point and mark).
2858 C-c C-v `message-delete-not-region' (remove the text outside the region).
2859 C-c C-z `message-kill-to-signature' (kill the text up to the signature).
2860 C-c C-r `message-caesar-buffer-body' (rot13 the message body).
2861 C-c C-a `mml-attach-file' (attach a file as MIME).
2862 C-c C-u `message-insert-or-toggle-importance' (insert or cycle importance).
2863 C-c M-n `message-insert-disposition-notification-to' (request receipt).
2864 C-c M-m `message-mark-inserted-region' (mark region with enclosing tags).
2865 C-c M-f `message-mark-insert-file' (insert file marked with enclosing tags).
2866 M-RET `message-newline-and-reformat' (break the line and reformat)."
2867 (setq local-abbrev-table text-mode-abbrev-table
)
2868 (set (make-local-variable 'message-reply-buffer
) nil
)
2869 (set (make-local-variable 'message-inserted-headers
) nil
)
2870 (set (make-local-variable 'message-send-actions
) nil
)
2871 (set (make-local-variable 'message-exit-actions
) nil
)
2872 (set (make-local-variable 'message-kill-actions
) nil
)
2873 (set (make-local-variable 'message-postpone-actions
) nil
)
2874 (set (make-local-variable 'message-draft-article
) nil
)
2875 (setq buffer-offer-save t
)
2876 (set (make-local-variable 'facemenu-add-face-function
)
2878 (let ((face-fun (cdr (assq face message-face-alist
))))
2880 (funcall face-fun
(point) end
)
2881 (error "Face %s not configured for %s mode" face mode-name
)))
2883 (set (make-local-variable 'facemenu-remove-face-function
) t
)
2884 (set (make-local-variable 'message-reply-headers
) nil
)
2885 (make-local-variable 'message-newsreader
)
2886 (make-local-variable 'message-mailer
)
2887 (make-local-variable 'message-post-method
)
2888 (set (make-local-variable 'message-sent-message-via
) nil
)
2889 (set (make-local-variable 'message-checksum
) nil
)
2890 (set (make-local-variable 'message-mime-part
) 0)
2891 (message-setup-fill-variables)
2892 (when message-fill-column
2893 (setq fill-column message-fill-column
)
2894 (turn-on-auto-fill))
2895 ;; Allow using comment commands to add/remove quoting.
2896 ;; (set (make-local-variable 'comment-start) message-yank-prefix)
2897 (when message-yank-prefix
2898 (set (make-local-variable 'comment-start
) message-yank-prefix
)
2899 (set (make-local-variable 'comment-start-skip
)
2900 (concat "^" (regexp-quote message-yank-prefix
) "[ \t]*")))
2901 (if (featurep 'xemacs
)
2902 (message-setup-toolbar)
2903 (set (make-local-variable 'font-lock-defaults
)
2904 '(message-font-lock-keywords t
))
2905 (if (boundp 'tool-bar-map
)
2906 (set (make-local-variable 'tool-bar-map
) (message-make-tool-bar))))
2907 (easy-menu-add message-mode-menu message-mode-map
)
2908 (easy-menu-add message-mode-field-menu message-mode-map
)
2909 (gnus-make-local-hook 'after-change-functions
)
2910 ;; Mmmm... Forbidden properties...
2911 (add-hook 'after-change-functions
'message-strip-forbidden-properties
2913 ;; Allow mail alias things.
2915 ((message-mail-alias-type-p 'abbrev
)
2916 (if (fboundp 'mail-abbrevs-setup
)
2917 (mail-abbrevs-setup)
2918 (if (fboundp 'mail-aliases-setup
) ; warning avoidance
2919 (mail-aliases-setup))))
2920 ((message-mail-alias-type-p 'ecomplete
)
2922 (unless buffer-file-name
2923 (message-set-auto-save-file-name))
2924 (unless (buffer-base-buffer)
2925 ;; Don't enable multibyte on an indirect buffer. Maybe enabling
2926 ;; multibyte is not necessary at all. -- zsh
2927 (mm-enable-multibyte))
2928 (set (make-local-variable 'indent-tabs-mode
) nil
) ;No tabs for indentation.
2931 (defun message-setup-fill-variables ()
2932 "Setup message fill variables."
2933 (set (make-local-variable 'fill-paragraph-function
)
2934 'message-fill-paragraph
)
2935 (make-local-variable 'paragraph-separate
)
2936 (make-local-variable 'paragraph-start
)
2937 (make-local-variable 'adaptive-fill-regexp
)
2938 (unless (boundp 'adaptive-fill-first-line-regexp
)
2939 (setq adaptive-fill-first-line-regexp nil
))
2940 (make-local-variable 'adaptive-fill-first-line-regexp
)
2941 (let ((quote-prefix-regexp
2942 ;; User should change message-cite-prefix-regexp if
2943 ;; message-yank-prefix is set to an abnormal value.
2944 (concat "\\(" message-cite-prefix-regexp
"\\)[ \t]*")))
2945 (setq paragraph-start
2947 (regexp-quote mail-header-separator
) "$\\|"
2948 "[ \t]*$\\|" ; blank lines
2949 "-- $\\|" ; signature delimiter
2950 "---+$\\|" ; delimiters for forwarded messages
2951 page-delimiter
"$\\|" ; spoiler warnings
2952 ".*wrote:$\\|" ; attribution lines
2953 quote-prefix-regexp
"$\\|" ; empty lines in quoted text
2955 "<#!*/?\\(multipart\\|part\\|external\\|mml\\|secure\\)"))
2956 (setq paragraph-separate paragraph-start
)
2957 (setq adaptive-fill-regexp
2958 (concat quote-prefix-regexp
"\\|" adaptive-fill-regexp
))
2959 (setq adaptive-fill-first-line-regexp
2960 (concat quote-prefix-regexp
"\\|"
2961 adaptive-fill-first-line-regexp
)))
2962 (make-local-variable 'auto-fill-inhibit-regexp
)
2963 ;;(setq auto-fill-inhibit-regexp "^[A-Z][^: \n\t]+:")
2964 (setq auto-fill-inhibit-regexp nil
)
2965 (make-local-variable 'normal-auto-fill-function
)
2966 (setq normal-auto-fill-function
'message-do-auto-fill
)
2967 ;; KLUDGE: auto fill might already be turned on in `text-mode-hook'.
2968 ;; In that case, ensure that it uses the right function. The real
2969 ;; solution would be not to use `define-derived-mode', and run
2970 ;; `text-mode-hook' ourself at the end of the mode.
2971 ;; -- Per Abrahamsen <abraham@dina.kvl.dk> Date: 2001-10-19.
2972 ;; This kludge is unneeded in Emacs>=21 since define-derived-mode is
2973 ;; now careful to run parent hooks after the body. --Stef
2974 (when auto-fill-function
2975 (setq auto-fill-function normal-auto-fill-function
)))
2980 ;;; Message mode commands
2983 ;;; Movement commands
2985 (defun message-goto-to ()
2986 "Move point to the To header."
2988 (message-position-on-field "To"))
2990 (defun message-goto-from ()
2991 "Move point to the From header."
2993 (message-position-on-field "From"))
2995 (defun message-goto-subject ()
2996 "Move point to the Subject header."
2998 (message-position-on-field "Subject"))
3000 (defun message-goto-cc ()
3001 "Move point to the Cc header."
3003 (message-position-on-field "Cc" "To"))
3005 (defun message-goto-bcc ()
3006 "Move point to the Bcc header."
3008 (message-position-on-field "Bcc" "Cc" "To"))
3010 (defun message-goto-fcc ()
3011 "Move point to the Fcc header."
3013 (message-position-on-field "Fcc" "To" "Newsgroups"))
3015 (defun message-goto-reply-to ()
3016 "Move point to the Reply-To header."
3018 (message-position-on-field "Reply-To" "Subject"))
3020 (defun message-goto-newsgroups ()
3021 "Move point to the Newsgroups header."
3023 (message-position-on-field "Newsgroups"))
3025 (defun message-goto-distribution ()
3026 "Move point to the Distribution header."
3028 (message-position-on-field "Distribution"))
3030 (defun message-goto-followup-to ()
3031 "Move point to the Followup-To header."
3033 (message-position-on-field "Followup-To" "Newsgroups"))
3035 (defun message-goto-mail-followup-to ()
3036 "Move point to the Mail-Followup-To header."
3038 (message-position-on-field "Mail-Followup-To" "To"))
3040 (defun message-goto-keywords ()
3041 "Move point to the Keywords header."
3043 (message-position-on-field "Keywords" "Subject"))
3045 (defun message-goto-summary ()
3046 "Move point to the Summary header."
3048 (message-position-on-field "Summary" "Subject"))
3050 (defun message-goto-body (&optional interactivep
)
3051 "Move point to the beginning of the message body."
3052 (interactive (list t
))
3053 (when (and interactivep
3054 (looking-at "[ \t]*\n"))
3056 (goto-char (point-min))
3057 (or (search-forward (concat "\n" mail-header-separator
"\n") nil t
)
3058 (search-forward-regexp "[^:]+:\\([^\n]\\|\n[ \t]\\)+\n\n" nil t
)))
3060 (defun message-in-body-p ()
3061 "Return t if point is in the message body."
3062 (let ((body (save-excursion (message-goto-body) (point))))
3065 (defun message-goto-eoh ()
3066 "Move point to the end of the headers."
3071 (defun message-goto-signature ()
3072 "Move point to the beginning of the message signature.
3073 If there is no signature in the article, go to the end and
3076 (goto-char (point-min))
3077 (if (re-search-forward message-signature-separator nil t
)
3079 (goto-char (point-max))
3082 (defun message-generate-unsubscribed-mail-followup-to (&optional include-cc
)
3083 "Insert a reasonable MFT header in a post to an unsubscribed list.
3084 When making original posts to a mailing list you are not subscribed to,
3085 you have to type in a MFT header by hand. The contents, usually, are
3086 the addresses of the list and your own address. This function inserts
3087 such a header automatically. It fetches the contents of the To: header
3088 in the current mail buffer, and appends the current `user-mail-address'.
3090 If the optional argument INCLUDE-CC is non-nil, the addresses in the
3091 Cc: header are also put into the MFT."
3096 (message-narrow-to-headers)
3097 (message-remove-header "Mail-Followup-To")
3098 (setq cc
(and include-cc
(message-fetch-field "Cc")))
3100 (concat (message-fetch-field "To") "," cc
)
3101 (message-fetch-field "To"))))
3102 (message-goto-mail-followup-to)
3103 (insert (concat tos
", " user-mail-address
))))
3107 (defun message-insert-to (&optional force
)
3108 "Insert a To header that points to the author of the article being replied to.
3109 If the original author requested not to be sent mail, don't insert unless the
3110 prefix FORCE is given."
3112 (let* ((mct (message-fetch-reply-field "mail-copies-to"))
3113 (dont (and mct
(or (equal (downcase mct
) "never")
3114 (equal (downcase mct
) "nobody"))))
3115 (to (or (message-fetch-reply-field "mail-reply-to")
3116 (message-fetch-reply-field "reply-to")
3117 (message-fetch-reply-field "from"))))
3121 "Ignoring the user request not to have copies sent via mail"
3122 "Complying with the user request not to have copies sent via mail")))
3123 (when (and force
(not to
))
3124 (error "No mail address in the article"))
3125 (when (and to
(or force
(not dont
)))
3126 (message-carefully-insert-headers (list (cons 'To to
))))))
3128 (defun message-insert-wide-reply ()
3129 "Insert To and Cc headers as if you were doing a wide reply."
3131 (let ((headers (message-with-reply-buffer
3132 (message-get-reply-headers t
))))
3133 (message-carefully-insert-headers headers
)))
3135 (defcustom message-header-synonyms
3138 "List of lists of header synonyms.
3139 E.g., if this list contains a member list with elements `Cc' and `To',
3140 then `message-carefully-insert-headers' will not insert a `To' header
3141 when the message is already `Cc'ed to the recipient."
3143 :group
'message-headers
3144 :link
'(custom-manual "(message)Message Headers")
3145 :type
'(repeat sexp
))
3147 (defun message-carefully-insert-headers (headers)
3148 "Insert the HEADERS, an alist, into the message buffer.
3149 Does not insert the headers when they are already present there
3150 or in the synonym headers, defined by `message-header-synonyms'."
3151 ;; FIXME: Should compare only the address and not the full name. Comparison
3152 ;; should be done case-folded (and with `string=' rather than
3154 ;; (mail-strip-quoted-names "Foo Bar <foo@bar>, bla@fasel (Bla Fasel)")
3155 (dolist (header headers
)
3156 (let* ((header-name (symbol-name (car header
)))
3157 (new-header (cdr header
))
3158 (synonyms (loop for synonym in message-header-synonyms
3159 when
(memq (car header
) synonym
) return synonym
))
3161 (loop for synonym in synonyms
3162 for old-header
= (mail-fetch-field (symbol-name synonym
))
3163 when
(and old-header
(string-match new-header old-header
))
3166 (message "already have `%s' in `%s'" new-header old-header
)
3167 (when (and (message-position-on-field header-name
)
3168 (setq old-header
(mail-fetch-field header-name
))
3169 (not (string-match "\\` *\\'" old-header
)))
3171 (insert new-header
)))))
3173 (defun message-widen-reply ()
3174 "Widen the reply to include maximum recipients."
3177 (and (bufferp message-reply-buffer
)
3178 (buffer-name message-reply-buffer
)
3179 (with-current-buffer message-reply-buffer
3180 (message-get-reply-headers t
)))))
3183 (message-narrow-to-headers)
3184 (dolist (elem follow-to
)
3185 (message-remove-header (symbol-name (car elem
)))
3186 (goto-char (point-min))
3187 (insert (symbol-name (car elem
)) ": "
3188 (cdr elem
) "\n"))))))
3190 (defun message-insert-newsgroups ()
3191 "Insert the Newsgroups header from the article being replied to."
3193 (when (and (message-position-on-field "Newsgroups")
3194 (mail-fetch-field "newsgroups")
3195 (not (string-match "\\` *\\'" (mail-fetch-field "newsgroups"))))
3197 (insert (or (message-fetch-reply-field "newsgroups") "")))
3201 ;;; Various commands
3203 (defun message-delete-not-region (beg end
)
3204 "Delete everything in the body of the current message outside of the region."
3209 ;; snarf citation prefix, if appropriate
3210 (unless (eq (point) (progn (beginning-of-line) (point)))
3211 (when (looking-at message-cite-prefix-regexp
)
3212 (setq citeprefix
(match-string 0))))
3214 (delete-region (point) (if (not (message-goto-signature))
3220 (delete-region beg
(progn (message-goto-body)
3224 (insert citeprefix
))))
3225 (when (message-goto-signature)
3228 (defun message-kill-to-signature (&optional arg
)
3229 "Kill all text up to the signature.
3230 If a numeric argument or prefix arg is given, leave that number
3231 of lines before the signature intact."
3235 (let ((point (point)))
3236 (narrow-to-region point
(point-max))
3237 (message-goto-signature)
3239 (if (and arg
(numberp arg
))
3240 (forward-line (- -
1 arg
))
3242 (unless (= point
(point))
3243 (kill-region point
(point))
3247 (defun message-newline-and-reformat (&optional arg not-break
)
3248 "Insert four newlines, and then reformat if inside quoted text.
3249 Prefix arg means justify as well."
3250 (interactive (list (if current-prefix-arg
'full
)))
3251 (let (quoted point beg end leading-space bolp fill-paragraph-function
)
3252 (setq point
(point))
3255 (setq bolp
(= beg point
))
3256 ;; Find first line of the paragraph.
3258 (while (and (not (eobp))
3259 (not (looking-at message-cite-prefix-regexp
))
3260 (looking-at paragraph-start
))
3263 (when (looking-at message-cite-prefix-regexp
)
3264 (setq quoted
(match-string 0))
3265 (goto-char (match-end 0))
3266 (looking-at "[ \t]*")
3267 (setq leading-space
(match-string 0)))
3271 (< (- point beg
) (length quoted
)))
3272 ;; break inside the cite prefix.
3278 (while (and (not (eobp))
3279 (not (looking-at paragraph-separate
))
3280 (looking-at message-cite-prefix-regexp
)
3281 (equal quoted
(match-string 0)))
3282 (goto-char (match-end 0))
3283 (looking-at "[ \t]*")
3284 (if (> (length leading-space
) (length (match-string 0)))
3285 (setq leading-space
(match-string 0)))
3289 (while (and (if (bobp) nil
(forward-line -
1) t
)
3290 (not (looking-at paragraph-start
))
3291 (looking-at message-cite-prefix-regexp
)
3292 (equal quoted
(match-string 0)))
3294 (goto-char (match-end 0))
3295 (looking-at "[ \t]*")
3296 (if (> (length leading-space
) (length (match-string 0)))
3297 (setq leading-space
(match-string 0)))))
3298 (while (and (not (eobp))
3299 (not (looking-at paragraph-separate
))
3300 (not (looking-at message-cite-prefix-regexp
)))
3304 (while (and (if (bobp) nil
(forward-line -
1) t
)
3305 (not (looking-at paragraph-start
))
3306 (not (looking-at message-cite-prefix-regexp
)))
3307 (setq beg
(point))))
3310 (narrow-to-region beg end
)
3317 (setq point
(point))
3318 ;; (newline 2) doesn't mark both newline's as hard, so call
3319 ;; newline twice. -jas
3322 (delete-region (point) (re-search-forward "[ \t]*"))
3323 (when (and quoted
(not bolp
))
3324 (insert quoted leading-space
)))
3327 (let* ((adaptive-fill-regexp
3328 (regexp-quote (concat quoted leading-space
)))
3329 (adaptive-fill-first-line-regexp
3330 adaptive-fill-regexp
))
3331 (fill-paragraph arg
))
3332 (fill-paragraph arg
))
3333 (if point
(goto-char point
)))))
3335 (defun message-fill-paragraph (&optional arg
)
3336 "Message specific function to fill a paragraph.
3337 This function is used as the value of `fill-paragraph-function' in
3338 Message buffers and is not meant to be called directly."
3339 (interactive (list (if current-prefix-arg
'full
)))
3340 (if (if (boundp 'filladapt-mode
) filladapt-mode
)
3342 (if (message-point-in-header-p)
3343 (message-fill-field)
3344 (message-newline-and-reformat arg t
))
3347 (defun message-point-in-header-p ()
3348 "Return t if point is in the header."
3350 (not (re-search-backward
3351 (concat "^" (regexp-quote mail-header-separator
) "\n") nil t
))))
3353 (defun message-do-auto-fill ()
3354 "Like `do-auto-fill', but don't fill in message header."
3355 (unless (message-point-in-header-p)
3358 (defun message-insert-signature (&optional force
)
3359 "Insert a signature. See documentation for variable `message-signature'."
3360 (interactive (list 0))
3363 ((and (null message-signature
)
3366 (goto-char (point-max))
3367 (not (re-search-backward message-signature-separator nil t
))))
3368 ((and (null message-signature
)
3371 ((functionp message-signature
)
3372 (funcall message-signature
))
3373 ((listp message-signature
)
3374 (eval message-signature
))
3375 (t message-signature
)))
3378 (cond ((stringp signature
)
3380 ((and (eq t signature
) message-signature-file
)
3381 (setq signature-file
3382 (if (and message-signature-directory
3383 ;; don't actually use the signature directory
3384 ;; if message-signature-file contains a path.
3385 (not (file-name-directory
3386 message-signature-file
)))
3387 (expand-file-name message-signature-file
3388 message-signature-directory
)
3389 message-signature-file
))
3390 (file-exists-p signature-file
))))
3392 (goto-char (point-max))
3393 ;; Insert the signature.
3396 (when message-signature-insert-empty-line
3399 (if (eq signature t
)
3400 (insert-file-contents signature-file
)
3402 (goto-char (point-max))
3403 (or (bolp) (insert "\n")))))
3405 (defun message-insert-importance-high ()
3406 "Insert header to mark message as important."
3410 (message-narrow-to-headers)
3411 (message-remove-header "Importance"))
3413 (insert "Importance: high\n")))
3415 (defun message-insert-importance-low ()
3416 "Insert header to mark message as unimportant."
3420 (message-narrow-to-headers)
3421 (message-remove-header "Importance"))
3423 (insert "Importance: low\n")))
3425 (defun message-insert-or-toggle-importance ()
3426 "Insert a \"Importance: high\" header, or cycle through the header values.
3427 The three allowed values according to RFC 1327 are `high', `normal'
3434 (message-narrow-to-headers)
3435 (when (setq cur
(message-fetch-field "Importance"))
3436 (message-remove-header "Importance")
3437 (setq new
(cond ((string= cur
"high")
3439 ((string= cur
"low")
3444 (insert (format "Importance: %s\n" new
)))))
3446 (defun message-insert-disposition-notification-to ()
3447 "Request a disposition notification (return receipt) to this message.
3448 Note that this should not be used in newsgroups."
3452 (message-narrow-to-headers)
3453 (message-remove-header "Disposition-Notification-To"))
3455 (insert (format "Disposition-Notification-To: %s\n"
3456 (or (message-field-value "Reply-to")
3457 (message-field-value "From")
3458 (message-make-from))))))
3460 (defun message-elide-region (b e
)
3461 "Elide the text in the region.
3462 An ellipsis (from `message-elide-ellipsis') will be inserted where the
3466 (insert message-elide-ellipsis
))
3468 (defvar message-caesar-translation-table nil
)
3470 (defun message-caesar-region (b e
&optional n
)
3471 "Caesar rotate region B to E by N, default 13, for decrypting netnews."
3474 (min (point) (or (mark t
) (point)))
3475 (max (point) (or (mark t
) (point)))
3476 (when current-prefix-arg
3477 (prefix-numeric-value current-prefix-arg
))))
3479 (setq n
(if (numberp n
) (mod n
26) 13)) ;canonize N
3480 (unless (or (zerop n
) ; no action needed for a rot of 0
3481 (= b e
)) ; no region to rotate
3482 ;; We build the table, if necessary.
3483 (when (or (not message-caesar-translation-table
)
3484 (/= (aref message-caesar-translation-table ?a
) (+ ?a n
)))
3485 (setq message-caesar-translation-table
3486 (message-make-caesar-translation-table n
)))
3487 (translate-region b e message-caesar-translation-table
)))
3489 (defun message-make-caesar-translation-table (n)
3490 "Create a rot table with offset N."
3492 (table (make-string 256 0)))
3493 (while (< (incf i
) 256)
3496 (substring table
0 ?A
)
3497 (substring table
(+ ?A n
) (+ ?A n
(- 26 n
)))
3498 (substring table ?A
(+ ?A n
))
3499 (substring table
(+ ?A
26) ?a
)
3500 (substring table
(+ ?a n
) (+ ?a n
(- 26 n
)))
3501 (substring table ?a
(+ ?a n
))
3502 (substring table
(+ ?a
26) 255))))
3504 (defun message-caesar-buffer-body (&optional rotnum wide
)
3505 "Caesar rotate all letters in the current buffer by 13 places.
3506 Used to encode/decode possibly offensive messages (commonly in rec.humor).
3507 With prefix arg, specifies the number of places to rotate each letter forward.
3508 Mail and USENET news headers are not rotated unless WIDE is non-nil."
3509 (interactive (if current-prefix-arg
3510 (list (prefix-numeric-value current-prefix-arg
))
3514 (when (and (not wide
) (message-goto-body))
3515 (narrow-to-region (point) (point-max)))
3516 (message-caesar-region (point-min) (point-max) rotnum
))))
3518 (defun message-pipe-buffer-body (program)
3519 "Pipe the message body in the current buffer through PROGRAM."
3522 (when (message-goto-body)
3523 (narrow-to-region (point) (point-max)))
3524 (shell-command-on-region
3525 (point-min) (point-max) program nil t
))))
3527 (defun message-rename-buffer (&optional enter-string
)
3528 "Rename the *message* buffer to \"*message* RECIPIENT\".
3529 If the function is run with a prefix, it will ask for a new buffer
3530 name, rather than giving an automatic name."
3531 (interactive "Pbuffer name: ")
3534 (goto-char (point-min))
3535 (narrow-to-region (point)
3536 (search-forward mail-header-separator nil
'end
))
3538 (if (message-news-p) (message-fetch-field "Newsgroups")
3539 (message-fetch-field "To"))
3542 (if (string-match "," mail-to
)
3543 (concat (substring mail-to
0 (match-beginning 0)) ", ...")
3545 (name-default (concat "*message* " mail-trimmed-to
))
3546 (name (if enter-string
3547 (read-string "New buffer name: " name-default
)
3549 (rename-buffer name t
)))))
3551 (defun message-fill-yanked-message (&optional justifyp
)
3552 "Fill the paragraphs of a message yanked into this one.
3553 Numeric argument means justify as well."
3556 (goto-char (point-min))
3557 (search-forward (concat "\n" mail-header-separator
"\n") nil t
)
3558 (let ((fill-prefix message-yank-prefix
))
3559 (fill-individual-paragraphs (point) (point-max) justifyp
))))
3561 (defun message-indent-citation (&optional start end yank-only
)
3562 "Modify text just inserted from a message to be cited.
3563 The inserted text should be the region.
3564 When this function returns, the region is again around the modified text.
3566 Normally, indent each nonblank line `message-indentation-spaces' spaces.
3567 However, if `message-yank-prefix' is non-nil, insert that prefix on each line."
3568 (unless start
(setq start
(point)))
3570 ;; Remove unwanted headers.
3571 (when message-ignored-cited-headers
3576 (if (search-forward "\n\n" nil t
)
3579 (message-remove-header message-ignored-cited-headers t
)
3580 (when (= (point-min) (point-max))
3581 (setq all-removed t
))
3582 (goto-char (point-max)))
3586 ;; Delete blank lines at the start of the buffer.
3587 (while (and (point-min)
3590 (message-delete-line))
3591 ;; Delete blank lines at the end of the buffer.
3592 (goto-char (point-max))
3595 (while (and (zerop (forward-line -
1))
3597 (message-delete-line)))
3598 ;; Do the indentation.
3599 (if (null message-yank-prefix
)
3600 (indent-rigidly start
(or end
(mark t
)) message-indentation-spaces
)
3603 (while (< (point) (or end
(mark t
)))
3604 (cond ((looking-at ">")
3605 (insert message-yank-cited-prefix
))
3607 (insert message-yank-empty-prefix
))
3609 (insert message-yank-prefix
)))
3613 (defun message-remove-blank-cited-lines (&optional remove
)
3614 "Remove cited lines containing only blanks.
3615 If REMOVE is non-nil, remove newlines, too.
3617 To use this automatically, you may add this function to
3618 `gnus-message-setup-hook'."
3623 (when (boundp 'message-yank-cited-prefix
)
3624 (concat message-yank-cited-prefix
"\\|"))
3628 (gnus-message 8 "removing `%s'" citexp
)
3631 (while (re-search-forward citexp nil t
)
3632 (replace-match (if remove
"" "\n"))))))
3634 (defvar message-cite-reply-above nil
3635 "If non-nil, start own text above the quote.
3637 Note: Top posting is bad netiquette. Don't use it unless you
3638 really must. You probably want to set variable only for specific
3639 groups, e.g. using `gnus-posting-styles':
3641 (eval (set (make-local-variable 'message-cite-reply-above) t))
3643 This variable has no effect in news postings.")
3645 (defun message-yank-original (&optional arg
)
3646 "Insert the message being replied to, if any.
3647 Puts point before the text and mark after.
3648 Normally indents each nonblank line ARG spaces (default 3). However,
3649 if `message-yank-prefix' is non-nil, insert that prefix on each line.
3651 This function uses `message-cite-function' to do the actual citing.
3653 Just \\[universal-argument] as argument means don't indent, insert no
3654 prefix, and don't delete any headers."
3656 (let ((modified (buffer-modified-p))
3658 (when (and message-reply-buffer
3659 message-cite-function
)
3660 (when message-cite-reply-above
3661 (if (and (not (message-news-p))
3662 (or (eq message-cite-reply-above
'is-evil
)
3664 Top posting is bad netiquette. Please don't top post unless you really must.
3665 Really top post? ")))
3668 (buffer-substring (message-goto-body)
3670 (delete-region (message-goto-body) (point-max)))
3671 (set (make-local-variable 'message-cite-reply-above
) nil
)))
3672 (if (bufferp message-reply-buffer
)
3673 (delete-windows-on message-reply-buffer t
))
3674 (push-mark (save-excursion
3676 ((bufferp message-reply-buffer
)
3677 (insert-buffer-substring message-reply-buffer
))
3678 ((and (consp message-reply-buffer
)
3679 (functionp (car message-reply-buffer
)))
3680 (apply (car message-reply-buffer
)
3681 (cdr message-reply-buffer
))))
3686 (funcall message-cite-function
)
3687 (unless (eq (char-before (mark t
)) ?
\n)
3689 (goto-char (mark t
))
3690 (insert-before-markers ?
\n)
3692 (when message-cite-reply-above
3695 (insert (if (bolp) "\n" "\n\n"))
3696 (message-goto-body))
3697 ;; Add a `message-setup-very-last-hook' here?
3698 ;; Add `gnus-article-highlight-citation' here?
3700 (setq message-checksum
(message-checksum))))))
3702 (defun message-yank-buffer (buffer)
3703 "Insert BUFFER into the current buffer and quote it."
3704 (interactive "bYank buffer: ")
3705 (let ((message-reply-buffer (get-buffer buffer
)))
3706 (save-window-excursion
3707 (message-yank-original))))
3709 (defun message-buffers ()
3710 "Return a list of active message buffers."
3712 (save-current-buffer
3713 (dolist (buffer (buffer-list t
))
3715 (when (and (eq major-mode
'message-mode
)
3716 (null message-sent-message-via
))
3717 (push (buffer-name buffer
) buffers
))))
3718 (nreverse buffers
)))
3720 (defun message-cite-original-1 (strip-signature)
3721 "Cite an original message.
3722 If STRIP-SIGNATURE is non-nil, strips off the signature from the
3725 This function uses `mail-citation-hook' if that is non-nil."
3726 (if (and (boundp 'mail-citation-hook
)
3728 (run-hooks 'mail-citation-hook
)
3729 (let* ((start (point))
3733 (when message-indent-citation-function
3734 (if (listp message-indent-citation-function
)
3735 message-indent-citation-function
3736 (list message-indent-citation-function
))))
3737 ;; This function may be called by `gnus-summary-yank-message' and
3738 ;; may insert a different article from the original. So, we will
3739 ;; modify the value of `message-reply-headers' with that article.
3740 (message-reply-headers
3742 (narrow-to-region start end
)
3743 (message-narrow-to-head-1)
3744 (setq x-no-archive
(message-fetch-field "x-no-archive"))
3746 (or (message-fetch-field "subject") "none")
3747 (or (message-fetch-field "from") "nobody")
3748 (message-fetch-field "date")
3749 (message-fetch-field "message-id" t
)
3750 (message-fetch-field "references")
3752 (mml-quote-region start end
)
3753 (when strip-signature
3757 (when (re-search-backward message-signature-separator start t
)
3758 ;; Also peel off any blank lines before the signature.
3760 (while (looking-at "^[ \t]*$")
3763 (delete-region (point) end
)
3764 (unless (search-backward "\n\n" start t
)
3765 ;; Insert a blank line if it is peeled off.
3768 (mapc 'funcall functions
)
3769 (when message-citation-line-function
3772 (funcall message-citation-line-function
))
3773 (when (and x-no-archive
3774 (not message-cite-articles-with-x-no-archive
)
3775 (string-match "yes" x-no-archive
))
3777 (delete-region (point) (mark t
))
3778 (insert "> [Quoted text removed due to X-No-Archive]\n")
3780 (forward-line -
1)))))
3782 (defun message-cite-original ()
3783 "Cite function in the standard Message manner."
3784 (message-cite-original-1 nil
))
3786 (defvar gnus-extract-address-components
)
3788 (autoload 'format-spec
"format-spec")
3790 (defun message-insert-formatted-citation-line (&optional from date
)
3791 "Function that inserts a formatted citation line.
3793 See `message-citation-line-format'."
3794 ;; The optional args are for testing/debugging. They will disappear later.
3796 ;; (with-temp-buffer
3797 ;; (message-insert-formatted-citation-line
3798 ;; "John Doe <john.doe@example.invalid>"
3801 (when (or message-reply-headers
(and from date
))
3803 (setq from
(mail-header-from message-reply-headers
)))
3804 (let* ((data (condition-case ()
3805 (funcall (if (boundp gnus-extract-address-components
)
3806 gnus-extract-address-components
3807 'mail-extract-address-components
)
3813 (net (car (cdr data
)))
3814 (name-or-net (or (car data
)
3815 (car (cdr data
)) from
))
3819 ;; We need Gnus functionality if the user wants date or time from
3820 ;; the original article:
3821 (when (string-match "%[^fnNFL]" message-citation-line-format
)
3822 (autoload 'gnus-date-get-time
"gnus-util")
3823 (gnus-date-get-time (mail-header-date message-reply-headers
)))))
3826 (when (stringp name
)
3827 ;; Guess first name and last name:
3828 (cond ((string-match
3829 "\\`\\(\\w\\|[-.]\\)+ \\(\\w\\|[-.]\\)+\\'" name
)
3830 (setq fname
(nth 0 (split-string name
"[ \t]+"))
3831 lname
(nth 1 (split-string name
"[ \t]+"))))
3833 "\\`\\(\\w\\|[-.]\\)+, \\(\\w\\|[-.]\\)+\\'" name
)
3834 (setq fname
(nth 1 (split-string name
"[ \t,]+"))
3835 lname
(nth 0 (split-string name
"[ \t,]+"))))
3837 "\\`\\(\\w\\|[-.]\\)+\\'" name
)
3840 ;; The following letters are not used in `format-time-string':
3841 (push ?E lst
) (push "<E>" lst
)
3842 (push ?F lst
) (push fname lst
)
3843 ;; We might want to use "" instead of "<X>" later.
3844 (push ?J lst
) (push "<J>" lst
)
3845 (push ?K lst
) (push "<K>" lst
)
3846 (push ?L lst
) (push lname lst
)
3847 (push ?N lst
) (push name-or-net lst
)
3848 (push ?O lst
) (push "<O>" lst
)
3849 (push ?P lst
) (push "<P>" lst
)
3850 (push ?Q lst
) (push "<Q>" lst
)
3851 (push ?f lst
) (push from lst
)
3852 (push ?i lst
) (push "<i>" lst
)
3853 (push ?n lst
) (push net lst
)
3854 (push ?o lst
) (push "<o>" lst
)
3855 (push ?q lst
) (push "<q>" lst
)
3856 (push ?t lst
) (push "<t>" lst
)
3857 (push ?v lst
) (push "<v>" lst
)
3858 ;; Delegate the rest to `format-time-string':
3860 (when (and (not (memq i lst
))
3865 (push (condition-case nil
3866 (format-time-string (format "%%%c" i
) replydate
)
3867 (error (format ">%c<" i
)))
3871 (spec (apply 'format-spec-make flist
)))
3872 (insert (format-spec message-citation-line-format spec
)))
3875 (defun message-cite-original-without-signature ()
3876 "Cite function in the standard Message manner.
3877 This function strips off the signature from the original message."
3878 (message-cite-original-1 t
))
3880 (defun message-insert-citation-line ()
3881 "Insert a simple citation line."
3882 (when message-reply-headers
3883 (insert (mail-header-from message-reply-headers
) " writes:")
3887 (defun message-position-on-field (header &rest afters
)
3888 (let ((case-fold-search t
))
3891 (goto-char (point-min))
3894 (concat "^" (regexp-quote mail-header-separator
) "$"))
3895 (match-beginning 0)))
3896 (goto-char (point-min))
3897 (if (re-search-forward (concat "^" (regexp-quote header
) ":") nil t
)
3899 (re-search-forward "^[^ \t]" nil
'move
)
3901 (skip-chars-backward "\n")
3904 (not (re-search-forward
3905 (concat "^" (regexp-quote (car afters
)) ":")
3909 (re-search-forward "^[^ \t]" nil
'move
)
3910 (beginning-of-line))
3911 (insert header
": \n")
3915 (defun message-remove-signature ()
3916 "Remove the signature from the text between point and mark.
3917 The text will also be indented the normal way."
3919 (let ((start (point))
3921 (if (not (re-search-forward message-signature-separator
(mark t
) t
))
3922 ;; No signature here, so we just indent the cited text.
3923 (message-indent-citation)
3924 ;; Find the last non-empty line.
3926 (while (looking-at "[ \t]*$")
3929 (setq mark
(set-marker (make-marker) (point)))
3931 (message-indent-citation)
3932 ;; Enable undoing the deletion.
3934 (delete-region mark
(mark t
))
3935 (set-marker mark nil
)))))
3940 ;;; Sending messages
3943 (defun message-send-and-exit (&optional arg
)
3944 "Send message like `message-send', then, if no errors, exit from mail buffer."
3946 (let ((buf (current-buffer))
3947 (actions message-exit-actions
))
3948 (when (and (message-send arg
)
3950 (if message-kill-buffer-on-exit
3953 (when (eq buf
(current-buffer))
3954 (message-bury buf
)))
3955 (message-do-actions actions
)
3958 (defun message-dont-send ()
3959 "Don't send the message you have been editing.
3960 Instead, just auto-save the buffer and then bury it."
3962 (set-buffer-modified-p t
)
3964 (let ((actions message-postpone-actions
))
3965 (message-bury (current-buffer))
3966 (message-do-actions actions
)))
3968 (defun message-kill-buffer ()
3969 "Kill the current buffer."
3971 (when (or (not (buffer-modified-p))
3972 (not message-kill-buffer-query
)
3973 (yes-or-no-p "Message modified; kill anyway? "))
3974 (let ((actions message-kill-actions
)
3975 (draft-article message-draft-article
)
3976 (auto-save-file-name buffer-auto-save-file-name
)
3977 (file-name buffer-file-name
)
3978 (modified (buffer-modified-p)))
3979 (setq buffer-file-name nil
)
3980 (kill-buffer (current-buffer))
3981 (when (and (or (and auto-save-file-name
3982 (file-exists-p auto-save-file-name
))
3984 (file-exists-p file-name
)))
3986 ;; If the message buffer has lived in a dedicated window,
3987 ;; `kill-buffer' has killed the frame. Thus the
3988 ;; `yes-or-no-p' may show up in a lowered frame. Make sure
3989 ;; that the user can see the question by raising the
3992 (yes-or-no-p (format "Remove the backup file%s? "
3993 (if modified
" too" "")))))
3995 (delete-file auto-save-file-name
))
3996 (let ((message-draft-article draft-article
))
3997 (message-disassociate-draft)))
3998 (message-do-actions actions
))))
4000 (defun message-bury (buffer)
4001 "Bury this mail BUFFER."
4002 (let ((newbuf (other-buffer buffer
)))
4003 (bury-buffer buffer
)
4004 (if (and (window-dedicated-p (selected-window))
4005 (not (null (delq (selected-frame) (visible-frame-list)))))
4006 (delete-frame (selected-frame))
4007 (switch-to-buffer newbuf
))))
4009 (defun message-send (&optional arg
)
4010 "Send the message in the current buffer.
4011 If `message-interactive' is non-nil, wait for success indication or
4012 error messages, and inform user.
4013 Otherwise any failure is reported in a message back to the user from
4015 The usage of ARG is defined by the instance that called Message.
4016 It should typically alter the sending method in some way or other."
4018 ;; Make it possible to undo the coming changes.
4020 (let ((inhibit-read-only t
))
4021 (put-text-property (point-min) (point-max) 'read-only nil
))
4022 (message-fix-before-sending)
4023 (run-hooks 'message-send-hook
)
4024 (when message-confirm-send
4025 (or (y-or-n-p "Send message? ")
4027 (message message-sending-message
)
4028 (let ((alist message-send-method-alist
)
4030 elem sent dont-barf-on-no-method
4031 (message-options message-options
))
4032 (message-options-set-recipient)
4034 (setq elem
(pop alist
)))
4035 (when (funcall (cadr elem
))
4036 (when (and (or (not (memq (car elem
)
4037 message-sent-message-via
))
4038 (message-fetch-field "supersedes")
4039 (if (or (message-gnksa-enable-p 'multiple-copies
)
4040 (not (eq (car elem
) 'news
)))
4043 "Already sent message via %s; resend? "
4045 (error "Denied posting -- multiple copies")))
4046 (setq success
(funcall (caddr elem
) arg
)))
4050 (let ((fcc (message-fetch-field "Fcc"))
4051 (gcc (message-fetch-field "Gcc")))
4053 (or (eq message-allow-no-recipients
'always
)
4054 (and (not (eq message-allow-no-recipients
'never
))
4055 (setq dont-barf-on-no-method
4057 (format "No receiver, perform %s anyway? "
4058 (cond ((and fcc gcc
) "Fcc and Gcc")
4061 (error "No methods specified to send by"))
4062 (when (or dont-barf-on-no-method
4066 (run-hooks 'message-sent-hook
))
4067 (message "Sending...done")
4068 ;; Do ecomplete address snarfing.
4069 (when (and (message-mail-alias-type-p 'ecomplete
)
4070 (not message-inhibit-ecomplete
))
4071 (message-put-addresses-in-ecomplete))
4072 ;; Mark the buffer as unmodified and delete auto-save.
4073 (set-buffer-modified-p nil
)
4074 (delete-auto-save-file-if-necessary t
)
4075 (message-disassociate-draft)
4076 ;; Delete other mail buffers and stuff.
4077 (message-do-send-housekeeping)
4078 (message-do-actions message-send-actions
)
4082 (defun message-send-via-mail (arg)
4083 "Send the current message via mail."
4084 (message-send-mail arg
))
4086 (defun message-send-via-news (arg)
4087 "Send the current message via news."
4088 (funcall message-send-news-function arg
))
4090 (defmacro message-check
(type &rest forms
)
4091 "Eval FORMS if TYPE is to be checked."
4092 `(or (message-check-element ,type
)
4096 (put 'message-check
'lisp-indent-function
1)
4097 (put 'message-check
'edebug-form-spec
'(form body
))
4099 (defun message-text-with-property (prop &optional start end reverse
)
4100 "Return a list of start and end positions where the text has PROP.
4101 START and END bound the search, they default to `point-min' and
4102 `point-max' respectively. If REVERSE is non-nil, find text which does
4105 (setq start
(point-min)))
4107 (setq end
(point-max)))
4111 (setq start
(text-property-any start end prop nil
)))
4112 (setq next
(next-single-property-change start prop nil end
))
4113 (push (cons start
(or next end
)) regions
)
4116 (or (get-text-property start prop
)
4117 (and (setq start
(next-single-property-change
4118 start prop nil end
))
4119 (get-text-property start prop
))))
4120 (setq next
(text-property-any start end prop nil
))
4121 (push (cons start
(or next end
)) regions
)
4123 (nreverse regions
)))
4125 (defcustom message-bogus-addresses
4126 ;; '("noreply" "nospam" "invalid")
4127 '("noreply" "nospam" "invalid" "@@" "[^[:ascii:]].*@" "[ \t]")
4128 "List of regexps of potentially bogus mail addresses.
4129 See `message-check-recipients' how to setup checking.
4131 This list should make it possible to catch typos or warn about
4132 spam-trap addresses. It doesn't aim to verify strict RFC
4134 :version
"23.1" ;; No Gnus
4135 :group
'message-headers
4137 (const :tag
"None" nil
)
4143 (const :tag
"duplicate @" "@@")
4144 (const :tag
"non-ascii local part" "[^[:ascii:]].*@")
4145 ;; Already caught by `message-valid-fqdn-regexp'
4146 ;; (const :tag "`_' in domain part" "@.*_")
4147 (const :tag
"whitespace" "[ \t]"))
4152 (defun message-fix-before-sending ()
4153 "Do various things to make the message nice before sending it."
4154 ;; Make sure there's a newline at the end of the message.
4155 (goto-char (point-max))
4158 ;; Make the hidden headers visible.
4160 ;; Sort headers before sending the message.
4161 (message-sort-headers)
4162 ;; Make invisible text visible.
4163 ;; It doesn't seem as if this is useful, since the invisible property
4164 ;; is clobbered by an after-change hook anyhow.
4165 (message-check 'invisible-text
4166 (let ((regions (message-text-with-property 'invisible
))
4170 (setq from
(caar regions
)
4172 regions
(cdr regions
))
4173 (put-text-property from to
'invisible nil
)
4174 (message-overlay-put (message-make-overlay from to
)
4176 (unless (yes-or-no-p
4177 "Invisible text found and made visible; continue sending? ")
4178 (error "Invisible text found and made visible")))))
4179 (message-check 'illegible-text
4180 (let (char found choice
)
4183 (skip-chars-forward mm-7bit-chars
)
4184 (when (get-text-property (point) 'no-illegible-text
)
4185 ;; There is a signed or encrypted raw message part
4186 ;; that is considered to be safe.
4187 (goto-char (or (next-single-property-change
4188 (point) 'no-illegible-text
)
4190 (setq char
(char-after)))
4191 (when (or (< (mm-char-int char
) 128)
4192 (and (mm-multibyte-p)
4193 (memq (char-charset char
)
4194 '(eight-bit-control eight-bit-graphic
4195 ;; Emacs 23, Bug#1770:
4198 (not (get-text-property
4199 (point) 'untranslated-utf-8
))))
4200 (message-overlay-put (message-make-overlay (point) (1+ (point)))
4206 (gnus-multiple-choice
4207 "Non-printable characters found. Continue sending?"
4208 `((?d
"Remove non-printable characters and send")
4210 "Replace non-printable characters with \"%s\" and send"
4211 message-replacement-char
))
4212 (?s
"Send as is without removing anything")
4213 (?e
"Continue editing"))))
4215 (error "Non-printable characters"))
4217 (skip-chars-forward mm-7bit-chars
)
4219 (when (let ((char (char-after)))
4220 (or (< (mm-char-int char
) 128)
4221 (and (mm-multibyte-p)
4222 ;; FIXME: Wrong for Emacs 23 (unicode) and for
4223 ;; things like undecodable utf-8 (in Emacs 21?).
4224 ;; Should at least use find-coding-systems-region.
4226 (memq (char-charset char
)
4227 '(eight-bit-control eight-bit-graphic
4228 ;; Emacs 23, Bug#1770:
4231 (not (get-text-property
4232 (point) 'untranslated-utf-8
)))))
4234 (message-kill-all-overlays)
4236 (when (eq choice ?r
)
4237 (insert message-replacement-char
))))
4239 (skip-chars-forward mm-7bit-chars
)))))
4240 (message-check 'bogus-recipient
4241 ;; Warn before sending a mail to an invalid address.
4242 (message-check-recipients)))
4244 (defun message-bogus-recipient-p (recipients)
4245 "Check if a mail address in RECIPIENTS looks bogus.
4247 RECIPIENTS is a mail header. Return a list of potentially bogus
4248 addresses. If none is found, return nil.
4250 An address might be bogus if the domain part is not fully
4251 qualified, see `message-valid-fqdn-regexp', or if there's a
4252 matching entry in `message-bogus-addresses'."
4253 ;; FIXME: How about "foo@subdomain", when the MTA adds ".domain.tld"?
4255 (mapc (lambda (address)
4256 (setq address
(cadr address
))
4260 (not (string-match "@" address
))
4263 message-valid-fqdn-regexp
"\\)\\'") address
)))
4264 (and message-bogus-addresses
4266 (if (listp message-bogus-addresses
)
4267 (mapconcat 'identity
4268 message-bogus-addresses
4270 message-bogus-addresses
)))
4271 (string-match re address
))))
4272 (push address found
)))
4274 (mail-extract-address-components recipients t
))
4277 (defun message-check-recipients ()
4278 "Warn before composing or sending a mail to an invalid address.
4280 This function could be useful in `message-setup-hook'."
4283 (message-narrow-to-headers)
4284 (dolist (hdr '("To" "Cc" "Bcc"))
4285 (let ((addr (message-fetch-field hdr
)))
4286 (when (stringp addr
)
4287 (dolist (bog (message-bogus-recipient-p addr
))
4291 "Address `%s' might be bogus. Continue? " bog
)))
4292 (error "Bogus address"))))))))
4294 (custom-add-option 'message-setup-hook
'message-check-recipients
)
4296 (defun message-add-action (action &rest types
)
4297 "Add ACTION to be performed when doing an exit of type TYPES."
4299 (add-to-list (intern (format "message-%s-actions" (pop types
)))
4302 (defun message-delete-action (action &rest types
)
4303 "Delete ACTION from lists of actions performed when doing an exit of type TYPES."
4306 (set (setq var
(intern (format "message-%s-actions" (pop types
))))
4307 (delq action
(symbol-value var
))))))
4309 (defun message-do-actions (actions)
4310 "Perform all actions in ACTIONS."
4311 ;; Now perform actions on successful sending.
4312 (dolist (action actions
)
4315 ;; A simple function.
4318 ;; Something to be evaled.
4322 (defun message-send-mail-partially ()
4323 "Send mail as message/partial."
4324 ;; replace the header delimiter with a blank line
4325 (goto-char (point-min))
4327 (concat "^" (regexp-quote mail-header-separator
) "\n"))
4328 (replace-match "\n")
4329 (run-hooks 'message-send-mail-hook
)
4330 (let ((p (goto-char (point-min)))
4331 (tembuf (message-generate-new-buffer-clone-locals " message temp"))
4332 (curbuf (current-buffer))
4333 (id (message-make-message-id)) (n 1)
4334 plist total header required-mail-headers
)
4336 (if (< (point-max) (+ p message-send-mail-partially-limit
))
4337 (goto-char (point-max))
4338 (goto-char (+ p message-send-mail-partially-limit
))
4340 (if (<= (point) p
) (forward-line 1))) ;; In case of bad message.
4343 (setq total
(length plist
))
4344 (push (point-max) plist
)
4345 (setq plist
(nreverse plist
))
4348 (setq p
(pop plist
))
4351 (copy-to-buffer tembuf p
(car plist
))
4353 (goto-char (point-min))
4356 (goto-char (point-min))
4357 (narrow-to-region (point) (point))
4360 (setq header
(buffer-substring (point-min) (point)))
4361 (goto-char (point-min))
4362 (narrow-to-region (point) (point))
4364 (message-remove-header "Mime-Version")
4365 (message-remove-header "Content-Type")
4366 (message-remove-header "Content-Transfer-Encoding")
4367 (message-remove-header "Message-ID")
4368 (message-remove-header "Lines")
4369 (goto-char (point-max))
4370 (insert "Mime-Version: 1.0\n")
4371 (setq header
(buffer-string)))
4372 (goto-char (point-max))
4373 (insert (format "Content-Type: message/partial; id=\"%s\"; number=%d; total=%d\n\n"
4376 (let ((mail-header-separator ""))
4377 (when (memq 'Message-ID message-required-mail-headers
)
4378 (insert "Message-ID: " (message-make-message-id) "\n"))
4379 (when (memq 'Lines message-required-mail-headers
)
4380 (insert "Lines: " (message-make-lines) "\n"))
4381 (message-goto-subject)
4383 (insert (format " (%d/%d)" n total
))
4385 (funcall (or message-send-mail-real-function
4386 message-send-mail-function
)))
4388 (setq p
(pop plist
))
4390 (kill-buffer tembuf
))))
4392 (declare-function hashcash-wait-async
"hashcash" (&optional buffer
))
4394 (defun message-send-mail (&optional arg
)
4395 (require 'mail-utils
)
4396 (let* ((tembuf (message-generate-new-buffer-clone-locals " message temp"))
4397 (case-fold-search nil
)
4398 (news (message-news-p))
4399 (mailbuf (current-buffer))
4400 (message-this-is-mail t
)
4401 ;; gnus-setup-posting-charset is autoloaded in mml.el (FIXME
4402 ;; maybe it should not be), which this file requires. Hence
4403 ;; the fboundp test is always true. Loading it from gnus-msg
4404 ;; loads many Gnus files (Bug#5642). If
4405 ;; gnus-group-posting-charset-alist hasn't been customized,
4406 ;; this is just going to return nil anyway. FIXME it would
4407 ;; be good to improve this further, because even if g-g-p-c-a
4408 ;; has been customized, that is likely to just be for news.
4409 ;; Eg either move the definition from gnus-msg, or separate out
4410 ;; the mail and news parts.
4411 (message-posting-charset
4412 (if (and (fboundp 'gnus-setup-posting-charset
)
4413 (boundp 'gnus-group-posting-charset-alist
))
4414 (gnus-setup-posting-charset nil
)
4415 message-posting-charset
))
4416 (headers message-required-mail-headers
))
4417 (when (and message-generate-hashcash
4418 (not (eq message-generate-hashcash
'opportunistic
)))
4419 (message "Generating hashcash...")
4421 ;; Wait for calculations already started to finish...
4422 (hashcash-wait-async)
4423 ;; ...and do calculations not already done. mail-add-payment
4424 ;; will leave existing X-Hashcash headers alone.
4426 (message "Generating hashcash...done"))
4428 (message-narrow-to-headers)
4429 ;; Generate the Mail-Followup-To header if the header is not there...
4430 (if (and (message-subscribed-p)
4431 (not (mail-fetch-field "mail-followup-to")))
4434 (cons "Mail-Followup-To" (message-make-mail-followup-to))
4435 message-required-mail-headers
))
4436 ;; otherwise, delete the MFT header if the field is empty
4437 (when (equal "" (mail-fetch-field "mail-followup-to"))
4438 (message-remove-header "^Mail-Followup-To:")))
4439 ;; Insert some headers.
4440 (let ((message-deletable-headers
4441 (if news nil message-deletable-headers
)))
4442 (message-generate-headers headers
))
4443 ;; Check continuation headers.
4444 (message-check 'continuation-headers
4445 (goto-char (point-min))
4446 (while (re-search-forward "^[^ \t\n][^ \t\n:]*[ \t\n]" nil t
)
4447 (goto-char (match-beginning 0))
4448 (if (y-or-n-p "Fix continuation lines? ")
4451 (unless (y-or-n-p "Send anyway? ")
4452 (error "Failed to send the message")))))
4453 ;; Let the user do all of the above.
4454 (run-hooks 'message-header-hook
))
4456 (with-current-buffer tembuf
4458 ;; Avoid copying text props (except hard newlines).
4459 (insert (with-current-buffer mailbuf
4460 (mml-buffer-substring-no-properties-except-hard-newlines
4461 (point-min) (point-max))))
4462 ;; Remove some headers.
4463 (message-encode-message-body)
4465 (message-narrow-to-headers)
4466 ;; We (re)generate the Lines header.
4467 (when (memq 'Lines message-required-mail-headers
)
4468 (message-generate-headers '(Lines)))
4469 ;; Remove some headers.
4470 (message-remove-header message-ignored-mail-headers t
)
4471 (let ((mail-parse-charset message-default-charset
))
4472 (mail-encode-encoded-word-buffer)))
4473 (goto-char (point-max))
4474 ;; require one newline at the end.
4475 (or (= (preceding-char) ?
\n)
4477 (message-cleanup-headers)
4478 ;; FIXME: we're inserting the courtesy copy after encoding.
4479 ;; This is wrong if the courtesy copy string contains
4480 ;; non-ASCII characters. -- jh
4483 (message-narrow-to-headers)
4485 (or (message-fetch-field "cc")
4486 (message-fetch-field "bcc")
4487 (message-fetch-field "to"))
4488 (let ((content-type (message-fetch-field
4493 (string= "text/plain"
4495 (mail-header-parse-content-type
4499 (message-fetch-field
4500 "content-transfer-encoding")))))))
4501 (message-insert-courtesy-copy
4502 (with-current-buffer mailbuf
4503 message-courtesy-message
)))
4504 ;; Let's make sure we encoded all the body.
4505 (assert (save-excursion
4506 (goto-char (point-min))
4507 (not (re-search-forward "[^\000-\377]" nil t
))))
4508 (mm-disable-multibyte)
4509 (if (or (not message-send-mail-partially-limit
)
4510 (< (buffer-size) message-send-mail-partially-limit
)
4511 (not (message-y-or-n-p
4512 "The message size is too large, split? "
4516 (/ (buffer-size) 1000) "KB, is too large.
4518 Some mail gateways (MTA's) bounce large messages. To avoid the
4519 problem, answer `y', and the message will be split into several
4520 smaller pieces, the size of each is about "
4521 (/ message-send-mail-partially-limit
1000)
4525 However, some mail readers (MUA's) can't read split messages, i.e.,
4526 mails in message/partially format. Answer `n', and the message will be
4529 The size limit is controlled by `message-send-mail-partially-limit'.
4530 If you always want Gnus to send messages in one piece, set
4531 `message-send-mail-partially-limit' to nil.
4534 (message "Sending via mail...")
4535 (funcall (or message-send-mail-real-function
4536 message-send-mail-function
)))
4537 (message-send-mail-partially)))
4538 (kill-buffer tembuf
))
4539 (set-buffer mailbuf
)
4540 (push 'mail message-sent-message-via
)))
4542 (defun message-send-mail-with-sendmail ()
4543 "Send off the prepared buffer with sendmail."
4545 (let ((errbuf (if message-interactive
4546 (message-generate-new-buffer-clone-locals
4549 resend-to-addresses delimline
)
4552 (let ((case-fold-search t
))
4554 (message-narrow-to-headers)
4555 (setq resend-to-addresses
(message-fetch-field "resent-to")))
4556 ;; Change header-delimiter to be what sendmail expects.
4557 (goto-char (point-min))
4559 (concat "^" (regexp-quote mail-header-separator
) "\n"))
4560 (replace-match "\n")
4562 (setq delimline
(point-marker))
4563 (run-hooks 'message-send-mail-hook
)
4564 ;; Insert an extra newline if we need it to work around
4565 ;; Sun's bug that swallows newlines.
4566 (goto-char (1+ delimline
))
4567 (when (eval message-mailer-swallows-blank-line
)
4569 (when message-interactive
4570 (with-current-buffer errbuf
4572 (let* ((default-directory "/")
4573 (coding-system-for-write message-send-coding-system
)
4575 'call-process-region
4577 (list (point-min) (point-max)
4578 (cond ((boundp 'sendmail-program
)
4580 ((file-exists-p "/usr/sbin/sendmail")
4581 "/usr/sbin/sendmail")
4582 ((file-exists-p "/usr/lib/sendmail")
4583 "/usr/lib/sendmail")
4584 ((file-exists-p "/usr/ucblib/sendmail")
4585 "/usr/ucblib/sendmail")
4587 nil errbuf nil
"-oi")
4588 message-sendmail-extra-arguments
4589 ;; Always specify who from,
4590 ;; since some systems have broken sendmails.
4591 ;; But some systems are more broken with -f, so
4592 ;; we'll let users override this.
4593 (and (null message-sendmail-f-is-evil
)
4594 (list "-f" (message-sendmail-envelope-from)))
4595 ;; These mean "report errors by mail"
4596 ;; and "deliver in background".
4597 (if (null message-interactive
) '("-oem" "-odb"))
4598 ;; Get the addresses from the message
4599 ;; unless this is a resend.
4600 ;; We must not do that for a resend
4601 ;; because we would find the original addresses.
4602 ;; For a resend, include the specific addresses.
4603 (if resend-to-addresses
4604 (list resend-to-addresses
)
4606 (unless (or (null cpr
) (and (numberp cpr
) (zerop cpr
)))
4607 (if errbuf
(pop-to-buffer errbuf
))
4608 (error "Sending...failed with exit value %d" cpr
)))
4609 (when message-interactive
4610 (with-current-buffer errbuf
4611 (goto-char (point-min))
4612 (while (re-search-forward "\n+ *" nil t
)
4613 (replace-match "; "))
4614 (if (not (zerop (buffer-size)))
4615 (error "Sending...failed to %s"
4616 (buffer-string))))))
4617 (when (bufferp errbuf
)
4618 (kill-buffer errbuf
)))))
4620 (defun message-send-mail-with-qmail ()
4621 "Pass the prepared message buffer to qmail-inject.
4622 Refer to the documentation for the variable `message-send-mail-function'
4623 to find out how to use this."
4624 ;; replace the header delimiter with a blank line
4625 (goto-char (point-min))
4627 (concat "^" (regexp-quote mail-header-separator
) "\n"))
4628 (replace-match "\n")
4629 (run-hooks 'message-send-mail-hook
)
4632 (let ((coding-system-for-write message-send-coding-system
))
4634 'call-process-region
(point-min) (point-max)
4635 message-qmail-inject-program nil nil nil
4636 ;; qmail-inject's default behavior is to look for addresses on the
4637 ;; command line; if there're none, it scans the headers.
4638 ;; yes, it does The Right Thing w.r.t. Resent-To and it's kin.
4640 ;; in general, ALL of qmail-inject's defaults are perfect for simply
4641 ;; reading a formatted (i. e., at least a To: or Resent-To header)
4642 ;; message from stdin.
4644 ;; qmail also has the advantage of not having been raped by
4645 ;; various vendors, so we don't have to allow for that, either --
4646 ;; compare this with message-send-mail-with-sendmail and weep
4647 ;; for sendmail's lost innocence.
4649 ;; all this is way cool coz it lets us keep the arguments entirely
4650 ;; free for -inject-arguments -- a big win for the user and for us
4651 ;; since we don't have to play that double-guessing game and the user
4652 ;; gets full control (no gestapo'ish -f's, for instance). --sj
4653 (if (functionp message-qmail-inject-args
)
4654 (funcall message-qmail-inject-args
)
4655 message-qmail-inject-args
)))
4656 ;; qmail-inject doesn't say anything on it's stdout/stderr,
4657 ;; we have to look at the retval instead
4659 (100 (error "qmail-inject reported permanent failure"))
4660 (111 (error "qmail-inject reported transient failure"))
4661 ;; should never happen
4662 (t (error "qmail-inject reported unknown failure"))))
4664 (defun message-send-mail-with-mh ()
4665 "Send the prepared message buffer with mh."
4666 (let ((mh-previous-window-config nil
)
4667 (name (mh-new-draft-name)))
4668 (setq buffer-file-name name
)
4669 ;; MH wants to generate these headers itself.
4670 (when message-mh-deletable-headers
4671 (let ((headers message-mh-deletable-headers
))
4673 (goto-char (point-min))
4674 (and (re-search-forward
4675 (concat "^" (symbol-name (car headers
)) ": *") nil t
)
4676 (message-delete-line))
4678 (run-hooks 'message-send-mail-hook
)
4679 ;; Pass it on to mh.
4682 (defun message-smtpmail-send-it ()
4683 "Send the prepared message buffer with `smtpmail-send-it'.
4684 The only difference from `smtpmail-send-it' is that this command
4685 evaluates `message-send-mail-hook' just before sending a message.
4686 It is useful if your ISP requires the POP-before-SMTP
4687 authentication. See the Gnus manual for details."
4688 (run-hooks 'message-send-mail-hook
)
4691 (defun message-send-mail-with-mailclient ()
4692 "Send the prepared message buffer with `mailclient-send-it'.
4693 The only difference from `mailclient-send-it' is that this
4694 command evaluates `message-send-mail-hook' just before sending a message."
4695 (run-hooks 'message-send-mail-hook
)
4696 (mailclient-send-it))
4698 (defun message-canlock-generate ()
4699 "Return a string that is non-trivial to guess.
4700 Do not use this for anything important, it is cryptographically weak."
4702 (let (sha1-maximum-internal-length)
4703 (sha1 (concat (message-unique-id)
4704 (format "%x%x%x" (random) (random t
) (random))
4705 (prin1-to-string (recent-keys))
4706 (prin1-to-string (garbage-collect))))))
4708 (defvar canlock-password
)
4709 (defvar canlock-password-for-verify
)
4711 (defun message-canlock-password ()
4712 "The password used by message for cancel locks.
4713 This is the value of `canlock-password', if that option is non-nil.
4714 Otherwise, generate and save a value for `canlock-password' first."
4716 (unless canlock-password
4717 (customize-save-variable 'canlock-password
(message-canlock-generate))
4718 (setq canlock-password-for-verify canlock-password
))
4721 (defun message-insert-canlock ()
4722 (when message-insert-canlock
4723 (message-canlock-password)
4724 (canlock-insert-header)))
4726 (autoload 'nnheader-get-report
"nnheader")
4728 (declare-function gnus-setup-posting-charset
"gnus-msg" (group))
4730 (defun message-send-news (&optional arg
)
4732 (let* ((tembuf (message-generate-new-buffer-clone-locals " *message temp*"))
4733 (case-fold-search nil
)
4734 (method (if (functionp message-post-method
)
4735 (funcall message-post-method arg
)
4736 message-post-method
))
4737 (newsgroups-field (save-restriction
4738 (message-narrow-to-headers-or-head)
4739 (message-fetch-field "Newsgroups")))
4740 (followup-field (save-restriction
4741 (message-narrow-to-headers-or-head)
4742 (message-fetch-field "Followup-To")))
4743 ;; BUG: We really need to get the charset for each name in the
4744 ;; Newsgroups and Followup-To lines to allow crossposting
4745 ;; between group namess with incompatible character sets.
4746 ;; -- Per Abrahamsen <abraham@dina.kvl.dk> 2001-10-08.
4747 (group-field-charset
4748 (gnus-group-name-charset method newsgroups-field
))
4749 (followup-field-charset
4750 (gnus-group-name-charset method
(or followup-field
"")))
4751 (rfc2047-header-encoding-alist
4752 (append (when group-field-charset
4753 (list (cons "Newsgroups" group-field-charset
)))
4754 (when followup-field-charset
4755 (list (cons "Followup-To" followup-field-charset
)))
4756 rfc2047-header-encoding-alist
))
4757 (messbuf (current-buffer))
4758 (message-syntax-checks
4760 (listp message-syntax-checks
))
4761 (cons '(existing-newsgroups . disabled
)
4762 message-syntax-checks
)
4763 message-syntax-checks
))
4764 (message-this-is-news t
)
4765 (message-posting-charset
4766 (gnus-setup-posting-charset newsgroups-field
))
4768 (if (not (message-check-news-body-syntax))
4771 (message-narrow-to-headers)
4772 ;; Insert some headers.
4773 (message-generate-headers message-required-news-headers
)
4774 (message-insert-canlock)
4775 ;; Let the user do all of the above.
4776 (run-hooks 'message-header-hook
))
4777 ;; Note: This check will be disabled by the ".*" default value for
4778 ;; gnus-group-name-charset-group-alist. -- Pa 2001-10-07.
4779 (when (and group-field-charset
4780 (listp message-syntax-checks
))
4781 (setq message-syntax-checks
4782 (cons '(valid-newsgroups . disabled
)
4783 message-syntax-checks
)))
4784 (message-cleanup-headers)
4785 (if (not (let ((message-post-method method
))
4786 (message-check-news-syntax)))
4789 (with-current-buffer tembuf
4790 (buffer-disable-undo)
4792 ;; Avoid copying text props (except hard newlines).
4794 (with-current-buffer messbuf
4795 (mml-buffer-substring-no-properties-except-hard-newlines
4796 (point-min) (point-max))))
4797 (message-encode-message-body)
4798 ;; Remove some headers.
4800 (message-narrow-to-headers)
4801 ;; We (re)generate the Lines header.
4802 (when (memq 'Lines message-required-mail-headers
)
4803 (message-generate-headers '(Lines)))
4804 ;; Remove some headers.
4805 (message-remove-header message-ignored-news-headers t
)
4806 (let ((mail-parse-charset message-default-charset
))
4807 (mail-encode-encoded-word-buffer)))
4808 (goto-char (point-max))
4809 ;; require one newline at the end.
4810 (or (= (preceding-char) ?
\n)
4812 (let ((case-fold-search t
))
4813 ;; Remove the delimiter.
4814 (goto-char (point-min))
4816 (concat "^" (regexp-quote mail-header-separator
) "\n"))
4817 (replace-match "\n")
4819 (run-hooks 'message-send-news-hook
)
4820 (gnus-open-server method
)
4821 (message "Sending news via %s..." (gnus-server-string method
))
4822 (setq result
(let ((mail-header-separator ""))
4823 (gnus-request-post method
))))
4824 (kill-buffer tembuf
))
4825 (set-buffer messbuf
)
4827 (push 'news message-sent-message-via
)
4828 (message "Couldn't send message via news: %s"
4829 (nnheader-get-report (car method
)))
4833 ;;; Header generation & syntax checking.
4836 (defun message-check-element (type)
4837 "Return non-nil if this TYPE is not to be checked."
4838 (if (eq message-syntax-checks
'dont-check-for-anything-just-trust-me
)
4840 (let ((able (assq type message-syntax-checks
)))
4842 (eq (cdr able
) 'disabled
)))))
4844 (defun message-check-news-syntax ()
4845 "Check the syntax of the message."
4849 ;; We narrow to the headers and check them first.
4852 (message-narrow-to-headers)
4853 (message-check-news-header-syntax))))))
4855 (defun message-check-news-header-syntax ()
4857 ;; Check Newsgroups header.
4858 (message-check 'newsgroups
4859 (let ((group (message-fetch-field "newsgroups")))
4862 (not (string-match "\\`[ \t]*\\'" group
)))
4865 "The newsgroups field is empty or missing. Posting is denied.")))))
4866 ;; Check the Subject header.
4867 (message-check 'subject
4868 (let* ((case-fold-search t
)
4869 (subject (message-fetch-field "subject")))
4872 (not (string-match "\\`[ \t]*\\'" subject
)))
4875 "The subject field is empty or missing. Posting is denied.")))))
4876 ;; Check for commands in Subject.
4877 (message-check 'subject-cmsg
4878 (if (string-match "^cmsg " (message-fetch-field "subject"))
4880 "The control code \"cmsg\" is in the subject. Really post? ")
4882 ;; Check long header lines.
4883 (message-check 'long-header-lines
4884 (let ((start (point))
4888 (while (and (not found
)
4889 (re-search-forward "^\\([^ \t:]+\\): " nil t
))
4890 (if (> (- (point) (match-beginning 0)) 998)
4892 length
(- (point) (match-beginning 0)))
4893 (setq header
(match-string-no-properties 1)))
4894 (setq start
(match-beginning 0))
4897 (y-or-n-p (format "Your %s header is too long (%d). Really post? "
4900 ;; Check for multiple identical headers.
4901 (message-check 'multiple-headers
4903 (while (and (not found
)
4904 (re-search-forward "^[^ \t:]+: " nil t
))
4906 (or (re-search-forward
4911 (match-beginning 0) (- (match-end 0) 2))))
4916 (y-or-n-p (format "Multiple %s headers. Really post? " found
))
4918 ;; Check for Version and Sendsys.
4919 (message-check 'sendsys
4920 (if (re-search-forward "^Sendsys:\\|^Version:" nil t
)
4922 (format "The article contains a %s command. Really post? "
4923 (buffer-substring (match-beginning 0)
4924 (1- (match-end 0)))))
4926 ;; See whether we can shorten Followup-To.
4927 (message-check 'shorten-followup-to
4928 (let ((newsgroups (message-fetch-field "newsgroups"))
4929 (followup-to (message-fetch-field "followup-to"))
4931 (when (and newsgroups
4932 (string-match "," newsgroups
)
4937 (setq to
(completing-read
4938 "Followups to (default no Followup-To header): "
4941 (message-tokenize-header
4943 (goto-char (point-min))
4944 (insert "Followup-To: " to
"\n"))
4946 ;; Check "Shoot me".
4947 (message-check 'shoot
4948 (if (re-search-forward
4949 "Message-ID.*.i-did-not-set--mail-host-address--so-tickle-me" nil t
)
4950 (y-or-n-p "You appear to have a misconfigured system. Really post? ")
4952 ;; Check for Approved.
4953 (message-check 'approved
4954 (if (re-search-forward "^Approved:" nil t
)
4955 (y-or-n-p "The article contains an Approved header. Really post? ")
4957 ;; Check the Message-ID header.
4958 (message-check 'message-id
4959 (let* ((case-fold-search t
)
4960 (message-id (message-fetch-field "message-id" t
)))
4961 (or (not message-id
)
4962 ;; Is there an @ in the ID?
4963 (and (string-match "@" message-id
)
4964 ;; Is there a dot in the ID?
4965 (string-match "@[^.]*\\." message-id
)
4966 ;; Does the ID end with a dot?
4967 (not (string-match "\\.>" message-id
)))
4969 (format "The Message-ID looks strange: \"%s\". Really post? "
4971 ;; Check the Newsgroups & Followup-To headers.
4972 (message-check 'existing-newsgroups
4973 (let* ((case-fold-search t
)
4974 (newsgroups (message-fetch-field "newsgroups"))
4975 (followup-to (message-fetch-field "followup-to"))
4976 (groups (message-tokenize-header
4978 (concat newsgroups
"," followup-to
)
4980 (post-method (if (functionp message-post-method
)
4981 (funcall message-post-method
)
4982 message-post-method
))
4983 ;; KLUDGE to handle nnvirtual groups. Doing this right
4984 ;; would probably involve a new nnoo function.
4985 ;; -- Per Abrahamsen <abraham@dina.kvl.dk>, 2001-10-17.
4986 (method (if (and (consp post-method
)
4987 (eq (car post-method
) 'nnvirtual
)
4988 gnus-message-group-art
)
4989 (let ((group (car (nnvirtual-find-group-art
4990 (car gnus-message-group-art
)
4991 (cdr gnus-message-group-art
)))))
4992 (gnus-find-method-for-group group
))
4996 (gnus-group-name-decode
4997 (gnus-group-real-name n
)
4998 (gnus-group-name-charset method n
)))
4999 (gnus-groups-from-server method
)))
5002 (when (and (not (equal (car groups
) "poster"))
5003 (not (member (car groups
) known-groups
))
5004 (not (member (car groups
) errors
)))
5005 (push (car groups
) errors
))
5008 ;; Gnus is not running.
5009 ((or (not (and (boundp 'gnus-active-hashtb
)
5010 gnus-active-hashtb
))
5011 (not (boundp 'gnus-read-active-file
)))
5013 ;; We don't have all the group names.
5014 ((and (or (not gnus-read-active-file
)
5015 (eq gnus-read-active-file
'some
))
5019 "Really use %s possibly unknown group%s: %s? "
5020 (if (= (length errors
) 1) "this" "these")
5021 (if (= (length errors
) 1) "" "s")
5022 (mapconcat 'identity errors
", "))))
5023 ;; There were no errors.
5026 ;; There are unknown groups.
5030 "Really post to %s unknown group%s: %s? "
5031 (if (= (length errors
) 1) "this" "these")
5032 (if (= (length errors
) 1) "" "s")
5033 (mapconcat 'identity errors
", ")))))))
5034 ;; Check continuation headers.
5035 (message-check 'continuation-headers
5036 (goto-char (point-min))
5037 (let ((do-posting t
))
5038 (while (re-search-forward "^[^ \t\n][^ \t\n:]*[ \t\n]" nil t
)
5039 (goto-char (match-beginning 0))
5040 (if (y-or-n-p "Fix continuation lines? ")
5043 (unless (y-or-n-p "Send anyway? ")
5044 (setq do-posting nil
))))
5046 ;; Check the Newsgroups & Followup-To headers for syntax errors.
5047 (message-check 'valid-newsgroups
5048 (let ((case-fold-search t
)
5049 (headers '("Newsgroups" "Followup-To"))
5051 (while (and headers
(not error
))
5052 (when (setq header
(mail-fetch-field (car headers
)))
5056 "\\`\\([-+_&.a-zA-Z0-9]+\\)?\\(,[-+_&.a-zA-Z0-9]+\\)*\\'"
5061 (not (string-match "\\.\\'\\|\\.\\." g
)))
5062 (message-tokenize-header header
","))))
5069 (format "The %s header looks odd: \"%s\". Really post? "
5070 (car headers
) header
)))))
5071 (message-check 'repeated-newsgroups
5072 (let ((case-fold-search t
)
5073 (headers '("Newsgroups" "Followup-To"))
5074 header error groups group
)
5077 (when (setq header
(mail-fetch-field (pop headers
)))
5078 (setq groups
(message-tokenize-header header
","))
5079 (while (setq group
(pop groups
))
5080 (when (member group groups
)
5086 (format "Group %s is repeated in headers. Really post? " error
)))))
5087 ;; Check the From header.
5088 (message-check 'from
5089 (let* ((case-fold-search t
)
5090 (from (message-fetch-field "from"))
5094 (message "There is no From line. Posting is denied.")
5096 ((or (not (string-match
5098 (setq ad
(nth 1 (mail-extract-address-components
5099 from
))))) ;larsi@ifi
5100 (string-match "\\.\\." ad
) ;larsi@ifi..uio
5101 (string-match "@\\." ad
) ;larsi@.ifi.uio
5102 (string-match "\\.$" ad
) ;larsi@ifi.uio.
5103 (not (string-match "^[^@]+@[^@]+$" ad
)) ;larsi.ifi.uio
5104 (string-match "(.*).*(.*)" from
)) ;(lars) (lars)
5106 "Denied posting -- the From looks strange: \"%s\"." from
)
5108 ((let ((addresses (rfc822-addresses from
)))
5109 ;; `rfc822-addresses' returns a string if parsing fails.
5110 (while (and (consp addresses
)
5111 (not (eq (string-to-char (car addresses
)) ?\
()))
5112 (setq addresses
(cdr addresses
)))
5115 "Denied posting -- bad From address: \"%s\"." from
)
5118 ;; Check the Reply-To header.
5119 (message-check 'reply-to
5120 (let* ((case-fold-search t
)
5121 (reply-to (message-fetch-field "reply-to"))
5126 ((string-match "," reply-to
)
5128 (format "Multiple Reply-To addresses: \"%s\". Really post? "
5130 ((or (not (string-match
5132 (setq ad
(nth 1 (mail-extract-address-components
5133 reply-to
))))) ;larsi@ifi
5134 (string-match "\\.\\." ad
) ;larsi@ifi..uio
5135 (string-match "@\\." ad
) ;larsi@.ifi.uio
5136 (string-match "\\.$" ad
) ;larsi@ifi.uio.
5137 (not (string-match "^[^@]+@[^@]+$" ad
)) ;larsi.ifi.uio
5138 (string-match "(.*).*(.*)" reply-to
)) ;(lars) (lars)
5141 "The Reply-To looks strange: \"%s\". Really post? "
5145 (defun message-check-news-body-syntax ()
5147 ;; Check for long lines.
5148 (message-check 'long-lines
5149 (goto-char (point-min))
5151 (concat "^" (regexp-quote mail-header-separator
) "$"))
5155 "<#\\(/\\)?\\(multipart\\|part\\|external\\|mml\\)")
5158 (< (- (point) p
) 80)))
5159 (zerop (forward-line 1))))
5163 "You have lines longer than 79 characters. Really post? ")))
5164 ;; Check whether the article is empty.
5165 (message-check 'empty
5166 (goto-char (point-min))
5168 (concat "^" (regexp-quote mail-header-separator
) "$"))
5171 (goto-char (point-max))
5172 (re-search-backward message-signature-separator nil t
)
5174 (or (re-search-backward "[^ \n\t]" b t
)
5175 (if (message-gnksa-enable-p 'empty-article
)
5176 (y-or-n-p "Empty article. Really post? ")
5177 (message "Denied posting -- Empty article.")
5179 ;; Check for control characters.
5180 (message-check 'control-chars
5181 (if (re-search-forward
5182 (mm-string-to-multibyte "[\000-\007\013\015-\032\034-\037\200-\237]")
5185 "The article contains control characters. Really post? ")
5187 ;; Check excessive size.
5188 (message-check 'size
5189 (if (> (buffer-size) 60000)
5191 (format "The article is %d octets long. Really post? "
5194 ;; Check whether any new text has been added.
5195 (message-check 'new-text
5197 (not message-checksum
)
5198 (not (eq (message-checksum) message-checksum
))
5199 (if (message-gnksa-enable-p 'quoted-text-only
)
5201 "It looks like no new text has been added. Really post? ")
5202 (message "Denied posting -- no new text has been added.")
5204 ;; Check the length of the signature.
5205 (message-check 'signature
5206 (let (sig-start sig-end
)
5207 (goto-char (point-max))
5208 (if (not (re-search-backward message-signature-separator nil t
))
5210 (setq sig-start
(1+ (point-at-eol)))
5212 (if (re-search-forward
5213 "<#/?\\(multipart\\|part\\|external\\|mml\\)" nil t
)
5214 (- (point-at-bol) 1)
5216 (if (>= (count-lines sig-start sig-end
) 5)
5217 (if (message-gnksa-enable-p 'signature
)
5219 (format "Signature is excessively long (%d lines). Really post? "
5220 (count-lines sig-start sig-end
)))
5221 (message "Denied posting -- Excessive signature.")
5224 ;; Ensure that text follows last quoted portion.
5225 (message-check 'quoting-style
5226 (goto-char (point-max))
5227 (let ((no-problem t
))
5228 (when (search-backward-regexp "^>[^\n]*\n" nil t
)
5229 (setq no-problem
(search-forward-regexp "^[ \t]*[^>\n]" nil t
)))
5232 (if (message-gnksa-enable-p 'quoted-text-only
)
5233 (y-or-n-p "Your text should follow quoted text. Really post? ")
5235 (goto-char (point-min))
5237 (concat "^" (regexp-quote mail-header-separator
) "$"))
5238 (if (search-forward-regexp "^[ \t]*[^>\n]" nil t
)
5239 (y-or-n-p "Your text should follow quoted text. Really post? ")
5240 (message "Denied posting -- only quoted text.")
5243 (defun message-checksum ()
5244 "Return a \"checksum\" for the current buffer."
5247 (goto-char (point-min))
5249 (concat "^" (regexp-quote mail-header-separator
) "$"))
5251 (when (not (looking-at "[ \t\n]"))
5252 (setq sum
(logxor (ash sum
1) (if (natnump sum
) 0 1)
5257 (defun message-do-fcc ()
5258 "Process Fcc headers in the current buffer."
5259 (let ((case-fold-search t
)
5260 (buf (current-buffer))
5262 (mml-externalize-attachments message-fcc-externalize-attachments
))
5265 (message-narrow-to-headers)
5266 (setq file
(message-fetch-field "fcc" t
)))
5268 (set-buffer (get-buffer-create " *message temp*"))
5270 (insert-buffer-substring buf
)
5271 (message-encode-message-body)
5273 (message-narrow-to-headers)
5274 (while (setq file
(message-fetch-field "fcc" t
))
5276 (message-remove-header "fcc" nil t
))
5277 (let ((mail-parse-charset message-default-charset
)
5278 (rfc2047-header-encoding-alist
5279 (cons '("Newsgroups" . default
)
5280 rfc2047-header-encoding-alist
)))
5281 (mail-encode-encoded-word-buffer)))
5282 (goto-char (point-min))
5283 (when (re-search-forward
5284 (concat "^" (regexp-quote mail-header-separator
) "$")
5286 (replace-match "" t t
))
5287 ;; Process FCC operations.
5289 (setq file
(pop list
))
5290 (if (string-match "^[ \t]*|[ \t]*\\(.*\\)[ \t]*$" file
)
5291 ;; Pipe the article to the program in question.
5292 (call-process-region (point-min) (point-max) shell-file-name
5293 nil nil nil shell-command-switch
5294 (match-string 1 file
))
5295 ;; Save the article.
5296 (setq file
(expand-file-name file
))
5297 (unless (file-exists-p (file-name-directory file
))
5298 (make-directory (file-name-directory file
) t
))
5299 (if (and message-fcc-handler-function
5300 (not (eq message-fcc-handler-function
'rmail-output
)))
5301 (funcall message-fcc-handler-function file
)
5302 ;; FIXME this option, rmail-output (also used if
5303 ;; message-fcc-handler-function is nil) is not
5304 ;; documented anywhere AFAICS. It should work in Emacs
5305 ;; 23; I suspect it does not work in Emacs 22.
5306 ;; FIXME I don't see the need for the two different cases here.
5307 ;; mail-use-rfc822 makes no difference (in Emacs 23),and
5308 ;; the third argument just controls \"Wrote file\" message.
5309 (if (and (file-readable-p file
) (mail-file-babyl-p file
))
5310 (rmail-output file
1 nil t
)
5311 (let ((mail-use-rfc822 t
))
5312 (rmail-output file
1 t t
))))))
5313 (kill-buffer (current-buffer))))))
5315 (defun message-output (filename)
5316 "Append this article to Unix/babyl mail file FILENAME."
5317 (if (or (and (file-readable-p filename
)
5318 (mail-file-babyl-p filename
))
5319 ;; gnus-output-to-mail does the wrong thing with live, mbox
5320 ;; Rmail buffers in Emacs 23.
5321 ;; http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=597255
5322 (let ((buff (find-buffer-visiting filename
)))
5323 (and buff
(with-current-buffer buff
5324 (eq major-mode
'rmail-mode
)))))
5325 (gnus-output-to-rmail filename t
)
5326 (gnus-output-to-mail filename t
)))
5328 (defun message-cleanup-headers ()
5329 "Do various automatic cleanups of the headers."
5330 ;; Remove empty lines in the header.
5332 (message-narrow-to-headers)
5333 ;; Remove blank lines.
5334 (while (re-search-forward "^[ \t]*\n" nil t
)
5335 (replace-match "" t t
))
5337 ;; Correct Newsgroups and Followup-To headers: Change sequence of
5338 ;; spaces to comma and eliminate spaces around commas. Eliminate
5339 ;; embedded line breaks.
5340 (goto-char (point-min))
5341 (while (re-search-forward "^\\(Newsgroups\\|Followup-To\\): +" nil t
)
5345 (if (re-search-forward "^[^ \t]" nil t
)
5349 (goto-char (point-min))
5350 (while (re-search-forward "\n[ \t]+" nil t
)
5351 (replace-match " " t t
)) ;No line breaks (too confusing)
5352 (goto-char (point-min))
5353 (while (re-search-forward "[ \t\n]*,[ \t\n]*\\|[ \t]+" nil t
)
5354 (replace-match "," t t
))
5355 (goto-char (point-min))
5356 ;; Remove trailing commas.
5357 (when (re-search-forward ",+$" nil t
)
5358 (replace-match "" t t
))))))
5360 (defun message-make-date (&optional now
)
5361 "Make a valid data header.
5362 If NOW, use that time instead."
5363 (let ((system-time-locale "C"))
5364 (format-time-string "%a, %d %b %Y %T %z" now
)))
5366 (defun message-insert-expires (days)
5367 "Insert the Expires header. Expiry in DAYS days."
5368 (interactive "NExpire article in how many days? ")
5370 (message-position-on-field "Expires" "X-Draft-From")
5371 (insert (message-make-expires-date days
))))
5373 (defun message-make-expires-date (days)
5374 "Make date string for the Expires header. Expiry in DAYS days.
5376 In posting styles use `(\"Expires\" (make-expires-date 30))'."
5377 (let* ((cur (decode-time (current-time)))
5378 (nday (+ days
(nth 3 cur
))))
5379 (setf (nth 3 cur
) nday
)
5380 (message-make-date (apply 'encode-time cur
))))
5382 (defun message-make-message-id ()
5383 "Make a unique Message-ID."
5384 (concat "<" (message-unique-id)
5385 (let ((psubject (save-excursion (message-fetch-field "subject")))
5387 (save-excursion (message-fetch-field "supersedes"))))
5389 (and message-reply-headers
5390 (mail-header-references message-reply-headers
)
5391 (mail-header-subject message-reply-headers
)
5394 (message-strip-subject-re
5395 (mail-header-subject message-reply-headers
))
5396 (message-strip-subject-re psubject
))))
5398 (string-match "_-_@" psupersedes
)))
5400 "@" (message-make-fqdn) ">"))
5402 (defvar message-unique-id-char nil
)
5404 ;; If you ever change this function, make sure the new version
5405 ;; cannot generate IDs that the old version could.
5406 ;; You might for example insert a "." somewhere (not next to another dot
5407 ;; or string boundary), or modify the "fsf" string.
5408 (defun message-unique-id ()
5409 ;; Don't use microseconds from (current-time), they may be unsupported.
5410 ;; Instead we use this randomly inited counter.
5411 (setq message-unique-id-char
5412 (%
(1+ (or message-unique-id-char
(logand (random t
) (1- (lsh 1 20)))))
5413 ;; (current-time) returns 16-bit ints,
5414 ;; and 2^16*25 just fits into 4 digits i base 36.
5416 (let ((tm (current-time)))
5418 (if (or (eq system-type
'ms-dos
)
5419 ;; message-number-base36 doesn't handle bigints.
5420 (floatp (user-uid)))
5421 (let ((user (downcase (user-login-name))))
5422 (while (string-match "[^a-z0-9_]" user
)
5423 (aset user
(match-beginning 0) ?_
))
5425 (message-number-base36 (user-uid) -
1))
5426 (message-number-base36 (+ (car tm
)
5427 (lsh (% message-unique-id-char
25) 16)) 4)
5428 (message-number-base36 (+ (nth 1 tm
)
5429 (lsh (/ message-unique-id-char
25) 16)) 4)
5430 ;; Append a given name, because while the generated ID is unique
5431 ;; to this newsreader, other newsreaders might otherwise generate
5432 ;; the same ID via another algorithm.
5435 (defun message-number-base36 (num len
)
5440 (concat (message-number-base36 (/ num
36) (1- len
))
5441 (char-to-string (aref "zyxwvutsrqponmlkjihgfedcba9876543210"
5444 (defun message-make-organization ()
5445 "Make an Organization header."
5446 (let* ((organization
5447 (when message-user-organization
5448 (if (functionp message-user-organization
)
5449 (funcall message-user-organization
)
5450 message-user-organization
))))
5452 (mm-enable-multibyte)
5453 (cond ((stringp organization
)
5454 (insert organization
))
5455 ((and (eq t organization
)
5456 message-user-organization-file
5457 (file-exists-p message-user-organization-file
))
5458 (insert-file-contents message-user-organization-file
)))
5459 (goto-char (point-min))
5460 (while (re-search-forward "[\t\n]+" nil t
)
5461 (replace-match "" t t
))
5462 (unless (zerop (buffer-size))
5465 (defun message-make-lines ()
5466 "Count the number of lines and return numeric string."
5471 (int-to-string (count-lines (point) (point-max))))))
5473 (defun message-make-references ()
5474 "Return the References header for this message."
5475 (when message-reply-headers
5476 (let ((message-id (mail-header-id message-reply-headers
))
5477 (references (mail-header-references message-reply-headers
)))
5478 (if (or references message-id
)
5479 (concat (or references
"") (and references
" ")
5483 (defun message-make-in-reply-to ()
5484 "Return the In-Reply-To header for this message."
5485 (when message-reply-headers
5486 (let ((from (mail-header-from message-reply-headers
))
5487 (date (mail-header-date message-reply-headers
))
5488 (msg-id (mail-header-id message-reply-headers
)))
5490 (let ((name (mail-extract-address-components from
)))
5492 msg-id
(if msg-id
" (")
5494 (if (string-match "[^\000-\177]" (car name
))
5495 ;; Quote a string containing non-ASCII characters.
5496 ;; It will make the RFC2047 encoder cause an error
5497 ;; if there are special characters.
5498 (mm-with-multibyte-buffer
5500 (goto-char (point-min))
5501 (while (search-forward "\"" nil t
)
5504 (zerop (%
(skip-chars-backward "\\\\") 2))
5505 (goto-char (match-beginning 0)))
5508 ;; Those quotes will be removed by the RFC2047 encoder.
5509 (concat "\"" (buffer-string) "\""))
5513 (if (or (not date
) (string= date
""))
5514 "(unknown date)" date
)
5515 "\"" (if msg-id
")")))))))
5517 (defun message-make-distribution ()
5518 "Make a Distribution header."
5519 (let ((orig-distribution (message-fetch-reply-field "distribution")))
5520 (cond ((functionp message-distribution-function
)
5521 (funcall message-distribution-function
))
5522 (t orig-distribution
))))
5524 (defun message-make-expires ()
5525 "Return an Expires header based on `message-expires'."
5526 (let ((current (current-time))
5527 (future (* 1.0 message-expires
60 60 24)))
5528 ;; Add the future to current.
5529 (setcar current
(+ (car current
) (round (/ future
(expt 2 16)))))
5530 (setcar (cdr current
) (+ (nth 1 current
) (%
(round future
) (expt 2 16))))
5531 (message-make-date current
)))
5533 (defun message-make-path ()
5535 (let ((login-name (user-login-name)))
5536 (cond ((null message-user-path
)
5537 (concat (system-name) "!" login-name
))
5538 ((stringp message-user-path
)
5539 ;; Support GENERICPATH. Suggested by vixie@decwrl.dec.com.
5540 (concat message-user-path
"!" login-name
))
5543 (defun message-make-from (&optional name address
)
5544 "Make a From header."
5545 (let* ((style message-from-style
)
5546 (login (or address
(message-make-address)))
5548 (and (boundp 'user-full-name
)
5551 (when (string= fullname
"&")
5552 (setq fullname
(user-login-name)))
5554 (mm-enable-multibyte)
5557 (equal fullname
""))
5559 ((or (eq style
'angles
)
5560 (and (not (eq style
'parens
))
5561 ;; Use angles if no quoting is needed, or if parens would
5562 ;; need quoting too.
5563 (or (not (string-match "[^- !#-'*+/-9=?A-Z^-~]" fullname
))
5564 (let ((tmp (concat fullname nil
)))
5565 (while (string-match "([^()]*)" tmp
)
5566 (aset tmp
(match-beginning 0) ?-
)
5567 (aset tmp
(1- (match-end 0)) ?-
))
5568 (string-match "[\\()]" tmp
)))))
5570 (goto-char (point-min))
5571 ;; Look for a character that cannot appear unquoted
5572 ;; according to RFC 822.
5573 (when (re-search-forward "[^- !#-'*+/-9=?A-Z^-~]" nil
1)
5574 ;; Quote fullname, escaping specials.
5575 (goto-char (point-min))
5577 (while (re-search-forward "[\"\\]" nil
1)
5578 (replace-match "\\\\\\&" t
))
5580 (insert " <" login
">"))
5581 (t ; 'parens or default
5583 (let ((fullname-start (point)))
5585 (goto-char fullname-start
)
5586 ;; RFC 822 says \ and nonmatching parentheses
5587 ;; must be escaped in comments.
5588 ;; Escape every instance of ()\ ...
5589 (while (re-search-forward "[()\\]" nil
1)
5590 (replace-match "\\\\\\&" t
))
5591 ;; ... then undo escaping of matching parentheses,
5592 ;; including matching nested parentheses.
5593 (goto-char fullname-start
)
5594 (while (re-search-forward
5595 "\\(\\=\\|[^\\]\\(\\\\\\\\\\)*\\)\\\\(\\(\\([^\\]\\|\\\\\\\\\\)*\\)\\\\)"
5597 (replace-match "\\1(\\3)" t
)
5598 (goto-char fullname-start
)))
5602 (defun message-make-sender ()
5603 "Return the \"real\" user address.
5604 This function tries to ignore all user modifications, and
5605 give as trustworthy answer as possible."
5606 (concat (user-login-name) "@" (system-name)))
5608 (defun message-make-address ()
5609 "Make the address of the user."
5610 (or (message-user-mail-address)
5611 (concat (user-login-name) "@" (message-make-domain))))
5613 (defun message-user-mail-address ()
5614 "Return the pertinent part of `user-mail-address'."
5615 (when (and user-mail-address
5616 (string-match "@.*\\." user-mail-address
))
5617 (if (string-match " " user-mail-address
)
5618 (nth 1 (mail-extract-address-components user-mail-address
))
5619 user-mail-address
)))
5621 (defun message-sendmail-envelope-from ()
5622 "Return the envelope from."
5623 (cond ((eq message-sendmail-envelope-from
'header
)
5624 (nth 1 (mail-extract-address-components
5625 (message-fetch-field "from"))))
5626 ((stringp message-sendmail-envelope-from
)
5627 message-sendmail-envelope-from
)
5629 (message-make-address))))
5631 (defun message-make-fqdn ()
5632 "Return user's fully qualified domain name."
5633 (let* ((system-name (system-name))
5634 (user-mail (message-user-mail-address))
5637 (string-match "@\\(.*\\)\\'" user-mail
))
5638 (match-string 1 user-mail
)))
5639 (case-fold-search t
))
5641 ((and message-user-fqdn
5642 (stringp message-user-fqdn
)
5643 (string-match message-valid-fqdn-regexp message-user-fqdn
)
5644 (not (string-match message-bogus-system-names message-user-fqdn
)))
5645 ;; `message-user-fqdn' seems to be valid
5647 ((and (string-match message-valid-fqdn-regexp system-name
)
5648 (not (string-match message-bogus-system-names system-name
)))
5649 ;; `system-name' returned the right result.
5651 ;; Try `mail-host-address'.
5652 ((and (boundp 'mail-host-address
)
5653 (stringp mail-host-address
)
5654 (string-match message-valid-fqdn-regexp mail-host-address
)
5655 (not (string-match message-bogus-system-names mail-host-address
)))
5657 ;; We try `user-mail-address' as a backup.
5659 (stringp user-domain
)
5660 (string-match message-valid-fqdn-regexp user-domain
)
5661 (not (string-match message-bogus-system-names user-domain
)))
5663 ;; Default to this bogus thing.
5666 ".i-did-not-set--mail-host-address--so-tickle-me")))))
5668 (defun message-make-host-name ()
5669 "Return the name of the host."
5670 (let ((fqdn (message-make-fqdn)))
5671 (string-match "^[^.]+\\." fqdn
)
5672 (substring fqdn
0 (1- (match-end 0)))))
5674 (defun message-make-domain ()
5675 "Return the domain name."
5676 (or mail-host-address
5677 (message-make-fqdn)))
5679 (defun message-to-list-only ()
5680 "Send a message to the list only.
5681 Remove all addresses but the list address from To and Cc headers."
5683 (let ((listaddr (message-make-mail-followup-to t
)))
5686 (message-remove-header "to")
5687 (message-remove-header "cc")
5688 (message-position-on-field "To" "X-Draft-From")
5689 (insert listaddr
)))))
5691 (defun message-make-mail-followup-to (&optional only-show-subscribed
)
5692 "Return the Mail-Followup-To header.
5693 If passed the optional argument ONLY-SHOW-SUBSCRIBED only return the
5694 subscribed address (and not the additional To and Cc header contents)."
5695 (let* ((case-fold-search t
)
5696 (to (message-fetch-field "To"))
5697 (cc (message-fetch-field "cc"))
5698 (msg-recipients (concat to
(and to cc
", ") cc
))
5700 (mapcar 'mail-strip-quoted-names
5701 (message-tokenize-header msg-recipients
)))
5703 (if message-subscribed-address-file
5704 (let (begin end item re
)
5707 (insert-file-contents message-subscribed-address-file
)
5709 (setq begin
(point))
5712 (if (bolp) (setq end
(1- end
)))
5713 (setq item
(regexp-quote (buffer-substring begin end
)))
5714 (if re
(setq re
(concat re
"\\|" item
))
5715 (setq re
(concat "\\`\\(" item
))))
5716 (and re
(list (concat re
"\\)\\'"))))))))
5717 (mft-regexps (apply 'append message-subscribed-regexps
5718 (mapcar 'regexp-quote
5719 message-subscribed-addresses
)
5722 message-subscribed-address-functions
))))
5725 (loop for recipient in recipients
5726 when
(loop for regexp in mft-regexps
5727 when
(string-match regexp recipient
) return t
)
5730 (if only-show-subscribed
5732 msg-recipients
))))))
5734 (defun message-idna-to-ascii-rhs-1 (header)
5735 "Interactively potentially IDNA encode domain names in HEADER."
5736 (let ((field (message-fetch-field header
))
5740 (mm-delete-duplicates
5741 (mapcar (lambda (rhs) (or (cadr (split-string rhs
"@")) ""))
5747 (mail-extract-address-components field t
))))))
5748 ;; Note that `rhs' will be "" if the address does not have
5749 ;; the domain part, i.e., if it is a local user's address.
5750 (setq ace
(if (string-match "\\`[[:ascii:]]*\\'" rhs
)
5752 (downcase (idna-to-ascii rhs
))))
5753 (when (and (not (equal rhs ace
))
5754 (or (not (eq message-use-idna
'ask
))
5755 (y-or-n-p (format "Replace %s with %s in %s:? "
5757 (goto-char (point-min))
5758 (while (re-search-forward (concat "^" header
":") nil t
)
5759 (message-narrow-to-field)
5760 (while (search-forward (concat "@" rhs
) nil t
)
5761 (replace-match (concat "@" ace
) t t
))
5762 (goto-char (point-max))
5765 (defun message-idna-to-ascii-rhs ()
5766 "Possibly IDNA encode non-ASCII domain names in From:, To: and Cc: headers.
5767 See `message-idna-encode'."
5769 (when message-use-idna
5772 ;; `message-narrow-to-head' that recognizes only the first empty
5773 ;; line as the message header separator used to be used here.
5774 ;; However, since there is the "--text follows this line--" line
5775 ;; normally, it failed in narrowing to the headers and potentially
5776 ;; caused the IDNA encoding on lines that look like headers in
5777 ;; the message body.
5778 (message-narrow-to-headers-or-head)
5779 (message-idna-to-ascii-rhs-1 "From")
5780 (message-idna-to-ascii-rhs-1 "To")
5781 (message-idna-to-ascii-rhs-1 "Reply-To")
5782 (message-idna-to-ascii-rhs-1 "Mail-Reply-To")
5783 (message-idna-to-ascii-rhs-1 "Mail-Followup-To")
5784 (message-idna-to-ascii-rhs-1 "Cc")))))
5786 (defun message-generate-headers (headers)
5787 "Prepare article HEADERS.
5788 Headers already prepared in the buffer are not modified."
5789 (setq headers
(append headers message-required-headers
))
5791 (message-narrow-to-headers)
5792 (let* ((Date (message-make-date))
5793 (Message-ID (message-make-message-id))
5794 (Organization (message-make-organization))
5795 (From (message-make-from))
5796 (Path (message-make-path))
5799 (In-Reply-To (message-make-in-reply-to))
5800 (References (message-make-references))
5802 (Distribution (message-make-distribution))
5803 (Lines (message-make-lines))
5804 (User-Agent message-newsreader
)
5805 (Expires (message-make-expires))
5806 (case-fold-search t
)
5808 header value elem header-string
)
5809 ;; First we remove any old generated headers.
5810 (let ((headers message-deletable-headers
))
5811 (unless (buffer-modified-p)
5812 (setq headers
(delq 'Message-ID
(copy-sequence headers
))))
5814 (goto-char (point-min))
5815 (and (re-search-forward
5816 (concat "^" (symbol-name (car headers
)) ": *") nil t
)
5817 (get-text-property (1+ (match-beginning 0)) 'message-deletable
)
5818 (message-delete-line))
5820 ;; Go through all the required headers and see if they are in the
5821 ;; articles already. If they are not, or are empty, they are
5822 ;; inserted automatically - except for Subject, Newsgroups and
5825 (goto-char (point-min))
5826 (setq elem
(pop headers
))
5828 (if (eq (car elem
) 'optional
)
5829 (setq header
(cdr elem
)
5831 (setq header
(car elem
)))
5833 (setq header-string
(if (stringp header
)
5835 (symbol-name header
)))
5836 (when (or (not (re-search-forward
5838 (regexp-quote (downcase header-string
))
5842 ;; The header was found. We insert a space after the
5843 ;; colon, if there is none.
5844 (if (/= (char-after) ?
) (insert " ") (forward-char 1))
5845 ;; Find out whether the header is empty.
5846 (looking-at "[ \t]*\n[^ \t]")))
5847 ;; So we find out what value we should insert.
5851 (eq (car elem
) 'optional
)
5852 (not (member header-string message-inserted-headers
)))
5853 ;; This is an optional header. If the cdr of this
5854 ;; is something that is nil, then we do not insert
5856 (setq header
(cdr elem
))
5857 (or (and (functionp (cdr elem
))
5858 (funcall (cdr elem
)))
5859 (and (boundp (cdr elem
))
5860 (symbol-value (cdr elem
)))))
5862 ;; The element is a cons. Either the cdr is a
5863 ;; string to be inserted verbatim, or it is a
5864 ;; function, and we insert the value returned from
5866 (or (and (stringp (cdr elem
))
5868 (and (functionp (cdr elem
))
5869 (funcall (cdr elem
)))))
5870 ((and (boundp header
)
5871 (symbol-value header
))
5872 ;; The element is a symbol. We insert the value
5873 ;; of this symbol, if any.
5874 (symbol-value header
))
5875 ((not (message-check-element
5876 (intern (downcase (symbol-name header
)))))
5877 ;; We couldn't generate a value for this header,
5878 ;; so we just ask the user.
5879 (read-from-minibuffer
5880 (format "Empty header for %s; enter value: " header
)))))
5881 ;; Finally insert the header.
5883 (not (equal value
"")))
5887 ;; This header didn't exist, so we insert it.
5888 (goto-char (point-max))
5890 (cdr (assq header message-header-format-alist
))))
5892 (funcall formatter header value
)
5893 (insert header-string
": " value
))
5894 (push header-string message-inserted-headers
)
5895 (goto-char (message-fill-field))
5896 ;; We check whether the value was ended by a
5897 ;; newline. If not, we insert one.
5901 ;; The value of this header was empty, so we clear
5902 ;; totally and insert the new value.
5903 (delete-region (point) (point-at-eol))
5904 ;; If the header is optional, and the header was
5905 ;; empty, we can't insert it anyway.
5907 (push header-string message-inserted-headers
)
5909 (message-fill-field)))
5910 ;; Add the deletable property to the headers that require it.
5911 (and (memq header message-deletable-headers
)
5912 (progn (beginning-of-line) (looking-at "[^:]+: "))
5913 (add-text-properties
5914 (point) (match-end 0)
5915 '(message-deletable t face italic
) (current-buffer)))))))
5916 ;; Insert new Sender if the From is strange.
5917 (let ((from (message-fetch-field "from"))
5918 (sender (message-fetch-field "sender"))
5919 (secure-sender (message-make-sender)))
5921 (not (message-check-element 'sender
))
5924 (cadr (mail-extract-address-components from
)))
5925 (downcase secure-sender
)))
5930 (cadr (mail-extract-address-components sender
)))
5931 (downcase secure-sender
)))))
5932 (goto-char (point-min))
5933 ;; Rename any old Sender headers to Original-Sender.
5934 (when (re-search-forward "^\\(Original-\\)*Sender:" nil t
)
5936 (insert "Original-")
5937 (beginning-of-line))
5938 (when (or (message-news-p)
5939 (string-match "@.+\\.." secure-sender
))
5940 (insert "Sender: " secure-sender
"\n"))))
5942 (message-idna-to-ascii-rhs))))
5944 (defun message-insert-courtesy-copy (message)
5945 "Insert a courtesy message in mail copies of combined messages."
5949 (message-narrow-to-headers)
5950 (when (setq newsgroups
(message-fetch-field "newsgroups"))
5951 (goto-char (point-max))
5952 (insert "Posted-To: " newsgroups
"\n")))
5956 ((string-match "%s" message
)
5957 (insert (format message newsgroups
)))
5959 (insert message
)))))))
5962 ;;; Setting up a message buffer
5965 (defun message-skip-to-next-address ()
5966 (let ((end (save-excursion
5967 (message-next-header)
5970 (when (looking-at ",")
5972 (while (and (not (= (point) end
))
5973 (or (not (eq char ?
,))
5975 (skip-chars-forward "^,\"" (point-max))
5976 (when (eq (setq char
(following-char)) ?
\")
5977 (setq quoted
(not quoted
)))
5978 (unless (= (point) end
)
5980 (skip-chars-forward " \t\n")))
5982 (defun message-fill-address (header value
)
5983 (insert (capitalize (symbol-name header
))
5985 (if (consp value
) (car value
) value
)
5987 (message-fill-field-address))
5989 (defun message-split-line ()
5990 "Split current line, moving portion beyond point vertically down.
5991 If the current line has `message-yank-prefix', insert it on the new line."
5994 (split-line message-yank-prefix
) ;; Emacs 22.1+ supports arg.
5998 (defun message-insert-header (header value
)
5999 (insert (capitalize (symbol-name header
))
6001 (if (consp value
) (car value
) value
)))
6003 (defun message-field-name ()
6005 (goto-char (point-min))
6006 (when (looking-at "\\([^:]+\\):")
6007 (intern (capitalize (match-string 1))))))
6009 (defun message-fill-field ()
6012 (message-narrow-to-field)
6013 (let ((field-name (message-field-name)))
6014 (funcall (or (cadr (assq field-name message-field-fillers
))
6015 'message-fill-field-general
)))
6018 (defun message-fill-field-address ()
6020 (message-skip-to-next-address)
6022 (if (and (> (current-column) 78)
6028 (setq last
(1+ (point))))
6029 (setq last
(1+ (point)))))))
6031 (defun message-fill-field-general ()
6032 (let ((begin (point))
6035 (while (and (search-forward "\n" nil t
)
6037 (replace-match " " t t
))
6038 (fill-region-as-paragraph begin
(point-max))
6039 ;; Tapdance around looong Message-IDs.
6041 (when (looking-at "[ \t]*$")
6042 (message-delete-line))
6044 (search-forward ":" nil t
)
6045 (when (looking-at "\n[ \t]+")
6046 (replace-match " " t t
))
6047 (goto-char (point-max))))
6049 (defun message-shorten-1 (list cut surplus
)
6050 "Cut SURPLUS elements out of LIST, beginning with CUTth one."
6051 (setcdr (nthcdr (- cut
2) list
)
6052 (nthcdr (+ (- cut
2) surplus
1) list
)))
6054 (defun message-shorten-references (header references
)
6055 "Trim REFERENCES to be 21 Message-ID long or less, and fold them.
6056 When sending via news, also check that the REFERENCES are less
6057 than 988 characters long, and if they are not, trim them until
6059 ;; 21 is the number suggested by USEAGE.
6066 (goto-char (point-min))
6067 ;; Cons a list of valid references. GNKSA says we must not include MIDs
6068 ;; with whitespace or missing brackets (7.a "Does not propagate broken
6069 ;; Message-IDs in original References").
6070 (while (re-search-forward "<[^ <]+@[^ <]+>" nil t
)
6071 (push (match-string 0) refs
))
6072 (setq refs
(nreverse refs
)
6073 count
(length refs
)))
6075 ;; If the list has more than MAXCOUNT elements, trim it by
6076 ;; removing the CUTth element and the required number of
6077 ;; elements that follow.
6078 (when (> count maxcount
)
6079 (let ((surplus (- count maxcount
)))
6080 (message-shorten-1 refs cut surplus
)
6081 (decf count surplus
)))
6083 ;; When sending via news, make sure the total folded length will
6084 ;; be less than 998 characters. This is to cater to broken INN
6085 ;; 2.3 which counts the total number of characters in a header
6086 ;; rather than the physical line length of each line, as it should.
6088 ;; This hack should be removed when it's believed than INN 2.3 is
6089 ;; no longer widely used.
6091 ;; At this point the headers have not been generated, thus we use
6092 ;; message-this-is-news directly.
6093 (when message-this-is-news
6096 (message-insert-header
6097 header
(mapconcat #'identity refs
" "))
6099 (message-shorten-1 refs cut
1)))
6100 ;; Finally, collect the references back into a string and insert
6101 ;; it into the buffer.
6102 (message-insert-header header
(mapconcat #'identity refs
" "))))
6104 (defun message-position-point ()
6105 "Move point to where the user probably wants to find it."
6106 (message-narrow-to-headers)
6108 ((re-search-forward "^[^:]+:[ \t]*$" nil t
)
6109 (search-backward ":" )
6112 (if (eq (char-after) ?
)
6116 (goto-char (point-max))
6119 (unless (looking-at "$")
6123 (defcustom message-beginning-of-line t
6124 "Whether \\<message-mode-map>\\[message-beginning-of-line]\
6125 goes to beginning of header values."
6127 :group
'message-buffers
6128 :link
'(custom-manual "(message)Movement")
6131 (defun message-beginning-of-line (&optional n
)
6132 "Move point to beginning of header value or to beginning of line.
6133 The prefix argument N is passed directly to `beginning-of-line'.
6135 This command is identical to `beginning-of-line' if point is
6136 outside the message header or if the option `message-beginning-of-line'
6139 If point is in the message header and on a (non-continued) header
6140 line, move point to the beginning of the header value or the beginning of line,
6141 whichever is closer. If point is already at beginning of line, move point to
6142 beginning of header value. Therefore, repeated calls will toggle point
6143 between beginning of field and beginning of line."
6145 (let ((zrs 'zmacs-region-stays
))
6146 (when (and (featurep 'xemacs
) (interactive-p) (boundp zrs
))
6148 (if (and message-beginning-of-line
6149 (message-point-in-header-p))
6150 (let* ((here (point))
6151 (bol (progn (beginning-of-line n
) (point)))
6152 (eol (point-at-eol))
6153 (eoh (re-search-forward ": *" eol t
)))
6155 (if (and eoh
(or (< eoh here
) (= bol here
)))
6157 (beginning-of-line n
)))
6159 (defun message-buffer-name (type &optional to group
)
6160 "Return a new (unique) buffer name based on TYPE and TO."
6162 ;; Generate a new buffer name The Message Way.
6163 ((memq message-generate-new-buffers
'(unique t
))
6164 (generate-new-buffer-name
6168 (or (car (mail-extract-address-components to
))
6171 (if (and group
(not (string= group
""))) (concat " on " group
) "")
6173 ;; Check whether `message-generate-new-buffers' is a function,
6174 ;; and if so, call it.
6175 ((functionp message-generate-new-buffers
)
6176 (funcall message-generate-new-buffers type to group
))
6177 ((eq message-generate-new-buffers
'unsent
)
6178 (generate-new-buffer-name
6179 (concat "*unsent " type
6182 (or (car (mail-extract-address-components to
))
6185 (if (and group
(not (string= group
""))) (concat " on " group
) "")
6187 ;; Search for the existing message buffer with the specified name.
6189 (let* ((new (if (eq message-generate-new-buffers
'standard
)
6190 (generate-new-buffer-name (concat "*" type
" message*"))
6191 (let ((message-generate-new-buffers 'unique
))
6192 (message-buffer-name type to group
))))
6193 (regexp (concat "\\`"
6195 (if (string-match "<[0-9]+>\\'" new
)
6196 (substring new
0 (match-beginning 0))
6198 "\\(?:<\\([0-9]+\\)>\\)?\\'"))
6199 (case-fold-search nil
))
6206 (when (and (string-match regexp
(setq b
(buffer-name b
)))
6207 (eq (with-current-buffer b major-mode
)
6209 (cons (string-to-number (or (match-string 1 b
) "1"))
6212 'car-less-than-car
)))
6215 (defun message-pop-to-buffer (name &optional switch-function
)
6216 "Pop to buffer NAME, and warn if it already exists and is modified."
6217 (let ((buffer (get-buffer name
)))
6219 (buffer-name buffer
))
6220 (let ((window (get-buffer-window buffer
0)))
6222 ;; Raise the frame already displaying the message buffer.
6224 (gnus-select-frame-set-input-focus (window-frame window
))
6225 (select-window window
))
6226 (funcall (or switch-function
'pop-to-buffer
) buffer
)
6227 (set-buffer buffer
))
6228 (when (and (buffer-modified-p)
6231 "Message already being composed; erase? ")
6233 (error "Message being composed")))
6234 (funcall (or switch-function
'pop-to-buffer
) name
)
6239 (defun message-do-send-housekeeping ()
6240 "Kill old message buffers."
6241 ;; We might have sent this buffer already. Delete it from the
6243 (setq message-buffer-list
(delq (current-buffer) message-buffer-list
))
6244 (while (and message-max-buffers
6246 (>= (length message-buffer-list
) message-max-buffers
))
6247 ;; Kill the oldest buffer -- unless it has been changed.
6248 (let ((buffer (pop message-buffer-list
)))
6249 (when (and (buffer-name buffer
)
6250 (not (buffer-modified-p buffer
)))
6251 (kill-buffer buffer
))))
6252 ;; Rename the buffer.
6253 (if message-send-rename-function
6254 (funcall message-send-rename-function
)
6255 ;; Note: mail-abbrevs of XEmacs renames buffer name behind Gnus.
6257 "\\`\\*\\(sent \\|unsent \\)?\\(.+\\)\\*[^\\*]*\\|\\`mail to "
6259 (let ((name (match-string 2 (buffer-name)))
6261 (if (not (or (null name
)
6262 (string-equal name
"mail")
6263 (string-equal name
"posting")))
6264 (setq name
(concat "*sent " name
"*"))
6265 (message-narrow-to-headers)
6266 (setq to
(message-fetch-field "to"))
6267 (setq group
(message-fetch-field "newsgroups"))
6271 (to (concat "*sent mail to "
6272 (or (car (mail-extract-address-components to
))
6274 ((and group
(not (string= group
"")))
6275 (concat "*sent posting on " group
"*"))
6276 (t "*sent mail*"))))
6277 (unless (string-equal name
(buffer-name))
6278 (rename-buffer name t
)))))
6279 ;; Push the current buffer onto the list.
6280 (when message-max-buffers
6281 (setq message-buffer-list
6282 (nconc message-buffer-list
(list (current-buffer))))))
6284 (defun message-mail-user-agent ()
6286 ((not message-mail-user-agent
) nil
)
6287 ((eq message-mail-user-agent t
) mail-user-agent
)
6288 (t message-mail-user-agent
))))
6289 (if (memq mua
'(message-user-agent gnus-user-agent
))
6293 ;; YANK-ACTION, if non-nil, can be a buffer or a yank action of the
6294 ;; form (FUNCTION . ARGS).
6295 (defun message-setup (headers &optional yank-action actions
6296 continue switch-function
)
6297 (let ((mua (message-mail-user-agent))
6299 (if (not (and message-this-is-mail mua
))
6300 (message-setup-1 headers yank-action actions
)
6301 (setq headers
(copy-sequence headers
))
6302 (setq field
(assq 'Subject headers
))
6304 (setq subject
(cdr field
))
6305 (setq headers
(delq field headers
)))
6306 (setq field
(assq 'To headers
))
6308 (setq to
(cdr field
))
6309 (setq headers
(delq field headers
)))
6310 (let ((mail-user-agent mua
))
6311 (compose-mail to subject
6312 (mapcar (lambda (item)
6314 (format "%s" (car item
))
6317 continue switch-function
6318 (if (bufferp yank-action
)
6319 (list 'insert-buffer yank-action
)
6323 (defun message-headers-to-generate (headers included-headers excluded-headers
)
6324 "Return a list that includes all headers from HEADERS.
6325 If INCLUDED-HEADERS is a list, just include those headers. If it is
6326 t, include all headers. In any case, headers from EXCLUDED-HEADERS
6330 (dolist (header headers
)
6331 (setq header-name
(cond
6332 ((and (consp header
)
6333 (eq (car header
) 'optional
))
6334 ;; On the form (optional . Header)
6337 ;; On the form (Header . function)
6342 (when (and (not (memq header-name excluded-headers
))
6343 (or (eq included-headers t
)
6344 (memq header-name included-headers
)))
6345 (push header result
)))
6348 (defun message-setup-1 (headers &optional yank-action actions
)
6349 (dolist (action actions
)
6351 (add-to-list 'message-send-actions
6352 `(apply ',(car action
) ',(cdr action
)))))
6353 (setq message-reply-buffer
6354 (if (and (consp yank-action
)
6355 (eq (car yank-action
) 'insert-buffer
))
6358 (goto-char (point-min))
6359 ;; Insert all the headers.
6362 (alist message-header-format-alist
))
6364 (unless (assq (caar h
) message-header-format-alist
)
6365 (push (list (caar h
)) alist
))
6369 (delete-region (point) (progn (forward-line -
1) (point)))
6370 (when message-default-headers
6372 (if (functionp message-default-headers
)
6373 (funcall message-default-headers
)
6374 message-default-headers
))
6375 (or (bolp) (insert ?
\n)))
6376 (insert mail-header-separator
"\n")
6378 (when (message-news-p)
6379 (when message-default-news-headers
6380 (insert message-default-news-headers
)
6381 (or (bolp) (insert ?
\n)))
6382 (when message-generate-headers-first
6383 (message-generate-headers
6384 (message-headers-to-generate
6385 (append message-required-news-headers
6386 message-required-headers
)
6387 message-generate-headers-first
6388 '(Lines Subject
)))))
6389 (when (message-mail-p)
6390 (when message-default-mail-headers
6391 (insert message-default-mail-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-mail-headers
6397 message-required-headers
)
6398 message-generate-headers-first
6399 '(Lines Subject
)))))
6400 (run-hooks 'message-signature-setup-hook
)
6401 (message-insert-signature)
6403 (message-narrow-to-headers)
6404 (run-hooks 'message-header-setup-hook
))
6405 (setq buffer-undo-list nil
)
6406 (when message-generate-hashcash
6407 ;; Generate hashcash headers for recipients already known
6408 (mail-add-payment-async))
6409 ;; Gnus posting styles are applied via buffer-local `message-setup-hook'
6411 (run-hooks 'message-setup-hook
)
6412 ;; Do this last to give it precedence over posting styles, etc.
6413 (when (message-mail-p)
6415 (message-narrow-to-headers)
6416 (if message-alternative-emails
6417 (message-use-alternative-email-as-from))))
6418 (message-position-point)
6419 ;; Allow correct handling of `message-checksum' in `message-yank-original':
6420 (set-buffer-modified-p nil
)
6423 (defun message-set-auto-save-file-name ()
6424 "Associate the message buffer with a file in the drafts directory."
6425 (when message-auto-save-directory
6426 (unless (file-directory-p
6427 (directory-file-name message-auto-save-directory
))
6428 (make-directory message-auto-save-directory t
))
6430 (setq message-draft-article
6431 (nndraft-request-associate-buffer "drafts"))
6433 ;; If Gnus were alive, draft messages would be saved in the drafts folder.
6434 ;; But Gnus is not alive, so arrange to save the draft message in a
6435 ;; regular file in message-auto-save-directory. Append a unique
6436 ;; time-based suffix to the filename to allow multiple drafts to be saved
6437 ;; simultaneously without overwriting each other (which mimics the
6438 ;; functionality of the Gnus drafts folder).
6439 (setq buffer-file-name
(expand-file-name
6441 (if (memq system-type
6442 '(ms-dos windows-nt cygwin
))
6445 (format-time-string "-%Y%m%d-%H%M%S"))
6446 message-auto-save-directory
))
6447 (setq buffer-auto-save-file-name
(make-auto-save-file-name)))
6448 (clear-visited-file-modtime)
6449 (setq buffer-file-coding-system message-draft-coding-system
)))
6451 (defun message-disassociate-draft ()
6452 "Disassociate the message buffer from the drafts directory."
6453 (when message-draft-article
6454 (nndraft-request-expire-articles
6455 (list message-draft-article
) "drafts" nil t
)))
6457 (defun message-insert-headers ()
6458 "Generate the headers for the article."
6462 (message-narrow-to-headers)
6463 (when (message-news-p)
6464 (message-generate-headers
6467 (copy-sequence message-required-news-headers
)))))
6468 (when (message-mail-p)
6469 (message-generate-headers
6472 (copy-sequence message-required-mail-headers
))))))))
6477 ;;; Commands for interfacing with message
6481 (defun message-mail (&optional to subject
6482 other-headers continue switch-function
6483 yank-action send-actions
)
6484 "Start editing a mail message to be sent.
6485 OTHER-HEADERS is an alist of header/value pairs. CONTINUE says whether
6486 to continue editing a message already being composed. SWITCH-FUNCTION
6487 is a function used to switch to and display the mail buffer."
6489 (let ((message-this-is-mail t
))
6490 (unless (message-mail-user-agent)
6491 (message-pop-to-buffer
6492 ;; Search for the existing message buffer if `continue' is non-nil.
6493 (let ((message-generate-new-buffers
6494 (when (or (not continue
)
6495 (eq message-generate-new-buffers
'standard
)
6496 (functionp message-generate-new-buffers
))
6497 message-generate-new-buffers
)))
6498 (message-buffer-name "mail" to
))
6502 `((To .
,(or to
"")) (Subject .
,(or subject
"")))
6503 (when other-headers other-headers
))
6504 yank-action send-actions continue switch-function
)
6505 ;; FIXME: Should return nil if failure.
6509 (defun message-news (&optional newsgroups subject
)
6510 "Start editing a news article to be sent."
6512 (let ((message-this-is-news t
))
6513 (message-pop-to-buffer (message-buffer-name "posting" nil newsgroups
))
6514 (message-setup `((Newsgroups .
,(or newsgroups
""))
6515 (Subject .
,(or subject
""))))))
6517 (defun message-alter-recipients-discard-bogus-full-name (addrcell)
6518 "Discard mail address in full names.
6519 When the full name in reply headers contains the mail
6520 address (e.g. \"foo@bar <foo@bar>\"), discard full name.
6521 ADDRCELL is a cons cell where the car is the mail address and the
6522 cdr is the complete address (full name and mail address)."
6523 (if (string-match (concat (regexp-quote (car addrcell
)) ".*"
6524 (regexp-quote (car addrcell
)))
6526 (cons (car addrcell
) (car addrcell
))
6529 (defcustom message-alter-recipients-function nil
6530 "Function called to allow alteration of reply header structures.
6531 It is called in `message-get-reply-headers' for each recipient.
6532 The function is called with one parameter, a cons cell ..."
6533 :type
'(choice (const :tag
"None" nil
)
6534 (const :tag
"Discard bogus full name"
6535 message-alter-recipients-discard-bogus-full-name
)
6537 :version
"23.1" ;; No Gnus
6538 :group
'message-headers
)
6540 (defun message-get-reply-headers (wide &optional to-address address-headers
)
6541 (let (follow-to mct never-mct to cc author mft recipients extra
)
6542 ;; Find all relevant headers we need.
6544 (message-narrow-to-headers-or-head)
6545 ;; Gmane renames "To". Look at "Original-To", too, if it is present in
6546 ;; message-header-synonyms.
6547 (setq to
(or (message-fetch-field "to")
6548 (and (loop for synonym in message-header-synonyms
6549 when
(memq 'Original-To synonym
)
6551 (message-fetch-field "original-to")))
6552 cc
(message-fetch-field "cc")
6553 extra
(when message-extra-wide-headers
6554 (mapconcat 'identity
6555 (mapcar 'message-fetch-field
6556 message-extra-wide-headers
)
6558 mct
(message-fetch-field "mail-copies-to")
6559 author
(or (message-fetch-field "mail-reply-to")
6560 (message-fetch-field "reply-to")
6561 (message-fetch-field "from")
6563 mft
(and message-use-mail-followup-to
6564 (message-fetch-field "mail-followup-to"))))
6566 ;; Handle special values of Mail-Copies-To.
6568 (cond ((or (equal (downcase mct
) "never")
6569 (equal (downcase mct
) "nobody"))
6572 ((or (equal (downcase mct
) "always")
6573 (equal (downcase mct
) "poster"))
6574 (setq mct author
))))
6577 ;; Build (textual) list of new recipient addresses.
6580 (setq recipients
(concat ", " to-address
))
6581 ;; If the author explicitly asked for a copy, we don't deny it to them.
6582 (if mct
(setq recipients
(concat recipients
", " mct
))))
6584 (setq recipients
(concat ", " author
)))
6586 (dolist (header address-headers
)
6587 (let ((value (message-fetch-field header
)))
6589 (setq recipients
(concat recipients
", " value
))))))
6591 (string-match "[^ \t,]" mft
)
6592 (or (not (eq message-use-mail-followup-to
'ask
))
6593 (message-y-or-n-p "Obey Mail-Followup-To? " t
"\
6594 You should normally obey the Mail-Followup-To: header. In this
6595 article, it has the value of
6599 which directs your response to " (if (string-match "," mft
)
6600 "the specified addresses"
6601 "that address only") ".
6603 Most commonly, Mail-Followup-To is used by a mailing list poster to
6604 express that responses should be sent to just the list, and not the
6607 If a message is posted to several mailing lists, Mail-Followup-To may
6608 also be used to direct the following discussion to one list only,
6609 because discussions that are spread over several lists tend to be
6610 fragmented and very difficult to follow.
6612 Also, some source/announcement lists are not intended for discussion;
6613 responses here are directed to other addresses.
6615 You may customize the variable `message-use-mail-followup-to', if you
6616 want to get rid of this query permanently.")))
6617 (setq recipients
(concat ", " mft
)))
6619 (setq recipients
(if never-mct
"" (concat ", " author
)))
6620 (if to
(setq recipients
(concat recipients
", " to
)))
6621 (if cc
(setq recipients
(concat recipients
", " cc
)))
6622 (if extra
(setq recipients
(concat recipients
", " extra
)))
6623 (if mct
(setq recipients
(concat recipients
", " mct
)))))
6624 (if (>= (length recipients
) 2)
6625 ;; Strip the leading ", ".
6626 (setq recipients
(substring recipients
2)))
6627 ;; Squeeze whitespace.
6628 (while (string-match "[ \t][ \t]+" recipients
)
6629 (setq recipients
(replace-match " " t t recipients
)))
6630 ;; Remove addresses that match `rmail-dont-reply-to-names'.
6631 (let ((rmail-dont-reply-to-names (message-dont-reply-to-names)))
6632 (setq recipients
(rmail-dont-reply-to recipients
)))
6633 ;; Perhaps "Mail-Copies-To: never" removed the only address?
6634 (if (string-equal recipients
"")
6635 (setq recipients author
))
6636 ;; Convert string to a list of (("foo@bar" . "Name <Foo@BAR>") ...).
6640 (if message-alter-recipients-function
6641 (funcall message-alter-recipients-function
6642 (cons (downcase (mail-strip-quoted-names addr
))
6644 (cons (downcase (mail-strip-quoted-names addr
)) addr
)))
6645 (message-tokenize-header recipients
)))
6646 ;; Remove first duplicates. (Why not all duplicates? Is this a bug?)
6647 (let ((s recipients
))
6649 (setq recipients
(delq (assoc (car (pop s
)) s
) recipients
))))
6651 ;; Remove hierarchical lists that are contained within each other,
6652 ;; if message-hierarchical-addresses is defined.
6653 (when message-hierarchical-addresses
6654 (let ((plain-addrs (mapcar 'car recipients
))
6657 (setq subaddrs
(assoc (car plain-addrs
)
6658 message-hierarchical-addresses
)
6659 plain-addrs
(cdr plain-addrs
))
6661 (setq subaddrs
(cdr subaddrs
))
6663 (setq recip
(assoc (car subaddrs
) recipients
)
6664 subaddrs
(cdr subaddrs
))
6666 (setq recipients
(delq recip recipients
))))))))
6668 (setq recipients
(message-prune-recipients recipients
))
6670 ;; Build the header alist. Allow the user to be asked whether
6671 ;; or not to reply to all recipients in a wide reply.
6672 (setq follow-to
(list (cons 'To
(cdr (pop recipients
)))))
6673 (when (and recipients
6674 (or (not message-wide-reply-confirm-recipients
)
6675 (y-or-n-p "Reply to all recipients? ")))
6676 (setq recipients
(mapconcat
6677 (lambda (addr) (cdr addr
)) recipients
", "))
6678 (if (string-match "^ +" recipients
)
6679 (setq recipients
(substring recipients
(match-end 0))))
6680 (push (cons 'Cc recipients
) follow-to
)))
6683 (defun message-prune-recipients (recipients)
6684 (dolist (rule message-prune-recipient-rules
)
6685 (let ((match (car rule
))
6688 (dolist (recipient recipients
)
6689 (setq address
(car recipient
))
6690 (when (string-match match address
)
6691 (setq dup-match
(replace-match (cadr rule
) nil nil address
))
6692 (dolist (recipient recipients
)
6693 ;; Don't delete the address that triggered this.
6694 (when (and (not (eq address
(car recipient
)))
6695 (string-match dup-match
(car recipient
)))
6696 (setq recipients
(delq recipient recipients
))))))))
6699 (defcustom message-simplify-subject-functions
6700 '(message-strip-list-identifiers
6701 message-strip-subject-re
6702 message-strip-subject-trailing-was
6703 message-strip-subject-encoded-words
)
6704 "List of functions taking a string argument that simplify subjects.
6705 The functions are applied when replying to a message.
6707 Useful functions to put in this list include:
6708 `message-strip-list-identifiers', `message-strip-subject-re',
6709 `message-strip-subject-trailing-was', and
6710 `message-strip-subject-encoded-words'."
6711 :version
"22.1" ;; Gnus 5.10.9
6712 :group
'message-various
6713 :type
'(repeat function
))
6715 (defun message-simplify-subject (subject &optional functions
)
6716 "Return simplified SUBJECT."
6719 (setq functions message-simplify-subject-functions
))
6720 (when (and (memq 'message-strip-list-identifiers functions
)
6721 gnus-list-identifiers
)
6722 (setq subject
(message-strip-list-identifiers subject
)))
6723 (when (memq 'message-strip-subject-re functions
)
6724 (setq subject
(concat "Re: " (message-strip-subject-re subject
))))
6725 (when (and (memq 'message-strip-subject-trailing-was functions
)
6726 message-subject-trailing-was-query
)
6727 (setq subject
(message-strip-subject-trailing-was subject
)))
6728 (when (memq 'message-strip-subject-encoded-words functions
)
6729 (setq subject
(message-strip-subject-encoded-words subject
)))
6733 (defun message-reply (&optional to-address wide
)
6734 "Start editing a reply to the article in the current buffer."
6736 (require 'gnus-sum
) ; for gnus-list-identifiers
6737 (let ((cur (current-buffer))
6738 from subject date reply-to to cc
6739 references message-id follow-to
6740 (inhibit-point-motion-hooks t
)
6741 (message-this-is-mail t
)
6744 (message-narrow-to-head-1)
6745 ;; Allow customizations to have their say.
6747 ;; This is a regular reply.
6748 (when (functionp message-reply-to-function
)
6750 (setq follow-to
(funcall message-reply-to-function
))))
6751 ;; This is a followup.
6752 (when (functionp message-wide-reply-to-function
)
6755 (funcall message-wide-reply-to-function
)))))
6756 (setq message-id
(message-fetch-field "message-id" t
)
6757 references
(message-fetch-field "references")
6758 date
(message-fetch-field "date")
6759 from
(or (message-fetch-field "from") "nobody")
6760 subject
(or (message-fetch-field "subject") "none"))
6762 ;; Strip list identifiers, "Re: ", and "was:"
6763 (setq subject
(message-simplify-subject subject
))
6765 (when (and (setq gnus-warning
(message-fetch-field "gnus-warning"))
6766 (string-match "<[^>]+>" gnus-warning
))
6767 (setq message-id
(match-string 0 gnus-warning
)))
6770 (setq follow-to
(message-get-reply-headers wide to-address
))))
6772 (unless (message-mail-user-agent)
6773 (message-pop-to-buffer
6774 (message-buffer-name
6775 (if wide
"wide reply" "reply") from
6776 (if wide to-address nil
))))
6778 (setq message-reply-headers
6779 (vector 0 subject from date message-id references
0 0 ""))
6782 `((Subject .
,subject
)
6787 (defun message-wide-reply (&optional to-address
)
6788 "Make a \"wide\" reply to the message in the current buffer."
6790 (message-reply to-address t
))
6793 (defun message-followup (&optional to-newsgroups
)
6794 "Follow up to the message in the current buffer.
6795 If TO-NEWSGROUPS, use that as the new Newsgroups line."
6797 (require 'gnus-sum
) ; for gnus-list-identifiers
6798 (let ((cur (current-buffer))
6799 from subject date reply-to mrt mct
6800 references message-id follow-to
6801 (inhibit-point-motion-hooks t
)
6802 (message-this-is-news t
)
6803 followup-to distribution newsgroups gnus-warning posted-to
)
6806 (goto-char (point-min))
6807 (if (search-forward "\n\n" nil t
)
6810 (when (functionp message-followup-to-function
)
6812 (funcall message-followup-to-function
)))
6813 (setq from
(message-fetch-field "from")
6814 date
(message-fetch-field "date")
6815 subject
(or (message-fetch-field "subject") "none")
6816 references
(message-fetch-field "references")
6817 message-id
(message-fetch-field "message-id" t
)
6818 followup-to
(message-fetch-field "followup-to")
6819 newsgroups
(message-fetch-field "newsgroups")
6820 posted-to
(message-fetch-field "posted-to")
6821 reply-to
(message-fetch-field "reply-to")
6822 mrt
(message-fetch-field "mail-reply-to")
6823 distribution
(message-fetch-field "distribution")
6824 mct
(message-fetch-field "mail-copies-to"))
6825 (when (and (setq gnus-warning
(message-fetch-field "gnus-warning"))
6826 (string-match "<[^>]+>" gnus-warning
))
6827 (setq message-id
(match-string 0 gnus-warning
)))
6828 ;; Remove bogus distribution.
6829 (when (and (stringp distribution
)
6830 (let ((case-fold-search t
))
6831 (string-match "world" distribution
)))
6832 (setq distribution nil
))
6833 ;; Strip list identifiers, "Re: ", and "was:"
6834 (setq subject
(message-simplify-subject subject
))
6837 (message-pop-to-buffer (message-buffer-name "followup" from newsgroups
))
6839 (setq message-reply-headers
6840 (vector 0 subject from date message-id references
0 0 ""))
6843 `((Subject .
,subject
)
6846 (list (cons 'Newsgroups to-newsgroups
)))
6847 (follow-to follow-to
)
6848 ((and followup-to message-use-followup-to
)
6851 ((equal (downcase followup-to
) "poster")
6852 (if (or (eq message-use-followup-to
'use
)
6853 (message-y-or-n-p "Obey Followup-To: poster? " t
"\
6854 You should normally obey the Followup-To: header.
6856 `Followup-To: poster' sends your response via e-mail instead of news.
6858 A typical situation where `Followup-To: poster' is used is when the poster
6859 does not read the newsgroup, so he wouldn't see any replies sent to it.
6861 You may customize the variable `message-use-followup-to', if you
6862 want to get rid of this query permanently."))
6864 (setq message-this-is-news nil
)
6865 (cons 'To
(or mrt reply-to from
"")))
6866 (cons 'Newsgroups newsgroups
)))
6868 (if (or (equal followup-to newsgroups
)
6869 (not (eq message-use-followup-to
'ask
))
6871 (concat "Obey Followup-To: " followup-to
"? ") t
"\
6872 You should normally obey the Followup-To: header.
6874 `Followup-To: " followup-to
"'
6875 directs your response to " (if (string-match "," followup-to
)
6876 "the specified newsgroups"
6877 "that newsgroup only") ".
6879 If a message is posted to several newsgroups, Followup-To is often
6880 used to direct the following discussion to one newsgroup only,
6881 because discussions that are spread over several newsgroup tend to
6882 be fragmented and very difficult to follow.
6884 Also, some source/announcement newsgroups are not intended for discussion;
6885 responses here are directed to other newsgroups.
6887 You may customize the variable `message-use-followup-to', if you
6888 want to get rid of this query permanently."))
6889 (cons 'Newsgroups followup-to
)
6890 (cons 'Newsgroups newsgroups
))))))
6892 `((Newsgroups .
,posted-to
)))
6894 `((Newsgroups .
,newsgroups
))))
6895 ,@(and distribution
(list (cons 'Distribution distribution
)))
6897 (not (or (equal (downcase mct
) "never")
6898 (equal (downcase mct
) "nobody"))))
6899 (list (cons 'Cc
(if (or (equal (downcase mct
) "always")
6900 (equal (downcase mct
) "poster"))
6901 (or mrt reply-to from
"")
6906 (defun message-is-yours-p ()
6907 "Non-nil means current article is yours.
6908 If you have added 'cancel-messages to `message-shoot-gnksa-feet', all articles
6909 are yours except those that have Cancel-Lock header not belonging to you.
6910 Instead of shooting GNKSA feet, you should modify `message-alternative-emails'
6911 regexp to match all of yours addresses."
6912 ;; Canlock-logic as suggested by Per Abrahamsen
6913 ;; <abraham@dina.kvl.dk>
6915 ;; IF article has cancel-lock THEN
6916 ;; IF we can verify it THEN
6919 ;; error: cancellock: article is not yours
6921 ;; Use old rules, comparing sender...
6924 (message-narrow-to-head-1)
6925 (if (message-fetch-field "Cancel-Lock")
6926 (if (null (canlock-verify))
6928 (error "Failed to verify Cancel-lock: This article is not yours"))
6931 (message-gnksa-enable-p 'cancel-messages
)
6932 (and (setq sender
(message-fetch-field "sender"))
6933 (string-equal (downcase sender
)
6934 (downcase (message-make-sender))))
6935 ;; Email address in From field equals to our address
6936 (and (setq from
(message-fetch-field "from"))
6938 (downcase (car (mail-header-parse-address from
)))
6939 (downcase (car (mail-header-parse-address
6940 (message-make-from))))))
6941 ;; Email address in From field matches
6942 ;; 'message-alternative-emails' regexp
6944 message-alternative-emails
6946 message-alternative-emails
6947 (car (mail-header-parse-address from
))))))))))
6950 (defun message-cancel-news (&optional arg
)
6951 "Cancel an article you posted.
6952 If ARG, allow editing of the cancellation message."
6954 (unless (message-news-p)
6955 (error "This is not a news article; canceling is impossible"))
6956 (let (from newsgroups message-id distribution buf
)
6958 ;; Get header info from original article.
6960 (message-narrow-to-head-1)
6961 (setq from
(message-fetch-field "from")
6962 newsgroups
(message-fetch-field "newsgroups")
6963 message-id
(message-fetch-field "message-id" t
)
6964 distribution
(message-fetch-field "distribution")))
6965 ;; Make sure that this article was written by the user.
6966 (unless (message-is-yours-p)
6967 (error "This article is not yours"))
6968 (when (yes-or-no-p "Do you really want to cancel this article? ")
6969 ;; Make control message.
6972 (setq buf
(set-buffer (get-buffer-create " *message cancel*"))))
6974 (insert "Newsgroups: " newsgroups
"\n"
6976 "Subject: cmsg cancel " message-id
"\n"
6977 "Control: cancel " message-id
"\n"
6979 (concat "Distribution: " distribution
"\n")
6981 mail-header-separator
"\n"
6982 message-cancel-message
)
6983 (run-hooks 'message-cancel-hook
)
6985 (message "Canceling your article...")
6986 (if (let ((message-syntax-checks
6987 'dont-check-for-anything-just-trust-me
))
6988 (funcall message-send-news-function
))
6989 (message "Canceling your article...done"))
6990 (kill-buffer buf
))))))
6993 (defun message-supersede ()
6994 "Start composing a message to supersede the current message.
6995 This is done simply by taking the old article and adding a Supersedes
6996 header line with the old Message-ID."
6998 (let ((cur (current-buffer)))
6999 ;; Check whether the user owns the article that is to be superseded.
7000 (unless (message-is-yours-p)
7001 (error "This article is not yours"))
7002 ;; Get a normal message buffer.
7003 (message-pop-to-buffer (message-buffer-name "supersede"))
7004 (insert-buffer-substring cur
)
7006 (message-narrow-to-head-1)
7007 ;; Remove unwanted headers.
7008 (when message-ignored-supersedes-headers
7009 (message-remove-header message-ignored-supersedes-headers t
))
7010 (goto-char (point-min))
7011 (if (not (re-search-forward "^Message-ID: " nil t
))
7012 (error "No Message-ID in this article")
7013 (replace-match "Supersedes: " t t
))
7014 (goto-char (point-max))
7015 (insert mail-header-separator
)
7020 (defun message-recover ()
7021 "Reread contents of current buffer from its last auto-save file."
7023 (let ((file-name (make-auto-save-file-name)))
7024 (cond ((save-window-excursion
7025 (with-output-to-temp-buffer "*Directory*"
7026 (with-current-buffer standard-output
7027 (fundamental-mode)) ; for Emacs 20.4+
7028 (buffer-disable-undo standard-output
)
7029 (let ((default-directory "/"))
7031 "ls" nil standard-output nil
"-l" file-name
)))
7032 (yes-or-no-p (format "Recover auto save file %s? " file-name
)))
7033 (let ((buffer-read-only nil
))
7035 (insert-file-contents file-name nil
)))
7036 (t (error "message-recover cancelled")))))
7038 ;;; Washing Subject:
7040 (defun message-wash-subject (subject)
7041 "Remove junk like \"Re:\", \"(fwd)\", etc. added to subject string SUBJECT.
7042 Previous forwarders, replyers, etc. may add it."
7045 (goto-char (point-min))
7046 ;; strip Re/Fwd stuff off the beginning
7047 (while (re-search-forward
7048 "\\([Rr][Ee]:\\|[Ff][Ww][Dd]\\(\\[[0-9]*\\]\\)?:\\|[Ff][Ww]:\\)" nil t
)
7051 ;; and gnus-style forwards [foo@bar.com] subject
7052 (goto-char (point-min))
7053 (while (re-search-forward "\\[[^ \t]*\\(@\\|\\.\\)[^ \t]*\\]" nil t
)
7057 (goto-char (point-max))
7058 (while (re-search-backward "([Ff][Ww][Dd])" nil t
)
7061 ;; and finally, any whitespace that was left-over
7062 (goto-char (point-min))
7063 (while (re-search-forward "^[ \t]+" nil t
)
7065 (goto-char (point-max))
7066 (while (re-search-backward "[ \t]+$" nil t
)
7071 ;;; Forwarding messages.
7073 (defvar message-forward-decoded-p nil
7074 "Non-nil means the original message is decoded.")
7076 (defun message-forward-subject-name-subject (subject)
7077 "Generate a SUBJECT for a forwarded message.
7078 The form is: [Source] Subject, where if the original message was mail,
7079 Source is the name of the sender, and if the original message was
7080 news, Source is the list of newsgroups is was posted to."
7081 (let* ((group (message-fetch-field "newsgroups"))
7082 (from (message-fetch-field "from"))
7085 (gnus-group-decoded-name group
)
7087 (car (gnus-extract-address-components from
))
7088 (cadr (gnus-extract-address-components from
))))
7091 (if message-forward-decoded-p
7093 (mail-decode-encoded-word-string prefix
))
7096 (defun message-forward-subject-author-subject (subject)
7097 "Generate a SUBJECT for a forwarded message.
7098 The form is: [Source] Subject, where if the original message was mail,
7099 Source is the sender, and if the original message was news, Source is
7100 the list of newsgroups is was posted to."
7101 (let* ((group (message-fetch-field "newsgroups"))
7104 (gnus-group-decoded-name group
)
7105 (or (message-fetch-field "from")
7108 (if message-forward-decoded-p
7110 (mail-decode-encoded-word-string prefix
))
7113 (defun message-forward-subject-fwd (subject)
7114 "Generate a SUBJECT for a forwarded message.
7115 The form is: Fwd: Subject, where Subject is the original subject of
7117 (if (string-match "^Fwd: " subject
)
7119 (concat "Fwd: " subject
)))
7121 (defun message-make-forward-subject ()
7122 "Return a Subject header suitable for the message in the current buffer."
7125 (message-narrow-to-head-1)
7126 (let ((funcs message-make-forward-subject-function
)
7127 (subject (message-fetch-field "Subject")))
7130 (if message-forward-decoded-p
7132 (mail-decode-encoded-word-string subject
))
7134 (when message-wash-forwarded-subjects
7135 (setq subject
(message-wash-subject subject
)))
7136 ;; Make sure funcs is a list.
7139 (setq funcs
(list funcs
)))
7140 ;; Apply funcs in order, passing subject generated by previous
7141 ;; func to the next one.
7142 (dolist (func funcs
)
7143 (when (functionp func
)
7144 (setq subject
(funcall func subject
))))
7147 (defvar gnus-article-decoded-p
)
7151 (defun message-forward (&optional news digest
)
7152 "Forward the current message via mail.
7153 Optional NEWS will use news to forward instead of mail.
7154 Optional DIGEST will use digest to forward."
7156 (let* ((cur (current-buffer))
7157 (message-forward-decoded-p
7158 (if (local-variable-p 'gnus-article-decoded-p
(current-buffer))
7159 gnus-article-decoded-p
;; In an article buffer.
7160 message-forward-decoded-p
))
7161 (subject (message-make-forward-subject)))
7163 (message-news nil subject
)
7164 (message-mail nil subject
))
7165 (message-forward-make-body cur digest
)))
7167 (defun message-forward-make-body-plain (forward-buffer)
7169 "\n-------------------- Start of forwarded message --------------------\n")
7171 (contents (with-current-buffer forward-buffer
(buffer-string)))
7173 (unless (featurep 'xemacs
)
7174 (unless (mm-multibyte-string-p contents
)
7175 (error "Attempt to insert unibyte string from the buffer \"%s\"\
7176 to the multibyte buffer \"%s\""
7177 (if (bufferp forward-buffer
)
7178 (buffer-name forward-buffer
)
7181 (insert (mm-with-multibyte-buffer
7184 (goto-char (point-min))
7185 (when (looking-at "From ")
7186 (replace-match "X-From-Line: "))
7188 (unless (bolp) (insert "\n"))
7191 "-------------------- End of forwarded message --------------------\n")
7192 (message-remove-ignored-headers b e
)))
7194 (defun message-remove-ignored-headers (b e
)
7195 (when message-forward-ignored-headers
7197 (narrow-to-region b e
)
7199 (narrow-to-region (point)
7200 (or (search-forward "\n\n" nil t
) (point)))
7201 (let ((ignored (if (stringp message-forward-ignored-headers
)
7202 (list message-forward-ignored-headers
)
7203 message-forward-ignored-headers
)))
7204 (dolist (elem ignored
)
7205 (message-remove-header elem t
))))))
7207 (defun message-forward-make-body-mime (forward-buffer)
7209 (insert "\n\n<#part type=message/rfc822 disposition=inline raw=t>\n")
7211 (narrow-to-region (point) (point))
7212 (mml-insert-buffer forward-buffer
)
7213 (goto-char (point-min))
7214 (when (looking-at "From ")
7215 (replace-match "X-From-Line: "))
7216 (goto-char (point-max)))
7217 (insert "<#/part>\n")
7218 ;; Consider there is no illegible text.
7219 (add-text-properties
7221 `(no-illegible-text t rear-nonsticky t start-open t
))))
7223 (defun message-forward-make-body-mml (forward-buffer)
7224 (insert "\n\n<#mml type=message/rfc822 disposition=inline>\n")
7225 (let ((b (point)) e
)
7226 (if (not message-forward-decoded-p
)
7227 (let ((contents (with-current-buffer forward-buffer
(buffer-string))))
7228 (unless (featurep 'xemacs
)
7229 (unless (mm-multibyte-string-p contents
)
7230 (error "Attempt to insert unibyte string from the buffer \"%s\"\
7231 to the multibyte buffer \"%s\""
7232 (if (bufferp forward-buffer
)
7233 (buffer-name forward-buffer
)
7236 (insert (mm-with-multibyte-buffer
7239 (goto-char (point-min))
7240 (when (looking-at "From ")
7241 (replace-match "X-From-Line: "))
7244 (narrow-to-region (point) (point))
7245 (mml-insert-buffer forward-buffer
)
7246 (goto-char (point-min))
7247 (when (looking-at "From ")
7248 (replace-match "X-From-Line: "))
7249 (goto-char (point-max))))
7251 (insert "<#/mml>\n")
7252 (when (and (not message-forward-decoded-p
)
7253 message-forward-ignored-headers
)
7254 (message-remove-ignored-headers b e
))))
7256 (defun message-forward-make-body-digest-plain (forward-buffer)
7258 "\n-------------------- Start of forwarded message --------------------\n")
7259 (let ((b (point)) e
)
7260 (mml-insert-buffer forward-buffer
)
7263 "\n-------------------- End of forwarded message --------------------\n")))
7265 (defun message-forward-make-body-digest-mime (forward-buffer)
7266 (insert "\n<#multipart type=digest>\n")
7267 (let ((b (point)) e
)
7268 (insert-buffer-substring forward-buffer
)
7270 (insert "<#/multipart>\n")
7272 (narrow-to-region b e
)
7274 (narrow-to-region (point)
7275 (or (search-forward "\n\n" nil t
) (point)))
7276 (delete-region (point-min) (point-max)))))
7278 (defun message-forward-make-body-digest (forward-buffer)
7279 (if message-forward-as-mime
7280 (message-forward-make-body-digest-mime forward-buffer
)
7281 (message-forward-make-body-digest-plain forward-buffer
)))
7283 (autoload 'mm-uu-dissect-text-parts
"mm-uu")
7284 (autoload 'mm-uu-dissect
"mm-uu")
7286 (defun message-signed-or-encrypted-p (&optional dont-emulate-mime handles
)
7287 "Say whether the current buffer contains signed or encrypted message.
7288 If DONT-EMULATE-MIME is nil, this function does the MIME emulation on
7289 messages that don't conform to PGP/MIME described in RFC2015. HANDLES
7290 is for the internal use."
7292 (let ((mm-decrypt-option 'never
)
7293 (mm-verify-option 'never
))
7294 (if (setq handles
(mm-dissect-buffer nil t
))
7295 (unless dont-emulate-mime
7296 (mm-uu-dissect-text-parts handles
))
7297 (unless dont-emulate-mime
7298 (setq handles
(mm-uu-dissect))))))
7299 ;; Check text/plain message in which there is a signed or encrypted
7300 ;; body that has been encoded by B or Q.
7301 (unless (or handles dont-emulate-mime
)
7302 (let ((cur (current-buffer))
7303 (mm-decrypt-option 'never
)
7304 (mm-verify-option 'never
))
7306 (insert-buffer-substring cur
)
7307 (when (setq handles
(mm-dissect-buffer t t
))
7309 (bufferp (car handles
))
7310 (mm-destroy-parts handles
))
7311 (equal (mm-handle-media-type handles
) "text/plain"))
7313 (mm-decode-content-transfer-encoding
7314 (mm-handle-encoding handles
))
7315 (setq handles
(mm-uu-dissect)))
7316 (setq handles nil
))))))
7320 (dolist (handle (if (stringp (car handles
))
7321 (if (member (car handles
)
7322 '("multipart/signed"
7323 "multipart/encrypted"))
7327 (if (stringp (car handle
))
7328 (when (message-signed-or-encrypted-p dont-emulate-mime handle
)
7330 (when (and (bufferp (car handle
))
7331 (equal (mm-handle-media-type handle
)
7333 (with-current-buffer (mm-handle-buffer handle
)
7334 (when (message-signed-or-encrypted-p dont-emulate-mime
)
7335 (throw 'found t
)))))))
7336 (mm-destroy-parts handles
))))
7339 (defun message-forward-make-body (forward-buffer &optional digest
)
7340 ;; Put point where we want it before inserting the forwarded
7342 (if message-forward-before-signature
7344 (goto-char (point-max)))
7346 (message-forward-make-body-digest forward-buffer
)
7347 (if message-forward-as-mime
7348 (if (and message-forward-show-mml
7349 (not (and (eq message-forward-show-mml
'best
)
7350 ;; Use the raw form in the body if it contains
7351 ;; signed or encrypted message so as not to be
7352 ;; destroyed by re-encoding.
7353 (with-current-buffer forward-buffer
7355 (message-signed-or-encrypted-p)
7357 (message-forward-make-body-mml forward-buffer
)
7358 (message-forward-make-body-mime forward-buffer
))
7359 (message-forward-make-body-plain forward-buffer
)))
7360 (message-position-point))
7362 (declare-function rmail-toggle-header
"rmail" (&optional arg
))
7365 (defun message-forward-rmail-make-body (forward-buffer)
7366 (save-window-excursion
7367 (set-buffer forward-buffer
)
7368 (if (rmail-msg-is-pruned)
7369 (if (fboundp 'rmail-msg-restore-non-pruned-header
)
7370 (rmail-msg-restore-non-pruned-header) ; Emacs 22
7371 (rmail-toggle-header 0)))) ; Emacs 23
7372 (message-forward-make-body forward-buffer
))
7374 ;; Fixme: Should have defcustom.
7376 (defun message-insinuate-rmail ()
7377 "Let RMAIL use message to forward."
7379 (setq rmail-enable-mime-composing t
)
7380 (setq rmail-insert-mime-forwarded-message-function
7381 'message-forward-rmail-make-body
))
7384 (defun message-resend (address)
7385 "Resend the current article to ADDRESS."
7387 (list (message-read-from-minibuffer "Resend message to: ")))
7388 (message "Resending message to %s..." address
)
7390 (let ((cur (current-buffer))
7392 ;; We first set up a normal mail buffer.
7393 (unless (message-mail-user-agent)
7394 (set-buffer (get-buffer-create " *message resend*"))
7396 (let ((message-this-is-mail t
)
7397 message-generate-hashcash
7399 (message-setup `((To .
,address
))))
7400 ;; Insert our usual headers.
7401 (message-generate-headers '(From Date To Message-ID
))
7402 (message-narrow-to-headers)
7403 ;; Remove X-Draft-From header etc.
7404 (message-remove-header message-ignored-mail-headers t
)
7405 ;; Rename them all to "Resent-*".
7406 (goto-char (point-min))
7407 (while (re-search-forward "^[A-Za-z]" nil t
)
7412 (delete-region (point) (point-max))
7414 ;; Insert the message to be resent.
7415 (insert-buffer-substring cur
)
7416 (goto-char (point-min))
7417 (search-forward "\n\n")
7420 (narrow-to-region beg
(point))
7421 (message-remove-header message-ignored-resent-headers t
)
7422 (goto-char (point-max)))
7423 (insert mail-header-separator
)
7424 ;; Rename all old ("Also-")Resent headers.
7425 (while (re-search-backward "^\\(Also-\\)*Resent-" beg t
)
7428 ;; Quote any "From " lines at the beginning.
7430 (when (looking-at "From ")
7431 (replace-match "X-From-Line: "))
7433 (let ((message-inhibit-body-encoding t
)
7434 (message-inhibit-ecomplete t
)
7435 message-required-mail-headers
7436 message-generate-hashcash
7437 rfc2047-encode-encoded-words
)
7438 (message-send-mail))
7439 (kill-buffer (current-buffer)))
7440 (message "Resending message to %s...done" address
)))
7443 (defun message-bounce ()
7444 "Re-mail the current message.
7445 This only makes sense if the current message is a bounce message that
7446 contains some mail you have written which has been bounced back to
7449 (let ((handles (mm-dissect-buffer t
))
7451 (message-pop-to-buffer (message-buffer-name "bounce"))
7452 (if (stringp (car handles
))
7453 ;; This is a MIME bounce.
7454 (mm-insert-part (car (last handles
)))
7455 ;; This is a non-MIME bounce, so we try to remove things
7457 (mm-insert-part handles
)
7459 (goto-char (point-min))
7460 (re-search-forward "\n\n+" nil t
)
7461 (setq boundary
(point))
7462 ;; We remove everything before the bounced mail.
7463 (if (or (re-search-forward message-unsent-separator nil t
)
7465 (search-forward "\n\n" nil
'move
)
7466 (re-search-backward "^Return-Path:.*\n" boundary t
)))
7469 (delete-region (point-min)
7470 (if (re-search-forward "^[^ \n\t]+:" nil t
)
7473 (goto-char boundary
)
7474 (when (re-search-backward "^.?From .*\n" nil t
)
7475 (delete-region (match-beginning 0) (match-end 0)))))
7478 (message-narrow-to-head-1)
7479 (message-remove-header message-ignored-bounced-headers t
)
7480 (goto-char (point-max))
7481 (insert mail-header-separator
))
7482 (message-position-point)))
7485 ;;; Interactive entry points for new message buffers.
7489 (defun message-mail-other-window (&optional to subject
)
7490 "Like `message-mail' command, but display mail buffer in another window."
7492 (unless (message-mail-user-agent)
7493 (message-pop-to-buffer
7494 (message-buffer-name "mail" to
) 'pop-to-buffer-other-window
))
7495 (let ((message-this-is-mail t
))
7496 (message-setup `((To .
,(or to
"")) (Subject .
,(or subject
"")))
7497 nil nil nil
'switch-to-buffer-other-window
)))
7500 (defun message-mail-other-frame (&optional to subject
)
7501 "Like `message-mail' command, but display mail buffer in another frame."
7503 (unless (message-mail-user-agent)
7504 (message-pop-to-buffer
7505 (message-buffer-name "mail" to
) 'pop-to-buffer-other-frame
))
7506 (let ((message-this-is-mail t
))
7507 (message-setup `((To .
,(or to
"")) (Subject .
,(or subject
"")))
7508 nil nil nil
'switch-to-buffer-other-frame
)))
7511 (defun message-news-other-window (&optional newsgroups subject
)
7512 "Start editing a news article to be sent."
7514 (message-pop-to-buffer
7515 (message-buffer-name "posting" nil newsgroups
) 'pop-to-buffer-other-window
)
7516 (let ((message-this-is-news t
))
7517 (message-setup `((Newsgroups .
,(or newsgroups
""))
7518 (Subject .
,(or subject
""))))))
7521 (defun message-news-other-frame (&optional newsgroups subject
)
7522 "Start editing a news article to be sent."
7524 (message-pop-to-buffer
7525 (message-buffer-name "posting" nil newsgroups
) 'pop-to-buffer-other-frame
)
7526 (let ((message-this-is-news t
))
7527 (message-setup `((Newsgroups .
,(or newsgroups
""))
7528 (Subject .
,(or subject
""))))))
7532 ;; This code should be moved to underline.el (from which it is stolen).
7535 (defun message-bold-region (start end
)
7536 "Bold all nonblank characters in the region.
7537 Works by overstriking characters.
7538 Called from program, takes two arguments START and END
7539 which specify the range to operate on."
7542 (let ((end1 (make-marker)))
7543 (move-marker end1
(max start end
))
7544 (goto-char (min start end
))
7545 (while (< (point) end1
)
7546 (or (looking-at "[_\^@- ]")
7547 (insert (char-after) "\b"))
7548 (forward-char 1)))))
7551 (defun message-unbold-region (start end
)
7552 "Remove all boldness (overstruck characters) in the region.
7553 Called from program, takes two arguments START and END
7554 which specify the range to operate on."
7557 (let ((end1 (make-marker)))
7558 (move-marker end1
(max start end
))
7559 (goto-char (min start end
))
7560 (while (search-forward "\b" end1 t
)
7561 (if (eq (char-after) (char-after (- (point) 2)))
7562 (delete-char -
2))))))
7564 (defun message-exchange-point-and-mark ()
7565 "Exchange point and mark, but don't activate region if it was inactive."
7566 (goto-char (prog1 (mark t
)
7567 (set-marker (mark-marker) (point)))))
7569 (defalias 'message-make-overlay
'make-overlay
)
7570 (defalias 'message-delete-overlay
'delete-overlay
)
7571 (defalias 'message-overlay-put
'overlay-put
)
7572 (defun message-kill-all-overlays ()
7573 (if (featurep 'xemacs
)
7574 (map-extents (lambda (extent ignore
) (delete-extent extent
)))
7575 (mapcar #'delete-overlay
(overlays-in (point-min) (point-max)))))
7577 ;; Support for toolbar
7578 (defvar tool-bar-mode
)
7580 ;; Note: The :set function in the `message-tool-bar*' variables will only
7581 ;; affect _new_ message buffers. We might add a function that walks thru all
7582 ;; message-mode buffers and force the update.
7583 (defun message-tool-bar-update (&optional symbol value
)
7584 "Update message mode toolbar.
7585 Setter function for custom variables."
7586 (setq-default message-tool-bar-map nil
)
7588 ;; When used as ":set" function:
7589 (set-default symbol value
)))
7591 (defcustom message-tool-bar
(if (eq gmm-tool-bar-style
'gnome
)
7592 'message-tool-bar-gnome
7593 'message-tool-bar-retro
)
7594 "Specifies the message mode tool bar.
7596 It can be either a list or a symbol refering to a list. See
7597 `gmm-tool-bar-from-list' for the format of the list. The
7598 default key map is `message-mode-map'.
7600 Pre-defined symbols include `message-tool-bar-gnome' and
7601 `message-tool-bar-retro'."
7602 :type
'(repeat gmm-tool-bar-list-item
)
7603 :type
'(choice (const :tag
"GNOME style" message-tool-bar-gnome
)
7604 (const :tag
"Retro look" message-tool-bar-retro
)
7605 (repeat :tag
"User defined list" gmm-tool-bar-item
)
7607 :version
"23.1" ;; No Gnus
7608 :initialize
'custom-initialize-default
7609 :set
'message-tool-bar-update
7612 (defcustom message-tool-bar-gnome
7613 '((ispell-message "spell" nil
7614 :visible
(or (not (boundp 'flyspell-mode
))
7615 (not flyspell-mode
)))
7616 (flyspell-buffer "spell" t
7617 :visible
(and (boundp 'flyspell-mode
)
7619 :help
"Flyspell whole buffer")
7620 (gmm-ignore "separator")
7621 (message-send-and-exit "mail/send")
7622 (message-dont-send "mail/save-draft")
7623 (message-kill-buffer "close") ;; stock_cancel
7624 (mml-attach-file "attach" mml-mode-map
)
7625 (mml-preview "mail/preview" mml-mode-map
)
7626 (mml-secure-message-sign-encrypt "lock" mml-mode-map
:visible nil
)
7627 (message-insert-importance-high "important" nil
:visible nil
)
7628 (message-insert-importance-low "unimportant" nil
:visible nil
)
7629 (message-insert-disposition-notification-to "receipt" nil
:visible nil
)
7630 (gmm-customize-mode "preferences" t
:help
"Edit mode preferences")
7631 (message-info "help" t
:help
"Message manual"))
7632 "List of items for the message tool bar (GNOME style).
7634 See `gmm-tool-bar-from-list' for details on the format of the list."
7635 :type
'(repeat gmm-tool-bar-item
)
7636 :version
"23.1" ;; No Gnus
7637 :initialize
'custom-initialize-default
7638 :set
'message-tool-bar-update
7641 (defcustom message-tool-bar-retro
7642 '(;; Old Emacs 21 icon for consistency.
7643 (message-send-and-exit "gnus/mail-send")
7644 (message-kill-buffer "close")
7645 (message-dont-send "cancel")
7646 (mml-attach-file "attach" mml-mode-map
)
7647 (ispell-message "spell")
7648 (mml-preview "preview" mml-mode-map
)
7649 (message-insert-importance-high "gnus/important")
7650 (message-insert-importance-low "gnus/unimportant")
7651 (message-insert-disposition-notification-to "gnus/receipt"))
7652 "List of items for the message tool bar (retro style).
7654 See `gmm-tool-bar-from-list' for details on the format of the list."
7655 :type
'(repeat gmm-tool-bar-item
)
7656 :version
"23.1" ;; No Gnus
7657 :initialize
'custom-initialize-default
7658 :set
'message-tool-bar-update
7661 (defcustom message-tool-bar-zap-list
7662 '(new-file open-file dired kill-buffer write-file
7663 print-buffer customize help
)
7664 "List of icon items from the global tool bar.
7665 These items are not displayed on the message mode tool bar.
7667 See `gmm-tool-bar-from-list' for the format of the list."
7668 :type
'gmm-tool-bar-zap-list
7669 :version
"23.1" ;; No Gnus
7670 :initialize
'custom-initialize-default
7671 :set
'message-tool-bar-update
7674 (defvar image-load-path
)
7676 (defun message-make-tool-bar (&optional force
)
7677 "Make a message mode tool bar from `message-tool-bar-list'.
7678 When FORCE, rebuild the tool bar."
7679 (when (and (not (featurep 'xemacs
))
7680 (boundp 'tool-bar-mode
)
7682 (or (not message-tool-bar-map
) force
))
7683 (setq message-tool-bar-map
7685 (gmm-image-load-path-for-library "message"
7686 "mail/save-draft.xpm"
7688 (image-load-path (cons (car load-path
)
7689 (when (boundp 'image-load-path
)
7691 (gmm-tool-bar-from-list message-tool-bar
7692 message-tool-bar-zap-list
7693 'message-mode-map
))))
7694 message-tool-bar-map
)
7696 ;;; Group name completion.
7698 (defcustom message-newgroups-header-regexp
7699 "^\\(Newsgroups\\|Followup-To\\|Posted-To\\|Gcc\\):"
7700 "Regexp that match headers that lists groups."
7704 (defcustom message-completion-alist
7705 (list (cons message-newgroups-header-regexp
'message-expand-group
)
7706 '("^\\(Resent-\\)?\\(To\\|B?Cc\\):" . message-expand-name
)
7707 '("^\\(Reply-To\\|From\\|Mail-Followup-To\\|Mail-Copies-To\\):"
7708 . message-expand-name
)
7709 '("^\\(Disposition-Notification-To\\|Return-Receipt-To\\):"
7710 . message-expand-name
))
7711 "Alist of (RE . FUN). Use FUN for completion on header lines matching RE."
7714 :type
'(alist :key-type regexp
:value-type function
))
7716 (defcustom message-expand-name-databases
7718 "List of databases to try for name completion (`message-expand-name').
7719 Each element is a symbol and can be `bbdb' or `eudc'."
7721 :type
'(set (const bbdb
) (const eudc
)))
7723 (defcustom message-tab-body-function nil
7724 "*Function to execute when `message-tab' (TAB) is executed in the body.
7725 If nil, the function bound in `text-mode-map' or `global-map' is executed."
7728 :link
'(custom-manual "(message)Various Commands")
7729 :type
'(choice (const nil
)
7732 (declare-function mail-abbrev-in-expansion-header-p
"mailabbrev" ())
7734 (defun message-tab ()
7735 "Complete names according to `message-completion-alist'.
7736 Execute function specified by `message-tab-body-function' when not in
7739 (let ((alist message-completion-alist
))
7741 (let ((mail-abbrev-mode-regexp (caar alist
)))
7742 (not (mail-abbrev-in-expansion-header-p))))
7743 (setq alist
(cdr alist
)))
7744 (funcall (or (cdar alist
) message-tab-body-function
7745 (lookup-key text-mode-map
"\t")
7746 (lookup-key global-map
"\t")
7747 'indent-relative
))))
7752 (let ((standard-output (current-buffer)))
7753 (eval '(display-completion-list nil
"")))
7754 (defalias 'message-display-completion-list
'display-completion-list
))
7755 (error ;; Don't use `wrong-number-of-arguments' here because of XEmacs.
7756 (defun message-display-completion-list (completions &optional ignore
)
7757 "Display the list of completions, COMPLETIONS, using `standard-output'."
7758 (display-completion-list completions
)))))
7760 (defun message-expand-group ()
7761 "Expand the group name under point."
7762 (let* ((b (save-excursion
7767 (skip-chars-forward "^:")
7770 (skip-chars-backward "^, \t\n") (point))))
7771 (completion-ignore-case t
)
7772 (e (progn (skip-chars-forward "^,\t\n ") (point)))
7773 (hashtb (and (boundp 'gnus-active-hashtb
) gnus-active-hashtb
)))
7774 (message-completion-in-region e b hashtb
)))
7776 (defalias 'message-completion-in-region
7777 (if (fboundp 'completion-in-region
)
7778 'completion-in-region
7779 (lambda (e b hashtb
)
7780 (let* ((string (buffer-substring b e
))
7781 (completions (all-completions string hashtb
))
7783 (delete-region b
(point))
7785 ((= (length completions
) 1)
7786 (if (string= (car completions
) string
)
7789 (message "Only matching group"))
7790 (insert (car completions
))))
7791 ((and (setq comp
(try-completion string hashtb
))
7792 (not (string= comp string
)))
7797 (message "No matching groups")
7798 (save-selected-window
7799 (pop-to-buffer "*Completions*")
7800 (buffer-disable-undo)
7801 (let ((buffer-read-only nil
))
7803 (let ((standard-output (current-buffer)))
7804 (message-display-completion-list (sort completions
'string
<)
7806 (setq buffer-read-only nil
)
7807 (goto-char (point-min))
7808 (delete-region (point)
7809 (progn (forward-line 3) (point))))))))))))
7811 (defun message-expand-name ()
7812 (cond ((and (memq 'eudc message-expand-name-databases
)
7813 (boundp 'eudc-protocol
)
7815 (eudc-expand-inline))
7816 ((and (memq 'bbdb message-expand-name-databases
)
7817 (fboundp 'bbdb-complete-name
))
7818 (bbdb-complete-name))
7824 (defun message-talkative-question (ask question show
&rest text
)
7825 "Call FUNCTION with argument QUESTION; optionally display TEXT... args.
7826 If SHOW is non-nil, the arguments TEXT... are displayed in a temp buffer.
7827 The following arguments may contain lists of values."
7829 (setq text
(message-flatten-list text
)))
7830 (save-window-excursion
7831 (with-output-to-temp-buffer " *MESSAGE information message*"
7832 (with-current-buffer " *MESSAGE information message*"
7833 (fundamental-mode) ; for Emacs 20.4+
7835 (goto-char (point-min))))
7836 (funcall ask question
))
7837 (funcall ask question
)))
7839 (defun message-flatten-list (list)
7840 "Return a new, flat list that contains all elements of LIST.
7842 \(message-flatten-list '(1 (2 3 (4 5 (6))) 7))
7845 (apply 'append
(mapcar 'message-flatten-list list
)))
7849 (defun message-generate-new-buffer-clone-locals (name &optional varstr
)
7850 "Create and return a buffer with name based on NAME using `generate-new-buffer'.
7851 Then clone the local variables and values from the old buffer to the
7852 new one, cloning only the locals having a substring matching the
7854 (let ((oldbuf (current-buffer)))
7855 (with-current-buffer (generate-new-buffer name
)
7856 (message-clone-locals oldbuf varstr
)
7859 (defun message-clone-locals (buffer &optional varstr
)
7860 "Clone the local variables from BUFFER to the current buffer."
7861 (let ((locals (with-current-buffer buffer
(buffer-local-variables)))
7862 (regexp "^gnus\\|^nn\\|^message\\|^sendmail\\|^smtp\\|^user-mail-address"))
7865 (when (and (consp local
)
7867 (string-match regexp
(symbol-name (car local
)))
7869 (string-match varstr
(symbol-name (car local
)))))
7871 (set (make-local-variable (car local
))
7879 (defvar message-inhibit-body-encoding nil
)
7881 (defun message-encode-message-body ()
7882 (unless message-inhibit-body-encoding
7883 (let ((mail-parse-charset (or mail-parse-charset
7884 message-default-charset
))
7885 (case-fold-search t
)
7886 lines content-type-p
)
7889 (narrow-to-region (point) (point-max))
7890 (let ((new (mml-generate-mime)))
7892 (delete-region (point-min) (point-max))
7894 (goto-char (point-min))
7895 (if (eq (aref new
0) ?
\n)
7897 (search-forward "\n\n")
7898 (setq lines
(buffer-substring (point-min) (1- (point))))
7899 (delete-region (point-min) (point))))))
7901 (message-narrow-to-headers-or-head)
7902 (message-remove-header "Mime-Version")
7903 (goto-char (point-max))
7904 (insert "MIME-Version: 1.0\n")
7907 (setq content-type-p
7909 (re-search-backward "^Content-Type:" nil t
))))
7911 (message-narrow-to-headers-or-head)
7912 (message-remove-first-header "Content-Type")
7913 (message-remove-first-header "Content-Transfer-Encoding"))
7914 ;; We always make sure that the message has a Content-Type
7915 ;; header. This is because some broken MTAs and MUAs get
7916 ;; awfully confused when confronted with a message with a
7917 ;; MIME-Version header and without a Content-Type header. For
7918 ;; instance, Solaris' /usr/bin/mail.
7919 (unless content-type-p
7920 (goto-char (point-min))
7921 ;; For unknown reason, MIME-Version doesn't exist.
7922 (when (re-search-forward "^MIME-Version:" nil t
)
7924 (insert "Content-Type: text/plain; charset=us-ascii\n"))))))
7926 (defun message-read-from-minibuffer (prompt &optional initial-contents
)
7927 "Read from the minibuffer while providing abbrev expansion."
7928 (if (fboundp 'mail-abbrevs-setup
)
7929 (let ((mail-abbrev-mode-regexp "")
7930 (minibuffer-setup-hook 'mail-abbrevs-setup
)
7931 (minibuffer-local-map message-minibuffer-local-map
))
7932 (read-from-minibuffer prompt initial-contents
))
7933 (let ((minibuffer-setup-hook 'mail-abbrev-minibuffer-setup-hook
)
7934 (minibuffer-local-map message-minibuffer-local-map
))
7935 (read-string prompt initial-contents
))))
7937 (defun message-use-alternative-email-as-from ()
7938 "Set From field of the outgoing message to the first matching
7939 address in `message-alternative-emails', looking at To, Cc and
7940 From headers in the original article."
7941 (require 'mail-utils
)
7942 (let* ((fields '("To" "Cc" "From"))
7945 (mail-strip-quoted-names
7946 (mapconcat 'message-fetch-reply-field fields
","))
7950 (if (string-match message-alternative-emails
(car emails
))
7951 (setq email
(car emails
)
7954 (unless (or (not email
) (equal email user-mail-address
))
7955 (message-remove-header "From")
7956 (goto-char (point-max))
7957 (insert "From: " (let ((user-mail-address email
)) (message-make-from))
7960 (defun message-options-get (symbol)
7961 (cdr (assq symbol message-options
)))
7963 (defun message-options-set (symbol value
)
7964 (let ((the-cons (assq symbol message-options
)))
7967 (setcdr the-cons value
)
7968 (setq message-options
(delq the-cons message-options
)))
7970 (push (cons symbol value
) message-options
))))
7973 (defun message-options-set-recipient ()
7975 (message-narrow-to-headers-or-head)
7976 (message-options-set 'message-sender
7977 (mail-strip-quoted-names
7978 (message-fetch-field "from")))
7979 (message-options-set 'message-recipients
7980 (mail-strip-quoted-names
7981 (let ((to (message-fetch-field "to"))
7982 (cc (message-fetch-field "cc"))
7983 (bcc (message-fetch-field "bcc")))
7986 (if (and to cc
) ", ")
7988 (if (and (or to cc
) bcc
) ", ")
7991 (defun message-hide-headers ()
7992 "Hide headers based on the `message-hidden-headers' variable."
7993 (let ((regexps (if (stringp message-hidden-headers
)
7994 (list message-hidden-headers
)
7995 message-hidden-headers
))
7996 (inhibit-point-motion-hooks t
)
7997 (after-change-functions nil
)
7998 (end-of-headers (point-min)))
8002 (message-narrow-to-headers)
8003 (goto-char (point-min))
8005 (if (not (message-hide-header-p regexps
))
8006 (message-next-header)
8007 (let ((begin (point))
8009 (message-next-header)
8010 (setq header
(buffer-substring begin
(point))
8011 header-len
(- (point) begin
))
8012 (delete-region begin
(point))
8013 (goto-char end-of-headers
)
8015 (setq end-of-headers
8016 (+ end-of-headers header-len
))))))))
8017 (narrow-to-region end-of-headers
(point-max))))
8019 (defun message-hide-header-p (regexps)
8022 (when (eq (car regexps
) 'not
)
8025 (dolist (regexp regexps
)
8026 (setq result
(or result
(looking-at regexp
))))
8031 (declare-function ecomplete-add-item
"ecomplete" (type key text
))
8032 (declare-function ecomplete-save
"ecomplete" ())
8034 (defun message-put-addresses-in-ecomplete ()
8035 (require 'ecomplete
)
8036 (dolist (header '("to" "cc" "from" "reply-to"))
8037 (let ((value (message-field-value header
)))
8038 (dolist (string (mail-header-parse-addresses value
'raw
))
8040 (gnus-replace-in-string
8041 (gnus-replace-in-string string
"^ +\\| +$" "") "\n" ""))
8042 (ecomplete-add-item 'mail
(car (mail-header-parse-address string
))
8046 (autoload 'ecomplete-display-matches
"ecomplete")
8048 (defun message-display-abbrev (&optional choose
)
8049 "Display the next possible abbrev for the text before point."
8050 (interactive (list t
))
8051 (when (and (memq (char-after (point-at-bol)) '(?C ?T ?
\t ?
))
8052 (message-point-in-header-p)
8055 (while (and (memq (char-after) '(?
\t ?
))
8056 (zerop (forward-line -
1))))
8057 (looking-at "To:\\|Cc:")))
8058 (let* ((end (point))
8059 (start (save-excursion
8060 (and (re-search-backward "[\n\t ]" nil t
)
8062 (word (when start
(buffer-substring start end
)))
8063 (match (when (and word
8064 (not (zerop (length word
))))
8065 (ecomplete-display-matches 'mail word choose
))))
8066 (when (and choose match
)
8067 (delete-region start end
)
8070 ;; To send pre-formatted letters like the example below, you can use
8071 ;; `message-send-form-letter':
8072 ;; --8<---------------cut here---------------start------------->8---
8073 ;; To: alice@invalid.invalid
8074 ;; Subject: Verification of your contact information
8075 ;; From: Contact verification <admin@foo.invalid>
8076 ;; --text follows this line--
8078 ;; please verify that your contact information is still valid:
8079 ;; Alice A, A avenue 11, 1111 A town, Austria
8080 ;; ----------next form letter message follows this line----------
8081 ;; To: bob@invalid.invalid
8082 ;; Subject: Verification of your contact information
8083 ;; From: Contact verification <admin@foo.invalid>
8084 ;; --text follows this line--
8086 ;; please verify that your contact information is still valid:
8087 ;; Bob, B street 22, 22222 Be town, Belgium
8088 ;; ----------next form letter message follows this line----------
8089 ;; To: charlie@invalid.invalid
8090 ;; Subject: Verification of your contact information
8091 ;; From: Contact verification <admin@foo.invalid>
8092 ;; --text follows this line--
8094 ;; please verify that your contact information is still valid:
8095 ;; Charlie Chaplin, C plaza 33, 33333 C town, Chile
8096 ;; --8<---------------cut here---------------end--------------->8---
8098 ;; FIXME: What is the most common term (circular letter, form letter, serial
8099 ;; letter, standard letter) for such kind of letter? See also
8100 ;; <http://en.wikipedia.org/wiki/Form_letter>
8102 ;; FIXME: Maybe extent message-mode's font-lock support to recognize
8103 ;; `message-form-letter-separator', i.e. highlight each message like a single
8106 (defcustom message-form-letter-separator
8107 "\n----------next form letter message follows this line----------\n"
8108 "Separator for `message-send-form-letter'."
8109 ;; :group 'message-form-letter
8110 :group
'message-various
8111 :version
"23.1" ;; No Gnus
8114 (defcustom message-send-form-letter-delay
1
8115 "Delay in seconds when sending a message with `message-send-form-letter'.
8116 Only used when `message-send-form-letter' is called with non-nil
8118 ;; :group 'message-form-letter
8119 :group
'message-various
8120 :version
"23.1" ;; No Gnus
8123 (defun message-send-form-letter (&optional force
)
8124 "Sent all form letter messages from current buffer.
8125 Unless FORCE, prompt before sending.
8127 The messages are separated by `message-form-letter-separator'.
8128 Header and body are separated by `mail-header-separator'."
8130 (let ((sent 0) (skipped 0)
8134 (goto-char (point-min))
8137 end
(if (search-forward message-form-letter-separator nil t
)
8138 (- (point) (length message-form-letter-separator
) -
1)
8142 (buffer-substring-no-properties start end
))
8143 (setq buff
(generate-new-buffer "*mail - form letter*"))
8144 (with-current-buffer buff
8147 (setq to
(message-fetch-field "To"))
8148 (switch-to-buffer buff
)
8150 (sit-for message-send-form-letter-delay
))
8152 (y-or-n-p (format "Send message to `%s'? " to
)))
8154 (setq sent
(1+ sent
))
8155 (message-send-and-exit))
8156 (message (format "Message to `%s' skipped." to
))
8157 (setq skipped
(1+ skipped
)))
8158 (when (buffer-live-p buff
)
8159 (kill-buffer buff
))))
8160 (message "%s message(s) sent, %s skipped." sent skipped
)))
8162 (defun message-replace-header (header new-value
&optional after force
)
8163 "Remove HEADER and insert the NEW-VALUE.
8164 If AFTER, insert after this header. If FORCE, insert new field
8165 even if NEW-VALUE is empty."
8166 ;; Similar to `nnheader-replace-header' but for message buffers.
8169 (message-narrow-to-headers)
8170 (message-remove-header header
))
8171 (when (or force
(> (length new-value
) 0))
8173 (message-position-on-field header after
)
8174 (message-position-on-field header
))
8175 (insert new-value
))))
8177 (defcustom message-recipients-without-full-name
8178 (list "ding@gnus.org"
8180 "emacs-devel@gnu.org"
8181 "emacs-pretest-bug@gnu.org"
8182 "bug-gnu-emacs@gnu.org")
8183 "Mail addresses that have no full name.
8184 Used in `message-simplify-recipients'."
8185 ;; Maybe the addresses could be extracted from
8186 ;; `gnus-parameter-to-list-alist'?
8187 :type
'(choice (const :tag
"None" nil
)
8189 :version
"23.1" ;; No Gnus
8190 :group
'message-headers
)
8192 (defun message-simplify-recipients ()
8194 (dolist (hdr '("Cc" "To"))
8195 (message-replace-header
8199 (if (and message-recipients-without-full-name
8201 (regexp-opt message-recipients-without-full-name
)
8205 (message-make-from (car addrcomp
) (cadr addrcomp
))
8207 (when (message-fetch-field hdr
)
8208 (mail-extract-address-components
8209 (message-fetch-field hdr
) t
))
8212 (when (featurep 'xemacs
)
8213 (require 'messagexmas
)
8214 (message-xmas-redefine))
8218 (run-hooks 'message-load-hook
)
8221 ;; coding: iso-8859-1
8224 ;;; message.el ends here